[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 end if;
1461
1462 -- Output case (SPARK RM 6.1.5(10))
1463
1464 else
1465 Name_Len := 0;
1466
1467 Add_Item_To_Name_Buffer (Item_Id);
1468 Add_Str_To_Name_Buffer
1469 (" & is missing from output dependence list");
1470
1471 Error_Msg := Name_Find;
1472 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1473 end if;
1474 end Usage_Error;
1475
1476 -- Local variables
1477
1478 Elmt : Elmt_Id;
1479 Item : Node_Id;
1480 Item_Id : Entity_Id;
1481
1482 -- Start of processing for Check_Usage
1483
1484 begin
1485 if No (Subp_Items) then
1486 return;
1487 end if;
1488
1489 -- Each input or output of the subprogram must appear in a dependency
1490 -- relation.
1491
1492 Elmt := First_Elmt (Subp_Items);
1493 while Present (Elmt) loop
1494 Item := Node (Elmt);
1495
1496 if Nkind (Item) = N_Defining_Identifier then
1497 Item_Id := Item;
1498 else
1499 Item_Id := Entity_Of (Item);
1500 end if;
1501
1502 -- The item does not appear in a dependency
1503
1504 if Present (Item_Id)
1505 and then not Contains (Used_Items, Item_Id)
1506 then
1507 if Is_Formal (Item_Id) then
1508 Usage_Error (Item_Id);
1509
1510 -- The current instance of a protected type behaves as a formal
1511 -- parameter (SPARK RM 6.1.4).
1512
1513 elsif Ekind (Item_Id) = E_Protected_Type
1514 or else Is_Single_Protected_Object (Item_Id)
1515 then
1516 Usage_Error (Item_Id);
1517
1518 -- The current instance of a task type behaves as a formal
1519 -- parameter (SPARK RM 6.1.4).
1520
1521 elsif Ekind (Item_Id) = E_Task_Type
1522 or else Is_Single_Task_Object (Item_Id)
1523 then
1524 -- The dependence of a task unit on itself is implicit and
1525 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1526 -- Emit an error if only one input/output is present.
1527
1528 if Task_Input_Seen /= Task_Output_Seen then
1529 Usage_Error (Item_Id);
1530 end if;
1531
1532 -- States and global objects are not used properly only when
1533 -- the subprogram is subject to pragma Global.
1534
1535 elsif Global_Seen then
1536 Usage_Error (Item_Id);
1537 end if;
1538 end if;
1539
1540 Next_Elmt (Elmt);
1541 end loop;
1542 end Check_Usage;
1543
1544 ----------------------
1545 -- Normalize_Clause --
1546 ----------------------
1547
1548 procedure Normalize_Clause (Clause : Node_Id) is
1549 procedure Create_Or_Modify_Clause
1550 (Output : Node_Id;
1551 Outputs : Node_Id;
1552 Inputs : Node_Id;
1553 After : Node_Id;
1554 In_Place : Boolean;
1555 Multiple : Boolean);
1556 -- Create a brand new clause to represent the self-reference or
1557 -- modify the input and/or output lists of an existing clause. Output
1558 -- denotes a self-referencial output. Outputs is the output list of a
1559 -- clause. Inputs is the input list of a clause. After denotes the
1560 -- clause after which the new clause is to be inserted. Flag In_Place
1561 -- should be set when normalizing the last output of an output list.
1562 -- Flag Multiple should be set when Output comes from a list with
1563 -- multiple items.
1564
1565 -----------------------------
1566 -- Create_Or_Modify_Clause --
1567 -----------------------------
1568
1569 procedure Create_Or_Modify_Clause
1570 (Output : Node_Id;
1571 Outputs : Node_Id;
1572 Inputs : Node_Id;
1573 After : Node_Id;
1574 In_Place : Boolean;
1575 Multiple : Boolean)
1576 is
1577 procedure Propagate_Output
1578 (Output : Node_Id;
1579 Inputs : Node_Id);
1580 -- Handle the various cases of output propagation to the input
1581 -- list. Output denotes a self-referencial output item. Inputs
1582 -- is the input list of a clause.
1583
1584 ----------------------
1585 -- Propagate_Output --
1586 ----------------------
1587
1588 procedure Propagate_Output
1589 (Output : Node_Id;
1590 Inputs : Node_Id)
1591 is
1592 function In_Input_List
1593 (Item : Entity_Id;
1594 Inputs : List_Id) return Boolean;
1595 -- Determine whether a particulat item appears in the input
1596 -- list of a clause.
1597
1598 -------------------
1599 -- In_Input_List --
1600 -------------------
1601
1602 function In_Input_List
1603 (Item : Entity_Id;
1604 Inputs : List_Id) return Boolean
1605 is
1606 Elmt : Node_Id;
1607
1608 begin
1609 Elmt := First (Inputs);
1610 while Present (Elmt) loop
1611 if Entity_Of (Elmt) = Item then
1612 return True;
1613 end if;
1614
1615 Next (Elmt);
1616 end loop;
1617
1618 return False;
1619 end In_Input_List;
1620
1621 -- Local variables
1622
1623 Output_Id : constant Entity_Id := Entity_Of (Output);
1624 Grouped : List_Id;
1625
1626 -- Start of processing for Propagate_Output
1627
1628 begin
1629 -- The clause is of the form:
1630
1631 -- (Output =>+ null)
1632
1633 -- Remove null input and replace it with a copy of the output:
1634
1635 -- (Output => Output)
1636
1637 if Nkind (Inputs) = N_Null then
1638 Rewrite (Inputs, New_Copy_Tree (Output));
1639
1640 -- The clause is of the form:
1641
1642 -- (Output =>+ (Input1, ..., InputN))
1643
1644 -- Determine whether the output is not already mentioned in the
1645 -- input list and if not, add it to the list of inputs:
1646
1647 -- (Output => (Output, Input1, ..., InputN))
1648
1649 elsif Nkind (Inputs) = N_Aggregate then
1650 Grouped := Expressions (Inputs);
1651
1652 if not In_Input_List
1653 (Item => Output_Id,
1654 Inputs => Grouped)
1655 then
1656 Prepend_To (Grouped, New_Copy_Tree (Output));
1657 end if;
1658
1659 -- The clause is of the form:
1660
1661 -- (Output =>+ Input)
1662
1663 -- If the input does not mention the output, group the two
1664 -- together:
1665
1666 -- (Output => (Output, Input))
1667
1668 elsif Entity_Of (Inputs) /= Output_Id then
1669 Rewrite (Inputs,
1670 Make_Aggregate (Loc,
1671 Expressions => New_List (
1672 New_Copy_Tree (Output),
1673 New_Copy_Tree (Inputs))));
1674 end if;
1675 end Propagate_Output;
1676
1677 -- Local variables
1678
1679 Loc : constant Source_Ptr := Sloc (Clause);
1680 New_Clause : Node_Id;
1681
1682 -- Start of processing for Create_Or_Modify_Clause
1683
1684 begin
1685 -- A null output depending on itself does not require any
1686 -- normalization.
1687
1688 if Nkind (Output) = N_Null then
1689 return;
1690
1691 -- A function result cannot depend on itself because it cannot
1692 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1693
1694 elsif Is_Attribute_Result (Output) then
1695 SPARK_Msg_N ("function result cannot depend on itself", Output);
1696 return;
1697 end if;
1698
1699 -- When performing the transformation in place, simply add the
1700 -- output to the list of inputs (if not already there). This
1701 -- case arises when dealing with the last output of an output
1702 -- list. Perform the normalization in place to avoid generating
1703 -- a malformed tree.
1704
1705 if In_Place then
1706 Propagate_Output (Output, Inputs);
1707
1708 -- A list with multiple outputs is slowly trimmed until only
1709 -- one element remains. When this happens, replace aggregate
1710 -- with the element itself.
1711
1712 if Multiple then
1713 Remove (Output);
1714 Rewrite (Outputs, Output);
1715 end if;
1716
1717 -- Default case
1718
1719 else
1720 -- Unchain the output from its output list as it will appear in
1721 -- a new clause. Note that we cannot simply rewrite the output
1722 -- as null because this will violate the semantics of pragma
1723 -- Depends.
1724
1725 Remove (Output);
1726
1727 -- Generate a new clause of the form:
1728 -- (Output => Inputs)
1729
1730 New_Clause :=
1731 Make_Component_Association (Loc,
1732 Choices => New_List (Output),
1733 Expression => New_Copy_Tree (Inputs));
1734
1735 -- The new clause contains replicated content that has already
1736 -- been analyzed. There is not need to reanalyze or renormalize
1737 -- it again.
1738
1739 Set_Analyzed (New_Clause);
1740
1741 Propagate_Output
1742 (Output => First (Choices (New_Clause)),
1743 Inputs => Expression (New_Clause));
1744
1745 Insert_After (After, New_Clause);
1746 end if;
1747 end Create_Or_Modify_Clause;
1748
1749 -- Local variables
1750
1751 Outputs : constant Node_Id := First (Choices (Clause));
1752 Inputs : Node_Id;
1753 Last_Output : Node_Id;
1754 Next_Output : Node_Id;
1755 Output : Node_Id;
1756
1757 -- Start of processing for Normalize_Clause
1758
1759 begin
1760 -- A self-dependency appears as operator "+". Remove the "+" from the
1761 -- tree by moving the real inputs to their proper place.
1762
1763 if Nkind (Expression (Clause)) = N_Op_Plus then
1764 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1765 Inputs := Expression (Clause);
1766
1767 -- Multiple outputs appear as an aggregate
1768
1769 if Nkind (Outputs) = N_Aggregate then
1770 Last_Output := Last (Expressions (Outputs));
1771
1772 Output := First (Expressions (Outputs));
1773 while Present (Output) loop
1774
1775 -- Normalization may remove an output from its list,
1776 -- preserve the subsequent output now.
1777
1778 Next_Output := Next (Output);
1779
1780 Create_Or_Modify_Clause
1781 (Output => Output,
1782 Outputs => Outputs,
1783 Inputs => Inputs,
1784 After => Clause,
1785 In_Place => Output = Last_Output,
1786 Multiple => True);
1787
1788 Output := Next_Output;
1789 end loop;
1790
1791 -- Solitary output
1792
1793 else
1794 Create_Or_Modify_Clause
1795 (Output => Outputs,
1796 Outputs => Empty,
1797 Inputs => Inputs,
1798 After => Empty,
1799 In_Place => True,
1800 Multiple => False);
1801 end if;
1802 end if;
1803 end Normalize_Clause;
1804
1805 -- Local variables
1806
1807 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1808 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1809
1810 Clause : Node_Id;
1811 Errors : Nat;
1812 Last_Clause : Node_Id;
1813 Restore_Scope : Boolean := False;
1814
1815 -- Start of processing for Analyze_Depends_In_Decl_Part
1816
1817 begin
1818 -- Do not analyze the pragma multiple times
1819
1820 if Is_Analyzed_Pragma (N) then
1821 return;
1822 end if;
1823
1824 -- Empty dependency list
1825
1826 if Nkind (Deps) = N_Null then
1827
1828 -- Gather all states, objects and formal parameters that the
1829 -- subprogram may depend on. These items are obtained from the
1830 -- parameter profile or pragma [Refined_]Global (if available).
1831
1832 Collect_Subprogram_Inputs_Outputs
1833 (Subp_Id => Subp_Id,
1834 Subp_Inputs => Subp_Inputs,
1835 Subp_Outputs => Subp_Outputs,
1836 Global_Seen => Global_Seen);
1837
1838 -- Verify that every input or output of the subprogram appear in a
1839 -- dependency.
1840
1841 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1842 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1843 Check_Function_Return;
1844
1845 -- Dependency clauses appear as component associations of an aggregate
1846
1847 elsif Nkind (Deps) = N_Aggregate then
1848
1849 -- Do not attempt to perform analysis of a syntactically illegal
1850 -- clause as this will lead to misleading errors.
1851
1852 if Has_Extra_Parentheses (Deps) then
1853 return;
1854 end if;
1855
1856 if Present (Component_Associations (Deps)) then
1857 Last_Clause := Last (Component_Associations (Deps));
1858
1859 -- Gather all states, objects and formal parameters that the
1860 -- subprogram may depend on. These items are obtained from the
1861 -- parameter profile or pragma [Refined_]Global (if available).
1862
1863 Collect_Subprogram_Inputs_Outputs
1864 (Subp_Id => Subp_Id,
1865 Subp_Inputs => Subp_Inputs,
1866 Subp_Outputs => Subp_Outputs,
1867 Global_Seen => Global_Seen);
1868
1869 -- When pragma [Refined_]Depends appears on a single concurrent
1870 -- type, it is relocated to the anonymous object.
1871
1872 if Is_Single_Concurrent_Object (Spec_Id) then
1873 null;
1874
1875 -- Ensure that the formal parameters are visible when analyzing
1876 -- all clauses. This falls out of the general rule of aspects
1877 -- pertaining to subprogram declarations.
1878
1879 elsif not In_Open_Scopes (Spec_Id) then
1880 Restore_Scope := True;
1881 Push_Scope (Spec_Id);
1882
1883 if Ekind (Spec_Id) = E_Task_Type then
1884 if Has_Discriminants (Spec_Id) then
1885 Install_Discriminants (Spec_Id);
1886 end if;
1887
1888 elsif Is_Generic_Subprogram (Spec_Id) then
1889 Install_Generic_Formals (Spec_Id);
1890
1891 else
1892 Install_Formals (Spec_Id);
1893 end if;
1894 end if;
1895
1896 Clause := First (Component_Associations (Deps));
1897 while Present (Clause) loop
1898 Errors := Serious_Errors_Detected;
1899
1900 -- The normalization mechanism may create extra clauses that
1901 -- contain replicated input and output names. There is no need
1902 -- to reanalyze them.
1903
1904 if not Analyzed (Clause) then
1905 Set_Analyzed (Clause);
1906
1907 Analyze_Dependency_Clause
1908 (Clause => Clause,
1909 Is_Last => Clause = Last_Clause);
1910 end if;
1911
1912 -- Do not normalize a clause if errors were detected (count
1913 -- of Serious_Errors has increased) because the inputs and/or
1914 -- outputs may denote illegal items. Normalization is disabled
1915 -- in ASIS mode as it alters the tree by introducing new nodes
1916 -- similar to expansion.
1917
1918 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1919 Normalize_Clause (Clause);
1920 end if;
1921
1922 Next (Clause);
1923 end loop;
1924
1925 if Restore_Scope then
1926 End_Scope;
1927 end if;
1928
1929 -- Verify that every input or output of the subprogram appear in a
1930 -- dependency.
1931
1932 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1933 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1934 Check_Function_Return;
1935
1936 -- The dependency list is malformed. This is a syntax error, always
1937 -- report.
1938
1939 else
1940 Error_Msg_N ("malformed dependency relation", Deps);
1941 return;
1942 end if;
1943
1944 -- The top level dependency relation is malformed. This is a syntax
1945 -- error, always report.
1946
1947 else
1948 Error_Msg_N ("malformed dependency relation", Deps);
1949 goto Leave;
1950 end if;
1951
1952 -- Ensure that a state and a corresponding constituent do not appear
1953 -- together in pragma [Refined_]Depends.
1954
1955 Check_State_And_Constituent_Use
1956 (States => States_Seen,
1957 Constits => Constits_Seen,
1958 Context => N);
1959
1960 <<Leave>>
1961 Set_Is_Analyzed_Pragma (N);
1962 end Analyze_Depends_In_Decl_Part;
1963
1964 --------------------------------------------
1965 -- Analyze_External_Property_In_Decl_Part --
1966 --------------------------------------------
1967
1968 procedure Analyze_External_Property_In_Decl_Part
1969 (N : Node_Id;
1970 Expr_Val : out Boolean)
1971 is
1972 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1973 Obj_Decl : constant Node_Id := Find_Related_Context (N);
1974 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
1975 Expr : Node_Id;
1976
1977 begin
1978 Expr_Val := False;
1979
1980 -- Do not analyze the pragma multiple times
1981
1982 if Is_Analyzed_Pragma (N) then
1983 return;
1984 end if;
1985
1986 Error_Msg_Name_1 := Pragma_Name (N);
1987
1988 -- An external property pragma must apply to an effectively volatile
1989 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1990 -- The check is performed at the end of the declarative region due to a
1991 -- possible out-of-order arrangement of pragmas:
1992
1993 -- Obj : ...;
1994 -- pragma Async_Readers (Obj);
1995 -- pragma Volatile (Obj);
1996
1997 if not Is_Effectively_Volatile (Obj_Id) then
1998 SPARK_Msg_N
1999 ("external property % must apply to a volatile object", N);
2000 end if;
2001
2002 -- Ensure that the Boolean expression (if present) is static. A missing
2003 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2004
2005 Expr_Val := True;
2006
2007 if Present (Arg1) then
2008 Expr := Get_Pragma_Arg (Arg1);
2009
2010 if Is_OK_Static_Expression (Expr) then
2011 Expr_Val := Is_True (Expr_Value (Expr));
2012 end if;
2013 end if;
2014
2015 Set_Is_Analyzed_Pragma (N);
2016 end Analyze_External_Property_In_Decl_Part;
2017
2018 ---------------------------------
2019 -- Analyze_Global_In_Decl_Part --
2020 ---------------------------------
2021
2022 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2023 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2024 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2025 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2026
2027 Constits_Seen : Elist_Id := No_Elist;
2028 -- A list containing the entities of all constituents processed so far.
2029 -- It aids in detecting illegal usage of a state and a corresponding
2030 -- constituent in pragma [Refinde_]Global.
2031
2032 Seen : Elist_Id := No_Elist;
2033 -- A list containing the entities of all the items processed so far. It
2034 -- plays a role in detecting distinct entities.
2035
2036 States_Seen : Elist_Id := No_Elist;
2037 -- A list containing the entities of all states processed so far. It
2038 -- helps in detecting illegal usage of a state and a corresponding
2039 -- constituent in pragma [Refined_]Global.
2040
2041 In_Out_Seen : Boolean := False;
2042 Input_Seen : Boolean := False;
2043 Output_Seen : Boolean := False;
2044 Proof_Seen : Boolean := False;
2045 -- Flags used to verify the consistency of modes
2046
2047 procedure Analyze_Global_List
2048 (List : Node_Id;
2049 Global_Mode : Name_Id := Name_Input);
2050 -- Verify the legality of a single global list declaration. Global_Mode
2051 -- denotes the current mode in effect.
2052
2053 -------------------------
2054 -- Analyze_Global_List --
2055 -------------------------
2056
2057 procedure Analyze_Global_List
2058 (List : Node_Id;
2059 Global_Mode : Name_Id := Name_Input)
2060 is
2061 procedure Analyze_Global_Item
2062 (Item : Node_Id;
2063 Global_Mode : Name_Id);
2064 -- Verify the legality of a single global item declaration denoted by
2065 -- Item. Global_Mode denotes the current mode in effect.
2066
2067 procedure Check_Duplicate_Mode
2068 (Mode : Node_Id;
2069 Status : in out Boolean);
2070 -- Flag Status denotes whether a particular mode has been seen while
2071 -- processing a global list. This routine verifies that Mode is not a
2072 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2073
2074 procedure Check_Mode_Restriction_In_Enclosing_Context
2075 (Item : Node_Id;
2076 Item_Id : Entity_Id);
2077 -- Verify that an item of mode In_Out or Output does not appear as an
2078 -- input in the Global aspect of an enclosing subprogram. If this is
2079 -- the case, emit an error. Item and Item_Id are respectively the
2080 -- item and its entity.
2081
2082 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2083 -- Mode denotes either In_Out or Output. Depending on the kind of the
2084 -- related subprogram, emit an error if those two modes apply to a
2085 -- function (SPARK RM 6.1.4(10)).
2086
2087 -------------------------
2088 -- Analyze_Global_Item --
2089 -------------------------
2090
2091 procedure Analyze_Global_Item
2092 (Item : Node_Id;
2093 Global_Mode : Name_Id)
2094 is
2095 Item_Id : Entity_Id;
2096
2097 begin
2098 -- Detect one of the following cases
2099
2100 -- with Global => (null, Name)
2101 -- with Global => (Name_1, null, Name_2)
2102 -- with Global => (Name, null)
2103
2104 if Nkind (Item) = N_Null then
2105 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2106 return;
2107 end if;
2108
2109 Analyze (Item);
2110 Resolve_State (Item);
2111
2112 -- Find the entity of the item. If this is a renaming, climb the
2113 -- renaming chain to reach the root object. Renamings of non-
2114 -- entire objects do not yield an entity (Empty).
2115
2116 Item_Id := Entity_Of (Item);
2117
2118 if Present (Item_Id) then
2119
2120 -- A global item may denote a formal parameter of an enclosing
2121 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2122 -- provide a better error diagnostic.
2123
2124 if Is_Formal (Item_Id) then
2125 if Scope (Item_Id) = Spec_Id then
2126 SPARK_Msg_NE
2127 (Fix_Msg (Spec_Id, "global item cannot reference "
2128 & "parameter of subprogram &"), Item, Spec_Id);
2129 return;
2130 end if;
2131
2132 -- A global item may denote a concurrent type as long as it is
2133 -- the current instance of an enclosing protected or task type
2134 -- (SPARK RM 6.1.4).
2135
2136 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2137 if Is_CCT_Instance (Item_Id, Spec_Id) then
2138
2139 -- Pragma [Refined_]Global associated with a protected
2140 -- subprogram cannot mention the current instance of a
2141 -- protected type because the instance behaves as a
2142 -- formal parameter.
2143
2144 if Ekind (Item_Id) = E_Protected_Type then
2145 Error_Msg_Name_1 := Chars (Item_Id);
2146 SPARK_Msg_NE
2147 (Fix_Msg (Spec_Id, "global item of subprogram & "
2148 & "cannot reference current instance of protected "
2149 & "type %"), Item, Spec_Id);
2150 return;
2151
2152 -- Pragma [Refined_]Global associated with a task type
2153 -- cannot mention the current instance of a task type
2154 -- because the instance behaves as a formal parameter.
2155
2156 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2157 Error_Msg_Name_1 := Chars (Item_Id);
2158 SPARK_Msg_NE
2159 (Fix_Msg (Spec_Id, "global item of subprogram & "
2160 & "cannot reference current instance of task type "
2161 & "%"), Item, Spec_Id);
2162 return;
2163 end if;
2164
2165 -- Otherwise the global item denotes a subtype mark that is
2166 -- not a current instance.
2167
2168 else
2169 SPARK_Msg_N
2170 ("invalid use of subtype mark in global list", Item);
2171 return;
2172 end if;
2173
2174 -- A global item may denote the anonymous object created for a
2175 -- single protected/task type as long as the current instance
2176 -- is the same single type (SPARK RM 6.1.4).
2177
2178 elsif Is_Single_Concurrent_Object (Item_Id)
2179 and then Is_CCT_Instance (Item_Id, Spec_Id)
2180 then
2181 -- Pragma [Refined_]Global associated with a protected
2182 -- subprogram cannot mention the current instance of a
2183 -- protected type because the instance behaves as a formal
2184 -- parameter.
2185
2186 if Is_Single_Protected_Object (Item_Id) then
2187 Error_Msg_Name_1 := Chars (Item_Id);
2188 SPARK_Msg_NE
2189 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2190 & "reference current instance of protected type %"),
2191 Item, Spec_Id);
2192 return;
2193
2194 -- Pragma [Refined_]Global associated with a task type
2195 -- cannot mention the current instance of a task type
2196 -- because the instance behaves as a formal parameter.
2197
2198 else pragma Assert (Is_Single_Task_Object (Item_Id));
2199 Error_Msg_Name_1 := Chars (Item_Id);
2200 SPARK_Msg_NE
2201 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2202 & "reference current instance of task type %"),
2203 Item, Spec_Id);
2204 return;
2205 end if;
2206
2207 -- A formal object may act as a global item inside a generic
2208
2209 elsif Is_Formal_Object (Item_Id) then
2210 null;
2211
2212 -- The only legal references are those to abstract states,
2213 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2214
2215 elsif not Ekind_In (Item_Id, E_Abstract_State,
2216 E_Constant,
2217 E_Loop_Parameter,
2218 E_Variable)
2219 then
2220 SPARK_Msg_N
2221 ("global item must denote object, state or current "
2222 & "instance of concurrent type", Item);
2223 return;
2224 end if;
2225
2226 -- State related checks
2227
2228 if Ekind (Item_Id) = E_Abstract_State then
2229
2230 -- Package and subprogram bodies are instantiated
2231 -- individually in a separate compiler pass. Due to this
2232 -- mode of instantiation, the refinement of a state may
2233 -- no longer be visible when a subprogram body contract
2234 -- is instantiated. Since the generic template is legal,
2235 -- do not perform this check in the instance to circumvent
2236 -- this oddity.
2237
2238 if Is_Generic_Instance (Spec_Id) then
2239 null;
2240
2241 -- An abstract state with visible refinement cannot appear
2242 -- in pragma [Refined_]Global as its place must be taken by
2243 -- some of its constituents (SPARK RM 6.1.4(7)).
2244
2245 elsif Has_Visible_Refinement (Item_Id) then
2246 SPARK_Msg_NE
2247 ("cannot mention state & in global refinement",
2248 Item, Item_Id);
2249 SPARK_Msg_N ("\use its constituents instead", Item);
2250 return;
2251
2252 -- An external state cannot appear as a global item of a
2253 -- nonvolatile function (SPARK RM 7.1.3(8)).
2254
2255 elsif Is_External_State (Item_Id)
2256 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2257 and then not Is_Volatile_Function (Spec_Id)
2258 then
2259 SPARK_Msg_NE
2260 ("external state & cannot act as global item of "
2261 & "nonvolatile function", Item, Item_Id);
2262 return;
2263
2264 -- If the reference to the abstract state appears in an
2265 -- enclosing package body that will eventually refine the
2266 -- state, record the reference for future checks.
2267
2268 else
2269 Record_Possible_Body_Reference
2270 (State_Id => Item_Id,
2271 Ref => Item);
2272 end if;
2273
2274 -- Constant related checks
2275
2276 elsif Ekind (Item_Id) = E_Constant then
2277
2278 -- A constant is a read-only item, therefore it cannot act
2279 -- as an output.
2280
2281 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2282 SPARK_Msg_NE
2283 ("constant & cannot act as output", Item, Item_Id);
2284 return;
2285 end if;
2286
2287 -- Loop parameter related checks
2288
2289 elsif Ekind (Item_Id) = E_Loop_Parameter then
2290
2291 -- A loop parameter is a read-only item, therefore it cannot
2292 -- act as an output.
2293
2294 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2295 SPARK_Msg_NE
2296 ("loop parameter & cannot act as output",
2297 Item, Item_Id);
2298 return;
2299 end if;
2300
2301 -- Variable related checks. These are only relevant when
2302 -- SPARK_Mode is on as they are not standard Ada legality
2303 -- rules.
2304
2305 elsif SPARK_Mode = On
2306 and then Ekind (Item_Id) = E_Variable
2307 and then Is_Effectively_Volatile (Item_Id)
2308 then
2309 -- An effectively volatile object cannot appear as a global
2310 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2311
2312 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2313 and then not Is_Volatile_Function (Spec_Id)
2314 then
2315 Error_Msg_NE
2316 ("volatile object & cannot act as global item of a "
2317 & "function", Item, Item_Id);
2318 return;
2319
2320 -- An effectively volatile object with external property
2321 -- Effective_Reads set to True must have mode Output or
2322 -- In_Out (SPARK RM 7.1.3(10)).
2323
2324 elsif Effective_Reads_Enabled (Item_Id)
2325 and then Global_Mode = Name_Input
2326 then
2327 Error_Msg_NE
2328 ("volatile object & with property Effective_Reads must "
2329 & "have mode In_Out or Output", Item, Item_Id);
2330 return;
2331 end if;
2332 end if;
2333
2334 -- When the item renames an entire object, replace the item
2335 -- with a reference to the object.
2336
2337 if Entity (Item) /= Item_Id then
2338 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2339 Analyze (Item);
2340 end if;
2341
2342 -- Some form of illegal construct masquerading as a name
2343 -- (SPARK RM 6.1.4(4)).
2344
2345 else
2346 Error_Msg_N
2347 ("global item must denote object, state or current instance "
2348 & "of concurrent type", Item);
2349 return;
2350 end if;
2351
2352 -- Verify that an output does not appear as an input in an
2353 -- enclosing subprogram.
2354
2355 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2356 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2357 end if;
2358
2359 -- The same entity might be referenced through various way.
2360 -- Check the entity of the item rather than the item itself
2361 -- (SPARK RM 6.1.4(10)).
2362
2363 if Contains (Seen, Item_Id) then
2364 SPARK_Msg_N ("duplicate global item", Item);
2365
2366 -- Add the entity of the current item to the list of processed
2367 -- items.
2368
2369 else
2370 Append_New_Elmt (Item_Id, Seen);
2371
2372 if Ekind (Item_Id) = E_Abstract_State then
2373 Append_New_Elmt (Item_Id, States_Seen);
2374
2375 -- The variable may eventually become a constituent of a single
2376 -- protected/task type. Record the reference now and verify its
2377 -- legality when analyzing the contract of the variable
2378 -- (SPARK RM 9.3).
2379
2380 elsif Ekind (Item_Id) = E_Variable then
2381 Record_Possible_Part_Of_Reference
2382 (Var_Id => Item_Id,
2383 Ref => Item);
2384 end if;
2385
2386 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2387 and then Present (Encapsulating_State (Item_Id))
2388 then
2389 Append_New_Elmt (Item_Id, Constits_Seen);
2390 end if;
2391 end if;
2392 end Analyze_Global_Item;
2393
2394 --------------------------
2395 -- Check_Duplicate_Mode --
2396 --------------------------
2397
2398 procedure Check_Duplicate_Mode
2399 (Mode : Node_Id;
2400 Status : in out Boolean)
2401 is
2402 begin
2403 if Status then
2404 SPARK_Msg_N ("duplicate global mode", Mode);
2405 end if;
2406
2407 Status := True;
2408 end Check_Duplicate_Mode;
2409
2410 -------------------------------------------------
2411 -- Check_Mode_Restriction_In_Enclosing_Context --
2412 -------------------------------------------------
2413
2414 procedure Check_Mode_Restriction_In_Enclosing_Context
2415 (Item : Node_Id;
2416 Item_Id : Entity_Id)
2417 is
2418 Context : Entity_Id;
2419 Dummy : Boolean;
2420 Inputs : Elist_Id := No_Elist;
2421 Outputs : Elist_Id := No_Elist;
2422
2423 begin
2424 -- Traverse the scope stack looking for enclosing subprograms
2425 -- subject to pragma [Refined_]Global.
2426
2427 Context := Scope (Subp_Id);
2428 while Present (Context) and then Context /= Standard_Standard loop
2429 if Is_Subprogram (Context)
2430 and then
2431 (Present (Get_Pragma (Context, Pragma_Global))
2432 or else
2433 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2434 then
2435 Collect_Subprogram_Inputs_Outputs
2436 (Subp_Id => Context,
2437 Subp_Inputs => Inputs,
2438 Subp_Outputs => Outputs,
2439 Global_Seen => Dummy);
2440
2441 -- The item is classified as In_Out or Output but appears as
2442 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2443
2444 if Appears_In (Inputs, Item_Id)
2445 and then not Appears_In (Outputs, Item_Id)
2446 then
2447 SPARK_Msg_NE
2448 ("global item & cannot have mode In_Out or Output",
2449 Item, Item_Id);
2450
2451 SPARK_Msg_NE
2452 (Fix_Msg (Subp_Id, "\item already appears as input of "
2453 & "subprogram &"), Item, Context);
2454
2455 -- Stop the traversal once an error has been detected
2456
2457 exit;
2458 end if;
2459 end if;
2460
2461 Context := Scope (Context);
2462 end loop;
2463 end Check_Mode_Restriction_In_Enclosing_Context;
2464
2465 ----------------------------------------
2466 -- Check_Mode_Restriction_In_Function --
2467 ----------------------------------------
2468
2469 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2470 begin
2471 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2472 SPARK_Msg_N
2473 ("global mode & is not applicable to functions", Mode);
2474 end if;
2475 end Check_Mode_Restriction_In_Function;
2476
2477 -- Local variables
2478
2479 Assoc : Node_Id;
2480 Item : Node_Id;
2481 Mode : Node_Id;
2482
2483 -- Start of processing for Analyze_Global_List
2484
2485 begin
2486 if Nkind (List) = N_Null then
2487 Set_Analyzed (List);
2488
2489 -- Single global item declaration
2490
2491 elsif Nkind_In (List, N_Expanded_Name,
2492 N_Identifier,
2493 N_Selected_Component)
2494 then
2495 Analyze_Global_Item (List, Global_Mode);
2496
2497 -- Simple global list or moded global list declaration
2498
2499 elsif Nkind (List) = N_Aggregate then
2500 Set_Analyzed (List);
2501
2502 -- The declaration of a simple global list appear as a collection
2503 -- of expressions.
2504
2505 if Present (Expressions (List)) then
2506 if Present (Component_Associations (List)) then
2507 SPARK_Msg_N
2508 ("cannot mix moded and non-moded global lists", List);
2509 end if;
2510
2511 Item := First (Expressions (List));
2512 while Present (Item) loop
2513 Analyze_Global_Item (Item, Global_Mode);
2514 Next (Item);
2515 end loop;
2516
2517 -- The declaration of a moded global list appears as a collection
2518 -- of component associations where individual choices denote
2519 -- modes.
2520
2521 elsif Present (Component_Associations (List)) then
2522 if Present (Expressions (List)) then
2523 SPARK_Msg_N
2524 ("cannot mix moded and non-moded global lists", List);
2525 end if;
2526
2527 Assoc := First (Component_Associations (List));
2528 while Present (Assoc) loop
2529 Mode := First (Choices (Assoc));
2530
2531 if Nkind (Mode) = N_Identifier then
2532 if Chars (Mode) = Name_In_Out then
2533 Check_Duplicate_Mode (Mode, In_Out_Seen);
2534 Check_Mode_Restriction_In_Function (Mode);
2535
2536 elsif Chars (Mode) = Name_Input then
2537 Check_Duplicate_Mode (Mode, Input_Seen);
2538
2539 elsif Chars (Mode) = Name_Output then
2540 Check_Duplicate_Mode (Mode, Output_Seen);
2541 Check_Mode_Restriction_In_Function (Mode);
2542
2543 elsif Chars (Mode) = Name_Proof_In then
2544 Check_Duplicate_Mode (Mode, Proof_Seen);
2545
2546 else
2547 SPARK_Msg_N ("invalid mode selector", Mode);
2548 end if;
2549
2550 else
2551 SPARK_Msg_N ("invalid mode selector", Mode);
2552 end if;
2553
2554 -- Items in a moded list appear as a collection of
2555 -- expressions. Reuse the existing machinery to analyze
2556 -- them.
2557
2558 Analyze_Global_List
2559 (List => Expression (Assoc),
2560 Global_Mode => Chars (Mode));
2561
2562 Next (Assoc);
2563 end loop;
2564
2565 -- Invalid tree
2566
2567 else
2568 raise Program_Error;
2569 end if;
2570
2571 -- Any other attempt to declare a global item is illegal. This is a
2572 -- syntax error, always report.
2573
2574 else
2575 Error_Msg_N ("malformed global list", List);
2576 end if;
2577 end Analyze_Global_List;
2578
2579 -- Local variables
2580
2581 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2582
2583 Restore_Scope : Boolean := False;
2584
2585 -- Start of processing for Analyze_Global_In_Decl_Part
2586
2587 begin
2588 -- Do not analyze the pragma multiple times
2589
2590 if Is_Analyzed_Pragma (N) then
2591 return;
2592 end if;
2593
2594 -- There is nothing to be done for a null global list
2595
2596 if Nkind (Items) = N_Null then
2597 Set_Analyzed (Items);
2598
2599 -- Analyze the various forms of global lists and items. Note that some
2600 -- of these may be malformed in which case the analysis emits error
2601 -- messages.
2602
2603 else
2604 -- When pragma [Refined_]Global appears on a single concurrent type,
2605 -- it is relocated to the anonymous object.
2606
2607 if Is_Single_Concurrent_Object (Spec_Id) then
2608 null;
2609
2610 -- Ensure that the formal parameters are visible when processing an
2611 -- item. This falls out of the general rule of aspects pertaining to
2612 -- subprogram declarations.
2613
2614 elsif not In_Open_Scopes (Spec_Id) then
2615 Restore_Scope := True;
2616 Push_Scope (Spec_Id);
2617
2618 if Ekind (Spec_Id) = E_Task_Type then
2619 if Has_Discriminants (Spec_Id) then
2620 Install_Discriminants (Spec_Id);
2621 end if;
2622
2623 elsif Is_Generic_Subprogram (Spec_Id) then
2624 Install_Generic_Formals (Spec_Id);
2625
2626 else
2627 Install_Formals (Spec_Id);
2628 end if;
2629 end if;
2630
2631 Analyze_Global_List (Items);
2632
2633 if Restore_Scope then
2634 End_Scope;
2635 end if;
2636 end if;
2637
2638 -- Ensure that a state and a corresponding constituent do not appear
2639 -- together in pragma [Refined_]Global.
2640
2641 Check_State_And_Constituent_Use
2642 (States => States_Seen,
2643 Constits => Constits_Seen,
2644 Context => N);
2645
2646 Set_Is_Analyzed_Pragma (N);
2647 end Analyze_Global_In_Decl_Part;
2648
2649 --------------------------------------------
2650 -- Analyze_Initial_Condition_In_Decl_Part --
2651 --------------------------------------------
2652
2653 -- WARNING: This routine manages Ghost regions. Return statements must be
2654 -- replaced by gotos which jump to the end of the routine and restore the
2655 -- Ghost mode.
2656
2657 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2658 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2659 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2660 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2661
2662 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
2663 -- Save the Ghost mode to restore on exit
2664
2665 begin
2666 -- Do not analyze the pragma multiple times
2667
2668 if Is_Analyzed_Pragma (N) then
2669 return;
2670 end if;
2671
2672 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2673 -- analysis of the pragma, the Ghost mode at point of declaration and
2674 -- point of analysis may not necessarily be the same. Use the mode in
2675 -- effect at the point of declaration.
2676
2677 Set_Ghost_Mode (N);
2678
2679 -- The expression is preanalyzed because it has not been moved to its
2680 -- final place yet. A direct analysis may generate side effects and this
2681 -- is not desired at this point.
2682
2683 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2684 Set_Is_Analyzed_Pragma (N);
2685
2686 Restore_Ghost_Mode (Saved_GM);
2687 end Analyze_Initial_Condition_In_Decl_Part;
2688
2689 --------------------------------------
2690 -- Analyze_Initializes_In_Decl_Part --
2691 --------------------------------------
2692
2693 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2694 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2695 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2696
2697 Constits_Seen : Elist_Id := No_Elist;
2698 -- A list containing the entities of all constituents processed so far.
2699 -- It aids in detecting illegal usage of a state and a corresponding
2700 -- constituent in pragma Initializes.
2701
2702 Items_Seen : Elist_Id := No_Elist;
2703 -- A list of all initialization items processed so far. This list is
2704 -- used to detect duplicate items.
2705
2706 Non_Null_Seen : Boolean := False;
2707 Null_Seen : Boolean := False;
2708 -- Flags used to check the legality of a null initialization list
2709
2710 States_And_Objs : Elist_Id := No_Elist;
2711 -- A list of all abstract states and objects declared in the visible
2712 -- declarations of the related package. This list is used to detect the
2713 -- legality of initialization items.
2714
2715 States_Seen : Elist_Id := No_Elist;
2716 -- A list containing the entities of all states processed so far. It
2717 -- helps in detecting illegal usage of a state and a corresponding
2718 -- constituent in pragma Initializes.
2719
2720 procedure Analyze_Initialization_Item (Item : Node_Id);
2721 -- Verify the legality of a single initialization item
2722
2723 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2724 -- Verify the legality of a single initialization item followed by a
2725 -- list of input items.
2726
2727 procedure Collect_States_And_Objects;
2728 -- Inspect the visible declarations of the related package and gather
2729 -- the entities of all abstract states and objects in States_And_Objs.
2730
2731 ---------------------------------
2732 -- Analyze_Initialization_Item --
2733 ---------------------------------
2734
2735 procedure Analyze_Initialization_Item (Item : Node_Id) is
2736 Item_Id : Entity_Id;
2737
2738 begin
2739 -- Null initialization list
2740
2741 if Nkind (Item) = N_Null then
2742 if Null_Seen then
2743 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2744
2745 elsif Non_Null_Seen then
2746 SPARK_Msg_N
2747 ("cannot mix null and non-null initialization items", Item);
2748 else
2749 Null_Seen := True;
2750 end if;
2751
2752 -- Initialization item
2753
2754 else
2755 Non_Null_Seen := True;
2756
2757 if Null_Seen then
2758 SPARK_Msg_N
2759 ("cannot mix null and non-null initialization items", Item);
2760 end if;
2761
2762 Analyze (Item);
2763 Resolve_State (Item);
2764
2765 if Is_Entity_Name (Item) then
2766 Item_Id := Entity_Of (Item);
2767
2768 if Ekind_In (Item_Id, E_Abstract_State,
2769 E_Constant,
2770 E_Variable)
2771 then
2772 -- The state or variable must be declared in the visible
2773 -- declarations of the package (SPARK RM 7.1.5(7)).
2774
2775 if not Contains (States_And_Objs, Item_Id) then
2776 Error_Msg_Name_1 := Chars (Pack_Id);
2777 SPARK_Msg_NE
2778 ("initialization item & must appear in the visible "
2779 & "declarations of package %", Item, Item_Id);
2780
2781 -- Detect a duplicate use of the same initialization item
2782 -- (SPARK RM 7.1.5(5)).
2783
2784 elsif Contains (Items_Seen, Item_Id) then
2785 SPARK_Msg_N ("duplicate initialization item", Item);
2786
2787 -- The item is legal, add it to the list of processed states
2788 -- and variables.
2789
2790 else
2791 Append_New_Elmt (Item_Id, Items_Seen);
2792
2793 if Ekind (Item_Id) = E_Abstract_State then
2794 Append_New_Elmt (Item_Id, States_Seen);
2795 end if;
2796
2797 if Present (Encapsulating_State (Item_Id)) then
2798 Append_New_Elmt (Item_Id, Constits_Seen);
2799 end if;
2800 end if;
2801
2802 -- The item references something that is not a state or object
2803 -- (SPARK RM 7.1.5(3)).
2804
2805 else
2806 SPARK_Msg_N
2807 ("initialization item must denote object or state", Item);
2808 end if;
2809
2810 -- Some form of illegal construct masquerading as a name
2811 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2812
2813 else
2814 Error_Msg_N
2815 ("initialization item must denote object or state", Item);
2816 end if;
2817 end if;
2818 end Analyze_Initialization_Item;
2819
2820 ---------------------------------------------
2821 -- Analyze_Initialization_Item_With_Inputs --
2822 ---------------------------------------------
2823
2824 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2825 Inputs_Seen : Elist_Id := No_Elist;
2826 -- A list of all inputs processed so far. This list is used to detect
2827 -- duplicate uses of an input.
2828
2829 Non_Null_Seen : Boolean := False;
2830 Null_Seen : Boolean := False;
2831 -- Flags used to check the legality of an input list
2832
2833 procedure Analyze_Input_Item (Input : Node_Id);
2834 -- Verify the legality of a single input item
2835
2836 ------------------------
2837 -- Analyze_Input_Item --
2838 ------------------------
2839
2840 procedure Analyze_Input_Item (Input : Node_Id) is
2841 Input_Id : Entity_Id;
2842 Input_OK : Boolean := True;
2843
2844 begin
2845 -- Null input list
2846
2847 if Nkind (Input) = N_Null then
2848 if Null_Seen then
2849 SPARK_Msg_N
2850 ("multiple null initializations not allowed", Item);
2851
2852 elsif Non_Null_Seen then
2853 SPARK_Msg_N
2854 ("cannot mix null and non-null initialization item", Item);
2855 else
2856 Null_Seen := True;
2857 end if;
2858
2859 -- Input item
2860
2861 else
2862 Non_Null_Seen := True;
2863
2864 if Null_Seen then
2865 SPARK_Msg_N
2866 ("cannot mix null and non-null initialization item", Item);
2867 end if;
2868
2869 Analyze (Input);
2870 Resolve_State (Input);
2871
2872 if Is_Entity_Name (Input) then
2873 Input_Id := Entity_Of (Input);
2874
2875 if Ekind_In (Input_Id, E_Abstract_State,
2876 E_Constant,
2877 E_Generic_In_Out_Parameter,
2878 E_Generic_In_Parameter,
2879 E_In_Parameter,
2880 E_In_Out_Parameter,
2881 E_Out_Parameter,
2882 E_Variable)
2883 then
2884 -- The input cannot denote states or objects declared
2885 -- within the related package (SPARK RM 7.1.5(4)).
2886
2887 if Within_Scope (Input_Id, Current_Scope) then
2888
2889 -- Do not consider generic formal parameters or their
2890 -- respective mappings to generic formals. Even though
2891 -- the formals appear within the scope of the package,
2892 -- it is allowed for an initialization item to depend
2893 -- on an input item.
2894
2895 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
2896 E_Generic_In_Parameter)
2897 then
2898 null;
2899
2900 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
2901 and then Present (Corresponding_Generic_Association
2902 (Declaration_Node (Input_Id)))
2903 then
2904 null;
2905
2906 else
2907 Input_OK := False;
2908 Error_Msg_Name_1 := Chars (Pack_Id);
2909 SPARK_Msg_NE
2910 ("input item & cannot denote a visible object or "
2911 & "state of package %", Input, Input_Id);
2912 end if;
2913 end if;
2914
2915 -- Detect a duplicate use of the same input item
2916 -- (SPARK RM 7.1.5(5)).
2917
2918 if Contains (Inputs_Seen, Input_Id) then
2919 Input_OK := False;
2920 SPARK_Msg_N ("duplicate input item", Input);
2921 end if;
2922
2923 -- Input is legal, add it to the list of processed inputs
2924
2925 if Input_OK then
2926 Append_New_Elmt (Input_Id, Inputs_Seen);
2927
2928 if Ekind (Input_Id) = E_Abstract_State then
2929 Append_New_Elmt (Input_Id, States_Seen);
2930 end if;
2931
2932 if Ekind_In (Input_Id, E_Abstract_State,
2933 E_Constant,
2934 E_Variable)
2935 and then Present (Encapsulating_State (Input_Id))
2936 then
2937 Append_New_Elmt (Input_Id, Constits_Seen);
2938 end if;
2939 end if;
2940
2941 -- The input references something that is not a state or an
2942 -- object (SPARK RM 7.1.5(3)).
2943
2944 else
2945 SPARK_Msg_N
2946 ("input item must denote object or state", Input);
2947 end if;
2948
2949 -- Some form of illegal construct masquerading as a name
2950 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2951
2952 else
2953 Error_Msg_N
2954 ("input item must denote object or state", Input);
2955 end if;
2956 end if;
2957 end Analyze_Input_Item;
2958
2959 -- Local variables
2960
2961 Inputs : constant Node_Id := Expression (Item);
2962 Elmt : Node_Id;
2963 Input : Node_Id;
2964
2965 Name_Seen : Boolean := False;
2966 -- A flag used to detect multiple item names
2967
2968 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2969
2970 begin
2971 -- Inspect the name of an item with inputs
2972
2973 Elmt := First (Choices (Item));
2974 while Present (Elmt) loop
2975 if Name_Seen then
2976 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2977 else
2978 Name_Seen := True;
2979 Analyze_Initialization_Item (Elmt);
2980 end if;
2981
2982 Next (Elmt);
2983 end loop;
2984
2985 -- Multiple input items appear as an aggregate
2986
2987 if Nkind (Inputs) = N_Aggregate then
2988 if Present (Expressions (Inputs)) then
2989 Input := First (Expressions (Inputs));
2990 while Present (Input) loop
2991 Analyze_Input_Item (Input);
2992 Next (Input);
2993 end loop;
2994 end if;
2995
2996 if Present (Component_Associations (Inputs)) then
2997 SPARK_Msg_N
2998 ("inputs must appear in named association form", Inputs);
2999 end if;
3000
3001 -- Single input item
3002
3003 else
3004 Analyze_Input_Item (Inputs);
3005 end if;
3006 end Analyze_Initialization_Item_With_Inputs;
3007
3008 --------------------------------
3009 -- Collect_States_And_Objects --
3010 --------------------------------
3011
3012 procedure Collect_States_And_Objects is
3013 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3014 Decl : Node_Id;
3015
3016 begin
3017 -- Collect the abstract states defined in the package (if any)
3018
3019 if Present (Abstract_States (Pack_Id)) then
3020 States_And_Objs := New_Copy_Elist (Abstract_States (Pack_Id));
3021 end if;
3022
3023 -- Collect all objects the appear in the visible declarations of the
3024 -- related package.
3025
3026 if Present (Visible_Declarations (Pack_Spec)) then
3027 Decl := First (Visible_Declarations (Pack_Spec));
3028 while Present (Decl) loop
3029 if Comes_From_Source (Decl)
3030 and then Nkind (Decl) = N_Object_Declaration
3031 then
3032 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3033 end if;
3034
3035 Next (Decl);
3036 end loop;
3037 end if;
3038 end Collect_States_And_Objects;
3039
3040 -- Local variables
3041
3042 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3043 Init : Node_Id;
3044
3045 -- Start of processing for Analyze_Initializes_In_Decl_Part
3046
3047 begin
3048 -- Do not analyze the pragma multiple times
3049
3050 if Is_Analyzed_Pragma (N) then
3051 return;
3052 end if;
3053
3054 -- Nothing to do when the initialization list is empty
3055
3056 if Nkind (Inits) = N_Null then
3057 return;
3058 end if;
3059
3060 -- Single and multiple initialization clauses appear as an aggregate. If
3061 -- this is not the case, then either the parser or the analysis of the
3062 -- pragma failed to produce an aggregate.
3063
3064 pragma Assert (Nkind (Inits) = N_Aggregate);
3065
3066 -- Initialize the various lists used during analysis
3067
3068 Collect_States_And_Objects;
3069
3070 if Present (Expressions (Inits)) then
3071 Init := First (Expressions (Inits));
3072 while Present (Init) loop
3073 Analyze_Initialization_Item (Init);
3074 Next (Init);
3075 end loop;
3076 end if;
3077
3078 if Present (Component_Associations (Inits)) then
3079 Init := First (Component_Associations (Inits));
3080 while Present (Init) loop
3081 Analyze_Initialization_Item_With_Inputs (Init);
3082 Next (Init);
3083 end loop;
3084 end if;
3085
3086 -- Ensure that a state and a corresponding constituent do not appear
3087 -- together in pragma Initializes.
3088
3089 Check_State_And_Constituent_Use
3090 (States => States_Seen,
3091 Constits => Constits_Seen,
3092 Context => N);
3093
3094 Set_Is_Analyzed_Pragma (N);
3095 end Analyze_Initializes_In_Decl_Part;
3096
3097 ---------------------
3098 -- Analyze_Part_Of --
3099 ---------------------
3100
3101 procedure Analyze_Part_Of
3102 (Indic : Node_Id;
3103 Item_Id : Entity_Id;
3104 Encap : Node_Id;
3105 Encap_Id : out Entity_Id;
3106 Legal : out Boolean)
3107 is
3108 Encap_Typ : Entity_Id;
3109 Item_Decl : Node_Id;
3110 Pack_Id : Entity_Id;
3111 Placement : State_Space_Kind;
3112 Parent_Unit : Entity_Id;
3113
3114 begin
3115 -- Assume that the indicator is illegal
3116
3117 Encap_Id := Empty;
3118 Legal := False;
3119
3120 if Nkind_In (Encap, N_Expanded_Name,
3121 N_Identifier,
3122 N_Selected_Component)
3123 then
3124 Analyze (Encap);
3125 Resolve_State (Encap);
3126
3127 Encap_Id := Entity (Encap);
3128
3129 -- The encapsulator is an abstract state
3130
3131 if Ekind (Encap_Id) = E_Abstract_State then
3132 null;
3133
3134 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3135
3136 elsif Is_Single_Concurrent_Object (Encap_Id) then
3137 null;
3138
3139 -- Otherwise the encapsulator is not a legal choice
3140
3141 else
3142 SPARK_Msg_N
3143 ("indicator Part_Of must denote abstract state, single "
3144 & "protected type or single task type", Encap);
3145 return;
3146 end if;
3147
3148 -- This is a syntax error, always report
3149
3150 else
3151 Error_Msg_N
3152 ("indicator Part_Of must denote abstract state, single protected "
3153 & "type or single task type", Encap);
3154 return;
3155 end if;
3156
3157 -- Catch a case where indicator Part_Of denotes the abstract view of a
3158 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3159
3160 if From_Limited_With (Encap_Id)
3161 and then Present (Non_Limited_View (Encap_Id))
3162 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3163 then
3164 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3165 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3166 return;
3167 end if;
3168
3169 -- The encapsulator is an abstract state
3170
3171 if Ekind (Encap_Id) = E_Abstract_State then
3172
3173 -- Determine where the object, package instantiation or state lives
3174 -- with respect to the enclosing packages or package bodies.
3175
3176 Find_Placement_In_State_Space
3177 (Item_Id => Item_Id,
3178 Placement => Placement,
3179 Pack_Id => Pack_Id);
3180
3181 -- The item appears in a non-package construct with a declarative
3182 -- part (subprogram, block, etc). As such, the item is not allowed
3183 -- to be a part of an encapsulating state because the item is not
3184 -- visible.
3185
3186 if Placement = Not_In_Package then
3187 SPARK_Msg_N
3188 ("indicator Part_Of cannot appear in this context "
3189 & "(SPARK RM 7.2.6(5))", Indic);
3190 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3191 SPARK_Msg_NE
3192 ("\& is not part of the hidden state of package %",
3193 Indic, Item_Id);
3194
3195 -- The item appears in the visible state space of some package. In
3196 -- general this scenario does not warrant Part_Of except when the
3197 -- package is a private child unit and the encapsulating state is
3198 -- declared in a parent unit or a public descendant of that parent
3199 -- unit.
3200
3201 elsif Placement = Visible_State_Space then
3202 if Is_Child_Unit (Pack_Id)
3203 and then Is_Private_Descendant (Pack_Id)
3204 then
3205 -- A variable or state abstraction which is part of the visible
3206 -- state of a private child unit (or one of its public
3207 -- descendants) must have its Part_Of indicator specified. The
3208 -- Part_Of indicator must denote a state abstraction declared
3209 -- by either the parent unit of the private unit or by a public
3210 -- descendant of that parent unit.
3211
3212 -- Find nearest private ancestor (which can be the current unit
3213 -- itself).
3214
3215 Parent_Unit := Pack_Id;
3216 while Present (Parent_Unit) loop
3217 exit when
3218 Private_Present
3219 (Parent (Unit_Declaration_Node (Parent_Unit)));
3220 Parent_Unit := Scope (Parent_Unit);
3221 end loop;
3222
3223 Parent_Unit := Scope (Parent_Unit);
3224
3225 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3226 SPARK_Msg_NE
3227 ("indicator Part_Of must denote abstract state or public "
3228 & "descendant of & (SPARK RM 7.2.6(3))",
3229 Indic, Parent_Unit);
3230
3231 elsif Scope (Encap_Id) = Parent_Unit
3232 or else
3233 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3234 and then not Is_Private_Descendant (Scope (Encap_Id)))
3235 then
3236 null;
3237
3238 else
3239 SPARK_Msg_NE
3240 ("indicator Part_Of must denote abstract state or public "
3241 & "descendant of & (SPARK RM 7.2.6(3))",
3242 Indic, Parent_Unit);
3243 end if;
3244
3245 -- Indicator Part_Of is not needed when the related package is not
3246 -- a private child unit or a public descendant thereof.
3247
3248 else
3249 SPARK_Msg_N
3250 ("indicator Part_Of cannot appear in this context "
3251 & "(SPARK RM 7.2.6(5))", Indic);
3252 Error_Msg_Name_1 := Chars (Pack_Id);
3253 SPARK_Msg_NE
3254 ("\& is declared in the visible part of package %",
3255 Indic, Item_Id);
3256 end if;
3257
3258 -- When the item appears in the private state space of a package, the
3259 -- encapsulating state must be declared in the same package.
3260
3261 elsif Placement = Private_State_Space then
3262 if Scope (Encap_Id) /= Pack_Id then
3263 SPARK_Msg_NE
3264 ("indicator Part_Of must designate an abstract state of "
3265 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3266 Error_Msg_Name_1 := Chars (Pack_Id);
3267 SPARK_Msg_NE
3268 ("\& is declared in the private part of package %",
3269 Indic, Item_Id);
3270 end if;
3271
3272 -- Items declared in the body state space of a package do not need
3273 -- Part_Of indicators as the refinement has already been seen.
3274
3275 else
3276 SPARK_Msg_N
3277 ("indicator Part_Of cannot appear in this context "
3278 & "(SPARK RM 7.2.6(5))", Indic);
3279
3280 if Scope (Encap_Id) = Pack_Id then
3281 Error_Msg_Name_1 := Chars (Pack_Id);
3282 SPARK_Msg_NE
3283 ("\& is declared in the body of package %", Indic, Item_Id);
3284 end if;
3285 end if;
3286
3287 -- The encapsulator is a single concurrent type
3288
3289 else
3290 Encap_Typ := Etype (Encap_Id);
3291
3292 -- Only abstract states and variables can act as constituents of an
3293 -- encapsulating single concurrent type.
3294
3295 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3296 null;
3297
3298 -- The constituent is a constant
3299
3300 elsif Ekind (Item_Id) = E_Constant then
3301 Error_Msg_Name_1 := Chars (Encap_Id);
3302 SPARK_Msg_NE
3303 (Fix_Msg (Encap_Typ, "constant & cannot act as constituent of "
3304 & "single protected type %"), Indic, Item_Id);
3305
3306 -- The constituent is a package instantiation
3307
3308 else
3309 Error_Msg_Name_1 := Chars (Encap_Id);
3310 SPARK_Msg_NE
3311 (Fix_Msg (Encap_Typ, "package instantiation & cannot act as "
3312 & "constituent of single protected type %"), Indic, Item_Id);
3313 end if;
3314
3315 -- When the item denotes an abstract state of a nested package, use
3316 -- the declaration of the package to detect proper placement.
3317
3318 -- package Pack is
3319 -- task T;
3320 -- package Nested
3321 -- with Abstract_State => (State with Part_Of => T)
3322
3323 if Ekind (Item_Id) = E_Abstract_State then
3324 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3325 else
3326 Item_Decl := Declaration_Node (Item_Id);
3327 end if;
3328
3329 -- Both the item and its encapsulating single concurrent type must
3330 -- appear in the same declarative region (SPARK RM 9.3). Note that
3331 -- privacy is ignored.
3332
3333 if Parent (Item_Decl) /= Parent (Declaration_Node (Encap_Id)) then
3334 Error_Msg_Name_1 := Chars (Encap_Id);
3335 SPARK_Msg_NE
3336 (Fix_Msg (Encap_Typ, "constituent & must be declared "
3337 & "immediately within the same region as single protected "
3338 & "type %"), Indic, Item_Id);
3339 end if;
3340 end if;
3341
3342 Legal := True;
3343 end Analyze_Part_Of;
3344
3345 ----------------------------------
3346 -- Analyze_Part_Of_In_Decl_Part --
3347 ----------------------------------
3348
3349 procedure Analyze_Part_Of_In_Decl_Part
3350 (N : Node_Id;
3351 Freeze_Id : Entity_Id := Empty)
3352 is
3353 Encap : constant Node_Id :=
3354 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3355 Errors : constant Nat := Serious_Errors_Detected;
3356 Var_Decl : constant Node_Id := Find_Related_Context (N);
3357 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3358 Constits : Elist_Id;
3359 Encap_Id : Entity_Id;
3360 Legal : Boolean;
3361
3362 begin
3363 -- Detect any discrepancies between the placement of the variable with
3364 -- respect to general state space and the encapsulating state or single
3365 -- concurrent type.
3366
3367 Analyze_Part_Of
3368 (Indic => N,
3369 Item_Id => Var_Id,
3370 Encap => Encap,
3371 Encap_Id => Encap_Id,
3372 Legal => Legal);
3373
3374 -- The Part_Of indicator turns the variable into a constituent of the
3375 -- encapsulating state or single concurrent type.
3376
3377 if Legal then
3378 pragma Assert (Present (Encap_Id));
3379 Constits := Part_Of_Constituents (Encap_Id);
3380
3381 if No (Constits) then
3382 Constits := New_Elmt_List;
3383 Set_Part_Of_Constituents (Encap_Id, Constits);
3384 end if;
3385
3386 Append_Elmt (Var_Id, Constits);
3387 Set_Encapsulating_State (Var_Id, Encap_Id);
3388
3389 -- A Part_Of constituent partially refines an abstract state. This
3390 -- property does not apply to protected or task units.
3391
3392 if Ekind (Encap_Id) = E_Abstract_State then
3393 Set_Has_Partial_Visible_Refinement (Encap_Id);
3394 end if;
3395 end if;
3396
3397 -- Emit a clarification message when the encapsulator is undefined,
3398 -- possibly due to contract "freezing".
3399
3400 if Errors /= Serious_Errors_Detected
3401 and then Present (Freeze_Id)
3402 and then Has_Undefined_Reference (Encap)
3403 then
3404 Contract_Freeze_Error (Var_Id, Freeze_Id);
3405 end if;
3406 end Analyze_Part_Of_In_Decl_Part;
3407
3408 --------------------
3409 -- Analyze_Pragma --
3410 --------------------
3411
3412 procedure Analyze_Pragma (N : Node_Id) is
3413 Loc : constant Source_Ptr := Sloc (N);
3414
3415 Pname : Name_Id := Pragma_Name (N);
3416 -- Name of the source pragma, or name of the corresponding aspect for
3417 -- pragmas which originate in a source aspect. In the latter case, the
3418 -- name may be different from the pragma name.
3419
3420 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
3421
3422 Pragma_Exit : exception;
3423 -- This exception is used to exit pragma processing completely. It
3424 -- is used when an error is detected, and no further processing is
3425 -- required. It is also used if an earlier error has left the tree in
3426 -- a state where the pragma should not be processed.
3427
3428 Arg_Count : Nat;
3429 -- Number of pragma argument associations
3430
3431 Arg1 : Node_Id;
3432 Arg2 : Node_Id;
3433 Arg3 : Node_Id;
3434 Arg4 : Node_Id;
3435 -- First four pragma arguments (pragma argument association nodes, or
3436 -- Empty if the corresponding argument does not exist).
3437
3438 type Name_List is array (Natural range <>) of Name_Id;
3439 type Args_List is array (Natural range <>) of Node_Id;
3440 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3441
3442 -----------------------
3443 -- Local Subprograms --
3444 -----------------------
3445
3446 procedure Acquire_Warning_Match_String (Arg : Node_Id);
3447 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3448 -- get the given string argument, and place it in Name_Buffer, adding
3449 -- leading and trailing asterisks if they are not already present. The
3450 -- caller has already checked that Arg is a static string expression.
3451
3452 procedure Ada_2005_Pragma;
3453 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3454 -- Ada 95 mode, these are implementation defined pragmas, so should be
3455 -- caught by the No_Implementation_Pragmas restriction.
3456
3457 procedure Ada_2012_Pragma;
3458 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3459 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3460 -- should be caught by the No_Implementation_Pragmas restriction.
3461
3462 procedure Analyze_Depends_Global
3463 (Spec_Id : out Entity_Id;
3464 Subp_Decl : out Node_Id;
3465 Legal : out Boolean);
3466 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3467 -- legality of the placement and related context of the pragma. Spec_Id
3468 -- is the entity of the related subprogram. Subp_Decl is the declaration
3469 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3470
3471 procedure Analyze_If_Present (Id : Pragma_Id);
3472 -- Inspect the remainder of the list containing pragma N and look for
3473 -- a pragma that matches Id. If found, analyze the pragma.
3474
3475 procedure Analyze_Pre_Post_Condition;
3476 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3477
3478 procedure Analyze_Refined_Depends_Global_Post
3479 (Spec_Id : out Entity_Id;
3480 Body_Id : out Entity_Id;
3481 Legal : out Boolean);
3482 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3483 -- Refined_Global and Refined_Post. Verify the legality of the placement
3484 -- and related context of the pragma. Spec_Id is the entity of the
3485 -- related subprogram. Body_Id is the entity of the subprogram body.
3486 -- Flag Legal is set when the pragma is legal.
3487
3488 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False);
3489 -- Perform full analysis of pragma Unmodified and the write aspect of
3490 -- pragma Unused. Flag Is_Unused should be set when verifying the
3491 -- semantics of pragma Unused.
3492
3493 procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False);
3494 -- Perform full analysis of pragma Unreferenced and the read aspect of
3495 -- pragma Unused. Flag Is_Unused should be set when verifying the
3496 -- semantics of pragma Unused.
3497
3498 procedure Check_Ada_83_Warning;
3499 -- Issues a warning message for the current pragma if operating in Ada
3500 -- 83 mode (used for language pragmas that are not a standard part of
3501 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3502 -- of 95 pragma.
3503
3504 procedure Check_Arg_Count (Required : Nat);
3505 -- Check argument count for pragma is equal to given parameter. If not,
3506 -- then issue an error message and raise Pragma_Exit.
3507
3508 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3509 -- Arg which can either be a pragma argument association, in which case
3510 -- the check is applied to the expression of the association or an
3511 -- expression directly.
3512
3513 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3514 -- Check that an argument has the right form for an EXTERNAL_NAME
3515 -- parameter of an extended import/export pragma. The rule is that the
3516 -- name must be an identifier or string literal (in Ada 83 mode) or a
3517 -- static string expression (in Ada 95 mode).
3518
3519 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3520 -- Check the specified argument Arg to make sure that it is an
3521 -- identifier. If not give error and raise Pragma_Exit.
3522
3523 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3524 -- Check the specified argument Arg to make sure that it is an integer
3525 -- literal. If not give error and raise Pragma_Exit.
3526
3527 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3528 -- Check the specified argument Arg to make sure that it has the proper
3529 -- syntactic form for a local name and meets the semantic requirements
3530 -- for a local name. The local name is analyzed as part of the
3531 -- processing for this call. In addition, the local name is required
3532 -- to represent an entity at the library level.
3533
3534 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3535 -- Check the specified argument Arg to make sure that it has the proper
3536 -- syntactic form for a local name and meets the semantic requirements
3537 -- for a local name. The local name is analyzed as part of the
3538 -- processing for this call.
3539
3540 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3541 -- Check the specified argument Arg to make sure that it is a valid
3542 -- locking policy name. If not give error and raise Pragma_Exit.
3543
3544 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3545 -- Check the specified argument Arg to make sure that it is a valid
3546 -- elaboration policy name. If not give error and raise Pragma_Exit.
3547
3548 procedure Check_Arg_Is_One_Of
3549 (Arg : Node_Id;
3550 N1, N2 : Name_Id);
3551 procedure Check_Arg_Is_One_Of
3552 (Arg : Node_Id;
3553 N1, N2, N3 : Name_Id);
3554 procedure Check_Arg_Is_One_Of
3555 (Arg : Node_Id;
3556 N1, N2, N3, N4 : Name_Id);
3557 procedure Check_Arg_Is_One_Of
3558 (Arg : Node_Id;
3559 N1, N2, N3, N4, N5 : Name_Id);
3560 -- Check the specified argument Arg to make sure that it is an
3561 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3562 -- present). If not then give error and raise Pragma_Exit.
3563
3564 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3565 -- Check the specified argument Arg to make sure that it is a valid
3566 -- queuing policy name. If not give error and raise Pragma_Exit.
3567
3568 procedure Check_Arg_Is_OK_Static_Expression
3569 (Arg : Node_Id;
3570 Typ : Entity_Id := Empty);
3571 -- Check the specified argument Arg to make sure that it is a static
3572 -- expression of the given type (i.e. it will be analyzed and resolved
3573 -- using this type, which can be any valid argument to Resolve, e.g.
3574 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3575 -- Typ is left Empty, then any static expression is allowed. Includes
3576 -- checking that the argument does not raise Constraint_Error.
3577
3578 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3579 -- Check the specified argument Arg to make sure that it is a valid task
3580 -- dispatching policy name. If not give error and raise Pragma_Exit.
3581
3582 procedure Check_Arg_Order (Names : Name_List);
3583 -- Checks for an instance of two arguments with identifiers for the
3584 -- current pragma which are not in the sequence indicated by Names,
3585 -- and if so, generates a fatal message about bad order of arguments.
3586
3587 procedure Check_At_Least_N_Arguments (N : Nat);
3588 -- Check there are at least N arguments present
3589
3590 procedure Check_At_Most_N_Arguments (N : Nat);
3591 -- Check there are no more than N arguments present
3592
3593 procedure Check_Component
3594 (Comp : Node_Id;
3595 UU_Typ : Entity_Id;
3596 In_Variant_Part : Boolean := False);
3597 -- Examine an Unchecked_Union component for correct use of per-object
3598 -- constrained subtypes, and for restrictions on finalizable components.
3599 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3600 -- should be set when Comp comes from a record variant.
3601
3602 procedure Check_Duplicate_Pragma (E : Entity_Id);
3603 -- Check if a rep item of the same name as the current pragma is already
3604 -- chained as a rep pragma to the given entity. If so give a message
3605 -- about the duplicate, and then raise Pragma_Exit so does not return.
3606 -- Note that if E is a type, then this routine avoids flagging a pragma
3607 -- which applies to a parent type from which E is derived.
3608
3609 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3610 -- Nam is an N_String_Literal node containing the external name set by
3611 -- an Import or Export pragma (or extended Import or Export pragma).
3612 -- This procedure checks for possible duplications if this is the export
3613 -- case, and if found, issues an appropriate error message.
3614
3615 procedure Check_Expr_Is_OK_Static_Expression
3616 (Expr : Node_Id;
3617 Typ : Entity_Id := Empty);
3618 -- Check the specified expression Expr to make sure that it is a static
3619 -- expression of the given type (i.e. it will be analyzed and resolved
3620 -- using this type, which can be any valid argument to Resolve, e.g.
3621 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3622 -- Typ is left Empty, then any static expression is allowed. Includes
3623 -- checking that the expression does not raise Constraint_Error.
3624
3625 procedure Check_First_Subtype (Arg : Node_Id);
3626 -- Checks that Arg, whose expression is an entity name, references a
3627 -- first subtype.
3628
3629 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3630 -- Checks that the given argument has an identifier, and if so, requires
3631 -- it to match the given identifier name. If there is no identifier, or
3632 -- a non-matching identifier, then an error message is given and
3633 -- Pragma_Exit is raised.
3634
3635 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3636 -- Checks that the given argument has an identifier, and if so, requires
3637 -- it to match one of the given identifier names. If there is no
3638 -- identifier, or a non-matching identifier, then an error message is
3639 -- given and Pragma_Exit is raised.
3640
3641 procedure Check_In_Main_Program;
3642 -- Common checks for pragmas that appear within a main program
3643 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3644
3645 procedure Check_Interrupt_Or_Attach_Handler;
3646 -- Common processing for first argument of pragma Interrupt_Handler or
3647 -- pragma Attach_Handler.
3648
3649 procedure Check_Loop_Pragma_Placement;
3650 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3651 -- appear immediately within a construct restricted to loops, and that
3652 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3653
3654 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
3655 -- Check that pragma appears in a declarative part, or in a package
3656 -- specification, i.e. that it does not occur in a statement sequence
3657 -- in a body.
3658
3659 procedure Check_No_Identifier (Arg : Node_Id);
3660 -- Checks that the given argument does not have an identifier. If
3661 -- an identifier is present, then an error message is issued, and
3662 -- Pragma_Exit is raised.
3663
3664 procedure Check_No_Identifiers;
3665 -- Checks that none of the arguments to the pragma has an identifier.
3666 -- If any argument has an identifier, then an error message is issued,
3667 -- and Pragma_Exit is raised.
3668
3669 procedure Check_No_Link_Name;
3670 -- Checks that no link name is specified
3671
3672 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3673 -- Checks if the given argument has an identifier, and if so, requires
3674 -- it to match the given identifier name. If there is a non-matching
3675 -- identifier, then an error message is given and Pragma_Exit is raised.
3676
3677 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3678 -- Checks if the given argument has an identifier, and if so, requires
3679 -- it to match the given identifier name. If there is a non-matching
3680 -- identifier, then an error message is given and Pragma_Exit is raised.
3681 -- In this version of the procedure, the identifier name is given as
3682 -- a string with lower case letters.
3683
3684 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
3685 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3686 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3687 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3688 -- is an OK static boolean expression. Emit an error if this is not the
3689 -- case.
3690
3691 procedure Check_Static_Constraint (Constr : Node_Id);
3692 -- Constr is a constraint from an N_Subtype_Indication node from a
3693 -- component constraint in an Unchecked_Union type. This routine checks
3694 -- that the constraint is static as required by the restrictions for
3695 -- Unchecked_Union.
3696
3697 procedure Check_Valid_Configuration_Pragma;
3698 -- Legality checks for placement of a configuration pragma
3699
3700 procedure Check_Valid_Library_Unit_Pragma;
3701 -- Legality checks for library unit pragmas. A special case arises for
3702 -- pragmas in generic instances that come from copies of the original
3703 -- library unit pragmas in the generic templates. In the case of other
3704 -- than library level instantiations these can appear in contexts which
3705 -- would normally be invalid (they only apply to the original template
3706 -- and to library level instantiations), and they are simply ignored,
3707 -- which is implemented by rewriting them as null statements.
3708
3709 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3710 -- Check an Unchecked_Union variant for lack of nested variants and
3711 -- presence of at least one component. UU_Typ is the related Unchecked_
3712 -- Union type.
3713
3714 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3715 -- Subsidiary routine to the processing of pragmas Abstract_State,
3716 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3717 -- Refined_Global and Refined_State. Transform argument Arg into
3718 -- an aggregate if not one already. N_Null is never transformed.
3719 -- Arg may denote an aspect specification or a pragma argument
3720 -- association.
3721
3722 procedure Error_Pragma (Msg : String);
3723 pragma No_Return (Error_Pragma);
3724 -- Outputs error message for current pragma. The message contains a %
3725 -- that will be replaced with the pragma name, and the flag is placed
3726 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3727 -- calls Fix_Error (see spec of that procedure for details).
3728
3729 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3730 pragma No_Return (Error_Pragma_Arg);
3731 -- Outputs error message for current pragma. The message may contain
3732 -- a % that will be replaced with the pragma name. The parameter Arg
3733 -- may either be a pragma argument association, in which case the flag
3734 -- is placed on the expression of this association, or an expression,
3735 -- in which case the flag is placed directly on the expression. The
3736 -- message is placed using Error_Msg_N, so the message may also contain
3737 -- an & insertion character which will reference the given Arg value.
3738 -- After placing the message, Pragma_Exit is raised. Note: this routine
3739 -- calls Fix_Error (see spec of that procedure for details).
3740
3741 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3742 pragma No_Return (Error_Pragma_Arg);
3743 -- Similar to above form of Error_Pragma_Arg except that two messages
3744 -- are provided, the second is a continuation comment starting with \.
3745
3746 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3747 pragma No_Return (Error_Pragma_Arg_Ident);
3748 -- Outputs error message for current pragma. The message may contain a %
3749 -- that will be replaced with the pragma name. The parameter Arg must be
3750 -- a pragma argument association with a non-empty identifier (i.e. its
3751 -- Chars field must be set), and the error message is placed on the
3752 -- identifier. The message is placed using Error_Msg_N so the message
3753 -- may also contain an & insertion character which will reference
3754 -- the identifier. After placing the message, Pragma_Exit is raised.
3755 -- Note: this routine calls Fix_Error (see spec of that procedure for
3756 -- details).
3757
3758 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3759 pragma No_Return (Error_Pragma_Ref);
3760 -- Outputs error message for current pragma. The message may contain
3761 -- a % that will be replaced with the pragma name. The parameter Ref
3762 -- must be an entity whose name can be referenced by & and sloc by #.
3763 -- After placing the message, Pragma_Exit is raised. Note: this routine
3764 -- calls Fix_Error (see spec of that procedure for details).
3765
3766 function Find_Lib_Unit_Name return Entity_Id;
3767 -- Used for a library unit pragma to find the entity to which the
3768 -- library unit pragma applies, returns the entity found.
3769
3770 procedure Find_Program_Unit_Name (Id : Node_Id);
3771 -- If the pragma is a compilation unit pragma, the id must denote the
3772 -- compilation unit in the same compilation, and the pragma must appear
3773 -- in the list of preceding or trailing pragmas. If it is a program
3774 -- unit pragma that is not a compilation unit pragma, then the
3775 -- identifier must be visible.
3776
3777 function Find_Unique_Parameterless_Procedure
3778 (Name : Entity_Id;
3779 Arg : Node_Id) return Entity_Id;
3780 -- Used for a procedure pragma to find the unique parameterless
3781 -- procedure identified by Name, returns it if it exists, otherwise
3782 -- errors out and uses Arg as the pragma argument for the message.
3783
3784 function Fix_Error (Msg : String) return String;
3785 -- This is called prior to issuing an error message. Msg is the normal
3786 -- error message issued in the pragma case. This routine checks for the
3787 -- case of a pragma coming from an aspect in the source, and returns a
3788 -- message suitable for the aspect case as follows:
3789 --
3790 -- Each substring "pragma" is replaced by "aspect"
3791 --
3792 -- If "argument of" is at the start of the error message text, it is
3793 -- replaced by "entity for".
3794 --
3795 -- If "argument" is at the start of the error message text, it is
3796 -- replaced by "entity".
3797 --
3798 -- So for example, "argument of pragma X must be discrete type"
3799 -- returns "entity for aspect X must be a discrete type".
3800
3801 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3802 -- be different from the pragma name). If the current pragma results
3803 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3804 -- original pragma name.
3805
3806 procedure Gather_Associations
3807 (Names : Name_List;
3808 Args : out Args_List);
3809 -- This procedure is used to gather the arguments for a pragma that
3810 -- permits arbitrary ordering of parameters using the normal rules
3811 -- for named and positional parameters. The Names argument is a list
3812 -- of Name_Id values that corresponds to the allowed pragma argument
3813 -- association identifiers in order. The result returned in Args is
3814 -- a list of corresponding expressions that are the pragma arguments.
3815 -- Note that this is a list of expressions, not of pragma argument
3816 -- associations (Gather_Associations has completely checked all the
3817 -- optional identifiers when it returns). An entry in Args is Empty
3818 -- on return if the corresponding argument is not present.
3819
3820 procedure GNAT_Pragma;
3821 -- Called for all GNAT defined pragmas to check the relevant restriction
3822 -- (No_Implementation_Pragmas).
3823
3824 function Is_Before_First_Decl
3825 (Pragma_Node : Node_Id;
3826 Decls : List_Id) return Boolean;
3827 -- Return True if Pragma_Node is before the first declarative item in
3828 -- Decls where Decls is the list of declarative items.
3829
3830 function Is_Configuration_Pragma return Boolean;
3831 -- Determines if the placement of the current pragma is appropriate
3832 -- for a configuration pragma.
3833
3834 function Is_In_Context_Clause return Boolean;
3835 -- Returns True if pragma appears within the context clause of a unit,
3836 -- and False for any other placement (does not generate any messages).
3837
3838 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3839 -- Analyzes the argument, and determines if it is a static string
3840 -- expression, returns True if so, False if non-static or not String.
3841 -- A special case is that a string literal returns True in Ada 83 mode
3842 -- (which has no such thing as static string expressions). Note that
3843 -- the call analyzes its argument, so this cannot be used for the case
3844 -- where an identifier might not be declared.
3845
3846 procedure Pragma_Misplaced;
3847 pragma No_Return (Pragma_Misplaced);
3848 -- Issue fatal error message for misplaced pragma
3849
3850 procedure Process_Atomic_Independent_Shared_Volatile;
3851 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3852 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3853 -- and treated as being identical in effect to pragma Atomic.
3854
3855 procedure Process_Compile_Time_Warning_Or_Error;
3856 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3857
3858 procedure Process_Convention
3859 (C : out Convention_Id;
3860 Ent : out Entity_Id);
3861 -- Common processing for Convention, Interface, Import and Export.
3862 -- Checks first two arguments of pragma, and sets the appropriate
3863 -- convention value in the specified entity or entities. On return
3864 -- C is the convention, Ent is the referenced entity.
3865
3866 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3867 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3868 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3869
3870 procedure Process_Extended_Import_Export_Object_Pragma
3871 (Arg_Internal : Node_Id;
3872 Arg_External : Node_Id;
3873 Arg_Size : Node_Id);
3874 -- Common processing for the pragmas Import/Export_Object. The three
3875 -- arguments correspond to the three named parameters of the pragmas. An
3876 -- argument is empty if the corresponding parameter is not present in
3877 -- the pragma.
3878
3879 procedure Process_Extended_Import_Export_Internal_Arg
3880 (Arg_Internal : Node_Id := Empty);
3881 -- Common processing for all extended Import and Export pragmas. The
3882 -- argument is the pragma parameter for the Internal argument. If
3883 -- Arg_Internal is empty or inappropriate, an error message is posted.
3884 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3885 -- set to identify the referenced entity.
3886
3887 procedure Process_Extended_Import_Export_Subprogram_Pragma
3888 (Arg_Internal : Node_Id;
3889 Arg_External : Node_Id;
3890 Arg_Parameter_Types : Node_Id;
3891 Arg_Result_Type : Node_Id := Empty;
3892 Arg_Mechanism : Node_Id;
3893 Arg_Result_Mechanism : Node_Id := Empty);
3894 -- Common processing for all extended Import and Export pragmas applying
3895 -- to subprograms. The caller omits any arguments that do not apply to
3896 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3897 -- only in the Import_Function and Export_Function cases). The argument
3898 -- names correspond to the allowed pragma association identifiers.
3899
3900 procedure Process_Generic_List;
3901 -- Common processing for Share_Generic and Inline_Generic
3902
3903 procedure Process_Import_Or_Interface;
3904 -- Common processing for Import or Interface
3905
3906 procedure Process_Import_Predefined_Type;
3907 -- Processing for completing a type with pragma Import. This is used
3908 -- to declare types that match predefined C types, especially for cases
3909 -- without corresponding Ada predefined type.
3910
3911 type Inline_Status is (Suppressed, Disabled, Enabled);
3912 -- Inline status of a subprogram, indicated as follows:
3913 -- Suppressed: inlining is suppressed for the subprogram
3914 -- Disabled: no inlining is requested for the subprogram
3915 -- Enabled: inlining is requested/required for the subprogram
3916
3917 procedure Process_Inline (Status : Inline_Status);
3918 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
3919 -- indicates the inline status specified by the pragma.
3920
3921 procedure Process_Interface_Name
3922 (Subprogram_Def : Entity_Id;
3923 Ext_Arg : Node_Id;
3924 Link_Arg : Node_Id;
3925 Prag : Node_Id);
3926 -- Given the last two arguments of pragma Import, pragma Export, or
3927 -- pragma Interface_Name, performs validity checks and sets the
3928 -- Interface_Name field of the given subprogram entity to the
3929 -- appropriate external or link name, depending on the arguments given.
3930 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3931 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3932 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3933 -- nor Link_Arg is present, the interface name is set to the default
3934 -- from the subprogram name. In addition, the pragma itself is passed
3935 -- to analyze any expressions in the case the pragma came from an aspect
3936 -- specification.
3937
3938 procedure Process_Interrupt_Or_Attach_Handler;
3939 -- Common processing for Interrupt and Attach_Handler pragmas
3940
3941 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3942 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3943 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3944 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3945 -- is not set in the Restrictions case.
3946
3947 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3948 -- Common processing for Suppress and Unsuppress. The boolean parameter
3949 -- Suppress_Case is True for the Suppress case, and False for the
3950 -- Unsuppress case.
3951
3952 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
3953 -- Subsidiary to the analysis of pragmas Independent[_Components].
3954 -- Record such a pragma N applied to entity E for future checks.
3955
3956 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3957 -- This procedure sets the Is_Exported flag for the given entity,
3958 -- checking that the entity was not previously imported. Arg is
3959 -- the argument that specified the entity. A check is also made
3960 -- for exporting inappropriate entities.
3961
3962 procedure Set_Extended_Import_Export_External_Name
3963 (Internal_Ent : Entity_Id;
3964 Arg_External : Node_Id);
3965 -- Common processing for all extended import export pragmas. The first
3966 -- argument, Internal_Ent, is the internal entity, which has already
3967 -- been checked for validity by the caller. Arg_External is from the
3968 -- Import or Export pragma, and may be null if no External parameter
3969 -- was present. If Arg_External is present and is a non-null string
3970 -- (a null string is treated as the default), then the Interface_Name
3971 -- field of Internal_Ent is set appropriately.
3972
3973 procedure Set_Imported (E : Entity_Id);
3974 -- This procedure sets the Is_Imported flag for the given entity,
3975 -- checking that it is not previously exported or imported.
3976
3977 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3978 -- Mech is a parameter passing mechanism (see Import_Function syntax
3979 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3980 -- has the right form, and if not issues an error message. If the
3981 -- argument has the right form then the Mechanism field of Ent is
3982 -- set appropriately.
3983
3984 procedure Set_Rational_Profile;
3985 -- Activate the set of configuration pragmas and permissions that make
3986 -- up the Rational profile.
3987
3988 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
3989 -- Activate the set of configuration pragmas and restrictions that make
3990 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
3991 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
3992 -- which is used for error messages on any constructs violating the
3993 -- profile.
3994
3995 ----------------------------------
3996 -- Acquire_Warning_Match_String --
3997 ----------------------------------
3998
3999 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
4000 begin
4001 String_To_Name_Buffer
4002 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
4003
4004 -- Add asterisk at start if not already there
4005
4006 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
4007 Name_Buffer (2 .. Name_Len + 1) :=
4008 Name_Buffer (1 .. Name_Len);
4009 Name_Buffer (1) := '*';
4010 Name_Len := Name_Len + 1;
4011 end if;
4012
4013 -- Add asterisk at end if not already there
4014
4015 if Name_Buffer (Name_Len) /= '*' then
4016 Name_Len := Name_Len + 1;
4017 Name_Buffer (Name_Len) := '*';
4018 end if;
4019 end Acquire_Warning_Match_String;
4020
4021 ---------------------
4022 -- Ada_2005_Pragma --
4023 ---------------------
4024
4025 procedure Ada_2005_Pragma is
4026 begin
4027 if Ada_Version <= Ada_95 then
4028 Check_Restriction (No_Implementation_Pragmas, N);
4029 end if;
4030 end Ada_2005_Pragma;
4031
4032 ---------------------
4033 -- Ada_2012_Pragma --
4034 ---------------------
4035
4036 procedure Ada_2012_Pragma is
4037 begin
4038 if Ada_Version <= Ada_2005 then
4039 Check_Restriction (No_Implementation_Pragmas, N);
4040 end if;
4041 end Ada_2012_Pragma;
4042
4043 ----------------------------
4044 -- Analyze_Depends_Global --
4045 ----------------------------
4046
4047 procedure Analyze_Depends_Global
4048 (Spec_Id : out Entity_Id;
4049 Subp_Decl : out Node_Id;
4050 Legal : out Boolean)
4051 is
4052 begin
4053 -- Assume that the pragma is illegal
4054
4055 Spec_Id := Empty;
4056 Subp_Decl := Empty;
4057 Legal := False;
4058
4059 GNAT_Pragma;
4060 Check_Arg_Count (1);
4061
4062 -- Ensure the proper placement of the pragma. Depends/Global must be
4063 -- associated with a subprogram declaration or a body that acts as a
4064 -- spec.
4065
4066 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4067
4068 -- Entry
4069
4070 if Nkind (Subp_Decl) = N_Entry_Declaration then
4071 null;
4072
4073 -- Generic subprogram
4074
4075 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4076 null;
4077
4078 -- Object declaration of a single concurrent type
4079
4080 elsif Nkind (Subp_Decl) = N_Object_Declaration then
4081 null;
4082
4083 -- Single task type
4084
4085 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4086 null;
4087
4088 -- Subprogram body acts as spec
4089
4090 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4091 and then No (Corresponding_Spec (Subp_Decl))
4092 then
4093 null;
4094
4095 -- Subprogram body stub acts as spec
4096
4097 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4098 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4099 then
4100 null;
4101
4102 -- Subprogram declaration
4103
4104 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4105 null;
4106
4107 -- Task type
4108
4109 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4110 null;
4111
4112 else
4113 Pragma_Misplaced;
4114 return;
4115 end if;
4116
4117 -- If we get here, then the pragma is legal
4118
4119 Legal := True;
4120 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4121
4122 -- When the related context is an entry, the entry must belong to a
4123 -- protected unit (SPARK RM 6.1.4(6)).
4124
4125 if Is_Entry_Declaration (Spec_Id)
4126 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4127 then
4128 Pragma_Misplaced;
4129 return;
4130
4131 -- When the related context is an anonymous object created for a
4132 -- simple concurrent type, the type must be a task
4133 -- (SPARK RM 6.1.4(6)).
4134
4135 elsif Is_Single_Concurrent_Object (Spec_Id)
4136 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4137 then
4138 Pragma_Misplaced;
4139 return;
4140 end if;
4141
4142 -- A pragma that applies to a Ghost entity becomes Ghost for the
4143 -- purposes of legality checks and removal of ignored Ghost code.
4144
4145 Mark_Ghost_Pragma (N, Spec_Id);
4146 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4147 end Analyze_Depends_Global;
4148
4149 ------------------------
4150 -- Analyze_If_Present --
4151 ------------------------
4152
4153 procedure Analyze_If_Present (Id : Pragma_Id) is
4154 Stmt : Node_Id;
4155
4156 begin
4157 pragma Assert (Is_List_Member (N));
4158
4159 -- Inspect the declarations or statements following pragma N looking
4160 -- for another pragma whose Id matches the caller's request. If it is
4161 -- available, analyze it.
4162
4163 Stmt := Next (N);
4164 while Present (Stmt) loop
4165 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4166 Analyze_Pragma (Stmt);
4167 exit;
4168
4169 -- The first source declaration or statement immediately following
4170 -- N ends the region where a pragma may appear.
4171
4172 elsif Comes_From_Source (Stmt) then
4173 exit;
4174 end if;
4175
4176 Next (Stmt);
4177 end loop;
4178 end Analyze_If_Present;
4179
4180 --------------------------------
4181 -- Analyze_Pre_Post_Condition --
4182 --------------------------------
4183
4184 procedure Analyze_Pre_Post_Condition is
4185 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4186 Subp_Decl : Node_Id;
4187 Subp_Id : Entity_Id;
4188
4189 Duplicates_OK : Boolean := False;
4190 -- Flag set when a pre/postcondition allows multiple pragmas of the
4191 -- same kind.
4192
4193 In_Body_OK : Boolean := False;
4194 -- Flag set when a pre/postcondition is allowed to appear on a body
4195 -- even though the subprogram may have a spec.
4196
4197 Is_Pre_Post : Boolean := False;
4198 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4199 -- Post_Class.
4200
4201 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean;
4202 -- Implement rules in AI12-0131: an overriding operation can have
4203 -- a class-wide precondition only if one of its ancestors has an
4204 -- explicit class-wide precondition.
4205
4206 -----------------------------
4207 -- Inherits_Class_Wide_Pre --
4208 -----------------------------
4209
4210 function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is
4211 Typ : constant Entity_Id := Find_Dispatching_Type (E);
4212 Cont : Node_Id;
4213 Prag : Node_Id;
4214 Prev : Entity_Id := Overridden_Operation (E);
4215
4216 begin
4217 -- Check ancestors on the overriding operation to examine the
4218 -- preconditions that may apply to them.
4219
4220 while Present (Prev) loop
4221 Cont := Contract (Prev);
4222 if Present (Cont) then
4223 Prag := Pre_Post_Conditions (Cont);
4224 while Present (Prag) loop
4225 if Class_Present (Prag) then
4226 return True;
4227 end if;
4228
4229 Prag := Next_Pragma (Prag);
4230 end loop;
4231 end if;
4232
4233 -- For a type derived from a generic formal type, the operation
4234 -- inheriting the condition is a renaming, not an overriding of
4235 -- the operation of the formal.
4236
4237 if Is_Generic_Type (Find_Dispatching_Type (Prev)) then
4238 Prev := Alias (Prev);
4239 else
4240 Prev := Overridden_Operation (Prev);
4241 end if;
4242 end loop;
4243
4244 -- If the controlling type of the subprogram has progenitors, an
4245 -- interface operation implemented by the current operation may
4246 -- have a class-wide precondition.
4247
4248 if Has_Interfaces (Typ) then
4249 declare
4250 Elmt : Elmt_Id;
4251 Ints : Elist_Id;
4252 Prim : Entity_Id;
4253 Prim_Elmt : Elmt_Id;
4254 Prim_List : Elist_Id;
4255
4256 begin
4257 Collect_Interfaces (Typ, Ints);
4258 Elmt := First_Elmt (Ints);
4259
4260 -- Iterate over the primitive operations of each interface
4261
4262 while Present (Elmt) loop
4263 Prim_List := Direct_Primitive_Operations (Node (Elmt));
4264 Prim_Elmt := First_Elmt (Prim_List);
4265 while Present (Prim_Elmt) loop
4266 Prim := Node (Prim_Elmt);
4267 if Chars (Prim) = Chars (E)
4268 and then Present (Contract (Prim))
4269 and then Class_Present
4270 (Pre_Post_Conditions (Contract (Prim)))
4271 then
4272 return True;
4273 end if;
4274
4275 Next_Elmt (Prim_Elmt);
4276 end loop;
4277
4278 Next_Elmt (Elmt);
4279 end loop;
4280 end;
4281 end if;
4282
4283 return False;
4284 end Inherits_Class_Wide_Pre;
4285
4286 -- Start of processing for Analyze_Pre_Post_Condition
4287
4288 begin
4289 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4290 -- offer uniformity among the various kinds of pre/postconditions by
4291 -- rewriting the pragma identifier. This allows the retrieval of the
4292 -- original pragma name by routine Original_Aspect_Pragma_Name.
4293
4294 if Comes_From_Source (N) then
4295 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4296 Is_Pre_Post := True;
4297 Set_Class_Present (N, Pname = Name_Pre_Class);
4298 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4299
4300 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4301 Is_Pre_Post := True;
4302 Set_Class_Present (N, Pname = Name_Post_Class);
4303 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4304 end if;
4305 end if;
4306
4307 -- Determine the semantics with respect to duplicates and placement
4308 -- in a body. Pragmas Precondition and Postcondition were introduced
4309 -- before aspects and are not subject to the same aspect-like rules.
4310
4311 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4312 Duplicates_OK := True;
4313 In_Body_OK := True;
4314 end if;
4315
4316 GNAT_Pragma;
4317
4318 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4319 -- argument without an identifier.
4320
4321 if Is_Pre_Post then
4322 Check_Arg_Count (1);
4323 Check_No_Identifiers;
4324
4325 -- Pragmas Precondition and Postcondition have complex argument
4326 -- profile.
4327
4328 else
4329 Check_At_Least_N_Arguments (1);
4330 Check_At_Most_N_Arguments (2);
4331 Check_Optional_Identifier (Arg1, Name_Check);
4332
4333 if Present (Arg2) then
4334 Check_Optional_Identifier (Arg2, Name_Message);
4335 Preanalyze_Spec_Expression
4336 (Get_Pragma_Arg (Arg2), Standard_String);
4337 end if;
4338 end if;
4339
4340 -- For a pragma PPC in the extended main source unit, record enabled
4341 -- status in SCO.
4342 -- ??? nothing checks that the pragma is in the main source unit
4343
4344 if Is_Checked (N) and then not Split_PPC (N) then
4345 Set_SCO_Pragma_Enabled (Loc);
4346 end if;
4347
4348 -- Ensure the proper placement of the pragma
4349
4350 Subp_Decl :=
4351 Find_Related_Declaration_Or_Body
4352 (N, Do_Checks => not Duplicates_OK);
4353
4354 -- When a pre/postcondition pragma applies to an abstract subprogram,
4355 -- its original form must be an aspect with 'Class.
4356
4357 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4358 if not From_Aspect_Specification (N) then
4359 Error_Pragma
4360 ("pragma % cannot be applied to abstract subprogram");
4361
4362 elsif not Class_Present (N) then
4363 Error_Pragma
4364 ("aspect % requires ''Class for abstract subprogram");
4365 end if;
4366
4367 -- Entry declaration
4368
4369 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4370 null;
4371
4372 -- Generic subprogram declaration
4373
4374 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4375 null;
4376
4377 -- Subprogram body
4378
4379 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4380 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4381 then
4382 null;
4383
4384 -- Subprogram body stub
4385
4386 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4387 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4388 then
4389 null;
4390
4391 -- Subprogram declaration
4392
4393 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4394
4395 -- AI05-0230: When a pre/postcondition pragma applies to a null
4396 -- procedure, its original form must be an aspect with 'Class.
4397
4398 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4399 and then Null_Present (Specification (Subp_Decl))
4400 and then From_Aspect_Specification (N)
4401 and then not Class_Present (N)
4402 then
4403 Error_Pragma ("aspect % requires ''Class for null procedure");
4404 end if;
4405
4406 -- Implement the legality checks mandated by AI12-0131:
4407 -- Pre'Class shall not be specified for an overriding primitive
4408 -- subprogram of a tagged type T unless the Pre'Class aspect is
4409 -- specified for the corresponding primitive subprogram of some
4410 -- ancestor of T.
4411
4412 declare
4413 E : constant Entity_Id := Defining_Entity (Subp_Decl);
4414
4415 begin
4416 if Class_Present (N)
4417 and then Pragma_Name (N) = Name_Precondition
4418 and then Present (Overridden_Operation (E))
4419 and then not Inherits_Class_Wide_Pre (E)
4420 then
4421 Error_Msg_N
4422 ("illegal class-wide precondition on overriding operation",
4423 Corresponding_Aspect (N));
4424 end if;
4425 end;
4426
4427 -- Otherwise the placement is illegal
4428
4429 else
4430 Pragma_Misplaced;
4431 return;
4432 end if;
4433
4434 Subp_Id := Defining_Entity (Subp_Decl);
4435
4436 -- A pragma that applies to a Ghost entity becomes Ghost for the
4437 -- purposes of legality checks and removal of ignored Ghost code.
4438
4439 Mark_Ghost_Pragma (N, Subp_Id);
4440
4441 -- Chain the pragma on the contract for further processing by
4442 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4443
4444 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4445
4446 -- Fully analyze the pragma when it appears inside an entry or
4447 -- subprogram body because it cannot benefit from forward references.
4448
4449 if Nkind_In (Subp_Decl, N_Entry_Body,
4450 N_Subprogram_Body,
4451 N_Subprogram_Body_Stub)
4452 then
4453 -- The legality checks of pragmas Precondition and Postcondition
4454 -- are affected by the SPARK mode in effect and the volatility of
4455 -- the context. Analyze all pragmas in a specific order.
4456
4457 Analyze_If_Present (Pragma_SPARK_Mode);
4458 Analyze_If_Present (Pragma_Volatile_Function);
4459 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4460 end if;
4461 end Analyze_Pre_Post_Condition;
4462
4463 -----------------------------------------
4464 -- Analyze_Refined_Depends_Global_Post --
4465 -----------------------------------------
4466
4467 procedure Analyze_Refined_Depends_Global_Post
4468 (Spec_Id : out Entity_Id;
4469 Body_Id : out Entity_Id;
4470 Legal : out Boolean)
4471 is
4472 Body_Decl : Node_Id;
4473 Spec_Decl : Node_Id;
4474
4475 begin
4476 -- Assume that the pragma is illegal
4477
4478 Spec_Id := Empty;
4479 Body_Id := Empty;
4480 Legal := False;
4481
4482 GNAT_Pragma;
4483 Check_Arg_Count (1);
4484 Check_No_Identifiers;
4485
4486 -- Verify the placement of the pragma and check for duplicates. The
4487 -- pragma must apply to a subprogram body [stub].
4488
4489 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4490
4491 -- Entry body
4492
4493 if Nkind (Body_Decl) = N_Entry_Body then
4494 null;
4495
4496 -- Subprogram body
4497
4498 elsif Nkind (Body_Decl) = N_Subprogram_Body then
4499 null;
4500
4501 -- Subprogram body stub
4502
4503 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
4504 null;
4505
4506 -- Task body
4507
4508 elsif Nkind (Body_Decl) = N_Task_Body then
4509 null;
4510
4511 else
4512 Pragma_Misplaced;
4513 return;
4514 end if;
4515
4516 Body_Id := Defining_Entity (Body_Decl);
4517 Spec_Id := Unique_Defining_Entity (Body_Decl);
4518
4519 -- The pragma must apply to the second declaration of a subprogram.
4520 -- In other words, the body [stub] cannot acts as a spec.
4521
4522 if No (Spec_Id) then
4523 Error_Pragma ("pragma % cannot apply to a stand alone body");
4524 return;
4525
4526 -- Catch the case where the subprogram body is a subunit and acts as
4527 -- the third declaration of the subprogram.
4528
4529 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4530 Error_Pragma ("pragma % cannot apply to a subunit");
4531 return;
4532 end if;
4533
4534 -- A refined pragma can only apply to the body [stub] of a subprogram
4535 -- declared in the visible part of a package. Retrieve the context of
4536 -- the subprogram declaration.
4537
4538 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4539
4540 -- When dealing with protected entries or protected subprograms, use
4541 -- the enclosing protected type as the proper context.
4542
4543 if Ekind_In (Spec_Id, E_Entry,
4544 E_Entry_Family,
4545 E_Function,
4546 E_Procedure)
4547 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4548 then
4549 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4550 end if;
4551
4552 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4553 Error_Pragma
4554 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4555 & "subprogram declared in a package specification"));
4556 return;
4557 end if;
4558
4559 -- If we get here, then the pragma is legal
4560
4561 Legal := True;
4562
4563 -- A pragma that applies to a Ghost entity becomes Ghost for the
4564 -- purposes of legality checks and removal of ignored Ghost code.
4565
4566 Mark_Ghost_Pragma (N, Spec_Id);
4567
4568 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4569 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4570 end if;
4571 end Analyze_Refined_Depends_Global_Post;
4572
4573 ----------------------------------
4574 -- Analyze_Unmodified_Or_Unused --
4575 ----------------------------------
4576
4577 procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is
4578 Arg : Node_Id;
4579 Arg_Expr : Node_Id;
4580 Arg_Id : Entity_Id;
4581
4582 Ghost_Error_Posted : Boolean := False;
4583 -- Flag set when an error concerning the illegal mix of Ghost and
4584 -- non-Ghost variables is emitted.
4585
4586 Ghost_Id : Entity_Id := Empty;
4587 -- The entity of the first Ghost variable encountered while
4588 -- processing the arguments of the pragma.
4589
4590 begin
4591 GNAT_Pragma;
4592 Check_At_Least_N_Arguments (1);
4593
4594 -- Loop through arguments
4595
4596 Arg := Arg1;
4597 while Present (Arg) loop
4598 Check_No_Identifier (Arg);
4599
4600 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4601 -- in fact generate reference, so that the entity will have a
4602 -- reference, which will inhibit any warnings about it not
4603 -- being referenced, and also properly show up in the ali file
4604 -- as a reference. But this reference is recorded before the
4605 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4606 -- generated for this reference.
4607
4608 Check_Arg_Is_Local_Name (Arg);
4609 Arg_Expr := Get_Pragma_Arg (Arg);
4610
4611 if Is_Entity_Name (Arg_Expr) then
4612 Arg_Id := Entity (Arg_Expr);
4613
4614 -- Skip processing the argument if already flagged
4615
4616 if Is_Assignable (Arg_Id)
4617 and then not Has_Pragma_Unmodified (Arg_Id)
4618 and then not Has_Pragma_Unused (Arg_Id)
4619 then
4620 Set_Has_Pragma_Unmodified (Arg_Id);
4621
4622 if Is_Unused then
4623 Set_Has_Pragma_Unused (Arg_Id);
4624 end if;
4625
4626 -- A pragma that applies to a Ghost entity becomes Ghost for
4627 -- the purposes of legality checks and removal of ignored
4628 -- Ghost code.
4629
4630 Mark_Ghost_Pragma (N, Arg_Id);
4631
4632 -- Capture the entity of the first Ghost variable being
4633 -- processed for error detection purposes.
4634
4635 if Is_Ghost_Entity (Arg_Id) then
4636 if No (Ghost_Id) then
4637 Ghost_Id := Arg_Id;
4638 end if;
4639
4640 -- Otherwise the variable is non-Ghost. It is illegal to mix
4641 -- references to Ghost and non-Ghost entities
4642 -- (SPARK RM 6.9).
4643
4644 elsif Present (Ghost_Id)
4645 and then not Ghost_Error_Posted
4646 then
4647 Ghost_Error_Posted := True;
4648
4649 Error_Msg_Name_1 := Pname;
4650 Error_Msg_N
4651 ("pragma % cannot mention ghost and non-ghost "
4652 & "variables", N);
4653
4654 Error_Msg_Sloc := Sloc (Ghost_Id);
4655 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
4656
4657 Error_Msg_Sloc := Sloc (Arg_Id);
4658 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
4659 end if;
4660
4661 -- Warn if already flagged as Unused or Unmodified
4662
4663 elsif Has_Pragma_Unmodified (Arg_Id) then
4664 if Has_Pragma_Unused (Arg_Id) then
4665 Error_Msg_NE
4666 ("??pragma Unused already given for &!", Arg_Expr,
4667 Arg_Id);
4668 else
4669 Error_Msg_NE
4670 ("??pragma Unmodified already given for &!", Arg_Expr,
4671 Arg_Id);
4672 end if;
4673
4674 -- Otherwise the pragma referenced an illegal entity
4675
4676 else
4677 Error_Pragma_Arg
4678 ("pragma% can only be applied to a variable", Arg_Expr);
4679 end if;
4680 end if;
4681
4682 Next (Arg);
4683 end loop;
4684 end Analyze_Unmodified_Or_Unused;
4685
4686 -----------------------------------
4687 -- Analyze_Unreference_Or_Unused --
4688 -----------------------------------
4689
4690 procedure Analyze_Unreferenced_Or_Unused
4691 (Is_Unused : Boolean := False)
4692 is
4693 Arg : Node_Id;
4694 Arg_Expr : Node_Id;
4695 Arg_Id : Entity_Id;
4696 Citem : Node_Id;
4697
4698 Ghost_Error_Posted : Boolean := False;
4699 -- Flag set when an error concerning the illegal mix of Ghost and
4700 -- non-Ghost names is emitted.
4701
4702 Ghost_Id : Entity_Id := Empty;
4703 -- The entity of the first Ghost name encountered while processing
4704 -- the arguments of the pragma.
4705
4706 begin
4707 GNAT_Pragma;
4708 Check_At_Least_N_Arguments (1);
4709
4710 -- Check case of appearing within context clause
4711
4712 if not Is_Unused and then Is_In_Context_Clause then
4713
4714 -- The arguments must all be units mentioned in a with clause in
4715 -- the same context clause. Note that Par.Prag already checked
4716 -- that the arguments are either identifiers or selected
4717 -- components.
4718
4719 Arg := Arg1;
4720 while Present (Arg) loop
4721 Citem := First (List_Containing (N));
4722 while Citem /= N loop
4723 Arg_Expr := Get_Pragma_Arg (Arg);
4724
4725 if Nkind (Citem) = N_With_Clause
4726 and then Same_Name (Name (Citem), Arg_Expr)
4727 then
4728 Set_Has_Pragma_Unreferenced
4729 (Cunit_Entity
4730 (Get_Source_Unit
4731 (Library_Unit (Citem))));
4732 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
4733 exit;
4734 end if;
4735
4736 Next (Citem);
4737 end loop;
4738
4739 if Citem = N then
4740 Error_Pragma_Arg
4741 ("argument of pragma% is not withed unit", Arg);
4742 end if;
4743
4744 Next (Arg);
4745 end loop;
4746
4747 -- Case of not in list of context items
4748
4749 else
4750 Arg := Arg1;
4751 while Present (Arg) loop
4752 Check_No_Identifier (Arg);
4753
4754 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4755 -- in fact generate reference, so that the entity will have a
4756 -- reference, which will inhibit any warnings about it not
4757 -- being referenced, and also properly show up in the ali file
4758 -- as a reference. But this reference is recorded before the
4759 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4760 -- generated for this reference.
4761
4762 Check_Arg_Is_Local_Name (Arg);
4763 Arg_Expr := Get_Pragma_Arg (Arg);
4764
4765 if Is_Entity_Name (Arg_Expr) then
4766 Arg_Id := Entity (Arg_Expr);
4767
4768 -- Warn if already flagged as Unused or Unreferenced and
4769 -- skip processing the argument.
4770
4771 if Has_Pragma_Unreferenced (Arg_Id) then
4772 if Has_Pragma_Unused (Arg_Id) then
4773 Error_Msg_NE
4774 ("??pragma Unused already given for &!", Arg_Expr,
4775 Arg_Id);
4776 else
4777 Error_Msg_NE
4778 ("??pragma Unreferenced already given for &!",
4779 Arg_Expr, Arg_Id);
4780 end if;
4781
4782 -- Apply Unreferenced to the entity
4783
4784 else
4785 -- If the entity is overloaded, the pragma applies to the
4786 -- most recent overloading, as documented. In this case,
4787 -- name resolution does not generate a reference, so it
4788 -- must be done here explicitly.
4789
4790 if Is_Overloaded (Arg_Expr) then
4791 Generate_Reference (Arg_Id, N);
4792 end if;
4793
4794 Set_Has_Pragma_Unreferenced (Arg_Id);
4795
4796 if Is_Unused then
4797 Set_Has_Pragma_Unused (Arg_Id);
4798 end if;
4799
4800 -- A pragma that applies to a Ghost entity becomes Ghost
4801 -- for the purposes of legality checks and removal of
4802 -- ignored Ghost code.
4803
4804 Mark_Ghost_Pragma (N, Arg_Id);
4805
4806 -- Capture the entity of the first Ghost name being
4807 -- processed for error detection purposes.
4808
4809 if Is_Ghost_Entity (Arg_Id) then
4810 if No (Ghost_Id) then
4811 Ghost_Id := Arg_Id;
4812 end if;
4813
4814 -- Otherwise the name is non-Ghost. It is illegal to mix
4815 -- references to Ghost and non-Ghost entities
4816 -- (SPARK RM 6.9).
4817
4818 elsif Present (Ghost_Id)
4819 and then not Ghost_Error_Posted
4820 then
4821 Ghost_Error_Posted := True;
4822
4823 Error_Msg_Name_1 := Pname;
4824 Error_Msg_N
4825 ("pragma % cannot mention ghost and non-ghost "
4826 & "names", N);
4827
4828 Error_Msg_Sloc := Sloc (Ghost_Id);
4829 Error_Msg_NE
4830 ("\& # declared as ghost", N, Ghost_Id);
4831
4832 Error_Msg_Sloc := Sloc (Arg_Id);
4833 Error_Msg_NE
4834 ("\& # declared as non-ghost", N, Arg_Id);
4835 end if;
4836 end if;
4837 end if;
4838
4839 Next (Arg);
4840 end loop;
4841 end if;
4842 end Analyze_Unreferenced_Or_Unused;
4843
4844 --------------------------
4845 -- Check_Ada_83_Warning --
4846 --------------------------
4847
4848 procedure Check_Ada_83_Warning is
4849 begin
4850 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4851 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
4852 end if;
4853 end Check_Ada_83_Warning;
4854
4855 ---------------------
4856 -- Check_Arg_Count --
4857 ---------------------
4858
4859 procedure Check_Arg_Count (Required : Nat) is
4860 begin
4861 if Arg_Count /= Required then
4862 Error_Pragma ("wrong number of arguments for pragma%");
4863 end if;
4864 end Check_Arg_Count;
4865
4866 --------------------------------
4867 -- Check_Arg_Is_External_Name --
4868 --------------------------------
4869
4870 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
4871 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4872
4873 begin
4874 if Nkind (Argx) = N_Identifier then
4875 return;
4876
4877 else
4878 Analyze_And_Resolve (Argx, Standard_String);
4879
4880 if Is_OK_Static_Expression (Argx) then
4881 return;
4882
4883 elsif Etype (Argx) = Any_Type then
4884 raise Pragma_Exit;
4885
4886 -- An interesting special case, if we have a string literal and
4887 -- we are in Ada 83 mode, then we allow it even though it will
4888 -- not be flagged as static. This allows expected Ada 83 mode
4889 -- use of external names which are string literals, even though
4890 -- technically these are not static in Ada 83.
4891
4892 elsif Ada_Version = Ada_83
4893 and then Nkind (Argx) = N_String_Literal
4894 then
4895 return;
4896
4897 -- Static expression that raises Constraint_Error. This has
4898 -- already been flagged, so just exit from pragma processing.
4899
4900 elsif Is_OK_Static_Expression (Argx) then
4901 raise Pragma_Exit;
4902
4903 -- Here we have a real error (non-static expression)
4904
4905 else
4906 Error_Msg_Name_1 := Pname;
4907
4908 declare
4909 Msg : constant String :=
4910 "argument for pragma% must be a identifier or "
4911 & "static string expression!";
4912 begin
4913 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
4914 raise Pragma_Exit;
4915 end;
4916 end if;
4917 end if;
4918 end Check_Arg_Is_External_Name;
4919
4920 -----------------------------
4921 -- Check_Arg_Is_Identifier --
4922 -----------------------------
4923
4924 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
4925 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4926 begin
4927 if Nkind (Argx) /= N_Identifier then
4928 Error_Pragma_Arg
4929 ("argument for pragma% must be identifier", Argx);
4930 end if;
4931 end Check_Arg_Is_Identifier;
4932
4933 ----------------------------------
4934 -- Check_Arg_Is_Integer_Literal --
4935 ----------------------------------
4936
4937 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
4938 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4939 begin
4940 if Nkind (Argx) /= N_Integer_Literal then
4941 Error_Pragma_Arg
4942 ("argument for pragma% must be integer literal", Argx);
4943 end if;
4944 end Check_Arg_Is_Integer_Literal;
4945
4946 -------------------------------------------
4947 -- Check_Arg_Is_Library_Level_Local_Name --
4948 -------------------------------------------
4949
4950 -- LOCAL_NAME ::=
4951 -- DIRECT_NAME
4952 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4953 -- | library_unit_NAME
4954
4955 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
4956 begin
4957 Check_Arg_Is_Local_Name (Arg);
4958
4959 -- If it came from an aspect, we want to give the error just as if it
4960 -- came from source.
4961
4962 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
4963 and then (Comes_From_Source (N)
4964 or else Present (Corresponding_Aspect (Parent (Arg))))
4965 then
4966 Error_Pragma_Arg
4967 ("argument for pragma% must be library level entity", Arg);
4968 end if;
4969 end Check_Arg_Is_Library_Level_Local_Name;
4970
4971 -----------------------------
4972 -- Check_Arg_Is_Local_Name --
4973 -----------------------------
4974
4975 -- LOCAL_NAME ::=
4976 -- DIRECT_NAME
4977 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4978 -- | library_unit_NAME
4979
4980 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
4981 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4982
4983 begin
4984 -- If this pragma came from an aspect specification, we don't want to
4985 -- check for this error, because that would cause spurious errors, in
4986 -- case a type is frozen in a scope more nested than the type. The
4987 -- aspect itself of course can't be anywhere but on the declaration
4988 -- itself.
4989
4990 if Nkind (Arg) = N_Pragma_Argument_Association then
4991 if From_Aspect_Specification (Parent (Arg)) then
4992 return;
4993 end if;
4994
4995 -- Arg is the Expression of an N_Pragma_Argument_Association
4996
4997 else
4998 if From_Aspect_Specification (Parent (Parent (Arg))) then
4999 return;
5000 end if;
5001 end if;
5002
5003 Analyze (Argx);
5004
5005 if Nkind (Argx) not in N_Direct_Name
5006 and then (Nkind (Argx) /= N_Attribute_Reference
5007 or else Present (Expressions (Argx))
5008 or else Nkind (Prefix (Argx)) /= N_Identifier)
5009 and then (not Is_Entity_Name (Argx)
5010 or else not Is_Compilation_Unit (Entity (Argx)))
5011 then
5012 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
5013 end if;
5014
5015 -- No further check required if not an entity name
5016
5017 if not Is_Entity_Name (Argx) then
5018 null;
5019
5020 else
5021 declare
5022 OK : Boolean;
5023 Ent : constant Entity_Id := Entity (Argx);
5024 Scop : constant Entity_Id := Scope (Ent);
5025
5026 begin
5027 -- Case of a pragma applied to a compilation unit: pragma must
5028 -- occur immediately after the program unit in the compilation.
5029
5030 if Is_Compilation_Unit (Ent) then
5031 declare
5032 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
5033
5034 begin
5035 -- Case of pragma placed immediately after spec
5036
5037 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
5038 OK := True;
5039
5040 -- Case of pragma placed immediately after body
5041
5042 elsif Nkind (Decl) = N_Subprogram_Declaration
5043 and then Present (Corresponding_Body (Decl))
5044 then
5045 OK := Parent (N) =
5046 Aux_Decls_Node
5047 (Parent (Unit_Declaration_Node
5048 (Corresponding_Body (Decl))));
5049
5050 -- All other cases are illegal
5051
5052 else
5053 OK := False;
5054 end if;
5055 end;
5056
5057 -- Special restricted placement rule from 10.2.1(11.8/2)
5058
5059 elsif Is_Generic_Formal (Ent)
5060 and then Prag_Id = Pragma_Preelaborable_Initialization
5061 then
5062 OK := List_Containing (N) =
5063 Generic_Formal_Declarations
5064 (Unit_Declaration_Node (Scop));
5065
5066 -- If this is an aspect applied to a subprogram body, the
5067 -- pragma is inserted in its declarative part.
5068
5069 elsif From_Aspect_Specification (N)
5070 and then Ent = Current_Scope
5071 and then
5072 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
5073 then
5074 OK := True;
5075
5076 -- If the aspect is a predicate (possibly others ???) and the
5077 -- context is a record type, this is a discriminant expression
5078 -- within a type declaration, that freezes the predicated
5079 -- subtype.
5080
5081 elsif From_Aspect_Specification (N)
5082 and then Prag_Id = Pragma_Predicate
5083 and then Ekind (Current_Scope) = E_Record_Type
5084 and then Scop = Scope (Current_Scope)
5085 then
5086 OK := True;
5087
5088 -- Default case, just check that the pragma occurs in the scope
5089 -- of the entity denoted by the name.
5090
5091 else
5092 OK := Current_Scope = Scop;
5093 end if;
5094
5095 if not OK then
5096 Error_Pragma_Arg
5097 ("pragma% argument must be in same declarative part", Arg);
5098 end if;
5099 end;
5100 end if;
5101 end Check_Arg_Is_Local_Name;
5102
5103 ---------------------------------
5104 -- Check_Arg_Is_Locking_Policy --
5105 ---------------------------------
5106
5107 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
5108 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5109
5110 begin
5111 Check_Arg_Is_Identifier (Argx);
5112
5113 if not Is_Locking_Policy_Name (Chars (Argx)) then
5114 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
5115 end if;
5116 end Check_Arg_Is_Locking_Policy;
5117
5118 -----------------------------------------------
5119 -- Check_Arg_Is_Partition_Elaboration_Policy --
5120 -----------------------------------------------
5121
5122 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
5123 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5124
5125 begin
5126 Check_Arg_Is_Identifier (Argx);
5127
5128 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
5129 Error_Pragma_Arg
5130 ("& is not a valid partition elaboration policy name", Argx);
5131 end if;
5132 end Check_Arg_Is_Partition_Elaboration_Policy;
5133
5134 -------------------------
5135 -- Check_Arg_Is_One_Of --
5136 -------------------------
5137
5138 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5139 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5140
5141 begin
5142 Check_Arg_Is_Identifier (Argx);
5143
5144 if not Nam_In (Chars (Argx), N1, N2) then
5145 Error_Msg_Name_2 := N1;
5146 Error_Msg_Name_3 := N2;
5147 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
5148 end if;
5149 end Check_Arg_Is_One_Of;
5150
5151 procedure Check_Arg_Is_One_Of
5152 (Arg : Node_Id;
5153 N1, N2, N3 : Name_Id)
5154 is
5155 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5156
5157 begin
5158 Check_Arg_Is_Identifier (Argx);
5159
5160 if not Nam_In (Chars (Argx), N1, N2, N3) then
5161 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5162 end if;
5163 end Check_Arg_Is_One_Of;
5164
5165 procedure Check_Arg_Is_One_Of
5166 (Arg : Node_Id;
5167 N1, N2, N3, N4 : Name_Id)
5168 is
5169 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5170
5171 begin
5172 Check_Arg_Is_Identifier (Argx);
5173
5174 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
5175 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5176 end if;
5177 end Check_Arg_Is_One_Of;
5178
5179 procedure Check_Arg_Is_One_Of
5180 (Arg : Node_Id;
5181 N1, N2, N3, N4, N5 : Name_Id)
5182 is
5183 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5184
5185 begin
5186 Check_Arg_Is_Identifier (Argx);
5187
5188 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
5189 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
5190 end if;
5191 end Check_Arg_Is_One_Of;
5192
5193 ---------------------------------
5194 -- Check_Arg_Is_Queuing_Policy --
5195 ---------------------------------
5196
5197 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
5198 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5199
5200 begin
5201 Check_Arg_Is_Identifier (Argx);
5202
5203 if not Is_Queuing_Policy_Name (Chars (Argx)) then
5204 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
5205 end if;
5206 end Check_Arg_Is_Queuing_Policy;
5207
5208 ---------------------------------------
5209 -- Check_Arg_Is_OK_Static_Expression --
5210 ---------------------------------------
5211
5212 procedure Check_Arg_Is_OK_Static_Expression
5213 (Arg : Node_Id;
5214 Typ : Entity_Id := Empty)
5215 is
5216 begin
5217 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
5218 end Check_Arg_Is_OK_Static_Expression;
5219
5220 ------------------------------------------
5221 -- Check_Arg_Is_Task_Dispatching_Policy --
5222 ------------------------------------------
5223
5224 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
5225 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5226
5227 begin
5228 Check_Arg_Is_Identifier (Argx);
5229
5230 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
5231 Error_Pragma_Arg
5232 ("& is not an allowed task dispatching policy name", Argx);
5233 end if;
5234 end Check_Arg_Is_Task_Dispatching_Policy;
5235
5236 ---------------------
5237 -- Check_Arg_Order --
5238 ---------------------
5239
5240 procedure Check_Arg_Order (Names : Name_List) is
5241 Arg : Node_Id;
5242
5243 Highest_So_Far : Natural := 0;
5244 -- Highest index in Names seen do far
5245
5246 begin
5247 Arg := Arg1;
5248 for J in 1 .. Arg_Count loop
5249 if Chars (Arg) /= No_Name then
5250 for K in Names'Range loop
5251 if Chars (Arg) = Names (K) then
5252 if K < Highest_So_Far then
5253 Error_Msg_Name_1 := Pname;
5254 Error_Msg_N
5255 ("parameters out of order for pragma%", Arg);
5256 Error_Msg_Name_1 := Names (K);
5257 Error_Msg_Name_2 := Names (Highest_So_Far);
5258 Error_Msg_N ("\% must appear before %", Arg);
5259 raise Pragma_Exit;
5260
5261 else
5262 Highest_So_Far := K;
5263 end if;
5264 end if;
5265 end loop;
5266 end if;
5267
5268 Arg := Next (Arg);
5269 end loop;
5270 end Check_Arg_Order;
5271
5272 --------------------------------
5273 -- Check_At_Least_N_Arguments --
5274 --------------------------------
5275
5276 procedure Check_At_Least_N_Arguments (N : Nat) is
5277 begin
5278 if Arg_Count < N then
5279 Error_Pragma ("too few arguments for pragma%");
5280 end if;
5281 end Check_At_Least_N_Arguments;
5282
5283 -------------------------------
5284 -- Check_At_Most_N_Arguments --
5285 -------------------------------
5286
5287 procedure Check_At_Most_N_Arguments (N : Nat) is
5288 Arg : Node_Id;
5289 begin
5290 if Arg_Count > N then
5291 Arg := Arg1;
5292 for J in 1 .. N loop
5293 Next (Arg);
5294 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
5295 end loop;
5296 end if;
5297 end Check_At_Most_N_Arguments;
5298
5299 ---------------------
5300 -- Check_Component --
5301 ---------------------
5302
5303 procedure Check_Component
5304 (Comp : Node_Id;
5305 UU_Typ : Entity_Id;
5306 In_Variant_Part : Boolean := False)
5307 is
5308 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
5309 Sindic : constant Node_Id :=
5310 Subtype_Indication (Component_Definition (Comp));
5311 Typ : constant Entity_Id := Etype (Comp_Id);
5312
5313 begin
5314 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5315 -- object constraint, then the component type shall be an Unchecked_
5316 -- Union.
5317
5318 if Nkind (Sindic) = N_Subtype_Indication
5319 and then Has_Per_Object_Constraint (Comp_Id)
5320 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
5321 then
5322 Error_Msg_N
5323 ("component subtype subject to per-object constraint "
5324 & "must be an Unchecked_Union", Comp);
5325
5326 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5327 -- the body of a generic unit, or within the body of any of its
5328 -- descendant library units, no part of the type of a component
5329 -- declared in a variant_part of the unchecked union type shall be of
5330 -- a formal private type or formal private extension declared within
5331 -- the formal part of the generic unit.
5332
5333 elsif Ada_Version >= Ada_2012
5334 and then In_Generic_Body (UU_Typ)
5335 and then In_Variant_Part
5336 and then Is_Private_Type (Typ)
5337 and then Is_Generic_Type (Typ)
5338 then
5339 Error_Msg_N
5340 ("component of unchecked union cannot be of generic type", Comp);
5341
5342 elsif Needs_Finalization (Typ) then
5343 Error_Msg_N
5344 ("component of unchecked union cannot be controlled", Comp);
5345
5346 elsif Has_Task (Typ) then
5347 Error_Msg_N
5348 ("component of unchecked union cannot have tasks", Comp);
5349 end if;
5350 end Check_Component;
5351
5352 ----------------------------
5353 -- Check_Duplicate_Pragma --
5354 ----------------------------
5355
5356 procedure Check_Duplicate_Pragma (E : Entity_Id) is
5357 Id : Entity_Id := E;
5358 P : Node_Id;
5359
5360 begin
5361 -- Nothing to do if this pragma comes from an aspect specification,
5362 -- since we could not be duplicating a pragma, and we dealt with the
5363 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5364
5365 if From_Aspect_Specification (N) then
5366 return;
5367 end if;
5368
5369 -- Otherwise current pragma may duplicate previous pragma or a
5370 -- previously given aspect specification or attribute definition
5371 -- clause for the same pragma.
5372
5373 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
5374
5375 if Present (P) then
5376
5377 -- If the entity is a type, then we have to make sure that the
5378 -- ostensible duplicate is not for a parent type from which this
5379 -- type is derived.
5380
5381 if Is_Type (E) then
5382 if Nkind (P) = N_Pragma then
5383 declare
5384 Args : constant List_Id :=
5385 Pragma_Argument_Associations (P);
5386 begin
5387 if Present (Args)
5388 and then Is_Entity_Name (Expression (First (Args)))
5389 and then Is_Type (Entity (Expression (First (Args))))
5390 and then Entity (Expression (First (Args))) /= E
5391 then
5392 return;
5393 end if;
5394 end;
5395
5396 elsif Nkind (P) = N_Aspect_Specification
5397 and then Is_Type (Entity (P))
5398 and then Entity (P) /= E
5399 then
5400 return;
5401 end if;
5402 end if;
5403
5404 -- Here we have a definite duplicate
5405
5406 Error_Msg_Name_1 := Pragma_Name (N);
5407 Error_Msg_Sloc := Sloc (P);
5408
5409 -- For a single protected or a single task object, the error is
5410 -- issued on the original entity.
5411
5412 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5413 Id := Defining_Identifier (Original_Node (Parent (Id)));
5414 end if;
5415
5416 if Nkind (P) = N_Aspect_Specification
5417 or else From_Aspect_Specification (P)
5418 then
5419 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5420 else
5421 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5422 end if;
5423
5424 raise Pragma_Exit;
5425 end if;
5426 end Check_Duplicate_Pragma;
5427
5428 ----------------------------------
5429 -- Check_Duplicated_Export_Name --
5430 ----------------------------------
5431
5432 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5433 String_Val : constant String_Id := Strval (Nam);
5434
5435 begin
5436 -- We are only interested in the export case, and in the case of
5437 -- generics, it is the instance, not the template, that is the
5438 -- problem (the template will generate a warning in any case).
5439
5440 if not Inside_A_Generic
5441 and then (Prag_Id = Pragma_Export
5442 or else
5443 Prag_Id = Pragma_Export_Procedure
5444 or else
5445 Prag_Id = Pragma_Export_Valued_Procedure
5446 or else
5447 Prag_Id = Pragma_Export_Function)
5448 then
5449 for J in Externals.First .. Externals.Last loop
5450 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5451 Error_Msg_Sloc := Sloc (Externals.Table (J));
5452 Error_Msg_N ("external name duplicates name given#", Nam);
5453 exit;
5454 end if;
5455 end loop;
5456
5457 Externals.Append (Nam);
5458 end if;
5459 end Check_Duplicated_Export_Name;
5460
5461 ----------------------------------------
5462 -- Check_Expr_Is_OK_Static_Expression --
5463 ----------------------------------------
5464
5465 procedure Check_Expr_Is_OK_Static_Expression
5466 (Expr : Node_Id;
5467 Typ : Entity_Id := Empty)
5468 is
5469 begin
5470 if Present (Typ) then
5471 Analyze_And_Resolve (Expr, Typ);
5472 else
5473 Analyze_And_Resolve (Expr);
5474 end if;
5475
5476 -- An expression cannot be considered static if its resolution failed
5477 -- or if it's erroneous. Stop the analysis of the related pragma.
5478
5479 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5480 raise Pragma_Exit;
5481
5482 elsif Is_OK_Static_Expression (Expr) then
5483 return;
5484
5485 -- An interesting special case, if we have a string literal and we
5486 -- are in Ada 83 mode, then we allow it even though it will not be
5487 -- flagged as static. This allows the use of Ada 95 pragmas like
5488 -- Import in Ada 83 mode. They will of course be flagged with
5489 -- warnings as usual, but will not cause errors.
5490
5491 elsif Ada_Version = Ada_83
5492 and then Nkind (Expr) = N_String_Literal
5493 then
5494 return;
5495
5496 -- Finally, we have a real error
5497
5498 else
5499 Error_Msg_Name_1 := Pname;
5500 Flag_Non_Static_Expr
5501 (Fix_Error ("argument for pragma% must be a static expression!"),
5502 Expr);
5503 raise Pragma_Exit;
5504 end if;
5505 end Check_Expr_Is_OK_Static_Expression;
5506
5507 -------------------------
5508 -- Check_First_Subtype --
5509 -------------------------
5510
5511 procedure Check_First_Subtype (Arg : Node_Id) is
5512 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5513 Ent : constant Entity_Id := Entity (Argx);
5514
5515 begin
5516 if Is_First_Subtype (Ent) then
5517 null;
5518
5519 elsif Is_Type (Ent) then
5520 Error_Pragma_Arg
5521 ("pragma% cannot apply to subtype", Argx);
5522
5523 elsif Is_Object (Ent) then
5524 Error_Pragma_Arg
5525 ("pragma% cannot apply to object, requires a type", Argx);
5526
5527 else
5528 Error_Pragma_Arg
5529 ("pragma% cannot apply to&, requires a type", Argx);
5530 end if;
5531 end Check_First_Subtype;
5532
5533 ----------------------
5534 -- Check_Identifier --
5535 ----------------------
5536
5537 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
5538 begin
5539 if Present (Arg)
5540 and then Nkind (Arg) = N_Pragma_Argument_Association
5541 then
5542 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
5543 Error_Msg_Name_1 := Pname;
5544 Error_Msg_Name_2 := Id;
5545 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5546 raise Pragma_Exit;
5547 end if;
5548 end if;
5549 end Check_Identifier;
5550
5551 --------------------------------
5552 -- Check_Identifier_Is_One_Of --
5553 --------------------------------
5554
5555 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5556 begin
5557 if Present (Arg)
5558 and then Nkind (Arg) = N_Pragma_Argument_Association
5559 then
5560 if Chars (Arg) = No_Name then
5561 Error_Msg_Name_1 := Pname;
5562 Error_Msg_N ("pragma% argument expects an identifier", Arg);
5563 raise Pragma_Exit;
5564
5565 elsif Chars (Arg) /= N1
5566 and then Chars (Arg) /= N2
5567 then
5568 Error_Msg_Name_1 := Pname;
5569 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
5570 raise Pragma_Exit;
5571 end if;
5572 end if;
5573 end Check_Identifier_Is_One_Of;
5574
5575 ---------------------------
5576 -- Check_In_Main_Program --
5577 ---------------------------
5578
5579 procedure Check_In_Main_Program is
5580 P : constant Node_Id := Parent (N);
5581
5582 begin
5583 -- Must be in subprogram body
5584
5585 if Nkind (P) /= N_Subprogram_Body then
5586 Error_Pragma ("% pragma allowed only in subprogram");
5587
5588 -- Otherwise warn if obviously not main program
5589
5590 elsif Present (Parameter_Specifications (Specification (P)))
5591 or else not Is_Compilation_Unit (Defining_Entity (P))
5592 then
5593 Error_Msg_Name_1 := Pname;
5594 Error_Msg_N
5595 ("??pragma% is only effective in main program", N);
5596 end if;
5597 end Check_In_Main_Program;
5598
5599 ---------------------------------------
5600 -- Check_Interrupt_Or_Attach_Handler --
5601 ---------------------------------------
5602
5603 procedure Check_Interrupt_Or_Attach_Handler is
5604 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5605 Handler_Proc, Proc_Scope : Entity_Id;
5606
5607 begin
5608 Analyze (Arg1_X);
5609
5610 if Prag_Id = Pragma_Interrupt_Handler then
5611 Check_Restriction (No_Dynamic_Attachment, N);
5612 end if;
5613
5614 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
5615 Proc_Scope := Scope (Handler_Proc);
5616
5617 if Ekind (Proc_Scope) /= E_Protected_Type then
5618 Error_Pragma_Arg
5619 ("argument of pragma% must be protected procedure", Arg1);
5620 end if;
5621
5622 -- For pragma case (as opposed to access case), check placement.
5623 -- We don't need to do that for aspects, because we have the
5624 -- check that they aspect applies an appropriate procedure.
5625
5626 if not From_Aspect_Specification (N)
5627 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
5628 then
5629 Error_Pragma ("pragma% must be in protected definition");
5630 end if;
5631
5632 if not Is_Library_Level_Entity (Proc_Scope) then
5633 Error_Pragma_Arg
5634 ("argument for pragma% must be library level entity", Arg1);
5635 end if;
5636
5637 -- AI05-0033: A pragma cannot appear within a generic body, because
5638 -- instance can be in a nested scope. The check that protected type
5639 -- is itself a library-level declaration is done elsewhere.
5640
5641 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5642 -- handle code prior to AI-0033. Analysis tools typically are not
5643 -- interested in this pragma in any case, so no need to worry too
5644 -- much about its placement.
5645
5646 if Inside_A_Generic then
5647 if Ekind (Scope (Current_Scope)) = E_Generic_Package
5648 and then In_Package_Body (Scope (Current_Scope))
5649 and then not Relaxed_RM_Semantics
5650 then
5651 Error_Pragma ("pragma% cannot be used inside a generic");
5652 end if;
5653 end if;
5654 end Check_Interrupt_Or_Attach_Handler;
5655
5656 ---------------------------------
5657 -- Check_Loop_Pragma_Placement --
5658 ---------------------------------
5659
5660 procedure Check_Loop_Pragma_Placement is
5661 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
5662 -- Verify whether the current pragma is properly grouped with other
5663 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5664 -- related loop where the pragma appears.
5665
5666 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
5667 -- Determine whether an arbitrary statement Stmt denotes pragma
5668 -- Loop_Invariant or Loop_Variant.
5669
5670 procedure Placement_Error (Constr : Node_Id);
5671 pragma No_Return (Placement_Error);
5672 -- Node Constr denotes the last loop restricted construct before we
5673 -- encountered an illegal relation between enclosing constructs. Emit
5674 -- an error depending on what Constr was.
5675
5676 --------------------------------
5677 -- Check_Loop_Pragma_Grouping --
5678 --------------------------------
5679
5680 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
5681 Stop_Search : exception;
5682 -- This exception is used to terminate the recursive descent of
5683 -- routine Check_Grouping.
5684
5685 procedure Check_Grouping (L : List_Id);
5686 -- Find the first group of pragmas in list L and if successful,
5687 -- ensure that the current pragma is part of that group. The
5688 -- routine raises Stop_Search once such a check is performed to
5689 -- halt the recursive descent.
5690
5691 procedure Grouping_Error (Prag : Node_Id);
5692 pragma No_Return (Grouping_Error);
5693 -- Emit an error concerning the current pragma indicating that it
5694 -- should be placed after pragma Prag.
5695
5696 --------------------
5697 -- Check_Grouping --
5698 --------------------
5699
5700 procedure Check_Grouping (L : List_Id) is
5701 HSS : Node_Id;
5702 Prag : Node_Id;
5703 Stmt : Node_Id;
5704
5705 begin
5706 -- Inspect the list of declarations or statements looking for
5707 -- the first grouping of pragmas:
5708
5709 -- loop
5710 -- pragma Loop_Invariant ...;
5711 -- pragma Loop_Variant ...;
5712 -- . . . -- (1)
5713 -- pragma Loop_Variant ...; -- current pragma
5714
5715 -- If the current pragma is not in the grouping, then it must
5716 -- either appear in a different declarative or statement list
5717 -- or the construct at (1) is separating the pragma from the
5718 -- grouping.
5719
5720 Stmt := First (L);
5721 while Present (Stmt) loop
5722
5723 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5724 -- inside a loop or a block housed inside a loop. Inspect
5725 -- the declarations and statements of the block as they may
5726 -- contain the first grouping.
5727
5728 if Nkind (Stmt) = N_Block_Statement then
5729 HSS := Handled_Statement_Sequence (Stmt);
5730
5731 Check_Grouping (Declarations (Stmt));
5732
5733 if Present (HSS) then
5734 Check_Grouping (Statements (HSS));
5735 end if;
5736
5737 -- First pragma of the first topmost grouping has been found
5738
5739 elsif Is_Loop_Pragma (Stmt) then
5740
5741 -- The group and the current pragma are not in the same
5742 -- declarative or statement list.
5743
5744 if List_Containing (Stmt) /= List_Containing (N) then
5745 Grouping_Error (Stmt);
5746
5747 -- Try to reach the current pragma from the first pragma
5748 -- of the grouping while skipping other members:
5749
5750 -- pragma Loop_Invariant ...; -- first pragma
5751 -- pragma Loop_Variant ...; -- member
5752 -- . . .
5753 -- pragma Loop_Variant ...; -- current pragma
5754
5755 else
5756 while Present (Stmt) loop
5757
5758 -- The current pragma is either the first pragma
5759 -- of the group or is a member of the group. Stop
5760 -- the search as the placement is legal.
5761
5762 if Stmt = N then
5763 raise Stop_Search;
5764
5765 -- Skip group members, but keep track of the last
5766 -- pragma in the group.
5767
5768 elsif Is_Loop_Pragma (Stmt) then
5769 Prag := Stmt;
5770
5771 -- Skip declarations and statements generated by
5772 -- the compiler during expansion.
5773
5774 elsif not Comes_From_Source (Stmt) then
5775 null;
5776
5777 -- A non-pragma is separating the group from the
5778 -- current pragma, the placement is illegal.
5779
5780 else
5781 Grouping_Error (Prag);
5782 end if;
5783
5784 Next (Stmt);
5785 end loop;
5786
5787 -- If the traversal did not reach the current pragma,
5788 -- then the list must be malformed.
5789
5790 raise Program_Error;
5791 end if;
5792 end if;
5793
5794 Next (Stmt);
5795 end loop;
5796 end Check_Grouping;
5797
5798 --------------------
5799 -- Grouping_Error --
5800 --------------------
5801
5802 procedure Grouping_Error (Prag : Node_Id) is
5803 begin
5804 Error_Msg_Sloc := Sloc (Prag);
5805 Error_Pragma ("pragma% must appear next to pragma#");
5806 end Grouping_Error;
5807
5808 -- Start of processing for Check_Loop_Pragma_Grouping
5809
5810 begin
5811 -- Inspect the statements of the loop or nested blocks housed
5812 -- within to determine whether the current pragma is part of the
5813 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5814
5815 Check_Grouping (Statements (Loop_Stmt));
5816
5817 exception
5818 when Stop_Search => null;
5819 end Check_Loop_Pragma_Grouping;
5820
5821 --------------------
5822 -- Is_Loop_Pragma --
5823 --------------------
5824
5825 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
5826 begin
5827 -- Inspect the original node as Loop_Invariant and Loop_Variant
5828 -- pragmas are rewritten to null when assertions are disabled.
5829
5830 if Nkind (Original_Node (Stmt)) = N_Pragma then
5831 return
5832 Nam_In (Pragma_Name_Unmapped (Original_Node (Stmt)),
5833 Name_Loop_Invariant,
5834 Name_Loop_Variant);
5835 else
5836 return False;
5837 end if;
5838 end Is_Loop_Pragma;
5839
5840 ---------------------
5841 -- Placement_Error --
5842 ---------------------
5843
5844 procedure Placement_Error (Constr : Node_Id) is
5845 LA : constant String := " with Loop_Entry";
5846
5847 begin
5848 if Prag_Id = Pragma_Assert then
5849 Error_Msg_String (1 .. LA'Length) := LA;
5850 Error_Msg_Strlen := LA'Length;
5851 else
5852 Error_Msg_Strlen := 0;
5853 end if;
5854
5855 if Nkind (Constr) = N_Pragma then
5856 Error_Pragma
5857 ("pragma %~ must appear immediately within the statements "
5858 & "of a loop");
5859 else
5860 Error_Pragma_Arg
5861 ("block containing pragma %~ must appear immediately within "
5862 & "the statements of a loop", Constr);
5863 end if;
5864 end Placement_Error;
5865
5866 -- Local declarations
5867
5868 Prev : Node_Id;
5869 Stmt : Node_Id;
5870
5871 -- Start of processing for Check_Loop_Pragma_Placement
5872
5873 begin
5874 -- Check that pragma appears immediately within a loop statement,
5875 -- ignoring intervening block statements.
5876
5877 Prev := N;
5878 Stmt := Parent (N);
5879 while Present (Stmt) loop
5880
5881 -- The pragma or previous block must appear immediately within the
5882 -- current block's declarative or statement part.
5883
5884 if Nkind (Stmt) = N_Block_Statement then
5885 if (No (Declarations (Stmt))
5886 or else List_Containing (Prev) /= Declarations (Stmt))
5887 and then
5888 List_Containing (Prev) /=
5889 Statements (Handled_Statement_Sequence (Stmt))
5890 then
5891 Placement_Error (Prev);
5892 return;
5893
5894 -- Keep inspecting the parents because we are now within a
5895 -- chain of nested blocks.
5896
5897 else
5898 Prev := Stmt;
5899 Stmt := Parent (Stmt);
5900 end if;
5901
5902 -- The pragma or previous block must appear immediately within the
5903 -- statements of the loop.
5904
5905 elsif Nkind (Stmt) = N_Loop_Statement then
5906 if List_Containing (Prev) /= Statements (Stmt) then
5907 Placement_Error (Prev);
5908 end if;
5909
5910 -- Stop the traversal because we reached the innermost loop
5911 -- regardless of whether we encountered an error or not.
5912
5913 exit;
5914
5915 -- Ignore a handled statement sequence. Note that this node may
5916 -- be related to a subprogram body in which case we will emit an
5917 -- error on the next iteration of the search.
5918
5919 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
5920 Stmt := Parent (Stmt);
5921
5922 -- Any other statement breaks the chain from the pragma to the
5923 -- loop.
5924
5925 else
5926 Placement_Error (Prev);
5927 return;
5928 end if;
5929 end loop;
5930
5931 -- Check that the current pragma Loop_Invariant or Loop_Variant is
5932 -- grouped together with other such pragmas.
5933
5934 if Is_Loop_Pragma (N) then
5935
5936 -- The previous check should have located the related loop
5937
5938 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
5939 Check_Loop_Pragma_Grouping (Stmt);
5940 end if;
5941 end Check_Loop_Pragma_Placement;
5942
5943 -------------------------------------------
5944 -- Check_Is_In_Decl_Part_Or_Package_Spec --
5945 -------------------------------------------
5946
5947 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
5948 P : Node_Id;
5949
5950 begin
5951 P := Parent (N);
5952 loop
5953 if No (P) then
5954 exit;
5955
5956 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
5957 exit;
5958
5959 elsif Nkind_In (P, N_Package_Specification,
5960 N_Block_Statement)
5961 then
5962 return;
5963
5964 -- Note: the following tests seem a little peculiar, because
5965 -- they test for bodies, but if we were in the statement part
5966 -- of the body, we would already have hit the handled statement
5967 -- sequence, so the only way we get here is by being in the
5968 -- declarative part of the body.
5969
5970 elsif Nkind_In (P, N_Subprogram_Body,
5971 N_Package_Body,
5972 N_Task_Body,
5973 N_Entry_Body)
5974 then
5975 return;
5976 end if;
5977
5978 P := Parent (P);
5979 end loop;
5980
5981 Error_Pragma ("pragma% is not in declarative part or package spec");
5982 end Check_Is_In_Decl_Part_Or_Package_Spec;
5983
5984 -------------------------
5985 -- Check_No_Identifier --
5986 -------------------------
5987
5988 procedure Check_No_Identifier (Arg : Node_Id) is
5989 begin
5990 if Nkind (Arg) = N_Pragma_Argument_Association
5991 and then Chars (Arg) /= No_Name
5992 then
5993 Error_Pragma_Arg_Ident
5994 ("pragma% does not permit identifier& here", Arg);
5995 end if;
5996 end Check_No_Identifier;
5997
5998 --------------------------
5999 -- Check_No_Identifiers --
6000 --------------------------
6001
6002 procedure Check_No_Identifiers is
6003 Arg_Node : Node_Id;
6004 begin
6005 Arg_Node := Arg1;
6006 for J in 1 .. Arg_Count loop
6007 Check_No_Identifier (Arg_Node);
6008 Next (Arg_Node);
6009 end loop;
6010 end Check_No_Identifiers;
6011
6012 ------------------------
6013 -- Check_No_Link_Name --
6014 ------------------------
6015
6016 procedure Check_No_Link_Name is
6017 begin
6018 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
6019 Arg4 := Arg3;
6020 end if;
6021
6022 if Present (Arg4) then
6023 Error_Pragma_Arg
6024 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
6025 end if;
6026 end Check_No_Link_Name;
6027
6028 -------------------------------
6029 -- Check_Optional_Identifier --
6030 -------------------------------
6031
6032 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
6033 begin
6034 if Present (Arg)
6035 and then Nkind (Arg) = N_Pragma_Argument_Association
6036 and then Chars (Arg) /= No_Name
6037 then
6038 if Chars (Arg) /= Id then
6039 Error_Msg_Name_1 := Pname;
6040 Error_Msg_Name_2 := Id;
6041 Error_Msg_N ("pragma% argument expects identifier%", Arg);
6042 raise Pragma_Exit;
6043 end if;
6044 end if;
6045 end Check_Optional_Identifier;
6046
6047 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
6048 begin
6049 Check_Optional_Identifier (Arg, Name_Find (Id));
6050 end Check_Optional_Identifier;
6051
6052 -------------------------------------
6053 -- Check_Static_Boolean_Expression --
6054 -------------------------------------
6055
6056 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
6057 begin
6058 if Present (Expr) then
6059 Analyze_And_Resolve (Expr, Standard_Boolean);
6060
6061 if not Is_OK_Static_Expression (Expr) then
6062 Error_Pragma_Arg
6063 ("expression of pragma % must be static", Expr);
6064 end if;
6065 end if;
6066 end Check_Static_Boolean_Expression;
6067
6068 -----------------------------
6069 -- Check_Static_Constraint --
6070 -----------------------------
6071
6072 -- Note: for convenience in writing this procedure, in addition to
6073 -- the officially (i.e. by spec) allowed argument which is always a
6074 -- constraint, it also allows ranges and discriminant associations.
6075 -- Above is not clear ???
6076
6077 procedure Check_Static_Constraint (Constr : Node_Id) is
6078
6079 procedure Require_Static (E : Node_Id);
6080 -- Require given expression to be static expression
6081
6082 --------------------
6083 -- Require_Static --
6084 --------------------
6085
6086 procedure Require_Static (E : Node_Id) is
6087 begin
6088 if not Is_OK_Static_Expression (E) then
6089 Flag_Non_Static_Expr
6090 ("non-static constraint not allowed in Unchecked_Union!", E);
6091 raise Pragma_Exit;
6092 end if;
6093 end Require_Static;
6094
6095 -- Start of processing for Check_Static_Constraint
6096
6097 begin
6098 case Nkind (Constr) is
6099 when N_Discriminant_Association =>
6100 Require_Static (Expression (Constr));
6101
6102 when N_Range =>
6103 Require_Static (Low_Bound (Constr));
6104 Require_Static (High_Bound (Constr));
6105
6106 when N_Attribute_Reference =>
6107 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
6108 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
6109
6110 when N_Range_Constraint =>
6111 Check_Static_Constraint (Range_Expression (Constr));
6112
6113 when N_Index_Or_Discriminant_Constraint =>
6114 declare
6115 IDC : Entity_Id;
6116 begin
6117 IDC := First (Constraints (Constr));
6118 while Present (IDC) loop
6119 Check_Static_Constraint (IDC);
6120 Next (IDC);
6121 end loop;
6122 end;
6123
6124 when others =>
6125 null;
6126 end case;
6127 end Check_Static_Constraint;
6128
6129 --------------------------------------
6130 -- Check_Valid_Configuration_Pragma --
6131 --------------------------------------
6132
6133 -- A configuration pragma must appear in the context clause of a
6134 -- compilation unit, and only other pragmas may precede it. Note that
6135 -- the test also allows use in a configuration pragma file.
6136
6137 procedure Check_Valid_Configuration_Pragma is
6138 begin
6139 if not Is_Configuration_Pragma then
6140 Error_Pragma ("incorrect placement for configuration pragma%");
6141 end if;
6142 end Check_Valid_Configuration_Pragma;
6143
6144 -------------------------------------
6145 -- Check_Valid_Library_Unit_Pragma --
6146 -------------------------------------
6147
6148 procedure Check_Valid_Library_Unit_Pragma is
6149 Plist : List_Id;
6150 Parent_Node : Node_Id;
6151 Unit_Name : Entity_Id;
6152 Unit_Kind : Node_Kind;
6153 Unit_Node : Node_Id;
6154 Sindex : Source_File_Index;
6155
6156 begin
6157 if not Is_List_Member (N) then
6158 Pragma_Misplaced;
6159
6160 else
6161 Plist := List_Containing (N);
6162 Parent_Node := Parent (Plist);
6163
6164 if Parent_Node = Empty then
6165 Pragma_Misplaced;
6166
6167 -- Case of pragma appearing after a compilation unit. In this case
6168 -- it must have an argument with the corresponding name and must
6169 -- be part of the following pragmas of its parent.
6170
6171 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
6172 if Plist /= Pragmas_After (Parent_Node) then
6173 Pragma_Misplaced;
6174
6175 elsif Arg_Count = 0 then
6176 Error_Pragma
6177 ("argument required if outside compilation unit");
6178
6179 else
6180 Check_No_Identifiers;
6181 Check_Arg_Count (1);
6182 Unit_Node := Unit (Parent (Parent_Node));
6183 Unit_Kind := Nkind (Unit_Node);
6184
6185 Analyze (Get_Pragma_Arg (Arg1));
6186
6187 if Unit_Kind = N_Generic_Subprogram_Declaration
6188 or else Unit_Kind = N_Subprogram_Declaration
6189 then
6190 Unit_Name := Defining_Entity (Unit_Node);
6191
6192 elsif Unit_Kind in N_Generic_Instantiation then
6193 Unit_Name := Defining_Entity (Unit_Node);
6194
6195 else
6196 Unit_Name := Cunit_Entity (Current_Sem_Unit);
6197 end if;
6198
6199 if Chars (Unit_Name) /=
6200 Chars (Entity (Get_Pragma_Arg (Arg1)))
6201 then
6202 Error_Pragma_Arg
6203 ("pragma% argument is not current unit name", Arg1);
6204 end if;
6205
6206 if Ekind (Unit_Name) = E_Package
6207 and then Present (Renamed_Entity (Unit_Name))
6208 then
6209 Error_Pragma ("pragma% not allowed for renamed package");
6210 end if;
6211 end if;
6212
6213 -- Pragma appears other than after a compilation unit
6214
6215 else
6216 -- Here we check for the generic instantiation case and also
6217 -- for the case of processing a generic formal package. We
6218 -- detect these cases by noting that the Sloc on the node
6219 -- does not belong to the current compilation unit.
6220
6221 Sindex := Source_Index (Current_Sem_Unit);
6222
6223 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
6224 Rewrite (N, Make_Null_Statement (Loc));
6225 return;
6226
6227 -- If before first declaration, the pragma applies to the
6228 -- enclosing unit, and the name if present must be this name.
6229
6230 elsif Is_Before_First_Decl (N, Plist) then
6231 Unit_Node := Unit_Declaration_Node (Current_Scope);
6232 Unit_Kind := Nkind (Unit_Node);
6233
6234 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
6235 Pragma_Misplaced;
6236
6237 elsif Unit_Kind = N_Subprogram_Body
6238 and then not Acts_As_Spec (Unit_Node)
6239 then
6240 Pragma_Misplaced;
6241
6242 elsif Nkind (Parent_Node) = N_Package_Body then
6243 Pragma_Misplaced;
6244
6245 elsif Nkind (Parent_Node) = N_Package_Specification
6246 and then Plist = Private_Declarations (Parent_Node)
6247 then
6248 Pragma_Misplaced;
6249
6250 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
6251 or else Nkind (Parent_Node) =
6252 N_Generic_Subprogram_Declaration)
6253 and then Plist = Generic_Formal_Declarations (Parent_Node)
6254 then
6255 Pragma_Misplaced;
6256
6257 elsif Arg_Count > 0 then
6258 Analyze (Get_Pragma_Arg (Arg1));
6259
6260 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
6261 Error_Pragma_Arg
6262 ("name in pragma% must be enclosing unit", Arg1);
6263 end if;
6264
6265 -- It is legal to have no argument in this context
6266
6267 else
6268 return;
6269 end if;
6270
6271 -- Error if not before first declaration. This is because a
6272 -- library unit pragma argument must be the name of a library
6273 -- unit (RM 10.1.5(7)), but the only names permitted in this
6274 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6275 -- generic subprogram declarations or generic instantiations.
6276
6277 else
6278 Error_Pragma
6279 ("pragma% misplaced, must be before first declaration");
6280 end if;
6281 end if;
6282 end if;
6283 end Check_Valid_Library_Unit_Pragma;
6284
6285 -------------------
6286 -- Check_Variant --
6287 -------------------
6288
6289 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
6290 Clist : constant Node_Id := Component_List (Variant);
6291 Comp : Node_Id;
6292
6293 begin
6294 Comp := First (Component_Items (Clist));
6295 while Present (Comp) loop
6296 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
6297 Next (Comp);
6298 end loop;
6299 end Check_Variant;
6300
6301 ---------------------------
6302 -- Ensure_Aggregate_Form --
6303 ---------------------------
6304
6305 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
6306 CFSD : constant Boolean := Get_Comes_From_Source_Default;
6307 Expr : constant Node_Id := Expression (Arg);
6308 Loc : constant Source_Ptr := Sloc (Expr);
6309 Comps : List_Id := No_List;
6310 Exprs : List_Id := No_List;
6311 Nam : Name_Id := No_Name;
6312 Nam_Loc : Source_Ptr;
6313
6314 begin
6315 -- The pragma argument is in positional form:
6316
6317 -- pragma Depends (Nam => ...)
6318 -- ^
6319 -- Chars field
6320
6321 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6322 -- argument association.
6323
6324 if Nkind (Arg) = N_Pragma_Argument_Association then
6325 Nam := Chars (Arg);
6326 Nam_Loc := Sloc (Arg);
6327
6328 -- Remove the pragma argument name as this will be captured in the
6329 -- aggregate.
6330
6331 Set_Chars (Arg, No_Name);
6332 end if;
6333
6334 -- The argument is already in aggregate form, but the presence of a
6335 -- name causes this to be interpreted as named association which in
6336 -- turn must be converted into an aggregate.
6337
6338 -- pragma Global (In_Out => (A, B, C))
6339 -- ^ ^
6340 -- name aggregate
6341
6342 -- pragma Global ((In_Out => (A, B, C)))
6343 -- ^ ^
6344 -- aggregate aggregate
6345
6346 if Nkind (Expr) = N_Aggregate then
6347 if Nam = No_Name then
6348 return;
6349 end if;
6350
6351 -- Do not transform a null argument into an aggregate as N_Null has
6352 -- special meaning in formal verification pragmas.
6353
6354 elsif Nkind (Expr) = N_Null then
6355 return;
6356 end if;
6357
6358 -- Everything comes from source if the original comes from source
6359
6360 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
6361
6362 -- Positional argument is transformed into an aggregate with an
6363 -- Expressions list.
6364
6365 if Nam = No_Name then
6366 Exprs := New_List (Relocate_Node (Expr));
6367
6368 -- An associative argument is transformed into an aggregate with
6369 -- Component_Associations.
6370
6371 else
6372 Comps := New_List (
6373 Make_Component_Association (Loc,
6374 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
6375 Expression => Relocate_Node (Expr)));
6376 end if;
6377
6378 Set_Expression (Arg,
6379 Make_Aggregate (Loc,
6380 Component_Associations => Comps,
6381 Expressions => Exprs));
6382
6383 -- Restore Comes_From_Source default
6384
6385 Set_Comes_From_Source_Default (CFSD);
6386 end Ensure_Aggregate_Form;
6387
6388 ------------------
6389 -- Error_Pragma --
6390 ------------------
6391
6392 procedure Error_Pragma (Msg : String) is
6393 begin
6394 Error_Msg_Name_1 := Pname;
6395 Error_Msg_N (Fix_Error (Msg), N);
6396 raise Pragma_Exit;
6397 end Error_Pragma;
6398
6399 ----------------------
6400 -- Error_Pragma_Arg --
6401 ----------------------
6402
6403 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
6404 begin
6405 Error_Msg_Name_1 := Pname;
6406 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
6407 raise Pragma_Exit;
6408 end Error_Pragma_Arg;
6409
6410 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6411 begin
6412 Error_Msg_Name_1 := Pname;
6413 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6414 Error_Pragma_Arg (Msg2, Arg);
6415 end Error_Pragma_Arg;
6416
6417 ----------------------------
6418 -- Error_Pragma_Arg_Ident --
6419 ----------------------------
6420
6421 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6422 begin
6423 Error_Msg_Name_1 := Pname;
6424 Error_Msg_N (Fix_Error (Msg), Arg);
6425 raise Pragma_Exit;
6426 end Error_Pragma_Arg_Ident;
6427
6428 ----------------------
6429 -- Error_Pragma_Ref --
6430 ----------------------
6431
6432 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6433 begin
6434 Error_Msg_Name_1 := Pname;
6435 Error_Msg_Sloc := Sloc (Ref);
6436 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6437 raise Pragma_Exit;
6438 end Error_Pragma_Ref;
6439
6440 ------------------------
6441 -- Find_Lib_Unit_Name --
6442 ------------------------
6443
6444 function Find_Lib_Unit_Name return Entity_Id is
6445 begin
6446 -- Return inner compilation unit entity, for case of nested
6447 -- categorization pragmas. This happens in generic unit.
6448
6449 if Nkind (Parent (N)) = N_Package_Specification
6450 and then Defining_Entity (Parent (N)) /= Current_Scope
6451 then
6452 return Defining_Entity (Parent (N));
6453 else
6454 return Current_Scope;
6455 end if;
6456 end Find_Lib_Unit_Name;
6457
6458 ----------------------------
6459 -- Find_Program_Unit_Name --
6460 ----------------------------
6461
6462 procedure Find_Program_Unit_Name (Id : Node_Id) is
6463 Unit_Name : Entity_Id;
6464 Unit_Kind : Node_Kind;
6465 P : constant Node_Id := Parent (N);
6466
6467 begin
6468 if Nkind (P) = N_Compilation_Unit then
6469 Unit_Kind := Nkind (Unit (P));
6470
6471 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
6472 N_Package_Declaration)
6473 or else Unit_Kind in N_Generic_Declaration
6474 then
6475 Unit_Name := Defining_Entity (Unit (P));
6476
6477 if Chars (Id) = Chars (Unit_Name) then
6478 Set_Entity (Id, Unit_Name);
6479 Set_Etype (Id, Etype (Unit_Name));
6480 else
6481 Set_Etype (Id, Any_Type);
6482 Error_Pragma
6483 ("cannot find program unit referenced by pragma%");
6484 end if;
6485
6486 else
6487 Set_Etype (Id, Any_Type);
6488 Error_Pragma ("pragma% inapplicable to this unit");
6489 end if;
6490
6491 else
6492 Analyze (Id);
6493 end if;
6494 end Find_Program_Unit_Name;
6495
6496 -----------------------------------------
6497 -- Find_Unique_Parameterless_Procedure --
6498 -----------------------------------------
6499
6500 function Find_Unique_Parameterless_Procedure
6501 (Name : Entity_Id;
6502 Arg : Node_Id) return Entity_Id
6503 is
6504 Proc : Entity_Id := Empty;
6505
6506 begin
6507 -- The body of this procedure needs some comments ???
6508
6509 if not Is_Entity_Name (Name) then
6510 Error_Pragma_Arg
6511 ("argument of pragma% must be entity name", Arg);
6512
6513 elsif not Is_Overloaded (Name) then
6514 Proc := Entity (Name);
6515
6516 if Ekind (Proc) /= E_Procedure
6517 or else Present (First_Formal (Proc))
6518 then
6519 Error_Pragma_Arg
6520 ("argument of pragma% must be parameterless procedure", Arg);
6521 end if;
6522
6523 else
6524 declare
6525 Found : Boolean := False;
6526 It : Interp;
6527 Index : Interp_Index;
6528
6529 begin
6530 Get_First_Interp (Name, Index, It);
6531 while Present (It.Nam) loop
6532 Proc := It.Nam;
6533
6534 if Ekind (Proc) = E_Procedure
6535 and then No (First_Formal (Proc))
6536 then
6537 if not Found then
6538 Found := True;
6539 Set_Entity (Name, Proc);
6540 Set_Is_Overloaded (Name, False);
6541 else
6542 Error_Pragma_Arg
6543 ("ambiguous handler name for pragma% ", Arg);
6544 end if;
6545 end if;
6546
6547 Get_Next_Interp (Index, It);
6548 end loop;
6549
6550 if not Found then
6551 Error_Pragma_Arg
6552 ("argument of pragma% must be parameterless procedure",
6553 Arg);
6554 else
6555 Proc := Entity (Name);
6556 end if;
6557 end;
6558 end if;
6559
6560 return Proc;
6561 end Find_Unique_Parameterless_Procedure;
6562
6563 ---------------
6564 -- Fix_Error --
6565 ---------------
6566
6567 function Fix_Error (Msg : String) return String is
6568 Res : String (Msg'Range) := Msg;
6569 Res_Last : Natural := Msg'Last;
6570 J : Natural;
6571
6572 begin
6573 -- If we have a rewriting of another pragma, go to that pragma
6574
6575 if Is_Rewrite_Substitution (N)
6576 and then Nkind (Original_Node (N)) = N_Pragma
6577 then
6578 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
6579 end if;
6580
6581 -- Case where pragma comes from an aspect specification
6582
6583 if From_Aspect_Specification (N) then
6584
6585 -- Change appearence of "pragma" in message to "aspect"
6586
6587 J := Res'First;
6588 while J <= Res_Last - 5 loop
6589 if Res (J .. J + 5) = "pragma" then
6590 Res (J .. J + 5) := "aspect";
6591 J := J + 6;
6592
6593 else
6594 J := J + 1;
6595 end if;
6596 end loop;
6597
6598 -- Change "argument of" at start of message to "entity for"
6599
6600 if Res'Length > 11
6601 and then Res (Res'First .. Res'First + 10) = "argument of"
6602 then
6603 Res (Res'First .. Res'First + 9) := "entity for";
6604 Res (Res'First + 10 .. Res_Last - 1) :=
6605 Res (Res'First + 11 .. Res_Last);
6606 Res_Last := Res_Last - 1;
6607 end if;
6608
6609 -- Change "argument" at start of message to "entity"
6610
6611 if Res'Length > 8
6612 and then Res (Res'First .. Res'First + 7) = "argument"
6613 then
6614 Res (Res'First .. Res'First + 5) := "entity";
6615 Res (Res'First + 6 .. Res_Last - 2) :=
6616 Res (Res'First + 8 .. Res_Last);
6617 Res_Last := Res_Last - 2;
6618 end if;
6619
6620 -- Get name from corresponding aspect
6621
6622 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
6623 end if;
6624
6625 -- Return possibly modified message
6626
6627 return Res (Res'First .. Res_Last);
6628 end Fix_Error;
6629
6630 -------------------------
6631 -- Gather_Associations --
6632 -------------------------
6633
6634 procedure Gather_Associations
6635 (Names : Name_List;
6636 Args : out Args_List)
6637 is
6638 Arg : Node_Id;
6639
6640 begin
6641 -- Initialize all parameters to Empty
6642
6643 for J in Args'Range loop
6644 Args (J) := Empty;
6645 end loop;
6646
6647 -- That's all we have to do if there are no argument associations
6648
6649 if No (Pragma_Argument_Associations (N)) then
6650 return;
6651 end if;
6652
6653 -- Otherwise first deal with any positional parameters present
6654
6655 Arg := First (Pragma_Argument_Associations (N));
6656 for Index in Args'Range loop
6657 exit when No (Arg) or else Chars (Arg) /= No_Name;
6658 Args (Index) := Get_Pragma_Arg (Arg);
6659 Next (Arg);
6660 end loop;
6661
6662 -- Positional parameters all processed, if any left, then we
6663 -- have too many positional parameters.
6664
6665 if Present (Arg) and then Chars (Arg) = No_Name then
6666 Error_Pragma_Arg
6667 ("too many positional associations for pragma%", Arg);
6668 end if;
6669
6670 -- Process named parameters if any are present
6671
6672 while Present (Arg) loop
6673 if Chars (Arg) = No_Name then
6674 Error_Pragma_Arg
6675 ("positional association cannot follow named association",
6676 Arg);
6677
6678 else
6679 for Index in Names'Range loop
6680 if Names (Index) = Chars (Arg) then
6681 if Present (Args (Index)) then
6682 Error_Pragma_Arg
6683 ("duplicate argument association for pragma%", Arg);
6684 else
6685 Args (Index) := Get_Pragma_Arg (Arg);
6686 exit;
6687 end if;
6688 end if;
6689
6690 if Index = Names'Last then
6691 Error_Msg_Name_1 := Pname;
6692 Error_Msg_N ("pragma% does not allow & argument", Arg);
6693
6694 -- Check for possible misspelling
6695
6696 for Index1 in Names'Range loop
6697 if Is_Bad_Spelling_Of
6698 (Chars (Arg), Names (Index1))
6699 then
6700 Error_Msg_Name_1 := Names (Index1);
6701 Error_Msg_N -- CODEFIX
6702 ("\possible misspelling of%", Arg);
6703 exit;
6704 end if;
6705 end loop;
6706
6707 raise Pragma_Exit;
6708 end if;
6709 end loop;
6710 end if;
6711
6712 Next (Arg);
6713 end loop;
6714 end Gather_Associations;
6715
6716 -----------------
6717 -- GNAT_Pragma --
6718 -----------------
6719
6720 procedure GNAT_Pragma is
6721 begin
6722 -- We need to check the No_Implementation_Pragmas restriction for
6723 -- the case of a pragma from source. Note that the case of aspects
6724 -- generating corresponding pragmas marks these pragmas as not being
6725 -- from source, so this test also catches that case.
6726
6727 if Comes_From_Source (N) then
6728 Check_Restriction (No_Implementation_Pragmas, N);
6729 end if;
6730 end GNAT_Pragma;
6731
6732 --------------------------
6733 -- Is_Before_First_Decl --
6734 --------------------------
6735
6736 function Is_Before_First_Decl
6737 (Pragma_Node : Node_Id;
6738 Decls : List_Id) return Boolean
6739 is
6740 Item : Node_Id := First (Decls);
6741
6742 begin
6743 -- Only other pragmas can come before this pragma
6744
6745 loop
6746 if No (Item) or else Nkind (Item) /= N_Pragma then
6747 return False;
6748
6749 elsif Item = Pragma_Node then
6750 return True;
6751 end if;
6752
6753 Next (Item);
6754 end loop;
6755 end Is_Before_First_Decl;
6756
6757 -----------------------------
6758 -- Is_Configuration_Pragma --
6759 -----------------------------
6760
6761 -- A configuration pragma must appear in the context clause of a
6762 -- compilation unit, and only other pragmas may precede it. Note that
6763 -- the test below also permits use in a configuration pragma file.
6764
6765 function Is_Configuration_Pragma return Boolean is
6766 Lis : constant List_Id := List_Containing (N);
6767 Par : constant Node_Id := Parent (N);
6768 Prg : Node_Id;
6769
6770 begin
6771 -- If no parent, then we are in the configuration pragma file,
6772 -- so the placement is definitely appropriate.
6773
6774 if No (Par) then
6775 return True;
6776
6777 -- Otherwise we must be in the context clause of a compilation unit
6778 -- and the only thing allowed before us in the context list is more
6779 -- configuration pragmas.
6780
6781 elsif Nkind (Par) = N_Compilation_Unit
6782 and then Context_Items (Par) = Lis
6783 then
6784 Prg := First (Lis);
6785
6786 loop
6787 if Prg = N then
6788 return True;
6789 elsif Nkind (Prg) /= N_Pragma then
6790 return False;
6791 end if;
6792
6793 Next (Prg);
6794 end loop;
6795
6796 else
6797 return False;
6798 end if;
6799 end Is_Configuration_Pragma;
6800
6801 --------------------------
6802 -- Is_In_Context_Clause --
6803 --------------------------
6804
6805 function Is_In_Context_Clause return Boolean is
6806 Plist : List_Id;
6807 Parent_Node : Node_Id;
6808
6809 begin
6810 if not Is_List_Member (N) then
6811 return False;
6812
6813 else
6814 Plist := List_Containing (N);
6815 Parent_Node := Parent (Plist);
6816
6817 if Parent_Node = Empty
6818 or else Nkind (Parent_Node) /= N_Compilation_Unit
6819 or else Context_Items (Parent_Node) /= Plist
6820 then
6821 return False;
6822 end if;
6823 end if;
6824
6825 return True;
6826 end Is_In_Context_Clause;
6827
6828 ---------------------------------
6829 -- Is_Static_String_Expression --
6830 ---------------------------------
6831
6832 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6833 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6834 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
6835
6836 begin
6837 Analyze_And_Resolve (Argx);
6838
6839 -- Special case Ada 83, where the expression will never be static,
6840 -- but we will return true if we had a string literal to start with.
6841
6842 if Ada_Version = Ada_83 then
6843 return Lit;
6844
6845 -- Normal case, true only if we end up with a string literal that
6846 -- is marked as being the result of evaluating a static expression.
6847
6848 else
6849 return Is_OK_Static_Expression (Argx)
6850 and then Nkind (Argx) = N_String_Literal;
6851 end if;
6852
6853 end Is_Static_String_Expression;
6854
6855 ----------------------
6856 -- Pragma_Misplaced --
6857 ----------------------
6858
6859 procedure Pragma_Misplaced is
6860 begin
6861 Error_Pragma ("incorrect placement of pragma%");
6862 end Pragma_Misplaced;
6863
6864 ------------------------------------------------
6865 -- Process_Atomic_Independent_Shared_Volatile --
6866 ------------------------------------------------
6867
6868 procedure Process_Atomic_Independent_Shared_Volatile is
6869 procedure Set_Atomic_VFA (E : Entity_Id);
6870 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6871 -- no explicit alignment was given, set alignment to unknown, since
6872 -- back end knows what the alignment requirements are for atomic and
6873 -- full access arrays. Note: this is necessary for derived types.
6874
6875 --------------------
6876 -- Set_Atomic_VFA --
6877 --------------------
6878
6879 procedure Set_Atomic_VFA (E : Entity_Id) is
6880 begin
6881 if Prag_Id = Pragma_Volatile_Full_Access then
6882 Set_Is_Volatile_Full_Access (E);
6883 else
6884 Set_Is_Atomic (E);
6885 end if;
6886
6887 if not Has_Alignment_Clause (E) then
6888 Set_Alignment (E, Uint_0);
6889 end if;
6890 end Set_Atomic_VFA;
6891
6892 -- Local variables
6893
6894 Decl : Node_Id;
6895 E : Entity_Id;
6896 E_Arg : Node_Id;
6897
6898 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6899
6900 begin
6901 Check_Ada_83_Warning;
6902 Check_No_Identifiers;
6903 Check_Arg_Count (1);
6904 Check_Arg_Is_Local_Name (Arg1);
6905 E_Arg := Get_Pragma_Arg (Arg1);
6906
6907 if Etype (E_Arg) = Any_Type then
6908 return;
6909 end if;
6910
6911 E := Entity (E_Arg);
6912
6913 -- A pragma that applies to a Ghost entity becomes Ghost for the
6914 -- purposes of legality checks and removal of ignored Ghost code.
6915
6916 Mark_Ghost_Pragma (N, E);
6917
6918 -- Check duplicate before we chain ourselves
6919
6920 Check_Duplicate_Pragma (E);
6921
6922 -- Check Atomic and VFA used together
6923
6924 if (Is_Atomic (E) and then Prag_Id = Pragma_Volatile_Full_Access)
6925 or else (Is_Volatile_Full_Access (E)
6926 and then (Prag_Id = Pragma_Atomic
6927 or else
6928 Prag_Id = Pragma_Shared))
6929 then
6930 Error_Pragma
6931 ("cannot have Volatile_Full_Access and Atomic for same entity");
6932 end if;
6933
6934 -- Check for applying VFA to an entity which has aliased component
6935
6936 if Prag_Id = Pragma_Volatile_Full_Access then
6937 declare
6938 Comp : Entity_Id;
6939 Aliased_Comp : Boolean := False;
6940 -- Set True if aliased component present
6941
6942 begin
6943 if Is_Array_Type (Etype (E)) then
6944 Aliased_Comp := Has_Aliased_Components (Etype (E));
6945
6946 -- Record case, too bad Has_Aliased_Components is not also
6947 -- set for records, should it be ???
6948
6949 elsif Is_Record_Type (Etype (E)) then
6950 Comp := First_Component_Or_Discriminant (Etype (E));
6951 while Present (Comp) loop
6952 if Is_Aliased (Comp)
6953 or else Is_Aliased (Etype (Comp))
6954 then
6955 Aliased_Comp := True;
6956 exit;
6957 end if;
6958
6959 Next_Component_Or_Discriminant (Comp);
6960 end loop;
6961 end if;
6962
6963 if Aliased_Comp then
6964 Error_Pragma
6965 ("cannot apply Volatile_Full_Access (aliased component "
6966 & "present)");
6967 end if;
6968 end;
6969 end if;
6970
6971 -- Now check appropriateness of the entity
6972
6973 Decl := Declaration_Node (E);
6974
6975 if Is_Type (E) then
6976 if Rep_Item_Too_Early (E, N)
6977 or else
6978 Rep_Item_Too_Late (E, N)
6979 then
6980 return;
6981 else
6982 Check_First_Subtype (Arg1);
6983 end if;
6984
6985 -- Attribute belongs on the base type. If the view of the type is
6986 -- currently private, it also belongs on the underlying type.
6987
6988 if Prag_Id = Pragma_Atomic
6989 or else
6990 Prag_Id = Pragma_Shared
6991 or else
6992 Prag_Id = Pragma_Volatile_Full_Access
6993 then
6994 Set_Atomic_VFA (E);
6995 Set_Atomic_VFA (Base_Type (E));
6996 Set_Atomic_VFA (Underlying_Type (E));
6997 end if;
6998
6999 -- Atomic/Shared/Volatile_Full_Access imply Independent
7000
7001 if Prag_Id /= Pragma_Volatile then
7002 Set_Is_Independent (E);
7003 Set_Is_Independent (Base_Type (E));
7004 Set_Is_Independent (Underlying_Type (E));
7005
7006 if Prag_Id = Pragma_Independent then
7007 Record_Independence_Check (N, Base_Type (E));
7008 end if;
7009 end if;
7010
7011 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7012
7013 if Prag_Id /= Pragma_Independent then
7014 Set_Is_Volatile (E);
7015 Set_Is_Volatile (Base_Type (E));
7016 Set_Is_Volatile (Underlying_Type (E));
7017
7018 Set_Treat_As_Volatile (E);
7019 Set_Treat_As_Volatile (Underlying_Type (E));
7020 end if;
7021
7022 elsif Nkind (Decl) = N_Object_Declaration
7023 or else (Nkind (Decl) = N_Component_Declaration
7024 and then Original_Record_Component (E) = E)
7025 then
7026 if Rep_Item_Too_Late (E, N) then
7027 return;
7028 end if;
7029
7030 if Prag_Id = Pragma_Atomic
7031 or else
7032 Prag_Id = Pragma_Shared
7033 or else
7034 Prag_Id = Pragma_Volatile_Full_Access
7035 then
7036 if Prag_Id = Pragma_Volatile_Full_Access then
7037 Set_Is_Volatile_Full_Access (E);
7038 else
7039 Set_Is_Atomic (E);
7040 end if;
7041
7042 -- If the object declaration has an explicit initialization, a
7043 -- temporary may have to be created to hold the expression, to
7044 -- ensure that access to the object remain atomic.
7045
7046 if Nkind (Parent (E)) = N_Object_Declaration
7047 and then Present (Expression (Parent (E)))
7048 then
7049 Set_Has_Delayed_Freeze (E);
7050 end if;
7051 end if;
7052
7053 -- Atomic/Shared/Volatile_Full_Access imply Independent
7054
7055 if Prag_Id /= Pragma_Volatile then
7056 Set_Is_Independent (E);
7057
7058 if Prag_Id = Pragma_Independent then
7059 Record_Independence_Check (N, E);
7060 end if;
7061 end if;
7062
7063 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7064
7065 if Prag_Id /= Pragma_Independent then
7066 Set_Is_Volatile (E);
7067 Set_Treat_As_Volatile (E);
7068 end if;
7069
7070 else
7071 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7072 end if;
7073
7074 -- The following check is only relevant when SPARK_Mode is on as
7075 -- this is not a standard Ada legality rule. Pragma Volatile can
7076 -- only apply to a full type declaration or an object declaration
7077 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7078 -- untagged derived types that are rewritten as subtypes of their
7079 -- respective root types.
7080
7081 if SPARK_Mode = On
7082 and then Prag_Id = Pragma_Volatile
7083 and then
7084 not Nkind_In (Original_Node (Decl), N_Full_Type_Declaration,
7085 N_Object_Declaration)
7086 then
7087 Error_Pragma_Arg
7088 ("argument of pragma % must denote a full type or object "
7089 & "declaration", Arg1);
7090 end if;
7091 end Process_Atomic_Independent_Shared_Volatile;
7092
7093 -------------------------------------------
7094 -- Process_Compile_Time_Warning_Or_Error --
7095 -------------------------------------------
7096
7097 procedure Process_Compile_Time_Warning_Or_Error is
7098 Validation_Needed : Boolean := False;
7099
7100 function Check_Node (N : Node_Id) return Traverse_Result;
7101 -- Tree visitor that checks if N is an attribute reference that can
7102 -- be statically computed by the back end. Validation_Needed is set
7103 -- to True if found.
7104
7105 ----------------
7106 -- Check_Node --
7107 ----------------
7108
7109 function Check_Node (N : Node_Id) return Traverse_Result is
7110 begin
7111 if Nkind (N) = N_Attribute_Reference
7112 and then Is_Entity_Name (Prefix (N))
7113 then
7114 declare
7115 Attr_Id : constant Attribute_Id :=
7116 Get_Attribute_Id (Attribute_Name (N));
7117 begin
7118 if Attr_Id = Attribute_Alignment
7119 or else Attr_Id = Attribute_Size
7120 then
7121 Validation_Needed := True;
7122 end if;
7123 end;
7124 end if;
7125
7126 return OK;
7127 end Check_Node;
7128
7129 procedure Check_Expression is new Traverse_Proc (Check_Node);
7130
7131 -- Local variables
7132
7133 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
7134
7135 -- Start of processing for Process_Compile_Time_Warning_Or_Error
7136
7137 begin
7138 Check_Arg_Count (2);
7139 Check_No_Identifiers;
7140 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
7141 Analyze_And_Resolve (Arg1x, Standard_Boolean);
7142
7143 if Compile_Time_Known_Value (Arg1x) then
7144 Process_Compile_Time_Warning_Or_Error (N, Sloc (Arg1));
7145
7146 -- Register the expression for its validation after the back end has
7147 -- been called if it has occurrences of attributes Size or Alignment
7148 -- (because they may be statically computed by the back end and hence
7149 -- the whole expression needs to be reevaluated).
7150
7151 else
7152 Check_Expression (Arg1x);
7153
7154 if Validation_Needed then
7155 Sem_Ch13.Validate_Compile_Time_Warning_Error (N);
7156 end if;
7157 end if;
7158 end Process_Compile_Time_Warning_Or_Error;
7159
7160 ------------------------
7161 -- Process_Convention --
7162 ------------------------
7163
7164 procedure Process_Convention
7165 (C : out Convention_Id;
7166 Ent : out Entity_Id)
7167 is
7168 Cname : Name_Id;
7169
7170 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
7171 -- Called if we have more than one Export/Import/Convention pragma.
7172 -- This is generally illegal, but we have a special case of allowing
7173 -- Import and Interface to coexist if they specify the convention in
7174 -- a consistent manner. We are allowed to do this, since Interface is
7175 -- an implementation defined pragma, and we choose to do it since we
7176 -- know Rational allows this combination. S is the entity id of the
7177 -- subprogram in question. This procedure also sets the special flag
7178 -- Import_Interface_Present in both pragmas in the case where we do
7179 -- have matching Import and Interface pragmas.
7180
7181 procedure Set_Convention_From_Pragma (E : Entity_Id);
7182 -- Set convention in entity E, and also flag that the entity has a
7183 -- convention pragma. If entity is for a private or incomplete type,
7184 -- also set convention and flag on underlying type. This procedure
7185 -- also deals with the special case of C_Pass_By_Copy convention,
7186 -- and error checks for inappropriate convention specification.
7187
7188 -------------------------------
7189 -- Diagnose_Multiple_Pragmas --
7190 -------------------------------
7191
7192 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
7193 Pdec : constant Node_Id := Declaration_Node (S);
7194 Decl : Node_Id;
7195 Err : Boolean;
7196
7197 function Same_Convention (Decl : Node_Id) return Boolean;
7198 -- Decl is a pragma node. This function returns True if this
7199 -- pragma has a first argument that is an identifier with a
7200 -- Chars field corresponding to the Convention_Id C.
7201
7202 function Same_Name (Decl : Node_Id) return Boolean;
7203 -- Decl is a pragma node. This function returns True if this
7204 -- pragma has a second argument that is an identifier with a
7205 -- Chars field that matches the Chars of the current subprogram.
7206
7207 ---------------------
7208 -- Same_Convention --
7209 ---------------------
7210
7211 function Same_Convention (Decl : Node_Id) return Boolean is
7212 Arg1 : constant Node_Id :=
7213 First (Pragma_Argument_Associations (Decl));
7214
7215 begin
7216 if Present (Arg1) then
7217 declare
7218 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
7219 begin
7220 if Nkind (Arg) = N_Identifier
7221 and then Is_Convention_Name (Chars (Arg))
7222 and then Get_Convention_Id (Chars (Arg)) = C
7223 then
7224 return True;
7225 end if;
7226 end;
7227 end if;
7228
7229 return False;
7230 end Same_Convention;
7231
7232 ---------------
7233 -- Same_Name --
7234 ---------------
7235
7236 function Same_Name (Decl : Node_Id) return Boolean is
7237 Arg1 : constant Node_Id :=
7238 First (Pragma_Argument_Associations (Decl));
7239 Arg2 : Node_Id;
7240
7241 begin
7242 if No (Arg1) then
7243 return False;
7244 end if;
7245
7246 Arg2 := Next (Arg1);
7247
7248 if No (Arg2) then
7249 return False;
7250 end if;
7251
7252 declare
7253 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
7254 begin
7255 if Nkind (Arg) = N_Identifier
7256 and then Chars (Arg) = Chars (S)
7257 then
7258 return True;
7259 end if;
7260 end;
7261
7262 return False;
7263 end Same_Name;
7264
7265 -- Start of processing for Diagnose_Multiple_Pragmas
7266
7267 begin
7268 Err := True;
7269
7270 -- Definitely give message if we have Convention/Export here
7271
7272 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
7273 null;
7274
7275 -- If we have an Import or Export, scan back from pragma to
7276 -- find any previous pragma applying to the same procedure.
7277 -- The scan will be terminated by the start of the list, or
7278 -- hitting the subprogram declaration. This won't allow one
7279 -- pragma to appear in the public part and one in the private
7280 -- part, but that seems very unlikely in practice.
7281
7282 else
7283 Decl := Prev (N);
7284 while Present (Decl) and then Decl /= Pdec loop
7285
7286 -- Look for pragma with same name as us
7287
7288 if Nkind (Decl) = N_Pragma
7289 and then Same_Name (Decl)
7290 then
7291 -- Give error if same as our pragma or Export/Convention
7292
7293 if Nam_In (Pragma_Name_Unmapped (Decl),
7294 Name_Export,
7295 Name_Convention,
7296 Pragma_Name_Unmapped (N))
7297 then
7298 exit;
7299
7300 -- Case of Import/Interface or the other way round
7301
7302 elsif Nam_In (Pragma_Name_Unmapped (Decl),
7303 Name_Interface, Name_Import)
7304 then
7305 -- Here we know that we have Import and Interface. It
7306 -- doesn't matter which way round they are. See if
7307 -- they specify the same convention. If so, all OK,
7308 -- and set special flags to stop other messages
7309
7310 if Same_Convention (Decl) then
7311 Set_Import_Interface_Present (N);
7312 Set_Import_Interface_Present (Decl);
7313 Err := False;
7314
7315 -- If different conventions, special message
7316
7317 else
7318 Error_Msg_Sloc := Sloc (Decl);
7319 Error_Pragma_Arg
7320 ("convention differs from that given#", Arg1);
7321 return;
7322 end if;
7323 end if;
7324 end if;
7325
7326 Next (Decl);
7327 end loop;
7328 end if;
7329
7330 -- Give message if needed if we fall through those tests
7331 -- except on Relaxed_RM_Semantics where we let go: either this
7332 -- is a case accepted/ignored by other Ada compilers (e.g.
7333 -- a mix of Convention and Import), or another error will be
7334 -- generated later (e.g. using both Import and Export).
7335
7336 if Err and not Relaxed_RM_Semantics then
7337 Error_Pragma_Arg
7338 ("at most one Convention/Export/Import pragma is allowed",
7339 Arg2);
7340 end if;
7341 end Diagnose_Multiple_Pragmas;
7342
7343 --------------------------------
7344 -- Set_Convention_From_Pragma --
7345 --------------------------------
7346
7347 procedure Set_Convention_From_Pragma (E : Entity_Id) is
7348 begin
7349 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7350 -- for an overridden dispatching operation. Technically this is
7351 -- an amendment and should only be done in Ada 2005 mode. However,
7352 -- this is clearly a mistake, since the problem that is addressed
7353 -- by this AI is that there is a clear gap in the RM.
7354
7355 if Is_Dispatching_Operation (E)
7356 and then Present (Overridden_Operation (E))
7357 and then C /= Convention (Overridden_Operation (E))
7358 then
7359 Error_Pragma_Arg
7360 ("cannot change convention for overridden dispatching "
7361 & "operation", Arg1);
7362 end if;
7363
7364 -- Special checks for Convention_Stdcall
7365
7366 if C = Convention_Stdcall then
7367
7368 -- A dispatching call is not allowed. A dispatching subprogram
7369 -- cannot be used to interface to the Win32 API, so in fact
7370 -- this check does not impose any effective restriction.
7371
7372 if Is_Dispatching_Operation (E) then
7373 Error_Msg_Sloc := Sloc (E);
7374
7375 -- Note: make this unconditional so that if there is more
7376 -- than one call to which the pragma applies, we get a
7377 -- message for each call. Also don't use Error_Pragma,
7378 -- so that we get multiple messages.
7379
7380 Error_Msg_N
7381 ("dispatching subprogram# cannot use Stdcall convention!",
7382 Arg1);
7383
7384 -- Several allowed cases
7385
7386 elsif Is_Subprogram_Or_Generic_Subprogram (E)
7387
7388 -- A variable is OK
7389
7390 or else Ekind (E) = E_Variable
7391
7392 -- A component as well. The entity does not have its Ekind
7393 -- set until the enclosing record declaration is fully
7394 -- analyzed.
7395
7396 or else Nkind (Parent (E)) = N_Component_Declaration
7397
7398 -- An access to subprogram is also allowed
7399
7400 or else
7401 (Is_Access_Type (E)
7402 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
7403
7404 -- Allow internal call to set convention of subprogram type
7405
7406 or else Ekind (E) = E_Subprogram_Type
7407 then
7408 null;
7409
7410 else
7411 Error_Pragma_Arg
7412 ("second argument of pragma% must be subprogram (type)",
7413 Arg2);
7414 end if;
7415 end if;
7416
7417 -- Set the convention
7418
7419 Set_Convention (E, C);
7420 Set_Has_Convention_Pragma (E);
7421
7422 -- For the case of a record base type, also set the convention of
7423 -- any anonymous access types declared in the record which do not
7424 -- currently have a specified convention.
7425
7426 if Is_Record_Type (E) and then Is_Base_Type (E) then
7427 declare
7428 Comp : Node_Id;
7429
7430 begin
7431 Comp := First_Component (E);
7432 while Present (Comp) loop
7433 if Present (Etype (Comp))
7434 and then Ekind_In (Etype (Comp),
7435 E_Anonymous_Access_Type,
7436 E_Anonymous_Access_Subprogram_Type)
7437 and then not Has_Convention_Pragma (Comp)
7438 then
7439 Set_Convention (Comp, C);
7440 end if;
7441
7442 Next_Component (Comp);
7443 end loop;
7444 end;
7445 end if;
7446
7447 -- Deal with incomplete/private type case, where underlying type
7448 -- is available, so set convention of that underlying type.
7449
7450 if Is_Incomplete_Or_Private_Type (E)
7451 and then Present (Underlying_Type (E))
7452 then
7453 Set_Convention (Underlying_Type (E), C);
7454 Set_Has_Convention_Pragma (Underlying_Type (E), True);
7455 end if;
7456
7457 -- A class-wide type should inherit the convention of the specific
7458 -- root type (although this isn't specified clearly by the RM).
7459
7460 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
7461 Set_Convention (Class_Wide_Type (E), C);
7462 end if;
7463
7464 -- If the entity is a record type, then check for special case of
7465 -- C_Pass_By_Copy, which is treated the same as C except that the
7466 -- special record flag is set. This convention is only permitted
7467 -- on record types (see AI95-00131).
7468
7469 if Cname = Name_C_Pass_By_Copy then
7470 if Is_Record_Type (E) then
7471 Set_C_Pass_By_Copy (Base_Type (E));
7472 elsif Is_Incomplete_Or_Private_Type (E)
7473 and then Is_Record_Type (Underlying_Type (E))
7474 then
7475 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
7476 else
7477 Error_Pragma_Arg
7478 ("C_Pass_By_Copy convention allowed only for record type",
7479 Arg2);
7480 end if;
7481 end if;
7482
7483 -- If the entity is a derived boolean type, check for the special
7484 -- case of convention C, C++, or Fortran, where we consider any
7485 -- nonzero value to represent true.
7486
7487 if Is_Discrete_Type (E)
7488 and then Root_Type (Etype (E)) = Standard_Boolean
7489 and then
7490 (C = Convention_C
7491 or else
7492 C = Convention_CPP
7493 or else
7494 C = Convention_Fortran)
7495 then
7496 Set_Nonzero_Is_True (Base_Type (E));
7497 end if;
7498 end Set_Convention_From_Pragma;
7499
7500 -- Local variables
7501
7502 Comp_Unit : Unit_Number_Type;
7503 E : Entity_Id;
7504 E1 : Entity_Id;
7505 Id : Node_Id;
7506
7507 -- Start of processing for Process_Convention
7508
7509 begin
7510 Check_At_Least_N_Arguments (2);
7511 Check_Optional_Identifier (Arg1, Name_Convention);
7512 Check_Arg_Is_Identifier (Arg1);
7513 Cname := Chars (Get_Pragma_Arg (Arg1));
7514
7515 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7516 -- tested again below to set the critical flag).
7517
7518 if Cname = Name_C_Pass_By_Copy then
7519 C := Convention_C;
7520
7521 -- Otherwise we must have something in the standard convention list
7522
7523 elsif Is_Convention_Name (Cname) then
7524 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
7525
7526 -- Otherwise warn on unrecognized convention
7527
7528 else
7529 if Warn_On_Export_Import then
7530 Error_Msg_N
7531 ("??unrecognized convention name, C assumed",
7532 Get_Pragma_Arg (Arg1));
7533 end if;
7534
7535 C := Convention_C;
7536 end if;
7537
7538 Check_Optional_Identifier (Arg2, Name_Entity);
7539 Check_Arg_Is_Local_Name (Arg2);
7540
7541 Id := Get_Pragma_Arg (Arg2);
7542 Analyze (Id);
7543
7544 if not Is_Entity_Name (Id) then
7545 Error_Pragma_Arg ("entity name required", Arg2);
7546 end if;
7547
7548 E := Entity (Id);
7549
7550 -- Set entity to return
7551
7552 Ent := E;
7553
7554 -- Ada_Pass_By_Copy special checking
7555
7556 if C = Convention_Ada_Pass_By_Copy then
7557 if not Is_First_Subtype (E) then
7558 Error_Pragma_Arg
7559 ("convention `Ada_Pass_By_Copy` only allowed for types",
7560 Arg2);
7561 end if;
7562
7563 if Is_By_Reference_Type (E) then
7564 Error_Pragma_Arg
7565 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7566 & "type", Arg1);
7567 end if;
7568
7569 -- Ada_Pass_By_Reference special checking
7570
7571 elsif C = Convention_Ada_Pass_By_Reference then
7572 if not Is_First_Subtype (E) then
7573 Error_Pragma_Arg
7574 ("convention `Ada_Pass_By_Reference` only allowed for types",
7575 Arg2);
7576 end if;
7577
7578 if Is_By_Copy_Type (E) then
7579 Error_Pragma_Arg
7580 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7581 & "type", Arg1);
7582 end if;
7583 end if;
7584
7585 -- Go to renamed subprogram if present, since convention applies to
7586 -- the actual renamed entity, not to the renaming entity. If the
7587 -- subprogram is inherited, go to parent subprogram.
7588
7589 if Is_Subprogram (E)
7590 and then Present (Alias (E))
7591 then
7592 if Nkind (Parent (Declaration_Node (E))) =
7593 N_Subprogram_Renaming_Declaration
7594 then
7595 if Scope (E) /= Scope (Alias (E)) then
7596 Error_Pragma_Ref
7597 ("cannot apply pragma% to non-local entity&#", E);
7598 end if;
7599
7600 E := Alias (E);
7601
7602 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
7603 N_Private_Extension_Declaration)
7604 and then Scope (E) = Scope (Alias (E))
7605 then
7606 E := Alias (E);
7607
7608 -- Return the parent subprogram the entity was inherited from
7609
7610 Ent := E;
7611 end if;
7612 end if;
7613
7614 -- Check that we are not applying this to a specless body. Relax this
7615 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
7616
7617 if Is_Subprogram (E)
7618 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
7619 and then not Relaxed_RM_Semantics
7620 then
7621 Error_Pragma
7622 ("pragma% requires separate spec and must come before body");
7623 end if;
7624
7625 -- Check that we are not applying this to a named constant
7626
7627 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
7628 Error_Msg_Name_1 := Pname;
7629 Error_Msg_N
7630 ("cannot apply pragma% to named constant!",
7631 Get_Pragma_Arg (Arg2));
7632 Error_Pragma_Arg
7633 ("\supply appropriate type for&!", Arg2);
7634 end if;
7635
7636 if Ekind (E) = E_Enumeration_Literal then
7637 Error_Pragma ("enumeration literal not allowed for pragma%");
7638 end if;
7639
7640 -- Check for rep item appearing too early or too late
7641
7642 if Etype (E) = Any_Type
7643 or else Rep_Item_Too_Early (E, N)
7644 then
7645 raise Pragma_Exit;
7646
7647 elsif Present (Underlying_Type (E)) then
7648 E := Underlying_Type (E);
7649 end if;
7650
7651 if Rep_Item_Too_Late (E, N) then
7652 raise Pragma_Exit;
7653 end if;
7654
7655 if Has_Convention_Pragma (E) then
7656 Diagnose_Multiple_Pragmas (E);
7657
7658 elsif Convention (E) = Convention_Protected
7659 or else Ekind (Scope (E)) = E_Protected_Type
7660 then
7661 Error_Pragma_Arg
7662 ("a protected operation cannot be given a different convention",
7663 Arg2);
7664 end if;
7665
7666 -- For Intrinsic, a subprogram is required
7667
7668 if C = Convention_Intrinsic
7669 and then not Is_Subprogram_Or_Generic_Subprogram (E)
7670 then
7671 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7672
7673 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
7674 Error_Pragma_Arg
7675 ("second argument of pragma% must be a subprogram", Arg2);
7676 end if;
7677 end if;
7678
7679 -- Deal with non-subprogram cases
7680
7681 if not Is_Subprogram_Or_Generic_Subprogram (E) then
7682 Set_Convention_From_Pragma (E);
7683
7684 if Is_Type (E) then
7685
7686 -- The pragma must apply to a first subtype, but it can also
7687 -- apply to a generic type in a generic formal part, in which
7688 -- case it will also appear in the corresponding instance.
7689
7690 if Is_Generic_Type (E) or else In_Instance then
7691 null;
7692 else
7693 Check_First_Subtype (Arg2);
7694 end if;
7695
7696 Set_Convention_From_Pragma (Base_Type (E));
7697
7698 -- For access subprograms, we must set the convention on the
7699 -- internally generated directly designated type as well.
7700
7701 if Ekind (E) = E_Access_Subprogram_Type then
7702 Set_Convention_From_Pragma (Directly_Designated_Type (E));
7703 end if;
7704 end if;
7705
7706 -- For the subprogram case, set proper convention for all homonyms
7707 -- in same scope and the same declarative part, i.e. the same
7708 -- compilation unit.
7709
7710 else
7711 Comp_Unit := Get_Source_Unit (E);
7712 Set_Convention_From_Pragma (E);
7713
7714 -- Treat a pragma Import as an implicit body, and pragma import
7715 -- as implicit reference (for navigation in GPS).
7716
7717 if Prag_Id = Pragma_Import then
7718 Generate_Reference (E, Id, 'b');
7719
7720 -- For exported entities we restrict the generation of references
7721 -- to entities exported to foreign languages since entities
7722 -- exported to Ada do not provide further information to GPS and
7723 -- add undesired references to the output of the gnatxref tool.
7724
7725 elsif Prag_Id = Pragma_Export
7726 and then Convention (E) /= Convention_Ada
7727 then
7728 Generate_Reference (E, Id, 'i');
7729 end if;
7730
7731 -- If the pragma comes from an aspect, it only applies to the
7732 -- given entity, not its homonyms.
7733
7734 if From_Aspect_Specification (N) then
7735 return;
7736 end if;
7737
7738 -- Otherwise Loop through the homonyms of the pragma argument's
7739 -- entity, an apply convention to those in the current scope.
7740
7741 E1 := Ent;
7742
7743 loop
7744 E1 := Homonym (E1);
7745 exit when No (E1) or else Scope (E1) /= Current_Scope;
7746
7747 -- Ignore entry for which convention is already set
7748
7749 if Has_Convention_Pragma (E1) then
7750 goto Continue;
7751 end if;
7752
7753 if Is_Subprogram (E1)
7754 and then Nkind (Parent (Declaration_Node (E1))) =
7755 N_Subprogram_Body
7756 and then not Relaxed_RM_Semantics
7757 then
7758 Set_Has_Completion (E); -- to prevent cascaded error
7759 Error_Pragma_Ref
7760 ("pragma% requires separate spec and must come before "
7761 & "body#", E1);
7762 end if;
7763
7764 -- Do not set the pragma on inherited operations or on formal
7765 -- subprograms.
7766
7767 if Comes_From_Source (E1)
7768 and then Comp_Unit = Get_Source_Unit (E1)
7769 and then not Is_Formal_Subprogram (E1)
7770 and then Nkind (Original_Node (Parent (E1))) /=
7771 N_Full_Type_Declaration
7772 then
7773 if Present (Alias (E1))
7774 and then Scope (E1) /= Scope (Alias (E1))
7775 then
7776 Error_Pragma_Ref
7777 ("cannot apply pragma% to non-local entity& declared#",
7778 E1);
7779 end if;
7780
7781 Set_Convention_From_Pragma (E1);
7782
7783 if Prag_Id = Pragma_Import then
7784 Generate_Reference (E1, Id, 'b');
7785 end if;
7786 end if;
7787
7788 <<Continue>>
7789 null;
7790 end loop;
7791 end if;
7792 end Process_Convention;
7793
7794 ----------------------------------------
7795 -- Process_Disable_Enable_Atomic_Sync --
7796 ----------------------------------------
7797
7798 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7799 begin
7800 Check_No_Identifiers;
7801 Check_At_Most_N_Arguments (1);
7802
7803 -- Modeled internally as
7804 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7805
7806 Rewrite (N,
7807 Make_Pragma (Loc,
7808 Chars => Nam,
7809 Pragma_Argument_Associations => New_List (
7810 Make_Pragma_Argument_Association (Loc,
7811 Expression =>
7812 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7813
7814 if Present (Arg1) then
7815 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7816 end if;
7817
7818 Analyze (N);
7819 end Process_Disable_Enable_Atomic_Sync;
7820
7821 -------------------------------------------------
7822 -- Process_Extended_Import_Export_Internal_Arg --
7823 -------------------------------------------------
7824
7825 procedure Process_Extended_Import_Export_Internal_Arg
7826 (Arg_Internal : Node_Id := Empty)
7827 is
7828 begin
7829 if No (Arg_Internal) then
7830 Error_Pragma ("Internal parameter required for pragma%");
7831 end if;
7832
7833 if Nkind (Arg_Internal) = N_Identifier then
7834 null;
7835
7836 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7837 and then (Prag_Id = Pragma_Import_Function
7838 or else
7839 Prag_Id = Pragma_Export_Function)
7840 then
7841 null;
7842
7843 else
7844 Error_Pragma_Arg
7845 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7846 end if;
7847
7848 Check_Arg_Is_Local_Name (Arg_Internal);
7849 end Process_Extended_Import_Export_Internal_Arg;
7850
7851 --------------------------------------------------
7852 -- Process_Extended_Import_Export_Object_Pragma --
7853 --------------------------------------------------
7854
7855 procedure Process_Extended_Import_Export_Object_Pragma
7856 (Arg_Internal : Node_Id;
7857 Arg_External : Node_Id;
7858 Arg_Size : Node_Id)
7859 is
7860 Def_Id : Entity_Id;
7861
7862 begin
7863 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7864 Def_Id := Entity (Arg_Internal);
7865
7866 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7867 Error_Pragma_Arg
7868 ("pragma% must designate an object", Arg_Internal);
7869 end if;
7870
7871 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7872 or else
7873 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7874 then
7875 Error_Pragma_Arg
7876 ("previous Common/Psect_Object applies, pragma % not permitted",
7877 Arg_Internal);
7878 end if;
7879
7880 if Rep_Item_Too_Late (Def_Id, N) then
7881 raise Pragma_Exit;
7882 end if;
7883
7884 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7885
7886 if Present (Arg_Size) then
7887 Check_Arg_Is_External_Name (Arg_Size);
7888 end if;
7889
7890 -- Export_Object case
7891
7892 if Prag_Id = Pragma_Export_Object then
7893 if not Is_Library_Level_Entity (Def_Id) then
7894 Error_Pragma_Arg
7895 ("argument for pragma% must be library level entity",
7896 Arg_Internal);
7897 end if;
7898
7899 if Ekind (Current_Scope) = E_Generic_Package then
7900 Error_Pragma ("pragma& cannot appear in a generic unit");
7901 end if;
7902
7903 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7904 Error_Pragma_Arg
7905 ("exported object must have compile time known size",
7906 Arg_Internal);
7907 end if;
7908
7909 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7910 Error_Msg_N ("??duplicate Export_Object pragma", N);
7911 else
7912 Set_Exported (Def_Id, Arg_Internal);
7913 end if;
7914
7915 -- Import_Object case
7916
7917 else
7918 if Is_Concurrent_Type (Etype (Def_Id)) then
7919 Error_Pragma_Arg
7920 ("cannot use pragma% for task/protected object",
7921 Arg_Internal);
7922 end if;
7923
7924 if Ekind (Def_Id) = E_Constant then
7925 Error_Pragma_Arg
7926 ("cannot import a constant", Arg_Internal);
7927 end if;
7928
7929 if Warn_On_Export_Import
7930 and then Has_Discriminants (Etype (Def_Id))
7931 then
7932 Error_Msg_N
7933 ("imported value must be initialized??", Arg_Internal);
7934 end if;
7935
7936 if Warn_On_Export_Import
7937 and then Is_Access_Type (Etype (Def_Id))
7938 then
7939 Error_Pragma_Arg
7940 ("cannot import object of an access type??", Arg_Internal);
7941 end if;
7942
7943 if Warn_On_Export_Import
7944 and then Is_Imported (Def_Id)
7945 then
7946 Error_Msg_N ("??duplicate Import_Object pragma", N);
7947
7948 -- Check for explicit initialization present. Note that an
7949 -- initialization generated by the code generator, e.g. for an
7950 -- access type, does not count here.
7951
7952 elsif Present (Expression (Parent (Def_Id)))
7953 and then
7954 Comes_From_Source
7955 (Original_Node (Expression (Parent (Def_Id))))
7956 then
7957 Error_Msg_Sloc := Sloc (Def_Id);
7958 Error_Pragma_Arg
7959 ("imported entities cannot be initialized (RM B.1(24))",
7960 "\no initialization allowed for & declared#", Arg1);
7961 else
7962 Set_Imported (Def_Id);
7963 Note_Possible_Modification (Arg_Internal, Sure => False);
7964 end if;
7965 end if;
7966 end Process_Extended_Import_Export_Object_Pragma;
7967
7968 ------------------------------------------------------
7969 -- Process_Extended_Import_Export_Subprogram_Pragma --
7970 ------------------------------------------------------
7971
7972 procedure Process_Extended_Import_Export_Subprogram_Pragma
7973 (Arg_Internal : Node_Id;
7974 Arg_External : Node_Id;
7975 Arg_Parameter_Types : Node_Id;
7976 Arg_Result_Type : Node_Id := Empty;
7977 Arg_Mechanism : Node_Id;
7978 Arg_Result_Mechanism : Node_Id := Empty)
7979 is
7980 Ent : Entity_Id;
7981 Def_Id : Entity_Id;
7982 Hom_Id : Entity_Id;
7983 Formal : Entity_Id;
7984 Ambiguous : Boolean;
7985 Match : Boolean;
7986
7987 function Same_Base_Type
7988 (Ptype : Node_Id;
7989 Formal : Entity_Id) return Boolean;
7990 -- Determines if Ptype references the type of Formal. Note that only
7991 -- the base types need to match according to the spec. Ptype here is
7992 -- the argument from the pragma, which is either a type name, or an
7993 -- access attribute.
7994
7995 --------------------
7996 -- Same_Base_Type --
7997 --------------------
7998
7999 function Same_Base_Type
8000 (Ptype : Node_Id;
8001 Formal : Entity_Id) return Boolean
8002 is
8003 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
8004 Pref : Node_Id;
8005
8006 begin
8007 -- Case where pragma argument is typ'Access
8008
8009 if Nkind (Ptype) = N_Attribute_Reference
8010 and then Attribute_Name (Ptype) = Name_Access
8011 then
8012 Pref := Prefix (Ptype);
8013 Find_Type (Pref);
8014
8015 if not Is_Entity_Name (Pref)
8016 or else Entity (Pref) = Any_Type
8017 then
8018 raise Pragma_Exit;
8019 end if;
8020
8021 -- We have a match if the corresponding argument is of an
8022 -- anonymous access type, and its designated type matches the
8023 -- type of the prefix of the access attribute
8024
8025 return Ekind (Ftyp) = E_Anonymous_Access_Type
8026 and then Base_Type (Entity (Pref)) =
8027 Base_Type (Etype (Designated_Type (Ftyp)));
8028
8029 -- Case where pragma argument is a type name
8030
8031 else
8032 Find_Type (Ptype);
8033
8034 if not Is_Entity_Name (Ptype)
8035 or else Entity (Ptype) = Any_Type
8036 then
8037 raise Pragma_Exit;
8038 end if;
8039
8040 -- We have a match if the corresponding argument is of the type
8041 -- given in the pragma (comparing base types)
8042
8043 return Base_Type (Entity (Ptype)) = Ftyp;
8044 end if;
8045 end Same_Base_Type;
8046
8047 -- Start of processing for
8048 -- Process_Extended_Import_Export_Subprogram_Pragma
8049
8050 begin
8051 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
8052 Ent := Empty;
8053 Ambiguous := False;
8054
8055 -- Loop through homonyms (overloadings) of the entity
8056
8057 Hom_Id := Entity (Arg_Internal);
8058 while Present (Hom_Id) loop
8059 Def_Id := Get_Base_Subprogram (Hom_Id);
8060
8061 -- We need a subprogram in the current scope
8062
8063 if not Is_Subprogram (Def_Id)
8064 or else Scope (Def_Id) /= Current_Scope
8065 then
8066 null;
8067
8068 else
8069 Match := True;
8070
8071 -- Pragma cannot apply to subprogram body
8072
8073 if Is_Subprogram (Def_Id)
8074 and then Nkind (Parent (Declaration_Node (Def_Id))) =
8075 N_Subprogram_Body
8076 then
8077 Error_Pragma
8078 ("pragma% requires separate spec and must come before "
8079 & "body");
8080 end if;
8081
8082 -- Test result type if given, note that the result type
8083 -- parameter can only be present for the function cases.
8084
8085 if Present (Arg_Result_Type)
8086 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
8087 then
8088 Match := False;
8089
8090 elsif Etype (Def_Id) /= Standard_Void_Type
8091 and then Nam_In (Pname, Name_Export_Procedure,
8092 Name_Import_Procedure)
8093 then
8094 Match := False;
8095
8096 -- Test parameter types if given. Note that this parameter has
8097 -- not been analyzed (and must not be, since it is semantic
8098 -- nonsense), so we get it as the parser left it.
8099
8100 elsif Present (Arg_Parameter_Types) then
8101 Check_Matching_Types : declare
8102 Formal : Entity_Id;
8103 Ptype : Node_Id;
8104
8105 begin
8106 Formal := First_Formal (Def_Id);
8107
8108 if Nkind (Arg_Parameter_Types) = N_Null then
8109 if Present (Formal) then
8110 Match := False;
8111 end if;
8112
8113 -- A list of one type, e.g. (List) is parsed as a
8114 -- parenthesized expression.
8115
8116 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
8117 and then Paren_Count (Arg_Parameter_Types) = 1
8118 then
8119 if No (Formal)
8120 or else Present (Next_Formal (Formal))
8121 then
8122 Match := False;
8123 else
8124 Match :=
8125 Same_Base_Type (Arg_Parameter_Types, Formal);
8126 end if;
8127
8128 -- A list of more than one type is parsed as a aggregate
8129
8130 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
8131 and then Paren_Count (Arg_Parameter_Types) = 0
8132 then
8133 Ptype := First (Expressions (Arg_Parameter_Types));
8134 while Present (Ptype) or else Present (Formal) loop
8135 if No (Ptype)
8136 or else No (Formal)
8137 or else not Same_Base_Type (Ptype, Formal)
8138 then
8139 Match := False;
8140 exit;
8141 else
8142 Next_Formal (Formal);
8143 Next (Ptype);
8144 end if;
8145 end loop;
8146
8147 -- Anything else is of the wrong form
8148
8149 else
8150 Error_Pragma_Arg
8151 ("wrong form for Parameter_Types parameter",
8152 Arg_Parameter_Types);
8153 end if;
8154 end Check_Matching_Types;
8155 end if;
8156
8157 -- Match is now False if the entry we found did not match
8158 -- either a supplied Parameter_Types or Result_Types argument
8159
8160 if Match then
8161 if No (Ent) then
8162 Ent := Def_Id;
8163
8164 -- Ambiguous case, the flag Ambiguous shows if we already
8165 -- detected this and output the initial messages.
8166
8167 else
8168 if not Ambiguous then
8169 Ambiguous := True;
8170 Error_Msg_Name_1 := Pname;
8171 Error_Msg_N
8172 ("pragma% does not uniquely identify subprogram!",
8173 N);
8174 Error_Msg_Sloc := Sloc (Ent);
8175 Error_Msg_N ("matching subprogram #!", N);
8176 Ent := Empty;
8177 end if;
8178
8179 Error_Msg_Sloc := Sloc (Def_Id);
8180 Error_Msg_N ("matching subprogram #!", N);
8181 end if;
8182 end if;
8183 end if;
8184
8185 Hom_Id := Homonym (Hom_Id);
8186 end loop;
8187
8188 -- See if we found an entry
8189
8190 if No (Ent) then
8191 if not Ambiguous then
8192 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
8193 Error_Pragma
8194 ("pragma% cannot be given for generic subprogram");
8195 else
8196 Error_Pragma
8197 ("pragma% does not identify local subprogram");
8198 end if;
8199 end if;
8200
8201 return;
8202 end if;
8203
8204 -- Import pragmas must be for imported entities
8205
8206 if Prag_Id = Pragma_Import_Function
8207 or else
8208 Prag_Id = Pragma_Import_Procedure
8209 or else
8210 Prag_Id = Pragma_Import_Valued_Procedure
8211 then
8212 if not Is_Imported (Ent) then
8213 Error_Pragma
8214 ("pragma Import or Interface must precede pragma%");
8215 end if;
8216
8217 -- Here we have the Export case which can set the entity as exported
8218
8219 -- But does not do so if the specified external name is null, since
8220 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8221 -- compatible) to request no external name.
8222
8223 elsif Nkind (Arg_External) = N_String_Literal
8224 and then String_Length (Strval (Arg_External)) = 0
8225 then
8226 null;
8227
8228 -- In all other cases, set entity as exported
8229
8230 else
8231 Set_Exported (Ent, Arg_Internal);
8232 end if;
8233
8234 -- Special processing for Valued_Procedure cases
8235
8236 if Prag_Id = Pragma_Import_Valued_Procedure
8237 or else
8238 Prag_Id = Pragma_Export_Valued_Procedure
8239 then
8240 Formal := First_Formal (Ent);
8241
8242 if No (Formal) then
8243 Error_Pragma ("at least one parameter required for pragma%");
8244
8245 elsif Ekind (Formal) /= E_Out_Parameter then
8246 Error_Pragma ("first parameter must have mode out for pragma%");
8247
8248 else
8249 Set_Is_Valued_Procedure (Ent);
8250 end if;
8251 end if;
8252
8253 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
8254
8255 -- Process Result_Mechanism argument if present. We have already
8256 -- checked that this is only allowed for the function case.
8257
8258 if Present (Arg_Result_Mechanism) then
8259 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
8260 end if;
8261
8262 -- Process Mechanism parameter if present. Note that this parameter
8263 -- is not analyzed, and must not be analyzed since it is semantic
8264 -- nonsense, so we get it in exactly as the parser left it.
8265
8266 if Present (Arg_Mechanism) then
8267 declare
8268 Formal : Entity_Id;
8269 Massoc : Node_Id;
8270 Mname : Node_Id;
8271 Choice : Node_Id;
8272
8273 begin
8274 -- A single mechanism association without a formal parameter
8275 -- name is parsed as a parenthesized expression. All other
8276 -- cases are parsed as aggregates, so we rewrite the single
8277 -- parameter case as an aggregate for consistency.
8278
8279 if Nkind (Arg_Mechanism) /= N_Aggregate
8280 and then Paren_Count (Arg_Mechanism) = 1
8281 then
8282 Rewrite (Arg_Mechanism,
8283 Make_Aggregate (Sloc (Arg_Mechanism),
8284 Expressions => New_List (
8285 Relocate_Node (Arg_Mechanism))));
8286 end if;
8287
8288 -- Case of only mechanism name given, applies to all formals
8289
8290 if Nkind (Arg_Mechanism) /= N_Aggregate then
8291 Formal := First_Formal (Ent);
8292 while Present (Formal) loop
8293 Set_Mechanism_Value (Formal, Arg_Mechanism);
8294 Next_Formal (Formal);
8295 end loop;
8296
8297 -- Case of list of mechanism associations given
8298
8299 else
8300 if Null_Record_Present (Arg_Mechanism) then
8301 Error_Pragma_Arg
8302 ("inappropriate form for Mechanism parameter",
8303 Arg_Mechanism);
8304 end if;
8305
8306 -- Deal with positional ones first
8307
8308 Formal := First_Formal (Ent);
8309
8310 if Present (Expressions (Arg_Mechanism)) then
8311 Mname := First (Expressions (Arg_Mechanism));
8312 while Present (Mname) loop
8313 if No (Formal) then
8314 Error_Pragma_Arg
8315 ("too many mechanism associations", Mname);
8316 end if;
8317
8318 Set_Mechanism_Value (Formal, Mname);
8319 Next_Formal (Formal);
8320 Next (Mname);
8321 end loop;
8322 end if;
8323
8324 -- Deal with named entries
8325
8326 if Present (Component_Associations (Arg_Mechanism)) then
8327 Massoc := First (Component_Associations (Arg_Mechanism));
8328 while Present (Massoc) loop
8329 Choice := First (Choices (Massoc));
8330
8331 if Nkind (Choice) /= N_Identifier
8332 or else Present (Next (Choice))
8333 then
8334 Error_Pragma_Arg
8335 ("incorrect form for mechanism association",
8336 Massoc);
8337 end if;
8338
8339 Formal := First_Formal (Ent);
8340 loop
8341 if No (Formal) then
8342 Error_Pragma_Arg
8343 ("parameter name & not present", Choice);
8344 end if;
8345
8346 if Chars (Choice) = Chars (Formal) then
8347 Set_Mechanism_Value
8348 (Formal, Expression (Massoc));
8349
8350 -- Set entity on identifier (needed by ASIS)
8351
8352 Set_Entity (Choice, Formal);
8353
8354 exit;
8355 end if;
8356
8357 Next_Formal (Formal);
8358 end loop;
8359
8360 Next (Massoc);
8361 end loop;
8362 end if;
8363 end if;
8364 end;
8365 end if;
8366 end Process_Extended_Import_Export_Subprogram_Pragma;
8367
8368 --------------------------
8369 -- Process_Generic_List --
8370 --------------------------
8371
8372 procedure Process_Generic_List is
8373 Arg : Node_Id;
8374 Exp : Node_Id;
8375
8376 begin
8377 Check_No_Identifiers;
8378 Check_At_Least_N_Arguments (1);
8379
8380 -- Check all arguments are names of generic units or instances
8381
8382 Arg := Arg1;
8383 while Present (Arg) loop
8384 Exp := Get_Pragma_Arg (Arg);
8385 Analyze (Exp);
8386
8387 if not Is_Entity_Name (Exp)
8388 or else
8389 (not Is_Generic_Instance (Entity (Exp))
8390 and then
8391 not Is_Generic_Unit (Entity (Exp)))
8392 then
8393 Error_Pragma_Arg
8394 ("pragma% argument must be name of generic unit/instance",
8395 Arg);
8396 end if;
8397
8398 Next (Arg);
8399 end loop;
8400 end Process_Generic_List;
8401
8402 ------------------------------------
8403 -- Process_Import_Predefined_Type --
8404 ------------------------------------
8405
8406 procedure Process_Import_Predefined_Type is
8407 Loc : constant Source_Ptr := Sloc (N);
8408 Elmt : Elmt_Id;
8409 Ftyp : Node_Id := Empty;
8410 Decl : Node_Id;
8411 Def : Node_Id;
8412 Nam : Name_Id;
8413
8414 begin
8415 Nam := String_To_Name (Strval (Expression (Arg3)));
8416
8417 Elmt := First_Elmt (Predefined_Float_Types);
8418 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
8419 Next_Elmt (Elmt);
8420 end loop;
8421
8422 Ftyp := Node (Elmt);
8423
8424 if Present (Ftyp) then
8425
8426 -- Don't build a derived type declaration, because predefined C
8427 -- types have no declaration anywhere, so cannot really be named.
8428 -- Instead build a full type declaration, starting with an
8429 -- appropriate type definition is built
8430
8431 if Is_Floating_Point_Type (Ftyp) then
8432 Def := Make_Floating_Point_Definition (Loc,
8433 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
8434 Make_Real_Range_Specification (Loc,
8435 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
8436 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
8437
8438 -- Should never have a predefined type we cannot handle
8439
8440 else
8441 raise Program_Error;
8442 end if;
8443
8444 -- Build and insert a Full_Type_Declaration, which will be
8445 -- analyzed as soon as this list entry has been analyzed.
8446
8447 Decl := Make_Full_Type_Declaration (Loc,
8448 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
8449 Type_Definition => Def);
8450
8451 Insert_After (N, Decl);
8452 Mark_Rewrite_Insertion (Decl);
8453
8454 else
8455 Error_Pragma_Arg ("no matching type found for pragma%",
8456 Arg2);
8457 end if;
8458 end Process_Import_Predefined_Type;
8459
8460 ---------------------------------
8461 -- Process_Import_Or_Interface --
8462 ---------------------------------
8463
8464 procedure Process_Import_Or_Interface is
8465 C : Convention_Id;
8466 Def_Id : Entity_Id;
8467 Hom_Id : Entity_Id;
8468
8469 begin
8470 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8471 -- pragma Import (Entity, "external name");
8472
8473 if Relaxed_RM_Semantics
8474 and then Arg_Count = 2
8475 and then Prag_Id = Pragma_Import
8476 and then Nkind (Expression (Arg2)) = N_String_Literal
8477 then
8478 C := Convention_C;
8479 Def_Id := Get_Pragma_Arg (Arg1);
8480 Analyze (Def_Id);
8481
8482 if not Is_Entity_Name (Def_Id) then
8483 Error_Pragma_Arg ("entity name required", Arg1);
8484 end if;
8485
8486 Def_Id := Entity (Def_Id);
8487 Kill_Size_Check_Code (Def_Id);
8488 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
8489
8490 else
8491 Process_Convention (C, Def_Id);
8492
8493 -- A pragma that applies to a Ghost entity becomes Ghost for the
8494 -- purposes of legality checks and removal of ignored Ghost code.
8495
8496 Mark_Ghost_Pragma (N, Def_Id);
8497 Kill_Size_Check_Code (Def_Id);
8498 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
8499 end if;
8500
8501 -- Various error checks
8502
8503 if Ekind_In (Def_Id, E_Variable, E_Constant) then
8504
8505 -- We do not permit Import to apply to a renaming declaration
8506
8507 if Present (Renamed_Object (Def_Id)) then
8508 Error_Pragma_Arg
8509 ("pragma% not allowed for object renaming", Arg2);
8510
8511 -- User initialization is not allowed for imported object, but
8512 -- the object declaration may contain a default initialization,
8513 -- that will be discarded. Note that an explicit initialization
8514 -- only counts if it comes from source, otherwise it is simply
8515 -- the code generator making an implicit initialization explicit.
8516
8517 elsif Present (Expression (Parent (Def_Id)))
8518 and then Comes_From_Source
8519 (Original_Node (Expression (Parent (Def_Id))))
8520 then
8521 -- Set imported flag to prevent cascaded errors
8522
8523 Set_Is_Imported (Def_Id);
8524
8525 Error_Msg_Sloc := Sloc (Def_Id);
8526 Error_Pragma_Arg
8527 ("no initialization allowed for declaration of& #",
8528 "\imported entities cannot be initialized (RM B.1(24))",
8529 Arg2);
8530
8531 else
8532 -- If the pragma comes from an aspect specification the
8533 -- Is_Imported flag has already been set.
8534
8535 if not From_Aspect_Specification (N) then
8536 Set_Imported (Def_Id);
8537 end if;
8538
8539 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
8540
8541 -- Note that we do not set Is_Public here. That's because we
8542 -- only want to set it if there is no address clause, and we
8543 -- don't know that yet, so we delay that processing till
8544 -- freeze time.
8545
8546 -- pragma Import completes deferred constants
8547
8548 if Ekind (Def_Id) = E_Constant then
8549 Set_Has_Completion (Def_Id);
8550 end if;
8551
8552 -- It is not possible to import a constant of an unconstrained
8553 -- array type (e.g. string) because there is no simple way to
8554 -- write a meaningful subtype for it.
8555
8556 if Is_Array_Type (Etype (Def_Id))
8557 and then not Is_Constrained (Etype (Def_Id))
8558 then
8559 Error_Msg_NE
8560 ("imported constant& must have a constrained subtype",
8561 N, Def_Id);
8562 end if;
8563 end if;
8564
8565 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8566
8567 -- If the name is overloaded, pragma applies to all of the denoted
8568 -- entities in the same declarative part, unless the pragma comes
8569 -- from an aspect specification or was generated by the compiler
8570 -- (such as for pragma Provide_Shift_Operators).
8571
8572 Hom_Id := Def_Id;
8573 while Present (Hom_Id) loop
8574
8575 Def_Id := Get_Base_Subprogram (Hom_Id);
8576
8577 -- Ignore inherited subprograms because the pragma will apply
8578 -- to the parent operation, which is the one called.
8579
8580 if Is_Overloadable (Def_Id)
8581 and then Present (Alias (Def_Id))
8582 then
8583 null;
8584
8585 -- If it is not a subprogram, it must be in an outer scope and
8586 -- pragma does not apply.
8587
8588 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8589 null;
8590
8591 -- The pragma does not apply to primitives of interfaces
8592
8593 elsif Is_Dispatching_Operation (Def_Id)
8594 and then Present (Find_Dispatching_Type (Def_Id))
8595 and then Is_Interface (Find_Dispatching_Type (Def_Id))
8596 then
8597 null;
8598
8599 -- Verify that the homonym is in the same declarative part (not
8600 -- just the same scope). If the pragma comes from an aspect
8601 -- specification we know that it is part of the declaration.
8602
8603 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
8604 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8605 and then not From_Aspect_Specification (N)
8606 then
8607 exit;
8608
8609 else
8610 -- If the pragma comes from an aspect specification the
8611 -- Is_Imported flag has already been set.
8612
8613 if not From_Aspect_Specification (N) then
8614 Set_Imported (Def_Id);
8615 end if;
8616
8617 -- Reject an Import applied to an abstract subprogram
8618
8619 if Is_Subprogram (Def_Id)
8620 and then Is_Abstract_Subprogram (Def_Id)
8621 then
8622 Error_Msg_Sloc := Sloc (Def_Id);
8623 Error_Msg_NE
8624 ("cannot import abstract subprogram& declared#",
8625 Arg2, Def_Id);
8626 end if;
8627
8628 -- Special processing for Convention_Intrinsic
8629
8630 if C = Convention_Intrinsic then
8631
8632 -- Link_Name argument not allowed for intrinsic
8633
8634 Check_No_Link_Name;
8635
8636 Set_Is_Intrinsic_Subprogram (Def_Id);
8637
8638 -- If no external name is present, then check that this
8639 -- is a valid intrinsic subprogram. If an external name
8640 -- is present, then this is handled by the back end.
8641
8642 if No (Arg3) then
8643 Check_Intrinsic_Subprogram
8644 (Def_Id, Get_Pragma_Arg (Arg2));
8645 end if;
8646 end if;
8647
8648 -- Verify that the subprogram does not have a completion
8649 -- through a renaming declaration. For other completions the
8650 -- pragma appears as a too late representation.
8651
8652 declare
8653 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
8654
8655 begin
8656 if Present (Decl)
8657 and then Nkind (Decl) = N_Subprogram_Declaration
8658 and then Present (Corresponding_Body (Decl))
8659 and then Nkind (Unit_Declaration_Node
8660 (Corresponding_Body (Decl))) =
8661 N_Subprogram_Renaming_Declaration
8662 then
8663 Error_Msg_Sloc := Sloc (Def_Id);
8664 Error_Msg_NE
8665 ("cannot import&, renaming already provided for "
8666 & "declaration #", N, Def_Id);
8667 end if;
8668 end;
8669
8670 -- If the pragma comes from an aspect specification, there
8671 -- must be an Import aspect specified as well. In the rare
8672 -- case where Import is set to False, the suprogram needs to
8673 -- have a local completion.
8674
8675 declare
8676 Imp_Aspect : constant Node_Id :=
8677 Find_Aspect (Def_Id, Aspect_Import);
8678 Expr : Node_Id;
8679
8680 begin
8681 if Present (Imp_Aspect)
8682 and then Present (Expression (Imp_Aspect))
8683 then
8684 Expr := Expression (Imp_Aspect);
8685 Analyze_And_Resolve (Expr, Standard_Boolean);
8686
8687 if Is_Entity_Name (Expr)
8688 and then Entity (Expr) = Standard_True
8689 then
8690 Set_Has_Completion (Def_Id);
8691 end if;
8692
8693 -- If there is no expression, the default is True, as for
8694 -- all boolean aspects. Same for the older pragma.
8695
8696 else
8697 Set_Has_Completion (Def_Id);
8698 end if;
8699 end;
8700
8701 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
8702 end if;
8703
8704 if Is_Compilation_Unit (Hom_Id) then
8705
8706 -- Its possible homonyms are not affected by the pragma.
8707 -- Such homonyms might be present in the context of other
8708 -- units being compiled.
8709
8710 exit;
8711
8712 elsif From_Aspect_Specification (N) then
8713 exit;
8714
8715 -- If the pragma was created by the compiler, then we don't
8716 -- want it to apply to other homonyms. This kind of case can
8717 -- occur when using pragma Provide_Shift_Operators, which
8718 -- generates implicit shift and rotate operators with Import
8719 -- pragmas that might apply to earlier explicit or implicit
8720 -- declarations marked with Import (for example, coming from
8721 -- an earlier pragma Provide_Shift_Operators for another type),
8722 -- and we don't generally want other homonyms being treated
8723 -- as imported or the pragma flagged as an illegal duplicate.
8724
8725 elsif not Comes_From_Source (N) then
8726 exit;
8727
8728 else
8729 Hom_Id := Homonym (Hom_Id);
8730 end if;
8731 end loop;
8732
8733 -- Import a CPP class
8734
8735 elsif C = Convention_CPP
8736 and then (Is_Record_Type (Def_Id)
8737 or else Ekind (Def_Id) = E_Incomplete_Type)
8738 then
8739 if Ekind (Def_Id) = E_Incomplete_Type then
8740 if Present (Full_View (Def_Id)) then
8741 Def_Id := Full_View (Def_Id);
8742
8743 else
8744 Error_Msg_N
8745 ("cannot import 'C'P'P type before full declaration seen",
8746 Get_Pragma_Arg (Arg2));
8747
8748 -- Although we have reported the error we decorate it as
8749 -- CPP_Class to avoid reporting spurious errors
8750
8751 Set_Is_CPP_Class (Def_Id);
8752 return;
8753 end if;
8754 end if;
8755
8756 -- Types treated as CPP classes must be declared limited (note:
8757 -- this used to be a warning but there is no real benefit to it
8758 -- since we did effectively intend to treat the type as limited
8759 -- anyway).
8760
8761 if not Is_Limited_Type (Def_Id) then
8762 Error_Msg_N
8763 ("imported 'C'P'P type must be limited",
8764 Get_Pragma_Arg (Arg2));
8765 end if;
8766
8767 if Etype (Def_Id) /= Def_Id
8768 and then not Is_CPP_Class (Root_Type (Def_Id))
8769 then
8770 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8771 end if;
8772
8773 Set_Is_CPP_Class (Def_Id);
8774
8775 -- Imported CPP types must not have discriminants (because C++
8776 -- classes do not have discriminants).
8777
8778 if Has_Discriminants (Def_Id) then
8779 Error_Msg_N
8780 ("imported 'C'P'P type cannot have discriminants",
8781 First (Discriminant_Specifications
8782 (Declaration_Node (Def_Id))));
8783 end if;
8784
8785 -- Check that components of imported CPP types do not have default
8786 -- expressions. For private types this check is performed when the
8787 -- full view is analyzed (see Process_Full_View).
8788
8789 if not Is_Private_Type (Def_Id) then
8790 Check_CPP_Type_Has_No_Defaults (Def_Id);
8791 end if;
8792
8793 -- Import a CPP exception
8794
8795 elsif C = Convention_CPP
8796 and then Ekind (Def_Id) = E_Exception
8797 then
8798 if No (Arg3) then
8799 Error_Pragma_Arg
8800 ("'External_'Name arguments is required for 'Cpp exception",
8801 Arg3);
8802 else
8803 -- As only a string is allowed, Check_Arg_Is_External_Name
8804 -- isn't called.
8805
8806 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8807 end if;
8808
8809 if Present (Arg4) then
8810 Error_Pragma_Arg
8811 ("Link_Name argument not allowed for imported Cpp exception",
8812 Arg4);
8813 end if;
8814
8815 -- Do not call Set_Interface_Name as the name of the exception
8816 -- shouldn't be modified (and in particular it shouldn't be
8817 -- the External_Name). For exceptions, the External_Name is the
8818 -- name of the RTTI structure.
8819
8820 -- ??? Emit an error if pragma Import/Export_Exception is present
8821
8822 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8823 Check_No_Link_Name;
8824 Check_Arg_Count (3);
8825 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8826
8827 Process_Import_Predefined_Type;
8828
8829 else
8830 Error_Pragma_Arg
8831 ("second argument of pragma% must be object, subprogram "
8832 & "or incomplete type",
8833 Arg2);
8834 end if;
8835
8836 -- If this pragma applies to a compilation unit, then the unit, which
8837 -- is a subprogram, does not require (or allow) a body. We also do
8838 -- not need to elaborate imported procedures.
8839
8840 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8841 declare
8842 Cunit : constant Node_Id := Parent (Parent (N));
8843 begin
8844 Set_Body_Required (Cunit, False);
8845 end;
8846 end if;
8847 end Process_Import_Or_Interface;
8848
8849 --------------------
8850 -- Process_Inline --
8851 --------------------
8852
8853 procedure Process_Inline (Status : Inline_Status) is
8854 Applies : Boolean;
8855 Assoc : Node_Id;
8856 Decl : Node_Id;
8857 Subp : Entity_Id;
8858 Subp_Id : Node_Id;
8859
8860 Ghost_Error_Posted : Boolean := False;
8861 -- Flag set when an error concerning the illegal mix of Ghost and
8862 -- non-Ghost subprograms is emitted.
8863
8864 Ghost_Id : Entity_Id := Empty;
8865 -- The entity of the first Ghost subprogram encountered while
8866 -- processing the arguments of the pragma.
8867
8868 procedure Make_Inline (Subp : Entity_Id);
8869 -- Subp is the defining unit name of the subprogram declaration. If
8870 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
8871 -- the corresponding body, if there is one present.
8872
8873 procedure Set_Inline_Flags (Subp : Entity_Id);
8874 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
8875 -- Also set or clear Is_Inlined flag on Subp depending on Status.
8876
8877 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8878 -- Returns True if it can be determined at this stage that inlining
8879 -- is not possible, for example if the body is available and contains
8880 -- exception handlers, we prevent inlining, since otherwise we can
8881 -- get undefined symbols at link time. This function also emits a
8882 -- warning if the pragma appears too late.
8883 --
8884 -- ??? is business with link symbols still valid, or does it relate
8885 -- to front end ZCX which is being phased out ???
8886
8887 ---------------------------
8888 -- Inlining_Not_Possible --
8889 ---------------------------
8890
8891 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8892 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8893 Stats : Node_Id;
8894
8895 begin
8896 if Nkind (Decl) = N_Subprogram_Body then
8897 Stats := Handled_Statement_Sequence (Decl);
8898 return Present (Exception_Handlers (Stats))
8899 or else Present (At_End_Proc (Stats));
8900
8901 elsif Nkind (Decl) = N_Subprogram_Declaration
8902 and then Present (Corresponding_Body (Decl))
8903 then
8904 if Analyzed (Corresponding_Body (Decl)) then
8905 Error_Msg_N ("pragma appears too late, ignored??", N);
8906 return True;
8907
8908 -- If the subprogram is a renaming as body, the body is just a
8909 -- call to the renamed subprogram, and inlining is trivially
8910 -- possible.
8911
8912 elsif
8913 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8914 N_Subprogram_Renaming_Declaration
8915 then
8916 return False;
8917
8918 else
8919 Stats :=
8920 Handled_Statement_Sequence
8921 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8922
8923 return
8924 Present (Exception_Handlers (Stats))
8925 or else Present (At_End_Proc (Stats));
8926 end if;
8927
8928 else
8929 -- If body is not available, assume the best, the check is
8930 -- performed again when compiling enclosing package bodies.
8931
8932 return False;
8933 end if;
8934 end Inlining_Not_Possible;
8935
8936 -----------------
8937 -- Make_Inline --
8938 -----------------
8939
8940 procedure Make_Inline (Subp : Entity_Id) is
8941 Kind : constant Entity_Kind := Ekind (Subp);
8942 Inner_Subp : Entity_Id := Subp;
8943
8944 begin
8945 -- Ignore if bad type, avoid cascaded error
8946
8947 if Etype (Subp) = Any_Type then
8948 Applies := True;
8949 return;
8950
8951 -- If inlining is not possible, for now do not treat as an error
8952
8953 elsif Status /= Suppressed
8954 and then Front_End_Inlining
8955 and then Inlining_Not_Possible (Subp)
8956 then
8957 Applies := True;
8958 return;
8959
8960 -- Here we have a candidate for inlining, but we must exclude
8961 -- derived operations. Otherwise we would end up trying to inline
8962 -- a phantom declaration, and the result would be to drag in a
8963 -- body which has no direct inlining associated with it. That
8964 -- would not only be inefficient but would also result in the
8965 -- backend doing cross-unit inlining in cases where it was
8966 -- definitely inappropriate to do so.
8967
8968 -- However, a simple Comes_From_Source test is insufficient, since
8969 -- we do want to allow inlining of generic instances which also do
8970 -- not come from source. We also need to recognize specs generated
8971 -- by the front-end for bodies that carry the pragma. Finally,
8972 -- predefined operators do not come from source but are not
8973 -- inlineable either.
8974
8975 elsif Is_Generic_Instance (Subp)
8976 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8977 then
8978 null;
8979
8980 elsif not Comes_From_Source (Subp)
8981 and then Scope (Subp) /= Standard_Standard
8982 then
8983 Applies := True;
8984 return;
8985 end if;
8986
8987 -- The referenced entity must either be the enclosing entity, or
8988 -- an entity declared within the current open scope.
8989
8990 if Present (Scope (Subp))
8991 and then Scope (Subp) /= Current_Scope
8992 and then Subp /= Current_Scope
8993 then
8994 Error_Pragma_Arg
8995 ("argument of% must be entity in current scope", Assoc);
8996 return;
8997 end if;
8998
8999 -- Processing for procedure, operator or function. If subprogram
9000 -- is aliased (as for an instance) indicate that the renamed
9001 -- entity (if declared in the same unit) is inlined.
9002 -- If this is the anonymous subprogram created for a subprogram
9003 -- instance, the inlining applies to it directly. Otherwise we
9004 -- retrieve it as the alias of the visible subprogram instance.
9005
9006 if Is_Subprogram (Subp) then
9007 if Is_Wrapper_Package (Scope (Subp)) then
9008 Inner_Subp := Subp;
9009 else
9010 Inner_Subp := Ultimate_Alias (Inner_Subp);
9011 end if;
9012
9013 if In_Same_Source_Unit (Subp, Inner_Subp) then
9014 Set_Inline_Flags (Inner_Subp);
9015
9016 Decl := Parent (Parent (Inner_Subp));
9017
9018 if Nkind (Decl) = N_Subprogram_Declaration
9019 and then Present (Corresponding_Body (Decl))
9020 then
9021 Set_Inline_Flags (Corresponding_Body (Decl));
9022
9023 elsif Is_Generic_Instance (Subp)
9024 and then Comes_From_Source (Subp)
9025 then
9026 -- Indicate that the body needs to be created for
9027 -- inlining subsequent calls. The instantiation node
9028 -- follows the declaration of the wrapper package
9029 -- created for it. The subprogram that requires the
9030 -- body is the anonymous one in the wrapper package.
9031
9032 if Scope (Subp) /= Standard_Standard
9033 and then
9034 Need_Subprogram_Instance_Body
9035 (Next (Unit_Declaration_Node
9036 (Scope (Alias (Subp)))), Subp)
9037 then
9038 null;
9039 end if;
9040
9041 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9042 -- appear in a formal part to apply to a formal subprogram.
9043 -- Do not apply check within an instance or a formal package
9044 -- the test will have been applied to the original generic.
9045
9046 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
9047 and then List_Containing (Decl) = List_Containing (N)
9048 and then not In_Instance
9049 then
9050 Error_Msg_N
9051 ("Inline cannot apply to a formal subprogram", N);
9052
9053 -- If Subp is a renaming, it is the renamed entity that
9054 -- will appear in any call, and be inlined. However, for
9055 -- ASIS uses it is convenient to indicate that the renaming
9056 -- itself is an inlined subprogram, so that some gnatcheck
9057 -- rules can be applied in the absence of expansion.
9058
9059 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
9060 Set_Inline_Flags (Subp);
9061 end if;
9062 end if;
9063
9064 Applies := True;
9065
9066 -- For a generic subprogram set flag as well, for use at the point
9067 -- of instantiation, to determine whether the body should be
9068 -- generated.
9069
9070 elsif Is_Generic_Subprogram (Subp) then
9071 Set_Inline_Flags (Subp);
9072 Applies := True;
9073
9074 -- Literals are by definition inlined
9075
9076 elsif Kind = E_Enumeration_Literal then
9077 null;
9078
9079 -- Anything else is an error
9080
9081 else
9082 Error_Pragma_Arg
9083 ("expect subprogram name for pragma%", Assoc);
9084 end if;
9085 end Make_Inline;
9086
9087 ----------------------
9088 -- Set_Inline_Flags --
9089 ----------------------
9090
9091 procedure Set_Inline_Flags (Subp : Entity_Id) is
9092 begin
9093 -- First set the Has_Pragma_XXX flags and issue the appropriate
9094 -- errors and warnings for suspicious combinations.
9095
9096 if Prag_Id = Pragma_No_Inline then
9097 if Has_Pragma_Inline_Always (Subp) then
9098 Error_Msg_N
9099 ("Inline_Always and No_Inline are mutually exclusive", N);
9100 elsif Has_Pragma_Inline (Subp) then
9101 Error_Msg_NE
9102 ("Inline and No_Inline both specified for& ??",
9103 N, Entity (Subp_Id));
9104 end if;
9105
9106 Set_Has_Pragma_No_Inline (Subp);
9107 else
9108 if Prag_Id = Pragma_Inline_Always then
9109 if Has_Pragma_No_Inline (Subp) then
9110 Error_Msg_N
9111 ("Inline_Always and No_Inline are mutually exclusive",
9112 N);
9113 end if;
9114
9115 Set_Has_Pragma_Inline_Always (Subp);
9116 else
9117 if Has_Pragma_No_Inline (Subp) then
9118 Error_Msg_NE
9119 ("Inline and No_Inline both specified for& ??",
9120 N, Entity (Subp_Id));
9121 end if;
9122 end if;
9123
9124 Set_Has_Pragma_Inline (Subp);
9125 end if;
9126
9127 -- Then adjust the Is_Inlined flag. It can never be set if the
9128 -- subprogram is subject to pragma No_Inline.
9129
9130 case Status is
9131 when Suppressed =>
9132 Set_Is_Inlined (Subp, False);
9133
9134 when Disabled =>
9135 null;
9136
9137 when Enabled =>
9138 if not Has_Pragma_No_Inline (Subp) then
9139 Set_Is_Inlined (Subp, True);
9140 end if;
9141 end case;
9142
9143 -- A pragma that applies to a Ghost entity becomes Ghost for the
9144 -- purposes of legality checks and removal of ignored Ghost code.
9145
9146 Mark_Ghost_Pragma (N, Subp);
9147
9148 -- Capture the entity of the first Ghost subprogram being
9149 -- processed for error detection purposes.
9150
9151 if Is_Ghost_Entity (Subp) then
9152 if No (Ghost_Id) then
9153 Ghost_Id := Subp;
9154 end if;
9155
9156 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9157 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9158
9159 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
9160 Ghost_Error_Posted := True;
9161
9162 Error_Msg_Name_1 := Pname;
9163 Error_Msg_N
9164 ("pragma % cannot mention ghost and non-ghost subprograms",
9165 N);
9166
9167 Error_Msg_Sloc := Sloc (Ghost_Id);
9168 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
9169
9170 Error_Msg_Sloc := Sloc (Subp);
9171 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
9172 end if;
9173 end Set_Inline_Flags;
9174
9175 -- Start of processing for Process_Inline
9176
9177 begin
9178 Check_No_Identifiers;
9179 Check_At_Least_N_Arguments (1);
9180
9181 if Status = Enabled then
9182 Inline_Processing_Required := True;
9183 end if;
9184
9185 Assoc := Arg1;
9186 while Present (Assoc) loop
9187 Subp_Id := Get_Pragma_Arg (Assoc);
9188 Analyze (Subp_Id);
9189 Applies := False;
9190
9191 if Is_Entity_Name (Subp_Id) then
9192 Subp := Entity (Subp_Id);
9193
9194 if Subp = Any_Id then
9195
9196 -- If previous error, avoid cascaded errors
9197
9198 Check_Error_Detected;
9199 Applies := True;
9200
9201 else
9202 Make_Inline (Subp);
9203
9204 -- For the pragma case, climb homonym chain. This is
9205 -- what implements allowing the pragma in the renaming
9206 -- case, with the result applying to the ancestors, and
9207 -- also allows Inline to apply to all previous homonyms.
9208
9209 if not From_Aspect_Specification (N) then
9210 while Present (Homonym (Subp))
9211 and then Scope (Homonym (Subp)) = Current_Scope
9212 loop
9213 Make_Inline (Homonym (Subp));
9214 Subp := Homonym (Subp);
9215 end loop;
9216 end if;
9217 end if;
9218 end if;
9219
9220 if not Applies then
9221 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
9222 end if;
9223
9224 Next (Assoc);
9225 end loop;
9226
9227 -- If the context is a package declaration, the pragma indicates
9228 -- that inlining will require the presence of the corresponding
9229 -- body. (this may be further refined).
9230
9231 if not In_Instance
9232 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9233 N_Package_Declaration
9234 then
9235 Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit));
9236 end if;
9237 end Process_Inline;
9238
9239 ----------------------------
9240 -- Process_Interface_Name --
9241 ----------------------------
9242
9243 procedure Process_Interface_Name
9244 (Subprogram_Def : Entity_Id;
9245 Ext_Arg : Node_Id;
9246 Link_Arg : Node_Id;
9247 Prag : Node_Id)
9248 is
9249 Ext_Nam : Node_Id;
9250 Link_Nam : Node_Id;
9251 String_Val : String_Id;
9252
9253 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
9254 -- SN is a string literal node for an interface name. This routine
9255 -- performs some minimal checks that the name is reasonable. In
9256 -- particular that no spaces or other obviously incorrect characters
9257 -- appear. This is only a warning, since any characters are allowed.
9258
9259 ----------------------------------
9260 -- Check_Form_Of_Interface_Name --
9261 ----------------------------------
9262
9263 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
9264 S : constant String_Id := Strval (Expr_Value_S (SN));
9265 SL : constant Nat := String_Length (S);
9266 C : Char_Code;
9267
9268 begin
9269 if SL = 0 then
9270 Error_Msg_N ("interface name cannot be null string", SN);
9271 end if;
9272
9273 for J in 1 .. SL loop
9274 C := Get_String_Char (S, J);
9275
9276 -- Look for dubious character and issue unconditional warning.
9277 -- Definitely dubious if not in character range.
9278
9279 if not In_Character_Range (C)
9280
9281 -- Commas, spaces and (back)slashes are dubious
9282
9283 or else Get_Character (C) = ','
9284 or else Get_Character (C) = '\'
9285 or else Get_Character (C) = ' '
9286 or else Get_Character (C) = '/'
9287 then
9288 Error_Msg
9289 ("??interface name contains illegal character",
9290 Sloc (SN) + Source_Ptr (J));
9291 end if;
9292 end loop;
9293 end Check_Form_Of_Interface_Name;
9294
9295 -- Start of processing for Process_Interface_Name
9296
9297 begin
9298 -- If we are looking at a pragma that comes from an aspect then it
9299 -- needs to have its corresponding aspect argument expressions
9300 -- analyzed in addition to the generated pragma so that aspects
9301 -- within generic units get properly resolved.
9302
9303 if Present (Prag) and then From_Aspect_Specification (Prag) then
9304 declare
9305 Asp : constant Node_Id := Corresponding_Aspect (Prag);
9306 Dummy_1 : Node_Id;
9307 Dummy_2 : Node_Id;
9308 Dummy_3 : Node_Id;
9309 EN : Node_Id;
9310 LN : Node_Id;
9311
9312 begin
9313 -- Obtain all interfacing aspects used to construct the pragma
9314
9315 Get_Interfacing_Aspects
9316 (Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN);
9317
9318 -- Analyze the expression of aspect External_Name
9319
9320 if Present (EN) then
9321 Analyze (Expression (EN));
9322 end if;
9323
9324 -- Analyze the expressio of aspect Link_Name
9325
9326 if Present (LN) then
9327 Analyze (Expression (LN));
9328 end if;
9329 end;
9330 end if;
9331
9332 if No (Link_Arg) then
9333 if No (Ext_Arg) then
9334 return;
9335
9336 elsif Chars (Ext_Arg) = Name_Link_Name then
9337 Ext_Nam := Empty;
9338 Link_Nam := Expression (Ext_Arg);
9339
9340 else
9341 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
9342 Ext_Nam := Expression (Ext_Arg);
9343 Link_Nam := Empty;
9344 end if;
9345
9346 else
9347 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
9348 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
9349 Ext_Nam := Expression (Ext_Arg);
9350 Link_Nam := Expression (Link_Arg);
9351 end if;
9352
9353 -- Check expressions for external name and link name are static
9354
9355 if Present (Ext_Nam) then
9356 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
9357 Check_Form_Of_Interface_Name (Ext_Nam);
9358
9359 -- Verify that external name is not the name of a local entity,
9360 -- which would hide the imported one and could lead to run-time
9361 -- surprises. The problem can only arise for entities declared in
9362 -- a package body (otherwise the external name is fully qualified
9363 -- and will not conflict).
9364
9365 declare
9366 Nam : Name_Id;
9367 E : Entity_Id;
9368 Par : Node_Id;
9369
9370 begin
9371 if Prag_Id = Pragma_Import then
9372 Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam)));
9373 E := Entity_Id (Get_Name_Table_Int (Nam));
9374
9375 if Nam /= Chars (Subprogram_Def)
9376 and then Present (E)
9377 and then not Is_Overloadable (E)
9378 and then Is_Immediately_Visible (E)
9379 and then not Is_Imported (E)
9380 and then Ekind (Scope (E)) = E_Package
9381 then
9382 Par := Parent (E);
9383 while Present (Par) loop
9384 if Nkind (Par) = N_Package_Body then
9385 Error_Msg_Sloc := Sloc (E);
9386 Error_Msg_NE
9387 ("imported entity is hidden by & declared#",
9388 Ext_Arg, E);
9389 exit;
9390 end if;
9391
9392 Par := Parent (Par);
9393 end loop;
9394 end if;
9395 end if;
9396 end;
9397 end if;
9398
9399 if Present (Link_Nam) then
9400 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
9401 Check_Form_Of_Interface_Name (Link_Nam);
9402 end if;
9403
9404 -- If there is no link name, just set the external name
9405
9406 if No (Link_Nam) then
9407 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
9408
9409 -- For the Link_Name case, the given literal is preceded by an
9410 -- asterisk, which indicates to GCC that the given name should be
9411 -- taken literally, and in particular that no prepending of
9412 -- underlines should occur, even in systems where this is the
9413 -- normal default.
9414
9415 else
9416 Start_String;
9417 Store_String_Char (Get_Char_Code ('*'));
9418 String_Val := Strval (Expr_Value_S (Link_Nam));
9419 Store_String_Chars (String_Val);
9420 Link_Nam :=
9421 Make_String_Literal (Sloc (Link_Nam),
9422 Strval => End_String);
9423 end if;
9424
9425 -- Set the interface name. If the entity is a generic instance, use
9426 -- its alias, which is the callable entity.
9427
9428 if Is_Generic_Instance (Subprogram_Def) then
9429 Set_Encoded_Interface_Name
9430 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
9431 else
9432 Set_Encoded_Interface_Name
9433 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
9434 end if;
9435
9436 Check_Duplicated_Export_Name (Link_Nam);
9437 end Process_Interface_Name;
9438
9439 -----------------------------------------
9440 -- Process_Interrupt_Or_Attach_Handler --
9441 -----------------------------------------
9442
9443 procedure Process_Interrupt_Or_Attach_Handler is
9444 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
9445 Prot_Typ : constant Entity_Id := Scope (Handler);
9446
9447 begin
9448 -- A pragma that applies to a Ghost entity becomes Ghost for the
9449 -- purposes of legality checks and removal of ignored Ghost code.
9450
9451 Mark_Ghost_Pragma (N, Handler);
9452 Set_Is_Interrupt_Handler (Handler);
9453
9454 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
9455
9456 Record_Rep_Item (Prot_Typ, N);
9457
9458 -- Chain the pragma on the contract for completeness
9459
9460 Add_Contract_Item (N, Handler);
9461 end Process_Interrupt_Or_Attach_Handler;
9462
9463 --------------------------------------------------
9464 -- Process_Restrictions_Or_Restriction_Warnings --
9465 --------------------------------------------------
9466
9467 -- Note: some of the simple identifier cases were handled in par-prag,
9468 -- but it is harmless (and more straightforward) to simply handle all
9469 -- cases here, even if it means we repeat a bit of work in some cases.
9470
9471 procedure Process_Restrictions_Or_Restriction_Warnings
9472 (Warn : Boolean)
9473 is
9474 Arg : Node_Id;
9475 R_Id : Restriction_Id;
9476 Id : Name_Id;
9477 Expr : Node_Id;
9478 Val : Uint;
9479
9480 begin
9481 -- Ignore all Restrictions pragmas in CodePeer mode
9482
9483 if CodePeer_Mode then
9484 return;
9485 end if;
9486
9487 Check_Ada_83_Warning;
9488 Check_At_Least_N_Arguments (1);
9489 Check_Valid_Configuration_Pragma;
9490
9491 Arg := Arg1;
9492 while Present (Arg) loop
9493 Id := Chars (Arg);
9494 Expr := Get_Pragma_Arg (Arg);
9495
9496 -- Case of no restriction identifier present
9497
9498 if Id = No_Name then
9499 if Nkind (Expr) /= N_Identifier then
9500 Error_Pragma_Arg
9501 ("invalid form for restriction", Arg);
9502 end if;
9503
9504 R_Id :=
9505 Get_Restriction_Id
9506 (Process_Restriction_Synonyms (Expr));
9507
9508 if R_Id not in All_Boolean_Restrictions then
9509 Error_Msg_Name_1 := Pname;
9510 Error_Msg_N
9511 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
9512
9513 -- Check for possible misspelling
9514
9515 for J in Restriction_Id loop
9516 declare
9517 Rnm : constant String := Restriction_Id'Image (J);
9518
9519 begin
9520 Name_Buffer (1 .. Rnm'Length) := Rnm;
9521 Name_Len := Rnm'Length;
9522 Set_Casing (All_Lower_Case);
9523
9524 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
9525 Set_Casing
9526 (Identifier_Casing
9527 (Source_Index (Current_Sem_Unit)));
9528 Error_Msg_String (1 .. Rnm'Length) :=
9529 Name_Buffer (1 .. Name_Len);
9530 Error_Msg_Strlen := Rnm'Length;
9531 Error_Msg_N -- CODEFIX
9532 ("\possible misspelling of ""~""",
9533 Get_Pragma_Arg (Arg));
9534 exit;
9535 end if;
9536 end;
9537 end loop;
9538
9539 raise Pragma_Exit;
9540 end if;
9541
9542 if Implementation_Restriction (R_Id) then
9543 Check_Restriction (No_Implementation_Restrictions, Arg);
9544 end if;
9545
9546 -- Special processing for No_Elaboration_Code restriction
9547
9548 if R_Id = No_Elaboration_Code then
9549
9550 -- Restriction is only recognized within a configuration
9551 -- pragma file, or within a unit of the main extended
9552 -- program. Note: the test for Main_Unit is needed to
9553 -- properly include the case of configuration pragma files.
9554
9555 if not (Current_Sem_Unit = Main_Unit
9556 or else In_Extended_Main_Source_Unit (N))
9557 then
9558 return;
9559
9560 -- Don't allow in a subunit unless already specified in
9561 -- body or spec.
9562
9563 elsif Nkind (Parent (N)) = N_Compilation_Unit
9564 and then Nkind (Unit (Parent (N))) = N_Subunit
9565 and then not Restriction_Active (No_Elaboration_Code)
9566 then
9567 Error_Msg_N
9568 ("invalid specification of ""No_Elaboration_Code""",
9569 N);
9570 Error_Msg_N
9571 ("\restriction cannot be specified in a subunit", N);
9572 Error_Msg_N
9573 ("\unless also specified in body or spec", N);
9574 return;
9575
9576 -- If we accept a No_Elaboration_Code restriction, then it
9577 -- needs to be added to the configuration restriction set so
9578 -- that we get proper application to other units in the main
9579 -- extended source as required.
9580
9581 else
9582 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
9583 end if;
9584 end if;
9585
9586 -- If this is a warning, then set the warning unless we already
9587 -- have a real restriction active (we never want a warning to
9588 -- override a real restriction).
9589
9590 if Warn then
9591 if not Restriction_Active (R_Id) then
9592 Set_Restriction (R_Id, N);
9593 Restriction_Warnings (R_Id) := True;
9594 end if;
9595
9596 -- If real restriction case, then set it and make sure that the
9597 -- restriction warning flag is off, since a real restriction
9598 -- always overrides a warning.
9599
9600 else
9601 Set_Restriction (R_Id, N);
9602 Restriction_Warnings (R_Id) := False;
9603 end if;
9604
9605 -- Check for obsolescent restrictions in Ada 2005 mode
9606
9607 if not Warn
9608 and then Ada_Version >= Ada_2005
9609 and then (R_Id = No_Asynchronous_Control
9610 or else
9611 R_Id = No_Unchecked_Deallocation
9612 or else
9613 R_Id = No_Unchecked_Conversion)
9614 then
9615 Check_Restriction (No_Obsolescent_Features, N);
9616 end if;
9617
9618 -- A very special case that must be processed here: pragma
9619 -- Restrictions (No_Exceptions) turns off all run-time
9620 -- checking. This is a bit dubious in terms of the formal
9621 -- language definition, but it is what is intended by RM
9622 -- H.4(12). Restriction_Warnings never affects generated code
9623 -- so this is done only in the real restriction case.
9624
9625 -- Atomic_Synchronization is not a real check, so it is not
9626 -- affected by this processing).
9627
9628 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9629 -- run-time checks in CodePeer and GNATprove modes: we want to
9630 -- generate checks for analysis purposes, as set respectively
9631 -- by -gnatC and -gnatd.F
9632
9633 if not Warn
9634 and then not (CodePeer_Mode or GNATprove_Mode)
9635 and then R_Id = No_Exceptions
9636 then
9637 for J in Scope_Suppress.Suppress'Range loop
9638 if J /= Atomic_Synchronization then
9639 Scope_Suppress.Suppress (J) := True;
9640 end if;
9641 end loop;
9642 end if;
9643
9644 -- Case of No_Dependence => unit-name. Note that the parser
9645 -- already made the necessary entry in the No_Dependence table.
9646
9647 elsif Id = Name_No_Dependence then
9648 if not OK_No_Dependence_Unit_Name (Expr) then
9649 raise Pragma_Exit;
9650 end if;
9651
9652 -- Case of No_Specification_Of_Aspect => aspect-identifier
9653
9654 elsif Id = Name_No_Specification_Of_Aspect then
9655 declare
9656 A_Id : Aspect_Id;
9657
9658 begin
9659 if Nkind (Expr) /= N_Identifier then
9660 A_Id := No_Aspect;
9661 else
9662 A_Id := Get_Aspect_Id (Chars (Expr));
9663 end if;
9664
9665 if A_Id = No_Aspect then
9666 Error_Pragma_Arg ("invalid restriction name", Arg);
9667 else
9668 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
9669 end if;
9670 end;
9671
9672 -- Case of No_Use_Of_Attribute => attribute-identifier
9673
9674 elsif Id = Name_No_Use_Of_Attribute then
9675 if Nkind (Expr) /= N_Identifier
9676 or else not Is_Attribute_Name (Chars (Expr))
9677 then
9678 Error_Msg_N ("unknown attribute name??", Expr);
9679
9680 else
9681 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
9682 end if;
9683
9684 -- Case of No_Use_Of_Entity => fully-qualified-name
9685
9686 elsif Id = Name_No_Use_Of_Entity then
9687
9688 -- Restriction is only recognized within a configuration
9689 -- pragma file, or within a unit of the main extended
9690 -- program. Note: the test for Main_Unit is needed to
9691 -- properly include the case of configuration pragma files.
9692
9693 if Current_Sem_Unit = Main_Unit
9694 or else In_Extended_Main_Source_Unit (N)
9695 then
9696 if not OK_No_Dependence_Unit_Name (Expr) then
9697 Error_Msg_N ("wrong form for entity name", Expr);
9698 else
9699 Set_Restriction_No_Use_Of_Entity
9700 (Expr, Warn, No_Profile);
9701 end if;
9702 end if;
9703
9704 -- Case of No_Use_Of_Pragma => pragma-identifier
9705
9706 elsif Id = Name_No_Use_Of_Pragma then
9707 if Nkind (Expr) /= N_Identifier
9708 or else not Is_Pragma_Name (Chars (Expr))
9709 then
9710 Error_Msg_N ("unknown pragma name??", Expr);
9711 else
9712 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
9713 end if;
9714
9715 -- All other cases of restriction identifier present
9716
9717 else
9718 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
9719 Analyze_And_Resolve (Expr, Any_Integer);
9720
9721 if R_Id not in All_Parameter_Restrictions then
9722 Error_Pragma_Arg
9723 ("invalid restriction parameter identifier", Arg);
9724
9725 elsif not Is_OK_Static_Expression (Expr) then
9726 Flag_Non_Static_Expr
9727 ("value must be static expression!", Expr);
9728 raise Pragma_Exit;
9729
9730 elsif not Is_Integer_Type (Etype (Expr))
9731 or else Expr_Value (Expr) < 0
9732 then
9733 Error_Pragma_Arg
9734 ("value must be non-negative integer", Arg);
9735 end if;
9736
9737 -- Restriction pragma is active
9738
9739 Val := Expr_Value (Expr);
9740
9741 if not UI_Is_In_Int_Range (Val) then
9742 Error_Pragma_Arg
9743 ("pragma ignored, value too large??", Arg);
9744 end if;
9745
9746 -- Warning case. If the real restriction is active, then we
9747 -- ignore the request, since warning never overrides a real
9748 -- restriction. Otherwise we set the proper warning. Note that
9749 -- this circuit sets the warning again if it is already set,
9750 -- which is what we want, since the constant may have changed.
9751
9752 if Warn then
9753 if not Restriction_Active (R_Id) then
9754 Set_Restriction
9755 (R_Id, N, Integer (UI_To_Int (Val)));
9756 Restriction_Warnings (R_Id) := True;
9757 end if;
9758
9759 -- Real restriction case, set restriction and make sure warning
9760 -- flag is off since real restriction always overrides warning.
9761
9762 else
9763 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9764 Restriction_Warnings (R_Id) := False;
9765 end if;
9766 end if;
9767
9768 Next (Arg);
9769 end loop;
9770 end Process_Restrictions_Or_Restriction_Warnings;
9771
9772 ---------------------------------
9773 -- Process_Suppress_Unsuppress --
9774 ---------------------------------
9775
9776 -- Note: this procedure makes entries in the check suppress data
9777 -- structures managed by Sem. See spec of package Sem for full
9778 -- details on how we handle recording of check suppression.
9779
9780 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9781 C : Check_Id;
9782 E : Entity_Id;
9783 E_Id : Node_Id;
9784
9785 In_Package_Spec : constant Boolean :=
9786 Is_Package_Or_Generic_Package (Current_Scope)
9787 and then not In_Package_Body (Current_Scope);
9788
9789 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9790 -- Used to suppress a single check on the given entity
9791
9792 --------------------------------
9793 -- Suppress_Unsuppress_Echeck --
9794 --------------------------------
9795
9796 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9797 begin
9798 -- Check for error of trying to set atomic synchronization for
9799 -- a non-atomic variable.
9800
9801 if C = Atomic_Synchronization
9802 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9803 then
9804 Error_Msg_N
9805 ("pragma & requires atomic type or variable",
9806 Pragma_Identifier (Original_Node (N)));
9807 end if;
9808
9809 Set_Checks_May_Be_Suppressed (E);
9810
9811 if In_Package_Spec then
9812 Push_Global_Suppress_Stack_Entry
9813 (Entity => E,
9814 Check => C,
9815 Suppress => Suppress_Case);
9816 else
9817 Push_Local_Suppress_Stack_Entry
9818 (Entity => E,
9819 Check => C,
9820 Suppress => Suppress_Case);
9821 end if;
9822
9823 -- If this is a first subtype, and the base type is distinct,
9824 -- then also set the suppress flags on the base type.
9825
9826 if Is_First_Subtype (E) and then Etype (E) /= E then
9827 Suppress_Unsuppress_Echeck (Etype (E), C);
9828 end if;
9829 end Suppress_Unsuppress_Echeck;
9830
9831 -- Start of processing for Process_Suppress_Unsuppress
9832
9833 begin
9834 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9835 -- on user code: we want to generate checks for analysis purposes, as
9836 -- set respectively by -gnatC and -gnatd.F
9837
9838 if Comes_From_Source (N)
9839 and then (CodePeer_Mode or GNATprove_Mode)
9840 then
9841 return;
9842 end if;
9843
9844 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9845 -- declarative part or a package spec (RM 11.5(5)).
9846
9847 if not Is_Configuration_Pragma then
9848 Check_Is_In_Decl_Part_Or_Package_Spec;
9849 end if;
9850
9851 Check_At_Least_N_Arguments (1);
9852 Check_At_Most_N_Arguments (2);
9853 Check_No_Identifier (Arg1);
9854 Check_Arg_Is_Identifier (Arg1);
9855
9856 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9857
9858 if C = No_Check_Id then
9859 Error_Pragma_Arg
9860 ("argument of pragma% is not valid check name", Arg1);
9861 end if;
9862
9863 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9864
9865 if C = Elaboration_Check and then SPARK_Mode = On then
9866 Error_Pragma_Arg
9867 ("Suppress of Elaboration_Check ignored in SPARK??",
9868 "\elaboration checking rules are statically enforced "
9869 & "(SPARK RM 7.7)", Arg1);
9870 end if;
9871
9872 -- One-argument case
9873
9874 if Arg_Count = 1 then
9875
9876 -- Make an entry in the local scope suppress table. This is the
9877 -- table that directly shows the current value of the scope
9878 -- suppress check for any check id value.
9879
9880 if C = All_Checks then
9881
9882 -- For All_Checks, we set all specific predefined checks with
9883 -- the exception of Elaboration_Check, which is handled
9884 -- specially because of not wanting All_Checks to have the
9885 -- effect of deactivating static elaboration order processing.
9886 -- Atomic_Synchronization is also not affected, since this is
9887 -- not a real check.
9888
9889 for J in Scope_Suppress.Suppress'Range loop
9890 if J /= Elaboration_Check
9891 and then
9892 J /= Atomic_Synchronization
9893 then
9894 Scope_Suppress.Suppress (J) := Suppress_Case;
9895 end if;
9896 end loop;
9897
9898 -- If not All_Checks, and predefined check, then set appropriate
9899 -- scope entry. Note that we will set Elaboration_Check if this
9900 -- is explicitly specified. Atomic_Synchronization is allowed
9901 -- only if internally generated and entity is atomic.
9902
9903 elsif C in Predefined_Check_Id
9904 and then (not Comes_From_Source (N)
9905 or else C /= Atomic_Synchronization)
9906 then
9907 Scope_Suppress.Suppress (C) := Suppress_Case;
9908 end if;
9909
9910 -- Also make an entry in the Local_Entity_Suppress table
9911
9912 Push_Local_Suppress_Stack_Entry
9913 (Entity => Empty,
9914 Check => C,
9915 Suppress => Suppress_Case);
9916
9917 -- Case of two arguments present, where the check is suppressed for
9918 -- a specified entity (given as the second argument of the pragma)
9919
9920 else
9921 -- This is obsolescent in Ada 2005 mode
9922
9923 if Ada_Version >= Ada_2005 then
9924 Check_Restriction (No_Obsolescent_Features, Arg2);
9925 end if;
9926
9927 Check_Optional_Identifier (Arg2, Name_On);
9928 E_Id := Get_Pragma_Arg (Arg2);
9929 Analyze (E_Id);
9930
9931 if not Is_Entity_Name (E_Id) then
9932 Error_Pragma_Arg
9933 ("second argument of pragma% must be entity name", Arg2);
9934 end if;
9935
9936 E := Entity (E_Id);
9937
9938 if E = Any_Id then
9939 return;
9940 end if;
9941
9942 -- A pragma that applies to a Ghost entity becomes Ghost for the
9943 -- purposes of legality checks and removal of ignored Ghost code.
9944
9945 Mark_Ghost_Pragma (N, E);
9946
9947 -- Enforce RM 11.5(7) which requires that for a pragma that
9948 -- appears within a package spec, the named entity must be
9949 -- within the package spec. We allow the package name itself
9950 -- to be mentioned since that makes sense, although it is not
9951 -- strictly allowed by 11.5(7).
9952
9953 if In_Package_Spec
9954 and then E /= Current_Scope
9955 and then Scope (E) /= Current_Scope
9956 then
9957 Error_Pragma_Arg
9958 ("entity in pragma% is not in package spec (RM 11.5(7))",
9959 Arg2);
9960 end if;
9961
9962 -- Loop through homonyms. As noted below, in the case of a package
9963 -- spec, only homonyms within the package spec are considered.
9964
9965 loop
9966 Suppress_Unsuppress_Echeck (E, C);
9967
9968 if Is_Generic_Instance (E)
9969 and then Is_Subprogram (E)
9970 and then Present (Alias (E))
9971 then
9972 Suppress_Unsuppress_Echeck (Alias (E), C);
9973 end if;
9974
9975 -- Move to next homonym if not aspect spec case
9976
9977 exit when From_Aspect_Specification (N);
9978 E := Homonym (E);
9979 exit when No (E);
9980
9981 -- If we are within a package specification, the pragma only
9982 -- applies to homonyms in the same scope.
9983
9984 exit when In_Package_Spec
9985 and then Scope (E) /= Current_Scope;
9986 end loop;
9987 end if;
9988 end Process_Suppress_Unsuppress;
9989
9990 -------------------------------
9991 -- Record_Independence_Check --
9992 -------------------------------
9993
9994 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
9995 begin
9996 -- For GCC back ends the validation is done a priori
9997
9998 if not AAMP_On_Target then
9999 return;
10000 end if;
10001
10002 Independence_Checks.Append ((N, E));
10003 end Record_Independence_Check;
10004
10005 ------------------
10006 -- Set_Exported --
10007 ------------------
10008
10009 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
10010 begin
10011 if Is_Imported (E) then
10012 Error_Pragma_Arg
10013 ("cannot export entity& that was previously imported", Arg);
10014
10015 elsif Present (Address_Clause (E))
10016 and then not Relaxed_RM_Semantics
10017 then
10018 Error_Pragma_Arg
10019 ("cannot export entity& that has an address clause", Arg);
10020 end if;
10021
10022 Set_Is_Exported (E);
10023
10024 -- Generate a reference for entity explicitly, because the
10025 -- identifier may be overloaded and name resolution will not
10026 -- generate one.
10027
10028 Generate_Reference (E, Arg);
10029
10030 -- Deal with exporting non-library level entity
10031
10032 if not Is_Library_Level_Entity (E) then
10033
10034 -- Not allowed at all for subprograms
10035
10036 if Is_Subprogram (E) then
10037 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
10038
10039 -- Otherwise set public and statically allocated
10040
10041 else
10042 Set_Is_Public (E);
10043 Set_Is_Statically_Allocated (E);
10044
10045 -- Warn if the corresponding W flag is set
10046
10047 if Warn_On_Export_Import
10048
10049 -- Only do this for something that was in the source. Not
10050 -- clear if this can be False now (there used for sure to be
10051 -- cases on some systems where it was False), but anyway the
10052 -- test is harmless if not needed, so it is retained.
10053
10054 and then Comes_From_Source (Arg)
10055 then
10056 Error_Msg_NE
10057 ("?x?& has been made static as a result of Export",
10058 Arg, E);
10059 Error_Msg_N
10060 ("\?x?this usage is non-standard and non-portable",
10061 Arg);
10062 end if;
10063 end if;
10064 end if;
10065
10066 if Warn_On_Export_Import and then Is_Type (E) then
10067 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
10068 end if;
10069
10070 if Warn_On_Export_Import and Inside_A_Generic then
10071 Error_Msg_NE
10072 ("all instances of& will have the same external name?x?",
10073 Arg, E);
10074 end if;
10075 end Set_Exported;
10076
10077 ----------------------------------------------
10078 -- Set_Extended_Import_Export_External_Name --
10079 ----------------------------------------------
10080
10081 procedure Set_Extended_Import_Export_External_Name
10082 (Internal_Ent : Entity_Id;
10083 Arg_External : Node_Id)
10084 is
10085 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
10086 New_Name : Node_Id;
10087
10088 begin
10089 if No (Arg_External) then
10090 return;
10091 end if;
10092
10093 Check_Arg_Is_External_Name (Arg_External);
10094
10095 if Nkind (Arg_External) = N_String_Literal then
10096 if String_Length (Strval (Arg_External)) = 0 then
10097 return;
10098 else
10099 New_Name := Adjust_External_Name_Case (Arg_External);
10100 end if;
10101
10102 elsif Nkind (Arg_External) = N_Identifier then
10103 New_Name := Get_Default_External_Name (Arg_External);
10104
10105 -- Check_Arg_Is_External_Name should let through only identifiers and
10106 -- string literals or static string expressions (which are folded to
10107 -- string literals).
10108
10109 else
10110 raise Program_Error;
10111 end if;
10112
10113 -- If we already have an external name set (by a prior normal Import
10114 -- or Export pragma), then the external names must match
10115
10116 if Present (Interface_Name (Internal_Ent)) then
10117
10118 -- Ignore mismatching names in CodePeer mode, to support some
10119 -- old compilers which would export the same procedure under
10120 -- different names, e.g:
10121 -- procedure P;
10122 -- pragma Export_Procedure (P, "a");
10123 -- pragma Export_Procedure (P, "b");
10124
10125 if CodePeer_Mode then
10126 return;
10127 end if;
10128
10129 Check_Matching_Internal_Names : declare
10130 S1 : constant String_Id := Strval (Old_Name);
10131 S2 : constant String_Id := Strval (New_Name);
10132
10133 procedure Mismatch;
10134 pragma No_Return (Mismatch);
10135 -- Called if names do not match
10136
10137 --------------
10138 -- Mismatch --
10139 --------------
10140
10141 procedure Mismatch is
10142 begin
10143 Error_Msg_Sloc := Sloc (Old_Name);
10144 Error_Pragma_Arg
10145 ("external name does not match that given #",
10146 Arg_External);
10147 end Mismatch;
10148
10149 -- Start of processing for Check_Matching_Internal_Names
10150
10151 begin
10152 if String_Length (S1) /= String_Length (S2) then
10153 Mismatch;
10154
10155 else
10156 for J in 1 .. String_Length (S1) loop
10157 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
10158 Mismatch;
10159 end if;
10160 end loop;
10161 end if;
10162 end Check_Matching_Internal_Names;
10163
10164 -- Otherwise set the given name
10165
10166 else
10167 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
10168 Check_Duplicated_Export_Name (New_Name);
10169 end if;
10170 end Set_Extended_Import_Export_External_Name;
10171
10172 ------------------
10173 -- Set_Imported --
10174 ------------------
10175
10176 procedure Set_Imported (E : Entity_Id) is
10177 begin
10178 -- Error message if already imported or exported
10179
10180 if Is_Exported (E) or else Is_Imported (E) then
10181
10182 -- Error if being set Exported twice
10183
10184 if Is_Exported (E) then
10185 Error_Msg_NE ("entity& was previously exported", N, E);
10186
10187 -- Ignore error in CodePeer mode where we treat all imported
10188 -- subprograms as unknown.
10189
10190 elsif CodePeer_Mode then
10191 goto OK;
10192
10193 -- OK if Import/Interface case
10194
10195 elsif Import_Interface_Present (N) then
10196 goto OK;
10197
10198 -- Error if being set Imported twice
10199
10200 else
10201 Error_Msg_NE ("entity& was previously imported", N, E);
10202 end if;
10203
10204 Error_Msg_Name_1 := Pname;
10205 Error_Msg_N
10206 ("\(pragma% applies to all previous entities)", N);
10207
10208 Error_Msg_Sloc := Sloc (E);
10209 Error_Msg_NE ("\import not allowed for& declared#", N, E);
10210
10211 -- Here if not previously imported or exported, OK to import
10212
10213 else
10214 Set_Is_Imported (E);
10215
10216 -- For subprogram, set Import_Pragma field
10217
10218 if Is_Subprogram (E) then
10219 Set_Import_Pragma (E, N);
10220 end if;
10221
10222 -- If the entity is an object that is not at the library level,
10223 -- then it is statically allocated. We do not worry about objects
10224 -- with address clauses in this context since they are not really
10225 -- imported in the linker sense.
10226
10227 if Is_Object (E)
10228 and then not Is_Library_Level_Entity (E)
10229 and then No (Address_Clause (E))
10230 then
10231 Set_Is_Statically_Allocated (E);
10232 end if;
10233 end if;
10234
10235 <<OK>> null;
10236 end Set_Imported;
10237
10238 -------------------------
10239 -- Set_Mechanism_Value --
10240 -------------------------
10241
10242 -- Note: the mechanism name has not been analyzed (and cannot indeed be
10243 -- analyzed, since it is semantic nonsense), so we get it in the exact
10244 -- form created by the parser.
10245
10246 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
10247 procedure Bad_Mechanism;
10248 pragma No_Return (Bad_Mechanism);
10249 -- Signal bad mechanism name
10250
10251 -------------------------
10252 -- Bad_Mechanism_Value --
10253 -------------------------
10254
10255 procedure Bad_Mechanism is
10256 begin
10257 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
10258 end Bad_Mechanism;
10259
10260 -- Start of processing for Set_Mechanism_Value
10261
10262 begin
10263 if Mechanism (Ent) /= Default_Mechanism then
10264 Error_Msg_NE
10265 ("mechanism for & has already been set", Mech_Name, Ent);
10266 end if;
10267
10268 -- MECHANISM_NAME ::= value | reference
10269
10270 if Nkind (Mech_Name) = N_Identifier then
10271 if Chars (Mech_Name) = Name_Value then
10272 Set_Mechanism (Ent, By_Copy);
10273 return;
10274
10275 elsif Chars (Mech_Name) = Name_Reference then
10276 Set_Mechanism (Ent, By_Reference);
10277 return;
10278
10279 elsif Chars (Mech_Name) = Name_Copy then
10280 Error_Pragma_Arg
10281 ("bad mechanism name, Value assumed", Mech_Name);
10282
10283 else
10284 Bad_Mechanism;
10285 end if;
10286
10287 else
10288 Bad_Mechanism;
10289 end if;
10290 end Set_Mechanism_Value;
10291
10292 --------------------------
10293 -- Set_Rational_Profile --
10294 --------------------------
10295
10296 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
10297 -- extension to the semantics of renaming declarations.
10298
10299 procedure Set_Rational_Profile is
10300 begin
10301 Implicit_Packing := True;
10302 Overriding_Renamings := True;
10303 Use_VADS_Size := True;
10304 end Set_Rational_Profile;
10305
10306 ---------------------------
10307 -- Set_Ravenscar_Profile --
10308 ---------------------------
10309
10310 -- The tasks to be done here are
10311
10312 -- Set required policies
10313
10314 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10315 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
10316 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10317 -- (For GNAT_Ravenscar_EDF profile)
10318 -- pragma Locking_Policy (Ceiling_Locking)
10319
10320 -- Set Detect_Blocking mode
10321
10322 -- Set required restrictions (see System.Rident for detailed list)
10323
10324 -- Set the No_Dependence rules
10325 -- No_Dependence => Ada.Asynchronous_Task_Control
10326 -- No_Dependence => Ada.Calendar
10327 -- No_Dependence => Ada.Execution_Time.Group_Budget
10328 -- No_Dependence => Ada.Execution_Time.Timers
10329 -- No_Dependence => Ada.Task_Attributes
10330 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10331
10332 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
10333 procedure Set_Error_Msg_To_Profile_Name;
10334 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
10335 -- profile.
10336
10337 -----------------------------------
10338 -- Set_Error_Msg_To_Profile_Name --
10339 -----------------------------------
10340
10341 procedure Set_Error_Msg_To_Profile_Name is
10342 Prof_Nam : constant Node_Id :=
10343 Get_Pragma_Arg
10344 (First (Pragma_Argument_Associations (N)));
10345
10346 begin
10347 Get_Name_String (Chars (Prof_Nam));
10348 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
10349 Error_Msg_Strlen := Name_Len;
10350 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
10351 end Set_Error_Msg_To_Profile_Name;
10352
10353 -- Local variables
10354
10355 Nod : Node_Id;
10356 Pref : Node_Id;
10357 Pref_Id : Node_Id;
10358 Sel_Id : Node_Id;
10359
10360 Profile_Dispatching_Policy : Character;
10361
10362 -- Start of processing for Set_Ravenscar_Profile
10363
10364 begin
10365 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10366
10367 if Profile = GNAT_Ravenscar_EDF then
10368 Profile_Dispatching_Policy := 'E';
10369
10370 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10371
10372 else
10373 Profile_Dispatching_Policy := 'F';
10374 end if;
10375
10376 if Task_Dispatching_Policy /= ' '
10377 and then Task_Dispatching_Policy /= Profile_Dispatching_Policy
10378 then
10379 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10380 Set_Error_Msg_To_Profile_Name;
10381 Error_Pragma ("Profile (~) incompatible with policy#");
10382
10383 -- Set the FIFO_Within_Priorities policy, but always preserve
10384 -- System_Location since we like the error message with the run time
10385 -- name.
10386
10387 else
10388 Task_Dispatching_Policy := Profile_Dispatching_Policy;
10389
10390 if Task_Dispatching_Policy_Sloc /= System_Location then
10391 Task_Dispatching_Policy_Sloc := Loc;
10392 end if;
10393 end if;
10394
10395 -- pragma Locking_Policy (Ceiling_Locking)
10396
10397 if Locking_Policy /= ' '
10398 and then Locking_Policy /= 'C'
10399 then
10400 Error_Msg_Sloc := Locking_Policy_Sloc;
10401 Set_Error_Msg_To_Profile_Name;
10402 Error_Pragma ("Profile (~) incompatible with policy#");
10403
10404 -- Set the Ceiling_Locking policy, but preserve System_Location since
10405 -- we like the error message with the run time name.
10406
10407 else
10408 Locking_Policy := 'C';
10409
10410 if Locking_Policy_Sloc /= System_Location then
10411 Locking_Policy_Sloc := Loc;
10412 end if;
10413 end if;
10414
10415 -- pragma Detect_Blocking
10416
10417 Detect_Blocking := True;
10418
10419 -- Set the corresponding restrictions
10420
10421 Set_Profile_Restrictions
10422 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
10423
10424 -- Set the No_Dependence restrictions
10425
10426 -- The following No_Dependence restrictions:
10427 -- No_Dependence => Ada.Asynchronous_Task_Control
10428 -- No_Dependence => Ada.Calendar
10429 -- No_Dependence => Ada.Task_Attributes
10430 -- are already set by previous call to Set_Profile_Restrictions.
10431
10432 -- Set the following restrictions which were added to Ada 2005:
10433 -- No_Dependence => Ada.Execution_Time.Group_Budget
10434 -- No_Dependence => Ada.Execution_Time.Timers
10435
10436 if Ada_Version >= Ada_2005 then
10437 Pref_Id := Make_Identifier (Loc, Name_Find ("ada"));
10438 Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time"));
10439
10440 Pref :=
10441 Make_Selected_Component
10442 (Sloc => Loc,
10443 Prefix => Pref_Id,
10444 Selector_Name => Sel_Id);
10445
10446 Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets"));
10447
10448 Nod :=
10449 Make_Selected_Component
10450 (Sloc => Loc,
10451 Prefix => Pref,
10452 Selector_Name => Sel_Id);
10453
10454 Set_Restriction_No_Dependence
10455 (Unit => Nod,
10456 Warn => Treat_Restrictions_As_Warnings,
10457 Profile => Ravenscar);
10458
10459 Sel_Id := Make_Identifier (Loc, Name_Find ("timers"));
10460
10461 Nod :=
10462 Make_Selected_Component
10463 (Sloc => Loc,
10464 Prefix => Pref,
10465 Selector_Name => Sel_Id);
10466
10467 Set_Restriction_No_Dependence
10468 (Unit => Nod,
10469 Warn => Treat_Restrictions_As_Warnings,
10470 Profile => Ravenscar);
10471 end if;
10472
10473 -- Set the following restriction which was added to Ada 2012 (see
10474 -- AI-0171):
10475 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10476
10477 if Ada_Version >= Ada_2012 then
10478 Pref_Id := Make_Identifier (Loc, Name_Find ("system"));
10479 Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors"));
10480
10481 Pref :=
10482 Make_Selected_Component
10483 (Sloc => Loc,
10484 Prefix => Pref_Id,
10485 Selector_Name => Sel_Id);
10486
10487 Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains"));
10488
10489 Nod :=
10490 Make_Selected_Component
10491 (Sloc => Loc,
10492 Prefix => Pref,
10493 Selector_Name => Sel_Id);
10494
10495 Set_Restriction_No_Dependence
10496 (Unit => Nod,
10497 Warn => Treat_Restrictions_As_Warnings,
10498 Profile => Ravenscar);
10499 end if;
10500 end Set_Ravenscar_Profile;
10501
10502 -- Start of processing for Analyze_Pragma
10503
10504 begin
10505 -- The following code is a defense against recursion. Not clear that
10506 -- this can happen legitimately, but perhaps some error situations can
10507 -- cause it, and we did see this recursion during testing.
10508
10509 if Analyzed (N) then
10510 return;
10511 else
10512 Set_Analyzed (N);
10513 end if;
10514
10515 Check_Restriction_No_Use_Of_Pragma (N);
10516
10517 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
10518 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
10519
10520 if Should_Ignore_Pragma_Sem (N)
10521 or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
10522 and then Ignore_Rep_Clauses)
10523 then
10524 return;
10525 end if;
10526
10527 -- Deal with unrecognized pragma
10528
10529 if not Is_Pragma_Name (Pname) then
10530 if Warn_On_Unrecognized_Pragma then
10531 Error_Msg_Name_1 := Pname;
10532 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
10533
10534 for PN in First_Pragma_Name .. Last_Pragma_Name loop
10535 if Is_Bad_Spelling_Of (Pname, PN) then
10536 Error_Msg_Name_1 := PN;
10537 Error_Msg_N -- CODEFIX
10538 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
10539 exit;
10540 end if;
10541 end loop;
10542 end if;
10543
10544 return;
10545 end if;
10546
10547 -- Here to start processing for recognized pragma
10548
10549 Pname := Original_Aspect_Pragma_Name (N);
10550
10551 -- Capture setting of Opt.Uneval_Old
10552
10553 case Opt.Uneval_Old is
10554 when 'A' =>
10555 Set_Uneval_Old_Accept (N);
10556
10557 when 'E' =>
10558 null;
10559
10560 when 'W' =>
10561 Set_Uneval_Old_Warn (N);
10562
10563 when others =>
10564 raise Program_Error;
10565 end case;
10566
10567 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10568 -- is already set, indicating that we have already checked the policy
10569 -- at the right point. This happens for example in the case of a pragma
10570 -- that is derived from an Aspect.
10571
10572 if Is_Ignored (N) or else Is_Checked (N) then
10573 null;
10574
10575 -- For a pragma that is a rewriting of another pragma, copy the
10576 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10577
10578 elsif Is_Rewrite_Substitution (N)
10579 and then Nkind (Original_Node (N)) = N_Pragma
10580 and then Original_Node (N) /= N
10581 then
10582 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10583 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10584
10585 -- Otherwise query the applicable policy at this point
10586
10587 else
10588 Check_Applicable_Policy (N);
10589
10590 -- If pragma is disabled, rewrite as NULL and skip analysis
10591
10592 if Is_Disabled (N) then
10593 Rewrite (N, Make_Null_Statement (Loc));
10594 Analyze (N);
10595 raise Pragma_Exit;
10596 end if;
10597 end if;
10598
10599 -- Preset arguments
10600
10601 Arg_Count := 0;
10602 Arg1 := Empty;
10603 Arg2 := Empty;
10604 Arg3 := Empty;
10605 Arg4 := Empty;
10606
10607 if Present (Pragma_Argument_Associations (N)) then
10608 Arg_Count := List_Length (Pragma_Argument_Associations (N));
10609 Arg1 := First (Pragma_Argument_Associations (N));
10610
10611 if Present (Arg1) then
10612 Arg2 := Next (Arg1);
10613
10614 if Present (Arg2) then
10615 Arg3 := Next (Arg2);
10616
10617 if Present (Arg3) then
10618 Arg4 := Next (Arg3);
10619 end if;
10620 end if;
10621 end if;
10622 end if;
10623
10624 -- An enumeration type defines the pragmas that are supported by the
10625 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10626 -- into the corresponding enumeration value for the following case.
10627
10628 case Prag_Id is
10629
10630 -----------------
10631 -- Abort_Defer --
10632 -----------------
10633
10634 -- pragma Abort_Defer;
10635
10636 when Pragma_Abort_Defer =>
10637 GNAT_Pragma;
10638 Check_Arg_Count (0);
10639
10640 -- The only required semantic processing is to check the
10641 -- placement. This pragma must appear at the start of the
10642 -- statement sequence of a handled sequence of statements.
10643
10644 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
10645 or else N /= First (Statements (Parent (N)))
10646 then
10647 Pragma_Misplaced;
10648 end if;
10649
10650 --------------------
10651 -- Abstract_State --
10652 --------------------
10653
10654 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10655
10656 -- ABSTRACT_STATE_LIST ::=
10657 -- null
10658 -- | STATE_NAME_WITH_OPTIONS
10659 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10660
10661 -- STATE_NAME_WITH_OPTIONS ::=
10662 -- STATE_NAME
10663 -- | (STATE_NAME with OPTION_LIST)
10664
10665 -- OPTION_LIST ::= OPTION {, OPTION}
10666
10667 -- OPTION ::=
10668 -- SIMPLE_OPTION
10669 -- | NAME_VALUE_OPTION
10670
10671 -- SIMPLE_OPTION ::= Ghost | Synchronous
10672
10673 -- NAME_VALUE_OPTION ::=
10674 -- Part_Of => ABSTRACT_STATE
10675 -- | External [=> EXTERNAL_PROPERTY_LIST]
10676
10677 -- EXTERNAL_PROPERTY_LIST ::=
10678 -- EXTERNAL_PROPERTY
10679 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10680
10681 -- EXTERNAL_PROPERTY ::=
10682 -- Async_Readers [=> boolean_EXPRESSION]
10683 -- | Async_Writers [=> boolean_EXPRESSION]
10684 -- | Effective_Reads [=> boolean_EXPRESSION]
10685 -- | Effective_Writes [=> boolean_EXPRESSION]
10686 -- others => boolean_EXPRESSION
10687
10688 -- STATE_NAME ::= defining_identifier
10689
10690 -- ABSTRACT_STATE ::= name
10691
10692 -- Characteristics:
10693
10694 -- * Analysis - The annotation is fully analyzed immediately upon
10695 -- elaboration as it cannot forward reference entities.
10696
10697 -- * Expansion - None.
10698
10699 -- * Template - The annotation utilizes the generic template of the
10700 -- related package declaration.
10701
10702 -- * Globals - The annotation cannot reference global entities.
10703
10704 -- * Instance - The annotation is instantiated automatically when
10705 -- the related generic package is instantiated.
10706
10707 when Pragma_Abstract_State => Abstract_State : declare
10708 Missing_Parentheses : Boolean := False;
10709 -- Flag set when a state declaration with options is not properly
10710 -- parenthesized.
10711
10712 -- Flags used to verify the consistency of states
10713
10714 Non_Null_Seen : Boolean := False;
10715 Null_Seen : Boolean := False;
10716
10717 procedure Analyze_Abstract_State
10718 (State : Node_Id;
10719 Pack_Id : Entity_Id);
10720 -- Verify the legality of a single state declaration. Create and
10721 -- decorate a state abstraction entity and introduce it into the
10722 -- visibility chain. Pack_Id denotes the entity or the related
10723 -- package where pragma Abstract_State appears.
10724
10725 procedure Malformed_State_Error (State : Node_Id);
10726 -- Emit an error concerning the illegal declaration of abstract
10727 -- state State. This routine diagnoses syntax errors that lead to
10728 -- a different parse tree. The error is issued regardless of the
10729 -- SPARK mode in effect.
10730
10731 ----------------------------
10732 -- Analyze_Abstract_State --
10733 ----------------------------
10734
10735 procedure Analyze_Abstract_State
10736 (State : Node_Id;
10737 Pack_Id : Entity_Id)
10738 is
10739 -- Flags used to verify the consistency of options
10740
10741 AR_Seen : Boolean := False;
10742 AW_Seen : Boolean := False;
10743 ER_Seen : Boolean := False;
10744 EW_Seen : Boolean := False;
10745 External_Seen : Boolean := False;
10746 Ghost_Seen : Boolean := False;
10747 Others_Seen : Boolean := False;
10748 Part_Of_Seen : Boolean := False;
10749 Synchronous_Seen : Boolean := False;
10750
10751 -- Flags used to store the static value of all external states'
10752 -- expressions.
10753
10754 AR_Val : Boolean := False;
10755 AW_Val : Boolean := False;
10756 ER_Val : Boolean := False;
10757 EW_Val : Boolean := False;
10758
10759 State_Id : Entity_Id := Empty;
10760 -- The entity to be generated for the current state declaration
10761
10762 procedure Analyze_External_Option (Opt : Node_Id);
10763 -- Verify the legality of option External
10764
10765 procedure Analyze_External_Property
10766 (Prop : Node_Id;
10767 Expr : Node_Id := Empty);
10768 -- Verify the legailty of a single external property. Prop
10769 -- denotes the external property. Expr is the expression used
10770 -- to set the property.
10771
10772 procedure Analyze_Part_Of_Option (Opt : Node_Id);
10773 -- Verify the legality of option Part_Of
10774
10775 procedure Check_Duplicate_Option
10776 (Opt : Node_Id;
10777 Status : in out Boolean);
10778 -- Flag Status denotes whether a particular option has been
10779 -- seen while processing a state. This routine verifies that
10780 -- Opt is not a duplicate option and sets the flag Status
10781 -- (SPARK RM 7.1.4(1)).
10782
10783 procedure Check_Duplicate_Property
10784 (Prop : Node_Id;
10785 Status : in out Boolean);
10786 -- Flag Status denotes whether a particular property has been
10787 -- seen while processing option External. This routine verifies
10788 -- that Prop is not a duplicate property and sets flag Status.
10789 -- Opt is not a duplicate property and sets the flag Status.
10790 -- (SPARK RM 7.1.4(2))
10791
10792 procedure Check_Ghost_Synchronous;
10793 -- Ensure that the abstract state is not subject to both Ghost
10794 -- and Synchronous simple options. Emit an error if this is the
10795 -- case.
10796
10797 procedure Create_Abstract_State
10798 (Nam : Name_Id;
10799 Decl : Node_Id;
10800 Loc : Source_Ptr;
10801 Is_Null : Boolean);
10802 -- Generate an abstract state entity with name Nam and enter it
10803 -- into visibility. Decl is the "declaration" of the state as
10804 -- it appears in pragma Abstract_State. Loc is the location of
10805 -- the related state "declaration". Flag Is_Null should be set
10806 -- when the associated Abstract_State pragma defines a null
10807 -- state.
10808
10809 -----------------------------
10810 -- Analyze_External_Option --
10811 -----------------------------
10812
10813 procedure Analyze_External_Option (Opt : Node_Id) is
10814 Errors : constant Nat := Serious_Errors_Detected;
10815 Prop : Node_Id;
10816 Props : Node_Id := Empty;
10817
10818 begin
10819 if Nkind (Opt) = N_Component_Association then
10820 Props := Expression (Opt);
10821 end if;
10822
10823 -- External state with properties
10824
10825 if Present (Props) then
10826
10827 -- Multiple properties appear as an aggregate
10828
10829 if Nkind (Props) = N_Aggregate then
10830
10831 -- Simple property form
10832
10833 Prop := First (Expressions (Props));
10834 while Present (Prop) loop
10835 Analyze_External_Property (Prop);
10836 Next (Prop);
10837 end loop;
10838
10839 -- Property with expression form
10840
10841 Prop := First (Component_Associations (Props));
10842 while Present (Prop) loop
10843 Analyze_External_Property
10844 (Prop => First (Choices (Prop)),
10845 Expr => Expression (Prop));
10846
10847 Next (Prop);
10848 end loop;
10849
10850 -- Single property
10851
10852 else
10853 Analyze_External_Property (Props);
10854 end if;
10855
10856 -- An external state defined without any properties defaults
10857 -- all properties to True.
10858
10859 else
10860 AR_Val := True;
10861 AW_Val := True;
10862 ER_Val := True;
10863 EW_Val := True;
10864 end if;
10865
10866 -- Once all external properties have been processed, verify
10867 -- their mutual interaction. Do not perform the check when
10868 -- at least one of the properties is illegal as this will
10869 -- produce a bogus error.
10870
10871 if Errors = Serious_Errors_Detected then
10872 Check_External_Properties
10873 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10874 end if;
10875 end Analyze_External_Option;
10876
10877 -------------------------------
10878 -- Analyze_External_Property --
10879 -------------------------------
10880
10881 procedure Analyze_External_Property
10882 (Prop : Node_Id;
10883 Expr : Node_Id := Empty)
10884 is
10885 Expr_Val : Boolean;
10886
10887 begin
10888 -- Check the placement of "others" (if available)
10889
10890 if Nkind (Prop) = N_Others_Choice then
10891 if Others_Seen then
10892 SPARK_Msg_N
10893 ("only one others choice allowed in option External",
10894 Prop);
10895 else
10896 Others_Seen := True;
10897 end if;
10898
10899 elsif Others_Seen then
10900 SPARK_Msg_N
10901 ("others must be the last property in option External",
10902 Prop);
10903
10904 -- The only remaining legal options are the four predefined
10905 -- external properties.
10906
10907 elsif Nkind (Prop) = N_Identifier
10908 and then Nam_In (Chars (Prop), Name_Async_Readers,
10909 Name_Async_Writers,
10910 Name_Effective_Reads,
10911 Name_Effective_Writes)
10912 then
10913 null;
10914
10915 -- Otherwise the construct is not a valid property
10916
10917 else
10918 SPARK_Msg_N ("invalid external state property", Prop);
10919 return;
10920 end if;
10921
10922 -- Ensure that the expression of the external state property
10923 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10924
10925 if Present (Expr) then
10926 Analyze_And_Resolve (Expr, Standard_Boolean);
10927
10928 if Is_OK_Static_Expression (Expr) then
10929 Expr_Val := Is_True (Expr_Value (Expr));
10930 else
10931 SPARK_Msg_N
10932 ("expression of external state property must be "
10933 & "static", Expr);
10934 end if;
10935
10936 -- The lack of expression defaults the property to True
10937
10938 else
10939 Expr_Val := True;
10940 end if;
10941
10942 -- Named properties
10943
10944 if Nkind (Prop) = N_Identifier then
10945 if Chars (Prop) = Name_Async_Readers then
10946 Check_Duplicate_Property (Prop, AR_Seen);
10947 AR_Val := Expr_Val;
10948
10949 elsif Chars (Prop) = Name_Async_Writers then
10950 Check_Duplicate_Property (Prop, AW_Seen);
10951 AW_Val := Expr_Val;
10952
10953 elsif Chars (Prop) = Name_Effective_Reads then
10954 Check_Duplicate_Property (Prop, ER_Seen);
10955 ER_Val := Expr_Val;
10956
10957 else
10958 Check_Duplicate_Property (Prop, EW_Seen);
10959 EW_Val := Expr_Val;
10960 end if;
10961
10962 -- The handling of property "others" must take into account
10963 -- all other named properties that have been encountered so
10964 -- far. Only those that have not been seen are affected by
10965 -- "others".
10966
10967 else
10968 if not AR_Seen then
10969 AR_Val := Expr_Val;
10970 end if;
10971
10972 if not AW_Seen then
10973 AW_Val := Expr_Val;
10974 end if;
10975
10976 if not ER_Seen then
10977 ER_Val := Expr_Val;
10978 end if;
10979
10980 if not EW_Seen then
10981 EW_Val := Expr_Val;
10982 end if;
10983 end if;
10984 end Analyze_External_Property;
10985
10986 ----------------------------
10987 -- Analyze_Part_Of_Option --
10988 ----------------------------
10989
10990 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10991 Encap : constant Node_Id := Expression (Opt);
10992 Constits : Elist_Id;
10993 Encap_Id : Entity_Id;
10994 Legal : Boolean;
10995
10996 begin
10997 Check_Duplicate_Option (Opt, Part_Of_Seen);
10998
10999 Analyze_Part_Of
11000 (Indic => First (Choices (Opt)),
11001 Item_Id => State_Id,
11002 Encap => Encap,
11003 Encap_Id => Encap_Id,
11004 Legal => Legal);
11005
11006 -- The Part_Of indicator transforms the abstract state into
11007 -- a constituent of the encapsulating state or single
11008 -- concurrent type.
11009
11010 if Legal then
11011 pragma Assert (Present (Encap_Id));
11012 Constits := Part_Of_Constituents (Encap_Id);
11013
11014 if No (Constits) then
11015 Constits := New_Elmt_List;
11016 Set_Part_Of_Constituents (Encap_Id, Constits);
11017 end if;
11018
11019 Append_Elmt (State_Id, Constits);
11020 Set_Encapsulating_State (State_Id, Encap_Id);
11021 end if;
11022 end Analyze_Part_Of_Option;
11023
11024 ----------------------------
11025 -- Check_Duplicate_Option --
11026 ----------------------------
11027
11028 procedure Check_Duplicate_Option
11029 (Opt : Node_Id;
11030 Status : in out Boolean)
11031 is
11032 begin
11033 if Status then
11034 SPARK_Msg_N ("duplicate state option", Opt);
11035 end if;
11036
11037 Status := True;
11038 end Check_Duplicate_Option;
11039
11040 ------------------------------
11041 -- Check_Duplicate_Property --
11042 ------------------------------
11043
11044 procedure Check_Duplicate_Property
11045 (Prop : Node_Id;
11046 Status : in out Boolean)
11047 is
11048 begin
11049 if Status then
11050 SPARK_Msg_N ("duplicate external property", Prop);
11051 end if;
11052
11053 Status := True;
11054 end Check_Duplicate_Property;
11055
11056 -----------------------------
11057 -- Check_Ghost_Synchronous --
11058 -----------------------------
11059
11060 procedure Check_Ghost_Synchronous is
11061 begin
11062 -- A synchronized abstract state cannot be Ghost and vice
11063 -- versa (SPARK RM 6.9(19)).
11064
11065 if Ghost_Seen and Synchronous_Seen then
11066 SPARK_Msg_N ("synchronized state cannot be ghost", State);
11067 end if;
11068 end Check_Ghost_Synchronous;
11069
11070 ---------------------------
11071 -- Create_Abstract_State --
11072 ---------------------------
11073
11074 procedure Create_Abstract_State
11075 (Nam : Name_Id;
11076 Decl : Node_Id;
11077 Loc : Source_Ptr;
11078 Is_Null : Boolean)
11079 is
11080 begin
11081 -- The abstract state may be semi-declared when the related
11082 -- package was withed through a limited with clause. In that
11083 -- case reuse the entity to fully declare the state.
11084
11085 if Present (Decl) and then Present (Entity (Decl)) then
11086 State_Id := Entity (Decl);
11087
11088 -- Otherwise the elaboration of pragma Abstract_State
11089 -- declares the state.
11090
11091 else
11092 State_Id := Make_Defining_Identifier (Loc, Nam);
11093
11094 if Present (Decl) then
11095 Set_Entity (Decl, State_Id);
11096 end if;
11097 end if;
11098
11099 -- Null states never come from source
11100
11101 Set_Comes_From_Source (State_Id, not Is_Null);
11102 Set_Parent (State_Id, State);
11103 Set_Ekind (State_Id, E_Abstract_State);
11104 Set_Etype (State_Id, Standard_Void_Type);
11105 Set_Encapsulating_State (State_Id, Empty);
11106
11107 -- An abstract state declared within a Ghost region becomes
11108 -- Ghost (SPARK RM 6.9(2)).
11109
11110 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
11111 Set_Is_Ghost_Entity (State_Id);
11112 end if;
11113
11114 -- Establish a link between the state declaration and the
11115 -- abstract state entity. Note that a null state remains as
11116 -- N_Null and does not carry any linkages.
11117
11118 if not Is_Null then
11119 if Present (Decl) then
11120 Set_Entity (Decl, State_Id);
11121 Set_Etype (Decl, Standard_Void_Type);
11122 end if;
11123
11124 -- Every non-null state must be defined, nameable and
11125 -- resolvable.
11126
11127 Push_Scope (Pack_Id);
11128 Generate_Definition (State_Id);
11129 Enter_Name (State_Id);
11130 Pop_Scope;
11131 end if;
11132 end Create_Abstract_State;
11133
11134 -- Local variables
11135
11136 Opt : Node_Id;
11137 Opt_Nam : Node_Id;
11138
11139 -- Start of processing for Analyze_Abstract_State
11140
11141 begin
11142 -- A package with a null abstract state is not allowed to
11143 -- declare additional states.
11144
11145 if Null_Seen then
11146 SPARK_Msg_NE
11147 ("package & has null abstract state", State, Pack_Id);
11148
11149 -- Null states appear as internally generated entities
11150
11151 elsif Nkind (State) = N_Null then
11152 Create_Abstract_State
11153 (Nam => New_Internal_Name ('S'),
11154 Decl => Empty,
11155 Loc => Sloc (State),
11156 Is_Null => True);
11157 Null_Seen := True;
11158
11159 -- Catch a case where a null state appears in a list of
11160 -- non-null states.
11161
11162 if Non_Null_Seen then
11163 SPARK_Msg_NE
11164 ("package & has non-null abstract state",
11165 State, Pack_Id);
11166 end if;
11167
11168 -- Simple state declaration
11169
11170 elsif Nkind (State) = N_Identifier then
11171 Create_Abstract_State
11172 (Nam => Chars (State),
11173 Decl => State,
11174 Loc => Sloc (State),
11175 Is_Null => False);
11176 Non_Null_Seen := True;
11177
11178 -- State declaration with various options. This construct
11179 -- appears as an extension aggregate in the tree.
11180
11181 elsif Nkind (State) = N_Extension_Aggregate then
11182 if Nkind (Ancestor_Part (State)) = N_Identifier then
11183 Create_Abstract_State
11184 (Nam => Chars (Ancestor_Part (State)),
11185 Decl => Ancestor_Part (State),
11186 Loc => Sloc (Ancestor_Part (State)),
11187 Is_Null => False);
11188 Non_Null_Seen := True;
11189 else
11190 SPARK_Msg_N
11191 ("state name must be an identifier",
11192 Ancestor_Part (State));
11193 end if;
11194
11195 -- Options External, Ghost and Synchronous appear as
11196 -- expressions.
11197
11198 Opt := First (Expressions (State));
11199 while Present (Opt) loop
11200 if Nkind (Opt) = N_Identifier then
11201
11202 -- External
11203
11204 if Chars (Opt) = Name_External then
11205 Check_Duplicate_Option (Opt, External_Seen);
11206 Analyze_External_Option (Opt);
11207
11208 -- Ghost
11209
11210 elsif Chars (Opt) = Name_Ghost then
11211 Check_Duplicate_Option (Opt, Ghost_Seen);
11212 Check_Ghost_Synchronous;
11213
11214 if Present (State_Id) then
11215 Set_Is_Ghost_Entity (State_Id);
11216 end if;
11217
11218 -- Synchronous
11219
11220 elsif Chars (Opt) = Name_Synchronous then
11221 Check_Duplicate_Option (Opt, Synchronous_Seen);
11222 Check_Ghost_Synchronous;
11223
11224 -- Option Part_Of without an encapsulating state is
11225 -- illegal (SPARK RM 7.1.4(9)).
11226
11227 elsif Chars (Opt) = Name_Part_Of then
11228 SPARK_Msg_N
11229 ("indicator Part_Of must denote abstract state, "
11230 & "single protected type or single task type",
11231 Opt);
11232
11233 -- Do not emit an error message when a previous state
11234 -- declaration with options was not parenthesized as
11235 -- the option is actually another state declaration.
11236 --
11237 -- with Abstract_State
11238 -- (State_1 with ..., -- missing parentheses
11239 -- (State_2 with ...),
11240 -- State_3) -- ok state declaration
11241
11242 elsif Missing_Parentheses then
11243 null;
11244
11245 -- Otherwise the option is not allowed. Note that it
11246 -- is not possible to distinguish between an option
11247 -- and a state declaration when a previous state with
11248 -- options not properly parentheses.
11249 --
11250 -- with Abstract_State
11251 -- (State_1 with ..., -- missing parentheses
11252 -- State_2); -- could be an option
11253
11254 else
11255 SPARK_Msg_N
11256 ("simple option not allowed in state declaration",
11257 Opt);
11258 end if;
11259
11260 -- Catch a case where missing parentheses around a state
11261 -- declaration with options cause a subsequent state
11262 -- declaration with options to be treated as an option.
11263 --
11264 -- with Abstract_State
11265 -- (State_1 with ..., -- missing parentheses
11266 -- (State_2 with ...))
11267
11268 elsif Nkind (Opt) = N_Extension_Aggregate then
11269 Missing_Parentheses := True;
11270 SPARK_Msg_N
11271 ("state declaration must be parenthesized",
11272 Ancestor_Part (State));
11273
11274 -- Otherwise the option is malformed
11275
11276 else
11277 SPARK_Msg_N ("malformed option", Opt);
11278 end if;
11279
11280 Next (Opt);
11281 end loop;
11282
11283 -- Options External and Part_Of appear as component
11284 -- associations.
11285
11286 Opt := First (Component_Associations (State));
11287 while Present (Opt) loop
11288 Opt_Nam := First (Choices (Opt));
11289
11290 if Nkind (Opt_Nam) = N_Identifier then
11291 if Chars (Opt_Nam) = Name_External then
11292 Analyze_External_Option (Opt);
11293
11294 elsif Chars (Opt_Nam) = Name_Part_Of then
11295 Analyze_Part_Of_Option (Opt);
11296
11297 else
11298 SPARK_Msg_N ("invalid state option", Opt);
11299 end if;
11300 else
11301 SPARK_Msg_N ("invalid state option", Opt);
11302 end if;
11303
11304 Next (Opt);
11305 end loop;
11306
11307 -- Any other attempt to declare a state is illegal
11308
11309 else
11310 Malformed_State_Error (State);
11311 return;
11312 end if;
11313
11314 -- Guard against a junk state. In such cases no entity is
11315 -- generated and the subsequent checks cannot be applied.
11316
11317 if Present (State_Id) then
11318
11319 -- Verify whether the state does not introduce an illegal
11320 -- hidden state within a package subject to a null abstract
11321 -- state.
11322
11323 Check_No_Hidden_State (State_Id);
11324
11325 -- Check whether the lack of option Part_Of agrees with the
11326 -- placement of the abstract state with respect to the state
11327 -- space.
11328
11329 if not Part_Of_Seen then
11330 Check_Missing_Part_Of (State_Id);
11331 end if;
11332
11333 -- Associate the state with its related package
11334
11335 if No (Abstract_States (Pack_Id)) then
11336 Set_Abstract_States (Pack_Id, New_Elmt_List);
11337 end if;
11338
11339 Append_Elmt (State_Id, Abstract_States (Pack_Id));
11340 end if;
11341 end Analyze_Abstract_State;
11342
11343 ---------------------------
11344 -- Malformed_State_Error --
11345 ---------------------------
11346
11347 procedure Malformed_State_Error (State : Node_Id) is
11348 begin
11349 Error_Msg_N ("malformed abstract state declaration", State);
11350
11351 -- An abstract state with a simple option is being declared
11352 -- with "=>" rather than the legal "with". The state appears
11353 -- as a component association.
11354
11355 if Nkind (State) = N_Component_Association then
11356 Error_Msg_N ("\use WITH to specify simple option", State);
11357 end if;
11358 end Malformed_State_Error;
11359
11360 -- Local variables
11361
11362 Pack_Decl : Node_Id;
11363 Pack_Id : Entity_Id;
11364 State : Node_Id;
11365 States : Node_Id;
11366
11367 -- Start of processing for Abstract_State
11368
11369 begin
11370 GNAT_Pragma;
11371 Check_No_Identifiers;
11372 Check_Arg_Count (1);
11373
11374 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
11375
11376 -- Ensure the proper placement of the pragma. Abstract states must
11377 -- be associated with a package declaration.
11378
11379 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
11380 N_Package_Declaration)
11381 then
11382 null;
11383
11384 -- Otherwise the pragma is associated with an illegal construct
11385
11386 else
11387 Pragma_Misplaced;
11388 return;
11389 end if;
11390
11391 Pack_Id := Defining_Entity (Pack_Decl);
11392
11393 -- A pragma that applies to a Ghost entity becomes Ghost for the
11394 -- purposes of legality checks and removal of ignored Ghost code.
11395
11396 Mark_Ghost_Pragma (N, Pack_Id);
11397 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
11398
11399 -- Chain the pragma on the contract for completeness
11400
11401 Add_Contract_Item (N, Pack_Id);
11402
11403 -- The legality checks of pragmas Abstract_State, Initializes, and
11404 -- Initial_Condition are affected by the SPARK mode in effect. In
11405 -- addition, these three pragmas are subject to an inherent order:
11406
11407 -- 1) Abstract_State
11408 -- 2) Initializes
11409 -- 3) Initial_Condition
11410
11411 -- Analyze all these pragmas in the order outlined above
11412
11413 Analyze_If_Present (Pragma_SPARK_Mode);
11414 States := Expression (Get_Argument (N, Pack_Id));
11415
11416 -- Multiple non-null abstract states appear as an aggregate
11417
11418 if Nkind (States) = N_Aggregate then
11419 State := First (Expressions (States));
11420 while Present (State) loop
11421 Analyze_Abstract_State (State, Pack_Id);
11422 Next (State);
11423 end loop;
11424
11425 -- An abstract state with a simple option is being illegaly
11426 -- declared with "=>" rather than "with". In this case the
11427 -- state declaration appears as a component association.
11428
11429 if Present (Component_Associations (States)) then
11430 State := First (Component_Associations (States));
11431 while Present (State) loop
11432 Malformed_State_Error (State);
11433 Next (State);
11434 end loop;
11435 end if;
11436
11437 -- Various forms of a single abstract state. Note that these may
11438 -- include malformed state declarations.
11439
11440 else
11441 Analyze_Abstract_State (States, Pack_Id);
11442 end if;
11443
11444 Analyze_If_Present (Pragma_Initializes);
11445 Analyze_If_Present (Pragma_Initial_Condition);
11446 end Abstract_State;
11447
11448 ------------
11449 -- Ada_83 --
11450 ------------
11451
11452 -- pragma Ada_83;
11453
11454 -- Note: this pragma also has some specific processing in Par.Prag
11455 -- because we want to set the Ada version mode during parsing.
11456
11457 when Pragma_Ada_83 =>
11458 GNAT_Pragma;
11459 Check_Arg_Count (0);
11460
11461 -- We really should check unconditionally for proper configuration
11462 -- pragma placement, since we really don't want mixed Ada modes
11463 -- within a single unit, and the GNAT reference manual has always
11464 -- said this was a configuration pragma, but we did not check and
11465 -- are hesitant to add the check now.
11466
11467 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11468 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11469 -- or Ada 2012 mode.
11470
11471 if Ada_Version >= Ada_2005 then
11472 Check_Valid_Configuration_Pragma;
11473 end if;
11474
11475 -- Now set Ada 83 mode
11476
11477 if Latest_Ada_Only then
11478 Error_Pragma ("??pragma% ignored");
11479 else
11480 Ada_Version := Ada_83;
11481 Ada_Version_Explicit := Ada_83;
11482 Ada_Version_Pragma := N;
11483 end if;
11484
11485 ------------
11486 -- Ada_95 --
11487 ------------
11488
11489 -- pragma Ada_95;
11490
11491 -- Note: this pragma also has some specific processing in Par.Prag
11492 -- because we want to set the Ada 83 version mode during parsing.
11493
11494 when Pragma_Ada_95 =>
11495 GNAT_Pragma;
11496 Check_Arg_Count (0);
11497
11498 -- We really should check unconditionally for proper configuration
11499 -- pragma placement, since we really don't want mixed Ada modes
11500 -- within a single unit, and the GNAT reference manual has always
11501 -- said this was a configuration pragma, but we did not check and
11502 -- are hesitant to add the check now.
11503
11504 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11505 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11506
11507 if Ada_Version >= Ada_2005 then
11508 Check_Valid_Configuration_Pragma;
11509 end if;
11510
11511 -- Now set Ada 95 mode
11512
11513 if Latest_Ada_Only then
11514 Error_Pragma ("??pragma% ignored");
11515 else
11516 Ada_Version := Ada_95;
11517 Ada_Version_Explicit := Ada_95;
11518 Ada_Version_Pragma := N;
11519 end if;
11520
11521 ---------------------
11522 -- Ada_05/Ada_2005 --
11523 ---------------------
11524
11525 -- pragma Ada_05;
11526 -- pragma Ada_05 (LOCAL_NAME);
11527
11528 -- pragma Ada_2005;
11529 -- pragma Ada_2005 (LOCAL_NAME):
11530
11531 -- Note: these pragmas also have some specific processing in Par.Prag
11532 -- because we want to set the Ada 2005 version mode during parsing.
11533
11534 -- The one argument form is used for managing the transition from
11535 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
11536 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
11537 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
11538 -- mode, a preference rule is established which does not choose
11539 -- such an entity unless it is unambiguously specified. This avoids
11540 -- extra subprograms marked this way from generating ambiguities in
11541 -- otherwise legal pre-Ada_2005 programs. The one argument form is
11542 -- intended for exclusive use in the GNAT run-time library.
11543
11544 when Pragma_Ada_05
11545 | Pragma_Ada_2005
11546 =>
11547 declare
11548 E_Id : Node_Id;
11549
11550 begin
11551 GNAT_Pragma;
11552
11553 if Arg_Count = 1 then
11554 Check_Arg_Is_Local_Name (Arg1);
11555 E_Id := Get_Pragma_Arg (Arg1);
11556
11557 if Etype (E_Id) = Any_Type then
11558 return;
11559 end if;
11560
11561 Set_Is_Ada_2005_Only (Entity (E_Id));
11562 Record_Rep_Item (Entity (E_Id), N);
11563
11564 else
11565 Check_Arg_Count (0);
11566
11567 -- For Ada_2005 we unconditionally enforce the documented
11568 -- configuration pragma placement, since we do not want to
11569 -- tolerate mixed modes in a unit involving Ada 2005. That
11570 -- would cause real difficulties for those cases where there
11571 -- are incompatibilities between Ada 95 and Ada 2005.
11572
11573 Check_Valid_Configuration_Pragma;
11574
11575 -- Now set appropriate Ada mode
11576
11577 if Latest_Ada_Only then
11578 Error_Pragma ("??pragma% ignored");
11579 else
11580 Ada_Version := Ada_2005;
11581 Ada_Version_Explicit := Ada_2005;
11582 Ada_Version_Pragma := N;
11583 end if;
11584 end if;
11585 end;
11586
11587 ---------------------
11588 -- Ada_12/Ada_2012 --
11589 ---------------------
11590
11591 -- pragma Ada_12;
11592 -- pragma Ada_12 (LOCAL_NAME);
11593
11594 -- pragma Ada_2012;
11595 -- pragma Ada_2012 (LOCAL_NAME):
11596
11597 -- Note: these pragmas also have some specific processing in Par.Prag
11598 -- because we want to set the Ada 2012 version mode during parsing.
11599
11600 -- The one argument form is used for managing the transition from Ada
11601 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11602 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11603 -- mode will generate a warning. In addition, in any pre-Ada_2012
11604 -- mode, a preference rule is established which does not choose
11605 -- such an entity unless it is unambiguously specified. This avoids
11606 -- extra subprograms marked this way from generating ambiguities in
11607 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11608 -- intended for exclusive use in the GNAT run-time library.
11609
11610 when Pragma_Ada_12
11611 | Pragma_Ada_2012
11612 =>
11613 declare
11614 E_Id : Node_Id;
11615
11616 begin
11617 GNAT_Pragma;
11618
11619 if Arg_Count = 1 then
11620 Check_Arg_Is_Local_Name (Arg1);
11621 E_Id := Get_Pragma_Arg (Arg1);
11622
11623 if Etype (E_Id) = Any_Type then
11624 return;
11625 end if;
11626
11627 Set_Is_Ada_2012_Only (Entity (E_Id));
11628 Record_Rep_Item (Entity (E_Id), N);
11629
11630 else
11631 Check_Arg_Count (0);
11632
11633 -- For Ada_2012 we unconditionally enforce the documented
11634 -- configuration pragma placement, since we do not want to
11635 -- tolerate mixed modes in a unit involving Ada 2012. That
11636 -- would cause real difficulties for those cases where there
11637 -- are incompatibilities between Ada 95 and Ada 2012. We could
11638 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11639
11640 Check_Valid_Configuration_Pragma;
11641
11642 -- Now set appropriate Ada mode
11643
11644 Ada_Version := Ada_2012;
11645 Ada_Version_Explicit := Ada_2012;
11646 Ada_Version_Pragma := N;
11647 end if;
11648 end;
11649
11650 ----------------------
11651 -- All_Calls_Remote --
11652 ----------------------
11653
11654 -- pragma All_Calls_Remote [(library_package_NAME)];
11655
11656 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
11657 Lib_Entity : Entity_Id;
11658
11659 begin
11660 Check_Ada_83_Warning;
11661 Check_Valid_Library_Unit_Pragma;
11662
11663 if Nkind (N) = N_Null_Statement then
11664 return;
11665 end if;
11666
11667 Lib_Entity := Find_Lib_Unit_Name;
11668
11669 -- A pragma that applies to a Ghost entity becomes Ghost for the
11670 -- purposes of legality checks and removal of ignored Ghost code.
11671
11672 Mark_Ghost_Pragma (N, Lib_Entity);
11673
11674 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11675
11676 if Present (Lib_Entity) and then not Debug_Flag_U then
11677 if not Is_Remote_Call_Interface (Lib_Entity) then
11678 Error_Pragma ("pragma% only apply to rci unit");
11679
11680 -- Set flag for entity of the library unit
11681
11682 else
11683 Set_Has_All_Calls_Remote (Lib_Entity);
11684 end if;
11685 end if;
11686 end All_Calls_Remote;
11687
11688 ---------------------------
11689 -- Allow_Integer_Address --
11690 ---------------------------
11691
11692 -- pragma Allow_Integer_Address;
11693
11694 when Pragma_Allow_Integer_Address =>
11695 GNAT_Pragma;
11696 Check_Valid_Configuration_Pragma;
11697 Check_Arg_Count (0);
11698
11699 -- If Address is a private type, then set the flag to allow
11700 -- integer address values. If Address is not private, then this
11701 -- pragma has no purpose, so it is simply ignored. Not clear if
11702 -- there are any such targets now.
11703
11704 if Opt.Address_Is_Private then
11705 Opt.Allow_Integer_Address := True;
11706 end if;
11707
11708 --------------
11709 -- Annotate --
11710 --------------
11711
11712 -- pragma Annotate
11713 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11714 -- ARG ::= NAME | EXPRESSION
11715
11716 -- The first two arguments are by convention intended to refer to an
11717 -- external tool and a tool-specific function. These arguments are
11718 -- not analyzed.
11719
11720 when Pragma_Annotate => Annotate : declare
11721 Arg : Node_Id;
11722 Expr : Node_Id;
11723 Nam_Arg : Node_Id;
11724
11725 begin
11726 GNAT_Pragma;
11727 Check_At_Least_N_Arguments (1);
11728
11729 Nam_Arg := Last (Pragma_Argument_Associations (N));
11730
11731 -- Determine whether the last argument is "Entity => local_NAME"
11732 -- and if it is, perform the required semantic checks. Remove the
11733 -- argument from further processing.
11734
11735 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
11736 and then Chars (Nam_Arg) = Name_Entity
11737 then
11738 Check_Arg_Is_Local_Name (Nam_Arg);
11739 Arg_Count := Arg_Count - 1;
11740
11741 -- A pragma that applies to a Ghost entity becomes Ghost for
11742 -- the purposes of legality checks and removal of ignored Ghost
11743 -- code.
11744
11745 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
11746 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
11747 then
11748 Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg)));
11749 end if;
11750
11751 -- Not allowed in compiler units (bootstrap issues)
11752
11753 Check_Compiler_Unit ("Entity for pragma Annotate", N);
11754 end if;
11755
11756 -- Continue the processing with last argument removed for now
11757
11758 Check_Arg_Is_Identifier (Arg1);
11759 Check_No_Identifiers;
11760 Store_Note (N);
11761
11762 -- The second parameter is optional, it is never analyzed
11763
11764 if No (Arg2) then
11765 null;
11766
11767 -- Otherwise there is a second parameter
11768
11769 else
11770 -- The second parameter must be an identifier
11771
11772 Check_Arg_Is_Identifier (Arg2);
11773
11774 -- Process the remaining parameters (if any)
11775
11776 Arg := Next (Arg2);
11777 while Present (Arg) loop
11778 Expr := Get_Pragma_Arg (Arg);
11779 Analyze (Expr);
11780
11781 if Is_Entity_Name (Expr) then
11782 null;
11783
11784 -- For string literals, we assume Standard_String as the
11785 -- type, unless the string contains wide or wide_wide
11786 -- characters.
11787
11788 elsif Nkind (Expr) = N_String_Literal then
11789 if Has_Wide_Wide_Character (Expr) then
11790 Resolve (Expr, Standard_Wide_Wide_String);
11791 elsif Has_Wide_Character (Expr) then
11792 Resolve (Expr, Standard_Wide_String);
11793 else
11794 Resolve (Expr, Standard_String);
11795 end if;
11796
11797 elsif Is_Overloaded (Expr) then
11798 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
11799
11800 else
11801 Resolve (Expr);
11802 end if;
11803
11804 Next (Arg);
11805 end loop;
11806 end if;
11807 end Annotate;
11808
11809 -------------------------------------------------
11810 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11811 -------------------------------------------------
11812
11813 -- pragma Assert
11814 -- ( [Check => ] Boolean_EXPRESSION
11815 -- [, [Message =>] Static_String_EXPRESSION]);
11816
11817 -- pragma Assert_And_Cut
11818 -- ( [Check => ] Boolean_EXPRESSION
11819 -- [, [Message =>] Static_String_EXPRESSION]);
11820
11821 -- pragma Assume
11822 -- ( [Check => ] Boolean_EXPRESSION
11823 -- [, [Message =>] Static_String_EXPRESSION]);
11824
11825 -- pragma Loop_Invariant
11826 -- ( [Check => ] Boolean_EXPRESSION
11827 -- [, [Message =>] Static_String_EXPRESSION]);
11828
11829 when Pragma_Assert
11830 | Pragma_Assert_And_Cut
11831 | Pragma_Assume
11832 | Pragma_Loop_Invariant
11833 =>
11834 Assert : declare
11835 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
11836 -- Determine whether expression Expr contains a Loop_Entry
11837 -- attribute reference.
11838
11839 -------------------------
11840 -- Contains_Loop_Entry --
11841 -------------------------
11842
11843 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
11844 Has_Loop_Entry : Boolean := False;
11845
11846 function Process (N : Node_Id) return Traverse_Result;
11847 -- Process function for traversal to look for Loop_Entry
11848
11849 -------------
11850 -- Process --
11851 -------------
11852
11853 function Process (N : Node_Id) return Traverse_Result is
11854 begin
11855 if Nkind (N) = N_Attribute_Reference
11856 and then Attribute_Name (N) = Name_Loop_Entry
11857 then
11858 Has_Loop_Entry := True;
11859 return Abandon;
11860 else
11861 return OK;
11862 end if;
11863 end Process;
11864
11865 procedure Traverse is new Traverse_Proc (Process);
11866
11867 -- Start of processing for Contains_Loop_Entry
11868
11869 begin
11870 Traverse (Expr);
11871 return Has_Loop_Entry;
11872 end Contains_Loop_Entry;
11873
11874 -- Local variables
11875
11876 Expr : Node_Id;
11877 New_Args : List_Id;
11878
11879 -- Start of processing for Assert
11880
11881 begin
11882 -- Assert is an Ada 2005 RM-defined pragma
11883
11884 if Prag_Id = Pragma_Assert then
11885 Ada_2005_Pragma;
11886
11887 -- The remaining ones are GNAT pragmas
11888
11889 else
11890 GNAT_Pragma;
11891 end if;
11892
11893 Check_At_Least_N_Arguments (1);
11894 Check_At_Most_N_Arguments (2);
11895 Check_Arg_Order ((Name_Check, Name_Message));
11896 Check_Optional_Identifier (Arg1, Name_Check);
11897 Expr := Get_Pragma_Arg (Arg1);
11898
11899 -- Special processing for Loop_Invariant, Loop_Variant or for
11900 -- other cases where a Loop_Entry attribute is present. If the
11901 -- assertion pragma contains attribute Loop_Entry, ensure that
11902 -- the related pragma is within a loop.
11903
11904 if Prag_Id = Pragma_Loop_Invariant
11905 or else Prag_Id = Pragma_Loop_Variant
11906 or else Contains_Loop_Entry (Expr)
11907 then
11908 Check_Loop_Pragma_Placement;
11909
11910 -- Perform preanalysis to deal with embedded Loop_Entry
11911 -- attributes.
11912
11913 Preanalyze_Assert_Expression (Expr, Any_Boolean);
11914 end if;
11915
11916 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11917 -- a corresponding Check pragma:
11918
11919 -- pragma Check (name, condition [, msg]);
11920
11921 -- Where name is the identifier matching the pragma name. So
11922 -- rewrite pragma in this manner, transfer the message argument
11923 -- if present, and analyze the result
11924
11925 -- Note: When dealing with a semantically analyzed tree, the
11926 -- information that a Check node N corresponds to a source Assert,
11927 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11928 -- pragma kind of Original_Node(N).
11929
11930 New_Args := New_List (
11931 Make_Pragma_Argument_Association (Loc,
11932 Expression => Make_Identifier (Loc, Pname)),
11933 Make_Pragma_Argument_Association (Sloc (Expr),
11934 Expression => Expr));
11935
11936 if Arg_Count > 1 then
11937 Check_Optional_Identifier (Arg2, Name_Message);
11938
11939 -- Provide semantic annnotations for optional argument, for
11940 -- ASIS use, before rewriting.
11941
11942 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
11943 Append_To (New_Args, New_Copy_Tree (Arg2));
11944 end if;
11945
11946 -- Rewrite as Check pragma
11947
11948 Rewrite (N,
11949 Make_Pragma (Loc,
11950 Chars => Name_Check,
11951 Pragma_Argument_Associations => New_Args));
11952
11953 Analyze (N);
11954 end Assert;
11955
11956 ----------------------
11957 -- Assertion_Policy --
11958 ----------------------
11959
11960 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11961
11962 -- The following form is Ada 2012 only, but we allow it in all modes
11963
11964 -- Pragma Assertion_Policy (
11965 -- ASSERTION_KIND => POLICY_IDENTIFIER
11966 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11967
11968 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11969
11970 -- RM_ASSERTION_KIND ::= Assert |
11971 -- Static_Predicate |
11972 -- Dynamic_Predicate |
11973 -- Pre |
11974 -- Pre'Class |
11975 -- Post |
11976 -- Post'Class |
11977 -- Type_Invariant |
11978 -- Type_Invariant'Class
11979
11980 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11981 -- Assume |
11982 -- Contract_Cases |
11983 -- Debug |
11984 -- Default_Initial_Condition |
11985 -- Ghost |
11986 -- Initial_Condition |
11987 -- Loop_Invariant |
11988 -- Loop_Variant |
11989 -- Postcondition |
11990 -- Precondition |
11991 -- Predicate |
11992 -- Refined_Post |
11993 -- Statement_Assertions
11994
11995 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11996 -- ID_ASSERTION_KIND list contains implementation-defined additions
11997 -- recognized by GNAT. The effect is to control the behavior of
11998 -- identically named aspects and pragmas, depending on the specified
11999 -- policy identifier:
12000
12001 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12002
12003 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12004 -- implementation-defined addition that results in totally ignoring
12005 -- the corresponding assertion. If Disable is specified, then the
12006 -- argument of the assertion is not even analyzed. This is useful
12007 -- when the aspect/pragma argument references entities in a with'ed
12008 -- package that is replaced by a dummy package in the final build.
12009
12010 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12011 -- and Type_Invariant'Class were recognized by the parser and
12012 -- transformed into references to the special internal identifiers
12013 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12014 -- processing is required here.
12015
12016 when Pragma_Assertion_Policy => Assertion_Policy : declare
12017 procedure Resolve_Suppressible (Policy : Node_Id);
12018 -- Converts the assertion policy 'Suppressible' to either Check or
12019 -- Ignore based on whether checks are suppressed via -gnatp.
12020
12021 --------------------------
12022 -- Resolve_Suppressible --
12023 --------------------------
12024
12025 procedure Resolve_Suppressible (Policy : Node_Id) is
12026 Arg : constant Node_Id := Get_Pragma_Arg (Policy);
12027 Nam : Name_Id;
12028
12029 begin
12030 -- Transform policy argument Suppressible into either Ignore or
12031 -- Check depending on whether checks are enabled or suppressed.
12032
12033 if Chars (Arg) = Name_Suppressible then
12034 if Suppress_Checks then
12035 Nam := Name_Ignore;
12036 else
12037 Nam := Name_Check;
12038 end if;
12039
12040 Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam));
12041 end if;
12042 end Resolve_Suppressible;
12043
12044 -- Local variables
12045
12046 Arg : Node_Id;
12047 Kind : Name_Id;
12048 LocP : Source_Ptr;
12049 Policy : Node_Id;
12050
12051 begin
12052 Ada_2005_Pragma;
12053
12054 -- This can always appear as a configuration pragma
12055
12056 if Is_Configuration_Pragma then
12057 null;
12058
12059 -- It can also appear in a declarative part or package spec in Ada
12060 -- 2012 mode. We allow this in other modes, but in that case we
12061 -- consider that we have an Ada 2012 pragma on our hands.
12062
12063 else
12064 Check_Is_In_Decl_Part_Or_Package_Spec;
12065 Ada_2012_Pragma;
12066 end if;
12067
12068 -- One argument case with no identifier (first form above)
12069
12070 if Arg_Count = 1
12071 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
12072 or else Chars (Arg1) = No_Name)
12073 then
12074 Check_Arg_Is_One_Of (Arg1,
12075 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12076
12077 Resolve_Suppressible (Arg1);
12078
12079 -- Treat one argument Assertion_Policy as equivalent to:
12080
12081 -- pragma Check_Policy (Assertion, policy)
12082
12083 -- So rewrite pragma in that manner and link on to the chain
12084 -- of Check_Policy pragmas, marking the pragma as analyzed.
12085
12086 Policy := Get_Pragma_Arg (Arg1);
12087
12088 Rewrite (N,
12089 Make_Pragma (Loc,
12090 Chars => Name_Check_Policy,
12091 Pragma_Argument_Associations => New_List (
12092 Make_Pragma_Argument_Association (Loc,
12093 Expression => Make_Identifier (Loc, Name_Assertion)),
12094
12095 Make_Pragma_Argument_Association (Loc,
12096 Expression =>
12097 Make_Identifier (Sloc (Policy), Chars (Policy))))));
12098 Analyze (N);
12099
12100 -- Here if we have two or more arguments
12101
12102 else
12103 Check_At_Least_N_Arguments (1);
12104 Ada_2012_Pragma;
12105
12106 -- Loop through arguments
12107
12108 Arg := Arg1;
12109 while Present (Arg) loop
12110 LocP := Sloc (Arg);
12111
12112 -- Kind must be specified
12113
12114 if Nkind (Arg) /= N_Pragma_Argument_Association
12115 or else Chars (Arg) = No_Name
12116 then
12117 Error_Pragma_Arg
12118 ("missing assertion kind for pragma%", Arg);
12119 end if;
12120
12121 -- Check Kind and Policy have allowed forms
12122
12123 Kind := Chars (Arg);
12124 Policy := Get_Pragma_Arg (Arg);
12125
12126 if not Is_Valid_Assertion_Kind (Kind) then
12127 Error_Pragma_Arg
12128 ("invalid assertion kind for pragma%", Arg);
12129 end if;
12130
12131 Check_Arg_Is_One_Of (Arg,
12132 Name_Check, Name_Disable, Name_Ignore, Name_Suppressible);
12133
12134 Resolve_Suppressible (Arg);
12135
12136 if Kind = Name_Ghost then
12137
12138 -- The Ghost policy must be either Check or Ignore
12139 -- (SPARK RM 6.9(6)).
12140
12141 if not Nam_In (Chars (Policy), Name_Check,
12142 Name_Ignore)
12143 then
12144 Error_Pragma_Arg
12145 ("argument of pragma % Ghost must be Check or "
12146 & "Ignore", Policy);
12147 end if;
12148
12149 -- Pragma Assertion_Policy specifying a Ghost policy
12150 -- cannot occur within a Ghost subprogram or package
12151 -- (SPARK RM 6.9(14)).
12152
12153 if Ghost_Mode > None then
12154 Error_Pragma
12155 ("pragma % cannot appear within ghost subprogram or "
12156 & "package");
12157 end if;
12158 end if;
12159
12160 -- Rewrite the Assertion_Policy pragma as a series of
12161 -- Check_Policy pragmas of the form:
12162
12163 -- Check_Policy (Kind, Policy);
12164
12165 -- Note: the insertion of the pragmas cannot be done with
12166 -- Insert_Action because in the configuration case, there
12167 -- are no scopes on the scope stack and the mechanism will
12168 -- fail.
12169
12170 Insert_Before_And_Analyze (N,
12171 Make_Pragma (LocP,
12172 Chars => Name_Check_Policy,
12173 Pragma_Argument_Associations => New_List (
12174 Make_Pragma_Argument_Association (LocP,
12175 Expression => Make_Identifier (LocP, Kind)),
12176 Make_Pragma_Argument_Association (LocP,
12177 Expression => Policy))));
12178
12179 Arg := Next (Arg);
12180 end loop;
12181
12182 -- Rewrite the Assertion_Policy pragma as null since we have
12183 -- now inserted all the equivalent Check pragmas.
12184
12185 Rewrite (N, Make_Null_Statement (Loc));
12186 Analyze (N);
12187 end if;
12188 end Assertion_Policy;
12189
12190 ------------------------------
12191 -- Assume_No_Invalid_Values --
12192 ------------------------------
12193
12194 -- pragma Assume_No_Invalid_Values (On | Off);
12195
12196 when Pragma_Assume_No_Invalid_Values =>
12197 GNAT_Pragma;
12198 Check_Valid_Configuration_Pragma;
12199 Check_Arg_Count (1);
12200 Check_No_Identifiers;
12201 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12202
12203 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
12204 Assume_No_Invalid_Values := True;
12205 else
12206 Assume_No_Invalid_Values := False;
12207 end if;
12208
12209 --------------------------
12210 -- Attribute_Definition --
12211 --------------------------
12212
12213 -- pragma Attribute_Definition
12214 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
12215 -- [Entity =>] LOCAL_NAME,
12216 -- [Expression =>] EXPRESSION | NAME);
12217
12218 when Pragma_Attribute_Definition => Attribute_Definition : declare
12219 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
12220 Aname : Name_Id;
12221
12222 begin
12223 GNAT_Pragma;
12224 Check_Arg_Count (3);
12225 Check_Optional_Identifier (Arg1, "attribute");
12226 Check_Optional_Identifier (Arg2, "entity");
12227 Check_Optional_Identifier (Arg3, "expression");
12228
12229 if Nkind (Attribute_Designator) /= N_Identifier then
12230 Error_Msg_N ("attribute name expected", Attribute_Designator);
12231 return;
12232 end if;
12233
12234 Check_Arg_Is_Local_Name (Arg2);
12235
12236 -- If the attribute is not recognized, then issue a warning (not
12237 -- an error), and ignore the pragma.
12238
12239 Aname := Chars (Attribute_Designator);
12240
12241 if not Is_Attribute_Name (Aname) then
12242 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
12243 return;
12244 end if;
12245
12246 -- Otherwise, rewrite the pragma as an attribute definition clause
12247
12248 Rewrite (N,
12249 Make_Attribute_Definition_Clause (Loc,
12250 Name => Get_Pragma_Arg (Arg2),
12251 Chars => Aname,
12252 Expression => Get_Pragma_Arg (Arg3)));
12253 Analyze (N);
12254 end Attribute_Definition;
12255
12256 ------------------------------------------------------------------
12257 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
12258 ------------------------------------------------------------------
12259
12260 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
12261 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
12262 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
12263 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
12264
12265 when Pragma_Async_Readers
12266 | Pragma_Async_Writers
12267 | Pragma_Effective_Reads
12268 | Pragma_Effective_Writes
12269 =>
12270 Async_Effective : declare
12271 Obj_Decl : Node_Id;
12272 Obj_Id : Entity_Id;
12273
12274 begin
12275 GNAT_Pragma;
12276 Check_No_Identifiers;
12277 Check_At_Most_N_Arguments (1);
12278
12279 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
12280
12281 -- Object declaration
12282
12283 if Nkind (Obj_Decl) = N_Object_Declaration then
12284 null;
12285
12286 -- Otherwise the pragma is associated with an illegal construact
12287
12288 else
12289 Pragma_Misplaced;
12290 return;
12291 end if;
12292
12293 Obj_Id := Defining_Entity (Obj_Decl);
12294
12295 -- Perform minimal verification to ensure that the argument is at
12296 -- least a variable. Subsequent finer grained checks will be done
12297 -- at the end of the declarative region the contains the pragma.
12298
12299 if Ekind (Obj_Id) = E_Variable then
12300
12301 -- A pragma that applies to a Ghost entity becomes Ghost for
12302 -- the purposes of legality checks and removal of ignored Ghost
12303 -- code.
12304
12305 Mark_Ghost_Pragma (N, Obj_Id);
12306
12307 -- Chain the pragma on the contract for further processing by
12308 -- Analyze_External_Property_In_Decl_Part.
12309
12310 Add_Contract_Item (N, Obj_Id);
12311
12312 -- Analyze the Boolean expression (if any)
12313
12314 if Present (Arg1) then
12315 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
12316 end if;
12317
12318 -- Otherwise the external property applies to a constant
12319
12320 else
12321 Error_Pragma ("pragma % must apply to a volatile object");
12322 end if;
12323 end Async_Effective;
12324
12325 ------------------
12326 -- Asynchronous --
12327 ------------------
12328
12329 -- pragma Asynchronous (LOCAL_NAME);
12330
12331 when Pragma_Asynchronous => Asynchronous : declare
12332 C_Ent : Entity_Id;
12333 Decl : Node_Id;
12334 Formal : Entity_Id;
12335 L : List_Id;
12336 Nm : Entity_Id;
12337 S : Node_Id;
12338
12339 procedure Process_Async_Pragma;
12340 -- Common processing for procedure and access-to-procedure case
12341
12342 --------------------------
12343 -- Process_Async_Pragma --
12344 --------------------------
12345
12346 procedure Process_Async_Pragma is
12347 begin
12348 if No (L) then
12349 Set_Is_Asynchronous (Nm);
12350 return;
12351 end if;
12352
12353 -- The formals should be of mode IN (RM E.4.1(6))
12354
12355 S := First (L);
12356 while Present (S) loop
12357 Formal := Defining_Identifier (S);
12358
12359 if Nkind (Formal) = N_Defining_Identifier
12360 and then Ekind (Formal) /= E_In_Parameter
12361 then
12362 Error_Pragma_Arg
12363 ("pragma% procedure can only have IN parameter",
12364 Arg1);
12365 end if;
12366
12367 Next (S);
12368 end loop;
12369
12370 Set_Is_Asynchronous (Nm);
12371 end Process_Async_Pragma;
12372
12373 -- Start of processing for pragma Asynchronous
12374
12375 begin
12376 Check_Ada_83_Warning;
12377 Check_No_Identifiers;
12378 Check_Arg_Count (1);
12379 Check_Arg_Is_Local_Name (Arg1);
12380
12381 if Debug_Flag_U then
12382 return;
12383 end if;
12384
12385 C_Ent := Cunit_Entity (Current_Sem_Unit);
12386 Analyze (Get_Pragma_Arg (Arg1));
12387 Nm := Entity (Get_Pragma_Arg (Arg1));
12388
12389 -- A pragma that applies to a Ghost entity becomes Ghost for the
12390 -- purposes of legality checks and removal of ignored Ghost code.
12391
12392 Mark_Ghost_Pragma (N, Nm);
12393
12394 if not Is_Remote_Call_Interface (C_Ent)
12395 and then not Is_Remote_Types (C_Ent)
12396 then
12397 -- This pragma should only appear in an RCI or Remote Types
12398 -- unit (RM E.4.1(4)).
12399
12400 Error_Pragma
12401 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
12402 end if;
12403
12404 if Ekind (Nm) = E_Procedure
12405 and then Nkind (Parent (Nm)) = N_Procedure_Specification
12406 then
12407 if not Is_Remote_Call_Interface (Nm) then
12408 Error_Pragma_Arg
12409 ("pragma% cannot be applied on non-remote procedure",
12410 Arg1);
12411 end if;
12412
12413 L := Parameter_Specifications (Parent (Nm));
12414 Process_Async_Pragma;
12415 return;
12416
12417 elsif Ekind (Nm) = E_Function then
12418 Error_Pragma_Arg
12419 ("pragma% cannot be applied to function", Arg1);
12420
12421 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
12422 if Is_Record_Type (Nm) then
12423
12424 -- A record type that is the Equivalent_Type for a remote
12425 -- access-to-subprogram type.
12426
12427 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
12428
12429 else
12430 -- A non-expanded RAS type (distribution is not enabled)
12431
12432 Decl := Declaration_Node (Nm);
12433 end if;
12434
12435 if Nkind (Decl) = N_Full_Type_Declaration
12436 and then Nkind (Type_Definition (Decl)) =
12437 N_Access_Procedure_Definition
12438 then
12439 L := Parameter_Specifications (Type_Definition (Decl));
12440 Process_Async_Pragma;
12441
12442 if Is_Asynchronous (Nm)
12443 and then Expander_Active
12444 and then Get_PCS_Name /= Name_No_DSA
12445 then
12446 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
12447 end if;
12448
12449 else
12450 Error_Pragma_Arg
12451 ("pragma% cannot reference access-to-function type",
12452 Arg1);
12453 end if;
12454
12455 -- Only other possibility is Access-to-class-wide type
12456
12457 elsif Is_Access_Type (Nm)
12458 and then Is_Class_Wide_Type (Designated_Type (Nm))
12459 then
12460 Check_First_Subtype (Arg1);
12461 Set_Is_Asynchronous (Nm);
12462 if Expander_Active then
12463 RACW_Type_Is_Asynchronous (Nm);
12464 end if;
12465
12466 else
12467 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
12468 end if;
12469 end Asynchronous;
12470
12471 ------------
12472 -- Atomic --
12473 ------------
12474
12475 -- pragma Atomic (LOCAL_NAME);
12476
12477 when Pragma_Atomic =>
12478 Process_Atomic_Independent_Shared_Volatile;
12479
12480 -----------------------
12481 -- Atomic_Components --
12482 -----------------------
12483
12484 -- pragma Atomic_Components (array_LOCAL_NAME);
12485
12486 -- This processing is shared by Volatile_Components
12487
12488 when Pragma_Atomic_Components
12489 | Pragma_Volatile_Components
12490 =>
12491 Atomic_Components : declare
12492 D : Node_Id;
12493 E : Entity_Id;
12494 E_Id : Node_Id;
12495 K : Node_Kind;
12496
12497 begin
12498 Check_Ada_83_Warning;
12499 Check_No_Identifiers;
12500 Check_Arg_Count (1);
12501 Check_Arg_Is_Local_Name (Arg1);
12502 E_Id := Get_Pragma_Arg (Arg1);
12503
12504 if Etype (E_Id) = Any_Type then
12505 return;
12506 end if;
12507
12508 E := Entity (E_Id);
12509
12510 -- A pragma that applies to a Ghost entity becomes Ghost for the
12511 -- purposes of legality checks and removal of ignored Ghost code.
12512
12513 Mark_Ghost_Pragma (N, E);
12514 Check_Duplicate_Pragma (E);
12515
12516 if Rep_Item_Too_Early (E, N)
12517 or else
12518 Rep_Item_Too_Late (E, N)
12519 then
12520 return;
12521 end if;
12522
12523 D := Declaration_Node (E);
12524 K := Nkind (D);
12525
12526 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
12527 or else
12528 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12529 and then Nkind (D) = N_Object_Declaration
12530 and then Nkind (Object_Definition (D)) =
12531 N_Constrained_Array_Definition)
12532 then
12533 -- The flag is set on the object, or on the base type
12534
12535 if Nkind (D) /= N_Object_Declaration then
12536 E := Base_Type (E);
12537 end if;
12538
12539 -- Atomic implies both Independent and Volatile
12540
12541 if Prag_Id = Pragma_Atomic_Components then
12542 Set_Has_Atomic_Components (E);
12543 Set_Has_Independent_Components (E);
12544 end if;
12545
12546 Set_Has_Volatile_Components (E);
12547
12548 else
12549 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12550 end if;
12551 end Atomic_Components;
12552
12553 --------------------
12554 -- Attach_Handler --
12555 --------------------
12556
12557 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
12558
12559 when Pragma_Attach_Handler =>
12560 Check_Ada_83_Warning;
12561 Check_No_Identifiers;
12562 Check_Arg_Count (2);
12563
12564 if No_Run_Time_Mode then
12565 Error_Msg_CRT ("Attach_Handler pragma", N);
12566 else
12567 Check_Interrupt_Or_Attach_Handler;
12568
12569 -- The expression that designates the attribute may depend on a
12570 -- discriminant, and is therefore a per-object expression, to
12571 -- be expanded in the init proc. If expansion is enabled, then
12572 -- perform semantic checks on a copy only.
12573
12574 declare
12575 Temp : Node_Id;
12576 Typ : Node_Id;
12577 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
12578
12579 begin
12580 -- In Relaxed_RM_Semantics mode, we allow any static
12581 -- integer value, for compatibility with other compilers.
12582
12583 if Relaxed_RM_Semantics
12584 and then Nkind (Parg2) = N_Integer_Literal
12585 then
12586 Typ := Standard_Integer;
12587 else
12588 Typ := RTE (RE_Interrupt_ID);
12589 end if;
12590
12591 if Expander_Active then
12592 Temp := New_Copy_Tree (Parg2);
12593 Set_Parent (Temp, N);
12594 Preanalyze_And_Resolve (Temp, Typ);
12595 else
12596 Analyze (Parg2);
12597 Resolve (Parg2, Typ);
12598 end if;
12599 end;
12600
12601 Process_Interrupt_Or_Attach_Handler;
12602 end if;
12603
12604 --------------------
12605 -- C_Pass_By_Copy --
12606 --------------------
12607
12608 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
12609
12610 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
12611 Arg : Node_Id;
12612 Val : Uint;
12613
12614 begin
12615 GNAT_Pragma;
12616 Check_Valid_Configuration_Pragma;
12617 Check_Arg_Count (1);
12618 Check_Optional_Identifier (Arg1, "max_size");
12619
12620 Arg := Get_Pragma_Arg (Arg1);
12621 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
12622
12623 Val := Expr_Value (Arg);
12624
12625 if Val <= 0 then
12626 Error_Pragma_Arg
12627 ("maximum size for pragma% must be positive", Arg1);
12628
12629 elsif UI_Is_In_Int_Range (Val) then
12630 Default_C_Record_Mechanism := UI_To_Int (Val);
12631
12632 -- If a giant value is given, Int'Last will do well enough.
12633 -- If sometime someone complains that a record larger than
12634 -- two gigabytes is not copied, we will worry about it then.
12635
12636 else
12637 Default_C_Record_Mechanism := Mechanism_Type'Last;
12638 end if;
12639 end C_Pass_By_Copy;
12640
12641 -----------
12642 -- Check --
12643 -----------
12644
12645 -- pragma Check ([Name =>] CHECK_KIND,
12646 -- [Check =>] Boolean_EXPRESSION
12647 -- [,[Message =>] String_EXPRESSION]);
12648
12649 -- CHECK_KIND ::= IDENTIFIER |
12650 -- Pre'Class |
12651 -- Post'Class |
12652 -- Invariant'Class |
12653 -- Type_Invariant'Class
12654
12655 -- The identifiers Assertions and Statement_Assertions are not
12656 -- allowed, since they have special meaning for Check_Policy.
12657
12658 -- WARNING: The code below manages Ghost regions. Return statements
12659 -- must be replaced by gotos which jump to the end of the code and
12660 -- restore the Ghost mode.
12661
12662 when Pragma_Check => Check : declare
12663 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
12664 -- Save the Ghost mode to restore on exit
12665
12666 Cname : Name_Id;
12667 Eloc : Source_Ptr;
12668 Expr : Node_Id;
12669 Str : Node_Id;
12670
12671 begin
12672 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12673 -- the mode now to ensure that any nodes generated during analysis
12674 -- and expansion are marked as Ghost.
12675
12676 Set_Ghost_Mode (N);
12677
12678 GNAT_Pragma;
12679 Check_At_Least_N_Arguments (2);
12680 Check_At_Most_N_Arguments (3);
12681 Check_Optional_Identifier (Arg1, Name_Name);
12682 Check_Optional_Identifier (Arg2, Name_Check);
12683
12684 if Arg_Count = 3 then
12685 Check_Optional_Identifier (Arg3, Name_Message);
12686 Str := Get_Pragma_Arg (Arg3);
12687 end if;
12688
12689 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
12690 Check_Arg_Is_Identifier (Arg1);
12691 Cname := Chars (Get_Pragma_Arg (Arg1));
12692
12693 -- Check forbidden name Assertions or Statement_Assertions
12694
12695 case Cname is
12696 when Name_Assertions =>
12697 Error_Pragma_Arg
12698 ("""Assertions"" is not allowed as a check kind for "
12699 & "pragma%", Arg1);
12700
12701 when Name_Statement_Assertions =>
12702 Error_Pragma_Arg
12703 ("""Statement_Assertions"" is not allowed as a check kind "
12704 & "for pragma%", Arg1);
12705
12706 when others =>
12707 null;
12708 end case;
12709
12710 -- Check applicable policy. We skip this if Checked/Ignored status
12711 -- is already set (e.g. in the case of a pragma from an aspect).
12712
12713 if Is_Checked (N) or else Is_Ignored (N) then
12714 null;
12715
12716 -- For a non-source pragma that is a rewriting of another pragma,
12717 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12718
12719 elsif Is_Rewrite_Substitution (N)
12720 and then Nkind (Original_Node (N)) = N_Pragma
12721 and then Original_Node (N) /= N
12722 then
12723 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12724 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12725
12726 -- Otherwise query the applicable policy at this point
12727
12728 else
12729 case Check_Kind (Cname) is
12730 when Name_Ignore =>
12731 Set_Is_Ignored (N, True);
12732 Set_Is_Checked (N, False);
12733
12734 when Name_Check =>
12735 Set_Is_Ignored (N, False);
12736 Set_Is_Checked (N, True);
12737
12738 -- For disable, rewrite pragma as null statement and skip
12739 -- rest of the analysis of the pragma.
12740
12741 when Name_Disable =>
12742 Rewrite (N, Make_Null_Statement (Loc));
12743 Analyze (N);
12744 raise Pragma_Exit;
12745
12746 -- No other possibilities
12747
12748 when others =>
12749 raise Program_Error;
12750 end case;
12751 end if;
12752
12753 -- If check kind was not Disable, then continue pragma analysis
12754
12755 Expr := Get_Pragma_Arg (Arg2);
12756
12757 -- Deal with SCO generation
12758
12759 if Is_Checked (N) and then not Split_PPC (N) then
12760 Set_SCO_Pragma_Enabled (Loc);
12761 end if;
12762
12763 -- Deal with analyzing the string argument
12764
12765 if Arg_Count = 3 then
12766
12767 -- If checks are not on we don't want any expansion (since
12768 -- such expansion would not get properly deleted) but
12769 -- we do want to analyze (to get proper references).
12770 -- The Preanalyze_And_Resolve routine does just what we want
12771
12772 if Is_Ignored (N) then
12773 Preanalyze_And_Resolve (Str, Standard_String);
12774
12775 -- Otherwise we need a proper analysis and expansion
12776
12777 else
12778 Analyze_And_Resolve (Str, Standard_String);
12779 end if;
12780 end if;
12781
12782 -- Now you might think we could just do the same with the Boolean
12783 -- expression if checks are off (and expansion is on) and then
12784 -- rewrite the check as a null statement. This would work but we
12785 -- would lose the useful warnings about an assertion being bound
12786 -- to fail even if assertions are turned off.
12787
12788 -- So instead we wrap the boolean expression in an if statement
12789 -- that looks like:
12790
12791 -- if False and then condition then
12792 -- null;
12793 -- end if;
12794
12795 -- The reason we do this rewriting during semantic analysis rather
12796 -- than as part of normal expansion is that we cannot analyze and
12797 -- expand the code for the boolean expression directly, or it may
12798 -- cause insertion of actions that would escape the attempt to
12799 -- suppress the check code.
12800
12801 -- Note that the Sloc for the if statement corresponds to the
12802 -- argument condition, not the pragma itself. The reason for
12803 -- this is that we may generate a warning if the condition is
12804 -- False at compile time, and we do not want to delete this
12805 -- warning when we delete the if statement.
12806
12807 if Expander_Active and Is_Ignored (N) then
12808 Eloc := Sloc (Expr);
12809
12810 Rewrite (N,
12811 Make_If_Statement (Eloc,
12812 Condition =>
12813 Make_And_Then (Eloc,
12814 Left_Opnd => Make_Identifier (Eloc, Name_False),
12815 Right_Opnd => Expr),
12816 Then_Statements => New_List (
12817 Make_Null_Statement (Eloc))));
12818
12819 -- Now go ahead and analyze the if statement
12820
12821 In_Assertion_Expr := In_Assertion_Expr + 1;
12822
12823 -- One rather special treatment. If we are now in Eliminated
12824 -- overflow mode, then suppress overflow checking since we do
12825 -- not want to drag in the bignum stuff if we are in Ignore
12826 -- mode anyway. This is particularly important if we are using
12827 -- a configurable run time that does not support bignum ops.
12828
12829 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
12830 declare
12831 Svo : constant Boolean :=
12832 Scope_Suppress.Suppress (Overflow_Check);
12833 begin
12834 Scope_Suppress.Overflow_Mode_Assertions := Strict;
12835 Scope_Suppress.Suppress (Overflow_Check) := True;
12836 Analyze (N);
12837 Scope_Suppress.Suppress (Overflow_Check) := Svo;
12838 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
12839 end;
12840
12841 -- Not that special case
12842
12843 else
12844 Analyze (N);
12845 end if;
12846
12847 -- All done with this check
12848
12849 In_Assertion_Expr := In_Assertion_Expr - 1;
12850
12851 -- Check is active or expansion not active. In these cases we can
12852 -- just go ahead and analyze the boolean with no worries.
12853
12854 else
12855 In_Assertion_Expr := In_Assertion_Expr + 1;
12856 Analyze_And_Resolve (Expr, Any_Boolean);
12857 In_Assertion_Expr := In_Assertion_Expr - 1;
12858 end if;
12859
12860 Restore_Ghost_Mode (Saved_GM);
12861 end Check;
12862
12863 --------------------------
12864 -- Check_Float_Overflow --
12865 --------------------------
12866
12867 -- pragma Check_Float_Overflow;
12868
12869 when Pragma_Check_Float_Overflow =>
12870 GNAT_Pragma;
12871 Check_Valid_Configuration_Pragma;
12872 Check_Arg_Count (0);
12873 Check_Float_Overflow := not Machine_Overflows_On_Target;
12874
12875 ----------------
12876 -- Check_Name --
12877 ----------------
12878
12879 -- pragma Check_Name (check_IDENTIFIER);
12880
12881 when Pragma_Check_Name =>
12882 GNAT_Pragma;
12883 Check_No_Identifiers;
12884 Check_Valid_Configuration_Pragma;
12885 Check_Arg_Count (1);
12886 Check_Arg_Is_Identifier (Arg1);
12887
12888 declare
12889 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12890
12891 begin
12892 for J in Check_Names.First .. Check_Names.Last loop
12893 if Check_Names.Table (J) = Nam then
12894 return;
12895 end if;
12896 end loop;
12897
12898 Check_Names.Append (Nam);
12899 end;
12900
12901 ------------------
12902 -- Check_Policy --
12903 ------------------
12904
12905 -- This is the old style syntax, which is still allowed in all modes:
12906
12907 -- pragma Check_Policy ([Name =>] CHECK_KIND
12908 -- [Policy =>] POLICY_IDENTIFIER);
12909
12910 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12911
12912 -- CHECK_KIND ::= IDENTIFIER |
12913 -- Pre'Class |
12914 -- Post'Class |
12915 -- Type_Invariant'Class |
12916 -- Invariant'Class
12917
12918 -- This is the new style syntax, compatible with Assertion_Policy
12919 -- and also allowed in all modes.
12920
12921 -- Pragma Check_Policy (
12922 -- CHECK_KIND => POLICY_IDENTIFIER
12923 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12924
12925 -- Note: the identifiers Name and Policy are not allowed as
12926 -- Check_Kind values. This avoids ambiguities between the old and
12927 -- new form syntax.
12928
12929 when Pragma_Check_Policy => Check_Policy : declare
12930 Kind : Node_Id;
12931
12932 begin
12933 GNAT_Pragma;
12934 Check_At_Least_N_Arguments (1);
12935
12936 -- A Check_Policy pragma can appear either as a configuration
12937 -- pragma, or in a declarative part or a package spec (see RM
12938 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12939 -- followed for Check_Policy).
12940
12941 if not Is_Configuration_Pragma then
12942 Check_Is_In_Decl_Part_Or_Package_Spec;
12943 end if;
12944
12945 -- Figure out if we have the old or new syntax. We have the
12946 -- old syntax if the first argument has no identifier, or the
12947 -- identifier is Name.
12948
12949 if Nkind (Arg1) /= N_Pragma_Argument_Association
12950 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
12951 then
12952 -- Old syntax
12953
12954 Check_Arg_Count (2);
12955 Check_Optional_Identifier (Arg1, Name_Name);
12956 Kind := Get_Pragma_Arg (Arg1);
12957 Rewrite_Assertion_Kind (Kind,
12958 From_Policy => Comes_From_Source (N));
12959 Check_Arg_Is_Identifier (Arg1);
12960
12961 -- Check forbidden check kind
12962
12963 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
12964 Error_Msg_Name_2 := Chars (Kind);
12965 Error_Pragma_Arg
12966 ("pragma% does not allow% as check name", Arg1);
12967 end if;
12968
12969 -- Check policy
12970
12971 Check_Optional_Identifier (Arg2, Name_Policy);
12972 Check_Arg_Is_One_Of
12973 (Arg2,
12974 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
12975
12976 -- And chain pragma on the Check_Policy_List for search
12977
12978 Set_Next_Pragma (N, Opt.Check_Policy_List);
12979 Opt.Check_Policy_List := N;
12980
12981 -- For the new syntax, what we do is to convert each argument to
12982 -- an old syntax equivalent. We do that because we want to chain
12983 -- old style Check_Policy pragmas for the search (we don't want
12984 -- to have to deal with multiple arguments in the search).
12985
12986 else
12987 declare
12988 Arg : Node_Id;
12989 Argx : Node_Id;
12990 LocP : Source_Ptr;
12991 New_P : Node_Id;
12992
12993 begin
12994 Arg := Arg1;
12995 while Present (Arg) loop
12996 LocP := Sloc (Arg);
12997 Argx := Get_Pragma_Arg (Arg);
12998
12999 -- Kind must be specified
13000
13001 if Nkind (Arg) /= N_Pragma_Argument_Association
13002 or else Chars (Arg) = No_Name
13003 then
13004 Error_Pragma_Arg
13005 ("missing assertion kind for pragma%", Arg);
13006 end if;
13007
13008 -- Construct equivalent old form syntax Check_Policy
13009 -- pragma and insert it to get remaining checks.
13010
13011 New_P :=
13012 Make_Pragma (LocP,
13013 Chars => Name_Check_Policy,
13014 Pragma_Argument_Associations => New_List (
13015 Make_Pragma_Argument_Association (LocP,
13016 Expression =>
13017 Make_Identifier (LocP, Chars (Arg))),
13018 Make_Pragma_Argument_Association (Sloc (Argx),
13019 Expression => Argx)));
13020
13021 Arg := Next (Arg);
13022
13023 -- For a configuration pragma, insert old form in
13024 -- the corresponding file.
13025
13026 if Is_Configuration_Pragma then
13027 Insert_After (N, New_P);
13028 Analyze (New_P);
13029
13030 else
13031 Insert_Action (N, New_P);
13032 end if;
13033 end loop;
13034
13035 -- Rewrite original Check_Policy pragma to null, since we
13036 -- have converted it into a series of old syntax pragmas.
13037
13038 Rewrite (N, Make_Null_Statement (Loc));
13039 Analyze (N);
13040 end;
13041 end if;
13042 end Check_Policy;
13043
13044 -------------
13045 -- Comment --
13046 -------------
13047
13048 -- pragma Comment (static_string_EXPRESSION)
13049
13050 -- Processing for pragma Comment shares the circuitry for pragma
13051 -- Ident. The only differences are that Ident enforces a limit of 31
13052 -- characters on its argument, and also enforces limitations on
13053 -- placement for DEC compatibility. Pragma Comment shares neither of
13054 -- these restrictions.
13055
13056 -------------------
13057 -- Common_Object --
13058 -------------------
13059
13060 -- pragma Common_Object (
13061 -- [Internal =>] LOCAL_NAME
13062 -- [, [External =>] EXTERNAL_SYMBOL]
13063 -- [, [Size =>] EXTERNAL_SYMBOL]);
13064
13065 -- Processing for this pragma is shared with Psect_Object
13066
13067 ------------------------
13068 -- Compile_Time_Error --
13069 ------------------------
13070
13071 -- pragma Compile_Time_Error
13072 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13073
13074 when Pragma_Compile_Time_Error =>
13075 GNAT_Pragma;
13076 Process_Compile_Time_Warning_Or_Error;
13077
13078 --------------------------
13079 -- Compile_Time_Warning --
13080 --------------------------
13081
13082 -- pragma Compile_Time_Warning
13083 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13084
13085 when Pragma_Compile_Time_Warning =>
13086 GNAT_Pragma;
13087 Process_Compile_Time_Warning_Or_Error;
13088
13089 ---------------------------
13090 -- Compiler_Unit_Warning --
13091 ---------------------------
13092
13093 -- pragma Compiler_Unit_Warning;
13094
13095 -- Historical note
13096
13097 -- Originally, we had only pragma Compiler_Unit, and it resulted in
13098 -- errors not warnings. This means that we had introduced a big extra
13099 -- inertia to compiler changes, since even if we implemented a new
13100 -- feature, and even if all versions to be used for bootstrapping
13101 -- implemented this new feature, we could not use it, since old
13102 -- compilers would give errors for using this feature in units
13103 -- having Compiler_Unit pragmas.
13104
13105 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
13106 -- problem. We no longer have any units mentioning Compiler_Unit,
13107 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
13108 -- and thus generates a warning which can be ignored. So that deals
13109 -- with the problem of old compilers not implementing the newer form
13110 -- of the pragma.
13111
13112 -- Newer compilers recognize the new pragma, but generate warning
13113 -- messages instead of errors, which again can be ignored in the
13114 -- case of an old compiler which implements a wanted new feature
13115 -- but at the time felt like warning about it for older compilers.
13116
13117 -- We retain Compiler_Unit so that new compilers can be used to build
13118 -- older run-times that use this pragma. That's an unusual case, but
13119 -- it's easy enough to handle, so why not?
13120
13121 when Pragma_Compiler_Unit
13122 | Pragma_Compiler_Unit_Warning
13123 =>
13124 GNAT_Pragma;
13125 Check_Arg_Count (0);
13126
13127 -- Only recognized in main unit
13128
13129 if Current_Sem_Unit = Main_Unit then
13130 Compiler_Unit := True;
13131 end if;
13132
13133 -----------------------------
13134 -- Complete_Representation --
13135 -----------------------------
13136
13137 -- pragma Complete_Representation;
13138
13139 when Pragma_Complete_Representation =>
13140 GNAT_Pragma;
13141 Check_Arg_Count (0);
13142
13143 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
13144 Error_Pragma
13145 ("pragma & must appear within record representation clause");
13146 end if;
13147
13148 ----------------------------
13149 -- Complex_Representation --
13150 ----------------------------
13151
13152 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
13153
13154 when Pragma_Complex_Representation => Complex_Representation : declare
13155 E_Id : Entity_Id;
13156 E : Entity_Id;
13157 Ent : Entity_Id;
13158
13159 begin
13160 GNAT_Pragma;
13161 Check_Arg_Count (1);
13162 Check_Optional_Identifier (Arg1, Name_Entity);
13163 Check_Arg_Is_Local_Name (Arg1);
13164 E_Id := Get_Pragma_Arg (Arg1);
13165
13166 if Etype (E_Id) = Any_Type then
13167 return;
13168 end if;
13169
13170 E := Entity (E_Id);
13171
13172 if not Is_Record_Type (E) then
13173 Error_Pragma_Arg
13174 ("argument for pragma% must be record type", Arg1);
13175 end if;
13176
13177 Ent := First_Entity (E);
13178
13179 if No (Ent)
13180 or else No (Next_Entity (Ent))
13181 or else Present (Next_Entity (Next_Entity (Ent)))
13182 or else not Is_Floating_Point_Type (Etype (Ent))
13183 or else Etype (Ent) /= Etype (Next_Entity (Ent))
13184 then
13185 Error_Pragma_Arg
13186 ("record for pragma% must have two fields of the same "
13187 & "floating-point type", Arg1);
13188
13189 else
13190 Set_Has_Complex_Representation (Base_Type (E));
13191
13192 -- We need to treat the type has having a non-standard
13193 -- representation, for back-end purposes, even though in
13194 -- general a complex will have the default representation
13195 -- of a record with two real components.
13196
13197 Set_Has_Non_Standard_Rep (Base_Type (E));
13198 end if;
13199 end Complex_Representation;
13200
13201 -------------------------
13202 -- Component_Alignment --
13203 -------------------------
13204
13205 -- pragma Component_Alignment (
13206 -- [Form =>] ALIGNMENT_CHOICE
13207 -- [, [Name =>] type_LOCAL_NAME]);
13208 --
13209 -- ALIGNMENT_CHOICE ::=
13210 -- Component_Size
13211 -- | Component_Size_4
13212 -- | Storage_Unit
13213 -- | Default
13214
13215 when Pragma_Component_Alignment => Component_AlignmentP : declare
13216 Args : Args_List (1 .. 2);
13217 Names : constant Name_List (1 .. 2) := (
13218 Name_Form,
13219 Name_Name);
13220
13221 Form : Node_Id renames Args (1);
13222 Name : Node_Id renames Args (2);
13223
13224 Atype : Component_Alignment_Kind;
13225 Typ : Entity_Id;
13226
13227 begin
13228 GNAT_Pragma;
13229 Gather_Associations (Names, Args);
13230
13231 if No (Form) then
13232 Error_Pragma ("missing Form argument for pragma%");
13233 end if;
13234
13235 Check_Arg_Is_Identifier (Form);
13236
13237 -- Get proper alignment, note that Default = Component_Size on all
13238 -- machines we have so far, and we want to set this value rather
13239 -- than the default value to indicate that it has been explicitly
13240 -- set (and thus will not get overridden by the default component
13241 -- alignment for the current scope)
13242
13243 if Chars (Form) = Name_Component_Size then
13244 Atype := Calign_Component_Size;
13245
13246 elsif Chars (Form) = Name_Component_Size_4 then
13247 Atype := Calign_Component_Size_4;
13248
13249 elsif Chars (Form) = Name_Default then
13250 Atype := Calign_Component_Size;
13251
13252 elsif Chars (Form) = Name_Storage_Unit then
13253 Atype := Calign_Storage_Unit;
13254
13255 else
13256 Error_Pragma_Arg
13257 ("invalid Form parameter for pragma%", Form);
13258 end if;
13259
13260 -- The pragma appears in a configuration file
13261
13262 if No (Parent (N)) then
13263 Check_Valid_Configuration_Pragma;
13264
13265 -- Capture the component alignment in a global variable when
13266 -- the pragma appears in a configuration file. Note that the
13267 -- scope stack is empty at this point and cannot be used to
13268 -- store the alignment value.
13269
13270 Configuration_Component_Alignment := Atype;
13271
13272 -- Case with no name, supplied, affects scope table entry
13273
13274 elsif No (Name) then
13275 Scope_Stack.Table
13276 (Scope_Stack.Last).Component_Alignment_Default := Atype;
13277
13278 -- Case of name supplied
13279
13280 else
13281 Check_Arg_Is_Local_Name (Name);
13282 Find_Type (Name);
13283 Typ := Entity (Name);
13284
13285 if Typ = Any_Type
13286 or else Rep_Item_Too_Early (Typ, N)
13287 then
13288 return;
13289 else
13290 Typ := Underlying_Type (Typ);
13291 end if;
13292
13293 if not Is_Record_Type (Typ)
13294 and then not Is_Array_Type (Typ)
13295 then
13296 Error_Pragma_Arg
13297 ("Name parameter of pragma% must identify record or "
13298 & "array type", Name);
13299 end if;
13300
13301 -- An explicit Component_Alignment pragma overrides an
13302 -- implicit pragma Pack, but not an explicit one.
13303
13304 if not Has_Pragma_Pack (Base_Type (Typ)) then
13305 Set_Is_Packed (Base_Type (Typ), False);
13306 Set_Component_Alignment (Base_Type (Typ), Atype);
13307 end if;
13308 end if;
13309 end Component_AlignmentP;
13310
13311 --------------------------------
13312 -- Constant_After_Elaboration --
13313 --------------------------------
13314
13315 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
13316
13317 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
13318 declare
13319 Obj_Decl : Node_Id;
13320 Obj_Id : Entity_Id;
13321
13322 begin
13323 GNAT_Pragma;
13324 Check_No_Identifiers;
13325 Check_At_Most_N_Arguments (1);
13326
13327 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
13328
13329 -- Object declaration
13330
13331 if Nkind (Obj_Decl) = N_Object_Declaration then
13332 null;
13333
13334 -- Otherwise the pragma is associated with an illegal construct
13335
13336 else
13337 Pragma_Misplaced;
13338 return;
13339 end if;
13340
13341 Obj_Id := Defining_Entity (Obj_Decl);
13342
13343 -- The object declaration must be a library-level variable which
13344 -- is either explicitly initialized or obtains a value during the
13345 -- elaboration of a package body (SPARK RM 3.3.1).
13346
13347 if Ekind (Obj_Id) = E_Variable then
13348 if not Is_Library_Level_Entity (Obj_Id) then
13349 Error_Pragma
13350 ("pragma % must apply to a library level variable");
13351 return;
13352 end if;
13353
13354 -- Otherwise the pragma applies to a constant, which is illegal
13355
13356 else
13357 Error_Pragma ("pragma % must apply to a variable declaration");
13358 return;
13359 end if;
13360
13361 -- A pragma that applies to a Ghost entity becomes Ghost for the
13362 -- purposes of legality checks and removal of ignored Ghost code.
13363
13364 Mark_Ghost_Pragma (N, Obj_Id);
13365
13366 -- Chain the pragma on the contract for completeness
13367
13368 Add_Contract_Item (N, Obj_Id);
13369
13370 -- Analyze the Boolean expression (if any)
13371
13372 if Present (Arg1) then
13373 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
13374 end if;
13375 end Constant_After_Elaboration;
13376
13377 --------------------
13378 -- Contract_Cases --
13379 --------------------
13380
13381 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
13382
13383 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
13384
13385 -- CASE_GUARD ::= boolean_EXPRESSION | others
13386
13387 -- CONSEQUENCE ::= boolean_EXPRESSION
13388
13389 -- Characteristics:
13390
13391 -- * Analysis - The annotation undergoes initial checks to verify
13392 -- the legal placement and context. Secondary checks preanalyze the
13393 -- expressions in:
13394
13395 -- Analyze_Contract_Cases_In_Decl_Part
13396
13397 -- * Expansion - The annotation is expanded during the expansion of
13398 -- the related subprogram [body] contract as performed in:
13399
13400 -- Expand_Subprogram_Contract
13401
13402 -- * Template - The annotation utilizes the generic template of the
13403 -- related subprogram [body] when it is:
13404
13405 -- aspect on subprogram declaration
13406 -- aspect on stand alone subprogram body
13407 -- pragma on stand alone subprogram body
13408
13409 -- The annotation must prepare its own template when it is:
13410
13411 -- pragma on subprogram declaration
13412
13413 -- * Globals - Capture of global references must occur after full
13414 -- analysis.
13415
13416 -- * Instance - The annotation is instantiated automatically when
13417 -- the related generic subprogram [body] is instantiated except for
13418 -- the "pragma on subprogram declaration" case. In that scenario
13419 -- the annotation must instantiate itself.
13420
13421 when Pragma_Contract_Cases => Contract_Cases : declare
13422 Spec_Id : Entity_Id;
13423 Subp_Decl : Node_Id;
13424
13425 begin
13426 GNAT_Pragma;
13427 Check_No_Identifiers;
13428 Check_Arg_Count (1);
13429
13430 -- Ensure the proper placement of the pragma. Contract_Cases must
13431 -- be associated with a subprogram declaration or a body that acts
13432 -- as a spec.
13433
13434 Subp_Decl :=
13435 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
13436
13437 -- Entry
13438
13439 if Nkind (Subp_Decl) = N_Entry_Declaration then
13440 null;
13441
13442 -- Generic subprogram
13443
13444 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
13445 null;
13446
13447 -- Body acts as spec
13448
13449 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13450 and then No (Corresponding_Spec (Subp_Decl))
13451 then
13452 null;
13453
13454 -- Body stub acts as spec
13455
13456 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13457 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13458 then
13459 null;
13460
13461 -- Subprogram
13462
13463 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
13464 null;
13465
13466 else
13467 Pragma_Misplaced;
13468 return;
13469 end if;
13470
13471 Spec_Id := Unique_Defining_Entity (Subp_Decl);
13472
13473 -- A pragma that applies to a Ghost entity becomes Ghost for the
13474 -- purposes of legality checks and removal of ignored Ghost code.
13475
13476 Mark_Ghost_Pragma (N, Spec_Id);
13477 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
13478
13479 -- Chain the pragma on the contract for further processing by
13480 -- Analyze_Contract_Cases_In_Decl_Part.
13481
13482 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13483
13484 -- Fully analyze the pragma when it appears inside an entry
13485 -- or subprogram body because it cannot benefit from forward
13486 -- references.
13487
13488 if Nkind_In (Subp_Decl, N_Entry_Body,
13489 N_Subprogram_Body,
13490 N_Subprogram_Body_Stub)
13491 then
13492 -- The legality checks of pragma Contract_Cases are affected by
13493 -- the SPARK mode in effect and the volatility of the context.
13494 -- Analyze all pragmas in a specific order.
13495
13496 Analyze_If_Present (Pragma_SPARK_Mode);
13497 Analyze_If_Present (Pragma_Volatile_Function);
13498 Analyze_Contract_Cases_In_Decl_Part (N);
13499 end if;
13500 end Contract_Cases;
13501
13502 ----------------
13503 -- Controlled --
13504 ----------------
13505
13506 -- pragma Controlled (first_subtype_LOCAL_NAME);
13507
13508 when Pragma_Controlled => Controlled : declare
13509 Arg : Node_Id;
13510
13511 begin
13512 Check_No_Identifiers;
13513 Check_Arg_Count (1);
13514 Check_Arg_Is_Local_Name (Arg1);
13515 Arg := Get_Pragma_Arg (Arg1);
13516
13517 if not Is_Entity_Name (Arg)
13518 or else not Is_Access_Type (Entity (Arg))
13519 then
13520 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13521 else
13522 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
13523 end if;
13524 end Controlled;
13525
13526 ----------------
13527 -- Convention --
13528 ----------------
13529
13530 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
13531 -- [Entity =>] LOCAL_NAME);
13532
13533 when Pragma_Convention => Convention : declare
13534 C : Convention_Id;
13535 E : Entity_Id;
13536 pragma Warnings (Off, C);
13537 pragma Warnings (Off, E);
13538
13539 begin
13540 Check_Arg_Order ((Name_Convention, Name_Entity));
13541 Check_Ada_83_Warning;
13542 Check_Arg_Count (2);
13543 Process_Convention (C, E);
13544
13545 -- A pragma that applies to a Ghost entity becomes Ghost for the
13546 -- purposes of legality checks and removal of ignored Ghost code.
13547
13548 Mark_Ghost_Pragma (N, E);
13549 end Convention;
13550
13551 ---------------------------
13552 -- Convention_Identifier --
13553 ---------------------------
13554
13555 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
13556 -- [Convention =>] convention_IDENTIFIER);
13557
13558 when Pragma_Convention_Identifier => Convention_Identifier : declare
13559 Idnam : Name_Id;
13560 Cname : Name_Id;
13561
13562 begin
13563 GNAT_Pragma;
13564 Check_Arg_Order ((Name_Name, Name_Convention));
13565 Check_Arg_Count (2);
13566 Check_Optional_Identifier (Arg1, Name_Name);
13567 Check_Optional_Identifier (Arg2, Name_Convention);
13568 Check_Arg_Is_Identifier (Arg1);
13569 Check_Arg_Is_Identifier (Arg2);
13570 Idnam := Chars (Get_Pragma_Arg (Arg1));
13571 Cname := Chars (Get_Pragma_Arg (Arg2));
13572
13573 if Is_Convention_Name (Cname) then
13574 Record_Convention_Identifier
13575 (Idnam, Get_Convention_Id (Cname));
13576 else
13577 Error_Pragma_Arg
13578 ("second arg for % pragma must be convention", Arg2);
13579 end if;
13580 end Convention_Identifier;
13581
13582 ---------------
13583 -- CPP_Class --
13584 ---------------
13585
13586 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
13587
13588 when Pragma_CPP_Class =>
13589 GNAT_Pragma;
13590
13591 if Warn_On_Obsolescent_Feature then
13592 Error_Msg_N
13593 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
13594 & "effect; replace it by pragma import?j?", N);
13595 end if;
13596
13597 Check_Arg_Count (1);
13598
13599 Rewrite (N,
13600 Make_Pragma (Loc,
13601 Chars => Name_Import,
13602 Pragma_Argument_Associations => New_List (
13603 Make_Pragma_Argument_Association (Loc,
13604 Expression => Make_Identifier (Loc, Name_CPP)),
13605 New_Copy (First (Pragma_Argument_Associations (N))))));
13606 Analyze (N);
13607
13608 ---------------------
13609 -- CPP_Constructor --
13610 ---------------------
13611
13612 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
13613 -- [, [External_Name =>] static_string_EXPRESSION ]
13614 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13615
13616 when Pragma_CPP_Constructor => CPP_Constructor : declare
13617 Elmt : Elmt_Id;
13618 Id : Entity_Id;
13619 Def_Id : Entity_Id;
13620 Tag_Typ : Entity_Id;
13621
13622 begin
13623 GNAT_Pragma;
13624 Check_At_Least_N_Arguments (1);
13625 Check_At_Most_N_Arguments (3);
13626 Check_Optional_Identifier (Arg1, Name_Entity);
13627 Check_Arg_Is_Local_Name (Arg1);
13628
13629 Id := Get_Pragma_Arg (Arg1);
13630 Find_Program_Unit_Name (Id);
13631
13632 -- If we did not find the name, we are done
13633
13634 if Etype (Id) = Any_Type then
13635 return;
13636 end if;
13637
13638 Def_Id := Entity (Id);
13639
13640 -- Check if already defined as constructor
13641
13642 if Is_Constructor (Def_Id) then
13643 Error_Msg_N
13644 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
13645 return;
13646 end if;
13647
13648 if Ekind (Def_Id) = E_Function
13649 and then (Is_CPP_Class (Etype (Def_Id))
13650 or else (Is_Class_Wide_Type (Etype (Def_Id))
13651 and then
13652 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
13653 then
13654 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
13655 Error_Msg_N
13656 ("'C'P'P constructor must be defined in the scope of "
13657 & "its returned type", Arg1);
13658 end if;
13659
13660 if Arg_Count >= 2 then
13661 Set_Imported (Def_Id);
13662 Set_Is_Public (Def_Id);
13663 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
13664 end if;
13665
13666 Set_Has_Completion (Def_Id);
13667 Set_Is_Constructor (Def_Id);
13668 Set_Convention (Def_Id, Convention_CPP);
13669
13670 -- Imported C++ constructors are not dispatching primitives
13671 -- because in C++ they don't have a dispatch table slot.
13672 -- However, in Ada the constructor has the profile of a
13673 -- function that returns a tagged type and therefore it has
13674 -- been treated as a primitive operation during semantic
13675 -- analysis. We now remove it from the list of primitive
13676 -- operations of the type.
13677
13678 if Is_Tagged_Type (Etype (Def_Id))
13679 and then not Is_Class_Wide_Type (Etype (Def_Id))
13680 and then Is_Dispatching_Operation (Def_Id)
13681 then
13682 Tag_Typ := Etype (Def_Id);
13683
13684 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
13685 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
13686 Next_Elmt (Elmt);
13687 end loop;
13688
13689 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
13690 Set_Is_Dispatching_Operation (Def_Id, False);
13691 end if;
13692
13693 -- For backward compatibility, if the constructor returns a
13694 -- class wide type, and we internally change the return type to
13695 -- the corresponding root type.
13696
13697 if Is_Class_Wide_Type (Etype (Def_Id)) then
13698 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
13699 end if;
13700 else
13701 Error_Pragma_Arg
13702 ("pragma% requires function returning a 'C'P'P_Class type",
13703 Arg1);
13704 end if;
13705 end CPP_Constructor;
13706
13707 -----------------
13708 -- CPP_Virtual --
13709 -----------------
13710
13711 when Pragma_CPP_Virtual =>
13712 GNAT_Pragma;
13713
13714 if Warn_On_Obsolescent_Feature then
13715 Error_Msg_N
13716 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13717 & "effect?j?", N);
13718 end if;
13719
13720 ----------------
13721 -- CPP_Vtable --
13722 ----------------
13723
13724 when Pragma_CPP_Vtable =>
13725 GNAT_Pragma;
13726
13727 if Warn_On_Obsolescent_Feature then
13728 Error_Msg_N
13729 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13730 & "effect?j?", N);
13731 end if;
13732
13733 ---------
13734 -- CPU --
13735 ---------
13736
13737 -- pragma CPU (EXPRESSION);
13738
13739 when Pragma_CPU => CPU : declare
13740 P : constant Node_Id := Parent (N);
13741 Arg : Node_Id;
13742 Ent : Entity_Id;
13743
13744 begin
13745 Ada_2012_Pragma;
13746 Check_No_Identifiers;
13747 Check_Arg_Count (1);
13748
13749 -- Subprogram case
13750
13751 if Nkind (P) = N_Subprogram_Body then
13752 Check_In_Main_Program;
13753
13754 Arg := Get_Pragma_Arg (Arg1);
13755 Analyze_And_Resolve (Arg, Any_Integer);
13756
13757 Ent := Defining_Unit_Name (Specification (P));
13758
13759 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13760 Ent := Defining_Identifier (Ent);
13761 end if;
13762
13763 -- Must be static
13764
13765 if not Is_OK_Static_Expression (Arg) then
13766 Flag_Non_Static_Expr
13767 ("main subprogram affinity is not static!", Arg);
13768 raise Pragma_Exit;
13769
13770 -- If constraint error, then we already signalled an error
13771
13772 elsif Raises_Constraint_Error (Arg) then
13773 null;
13774
13775 -- Otherwise check in range
13776
13777 else
13778 declare
13779 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
13780 -- This is the entity System.Multiprocessors.CPU_Range;
13781
13782 Val : constant Uint := Expr_Value (Arg);
13783
13784 begin
13785 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
13786 or else
13787 Val > Expr_Value (Type_High_Bound (CPU_Id))
13788 then
13789 Error_Pragma_Arg
13790 ("main subprogram CPU is out of range", Arg1);
13791 end if;
13792 end;
13793 end if;
13794
13795 Set_Main_CPU
13796 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13797
13798 -- Task case
13799
13800 elsif Nkind (P) = N_Task_Definition then
13801 Arg := Get_Pragma_Arg (Arg1);
13802 Ent := Defining_Identifier (Parent (P));
13803
13804 -- The expression must be analyzed in the special manner
13805 -- described in "Handling of Default and Per-Object
13806 -- Expressions" in sem.ads.
13807
13808 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
13809
13810 -- Anything else is incorrect
13811
13812 else
13813 Pragma_Misplaced;
13814 end if;
13815
13816 -- Check duplicate pragma before we chain the pragma in the Rep
13817 -- Item chain of Ent.
13818
13819 Check_Duplicate_Pragma (Ent);
13820 Record_Rep_Item (Ent, N);
13821 end CPU;
13822
13823 --------------------
13824 -- Deadline_Floor --
13825 --------------------
13826
13827 -- pragma Deadline_Floor (time_span_EXPRESSION);
13828
13829 when Pragma_Deadline_Floor => Deadline_Floor : declare
13830 P : constant Node_Id := Parent (N);
13831 Arg : Node_Id;
13832 Ent : Entity_Id;
13833
13834 begin
13835 GNAT_Pragma;
13836 Check_No_Identifiers;
13837 Check_Arg_Count (1);
13838
13839 Arg := Get_Pragma_Arg (Arg1);
13840
13841 -- The expression must be analyzed in the special manner described
13842 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
13843
13844 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
13845
13846 -- Only protected types allowed
13847
13848 if Nkind (P) /= N_Protected_Definition then
13849 Pragma_Misplaced;
13850
13851 else
13852 Ent := Defining_Identifier (Parent (P));
13853
13854 -- Check duplicate pragma before we chain the pragma in the Rep
13855 -- Item chain of Ent.
13856
13857 Check_Duplicate_Pragma (Ent);
13858 Record_Rep_Item (Ent, N);
13859 end if;
13860 end Deadline_Floor;
13861
13862 -----------
13863 -- Debug --
13864 -----------
13865
13866 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13867
13868 when Pragma_Debug => Debug : declare
13869 Cond : Node_Id;
13870 Call : Node_Id;
13871
13872 begin
13873 GNAT_Pragma;
13874
13875 -- The condition for executing the call is that the expander
13876 -- is active and that we are not ignoring this debug pragma.
13877
13878 Cond :=
13879 New_Occurrence_Of
13880 (Boolean_Literals
13881 (Expander_Active and then not Is_Ignored (N)),
13882 Loc);
13883
13884 if not Is_Ignored (N) then
13885 Set_SCO_Pragma_Enabled (Loc);
13886 end if;
13887
13888 if Arg_Count = 2 then
13889 Cond :=
13890 Make_And_Then (Loc,
13891 Left_Opnd => Relocate_Node (Cond),
13892 Right_Opnd => Get_Pragma_Arg (Arg1));
13893 Call := Get_Pragma_Arg (Arg2);
13894 else
13895 Call := Get_Pragma_Arg (Arg1);
13896 end if;
13897
13898 if Nkind_In (Call,
13899 N_Indexed_Component,
13900 N_Function_Call,
13901 N_Identifier,
13902 N_Expanded_Name,
13903 N_Selected_Component)
13904 then
13905 -- If this pragma Debug comes from source, its argument was
13906 -- parsed as a name form (which is syntactically identical).
13907 -- In a generic context a parameterless call will be left as
13908 -- an expanded name (if global) or selected_component if local.
13909 -- Change it to a procedure call statement now.
13910
13911 Change_Name_To_Procedure_Call_Statement (Call);
13912
13913 elsif Nkind (Call) = N_Procedure_Call_Statement then
13914
13915 -- Already in the form of a procedure call statement: nothing
13916 -- to do (could happen in case of an internally generated
13917 -- pragma Debug).
13918
13919 null;
13920
13921 else
13922 -- All other cases: diagnose error
13923
13924 Error_Msg
13925 ("argument of pragma ""Debug"" is not procedure call",
13926 Sloc (Call));
13927 return;
13928 end if;
13929
13930 -- Rewrite into a conditional with an appropriate condition. We
13931 -- wrap the procedure call in a block so that overhead from e.g.
13932 -- use of the secondary stack does not generate execution overhead
13933 -- for suppressed conditions.
13934
13935 -- Normally the analysis that follows will freeze the subprogram
13936 -- being called. However, if the call is to a null procedure,
13937 -- we want to freeze it before creating the block, because the
13938 -- analysis that follows may be done with expansion disabled, in
13939 -- which case the body will not be generated, leading to spurious
13940 -- errors.
13941
13942 if Nkind (Call) = N_Procedure_Call_Statement
13943 and then Is_Entity_Name (Name (Call))
13944 then
13945 Analyze (Name (Call));
13946 Freeze_Before (N, Entity (Name (Call)));
13947 end if;
13948
13949 Rewrite (N,
13950 Make_Implicit_If_Statement (N,
13951 Condition => Cond,
13952 Then_Statements => New_List (
13953 Make_Block_Statement (Loc,
13954 Handled_Statement_Sequence =>
13955 Make_Handled_Sequence_Of_Statements (Loc,
13956 Statements => New_List (Relocate_Node (Call)))))));
13957 Analyze (N);
13958
13959 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13960 -- after analysis of the normally rewritten node, to capture all
13961 -- references to entities, which avoids issuing wrong warnings
13962 -- about unused entities.
13963
13964 if GNATprove_Mode then
13965 Rewrite (N, Make_Null_Statement (Loc));
13966 end if;
13967 end Debug;
13968
13969 ------------------
13970 -- Debug_Policy --
13971 ------------------
13972
13973 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13974
13975 when Pragma_Debug_Policy =>
13976 GNAT_Pragma;
13977 Check_Arg_Count (1);
13978 Check_No_Identifiers;
13979 Check_Arg_Is_Identifier (Arg1);
13980
13981 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13982 -- rewrite it that way, and let the rest of the checking come
13983 -- from analyzing the rewritten pragma.
13984
13985 Rewrite (N,
13986 Make_Pragma (Loc,
13987 Chars => Name_Check_Policy,
13988 Pragma_Argument_Associations => New_List (
13989 Make_Pragma_Argument_Association (Loc,
13990 Expression => Make_Identifier (Loc, Name_Debug)),
13991
13992 Make_Pragma_Argument_Association (Loc,
13993 Expression => Get_Pragma_Arg (Arg1)))));
13994 Analyze (N);
13995
13996 -------------------------------
13997 -- Default_Initial_Condition --
13998 -------------------------------
13999
14000 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14001
14002 when Pragma_Default_Initial_Condition => DIC : declare
14003 Discard : Boolean;
14004 Stmt : Node_Id;
14005 Typ : Entity_Id;
14006
14007 begin
14008 GNAT_Pragma;
14009 Check_No_Identifiers;
14010 Check_At_Most_N_Arguments (1);
14011
14012 Typ := Empty;
14013 Stmt := Prev (N);
14014 while Present (Stmt) loop
14015
14016 -- Skip prior pragmas, but check for duplicates
14017
14018 if Nkind (Stmt) = N_Pragma then
14019 if Pragma_Name (Stmt) = Pname then
14020 Duplication_Error
14021 (Prag => N,
14022 Prev => Stmt);
14023 raise Pragma_Exit;
14024 end if;
14025
14026 -- Skip internally generated code. Note that derived type
14027 -- declarations of untagged types with discriminants are
14028 -- rewritten as private type declarations.
14029
14030 elsif not Comes_From_Source (Stmt)
14031 and then Nkind (Stmt) /= N_Private_Type_Declaration
14032 then
14033 null;
14034
14035 -- The associated private type [extension] has been found, stop
14036 -- the search.
14037
14038 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
14039 N_Private_Type_Declaration)
14040 then
14041 Typ := Defining_Entity (Stmt);
14042 exit;
14043
14044 -- The pragma does not apply to a legal construct, issue an
14045 -- error and stop the analysis.
14046
14047 else
14048 Pragma_Misplaced;
14049 return;
14050 end if;
14051
14052 Stmt := Prev (Stmt);
14053 end loop;
14054
14055 -- The pragma does not apply to a legal construct, issue an error
14056 -- and stop the analysis.
14057
14058 if No (Typ) then
14059 Pragma_Misplaced;
14060 return;
14061 end if;
14062
14063 -- A pragma that applies to a Ghost entity becomes Ghost for the
14064 -- purposes of legality checks and removal of ignored Ghost code.
14065
14066 Mark_Ghost_Pragma (N, Typ);
14067
14068 -- The pragma signals that the type defines its own DIC assertion
14069 -- expression.
14070
14071 Set_Has_Own_DIC (Typ);
14072
14073 -- Chain the pragma on the rep item chain for further processing
14074
14075 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14076
14077 -- Create the declaration of the procedure which verifies the
14078 -- assertion expression of pragma DIC at runtime.
14079
14080 Build_DIC_Procedure_Declaration (Typ);
14081 end DIC;
14082
14083 ----------------------------------
14084 -- Default_Scalar_Storage_Order --
14085 ----------------------------------
14086
14087 -- pragma Default_Scalar_Storage_Order
14088 -- (High_Order_First | Low_Order_First);
14089
14090 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
14091 Default : Character;
14092
14093 begin
14094 GNAT_Pragma;
14095 Check_Arg_Count (1);
14096
14097 -- Default_Scalar_Storage_Order can appear as a configuration
14098 -- pragma, or in a declarative part of a package spec.
14099
14100 if not Is_Configuration_Pragma then
14101 Check_Is_In_Decl_Part_Or_Package_Spec;
14102 end if;
14103
14104 Check_No_Identifiers;
14105 Check_Arg_Is_One_Of
14106 (Arg1, Name_High_Order_First, Name_Low_Order_First);
14107 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14108 Default := Fold_Upper (Name_Buffer (1));
14109
14110 if not Support_Nondefault_SSO_On_Target
14111 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
14112 then
14113 if Warn_On_Unrecognized_Pragma then
14114 Error_Msg_N
14115 ("non-default Scalar_Storage_Order not supported "
14116 & "on target?g?", N);
14117 Error_Msg_N
14118 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
14119 end if;
14120
14121 -- Here set the specified default
14122
14123 else
14124 Opt.Default_SSO := Default;
14125 end if;
14126 end DSSO;
14127
14128 --------------------------
14129 -- Default_Storage_Pool --
14130 --------------------------
14131
14132 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
14133
14134 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
14135 Pool : Node_Id;
14136
14137 begin
14138 Ada_2012_Pragma;
14139 Check_Arg_Count (1);
14140
14141 -- Default_Storage_Pool can appear as a configuration pragma, or
14142 -- in a declarative part of a package spec.
14143
14144 if not Is_Configuration_Pragma then
14145 Check_Is_In_Decl_Part_Or_Package_Spec;
14146 end if;
14147
14148 if From_Aspect_Specification (N) then
14149 declare
14150 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
14151 begin
14152 if not In_Open_Scopes (E) then
14153 Error_Msg_N
14154 ("aspect must apply to package or subprogram", N);
14155 end if;
14156 end;
14157 end if;
14158
14159 if Present (Arg1) then
14160 Pool := Get_Pragma_Arg (Arg1);
14161
14162 -- Case of Default_Storage_Pool (null);
14163
14164 if Nkind (Pool) = N_Null then
14165 Analyze (Pool);
14166
14167 -- This is an odd case, this is not really an expression,
14168 -- so we don't have a type for it. So just set the type to
14169 -- Empty.
14170
14171 Set_Etype (Pool, Empty);
14172
14173 -- Case of Default_Storage_Pool (storage_pool_NAME);
14174
14175 else
14176 -- If it's a configuration pragma, then the only allowed
14177 -- argument is "null".
14178
14179 if Is_Configuration_Pragma then
14180 Error_Pragma_Arg ("NULL expected", Arg1);
14181 end if;
14182
14183 -- The expected type for a non-"null" argument is
14184 -- Root_Storage_Pool'Class, and the pool must be a variable.
14185
14186 Analyze_And_Resolve
14187 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
14188
14189 if Is_Variable (Pool) then
14190
14191 -- A pragma that applies to a Ghost entity becomes Ghost
14192 -- for the purposes of legality checks and removal of
14193 -- ignored Ghost code.
14194
14195 Mark_Ghost_Pragma (N, Entity (Pool));
14196
14197 else
14198 Error_Pragma_Arg
14199 ("default storage pool must be a variable", Arg1);
14200 end if;
14201 end if;
14202
14203 -- Record the pool name (or null). Freeze.Freeze_Entity for an
14204 -- access type will use this information to set the appropriate
14205 -- attributes of the access type.
14206
14207 Default_Pool := Pool;
14208 end if;
14209 end Default_Storage_Pool;
14210
14211 -------------
14212 -- Depends --
14213 -------------
14214
14215 -- pragma Depends (DEPENDENCY_RELATION);
14216
14217 -- DEPENDENCY_RELATION ::=
14218 -- null
14219 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
14220
14221 -- DEPENDENCY_CLAUSE ::=
14222 -- OUTPUT_LIST =>[+] INPUT_LIST
14223 -- | NULL_DEPENDENCY_CLAUSE
14224
14225 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
14226
14227 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
14228
14229 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
14230
14231 -- OUTPUT ::= NAME | FUNCTION_RESULT
14232 -- INPUT ::= NAME
14233
14234 -- where FUNCTION_RESULT is a function Result attribute_reference
14235
14236 -- Characteristics:
14237
14238 -- * Analysis - The annotation undergoes initial checks to verify
14239 -- the legal placement and context. Secondary checks fully analyze
14240 -- the dependency clauses in:
14241
14242 -- Analyze_Depends_In_Decl_Part
14243
14244 -- * Expansion - None.
14245
14246 -- * Template - The annotation utilizes the generic template of the
14247 -- related subprogram [body] when it is:
14248
14249 -- aspect on subprogram declaration
14250 -- aspect on stand alone subprogram body
14251 -- pragma on stand alone subprogram body
14252
14253 -- The annotation must prepare its own template when it is:
14254
14255 -- pragma on subprogram declaration
14256
14257 -- * Globals - Capture of global references must occur after full
14258 -- analysis.
14259
14260 -- * Instance - The annotation is instantiated automatically when
14261 -- the related generic subprogram [body] is instantiated except for
14262 -- the "pragma on subprogram declaration" case. In that scenario
14263 -- the annotation must instantiate itself.
14264
14265 when Pragma_Depends => Depends : declare
14266 Legal : Boolean;
14267 Spec_Id : Entity_Id;
14268 Subp_Decl : Node_Id;
14269
14270 begin
14271 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
14272
14273 if Legal then
14274
14275 -- Chain the pragma on the contract for further processing by
14276 -- Analyze_Depends_In_Decl_Part.
14277
14278 Add_Contract_Item (N, Spec_Id);
14279
14280 -- Fully analyze the pragma when it appears inside an entry
14281 -- or subprogram body because it cannot benefit from forward
14282 -- references.
14283
14284 if Nkind_In (Subp_Decl, N_Entry_Body,
14285 N_Subprogram_Body,
14286 N_Subprogram_Body_Stub)
14287 then
14288 -- The legality checks of pragmas Depends and Global are
14289 -- affected by the SPARK mode in effect and the volatility
14290 -- of the context. In addition these two pragmas are subject
14291 -- to an inherent order:
14292
14293 -- 1) Global
14294 -- 2) Depends
14295
14296 -- Analyze all these pragmas in the order outlined above
14297
14298 Analyze_If_Present (Pragma_SPARK_Mode);
14299 Analyze_If_Present (Pragma_Volatile_Function);
14300 Analyze_If_Present (Pragma_Global);
14301 Analyze_Depends_In_Decl_Part (N);
14302 end if;
14303 end if;
14304 end Depends;
14305
14306 ---------------------
14307 -- Detect_Blocking --
14308 ---------------------
14309
14310 -- pragma Detect_Blocking;
14311
14312 when Pragma_Detect_Blocking =>
14313 Ada_2005_Pragma;
14314 Check_Arg_Count (0);
14315 Check_Valid_Configuration_Pragma;
14316 Detect_Blocking := True;
14317
14318 ------------------------------------
14319 -- Disable_Atomic_Synchronization --
14320 ------------------------------------
14321
14322 -- pragma Disable_Atomic_Synchronization [(Entity)];
14323
14324 when Pragma_Disable_Atomic_Synchronization =>
14325 GNAT_Pragma;
14326 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
14327
14328 -------------------
14329 -- Discard_Names --
14330 -------------------
14331
14332 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
14333
14334 when Pragma_Discard_Names => Discard_Names : declare
14335 E : Entity_Id;
14336 E_Id : Node_Id;
14337
14338 begin
14339 Check_Ada_83_Warning;
14340
14341 -- Deal with configuration pragma case
14342
14343 if Arg_Count = 0 and then Is_Configuration_Pragma then
14344 Global_Discard_Names := True;
14345 return;
14346
14347 -- Otherwise, check correct appropriate context
14348
14349 else
14350 Check_Is_In_Decl_Part_Or_Package_Spec;
14351
14352 if Arg_Count = 0 then
14353
14354 -- If there is no parameter, then from now on this pragma
14355 -- applies to any enumeration, exception or tagged type
14356 -- defined in the current declarative part, and recursively
14357 -- to any nested scope.
14358
14359 Set_Discard_Names (Current_Scope);
14360 return;
14361
14362 else
14363 Check_Arg_Count (1);
14364 Check_Optional_Identifier (Arg1, Name_On);
14365 Check_Arg_Is_Local_Name (Arg1);
14366
14367 E_Id := Get_Pragma_Arg (Arg1);
14368
14369 if Etype (E_Id) = Any_Type then
14370 return;
14371 else
14372 E := Entity (E_Id);
14373 end if;
14374
14375 -- A pragma that applies to a Ghost entity becomes Ghost for
14376 -- the purposes of legality checks and removal of ignored
14377 -- Ghost code.
14378
14379 Mark_Ghost_Pragma (N, E);
14380
14381 if (Is_First_Subtype (E)
14382 and then
14383 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
14384 or else Ekind (E) = E_Exception
14385 then
14386 Set_Discard_Names (E);
14387 Record_Rep_Item (E, N);
14388
14389 else
14390 Error_Pragma_Arg
14391 ("inappropriate entity for pragma%", Arg1);
14392 end if;
14393 end if;
14394 end if;
14395 end Discard_Names;
14396
14397 ------------------------
14398 -- Dispatching_Domain --
14399 ------------------------
14400
14401 -- pragma Dispatching_Domain (EXPRESSION);
14402
14403 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
14404 P : constant Node_Id := Parent (N);
14405 Arg : Node_Id;
14406 Ent : Entity_Id;
14407
14408 begin
14409 Ada_2012_Pragma;
14410 Check_No_Identifiers;
14411 Check_Arg_Count (1);
14412
14413 -- This pragma is born obsolete, but not the aspect
14414
14415 if not From_Aspect_Specification (N) then
14416 Check_Restriction
14417 (No_Obsolescent_Features, Pragma_Identifier (N));
14418 end if;
14419
14420 if Nkind (P) = N_Task_Definition then
14421 Arg := Get_Pragma_Arg (Arg1);
14422 Ent := Defining_Identifier (Parent (P));
14423
14424 -- A pragma that applies to a Ghost entity becomes Ghost for
14425 -- the purposes of legality checks and removal of ignored Ghost
14426 -- code.
14427
14428 Mark_Ghost_Pragma (N, Ent);
14429
14430 -- The expression must be analyzed in the special manner
14431 -- described in "Handling of Default and Per-Object
14432 -- Expressions" in sem.ads.
14433
14434 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
14435
14436 -- Check duplicate pragma before we chain the pragma in the Rep
14437 -- Item chain of Ent.
14438
14439 Check_Duplicate_Pragma (Ent);
14440 Record_Rep_Item (Ent, N);
14441
14442 -- Anything else is incorrect
14443
14444 else
14445 Pragma_Misplaced;
14446 end if;
14447 end Dispatching_Domain;
14448
14449 ---------------
14450 -- Elaborate --
14451 ---------------
14452
14453 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
14454
14455 when Pragma_Elaborate => Elaborate : declare
14456 Arg : Node_Id;
14457 Citem : Node_Id;
14458
14459 begin
14460 -- Pragma must be in context items list of a compilation unit
14461
14462 if not Is_In_Context_Clause then
14463 Pragma_Misplaced;
14464 end if;
14465
14466 -- Must be at least one argument
14467
14468 if Arg_Count = 0 then
14469 Error_Pragma ("pragma% requires at least one argument");
14470 end if;
14471
14472 -- In Ada 83 mode, there can be no items following it in the
14473 -- context list except other pragmas and implicit with clauses
14474 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
14475 -- placement rule does not apply.
14476
14477 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
14478 Citem := Next (N);
14479 while Present (Citem) loop
14480 if Nkind (Citem) = N_Pragma
14481 or else (Nkind (Citem) = N_With_Clause
14482 and then Implicit_With (Citem))
14483 then
14484 null;
14485 else
14486 Error_Pragma
14487 ("(Ada 83) pragma% must be at end of context clause");
14488 end if;
14489
14490 Next (Citem);
14491 end loop;
14492 end if;
14493
14494 -- Finally, the arguments must all be units mentioned in a with
14495 -- clause in the same context clause. Note we already checked (in
14496 -- Par.Prag) that the arguments are all identifiers or selected
14497 -- components.
14498
14499 Arg := Arg1;
14500 Outer : while Present (Arg) loop
14501 Citem := First (List_Containing (N));
14502 Inner : while Citem /= N loop
14503 if Nkind (Citem) = N_With_Clause
14504 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
14505 then
14506 Set_Elaborate_Present (Citem, True);
14507 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
14508
14509 -- With the pragma present, elaboration calls on
14510 -- subprograms from the named unit need no further
14511 -- checks, as long as the pragma appears in the current
14512 -- compilation unit. If the pragma appears in some unit
14513 -- in the context, there might still be a need for an
14514 -- Elaborate_All_Desirable from the current compilation
14515 -- to the named unit, so we keep the check enabled.
14516
14517 if In_Extended_Main_Source_Unit (N) then
14518
14519 -- This does not apply in SPARK mode, where we allow
14520 -- pragma Elaborate, but we don't trust it to be right
14521 -- so we will still insist on the Elaborate_All.
14522
14523 if SPARK_Mode /= On then
14524 Set_Suppress_Elaboration_Warnings
14525 (Entity (Name (Citem)));
14526 end if;
14527 end if;
14528
14529 exit Inner;
14530 end if;
14531
14532 Next (Citem);
14533 end loop Inner;
14534
14535 if Citem = N then
14536 Error_Pragma_Arg
14537 ("argument of pragma% is not withed unit", Arg);
14538 end if;
14539
14540 Next (Arg);
14541 end loop Outer;
14542
14543 -- Give a warning if operating in static mode with one of the
14544 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
14545
14546 if Elab_Warnings
14547 and not Dynamic_Elaboration_Checks
14548
14549 -- pragma Elaborate not allowed in SPARK mode anyway. We
14550 -- already complained about it, no point in generating any
14551 -- further complaint.
14552
14553 and SPARK_Mode /= On
14554 then
14555 Error_Msg_N
14556 ("?l?use of pragma Elaborate may not be safe", N);
14557 Error_Msg_N
14558 ("?l?use pragma Elaborate_All instead if possible", N);
14559 end if;
14560 end Elaborate;
14561
14562 -------------------
14563 -- Elaborate_All --
14564 -------------------
14565
14566 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
14567
14568 when Pragma_Elaborate_All => Elaborate_All : declare
14569 Arg : Node_Id;
14570 Citem : Node_Id;
14571
14572 begin
14573 Check_Ada_83_Warning;
14574
14575 -- Pragma must be in context items list of a compilation unit
14576
14577 if not Is_In_Context_Clause then
14578 Pragma_Misplaced;
14579 end if;
14580
14581 -- Must be at least one argument
14582
14583 if Arg_Count = 0 then
14584 Error_Pragma ("pragma% requires at least one argument");
14585 end if;
14586
14587 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
14588 -- have to appear at the end of the context clause, but may
14589 -- appear mixed in with other items, even in Ada 83 mode.
14590
14591 -- Final check: the arguments must all be units mentioned in
14592 -- a with clause in the same context clause. Note that we
14593 -- already checked (in Par.Prag) that all the arguments are
14594 -- either identifiers or selected components.
14595
14596 Arg := Arg1;
14597 Outr : while Present (Arg) loop
14598 Citem := First (List_Containing (N));
14599 Innr : while Citem /= N loop
14600 if Nkind (Citem) = N_With_Clause
14601 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
14602 then
14603 Set_Elaborate_All_Present (Citem, True);
14604 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
14605
14606 -- Suppress warnings and elaboration checks on the named
14607 -- unit if the pragma is in the current compilation, as
14608 -- for pragma Elaborate.
14609
14610 if In_Extended_Main_Source_Unit (N) then
14611 Set_Suppress_Elaboration_Warnings
14612 (Entity (Name (Citem)));
14613 end if;
14614 exit Innr;
14615 end if;
14616
14617 Next (Citem);
14618 end loop Innr;
14619
14620 if Citem = N then
14621 Set_Error_Posted (N);
14622 Error_Pragma_Arg
14623 ("argument of pragma% is not withed unit", Arg);
14624 end if;
14625
14626 Next (Arg);
14627 end loop Outr;
14628 end Elaborate_All;
14629
14630 --------------------
14631 -- Elaborate_Body --
14632 --------------------
14633
14634 -- pragma Elaborate_Body [( library_unit_NAME )];
14635
14636 when Pragma_Elaborate_Body => Elaborate_Body : declare
14637 Cunit_Node : Node_Id;
14638 Cunit_Ent : Entity_Id;
14639
14640 begin
14641 Check_Ada_83_Warning;
14642 Check_Valid_Library_Unit_Pragma;
14643
14644 if Nkind (N) = N_Null_Statement then
14645 return;
14646 end if;
14647
14648 Cunit_Node := Cunit (Current_Sem_Unit);
14649 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14650
14651 -- A pragma that applies to a Ghost entity becomes Ghost for the
14652 -- purposes of legality checks and removal of ignored Ghost code.
14653
14654 Mark_Ghost_Pragma (N, Cunit_Ent);
14655
14656 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
14657 N_Subprogram_Body)
14658 then
14659 Error_Pragma ("pragma% must refer to a spec, not a body");
14660 else
14661 Set_Body_Required (Cunit_Node, True);
14662 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
14663
14664 -- If we are in dynamic elaboration mode, then we suppress
14665 -- elaboration warnings for the unit, since it is definitely
14666 -- fine NOT to do dynamic checks at the first level (and such
14667 -- checks will be suppressed because no elaboration boolean
14668 -- is created for Elaborate_Body packages).
14669
14670 -- But in the static model of elaboration, Elaborate_Body is
14671 -- definitely NOT good enough to ensure elaboration safety on
14672 -- its own, since the body may WITH other units that are not
14673 -- safe from an elaboration point of view, so a client must
14674 -- still do an Elaborate_All on such units.
14675
14676 -- Debug flag -gnatdD restores the old behavior of 3.13, where
14677 -- Elaborate_Body always suppressed elab warnings.
14678
14679 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
14680 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
14681 end if;
14682 end if;
14683 end Elaborate_Body;
14684
14685 ------------------------
14686 -- Elaboration_Checks --
14687 ------------------------
14688
14689 -- pragma Elaboration_Checks (Static | Dynamic);
14690
14691 when Pragma_Elaboration_Checks =>
14692 GNAT_Pragma;
14693 Check_Arg_Count (1);
14694 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
14695
14696 -- Set flag accordingly (ignore attempt at dynamic elaboration
14697 -- checks in SPARK mode).
14698
14699 Dynamic_Elaboration_Checks :=
14700 Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic;
14701
14702 ---------------
14703 -- Eliminate --
14704 ---------------
14705
14706 -- pragma Eliminate (
14707 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
14708 -- [,[Entity =>] IDENTIFIER |
14709 -- SELECTED_COMPONENT |
14710 -- STRING_LITERAL]
14711 -- [, OVERLOADING_RESOLUTION]);
14712
14713 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
14714 -- SOURCE_LOCATION
14715
14716 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
14717 -- FUNCTION_PROFILE
14718
14719 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
14720
14721 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
14722 -- Result_Type => result_SUBTYPE_NAME]
14723
14724 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
14725 -- SUBTYPE_NAME ::= STRING_LITERAL
14726
14727 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14728 -- SOURCE_TRACE ::= STRING_LITERAL
14729
14730 when Pragma_Eliminate => Eliminate : declare
14731 Args : Args_List (1 .. 5);
14732 Names : constant Name_List (1 .. 5) := (
14733 Name_Unit_Name,
14734 Name_Entity,
14735 Name_Parameter_Types,
14736 Name_Result_Type,
14737 Name_Source_Location);
14738
14739 Unit_Name : Node_Id renames Args (1);
14740 Entity : Node_Id renames Args (2);
14741 Parameter_Types : Node_Id renames Args (3);
14742 Result_Type : Node_Id renames Args (4);
14743 Source_Location : Node_Id renames Args (5);
14744
14745 begin
14746 GNAT_Pragma;
14747 Check_Valid_Configuration_Pragma;
14748 Gather_Associations (Names, Args);
14749
14750 if No (Unit_Name) then
14751 Error_Pragma ("missing Unit_Name argument for pragma%");
14752 end if;
14753
14754 if No (Entity)
14755 and then (Present (Parameter_Types)
14756 or else
14757 Present (Result_Type)
14758 or else
14759 Present (Source_Location))
14760 then
14761 Error_Pragma ("missing Entity argument for pragma%");
14762 end if;
14763
14764 if (Present (Parameter_Types)
14765 or else
14766 Present (Result_Type))
14767 and then
14768 Present (Source_Location)
14769 then
14770 Error_Pragma
14771 ("parameter profile and source location cannot be used "
14772 & "together in pragma%");
14773 end if;
14774
14775 Process_Eliminate_Pragma
14776 (N,
14777 Unit_Name,
14778 Entity,
14779 Parameter_Types,
14780 Result_Type,
14781 Source_Location);
14782 end Eliminate;
14783
14784 -----------------------------------
14785 -- Enable_Atomic_Synchronization --
14786 -----------------------------------
14787
14788 -- pragma Enable_Atomic_Synchronization [(Entity)];
14789
14790 when Pragma_Enable_Atomic_Synchronization =>
14791 GNAT_Pragma;
14792 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
14793
14794 ------------
14795 -- Export --
14796 ------------
14797
14798 -- pragma Export (
14799 -- [ Convention =>] convention_IDENTIFIER,
14800 -- [ Entity =>] LOCAL_NAME
14801 -- [, [External_Name =>] static_string_EXPRESSION ]
14802 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14803
14804 when Pragma_Export => Export : declare
14805 C : Convention_Id;
14806 Def_Id : Entity_Id;
14807
14808 pragma Warnings (Off, C);
14809
14810 begin
14811 Check_Ada_83_Warning;
14812 Check_Arg_Order
14813 ((Name_Convention,
14814 Name_Entity,
14815 Name_External_Name,
14816 Name_Link_Name));
14817
14818 Check_At_Least_N_Arguments (2);
14819 Check_At_Most_N_Arguments (4);
14820
14821 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14822 -- pragma Export (Entity, "external name");
14823
14824 if Relaxed_RM_Semantics
14825 and then Arg_Count = 2
14826 and then Nkind (Expression (Arg2)) = N_String_Literal
14827 then
14828 C := Convention_C;
14829 Def_Id := Get_Pragma_Arg (Arg1);
14830 Analyze (Def_Id);
14831
14832 if not Is_Entity_Name (Def_Id) then
14833 Error_Pragma_Arg ("entity name required", Arg1);
14834 end if;
14835
14836 Def_Id := Entity (Def_Id);
14837 Set_Exported (Def_Id, Arg1);
14838
14839 else
14840 Process_Convention (C, Def_Id);
14841
14842 -- A pragma that applies to a Ghost entity becomes Ghost for
14843 -- the purposes of legality checks and removal of ignored Ghost
14844 -- code.
14845
14846 Mark_Ghost_Pragma (N, Def_Id);
14847
14848 if Ekind (Def_Id) /= E_Constant then
14849 Note_Possible_Modification
14850 (Get_Pragma_Arg (Arg2), Sure => False);
14851 end if;
14852
14853 Process_Interface_Name (Def_Id, Arg3, Arg4, N);
14854 Set_Exported (Def_Id, Arg2);
14855 end if;
14856
14857 -- If the entity is a deferred constant, propagate the information
14858 -- to the full view, because gigi elaborates the full view only.
14859
14860 if Ekind (Def_Id) = E_Constant
14861 and then Present (Full_View (Def_Id))
14862 then
14863 declare
14864 Id2 : constant Entity_Id := Full_View (Def_Id);
14865 begin
14866 Set_Is_Exported (Id2, Is_Exported (Def_Id));
14867 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
14868 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
14869 end;
14870 end if;
14871 end Export;
14872
14873 ---------------------
14874 -- Export_Function --
14875 ---------------------
14876
14877 -- pragma Export_Function (
14878 -- [Internal =>] LOCAL_NAME
14879 -- [, [External =>] EXTERNAL_SYMBOL]
14880 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14881 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14882 -- [, [Mechanism =>] MECHANISM]
14883 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14884
14885 -- EXTERNAL_SYMBOL ::=
14886 -- IDENTIFIER
14887 -- | static_string_EXPRESSION
14888
14889 -- PARAMETER_TYPES ::=
14890 -- null
14891 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14892
14893 -- TYPE_DESIGNATOR ::=
14894 -- subtype_NAME
14895 -- | subtype_Name ' Access
14896
14897 -- MECHANISM ::=
14898 -- MECHANISM_NAME
14899 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14900
14901 -- MECHANISM_ASSOCIATION ::=
14902 -- [formal_parameter_NAME =>] MECHANISM_NAME
14903
14904 -- MECHANISM_NAME ::=
14905 -- Value
14906 -- | Reference
14907
14908 when Pragma_Export_Function => Export_Function : declare
14909 Args : Args_List (1 .. 6);
14910 Names : constant Name_List (1 .. 6) := (
14911 Name_Internal,
14912 Name_External,
14913 Name_Parameter_Types,
14914 Name_Result_Type,
14915 Name_Mechanism,
14916 Name_Result_Mechanism);
14917
14918 Internal : Node_Id renames Args (1);
14919 External : Node_Id renames Args (2);
14920 Parameter_Types : Node_Id renames Args (3);
14921 Result_Type : Node_Id renames Args (4);
14922 Mechanism : Node_Id renames Args (5);
14923 Result_Mechanism : Node_Id renames Args (6);
14924
14925 begin
14926 GNAT_Pragma;
14927 Gather_Associations (Names, Args);
14928 Process_Extended_Import_Export_Subprogram_Pragma (
14929 Arg_Internal => Internal,
14930 Arg_External => External,
14931 Arg_Parameter_Types => Parameter_Types,
14932 Arg_Result_Type => Result_Type,
14933 Arg_Mechanism => Mechanism,
14934 Arg_Result_Mechanism => Result_Mechanism);
14935 end Export_Function;
14936
14937 -------------------
14938 -- Export_Object --
14939 -------------------
14940
14941 -- pragma Export_Object (
14942 -- [Internal =>] LOCAL_NAME
14943 -- [, [External =>] EXTERNAL_SYMBOL]
14944 -- [, [Size =>] EXTERNAL_SYMBOL]);
14945
14946 -- EXTERNAL_SYMBOL ::=
14947 -- IDENTIFIER
14948 -- | static_string_EXPRESSION
14949
14950 -- PARAMETER_TYPES ::=
14951 -- null
14952 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14953
14954 -- TYPE_DESIGNATOR ::=
14955 -- subtype_NAME
14956 -- | subtype_Name ' Access
14957
14958 -- MECHANISM ::=
14959 -- MECHANISM_NAME
14960 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14961
14962 -- MECHANISM_ASSOCIATION ::=
14963 -- [formal_parameter_NAME =>] MECHANISM_NAME
14964
14965 -- MECHANISM_NAME ::=
14966 -- Value
14967 -- | Reference
14968
14969 when Pragma_Export_Object => Export_Object : declare
14970 Args : Args_List (1 .. 3);
14971 Names : constant Name_List (1 .. 3) := (
14972 Name_Internal,
14973 Name_External,
14974 Name_Size);
14975
14976 Internal : Node_Id renames Args (1);
14977 External : Node_Id renames Args (2);
14978 Size : Node_Id renames Args (3);
14979
14980 begin
14981 GNAT_Pragma;
14982 Gather_Associations (Names, Args);
14983 Process_Extended_Import_Export_Object_Pragma (
14984 Arg_Internal => Internal,
14985 Arg_External => External,
14986 Arg_Size => Size);
14987 end Export_Object;
14988
14989 ----------------------
14990 -- Export_Procedure --
14991 ----------------------
14992
14993 -- pragma Export_Procedure (
14994 -- [Internal =>] LOCAL_NAME
14995 -- [, [External =>] EXTERNAL_SYMBOL]
14996 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14997 -- [, [Mechanism =>] MECHANISM]);
14998
14999 -- EXTERNAL_SYMBOL ::=
15000 -- IDENTIFIER
15001 -- | static_string_EXPRESSION
15002
15003 -- PARAMETER_TYPES ::=
15004 -- null
15005 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15006
15007 -- TYPE_DESIGNATOR ::=
15008 -- subtype_NAME
15009 -- | subtype_Name ' Access
15010
15011 -- MECHANISM ::=
15012 -- MECHANISM_NAME
15013 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15014
15015 -- MECHANISM_ASSOCIATION ::=
15016 -- [formal_parameter_NAME =>] MECHANISM_NAME
15017
15018 -- MECHANISM_NAME ::=
15019 -- Value
15020 -- | Reference
15021
15022 when Pragma_Export_Procedure => Export_Procedure : declare
15023 Args : Args_List (1 .. 4);
15024 Names : constant Name_List (1 .. 4) := (
15025 Name_Internal,
15026 Name_External,
15027 Name_Parameter_Types,
15028 Name_Mechanism);
15029
15030 Internal : Node_Id renames Args (1);
15031 External : Node_Id renames Args (2);
15032 Parameter_Types : Node_Id renames Args (3);
15033 Mechanism : Node_Id renames Args (4);
15034
15035 begin
15036 GNAT_Pragma;
15037 Gather_Associations (Names, Args);
15038 Process_Extended_Import_Export_Subprogram_Pragma (
15039 Arg_Internal => Internal,
15040 Arg_External => External,
15041 Arg_Parameter_Types => Parameter_Types,
15042 Arg_Mechanism => Mechanism);
15043 end Export_Procedure;
15044
15045 ------------------
15046 -- Export_Value --
15047 ------------------
15048
15049 -- pragma Export_Value (
15050 -- [Value =>] static_integer_EXPRESSION,
15051 -- [Link_Name =>] static_string_EXPRESSION);
15052
15053 when Pragma_Export_Value =>
15054 GNAT_Pragma;
15055 Check_Arg_Order ((Name_Value, Name_Link_Name));
15056 Check_Arg_Count (2);
15057
15058 Check_Optional_Identifier (Arg1, Name_Value);
15059 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15060
15061 Check_Optional_Identifier (Arg2, Name_Link_Name);
15062 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
15063
15064 -----------------------------
15065 -- Export_Valued_Procedure --
15066 -----------------------------
15067
15068 -- pragma Export_Valued_Procedure (
15069 -- [Internal =>] LOCAL_NAME
15070 -- [, [External =>] EXTERNAL_SYMBOL,]
15071 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15072 -- [, [Mechanism =>] MECHANISM]);
15073
15074 -- EXTERNAL_SYMBOL ::=
15075 -- IDENTIFIER
15076 -- | static_string_EXPRESSION
15077
15078 -- PARAMETER_TYPES ::=
15079 -- null
15080 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15081
15082 -- TYPE_DESIGNATOR ::=
15083 -- subtype_NAME
15084 -- | subtype_Name ' Access
15085
15086 -- MECHANISM ::=
15087 -- MECHANISM_NAME
15088 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15089
15090 -- MECHANISM_ASSOCIATION ::=
15091 -- [formal_parameter_NAME =>] MECHANISM_NAME
15092
15093 -- MECHANISM_NAME ::=
15094 -- Value
15095 -- | Reference
15096
15097 when Pragma_Export_Valued_Procedure =>
15098 Export_Valued_Procedure : declare
15099 Args : Args_List (1 .. 4);
15100 Names : constant Name_List (1 .. 4) := (
15101 Name_Internal,
15102 Name_External,
15103 Name_Parameter_Types,
15104 Name_Mechanism);
15105
15106 Internal : Node_Id renames Args (1);
15107 External : Node_Id renames Args (2);
15108 Parameter_Types : Node_Id renames Args (3);
15109 Mechanism : Node_Id renames Args (4);
15110
15111 begin
15112 GNAT_Pragma;
15113 Gather_Associations (Names, Args);
15114 Process_Extended_Import_Export_Subprogram_Pragma (
15115 Arg_Internal => Internal,
15116 Arg_External => External,
15117 Arg_Parameter_Types => Parameter_Types,
15118 Arg_Mechanism => Mechanism);
15119 end Export_Valued_Procedure;
15120
15121 -------------------
15122 -- Extend_System --
15123 -------------------
15124
15125 -- pragma Extend_System ([Name =>] Identifier);
15126
15127 when Pragma_Extend_System =>
15128 GNAT_Pragma;
15129 Check_Valid_Configuration_Pragma;
15130 Check_Arg_Count (1);
15131 Check_Optional_Identifier (Arg1, Name_Name);
15132 Check_Arg_Is_Identifier (Arg1);
15133
15134 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15135
15136 if Name_Len > 4
15137 and then Name_Buffer (1 .. 4) = "aux_"
15138 then
15139 if Present (System_Extend_Pragma_Arg) then
15140 if Chars (Get_Pragma_Arg (Arg1)) =
15141 Chars (Expression (System_Extend_Pragma_Arg))
15142 then
15143 null;
15144 else
15145 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
15146 Error_Pragma ("pragma% conflicts with that #");
15147 end if;
15148
15149 else
15150 System_Extend_Pragma_Arg := Arg1;
15151
15152 if not GNAT_Mode then
15153 System_Extend_Unit := Arg1;
15154 end if;
15155 end if;
15156 else
15157 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
15158 end if;
15159
15160 ------------------------
15161 -- Extensions_Allowed --
15162 ------------------------
15163
15164 -- pragma Extensions_Allowed (ON | OFF);
15165
15166 when Pragma_Extensions_Allowed =>
15167 GNAT_Pragma;
15168 Check_Arg_Count (1);
15169 Check_No_Identifiers;
15170 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15171
15172 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
15173 Extensions_Allowed := True;
15174 Ada_Version := Ada_Version_Type'Last;
15175
15176 else
15177 Extensions_Allowed := False;
15178 Ada_Version := Ada_Version_Explicit;
15179 Ada_Version_Pragma := Empty;
15180 end if;
15181
15182 ------------------------
15183 -- Extensions_Visible --
15184 ------------------------
15185
15186 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
15187
15188 -- Characteristics:
15189
15190 -- * Analysis - The annotation is fully analyzed immediately upon
15191 -- elaboration as its expression must be static.
15192
15193 -- * Expansion - None.
15194
15195 -- * Template - The annotation utilizes the generic template of the
15196 -- related subprogram [body] when it is:
15197
15198 -- aspect on subprogram declaration
15199 -- aspect on stand alone subprogram body
15200 -- pragma on stand alone subprogram body
15201
15202 -- The annotation must prepare its own template when it is:
15203
15204 -- pragma on subprogram declaration
15205
15206 -- * Globals - Capture of global references must occur after full
15207 -- analysis.
15208
15209 -- * Instance - The annotation is instantiated automatically when
15210 -- the related generic subprogram [body] is instantiated except for
15211 -- the "pragma on subprogram declaration" case. In that scenario
15212 -- the annotation must instantiate itself.
15213
15214 when Pragma_Extensions_Visible => Extensions_Visible : declare
15215 Formal : Entity_Id;
15216 Has_OK_Formal : Boolean := False;
15217 Spec_Id : Entity_Id;
15218 Subp_Decl : Node_Id;
15219
15220 begin
15221 GNAT_Pragma;
15222 Check_No_Identifiers;
15223 Check_At_Most_N_Arguments (1);
15224
15225 Subp_Decl :=
15226 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
15227
15228 -- Abstract subprogram declaration
15229
15230 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
15231 null;
15232
15233 -- Generic subprogram declaration
15234
15235 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
15236 null;
15237
15238 -- Body acts as spec
15239
15240 elsif Nkind (Subp_Decl) = N_Subprogram_Body
15241 and then No (Corresponding_Spec (Subp_Decl))
15242 then
15243 null;
15244
15245 -- Body stub acts as spec
15246
15247 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
15248 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
15249 then
15250 null;
15251
15252 -- Subprogram declaration
15253
15254 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
15255 null;
15256
15257 -- Otherwise the pragma is associated with an illegal construct
15258
15259 else
15260 Error_Pragma ("pragma % must apply to a subprogram");
15261 return;
15262 end if;
15263
15264 -- Mark the pragma as Ghost if the related subprogram is also
15265 -- Ghost. This also ensures that any expansion performed further
15266 -- below will produce Ghost nodes.
15267
15268 Spec_Id := Unique_Defining_Entity (Subp_Decl);
15269 Mark_Ghost_Pragma (N, Spec_Id);
15270
15271 -- Chain the pragma on the contract for completeness
15272
15273 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
15274
15275 -- The legality checks of pragma Extension_Visible are affected
15276 -- by the SPARK mode in effect. Analyze all pragmas in specific
15277 -- order.
15278
15279 Analyze_If_Present (Pragma_SPARK_Mode);
15280
15281 -- Examine the formals of the related subprogram
15282
15283 Formal := First_Formal (Spec_Id);
15284 while Present (Formal) loop
15285
15286 -- At least one of the formals is of a specific tagged type,
15287 -- the pragma is legal.
15288
15289 if Is_Specific_Tagged_Type (Etype (Formal)) then
15290 Has_OK_Formal := True;
15291 exit;
15292
15293 -- A generic subprogram with at least one formal of a private
15294 -- type ensures the legality of the pragma because the actual
15295 -- may be specifically tagged. Note that this is verified by
15296 -- the check above at instantiation time.
15297
15298 elsif Is_Private_Type (Etype (Formal))
15299 and then Is_Generic_Type (Etype (Formal))
15300 then
15301 Has_OK_Formal := True;
15302 exit;
15303 end if;
15304
15305 Next_Formal (Formal);
15306 end loop;
15307
15308 if not Has_OK_Formal then
15309 Error_Msg_Name_1 := Pname;
15310 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
15311 Error_Msg_NE
15312 ("\subprogram & lacks parameter of specific tagged or "
15313 & "generic private type", N, Spec_Id);
15314
15315 return;
15316 end if;
15317
15318 -- Analyze the Boolean expression (if any)
15319
15320 if Present (Arg1) then
15321 Check_Static_Boolean_Expression
15322 (Expression (Get_Argument (N, Spec_Id)));
15323 end if;
15324 end Extensions_Visible;
15325
15326 --------------
15327 -- External --
15328 --------------
15329
15330 -- pragma External (
15331 -- [ Convention =>] convention_IDENTIFIER,
15332 -- [ Entity =>] LOCAL_NAME
15333 -- [, [External_Name =>] static_string_EXPRESSION ]
15334 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15335
15336 when Pragma_External => External : declare
15337 C : Convention_Id;
15338 E : Entity_Id;
15339 pragma Warnings (Off, C);
15340
15341 begin
15342 GNAT_Pragma;
15343 Check_Arg_Order
15344 ((Name_Convention,
15345 Name_Entity,
15346 Name_External_Name,
15347 Name_Link_Name));
15348 Check_At_Least_N_Arguments (2);
15349 Check_At_Most_N_Arguments (4);
15350 Process_Convention (C, E);
15351
15352 -- A pragma that applies to a Ghost entity becomes Ghost for the
15353 -- purposes of legality checks and removal of ignored Ghost code.
15354
15355 Mark_Ghost_Pragma (N, E);
15356
15357 Note_Possible_Modification
15358 (Get_Pragma_Arg (Arg2), Sure => False);
15359 Process_Interface_Name (E, Arg3, Arg4, N);
15360 Set_Exported (E, Arg2);
15361 end External;
15362
15363 --------------------------
15364 -- External_Name_Casing --
15365 --------------------------
15366
15367 -- pragma External_Name_Casing (
15368 -- UPPERCASE | LOWERCASE
15369 -- [, AS_IS | UPPERCASE | LOWERCASE]);
15370
15371 when Pragma_External_Name_Casing =>
15372 GNAT_Pragma;
15373 Check_No_Identifiers;
15374
15375 if Arg_Count = 2 then
15376 Check_Arg_Is_One_Of
15377 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
15378
15379 case Chars (Get_Pragma_Arg (Arg2)) is
15380 when Name_As_Is =>
15381 Opt.External_Name_Exp_Casing := As_Is;
15382
15383 when Name_Uppercase =>
15384 Opt.External_Name_Exp_Casing := Uppercase;
15385
15386 when Name_Lowercase =>
15387 Opt.External_Name_Exp_Casing := Lowercase;
15388
15389 when others =>
15390 null;
15391 end case;
15392
15393 else
15394 Check_Arg_Count (1);
15395 end if;
15396
15397 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
15398
15399 case Chars (Get_Pragma_Arg (Arg1)) is
15400 when Name_Uppercase =>
15401 Opt.External_Name_Imp_Casing := Uppercase;
15402
15403 when Name_Lowercase =>
15404 Opt.External_Name_Imp_Casing := Lowercase;
15405
15406 when others =>
15407 null;
15408 end case;
15409
15410 ---------------
15411 -- Fast_Math --
15412 ---------------
15413
15414 -- pragma Fast_Math;
15415
15416 when Pragma_Fast_Math =>
15417 GNAT_Pragma;
15418 Check_No_Identifiers;
15419 Check_Valid_Configuration_Pragma;
15420 Fast_Math := True;
15421
15422 --------------------------
15423 -- Favor_Top_Level --
15424 --------------------------
15425
15426 -- pragma Favor_Top_Level (type_NAME);
15427
15428 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
15429 Typ : Entity_Id;
15430
15431 begin
15432 GNAT_Pragma;
15433 Check_No_Identifiers;
15434 Check_Arg_Count (1);
15435 Check_Arg_Is_Local_Name (Arg1);
15436 Typ := Entity (Get_Pragma_Arg (Arg1));
15437
15438 -- A pragma that applies to a Ghost entity becomes Ghost for the
15439 -- purposes of legality checks and removal of ignored Ghost code.
15440
15441 Mark_Ghost_Pragma (N, Typ);
15442
15443 -- If it's an access-to-subprogram type (in particular, not a
15444 -- subtype), set the flag on that type.
15445
15446 if Is_Access_Subprogram_Type (Typ) then
15447 Set_Can_Use_Internal_Rep (Typ, False);
15448
15449 -- Otherwise it's an error (name denotes the wrong sort of entity)
15450
15451 else
15452 Error_Pragma_Arg
15453 ("access-to-subprogram type expected",
15454 Get_Pragma_Arg (Arg1));
15455 end if;
15456 end Favor_Top_Level;
15457
15458 ---------------------------
15459 -- Finalize_Storage_Only --
15460 ---------------------------
15461
15462 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
15463
15464 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
15465 Assoc : constant Node_Id := Arg1;
15466 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
15467 Typ : Entity_Id;
15468
15469 begin
15470 GNAT_Pragma;
15471 Check_No_Identifiers;
15472 Check_Arg_Count (1);
15473 Check_Arg_Is_Local_Name (Arg1);
15474
15475 Find_Type (Type_Id);
15476 Typ := Entity (Type_Id);
15477
15478 if Typ = Any_Type
15479 or else Rep_Item_Too_Early (Typ, N)
15480 then
15481 return;
15482 else
15483 Typ := Underlying_Type (Typ);
15484 end if;
15485
15486 if not Is_Controlled (Typ) then
15487 Error_Pragma ("pragma% must specify controlled type");
15488 end if;
15489
15490 Check_First_Subtype (Arg1);
15491
15492 if Finalize_Storage_Only (Typ) then
15493 Error_Pragma ("duplicate pragma%, only one allowed");
15494
15495 elsif not Rep_Item_Too_Late (Typ, N) then
15496 Set_Finalize_Storage_Only (Base_Type (Typ), True);
15497 end if;
15498 end Finalize_Storage;
15499
15500 -----------
15501 -- Ghost --
15502 -----------
15503
15504 -- pragma Ghost [ (boolean_EXPRESSION) ];
15505
15506 when Pragma_Ghost => Ghost : declare
15507 Context : Node_Id;
15508 Expr : Node_Id;
15509 Id : Entity_Id;
15510 Orig_Stmt : Node_Id;
15511 Prev_Id : Entity_Id;
15512 Stmt : Node_Id;
15513
15514 begin
15515 GNAT_Pragma;
15516 Check_No_Identifiers;
15517 Check_At_Most_N_Arguments (1);
15518
15519 Id := Empty;
15520 Stmt := Prev (N);
15521 while Present (Stmt) loop
15522
15523 -- Skip prior pragmas, but check for duplicates
15524
15525 if Nkind (Stmt) = N_Pragma then
15526 if Pragma_Name (Stmt) = Pname then
15527 Duplication_Error
15528 (Prag => N,
15529 Prev => Stmt);
15530 raise Pragma_Exit;
15531 end if;
15532
15533 -- Task unit declared without a definition cannot be subject to
15534 -- pragma Ghost (SPARK RM 6.9(19)).
15535
15536 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
15537 N_Task_Type_Declaration)
15538 then
15539 Error_Pragma ("pragma % cannot apply to a task type");
15540 return;
15541
15542 -- Skip internally generated code
15543
15544 elsif not Comes_From_Source (Stmt) then
15545 Orig_Stmt := Original_Node (Stmt);
15546
15547 -- When pragma Ghost applies to an untagged derivation, the
15548 -- derivation is transformed into a [sub]type declaration.
15549
15550 if Nkind_In (Stmt, N_Full_Type_Declaration,
15551 N_Subtype_Declaration)
15552 and then Comes_From_Source (Orig_Stmt)
15553 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
15554 and then Nkind (Type_Definition (Orig_Stmt)) =
15555 N_Derived_Type_Definition
15556 then
15557 Id := Defining_Entity (Stmt);
15558 exit;
15559
15560 -- When pragma Ghost applies to an object declaration which
15561 -- is initialized by means of a function call that returns
15562 -- on the secondary stack, the object declaration becomes a
15563 -- renaming.
15564
15565 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
15566 and then Comes_From_Source (Orig_Stmt)
15567 and then Nkind (Orig_Stmt) = N_Object_Declaration
15568 then
15569 Id := Defining_Entity (Stmt);
15570 exit;
15571
15572 -- When pragma Ghost applies to an expression function, the
15573 -- expression function is transformed into a subprogram.
15574
15575 elsif Nkind (Stmt) = N_Subprogram_Declaration
15576 and then Comes_From_Source (Orig_Stmt)
15577 and then Nkind (Orig_Stmt) = N_Expression_Function
15578 then
15579 Id := Defining_Entity (Stmt);
15580 exit;
15581 end if;
15582
15583 -- The pragma applies to a legal construct, stop the traversal
15584
15585 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
15586 N_Full_Type_Declaration,
15587 N_Generic_Subprogram_Declaration,
15588 N_Object_Declaration,
15589 N_Private_Extension_Declaration,
15590 N_Private_Type_Declaration,
15591 N_Subprogram_Declaration,
15592 N_Subtype_Declaration)
15593 then
15594 Id := Defining_Entity (Stmt);
15595 exit;
15596
15597 -- The pragma does not apply to a legal construct, issue an
15598 -- error and stop the analysis.
15599
15600 else
15601 Error_Pragma
15602 ("pragma % must apply to an object, package, subprogram "
15603 & "or type");
15604 return;
15605 end if;
15606
15607 Stmt := Prev (Stmt);
15608 end loop;
15609
15610 Context := Parent (N);
15611
15612 -- Handle compilation units
15613
15614 if Nkind (Context) = N_Compilation_Unit_Aux then
15615 Context := Unit (Parent (Context));
15616 end if;
15617
15618 -- Protected and task types cannot be subject to pragma Ghost
15619 -- (SPARK RM 6.9(19)).
15620
15621 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
15622 then
15623 Error_Pragma ("pragma % cannot apply to a protected type");
15624 return;
15625
15626 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
15627 Error_Pragma ("pragma % cannot apply to a task type");
15628 return;
15629 end if;
15630
15631 if No (Id) then
15632
15633 -- When pragma Ghost is associated with a [generic] package, it
15634 -- appears in the visible declarations.
15635
15636 if Nkind (Context) = N_Package_Specification
15637 and then Present (Visible_Declarations (Context))
15638 and then List_Containing (N) = Visible_Declarations (Context)
15639 then
15640 Id := Defining_Entity (Context);
15641
15642 -- Pragma Ghost applies to a stand alone subprogram body
15643
15644 elsif Nkind (Context) = N_Subprogram_Body
15645 and then No (Corresponding_Spec (Context))
15646 then
15647 Id := Defining_Entity (Context);
15648
15649 -- Pragma Ghost applies to a subprogram declaration that acts
15650 -- as a compilation unit.
15651
15652 elsif Nkind (Context) = N_Subprogram_Declaration then
15653 Id := Defining_Entity (Context);
15654 end if;
15655 end if;
15656
15657 if No (Id) then
15658 Error_Pragma
15659 ("pragma % must apply to an object, package, subprogram or "
15660 & "type");
15661 return;
15662 end if;
15663
15664 -- Handle completions of types and constants that are subject to
15665 -- pragma Ghost.
15666
15667 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
15668 Prev_Id := Incomplete_Or_Partial_View (Id);
15669
15670 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
15671 Error_Msg_Name_1 := Pname;
15672
15673 -- The full declaration of a deferred constant cannot be
15674 -- subject to pragma Ghost unless the deferred declaration
15675 -- is also Ghost (SPARK RM 6.9(9)).
15676
15677 if Ekind (Prev_Id) = E_Constant then
15678 Error_Msg_Name_1 := Pname;
15679 Error_Msg_NE (Fix_Error
15680 ("pragma % must apply to declaration of deferred "
15681 & "constant &"), N, Id);
15682 return;
15683
15684 -- Pragma Ghost may appear on the full view of an incomplete
15685 -- type because the incomplete declaration lacks aspects and
15686 -- cannot be subject to pragma Ghost.
15687
15688 elsif Ekind (Prev_Id) = E_Incomplete_Type then
15689 null;
15690
15691 -- The full declaration of a type cannot be subject to
15692 -- pragma Ghost unless the partial view is also Ghost
15693 -- (SPARK RM 6.9(9)).
15694
15695 else
15696 Error_Msg_NE (Fix_Error
15697 ("pragma % must apply to partial view of type &"),
15698 N, Id);
15699 return;
15700 end if;
15701 end if;
15702
15703 -- A synchronized object cannot be subject to pragma Ghost
15704 -- (SPARK RM 6.9(19)).
15705
15706 elsif Ekind (Id) = E_Variable then
15707 if Is_Protected_Type (Etype (Id)) then
15708 Error_Pragma ("pragma % cannot apply to a protected object");
15709 return;
15710
15711 elsif Is_Task_Type (Etype (Id)) then
15712 Error_Pragma ("pragma % cannot apply to a task object");
15713 return;
15714 end if;
15715 end if;
15716
15717 -- Analyze the Boolean expression (if any)
15718
15719 if Present (Arg1) then
15720 Expr := Get_Pragma_Arg (Arg1);
15721
15722 Analyze_And_Resolve (Expr, Standard_Boolean);
15723
15724 if Is_OK_Static_Expression (Expr) then
15725
15726 -- "Ghostness" cannot be turned off once enabled within a
15727 -- region (SPARK RM 6.9(6)).
15728
15729 if Is_False (Expr_Value (Expr))
15730 and then Ghost_Mode > None
15731 then
15732 Error_Pragma
15733 ("pragma % with value False cannot appear in enabled "
15734 & "ghost region");
15735 return;
15736 end if;
15737
15738 -- Otherwie the expression is not static
15739
15740 else
15741 Error_Pragma_Arg
15742 ("expression of pragma % must be static", Expr);
15743 return;
15744 end if;
15745 end if;
15746
15747 Set_Is_Ghost_Entity (Id);
15748 end Ghost;
15749
15750 ------------
15751 -- Global --
15752 ------------
15753
15754 -- pragma Global (GLOBAL_SPECIFICATION);
15755
15756 -- GLOBAL_SPECIFICATION ::=
15757 -- null
15758 -- | (GLOBAL_LIST)
15759 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15760
15761 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15762
15763 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15764 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15765 -- GLOBAL_ITEM ::= NAME
15766
15767 -- Characteristics:
15768
15769 -- * Analysis - The annotation undergoes initial checks to verify
15770 -- the legal placement and context. Secondary checks fully analyze
15771 -- the dependency clauses in:
15772
15773 -- Analyze_Global_In_Decl_Part
15774
15775 -- * Expansion - None.
15776
15777 -- * Template - The annotation utilizes the generic template of the
15778 -- related subprogram [body] when it is:
15779
15780 -- aspect on subprogram declaration
15781 -- aspect on stand alone subprogram body
15782 -- pragma on stand alone subprogram body
15783
15784 -- The annotation must prepare its own template when it is:
15785
15786 -- pragma on subprogram declaration
15787
15788 -- * Globals - Capture of global references must occur after full
15789 -- analysis.
15790
15791 -- * Instance - The annotation is instantiated automatically when
15792 -- the related generic subprogram [body] is instantiated except for
15793 -- the "pragma on subprogram declaration" case. In that scenario
15794 -- the annotation must instantiate itself.
15795
15796 when Pragma_Global => Global : declare
15797 Legal : Boolean;
15798 Spec_Id : Entity_Id;
15799 Subp_Decl : Node_Id;
15800
15801 begin
15802 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15803
15804 if Legal then
15805
15806 -- Chain the pragma on the contract for further processing by
15807 -- Analyze_Global_In_Decl_Part.
15808
15809 Add_Contract_Item (N, Spec_Id);
15810
15811 -- Fully analyze the pragma when it appears inside an entry
15812 -- or subprogram body because it cannot benefit from forward
15813 -- references.
15814
15815 if Nkind_In (Subp_Decl, N_Entry_Body,
15816 N_Subprogram_Body,
15817 N_Subprogram_Body_Stub)
15818 then
15819 -- The legality checks of pragmas Depends and Global are
15820 -- affected by the SPARK mode in effect and the volatility
15821 -- of the context. In addition these two pragmas are subject
15822 -- to an inherent order:
15823
15824 -- 1) Global
15825 -- 2) Depends
15826
15827 -- Analyze all these pragmas in the order outlined above
15828
15829 Analyze_If_Present (Pragma_SPARK_Mode);
15830 Analyze_If_Present (Pragma_Volatile_Function);
15831 Analyze_Global_In_Decl_Part (N);
15832 Analyze_If_Present (Pragma_Depends);
15833 end if;
15834 end if;
15835 end Global;
15836
15837 -----------
15838 -- Ident --
15839 -----------
15840
15841 -- pragma Ident (static_string_EXPRESSION)
15842
15843 -- Note: pragma Comment shares this processing. Pragma Ident is
15844 -- identical in effect to pragma Commment.
15845
15846 when Pragma_Comment
15847 | Pragma_Ident
15848 =>
15849 Ident : declare
15850 Str : Node_Id;
15851
15852 begin
15853 GNAT_Pragma;
15854 Check_Arg_Count (1);
15855 Check_No_Identifiers;
15856 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15857 Store_Note (N);
15858
15859 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
15860
15861 declare
15862 CS : Node_Id;
15863 GP : Node_Id;
15864
15865 begin
15866 GP := Parent (Parent (N));
15867
15868 if Nkind_In (GP, N_Package_Declaration,
15869 N_Generic_Package_Declaration)
15870 then
15871 GP := Parent (GP);
15872 end if;
15873
15874 -- If we have a compilation unit, then record the ident value,
15875 -- checking for improper duplication.
15876
15877 if Nkind (GP) = N_Compilation_Unit then
15878 CS := Ident_String (Current_Sem_Unit);
15879
15880 if Present (CS) then
15881
15882 -- If we have multiple instances, concatenate them, but
15883 -- not in ASIS, where we want the original tree.
15884
15885 if not ASIS_Mode then
15886 Start_String (Strval (CS));
15887 Store_String_Char (' ');
15888 Store_String_Chars (Strval (Str));
15889 Set_Strval (CS, End_String);
15890 end if;
15891
15892 else
15893 Set_Ident_String (Current_Sem_Unit, Str);
15894 end if;
15895
15896 -- For subunits, we just ignore the Ident, since in GNAT these
15897 -- are not separate object files, and hence not separate units
15898 -- in the unit table.
15899
15900 elsif Nkind (GP) = N_Subunit then
15901 null;
15902 end if;
15903 end;
15904 end Ident;
15905
15906 -------------------
15907 -- Ignore_Pragma --
15908 -------------------
15909
15910 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15911
15912 -- Entirely handled in the parser, nothing to do here
15913
15914 when Pragma_Ignore_Pragma =>
15915 null;
15916
15917 ----------------------------
15918 -- Implementation_Defined --
15919 ----------------------------
15920
15921 -- pragma Implementation_Defined (LOCAL_NAME);
15922
15923 -- Marks previously declared entity as implementation defined. For
15924 -- an overloaded entity, applies to the most recent homonym.
15925
15926 -- pragma Implementation_Defined;
15927
15928 -- The form with no arguments appears anywhere within a scope, most
15929 -- typically a package spec, and indicates that all entities that are
15930 -- defined within the package spec are Implementation_Defined.
15931
15932 when Pragma_Implementation_Defined => Implementation_Defined : declare
15933 Ent : Entity_Id;
15934
15935 begin
15936 GNAT_Pragma;
15937 Check_No_Identifiers;
15938
15939 -- Form with no arguments
15940
15941 if Arg_Count = 0 then
15942 Set_Is_Implementation_Defined (Current_Scope);
15943
15944 -- Form with one argument
15945
15946 else
15947 Check_Arg_Count (1);
15948 Check_Arg_Is_Local_Name (Arg1);
15949 Ent := Entity (Get_Pragma_Arg (Arg1));
15950 Set_Is_Implementation_Defined (Ent);
15951 end if;
15952 end Implementation_Defined;
15953
15954 -----------------
15955 -- Implemented --
15956 -----------------
15957
15958 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15959
15960 -- IMPLEMENTATION_KIND ::=
15961 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15962
15963 -- "By_Any" and "Optional" are treated as synonyms in order to
15964 -- support Ada 2012 aspect Synchronization.
15965
15966 when Pragma_Implemented => Implemented : declare
15967 Proc_Id : Entity_Id;
15968 Typ : Entity_Id;
15969
15970 begin
15971 Ada_2012_Pragma;
15972 Check_Arg_Count (2);
15973 Check_No_Identifiers;
15974 Check_Arg_Is_Identifier (Arg1);
15975 Check_Arg_Is_Local_Name (Arg1);
15976 Check_Arg_Is_One_Of (Arg2,
15977 Name_By_Any,
15978 Name_By_Entry,
15979 Name_By_Protected_Procedure,
15980 Name_Optional);
15981
15982 -- Extract the name of the local procedure
15983
15984 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
15985
15986 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
15987 -- primitive procedure of a synchronized tagged type.
15988
15989 if Ekind (Proc_Id) = E_Procedure
15990 and then Is_Primitive (Proc_Id)
15991 and then Present (First_Formal (Proc_Id))
15992 then
15993 Typ := Etype (First_Formal (Proc_Id));
15994
15995 if Is_Tagged_Type (Typ)
15996 and then
15997
15998 -- Check for a protected, a synchronized or a task interface
15999
16000 ((Is_Interface (Typ)
16001 and then Is_Synchronized_Interface (Typ))
16002
16003 -- Check for a protected type or a task type that implements
16004 -- an interface.
16005
16006 or else
16007 (Is_Concurrent_Record_Type (Typ)
16008 and then Present (Interfaces (Typ)))
16009
16010 -- In analysis-only mode, examine original protected type
16011
16012 or else
16013 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
16014 and then Present (Interface_List (Parent (Typ))))
16015
16016 -- Check for a private record extension with keyword
16017 -- "synchronized".
16018
16019 or else
16020 (Ekind_In (Typ, E_Record_Type_With_Private,
16021 E_Record_Subtype_With_Private)
16022 and then Synchronized_Present (Parent (Typ))))
16023 then
16024 null;
16025 else
16026 Error_Pragma_Arg
16027 ("controlling formal must be of synchronized tagged type",
16028 Arg1);
16029 return;
16030 end if;
16031
16032 -- Procedures declared inside a protected type must be accepted
16033
16034 elsif Ekind (Proc_Id) = E_Procedure
16035 and then Is_Protected_Type (Scope (Proc_Id))
16036 then
16037 null;
16038
16039 -- The first argument is not a primitive procedure
16040
16041 else
16042 Error_Pragma_Arg
16043 ("pragma % must be applied to a primitive procedure", Arg1);
16044 return;
16045 end if;
16046
16047 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
16048 -- By_Protected_Procedure to the primitive procedure of a task
16049 -- interface.
16050
16051 if Chars (Arg2) = Name_By_Protected_Procedure
16052 and then Is_Interface (Typ)
16053 and then Is_Task_Interface (Typ)
16054 then
16055 Error_Pragma_Arg
16056 ("implementation kind By_Protected_Procedure cannot be "
16057 & "applied to a task interface primitive", Arg2);
16058 return;
16059 end if;
16060
16061 Record_Rep_Item (Proc_Id, N);
16062 end Implemented;
16063
16064 ----------------------
16065 -- Implicit_Packing --
16066 ----------------------
16067
16068 -- pragma Implicit_Packing;
16069
16070 when Pragma_Implicit_Packing =>
16071 GNAT_Pragma;
16072 Check_Arg_Count (0);
16073 Implicit_Packing := True;
16074
16075 ------------
16076 -- Import --
16077 ------------
16078
16079 -- pragma Import (
16080 -- [Convention =>] convention_IDENTIFIER,
16081 -- [Entity =>] LOCAL_NAME
16082 -- [, [External_Name =>] static_string_EXPRESSION ]
16083 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16084
16085 when Pragma_Import =>
16086 Check_Ada_83_Warning;
16087 Check_Arg_Order
16088 ((Name_Convention,
16089 Name_Entity,
16090 Name_External_Name,
16091 Name_Link_Name));
16092
16093 Check_At_Least_N_Arguments (2);
16094 Check_At_Most_N_Arguments (4);
16095 Process_Import_Or_Interface;
16096
16097 ---------------------
16098 -- Import_Function --
16099 ---------------------
16100
16101 -- pragma Import_Function (
16102 -- [Internal =>] LOCAL_NAME,
16103 -- [, [External =>] EXTERNAL_SYMBOL]
16104 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16105 -- [, [Result_Type =>] SUBTYPE_MARK]
16106 -- [, [Mechanism =>] MECHANISM]
16107 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16108
16109 -- EXTERNAL_SYMBOL ::=
16110 -- IDENTIFIER
16111 -- | static_string_EXPRESSION
16112
16113 -- PARAMETER_TYPES ::=
16114 -- null
16115 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16116
16117 -- TYPE_DESIGNATOR ::=
16118 -- subtype_NAME
16119 -- | subtype_Name ' Access
16120
16121 -- MECHANISM ::=
16122 -- MECHANISM_NAME
16123 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16124
16125 -- MECHANISM_ASSOCIATION ::=
16126 -- [formal_parameter_NAME =>] MECHANISM_NAME
16127
16128 -- MECHANISM_NAME ::=
16129 -- Value
16130 -- | Reference
16131
16132 when Pragma_Import_Function => Import_Function : declare
16133 Args : Args_List (1 .. 6);
16134 Names : constant Name_List (1 .. 6) := (
16135 Name_Internal,
16136 Name_External,
16137 Name_Parameter_Types,
16138 Name_Result_Type,
16139 Name_Mechanism,
16140 Name_Result_Mechanism);
16141
16142 Internal : Node_Id renames Args (1);
16143 External : Node_Id renames Args (2);
16144 Parameter_Types : Node_Id renames Args (3);
16145 Result_Type : Node_Id renames Args (4);
16146 Mechanism : Node_Id renames Args (5);
16147 Result_Mechanism : Node_Id renames Args (6);
16148
16149 begin
16150 GNAT_Pragma;
16151 Gather_Associations (Names, Args);
16152 Process_Extended_Import_Export_Subprogram_Pragma (
16153 Arg_Internal => Internal,
16154 Arg_External => External,
16155 Arg_Parameter_Types => Parameter_Types,
16156 Arg_Result_Type => Result_Type,
16157 Arg_Mechanism => Mechanism,
16158 Arg_Result_Mechanism => Result_Mechanism);
16159 end Import_Function;
16160
16161 -------------------
16162 -- Import_Object --
16163 -------------------
16164
16165 -- pragma Import_Object (
16166 -- [Internal =>] LOCAL_NAME
16167 -- [, [External =>] EXTERNAL_SYMBOL]
16168 -- [, [Size =>] EXTERNAL_SYMBOL]);
16169
16170 -- EXTERNAL_SYMBOL ::=
16171 -- IDENTIFIER
16172 -- | static_string_EXPRESSION
16173
16174 when Pragma_Import_Object => Import_Object : declare
16175 Args : Args_List (1 .. 3);
16176 Names : constant Name_List (1 .. 3) := (
16177 Name_Internal,
16178 Name_External,
16179 Name_Size);
16180
16181 Internal : Node_Id renames Args (1);
16182 External : Node_Id renames Args (2);
16183 Size : Node_Id renames Args (3);
16184
16185 begin
16186 GNAT_Pragma;
16187 Gather_Associations (Names, Args);
16188 Process_Extended_Import_Export_Object_Pragma (
16189 Arg_Internal => Internal,
16190 Arg_External => External,
16191 Arg_Size => Size);
16192 end Import_Object;
16193
16194 ----------------------
16195 -- Import_Procedure --
16196 ----------------------
16197
16198 -- pragma Import_Procedure (
16199 -- [Internal =>] LOCAL_NAME
16200 -- [, [External =>] EXTERNAL_SYMBOL]
16201 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16202 -- [, [Mechanism =>] MECHANISM]);
16203
16204 -- EXTERNAL_SYMBOL ::=
16205 -- IDENTIFIER
16206 -- | static_string_EXPRESSION
16207
16208 -- PARAMETER_TYPES ::=
16209 -- null
16210 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16211
16212 -- TYPE_DESIGNATOR ::=
16213 -- subtype_NAME
16214 -- | subtype_Name ' Access
16215
16216 -- MECHANISM ::=
16217 -- MECHANISM_NAME
16218 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16219
16220 -- MECHANISM_ASSOCIATION ::=
16221 -- [formal_parameter_NAME =>] MECHANISM_NAME
16222
16223 -- MECHANISM_NAME ::=
16224 -- Value
16225 -- | Reference
16226
16227 when Pragma_Import_Procedure => Import_Procedure : declare
16228 Args : Args_List (1 .. 4);
16229 Names : constant Name_List (1 .. 4) := (
16230 Name_Internal,
16231 Name_External,
16232 Name_Parameter_Types,
16233 Name_Mechanism);
16234
16235 Internal : Node_Id renames Args (1);
16236 External : Node_Id renames Args (2);
16237 Parameter_Types : Node_Id renames Args (3);
16238 Mechanism : Node_Id renames Args (4);
16239
16240 begin
16241 GNAT_Pragma;
16242 Gather_Associations (Names, Args);
16243 Process_Extended_Import_Export_Subprogram_Pragma (
16244 Arg_Internal => Internal,
16245 Arg_External => External,
16246 Arg_Parameter_Types => Parameter_Types,
16247 Arg_Mechanism => Mechanism);
16248 end Import_Procedure;
16249
16250 -----------------------------
16251 -- Import_Valued_Procedure --
16252 -----------------------------
16253
16254 -- pragma Import_Valued_Procedure (
16255 -- [Internal =>] LOCAL_NAME
16256 -- [, [External =>] EXTERNAL_SYMBOL]
16257 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16258 -- [, [Mechanism =>] MECHANISM]);
16259
16260 -- EXTERNAL_SYMBOL ::=
16261 -- IDENTIFIER
16262 -- | static_string_EXPRESSION
16263
16264 -- PARAMETER_TYPES ::=
16265 -- null
16266 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16267
16268 -- TYPE_DESIGNATOR ::=
16269 -- subtype_NAME
16270 -- | subtype_Name ' Access
16271
16272 -- MECHANISM ::=
16273 -- MECHANISM_NAME
16274 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16275
16276 -- MECHANISM_ASSOCIATION ::=
16277 -- [formal_parameter_NAME =>] MECHANISM_NAME
16278
16279 -- MECHANISM_NAME ::=
16280 -- Value
16281 -- | Reference
16282
16283 when Pragma_Import_Valued_Procedure =>
16284 Import_Valued_Procedure : declare
16285 Args : Args_List (1 .. 4);
16286 Names : constant Name_List (1 .. 4) := (
16287 Name_Internal,
16288 Name_External,
16289 Name_Parameter_Types,
16290 Name_Mechanism);
16291
16292 Internal : Node_Id renames Args (1);
16293 External : Node_Id renames Args (2);
16294 Parameter_Types : Node_Id renames Args (3);
16295 Mechanism : Node_Id renames Args (4);
16296
16297 begin
16298 GNAT_Pragma;
16299 Gather_Associations (Names, Args);
16300 Process_Extended_Import_Export_Subprogram_Pragma (
16301 Arg_Internal => Internal,
16302 Arg_External => External,
16303 Arg_Parameter_Types => Parameter_Types,
16304 Arg_Mechanism => Mechanism);
16305 end Import_Valued_Procedure;
16306
16307 -----------------
16308 -- Independent --
16309 -----------------
16310
16311 -- pragma Independent (LOCAL_NAME);
16312
16313 when Pragma_Independent =>
16314 Process_Atomic_Independent_Shared_Volatile;
16315
16316 ----------------------------
16317 -- Independent_Components --
16318 ----------------------------
16319
16320 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
16321
16322 when Pragma_Independent_Components => Independent_Components : declare
16323 C : Node_Id;
16324 D : Node_Id;
16325 E_Id : Node_Id;
16326 E : Entity_Id;
16327 K : Node_Kind;
16328
16329 begin
16330 Check_Ada_83_Warning;
16331 Ada_2012_Pragma;
16332 Check_No_Identifiers;
16333 Check_Arg_Count (1);
16334 Check_Arg_Is_Local_Name (Arg1);
16335 E_Id := Get_Pragma_Arg (Arg1);
16336
16337 if Etype (E_Id) = Any_Type then
16338 return;
16339 end if;
16340
16341 E := Entity (E_Id);
16342
16343 -- A pragma that applies to a Ghost entity becomes Ghost for the
16344 -- purposes of legality checks and removal of ignored Ghost code.
16345
16346 Mark_Ghost_Pragma (N, E);
16347
16348 -- Check duplicate before we chain ourselves
16349
16350 Check_Duplicate_Pragma (E);
16351
16352 -- Check appropriate entity
16353
16354 if Rep_Item_Too_Early (E, N)
16355 or else
16356 Rep_Item_Too_Late (E, N)
16357 then
16358 return;
16359 end if;
16360
16361 D := Declaration_Node (E);
16362 K := Nkind (D);
16363
16364 -- The flag is set on the base type, or on the object
16365
16366 if K = N_Full_Type_Declaration
16367 and then (Is_Array_Type (E) or else Is_Record_Type (E))
16368 then
16369 Set_Has_Independent_Components (Base_Type (E));
16370 Record_Independence_Check (N, Base_Type (E));
16371
16372 -- For record type, set all components independent
16373
16374 if Is_Record_Type (E) then
16375 C := First_Component (E);
16376 while Present (C) loop
16377 Set_Is_Independent (C);
16378 Next_Component (C);
16379 end loop;
16380 end if;
16381
16382 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
16383 and then Nkind (D) = N_Object_Declaration
16384 and then Nkind (Object_Definition (D)) =
16385 N_Constrained_Array_Definition
16386 then
16387 Set_Has_Independent_Components (E);
16388 Record_Independence_Check (N, E);
16389
16390 else
16391 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
16392 end if;
16393 end Independent_Components;
16394
16395 -----------------------
16396 -- Initial_Condition --
16397 -----------------------
16398
16399 -- pragma Initial_Condition (boolean_EXPRESSION);
16400
16401 -- Characteristics:
16402
16403 -- * Analysis - The annotation undergoes initial checks to verify
16404 -- the legal placement and context. Secondary checks preanalyze the
16405 -- expression in:
16406
16407 -- Analyze_Initial_Condition_In_Decl_Part
16408
16409 -- * Expansion - The annotation is expanded during the expansion of
16410 -- the package body whose declaration is subject to the annotation
16411 -- as done in:
16412
16413 -- Expand_Pragma_Initial_Condition
16414
16415 -- * Template - The annotation utilizes the generic template of the
16416 -- related package declaration.
16417
16418 -- * Globals - Capture of global references must occur after full
16419 -- analysis.
16420
16421 -- * Instance - The annotation is instantiated automatically when
16422 -- the related generic package is instantiated.
16423
16424 when Pragma_Initial_Condition => Initial_Condition : declare
16425 Pack_Decl : Node_Id;
16426 Pack_Id : Entity_Id;
16427
16428 begin
16429 GNAT_Pragma;
16430 Check_No_Identifiers;
16431 Check_Arg_Count (1);
16432
16433 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
16434
16435 -- Ensure the proper placement of the pragma. Initial_Condition
16436 -- must be associated with a package declaration.
16437
16438 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
16439 N_Package_Declaration)
16440 then
16441 null;
16442
16443 -- Otherwise the pragma is associated with an illegal context
16444
16445 else
16446 Pragma_Misplaced;
16447 return;
16448 end if;
16449
16450 Pack_Id := Defining_Entity (Pack_Decl);
16451
16452 -- A pragma that applies to a Ghost entity becomes Ghost for the
16453 -- purposes of legality checks and removal of ignored Ghost code.
16454
16455 Mark_Ghost_Pragma (N, Pack_Id);
16456
16457 -- Chain the pragma on the contract for further processing by
16458 -- Analyze_Initial_Condition_In_Decl_Part.
16459
16460 Add_Contract_Item (N, Pack_Id);
16461
16462 -- The legality checks of pragmas Abstract_State, Initializes, and
16463 -- Initial_Condition are affected by the SPARK mode in effect. In
16464 -- addition, these three pragmas are subject to an inherent order:
16465
16466 -- 1) Abstract_State
16467 -- 2) Initializes
16468 -- 3) Initial_Condition
16469
16470 -- Analyze all these pragmas in the order outlined above
16471
16472 Analyze_If_Present (Pragma_SPARK_Mode);
16473 Analyze_If_Present (Pragma_Abstract_State);
16474 Analyze_If_Present (Pragma_Initializes);
16475 end Initial_Condition;
16476
16477 ------------------------
16478 -- Initialize_Scalars --
16479 ------------------------
16480
16481 -- pragma Initialize_Scalars;
16482
16483 when Pragma_Initialize_Scalars =>
16484 GNAT_Pragma;
16485 Check_Arg_Count (0);
16486 Check_Valid_Configuration_Pragma;
16487 Check_Restriction (No_Initialize_Scalars, N);
16488
16489 -- Initialize_Scalars creates false positives in CodePeer, and
16490 -- incorrect negative results in GNATprove mode, so ignore this
16491 -- pragma in these modes.
16492
16493 if not Restriction_Active (No_Initialize_Scalars)
16494 and then not (CodePeer_Mode or GNATprove_Mode)
16495 then
16496 Init_Or_Norm_Scalars := True;
16497 Initialize_Scalars := True;
16498 end if;
16499
16500 -----------------
16501 -- Initializes --
16502 -----------------
16503
16504 -- pragma Initializes (INITIALIZATION_LIST);
16505
16506 -- INITIALIZATION_LIST ::=
16507 -- null
16508 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
16509
16510 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
16511
16512 -- INPUT_LIST ::=
16513 -- null
16514 -- | INPUT
16515 -- | (INPUT {, INPUT})
16516
16517 -- INPUT ::= name
16518
16519 -- Characteristics:
16520
16521 -- * Analysis - The annotation undergoes initial checks to verify
16522 -- the legal placement and context. Secondary checks preanalyze the
16523 -- expression in:
16524
16525 -- Analyze_Initializes_In_Decl_Part
16526
16527 -- * Expansion - None.
16528
16529 -- * Template - The annotation utilizes the generic template of the
16530 -- related package declaration.
16531
16532 -- * Globals - Capture of global references must occur after full
16533 -- analysis.
16534
16535 -- * Instance - The annotation is instantiated automatically when
16536 -- the related generic package is instantiated.
16537
16538 when Pragma_Initializes => Initializes : declare
16539 Pack_Decl : Node_Id;
16540 Pack_Id : Entity_Id;
16541
16542 begin
16543 GNAT_Pragma;
16544 Check_No_Identifiers;
16545 Check_Arg_Count (1);
16546
16547 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
16548
16549 -- Ensure the proper placement of the pragma. Initializes must be
16550 -- associated with a package declaration.
16551
16552 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
16553 N_Package_Declaration)
16554 then
16555 null;
16556
16557 -- Otherwise the pragma is associated with an illegal construc
16558
16559 else
16560 Pragma_Misplaced;
16561 return;
16562 end if;
16563
16564 Pack_Id := Defining_Entity (Pack_Decl);
16565
16566 -- A pragma that applies to a Ghost entity becomes Ghost for the
16567 -- purposes of legality checks and removal of ignored Ghost code.
16568
16569 Mark_Ghost_Pragma (N, Pack_Id);
16570 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
16571
16572 -- Chain the pragma on the contract for further processing by
16573 -- Analyze_Initializes_In_Decl_Part.
16574
16575 Add_Contract_Item (N, Pack_Id);
16576
16577 -- The legality checks of pragmas Abstract_State, Initializes, and
16578 -- Initial_Condition are affected by the SPARK mode in effect. In
16579 -- addition, these three pragmas are subject to an inherent order:
16580
16581 -- 1) Abstract_State
16582 -- 2) Initializes
16583 -- 3) Initial_Condition
16584
16585 -- Analyze all these pragmas in the order outlined above
16586
16587 Analyze_If_Present (Pragma_SPARK_Mode);
16588 Analyze_If_Present (Pragma_Abstract_State);
16589 Analyze_If_Present (Pragma_Initial_Condition);
16590 end Initializes;
16591
16592 ------------
16593 -- Inline --
16594 ------------
16595
16596 -- pragma Inline ( NAME {, NAME} );
16597
16598 when Pragma_Inline =>
16599
16600 -- Pragma always active unless in GNATprove mode. It is disabled
16601 -- in GNATprove mode because frontend inlining is applied
16602 -- independently of pragmas Inline and Inline_Always for
16603 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
16604 -- in inline.ads.
16605
16606 if not GNATprove_Mode then
16607
16608 -- Inline status is Enabled if option -gnatn is specified.
16609 -- However this status determines only the value of the
16610 -- Is_Inlined flag on the subprogram and does not prevent
16611 -- the pragma itself from being recorded for later use,
16612 -- in particular for a later modification of Is_Inlined
16613 -- independently of the -gnatn option.
16614
16615 -- In other words, if -gnatn is specified for a unit, then
16616 -- all Inline pragmas processed for the compilation of this
16617 -- unit, including those in the spec of other units, are
16618 -- activated, so subprograms will be inlined across units.
16619
16620 -- If -gnatn is not specified, no Inline pragma is activated
16621 -- here, which means that subprograms will not be inlined
16622 -- across units. The Is_Inlined flag will nevertheless be
16623 -- set later when bodies are analyzed, so subprograms will
16624 -- be inlined within the unit.
16625
16626 if Inline_Active then
16627 Process_Inline (Enabled);
16628 else
16629 Process_Inline (Disabled);
16630 end if;
16631 end if;
16632
16633 -------------------
16634 -- Inline_Always --
16635 -------------------
16636
16637 -- pragma Inline_Always ( NAME {, NAME} );
16638
16639 when Pragma_Inline_Always =>
16640 GNAT_Pragma;
16641
16642 -- Pragma always active unless in CodePeer mode or GNATprove
16643 -- mode. It is disabled in CodePeer mode because inlining is
16644 -- not helpful, and enabling it caused walk order issues. It
16645 -- is disabled in GNATprove mode because frontend inlining is
16646 -- applied independently of pragmas Inline and Inline_Always for
16647 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
16648 -- inline.ads.
16649
16650 if not CodePeer_Mode and not GNATprove_Mode then
16651 Process_Inline (Enabled);
16652 end if;
16653
16654 --------------------
16655 -- Inline_Generic --
16656 --------------------
16657
16658 -- pragma Inline_Generic (NAME {, NAME});
16659
16660 when Pragma_Inline_Generic =>
16661 GNAT_Pragma;
16662 Process_Generic_List;
16663
16664 ----------------------
16665 -- Inspection_Point --
16666 ----------------------
16667
16668 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
16669
16670 when Pragma_Inspection_Point => Inspection_Point : declare
16671 Arg : Node_Id;
16672 Exp : Node_Id;
16673
16674 begin
16675 ip;
16676
16677 if Arg_Count > 0 then
16678 Arg := Arg1;
16679 loop
16680 Exp := Get_Pragma_Arg (Arg);
16681 Analyze (Exp);
16682
16683 if not Is_Entity_Name (Exp)
16684 or else not Is_Object (Entity (Exp))
16685 then
16686 Error_Pragma_Arg ("object name required", Arg);
16687 end if;
16688
16689 Next (Arg);
16690 exit when No (Arg);
16691 end loop;
16692 end if;
16693 end Inspection_Point;
16694
16695 ---------------
16696 -- Interface --
16697 ---------------
16698
16699 -- pragma Interface (
16700 -- [ Convention =>] convention_IDENTIFIER,
16701 -- [ Entity =>] LOCAL_NAME
16702 -- [, [External_Name =>] static_string_EXPRESSION ]
16703 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16704
16705 when Pragma_Interface =>
16706 GNAT_Pragma;
16707 Check_Arg_Order
16708 ((Name_Convention,
16709 Name_Entity,
16710 Name_External_Name,
16711 Name_Link_Name));
16712 Check_At_Least_N_Arguments (2);
16713 Check_At_Most_N_Arguments (4);
16714 Process_Import_Or_Interface;
16715
16716 -- In Ada 2005, the permission to use Interface (a reserved word)
16717 -- as a pragma name is considered an obsolescent feature, and this
16718 -- pragma was already obsolescent in Ada 95.
16719
16720 if Ada_Version >= Ada_95 then
16721 Check_Restriction
16722 (No_Obsolescent_Features, Pragma_Identifier (N));
16723
16724 if Warn_On_Obsolescent_Feature then
16725 Error_Msg_N
16726 ("pragma Interface is an obsolescent feature?j?", N);
16727 Error_Msg_N
16728 ("|use pragma Import instead?j?", N);
16729 end if;
16730 end if;
16731
16732 --------------------
16733 -- Interface_Name --
16734 --------------------
16735
16736 -- pragma Interface_Name (
16737 -- [ Entity =>] LOCAL_NAME
16738 -- [,[External_Name =>] static_string_EXPRESSION ]
16739 -- [,[Link_Name =>] static_string_EXPRESSION ]);
16740
16741 when Pragma_Interface_Name => Interface_Name : declare
16742 Id : Node_Id;
16743 Def_Id : Entity_Id;
16744 Hom_Id : Entity_Id;
16745 Found : Boolean;
16746
16747 begin
16748 GNAT_Pragma;
16749 Check_Arg_Order
16750 ((Name_Entity, Name_External_Name, Name_Link_Name));
16751 Check_At_Least_N_Arguments (2);
16752 Check_At_Most_N_Arguments (3);
16753 Id := Get_Pragma_Arg (Arg1);
16754 Analyze (Id);
16755
16756 -- This is obsolete from Ada 95 on, but it is an implementation
16757 -- defined pragma, so we do not consider that it violates the
16758 -- restriction (No_Obsolescent_Features).
16759
16760 if Ada_Version >= Ada_95 then
16761 if Warn_On_Obsolescent_Feature then
16762 Error_Msg_N
16763 ("pragma Interface_Name is an obsolescent feature?j?", N);
16764 Error_Msg_N
16765 ("|use pragma Import instead?j?", N);
16766 end if;
16767 end if;
16768
16769 if not Is_Entity_Name (Id) then
16770 Error_Pragma_Arg
16771 ("first argument for pragma% must be entity name", Arg1);
16772 elsif Etype (Id) = Any_Type then
16773 return;
16774 else
16775 Def_Id := Entity (Id);
16776 end if;
16777
16778 -- Special DEC-compatible processing for the object case, forces
16779 -- object to be imported.
16780
16781 if Ekind (Def_Id) = E_Variable then
16782 Kill_Size_Check_Code (Def_Id);
16783 Note_Possible_Modification (Id, Sure => False);
16784
16785 -- Initialization is not allowed for imported variable
16786
16787 if Present (Expression (Parent (Def_Id)))
16788 and then Comes_From_Source (Expression (Parent (Def_Id)))
16789 then
16790 Error_Msg_Sloc := Sloc (Def_Id);
16791 Error_Pragma_Arg
16792 ("no initialization allowed for declaration of& #",
16793 Arg2);
16794
16795 else
16796 -- For compatibility, support VADS usage of providing both
16797 -- pragmas Interface and Interface_Name to obtain the effect
16798 -- of a single Import pragma.
16799
16800 if Is_Imported (Def_Id)
16801 and then Present (First_Rep_Item (Def_Id))
16802 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
16803 and then Pragma_Name (First_Rep_Item (Def_Id)) =
16804 Name_Interface
16805 then
16806 null;
16807 else
16808 Set_Imported (Def_Id);
16809 end if;
16810
16811 Set_Is_Public (Def_Id);
16812 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
16813 end if;
16814
16815 -- Otherwise must be subprogram
16816
16817 elsif not Is_Subprogram (Def_Id) then
16818 Error_Pragma_Arg
16819 ("argument of pragma% is not subprogram", Arg1);
16820
16821 else
16822 Check_At_Most_N_Arguments (3);
16823 Hom_Id := Def_Id;
16824 Found := False;
16825
16826 -- Loop through homonyms
16827
16828 loop
16829 Def_Id := Get_Base_Subprogram (Hom_Id);
16830
16831 if Is_Imported (Def_Id) then
16832 Process_Interface_Name (Def_Id, Arg2, Arg3, N);
16833 Found := True;
16834 end if;
16835
16836 exit when From_Aspect_Specification (N);
16837 Hom_Id := Homonym (Hom_Id);
16838
16839 exit when No (Hom_Id)
16840 or else Scope (Hom_Id) /= Current_Scope;
16841 end loop;
16842
16843 if not Found then
16844 Error_Pragma_Arg
16845 ("argument of pragma% is not imported subprogram",
16846 Arg1);
16847 end if;
16848 end if;
16849 end Interface_Name;
16850
16851 -----------------------
16852 -- Interrupt_Handler --
16853 -----------------------
16854
16855 -- pragma Interrupt_Handler (handler_NAME);
16856
16857 when Pragma_Interrupt_Handler =>
16858 Check_Ada_83_Warning;
16859 Check_Arg_Count (1);
16860 Check_No_Identifiers;
16861
16862 if No_Run_Time_Mode then
16863 Error_Msg_CRT ("Interrupt_Handler pragma", N);
16864 else
16865 Check_Interrupt_Or_Attach_Handler;
16866 Process_Interrupt_Or_Attach_Handler;
16867 end if;
16868
16869 ------------------------
16870 -- Interrupt_Priority --
16871 ------------------------
16872
16873 -- pragma Interrupt_Priority [(EXPRESSION)];
16874
16875 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
16876 P : constant Node_Id := Parent (N);
16877 Arg : Node_Id;
16878 Ent : Entity_Id;
16879
16880 begin
16881 Check_Ada_83_Warning;
16882
16883 if Arg_Count /= 0 then
16884 Arg := Get_Pragma_Arg (Arg1);
16885 Check_Arg_Count (1);
16886 Check_No_Identifiers;
16887
16888 -- The expression must be analyzed in the special manner
16889 -- described in "Handling of Default and Per-Object
16890 -- Expressions" in sem.ads.
16891
16892 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
16893 end if;
16894
16895 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
16896 Pragma_Misplaced;
16897 return;
16898
16899 else
16900 Ent := Defining_Identifier (Parent (P));
16901
16902 -- Check duplicate pragma before we chain the pragma in the Rep
16903 -- Item chain of Ent.
16904
16905 Check_Duplicate_Pragma (Ent);
16906 Record_Rep_Item (Ent, N);
16907
16908 -- Check the No_Task_At_Interrupt_Priority restriction
16909
16910 if Nkind (P) = N_Task_Definition then
16911 Check_Restriction (No_Task_At_Interrupt_Priority, N);
16912 end if;
16913 end if;
16914 end Interrupt_Priority;
16915
16916 ---------------------
16917 -- Interrupt_State --
16918 ---------------------
16919
16920 -- pragma Interrupt_State (
16921 -- [Name =>] INTERRUPT_ID,
16922 -- [State =>] INTERRUPT_STATE);
16923
16924 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16925 -- INTERRUPT_STATE => System | Runtime | User
16926
16927 -- Note: if the interrupt id is given as an identifier, then it must
16928 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16929 -- given as a static integer expression which must be in the range of
16930 -- Ada.Interrupts.Interrupt_ID.
16931
16932 when Pragma_Interrupt_State => Interrupt_State : declare
16933 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
16934 -- This is the entity Ada.Interrupts.Interrupt_ID;
16935
16936 State_Type : Character;
16937 -- Set to 's'/'r'/'u' for System/Runtime/User
16938
16939 IST_Num : Pos;
16940 -- Index to entry in Interrupt_States table
16941
16942 Int_Val : Uint;
16943 -- Value of interrupt
16944
16945 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
16946 -- The first argument to the pragma
16947
16948 Int_Ent : Entity_Id;
16949 -- Interrupt entity in Ada.Interrupts.Names
16950
16951 begin
16952 GNAT_Pragma;
16953 Check_Arg_Order ((Name_Name, Name_State));
16954 Check_Arg_Count (2);
16955
16956 Check_Optional_Identifier (Arg1, Name_Name);
16957 Check_Optional_Identifier (Arg2, Name_State);
16958 Check_Arg_Is_Identifier (Arg2);
16959
16960 -- First argument is identifier
16961
16962 if Nkind (Arg1X) = N_Identifier then
16963
16964 -- Search list of names in Ada.Interrupts.Names
16965
16966 Int_Ent := First_Entity (RTE (RE_Names));
16967 loop
16968 if No (Int_Ent) then
16969 Error_Pragma_Arg ("invalid interrupt name", Arg1);
16970
16971 elsif Chars (Int_Ent) = Chars (Arg1X) then
16972 Int_Val := Expr_Value (Constant_Value (Int_Ent));
16973 exit;
16974 end if;
16975
16976 Next_Entity (Int_Ent);
16977 end loop;
16978
16979 -- First argument is not an identifier, so it must be a static
16980 -- expression of type Ada.Interrupts.Interrupt_ID.
16981
16982 else
16983 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16984 Int_Val := Expr_Value (Arg1X);
16985
16986 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
16987 or else
16988 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
16989 then
16990 Error_Pragma_Arg
16991 ("value not in range of type "
16992 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
16993 end if;
16994 end if;
16995
16996 -- Check OK state
16997
16998 case Chars (Get_Pragma_Arg (Arg2)) is
16999 when Name_Runtime => State_Type := 'r';
17000 when Name_System => State_Type := 's';
17001 when Name_User => State_Type := 'u';
17002
17003 when others =>
17004 Error_Pragma_Arg ("invalid interrupt state", Arg2);
17005 end case;
17006
17007 -- Check if entry is already stored
17008
17009 IST_Num := Interrupt_States.First;
17010 loop
17011 -- If entry not found, add it
17012
17013 if IST_Num > Interrupt_States.Last then
17014 Interrupt_States.Append
17015 ((Interrupt_Number => UI_To_Int (Int_Val),
17016 Interrupt_State => State_Type,
17017 Pragma_Loc => Loc));
17018 exit;
17019
17020 -- Case of entry for the same entry
17021
17022 elsif Int_Val = Interrupt_States.Table (IST_Num).
17023 Interrupt_Number
17024 then
17025 -- If state matches, done, no need to make redundant entry
17026
17027 exit when
17028 State_Type = Interrupt_States.Table (IST_Num).
17029 Interrupt_State;
17030
17031 -- Otherwise if state does not match, error
17032
17033 Error_Msg_Sloc :=
17034 Interrupt_States.Table (IST_Num).Pragma_Loc;
17035 Error_Pragma_Arg
17036 ("state conflicts with that given #", Arg2);
17037 exit;
17038 end if;
17039
17040 IST_Num := IST_Num + 1;
17041 end loop;
17042 end Interrupt_State;
17043
17044 ---------------
17045 -- Invariant --
17046 ---------------
17047
17048 -- pragma Invariant
17049 -- ([Entity =>] type_LOCAL_NAME,
17050 -- [Check =>] EXPRESSION
17051 -- [,[Message =>] String_Expression]);
17052
17053 when Pragma_Invariant => Invariant : declare
17054 Discard : Boolean;
17055 Typ : Entity_Id;
17056 Typ_Arg : Node_Id;
17057
17058 begin
17059 GNAT_Pragma;
17060 Check_At_Least_N_Arguments (2);
17061 Check_At_Most_N_Arguments (3);
17062 Check_Optional_Identifier (Arg1, Name_Entity);
17063 Check_Optional_Identifier (Arg2, Name_Check);
17064
17065 if Arg_Count = 3 then
17066 Check_Optional_Identifier (Arg3, Name_Message);
17067 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
17068 end if;
17069
17070 Check_Arg_Is_Local_Name (Arg1);
17071
17072 Typ_Arg := Get_Pragma_Arg (Arg1);
17073 Find_Type (Typ_Arg);
17074 Typ := Entity (Typ_Arg);
17075
17076 -- Nothing to do of the related type is erroneous in some way
17077
17078 if Typ = Any_Type then
17079 return;
17080
17081 -- AI12-0041: Invariants are allowed in interface types
17082
17083 elsif Is_Interface (Typ) then
17084 null;
17085
17086 -- An invariant must apply to a private type, or appear in the
17087 -- private part of a package spec and apply to a completion.
17088 -- a class-wide invariant can only appear on a private declaration
17089 -- or private extension, not a completion.
17090
17091 -- A [class-wide] invariant may be associated a [limited] private
17092 -- type or a private extension.
17093
17094 elsif Ekind_In (Typ, E_Limited_Private_Type,
17095 E_Private_Type,
17096 E_Record_Type_With_Private)
17097 then
17098 null;
17099
17100 -- A non-class-wide invariant may be associated with the full view
17101 -- of a [limited] private type or a private extension.
17102
17103 elsif Has_Private_Declaration (Typ)
17104 and then not Class_Present (N)
17105 then
17106 null;
17107
17108 -- A class-wide invariant may appear on the partial view only
17109
17110 elsif Class_Present (N) then
17111 Error_Pragma_Arg
17112 ("pragma % only allowed for private type", Arg1);
17113 return;
17114
17115 -- A regular invariant may appear on both views
17116
17117 else
17118 Error_Pragma_Arg
17119 ("pragma % only allowed for private type or corresponding "
17120 & "full view", Arg1);
17121 return;
17122 end if;
17123
17124 -- An invariant associated with an abstract type (this includes
17125 -- interfaces) must be class-wide.
17126
17127 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
17128 Error_Pragma_Arg
17129 ("pragma % not allowed for abstract type", Arg1);
17130 return;
17131 end if;
17132
17133 -- A pragma that applies to a Ghost entity becomes Ghost for the
17134 -- purposes of legality checks and removal of ignored Ghost code.
17135
17136 Mark_Ghost_Pragma (N, Typ);
17137
17138 -- The pragma defines a type-specific invariant, the type is said
17139 -- to have invariants of its "own".
17140
17141 Set_Has_Own_Invariants (Typ);
17142
17143 -- If the invariant is class-wide, then it can be inherited by
17144 -- derived or interface implementing types. The type is said to
17145 -- have "inheritable" invariants.
17146
17147 if Class_Present (N) then
17148 Set_Has_Inheritable_Invariants (Typ);
17149 end if;
17150
17151 -- Chain the pragma on to the rep item chain, for processing when
17152 -- the type is frozen.
17153
17154 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
17155
17156 -- Create the declaration of the invariant procedure that will
17157 -- verify the invariant at run time. Interfaces are treated as the
17158 -- partial view of a private type in order to achieve uniformity
17159 -- with the general case. As a result, an interface receives only
17160 -- a "partial" invariant procedure, which is never called.
17161
17162 Build_Invariant_Procedure_Declaration
17163 (Typ => Typ,
17164 Partial_Invariant => Is_Interface (Typ));
17165 end Invariant;
17166
17167 ----------------
17168 -- Keep_Names --
17169 ----------------
17170
17171 -- pragma Keep_Names ([On => ] LOCAL_NAME);
17172
17173 when Pragma_Keep_Names => Keep_Names : declare
17174 Arg : Node_Id;
17175
17176 begin
17177 GNAT_Pragma;
17178 Check_Arg_Count (1);
17179 Check_Optional_Identifier (Arg1, Name_On);
17180 Check_Arg_Is_Local_Name (Arg1);
17181
17182 Arg := Get_Pragma_Arg (Arg1);
17183 Analyze (Arg);
17184
17185 if Etype (Arg) = Any_Type then
17186 return;
17187 end if;
17188
17189 if not Is_Entity_Name (Arg)
17190 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
17191 then
17192 Error_Pragma_Arg
17193 ("pragma% requires a local enumeration type", Arg1);
17194 end if;
17195
17196 Set_Discard_Names (Entity (Arg), False);
17197 end Keep_Names;
17198
17199 -------------
17200 -- License --
17201 -------------
17202
17203 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
17204
17205 when Pragma_License =>
17206 GNAT_Pragma;
17207
17208 -- Do not analyze pragma any further in CodePeer mode, to avoid
17209 -- extraneous errors in this implementation-dependent pragma,
17210 -- which has a different profile on other compilers.
17211
17212 if CodePeer_Mode then
17213 return;
17214 end if;
17215
17216 Check_Arg_Count (1);
17217 Check_No_Identifiers;
17218 Check_Valid_Configuration_Pragma;
17219 Check_Arg_Is_Identifier (Arg1);
17220
17221 declare
17222 Sind : constant Source_File_Index :=
17223 Source_Index (Current_Sem_Unit);
17224
17225 begin
17226 case Chars (Get_Pragma_Arg (Arg1)) is
17227 when Name_GPL =>
17228 Set_License (Sind, GPL);
17229
17230 when Name_Modified_GPL =>
17231 Set_License (Sind, Modified_GPL);
17232
17233 when Name_Restricted =>
17234 Set_License (Sind, Restricted);
17235
17236 when Name_Unrestricted =>
17237 Set_License (Sind, Unrestricted);
17238
17239 when others =>
17240 Error_Pragma_Arg ("invalid license name", Arg1);
17241 end case;
17242 end;
17243
17244 ---------------
17245 -- Link_With --
17246 ---------------
17247
17248 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
17249
17250 when Pragma_Link_With => Link_With : declare
17251 Arg : Node_Id;
17252
17253 begin
17254 GNAT_Pragma;
17255
17256 if Operating_Mode = Generate_Code
17257 and then In_Extended_Main_Source_Unit (N)
17258 then
17259 Check_At_Least_N_Arguments (1);
17260 Check_No_Identifiers;
17261 Check_Is_In_Decl_Part_Or_Package_Spec;
17262 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17263 Start_String;
17264
17265 Arg := Arg1;
17266 while Present (Arg) loop
17267 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
17268
17269 -- Store argument, converting sequences of spaces to a
17270 -- single null character (this is one of the differences
17271 -- in processing between Link_With and Linker_Options).
17272
17273 Arg_Store : declare
17274 C : constant Char_Code := Get_Char_Code (' ');
17275 S : constant String_Id :=
17276 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
17277 L : constant Nat := String_Length (S);
17278 F : Nat := 1;
17279
17280 procedure Skip_Spaces;
17281 -- Advance F past any spaces
17282
17283 -----------------
17284 -- Skip_Spaces --
17285 -----------------
17286
17287 procedure Skip_Spaces is
17288 begin
17289 while F <= L and then Get_String_Char (S, F) = C loop
17290 F := F + 1;
17291 end loop;
17292 end Skip_Spaces;
17293
17294 -- Start of processing for Arg_Store
17295
17296 begin
17297 Skip_Spaces; -- skip leading spaces
17298
17299 -- Loop through characters, changing any embedded
17300 -- sequence of spaces to a single null character (this
17301 -- is how Link_With/Linker_Options differ)
17302
17303 while F <= L loop
17304 if Get_String_Char (S, F) = C then
17305 Skip_Spaces;
17306 exit when F > L;
17307 Store_String_Char (ASCII.NUL);
17308
17309 else
17310 Store_String_Char (Get_String_Char (S, F));
17311 F := F + 1;
17312 end if;
17313 end loop;
17314 end Arg_Store;
17315
17316 Arg := Next (Arg);
17317
17318 if Present (Arg) then
17319 Store_String_Char (ASCII.NUL);
17320 end if;
17321 end loop;
17322
17323 Store_Linker_Option_String (End_String);
17324 end if;
17325 end Link_With;
17326
17327 ------------------
17328 -- Linker_Alias --
17329 ------------------
17330
17331 -- pragma Linker_Alias (
17332 -- [Entity =>] LOCAL_NAME
17333 -- [Target =>] static_string_EXPRESSION);
17334
17335 when Pragma_Linker_Alias =>
17336 GNAT_Pragma;
17337 Check_Arg_Order ((Name_Entity, Name_Target));
17338 Check_Arg_Count (2);
17339 Check_Optional_Identifier (Arg1, Name_Entity);
17340 Check_Optional_Identifier (Arg2, Name_Target);
17341 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17342 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17343
17344 -- The only processing required is to link this item on to the
17345 -- list of rep items for the given entity. This is accomplished
17346 -- by the call to Rep_Item_Too_Late (when no error is detected
17347 -- and False is returned).
17348
17349 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
17350 return;
17351 else
17352 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
17353 end if;
17354
17355 ------------------------
17356 -- Linker_Constructor --
17357 ------------------------
17358
17359 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
17360
17361 -- Code is shared with Linker_Destructor
17362
17363 -----------------------
17364 -- Linker_Destructor --
17365 -----------------------
17366
17367 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
17368
17369 when Pragma_Linker_Constructor
17370 | Pragma_Linker_Destructor
17371 =>
17372 Linker_Constructor : declare
17373 Arg1_X : Node_Id;
17374 Proc : Entity_Id;
17375
17376 begin
17377 GNAT_Pragma;
17378 Check_Arg_Count (1);
17379 Check_No_Identifiers;
17380 Check_Arg_Is_Local_Name (Arg1);
17381 Arg1_X := Get_Pragma_Arg (Arg1);
17382 Analyze (Arg1_X);
17383 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
17384
17385 if not Is_Library_Level_Entity (Proc) then
17386 Error_Pragma_Arg
17387 ("argument for pragma% must be library level entity", Arg1);
17388 end if;
17389
17390 -- The only processing required is to link this item on to the
17391 -- list of rep items for the given entity. This is accomplished
17392 -- by the call to Rep_Item_Too_Late (when no error is detected
17393 -- and False is returned).
17394
17395 if Rep_Item_Too_Late (Proc, N) then
17396 return;
17397 else
17398 Set_Has_Gigi_Rep_Item (Proc);
17399 end if;
17400 end Linker_Constructor;
17401
17402 --------------------
17403 -- Linker_Options --
17404 --------------------
17405
17406 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
17407
17408 when Pragma_Linker_Options => Linker_Options : declare
17409 Arg : Node_Id;
17410
17411 begin
17412 Check_Ada_83_Warning;
17413 Check_No_Identifiers;
17414 Check_Arg_Count (1);
17415 Check_Is_In_Decl_Part_Or_Package_Spec;
17416 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17417 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
17418
17419 Arg := Arg2;
17420 while Present (Arg) loop
17421 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
17422 Store_String_Char (ASCII.NUL);
17423 Store_String_Chars
17424 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
17425 Arg := Next (Arg);
17426 end loop;
17427
17428 if Operating_Mode = Generate_Code
17429 and then In_Extended_Main_Source_Unit (N)
17430 then
17431 Store_Linker_Option_String (End_String);
17432 end if;
17433 end Linker_Options;
17434
17435 --------------------
17436 -- Linker_Section --
17437 --------------------
17438
17439 -- pragma Linker_Section (
17440 -- [Entity =>] LOCAL_NAME
17441 -- [Section =>] static_string_EXPRESSION);
17442
17443 when Pragma_Linker_Section => Linker_Section : declare
17444 Arg : Node_Id;
17445 Ent : Entity_Id;
17446 LPE : Node_Id;
17447
17448 Ghost_Error_Posted : Boolean := False;
17449 -- Flag set when an error concerning the illegal mix of Ghost and
17450 -- non-Ghost subprograms is emitted.
17451
17452 Ghost_Id : Entity_Id := Empty;
17453 -- The entity of the first Ghost subprogram encountered while
17454 -- processing the arguments of the pragma.
17455
17456 begin
17457 GNAT_Pragma;
17458 Check_Arg_Order ((Name_Entity, Name_Section));
17459 Check_Arg_Count (2);
17460 Check_Optional_Identifier (Arg1, Name_Entity);
17461 Check_Optional_Identifier (Arg2, Name_Section);
17462 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17463 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17464
17465 -- Check kind of entity
17466
17467 Arg := Get_Pragma_Arg (Arg1);
17468 Ent := Entity (Arg);
17469
17470 case Ekind (Ent) is
17471
17472 -- Objects (constants and variables) and types. For these cases
17473 -- all we need to do is to set the Linker_Section_pragma field,
17474 -- checking that we do not have a duplicate.
17475
17476 when Type_Kind
17477 | E_Constant
17478 | E_Variable
17479 =>
17480 LPE := Linker_Section_Pragma (Ent);
17481
17482 if Present (LPE) then
17483 Error_Msg_Sloc := Sloc (LPE);
17484 Error_Msg_NE
17485 ("Linker_Section already specified for &#", Arg1, Ent);
17486 end if;
17487
17488 Set_Linker_Section_Pragma (Ent, N);
17489
17490 -- A pragma that applies to a Ghost entity becomes Ghost for
17491 -- the purposes of legality checks and removal of ignored
17492 -- Ghost code.
17493
17494 Mark_Ghost_Pragma (N, Ent);
17495
17496 -- Subprograms
17497
17498 when Subprogram_Kind =>
17499
17500 -- Aspect case, entity already set
17501
17502 if From_Aspect_Specification (N) then
17503 Set_Linker_Section_Pragma
17504 (Entity (Corresponding_Aspect (N)), N);
17505
17506 -- Pragma case, we must climb the homonym chain, but skip
17507 -- any for which the linker section is already set.
17508
17509 else
17510 loop
17511 if No (Linker_Section_Pragma (Ent)) then
17512 Set_Linker_Section_Pragma (Ent, N);
17513
17514 -- A pragma that applies to a Ghost entity becomes
17515 -- Ghost for the purposes of legality checks and
17516 -- removal of ignored Ghost code.
17517
17518 Mark_Ghost_Pragma (N, Ent);
17519
17520 -- Capture the entity of the first Ghost subprogram
17521 -- being processed for error detection purposes.
17522
17523 if Is_Ghost_Entity (Ent) then
17524 if No (Ghost_Id) then
17525 Ghost_Id := Ent;
17526 end if;
17527
17528 -- Otherwise the subprogram is non-Ghost. It is
17529 -- illegal to mix references to Ghost and non-Ghost
17530 -- entities (SPARK RM 6.9).
17531
17532 elsif Present (Ghost_Id)
17533 and then not Ghost_Error_Posted
17534 then
17535 Ghost_Error_Posted := True;
17536
17537 Error_Msg_Name_1 := Pname;
17538 Error_Msg_N
17539 ("pragma % cannot mention ghost and "
17540 & "non-ghost subprograms", N);
17541
17542 Error_Msg_Sloc := Sloc (Ghost_Id);
17543 Error_Msg_NE
17544 ("\& # declared as ghost", N, Ghost_Id);
17545
17546 Error_Msg_Sloc := Sloc (Ent);
17547 Error_Msg_NE
17548 ("\& # declared as non-ghost", N, Ent);
17549 end if;
17550 end if;
17551
17552 Ent := Homonym (Ent);
17553 exit when No (Ent)
17554 or else Scope (Ent) /= Current_Scope;
17555 end loop;
17556 end if;
17557
17558 -- All other cases are illegal
17559
17560 when others =>
17561 Error_Pragma_Arg
17562 ("pragma% applies only to objects, subprograms, and types",
17563 Arg1);
17564 end case;
17565 end Linker_Section;
17566
17567 ----------
17568 -- List --
17569 ----------
17570
17571 -- pragma List (On | Off)
17572
17573 -- There is nothing to do here, since we did all the processing for
17574 -- this pragma in Par.Prag (so that it works properly even in syntax
17575 -- only mode).
17576
17577 when Pragma_List =>
17578 null;
17579
17580 ---------------
17581 -- Lock_Free --
17582 ---------------
17583
17584 -- pragma Lock_Free [(Boolean_EXPRESSION)];
17585
17586 when Pragma_Lock_Free => Lock_Free : declare
17587 P : constant Node_Id := Parent (N);
17588 Arg : Node_Id;
17589 Ent : Entity_Id;
17590 Val : Boolean;
17591
17592 begin
17593 Check_No_Identifiers;
17594 Check_At_Most_N_Arguments (1);
17595
17596 -- Protected definition case
17597
17598 if Nkind (P) = N_Protected_Definition then
17599 Ent := Defining_Identifier (Parent (P));
17600
17601 -- One argument
17602
17603 if Arg_Count = 1 then
17604 Arg := Get_Pragma_Arg (Arg1);
17605 Val := Is_True (Static_Boolean (Arg));
17606
17607 -- No arguments (expression is considered to be True)
17608
17609 else
17610 Val := True;
17611 end if;
17612
17613 -- Check duplicate pragma before we chain the pragma in the Rep
17614 -- Item chain of Ent.
17615
17616 Check_Duplicate_Pragma (Ent);
17617 Record_Rep_Item (Ent, N);
17618 Set_Uses_Lock_Free (Ent, Val);
17619
17620 -- Anything else is incorrect placement
17621
17622 else
17623 Pragma_Misplaced;
17624 end if;
17625 end Lock_Free;
17626
17627 --------------------
17628 -- Locking_Policy --
17629 --------------------
17630
17631 -- pragma Locking_Policy (policy_IDENTIFIER);
17632
17633 when Pragma_Locking_Policy => declare
17634 subtype LP_Range is Name_Id
17635 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
17636 LP_Val : LP_Range;
17637 LP : Character;
17638
17639 begin
17640 Check_Ada_83_Warning;
17641 Check_Arg_Count (1);
17642 Check_No_Identifiers;
17643 Check_Arg_Is_Locking_Policy (Arg1);
17644 Check_Valid_Configuration_Pragma;
17645 LP_Val := Chars (Get_Pragma_Arg (Arg1));
17646
17647 case LP_Val is
17648 when Name_Ceiling_Locking => LP := 'C';
17649 when Name_Concurrent_Readers_Locking => LP := 'R';
17650 when Name_Inheritance_Locking => LP := 'I';
17651 end case;
17652
17653 if Locking_Policy /= ' '
17654 and then Locking_Policy /= LP
17655 then
17656 Error_Msg_Sloc := Locking_Policy_Sloc;
17657 Error_Pragma ("locking policy incompatible with policy#");
17658
17659 -- Set new policy, but always preserve System_Location since we
17660 -- like the error message with the run time name.
17661
17662 else
17663 Locking_Policy := LP;
17664
17665 if Locking_Policy_Sloc /= System_Location then
17666 Locking_Policy_Sloc := Loc;
17667 end if;
17668 end if;
17669 end;
17670
17671 -------------------
17672 -- Loop_Optimize --
17673 -------------------
17674
17675 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
17676
17677 -- OPTIMIZATION_HINT ::=
17678 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
17679
17680 when Pragma_Loop_Optimize => Loop_Optimize : declare
17681 Hint : Node_Id;
17682
17683 begin
17684 GNAT_Pragma;
17685 Check_At_Least_N_Arguments (1);
17686 Check_No_Identifiers;
17687
17688 Hint := First (Pragma_Argument_Associations (N));
17689 while Present (Hint) loop
17690 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
17691 Name_No_Unroll,
17692 Name_Unroll,
17693 Name_No_Vector,
17694 Name_Vector);
17695 Next (Hint);
17696 end loop;
17697
17698 Check_Loop_Pragma_Placement;
17699 end Loop_Optimize;
17700
17701 ------------------
17702 -- Loop_Variant --
17703 ------------------
17704
17705 -- pragma Loop_Variant
17706 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
17707
17708 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
17709
17710 -- CHANGE_DIRECTION ::= Increases | Decreases
17711
17712 when Pragma_Loop_Variant => Loop_Variant : declare
17713 Variant : Node_Id;
17714
17715 begin
17716 GNAT_Pragma;
17717 Check_At_Least_N_Arguments (1);
17718 Check_Loop_Pragma_Placement;
17719
17720 -- Process all increasing / decreasing expressions
17721
17722 Variant := First (Pragma_Argument_Associations (N));
17723 while Present (Variant) loop
17724 if not Nam_In (Chars (Variant), Name_Decreases,
17725 Name_Increases)
17726 then
17727 Error_Pragma_Arg ("wrong change modifier", Variant);
17728 end if;
17729
17730 Preanalyze_Assert_Expression
17731 (Expression (Variant), Any_Discrete);
17732
17733 Next (Variant);
17734 end loop;
17735 end Loop_Variant;
17736
17737 -----------------------
17738 -- Machine_Attribute --
17739 -----------------------
17740
17741 -- pragma Machine_Attribute (
17742 -- [Entity =>] LOCAL_NAME,
17743 -- [Attribute_Name =>] static_string_EXPRESSION
17744 -- [, [Info =>] static_EXPRESSION] );
17745
17746 when Pragma_Machine_Attribute => Machine_Attribute : declare
17747 Def_Id : Entity_Id;
17748
17749 begin
17750 GNAT_Pragma;
17751 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
17752
17753 if Arg_Count = 3 then
17754 Check_Optional_Identifier (Arg3, Name_Info);
17755 Check_Arg_Is_OK_Static_Expression (Arg3);
17756 else
17757 Check_Arg_Count (2);
17758 end if;
17759
17760 Check_Optional_Identifier (Arg1, Name_Entity);
17761 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
17762 Check_Arg_Is_Local_Name (Arg1);
17763 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17764 Def_Id := Entity (Get_Pragma_Arg (Arg1));
17765
17766 if Is_Access_Type (Def_Id) then
17767 Def_Id := Designated_Type (Def_Id);
17768 end if;
17769
17770 if Rep_Item_Too_Early (Def_Id, N) then
17771 return;
17772 end if;
17773
17774 Def_Id := Underlying_Type (Def_Id);
17775
17776 -- The only processing required is to link this item on to the
17777 -- list of rep items for the given entity. This is accomplished
17778 -- by the call to Rep_Item_Too_Late (when no error is detected
17779 -- and False is returned).
17780
17781 if Rep_Item_Too_Late (Def_Id, N) then
17782 return;
17783 else
17784 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
17785 end if;
17786 end Machine_Attribute;
17787
17788 ----------
17789 -- Main --
17790 ----------
17791
17792 -- pragma Main
17793 -- (MAIN_OPTION [, MAIN_OPTION]);
17794
17795 -- MAIN_OPTION ::=
17796 -- [STACK_SIZE =>] static_integer_EXPRESSION
17797 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17798 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17799
17800 when Pragma_Main => Main : declare
17801 Args : Args_List (1 .. 3);
17802 Names : constant Name_List (1 .. 3) := (
17803 Name_Stack_Size,
17804 Name_Task_Stack_Size_Default,
17805 Name_Time_Slicing_Enabled);
17806
17807 Nod : Node_Id;
17808
17809 begin
17810 GNAT_Pragma;
17811 Gather_Associations (Names, Args);
17812
17813 for J in 1 .. 2 loop
17814 if Present (Args (J)) then
17815 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17816 end if;
17817 end loop;
17818
17819 if Present (Args (3)) then
17820 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
17821 end if;
17822
17823 Nod := Next (N);
17824 while Present (Nod) loop
17825 if Nkind (Nod) = N_Pragma
17826 and then Pragma_Name (Nod) = Name_Main
17827 then
17828 Error_Msg_Name_1 := Pname;
17829 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17830 end if;
17831
17832 Next (Nod);
17833 end loop;
17834 end Main;
17835
17836 ------------------
17837 -- Main_Storage --
17838 ------------------
17839
17840 -- pragma Main_Storage
17841 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17842
17843 -- MAIN_STORAGE_OPTION ::=
17844 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17845 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17846
17847 when Pragma_Main_Storage => Main_Storage : declare
17848 Args : Args_List (1 .. 2);
17849 Names : constant Name_List (1 .. 2) := (
17850 Name_Working_Storage,
17851 Name_Top_Guard);
17852
17853 Nod : Node_Id;
17854
17855 begin
17856 GNAT_Pragma;
17857 Gather_Associations (Names, Args);
17858
17859 for J in 1 .. 2 loop
17860 if Present (Args (J)) then
17861 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17862 end if;
17863 end loop;
17864
17865 Check_In_Main_Program;
17866
17867 Nod := Next (N);
17868 while Present (Nod) loop
17869 if Nkind (Nod) = N_Pragma
17870 and then Pragma_Name (Nod) = Name_Main_Storage
17871 then
17872 Error_Msg_Name_1 := Pname;
17873 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17874 end if;
17875
17876 Next (Nod);
17877 end loop;
17878 end Main_Storage;
17879
17880 ----------------------
17881 -- Max_Queue_Length --
17882 ----------------------
17883
17884 -- pragma Max_Queue_Length (static_integer_EXPRESSION);
17885
17886 when Pragma_Max_Queue_Length => Max_Queue_Length : declare
17887 Arg : Node_Id;
17888 Entry_Decl : Node_Id;
17889 Entry_Id : Entity_Id;
17890 Val : Uint;
17891
17892 begin
17893 GNAT_Pragma;
17894 Check_Arg_Count (1);
17895
17896 Entry_Decl :=
17897 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
17898
17899 -- Entry declaration
17900
17901 if Nkind (Entry_Decl) = N_Entry_Declaration then
17902
17903 -- Entry illegally within a task
17904
17905 if Nkind (Parent (N)) = N_Task_Definition then
17906 Error_Pragma ("pragma % cannot apply to task entries");
17907 return;
17908 end if;
17909
17910 Entry_Id := Unique_Defining_Entity (Entry_Decl);
17911
17912 -- Otherwise the pragma is associated with an illegal construct
17913
17914 else
17915 Error_Pragma ("pragma % must apply to a protected entry");
17916 return;
17917 end if;
17918
17919 -- Mark the pragma as Ghost if the related subprogram is also
17920 -- Ghost. This also ensures that any expansion performed further
17921 -- below will produce Ghost nodes.
17922
17923 Mark_Ghost_Pragma (N, Entry_Id);
17924
17925 -- Analyze the Integer expression
17926
17927 Arg := Get_Pragma_Arg (Arg1);
17928 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
17929
17930 Val := Expr_Value (Arg);
17931
17932 if Val <= 0 then
17933 Error_Pragma_Arg
17934 ("argument for pragma% must be positive", Arg1);
17935
17936 elsif not UI_Is_In_Int_Range (Val) then
17937 Error_Pragma_Arg
17938 ("argument for pragma% out of range of Integer", Arg1);
17939
17940 end if;
17941
17942 -- Manually substitute the expression value of the pragma argument
17943 -- if it's not an integer literal because this is not taken care
17944 -- of automatically elsewhere.
17945
17946 if Nkind (Arg) /= N_Integer_Literal then
17947 Rewrite (Arg, Make_Integer_Literal (Sloc (Arg), Val));
17948 end if;
17949
17950 Record_Rep_Item (Entry_Id, N);
17951 end Max_Queue_Length;
17952
17953 -----------------
17954 -- Memory_Size --
17955 -----------------
17956
17957 -- pragma Memory_Size (NUMERIC_LITERAL)
17958
17959 when Pragma_Memory_Size =>
17960 GNAT_Pragma;
17961
17962 -- Memory size is simply ignored
17963
17964 Check_No_Identifiers;
17965 Check_Arg_Count (1);
17966 Check_Arg_Is_Integer_Literal (Arg1);
17967
17968 -------------
17969 -- No_Body --
17970 -------------
17971
17972 -- pragma No_Body;
17973
17974 -- The only correct use of this pragma is on its own in a file, in
17975 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
17976 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
17977 -- check for a file containing nothing but a No_Body pragma). If we
17978 -- attempt to process it during normal semantics processing, it means
17979 -- it was misplaced.
17980
17981 when Pragma_No_Body =>
17982 GNAT_Pragma;
17983 Pragma_Misplaced;
17984
17985 -----------------------------
17986 -- No_Elaboration_Code_All --
17987 -----------------------------
17988
17989 -- pragma No_Elaboration_Code_All;
17990
17991 when Pragma_No_Elaboration_Code_All =>
17992 GNAT_Pragma;
17993 Check_Valid_Library_Unit_Pragma;
17994
17995 if Nkind (N) = N_Null_Statement then
17996 return;
17997 end if;
17998
17999 -- Must appear for a spec or generic spec
18000
18001 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
18002 N_Generic_Package_Declaration,
18003 N_Generic_Subprogram_Declaration,
18004 N_Package_Declaration,
18005 N_Subprogram_Declaration)
18006 then
18007 Error_Pragma
18008 (Fix_Error
18009 ("pragma% can only occur for package "
18010 & "or subprogram spec"));
18011 end if;
18012
18013 -- Set flag in unit table
18014
18015 Set_No_Elab_Code_All (Current_Sem_Unit);
18016
18017 -- Set restriction No_Elaboration_Code if this is the main unit
18018
18019 if Current_Sem_Unit = Main_Unit then
18020 Set_Restriction (No_Elaboration_Code, N);
18021 end if;
18022
18023 -- If we are in the main unit or in an extended main source unit,
18024 -- then we also add it to the configuration restrictions so that
18025 -- it will apply to all units in the extended main source.
18026
18027 if Current_Sem_Unit = Main_Unit
18028 or else In_Extended_Main_Source_Unit (N)
18029 then
18030 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
18031 end if;
18032
18033 -- If in main extended unit, activate transitive with test
18034
18035 if In_Extended_Main_Source_Unit (N) then
18036 Opt.No_Elab_Code_All_Pragma := N;
18037 end if;
18038
18039 --------------------------
18040 -- No_Heap_Finalization --
18041 --------------------------
18042
18043 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
18044
18045 when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare
18046 Context : constant Node_Id := Parent (N);
18047 Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
18048 Prev : Node_Id;
18049 Typ : Entity_Id;
18050
18051 begin
18052 GNAT_Pragma;
18053 Check_No_Identifiers;
18054
18055 -- The pragma appears in a configuration file
18056
18057 if No (Context) then
18058 Check_Arg_Count (0);
18059 Check_Valid_Configuration_Pragma;
18060
18061 -- Detect a duplicate pragma
18062
18063 if Present (No_Heap_Finalization_Pragma) then
18064 Duplication_Error
18065 (Prag => N,
18066 Prev => No_Heap_Finalization_Pragma);
18067 raise Pragma_Exit;
18068 end if;
18069
18070 No_Heap_Finalization_Pragma := N;
18071
18072 -- Otherwise the pragma should be associated with a library-level
18073 -- named access-to-object type.
18074
18075 else
18076 Check_Arg_Count (1);
18077 Check_Arg_Is_Local_Name (Arg1);
18078
18079 Find_Type (Typ_Arg);
18080 Typ := Entity (Typ_Arg);
18081
18082 -- The type being subjected to the pragma is erroneous
18083
18084 if Typ = Any_Type then
18085 Error_Pragma ("cannot find type referenced by pragma %");
18086
18087 -- The pragma is applied to an incomplete or generic formal
18088 -- type way too early.
18089
18090 elsif Rep_Item_Too_Early (Typ, N) then
18091 return;
18092
18093 else
18094 Typ := Underlying_Type (Typ);
18095 end if;
18096
18097 -- The pragma must apply to an access-to-object type
18098
18099 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type) then
18100 null;
18101
18102 -- Give a detailed error message on all other access type kinds
18103
18104 elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then
18105 Error_Pragma
18106 ("pragma % cannot apply to access protected subprogram "
18107 & "type");
18108
18109 elsif Ekind (Typ) = E_Access_Subprogram_Type then
18110 Error_Pragma
18111 ("pragma % cannot apply to access subprogram type");
18112
18113 elsif Is_Anonymous_Access_Type (Typ) then
18114 Error_Pragma
18115 ("pragma % cannot apply to anonymous access type");
18116
18117 -- Give a general error message in case the pragma applies to a
18118 -- non-access type.
18119
18120 else
18121 Error_Pragma
18122 ("pragma % must apply to library level access type");
18123 end if;
18124
18125 -- At this point the argument denotes an access-to-object type.
18126 -- Ensure that the type is declared at the library level.
18127
18128 if Is_Library_Level_Entity (Typ) then
18129 null;
18130
18131 -- Quietly ignore an access-to-object type originally declared
18132 -- at the library level within a generic, but instantiated at
18133 -- a non-library level. As a result the access-to-object type
18134 -- "loses" its No_Heap_Finalization property.
18135
18136 elsif In_Instance then
18137 raise Pragma_Exit;
18138
18139 else
18140 Error_Pragma
18141 ("pragma % must apply to library level access type");
18142 end if;
18143
18144 -- Detect a duplicate pragma
18145
18146 if Present (No_Heap_Finalization_Pragma) then
18147 Duplication_Error
18148 (Prag => N,
18149 Prev => No_Heap_Finalization_Pragma);
18150 raise Pragma_Exit;
18151
18152 else
18153 Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization);
18154
18155 if Present (Prev) then
18156 Duplication_Error
18157 (Prag => N,
18158 Prev => Prev);
18159 raise Pragma_Exit;
18160 end if;
18161 end if;
18162
18163 Record_Rep_Item (Typ, N);
18164 end if;
18165 end No_Heap_Finalization;
18166
18167 ---------------
18168 -- No_Inline --
18169 ---------------
18170
18171 -- pragma No_Inline ( NAME {, NAME} );
18172
18173 when Pragma_No_Inline =>
18174 GNAT_Pragma;
18175 Process_Inline (Suppressed);
18176
18177 ---------------
18178 -- No_Return --
18179 ---------------
18180
18181 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
18182
18183 when Pragma_No_Return => No_Return : declare
18184 Arg : Node_Id;
18185 E : Entity_Id;
18186 Found : Boolean;
18187 Id : Node_Id;
18188
18189 Ghost_Error_Posted : Boolean := False;
18190 -- Flag set when an error concerning the illegal mix of Ghost and
18191 -- non-Ghost subprograms is emitted.
18192
18193 Ghost_Id : Entity_Id := Empty;
18194 -- The entity of the first Ghost procedure encountered while
18195 -- processing the arguments of the pragma.
18196
18197 begin
18198 Ada_2005_Pragma;
18199 Check_At_Least_N_Arguments (1);
18200
18201 -- Loop through arguments of pragma
18202
18203 Arg := Arg1;
18204 while Present (Arg) loop
18205 Check_Arg_Is_Local_Name (Arg);
18206 Id := Get_Pragma_Arg (Arg);
18207 Analyze (Id);
18208
18209 if not Is_Entity_Name (Id) then
18210 Error_Pragma_Arg ("entity name required", Arg);
18211 end if;
18212
18213 if Etype (Id) = Any_Type then
18214 raise Pragma_Exit;
18215 end if;
18216
18217 -- Loop to find matching procedures
18218
18219 E := Entity (Id);
18220
18221 Found := False;
18222 while Present (E)
18223 and then Scope (E) = Current_Scope
18224 loop
18225 if Ekind_In (E, E_Generic_Procedure, E_Procedure) then
18226
18227 -- Check that the pragma is not applied to a body.
18228 -- First check the specless body case, to give a
18229 -- different error message. These checks do not apply
18230 -- if Relaxed_RM_Semantics, to accommodate other Ada
18231 -- compilers. Disable these checks under -gnatd.J.
18232
18233 if not Debug_Flag_Dot_JJ then
18234 if Nkind (Parent (Declaration_Node (E))) =
18235 N_Subprogram_Body
18236 and then not Relaxed_RM_Semantics
18237 then
18238 Error_Pragma
18239 ("pragma% requires separate spec and must come "
18240 & "before body");
18241 end if;
18242
18243 -- Now the "specful" body case
18244
18245 if Rep_Item_Too_Late (E, N) then
18246 raise Pragma_Exit;
18247 end if;
18248 end if;
18249
18250 Set_No_Return (E);
18251
18252 -- A pragma that applies to a Ghost entity becomes Ghost
18253 -- for the purposes of legality checks and removal of
18254 -- ignored Ghost code.
18255
18256 Mark_Ghost_Pragma (N, E);
18257
18258 -- Capture the entity of the first Ghost procedure being
18259 -- processed for error detection purposes.
18260
18261 if Is_Ghost_Entity (E) then
18262 if No (Ghost_Id) then
18263 Ghost_Id := E;
18264 end if;
18265
18266 -- Otherwise the subprogram is non-Ghost. It is illegal
18267 -- to mix references to Ghost and non-Ghost entities
18268 -- (SPARK RM 6.9).
18269
18270 elsif Present (Ghost_Id)
18271 and then not Ghost_Error_Posted
18272 then
18273 Ghost_Error_Posted := True;
18274
18275 Error_Msg_Name_1 := Pname;
18276 Error_Msg_N
18277 ("pragma % cannot mention ghost and non-ghost "
18278 & "procedures", N);
18279
18280 Error_Msg_Sloc := Sloc (Ghost_Id);
18281 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
18282
18283 Error_Msg_Sloc := Sloc (E);
18284 Error_Msg_NE ("\& # declared as non-ghost", N, E);
18285 end if;
18286
18287 -- Set flag on any alias as well
18288
18289 if Is_Overloadable (E) and then Present (Alias (E)) then
18290 Set_No_Return (Alias (E));
18291 end if;
18292
18293 Found := True;
18294 end if;
18295
18296 exit when From_Aspect_Specification (N);
18297 E := Homonym (E);
18298 end loop;
18299
18300 -- If entity in not in current scope it may be the enclosing
18301 -- suprogram body to which the aspect applies.
18302
18303 if not Found then
18304 if Entity (Id) = Current_Scope
18305 and then From_Aspect_Specification (N)
18306 then
18307 Set_No_Return (Entity (Id));
18308 else
18309 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
18310 end if;
18311 end if;
18312
18313 Next (Arg);
18314 end loop;
18315 end No_Return;
18316
18317 -----------------
18318 -- No_Run_Time --
18319 -----------------
18320
18321 -- pragma No_Run_Time;
18322
18323 -- Note: this pragma is retained for backwards compatibility. See
18324 -- body of Rtsfind for full details on its handling.
18325
18326 when Pragma_No_Run_Time =>
18327 GNAT_Pragma;
18328 Check_Valid_Configuration_Pragma;
18329 Check_Arg_Count (0);
18330
18331 -- Remove backward compatibility if Build_Type is FSF or GPL and
18332 -- generate a warning.
18333
18334 declare
18335 Ignore : constant Boolean := Build_Type in FSF .. GPL;
18336 begin
18337 if Ignore then
18338 Error_Pragma ("pragma% is ignored, has no effect??");
18339 else
18340 No_Run_Time_Mode := True;
18341 Configurable_Run_Time_Mode := True;
18342
18343 -- Set Duration to 32 bits if word size is 32
18344
18345 if Ttypes.System_Word_Size = 32 then
18346 Duration_32_Bits_On_Target := True;
18347 end if;
18348
18349 -- Set appropriate restrictions
18350
18351 Set_Restriction (No_Finalization, N);
18352 Set_Restriction (No_Exception_Handlers, N);
18353 Set_Restriction (Max_Tasks, N, 0);
18354 Set_Restriction (No_Tasking, N);
18355 end if;
18356 end;
18357
18358 -----------------------
18359 -- No_Tagged_Streams --
18360 -----------------------
18361
18362 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
18363
18364 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
18365 E : Entity_Id;
18366 E_Id : Node_Id;
18367
18368 begin
18369 GNAT_Pragma;
18370 Check_At_Most_N_Arguments (1);
18371
18372 -- One argument case
18373
18374 if Arg_Count = 1 then
18375 Check_Optional_Identifier (Arg1, Name_Entity);
18376 Check_Arg_Is_Local_Name (Arg1);
18377 E_Id := Get_Pragma_Arg (Arg1);
18378
18379 if Etype (E_Id) = Any_Type then
18380 return;
18381 end if;
18382
18383 E := Entity (E_Id);
18384
18385 Check_Duplicate_Pragma (E);
18386
18387 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
18388 Error_Pragma_Arg
18389 ("argument for pragma% must be root tagged type", Arg1);
18390 end if;
18391
18392 if Rep_Item_Too_Early (E, N)
18393 or else
18394 Rep_Item_Too_Late (E, N)
18395 then
18396 return;
18397 else
18398 Set_No_Tagged_Streams_Pragma (E, N);
18399 end if;
18400
18401 -- Zero argument case
18402
18403 else
18404 Check_Is_In_Decl_Part_Or_Package_Spec;
18405 No_Tagged_Streams := N;
18406 end if;
18407 end No_Tagged_Strms;
18408
18409 ------------------------
18410 -- No_Strict_Aliasing --
18411 ------------------------
18412
18413 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
18414
18415 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
18416 E_Id : Entity_Id;
18417
18418 begin
18419 GNAT_Pragma;
18420 Check_At_Most_N_Arguments (1);
18421
18422 if Arg_Count = 0 then
18423 Check_Valid_Configuration_Pragma;
18424 Opt.No_Strict_Aliasing := True;
18425
18426 else
18427 Check_Optional_Identifier (Arg2, Name_Entity);
18428 Check_Arg_Is_Local_Name (Arg1);
18429 E_Id := Entity (Get_Pragma_Arg (Arg1));
18430
18431 if E_Id = Any_Type then
18432 return;
18433 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
18434 Error_Pragma_Arg ("pragma% requires access type", Arg1);
18435 end if;
18436
18437 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
18438 end if;
18439 end No_Strict_Aliasing;
18440
18441 -----------------------
18442 -- Normalize_Scalars --
18443 -----------------------
18444
18445 -- pragma Normalize_Scalars;
18446
18447 when Pragma_Normalize_Scalars =>
18448 Check_Ada_83_Warning;
18449 Check_Arg_Count (0);
18450 Check_Valid_Configuration_Pragma;
18451
18452 -- Normalize_Scalars creates false positives in CodePeer, and
18453 -- incorrect negative results in GNATprove mode, so ignore this
18454 -- pragma in these modes.
18455
18456 if not (CodePeer_Mode or GNATprove_Mode) then
18457 Normalize_Scalars := True;
18458 Init_Or_Norm_Scalars := True;
18459 end if;
18460
18461 -----------------
18462 -- Obsolescent --
18463 -----------------
18464
18465 -- pragma Obsolescent;
18466
18467 -- pragma Obsolescent (
18468 -- [Message =>] static_string_EXPRESSION
18469 -- [,[Version =>] Ada_05]]);
18470
18471 -- pragma Obsolescent (
18472 -- [Entity =>] NAME
18473 -- [,[Message =>] static_string_EXPRESSION
18474 -- [,[Version =>] Ada_05]] );
18475
18476 when Pragma_Obsolescent => Obsolescent : declare
18477 Decl : Node_Id;
18478 Ename : Node_Id;
18479
18480 procedure Set_Obsolescent (E : Entity_Id);
18481 -- Given an entity Ent, mark it as obsolescent if appropriate
18482
18483 ---------------------
18484 -- Set_Obsolescent --
18485 ---------------------
18486
18487 procedure Set_Obsolescent (E : Entity_Id) is
18488 Active : Boolean;
18489 Ent : Entity_Id;
18490 S : String_Id;
18491
18492 begin
18493 Active := True;
18494 Ent := E;
18495
18496 -- A pragma that applies to a Ghost entity becomes Ghost for
18497 -- the purposes of legality checks and removal of ignored Ghost
18498 -- code.
18499
18500 Mark_Ghost_Pragma (N, E);
18501
18502 -- Entity name was given
18503
18504 if Present (Ename) then
18505
18506 -- If entity name matches, we are fine. Save entity in
18507 -- pragma argument, for ASIS use.
18508
18509 if Chars (Ename) = Chars (Ent) then
18510 Set_Entity (Ename, Ent);
18511 Generate_Reference (Ent, Ename);
18512
18513 -- If entity name does not match, only possibility is an
18514 -- enumeration literal from an enumeration type declaration.
18515
18516 elsif Ekind (Ent) /= E_Enumeration_Type then
18517 Error_Pragma
18518 ("pragma % entity name does not match declaration");
18519
18520 else
18521 Ent := First_Literal (E);
18522 loop
18523 if No (Ent) then
18524 Error_Pragma
18525 ("pragma % entity name does not match any "
18526 & "enumeration literal");
18527
18528 elsif Chars (Ent) = Chars (Ename) then
18529 Set_Entity (Ename, Ent);
18530 Generate_Reference (Ent, Ename);
18531 exit;
18532
18533 else
18534 Ent := Next_Literal (Ent);
18535 end if;
18536 end loop;
18537 end if;
18538 end if;
18539
18540 -- Ent points to entity to be marked
18541
18542 if Arg_Count >= 1 then
18543
18544 -- Deal with static string argument
18545
18546 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
18547 S := Strval (Get_Pragma_Arg (Arg1));
18548
18549 for J in 1 .. String_Length (S) loop
18550 if not In_Character_Range (Get_String_Char (S, J)) then
18551 Error_Pragma_Arg
18552 ("pragma% argument does not allow wide characters",
18553 Arg1);
18554 end if;
18555 end loop;
18556
18557 Obsolescent_Warnings.Append
18558 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
18559
18560 -- Check for Ada_05 parameter
18561
18562 if Arg_Count /= 1 then
18563 Check_Arg_Count (2);
18564
18565 declare
18566 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
18567
18568 begin
18569 Check_Arg_Is_Identifier (Argx);
18570
18571 if Chars (Argx) /= Name_Ada_05 then
18572 Error_Msg_Name_2 := Name_Ada_05;
18573 Error_Pragma_Arg
18574 ("only allowed argument for pragma% is %", Argx);
18575 end if;
18576
18577 if Ada_Version_Explicit < Ada_2005
18578 or else not Warn_On_Ada_2005_Compatibility
18579 then
18580 Active := False;
18581 end if;
18582 end;
18583 end if;
18584 end if;
18585
18586 -- Set flag if pragma active
18587
18588 if Active then
18589 Set_Is_Obsolescent (Ent);
18590 end if;
18591
18592 return;
18593 end Set_Obsolescent;
18594
18595 -- Start of processing for pragma Obsolescent
18596
18597 begin
18598 GNAT_Pragma;
18599
18600 Check_At_Most_N_Arguments (3);
18601
18602 -- See if first argument specifies an entity name
18603
18604 if Arg_Count >= 1
18605 and then
18606 (Chars (Arg1) = Name_Entity
18607 or else
18608 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
18609 N_Identifier,
18610 N_Operator_Symbol))
18611 then
18612 Ename := Get_Pragma_Arg (Arg1);
18613
18614 -- Eliminate first argument, so we can share processing
18615
18616 Arg1 := Arg2;
18617 Arg2 := Arg3;
18618 Arg_Count := Arg_Count - 1;
18619
18620 -- No Entity name argument given
18621
18622 else
18623 Ename := Empty;
18624 end if;
18625
18626 if Arg_Count >= 1 then
18627 Check_Optional_Identifier (Arg1, Name_Message);
18628
18629 if Arg_Count = 2 then
18630 Check_Optional_Identifier (Arg2, Name_Version);
18631 end if;
18632 end if;
18633
18634 -- Get immediately preceding declaration
18635
18636 Decl := Prev (N);
18637 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
18638 Prev (Decl);
18639 end loop;
18640
18641 -- Cases where we do not follow anything other than another pragma
18642
18643 if No (Decl) then
18644
18645 -- First case: library level compilation unit declaration with
18646 -- the pragma immediately following the declaration.
18647
18648 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
18649 Set_Obsolescent
18650 (Defining_Entity (Unit (Parent (Parent (N)))));
18651 return;
18652
18653 -- Case 2: library unit placement for package
18654
18655 else
18656 declare
18657 Ent : constant Entity_Id := Find_Lib_Unit_Name;
18658 begin
18659 if Is_Package_Or_Generic_Package (Ent) then
18660 Set_Obsolescent (Ent);
18661 return;
18662 end if;
18663 end;
18664 end if;
18665
18666 -- Cases where we must follow a declaration, including an
18667 -- abstract subprogram declaration, which is not in the
18668 -- other node subtypes.
18669
18670 else
18671 if Nkind (Decl) not in N_Declaration
18672 and then Nkind (Decl) not in N_Later_Decl_Item
18673 and then Nkind (Decl) not in N_Generic_Declaration
18674 and then Nkind (Decl) not in N_Renaming_Declaration
18675 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
18676 then
18677 Error_Pragma
18678 ("pragma% misplaced, "
18679 & "must immediately follow a declaration");
18680
18681 else
18682 Set_Obsolescent (Defining_Entity (Decl));
18683 return;
18684 end if;
18685 end if;
18686 end Obsolescent;
18687
18688 --------------
18689 -- Optimize --
18690 --------------
18691
18692 -- pragma Optimize (Time | Space | Off);
18693
18694 -- The actual check for optimize is done in Gigi. Note that this
18695 -- pragma does not actually change the optimization setting, it
18696 -- simply checks that it is consistent with the pragma.
18697
18698 when Pragma_Optimize =>
18699 Check_No_Identifiers;
18700 Check_Arg_Count (1);
18701 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
18702
18703 ------------------------
18704 -- Optimize_Alignment --
18705 ------------------------
18706
18707 -- pragma Optimize_Alignment (Time | Space | Off);
18708
18709 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
18710 GNAT_Pragma;
18711 Check_No_Identifiers;
18712 Check_Arg_Count (1);
18713 Check_Valid_Configuration_Pragma;
18714
18715 declare
18716 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
18717 begin
18718 case Nam is
18719 when Name_Off => Opt.Optimize_Alignment := 'O';
18720 when Name_Space => Opt.Optimize_Alignment := 'S';
18721 when Name_Time => Opt.Optimize_Alignment := 'T';
18722
18723 when others =>
18724 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
18725 end case;
18726 end;
18727
18728 -- Set indication that mode is set locally. If we are in fact in a
18729 -- configuration pragma file, this setting is harmless since the
18730 -- switch will get reset anyway at the start of each unit.
18731
18732 Optimize_Alignment_Local := True;
18733 end Optimize_Alignment;
18734
18735 -------------
18736 -- Ordered --
18737 -------------
18738
18739 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
18740
18741 when Pragma_Ordered => Ordered : declare
18742 Assoc : constant Node_Id := Arg1;
18743 Type_Id : Node_Id;
18744 Typ : Entity_Id;
18745
18746 begin
18747 GNAT_Pragma;
18748 Check_No_Identifiers;
18749 Check_Arg_Count (1);
18750 Check_Arg_Is_Local_Name (Arg1);
18751
18752 Type_Id := Get_Pragma_Arg (Assoc);
18753 Find_Type (Type_Id);
18754 Typ := Entity (Type_Id);
18755
18756 if Typ = Any_Type then
18757 return;
18758 else
18759 Typ := Underlying_Type (Typ);
18760 end if;
18761
18762 if not Is_Enumeration_Type (Typ) then
18763 Error_Pragma ("pragma% must specify enumeration type");
18764 end if;
18765
18766 Check_First_Subtype (Arg1);
18767 Set_Has_Pragma_Ordered (Base_Type (Typ));
18768 end Ordered;
18769
18770 -------------------
18771 -- Overflow_Mode --
18772 -------------------
18773
18774 -- pragma Overflow_Mode
18775 -- ([General => ] MODE [, [Assertions => ] MODE]);
18776
18777 -- MODE := STRICT | MINIMIZED | ELIMINATED
18778
18779 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
18780 -- since System.Bignums makes this assumption. This is true of nearly
18781 -- all (all?) targets.
18782
18783 when Pragma_Overflow_Mode => Overflow_Mode : declare
18784 function Get_Overflow_Mode
18785 (Name : Name_Id;
18786 Arg : Node_Id) return Overflow_Mode_Type;
18787 -- Function to process one pragma argument, Arg. If an identifier
18788 -- is present, it must be Name. Mode type is returned if a valid
18789 -- argument exists, otherwise an error is signalled.
18790
18791 -----------------------
18792 -- Get_Overflow_Mode --
18793 -----------------------
18794
18795 function Get_Overflow_Mode
18796 (Name : Name_Id;
18797 Arg : Node_Id) return Overflow_Mode_Type
18798 is
18799 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
18800
18801 begin
18802 Check_Optional_Identifier (Arg, Name);
18803 Check_Arg_Is_Identifier (Argx);
18804
18805 if Chars (Argx) = Name_Strict then
18806 return Strict;
18807
18808 elsif Chars (Argx) = Name_Minimized then
18809 return Minimized;
18810
18811 elsif Chars (Argx) = Name_Eliminated then
18812 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
18813 Error_Pragma_Arg
18814 ("Eliminated not implemented on this target", Argx);
18815 else
18816 return Eliminated;
18817 end if;
18818
18819 else
18820 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
18821 end if;
18822 end Get_Overflow_Mode;
18823
18824 -- Start of processing for Overflow_Mode
18825
18826 begin
18827 GNAT_Pragma;
18828 Check_At_Least_N_Arguments (1);
18829 Check_At_Most_N_Arguments (2);
18830
18831 -- Process first argument
18832
18833 Scope_Suppress.Overflow_Mode_General :=
18834 Get_Overflow_Mode (Name_General, Arg1);
18835
18836 -- Case of only one argument
18837
18838 if Arg_Count = 1 then
18839 Scope_Suppress.Overflow_Mode_Assertions :=
18840 Scope_Suppress.Overflow_Mode_General;
18841
18842 -- Case of two arguments present
18843
18844 else
18845 Scope_Suppress.Overflow_Mode_Assertions :=
18846 Get_Overflow_Mode (Name_Assertions, Arg2);
18847 end if;
18848 end Overflow_Mode;
18849
18850 --------------------------
18851 -- Overriding Renamings --
18852 --------------------------
18853
18854 -- pragma Overriding_Renamings;
18855
18856 when Pragma_Overriding_Renamings =>
18857 GNAT_Pragma;
18858 Check_Arg_Count (0);
18859 Check_Valid_Configuration_Pragma;
18860 Overriding_Renamings := True;
18861
18862 ----------
18863 -- Pack --
18864 ----------
18865
18866 -- pragma Pack (first_subtype_LOCAL_NAME);
18867
18868 when Pragma_Pack => Pack : declare
18869 Assoc : constant Node_Id := Arg1;
18870 Ctyp : Entity_Id;
18871 Ignore : Boolean := False;
18872 Typ : Entity_Id;
18873 Type_Id : Node_Id;
18874
18875 begin
18876 Check_No_Identifiers;
18877 Check_Arg_Count (1);
18878 Check_Arg_Is_Local_Name (Arg1);
18879 Type_Id := Get_Pragma_Arg (Assoc);
18880
18881 if not Is_Entity_Name (Type_Id)
18882 or else not Is_Type (Entity (Type_Id))
18883 then
18884 Error_Pragma_Arg
18885 ("argument for pragma% must be type or subtype", Arg1);
18886 end if;
18887
18888 Find_Type (Type_Id);
18889 Typ := Entity (Type_Id);
18890
18891 if Typ = Any_Type
18892 or else Rep_Item_Too_Early (Typ, N)
18893 then
18894 return;
18895 else
18896 Typ := Underlying_Type (Typ);
18897 end if;
18898
18899 -- A pragma that applies to a Ghost entity becomes Ghost for the
18900 -- purposes of legality checks and removal of ignored Ghost code.
18901
18902 Mark_Ghost_Pragma (N, Typ);
18903
18904 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
18905 Error_Pragma ("pragma% must specify array or record type");
18906 end if;
18907
18908 Check_First_Subtype (Arg1);
18909 Check_Duplicate_Pragma (Typ);
18910
18911 -- Array type
18912
18913 if Is_Array_Type (Typ) then
18914 Ctyp := Component_Type (Typ);
18915
18916 -- Ignore pack that does nothing
18917
18918 if Known_Static_Esize (Ctyp)
18919 and then Known_Static_RM_Size (Ctyp)
18920 and then Esize (Ctyp) = RM_Size (Ctyp)
18921 and then Addressable (Esize (Ctyp))
18922 then
18923 Ignore := True;
18924 end if;
18925
18926 -- Process OK pragma Pack. Note that if there is a separate
18927 -- component clause present, the Pack will be cancelled. This
18928 -- processing is in Freeze.
18929
18930 if not Rep_Item_Too_Late (Typ, N) then
18931
18932 -- In CodePeer mode, we do not need complex front-end
18933 -- expansions related to pragma Pack, so disable handling
18934 -- of pragma Pack.
18935
18936 if CodePeer_Mode then
18937 null;
18938
18939 -- Normal case where we do the pack action
18940
18941 else
18942 if not Ignore then
18943 Set_Is_Packed (Base_Type (Typ));
18944 Set_Has_Non_Standard_Rep (Base_Type (Typ));
18945 end if;
18946
18947 Set_Has_Pragma_Pack (Base_Type (Typ));
18948 end if;
18949 end if;
18950
18951 -- For record types, the pack is always effective
18952
18953 else pragma Assert (Is_Record_Type (Typ));
18954 if not Rep_Item_Too_Late (Typ, N) then
18955 Set_Is_Packed (Base_Type (Typ));
18956 Set_Has_Pragma_Pack (Base_Type (Typ));
18957 Set_Has_Non_Standard_Rep (Base_Type (Typ));
18958 end if;
18959 end if;
18960 end Pack;
18961
18962 ----------
18963 -- Page --
18964 ----------
18965
18966 -- pragma Page;
18967
18968 -- There is nothing to do here, since we did all the processing for
18969 -- this pragma in Par.Prag (so that it works properly even in syntax
18970 -- only mode).
18971
18972 when Pragma_Page =>
18973 null;
18974
18975 -------------
18976 -- Part_Of --
18977 -------------
18978
18979 -- pragma Part_Of (ABSTRACT_STATE);
18980
18981 -- ABSTRACT_STATE ::= NAME
18982
18983 when Pragma_Part_Of => Part_Of : declare
18984 procedure Propagate_Part_Of
18985 (Pack_Id : Entity_Id;
18986 State_Id : Entity_Id;
18987 Instance : Node_Id);
18988 -- Propagate the Part_Of indicator to all abstract states and
18989 -- objects declared in the visible state space of a package
18990 -- denoted by Pack_Id. State_Id is the encapsulating state.
18991 -- Instance is the package instantiation node.
18992
18993 -----------------------
18994 -- Propagate_Part_Of --
18995 -----------------------
18996
18997 procedure Propagate_Part_Of
18998 (Pack_Id : Entity_Id;
18999 State_Id : Entity_Id;
19000 Instance : Node_Id)
19001 is
19002 Has_Item : Boolean := False;
19003 -- Flag set when the visible state space contains at least one
19004 -- abstract state or variable.
19005
19006 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
19007 -- Propagate the Part_Of indicator to all abstract states and
19008 -- objects declared in the visible state space of a package
19009 -- denoted by Pack_Id.
19010
19011 -----------------------
19012 -- Propagate_Part_Of --
19013 -----------------------
19014
19015 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
19016 Constits : Elist_Id;
19017 Item_Id : Entity_Id;
19018
19019 begin
19020 -- Traverse the entity chain of the package and set relevant
19021 -- attributes of abstract states and objects declared in the
19022 -- visible state space of the package.
19023
19024 Item_Id := First_Entity (Pack_Id);
19025 while Present (Item_Id)
19026 and then not In_Private_Part (Item_Id)
19027 loop
19028 -- Do not consider internally generated items
19029
19030 if not Comes_From_Source (Item_Id) then
19031 null;
19032
19033 -- The Part_Of indicator turns an abstract state or an
19034 -- object into a constituent of the encapsulating state.
19035
19036 elsif Ekind_In (Item_Id, E_Abstract_State,
19037 E_Constant,
19038 E_Variable)
19039 then
19040 Has_Item := True;
19041 Constits := Part_Of_Constituents (State_Id);
19042
19043 if No (Constits) then
19044 Constits := New_Elmt_List;
19045 Set_Part_Of_Constituents (State_Id, Constits);
19046 end if;
19047
19048 Append_Elmt (Item_Id, Constits);
19049 Set_Encapsulating_State (Item_Id, State_Id);
19050
19051 -- Recursively handle nested packages and instantiations
19052
19053 elsif Ekind (Item_Id) = E_Package then
19054 Propagate_Part_Of (Item_Id);
19055 end if;
19056
19057 Next_Entity (Item_Id);
19058 end loop;
19059 end Propagate_Part_Of;
19060
19061 -- Start of processing for Propagate_Part_Of
19062
19063 begin
19064 Propagate_Part_Of (Pack_Id);
19065
19066 -- Detect a package instantiation that is subject to a Part_Of
19067 -- indicator, but has no visible state.
19068
19069 if not Has_Item then
19070 SPARK_Msg_NE
19071 ("package instantiation & has Part_Of indicator but "
19072 & "lacks visible state", Instance, Pack_Id);
19073 end if;
19074 end Propagate_Part_Of;
19075
19076 -- Local variables
19077
19078 Constits : Elist_Id;
19079 Encap : Node_Id;
19080 Encap_Id : Entity_Id;
19081 Item_Id : Entity_Id;
19082 Legal : Boolean;
19083 Stmt : Node_Id;
19084
19085 -- Start of processing for Part_Of
19086
19087 begin
19088 GNAT_Pragma;
19089 Check_No_Identifiers;
19090 Check_Arg_Count (1);
19091
19092 Stmt := Find_Related_Context (N, Do_Checks => True);
19093
19094 -- Object declaration
19095
19096 if Nkind (Stmt) = N_Object_Declaration then
19097 null;
19098
19099 -- Package instantiation
19100
19101 elsif Nkind (Stmt) = N_Package_Instantiation then
19102 null;
19103
19104 -- Single concurrent type declaration
19105
19106 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
19107 null;
19108
19109 -- Otherwise the pragma is associated with an illegal construct
19110
19111 else
19112 Pragma_Misplaced;
19113 return;
19114 end if;
19115
19116 -- Extract the entity of the related object declaration or package
19117 -- instantiation. In the case of the instantiation, use the entity
19118 -- of the instance spec.
19119
19120 if Nkind (Stmt) = N_Package_Instantiation then
19121 Stmt := Instance_Spec (Stmt);
19122 end if;
19123
19124 Item_Id := Defining_Entity (Stmt);
19125
19126 -- A pragma that applies to a Ghost entity becomes Ghost for the
19127 -- purposes of legality checks and removal of ignored Ghost code.
19128
19129 Mark_Ghost_Pragma (N, Item_Id);
19130
19131 -- Chain the pragma on the contract for further processing by
19132 -- Analyze_Part_Of_In_Decl_Part or for completeness.
19133
19134 Add_Contract_Item (N, Item_Id);
19135
19136 -- A variable may act as constituent of a single concurrent type
19137 -- which in turn could be declared after the variable. Due to this
19138 -- discrepancy, the full analysis of indicator Part_Of is delayed
19139 -- until the end of the enclosing declarative region (see routine
19140 -- Analyze_Part_Of_In_Decl_Part).
19141
19142 if Ekind (Item_Id) = E_Variable then
19143 null;
19144
19145 -- Otherwise indicator Part_Of applies to a constant or a package
19146 -- instantiation.
19147
19148 else
19149 Encap := Get_Pragma_Arg (Arg1);
19150
19151 -- Detect any discrepancies between the placement of the
19152 -- constant or package instantiation with respect to state
19153 -- space and the encapsulating state.
19154
19155 Analyze_Part_Of
19156 (Indic => N,
19157 Item_Id => Item_Id,
19158 Encap => Encap,
19159 Encap_Id => Encap_Id,
19160 Legal => Legal);
19161
19162 if Legal then
19163 pragma Assert (Present (Encap_Id));
19164
19165 if Ekind (Item_Id) = E_Constant then
19166 Constits := Part_Of_Constituents (Encap_Id);
19167
19168 if No (Constits) then
19169 Constits := New_Elmt_List;
19170 Set_Part_Of_Constituents (Encap_Id, Constits);
19171 end if;
19172
19173 Append_Elmt (Item_Id, Constits);
19174 Set_Encapsulating_State (Item_Id, Encap_Id);
19175
19176 -- Propagate the Part_Of indicator to the visible state
19177 -- space of the package instantiation.
19178
19179 else
19180 Propagate_Part_Of
19181 (Pack_Id => Item_Id,
19182 State_Id => Encap_Id,
19183 Instance => Stmt);
19184 end if;
19185 end if;
19186 end if;
19187 end Part_Of;
19188
19189 ----------------------------------
19190 -- Partition_Elaboration_Policy --
19191 ----------------------------------
19192
19193 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
19194
19195 when Pragma_Partition_Elaboration_Policy => PEP : declare
19196 subtype PEP_Range is Name_Id
19197 range First_Partition_Elaboration_Policy_Name
19198 .. Last_Partition_Elaboration_Policy_Name;
19199 PEP_Val : PEP_Range;
19200 PEP : Character;
19201
19202 begin
19203 Ada_2005_Pragma;
19204 Check_Arg_Count (1);
19205 Check_No_Identifiers;
19206 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
19207 Check_Valid_Configuration_Pragma;
19208 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
19209
19210 case PEP_Val is
19211 when Name_Concurrent => PEP := 'C';
19212 when Name_Sequential => PEP := 'S';
19213 end case;
19214
19215 if Partition_Elaboration_Policy /= ' '
19216 and then Partition_Elaboration_Policy /= PEP
19217 then
19218 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
19219 Error_Pragma
19220 ("partition elaboration policy incompatible with policy#");
19221
19222 -- Set new policy, but always preserve System_Location since we
19223 -- like the error message with the run time name.
19224
19225 else
19226 Partition_Elaboration_Policy := PEP;
19227
19228 if Partition_Elaboration_Policy_Sloc /= System_Location then
19229 Partition_Elaboration_Policy_Sloc := Loc;
19230 end if;
19231 end if;
19232 end PEP;
19233
19234 -------------
19235 -- Passive --
19236 -------------
19237
19238 -- pragma Passive [(PASSIVE_FORM)];
19239
19240 -- PASSIVE_FORM ::= Semaphore | No
19241
19242 when Pragma_Passive =>
19243 GNAT_Pragma;
19244
19245 if Nkind (Parent (N)) /= N_Task_Definition then
19246 Error_Pragma ("pragma% must be within task definition");
19247 end if;
19248
19249 if Arg_Count /= 0 then
19250 Check_Arg_Count (1);
19251 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
19252 end if;
19253
19254 ----------------------------------
19255 -- Preelaborable_Initialization --
19256 ----------------------------------
19257
19258 -- pragma Preelaborable_Initialization (DIRECT_NAME);
19259
19260 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
19261 Ent : Entity_Id;
19262
19263 begin
19264 Ada_2005_Pragma;
19265 Check_Arg_Count (1);
19266 Check_No_Identifiers;
19267 Check_Arg_Is_Identifier (Arg1);
19268 Check_Arg_Is_Local_Name (Arg1);
19269 Check_First_Subtype (Arg1);
19270 Ent := Entity (Get_Pragma_Arg (Arg1));
19271
19272 -- A pragma that applies to a Ghost entity becomes Ghost for the
19273 -- purposes of legality checks and removal of ignored Ghost code.
19274
19275 Mark_Ghost_Pragma (N, Ent);
19276
19277 -- The pragma may come from an aspect on a private declaration,
19278 -- even if the freeze point at which this is analyzed in the
19279 -- private part after the full view.
19280
19281 if Has_Private_Declaration (Ent)
19282 and then From_Aspect_Specification (N)
19283 then
19284 null;
19285
19286 -- Check appropriate type argument
19287
19288 elsif Is_Private_Type (Ent)
19289 or else Is_Protected_Type (Ent)
19290 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
19291
19292 -- AI05-0028: The pragma applies to all composite types. Note
19293 -- that we apply this binding interpretation to earlier versions
19294 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
19295 -- choice since there are other compilers that do the same.
19296
19297 or else Is_Composite_Type (Ent)
19298 then
19299 null;
19300
19301 else
19302 Error_Pragma_Arg
19303 ("pragma % can only be applied to private, formal derived, "
19304 & "protected, or composite type", Arg1);
19305 end if;
19306
19307 -- Give an error if the pragma is applied to a protected type that
19308 -- does not qualify (due to having entries, or due to components
19309 -- that do not qualify).
19310
19311 if Is_Protected_Type (Ent)
19312 and then not Has_Preelaborable_Initialization (Ent)
19313 then
19314 Error_Msg_N
19315 ("protected type & does not have preelaborable "
19316 & "initialization", Ent);
19317
19318 -- Otherwise mark the type as definitely having preelaborable
19319 -- initialization.
19320
19321 else
19322 Set_Known_To_Have_Preelab_Init (Ent);
19323 end if;
19324
19325 if Has_Pragma_Preelab_Init (Ent)
19326 and then Warn_On_Redundant_Constructs
19327 then
19328 Error_Pragma ("?r?duplicate pragma%!");
19329 else
19330 Set_Has_Pragma_Preelab_Init (Ent);
19331 end if;
19332 end Preelab_Init;
19333
19334 --------------------
19335 -- Persistent_BSS --
19336 --------------------
19337
19338 -- pragma Persistent_BSS [(object_NAME)];
19339
19340 when Pragma_Persistent_BSS => Persistent_BSS : declare
19341 Decl : Node_Id;
19342 Ent : Entity_Id;
19343 Prag : Node_Id;
19344
19345 begin
19346 GNAT_Pragma;
19347 Check_At_Most_N_Arguments (1);
19348
19349 -- Case of application to specific object (one argument)
19350
19351 if Arg_Count = 1 then
19352 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19353
19354 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
19355 or else not
19356 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
19357 E_Constant)
19358 then
19359 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
19360 end if;
19361
19362 Ent := Entity (Get_Pragma_Arg (Arg1));
19363
19364 -- A pragma that applies to a Ghost entity becomes Ghost for
19365 -- the purposes of legality checks and removal of ignored Ghost
19366 -- code.
19367
19368 Mark_Ghost_Pragma (N, Ent);
19369
19370 -- Check for duplication before inserting in list of
19371 -- representation items.
19372
19373 Check_Duplicate_Pragma (Ent);
19374
19375 if Rep_Item_Too_Late (Ent, N) then
19376 return;
19377 end if;
19378
19379 Decl := Parent (Ent);
19380
19381 if Present (Expression (Decl)) then
19382 Error_Pragma_Arg
19383 ("object for pragma% cannot have initialization", Arg1);
19384 end if;
19385
19386 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
19387 Error_Pragma_Arg
19388 ("object type for pragma% is not potentially persistent",
19389 Arg1);
19390 end if;
19391
19392 Prag :=
19393 Make_Linker_Section_Pragma
19394 (Ent, Sloc (N), ".persistent.bss");
19395 Insert_After (N, Prag);
19396 Analyze (Prag);
19397
19398 -- Case of use as configuration pragma with no arguments
19399
19400 else
19401 Check_Valid_Configuration_Pragma;
19402 Persistent_BSS_Mode := True;
19403 end if;
19404 end Persistent_BSS;
19405
19406 --------------------
19407 -- Rename_Pragma --
19408 --------------------
19409
19410 -- pragma Rename_Pragma (
19411 -- [New_Name =>] IDENTIFIER,
19412 -- [Renamed =>] pragma_IDENTIFIER);
19413
19414 when Pragma_Rename_Pragma => Rename_Pragma : declare
19415 New_Name : constant Node_Id := Get_Pragma_Arg (Arg1);
19416 Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2);
19417
19418 begin
19419 GNAT_Pragma;
19420 Check_Valid_Configuration_Pragma;
19421 Check_Arg_Count (2);
19422 Check_Optional_Identifier (Arg1, Name_New_Name);
19423 Check_Optional_Identifier (Arg2, Name_Renamed);
19424
19425 if Nkind (New_Name) /= N_Identifier then
19426 Error_Pragma_Arg ("identifier expected", Arg1);
19427 end if;
19428
19429 if Nkind (Old_Name) /= N_Identifier then
19430 Error_Pragma_Arg ("identifier expected", Arg2);
19431 end if;
19432
19433 -- The New_Name arg should not be an existing pragma (but we allow
19434 -- it; it's just a warning). The Old_Name arg must be an existing
19435 -- pragma.
19436
19437 if Is_Pragma_Name (Chars (New_Name)) then
19438 Error_Pragma_Arg ("??pragma is already defined", Arg1);
19439 end if;
19440
19441 if not Is_Pragma_Name (Chars (Old_Name)) then
19442 Error_Pragma_Arg ("existing pragma name expected", Arg1);
19443 end if;
19444
19445 Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name));
19446 end Rename_Pragma;
19447
19448 -------------
19449 -- Polling --
19450 -------------
19451
19452 -- pragma Polling (ON | OFF);
19453
19454 when Pragma_Polling =>
19455 GNAT_Pragma;
19456 Check_Arg_Count (1);
19457 Check_No_Identifiers;
19458 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19459 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
19460
19461 -----------------------------------
19462 -- Post/Post_Class/Postcondition --
19463 -----------------------------------
19464
19465 -- pragma Post (Boolean_EXPRESSION);
19466 -- pragma Post_Class (Boolean_EXPRESSION);
19467 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
19468 -- [,[Message =>] String_EXPRESSION]);
19469
19470 -- Characteristics:
19471
19472 -- * Analysis - The annotation undergoes initial checks to verify
19473 -- the legal placement and context. Secondary checks preanalyze the
19474 -- expression in:
19475
19476 -- Analyze_Pre_Post_Condition_In_Decl_Part
19477
19478 -- * Expansion - The annotation is expanded during the expansion of
19479 -- the related subprogram [body] contract as performed in:
19480
19481 -- Expand_Subprogram_Contract
19482
19483 -- * Template - The annotation utilizes the generic template of the
19484 -- related subprogram [body] when it is:
19485
19486 -- aspect on subprogram declaration
19487 -- aspect on stand alone subprogram body
19488 -- pragma on stand alone subprogram body
19489
19490 -- The annotation must prepare its own template when it is:
19491
19492 -- pragma on subprogram declaration
19493
19494 -- * Globals - Capture of global references must occur after full
19495 -- analysis.
19496
19497 -- * Instance - The annotation is instantiated automatically when
19498 -- the related generic subprogram [body] is instantiated except for
19499 -- the "pragma on subprogram declaration" case. In that scenario
19500 -- the annotation must instantiate itself.
19501
19502 when Pragma_Post
19503 | Pragma_Post_Class
19504 | Pragma_Postcondition
19505 =>
19506 Analyze_Pre_Post_Condition;
19507
19508 --------------------------------
19509 -- Pre/Pre_Class/Precondition --
19510 --------------------------------
19511
19512 -- pragma Pre (Boolean_EXPRESSION);
19513 -- pragma Pre_Class (Boolean_EXPRESSION);
19514 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
19515 -- [,[Message =>] String_EXPRESSION]);
19516
19517 -- Characteristics:
19518
19519 -- * Analysis - The annotation undergoes initial checks to verify
19520 -- the legal placement and context. Secondary checks preanalyze the
19521 -- expression in:
19522
19523 -- Analyze_Pre_Post_Condition_In_Decl_Part
19524
19525 -- * Expansion - The annotation is expanded during the expansion of
19526 -- the related subprogram [body] contract as performed in:
19527
19528 -- Expand_Subprogram_Contract
19529
19530 -- * Template - The annotation utilizes the generic template of the
19531 -- related subprogram [body] when it is:
19532
19533 -- aspect on subprogram declaration
19534 -- aspect on stand alone subprogram body
19535 -- pragma on stand alone subprogram body
19536
19537 -- The annotation must prepare its own template when it is:
19538
19539 -- pragma on subprogram declaration
19540
19541 -- * Globals - Capture of global references must occur after full
19542 -- analysis.
19543
19544 -- * Instance - The annotation is instantiated automatically when
19545 -- the related generic subprogram [body] is instantiated except for
19546 -- the "pragma on subprogram declaration" case. In that scenario
19547 -- the annotation must instantiate itself.
19548
19549 when Pragma_Pre
19550 | Pragma_Pre_Class
19551 | Pragma_Precondition
19552 =>
19553 Analyze_Pre_Post_Condition;
19554
19555 ---------------
19556 -- Predicate --
19557 ---------------
19558
19559 -- pragma Predicate
19560 -- ([Entity =>] type_LOCAL_NAME,
19561 -- [Check =>] boolean_EXPRESSION);
19562
19563 when Pragma_Predicate => Predicate : declare
19564 Discard : Boolean;
19565 Typ : Entity_Id;
19566 Type_Id : Node_Id;
19567
19568 begin
19569 GNAT_Pragma;
19570 Check_Arg_Count (2);
19571 Check_Optional_Identifier (Arg1, Name_Entity);
19572 Check_Optional_Identifier (Arg2, Name_Check);
19573
19574 Check_Arg_Is_Local_Name (Arg1);
19575
19576 Type_Id := Get_Pragma_Arg (Arg1);
19577 Find_Type (Type_Id);
19578 Typ := Entity (Type_Id);
19579
19580 if Typ = Any_Type then
19581 return;
19582 end if;
19583
19584 -- A pragma that applies to a Ghost entity becomes Ghost for the
19585 -- purposes of legality checks and removal of ignored Ghost code.
19586
19587 Mark_Ghost_Pragma (N, Typ);
19588
19589 -- The remaining processing is simply to link the pragma on to
19590 -- the rep item chain, for processing when the type is frozen.
19591 -- This is accomplished by a call to Rep_Item_Too_Late. We also
19592 -- mark the type as having predicates.
19593
19594 -- If the current policy for predicate checking is Ignore mark the
19595 -- subtype accordingly. In the case of predicates we consider them
19596 -- enabled unless Ignore is specified (either directly or with a
19597 -- general Assertion_Policy pragma) to preserve existing warnings.
19598
19599 Set_Has_Predicates (Typ);
19600 Set_Predicates_Ignored (Typ,
19601 Present (Check_Policy_List)
19602 and then
19603 Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore);
19604 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19605 end Predicate;
19606
19607 -----------------------
19608 -- Predicate_Failure --
19609 -----------------------
19610
19611 -- pragma Predicate_Failure
19612 -- ([Entity =>] type_LOCAL_NAME,
19613 -- [Message =>] string_EXPRESSION);
19614
19615 when Pragma_Predicate_Failure => Predicate_Failure : declare
19616 Discard : Boolean;
19617 Typ : Entity_Id;
19618 Type_Id : Node_Id;
19619
19620 begin
19621 GNAT_Pragma;
19622 Check_Arg_Count (2);
19623 Check_Optional_Identifier (Arg1, Name_Entity);
19624 Check_Optional_Identifier (Arg2, Name_Message);
19625
19626 Check_Arg_Is_Local_Name (Arg1);
19627
19628 Type_Id := Get_Pragma_Arg (Arg1);
19629 Find_Type (Type_Id);
19630 Typ := Entity (Type_Id);
19631
19632 if Typ = Any_Type then
19633 return;
19634 end if;
19635
19636 -- A pragma that applies to a Ghost entity becomes Ghost for the
19637 -- purposes of legality checks and removal of ignored Ghost code.
19638
19639 Mark_Ghost_Pragma (N, Typ);
19640
19641 -- The remaining processing is simply to link the pragma on to
19642 -- the rep item chain, for processing when the type is frozen.
19643 -- This is accomplished by a call to Rep_Item_Too_Late.
19644
19645 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
19646 end Predicate_Failure;
19647
19648 ------------------
19649 -- Preelaborate --
19650 ------------------
19651
19652 -- pragma Preelaborate [(library_unit_NAME)];
19653
19654 -- Set the flag Is_Preelaborated of program unit name entity
19655
19656 when Pragma_Preelaborate => Preelaborate : declare
19657 Pa : constant Node_Id := Parent (N);
19658 Pk : constant Node_Kind := Nkind (Pa);
19659 Ent : Entity_Id;
19660
19661 begin
19662 Check_Ada_83_Warning;
19663 Check_Valid_Library_Unit_Pragma;
19664
19665 if Nkind (N) = N_Null_Statement then
19666 return;
19667 end if;
19668
19669 Ent := Find_Lib_Unit_Name;
19670
19671 -- A pragma that applies to a Ghost entity becomes Ghost for the
19672 -- purposes of legality checks and removal of ignored Ghost code.
19673
19674 Mark_Ghost_Pragma (N, Ent);
19675 Check_Duplicate_Pragma (Ent);
19676
19677 -- This filters out pragmas inside generic parents that show up
19678 -- inside instantiations. Pragmas that come from aspects in the
19679 -- unit are not ignored.
19680
19681 if Present (Ent) then
19682 if Pk = N_Package_Specification
19683 and then Present (Generic_Parent (Pa))
19684 and then not From_Aspect_Specification (N)
19685 then
19686 null;
19687
19688 else
19689 if not Debug_Flag_U then
19690 Set_Is_Preelaborated (Ent);
19691 Set_Suppress_Elaboration_Warnings (Ent);
19692 end if;
19693 end if;
19694 end if;
19695 end Preelaborate;
19696
19697 -------------------------------
19698 -- Prefix_Exception_Messages --
19699 -------------------------------
19700
19701 -- pragma Prefix_Exception_Messages;
19702
19703 when Pragma_Prefix_Exception_Messages =>
19704 GNAT_Pragma;
19705 Check_Valid_Configuration_Pragma;
19706 Check_Arg_Count (0);
19707 Prefix_Exception_Messages := True;
19708
19709 --------------
19710 -- Priority --
19711 --------------
19712
19713 -- pragma Priority (EXPRESSION);
19714
19715 when Pragma_Priority => Priority : declare
19716 P : constant Node_Id := Parent (N);
19717 Arg : Node_Id;
19718 Ent : Entity_Id;
19719
19720 begin
19721 Check_No_Identifiers;
19722 Check_Arg_Count (1);
19723
19724 -- Subprogram case
19725
19726 if Nkind (P) = N_Subprogram_Body then
19727 Check_In_Main_Program;
19728
19729 Ent := Defining_Unit_Name (Specification (P));
19730
19731 if Nkind (Ent) = N_Defining_Program_Unit_Name then
19732 Ent := Defining_Identifier (Ent);
19733 end if;
19734
19735 Arg := Get_Pragma_Arg (Arg1);
19736 Analyze_And_Resolve (Arg, Standard_Integer);
19737
19738 -- Must be static
19739
19740 if not Is_OK_Static_Expression (Arg) then
19741 Flag_Non_Static_Expr
19742 ("main subprogram priority is not static!", Arg);
19743 raise Pragma_Exit;
19744
19745 -- If constraint error, then we already signalled an error
19746
19747 elsif Raises_Constraint_Error (Arg) then
19748 null;
19749
19750 -- Otherwise check in range except if Relaxed_RM_Semantics
19751 -- where we ignore the value if out of range.
19752
19753 else
19754 if not Relaxed_RM_Semantics
19755 and then not Is_In_Range (Arg, RTE (RE_Priority))
19756 then
19757 Error_Pragma_Arg
19758 ("main subprogram priority is out of range", Arg1);
19759 else
19760 Set_Main_Priority
19761 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
19762 end if;
19763 end if;
19764
19765 -- Load an arbitrary entity from System.Tasking.Stages or
19766 -- System.Tasking.Restricted.Stages (depending on the
19767 -- supported profile) to make sure that one of these packages
19768 -- is implicitly with'ed, since we need to have the tasking
19769 -- run time active for the pragma Priority to have any effect.
19770 -- Previously we with'ed the package System.Tasking, but this
19771 -- package does not trigger the required initialization of the
19772 -- run-time library.
19773
19774 declare
19775 Discard : Entity_Id;
19776 pragma Warnings (Off, Discard);
19777 begin
19778 if Restricted_Profile then
19779 Discard := RTE (RE_Activate_Restricted_Tasks);
19780 else
19781 Discard := RTE (RE_Activate_Tasks);
19782 end if;
19783 end;
19784
19785 -- Task or Protected, must be of type Integer
19786
19787 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
19788 Arg := Get_Pragma_Arg (Arg1);
19789 Ent := Defining_Identifier (Parent (P));
19790
19791 -- The expression must be analyzed in the special manner
19792 -- described in "Handling of Default and Per-Object
19793 -- Expressions" in sem.ads.
19794
19795 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
19796
19797 if not Is_OK_Static_Expression (Arg) then
19798 Check_Restriction (Static_Priorities, Arg);
19799 end if;
19800
19801 -- Anything else is incorrect
19802
19803 else
19804 Pragma_Misplaced;
19805 end if;
19806
19807 -- Check duplicate pragma before we chain the pragma in the Rep
19808 -- Item chain of Ent.
19809
19810 Check_Duplicate_Pragma (Ent);
19811 Record_Rep_Item (Ent, N);
19812 end Priority;
19813
19814 -----------------------------------
19815 -- Priority_Specific_Dispatching --
19816 -----------------------------------
19817
19818 -- pragma Priority_Specific_Dispatching (
19819 -- policy_IDENTIFIER,
19820 -- first_priority_EXPRESSION,
19821 -- last_priority_EXPRESSION);
19822
19823 when Pragma_Priority_Specific_Dispatching =>
19824 Priority_Specific_Dispatching : declare
19825 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
19826 -- This is the entity System.Any_Priority;
19827
19828 DP : Character;
19829 Lower_Bound : Node_Id;
19830 Upper_Bound : Node_Id;
19831 Lower_Val : Uint;
19832 Upper_Val : Uint;
19833
19834 begin
19835 Ada_2005_Pragma;
19836 Check_Arg_Count (3);
19837 Check_No_Identifiers;
19838 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
19839 Check_Valid_Configuration_Pragma;
19840 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
19841 DP := Fold_Upper (Name_Buffer (1));
19842
19843 Lower_Bound := Get_Pragma_Arg (Arg2);
19844 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
19845 Lower_Val := Expr_Value (Lower_Bound);
19846
19847 Upper_Bound := Get_Pragma_Arg (Arg3);
19848 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
19849 Upper_Val := Expr_Value (Upper_Bound);
19850
19851 -- It is not allowed to use Task_Dispatching_Policy and
19852 -- Priority_Specific_Dispatching in the same partition.
19853
19854 if Task_Dispatching_Policy /= ' ' then
19855 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19856 Error_Pragma
19857 ("pragma% incompatible with Task_Dispatching_Policy#");
19858
19859 -- Check lower bound in range
19860
19861 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19862 or else
19863 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
19864 then
19865 Error_Pragma_Arg
19866 ("first_priority is out of range", Arg2);
19867
19868 -- Check upper bound in range
19869
19870 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19871 or else
19872 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
19873 then
19874 Error_Pragma_Arg
19875 ("last_priority is out of range", Arg3);
19876
19877 -- Check that the priority range is valid
19878
19879 elsif Lower_Val > Upper_Val then
19880 Error_Pragma
19881 ("last_priority_expression must be greater than or equal to "
19882 & "first_priority_expression");
19883
19884 -- Store the new policy, but always preserve System_Location since
19885 -- we like the error message with the run-time name.
19886
19887 else
19888 -- Check overlapping in the priority ranges specified in other
19889 -- Priority_Specific_Dispatching pragmas within the same
19890 -- partition. We can only check those we know about.
19891
19892 for J in
19893 Specific_Dispatching.First .. Specific_Dispatching.Last
19894 loop
19895 if Specific_Dispatching.Table (J).First_Priority in
19896 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19897 or else Specific_Dispatching.Table (J).Last_Priority in
19898 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19899 then
19900 Error_Msg_Sloc :=
19901 Specific_Dispatching.Table (J).Pragma_Loc;
19902 Error_Pragma
19903 ("priority range overlaps with "
19904 & "Priority_Specific_Dispatching#");
19905 end if;
19906 end loop;
19907
19908 -- The use of Priority_Specific_Dispatching is incompatible
19909 -- with Task_Dispatching_Policy.
19910
19911 if Task_Dispatching_Policy /= ' ' then
19912 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19913 Error_Pragma
19914 ("Priority_Specific_Dispatching incompatible "
19915 & "with Task_Dispatching_Policy#");
19916 end if;
19917
19918 -- The use of Priority_Specific_Dispatching forces ceiling
19919 -- locking policy.
19920
19921 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
19922 Error_Msg_Sloc := Locking_Policy_Sloc;
19923 Error_Pragma
19924 ("Priority_Specific_Dispatching incompatible "
19925 & "with Locking_Policy#");
19926
19927 -- Set the Ceiling_Locking policy, but preserve System_Location
19928 -- since we like the error message with the run time name.
19929
19930 else
19931 Locking_Policy := 'C';
19932
19933 if Locking_Policy_Sloc /= System_Location then
19934 Locking_Policy_Sloc := Loc;
19935 end if;
19936 end if;
19937
19938 -- Add entry in the table
19939
19940 Specific_Dispatching.Append
19941 ((Dispatching_Policy => DP,
19942 First_Priority => UI_To_Int (Lower_Val),
19943 Last_Priority => UI_To_Int (Upper_Val),
19944 Pragma_Loc => Loc));
19945 end if;
19946 end Priority_Specific_Dispatching;
19947
19948 -------------
19949 -- Profile --
19950 -------------
19951
19952 -- pragma Profile (profile_IDENTIFIER);
19953
19954 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
19955
19956 when Pragma_Profile =>
19957 Ada_2005_Pragma;
19958 Check_Arg_Count (1);
19959 Check_Valid_Configuration_Pragma;
19960 Check_No_Identifiers;
19961
19962 declare
19963 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19964
19965 begin
19966 if Chars (Argx) = Name_Ravenscar then
19967 Set_Ravenscar_Profile (Ravenscar, N);
19968
19969 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
19970 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
19971
19972 elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then
19973 Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N);
19974
19975 elsif Chars (Argx) = Name_Restricted then
19976 Set_Profile_Restrictions
19977 (Restricted,
19978 N, Warn => Treat_Restrictions_As_Warnings);
19979
19980 elsif Chars (Argx) = Name_Rational then
19981 Set_Rational_Profile;
19982
19983 elsif Chars (Argx) = Name_No_Implementation_Extensions then
19984 Set_Profile_Restrictions
19985 (No_Implementation_Extensions,
19986 N, Warn => Treat_Restrictions_As_Warnings);
19987
19988 else
19989 Error_Pragma_Arg ("& is not a valid profile", Argx);
19990 end if;
19991 end;
19992
19993 ----------------------
19994 -- Profile_Warnings --
19995 ----------------------
19996
19997 -- pragma Profile_Warnings (profile_IDENTIFIER);
19998
19999 -- profile_IDENTIFIER => Restricted | Ravenscar
20000
20001 when Pragma_Profile_Warnings =>
20002 GNAT_Pragma;
20003 Check_Arg_Count (1);
20004 Check_Valid_Configuration_Pragma;
20005 Check_No_Identifiers;
20006
20007 declare
20008 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
20009
20010 begin
20011 if Chars (Argx) = Name_Ravenscar then
20012 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
20013
20014 elsif Chars (Argx) = Name_Restricted then
20015 Set_Profile_Restrictions (Restricted, N, Warn => True);
20016
20017 elsif Chars (Argx) = Name_No_Implementation_Extensions then
20018 Set_Profile_Restrictions
20019 (No_Implementation_Extensions, N, Warn => True);
20020
20021 else
20022 Error_Pragma_Arg ("& is not a valid profile", Argx);
20023 end if;
20024 end;
20025
20026 --------------------------
20027 -- Propagate_Exceptions --
20028 --------------------------
20029
20030 -- pragma Propagate_Exceptions;
20031
20032 -- Note: this pragma is obsolete and has no effect
20033
20034 when Pragma_Propagate_Exceptions =>
20035 GNAT_Pragma;
20036 Check_Arg_Count (0);
20037
20038 if Warn_On_Obsolescent_Feature then
20039 Error_Msg_N
20040 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
20041 "and has no effect?j?", N);
20042 end if;
20043
20044 -----------------------------
20045 -- Provide_Shift_Operators --
20046 -----------------------------
20047
20048 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
20049
20050 when Pragma_Provide_Shift_Operators =>
20051 Provide_Shift_Operators : declare
20052 Ent : Entity_Id;
20053
20054 procedure Declare_Shift_Operator (Nam : Name_Id);
20055 -- Insert declaration and pragma Instrinsic for named shift op
20056
20057 ----------------------------
20058 -- Declare_Shift_Operator --
20059 ----------------------------
20060
20061 procedure Declare_Shift_Operator (Nam : Name_Id) is
20062 Func : Node_Id;
20063 Import : Node_Id;
20064
20065 begin
20066 Func :=
20067 Make_Subprogram_Declaration (Loc,
20068 Make_Function_Specification (Loc,
20069 Defining_Unit_Name =>
20070 Make_Defining_Identifier (Loc, Chars => Nam),
20071
20072 Result_Definition =>
20073 Make_Identifier (Loc, Chars => Chars (Ent)),
20074
20075 Parameter_Specifications => New_List (
20076 Make_Parameter_Specification (Loc,
20077 Defining_Identifier =>
20078 Make_Defining_Identifier (Loc, Name_Value),
20079 Parameter_Type =>
20080 Make_Identifier (Loc, Chars => Chars (Ent))),
20081
20082 Make_Parameter_Specification (Loc,
20083 Defining_Identifier =>
20084 Make_Defining_Identifier (Loc, Name_Amount),
20085 Parameter_Type =>
20086 New_Occurrence_Of (Standard_Natural, Loc)))));
20087
20088 Import :=
20089 Make_Pragma (Loc,
20090 Chars => Name_Import,
20091 Pragma_Argument_Associations => New_List (
20092 Make_Pragma_Argument_Association (Loc,
20093 Expression => Make_Identifier (Loc, Name_Intrinsic)),
20094 Make_Pragma_Argument_Association (Loc,
20095 Expression => Make_Identifier (Loc, Nam))));
20096
20097 Insert_After (N, Import);
20098 Insert_After (N, Func);
20099 end Declare_Shift_Operator;
20100
20101 -- Start of processing for Provide_Shift_Operators
20102
20103 begin
20104 GNAT_Pragma;
20105 Check_Arg_Count (1);
20106 Check_Arg_Is_Local_Name (Arg1);
20107
20108 Arg1 := Get_Pragma_Arg (Arg1);
20109
20110 -- We must have an entity name
20111
20112 if not Is_Entity_Name (Arg1) then
20113 Error_Pragma_Arg
20114 ("pragma % must apply to integer first subtype", Arg1);
20115 end if;
20116
20117 -- If no Entity, means there was a prior error so ignore
20118
20119 if Present (Entity (Arg1)) then
20120 Ent := Entity (Arg1);
20121
20122 -- Apply error checks
20123
20124 if not Is_First_Subtype (Ent) then
20125 Error_Pragma_Arg
20126 ("cannot apply pragma %",
20127 "\& is not a first subtype",
20128 Arg1);
20129
20130 elsif not Is_Integer_Type (Ent) then
20131 Error_Pragma_Arg
20132 ("cannot apply pragma %",
20133 "\& is not an integer type",
20134 Arg1);
20135
20136 elsif Has_Shift_Operator (Ent) then
20137 Error_Pragma_Arg
20138 ("cannot apply pragma %",
20139 "\& already has declared shift operators",
20140 Arg1);
20141
20142 elsif Is_Frozen (Ent) then
20143 Error_Pragma_Arg
20144 ("pragma % appears too late",
20145 "\& is already frozen",
20146 Arg1);
20147 end if;
20148
20149 -- Now declare the operators. We do this during analysis rather
20150 -- than expansion, since we want the operators available if we
20151 -- are operating in -gnatc or ASIS mode.
20152
20153 Declare_Shift_Operator (Name_Rotate_Left);
20154 Declare_Shift_Operator (Name_Rotate_Right);
20155 Declare_Shift_Operator (Name_Shift_Left);
20156 Declare_Shift_Operator (Name_Shift_Right);
20157 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
20158 end if;
20159 end Provide_Shift_Operators;
20160
20161 ------------------
20162 -- Psect_Object --
20163 ------------------
20164
20165 -- pragma Psect_Object (
20166 -- [Internal =>] LOCAL_NAME,
20167 -- [, [External =>] EXTERNAL_SYMBOL]
20168 -- [, [Size =>] EXTERNAL_SYMBOL]);
20169
20170 when Pragma_Common_Object
20171 | Pragma_Psect_Object
20172 =>
20173 Psect_Object : declare
20174 Args : Args_List (1 .. 3);
20175 Names : constant Name_List (1 .. 3) := (
20176 Name_Internal,
20177 Name_External,
20178 Name_Size);
20179
20180 Internal : Node_Id renames Args (1);
20181 External : Node_Id renames Args (2);
20182 Size : Node_Id renames Args (3);
20183
20184 Def_Id : Entity_Id;
20185
20186 procedure Check_Arg (Arg : Node_Id);
20187 -- Checks that argument is either a string literal or an
20188 -- identifier, and posts error message if not.
20189
20190 ---------------
20191 -- Check_Arg --
20192 ---------------
20193
20194 procedure Check_Arg (Arg : Node_Id) is
20195 begin
20196 if not Nkind_In (Original_Node (Arg),
20197 N_String_Literal,
20198 N_Identifier)
20199 then
20200 Error_Pragma_Arg
20201 ("inappropriate argument for pragma %", Arg);
20202 end if;
20203 end Check_Arg;
20204
20205 -- Start of processing for Common_Object/Psect_Object
20206
20207 begin
20208 GNAT_Pragma;
20209 Gather_Associations (Names, Args);
20210 Process_Extended_Import_Export_Internal_Arg (Internal);
20211
20212 Def_Id := Entity (Internal);
20213
20214 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
20215 Error_Pragma_Arg
20216 ("pragma% must designate an object", Internal);
20217 end if;
20218
20219 Check_Arg (Internal);
20220
20221 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
20222 Error_Pragma_Arg
20223 ("cannot use pragma% for imported/exported object",
20224 Internal);
20225 end if;
20226
20227 if Is_Concurrent_Type (Etype (Internal)) then
20228 Error_Pragma_Arg
20229 ("cannot specify pragma % for task/protected object",
20230 Internal);
20231 end if;
20232
20233 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
20234 or else
20235 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
20236 then
20237 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
20238 end if;
20239
20240 if Ekind (Def_Id) = E_Constant then
20241 Error_Pragma_Arg
20242 ("cannot specify pragma % for a constant", Internal);
20243 end if;
20244
20245 if Is_Record_Type (Etype (Internal)) then
20246 declare
20247 Ent : Entity_Id;
20248 Decl : Entity_Id;
20249
20250 begin
20251 Ent := First_Entity (Etype (Internal));
20252 while Present (Ent) loop
20253 Decl := Declaration_Node (Ent);
20254
20255 if Ekind (Ent) = E_Component
20256 and then Nkind (Decl) = N_Component_Declaration
20257 and then Present (Expression (Decl))
20258 and then Warn_On_Export_Import
20259 then
20260 Error_Msg_N
20261 ("?x?object for pragma % has defaults", Internal);
20262 exit;
20263
20264 else
20265 Next_Entity (Ent);
20266 end if;
20267 end loop;
20268 end;
20269 end if;
20270
20271 if Present (Size) then
20272 Check_Arg (Size);
20273 end if;
20274
20275 if Present (External) then
20276 Check_Arg_Is_External_Name (External);
20277 end if;
20278
20279 -- If all error tests pass, link pragma on to the rep item chain
20280
20281 Record_Rep_Item (Def_Id, N);
20282 end Psect_Object;
20283
20284 ----------
20285 -- Pure --
20286 ----------
20287
20288 -- pragma Pure [(library_unit_NAME)];
20289
20290 when Pragma_Pure => Pure : declare
20291 Ent : Entity_Id;
20292
20293 begin
20294 Check_Ada_83_Warning;
20295
20296 -- If the pragma comes from a subprogram instantiation, nothing to
20297 -- check, this can happen at any level of nesting.
20298
20299 if Is_Wrapper_Package (Current_Scope) then
20300 return;
20301 else
20302 Check_Valid_Library_Unit_Pragma;
20303 end if;
20304
20305 if Nkind (N) = N_Null_Statement then
20306 return;
20307 end if;
20308
20309 Ent := Find_Lib_Unit_Name;
20310
20311 -- A pragma that applies to a Ghost entity becomes Ghost for the
20312 -- purposes of legality checks and removal of ignored Ghost code.
20313
20314 Mark_Ghost_Pragma (N, Ent);
20315
20316 if not Debug_Flag_U then
20317 Set_Is_Pure (Ent);
20318 Set_Has_Pragma_Pure (Ent);
20319 Set_Suppress_Elaboration_Warnings (Ent);
20320 end if;
20321 end Pure;
20322
20323 -------------------
20324 -- Pure_Function --
20325 -------------------
20326
20327 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
20328
20329 when Pragma_Pure_Function => Pure_Function : declare
20330 Def_Id : Entity_Id;
20331 E : Entity_Id;
20332 E_Id : Node_Id;
20333 Effective : Boolean := False;
20334
20335 begin
20336 GNAT_Pragma;
20337 Check_Arg_Count (1);
20338 Check_Optional_Identifier (Arg1, Name_Entity);
20339 Check_Arg_Is_Local_Name (Arg1);
20340 E_Id := Get_Pragma_Arg (Arg1);
20341
20342 if Error_Posted (E_Id) then
20343 return;
20344 end if;
20345
20346 -- Loop through homonyms (overloadings) of referenced entity
20347
20348 E := Entity (E_Id);
20349
20350 -- A pragma that applies to a Ghost entity becomes Ghost for the
20351 -- purposes of legality checks and removal of ignored Ghost code.
20352
20353 Mark_Ghost_Pragma (N, E);
20354
20355 if Present (E) then
20356 loop
20357 Def_Id := Get_Base_Subprogram (E);
20358
20359 if not Ekind_In (Def_Id, E_Function,
20360 E_Generic_Function,
20361 E_Operator)
20362 then
20363 Error_Pragma_Arg
20364 ("pragma% requires a function name", Arg1);
20365 end if;
20366
20367 Set_Is_Pure (Def_Id);
20368
20369 if not Has_Pragma_Pure_Function (Def_Id) then
20370 Set_Has_Pragma_Pure_Function (Def_Id);
20371 Effective := True;
20372 end if;
20373
20374 exit when From_Aspect_Specification (N);
20375 E := Homonym (E);
20376 exit when No (E) or else Scope (E) /= Current_Scope;
20377 end loop;
20378
20379 if not Effective
20380 and then Warn_On_Redundant_Constructs
20381 then
20382 Error_Msg_NE
20383 ("pragma Pure_Function on& is redundant?r?",
20384 N, Entity (E_Id));
20385 end if;
20386 end if;
20387 end Pure_Function;
20388
20389 --------------------
20390 -- Queuing_Policy --
20391 --------------------
20392
20393 -- pragma Queuing_Policy (policy_IDENTIFIER);
20394
20395 when Pragma_Queuing_Policy => declare
20396 QP : Character;
20397
20398 begin
20399 Check_Ada_83_Warning;
20400 Check_Arg_Count (1);
20401 Check_No_Identifiers;
20402 Check_Arg_Is_Queuing_Policy (Arg1);
20403 Check_Valid_Configuration_Pragma;
20404 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20405 QP := Fold_Upper (Name_Buffer (1));
20406
20407 if Queuing_Policy /= ' '
20408 and then Queuing_Policy /= QP
20409 then
20410 Error_Msg_Sloc := Queuing_Policy_Sloc;
20411 Error_Pragma ("queuing policy incompatible with policy#");
20412
20413 -- Set new policy, but always preserve System_Location since we
20414 -- like the error message with the run time name.
20415
20416 else
20417 Queuing_Policy := QP;
20418
20419 if Queuing_Policy_Sloc /= System_Location then
20420 Queuing_Policy_Sloc := Loc;
20421 end if;
20422 end if;
20423 end;
20424
20425 --------------
20426 -- Rational --
20427 --------------
20428
20429 -- pragma Rational, for compatibility with foreign compiler
20430
20431 when Pragma_Rational =>
20432 Set_Rational_Profile;
20433
20434 ---------------------
20435 -- Refined_Depends --
20436 ---------------------
20437
20438 -- pragma Refined_Depends (DEPENDENCY_RELATION);
20439
20440 -- DEPENDENCY_RELATION ::=
20441 -- null
20442 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
20443
20444 -- DEPENDENCY_CLAUSE ::=
20445 -- OUTPUT_LIST =>[+] INPUT_LIST
20446 -- | NULL_DEPENDENCY_CLAUSE
20447
20448 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
20449
20450 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
20451
20452 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
20453
20454 -- OUTPUT ::= NAME | FUNCTION_RESULT
20455 -- INPUT ::= NAME
20456
20457 -- where FUNCTION_RESULT is a function Result attribute_reference
20458
20459 -- Characteristics:
20460
20461 -- * Analysis - The annotation undergoes initial checks to verify
20462 -- the legal placement and context. Secondary checks fully analyze
20463 -- the dependency clauses/global list in:
20464
20465 -- Analyze_Refined_Depends_In_Decl_Part
20466
20467 -- * Expansion - None.
20468
20469 -- * Template - The annotation utilizes the generic template of the
20470 -- related subprogram body.
20471
20472 -- * Globals - Capture of global references must occur after full
20473 -- analysis.
20474
20475 -- * Instance - The annotation is instantiated automatically when
20476 -- the related generic subprogram body is instantiated.
20477
20478 when Pragma_Refined_Depends => Refined_Depends : declare
20479 Body_Id : Entity_Id;
20480 Legal : Boolean;
20481 Spec_Id : Entity_Id;
20482
20483 begin
20484 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
20485
20486 if Legal then
20487
20488 -- Chain the pragma on the contract for further processing by
20489 -- Analyze_Refined_Depends_In_Decl_Part.
20490
20491 Add_Contract_Item (N, Body_Id);
20492
20493 -- The legality checks of pragmas Refined_Depends and
20494 -- Refined_Global are affected by the SPARK mode in effect and
20495 -- the volatility of the context. In addition these two pragmas
20496 -- are subject to an inherent order:
20497
20498 -- 1) Refined_Global
20499 -- 2) Refined_Depends
20500
20501 -- Analyze all these pragmas in the order outlined above
20502
20503 Analyze_If_Present (Pragma_SPARK_Mode);
20504 Analyze_If_Present (Pragma_Volatile_Function);
20505 Analyze_If_Present (Pragma_Refined_Global);
20506 Analyze_Refined_Depends_In_Decl_Part (N);
20507 end if;
20508 end Refined_Depends;
20509
20510 --------------------
20511 -- Refined_Global --
20512 --------------------
20513
20514 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
20515
20516 -- GLOBAL_SPECIFICATION ::=
20517 -- null
20518 -- | (GLOBAL_LIST)
20519 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
20520
20521 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
20522
20523 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
20524 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
20525 -- GLOBAL_ITEM ::= NAME
20526
20527 -- Characteristics:
20528
20529 -- * Analysis - The annotation undergoes initial checks to verify
20530 -- the legal placement and context. Secondary checks fully analyze
20531 -- the dependency clauses/global list in:
20532
20533 -- Analyze_Refined_Global_In_Decl_Part
20534
20535 -- * Expansion - None.
20536
20537 -- * Template - The annotation utilizes the generic template of the
20538 -- related subprogram body.
20539
20540 -- * Globals - Capture of global references must occur after full
20541 -- analysis.
20542
20543 -- * Instance - The annotation is instantiated automatically when
20544 -- the related generic subprogram body is instantiated.
20545
20546 when Pragma_Refined_Global => Refined_Global : declare
20547 Body_Id : Entity_Id;
20548 Legal : Boolean;
20549 Spec_Id : Entity_Id;
20550
20551 begin
20552 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
20553
20554 if Legal then
20555
20556 -- Chain the pragma on the contract for further processing by
20557 -- Analyze_Refined_Global_In_Decl_Part.
20558
20559 Add_Contract_Item (N, Body_Id);
20560
20561 -- The legality checks of pragmas Refined_Depends and
20562 -- Refined_Global are affected by the SPARK mode in effect and
20563 -- the volatility of the context. In addition these two pragmas
20564 -- are subject to an inherent order:
20565
20566 -- 1) Refined_Global
20567 -- 2) Refined_Depends
20568
20569 -- Analyze all these pragmas in the order outlined above
20570
20571 Analyze_If_Present (Pragma_SPARK_Mode);
20572 Analyze_If_Present (Pragma_Volatile_Function);
20573 Analyze_Refined_Global_In_Decl_Part (N);
20574 Analyze_If_Present (Pragma_Refined_Depends);
20575 end if;
20576 end Refined_Global;
20577
20578 ------------------
20579 -- Refined_Post --
20580 ------------------
20581
20582 -- pragma Refined_Post (boolean_EXPRESSION);
20583
20584 -- Characteristics:
20585
20586 -- * Analysis - The annotation is fully analyzed immediately upon
20587 -- elaboration as it cannot forward reference entities.
20588
20589 -- * Expansion - The annotation is expanded during the expansion of
20590 -- the related subprogram body contract as performed in:
20591
20592 -- Expand_Subprogram_Contract
20593
20594 -- * Template - The annotation utilizes the generic template of the
20595 -- related subprogram body.
20596
20597 -- * Globals - Capture of global references must occur after full
20598 -- analysis.
20599
20600 -- * Instance - The annotation is instantiated automatically when
20601 -- the related generic subprogram body is instantiated.
20602
20603 when Pragma_Refined_Post => Refined_Post : declare
20604 Body_Id : Entity_Id;
20605 Legal : Boolean;
20606 Spec_Id : Entity_Id;
20607
20608 begin
20609 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
20610
20611 -- Fully analyze the pragma when it appears inside a subprogram
20612 -- body because it cannot benefit from forward references.
20613
20614 if Legal then
20615
20616 -- Chain the pragma on the contract for completeness
20617
20618 Add_Contract_Item (N, Body_Id);
20619
20620 -- The legality checks of pragma Refined_Post are affected by
20621 -- the SPARK mode in effect and the volatility of the context.
20622 -- Analyze all pragmas in a specific order.
20623
20624 Analyze_If_Present (Pragma_SPARK_Mode);
20625 Analyze_If_Present (Pragma_Volatile_Function);
20626 Analyze_Pre_Post_Condition_In_Decl_Part (N);
20627
20628 -- Currently it is not possible to inline pre/postconditions on
20629 -- a subprogram subject to pragma Inline_Always.
20630
20631 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
20632 end if;
20633 end Refined_Post;
20634
20635 -------------------
20636 -- Refined_State --
20637 -------------------
20638
20639 -- pragma Refined_State (REFINEMENT_LIST);
20640
20641 -- REFINEMENT_LIST ::=
20642 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
20643
20644 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
20645
20646 -- CONSTITUENT_LIST ::=
20647 -- null
20648 -- | CONSTITUENT
20649 -- | (CONSTITUENT {, CONSTITUENT})
20650
20651 -- CONSTITUENT ::= object_NAME | state_NAME
20652
20653 -- Characteristics:
20654
20655 -- * Analysis - The annotation undergoes initial checks to verify
20656 -- the legal placement and context. Secondary checks preanalyze the
20657 -- refinement clauses in:
20658
20659 -- Analyze_Refined_State_In_Decl_Part
20660
20661 -- * Expansion - None.
20662
20663 -- * Template - The annotation utilizes the template of the related
20664 -- package 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 package body is instantiated.
20671
20672 when Pragma_Refined_State => Refined_State : declare
20673 Pack_Decl : Node_Id;
20674 Spec_Id : Entity_Id;
20675
20676 begin
20677 GNAT_Pragma;
20678 Check_No_Identifiers;
20679 Check_Arg_Count (1);
20680
20681 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
20682
20683 -- Ensure the proper placement of the pragma. Refined states must
20684 -- be associated with a package body.
20685
20686 if Nkind (Pack_Decl) = N_Package_Body then
20687 null;
20688
20689 -- Otherwise the pragma is associated with an illegal construct
20690
20691 else
20692 Pragma_Misplaced;
20693 return;
20694 end if;
20695
20696 Spec_Id := Corresponding_Spec (Pack_Decl);
20697
20698 -- A pragma that applies to a Ghost entity becomes Ghost for the
20699 -- purposes of legality checks and removal of ignored Ghost code.
20700
20701 Mark_Ghost_Pragma (N, Spec_Id);
20702
20703 -- Chain the pragma on the contract for further processing by
20704 -- Analyze_Refined_State_In_Decl_Part.
20705
20706 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
20707
20708 -- The legality checks of pragma Refined_State are affected by the
20709 -- SPARK mode in effect. Analyze all pragmas in a specific order.
20710
20711 Analyze_If_Present (Pragma_SPARK_Mode);
20712
20713 -- State refinement is allowed only when the corresponding package
20714 -- declaration has non-null pragma Abstract_State. Refinement not
20715 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
20716
20717 if SPARK_Mode /= Off
20718 and then
20719 (No (Abstract_States (Spec_Id))
20720 or else Has_Null_Abstract_State (Spec_Id))
20721 then
20722 Error_Msg_NE
20723 ("useless refinement, package & does not define abstract "
20724 & "states", N, Spec_Id);
20725 return;
20726 end if;
20727 end Refined_State;
20728
20729 -----------------------
20730 -- Relative_Deadline --
20731 -----------------------
20732
20733 -- pragma Relative_Deadline (time_span_EXPRESSION);
20734
20735 when Pragma_Relative_Deadline => Relative_Deadline : declare
20736 P : constant Node_Id := Parent (N);
20737 Arg : Node_Id;
20738
20739 begin
20740 Ada_2005_Pragma;
20741 Check_No_Identifiers;
20742 Check_Arg_Count (1);
20743
20744 Arg := Get_Pragma_Arg (Arg1);
20745
20746 -- The expression must be analyzed in the special manner described
20747 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
20748
20749 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
20750
20751 -- Subprogram case
20752
20753 if Nkind (P) = N_Subprogram_Body then
20754 Check_In_Main_Program;
20755
20756 -- Only Task and subprogram cases allowed
20757
20758 elsif Nkind (P) /= N_Task_Definition then
20759 Pragma_Misplaced;
20760 end if;
20761
20762 -- Check duplicate pragma before we set the corresponding flag
20763
20764 if Has_Relative_Deadline_Pragma (P) then
20765 Error_Pragma ("duplicate pragma% not allowed");
20766 end if;
20767
20768 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
20769 -- Relative_Deadline pragma node cannot be inserted in the Rep
20770 -- Item chain of Ent since it is rewritten by the expander as a
20771 -- procedure call statement that will break the chain.
20772
20773 Set_Has_Relative_Deadline_Pragma (P);
20774 end Relative_Deadline;
20775
20776 ------------------------
20777 -- Remote_Access_Type --
20778 ------------------------
20779
20780 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
20781
20782 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
20783 E : Entity_Id;
20784
20785 begin
20786 GNAT_Pragma;
20787 Check_Arg_Count (1);
20788 Check_Optional_Identifier (Arg1, Name_Entity);
20789 Check_Arg_Is_Local_Name (Arg1);
20790
20791 E := Entity (Get_Pragma_Arg (Arg1));
20792
20793 -- A pragma that applies to a Ghost entity becomes Ghost for the
20794 -- purposes of legality checks and removal of ignored Ghost code.
20795
20796 Mark_Ghost_Pragma (N, E);
20797
20798 if Nkind (Parent (E)) = N_Formal_Type_Declaration
20799 and then Ekind (E) = E_General_Access_Type
20800 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
20801 and then Scope (Root_Type (Directly_Designated_Type (E)))
20802 = Scope (E)
20803 and then Is_Valid_Remote_Object_Type
20804 (Root_Type (Directly_Designated_Type (E)))
20805 then
20806 Set_Is_Remote_Types (E);
20807
20808 else
20809 Error_Pragma_Arg
20810 ("pragma% applies only to formal access-to-class-wide types",
20811 Arg1);
20812 end if;
20813 end Remote_Access_Type;
20814
20815 ---------------------------
20816 -- Remote_Call_Interface --
20817 ---------------------------
20818
20819 -- pragma Remote_Call_Interface [(library_unit_NAME)];
20820
20821 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
20822 Cunit_Node : Node_Id;
20823 Cunit_Ent : Entity_Id;
20824 K : Node_Kind;
20825
20826 begin
20827 Check_Ada_83_Warning;
20828 Check_Valid_Library_Unit_Pragma;
20829
20830 if Nkind (N) = N_Null_Statement then
20831 return;
20832 end if;
20833
20834 Cunit_Node := Cunit (Current_Sem_Unit);
20835 K := Nkind (Unit (Cunit_Node));
20836 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20837
20838 -- A pragma that applies to a Ghost entity becomes Ghost for the
20839 -- purposes of legality checks and removal of ignored Ghost code.
20840
20841 Mark_Ghost_Pragma (N, Cunit_Ent);
20842
20843 if K = N_Package_Declaration
20844 or else K = N_Generic_Package_Declaration
20845 or else K = N_Subprogram_Declaration
20846 or else K = N_Generic_Subprogram_Declaration
20847 or else (K = N_Subprogram_Body
20848 and then Acts_As_Spec (Unit (Cunit_Node)))
20849 then
20850 null;
20851 else
20852 Error_Pragma (
20853 "pragma% must apply to package or subprogram declaration");
20854 end if;
20855
20856 Set_Is_Remote_Call_Interface (Cunit_Ent);
20857 end Remote_Call_Interface;
20858
20859 ------------------
20860 -- Remote_Types --
20861 ------------------
20862
20863 -- pragma Remote_Types [(library_unit_NAME)];
20864
20865 when Pragma_Remote_Types => Remote_Types : declare
20866 Cunit_Node : Node_Id;
20867 Cunit_Ent : Entity_Id;
20868
20869 begin
20870 Check_Ada_83_Warning;
20871 Check_Valid_Library_Unit_Pragma;
20872
20873 if Nkind (N) = N_Null_Statement then
20874 return;
20875 end if;
20876
20877 Cunit_Node := Cunit (Current_Sem_Unit);
20878 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20879
20880 -- A pragma that applies to a Ghost entity becomes Ghost for the
20881 -- purposes of legality checks and removal of ignored Ghost code.
20882
20883 Mark_Ghost_Pragma (N, Cunit_Ent);
20884
20885 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
20886 N_Generic_Package_Declaration)
20887 then
20888 Error_Pragma
20889 ("pragma% can only apply to a package declaration");
20890 end if;
20891
20892 Set_Is_Remote_Types (Cunit_Ent);
20893 end Remote_Types;
20894
20895 ---------------
20896 -- Ravenscar --
20897 ---------------
20898
20899 -- pragma Ravenscar;
20900
20901 when Pragma_Ravenscar =>
20902 GNAT_Pragma;
20903 Check_Arg_Count (0);
20904 Check_Valid_Configuration_Pragma;
20905 Set_Ravenscar_Profile (Ravenscar, N);
20906
20907 if Warn_On_Obsolescent_Feature then
20908 Error_Msg_N
20909 ("pragma Ravenscar is an obsolescent feature?j?", N);
20910 Error_Msg_N
20911 ("|use pragma Profile (Ravenscar) instead?j?", N);
20912 end if;
20913
20914 -------------------------
20915 -- Restricted_Run_Time --
20916 -------------------------
20917
20918 -- pragma Restricted_Run_Time;
20919
20920 when Pragma_Restricted_Run_Time =>
20921 GNAT_Pragma;
20922 Check_Arg_Count (0);
20923 Check_Valid_Configuration_Pragma;
20924 Set_Profile_Restrictions
20925 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
20926
20927 if Warn_On_Obsolescent_Feature then
20928 Error_Msg_N
20929 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
20930 N);
20931 Error_Msg_N
20932 ("|use pragma Profile (Restricted) instead?j?", N);
20933 end if;
20934
20935 ------------------
20936 -- Restrictions --
20937 ------------------
20938
20939 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
20940
20941 -- RESTRICTION ::=
20942 -- restriction_IDENTIFIER
20943 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20944
20945 when Pragma_Restrictions =>
20946 Process_Restrictions_Or_Restriction_Warnings
20947 (Warn => Treat_Restrictions_As_Warnings);
20948
20949 --------------------------
20950 -- Restriction_Warnings --
20951 --------------------------
20952
20953 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
20954
20955 -- RESTRICTION ::=
20956 -- restriction_IDENTIFIER
20957 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20958
20959 when Pragma_Restriction_Warnings =>
20960 GNAT_Pragma;
20961 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
20962
20963 ----------------
20964 -- Reviewable --
20965 ----------------
20966
20967 -- pragma Reviewable;
20968
20969 when Pragma_Reviewable =>
20970 Check_Ada_83_Warning;
20971 Check_Arg_Count (0);
20972
20973 -- Call dummy debugging function rv. This is done to assist front
20974 -- end debugging. By placing a Reviewable pragma in the source
20975 -- program, a breakpoint on rv catches this place in the source,
20976 -- allowing convenient stepping to the point of interest.
20977
20978 rv;
20979
20980 --------------------------
20981 -- Secondary_Stack_Size --
20982 --------------------------
20983
20984 -- pragma Secondary_Stack_Size (EXPRESSION);
20985
20986 when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare
20987 P : constant Node_Id := Parent (N);
20988 Arg : Node_Id;
20989 Ent : Entity_Id;
20990
20991 begin
20992 GNAT_Pragma;
20993 Check_No_Identifiers;
20994 Check_Arg_Count (1);
20995
20996 if Nkind (P) = N_Task_Definition then
20997 Arg := Get_Pragma_Arg (Arg1);
20998 Ent := Defining_Identifier (Parent (P));
20999
21000 -- The expression must be analyzed in the special manner
21001 -- described in "Handling of Default Expressions" in sem.ads.
21002
21003 Preanalyze_Spec_Expression (Arg, Any_Integer);
21004
21005 -- The pragma cannot appear if the No_Secondary_Stack
21006 -- restriction is in effect.
21007
21008 Check_Restriction (No_Secondary_Stack, Arg);
21009
21010 -- Anything else is incorrect
21011
21012 else
21013 Pragma_Misplaced;
21014 end if;
21015
21016 -- Check duplicate pragma before we chain the pragma in the Rep
21017 -- Item chain of Ent.
21018
21019 Check_Duplicate_Pragma (Ent);
21020 Record_Rep_Item (Ent, N);
21021 end Secondary_Stack_Size;
21022
21023 --------------------------
21024 -- Short_Circuit_And_Or --
21025 --------------------------
21026
21027 -- pragma Short_Circuit_And_Or;
21028
21029 when Pragma_Short_Circuit_And_Or =>
21030 GNAT_Pragma;
21031 Check_Arg_Count (0);
21032 Check_Valid_Configuration_Pragma;
21033 Short_Circuit_And_Or := True;
21034
21035 -------------------
21036 -- Share_Generic --
21037 -------------------
21038
21039 -- pragma Share_Generic (GNAME {, GNAME});
21040
21041 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
21042
21043 when Pragma_Share_Generic =>
21044 GNAT_Pragma;
21045 Process_Generic_List;
21046
21047 ------------
21048 -- Shared --
21049 ------------
21050
21051 -- pragma Shared (LOCAL_NAME);
21052
21053 when Pragma_Shared =>
21054 GNAT_Pragma;
21055 Process_Atomic_Independent_Shared_Volatile;
21056
21057 --------------------
21058 -- Shared_Passive --
21059 --------------------
21060
21061 -- pragma Shared_Passive [(library_unit_NAME)];
21062
21063 -- Set the flag Is_Shared_Passive of program unit name entity
21064
21065 when Pragma_Shared_Passive => Shared_Passive : declare
21066 Cunit_Node : Node_Id;
21067 Cunit_Ent : Entity_Id;
21068
21069 begin
21070 Check_Ada_83_Warning;
21071 Check_Valid_Library_Unit_Pragma;
21072
21073 if Nkind (N) = N_Null_Statement then
21074 return;
21075 end if;
21076
21077 Cunit_Node := Cunit (Current_Sem_Unit);
21078 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
21079
21080 -- A pragma that applies to a Ghost entity becomes Ghost for the
21081 -- purposes of legality checks and removal of ignored Ghost code.
21082
21083 Mark_Ghost_Pragma (N, Cunit_Ent);
21084
21085 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
21086 N_Generic_Package_Declaration)
21087 then
21088 Error_Pragma
21089 ("pragma% can only apply to a package declaration");
21090 end if;
21091
21092 Set_Is_Shared_Passive (Cunit_Ent);
21093 end Shared_Passive;
21094
21095 -----------------------
21096 -- Short_Descriptors --
21097 -----------------------
21098
21099 -- pragma Short_Descriptors;
21100
21101 -- Recognize and validate, but otherwise ignore
21102
21103 when Pragma_Short_Descriptors =>
21104 GNAT_Pragma;
21105 Check_Arg_Count (0);
21106 Check_Valid_Configuration_Pragma;
21107
21108 ------------------------------
21109 -- Simple_Storage_Pool_Type --
21110 ------------------------------
21111
21112 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
21113
21114 when Pragma_Simple_Storage_Pool_Type =>
21115 Simple_Storage_Pool_Type : declare
21116 Typ : Entity_Id;
21117 Type_Id : Node_Id;
21118
21119 begin
21120 GNAT_Pragma;
21121 Check_Arg_Count (1);
21122 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21123
21124 Type_Id := Get_Pragma_Arg (Arg1);
21125 Find_Type (Type_Id);
21126 Typ := Entity (Type_Id);
21127
21128 if Typ = Any_Type then
21129 return;
21130 end if;
21131
21132 -- A pragma that applies to a Ghost entity becomes Ghost for the
21133 -- purposes of legality checks and removal of ignored Ghost code.
21134
21135 Mark_Ghost_Pragma (N, Typ);
21136
21137 -- We require the pragma to apply to a type declared in a package
21138 -- declaration, but not (immediately) within a package body.
21139
21140 if Ekind (Current_Scope) /= E_Package
21141 or else In_Package_Body (Current_Scope)
21142 then
21143 Error_Pragma
21144 ("pragma% can only apply to type declared immediately "
21145 & "within a package declaration");
21146 end if;
21147
21148 -- A simple storage pool type must be an immutably limited record
21149 -- or private type. If the pragma is given for a private type,
21150 -- the full type is similarly restricted (which is checked later
21151 -- in Freeze_Entity).
21152
21153 if Is_Record_Type (Typ)
21154 and then not Is_Limited_View (Typ)
21155 then
21156 Error_Pragma
21157 ("pragma% can only apply to explicitly limited record type");
21158
21159 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
21160 Error_Pragma
21161 ("pragma% can only apply to a private type that is limited");
21162
21163 elsif not Is_Record_Type (Typ)
21164 and then not Is_Private_Type (Typ)
21165 then
21166 Error_Pragma
21167 ("pragma% can only apply to limited record or private type");
21168 end if;
21169
21170 Record_Rep_Item (Typ, N);
21171 end Simple_Storage_Pool_Type;
21172
21173 ----------------------
21174 -- Source_File_Name --
21175 ----------------------
21176
21177 -- There are five forms for this pragma:
21178
21179 -- pragma Source_File_Name (
21180 -- [UNIT_NAME =>] unit_NAME,
21181 -- BODY_FILE_NAME => STRING_LITERAL
21182 -- [, [INDEX =>] INTEGER_LITERAL]);
21183
21184 -- pragma Source_File_Name (
21185 -- [UNIT_NAME =>] unit_NAME,
21186 -- SPEC_FILE_NAME => STRING_LITERAL
21187 -- [, [INDEX =>] INTEGER_LITERAL]);
21188
21189 -- pragma Source_File_Name (
21190 -- BODY_FILE_NAME => STRING_LITERAL
21191 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21192 -- [, CASING => CASING_SPEC]);
21193
21194 -- pragma Source_File_Name (
21195 -- SPEC_FILE_NAME => STRING_LITERAL
21196 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21197 -- [, CASING => CASING_SPEC]);
21198
21199 -- pragma Source_File_Name (
21200 -- SUBUNIT_FILE_NAME => STRING_LITERAL
21201 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21202 -- [, CASING => CASING_SPEC]);
21203
21204 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
21205
21206 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
21207 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
21208 -- only be used when no project file is used, while SFNP can only be
21209 -- used when a project file is used.
21210
21211 -- No processing here. Processing was completed during parsing, since
21212 -- we need to have file names set as early as possible. Units are
21213 -- loaded well before semantic processing starts.
21214
21215 -- The only processing we defer to this point is the check for
21216 -- correct placement.
21217
21218 when Pragma_Source_File_Name =>
21219 GNAT_Pragma;
21220 Check_Valid_Configuration_Pragma;
21221
21222 ------------------------------
21223 -- Source_File_Name_Project --
21224 ------------------------------
21225
21226 -- See Source_File_Name for syntax
21227
21228 -- No processing here. Processing was completed during parsing, since
21229 -- we need to have file names set as early as possible. Units are
21230 -- loaded well before semantic processing starts.
21231
21232 -- The only processing we defer to this point is the check for
21233 -- correct placement.
21234
21235 when Pragma_Source_File_Name_Project =>
21236 GNAT_Pragma;
21237 Check_Valid_Configuration_Pragma;
21238
21239 -- Check that a pragma Source_File_Name_Project is used only in a
21240 -- configuration pragmas file.
21241
21242 -- Pragmas Source_File_Name_Project should only be generated by
21243 -- the Project Manager in configuration pragmas files.
21244
21245 -- This is really an ugly test. It seems to depend on some
21246 -- accidental and undocumented property. At the very least it
21247 -- needs to be documented, but it would be better to have a
21248 -- clean way of testing if we are in a configuration file???
21249
21250 if Present (Parent (N)) then
21251 Error_Pragma
21252 ("pragma% can only appear in a configuration pragmas file");
21253 end if;
21254
21255 ----------------------
21256 -- Source_Reference --
21257 ----------------------
21258
21259 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
21260
21261 -- Nothing to do, all processing completed in Par.Prag, since we need
21262 -- the information for possible parser messages that are output.
21263
21264 when Pragma_Source_Reference =>
21265 GNAT_Pragma;
21266
21267 ----------------
21268 -- SPARK_Mode --
21269 ----------------
21270
21271 -- pragma SPARK_Mode [(On | Off)];
21272
21273 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
21274 Mode_Id : SPARK_Mode_Type;
21275
21276 procedure Check_Pragma_Conformance
21277 (Context_Pragma : Node_Id;
21278 Entity : Entity_Id;
21279 Entity_Pragma : Node_Id);
21280 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
21281 -- conformance of pragma N depending the following scenarios:
21282 --
21283 -- If pragma Context_Pragma is not Empty, verify that pragma N is
21284 -- compatible with the pragma Context_Pragma that was inherited
21285 -- from the context:
21286 -- * If the mode of Context_Pragma is ON, then the new mode can
21287 -- be anything.
21288 -- * If the mode of Context_Pragma is OFF, then the only allowed
21289 -- new mode is also OFF. Emit error if this is not the case.
21290 --
21291 -- If Entity is not Empty, verify that pragma N is compatible with
21292 -- pragma Entity_Pragma that belongs to Entity.
21293 -- * If Entity_Pragma is Empty, always issue an error as this
21294 -- corresponds to the case where a previous section of Entity
21295 -- has no SPARK_Mode set.
21296 -- * If the mode of Entity_Pragma is ON, then the new mode can
21297 -- be anything.
21298 -- * If the mode of Entity_Pragma is OFF, then the only allowed
21299 -- new mode is also OFF. Emit error if this is not the case.
21300
21301 procedure Check_Library_Level_Entity (E : Entity_Id);
21302 -- Subsidiary to routines Process_xxx. Verify that the related
21303 -- entity E subject to pragma SPARK_Mode is library-level.
21304
21305 procedure Process_Body (Decl : Node_Id);
21306 -- Verify the legality of pragma SPARK_Mode when it appears as the
21307 -- top of the body declarations of entry, package, protected unit,
21308 -- subprogram or task unit body denoted by Decl.
21309
21310 procedure Process_Overloadable (Decl : Node_Id);
21311 -- Verify the legality of pragma SPARK_Mode when it applies to an
21312 -- entry or [generic] subprogram declaration denoted by Decl.
21313
21314 procedure Process_Private_Part (Decl : Node_Id);
21315 -- Verify the legality of pragma SPARK_Mode when it appears at the
21316 -- top of the private declarations of a package spec, protected or
21317 -- task unit declaration denoted by Decl.
21318
21319 procedure Process_Statement_Part (Decl : Node_Id);
21320 -- Verify the legality of pragma SPARK_Mode when it appears at the
21321 -- top of the statement sequence of a package body denoted by node
21322 -- Decl.
21323
21324 procedure Process_Visible_Part (Decl : Node_Id);
21325 -- Verify the legality of pragma SPARK_Mode when it appears at the
21326 -- top of the visible declarations of a package spec, protected or
21327 -- task unit declaration denoted by Decl. The routine is also used
21328 -- on protected or task units declared without a definition.
21329
21330 procedure Set_SPARK_Context;
21331 -- Subsidiary to routines Process_xxx. Set the global variables
21332 -- which represent the mode of the context from pragma N. Ensure
21333 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
21334
21335 ------------------------------
21336 -- Check_Pragma_Conformance --
21337 ------------------------------
21338
21339 procedure Check_Pragma_Conformance
21340 (Context_Pragma : Node_Id;
21341 Entity : Entity_Id;
21342 Entity_Pragma : Node_Id)
21343 is
21344 Err_Id : Entity_Id;
21345 Err_N : Node_Id;
21346
21347 begin
21348 -- The current pragma may appear without an argument. If this
21349 -- is the case, associate all error messages with the pragma
21350 -- itself.
21351
21352 if Present (Arg1) then
21353 Err_N := Arg1;
21354 else
21355 Err_N := N;
21356 end if;
21357
21358 -- The mode of the current pragma is compared against that of
21359 -- an enclosing context.
21360
21361 if Present (Context_Pragma) then
21362 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
21363
21364 -- Issue an error if the new mode is less restrictive than
21365 -- that of the context.
21366
21367 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
21368 and then Get_SPARK_Mode_From_Annotation (N) = On
21369 then
21370 Error_Msg_N
21371 ("cannot change SPARK_Mode from Off to On", Err_N);
21372 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
21373 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
21374 raise Pragma_Exit;
21375 end if;
21376 end if;
21377
21378 -- The mode of the current pragma is compared against that of
21379 -- an initial package, protected type, subprogram or task type
21380 -- declaration.
21381
21382 if Present (Entity) then
21383
21384 -- A simple protected or task type is transformed into an
21385 -- anonymous type whose name cannot be used to issue error
21386 -- messages. Recover the original entity of the type.
21387
21388 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
21389 Err_Id :=
21390 Defining_Entity
21391 (Original_Node (Unit_Declaration_Node (Entity)));
21392 else
21393 Err_Id := Entity;
21394 end if;
21395
21396 -- Both the initial declaration and the completion carry
21397 -- SPARK_Mode pragmas.
21398
21399 if Present (Entity_Pragma) then
21400 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
21401
21402 -- Issue an error if the new mode is less restrictive
21403 -- than that of the initial declaration.
21404
21405 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
21406 and then Get_SPARK_Mode_From_Annotation (N) = On
21407 then
21408 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
21409 Error_Msg_Sloc := Sloc (Entity_Pragma);
21410 Error_Msg_NE
21411 ("\value Off was set for SPARK_Mode on&#",
21412 Err_N, Err_Id);
21413 raise Pragma_Exit;
21414 end if;
21415
21416 -- Otherwise the initial declaration lacks a SPARK_Mode
21417 -- pragma in which case the current pragma is illegal as
21418 -- it cannot "complete".
21419
21420 else
21421 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
21422 Error_Msg_Sloc := Sloc (Err_Id);
21423 Error_Msg_NE
21424 ("\no value was set for SPARK_Mode on&#",
21425 Err_N, Err_Id);
21426 raise Pragma_Exit;
21427 end if;
21428 end if;
21429 end Check_Pragma_Conformance;
21430
21431 --------------------------------
21432 -- Check_Library_Level_Entity --
21433 --------------------------------
21434
21435 procedure Check_Library_Level_Entity (E : Entity_Id) is
21436 procedure Add_Entity_To_Name_Buffer;
21437 -- Add the E_Kind of entity E to the name buffer
21438
21439 -------------------------------
21440 -- Add_Entity_To_Name_Buffer --
21441 -------------------------------
21442
21443 procedure Add_Entity_To_Name_Buffer is
21444 begin
21445 if Ekind_In (E, E_Entry, E_Entry_Family) then
21446 Add_Str_To_Name_Buffer ("entry");
21447
21448 elsif Ekind_In (E, E_Generic_Package,
21449 E_Package,
21450 E_Package_Body)
21451 then
21452 Add_Str_To_Name_Buffer ("package");
21453
21454 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
21455 Add_Str_To_Name_Buffer ("protected type");
21456
21457 elsif Ekind_In (E, E_Function,
21458 E_Generic_Function,
21459 E_Generic_Procedure,
21460 E_Procedure,
21461 E_Subprogram_Body)
21462 then
21463 Add_Str_To_Name_Buffer ("subprogram");
21464
21465 else
21466 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
21467 Add_Str_To_Name_Buffer ("task type");
21468 end if;
21469 end Add_Entity_To_Name_Buffer;
21470
21471 -- Local variables
21472
21473 Msg_1 : constant String := "incorrect placement of pragma%";
21474 Msg_2 : Name_Id;
21475
21476 -- Start of processing for Check_Library_Level_Entity
21477
21478 begin
21479 if not Is_Library_Level_Entity (E) then
21480 Error_Msg_Name_1 := Pname;
21481 Error_Msg_N (Fix_Error (Msg_1), N);
21482
21483 Name_Len := 0;
21484 Add_Str_To_Name_Buffer ("\& is not a library-level ");
21485 Add_Entity_To_Name_Buffer;
21486
21487 Msg_2 := Name_Find;
21488 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
21489
21490 raise Pragma_Exit;
21491 end if;
21492 end Check_Library_Level_Entity;
21493
21494 ------------------
21495 -- Process_Body --
21496 ------------------
21497
21498 procedure Process_Body (Decl : Node_Id) is
21499 Body_Id : constant Entity_Id := Defining_Entity (Decl);
21500 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
21501
21502 begin
21503 -- Ignore pragma when applied to the special body created for
21504 -- inlining, recognized by its internal name _Parent.
21505
21506 if Chars (Body_Id) = Name_uParent then
21507 return;
21508 end if;
21509
21510 Check_Library_Level_Entity (Body_Id);
21511
21512 -- For entry bodies, verify the legality against:
21513 -- * The mode of the context
21514 -- * The mode of the spec (if any)
21515
21516 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
21517
21518 -- A stand alone subprogram body
21519
21520 if Body_Id = Spec_Id then
21521 Check_Pragma_Conformance
21522 (Context_Pragma => SPARK_Pragma (Body_Id),
21523 Entity => Empty,
21524 Entity_Pragma => Empty);
21525
21526 -- An entry or subprogram body that completes a previous
21527 -- declaration.
21528
21529 else
21530 Check_Pragma_Conformance
21531 (Context_Pragma => SPARK_Pragma (Body_Id),
21532 Entity => Spec_Id,
21533 Entity_Pragma => SPARK_Pragma (Spec_Id));
21534 end if;
21535
21536 Set_SPARK_Context;
21537 Set_SPARK_Pragma (Body_Id, N);
21538 Set_SPARK_Pragma_Inherited (Body_Id, False);
21539
21540 -- For package bodies, verify the legality against:
21541 -- * The mode of the context
21542 -- * The mode of the private part
21543
21544 -- This case is separated from protected and task bodies
21545 -- because the statement part of the package body inherits
21546 -- the mode of the body declarations.
21547
21548 elsif Nkind (Decl) = N_Package_Body then
21549 Check_Pragma_Conformance
21550 (Context_Pragma => SPARK_Pragma (Body_Id),
21551 Entity => Spec_Id,
21552 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
21553
21554 Set_SPARK_Context;
21555 Set_SPARK_Pragma (Body_Id, N);
21556 Set_SPARK_Pragma_Inherited (Body_Id, False);
21557 Set_SPARK_Aux_Pragma (Body_Id, N);
21558 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
21559
21560 -- For protected and task bodies, verify the legality against:
21561 -- * The mode of the context
21562 -- * The mode of the private part
21563
21564 else
21565 pragma Assert
21566 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
21567
21568 Check_Pragma_Conformance
21569 (Context_Pragma => SPARK_Pragma (Body_Id),
21570 Entity => Spec_Id,
21571 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
21572
21573 Set_SPARK_Context;
21574 Set_SPARK_Pragma (Body_Id, N);
21575 Set_SPARK_Pragma_Inherited (Body_Id, False);
21576 end if;
21577 end Process_Body;
21578
21579 --------------------------
21580 -- Process_Overloadable --
21581 --------------------------
21582
21583 procedure Process_Overloadable (Decl : Node_Id) is
21584 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
21585 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
21586
21587 begin
21588 Check_Library_Level_Entity (Spec_Id);
21589
21590 -- Verify the legality against:
21591 -- * The mode of the context
21592
21593 Check_Pragma_Conformance
21594 (Context_Pragma => SPARK_Pragma (Spec_Id),
21595 Entity => Empty,
21596 Entity_Pragma => Empty);
21597
21598 Set_SPARK_Pragma (Spec_Id, N);
21599 Set_SPARK_Pragma_Inherited (Spec_Id, False);
21600
21601 -- When the pragma applies to the anonymous object created for
21602 -- a single task type, decorate the type as well. This scenario
21603 -- arises when the single task type lacks a task definition,
21604 -- therefore there is no issue with respect to a potential
21605 -- pragma SPARK_Mode in the private part.
21606
21607 -- task type Anon_Task_Typ;
21608 -- Obj : Anon_Task_Typ;
21609 -- pragma SPARK_Mode ...;
21610
21611 if Is_Single_Task_Object (Spec_Id) then
21612 Set_SPARK_Pragma (Spec_Typ, N);
21613 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
21614 Set_SPARK_Aux_Pragma (Spec_Typ, N);
21615 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
21616 end if;
21617 end Process_Overloadable;
21618
21619 --------------------------
21620 -- Process_Private_Part --
21621 --------------------------
21622
21623 procedure Process_Private_Part (Decl : Node_Id) is
21624 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
21625
21626 begin
21627 Check_Library_Level_Entity (Spec_Id);
21628
21629 -- Verify the legality against:
21630 -- * The mode of the visible declarations
21631
21632 Check_Pragma_Conformance
21633 (Context_Pragma => Empty,
21634 Entity => Spec_Id,
21635 Entity_Pragma => SPARK_Pragma (Spec_Id));
21636
21637 Set_SPARK_Context;
21638 Set_SPARK_Aux_Pragma (Spec_Id, N);
21639 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
21640 end Process_Private_Part;
21641
21642 ----------------------------
21643 -- Process_Statement_Part --
21644 ----------------------------
21645
21646 procedure Process_Statement_Part (Decl : Node_Id) is
21647 Body_Id : constant Entity_Id := Defining_Entity (Decl);
21648
21649 begin
21650 Check_Library_Level_Entity (Body_Id);
21651
21652 -- Verify the legality against:
21653 -- * The mode of the body declarations
21654
21655 Check_Pragma_Conformance
21656 (Context_Pragma => Empty,
21657 Entity => Body_Id,
21658 Entity_Pragma => SPARK_Pragma (Body_Id));
21659
21660 Set_SPARK_Context;
21661 Set_SPARK_Aux_Pragma (Body_Id, N);
21662 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
21663 end Process_Statement_Part;
21664
21665 --------------------------
21666 -- Process_Visible_Part --
21667 --------------------------
21668
21669 procedure Process_Visible_Part (Decl : Node_Id) is
21670 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
21671 Obj_Id : Entity_Id;
21672
21673 begin
21674 Check_Library_Level_Entity (Spec_Id);
21675
21676 -- Verify the legality against:
21677 -- * The mode of the context
21678
21679 Check_Pragma_Conformance
21680 (Context_Pragma => SPARK_Pragma (Spec_Id),
21681 Entity => Empty,
21682 Entity_Pragma => Empty);
21683
21684 -- A task unit declared without a definition does not set the
21685 -- SPARK_Mode of the context because the task does not have any
21686 -- entries that could inherit the mode.
21687
21688 if not Nkind_In (Decl, N_Single_Task_Declaration,
21689 N_Task_Type_Declaration)
21690 then
21691 Set_SPARK_Context;
21692 end if;
21693
21694 Set_SPARK_Pragma (Spec_Id, N);
21695 Set_SPARK_Pragma_Inherited (Spec_Id, False);
21696 Set_SPARK_Aux_Pragma (Spec_Id, N);
21697 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
21698
21699 -- When the pragma applies to a single protected or task type,
21700 -- decorate the corresponding anonymous object as well.
21701
21702 -- protected Anon_Prot_Typ is
21703 -- pragma SPARK_Mode ...;
21704 -- ...
21705 -- end Anon_Prot_Typ;
21706
21707 -- Obj : Anon_Prot_Typ;
21708
21709 if Is_Single_Concurrent_Type (Spec_Id) then
21710 Obj_Id := Anonymous_Object (Spec_Id);
21711
21712 Set_SPARK_Pragma (Obj_Id, N);
21713 Set_SPARK_Pragma_Inherited (Obj_Id, False);
21714 end if;
21715 end Process_Visible_Part;
21716
21717 -----------------------
21718 -- Set_SPARK_Context --
21719 -----------------------
21720
21721 procedure Set_SPARK_Context is
21722 begin
21723 SPARK_Mode := Mode_Id;
21724 SPARK_Mode_Pragma := N;
21725 end Set_SPARK_Context;
21726
21727 -- Local variables
21728
21729 Context : Node_Id;
21730 Mode : Name_Id;
21731 Stmt : Node_Id;
21732
21733 -- Start of processing for Do_SPARK_Mode
21734
21735 begin
21736 -- When a SPARK_Mode pragma appears inside an instantiation whose
21737 -- enclosing context has SPARK_Mode set to "off", the pragma has
21738 -- no semantic effect.
21739
21740 if Ignore_SPARK_Mode_Pragmas_In_Instance then
21741 Rewrite (N, Make_Null_Statement (Loc));
21742 Analyze (N);
21743 return;
21744 end if;
21745
21746 GNAT_Pragma;
21747 Check_No_Identifiers;
21748 Check_At_Most_N_Arguments (1);
21749
21750 -- Check the legality of the mode (no argument = ON)
21751
21752 if Arg_Count = 1 then
21753 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21754 Mode := Chars (Get_Pragma_Arg (Arg1));
21755 else
21756 Mode := Name_On;
21757 end if;
21758
21759 Mode_Id := Get_SPARK_Mode_Type (Mode);
21760 Context := Parent (N);
21761
21762 -- The pragma appears in a configuration file
21763
21764 if No (Context) then
21765 Check_Valid_Configuration_Pragma;
21766
21767 if Present (SPARK_Mode_Pragma) then
21768 Duplication_Error
21769 (Prag => N,
21770 Prev => SPARK_Mode_Pragma);
21771 raise Pragma_Exit;
21772 end if;
21773
21774 Set_SPARK_Context;
21775
21776 -- The pragma acts as a configuration pragma in a compilation unit
21777
21778 -- pragma SPARK_Mode ...;
21779 -- package Pack is ...;
21780
21781 elsif Nkind (Context) = N_Compilation_Unit
21782 and then List_Containing (N) = Context_Items (Context)
21783 then
21784 Check_Valid_Configuration_Pragma;
21785 Set_SPARK_Context;
21786
21787 -- Otherwise the placement of the pragma within the tree dictates
21788 -- its associated construct. Inspect the declarative list where
21789 -- the pragma resides to find a potential construct.
21790
21791 else
21792 Stmt := Prev (N);
21793 while Present (Stmt) loop
21794
21795 -- Skip prior pragmas, but check for duplicates. Note that
21796 -- this also takes care of pragmas generated for aspects.
21797
21798 if Nkind (Stmt) = N_Pragma then
21799 if Pragma_Name (Stmt) = Pname then
21800 Duplication_Error
21801 (Prag => N,
21802 Prev => Stmt);
21803 raise Pragma_Exit;
21804 end if;
21805
21806 -- The pragma applies to an expression function that has
21807 -- already been rewritten into a subprogram declaration.
21808
21809 -- function Expr_Func return ... is (...);
21810 -- pragma SPARK_Mode ...;
21811
21812 elsif Nkind (Stmt) = N_Subprogram_Declaration
21813 and then Nkind (Original_Node (Stmt)) =
21814 N_Expression_Function
21815 then
21816 Process_Overloadable (Stmt);
21817 return;
21818
21819 -- The pragma applies to the anonymous object created for a
21820 -- single concurrent type.
21821
21822 -- protected type Anon_Prot_Typ ...;
21823 -- Obj : Anon_Prot_Typ;
21824 -- pragma SPARK_Mode ...;
21825
21826 elsif Nkind (Stmt) = N_Object_Declaration
21827 and then Is_Single_Concurrent_Object
21828 (Defining_Entity (Stmt))
21829 then
21830 Process_Overloadable (Stmt);
21831 return;
21832
21833 -- Skip internally generated code
21834
21835 elsif not Comes_From_Source (Stmt) then
21836 null;
21837
21838 -- The pragma applies to an entry or [generic] subprogram
21839 -- declaration.
21840
21841 -- entry Ent ...;
21842 -- pragma SPARK_Mode ...;
21843
21844 -- [generic]
21845 -- procedure Proc ...;
21846 -- pragma SPARK_Mode ...;
21847
21848 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
21849 N_Subprogram_Declaration)
21850 or else (Nkind (Stmt) = N_Entry_Declaration
21851 and then Is_Protected_Type
21852 (Scope (Defining_Entity (Stmt))))
21853 then
21854 Process_Overloadable (Stmt);
21855 return;
21856
21857 -- Otherwise the pragma does not apply to a legal construct
21858 -- or it does not appear at the top of a declarative or a
21859 -- statement list. Issue an error and stop the analysis.
21860
21861 else
21862 Pragma_Misplaced;
21863 exit;
21864 end if;
21865
21866 Prev (Stmt);
21867 end loop;
21868
21869 -- The pragma applies to a package or a subprogram that acts as
21870 -- a compilation unit.
21871
21872 -- procedure Proc ...;
21873 -- pragma SPARK_Mode ...;
21874
21875 if Nkind (Context) = N_Compilation_Unit_Aux then
21876 Context := Unit (Parent (Context));
21877 end if;
21878
21879 -- The pragma appears at the top of entry, package, protected
21880 -- unit, subprogram or task unit body declarations.
21881
21882 -- entry Ent when ... is
21883 -- pragma SPARK_Mode ...;
21884
21885 -- package body Pack is
21886 -- pragma SPARK_Mode ...;
21887
21888 -- procedure Proc ... is
21889 -- pragma SPARK_Mode;
21890
21891 -- protected body Prot is
21892 -- pragma SPARK_Mode ...;
21893
21894 if Nkind_In (Context, N_Entry_Body,
21895 N_Package_Body,
21896 N_Protected_Body,
21897 N_Subprogram_Body,
21898 N_Task_Body)
21899 then
21900 Process_Body (Context);
21901
21902 -- The pragma appears at the top of the visible or private
21903 -- declaration of a package spec, protected or task unit.
21904
21905 -- package Pack is
21906 -- pragma SPARK_Mode ...;
21907 -- private
21908 -- pragma SPARK_Mode ...;
21909
21910 -- protected [type] Prot is
21911 -- pragma SPARK_Mode ...;
21912 -- private
21913 -- pragma SPARK_Mode ...;
21914
21915 elsif Nkind_In (Context, N_Package_Specification,
21916 N_Protected_Definition,
21917 N_Task_Definition)
21918 then
21919 if List_Containing (N) = Visible_Declarations (Context) then
21920 Process_Visible_Part (Parent (Context));
21921 else
21922 Process_Private_Part (Parent (Context));
21923 end if;
21924
21925 -- The pragma appears at the top of package body statements
21926
21927 -- package body Pack is
21928 -- begin
21929 -- pragma SPARK_Mode;
21930
21931 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
21932 and then Nkind (Parent (Context)) = N_Package_Body
21933 then
21934 Process_Statement_Part (Parent (Context));
21935
21936 -- The pragma appeared as an aspect of a [generic] subprogram
21937 -- declaration that acts as a compilation unit.
21938
21939 -- [generic]
21940 -- procedure Proc ...;
21941 -- pragma SPARK_Mode ...;
21942
21943 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
21944 N_Subprogram_Declaration)
21945 then
21946 Process_Overloadable (Context);
21947
21948 -- The pragma does not apply to a legal construct, issue error
21949
21950 else
21951 Pragma_Misplaced;
21952 end if;
21953 end if;
21954 end Do_SPARK_Mode;
21955
21956 --------------------------------
21957 -- Static_Elaboration_Desired --
21958 --------------------------------
21959
21960 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
21961
21962 when Pragma_Static_Elaboration_Desired =>
21963 GNAT_Pragma;
21964 Check_At_Most_N_Arguments (1);
21965
21966 if Is_Compilation_Unit (Current_Scope)
21967 and then Ekind (Current_Scope) = E_Package
21968 then
21969 Set_Static_Elaboration_Desired (Current_Scope, True);
21970 else
21971 Error_Pragma ("pragma% must apply to a library-level package");
21972 end if;
21973
21974 ------------------
21975 -- Storage_Size --
21976 ------------------
21977
21978 -- pragma Storage_Size (EXPRESSION);
21979
21980 when Pragma_Storage_Size => Storage_Size : declare
21981 P : constant Node_Id := Parent (N);
21982 Arg : Node_Id;
21983
21984 begin
21985 Check_No_Identifiers;
21986 Check_Arg_Count (1);
21987
21988 -- The expression must be analyzed in the special manner described
21989 -- in "Handling of Default Expressions" in sem.ads.
21990
21991 Arg := Get_Pragma_Arg (Arg1);
21992 Preanalyze_Spec_Expression (Arg, Any_Integer);
21993
21994 if not Is_OK_Static_Expression (Arg) then
21995 Check_Restriction (Static_Storage_Size, Arg);
21996 end if;
21997
21998 if Nkind (P) /= N_Task_Definition then
21999 Pragma_Misplaced;
22000 return;
22001
22002 else
22003 if Has_Storage_Size_Pragma (P) then
22004 Error_Pragma ("duplicate pragma% not allowed");
22005 else
22006 Set_Has_Storage_Size_Pragma (P, True);
22007 end if;
22008
22009 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
22010 end if;
22011 end Storage_Size;
22012
22013 ------------------
22014 -- Storage_Unit --
22015 ------------------
22016
22017 -- pragma Storage_Unit (NUMERIC_LITERAL);
22018
22019 -- Only permitted argument is System'Storage_Unit value
22020
22021 when Pragma_Storage_Unit =>
22022 Check_No_Identifiers;
22023 Check_Arg_Count (1);
22024 Check_Arg_Is_Integer_Literal (Arg1);
22025
22026 if Intval (Get_Pragma_Arg (Arg1)) /=
22027 UI_From_Int (Ttypes.System_Storage_Unit)
22028 then
22029 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
22030 Error_Pragma_Arg
22031 ("the only allowed argument for pragma% is ^", Arg1);
22032 end if;
22033
22034 --------------------
22035 -- Stream_Convert --
22036 --------------------
22037
22038 -- pragma Stream_Convert (
22039 -- [Entity =>] type_LOCAL_NAME,
22040 -- [Read =>] function_NAME,
22041 -- [Write =>] function NAME);
22042
22043 when Pragma_Stream_Convert => Stream_Convert : declare
22044 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
22045 -- Check that the given argument is the name of a local function
22046 -- of one argument that is not overloaded earlier in the current
22047 -- local scope. A check is also made that the argument is a
22048 -- function with one parameter.
22049
22050 --------------------------------------
22051 -- Check_OK_Stream_Convert_Function --
22052 --------------------------------------
22053
22054 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
22055 Ent : Entity_Id;
22056
22057 begin
22058 Check_Arg_Is_Local_Name (Arg);
22059 Ent := Entity (Get_Pragma_Arg (Arg));
22060
22061 if Has_Homonym (Ent) then
22062 Error_Pragma_Arg
22063 ("argument for pragma% may not be overloaded", Arg);
22064 end if;
22065
22066 if Ekind (Ent) /= E_Function
22067 or else No (First_Formal (Ent))
22068 or else Present (Next_Formal (First_Formal (Ent)))
22069 then
22070 Error_Pragma_Arg
22071 ("argument for pragma% must be function of one argument",
22072 Arg);
22073 end if;
22074 end Check_OK_Stream_Convert_Function;
22075
22076 -- Start of processing for Stream_Convert
22077
22078 begin
22079 GNAT_Pragma;
22080 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
22081 Check_Arg_Count (3);
22082 Check_Optional_Identifier (Arg1, Name_Entity);
22083 Check_Optional_Identifier (Arg2, Name_Read);
22084 Check_Optional_Identifier (Arg3, Name_Write);
22085 Check_Arg_Is_Local_Name (Arg1);
22086 Check_OK_Stream_Convert_Function (Arg2);
22087 Check_OK_Stream_Convert_Function (Arg3);
22088
22089 declare
22090 Typ : constant Entity_Id :=
22091 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
22092 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
22093 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
22094
22095 begin
22096 Check_First_Subtype (Arg1);
22097
22098 -- Check for too early or too late. Note that we don't enforce
22099 -- the rule about primitive operations in this case, since, as
22100 -- is the case for explicit stream attributes themselves, these
22101 -- restrictions are not appropriate. Note that the chaining of
22102 -- the pragma by Rep_Item_Too_Late is actually the critical
22103 -- processing done for this pragma.
22104
22105 if Rep_Item_Too_Early (Typ, N)
22106 or else
22107 Rep_Item_Too_Late (Typ, N, FOnly => True)
22108 then
22109 return;
22110 end if;
22111
22112 -- Return if previous error
22113
22114 if Etype (Typ) = Any_Type
22115 or else
22116 Etype (Read) = Any_Type
22117 or else
22118 Etype (Write) = Any_Type
22119 then
22120 return;
22121 end if;
22122
22123 -- Error checks
22124
22125 if Underlying_Type (Etype (Read)) /= Typ then
22126 Error_Pragma_Arg
22127 ("incorrect return type for function&", Arg2);
22128 end if;
22129
22130 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
22131 Error_Pragma_Arg
22132 ("incorrect parameter type for function&", Arg3);
22133 end if;
22134
22135 if Underlying_Type (Etype (First_Formal (Read))) /=
22136 Underlying_Type (Etype (Write))
22137 then
22138 Error_Pragma_Arg
22139 ("result type of & does not match Read parameter type",
22140 Arg3);
22141 end if;
22142 end;
22143 end Stream_Convert;
22144
22145 ------------------
22146 -- Style_Checks --
22147 ------------------
22148
22149 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22150
22151 -- This is processed by the parser since some of the style checks
22152 -- take place during source scanning and parsing. This means that
22153 -- we don't need to issue error messages here.
22154
22155 when Pragma_Style_Checks => Style_Checks : declare
22156 A : constant Node_Id := Get_Pragma_Arg (Arg1);
22157 S : String_Id;
22158 C : Char_Code;
22159
22160 begin
22161 GNAT_Pragma;
22162 Check_No_Identifiers;
22163
22164 -- Two argument form
22165
22166 if Arg_Count = 2 then
22167 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
22168
22169 declare
22170 E_Id : Node_Id;
22171 E : Entity_Id;
22172
22173 begin
22174 E_Id := Get_Pragma_Arg (Arg2);
22175 Analyze (E_Id);
22176
22177 if not Is_Entity_Name (E_Id) then
22178 Error_Pragma_Arg
22179 ("second argument of pragma% must be entity name",
22180 Arg2);
22181 end if;
22182
22183 E := Entity (E_Id);
22184
22185 if not Ignore_Style_Checks_Pragmas then
22186 if E = Any_Id then
22187 return;
22188 else
22189 loop
22190 Set_Suppress_Style_Checks
22191 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
22192 exit when No (Homonym (E));
22193 E := Homonym (E);
22194 end loop;
22195 end if;
22196 end if;
22197 end;
22198
22199 -- One argument form
22200
22201 else
22202 Check_Arg_Count (1);
22203
22204 if Nkind (A) = N_String_Literal then
22205 S := Strval (A);
22206
22207 declare
22208 Slen : constant Natural := Natural (String_Length (S));
22209 Options : String (1 .. Slen);
22210 J : Positive;
22211
22212 begin
22213 J := 1;
22214 loop
22215 C := Get_String_Char (S, Pos (J));
22216 exit when not In_Character_Range (C);
22217 Options (J) := Get_Character (C);
22218
22219 -- If at end of string, set options. As per discussion
22220 -- above, no need to check for errors, since we issued
22221 -- them in the parser.
22222
22223 if J = Slen then
22224 if not Ignore_Style_Checks_Pragmas then
22225 Set_Style_Check_Options (Options);
22226 end if;
22227
22228 exit;
22229 end if;
22230
22231 J := J + 1;
22232 end loop;
22233 end;
22234
22235 elsif Nkind (A) = N_Identifier then
22236 if Chars (A) = Name_All_Checks then
22237 if not Ignore_Style_Checks_Pragmas then
22238 if GNAT_Mode then
22239 Set_GNAT_Style_Check_Options;
22240 else
22241 Set_Default_Style_Check_Options;
22242 end if;
22243 end if;
22244
22245 elsif Chars (A) = Name_On then
22246 if not Ignore_Style_Checks_Pragmas then
22247 Style_Check := True;
22248 end if;
22249
22250 elsif Chars (A) = Name_Off then
22251 if not Ignore_Style_Checks_Pragmas then
22252 Style_Check := False;
22253 end if;
22254 end if;
22255 end if;
22256 end if;
22257 end Style_Checks;
22258
22259 --------------
22260 -- Subtitle --
22261 --------------
22262
22263 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
22264
22265 when Pragma_Subtitle =>
22266 GNAT_Pragma;
22267 Check_Arg_Count (1);
22268 Check_Optional_Identifier (Arg1, Name_Subtitle);
22269 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
22270 Store_Note (N);
22271
22272 --------------
22273 -- Suppress --
22274 --------------
22275
22276 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
22277
22278 when Pragma_Suppress =>
22279 Process_Suppress_Unsuppress (Suppress_Case => True);
22280
22281 ------------------
22282 -- Suppress_All --
22283 ------------------
22284
22285 -- pragma Suppress_All;
22286
22287 -- The only check made here is that the pragma has no arguments.
22288 -- There are no placement rules, and the processing required (setting
22289 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
22290 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
22291 -- then creates and inserts a pragma Suppress (All_Checks).
22292
22293 when Pragma_Suppress_All =>
22294 GNAT_Pragma;
22295 Check_Arg_Count (0);
22296
22297 -------------------------
22298 -- Suppress_Debug_Info --
22299 -------------------------
22300
22301 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
22302
22303 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
22304 Nam_Id : Entity_Id;
22305
22306 begin
22307 GNAT_Pragma;
22308 Check_Arg_Count (1);
22309 Check_Optional_Identifier (Arg1, Name_Entity);
22310 Check_Arg_Is_Local_Name (Arg1);
22311
22312 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
22313
22314 -- A pragma that applies to a Ghost entity becomes Ghost for the
22315 -- purposes of legality checks and removal of ignored Ghost code.
22316
22317 Mark_Ghost_Pragma (N, Nam_Id);
22318 Set_Debug_Info_Off (Nam_Id);
22319 end Suppress_Debug_Info;
22320
22321 ----------------------------------
22322 -- Suppress_Exception_Locations --
22323 ----------------------------------
22324
22325 -- pragma Suppress_Exception_Locations;
22326
22327 when Pragma_Suppress_Exception_Locations =>
22328 GNAT_Pragma;
22329 Check_Arg_Count (0);
22330 Check_Valid_Configuration_Pragma;
22331 Exception_Locations_Suppressed := True;
22332
22333 -----------------------------
22334 -- Suppress_Initialization --
22335 -----------------------------
22336
22337 -- pragma Suppress_Initialization ([Entity =>] type_Name);
22338
22339 when Pragma_Suppress_Initialization => Suppress_Init : declare
22340 E : Entity_Id;
22341 E_Id : Node_Id;
22342
22343 begin
22344 GNAT_Pragma;
22345 Check_Arg_Count (1);
22346 Check_Optional_Identifier (Arg1, Name_Entity);
22347 Check_Arg_Is_Local_Name (Arg1);
22348
22349 E_Id := Get_Pragma_Arg (Arg1);
22350
22351 if Etype (E_Id) = Any_Type then
22352 return;
22353 end if;
22354
22355 E := Entity (E_Id);
22356
22357 -- A pragma that applies to a Ghost entity becomes Ghost for the
22358 -- purposes of legality checks and removal of ignored Ghost code.
22359
22360 Mark_Ghost_Pragma (N, E);
22361
22362 if not Is_Type (E) and then Ekind (E) /= E_Variable then
22363 Error_Pragma_Arg
22364 ("pragma% requires variable, type or subtype", Arg1);
22365 end if;
22366
22367 if Rep_Item_Too_Early (E, N)
22368 or else
22369 Rep_Item_Too_Late (E, N, FOnly => True)
22370 then
22371 return;
22372 end if;
22373
22374 -- For incomplete/private type, set flag on full view
22375
22376 if Is_Incomplete_Or_Private_Type (E) then
22377 if No (Full_View (Base_Type (E))) then
22378 Error_Pragma_Arg
22379 ("argument of pragma% cannot be an incomplete type", Arg1);
22380 else
22381 Set_Suppress_Initialization (Full_View (Base_Type (E)));
22382 end if;
22383
22384 -- For first subtype, set flag on base type
22385
22386 elsif Is_First_Subtype (E) then
22387 Set_Suppress_Initialization (Base_Type (E));
22388
22389 -- For other than first subtype, set flag on subtype or variable
22390
22391 else
22392 Set_Suppress_Initialization (E);
22393 end if;
22394 end Suppress_Init;
22395
22396 -----------------
22397 -- System_Name --
22398 -----------------
22399
22400 -- pragma System_Name (DIRECT_NAME);
22401
22402 -- Syntax check: one argument, which must be the identifier GNAT or
22403 -- the identifier GCC, no other identifiers are acceptable.
22404
22405 when Pragma_System_Name =>
22406 GNAT_Pragma;
22407 Check_No_Identifiers;
22408 Check_Arg_Count (1);
22409 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
22410
22411 -----------------------------
22412 -- Task_Dispatching_Policy --
22413 -----------------------------
22414
22415 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
22416
22417 when Pragma_Task_Dispatching_Policy => declare
22418 DP : Character;
22419
22420 begin
22421 Check_Ada_83_Warning;
22422 Check_Arg_Count (1);
22423 Check_No_Identifiers;
22424 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
22425 Check_Valid_Configuration_Pragma;
22426 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22427 DP := Fold_Upper (Name_Buffer (1));
22428
22429 if Task_Dispatching_Policy /= ' '
22430 and then Task_Dispatching_Policy /= DP
22431 then
22432 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
22433 Error_Pragma
22434 ("task dispatching policy incompatible with policy#");
22435
22436 -- Set new policy, but always preserve System_Location since we
22437 -- like the error message with the run time name.
22438
22439 else
22440 Task_Dispatching_Policy := DP;
22441
22442 if Task_Dispatching_Policy_Sloc /= System_Location then
22443 Task_Dispatching_Policy_Sloc := Loc;
22444 end if;
22445 end if;
22446 end;
22447
22448 ---------------
22449 -- Task_Info --
22450 ---------------
22451
22452 -- pragma Task_Info (EXPRESSION);
22453
22454 when Pragma_Task_Info => Task_Info : declare
22455 P : constant Node_Id := Parent (N);
22456 Ent : Entity_Id;
22457
22458 begin
22459 GNAT_Pragma;
22460
22461 if Warn_On_Obsolescent_Feature then
22462 Error_Msg_N
22463 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
22464 & "instead?j?", N);
22465 end if;
22466
22467 if Nkind (P) /= N_Task_Definition then
22468 Error_Pragma ("pragma% must appear in task definition");
22469 end if;
22470
22471 Check_No_Identifiers;
22472 Check_Arg_Count (1);
22473
22474 Analyze_And_Resolve
22475 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
22476
22477 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
22478 return;
22479 end if;
22480
22481 Ent := Defining_Identifier (Parent (P));
22482
22483 -- Check duplicate pragma before we chain the pragma in the Rep
22484 -- Item chain of Ent.
22485
22486 if Has_Rep_Pragma
22487 (Ent, Name_Task_Info, Check_Parents => False)
22488 then
22489 Error_Pragma ("duplicate pragma% not allowed");
22490 end if;
22491
22492 Record_Rep_Item (Ent, N);
22493 end Task_Info;
22494
22495 ---------------
22496 -- Task_Name --
22497 ---------------
22498
22499 -- pragma Task_Name (string_EXPRESSION);
22500
22501 when Pragma_Task_Name => Task_Name : declare
22502 P : constant Node_Id := Parent (N);
22503 Arg : Node_Id;
22504 Ent : Entity_Id;
22505
22506 begin
22507 Check_No_Identifiers;
22508 Check_Arg_Count (1);
22509
22510 Arg := Get_Pragma_Arg (Arg1);
22511
22512 -- The expression is used in the call to Create_Task, and must be
22513 -- expanded there, not in the context of the current spec. It must
22514 -- however be analyzed to capture global references, in case it
22515 -- appears in a generic context.
22516
22517 Preanalyze_And_Resolve (Arg, Standard_String);
22518
22519 if Nkind (P) /= N_Task_Definition then
22520 Pragma_Misplaced;
22521 end if;
22522
22523 Ent := Defining_Identifier (Parent (P));
22524
22525 -- Check duplicate pragma before we chain the pragma in the Rep
22526 -- Item chain of Ent.
22527
22528 if Has_Rep_Pragma
22529 (Ent, Name_Task_Name, Check_Parents => False)
22530 then
22531 Error_Pragma ("duplicate pragma% not allowed");
22532 end if;
22533
22534 Record_Rep_Item (Ent, N);
22535 end Task_Name;
22536
22537 ------------------
22538 -- Task_Storage --
22539 ------------------
22540
22541 -- pragma Task_Storage (
22542 -- [Task_Type =>] LOCAL_NAME,
22543 -- [Top_Guard =>] static_integer_EXPRESSION);
22544
22545 when Pragma_Task_Storage => Task_Storage : declare
22546 Args : Args_List (1 .. 2);
22547 Names : constant Name_List (1 .. 2) := (
22548 Name_Task_Type,
22549 Name_Top_Guard);
22550
22551 Task_Type : Node_Id renames Args (1);
22552 Top_Guard : Node_Id renames Args (2);
22553
22554 Ent : Entity_Id;
22555
22556 begin
22557 GNAT_Pragma;
22558 Gather_Associations (Names, Args);
22559
22560 if No (Task_Type) then
22561 Error_Pragma
22562 ("missing task_type argument for pragma%");
22563 end if;
22564
22565 Check_Arg_Is_Local_Name (Task_Type);
22566
22567 Ent := Entity (Task_Type);
22568
22569 if not Is_Task_Type (Ent) then
22570 Error_Pragma_Arg
22571 ("argument for pragma% must be task type", Task_Type);
22572 end if;
22573
22574 if No (Top_Guard) then
22575 Error_Pragma_Arg
22576 ("pragma% takes two arguments", Task_Type);
22577 else
22578 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
22579 end if;
22580
22581 Check_First_Subtype (Task_Type);
22582
22583 if Rep_Item_Too_Late (Ent, N) then
22584 raise Pragma_Exit;
22585 end if;
22586 end Task_Storage;
22587
22588 ---------------
22589 -- Test_Case --
22590 ---------------
22591
22592 -- pragma Test_Case
22593 -- ([Name =>] Static_String_EXPRESSION
22594 -- ,[Mode =>] MODE_TYPE
22595 -- [, Requires => Boolean_EXPRESSION]
22596 -- [, Ensures => Boolean_EXPRESSION]);
22597
22598 -- MODE_TYPE ::= Nominal | Robustness
22599
22600 -- Characteristics:
22601
22602 -- * Analysis - The annotation undergoes initial checks to verify
22603 -- the legal placement and context. Secondary checks preanalyze the
22604 -- expressions in:
22605
22606 -- Analyze_Test_Case_In_Decl_Part
22607
22608 -- * Expansion - None.
22609
22610 -- * Template - The annotation utilizes the generic template of the
22611 -- related subprogram when it is:
22612
22613 -- aspect on subprogram declaration
22614
22615 -- The annotation must prepare its own template when it is:
22616
22617 -- pragma on subprogram declaration
22618
22619 -- * Globals - Capture of global references must occur after full
22620 -- analysis.
22621
22622 -- * Instance - The annotation is instantiated automatically when
22623 -- the related generic subprogram is instantiated except for the
22624 -- "pragma on subprogram declaration" case. In that scenario the
22625 -- annotation must instantiate itself.
22626
22627 when Pragma_Test_Case => Test_Case : declare
22628 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
22629 -- Ensure that the contract of subprogram Subp_Id does not contain
22630 -- another Test_Case pragma with the same Name as the current one.
22631
22632 -------------------------
22633 -- Check_Distinct_Name --
22634 -------------------------
22635
22636 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
22637 Items : constant Node_Id := Contract (Subp_Id);
22638 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
22639 Prag : Node_Id;
22640
22641 begin
22642 -- Inspect all Test_Case pragma of the related subprogram
22643 -- looking for one with a duplicate "Name" argument.
22644
22645 if Present (Items) then
22646 Prag := Contract_Test_Cases (Items);
22647 while Present (Prag) loop
22648 if Pragma_Name (Prag) = Name_Test_Case
22649 and then Prag /= N
22650 and then String_Equal
22651 (Name, Get_Name_From_CTC_Pragma (Prag))
22652 then
22653 Error_Msg_Sloc := Sloc (Prag);
22654 Error_Pragma ("name for pragma % is already used #");
22655 end if;
22656
22657 Prag := Next_Pragma (Prag);
22658 end loop;
22659 end if;
22660 end Check_Distinct_Name;
22661
22662 -- Local variables
22663
22664 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
22665 Asp_Arg : Node_Id;
22666 Context : Node_Id;
22667 Subp_Decl : Node_Id;
22668 Subp_Id : Entity_Id;
22669
22670 -- Start of processing for Test_Case
22671
22672 begin
22673 GNAT_Pragma;
22674 Check_At_Least_N_Arguments (2);
22675 Check_At_Most_N_Arguments (4);
22676 Check_Arg_Order
22677 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
22678
22679 -- Argument "Name"
22680
22681 Check_Optional_Identifier (Arg1, Name_Name);
22682 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
22683
22684 -- Argument "Mode"
22685
22686 Check_Optional_Identifier (Arg2, Name_Mode);
22687 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
22688
22689 -- Arguments "Requires" and "Ensures"
22690
22691 if Present (Arg3) then
22692 if Present (Arg4) then
22693 Check_Identifier (Arg3, Name_Requires);
22694 Check_Identifier (Arg4, Name_Ensures);
22695 else
22696 Check_Identifier_Is_One_Of
22697 (Arg3, Name_Requires, Name_Ensures);
22698 end if;
22699 end if;
22700
22701 -- Pragma Test_Case must be associated with a subprogram declared
22702 -- in a library-level package. First determine whether the current
22703 -- compilation unit is a legal context.
22704
22705 if Nkind_In (Pack_Decl, N_Package_Declaration,
22706 N_Generic_Package_Declaration)
22707 then
22708 null;
22709
22710 -- Otherwise the placement is illegal
22711
22712 else
22713 Error_Pragma
22714 ("pragma % must be specified within a package declaration");
22715 return;
22716 end if;
22717
22718 Subp_Decl := Find_Related_Declaration_Or_Body (N);
22719
22720 -- Find the enclosing context
22721
22722 Context := Parent (Subp_Decl);
22723
22724 if Present (Context) then
22725 Context := Parent (Context);
22726 end if;
22727
22728 -- Verify the placement of the pragma
22729
22730 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
22731 Error_Pragma
22732 ("pragma % cannot be applied to abstract subprogram");
22733 return;
22734
22735 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
22736 Error_Pragma ("pragma % cannot be applied to entry");
22737 return;
22738
22739 -- The context is a [generic] subprogram declared at the top level
22740 -- of the [generic] package unit.
22741
22742 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
22743 N_Subprogram_Declaration)
22744 and then Present (Context)
22745 and then Nkind_In (Context, N_Generic_Package_Declaration,
22746 N_Package_Declaration)
22747 then
22748 null;
22749
22750 -- Otherwise the placement is illegal
22751
22752 else
22753 Error_Pragma
22754 ("pragma % must be applied to a library-level subprogram "
22755 & "declaration");
22756 return;
22757 end if;
22758
22759 Subp_Id := Defining_Entity (Subp_Decl);
22760
22761 -- A pragma that applies to a Ghost entity becomes Ghost for the
22762 -- purposes of legality checks and removal of ignored Ghost code.
22763
22764 Mark_Ghost_Pragma (N, Subp_Id);
22765
22766 -- Chain the pragma on the contract for further processing by
22767 -- Analyze_Test_Case_In_Decl_Part.
22768
22769 Add_Contract_Item (N, Subp_Id);
22770
22771 -- Preanalyze the original aspect argument "Name" for ASIS or for
22772 -- a generic subprogram to properly capture global references.
22773
22774 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
22775 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
22776
22777 if Present (Asp_Arg) then
22778
22779 -- The argument appears with an identifier in association
22780 -- form.
22781
22782 if Nkind (Asp_Arg) = N_Component_Association then
22783 Asp_Arg := Expression (Asp_Arg);
22784 end if;
22785
22786 Check_Expr_Is_OK_Static_Expression
22787 (Asp_Arg, Standard_String);
22788 end if;
22789 end if;
22790
22791 -- Ensure that the all Test_Case pragmas of the related subprogram
22792 -- have distinct names.
22793
22794 Check_Distinct_Name (Subp_Id);
22795
22796 -- Fully analyze the pragma when it appears inside an entry
22797 -- or subprogram body because it cannot benefit from forward
22798 -- references.
22799
22800 if Nkind_In (Subp_Decl, N_Entry_Body,
22801 N_Subprogram_Body,
22802 N_Subprogram_Body_Stub)
22803 then
22804 -- The legality checks of pragma Test_Case are affected by the
22805 -- SPARK mode in effect and the volatility of the context.
22806 -- Analyze all pragmas in a specific order.
22807
22808 Analyze_If_Present (Pragma_SPARK_Mode);
22809 Analyze_If_Present (Pragma_Volatile_Function);
22810 Analyze_Test_Case_In_Decl_Part (N);
22811 end if;
22812 end Test_Case;
22813
22814 --------------------------
22815 -- Thread_Local_Storage --
22816 --------------------------
22817
22818 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
22819
22820 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
22821 E : Entity_Id;
22822 Id : Node_Id;
22823
22824 begin
22825 GNAT_Pragma;
22826 Check_Arg_Count (1);
22827 Check_Optional_Identifier (Arg1, Name_Entity);
22828 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22829
22830 Id := Get_Pragma_Arg (Arg1);
22831 Analyze (Id);
22832
22833 if not Is_Entity_Name (Id)
22834 or else Ekind (Entity (Id)) /= E_Variable
22835 then
22836 Error_Pragma_Arg ("local variable name required", Arg1);
22837 end if;
22838
22839 E := Entity (Id);
22840
22841 -- A pragma that applies to a Ghost entity becomes Ghost for the
22842 -- purposes of legality checks and removal of ignored Ghost code.
22843
22844 Mark_Ghost_Pragma (N, E);
22845
22846 if Rep_Item_Too_Early (E, N)
22847 or else
22848 Rep_Item_Too_Late (E, N)
22849 then
22850 raise Pragma_Exit;
22851 end if;
22852
22853 Set_Has_Pragma_Thread_Local_Storage (E);
22854 Set_Has_Gigi_Rep_Item (E);
22855 end Thread_Local_Storage;
22856
22857 ----------------
22858 -- Time_Slice --
22859 ----------------
22860
22861 -- pragma Time_Slice (static_duration_EXPRESSION);
22862
22863 when Pragma_Time_Slice => Time_Slice : declare
22864 Val : Ureal;
22865 Nod : Node_Id;
22866
22867 begin
22868 GNAT_Pragma;
22869 Check_Arg_Count (1);
22870 Check_No_Identifiers;
22871 Check_In_Main_Program;
22872 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
22873
22874 if not Error_Posted (Arg1) then
22875 Nod := Next (N);
22876 while Present (Nod) loop
22877 if Nkind (Nod) = N_Pragma
22878 and then Pragma_Name (Nod) = Name_Time_Slice
22879 then
22880 Error_Msg_Name_1 := Pname;
22881 Error_Msg_N ("duplicate pragma% not permitted", Nod);
22882 end if;
22883
22884 Next (Nod);
22885 end loop;
22886 end if;
22887
22888 -- Process only if in main unit
22889
22890 if Get_Source_Unit (Loc) = Main_Unit then
22891 Opt.Time_Slice_Set := True;
22892 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
22893
22894 if Val <= Ureal_0 then
22895 Opt.Time_Slice_Value := 0;
22896
22897 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
22898 Opt.Time_Slice_Value := 1_000_000_000;
22899
22900 else
22901 Opt.Time_Slice_Value :=
22902 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
22903 end if;
22904 end if;
22905 end Time_Slice;
22906
22907 -----------
22908 -- Title --
22909 -----------
22910
22911 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
22912
22913 -- TITLING_OPTION ::=
22914 -- [Title =>] STRING_LITERAL
22915 -- | [Subtitle =>] STRING_LITERAL
22916
22917 when Pragma_Title => Title : declare
22918 Args : Args_List (1 .. 2);
22919 Names : constant Name_List (1 .. 2) := (
22920 Name_Title,
22921 Name_Subtitle);
22922
22923 begin
22924 GNAT_Pragma;
22925 Gather_Associations (Names, Args);
22926 Store_Note (N);
22927
22928 for J in 1 .. 2 loop
22929 if Present (Args (J)) then
22930 Check_Arg_Is_OK_Static_Expression
22931 (Args (J), Standard_String);
22932 end if;
22933 end loop;
22934 end Title;
22935
22936 ----------------------------
22937 -- Type_Invariant[_Class] --
22938 ----------------------------
22939
22940 -- pragma Type_Invariant[_Class]
22941 -- ([Entity =>] type_LOCAL_NAME,
22942 -- [Check =>] EXPRESSION);
22943
22944 when Pragma_Type_Invariant
22945 | Pragma_Type_Invariant_Class
22946 =>
22947 Type_Invariant : declare
22948 I_Pragma : Node_Id;
22949
22950 begin
22951 Check_Arg_Count (2);
22952
22953 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
22954 -- setting Class_Present for the Type_Invariant_Class case.
22955
22956 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
22957 I_Pragma := New_Copy (N);
22958 Set_Pragma_Identifier
22959 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
22960 Rewrite (N, I_Pragma);
22961 Set_Analyzed (N, False);
22962 Analyze (N);
22963 end Type_Invariant;
22964
22965 ---------------------
22966 -- Unchecked_Union --
22967 ---------------------
22968
22969 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
22970
22971 when Pragma_Unchecked_Union => Unchecked_Union : declare
22972 Assoc : constant Node_Id := Arg1;
22973 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
22974 Clist : Node_Id;
22975 Comp : Node_Id;
22976 Tdef : Node_Id;
22977 Typ : Entity_Id;
22978 Variant : Node_Id;
22979 Vpart : Node_Id;
22980
22981 begin
22982 Ada_2005_Pragma;
22983 Check_No_Identifiers;
22984 Check_Arg_Count (1);
22985 Check_Arg_Is_Local_Name (Arg1);
22986
22987 Find_Type (Type_Id);
22988
22989 Typ := Entity (Type_Id);
22990
22991 -- A pragma that applies to a Ghost entity becomes Ghost for the
22992 -- purposes of legality checks and removal of ignored Ghost code.
22993
22994 Mark_Ghost_Pragma (N, Typ);
22995
22996 if Typ = Any_Type
22997 or else Rep_Item_Too_Early (Typ, N)
22998 then
22999 return;
23000 else
23001 Typ := Underlying_Type (Typ);
23002 end if;
23003
23004 if Rep_Item_Too_Late (Typ, N) then
23005 return;
23006 end if;
23007
23008 Check_First_Subtype (Arg1);
23009
23010 -- Note remaining cases are references to a type in the current
23011 -- declarative part. If we find an error, we post the error on
23012 -- the relevant type declaration at an appropriate point.
23013
23014 if not Is_Record_Type (Typ) then
23015 Error_Msg_N ("unchecked union must be record type", Typ);
23016 return;
23017
23018 elsif Is_Tagged_Type (Typ) then
23019 Error_Msg_N ("unchecked union must not be tagged", Typ);
23020 return;
23021
23022 elsif not Has_Discriminants (Typ) then
23023 Error_Msg_N
23024 ("unchecked union must have one discriminant", Typ);
23025 return;
23026
23027 -- Note: in previous versions of GNAT we used to check for limited
23028 -- types and give an error, but in fact the standard does allow
23029 -- Unchecked_Union on limited types, so this check was removed.
23030
23031 -- Similarly, GNAT used to require that all discriminants have
23032 -- default values, but this is not mandated by the RM.
23033
23034 -- Proceed with basic error checks completed
23035
23036 else
23037 Tdef := Type_Definition (Declaration_Node (Typ));
23038 Clist := Component_List (Tdef);
23039
23040 -- Check presence of component list and variant part
23041
23042 if No (Clist) or else No (Variant_Part (Clist)) then
23043 Error_Msg_N
23044 ("unchecked union must have variant part", Tdef);
23045 return;
23046 end if;
23047
23048 -- Check components
23049
23050 Comp := First (Component_Items (Clist));
23051 while Present (Comp) loop
23052 Check_Component (Comp, Typ);
23053 Next (Comp);
23054 end loop;
23055
23056 -- Check variant part
23057
23058 Vpart := Variant_Part (Clist);
23059
23060 Variant := First (Variants (Vpart));
23061 while Present (Variant) loop
23062 Check_Variant (Variant, Typ);
23063 Next (Variant);
23064 end loop;
23065 end if;
23066
23067 Set_Is_Unchecked_Union (Typ);
23068 Set_Convention (Typ, Convention_C);
23069 Set_Has_Unchecked_Union (Base_Type (Typ));
23070 Set_Is_Unchecked_Union (Base_Type (Typ));
23071 end Unchecked_Union;
23072
23073 ----------------------------
23074 -- Unevaluated_Use_Of_Old --
23075 ----------------------------
23076
23077 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
23078
23079 when Pragma_Unevaluated_Use_Of_Old =>
23080 GNAT_Pragma;
23081 Check_Arg_Count (1);
23082 Check_No_Identifiers;
23083 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
23084
23085 -- Suppress/Unsuppress can appear as a configuration pragma, or in
23086 -- a declarative part or a package spec.
23087
23088 if not Is_Configuration_Pragma then
23089 Check_Is_In_Decl_Part_Or_Package_Spec;
23090 end if;
23091
23092 -- Store proper setting of Uneval_Old
23093
23094 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
23095 Uneval_Old := Fold_Upper (Name_Buffer (1));
23096
23097 ------------------------
23098 -- Unimplemented_Unit --
23099 ------------------------
23100
23101 -- pragma Unimplemented_Unit;
23102
23103 -- Note: this only gives an error if we are generating code, or if
23104 -- we are in a generic library unit (where the pragma appears in the
23105 -- body, not in the spec).
23106
23107 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
23108 Cunitent : constant Entity_Id :=
23109 Cunit_Entity (Get_Source_Unit (Loc));
23110 Ent_Kind : constant Entity_Kind := Ekind (Cunitent);
23111
23112 begin
23113 GNAT_Pragma;
23114 Check_Arg_Count (0);
23115
23116 if Operating_Mode = Generate_Code
23117 or else Ent_Kind = E_Generic_Function
23118 or else Ent_Kind = E_Generic_Procedure
23119 or else Ent_Kind = E_Generic_Package
23120 then
23121 Get_Name_String (Chars (Cunitent));
23122 Set_Casing (Mixed_Case);
23123 Write_Str (Name_Buffer (1 .. Name_Len));
23124 Write_Str (" is not supported in this configuration");
23125 Write_Eol;
23126 raise Unrecoverable_Error;
23127 end if;
23128 end Unimplemented_Unit;
23129
23130 ------------------------
23131 -- Universal_Aliasing --
23132 ------------------------
23133
23134 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
23135
23136 when Pragma_Universal_Aliasing => Universal_Alias : declare
23137 E_Id : Entity_Id;
23138
23139 begin
23140 GNAT_Pragma;
23141 Check_Arg_Count (1);
23142 Check_Optional_Identifier (Arg2, Name_Entity);
23143 Check_Arg_Is_Local_Name (Arg1);
23144 E_Id := Entity (Get_Pragma_Arg (Arg1));
23145
23146 if E_Id = Any_Type then
23147 return;
23148 elsif No (E_Id) or else not Is_Type (E_Id) then
23149 Error_Pragma_Arg ("pragma% requires type", Arg1);
23150 end if;
23151
23152 -- A pragma that applies to a Ghost entity becomes Ghost for the
23153 -- purposes of legality checks and removal of ignored Ghost code.
23154
23155 Mark_Ghost_Pragma (N, E_Id);
23156 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
23157 Record_Rep_Item (E_Id, N);
23158 end Universal_Alias;
23159
23160 --------------------
23161 -- Universal_Data --
23162 --------------------
23163
23164 -- pragma Universal_Data [(library_unit_NAME)];
23165
23166 when Pragma_Universal_Data =>
23167 GNAT_Pragma;
23168 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
23169
23170 ----------------
23171 -- Unmodified --
23172 ----------------
23173
23174 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
23175
23176 when Pragma_Unmodified =>
23177 Analyze_Unmodified_Or_Unused;
23178
23179 ------------------
23180 -- Unreferenced --
23181 ------------------
23182
23183 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
23184
23185 -- or when used in a context clause:
23186
23187 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
23188
23189 when Pragma_Unreferenced =>
23190 Analyze_Unreferenced_Or_Unused;
23191
23192 --------------------------
23193 -- Unreferenced_Objects --
23194 --------------------------
23195
23196 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
23197
23198 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
23199 Arg : Node_Id;
23200 Arg_Expr : Node_Id;
23201 Arg_Id : Entity_Id;
23202
23203 Ghost_Error_Posted : Boolean := False;
23204 -- Flag set when an error concerning the illegal mix of Ghost and
23205 -- non-Ghost types is emitted.
23206
23207 Ghost_Id : Entity_Id := Empty;
23208 -- The entity of the first Ghost type encountered while processing
23209 -- the arguments of the pragma.
23210
23211 begin
23212 GNAT_Pragma;
23213 Check_At_Least_N_Arguments (1);
23214
23215 Arg := Arg1;
23216 while Present (Arg) loop
23217 Check_No_Identifier (Arg);
23218 Check_Arg_Is_Local_Name (Arg);
23219 Arg_Expr := Get_Pragma_Arg (Arg);
23220
23221 if Is_Entity_Name (Arg_Expr) then
23222 Arg_Id := Entity (Arg_Expr);
23223
23224 if Is_Type (Arg_Id) then
23225 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
23226
23227 -- A pragma that applies to a Ghost entity becomes Ghost
23228 -- for the purposes of legality checks and removal of
23229 -- ignored Ghost code.
23230
23231 Mark_Ghost_Pragma (N, Arg_Id);
23232
23233 -- Capture the entity of the first Ghost type being
23234 -- processed for error detection purposes.
23235
23236 if Is_Ghost_Entity (Arg_Id) then
23237 if No (Ghost_Id) then
23238 Ghost_Id := Arg_Id;
23239 end if;
23240
23241 -- Otherwise the type is non-Ghost. It is illegal to mix
23242 -- references to Ghost and non-Ghost entities
23243 -- (SPARK RM 6.9).
23244
23245 elsif Present (Ghost_Id)
23246 and then not Ghost_Error_Posted
23247 then
23248 Ghost_Error_Posted := True;
23249
23250 Error_Msg_Name_1 := Pname;
23251 Error_Msg_N
23252 ("pragma % cannot mention ghost and non-ghost types",
23253 N);
23254
23255 Error_Msg_Sloc := Sloc (Ghost_Id);
23256 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
23257
23258 Error_Msg_Sloc := Sloc (Arg_Id);
23259 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
23260 end if;
23261 else
23262 Error_Pragma_Arg
23263 ("argument for pragma% must be type or subtype", Arg);
23264 end if;
23265 else
23266 Error_Pragma_Arg
23267 ("argument for pragma% must be type or subtype", Arg);
23268 end if;
23269
23270 Next (Arg);
23271 end loop;
23272 end Unreferenced_Objects;
23273
23274 ------------------------------
23275 -- Unreserve_All_Interrupts --
23276 ------------------------------
23277
23278 -- pragma Unreserve_All_Interrupts;
23279
23280 when Pragma_Unreserve_All_Interrupts =>
23281 GNAT_Pragma;
23282 Check_Arg_Count (0);
23283
23284 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
23285 Unreserve_All_Interrupts := True;
23286 end if;
23287
23288 ----------------
23289 -- Unsuppress --
23290 ----------------
23291
23292 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
23293
23294 when Pragma_Unsuppress =>
23295 Ada_2005_Pragma;
23296 Process_Suppress_Unsuppress (Suppress_Case => False);
23297
23298 ------------
23299 -- Unused --
23300 ------------
23301
23302 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
23303
23304 when Pragma_Unused =>
23305 Analyze_Unmodified_Or_Unused (Is_Unused => True);
23306 Analyze_Unreferenced_Or_Unused (Is_Unused => True);
23307
23308 -------------------
23309 -- Use_VADS_Size --
23310 -------------------
23311
23312 -- pragma Use_VADS_Size;
23313
23314 when Pragma_Use_VADS_Size =>
23315 GNAT_Pragma;
23316 Check_Arg_Count (0);
23317 Check_Valid_Configuration_Pragma;
23318 Use_VADS_Size := True;
23319
23320 ---------------------
23321 -- Validity_Checks --
23322 ---------------------
23323
23324 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23325
23326 when Pragma_Validity_Checks => Validity_Checks : declare
23327 A : constant Node_Id := Get_Pragma_Arg (Arg1);
23328 S : String_Id;
23329 C : Char_Code;
23330
23331 begin
23332 GNAT_Pragma;
23333 Check_Arg_Count (1);
23334 Check_No_Identifiers;
23335
23336 -- Pragma always active unless in CodePeer or GNATprove modes,
23337 -- which use a fixed configuration of validity checks.
23338
23339 if not (CodePeer_Mode or GNATprove_Mode) then
23340 if Nkind (A) = N_String_Literal then
23341 S := Strval (A);
23342
23343 declare
23344 Slen : constant Natural := Natural (String_Length (S));
23345 Options : String (1 .. Slen);
23346 J : Positive;
23347
23348 begin
23349 -- Couldn't we use a for loop here over Options'Range???
23350
23351 J := 1;
23352 loop
23353 C := Get_String_Char (S, Pos (J));
23354
23355 -- This is a weird test, it skips setting validity
23356 -- checks entirely if any element of S is out of
23357 -- range of Character, what is that about ???
23358
23359 exit when not In_Character_Range (C);
23360 Options (J) := Get_Character (C);
23361
23362 if J = Slen then
23363 Set_Validity_Check_Options (Options);
23364 exit;
23365 else
23366 J := J + 1;
23367 end if;
23368 end loop;
23369 end;
23370
23371 elsif Nkind (A) = N_Identifier then
23372 if Chars (A) = Name_All_Checks then
23373 Set_Validity_Check_Options ("a");
23374 elsif Chars (A) = Name_On then
23375 Validity_Checks_On := True;
23376 elsif Chars (A) = Name_Off then
23377 Validity_Checks_On := False;
23378 end if;
23379 end if;
23380 end if;
23381 end Validity_Checks;
23382
23383 --------------
23384 -- Volatile --
23385 --------------
23386
23387 -- pragma Volatile (LOCAL_NAME);
23388
23389 when Pragma_Volatile =>
23390 Process_Atomic_Independent_Shared_Volatile;
23391
23392 -------------------------
23393 -- Volatile_Components --
23394 -------------------------
23395
23396 -- pragma Volatile_Components (array_LOCAL_NAME);
23397
23398 -- Volatile is handled by the same circuit as Atomic_Components
23399
23400 --------------------------
23401 -- Volatile_Full_Access --
23402 --------------------------
23403
23404 -- pragma Volatile_Full_Access (LOCAL_NAME);
23405
23406 when Pragma_Volatile_Full_Access =>
23407 GNAT_Pragma;
23408 Process_Atomic_Independent_Shared_Volatile;
23409
23410 -----------------------
23411 -- Volatile_Function --
23412 -----------------------
23413
23414 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
23415
23416 when Pragma_Volatile_Function => Volatile_Function : declare
23417 Over_Id : Entity_Id;
23418 Spec_Id : Entity_Id;
23419 Subp_Decl : Node_Id;
23420
23421 begin
23422 GNAT_Pragma;
23423 Check_No_Identifiers;
23424 Check_At_Most_N_Arguments (1);
23425
23426 Subp_Decl :=
23427 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
23428
23429 -- Generic subprogram
23430
23431 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
23432 null;
23433
23434 -- Body acts as spec
23435
23436 elsif Nkind (Subp_Decl) = N_Subprogram_Body
23437 and then No (Corresponding_Spec (Subp_Decl))
23438 then
23439 null;
23440
23441 -- Body stub acts as spec
23442
23443 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
23444 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
23445 then
23446 null;
23447
23448 -- Subprogram
23449
23450 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
23451 null;
23452
23453 else
23454 Pragma_Misplaced;
23455 return;
23456 end if;
23457
23458 Spec_Id := Unique_Defining_Entity (Subp_Decl);
23459
23460 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
23461 Pragma_Misplaced;
23462 return;
23463 end if;
23464
23465 -- A pragma that applies to a Ghost entity becomes Ghost for the
23466 -- purposes of legality checks and removal of ignored Ghost code.
23467
23468 Mark_Ghost_Pragma (N, Spec_Id);
23469
23470 -- Chain the pragma on the contract for completeness
23471
23472 Add_Contract_Item (N, Spec_Id);
23473
23474 -- The legality checks of pragma Volatile_Function are affected by
23475 -- the SPARK mode in effect. Analyze all pragmas in a specific
23476 -- order.
23477
23478 Analyze_If_Present (Pragma_SPARK_Mode);
23479
23480 -- A volatile function cannot override a non-volatile function
23481 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
23482 -- in New_Overloaded_Entity, however at that point the pragma has
23483 -- not been processed yet.
23484
23485 Over_Id := Overridden_Operation (Spec_Id);
23486
23487 if Present (Over_Id)
23488 and then not Is_Volatile_Function (Over_Id)
23489 then
23490 Error_Msg_N
23491 ("incompatible volatile function values in effect", Spec_Id);
23492
23493 Error_Msg_Sloc := Sloc (Over_Id);
23494 Error_Msg_N
23495 ("\& declared # with Volatile_Function value False",
23496 Spec_Id);
23497
23498 Error_Msg_Sloc := Sloc (Spec_Id);
23499 Error_Msg_N
23500 ("\overridden # with Volatile_Function value True",
23501 Spec_Id);
23502 end if;
23503
23504 -- Analyze the Boolean expression (if any)
23505
23506 if Present (Arg1) then
23507 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
23508 end if;
23509 end Volatile_Function;
23510
23511 ----------------------
23512 -- Warning_As_Error --
23513 ----------------------
23514
23515 -- pragma Warning_As_Error (static_string_EXPRESSION);
23516
23517 when Pragma_Warning_As_Error =>
23518 GNAT_Pragma;
23519 Check_Arg_Count (1);
23520 Check_No_Identifiers;
23521 Check_Valid_Configuration_Pragma;
23522
23523 if not Is_Static_String_Expression (Arg1) then
23524 Error_Pragma_Arg
23525 ("argument of pragma% must be static string expression",
23526 Arg1);
23527
23528 -- OK static string expression
23529
23530 else
23531 Acquire_Warning_Match_String (Arg1);
23532 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
23533 Warnings_As_Errors (Warnings_As_Errors_Count) :=
23534 new String'(Name_Buffer (1 .. Name_Len));
23535 end if;
23536
23537 --------------
23538 -- Warnings --
23539 --------------
23540
23541 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
23542
23543 -- DETAILS ::= On | Off
23544 -- DETAILS ::= On | Off, local_NAME
23545 -- DETAILS ::= static_string_EXPRESSION
23546 -- DETAILS ::= On | Off, static_string_EXPRESSION
23547
23548 -- TOOL_NAME ::= GNAT | GNATProve
23549
23550 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
23551
23552 -- Note: If the first argument matches an allowed tool name, it is
23553 -- always considered to be a tool name, even if there is a string
23554 -- variable of that name.
23555
23556 -- Note if the second argument of DETAILS is a local_NAME then the
23557 -- second form is always understood. If the intention is to use
23558 -- the fourth form, then you can write NAME & "" to force the
23559 -- intepretation as a static_string_EXPRESSION.
23560
23561 when Pragma_Warnings => Warnings : declare
23562 Reason : String_Id;
23563
23564 begin
23565 GNAT_Pragma;
23566 Check_At_Least_N_Arguments (1);
23567
23568 -- See if last argument is labeled Reason. If so, make sure we
23569 -- have a string literal or a concatenation of string literals,
23570 -- and acquire the REASON string. Then remove the REASON argument
23571 -- by decreasing Num_Args by one; Remaining processing looks only
23572 -- at first Num_Args arguments).
23573
23574 declare
23575 Last_Arg : constant Node_Id :=
23576 Last (Pragma_Argument_Associations (N));
23577
23578 begin
23579 if Nkind (Last_Arg) = N_Pragma_Argument_Association
23580 and then Chars (Last_Arg) = Name_Reason
23581 then
23582 Start_String;
23583 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
23584 Reason := End_String;
23585 Arg_Count := Arg_Count - 1;
23586
23587 -- Not allowed in compiler units (bootstrap issues)
23588
23589 Check_Compiler_Unit ("Reason for pragma Warnings", N);
23590
23591 -- No REASON string, set null string as reason
23592
23593 else
23594 Reason := Null_String_Id;
23595 end if;
23596 end;
23597
23598 -- Now proceed with REASON taken care of and eliminated
23599
23600 Check_No_Identifiers;
23601
23602 -- If debug flag -gnatd.i is set, pragma is ignored
23603
23604 if Debug_Flag_Dot_I then
23605 return;
23606 end if;
23607
23608 -- Process various forms of the pragma
23609
23610 declare
23611 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
23612 Shifted_Args : List_Id;
23613
23614 begin
23615 -- See if first argument is a tool name, currently either
23616 -- GNAT or GNATprove. If so, either ignore the pragma if the
23617 -- tool used does not match, or continue as if no tool name
23618 -- was given otherwise, by shifting the arguments.
23619
23620 if Nkind (Argx) = N_Identifier
23621 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
23622 then
23623 if Chars (Argx) = Name_Gnat then
23624 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
23625 Rewrite (N, Make_Null_Statement (Loc));
23626 Analyze (N);
23627 raise Pragma_Exit;
23628 end if;
23629
23630 elsif Chars (Argx) = Name_Gnatprove then
23631 if not GNATprove_Mode then
23632 Rewrite (N, Make_Null_Statement (Loc));
23633 Analyze (N);
23634 raise Pragma_Exit;
23635 end if;
23636
23637 else
23638 raise Program_Error;
23639 end if;
23640
23641 -- At this point, the pragma Warnings applies to the tool,
23642 -- so continue with shifted arguments.
23643
23644 Arg_Count := Arg_Count - 1;
23645
23646 if Arg_Count = 1 then
23647 Shifted_Args := New_List (New_Copy (Arg2));
23648 elsif Arg_Count = 2 then
23649 Shifted_Args := New_List (New_Copy (Arg2),
23650 New_Copy (Arg3));
23651 elsif Arg_Count = 3 then
23652 Shifted_Args := New_List (New_Copy (Arg2),
23653 New_Copy (Arg3),
23654 New_Copy (Arg4));
23655 else
23656 raise Program_Error;
23657 end if;
23658
23659 Rewrite (N,
23660 Make_Pragma (Loc,
23661 Chars => Name_Warnings,
23662 Pragma_Argument_Associations => Shifted_Args));
23663 Analyze (N);
23664 raise Pragma_Exit;
23665 end if;
23666
23667 -- One argument case
23668
23669 if Arg_Count = 1 then
23670
23671 -- On/Off one argument case was processed by parser
23672
23673 if Nkind (Argx) = N_Identifier
23674 and then Nam_In (Chars (Argx), Name_On, Name_Off)
23675 then
23676 null;
23677
23678 -- One argument case must be ON/OFF or static string expr
23679
23680 elsif not Is_Static_String_Expression (Arg1) then
23681 Error_Pragma_Arg
23682 ("argument of pragma% must be On/Off or static string "
23683 & "expression", Arg1);
23684
23685 -- One argument string expression case
23686
23687 else
23688 declare
23689 Lit : constant Node_Id := Expr_Value_S (Argx);
23690 Str : constant String_Id := Strval (Lit);
23691 Len : constant Nat := String_Length (Str);
23692 C : Char_Code;
23693 J : Nat;
23694 OK : Boolean;
23695 Chr : Character;
23696
23697 begin
23698 J := 1;
23699 while J <= Len loop
23700 C := Get_String_Char (Str, J);
23701 OK := In_Character_Range (C);
23702
23703 if OK then
23704 Chr := Get_Character (C);
23705
23706 -- Dash case: only -Wxxx is accepted
23707
23708 if J = 1
23709 and then J < Len
23710 and then Chr = '-'
23711 then
23712 J := J + 1;
23713 C := Get_String_Char (Str, J);
23714 Chr := Get_Character (C);
23715 exit when Chr = 'W';
23716 OK := False;
23717
23718 -- Dot case
23719
23720 elsif J < Len and then Chr = '.' then
23721 J := J + 1;
23722 C := Get_String_Char (Str, J);
23723 Chr := Get_Character (C);
23724
23725 if not Set_Dot_Warning_Switch (Chr) then
23726 Error_Pragma_Arg
23727 ("invalid warning switch character "
23728 & '.' & Chr, Arg1);
23729 end if;
23730
23731 -- Non-Dot case
23732
23733 else
23734 OK := Set_Warning_Switch (Chr);
23735 end if;
23736 end if;
23737
23738 if not OK then
23739 Error_Pragma_Arg
23740 ("invalid warning switch character " & Chr,
23741 Arg1);
23742 end if;
23743
23744 J := J + 1;
23745 end loop;
23746 end;
23747 end if;
23748
23749 -- Two or more arguments (must be two)
23750
23751 else
23752 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23753 Check_Arg_Count (2);
23754
23755 declare
23756 E_Id : Node_Id;
23757 E : Entity_Id;
23758 Err : Boolean;
23759
23760 begin
23761 E_Id := Get_Pragma_Arg (Arg2);
23762 Analyze (E_Id);
23763
23764 -- In the expansion of an inlined body, a reference to
23765 -- the formal may be wrapped in a conversion if the
23766 -- actual is a conversion. Retrieve the real entity name.
23767
23768 if (In_Instance_Body or In_Inlined_Body)
23769 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
23770 then
23771 E_Id := Expression (E_Id);
23772 end if;
23773
23774 -- Entity name case
23775
23776 if Is_Entity_Name (E_Id) then
23777 E := Entity (E_Id);
23778
23779 if E = Any_Id then
23780 return;
23781 else
23782 loop
23783 Set_Warnings_Off
23784 (E, (Chars (Get_Pragma_Arg (Arg1)) =
23785 Name_Off));
23786
23787 -- For OFF case, make entry in warnings off
23788 -- pragma table for later processing. But we do
23789 -- not do that within an instance, since these
23790 -- warnings are about what is needed in the
23791 -- template, not an instance of it.
23792
23793 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
23794 and then Warn_On_Warnings_Off
23795 and then not In_Instance
23796 then
23797 Warnings_Off_Pragmas.Append ((N, E, Reason));
23798 end if;
23799
23800 if Is_Enumeration_Type (E) then
23801 declare
23802 Lit : Entity_Id;
23803 begin
23804 Lit := First_Literal (E);
23805 while Present (Lit) loop
23806 Set_Warnings_Off (Lit);
23807 Next_Literal (Lit);
23808 end loop;
23809 end;
23810 end if;
23811
23812 exit when No (Homonym (E));
23813 E := Homonym (E);
23814 end loop;
23815 end if;
23816
23817 -- Error if not entity or static string expression case
23818
23819 elsif not Is_Static_String_Expression (Arg2) then
23820 Error_Pragma_Arg
23821 ("second argument of pragma% must be entity name "
23822 & "or static string expression", Arg2);
23823
23824 -- Static string expression case
23825
23826 else
23827 Acquire_Warning_Match_String (Arg2);
23828
23829 -- Note on configuration pragma case: If this is a
23830 -- configuration pragma, then for an OFF pragma, we
23831 -- just set Config True in the call, which is all
23832 -- that needs to be done. For the case of ON, this
23833 -- is normally an error, unless it is canceling the
23834 -- effect of a previous OFF pragma in the same file.
23835 -- In any other case, an error will be signalled (ON
23836 -- with no matching OFF).
23837
23838 -- Note: We set Used if we are inside a generic to
23839 -- disable the test that the non-config case actually
23840 -- cancels a warning. That's because we can't be sure
23841 -- there isn't an instantiation in some other unit
23842 -- where a warning is suppressed.
23843
23844 -- We could do a little better here by checking if the
23845 -- generic unit we are inside is public, but for now
23846 -- we don't bother with that refinement.
23847
23848 if Chars (Argx) = Name_Off then
23849 Set_Specific_Warning_Off
23850 (Loc, Name_Buffer (1 .. Name_Len), Reason,
23851 Config => Is_Configuration_Pragma,
23852 Used => Inside_A_Generic or else In_Instance);
23853
23854 elsif Chars (Argx) = Name_On then
23855 Set_Specific_Warning_On
23856 (Loc, Name_Buffer (1 .. Name_Len), Err);
23857
23858 if Err then
23859 Error_Msg
23860 ("??pragma Warnings On with no matching "
23861 & "Warnings Off", Loc);
23862 end if;
23863 end if;
23864 end if;
23865 end;
23866 end if;
23867 end;
23868 end Warnings;
23869
23870 -------------------
23871 -- Weak_External --
23872 -------------------
23873
23874 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
23875
23876 when Pragma_Weak_External => Weak_External : declare
23877 Ent : Entity_Id;
23878
23879 begin
23880 GNAT_Pragma;
23881 Check_Arg_Count (1);
23882 Check_Optional_Identifier (Arg1, Name_Entity);
23883 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23884 Ent := Entity (Get_Pragma_Arg (Arg1));
23885
23886 if Rep_Item_Too_Early (Ent, N) then
23887 return;
23888 else
23889 Ent := Underlying_Type (Ent);
23890 end if;
23891
23892 -- The only processing required is to link this item on to the
23893 -- list of rep items for the given entity. This is accomplished
23894 -- by the call to Rep_Item_Too_Late (when no error is detected
23895 -- and False is returned).
23896
23897 if Rep_Item_Too_Late (Ent, N) then
23898 return;
23899 else
23900 Set_Has_Gigi_Rep_Item (Ent);
23901 end if;
23902 end Weak_External;
23903
23904 -----------------------------
23905 -- Wide_Character_Encoding --
23906 -----------------------------
23907
23908 -- pragma Wide_Character_Encoding (IDENTIFIER);
23909
23910 when Pragma_Wide_Character_Encoding =>
23911 GNAT_Pragma;
23912
23913 -- Nothing to do, handled in parser. Note that we do not enforce
23914 -- configuration pragma placement, this pragma can appear at any
23915 -- place in the source, allowing mixed encodings within a single
23916 -- source program.
23917
23918 null;
23919
23920 --------------------
23921 -- Unknown_Pragma --
23922 --------------------
23923
23924 -- Should be impossible, since the case of an unknown pragma is
23925 -- separately processed before the case statement is entered.
23926
23927 when Unknown_Pragma =>
23928 raise Program_Error;
23929 end case;
23930
23931 -- AI05-0144: detect dangerous order dependence. Disabled for now,
23932 -- until AI is formally approved.
23933
23934 -- Check_Order_Dependence;
23935
23936 exception
23937 when Pragma_Exit => null;
23938 end Analyze_Pragma;
23939
23940 ---------------------------------------------
23941 -- Analyze_Pre_Post_Condition_In_Decl_Part --
23942 ---------------------------------------------
23943
23944 -- WARNING: This routine manages Ghost regions. Return statements must be
23945 -- replaced by gotos which jump to the end of the routine and restore the
23946 -- Ghost mode.
23947
23948 procedure Analyze_Pre_Post_Condition_In_Decl_Part
23949 (N : Node_Id;
23950 Freeze_Id : Entity_Id := Empty)
23951 is
23952 Disp_Typ : Entity_Id;
23953 -- The dispatching type of the subprogram subject to the pre- or
23954 -- postcondition.
23955
23956 function Check_References (Nod : Node_Id) return Traverse_Result;
23957 -- Check that expression Nod does not mention non-primitives of the
23958 -- type, global objects of the type, or other illegalities described
23959 -- and implied by AI12-0113.
23960
23961 ----------------------
23962 -- Check_References --
23963 ----------------------
23964
23965 function Check_References (Nod : Node_Id) return Traverse_Result is
23966 begin
23967 if Nkind (Nod) = N_Function_Call
23968 and then Is_Entity_Name (Name (Nod))
23969 then
23970 declare
23971 Func : constant Entity_Id := Entity (Name (Nod));
23972 Form : Entity_Id;
23973
23974 begin
23975 -- An operation of the type must be a primitive
23976
23977 if No (Find_Dispatching_Type (Func)) then
23978 Form := First_Formal (Func);
23979 while Present (Form) loop
23980 if Etype (Form) = Disp_Typ then
23981 Error_Msg_NE
23982 ("operation in class-wide condition must be "
23983 & "primitive of &", Nod, Disp_Typ);
23984 end if;
23985
23986 Next_Formal (Form);
23987 end loop;
23988
23989 -- A return object of the type is illegal as well
23990
23991 if Etype (Func) = Disp_Typ
23992 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
23993 then
23994 Error_Msg_NE
23995 ("operation in class-wide condition must be primitive "
23996 & "of &", Nod, Disp_Typ);
23997 end if;
23998 end if;
23999 end;
24000
24001 elsif Is_Entity_Name (Nod)
24002 and then
24003 (Etype (Nod) = Disp_Typ
24004 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24005 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
24006 then
24007 Error_Msg_NE
24008 ("object in class-wide condition must be formal of type &",
24009 Nod, Disp_Typ);
24010
24011 elsif Nkind (Nod) = N_Explicit_Dereference
24012 and then (Etype (Nod) = Disp_Typ
24013 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24014 and then (not Is_Entity_Name (Prefix (Nod))
24015 or else not Is_Formal (Entity (Prefix (Nod))))
24016 then
24017 Error_Msg_NE
24018 ("operation in class-wide condition must be primitive of &",
24019 Nod, Disp_Typ);
24020 end if;
24021
24022 return OK;
24023 end Check_References;
24024
24025 procedure Check_Class_Wide_Condition is
24026 new Traverse_Proc (Check_References);
24027
24028 -- Local variables
24029
24030 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24031 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
24032 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
24033
24034 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
24035 -- Save the Ghost mode to restore on exit
24036
24037 Errors : Nat;
24038 Restore_Scope : Boolean := False;
24039
24040 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
24041
24042 begin
24043 -- Do not analyze the pragma multiple times
24044
24045 if Is_Analyzed_Pragma (N) then
24046 return;
24047 end if;
24048
24049 -- Set the Ghost mode in effect from the pragma. Due to the delayed
24050 -- analysis of the pragma, the Ghost mode at point of declaration and
24051 -- point of analysis may not necessarily be the same. Use the mode in
24052 -- effect at the point of declaration.
24053
24054 Set_Ghost_Mode (N);
24055
24056 -- Ensure that the subprogram and its formals are visible when analyzing
24057 -- the expression of the pragma.
24058
24059 if not In_Open_Scopes (Spec_Id) then
24060 Restore_Scope := True;
24061 Push_Scope (Spec_Id);
24062
24063 if Is_Generic_Subprogram (Spec_Id) then
24064 Install_Generic_Formals (Spec_Id);
24065 else
24066 Install_Formals (Spec_Id);
24067 end if;
24068 end if;
24069
24070 Errors := Serious_Errors_Detected;
24071 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
24072
24073 -- Emit a clarification message when the expression contains at least
24074 -- one undefined reference, possibly due to contract "freezing".
24075
24076 if Errors /= Serious_Errors_Detected
24077 and then Present (Freeze_Id)
24078 and then Has_Undefined_Reference (Expr)
24079 then
24080 Contract_Freeze_Error (Spec_Id, Freeze_Id);
24081 end if;
24082
24083 if Class_Present (N) then
24084
24085 -- Verify that a class-wide condition is legal, i.e. the operation is
24086 -- a primitive of a tagged type. Note that a generic subprogram is
24087 -- not a primitive operation.
24088
24089 Disp_Typ := Find_Dispatching_Type (Spec_Id);
24090
24091 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
24092 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
24093
24094 if From_Aspect_Specification (N) then
24095 Error_Msg_N
24096 ("aspect % can only be specified for a primitive operation "
24097 & "of a tagged type", Corresponding_Aspect (N));
24098
24099 -- The pragma is a source construct
24100
24101 else
24102 Error_Msg_N
24103 ("pragma % can only be specified for a primitive operation "
24104 & "of a tagged type", N);
24105 end if;
24106
24107 -- Remaining semantic checks require a full tree traversal
24108
24109 else
24110 Check_Class_Wide_Condition (Expr);
24111 end if;
24112
24113 end if;
24114
24115 if Restore_Scope then
24116 End_Scope;
24117 end if;
24118
24119 -- Currently it is not possible to inline pre/postconditions on a
24120 -- subprogram subject to pragma Inline_Always.
24121
24122 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
24123 Set_Is_Analyzed_Pragma (N);
24124
24125 Restore_Ghost_Mode (Saved_GM);
24126 end Analyze_Pre_Post_Condition_In_Decl_Part;
24127
24128 ------------------------------------------
24129 -- Analyze_Refined_Depends_In_Decl_Part --
24130 ------------------------------------------
24131
24132 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
24133 procedure Check_Dependency_Clause
24134 (Spec_Id : Entity_Id;
24135 Dep_Clause : Node_Id;
24136 Dep_States : Elist_Id;
24137 Refinements : List_Id;
24138 Matched_Items : in out Elist_Id);
24139 -- Try to match a single dependency clause Dep_Clause against one or
24140 -- more refinement clauses found in list Refinements. Each successful
24141 -- match eliminates at least one refinement clause from Refinements.
24142 -- Spec_Id denotes the entity of the related subprogram. Dep_States
24143 -- denotes the entities of all abstract states which appear in pragma
24144 -- Depends. Matched_Items contains the entities of all successfully
24145 -- matched items found in pragma Depends.
24146
24147 procedure Check_Output_States
24148 (Spec_Id : Entity_Id;
24149 Spec_Inputs : Elist_Id;
24150 Spec_Outputs : Elist_Id;
24151 Body_Inputs : Elist_Id;
24152 Body_Outputs : Elist_Id);
24153 -- Determine whether pragma Depends contains an output state with a
24154 -- visible refinement and if so, ensure that pragma Refined_Depends
24155 -- mentions all its constituents as outputs. Spec_Id is the entity of
24156 -- the related subprograms. Spec_Inputs and Spec_Outputs denote the
24157 -- inputs and outputs of the subprogram spec synthesized from pragma
24158 -- Depends. Body_Inputs and Body_Outputs denote the inputs and outputs
24159 -- of the subprogram body synthesized from pragma Refined_Depends.
24160
24161 function Collect_States (Clauses : List_Id) return Elist_Id;
24162 -- Given a normalized list of dependencies obtained from calling
24163 -- Normalize_Clauses, return a list containing the entities of all
24164 -- states appearing in dependencies. It helps in checking refinements
24165 -- involving a state and a corresponding constituent which is not a
24166 -- direct constituent of the state.
24167
24168 procedure Normalize_Clauses (Clauses : List_Id);
24169 -- Given a list of dependence or refinement clauses Clauses, normalize
24170 -- each clause by creating multiple dependencies with exactly one input
24171 -- and one output.
24172
24173 procedure Remove_Extra_Clauses
24174 (Clauses : List_Id;
24175 Matched_Items : Elist_Id);
24176 -- Given a list of refinement clauses Clauses, remove all clauses whose
24177 -- inputs and/or outputs have been previously matched. See the body for
24178 -- all special cases. Matched_Items contains the entities of all matched
24179 -- items found in pragma Depends.
24180
24181 procedure Report_Extra_Clauses
24182 (Spec_Id : Entity_Id;
24183 Clauses : List_Id);
24184 -- Emit an error for each extra clause found in list Clauses. Spec_Id
24185 -- denotes the entity of the related subprogram.
24186
24187 -----------------------------
24188 -- Check_Dependency_Clause --
24189 -----------------------------
24190
24191 procedure Check_Dependency_Clause
24192 (Spec_Id : Entity_Id;
24193 Dep_Clause : Node_Id;
24194 Dep_States : Elist_Id;
24195 Refinements : List_Id;
24196 Matched_Items : in out Elist_Id)
24197 is
24198 Dep_Input : constant Node_Id := Expression (Dep_Clause);
24199 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
24200
24201 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
24202 -- Determine whether dependency item Dep_Item has been matched in a
24203 -- previous clause.
24204
24205 function Is_In_Out_State_Clause return Boolean;
24206 -- Determine whether dependence clause Dep_Clause denotes an abstract
24207 -- state that depends on itself (State => State).
24208
24209 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
24210 -- Determine whether item Item denotes an abstract state with visible
24211 -- null refinement.
24212
24213 procedure Match_Items
24214 (Dep_Item : Node_Id;
24215 Ref_Item : Node_Id;
24216 Matched : out Boolean);
24217 -- Try to match dependence item Dep_Item against refinement item
24218 -- Ref_Item. To match against a possible null refinement (see 2, 9),
24219 -- set Ref_Item to Empty. Flag Matched is set to True when one of
24220 -- the following conformance scenarios is in effect:
24221 -- 1) Both items denote null
24222 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
24223 -- 3) Both items denote attribute 'Result
24224 -- 4) Both items denote the same object
24225 -- 5) Both items denote the same formal parameter
24226 -- 6) Both items denote the same current instance of a type
24227 -- 7) Both items denote the same discriminant
24228 -- 8) Dep_Item is an abstract state with visible null refinement
24229 -- and Ref_Item denotes null.
24230 -- 9) Dep_Item is an abstract state with visible null refinement
24231 -- and Ref_Item is Empty (special case).
24232 -- 10) Dep_Item is an abstract state with full or partial visible
24233 -- non-null refinement and Ref_Item denotes one of its
24234 -- constituents.
24235 -- 11) Dep_Item is an abstract state without a full visible
24236 -- refinement and Ref_Item denotes the same state.
24237 -- When scenario 10 is in effect, the entity of the abstract state
24238 -- denoted by Dep_Item is added to list Refined_States.
24239
24240 procedure Record_Item (Item_Id : Entity_Id);
24241 -- Store the entity of an item denoted by Item_Id in Matched_Items
24242
24243 ------------------------
24244 -- Is_Already_Matched --
24245 ------------------------
24246
24247 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is
24248 Item_Id : Entity_Id := Empty;
24249
24250 begin
24251 -- When the dependency item denotes attribute 'Result, check for
24252 -- the entity of the related subprogram.
24253
24254 if Is_Attribute_Result (Dep_Item) then
24255 Item_Id := Spec_Id;
24256
24257 elsif Is_Entity_Name (Dep_Item) then
24258 Item_Id := Available_View (Entity_Of (Dep_Item));
24259 end if;
24260
24261 return
24262 Present (Item_Id) and then Contains (Matched_Items, Item_Id);
24263 end Is_Already_Matched;
24264
24265 ----------------------------
24266 -- Is_In_Out_State_Clause --
24267 ----------------------------
24268
24269 function Is_In_Out_State_Clause return Boolean is
24270 Dep_Input_Id : Entity_Id;
24271 Dep_Output_Id : Entity_Id;
24272
24273 begin
24274 -- Detect the following clause:
24275 -- State => State
24276
24277 if Is_Entity_Name (Dep_Input)
24278 and then Is_Entity_Name (Dep_Output)
24279 then
24280 -- Handle abstract views generated for limited with clauses
24281
24282 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
24283 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
24284
24285 return
24286 Ekind (Dep_Input_Id) = E_Abstract_State
24287 and then Dep_Input_Id = Dep_Output_Id;
24288 else
24289 return False;
24290 end if;
24291 end Is_In_Out_State_Clause;
24292
24293 ---------------------------
24294 -- Is_Null_Refined_State --
24295 ---------------------------
24296
24297 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
24298 Item_Id : Entity_Id;
24299
24300 begin
24301 if Is_Entity_Name (Item) then
24302
24303 -- Handle abstract views generated for limited with clauses
24304
24305 Item_Id := Available_View (Entity_Of (Item));
24306
24307 return
24308 Ekind (Item_Id) = E_Abstract_State
24309 and then Has_Null_Visible_Refinement (Item_Id);
24310 else
24311 return False;
24312 end if;
24313 end Is_Null_Refined_State;
24314
24315 -----------------
24316 -- Match_Items --
24317 -----------------
24318
24319 procedure Match_Items
24320 (Dep_Item : Node_Id;
24321 Ref_Item : Node_Id;
24322 Matched : out Boolean)
24323 is
24324 Dep_Item_Id : Entity_Id;
24325 Ref_Item_Id : Entity_Id;
24326
24327 begin
24328 -- Assume that the two items do not match
24329
24330 Matched := False;
24331
24332 -- A null matches null or Empty (special case)
24333
24334 if Nkind (Dep_Item) = N_Null
24335 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
24336 then
24337 Matched := True;
24338
24339 -- Attribute 'Result matches attribute 'Result
24340
24341 elsif Is_Attribute_Result (Dep_Item)
24342 and then Is_Attribute_Result (Ref_Item)
24343 then
24344 -- Put the entity of the related function on the list of
24345 -- matched items because attribute 'Result does not carry
24346 -- an entity similar to states and constituents.
24347
24348 Record_Item (Spec_Id);
24349 Matched := True;
24350
24351 -- Abstract states, current instances of concurrent types,
24352 -- discriminants, formal parameters and objects.
24353
24354 elsif Is_Entity_Name (Dep_Item) then
24355
24356 -- Handle abstract views generated for limited with clauses
24357
24358 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
24359
24360 if Ekind (Dep_Item_Id) = E_Abstract_State then
24361
24362 -- An abstract state with visible null refinement matches
24363 -- null or Empty (special case).
24364
24365 if Has_Null_Visible_Refinement (Dep_Item_Id)
24366 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
24367 then
24368 Record_Item (Dep_Item_Id);
24369 Matched := True;
24370
24371 -- An abstract state with visible non-null refinement
24372 -- matches one of its constituents, or itself for an
24373 -- abstract state with partial visible refinement.
24374
24375 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
24376 if Is_Entity_Name (Ref_Item) then
24377 Ref_Item_Id := Entity_Of (Ref_Item);
24378
24379 if Ekind_In (Ref_Item_Id, E_Abstract_State,
24380 E_Constant,
24381 E_Variable)
24382 and then Present (Encapsulating_State (Ref_Item_Id))
24383 and then Find_Encapsulating_State
24384 (Dep_States, Ref_Item_Id) = Dep_Item_Id
24385 then
24386 Record_Item (Dep_Item_Id);
24387 Matched := True;
24388
24389 elsif not Has_Visible_Refinement (Dep_Item_Id)
24390 and then Ref_Item_Id = Dep_Item_Id
24391 then
24392 Record_Item (Dep_Item_Id);
24393 Matched := True;
24394 end if;
24395 end if;
24396
24397 -- An abstract state without a visible refinement matches
24398 -- itself.
24399
24400 elsif Is_Entity_Name (Ref_Item)
24401 and then Entity_Of (Ref_Item) = Dep_Item_Id
24402 then
24403 Record_Item (Dep_Item_Id);
24404 Matched := True;
24405 end if;
24406
24407 -- A current instance of a concurrent type, discriminant,
24408 -- formal parameter or an object matches itself.
24409
24410 elsif Is_Entity_Name (Ref_Item)
24411 and then Entity_Of (Ref_Item) = Dep_Item_Id
24412 then
24413 Record_Item (Dep_Item_Id);
24414 Matched := True;
24415 end if;
24416 end if;
24417 end Match_Items;
24418
24419 -----------------
24420 -- Record_Item --
24421 -----------------
24422
24423 procedure Record_Item (Item_Id : Entity_Id) is
24424 begin
24425 if No (Matched_Items) then
24426 Matched_Items := New_Elmt_List;
24427 end if;
24428
24429 Append_Unique_Elmt (Item_Id, Matched_Items);
24430 end Record_Item;
24431
24432 -- Local variables
24433
24434 Clause_Matched : Boolean := False;
24435 Dummy : Boolean := False;
24436 Inputs_Match : Boolean;
24437 Next_Ref_Clause : Node_Id;
24438 Outputs_Match : Boolean;
24439 Ref_Clause : Node_Id;
24440 Ref_Input : Node_Id;
24441 Ref_Output : Node_Id;
24442
24443 -- Start of processing for Check_Dependency_Clause
24444
24445 begin
24446 -- Do not perform this check in an instance because it was already
24447 -- performed successfully in the generic template.
24448
24449 if Is_Generic_Instance (Spec_Id) then
24450 return;
24451 end if;
24452
24453 -- Examine all refinement clauses and compare them against the
24454 -- dependence clause.
24455
24456 Ref_Clause := First (Refinements);
24457 while Present (Ref_Clause) loop
24458 Next_Ref_Clause := Next (Ref_Clause);
24459
24460 -- Obtain the attributes of the current refinement clause
24461
24462 Ref_Input := Expression (Ref_Clause);
24463 Ref_Output := First (Choices (Ref_Clause));
24464
24465 -- The current refinement clause matches the dependence clause
24466 -- when both outputs match and both inputs match. See routine
24467 -- Match_Items for all possible conformance scenarios.
24468
24469 -- Depends Dep_Output => Dep_Input
24470 -- ^ ^
24471 -- match ? match ?
24472 -- v v
24473 -- Refined_Depends Ref_Output => Ref_Input
24474
24475 Match_Items
24476 (Dep_Item => Dep_Input,
24477 Ref_Item => Ref_Input,
24478 Matched => Inputs_Match);
24479
24480 Match_Items
24481 (Dep_Item => Dep_Output,
24482 Ref_Item => Ref_Output,
24483 Matched => Outputs_Match);
24484
24485 -- An In_Out state clause may be matched against a refinement with
24486 -- a null input or null output as long as the non-null side of the
24487 -- relation contains a valid constituent of the In_Out_State.
24488
24489 if Is_In_Out_State_Clause then
24490
24491 -- Depends => (State => State)
24492 -- Refined_Depends => (null => Constit) -- OK
24493
24494 if Inputs_Match
24495 and then not Outputs_Match
24496 and then Nkind (Ref_Output) = N_Null
24497 then
24498 Outputs_Match := True;
24499 end if;
24500
24501 -- Depends => (State => State)
24502 -- Refined_Depends => (Constit => null) -- OK
24503
24504 if not Inputs_Match
24505 and then Outputs_Match
24506 and then Nkind (Ref_Input) = N_Null
24507 then
24508 Inputs_Match := True;
24509 end if;
24510 end if;
24511
24512 -- The current refinement clause is legally constructed following
24513 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
24514 -- the pool of candidates. The seach continues because a single
24515 -- dependence clause may have multiple matching refinements.
24516
24517 if Inputs_Match and Outputs_Match then
24518 Clause_Matched := True;
24519 Remove (Ref_Clause);
24520 end if;
24521
24522 Ref_Clause := Next_Ref_Clause;
24523 end loop;
24524
24525 -- Depending on the order or composition of refinement clauses, an
24526 -- In_Out state clause may not be directly refinable.
24527
24528 -- Refined_State => (State => (Constit_1, Constit_2))
24529 -- Depends => ((Output, State) => (Input, State))
24530 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
24531
24532 -- Matching normalized clause (State => State) fails because there is
24533 -- no direct refinement capable of satisfying this relation. Another
24534 -- similar case arises when clauses (Constit_1 => Input) and (Output
24535 -- => Constit_2) are matched first, leaving no candidates for clause
24536 -- (State => State). Both scenarios are legal as long as one of the
24537 -- previous clauses mentioned a valid constituent of State.
24538
24539 if not Clause_Matched
24540 and then Is_In_Out_State_Clause
24541 and then Is_Already_Matched (Dep_Input)
24542 then
24543 Clause_Matched := True;
24544 end if;
24545
24546 -- A clause where the input is an abstract state with visible null
24547 -- refinement or a 'Result attribute is implicitly matched when the
24548 -- output has already been matched in a previous clause.
24549
24550 -- Refined_State => (State => null)
24551 -- Depends => (Output => State) -- implicitly OK
24552 -- Refined_Depends => (Output => ...)
24553 -- Depends => (...'Result => State) -- implicitly OK
24554 -- Refined_Depends => (...'Result => ...)
24555
24556 if not Clause_Matched
24557 and then Is_Null_Refined_State (Dep_Input)
24558 and then Is_Already_Matched (Dep_Output)
24559 then
24560 Clause_Matched := True;
24561 end if;
24562
24563 -- A clause where the output is an abstract state with visible null
24564 -- refinement is implicitly matched when the input has already been
24565 -- matched in a previous clause.
24566
24567 -- Refined_State => (State => null)
24568 -- Depends => (State => Input) -- implicitly OK
24569 -- Refined_Depends => (... => Input)
24570
24571 if not Clause_Matched
24572 and then Is_Null_Refined_State (Dep_Output)
24573 and then Is_Already_Matched (Dep_Input)
24574 then
24575 Clause_Matched := True;
24576 end if;
24577
24578 -- At this point either all refinement clauses have been examined or
24579 -- pragma Refined_Depends contains a solitary null. Only an abstract
24580 -- state with null refinement can possibly match these cases.
24581
24582 -- Refined_State => (State => null)
24583 -- Depends => (State => null)
24584 -- Refined_Depends => null -- OK
24585
24586 if not Clause_Matched then
24587 Match_Items
24588 (Dep_Item => Dep_Input,
24589 Ref_Item => Empty,
24590 Matched => Inputs_Match);
24591
24592 Match_Items
24593 (Dep_Item => Dep_Output,
24594 Ref_Item => Empty,
24595 Matched => Outputs_Match);
24596
24597 Clause_Matched := Inputs_Match and Outputs_Match;
24598 end if;
24599
24600 -- If the contents of Refined_Depends are legal, then the current
24601 -- dependence clause should be satisfied either by an explicit match
24602 -- or by one of the special cases.
24603
24604 if not Clause_Matched then
24605 SPARK_Msg_NE
24606 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
24607 & "matching refinement in body"), Dep_Clause, Spec_Id);
24608 end if;
24609 end Check_Dependency_Clause;
24610
24611 -------------------------
24612 -- Check_Output_States --
24613 -------------------------
24614
24615 procedure Check_Output_States
24616 (Spec_Id : Entity_Id;
24617 Spec_Inputs : Elist_Id;
24618 Spec_Outputs : Elist_Id;
24619 Body_Inputs : Elist_Id;
24620 Body_Outputs : Elist_Id)
24621 is
24622 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24623 -- Determine whether all constituents of state State_Id with full
24624 -- visible refinement are used as outputs in pragma Refined_Depends.
24625 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
24626
24627 -----------------------------
24628 -- Check_Constituent_Usage --
24629 -----------------------------
24630
24631 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24632 Constits : constant Elist_Id :=
24633 Partial_Refinement_Constituents (State_Id);
24634 Constit_Elmt : Elmt_Id;
24635 Constit_Id : Entity_Id;
24636 Only_Partial : constant Boolean :=
24637 not Has_Visible_Refinement (State_Id);
24638 Posted : Boolean := False;
24639
24640 begin
24641 if Present (Constits) then
24642 Constit_Elmt := First_Elmt (Constits);
24643 while Present (Constit_Elmt) loop
24644 Constit_Id := Node (Constit_Elmt);
24645
24646 -- Issue an error when a constituent of State_Id is used,
24647 -- and State_Id has only partial visible refinement
24648 -- (SPARK RM 7.2.4(3d)).
24649
24650 if Only_Partial then
24651 if (Present (Body_Inputs)
24652 and then Appears_In (Body_Inputs, Constit_Id))
24653 or else
24654 (Present (Body_Outputs)
24655 and then Appears_In (Body_Outputs, Constit_Id))
24656 then
24657 Error_Msg_Name_1 := Chars (State_Id);
24658 SPARK_Msg_NE
24659 ("constituent & of state % cannot be used in "
24660 & "dependence refinement", N, Constit_Id);
24661 Error_Msg_Name_1 := Chars (State_Id);
24662 SPARK_Msg_N ("\use state % instead", N);
24663 end if;
24664
24665 -- The constituent acts as an input (SPARK RM 7.2.5(3))
24666
24667 elsif Present (Body_Inputs)
24668 and then Appears_In (Body_Inputs, Constit_Id)
24669 then
24670 Error_Msg_Name_1 := Chars (State_Id);
24671 SPARK_Msg_NE
24672 ("constituent & of state % must act as output in "
24673 & "dependence refinement", N, Constit_Id);
24674
24675 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24676
24677 elsif No (Body_Outputs)
24678 or else not Appears_In (Body_Outputs, Constit_Id)
24679 then
24680 if not Posted then
24681 Posted := True;
24682 SPARK_Msg_NE
24683 ("output state & must be replaced by all its "
24684 & "constituents in dependence refinement",
24685 N, State_Id);
24686 end if;
24687
24688 SPARK_Msg_NE
24689 ("\constituent & is missing in output list",
24690 N, Constit_Id);
24691 end if;
24692
24693 Next_Elmt (Constit_Elmt);
24694 end loop;
24695 end if;
24696 end Check_Constituent_Usage;
24697
24698 -- Local variables
24699
24700 Item : Node_Id;
24701 Item_Elmt : Elmt_Id;
24702 Item_Id : Entity_Id;
24703
24704 -- Start of processing for Check_Output_States
24705
24706 begin
24707 -- Do not perform this check in an instance because it was already
24708 -- performed successfully in the generic template.
24709
24710 if Is_Generic_Instance (Spec_Id) then
24711 null;
24712
24713 -- Inspect the outputs of pragma Depends looking for a state with a
24714 -- visible refinement.
24715
24716 elsif Present (Spec_Outputs) then
24717 Item_Elmt := First_Elmt (Spec_Outputs);
24718 while Present (Item_Elmt) loop
24719 Item := Node (Item_Elmt);
24720
24721 -- Deal with the mixed nature of the input and output lists
24722
24723 if Nkind (Item) = N_Defining_Identifier then
24724 Item_Id := Item;
24725 else
24726 Item_Id := Available_View (Entity_Of (Item));
24727 end if;
24728
24729 if Ekind (Item_Id) = E_Abstract_State then
24730
24731 -- The state acts as an input-output, skip it
24732
24733 if Present (Spec_Inputs)
24734 and then Appears_In (Spec_Inputs, Item_Id)
24735 then
24736 null;
24737
24738 -- Ensure that all of the constituents are utilized as
24739 -- outputs in pragma Refined_Depends.
24740
24741 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
24742 Check_Constituent_Usage (Item_Id);
24743 end if;
24744 end if;
24745
24746 Next_Elmt (Item_Elmt);
24747 end loop;
24748 end if;
24749 end Check_Output_States;
24750
24751 --------------------
24752 -- Collect_States --
24753 --------------------
24754
24755 function Collect_States (Clauses : List_Id) return Elist_Id is
24756 procedure Collect_State
24757 (Item : Node_Id;
24758 States : in out Elist_Id);
24759 -- Add the entity of Item to list States when it denotes to a state
24760
24761 -------------------
24762 -- Collect_State --
24763 -------------------
24764
24765 procedure Collect_State
24766 (Item : Node_Id;
24767 States : in out Elist_Id)
24768 is
24769 Id : Entity_Id;
24770
24771 begin
24772 if Is_Entity_Name (Item) then
24773 Id := Entity_Of (Item);
24774
24775 if Ekind (Id) = E_Abstract_State then
24776 if No (States) then
24777 States := New_Elmt_List;
24778 end if;
24779
24780 Append_Unique_Elmt (Id, States);
24781 end if;
24782 end if;
24783 end Collect_State;
24784
24785 -- Local variables
24786
24787 Clause : Node_Id;
24788 Input : Node_Id;
24789 Output : Node_Id;
24790 States : Elist_Id := No_Elist;
24791
24792 -- Start of processing for Collect_States
24793
24794 begin
24795 Clause := First (Clauses);
24796 while Present (Clause) loop
24797 Input := Expression (Clause);
24798 Output := First (Choices (Clause));
24799
24800 Collect_State (Input, States);
24801 Collect_State (Output, States);
24802
24803 Next (Clause);
24804 end loop;
24805
24806 return States;
24807 end Collect_States;
24808
24809 -----------------------
24810 -- Normalize_Clauses --
24811 -----------------------
24812
24813 procedure Normalize_Clauses (Clauses : List_Id) is
24814 procedure Normalize_Inputs (Clause : Node_Id);
24815 -- Normalize clause Clause by creating multiple clauses for each
24816 -- input item of Clause. It is assumed that Clause has exactly one
24817 -- output. The transformation is as follows:
24818 --
24819 -- Output => (Input_1, Input_2) -- original
24820 --
24821 -- Output => Input_1 -- normalizations
24822 -- Output => Input_2
24823
24824 procedure Normalize_Outputs (Clause : Node_Id);
24825 -- Normalize clause Clause by creating multiple clause for each
24826 -- output item of Clause. The transformation is as follows:
24827 --
24828 -- (Output_1, Output_2) => Input -- original
24829 --
24830 -- Output_1 => Input -- normalization
24831 -- Output_2 => Input
24832
24833 ----------------------
24834 -- Normalize_Inputs --
24835 ----------------------
24836
24837 procedure Normalize_Inputs (Clause : Node_Id) is
24838 Inputs : constant Node_Id := Expression (Clause);
24839 Loc : constant Source_Ptr := Sloc (Clause);
24840 Output : constant List_Id := Choices (Clause);
24841 Last_Input : Node_Id;
24842 Input : Node_Id;
24843 New_Clause : Node_Id;
24844 Next_Input : Node_Id;
24845
24846 begin
24847 -- Normalization is performed only when the original clause has
24848 -- more than one input. Multiple inputs appear as an aggregate.
24849
24850 if Nkind (Inputs) = N_Aggregate then
24851 Last_Input := Last (Expressions (Inputs));
24852
24853 -- Create a new clause for each input
24854
24855 Input := First (Expressions (Inputs));
24856 while Present (Input) loop
24857 Next_Input := Next (Input);
24858
24859 -- Unhook the current input from the original input list
24860 -- because it will be relocated to a new clause.
24861
24862 Remove (Input);
24863
24864 -- Special processing for the last input. At this point the
24865 -- original aggregate has been stripped down to one element.
24866 -- Replace the aggregate by the element itself.
24867
24868 if Input = Last_Input then
24869 Rewrite (Inputs, Input);
24870
24871 -- Generate a clause of the form:
24872 -- Output => Input
24873
24874 else
24875 New_Clause :=
24876 Make_Component_Association (Loc,
24877 Choices => New_Copy_List_Tree (Output),
24878 Expression => Input);
24879
24880 -- The new clause contains replicated content that has
24881 -- already been analyzed, mark the clause as analyzed.
24882
24883 Set_Analyzed (New_Clause);
24884 Insert_After (Clause, New_Clause);
24885 end if;
24886
24887 Input := Next_Input;
24888 end loop;
24889 end if;
24890 end Normalize_Inputs;
24891
24892 -----------------------
24893 -- Normalize_Outputs --
24894 -----------------------
24895
24896 procedure Normalize_Outputs (Clause : Node_Id) is
24897 Inputs : constant Node_Id := Expression (Clause);
24898 Loc : constant Source_Ptr := Sloc (Clause);
24899 Outputs : constant Node_Id := First (Choices (Clause));
24900 Last_Output : Node_Id;
24901 New_Clause : Node_Id;
24902 Next_Output : Node_Id;
24903 Output : Node_Id;
24904
24905 begin
24906 -- Multiple outputs appear as an aggregate. Nothing to do when
24907 -- the clause has exactly one output.
24908
24909 if Nkind (Outputs) = N_Aggregate then
24910 Last_Output := Last (Expressions (Outputs));
24911
24912 -- Create a clause for each output. Note that each time a new
24913 -- clause is created, the original output list slowly shrinks
24914 -- until there is one item left.
24915
24916 Output := First (Expressions (Outputs));
24917 while Present (Output) loop
24918 Next_Output := Next (Output);
24919
24920 -- Unhook the output from the original output list as it
24921 -- will be relocated to a new clause.
24922
24923 Remove (Output);
24924
24925 -- Special processing for the last output. At this point
24926 -- the original aggregate has been stripped down to one
24927 -- element. Replace the aggregate by the element itself.
24928
24929 if Output = Last_Output then
24930 Rewrite (Outputs, Output);
24931
24932 else
24933 -- Generate a clause of the form:
24934 -- (Output => Inputs)
24935
24936 New_Clause :=
24937 Make_Component_Association (Loc,
24938 Choices => New_List (Output),
24939 Expression => New_Copy_Tree (Inputs));
24940
24941 -- The new clause contains replicated content that has
24942 -- already been analyzed. There is not need to reanalyze
24943 -- them.
24944
24945 Set_Analyzed (New_Clause);
24946 Insert_After (Clause, New_Clause);
24947 end if;
24948
24949 Output := Next_Output;
24950 end loop;
24951 end if;
24952 end Normalize_Outputs;
24953
24954 -- Local variables
24955
24956 Clause : Node_Id;
24957
24958 -- Start of processing for Normalize_Clauses
24959
24960 begin
24961 Clause := First (Clauses);
24962 while Present (Clause) loop
24963 Normalize_Outputs (Clause);
24964 Next (Clause);
24965 end loop;
24966
24967 Clause := First (Clauses);
24968 while Present (Clause) loop
24969 Normalize_Inputs (Clause);
24970 Next (Clause);
24971 end loop;
24972 end Normalize_Clauses;
24973
24974 --------------------------
24975 -- Remove_Extra_Clauses --
24976 --------------------------
24977
24978 procedure Remove_Extra_Clauses
24979 (Clauses : List_Id;
24980 Matched_Items : Elist_Id)
24981 is
24982 Clause : Node_Id;
24983 Input : Node_Id;
24984 Input_Id : Entity_Id;
24985 Next_Clause : Node_Id;
24986 Output : Node_Id;
24987 State_Id : Entity_Id;
24988
24989 begin
24990 Clause := First (Clauses);
24991 while Present (Clause) loop
24992 Next_Clause := Next (Clause);
24993
24994 Input := Expression (Clause);
24995 Output := First (Choices (Clause));
24996
24997 -- Recognize a clause of the form
24998
24999 -- null => Input
25000
25001 -- where Input is a constituent of a state which was already
25002 -- successfully matched. This clause must be removed because it
25003 -- simply indicates that some of the constituents of the state
25004 -- are not used.
25005
25006 -- Refined_State => (State => (Constit_1, Constit_2))
25007 -- Depends => (Output => State)
25008 -- Refined_Depends => ((Output => Constit_1), -- State matched
25009 -- (null => Constit_2)) -- OK
25010
25011 if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then
25012
25013 -- Handle abstract views generated for limited with clauses
25014
25015 Input_Id := Available_View (Entity_Of (Input));
25016
25017 -- The input must be a constituent of a state
25018
25019 if Ekind_In (Input_Id, E_Abstract_State,
25020 E_Constant,
25021 E_Variable)
25022 and then Present (Encapsulating_State (Input_Id))
25023 then
25024 State_Id := Encapsulating_State (Input_Id);
25025
25026 -- The state must have a non-null visible refinement and be
25027 -- matched in a previous clause.
25028
25029 if Has_Non_Null_Visible_Refinement (State_Id)
25030 and then Contains (Matched_Items, State_Id)
25031 then
25032 Remove (Clause);
25033 end if;
25034 end if;
25035
25036 -- Recognize a clause of the form
25037
25038 -- Output => null
25039
25040 -- where Output is an arbitrary item. This clause must be removed
25041 -- because a null input legitimately matches anything.
25042
25043 elsif Nkind (Input) = N_Null then
25044 Remove (Clause);
25045 end if;
25046
25047 Clause := Next_Clause;
25048 end loop;
25049 end Remove_Extra_Clauses;
25050
25051 --------------------------
25052 -- Report_Extra_Clauses --
25053 --------------------------
25054
25055 procedure Report_Extra_Clauses
25056 (Spec_Id : Entity_Id;
25057 Clauses : List_Id)
25058 is
25059 Clause : Node_Id;
25060
25061 begin
25062 -- Do not perform this check in an instance because it was already
25063 -- performed successfully in the generic template.
25064
25065 if Is_Generic_Instance (Spec_Id) then
25066 null;
25067
25068 elsif Present (Clauses) then
25069 Clause := First (Clauses);
25070 while Present (Clause) loop
25071 SPARK_Msg_N
25072 ("unmatched or extra clause in dependence refinement",
25073 Clause);
25074
25075 Next (Clause);
25076 end loop;
25077 end if;
25078 end Report_Extra_Clauses;
25079
25080 -- Local variables
25081
25082 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25083 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
25084 Errors : constant Nat := Serious_Errors_Detected;
25085
25086 Clause : Node_Id;
25087 Deps : Node_Id;
25088 Dummy : Boolean;
25089 Refs : Node_Id;
25090
25091 Body_Inputs : Elist_Id := No_Elist;
25092 Body_Outputs : Elist_Id := No_Elist;
25093 -- The inputs and outputs of the subprogram body synthesized from pragma
25094 -- Refined_Depends.
25095
25096 Dependencies : List_Id := No_List;
25097 Depends : Node_Id;
25098 -- The corresponding Depends pragma along with its clauses
25099
25100 Matched_Items : Elist_Id := No_Elist;
25101 -- A list containing the entities of all successfully matched items
25102 -- found in pragma Depends.
25103
25104 Refinements : List_Id := No_List;
25105 -- The clauses of pragma Refined_Depends
25106
25107 Spec_Id : Entity_Id;
25108 -- The entity of the subprogram subject to pragma Refined_Depends
25109
25110 Spec_Inputs : Elist_Id := No_Elist;
25111 Spec_Outputs : Elist_Id := No_Elist;
25112 -- The inputs and outputs of the subprogram spec synthesized from pragma
25113 -- Depends.
25114
25115 States : Elist_Id := No_Elist;
25116 -- A list containing the entities of all states whose constituents
25117 -- appear in pragma Depends.
25118
25119 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
25120
25121 begin
25122 -- Do not analyze the pragma multiple times
25123
25124 if Is_Analyzed_Pragma (N) then
25125 return;
25126 end if;
25127
25128 Spec_Id := Unique_Defining_Entity (Body_Decl);
25129
25130 -- Use the anonymous object as the proper spec when Refined_Depends
25131 -- applies to the body of a single task type. The object carries the
25132 -- proper Chars as well as all non-refined versions of pragmas.
25133
25134 if Is_Single_Concurrent_Type (Spec_Id) then
25135 Spec_Id := Anonymous_Object (Spec_Id);
25136 end if;
25137
25138 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
25139
25140 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
25141 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
25142
25143 if No (Depends) then
25144 SPARK_Msg_NE
25145 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
25146 & "& lacks aspect or pragma Depends"), N, Spec_Id);
25147 goto Leave;
25148 end if;
25149
25150 Deps := Expression (Get_Argument (Depends, Spec_Id));
25151
25152 -- A null dependency relation renders the refinement useless because it
25153 -- cannot possibly mention abstract states with visible refinement. Note
25154 -- that the inverse is not true as states may be refined to null
25155 -- (SPARK RM 7.2.5(2)).
25156
25157 if Nkind (Deps) = N_Null then
25158 SPARK_Msg_NE
25159 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
25160 & "depend on abstract state with visible refinement"), N, Spec_Id);
25161 goto Leave;
25162 end if;
25163
25164 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
25165 -- This ensures that the categorization of all refined dependency items
25166 -- is consistent with their role.
25167
25168 Analyze_Depends_In_Decl_Part (N);
25169
25170 -- Do not match dependencies against refinements if Refined_Depends is
25171 -- illegal to avoid emitting misleading error.
25172
25173 if Serious_Errors_Detected = Errors then
25174
25175 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
25176 -- the inputs and outputs of the subprogram spec and body to verify
25177 -- the use of states with visible refinement and their constituents.
25178
25179 if No (Get_Pragma (Spec_Id, Pragma_Global))
25180 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
25181 then
25182 Collect_Subprogram_Inputs_Outputs
25183 (Subp_Id => Spec_Id,
25184 Synthesize => True,
25185 Subp_Inputs => Spec_Inputs,
25186 Subp_Outputs => Spec_Outputs,
25187 Global_Seen => Dummy);
25188
25189 Collect_Subprogram_Inputs_Outputs
25190 (Subp_Id => Body_Id,
25191 Synthesize => True,
25192 Subp_Inputs => Body_Inputs,
25193 Subp_Outputs => Body_Outputs,
25194 Global_Seen => Dummy);
25195
25196 -- For an output state with a visible refinement, ensure that all
25197 -- constituents appear as outputs in the dependency refinement.
25198
25199 Check_Output_States
25200 (Spec_Id => Spec_Id,
25201 Spec_Inputs => Spec_Inputs,
25202 Spec_Outputs => Spec_Outputs,
25203 Body_Inputs => Body_Inputs,
25204 Body_Outputs => Body_Outputs);
25205 end if;
25206
25207 -- Matching is disabled in ASIS because clauses are not normalized as
25208 -- this is a tree altering activity similar to expansion.
25209
25210 if ASIS_Mode then
25211 goto Leave;
25212 end if;
25213
25214 -- Multiple dependency clauses appear as component associations of an
25215 -- aggregate. Note that the clauses are copied because the algorithm
25216 -- modifies them and this should not be visible in Depends.
25217
25218 pragma Assert (Nkind (Deps) = N_Aggregate);
25219 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
25220 Normalize_Clauses (Dependencies);
25221
25222 -- Gather all states which appear in Depends
25223
25224 States := Collect_States (Dependencies);
25225
25226 Refs := Expression (Get_Argument (N, Spec_Id));
25227
25228 if Nkind (Refs) = N_Null then
25229 Refinements := No_List;
25230
25231 -- Multiple dependency clauses appear as component associations of an
25232 -- aggregate. Note that the clauses are copied because the algorithm
25233 -- modifies them and this should not be visible in Refined_Depends.
25234
25235 else pragma Assert (Nkind (Refs) = N_Aggregate);
25236 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
25237 Normalize_Clauses (Refinements);
25238 end if;
25239
25240 -- At this point the clauses of pragmas Depends and Refined_Depends
25241 -- have been normalized into simple dependencies between one output
25242 -- and one input. Examine all clauses of pragma Depends looking for
25243 -- matching clauses in pragma Refined_Depends.
25244
25245 Clause := First (Dependencies);
25246 while Present (Clause) loop
25247 Check_Dependency_Clause
25248 (Spec_Id => Spec_Id,
25249 Dep_Clause => Clause,
25250 Dep_States => States,
25251 Refinements => Refinements,
25252 Matched_Items => Matched_Items);
25253
25254 Next (Clause);
25255 end loop;
25256
25257 -- Pragma Refined_Depends may contain multiple clarification clauses
25258 -- which indicate that certain constituents do not influence the data
25259 -- flow in any way. Such clauses must be removed as long as the state
25260 -- has been matched, otherwise they will be incorrectly flagged as
25261 -- unmatched.
25262
25263 -- Refined_State => (State => (Constit_1, Constit_2))
25264 -- Depends => (Output => State)
25265 -- Refined_Depends => ((Output => Constit_1), -- State matched
25266 -- (null => Constit_2)) -- must be removed
25267
25268 Remove_Extra_Clauses (Refinements, Matched_Items);
25269
25270 if Serious_Errors_Detected = Errors then
25271 Report_Extra_Clauses (Spec_Id, Refinements);
25272 end if;
25273 end if;
25274
25275 <<Leave>>
25276 Set_Is_Analyzed_Pragma (N);
25277 end Analyze_Refined_Depends_In_Decl_Part;
25278
25279 -----------------------------------------
25280 -- Analyze_Refined_Global_In_Decl_Part --
25281 -----------------------------------------
25282
25283 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
25284 Global : Node_Id;
25285 -- The corresponding Global pragma
25286
25287 Has_In_State : Boolean := False;
25288 Has_In_Out_State : Boolean := False;
25289 Has_Out_State : Boolean := False;
25290 Has_Proof_In_State : Boolean := False;
25291 -- These flags are set when the corresponding Global pragma has a state
25292 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
25293 -- refinement.
25294
25295 Has_Null_State : Boolean := False;
25296 -- This flag is set when the corresponding Global pragma has at least
25297 -- one state with a null refinement.
25298
25299 In_Constits : Elist_Id := No_Elist;
25300 In_Out_Constits : Elist_Id := No_Elist;
25301 Out_Constits : Elist_Id := No_Elist;
25302 Proof_In_Constits : Elist_Id := No_Elist;
25303 -- These lists contain the entities of all Input, In_Out, Output and
25304 -- Proof_In constituents that appear in Refined_Global and participate
25305 -- in state refinement.
25306
25307 In_Items : Elist_Id := No_Elist;
25308 In_Out_Items : Elist_Id := No_Elist;
25309 Out_Items : Elist_Id := No_Elist;
25310 Proof_In_Items : Elist_Id := No_Elist;
25311 -- These lists contain the entities of all Input, In_Out, Output and
25312 -- Proof_In items defined in the corresponding Global pragma.
25313
25314 Repeat_Items : Elist_Id := No_Elist;
25315 -- A list of all global items without full visible refinement found
25316 -- in pragma Global. These states should be repeated in the global
25317 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
25318 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
25319
25320 Spec_Id : Entity_Id;
25321 -- The entity of the subprogram subject to pragma Refined_Global
25322
25323 States : Elist_Id := No_Elist;
25324 -- A list of all states with full or partial visible refinement found in
25325 -- pragma Global.
25326
25327 procedure Check_In_Out_States;
25328 -- Determine whether the corresponding Global pragma mentions In_Out
25329 -- states with visible refinement and if so, ensure that one of the
25330 -- following completions apply to the constituents of the state:
25331 -- 1) there is at least one constituent of mode In_Out
25332 -- 2) there is at least one Input and one Output constituent
25333 -- 3) not all constituents are present and one of them is of mode
25334 -- Output.
25335 -- This routine may remove elements from In_Constits, In_Out_Constits,
25336 -- Out_Constits and Proof_In_Constits.
25337
25338 procedure Check_Input_States;
25339 -- Determine whether the corresponding Global pragma mentions Input
25340 -- states with visible refinement and if so, ensure that at least one of
25341 -- its constituents appears as an Input item in Refined_Global.
25342 -- This routine may remove elements from In_Constits, In_Out_Constits,
25343 -- Out_Constits and Proof_In_Constits.
25344
25345 procedure Check_Output_States;
25346 -- Determine whether the corresponding Global pragma mentions Output
25347 -- states with visible refinement and if so, ensure that all of its
25348 -- constituents appear as Output items in Refined_Global.
25349 -- This routine may remove elements from In_Constits, In_Out_Constits,
25350 -- Out_Constits and Proof_In_Constits.
25351
25352 procedure Check_Proof_In_States;
25353 -- Determine whether the corresponding Global pragma mentions Proof_In
25354 -- states with visible refinement and if so, ensure that at least one of
25355 -- its constituents appears as a Proof_In item in Refined_Global.
25356 -- This routine may remove elements from In_Constits, In_Out_Constits,
25357 -- Out_Constits and Proof_In_Constits.
25358
25359 procedure Check_Refined_Global_List
25360 (List : Node_Id;
25361 Global_Mode : Name_Id := Name_Input);
25362 -- Verify the legality of a single global list declaration. Global_Mode
25363 -- denotes the current mode in effect.
25364
25365 procedure Collect_Global_Items
25366 (List : Node_Id;
25367 Mode : Name_Id := Name_Input);
25368 -- Gather all Input, In_Out, Output and Proof_In items from node List
25369 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
25370 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
25371 -- and Has_Proof_In_State are set when there is at least one abstract
25372 -- state with full or partial visible refinement available in the
25373 -- corresponding mode. Flag Has_Null_State is set when at least state
25374 -- has a null refinement. Mode denotes the current global mode in
25375 -- effect.
25376
25377 function Present_Then_Remove
25378 (List : Elist_Id;
25379 Item : Entity_Id) return Boolean;
25380 -- Search List for a particular entity Item. If Item has been found,
25381 -- remove it from List. This routine is used to strip lists In_Constits,
25382 -- In_Out_Constits and Out_Constits of valid constituents.
25383
25384 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id);
25385 -- Same as function Present_Then_Remove, but do not report the presence
25386 -- of Item in List.
25387
25388 procedure Report_Extra_Constituents;
25389 -- Emit an error for each constituent found in lists In_Constits,
25390 -- In_Out_Constits and Out_Constits.
25391
25392 procedure Report_Missing_Items;
25393 -- Emit an error for each global item not repeated found in list
25394 -- Repeat_Items.
25395
25396 -------------------------
25397 -- Check_In_Out_States --
25398 -------------------------
25399
25400 procedure Check_In_Out_States is
25401 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25402 -- Determine whether one of the following coverage scenarios is in
25403 -- effect:
25404 -- 1) there is at least one constituent of mode In_Out or Output
25405 -- 2) there is at least one pair of constituents with modes Input
25406 -- and Output, or Proof_In and Output.
25407 -- 3) there is at least one constituent of mode Output and not all
25408 -- constituents are present.
25409 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
25410
25411 -----------------------------
25412 -- Check_Constituent_Usage --
25413 -----------------------------
25414
25415 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25416 Constits : constant Elist_Id :=
25417 Partial_Refinement_Constituents (State_Id);
25418 Constit_Elmt : Elmt_Id;
25419 Constit_Id : Entity_Id;
25420 Has_Missing : Boolean := False;
25421 In_Out_Seen : Boolean := False;
25422 Input_Seen : Boolean := False;
25423 Output_Seen : Boolean := False;
25424 Proof_In_Seen : Boolean := False;
25425
25426 begin
25427 -- Process all the constituents of the state and note their modes
25428 -- within the global refinement.
25429
25430 if Present (Constits) then
25431 Constit_Elmt := First_Elmt (Constits);
25432 while Present (Constit_Elmt) loop
25433 Constit_Id := Node (Constit_Elmt);
25434
25435 if Present_Then_Remove (In_Constits, Constit_Id) then
25436 Input_Seen := True;
25437
25438 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
25439 In_Out_Seen := True;
25440
25441 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
25442 Output_Seen := True;
25443
25444 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
25445 then
25446 Proof_In_Seen := True;
25447
25448 else
25449 Has_Missing := True;
25450 end if;
25451
25452 Next_Elmt (Constit_Elmt);
25453 end loop;
25454 end if;
25455
25456 -- An In_Out constituent is a valid completion
25457
25458 if In_Out_Seen then
25459 null;
25460
25461 -- A pair of one Input/Proof_In and one Output constituent is a
25462 -- valid completion.
25463
25464 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
25465 null;
25466
25467 elsif Output_Seen then
25468
25469 -- A single Output constituent is a valid completion only when
25470 -- some of the other constituents are missing.
25471
25472 if Has_Missing then
25473 null;
25474
25475 -- Otherwise all constituents are of mode Output
25476
25477 else
25478 SPARK_Msg_NE
25479 ("global refinement of state & must include at least one "
25480 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
25481 N, State_Id);
25482 end if;
25483
25484 -- The state lacks a completion. When full refinement is visible,
25485 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
25486 -- refinement is visible, emit an error if the abstract state
25487 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
25488 -- both are utilized, Check_State_And_Constituent_Use. will issue
25489 -- the error.
25490
25491 elsif not Input_Seen
25492 and then not In_Out_Seen
25493 and then not Output_Seen
25494 and then not Proof_In_Seen
25495 then
25496 if Has_Visible_Refinement (State_Id)
25497 or else Contains (Repeat_Items, State_Id)
25498 then
25499 SPARK_Msg_NE
25500 ("missing global refinement of state &", N, State_Id);
25501 end if;
25502
25503 -- Otherwise the state has a malformed completion where at least
25504 -- one of the constituents has a different mode.
25505
25506 else
25507 SPARK_Msg_NE
25508 ("global refinement of state & redefines the mode of its "
25509 & "constituents", N, State_Id);
25510 end if;
25511 end Check_Constituent_Usage;
25512
25513 -- Local variables
25514
25515 Item_Elmt : Elmt_Id;
25516 Item_Id : Entity_Id;
25517
25518 -- Start of processing for Check_In_Out_States
25519
25520 begin
25521 -- Do not perform this check in an instance because it was already
25522 -- performed successfully in the generic template.
25523
25524 if Is_Generic_Instance (Spec_Id) then
25525 null;
25526
25527 -- Inspect the In_Out items of the corresponding Global pragma
25528 -- looking for a state with a visible refinement.
25529
25530 elsif Has_In_Out_State and then Present (In_Out_Items) then
25531 Item_Elmt := First_Elmt (In_Out_Items);
25532 while Present (Item_Elmt) loop
25533 Item_Id := Node (Item_Elmt);
25534
25535 -- Ensure that one of the three coverage variants is satisfied
25536
25537 if Ekind (Item_Id) = E_Abstract_State
25538 and then Has_Non_Null_Visible_Refinement (Item_Id)
25539 then
25540 Check_Constituent_Usage (Item_Id);
25541 end if;
25542
25543 Next_Elmt (Item_Elmt);
25544 end loop;
25545 end if;
25546 end Check_In_Out_States;
25547
25548 ------------------------
25549 -- Check_Input_States --
25550 ------------------------
25551
25552 procedure Check_Input_States is
25553 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25554 -- Determine whether at least one constituent of state State_Id with
25555 -- full or partial visible refinement is used and has mode Input.
25556 -- Ensure that the remaining constituents do not have In_Out or
25557 -- Output modes. Emit an error if this is not the case
25558 -- (SPARK RM 7.2.4(5)).
25559
25560 -----------------------------
25561 -- Check_Constituent_Usage --
25562 -----------------------------
25563
25564 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25565 Constits : constant Elist_Id :=
25566 Partial_Refinement_Constituents (State_Id);
25567 Constit_Elmt : Elmt_Id;
25568 Constit_Id : Entity_Id;
25569 In_Seen : Boolean := False;
25570
25571 begin
25572 if Present (Constits) then
25573 Constit_Elmt := First_Elmt (Constits);
25574 while Present (Constit_Elmt) loop
25575 Constit_Id := Node (Constit_Elmt);
25576
25577 -- At least one of the constituents appears as an Input
25578
25579 if Present_Then_Remove (In_Constits, Constit_Id) then
25580 In_Seen := True;
25581
25582 -- A Proof_In constituent can refine an Input state as long
25583 -- as there is at least one Input constituent present.
25584
25585 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
25586 then
25587 null;
25588
25589 -- The constituent appears in the global refinement, but has
25590 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
25591
25592 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
25593 or else Present_Then_Remove (Out_Constits, Constit_Id)
25594 then
25595 Error_Msg_Name_1 := Chars (State_Id);
25596 SPARK_Msg_NE
25597 ("constituent & of state % must have mode `Input` in "
25598 & "global refinement", N, Constit_Id);
25599 end if;
25600
25601 Next_Elmt (Constit_Elmt);
25602 end loop;
25603 end if;
25604
25605 -- Not one of the constituents appeared as Input. Always emit an
25606 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
25607 -- When only partial refinement is visible, emit an error if the
25608 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
25609 -- the case where both are utilized, an error will be issued in
25610 -- Check_State_And_Constituent_Use.
25611
25612 if not In_Seen
25613 and then (Has_Visible_Refinement (State_Id)
25614 or else Contains (Repeat_Items, State_Id))
25615 then
25616 SPARK_Msg_NE
25617 ("global refinement of state & must include at least one "
25618 & "constituent of mode `Input`", N, State_Id);
25619 end if;
25620 end Check_Constituent_Usage;
25621
25622 -- Local variables
25623
25624 Item_Elmt : Elmt_Id;
25625 Item_Id : Entity_Id;
25626
25627 -- Start of processing for Check_Input_States
25628
25629 begin
25630 -- Do not perform this check in an instance because it was already
25631 -- performed successfully in the generic template.
25632
25633 if Is_Generic_Instance (Spec_Id) then
25634 null;
25635
25636 -- Inspect the Input items of the corresponding Global pragma looking
25637 -- for a state with a visible refinement.
25638
25639 elsif Has_In_State and then Present (In_Items) then
25640 Item_Elmt := First_Elmt (In_Items);
25641 while Present (Item_Elmt) loop
25642 Item_Id := Node (Item_Elmt);
25643
25644 -- When full refinement is visible, ensure that at least one of
25645 -- the constituents is utilized and is of mode Input. When only
25646 -- partial refinement is visible, ensure that either one of
25647 -- the constituents is utilized and is of mode Input, or the
25648 -- abstract state is repeated and no constituent is utilized.
25649
25650 if Ekind (Item_Id) = E_Abstract_State
25651 and then Has_Non_Null_Visible_Refinement (Item_Id)
25652 then
25653 Check_Constituent_Usage (Item_Id);
25654 end if;
25655
25656 Next_Elmt (Item_Elmt);
25657 end loop;
25658 end if;
25659 end Check_Input_States;
25660
25661 -------------------------
25662 -- Check_Output_States --
25663 -------------------------
25664
25665 procedure Check_Output_States is
25666 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25667 -- Determine whether all constituents of state State_Id with full
25668 -- visible refinement are used and have mode Output. Emit an error
25669 -- if this is not the case (SPARK RM 7.2.4(5)).
25670
25671 -----------------------------
25672 -- Check_Constituent_Usage --
25673 -----------------------------
25674
25675 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25676 Constits : constant Elist_Id :=
25677 Partial_Refinement_Constituents (State_Id);
25678 Only_Partial : constant Boolean :=
25679 not Has_Visible_Refinement (State_Id);
25680 Constit_Elmt : Elmt_Id;
25681 Constit_Id : Entity_Id;
25682 Posted : Boolean := False;
25683
25684 begin
25685 if Present (Constits) then
25686 Constit_Elmt := First_Elmt (Constits);
25687 while Present (Constit_Elmt) loop
25688 Constit_Id := Node (Constit_Elmt);
25689
25690 -- Issue an error when a constituent of State_Id is utilized
25691 -- and State_Id has only partial visible refinement
25692 -- (SPARK RM 7.2.4(3d)).
25693
25694 if Only_Partial then
25695 if Present_Then_Remove (Out_Constits, Constit_Id)
25696 or else Present_Then_Remove (In_Constits, Constit_Id)
25697 or else
25698 Present_Then_Remove (In_Out_Constits, Constit_Id)
25699 or else
25700 Present_Then_Remove (Proof_In_Constits, Constit_Id)
25701 then
25702 Error_Msg_Name_1 := Chars (State_Id);
25703 SPARK_Msg_NE
25704 ("constituent & of state % cannot be used in global "
25705 & "refinement", N, Constit_Id);
25706 Error_Msg_Name_1 := Chars (State_Id);
25707 SPARK_Msg_N ("\use state % instead", N);
25708 end if;
25709
25710 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
25711 null;
25712
25713 -- The constituent appears in the global refinement, but has
25714 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
25715
25716 elsif Present_Then_Remove (In_Constits, Constit_Id)
25717 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
25718 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
25719 then
25720 Error_Msg_Name_1 := Chars (State_Id);
25721 SPARK_Msg_NE
25722 ("constituent & of state % must have mode `Output` in "
25723 & "global refinement", N, Constit_Id);
25724
25725 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
25726
25727 else
25728 if not Posted then
25729 Posted := True;
25730 SPARK_Msg_NE
25731 ("`Output` state & must be replaced by all its "
25732 & "constituents in global refinement", N, State_Id);
25733 end if;
25734
25735 SPARK_Msg_NE
25736 ("\constituent & is missing in output list",
25737 N, Constit_Id);
25738 end if;
25739
25740 Next_Elmt (Constit_Elmt);
25741 end loop;
25742 end if;
25743 end Check_Constituent_Usage;
25744
25745 -- Local variables
25746
25747 Item_Elmt : Elmt_Id;
25748 Item_Id : Entity_Id;
25749
25750 -- Start of processing for Check_Output_States
25751
25752 begin
25753 -- Do not perform this check in an instance because it was already
25754 -- performed successfully in the generic template.
25755
25756 if Is_Generic_Instance (Spec_Id) then
25757 null;
25758
25759 -- Inspect the Output items of the corresponding Global pragma
25760 -- looking for a state with a visible refinement.
25761
25762 elsif Has_Out_State and then Present (Out_Items) then
25763 Item_Elmt := First_Elmt (Out_Items);
25764 while Present (Item_Elmt) loop
25765 Item_Id := Node (Item_Elmt);
25766
25767 -- When full refinement is visible, ensure that all of the
25768 -- constituents are utilized and they have mode Output. When
25769 -- only partial refinement is visible, ensure that no
25770 -- constituent is utilized.
25771
25772 if Ekind (Item_Id) = E_Abstract_State
25773 and then Has_Non_Null_Visible_Refinement (Item_Id)
25774 then
25775 Check_Constituent_Usage (Item_Id);
25776 end if;
25777
25778 Next_Elmt (Item_Elmt);
25779 end loop;
25780 end if;
25781 end Check_Output_States;
25782
25783 ---------------------------
25784 -- Check_Proof_In_States --
25785 ---------------------------
25786
25787 procedure Check_Proof_In_States is
25788 procedure Check_Constituent_Usage (State_Id : Entity_Id);
25789 -- Determine whether at least one constituent of state State_Id with
25790 -- full or partial visible refinement is used and has mode Proof_In.
25791 -- Ensure that the remaining constituents do not have Input, In_Out,
25792 -- or Output modes. Emit an error if this is not the case
25793 -- (SPARK RM 7.2.4(5)).
25794
25795 -----------------------------
25796 -- Check_Constituent_Usage --
25797 -----------------------------
25798
25799 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
25800 Constits : constant Elist_Id :=
25801 Partial_Refinement_Constituents (State_Id);
25802 Constit_Elmt : Elmt_Id;
25803 Constit_Id : Entity_Id;
25804 Proof_In_Seen : Boolean := False;
25805
25806 begin
25807 if Present (Constits) then
25808 Constit_Elmt := First_Elmt (Constits);
25809 while Present (Constit_Elmt) loop
25810 Constit_Id := Node (Constit_Elmt);
25811
25812 -- At least one of the constituents appears as Proof_In
25813
25814 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
25815 Proof_In_Seen := True;
25816
25817 -- The constituent appears in the global refinement, but has
25818 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
25819
25820 elsif Present_Then_Remove (In_Constits, Constit_Id)
25821 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
25822 or else Present_Then_Remove (Out_Constits, Constit_Id)
25823 then
25824 Error_Msg_Name_1 := Chars (State_Id);
25825 SPARK_Msg_NE
25826 ("constituent & of state % must have mode `Proof_In` "
25827 & "in global refinement", N, Constit_Id);
25828 end if;
25829
25830 Next_Elmt (Constit_Elmt);
25831 end loop;
25832 end if;
25833
25834 -- Not one of the constituents appeared as Proof_In. Always emit
25835 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
25836 -- When only partial refinement is visible, emit an error if the
25837 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
25838 -- the case where both are utilized, an error will be issued by
25839 -- Check_State_And_Constituent_Use.
25840
25841 if not Proof_In_Seen
25842 and then (Has_Visible_Refinement (State_Id)
25843 or else Contains (Repeat_Items, State_Id))
25844 then
25845 SPARK_Msg_NE
25846 ("global refinement of state & must include at least one "
25847 & "constituent of mode `Proof_In`", N, State_Id);
25848 end if;
25849 end Check_Constituent_Usage;
25850
25851 -- Local variables
25852
25853 Item_Elmt : Elmt_Id;
25854 Item_Id : Entity_Id;
25855
25856 -- Start of processing for Check_Proof_In_States
25857
25858 begin
25859 -- Do not perform this check in an instance because it was already
25860 -- performed successfully in the generic template.
25861
25862 if Is_Generic_Instance (Spec_Id) then
25863 null;
25864
25865 -- Inspect the Proof_In items of the corresponding Global pragma
25866 -- looking for a state with a visible refinement.
25867
25868 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
25869 Item_Elmt := First_Elmt (Proof_In_Items);
25870 while Present (Item_Elmt) loop
25871 Item_Id := Node (Item_Elmt);
25872
25873 -- Ensure that at least one of the constituents is utilized
25874 -- and is of mode Proof_In. When only partial refinement is
25875 -- visible, ensure that either one of the constituents is
25876 -- utilized and is of mode Proof_In, or the abstract state
25877 -- is repeated and no constituent is utilized.
25878
25879 if Ekind (Item_Id) = E_Abstract_State
25880 and then Has_Non_Null_Visible_Refinement (Item_Id)
25881 then
25882 Check_Constituent_Usage (Item_Id);
25883 end if;
25884
25885 Next_Elmt (Item_Elmt);
25886 end loop;
25887 end if;
25888 end Check_Proof_In_States;
25889
25890 -------------------------------
25891 -- Check_Refined_Global_List --
25892 -------------------------------
25893
25894 procedure Check_Refined_Global_List
25895 (List : Node_Id;
25896 Global_Mode : Name_Id := Name_Input)
25897 is
25898 procedure Check_Refined_Global_Item
25899 (Item : Node_Id;
25900 Global_Mode : Name_Id);
25901 -- Verify the legality of a single global item declaration. Parameter
25902 -- Global_Mode denotes the current mode in effect.
25903
25904 -------------------------------
25905 -- Check_Refined_Global_Item --
25906 -------------------------------
25907
25908 procedure Check_Refined_Global_Item
25909 (Item : Node_Id;
25910 Global_Mode : Name_Id)
25911 is
25912 Item_Id : constant Entity_Id := Entity_Of (Item);
25913
25914 procedure Inconsistent_Mode_Error (Expect : Name_Id);
25915 -- Issue a common error message for all mode mismatches. Expect
25916 -- denotes the expected mode.
25917
25918 -----------------------------
25919 -- Inconsistent_Mode_Error --
25920 -----------------------------
25921
25922 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
25923 begin
25924 SPARK_Msg_NE
25925 ("global item & has inconsistent modes", Item, Item_Id);
25926
25927 Error_Msg_Name_1 := Global_Mode;
25928 Error_Msg_Name_2 := Expect;
25929 SPARK_Msg_N ("\expected mode %, found mode %", Item);
25930 end Inconsistent_Mode_Error;
25931
25932 -- Local variables
25933
25934 Enc_State : Entity_Id := Empty;
25935 -- Encapsulating state for constituent, Empty otherwise
25936
25937 -- Start of processing for Check_Refined_Global_Item
25938
25939 begin
25940 if Ekind_In (Item_Id, E_Abstract_State,
25941 E_Constant,
25942 E_Variable)
25943 then
25944 Enc_State := Find_Encapsulating_State (States, Item_Id);
25945 end if;
25946
25947 -- When the state or object acts as a constituent of another
25948 -- state with a visible refinement, collect it for the state
25949 -- completeness checks performed later on. Note that the item
25950 -- acts as a constituent only when the encapsulating state is
25951 -- present in pragma Global.
25952
25953 if Present (Enc_State)
25954 and then (Has_Visible_Refinement (Enc_State)
25955 or else Has_Partial_Visible_Refinement (Enc_State))
25956 and then Contains (States, Enc_State)
25957 then
25958 -- If the state has only partial visible refinement, remove it
25959 -- from the list of items that should be repeated from pragma
25960 -- Global.
25961
25962 if not Has_Visible_Refinement (Enc_State) then
25963 Present_Then_Remove (Repeat_Items, Enc_State);
25964 end if;
25965
25966 if Global_Mode = Name_Input then
25967 Append_New_Elmt (Item_Id, In_Constits);
25968
25969 elsif Global_Mode = Name_In_Out then
25970 Append_New_Elmt (Item_Id, In_Out_Constits);
25971
25972 elsif Global_Mode = Name_Output then
25973 Append_New_Elmt (Item_Id, Out_Constits);
25974
25975 elsif Global_Mode = Name_Proof_In then
25976 Append_New_Elmt (Item_Id, Proof_In_Constits);
25977 end if;
25978
25979 -- When not a constituent, ensure that both occurrences of the
25980 -- item in pragmas Global and Refined_Global match. Also remove
25981 -- it when present from the list of items that should be repeated
25982 -- from pragma Global.
25983
25984 else
25985 Present_Then_Remove (Repeat_Items, Item_Id);
25986
25987 if Contains (In_Items, Item_Id) then
25988 if Global_Mode /= Name_Input then
25989 Inconsistent_Mode_Error (Name_Input);
25990 end if;
25991
25992 elsif Contains (In_Out_Items, Item_Id) then
25993 if Global_Mode /= Name_In_Out then
25994 Inconsistent_Mode_Error (Name_In_Out);
25995 end if;
25996
25997 elsif Contains (Out_Items, Item_Id) then
25998 if Global_Mode /= Name_Output then
25999 Inconsistent_Mode_Error (Name_Output);
26000 end if;
26001
26002 elsif Contains (Proof_In_Items, Item_Id) then
26003 null;
26004
26005 -- The item does not appear in the corresponding Global pragma,
26006 -- it must be an extra (SPARK RM 7.2.4(3)).
26007
26008 else
26009 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
26010 end if;
26011 end if;
26012 end Check_Refined_Global_Item;
26013
26014 -- Local variables
26015
26016 Item : Node_Id;
26017
26018 -- Start of processing for Check_Refined_Global_List
26019
26020 begin
26021 -- Do not perform this check in an instance because it was already
26022 -- performed successfully in the generic template.
26023
26024 if Is_Generic_Instance (Spec_Id) then
26025 null;
26026
26027 elsif Nkind (List) = N_Null then
26028 null;
26029
26030 -- Single global item declaration
26031
26032 elsif Nkind_In (List, N_Expanded_Name,
26033 N_Identifier,
26034 N_Selected_Component)
26035 then
26036 Check_Refined_Global_Item (List, Global_Mode);
26037
26038 -- Simple global list or moded global list declaration
26039
26040 elsif Nkind (List) = N_Aggregate then
26041
26042 -- The declaration of a simple global list appear as a collection
26043 -- of expressions.
26044
26045 if Present (Expressions (List)) then
26046 Item := First (Expressions (List));
26047 while Present (Item) loop
26048 Check_Refined_Global_Item (Item, Global_Mode);
26049 Next (Item);
26050 end loop;
26051
26052 -- The declaration of a moded global list appears as a collection
26053 -- of component associations where individual choices denote
26054 -- modes.
26055
26056 elsif Present (Component_Associations (List)) then
26057 Item := First (Component_Associations (List));
26058 while Present (Item) loop
26059 Check_Refined_Global_List
26060 (List => Expression (Item),
26061 Global_Mode => Chars (First (Choices (Item))));
26062
26063 Next (Item);
26064 end loop;
26065
26066 -- Invalid tree
26067
26068 else
26069 raise Program_Error;
26070 end if;
26071
26072 -- Invalid list
26073
26074 else
26075 raise Program_Error;
26076 end if;
26077 end Check_Refined_Global_List;
26078
26079 --------------------------
26080 -- Collect_Global_Items --
26081 --------------------------
26082
26083 procedure Collect_Global_Items
26084 (List : Node_Id;
26085 Mode : Name_Id := Name_Input)
26086 is
26087 procedure Collect_Global_Item
26088 (Item : Node_Id;
26089 Item_Mode : Name_Id);
26090 -- Add a single item to the appropriate list. Item_Mode denotes the
26091 -- current mode in effect.
26092
26093 -------------------------
26094 -- Collect_Global_Item --
26095 -------------------------
26096
26097 procedure Collect_Global_Item
26098 (Item : Node_Id;
26099 Item_Mode : Name_Id)
26100 is
26101 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
26102 -- The above handles abstract views of variables and states built
26103 -- for limited with clauses.
26104
26105 begin
26106 -- Signal that the global list contains at least one abstract
26107 -- state with a visible refinement. Note that the refinement may
26108 -- be null in which case there are no constituents.
26109
26110 if Ekind (Item_Id) = E_Abstract_State then
26111 if Has_Null_Visible_Refinement (Item_Id) then
26112 Has_Null_State := True;
26113
26114 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
26115 Append_New_Elmt (Item_Id, States);
26116
26117 if Item_Mode = Name_Input then
26118 Has_In_State := True;
26119 elsif Item_Mode = Name_In_Out then
26120 Has_In_Out_State := True;
26121 elsif Item_Mode = Name_Output then
26122 Has_Out_State := True;
26123 elsif Item_Mode = Name_Proof_In then
26124 Has_Proof_In_State := True;
26125 end if;
26126 end if;
26127 end if;
26128
26129 -- Record global items without full visible refinement found in
26130 -- pragma Global which should be repeated in the global refinement
26131 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
26132
26133 if Ekind (Item_Id) /= E_Abstract_State
26134 or else not Has_Visible_Refinement (Item_Id)
26135 then
26136 Append_New_Elmt (Item_Id, Repeat_Items);
26137 end if;
26138
26139 -- Add the item to the proper list
26140
26141 if Item_Mode = Name_Input then
26142 Append_New_Elmt (Item_Id, In_Items);
26143 elsif Item_Mode = Name_In_Out then
26144 Append_New_Elmt (Item_Id, In_Out_Items);
26145 elsif Item_Mode = Name_Output then
26146 Append_New_Elmt (Item_Id, Out_Items);
26147 elsif Item_Mode = Name_Proof_In then
26148 Append_New_Elmt (Item_Id, Proof_In_Items);
26149 end if;
26150 end Collect_Global_Item;
26151
26152 -- Local variables
26153
26154 Item : Node_Id;
26155
26156 -- Start of processing for Collect_Global_Items
26157
26158 begin
26159 if Nkind (List) = N_Null then
26160 null;
26161
26162 -- Single global item declaration
26163
26164 elsif Nkind_In (List, N_Expanded_Name,
26165 N_Identifier,
26166 N_Selected_Component)
26167 then
26168 Collect_Global_Item (List, Mode);
26169
26170 -- Single global list or moded global list declaration
26171
26172 elsif Nkind (List) = N_Aggregate then
26173
26174 -- The declaration of a simple global list appear as a collection
26175 -- of expressions.
26176
26177 if Present (Expressions (List)) then
26178 Item := First (Expressions (List));
26179 while Present (Item) loop
26180 Collect_Global_Item (Item, Mode);
26181 Next (Item);
26182 end loop;
26183
26184 -- The declaration of a moded global list appears as a collection
26185 -- of component associations where individual choices denote mode.
26186
26187 elsif Present (Component_Associations (List)) then
26188 Item := First (Component_Associations (List));
26189 while Present (Item) loop
26190 Collect_Global_Items
26191 (List => Expression (Item),
26192 Mode => Chars (First (Choices (Item))));
26193
26194 Next (Item);
26195 end loop;
26196
26197 -- Invalid tree
26198
26199 else
26200 raise Program_Error;
26201 end if;
26202
26203 -- To accommodate partial decoration of disabled SPARK features, this
26204 -- routine may be called with illegal input. If this is the case, do
26205 -- not raise Program_Error.
26206
26207 else
26208 null;
26209 end if;
26210 end Collect_Global_Items;
26211
26212 -------------------------
26213 -- Present_Then_Remove --
26214 -------------------------
26215
26216 function Present_Then_Remove
26217 (List : Elist_Id;
26218 Item : Entity_Id) return Boolean
26219 is
26220 Elmt : Elmt_Id;
26221
26222 begin
26223 if Present (List) then
26224 Elmt := First_Elmt (List);
26225 while Present (Elmt) loop
26226 if Node (Elmt) = Item then
26227 Remove_Elmt (List, Elmt);
26228 return True;
26229 end if;
26230
26231 Next_Elmt (Elmt);
26232 end loop;
26233 end if;
26234
26235 return False;
26236 end Present_Then_Remove;
26237
26238 procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is
26239 Ignore : Boolean;
26240 begin
26241 Ignore := Present_Then_Remove (List, Item);
26242 end Present_Then_Remove;
26243
26244 -------------------------------
26245 -- Report_Extra_Constituents --
26246 -------------------------------
26247
26248 procedure Report_Extra_Constituents is
26249 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
26250 -- Emit an error for every element of List
26251
26252 ---------------------------------------
26253 -- Report_Extra_Constituents_In_List --
26254 ---------------------------------------
26255
26256 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
26257 Constit_Elmt : Elmt_Id;
26258
26259 begin
26260 if Present (List) then
26261 Constit_Elmt := First_Elmt (List);
26262 while Present (Constit_Elmt) loop
26263 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
26264 Next_Elmt (Constit_Elmt);
26265 end loop;
26266 end if;
26267 end Report_Extra_Constituents_In_List;
26268
26269 -- Start of processing for Report_Extra_Constituents
26270
26271 begin
26272 -- Do not perform this check in an instance because it was already
26273 -- performed successfully in the generic template.
26274
26275 if Is_Generic_Instance (Spec_Id) then
26276 null;
26277
26278 else
26279 Report_Extra_Constituents_In_List (In_Constits);
26280 Report_Extra_Constituents_In_List (In_Out_Constits);
26281 Report_Extra_Constituents_In_List (Out_Constits);
26282 Report_Extra_Constituents_In_List (Proof_In_Constits);
26283 end if;
26284 end Report_Extra_Constituents;
26285
26286 --------------------------
26287 -- Report_Missing_Items --
26288 --------------------------
26289
26290 procedure Report_Missing_Items is
26291 Item_Elmt : Elmt_Id;
26292 Item_Id : Entity_Id;
26293
26294 begin
26295 -- Do not perform this check in an instance because it was already
26296 -- performed successfully in the generic template.
26297
26298 if Is_Generic_Instance (Spec_Id) then
26299 null;
26300
26301 else
26302 if Present (Repeat_Items) then
26303 Item_Elmt := First_Elmt (Repeat_Items);
26304 while Present (Item_Elmt) loop
26305 Item_Id := Node (Item_Elmt);
26306 SPARK_Msg_NE ("missing global item &", N, Item_Id);
26307 Next_Elmt (Item_Elmt);
26308 end loop;
26309 end if;
26310 end if;
26311 end Report_Missing_Items;
26312
26313 -- Local variables
26314
26315 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26316 Errors : constant Nat := Serious_Errors_Detected;
26317 Items : Node_Id;
26318 No_Constit : Boolean;
26319
26320 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
26321
26322 begin
26323 -- Do not analyze the pragma multiple times
26324
26325 if Is_Analyzed_Pragma (N) then
26326 return;
26327 end if;
26328
26329 Spec_Id := Unique_Defining_Entity (Body_Decl);
26330
26331 -- Use the anonymous object as the proper spec when Refined_Global
26332 -- applies to the body of a single task type. The object carries the
26333 -- proper Chars as well as all non-refined versions of pragmas.
26334
26335 if Is_Single_Concurrent_Type (Spec_Id) then
26336 Spec_Id := Anonymous_Object (Spec_Id);
26337 end if;
26338
26339 Global := Get_Pragma (Spec_Id, Pragma_Global);
26340 Items := Expression (Get_Argument (N, Spec_Id));
26341
26342 -- The subprogram declaration lacks pragma Global. This renders
26343 -- Refined_Global useless as there is nothing to refine.
26344
26345 if No (Global) then
26346 SPARK_Msg_NE
26347 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
26348 & "& lacks aspect or pragma Global"), N, Spec_Id);
26349 goto Leave;
26350 end if;
26351
26352 -- Extract all relevant items from the corresponding Global pragma
26353
26354 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
26355
26356 -- Package and subprogram bodies are instantiated individually in
26357 -- a separate compiler pass. Due to this mode of instantiation, the
26358 -- refinement of a state may no longer be visible when a subprogram
26359 -- body contract is instantiated. Since the generic template is legal,
26360 -- do not perform this check in the instance to circumvent this oddity.
26361
26362 if Is_Generic_Instance (Spec_Id) then
26363 null;
26364
26365 -- Non-instance case
26366
26367 else
26368 -- The corresponding Global pragma must mention at least one
26369 -- state with a visible refinement at the point Refined_Global
26370 -- is processed. States with null refinements need Refined_Global
26371 -- pragma (SPARK RM 7.2.4(2)).
26372
26373 if not Has_In_State
26374 and then not Has_In_Out_State
26375 and then not Has_Out_State
26376 and then not Has_Proof_In_State
26377 and then not Has_Null_State
26378 then
26379 SPARK_Msg_NE
26380 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
26381 & "depend on abstract state with visible refinement"),
26382 N, Spec_Id);
26383 goto Leave;
26384
26385 -- The global refinement of inputs and outputs cannot be null when
26386 -- the corresponding Global pragma contains at least one item except
26387 -- in the case where we have states with null refinements.
26388
26389 elsif Nkind (Items) = N_Null
26390 and then
26391 (Present (In_Items)
26392 or else Present (In_Out_Items)
26393 or else Present (Out_Items)
26394 or else Present (Proof_In_Items))
26395 and then not Has_Null_State
26396 then
26397 SPARK_Msg_NE
26398 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
26399 & "global items"), N, Spec_Id);
26400 goto Leave;
26401 end if;
26402 end if;
26403
26404 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
26405 -- This ensures that the categorization of all refined global items is
26406 -- consistent with their role.
26407
26408 Analyze_Global_In_Decl_Part (N);
26409
26410 -- Perform all refinement checks with respect to completeness and mode
26411 -- matching.
26412
26413 if Serious_Errors_Detected = Errors then
26414 Check_Refined_Global_List (Items);
26415 end if;
26416
26417 -- Store the information that no constituent is used in the global
26418 -- refinement, prior to calling checking procedures which remove items
26419 -- from the list of constituents.
26420
26421 No_Constit :=
26422 No (In_Constits)
26423 and then No (In_Out_Constits)
26424 and then No (Out_Constits)
26425 and then No (Proof_In_Constits);
26426
26427 -- For Input states with visible refinement, at least one constituent
26428 -- must be used as an Input in the global refinement.
26429
26430 if Serious_Errors_Detected = Errors then
26431 Check_Input_States;
26432 end if;
26433
26434 -- Verify all possible completion variants for In_Out states with
26435 -- visible refinement.
26436
26437 if Serious_Errors_Detected = Errors then
26438 Check_In_Out_States;
26439 end if;
26440
26441 -- For Output states with visible refinement, all constituents must be
26442 -- used as Outputs in the global refinement.
26443
26444 if Serious_Errors_Detected = Errors then
26445 Check_Output_States;
26446 end if;
26447
26448 -- For Proof_In states with visible refinement, at least one constituent
26449 -- must be used as Proof_In in the global refinement.
26450
26451 if Serious_Errors_Detected = Errors then
26452 Check_Proof_In_States;
26453 end if;
26454
26455 -- Emit errors for all constituents that belong to other states with
26456 -- visible refinement that do not appear in Global.
26457
26458 if Serious_Errors_Detected = Errors then
26459 Report_Extra_Constituents;
26460 end if;
26461
26462 -- Emit errors for all items in Global that are not repeated in the
26463 -- global refinement and for which there is no full visible refinement
26464 -- and, in the case of states with partial visible refinement, no
26465 -- constituent is mentioned in the global refinement.
26466
26467 if Serious_Errors_Detected = Errors then
26468 Report_Missing_Items;
26469 end if;
26470
26471 -- Emit an error if no constituent is used in the global refinement
26472 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
26473 -- one may be issued by the checking procedures. Do not perform this
26474 -- check in an instance because it was already performed successfully
26475 -- in the generic template.
26476
26477 if Serious_Errors_Detected = Errors
26478 and then not Is_Generic_Instance (Spec_Id)
26479 and then not Has_Null_State
26480 and then No_Constit
26481 then
26482 SPARK_Msg_N ("missing refinement", N);
26483 end if;
26484
26485 <<Leave>>
26486 Set_Is_Analyzed_Pragma (N);
26487 end Analyze_Refined_Global_In_Decl_Part;
26488
26489 ----------------------------------------
26490 -- Analyze_Refined_State_In_Decl_Part --
26491 ----------------------------------------
26492
26493 procedure Analyze_Refined_State_In_Decl_Part
26494 (N : Node_Id;
26495 Freeze_Id : Entity_Id := Empty)
26496 is
26497 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
26498 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
26499 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
26500
26501 Available_States : Elist_Id := No_Elist;
26502 -- A list of all abstract states defined in the package declaration that
26503 -- are available for refinement. The list is used to report unrefined
26504 -- states.
26505
26506 Body_States : Elist_Id := No_Elist;
26507 -- A list of all hidden states that appear in the body of the related
26508 -- package. The list is used to report unused hidden states.
26509
26510 Constituents_Seen : Elist_Id := No_Elist;
26511 -- A list that contains all constituents processed so far. The list is
26512 -- used to detect multiple uses of the same constituent.
26513
26514 Freeze_Posted : Boolean := False;
26515 -- A flag that controls the output of a freezing-related error (see use
26516 -- below).
26517
26518 Refined_States_Seen : Elist_Id := No_Elist;
26519 -- A list that contains all refined states processed so far. The list is
26520 -- used to detect duplicate refinements.
26521
26522 procedure Analyze_Refinement_Clause (Clause : Node_Id);
26523 -- Perform full analysis of a single refinement clause
26524
26525 procedure Report_Unrefined_States (States : Elist_Id);
26526 -- Emit errors for all unrefined abstract states found in list States
26527
26528 -------------------------------
26529 -- Analyze_Refinement_Clause --
26530 -------------------------------
26531
26532 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
26533 AR_Constit : Entity_Id := Empty;
26534 AW_Constit : Entity_Id := Empty;
26535 ER_Constit : Entity_Id := Empty;
26536 EW_Constit : Entity_Id := Empty;
26537 -- The entities of external constituents that contain one of the
26538 -- following enabled properties: Async_Readers, Async_Writers,
26539 -- Effective_Reads and Effective_Writes.
26540
26541 External_Constit_Seen : Boolean := False;
26542 -- Flag used to mark when at least one external constituent is part
26543 -- of the state refinement.
26544
26545 Non_Null_Seen : Boolean := False;
26546 Null_Seen : Boolean := False;
26547 -- Flags used to detect multiple uses of null in a single clause or a
26548 -- mixture of null and non-null constituents.
26549
26550 Part_Of_Constits : Elist_Id := No_Elist;
26551 -- A list of all candidate constituents subject to indicator Part_Of
26552 -- where the encapsulating state is the current state.
26553
26554 State : Node_Id;
26555 State_Id : Entity_Id;
26556 -- The current state being refined
26557
26558 procedure Analyze_Constituent (Constit : Node_Id);
26559 -- Perform full analysis of a single constituent
26560
26561 procedure Check_External_Property
26562 (Prop_Nam : Name_Id;
26563 Enabled : Boolean;
26564 Constit : Entity_Id);
26565 -- Determine whether a property denoted by name Prop_Nam is present
26566 -- in the refined state. Emit an error if this is not the case. Flag
26567 -- Enabled should be set when the property applies to the refined
26568 -- state. Constit denotes the constituent (if any) which introduces
26569 -- the property in the refinement.
26570
26571 procedure Match_State;
26572 -- Determine whether the state being refined appears in list
26573 -- Available_States. Emit an error when attempting to re-refine the
26574 -- state or when the state is not defined in the package declaration,
26575 -- otherwise remove the state from Available_States.
26576
26577 procedure Report_Unused_Constituents (Constits : Elist_Id);
26578 -- Emit errors for all unused Part_Of constituents in list Constits
26579
26580 -------------------------
26581 -- Analyze_Constituent --
26582 -------------------------
26583
26584 procedure Analyze_Constituent (Constit : Node_Id) is
26585 procedure Match_Constituent (Constit_Id : Entity_Id);
26586 -- Determine whether constituent Constit denoted by its entity
26587 -- Constit_Id appears in Body_States. Emit an error when the
26588 -- constituent is not a valid hidden state of the related package
26589 -- or when it is used more than once. Otherwise remove the
26590 -- constituent from Body_States.
26591
26592 -----------------------
26593 -- Match_Constituent --
26594 -----------------------
26595
26596 procedure Match_Constituent (Constit_Id : Entity_Id) is
26597 procedure Collect_Constituent;
26598 -- Verify the legality of constituent Constit_Id and add it to
26599 -- the refinements of State_Id.
26600
26601 -------------------------
26602 -- Collect_Constituent --
26603 -------------------------
26604
26605 procedure Collect_Constituent is
26606 Constits : Elist_Id;
26607
26608 begin
26609 -- The Ghost policy in effect at the point of abstract state
26610 -- declaration and constituent must match (SPARK RM 6.9(15))
26611
26612 Check_Ghost_Refinement
26613 (State, State_Id, Constit, Constit_Id);
26614
26615 -- A synchronized state must be refined by a synchronized
26616 -- object or another synchronized state (SPARK RM 9.6).
26617
26618 if Is_Synchronized_State (State_Id)
26619 and then not Is_Synchronized_Object (Constit_Id)
26620 and then not Is_Synchronized_State (Constit_Id)
26621 then
26622 SPARK_Msg_NE
26623 ("constituent of synchronized state & must be "
26624 & "synchronized", Constit, State_Id);
26625 end if;
26626
26627 -- Add the constituent to the list of processed items to aid
26628 -- with the detection of duplicates.
26629
26630 Append_New_Elmt (Constit_Id, Constituents_Seen);
26631
26632 -- Collect the constituent in the list of refinement items
26633 -- and establish a relation between the refined state and
26634 -- the item.
26635
26636 Constits := Refinement_Constituents (State_Id);
26637
26638 if No (Constits) then
26639 Constits := New_Elmt_List;
26640 Set_Refinement_Constituents (State_Id, Constits);
26641 end if;
26642
26643 Append_Elmt (Constit_Id, Constits);
26644 Set_Encapsulating_State (Constit_Id, State_Id);
26645
26646 -- The state has at least one legal constituent, mark the
26647 -- start of the refinement region. The region ends when the
26648 -- body declarations end (see routine Analyze_Declarations).
26649
26650 Set_Has_Visible_Refinement (State_Id);
26651
26652 -- When the constituent is external, save its relevant
26653 -- property for further checks.
26654
26655 if Async_Readers_Enabled (Constit_Id) then
26656 AR_Constit := Constit_Id;
26657 External_Constit_Seen := True;
26658 end if;
26659
26660 if Async_Writers_Enabled (Constit_Id) then
26661 AW_Constit := Constit_Id;
26662 External_Constit_Seen := True;
26663 end if;
26664
26665 if Effective_Reads_Enabled (Constit_Id) then
26666 ER_Constit := Constit_Id;
26667 External_Constit_Seen := True;
26668 end if;
26669
26670 if Effective_Writes_Enabled (Constit_Id) then
26671 EW_Constit := Constit_Id;
26672 External_Constit_Seen := True;
26673 end if;
26674 end Collect_Constituent;
26675
26676 -- Local variables
26677
26678 State_Elmt : Elmt_Id;
26679
26680 -- Start of processing for Match_Constituent
26681
26682 begin
26683 -- Detect a duplicate use of a constituent
26684
26685 if Contains (Constituents_Seen, Constit_Id) then
26686 SPARK_Msg_NE
26687 ("duplicate use of constituent &", Constit, Constit_Id);
26688 return;
26689 end if;
26690
26691 -- The constituent is subject to a Part_Of indicator
26692
26693 if Present (Encapsulating_State (Constit_Id)) then
26694 if Encapsulating_State (Constit_Id) = State_Id then
26695 Remove (Part_Of_Constits, Constit_Id);
26696 Collect_Constituent;
26697
26698 -- The constituent is part of another state and is used
26699 -- incorrectly in the refinement of the current state.
26700
26701 else
26702 Error_Msg_Name_1 := Chars (State_Id);
26703 SPARK_Msg_NE
26704 ("& cannot act as constituent of state %",
26705 Constit, Constit_Id);
26706 SPARK_Msg_NE
26707 ("\Part_Of indicator specifies encapsulator &",
26708 Constit, Encapsulating_State (Constit_Id));
26709 end if;
26710
26711 -- The only other source of legal constituents is the body
26712 -- state space of the related package.
26713
26714 else
26715 if Present (Body_States) then
26716 State_Elmt := First_Elmt (Body_States);
26717 while Present (State_Elmt) loop
26718
26719 -- Consume a valid constituent to signal that it has
26720 -- been encountered.
26721
26722 if Node (State_Elmt) = Constit_Id then
26723 Remove_Elmt (Body_States, State_Elmt);
26724 Collect_Constituent;
26725 return;
26726 end if;
26727
26728 Next_Elmt (State_Elmt);
26729 end loop;
26730 end if;
26731
26732 -- Constants are part of the hidden state of a package, but
26733 -- the compiler cannot determine whether they have variable
26734 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
26735 -- hidden state. Accept the constant quietly even if it is
26736 -- a visible state or lacks a Part_Of indicator.
26737
26738 if Ekind (Constit_Id) = E_Constant then
26739 Collect_Constituent;
26740
26741 -- If we get here, then the constituent is not a hidden
26742 -- state of the related package and may not be used in a
26743 -- refinement (SPARK RM 7.2.2(9)).
26744
26745 else
26746 Error_Msg_Name_1 := Chars (Spec_Id);
26747 SPARK_Msg_NE
26748 ("cannot use & in refinement, constituent is not a "
26749 & "hidden state of package %", Constit, Constit_Id);
26750 end if;
26751 end if;
26752 end Match_Constituent;
26753
26754 -- Local variables
26755
26756 Constit_Id : Entity_Id;
26757 Constits : Elist_Id;
26758
26759 -- Start of processing for Analyze_Constituent
26760
26761 begin
26762 -- Detect multiple uses of null in a single refinement clause or a
26763 -- mixture of null and non-null constituents.
26764
26765 if Nkind (Constit) = N_Null then
26766 if Null_Seen then
26767 SPARK_Msg_N
26768 ("multiple null constituents not allowed", Constit);
26769
26770 elsif Non_Null_Seen then
26771 SPARK_Msg_N
26772 ("cannot mix null and non-null constituents", Constit);
26773
26774 else
26775 Null_Seen := True;
26776
26777 -- Collect the constituent in the list of refinement items
26778
26779 Constits := Refinement_Constituents (State_Id);
26780
26781 if No (Constits) then
26782 Constits := New_Elmt_List;
26783 Set_Refinement_Constituents (State_Id, Constits);
26784 end if;
26785
26786 Append_Elmt (Constit, Constits);
26787
26788 -- The state has at least one legal constituent, mark the
26789 -- start of the refinement region. The region ends when the
26790 -- body declarations end (see Analyze_Declarations).
26791
26792 Set_Has_Visible_Refinement (State_Id);
26793 end if;
26794
26795 -- Non-null constituents
26796
26797 else
26798 Non_Null_Seen := True;
26799
26800 if Null_Seen then
26801 SPARK_Msg_N
26802 ("cannot mix null and non-null constituents", Constit);
26803 end if;
26804
26805 Analyze (Constit);
26806 Resolve_State (Constit);
26807
26808 -- Ensure that the constituent denotes a valid state or a
26809 -- whole object (SPARK RM 7.2.2(5)).
26810
26811 if Is_Entity_Name (Constit) then
26812 Constit_Id := Entity_Of (Constit);
26813
26814 -- When a constituent is declared after a subprogram body
26815 -- that caused "freezing" of the related contract where
26816 -- pragma Refined_State resides, the constituent appears
26817 -- undefined and carries Any_Id as its entity.
26818
26819 -- package body Pack
26820 -- with Refined_State => (State => Constit)
26821 -- is
26822 -- procedure Proc
26823 -- with Refined_Global => (Input => Constit)
26824 -- is
26825 -- ...
26826 -- end Proc;
26827
26828 -- Constit : ...;
26829 -- end Pack;
26830
26831 if Constit_Id = Any_Id then
26832 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
26833
26834 -- Emit a specialized info message when the contract of
26835 -- the related package body was "frozen" by another body.
26836 -- Note that it is not possible to precisely identify why
26837 -- the constituent is undefined because it is not visible
26838 -- when pragma Refined_State is analyzed. This message is
26839 -- a reasonable approximation.
26840
26841 if Present (Freeze_Id) and then not Freeze_Posted then
26842 Freeze_Posted := True;
26843
26844 Error_Msg_Name_1 := Chars (Body_Id);
26845 Error_Msg_Sloc := Sloc (Freeze_Id);
26846 SPARK_Msg_NE
26847 ("body & declared # freezes the contract of %",
26848 N, Freeze_Id);
26849 SPARK_Msg_N
26850 ("\all constituents must be declared before body #",
26851 N);
26852
26853 -- A misplaced constituent is a critical error because
26854 -- pragma Refined_Depends or Refined_Global depends on
26855 -- the proper link between a state and a constituent.
26856 -- Stop the compilation, as this leads to a multitude
26857 -- of misleading cascaded errors.
26858
26859 raise Program_Error;
26860 end if;
26861
26862 -- The constituent is a valid state or object
26863
26864 elsif Ekind_In (Constit_Id, E_Abstract_State,
26865 E_Constant,
26866 E_Variable)
26867 then
26868 Match_Constituent (Constit_Id);
26869
26870 -- The variable may eventually become a constituent of a
26871 -- single protected/task type. Record the reference now
26872 -- and verify its legality when analyzing the contract of
26873 -- the variable (SPARK RM 9.3).
26874
26875 if Ekind (Constit_Id) = E_Variable then
26876 Record_Possible_Part_Of_Reference
26877 (Var_Id => Constit_Id,
26878 Ref => Constit);
26879 end if;
26880
26881 -- Otherwise the constituent is illegal
26882
26883 else
26884 SPARK_Msg_NE
26885 ("constituent & must denote object or state",
26886 Constit, Constit_Id);
26887 end if;
26888
26889 -- The constituent is illegal
26890
26891 else
26892 SPARK_Msg_N ("malformed constituent", Constit);
26893 end if;
26894 end if;
26895 end Analyze_Constituent;
26896
26897 -----------------------------
26898 -- Check_External_Property --
26899 -----------------------------
26900
26901 procedure Check_External_Property
26902 (Prop_Nam : Name_Id;
26903 Enabled : Boolean;
26904 Constit : Entity_Id)
26905 is
26906 begin
26907 -- The property is missing in the declaration of the state, but
26908 -- a constituent is introducing it in the state refinement
26909 -- (SPARK RM 7.2.8(2)).
26910
26911 if not Enabled and then Present (Constit) then
26912 Error_Msg_Name_1 := Prop_Nam;
26913 Error_Msg_Name_2 := Chars (State_Id);
26914 SPARK_Msg_NE
26915 ("constituent & introduces external property % in refinement "
26916 & "of state %", State, Constit);
26917
26918 Error_Msg_Sloc := Sloc (State_Id);
26919 SPARK_Msg_N
26920 ("\property is missing in abstract state declaration #",
26921 State);
26922 end if;
26923 end Check_External_Property;
26924
26925 -----------------
26926 -- Match_State --
26927 -----------------
26928
26929 procedure Match_State is
26930 State_Elmt : Elmt_Id;
26931
26932 begin
26933 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
26934
26935 if Contains (Refined_States_Seen, State_Id) then
26936 SPARK_Msg_NE
26937 ("duplicate refinement of state &", State, State_Id);
26938 return;
26939 end if;
26940
26941 -- Inspect the abstract states defined in the package declaration
26942 -- looking for a match.
26943
26944 State_Elmt := First_Elmt (Available_States);
26945 while Present (State_Elmt) loop
26946
26947 -- A valid abstract state is being refined in the body. Add
26948 -- the state to the list of processed refined states to aid
26949 -- with the detection of duplicate refinements. Remove the
26950 -- state from Available_States to signal that it has already
26951 -- been refined.
26952
26953 if Node (State_Elmt) = State_Id then
26954 Append_New_Elmt (State_Id, Refined_States_Seen);
26955 Remove_Elmt (Available_States, State_Elmt);
26956 return;
26957 end if;
26958
26959 Next_Elmt (State_Elmt);
26960 end loop;
26961
26962 -- If we get here, we are refining a state that is not defined in
26963 -- the package declaration.
26964
26965 Error_Msg_Name_1 := Chars (Spec_Id);
26966 SPARK_Msg_NE
26967 ("cannot refine state, & is not defined in package %",
26968 State, State_Id);
26969 end Match_State;
26970
26971 --------------------------------
26972 -- Report_Unused_Constituents --
26973 --------------------------------
26974
26975 procedure Report_Unused_Constituents (Constits : Elist_Id) is
26976 Constit_Elmt : Elmt_Id;
26977 Constit_Id : Entity_Id;
26978 Posted : Boolean := False;
26979
26980 begin
26981 if Present (Constits) then
26982 Constit_Elmt := First_Elmt (Constits);
26983 while Present (Constit_Elmt) loop
26984 Constit_Id := Node (Constit_Elmt);
26985
26986 -- Generate an error message of the form:
26987
26988 -- state ... has unused Part_Of constituents
26989 -- abstract state ... defined at ...
26990 -- constant ... defined at ...
26991 -- variable ... defined at ...
26992
26993 if not Posted then
26994 Posted := True;
26995 SPARK_Msg_NE
26996 ("state & has unused Part_Of constituents",
26997 State, State_Id);
26998 end if;
26999
27000 Error_Msg_Sloc := Sloc (Constit_Id);
27001
27002 if Ekind (Constit_Id) = E_Abstract_State then
27003 SPARK_Msg_NE
27004 ("\abstract state & defined #", State, Constit_Id);
27005
27006 elsif Ekind (Constit_Id) = E_Constant then
27007 SPARK_Msg_NE
27008 ("\constant & defined #", State, Constit_Id);
27009
27010 else
27011 pragma Assert (Ekind (Constit_Id) = E_Variable);
27012 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
27013 end if;
27014
27015 Next_Elmt (Constit_Elmt);
27016 end loop;
27017 end if;
27018 end Report_Unused_Constituents;
27019
27020 -- Local declarations
27021
27022 Body_Ref : Node_Id;
27023 Body_Ref_Elmt : Elmt_Id;
27024 Constit : Node_Id;
27025 Extra_State : Node_Id;
27026
27027 -- Start of processing for Analyze_Refinement_Clause
27028
27029 begin
27030 -- A refinement clause appears as a component association where the
27031 -- sole choice is the state and the expressions are the constituents.
27032 -- This is a syntax error, always report.
27033
27034 if Nkind (Clause) /= N_Component_Association then
27035 Error_Msg_N ("malformed state refinement clause", Clause);
27036 return;
27037 end if;
27038
27039 -- Analyze the state name of a refinement clause
27040
27041 State := First (Choices (Clause));
27042
27043 Analyze (State);
27044 Resolve_State (State);
27045
27046 -- Ensure that the state name denotes a valid abstract state that is
27047 -- defined in the spec of the related package.
27048
27049 if Is_Entity_Name (State) then
27050 State_Id := Entity_Of (State);
27051
27052 -- When the abstract state is undefined, it appears as Any_Id. Do
27053 -- not continue with the analysis of the clause.
27054
27055 if State_Id = Any_Id then
27056 return;
27057
27058 -- Catch any attempts to re-refine a state or refine a state that
27059 -- is not defined in the package declaration.
27060
27061 elsif Ekind (State_Id) = E_Abstract_State then
27062 Match_State;
27063
27064 else
27065 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
27066 return;
27067 end if;
27068
27069 -- References to a state with visible refinement are illegal.
27070 -- When nested packages are involved, detecting such references is
27071 -- tricky because pragma Refined_State is analyzed later than the
27072 -- offending pragma Depends or Global. References that occur in
27073 -- such nested context are stored in a list. Emit errors for all
27074 -- references found in Body_References (SPARK RM 6.1.4(8)).
27075
27076 if Present (Body_References (State_Id)) then
27077 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
27078 while Present (Body_Ref_Elmt) loop
27079 Body_Ref := Node (Body_Ref_Elmt);
27080
27081 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
27082 Error_Msg_Sloc := Sloc (State);
27083 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
27084
27085 Next_Elmt (Body_Ref_Elmt);
27086 end loop;
27087 end if;
27088
27089 -- The state name is illegal. This is a syntax error, always report.
27090
27091 else
27092 Error_Msg_N ("malformed state name in refinement clause", State);
27093 return;
27094 end if;
27095
27096 -- A refinement clause may only refine one state at a time
27097
27098 Extra_State := Next (State);
27099
27100 if Present (Extra_State) then
27101 SPARK_Msg_N
27102 ("refinement clause cannot cover multiple states", Extra_State);
27103 end if;
27104
27105 -- Replicate the Part_Of constituents of the refined state because
27106 -- the algorithm will consume items.
27107
27108 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
27109
27110 -- Analyze all constituents of the refinement. Multiple constituents
27111 -- appear as an aggregate.
27112
27113 Constit := Expression (Clause);
27114
27115 if Nkind (Constit) = N_Aggregate then
27116 if Present (Component_Associations (Constit)) then
27117 SPARK_Msg_N
27118 ("constituents of refinement clause must appear in "
27119 & "positional form", Constit);
27120
27121 else pragma Assert (Present (Expressions (Constit)));
27122 Constit := First (Expressions (Constit));
27123 while Present (Constit) loop
27124 Analyze_Constituent (Constit);
27125 Next (Constit);
27126 end loop;
27127 end if;
27128
27129 -- Various forms of a single constituent. Note that these may include
27130 -- malformed constituents.
27131
27132 else
27133 Analyze_Constituent (Constit);
27134 end if;
27135
27136 -- Verify that external constituents do not introduce new external
27137 -- property in the state refinement (SPARK RM 7.2.8(2)).
27138
27139 if Is_External_State (State_Id) then
27140 Check_External_Property
27141 (Prop_Nam => Name_Async_Readers,
27142 Enabled => Async_Readers_Enabled (State_Id),
27143 Constit => AR_Constit);
27144
27145 Check_External_Property
27146 (Prop_Nam => Name_Async_Writers,
27147 Enabled => Async_Writers_Enabled (State_Id),
27148 Constit => AW_Constit);
27149
27150 Check_External_Property
27151 (Prop_Nam => Name_Effective_Reads,
27152 Enabled => Effective_Reads_Enabled (State_Id),
27153 Constit => ER_Constit);
27154
27155 Check_External_Property
27156 (Prop_Nam => Name_Effective_Writes,
27157 Enabled => Effective_Writes_Enabled (State_Id),
27158 Constit => EW_Constit);
27159
27160 -- When a refined state is not external, it should not have external
27161 -- constituents (SPARK RM 7.2.8(1)).
27162
27163 elsif External_Constit_Seen then
27164 SPARK_Msg_NE
27165 ("non-external state & cannot contain external constituents in "
27166 & "refinement", State, State_Id);
27167 end if;
27168
27169 -- Ensure that all Part_Of candidate constituents have been mentioned
27170 -- in the refinement clause.
27171
27172 Report_Unused_Constituents (Part_Of_Constits);
27173 end Analyze_Refinement_Clause;
27174
27175 -----------------------------
27176 -- Report_Unrefined_States --
27177 -----------------------------
27178
27179 procedure Report_Unrefined_States (States : Elist_Id) is
27180 State_Elmt : Elmt_Id;
27181
27182 begin
27183 if Present (States) then
27184 State_Elmt := First_Elmt (States);
27185 while Present (State_Elmt) loop
27186 SPARK_Msg_N
27187 ("abstract state & must be refined", Node (State_Elmt));
27188
27189 Next_Elmt (State_Elmt);
27190 end loop;
27191 end if;
27192 end Report_Unrefined_States;
27193
27194 -- Local declarations
27195
27196 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
27197 Clause : Node_Id;
27198
27199 -- Start of processing for Analyze_Refined_State_In_Decl_Part
27200
27201 begin
27202 -- Do not analyze the pragma multiple times
27203
27204 if Is_Analyzed_Pragma (N) then
27205 return;
27206 end if;
27207
27208 -- Replicate the abstract states declared by the package because the
27209 -- matching algorithm will consume states.
27210
27211 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
27212
27213 -- Gather all abstract states and objects declared in the visible
27214 -- state space of the package body. These items must be utilized as
27215 -- constituents in a state refinement.
27216
27217 Body_States := Collect_Body_States (Body_Id);
27218
27219 -- Multiple non-null state refinements appear as an aggregate
27220
27221 if Nkind (Clauses) = N_Aggregate then
27222 if Present (Expressions (Clauses)) then
27223 SPARK_Msg_N
27224 ("state refinements must appear as component associations",
27225 Clauses);
27226
27227 else pragma Assert (Present (Component_Associations (Clauses)));
27228 Clause := First (Component_Associations (Clauses));
27229 while Present (Clause) loop
27230 Analyze_Refinement_Clause (Clause);
27231 Next (Clause);
27232 end loop;
27233 end if;
27234
27235 -- Various forms of a single state refinement. Note that these may
27236 -- include malformed refinements.
27237
27238 else
27239 Analyze_Refinement_Clause (Clauses);
27240 end if;
27241
27242 -- List all abstract states that were left unrefined
27243
27244 Report_Unrefined_States (Available_States);
27245
27246 Set_Is_Analyzed_Pragma (N);
27247 end Analyze_Refined_State_In_Decl_Part;
27248
27249 ------------------------------------
27250 -- Analyze_Test_Case_In_Decl_Part --
27251 ------------------------------------
27252
27253 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
27254 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
27255 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
27256
27257 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
27258 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
27259 -- denoted by Arg_Nam.
27260
27261 ------------------------------
27262 -- Preanalyze_Test_Case_Arg --
27263 ------------------------------
27264
27265 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
27266 Arg : Node_Id;
27267
27268 begin
27269 -- Preanalyze the original aspect argument for ASIS or for a generic
27270 -- subprogram to properly capture global references.
27271
27272 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
27273 Arg :=
27274 Test_Case_Arg
27275 (Prag => N,
27276 Arg_Nam => Arg_Nam,
27277 From_Aspect => True);
27278
27279 if Present (Arg) then
27280 Preanalyze_Assert_Expression
27281 (Expression (Arg), Standard_Boolean);
27282 end if;
27283 end if;
27284
27285 Arg := Test_Case_Arg (N, Arg_Nam);
27286
27287 if Present (Arg) then
27288 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
27289 end if;
27290 end Preanalyze_Test_Case_Arg;
27291
27292 -- Local variables
27293
27294 Restore_Scope : Boolean := False;
27295
27296 -- Start of processing for Analyze_Test_Case_In_Decl_Part
27297
27298 begin
27299 -- Do not analyze the pragma multiple times
27300
27301 if Is_Analyzed_Pragma (N) then
27302 return;
27303 end if;
27304
27305 -- Ensure that the formal parameters are visible when analyzing all
27306 -- clauses. This falls out of the general rule of aspects pertaining
27307 -- to subprogram declarations.
27308
27309 if not In_Open_Scopes (Spec_Id) then
27310 Restore_Scope := True;
27311 Push_Scope (Spec_Id);
27312
27313 if Is_Generic_Subprogram (Spec_Id) then
27314 Install_Generic_Formals (Spec_Id);
27315 else
27316 Install_Formals (Spec_Id);
27317 end if;
27318 end if;
27319
27320 Preanalyze_Test_Case_Arg (Name_Requires);
27321 Preanalyze_Test_Case_Arg (Name_Ensures);
27322
27323 if Restore_Scope then
27324 End_Scope;
27325 end if;
27326
27327 -- Currently it is not possible to inline pre/postconditions on a
27328 -- subprogram subject to pragma Inline_Always.
27329
27330 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
27331
27332 Set_Is_Analyzed_Pragma (N);
27333 end Analyze_Test_Case_In_Decl_Part;
27334
27335 ----------------
27336 -- Appears_In --
27337 ----------------
27338
27339 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
27340 Elmt : Elmt_Id;
27341 Id : Entity_Id;
27342
27343 begin
27344 if Present (List) then
27345 Elmt := First_Elmt (List);
27346 while Present (Elmt) loop
27347 if Nkind (Node (Elmt)) = N_Defining_Identifier then
27348 Id := Node (Elmt);
27349 else
27350 Id := Entity_Of (Node (Elmt));
27351 end if;
27352
27353 if Id = Item_Id then
27354 return True;
27355 end if;
27356
27357 Next_Elmt (Elmt);
27358 end loop;
27359 end if;
27360
27361 return False;
27362 end Appears_In;
27363
27364 -----------------------------------
27365 -- Build_Pragma_Check_Equivalent --
27366 -----------------------------------
27367
27368 function Build_Pragma_Check_Equivalent
27369 (Prag : Node_Id;
27370 Subp_Id : Entity_Id := Empty;
27371 Inher_Id : Entity_Id := Empty;
27372 Keep_Pragma_Id : Boolean := False) return Node_Id
27373 is
27374 function Suppress_Reference (N : Node_Id) return Traverse_Result;
27375 -- Detect whether node N references a formal parameter subject to
27376 -- pragma Unreferenced. If this is the case, set Comes_From_Source
27377 -- to False to suppress the generation of a reference when analyzing
27378 -- N later on.
27379
27380 ------------------------
27381 -- Suppress_Reference --
27382 ------------------------
27383
27384 function Suppress_Reference (N : Node_Id) return Traverse_Result is
27385 Formal : Entity_Id;
27386
27387 begin
27388 if Is_Entity_Name (N) and then Present (Entity (N)) then
27389 Formal := Entity (N);
27390
27391 -- The formal parameter is subject to pragma Unreferenced. Prevent
27392 -- the generation of references by resetting the Comes_From_Source
27393 -- flag.
27394
27395 if Is_Formal (Formal)
27396 and then Has_Pragma_Unreferenced (Formal)
27397 then
27398 Set_Comes_From_Source (N, False);
27399 end if;
27400 end if;
27401
27402 return OK;
27403 end Suppress_Reference;
27404
27405 procedure Suppress_References is
27406 new Traverse_Proc (Suppress_Reference);
27407
27408 -- Local variables
27409
27410 Loc : constant Source_Ptr := Sloc (Prag);
27411 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
27412 Check_Prag : Node_Id;
27413 Msg_Arg : Node_Id;
27414 Nam : Name_Id;
27415
27416 Needs_Wrapper : Boolean;
27417 pragma Unreferenced (Needs_Wrapper);
27418
27419 -- Start of processing for Build_Pragma_Check_Equivalent
27420
27421 begin
27422 -- When the pre- or postcondition is inherited, map the formals of the
27423 -- inherited subprogram to those of the current subprogram. In addition,
27424 -- map primitive operations of the parent type into the corresponding
27425 -- primitive operations of the descendant.
27426
27427 if Present (Inher_Id) then
27428 pragma Assert (Present (Subp_Id));
27429
27430 Update_Primitives_Mapping (Inher_Id, Subp_Id);
27431
27432 -- Use generic machinery to copy inherited pragma, as if it were an
27433 -- instantiation, resetting source locations appropriately, so that
27434 -- expressions inside the inherited pragma use chained locations.
27435 -- This is used in particular in GNATprove to locate precisely
27436 -- messages on a given inherited pragma.
27437
27438 Set_Copied_Sloc_For_Inherited_Pragma
27439 (Unit_Declaration_Node (Subp_Id), Inher_Id);
27440 Check_Prag := New_Copy_Tree (Source => Prag);
27441
27442 -- Build the inherited class-wide condition
27443
27444 Build_Class_Wide_Expression
27445 (Prag => Check_Prag,
27446 Subp => Subp_Id,
27447 Par_Subp => Inher_Id,
27448 Adjust_Sloc => True,
27449 Needs_Wrapper => Needs_Wrapper);
27450
27451 -- If not an inherited condition simply copy the original pragma
27452
27453 else
27454 Check_Prag := New_Copy_Tree (Source => Prag);
27455 end if;
27456
27457 -- Mark the pragma as being internally generated and reset the Analyzed
27458 -- flag.
27459
27460 Set_Analyzed (Check_Prag, False);
27461 Set_Comes_From_Source (Check_Prag, False);
27462
27463 -- The tree of the original pragma may contain references to the
27464 -- formal parameters of the related subprogram. At the same time
27465 -- the corresponding body may mark the formals as unreferenced:
27466
27467 -- procedure Proc (Formal : ...)
27468 -- with Pre => Formal ...;
27469
27470 -- procedure Proc (Formal : ...) is
27471 -- pragma Unreferenced (Formal);
27472 -- ...
27473
27474 -- This creates problems because all pragma Check equivalents are
27475 -- analyzed at the end of the body declarations. Since all source
27476 -- references have already been accounted for, reset any references
27477 -- to such formals in the generated pragma Check equivalent.
27478
27479 Suppress_References (Check_Prag);
27480
27481 if Present (Corresponding_Aspect (Prag)) then
27482 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
27483 else
27484 Nam := Prag_Nam;
27485 end if;
27486
27487 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
27488 -- the copied pragma in the newly created pragma, convert the copy into
27489 -- pragma Check by correcting the name and adding a check_kind argument.
27490
27491 if not Keep_Pragma_Id then
27492 Set_Class_Present (Check_Prag, False);
27493
27494 Set_Pragma_Identifier
27495 (Check_Prag, Make_Identifier (Loc, Name_Check));
27496
27497 Prepend_To (Pragma_Argument_Associations (Check_Prag),
27498 Make_Pragma_Argument_Association (Loc,
27499 Expression => Make_Identifier (Loc, Nam)));
27500 end if;
27501
27502 -- Update the error message when the pragma is inherited
27503
27504 if Present (Inher_Id) then
27505 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
27506
27507 if Chars (Msg_Arg) = Name_Message then
27508 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
27509
27510 -- Insert "inherited" to improve the error message
27511
27512 if Name_Buffer (1 .. 8) = "failed p" then
27513 Insert_Str_In_Name_Buffer ("inherited ", 8);
27514 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
27515 end if;
27516 end if;
27517 end if;
27518
27519 return Check_Prag;
27520 end Build_Pragma_Check_Equivalent;
27521
27522 -----------------------------
27523 -- Check_Applicable_Policy --
27524 -----------------------------
27525
27526 procedure Check_Applicable_Policy (N : Node_Id) is
27527 PP : Node_Id;
27528 Policy : Name_Id;
27529
27530 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
27531
27532 begin
27533 -- No effect if not valid assertion kind name
27534
27535 if not Is_Valid_Assertion_Kind (Ename) then
27536 return;
27537 end if;
27538
27539 -- Loop through entries in check policy list
27540
27541 PP := Opt.Check_Policy_List;
27542 while Present (PP) loop
27543 declare
27544 PPA : constant List_Id := Pragma_Argument_Associations (PP);
27545 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
27546
27547 begin
27548 if Ename = Pnm
27549 or else Pnm = Name_Assertion
27550 or else (Pnm = Name_Statement_Assertions
27551 and then Nam_In (Ename, Name_Assert,
27552 Name_Assert_And_Cut,
27553 Name_Assume,
27554 Name_Loop_Invariant,
27555 Name_Loop_Variant))
27556 then
27557 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
27558
27559 case Policy is
27560 when Name_Ignore
27561 | Name_Off
27562 =>
27563 Set_Is_Ignored (N, True);
27564 Set_Is_Checked (N, False);
27565
27566 when Name_Check
27567 | Name_On
27568 =>
27569 Set_Is_Checked (N, True);
27570 Set_Is_Ignored (N, False);
27571
27572 when Name_Disable =>
27573 Set_Is_Ignored (N, True);
27574 Set_Is_Checked (N, False);
27575 Set_Is_Disabled (N, True);
27576
27577 -- That should be exhaustive, the null here is a defence
27578 -- against a malformed tree from previous errors.
27579
27580 when others =>
27581 null;
27582 end case;
27583
27584 return;
27585 end if;
27586
27587 PP := Next_Pragma (PP);
27588 end;
27589 end loop;
27590
27591 -- If there are no specific entries that matched, then we let the
27592 -- setting of assertions govern. Note that this provides the needed
27593 -- compatibility with the RM for the cases of assertion, invariant,
27594 -- precondition, predicate, and postcondition.
27595
27596 if Assertions_Enabled then
27597 Set_Is_Checked (N, True);
27598 Set_Is_Ignored (N, False);
27599 else
27600 Set_Is_Checked (N, False);
27601 Set_Is_Ignored (N, True);
27602 end if;
27603 end Check_Applicable_Policy;
27604
27605 -------------------------------
27606 -- Check_External_Properties --
27607 -------------------------------
27608
27609 procedure Check_External_Properties
27610 (Item : Node_Id;
27611 AR : Boolean;
27612 AW : Boolean;
27613 ER : Boolean;
27614 EW : Boolean)
27615 is
27616 begin
27617 -- All properties enabled
27618
27619 if AR and AW and ER and EW then
27620 null;
27621
27622 -- Async_Readers + Effective_Writes
27623 -- Async_Readers + Async_Writers + Effective_Writes
27624
27625 elsif AR and EW and not ER then
27626 null;
27627
27628 -- Async_Writers + Effective_Reads
27629 -- Async_Readers + Async_Writers + Effective_Reads
27630
27631 elsif AW and ER and not EW then
27632 null;
27633
27634 -- Async_Readers + Async_Writers
27635
27636 elsif AR and AW and not ER and not EW then
27637 null;
27638
27639 -- Async_Readers
27640
27641 elsif AR and not AW and not ER and not EW then
27642 null;
27643
27644 -- Async_Writers
27645
27646 elsif AW and not AR and not ER and not EW then
27647 null;
27648
27649 else
27650 SPARK_Msg_N
27651 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
27652 Item);
27653 end if;
27654 end Check_External_Properties;
27655
27656 ----------------
27657 -- Check_Kind --
27658 ----------------
27659
27660 function Check_Kind (Nam : Name_Id) return Name_Id is
27661 PP : Node_Id;
27662
27663 begin
27664 -- Loop through entries in check policy list
27665
27666 PP := Opt.Check_Policy_List;
27667 while Present (PP) loop
27668 declare
27669 PPA : constant List_Id := Pragma_Argument_Associations (PP);
27670 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
27671
27672 begin
27673 if Nam = Pnm
27674 or else (Pnm = Name_Assertion
27675 and then Is_Valid_Assertion_Kind (Nam))
27676 or else (Pnm = Name_Statement_Assertions
27677 and then Nam_In (Nam, Name_Assert,
27678 Name_Assert_And_Cut,
27679 Name_Assume,
27680 Name_Loop_Invariant,
27681 Name_Loop_Variant))
27682 then
27683 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
27684 when Name_Check
27685 | Name_On
27686 =>
27687 return Name_Check;
27688
27689 when Name_Ignore
27690 | Name_Off
27691 =>
27692 return Name_Ignore;
27693
27694 when Name_Disable =>
27695 return Name_Disable;
27696
27697 when others =>
27698 raise Program_Error;
27699 end case;
27700
27701 else
27702 PP := Next_Pragma (PP);
27703 end if;
27704 end;
27705 end loop;
27706
27707 -- If there are no specific entries that matched, then we let the
27708 -- setting of assertions govern. Note that this provides the needed
27709 -- compatibility with the RM for the cases of assertion, invariant,
27710 -- precondition, predicate, and postcondition.
27711
27712 if Assertions_Enabled then
27713 return Name_Check;
27714 else
27715 return Name_Ignore;
27716 end if;
27717 end Check_Kind;
27718
27719 ---------------------------
27720 -- Check_Missing_Part_Of --
27721 ---------------------------
27722
27723 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
27724 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
27725 -- Determine whether a package denoted by Pack_Id declares at least one
27726 -- visible state.
27727
27728 -----------------------
27729 -- Has_Visible_State --
27730 -----------------------
27731
27732 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
27733 Item_Id : Entity_Id;
27734
27735 begin
27736 -- Traverse the entity chain of the package trying to find at least
27737 -- one visible abstract state, variable or a package [instantiation]
27738 -- that declares a visible state.
27739
27740 Item_Id := First_Entity (Pack_Id);
27741 while Present (Item_Id)
27742 and then not In_Private_Part (Item_Id)
27743 loop
27744 -- Do not consider internally generated items
27745
27746 if not Comes_From_Source (Item_Id) then
27747 null;
27748
27749 -- A visible state has been found
27750
27751 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
27752 return True;
27753
27754 -- Recursively peek into nested packages and instantiations
27755
27756 elsif Ekind (Item_Id) = E_Package
27757 and then Has_Visible_State (Item_Id)
27758 then
27759 return True;
27760 end if;
27761
27762 Next_Entity (Item_Id);
27763 end loop;
27764
27765 return False;
27766 end Has_Visible_State;
27767
27768 -- Local variables
27769
27770 Pack_Id : Entity_Id;
27771 Placement : State_Space_Kind;
27772
27773 -- Start of processing for Check_Missing_Part_Of
27774
27775 begin
27776 -- Do not consider abstract states, variables or package instantiations
27777 -- coming from an instance as those always inherit the Part_Of indicator
27778 -- of the instance itself.
27779
27780 if In_Instance then
27781 return;
27782
27783 -- Do not consider internally generated entities as these can never
27784 -- have a Part_Of indicator.
27785
27786 elsif not Comes_From_Source (Item_Id) then
27787 return;
27788
27789 -- Perform these checks only when SPARK_Mode is enabled as they will
27790 -- interfere with standard Ada rules and produce false positives.
27791
27792 elsif SPARK_Mode /= On then
27793 return;
27794
27795 -- Do not consider constants, because the compiler cannot accurately
27796 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
27797 -- act as a hidden state of a package.
27798
27799 elsif Ekind (Item_Id) = E_Constant then
27800 return;
27801 end if;
27802
27803 -- Find where the abstract state, variable or package instantiation
27804 -- lives with respect to the state space.
27805
27806 Find_Placement_In_State_Space
27807 (Item_Id => Item_Id,
27808 Placement => Placement,
27809 Pack_Id => Pack_Id);
27810
27811 -- Items that appear in a non-package construct (subprogram, block, etc)
27812 -- do not require a Part_Of indicator because they can never act as a
27813 -- hidden state.
27814
27815 if Placement = Not_In_Package then
27816 null;
27817
27818 -- An item declared in the body state space of a package always act as a
27819 -- constituent and does not need explicit Part_Of indicator.
27820
27821 elsif Placement = Body_State_Space then
27822 null;
27823
27824 -- In general an item declared in the visible state space of a package
27825 -- does not require a Part_Of indicator. The only exception is when the
27826 -- related package is a private child unit in which case Part_Of must
27827 -- denote a state in the parent unit or in one of its descendants.
27828
27829 elsif Placement = Visible_State_Space then
27830 if Is_Child_Unit (Pack_Id)
27831 and then Is_Private_Descendant (Pack_Id)
27832 then
27833 -- A package instantiation does not need a Part_Of indicator when
27834 -- the related generic template has no visible state.
27835
27836 if Ekind (Item_Id) = E_Package
27837 and then Is_Generic_Instance (Item_Id)
27838 and then not Has_Visible_State (Item_Id)
27839 then
27840 null;
27841
27842 -- All other cases require Part_Of
27843
27844 else
27845 Error_Msg_N
27846 ("indicator Part_Of is required in this context "
27847 & "(SPARK RM 7.2.6(3))", Item_Id);
27848 Error_Msg_Name_1 := Chars (Pack_Id);
27849 Error_Msg_N
27850 ("\& is declared in the visible part of private child "
27851 & "unit %", Item_Id);
27852 end if;
27853 end if;
27854
27855 -- When the item appears in the private state space of a packge, it must
27856 -- be a part of some state declared by the said package.
27857
27858 else pragma Assert (Placement = Private_State_Space);
27859
27860 -- The related package does not declare a state, the item cannot act
27861 -- as a Part_Of constituent.
27862
27863 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
27864 null;
27865
27866 -- A package instantiation does not need a Part_Of indicator when the
27867 -- related generic template has no visible state.
27868
27869 elsif Ekind (Pack_Id) = E_Package
27870 and then Is_Generic_Instance (Pack_Id)
27871 and then not Has_Visible_State (Pack_Id)
27872 then
27873 null;
27874
27875 -- All other cases require Part_Of
27876
27877 else
27878 Error_Msg_N
27879 ("indicator Part_Of is required in this context "
27880 & "(SPARK RM 7.2.6(2))", Item_Id);
27881 Error_Msg_Name_1 := Chars (Pack_Id);
27882 Error_Msg_N
27883 ("\& is declared in the private part of package %", Item_Id);
27884 end if;
27885 end if;
27886 end Check_Missing_Part_Of;
27887
27888 ---------------------------------------------------
27889 -- Check_Postcondition_Use_In_Inlined_Subprogram --
27890 ---------------------------------------------------
27891
27892 procedure Check_Postcondition_Use_In_Inlined_Subprogram
27893 (Prag : Node_Id;
27894 Spec_Id : Entity_Id)
27895 is
27896 begin
27897 if Warn_On_Redundant_Constructs
27898 and then Has_Pragma_Inline_Always (Spec_Id)
27899 then
27900 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
27901
27902 if From_Aspect_Specification (Prag) then
27903 Error_Msg_NE
27904 ("aspect % not enforced on inlined subprogram &?r?",
27905 Corresponding_Aspect (Prag), Spec_Id);
27906 else
27907 Error_Msg_NE
27908 ("pragma % not enforced on inlined subprogram &?r?",
27909 Prag, Spec_Id);
27910 end if;
27911 end if;
27912 end Check_Postcondition_Use_In_Inlined_Subprogram;
27913
27914 -------------------------------------
27915 -- Check_State_And_Constituent_Use --
27916 -------------------------------------
27917
27918 procedure Check_State_And_Constituent_Use
27919 (States : Elist_Id;
27920 Constits : Elist_Id;
27921 Context : Node_Id)
27922 is
27923 Constit_Elmt : Elmt_Id;
27924 Constit_Id : Entity_Id;
27925 State_Id : Entity_Id;
27926
27927 begin
27928 -- Nothing to do if there are no states or constituents
27929
27930 if No (States) or else No (Constits) then
27931 return;
27932 end if;
27933
27934 -- Inspect the list of constituents and try to determine whether its
27935 -- encapsulating state is in list States.
27936
27937 Constit_Elmt := First_Elmt (Constits);
27938 while Present (Constit_Elmt) loop
27939 Constit_Id := Node (Constit_Elmt);
27940
27941 -- Determine whether the constituent is part of an encapsulating
27942 -- state that appears in the same context and if this is the case,
27943 -- emit an error (SPARK RM 7.2.6(7)).
27944
27945 State_Id := Find_Encapsulating_State (States, Constit_Id);
27946
27947 if Present (State_Id) then
27948 Error_Msg_Name_1 := Chars (Constit_Id);
27949 SPARK_Msg_NE
27950 ("cannot mention state & and its constituent % in the same "
27951 & "context", Context, State_Id);
27952 exit;
27953 end if;
27954
27955 Next_Elmt (Constit_Elmt);
27956 end loop;
27957 end Check_State_And_Constituent_Use;
27958
27959 ---------------------------------------------
27960 -- Collect_Inherited_Class_Wide_Conditions --
27961 ---------------------------------------------
27962
27963 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
27964 Parent_Subp : constant Entity_Id :=
27965 Ultimate_Alias (Overridden_Operation (Subp));
27966 -- The Overridden_Operation may itself be inherited and as such have no
27967 -- explicit contract.
27968
27969 Prags : constant Node_Id := Contract (Parent_Subp);
27970 In_Spec_Expr : Boolean;
27971 Installed : Boolean;
27972 Prag : Node_Id;
27973 New_Prag : Node_Id;
27974
27975 begin
27976 Installed := False;
27977
27978 -- Iterate over the contract of the overridden subprogram to find all
27979 -- inherited class-wide pre- and postconditions.
27980
27981 if Present (Prags) then
27982 Prag := Pre_Post_Conditions (Prags);
27983
27984 while Present (Prag) loop
27985 if Nam_In (Pragma_Name_Unmapped (Prag),
27986 Name_Precondition, Name_Postcondition)
27987 and then Class_Present (Prag)
27988 then
27989 -- The generated pragma must be analyzed in the context of
27990 -- the subprogram, to make its formals visible. In addition,
27991 -- we must inhibit freezing and full analysis because the
27992 -- controlling type of the subprogram is not frozen yet, and
27993 -- may have further primitives.
27994
27995 if not Installed then
27996 Installed := True;
27997 Push_Scope (Subp);
27998 Install_Formals (Subp);
27999 In_Spec_Expr := In_Spec_Expression;
28000 In_Spec_Expression := True;
28001 end if;
28002
28003 New_Prag :=
28004 Build_Pragma_Check_Equivalent
28005 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
28006
28007 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
28008 Preanalyze (New_Prag);
28009
28010 -- Prevent further analysis in subsequent processing of the
28011 -- current list of declarations
28012
28013 Set_Analyzed (New_Prag);
28014 end if;
28015
28016 Prag := Next_Pragma (Prag);
28017 end loop;
28018
28019 if Installed then
28020 In_Spec_Expression := In_Spec_Expr;
28021 End_Scope;
28022 end if;
28023 end if;
28024 end Collect_Inherited_Class_Wide_Conditions;
28025
28026 ---------------------------------------
28027 -- Collect_Subprogram_Inputs_Outputs --
28028 ---------------------------------------
28029
28030 procedure Collect_Subprogram_Inputs_Outputs
28031 (Subp_Id : Entity_Id;
28032 Synthesize : Boolean := False;
28033 Subp_Inputs : in out Elist_Id;
28034 Subp_Outputs : in out Elist_Id;
28035 Global_Seen : out Boolean)
28036 is
28037 procedure Collect_Dependency_Clause (Clause : Node_Id);
28038 -- Collect all relevant items from a dependency clause
28039
28040 procedure Collect_Global_List
28041 (List : Node_Id;
28042 Mode : Name_Id := Name_Input);
28043 -- Collect all relevant items from a global list
28044
28045 -------------------------------
28046 -- Collect_Dependency_Clause --
28047 -------------------------------
28048
28049 procedure Collect_Dependency_Clause (Clause : Node_Id) is
28050 procedure Collect_Dependency_Item
28051 (Item : Node_Id;
28052 Is_Input : Boolean);
28053 -- Add an item to the proper subprogram input or output collection
28054
28055 -----------------------------
28056 -- Collect_Dependency_Item --
28057 -----------------------------
28058
28059 procedure Collect_Dependency_Item
28060 (Item : Node_Id;
28061 Is_Input : Boolean)
28062 is
28063 Extra : Node_Id;
28064
28065 begin
28066 -- Nothing to collect when the item is null
28067
28068 if Nkind (Item) = N_Null then
28069 null;
28070
28071 -- Ditto for attribute 'Result
28072
28073 elsif Is_Attribute_Result (Item) then
28074 null;
28075
28076 -- Multiple items appear as an aggregate
28077
28078 elsif Nkind (Item) = N_Aggregate then
28079 Extra := First (Expressions (Item));
28080 while Present (Extra) loop
28081 Collect_Dependency_Item (Extra, Is_Input);
28082 Next (Extra);
28083 end loop;
28084
28085 -- Otherwise this is a solitary item
28086
28087 else
28088 if Is_Input then
28089 Append_New_Elmt (Item, Subp_Inputs);
28090 else
28091 Append_New_Elmt (Item, Subp_Outputs);
28092 end if;
28093 end if;
28094 end Collect_Dependency_Item;
28095
28096 -- Start of processing for Collect_Dependency_Clause
28097
28098 begin
28099 if Nkind (Clause) = N_Null then
28100 null;
28101
28102 -- A dependency cause appears as component association
28103
28104 elsif Nkind (Clause) = N_Component_Association then
28105 Collect_Dependency_Item
28106 (Item => Expression (Clause),
28107 Is_Input => True);
28108
28109 Collect_Dependency_Item
28110 (Item => First (Choices (Clause)),
28111 Is_Input => False);
28112
28113 -- To accommodate partial decoration of disabled SPARK features, this
28114 -- routine may be called with illegal input. If this is the case, do
28115 -- not raise Program_Error.
28116
28117 else
28118 null;
28119 end if;
28120 end Collect_Dependency_Clause;
28121
28122 -------------------------
28123 -- Collect_Global_List --
28124 -------------------------
28125
28126 procedure Collect_Global_List
28127 (List : Node_Id;
28128 Mode : Name_Id := Name_Input)
28129 is
28130 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
28131 -- Add an item to the proper subprogram input or output collection
28132
28133 -------------------------
28134 -- Collect_Global_Item --
28135 -------------------------
28136
28137 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
28138 begin
28139 if Nam_In (Mode, Name_In_Out, Name_Input) then
28140 Append_New_Elmt (Item, Subp_Inputs);
28141 end if;
28142
28143 if Nam_In (Mode, Name_In_Out, Name_Output) then
28144 Append_New_Elmt (Item, Subp_Outputs);
28145 end if;
28146 end Collect_Global_Item;
28147
28148 -- Local variables
28149
28150 Assoc : Node_Id;
28151 Item : Node_Id;
28152
28153 -- Start of processing for Collect_Global_List
28154
28155 begin
28156 if Nkind (List) = N_Null then
28157 null;
28158
28159 -- Single global item declaration
28160
28161 elsif Nkind_In (List, N_Expanded_Name,
28162 N_Identifier,
28163 N_Selected_Component)
28164 then
28165 Collect_Global_Item (List, Mode);
28166
28167 -- Simple global list or moded global list declaration
28168
28169 elsif Nkind (List) = N_Aggregate then
28170 if Present (Expressions (List)) then
28171 Item := First (Expressions (List));
28172 while Present (Item) loop
28173 Collect_Global_Item (Item, Mode);
28174 Next (Item);
28175 end loop;
28176
28177 else
28178 Assoc := First (Component_Associations (List));
28179 while Present (Assoc) loop
28180 Collect_Global_List
28181 (List => Expression (Assoc),
28182 Mode => Chars (First (Choices (Assoc))));
28183 Next (Assoc);
28184 end loop;
28185 end if;
28186
28187 -- To accommodate partial decoration of disabled SPARK features, this
28188 -- routine may be called with illegal input. If this is the case, do
28189 -- not raise Program_Error.
28190
28191 else
28192 null;
28193 end if;
28194 end Collect_Global_List;
28195
28196 -- Local variables
28197
28198 Clause : Node_Id;
28199 Clauses : Node_Id;
28200 Depends : Node_Id;
28201 Formal : Entity_Id;
28202 Global : Node_Id;
28203 Spec_Id : Entity_Id;
28204 Subp_Decl : Node_Id;
28205 Typ : Entity_Id;
28206
28207 -- Start of processing for Collect_Subprogram_Inputs_Outputs
28208
28209 begin
28210 Global_Seen := False;
28211
28212 -- Process all formal parameters of entries, [generic] subprograms, and
28213 -- their bodies.
28214
28215 if Ekind_In (Subp_Id, E_Entry,
28216 E_Entry_Family,
28217 E_Function,
28218 E_Generic_Function,
28219 E_Generic_Procedure,
28220 E_Procedure,
28221 E_Subprogram_Body)
28222 then
28223 Subp_Decl := Unit_Declaration_Node (Subp_Id);
28224 Spec_Id := Unique_Defining_Entity (Subp_Decl);
28225
28226 -- Process all [generic] formal parameters
28227
28228 Formal := First_Entity (Spec_Id);
28229 while Present (Formal) loop
28230 if Ekind_In (Formal, E_Generic_In_Parameter,
28231 E_In_Out_Parameter,
28232 E_In_Parameter)
28233 then
28234 Append_New_Elmt (Formal, Subp_Inputs);
28235 end if;
28236
28237 if Ekind_In (Formal, E_Generic_In_Out_Parameter,
28238 E_In_Out_Parameter,
28239 E_Out_Parameter)
28240 then
28241 Append_New_Elmt (Formal, Subp_Outputs);
28242
28243 -- Out parameters can act as inputs when the related type is
28244 -- tagged, unconstrained array, unconstrained record, or record
28245 -- with unconstrained components.
28246
28247 if Ekind (Formal) = E_Out_Parameter
28248 and then Is_Unconstrained_Or_Tagged_Item (Formal)
28249 then
28250 Append_New_Elmt (Formal, Subp_Inputs);
28251 end if;
28252 end if;
28253
28254 Next_Entity (Formal);
28255 end loop;
28256
28257 -- Otherwise the input denotes a task type, a task body, or the
28258 -- anonymous object created for a single task type.
28259
28260 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
28261 or else Is_Single_Task_Object (Subp_Id)
28262 then
28263 Subp_Decl := Declaration_Node (Subp_Id);
28264 Spec_Id := Unique_Defining_Entity (Subp_Decl);
28265 end if;
28266
28267 -- When processing an entry, subprogram or task body, look for pragmas
28268 -- Refined_Depends and Refined_Global as they specify the inputs and
28269 -- outputs.
28270
28271 if Is_Entry_Body (Subp_Id)
28272 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
28273 then
28274 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
28275 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
28276
28277 -- Subprogram declaration or stand alone body case, look for pragmas
28278 -- Depends and Global
28279
28280 else
28281 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
28282 Global := Get_Pragma (Spec_Id, Pragma_Global);
28283 end if;
28284
28285 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
28286 -- because it provides finer granularity of inputs and outputs.
28287
28288 if Present (Global) then
28289 Global_Seen := True;
28290 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
28291
28292 -- When the related subprogram lacks pragma [Refined_]Global, fall back
28293 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
28294 -- the inputs and outputs from [Refined_]Depends.
28295
28296 elsif Synthesize and then Present (Depends) then
28297 Clauses := Expression (Get_Argument (Depends, Spec_Id));
28298
28299 -- Multiple dependency clauses appear as an aggregate
28300
28301 if Nkind (Clauses) = N_Aggregate then
28302 Clause := First (Component_Associations (Clauses));
28303 while Present (Clause) loop
28304 Collect_Dependency_Clause (Clause);
28305 Next (Clause);
28306 end loop;
28307
28308 -- Otherwise this is a single dependency clause
28309
28310 else
28311 Collect_Dependency_Clause (Clauses);
28312 end if;
28313 end if;
28314
28315 -- The current instance of a protected type acts as a formal parameter
28316 -- of mode IN for functions and IN OUT for entries and procedures
28317 -- (SPARK RM 6.1.4).
28318
28319 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
28320 Typ := Scope (Spec_Id);
28321
28322 -- Use the anonymous object when the type is single protected
28323
28324 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
28325 Typ := Anonymous_Object (Typ);
28326 end if;
28327
28328 Append_New_Elmt (Typ, Subp_Inputs);
28329
28330 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
28331 Append_New_Elmt (Typ, Subp_Outputs);
28332 end if;
28333
28334 -- The current instance of a task type acts as a formal parameter of
28335 -- mode IN OUT (SPARK RM 6.1.4).
28336
28337 elsif Ekind (Spec_Id) = E_Task_Type then
28338 Typ := Spec_Id;
28339
28340 -- Use the anonymous object when the type is single task
28341
28342 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
28343 Typ := Anonymous_Object (Typ);
28344 end if;
28345
28346 Append_New_Elmt (Typ, Subp_Inputs);
28347 Append_New_Elmt (Typ, Subp_Outputs);
28348
28349 elsif Is_Single_Task_Object (Spec_Id) then
28350 Append_New_Elmt (Spec_Id, Subp_Inputs);
28351 Append_New_Elmt (Spec_Id, Subp_Outputs);
28352 end if;
28353 end Collect_Subprogram_Inputs_Outputs;
28354
28355 ---------------------------
28356 -- Contract_Freeze_Error --
28357 ---------------------------
28358
28359 procedure Contract_Freeze_Error
28360 (Contract_Id : Entity_Id;
28361 Freeze_Id : Entity_Id)
28362 is
28363 begin
28364 Error_Msg_Name_1 := Chars (Contract_Id);
28365 Error_Msg_Sloc := Sloc (Freeze_Id);
28366
28367 SPARK_Msg_NE
28368 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
28369 SPARK_Msg_N
28370 ("\all contractual items must be declared before body #", Contract_Id);
28371 end Contract_Freeze_Error;
28372
28373 ---------------------------------
28374 -- Delay_Config_Pragma_Analyze --
28375 ---------------------------------
28376
28377 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
28378 begin
28379 return Nam_In (Pragma_Name_Unmapped (N),
28380 Name_Interrupt_State, Name_Priority_Specific_Dispatching);
28381 end Delay_Config_Pragma_Analyze;
28382
28383 -----------------------
28384 -- Duplication_Error --
28385 -----------------------
28386
28387 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
28388 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
28389 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
28390
28391 begin
28392 Error_Msg_Sloc := Sloc (Prev);
28393 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
28394
28395 -- Emit a precise message to distinguish between source pragmas and
28396 -- pragmas generated from aspects. The ordering of the two pragmas is
28397 -- the following:
28398
28399 -- Prev -- ok
28400 -- Prag -- duplicate
28401
28402 -- No error is emitted when both pragmas come from aspects because this
28403 -- is already detected by the general aspect analysis mechanism.
28404
28405 if Prag_From_Asp and Prev_From_Asp then
28406 null;
28407 elsif Prag_From_Asp then
28408 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
28409 elsif Prev_From_Asp then
28410 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
28411 else
28412 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
28413 end if;
28414 end Duplication_Error;
28415
28416 ------------------------------
28417 -- Find_Encapsulating_State --
28418 ------------------------------
28419
28420 function Find_Encapsulating_State
28421 (States : Elist_Id;
28422 Constit_Id : Entity_Id) return Entity_Id
28423 is
28424 State_Id : Entity_Id;
28425
28426 begin
28427 -- Since a constituent may be part of a larger constituent set, climb
28428 -- the encapsulating state chain looking for a state that appears in
28429 -- States.
28430
28431 State_Id := Encapsulating_State (Constit_Id);
28432 while Present (State_Id) loop
28433 if Contains (States, State_Id) then
28434 return State_Id;
28435 end if;
28436
28437 State_Id := Encapsulating_State (State_Id);
28438 end loop;
28439
28440 return Empty;
28441 end Find_Encapsulating_State;
28442
28443 --------------------------
28444 -- Find_Related_Context --
28445 --------------------------
28446
28447 function Find_Related_Context
28448 (Prag : Node_Id;
28449 Do_Checks : Boolean := False) return Node_Id
28450 is
28451 Stmt : Node_Id;
28452
28453 begin
28454 Stmt := Prev (Prag);
28455 while Present (Stmt) loop
28456
28457 -- Skip prior pragmas, but check for duplicates
28458
28459 if Nkind (Stmt) = N_Pragma then
28460 if Do_Checks
28461 and then Pragma_Name (Stmt) = Pragma_Name (Prag)
28462 then
28463 Duplication_Error
28464 (Prag => Prag,
28465 Prev => Stmt);
28466 end if;
28467
28468 -- Skip internally generated code
28469
28470 elsif not Comes_From_Source (Stmt) then
28471
28472 -- The anonymous object created for a single concurrent type is a
28473 -- suitable context.
28474
28475 if Nkind (Stmt) = N_Object_Declaration
28476 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
28477 then
28478 return Stmt;
28479 end if;
28480
28481 -- Return the current source construct
28482
28483 else
28484 return Stmt;
28485 end if;
28486
28487 Prev (Stmt);
28488 end loop;
28489
28490 return Empty;
28491 end Find_Related_Context;
28492
28493 --------------------------------------
28494 -- Find_Related_Declaration_Or_Body --
28495 --------------------------------------
28496
28497 function Find_Related_Declaration_Or_Body
28498 (Prag : Node_Id;
28499 Do_Checks : Boolean := False) return Node_Id
28500 is
28501 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
28502
28503 procedure Expression_Function_Error;
28504 -- Emit an error concerning pragma Prag that illegaly applies to an
28505 -- expression function.
28506
28507 -------------------------------
28508 -- Expression_Function_Error --
28509 -------------------------------
28510
28511 procedure Expression_Function_Error is
28512 begin
28513 Error_Msg_Name_1 := Prag_Nam;
28514
28515 -- Emit a precise message to distinguish between source pragmas and
28516 -- pragmas generated from aspects.
28517
28518 if From_Aspect_Specification (Prag) then
28519 Error_Msg_N
28520 ("aspect % cannot apply to a stand alone expression function",
28521 Prag);
28522 else
28523 Error_Msg_N
28524 ("pragma % cannot apply to a stand alone expression function",
28525 Prag);
28526 end if;
28527 end Expression_Function_Error;
28528
28529 -- Local variables
28530
28531 Context : constant Node_Id := Parent (Prag);
28532 Stmt : Node_Id;
28533
28534 Look_For_Body : constant Boolean :=
28535 Nam_In (Prag_Nam, Name_Refined_Depends,
28536 Name_Refined_Global,
28537 Name_Refined_Post);
28538 -- Refinement pragmas must be associated with a subprogram body [stub]
28539
28540 -- Start of processing for Find_Related_Declaration_Or_Body
28541
28542 begin
28543 Stmt := Prev (Prag);
28544 while Present (Stmt) loop
28545
28546 -- Skip prior pragmas, but check for duplicates. Pragmas produced
28547 -- by splitting a complex pre/postcondition are not considered to
28548 -- be duplicates.
28549
28550 if Nkind (Stmt) = N_Pragma then
28551 if Do_Checks
28552 and then not Split_PPC (Stmt)
28553 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
28554 then
28555 Duplication_Error
28556 (Prag => Prag,
28557 Prev => Stmt);
28558 end if;
28559
28560 -- Emit an error when a refinement pragma appears on an expression
28561 -- function without a completion.
28562
28563 elsif Do_Checks
28564 and then Look_For_Body
28565 and then Nkind (Stmt) = N_Subprogram_Declaration
28566 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
28567 and then not Has_Completion (Defining_Entity (Stmt))
28568 then
28569 Expression_Function_Error;
28570 return Empty;
28571
28572 -- The refinement pragma applies to a subprogram body stub
28573
28574 elsif Look_For_Body
28575 and then Nkind (Stmt) = N_Subprogram_Body_Stub
28576 then
28577 return Stmt;
28578
28579 -- Skip internally generated code
28580
28581 elsif not Comes_From_Source (Stmt) then
28582
28583 -- The anonymous object created for a single concurrent type is a
28584 -- suitable context.
28585
28586 if Nkind (Stmt) = N_Object_Declaration
28587 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
28588 then
28589 return Stmt;
28590
28591 elsif Nkind (Stmt) = N_Subprogram_Declaration then
28592
28593 -- The subprogram declaration is an internally generated spec
28594 -- for an expression function.
28595
28596 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
28597 return Stmt;
28598
28599 -- The subprogram is actually an instance housed within an
28600 -- anonymous wrapper package.
28601
28602 elsif Present (Generic_Parent (Specification (Stmt))) then
28603 return Stmt;
28604 end if;
28605 end if;
28606
28607 -- Return the current construct which is either a subprogram body,
28608 -- a subprogram declaration or is illegal.
28609
28610 else
28611 return Stmt;
28612 end if;
28613
28614 Prev (Stmt);
28615 end loop;
28616
28617 -- If we fall through, then the pragma was either the first declaration
28618 -- or it was preceded by other pragmas and no source constructs.
28619
28620 -- The pragma is associated with a library-level subprogram
28621
28622 if Nkind (Context) = N_Compilation_Unit_Aux then
28623 return Unit (Parent (Context));
28624
28625 -- The pragma appears inside the declarations of an entry body
28626
28627 elsif Nkind (Context) = N_Entry_Body then
28628 return Context;
28629
28630 -- The pragma appears inside the statements of a subprogram body. This
28631 -- placement is the result of subprogram contract expansion.
28632
28633 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
28634 return Parent (Context);
28635
28636 -- The pragma appears inside the declarative part of a subprogram body
28637
28638 elsif Nkind (Context) = N_Subprogram_Body then
28639 return Context;
28640
28641 -- The pragma appears inside the declarative part of a task body
28642
28643 elsif Nkind (Context) = N_Task_Body then
28644 return Context;
28645
28646 -- The pragma is a byproduct of aspect expansion, return the related
28647 -- context of the original aspect. This case has a lower priority as
28648 -- the above circuitry pinpoints precisely the related context.
28649
28650 elsif Present (Corresponding_Aspect (Prag)) then
28651 return Parent (Corresponding_Aspect (Prag));
28652
28653 -- No candidate subprogram [body] found
28654
28655 else
28656 return Empty;
28657 end if;
28658 end Find_Related_Declaration_Or_Body;
28659
28660 ----------------------------------
28661 -- Find_Related_Package_Or_Body --
28662 ----------------------------------
28663
28664 function Find_Related_Package_Or_Body
28665 (Prag : Node_Id;
28666 Do_Checks : Boolean := False) return Node_Id
28667 is
28668 Context : constant Node_Id := Parent (Prag);
28669 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
28670 Stmt : Node_Id;
28671
28672 begin
28673 Stmt := Prev (Prag);
28674 while Present (Stmt) loop
28675
28676 -- Skip prior pragmas, but check for duplicates
28677
28678 if Nkind (Stmt) = N_Pragma then
28679 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
28680 Duplication_Error
28681 (Prag => Prag,
28682 Prev => Stmt);
28683 end if;
28684
28685 -- Skip internally generated code
28686
28687 elsif not Comes_From_Source (Stmt) then
28688 if Nkind (Stmt) = N_Subprogram_Declaration then
28689
28690 -- The subprogram declaration is an internally generated spec
28691 -- for an expression function.
28692
28693 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
28694 return Stmt;
28695
28696 -- The subprogram is actually an instance housed within an
28697 -- anonymous wrapper package.
28698
28699 elsif Present (Generic_Parent (Specification (Stmt))) then
28700 return Stmt;
28701 end if;
28702 end if;
28703
28704 -- Return the current source construct which is illegal
28705
28706 else
28707 return Stmt;
28708 end if;
28709
28710 Prev (Stmt);
28711 end loop;
28712
28713 -- If we fall through, then the pragma was either the first declaration
28714 -- or it was preceded by other pragmas and no source constructs.
28715
28716 -- The pragma is associated with a package. The immediate context in
28717 -- this case is the specification of the package.
28718
28719 if Nkind (Context) = N_Package_Specification then
28720 return Parent (Context);
28721
28722 -- The pragma appears in the declarations of a package body
28723
28724 elsif Nkind (Context) = N_Package_Body then
28725 return Context;
28726
28727 -- The pragma appears in the statements of a package body
28728
28729 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
28730 and then Nkind (Parent (Context)) = N_Package_Body
28731 then
28732 return Parent (Context);
28733
28734 -- The pragma is a byproduct of aspect expansion, return the related
28735 -- context of the original aspect. This case has a lower priority as
28736 -- the above circuitry pinpoints precisely the related context.
28737
28738 elsif Present (Corresponding_Aspect (Prag)) then
28739 return Parent (Corresponding_Aspect (Prag));
28740
28741 -- No candidate packge [body] found
28742
28743 else
28744 return Empty;
28745 end if;
28746 end Find_Related_Package_Or_Body;
28747
28748 ------------------
28749 -- Get_Argument --
28750 ------------------
28751
28752 function Get_Argument
28753 (Prag : Node_Id;
28754 Context_Id : Entity_Id := Empty) return Node_Id
28755 is
28756 Args : constant List_Id := Pragma_Argument_Associations (Prag);
28757
28758 begin
28759 -- Use the expression of the original aspect when compiling for ASIS or
28760 -- when analyzing the template of a generic unit. In both cases the
28761 -- aspect's tree must be decorated to allow for ASIS queries or to save
28762 -- the global references in the generic context.
28763
28764 if From_Aspect_Specification (Prag)
28765 and then (ASIS_Mode or else (Present (Context_Id)
28766 and then Is_Generic_Unit (Context_Id)))
28767 then
28768 return Corresponding_Aspect (Prag);
28769
28770 -- Otherwise use the expression of the pragma
28771
28772 elsif Present (Args) then
28773 return First (Args);
28774
28775 else
28776 return Empty;
28777 end if;
28778 end Get_Argument;
28779
28780 -------------------------
28781 -- Get_Base_Subprogram --
28782 -------------------------
28783
28784 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
28785 Result : Entity_Id;
28786
28787 begin
28788 -- Follow subprogram renaming chain
28789
28790 Result := Def_Id;
28791
28792 if Is_Subprogram (Result)
28793 and then
28794 Nkind (Parent (Declaration_Node (Result))) =
28795 N_Subprogram_Renaming_Declaration
28796 and then Present (Alias (Result))
28797 then
28798 Result := Alias (Result);
28799 end if;
28800
28801 return Result;
28802 end Get_Base_Subprogram;
28803
28804 -----------------------
28805 -- Get_SPARK_Mode_Type --
28806 -----------------------
28807
28808 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
28809 begin
28810 if N = Name_On then
28811 return On;
28812 elsif N = Name_Off then
28813 return Off;
28814
28815 -- Any other argument is illegal
28816
28817 else
28818 raise Program_Error;
28819 end if;
28820 end Get_SPARK_Mode_Type;
28821
28822 ------------------------------------
28823 -- Get_SPARK_Mode_From_Annotation --
28824 ------------------------------------
28825
28826 function Get_SPARK_Mode_From_Annotation
28827 (N : Node_Id) return SPARK_Mode_Type
28828 is
28829 Mode : Node_Id;
28830
28831 begin
28832 if Nkind (N) = N_Aspect_Specification then
28833 Mode := Expression (N);
28834
28835 else pragma Assert (Nkind (N) = N_Pragma);
28836 Mode := First (Pragma_Argument_Associations (N));
28837
28838 if Present (Mode) then
28839 Mode := Get_Pragma_Arg (Mode);
28840 end if;
28841 end if;
28842
28843 -- Aspect or pragma SPARK_Mode specifies an explicit mode
28844
28845 if Present (Mode) then
28846 if Nkind (Mode) = N_Identifier then
28847 return Get_SPARK_Mode_Type (Chars (Mode));
28848
28849 -- In case of a malformed aspect or pragma, return the default None
28850
28851 else
28852 return None;
28853 end if;
28854
28855 -- Otherwise the lack of an expression defaults SPARK_Mode to On
28856
28857 else
28858 return On;
28859 end if;
28860 end Get_SPARK_Mode_From_Annotation;
28861
28862 ---------------------------
28863 -- Has_Extra_Parentheses --
28864 ---------------------------
28865
28866 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
28867 Expr : Node_Id;
28868
28869 begin
28870 -- The aggregate should not have an expression list because a clause
28871 -- is always interpreted as a component association. The only way an
28872 -- expression list can sneak in is by adding extra parentheses around
28873 -- the individual clauses:
28874
28875 -- Depends (Output => Input) -- proper form
28876 -- Depends ((Output => Input)) -- extra parentheses
28877
28878 -- Since the extra parentheses are not allowed by the syntax of the
28879 -- pragma, flag them now to avoid emitting misleading errors down the
28880 -- line.
28881
28882 if Nkind (Clause) = N_Aggregate
28883 and then Present (Expressions (Clause))
28884 then
28885 Expr := First (Expressions (Clause));
28886 while Present (Expr) loop
28887
28888 -- A dependency clause surrounded by extra parentheses appears
28889 -- as an aggregate of component associations with an optional
28890 -- Paren_Count set.
28891
28892 if Nkind (Expr) = N_Aggregate
28893 and then Present (Component_Associations (Expr))
28894 then
28895 SPARK_Msg_N
28896 ("dependency clause contains extra parentheses", Expr);
28897
28898 -- Otherwise the expression is a malformed construct
28899
28900 else
28901 SPARK_Msg_N ("malformed dependency clause", Expr);
28902 end if;
28903
28904 Next (Expr);
28905 end loop;
28906
28907 return True;
28908 end if;
28909
28910 return False;
28911 end Has_Extra_Parentheses;
28912
28913 ----------------
28914 -- Initialize --
28915 ----------------
28916
28917 procedure Initialize is
28918 begin
28919 Externals.Init;
28920 end Initialize;
28921
28922 --------
28923 -- ip --
28924 --------
28925
28926 procedure ip is
28927 begin
28928 Dummy := Dummy + 1;
28929 end ip;
28930
28931 -----------------------------
28932 -- Is_Config_Static_String --
28933 -----------------------------
28934
28935 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
28936
28937 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
28938 -- This is an internal recursive function that is just like the outer
28939 -- function except that it adds the string to the name buffer rather
28940 -- than placing the string in the name buffer.
28941
28942 ------------------------------
28943 -- Add_Config_Static_String --
28944 ------------------------------
28945
28946 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
28947 N : Node_Id;
28948 C : Char_Code;
28949
28950 begin
28951 N := Arg;
28952
28953 if Nkind (N) = N_Op_Concat then
28954 if Add_Config_Static_String (Left_Opnd (N)) then
28955 N := Right_Opnd (N);
28956 else
28957 return False;
28958 end if;
28959 end if;
28960
28961 if Nkind (N) /= N_String_Literal then
28962 Error_Msg_N ("string literal expected for pragma argument", N);
28963 return False;
28964
28965 else
28966 for J in 1 .. String_Length (Strval (N)) loop
28967 C := Get_String_Char (Strval (N), J);
28968
28969 if not In_Character_Range (C) then
28970 Error_Msg
28971 ("string literal contains invalid wide character",
28972 Sloc (N) + 1 + Source_Ptr (J));
28973 return False;
28974 end if;
28975
28976 Add_Char_To_Name_Buffer (Get_Character (C));
28977 end loop;
28978 end if;
28979
28980 return True;
28981 end Add_Config_Static_String;
28982
28983 -- Start of processing for Is_Config_Static_String
28984
28985 begin
28986 Name_Len := 0;
28987
28988 return Add_Config_Static_String (Arg);
28989 end Is_Config_Static_String;
28990
28991 ---------------------
28992 -- Is_CCT_Instance --
28993 ---------------------
28994
28995 function Is_CCT_Instance
28996 (Ref_Id : Entity_Id;
28997 Context_Id : Entity_Id) return Boolean
28998 is
28999 S : Entity_Id;
29000 Typ : Entity_Id;
29001
29002 begin
29003 -- When the reference denotes a single protected type, the context is
29004 -- either a protected subprogram or its body.
29005
29006 if Is_Single_Protected_Object (Ref_Id) then
29007 Typ := Scope (Context_Id);
29008
29009 return
29010 Ekind (Typ) = E_Protected_Type
29011 and then Present (Anonymous_Object (Typ))
29012 and then Anonymous_Object (Typ) = Ref_Id;
29013
29014 -- When the reference denotes a single task type, the context is either
29015 -- the same type or if inside the body, the anonymous task type.
29016
29017 elsif Is_Single_Task_Object (Ref_Id) then
29018 if Ekind (Context_Id) = E_Task_Type then
29019 return
29020 Present (Anonymous_Object (Context_Id))
29021 and then Anonymous_Object (Context_Id) = Ref_Id;
29022 else
29023 return Ref_Id = Context_Id;
29024 end if;
29025
29026 -- Otherwise the reference denotes a protected or a task type. Climb the
29027 -- scope chain looking for an enclosing concurrent type that matches the
29028 -- referenced entity.
29029
29030 else
29031 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
29032
29033 S := Current_Scope;
29034 while Present (S) and then S /= Standard_Standard loop
29035 if Ekind_In (S, E_Protected_Type, E_Task_Type)
29036 and then S = Ref_Id
29037 then
29038 return True;
29039 end if;
29040
29041 S := Scope (S);
29042 end loop;
29043 end if;
29044
29045 return False;
29046 end Is_CCT_Instance;
29047
29048 -------------------------------
29049 -- Is_Elaboration_SPARK_Mode --
29050 -------------------------------
29051
29052 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
29053 begin
29054 pragma Assert
29055 (Nkind (N) = N_Pragma
29056 and then Pragma_Name (N) = Name_SPARK_Mode
29057 and then Is_List_Member (N));
29058
29059 -- Pragma SPARK_Mode affects the elaboration of a package body when it
29060 -- appears in the statement part of the body.
29061
29062 return
29063 Present (Parent (N))
29064 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
29065 and then List_Containing (N) = Statements (Parent (N))
29066 and then Present (Parent (Parent (N)))
29067 and then Nkind (Parent (Parent (N))) = N_Package_Body;
29068 end Is_Elaboration_SPARK_Mode;
29069
29070 -----------------------
29071 -- Is_Enabled_Pragma --
29072 -----------------------
29073
29074 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
29075 Arg : Node_Id;
29076
29077 begin
29078 if Present (Prag) then
29079 Arg := First (Pragma_Argument_Associations (Prag));
29080
29081 if Present (Arg) then
29082 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
29083
29084 -- The lack of a Boolean argument automatically enables the pragma
29085
29086 else
29087 return True;
29088 end if;
29089
29090 -- The pragma is missing, therefore it is not enabled
29091
29092 else
29093 return False;
29094 end if;
29095 end Is_Enabled_Pragma;
29096
29097 -----------------------------------------
29098 -- Is_Non_Significant_Pragma_Reference --
29099 -----------------------------------------
29100
29101 -- This function makes use of the following static table which indicates
29102 -- whether appearance of some name in a given pragma is to be considered
29103 -- as a reference for the purposes of warnings about unreferenced objects.
29104
29105 -- -1 indicates that appearence in any argument is significant
29106 -- 0 indicates that appearance in any argument is not significant
29107 -- +n indicates that appearance as argument n is significant, but all
29108 -- other arguments are not significant
29109 -- 9n arguments from n on are significant, before n insignificant
29110
29111 Sig_Flags : constant array (Pragma_Id) of Int :=
29112 (Pragma_Abort_Defer => -1,
29113 Pragma_Abstract_State => -1,
29114 Pragma_Ada_83 => -1,
29115 Pragma_Ada_95 => -1,
29116 Pragma_Ada_05 => -1,
29117 Pragma_Ada_2005 => -1,
29118 Pragma_Ada_12 => -1,
29119 Pragma_Ada_2012 => -1,
29120 Pragma_All_Calls_Remote => -1,
29121 Pragma_Allow_Integer_Address => -1,
29122 Pragma_Annotate => 93,
29123 Pragma_Assert => -1,
29124 Pragma_Assert_And_Cut => -1,
29125 Pragma_Assertion_Policy => 0,
29126 Pragma_Assume => -1,
29127 Pragma_Assume_No_Invalid_Values => 0,
29128 Pragma_Async_Readers => 0,
29129 Pragma_Async_Writers => 0,
29130 Pragma_Asynchronous => 0,
29131 Pragma_Atomic => 0,
29132 Pragma_Atomic_Components => 0,
29133 Pragma_Attach_Handler => -1,
29134 Pragma_Attribute_Definition => 92,
29135 Pragma_Check => -1,
29136 Pragma_Check_Float_Overflow => 0,
29137 Pragma_Check_Name => 0,
29138 Pragma_Check_Policy => 0,
29139 Pragma_CPP_Class => 0,
29140 Pragma_CPP_Constructor => 0,
29141 Pragma_CPP_Virtual => 0,
29142 Pragma_CPP_Vtable => 0,
29143 Pragma_CPU => -1,
29144 Pragma_C_Pass_By_Copy => 0,
29145 Pragma_Comment => -1,
29146 Pragma_Common_Object => 0,
29147 Pragma_Compile_Time_Error => -1,
29148 Pragma_Compile_Time_Warning => -1,
29149 Pragma_Compiler_Unit => -1,
29150 Pragma_Compiler_Unit_Warning => -1,
29151 Pragma_Complete_Representation => 0,
29152 Pragma_Complex_Representation => 0,
29153 Pragma_Component_Alignment => 0,
29154 Pragma_Constant_After_Elaboration => 0,
29155 Pragma_Contract_Cases => -1,
29156 Pragma_Controlled => 0,
29157 Pragma_Convention => 0,
29158 Pragma_Convention_Identifier => 0,
29159 Pragma_Deadline_Floor => -1,
29160 Pragma_Debug => -1,
29161 Pragma_Debug_Policy => 0,
29162 Pragma_Detect_Blocking => 0,
29163 Pragma_Default_Initial_Condition => -1,
29164 Pragma_Default_Scalar_Storage_Order => 0,
29165 Pragma_Default_Storage_Pool => 0,
29166 Pragma_Depends => -1,
29167 Pragma_Disable_Atomic_Synchronization => 0,
29168 Pragma_Discard_Names => 0,
29169 Pragma_Dispatching_Domain => -1,
29170 Pragma_Effective_Reads => 0,
29171 Pragma_Effective_Writes => 0,
29172 Pragma_Elaborate => 0,
29173 Pragma_Elaborate_All => 0,
29174 Pragma_Elaborate_Body => 0,
29175 Pragma_Elaboration_Checks => 0,
29176 Pragma_Eliminate => 0,
29177 Pragma_Enable_Atomic_Synchronization => 0,
29178 Pragma_Export => -1,
29179 Pragma_Export_Function => -1,
29180 Pragma_Export_Object => -1,
29181 Pragma_Export_Procedure => -1,
29182 Pragma_Export_Value => -1,
29183 Pragma_Export_Valued_Procedure => -1,
29184 Pragma_Extend_System => -1,
29185 Pragma_Extensions_Allowed => 0,
29186 Pragma_Extensions_Visible => 0,
29187 Pragma_External => -1,
29188 Pragma_Favor_Top_Level => 0,
29189 Pragma_External_Name_Casing => 0,
29190 Pragma_Fast_Math => 0,
29191 Pragma_Finalize_Storage_Only => 0,
29192 Pragma_Ghost => 0,
29193 Pragma_Global => -1,
29194 Pragma_Ident => -1,
29195 Pragma_Ignore_Pragma => 0,
29196 Pragma_Implementation_Defined => -1,
29197 Pragma_Implemented => -1,
29198 Pragma_Implicit_Packing => 0,
29199 Pragma_Import => 93,
29200 Pragma_Import_Function => 0,
29201 Pragma_Import_Object => 0,
29202 Pragma_Import_Procedure => 0,
29203 Pragma_Import_Valued_Procedure => 0,
29204 Pragma_Independent => 0,
29205 Pragma_Independent_Components => 0,
29206 Pragma_Initial_Condition => -1,
29207 Pragma_Initialize_Scalars => 0,
29208 Pragma_Initializes => -1,
29209 Pragma_Inline => 0,
29210 Pragma_Inline_Always => 0,
29211 Pragma_Inline_Generic => 0,
29212 Pragma_Inspection_Point => -1,
29213 Pragma_Interface => 92,
29214 Pragma_Interface_Name => 0,
29215 Pragma_Interrupt_Handler => -1,
29216 Pragma_Interrupt_Priority => -1,
29217 Pragma_Interrupt_State => -1,
29218 Pragma_Invariant => -1,
29219 Pragma_Keep_Names => 0,
29220 Pragma_License => 0,
29221 Pragma_Link_With => -1,
29222 Pragma_Linker_Alias => -1,
29223 Pragma_Linker_Constructor => -1,
29224 Pragma_Linker_Destructor => -1,
29225 Pragma_Linker_Options => -1,
29226 Pragma_Linker_Section => 0,
29227 Pragma_List => 0,
29228 Pragma_Lock_Free => 0,
29229 Pragma_Locking_Policy => 0,
29230 Pragma_Loop_Invariant => -1,
29231 Pragma_Loop_Optimize => 0,
29232 Pragma_Loop_Variant => -1,
29233 Pragma_Machine_Attribute => -1,
29234 Pragma_Main => -1,
29235 Pragma_Main_Storage => -1,
29236 Pragma_Max_Queue_Length => 0,
29237 Pragma_Memory_Size => 0,
29238 Pragma_No_Return => 0,
29239 Pragma_No_Body => 0,
29240 Pragma_No_Elaboration_Code_All => 0,
29241 Pragma_No_Heap_Finalization => 0,
29242 Pragma_No_Inline => 0,
29243 Pragma_No_Run_Time => -1,
29244 Pragma_No_Strict_Aliasing => -1,
29245 Pragma_No_Tagged_Streams => 0,
29246 Pragma_Normalize_Scalars => 0,
29247 Pragma_Obsolescent => 0,
29248 Pragma_Optimize => 0,
29249 Pragma_Optimize_Alignment => 0,
29250 Pragma_Overflow_Mode => 0,
29251 Pragma_Overriding_Renamings => 0,
29252 Pragma_Ordered => 0,
29253 Pragma_Pack => 0,
29254 Pragma_Page => 0,
29255 Pragma_Part_Of => 0,
29256 Pragma_Partition_Elaboration_Policy => 0,
29257 Pragma_Passive => 0,
29258 Pragma_Persistent_BSS => 0,
29259 Pragma_Polling => 0,
29260 Pragma_Prefix_Exception_Messages => 0,
29261 Pragma_Post => -1,
29262 Pragma_Postcondition => -1,
29263 Pragma_Post_Class => -1,
29264 Pragma_Pre => -1,
29265 Pragma_Precondition => -1,
29266 Pragma_Predicate => -1,
29267 Pragma_Predicate_Failure => -1,
29268 Pragma_Preelaborable_Initialization => -1,
29269 Pragma_Preelaborate => 0,
29270 Pragma_Pre_Class => -1,
29271 Pragma_Priority => -1,
29272 Pragma_Priority_Specific_Dispatching => 0,
29273 Pragma_Profile => 0,
29274 Pragma_Profile_Warnings => 0,
29275 Pragma_Propagate_Exceptions => 0,
29276 Pragma_Provide_Shift_Operators => 0,
29277 Pragma_Psect_Object => 0,
29278 Pragma_Pure => 0,
29279 Pragma_Pure_Function => 0,
29280 Pragma_Queuing_Policy => 0,
29281 Pragma_Rational => 0,
29282 Pragma_Ravenscar => 0,
29283 Pragma_Refined_Depends => -1,
29284 Pragma_Refined_Global => -1,
29285 Pragma_Refined_Post => -1,
29286 Pragma_Refined_State => -1,
29287 Pragma_Relative_Deadline => 0,
29288 Pragma_Rename_Pragma => 0,
29289 Pragma_Remote_Access_Type => -1,
29290 Pragma_Remote_Call_Interface => -1,
29291 Pragma_Remote_Types => -1,
29292 Pragma_Restricted_Run_Time => 0,
29293 Pragma_Restriction_Warnings => 0,
29294 Pragma_Restrictions => 0,
29295 Pragma_Reviewable => -1,
29296 Pragma_Secondary_Stack_Size => -1,
29297 Pragma_Short_Circuit_And_Or => 0,
29298 Pragma_Share_Generic => 0,
29299 Pragma_Shared => 0,
29300 Pragma_Shared_Passive => 0,
29301 Pragma_Short_Descriptors => 0,
29302 Pragma_Simple_Storage_Pool_Type => 0,
29303 Pragma_Source_File_Name => 0,
29304 Pragma_Source_File_Name_Project => 0,
29305 Pragma_Source_Reference => 0,
29306 Pragma_SPARK_Mode => 0,
29307 Pragma_Storage_Size => -1,
29308 Pragma_Storage_Unit => 0,
29309 Pragma_Static_Elaboration_Desired => 0,
29310 Pragma_Stream_Convert => 0,
29311 Pragma_Style_Checks => 0,
29312 Pragma_Subtitle => 0,
29313 Pragma_Suppress => 0,
29314 Pragma_Suppress_Exception_Locations => 0,
29315 Pragma_Suppress_All => 0,
29316 Pragma_Suppress_Debug_Info => 0,
29317 Pragma_Suppress_Initialization => 0,
29318 Pragma_System_Name => 0,
29319 Pragma_Task_Dispatching_Policy => 0,
29320 Pragma_Task_Info => -1,
29321 Pragma_Task_Name => -1,
29322 Pragma_Task_Storage => -1,
29323 Pragma_Test_Case => -1,
29324 Pragma_Thread_Local_Storage => -1,
29325 Pragma_Time_Slice => -1,
29326 Pragma_Title => 0,
29327 Pragma_Type_Invariant => -1,
29328 Pragma_Type_Invariant_Class => -1,
29329 Pragma_Unchecked_Union => 0,
29330 Pragma_Unevaluated_Use_Of_Old => 0,
29331 Pragma_Unimplemented_Unit => 0,
29332 Pragma_Universal_Aliasing => 0,
29333 Pragma_Universal_Data => 0,
29334 Pragma_Unmodified => 0,
29335 Pragma_Unreferenced => 0,
29336 Pragma_Unreferenced_Objects => 0,
29337 Pragma_Unreserve_All_Interrupts => 0,
29338 Pragma_Unsuppress => 0,
29339 Pragma_Unused => 0,
29340 Pragma_Use_VADS_Size => 0,
29341 Pragma_Validity_Checks => 0,
29342 Pragma_Volatile => 0,
29343 Pragma_Volatile_Components => 0,
29344 Pragma_Volatile_Full_Access => 0,
29345 Pragma_Volatile_Function => 0,
29346 Pragma_Warning_As_Error => 0,
29347 Pragma_Warnings => 0,
29348 Pragma_Weak_External => 0,
29349 Pragma_Wide_Character_Encoding => 0,
29350 Unknown_Pragma => 0);
29351
29352 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
29353 Id : Pragma_Id;
29354 P : Node_Id;
29355 C : Int;
29356 AN : Nat;
29357
29358 function Arg_No return Nat;
29359 -- Returns an integer showing what argument we are in. A value of
29360 -- zero means we are not in any of the arguments.
29361
29362 ------------
29363 -- Arg_No --
29364 ------------
29365
29366 function Arg_No return Nat is
29367 A : Node_Id;
29368 N : Nat;
29369
29370 begin
29371 A := First (Pragma_Argument_Associations (Parent (P)));
29372 N := 1;
29373 loop
29374 if No (A) then
29375 return 0;
29376 elsif A = P then
29377 return N;
29378 end if;
29379
29380 Next (A);
29381 N := N + 1;
29382 end loop;
29383 end Arg_No;
29384
29385 -- Start of processing for Non_Significant_Pragma_Reference
29386
29387 begin
29388 P := Parent (N);
29389
29390 if Nkind (P) /= N_Pragma_Argument_Association then
29391 return False;
29392
29393 else
29394 Id := Get_Pragma_Id (Parent (P));
29395 C := Sig_Flags (Id);
29396 AN := Arg_No;
29397
29398 if AN = 0 then
29399 return False;
29400 end if;
29401
29402 case C is
29403 when -1 =>
29404 return False;
29405
29406 when 0 =>
29407 return True;
29408
29409 when 92 .. 99 =>
29410 return AN < (C - 90);
29411
29412 when others =>
29413 return AN /= C;
29414 end case;
29415 end if;
29416 end Is_Non_Significant_Pragma_Reference;
29417
29418 ------------------------------
29419 -- Is_Pragma_String_Literal --
29420 ------------------------------
29421
29422 -- This function returns true if the corresponding pragma argument is a
29423 -- static string expression. These are the only cases in which string
29424 -- literals can appear as pragma arguments. We also allow a string literal
29425 -- as the first argument to pragma Assert (although it will of course
29426 -- always generate a type error).
29427
29428 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
29429 Pragn : constant Node_Id := Parent (Par);
29430 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
29431 Pname : constant Name_Id := Pragma_Name (Pragn);
29432 Argn : Natural;
29433 N : Node_Id;
29434
29435 begin
29436 Argn := 1;
29437 N := First (Assoc);
29438 loop
29439 exit when N = Par;
29440 Argn := Argn + 1;
29441 Next (N);
29442 end loop;
29443
29444 if Pname = Name_Assert then
29445 return True;
29446
29447 elsif Pname = Name_Export then
29448 return Argn > 2;
29449
29450 elsif Pname = Name_Ident then
29451 return Argn = 1;
29452
29453 elsif Pname = Name_Import then
29454 return Argn > 2;
29455
29456 elsif Pname = Name_Interface_Name then
29457 return Argn > 1;
29458
29459 elsif Pname = Name_Linker_Alias then
29460 return Argn = 2;
29461
29462 elsif Pname = Name_Linker_Section then
29463 return Argn = 2;
29464
29465 elsif Pname = Name_Machine_Attribute then
29466 return Argn = 2;
29467
29468 elsif Pname = Name_Source_File_Name then
29469 return True;
29470
29471 elsif Pname = Name_Source_Reference then
29472 return Argn = 2;
29473
29474 elsif Pname = Name_Title then
29475 return True;
29476
29477 elsif Pname = Name_Subtitle then
29478 return True;
29479
29480 else
29481 return False;
29482 end if;
29483 end Is_Pragma_String_Literal;
29484
29485 ---------------------------
29486 -- Is_Private_SPARK_Mode --
29487 ---------------------------
29488
29489 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
29490 begin
29491 pragma Assert
29492 (Nkind (N) = N_Pragma
29493 and then Pragma_Name (N) = Name_SPARK_Mode
29494 and then Is_List_Member (N));
29495
29496 -- For pragma SPARK_Mode to be private, it has to appear in the private
29497 -- declarations of a package.
29498
29499 return
29500 Present (Parent (N))
29501 and then Nkind (Parent (N)) = N_Package_Specification
29502 and then List_Containing (N) = Private_Declarations (Parent (N));
29503 end Is_Private_SPARK_Mode;
29504
29505 -------------------------------------
29506 -- Is_Unconstrained_Or_Tagged_Item --
29507 -------------------------------------
29508
29509 function Is_Unconstrained_Or_Tagged_Item
29510 (Item : Entity_Id) return Boolean
29511 is
29512 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
29513 -- Determine whether record type Typ has at least one unconstrained
29514 -- component.
29515
29516 ---------------------------------
29517 -- Has_Unconstrained_Component --
29518 ---------------------------------
29519
29520 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
29521 Comp : Entity_Id;
29522
29523 begin
29524 Comp := First_Component (Typ);
29525 while Present (Comp) loop
29526 if Is_Unconstrained_Or_Tagged_Item (Comp) then
29527 return True;
29528 end if;
29529
29530 Next_Component (Comp);
29531 end loop;
29532
29533 return False;
29534 end Has_Unconstrained_Component;
29535
29536 -- Local variables
29537
29538 Typ : constant Entity_Id := Etype (Item);
29539
29540 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
29541
29542 begin
29543 if Is_Tagged_Type (Typ) then
29544 return True;
29545
29546 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
29547 return True;
29548
29549 elsif Is_Record_Type (Typ) then
29550 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
29551 return True;
29552 else
29553 return Has_Unconstrained_Component (Typ);
29554 end if;
29555
29556 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
29557 return True;
29558
29559 else
29560 return False;
29561 end if;
29562 end Is_Unconstrained_Or_Tagged_Item;
29563
29564 -----------------------------
29565 -- Is_Valid_Assertion_Kind --
29566 -----------------------------
29567
29568 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
29569 begin
29570 case Nam is
29571 when
29572 -- RM defined
29573
29574 Name_Assert
29575 | Name_Assertion_Policy
29576 | Name_Static_Predicate
29577 | Name_Dynamic_Predicate
29578 | Name_Pre
29579 | Name_uPre
29580 | Name_Post
29581 | Name_uPost
29582 | Name_Type_Invariant
29583 | Name_uType_Invariant
29584
29585 -- Impl defined
29586
29587 | Name_Assert_And_Cut
29588 | Name_Assume
29589 | Name_Contract_Cases
29590 | Name_Debug
29591 | Name_Default_Initial_Condition
29592 | Name_Ghost
29593 | Name_Initial_Condition
29594 | Name_Invariant
29595 | Name_uInvariant
29596 | Name_Loop_Invariant
29597 | Name_Loop_Variant
29598 | Name_Postcondition
29599 | Name_Precondition
29600 | Name_Predicate
29601 | Name_Refined_Post
29602 | Name_Statement_Assertions
29603 =>
29604 return True;
29605
29606 when others =>
29607 return False;
29608 end case;
29609 end Is_Valid_Assertion_Kind;
29610
29611 --------------------------------------
29612 -- Process_Compilation_Unit_Pragmas --
29613 --------------------------------------
29614
29615 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
29616 begin
29617 -- A special check for pragma Suppress_All, a very strange DEC pragma,
29618 -- strange because it comes at the end of the unit. Rational has the
29619 -- same name for a pragma, but treats it as a program unit pragma, In
29620 -- GNAT we just decide to allow it anywhere at all. If it appeared then
29621 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
29622 -- node, and we insert a pragma Suppress (All_Checks) at the start of
29623 -- the context clause to ensure the correct processing.
29624
29625 if Has_Pragma_Suppress_All (N) then
29626 Prepend_To (Context_Items (N),
29627 Make_Pragma (Sloc (N),
29628 Chars => Name_Suppress,
29629 Pragma_Argument_Associations => New_List (
29630 Make_Pragma_Argument_Association (Sloc (N),
29631 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
29632 end if;
29633
29634 -- Nothing else to do at the current time
29635
29636 end Process_Compilation_Unit_Pragmas;
29637
29638 -------------------------------------------
29639 -- Process_Compile_Time_Warning_Or_Error --
29640 -------------------------------------------
29641
29642 procedure Process_Compile_Time_Warning_Or_Error
29643 (N : Node_Id;
29644 Eloc : Source_Ptr)
29645 is
29646 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
29647 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
29648 Arg2 : constant Node_Id := Next (Arg1);
29649
29650 begin
29651 Analyze_And_Resolve (Arg1x, Standard_Boolean);
29652
29653 if Compile_Time_Known_Value (Arg1x) then
29654 if Is_True (Expr_Value (Arg1x)) then
29655 declare
29656 Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
29657 Pname : constant Name_Id := Pragma_Name_Unmapped (N);
29658 Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
29659 Str : constant String_Id := Strval (Get_Pragma_Arg (Arg2));
29660 Str_Len : constant Nat := String_Length (Str);
29661
29662 Force : constant Boolean :=
29663 Prag_Id = Pragma_Compile_Time_Warning
29664 and then Is_Spec_Name (Unit_Name (Current_Sem_Unit))
29665 and then (Ekind (Cent) /= E_Package
29666 or else not In_Private_Part (Cent));
29667 -- Set True if this is the warning case, and we are in the
29668 -- visible part of a package spec, or in a subprogram spec,
29669 -- in which case we want to force the client to see the
29670 -- warning, even though it is not in the main unit.
29671
29672 C : Character;
29673 CC : Char_Code;
29674 Cont : Boolean;
29675 Ptr : Nat;
29676
29677 begin
29678 -- Loop through segments of message separated by line feeds.
29679 -- We output these segments as separate messages with
29680 -- continuation marks for all but the first.
29681
29682 Cont := False;
29683 Ptr := 1;
29684 loop
29685 Error_Msg_Strlen := 0;
29686
29687 -- Loop to copy characters from argument to error message
29688 -- string buffer.
29689
29690 loop
29691 exit when Ptr > Str_Len;
29692 CC := Get_String_Char (Str, Ptr);
29693 Ptr := Ptr + 1;
29694
29695 -- Ignore wide chars ??? else store character
29696
29697 if In_Character_Range (CC) then
29698 C := Get_Character (CC);
29699 exit when C = ASCII.LF;
29700 Error_Msg_Strlen := Error_Msg_Strlen + 1;
29701 Error_Msg_String (Error_Msg_Strlen) := C;
29702 end if;
29703 end loop;
29704
29705 -- Here with one line ready to go
29706
29707 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
29708
29709 -- If this is a warning in a spec, then we want clients
29710 -- to see the warning, so mark the message with the
29711 -- special sequence !! to force the warning. In the case
29712 -- of a package spec, we do not force this if we are in
29713 -- the private part of the spec.
29714
29715 if Force then
29716 if Cont = False then
29717 Error_Msg ("<<~!!", Eloc);
29718 Cont := True;
29719 else
29720 Error_Msg ("\<<~!!", Eloc);
29721 end if;
29722
29723 -- Error, rather than warning, or in a body, so we do not
29724 -- need to force visibility for client (error will be
29725 -- output in any case, and this is the situation in which
29726 -- we do not want a client to get a warning, since the
29727 -- warning is in the body or the spec private part).
29728
29729 else
29730 if Cont = False then
29731 Error_Msg ("<<~", Eloc);
29732 Cont := True;
29733 else
29734 Error_Msg ("\<<~", Eloc);
29735 end if;
29736 end if;
29737
29738 exit when Ptr > Str_Len;
29739 end loop;
29740 end;
29741 end if;
29742 end if;
29743 end Process_Compile_Time_Warning_Or_Error;
29744
29745 ------------------------------------
29746 -- Record_Possible_Body_Reference --
29747 ------------------------------------
29748
29749 procedure Record_Possible_Body_Reference
29750 (State_Id : Entity_Id;
29751 Ref : Node_Id)
29752 is
29753 Context : Node_Id;
29754 Spec_Id : Entity_Id;
29755
29756 begin
29757 -- Ensure that we are dealing with a reference to a state
29758
29759 pragma Assert (Ekind (State_Id) = E_Abstract_State);
29760
29761 -- Climb the tree starting from the reference looking for a package body
29762 -- whose spec declares the referenced state. This criteria automatically
29763 -- excludes references in package specs which are legal. Note that it is
29764 -- not wise to emit an error now as the package body may lack pragma
29765 -- Refined_State or the referenced state may not be mentioned in the
29766 -- refinement. This approach avoids the generation of misleading errors.
29767
29768 Context := Ref;
29769 while Present (Context) loop
29770 if Nkind (Context) = N_Package_Body then
29771 Spec_Id := Corresponding_Spec (Context);
29772
29773 if Present (Abstract_States (Spec_Id))
29774 and then Contains (Abstract_States (Spec_Id), State_Id)
29775 then
29776 if No (Body_References (State_Id)) then
29777 Set_Body_References (State_Id, New_Elmt_List);
29778 end if;
29779
29780 Append_Elmt (Ref, To => Body_References (State_Id));
29781 exit;
29782 end if;
29783 end if;
29784
29785 Context := Parent (Context);
29786 end loop;
29787 end Record_Possible_Body_Reference;
29788
29789 ------------------------------------------
29790 -- Relocate_Pragmas_To_Anonymous_Object --
29791 ------------------------------------------
29792
29793 procedure Relocate_Pragmas_To_Anonymous_Object
29794 (Typ_Decl : Node_Id;
29795 Obj_Decl : Node_Id)
29796 is
29797 Decl : Node_Id;
29798 Def : Node_Id;
29799 Next_Decl : Node_Id;
29800
29801 begin
29802 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
29803 Def := Protected_Definition (Typ_Decl);
29804 else
29805 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
29806 Def := Task_Definition (Typ_Decl);
29807 end if;
29808
29809 -- The concurrent definition has a visible declaration list. Inspect it
29810 -- and relocate all canidate pragmas.
29811
29812 if Present (Def) and then Present (Visible_Declarations (Def)) then
29813 Decl := First (Visible_Declarations (Def));
29814 while Present (Decl) loop
29815
29816 -- Preserve the following declaration for iteration purposes due
29817 -- to possible relocation of a pragma.
29818
29819 Next_Decl := Next (Decl);
29820
29821 if Nkind (Decl) = N_Pragma
29822 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
29823 then
29824 Remove (Decl);
29825 Insert_After (Obj_Decl, Decl);
29826
29827 -- Skip internally generated code
29828
29829 elsif not Comes_From_Source (Decl) then
29830 null;
29831
29832 -- No candidate pragmas are available for relocation
29833
29834 else
29835 exit;
29836 end if;
29837
29838 Decl := Next_Decl;
29839 end loop;
29840 end if;
29841 end Relocate_Pragmas_To_Anonymous_Object;
29842
29843 ------------------------------
29844 -- Relocate_Pragmas_To_Body --
29845 ------------------------------
29846
29847 procedure Relocate_Pragmas_To_Body
29848 (Subp_Body : Node_Id;
29849 Target_Body : Node_Id := Empty)
29850 is
29851 procedure Relocate_Pragma (Prag : Node_Id);
29852 -- Remove a single pragma from its current list and add it to the
29853 -- declarations of the proper body (either Subp_Body or Target_Body).
29854
29855 ---------------------
29856 -- Relocate_Pragma --
29857 ---------------------
29858
29859 procedure Relocate_Pragma (Prag : Node_Id) is
29860 Decls : List_Id;
29861 Target : Node_Id;
29862
29863 begin
29864 -- When subprogram stubs or expression functions are involves, the
29865 -- destination declaration list belongs to the proper body.
29866
29867 if Present (Target_Body) then
29868 Target := Target_Body;
29869 else
29870 Target := Subp_Body;
29871 end if;
29872
29873 Decls := Declarations (Target);
29874
29875 if No (Decls) then
29876 Decls := New_List;
29877 Set_Declarations (Target, Decls);
29878 end if;
29879
29880 -- Unhook the pragma from its current list
29881
29882 Remove (Prag);
29883 Prepend (Prag, Decls);
29884 end Relocate_Pragma;
29885
29886 -- Local variables
29887
29888 Body_Id : constant Entity_Id :=
29889 Defining_Unit_Name (Specification (Subp_Body));
29890 Next_Stmt : Node_Id;
29891 Stmt : Node_Id;
29892
29893 -- Start of processing for Relocate_Pragmas_To_Body
29894
29895 begin
29896 -- Do not process a body that comes from a separate unit as no construct
29897 -- can possibly follow it.
29898
29899 if not Is_List_Member (Subp_Body) then
29900 return;
29901
29902 -- Do not relocate pragmas that follow a stub if the stub does not have
29903 -- a proper body.
29904
29905 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
29906 and then No (Target_Body)
29907 then
29908 return;
29909
29910 -- Do not process internally generated routine _Postconditions
29911
29912 elsif Ekind (Body_Id) = E_Procedure
29913 and then Chars (Body_Id) = Name_uPostconditions
29914 then
29915 return;
29916 end if;
29917
29918 -- Look at what is following the body. We are interested in certain kind
29919 -- of pragmas (either from source or byproducts of expansion) that can
29920 -- apply to a body [stub].
29921
29922 Stmt := Next (Subp_Body);
29923 while Present (Stmt) loop
29924
29925 -- Preserve the following statement for iteration purposes due to a
29926 -- possible relocation of a pragma.
29927
29928 Next_Stmt := Next (Stmt);
29929
29930 -- Move a candidate pragma following the body to the declarations of
29931 -- the body.
29932
29933 if Nkind (Stmt) = N_Pragma
29934 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
29935 then
29936 Relocate_Pragma (Stmt);
29937
29938 -- Skip internally generated code
29939
29940 elsif not Comes_From_Source (Stmt) then
29941 null;
29942
29943 -- No candidate pragmas are available for relocation
29944
29945 else
29946 exit;
29947 end if;
29948
29949 Stmt := Next_Stmt;
29950 end loop;
29951 end Relocate_Pragmas_To_Body;
29952
29953 -------------------
29954 -- Resolve_State --
29955 -------------------
29956
29957 procedure Resolve_State (N : Node_Id) is
29958 Func : Entity_Id;
29959 State : Entity_Id;
29960
29961 begin
29962 if Is_Entity_Name (N) and then Present (Entity (N)) then
29963 Func := Entity (N);
29964
29965 -- Handle overloading of state names by functions. Traverse the
29966 -- homonym chain looking for an abstract state.
29967
29968 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
29969 State := Homonym (Func);
29970 while Present (State) loop
29971
29972 -- Resolve the overloading by setting the proper entity of the
29973 -- reference to that of the state.
29974
29975 if Ekind (State) = E_Abstract_State then
29976 Set_Etype (N, Standard_Void_Type);
29977 Set_Entity (N, State);
29978 Set_Associated_Node (N, State);
29979 return;
29980 end if;
29981
29982 State := Homonym (State);
29983 end loop;
29984
29985 -- A function can never act as a state. If the homonym chain does
29986 -- not contain a corresponding state, then something went wrong in
29987 -- the overloading mechanism.
29988
29989 raise Program_Error;
29990 end if;
29991 end if;
29992 end Resolve_State;
29993
29994 ----------------------------
29995 -- Rewrite_Assertion_Kind --
29996 ----------------------------
29997
29998 procedure Rewrite_Assertion_Kind
29999 (N : Node_Id;
30000 From_Policy : Boolean := False)
30001 is
30002 Nam : Name_Id;
30003
30004 begin
30005 Nam := No_Name;
30006 if Nkind (N) = N_Attribute_Reference
30007 and then Attribute_Name (N) = Name_Class
30008 and then Nkind (Prefix (N)) = N_Identifier
30009 then
30010 case Chars (Prefix (N)) is
30011 when Name_Pre =>
30012 Nam := Name_uPre;
30013
30014 when Name_Post =>
30015 Nam := Name_uPost;
30016
30017 when Name_Type_Invariant =>
30018 Nam := Name_uType_Invariant;
30019
30020 when Name_Invariant =>
30021 Nam := Name_uInvariant;
30022
30023 when others =>
30024 return;
30025 end case;
30026
30027 -- Recommend standard use of aspect names Pre/Post
30028
30029 elsif Nkind (N) = N_Identifier
30030 and then From_Policy
30031 and then Serious_Errors_Detected = 0
30032 and then not ASIS_Mode
30033 then
30034 if Chars (N) = Name_Precondition
30035 or else Chars (N) = Name_Postcondition
30036 then
30037 Error_Msg_N ("Check_Policy is a non-standard pragma??", N);
30038 Error_Msg_N
30039 ("\use Assertion_Policy and aspect names Pre/Post for "
30040 & "Ada2012 conformance?", N);
30041 end if;
30042
30043 return;
30044 end if;
30045
30046 if Nam /= No_Name then
30047 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
30048 end if;
30049 end Rewrite_Assertion_Kind;
30050
30051 --------
30052 -- rv --
30053 --------
30054
30055 procedure rv is
30056 begin
30057 Dummy := Dummy + 1;
30058 end rv;
30059
30060 --------------------------------
30061 -- Set_Encoded_Interface_Name --
30062 --------------------------------
30063
30064 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
30065 Str : constant String_Id := Strval (S);
30066 Len : constant Nat := String_Length (Str);
30067 CC : Char_Code;
30068 C : Character;
30069 J : Pos;
30070
30071 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
30072
30073 procedure Encode;
30074 -- Stores encoded value of character code CC. The encoding we use an
30075 -- underscore followed by four lower case hex digits.
30076
30077 ------------
30078 -- Encode --
30079 ------------
30080
30081 procedure Encode is
30082 begin
30083 Store_String_Char (Get_Char_Code ('_'));
30084 Store_String_Char
30085 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
30086 Store_String_Char
30087 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
30088 Store_String_Char
30089 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
30090 Store_String_Char
30091 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
30092 end Encode;
30093
30094 -- Start of processing for Set_Encoded_Interface_Name
30095
30096 begin
30097 -- If first character is asterisk, this is a link name, and we leave it
30098 -- completely unmodified. We also ignore null strings (the latter case
30099 -- happens only in error cases).
30100
30101 if Len = 0
30102 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
30103 then
30104 Set_Interface_Name (E, S);
30105
30106 else
30107 J := 1;
30108 loop
30109 CC := Get_String_Char (Str, J);
30110
30111 exit when not In_Character_Range (CC);
30112
30113 C := Get_Character (CC);
30114
30115 exit when C /= '_' and then C /= '$'
30116 and then C not in '0' .. '9'
30117 and then C not in 'a' .. 'z'
30118 and then C not in 'A' .. 'Z';
30119
30120 if J = Len then
30121 Set_Interface_Name (E, S);
30122 return;
30123
30124 else
30125 J := J + 1;
30126 end if;
30127 end loop;
30128
30129 -- Here we need to encode. The encoding we use as follows:
30130 -- three underscores + four hex digits (lower case)
30131
30132 Start_String;
30133
30134 for J in 1 .. String_Length (Str) loop
30135 CC := Get_String_Char (Str, J);
30136
30137 if not In_Character_Range (CC) then
30138 Encode;
30139 else
30140 C := Get_Character (CC);
30141
30142 if C = '_' or else C = '$'
30143 or else C in '0' .. '9'
30144 or else C in 'a' .. 'z'
30145 or else C in 'A' .. 'Z'
30146 then
30147 Store_String_Char (CC);
30148 else
30149 Encode;
30150 end if;
30151 end if;
30152 end loop;
30153
30154 Set_Interface_Name (E,
30155 Make_String_Literal (Sloc (S),
30156 Strval => End_String));
30157 end if;
30158 end Set_Encoded_Interface_Name;
30159
30160 ------------------------
30161 -- Set_Elab_Unit_Name --
30162 ------------------------
30163
30164 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
30165 Pref : Node_Id;
30166 Scop : Entity_Id;
30167
30168 begin
30169 if Nkind (N) = N_Identifier
30170 and then Nkind (With_Item) = N_Identifier
30171 then
30172 Set_Entity (N, Entity (With_Item));
30173
30174 elsif Nkind (N) = N_Selected_Component then
30175 Change_Selected_Component_To_Expanded_Name (N);
30176 Set_Entity (N, Entity (With_Item));
30177 Set_Entity (Selector_Name (N), Entity (N));
30178
30179 Pref := Prefix (N);
30180 Scop := Scope (Entity (N));
30181 while Nkind (Pref) = N_Selected_Component loop
30182 Change_Selected_Component_To_Expanded_Name (Pref);
30183 Set_Entity (Selector_Name (Pref), Scop);
30184 Set_Entity (Pref, Scop);
30185 Pref := Prefix (Pref);
30186 Scop := Scope (Scop);
30187 end loop;
30188
30189 Set_Entity (Pref, Scop);
30190 end if;
30191
30192 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
30193 end Set_Elab_Unit_Name;
30194
30195 -------------------
30196 -- Test_Case_Arg --
30197 -------------------
30198
30199 function Test_Case_Arg
30200 (Prag : Node_Id;
30201 Arg_Nam : Name_Id;
30202 From_Aspect : Boolean := False) return Node_Id
30203 is
30204 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
30205 Arg : Node_Id;
30206 Args : Node_Id;
30207
30208 begin
30209 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
30210 Name_Mode,
30211 Name_Name,
30212 Name_Requires));
30213
30214 -- The caller requests the aspect argument
30215
30216 if From_Aspect then
30217 if Present (Aspect)
30218 and then Nkind (Expression (Aspect)) = N_Aggregate
30219 then
30220 Args := Expression (Aspect);
30221
30222 -- "Name" and "Mode" may appear without an identifier as a
30223 -- positional association.
30224
30225 if Present (Expressions (Args)) then
30226 Arg := First (Expressions (Args));
30227
30228 if Present (Arg) and then Arg_Nam = Name_Name then
30229 return Arg;
30230 end if;
30231
30232 -- Skip "Name"
30233
30234 Arg := Next (Arg);
30235
30236 if Present (Arg) and then Arg_Nam = Name_Mode then
30237 return Arg;
30238 end if;
30239 end if;
30240
30241 -- Some or all arguments may appear as component associatons
30242
30243 if Present (Component_Associations (Args)) then
30244 Arg := First (Component_Associations (Args));
30245 while Present (Arg) loop
30246 if Chars (First (Choices (Arg))) = Arg_Nam then
30247 return Arg;
30248 end if;
30249
30250 Next (Arg);
30251 end loop;
30252 end if;
30253 end if;
30254
30255 -- Otherwise retrieve the argument directly from the pragma
30256
30257 else
30258 Arg := First (Pragma_Argument_Associations (Prag));
30259
30260 if Present (Arg) and then Arg_Nam = Name_Name then
30261 return Arg;
30262 end if;
30263
30264 -- Skip argument "Name"
30265
30266 Arg := Next (Arg);
30267
30268 if Present (Arg) and then Arg_Nam = Name_Mode then
30269 return Arg;
30270 end if;
30271
30272 -- Skip argument "Mode"
30273
30274 Arg := Next (Arg);
30275
30276 -- Arguments "Requires" and "Ensures" are optional and may not be
30277 -- present at all.
30278
30279 while Present (Arg) loop
30280 if Chars (Arg) = Arg_Nam then
30281 return Arg;
30282 end if;
30283
30284 Next (Arg);
30285 end loop;
30286 end if;
30287
30288 return Empty;
30289 end Test_Case_Arg;
30290
30291 end Sem_Prag;