]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/sem_prag.adb
[multiple changes]
[thirdparty/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-2016, 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_Ch7; use Exp_Ch7;
43 with Exp_Dist; use Exp_Dist;
44 with Exp_Util; use Exp_Util;
45 with Freeze; use Freeze;
46 with Ghost; use Ghost;
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_Related_Context
225 (Prag : Node_Id;
226 Do_Checks : Boolean := False) return Node_Id;
227 -- Subsidiaty to the analysis of pragmas Async_Readers, Async_Writers,
228 -- Constant_After_Elaboration, Effective_Reads, Effective_Writers and
229 -- Part_Of. Find the first source declaration or statement found while
230 -- traversing the previous node chain starting from pragma Prag. If flag
231 -- Do_Checks is set, the routine reports duplicate pragmas. The routine
232 -- returns Empty when reaching the start of the node chain.
233
234 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
235 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
236 -- original one, following the renaming chain) is returned. Otherwise the
237 -- entity is returned unchanged. Should be in Einfo???
238
239 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
240 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
241 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
242 -- value of type SPARK_Mode_Type.
243
244 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
245 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
246 -- Determine whether dependency clause Clause is surrounded by extra
247 -- parentheses. If this is the case, issue an error message.
248
249 function Is_CCT_Instance
250 (Ref_Id : Entity_Id;
251 Context_Id : Entity_Id) return Boolean;
252 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
253 -- Global. Determine whether entity Ref_Id denotes the current instance of
254 -- a concurrent type. Context_Id denotes the associated context where the
255 -- pragma appears.
256
257 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
258 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
259 -- pragma Depends. Determine whether the type of dependency item Item is
260 -- tagged, unconstrained array, unconstrained record or a record with at
261 -- least one unconstrained component.
262
263 procedure Record_Possible_Body_Reference
264 (State_Id : Entity_Id;
265 Ref : Node_Id);
266 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
267 -- Global. Given an abstract state denoted by State_Id and a reference Ref
268 -- to it, determine whether the reference appears in a package body that
269 -- will eventually refine the state. If this is the case, record the
270 -- reference for future checks (see Analyze_Refined_State_In_Decls).
271
272 procedure Resolve_State (N : Node_Id);
273 -- Handle the overloading of state names by functions. When N denotes a
274 -- function, this routine finds the corresponding state and sets the entity
275 -- of N to that of the state.
276
277 procedure Rewrite_Assertion_Kind (N : Node_Id);
278 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
279 -- then it is rewritten as an identifier with the corresponding special
280 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
281 -- and Check_Policy.
282
283 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id);
284 -- Place semantic information on the argument of an Elaborate/Elaborate_All
285 -- pragma. Entity name for unit and its parents is taken from item in
286 -- previous with_clause that mentions the unit.
287
288 Dummy : Integer := 0;
289 pragma Volatile (Dummy);
290 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
291
292 procedure ip;
293 pragma No_Inline (ip);
294 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
295 -- is just to help debugging the front end. If a pragma Inspection_Point
296 -- is added to a source program, then breaking on ip will get you to that
297 -- point in the program.
298
299 procedure rv;
300 pragma No_Inline (rv);
301 -- This is a dummy function called by the processing for pragma Reviewable.
302 -- It is there for assisting front end debugging. By placing a Reviewable
303 -- pragma in the source program, a breakpoint on rv catches this place in
304 -- the source, allowing convenient stepping to the point of interest.
305
306 -------------------------------
307 -- Adjust_External_Name_Case --
308 -------------------------------
309
310 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
311 CC : Char_Code;
312
313 begin
314 -- Adjust case of literal if required
315
316 if Opt.External_Name_Exp_Casing = As_Is then
317 return N;
318
319 else
320 -- Copy existing string
321
322 Start_String;
323
324 -- Set proper casing
325
326 for J in 1 .. String_Length (Strval (N)) loop
327 CC := Get_String_Char (Strval (N), J);
328
329 if Opt.External_Name_Exp_Casing = Uppercase
330 and then CC >= Get_Char_Code ('a')
331 and then CC <= Get_Char_Code ('z')
332 then
333 Store_String_Char (CC - 32);
334
335 elsif Opt.External_Name_Exp_Casing = Lowercase
336 and then CC >= Get_Char_Code ('A')
337 and then CC <= Get_Char_Code ('Z')
338 then
339 Store_String_Char (CC + 32);
340
341 else
342 Store_String_Char (CC);
343 end if;
344 end loop;
345
346 return
347 Make_String_Literal (Sloc (N),
348 Strval => End_String);
349 end if;
350 end Adjust_External_Name_Case;
351
352 -----------------------------------------
353 -- Analyze_Contract_Cases_In_Decl_Part --
354 -----------------------------------------
355
356 procedure Analyze_Contract_Cases_In_Decl_Part
357 (N : Node_Id;
358 Freeze_Id : Entity_Id := Empty)
359 is
360 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
361 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
362
363 Others_Seen : Boolean := False;
364 -- This flag is set when an "others" choice is encountered. It is used
365 -- to detect multiple illegal occurrences of "others".
366
367 procedure Analyze_Contract_Case (CCase : Node_Id);
368 -- Verify the legality of a single contract case
369
370 ---------------------------
371 -- Analyze_Contract_Case --
372 ---------------------------
373
374 procedure Analyze_Contract_Case (CCase : Node_Id) is
375 Case_Guard : Node_Id;
376 Conseq : Node_Id;
377 Errors : Nat;
378 Extra_Guard : Node_Id;
379
380 begin
381 if Nkind (CCase) = N_Component_Association then
382 Case_Guard := First (Choices (CCase));
383 Conseq := Expression (CCase);
384
385 -- Each contract case must have exactly one case guard
386
387 Extra_Guard := Next (Case_Guard);
388
389 if Present (Extra_Guard) then
390 Error_Msg_N
391 ("contract case must have exactly one case guard",
392 Extra_Guard);
393 end if;
394
395 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
396
397 if Nkind (Case_Guard) = N_Others_Choice then
398 if Others_Seen then
399 Error_Msg_N
400 ("only one others choice allowed in contract cases",
401 Case_Guard);
402 else
403 Others_Seen := True;
404 end if;
405
406 elsif Others_Seen then
407 Error_Msg_N
408 ("others must be the last choice in contract cases", N);
409 end if;
410
411 -- Preanalyze the case guard and consequence
412
413 if Nkind (Case_Guard) /= N_Others_Choice then
414 Errors := Serious_Errors_Detected;
415 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
416
417 -- Emit a clarification message when the case guard contains
418 -- at least one undefined reference, possibly due to contract
419 -- "freezing".
420
421 if Errors /= Serious_Errors_Detected
422 and then Present (Freeze_Id)
423 and then Has_Undefined_Reference (Case_Guard)
424 then
425 Contract_Freeze_Error (Spec_Id, Freeze_Id);
426 end if;
427 end if;
428
429 Errors := Serious_Errors_Detected;
430 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
431
432 -- Emit a clarification message when the consequence contains
433 -- at least one undefined reference, possibly due to contract
434 -- "freezing".
435
436 if Errors /= Serious_Errors_Detected
437 and then Present (Freeze_Id)
438 and then Has_Undefined_Reference (Conseq)
439 then
440 Contract_Freeze_Error (Spec_Id, Freeze_Id);
441 end if;
442
443 -- The contract case is malformed
444
445 else
446 Error_Msg_N ("wrong syntax in contract case", CCase);
447 end if;
448 end Analyze_Contract_Case;
449
450 -- Local variables
451
452 CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
453
454 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
455
456 CCase : Node_Id;
457 Restore_Scope : Boolean := False;
458
459 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
460
461 begin
462 -- Do not analyze the pragma multiple times
463
464 if Is_Analyzed_Pragma (N) then
465 return;
466 end if;
467
468 -- Set the Ghost mode in effect from the pragma. Due to the delayed
469 -- analysis of the pragma, the Ghost mode at point of declaration and
470 -- point of analysis may not necessarily be the same. Use the mode in
471 -- effect at the point of declaration.
472
473 Set_Ghost_Mode (N);
474
475 -- Single and multiple contract cases must appear in aggregate form. If
476 -- this is not the case, then either the parser of the analysis of the
477 -- pragma failed to produce an aggregate.
478
479 pragma Assert (Nkind (CCases) = N_Aggregate);
480
481 if Present (Component_Associations (CCases)) then
482
483 -- Ensure that the formal parameters are visible when analyzing all
484 -- clauses. This falls out of the general rule of aspects pertaining
485 -- to subprogram declarations.
486
487 if not In_Open_Scopes (Spec_Id) then
488 Restore_Scope := True;
489 Push_Scope (Spec_Id);
490
491 if Is_Generic_Subprogram (Spec_Id) then
492 Install_Generic_Formals (Spec_Id);
493 else
494 Install_Formals (Spec_Id);
495 end if;
496 end if;
497
498 CCase := First (Component_Associations (CCases));
499 while Present (CCase) loop
500 Analyze_Contract_Case (CCase);
501 Next (CCase);
502 end loop;
503
504 if Restore_Scope then
505 End_Scope;
506 end if;
507
508 -- Currently it is not possible to inline pre/postconditions on a
509 -- subprogram subject to pragma Inline_Always.
510
511 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
512
513 -- Otherwise the pragma is illegal
514
515 else
516 Error_Msg_N ("wrong syntax for constract cases", N);
517 end if;
518
519 Ghost_Mode := Save_Ghost_Mode;
520 Set_Is_Analyzed_Pragma (N);
521 end Analyze_Contract_Cases_In_Decl_Part;
522
523 ----------------------------------
524 -- Analyze_Depends_In_Decl_Part --
525 ----------------------------------
526
527 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
528 Loc : constant Source_Ptr := Sloc (N);
529 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
530 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
531
532 All_Inputs_Seen : Elist_Id := No_Elist;
533 -- A list containing the entities of all the inputs processed so far.
534 -- The list is populated with unique entities because the same input
535 -- may appear in multiple input lists.
536
537 All_Outputs_Seen : Elist_Id := No_Elist;
538 -- A list containing the entities of all the outputs processed so far.
539 -- The list is populated with unique entities because output items are
540 -- unique in a dependence relation.
541
542 Constits_Seen : Elist_Id := No_Elist;
543 -- A list containing the entities of all constituents processed so far.
544 -- It aids in detecting illegal usage of a state and a corresponding
545 -- constituent in pragma [Refinde_]Depends.
546
547 Global_Seen : Boolean := False;
548 -- A flag set when pragma Global has been processed
549
550 Null_Output_Seen : Boolean := False;
551 -- A flag used to track the legality of a null output
552
553 Result_Seen : Boolean := False;
554 -- A flag set when Spec_Id'Result is processed
555
556 States_Seen : Elist_Id := No_Elist;
557 -- A list containing the entities of all states processed so far. It
558 -- helps in detecting illegal usage of a state and a corresponding
559 -- constituent in pragma [Refined_]Depends.
560
561 Subp_Inputs : Elist_Id := No_Elist;
562 Subp_Outputs : Elist_Id := No_Elist;
563 -- Two lists containing the full set of inputs and output of the related
564 -- subprograms. Note that these lists contain both nodes and entities.
565
566 Task_Input_Seen : Boolean := False;
567 Task_Output_Seen : Boolean := False;
568 -- Flags used to track the implicit dependence of a task unit on itself
569
570 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
571 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
572 -- to the name buffer. The individual kinds are as follows:
573 -- E_Abstract_State - "state"
574 -- E_Constant - "constant"
575 -- E_Discriminant - "discriminant"
576 -- E_Generic_In_Out_Parameter - "generic parameter"
577 -- E_Generic_In_Parameter - "generic parameter"
578 -- E_In_Parameter - "parameter"
579 -- E_In_Out_Parameter - "parameter"
580 -- E_Loop_Parameter - "loop parameter"
581 -- E_Out_Parameter - "parameter"
582 -- E_Protected_Type - "current instance of protected type"
583 -- E_Task_Type - "current instance of task type"
584 -- E_Variable - "global"
585
586 procedure Analyze_Dependency_Clause
587 (Clause : Node_Id;
588 Is_Last : Boolean);
589 -- Verify the legality of a single dependency clause. Flag Is_Last
590 -- denotes whether Clause is the last clause in the relation.
591
592 procedure Check_Function_Return;
593 -- Verify that Funtion'Result appears as one of the outputs
594 -- (SPARK RM 6.1.5(10)).
595
596 procedure Check_Role
597 (Item : Node_Id;
598 Item_Id : Entity_Id;
599 Is_Input : Boolean;
600 Self_Ref : Boolean);
601 -- Ensure that an item fulfills its designated input and/or output role
602 -- as specified by pragma Global (if any) or the enclosing context. If
603 -- this is not the case, emit an error. Item and Item_Id denote the
604 -- attributes of an item. Flag Is_Input should be set when item comes
605 -- from an input list. Flag Self_Ref should be set when the item is an
606 -- output and the dependency clause has operator "+".
607
608 procedure Check_Usage
609 (Subp_Items : Elist_Id;
610 Used_Items : Elist_Id;
611 Is_Input : Boolean);
612 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
613 -- error if this is not the case.
614
615 procedure Normalize_Clause (Clause : Node_Id);
616 -- Remove a self-dependency "+" from the input list of a clause
617
618 -----------------------------
619 -- Add_Item_To_Name_Buffer --
620 -----------------------------
621
622 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
623 begin
624 if Ekind (Item_Id) = E_Abstract_State then
625 Add_Str_To_Name_Buffer ("state");
626
627 elsif Ekind (Item_Id) = E_Constant then
628 Add_Str_To_Name_Buffer ("constant");
629
630 elsif Ekind (Item_Id) = E_Discriminant then
631 Add_Str_To_Name_Buffer ("discriminant");
632
633 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
634 E_Generic_In_Parameter)
635 then
636 Add_Str_To_Name_Buffer ("generic parameter");
637
638 elsif Is_Formal (Item_Id) then
639 Add_Str_To_Name_Buffer ("parameter");
640
641 elsif Ekind (Item_Id) = E_Loop_Parameter then
642 Add_Str_To_Name_Buffer ("loop parameter");
643
644 elsif Ekind (Item_Id) = E_Protected_Type
645 or else Is_Single_Protected_Object (Item_Id)
646 then
647 Add_Str_To_Name_Buffer ("current instance of protected type");
648
649 elsif Ekind (Item_Id) = E_Task_Type
650 or else Is_Single_Task_Object (Item_Id)
651 then
652 Add_Str_To_Name_Buffer ("current instance of task type");
653
654 elsif Ekind (Item_Id) = E_Variable then
655 Add_Str_To_Name_Buffer ("global");
656
657 -- The routine should not be called with non-SPARK items
658
659 else
660 raise Program_Error;
661 end if;
662 end Add_Item_To_Name_Buffer;
663
664 -------------------------------
665 -- Analyze_Dependency_Clause --
666 -------------------------------
667
668 procedure Analyze_Dependency_Clause
669 (Clause : Node_Id;
670 Is_Last : Boolean)
671 is
672 procedure Analyze_Input_List (Inputs : Node_Id);
673 -- Verify the legality of a single input list
674
675 procedure Analyze_Input_Output
676 (Item : Node_Id;
677 Is_Input : Boolean;
678 Self_Ref : Boolean;
679 Top_Level : Boolean;
680 Seen : in out Elist_Id;
681 Null_Seen : in out Boolean;
682 Non_Null_Seen : in out Boolean);
683 -- Verify the legality of a single input or output item. Flag
684 -- Is_Input should be set whenever Item is an input, False when it
685 -- denotes an output. Flag Self_Ref should be set when the item is an
686 -- output and the dependency clause has a "+". Flag Top_Level should
687 -- be set whenever Item appears immediately within an input or output
688 -- list. Seen is a collection of all abstract states, objects and
689 -- formals processed so far. Flag Null_Seen denotes whether a null
690 -- input or output has been encountered. Flag Non_Null_Seen denotes
691 -- whether a non-null input or output has been encountered.
692
693 ------------------------
694 -- Analyze_Input_List --
695 ------------------------
696
697 procedure Analyze_Input_List (Inputs : Node_Id) is
698 Inputs_Seen : Elist_Id := No_Elist;
699 -- A list containing the entities of all inputs that appear in the
700 -- current input list.
701
702 Non_Null_Input_Seen : Boolean := False;
703 Null_Input_Seen : Boolean := False;
704 -- Flags used to check the legality of an input list
705
706 Input : Node_Id;
707
708 begin
709 -- Multiple inputs appear as an aggregate
710
711 if Nkind (Inputs) = N_Aggregate then
712 if Present (Component_Associations (Inputs)) then
713 SPARK_Msg_N
714 ("nested dependency relations not allowed", Inputs);
715
716 elsif Present (Expressions (Inputs)) then
717 Input := First (Expressions (Inputs));
718 while Present (Input) loop
719 Analyze_Input_Output
720 (Item => Input,
721 Is_Input => True,
722 Self_Ref => False,
723 Top_Level => False,
724 Seen => Inputs_Seen,
725 Null_Seen => Null_Input_Seen,
726 Non_Null_Seen => Non_Null_Input_Seen);
727
728 Next (Input);
729 end loop;
730
731 -- Syntax error, always report
732
733 else
734 Error_Msg_N ("malformed input dependency list", Inputs);
735 end if;
736
737 -- Process a solitary input
738
739 else
740 Analyze_Input_Output
741 (Item => Inputs,
742 Is_Input => True,
743 Self_Ref => False,
744 Top_Level => False,
745 Seen => Inputs_Seen,
746 Null_Seen => Null_Input_Seen,
747 Non_Null_Seen => Non_Null_Input_Seen);
748 end if;
749
750 -- Detect an illegal dependency clause of the form
751
752 -- (null =>[+] null)
753
754 if Null_Output_Seen and then Null_Input_Seen then
755 SPARK_Msg_N
756 ("null dependency clause cannot have a null input list",
757 Inputs);
758 end if;
759 end Analyze_Input_List;
760
761 --------------------------
762 -- Analyze_Input_Output --
763 --------------------------
764
765 procedure Analyze_Input_Output
766 (Item : Node_Id;
767 Is_Input : Boolean;
768 Self_Ref : Boolean;
769 Top_Level : Boolean;
770 Seen : in out Elist_Id;
771 Null_Seen : in out Boolean;
772 Non_Null_Seen : in out Boolean)
773 is
774 procedure Current_Task_Instance_Seen;
775 -- Set the appropriate global flag when the current instance of a
776 -- task unit is encountered.
777
778 --------------------------------
779 -- Current_Task_Instance_Seen --
780 --------------------------------
781
782 procedure Current_Task_Instance_Seen is
783 begin
784 if Is_Input then
785 Task_Input_Seen := True;
786 else
787 Task_Output_Seen := True;
788 end if;
789 end Current_Task_Instance_Seen;
790
791 -- Local variables
792
793 Is_Output : constant Boolean := not Is_Input;
794 Grouped : Node_Id;
795 Item_Id : Entity_Id;
796
797 -- Start of processing for Analyze_Input_Output
798
799 begin
800 -- Multiple input or output items appear as an aggregate
801
802 if Nkind (Item) = N_Aggregate then
803 if not Top_Level then
804 SPARK_Msg_N ("nested grouping of items not allowed", Item);
805
806 elsif Present (Component_Associations (Item)) then
807 SPARK_Msg_N
808 ("nested dependency relations not allowed", Item);
809
810 -- Recursively analyze the grouped items
811
812 elsif Present (Expressions (Item)) then
813 Grouped := First (Expressions (Item));
814 while Present (Grouped) loop
815 Analyze_Input_Output
816 (Item => Grouped,
817 Is_Input => Is_Input,
818 Self_Ref => Self_Ref,
819 Top_Level => False,
820 Seen => Seen,
821 Null_Seen => Null_Seen,
822 Non_Null_Seen => Non_Null_Seen);
823
824 Next (Grouped);
825 end loop;
826
827 -- Syntax error, always report
828
829 else
830 Error_Msg_N ("malformed dependency list", Item);
831 end if;
832
833 -- Process attribute 'Result in the context of a dependency clause
834
835 elsif Is_Attribute_Result (Item) then
836 Non_Null_Seen := True;
837
838 Analyze (Item);
839
840 -- Attribute 'Result is allowed to appear on the output side of
841 -- a dependency clause (SPARK RM 6.1.5(6)).
842
843 if Is_Input then
844 SPARK_Msg_N ("function result cannot act as input", Item);
845
846 elsif Null_Seen then
847 SPARK_Msg_N
848 ("cannot mix null and non-null dependency items", Item);
849
850 else
851 Result_Seen := True;
852 end if;
853
854 -- Detect multiple uses of null in a single dependency list or
855 -- throughout the whole relation. Verify the placement of a null
856 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
857
858 elsif Nkind (Item) = N_Null then
859 if Null_Seen then
860 SPARK_Msg_N
861 ("multiple null dependency relations not allowed", Item);
862
863 elsif Non_Null_Seen then
864 SPARK_Msg_N
865 ("cannot mix null and non-null dependency items", Item);
866
867 else
868 Null_Seen := True;
869
870 if Is_Output then
871 if not Is_Last then
872 SPARK_Msg_N
873 ("null output list must be the last clause in a "
874 & "dependency relation", Item);
875
876 -- Catch a useless dependence of the form:
877 -- null =>+ ...
878
879 elsif Self_Ref then
880 SPARK_Msg_N
881 ("useless dependence, null depends on itself", Item);
882 end if;
883 end if;
884 end if;
885
886 -- Default case
887
888 else
889 Non_Null_Seen := True;
890
891 if Null_Seen then
892 SPARK_Msg_N ("cannot mix null and non-null items", Item);
893 end if;
894
895 Analyze (Item);
896 Resolve_State (Item);
897
898 -- Find the entity of the item. If this is a renaming, climb
899 -- the renaming chain to reach the root object. Renamings of
900 -- non-entire objects do not yield an entity (Empty).
901
902 Item_Id := Entity_Of (Item);
903
904 if Present (Item_Id) then
905
906 -- Constants
907
908 if Ekind_In (Item_Id, E_Constant,
909 E_Discriminant,
910 E_Loop_Parameter)
911 or else
912
913 -- Current instances of concurrent types
914
915 Ekind_In (Item_Id, E_Protected_Type, E_Task_Type)
916 or else
917
918 -- Formal parameters
919
920 Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
921 E_Generic_In_Parameter,
922 E_In_Parameter,
923 E_In_Out_Parameter,
924 E_Out_Parameter)
925 or else
926
927 -- States, variables
928
929 Ekind_In (Item_Id, E_Abstract_State, E_Variable)
930 then
931 -- The item denotes a concurrent type. Note that single
932 -- protected/task types are not considered here because
933 -- they behave as objects in the context of pragma
934 -- [Refined_]Depends.
935
936 if Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
937
938 -- This use is legal as long as the concurrent type is
939 -- the current instance of an enclosing type.
940
941 if Is_CCT_Instance (Item_Id, Spec_Id) then
942
943 -- The dependence of a task unit on itself is
944 -- implicit and may or may not be explicitly
945 -- specified (SPARK RM 6.1.4).
946
947 if Ekind (Item_Id) = E_Task_Type then
948 Current_Task_Instance_Seen;
949 end if;
950
951 -- Otherwise this is not the current instance
952
953 else
954 SPARK_Msg_N
955 ("invalid use of subtype mark in dependency "
956 & "relation", Item);
957 end if;
958
959 -- The dependency of a task unit on itself is implicit
960 -- and may or may not be explicitly specified
961 -- (SPARK RM 6.1.4).
962
963 elsif Is_Single_Task_Object (Item_Id)
964 and then Is_CCT_Instance (Item_Id, Spec_Id)
965 then
966 Current_Task_Instance_Seen;
967 end if;
968
969 -- Ensure that the item fulfills its role as input and/or
970 -- output as specified by pragma Global or the enclosing
971 -- context.
972
973 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
974
975 -- Detect multiple uses of the same state, variable or
976 -- formal parameter. If this is not the case, add the
977 -- item to the list of processed relations.
978
979 if Contains (Seen, Item_Id) then
980 SPARK_Msg_NE
981 ("duplicate use of item &", Item, Item_Id);
982 else
983 Append_New_Elmt (Item_Id, Seen);
984 end if;
985
986 -- Detect illegal use of an input related to a null
987 -- output. Such input items cannot appear in other
988 -- input lists (SPARK RM 6.1.5(13)).
989
990 if Is_Input
991 and then Null_Output_Seen
992 and then Contains (All_Inputs_Seen, Item_Id)
993 then
994 SPARK_Msg_N
995 ("input of a null output list cannot appear in "
996 & "multiple input lists", Item);
997 end if;
998
999 -- Add an input or a self-referential output to the list
1000 -- of all processed inputs.
1001
1002 if Is_Input or else Self_Ref then
1003 Append_New_Elmt (Item_Id, All_Inputs_Seen);
1004 end if;
1005
1006 -- State related checks (SPARK RM 6.1.5(3))
1007
1008 if Ekind (Item_Id) = E_Abstract_State then
1009
1010 -- Package and subprogram bodies are instantiated
1011 -- individually in a separate compiler pass. Due to
1012 -- this mode of instantiation, the refinement of a
1013 -- state may no longer be visible when a subprogram
1014 -- body contract is instantiated. Since the generic
1015 -- template is legal, do not perform this check in
1016 -- the instance to circumvent this oddity.
1017
1018 if Is_Generic_Instance (Spec_Id) then
1019 null;
1020
1021 -- An abstract state with visible refinement cannot
1022 -- appear in pragma [Refined_]Depends as its place
1023 -- must be taken by some of its constituents
1024 -- (SPARK RM 6.1.4(7)).
1025
1026 elsif Has_Visible_Refinement (Item_Id) then
1027 SPARK_Msg_NE
1028 ("cannot mention state & in dependence relation",
1029 Item, Item_Id);
1030 SPARK_Msg_N ("\use its constituents instead", Item);
1031 return;
1032
1033 -- If the reference to the abstract state appears in
1034 -- an enclosing package body that will eventually
1035 -- refine the state, record the reference for future
1036 -- checks.
1037
1038 else
1039 Record_Possible_Body_Reference
1040 (State_Id => Item_Id,
1041 Ref => Item);
1042 end if;
1043 end if;
1044
1045 -- When the item renames an entire object, replace the
1046 -- item with a reference to the object.
1047
1048 if Entity (Item) /= Item_Id then
1049 Rewrite (Item,
1050 New_Occurrence_Of (Item_Id, Sloc (Item)));
1051 Analyze (Item);
1052 end if;
1053
1054 -- Add the entity of the current item to the list of
1055 -- processed items.
1056
1057 if Ekind (Item_Id) = E_Abstract_State then
1058 Append_New_Elmt (Item_Id, States_Seen);
1059
1060 -- The variable may eventually become a constituent of a
1061 -- single protected/task type. Record the reference now
1062 -- and verify its legality when analyzing the contract of
1063 -- the variable (SPARK RM 9.3).
1064
1065 elsif Ekind (Item_Id) = E_Variable then
1066 Record_Possible_Part_Of_Reference
1067 (Var_Id => Item_Id,
1068 Ref => Item);
1069 end if;
1070
1071 if Ekind_In (Item_Id, E_Abstract_State,
1072 E_Constant,
1073 E_Variable)
1074 and then Present (Encapsulating_State (Item_Id))
1075 then
1076 Append_New_Elmt (Item_Id, Constits_Seen);
1077 end if;
1078
1079 -- All other input/output items are illegal
1080 -- (SPARK RM 6.1.5(1)).
1081
1082 else
1083 SPARK_Msg_N
1084 ("item must denote parameter, variable, state or "
1085 & "current instance of concurren type", Item);
1086 end if;
1087
1088 -- All other input/output items are illegal
1089 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1090
1091 else
1092 Error_Msg_N
1093 ("item must denote parameter, variable, state or current "
1094 & "instance of concurrent type", Item);
1095 end if;
1096 end if;
1097 end Analyze_Input_Output;
1098
1099 -- Local variables
1100
1101 Inputs : Node_Id;
1102 Output : Node_Id;
1103 Self_Ref : Boolean;
1104
1105 Non_Null_Output_Seen : Boolean := False;
1106 -- Flag used to check the legality of an output list
1107
1108 -- Start of processing for Analyze_Dependency_Clause
1109
1110 begin
1111 Inputs := Expression (Clause);
1112 Self_Ref := False;
1113
1114 -- An input list with a self-dependency appears as operator "+" where
1115 -- the actuals inputs are the right operand.
1116
1117 if Nkind (Inputs) = N_Op_Plus then
1118 Inputs := Right_Opnd (Inputs);
1119 Self_Ref := True;
1120 end if;
1121
1122 -- Process the output_list of a dependency_clause
1123
1124 Output := First (Choices (Clause));
1125 while Present (Output) loop
1126 Analyze_Input_Output
1127 (Item => Output,
1128 Is_Input => False,
1129 Self_Ref => Self_Ref,
1130 Top_Level => True,
1131 Seen => All_Outputs_Seen,
1132 Null_Seen => Null_Output_Seen,
1133 Non_Null_Seen => Non_Null_Output_Seen);
1134
1135 Next (Output);
1136 end loop;
1137
1138 -- Process the input_list of a dependency_clause
1139
1140 Analyze_Input_List (Inputs);
1141 end Analyze_Dependency_Clause;
1142
1143 ---------------------------
1144 -- Check_Function_Return --
1145 ---------------------------
1146
1147 procedure Check_Function_Return is
1148 begin
1149 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
1150 and then not Result_Seen
1151 then
1152 SPARK_Msg_NE
1153 ("result of & must appear in exactly one output list",
1154 N, Spec_Id);
1155 end if;
1156 end Check_Function_Return;
1157
1158 ----------------
1159 -- Check_Role --
1160 ----------------
1161
1162 procedure Check_Role
1163 (Item : Node_Id;
1164 Item_Id : Entity_Id;
1165 Is_Input : Boolean;
1166 Self_Ref : Boolean)
1167 is
1168 procedure Find_Role
1169 (Item_Is_Input : out Boolean;
1170 Item_Is_Output : out Boolean);
1171 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1172 -- Item_Is_Output are set depending on the role.
1173
1174 procedure Role_Error
1175 (Item_Is_Input : Boolean;
1176 Item_Is_Output : Boolean);
1177 -- Emit an error message concerning the incorrect use of Item in
1178 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1179 -- denote whether the item is an input and/or an output.
1180
1181 ---------------
1182 -- Find_Role --
1183 ---------------
1184
1185 procedure Find_Role
1186 (Item_Is_Input : out Boolean;
1187 Item_Is_Output : out Boolean)
1188 is
1189 begin
1190 Item_Is_Input := False;
1191 Item_Is_Output := False;
1192
1193 -- Abstract states
1194
1195 if Ekind (Item_Id) = E_Abstract_State then
1196
1197 -- When pragma Global is present, the mode of the state may be
1198 -- further constrained by setting a more restrictive mode.
1199
1200 if Global_Seen then
1201 if Appears_In (Subp_Inputs, Item_Id) then
1202 Item_Is_Input := True;
1203 end if;
1204
1205 if Appears_In (Subp_Outputs, Item_Id) then
1206 Item_Is_Output := True;
1207 end if;
1208
1209 -- Otherwise the state has a default IN OUT mode
1210
1211 else
1212 Item_Is_Input := True;
1213 Item_Is_Output := True;
1214 end if;
1215
1216 -- Constants
1217
1218 elsif Ekind_In (Item_Id, E_Constant,
1219 E_Discriminant,
1220 E_Loop_Parameter)
1221 then
1222 Item_Is_Input := True;
1223
1224 -- Parameters
1225
1226 elsif Ekind_In (Item_Id, E_Generic_In_Parameter,
1227 E_In_Parameter)
1228 then
1229 Item_Is_Input := True;
1230
1231 elsif Ekind_In (Item_Id, E_Generic_In_Out_Parameter,
1232 E_In_Out_Parameter)
1233 then
1234 Item_Is_Input := True;
1235 Item_Is_Output := True;
1236
1237 elsif Ekind (Item_Id) = E_Out_Parameter then
1238 if Scope (Item_Id) = Spec_Id then
1239
1240 -- An OUT parameter of the related subprogram has mode IN
1241 -- if its type is unconstrained or tagged because array
1242 -- bounds, discriminants or tags can be read.
1243
1244 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1245 Item_Is_Input := True;
1246 end if;
1247
1248 Item_Is_Output := True;
1249
1250 -- An OUT parameter of an enclosing subprogram behaves as a
1251 -- read-write variable in which case the mode is IN OUT.
1252
1253 else
1254 Item_Is_Input := True;
1255 Item_Is_Output := True;
1256 end if;
1257
1258 -- Protected types
1259
1260 elsif Ekind (Item_Id) = E_Protected_Type then
1261
1262 -- A protected type acts as a formal parameter of mode IN when
1263 -- it applies to a protected function.
1264
1265 if Ekind (Spec_Id) = E_Function then
1266 Item_Is_Input := True;
1267
1268 -- Otherwise the protected type acts as a formal of mode IN OUT
1269
1270 else
1271 Item_Is_Input := True;
1272 Item_Is_Output := True;
1273 end if;
1274
1275 -- Task types
1276
1277 elsif Ekind (Item_Id) = E_Task_Type then
1278 Item_Is_Input := True;
1279 Item_Is_Output := True;
1280
1281 -- Variable case
1282
1283 else pragma Assert (Ekind (Item_Id) = E_Variable);
1284
1285 -- When pragma Global is present, the mode of the variable may
1286 -- be further constrained by setting a more restrictive mode.
1287
1288 if Global_Seen then
1289
1290 -- A variable has mode IN when its type is unconstrained or
1291 -- tagged because array bounds, discriminants or tags can be
1292 -- read.
1293
1294 if Appears_In (Subp_Inputs, Item_Id)
1295 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1296 then
1297 Item_Is_Input := True;
1298 end if;
1299
1300 if Appears_In (Subp_Outputs, Item_Id) then
1301 Item_Is_Output := True;
1302 end if;
1303
1304 -- Otherwise the variable has a default IN OUT mode
1305
1306 else
1307 Item_Is_Input := True;
1308 Item_Is_Output := True;
1309 end if;
1310 end if;
1311 end Find_Role;
1312
1313 ----------------
1314 -- Role_Error --
1315 ----------------
1316
1317 procedure Role_Error
1318 (Item_Is_Input : Boolean;
1319 Item_Is_Output : Boolean)
1320 is
1321 Error_Msg : Name_Id;
1322
1323 begin
1324 Name_Len := 0;
1325
1326 -- When the item is not part of the input and the output set of
1327 -- the related subprogram, then it appears as extra in pragma
1328 -- [Refined_]Depends.
1329
1330 if not Item_Is_Input and then not Item_Is_Output then
1331 Add_Item_To_Name_Buffer (Item_Id);
1332 Add_Str_To_Name_Buffer
1333 (" & cannot appear in dependence relation");
1334
1335 Error_Msg := Name_Find;
1336 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1337
1338 Error_Msg_Name_1 := Chars (Spec_Id);
1339 SPARK_Msg_NE
1340 (Fix_Msg (Spec_Id, "\& is not part of the input or output "
1341 & "set of subprogram %"), Item, Item_Id);
1342
1343 -- The mode of the item and its role in pragma [Refined_]Depends
1344 -- are in conflict. Construct a detailed message explaining the
1345 -- illegality (SPARK RM 6.1.5(5-6)).
1346
1347 else
1348 if Item_Is_Input then
1349 Add_Str_To_Name_Buffer ("read-only");
1350 else
1351 Add_Str_To_Name_Buffer ("write-only");
1352 end if;
1353
1354 Add_Char_To_Name_Buffer (' ');
1355 Add_Item_To_Name_Buffer (Item_Id);
1356 Add_Str_To_Name_Buffer (" & cannot appear as ");
1357
1358 if Item_Is_Input then
1359 Add_Str_To_Name_Buffer ("output");
1360 else
1361 Add_Str_To_Name_Buffer ("input");
1362 end if;
1363
1364 Add_Str_To_Name_Buffer (" in dependence relation");
1365 Error_Msg := Name_Find;
1366 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1367 end if;
1368 end Role_Error;
1369
1370 -- Local variables
1371
1372 Item_Is_Input : Boolean;
1373 Item_Is_Output : Boolean;
1374
1375 -- Start of processing for Check_Role
1376
1377 begin
1378 Find_Role (Item_Is_Input, Item_Is_Output);
1379
1380 -- Input item
1381
1382 if Is_Input then
1383 if not Item_Is_Input then
1384 Role_Error (Item_Is_Input, Item_Is_Output);
1385 end if;
1386
1387 -- Self-referential item
1388
1389 elsif Self_Ref then
1390 if not Item_Is_Input or else not Item_Is_Output then
1391 Role_Error (Item_Is_Input, Item_Is_Output);
1392 end if;
1393
1394 -- Output item
1395
1396 elsif not Item_Is_Output then
1397 Role_Error (Item_Is_Input, Item_Is_Output);
1398 end if;
1399 end Check_Role;
1400
1401 -----------------
1402 -- Check_Usage --
1403 -----------------
1404
1405 procedure Check_Usage
1406 (Subp_Items : Elist_Id;
1407 Used_Items : Elist_Id;
1408 Is_Input : Boolean)
1409 is
1410 procedure Usage_Error (Item_Id : Entity_Id);
1411 -- Emit an error concerning the illegal usage of an item
1412
1413 -----------------
1414 -- Usage_Error --
1415 -----------------
1416
1417 procedure Usage_Error (Item_Id : Entity_Id) is
1418 Error_Msg : Name_Id;
1419
1420 begin
1421 -- Input case
1422
1423 if Is_Input then
1424
1425 -- Unconstrained and tagged items are not part of the explicit
1426 -- input set of the related subprogram, they do not have to be
1427 -- present in a dependence relation and should not be flagged
1428 -- (SPARK RM 6.1.5(8)).
1429
1430 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1431 Name_Len := 0;
1432
1433 Add_Item_To_Name_Buffer (Item_Id);
1434 Add_Str_To_Name_Buffer
1435 (" & is missing from input dependence list");
1436
1437 Error_Msg := Name_Find;
1438 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1439 end if;
1440
1441 -- Output case (SPARK RM 6.1.5(10))
1442
1443 else
1444 Name_Len := 0;
1445
1446 Add_Item_To_Name_Buffer (Item_Id);
1447 Add_Str_To_Name_Buffer
1448 (" & is missing from output dependence list");
1449
1450 Error_Msg := Name_Find;
1451 SPARK_Msg_NE (Get_Name_String (Error_Msg), N, Item_Id);
1452 end if;
1453 end Usage_Error;
1454
1455 -- Local variables
1456
1457 Elmt : Elmt_Id;
1458 Item : Node_Id;
1459 Item_Id : Entity_Id;
1460
1461 -- Start of processing for Check_Usage
1462
1463 begin
1464 if No (Subp_Items) then
1465 return;
1466 end if;
1467
1468 -- Each input or output of the subprogram must appear in a dependency
1469 -- relation.
1470
1471 Elmt := First_Elmt (Subp_Items);
1472 while Present (Elmt) loop
1473 Item := Node (Elmt);
1474
1475 if Nkind (Item) = N_Defining_Identifier then
1476 Item_Id := Item;
1477 else
1478 Item_Id := Entity_Of (Item);
1479 end if;
1480
1481 -- The item does not appear in a dependency
1482
1483 if Present (Item_Id)
1484 and then not Contains (Used_Items, Item_Id)
1485 then
1486 if Is_Formal (Item_Id) then
1487 Usage_Error (Item_Id);
1488
1489 -- The current instance of a protected type behaves as a formal
1490 -- parameter (SPARK RM 6.1.4).
1491
1492 elsif Ekind (Item_Id) = E_Protected_Type
1493 or else Is_Single_Protected_Object (Item_Id)
1494 then
1495 Usage_Error (Item_Id);
1496
1497 -- The current instance of a task type behaves as a formal
1498 -- parameter (SPARK RM 6.1.4).
1499
1500 elsif Ekind (Item_Id) = E_Task_Type
1501 or else Is_Single_Task_Object (Item_Id)
1502 then
1503 -- The dependence of a task unit on itself is implicit and
1504 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1505 -- Emit an error if only one input/output is present.
1506
1507 if Task_Input_Seen /= Task_Output_Seen then
1508 Usage_Error (Item_Id);
1509 end if;
1510
1511 -- States and global objects are not used properly only when
1512 -- the subprogram is subject to pragma Global.
1513
1514 elsif Global_Seen then
1515 Usage_Error (Item_Id);
1516 end if;
1517 end if;
1518
1519 Next_Elmt (Elmt);
1520 end loop;
1521 end Check_Usage;
1522
1523 ----------------------
1524 -- Normalize_Clause --
1525 ----------------------
1526
1527 procedure Normalize_Clause (Clause : Node_Id) is
1528 procedure Create_Or_Modify_Clause
1529 (Output : Node_Id;
1530 Outputs : Node_Id;
1531 Inputs : Node_Id;
1532 After : Node_Id;
1533 In_Place : Boolean;
1534 Multiple : Boolean);
1535 -- Create a brand new clause to represent the self-reference or
1536 -- modify the input and/or output lists of an existing clause. Output
1537 -- denotes a self-referencial output. Outputs is the output list of a
1538 -- clause. Inputs is the input list of a clause. After denotes the
1539 -- clause after which the new clause is to be inserted. Flag In_Place
1540 -- should be set when normalizing the last output of an output list.
1541 -- Flag Multiple should be set when Output comes from a list with
1542 -- multiple items.
1543
1544 -----------------------------
1545 -- Create_Or_Modify_Clause --
1546 -----------------------------
1547
1548 procedure Create_Or_Modify_Clause
1549 (Output : Node_Id;
1550 Outputs : Node_Id;
1551 Inputs : Node_Id;
1552 After : Node_Id;
1553 In_Place : Boolean;
1554 Multiple : Boolean)
1555 is
1556 procedure Propagate_Output
1557 (Output : Node_Id;
1558 Inputs : Node_Id);
1559 -- Handle the various cases of output propagation to the input
1560 -- list. Output denotes a self-referencial output item. Inputs
1561 -- is the input list of a clause.
1562
1563 ----------------------
1564 -- Propagate_Output --
1565 ----------------------
1566
1567 procedure Propagate_Output
1568 (Output : Node_Id;
1569 Inputs : Node_Id)
1570 is
1571 function In_Input_List
1572 (Item : Entity_Id;
1573 Inputs : List_Id) return Boolean;
1574 -- Determine whether a particulat item appears in the input
1575 -- list of a clause.
1576
1577 -------------------
1578 -- In_Input_List --
1579 -------------------
1580
1581 function In_Input_List
1582 (Item : Entity_Id;
1583 Inputs : List_Id) return Boolean
1584 is
1585 Elmt : Node_Id;
1586
1587 begin
1588 Elmt := First (Inputs);
1589 while Present (Elmt) loop
1590 if Entity_Of (Elmt) = Item then
1591 return True;
1592 end if;
1593
1594 Next (Elmt);
1595 end loop;
1596
1597 return False;
1598 end In_Input_List;
1599
1600 -- Local variables
1601
1602 Output_Id : constant Entity_Id := Entity_Of (Output);
1603 Grouped : List_Id;
1604
1605 -- Start of processing for Propagate_Output
1606
1607 begin
1608 -- The clause is of the form:
1609
1610 -- (Output =>+ null)
1611
1612 -- Remove null input and replace it with a copy of the output:
1613
1614 -- (Output => Output)
1615
1616 if Nkind (Inputs) = N_Null then
1617 Rewrite (Inputs, New_Copy_Tree (Output));
1618
1619 -- The clause is of the form:
1620
1621 -- (Output =>+ (Input1, ..., InputN))
1622
1623 -- Determine whether the output is not already mentioned in the
1624 -- input list and if not, add it to the list of inputs:
1625
1626 -- (Output => (Output, Input1, ..., InputN))
1627
1628 elsif Nkind (Inputs) = N_Aggregate then
1629 Grouped := Expressions (Inputs);
1630
1631 if not In_Input_List
1632 (Item => Output_Id,
1633 Inputs => Grouped)
1634 then
1635 Prepend_To (Grouped, New_Copy_Tree (Output));
1636 end if;
1637
1638 -- The clause is of the form:
1639
1640 -- (Output =>+ Input)
1641
1642 -- If the input does not mention the output, group the two
1643 -- together:
1644
1645 -- (Output => (Output, Input))
1646
1647 elsif Entity_Of (Inputs) /= Output_Id then
1648 Rewrite (Inputs,
1649 Make_Aggregate (Loc,
1650 Expressions => New_List (
1651 New_Copy_Tree (Output),
1652 New_Copy_Tree (Inputs))));
1653 end if;
1654 end Propagate_Output;
1655
1656 -- Local variables
1657
1658 Loc : constant Source_Ptr := Sloc (Clause);
1659 New_Clause : Node_Id;
1660
1661 -- Start of processing for Create_Or_Modify_Clause
1662
1663 begin
1664 -- A null output depending on itself does not require any
1665 -- normalization.
1666
1667 if Nkind (Output) = N_Null then
1668 return;
1669
1670 -- A function result cannot depend on itself because it cannot
1671 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1672
1673 elsif Is_Attribute_Result (Output) then
1674 SPARK_Msg_N ("function result cannot depend on itself", Output);
1675 return;
1676 end if;
1677
1678 -- When performing the transformation in place, simply add the
1679 -- output to the list of inputs (if not already there). This
1680 -- case arises when dealing with the last output of an output
1681 -- list. Perform the normalization in place to avoid generating
1682 -- a malformed tree.
1683
1684 if In_Place then
1685 Propagate_Output (Output, Inputs);
1686
1687 -- A list with multiple outputs is slowly trimmed until only
1688 -- one element remains. When this happens, replace aggregate
1689 -- with the element itself.
1690
1691 if Multiple then
1692 Remove (Output);
1693 Rewrite (Outputs, Output);
1694 end if;
1695
1696 -- Default case
1697
1698 else
1699 -- Unchain the output from its output list as it will appear in
1700 -- a new clause. Note that we cannot simply rewrite the output
1701 -- as null because this will violate the semantics of pragma
1702 -- Depends.
1703
1704 Remove (Output);
1705
1706 -- Generate a new clause of the form:
1707 -- (Output => Inputs)
1708
1709 New_Clause :=
1710 Make_Component_Association (Loc,
1711 Choices => New_List (Output),
1712 Expression => New_Copy_Tree (Inputs));
1713
1714 -- The new clause contains replicated content that has already
1715 -- been analyzed. There is not need to reanalyze or renormalize
1716 -- it again.
1717
1718 Set_Analyzed (New_Clause);
1719
1720 Propagate_Output
1721 (Output => First (Choices (New_Clause)),
1722 Inputs => Expression (New_Clause));
1723
1724 Insert_After (After, New_Clause);
1725 end if;
1726 end Create_Or_Modify_Clause;
1727
1728 -- Local variables
1729
1730 Outputs : constant Node_Id := First (Choices (Clause));
1731 Inputs : Node_Id;
1732 Last_Output : Node_Id;
1733 Next_Output : Node_Id;
1734 Output : Node_Id;
1735
1736 -- Start of processing for Normalize_Clause
1737
1738 begin
1739 -- A self-dependency appears as operator "+". Remove the "+" from the
1740 -- tree by moving the real inputs to their proper place.
1741
1742 if Nkind (Expression (Clause)) = N_Op_Plus then
1743 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1744 Inputs := Expression (Clause);
1745
1746 -- Multiple outputs appear as an aggregate
1747
1748 if Nkind (Outputs) = N_Aggregate then
1749 Last_Output := Last (Expressions (Outputs));
1750
1751 Output := First (Expressions (Outputs));
1752 while Present (Output) loop
1753
1754 -- Normalization may remove an output from its list,
1755 -- preserve the subsequent output now.
1756
1757 Next_Output := Next (Output);
1758
1759 Create_Or_Modify_Clause
1760 (Output => Output,
1761 Outputs => Outputs,
1762 Inputs => Inputs,
1763 After => Clause,
1764 In_Place => Output = Last_Output,
1765 Multiple => True);
1766
1767 Output := Next_Output;
1768 end loop;
1769
1770 -- Solitary output
1771
1772 else
1773 Create_Or_Modify_Clause
1774 (Output => Outputs,
1775 Outputs => Empty,
1776 Inputs => Inputs,
1777 After => Empty,
1778 In_Place => True,
1779 Multiple => False);
1780 end if;
1781 end if;
1782 end Normalize_Clause;
1783
1784 -- Local variables
1785
1786 Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
1787 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
1788
1789 Clause : Node_Id;
1790 Errors : Nat;
1791 Last_Clause : Node_Id;
1792 Restore_Scope : Boolean := False;
1793
1794 -- Start of processing for Analyze_Depends_In_Decl_Part
1795
1796 begin
1797 -- Do not analyze the pragma multiple times
1798
1799 if Is_Analyzed_Pragma (N) then
1800 return;
1801 end if;
1802
1803 -- Empty dependency list
1804
1805 if Nkind (Deps) = N_Null then
1806
1807 -- Gather all states, objects and formal parameters that the
1808 -- subprogram may depend on. These items are obtained from the
1809 -- parameter profile or pragma [Refined_]Global (if available).
1810
1811 Collect_Subprogram_Inputs_Outputs
1812 (Subp_Id => Subp_Id,
1813 Subp_Inputs => Subp_Inputs,
1814 Subp_Outputs => Subp_Outputs,
1815 Global_Seen => Global_Seen);
1816
1817 -- Verify that every input or output of the subprogram appear in a
1818 -- dependency.
1819
1820 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1821 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1822 Check_Function_Return;
1823
1824 -- Dependency clauses appear as component associations of an aggregate
1825
1826 elsif Nkind (Deps) = N_Aggregate then
1827
1828 -- Do not attempt to perform analysis of a syntactically illegal
1829 -- clause as this will lead to misleading errors.
1830
1831 if Has_Extra_Parentheses (Deps) then
1832 return;
1833 end if;
1834
1835 if Present (Component_Associations (Deps)) then
1836 Last_Clause := Last (Component_Associations (Deps));
1837
1838 -- Gather all states, objects and formal parameters that the
1839 -- subprogram may depend on. These items are obtained from the
1840 -- parameter profile or pragma [Refined_]Global (if available).
1841
1842 Collect_Subprogram_Inputs_Outputs
1843 (Subp_Id => Subp_Id,
1844 Subp_Inputs => Subp_Inputs,
1845 Subp_Outputs => Subp_Outputs,
1846 Global_Seen => Global_Seen);
1847
1848 -- When pragma [Refined_]Depends appears on a single concurrent
1849 -- type, it is relocated to the anonymous object.
1850
1851 if Is_Single_Concurrent_Object (Spec_Id) then
1852 null;
1853
1854 -- Ensure that the formal parameters are visible when analyzing
1855 -- all clauses. This falls out of the general rule of aspects
1856 -- pertaining to subprogram declarations.
1857
1858 elsif not In_Open_Scopes (Spec_Id) then
1859 Restore_Scope := True;
1860 Push_Scope (Spec_Id);
1861
1862 if Ekind (Spec_Id) = E_Task_Type then
1863 if Has_Discriminants (Spec_Id) then
1864 Install_Discriminants (Spec_Id);
1865 end if;
1866
1867 elsif Is_Generic_Subprogram (Spec_Id) then
1868 Install_Generic_Formals (Spec_Id);
1869
1870 else
1871 Install_Formals (Spec_Id);
1872 end if;
1873 end if;
1874
1875 Clause := First (Component_Associations (Deps));
1876 while Present (Clause) loop
1877 Errors := Serious_Errors_Detected;
1878
1879 -- The normalization mechanism may create extra clauses that
1880 -- contain replicated input and output names. There is no need
1881 -- to reanalyze them.
1882
1883 if not Analyzed (Clause) then
1884 Set_Analyzed (Clause);
1885
1886 Analyze_Dependency_Clause
1887 (Clause => Clause,
1888 Is_Last => Clause = Last_Clause);
1889 end if;
1890
1891 -- Do not normalize a clause if errors were detected (count
1892 -- of Serious_Errors has increased) because the inputs and/or
1893 -- outputs may denote illegal items. Normalization is disabled
1894 -- in ASIS mode as it alters the tree by introducing new nodes
1895 -- similar to expansion.
1896
1897 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1898 Normalize_Clause (Clause);
1899 end if;
1900
1901 Next (Clause);
1902 end loop;
1903
1904 if Restore_Scope then
1905 End_Scope;
1906 end if;
1907
1908 -- Verify that every input or output of the subprogram appear in a
1909 -- dependency.
1910
1911 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1912 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1913 Check_Function_Return;
1914
1915 -- The dependency list is malformed. This is a syntax error, always
1916 -- report.
1917
1918 else
1919 Error_Msg_N ("malformed dependency relation", Deps);
1920 return;
1921 end if;
1922
1923 -- The top level dependency relation is malformed. This is a syntax
1924 -- error, always report.
1925
1926 else
1927 Error_Msg_N ("malformed dependency relation", Deps);
1928 goto Leave;
1929 end if;
1930
1931 -- Ensure that a state and a corresponding constituent do not appear
1932 -- together in pragma [Refined_]Depends.
1933
1934 Check_State_And_Constituent_Use
1935 (States => States_Seen,
1936 Constits => Constits_Seen,
1937 Context => N);
1938
1939 <<Leave>>
1940 Set_Is_Analyzed_Pragma (N);
1941 end Analyze_Depends_In_Decl_Part;
1942
1943 --------------------------------------------
1944 -- Analyze_External_Property_In_Decl_Part --
1945 --------------------------------------------
1946
1947 procedure Analyze_External_Property_In_Decl_Part
1948 (N : Node_Id;
1949 Expr_Val : out Boolean)
1950 is
1951 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1952 Obj_Decl : constant Node_Id := Find_Related_Context (N);
1953 Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl);
1954 Expr : Node_Id;
1955
1956 begin
1957 Expr_Val := False;
1958
1959 -- Do not analyze the pragma multiple times
1960
1961 if Is_Analyzed_Pragma (N) then
1962 return;
1963 end if;
1964
1965 Error_Msg_Name_1 := Pragma_Name (N);
1966
1967 -- An external property pragma must apply to an effectively volatile
1968 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1969 -- The check is performed at the end of the declarative region due to a
1970 -- possible out-of-order arrangement of pragmas:
1971
1972 -- Obj : ...;
1973 -- pragma Async_Readers (Obj);
1974 -- pragma Volatile (Obj);
1975
1976 if not Is_Effectively_Volatile (Obj_Id) then
1977 SPARK_Msg_N
1978 ("external property % must apply to a volatile object", N);
1979 end if;
1980
1981 -- Ensure that the Boolean expression (if present) is static. A missing
1982 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1983
1984 Expr_Val := True;
1985
1986 if Present (Arg1) then
1987 Expr := Get_Pragma_Arg (Arg1);
1988
1989 if Is_OK_Static_Expression (Expr) then
1990 Expr_Val := Is_True (Expr_Value (Expr));
1991 end if;
1992 end if;
1993
1994 Set_Is_Analyzed_Pragma (N);
1995 end Analyze_External_Property_In_Decl_Part;
1996
1997 ---------------------------------
1998 -- Analyze_Global_In_Decl_Part --
1999 ---------------------------------
2000
2001 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
2002 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
2003 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
2004 Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
2005
2006 Constits_Seen : Elist_Id := No_Elist;
2007 -- A list containing the entities of all constituents processed so far.
2008 -- It aids in detecting illegal usage of a state and a corresponding
2009 -- constituent in pragma [Refinde_]Global.
2010
2011 Seen : Elist_Id := No_Elist;
2012 -- A list containing the entities of all the items processed so far. It
2013 -- plays a role in detecting distinct entities.
2014
2015 States_Seen : Elist_Id := No_Elist;
2016 -- A list containing the entities of all states processed so far. It
2017 -- helps in detecting illegal usage of a state and a corresponding
2018 -- constituent in pragma [Refined_]Global.
2019
2020 In_Out_Seen : Boolean := False;
2021 Input_Seen : Boolean := False;
2022 Output_Seen : Boolean := False;
2023 Proof_Seen : Boolean := False;
2024 -- Flags used to verify the consistency of modes
2025
2026 procedure Analyze_Global_List
2027 (List : Node_Id;
2028 Global_Mode : Name_Id := Name_Input);
2029 -- Verify the legality of a single global list declaration. Global_Mode
2030 -- denotes the current mode in effect.
2031
2032 -------------------------
2033 -- Analyze_Global_List --
2034 -------------------------
2035
2036 procedure Analyze_Global_List
2037 (List : Node_Id;
2038 Global_Mode : Name_Id := Name_Input)
2039 is
2040 procedure Analyze_Global_Item
2041 (Item : Node_Id;
2042 Global_Mode : Name_Id);
2043 -- Verify the legality of a single global item declaration denoted by
2044 -- Item. Global_Mode denotes the current mode in effect.
2045
2046 procedure Check_Duplicate_Mode
2047 (Mode : Node_Id;
2048 Status : in out Boolean);
2049 -- Flag Status denotes whether a particular mode has been seen while
2050 -- processing a global list. This routine verifies that Mode is not a
2051 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2052
2053 procedure Check_Mode_Restriction_In_Enclosing_Context
2054 (Item : Node_Id;
2055 Item_Id : Entity_Id);
2056 -- Verify that an item of mode In_Out or Output does not appear as an
2057 -- input in the Global aspect of an enclosing subprogram. If this is
2058 -- the case, emit an error. Item and Item_Id are respectively the
2059 -- item and its entity.
2060
2061 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
2062 -- Mode denotes either In_Out or Output. Depending on the kind of the
2063 -- related subprogram, emit an error if those two modes apply to a
2064 -- function (SPARK RM 6.1.4(10)).
2065
2066 -------------------------
2067 -- Analyze_Global_Item --
2068 -------------------------
2069
2070 procedure Analyze_Global_Item
2071 (Item : Node_Id;
2072 Global_Mode : Name_Id)
2073 is
2074 Item_Id : Entity_Id;
2075
2076 begin
2077 -- Detect one of the following cases
2078
2079 -- with Global => (null, Name)
2080 -- with Global => (Name_1, null, Name_2)
2081 -- with Global => (Name, null)
2082
2083 if Nkind (Item) = N_Null then
2084 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
2085 return;
2086 end if;
2087
2088 Analyze (Item);
2089 Resolve_State (Item);
2090
2091 -- Find the entity of the item. If this is a renaming, climb the
2092 -- renaming chain to reach the root object. Renamings of non-
2093 -- entire objects do not yield an entity (Empty).
2094
2095 Item_Id := Entity_Of (Item);
2096
2097 if Present (Item_Id) then
2098
2099 -- A global item may denote a formal parameter of an enclosing
2100 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2101 -- provide a better error diagnostic.
2102
2103 if Is_Formal (Item_Id) then
2104 if Scope (Item_Id) = Spec_Id then
2105 SPARK_Msg_NE
2106 (Fix_Msg (Spec_Id, "global item cannot reference "
2107 & "parameter of subprogram &"), Item, Spec_Id);
2108 return;
2109 end if;
2110
2111 -- A global item may denote a concurrent type as long as it is
2112 -- the current instance of an enclosing protected or task type
2113 -- (SPARK RM 6.1.4).
2114
2115 elsif Ekind_In (Item_Id, E_Protected_Type, E_Task_Type) then
2116 if Is_CCT_Instance (Item_Id, Spec_Id) then
2117
2118 -- Pragma [Refined_]Global associated with a protected
2119 -- subprogram cannot mention the current instance of a
2120 -- protected type because the instance behaves as a
2121 -- formal parameter.
2122
2123 if Ekind (Item_Id) = E_Protected_Type then
2124 Error_Msg_Name_1 := Chars (Item_Id);
2125 SPARK_Msg_NE
2126 (Fix_Msg (Spec_Id, "global item of subprogram & "
2127 & "cannot reference current instance of protected "
2128 & "type %"), Item, Spec_Id);
2129 return;
2130
2131 -- Pragma [Refined_]Global associated with a task type
2132 -- cannot mention the current instance of a task type
2133 -- because the instance behaves as a formal parameter.
2134
2135 else pragma Assert (Ekind (Item_Id) = E_Task_Type);
2136 Error_Msg_Name_1 := Chars (Item_Id);
2137 SPARK_Msg_NE
2138 (Fix_Msg (Spec_Id, "global item of subprogram & "
2139 & "cannot reference current instance of task type "
2140 & "%"), Item, Spec_Id);
2141 return;
2142 end if;
2143
2144 -- Otherwise the global item denotes a subtype mark that is
2145 -- not a current instance.
2146
2147 else
2148 SPARK_Msg_N
2149 ("invalid use of subtype mark in global list", Item);
2150 return;
2151 end if;
2152
2153 -- A global item may denote the anonymous object created for a
2154 -- single protected/task type as long as the current instance
2155 -- is the same single type (SPARK RM 6.1.4).
2156
2157 elsif Is_Single_Concurrent_Object (Item_Id)
2158 and then Is_CCT_Instance (Item_Id, Spec_Id)
2159 then
2160 -- Pragma [Refined_]Global associated with a protected
2161 -- subprogram cannot mention the current instance of a
2162 -- protected type because the instance behaves as a formal
2163 -- parameter.
2164
2165 if Is_Single_Protected_Object (Item_Id) then
2166 Error_Msg_Name_1 := Chars (Item_Id);
2167 SPARK_Msg_NE
2168 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2169 & "reference current instance of protected type %"),
2170 Item, Spec_Id);
2171 return;
2172
2173 -- Pragma [Refined_]Global associated with a task type
2174 -- cannot mention the current instance of a task type
2175 -- because the instance behaves as a formal parameter.
2176
2177 else pragma Assert (Is_Single_Task_Object (Item_Id));
2178 Error_Msg_Name_1 := Chars (Item_Id);
2179 SPARK_Msg_NE
2180 (Fix_Msg (Spec_Id, "global item of subprogram & cannot "
2181 & "reference current instance of task type %"),
2182 Item, Spec_Id);
2183 return;
2184 end if;
2185
2186 -- A formal object may act as a global item inside a generic
2187
2188 elsif Is_Formal_Object (Item_Id) then
2189 null;
2190
2191 -- The only legal references are those to abstract states,
2192 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2193
2194 elsif not Ekind_In (Item_Id, E_Abstract_State,
2195 E_Constant,
2196 E_Discriminant,
2197 E_Loop_Parameter,
2198 E_Variable)
2199 then
2200 SPARK_Msg_N
2201 ("global item must denote object, state or current "
2202 & "instance of concurrent type", Item);
2203 return;
2204 end if;
2205
2206 -- State related checks
2207
2208 if Ekind (Item_Id) = E_Abstract_State then
2209
2210 -- Package and subprogram bodies are instantiated
2211 -- individually in a separate compiler pass. Due to this
2212 -- mode of instantiation, the refinement of a state may
2213 -- no longer be visible when a subprogram body contract
2214 -- is instantiated. Since the generic template is legal,
2215 -- do not perform this check in the instance to circumvent
2216 -- this oddity.
2217
2218 if Is_Generic_Instance (Spec_Id) then
2219 null;
2220
2221 -- An abstract state with visible refinement cannot appear
2222 -- in pragma [Refined_]Global as its place must be taken by
2223 -- some of its constituents (SPARK RM 6.1.4(7)).
2224
2225 elsif Has_Visible_Refinement (Item_Id) then
2226 SPARK_Msg_NE
2227 ("cannot mention state & in global refinement",
2228 Item, Item_Id);
2229 SPARK_Msg_N ("\use its constituents instead", Item);
2230 return;
2231
2232 -- An external state cannot appear as a global item of a
2233 -- nonvolatile function (SPARK RM 7.1.3(8)).
2234
2235 elsif Is_External_State (Item_Id)
2236 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2237 and then not Is_Volatile_Function (Spec_Id)
2238 then
2239 SPARK_Msg_NE
2240 ("external state & cannot act as global item of "
2241 & "nonvolatile function", Item, Item_Id);
2242 return;
2243
2244 -- If the reference to the abstract state appears in an
2245 -- enclosing package body that will eventually refine the
2246 -- state, record the reference for future checks.
2247
2248 else
2249 Record_Possible_Body_Reference
2250 (State_Id => Item_Id,
2251 Ref => Item);
2252 end if;
2253
2254 -- Constant related checks
2255
2256 elsif Ekind (Item_Id) = E_Constant then
2257
2258 -- A constant is a read-only item, therefore it cannot act
2259 -- as an output.
2260
2261 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2262 SPARK_Msg_NE
2263 ("constant & cannot act as output", Item, Item_Id);
2264 return;
2265 end if;
2266
2267 -- Discriminant related checks
2268
2269 elsif Ekind (Item_Id) = E_Discriminant then
2270
2271 -- A discriminant is a read-only item, therefore it cannot
2272 -- act as an output.
2273
2274 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2275 SPARK_Msg_NE
2276 ("discriminant & cannot act as output", Item, Item_Id);
2277 return;
2278 end if;
2279
2280 -- Loop parameter related checks
2281
2282 elsif Ekind (Item_Id) = E_Loop_Parameter then
2283
2284 -- A loop parameter is a read-only item, therefore it cannot
2285 -- act as an output.
2286
2287 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2288 SPARK_Msg_NE
2289 ("loop parameter & cannot act as output",
2290 Item, Item_Id);
2291 return;
2292 end if;
2293
2294 -- Variable related checks. These are only relevant when
2295 -- SPARK_Mode is on as they are not standard Ada legality
2296 -- rules.
2297
2298 elsif SPARK_Mode = On
2299 and then Ekind (Item_Id) = E_Variable
2300 and then Is_Effectively_Volatile (Item_Id)
2301 then
2302 -- An effectively volatile object cannot appear as a global
2303 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2304
2305 if Ekind_In (Spec_Id, E_Function, E_Generic_Function)
2306 and then not Is_Volatile_Function (Spec_Id)
2307 then
2308 Error_Msg_NE
2309 ("volatile object & cannot act as global item of a "
2310 & "function", Item, Item_Id);
2311 return;
2312
2313 -- An effectively volatile object with external property
2314 -- Effective_Reads set to True must have mode Output or
2315 -- In_Out (SPARK RM 7.1.3(10)).
2316
2317 elsif Effective_Reads_Enabled (Item_Id)
2318 and then Global_Mode = Name_Input
2319 then
2320 Error_Msg_NE
2321 ("volatile object & with property Effective_Reads must "
2322 & "have mode In_Out or Output", Item, Item_Id);
2323 return;
2324 end if;
2325 end if;
2326
2327 -- When the item renames an entire object, replace the item
2328 -- with a reference to the object.
2329
2330 if Entity (Item) /= Item_Id then
2331 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2332 Analyze (Item);
2333 end if;
2334
2335 -- Some form of illegal construct masquerading as a name
2336 -- (SPARK RM 6.1.4(4)).
2337
2338 else
2339 Error_Msg_N
2340 ("global item must denote object, state or current instance "
2341 & "of concurrent type", Item);
2342 return;
2343 end if;
2344
2345 -- Verify that an output does not appear as an input in an
2346 -- enclosing subprogram.
2347
2348 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2349 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2350 end if;
2351
2352 -- The same entity might be referenced through various way.
2353 -- Check the entity of the item rather than the item itself
2354 -- (SPARK RM 6.1.4(10)).
2355
2356 if Contains (Seen, Item_Id) then
2357 SPARK_Msg_N ("duplicate global item", Item);
2358
2359 -- Add the entity of the current item to the list of processed
2360 -- items.
2361
2362 else
2363 Append_New_Elmt (Item_Id, Seen);
2364
2365 if Ekind (Item_Id) = E_Abstract_State then
2366 Append_New_Elmt (Item_Id, States_Seen);
2367
2368 -- The variable may eventually become a constituent of a single
2369 -- protected/task type. Record the reference now and verify its
2370 -- legality when analyzing the contract of the variable
2371 -- (SPARK RM 9.3).
2372
2373 elsif Ekind (Item_Id) = E_Variable then
2374 Record_Possible_Part_Of_Reference
2375 (Var_Id => Item_Id,
2376 Ref => Item);
2377 end if;
2378
2379 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
2380 and then Present (Encapsulating_State (Item_Id))
2381 then
2382 Append_New_Elmt (Item_Id, Constits_Seen);
2383 end if;
2384 end if;
2385 end Analyze_Global_Item;
2386
2387 --------------------------
2388 -- Check_Duplicate_Mode --
2389 --------------------------
2390
2391 procedure Check_Duplicate_Mode
2392 (Mode : Node_Id;
2393 Status : in out Boolean)
2394 is
2395 begin
2396 if Status then
2397 SPARK_Msg_N ("duplicate global mode", Mode);
2398 end if;
2399
2400 Status := True;
2401 end Check_Duplicate_Mode;
2402
2403 -------------------------------------------------
2404 -- Check_Mode_Restriction_In_Enclosing_Context --
2405 -------------------------------------------------
2406
2407 procedure Check_Mode_Restriction_In_Enclosing_Context
2408 (Item : Node_Id;
2409 Item_Id : Entity_Id)
2410 is
2411 Context : Entity_Id;
2412 Dummy : Boolean;
2413 Inputs : Elist_Id := No_Elist;
2414 Outputs : Elist_Id := No_Elist;
2415
2416 begin
2417 -- Traverse the scope stack looking for enclosing subprograms
2418 -- subject to pragma [Refined_]Global.
2419
2420 Context := Scope (Subp_Id);
2421 while Present (Context) and then Context /= Standard_Standard loop
2422 if Is_Subprogram (Context)
2423 and then
2424 (Present (Get_Pragma (Context, Pragma_Global))
2425 or else
2426 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2427 then
2428 Collect_Subprogram_Inputs_Outputs
2429 (Subp_Id => Context,
2430 Subp_Inputs => Inputs,
2431 Subp_Outputs => Outputs,
2432 Global_Seen => Dummy);
2433
2434 -- The item is classified as In_Out or Output but appears as
2435 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2436
2437 if Appears_In (Inputs, Item_Id)
2438 and then not Appears_In (Outputs, Item_Id)
2439 then
2440 SPARK_Msg_NE
2441 ("global item & cannot have mode In_Out or Output",
2442 Item, Item_Id);
2443
2444 SPARK_Msg_NE
2445 (Fix_Msg (Subp_Id, "\item already appears as input of "
2446 & "subprogram &"), Item, Context);
2447
2448 -- Stop the traversal once an error has been detected
2449
2450 exit;
2451 end if;
2452 end if;
2453
2454 Context := Scope (Context);
2455 end loop;
2456 end Check_Mode_Restriction_In_Enclosing_Context;
2457
2458 ----------------------------------------
2459 -- Check_Mode_Restriction_In_Function --
2460 ----------------------------------------
2461
2462 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2463 begin
2464 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2465 SPARK_Msg_N
2466 ("global mode & is not applicable to functions", Mode);
2467 end if;
2468 end Check_Mode_Restriction_In_Function;
2469
2470 -- Local variables
2471
2472 Assoc : Node_Id;
2473 Item : Node_Id;
2474 Mode : Node_Id;
2475
2476 -- Start of processing for Analyze_Global_List
2477
2478 begin
2479 if Nkind (List) = N_Null then
2480 Set_Analyzed (List);
2481
2482 -- Single global item declaration
2483
2484 elsif Nkind_In (List, N_Expanded_Name,
2485 N_Identifier,
2486 N_Selected_Component)
2487 then
2488 Analyze_Global_Item (List, Global_Mode);
2489
2490 -- Simple global list or moded global list declaration
2491
2492 elsif Nkind (List) = N_Aggregate then
2493 Set_Analyzed (List);
2494
2495 -- The declaration of a simple global list appear as a collection
2496 -- of expressions.
2497
2498 if Present (Expressions (List)) then
2499 if Present (Component_Associations (List)) then
2500 SPARK_Msg_N
2501 ("cannot mix moded and non-moded global lists", List);
2502 end if;
2503
2504 Item := First (Expressions (List));
2505 while Present (Item) loop
2506 Analyze_Global_Item (Item, Global_Mode);
2507 Next (Item);
2508 end loop;
2509
2510 -- The declaration of a moded global list appears as a collection
2511 -- of component associations where individual choices denote
2512 -- modes.
2513
2514 elsif Present (Component_Associations (List)) then
2515 if Present (Expressions (List)) then
2516 SPARK_Msg_N
2517 ("cannot mix moded and non-moded global lists", List);
2518 end if;
2519
2520 Assoc := First (Component_Associations (List));
2521 while Present (Assoc) loop
2522 Mode := First (Choices (Assoc));
2523
2524 if Nkind (Mode) = N_Identifier then
2525 if Chars (Mode) = Name_In_Out then
2526 Check_Duplicate_Mode (Mode, In_Out_Seen);
2527 Check_Mode_Restriction_In_Function (Mode);
2528
2529 elsif Chars (Mode) = Name_Input then
2530 Check_Duplicate_Mode (Mode, Input_Seen);
2531
2532 elsif Chars (Mode) = Name_Output then
2533 Check_Duplicate_Mode (Mode, Output_Seen);
2534 Check_Mode_Restriction_In_Function (Mode);
2535
2536 elsif Chars (Mode) = Name_Proof_In then
2537 Check_Duplicate_Mode (Mode, Proof_Seen);
2538
2539 else
2540 SPARK_Msg_N ("invalid mode selector", Mode);
2541 end if;
2542
2543 else
2544 SPARK_Msg_N ("invalid mode selector", Mode);
2545 end if;
2546
2547 -- Items in a moded list appear as a collection of
2548 -- expressions. Reuse the existing machinery to analyze
2549 -- them.
2550
2551 Analyze_Global_List
2552 (List => Expression (Assoc),
2553 Global_Mode => Chars (Mode));
2554
2555 Next (Assoc);
2556 end loop;
2557
2558 -- Invalid tree
2559
2560 else
2561 raise Program_Error;
2562 end if;
2563
2564 -- Any other attempt to declare a global item is illegal. This is a
2565 -- syntax error, always report.
2566
2567 else
2568 Error_Msg_N ("malformed global list", List);
2569 end if;
2570 end Analyze_Global_List;
2571
2572 -- Local variables
2573
2574 Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
2575
2576 Restore_Scope : Boolean := False;
2577
2578 -- Start of processing for Analyze_Global_In_Decl_Part
2579
2580 begin
2581 -- Do not analyze the pragma multiple times
2582
2583 if Is_Analyzed_Pragma (N) then
2584 return;
2585 end if;
2586
2587 -- There is nothing to be done for a null global list
2588
2589 if Nkind (Items) = N_Null then
2590 Set_Analyzed (Items);
2591
2592 -- Analyze the various forms of global lists and items. Note that some
2593 -- of these may be malformed in which case the analysis emits error
2594 -- messages.
2595
2596 else
2597 -- When pragma [Refined_]Global appears on a single concurrent type,
2598 -- it is relocated to the anonymous object.
2599
2600 if Is_Single_Concurrent_Object (Spec_Id) then
2601 null;
2602
2603 -- Ensure that the formal parameters are visible when processing an
2604 -- item. This falls out of the general rule of aspects pertaining to
2605 -- subprogram declarations.
2606
2607 elsif not In_Open_Scopes (Spec_Id) then
2608 Restore_Scope := True;
2609 Push_Scope (Spec_Id);
2610
2611 if Ekind (Spec_Id) = E_Task_Type then
2612 if Has_Discriminants (Spec_Id) then
2613 Install_Discriminants (Spec_Id);
2614 end if;
2615
2616 elsif Is_Generic_Subprogram (Spec_Id) then
2617 Install_Generic_Formals (Spec_Id);
2618
2619 else
2620 Install_Formals (Spec_Id);
2621 end if;
2622 end if;
2623
2624 Analyze_Global_List (Items);
2625
2626 if Restore_Scope then
2627 End_Scope;
2628 end if;
2629 end if;
2630
2631 -- Ensure that a state and a corresponding constituent do not appear
2632 -- together in pragma [Refined_]Global.
2633
2634 Check_State_And_Constituent_Use
2635 (States => States_Seen,
2636 Constits => Constits_Seen,
2637 Context => N);
2638
2639 Set_Is_Analyzed_Pragma (N);
2640 end Analyze_Global_In_Decl_Part;
2641
2642 --------------------------------------------
2643 -- Analyze_Initial_Condition_In_Decl_Part --
2644 --------------------------------------------
2645
2646 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2647 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2648 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2649 Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
2650
2651 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
2652
2653 begin
2654 -- Do not analyze the pragma multiple times
2655
2656 if Is_Analyzed_Pragma (N) then
2657 return;
2658 end if;
2659
2660 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2661 -- analysis of the pragma, the Ghost mode at point of declaration and
2662 -- point of analysis may not necessarily be the same. Use the mode in
2663 -- effect at the point of declaration.
2664
2665 Set_Ghost_Mode (N);
2666
2667 -- The expression is preanalyzed because it has not been moved to its
2668 -- final place yet. A direct analysis may generate side effects and this
2669 -- is not desired at this point.
2670
2671 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
2672 Ghost_Mode := Save_Ghost_Mode;
2673
2674 Set_Is_Analyzed_Pragma (N);
2675 end Analyze_Initial_Condition_In_Decl_Part;
2676
2677 --------------------------------------
2678 -- Analyze_Initializes_In_Decl_Part --
2679 --------------------------------------
2680
2681 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2682 Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
2683 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
2684
2685 Constits_Seen : Elist_Id := No_Elist;
2686 -- A list containing the entities of all constituents processed so far.
2687 -- It aids in detecting illegal usage of a state and a corresponding
2688 -- constituent in pragma Initializes.
2689
2690 Items_Seen : Elist_Id := No_Elist;
2691 -- A list of all initialization items processed so far. This list is
2692 -- used to detect duplicate items.
2693
2694 Non_Null_Seen : Boolean := False;
2695 Null_Seen : Boolean := False;
2696 -- Flags used to check the legality of a null initialization list
2697
2698 States_And_Objs : Elist_Id := No_Elist;
2699 -- A list of all abstract states and objects declared in the visible
2700 -- declarations of the related package. This list is used to detect the
2701 -- legality of initialization items.
2702
2703 States_Seen : Elist_Id := No_Elist;
2704 -- A list containing the entities of all states processed so far. It
2705 -- helps in detecting illegal usage of a state and a corresponding
2706 -- constituent in pragma Initializes.
2707
2708 procedure Analyze_Initialization_Item (Item : Node_Id);
2709 -- Verify the legality of a single initialization item
2710
2711 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2712 -- Verify the legality of a single initialization item followed by a
2713 -- list of input items.
2714
2715 procedure Collect_States_And_Objects;
2716 -- Inspect the visible declarations of the related package and gather
2717 -- the entities of all abstract states and objects in States_And_Objs.
2718
2719 ---------------------------------
2720 -- Analyze_Initialization_Item --
2721 ---------------------------------
2722
2723 procedure Analyze_Initialization_Item (Item : Node_Id) is
2724 Item_Id : Entity_Id;
2725
2726 begin
2727 -- Null initialization list
2728
2729 if Nkind (Item) = N_Null then
2730 if Null_Seen then
2731 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2732
2733 elsif Non_Null_Seen then
2734 SPARK_Msg_N
2735 ("cannot mix null and non-null initialization items", Item);
2736 else
2737 Null_Seen := True;
2738 end if;
2739
2740 -- Initialization item
2741
2742 else
2743 Non_Null_Seen := True;
2744
2745 if Null_Seen then
2746 SPARK_Msg_N
2747 ("cannot mix null and non-null initialization items", Item);
2748 end if;
2749
2750 Analyze (Item);
2751 Resolve_State (Item);
2752
2753 if Is_Entity_Name (Item) then
2754 Item_Id := Entity_Of (Item);
2755
2756 if Ekind_In (Item_Id, E_Abstract_State,
2757 E_Constant,
2758 E_Variable)
2759 then
2760 -- The state or variable must be declared in the visible
2761 -- declarations of the package (SPARK RM 7.1.5(7)).
2762
2763 if not Contains (States_And_Objs, Item_Id) then
2764 Error_Msg_Name_1 := Chars (Pack_Id);
2765 SPARK_Msg_NE
2766 ("initialization item & must appear in the visible "
2767 & "declarations of package %", Item, Item_Id);
2768
2769 -- Detect a duplicate use of the same initialization item
2770 -- (SPARK RM 7.1.5(5)).
2771
2772 elsif Contains (Items_Seen, Item_Id) then
2773 SPARK_Msg_N ("duplicate initialization item", Item);
2774
2775 -- The item is legal, add it to the list of processed states
2776 -- and variables.
2777
2778 else
2779 Append_New_Elmt (Item_Id, Items_Seen);
2780
2781 if Ekind (Item_Id) = E_Abstract_State then
2782 Append_New_Elmt (Item_Id, States_Seen);
2783 end if;
2784
2785 if Present (Encapsulating_State (Item_Id)) then
2786 Append_New_Elmt (Item_Id, Constits_Seen);
2787 end if;
2788 end if;
2789
2790 -- The item references something that is not a state or object
2791 -- (SPARK RM 7.1.5(3)).
2792
2793 else
2794 SPARK_Msg_N
2795 ("initialization item must denote object or state", Item);
2796 end if;
2797
2798 -- Some form of illegal construct masquerading as a name
2799 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2800
2801 else
2802 Error_Msg_N
2803 ("initialization item must denote object or state", Item);
2804 end if;
2805 end if;
2806 end Analyze_Initialization_Item;
2807
2808 ---------------------------------------------
2809 -- Analyze_Initialization_Item_With_Inputs --
2810 ---------------------------------------------
2811
2812 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2813 Inputs_Seen : Elist_Id := No_Elist;
2814 -- A list of all inputs processed so far. This list is used to detect
2815 -- duplicate uses of an input.
2816
2817 Non_Null_Seen : Boolean := False;
2818 Null_Seen : Boolean := False;
2819 -- Flags used to check the legality of an input list
2820
2821 procedure Analyze_Input_Item (Input : Node_Id);
2822 -- Verify the legality of a single input item
2823
2824 ------------------------
2825 -- Analyze_Input_Item --
2826 ------------------------
2827
2828 procedure Analyze_Input_Item (Input : Node_Id) is
2829 Input_Id : Entity_Id;
2830 Input_OK : Boolean := True;
2831
2832 begin
2833 -- Null input list
2834
2835 if Nkind (Input) = N_Null then
2836 if Null_Seen then
2837 SPARK_Msg_N
2838 ("multiple null initializations not allowed", Item);
2839
2840 elsif Non_Null_Seen then
2841 SPARK_Msg_N
2842 ("cannot mix null and non-null initialization item", Item);
2843 else
2844 Null_Seen := True;
2845 end if;
2846
2847 -- Input item
2848
2849 else
2850 Non_Null_Seen := True;
2851
2852 if Null_Seen then
2853 SPARK_Msg_N
2854 ("cannot mix null and non-null initialization item", Item);
2855 end if;
2856
2857 Analyze (Input);
2858 Resolve_State (Input);
2859
2860 if Is_Entity_Name (Input) then
2861 Input_Id := Entity_Of (Input);
2862
2863 if Ekind_In (Input_Id, E_Abstract_State,
2864 E_Constant,
2865 E_Generic_In_Out_Parameter,
2866 E_Generic_In_Parameter,
2867 E_In_Parameter,
2868 E_In_Out_Parameter,
2869 E_Out_Parameter,
2870 E_Variable)
2871 then
2872 -- The input cannot denote states or objects declared
2873 -- within the related package (SPARK RM 7.1.5(4)).
2874
2875 if Within_Scope (Input_Id, Current_Scope) then
2876
2877 -- Do not consider generic formal parameters or their
2878 -- respective mappings to generic formals. Even though
2879 -- the formals appear within the scope of the package,
2880 -- it is allowed for an initialization item to depend
2881 -- on an input item.
2882
2883 if Ekind_In (Input_Id, E_Generic_In_Out_Parameter,
2884 E_Generic_In_Parameter)
2885 then
2886 null;
2887
2888 elsif Ekind_In (Input_Id, E_Constant, E_Variable)
2889 and then Present (Corresponding_Generic_Association
2890 (Declaration_Node (Input_Id)))
2891 then
2892 null;
2893
2894 else
2895 Input_OK := False;
2896 Error_Msg_Name_1 := Chars (Pack_Id);
2897 SPARK_Msg_NE
2898 ("input item & cannot denote a visible object or "
2899 & "state of package %", Input, Input_Id);
2900 end if;
2901 end if;
2902
2903 -- Detect a duplicate use of the same input item
2904 -- (SPARK RM 7.1.5(5)).
2905
2906 if Contains (Inputs_Seen, Input_Id) then
2907 Input_OK := False;
2908 SPARK_Msg_N ("duplicate input item", Input);
2909 end if;
2910
2911 -- Input is legal, add it to the list of processed inputs
2912
2913 if Input_OK then
2914 Append_New_Elmt (Input_Id, Inputs_Seen);
2915
2916 if Ekind (Input_Id) = E_Abstract_State then
2917 Append_New_Elmt (Input_Id, States_Seen);
2918 end if;
2919
2920 if Ekind_In (Input_Id, E_Abstract_State,
2921 E_Constant,
2922 E_Variable)
2923 and then Present (Encapsulating_State (Input_Id))
2924 then
2925 Append_New_Elmt (Input_Id, Constits_Seen);
2926 end if;
2927 end if;
2928
2929 -- The input references something that is not a state or an
2930 -- object (SPARK RM 7.1.5(3)).
2931
2932 else
2933 SPARK_Msg_N
2934 ("input item must denote object or state", Input);
2935 end if;
2936
2937 -- Some form of illegal construct masquerading as a name
2938 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2939
2940 else
2941 Error_Msg_N
2942 ("input item must denote object or state", Input);
2943 end if;
2944 end if;
2945 end Analyze_Input_Item;
2946
2947 -- Local variables
2948
2949 Inputs : constant Node_Id := Expression (Item);
2950 Elmt : Node_Id;
2951 Input : Node_Id;
2952
2953 Name_Seen : Boolean := False;
2954 -- A flag used to detect multiple item names
2955
2956 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2957
2958 begin
2959 -- Inspect the name of an item with inputs
2960
2961 Elmt := First (Choices (Item));
2962 while Present (Elmt) loop
2963 if Name_Seen then
2964 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2965 else
2966 Name_Seen := True;
2967 Analyze_Initialization_Item (Elmt);
2968 end if;
2969
2970 Next (Elmt);
2971 end loop;
2972
2973 -- Multiple input items appear as an aggregate
2974
2975 if Nkind (Inputs) = N_Aggregate then
2976 if Present (Expressions (Inputs)) then
2977 Input := First (Expressions (Inputs));
2978 while Present (Input) loop
2979 Analyze_Input_Item (Input);
2980 Next (Input);
2981 end loop;
2982 end if;
2983
2984 if Present (Component_Associations (Inputs)) then
2985 SPARK_Msg_N
2986 ("inputs must appear in named association form", Inputs);
2987 end if;
2988
2989 -- Single input item
2990
2991 else
2992 Analyze_Input_Item (Inputs);
2993 end if;
2994 end Analyze_Initialization_Item_With_Inputs;
2995
2996 --------------------------------
2997 -- Collect_States_And_Objects --
2998 --------------------------------
2999
3000 procedure Collect_States_And_Objects is
3001 Pack_Spec : constant Node_Id := Specification (Pack_Decl);
3002 Decl : Node_Id;
3003
3004 begin
3005 -- Collect the abstract states defined in the package (if any)
3006
3007 if Present (Abstract_States (Pack_Id)) then
3008 States_And_Objs := New_Copy_Elist (Abstract_States (Pack_Id));
3009 end if;
3010
3011 -- Collect all objects the appear in the visible declarations of the
3012 -- related package.
3013
3014 if Present (Visible_Declarations (Pack_Spec)) then
3015 Decl := First (Visible_Declarations (Pack_Spec));
3016 while Present (Decl) loop
3017 if Comes_From_Source (Decl)
3018 and then Nkind (Decl) = N_Object_Declaration
3019 then
3020 Append_New_Elmt (Defining_Entity (Decl), States_And_Objs);
3021 end if;
3022
3023 Next (Decl);
3024 end loop;
3025 end if;
3026 end Collect_States_And_Objects;
3027
3028 -- Local variables
3029
3030 Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id));
3031 Init : Node_Id;
3032
3033 -- Start of processing for Analyze_Initializes_In_Decl_Part
3034
3035 begin
3036 -- Do not analyze the pragma multiple times
3037
3038 if Is_Analyzed_Pragma (N) then
3039 return;
3040 end if;
3041
3042 -- Nothing to do when the initialization list is empty
3043
3044 if Nkind (Inits) = N_Null then
3045 return;
3046 end if;
3047
3048 -- Single and multiple initialization clauses appear as an aggregate. If
3049 -- this is not the case, then either the parser or the analysis of the
3050 -- pragma failed to produce an aggregate.
3051
3052 pragma Assert (Nkind (Inits) = N_Aggregate);
3053
3054 -- Initialize the various lists used during analysis
3055
3056 Collect_States_And_Objects;
3057
3058 if Present (Expressions (Inits)) then
3059 Init := First (Expressions (Inits));
3060 while Present (Init) loop
3061 Analyze_Initialization_Item (Init);
3062 Next (Init);
3063 end loop;
3064 end if;
3065
3066 if Present (Component_Associations (Inits)) then
3067 Init := First (Component_Associations (Inits));
3068 while Present (Init) loop
3069 Analyze_Initialization_Item_With_Inputs (Init);
3070 Next (Init);
3071 end loop;
3072 end if;
3073
3074 -- Ensure that a state and a corresponding constituent do not appear
3075 -- together in pragma Initializes.
3076
3077 Check_State_And_Constituent_Use
3078 (States => States_Seen,
3079 Constits => Constits_Seen,
3080 Context => N);
3081
3082 Set_Is_Analyzed_Pragma (N);
3083 end Analyze_Initializes_In_Decl_Part;
3084
3085 ---------------------
3086 -- Analyze_Part_Of --
3087 ---------------------
3088
3089 procedure Analyze_Part_Of
3090 (Indic : Node_Id;
3091 Item_Id : Entity_Id;
3092 Encap : Node_Id;
3093 Encap_Id : out Entity_Id;
3094 Legal : out Boolean)
3095 is
3096 Encap_Typ : Entity_Id;
3097 Item_Decl : Node_Id;
3098 Pack_Id : Entity_Id;
3099 Placement : State_Space_Kind;
3100 Parent_Unit : Entity_Id;
3101
3102 begin
3103 -- Assume that the indicator is illegal
3104
3105 Encap_Id := Empty;
3106 Legal := False;
3107
3108 if Nkind_In (Encap, N_Expanded_Name,
3109 N_Identifier,
3110 N_Selected_Component)
3111 then
3112 Analyze (Encap);
3113 Resolve_State (Encap);
3114
3115 Encap_Id := Entity (Encap);
3116
3117 -- The encapsulator is an abstract state
3118
3119 if Ekind (Encap_Id) = E_Abstract_State then
3120 null;
3121
3122 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3123
3124 elsif Is_Single_Concurrent_Object (Encap_Id) then
3125 null;
3126
3127 -- Otherwise the encapsulator is not a legal choice
3128
3129 else
3130 SPARK_Msg_N
3131 ("indicator Part_Of must denote abstract state, single "
3132 & "protected type or single task type", Encap);
3133 return;
3134 end if;
3135
3136 -- This is a syntax error, always report
3137
3138 else
3139 Error_Msg_N
3140 ("indicator Part_Of must denote abstract state, single protected "
3141 & "type or single task type", Encap);
3142 return;
3143 end if;
3144
3145 -- Catch a case where indicator Part_Of denotes the abstract view of a
3146 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3147
3148 if From_Limited_With (Encap_Id)
3149 and then Present (Non_Limited_View (Encap_Id))
3150 and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable
3151 then
3152 SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap);
3153 SPARK_Msg_N ("\& denotes abstract view of object", Encap);
3154 return;
3155 end if;
3156
3157 -- The encapsulator is an abstract state
3158
3159 if Ekind (Encap_Id) = E_Abstract_State then
3160
3161 -- Determine where the object, package instantiation or state lives
3162 -- with respect to the enclosing packages or package bodies.
3163
3164 Find_Placement_In_State_Space
3165 (Item_Id => Item_Id,
3166 Placement => Placement,
3167 Pack_Id => Pack_Id);
3168
3169 -- The item appears in a non-package construct with a declarative
3170 -- part (subprogram, block, etc). As such, the item is not allowed
3171 -- to be a part of an encapsulating state because the item is not
3172 -- visible.
3173
3174 if Placement = Not_In_Package then
3175 SPARK_Msg_N
3176 ("indicator Part_Of cannot appear in this context "
3177 & "(SPARK RM 7.2.6(5))", Indic);
3178 Error_Msg_Name_1 := Chars (Scope (Encap_Id));
3179 SPARK_Msg_NE
3180 ("\& is not part of the hidden state of package %",
3181 Indic, Item_Id);
3182
3183 -- The item appears in the visible state space of some package. In
3184 -- general this scenario does not warrant Part_Of except when the
3185 -- package is a private child unit and the encapsulating state is
3186 -- declared in a parent unit or a public descendant of that parent
3187 -- unit.
3188
3189 elsif Placement = Visible_State_Space then
3190 if Is_Child_Unit (Pack_Id)
3191 and then Is_Private_Descendant (Pack_Id)
3192 then
3193 -- A variable or state abstraction which is part of the visible
3194 -- state of a private child unit (or one of its public
3195 -- descendants) must have its Part_Of indicator specified. The
3196 -- Part_Of indicator must denote a state abstraction declared
3197 -- by either the parent unit of the private unit or by a public
3198 -- descendant of that parent unit.
3199
3200 -- Find nearest private ancestor (which can be the current unit
3201 -- itself).
3202
3203 Parent_Unit := Pack_Id;
3204 while Present (Parent_Unit) loop
3205 exit when
3206 Private_Present
3207 (Parent (Unit_Declaration_Node (Parent_Unit)));
3208 Parent_Unit := Scope (Parent_Unit);
3209 end loop;
3210
3211 Parent_Unit := Scope (Parent_Unit);
3212
3213 if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then
3214 SPARK_Msg_NE
3215 ("indicator Part_Of must denote abstract state or public "
3216 & "descendant of & (SPARK RM 7.2.6(3))",
3217 Indic, Parent_Unit);
3218
3219 elsif Scope (Encap_Id) = Parent_Unit
3220 or else
3221 (Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id))
3222 and then not Is_Private_Descendant (Scope (Encap_Id)))
3223 then
3224 null;
3225
3226 else
3227 SPARK_Msg_NE
3228 ("indicator Part_Of must denote abstract state or public "
3229 & "descendant of & (SPARK RM 7.2.6(3))",
3230 Indic, Parent_Unit);
3231 end if;
3232
3233 -- Indicator Part_Of is not needed when the related package is not
3234 -- a private child unit or a public descendant thereof.
3235
3236 else
3237 SPARK_Msg_N
3238 ("indicator Part_Of cannot appear in this context "
3239 & "(SPARK RM 7.2.6(5))", Indic);
3240 Error_Msg_Name_1 := Chars (Pack_Id);
3241 SPARK_Msg_NE
3242 ("\& is declared in the visible part of package %",
3243 Indic, Item_Id);
3244 end if;
3245
3246 -- When the item appears in the private state space of a package, the
3247 -- encapsulating state must be declared in the same package.
3248
3249 elsif Placement = Private_State_Space then
3250 if Scope (Encap_Id) /= Pack_Id then
3251 SPARK_Msg_NE
3252 ("indicator Part_Of must designate an abstract state of "
3253 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3254 Error_Msg_Name_1 := Chars (Pack_Id);
3255 SPARK_Msg_NE
3256 ("\& is declared in the private part of package %",
3257 Indic, Item_Id);
3258 end if;
3259
3260 -- Items declared in the body state space of a package do not need
3261 -- Part_Of indicators as the refinement has already been seen.
3262
3263 else
3264 SPARK_Msg_N
3265 ("indicator Part_Of cannot appear in this context "
3266 & "(SPARK RM 7.2.6(5))", Indic);
3267
3268 if Scope (Encap_Id) = Pack_Id then
3269 Error_Msg_Name_1 := Chars (Pack_Id);
3270 SPARK_Msg_NE
3271 ("\& is declared in the body of package %", Indic, Item_Id);
3272 end if;
3273 end if;
3274
3275 -- The encapsulator is a single concurrent type
3276
3277 else
3278 Encap_Typ := Etype (Encap_Id);
3279
3280 -- Only abstract states and variables can act as constituents of an
3281 -- encapsulating single concurrent type.
3282
3283 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
3284 null;
3285
3286 -- The constituent is a constant
3287
3288 elsif Ekind (Item_Id) = E_Constant then
3289 Error_Msg_Name_1 := Chars (Encap_Id);
3290 SPARK_Msg_NE
3291 (Fix_Msg (Encap_Typ, "consant & cannot act as constituent of "
3292 & "single protected type %"), Indic, Item_Id);
3293
3294 -- The constituent is a package instantiation
3295
3296 else
3297 Error_Msg_Name_1 := Chars (Encap_Id);
3298 SPARK_Msg_NE
3299 (Fix_Msg (Encap_Typ, "package instantiation & cannot act as "
3300 & "constituent of single protected type %"), Indic, Item_Id);
3301 end if;
3302
3303 -- When the item denotes an abstract state of a nested package, use
3304 -- the declaration of the package to detect proper placement.
3305
3306 -- package Pack is
3307 -- task T;
3308 -- package Nested
3309 -- with Abstract_State => (State with Part_Of => T)
3310
3311 if Ekind (Item_Id) = E_Abstract_State then
3312 Item_Decl := Unit_Declaration_Node (Scope (Item_Id));
3313 else
3314 Item_Decl := Declaration_Node (Item_Id);
3315 end if;
3316
3317 -- Both the item and its encapsulating single concurrent type must
3318 -- appear in the same declarative region (SPARK RM 9.3). Note that
3319 -- privacy is ignored.
3320
3321 if Parent (Item_Decl) /= Parent (Declaration_Node (Encap_Id)) then
3322 Error_Msg_Name_1 := Chars (Encap_Id);
3323 SPARK_Msg_NE
3324 (Fix_Msg (Encap_Typ, "constituent & must be declared "
3325 & "immediately within the same region as single protected "
3326 & "type %"), Indic, Item_Id);
3327 end if;
3328 end if;
3329
3330 Legal := True;
3331 end Analyze_Part_Of;
3332
3333 ----------------------------------
3334 -- Analyze_Part_Of_In_Decl_Part --
3335 ----------------------------------
3336
3337 procedure Analyze_Part_Of_In_Decl_Part
3338 (N : Node_Id;
3339 Freeze_Id : Entity_Id := Empty)
3340 is
3341 Encap : constant Node_Id :=
3342 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
3343 Errors : constant Nat := Serious_Errors_Detected;
3344 Var_Decl : constant Node_Id := Find_Related_Context (N);
3345 Var_Id : constant Entity_Id := Defining_Entity (Var_Decl);
3346 Constits : Elist_Id;
3347 Encap_Id : Entity_Id;
3348 Legal : Boolean;
3349
3350 begin
3351 -- Detect any discrepancies between the placement of the variable with
3352 -- respect to general state space and the encapsulating state or single
3353 -- concurrent type.
3354
3355 Analyze_Part_Of
3356 (Indic => N,
3357 Item_Id => Var_Id,
3358 Encap => Encap,
3359 Encap_Id => Encap_Id,
3360 Legal => Legal);
3361
3362 -- The Part_Of indicator turns the variable into a constituent of the
3363 -- encapsulating state or single concurrent type.
3364
3365 if Legal then
3366 pragma Assert (Present (Encap_Id));
3367 Constits := Part_Of_Constituents (Encap_Id);
3368
3369 if No (Constits) then
3370 Constits := New_Elmt_List;
3371 Set_Part_Of_Constituents (Encap_Id, Constits);
3372 end if;
3373
3374 Append_Elmt (Var_Id, Constits);
3375 Set_Encapsulating_State (Var_Id, Encap_Id);
3376 end if;
3377
3378 -- Emit a clarification message when the encapsulator is undefined,
3379 -- possibly due to contract "freezing".
3380
3381 if Errors /= Serious_Errors_Detected
3382 and then Present (Freeze_Id)
3383 and then Has_Undefined_Reference (Encap)
3384 then
3385 Contract_Freeze_Error (Var_Id, Freeze_Id);
3386 end if;
3387 end Analyze_Part_Of_In_Decl_Part;
3388
3389 --------------------
3390 -- Analyze_Pragma --
3391 --------------------
3392
3393 procedure Analyze_Pragma (N : Node_Id) is
3394 Loc : constant Source_Ptr := Sloc (N);
3395 Prag_Id : Pragma_Id;
3396
3397 Pname : Name_Id;
3398 -- Name of the source pragma, or name of the corresponding aspect for
3399 -- pragmas which originate in a source aspect. In the latter case, the
3400 -- name may be different from the pragma name.
3401
3402 Pragma_Exit : exception;
3403 -- This exception is used to exit pragma processing completely. It
3404 -- is used when an error is detected, and no further processing is
3405 -- required. It is also used if an earlier error has left the tree in
3406 -- a state where the pragma should not be processed.
3407
3408 Arg_Count : Nat;
3409 -- Number of pragma argument associations
3410
3411 Arg1 : Node_Id;
3412 Arg2 : Node_Id;
3413 Arg3 : Node_Id;
3414 Arg4 : Node_Id;
3415 -- First four pragma arguments (pragma argument association nodes, or
3416 -- Empty if the corresponding argument does not exist).
3417
3418 type Name_List is array (Natural range <>) of Name_Id;
3419 type Args_List is array (Natural range <>) of Node_Id;
3420 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3421
3422 -----------------------
3423 -- Local Subprograms --
3424 -----------------------
3425
3426 procedure Acquire_Warning_Match_String (Arg : Node_Id);
3427 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3428 -- get the given string argument, and place it in Name_Buffer, adding
3429 -- leading and trailing asterisks if they are not already present. The
3430 -- caller has already checked that Arg is a static string expression.
3431
3432 procedure Ada_2005_Pragma;
3433 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3434 -- Ada 95 mode, these are implementation defined pragmas, so should be
3435 -- caught by the No_Implementation_Pragmas restriction.
3436
3437 procedure Ada_2012_Pragma;
3438 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3439 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3440 -- should be caught by the No_Implementation_Pragmas restriction.
3441
3442 procedure Analyze_Depends_Global
3443 (Spec_Id : out Entity_Id;
3444 Subp_Decl : out Node_Id;
3445 Legal : out Boolean);
3446 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3447 -- legality of the placement and related context of the pragma. Spec_Id
3448 -- is the entity of the related subprogram. Subp_Decl is the declaration
3449 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3450
3451 procedure Analyze_If_Present (Id : Pragma_Id);
3452 -- Inspect the remainder of the list containing pragma N and look for
3453 -- a pragma that matches Id. If found, analyze the pragma.
3454
3455 procedure Analyze_Pre_Post_Condition;
3456 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3457
3458 procedure Analyze_Refined_Depends_Global_Post
3459 (Spec_Id : out Entity_Id;
3460 Body_Id : out Entity_Id;
3461 Legal : out Boolean);
3462 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3463 -- Refined_Global and Refined_Post. Verify the legality of the placement
3464 -- and related context of the pragma. Spec_Id is the entity of the
3465 -- related subprogram. Body_Id is the entity of the subprogram body.
3466 -- Flag Legal is set when the pragma is legal.
3467
3468 procedure Check_Ada_83_Warning;
3469 -- Issues a warning message for the current pragma if operating in Ada
3470 -- 83 mode (used for language pragmas that are not a standard part of
3471 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3472 -- of 95 pragma.
3473
3474 procedure Check_Arg_Count (Required : Nat);
3475 -- Check argument count for pragma is equal to given parameter. If not,
3476 -- then issue an error message and raise Pragma_Exit.
3477
3478 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3479 -- Arg which can either be a pragma argument association, in which case
3480 -- the check is applied to the expression of the association or an
3481 -- expression directly.
3482
3483 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
3484 -- Check that an argument has the right form for an EXTERNAL_NAME
3485 -- parameter of an extended import/export pragma. The rule is that the
3486 -- name must be an identifier or string literal (in Ada 83 mode) or a
3487 -- static string expression (in Ada 95 mode).
3488
3489 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
3490 -- Check the specified argument Arg to make sure that it is an
3491 -- identifier. If not give error and raise Pragma_Exit.
3492
3493 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
3494 -- Check the specified argument Arg to make sure that it is an integer
3495 -- literal. If not give error and raise Pragma_Exit.
3496
3497 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
3498 -- Check the specified argument Arg to make sure that it has the proper
3499 -- syntactic form for a local name and meets the semantic requirements
3500 -- for a local name. The local name is analyzed as part of the
3501 -- processing for this call. In addition, the local name is required
3502 -- to represent an entity at the library level.
3503
3504 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
3505 -- Check the specified argument Arg to make sure that it has the proper
3506 -- syntactic form for a local name and meets the semantic requirements
3507 -- for a local name. The local name is analyzed as part of the
3508 -- processing for this call.
3509
3510 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
3511 -- Check the specified argument Arg to make sure that it is a valid
3512 -- locking policy name. If not give error and raise Pragma_Exit.
3513
3514 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
3515 -- Check the specified argument Arg to make sure that it is a valid
3516 -- elaboration policy name. If not give error and raise Pragma_Exit.
3517
3518 procedure Check_Arg_Is_One_Of
3519 (Arg : Node_Id;
3520 N1, N2 : Name_Id);
3521 procedure Check_Arg_Is_One_Of
3522 (Arg : Node_Id;
3523 N1, N2, N3 : Name_Id);
3524 procedure Check_Arg_Is_One_Of
3525 (Arg : Node_Id;
3526 N1, N2, N3, N4 : Name_Id);
3527 procedure Check_Arg_Is_One_Of
3528 (Arg : Node_Id;
3529 N1, N2, N3, N4, N5 : Name_Id);
3530 -- Check the specified argument Arg to make sure that it is an
3531 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3532 -- present). If not then give error and raise Pragma_Exit.
3533
3534 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
3535 -- Check the specified argument Arg to make sure that it is a valid
3536 -- queuing policy name. If not give error and raise Pragma_Exit.
3537
3538 procedure Check_Arg_Is_OK_Static_Expression
3539 (Arg : Node_Id;
3540 Typ : Entity_Id := Empty);
3541 -- Check the specified argument Arg to make sure that it is a static
3542 -- expression of the given type (i.e. it will be analyzed and resolved
3543 -- using this type, which can be any valid argument to Resolve, e.g.
3544 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3545 -- Typ is left Empty, then any static expression is allowed. Includes
3546 -- checking that the argument does not raise Constraint_Error.
3547
3548 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
3549 -- Check the specified argument Arg to make sure that it is a valid task
3550 -- dispatching policy name. If not give error and raise Pragma_Exit.
3551
3552 procedure Check_Arg_Order (Names : Name_List);
3553 -- Checks for an instance of two arguments with identifiers for the
3554 -- current pragma which are not in the sequence indicated by Names,
3555 -- and if so, generates a fatal message about bad order of arguments.
3556
3557 procedure Check_At_Least_N_Arguments (N : Nat);
3558 -- Check there are at least N arguments present
3559
3560 procedure Check_At_Most_N_Arguments (N : Nat);
3561 -- Check there are no more than N arguments present
3562
3563 procedure Check_Component
3564 (Comp : Node_Id;
3565 UU_Typ : Entity_Id;
3566 In_Variant_Part : Boolean := False);
3567 -- Examine an Unchecked_Union component for correct use of per-object
3568 -- constrained subtypes, and for restrictions on finalizable components.
3569 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3570 -- should be set when Comp comes from a record variant.
3571
3572 procedure Check_Duplicate_Pragma (E : Entity_Id);
3573 -- Check if a rep item of the same name as the current pragma is already
3574 -- chained as a rep pragma to the given entity. If so give a message
3575 -- about the duplicate, and then raise Pragma_Exit so does not return.
3576 -- Note that if E is a type, then this routine avoids flagging a pragma
3577 -- which applies to a parent type from which E is derived.
3578
3579 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
3580 -- Nam is an N_String_Literal node containing the external name set by
3581 -- an Import or Export pragma (or extended Import or Export pragma).
3582 -- This procedure checks for possible duplications if this is the export
3583 -- case, and if found, issues an appropriate error message.
3584
3585 procedure Check_Expr_Is_OK_Static_Expression
3586 (Expr : Node_Id;
3587 Typ : Entity_Id := Empty);
3588 -- Check the specified expression Expr to make sure that it is a static
3589 -- expression of the given type (i.e. it will be analyzed and resolved
3590 -- using this type, which can be any valid argument to Resolve, e.g.
3591 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3592 -- Typ is left Empty, then any static expression is allowed. Includes
3593 -- checking that the expression does not raise Constraint_Error.
3594
3595 procedure Check_First_Subtype (Arg : Node_Id);
3596 -- Checks that Arg, whose expression is an entity name, references a
3597 -- first subtype.
3598
3599 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
3600 -- Checks that the given argument has an identifier, and if so, requires
3601 -- it to match the given identifier name. If there is no identifier, or
3602 -- a non-matching identifier, then an error message is given and
3603 -- Pragma_Exit is raised.
3604
3605 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
3606 -- Checks that the given argument has an identifier, and if so, requires
3607 -- it to match one of the given identifier names. If there is no
3608 -- identifier, or a non-matching identifier, then an error message is
3609 -- given and Pragma_Exit is raised.
3610
3611 procedure Check_In_Main_Program;
3612 -- Common checks for pragmas that appear within a main program
3613 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3614
3615 procedure Check_Interrupt_Or_Attach_Handler;
3616 -- Common processing for first argument of pragma Interrupt_Handler or
3617 -- pragma Attach_Handler.
3618
3619 procedure Check_Loop_Pragma_Placement;
3620 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3621 -- appear immediately within a construct restricted to loops, and that
3622 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3623
3624 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
3625 -- Check that pragma appears in a declarative part, or in a package
3626 -- specification, i.e. that it does not occur in a statement sequence
3627 -- in a body.
3628
3629 procedure Check_No_Identifier (Arg : Node_Id);
3630 -- Checks that the given argument does not have an identifier. If
3631 -- an identifier is present, then an error message is issued, and
3632 -- Pragma_Exit is raised.
3633
3634 procedure Check_No_Identifiers;
3635 -- Checks that none of the arguments to the pragma has an identifier.
3636 -- If any argument has an identifier, then an error message is issued,
3637 -- and Pragma_Exit is raised.
3638
3639 procedure Check_No_Link_Name;
3640 -- Checks that no link name is specified
3641
3642 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3643 -- Checks if the given argument has an identifier, and if so, requires
3644 -- it to match the given identifier name. If there is a non-matching
3645 -- identifier, then an error message is given and Pragma_Exit is raised.
3646
3647 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3648 -- Checks if the given argument has an identifier, and if so, requires
3649 -- it to match the given identifier name. If there is a non-matching
3650 -- identifier, then an error message is given and Pragma_Exit is raised.
3651 -- In this version of the procedure, the identifier name is given as
3652 -- a string with lower case letters.
3653
3654 procedure Check_Static_Boolean_Expression (Expr : Node_Id);
3655 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3656 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3657 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3658 -- is an OK static boolean expression. Emit an error if this is not the
3659 -- case.
3660
3661 procedure Check_Static_Constraint (Constr : Node_Id);
3662 -- Constr is a constraint from an N_Subtype_Indication node from a
3663 -- component constraint in an Unchecked_Union type. This routine checks
3664 -- that the constraint is static as required by the restrictions for
3665 -- Unchecked_Union.
3666
3667 procedure Check_Valid_Configuration_Pragma;
3668 -- Legality checks for placement of a configuration pragma
3669
3670 procedure Check_Valid_Library_Unit_Pragma;
3671 -- Legality checks for library unit pragmas. A special case arises for
3672 -- pragmas in generic instances that come from copies of the original
3673 -- library unit pragmas in the generic templates. In the case of other
3674 -- than library level instantiations these can appear in contexts which
3675 -- would normally be invalid (they only apply to the original template
3676 -- and to library level instantiations), and they are simply ignored,
3677 -- which is implemented by rewriting them as null statements.
3678
3679 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3680 -- Check an Unchecked_Union variant for lack of nested variants and
3681 -- presence of at least one component. UU_Typ is the related Unchecked_
3682 -- Union type.
3683
3684 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3685 -- Subsidiary routine to the processing of pragmas Abstract_State,
3686 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3687 -- Refined_Global and Refined_State. Transform argument Arg into
3688 -- an aggregate if not one already. N_Null is never transformed.
3689 -- Arg may denote an aspect specification or a pragma argument
3690 -- association.
3691
3692 procedure Error_Pragma (Msg : String);
3693 pragma No_Return (Error_Pragma);
3694 -- Outputs error message for current pragma. The message contains a %
3695 -- that will be replaced with the pragma name, and the flag is placed
3696 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3697 -- calls Fix_Error (see spec of that procedure for details).
3698
3699 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3700 pragma No_Return (Error_Pragma_Arg);
3701 -- Outputs error message for current pragma. The message may contain
3702 -- a % that will be replaced with the pragma name. The parameter Arg
3703 -- may either be a pragma argument association, in which case the flag
3704 -- is placed on the expression of this association, or an expression,
3705 -- in which case the flag is placed directly on the expression. The
3706 -- message is placed using Error_Msg_N, so the message may also contain
3707 -- an & insertion character which will reference the given Arg value.
3708 -- After placing the message, Pragma_Exit is raised. Note: this routine
3709 -- calls Fix_Error (see spec of that procedure for details).
3710
3711 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3712 pragma No_Return (Error_Pragma_Arg);
3713 -- Similar to above form of Error_Pragma_Arg except that two messages
3714 -- are provided, the second is a continuation comment starting with \.
3715
3716 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3717 pragma No_Return (Error_Pragma_Arg_Ident);
3718 -- Outputs error message for current pragma. The message may contain a %
3719 -- that will be replaced with the pragma name. The parameter Arg must be
3720 -- a pragma argument association with a non-empty identifier (i.e. its
3721 -- Chars field must be set), and the error message is placed on the
3722 -- identifier. The message is placed using Error_Msg_N so the message
3723 -- may also contain an & insertion character which will reference
3724 -- the identifier. After placing the message, Pragma_Exit is raised.
3725 -- Note: this routine calls Fix_Error (see spec of that procedure for
3726 -- details).
3727
3728 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3729 pragma No_Return (Error_Pragma_Ref);
3730 -- Outputs error message for current pragma. The message may contain
3731 -- a % that will be replaced with the pragma name. The parameter Ref
3732 -- must be an entity whose name can be referenced by & and sloc by #.
3733 -- After placing the message, Pragma_Exit is raised. Note: this routine
3734 -- calls Fix_Error (see spec of that procedure for details).
3735
3736 function Find_Lib_Unit_Name return Entity_Id;
3737 -- Used for a library unit pragma to find the entity to which the
3738 -- library unit pragma applies, returns the entity found.
3739
3740 procedure Find_Program_Unit_Name (Id : Node_Id);
3741 -- If the pragma is a compilation unit pragma, the id must denote the
3742 -- compilation unit in the same compilation, and the pragma must appear
3743 -- in the list of preceding or trailing pragmas. If it is a program
3744 -- unit pragma that is not a compilation unit pragma, then the
3745 -- identifier must be visible.
3746
3747 function Find_Unique_Parameterless_Procedure
3748 (Name : Entity_Id;
3749 Arg : Node_Id) return Entity_Id;
3750 -- Used for a procedure pragma to find the unique parameterless
3751 -- procedure identified by Name, returns it if it exists, otherwise
3752 -- errors out and uses Arg as the pragma argument for the message.
3753
3754 function Fix_Error (Msg : String) return String;
3755 -- This is called prior to issuing an error message. Msg is the normal
3756 -- error message issued in the pragma case. This routine checks for the
3757 -- case of a pragma coming from an aspect in the source, and returns a
3758 -- message suitable for the aspect case as follows:
3759 --
3760 -- Each substring "pragma" is replaced by "aspect"
3761 --
3762 -- If "argument of" is at the start of the error message text, it is
3763 -- replaced by "entity for".
3764 --
3765 -- If "argument" is at the start of the error message text, it is
3766 -- replaced by "entity".
3767 --
3768 -- So for example, "argument of pragma X must be discrete type"
3769 -- returns "entity for aspect X must be a discrete type".
3770
3771 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3772 -- be different from the pragma name). If the current pragma results
3773 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3774 -- original pragma name.
3775
3776 procedure Gather_Associations
3777 (Names : Name_List;
3778 Args : out Args_List);
3779 -- This procedure is used to gather the arguments for a pragma that
3780 -- permits arbitrary ordering of parameters using the normal rules
3781 -- for named and positional parameters. The Names argument is a list
3782 -- of Name_Id values that corresponds to the allowed pragma argument
3783 -- association identifiers in order. The result returned in Args is
3784 -- a list of corresponding expressions that are the pragma arguments.
3785 -- Note that this is a list of expressions, not of pragma argument
3786 -- associations (Gather_Associations has completely checked all the
3787 -- optional identifiers when it returns). An entry in Args is Empty
3788 -- on return if the corresponding argument is not present.
3789
3790 procedure GNAT_Pragma;
3791 -- Called for all GNAT defined pragmas to check the relevant restriction
3792 -- (No_Implementation_Pragmas).
3793
3794 function Is_Before_First_Decl
3795 (Pragma_Node : Node_Id;
3796 Decls : List_Id) return Boolean;
3797 -- Return True if Pragma_Node is before the first declarative item in
3798 -- Decls where Decls is the list of declarative items.
3799
3800 function Is_Configuration_Pragma return Boolean;
3801 -- Determines if the placement of the current pragma is appropriate
3802 -- for a configuration pragma.
3803
3804 function Is_In_Context_Clause return Boolean;
3805 -- Returns True if pragma appears within the context clause of a unit,
3806 -- and False for any other placement (does not generate any messages).
3807
3808 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3809 -- Analyzes the argument, and determines if it is a static string
3810 -- expression, returns True if so, False if non-static or not String.
3811 -- A special case is that a string literal returns True in Ada 83 mode
3812 -- (which has no such thing as static string expressions). Note that
3813 -- the call analyzes its argument, so this cannot be used for the case
3814 -- where an identifier might not be declared.
3815
3816 procedure Pragma_Misplaced;
3817 pragma No_Return (Pragma_Misplaced);
3818 -- Issue fatal error message for misplaced pragma
3819
3820 procedure Process_Atomic_Independent_Shared_Volatile;
3821 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3822 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3823 -- and treated as being identical in effect to pragma Atomic.
3824
3825 procedure Process_Compile_Time_Warning_Or_Error;
3826 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3827
3828 procedure Process_Convention
3829 (C : out Convention_Id;
3830 Ent : out Entity_Id);
3831 -- Common processing for Convention, Interface, Import and Export.
3832 -- Checks first two arguments of pragma, and sets the appropriate
3833 -- convention value in the specified entity or entities. On return
3834 -- C is the convention, Ent is the referenced entity.
3835
3836 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3837 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3838 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3839
3840 procedure Process_Extended_Import_Export_Object_Pragma
3841 (Arg_Internal : Node_Id;
3842 Arg_External : Node_Id;
3843 Arg_Size : Node_Id);
3844 -- Common processing for the pragmas Import/Export_Object. The three
3845 -- arguments correspond to the three named parameters of the pragmas. An
3846 -- argument is empty if the corresponding parameter is not present in
3847 -- the pragma.
3848
3849 procedure Process_Extended_Import_Export_Internal_Arg
3850 (Arg_Internal : Node_Id := Empty);
3851 -- Common processing for all extended Import and Export pragmas. The
3852 -- argument is the pragma parameter for the Internal argument. If
3853 -- Arg_Internal is empty or inappropriate, an error message is posted.
3854 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3855 -- set to identify the referenced entity.
3856
3857 procedure Process_Extended_Import_Export_Subprogram_Pragma
3858 (Arg_Internal : Node_Id;
3859 Arg_External : Node_Id;
3860 Arg_Parameter_Types : Node_Id;
3861 Arg_Result_Type : Node_Id := Empty;
3862 Arg_Mechanism : Node_Id;
3863 Arg_Result_Mechanism : Node_Id := Empty);
3864 -- Common processing for all extended Import and Export pragmas applying
3865 -- to subprograms. The caller omits any arguments that do not apply to
3866 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3867 -- only in the Import_Function and Export_Function cases). The argument
3868 -- names correspond to the allowed pragma association identifiers.
3869
3870 procedure Process_Generic_List;
3871 -- Common processing for Share_Generic and Inline_Generic
3872
3873 procedure Process_Import_Or_Interface;
3874 -- Common processing for Import or Interface
3875
3876 procedure Process_Import_Predefined_Type;
3877 -- Processing for completing a type with pragma Import. This is used
3878 -- to declare types that match predefined C types, especially for cases
3879 -- without corresponding Ada predefined type.
3880
3881 type Inline_Status is (Suppressed, Disabled, Enabled);
3882 -- Inline status of a subprogram, indicated as follows:
3883 -- Suppressed: inlining is suppressed for the subprogram
3884 -- Disabled: no inlining is requested for the subprogram
3885 -- Enabled: inlining is requested/required for the subprogram
3886
3887 procedure Process_Inline (Status : Inline_Status);
3888 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3889 -- indicates the inline status specified by the pragma.
3890
3891 procedure Process_Interface_Name
3892 (Subprogram_Def : Entity_Id;
3893 Ext_Arg : Node_Id;
3894 Link_Arg : Node_Id);
3895 -- Given the last two arguments of pragma Import, pragma Export, or
3896 -- pragma Interface_Name, performs validity checks and sets the
3897 -- Interface_Name field of the given subprogram entity to the
3898 -- appropriate external or link name, depending on the arguments given.
3899 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3900 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3901 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3902 -- nor Link_Arg is present, the interface name is set to the default
3903 -- from the subprogram name.
3904
3905 procedure Process_Interrupt_Or_Attach_Handler;
3906 -- Common processing for Interrupt and Attach_Handler pragmas
3907
3908 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3909 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3910 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3911 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3912 -- is not set in the Restrictions case.
3913
3914 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3915 -- Common processing for Suppress and Unsuppress. The boolean parameter
3916 -- Suppress_Case is True for the Suppress case, and False for the
3917 -- Unsuppress case.
3918
3919 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id);
3920 -- Subsidiary to the analysis of pragmas Independent[_Components].
3921 -- Record such a pragma N applied to entity E for future checks.
3922
3923 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3924 -- This procedure sets the Is_Exported flag for the given entity,
3925 -- checking that the entity was not previously imported. Arg is
3926 -- the argument that specified the entity. A check is also made
3927 -- for exporting inappropriate entities.
3928
3929 procedure Set_Extended_Import_Export_External_Name
3930 (Internal_Ent : Entity_Id;
3931 Arg_External : Node_Id);
3932 -- Common processing for all extended import export pragmas. The first
3933 -- argument, Internal_Ent, is the internal entity, which has already
3934 -- been checked for validity by the caller. Arg_External is from the
3935 -- Import or Export pragma, and may be null if no External parameter
3936 -- was present. If Arg_External is present and is a non-null string
3937 -- (a null string is treated as the default), then the Interface_Name
3938 -- field of Internal_Ent is set appropriately.
3939
3940 procedure Set_Imported (E : Entity_Id);
3941 -- This procedure sets the Is_Imported flag for the given entity,
3942 -- checking that it is not previously exported or imported.
3943
3944 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3945 -- Mech is a parameter passing mechanism (see Import_Function syntax
3946 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3947 -- has the right form, and if not issues an error message. If the
3948 -- argument has the right form then the Mechanism field of Ent is
3949 -- set appropriately.
3950
3951 procedure Set_Rational_Profile;
3952 -- Activate the set of configuration pragmas and permissions that make
3953 -- up the Rational profile.
3954
3955 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id);
3956 -- Activate the set of configuration pragmas and restrictions that make
3957 -- up the Profile. Profile must be either GNAT_Extended_Ravencar or
3958 -- Ravenscar. N is the corresponding pragma node, which is used for
3959 -- error messages on any constructs violating the profile.
3960
3961 ----------------------------------
3962 -- Acquire_Warning_Match_String --
3963 ----------------------------------
3964
3965 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3966 begin
3967 String_To_Name_Buffer
3968 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3969
3970 -- Add asterisk at start if not already there
3971
3972 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3973 Name_Buffer (2 .. Name_Len + 1) :=
3974 Name_Buffer (1 .. Name_Len);
3975 Name_Buffer (1) := '*';
3976 Name_Len := Name_Len + 1;
3977 end if;
3978
3979 -- Add asterisk at end if not already there
3980
3981 if Name_Buffer (Name_Len) /= '*' then
3982 Name_Len := Name_Len + 1;
3983 Name_Buffer (Name_Len) := '*';
3984 end if;
3985 end Acquire_Warning_Match_String;
3986
3987 ---------------------
3988 -- Ada_2005_Pragma --
3989 ---------------------
3990
3991 procedure Ada_2005_Pragma is
3992 begin
3993 if Ada_Version <= Ada_95 then
3994 Check_Restriction (No_Implementation_Pragmas, N);
3995 end if;
3996 end Ada_2005_Pragma;
3997
3998 ---------------------
3999 -- Ada_2012_Pragma --
4000 ---------------------
4001
4002 procedure Ada_2012_Pragma is
4003 begin
4004 if Ada_Version <= Ada_2005 then
4005 Check_Restriction (No_Implementation_Pragmas, N);
4006 end if;
4007 end Ada_2012_Pragma;
4008
4009 ----------------------------
4010 -- Analyze_Depends_Global --
4011 ----------------------------
4012
4013 procedure Analyze_Depends_Global
4014 (Spec_Id : out Entity_Id;
4015 Subp_Decl : out Node_Id;
4016 Legal : out Boolean)
4017 is
4018 begin
4019 -- Assume that the pragma is illegal
4020
4021 Spec_Id := Empty;
4022 Subp_Decl := Empty;
4023 Legal := False;
4024
4025 GNAT_Pragma;
4026 Check_Arg_Count (1);
4027
4028 -- Ensure the proper placement of the pragma. Depends/Global must be
4029 -- associated with a subprogram declaration or a body that acts as a
4030 -- spec.
4031
4032 Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4033
4034 -- Entry
4035
4036 if Nkind (Subp_Decl) = N_Entry_Declaration then
4037 null;
4038
4039 -- Generic subprogram
4040
4041 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4042 null;
4043
4044 -- Object declaration of a single concurrent type
4045
4046 elsif Nkind (Subp_Decl) = N_Object_Declaration then
4047 null;
4048
4049 -- Single task type
4050
4051 elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then
4052 null;
4053
4054 -- Subprogram body acts as spec
4055
4056 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4057 and then No (Corresponding_Spec (Subp_Decl))
4058 then
4059 null;
4060
4061 -- Subprogram body stub acts as spec
4062
4063 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4064 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
4065 then
4066 null;
4067
4068 -- Subprogram declaration
4069
4070 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4071 null;
4072
4073 -- Task type
4074
4075 elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then
4076 null;
4077
4078 else
4079 Pragma_Misplaced;
4080 return;
4081 end if;
4082
4083 -- If we get here, then the pragma is legal
4084
4085 Legal := True;
4086 Spec_Id := Unique_Defining_Entity (Subp_Decl);
4087
4088 -- When the related context is an entry, the entry must belong to a
4089 -- protected unit (SPARK RM 6.1.4(6)).
4090
4091 if Is_Entry_Declaration (Spec_Id)
4092 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
4093 then
4094 Pragma_Misplaced;
4095 return;
4096
4097 -- When the related context is an anonymous object created for a
4098 -- simple concurrent type, the type must be a task
4099 -- (SPARK RM 6.1.4(6)).
4100
4101 elsif Is_Single_Concurrent_Object (Spec_Id)
4102 and then Ekind (Etype (Spec_Id)) /= E_Task_Type
4103 then
4104 Pragma_Misplaced;
4105 return;
4106 end if;
4107
4108 -- A pragma that applies to a Ghost entity becomes Ghost for the
4109 -- purposes of legality checks and removal of ignored Ghost code.
4110
4111 Mark_Pragma_As_Ghost (N, Spec_Id);
4112 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4113 end Analyze_Depends_Global;
4114
4115 ------------------------
4116 -- Analyze_If_Present --
4117 ------------------------
4118
4119 procedure Analyze_If_Present (Id : Pragma_Id) is
4120 Stmt : Node_Id;
4121
4122 begin
4123 pragma Assert (Is_List_Member (N));
4124
4125 -- Inspect the declarations or statements following pragma N looking
4126 -- for another pragma whose Id matches the caller's request. If it is
4127 -- available, analyze it.
4128
4129 Stmt := Next (N);
4130 while Present (Stmt) loop
4131 if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then
4132 Analyze_Pragma (Stmt);
4133 exit;
4134
4135 -- The first source declaration or statement immediately following
4136 -- N ends the region where a pragma may appear.
4137
4138 elsif Comes_From_Source (Stmt) then
4139 exit;
4140 end if;
4141
4142 Next (Stmt);
4143 end loop;
4144 end Analyze_If_Present;
4145
4146 --------------------------------
4147 -- Analyze_Pre_Post_Condition --
4148 --------------------------------
4149
4150 procedure Analyze_Pre_Post_Condition is
4151 Prag_Iden : constant Node_Id := Pragma_Identifier (N);
4152 Subp_Decl : Node_Id;
4153 Subp_Id : Entity_Id;
4154
4155 Duplicates_OK : Boolean := False;
4156 -- Flag set when a pre/postcondition allows multiple pragmas of the
4157 -- same kind.
4158
4159 In_Body_OK : Boolean := False;
4160 -- Flag set when a pre/postcondition is allowed to appear on a body
4161 -- even though the subprogram may have a spec.
4162
4163 Is_Pre_Post : Boolean := False;
4164 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4165 -- Post_Class.
4166
4167 begin
4168 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4169 -- offer uniformity among the various kinds of pre/postconditions by
4170 -- rewriting the pragma identifier. This allows the retrieval of the
4171 -- original pragma name by routine Original_Aspect_Pragma_Name.
4172
4173 if Comes_From_Source (N) then
4174 if Nam_In (Pname, Name_Pre, Name_Pre_Class) then
4175 Is_Pre_Post := True;
4176 Set_Class_Present (N, Pname = Name_Pre_Class);
4177 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition));
4178
4179 elsif Nam_In (Pname, Name_Post, Name_Post_Class) then
4180 Is_Pre_Post := True;
4181 Set_Class_Present (N, Pname = Name_Post_Class);
4182 Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition));
4183 end if;
4184 end if;
4185
4186 -- Determine the semantics with respect to duplicates and placement
4187 -- in a body. Pragmas Precondition and Postcondition were introduced
4188 -- before aspects and are not subject to the same aspect-like rules.
4189
4190 if Nam_In (Pname, Name_Precondition, Name_Postcondition) then
4191 Duplicates_OK := True;
4192 In_Body_OK := True;
4193 end if;
4194
4195 GNAT_Pragma;
4196
4197 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4198 -- argument without an identifier.
4199
4200 if Is_Pre_Post then
4201 Check_Arg_Count (1);
4202 Check_No_Identifiers;
4203
4204 -- Pragmas Precondition and Postcondition have complex argument
4205 -- profile.
4206
4207 else
4208 Check_At_Least_N_Arguments (1);
4209 Check_At_Most_N_Arguments (2);
4210 Check_Optional_Identifier (Arg1, Name_Check);
4211
4212 if Present (Arg2) then
4213 Check_Optional_Identifier (Arg2, Name_Message);
4214 Preanalyze_Spec_Expression
4215 (Get_Pragma_Arg (Arg2), Standard_String);
4216 end if;
4217 end if;
4218
4219 -- For a pragma PPC in the extended main source unit, record enabled
4220 -- status in SCO.
4221 -- ??? nothing checks that the pragma is in the main source unit
4222
4223 if Is_Checked (N) and then not Split_PPC (N) then
4224 Set_SCO_Pragma_Enabled (Loc);
4225 end if;
4226
4227 -- Ensure the proper placement of the pragma
4228
4229 Subp_Decl :=
4230 Find_Related_Declaration_Or_Body
4231 (N, Do_Checks => not Duplicates_OK);
4232
4233 -- When a pre/postcondition pragma applies to an abstract subprogram,
4234 -- its original form must be an aspect with 'Class.
4235
4236 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
4237 if not From_Aspect_Specification (N) then
4238 Error_Pragma
4239 ("pragma % cannot be applied to abstract subprogram");
4240
4241 elsif not Class_Present (N) then
4242 Error_Pragma
4243 ("aspect % requires ''Class for abstract subprogram");
4244 end if;
4245
4246 -- Entry declaration
4247
4248 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
4249 null;
4250
4251 -- Generic subprogram declaration
4252
4253 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
4254 null;
4255
4256 -- Subprogram body
4257
4258 elsif Nkind (Subp_Decl) = N_Subprogram_Body
4259 and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK)
4260 then
4261 null;
4262
4263 -- Subprogram body stub
4264
4265 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4266 and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK)
4267 then
4268 null;
4269
4270 -- Subprogram declaration
4271
4272 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
4273
4274 -- AI05-0230: When a pre/postcondition pragma applies to a null
4275 -- procedure, its original form must be an aspect with 'Class.
4276
4277 if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification
4278 and then Null_Present (Specification (Subp_Decl))
4279 and then From_Aspect_Specification (N)
4280 and then not Class_Present (N)
4281 then
4282 Error_Pragma ("aspect % requires ''Class for null procedure");
4283 end if;
4284
4285 -- Otherwise the placement is illegal
4286
4287 else
4288 Pragma_Misplaced;
4289 return;
4290 end if;
4291
4292 Subp_Id := Defining_Entity (Subp_Decl);
4293
4294 -- Chain the pragma on the contract for further processing by
4295 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4296
4297 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
4298
4299 -- A pragma that applies to a Ghost entity becomes Ghost for the
4300 -- purposes of legality checks and removal of ignored Ghost code.
4301
4302 Mark_Pragma_As_Ghost (N, Subp_Id);
4303
4304 -- Fully analyze the pragma when it appears inside an entry or
4305 -- subprogram body because it cannot benefit from forward references.
4306
4307 if Nkind_In (Subp_Decl, N_Entry_Body,
4308 N_Subprogram_Body,
4309 N_Subprogram_Body_Stub)
4310 then
4311 -- The legality checks of pragmas Precondition and Postcondition
4312 -- are affected by the SPARK mode in effect and the volatility of
4313 -- the context. Analyze all pragmas in a specific order.
4314
4315 Analyze_If_Present (Pragma_SPARK_Mode);
4316 Analyze_If_Present (Pragma_Volatile_Function);
4317 Analyze_Pre_Post_Condition_In_Decl_Part (N);
4318 end if;
4319 end Analyze_Pre_Post_Condition;
4320
4321 -----------------------------------------
4322 -- Analyze_Refined_Depends_Global_Post --
4323 -----------------------------------------
4324
4325 procedure Analyze_Refined_Depends_Global_Post
4326 (Spec_Id : out Entity_Id;
4327 Body_Id : out Entity_Id;
4328 Legal : out Boolean)
4329 is
4330 Body_Decl : Node_Id;
4331 Spec_Decl : Node_Id;
4332
4333 begin
4334 -- Assume that the pragma is illegal
4335
4336 Spec_Id := Empty;
4337 Body_Id := Empty;
4338 Legal := False;
4339
4340 GNAT_Pragma;
4341 Check_Arg_Count (1);
4342 Check_No_Identifiers;
4343
4344 -- Verify the placement of the pragma and check for duplicates. The
4345 -- pragma must apply to a subprogram body [stub].
4346
4347 Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True);
4348
4349 -- Entry body
4350
4351 if Nkind (Body_Decl) = N_Entry_Body then
4352 null;
4353
4354 -- Subprogram body
4355
4356 elsif Nkind (Body_Decl) = N_Subprogram_Body then
4357 null;
4358
4359 -- Subprogram body stub
4360
4361 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
4362 null;
4363
4364 -- Task body
4365
4366 elsif Nkind (Body_Decl) = N_Task_Body then
4367 null;
4368
4369 else
4370 Pragma_Misplaced;
4371 return;
4372 end if;
4373
4374 Body_Id := Defining_Entity (Body_Decl);
4375 Spec_Id := Unique_Defining_Entity (Body_Decl);
4376
4377 -- The pragma must apply to the second declaration of a subprogram.
4378 -- In other words, the body [stub] cannot acts as a spec.
4379
4380 if No (Spec_Id) then
4381 Error_Pragma ("pragma % cannot apply to a stand alone body");
4382 return;
4383
4384 -- Catch the case where the subprogram body is a subunit and acts as
4385 -- the third declaration of the subprogram.
4386
4387 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
4388 Error_Pragma ("pragma % cannot apply to a subunit");
4389 return;
4390 end if;
4391
4392 -- A refined pragma can only apply to the body [stub] of a subprogram
4393 -- declared in the visible part of a package. Retrieve the context of
4394 -- the subprogram declaration.
4395
4396 Spec_Decl := Unit_Declaration_Node (Spec_Id);
4397
4398 -- When dealing with protected entries or protected subprograms, use
4399 -- the enclosing protected type as the proper context.
4400
4401 if Ekind_In (Spec_Id, E_Entry,
4402 E_Entry_Family,
4403 E_Function,
4404 E_Procedure)
4405 and then Ekind (Scope (Spec_Id)) = E_Protected_Type
4406 then
4407 Spec_Decl := Declaration_Node (Scope (Spec_Id));
4408 end if;
4409
4410 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
4411 Error_Pragma
4412 (Fix_Msg (Spec_Id, "pragma % must apply to the body of "
4413 & "subprogram declared in a package specification"));
4414 return;
4415 end if;
4416
4417 -- If we get here, then the pragma is legal
4418
4419 Legal := True;
4420
4421 -- A pragma that applies to a Ghost entity becomes Ghost for the
4422 -- purposes of legality checks and removal of ignored Ghost code.
4423
4424 Mark_Pragma_As_Ghost (N, Spec_Id);
4425
4426 if Nam_In (Pname, Name_Refined_Depends, Name_Refined_Global) then
4427 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
4428 end if;
4429 end Analyze_Refined_Depends_Global_Post;
4430
4431 --------------------------
4432 -- Check_Ada_83_Warning --
4433 --------------------------
4434
4435 procedure Check_Ada_83_Warning is
4436 begin
4437 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4438 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
4439 end if;
4440 end Check_Ada_83_Warning;
4441
4442 ---------------------
4443 -- Check_Arg_Count --
4444 ---------------------
4445
4446 procedure Check_Arg_Count (Required : Nat) is
4447 begin
4448 if Arg_Count /= Required then
4449 Error_Pragma ("wrong number of arguments for pragma%");
4450 end if;
4451 end Check_Arg_Count;
4452
4453 --------------------------------
4454 -- Check_Arg_Is_External_Name --
4455 --------------------------------
4456
4457 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
4458 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4459
4460 begin
4461 if Nkind (Argx) = N_Identifier then
4462 return;
4463
4464 else
4465 Analyze_And_Resolve (Argx, Standard_String);
4466
4467 if Is_OK_Static_Expression (Argx) then
4468 return;
4469
4470 elsif Etype (Argx) = Any_Type then
4471 raise Pragma_Exit;
4472
4473 -- An interesting special case, if we have a string literal and
4474 -- we are in Ada 83 mode, then we allow it even though it will
4475 -- not be flagged as static. This allows expected Ada 83 mode
4476 -- use of external names which are string literals, even though
4477 -- technically these are not static in Ada 83.
4478
4479 elsif Ada_Version = Ada_83
4480 and then Nkind (Argx) = N_String_Literal
4481 then
4482 return;
4483
4484 -- Static expression that raises Constraint_Error. This has
4485 -- already been flagged, so just exit from pragma processing.
4486
4487 elsif Is_OK_Static_Expression (Argx) then
4488 raise Pragma_Exit;
4489
4490 -- Here we have a real error (non-static expression)
4491
4492 else
4493 Error_Msg_Name_1 := Pname;
4494
4495 declare
4496 Msg : constant String :=
4497 "argument for pragma% must be a identifier or "
4498 & "static string expression!";
4499 begin
4500 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
4501 raise Pragma_Exit;
4502 end;
4503 end if;
4504 end if;
4505 end Check_Arg_Is_External_Name;
4506
4507 -----------------------------
4508 -- Check_Arg_Is_Identifier --
4509 -----------------------------
4510
4511 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
4512 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4513 begin
4514 if Nkind (Argx) /= N_Identifier then
4515 Error_Pragma_Arg
4516 ("argument for pragma% must be identifier", Argx);
4517 end if;
4518 end Check_Arg_Is_Identifier;
4519
4520 ----------------------------------
4521 -- Check_Arg_Is_Integer_Literal --
4522 ----------------------------------
4523
4524 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
4525 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4526 begin
4527 if Nkind (Argx) /= N_Integer_Literal then
4528 Error_Pragma_Arg
4529 ("argument for pragma% must be integer literal", Argx);
4530 end if;
4531 end Check_Arg_Is_Integer_Literal;
4532
4533 -------------------------------------------
4534 -- Check_Arg_Is_Library_Level_Local_Name --
4535 -------------------------------------------
4536
4537 -- LOCAL_NAME ::=
4538 -- DIRECT_NAME
4539 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4540 -- | library_unit_NAME
4541
4542 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
4543 begin
4544 Check_Arg_Is_Local_Name (Arg);
4545
4546 -- If it came from an aspect, we want to give the error just as if it
4547 -- came from source.
4548
4549 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
4550 and then (Comes_From_Source (N)
4551 or else Present (Corresponding_Aspect (Parent (Arg))))
4552 then
4553 Error_Pragma_Arg
4554 ("argument for pragma% must be library level entity", Arg);
4555 end if;
4556 end Check_Arg_Is_Library_Level_Local_Name;
4557
4558 -----------------------------
4559 -- Check_Arg_Is_Local_Name --
4560 -----------------------------
4561
4562 -- LOCAL_NAME ::=
4563 -- DIRECT_NAME
4564 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4565 -- | library_unit_NAME
4566
4567 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
4568 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4569
4570 begin
4571 -- If this pragma came from an aspect specification, we don't want to
4572 -- check for this error, because that would cause spurious errors, in
4573 -- case a type is frozen in a scope more nested than the type. The
4574 -- aspect itself of course can't be anywhere but on the declaration
4575 -- itself.
4576
4577 if Nkind (Arg) = N_Pragma_Argument_Association then
4578 if From_Aspect_Specification (Parent (Arg)) then
4579 return;
4580 end if;
4581
4582 -- Arg is the Expression of an N_Pragma_Argument_Association
4583
4584 else
4585 if From_Aspect_Specification (Parent (Parent (Arg))) then
4586 return;
4587 end if;
4588 end if;
4589
4590 Analyze (Argx);
4591
4592 if Nkind (Argx) not in N_Direct_Name
4593 and then (Nkind (Argx) /= N_Attribute_Reference
4594 or else Present (Expressions (Argx))
4595 or else Nkind (Prefix (Argx)) /= N_Identifier)
4596 and then (not Is_Entity_Name (Argx)
4597 or else not Is_Compilation_Unit (Entity (Argx)))
4598 then
4599 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
4600 end if;
4601
4602 -- No further check required if not an entity name
4603
4604 if not Is_Entity_Name (Argx) then
4605 null;
4606
4607 else
4608 declare
4609 OK : Boolean;
4610 Ent : constant Entity_Id := Entity (Argx);
4611 Scop : constant Entity_Id := Scope (Ent);
4612
4613 begin
4614 -- Case of a pragma applied to a compilation unit: pragma must
4615 -- occur immediately after the program unit in the compilation.
4616
4617 if Is_Compilation_Unit (Ent) then
4618 declare
4619 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
4620
4621 begin
4622 -- Case of pragma placed immediately after spec
4623
4624 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
4625 OK := True;
4626
4627 -- Case of pragma placed immediately after body
4628
4629 elsif Nkind (Decl) = N_Subprogram_Declaration
4630 and then Present (Corresponding_Body (Decl))
4631 then
4632 OK := Parent (N) =
4633 Aux_Decls_Node
4634 (Parent (Unit_Declaration_Node
4635 (Corresponding_Body (Decl))));
4636
4637 -- All other cases are illegal
4638
4639 else
4640 OK := False;
4641 end if;
4642 end;
4643
4644 -- Special restricted placement rule from 10.2.1(11.8/2)
4645
4646 elsif Is_Generic_Formal (Ent)
4647 and then Prag_Id = Pragma_Preelaborable_Initialization
4648 then
4649 OK := List_Containing (N) =
4650 Generic_Formal_Declarations
4651 (Unit_Declaration_Node (Scop));
4652
4653 -- If this is an aspect applied to a subprogram body, the
4654 -- pragma is inserted in its declarative part.
4655
4656 elsif From_Aspect_Specification (N)
4657 and then Ent = Current_Scope
4658 and then
4659 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
4660 then
4661 OK := True;
4662
4663 -- If the aspect is a predicate (possibly others ???) and the
4664 -- context is a record type, this is a discriminant expression
4665 -- within a type declaration, that freezes the predicated
4666 -- subtype.
4667
4668 elsif From_Aspect_Specification (N)
4669 and then Prag_Id = Pragma_Predicate
4670 and then Ekind (Current_Scope) = E_Record_Type
4671 and then Scop = Scope (Current_Scope)
4672 then
4673 OK := True;
4674
4675 -- Default case, just check that the pragma occurs in the scope
4676 -- of the entity denoted by the name.
4677
4678 else
4679 OK := Current_Scope = Scop;
4680 end if;
4681
4682 if not OK then
4683 Error_Pragma_Arg
4684 ("pragma% argument must be in same declarative part", Arg);
4685 end if;
4686 end;
4687 end if;
4688 end Check_Arg_Is_Local_Name;
4689
4690 ---------------------------------
4691 -- Check_Arg_Is_Locking_Policy --
4692 ---------------------------------
4693
4694 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
4695 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4696
4697 begin
4698 Check_Arg_Is_Identifier (Argx);
4699
4700 if not Is_Locking_Policy_Name (Chars (Argx)) then
4701 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
4702 end if;
4703 end Check_Arg_Is_Locking_Policy;
4704
4705 -----------------------------------------------
4706 -- Check_Arg_Is_Partition_Elaboration_Policy --
4707 -----------------------------------------------
4708
4709 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
4710 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4711
4712 begin
4713 Check_Arg_Is_Identifier (Argx);
4714
4715 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
4716 Error_Pragma_Arg
4717 ("& is not a valid partition elaboration policy name", Argx);
4718 end if;
4719 end Check_Arg_Is_Partition_Elaboration_Policy;
4720
4721 -------------------------
4722 -- Check_Arg_Is_One_Of --
4723 -------------------------
4724
4725 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4726 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4727
4728 begin
4729 Check_Arg_Is_Identifier (Argx);
4730
4731 if not Nam_In (Chars (Argx), N1, N2) then
4732 Error_Msg_Name_2 := N1;
4733 Error_Msg_Name_3 := N2;
4734 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
4735 end if;
4736 end Check_Arg_Is_One_Of;
4737
4738 procedure Check_Arg_Is_One_Of
4739 (Arg : Node_Id;
4740 N1, N2, N3 : Name_Id)
4741 is
4742 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4743
4744 begin
4745 Check_Arg_Is_Identifier (Argx);
4746
4747 if not Nam_In (Chars (Argx), N1, N2, N3) then
4748 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4749 end if;
4750 end Check_Arg_Is_One_Of;
4751
4752 procedure Check_Arg_Is_One_Of
4753 (Arg : Node_Id;
4754 N1, N2, N3, N4 : Name_Id)
4755 is
4756 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4757
4758 begin
4759 Check_Arg_Is_Identifier (Argx);
4760
4761 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
4762 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4763 end if;
4764 end Check_Arg_Is_One_Of;
4765
4766 procedure Check_Arg_Is_One_Of
4767 (Arg : Node_Id;
4768 N1, N2, N3, N4, N5 : Name_Id)
4769 is
4770 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4771
4772 begin
4773 Check_Arg_Is_Identifier (Argx);
4774
4775 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
4776 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
4777 end if;
4778 end Check_Arg_Is_One_Of;
4779
4780 ---------------------------------
4781 -- Check_Arg_Is_Queuing_Policy --
4782 ---------------------------------
4783
4784 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
4785 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4786
4787 begin
4788 Check_Arg_Is_Identifier (Argx);
4789
4790 if not Is_Queuing_Policy_Name (Chars (Argx)) then
4791 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
4792 end if;
4793 end Check_Arg_Is_Queuing_Policy;
4794
4795 ---------------------------------------
4796 -- Check_Arg_Is_OK_Static_Expression --
4797 ---------------------------------------
4798
4799 procedure Check_Arg_Is_OK_Static_Expression
4800 (Arg : Node_Id;
4801 Typ : Entity_Id := Empty)
4802 is
4803 begin
4804 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
4805 end Check_Arg_Is_OK_Static_Expression;
4806
4807 ------------------------------------------
4808 -- Check_Arg_Is_Task_Dispatching_Policy --
4809 ------------------------------------------
4810
4811 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4812 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4813
4814 begin
4815 Check_Arg_Is_Identifier (Argx);
4816
4817 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4818 Error_Pragma_Arg
4819 ("& is not an allowed task dispatching policy name", Argx);
4820 end if;
4821 end Check_Arg_Is_Task_Dispatching_Policy;
4822
4823 ---------------------
4824 -- Check_Arg_Order --
4825 ---------------------
4826
4827 procedure Check_Arg_Order (Names : Name_List) is
4828 Arg : Node_Id;
4829
4830 Highest_So_Far : Natural := 0;
4831 -- Highest index in Names seen do far
4832
4833 begin
4834 Arg := Arg1;
4835 for J in 1 .. Arg_Count loop
4836 if Chars (Arg) /= No_Name then
4837 for K in Names'Range loop
4838 if Chars (Arg) = Names (K) then
4839 if K < Highest_So_Far then
4840 Error_Msg_Name_1 := Pname;
4841 Error_Msg_N
4842 ("parameters out of order for pragma%", Arg);
4843 Error_Msg_Name_1 := Names (K);
4844 Error_Msg_Name_2 := Names (Highest_So_Far);
4845 Error_Msg_N ("\% must appear before %", Arg);
4846 raise Pragma_Exit;
4847
4848 else
4849 Highest_So_Far := K;
4850 end if;
4851 end if;
4852 end loop;
4853 end if;
4854
4855 Arg := Next (Arg);
4856 end loop;
4857 end Check_Arg_Order;
4858
4859 --------------------------------
4860 -- Check_At_Least_N_Arguments --
4861 --------------------------------
4862
4863 procedure Check_At_Least_N_Arguments (N : Nat) is
4864 begin
4865 if Arg_Count < N then
4866 Error_Pragma ("too few arguments for pragma%");
4867 end if;
4868 end Check_At_Least_N_Arguments;
4869
4870 -------------------------------
4871 -- Check_At_Most_N_Arguments --
4872 -------------------------------
4873
4874 procedure Check_At_Most_N_Arguments (N : Nat) is
4875 Arg : Node_Id;
4876 begin
4877 if Arg_Count > N then
4878 Arg := Arg1;
4879 for J in 1 .. N loop
4880 Next (Arg);
4881 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4882 end loop;
4883 end if;
4884 end Check_At_Most_N_Arguments;
4885
4886 ---------------------
4887 -- Check_Component --
4888 ---------------------
4889
4890 procedure Check_Component
4891 (Comp : Node_Id;
4892 UU_Typ : Entity_Id;
4893 In_Variant_Part : Boolean := False)
4894 is
4895 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
4896 Sindic : constant Node_Id :=
4897 Subtype_Indication (Component_Definition (Comp));
4898 Typ : constant Entity_Id := Etype (Comp_Id);
4899
4900 begin
4901 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4902 -- object constraint, then the component type shall be an Unchecked_
4903 -- Union.
4904
4905 if Nkind (Sindic) = N_Subtype_Indication
4906 and then Has_Per_Object_Constraint (Comp_Id)
4907 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4908 then
4909 Error_Msg_N
4910 ("component subtype subject to per-object constraint "
4911 & "must be an Unchecked_Union", Comp);
4912
4913 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4914 -- the body of a generic unit, or within the body of any of its
4915 -- descendant library units, no part of the type of a component
4916 -- declared in a variant_part of the unchecked union type shall be of
4917 -- a formal private type or formal private extension declared within
4918 -- the formal part of the generic unit.
4919
4920 elsif Ada_Version >= Ada_2012
4921 and then In_Generic_Body (UU_Typ)
4922 and then In_Variant_Part
4923 and then Is_Private_Type (Typ)
4924 and then Is_Generic_Type (Typ)
4925 then
4926 Error_Msg_N
4927 ("component of unchecked union cannot be of generic type", Comp);
4928
4929 elsif Needs_Finalization (Typ) then
4930 Error_Msg_N
4931 ("component of unchecked union cannot be controlled", Comp);
4932
4933 elsif Has_Task (Typ) then
4934 Error_Msg_N
4935 ("component of unchecked union cannot have tasks", Comp);
4936 end if;
4937 end Check_Component;
4938
4939 ----------------------------
4940 -- Check_Duplicate_Pragma --
4941 ----------------------------
4942
4943 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4944 Id : Entity_Id := E;
4945 P : Node_Id;
4946
4947 begin
4948 -- Nothing to do if this pragma comes from an aspect specification,
4949 -- since we could not be duplicating a pragma, and we dealt with the
4950 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4951
4952 if From_Aspect_Specification (N) then
4953 return;
4954 end if;
4955
4956 -- Otherwise current pragma may duplicate previous pragma or a
4957 -- previously given aspect specification or attribute definition
4958 -- clause for the same pragma.
4959
4960 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4961
4962 if Present (P) then
4963
4964 -- If the entity is a type, then we have to make sure that the
4965 -- ostensible duplicate is not for a parent type from which this
4966 -- type is derived.
4967
4968 if Is_Type (E) then
4969 if Nkind (P) = N_Pragma then
4970 declare
4971 Args : constant List_Id :=
4972 Pragma_Argument_Associations (P);
4973 begin
4974 if Present (Args)
4975 and then Is_Entity_Name (Expression (First (Args)))
4976 and then Is_Type (Entity (Expression (First (Args))))
4977 and then Entity (Expression (First (Args))) /= E
4978 then
4979 return;
4980 end if;
4981 end;
4982
4983 elsif Nkind (P) = N_Aspect_Specification
4984 and then Is_Type (Entity (P))
4985 and then Entity (P) /= E
4986 then
4987 return;
4988 end if;
4989 end if;
4990
4991 -- Here we have a definite duplicate
4992
4993 Error_Msg_Name_1 := Pragma_Name (N);
4994 Error_Msg_Sloc := Sloc (P);
4995
4996 -- For a single protected or a single task object, the error is
4997 -- issued on the original entity.
4998
4999 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
5000 Id := Defining_Identifier (Original_Node (Parent (Id)));
5001 end if;
5002
5003 if Nkind (P) = N_Aspect_Specification
5004 or else From_Aspect_Specification (P)
5005 then
5006 Error_Msg_NE ("aspect% for & previously given#", N, Id);
5007 else
5008 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
5009 end if;
5010
5011 raise Pragma_Exit;
5012 end if;
5013 end Check_Duplicate_Pragma;
5014
5015 ----------------------------------
5016 -- Check_Duplicated_Export_Name --
5017 ----------------------------------
5018
5019 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
5020 String_Val : constant String_Id := Strval (Nam);
5021
5022 begin
5023 -- We are only interested in the export case, and in the case of
5024 -- generics, it is the instance, not the template, that is the
5025 -- problem (the template will generate a warning in any case).
5026
5027 if not Inside_A_Generic
5028 and then (Prag_Id = Pragma_Export
5029 or else
5030 Prag_Id = Pragma_Export_Procedure
5031 or else
5032 Prag_Id = Pragma_Export_Valued_Procedure
5033 or else
5034 Prag_Id = Pragma_Export_Function)
5035 then
5036 for J in Externals.First .. Externals.Last loop
5037 if String_Equal (String_Val, Strval (Externals.Table (J))) then
5038 Error_Msg_Sloc := Sloc (Externals.Table (J));
5039 Error_Msg_N ("external name duplicates name given#", Nam);
5040 exit;
5041 end if;
5042 end loop;
5043
5044 Externals.Append (Nam);
5045 end if;
5046 end Check_Duplicated_Export_Name;
5047
5048 ----------------------------------------
5049 -- Check_Expr_Is_OK_Static_Expression --
5050 ----------------------------------------
5051
5052 procedure Check_Expr_Is_OK_Static_Expression
5053 (Expr : Node_Id;
5054 Typ : Entity_Id := Empty)
5055 is
5056 begin
5057 if Present (Typ) then
5058 Analyze_And_Resolve (Expr, Typ);
5059 else
5060 Analyze_And_Resolve (Expr);
5061 end if;
5062
5063 -- An expression cannot be considered static if its resolution failed
5064 -- or if it's erroneous. Stop the analysis of the related pragma.
5065
5066 if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
5067 raise Pragma_Exit;
5068
5069 elsif Is_OK_Static_Expression (Expr) then
5070 return;
5071
5072 -- An interesting special case, if we have a string literal and we
5073 -- are in Ada 83 mode, then we allow it even though it will not be
5074 -- flagged as static. This allows the use of Ada 95 pragmas like
5075 -- Import in Ada 83 mode. They will of course be flagged with
5076 -- warnings as usual, but will not cause errors.
5077
5078 elsif Ada_Version = Ada_83
5079 and then Nkind (Expr) = N_String_Literal
5080 then
5081 return;
5082
5083 -- Finally, we have a real error
5084
5085 else
5086 Error_Msg_Name_1 := Pname;
5087 Flag_Non_Static_Expr
5088 (Fix_Error ("argument for pragma% must be a static expression!"),
5089 Expr);
5090 raise Pragma_Exit;
5091 end if;
5092 end Check_Expr_Is_OK_Static_Expression;
5093
5094 -------------------------
5095 -- Check_First_Subtype --
5096 -------------------------
5097
5098 procedure Check_First_Subtype (Arg : Node_Id) is
5099 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5100 Ent : constant Entity_Id := Entity (Argx);
5101
5102 begin
5103 if Is_First_Subtype (Ent) then
5104 null;
5105
5106 elsif Is_Type (Ent) then
5107 Error_Pragma_Arg
5108 ("pragma% cannot apply to subtype", Argx);
5109
5110 elsif Is_Object (Ent) then
5111 Error_Pragma_Arg
5112 ("pragma% cannot apply to object, requires a type", Argx);
5113
5114 else
5115 Error_Pragma_Arg
5116 ("pragma% cannot apply to&, requires a type", Argx);
5117 end if;
5118 end Check_First_Subtype;
5119
5120 ----------------------
5121 -- Check_Identifier --
5122 ----------------------
5123
5124 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
5125 begin
5126 if Present (Arg)
5127 and then Nkind (Arg) = N_Pragma_Argument_Association
5128 then
5129 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
5130 Error_Msg_Name_1 := Pname;
5131 Error_Msg_Name_2 := Id;
5132 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5133 raise Pragma_Exit;
5134 end if;
5135 end if;
5136 end Check_Identifier;
5137
5138 --------------------------------
5139 -- Check_Identifier_Is_One_Of --
5140 --------------------------------
5141
5142 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
5143 begin
5144 if Present (Arg)
5145 and then Nkind (Arg) = N_Pragma_Argument_Association
5146 then
5147 if Chars (Arg) = No_Name then
5148 Error_Msg_Name_1 := Pname;
5149 Error_Msg_N ("pragma% argument expects an identifier", Arg);
5150 raise Pragma_Exit;
5151
5152 elsif Chars (Arg) /= N1
5153 and then Chars (Arg) /= N2
5154 then
5155 Error_Msg_Name_1 := Pname;
5156 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
5157 raise Pragma_Exit;
5158 end if;
5159 end if;
5160 end Check_Identifier_Is_One_Of;
5161
5162 ---------------------------
5163 -- Check_In_Main_Program --
5164 ---------------------------
5165
5166 procedure Check_In_Main_Program is
5167 P : constant Node_Id := Parent (N);
5168
5169 begin
5170 -- Must be in subprogram body
5171
5172 if Nkind (P) /= N_Subprogram_Body then
5173 Error_Pragma ("% pragma allowed only in subprogram");
5174
5175 -- Otherwise warn if obviously not main program
5176
5177 elsif Present (Parameter_Specifications (Specification (P)))
5178 or else not Is_Compilation_Unit (Defining_Entity (P))
5179 then
5180 Error_Msg_Name_1 := Pname;
5181 Error_Msg_N
5182 ("??pragma% is only effective in main program", N);
5183 end if;
5184 end Check_In_Main_Program;
5185
5186 ---------------------------------------
5187 -- Check_Interrupt_Or_Attach_Handler --
5188 ---------------------------------------
5189
5190 procedure Check_Interrupt_Or_Attach_Handler is
5191 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
5192 Handler_Proc, Proc_Scope : Entity_Id;
5193
5194 begin
5195 Analyze (Arg1_X);
5196
5197 if Prag_Id = Pragma_Interrupt_Handler then
5198 Check_Restriction (No_Dynamic_Attachment, N);
5199 end if;
5200
5201 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
5202 Proc_Scope := Scope (Handler_Proc);
5203
5204 if Ekind (Proc_Scope) /= E_Protected_Type then
5205 Error_Pragma_Arg
5206 ("argument of pragma% must be protected procedure", Arg1);
5207 end if;
5208
5209 -- For pragma case (as opposed to access case), check placement.
5210 -- We don't need to do that for aspects, because we have the
5211 -- check that they aspect applies an appropriate procedure.
5212
5213 if not From_Aspect_Specification (N)
5214 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
5215 then
5216 Error_Pragma ("pragma% must be in protected definition");
5217 end if;
5218
5219 if not Is_Library_Level_Entity (Proc_Scope) then
5220 Error_Pragma_Arg
5221 ("argument for pragma% must be library level entity", Arg1);
5222 end if;
5223
5224 -- AI05-0033: A pragma cannot appear within a generic body, because
5225 -- instance can be in a nested scope. The check that protected type
5226 -- is itself a library-level declaration is done elsewhere.
5227
5228 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5229 -- handle code prior to AI-0033. Analysis tools typically are not
5230 -- interested in this pragma in any case, so no need to worry too
5231 -- much about its placement.
5232
5233 if Inside_A_Generic then
5234 if Ekind (Scope (Current_Scope)) = E_Generic_Package
5235 and then In_Package_Body (Scope (Current_Scope))
5236 and then not Relaxed_RM_Semantics
5237 then
5238 Error_Pragma ("pragma% cannot be used inside a generic");
5239 end if;
5240 end if;
5241 end Check_Interrupt_Or_Attach_Handler;
5242
5243 ---------------------------------
5244 -- Check_Loop_Pragma_Placement --
5245 ---------------------------------
5246
5247 procedure Check_Loop_Pragma_Placement is
5248 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
5249 -- Verify whether the current pragma is properly grouped with other
5250 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5251 -- related loop where the pragma appears.
5252
5253 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
5254 -- Determine whether an arbitrary statement Stmt denotes pragma
5255 -- Loop_Invariant or Loop_Variant.
5256
5257 procedure Placement_Error (Constr : Node_Id);
5258 pragma No_Return (Placement_Error);
5259 -- Node Constr denotes the last loop restricted construct before we
5260 -- encountered an illegal relation between enclosing constructs. Emit
5261 -- an error depending on what Constr was.
5262
5263 --------------------------------
5264 -- Check_Loop_Pragma_Grouping --
5265 --------------------------------
5266
5267 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
5268 Stop_Search : exception;
5269 -- This exception is used to terminate the recursive descent of
5270 -- routine Check_Grouping.
5271
5272 procedure Check_Grouping (L : List_Id);
5273 -- Find the first group of pragmas in list L and if successful,
5274 -- ensure that the current pragma is part of that group. The
5275 -- routine raises Stop_Search once such a check is performed to
5276 -- halt the recursive descent.
5277
5278 procedure Grouping_Error (Prag : Node_Id);
5279 pragma No_Return (Grouping_Error);
5280 -- Emit an error concerning the current pragma indicating that it
5281 -- should be placed after pragma Prag.
5282
5283 --------------------
5284 -- Check_Grouping --
5285 --------------------
5286
5287 procedure Check_Grouping (L : List_Id) is
5288 HSS : Node_Id;
5289 Prag : Node_Id;
5290 Stmt : Node_Id;
5291
5292 begin
5293 -- Inspect the list of declarations or statements looking for
5294 -- the first grouping of pragmas:
5295
5296 -- loop
5297 -- pragma Loop_Invariant ...;
5298 -- pragma Loop_Variant ...;
5299 -- . . . -- (1)
5300 -- pragma Loop_Variant ...; -- current pragma
5301
5302 -- If the current pragma is not in the grouping, then it must
5303 -- either appear in a different declarative or statement list
5304 -- or the construct at (1) is separating the pragma from the
5305 -- grouping.
5306
5307 Stmt := First (L);
5308 while Present (Stmt) loop
5309
5310 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5311 -- inside a loop or a block housed inside a loop. Inspect
5312 -- the declarations and statements of the block as they may
5313 -- contain the first grouping.
5314
5315 if Nkind (Stmt) = N_Block_Statement then
5316 HSS := Handled_Statement_Sequence (Stmt);
5317
5318 Check_Grouping (Declarations (Stmt));
5319
5320 if Present (HSS) then
5321 Check_Grouping (Statements (HSS));
5322 end if;
5323
5324 -- First pragma of the first topmost grouping has been found
5325
5326 elsif Is_Loop_Pragma (Stmt) then
5327
5328 -- The group and the current pragma are not in the same
5329 -- declarative or statement list.
5330
5331 if List_Containing (Stmt) /= List_Containing (N) then
5332 Grouping_Error (Stmt);
5333
5334 -- Try to reach the current pragma from the first pragma
5335 -- of the grouping while skipping other members:
5336
5337 -- pragma Loop_Invariant ...; -- first pragma
5338 -- pragma Loop_Variant ...; -- member
5339 -- . . .
5340 -- pragma Loop_Variant ...; -- current pragma
5341
5342 else
5343 while Present (Stmt) loop
5344
5345 -- The current pragma is either the first pragma
5346 -- of the group or is a member of the group. Stop
5347 -- the search as the placement is legal.
5348
5349 if Stmt = N then
5350 raise Stop_Search;
5351
5352 -- Skip group members, but keep track of the last
5353 -- pragma in the group.
5354
5355 elsif Is_Loop_Pragma (Stmt) then
5356 Prag := Stmt;
5357
5358 -- Skip declarations and statements generated by
5359 -- the compiler during expansion.
5360
5361 elsif not Comes_From_Source (Stmt) then
5362 null;
5363
5364 -- A non-pragma is separating the group from the
5365 -- current pragma, the placement is illegal.
5366
5367 else
5368 Grouping_Error (Prag);
5369 end if;
5370
5371 Next (Stmt);
5372 end loop;
5373
5374 -- If the traversal did not reach the current pragma,
5375 -- then the list must be malformed.
5376
5377 raise Program_Error;
5378 end if;
5379 end if;
5380
5381 Next (Stmt);
5382 end loop;
5383 end Check_Grouping;
5384
5385 --------------------
5386 -- Grouping_Error --
5387 --------------------
5388
5389 procedure Grouping_Error (Prag : Node_Id) is
5390 begin
5391 Error_Msg_Sloc := Sloc (Prag);
5392 Error_Pragma ("pragma% must appear next to pragma#");
5393 end Grouping_Error;
5394
5395 -- Start of processing for Check_Loop_Pragma_Grouping
5396
5397 begin
5398 -- Inspect the statements of the loop or nested blocks housed
5399 -- within to determine whether the current pragma is part of the
5400 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5401
5402 Check_Grouping (Statements (Loop_Stmt));
5403
5404 exception
5405 when Stop_Search => null;
5406 end Check_Loop_Pragma_Grouping;
5407
5408 --------------------
5409 -- Is_Loop_Pragma --
5410 --------------------
5411
5412 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
5413 begin
5414 -- Inspect the original node as Loop_Invariant and Loop_Variant
5415 -- pragmas are rewritten to null when assertions are disabled.
5416
5417 if Nkind (Original_Node (Stmt)) = N_Pragma then
5418 return
5419 Nam_In (Pragma_Name (Original_Node (Stmt)),
5420 Name_Loop_Invariant,
5421 Name_Loop_Variant);
5422 else
5423 return False;
5424 end if;
5425 end Is_Loop_Pragma;
5426
5427 ---------------------
5428 -- Placement_Error --
5429 ---------------------
5430
5431 procedure Placement_Error (Constr : Node_Id) is
5432 LA : constant String := " with Loop_Entry";
5433
5434 begin
5435 if Prag_Id = Pragma_Assert then
5436 Error_Msg_String (1 .. LA'Length) := LA;
5437 Error_Msg_Strlen := LA'Length;
5438 else
5439 Error_Msg_Strlen := 0;
5440 end if;
5441
5442 if Nkind (Constr) = N_Pragma then
5443 Error_Pragma
5444 ("pragma %~ must appear immediately within the statements "
5445 & "of a loop");
5446 else
5447 Error_Pragma_Arg
5448 ("block containing pragma %~ must appear immediately within "
5449 & "the statements of a loop", Constr);
5450 end if;
5451 end Placement_Error;
5452
5453 -- Local declarations
5454
5455 Prev : Node_Id;
5456 Stmt : Node_Id;
5457
5458 -- Start of processing for Check_Loop_Pragma_Placement
5459
5460 begin
5461 -- Check that pragma appears immediately within a loop statement,
5462 -- ignoring intervening block statements.
5463
5464 Prev := N;
5465 Stmt := Parent (N);
5466 while Present (Stmt) loop
5467
5468 -- The pragma or previous block must appear immediately within the
5469 -- current block's declarative or statement part.
5470
5471 if Nkind (Stmt) = N_Block_Statement then
5472 if (No (Declarations (Stmt))
5473 or else List_Containing (Prev) /= Declarations (Stmt))
5474 and then
5475 List_Containing (Prev) /=
5476 Statements (Handled_Statement_Sequence (Stmt))
5477 then
5478 Placement_Error (Prev);
5479 return;
5480
5481 -- Keep inspecting the parents because we are now within a
5482 -- chain of nested blocks.
5483
5484 else
5485 Prev := Stmt;
5486 Stmt := Parent (Stmt);
5487 end if;
5488
5489 -- The pragma or previous block must appear immediately within the
5490 -- statements of the loop.
5491
5492 elsif Nkind (Stmt) = N_Loop_Statement then
5493 if List_Containing (Prev) /= Statements (Stmt) then
5494 Placement_Error (Prev);
5495 end if;
5496
5497 -- Stop the traversal because we reached the innermost loop
5498 -- regardless of whether we encountered an error or not.
5499
5500 exit;
5501
5502 -- Ignore a handled statement sequence. Note that this node may
5503 -- be related to a subprogram body in which case we will emit an
5504 -- error on the next iteration of the search.
5505
5506 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
5507 Stmt := Parent (Stmt);
5508
5509 -- Any other statement breaks the chain from the pragma to the
5510 -- loop.
5511
5512 else
5513 Placement_Error (Prev);
5514 return;
5515 end if;
5516 end loop;
5517
5518 -- Check that the current pragma Loop_Invariant or Loop_Variant is
5519 -- grouped together with other such pragmas.
5520
5521 if Is_Loop_Pragma (N) then
5522
5523 -- The previous check should have located the related loop
5524
5525 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
5526 Check_Loop_Pragma_Grouping (Stmt);
5527 end if;
5528 end Check_Loop_Pragma_Placement;
5529
5530 -------------------------------------------
5531 -- Check_Is_In_Decl_Part_Or_Package_Spec --
5532 -------------------------------------------
5533
5534 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
5535 P : Node_Id;
5536
5537 begin
5538 P := Parent (N);
5539 loop
5540 if No (P) then
5541 exit;
5542
5543 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
5544 exit;
5545
5546 elsif Nkind_In (P, N_Package_Specification,
5547 N_Block_Statement)
5548 then
5549 return;
5550
5551 -- Note: the following tests seem a little peculiar, because
5552 -- they test for bodies, but if we were in the statement part
5553 -- of the body, we would already have hit the handled statement
5554 -- sequence, so the only way we get here is by being in the
5555 -- declarative part of the body.
5556
5557 elsif Nkind_In (P, N_Subprogram_Body,
5558 N_Package_Body,
5559 N_Task_Body,
5560 N_Entry_Body)
5561 then
5562 return;
5563 end if;
5564
5565 P := Parent (P);
5566 end loop;
5567
5568 Error_Pragma ("pragma% is not in declarative part or package spec");
5569 end Check_Is_In_Decl_Part_Or_Package_Spec;
5570
5571 -------------------------
5572 -- Check_No_Identifier --
5573 -------------------------
5574
5575 procedure Check_No_Identifier (Arg : Node_Id) is
5576 begin
5577 if Nkind (Arg) = N_Pragma_Argument_Association
5578 and then Chars (Arg) /= No_Name
5579 then
5580 Error_Pragma_Arg_Ident
5581 ("pragma% does not permit identifier& here", Arg);
5582 end if;
5583 end Check_No_Identifier;
5584
5585 --------------------------
5586 -- Check_No_Identifiers --
5587 --------------------------
5588
5589 procedure Check_No_Identifiers is
5590 Arg_Node : Node_Id;
5591 begin
5592 Arg_Node := Arg1;
5593 for J in 1 .. Arg_Count loop
5594 Check_No_Identifier (Arg_Node);
5595 Next (Arg_Node);
5596 end loop;
5597 end Check_No_Identifiers;
5598
5599 ------------------------
5600 -- Check_No_Link_Name --
5601 ------------------------
5602
5603 procedure Check_No_Link_Name is
5604 begin
5605 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
5606 Arg4 := Arg3;
5607 end if;
5608
5609 if Present (Arg4) then
5610 Error_Pragma_Arg
5611 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
5612 end if;
5613 end Check_No_Link_Name;
5614
5615 -------------------------------
5616 -- Check_Optional_Identifier --
5617 -------------------------------
5618
5619 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
5620 begin
5621 if Present (Arg)
5622 and then Nkind (Arg) = N_Pragma_Argument_Association
5623 and then Chars (Arg) /= No_Name
5624 then
5625 if Chars (Arg) /= Id then
5626 Error_Msg_Name_1 := Pname;
5627 Error_Msg_Name_2 := Id;
5628 Error_Msg_N ("pragma% argument expects identifier%", Arg);
5629 raise Pragma_Exit;
5630 end if;
5631 end if;
5632 end Check_Optional_Identifier;
5633
5634 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
5635 begin
5636 Name_Buffer (1 .. Id'Length) := Id;
5637 Name_Len := Id'Length;
5638 Check_Optional_Identifier (Arg, Name_Find);
5639 end Check_Optional_Identifier;
5640
5641 -------------------------------------
5642 -- Check_Static_Boolean_Expression --
5643 -------------------------------------
5644
5645 procedure Check_Static_Boolean_Expression (Expr : Node_Id) is
5646 begin
5647 if Present (Expr) then
5648 Analyze_And_Resolve (Expr, Standard_Boolean);
5649
5650 if not Is_OK_Static_Expression (Expr) then
5651 Error_Pragma_Arg
5652 ("expression of pragma % must be static", Expr);
5653 end if;
5654 end if;
5655 end Check_Static_Boolean_Expression;
5656
5657 -----------------------------
5658 -- Check_Static_Constraint --
5659 -----------------------------
5660
5661 -- Note: for convenience in writing this procedure, in addition to
5662 -- the officially (i.e. by spec) allowed argument which is always a
5663 -- constraint, it also allows ranges and discriminant associations.
5664 -- Above is not clear ???
5665
5666 procedure Check_Static_Constraint (Constr : Node_Id) is
5667
5668 procedure Require_Static (E : Node_Id);
5669 -- Require given expression to be static expression
5670
5671 --------------------
5672 -- Require_Static --
5673 --------------------
5674
5675 procedure Require_Static (E : Node_Id) is
5676 begin
5677 if not Is_OK_Static_Expression (E) then
5678 Flag_Non_Static_Expr
5679 ("non-static constraint not allowed in Unchecked_Union!", E);
5680 raise Pragma_Exit;
5681 end if;
5682 end Require_Static;
5683
5684 -- Start of processing for Check_Static_Constraint
5685
5686 begin
5687 case Nkind (Constr) is
5688 when N_Discriminant_Association =>
5689 Require_Static (Expression (Constr));
5690
5691 when N_Range =>
5692 Require_Static (Low_Bound (Constr));
5693 Require_Static (High_Bound (Constr));
5694
5695 when N_Attribute_Reference =>
5696 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5697 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5698
5699 when N_Range_Constraint =>
5700 Check_Static_Constraint (Range_Expression (Constr));
5701
5702 when N_Index_Or_Discriminant_Constraint =>
5703 declare
5704 IDC : Entity_Id;
5705 begin
5706 IDC := First (Constraints (Constr));
5707 while Present (IDC) loop
5708 Check_Static_Constraint (IDC);
5709 Next (IDC);
5710 end loop;
5711 end;
5712
5713 when others =>
5714 null;
5715 end case;
5716 end Check_Static_Constraint;
5717
5718 --------------------------------------
5719 -- Check_Valid_Configuration_Pragma --
5720 --------------------------------------
5721
5722 -- A configuration pragma must appear in the context clause of a
5723 -- compilation unit, and only other pragmas may precede it. Note that
5724 -- the test also allows use in a configuration pragma file.
5725
5726 procedure Check_Valid_Configuration_Pragma is
5727 begin
5728 if not Is_Configuration_Pragma then
5729 Error_Pragma ("incorrect placement for configuration pragma%");
5730 end if;
5731 end Check_Valid_Configuration_Pragma;
5732
5733 -------------------------------------
5734 -- Check_Valid_Library_Unit_Pragma --
5735 -------------------------------------
5736
5737 procedure Check_Valid_Library_Unit_Pragma is
5738 Plist : List_Id;
5739 Parent_Node : Node_Id;
5740 Unit_Name : Entity_Id;
5741 Unit_Kind : Node_Kind;
5742 Unit_Node : Node_Id;
5743 Sindex : Source_File_Index;
5744
5745 begin
5746 if not Is_List_Member (N) then
5747 Pragma_Misplaced;
5748
5749 else
5750 Plist := List_Containing (N);
5751 Parent_Node := Parent (Plist);
5752
5753 if Parent_Node = Empty then
5754 Pragma_Misplaced;
5755
5756 -- Case of pragma appearing after a compilation unit. In this case
5757 -- it must have an argument with the corresponding name and must
5758 -- be part of the following pragmas of its parent.
5759
5760 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5761 if Plist /= Pragmas_After (Parent_Node) then
5762 Pragma_Misplaced;
5763
5764 elsif Arg_Count = 0 then
5765 Error_Pragma
5766 ("argument required if outside compilation unit");
5767
5768 else
5769 Check_No_Identifiers;
5770 Check_Arg_Count (1);
5771 Unit_Node := Unit (Parent (Parent_Node));
5772 Unit_Kind := Nkind (Unit_Node);
5773
5774 Analyze (Get_Pragma_Arg (Arg1));
5775
5776 if Unit_Kind = N_Generic_Subprogram_Declaration
5777 or else Unit_Kind = N_Subprogram_Declaration
5778 then
5779 Unit_Name := Defining_Entity (Unit_Node);
5780
5781 elsif Unit_Kind in N_Generic_Instantiation then
5782 Unit_Name := Defining_Entity (Unit_Node);
5783
5784 else
5785 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5786 end if;
5787
5788 if Chars (Unit_Name) /=
5789 Chars (Entity (Get_Pragma_Arg (Arg1)))
5790 then
5791 Error_Pragma_Arg
5792 ("pragma% argument is not current unit name", Arg1);
5793 end if;
5794
5795 if Ekind (Unit_Name) = E_Package
5796 and then Present (Renamed_Entity (Unit_Name))
5797 then
5798 Error_Pragma ("pragma% not allowed for renamed package");
5799 end if;
5800 end if;
5801
5802 -- Pragma appears other than after a compilation unit
5803
5804 else
5805 -- Here we check for the generic instantiation case and also
5806 -- for the case of processing a generic formal package. We
5807 -- detect these cases by noting that the Sloc on the node
5808 -- does not belong to the current compilation unit.
5809
5810 Sindex := Source_Index (Current_Sem_Unit);
5811
5812 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5813 Rewrite (N, Make_Null_Statement (Loc));
5814 return;
5815
5816 -- If before first declaration, the pragma applies to the
5817 -- enclosing unit, and the name if present must be this name.
5818
5819 elsif Is_Before_First_Decl (N, Plist) then
5820 Unit_Node := Unit_Declaration_Node (Current_Scope);
5821 Unit_Kind := Nkind (Unit_Node);
5822
5823 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5824 Pragma_Misplaced;
5825
5826 elsif Unit_Kind = N_Subprogram_Body
5827 and then not Acts_As_Spec (Unit_Node)
5828 then
5829 Pragma_Misplaced;
5830
5831 elsif Nkind (Parent_Node) = N_Package_Body then
5832 Pragma_Misplaced;
5833
5834 elsif Nkind (Parent_Node) = N_Package_Specification
5835 and then Plist = Private_Declarations (Parent_Node)
5836 then
5837 Pragma_Misplaced;
5838
5839 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5840 or else Nkind (Parent_Node) =
5841 N_Generic_Subprogram_Declaration)
5842 and then Plist = Generic_Formal_Declarations (Parent_Node)
5843 then
5844 Pragma_Misplaced;
5845
5846 elsif Arg_Count > 0 then
5847 Analyze (Get_Pragma_Arg (Arg1));
5848
5849 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5850 Error_Pragma_Arg
5851 ("name in pragma% must be enclosing unit", Arg1);
5852 end if;
5853
5854 -- It is legal to have no argument in this context
5855
5856 else
5857 return;
5858 end if;
5859
5860 -- Error if not before first declaration. This is because a
5861 -- library unit pragma argument must be the name of a library
5862 -- unit (RM 10.1.5(7)), but the only names permitted in this
5863 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5864 -- generic subprogram declarations or generic instantiations.
5865
5866 else
5867 Error_Pragma
5868 ("pragma% misplaced, must be before first declaration");
5869 end if;
5870 end if;
5871 end if;
5872 end Check_Valid_Library_Unit_Pragma;
5873
5874 -------------------
5875 -- Check_Variant --
5876 -------------------
5877
5878 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5879 Clist : constant Node_Id := Component_List (Variant);
5880 Comp : Node_Id;
5881
5882 begin
5883 Comp := First (Component_Items (Clist));
5884 while Present (Comp) loop
5885 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5886 Next (Comp);
5887 end loop;
5888 end Check_Variant;
5889
5890 ---------------------------
5891 -- Ensure_Aggregate_Form --
5892 ---------------------------
5893
5894 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5895 CFSD : constant Boolean := Get_Comes_From_Source_Default;
5896 Expr : constant Node_Id := Expression (Arg);
5897 Loc : constant Source_Ptr := Sloc (Expr);
5898 Comps : List_Id := No_List;
5899 Exprs : List_Id := No_List;
5900 Nam : Name_Id := No_Name;
5901 Nam_Loc : Source_Ptr;
5902
5903 begin
5904 -- The pragma argument is in positional form:
5905
5906 -- pragma Depends (Nam => ...)
5907 -- ^
5908 -- Chars field
5909
5910 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5911 -- argument association.
5912
5913 if Nkind (Arg) = N_Pragma_Argument_Association then
5914 Nam := Chars (Arg);
5915 Nam_Loc := Sloc (Arg);
5916
5917 -- Remove the pragma argument name as this will be captured in the
5918 -- aggregate.
5919
5920 Set_Chars (Arg, No_Name);
5921 end if;
5922
5923 -- The argument is already in aggregate form, but the presence of a
5924 -- name causes this to be interpreted as named association which in
5925 -- turn must be converted into an aggregate.
5926
5927 -- pragma Global (In_Out => (A, B, C))
5928 -- ^ ^
5929 -- name aggregate
5930
5931 -- pragma Global ((In_Out => (A, B, C)))
5932 -- ^ ^
5933 -- aggregate aggregate
5934
5935 if Nkind (Expr) = N_Aggregate then
5936 if Nam = No_Name then
5937 return;
5938 end if;
5939
5940 -- Do not transform a null argument into an aggregate as N_Null has
5941 -- special meaning in formal verification pragmas.
5942
5943 elsif Nkind (Expr) = N_Null then
5944 return;
5945 end if;
5946
5947 -- Everything comes from source if the original comes from source
5948
5949 Set_Comes_From_Source_Default (Comes_From_Source (Arg));
5950
5951 -- Positional argument is transformed into an aggregate with an
5952 -- Expressions list.
5953
5954 if Nam = No_Name then
5955 Exprs := New_List (Relocate_Node (Expr));
5956
5957 -- An associative argument is transformed into an aggregate with
5958 -- Component_Associations.
5959
5960 else
5961 Comps := New_List (
5962 Make_Component_Association (Loc,
5963 Choices => New_List (Make_Identifier (Nam_Loc, Nam)),
5964 Expression => Relocate_Node (Expr)));
5965 end if;
5966
5967 Set_Expression (Arg,
5968 Make_Aggregate (Loc,
5969 Component_Associations => Comps,
5970 Expressions => Exprs));
5971
5972 -- Restore Comes_From_Source default
5973
5974 Set_Comes_From_Source_Default (CFSD);
5975 end Ensure_Aggregate_Form;
5976
5977 ------------------
5978 -- Error_Pragma --
5979 ------------------
5980
5981 procedure Error_Pragma (Msg : String) is
5982 begin
5983 Error_Msg_Name_1 := Pname;
5984 Error_Msg_N (Fix_Error (Msg), N);
5985 raise Pragma_Exit;
5986 end Error_Pragma;
5987
5988 ----------------------
5989 -- Error_Pragma_Arg --
5990 ----------------------
5991
5992 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5993 begin
5994 Error_Msg_Name_1 := Pname;
5995 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5996 raise Pragma_Exit;
5997 end Error_Pragma_Arg;
5998
5999 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
6000 begin
6001 Error_Msg_Name_1 := Pname;
6002 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
6003 Error_Pragma_Arg (Msg2, Arg);
6004 end Error_Pragma_Arg;
6005
6006 ----------------------------
6007 -- Error_Pragma_Arg_Ident --
6008 ----------------------------
6009
6010 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
6011 begin
6012 Error_Msg_Name_1 := Pname;
6013 Error_Msg_N (Fix_Error (Msg), Arg);
6014 raise Pragma_Exit;
6015 end Error_Pragma_Arg_Ident;
6016
6017 ----------------------
6018 -- Error_Pragma_Ref --
6019 ----------------------
6020
6021 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
6022 begin
6023 Error_Msg_Name_1 := Pname;
6024 Error_Msg_Sloc := Sloc (Ref);
6025 Error_Msg_NE (Fix_Error (Msg), N, Ref);
6026 raise Pragma_Exit;
6027 end Error_Pragma_Ref;
6028
6029 ------------------------
6030 -- Find_Lib_Unit_Name --
6031 ------------------------
6032
6033 function Find_Lib_Unit_Name return Entity_Id is
6034 begin
6035 -- Return inner compilation unit entity, for case of nested
6036 -- categorization pragmas. This happens in generic unit.
6037
6038 if Nkind (Parent (N)) = N_Package_Specification
6039 and then Defining_Entity (Parent (N)) /= Current_Scope
6040 then
6041 return Defining_Entity (Parent (N));
6042 else
6043 return Current_Scope;
6044 end if;
6045 end Find_Lib_Unit_Name;
6046
6047 ----------------------------
6048 -- Find_Program_Unit_Name --
6049 ----------------------------
6050
6051 procedure Find_Program_Unit_Name (Id : Node_Id) is
6052 Unit_Name : Entity_Id;
6053 Unit_Kind : Node_Kind;
6054 P : constant Node_Id := Parent (N);
6055
6056 begin
6057 if Nkind (P) = N_Compilation_Unit then
6058 Unit_Kind := Nkind (Unit (P));
6059
6060 if Nkind_In (Unit_Kind, N_Subprogram_Declaration,
6061 N_Package_Declaration)
6062 or else Unit_Kind in N_Generic_Declaration
6063 then
6064 Unit_Name := Defining_Entity (Unit (P));
6065
6066 if Chars (Id) = Chars (Unit_Name) then
6067 Set_Entity (Id, Unit_Name);
6068 Set_Etype (Id, Etype (Unit_Name));
6069 else
6070 Set_Etype (Id, Any_Type);
6071 Error_Pragma
6072 ("cannot find program unit referenced by pragma%");
6073 end if;
6074
6075 else
6076 Set_Etype (Id, Any_Type);
6077 Error_Pragma ("pragma% inapplicable to this unit");
6078 end if;
6079
6080 else
6081 Analyze (Id);
6082 end if;
6083 end Find_Program_Unit_Name;
6084
6085 -----------------------------------------
6086 -- Find_Unique_Parameterless_Procedure --
6087 -----------------------------------------
6088
6089 function Find_Unique_Parameterless_Procedure
6090 (Name : Entity_Id;
6091 Arg : Node_Id) return Entity_Id
6092 is
6093 Proc : Entity_Id := Empty;
6094
6095 begin
6096 -- The body of this procedure needs some comments ???
6097
6098 if not Is_Entity_Name (Name) then
6099 Error_Pragma_Arg
6100 ("argument of pragma% must be entity name", Arg);
6101
6102 elsif not Is_Overloaded (Name) then
6103 Proc := Entity (Name);
6104
6105 if Ekind (Proc) /= E_Procedure
6106 or else Present (First_Formal (Proc))
6107 then
6108 Error_Pragma_Arg
6109 ("argument of pragma% must be parameterless procedure", Arg);
6110 end if;
6111
6112 else
6113 declare
6114 Found : Boolean := False;
6115 It : Interp;
6116 Index : Interp_Index;
6117
6118 begin
6119 Get_First_Interp (Name, Index, It);
6120 while Present (It.Nam) loop
6121 Proc := It.Nam;
6122
6123 if Ekind (Proc) = E_Procedure
6124 and then No (First_Formal (Proc))
6125 then
6126 if not Found then
6127 Found := True;
6128 Set_Entity (Name, Proc);
6129 Set_Is_Overloaded (Name, False);
6130 else
6131 Error_Pragma_Arg
6132 ("ambiguous handler name for pragma% ", Arg);
6133 end if;
6134 end if;
6135
6136 Get_Next_Interp (Index, It);
6137 end loop;
6138
6139 if not Found then
6140 Error_Pragma_Arg
6141 ("argument of pragma% must be parameterless procedure",
6142 Arg);
6143 else
6144 Proc := Entity (Name);
6145 end if;
6146 end;
6147 end if;
6148
6149 return Proc;
6150 end Find_Unique_Parameterless_Procedure;
6151
6152 ---------------
6153 -- Fix_Error --
6154 ---------------
6155
6156 function Fix_Error (Msg : String) return String is
6157 Res : String (Msg'Range) := Msg;
6158 Res_Last : Natural := Msg'Last;
6159 J : Natural;
6160
6161 begin
6162 -- If we have a rewriting of another pragma, go to that pragma
6163
6164 if Is_Rewrite_Substitution (N)
6165 and then Nkind (Original_Node (N)) = N_Pragma
6166 then
6167 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
6168 end if;
6169
6170 -- Case where pragma comes from an aspect specification
6171
6172 if From_Aspect_Specification (N) then
6173
6174 -- Change appearence of "pragma" in message to "aspect"
6175
6176 J := Res'First;
6177 while J <= Res_Last - 5 loop
6178 if Res (J .. J + 5) = "pragma" then
6179 Res (J .. J + 5) := "aspect";
6180 J := J + 6;
6181
6182 else
6183 J := J + 1;
6184 end if;
6185 end loop;
6186
6187 -- Change "argument of" at start of message to "entity for"
6188
6189 if Res'Length > 11
6190 and then Res (Res'First .. Res'First + 10) = "argument of"
6191 then
6192 Res (Res'First .. Res'First + 9) := "entity for";
6193 Res (Res'First + 10 .. Res_Last - 1) :=
6194 Res (Res'First + 11 .. Res_Last);
6195 Res_Last := Res_Last - 1;
6196 end if;
6197
6198 -- Change "argument" at start of message to "entity"
6199
6200 if Res'Length > 8
6201 and then Res (Res'First .. Res'First + 7) = "argument"
6202 then
6203 Res (Res'First .. Res'First + 5) := "entity";
6204 Res (Res'First + 6 .. Res_Last - 2) :=
6205 Res (Res'First + 8 .. Res_Last);
6206 Res_Last := Res_Last - 2;
6207 end if;
6208
6209 -- Get name from corresponding aspect
6210
6211 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
6212 end if;
6213
6214 -- Return possibly modified message
6215
6216 return Res (Res'First .. Res_Last);
6217 end Fix_Error;
6218
6219 -------------------------
6220 -- Gather_Associations --
6221 -------------------------
6222
6223 procedure Gather_Associations
6224 (Names : Name_List;
6225 Args : out Args_List)
6226 is
6227 Arg : Node_Id;
6228
6229 begin
6230 -- Initialize all parameters to Empty
6231
6232 for J in Args'Range loop
6233 Args (J) := Empty;
6234 end loop;
6235
6236 -- That's all we have to do if there are no argument associations
6237
6238 if No (Pragma_Argument_Associations (N)) then
6239 return;
6240 end if;
6241
6242 -- Otherwise first deal with any positional parameters present
6243
6244 Arg := First (Pragma_Argument_Associations (N));
6245 for Index in Args'Range loop
6246 exit when No (Arg) or else Chars (Arg) /= No_Name;
6247 Args (Index) := Get_Pragma_Arg (Arg);
6248 Next (Arg);
6249 end loop;
6250
6251 -- Positional parameters all processed, if any left, then we
6252 -- have too many positional parameters.
6253
6254 if Present (Arg) and then Chars (Arg) = No_Name then
6255 Error_Pragma_Arg
6256 ("too many positional associations for pragma%", Arg);
6257 end if;
6258
6259 -- Process named parameters if any are present
6260
6261 while Present (Arg) loop
6262 if Chars (Arg) = No_Name then
6263 Error_Pragma_Arg
6264 ("positional association cannot follow named association",
6265 Arg);
6266
6267 else
6268 for Index in Names'Range loop
6269 if Names (Index) = Chars (Arg) then
6270 if Present (Args (Index)) then
6271 Error_Pragma_Arg
6272 ("duplicate argument association for pragma%", Arg);
6273 else
6274 Args (Index) := Get_Pragma_Arg (Arg);
6275 exit;
6276 end if;
6277 end if;
6278
6279 if Index = Names'Last then
6280 Error_Msg_Name_1 := Pname;
6281 Error_Msg_N ("pragma% does not allow & argument", Arg);
6282
6283 -- Check for possible misspelling
6284
6285 for Index1 in Names'Range loop
6286 if Is_Bad_Spelling_Of
6287 (Chars (Arg), Names (Index1))
6288 then
6289 Error_Msg_Name_1 := Names (Index1);
6290 Error_Msg_N -- CODEFIX
6291 ("\possible misspelling of%", Arg);
6292 exit;
6293 end if;
6294 end loop;
6295
6296 raise Pragma_Exit;
6297 end if;
6298 end loop;
6299 end if;
6300
6301 Next (Arg);
6302 end loop;
6303 end Gather_Associations;
6304
6305 -----------------
6306 -- GNAT_Pragma --
6307 -----------------
6308
6309 procedure GNAT_Pragma is
6310 begin
6311 -- We need to check the No_Implementation_Pragmas restriction for
6312 -- the case of a pragma from source. Note that the case of aspects
6313 -- generating corresponding pragmas marks these pragmas as not being
6314 -- from source, so this test also catches that case.
6315
6316 if Comes_From_Source (N) then
6317 Check_Restriction (No_Implementation_Pragmas, N);
6318 end if;
6319 end GNAT_Pragma;
6320
6321 --------------------------
6322 -- Is_Before_First_Decl --
6323 --------------------------
6324
6325 function Is_Before_First_Decl
6326 (Pragma_Node : Node_Id;
6327 Decls : List_Id) return Boolean
6328 is
6329 Item : Node_Id := First (Decls);
6330
6331 begin
6332 -- Only other pragmas can come before this pragma
6333
6334 loop
6335 if No (Item) or else Nkind (Item) /= N_Pragma then
6336 return False;
6337
6338 elsif Item = Pragma_Node then
6339 return True;
6340 end if;
6341
6342 Next (Item);
6343 end loop;
6344 end Is_Before_First_Decl;
6345
6346 -----------------------------
6347 -- Is_Configuration_Pragma --
6348 -----------------------------
6349
6350 -- A configuration pragma must appear in the context clause of a
6351 -- compilation unit, and only other pragmas may precede it. Note that
6352 -- the test below also permits use in a configuration pragma file.
6353
6354 function Is_Configuration_Pragma return Boolean is
6355 Lis : constant List_Id := List_Containing (N);
6356 Par : constant Node_Id := Parent (N);
6357 Prg : Node_Id;
6358
6359 begin
6360 -- If no parent, then we are in the configuration pragma file,
6361 -- so the placement is definitely appropriate.
6362
6363 if No (Par) then
6364 return True;
6365
6366 -- Otherwise we must be in the context clause of a compilation unit
6367 -- and the only thing allowed before us in the context list is more
6368 -- configuration pragmas.
6369
6370 elsif Nkind (Par) = N_Compilation_Unit
6371 and then Context_Items (Par) = Lis
6372 then
6373 Prg := First (Lis);
6374
6375 loop
6376 if Prg = N then
6377 return True;
6378 elsif Nkind (Prg) /= N_Pragma then
6379 return False;
6380 end if;
6381
6382 Next (Prg);
6383 end loop;
6384
6385 else
6386 return False;
6387 end if;
6388 end Is_Configuration_Pragma;
6389
6390 --------------------------
6391 -- Is_In_Context_Clause --
6392 --------------------------
6393
6394 function Is_In_Context_Clause return Boolean is
6395 Plist : List_Id;
6396 Parent_Node : Node_Id;
6397
6398 begin
6399 if not Is_List_Member (N) then
6400 return False;
6401
6402 else
6403 Plist := List_Containing (N);
6404 Parent_Node := Parent (Plist);
6405
6406 if Parent_Node = Empty
6407 or else Nkind (Parent_Node) /= N_Compilation_Unit
6408 or else Context_Items (Parent_Node) /= Plist
6409 then
6410 return False;
6411 end if;
6412 end if;
6413
6414 return True;
6415 end Is_In_Context_Clause;
6416
6417 ---------------------------------
6418 -- Is_Static_String_Expression --
6419 ---------------------------------
6420
6421 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6422 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6423 Lit : constant Boolean := Nkind (Argx) = N_String_Literal;
6424
6425 begin
6426 Analyze_And_Resolve (Argx);
6427
6428 -- Special case Ada 83, where the expression will never be static,
6429 -- but we will return true if we had a string literal to start with.
6430
6431 if Ada_Version = Ada_83 then
6432 return Lit;
6433
6434 -- Normal case, true only if we end up with a string literal that
6435 -- is marked as being the result of evaluating a static expression.
6436
6437 else
6438 return Is_OK_Static_Expression (Argx)
6439 and then Nkind (Argx) = N_String_Literal;
6440 end if;
6441
6442 end Is_Static_String_Expression;
6443
6444 ----------------------
6445 -- Pragma_Misplaced --
6446 ----------------------
6447
6448 procedure Pragma_Misplaced is
6449 begin
6450 Error_Pragma ("incorrect placement of pragma%");
6451 end Pragma_Misplaced;
6452
6453 ------------------------------------------------
6454 -- Process_Atomic_Independent_Shared_Volatile --
6455 ------------------------------------------------
6456
6457 procedure Process_Atomic_Independent_Shared_Volatile is
6458 procedure Set_Atomic_VFA (E : Entity_Id);
6459 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6460 -- no explicit alignment was given, set alignment to unknown, since
6461 -- back end knows what the alignment requirements are for atomic and
6462 -- full access arrays. Note: this is necessary for derived types.
6463
6464 --------------------
6465 -- Set_Atomic_VFA --
6466 --------------------
6467
6468 procedure Set_Atomic_VFA (E : Entity_Id) is
6469 begin
6470 if Prag_Id = Pragma_Volatile_Full_Access then
6471 Set_Is_Volatile_Full_Access (E);
6472 else
6473 Set_Is_Atomic (E);
6474 end if;
6475
6476 if not Has_Alignment_Clause (E) then
6477 Set_Alignment (E, Uint_0);
6478 end if;
6479 end Set_Atomic_VFA;
6480
6481 -- Local variables
6482
6483 Decl : Node_Id;
6484 E : Entity_Id;
6485 E_Arg : Node_Id;
6486
6487 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6488
6489 begin
6490 Check_Ada_83_Warning;
6491 Check_No_Identifiers;
6492 Check_Arg_Count (1);
6493 Check_Arg_Is_Local_Name (Arg1);
6494 E_Arg := Get_Pragma_Arg (Arg1);
6495
6496 if Etype (E_Arg) = Any_Type then
6497 return;
6498 end if;
6499
6500 E := Entity (E_Arg);
6501 Decl := Declaration_Node (E);
6502
6503 -- A pragma that applies to a Ghost entity becomes Ghost for the
6504 -- purposes of legality checks and removal of ignored Ghost code.
6505
6506 Mark_Pragma_As_Ghost (N, E);
6507
6508 -- Check duplicate before we chain ourselves
6509
6510 Check_Duplicate_Pragma (E);
6511
6512 -- Check Atomic and VFA used together
6513
6514 if (Is_Atomic (E) and then Prag_Id = Pragma_Volatile_Full_Access)
6515 or else (Is_Volatile_Full_Access (E)
6516 and then (Prag_Id = Pragma_Atomic
6517 or else
6518 Prag_Id = Pragma_Shared))
6519 then
6520 Error_Pragma
6521 ("cannot have Volatile_Full_Access and Atomic for same entity");
6522 end if;
6523
6524 -- Check for applying VFA to an entity which has aliased component
6525
6526 if Prag_Id = Pragma_Volatile_Full_Access then
6527 declare
6528 Comp : Entity_Id;
6529 Aliased_Comp : Boolean := False;
6530 -- Set True if aliased component present
6531
6532 begin
6533 if Is_Array_Type (Etype (E)) then
6534 Aliased_Comp := Has_Aliased_Components (Etype (E));
6535
6536 -- Record case, too bad Has_Aliased_Components is not also
6537 -- set for records, should it be ???
6538
6539 elsif Is_Record_Type (Etype (E)) then
6540 Comp := First_Component_Or_Discriminant (Etype (E));
6541 while Present (Comp) loop
6542 if Is_Aliased (Comp)
6543 or else Is_Aliased (Etype (Comp))
6544 then
6545 Aliased_Comp := True;
6546 exit;
6547 end if;
6548
6549 Next_Component_Or_Discriminant (Comp);
6550 end loop;
6551 end if;
6552
6553 if Aliased_Comp then
6554 Error_Pragma
6555 ("cannot apply Volatile_Full_Access (aliased component "
6556 & "present)");
6557 end if;
6558 end;
6559 end if;
6560
6561 -- Now check appropriateness of the entity
6562
6563 if Is_Type (E) then
6564 if Rep_Item_Too_Early (E, N)
6565 or else
6566 Rep_Item_Too_Late (E, N)
6567 then
6568 return;
6569 else
6570 Check_First_Subtype (Arg1);
6571 end if;
6572
6573 -- Attribute belongs on the base type. If the view of the type is
6574 -- currently private, it also belongs on the underlying type.
6575
6576 if Prag_Id = Pragma_Atomic
6577 or else
6578 Prag_Id = Pragma_Shared
6579 or else
6580 Prag_Id = Pragma_Volatile_Full_Access
6581 then
6582 Set_Atomic_VFA (E);
6583 Set_Atomic_VFA (Base_Type (E));
6584 Set_Atomic_VFA (Underlying_Type (E));
6585 end if;
6586
6587 -- Atomic/Shared/Volatile_Full_Access imply Independent
6588
6589 if Prag_Id /= Pragma_Volatile then
6590 Set_Is_Independent (E);
6591 Set_Is_Independent (Base_Type (E));
6592 Set_Is_Independent (Underlying_Type (E));
6593
6594 if Prag_Id = Pragma_Independent then
6595 Record_Independence_Check (N, Base_Type (E));
6596 end if;
6597 end if;
6598
6599 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6600
6601 if Prag_Id /= Pragma_Independent then
6602 Set_Is_Volatile (E);
6603 Set_Is_Volatile (Base_Type (E));
6604 Set_Is_Volatile (Underlying_Type (E));
6605
6606 Set_Treat_As_Volatile (E);
6607 Set_Treat_As_Volatile (Underlying_Type (E));
6608 end if;
6609
6610 elsif Nkind (Decl) = N_Object_Declaration
6611 or else (Nkind (Decl) = N_Component_Declaration
6612 and then Original_Record_Component (E) = E)
6613 then
6614 if Rep_Item_Too_Late (E, N) then
6615 return;
6616 end if;
6617
6618 if Prag_Id = Pragma_Atomic
6619 or else
6620 Prag_Id = Pragma_Shared
6621 or else
6622 Prag_Id = Pragma_Volatile_Full_Access
6623 then
6624 if Prag_Id = Pragma_Volatile_Full_Access then
6625 Set_Is_Volatile_Full_Access (E);
6626 else
6627 Set_Is_Atomic (E);
6628 end if;
6629
6630 -- If the object declaration has an explicit initialization, a
6631 -- temporary may have to be created to hold the expression, to
6632 -- ensure that access to the object remain atomic.
6633
6634 if Nkind (Parent (E)) = N_Object_Declaration
6635 and then Present (Expression (Parent (E)))
6636 then
6637 Set_Has_Delayed_Freeze (E);
6638 end if;
6639 end if;
6640
6641 -- Atomic/Shared/Volatile_Full_Access imply Independent
6642
6643 if Prag_Id /= Pragma_Volatile then
6644 Set_Is_Independent (E);
6645
6646 if Prag_Id = Pragma_Independent then
6647 Record_Independence_Check (N, E);
6648 end if;
6649 end if;
6650
6651 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6652
6653 if Prag_Id /= Pragma_Independent then
6654 Set_Is_Volatile (E);
6655 Set_Treat_As_Volatile (E);
6656 end if;
6657
6658 else
6659 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6660 end if;
6661
6662 -- The following check is only relevant when SPARK_Mode is on as
6663 -- this is not a standard Ada legality rule. Pragma Volatile can
6664 -- only apply to a full type declaration or an object declaration
6665 -- (SPARK RM C.6(1)). Original_Node is necessary to account for
6666 -- untagged derived types that are rewritten as subtypes of their
6667 -- respective root types.
6668
6669 if SPARK_Mode = On
6670 and then Prag_Id = Pragma_Volatile
6671 and then
6672 not Nkind_In (Original_Node (Decl), N_Full_Type_Declaration,
6673 N_Object_Declaration)
6674 then
6675 Error_Pragma_Arg
6676 ("argument of pragma % must denote a full type or object "
6677 & "declaration", Arg1);
6678 end if;
6679 end Process_Atomic_Independent_Shared_Volatile;
6680
6681 -------------------------------------------
6682 -- Process_Compile_Time_Warning_Or_Error --
6683 -------------------------------------------
6684
6685 procedure Process_Compile_Time_Warning_Or_Error is
6686 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
6687
6688 begin
6689 Check_Arg_Count (2);
6690 Check_No_Identifiers;
6691 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
6692 Analyze_And_Resolve (Arg1x, Standard_Boolean);
6693
6694 if Compile_Time_Known_Value (Arg1x) then
6695 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6696 declare
6697 Str : constant String_Id :=
6698 Strval (Get_Pragma_Arg (Arg2));
6699 Len : constant Nat := String_Length (Str);
6700 Cont : Boolean;
6701 Ptr : Nat;
6702 CC : Char_Code;
6703 C : Character;
6704 Cent : constant Entity_Id :=
6705 Cunit_Entity (Current_Sem_Unit);
6706
6707 Force : constant Boolean :=
6708 Prag_Id = Pragma_Compile_Time_Warning
6709 and then
6710 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6711 and then (Ekind (Cent) /= E_Package
6712 or else not In_Private_Part (Cent));
6713 -- Set True if this is the warning case, and we are in the
6714 -- visible part of a package spec, or in a subprogram spec,
6715 -- in which case we want to force the client to see the
6716 -- warning, even though it is not in the main unit.
6717
6718 begin
6719 -- Loop through segments of message separated by line feeds.
6720 -- We output these segments as separate messages with
6721 -- continuation marks for all but the first.
6722
6723 Cont := False;
6724 Ptr := 1;
6725 loop
6726 Error_Msg_Strlen := 0;
6727
6728 -- Loop to copy characters from argument to error message
6729 -- string buffer.
6730
6731 loop
6732 exit when Ptr > Len;
6733 CC := Get_String_Char (Str, Ptr);
6734 Ptr := Ptr + 1;
6735
6736 -- Ignore wide chars ??? else store character
6737
6738 if In_Character_Range (CC) then
6739 C := Get_Character (CC);
6740 exit when C = ASCII.LF;
6741 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6742 Error_Msg_String (Error_Msg_Strlen) := C;
6743 end if;
6744 end loop;
6745
6746 -- Here with one line ready to go
6747
6748 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6749
6750 -- If this is a warning in a spec, then we want clients
6751 -- to see the warning, so mark the message with the
6752 -- special sequence !! to force the warning. In the case
6753 -- of a package spec, we do not force this if we are in
6754 -- the private part of the spec.
6755
6756 if Force then
6757 if Cont = False then
6758 Error_Msg_N ("<<~!!", Arg1);
6759 Cont := True;
6760 else
6761 Error_Msg_N ("\<<~!!", Arg1);
6762 end if;
6763
6764 -- Error, rather than warning, or in a body, so we do not
6765 -- need to force visibility for client (error will be
6766 -- output in any case, and this is the situation in which
6767 -- we do not want a client to get a warning, since the
6768 -- warning is in the body or the spec private part).
6769
6770 else
6771 if Cont = False then
6772 Error_Msg_N ("<<~", Arg1);
6773 Cont := True;
6774 else
6775 Error_Msg_N ("\<<~", Arg1);
6776 end if;
6777 end if;
6778
6779 exit when Ptr > Len;
6780 end loop;
6781 end;
6782 end if;
6783 end if;
6784 end Process_Compile_Time_Warning_Or_Error;
6785
6786 ------------------------
6787 -- Process_Convention --
6788 ------------------------
6789
6790 procedure Process_Convention
6791 (C : out Convention_Id;
6792 Ent : out Entity_Id)
6793 is
6794 Cname : Name_Id;
6795
6796 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6797 -- Called if we have more than one Export/Import/Convention pragma.
6798 -- This is generally illegal, but we have a special case of allowing
6799 -- Import and Interface to coexist if they specify the convention in
6800 -- a consistent manner. We are allowed to do this, since Interface is
6801 -- an implementation defined pragma, and we choose to do it since we
6802 -- know Rational allows this combination. S is the entity id of the
6803 -- subprogram in question. This procedure also sets the special flag
6804 -- Import_Interface_Present in both pragmas in the case where we do
6805 -- have matching Import and Interface pragmas.
6806
6807 procedure Set_Convention_From_Pragma (E : Entity_Id);
6808 -- Set convention in entity E, and also flag that the entity has a
6809 -- convention pragma. If entity is for a private or incomplete type,
6810 -- also set convention and flag on underlying type. This procedure
6811 -- also deals with the special case of C_Pass_By_Copy convention,
6812 -- and error checks for inappropriate convention specification.
6813
6814 -------------------------------
6815 -- Diagnose_Multiple_Pragmas --
6816 -------------------------------
6817
6818 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6819 Pdec : constant Node_Id := Declaration_Node (S);
6820 Decl : Node_Id;
6821 Err : Boolean;
6822
6823 function Same_Convention (Decl : Node_Id) return Boolean;
6824 -- Decl is a pragma node. This function returns True if this
6825 -- pragma has a first argument that is an identifier with a
6826 -- Chars field corresponding to the Convention_Id C.
6827
6828 function Same_Name (Decl : Node_Id) return Boolean;
6829 -- Decl is a pragma node. This function returns True if this
6830 -- pragma has a second argument that is an identifier with a
6831 -- Chars field that matches the Chars of the current subprogram.
6832
6833 ---------------------
6834 -- Same_Convention --
6835 ---------------------
6836
6837 function Same_Convention (Decl : Node_Id) return Boolean is
6838 Arg1 : constant Node_Id :=
6839 First (Pragma_Argument_Associations (Decl));
6840
6841 begin
6842 if Present (Arg1) then
6843 declare
6844 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6845 begin
6846 if Nkind (Arg) = N_Identifier
6847 and then Is_Convention_Name (Chars (Arg))
6848 and then Get_Convention_Id (Chars (Arg)) = C
6849 then
6850 return True;
6851 end if;
6852 end;
6853 end if;
6854
6855 return False;
6856 end Same_Convention;
6857
6858 ---------------
6859 -- Same_Name --
6860 ---------------
6861
6862 function Same_Name (Decl : Node_Id) return Boolean is
6863 Arg1 : constant Node_Id :=
6864 First (Pragma_Argument_Associations (Decl));
6865 Arg2 : Node_Id;
6866
6867 begin
6868 if No (Arg1) then
6869 return False;
6870 end if;
6871
6872 Arg2 := Next (Arg1);
6873
6874 if No (Arg2) then
6875 return False;
6876 end if;
6877
6878 declare
6879 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6880 begin
6881 if Nkind (Arg) = N_Identifier
6882 and then Chars (Arg) = Chars (S)
6883 then
6884 return True;
6885 end if;
6886 end;
6887
6888 return False;
6889 end Same_Name;
6890
6891 -- Start of processing for Diagnose_Multiple_Pragmas
6892
6893 begin
6894 Err := True;
6895
6896 -- Definitely give message if we have Convention/Export here
6897
6898 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6899 null;
6900
6901 -- If we have an Import or Export, scan back from pragma to
6902 -- find any previous pragma applying to the same procedure.
6903 -- The scan will be terminated by the start of the list, or
6904 -- hitting the subprogram declaration. This won't allow one
6905 -- pragma to appear in the public part and one in the private
6906 -- part, but that seems very unlikely in practice.
6907
6908 else
6909 Decl := Prev (N);
6910 while Present (Decl) and then Decl /= Pdec loop
6911
6912 -- Look for pragma with same name as us
6913
6914 if Nkind (Decl) = N_Pragma
6915 and then Same_Name (Decl)
6916 then
6917 -- Give error if same as our pragma or Export/Convention
6918
6919 if Nam_In (Pragma_Name (Decl), Name_Export,
6920 Name_Convention,
6921 Pragma_Name (N))
6922 then
6923 exit;
6924
6925 -- Case of Import/Interface or the other way round
6926
6927 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6928 Name_Import)
6929 then
6930 -- Here we know that we have Import and Interface. It
6931 -- doesn't matter which way round they are. See if
6932 -- they specify the same convention. If so, all OK,
6933 -- and set special flags to stop other messages
6934
6935 if Same_Convention (Decl) then
6936 Set_Import_Interface_Present (N);
6937 Set_Import_Interface_Present (Decl);
6938 Err := False;
6939
6940 -- If different conventions, special message
6941
6942 else
6943 Error_Msg_Sloc := Sloc (Decl);
6944 Error_Pragma_Arg
6945 ("convention differs from that given#", Arg1);
6946 return;
6947 end if;
6948 end if;
6949 end if;
6950
6951 Next (Decl);
6952 end loop;
6953 end if;
6954
6955 -- Give message if needed if we fall through those tests
6956 -- except on Relaxed_RM_Semantics where we let go: either this
6957 -- is a case accepted/ignored by other Ada compilers (e.g.
6958 -- a mix of Convention and Import), or another error will be
6959 -- generated later (e.g. using both Import and Export).
6960
6961 if Err and not Relaxed_RM_Semantics then
6962 Error_Pragma_Arg
6963 ("at most one Convention/Export/Import pragma is allowed",
6964 Arg2);
6965 end if;
6966 end Diagnose_Multiple_Pragmas;
6967
6968 --------------------------------
6969 -- Set_Convention_From_Pragma --
6970 --------------------------------
6971
6972 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6973 begin
6974 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6975 -- for an overridden dispatching operation. Technically this is
6976 -- an amendment and should only be done in Ada 2005 mode. However,
6977 -- this is clearly a mistake, since the problem that is addressed
6978 -- by this AI is that there is a clear gap in the RM.
6979
6980 if Is_Dispatching_Operation (E)
6981 and then Present (Overridden_Operation (E))
6982 and then C /= Convention (Overridden_Operation (E))
6983 then
6984 Error_Pragma_Arg
6985 ("cannot change convention for overridden dispatching "
6986 & "operation", Arg1);
6987 end if;
6988
6989 -- Special checks for Convention_Stdcall
6990
6991 if C = Convention_Stdcall then
6992
6993 -- A dispatching call is not allowed. A dispatching subprogram
6994 -- cannot be used to interface to the Win32 API, so in fact
6995 -- this check does not impose any effective restriction.
6996
6997 if Is_Dispatching_Operation (E) then
6998 Error_Msg_Sloc := Sloc (E);
6999
7000 -- Note: make this unconditional so that if there is more
7001 -- than one call to which the pragma applies, we get a
7002 -- message for each call. Also don't use Error_Pragma,
7003 -- so that we get multiple messages.
7004
7005 Error_Msg_N
7006 ("dispatching subprogram# cannot use Stdcall convention!",
7007 Arg1);
7008
7009 -- Subprograms are not allowed
7010
7011 elsif not Is_Subprogram_Or_Generic_Subprogram (E)
7012
7013 -- A variable is OK
7014
7015 and then Ekind (E) /= E_Variable
7016
7017 -- An access to subprogram is also allowed
7018
7019 and then not
7020 (Is_Access_Type (E)
7021 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
7022
7023 -- Allow internal call to set convention of subprogram type
7024
7025 and then not (Ekind (E) = E_Subprogram_Type)
7026 then
7027 Error_Pragma_Arg
7028 ("second argument of pragma% must be subprogram (type)",
7029 Arg2);
7030 end if;
7031 end if;
7032
7033 -- Set the convention
7034
7035 Set_Convention (E, C);
7036 Set_Has_Convention_Pragma (E);
7037
7038 -- For the case of a record base type, also set the convention of
7039 -- any anonymous access types declared in the record which do not
7040 -- currently have a specified convention.
7041
7042 if Is_Record_Type (E) and then Is_Base_Type (E) then
7043 declare
7044 Comp : Node_Id;
7045
7046 begin
7047 Comp := First_Component (E);
7048 while Present (Comp) loop
7049 if Present (Etype (Comp))
7050 and then Ekind_In (Etype (Comp),
7051 E_Anonymous_Access_Type,
7052 E_Anonymous_Access_Subprogram_Type)
7053 and then not Has_Convention_Pragma (Comp)
7054 then
7055 Set_Convention (Comp, C);
7056 end if;
7057
7058 Next_Component (Comp);
7059 end loop;
7060 end;
7061 end if;
7062
7063 -- Deal with incomplete/private type case, where underlying type
7064 -- is available, so set convention of that underlying type.
7065
7066 if Is_Incomplete_Or_Private_Type (E)
7067 and then Present (Underlying_Type (E))
7068 then
7069 Set_Convention (Underlying_Type (E), C);
7070 Set_Has_Convention_Pragma (Underlying_Type (E), True);
7071 end if;
7072
7073 -- A class-wide type should inherit the convention of the specific
7074 -- root type (although this isn't specified clearly by the RM).
7075
7076 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
7077 Set_Convention (Class_Wide_Type (E), C);
7078 end if;
7079
7080 -- If the entity is a record type, then check for special case of
7081 -- C_Pass_By_Copy, which is treated the same as C except that the
7082 -- special record flag is set. This convention is only permitted
7083 -- on record types (see AI95-00131).
7084
7085 if Cname = Name_C_Pass_By_Copy then
7086 if Is_Record_Type (E) then
7087 Set_C_Pass_By_Copy (Base_Type (E));
7088 elsif Is_Incomplete_Or_Private_Type (E)
7089 and then Is_Record_Type (Underlying_Type (E))
7090 then
7091 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
7092 else
7093 Error_Pragma_Arg
7094 ("C_Pass_By_Copy convention allowed only for record type",
7095 Arg2);
7096 end if;
7097 end if;
7098
7099 -- If the entity is a derived boolean type, check for the special
7100 -- case of convention C, C++, or Fortran, where we consider any
7101 -- nonzero value to represent true.
7102
7103 if Is_Discrete_Type (E)
7104 and then Root_Type (Etype (E)) = Standard_Boolean
7105 and then
7106 (C = Convention_C
7107 or else
7108 C = Convention_CPP
7109 or else
7110 C = Convention_Fortran)
7111 then
7112 Set_Nonzero_Is_True (Base_Type (E));
7113 end if;
7114 end Set_Convention_From_Pragma;
7115
7116 -- Local variables
7117
7118 Comp_Unit : Unit_Number_Type;
7119 E : Entity_Id;
7120 E1 : Entity_Id;
7121 Id : Node_Id;
7122
7123 -- Start of processing for Process_Convention
7124
7125 begin
7126 Check_At_Least_N_Arguments (2);
7127 Check_Optional_Identifier (Arg1, Name_Convention);
7128 Check_Arg_Is_Identifier (Arg1);
7129 Cname := Chars (Get_Pragma_Arg (Arg1));
7130
7131 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7132 -- tested again below to set the critical flag).
7133
7134 if Cname = Name_C_Pass_By_Copy then
7135 C := Convention_C;
7136
7137 -- Otherwise we must have something in the standard convention list
7138
7139 elsif Is_Convention_Name (Cname) then
7140 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
7141
7142 -- Otherwise warn on unrecognized convention
7143
7144 else
7145 if Warn_On_Export_Import then
7146 Error_Msg_N
7147 ("??unrecognized convention name, C assumed",
7148 Get_Pragma_Arg (Arg1));
7149 end if;
7150
7151 C := Convention_C;
7152 end if;
7153
7154 Check_Optional_Identifier (Arg2, Name_Entity);
7155 Check_Arg_Is_Local_Name (Arg2);
7156
7157 Id := Get_Pragma_Arg (Arg2);
7158 Analyze (Id);
7159
7160 if not Is_Entity_Name (Id) then
7161 Error_Pragma_Arg ("entity name required", Arg2);
7162 end if;
7163
7164 E := Entity (Id);
7165
7166 -- Set entity to return
7167
7168 Ent := E;
7169
7170 -- Ada_Pass_By_Copy special checking
7171
7172 if C = Convention_Ada_Pass_By_Copy then
7173 if not Is_First_Subtype (E) then
7174 Error_Pragma_Arg
7175 ("convention `Ada_Pass_By_Copy` only allowed for types",
7176 Arg2);
7177 end if;
7178
7179 if Is_By_Reference_Type (E) then
7180 Error_Pragma_Arg
7181 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7182 & "type", Arg1);
7183 end if;
7184
7185 -- Ada_Pass_By_Reference special checking
7186
7187 elsif C = Convention_Ada_Pass_By_Reference then
7188 if not Is_First_Subtype (E) then
7189 Error_Pragma_Arg
7190 ("convention `Ada_Pass_By_Reference` only allowed for types",
7191 Arg2);
7192 end if;
7193
7194 if Is_By_Copy_Type (E) then
7195 Error_Pragma_Arg
7196 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7197 & "type", Arg1);
7198 end if;
7199 end if;
7200
7201 -- Go to renamed subprogram if present, since convention applies to
7202 -- the actual renamed entity, not to the renaming entity. If the
7203 -- subprogram is inherited, go to parent subprogram.
7204
7205 if Is_Subprogram (E)
7206 and then Present (Alias (E))
7207 then
7208 if Nkind (Parent (Declaration_Node (E))) =
7209 N_Subprogram_Renaming_Declaration
7210 then
7211 if Scope (E) /= Scope (Alias (E)) then
7212 Error_Pragma_Ref
7213 ("cannot apply pragma% to non-local entity&#", E);
7214 end if;
7215
7216 E := Alias (E);
7217
7218 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
7219 N_Private_Extension_Declaration)
7220 and then Scope (E) = Scope (Alias (E))
7221 then
7222 E := Alias (E);
7223
7224 -- Return the parent subprogram the entity was inherited from
7225
7226 Ent := E;
7227 end if;
7228 end if;
7229
7230 -- Check that we are not applying this to a specless body. Relax this
7231 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
7232
7233 if Is_Subprogram (E)
7234 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
7235 and then not Relaxed_RM_Semantics
7236 then
7237 Error_Pragma
7238 ("pragma% requires separate spec and must come before body");
7239 end if;
7240
7241 -- Check that we are not applying this to a named constant
7242
7243 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
7244 Error_Msg_Name_1 := Pname;
7245 Error_Msg_N
7246 ("cannot apply pragma% to named constant!",
7247 Get_Pragma_Arg (Arg2));
7248 Error_Pragma_Arg
7249 ("\supply appropriate type for&!", Arg2);
7250 end if;
7251
7252 if Ekind (E) = E_Enumeration_Literal then
7253 Error_Pragma ("enumeration literal not allowed for pragma%");
7254 end if;
7255
7256 -- Check for rep item appearing too early or too late
7257
7258 if Etype (E) = Any_Type
7259 or else Rep_Item_Too_Early (E, N)
7260 then
7261 raise Pragma_Exit;
7262
7263 elsif Present (Underlying_Type (E)) then
7264 E := Underlying_Type (E);
7265 end if;
7266
7267 if Rep_Item_Too_Late (E, N) then
7268 raise Pragma_Exit;
7269 end if;
7270
7271 if Has_Convention_Pragma (E) then
7272 Diagnose_Multiple_Pragmas (E);
7273
7274 elsif Convention (E) = Convention_Protected
7275 or else Ekind (Scope (E)) = E_Protected_Type
7276 then
7277 Error_Pragma_Arg
7278 ("a protected operation cannot be given a different convention",
7279 Arg2);
7280 end if;
7281
7282 -- For Intrinsic, a subprogram is required
7283
7284 if C = Convention_Intrinsic
7285 and then not Is_Subprogram_Or_Generic_Subprogram (E)
7286 then
7287 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7288
7289 if not (Is_Type (E) and then Relaxed_RM_Semantics) then
7290 Error_Pragma_Arg
7291 ("second argument of pragma% must be a subprogram", Arg2);
7292 end if;
7293 end if;
7294
7295 -- Deal with non-subprogram cases
7296
7297 if not Is_Subprogram_Or_Generic_Subprogram (E) then
7298 Set_Convention_From_Pragma (E);
7299
7300 if Is_Type (E) then
7301
7302 -- The pragma must apply to a first subtype, but it can also
7303 -- apply to a generic type in a generic formal part, in which
7304 -- case it will also appear in the corresponding instance.
7305
7306 if Is_Generic_Type (E) or else In_Instance then
7307 null;
7308 else
7309 Check_First_Subtype (Arg2);
7310 end if;
7311
7312 Set_Convention_From_Pragma (Base_Type (E));
7313
7314 -- For access subprograms, we must set the convention on the
7315 -- internally generated directly designated type as well.
7316
7317 if Ekind (E) = E_Access_Subprogram_Type then
7318 Set_Convention_From_Pragma (Directly_Designated_Type (E));
7319 end if;
7320 end if;
7321
7322 -- For the subprogram case, set proper convention for all homonyms
7323 -- in same scope and the same declarative part, i.e. the same
7324 -- compilation unit.
7325
7326 else
7327 Comp_Unit := Get_Source_Unit (E);
7328 Set_Convention_From_Pragma (E);
7329
7330 -- Treat a pragma Import as an implicit body, and pragma import
7331 -- as implicit reference (for navigation in GPS).
7332
7333 if Prag_Id = Pragma_Import then
7334 Generate_Reference (E, Id, 'b');
7335
7336 -- For exported entities we restrict the generation of references
7337 -- to entities exported to foreign languages since entities
7338 -- exported to Ada do not provide further information to GPS and
7339 -- add undesired references to the output of the gnatxref tool.
7340
7341 elsif Prag_Id = Pragma_Export
7342 and then Convention (E) /= Convention_Ada
7343 then
7344 Generate_Reference (E, Id, 'i');
7345 end if;
7346
7347 -- If the pragma comes from an aspect, it only applies to the
7348 -- given entity, not its homonyms.
7349
7350 if From_Aspect_Specification (N) then
7351 return;
7352 end if;
7353
7354 -- Otherwise Loop through the homonyms of the pragma argument's
7355 -- entity, an apply convention to those in the current scope.
7356
7357 E1 := Ent;
7358
7359 loop
7360 E1 := Homonym (E1);
7361 exit when No (E1) or else Scope (E1) /= Current_Scope;
7362
7363 -- Ignore entry for which convention is already set
7364
7365 if Has_Convention_Pragma (E1) then
7366 goto Continue;
7367 end if;
7368
7369 -- Do not set the pragma on inherited operations or on formal
7370 -- subprograms.
7371
7372 if Comes_From_Source (E1)
7373 and then Comp_Unit = Get_Source_Unit (E1)
7374 and then not Is_Formal_Subprogram (E1)
7375 and then Nkind (Original_Node (Parent (E1))) /=
7376 N_Full_Type_Declaration
7377 then
7378 if Present (Alias (E1))
7379 and then Scope (E1) /= Scope (Alias (E1))
7380 then
7381 Error_Pragma_Ref
7382 ("cannot apply pragma% to non-local entity& declared#",
7383 E1);
7384 end if;
7385
7386 Set_Convention_From_Pragma (E1);
7387
7388 if Prag_Id = Pragma_Import then
7389 Generate_Reference (E1, Id, 'b');
7390 end if;
7391 end if;
7392
7393 <<Continue>>
7394 null;
7395 end loop;
7396 end if;
7397 end Process_Convention;
7398
7399 ----------------------------------------
7400 -- Process_Disable_Enable_Atomic_Sync --
7401 ----------------------------------------
7402
7403 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7404 begin
7405 Check_No_Identifiers;
7406 Check_At_Most_N_Arguments (1);
7407
7408 -- Modeled internally as
7409 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7410
7411 Rewrite (N,
7412 Make_Pragma (Loc,
7413 Pragma_Identifier =>
7414 Make_Identifier (Loc, Nam),
7415 Pragma_Argument_Associations => New_List (
7416 Make_Pragma_Argument_Association (Loc,
7417 Expression =>
7418 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7419
7420 if Present (Arg1) then
7421 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7422 end if;
7423
7424 Analyze (N);
7425 end Process_Disable_Enable_Atomic_Sync;
7426
7427 -------------------------------------------------
7428 -- Process_Extended_Import_Export_Internal_Arg --
7429 -------------------------------------------------
7430
7431 procedure Process_Extended_Import_Export_Internal_Arg
7432 (Arg_Internal : Node_Id := Empty)
7433 is
7434 begin
7435 if No (Arg_Internal) then
7436 Error_Pragma ("Internal parameter required for pragma%");
7437 end if;
7438
7439 if Nkind (Arg_Internal) = N_Identifier then
7440 null;
7441
7442 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7443 and then (Prag_Id = Pragma_Import_Function
7444 or else
7445 Prag_Id = Pragma_Export_Function)
7446 then
7447 null;
7448
7449 else
7450 Error_Pragma_Arg
7451 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7452 end if;
7453
7454 Check_Arg_Is_Local_Name (Arg_Internal);
7455 end Process_Extended_Import_Export_Internal_Arg;
7456
7457 --------------------------------------------------
7458 -- Process_Extended_Import_Export_Object_Pragma --
7459 --------------------------------------------------
7460
7461 procedure Process_Extended_Import_Export_Object_Pragma
7462 (Arg_Internal : Node_Id;
7463 Arg_External : Node_Id;
7464 Arg_Size : Node_Id)
7465 is
7466 Def_Id : Entity_Id;
7467
7468 begin
7469 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7470 Def_Id := Entity (Arg_Internal);
7471
7472 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7473 Error_Pragma_Arg
7474 ("pragma% must designate an object", Arg_Internal);
7475 end if;
7476
7477 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7478 or else
7479 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7480 then
7481 Error_Pragma_Arg
7482 ("previous Common/Psect_Object applies, pragma % not permitted",
7483 Arg_Internal);
7484 end if;
7485
7486 if Rep_Item_Too_Late (Def_Id, N) then
7487 raise Pragma_Exit;
7488 end if;
7489
7490 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7491
7492 if Present (Arg_Size) then
7493 Check_Arg_Is_External_Name (Arg_Size);
7494 end if;
7495
7496 -- Export_Object case
7497
7498 if Prag_Id = Pragma_Export_Object then
7499 if not Is_Library_Level_Entity (Def_Id) then
7500 Error_Pragma_Arg
7501 ("argument for pragma% must be library level entity",
7502 Arg_Internal);
7503 end if;
7504
7505 if Ekind (Current_Scope) = E_Generic_Package then
7506 Error_Pragma ("pragma& cannot appear in a generic unit");
7507 end if;
7508
7509 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7510 Error_Pragma_Arg
7511 ("exported object must have compile time known size",
7512 Arg_Internal);
7513 end if;
7514
7515 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7516 Error_Msg_N ("??duplicate Export_Object pragma", N);
7517 else
7518 Set_Exported (Def_Id, Arg_Internal);
7519 end if;
7520
7521 -- Import_Object case
7522
7523 else
7524 if Is_Concurrent_Type (Etype (Def_Id)) then
7525 Error_Pragma_Arg
7526 ("cannot use pragma% for task/protected object",
7527 Arg_Internal);
7528 end if;
7529
7530 if Ekind (Def_Id) = E_Constant then
7531 Error_Pragma_Arg
7532 ("cannot import a constant", Arg_Internal);
7533 end if;
7534
7535 if Warn_On_Export_Import
7536 and then Has_Discriminants (Etype (Def_Id))
7537 then
7538 Error_Msg_N
7539 ("imported value must be initialized??", Arg_Internal);
7540 end if;
7541
7542 if Warn_On_Export_Import
7543 and then Is_Access_Type (Etype (Def_Id))
7544 then
7545 Error_Pragma_Arg
7546 ("cannot import object of an access type??", Arg_Internal);
7547 end if;
7548
7549 if Warn_On_Export_Import
7550 and then Is_Imported (Def_Id)
7551 then
7552 Error_Msg_N ("??duplicate Import_Object pragma", N);
7553
7554 -- Check for explicit initialization present. Note that an
7555 -- initialization generated by the code generator, e.g. for an
7556 -- access type, does not count here.
7557
7558 elsif Present (Expression (Parent (Def_Id)))
7559 and then
7560 Comes_From_Source
7561 (Original_Node (Expression (Parent (Def_Id))))
7562 then
7563 Error_Msg_Sloc := Sloc (Def_Id);
7564 Error_Pragma_Arg
7565 ("imported entities cannot be initialized (RM B.1(24))",
7566 "\no initialization allowed for & declared#", Arg1);
7567 else
7568 Set_Imported (Def_Id);
7569 Note_Possible_Modification (Arg_Internal, Sure => False);
7570 end if;
7571 end if;
7572 end Process_Extended_Import_Export_Object_Pragma;
7573
7574 ------------------------------------------------------
7575 -- Process_Extended_Import_Export_Subprogram_Pragma --
7576 ------------------------------------------------------
7577
7578 procedure Process_Extended_Import_Export_Subprogram_Pragma
7579 (Arg_Internal : Node_Id;
7580 Arg_External : Node_Id;
7581 Arg_Parameter_Types : Node_Id;
7582 Arg_Result_Type : Node_Id := Empty;
7583 Arg_Mechanism : Node_Id;
7584 Arg_Result_Mechanism : Node_Id := Empty)
7585 is
7586 Ent : Entity_Id;
7587 Def_Id : Entity_Id;
7588 Hom_Id : Entity_Id;
7589 Formal : Entity_Id;
7590 Ambiguous : Boolean;
7591 Match : Boolean;
7592
7593 function Same_Base_Type
7594 (Ptype : Node_Id;
7595 Formal : Entity_Id) return Boolean;
7596 -- Determines if Ptype references the type of Formal. Note that only
7597 -- the base types need to match according to the spec. Ptype here is
7598 -- the argument from the pragma, which is either a type name, or an
7599 -- access attribute.
7600
7601 --------------------
7602 -- Same_Base_Type --
7603 --------------------
7604
7605 function Same_Base_Type
7606 (Ptype : Node_Id;
7607 Formal : Entity_Id) return Boolean
7608 is
7609 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
7610 Pref : Node_Id;
7611
7612 begin
7613 -- Case where pragma argument is typ'Access
7614
7615 if Nkind (Ptype) = N_Attribute_Reference
7616 and then Attribute_Name (Ptype) = Name_Access
7617 then
7618 Pref := Prefix (Ptype);
7619 Find_Type (Pref);
7620
7621 if not Is_Entity_Name (Pref)
7622 or else Entity (Pref) = Any_Type
7623 then
7624 raise Pragma_Exit;
7625 end if;
7626
7627 -- We have a match if the corresponding argument is of an
7628 -- anonymous access type, and its designated type matches the
7629 -- type of the prefix of the access attribute
7630
7631 return Ekind (Ftyp) = E_Anonymous_Access_Type
7632 and then Base_Type (Entity (Pref)) =
7633 Base_Type (Etype (Designated_Type (Ftyp)));
7634
7635 -- Case where pragma argument is a type name
7636
7637 else
7638 Find_Type (Ptype);
7639
7640 if not Is_Entity_Name (Ptype)
7641 or else Entity (Ptype) = Any_Type
7642 then
7643 raise Pragma_Exit;
7644 end if;
7645
7646 -- We have a match if the corresponding argument is of the type
7647 -- given in the pragma (comparing base types)
7648
7649 return Base_Type (Entity (Ptype)) = Ftyp;
7650 end if;
7651 end Same_Base_Type;
7652
7653 -- Start of processing for
7654 -- Process_Extended_Import_Export_Subprogram_Pragma
7655
7656 begin
7657 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7658 Ent := Empty;
7659 Ambiguous := False;
7660
7661 -- Loop through homonyms (overloadings) of the entity
7662
7663 Hom_Id := Entity (Arg_Internal);
7664 while Present (Hom_Id) loop
7665 Def_Id := Get_Base_Subprogram (Hom_Id);
7666
7667 -- We need a subprogram in the current scope
7668
7669 if not Is_Subprogram (Def_Id)
7670 or else Scope (Def_Id) /= Current_Scope
7671 then
7672 null;
7673
7674 else
7675 Match := True;
7676
7677 -- Pragma cannot apply to subprogram body
7678
7679 if Is_Subprogram (Def_Id)
7680 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7681 N_Subprogram_Body
7682 then
7683 Error_Pragma
7684 ("pragma% requires separate spec"
7685 & " and must come before body");
7686 end if;
7687
7688 -- Test result type if given, note that the result type
7689 -- parameter can only be present for the function cases.
7690
7691 if Present (Arg_Result_Type)
7692 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7693 then
7694 Match := False;
7695
7696 elsif Etype (Def_Id) /= Standard_Void_Type
7697 and then
7698 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
7699 then
7700 Match := False;
7701
7702 -- Test parameter types if given. Note that this parameter
7703 -- has not been analyzed (and must not be, since it is
7704 -- semantic nonsense), so we get it as the parser left it.
7705
7706 elsif Present (Arg_Parameter_Types) then
7707 Check_Matching_Types : declare
7708 Formal : Entity_Id;
7709 Ptype : Node_Id;
7710
7711 begin
7712 Formal := First_Formal (Def_Id);
7713
7714 if Nkind (Arg_Parameter_Types) = N_Null then
7715 if Present (Formal) then
7716 Match := False;
7717 end if;
7718
7719 -- A list of one type, e.g. (List) is parsed as
7720 -- a parenthesized expression.
7721
7722 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7723 and then Paren_Count (Arg_Parameter_Types) = 1
7724 then
7725 if No (Formal)
7726 or else Present (Next_Formal (Formal))
7727 then
7728 Match := False;
7729 else
7730 Match :=
7731 Same_Base_Type (Arg_Parameter_Types, Formal);
7732 end if;
7733
7734 -- A list of more than one type is parsed as a aggregate
7735
7736 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7737 and then Paren_Count (Arg_Parameter_Types) = 0
7738 then
7739 Ptype := First (Expressions (Arg_Parameter_Types));
7740 while Present (Ptype) or else Present (Formal) loop
7741 if No (Ptype)
7742 or else No (Formal)
7743 or else not Same_Base_Type (Ptype, Formal)
7744 then
7745 Match := False;
7746 exit;
7747 else
7748 Next_Formal (Formal);
7749 Next (Ptype);
7750 end if;
7751 end loop;
7752
7753 -- Anything else is of the wrong form
7754
7755 else
7756 Error_Pragma_Arg
7757 ("wrong form for Parameter_Types parameter",
7758 Arg_Parameter_Types);
7759 end if;
7760 end Check_Matching_Types;
7761 end if;
7762
7763 -- Match is now False if the entry we found did not match
7764 -- either a supplied Parameter_Types or Result_Types argument
7765
7766 if Match then
7767 if No (Ent) then
7768 Ent := Def_Id;
7769
7770 -- Ambiguous case, the flag Ambiguous shows if we already
7771 -- detected this and output the initial messages.
7772
7773 else
7774 if not Ambiguous then
7775 Ambiguous := True;
7776 Error_Msg_Name_1 := Pname;
7777 Error_Msg_N
7778 ("pragma% does not uniquely identify subprogram!",
7779 N);
7780 Error_Msg_Sloc := Sloc (Ent);
7781 Error_Msg_N ("matching subprogram #!", N);
7782 Ent := Empty;
7783 end if;
7784
7785 Error_Msg_Sloc := Sloc (Def_Id);
7786 Error_Msg_N ("matching subprogram #!", N);
7787 end if;
7788 end if;
7789 end if;
7790
7791 Hom_Id := Homonym (Hom_Id);
7792 end loop;
7793
7794 -- See if we found an entry
7795
7796 if No (Ent) then
7797 if not Ambiguous then
7798 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7799 Error_Pragma
7800 ("pragma% cannot be given for generic subprogram");
7801 else
7802 Error_Pragma
7803 ("pragma% does not identify local subprogram");
7804 end if;
7805 end if;
7806
7807 return;
7808 end if;
7809
7810 -- Import pragmas must be for imported entities
7811
7812 if Prag_Id = Pragma_Import_Function
7813 or else
7814 Prag_Id = Pragma_Import_Procedure
7815 or else
7816 Prag_Id = Pragma_Import_Valued_Procedure
7817 then
7818 if not Is_Imported (Ent) then
7819 Error_Pragma
7820 ("pragma Import or Interface must precede pragma%");
7821 end if;
7822
7823 -- Here we have the Export case which can set the entity as exported
7824
7825 -- But does not do so if the specified external name is null, since
7826 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7827 -- compatible) to request no external name.
7828
7829 elsif Nkind (Arg_External) = N_String_Literal
7830 and then String_Length (Strval (Arg_External)) = 0
7831 then
7832 null;
7833
7834 -- In all other cases, set entity as exported
7835
7836 else
7837 Set_Exported (Ent, Arg_Internal);
7838 end if;
7839
7840 -- Special processing for Valued_Procedure cases
7841
7842 if Prag_Id = Pragma_Import_Valued_Procedure
7843 or else
7844 Prag_Id = Pragma_Export_Valued_Procedure
7845 then
7846 Formal := First_Formal (Ent);
7847
7848 if No (Formal) then
7849 Error_Pragma ("at least one parameter required for pragma%");
7850
7851 elsif Ekind (Formal) /= E_Out_Parameter then
7852 Error_Pragma ("first parameter must have mode out for pragma%");
7853
7854 else
7855 Set_Is_Valued_Procedure (Ent);
7856 end if;
7857 end if;
7858
7859 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7860
7861 -- Process Result_Mechanism argument if present. We have already
7862 -- checked that this is only allowed for the function case.
7863
7864 if Present (Arg_Result_Mechanism) then
7865 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7866 end if;
7867
7868 -- Process Mechanism parameter if present. Note that this parameter
7869 -- is not analyzed, and must not be analyzed since it is semantic
7870 -- nonsense, so we get it in exactly as the parser left it.
7871
7872 if Present (Arg_Mechanism) then
7873 declare
7874 Formal : Entity_Id;
7875 Massoc : Node_Id;
7876 Mname : Node_Id;
7877 Choice : Node_Id;
7878
7879 begin
7880 -- A single mechanism association without a formal parameter
7881 -- name is parsed as a parenthesized expression. All other
7882 -- cases are parsed as aggregates, so we rewrite the single
7883 -- parameter case as an aggregate for consistency.
7884
7885 if Nkind (Arg_Mechanism) /= N_Aggregate
7886 and then Paren_Count (Arg_Mechanism) = 1
7887 then
7888 Rewrite (Arg_Mechanism,
7889 Make_Aggregate (Sloc (Arg_Mechanism),
7890 Expressions => New_List (
7891 Relocate_Node (Arg_Mechanism))));
7892 end if;
7893
7894 -- Case of only mechanism name given, applies to all formals
7895
7896 if Nkind (Arg_Mechanism) /= N_Aggregate then
7897 Formal := First_Formal (Ent);
7898 while Present (Formal) loop
7899 Set_Mechanism_Value (Formal, Arg_Mechanism);
7900 Next_Formal (Formal);
7901 end loop;
7902
7903 -- Case of list of mechanism associations given
7904
7905 else
7906 if Null_Record_Present (Arg_Mechanism) then
7907 Error_Pragma_Arg
7908 ("inappropriate form for Mechanism parameter",
7909 Arg_Mechanism);
7910 end if;
7911
7912 -- Deal with positional ones first
7913
7914 Formal := First_Formal (Ent);
7915
7916 if Present (Expressions (Arg_Mechanism)) then
7917 Mname := First (Expressions (Arg_Mechanism));
7918 while Present (Mname) loop
7919 if No (Formal) then
7920 Error_Pragma_Arg
7921 ("too many mechanism associations", Mname);
7922 end if;
7923
7924 Set_Mechanism_Value (Formal, Mname);
7925 Next_Formal (Formal);
7926 Next (Mname);
7927 end loop;
7928 end if;
7929
7930 -- Deal with named entries
7931
7932 if Present (Component_Associations (Arg_Mechanism)) then
7933 Massoc := First (Component_Associations (Arg_Mechanism));
7934 while Present (Massoc) loop
7935 Choice := First (Choices (Massoc));
7936
7937 if Nkind (Choice) /= N_Identifier
7938 or else Present (Next (Choice))
7939 then
7940 Error_Pragma_Arg
7941 ("incorrect form for mechanism association",
7942 Massoc);
7943 end if;
7944
7945 Formal := First_Formal (Ent);
7946 loop
7947 if No (Formal) then
7948 Error_Pragma_Arg
7949 ("parameter name & not present", Choice);
7950 end if;
7951
7952 if Chars (Choice) = Chars (Formal) then
7953 Set_Mechanism_Value
7954 (Formal, Expression (Massoc));
7955
7956 -- Set entity on identifier (needed by ASIS)
7957
7958 Set_Entity (Choice, Formal);
7959
7960 exit;
7961 end if;
7962
7963 Next_Formal (Formal);
7964 end loop;
7965
7966 Next (Massoc);
7967 end loop;
7968 end if;
7969 end if;
7970 end;
7971 end if;
7972 end Process_Extended_Import_Export_Subprogram_Pragma;
7973
7974 --------------------------
7975 -- Process_Generic_List --
7976 --------------------------
7977
7978 procedure Process_Generic_List is
7979 Arg : Node_Id;
7980 Exp : Node_Id;
7981
7982 begin
7983 Check_No_Identifiers;
7984 Check_At_Least_N_Arguments (1);
7985
7986 -- Check all arguments are names of generic units or instances
7987
7988 Arg := Arg1;
7989 while Present (Arg) loop
7990 Exp := Get_Pragma_Arg (Arg);
7991 Analyze (Exp);
7992
7993 if not Is_Entity_Name (Exp)
7994 or else
7995 (not Is_Generic_Instance (Entity (Exp))
7996 and then
7997 not Is_Generic_Unit (Entity (Exp)))
7998 then
7999 Error_Pragma_Arg
8000 ("pragma% argument must be name of generic unit/instance",
8001 Arg);
8002 end if;
8003
8004 Next (Arg);
8005 end loop;
8006 end Process_Generic_List;
8007
8008 ------------------------------------
8009 -- Process_Import_Predefined_Type --
8010 ------------------------------------
8011
8012 procedure Process_Import_Predefined_Type is
8013 Loc : constant Source_Ptr := Sloc (N);
8014 Elmt : Elmt_Id;
8015 Ftyp : Node_Id := Empty;
8016 Decl : Node_Id;
8017 Def : Node_Id;
8018 Nam : Name_Id;
8019
8020 begin
8021 String_To_Name_Buffer (Strval (Expression (Arg3)));
8022 Nam := Name_Find;
8023
8024 Elmt := First_Elmt (Predefined_Float_Types);
8025 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
8026 Next_Elmt (Elmt);
8027 end loop;
8028
8029 Ftyp := Node (Elmt);
8030
8031 if Present (Ftyp) then
8032
8033 -- Don't build a derived type declaration, because predefined C
8034 -- types have no declaration anywhere, so cannot really be named.
8035 -- Instead build a full type declaration, starting with an
8036 -- appropriate type definition is built
8037
8038 if Is_Floating_Point_Type (Ftyp) then
8039 Def := Make_Floating_Point_Definition (Loc,
8040 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
8041 Make_Real_Range_Specification (Loc,
8042 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
8043 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
8044
8045 -- Should never have a predefined type we cannot handle
8046
8047 else
8048 raise Program_Error;
8049 end if;
8050
8051 -- Build and insert a Full_Type_Declaration, which will be
8052 -- analyzed as soon as this list entry has been analyzed.
8053
8054 Decl := Make_Full_Type_Declaration (Loc,
8055 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
8056 Type_Definition => Def);
8057
8058 Insert_After (N, Decl);
8059 Mark_Rewrite_Insertion (Decl);
8060
8061 else
8062 Error_Pragma_Arg ("no matching type found for pragma%",
8063 Arg2);
8064 end if;
8065 end Process_Import_Predefined_Type;
8066
8067 ---------------------------------
8068 -- Process_Import_Or_Interface --
8069 ---------------------------------
8070
8071 procedure Process_Import_Or_Interface is
8072 C : Convention_Id;
8073 Def_Id : Entity_Id;
8074 Hom_Id : Entity_Id;
8075
8076 begin
8077 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8078 -- pragma Import (Entity, "external name");
8079
8080 if Relaxed_RM_Semantics
8081 and then Arg_Count = 2
8082 and then Prag_Id = Pragma_Import
8083 and then Nkind (Expression (Arg2)) = N_String_Literal
8084 then
8085 C := Convention_C;
8086 Def_Id := Get_Pragma_Arg (Arg1);
8087 Analyze (Def_Id);
8088
8089 if not Is_Entity_Name (Def_Id) then
8090 Error_Pragma_Arg ("entity name required", Arg1);
8091 end if;
8092
8093 Def_Id := Entity (Def_Id);
8094 Kill_Size_Check_Code (Def_Id);
8095 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
8096
8097 else
8098 Process_Convention (C, Def_Id);
8099
8100 -- A pragma that applies to a Ghost entity becomes Ghost for the
8101 -- purposes of legality checks and removal of ignored Ghost code.
8102
8103 Mark_Pragma_As_Ghost (N, Def_Id);
8104 Kill_Size_Check_Code (Def_Id);
8105 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
8106 end if;
8107
8108 -- Various error checks
8109
8110 if Ekind_In (Def_Id, E_Variable, E_Constant) then
8111
8112 -- We do not permit Import to apply to a renaming declaration
8113
8114 if Present (Renamed_Object (Def_Id)) then
8115 Error_Pragma_Arg
8116 ("pragma% not allowed for object renaming", Arg2);
8117
8118 -- User initialization is not allowed for imported object, but
8119 -- the object declaration may contain a default initialization,
8120 -- that will be discarded. Note that an explicit initialization
8121 -- only counts if it comes from source, otherwise it is simply
8122 -- the code generator making an implicit initialization explicit.
8123
8124 elsif Present (Expression (Parent (Def_Id)))
8125 and then Comes_From_Source
8126 (Original_Node (Expression (Parent (Def_Id))))
8127 then
8128 -- Set imported flag to prevent cascaded errors
8129
8130 Set_Is_Imported (Def_Id);
8131
8132 Error_Msg_Sloc := Sloc (Def_Id);
8133 Error_Pragma_Arg
8134 ("no initialization allowed for declaration of& #",
8135 "\imported entities cannot be initialized (RM B.1(24))",
8136 Arg2);
8137
8138 else
8139 -- If the pragma comes from an aspect specification the
8140 -- Is_Imported flag has already been set.
8141
8142 if not From_Aspect_Specification (N) then
8143 Set_Imported (Def_Id);
8144 end if;
8145
8146 Process_Interface_Name (Def_Id, Arg3, Arg4);
8147
8148 -- Note that we do not set Is_Public here. That's because we
8149 -- only want to set it if there is no address clause, and we
8150 -- don't know that yet, so we delay that processing till
8151 -- freeze time.
8152
8153 -- pragma Import completes deferred constants
8154
8155 if Ekind (Def_Id) = E_Constant then
8156 Set_Has_Completion (Def_Id);
8157 end if;
8158
8159 -- It is not possible to import a constant of an unconstrained
8160 -- array type (e.g. string) because there is no simple way to
8161 -- write a meaningful subtype for it.
8162
8163 if Is_Array_Type (Etype (Def_Id))
8164 and then not Is_Constrained (Etype (Def_Id))
8165 then
8166 Error_Msg_NE
8167 ("imported constant& must have a constrained subtype",
8168 N, Def_Id);
8169 end if;
8170 end if;
8171
8172 elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8173
8174 -- If the name is overloaded, pragma applies to all of the denoted
8175 -- entities in the same declarative part, unless the pragma comes
8176 -- from an aspect specification or was generated by the compiler
8177 -- (such as for pragma Provide_Shift_Operators).
8178
8179 Hom_Id := Def_Id;
8180 while Present (Hom_Id) loop
8181
8182 Def_Id := Get_Base_Subprogram (Hom_Id);
8183
8184 -- Ignore inherited subprograms because the pragma will apply
8185 -- to the parent operation, which is the one called.
8186
8187 if Is_Overloadable (Def_Id)
8188 and then Present (Alias (Def_Id))
8189 then
8190 null;
8191
8192 -- If it is not a subprogram, it must be in an outer scope and
8193 -- pragma does not apply.
8194
8195 elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then
8196 null;
8197
8198 -- The pragma does not apply to primitives of interfaces
8199
8200 elsif Is_Dispatching_Operation (Def_Id)
8201 and then Present (Find_Dispatching_Type (Def_Id))
8202 and then Is_Interface (Find_Dispatching_Type (Def_Id))
8203 then
8204 null;
8205
8206 -- Verify that the homonym is in the same declarative part (not
8207 -- just the same scope). If the pragma comes from an aspect
8208 -- specification we know that it is part of the declaration.
8209
8210 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
8211 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8212 and then not From_Aspect_Specification (N)
8213 then
8214 exit;
8215
8216 else
8217 -- If the pragma comes from an aspect specification the
8218 -- Is_Imported flag has already been set.
8219
8220 if not From_Aspect_Specification (N) then
8221 Set_Imported (Def_Id);
8222 end if;
8223
8224 -- Reject an Import applied to an abstract subprogram
8225
8226 if Is_Subprogram (Def_Id)
8227 and then Is_Abstract_Subprogram (Def_Id)
8228 then
8229 Error_Msg_Sloc := Sloc (Def_Id);
8230 Error_Msg_NE
8231 ("cannot import abstract subprogram& declared#",
8232 Arg2, Def_Id);
8233 end if;
8234
8235 -- Special processing for Convention_Intrinsic
8236
8237 if C = Convention_Intrinsic then
8238
8239 -- Link_Name argument not allowed for intrinsic
8240
8241 Check_No_Link_Name;
8242
8243 Set_Is_Intrinsic_Subprogram (Def_Id);
8244
8245 -- If no external name is present, then check that this
8246 -- is a valid intrinsic subprogram. If an external name
8247 -- is present, then this is handled by the back end.
8248
8249 if No (Arg3) then
8250 Check_Intrinsic_Subprogram
8251 (Def_Id, Get_Pragma_Arg (Arg2));
8252 end if;
8253 end if;
8254
8255 -- Verify that the subprogram does not have a completion
8256 -- through a renaming declaration. For other completions the
8257 -- pragma appears as a too late representation.
8258
8259 declare
8260 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
8261
8262 begin
8263 if Present (Decl)
8264 and then Nkind (Decl) = N_Subprogram_Declaration
8265 and then Present (Corresponding_Body (Decl))
8266 and then Nkind (Unit_Declaration_Node
8267 (Corresponding_Body (Decl))) =
8268 N_Subprogram_Renaming_Declaration
8269 then
8270 Error_Msg_Sloc := Sloc (Def_Id);
8271 Error_Msg_NE
8272 ("cannot import&, renaming already provided for "
8273 & "declaration #", N, Def_Id);
8274 end if;
8275 end;
8276
8277 -- If the pragma comes from an aspect specification, there
8278 -- must be an Import aspect specified as well. In the rare
8279 -- case where Import is set to False, the suprogram needs to
8280 -- have a local completion.
8281
8282 declare
8283 Imp_Aspect : constant Node_Id :=
8284 Find_Aspect (Def_Id, Aspect_Import);
8285 Expr : Node_Id;
8286
8287 begin
8288 if Present (Imp_Aspect)
8289 and then Present (Expression (Imp_Aspect))
8290 then
8291 Expr := Expression (Imp_Aspect);
8292 Analyze_And_Resolve (Expr, Standard_Boolean);
8293
8294 if Is_Entity_Name (Expr)
8295 and then Entity (Expr) = Standard_True
8296 then
8297 Set_Has_Completion (Def_Id);
8298 end if;
8299
8300 -- If there is no expression, the default is True, as for
8301 -- all boolean aspects. Same for the older pragma.
8302
8303 else
8304 Set_Has_Completion (Def_Id);
8305 end if;
8306 end;
8307
8308 Process_Interface_Name (Def_Id, Arg3, Arg4);
8309 end if;
8310
8311 if Is_Compilation_Unit (Hom_Id) then
8312
8313 -- Its possible homonyms are not affected by the pragma.
8314 -- Such homonyms might be present in the context of other
8315 -- units being compiled.
8316
8317 exit;
8318
8319 elsif From_Aspect_Specification (N) then
8320 exit;
8321
8322 -- If the pragma was created by the compiler, then we don't
8323 -- want it to apply to other homonyms. This kind of case can
8324 -- occur when using pragma Provide_Shift_Operators, which
8325 -- generates implicit shift and rotate operators with Import
8326 -- pragmas that might apply to earlier explicit or implicit
8327 -- declarations marked with Import (for example, coming from
8328 -- an earlier pragma Provide_Shift_Operators for another type),
8329 -- and we don't generally want other homonyms being treated
8330 -- as imported or the pragma flagged as an illegal duplicate.
8331
8332 elsif not Comes_From_Source (N) then
8333 exit;
8334
8335 else
8336 Hom_Id := Homonym (Hom_Id);
8337 end if;
8338 end loop;
8339
8340 -- Import a CPP class
8341
8342 elsif C = Convention_CPP
8343 and then (Is_Record_Type (Def_Id)
8344 or else Ekind (Def_Id) = E_Incomplete_Type)
8345 then
8346 if Ekind (Def_Id) = E_Incomplete_Type then
8347 if Present (Full_View (Def_Id)) then
8348 Def_Id := Full_View (Def_Id);
8349
8350 else
8351 Error_Msg_N
8352 ("cannot import 'C'P'P type before full declaration seen",
8353 Get_Pragma_Arg (Arg2));
8354
8355 -- Although we have reported the error we decorate it as
8356 -- CPP_Class to avoid reporting spurious errors
8357
8358 Set_Is_CPP_Class (Def_Id);
8359 return;
8360 end if;
8361 end if;
8362
8363 -- Types treated as CPP classes must be declared limited (note:
8364 -- this used to be a warning but there is no real benefit to it
8365 -- since we did effectively intend to treat the type as limited
8366 -- anyway).
8367
8368 if not Is_Limited_Type (Def_Id) then
8369 Error_Msg_N
8370 ("imported 'C'P'P type must be limited",
8371 Get_Pragma_Arg (Arg2));
8372 end if;
8373
8374 if Etype (Def_Id) /= Def_Id
8375 and then not Is_CPP_Class (Root_Type (Def_Id))
8376 then
8377 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8378 end if;
8379
8380 Set_Is_CPP_Class (Def_Id);
8381
8382 -- Imported CPP types must not have discriminants (because C++
8383 -- classes do not have discriminants).
8384
8385 if Has_Discriminants (Def_Id) then
8386 Error_Msg_N
8387 ("imported 'C'P'P type cannot have discriminants",
8388 First (Discriminant_Specifications
8389 (Declaration_Node (Def_Id))));
8390 end if;
8391
8392 -- Check that components of imported CPP types do not have default
8393 -- expressions. For private types this check is performed when the
8394 -- full view is analyzed (see Process_Full_View).
8395
8396 if not Is_Private_Type (Def_Id) then
8397 Check_CPP_Type_Has_No_Defaults (Def_Id);
8398 end if;
8399
8400 -- Import a CPP exception
8401
8402 elsif C = Convention_CPP
8403 and then Ekind (Def_Id) = E_Exception
8404 then
8405 if No (Arg3) then
8406 Error_Pragma_Arg
8407 ("'External_'Name arguments is required for 'Cpp exception",
8408 Arg3);
8409 else
8410 -- As only a string is allowed, Check_Arg_Is_External_Name
8411 -- isn't called.
8412
8413 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8414 end if;
8415
8416 if Present (Arg4) then
8417 Error_Pragma_Arg
8418 ("Link_Name argument not allowed for imported Cpp exception",
8419 Arg4);
8420 end if;
8421
8422 -- Do not call Set_Interface_Name as the name of the exception
8423 -- shouldn't be modified (and in particular it shouldn't be
8424 -- the External_Name). For exceptions, the External_Name is the
8425 -- name of the RTTI structure.
8426
8427 -- ??? Emit an error if pragma Import/Export_Exception is present
8428
8429 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8430 Check_No_Link_Name;
8431 Check_Arg_Count (3);
8432 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8433
8434 Process_Import_Predefined_Type;
8435
8436 else
8437 Error_Pragma_Arg
8438 ("second argument of pragma% must be object, subprogram "
8439 & "or incomplete type",
8440 Arg2);
8441 end if;
8442
8443 -- If this pragma applies to a compilation unit, then the unit, which
8444 -- is a subprogram, does not require (or allow) a body. We also do
8445 -- not need to elaborate imported procedures.
8446
8447 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8448 declare
8449 Cunit : constant Node_Id := Parent (Parent (N));
8450 begin
8451 Set_Body_Required (Cunit, False);
8452 end;
8453 end if;
8454 end Process_Import_Or_Interface;
8455
8456 --------------------
8457 -- Process_Inline --
8458 --------------------
8459
8460 procedure Process_Inline (Status : Inline_Status) is
8461 Applies : Boolean;
8462 Assoc : Node_Id;
8463 Decl : Node_Id;
8464 Subp : Entity_Id;
8465 Subp_Id : Node_Id;
8466
8467 Ghost_Error_Posted : Boolean := False;
8468 -- Flag set when an error concerning the illegal mix of Ghost and
8469 -- non-Ghost subprograms is emitted.
8470
8471 Ghost_Id : Entity_Id := Empty;
8472 -- The entity of the first Ghost subprogram encountered while
8473 -- processing the arguments of the pragma.
8474
8475 procedure Make_Inline (Subp : Entity_Id);
8476 -- Subp is the defining unit name of the subprogram declaration. Set
8477 -- the flag, as well as the flag in the corresponding body, if there
8478 -- is one present.
8479
8480 procedure Set_Inline_Flags (Subp : Entity_Id);
8481 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8482 -- Has_Pragma_Inline_Always for the Inline_Always case.
8483
8484 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8485 -- Returns True if it can be determined at this stage that inlining
8486 -- is not possible, for example if the body is available and contains
8487 -- exception handlers, we prevent inlining, since otherwise we can
8488 -- get undefined symbols at link time. This function also emits a
8489 -- warning if front-end inlining is enabled and the pragma appears
8490 -- too late.
8491 --
8492 -- ??? is business with link symbols still valid, or does it relate
8493 -- to front end ZCX which is being phased out ???
8494
8495 ---------------------------
8496 -- Inlining_Not_Possible --
8497 ---------------------------
8498
8499 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8500 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8501 Stats : Node_Id;
8502
8503 begin
8504 if Nkind (Decl) = N_Subprogram_Body then
8505 Stats := Handled_Statement_Sequence (Decl);
8506 return Present (Exception_Handlers (Stats))
8507 or else Present (At_End_Proc (Stats));
8508
8509 elsif Nkind (Decl) = N_Subprogram_Declaration
8510 and then Present (Corresponding_Body (Decl))
8511 then
8512 if Front_End_Inlining
8513 and then Analyzed (Corresponding_Body (Decl))
8514 then
8515 Error_Msg_N ("pragma appears too late, ignored??", N);
8516 return True;
8517
8518 -- If the subprogram is a renaming as body, the body is just a
8519 -- call to the renamed subprogram, and inlining is trivially
8520 -- possible.
8521
8522 elsif
8523 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8524 N_Subprogram_Renaming_Declaration
8525 then
8526 return False;
8527
8528 else
8529 Stats :=
8530 Handled_Statement_Sequence
8531 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8532
8533 return
8534 Present (Exception_Handlers (Stats))
8535 or else Present (At_End_Proc (Stats));
8536 end if;
8537
8538 else
8539 -- If body is not available, assume the best, the check is
8540 -- performed again when compiling enclosing package bodies.
8541
8542 return False;
8543 end if;
8544 end Inlining_Not_Possible;
8545
8546 -----------------
8547 -- Make_Inline --
8548 -----------------
8549
8550 procedure Make_Inline (Subp : Entity_Id) is
8551 Kind : constant Entity_Kind := Ekind (Subp);
8552 Inner_Subp : Entity_Id := Subp;
8553
8554 begin
8555 -- Ignore if bad type, avoid cascaded error
8556
8557 if Etype (Subp) = Any_Type then
8558 Applies := True;
8559 return;
8560
8561 -- If inlining is not possible, for now do not treat as an error
8562
8563 elsif Status /= Suppressed
8564 and then Inlining_Not_Possible (Subp)
8565 then
8566 Applies := True;
8567 return;
8568
8569 -- Here we have a candidate for inlining, but we must exclude
8570 -- derived operations. Otherwise we would end up trying to inline
8571 -- a phantom declaration, and the result would be to drag in a
8572 -- body which has no direct inlining associated with it. That
8573 -- would not only be inefficient but would also result in the
8574 -- backend doing cross-unit inlining in cases where it was
8575 -- definitely inappropriate to do so.
8576
8577 -- However, a simple Comes_From_Source test is insufficient, since
8578 -- we do want to allow inlining of generic instances which also do
8579 -- not come from source. We also need to recognize specs generated
8580 -- by the front-end for bodies that carry the pragma. Finally,
8581 -- predefined operators do not come from source but are not
8582 -- inlineable either.
8583
8584 elsif Is_Generic_Instance (Subp)
8585 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8586 then
8587 null;
8588
8589 elsif not Comes_From_Source (Subp)
8590 and then Scope (Subp) /= Standard_Standard
8591 then
8592 Applies := True;
8593 return;
8594 end if;
8595
8596 -- The referenced entity must either be the enclosing entity, or
8597 -- an entity declared within the current open scope.
8598
8599 if Present (Scope (Subp))
8600 and then Scope (Subp) /= Current_Scope
8601 and then Subp /= Current_Scope
8602 then
8603 Error_Pragma_Arg
8604 ("argument of% must be entity in current scope", Assoc);
8605 return;
8606 end if;
8607
8608 -- Processing for procedure, operator or function. If subprogram
8609 -- is aliased (as for an instance) indicate that the renamed
8610 -- entity (if declared in the same unit) is inlined.
8611 -- If this is the anonymous subprogram created for a subprogram
8612 -- instance, the inlining applies to it directly. Otherwise we
8613 -- retrieve it as the alias of the visible subprogram instance.
8614
8615 if Is_Subprogram (Subp) then
8616 if Is_Wrapper_Package (Scope (Subp)) then
8617 Inner_Subp := Subp;
8618 else
8619 Inner_Subp := Ultimate_Alias (Inner_Subp);
8620 end if;
8621
8622 if In_Same_Source_Unit (Subp, Inner_Subp) then
8623 Set_Inline_Flags (Inner_Subp);
8624
8625 Decl := Parent (Parent (Inner_Subp));
8626
8627 if Nkind (Decl) = N_Subprogram_Declaration
8628 and then Present (Corresponding_Body (Decl))
8629 then
8630 Set_Inline_Flags (Corresponding_Body (Decl));
8631
8632 elsif Is_Generic_Instance (Subp)
8633 and then Comes_From_Source (Subp)
8634 then
8635 -- Indicate that the body needs to be created for
8636 -- inlining subsequent calls. The instantiation node
8637 -- follows the declaration of the wrapper package
8638 -- created for it. The subprogram that requires the
8639 -- body is the anonymous one in the wrapper package.
8640
8641 if Scope (Subp) /= Standard_Standard
8642 and then
8643 Need_Subprogram_Instance_Body
8644 (Next (Unit_Declaration_Node
8645 (Scope (Alias (Subp)))), Subp)
8646 then
8647 null;
8648 end if;
8649
8650 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8651 -- appear in a formal part to apply to a formal subprogram.
8652 -- Do not apply check within an instance or a formal package
8653 -- the test will have been applied to the original generic.
8654
8655 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8656 and then List_Containing (Decl) = List_Containing (N)
8657 and then not In_Instance
8658 then
8659 Error_Msg_N
8660 ("Inline cannot apply to a formal subprogram", N);
8661
8662 -- If Subp is a renaming, it is the renamed entity that
8663 -- will appear in any call, and be inlined. However, for
8664 -- ASIS uses it is convenient to indicate that the renaming
8665 -- itself is an inlined subprogram, so that some gnatcheck
8666 -- rules can be applied in the absence of expansion.
8667
8668 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8669 Set_Inline_Flags (Subp);
8670 end if;
8671 end if;
8672
8673 Applies := True;
8674
8675 -- For a generic subprogram set flag as well, for use at the point
8676 -- of instantiation, to determine whether the body should be
8677 -- generated.
8678
8679 elsif Is_Generic_Subprogram (Subp) then
8680 Set_Inline_Flags (Subp);
8681 Applies := True;
8682
8683 -- Literals are by definition inlined
8684
8685 elsif Kind = E_Enumeration_Literal then
8686 null;
8687
8688 -- Anything else is an error
8689
8690 else
8691 Error_Pragma_Arg
8692 ("expect subprogram name for pragma%", Assoc);
8693 end if;
8694 end Make_Inline;
8695
8696 ----------------------
8697 -- Set_Inline_Flags --
8698 ----------------------
8699
8700 procedure Set_Inline_Flags (Subp : Entity_Id) is
8701 begin
8702 -- First set the Has_Pragma_XXX flags and issue the appropriate
8703 -- errors and warnings for suspicious combinations.
8704
8705 if Prag_Id = Pragma_No_Inline then
8706 if Has_Pragma_Inline_Always (Subp) then
8707 Error_Msg_N
8708 ("Inline_Always and No_Inline are mutually exclusive", N);
8709 elsif Has_Pragma_Inline (Subp) then
8710 Error_Msg_NE
8711 ("Inline and No_Inline both specified for& ??",
8712 N, Entity (Subp_Id));
8713 end if;
8714
8715 Set_Has_Pragma_No_Inline (Subp);
8716 else
8717 if Prag_Id = Pragma_Inline_Always then
8718 if Has_Pragma_No_Inline (Subp) then
8719 Error_Msg_N
8720 ("Inline_Always and No_Inline are mutually exclusive",
8721 N);
8722 end if;
8723
8724 Set_Has_Pragma_Inline_Always (Subp);
8725 else
8726 if Has_Pragma_No_Inline (Subp) then
8727 Error_Msg_NE
8728 ("Inline and No_Inline both specified for& ??",
8729 N, Entity (Subp_Id));
8730 end if;
8731 end if;
8732
8733 if not Has_Pragma_Inline (Subp) then
8734 Set_Has_Pragma_Inline (Subp);
8735 end if;
8736 end if;
8737
8738 -- Then adjust the Is_Inlined flag. It can never be set if the
8739 -- subprogram is subject to pragma No_Inline.
8740
8741 case Status is
8742 when Suppressed =>
8743 Set_Is_Inlined (Subp, False);
8744 when Disabled =>
8745 null;
8746 when Enabled =>
8747 if not Has_Pragma_No_Inline (Subp) then
8748 Set_Is_Inlined (Subp, True);
8749 end if;
8750 end case;
8751
8752 -- A pragma that applies to a Ghost entity becomes Ghost for the
8753 -- purposes of legality checks and removal of ignored Ghost code.
8754
8755 Mark_Pragma_As_Ghost (N, Subp);
8756
8757 -- Capture the entity of the first Ghost subprogram being
8758 -- processed for error detection purposes.
8759
8760 if Is_Ghost_Entity (Subp) then
8761 if No (Ghost_Id) then
8762 Ghost_Id := Subp;
8763 end if;
8764
8765 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
8766 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
8767
8768 elsif Present (Ghost_Id) and then not Ghost_Error_Posted then
8769 Ghost_Error_Posted := True;
8770
8771 Error_Msg_Name_1 := Pname;
8772 Error_Msg_N
8773 ("pragma % cannot mention ghost and non-ghost subprograms",
8774 N);
8775
8776 Error_Msg_Sloc := Sloc (Ghost_Id);
8777 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
8778
8779 Error_Msg_Sloc := Sloc (Subp);
8780 Error_Msg_NE ("\& # declared as non-ghost", N, Subp);
8781 end if;
8782 end Set_Inline_Flags;
8783
8784 -- Start of processing for Process_Inline
8785
8786 begin
8787 Check_No_Identifiers;
8788 Check_At_Least_N_Arguments (1);
8789
8790 if Status = Enabled then
8791 Inline_Processing_Required := True;
8792 end if;
8793
8794 Assoc := Arg1;
8795 while Present (Assoc) loop
8796 Subp_Id := Get_Pragma_Arg (Assoc);
8797 Analyze (Subp_Id);
8798 Applies := False;
8799
8800 if Is_Entity_Name (Subp_Id) then
8801 Subp := Entity (Subp_Id);
8802
8803 if Subp = Any_Id then
8804
8805 -- If previous error, avoid cascaded errors
8806
8807 Check_Error_Detected;
8808 Applies := True;
8809
8810 else
8811 Make_Inline (Subp);
8812
8813 -- For the pragma case, climb homonym chain. This is
8814 -- what implements allowing the pragma in the renaming
8815 -- case, with the result applying to the ancestors, and
8816 -- also allows Inline to apply to all previous homonyms.
8817
8818 if not From_Aspect_Specification (N) then
8819 while Present (Homonym (Subp))
8820 and then Scope (Homonym (Subp)) = Current_Scope
8821 loop
8822 Make_Inline (Homonym (Subp));
8823 Subp := Homonym (Subp);
8824 end loop;
8825 end if;
8826 end if;
8827 end if;
8828
8829 if not Applies then
8830 Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc);
8831 end if;
8832
8833 Next (Assoc);
8834 end loop;
8835 end Process_Inline;
8836
8837 ----------------------------
8838 -- Process_Interface_Name --
8839 ----------------------------
8840
8841 procedure Process_Interface_Name
8842 (Subprogram_Def : Entity_Id;
8843 Ext_Arg : Node_Id;
8844 Link_Arg : Node_Id)
8845 is
8846 Ext_Nam : Node_Id;
8847 Link_Nam : Node_Id;
8848 String_Val : String_Id;
8849
8850 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
8851 -- SN is a string literal node for an interface name. This routine
8852 -- performs some minimal checks that the name is reasonable. In
8853 -- particular that no spaces or other obviously incorrect characters
8854 -- appear. This is only a warning, since any characters are allowed.
8855
8856 ----------------------------------
8857 -- Check_Form_Of_Interface_Name --
8858 ----------------------------------
8859
8860 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
8861 S : constant String_Id := Strval (Expr_Value_S (SN));
8862 SL : constant Nat := String_Length (S);
8863 C : Char_Code;
8864
8865 begin
8866 if SL = 0 then
8867 Error_Msg_N ("interface name cannot be null string", SN);
8868 end if;
8869
8870 for J in 1 .. SL loop
8871 C := Get_String_Char (S, J);
8872
8873 -- Look for dubious character and issue unconditional warning.
8874 -- Definitely dubious if not in character range.
8875
8876 if not In_Character_Range (C)
8877
8878 -- Commas, spaces and (back)slashes are dubious
8879
8880 or else Get_Character (C) = ','
8881 or else Get_Character (C) = '\'
8882 or else Get_Character (C) = ' '
8883 or else Get_Character (C) = '/'
8884 then
8885 Error_Msg
8886 ("??interface name contains illegal character",
8887 Sloc (SN) + Source_Ptr (J));
8888 end if;
8889 end loop;
8890 end Check_Form_Of_Interface_Name;
8891
8892 -- Start of processing for Process_Interface_Name
8893
8894 begin
8895 if No (Link_Arg) then
8896 if No (Ext_Arg) then
8897 return;
8898
8899 elsif Chars (Ext_Arg) = Name_Link_Name then
8900 Ext_Nam := Empty;
8901 Link_Nam := Expression (Ext_Arg);
8902
8903 else
8904 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8905 Ext_Nam := Expression (Ext_Arg);
8906 Link_Nam := Empty;
8907 end if;
8908
8909 else
8910 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8911 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8912 Ext_Nam := Expression (Ext_Arg);
8913 Link_Nam := Expression (Link_Arg);
8914 end if;
8915
8916 -- Check expressions for external name and link name are static
8917
8918 if Present (Ext_Nam) then
8919 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8920 Check_Form_Of_Interface_Name (Ext_Nam);
8921
8922 -- Verify that external name is not the name of a local entity,
8923 -- which would hide the imported one and could lead to run-time
8924 -- surprises. The problem can only arise for entities declared in
8925 -- a package body (otherwise the external name is fully qualified
8926 -- and will not conflict).
8927
8928 declare
8929 Nam : Name_Id;
8930 E : Entity_Id;
8931 Par : Node_Id;
8932
8933 begin
8934 if Prag_Id = Pragma_Import then
8935 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8936 Nam := Name_Find;
8937 E := Entity_Id (Get_Name_Table_Int (Nam));
8938
8939 if Nam /= Chars (Subprogram_Def)
8940 and then Present (E)
8941 and then not Is_Overloadable (E)
8942 and then Is_Immediately_Visible (E)
8943 and then not Is_Imported (E)
8944 and then Ekind (Scope (E)) = E_Package
8945 then
8946 Par := Parent (E);
8947 while Present (Par) loop
8948 if Nkind (Par) = N_Package_Body then
8949 Error_Msg_Sloc := Sloc (E);
8950 Error_Msg_NE
8951 ("imported entity is hidden by & declared#",
8952 Ext_Arg, E);
8953 exit;
8954 end if;
8955
8956 Par := Parent (Par);
8957 end loop;
8958 end if;
8959 end if;
8960 end;
8961 end if;
8962
8963 if Present (Link_Nam) then
8964 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8965 Check_Form_Of_Interface_Name (Link_Nam);
8966 end if;
8967
8968 -- If there is no link name, just set the external name
8969
8970 if No (Link_Nam) then
8971 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8972
8973 -- For the Link_Name case, the given literal is preceded by an
8974 -- asterisk, which indicates to GCC that the given name should be
8975 -- taken literally, and in particular that no prepending of
8976 -- underlines should occur, even in systems where this is the
8977 -- normal default.
8978
8979 else
8980 Start_String;
8981 Store_String_Char (Get_Char_Code ('*'));
8982 String_Val := Strval (Expr_Value_S (Link_Nam));
8983 Store_String_Chars (String_Val);
8984 Link_Nam :=
8985 Make_String_Literal (Sloc (Link_Nam),
8986 Strval => End_String);
8987 end if;
8988
8989 -- Set the interface name. If the entity is a generic instance, use
8990 -- its alias, which is the callable entity.
8991
8992 if Is_Generic_Instance (Subprogram_Def) then
8993 Set_Encoded_Interface_Name
8994 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8995 else
8996 Set_Encoded_Interface_Name
8997 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8998 end if;
8999
9000 Check_Duplicated_Export_Name (Link_Nam);
9001 end Process_Interface_Name;
9002
9003 -----------------------------------------
9004 -- Process_Interrupt_Or_Attach_Handler --
9005 -----------------------------------------
9006
9007 procedure Process_Interrupt_Or_Attach_Handler is
9008 Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
9009 Prot_Typ : constant Entity_Id := Scope (Handler);
9010
9011 begin
9012 -- A pragma that applies to a Ghost entity becomes Ghost for the
9013 -- purposes of legality checks and removal of ignored Ghost code.
9014
9015 Mark_Pragma_As_Ghost (N, Handler);
9016 Set_Is_Interrupt_Handler (Handler);
9017
9018 pragma Assert (Ekind (Prot_Typ) = E_Protected_Type);
9019
9020 Record_Rep_Item (Prot_Typ, N);
9021
9022 -- Chain the pragma on the contract for completeness
9023
9024 Add_Contract_Item (N, Handler);
9025 end Process_Interrupt_Or_Attach_Handler;
9026
9027 --------------------------------------------------
9028 -- Process_Restrictions_Or_Restriction_Warnings --
9029 --------------------------------------------------
9030
9031 -- Note: some of the simple identifier cases were handled in par-prag,
9032 -- but it is harmless (and more straightforward) to simply handle all
9033 -- cases here, even if it means we repeat a bit of work in some cases.
9034
9035 procedure Process_Restrictions_Or_Restriction_Warnings
9036 (Warn : Boolean)
9037 is
9038 Arg : Node_Id;
9039 R_Id : Restriction_Id;
9040 Id : Name_Id;
9041 Expr : Node_Id;
9042 Val : Uint;
9043
9044 begin
9045 -- Ignore all Restrictions pragmas in CodePeer mode
9046
9047 if CodePeer_Mode then
9048 return;
9049 end if;
9050
9051 Check_Ada_83_Warning;
9052 Check_At_Least_N_Arguments (1);
9053 Check_Valid_Configuration_Pragma;
9054
9055 Arg := Arg1;
9056 while Present (Arg) loop
9057 Id := Chars (Arg);
9058 Expr := Get_Pragma_Arg (Arg);
9059
9060 -- Case of no restriction identifier present
9061
9062 if Id = No_Name then
9063 if Nkind (Expr) /= N_Identifier then
9064 Error_Pragma_Arg
9065 ("invalid form for restriction", Arg);
9066 end if;
9067
9068 R_Id :=
9069 Get_Restriction_Id
9070 (Process_Restriction_Synonyms (Expr));
9071
9072 if R_Id not in All_Boolean_Restrictions then
9073 Error_Msg_Name_1 := Pname;
9074 Error_Msg_N
9075 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
9076
9077 -- Check for possible misspelling
9078
9079 for J in Restriction_Id loop
9080 declare
9081 Rnm : constant String := Restriction_Id'Image (J);
9082
9083 begin
9084 Name_Buffer (1 .. Rnm'Length) := Rnm;
9085 Name_Len := Rnm'Length;
9086 Set_Casing (All_Lower_Case);
9087
9088 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
9089 Set_Casing
9090 (Identifier_Casing (Current_Source_File));
9091 Error_Msg_String (1 .. Rnm'Length) :=
9092 Name_Buffer (1 .. Name_Len);
9093 Error_Msg_Strlen := Rnm'Length;
9094 Error_Msg_N -- CODEFIX
9095 ("\possible misspelling of ""~""",
9096 Get_Pragma_Arg (Arg));
9097 exit;
9098 end if;
9099 end;
9100 end loop;
9101
9102 raise Pragma_Exit;
9103 end if;
9104
9105 if Implementation_Restriction (R_Id) then
9106 Check_Restriction (No_Implementation_Restrictions, Arg);
9107 end if;
9108
9109 -- Special processing for No_Elaboration_Code restriction
9110
9111 if R_Id = No_Elaboration_Code then
9112
9113 -- Restriction is only recognized within a configuration
9114 -- pragma file, or within a unit of the main extended
9115 -- program. Note: the test for Main_Unit is needed to
9116 -- properly include the case of configuration pragma files.
9117
9118 if not (Current_Sem_Unit = Main_Unit
9119 or else In_Extended_Main_Source_Unit (N))
9120 then
9121 return;
9122
9123 -- Don't allow in a subunit unless already specified in
9124 -- body or spec.
9125
9126 elsif Nkind (Parent (N)) = N_Compilation_Unit
9127 and then Nkind (Unit (Parent (N))) = N_Subunit
9128 and then not Restriction_Active (No_Elaboration_Code)
9129 then
9130 Error_Msg_N
9131 ("invalid specification of ""No_Elaboration_Code""",
9132 N);
9133 Error_Msg_N
9134 ("\restriction cannot be specified in a subunit", N);
9135 Error_Msg_N
9136 ("\unless also specified in body or spec", N);
9137 return;
9138
9139 -- If we accept a No_Elaboration_Code restriction, then it
9140 -- needs to be added to the configuration restriction set so
9141 -- that we get proper application to other units in the main
9142 -- extended source as required.
9143
9144 else
9145 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
9146 end if;
9147 end if;
9148
9149 -- If this is a warning, then set the warning unless we already
9150 -- have a real restriction active (we never want a warning to
9151 -- override a real restriction).
9152
9153 if Warn then
9154 if not Restriction_Active (R_Id) then
9155 Set_Restriction (R_Id, N);
9156 Restriction_Warnings (R_Id) := True;
9157 end if;
9158
9159 -- If real restriction case, then set it and make sure that the
9160 -- restriction warning flag is off, since a real restriction
9161 -- always overrides a warning.
9162
9163 else
9164 Set_Restriction (R_Id, N);
9165 Restriction_Warnings (R_Id) := False;
9166 end if;
9167
9168 -- Check for obsolescent restrictions in Ada 2005 mode
9169
9170 if not Warn
9171 and then Ada_Version >= Ada_2005
9172 and then (R_Id = No_Asynchronous_Control
9173 or else
9174 R_Id = No_Unchecked_Deallocation
9175 or else
9176 R_Id = No_Unchecked_Conversion)
9177 then
9178 Check_Restriction (No_Obsolescent_Features, N);
9179 end if;
9180
9181 -- A very special case that must be processed here: pragma
9182 -- Restrictions (No_Exceptions) turns off all run-time
9183 -- checking. This is a bit dubious in terms of the formal
9184 -- language definition, but it is what is intended by RM
9185 -- H.4(12). Restriction_Warnings never affects generated code
9186 -- so this is done only in the real restriction case.
9187
9188 -- Atomic_Synchronization is not a real check, so it is not
9189 -- affected by this processing).
9190
9191 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9192 -- run-time checks in CodePeer and GNATprove modes: we want to
9193 -- generate checks for analysis purposes, as set respectively
9194 -- by -gnatC and -gnatd.F
9195
9196 if not Warn
9197 and then not (CodePeer_Mode or GNATprove_Mode)
9198 and then R_Id = No_Exceptions
9199 then
9200 for J in Scope_Suppress.Suppress'Range loop
9201 if J /= Atomic_Synchronization then
9202 Scope_Suppress.Suppress (J) := True;
9203 end if;
9204 end loop;
9205 end if;
9206
9207 -- Case of No_Dependence => unit-name. Note that the parser
9208 -- already made the necessary entry in the No_Dependence table.
9209
9210 elsif Id = Name_No_Dependence then
9211 if not OK_No_Dependence_Unit_Name (Expr) then
9212 raise Pragma_Exit;
9213 end if;
9214
9215 -- Case of No_Specification_Of_Aspect => aspect-identifier
9216
9217 elsif Id = Name_No_Specification_Of_Aspect then
9218 declare
9219 A_Id : Aspect_Id;
9220
9221 begin
9222 if Nkind (Expr) /= N_Identifier then
9223 A_Id := No_Aspect;
9224 else
9225 A_Id := Get_Aspect_Id (Chars (Expr));
9226 end if;
9227
9228 if A_Id = No_Aspect then
9229 Error_Pragma_Arg ("invalid restriction name", Arg);
9230 else
9231 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
9232 end if;
9233 end;
9234
9235 -- Case of No_Use_Of_Attribute => attribute-identifier
9236
9237 elsif Id = Name_No_Use_Of_Attribute then
9238 if Nkind (Expr) /= N_Identifier
9239 or else not Is_Attribute_Name (Chars (Expr))
9240 then
9241 Error_Msg_N ("unknown attribute name??", Expr);
9242
9243 else
9244 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
9245 end if;
9246
9247 -- Case of No_Use_Of_Entity => fully-qualified-name
9248
9249 elsif Id = Name_No_Use_Of_Entity then
9250
9251 -- Restriction is only recognized within a configuration
9252 -- pragma file, or within a unit of the main extended
9253 -- program. Note: the test for Main_Unit is needed to
9254 -- properly include the case of configuration pragma files.
9255
9256 if Current_Sem_Unit = Main_Unit
9257 or else In_Extended_Main_Source_Unit (N)
9258 then
9259 if not OK_No_Dependence_Unit_Name (Expr) then
9260 Error_Msg_N ("wrong form for entity name", Expr);
9261 else
9262 Set_Restriction_No_Use_Of_Entity
9263 (Expr, Warn, No_Profile);
9264 end if;
9265 end if;
9266
9267 -- Case of No_Use_Of_Pragma => pragma-identifier
9268
9269 elsif Id = Name_No_Use_Of_Pragma then
9270 if Nkind (Expr) /= N_Identifier
9271 or else not Is_Pragma_Name (Chars (Expr))
9272 then
9273 Error_Msg_N ("unknown pragma name??", Expr);
9274 else
9275 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
9276 end if;
9277
9278 -- All other cases of restriction identifier present
9279
9280 else
9281 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
9282 Analyze_And_Resolve (Expr, Any_Integer);
9283
9284 if R_Id not in All_Parameter_Restrictions then
9285 Error_Pragma_Arg
9286 ("invalid restriction parameter identifier", Arg);
9287
9288 elsif not Is_OK_Static_Expression (Expr) then
9289 Flag_Non_Static_Expr
9290 ("value must be static expression!", Expr);
9291 raise Pragma_Exit;
9292
9293 elsif not Is_Integer_Type (Etype (Expr))
9294 or else Expr_Value (Expr) < 0
9295 then
9296 Error_Pragma_Arg
9297 ("value must be non-negative integer", Arg);
9298 end if;
9299
9300 -- Restriction pragma is active
9301
9302 Val := Expr_Value (Expr);
9303
9304 if not UI_Is_In_Int_Range (Val) then
9305 Error_Pragma_Arg
9306 ("pragma ignored, value too large??", Arg);
9307 end if;
9308
9309 -- Warning case. If the real restriction is active, then we
9310 -- ignore the request, since warning never overrides a real
9311 -- restriction. Otherwise we set the proper warning. Note that
9312 -- this circuit sets the warning again if it is already set,
9313 -- which is what we want, since the constant may have changed.
9314
9315 if Warn then
9316 if not Restriction_Active (R_Id) then
9317 Set_Restriction
9318 (R_Id, N, Integer (UI_To_Int (Val)));
9319 Restriction_Warnings (R_Id) := True;
9320 end if;
9321
9322 -- Real restriction case, set restriction and make sure warning
9323 -- flag is off since real restriction always overrides warning.
9324
9325 else
9326 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9327 Restriction_Warnings (R_Id) := False;
9328 end if;
9329 end if;
9330
9331 Next (Arg);
9332 end loop;
9333 end Process_Restrictions_Or_Restriction_Warnings;
9334
9335 ---------------------------------
9336 -- Process_Suppress_Unsuppress --
9337 ---------------------------------
9338
9339 -- Note: this procedure makes entries in the check suppress data
9340 -- structures managed by Sem. See spec of package Sem for full
9341 -- details on how we handle recording of check suppression.
9342
9343 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9344 C : Check_Id;
9345 E : Entity_Id;
9346 E_Id : Node_Id;
9347
9348 In_Package_Spec : constant Boolean :=
9349 Is_Package_Or_Generic_Package (Current_Scope)
9350 and then not In_Package_Body (Current_Scope);
9351
9352 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9353 -- Used to suppress a single check on the given entity
9354
9355 --------------------------------
9356 -- Suppress_Unsuppress_Echeck --
9357 --------------------------------
9358
9359 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9360 begin
9361 -- Check for error of trying to set atomic synchronization for
9362 -- a non-atomic variable.
9363
9364 if C = Atomic_Synchronization
9365 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9366 then
9367 Error_Msg_N
9368 ("pragma & requires atomic type or variable",
9369 Pragma_Identifier (Original_Node (N)));
9370 end if;
9371
9372 Set_Checks_May_Be_Suppressed (E);
9373
9374 if In_Package_Spec then
9375 Push_Global_Suppress_Stack_Entry
9376 (Entity => E,
9377 Check => C,
9378 Suppress => Suppress_Case);
9379 else
9380 Push_Local_Suppress_Stack_Entry
9381 (Entity => E,
9382 Check => C,
9383 Suppress => Suppress_Case);
9384 end if;
9385
9386 -- If this is a first subtype, and the base type is distinct,
9387 -- then also set the suppress flags on the base type.
9388
9389 if Is_First_Subtype (E) and then Etype (E) /= E then
9390 Suppress_Unsuppress_Echeck (Etype (E), C);
9391 end if;
9392 end Suppress_Unsuppress_Echeck;
9393
9394 -- Start of processing for Process_Suppress_Unsuppress
9395
9396 begin
9397 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9398 -- on user code: we want to generate checks for analysis purposes, as
9399 -- set respectively by -gnatC and -gnatd.F
9400
9401 if Comes_From_Source (N)
9402 and then (CodePeer_Mode or GNATprove_Mode)
9403 then
9404 return;
9405 end if;
9406
9407 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9408 -- declarative part or a package spec (RM 11.5(5)).
9409
9410 if not Is_Configuration_Pragma then
9411 Check_Is_In_Decl_Part_Or_Package_Spec;
9412 end if;
9413
9414 Check_At_Least_N_Arguments (1);
9415 Check_At_Most_N_Arguments (2);
9416 Check_No_Identifier (Arg1);
9417 Check_Arg_Is_Identifier (Arg1);
9418
9419 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9420
9421 if C = No_Check_Id then
9422 Error_Pragma_Arg
9423 ("argument of pragma% is not valid check name", Arg1);
9424 end if;
9425
9426 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9427
9428 if C = Elaboration_Check and then SPARK_Mode = On then
9429 Error_Pragma_Arg
9430 ("Suppress of Elaboration_Check ignored in SPARK??",
9431 "\elaboration checking rules are statically enforced "
9432 & "(SPARK RM 7.7)", Arg1);
9433 end if;
9434
9435 -- One-argument case
9436
9437 if Arg_Count = 1 then
9438
9439 -- Make an entry in the local scope suppress table. This is the
9440 -- table that directly shows the current value of the scope
9441 -- suppress check for any check id value.
9442
9443 if C = All_Checks then
9444
9445 -- For All_Checks, we set all specific predefined checks with
9446 -- the exception of Elaboration_Check, which is handled
9447 -- specially because of not wanting All_Checks to have the
9448 -- effect of deactivating static elaboration order processing.
9449 -- Atomic_Synchronization is also not affected, since this is
9450 -- not a real check.
9451
9452 for J in Scope_Suppress.Suppress'Range loop
9453 if J /= Elaboration_Check
9454 and then
9455 J /= Atomic_Synchronization
9456 then
9457 Scope_Suppress.Suppress (J) := Suppress_Case;
9458 end if;
9459 end loop;
9460
9461 -- If not All_Checks, and predefined check, then set appropriate
9462 -- scope entry. Note that we will set Elaboration_Check if this
9463 -- is explicitly specified. Atomic_Synchronization is allowed
9464 -- only if internally generated and entity is atomic.
9465
9466 elsif C in Predefined_Check_Id
9467 and then (not Comes_From_Source (N)
9468 or else C /= Atomic_Synchronization)
9469 then
9470 Scope_Suppress.Suppress (C) := Suppress_Case;
9471 end if;
9472
9473 -- Also make an entry in the Local_Entity_Suppress table
9474
9475 Push_Local_Suppress_Stack_Entry
9476 (Entity => Empty,
9477 Check => C,
9478 Suppress => Suppress_Case);
9479
9480 -- Case of two arguments present, where the check is suppressed for
9481 -- a specified entity (given as the second argument of the pragma)
9482
9483 else
9484 -- This is obsolescent in Ada 2005 mode
9485
9486 if Ada_Version >= Ada_2005 then
9487 Check_Restriction (No_Obsolescent_Features, Arg2);
9488 end if;
9489
9490 Check_Optional_Identifier (Arg2, Name_On);
9491 E_Id := Get_Pragma_Arg (Arg2);
9492 Analyze (E_Id);
9493
9494 if not Is_Entity_Name (E_Id) then
9495 Error_Pragma_Arg
9496 ("second argument of pragma% must be entity name", Arg2);
9497 end if;
9498
9499 E := Entity (E_Id);
9500
9501 if E = Any_Id then
9502 return;
9503 end if;
9504
9505 -- A pragma that applies to a Ghost entity becomes Ghost for the
9506 -- purposes of legality checks and removal of ignored Ghost code.
9507
9508 Mark_Pragma_As_Ghost (N, E);
9509
9510 -- Enforce RM 11.5(7) which requires that for a pragma that
9511 -- appears within a package spec, the named entity must be
9512 -- within the package spec. We allow the package name itself
9513 -- to be mentioned since that makes sense, although it is not
9514 -- strictly allowed by 11.5(7).
9515
9516 if In_Package_Spec
9517 and then E /= Current_Scope
9518 and then Scope (E) /= Current_Scope
9519 then
9520 Error_Pragma_Arg
9521 ("entity in pragma% is not in package spec (RM 11.5(7))",
9522 Arg2);
9523 end if;
9524
9525 -- Loop through homonyms. As noted below, in the case of a package
9526 -- spec, only homonyms within the package spec are considered.
9527
9528 loop
9529 Suppress_Unsuppress_Echeck (E, C);
9530
9531 if Is_Generic_Instance (E)
9532 and then Is_Subprogram (E)
9533 and then Present (Alias (E))
9534 then
9535 Suppress_Unsuppress_Echeck (Alias (E), C);
9536 end if;
9537
9538 -- Move to next homonym if not aspect spec case
9539
9540 exit when From_Aspect_Specification (N);
9541 E := Homonym (E);
9542 exit when No (E);
9543
9544 -- If we are within a package specification, the pragma only
9545 -- applies to homonyms in the same scope.
9546
9547 exit when In_Package_Spec
9548 and then Scope (E) /= Current_Scope;
9549 end loop;
9550 end if;
9551 end Process_Suppress_Unsuppress;
9552
9553 -------------------------------
9554 -- Record_Independence_Check --
9555 -------------------------------
9556
9557 procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is
9558 begin
9559 -- For GCC back ends the validation is done a priori
9560
9561 if not AAMP_On_Target then
9562 return;
9563 end if;
9564
9565 Independence_Checks.Append ((N, E));
9566 end Record_Independence_Check;
9567
9568 ------------------
9569 -- Set_Exported --
9570 ------------------
9571
9572 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
9573 begin
9574 if Is_Imported (E) then
9575 Error_Pragma_Arg
9576 ("cannot export entity& that was previously imported", Arg);
9577
9578 elsif Present (Address_Clause (E))
9579 and then not Relaxed_RM_Semantics
9580 then
9581 Error_Pragma_Arg
9582 ("cannot export entity& that has an address clause", Arg);
9583 end if;
9584
9585 Set_Is_Exported (E);
9586
9587 -- Generate a reference for entity explicitly, because the
9588 -- identifier may be overloaded and name resolution will not
9589 -- generate one.
9590
9591 Generate_Reference (E, Arg);
9592
9593 -- Deal with exporting non-library level entity
9594
9595 if not Is_Library_Level_Entity (E) then
9596
9597 -- Not allowed at all for subprograms
9598
9599 if Is_Subprogram (E) then
9600 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
9601
9602 -- Otherwise set public and statically allocated
9603
9604 else
9605 Set_Is_Public (E);
9606 Set_Is_Statically_Allocated (E);
9607
9608 -- Warn if the corresponding W flag is set
9609
9610 if Warn_On_Export_Import
9611
9612 -- Only do this for something that was in the source. Not
9613 -- clear if this can be False now (there used for sure to be
9614 -- cases on some systems where it was False), but anyway the
9615 -- test is harmless if not needed, so it is retained.
9616
9617 and then Comes_From_Source (Arg)
9618 then
9619 Error_Msg_NE
9620 ("?x?& has been made static as a result of Export",
9621 Arg, E);
9622 Error_Msg_N
9623 ("\?x?this usage is non-standard and non-portable",
9624 Arg);
9625 end if;
9626 end if;
9627 end if;
9628
9629 if Warn_On_Export_Import and then Is_Type (E) then
9630 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
9631 end if;
9632
9633 if Warn_On_Export_Import and Inside_A_Generic then
9634 Error_Msg_NE
9635 ("all instances of& will have the same external name?x?",
9636 Arg, E);
9637 end if;
9638 end Set_Exported;
9639
9640 ----------------------------------------------
9641 -- Set_Extended_Import_Export_External_Name --
9642 ----------------------------------------------
9643
9644 procedure Set_Extended_Import_Export_External_Name
9645 (Internal_Ent : Entity_Id;
9646 Arg_External : Node_Id)
9647 is
9648 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9649 New_Name : Node_Id;
9650
9651 begin
9652 if No (Arg_External) then
9653 return;
9654 end if;
9655
9656 Check_Arg_Is_External_Name (Arg_External);
9657
9658 if Nkind (Arg_External) = N_String_Literal then
9659 if String_Length (Strval (Arg_External)) = 0 then
9660 return;
9661 else
9662 New_Name := Adjust_External_Name_Case (Arg_External);
9663 end if;
9664
9665 elsif Nkind (Arg_External) = N_Identifier then
9666 New_Name := Get_Default_External_Name (Arg_External);
9667
9668 -- Check_Arg_Is_External_Name should let through only identifiers and
9669 -- string literals or static string expressions (which are folded to
9670 -- string literals).
9671
9672 else
9673 raise Program_Error;
9674 end if;
9675
9676 -- If we already have an external name set (by a prior normal Import
9677 -- or Export pragma), then the external names must match
9678
9679 if Present (Interface_Name (Internal_Ent)) then
9680
9681 -- Ignore mismatching names in CodePeer mode, to support some
9682 -- old compilers which would export the same procedure under
9683 -- different names, e.g:
9684 -- procedure P;
9685 -- pragma Export_Procedure (P, "a");
9686 -- pragma Export_Procedure (P, "b");
9687
9688 if CodePeer_Mode then
9689 return;
9690 end if;
9691
9692 Check_Matching_Internal_Names : declare
9693 S1 : constant String_Id := Strval (Old_Name);
9694 S2 : constant String_Id := Strval (New_Name);
9695
9696 procedure Mismatch;
9697 pragma No_Return (Mismatch);
9698 -- Called if names do not match
9699
9700 --------------
9701 -- Mismatch --
9702 --------------
9703
9704 procedure Mismatch is
9705 begin
9706 Error_Msg_Sloc := Sloc (Old_Name);
9707 Error_Pragma_Arg
9708 ("external name does not match that given #",
9709 Arg_External);
9710 end Mismatch;
9711
9712 -- Start of processing for Check_Matching_Internal_Names
9713
9714 begin
9715 if String_Length (S1) /= String_Length (S2) then
9716 Mismatch;
9717
9718 else
9719 for J in 1 .. String_Length (S1) loop
9720 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9721 Mismatch;
9722 end if;
9723 end loop;
9724 end if;
9725 end Check_Matching_Internal_Names;
9726
9727 -- Otherwise set the given name
9728
9729 else
9730 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9731 Check_Duplicated_Export_Name (New_Name);
9732 end if;
9733 end Set_Extended_Import_Export_External_Name;
9734
9735 ------------------
9736 -- Set_Imported --
9737 ------------------
9738
9739 procedure Set_Imported (E : Entity_Id) is
9740 begin
9741 -- Error message if already imported or exported
9742
9743 if Is_Exported (E) or else Is_Imported (E) then
9744
9745 -- Error if being set Exported twice
9746
9747 if Is_Exported (E) then
9748 Error_Msg_NE ("entity& was previously exported", N, E);
9749
9750 -- Ignore error in CodePeer mode where we treat all imported
9751 -- subprograms as unknown.
9752
9753 elsif CodePeer_Mode then
9754 goto OK;
9755
9756 -- OK if Import/Interface case
9757
9758 elsif Import_Interface_Present (N) then
9759 goto OK;
9760
9761 -- Error if being set Imported twice
9762
9763 else
9764 Error_Msg_NE ("entity& was previously imported", N, E);
9765 end if;
9766
9767 Error_Msg_Name_1 := Pname;
9768 Error_Msg_N
9769 ("\(pragma% applies to all previous entities)", N);
9770
9771 Error_Msg_Sloc := Sloc (E);
9772 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9773
9774 -- Here if not previously imported or exported, OK to import
9775
9776 else
9777 Set_Is_Imported (E);
9778
9779 -- For subprogram, set Import_Pragma field
9780
9781 if Is_Subprogram (E) then
9782 Set_Import_Pragma (E, N);
9783 end if;
9784
9785 -- If the entity is an object that is not at the library level,
9786 -- then it is statically allocated. We do not worry about objects
9787 -- with address clauses in this context since they are not really
9788 -- imported in the linker sense.
9789
9790 if Is_Object (E)
9791 and then not Is_Library_Level_Entity (E)
9792 and then No (Address_Clause (E))
9793 then
9794 Set_Is_Statically_Allocated (E);
9795 end if;
9796 end if;
9797
9798 <<OK>> null;
9799 end Set_Imported;
9800
9801 -------------------------
9802 -- Set_Mechanism_Value --
9803 -------------------------
9804
9805 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9806 -- analyzed, since it is semantic nonsense), so we get it in the exact
9807 -- form created by the parser.
9808
9809 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9810 procedure Bad_Mechanism;
9811 pragma No_Return (Bad_Mechanism);
9812 -- Signal bad mechanism name
9813
9814 -------------------------
9815 -- Bad_Mechanism_Value --
9816 -------------------------
9817
9818 procedure Bad_Mechanism is
9819 begin
9820 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9821 end Bad_Mechanism;
9822
9823 -- Start of processing for Set_Mechanism_Value
9824
9825 begin
9826 if Mechanism (Ent) /= Default_Mechanism then
9827 Error_Msg_NE
9828 ("mechanism for & has already been set", Mech_Name, Ent);
9829 end if;
9830
9831 -- MECHANISM_NAME ::= value | reference
9832
9833 if Nkind (Mech_Name) = N_Identifier then
9834 if Chars (Mech_Name) = Name_Value then
9835 Set_Mechanism (Ent, By_Copy);
9836 return;
9837
9838 elsif Chars (Mech_Name) = Name_Reference then
9839 Set_Mechanism (Ent, By_Reference);
9840 return;
9841
9842 elsif Chars (Mech_Name) = Name_Copy then
9843 Error_Pragma_Arg
9844 ("bad mechanism name, Value assumed", Mech_Name);
9845
9846 else
9847 Bad_Mechanism;
9848 end if;
9849
9850 else
9851 Bad_Mechanism;
9852 end if;
9853 end Set_Mechanism_Value;
9854
9855 --------------------------
9856 -- Set_Rational_Profile --
9857 --------------------------
9858
9859 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9860 -- extension to the semantics of renaming declarations.
9861
9862 procedure Set_Rational_Profile is
9863 begin
9864 Implicit_Packing := True;
9865 Overriding_Renamings := True;
9866 Use_VADS_Size := True;
9867 end Set_Rational_Profile;
9868
9869 ---------------------------
9870 -- Set_Ravenscar_Profile --
9871 ---------------------------
9872
9873 -- The tasks to be done here are
9874
9875 -- Set required policies
9876
9877 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9878 -- pragma Locking_Policy (Ceiling_Locking)
9879
9880 -- Set Detect_Blocking mode
9881
9882 -- Set required restrictions (see System.Rident for detailed list)
9883
9884 -- Set the No_Dependence rules
9885 -- No_Dependence => Ada.Asynchronous_Task_Control
9886 -- No_Dependence => Ada.Calendar
9887 -- No_Dependence => Ada.Execution_Time.Group_Budget
9888 -- No_Dependence => Ada.Execution_Time.Timers
9889 -- No_Dependence => Ada.Task_Attributes
9890 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9891
9892 procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is
9893 procedure Set_Error_Msg_To_Profile_Name;
9894 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
9895 -- profile.
9896
9897 -----------------------------------
9898 -- Set_Error_Msg_To_Profile_Name --
9899 -----------------------------------
9900
9901 procedure Set_Error_Msg_To_Profile_Name is
9902 Prof_Nam : constant Node_Id :=
9903 Get_Pragma_Arg
9904 (First (Pragma_Argument_Associations (N)));
9905
9906 begin
9907 Get_Name_String (Chars (Prof_Nam));
9908 Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam));
9909 Error_Msg_Strlen := Name_Len;
9910 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
9911 end Set_Error_Msg_To_Profile_Name;
9912
9913 -- Local variables
9914
9915 Nod : Node_Id;
9916 Pref : Node_Id;
9917 Pref_Id : Node_Id;
9918 Sel_Id : Node_Id;
9919
9920 -- Start of processing for Set_Ravenscar_Profile
9921
9922 begin
9923 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9924
9925 if Task_Dispatching_Policy /= ' '
9926 and then Task_Dispatching_Policy /= 'F'
9927 then
9928 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9929 Set_Error_Msg_To_Profile_Name;
9930 Error_Pragma ("Profile (~) incompatible with policy#");
9931
9932 -- Set the FIFO_Within_Priorities policy, but always preserve
9933 -- System_Location since we like the error message with the run time
9934 -- name.
9935
9936 else
9937 Task_Dispatching_Policy := 'F';
9938
9939 if Task_Dispatching_Policy_Sloc /= System_Location then
9940 Task_Dispatching_Policy_Sloc := Loc;
9941 end if;
9942 end if;
9943
9944 -- pragma Locking_Policy (Ceiling_Locking)
9945
9946 if Locking_Policy /= ' '
9947 and then Locking_Policy /= 'C'
9948 then
9949 Error_Msg_Sloc := Locking_Policy_Sloc;
9950 Set_Error_Msg_To_Profile_Name;
9951 Error_Pragma ("Profile (~) incompatible with policy#");
9952
9953 -- Set the Ceiling_Locking policy, but preserve System_Location since
9954 -- we like the error message with the run time name.
9955
9956 else
9957 Locking_Policy := 'C';
9958
9959 if Locking_Policy_Sloc /= System_Location then
9960 Locking_Policy_Sloc := Loc;
9961 end if;
9962 end if;
9963
9964 -- pragma Detect_Blocking
9965
9966 Detect_Blocking := True;
9967
9968 -- Set the corresponding restrictions
9969
9970 Set_Profile_Restrictions
9971 (Profile, N, Warn => Treat_Restrictions_As_Warnings);
9972
9973 -- Set the No_Dependence restrictions
9974
9975 -- The following No_Dependence restrictions:
9976 -- No_Dependence => Ada.Asynchronous_Task_Control
9977 -- No_Dependence => Ada.Calendar
9978 -- No_Dependence => Ada.Task_Attributes
9979 -- are already set by previous call to Set_Profile_Restrictions.
9980
9981 -- Set the following restrictions which were added to Ada 2005:
9982 -- No_Dependence => Ada.Execution_Time.Group_Budget
9983 -- No_Dependence => Ada.Execution_Time.Timers
9984
9985 -- ??? The use of Name_Buffer here is suspicious. The names should
9986 -- be registered in snames.ads-tmpl and used to build the qualified
9987 -- names of units.
9988
9989 if Ada_Version >= Ada_2005 then
9990 Name_Buffer (1 .. 3) := "ada";
9991 Name_Len := 3;
9992
9993 Pref_Id := Make_Identifier (Loc, Name_Find);
9994
9995 Name_Buffer (1 .. 14) := "execution_time";
9996 Name_Len := 14;
9997
9998 Sel_Id := Make_Identifier (Loc, Name_Find);
9999
10000 Pref :=
10001 Make_Selected_Component
10002 (Sloc => Loc,
10003 Prefix => Pref_Id,
10004 Selector_Name => Sel_Id);
10005
10006 Name_Buffer (1 .. 13) := "group_budgets";
10007 Name_Len := 13;
10008
10009 Sel_Id := Make_Identifier (Loc, Name_Find);
10010
10011 Nod :=
10012 Make_Selected_Component
10013 (Sloc => Loc,
10014 Prefix => Pref,
10015 Selector_Name => Sel_Id);
10016
10017 Set_Restriction_No_Dependence
10018 (Unit => Nod,
10019 Warn => Treat_Restrictions_As_Warnings,
10020 Profile => Ravenscar);
10021
10022 Name_Buffer (1 .. 6) := "timers";
10023 Name_Len := 6;
10024
10025 Sel_Id := Make_Identifier (Loc, Name_Find);
10026
10027 Nod :=
10028 Make_Selected_Component
10029 (Sloc => Loc,
10030 Prefix => Pref,
10031 Selector_Name => Sel_Id);
10032
10033 Set_Restriction_No_Dependence
10034 (Unit => Nod,
10035 Warn => Treat_Restrictions_As_Warnings,
10036 Profile => Ravenscar);
10037 end if;
10038
10039 -- Set the following restriction which was added to Ada 2012 (see
10040 -- AI-0171):
10041 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10042
10043 if Ada_Version >= Ada_2012 then
10044 Name_Buffer (1 .. 6) := "system";
10045 Name_Len := 6;
10046
10047 Pref_Id := Make_Identifier (Loc, Name_Find);
10048
10049 Name_Buffer (1 .. 15) := "multiprocessors";
10050 Name_Len := 15;
10051
10052 Sel_Id := Make_Identifier (Loc, Name_Find);
10053
10054 Pref :=
10055 Make_Selected_Component
10056 (Sloc => Loc,
10057 Prefix => Pref_Id,
10058 Selector_Name => Sel_Id);
10059
10060 Name_Buffer (1 .. 19) := "dispatching_domains";
10061 Name_Len := 19;
10062
10063 Sel_Id := Make_Identifier (Loc, Name_Find);
10064
10065 Nod :=
10066 Make_Selected_Component
10067 (Sloc => Loc,
10068 Prefix => Pref,
10069 Selector_Name => Sel_Id);
10070
10071 Set_Restriction_No_Dependence
10072 (Unit => Nod,
10073 Warn => Treat_Restrictions_As_Warnings,
10074 Profile => Ravenscar);
10075 end if;
10076 end Set_Ravenscar_Profile;
10077
10078 -- Start of processing for Analyze_Pragma
10079
10080 begin
10081 -- The following code is a defense against recursion. Not clear that
10082 -- this can happen legitimately, but perhaps some error situations can
10083 -- cause it, and we did see this recursion during testing.
10084
10085 if Analyzed (N) then
10086 return;
10087 else
10088 Set_Analyzed (N);
10089 end if;
10090
10091 Check_Restriction_No_Use_Of_Pragma (N);
10092
10093 -- Deal with unrecognized pragma
10094
10095 Pname := Pragma_Name (N);
10096
10097 if not Is_Pragma_Name (Pname) then
10098 if Warn_On_Unrecognized_Pragma then
10099 Error_Msg_Name_1 := Pname;
10100 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
10101
10102 for PN in First_Pragma_Name .. Last_Pragma_Name loop
10103 if Is_Bad_Spelling_Of (Pname, PN) then
10104 Error_Msg_Name_1 := PN;
10105 Error_Msg_N -- CODEFIX
10106 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
10107 exit;
10108 end if;
10109 end loop;
10110 end if;
10111
10112 return;
10113 end if;
10114
10115 -- Ignore pragma if Ignore_Pragma applies
10116
10117 if Get_Name_Table_Boolean3 (Pname) then
10118 return;
10119 end if;
10120
10121 -- Here to start processing for recognized pragma
10122
10123 Prag_Id := Get_Pragma_Id (Pname);
10124 Pname := Original_Aspect_Pragma_Name (N);
10125
10126 -- Capture setting of Opt.Uneval_Old
10127
10128 case Opt.Uneval_Old is
10129 when 'A' =>
10130 Set_Uneval_Old_Accept (N);
10131 when 'E' =>
10132 null;
10133 when 'W' =>
10134 Set_Uneval_Old_Warn (N);
10135 when others =>
10136 raise Program_Error;
10137 end case;
10138
10139 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10140 -- is already set, indicating that we have already checked the policy
10141 -- at the right point. This happens for example in the case of a pragma
10142 -- that is derived from an Aspect.
10143
10144 if Is_Ignored (N) or else Is_Checked (N) then
10145 null;
10146
10147 -- For a pragma that is a rewriting of another pragma, copy the
10148 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10149
10150 elsif Is_Rewrite_Substitution (N)
10151 and then Nkind (Original_Node (N)) = N_Pragma
10152 and then Original_Node (N) /= N
10153 then
10154 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10155 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10156
10157 -- Otherwise query the applicable policy at this point
10158
10159 else
10160 Check_Applicable_Policy (N);
10161
10162 -- If pragma is disabled, rewrite as NULL and skip analysis
10163
10164 if Is_Disabled (N) then
10165 Rewrite (N, Make_Null_Statement (Loc));
10166 Analyze (N);
10167 raise Pragma_Exit;
10168 end if;
10169 end if;
10170
10171 -- Preset arguments
10172
10173 Arg_Count := 0;
10174 Arg1 := Empty;
10175 Arg2 := Empty;
10176 Arg3 := Empty;
10177 Arg4 := Empty;
10178
10179 if Present (Pragma_Argument_Associations (N)) then
10180 Arg_Count := List_Length (Pragma_Argument_Associations (N));
10181 Arg1 := First (Pragma_Argument_Associations (N));
10182
10183 if Present (Arg1) then
10184 Arg2 := Next (Arg1);
10185
10186 if Present (Arg2) then
10187 Arg3 := Next (Arg2);
10188
10189 if Present (Arg3) then
10190 Arg4 := Next (Arg3);
10191 end if;
10192 end if;
10193 end if;
10194 end if;
10195
10196 -- An enumeration type defines the pragmas that are supported by the
10197 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10198 -- into the corresponding enumeration value for the following case.
10199
10200 case Prag_Id is
10201
10202 -----------------
10203 -- Abort_Defer --
10204 -----------------
10205
10206 -- pragma Abort_Defer;
10207
10208 when Pragma_Abort_Defer =>
10209 GNAT_Pragma;
10210 Check_Arg_Count (0);
10211
10212 -- The only required semantic processing is to check the
10213 -- placement. This pragma must appear at the start of the
10214 -- statement sequence of a handled sequence of statements.
10215
10216 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
10217 or else N /= First (Statements (Parent (N)))
10218 then
10219 Pragma_Misplaced;
10220 end if;
10221
10222 --------------------
10223 -- Abstract_State --
10224 --------------------
10225
10226 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10227
10228 -- ABSTRACT_STATE_LIST ::=
10229 -- null
10230 -- | STATE_NAME_WITH_OPTIONS
10231 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10232
10233 -- STATE_NAME_WITH_OPTIONS ::=
10234 -- STATE_NAME
10235 -- | (STATE_NAME with OPTION_LIST)
10236
10237 -- OPTION_LIST ::= OPTION {, OPTION}
10238
10239 -- OPTION ::=
10240 -- SIMPLE_OPTION
10241 -- | NAME_VALUE_OPTION
10242
10243 -- SIMPLE_OPTION ::= Ghost | Synchronous
10244
10245 -- NAME_VALUE_OPTION ::=
10246 -- Part_Of => ABSTRACT_STATE
10247 -- | External [=> EXTERNAL_PROPERTY_LIST]
10248
10249 -- EXTERNAL_PROPERTY_LIST ::=
10250 -- EXTERNAL_PROPERTY
10251 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10252
10253 -- EXTERNAL_PROPERTY ::=
10254 -- Async_Readers [=> boolean_EXPRESSION]
10255 -- | Async_Writers [=> boolean_EXPRESSION]
10256 -- | Effective_Reads [=> boolean_EXPRESSION]
10257 -- | Effective_Writes [=> boolean_EXPRESSION]
10258 -- others => boolean_EXPRESSION
10259
10260 -- STATE_NAME ::= defining_identifier
10261
10262 -- ABSTRACT_STATE ::= name
10263
10264 -- Characteristics:
10265
10266 -- * Analysis - The annotation is fully analyzed immediately upon
10267 -- elaboration as it cannot forward reference entities.
10268
10269 -- * Expansion - None.
10270
10271 -- * Template - The annotation utilizes the generic template of the
10272 -- related package declaration.
10273
10274 -- * Globals - The annotation cannot reference global entities.
10275
10276 -- * Instance - The annotation is instantiated automatically when
10277 -- the related generic package is instantiated.
10278
10279 when Pragma_Abstract_State => Abstract_State : declare
10280 Missing_Parentheses : Boolean := False;
10281 -- Flag set when a state declaration with options is not properly
10282 -- parenthesized.
10283
10284 -- Flags used to verify the consistency of states
10285
10286 Non_Null_Seen : Boolean := False;
10287 Null_Seen : Boolean := False;
10288
10289 procedure Analyze_Abstract_State
10290 (State : Node_Id;
10291 Pack_Id : Entity_Id);
10292 -- Verify the legality of a single state declaration. Create and
10293 -- decorate a state abstraction entity and introduce it into the
10294 -- visibility chain. Pack_Id denotes the entity or the related
10295 -- package where pragma Abstract_State appears.
10296
10297 procedure Malformed_State_Error (State : Node_Id);
10298 -- Emit an error concerning the illegal declaration of abstract
10299 -- state State. This routine diagnoses syntax errors that lead to
10300 -- a different parse tree. The error is issued regardless of the
10301 -- SPARK mode in effect.
10302
10303 ----------------------------
10304 -- Analyze_Abstract_State --
10305 ----------------------------
10306
10307 procedure Analyze_Abstract_State
10308 (State : Node_Id;
10309 Pack_Id : Entity_Id)
10310 is
10311 -- Flags used to verify the consistency of options
10312
10313 AR_Seen : Boolean := False;
10314 AW_Seen : Boolean := False;
10315 ER_Seen : Boolean := False;
10316 EW_Seen : Boolean := False;
10317 External_Seen : Boolean := False;
10318 Ghost_Seen : Boolean := False;
10319 Others_Seen : Boolean := False;
10320 Part_Of_Seen : Boolean := False;
10321 Synchronous_Seen : Boolean := False;
10322
10323 -- Flags used to store the static value of all external states'
10324 -- expressions.
10325
10326 AR_Val : Boolean := False;
10327 AW_Val : Boolean := False;
10328 ER_Val : Boolean := False;
10329 EW_Val : Boolean := False;
10330
10331 State_Id : Entity_Id := Empty;
10332 -- The entity to be generated for the current state declaration
10333
10334 procedure Analyze_External_Option (Opt : Node_Id);
10335 -- Verify the legality of option External
10336
10337 procedure Analyze_External_Property
10338 (Prop : Node_Id;
10339 Expr : Node_Id := Empty);
10340 -- Verify the legailty of a single external property. Prop
10341 -- denotes the external property. Expr is the expression used
10342 -- to set the property.
10343
10344 procedure Analyze_Part_Of_Option (Opt : Node_Id);
10345 -- Verify the legality of option Part_Of
10346
10347 procedure Check_Duplicate_Option
10348 (Opt : Node_Id;
10349 Status : in out Boolean);
10350 -- Flag Status denotes whether a particular option has been
10351 -- seen while processing a state. This routine verifies that
10352 -- Opt is not a duplicate option and sets the flag Status
10353 -- (SPARK RM 7.1.4(1)).
10354
10355 procedure Check_Duplicate_Property
10356 (Prop : Node_Id;
10357 Status : in out Boolean);
10358 -- Flag Status denotes whether a particular property has been
10359 -- seen while processing option External. This routine verifies
10360 -- that Prop is not a duplicate property and sets flag Status.
10361 -- Opt is not a duplicate property and sets the flag Status.
10362 -- (SPARK RM 7.1.4(2))
10363
10364 procedure Check_Ghost_Synchronous;
10365 -- Ensure that the abstract state is not subject to both Ghost
10366 -- and Synchronous simple options. Emit an error if this is the
10367 -- case.
10368
10369 procedure Create_Abstract_State
10370 (Nam : Name_Id;
10371 Decl : Node_Id;
10372 Loc : Source_Ptr;
10373 Is_Null : Boolean);
10374 -- Generate an abstract state entity with name Nam and enter it
10375 -- into visibility. Decl is the "declaration" of the state as
10376 -- it appears in pragma Abstract_State. Loc is the location of
10377 -- the related state "declaration". Flag Is_Null should be set
10378 -- when the associated Abstract_State pragma defines a null
10379 -- state.
10380
10381 -----------------------------
10382 -- Analyze_External_Option --
10383 -----------------------------
10384
10385 procedure Analyze_External_Option (Opt : Node_Id) is
10386 Errors : constant Nat := Serious_Errors_Detected;
10387 Prop : Node_Id;
10388 Props : Node_Id := Empty;
10389
10390 begin
10391 if Nkind (Opt) = N_Component_Association then
10392 Props := Expression (Opt);
10393 end if;
10394
10395 -- External state with properties
10396
10397 if Present (Props) then
10398
10399 -- Multiple properties appear as an aggregate
10400
10401 if Nkind (Props) = N_Aggregate then
10402
10403 -- Simple property form
10404
10405 Prop := First (Expressions (Props));
10406 while Present (Prop) loop
10407 Analyze_External_Property (Prop);
10408 Next (Prop);
10409 end loop;
10410
10411 -- Property with expression form
10412
10413 Prop := First (Component_Associations (Props));
10414 while Present (Prop) loop
10415 Analyze_External_Property
10416 (Prop => First (Choices (Prop)),
10417 Expr => Expression (Prop));
10418
10419 Next (Prop);
10420 end loop;
10421
10422 -- Single property
10423
10424 else
10425 Analyze_External_Property (Props);
10426 end if;
10427
10428 -- An external state defined without any properties defaults
10429 -- all properties to True.
10430
10431 else
10432 AR_Val := True;
10433 AW_Val := True;
10434 ER_Val := True;
10435 EW_Val := True;
10436 end if;
10437
10438 -- Once all external properties have been processed, verify
10439 -- their mutual interaction. Do not perform the check when
10440 -- at least one of the properties is illegal as this will
10441 -- produce a bogus error.
10442
10443 if Errors = Serious_Errors_Detected then
10444 Check_External_Properties
10445 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10446 end if;
10447 end Analyze_External_Option;
10448
10449 -------------------------------
10450 -- Analyze_External_Property --
10451 -------------------------------
10452
10453 procedure Analyze_External_Property
10454 (Prop : Node_Id;
10455 Expr : Node_Id := Empty)
10456 is
10457 Expr_Val : Boolean;
10458
10459 begin
10460 -- Check the placement of "others" (if available)
10461
10462 if Nkind (Prop) = N_Others_Choice then
10463 if Others_Seen then
10464 SPARK_Msg_N
10465 ("only one others choice allowed in option External",
10466 Prop);
10467 else
10468 Others_Seen := True;
10469 end if;
10470
10471 elsif Others_Seen then
10472 SPARK_Msg_N
10473 ("others must be the last property in option External",
10474 Prop);
10475
10476 -- The only remaining legal options are the four predefined
10477 -- external properties.
10478
10479 elsif Nkind (Prop) = N_Identifier
10480 and then Nam_In (Chars (Prop), Name_Async_Readers,
10481 Name_Async_Writers,
10482 Name_Effective_Reads,
10483 Name_Effective_Writes)
10484 then
10485 null;
10486
10487 -- Otherwise the construct is not a valid property
10488
10489 else
10490 SPARK_Msg_N ("invalid external state property", Prop);
10491 return;
10492 end if;
10493
10494 -- Ensure that the expression of the external state property
10495 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10496
10497 if Present (Expr) then
10498 Analyze_And_Resolve (Expr, Standard_Boolean);
10499
10500 if Is_OK_Static_Expression (Expr) then
10501 Expr_Val := Is_True (Expr_Value (Expr));
10502 else
10503 SPARK_Msg_N
10504 ("expression of external state property must be "
10505 & "static", Expr);
10506 end if;
10507
10508 -- The lack of expression defaults the property to True
10509
10510 else
10511 Expr_Val := True;
10512 end if;
10513
10514 -- Named properties
10515
10516 if Nkind (Prop) = N_Identifier then
10517 if Chars (Prop) = Name_Async_Readers then
10518 Check_Duplicate_Property (Prop, AR_Seen);
10519 AR_Val := Expr_Val;
10520
10521 elsif Chars (Prop) = Name_Async_Writers then
10522 Check_Duplicate_Property (Prop, AW_Seen);
10523 AW_Val := Expr_Val;
10524
10525 elsif Chars (Prop) = Name_Effective_Reads then
10526 Check_Duplicate_Property (Prop, ER_Seen);
10527 ER_Val := Expr_Val;
10528
10529 else
10530 Check_Duplicate_Property (Prop, EW_Seen);
10531 EW_Val := Expr_Val;
10532 end if;
10533
10534 -- The handling of property "others" must take into account
10535 -- all other named properties that have been encountered so
10536 -- far. Only those that have not been seen are affected by
10537 -- "others".
10538
10539 else
10540 if not AR_Seen then
10541 AR_Val := Expr_Val;
10542 end if;
10543
10544 if not AW_Seen then
10545 AW_Val := Expr_Val;
10546 end if;
10547
10548 if not ER_Seen then
10549 ER_Val := Expr_Val;
10550 end if;
10551
10552 if not EW_Seen then
10553 EW_Val := Expr_Val;
10554 end if;
10555 end if;
10556 end Analyze_External_Property;
10557
10558 ----------------------------
10559 -- Analyze_Part_Of_Option --
10560 ----------------------------
10561
10562 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10563 Encap : constant Node_Id := Expression (Opt);
10564 Constits : Elist_Id;
10565 Encap_Id : Entity_Id;
10566 Legal : Boolean;
10567
10568 begin
10569 Check_Duplicate_Option (Opt, Part_Of_Seen);
10570
10571 Analyze_Part_Of
10572 (Indic => First (Choices (Opt)),
10573 Item_Id => State_Id,
10574 Encap => Encap,
10575 Encap_Id => Encap_Id,
10576 Legal => Legal);
10577
10578 -- The Part_Of indicator transforms the abstract state into
10579 -- a constituent of the encapsulating state or single
10580 -- concurrent type.
10581
10582 if Legal then
10583 pragma Assert (Present (Encap_Id));
10584 Constits := Part_Of_Constituents (Encap_Id);
10585
10586 if No (Constits) then
10587 Constits := New_Elmt_List;
10588 Set_Part_Of_Constituents (Encap_Id, Constits);
10589 end if;
10590
10591 Append_Elmt (State_Id, Constits);
10592 Set_Encapsulating_State (State_Id, Encap_Id);
10593 end if;
10594 end Analyze_Part_Of_Option;
10595
10596 ----------------------------
10597 -- Check_Duplicate_Option --
10598 ----------------------------
10599
10600 procedure Check_Duplicate_Option
10601 (Opt : Node_Id;
10602 Status : in out Boolean)
10603 is
10604 begin
10605 if Status then
10606 SPARK_Msg_N ("duplicate state option", Opt);
10607 end if;
10608
10609 Status := True;
10610 end Check_Duplicate_Option;
10611
10612 ------------------------------
10613 -- Check_Duplicate_Property --
10614 ------------------------------
10615
10616 procedure Check_Duplicate_Property
10617 (Prop : Node_Id;
10618 Status : in out Boolean)
10619 is
10620 begin
10621 if Status then
10622 SPARK_Msg_N ("duplicate external property", Prop);
10623 end if;
10624
10625 Status := True;
10626 end Check_Duplicate_Property;
10627
10628 -----------------------------
10629 -- Check_Ghost_Synchronous --
10630 -----------------------------
10631
10632 procedure Check_Ghost_Synchronous is
10633 begin
10634 -- A synchronized abstract state cannot be Ghost and vice
10635 -- versa (SPARK RM 6.9(19)).
10636
10637 if Ghost_Seen and Synchronous_Seen then
10638 SPARK_Msg_N ("synchronized state cannot be ghost", State);
10639 end if;
10640 end Check_Ghost_Synchronous;
10641
10642 ---------------------------
10643 -- Create_Abstract_State --
10644 ---------------------------
10645
10646 procedure Create_Abstract_State
10647 (Nam : Name_Id;
10648 Decl : Node_Id;
10649 Loc : Source_Ptr;
10650 Is_Null : Boolean)
10651 is
10652 begin
10653 -- The abstract state may be semi-declared when the related
10654 -- package was withed through a limited with clause. In that
10655 -- case reuse the entity to fully declare the state.
10656
10657 if Present (Decl) and then Present (Entity (Decl)) then
10658 State_Id := Entity (Decl);
10659
10660 -- Otherwise the elaboration of pragma Abstract_State
10661 -- declares the state.
10662
10663 else
10664 State_Id := Make_Defining_Identifier (Loc, Nam);
10665
10666 if Present (Decl) then
10667 Set_Entity (Decl, State_Id);
10668 end if;
10669 end if;
10670
10671 -- Null states never come from source
10672
10673 Set_Comes_From_Source (State_Id, not Is_Null);
10674 Set_Parent (State_Id, State);
10675 Set_Ekind (State_Id, E_Abstract_State);
10676 Set_Etype (State_Id, Standard_Void_Type);
10677 Set_Encapsulating_State (State_Id, Empty);
10678
10679 -- An abstract state declared within a Ghost region becomes
10680 -- Ghost (SPARK RM 6.9(2)).
10681
10682 if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then
10683 Set_Is_Ghost_Entity (State_Id);
10684 end if;
10685
10686 -- Establish a link between the state declaration and the
10687 -- abstract state entity. Note that a null state remains as
10688 -- N_Null and does not carry any linkages.
10689
10690 if not Is_Null then
10691 if Present (Decl) then
10692 Set_Entity (Decl, State_Id);
10693 Set_Etype (Decl, Standard_Void_Type);
10694 end if;
10695
10696 -- Every non-null state must be defined, nameable and
10697 -- resolvable.
10698
10699 Push_Scope (Pack_Id);
10700 Generate_Definition (State_Id);
10701 Enter_Name (State_Id);
10702 Pop_Scope;
10703 end if;
10704 end Create_Abstract_State;
10705
10706 -- Local variables
10707
10708 Opt : Node_Id;
10709 Opt_Nam : Node_Id;
10710
10711 -- Start of processing for Analyze_Abstract_State
10712
10713 begin
10714 -- A package with a null abstract state is not allowed to
10715 -- declare additional states.
10716
10717 if Null_Seen then
10718 SPARK_Msg_NE
10719 ("package & has null abstract state", State, Pack_Id);
10720
10721 -- Null states appear as internally generated entities
10722
10723 elsif Nkind (State) = N_Null then
10724 Create_Abstract_State
10725 (Nam => New_Internal_Name ('S'),
10726 Decl => Empty,
10727 Loc => Sloc (State),
10728 Is_Null => True);
10729 Null_Seen := True;
10730
10731 -- Catch a case where a null state appears in a list of
10732 -- non-null states.
10733
10734 if Non_Null_Seen then
10735 SPARK_Msg_NE
10736 ("package & has non-null abstract state",
10737 State, Pack_Id);
10738 end if;
10739
10740 -- Simple state declaration
10741
10742 elsif Nkind (State) = N_Identifier then
10743 Create_Abstract_State
10744 (Nam => Chars (State),
10745 Decl => State,
10746 Loc => Sloc (State),
10747 Is_Null => False);
10748 Non_Null_Seen := True;
10749
10750 -- State declaration with various options. This construct
10751 -- appears as an extension aggregate in the tree.
10752
10753 elsif Nkind (State) = N_Extension_Aggregate then
10754 if Nkind (Ancestor_Part (State)) = N_Identifier then
10755 Create_Abstract_State
10756 (Nam => Chars (Ancestor_Part (State)),
10757 Decl => Ancestor_Part (State),
10758 Loc => Sloc (Ancestor_Part (State)),
10759 Is_Null => False);
10760 Non_Null_Seen := True;
10761 else
10762 SPARK_Msg_N
10763 ("state name must be an identifier",
10764 Ancestor_Part (State));
10765 end if;
10766
10767 -- Options External, Ghost and Synchronous appear as
10768 -- expressions.
10769
10770 Opt := First (Expressions (State));
10771 while Present (Opt) loop
10772 if Nkind (Opt) = N_Identifier then
10773
10774 -- External
10775
10776 if Chars (Opt) = Name_External then
10777 Check_Duplicate_Option (Opt, External_Seen);
10778 Analyze_External_Option (Opt);
10779
10780 -- Ghost
10781
10782 elsif Chars (Opt) = Name_Ghost then
10783 Check_Duplicate_Option (Opt, Ghost_Seen);
10784 Check_Ghost_Synchronous;
10785
10786 if Present (State_Id) then
10787 Set_Is_Ghost_Entity (State_Id);
10788 end if;
10789
10790 -- Synchronous
10791
10792 elsif Chars (Opt) = Name_Synchronous then
10793 Check_Duplicate_Option (Opt, Synchronous_Seen);
10794 Check_Ghost_Synchronous;
10795
10796 -- Option Part_Of without an encapsulating state is
10797 -- illegal (SPARK RM 7.1.4(9)).
10798
10799 elsif Chars (Opt) = Name_Part_Of then
10800 SPARK_Msg_N
10801 ("indicator Part_Of must denote abstract state, "
10802 & "single protected type or single task type",
10803 Opt);
10804
10805 -- Do not emit an error message when a previous state
10806 -- declaration with options was not parenthesized as
10807 -- the option is actually another state declaration.
10808 --
10809 -- with Abstract_State
10810 -- (State_1 with ..., -- missing parentheses
10811 -- (State_2 with ...),
10812 -- State_3) -- ok state declaration
10813
10814 elsif Missing_Parentheses then
10815 null;
10816
10817 -- Otherwise the option is not allowed. Note that it
10818 -- is not possible to distinguish between an option
10819 -- and a state declaration when a previous state with
10820 -- options not properly parentheses.
10821 --
10822 -- with Abstract_State
10823 -- (State_1 with ..., -- missing parentheses
10824 -- State_2); -- could be an option
10825
10826 else
10827 SPARK_Msg_N
10828 ("simple option not allowed in state declaration",
10829 Opt);
10830 end if;
10831
10832 -- Catch a case where missing parentheses around a state
10833 -- declaration with options cause a subsequent state
10834 -- declaration with options to be treated as an option.
10835 --
10836 -- with Abstract_State
10837 -- (State_1 with ..., -- missing parentheses
10838 -- (State_2 with ...))
10839
10840 elsif Nkind (Opt) = N_Extension_Aggregate then
10841 Missing_Parentheses := True;
10842 SPARK_Msg_N
10843 ("state declaration must be parenthesized",
10844 Ancestor_Part (State));
10845
10846 -- Otherwise the option is malformed
10847
10848 else
10849 SPARK_Msg_N ("malformed option", Opt);
10850 end if;
10851
10852 Next (Opt);
10853 end loop;
10854
10855 -- Options External and Part_Of appear as component
10856 -- associations.
10857
10858 Opt := First (Component_Associations (State));
10859 while Present (Opt) loop
10860 Opt_Nam := First (Choices (Opt));
10861
10862 if Nkind (Opt_Nam) = N_Identifier then
10863 if Chars (Opt_Nam) = Name_External then
10864 Analyze_External_Option (Opt);
10865
10866 elsif Chars (Opt_Nam) = Name_Part_Of then
10867 Analyze_Part_Of_Option (Opt);
10868
10869 else
10870 SPARK_Msg_N ("invalid state option", Opt);
10871 end if;
10872 else
10873 SPARK_Msg_N ("invalid state option", Opt);
10874 end if;
10875
10876 Next (Opt);
10877 end loop;
10878
10879 -- Any other attempt to declare a state is illegal
10880
10881 else
10882 Malformed_State_Error (State);
10883 return;
10884 end if;
10885
10886 -- Guard against a junk state. In such cases no entity is
10887 -- generated and the subsequent checks cannot be applied.
10888
10889 if Present (State_Id) then
10890
10891 -- Verify whether the state does not introduce an illegal
10892 -- hidden state within a package subject to a null abstract
10893 -- state.
10894
10895 Check_No_Hidden_State (State_Id);
10896
10897 -- Check whether the lack of option Part_Of agrees with the
10898 -- placement of the abstract state with respect to the state
10899 -- space.
10900
10901 if not Part_Of_Seen then
10902 Check_Missing_Part_Of (State_Id);
10903 end if;
10904
10905 -- Associate the state with its related package
10906
10907 if No (Abstract_States (Pack_Id)) then
10908 Set_Abstract_States (Pack_Id, New_Elmt_List);
10909 end if;
10910
10911 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10912 end if;
10913 end Analyze_Abstract_State;
10914
10915 ---------------------------
10916 -- Malformed_State_Error --
10917 ---------------------------
10918
10919 procedure Malformed_State_Error (State : Node_Id) is
10920 begin
10921 Error_Msg_N ("malformed abstract state declaration", State);
10922
10923 -- An abstract state with a simple option is being declared
10924 -- with "=>" rather than the legal "with". The state appears
10925 -- as a component association.
10926
10927 if Nkind (State) = N_Component_Association then
10928 Error_Msg_N ("\use WITH to specify simple option", State);
10929 end if;
10930 end Malformed_State_Error;
10931
10932 -- Local variables
10933
10934 Pack_Decl : Node_Id;
10935 Pack_Id : Entity_Id;
10936 State : Node_Id;
10937 States : Node_Id;
10938
10939 -- Start of processing for Abstract_State
10940
10941 begin
10942 GNAT_Pragma;
10943 Check_No_Identifiers;
10944 Check_Arg_Count (1);
10945
10946 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
10947
10948 -- Ensure the proper placement of the pragma. Abstract states must
10949 -- be associated with a package declaration.
10950
10951 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
10952 N_Package_Declaration)
10953 then
10954 null;
10955
10956 -- Otherwise the pragma is associated with an illegal construct
10957
10958 else
10959 Pragma_Misplaced;
10960 return;
10961 end if;
10962
10963 Pack_Id := Defining_Entity (Pack_Decl);
10964
10965 -- Chain the pragma on the contract for completeness
10966
10967 Add_Contract_Item (N, Pack_Id);
10968
10969 -- The legality checks of pragmas Abstract_State, Initializes, and
10970 -- Initial_Condition are affected by the SPARK mode in effect. In
10971 -- addition, these three pragmas are subject to an inherent order:
10972
10973 -- 1) Abstract_State
10974 -- 2) Initializes
10975 -- 3) Initial_Condition
10976
10977 -- Analyze all these pragmas in the order outlined above
10978
10979 Analyze_If_Present (Pragma_SPARK_Mode);
10980
10981 -- A pragma that applies to a Ghost entity becomes Ghost for the
10982 -- purposes of legality checks and removal of ignored Ghost code.
10983
10984 Mark_Pragma_As_Ghost (N, Pack_Id);
10985 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
10986
10987 States := Expression (Get_Argument (N, Pack_Id));
10988
10989 -- Multiple non-null abstract states appear as an aggregate
10990
10991 if Nkind (States) = N_Aggregate then
10992 State := First (Expressions (States));
10993 while Present (State) loop
10994 Analyze_Abstract_State (State, Pack_Id);
10995 Next (State);
10996 end loop;
10997
10998 -- An abstract state with a simple option is being illegaly
10999 -- declared with "=>" rather than "with". In this case the
11000 -- state declaration appears as a component association.
11001
11002 if Present (Component_Associations (States)) then
11003 State := First (Component_Associations (States));
11004 while Present (State) loop
11005 Malformed_State_Error (State);
11006 Next (State);
11007 end loop;
11008 end if;
11009
11010 -- Various forms of a single abstract state. Note that these may
11011 -- include malformed state declarations.
11012
11013 else
11014 Analyze_Abstract_State (States, Pack_Id);
11015 end if;
11016
11017 Analyze_If_Present (Pragma_Initializes);
11018 Analyze_If_Present (Pragma_Initial_Condition);
11019 end Abstract_State;
11020
11021 ------------
11022 -- Ada_83 --
11023 ------------
11024
11025 -- pragma Ada_83;
11026
11027 -- Note: this pragma also has some specific processing in Par.Prag
11028 -- because we want to set the Ada version mode during parsing.
11029
11030 when Pragma_Ada_83 =>
11031 GNAT_Pragma;
11032 Check_Arg_Count (0);
11033
11034 -- We really should check unconditionally for proper configuration
11035 -- pragma placement, since we really don't want mixed Ada modes
11036 -- within a single unit, and the GNAT reference manual has always
11037 -- said this was a configuration pragma, but we did not check and
11038 -- are hesitant to add the check now.
11039
11040 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11041 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11042 -- or Ada 2012 mode.
11043
11044 if Ada_Version >= Ada_2005 then
11045 Check_Valid_Configuration_Pragma;
11046 end if;
11047
11048 -- Now set Ada 83 mode
11049
11050 if not Latest_Ada_Only then
11051 Ada_Version := Ada_83;
11052 Ada_Version_Explicit := Ada_83;
11053 Ada_Version_Pragma := N;
11054 end if;
11055
11056 ------------
11057 -- Ada_95 --
11058 ------------
11059
11060 -- pragma Ada_95;
11061
11062 -- Note: this pragma also has some specific processing in Par.Prag
11063 -- because we want to set the Ada 83 version mode during parsing.
11064
11065 when Pragma_Ada_95 =>
11066 GNAT_Pragma;
11067 Check_Arg_Count (0);
11068
11069 -- We really should check unconditionally for proper configuration
11070 -- pragma placement, since we really don't want mixed Ada modes
11071 -- within a single unit, and the GNAT reference manual has always
11072 -- said this was a configuration pragma, but we did not check and
11073 -- are hesitant to add the check now.
11074
11075 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11076 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11077
11078 if Ada_Version >= Ada_2005 then
11079 Check_Valid_Configuration_Pragma;
11080 end if;
11081
11082 -- Now set Ada 95 mode
11083
11084 if not Latest_Ada_Only then
11085 Ada_Version := Ada_95;
11086 Ada_Version_Explicit := Ada_95;
11087 Ada_Version_Pragma := N;
11088 end if;
11089
11090 ---------------------
11091 -- Ada_05/Ada_2005 --
11092 ---------------------
11093
11094 -- pragma Ada_05;
11095 -- pragma Ada_05 (LOCAL_NAME);
11096
11097 -- pragma Ada_2005;
11098 -- pragma Ada_2005 (LOCAL_NAME):
11099
11100 -- Note: these pragmas also have some specific processing in Par.Prag
11101 -- because we want to set the Ada 2005 version mode during parsing.
11102
11103 -- The one argument form is used for managing the transition from
11104 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
11105 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
11106 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
11107 -- mode, a preference rule is established which does not choose
11108 -- such an entity unless it is unambiguously specified. This avoids
11109 -- extra subprograms marked this way from generating ambiguities in
11110 -- otherwise legal pre-Ada_2005 programs. The one argument form is
11111 -- intended for exclusive use in the GNAT run-time library.
11112
11113 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
11114 E_Id : Node_Id;
11115
11116 begin
11117 GNAT_Pragma;
11118
11119 if Arg_Count = 1 then
11120 Check_Arg_Is_Local_Name (Arg1);
11121 E_Id := Get_Pragma_Arg (Arg1);
11122
11123 if Etype (E_Id) = Any_Type then
11124 return;
11125 end if;
11126
11127 Set_Is_Ada_2005_Only (Entity (E_Id));
11128 Record_Rep_Item (Entity (E_Id), N);
11129
11130 else
11131 Check_Arg_Count (0);
11132
11133 -- For Ada_2005 we unconditionally enforce the documented
11134 -- configuration pragma placement, since we do not want to
11135 -- tolerate mixed modes in a unit involving Ada 2005. That
11136 -- would cause real difficulties for those cases where there
11137 -- are incompatibilities between Ada 95 and Ada 2005.
11138
11139 Check_Valid_Configuration_Pragma;
11140
11141 -- Now set appropriate Ada mode
11142
11143 if not Latest_Ada_Only then
11144 Ada_Version := Ada_2005;
11145 Ada_Version_Explicit := Ada_2005;
11146 Ada_Version_Pragma := N;
11147 end if;
11148 end if;
11149 end;
11150
11151 ---------------------
11152 -- Ada_12/Ada_2012 --
11153 ---------------------
11154
11155 -- pragma Ada_12;
11156 -- pragma Ada_12 (LOCAL_NAME);
11157
11158 -- pragma Ada_2012;
11159 -- pragma Ada_2012 (LOCAL_NAME):
11160
11161 -- Note: these pragmas also have some specific processing in Par.Prag
11162 -- because we want to set the Ada 2012 version mode during parsing.
11163
11164 -- The one argument form is used for managing the transition from Ada
11165 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11166 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11167 -- mode will generate a warning. In addition, in any pre-Ada_2012
11168 -- mode, a preference rule is established which does not choose
11169 -- such an entity unless it is unambiguously specified. This avoids
11170 -- extra subprograms marked this way from generating ambiguities in
11171 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11172 -- intended for exclusive use in the GNAT run-time library.
11173
11174 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
11175 E_Id : Node_Id;
11176
11177 begin
11178 GNAT_Pragma;
11179
11180 if Arg_Count = 1 then
11181 Check_Arg_Is_Local_Name (Arg1);
11182 E_Id := Get_Pragma_Arg (Arg1);
11183
11184 if Etype (E_Id) = Any_Type then
11185 return;
11186 end if;
11187
11188 Set_Is_Ada_2012_Only (Entity (E_Id));
11189 Record_Rep_Item (Entity (E_Id), N);
11190
11191 else
11192 Check_Arg_Count (0);
11193
11194 -- For Ada_2012 we unconditionally enforce the documented
11195 -- configuration pragma placement, since we do not want to
11196 -- tolerate mixed modes in a unit involving Ada 2012. That
11197 -- would cause real difficulties for those cases where there
11198 -- are incompatibilities between Ada 95 and Ada 2012. We could
11199 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11200
11201 Check_Valid_Configuration_Pragma;
11202
11203 -- Now set appropriate Ada mode
11204
11205 Ada_Version := Ada_2012;
11206 Ada_Version_Explicit := Ada_2012;
11207 Ada_Version_Pragma := N;
11208 end if;
11209 end;
11210
11211 ----------------------
11212 -- All_Calls_Remote --
11213 ----------------------
11214
11215 -- pragma All_Calls_Remote [(library_package_NAME)];
11216
11217 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
11218 Lib_Entity : Entity_Id;
11219
11220 begin
11221 Check_Ada_83_Warning;
11222 Check_Valid_Library_Unit_Pragma;
11223
11224 if Nkind (N) = N_Null_Statement then
11225 return;
11226 end if;
11227
11228 Lib_Entity := Find_Lib_Unit_Name;
11229
11230 -- A pragma that applies to a Ghost entity becomes Ghost for the
11231 -- purposes of legality checks and removal of ignored Ghost code.
11232
11233 Mark_Pragma_As_Ghost (N, Lib_Entity);
11234
11235 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11236
11237 if Present (Lib_Entity) and then not Debug_Flag_U then
11238 if not Is_Remote_Call_Interface (Lib_Entity) then
11239 Error_Pragma ("pragma% only apply to rci unit");
11240
11241 -- Set flag for entity of the library unit
11242
11243 else
11244 Set_Has_All_Calls_Remote (Lib_Entity);
11245 end if;
11246 end if;
11247 end All_Calls_Remote;
11248
11249 ---------------------------
11250 -- Allow_Integer_Address --
11251 ---------------------------
11252
11253 -- pragma Allow_Integer_Address;
11254
11255 when Pragma_Allow_Integer_Address =>
11256 GNAT_Pragma;
11257 Check_Valid_Configuration_Pragma;
11258 Check_Arg_Count (0);
11259
11260 -- If Address is a private type, then set the flag to allow
11261 -- integer address values. If Address is not private, then this
11262 -- pragma has no purpose, so it is simply ignored. Not clear if
11263 -- there are any such targets now.
11264
11265 if Opt.Address_Is_Private then
11266 Opt.Allow_Integer_Address := True;
11267 end if;
11268
11269 --------------
11270 -- Annotate --
11271 --------------
11272
11273 -- pragma Annotate
11274 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11275 -- ARG ::= NAME | EXPRESSION
11276
11277 -- The first two arguments are by convention intended to refer to an
11278 -- external tool and a tool-specific function. These arguments are
11279 -- not analyzed.
11280
11281 when Pragma_Annotate => Annotate : declare
11282 Arg : Node_Id;
11283 Expr : Node_Id;
11284 Nam_Arg : Node_Id;
11285
11286 begin
11287 GNAT_Pragma;
11288 Check_At_Least_N_Arguments (1);
11289
11290 Nam_Arg := Last (Pragma_Argument_Associations (N));
11291
11292 -- Determine whether the last argument is "Entity => local_NAME"
11293 -- and if it is, perform the required semantic checks. Remove the
11294 -- argument from further processing.
11295
11296 if Nkind (Nam_Arg) = N_Pragma_Argument_Association
11297 and then Chars (Nam_Arg) = Name_Entity
11298 then
11299 Check_Arg_Is_Local_Name (Nam_Arg);
11300 Arg_Count := Arg_Count - 1;
11301
11302 -- A pragma that applies to a Ghost entity becomes Ghost for
11303 -- the purposes of legality checks and removal of ignored Ghost
11304 -- code.
11305
11306 if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg))
11307 and then Present (Entity (Get_Pragma_Arg (Nam_Arg)))
11308 then
11309 Mark_Pragma_As_Ghost (N, Entity (Get_Pragma_Arg (Nam_Arg)));
11310 end if;
11311
11312 -- Not allowed in compiler units (bootstrap issues)
11313
11314 Check_Compiler_Unit ("Entity for pragma Annotate", N);
11315 end if;
11316
11317 -- Continue the processing with last argument removed for now
11318
11319 Check_Arg_Is_Identifier (Arg1);
11320 Check_No_Identifiers;
11321 Store_Note (N);
11322
11323 -- The second parameter is optional, it is never analyzed
11324
11325 if No (Arg2) then
11326 null;
11327
11328 -- Otherwise there is a second parameter
11329
11330 else
11331 -- The second parameter must be an identifier
11332
11333 Check_Arg_Is_Identifier (Arg2);
11334
11335 -- Process the remaining parameters (if any)
11336
11337 Arg := Next (Arg2);
11338 while Present (Arg) loop
11339 Expr := Get_Pragma_Arg (Arg);
11340 Analyze (Expr);
11341
11342 if Is_Entity_Name (Expr) then
11343 null;
11344
11345 -- For string literals, we assume Standard_String as the
11346 -- type, unless the string contains wide or wide_wide
11347 -- characters.
11348
11349 elsif Nkind (Expr) = N_String_Literal then
11350 if Has_Wide_Wide_Character (Expr) then
11351 Resolve (Expr, Standard_Wide_Wide_String);
11352 elsif Has_Wide_Character (Expr) then
11353 Resolve (Expr, Standard_Wide_String);
11354 else
11355 Resolve (Expr, Standard_String);
11356 end if;
11357
11358 elsif Is_Overloaded (Expr) then
11359 Error_Pragma_Arg ("ambiguous argument for pragma%", Expr);
11360
11361 else
11362 Resolve (Expr);
11363 end if;
11364
11365 Next (Arg);
11366 end loop;
11367 end if;
11368 end Annotate;
11369
11370 -------------------------------------------------
11371 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11372 -------------------------------------------------
11373
11374 -- pragma Assert
11375 -- ( [Check => ] Boolean_EXPRESSION
11376 -- [, [Message =>] Static_String_EXPRESSION]);
11377
11378 -- pragma Assert_And_Cut
11379 -- ( [Check => ] Boolean_EXPRESSION
11380 -- [, [Message =>] Static_String_EXPRESSION]);
11381
11382 -- pragma Assume
11383 -- ( [Check => ] Boolean_EXPRESSION
11384 -- [, [Message =>] Static_String_EXPRESSION]);
11385
11386 -- pragma Loop_Invariant
11387 -- ( [Check => ] Boolean_EXPRESSION
11388 -- [, [Message =>] Static_String_EXPRESSION]);
11389
11390 when Pragma_Assert |
11391 Pragma_Assert_And_Cut |
11392 Pragma_Assume |
11393 Pragma_Loop_Invariant =>
11394 Assert : declare
11395 function Contains_Loop_Entry (Expr : Node_Id) return Boolean;
11396 -- Determine whether expression Expr contains a Loop_Entry
11397 -- attribute reference.
11398
11399 -------------------------
11400 -- Contains_Loop_Entry --
11401 -------------------------
11402
11403 function Contains_Loop_Entry (Expr : Node_Id) return Boolean is
11404 Has_Loop_Entry : Boolean := False;
11405
11406 function Process (N : Node_Id) return Traverse_Result;
11407 -- Process function for traversal to look for Loop_Entry
11408
11409 -------------
11410 -- Process --
11411 -------------
11412
11413 function Process (N : Node_Id) return Traverse_Result is
11414 begin
11415 if Nkind (N) = N_Attribute_Reference
11416 and then Attribute_Name (N) = Name_Loop_Entry
11417 then
11418 Has_Loop_Entry := True;
11419 return Abandon;
11420 else
11421 return OK;
11422 end if;
11423 end Process;
11424
11425 procedure Traverse is new Traverse_Proc (Process);
11426
11427 -- Start of processing for Contains_Loop_Entry
11428
11429 begin
11430 Traverse (Expr);
11431 return Has_Loop_Entry;
11432 end Contains_Loop_Entry;
11433
11434 -- Local variables
11435
11436 Expr : Node_Id;
11437 New_Args : List_Id;
11438
11439 -- Start of processing for Assert
11440
11441 begin
11442 -- Assert is an Ada 2005 RM-defined pragma
11443
11444 if Prag_Id = Pragma_Assert then
11445 Ada_2005_Pragma;
11446
11447 -- The remaining ones are GNAT pragmas
11448
11449 else
11450 GNAT_Pragma;
11451 end if;
11452
11453 Check_At_Least_N_Arguments (1);
11454 Check_At_Most_N_Arguments (2);
11455 Check_Arg_Order ((Name_Check, Name_Message));
11456 Check_Optional_Identifier (Arg1, Name_Check);
11457 Expr := Get_Pragma_Arg (Arg1);
11458
11459 -- Special processing for Loop_Invariant, Loop_Variant or for
11460 -- other cases where a Loop_Entry attribute is present. If the
11461 -- assertion pragma contains attribute Loop_Entry, ensure that
11462 -- the related pragma is within a loop.
11463
11464 if Prag_Id = Pragma_Loop_Invariant
11465 or else Prag_Id = Pragma_Loop_Variant
11466 or else Contains_Loop_Entry (Expr)
11467 then
11468 Check_Loop_Pragma_Placement;
11469
11470 -- Perform preanalysis to deal with embedded Loop_Entry
11471 -- attributes.
11472
11473 Preanalyze_Assert_Expression (Expr, Any_Boolean);
11474 end if;
11475
11476 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11477 -- a corresponding Check pragma:
11478
11479 -- pragma Check (name, condition [, msg]);
11480
11481 -- Where name is the identifier matching the pragma name. So
11482 -- rewrite pragma in this manner, transfer the message argument
11483 -- if present, and analyze the result
11484
11485 -- Note: When dealing with a semantically analyzed tree, the
11486 -- information that a Check node N corresponds to a source Assert,
11487 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11488 -- pragma kind of Original_Node(N).
11489
11490 New_Args := New_List (
11491 Make_Pragma_Argument_Association (Loc,
11492 Expression => Make_Identifier (Loc, Pname)),
11493 Make_Pragma_Argument_Association (Sloc (Expr),
11494 Expression => Expr));
11495
11496 if Arg_Count > 1 then
11497 Check_Optional_Identifier (Arg2, Name_Message);
11498
11499 -- Provide semantic annnotations for optional argument, for
11500 -- ASIS use, before rewriting.
11501
11502 Preanalyze_And_Resolve (Expression (Arg2), Standard_String);
11503 Append_To (New_Args, New_Copy_Tree (Arg2));
11504 end if;
11505
11506 -- Rewrite as Check pragma
11507
11508 Rewrite (N,
11509 Make_Pragma (Loc,
11510 Chars => Name_Check,
11511 Pragma_Argument_Associations => New_Args));
11512
11513 Analyze (N);
11514 end Assert;
11515
11516 ----------------------
11517 -- Assertion_Policy --
11518 ----------------------
11519
11520 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11521
11522 -- The following form is Ada 2012 only, but we allow it in all modes
11523
11524 -- Pragma Assertion_Policy (
11525 -- ASSERTION_KIND => POLICY_IDENTIFIER
11526 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11527
11528 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11529
11530 -- RM_ASSERTION_KIND ::= Assert |
11531 -- Static_Predicate |
11532 -- Dynamic_Predicate |
11533 -- Pre |
11534 -- Pre'Class |
11535 -- Post |
11536 -- Post'Class |
11537 -- Type_Invariant |
11538 -- Type_Invariant'Class
11539
11540 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11541 -- Assume |
11542 -- Contract_Cases |
11543 -- Debug |
11544 -- Default_Initial_Condition |
11545 -- Ghost |
11546 -- Initial_Condition |
11547 -- Loop_Invariant |
11548 -- Loop_Variant |
11549 -- Postcondition |
11550 -- Precondition |
11551 -- Predicate |
11552 -- Refined_Post |
11553 -- Statement_Assertions
11554
11555 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11556 -- ID_ASSERTION_KIND list contains implementation-defined additions
11557 -- recognized by GNAT. The effect is to control the behavior of
11558 -- identically named aspects and pragmas, depending on the specified
11559 -- policy identifier:
11560
11561 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11562
11563 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11564 -- implementation-defined addition that results in totally ignoring
11565 -- the corresponding assertion. If Disable is specified, then the
11566 -- argument of the assertion is not even analyzed. This is useful
11567 -- when the aspect/pragma argument references entities in a with'ed
11568 -- package that is replaced by a dummy package in the final build.
11569
11570 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11571 -- and Type_Invariant'Class were recognized by the parser and
11572 -- transformed into references to the special internal identifiers
11573 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11574 -- processing is required here.
11575
11576 when Pragma_Assertion_Policy => Assertion_Policy : declare
11577 Arg : Node_Id;
11578 Kind : Name_Id;
11579 LocP : Source_Ptr;
11580 Policy : Node_Id;
11581
11582 begin
11583 Ada_2005_Pragma;
11584
11585 -- This can always appear as a configuration pragma
11586
11587 if Is_Configuration_Pragma then
11588 null;
11589
11590 -- It can also appear in a declarative part or package spec in Ada
11591 -- 2012 mode. We allow this in other modes, but in that case we
11592 -- consider that we have an Ada 2012 pragma on our hands.
11593
11594 else
11595 Check_Is_In_Decl_Part_Or_Package_Spec;
11596 Ada_2012_Pragma;
11597 end if;
11598
11599 -- One argument case with no identifier (first form above)
11600
11601 if Arg_Count = 1
11602 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
11603 or else Chars (Arg1) = No_Name)
11604 then
11605 Check_Arg_Is_One_Of
11606 (Arg1, Name_Check, Name_Disable, Name_Ignore);
11607
11608 -- Treat one argument Assertion_Policy as equivalent to:
11609
11610 -- pragma Check_Policy (Assertion, policy)
11611
11612 -- So rewrite pragma in that manner and link on to the chain
11613 -- of Check_Policy pragmas, marking the pragma as analyzed.
11614
11615 Policy := Get_Pragma_Arg (Arg1);
11616
11617 Rewrite (N,
11618 Make_Pragma (Loc,
11619 Chars => Name_Check_Policy,
11620 Pragma_Argument_Associations => New_List (
11621 Make_Pragma_Argument_Association (Loc,
11622 Expression => Make_Identifier (Loc, Name_Assertion)),
11623
11624 Make_Pragma_Argument_Association (Loc,
11625 Expression =>
11626 Make_Identifier (Sloc (Policy), Chars (Policy))))));
11627 Analyze (N);
11628
11629 -- Here if we have two or more arguments
11630
11631 else
11632 Check_At_Least_N_Arguments (1);
11633 Ada_2012_Pragma;
11634
11635 -- Loop through arguments
11636
11637 Arg := Arg1;
11638 while Present (Arg) loop
11639 LocP := Sloc (Arg);
11640
11641 -- Kind must be specified
11642
11643 if Nkind (Arg) /= N_Pragma_Argument_Association
11644 or else Chars (Arg) = No_Name
11645 then
11646 Error_Pragma_Arg
11647 ("missing assertion kind for pragma%", Arg);
11648 end if;
11649
11650 -- Check Kind and Policy have allowed forms
11651
11652 Kind := Chars (Arg);
11653 Policy := Get_Pragma_Arg (Arg);
11654
11655 if not Is_Valid_Assertion_Kind (Kind) then
11656 Error_Pragma_Arg
11657 ("invalid assertion kind for pragma%", Arg);
11658 end if;
11659
11660 Check_Arg_Is_One_Of
11661 (Arg, Name_Check, Name_Disable, Name_Ignore);
11662
11663 if Kind = Name_Ghost then
11664
11665 -- The Ghost policy must be either Check or Ignore
11666 -- (SPARK RM 6.9(6)).
11667
11668 if not Nam_In (Chars (Policy), Name_Check,
11669 Name_Ignore)
11670 then
11671 Error_Pragma_Arg
11672 ("argument of pragma % Ghost must be Check or "
11673 & "Ignore", Policy);
11674 end if;
11675
11676 -- Pragma Assertion_Policy specifying a Ghost policy
11677 -- cannot occur within a Ghost subprogram or package
11678 -- (SPARK RM 6.9(14)).
11679
11680 if Ghost_Mode > None then
11681 Error_Pragma
11682 ("pragma % cannot appear within ghost subprogram or "
11683 & "package");
11684 end if;
11685 end if;
11686
11687 -- Rewrite the Assertion_Policy pragma as a series of
11688 -- Check_Policy pragmas of the form:
11689
11690 -- Check_Policy (Kind, Policy);
11691
11692 -- Note: the insertion of the pragmas cannot be done with
11693 -- Insert_Action because in the configuration case, there
11694 -- are no scopes on the scope stack and the mechanism will
11695 -- fail.
11696
11697 Insert_Before_And_Analyze (N,
11698 Make_Pragma (LocP,
11699 Chars => Name_Check_Policy,
11700 Pragma_Argument_Associations => New_List (
11701 Make_Pragma_Argument_Association (LocP,
11702 Expression => Make_Identifier (LocP, Kind)),
11703 Make_Pragma_Argument_Association (LocP,
11704 Expression => Policy))));
11705
11706 Arg := Next (Arg);
11707 end loop;
11708
11709 -- Rewrite the Assertion_Policy pragma as null since we have
11710 -- now inserted all the equivalent Check pragmas.
11711
11712 Rewrite (N, Make_Null_Statement (Loc));
11713 Analyze (N);
11714 end if;
11715 end Assertion_Policy;
11716
11717 ------------------------------
11718 -- Assume_No_Invalid_Values --
11719 ------------------------------
11720
11721 -- pragma Assume_No_Invalid_Values (On | Off);
11722
11723 when Pragma_Assume_No_Invalid_Values =>
11724 GNAT_Pragma;
11725 Check_Valid_Configuration_Pragma;
11726 Check_Arg_Count (1);
11727 Check_No_Identifiers;
11728 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11729
11730 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11731 Assume_No_Invalid_Values := True;
11732 else
11733 Assume_No_Invalid_Values := False;
11734 end if;
11735
11736 --------------------------
11737 -- Attribute_Definition --
11738 --------------------------
11739
11740 -- pragma Attribute_Definition
11741 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11742 -- [Entity =>] LOCAL_NAME,
11743 -- [Expression =>] EXPRESSION | NAME);
11744
11745 when Pragma_Attribute_Definition => Attribute_Definition : declare
11746 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11747 Aname : Name_Id;
11748
11749 begin
11750 GNAT_Pragma;
11751 Check_Arg_Count (3);
11752 Check_Optional_Identifier (Arg1, "attribute");
11753 Check_Optional_Identifier (Arg2, "entity");
11754 Check_Optional_Identifier (Arg3, "expression");
11755
11756 if Nkind (Attribute_Designator) /= N_Identifier then
11757 Error_Msg_N ("attribute name expected", Attribute_Designator);
11758 return;
11759 end if;
11760
11761 Check_Arg_Is_Local_Name (Arg2);
11762
11763 -- If the attribute is not recognized, then issue a warning (not
11764 -- an error), and ignore the pragma.
11765
11766 Aname := Chars (Attribute_Designator);
11767
11768 if not Is_Attribute_Name (Aname) then
11769 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11770 return;
11771 end if;
11772
11773 -- Otherwise, rewrite the pragma as an attribute definition clause
11774
11775 Rewrite (N,
11776 Make_Attribute_Definition_Clause (Loc,
11777 Name => Get_Pragma_Arg (Arg2),
11778 Chars => Aname,
11779 Expression => Get_Pragma_Arg (Arg3)));
11780 Analyze (N);
11781 end Attribute_Definition;
11782
11783 ------------------------------------------------------------------
11784 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11785 ------------------------------------------------------------------
11786
11787 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
11788 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
11789 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
11790 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
11791
11792 when Pragma_Async_Readers |
11793 Pragma_Async_Writers |
11794 Pragma_Effective_Reads |
11795 Pragma_Effective_Writes =>
11796 Async_Effective : declare
11797 Obj_Decl : Node_Id;
11798 Obj_Id : Entity_Id;
11799
11800 begin
11801 GNAT_Pragma;
11802 Check_No_Identifiers;
11803 Check_At_Most_N_Arguments (1);
11804
11805 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
11806
11807 -- Object declaration
11808
11809 if Nkind (Obj_Decl) = N_Object_Declaration then
11810 null;
11811
11812 -- Otherwise the pragma is associated with an illegal construact
11813
11814 else
11815 Pragma_Misplaced;
11816 return;
11817 end if;
11818
11819 Obj_Id := Defining_Entity (Obj_Decl);
11820
11821 -- Perform minimal verification to ensure that the argument is at
11822 -- least a variable. Subsequent finer grained checks will be done
11823 -- at the end of the declarative region the contains the pragma.
11824
11825 if Ekind (Obj_Id) = E_Variable then
11826
11827 -- Chain the pragma on the contract for further processing by
11828 -- Analyze_External_Property_In_Decl_Part.
11829
11830 Add_Contract_Item (N, Obj_Id);
11831
11832 -- A pragma that applies to a Ghost entity becomes Ghost for
11833 -- the purposes of legality checks and removal of ignored Ghost
11834 -- code.
11835
11836 Mark_Pragma_As_Ghost (N, Obj_Id);
11837
11838 -- Analyze the Boolean expression (if any)
11839
11840 if Present (Arg1) then
11841 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
11842 end if;
11843
11844 -- Otherwise the external property applies to a constant
11845
11846 else
11847 Error_Pragma ("pragma % must apply to a volatile object");
11848 end if;
11849 end Async_Effective;
11850
11851 ------------------
11852 -- Asynchronous --
11853 ------------------
11854
11855 -- pragma Asynchronous (LOCAL_NAME);
11856
11857 when Pragma_Asynchronous => Asynchronous : declare
11858 C_Ent : Entity_Id;
11859 Decl : Node_Id;
11860 Formal : Entity_Id;
11861 L : List_Id;
11862 Nm : Entity_Id;
11863 S : Node_Id;
11864
11865 procedure Process_Async_Pragma;
11866 -- Common processing for procedure and access-to-procedure case
11867
11868 --------------------------
11869 -- Process_Async_Pragma --
11870 --------------------------
11871
11872 procedure Process_Async_Pragma is
11873 begin
11874 if No (L) then
11875 Set_Is_Asynchronous (Nm);
11876 return;
11877 end if;
11878
11879 -- The formals should be of mode IN (RM E.4.1(6))
11880
11881 S := First (L);
11882 while Present (S) loop
11883 Formal := Defining_Identifier (S);
11884
11885 if Nkind (Formal) = N_Defining_Identifier
11886 and then Ekind (Formal) /= E_In_Parameter
11887 then
11888 Error_Pragma_Arg
11889 ("pragma% procedure can only have IN parameter",
11890 Arg1);
11891 end if;
11892
11893 Next (S);
11894 end loop;
11895
11896 Set_Is_Asynchronous (Nm);
11897 end Process_Async_Pragma;
11898
11899 -- Start of processing for pragma Asynchronous
11900
11901 begin
11902 Check_Ada_83_Warning;
11903 Check_No_Identifiers;
11904 Check_Arg_Count (1);
11905 Check_Arg_Is_Local_Name (Arg1);
11906
11907 if Debug_Flag_U then
11908 return;
11909 end if;
11910
11911 C_Ent := Cunit_Entity (Current_Sem_Unit);
11912 Analyze (Get_Pragma_Arg (Arg1));
11913 Nm := Entity (Get_Pragma_Arg (Arg1));
11914
11915 -- A pragma that applies to a Ghost entity becomes Ghost for the
11916 -- purposes of legality checks and removal of ignored Ghost code.
11917
11918 Mark_Pragma_As_Ghost (N, Nm);
11919
11920 if not Is_Remote_Call_Interface (C_Ent)
11921 and then not Is_Remote_Types (C_Ent)
11922 then
11923 -- This pragma should only appear in an RCI or Remote Types
11924 -- unit (RM E.4.1(4)).
11925
11926 Error_Pragma
11927 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11928 end if;
11929
11930 if Ekind (Nm) = E_Procedure
11931 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11932 then
11933 if not Is_Remote_Call_Interface (Nm) then
11934 Error_Pragma_Arg
11935 ("pragma% cannot be applied on non-remote procedure",
11936 Arg1);
11937 end if;
11938
11939 L := Parameter_Specifications (Parent (Nm));
11940 Process_Async_Pragma;
11941 return;
11942
11943 elsif Ekind (Nm) = E_Function then
11944 Error_Pragma_Arg
11945 ("pragma% cannot be applied to function", Arg1);
11946
11947 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11948 if Is_Record_Type (Nm) then
11949
11950 -- A record type that is the Equivalent_Type for a remote
11951 -- access-to-subprogram type.
11952
11953 Decl := Declaration_Node (Corresponding_Remote_Type (Nm));
11954
11955 else
11956 -- A non-expanded RAS type (distribution is not enabled)
11957
11958 Decl := Declaration_Node (Nm);
11959 end if;
11960
11961 if Nkind (Decl) = N_Full_Type_Declaration
11962 and then Nkind (Type_Definition (Decl)) =
11963 N_Access_Procedure_Definition
11964 then
11965 L := Parameter_Specifications (Type_Definition (Decl));
11966 Process_Async_Pragma;
11967
11968 if Is_Asynchronous (Nm)
11969 and then Expander_Active
11970 and then Get_PCS_Name /= Name_No_DSA
11971 then
11972 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11973 end if;
11974
11975 else
11976 Error_Pragma_Arg
11977 ("pragma% cannot reference access-to-function type",
11978 Arg1);
11979 end if;
11980
11981 -- Only other possibility is Access-to-class-wide type
11982
11983 elsif Is_Access_Type (Nm)
11984 and then Is_Class_Wide_Type (Designated_Type (Nm))
11985 then
11986 Check_First_Subtype (Arg1);
11987 Set_Is_Asynchronous (Nm);
11988 if Expander_Active then
11989 RACW_Type_Is_Asynchronous (Nm);
11990 end if;
11991
11992 else
11993 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11994 end if;
11995 end Asynchronous;
11996
11997 ------------
11998 -- Atomic --
11999 ------------
12000
12001 -- pragma Atomic (LOCAL_NAME);
12002
12003 when Pragma_Atomic =>
12004 Process_Atomic_Independent_Shared_Volatile;
12005
12006 -----------------------
12007 -- Atomic_Components --
12008 -----------------------
12009
12010 -- pragma Atomic_Components (array_LOCAL_NAME);
12011
12012 -- This processing is shared by Volatile_Components
12013
12014 when Pragma_Atomic_Components |
12015 Pragma_Volatile_Components =>
12016 Atomic_Components : declare
12017 D : Node_Id;
12018 E : Entity_Id;
12019 E_Id : Node_Id;
12020 K : Node_Kind;
12021
12022 begin
12023 Check_Ada_83_Warning;
12024 Check_No_Identifiers;
12025 Check_Arg_Count (1);
12026 Check_Arg_Is_Local_Name (Arg1);
12027 E_Id := Get_Pragma_Arg (Arg1);
12028
12029 if Etype (E_Id) = Any_Type then
12030 return;
12031 end if;
12032
12033 E := Entity (E_Id);
12034
12035 -- A pragma that applies to a Ghost entity becomes Ghost for the
12036 -- purposes of legality checks and removal of ignored Ghost code.
12037
12038 Mark_Pragma_As_Ghost (N, E);
12039 Check_Duplicate_Pragma (E);
12040
12041 if Rep_Item_Too_Early (E, N)
12042 or else
12043 Rep_Item_Too_Late (E, N)
12044 then
12045 return;
12046 end if;
12047
12048 D := Declaration_Node (E);
12049 K := Nkind (D);
12050
12051 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
12052 or else
12053 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12054 and then Nkind (D) = N_Object_Declaration
12055 and then Nkind (Object_Definition (D)) =
12056 N_Constrained_Array_Definition)
12057 then
12058 -- The flag is set on the object, or on the base type
12059
12060 if Nkind (D) /= N_Object_Declaration then
12061 E := Base_Type (E);
12062 end if;
12063
12064 -- Atomic implies both Independent and Volatile
12065
12066 if Prag_Id = Pragma_Atomic_Components then
12067 Set_Has_Atomic_Components (E);
12068 Set_Has_Independent_Components (E);
12069 end if;
12070
12071 Set_Has_Volatile_Components (E);
12072
12073 else
12074 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12075 end if;
12076 end Atomic_Components;
12077
12078 --------------------
12079 -- Attach_Handler --
12080 --------------------
12081
12082 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
12083
12084 when Pragma_Attach_Handler =>
12085 Check_Ada_83_Warning;
12086 Check_No_Identifiers;
12087 Check_Arg_Count (2);
12088
12089 if No_Run_Time_Mode then
12090 Error_Msg_CRT ("Attach_Handler pragma", N);
12091 else
12092 Check_Interrupt_Or_Attach_Handler;
12093
12094 -- The expression that designates the attribute may depend on a
12095 -- discriminant, and is therefore a per-object expression, to
12096 -- be expanded in the init proc. If expansion is enabled, then
12097 -- perform semantic checks on a copy only.
12098
12099 declare
12100 Temp : Node_Id;
12101 Typ : Node_Id;
12102 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
12103
12104 begin
12105 -- In Relaxed_RM_Semantics mode, we allow any static
12106 -- integer value, for compatibility with other compilers.
12107
12108 if Relaxed_RM_Semantics
12109 and then Nkind (Parg2) = N_Integer_Literal
12110 then
12111 Typ := Standard_Integer;
12112 else
12113 Typ := RTE (RE_Interrupt_ID);
12114 end if;
12115
12116 if Expander_Active then
12117 Temp := New_Copy_Tree (Parg2);
12118 Set_Parent (Temp, N);
12119 Preanalyze_And_Resolve (Temp, Typ);
12120 else
12121 Analyze (Parg2);
12122 Resolve (Parg2, Typ);
12123 end if;
12124 end;
12125
12126 Process_Interrupt_Or_Attach_Handler;
12127 end if;
12128
12129 --------------------
12130 -- C_Pass_By_Copy --
12131 --------------------
12132
12133 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
12134
12135 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
12136 Arg : Node_Id;
12137 Val : Uint;
12138
12139 begin
12140 GNAT_Pragma;
12141 Check_Valid_Configuration_Pragma;
12142 Check_Arg_Count (1);
12143 Check_Optional_Identifier (Arg1, "max_size");
12144
12145 Arg := Get_Pragma_Arg (Arg1);
12146 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
12147
12148 Val := Expr_Value (Arg);
12149
12150 if Val <= 0 then
12151 Error_Pragma_Arg
12152 ("maximum size for pragma% must be positive", Arg1);
12153
12154 elsif UI_Is_In_Int_Range (Val) then
12155 Default_C_Record_Mechanism := UI_To_Int (Val);
12156
12157 -- If a giant value is given, Int'Last will do well enough.
12158 -- If sometime someone complains that a record larger than
12159 -- two gigabytes is not copied, we will worry about it then.
12160
12161 else
12162 Default_C_Record_Mechanism := Mechanism_Type'Last;
12163 end if;
12164 end C_Pass_By_Copy;
12165
12166 -----------
12167 -- Check --
12168 -----------
12169
12170 -- pragma Check ([Name =>] CHECK_KIND,
12171 -- [Check =>] Boolean_EXPRESSION
12172 -- [,[Message =>] String_EXPRESSION]);
12173
12174 -- CHECK_KIND ::= IDENTIFIER |
12175 -- Pre'Class |
12176 -- Post'Class |
12177 -- Invariant'Class |
12178 -- Type_Invariant'Class
12179
12180 -- The identifiers Assertions and Statement_Assertions are not
12181 -- allowed, since they have special meaning for Check_Policy.
12182
12183 when Pragma_Check => Check : declare
12184 Cname : Name_Id;
12185 Eloc : Source_Ptr;
12186 Expr : Node_Id;
12187 Str : Node_Id;
12188
12189 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
12190
12191 begin
12192 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12193 -- the mode now to ensure that any nodes generated during analysis
12194 -- and expansion are marked as Ghost.
12195
12196 Set_Ghost_Mode (N);
12197
12198 GNAT_Pragma;
12199 Check_At_Least_N_Arguments (2);
12200 Check_At_Most_N_Arguments (3);
12201 Check_Optional_Identifier (Arg1, Name_Name);
12202 Check_Optional_Identifier (Arg2, Name_Check);
12203
12204 if Arg_Count = 3 then
12205 Check_Optional_Identifier (Arg3, Name_Message);
12206 Str := Get_Pragma_Arg (Arg3);
12207 end if;
12208
12209 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
12210 Check_Arg_Is_Identifier (Arg1);
12211 Cname := Chars (Get_Pragma_Arg (Arg1));
12212
12213 -- Check forbidden name Assertions or Statement_Assertions
12214
12215 case Cname is
12216 when Name_Assertions =>
12217 Error_Pragma_Arg
12218 ("""Assertions"" is not allowed as a check kind for "
12219 & "pragma%", Arg1);
12220
12221 when Name_Statement_Assertions =>
12222 Error_Pragma_Arg
12223 ("""Statement_Assertions"" is not allowed as a check kind "
12224 & "for pragma%", Arg1);
12225
12226 when others =>
12227 null;
12228 end case;
12229
12230 -- Check applicable policy. We skip this if Checked/Ignored status
12231 -- is already set (e.g. in the case of a pragma from an aspect).
12232
12233 if Is_Checked (N) or else Is_Ignored (N) then
12234 null;
12235
12236 -- For a non-source pragma that is a rewriting of another pragma,
12237 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12238
12239 elsif Is_Rewrite_Substitution (N)
12240 and then Nkind (Original_Node (N)) = N_Pragma
12241 and then Original_Node (N) /= N
12242 then
12243 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12244 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12245
12246 -- Otherwise query the applicable policy at this point
12247
12248 else
12249 case Check_Kind (Cname) is
12250 when Name_Ignore =>
12251 Set_Is_Ignored (N, True);
12252 Set_Is_Checked (N, False);
12253
12254 when Name_Check =>
12255 Set_Is_Ignored (N, False);
12256 Set_Is_Checked (N, True);
12257
12258 -- For disable, rewrite pragma as null statement and skip
12259 -- rest of the analysis of the pragma.
12260
12261 when Name_Disable =>
12262 Rewrite (N, Make_Null_Statement (Loc));
12263 Analyze (N);
12264 raise Pragma_Exit;
12265
12266 -- No other possibilities
12267
12268 when others =>
12269 raise Program_Error;
12270 end case;
12271 end if;
12272
12273 -- If check kind was not Disable, then continue pragma analysis
12274
12275 Expr := Get_Pragma_Arg (Arg2);
12276
12277 -- Deal with SCO generation
12278
12279 case Cname is
12280
12281 -- Nothing to do for predicates as the checks occur in the
12282 -- client units. The SCO for the aspect in the declaration
12283 -- unit is conservatively always enabled.
12284
12285 when Name_Predicate =>
12286 null;
12287
12288 -- Otherwise mark aspect/pragma SCO as enabled
12289
12290 when others =>
12291 if Is_Checked (N) and then not Split_PPC (N) then
12292 Set_SCO_Pragma_Enabled (Loc);
12293 end if;
12294 end case;
12295
12296 -- Deal with analyzing the string argument
12297
12298 if Arg_Count = 3 then
12299
12300 -- If checks are not on we don't want any expansion (since
12301 -- such expansion would not get properly deleted) but
12302 -- we do want to analyze (to get proper references).
12303 -- The Preanalyze_And_Resolve routine does just what we want
12304
12305 if Is_Ignored (N) then
12306 Preanalyze_And_Resolve (Str, Standard_String);
12307
12308 -- Otherwise we need a proper analysis and expansion
12309
12310 else
12311 Analyze_And_Resolve (Str, Standard_String);
12312 end if;
12313 end if;
12314
12315 -- Now you might think we could just do the same with the Boolean
12316 -- expression if checks are off (and expansion is on) and then
12317 -- rewrite the check as a null statement. This would work but we
12318 -- would lose the useful warnings about an assertion being bound
12319 -- to fail even if assertions are turned off.
12320
12321 -- So instead we wrap the boolean expression in an if statement
12322 -- that looks like:
12323
12324 -- if False and then condition then
12325 -- null;
12326 -- end if;
12327
12328 -- The reason we do this rewriting during semantic analysis rather
12329 -- than as part of normal expansion is that we cannot analyze and
12330 -- expand the code for the boolean expression directly, or it may
12331 -- cause insertion of actions that would escape the attempt to
12332 -- suppress the check code.
12333
12334 -- Note that the Sloc for the if statement corresponds to the
12335 -- argument condition, not the pragma itself. The reason for
12336 -- this is that we may generate a warning if the condition is
12337 -- False at compile time, and we do not want to delete this
12338 -- warning when we delete the if statement.
12339
12340 if Expander_Active and Is_Ignored (N) then
12341 Eloc := Sloc (Expr);
12342
12343 Rewrite (N,
12344 Make_If_Statement (Eloc,
12345 Condition =>
12346 Make_And_Then (Eloc,
12347 Left_Opnd => Make_Identifier (Eloc, Name_False),
12348 Right_Opnd => Expr),
12349 Then_Statements => New_List (
12350 Make_Null_Statement (Eloc))));
12351
12352 -- Now go ahead and analyze the if statement
12353
12354 In_Assertion_Expr := In_Assertion_Expr + 1;
12355
12356 -- One rather special treatment. If we are now in Eliminated
12357 -- overflow mode, then suppress overflow checking since we do
12358 -- not want to drag in the bignum stuff if we are in Ignore
12359 -- mode anyway. This is particularly important if we are using
12360 -- a configurable run time that does not support bignum ops.
12361
12362 if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then
12363 declare
12364 Svo : constant Boolean :=
12365 Scope_Suppress.Suppress (Overflow_Check);
12366 begin
12367 Scope_Suppress.Overflow_Mode_Assertions := Strict;
12368 Scope_Suppress.Suppress (Overflow_Check) := True;
12369 Analyze (N);
12370 Scope_Suppress.Suppress (Overflow_Check) := Svo;
12371 Scope_Suppress.Overflow_Mode_Assertions := Eliminated;
12372 end;
12373
12374 -- Not that special case
12375
12376 else
12377 Analyze (N);
12378 end if;
12379
12380 -- All done with this check
12381
12382 In_Assertion_Expr := In_Assertion_Expr - 1;
12383
12384 -- Check is active or expansion not active. In these cases we can
12385 -- just go ahead and analyze the boolean with no worries.
12386
12387 else
12388 In_Assertion_Expr := In_Assertion_Expr + 1;
12389 Analyze_And_Resolve (Expr, Any_Boolean);
12390 In_Assertion_Expr := In_Assertion_Expr - 1;
12391 end if;
12392
12393 Ghost_Mode := Save_Ghost_Mode;
12394 end Check;
12395
12396 --------------------------
12397 -- Check_Float_Overflow --
12398 --------------------------
12399
12400 -- pragma Check_Float_Overflow;
12401
12402 when Pragma_Check_Float_Overflow =>
12403 GNAT_Pragma;
12404 Check_Valid_Configuration_Pragma;
12405 Check_Arg_Count (0);
12406 Check_Float_Overflow := not Machine_Overflows_On_Target;
12407
12408 ----------------
12409 -- Check_Name --
12410 ----------------
12411
12412 -- pragma Check_Name (check_IDENTIFIER);
12413
12414 when Pragma_Check_Name =>
12415 GNAT_Pragma;
12416 Check_No_Identifiers;
12417 Check_Valid_Configuration_Pragma;
12418 Check_Arg_Count (1);
12419 Check_Arg_Is_Identifier (Arg1);
12420
12421 declare
12422 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12423
12424 begin
12425 for J in Check_Names.First .. Check_Names.Last loop
12426 if Check_Names.Table (J) = Nam then
12427 return;
12428 end if;
12429 end loop;
12430
12431 Check_Names.Append (Nam);
12432 end;
12433
12434 ------------------
12435 -- Check_Policy --
12436 ------------------
12437
12438 -- This is the old style syntax, which is still allowed in all modes:
12439
12440 -- pragma Check_Policy ([Name =>] CHECK_KIND
12441 -- [Policy =>] POLICY_IDENTIFIER);
12442
12443 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12444
12445 -- CHECK_KIND ::= IDENTIFIER |
12446 -- Pre'Class |
12447 -- Post'Class |
12448 -- Type_Invariant'Class |
12449 -- Invariant'Class
12450
12451 -- This is the new style syntax, compatible with Assertion_Policy
12452 -- and also allowed in all modes.
12453
12454 -- Pragma Check_Policy (
12455 -- CHECK_KIND => POLICY_IDENTIFIER
12456 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12457
12458 -- Note: the identifiers Name and Policy are not allowed as
12459 -- Check_Kind values. This avoids ambiguities between the old and
12460 -- new form syntax.
12461
12462 when Pragma_Check_Policy => Check_Policy : declare
12463 Kind : Node_Id;
12464
12465 begin
12466 GNAT_Pragma;
12467 Check_At_Least_N_Arguments (1);
12468
12469 -- A Check_Policy pragma can appear either as a configuration
12470 -- pragma, or in a declarative part or a package spec (see RM
12471 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12472 -- followed for Check_Policy).
12473
12474 if not Is_Configuration_Pragma then
12475 Check_Is_In_Decl_Part_Or_Package_Spec;
12476 end if;
12477
12478 -- Figure out if we have the old or new syntax. We have the
12479 -- old syntax if the first argument has no identifier, or the
12480 -- identifier is Name.
12481
12482 if Nkind (Arg1) /= N_Pragma_Argument_Association
12483 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
12484 then
12485 -- Old syntax
12486
12487 Check_Arg_Count (2);
12488 Check_Optional_Identifier (Arg1, Name_Name);
12489 Kind := Get_Pragma_Arg (Arg1);
12490 Rewrite_Assertion_Kind (Kind);
12491 Check_Arg_Is_Identifier (Arg1);
12492
12493 -- Check forbidden check kind
12494
12495 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
12496 Error_Msg_Name_2 := Chars (Kind);
12497 Error_Pragma_Arg
12498 ("pragma% does not allow% as check name", Arg1);
12499 end if;
12500
12501 -- Check policy
12502
12503 Check_Optional_Identifier (Arg2, Name_Policy);
12504 Check_Arg_Is_One_Of
12505 (Arg2,
12506 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
12507
12508 -- And chain pragma on the Check_Policy_List for search
12509
12510 Set_Next_Pragma (N, Opt.Check_Policy_List);
12511 Opt.Check_Policy_List := N;
12512
12513 -- For the new syntax, what we do is to convert each argument to
12514 -- an old syntax equivalent. We do that because we want to chain
12515 -- old style Check_Policy pragmas for the search (we don't want
12516 -- to have to deal with multiple arguments in the search).
12517
12518 else
12519 declare
12520 Arg : Node_Id;
12521 Argx : Node_Id;
12522 LocP : Source_Ptr;
12523 New_P : Node_Id;
12524
12525 begin
12526 Arg := Arg1;
12527 while Present (Arg) loop
12528 LocP := Sloc (Arg);
12529 Argx := Get_Pragma_Arg (Arg);
12530
12531 -- Kind must be specified
12532
12533 if Nkind (Arg) /= N_Pragma_Argument_Association
12534 or else Chars (Arg) = No_Name
12535 then
12536 Error_Pragma_Arg
12537 ("missing assertion kind for pragma%", Arg);
12538 end if;
12539
12540 -- Construct equivalent old form syntax Check_Policy
12541 -- pragma and insert it to get remaining checks.
12542
12543 New_P :=
12544 Make_Pragma (LocP,
12545 Chars => Name_Check_Policy,
12546 Pragma_Argument_Associations => New_List (
12547 Make_Pragma_Argument_Association (LocP,
12548 Expression =>
12549 Make_Identifier (LocP, Chars (Arg))),
12550 Make_Pragma_Argument_Association (Sloc (Argx),
12551 Expression => Argx)));
12552
12553 Arg := Next (Arg);
12554
12555 -- For a configuration pragma, insert old form in
12556 -- the corresponding file.
12557
12558 if Is_Configuration_Pragma then
12559 Insert_After (N, New_P);
12560 Analyze (New_P);
12561
12562 else
12563 Insert_Action (N, New_P);
12564 end if;
12565 end loop;
12566
12567 -- Rewrite original Check_Policy pragma to null, since we
12568 -- have converted it into a series of old syntax pragmas.
12569
12570 Rewrite (N, Make_Null_Statement (Loc));
12571 Analyze (N);
12572 end;
12573 end if;
12574 end Check_Policy;
12575
12576 -------------
12577 -- Comment --
12578 -------------
12579
12580 -- pragma Comment (static_string_EXPRESSION)
12581
12582 -- Processing for pragma Comment shares the circuitry for pragma
12583 -- Ident. The only differences are that Ident enforces a limit of 31
12584 -- characters on its argument, and also enforces limitations on
12585 -- placement for DEC compatibility. Pragma Comment shares neither of
12586 -- these restrictions.
12587
12588 -------------------
12589 -- Common_Object --
12590 -------------------
12591
12592 -- pragma Common_Object (
12593 -- [Internal =>] LOCAL_NAME
12594 -- [, [External =>] EXTERNAL_SYMBOL]
12595 -- [, [Size =>] EXTERNAL_SYMBOL]);
12596
12597 -- Processing for this pragma is shared with Psect_Object
12598
12599 ------------------------
12600 -- Compile_Time_Error --
12601 ------------------------
12602
12603 -- pragma Compile_Time_Error
12604 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12605
12606 when Pragma_Compile_Time_Error =>
12607 GNAT_Pragma;
12608 Process_Compile_Time_Warning_Or_Error;
12609
12610 --------------------------
12611 -- Compile_Time_Warning --
12612 --------------------------
12613
12614 -- pragma Compile_Time_Warning
12615 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12616
12617 when Pragma_Compile_Time_Warning =>
12618 GNAT_Pragma;
12619 Process_Compile_Time_Warning_Or_Error;
12620
12621 ---------------------------
12622 -- Compiler_Unit_Warning --
12623 ---------------------------
12624
12625 -- pragma Compiler_Unit_Warning;
12626
12627 -- Historical note
12628
12629 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12630 -- errors not warnings. This means that we had introduced a big extra
12631 -- inertia to compiler changes, since even if we implemented a new
12632 -- feature, and even if all versions to be used for bootstrapping
12633 -- implemented this new feature, we could not use it, since old
12634 -- compilers would give errors for using this feature in units
12635 -- having Compiler_Unit pragmas.
12636
12637 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12638 -- problem. We no longer have any units mentioning Compiler_Unit,
12639 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12640 -- and thus generates a warning which can be ignored. So that deals
12641 -- with the problem of old compilers not implementing the newer form
12642 -- of the pragma.
12643
12644 -- Newer compilers recognize the new pragma, but generate warning
12645 -- messages instead of errors, which again can be ignored in the
12646 -- case of an old compiler which implements a wanted new feature
12647 -- but at the time felt like warning about it for older compilers.
12648
12649 -- We retain Compiler_Unit so that new compilers can be used to build
12650 -- older run-times that use this pragma. That's an unusual case, but
12651 -- it's easy enough to handle, so why not?
12652
12653 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
12654 GNAT_Pragma;
12655 Check_Arg_Count (0);
12656
12657 -- Only recognized in main unit
12658
12659 if Current_Sem_Unit = Main_Unit then
12660 Compiler_Unit := True;
12661 end if;
12662
12663 -----------------------------
12664 -- Complete_Representation --
12665 -----------------------------
12666
12667 -- pragma Complete_Representation;
12668
12669 when Pragma_Complete_Representation =>
12670 GNAT_Pragma;
12671 Check_Arg_Count (0);
12672
12673 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
12674 Error_Pragma
12675 ("pragma & must appear within record representation clause");
12676 end if;
12677
12678 ----------------------------
12679 -- Complex_Representation --
12680 ----------------------------
12681
12682 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12683
12684 when Pragma_Complex_Representation => Complex_Representation : declare
12685 E_Id : Entity_Id;
12686 E : Entity_Id;
12687 Ent : Entity_Id;
12688
12689 begin
12690 GNAT_Pragma;
12691 Check_Arg_Count (1);
12692 Check_Optional_Identifier (Arg1, Name_Entity);
12693 Check_Arg_Is_Local_Name (Arg1);
12694 E_Id := Get_Pragma_Arg (Arg1);
12695
12696 if Etype (E_Id) = Any_Type then
12697 return;
12698 end if;
12699
12700 E := Entity (E_Id);
12701
12702 if not Is_Record_Type (E) then
12703 Error_Pragma_Arg
12704 ("argument for pragma% must be record type", Arg1);
12705 end if;
12706
12707 Ent := First_Entity (E);
12708
12709 if No (Ent)
12710 or else No (Next_Entity (Ent))
12711 or else Present (Next_Entity (Next_Entity (Ent)))
12712 or else not Is_Floating_Point_Type (Etype (Ent))
12713 or else Etype (Ent) /= Etype (Next_Entity (Ent))
12714 then
12715 Error_Pragma_Arg
12716 ("record for pragma% must have two fields of the same "
12717 & "floating-point type", Arg1);
12718
12719 else
12720 Set_Has_Complex_Representation (Base_Type (E));
12721
12722 -- We need to treat the type has having a non-standard
12723 -- representation, for back-end purposes, even though in
12724 -- general a complex will have the default representation
12725 -- of a record with two real components.
12726
12727 Set_Has_Non_Standard_Rep (Base_Type (E));
12728 end if;
12729 end Complex_Representation;
12730
12731 -------------------------
12732 -- Component_Alignment --
12733 -------------------------
12734
12735 -- pragma Component_Alignment (
12736 -- [Form =>] ALIGNMENT_CHOICE
12737 -- [, [Name =>] type_LOCAL_NAME]);
12738 --
12739 -- ALIGNMENT_CHOICE ::=
12740 -- Component_Size
12741 -- | Component_Size_4
12742 -- | Storage_Unit
12743 -- | Default
12744
12745 when Pragma_Component_Alignment => Component_AlignmentP : declare
12746 Args : Args_List (1 .. 2);
12747 Names : constant Name_List (1 .. 2) := (
12748 Name_Form,
12749 Name_Name);
12750
12751 Form : Node_Id renames Args (1);
12752 Name : Node_Id renames Args (2);
12753
12754 Atype : Component_Alignment_Kind;
12755 Typ : Entity_Id;
12756
12757 begin
12758 GNAT_Pragma;
12759 Gather_Associations (Names, Args);
12760
12761 if No (Form) then
12762 Error_Pragma ("missing Form argument for pragma%");
12763 end if;
12764
12765 Check_Arg_Is_Identifier (Form);
12766
12767 -- Get proper alignment, note that Default = Component_Size on all
12768 -- machines we have so far, and we want to set this value rather
12769 -- than the default value to indicate that it has been explicitly
12770 -- set (and thus will not get overridden by the default component
12771 -- alignment for the current scope)
12772
12773 if Chars (Form) = Name_Component_Size then
12774 Atype := Calign_Component_Size;
12775
12776 elsif Chars (Form) = Name_Component_Size_4 then
12777 Atype := Calign_Component_Size_4;
12778
12779 elsif Chars (Form) = Name_Default then
12780 Atype := Calign_Component_Size;
12781
12782 elsif Chars (Form) = Name_Storage_Unit then
12783 Atype := Calign_Storage_Unit;
12784
12785 else
12786 Error_Pragma_Arg
12787 ("invalid Form parameter for pragma%", Form);
12788 end if;
12789
12790 -- Case with no name, supplied, affects scope table entry
12791
12792 if No (Name) then
12793 Scope_Stack.Table
12794 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12795
12796 -- Case of name supplied
12797
12798 else
12799 Check_Arg_Is_Local_Name (Name);
12800 Find_Type (Name);
12801 Typ := Entity (Name);
12802
12803 if Typ = Any_Type
12804 or else Rep_Item_Too_Early (Typ, N)
12805 then
12806 return;
12807 else
12808 Typ := Underlying_Type (Typ);
12809 end if;
12810
12811 if not Is_Record_Type (Typ)
12812 and then not Is_Array_Type (Typ)
12813 then
12814 Error_Pragma_Arg
12815 ("Name parameter of pragma% must identify record or "
12816 & "array type", Name);
12817 end if;
12818
12819 -- An explicit Component_Alignment pragma overrides an
12820 -- implicit pragma Pack, but not an explicit one.
12821
12822 if not Has_Pragma_Pack (Base_Type (Typ)) then
12823 Set_Is_Packed (Base_Type (Typ), False);
12824 Set_Component_Alignment (Base_Type (Typ), Atype);
12825 end if;
12826 end if;
12827 end Component_AlignmentP;
12828
12829 --------------------------------
12830 -- Constant_After_Elaboration --
12831 --------------------------------
12832
12833 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
12834
12835 when Pragma_Constant_After_Elaboration => Constant_After_Elaboration :
12836 declare
12837 Obj_Decl : Node_Id;
12838 Obj_Id : Entity_Id;
12839
12840 begin
12841 GNAT_Pragma;
12842 Check_No_Identifiers;
12843 Check_At_Most_N_Arguments (1);
12844
12845 Obj_Decl := Find_Related_Context (N, Do_Checks => True);
12846
12847 -- Object declaration
12848
12849 if Nkind (Obj_Decl) = N_Object_Declaration then
12850 null;
12851
12852 -- Otherwise the pragma is associated with an illegal construct
12853
12854 else
12855 Pragma_Misplaced;
12856 return;
12857 end if;
12858
12859 Obj_Id := Defining_Entity (Obj_Decl);
12860
12861 -- The object declaration must be a library-level variable which
12862 -- is either explicitly initialized or obtains a value during the
12863 -- elaboration of a package body (SPARK RM 3.3.1).
12864
12865 if Ekind (Obj_Id) = E_Variable then
12866 if not Is_Library_Level_Entity (Obj_Id) then
12867 Error_Pragma
12868 ("pragma % must apply to a library level variable");
12869 return;
12870 end if;
12871
12872 -- Otherwise the pragma applies to a constant, which is illegal
12873
12874 else
12875 Error_Pragma ("pragma % must apply to a variable declaration");
12876 return;
12877 end if;
12878
12879 -- Chain the pragma on the contract for completeness
12880
12881 Add_Contract_Item (N, Obj_Id);
12882
12883 -- A pragma that applies to a Ghost entity becomes Ghost for the
12884 -- purposes of legality checks and removal of ignored Ghost code.
12885
12886 Mark_Pragma_As_Ghost (N, Obj_Id);
12887
12888 -- Analyze the Boolean expression (if any)
12889
12890 if Present (Arg1) then
12891 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
12892 end if;
12893 end Constant_After_Elaboration;
12894
12895 --------------------
12896 -- Contract_Cases --
12897 --------------------
12898
12899 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12900
12901 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12902
12903 -- CASE_GUARD ::= boolean_EXPRESSION | others
12904
12905 -- CONSEQUENCE ::= boolean_EXPRESSION
12906
12907 -- Characteristics:
12908
12909 -- * Analysis - The annotation undergoes initial checks to verify
12910 -- the legal placement and context. Secondary checks preanalyze the
12911 -- expressions in:
12912
12913 -- Analyze_Contract_Cases_In_Decl_Part
12914
12915 -- * Expansion - The annotation is expanded during the expansion of
12916 -- the related subprogram [body] contract as performed in:
12917
12918 -- Expand_Subprogram_Contract
12919
12920 -- * Template - The annotation utilizes the generic template of the
12921 -- related subprogram [body] when it is:
12922
12923 -- aspect on subprogram declaration
12924 -- aspect on stand alone subprogram body
12925 -- pragma on stand alone subprogram body
12926
12927 -- The annotation must prepare its own template when it is:
12928
12929 -- pragma on subprogram declaration
12930
12931 -- * Globals - Capture of global references must occur after full
12932 -- analysis.
12933
12934 -- * Instance - The annotation is instantiated automatically when
12935 -- the related generic subprogram [body] is instantiated except for
12936 -- the "pragma on subprogram declaration" case. In that scenario
12937 -- the annotation must instantiate itself.
12938
12939 when Pragma_Contract_Cases => Contract_Cases : declare
12940 Spec_Id : Entity_Id;
12941 Subp_Decl : Node_Id;
12942
12943 begin
12944 GNAT_Pragma;
12945 Check_No_Identifiers;
12946 Check_Arg_Count (1);
12947
12948 -- Ensure the proper placement of the pragma. Contract_Cases must
12949 -- be associated with a subprogram declaration or a body that acts
12950 -- as a spec.
12951
12952 Subp_Decl :=
12953 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
12954
12955 -- Entry
12956
12957 if Nkind (Subp_Decl) = N_Entry_Declaration then
12958 null;
12959
12960 -- Generic subprogram
12961
12962 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
12963 null;
12964
12965 -- Body acts as spec
12966
12967 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12968 and then No (Corresponding_Spec (Subp_Decl))
12969 then
12970 null;
12971
12972 -- Body stub acts as spec
12973
12974 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12975 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12976 then
12977 null;
12978
12979 -- Subprogram
12980
12981 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
12982 null;
12983
12984 else
12985 Pragma_Misplaced;
12986 return;
12987 end if;
12988
12989 Spec_Id := Unique_Defining_Entity (Subp_Decl);
12990
12991 -- Chain the pragma on the contract for further processing by
12992 -- Analyze_Contract_Cases_In_Decl_Part.
12993
12994 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12995
12996 -- A pragma that applies to a Ghost entity becomes Ghost for the
12997 -- purposes of legality checks and removal of ignored Ghost code.
12998
12999 Mark_Pragma_As_Ghost (N, Spec_Id);
13000 Ensure_Aggregate_Form (Get_Argument (N, Spec_Id));
13001
13002 -- Fully analyze the pragma when it appears inside an entry
13003 -- or subprogram body because it cannot benefit from forward
13004 -- references.
13005
13006 if Nkind_In (Subp_Decl, N_Entry_Body,
13007 N_Subprogram_Body,
13008 N_Subprogram_Body_Stub)
13009 then
13010 -- The legality checks of pragma Contract_Cases are affected by
13011 -- the SPARK mode in effect and the volatility of the context.
13012 -- Analyze all pragmas in a specific order.
13013
13014 Analyze_If_Present (Pragma_SPARK_Mode);
13015 Analyze_If_Present (Pragma_Volatile_Function);
13016 Analyze_Contract_Cases_In_Decl_Part (N);
13017 end if;
13018 end Contract_Cases;
13019
13020 ----------------
13021 -- Controlled --
13022 ----------------
13023
13024 -- pragma Controlled (first_subtype_LOCAL_NAME);
13025
13026 when Pragma_Controlled => Controlled : declare
13027 Arg : Node_Id;
13028
13029 begin
13030 Check_No_Identifiers;
13031 Check_Arg_Count (1);
13032 Check_Arg_Is_Local_Name (Arg1);
13033 Arg := Get_Pragma_Arg (Arg1);
13034
13035 if not Is_Entity_Name (Arg)
13036 or else not Is_Access_Type (Entity (Arg))
13037 then
13038 Error_Pragma_Arg ("pragma% requires access type", Arg1);
13039 else
13040 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
13041 end if;
13042 end Controlled;
13043
13044 ----------------
13045 -- Convention --
13046 ----------------
13047
13048 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
13049 -- [Entity =>] LOCAL_NAME);
13050
13051 when Pragma_Convention => Convention : declare
13052 C : Convention_Id;
13053 E : Entity_Id;
13054 pragma Warnings (Off, C);
13055 pragma Warnings (Off, E);
13056 begin
13057 Check_Arg_Order ((Name_Convention, Name_Entity));
13058 Check_Ada_83_Warning;
13059 Check_Arg_Count (2);
13060 Process_Convention (C, E);
13061
13062 -- A pragma that applies to a Ghost entity becomes Ghost for the
13063 -- purposes of legality checks and removal of ignored Ghost code.
13064
13065 Mark_Pragma_As_Ghost (N, E);
13066 end Convention;
13067
13068 ---------------------------
13069 -- Convention_Identifier --
13070 ---------------------------
13071
13072 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
13073 -- [Convention =>] convention_IDENTIFIER);
13074
13075 when Pragma_Convention_Identifier => Convention_Identifier : declare
13076 Idnam : Name_Id;
13077 Cname : Name_Id;
13078
13079 begin
13080 GNAT_Pragma;
13081 Check_Arg_Order ((Name_Name, Name_Convention));
13082 Check_Arg_Count (2);
13083 Check_Optional_Identifier (Arg1, Name_Name);
13084 Check_Optional_Identifier (Arg2, Name_Convention);
13085 Check_Arg_Is_Identifier (Arg1);
13086 Check_Arg_Is_Identifier (Arg2);
13087 Idnam := Chars (Get_Pragma_Arg (Arg1));
13088 Cname := Chars (Get_Pragma_Arg (Arg2));
13089
13090 if Is_Convention_Name (Cname) then
13091 Record_Convention_Identifier
13092 (Idnam, Get_Convention_Id (Cname));
13093 else
13094 Error_Pragma_Arg
13095 ("second arg for % pragma must be convention", Arg2);
13096 end if;
13097 end Convention_Identifier;
13098
13099 ---------------
13100 -- CPP_Class --
13101 ---------------
13102
13103 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
13104
13105 when Pragma_CPP_Class => CPP_Class : declare
13106 begin
13107 GNAT_Pragma;
13108
13109 if Warn_On_Obsolescent_Feature then
13110 Error_Msg_N
13111 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
13112 & "effect; replace it by pragma import?j?", N);
13113 end if;
13114
13115 Check_Arg_Count (1);
13116
13117 Rewrite (N,
13118 Make_Pragma (Loc,
13119 Chars => Name_Import,
13120 Pragma_Argument_Associations => New_List (
13121 Make_Pragma_Argument_Association (Loc,
13122 Expression => Make_Identifier (Loc, Name_CPP)),
13123 New_Copy (First (Pragma_Argument_Associations (N))))));
13124 Analyze (N);
13125 end CPP_Class;
13126
13127 ---------------------
13128 -- CPP_Constructor --
13129 ---------------------
13130
13131 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
13132 -- [, [External_Name =>] static_string_EXPRESSION ]
13133 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13134
13135 when Pragma_CPP_Constructor => CPP_Constructor : declare
13136 Elmt : Elmt_Id;
13137 Id : Entity_Id;
13138 Def_Id : Entity_Id;
13139 Tag_Typ : Entity_Id;
13140
13141 begin
13142 GNAT_Pragma;
13143 Check_At_Least_N_Arguments (1);
13144 Check_At_Most_N_Arguments (3);
13145 Check_Optional_Identifier (Arg1, Name_Entity);
13146 Check_Arg_Is_Local_Name (Arg1);
13147
13148 Id := Get_Pragma_Arg (Arg1);
13149 Find_Program_Unit_Name (Id);
13150
13151 -- If we did not find the name, we are done
13152
13153 if Etype (Id) = Any_Type then
13154 return;
13155 end if;
13156
13157 Def_Id := Entity (Id);
13158
13159 -- Check if already defined as constructor
13160
13161 if Is_Constructor (Def_Id) then
13162 Error_Msg_N
13163 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
13164 return;
13165 end if;
13166
13167 if Ekind (Def_Id) = E_Function
13168 and then (Is_CPP_Class (Etype (Def_Id))
13169 or else (Is_Class_Wide_Type (Etype (Def_Id))
13170 and then
13171 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
13172 then
13173 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
13174 Error_Msg_N
13175 ("'C'P'P constructor must be defined in the scope of "
13176 & "its returned type", Arg1);
13177 end if;
13178
13179 if Arg_Count >= 2 then
13180 Set_Imported (Def_Id);
13181 Set_Is_Public (Def_Id);
13182 Process_Interface_Name (Def_Id, Arg2, Arg3);
13183 end if;
13184
13185 Set_Has_Completion (Def_Id);
13186 Set_Is_Constructor (Def_Id);
13187 Set_Convention (Def_Id, Convention_CPP);
13188
13189 -- Imported C++ constructors are not dispatching primitives
13190 -- because in C++ they don't have a dispatch table slot.
13191 -- However, in Ada the constructor has the profile of a
13192 -- function that returns a tagged type and therefore it has
13193 -- been treated as a primitive operation during semantic
13194 -- analysis. We now remove it from the list of primitive
13195 -- operations of the type.
13196
13197 if Is_Tagged_Type (Etype (Def_Id))
13198 and then not Is_Class_Wide_Type (Etype (Def_Id))
13199 and then Is_Dispatching_Operation (Def_Id)
13200 then
13201 Tag_Typ := Etype (Def_Id);
13202
13203 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
13204 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
13205 Next_Elmt (Elmt);
13206 end loop;
13207
13208 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
13209 Set_Is_Dispatching_Operation (Def_Id, False);
13210 end if;
13211
13212 -- For backward compatibility, if the constructor returns a
13213 -- class wide type, and we internally change the return type to
13214 -- the corresponding root type.
13215
13216 if Is_Class_Wide_Type (Etype (Def_Id)) then
13217 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
13218 end if;
13219 else
13220 Error_Pragma_Arg
13221 ("pragma% requires function returning a 'C'P'P_Class type",
13222 Arg1);
13223 end if;
13224 end CPP_Constructor;
13225
13226 -----------------
13227 -- CPP_Virtual --
13228 -----------------
13229
13230 when Pragma_CPP_Virtual => CPP_Virtual : declare
13231 begin
13232 GNAT_Pragma;
13233
13234 if Warn_On_Obsolescent_Feature then
13235 Error_Msg_N
13236 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13237 & "effect?j?", N);
13238 end if;
13239 end CPP_Virtual;
13240
13241 ----------------
13242 -- CPP_Vtable --
13243 ----------------
13244
13245 when Pragma_CPP_Vtable => CPP_Vtable : declare
13246 begin
13247 GNAT_Pragma;
13248
13249 if Warn_On_Obsolescent_Feature then
13250 Error_Msg_N
13251 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13252 & "effect?j?", N);
13253 end if;
13254 end CPP_Vtable;
13255
13256 ---------
13257 -- CPU --
13258 ---------
13259
13260 -- pragma CPU (EXPRESSION);
13261
13262 when Pragma_CPU => CPU : declare
13263 P : constant Node_Id := Parent (N);
13264 Arg : Node_Id;
13265 Ent : Entity_Id;
13266
13267 begin
13268 Ada_2012_Pragma;
13269 Check_No_Identifiers;
13270 Check_Arg_Count (1);
13271
13272 -- Subprogram case
13273
13274 if Nkind (P) = N_Subprogram_Body then
13275 Check_In_Main_Program;
13276
13277 Arg := Get_Pragma_Arg (Arg1);
13278 Analyze_And_Resolve (Arg, Any_Integer);
13279
13280 Ent := Defining_Unit_Name (Specification (P));
13281
13282 if Nkind (Ent) = N_Defining_Program_Unit_Name then
13283 Ent := Defining_Identifier (Ent);
13284 end if;
13285
13286 -- Must be static
13287
13288 if not Is_OK_Static_Expression (Arg) then
13289 Flag_Non_Static_Expr
13290 ("main subprogram affinity is not static!", Arg);
13291 raise Pragma_Exit;
13292
13293 -- If constraint error, then we already signalled an error
13294
13295 elsif Raises_Constraint_Error (Arg) then
13296 null;
13297
13298 -- Otherwise check in range
13299
13300 else
13301 declare
13302 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
13303 -- This is the entity System.Multiprocessors.CPU_Range;
13304
13305 Val : constant Uint := Expr_Value (Arg);
13306
13307 begin
13308 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
13309 or else
13310 Val > Expr_Value (Type_High_Bound (CPU_Id))
13311 then
13312 Error_Pragma_Arg
13313 ("main subprogram CPU is out of range", Arg1);
13314 end if;
13315 end;
13316 end if;
13317
13318 Set_Main_CPU
13319 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
13320
13321 -- Task case
13322
13323 elsif Nkind (P) = N_Task_Definition then
13324 Arg := Get_Pragma_Arg (Arg1);
13325 Ent := Defining_Identifier (Parent (P));
13326
13327 -- The expression must be analyzed in the special manner
13328 -- described in "Handling of Default and Per-Object
13329 -- Expressions" in sem.ads.
13330
13331 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
13332
13333 -- Anything else is incorrect
13334
13335 else
13336 Pragma_Misplaced;
13337 end if;
13338
13339 -- Check duplicate pragma before we chain the pragma in the Rep
13340 -- Item chain of Ent.
13341
13342 Check_Duplicate_Pragma (Ent);
13343 Record_Rep_Item (Ent, N);
13344 end CPU;
13345
13346 -----------
13347 -- Debug --
13348 -----------
13349
13350 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13351
13352 when Pragma_Debug => Debug : declare
13353 Cond : Node_Id;
13354 Call : Node_Id;
13355
13356 begin
13357 GNAT_Pragma;
13358
13359 -- The condition for executing the call is that the expander
13360 -- is active and that we are not ignoring this debug pragma.
13361
13362 Cond :=
13363 New_Occurrence_Of
13364 (Boolean_Literals
13365 (Expander_Active and then not Is_Ignored (N)),
13366 Loc);
13367
13368 if not Is_Ignored (N) then
13369 Set_SCO_Pragma_Enabled (Loc);
13370 end if;
13371
13372 if Arg_Count = 2 then
13373 Cond :=
13374 Make_And_Then (Loc,
13375 Left_Opnd => Relocate_Node (Cond),
13376 Right_Opnd => Get_Pragma_Arg (Arg1));
13377 Call := Get_Pragma_Arg (Arg2);
13378 else
13379 Call := Get_Pragma_Arg (Arg1);
13380 end if;
13381
13382 if Nkind_In (Call,
13383 N_Indexed_Component,
13384 N_Function_Call,
13385 N_Identifier,
13386 N_Expanded_Name,
13387 N_Selected_Component)
13388 then
13389 -- If this pragma Debug comes from source, its argument was
13390 -- parsed as a name form (which is syntactically identical).
13391 -- In a generic context a parameterless call will be left as
13392 -- an expanded name (if global) or selected_component if local.
13393 -- Change it to a procedure call statement now.
13394
13395 Change_Name_To_Procedure_Call_Statement (Call);
13396
13397 elsif Nkind (Call) = N_Procedure_Call_Statement then
13398
13399 -- Already in the form of a procedure call statement: nothing
13400 -- to do (could happen in case of an internally generated
13401 -- pragma Debug).
13402
13403 null;
13404
13405 else
13406 -- All other cases: diagnose error
13407
13408 Error_Msg
13409 ("argument of pragma ""Debug"" is not procedure call",
13410 Sloc (Call));
13411 return;
13412 end if;
13413
13414 -- Rewrite into a conditional with an appropriate condition. We
13415 -- wrap the procedure call in a block so that overhead from e.g.
13416 -- use of the secondary stack does not generate execution overhead
13417 -- for suppressed conditions.
13418
13419 -- Normally the analysis that follows will freeze the subprogram
13420 -- being called. However, if the call is to a null procedure,
13421 -- we want to freeze it before creating the block, because the
13422 -- analysis that follows may be done with expansion disabled, in
13423 -- which case the body will not be generated, leading to spurious
13424 -- errors.
13425
13426 if Nkind (Call) = N_Procedure_Call_Statement
13427 and then Is_Entity_Name (Name (Call))
13428 then
13429 Analyze (Name (Call));
13430 Freeze_Before (N, Entity (Name (Call)));
13431 end if;
13432
13433 Rewrite (N,
13434 Make_Implicit_If_Statement (N,
13435 Condition => Cond,
13436 Then_Statements => New_List (
13437 Make_Block_Statement (Loc,
13438 Handled_Statement_Sequence =>
13439 Make_Handled_Sequence_Of_Statements (Loc,
13440 Statements => New_List (Relocate_Node (Call)))))));
13441 Analyze (N);
13442
13443 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13444 -- after analysis of the normally rewritten node, to capture all
13445 -- references to entities, which avoids issuing wrong warnings
13446 -- about unused entities.
13447
13448 if GNATprove_Mode then
13449 Rewrite (N, Make_Null_Statement (Loc));
13450 end if;
13451 end Debug;
13452
13453 ------------------
13454 -- Debug_Policy --
13455 ------------------
13456
13457 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13458
13459 when Pragma_Debug_Policy =>
13460 GNAT_Pragma;
13461 Check_Arg_Count (1);
13462 Check_No_Identifiers;
13463 Check_Arg_Is_Identifier (Arg1);
13464
13465 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13466 -- rewrite it that way, and let the rest of the checking come
13467 -- from analyzing the rewritten pragma.
13468
13469 Rewrite (N,
13470 Make_Pragma (Loc,
13471 Chars => Name_Check_Policy,
13472 Pragma_Argument_Associations => New_List (
13473 Make_Pragma_Argument_Association (Loc,
13474 Expression => Make_Identifier (Loc, Name_Debug)),
13475
13476 Make_Pragma_Argument_Association (Loc,
13477 Expression => Get_Pragma_Arg (Arg1)))));
13478 Analyze (N);
13479
13480 -------------------------------
13481 -- Default_Initial_Condition --
13482 -------------------------------
13483
13484 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
13485
13486 when Pragma_Default_Initial_Condition => Default_Init_Cond : declare
13487 Discard : Boolean;
13488 Stmt : Node_Id;
13489 Typ : Entity_Id;
13490
13491 begin
13492 GNAT_Pragma;
13493 Check_No_Identifiers;
13494 Check_At_Most_N_Arguments (1);
13495
13496 Stmt := Prev (N);
13497 while Present (Stmt) loop
13498
13499 -- Skip prior pragmas, but check for duplicates
13500
13501 if Nkind (Stmt) = N_Pragma then
13502 if Pragma_Name (Stmt) = Pname then
13503 Error_Msg_Name_1 := Pname;
13504 Error_Msg_Sloc := Sloc (Stmt);
13505 Error_Msg_N ("pragma % duplicates pragma declared#", N);
13506 end if;
13507
13508 -- Skip internally generated code
13509
13510 elsif not Comes_From_Source (Stmt) then
13511 null;
13512
13513 -- The associated private type [extension] has been found, stop
13514 -- the search.
13515
13516 elsif Nkind_In (Stmt, N_Private_Extension_Declaration,
13517 N_Private_Type_Declaration)
13518 then
13519 Typ := Defining_Entity (Stmt);
13520 exit;
13521
13522 -- The pragma does not apply to a legal construct, issue an
13523 -- error and stop the analysis.
13524
13525 else
13526 Pragma_Misplaced;
13527 return;
13528 end if;
13529
13530 Stmt := Prev (Stmt);
13531 end loop;
13532
13533 -- A pragma that applies to a Ghost entity becomes Ghost for the
13534 -- purposes of legality checks and removal of ignored Ghost code.
13535
13536 Mark_Pragma_As_Ghost (N, Typ);
13537 Set_Has_Default_Init_Cond (Typ);
13538 Set_Has_Inherited_Default_Init_Cond (Typ, False);
13539
13540 -- Chain the pragma on the rep item chain for further processing
13541
13542 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13543 end Default_Init_Cond;
13544
13545 ----------------------------------
13546 -- Default_Scalar_Storage_Order --
13547 ----------------------------------
13548
13549 -- pragma Default_Scalar_Storage_Order
13550 -- (High_Order_First | Low_Order_First);
13551
13552 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
13553 Default : Character;
13554
13555 begin
13556 GNAT_Pragma;
13557 Check_Arg_Count (1);
13558
13559 -- Default_Scalar_Storage_Order can appear as a configuration
13560 -- pragma, or in a declarative part of a package spec.
13561
13562 if not Is_Configuration_Pragma then
13563 Check_Is_In_Decl_Part_Or_Package_Spec;
13564 end if;
13565
13566 Check_No_Identifiers;
13567 Check_Arg_Is_One_Of
13568 (Arg1, Name_High_Order_First, Name_Low_Order_First);
13569 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13570 Default := Fold_Upper (Name_Buffer (1));
13571
13572 if not Support_Nondefault_SSO_On_Target
13573 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
13574 then
13575 if Warn_On_Unrecognized_Pragma then
13576 Error_Msg_N
13577 ("non-default Scalar_Storage_Order not supported "
13578 & "on target?g?", N);
13579 Error_Msg_N
13580 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
13581 end if;
13582
13583 -- Here set the specified default
13584
13585 else
13586 Opt.Default_SSO := Default;
13587 end if;
13588 end DSSO;
13589
13590 --------------------------
13591 -- Default_Storage_Pool --
13592 --------------------------
13593
13594 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13595
13596 when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare
13597 Pool : Node_Id;
13598
13599 begin
13600 Ada_2012_Pragma;
13601 Check_Arg_Count (1);
13602
13603 -- Default_Storage_Pool can appear as a configuration pragma, or
13604 -- in a declarative part of a package spec.
13605
13606 if not Is_Configuration_Pragma then
13607 Check_Is_In_Decl_Part_Or_Package_Spec;
13608 end if;
13609
13610 if From_Aspect_Specification (N) then
13611 declare
13612 E : constant Entity_Id := Entity (Corresponding_Aspect (N));
13613 begin
13614 if not In_Open_Scopes (E) then
13615 Error_Msg_N
13616 ("aspect must apply to package or subprogram", N);
13617 end if;
13618 end;
13619 end if;
13620
13621 if Present (Arg1) then
13622 Pool := Get_Pragma_Arg (Arg1);
13623
13624 -- Case of Default_Storage_Pool (null);
13625
13626 if Nkind (Pool) = N_Null then
13627 Analyze (Pool);
13628
13629 -- This is an odd case, this is not really an expression,
13630 -- so we don't have a type for it. So just set the type to
13631 -- Empty.
13632
13633 Set_Etype (Pool, Empty);
13634
13635 -- Case of Default_Storage_Pool (storage_pool_NAME);
13636
13637 else
13638 -- If it's a configuration pragma, then the only allowed
13639 -- argument is "null".
13640
13641 if Is_Configuration_Pragma then
13642 Error_Pragma_Arg ("NULL expected", Arg1);
13643 end if;
13644
13645 -- The expected type for a non-"null" argument is
13646 -- Root_Storage_Pool'Class, and the pool must be a variable.
13647
13648 Analyze_And_Resolve
13649 (Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
13650
13651 if Is_Variable (Pool) then
13652
13653 -- A pragma that applies to a Ghost entity becomes Ghost
13654 -- for the purposes of legality checks and removal of
13655 -- ignored Ghost code.
13656
13657 Mark_Pragma_As_Ghost (N, Entity (Pool));
13658
13659 else
13660 Error_Pragma_Arg
13661 ("default storage pool must be a variable", Arg1);
13662 end if;
13663 end if;
13664
13665 -- Record the pool name (or null). Freeze.Freeze_Entity for an
13666 -- access type will use this information to set the appropriate
13667 -- attributes of the access type.
13668
13669 Default_Pool := Pool;
13670 end if;
13671 end Default_Storage_Pool;
13672
13673 -------------
13674 -- Depends --
13675 -------------
13676
13677 -- pragma Depends (DEPENDENCY_RELATION);
13678
13679 -- DEPENDENCY_RELATION ::=
13680 -- null
13681 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
13682
13683 -- DEPENDENCY_CLAUSE ::=
13684 -- OUTPUT_LIST =>[+] INPUT_LIST
13685 -- | NULL_DEPENDENCY_CLAUSE
13686
13687 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13688
13689 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13690
13691 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13692
13693 -- OUTPUT ::= NAME | FUNCTION_RESULT
13694 -- INPUT ::= NAME
13695
13696 -- where FUNCTION_RESULT is a function Result attribute_reference
13697
13698 -- Characteristics:
13699
13700 -- * Analysis - The annotation undergoes initial checks to verify
13701 -- the legal placement and context. Secondary checks fully analyze
13702 -- the dependency clauses in:
13703
13704 -- Analyze_Depends_In_Decl_Part
13705
13706 -- * Expansion - None.
13707
13708 -- * Template - The annotation utilizes the generic template of the
13709 -- related subprogram [body] when it is:
13710
13711 -- aspect on subprogram declaration
13712 -- aspect on stand alone subprogram body
13713 -- pragma on stand alone subprogram body
13714
13715 -- The annotation must prepare its own template when it is:
13716
13717 -- pragma on subprogram declaration
13718
13719 -- * Globals - Capture of global references must occur after full
13720 -- analysis.
13721
13722 -- * Instance - The annotation is instantiated automatically when
13723 -- the related generic subprogram [body] is instantiated except for
13724 -- the "pragma on subprogram declaration" case. In that scenario
13725 -- the annotation must instantiate itself.
13726
13727 when Pragma_Depends => Depends : declare
13728 Legal : Boolean;
13729 Spec_Id : Entity_Id;
13730 Subp_Decl : Node_Id;
13731
13732 begin
13733 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
13734
13735 if Legal then
13736
13737 -- Chain the pragma on the contract for further processing by
13738 -- Analyze_Depends_In_Decl_Part.
13739
13740 Add_Contract_Item (N, Spec_Id);
13741
13742 -- Fully analyze the pragma when it appears inside an entry
13743 -- or subprogram body because it cannot benefit from forward
13744 -- references.
13745
13746 if Nkind_In (Subp_Decl, N_Entry_Body,
13747 N_Subprogram_Body,
13748 N_Subprogram_Body_Stub)
13749 then
13750 -- The legality checks of pragmas Depends and Global are
13751 -- affected by the SPARK mode in effect and the volatility
13752 -- of the context. In addition these two pragmas are subject
13753 -- to an inherent order:
13754
13755 -- 1) Global
13756 -- 2) Depends
13757
13758 -- Analyze all these pragmas in the order outlined above
13759
13760 Analyze_If_Present (Pragma_SPARK_Mode);
13761 Analyze_If_Present (Pragma_Volatile_Function);
13762 Analyze_If_Present (Pragma_Global);
13763 Analyze_Depends_In_Decl_Part (N);
13764 end if;
13765 end if;
13766 end Depends;
13767
13768 ---------------------
13769 -- Detect_Blocking --
13770 ---------------------
13771
13772 -- pragma Detect_Blocking;
13773
13774 when Pragma_Detect_Blocking =>
13775 Ada_2005_Pragma;
13776 Check_Arg_Count (0);
13777 Check_Valid_Configuration_Pragma;
13778 Detect_Blocking := True;
13779
13780 ------------------------------------
13781 -- Disable_Atomic_Synchronization --
13782 ------------------------------------
13783
13784 -- pragma Disable_Atomic_Synchronization [(Entity)];
13785
13786 when Pragma_Disable_Atomic_Synchronization =>
13787 GNAT_Pragma;
13788 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
13789
13790 -------------------
13791 -- Discard_Names --
13792 -------------------
13793
13794 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13795
13796 when Pragma_Discard_Names => Discard_Names : declare
13797 E : Entity_Id;
13798 E_Id : Node_Id;
13799
13800 begin
13801 Check_Ada_83_Warning;
13802
13803 -- Deal with configuration pragma case
13804
13805 if Arg_Count = 0 and then Is_Configuration_Pragma then
13806 Global_Discard_Names := True;
13807 return;
13808
13809 -- Otherwise, check correct appropriate context
13810
13811 else
13812 Check_Is_In_Decl_Part_Or_Package_Spec;
13813
13814 if Arg_Count = 0 then
13815
13816 -- If there is no parameter, then from now on this pragma
13817 -- applies to any enumeration, exception or tagged type
13818 -- defined in the current declarative part, and recursively
13819 -- to any nested scope.
13820
13821 Set_Discard_Names (Current_Scope);
13822 return;
13823
13824 else
13825 Check_Arg_Count (1);
13826 Check_Optional_Identifier (Arg1, Name_On);
13827 Check_Arg_Is_Local_Name (Arg1);
13828
13829 E_Id := Get_Pragma_Arg (Arg1);
13830
13831 if Etype (E_Id) = Any_Type then
13832 return;
13833 else
13834 E := Entity (E_Id);
13835 end if;
13836
13837 -- A pragma that applies to a Ghost entity becomes Ghost for
13838 -- the purposes of legality checks and removal of ignored
13839 -- Ghost code.
13840
13841 Mark_Pragma_As_Ghost (N, E);
13842
13843 if (Is_First_Subtype (E)
13844 and then
13845 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
13846 or else Ekind (E) = E_Exception
13847 then
13848 Set_Discard_Names (E);
13849 Record_Rep_Item (E, N);
13850
13851 else
13852 Error_Pragma_Arg
13853 ("inappropriate entity for pragma%", Arg1);
13854 end if;
13855 end if;
13856 end if;
13857 end Discard_Names;
13858
13859 ------------------------
13860 -- Dispatching_Domain --
13861 ------------------------
13862
13863 -- pragma Dispatching_Domain (EXPRESSION);
13864
13865 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
13866 P : constant Node_Id := Parent (N);
13867 Arg : Node_Id;
13868 Ent : Entity_Id;
13869
13870 begin
13871 Ada_2012_Pragma;
13872 Check_No_Identifiers;
13873 Check_Arg_Count (1);
13874
13875 -- This pragma is born obsolete, but not the aspect
13876
13877 if not From_Aspect_Specification (N) then
13878 Check_Restriction
13879 (No_Obsolescent_Features, Pragma_Identifier (N));
13880 end if;
13881
13882 if Nkind (P) = N_Task_Definition then
13883 Arg := Get_Pragma_Arg (Arg1);
13884 Ent := Defining_Identifier (Parent (P));
13885
13886 -- A pragma that applies to a Ghost entity becomes Ghost for
13887 -- the purposes of legality checks and removal of ignored Ghost
13888 -- code.
13889
13890 Mark_Pragma_As_Ghost (N, Ent);
13891
13892 -- The expression must be analyzed in the special manner
13893 -- described in "Handling of Default and Per-Object
13894 -- Expressions" in sem.ads.
13895
13896 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
13897
13898 -- Check duplicate pragma before we chain the pragma in the Rep
13899 -- Item chain of Ent.
13900
13901 Check_Duplicate_Pragma (Ent);
13902 Record_Rep_Item (Ent, N);
13903
13904 -- Anything else is incorrect
13905
13906 else
13907 Pragma_Misplaced;
13908 end if;
13909 end Dispatching_Domain;
13910
13911 ---------------
13912 -- Elaborate --
13913 ---------------
13914
13915 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13916
13917 when Pragma_Elaborate => Elaborate : declare
13918 Arg : Node_Id;
13919 Citem : Node_Id;
13920
13921 begin
13922 -- Pragma must be in context items list of a compilation unit
13923
13924 if not Is_In_Context_Clause then
13925 Pragma_Misplaced;
13926 end if;
13927
13928 -- Must be at least one argument
13929
13930 if Arg_Count = 0 then
13931 Error_Pragma ("pragma% requires at least one argument");
13932 end if;
13933
13934 -- In Ada 83 mode, there can be no items following it in the
13935 -- context list except other pragmas and implicit with clauses
13936 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13937 -- placement rule does not apply.
13938
13939 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
13940 Citem := Next (N);
13941 while Present (Citem) loop
13942 if Nkind (Citem) = N_Pragma
13943 or else (Nkind (Citem) = N_With_Clause
13944 and then Implicit_With (Citem))
13945 then
13946 null;
13947 else
13948 Error_Pragma
13949 ("(Ada 83) pragma% must be at end of context clause");
13950 end if;
13951
13952 Next (Citem);
13953 end loop;
13954 end if;
13955
13956 -- Finally, the arguments must all be units mentioned in a with
13957 -- clause in the same context clause. Note we already checked (in
13958 -- Par.Prag) that the arguments are all identifiers or selected
13959 -- components.
13960
13961 Arg := Arg1;
13962 Outer : while Present (Arg) loop
13963 Citem := First (List_Containing (N));
13964 Inner : while Citem /= N loop
13965 if Nkind (Citem) = N_With_Clause
13966 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13967 then
13968 Set_Elaborate_Present (Citem, True);
13969 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13970
13971 -- With the pragma present, elaboration calls on
13972 -- subprograms from the named unit need no further
13973 -- checks, as long as the pragma appears in the current
13974 -- compilation unit. If the pragma appears in some unit
13975 -- in the context, there might still be a need for an
13976 -- Elaborate_All_Desirable from the current compilation
13977 -- to the named unit, so we keep the check enabled.
13978
13979 if In_Extended_Main_Source_Unit (N) then
13980
13981 -- This does not apply in SPARK mode, where we allow
13982 -- pragma Elaborate, but we don't trust it to be right
13983 -- so we will still insist on the Elaborate_All.
13984
13985 if SPARK_Mode /= On then
13986 Set_Suppress_Elaboration_Warnings
13987 (Entity (Name (Citem)));
13988 end if;
13989 end if;
13990
13991 exit Inner;
13992 end if;
13993
13994 Next (Citem);
13995 end loop Inner;
13996
13997 if Citem = N then
13998 Error_Pragma_Arg
13999 ("argument of pragma% is not withed unit", Arg);
14000 end if;
14001
14002 Next (Arg);
14003 end loop Outer;
14004
14005 -- Give a warning if operating in static mode with one of the
14006 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
14007
14008 if Elab_Warnings
14009 and not Dynamic_Elaboration_Checks
14010
14011 -- pragma Elaborate not allowed in SPARK mode anyway. We
14012 -- already complained about it, no point in generating any
14013 -- further complaint.
14014
14015 and SPARK_Mode /= On
14016 then
14017 Error_Msg_N
14018 ("?l?use of pragma Elaborate may not be safe", N);
14019 Error_Msg_N
14020 ("?l?use pragma Elaborate_All instead if possible", N);
14021 end if;
14022 end Elaborate;
14023
14024 -------------------
14025 -- Elaborate_All --
14026 -------------------
14027
14028 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
14029
14030 when Pragma_Elaborate_All => Elaborate_All : declare
14031 Arg : Node_Id;
14032 Citem : Node_Id;
14033
14034 begin
14035 Check_Ada_83_Warning;
14036
14037 -- Pragma must be in context items list of a compilation unit
14038
14039 if not Is_In_Context_Clause then
14040 Pragma_Misplaced;
14041 end if;
14042
14043 -- Must be at least one argument
14044
14045 if Arg_Count = 0 then
14046 Error_Pragma ("pragma% requires at least one argument");
14047 end if;
14048
14049 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
14050 -- have to appear at the end of the context clause, but may
14051 -- appear mixed in with other items, even in Ada 83 mode.
14052
14053 -- Final check: the arguments must all be units mentioned in
14054 -- a with clause in the same context clause. Note that we
14055 -- already checked (in Par.Prag) that all the arguments are
14056 -- either identifiers or selected components.
14057
14058 Arg := Arg1;
14059 Outr : while Present (Arg) loop
14060 Citem := First (List_Containing (N));
14061 Innr : while Citem /= N loop
14062 if Nkind (Citem) = N_With_Clause
14063 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
14064 then
14065 Set_Elaborate_All_Present (Citem, True);
14066 Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
14067
14068 -- Suppress warnings and elaboration checks on the named
14069 -- unit if the pragma is in the current compilation, as
14070 -- for pragma Elaborate.
14071
14072 if In_Extended_Main_Source_Unit (N) then
14073 Set_Suppress_Elaboration_Warnings
14074 (Entity (Name (Citem)));
14075 end if;
14076 exit Innr;
14077 end if;
14078
14079 Next (Citem);
14080 end loop Innr;
14081
14082 if Citem = N then
14083 Set_Error_Posted (N);
14084 Error_Pragma_Arg
14085 ("argument of pragma% is not withed unit", Arg);
14086 end if;
14087
14088 Next (Arg);
14089 end loop Outr;
14090 end Elaborate_All;
14091
14092 --------------------
14093 -- Elaborate_Body --
14094 --------------------
14095
14096 -- pragma Elaborate_Body [( library_unit_NAME )];
14097
14098 when Pragma_Elaborate_Body => Elaborate_Body : declare
14099 Cunit_Node : Node_Id;
14100 Cunit_Ent : Entity_Id;
14101
14102 begin
14103 Check_Ada_83_Warning;
14104 Check_Valid_Library_Unit_Pragma;
14105
14106 if Nkind (N) = N_Null_Statement then
14107 return;
14108 end if;
14109
14110 Cunit_Node := Cunit (Current_Sem_Unit);
14111 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
14112
14113 -- A pragma that applies to a Ghost entity becomes Ghost for the
14114 -- purposes of legality checks and removal of ignored Ghost code.
14115
14116 Mark_Pragma_As_Ghost (N, Cunit_Ent);
14117
14118 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
14119 N_Subprogram_Body)
14120 then
14121 Error_Pragma ("pragma% must refer to a spec, not a body");
14122 else
14123 Set_Body_Required (Cunit_Node, True);
14124 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
14125
14126 -- If we are in dynamic elaboration mode, then we suppress
14127 -- elaboration warnings for the unit, since it is definitely
14128 -- fine NOT to do dynamic checks at the first level (and such
14129 -- checks will be suppressed because no elaboration boolean
14130 -- is created for Elaborate_Body packages).
14131
14132 -- But in the static model of elaboration, Elaborate_Body is
14133 -- definitely NOT good enough to ensure elaboration safety on
14134 -- its own, since the body may WITH other units that are not
14135 -- safe from an elaboration point of view, so a client must
14136 -- still do an Elaborate_All on such units.
14137
14138 -- Debug flag -gnatdD restores the old behavior of 3.13, where
14139 -- Elaborate_Body always suppressed elab warnings.
14140
14141 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
14142 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
14143 end if;
14144 end if;
14145 end Elaborate_Body;
14146
14147 ------------------------
14148 -- Elaboration_Checks --
14149 ------------------------
14150
14151 -- pragma Elaboration_Checks (Static | Dynamic);
14152
14153 when Pragma_Elaboration_Checks =>
14154 GNAT_Pragma;
14155 Check_Arg_Count (1);
14156 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
14157
14158 -- Set flag accordingly (ignore attempt at dynamic elaboration
14159 -- checks in SPARK mode).
14160
14161 Dynamic_Elaboration_Checks :=
14162 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic)
14163 and then SPARK_Mode /= On;
14164
14165 ---------------
14166 -- Eliminate --
14167 ---------------
14168
14169 -- pragma Eliminate (
14170 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
14171 -- [,[Entity =>] IDENTIFIER |
14172 -- SELECTED_COMPONENT |
14173 -- STRING_LITERAL]
14174 -- [, OVERLOADING_RESOLUTION]);
14175
14176 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
14177 -- SOURCE_LOCATION
14178
14179 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
14180 -- FUNCTION_PROFILE
14181
14182 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
14183
14184 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
14185 -- Result_Type => result_SUBTYPE_NAME]
14186
14187 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
14188 -- SUBTYPE_NAME ::= STRING_LITERAL
14189
14190 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14191 -- SOURCE_TRACE ::= STRING_LITERAL
14192
14193 when Pragma_Eliminate => Eliminate : declare
14194 Args : Args_List (1 .. 5);
14195 Names : constant Name_List (1 .. 5) := (
14196 Name_Unit_Name,
14197 Name_Entity,
14198 Name_Parameter_Types,
14199 Name_Result_Type,
14200 Name_Source_Location);
14201
14202 Unit_Name : Node_Id renames Args (1);
14203 Entity : Node_Id renames Args (2);
14204 Parameter_Types : Node_Id renames Args (3);
14205 Result_Type : Node_Id renames Args (4);
14206 Source_Location : Node_Id renames Args (5);
14207
14208 begin
14209 GNAT_Pragma;
14210 Check_Valid_Configuration_Pragma;
14211 Gather_Associations (Names, Args);
14212
14213 if No (Unit_Name) then
14214 Error_Pragma ("missing Unit_Name argument for pragma%");
14215 end if;
14216
14217 if No (Entity)
14218 and then (Present (Parameter_Types)
14219 or else
14220 Present (Result_Type)
14221 or else
14222 Present (Source_Location))
14223 then
14224 Error_Pragma ("missing Entity argument for pragma%");
14225 end if;
14226
14227 if (Present (Parameter_Types)
14228 or else
14229 Present (Result_Type))
14230 and then
14231 Present (Source_Location)
14232 then
14233 Error_Pragma
14234 ("parameter profile and source location cannot be used "
14235 & "together in pragma%");
14236 end if;
14237
14238 Process_Eliminate_Pragma
14239 (N,
14240 Unit_Name,
14241 Entity,
14242 Parameter_Types,
14243 Result_Type,
14244 Source_Location);
14245 end Eliminate;
14246
14247 -----------------------------------
14248 -- Enable_Atomic_Synchronization --
14249 -----------------------------------
14250
14251 -- pragma Enable_Atomic_Synchronization [(Entity)];
14252
14253 when Pragma_Enable_Atomic_Synchronization =>
14254 GNAT_Pragma;
14255 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
14256
14257 ------------
14258 -- Export --
14259 ------------
14260
14261 -- pragma Export (
14262 -- [ Convention =>] convention_IDENTIFIER,
14263 -- [ Entity =>] LOCAL_NAME
14264 -- [, [External_Name =>] static_string_EXPRESSION ]
14265 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14266
14267 when Pragma_Export => Export : declare
14268 C : Convention_Id;
14269 Def_Id : Entity_Id;
14270
14271 pragma Warnings (Off, C);
14272
14273 begin
14274 Check_Ada_83_Warning;
14275 Check_Arg_Order
14276 ((Name_Convention,
14277 Name_Entity,
14278 Name_External_Name,
14279 Name_Link_Name));
14280
14281 Check_At_Least_N_Arguments (2);
14282 Check_At_Most_N_Arguments (4);
14283
14284 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14285 -- pragma Export (Entity, "external name");
14286
14287 if Relaxed_RM_Semantics
14288 and then Arg_Count = 2
14289 and then Nkind (Expression (Arg2)) = N_String_Literal
14290 then
14291 C := Convention_C;
14292 Def_Id := Get_Pragma_Arg (Arg1);
14293 Analyze (Def_Id);
14294
14295 if not Is_Entity_Name (Def_Id) then
14296 Error_Pragma_Arg ("entity name required", Arg1);
14297 end if;
14298
14299 Def_Id := Entity (Def_Id);
14300 Set_Exported (Def_Id, Arg1);
14301
14302 else
14303 Process_Convention (C, Def_Id);
14304
14305 -- A pragma that applies to a Ghost entity becomes Ghost for
14306 -- the purposes of legality checks and removal of ignored Ghost
14307 -- code.
14308
14309 Mark_Pragma_As_Ghost (N, Def_Id);
14310
14311 if Ekind (Def_Id) /= E_Constant then
14312 Note_Possible_Modification
14313 (Get_Pragma_Arg (Arg2), Sure => False);
14314 end if;
14315
14316 Process_Interface_Name (Def_Id, Arg3, Arg4);
14317 Set_Exported (Def_Id, Arg2);
14318 end if;
14319
14320 -- If the entity is a deferred constant, propagate the information
14321 -- to the full view, because gigi elaborates the full view only.
14322
14323 if Ekind (Def_Id) = E_Constant
14324 and then Present (Full_View (Def_Id))
14325 then
14326 declare
14327 Id2 : constant Entity_Id := Full_View (Def_Id);
14328 begin
14329 Set_Is_Exported (Id2, Is_Exported (Def_Id));
14330 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
14331 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
14332 end;
14333 end if;
14334 end Export;
14335
14336 ---------------------
14337 -- Export_Function --
14338 ---------------------
14339
14340 -- pragma Export_Function (
14341 -- [Internal =>] LOCAL_NAME
14342 -- [, [External =>] EXTERNAL_SYMBOL]
14343 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14344 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14345 -- [, [Mechanism =>] MECHANISM]
14346 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14347
14348 -- EXTERNAL_SYMBOL ::=
14349 -- IDENTIFIER
14350 -- | static_string_EXPRESSION
14351
14352 -- PARAMETER_TYPES ::=
14353 -- null
14354 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14355
14356 -- TYPE_DESIGNATOR ::=
14357 -- subtype_NAME
14358 -- | subtype_Name ' Access
14359
14360 -- MECHANISM ::=
14361 -- MECHANISM_NAME
14362 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14363
14364 -- MECHANISM_ASSOCIATION ::=
14365 -- [formal_parameter_NAME =>] MECHANISM_NAME
14366
14367 -- MECHANISM_NAME ::=
14368 -- Value
14369 -- | Reference
14370
14371 when Pragma_Export_Function => Export_Function : declare
14372 Args : Args_List (1 .. 6);
14373 Names : constant Name_List (1 .. 6) := (
14374 Name_Internal,
14375 Name_External,
14376 Name_Parameter_Types,
14377 Name_Result_Type,
14378 Name_Mechanism,
14379 Name_Result_Mechanism);
14380
14381 Internal : Node_Id renames Args (1);
14382 External : Node_Id renames Args (2);
14383 Parameter_Types : Node_Id renames Args (3);
14384 Result_Type : Node_Id renames Args (4);
14385 Mechanism : Node_Id renames Args (5);
14386 Result_Mechanism : Node_Id renames Args (6);
14387
14388 begin
14389 GNAT_Pragma;
14390 Gather_Associations (Names, Args);
14391 Process_Extended_Import_Export_Subprogram_Pragma (
14392 Arg_Internal => Internal,
14393 Arg_External => External,
14394 Arg_Parameter_Types => Parameter_Types,
14395 Arg_Result_Type => Result_Type,
14396 Arg_Mechanism => Mechanism,
14397 Arg_Result_Mechanism => Result_Mechanism);
14398 end Export_Function;
14399
14400 -------------------
14401 -- Export_Object --
14402 -------------------
14403
14404 -- pragma Export_Object (
14405 -- [Internal =>] LOCAL_NAME
14406 -- [, [External =>] EXTERNAL_SYMBOL]
14407 -- [, [Size =>] EXTERNAL_SYMBOL]);
14408
14409 -- EXTERNAL_SYMBOL ::=
14410 -- IDENTIFIER
14411 -- | static_string_EXPRESSION
14412
14413 -- PARAMETER_TYPES ::=
14414 -- null
14415 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14416
14417 -- TYPE_DESIGNATOR ::=
14418 -- subtype_NAME
14419 -- | subtype_Name ' Access
14420
14421 -- MECHANISM ::=
14422 -- MECHANISM_NAME
14423 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14424
14425 -- MECHANISM_ASSOCIATION ::=
14426 -- [formal_parameter_NAME =>] MECHANISM_NAME
14427
14428 -- MECHANISM_NAME ::=
14429 -- Value
14430 -- | Reference
14431
14432 when Pragma_Export_Object => Export_Object : declare
14433 Args : Args_List (1 .. 3);
14434 Names : constant Name_List (1 .. 3) := (
14435 Name_Internal,
14436 Name_External,
14437 Name_Size);
14438
14439 Internal : Node_Id renames Args (1);
14440 External : Node_Id renames Args (2);
14441 Size : Node_Id renames Args (3);
14442
14443 begin
14444 GNAT_Pragma;
14445 Gather_Associations (Names, Args);
14446 Process_Extended_Import_Export_Object_Pragma (
14447 Arg_Internal => Internal,
14448 Arg_External => External,
14449 Arg_Size => Size);
14450 end Export_Object;
14451
14452 ----------------------
14453 -- Export_Procedure --
14454 ----------------------
14455
14456 -- pragma Export_Procedure (
14457 -- [Internal =>] LOCAL_NAME
14458 -- [, [External =>] EXTERNAL_SYMBOL]
14459 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14460 -- [, [Mechanism =>] MECHANISM]);
14461
14462 -- EXTERNAL_SYMBOL ::=
14463 -- IDENTIFIER
14464 -- | static_string_EXPRESSION
14465
14466 -- PARAMETER_TYPES ::=
14467 -- null
14468 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14469
14470 -- TYPE_DESIGNATOR ::=
14471 -- subtype_NAME
14472 -- | subtype_Name ' Access
14473
14474 -- MECHANISM ::=
14475 -- MECHANISM_NAME
14476 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14477
14478 -- MECHANISM_ASSOCIATION ::=
14479 -- [formal_parameter_NAME =>] MECHANISM_NAME
14480
14481 -- MECHANISM_NAME ::=
14482 -- Value
14483 -- | Reference
14484
14485 when Pragma_Export_Procedure => Export_Procedure : declare
14486 Args : Args_List (1 .. 4);
14487 Names : constant Name_List (1 .. 4) := (
14488 Name_Internal,
14489 Name_External,
14490 Name_Parameter_Types,
14491 Name_Mechanism);
14492
14493 Internal : Node_Id renames Args (1);
14494 External : Node_Id renames Args (2);
14495 Parameter_Types : Node_Id renames Args (3);
14496 Mechanism : Node_Id renames Args (4);
14497
14498 begin
14499 GNAT_Pragma;
14500 Gather_Associations (Names, Args);
14501 Process_Extended_Import_Export_Subprogram_Pragma (
14502 Arg_Internal => Internal,
14503 Arg_External => External,
14504 Arg_Parameter_Types => Parameter_Types,
14505 Arg_Mechanism => Mechanism);
14506 end Export_Procedure;
14507
14508 ------------------
14509 -- Export_Value --
14510 ------------------
14511
14512 -- pragma Export_Value (
14513 -- [Value =>] static_integer_EXPRESSION,
14514 -- [Link_Name =>] static_string_EXPRESSION);
14515
14516 when Pragma_Export_Value =>
14517 GNAT_Pragma;
14518 Check_Arg_Order ((Name_Value, Name_Link_Name));
14519 Check_Arg_Count (2);
14520
14521 Check_Optional_Identifier (Arg1, Name_Value);
14522 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
14523
14524 Check_Optional_Identifier (Arg2, Name_Link_Name);
14525 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
14526
14527 -----------------------------
14528 -- Export_Valued_Procedure --
14529 -----------------------------
14530
14531 -- pragma Export_Valued_Procedure (
14532 -- [Internal =>] LOCAL_NAME
14533 -- [, [External =>] EXTERNAL_SYMBOL,]
14534 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14535 -- [, [Mechanism =>] MECHANISM]);
14536
14537 -- EXTERNAL_SYMBOL ::=
14538 -- IDENTIFIER
14539 -- | static_string_EXPRESSION
14540
14541 -- PARAMETER_TYPES ::=
14542 -- null
14543 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14544
14545 -- TYPE_DESIGNATOR ::=
14546 -- subtype_NAME
14547 -- | subtype_Name ' Access
14548
14549 -- MECHANISM ::=
14550 -- MECHANISM_NAME
14551 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14552
14553 -- MECHANISM_ASSOCIATION ::=
14554 -- [formal_parameter_NAME =>] MECHANISM_NAME
14555
14556 -- MECHANISM_NAME ::=
14557 -- Value
14558 -- | Reference
14559
14560 when Pragma_Export_Valued_Procedure =>
14561 Export_Valued_Procedure : declare
14562 Args : Args_List (1 .. 4);
14563 Names : constant Name_List (1 .. 4) := (
14564 Name_Internal,
14565 Name_External,
14566 Name_Parameter_Types,
14567 Name_Mechanism);
14568
14569 Internal : Node_Id renames Args (1);
14570 External : Node_Id renames Args (2);
14571 Parameter_Types : Node_Id renames Args (3);
14572 Mechanism : Node_Id renames Args (4);
14573
14574 begin
14575 GNAT_Pragma;
14576 Gather_Associations (Names, Args);
14577 Process_Extended_Import_Export_Subprogram_Pragma (
14578 Arg_Internal => Internal,
14579 Arg_External => External,
14580 Arg_Parameter_Types => Parameter_Types,
14581 Arg_Mechanism => Mechanism);
14582 end Export_Valued_Procedure;
14583
14584 -------------------
14585 -- Extend_System --
14586 -------------------
14587
14588 -- pragma Extend_System ([Name =>] Identifier);
14589
14590 when Pragma_Extend_System => Extend_System : declare
14591 begin
14592 GNAT_Pragma;
14593 Check_Valid_Configuration_Pragma;
14594 Check_Arg_Count (1);
14595 Check_Optional_Identifier (Arg1, Name_Name);
14596 Check_Arg_Is_Identifier (Arg1);
14597
14598 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14599
14600 if Name_Len > 4
14601 and then Name_Buffer (1 .. 4) = "aux_"
14602 then
14603 if Present (System_Extend_Pragma_Arg) then
14604 if Chars (Get_Pragma_Arg (Arg1)) =
14605 Chars (Expression (System_Extend_Pragma_Arg))
14606 then
14607 null;
14608 else
14609 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
14610 Error_Pragma ("pragma% conflicts with that #");
14611 end if;
14612
14613 else
14614 System_Extend_Pragma_Arg := Arg1;
14615
14616 if not GNAT_Mode then
14617 System_Extend_Unit := Arg1;
14618 end if;
14619 end if;
14620 else
14621 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
14622 end if;
14623 end Extend_System;
14624
14625 ------------------------
14626 -- Extensions_Allowed --
14627 ------------------------
14628
14629 -- pragma Extensions_Allowed (ON | OFF);
14630
14631 when Pragma_Extensions_Allowed =>
14632 GNAT_Pragma;
14633 Check_Arg_Count (1);
14634 Check_No_Identifiers;
14635 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14636
14637 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
14638 Extensions_Allowed := True;
14639 Ada_Version := Ada_Version_Type'Last;
14640
14641 else
14642 Extensions_Allowed := False;
14643 Ada_Version := Ada_Version_Explicit;
14644 Ada_Version_Pragma := Empty;
14645 end if;
14646
14647 ------------------------
14648 -- Extensions_Visible --
14649 ------------------------
14650
14651 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
14652
14653 -- Characteristics:
14654
14655 -- * Analysis - The annotation is fully analyzed immediately upon
14656 -- elaboration as its expression must be static.
14657
14658 -- * Expansion - None.
14659
14660 -- * Template - The annotation utilizes the generic template of the
14661 -- related subprogram [body] when it is:
14662
14663 -- aspect on subprogram declaration
14664 -- aspect on stand alone subprogram body
14665 -- pragma on stand alone subprogram body
14666
14667 -- The annotation must prepare its own template when it is:
14668
14669 -- pragma on subprogram declaration
14670
14671 -- * Globals - Capture of global references must occur after full
14672 -- analysis.
14673
14674 -- * Instance - The annotation is instantiated automatically when
14675 -- the related generic subprogram [body] is instantiated except for
14676 -- the "pragma on subprogram declaration" case. In that scenario
14677 -- the annotation must instantiate itself.
14678
14679 when Pragma_Extensions_Visible => Extensions_Visible : declare
14680 Formal : Entity_Id;
14681 Has_OK_Formal : Boolean := False;
14682 Spec_Id : Entity_Id;
14683 Subp_Decl : Node_Id;
14684
14685 begin
14686 GNAT_Pragma;
14687 Check_No_Identifiers;
14688 Check_At_Most_N_Arguments (1);
14689
14690 Subp_Decl :=
14691 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
14692
14693 -- Abstract subprogram declaration
14694
14695 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
14696 null;
14697
14698 -- Generic subprogram declaration
14699
14700 elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
14701 null;
14702
14703 -- Body acts as spec
14704
14705 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14706 and then No (Corresponding_Spec (Subp_Decl))
14707 then
14708 null;
14709
14710 -- Body stub acts as spec
14711
14712 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14713 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14714 then
14715 null;
14716
14717 -- Subprogram declaration
14718
14719 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
14720 null;
14721
14722 -- Otherwise the pragma is associated with an illegal construct
14723
14724 else
14725 Error_Pragma ("pragma % must apply to a subprogram");
14726 return;
14727 end if;
14728
14729 -- Chain the pragma on the contract for completeness
14730
14731 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14732
14733 -- The legality checks of pragma Extension_Visible are affected
14734 -- by the SPARK mode in effect. Analyze all pragmas in specific
14735 -- order.
14736
14737 Analyze_If_Present (Pragma_SPARK_Mode);
14738
14739 -- Mark the pragma as Ghost if the related subprogram is also
14740 -- Ghost. This also ensures that any expansion performed further
14741 -- below will produce Ghost nodes.
14742
14743 Spec_Id := Unique_Defining_Entity (Subp_Decl);
14744 Mark_Pragma_As_Ghost (N, Spec_Id);
14745
14746 -- Examine the formals of the related subprogram
14747
14748 Formal := First_Formal (Spec_Id);
14749 while Present (Formal) loop
14750
14751 -- At least one of the formals is of a specific tagged type,
14752 -- the pragma is legal.
14753
14754 if Is_Specific_Tagged_Type (Etype (Formal)) then
14755 Has_OK_Formal := True;
14756 exit;
14757
14758 -- A generic subprogram with at least one formal of a private
14759 -- type ensures the legality of the pragma because the actual
14760 -- may be specifically tagged. Note that this is verified by
14761 -- the check above at instantiation time.
14762
14763 elsif Is_Private_Type (Etype (Formal))
14764 and then Is_Generic_Type (Etype (Formal))
14765 then
14766 Has_OK_Formal := True;
14767 exit;
14768 end if;
14769
14770 Next_Formal (Formal);
14771 end loop;
14772
14773 if not Has_OK_Formal then
14774 Error_Msg_Name_1 := Pname;
14775 Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N);
14776 Error_Msg_NE
14777 ("\subprogram & lacks parameter of specific tagged or "
14778 & "generic private type", N, Spec_Id);
14779
14780 return;
14781 end if;
14782
14783 -- Analyze the Boolean expression (if any)
14784
14785 if Present (Arg1) then
14786 Check_Static_Boolean_Expression
14787 (Expression (Get_Argument (N, Spec_Id)));
14788 end if;
14789 end Extensions_Visible;
14790
14791 --------------
14792 -- External --
14793 --------------
14794
14795 -- pragma External (
14796 -- [ Convention =>] convention_IDENTIFIER,
14797 -- [ Entity =>] LOCAL_NAME
14798 -- [, [External_Name =>] static_string_EXPRESSION ]
14799 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14800
14801 when Pragma_External => External : declare
14802 C : Convention_Id;
14803 E : Entity_Id;
14804 pragma Warnings (Off, C);
14805
14806 begin
14807 GNAT_Pragma;
14808 Check_Arg_Order
14809 ((Name_Convention,
14810 Name_Entity,
14811 Name_External_Name,
14812 Name_Link_Name));
14813 Check_At_Least_N_Arguments (2);
14814 Check_At_Most_N_Arguments (4);
14815 Process_Convention (C, E);
14816
14817 -- A pragma that applies to a Ghost entity becomes Ghost for the
14818 -- purposes of legality checks and removal of ignored Ghost code.
14819
14820 Mark_Pragma_As_Ghost (N, E);
14821
14822 Note_Possible_Modification
14823 (Get_Pragma_Arg (Arg2), Sure => False);
14824 Process_Interface_Name (E, Arg3, Arg4);
14825 Set_Exported (E, Arg2);
14826 end External;
14827
14828 --------------------------
14829 -- External_Name_Casing --
14830 --------------------------
14831
14832 -- pragma External_Name_Casing (
14833 -- UPPERCASE | LOWERCASE
14834 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14835
14836 when Pragma_External_Name_Casing => External_Name_Casing : declare
14837 begin
14838 GNAT_Pragma;
14839 Check_No_Identifiers;
14840
14841 if Arg_Count = 2 then
14842 Check_Arg_Is_One_Of
14843 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
14844
14845 case Chars (Get_Pragma_Arg (Arg2)) is
14846 when Name_As_Is =>
14847 Opt.External_Name_Exp_Casing := As_Is;
14848
14849 when Name_Uppercase =>
14850 Opt.External_Name_Exp_Casing := Uppercase;
14851
14852 when Name_Lowercase =>
14853 Opt.External_Name_Exp_Casing := Lowercase;
14854
14855 when others =>
14856 null;
14857 end case;
14858
14859 else
14860 Check_Arg_Count (1);
14861 end if;
14862
14863 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
14864
14865 case Chars (Get_Pragma_Arg (Arg1)) is
14866 when Name_Uppercase =>
14867 Opt.External_Name_Imp_Casing := Uppercase;
14868
14869 when Name_Lowercase =>
14870 Opt.External_Name_Imp_Casing := Lowercase;
14871
14872 when others =>
14873 null;
14874 end case;
14875 end External_Name_Casing;
14876
14877 ---------------
14878 -- Fast_Math --
14879 ---------------
14880
14881 -- pragma Fast_Math;
14882
14883 when Pragma_Fast_Math =>
14884 GNAT_Pragma;
14885 Check_No_Identifiers;
14886 Check_Valid_Configuration_Pragma;
14887 Fast_Math := True;
14888
14889 --------------------------
14890 -- Favor_Top_Level --
14891 --------------------------
14892
14893 -- pragma Favor_Top_Level (type_NAME);
14894
14895 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
14896 Typ : Entity_Id;
14897
14898 begin
14899 GNAT_Pragma;
14900 Check_No_Identifiers;
14901 Check_Arg_Count (1);
14902 Check_Arg_Is_Local_Name (Arg1);
14903 Typ := Entity (Get_Pragma_Arg (Arg1));
14904
14905 -- A pragma that applies to a Ghost entity becomes Ghost for the
14906 -- purposes of legality checks and removal of ignored Ghost code.
14907
14908 Mark_Pragma_As_Ghost (N, Typ);
14909
14910 -- If it's an access-to-subprogram type (in particular, not a
14911 -- subtype), set the flag on that type.
14912
14913 if Is_Access_Subprogram_Type (Typ) then
14914 Set_Can_Use_Internal_Rep (Typ, False);
14915
14916 -- Otherwise it's an error (name denotes the wrong sort of entity)
14917
14918 else
14919 Error_Pragma_Arg
14920 ("access-to-subprogram type expected",
14921 Get_Pragma_Arg (Arg1));
14922 end if;
14923 end Favor_Top_Level;
14924
14925 ---------------------------
14926 -- Finalize_Storage_Only --
14927 ---------------------------
14928
14929 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14930
14931 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
14932 Assoc : constant Node_Id := Arg1;
14933 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14934 Typ : Entity_Id;
14935
14936 begin
14937 GNAT_Pragma;
14938 Check_No_Identifiers;
14939 Check_Arg_Count (1);
14940 Check_Arg_Is_Local_Name (Arg1);
14941
14942 Find_Type (Type_Id);
14943 Typ := Entity (Type_Id);
14944
14945 if Typ = Any_Type
14946 or else Rep_Item_Too_Early (Typ, N)
14947 then
14948 return;
14949 else
14950 Typ := Underlying_Type (Typ);
14951 end if;
14952
14953 if not Is_Controlled (Typ) then
14954 Error_Pragma ("pragma% must specify controlled type");
14955 end if;
14956
14957 Check_First_Subtype (Arg1);
14958
14959 if Finalize_Storage_Only (Typ) then
14960 Error_Pragma ("duplicate pragma%, only one allowed");
14961
14962 elsif not Rep_Item_Too_Late (Typ, N) then
14963 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14964 end if;
14965 end Finalize_Storage;
14966
14967 -----------
14968 -- Ghost --
14969 -----------
14970
14971 -- pragma Ghost [ (boolean_EXPRESSION) ];
14972
14973 when Pragma_Ghost => Ghost : declare
14974 Context : Node_Id;
14975 Expr : Node_Id;
14976 Id : Entity_Id;
14977 Orig_Stmt : Node_Id;
14978 Prev_Id : Entity_Id;
14979 Stmt : Node_Id;
14980
14981 begin
14982 GNAT_Pragma;
14983 Check_No_Identifiers;
14984 Check_At_Most_N_Arguments (1);
14985
14986 Id := Empty;
14987 Stmt := Prev (N);
14988 while Present (Stmt) loop
14989
14990 -- Skip prior pragmas, but check for duplicates
14991
14992 if Nkind (Stmt) = N_Pragma then
14993 if Pragma_Name (Stmt) = Pname then
14994 Error_Msg_Name_1 := Pname;
14995 Error_Msg_Sloc := Sloc (Stmt);
14996 Error_Msg_N ("pragma % duplicates pragma declared#", N);
14997 end if;
14998
14999 -- Task unit declared without a definition cannot be subject to
15000 -- pragma Ghost (SPARK RM 6.9(19)).
15001
15002 elsif Nkind_In (Stmt, N_Single_Task_Declaration,
15003 N_Task_Type_Declaration)
15004 then
15005 Error_Pragma ("pragma % cannot apply to a task type");
15006 return;
15007
15008 -- Skip internally generated code
15009
15010 elsif not Comes_From_Source (Stmt) then
15011 Orig_Stmt := Original_Node (Stmt);
15012
15013 -- When pragma Ghost applies to an untagged derivation, the
15014 -- derivation is transformed into a [sub]type declaration.
15015
15016 if Nkind_In (Stmt, N_Full_Type_Declaration,
15017 N_Subtype_Declaration)
15018 and then Comes_From_Source (Orig_Stmt)
15019 and then Nkind (Orig_Stmt) = N_Full_Type_Declaration
15020 and then Nkind (Type_Definition (Orig_Stmt)) =
15021 N_Derived_Type_Definition
15022 then
15023 Id := Defining_Entity (Stmt);
15024 exit;
15025
15026 -- When pragma Ghost applies to an object declaration which
15027 -- is initialized by means of a function call that returns
15028 -- on the secondary stack, the object declaration becomes a
15029 -- renaming.
15030
15031 elsif Nkind (Stmt) = N_Object_Renaming_Declaration
15032 and then Comes_From_Source (Orig_Stmt)
15033 and then Nkind (Orig_Stmt) = N_Object_Declaration
15034 then
15035 Id := Defining_Entity (Stmt);
15036 exit;
15037
15038 -- When pragma Ghost applies to an expression function, the
15039 -- expression function is transformed into a subprogram.
15040
15041 elsif Nkind (Stmt) = N_Subprogram_Declaration
15042 and then Comes_From_Source (Orig_Stmt)
15043 and then Nkind (Orig_Stmt) = N_Expression_Function
15044 then
15045 Id := Defining_Entity (Stmt);
15046 exit;
15047 end if;
15048
15049 -- The pragma applies to a legal construct, stop the traversal
15050
15051 elsif Nkind_In (Stmt, N_Abstract_Subprogram_Declaration,
15052 N_Full_Type_Declaration,
15053 N_Generic_Subprogram_Declaration,
15054 N_Object_Declaration,
15055 N_Private_Extension_Declaration,
15056 N_Private_Type_Declaration,
15057 N_Subprogram_Declaration,
15058 N_Subtype_Declaration)
15059 then
15060 Id := Defining_Entity (Stmt);
15061 exit;
15062
15063 -- The pragma does not apply to a legal construct, issue an
15064 -- error and stop the analysis.
15065
15066 else
15067 Error_Pragma
15068 ("pragma % must apply to an object, package, subprogram "
15069 & "or type");
15070 return;
15071 end if;
15072
15073 Stmt := Prev (Stmt);
15074 end loop;
15075
15076 Context := Parent (N);
15077
15078 -- Handle compilation units
15079
15080 if Nkind (Context) = N_Compilation_Unit_Aux then
15081 Context := Unit (Parent (Context));
15082 end if;
15083
15084 -- Protected and task types cannot be subject to pragma Ghost
15085 -- (SPARK RM 6.9(19)).
15086
15087 if Nkind_In (Context, N_Protected_Body, N_Protected_Definition)
15088 then
15089 Error_Pragma ("pragma % cannot apply to a protected type");
15090 return;
15091
15092 elsif Nkind_In (Context, N_Task_Body, N_Task_Definition) then
15093 Error_Pragma ("pragma % cannot apply to a task type");
15094 return;
15095 end if;
15096
15097 if No (Id) then
15098
15099 -- When pragma Ghost is associated with a [generic] package, it
15100 -- appears in the visible declarations.
15101
15102 if Nkind (Context) = N_Package_Specification
15103 and then Present (Visible_Declarations (Context))
15104 and then List_Containing (N) = Visible_Declarations (Context)
15105 then
15106 Id := Defining_Entity (Context);
15107
15108 -- Pragma Ghost applies to a stand alone subprogram body
15109
15110 elsif Nkind (Context) = N_Subprogram_Body
15111 and then No (Corresponding_Spec (Context))
15112 then
15113 Id := Defining_Entity (Context);
15114
15115 -- Pragma Ghost applies to a subprogram declaration that acts
15116 -- as a compilation unit.
15117
15118 elsif Nkind (Context) = N_Subprogram_Declaration then
15119 Id := Defining_Entity (Context);
15120 end if;
15121 end if;
15122
15123 if No (Id) then
15124 Error_Pragma
15125 ("pragma % must apply to an object, package, subprogram or "
15126 & "type");
15127 return;
15128 end if;
15129
15130 -- Handle completions of types and constants that are subject to
15131 -- pragma Ghost.
15132
15133 if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then
15134 Prev_Id := Incomplete_Or_Partial_View (Id);
15135
15136 if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then
15137 Error_Msg_Name_1 := Pname;
15138
15139 -- The full declaration of a deferred constant cannot be
15140 -- subject to pragma Ghost unless the deferred declaration
15141 -- is also Ghost (SPARK RM 6.9(9)).
15142
15143 if Ekind (Prev_Id) = E_Constant then
15144 Error_Msg_Name_1 := Pname;
15145 Error_Msg_NE (Fix_Error
15146 ("pragma % must apply to declaration of deferred "
15147 & "constant &"), N, Id);
15148 return;
15149
15150 -- Pragma Ghost may appear on the full view of an incomplete
15151 -- type because the incomplete declaration lacks aspects and
15152 -- cannot be subject to pragma Ghost.
15153
15154 elsif Ekind (Prev_Id) = E_Incomplete_Type then
15155 null;
15156
15157 -- The full declaration of a type cannot be subject to
15158 -- pragma Ghost unless the partial view is also Ghost
15159 -- (SPARK RM 6.9(9)).
15160
15161 else
15162 Error_Msg_NE (Fix_Error
15163 ("pragma % must apply to partial view of type &"),
15164 N, Id);
15165 return;
15166 end if;
15167 end if;
15168
15169 -- A synchronized object cannot be subject to pragma Ghost
15170 -- (SPARK RM 6.9(19)).
15171
15172 elsif Ekind (Id) = E_Variable then
15173 if Is_Protected_Type (Etype (Id)) then
15174 Error_Pragma ("pragma % cannot apply to a protected object");
15175 return;
15176
15177 elsif Is_Task_Type (Etype (Id)) then
15178 Error_Pragma ("pragma % cannot apply to a task object");
15179 return;
15180 end if;
15181 end if;
15182
15183 -- Analyze the Boolean expression (if any)
15184
15185 if Present (Arg1) then
15186 Expr := Get_Pragma_Arg (Arg1);
15187
15188 Analyze_And_Resolve (Expr, Standard_Boolean);
15189
15190 if Is_OK_Static_Expression (Expr) then
15191
15192 -- "Ghostness" cannot be turned off once enabled within a
15193 -- region (SPARK RM 6.9(6)).
15194
15195 if Is_False (Expr_Value (Expr))
15196 and then Ghost_Mode > None
15197 then
15198 Error_Pragma
15199 ("pragma % with value False cannot appear in enabled "
15200 & "ghost region");
15201 return;
15202 end if;
15203
15204 -- Otherwie the expression is not static
15205
15206 else
15207 Error_Pragma_Arg
15208 ("expression of pragma % must be static", Expr);
15209 return;
15210 end if;
15211 end if;
15212
15213 Set_Is_Ghost_Entity (Id);
15214 end Ghost;
15215
15216 ------------
15217 -- Global --
15218 ------------
15219
15220 -- pragma Global (GLOBAL_SPECIFICATION);
15221
15222 -- GLOBAL_SPECIFICATION ::=
15223 -- null
15224 -- | (GLOBAL_LIST)
15225 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15226
15227 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15228
15229 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15230 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15231 -- GLOBAL_ITEM ::= NAME
15232
15233 -- Characteristics:
15234
15235 -- * Analysis - The annotation undergoes initial checks to verify
15236 -- the legal placement and context. Secondary checks fully analyze
15237 -- the dependency clauses in:
15238
15239 -- Analyze_Global_In_Decl_Part
15240
15241 -- * Expansion - None.
15242
15243 -- * Template - The annotation utilizes the generic template of the
15244 -- related subprogram [body] when it is:
15245
15246 -- aspect on subprogram declaration
15247 -- aspect on stand alone subprogram body
15248 -- pragma on stand alone subprogram body
15249
15250 -- The annotation must prepare its own template when it is:
15251
15252 -- pragma on subprogram declaration
15253
15254 -- * Globals - Capture of global references must occur after full
15255 -- analysis.
15256
15257 -- * Instance - The annotation is instantiated automatically when
15258 -- the related generic subprogram [body] is instantiated except for
15259 -- the "pragma on subprogram declaration" case. In that scenario
15260 -- the annotation must instantiate itself.
15261
15262 when Pragma_Global => Global : declare
15263 Legal : Boolean;
15264 Spec_Id : Entity_Id;
15265 Subp_Decl : Node_Id;
15266
15267 begin
15268 Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal);
15269
15270 if Legal then
15271
15272 -- Chain the pragma on the contract for further processing by
15273 -- Analyze_Global_In_Decl_Part.
15274
15275 Add_Contract_Item (N, Spec_Id);
15276
15277 -- Fully analyze the pragma when it appears inside an entry
15278 -- or subprogram body because it cannot benefit from forward
15279 -- references.
15280
15281 if Nkind_In (Subp_Decl, N_Entry_Body,
15282 N_Subprogram_Body,
15283 N_Subprogram_Body_Stub)
15284 then
15285 -- The legality checks of pragmas Depends and Global are
15286 -- affected by the SPARK mode in effect and the volatility
15287 -- of the context. In addition these two pragmas are subject
15288 -- to an inherent order:
15289
15290 -- 1) Global
15291 -- 2) Depends
15292
15293 -- Analyze all these pragmas in the order outlined above
15294
15295 Analyze_If_Present (Pragma_SPARK_Mode);
15296 Analyze_If_Present (Pragma_Volatile_Function);
15297 Analyze_Global_In_Decl_Part (N);
15298 Analyze_If_Present (Pragma_Depends);
15299 end if;
15300 end if;
15301 end Global;
15302
15303 -----------
15304 -- Ident --
15305 -----------
15306
15307 -- pragma Ident (static_string_EXPRESSION)
15308
15309 -- Note: pragma Comment shares this processing. Pragma Ident is
15310 -- identical in effect to pragma Commment.
15311
15312 when Pragma_Ident | Pragma_Comment => Ident : declare
15313 Str : Node_Id;
15314
15315 begin
15316 GNAT_Pragma;
15317 Check_Arg_Count (1);
15318 Check_No_Identifiers;
15319 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
15320 Store_Note (N);
15321
15322 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
15323
15324 declare
15325 CS : Node_Id;
15326 GP : Node_Id;
15327
15328 begin
15329 GP := Parent (Parent (N));
15330
15331 if Nkind_In (GP, N_Package_Declaration,
15332 N_Generic_Package_Declaration)
15333 then
15334 GP := Parent (GP);
15335 end if;
15336
15337 -- If we have a compilation unit, then record the ident value,
15338 -- checking for improper duplication.
15339
15340 if Nkind (GP) = N_Compilation_Unit then
15341 CS := Ident_String (Current_Sem_Unit);
15342
15343 if Present (CS) then
15344
15345 -- If we have multiple instances, concatenate them, but
15346 -- not in ASIS, where we want the original tree.
15347
15348 if not ASIS_Mode then
15349 Start_String (Strval (CS));
15350 Store_String_Char (' ');
15351 Store_String_Chars (Strval (Str));
15352 Set_Strval (CS, End_String);
15353 end if;
15354
15355 else
15356 Set_Ident_String (Current_Sem_Unit, Str);
15357 end if;
15358
15359 -- For subunits, we just ignore the Ident, since in GNAT these
15360 -- are not separate object files, and hence not separate units
15361 -- in the unit table.
15362
15363 elsif Nkind (GP) = N_Subunit then
15364 null;
15365 end if;
15366 end;
15367 end Ident;
15368
15369 -------------------
15370 -- Ignore_Pragma --
15371 -------------------
15372
15373 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15374
15375 -- Entirely handled in the parser, nothing to do here
15376
15377 when Pragma_Ignore_Pragma =>
15378 null;
15379
15380 ----------------------------
15381 -- Implementation_Defined --
15382 ----------------------------
15383
15384 -- pragma Implementation_Defined (LOCAL_NAME);
15385
15386 -- Marks previously declared entity as implementation defined. For
15387 -- an overloaded entity, applies to the most recent homonym.
15388
15389 -- pragma Implementation_Defined;
15390
15391 -- The form with no arguments appears anywhere within a scope, most
15392 -- typically a package spec, and indicates that all entities that are
15393 -- defined within the package spec are Implementation_Defined.
15394
15395 when Pragma_Implementation_Defined => Implementation_Defined : declare
15396 Ent : Entity_Id;
15397
15398 begin
15399 GNAT_Pragma;
15400 Check_No_Identifiers;
15401
15402 -- Form with no arguments
15403
15404 if Arg_Count = 0 then
15405 Set_Is_Implementation_Defined (Current_Scope);
15406
15407 -- Form with one argument
15408
15409 else
15410 Check_Arg_Count (1);
15411 Check_Arg_Is_Local_Name (Arg1);
15412 Ent := Entity (Get_Pragma_Arg (Arg1));
15413 Set_Is_Implementation_Defined (Ent);
15414 end if;
15415 end Implementation_Defined;
15416
15417 -----------------
15418 -- Implemented --
15419 -----------------
15420
15421 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15422
15423 -- IMPLEMENTATION_KIND ::=
15424 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15425
15426 -- "By_Any" and "Optional" are treated as synonyms in order to
15427 -- support Ada 2012 aspect Synchronization.
15428
15429 when Pragma_Implemented => Implemented : declare
15430 Proc_Id : Entity_Id;
15431 Typ : Entity_Id;
15432
15433 begin
15434 Ada_2012_Pragma;
15435 Check_Arg_Count (2);
15436 Check_No_Identifiers;
15437 Check_Arg_Is_Identifier (Arg1);
15438 Check_Arg_Is_Local_Name (Arg1);
15439 Check_Arg_Is_One_Of (Arg2,
15440 Name_By_Any,
15441 Name_By_Entry,
15442 Name_By_Protected_Procedure,
15443 Name_Optional);
15444
15445 -- Extract the name of the local procedure
15446
15447 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
15448
15449 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
15450 -- primitive procedure of a synchronized tagged type.
15451
15452 if Ekind (Proc_Id) = E_Procedure
15453 and then Is_Primitive (Proc_Id)
15454 and then Present (First_Formal (Proc_Id))
15455 then
15456 Typ := Etype (First_Formal (Proc_Id));
15457
15458 if Is_Tagged_Type (Typ)
15459 and then
15460
15461 -- Check for a protected, a synchronized or a task interface
15462
15463 ((Is_Interface (Typ)
15464 and then Is_Synchronized_Interface (Typ))
15465
15466 -- Check for a protected type or a task type that implements
15467 -- an interface.
15468
15469 or else
15470 (Is_Concurrent_Record_Type (Typ)
15471 and then Present (Interfaces (Typ)))
15472
15473 -- In analysis-only mode, examine original protected type
15474
15475 or else
15476 (Nkind (Parent (Typ)) = N_Protected_Type_Declaration
15477 and then Present (Interface_List (Parent (Typ))))
15478
15479 -- Check for a private record extension with keyword
15480 -- "synchronized".
15481
15482 or else
15483 (Ekind_In (Typ, E_Record_Type_With_Private,
15484 E_Record_Subtype_With_Private)
15485 and then Synchronized_Present (Parent (Typ))))
15486 then
15487 null;
15488 else
15489 Error_Pragma_Arg
15490 ("controlling formal must be of synchronized tagged type",
15491 Arg1);
15492 return;
15493 end if;
15494
15495 -- Procedures declared inside a protected type must be accepted
15496
15497 elsif Ekind (Proc_Id) = E_Procedure
15498 and then Is_Protected_Type (Scope (Proc_Id))
15499 then
15500 null;
15501
15502 -- The first argument is not a primitive procedure
15503
15504 else
15505 Error_Pragma_Arg
15506 ("pragma % must be applied to a primitive procedure", Arg1);
15507 return;
15508 end if;
15509
15510 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
15511 -- By_Protected_Procedure to the primitive procedure of a task
15512 -- interface.
15513
15514 if Chars (Arg2) = Name_By_Protected_Procedure
15515 and then Is_Interface (Typ)
15516 and then Is_Task_Interface (Typ)
15517 then
15518 Error_Pragma_Arg
15519 ("implementation kind By_Protected_Procedure cannot be "
15520 & "applied to a task interface primitive", Arg2);
15521 return;
15522 end if;
15523
15524 Record_Rep_Item (Proc_Id, N);
15525 end Implemented;
15526
15527 ----------------------
15528 -- Implicit_Packing --
15529 ----------------------
15530
15531 -- pragma Implicit_Packing;
15532
15533 when Pragma_Implicit_Packing =>
15534 GNAT_Pragma;
15535 Check_Arg_Count (0);
15536 Implicit_Packing := True;
15537
15538 ------------
15539 -- Import --
15540 ------------
15541
15542 -- pragma Import (
15543 -- [Convention =>] convention_IDENTIFIER,
15544 -- [Entity =>] LOCAL_NAME
15545 -- [, [External_Name =>] static_string_EXPRESSION ]
15546 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15547
15548 when Pragma_Import =>
15549 Check_Ada_83_Warning;
15550 Check_Arg_Order
15551 ((Name_Convention,
15552 Name_Entity,
15553 Name_External_Name,
15554 Name_Link_Name));
15555
15556 Check_At_Least_N_Arguments (2);
15557 Check_At_Most_N_Arguments (4);
15558 Process_Import_Or_Interface;
15559
15560 ---------------------
15561 -- Import_Function --
15562 ---------------------
15563
15564 -- pragma Import_Function (
15565 -- [Internal =>] LOCAL_NAME,
15566 -- [, [External =>] EXTERNAL_SYMBOL]
15567 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15568 -- [, [Result_Type =>] SUBTYPE_MARK]
15569 -- [, [Mechanism =>] MECHANISM]
15570 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15571
15572 -- EXTERNAL_SYMBOL ::=
15573 -- IDENTIFIER
15574 -- | static_string_EXPRESSION
15575
15576 -- PARAMETER_TYPES ::=
15577 -- null
15578 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15579
15580 -- TYPE_DESIGNATOR ::=
15581 -- subtype_NAME
15582 -- | subtype_Name ' Access
15583
15584 -- MECHANISM ::=
15585 -- MECHANISM_NAME
15586 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15587
15588 -- MECHANISM_ASSOCIATION ::=
15589 -- [formal_parameter_NAME =>] MECHANISM_NAME
15590
15591 -- MECHANISM_NAME ::=
15592 -- Value
15593 -- | Reference
15594
15595 when Pragma_Import_Function => Import_Function : declare
15596 Args : Args_List (1 .. 6);
15597 Names : constant Name_List (1 .. 6) := (
15598 Name_Internal,
15599 Name_External,
15600 Name_Parameter_Types,
15601 Name_Result_Type,
15602 Name_Mechanism,
15603 Name_Result_Mechanism);
15604
15605 Internal : Node_Id renames Args (1);
15606 External : Node_Id renames Args (2);
15607 Parameter_Types : Node_Id renames Args (3);
15608 Result_Type : Node_Id renames Args (4);
15609 Mechanism : Node_Id renames Args (5);
15610 Result_Mechanism : Node_Id renames Args (6);
15611
15612 begin
15613 GNAT_Pragma;
15614 Gather_Associations (Names, Args);
15615 Process_Extended_Import_Export_Subprogram_Pragma (
15616 Arg_Internal => Internal,
15617 Arg_External => External,
15618 Arg_Parameter_Types => Parameter_Types,
15619 Arg_Result_Type => Result_Type,
15620 Arg_Mechanism => Mechanism,
15621 Arg_Result_Mechanism => Result_Mechanism);
15622 end Import_Function;
15623
15624 -------------------
15625 -- Import_Object --
15626 -------------------
15627
15628 -- pragma Import_Object (
15629 -- [Internal =>] LOCAL_NAME
15630 -- [, [External =>] EXTERNAL_SYMBOL]
15631 -- [, [Size =>] EXTERNAL_SYMBOL]);
15632
15633 -- EXTERNAL_SYMBOL ::=
15634 -- IDENTIFIER
15635 -- | static_string_EXPRESSION
15636
15637 when Pragma_Import_Object => Import_Object : declare
15638 Args : Args_List (1 .. 3);
15639 Names : constant Name_List (1 .. 3) := (
15640 Name_Internal,
15641 Name_External,
15642 Name_Size);
15643
15644 Internal : Node_Id renames Args (1);
15645 External : Node_Id renames Args (2);
15646 Size : Node_Id renames Args (3);
15647
15648 begin
15649 GNAT_Pragma;
15650 Gather_Associations (Names, Args);
15651 Process_Extended_Import_Export_Object_Pragma (
15652 Arg_Internal => Internal,
15653 Arg_External => External,
15654 Arg_Size => Size);
15655 end Import_Object;
15656
15657 ----------------------
15658 -- Import_Procedure --
15659 ----------------------
15660
15661 -- pragma Import_Procedure (
15662 -- [Internal =>] LOCAL_NAME
15663 -- [, [External =>] EXTERNAL_SYMBOL]
15664 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15665 -- [, [Mechanism =>] MECHANISM]);
15666
15667 -- EXTERNAL_SYMBOL ::=
15668 -- IDENTIFIER
15669 -- | static_string_EXPRESSION
15670
15671 -- PARAMETER_TYPES ::=
15672 -- null
15673 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15674
15675 -- TYPE_DESIGNATOR ::=
15676 -- subtype_NAME
15677 -- | subtype_Name ' Access
15678
15679 -- MECHANISM ::=
15680 -- MECHANISM_NAME
15681 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15682
15683 -- MECHANISM_ASSOCIATION ::=
15684 -- [formal_parameter_NAME =>] MECHANISM_NAME
15685
15686 -- MECHANISM_NAME ::=
15687 -- Value
15688 -- | Reference
15689
15690 when Pragma_Import_Procedure => Import_Procedure : declare
15691 Args : Args_List (1 .. 4);
15692 Names : constant Name_List (1 .. 4) := (
15693 Name_Internal,
15694 Name_External,
15695 Name_Parameter_Types,
15696 Name_Mechanism);
15697
15698 Internal : Node_Id renames Args (1);
15699 External : Node_Id renames Args (2);
15700 Parameter_Types : Node_Id renames Args (3);
15701 Mechanism : Node_Id renames Args (4);
15702
15703 begin
15704 GNAT_Pragma;
15705 Gather_Associations (Names, Args);
15706 Process_Extended_Import_Export_Subprogram_Pragma (
15707 Arg_Internal => Internal,
15708 Arg_External => External,
15709 Arg_Parameter_Types => Parameter_Types,
15710 Arg_Mechanism => Mechanism);
15711 end Import_Procedure;
15712
15713 -----------------------------
15714 -- Import_Valued_Procedure --
15715 -----------------------------
15716
15717 -- pragma Import_Valued_Procedure (
15718 -- [Internal =>] LOCAL_NAME
15719 -- [, [External =>] EXTERNAL_SYMBOL]
15720 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15721 -- [, [Mechanism =>] MECHANISM]);
15722
15723 -- EXTERNAL_SYMBOL ::=
15724 -- IDENTIFIER
15725 -- | static_string_EXPRESSION
15726
15727 -- PARAMETER_TYPES ::=
15728 -- null
15729 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15730
15731 -- TYPE_DESIGNATOR ::=
15732 -- subtype_NAME
15733 -- | subtype_Name ' Access
15734
15735 -- MECHANISM ::=
15736 -- MECHANISM_NAME
15737 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15738
15739 -- MECHANISM_ASSOCIATION ::=
15740 -- [formal_parameter_NAME =>] MECHANISM_NAME
15741
15742 -- MECHANISM_NAME ::=
15743 -- Value
15744 -- | Reference
15745
15746 when Pragma_Import_Valued_Procedure =>
15747 Import_Valued_Procedure : declare
15748 Args : Args_List (1 .. 4);
15749 Names : constant Name_List (1 .. 4) := (
15750 Name_Internal,
15751 Name_External,
15752 Name_Parameter_Types,
15753 Name_Mechanism);
15754
15755 Internal : Node_Id renames Args (1);
15756 External : Node_Id renames Args (2);
15757 Parameter_Types : Node_Id renames Args (3);
15758 Mechanism : Node_Id renames Args (4);
15759
15760 begin
15761 GNAT_Pragma;
15762 Gather_Associations (Names, Args);
15763 Process_Extended_Import_Export_Subprogram_Pragma (
15764 Arg_Internal => Internal,
15765 Arg_External => External,
15766 Arg_Parameter_Types => Parameter_Types,
15767 Arg_Mechanism => Mechanism);
15768 end Import_Valued_Procedure;
15769
15770 -----------------
15771 -- Independent --
15772 -----------------
15773
15774 -- pragma Independent (LOCAL_NAME);
15775
15776 when Pragma_Independent =>
15777 Process_Atomic_Independent_Shared_Volatile;
15778
15779 ----------------------------
15780 -- Independent_Components --
15781 ----------------------------
15782
15783 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
15784
15785 when Pragma_Independent_Components => Independent_Components : declare
15786 C : Node_Id;
15787 D : Node_Id;
15788 E_Id : Node_Id;
15789 E : Entity_Id;
15790 K : Node_Kind;
15791
15792 begin
15793 Check_Ada_83_Warning;
15794 Ada_2012_Pragma;
15795 Check_No_Identifiers;
15796 Check_Arg_Count (1);
15797 Check_Arg_Is_Local_Name (Arg1);
15798 E_Id := Get_Pragma_Arg (Arg1);
15799
15800 if Etype (E_Id) = Any_Type then
15801 return;
15802 end if;
15803
15804 E := Entity (E_Id);
15805
15806 -- A pragma that applies to a Ghost entity becomes Ghost for the
15807 -- purposes of legality checks and removal of ignored Ghost code.
15808
15809 Mark_Pragma_As_Ghost (N, E);
15810
15811 -- Check duplicate before we chain ourselves
15812
15813 Check_Duplicate_Pragma (E);
15814
15815 -- Check appropriate entity
15816
15817 if Rep_Item_Too_Early (E, N)
15818 or else
15819 Rep_Item_Too_Late (E, N)
15820 then
15821 return;
15822 end if;
15823
15824 D := Declaration_Node (E);
15825 K := Nkind (D);
15826
15827 -- The flag is set on the base type, or on the object
15828
15829 if K = N_Full_Type_Declaration
15830 and then (Is_Array_Type (E) or else Is_Record_Type (E))
15831 then
15832 Set_Has_Independent_Components (Base_Type (E));
15833 Record_Independence_Check (N, Base_Type (E));
15834
15835 -- For record type, set all components independent
15836
15837 if Is_Record_Type (E) then
15838 C := First_Component (E);
15839 while Present (C) loop
15840 Set_Is_Independent (C);
15841 Next_Component (C);
15842 end loop;
15843 end if;
15844
15845 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15846 and then Nkind (D) = N_Object_Declaration
15847 and then Nkind (Object_Definition (D)) =
15848 N_Constrained_Array_Definition
15849 then
15850 Set_Has_Independent_Components (E);
15851 Record_Independence_Check (N, E);
15852
15853 else
15854 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
15855 end if;
15856 end Independent_Components;
15857
15858 -----------------------
15859 -- Initial_Condition --
15860 -----------------------
15861
15862 -- pragma Initial_Condition (boolean_EXPRESSION);
15863
15864 -- Characteristics:
15865
15866 -- * Analysis - The annotation undergoes initial checks to verify
15867 -- the legal placement and context. Secondary checks preanalyze the
15868 -- expression in:
15869
15870 -- Analyze_Initial_Condition_In_Decl_Part
15871
15872 -- * Expansion - The annotation is expanded during the expansion of
15873 -- the package body whose declaration is subject to the annotation
15874 -- as done in:
15875
15876 -- Expand_Pragma_Initial_Condition
15877
15878 -- * Template - The annotation utilizes the generic template of the
15879 -- related package declaration.
15880
15881 -- * Globals - Capture of global references must occur after full
15882 -- analysis.
15883
15884 -- * Instance - The annotation is instantiated automatically when
15885 -- the related generic package is instantiated.
15886
15887 when Pragma_Initial_Condition => Initial_Condition : declare
15888 Pack_Decl : Node_Id;
15889 Pack_Id : Entity_Id;
15890
15891 begin
15892 GNAT_Pragma;
15893 Check_No_Identifiers;
15894 Check_Arg_Count (1);
15895
15896 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
15897
15898 -- Ensure the proper placement of the pragma. Initial_Condition
15899 -- must be associated with a package declaration.
15900
15901 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
15902 N_Package_Declaration)
15903 then
15904 null;
15905
15906 -- Otherwise the pragma is associated with an illegal context
15907
15908 else
15909 Pragma_Misplaced;
15910 return;
15911 end if;
15912
15913 Pack_Id := Defining_Entity (Pack_Decl);
15914
15915 -- Chain the pragma on the contract for further processing by
15916 -- Analyze_Initial_Condition_In_Decl_Part.
15917
15918 Add_Contract_Item (N, Pack_Id);
15919
15920 -- The legality checks of pragmas Abstract_State, Initializes, and
15921 -- Initial_Condition are affected by the SPARK mode in effect. In
15922 -- addition, these three pragmas are subject to an inherent order:
15923
15924 -- 1) Abstract_State
15925 -- 2) Initializes
15926 -- 3) Initial_Condition
15927
15928 -- Analyze all these pragmas in the order outlined above
15929
15930 Analyze_If_Present (Pragma_SPARK_Mode);
15931 Analyze_If_Present (Pragma_Abstract_State);
15932 Analyze_If_Present (Pragma_Initializes);
15933
15934 -- A pragma that applies to a Ghost entity becomes Ghost for the
15935 -- purposes of legality checks and removal of ignored Ghost code.
15936
15937 Mark_Pragma_As_Ghost (N, Pack_Id);
15938 end Initial_Condition;
15939
15940 ------------------------
15941 -- Initialize_Scalars --
15942 ------------------------
15943
15944 -- pragma Initialize_Scalars;
15945
15946 when Pragma_Initialize_Scalars =>
15947 GNAT_Pragma;
15948 Check_Arg_Count (0);
15949 Check_Valid_Configuration_Pragma;
15950 Check_Restriction (No_Initialize_Scalars, N);
15951
15952 -- Initialize_Scalars creates false positives in CodePeer, and
15953 -- incorrect negative results in GNATprove mode, so ignore this
15954 -- pragma in these modes.
15955
15956 if not Restriction_Active (No_Initialize_Scalars)
15957 and then not (CodePeer_Mode or GNATprove_Mode)
15958 then
15959 Init_Or_Norm_Scalars := True;
15960 Initialize_Scalars := True;
15961 end if;
15962
15963 -----------------
15964 -- Initializes --
15965 -----------------
15966
15967 -- pragma Initializes (INITIALIZATION_LIST);
15968
15969 -- INITIALIZATION_LIST ::=
15970 -- null
15971 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15972
15973 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15974
15975 -- INPUT_LIST ::=
15976 -- null
15977 -- | INPUT
15978 -- | (INPUT {, INPUT})
15979
15980 -- INPUT ::= name
15981
15982 -- Characteristics:
15983
15984 -- * Analysis - The annotation undergoes initial checks to verify
15985 -- the legal placement and context. Secondary checks preanalyze the
15986 -- expression in:
15987
15988 -- Analyze_Initializes_In_Decl_Part
15989
15990 -- * Expansion - None.
15991
15992 -- * Template - The annotation utilizes the generic template of the
15993 -- related package declaration.
15994
15995 -- * Globals - Capture of global references must occur after full
15996 -- analysis.
15997
15998 -- * Instance - The annotation is instantiated automatically when
15999 -- the related generic package is instantiated.
16000
16001 when Pragma_Initializes => Initializes : declare
16002 Pack_Decl : Node_Id;
16003 Pack_Id : Entity_Id;
16004
16005 begin
16006 GNAT_Pragma;
16007 Check_No_Identifiers;
16008 Check_Arg_Count (1);
16009
16010 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
16011
16012 -- Ensure the proper placement of the pragma. Initializes must be
16013 -- associated with a package declaration.
16014
16015 if Nkind_In (Pack_Decl, N_Generic_Package_Declaration,
16016 N_Package_Declaration)
16017 then
16018 null;
16019
16020 -- Otherwise the pragma is associated with an illegal construc
16021
16022 else
16023 Pragma_Misplaced;
16024 return;
16025 end if;
16026
16027 Pack_Id := Defining_Entity (Pack_Decl);
16028
16029 -- Chain the pragma on the contract for further processing by
16030 -- Analyze_Initializes_In_Decl_Part.
16031
16032 Add_Contract_Item (N, Pack_Id);
16033
16034 -- The legality checks of pragmas Abstract_State, Initializes, and
16035 -- Initial_Condition are affected by the SPARK mode in effect. In
16036 -- addition, these three pragmas are subject to an inherent order:
16037
16038 -- 1) Abstract_State
16039 -- 2) Initializes
16040 -- 3) Initial_Condition
16041
16042 -- Analyze all these pragmas in the order outlined above
16043
16044 Analyze_If_Present (Pragma_SPARK_Mode);
16045 Analyze_If_Present (Pragma_Abstract_State);
16046
16047 -- A pragma that applies to a Ghost entity becomes Ghost for the
16048 -- purposes of legality checks and removal of ignored Ghost code.
16049
16050 Mark_Pragma_As_Ghost (N, Pack_Id);
16051 Ensure_Aggregate_Form (Get_Argument (N, Pack_Id));
16052
16053 Analyze_If_Present (Pragma_Initial_Condition);
16054 end Initializes;
16055
16056 ------------
16057 -- Inline --
16058 ------------
16059
16060 -- pragma Inline ( NAME {, NAME} );
16061
16062 when Pragma_Inline =>
16063
16064 -- Pragma always active unless in GNATprove mode. It is disabled
16065 -- in GNATprove mode because frontend inlining is applied
16066 -- independently of pragmas Inline and Inline_Always for
16067 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
16068 -- in inline.ads.
16069
16070 if not GNATprove_Mode then
16071
16072 -- Inline status is Enabled if inlining option is active
16073
16074 if Inline_Active then
16075 Process_Inline (Enabled);
16076 else
16077 Process_Inline (Disabled);
16078 end if;
16079 end if;
16080
16081 -------------------
16082 -- Inline_Always --
16083 -------------------
16084
16085 -- pragma Inline_Always ( NAME {, NAME} );
16086
16087 when Pragma_Inline_Always =>
16088 GNAT_Pragma;
16089
16090 -- Pragma always active unless in CodePeer mode or GNATprove
16091 -- mode. It is disabled in CodePeer mode because inlining is
16092 -- not helpful, and enabling it caused walk order issues. It
16093 -- is disabled in GNATprove mode because frontend inlining is
16094 -- applied independently of pragmas Inline and Inline_Always for
16095 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
16096 -- inline.ads.
16097
16098 if not CodePeer_Mode and not GNATprove_Mode then
16099 Process_Inline (Enabled);
16100 end if;
16101
16102 --------------------
16103 -- Inline_Generic --
16104 --------------------
16105
16106 -- pragma Inline_Generic (NAME {, NAME});
16107
16108 when Pragma_Inline_Generic =>
16109 GNAT_Pragma;
16110 Process_Generic_List;
16111
16112 ----------------------
16113 -- Inspection_Point --
16114 ----------------------
16115
16116 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
16117
16118 when Pragma_Inspection_Point => Inspection_Point : declare
16119 Arg : Node_Id;
16120 Exp : Node_Id;
16121
16122 begin
16123 ip;
16124
16125 if Arg_Count > 0 then
16126 Arg := Arg1;
16127 loop
16128 Exp := Get_Pragma_Arg (Arg);
16129 Analyze (Exp);
16130
16131 if not Is_Entity_Name (Exp)
16132 or else not Is_Object (Entity (Exp))
16133 then
16134 Error_Pragma_Arg ("object name required", Arg);
16135 end if;
16136
16137 Next (Arg);
16138 exit when No (Arg);
16139 end loop;
16140 end if;
16141 end Inspection_Point;
16142
16143 ---------------
16144 -- Interface --
16145 ---------------
16146
16147 -- pragma Interface (
16148 -- [ Convention =>] convention_IDENTIFIER,
16149 -- [ Entity =>] LOCAL_NAME
16150 -- [, [External_Name =>] static_string_EXPRESSION ]
16151 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16152
16153 when Pragma_Interface =>
16154 GNAT_Pragma;
16155 Check_Arg_Order
16156 ((Name_Convention,
16157 Name_Entity,
16158 Name_External_Name,
16159 Name_Link_Name));
16160 Check_At_Least_N_Arguments (2);
16161 Check_At_Most_N_Arguments (4);
16162 Process_Import_Or_Interface;
16163
16164 -- In Ada 2005, the permission to use Interface (a reserved word)
16165 -- as a pragma name is considered an obsolescent feature, and this
16166 -- pragma was already obsolescent in Ada 95.
16167
16168 if Ada_Version >= Ada_95 then
16169 Check_Restriction
16170 (No_Obsolescent_Features, Pragma_Identifier (N));
16171
16172 if Warn_On_Obsolescent_Feature then
16173 Error_Msg_N
16174 ("pragma Interface is an obsolescent feature?j?", N);
16175 Error_Msg_N
16176 ("|use pragma Import instead?j?", N);
16177 end if;
16178 end if;
16179
16180 --------------------
16181 -- Interface_Name --
16182 --------------------
16183
16184 -- pragma Interface_Name (
16185 -- [ Entity =>] LOCAL_NAME
16186 -- [,[External_Name =>] static_string_EXPRESSION ]
16187 -- [,[Link_Name =>] static_string_EXPRESSION ]);
16188
16189 when Pragma_Interface_Name => Interface_Name : declare
16190 Id : Node_Id;
16191 Def_Id : Entity_Id;
16192 Hom_Id : Entity_Id;
16193 Found : Boolean;
16194
16195 begin
16196 GNAT_Pragma;
16197 Check_Arg_Order
16198 ((Name_Entity, Name_External_Name, Name_Link_Name));
16199 Check_At_Least_N_Arguments (2);
16200 Check_At_Most_N_Arguments (3);
16201 Id := Get_Pragma_Arg (Arg1);
16202 Analyze (Id);
16203
16204 -- This is obsolete from Ada 95 on, but it is an implementation
16205 -- defined pragma, so we do not consider that it violates the
16206 -- restriction (No_Obsolescent_Features).
16207
16208 if Ada_Version >= Ada_95 then
16209 if Warn_On_Obsolescent_Feature then
16210 Error_Msg_N
16211 ("pragma Interface_Name is an obsolescent feature?j?", N);
16212 Error_Msg_N
16213 ("|use pragma Import instead?j?", N);
16214 end if;
16215 end if;
16216
16217 if not Is_Entity_Name (Id) then
16218 Error_Pragma_Arg
16219 ("first argument for pragma% must be entity name", Arg1);
16220 elsif Etype (Id) = Any_Type then
16221 return;
16222 else
16223 Def_Id := Entity (Id);
16224 end if;
16225
16226 -- Special DEC-compatible processing for the object case, forces
16227 -- object to be imported.
16228
16229 if Ekind (Def_Id) = E_Variable then
16230 Kill_Size_Check_Code (Def_Id);
16231 Note_Possible_Modification (Id, Sure => False);
16232
16233 -- Initialization is not allowed for imported variable
16234
16235 if Present (Expression (Parent (Def_Id)))
16236 and then Comes_From_Source (Expression (Parent (Def_Id)))
16237 then
16238 Error_Msg_Sloc := Sloc (Def_Id);
16239 Error_Pragma_Arg
16240 ("no initialization allowed for declaration of& #",
16241 Arg2);
16242
16243 else
16244 -- For compatibility, support VADS usage of providing both
16245 -- pragmas Interface and Interface_Name to obtain the effect
16246 -- of a single Import pragma.
16247
16248 if Is_Imported (Def_Id)
16249 and then Present (First_Rep_Item (Def_Id))
16250 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
16251 and then
16252 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
16253 then
16254 null;
16255 else
16256 Set_Imported (Def_Id);
16257 end if;
16258
16259 Set_Is_Public (Def_Id);
16260 Process_Interface_Name (Def_Id, Arg2, Arg3);
16261 end if;
16262
16263 -- Otherwise must be subprogram
16264
16265 elsif not Is_Subprogram (Def_Id) then
16266 Error_Pragma_Arg
16267 ("argument of pragma% is not subprogram", Arg1);
16268
16269 else
16270 Check_At_Most_N_Arguments (3);
16271 Hom_Id := Def_Id;
16272 Found := False;
16273
16274 -- Loop through homonyms
16275
16276 loop
16277 Def_Id := Get_Base_Subprogram (Hom_Id);
16278
16279 if Is_Imported (Def_Id) then
16280 Process_Interface_Name (Def_Id, Arg2, Arg3);
16281 Found := True;
16282 end if;
16283
16284 exit when From_Aspect_Specification (N);
16285 Hom_Id := Homonym (Hom_Id);
16286
16287 exit when No (Hom_Id)
16288 or else Scope (Hom_Id) /= Current_Scope;
16289 end loop;
16290
16291 if not Found then
16292 Error_Pragma_Arg
16293 ("argument of pragma% is not imported subprogram",
16294 Arg1);
16295 end if;
16296 end if;
16297 end Interface_Name;
16298
16299 -----------------------
16300 -- Interrupt_Handler --
16301 -----------------------
16302
16303 -- pragma Interrupt_Handler (handler_NAME);
16304
16305 when Pragma_Interrupt_Handler =>
16306 Check_Ada_83_Warning;
16307 Check_Arg_Count (1);
16308 Check_No_Identifiers;
16309
16310 if No_Run_Time_Mode then
16311 Error_Msg_CRT ("Interrupt_Handler pragma", N);
16312 else
16313 Check_Interrupt_Or_Attach_Handler;
16314 Process_Interrupt_Or_Attach_Handler;
16315 end if;
16316
16317 ------------------------
16318 -- Interrupt_Priority --
16319 ------------------------
16320
16321 -- pragma Interrupt_Priority [(EXPRESSION)];
16322
16323 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
16324 P : constant Node_Id := Parent (N);
16325 Arg : Node_Id;
16326 Ent : Entity_Id;
16327
16328 begin
16329 Check_Ada_83_Warning;
16330
16331 if Arg_Count /= 0 then
16332 Arg := Get_Pragma_Arg (Arg1);
16333 Check_Arg_Count (1);
16334 Check_No_Identifiers;
16335
16336 -- The expression must be analyzed in the special manner
16337 -- described in "Handling of Default and Per-Object
16338 -- Expressions" in sem.ads.
16339
16340 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
16341 end if;
16342
16343 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
16344 Pragma_Misplaced;
16345 return;
16346
16347 else
16348 Ent := Defining_Identifier (Parent (P));
16349
16350 -- Check duplicate pragma before we chain the pragma in the Rep
16351 -- Item chain of Ent.
16352
16353 Check_Duplicate_Pragma (Ent);
16354 Record_Rep_Item (Ent, N);
16355
16356 -- Check the No_Task_At_Interrupt_Priority restriction
16357
16358 if Nkind (P) = N_Task_Definition then
16359 Check_Restriction (No_Task_At_Interrupt_Priority, N);
16360 end if;
16361 end if;
16362 end Interrupt_Priority;
16363
16364 ---------------------
16365 -- Interrupt_State --
16366 ---------------------
16367
16368 -- pragma Interrupt_State (
16369 -- [Name =>] INTERRUPT_ID,
16370 -- [State =>] INTERRUPT_STATE);
16371
16372 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16373 -- INTERRUPT_STATE => System | Runtime | User
16374
16375 -- Note: if the interrupt id is given as an identifier, then it must
16376 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16377 -- given as a static integer expression which must be in the range of
16378 -- Ada.Interrupts.Interrupt_ID.
16379
16380 when Pragma_Interrupt_State => Interrupt_State : declare
16381 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
16382 -- This is the entity Ada.Interrupts.Interrupt_ID;
16383
16384 State_Type : Character;
16385 -- Set to 's'/'r'/'u' for System/Runtime/User
16386
16387 IST_Num : Pos;
16388 -- Index to entry in Interrupt_States table
16389
16390 Int_Val : Uint;
16391 -- Value of interrupt
16392
16393 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
16394 -- The first argument to the pragma
16395
16396 Int_Ent : Entity_Id;
16397 -- Interrupt entity in Ada.Interrupts.Names
16398
16399 begin
16400 GNAT_Pragma;
16401 Check_Arg_Order ((Name_Name, Name_State));
16402 Check_Arg_Count (2);
16403
16404 Check_Optional_Identifier (Arg1, Name_Name);
16405 Check_Optional_Identifier (Arg2, Name_State);
16406 Check_Arg_Is_Identifier (Arg2);
16407
16408 -- First argument is identifier
16409
16410 if Nkind (Arg1X) = N_Identifier then
16411
16412 -- Search list of names in Ada.Interrupts.Names
16413
16414 Int_Ent := First_Entity (RTE (RE_Names));
16415 loop
16416 if No (Int_Ent) then
16417 Error_Pragma_Arg ("invalid interrupt name", Arg1);
16418
16419 elsif Chars (Int_Ent) = Chars (Arg1X) then
16420 Int_Val := Expr_Value (Constant_Value (Int_Ent));
16421 exit;
16422 end if;
16423
16424 Next_Entity (Int_Ent);
16425 end loop;
16426
16427 -- First argument is not an identifier, so it must be a static
16428 -- expression of type Ada.Interrupts.Interrupt_ID.
16429
16430 else
16431 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
16432 Int_Val := Expr_Value (Arg1X);
16433
16434 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
16435 or else
16436 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
16437 then
16438 Error_Pragma_Arg
16439 ("value not in range of type "
16440 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
16441 end if;
16442 end if;
16443
16444 -- Check OK state
16445
16446 case Chars (Get_Pragma_Arg (Arg2)) is
16447 when Name_Runtime => State_Type := 'r';
16448 when Name_System => State_Type := 's';
16449 when Name_User => State_Type := 'u';
16450
16451 when others =>
16452 Error_Pragma_Arg ("invalid interrupt state", Arg2);
16453 end case;
16454
16455 -- Check if entry is already stored
16456
16457 IST_Num := Interrupt_States.First;
16458 loop
16459 -- If entry not found, add it
16460
16461 if IST_Num > Interrupt_States.Last then
16462 Interrupt_States.Append
16463 ((Interrupt_Number => UI_To_Int (Int_Val),
16464 Interrupt_State => State_Type,
16465 Pragma_Loc => Loc));
16466 exit;
16467
16468 -- Case of entry for the same entry
16469
16470 elsif Int_Val = Interrupt_States.Table (IST_Num).
16471 Interrupt_Number
16472 then
16473 -- If state matches, done, no need to make redundant entry
16474
16475 exit when
16476 State_Type = Interrupt_States.Table (IST_Num).
16477 Interrupt_State;
16478
16479 -- Otherwise if state does not match, error
16480
16481 Error_Msg_Sloc :=
16482 Interrupt_States.Table (IST_Num).Pragma_Loc;
16483 Error_Pragma_Arg
16484 ("state conflicts with that given #", Arg2);
16485 exit;
16486 end if;
16487
16488 IST_Num := IST_Num + 1;
16489 end loop;
16490 end Interrupt_State;
16491
16492 ---------------
16493 -- Invariant --
16494 ---------------
16495
16496 -- pragma Invariant
16497 -- ([Entity =>] type_LOCAL_NAME,
16498 -- [Check =>] EXPRESSION
16499 -- [,[Message =>] String_Expression]);
16500
16501 when Pragma_Invariant => Invariant : declare
16502 Discard : Boolean;
16503 Typ : Entity_Id;
16504 Typ_Arg : Node_Id;
16505
16506 CRec_Typ : Entity_Id;
16507 -- The corresponding record type of Full_Typ
16508
16509 Full_Base : Entity_Id;
16510 -- The base type of Full_Typ
16511
16512 Full_Typ : Entity_Id;
16513 -- The full view of Typ
16514
16515 Priv_Typ : Entity_Id;
16516 -- The partial view of Typ
16517
16518 begin
16519 GNAT_Pragma;
16520 Check_At_Least_N_Arguments (2);
16521 Check_At_Most_N_Arguments (3);
16522 Check_Optional_Identifier (Arg1, Name_Entity);
16523 Check_Optional_Identifier (Arg2, Name_Check);
16524
16525 if Arg_Count = 3 then
16526 Check_Optional_Identifier (Arg3, Name_Message);
16527 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
16528 end if;
16529
16530 Check_Arg_Is_Local_Name (Arg1);
16531
16532 Typ_Arg := Get_Pragma_Arg (Arg1);
16533 Find_Type (Typ_Arg);
16534 Typ := Entity (Typ_Arg);
16535
16536 -- Nothing to do of the related type is erroneous in some way
16537
16538 if Typ = Any_Type then
16539 return;
16540
16541 -- AI12-0041: Invariants are allowed in interface types
16542
16543 elsif Is_Interface (Typ) then
16544 null;
16545
16546 -- An invariant must apply to a private type, or appear in the
16547 -- private part of a package spec and apply to a completion.
16548 -- a class-wide invariant can only appear on a private declaration
16549 -- or private extension, not a completion.
16550
16551 -- A [class-wide] invariant may be associated a [limited] private
16552 -- type or a private extension.
16553
16554 elsif Ekind_In (Typ, E_Limited_Private_Type,
16555 E_Private_Type,
16556 E_Record_Type_With_Private)
16557 then
16558 null;
16559
16560 -- A non-class-wide invariant may be associated with the full view
16561 -- of a [limited] private type or a private extension.
16562
16563 elsif Has_Private_Declaration (Typ)
16564 and then not Class_Present (N)
16565 then
16566 null;
16567
16568 -- A class-wide invariant may appear on the partial view only
16569
16570 elsif Class_Present (N) then
16571 Error_Pragma_Arg
16572 ("pragma % only allowed for private type", Arg1);
16573 return;
16574
16575 -- A regular invariant may appear on both views
16576
16577 else
16578 Error_Pragma_Arg
16579 ("pragma % only allowed for private type or corresponding "
16580 & "full view", Arg1);
16581 return;
16582 end if;
16583
16584 -- An invariant associated with an abstract type (this includes
16585 -- interfaces) must be class-wide.
16586
16587 if Is_Abstract_Type (Typ) and then not Class_Present (N) then
16588 Error_Pragma_Arg
16589 ("pragma % not allowed for abstract type", Arg1);
16590 return;
16591 end if;
16592
16593 -- A pragma that applies to a Ghost entity becomes Ghost for the
16594 -- purposes of legality checks and removal of ignored Ghost code.
16595
16596 Mark_Pragma_As_Ghost (N, Typ);
16597
16598 -- The pragma defines a type-specific invariant, the type is said
16599 -- to have invariants of its "own".
16600
16601 Set_Has_Own_Invariants (Typ);
16602
16603 -- If the invariant is class-wide, then it can be inherited by
16604 -- derived or interface implementing types. The type is said to
16605 -- have "inheritable" invariants.
16606
16607 if Class_Present (N) then
16608 Set_Has_Inheritable_Invariants (Typ);
16609 end if;
16610
16611 Get_Views (Typ, Priv_Typ, Full_Typ, Full_Base, CRec_Typ);
16612
16613 -- Propagate invariant-related attributes to all views of the type
16614 -- and any additional types that may have been created.
16615
16616 Propagate_Invariant_Attributes (Priv_Typ, From_Typ => Typ);
16617 Propagate_Invariant_Attributes (Full_Typ, From_Typ => Typ);
16618 Propagate_Invariant_Attributes (Full_Base, From_Typ => Typ);
16619 Propagate_Invariant_Attributes (CRec_Typ, From_Typ => Typ);
16620
16621 -- Chain the pragma on to the rep item chain, for processing when
16622 -- the type is frozen.
16623
16624 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
16625
16626 -- Create the declaration of the invariant procedure which will
16627 -- verify the invariant at run-time. Note that interfaces do not
16628 -- carry such a declaration.
16629
16630 Build_Invariant_Procedure_Declaration (Typ);
16631 end Invariant;
16632
16633 ----------------
16634 -- Keep_Names --
16635 ----------------
16636
16637 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16638
16639 when Pragma_Keep_Names => Keep_Names : declare
16640 Arg : Node_Id;
16641
16642 begin
16643 GNAT_Pragma;
16644 Check_Arg_Count (1);
16645 Check_Optional_Identifier (Arg1, Name_On);
16646 Check_Arg_Is_Local_Name (Arg1);
16647
16648 Arg := Get_Pragma_Arg (Arg1);
16649 Analyze (Arg);
16650
16651 if Etype (Arg) = Any_Type then
16652 return;
16653 end if;
16654
16655 if not Is_Entity_Name (Arg)
16656 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
16657 then
16658 Error_Pragma_Arg
16659 ("pragma% requires a local enumeration type", Arg1);
16660 end if;
16661
16662 Set_Discard_Names (Entity (Arg), False);
16663 end Keep_Names;
16664
16665 -------------
16666 -- License --
16667 -------------
16668
16669 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16670
16671 when Pragma_License =>
16672 GNAT_Pragma;
16673
16674 -- Do not analyze pragma any further in CodePeer mode, to avoid
16675 -- extraneous errors in this implementation-dependent pragma,
16676 -- which has a different profile on other compilers.
16677
16678 if CodePeer_Mode then
16679 return;
16680 end if;
16681
16682 Check_Arg_Count (1);
16683 Check_No_Identifiers;
16684 Check_Valid_Configuration_Pragma;
16685 Check_Arg_Is_Identifier (Arg1);
16686
16687 declare
16688 Sind : constant Source_File_Index :=
16689 Source_Index (Current_Sem_Unit);
16690
16691 begin
16692 case Chars (Get_Pragma_Arg (Arg1)) is
16693 when Name_GPL =>
16694 Set_License (Sind, GPL);
16695
16696 when Name_Modified_GPL =>
16697 Set_License (Sind, Modified_GPL);
16698
16699 when Name_Restricted =>
16700 Set_License (Sind, Restricted);
16701
16702 when Name_Unrestricted =>
16703 Set_License (Sind, Unrestricted);
16704
16705 when others =>
16706 Error_Pragma_Arg ("invalid license name", Arg1);
16707 end case;
16708 end;
16709
16710 ---------------
16711 -- Link_With --
16712 ---------------
16713
16714 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16715
16716 when Pragma_Link_With => Link_With : declare
16717 Arg : Node_Id;
16718
16719 begin
16720 GNAT_Pragma;
16721
16722 if Operating_Mode = Generate_Code
16723 and then In_Extended_Main_Source_Unit (N)
16724 then
16725 Check_At_Least_N_Arguments (1);
16726 Check_No_Identifiers;
16727 Check_Is_In_Decl_Part_Or_Package_Spec;
16728 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16729 Start_String;
16730
16731 Arg := Arg1;
16732 while Present (Arg) loop
16733 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16734
16735 -- Store argument, converting sequences of spaces to a
16736 -- single null character (this is one of the differences
16737 -- in processing between Link_With and Linker_Options).
16738
16739 Arg_Store : declare
16740 C : constant Char_Code := Get_Char_Code (' ');
16741 S : constant String_Id :=
16742 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
16743 L : constant Nat := String_Length (S);
16744 F : Nat := 1;
16745
16746 procedure Skip_Spaces;
16747 -- Advance F past any spaces
16748
16749 -----------------
16750 -- Skip_Spaces --
16751 -----------------
16752
16753 procedure Skip_Spaces is
16754 begin
16755 while F <= L and then Get_String_Char (S, F) = C loop
16756 F := F + 1;
16757 end loop;
16758 end Skip_Spaces;
16759
16760 -- Start of processing for Arg_Store
16761
16762 begin
16763 Skip_Spaces; -- skip leading spaces
16764
16765 -- Loop through characters, changing any embedded
16766 -- sequence of spaces to a single null character (this
16767 -- is how Link_With/Linker_Options differ)
16768
16769 while F <= L loop
16770 if Get_String_Char (S, F) = C then
16771 Skip_Spaces;
16772 exit when F > L;
16773 Store_String_Char (ASCII.NUL);
16774
16775 else
16776 Store_String_Char (Get_String_Char (S, F));
16777 F := F + 1;
16778 end if;
16779 end loop;
16780 end Arg_Store;
16781
16782 Arg := Next (Arg);
16783
16784 if Present (Arg) then
16785 Store_String_Char (ASCII.NUL);
16786 end if;
16787 end loop;
16788
16789 Store_Linker_Option_String (End_String);
16790 end if;
16791 end Link_With;
16792
16793 ------------------
16794 -- Linker_Alias --
16795 ------------------
16796
16797 -- pragma Linker_Alias (
16798 -- [Entity =>] LOCAL_NAME
16799 -- [Target =>] static_string_EXPRESSION);
16800
16801 when Pragma_Linker_Alias =>
16802 GNAT_Pragma;
16803 Check_Arg_Order ((Name_Entity, Name_Target));
16804 Check_Arg_Count (2);
16805 Check_Optional_Identifier (Arg1, Name_Entity);
16806 Check_Optional_Identifier (Arg2, Name_Target);
16807 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16808 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16809
16810 -- The only processing required is to link this item on to the
16811 -- list of rep items for the given entity. This is accomplished
16812 -- by the call to Rep_Item_Too_Late (when no error is detected
16813 -- and False is returned).
16814
16815 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16816 return;
16817 else
16818 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16819 end if;
16820
16821 ------------------------
16822 -- Linker_Constructor --
16823 ------------------------
16824
16825 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16826
16827 -- Code is shared with Linker_Destructor
16828
16829 -----------------------
16830 -- Linker_Destructor --
16831 -----------------------
16832
16833 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16834
16835 when Pragma_Linker_Constructor |
16836 Pragma_Linker_Destructor =>
16837 Linker_Constructor : declare
16838 Arg1_X : Node_Id;
16839 Proc : Entity_Id;
16840
16841 begin
16842 GNAT_Pragma;
16843 Check_Arg_Count (1);
16844 Check_No_Identifiers;
16845 Check_Arg_Is_Local_Name (Arg1);
16846 Arg1_X := Get_Pragma_Arg (Arg1);
16847 Analyze (Arg1_X);
16848 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16849
16850 if not Is_Library_Level_Entity (Proc) then
16851 Error_Pragma_Arg
16852 ("argument for pragma% must be library level entity", Arg1);
16853 end if;
16854
16855 -- The only processing required is to link this item on to the
16856 -- list of rep items for the given entity. This is accomplished
16857 -- by the call to Rep_Item_Too_Late (when no error is detected
16858 -- and False is returned).
16859
16860 if Rep_Item_Too_Late (Proc, N) then
16861 return;
16862 else
16863 Set_Has_Gigi_Rep_Item (Proc);
16864 end if;
16865 end Linker_Constructor;
16866
16867 --------------------
16868 -- Linker_Options --
16869 --------------------
16870
16871 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16872
16873 when Pragma_Linker_Options => Linker_Options : declare
16874 Arg : Node_Id;
16875
16876 begin
16877 Check_Ada_83_Warning;
16878 Check_No_Identifiers;
16879 Check_Arg_Count (1);
16880 Check_Is_In_Decl_Part_Or_Package_Spec;
16881 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16882 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
16883
16884 Arg := Arg2;
16885 while Present (Arg) loop
16886 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16887 Store_String_Char (ASCII.NUL);
16888 Store_String_Chars
16889 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16890 Arg := Next (Arg);
16891 end loop;
16892
16893 if Operating_Mode = Generate_Code
16894 and then In_Extended_Main_Source_Unit (N)
16895 then
16896 Store_Linker_Option_String (End_String);
16897 end if;
16898 end Linker_Options;
16899
16900 --------------------
16901 -- Linker_Section --
16902 --------------------
16903
16904 -- pragma Linker_Section (
16905 -- [Entity =>] LOCAL_NAME
16906 -- [Section =>] static_string_EXPRESSION);
16907
16908 when Pragma_Linker_Section => Linker_Section : declare
16909 Arg : Node_Id;
16910 Ent : Entity_Id;
16911 LPE : Node_Id;
16912
16913 Ghost_Error_Posted : Boolean := False;
16914 -- Flag set when an error concerning the illegal mix of Ghost and
16915 -- non-Ghost subprograms is emitted.
16916
16917 Ghost_Id : Entity_Id := Empty;
16918 -- The entity of the first Ghost subprogram encountered while
16919 -- processing the arguments of the pragma.
16920
16921 begin
16922 GNAT_Pragma;
16923 Check_Arg_Order ((Name_Entity, Name_Section));
16924 Check_Arg_Count (2);
16925 Check_Optional_Identifier (Arg1, Name_Entity);
16926 Check_Optional_Identifier (Arg2, Name_Section);
16927 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16928 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16929
16930 -- Check kind of entity
16931
16932 Arg := Get_Pragma_Arg (Arg1);
16933 Ent := Entity (Arg);
16934
16935 case Ekind (Ent) is
16936
16937 -- Objects (constants and variables) and types. For these cases
16938 -- all we need to do is to set the Linker_Section_pragma field,
16939 -- checking that we do not have a duplicate.
16940
16941 when E_Constant | E_Variable | Type_Kind =>
16942 LPE := Linker_Section_Pragma (Ent);
16943
16944 if Present (LPE) then
16945 Error_Msg_Sloc := Sloc (LPE);
16946 Error_Msg_NE
16947 ("Linker_Section already specified for &#", Arg1, Ent);
16948 end if;
16949
16950 Set_Linker_Section_Pragma (Ent, N);
16951
16952 -- A pragma that applies to a Ghost entity becomes Ghost for
16953 -- the purposes of legality checks and removal of ignored
16954 -- Ghost code.
16955
16956 Mark_Pragma_As_Ghost (N, Ent);
16957
16958 -- Subprograms
16959
16960 when Subprogram_Kind =>
16961
16962 -- Aspect case, entity already set
16963
16964 if From_Aspect_Specification (N) then
16965 Set_Linker_Section_Pragma
16966 (Entity (Corresponding_Aspect (N)), N);
16967
16968 -- Pragma case, we must climb the homonym chain, but skip
16969 -- any for which the linker section is already set.
16970
16971 else
16972 loop
16973 if No (Linker_Section_Pragma (Ent)) then
16974 Set_Linker_Section_Pragma (Ent, N);
16975
16976 -- A pragma that applies to a Ghost entity becomes
16977 -- Ghost for the purposes of legality checks and
16978 -- removal of ignored Ghost code.
16979
16980 Mark_Pragma_As_Ghost (N, Ent);
16981
16982 -- Capture the entity of the first Ghost subprogram
16983 -- being processed for error detection purposes.
16984
16985 if Is_Ghost_Entity (Ent) then
16986 if No (Ghost_Id) then
16987 Ghost_Id := Ent;
16988 end if;
16989
16990 -- Otherwise the subprogram is non-Ghost. It is
16991 -- illegal to mix references to Ghost and non-Ghost
16992 -- entities (SPARK RM 6.9).
16993
16994 elsif Present (Ghost_Id)
16995 and then not Ghost_Error_Posted
16996 then
16997 Ghost_Error_Posted := True;
16998
16999 Error_Msg_Name_1 := Pname;
17000 Error_Msg_N
17001 ("pragma % cannot mention ghost and "
17002 & "non-ghost subprograms", N);
17003
17004 Error_Msg_Sloc := Sloc (Ghost_Id);
17005 Error_Msg_NE
17006 ("\& # declared as ghost", N, Ghost_Id);
17007
17008 Error_Msg_Sloc := Sloc (Ent);
17009 Error_Msg_NE
17010 ("\& # declared as non-ghost", N, Ent);
17011 end if;
17012 end if;
17013
17014 Ent := Homonym (Ent);
17015 exit when No (Ent)
17016 or else Scope (Ent) /= Current_Scope;
17017 end loop;
17018 end if;
17019
17020 -- All other cases are illegal
17021
17022 when others =>
17023 Error_Pragma_Arg
17024 ("pragma% applies only to objects, subprograms, and types",
17025 Arg1);
17026 end case;
17027 end Linker_Section;
17028
17029 ----------
17030 -- List --
17031 ----------
17032
17033 -- pragma List (On | Off)
17034
17035 -- There is nothing to do here, since we did all the processing for
17036 -- this pragma in Par.Prag (so that it works properly even in syntax
17037 -- only mode).
17038
17039 when Pragma_List =>
17040 null;
17041
17042 ---------------
17043 -- Lock_Free --
17044 ---------------
17045
17046 -- pragma Lock_Free [(Boolean_EXPRESSION)];
17047
17048 when Pragma_Lock_Free => Lock_Free : declare
17049 P : constant Node_Id := Parent (N);
17050 Arg : Node_Id;
17051 Ent : Entity_Id;
17052 Val : Boolean;
17053
17054 begin
17055 Check_No_Identifiers;
17056 Check_At_Most_N_Arguments (1);
17057
17058 -- Protected definition case
17059
17060 if Nkind (P) = N_Protected_Definition then
17061 Ent := Defining_Identifier (Parent (P));
17062
17063 -- One argument
17064
17065 if Arg_Count = 1 then
17066 Arg := Get_Pragma_Arg (Arg1);
17067 Val := Is_True (Static_Boolean (Arg));
17068
17069 -- No arguments (expression is considered to be True)
17070
17071 else
17072 Val := True;
17073 end if;
17074
17075 -- Check duplicate pragma before we chain the pragma in the Rep
17076 -- Item chain of Ent.
17077
17078 Check_Duplicate_Pragma (Ent);
17079 Record_Rep_Item (Ent, N);
17080 Set_Uses_Lock_Free (Ent, Val);
17081
17082 -- Anything else is incorrect placement
17083
17084 else
17085 Pragma_Misplaced;
17086 end if;
17087 end Lock_Free;
17088
17089 --------------------
17090 -- Locking_Policy --
17091 --------------------
17092
17093 -- pragma Locking_Policy (policy_IDENTIFIER);
17094
17095 when Pragma_Locking_Policy => declare
17096 subtype LP_Range is Name_Id
17097 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
17098 LP_Val : LP_Range;
17099 LP : Character;
17100
17101 begin
17102 Check_Ada_83_Warning;
17103 Check_Arg_Count (1);
17104 Check_No_Identifiers;
17105 Check_Arg_Is_Locking_Policy (Arg1);
17106 Check_Valid_Configuration_Pragma;
17107 LP_Val := Chars (Get_Pragma_Arg (Arg1));
17108
17109 case LP_Val is
17110 when Name_Ceiling_Locking =>
17111 LP := 'C';
17112 when Name_Inheritance_Locking =>
17113 LP := 'I';
17114 when Name_Concurrent_Readers_Locking =>
17115 LP := 'R';
17116 end case;
17117
17118 if Locking_Policy /= ' '
17119 and then Locking_Policy /= LP
17120 then
17121 Error_Msg_Sloc := Locking_Policy_Sloc;
17122 Error_Pragma ("locking policy incompatible with policy#");
17123
17124 -- Set new policy, but always preserve System_Location since we
17125 -- like the error message with the run time name.
17126
17127 else
17128 Locking_Policy := LP;
17129
17130 if Locking_Policy_Sloc /= System_Location then
17131 Locking_Policy_Sloc := Loc;
17132 end if;
17133 end if;
17134 end;
17135
17136 -------------------
17137 -- Loop_Optimize --
17138 -------------------
17139
17140 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
17141
17142 -- OPTIMIZATION_HINT ::=
17143 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
17144
17145 when Pragma_Loop_Optimize => Loop_Optimize : declare
17146 Hint : Node_Id;
17147
17148 begin
17149 GNAT_Pragma;
17150 Check_At_Least_N_Arguments (1);
17151 Check_No_Identifiers;
17152
17153 Hint := First (Pragma_Argument_Associations (N));
17154 while Present (Hint) loop
17155 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
17156 Name_No_Unroll,
17157 Name_Unroll,
17158 Name_No_Vector,
17159 Name_Vector);
17160 Next (Hint);
17161 end loop;
17162
17163 Check_Loop_Pragma_Placement;
17164 end Loop_Optimize;
17165
17166 ------------------
17167 -- Loop_Variant --
17168 ------------------
17169
17170 -- pragma Loop_Variant
17171 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
17172
17173 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
17174
17175 -- CHANGE_DIRECTION ::= Increases | Decreases
17176
17177 when Pragma_Loop_Variant => Loop_Variant : declare
17178 Variant : Node_Id;
17179
17180 begin
17181 GNAT_Pragma;
17182 Check_At_Least_N_Arguments (1);
17183 Check_Loop_Pragma_Placement;
17184
17185 -- Process all increasing / decreasing expressions
17186
17187 Variant := First (Pragma_Argument_Associations (N));
17188 while Present (Variant) loop
17189 if not Nam_In (Chars (Variant), Name_Decreases,
17190 Name_Increases)
17191 then
17192 Error_Pragma_Arg ("wrong change modifier", Variant);
17193 end if;
17194
17195 Preanalyze_Assert_Expression
17196 (Expression (Variant), Any_Discrete);
17197
17198 Next (Variant);
17199 end loop;
17200 end Loop_Variant;
17201
17202 -----------------------
17203 -- Machine_Attribute --
17204 -----------------------
17205
17206 -- pragma Machine_Attribute (
17207 -- [Entity =>] LOCAL_NAME,
17208 -- [Attribute_Name =>] static_string_EXPRESSION
17209 -- [, [Info =>] static_EXPRESSION] );
17210
17211 when Pragma_Machine_Attribute => Machine_Attribute : declare
17212 Def_Id : Entity_Id;
17213
17214 begin
17215 GNAT_Pragma;
17216 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
17217
17218 if Arg_Count = 3 then
17219 Check_Optional_Identifier (Arg3, Name_Info);
17220 Check_Arg_Is_OK_Static_Expression (Arg3);
17221 else
17222 Check_Arg_Count (2);
17223 end if;
17224
17225 Check_Optional_Identifier (Arg1, Name_Entity);
17226 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
17227 Check_Arg_Is_Local_Name (Arg1);
17228 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
17229 Def_Id := Entity (Get_Pragma_Arg (Arg1));
17230
17231 if Is_Access_Type (Def_Id) then
17232 Def_Id := Designated_Type (Def_Id);
17233 end if;
17234
17235 if Rep_Item_Too_Early (Def_Id, N) then
17236 return;
17237 end if;
17238
17239 Def_Id := Underlying_Type (Def_Id);
17240
17241 -- The only processing required is to link this item on to the
17242 -- list of rep items for the given entity. This is accomplished
17243 -- by the call to Rep_Item_Too_Late (when no error is detected
17244 -- and False is returned).
17245
17246 if Rep_Item_Too_Late (Def_Id, N) then
17247 return;
17248 else
17249 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
17250 end if;
17251 end Machine_Attribute;
17252
17253 ----------
17254 -- Main --
17255 ----------
17256
17257 -- pragma Main
17258 -- (MAIN_OPTION [, MAIN_OPTION]);
17259
17260 -- MAIN_OPTION ::=
17261 -- [STACK_SIZE =>] static_integer_EXPRESSION
17262 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17263 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17264
17265 when Pragma_Main => Main : declare
17266 Args : Args_List (1 .. 3);
17267 Names : constant Name_List (1 .. 3) := (
17268 Name_Stack_Size,
17269 Name_Task_Stack_Size_Default,
17270 Name_Time_Slicing_Enabled);
17271
17272 Nod : Node_Id;
17273
17274 begin
17275 GNAT_Pragma;
17276 Gather_Associations (Names, Args);
17277
17278 for J in 1 .. 2 loop
17279 if Present (Args (J)) then
17280 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17281 end if;
17282 end loop;
17283
17284 if Present (Args (3)) then
17285 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
17286 end if;
17287
17288 Nod := Next (N);
17289 while Present (Nod) loop
17290 if Nkind (Nod) = N_Pragma
17291 and then Pragma_Name (Nod) = Name_Main
17292 then
17293 Error_Msg_Name_1 := Pname;
17294 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17295 end if;
17296
17297 Next (Nod);
17298 end loop;
17299 end Main;
17300
17301 ------------------
17302 -- Main_Storage --
17303 ------------------
17304
17305 -- pragma Main_Storage
17306 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17307
17308 -- MAIN_STORAGE_OPTION ::=
17309 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17310 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17311
17312 when Pragma_Main_Storage => Main_Storage : declare
17313 Args : Args_List (1 .. 2);
17314 Names : constant Name_List (1 .. 2) := (
17315 Name_Working_Storage,
17316 Name_Top_Guard);
17317
17318 Nod : Node_Id;
17319
17320 begin
17321 GNAT_Pragma;
17322 Gather_Associations (Names, Args);
17323
17324 for J in 1 .. 2 loop
17325 if Present (Args (J)) then
17326 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
17327 end if;
17328 end loop;
17329
17330 Check_In_Main_Program;
17331
17332 Nod := Next (N);
17333 while Present (Nod) loop
17334 if Nkind (Nod) = N_Pragma
17335 and then Pragma_Name (Nod) = Name_Main_Storage
17336 then
17337 Error_Msg_Name_1 := Pname;
17338 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17339 end if;
17340
17341 Next (Nod);
17342 end loop;
17343 end Main_Storage;
17344
17345 -----------------
17346 -- Memory_Size --
17347 -----------------
17348
17349 -- pragma Memory_Size (NUMERIC_LITERAL)
17350
17351 when Pragma_Memory_Size =>
17352 GNAT_Pragma;
17353
17354 -- Memory size is simply ignored
17355
17356 Check_No_Identifiers;
17357 Check_Arg_Count (1);
17358 Check_Arg_Is_Integer_Literal (Arg1);
17359
17360 -------------
17361 -- No_Body --
17362 -------------
17363
17364 -- pragma No_Body;
17365
17366 -- The only correct use of this pragma is on its own in a file, in
17367 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
17368 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
17369 -- check for a file containing nothing but a No_Body pragma). If we
17370 -- attempt to process it during normal semantics processing, it means
17371 -- it was misplaced.
17372
17373 when Pragma_No_Body =>
17374 GNAT_Pragma;
17375 Pragma_Misplaced;
17376
17377 -----------------------------
17378 -- No_Elaboration_Code_All --
17379 -----------------------------
17380
17381 -- pragma No_Elaboration_Code_All;
17382
17383 when Pragma_No_Elaboration_Code_All =>
17384 GNAT_Pragma;
17385 Check_Valid_Library_Unit_Pragma;
17386
17387 if Nkind (N) = N_Null_Statement then
17388 return;
17389 end if;
17390
17391 -- Must appear for a spec or generic spec
17392
17393 if not Nkind_In (Unit (Cunit (Current_Sem_Unit)),
17394 N_Generic_Package_Declaration,
17395 N_Generic_Subprogram_Declaration,
17396 N_Package_Declaration,
17397 N_Subprogram_Declaration)
17398 then
17399 Error_Pragma
17400 (Fix_Error
17401 ("pragma% can only occur for package "
17402 & "or subprogram spec"));
17403 end if;
17404
17405 -- Set flag in unit table
17406
17407 Set_No_Elab_Code_All (Current_Sem_Unit);
17408
17409 -- Set restriction No_Elaboration_Code if this is the main unit
17410
17411 if Current_Sem_Unit = Main_Unit then
17412 Set_Restriction (No_Elaboration_Code, N);
17413 end if;
17414
17415 -- If we are in the main unit or in an extended main source unit,
17416 -- then we also add it to the configuration restrictions so that
17417 -- it will apply to all units in the extended main source.
17418
17419 if Current_Sem_Unit = Main_Unit
17420 or else In_Extended_Main_Source_Unit (N)
17421 then
17422 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
17423 end if;
17424
17425 -- If in main extended unit, activate transitive with test
17426
17427 if In_Extended_Main_Source_Unit (N) then
17428 Opt.No_Elab_Code_All_Pragma := N;
17429 end if;
17430
17431 ---------------
17432 -- No_Inline --
17433 ---------------
17434
17435 -- pragma No_Inline ( NAME {, NAME} );
17436
17437 when Pragma_No_Inline =>
17438 GNAT_Pragma;
17439 Process_Inline (Suppressed);
17440
17441 ---------------
17442 -- No_Return --
17443 ---------------
17444
17445 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
17446
17447 when Pragma_No_Return => No_Return : declare
17448 Arg : Node_Id;
17449 E : Entity_Id;
17450 Found : Boolean;
17451 Id : Node_Id;
17452
17453 Ghost_Error_Posted : Boolean := False;
17454 -- Flag set when an error concerning the illegal mix of Ghost and
17455 -- non-Ghost subprograms is emitted.
17456
17457 Ghost_Id : Entity_Id := Empty;
17458 -- The entity of the first Ghost procedure encountered while
17459 -- processing the arguments of the pragma.
17460
17461 begin
17462 Ada_2005_Pragma;
17463 Check_At_Least_N_Arguments (1);
17464
17465 -- Loop through arguments of pragma
17466
17467 Arg := Arg1;
17468 while Present (Arg) loop
17469 Check_Arg_Is_Local_Name (Arg);
17470 Id := Get_Pragma_Arg (Arg);
17471 Analyze (Id);
17472
17473 if not Is_Entity_Name (Id) then
17474 Error_Pragma_Arg ("entity name required", Arg);
17475 end if;
17476
17477 if Etype (Id) = Any_Type then
17478 raise Pragma_Exit;
17479 end if;
17480
17481 -- Loop to find matching procedures
17482
17483 E := Entity (Id);
17484
17485 Found := False;
17486 while Present (E)
17487 and then Scope (E) = Current_Scope
17488 loop
17489 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
17490 Set_No_Return (E);
17491
17492 -- A pragma that applies to a Ghost entity becomes Ghost
17493 -- for the purposes of legality checks and removal of
17494 -- ignored Ghost code.
17495
17496 Mark_Pragma_As_Ghost (N, E);
17497
17498 -- Capture the entity of the first Ghost procedure being
17499 -- processed for error detection purposes.
17500
17501 if Is_Ghost_Entity (E) then
17502 if No (Ghost_Id) then
17503 Ghost_Id := E;
17504 end if;
17505
17506 -- Otherwise the subprogram is non-Ghost. It is illegal
17507 -- to mix references to Ghost and non-Ghost entities
17508 -- (SPARK RM 6.9).
17509
17510 elsif Present (Ghost_Id)
17511 and then not Ghost_Error_Posted
17512 then
17513 Ghost_Error_Posted := True;
17514
17515 Error_Msg_Name_1 := Pname;
17516 Error_Msg_N
17517 ("pragma % cannot mention ghost and non-ghost "
17518 & "procedures", N);
17519
17520 Error_Msg_Sloc := Sloc (Ghost_Id);
17521 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
17522
17523 Error_Msg_Sloc := Sloc (E);
17524 Error_Msg_NE ("\& # declared as non-ghost", N, E);
17525 end if;
17526
17527 -- Set flag on any alias as well
17528
17529 if Is_Overloadable (E) and then Present (Alias (E)) then
17530 Set_No_Return (Alias (E));
17531 end if;
17532
17533 Found := True;
17534 end if;
17535
17536 exit when From_Aspect_Specification (N);
17537 E := Homonym (E);
17538 end loop;
17539
17540 -- If entity in not in current scope it may be the enclosing
17541 -- suprogram body to which the aspect applies.
17542
17543 if not Found then
17544 if Entity (Id) = Current_Scope
17545 and then From_Aspect_Specification (N)
17546 then
17547 Set_No_Return (Entity (Id));
17548 else
17549 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
17550 end if;
17551 end if;
17552
17553 Next (Arg);
17554 end loop;
17555 end No_Return;
17556
17557 -----------------
17558 -- No_Run_Time --
17559 -----------------
17560
17561 -- pragma No_Run_Time;
17562
17563 -- Note: this pragma is retained for backwards compatibility. See
17564 -- body of Rtsfind for full details on its handling.
17565
17566 when Pragma_No_Run_Time =>
17567 GNAT_Pragma;
17568 Check_Valid_Configuration_Pragma;
17569 Check_Arg_Count (0);
17570
17571 No_Run_Time_Mode := True;
17572 Configurable_Run_Time_Mode := True;
17573
17574 -- Set Duration to 32 bits if word size is 32
17575
17576 if Ttypes.System_Word_Size = 32 then
17577 Duration_32_Bits_On_Target := True;
17578 end if;
17579
17580 -- Set appropriate restrictions
17581
17582 Set_Restriction (No_Finalization, N);
17583 Set_Restriction (No_Exception_Handlers, N);
17584 Set_Restriction (Max_Tasks, N, 0);
17585 Set_Restriction (No_Tasking, N);
17586
17587 -----------------------
17588 -- No_Tagged_Streams --
17589 -----------------------
17590
17591 -- pragma No_Tagged_Streams;
17592 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
17593
17594 when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare
17595 E : Entity_Id;
17596 E_Id : Node_Id;
17597
17598 begin
17599 GNAT_Pragma;
17600 Check_At_Most_N_Arguments (1);
17601
17602 -- One argument case
17603
17604 if Arg_Count = 1 then
17605 Check_Optional_Identifier (Arg1, Name_Entity);
17606 Check_Arg_Is_Local_Name (Arg1);
17607 E_Id := Get_Pragma_Arg (Arg1);
17608
17609 if Etype (E_Id) = Any_Type then
17610 return;
17611 end if;
17612
17613 E := Entity (E_Id);
17614
17615 Check_Duplicate_Pragma (E);
17616
17617 if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then
17618 Error_Pragma_Arg
17619 ("argument for pragma% must be root tagged type", Arg1);
17620 end if;
17621
17622 if Rep_Item_Too_Early (E, N)
17623 or else
17624 Rep_Item_Too_Late (E, N)
17625 then
17626 return;
17627 else
17628 Set_No_Tagged_Streams_Pragma (E, N);
17629 end if;
17630
17631 -- Zero argument case
17632
17633 else
17634 Check_Is_In_Decl_Part_Or_Package_Spec;
17635 No_Tagged_Streams := N;
17636 end if;
17637 end No_Tagged_Strms;
17638
17639 ------------------------
17640 -- No_Strict_Aliasing --
17641 ------------------------
17642
17643 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17644
17645 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
17646 E_Id : Entity_Id;
17647
17648 begin
17649 GNAT_Pragma;
17650 Check_At_Most_N_Arguments (1);
17651
17652 if Arg_Count = 0 then
17653 Check_Valid_Configuration_Pragma;
17654 Opt.No_Strict_Aliasing := True;
17655
17656 else
17657 Check_Optional_Identifier (Arg2, Name_Entity);
17658 Check_Arg_Is_Local_Name (Arg1);
17659 E_Id := Entity (Get_Pragma_Arg (Arg1));
17660
17661 if E_Id = Any_Type then
17662 return;
17663 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
17664 Error_Pragma_Arg ("pragma% requires access type", Arg1);
17665 end if;
17666
17667 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
17668 end if;
17669 end No_Strict_Aliasing;
17670
17671 -----------------------
17672 -- Normalize_Scalars --
17673 -----------------------
17674
17675 -- pragma Normalize_Scalars;
17676
17677 when Pragma_Normalize_Scalars =>
17678 Check_Ada_83_Warning;
17679 Check_Arg_Count (0);
17680 Check_Valid_Configuration_Pragma;
17681
17682 -- Normalize_Scalars creates false positives in CodePeer, and
17683 -- incorrect negative results in GNATprove mode, so ignore this
17684 -- pragma in these modes.
17685
17686 if not (CodePeer_Mode or GNATprove_Mode) then
17687 Normalize_Scalars := True;
17688 Init_Or_Norm_Scalars := True;
17689 end if;
17690
17691 -----------------
17692 -- Obsolescent --
17693 -----------------
17694
17695 -- pragma Obsolescent;
17696
17697 -- pragma Obsolescent (
17698 -- [Message =>] static_string_EXPRESSION
17699 -- [,[Version =>] Ada_05]]);
17700
17701 -- pragma Obsolescent (
17702 -- [Entity =>] NAME
17703 -- [,[Message =>] static_string_EXPRESSION
17704 -- [,[Version =>] Ada_05]] );
17705
17706 when Pragma_Obsolescent => Obsolescent : declare
17707 Decl : Node_Id;
17708 Ename : Node_Id;
17709
17710 procedure Set_Obsolescent (E : Entity_Id);
17711 -- Given an entity Ent, mark it as obsolescent if appropriate
17712
17713 ---------------------
17714 -- Set_Obsolescent --
17715 ---------------------
17716
17717 procedure Set_Obsolescent (E : Entity_Id) is
17718 Active : Boolean;
17719 Ent : Entity_Id;
17720 S : String_Id;
17721
17722 begin
17723 Active := True;
17724 Ent := E;
17725
17726 -- A pragma that applies to a Ghost entity becomes Ghost for
17727 -- the purposes of legality checks and removal of ignored Ghost
17728 -- code.
17729
17730 Mark_Pragma_As_Ghost (N, E);
17731
17732 -- Entity name was given
17733
17734 if Present (Ename) then
17735
17736 -- If entity name matches, we are fine. Save entity in
17737 -- pragma argument, for ASIS use.
17738
17739 if Chars (Ename) = Chars (Ent) then
17740 Set_Entity (Ename, Ent);
17741 Generate_Reference (Ent, Ename);
17742
17743 -- If entity name does not match, only possibility is an
17744 -- enumeration literal from an enumeration type declaration.
17745
17746 elsif Ekind (Ent) /= E_Enumeration_Type then
17747 Error_Pragma
17748 ("pragma % entity name does not match declaration");
17749
17750 else
17751 Ent := First_Literal (E);
17752 loop
17753 if No (Ent) then
17754 Error_Pragma
17755 ("pragma % entity name does not match any "
17756 & "enumeration literal");
17757
17758 elsif Chars (Ent) = Chars (Ename) then
17759 Set_Entity (Ename, Ent);
17760 Generate_Reference (Ent, Ename);
17761 exit;
17762
17763 else
17764 Ent := Next_Literal (Ent);
17765 end if;
17766 end loop;
17767 end if;
17768 end if;
17769
17770 -- Ent points to entity to be marked
17771
17772 if Arg_Count >= 1 then
17773
17774 -- Deal with static string argument
17775
17776 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17777 S := Strval (Get_Pragma_Arg (Arg1));
17778
17779 for J in 1 .. String_Length (S) loop
17780 if not In_Character_Range (Get_String_Char (S, J)) then
17781 Error_Pragma_Arg
17782 ("pragma% argument does not allow wide characters",
17783 Arg1);
17784 end if;
17785 end loop;
17786
17787 Obsolescent_Warnings.Append
17788 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
17789
17790 -- Check for Ada_05 parameter
17791
17792 if Arg_Count /= 1 then
17793 Check_Arg_Count (2);
17794
17795 declare
17796 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
17797
17798 begin
17799 Check_Arg_Is_Identifier (Argx);
17800
17801 if Chars (Argx) /= Name_Ada_05 then
17802 Error_Msg_Name_2 := Name_Ada_05;
17803 Error_Pragma_Arg
17804 ("only allowed argument for pragma% is %", Argx);
17805 end if;
17806
17807 if Ada_Version_Explicit < Ada_2005
17808 or else not Warn_On_Ada_2005_Compatibility
17809 then
17810 Active := False;
17811 end if;
17812 end;
17813 end if;
17814 end if;
17815
17816 -- Set flag if pragma active
17817
17818 if Active then
17819 Set_Is_Obsolescent (Ent);
17820 end if;
17821
17822 return;
17823 end Set_Obsolescent;
17824
17825 -- Start of processing for pragma Obsolescent
17826
17827 begin
17828 GNAT_Pragma;
17829
17830 Check_At_Most_N_Arguments (3);
17831
17832 -- See if first argument specifies an entity name
17833
17834 if Arg_Count >= 1
17835 and then
17836 (Chars (Arg1) = Name_Entity
17837 or else
17838 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
17839 N_Identifier,
17840 N_Operator_Symbol))
17841 then
17842 Ename := Get_Pragma_Arg (Arg1);
17843
17844 -- Eliminate first argument, so we can share processing
17845
17846 Arg1 := Arg2;
17847 Arg2 := Arg3;
17848 Arg_Count := Arg_Count - 1;
17849
17850 -- No Entity name argument given
17851
17852 else
17853 Ename := Empty;
17854 end if;
17855
17856 if Arg_Count >= 1 then
17857 Check_Optional_Identifier (Arg1, Name_Message);
17858
17859 if Arg_Count = 2 then
17860 Check_Optional_Identifier (Arg2, Name_Version);
17861 end if;
17862 end if;
17863
17864 -- Get immediately preceding declaration
17865
17866 Decl := Prev (N);
17867 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17868 Prev (Decl);
17869 end loop;
17870
17871 -- Cases where we do not follow anything other than another pragma
17872
17873 if No (Decl) then
17874
17875 -- First case: library level compilation unit declaration with
17876 -- the pragma immediately following the declaration.
17877
17878 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17879 Set_Obsolescent
17880 (Defining_Entity (Unit (Parent (Parent (N)))));
17881 return;
17882
17883 -- Case 2: library unit placement for package
17884
17885 else
17886 declare
17887 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17888 begin
17889 if Is_Package_Or_Generic_Package (Ent) then
17890 Set_Obsolescent (Ent);
17891 return;
17892 end if;
17893 end;
17894 end if;
17895
17896 -- Cases where we must follow a declaration, including an
17897 -- abstract subprogram declaration, which is not in the
17898 -- other node subtypes.
17899
17900 else
17901 if Nkind (Decl) not in N_Declaration
17902 and then Nkind (Decl) not in N_Later_Decl_Item
17903 and then Nkind (Decl) not in N_Generic_Declaration
17904 and then Nkind (Decl) not in N_Renaming_Declaration
17905 and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration
17906 then
17907 Error_Pragma
17908 ("pragma% misplaced, "
17909 & "must immediately follow a declaration");
17910
17911 else
17912 Set_Obsolescent (Defining_Entity (Decl));
17913 return;
17914 end if;
17915 end if;
17916 end Obsolescent;
17917
17918 --------------
17919 -- Optimize --
17920 --------------
17921
17922 -- pragma Optimize (Time | Space | Off);
17923
17924 -- The actual check for optimize is done in Gigi. Note that this
17925 -- pragma does not actually change the optimization setting, it
17926 -- simply checks that it is consistent with the pragma.
17927
17928 when Pragma_Optimize =>
17929 Check_No_Identifiers;
17930 Check_Arg_Count (1);
17931 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
17932
17933 ------------------------
17934 -- Optimize_Alignment --
17935 ------------------------
17936
17937 -- pragma Optimize_Alignment (Time | Space | Off);
17938
17939 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17940 GNAT_Pragma;
17941 Check_No_Identifiers;
17942 Check_Arg_Count (1);
17943 Check_Valid_Configuration_Pragma;
17944
17945 declare
17946 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17947 begin
17948 case Nam is
17949 when Name_Time =>
17950 Opt.Optimize_Alignment := 'T';
17951 when Name_Space =>
17952 Opt.Optimize_Alignment := 'S';
17953 when Name_Off =>
17954 Opt.Optimize_Alignment := 'O';
17955 when others =>
17956 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
17957 end case;
17958 end;
17959
17960 -- Set indication that mode is set locally. If we are in fact in a
17961 -- configuration pragma file, this setting is harmless since the
17962 -- switch will get reset anyway at the start of each unit.
17963
17964 Optimize_Alignment_Local := True;
17965 end Optimize_Alignment;
17966
17967 -------------
17968 -- Ordered --
17969 -------------
17970
17971 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17972
17973 when Pragma_Ordered => Ordered : declare
17974 Assoc : constant Node_Id := Arg1;
17975 Type_Id : Node_Id;
17976 Typ : Entity_Id;
17977
17978 begin
17979 GNAT_Pragma;
17980 Check_No_Identifiers;
17981 Check_Arg_Count (1);
17982 Check_Arg_Is_Local_Name (Arg1);
17983
17984 Type_Id := Get_Pragma_Arg (Assoc);
17985 Find_Type (Type_Id);
17986 Typ := Entity (Type_Id);
17987
17988 if Typ = Any_Type then
17989 return;
17990 else
17991 Typ := Underlying_Type (Typ);
17992 end if;
17993
17994 if not Is_Enumeration_Type (Typ) then
17995 Error_Pragma ("pragma% must specify enumeration type");
17996 end if;
17997
17998 Check_First_Subtype (Arg1);
17999 Set_Has_Pragma_Ordered (Base_Type (Typ));
18000 end Ordered;
18001
18002 -------------------
18003 -- Overflow_Mode --
18004 -------------------
18005
18006 -- pragma Overflow_Mode
18007 -- ([General => ] MODE [, [Assertions => ] MODE]);
18008
18009 -- MODE := STRICT | MINIMIZED | ELIMINATED
18010
18011 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
18012 -- since System.Bignums makes this assumption. This is true of nearly
18013 -- all (all?) targets.
18014
18015 when Pragma_Overflow_Mode => Overflow_Mode : declare
18016 function Get_Overflow_Mode
18017 (Name : Name_Id;
18018 Arg : Node_Id) return Overflow_Mode_Type;
18019 -- Function to process one pragma argument, Arg. If an identifier
18020 -- is present, it must be Name. Mode type is returned if a valid
18021 -- argument exists, otherwise an error is signalled.
18022
18023 -----------------------
18024 -- Get_Overflow_Mode --
18025 -----------------------
18026
18027 function Get_Overflow_Mode
18028 (Name : Name_Id;
18029 Arg : Node_Id) return Overflow_Mode_Type
18030 is
18031 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
18032
18033 begin
18034 Check_Optional_Identifier (Arg, Name);
18035 Check_Arg_Is_Identifier (Argx);
18036
18037 if Chars (Argx) = Name_Strict then
18038 return Strict;
18039
18040 elsif Chars (Argx) = Name_Minimized then
18041 return Minimized;
18042
18043 elsif Chars (Argx) = Name_Eliminated then
18044 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
18045 Error_Pragma_Arg
18046 ("Eliminated not implemented on this target", Argx);
18047 else
18048 return Eliminated;
18049 end if;
18050
18051 else
18052 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
18053 end if;
18054 end Get_Overflow_Mode;
18055
18056 -- Start of processing for Overflow_Mode
18057
18058 begin
18059 GNAT_Pragma;
18060 Check_At_Least_N_Arguments (1);
18061 Check_At_Most_N_Arguments (2);
18062
18063 -- Process first argument
18064
18065 Scope_Suppress.Overflow_Mode_General :=
18066 Get_Overflow_Mode (Name_General, Arg1);
18067
18068 -- Case of only one argument
18069
18070 if Arg_Count = 1 then
18071 Scope_Suppress.Overflow_Mode_Assertions :=
18072 Scope_Suppress.Overflow_Mode_General;
18073
18074 -- Case of two arguments present
18075
18076 else
18077 Scope_Suppress.Overflow_Mode_Assertions :=
18078 Get_Overflow_Mode (Name_Assertions, Arg2);
18079 end if;
18080 end Overflow_Mode;
18081
18082 --------------------------
18083 -- Overriding Renamings --
18084 --------------------------
18085
18086 -- pragma Overriding_Renamings;
18087
18088 when Pragma_Overriding_Renamings =>
18089 GNAT_Pragma;
18090 Check_Arg_Count (0);
18091 Check_Valid_Configuration_Pragma;
18092 Overriding_Renamings := True;
18093
18094 ----------
18095 -- Pack --
18096 ----------
18097
18098 -- pragma Pack (first_subtype_LOCAL_NAME);
18099
18100 when Pragma_Pack => Pack : declare
18101 Assoc : constant Node_Id := Arg1;
18102 Ctyp : Entity_Id;
18103 Ignore : Boolean := False;
18104 Typ : Entity_Id;
18105 Type_Id : Node_Id;
18106
18107 begin
18108 Check_No_Identifiers;
18109 Check_Arg_Count (1);
18110 Check_Arg_Is_Local_Name (Arg1);
18111 Type_Id := Get_Pragma_Arg (Assoc);
18112
18113 if not Is_Entity_Name (Type_Id)
18114 or else not Is_Type (Entity (Type_Id))
18115 then
18116 Error_Pragma_Arg
18117 ("argument for pragma% must be type or subtype", Arg1);
18118 end if;
18119
18120 Find_Type (Type_Id);
18121 Typ := Entity (Type_Id);
18122
18123 if Typ = Any_Type
18124 or else Rep_Item_Too_Early (Typ, N)
18125 then
18126 return;
18127 else
18128 Typ := Underlying_Type (Typ);
18129 end if;
18130
18131 -- A pragma that applies to a Ghost entity becomes Ghost for the
18132 -- purposes of legality checks and removal of ignored Ghost code.
18133
18134 Mark_Pragma_As_Ghost (N, Typ);
18135
18136 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
18137 Error_Pragma ("pragma% must specify array or record type");
18138 end if;
18139
18140 Check_First_Subtype (Arg1);
18141 Check_Duplicate_Pragma (Typ);
18142
18143 -- Array type
18144
18145 if Is_Array_Type (Typ) then
18146 Ctyp := Component_Type (Typ);
18147
18148 -- Ignore pack that does nothing
18149
18150 if Known_Static_Esize (Ctyp)
18151 and then Known_Static_RM_Size (Ctyp)
18152 and then Esize (Ctyp) = RM_Size (Ctyp)
18153 and then Addressable (Esize (Ctyp))
18154 then
18155 Ignore := True;
18156 end if;
18157
18158 -- Process OK pragma Pack. Note that if there is a separate
18159 -- component clause present, the Pack will be cancelled. This
18160 -- processing is in Freeze.
18161
18162 if not Rep_Item_Too_Late (Typ, N) then
18163
18164 -- In CodePeer mode, we do not need complex front-end
18165 -- expansions related to pragma Pack, so disable handling
18166 -- of pragma Pack.
18167
18168 if CodePeer_Mode then
18169 null;
18170
18171 -- Normal case where we do the pack action
18172
18173 else
18174 if not Ignore then
18175 Set_Is_Packed (Base_Type (Typ));
18176 Set_Has_Non_Standard_Rep (Base_Type (Typ));
18177 end if;
18178
18179 Set_Has_Pragma_Pack (Base_Type (Typ));
18180 end if;
18181 end if;
18182
18183 -- For record types, the pack is always effective
18184
18185 else pragma Assert (Is_Record_Type (Typ));
18186 if not Rep_Item_Too_Late (Typ, N) then
18187 Set_Is_Packed (Base_Type (Typ));
18188 Set_Has_Pragma_Pack (Base_Type (Typ));
18189 Set_Has_Non_Standard_Rep (Base_Type (Typ));
18190 end if;
18191 end if;
18192 end Pack;
18193
18194 ----------
18195 -- Page --
18196 ----------
18197
18198 -- pragma Page;
18199
18200 -- There is nothing to do here, since we did all the processing for
18201 -- this pragma in Par.Prag (so that it works properly even in syntax
18202 -- only mode).
18203
18204 when Pragma_Page =>
18205 null;
18206
18207 -------------
18208 -- Part_Of --
18209 -------------
18210
18211 -- pragma Part_Of (ABSTRACT_STATE);
18212
18213 -- ABSTRACT_STATE ::= NAME
18214
18215 when Pragma_Part_Of => Part_Of : declare
18216 procedure Propagate_Part_Of
18217 (Pack_Id : Entity_Id;
18218 State_Id : Entity_Id;
18219 Instance : Node_Id);
18220 -- Propagate the Part_Of indicator to all abstract states and
18221 -- objects declared in the visible state space of a package
18222 -- denoted by Pack_Id. State_Id is the encapsulating state.
18223 -- Instance is the package instantiation node.
18224
18225 -----------------------
18226 -- Propagate_Part_Of --
18227 -----------------------
18228
18229 procedure Propagate_Part_Of
18230 (Pack_Id : Entity_Id;
18231 State_Id : Entity_Id;
18232 Instance : Node_Id)
18233 is
18234 Has_Item : Boolean := False;
18235 -- Flag set when the visible state space contains at least one
18236 -- abstract state or variable.
18237
18238 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
18239 -- Propagate the Part_Of indicator to all abstract states and
18240 -- objects declared in the visible state space of a package
18241 -- denoted by Pack_Id.
18242
18243 -----------------------
18244 -- Propagate_Part_Of --
18245 -----------------------
18246
18247 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
18248 Constits : Elist_Id;
18249 Item_Id : Entity_Id;
18250
18251 begin
18252 -- Traverse the entity chain of the package and set relevant
18253 -- attributes of abstract states and objects declared in the
18254 -- visible state space of the package.
18255
18256 Item_Id := First_Entity (Pack_Id);
18257 while Present (Item_Id)
18258 and then not In_Private_Part (Item_Id)
18259 loop
18260 -- Do not consider internally generated items
18261
18262 if not Comes_From_Source (Item_Id) then
18263 null;
18264
18265 -- The Part_Of indicator turns an abstract state or an
18266 -- object into a constituent of the encapsulating state.
18267
18268 elsif Ekind_In (Item_Id, E_Abstract_State,
18269 E_Constant,
18270 E_Variable)
18271 then
18272 Has_Item := True;
18273 Constits := Part_Of_Constituents (State_Id);
18274
18275 if No (Constits) then
18276 Constits := New_Elmt_List;
18277 Set_Part_Of_Constituents (State_Id, Constits);
18278 end if;
18279
18280 Append_Elmt (Item_Id, Constits);
18281 Set_Encapsulating_State (Item_Id, State_Id);
18282
18283 -- Recursively handle nested packages and instantiations
18284
18285 elsif Ekind (Item_Id) = E_Package then
18286 Propagate_Part_Of (Item_Id);
18287 end if;
18288
18289 Next_Entity (Item_Id);
18290 end loop;
18291 end Propagate_Part_Of;
18292
18293 -- Start of processing for Propagate_Part_Of
18294
18295 begin
18296 Propagate_Part_Of (Pack_Id);
18297
18298 -- Detect a package instantiation that is subject to a Part_Of
18299 -- indicator, but has no visible state.
18300
18301 if not Has_Item then
18302 SPARK_Msg_NE
18303 ("package instantiation & has Part_Of indicator but "
18304 & "lacks visible state", Instance, Pack_Id);
18305 end if;
18306 end Propagate_Part_Of;
18307
18308 -- Local variables
18309
18310 Constits : Elist_Id;
18311 Encap : Node_Id;
18312 Encap_Id : Entity_Id;
18313 Item_Id : Entity_Id;
18314 Legal : Boolean;
18315 Stmt : Node_Id;
18316
18317 -- Start of processing for Part_Of
18318
18319 begin
18320 GNAT_Pragma;
18321 Check_No_Identifiers;
18322 Check_Arg_Count (1);
18323
18324 Stmt := Find_Related_Context (N, Do_Checks => True);
18325
18326 -- Object declaration
18327
18328 if Nkind (Stmt) = N_Object_Declaration then
18329 null;
18330
18331 -- Package instantiation
18332
18333 elsif Nkind (Stmt) = N_Package_Instantiation then
18334 null;
18335
18336 -- Single concurrent type declaration
18337
18338 elsif Is_Single_Concurrent_Type_Declaration (Stmt) then
18339 null;
18340
18341 -- Otherwise the pragma is associated with an illegal construct
18342
18343 else
18344 Pragma_Misplaced;
18345 return;
18346 end if;
18347
18348 -- Extract the entity of the related object declaration or package
18349 -- instantiation. In the case of the instantiation, use the entity
18350 -- of the instance spec.
18351
18352 if Nkind (Stmt) = N_Package_Instantiation then
18353 Stmt := Instance_Spec (Stmt);
18354 end if;
18355
18356 Item_Id := Defining_Entity (Stmt);
18357 Encap := Get_Pragma_Arg (Arg1);
18358
18359 -- A pragma that applies to a Ghost entity becomes Ghost for the
18360 -- purposes of legality checks and removal of ignored Ghost code.
18361
18362 Mark_Pragma_As_Ghost (N, Item_Id);
18363
18364 -- Chain the pragma on the contract for further processing by
18365 -- Analyze_Part_Of_In_Decl_Part or for completeness.
18366
18367 Add_Contract_Item (N, Item_Id);
18368
18369 -- A variable may act as consituent of a single concurrent type
18370 -- which in turn could be declared after the variable. Due to this
18371 -- discrepancy, the full analysis of indicator Part_Of is delayed
18372 -- until the end of the enclosing declarative region (see routine
18373 -- Analyze_Part_Of_In_Decl_Part).
18374
18375 if Ekind (Item_Id) = E_Variable then
18376 null;
18377
18378 -- Otherwise indicator Part_Of applies to a constant or a package
18379 -- instantiation.
18380
18381 else
18382 -- Detect any discrepancies between the placement of the
18383 -- constant or package instantiation with respect to state
18384 -- space and the encapsulating state.
18385
18386 Analyze_Part_Of
18387 (Indic => N,
18388 Item_Id => Item_Id,
18389 Encap => Encap,
18390 Encap_Id => Encap_Id,
18391 Legal => Legal);
18392
18393 if Legal then
18394 pragma Assert (Present (Encap_Id));
18395
18396 if Ekind (Item_Id) = E_Constant then
18397 Constits := Part_Of_Constituents (Encap_Id);
18398
18399 if No (Constits) then
18400 Constits := New_Elmt_List;
18401 Set_Part_Of_Constituents (Encap_Id, Constits);
18402 end if;
18403
18404 Append_Elmt (Item_Id, Constits);
18405 Set_Encapsulating_State (Item_Id, Encap_Id);
18406
18407 -- Propagate the Part_Of indicator to the visible state
18408 -- space of the package instantiation.
18409
18410 else
18411 Propagate_Part_Of
18412 (Pack_Id => Item_Id,
18413 State_Id => Encap_Id,
18414 Instance => Stmt);
18415 end if;
18416 end if;
18417 end if;
18418 end Part_Of;
18419
18420 ----------------------------------
18421 -- Partition_Elaboration_Policy --
18422 ----------------------------------
18423
18424 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
18425
18426 when Pragma_Partition_Elaboration_Policy => declare
18427 subtype PEP_Range is Name_Id
18428 range First_Partition_Elaboration_Policy_Name
18429 .. Last_Partition_Elaboration_Policy_Name;
18430 PEP_Val : PEP_Range;
18431 PEP : Character;
18432
18433 begin
18434 Ada_2005_Pragma;
18435 Check_Arg_Count (1);
18436 Check_No_Identifiers;
18437 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
18438 Check_Valid_Configuration_Pragma;
18439 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
18440
18441 case PEP_Val is
18442 when Name_Concurrent =>
18443 PEP := 'C';
18444 when Name_Sequential =>
18445 PEP := 'S';
18446 end case;
18447
18448 if Partition_Elaboration_Policy /= ' '
18449 and then Partition_Elaboration_Policy /= PEP
18450 then
18451 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
18452 Error_Pragma
18453 ("partition elaboration policy incompatible with policy#");
18454
18455 -- Set new policy, but always preserve System_Location since we
18456 -- like the error message with the run time name.
18457
18458 else
18459 Partition_Elaboration_Policy := PEP;
18460
18461 if Partition_Elaboration_Policy_Sloc /= System_Location then
18462 Partition_Elaboration_Policy_Sloc := Loc;
18463 end if;
18464 end if;
18465 end;
18466
18467 -------------
18468 -- Passive --
18469 -------------
18470
18471 -- pragma Passive [(PASSIVE_FORM)];
18472
18473 -- PASSIVE_FORM ::= Semaphore | No
18474
18475 when Pragma_Passive =>
18476 GNAT_Pragma;
18477
18478 if Nkind (Parent (N)) /= N_Task_Definition then
18479 Error_Pragma ("pragma% must be within task definition");
18480 end if;
18481
18482 if Arg_Count /= 0 then
18483 Check_Arg_Count (1);
18484 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
18485 end if;
18486
18487 ----------------------------------
18488 -- Preelaborable_Initialization --
18489 ----------------------------------
18490
18491 -- pragma Preelaborable_Initialization (DIRECT_NAME);
18492
18493 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
18494 Ent : Entity_Id;
18495
18496 begin
18497 Ada_2005_Pragma;
18498 Check_Arg_Count (1);
18499 Check_No_Identifiers;
18500 Check_Arg_Is_Identifier (Arg1);
18501 Check_Arg_Is_Local_Name (Arg1);
18502 Check_First_Subtype (Arg1);
18503 Ent := Entity (Get_Pragma_Arg (Arg1));
18504
18505 -- A pragma that applies to a Ghost entity becomes Ghost for the
18506 -- purposes of legality checks and removal of ignored Ghost code.
18507
18508 Mark_Pragma_As_Ghost (N, Ent);
18509
18510 -- The pragma may come from an aspect on a private declaration,
18511 -- even if the freeze point at which this is analyzed in the
18512 -- private part after the full view.
18513
18514 if Has_Private_Declaration (Ent)
18515 and then From_Aspect_Specification (N)
18516 then
18517 null;
18518
18519 -- Check appropriate type argument
18520
18521 elsif Is_Private_Type (Ent)
18522 or else Is_Protected_Type (Ent)
18523 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
18524
18525 -- AI05-0028: The pragma applies to all composite types. Note
18526 -- that we apply this binding interpretation to earlier versions
18527 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
18528 -- choice since there are other compilers that do the same.
18529
18530 or else Is_Composite_Type (Ent)
18531 then
18532 null;
18533
18534 else
18535 Error_Pragma_Arg
18536 ("pragma % can only be applied to private, formal derived, "
18537 & "protected, or composite type", Arg1);
18538 end if;
18539
18540 -- Give an error if the pragma is applied to a protected type that
18541 -- does not qualify (due to having entries, or due to components
18542 -- that do not qualify).
18543
18544 if Is_Protected_Type (Ent)
18545 and then not Has_Preelaborable_Initialization (Ent)
18546 then
18547 Error_Msg_N
18548 ("protected type & does not have preelaborable "
18549 & "initialization", Ent);
18550
18551 -- Otherwise mark the type as definitely having preelaborable
18552 -- initialization.
18553
18554 else
18555 Set_Known_To_Have_Preelab_Init (Ent);
18556 end if;
18557
18558 if Has_Pragma_Preelab_Init (Ent)
18559 and then Warn_On_Redundant_Constructs
18560 then
18561 Error_Pragma ("?r?duplicate pragma%!");
18562 else
18563 Set_Has_Pragma_Preelab_Init (Ent);
18564 end if;
18565 end Preelab_Init;
18566
18567 --------------------
18568 -- Persistent_BSS --
18569 --------------------
18570
18571 -- pragma Persistent_BSS [(object_NAME)];
18572
18573 when Pragma_Persistent_BSS => Persistent_BSS : declare
18574 Decl : Node_Id;
18575 Ent : Entity_Id;
18576 Prag : Node_Id;
18577
18578 begin
18579 GNAT_Pragma;
18580 Check_At_Most_N_Arguments (1);
18581
18582 -- Case of application to specific object (one argument)
18583
18584 if Arg_Count = 1 then
18585 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18586
18587 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
18588 or else not
18589 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
18590 E_Constant)
18591 then
18592 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
18593 end if;
18594
18595 Ent := Entity (Get_Pragma_Arg (Arg1));
18596 Decl := Parent (Ent);
18597
18598 -- A pragma that applies to a Ghost entity becomes Ghost for
18599 -- the purposes of legality checks and removal of ignored Ghost
18600 -- code.
18601
18602 Mark_Pragma_As_Ghost (N, Ent);
18603
18604 -- Check for duplication before inserting in list of
18605 -- representation items.
18606
18607 Check_Duplicate_Pragma (Ent);
18608
18609 if Rep_Item_Too_Late (Ent, N) then
18610 return;
18611 end if;
18612
18613 if Present (Expression (Decl)) then
18614 Error_Pragma_Arg
18615 ("object for pragma% cannot have initialization", Arg1);
18616 end if;
18617
18618 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
18619 Error_Pragma_Arg
18620 ("object type for pragma% is not potentially persistent",
18621 Arg1);
18622 end if;
18623
18624 Prag :=
18625 Make_Linker_Section_Pragma
18626 (Ent, Sloc (N), ".persistent.bss");
18627 Insert_After (N, Prag);
18628 Analyze (Prag);
18629
18630 -- Case of use as configuration pragma with no arguments
18631
18632 else
18633 Check_Valid_Configuration_Pragma;
18634 Persistent_BSS_Mode := True;
18635 end if;
18636 end Persistent_BSS;
18637
18638 -------------
18639 -- Polling --
18640 -------------
18641
18642 -- pragma Polling (ON | OFF);
18643
18644 when Pragma_Polling =>
18645 GNAT_Pragma;
18646 Check_Arg_Count (1);
18647 Check_No_Identifiers;
18648 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
18649 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
18650
18651 -----------------------------------
18652 -- Post/Post_Class/Postcondition --
18653 -----------------------------------
18654
18655 -- pragma Post (Boolean_EXPRESSION);
18656 -- pragma Post_Class (Boolean_EXPRESSION);
18657 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18658 -- [,[Message =>] String_EXPRESSION]);
18659
18660 -- Characteristics:
18661
18662 -- * Analysis - The annotation undergoes initial checks to verify
18663 -- the legal placement and context. Secondary checks preanalyze the
18664 -- expression in:
18665
18666 -- Analyze_Pre_Post_Condition_In_Decl_Part
18667
18668 -- * Expansion - The annotation is expanded during the expansion of
18669 -- the related subprogram [body] contract as performed in:
18670
18671 -- Expand_Subprogram_Contract
18672
18673 -- * Template - The annotation utilizes the generic template of the
18674 -- related subprogram [body] when it is:
18675
18676 -- aspect on subprogram declaration
18677 -- aspect on stand alone subprogram body
18678 -- pragma on stand alone subprogram body
18679
18680 -- The annotation must prepare its own template when it is:
18681
18682 -- pragma on subprogram declaration
18683
18684 -- * Globals - Capture of global references must occur after full
18685 -- analysis.
18686
18687 -- * Instance - The annotation is instantiated automatically when
18688 -- the related generic subprogram [body] is instantiated except for
18689 -- the "pragma on subprogram declaration" case. In that scenario
18690 -- the annotation must instantiate itself.
18691
18692 when Pragma_Post |
18693 Pragma_Post_Class |
18694 Pragma_Postcondition =>
18695 Analyze_Pre_Post_Condition;
18696
18697 --------------------------------
18698 -- Pre/Pre_Class/Precondition --
18699 --------------------------------
18700
18701 -- pragma Pre (Boolean_EXPRESSION);
18702 -- pragma Pre_Class (Boolean_EXPRESSION);
18703 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18704 -- [,[Message =>] String_EXPRESSION]);
18705
18706 -- Characteristics:
18707
18708 -- * Analysis - The annotation undergoes initial checks to verify
18709 -- the legal placement and context. Secondary checks preanalyze the
18710 -- expression in:
18711
18712 -- Analyze_Pre_Post_Condition_In_Decl_Part
18713
18714 -- * Expansion - The annotation is expanded during the expansion of
18715 -- the related subprogram [body] contract as performed in:
18716
18717 -- Expand_Subprogram_Contract
18718
18719 -- * Template - The annotation utilizes the generic template of the
18720 -- related subprogram [body] when it is:
18721
18722 -- aspect on subprogram declaration
18723 -- aspect on stand alone subprogram body
18724 -- pragma on stand alone subprogram body
18725
18726 -- The annotation must prepare its own template when it is:
18727
18728 -- pragma on subprogram declaration
18729
18730 -- * Globals - Capture of global references must occur after full
18731 -- analysis.
18732
18733 -- * Instance - The annotation is instantiated automatically when
18734 -- the related generic subprogram [body] is instantiated except for
18735 -- the "pragma on subprogram declaration" case. In that scenario
18736 -- the annotation must instantiate itself.
18737
18738 when Pragma_Pre |
18739 Pragma_Pre_Class |
18740 Pragma_Precondition =>
18741 Analyze_Pre_Post_Condition;
18742
18743 ---------------
18744 -- Predicate --
18745 ---------------
18746
18747 -- pragma Predicate
18748 -- ([Entity =>] type_LOCAL_NAME,
18749 -- [Check =>] boolean_EXPRESSION);
18750
18751 when Pragma_Predicate => Predicate : declare
18752 Discard : Boolean;
18753 Typ : Entity_Id;
18754 Type_Id : Node_Id;
18755
18756 begin
18757 GNAT_Pragma;
18758 Check_Arg_Count (2);
18759 Check_Optional_Identifier (Arg1, Name_Entity);
18760 Check_Optional_Identifier (Arg2, Name_Check);
18761
18762 Check_Arg_Is_Local_Name (Arg1);
18763
18764 Type_Id := Get_Pragma_Arg (Arg1);
18765 Find_Type (Type_Id);
18766 Typ := Entity (Type_Id);
18767
18768 if Typ = Any_Type then
18769 return;
18770 end if;
18771
18772 -- A pragma that applies to a Ghost entity becomes Ghost for the
18773 -- purposes of legality checks and removal of ignored Ghost code.
18774
18775 Mark_Pragma_As_Ghost (N, Typ);
18776
18777 -- The remaining processing is simply to link the pragma on to
18778 -- the rep item chain, for processing when the type is frozen.
18779 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18780 -- mark the type as having predicates.
18781 -- If the current policy is Ignore mark the subtype accordingly.
18782 -- In the case of predicates we consider them enabled unless an
18783 -- Ignore is specified, to preserve existing warnings.
18784
18785 Set_Has_Predicates (Typ);
18786 Set_Predicates_Ignored (Typ,
18787 Present (Check_Policy_List)
18788 and then
18789 Policy_In_Effect (Name_Assertion_Policy) = Name_Ignore);
18790 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18791 end Predicate;
18792
18793 -----------------------
18794 -- Predicate_Failure --
18795 -----------------------
18796
18797 -- pragma Predicate_Failure
18798 -- ([Entity =>] type_LOCAL_NAME,
18799 -- [Message =>] string_EXPRESSION);
18800
18801 when Pragma_Predicate_Failure => Predicate_Failure : declare
18802 Discard : Boolean;
18803 Typ : Entity_Id;
18804 Type_Id : Node_Id;
18805
18806 begin
18807 GNAT_Pragma;
18808 Check_Arg_Count (2);
18809 Check_Optional_Identifier (Arg1, Name_Entity);
18810 Check_Optional_Identifier (Arg2, Name_Message);
18811
18812 Check_Arg_Is_Local_Name (Arg1);
18813
18814 Type_Id := Get_Pragma_Arg (Arg1);
18815 Find_Type (Type_Id);
18816 Typ := Entity (Type_Id);
18817
18818 if Typ = Any_Type then
18819 return;
18820 end if;
18821
18822 -- A pragma that applies to a Ghost entity becomes Ghost for the
18823 -- purposes of legality checks and removal of ignored Ghost code.
18824
18825 Mark_Pragma_As_Ghost (N, Typ);
18826
18827 -- The remaining processing is simply to link the pragma on to
18828 -- the rep item chain, for processing when the type is frozen.
18829 -- This is accomplished by a call to Rep_Item_Too_Late.
18830
18831 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18832 end Predicate_Failure;
18833
18834 ------------------
18835 -- Preelaborate --
18836 ------------------
18837
18838 -- pragma Preelaborate [(library_unit_NAME)];
18839
18840 -- Set the flag Is_Preelaborated of program unit name entity
18841
18842 when Pragma_Preelaborate => Preelaborate : declare
18843 Pa : constant Node_Id := Parent (N);
18844 Pk : constant Node_Kind := Nkind (Pa);
18845 Ent : Entity_Id;
18846
18847 begin
18848 Check_Ada_83_Warning;
18849 Check_Valid_Library_Unit_Pragma;
18850
18851 if Nkind (N) = N_Null_Statement then
18852 return;
18853 end if;
18854
18855 Ent := Find_Lib_Unit_Name;
18856
18857 -- A pragma that applies to a Ghost entity becomes Ghost for the
18858 -- purposes of legality checks and removal of ignored Ghost code.
18859
18860 Mark_Pragma_As_Ghost (N, Ent);
18861 Check_Duplicate_Pragma (Ent);
18862
18863 -- This filters out pragmas inside generic parents that show up
18864 -- inside instantiations. Pragmas that come from aspects in the
18865 -- unit are not ignored.
18866
18867 if Present (Ent) then
18868 if Pk = N_Package_Specification
18869 and then Present (Generic_Parent (Pa))
18870 and then not From_Aspect_Specification (N)
18871 then
18872 null;
18873
18874 else
18875 if not Debug_Flag_U then
18876 Set_Is_Preelaborated (Ent);
18877 Set_Suppress_Elaboration_Warnings (Ent);
18878 end if;
18879 end if;
18880 end if;
18881 end Preelaborate;
18882
18883 -------------------------------
18884 -- Prefix_Exception_Messages --
18885 -------------------------------
18886
18887 -- pragma Prefix_Exception_Messages;
18888
18889 when Pragma_Prefix_Exception_Messages =>
18890 GNAT_Pragma;
18891 Check_Valid_Configuration_Pragma;
18892 Check_Arg_Count (0);
18893 Prefix_Exception_Messages := True;
18894
18895 --------------
18896 -- Priority --
18897 --------------
18898
18899 -- pragma Priority (EXPRESSION);
18900
18901 when Pragma_Priority => Priority : declare
18902 P : constant Node_Id := Parent (N);
18903 Arg : Node_Id;
18904 Ent : Entity_Id;
18905
18906 begin
18907 Check_No_Identifiers;
18908 Check_Arg_Count (1);
18909
18910 -- Subprogram case
18911
18912 if Nkind (P) = N_Subprogram_Body then
18913 Check_In_Main_Program;
18914
18915 Ent := Defining_Unit_Name (Specification (P));
18916
18917 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18918 Ent := Defining_Identifier (Ent);
18919 end if;
18920
18921 Arg := Get_Pragma_Arg (Arg1);
18922 Analyze_And_Resolve (Arg, Standard_Integer);
18923
18924 -- Must be static
18925
18926 if not Is_OK_Static_Expression (Arg) then
18927 Flag_Non_Static_Expr
18928 ("main subprogram priority is not static!", Arg);
18929 raise Pragma_Exit;
18930
18931 -- If constraint error, then we already signalled an error
18932
18933 elsif Raises_Constraint_Error (Arg) then
18934 null;
18935
18936 -- Otherwise check in range except if Relaxed_RM_Semantics
18937 -- where we ignore the value if out of range.
18938
18939 else
18940 if not Relaxed_RM_Semantics
18941 and then not Is_In_Range (Arg, RTE (RE_Priority))
18942 then
18943 Error_Pragma_Arg
18944 ("main subprogram priority is out of range", Arg1);
18945 else
18946 Set_Main_Priority
18947 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
18948 end if;
18949 end if;
18950
18951 -- Load an arbitrary entity from System.Tasking.Stages or
18952 -- System.Tasking.Restricted.Stages (depending on the
18953 -- supported profile) to make sure that one of these packages
18954 -- is implicitly with'ed, since we need to have the tasking
18955 -- run time active for the pragma Priority to have any effect.
18956 -- Previously we with'ed the package System.Tasking, but this
18957 -- package does not trigger the required initialization of the
18958 -- run-time library.
18959
18960 declare
18961 Discard : Entity_Id;
18962 pragma Warnings (Off, Discard);
18963 begin
18964 if Restricted_Profile then
18965 Discard := RTE (RE_Activate_Restricted_Tasks);
18966 else
18967 Discard := RTE (RE_Activate_Tasks);
18968 end if;
18969 end;
18970
18971 -- Task or Protected, must be of type Integer
18972
18973 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18974 Arg := Get_Pragma_Arg (Arg1);
18975 Ent := Defining_Identifier (Parent (P));
18976
18977 -- The expression must be analyzed in the special manner
18978 -- described in "Handling of Default and Per-Object
18979 -- Expressions" in sem.ads.
18980
18981 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18982
18983 if not Is_OK_Static_Expression (Arg) then
18984 Check_Restriction (Static_Priorities, Arg);
18985 end if;
18986
18987 -- Anything else is incorrect
18988
18989 else
18990 Pragma_Misplaced;
18991 end if;
18992
18993 -- Check duplicate pragma before we chain the pragma in the Rep
18994 -- Item chain of Ent.
18995
18996 Check_Duplicate_Pragma (Ent);
18997 Record_Rep_Item (Ent, N);
18998 end Priority;
18999
19000 -----------------------------------
19001 -- Priority_Specific_Dispatching --
19002 -----------------------------------
19003
19004 -- pragma Priority_Specific_Dispatching (
19005 -- policy_IDENTIFIER,
19006 -- first_priority_EXPRESSION,
19007 -- last_priority_EXPRESSION);
19008
19009 when Pragma_Priority_Specific_Dispatching =>
19010 Priority_Specific_Dispatching : declare
19011 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
19012 -- This is the entity System.Any_Priority;
19013
19014 DP : Character;
19015 Lower_Bound : Node_Id;
19016 Upper_Bound : Node_Id;
19017 Lower_Val : Uint;
19018 Upper_Val : Uint;
19019
19020 begin
19021 Ada_2005_Pragma;
19022 Check_Arg_Count (3);
19023 Check_No_Identifiers;
19024 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
19025 Check_Valid_Configuration_Pragma;
19026 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
19027 DP := Fold_Upper (Name_Buffer (1));
19028
19029 Lower_Bound := Get_Pragma_Arg (Arg2);
19030 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
19031 Lower_Val := Expr_Value (Lower_Bound);
19032
19033 Upper_Bound := Get_Pragma_Arg (Arg3);
19034 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
19035 Upper_Val := Expr_Value (Upper_Bound);
19036
19037 -- It is not allowed to use Task_Dispatching_Policy and
19038 -- Priority_Specific_Dispatching in the same partition.
19039
19040 if Task_Dispatching_Policy /= ' ' then
19041 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19042 Error_Pragma
19043 ("pragma% incompatible with Task_Dispatching_Policy#");
19044
19045 -- Check lower bound in range
19046
19047 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19048 or else
19049 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
19050 then
19051 Error_Pragma_Arg
19052 ("first_priority is out of range", Arg2);
19053
19054 -- Check upper bound in range
19055
19056 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
19057 or else
19058 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
19059 then
19060 Error_Pragma_Arg
19061 ("last_priority is out of range", Arg3);
19062
19063 -- Check that the priority range is valid
19064
19065 elsif Lower_Val > Upper_Val then
19066 Error_Pragma
19067 ("last_priority_expression must be greater than or equal to "
19068 & "first_priority_expression");
19069
19070 -- Store the new policy, but always preserve System_Location since
19071 -- we like the error message with the run-time name.
19072
19073 else
19074 -- Check overlapping in the priority ranges specified in other
19075 -- Priority_Specific_Dispatching pragmas within the same
19076 -- partition. We can only check those we know about.
19077
19078 for J in
19079 Specific_Dispatching.First .. Specific_Dispatching.Last
19080 loop
19081 if Specific_Dispatching.Table (J).First_Priority in
19082 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19083 or else Specific_Dispatching.Table (J).Last_Priority in
19084 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
19085 then
19086 Error_Msg_Sloc :=
19087 Specific_Dispatching.Table (J).Pragma_Loc;
19088 Error_Pragma
19089 ("priority range overlaps with "
19090 & "Priority_Specific_Dispatching#");
19091 end if;
19092 end loop;
19093
19094 -- The use of Priority_Specific_Dispatching is incompatible
19095 -- with Task_Dispatching_Policy.
19096
19097 if Task_Dispatching_Policy /= ' ' then
19098 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
19099 Error_Pragma
19100 ("Priority_Specific_Dispatching incompatible "
19101 & "with Task_Dispatching_Policy#");
19102 end if;
19103
19104 -- The use of Priority_Specific_Dispatching forces ceiling
19105 -- locking policy.
19106
19107 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
19108 Error_Msg_Sloc := Locking_Policy_Sloc;
19109 Error_Pragma
19110 ("Priority_Specific_Dispatching incompatible "
19111 & "with Locking_Policy#");
19112
19113 -- Set the Ceiling_Locking policy, but preserve System_Location
19114 -- since we like the error message with the run time name.
19115
19116 else
19117 Locking_Policy := 'C';
19118
19119 if Locking_Policy_Sloc /= System_Location then
19120 Locking_Policy_Sloc := Loc;
19121 end if;
19122 end if;
19123
19124 -- Add entry in the table
19125
19126 Specific_Dispatching.Append
19127 ((Dispatching_Policy => DP,
19128 First_Priority => UI_To_Int (Lower_Val),
19129 Last_Priority => UI_To_Int (Upper_Val),
19130 Pragma_Loc => Loc));
19131 end if;
19132 end Priority_Specific_Dispatching;
19133
19134 -------------
19135 -- Profile --
19136 -------------
19137
19138 -- pragma Profile (profile_IDENTIFIER);
19139
19140 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
19141
19142 when Pragma_Profile =>
19143 Ada_2005_Pragma;
19144 Check_Arg_Count (1);
19145 Check_Valid_Configuration_Pragma;
19146 Check_No_Identifiers;
19147
19148 declare
19149 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19150
19151 begin
19152 if Chars (Argx) = Name_Ravenscar then
19153 Set_Ravenscar_Profile (Ravenscar, N);
19154
19155 elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then
19156 Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N);
19157
19158 elsif Chars (Argx) = Name_Restricted then
19159 Set_Profile_Restrictions
19160 (Restricted,
19161 N, Warn => Treat_Restrictions_As_Warnings);
19162
19163 elsif Chars (Argx) = Name_Rational then
19164 Set_Rational_Profile;
19165
19166 elsif Chars (Argx) = Name_No_Implementation_Extensions then
19167 Set_Profile_Restrictions
19168 (No_Implementation_Extensions,
19169 N, Warn => Treat_Restrictions_As_Warnings);
19170
19171 else
19172 Error_Pragma_Arg ("& is not a valid profile", Argx);
19173 end if;
19174 end;
19175
19176 ----------------------
19177 -- Profile_Warnings --
19178 ----------------------
19179
19180 -- pragma Profile_Warnings (profile_IDENTIFIER);
19181
19182 -- profile_IDENTIFIER => Restricted | Ravenscar
19183
19184 when Pragma_Profile_Warnings =>
19185 GNAT_Pragma;
19186 Check_Arg_Count (1);
19187 Check_Valid_Configuration_Pragma;
19188 Check_No_Identifiers;
19189
19190 declare
19191 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19192
19193 begin
19194 if Chars (Argx) = Name_Ravenscar then
19195 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
19196
19197 elsif Chars (Argx) = Name_Restricted then
19198 Set_Profile_Restrictions (Restricted, N, Warn => True);
19199
19200 elsif Chars (Argx) = Name_No_Implementation_Extensions then
19201 Set_Profile_Restrictions
19202 (No_Implementation_Extensions, N, Warn => True);
19203
19204 else
19205 Error_Pragma_Arg ("& is not a valid profile", Argx);
19206 end if;
19207 end;
19208
19209 --------------------------
19210 -- Propagate_Exceptions --
19211 --------------------------
19212
19213 -- pragma Propagate_Exceptions;
19214
19215 -- Note: this pragma is obsolete and has no effect
19216
19217 when Pragma_Propagate_Exceptions =>
19218 GNAT_Pragma;
19219 Check_Arg_Count (0);
19220
19221 if Warn_On_Obsolescent_Feature then
19222 Error_Msg_N
19223 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
19224 "and has no effect?j?", N);
19225 end if;
19226
19227 -----------------------------
19228 -- Provide_Shift_Operators --
19229 -----------------------------
19230
19231 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
19232
19233 when Pragma_Provide_Shift_Operators =>
19234 Provide_Shift_Operators : declare
19235 Ent : Entity_Id;
19236
19237 procedure Declare_Shift_Operator (Nam : Name_Id);
19238 -- Insert declaration and pragma Instrinsic for named shift op
19239
19240 ----------------------------
19241 -- Declare_Shift_Operator --
19242 ----------------------------
19243
19244 procedure Declare_Shift_Operator (Nam : Name_Id) is
19245 Func : Node_Id;
19246 Import : Node_Id;
19247
19248 begin
19249 Func :=
19250 Make_Subprogram_Declaration (Loc,
19251 Make_Function_Specification (Loc,
19252 Defining_Unit_Name =>
19253 Make_Defining_Identifier (Loc, Chars => Nam),
19254
19255 Result_Definition =>
19256 Make_Identifier (Loc, Chars => Chars (Ent)),
19257
19258 Parameter_Specifications => New_List (
19259 Make_Parameter_Specification (Loc,
19260 Defining_Identifier =>
19261 Make_Defining_Identifier (Loc, Name_Value),
19262 Parameter_Type =>
19263 Make_Identifier (Loc, Chars => Chars (Ent))),
19264
19265 Make_Parameter_Specification (Loc,
19266 Defining_Identifier =>
19267 Make_Defining_Identifier (Loc, Name_Amount),
19268 Parameter_Type =>
19269 New_Occurrence_Of (Standard_Natural, Loc)))));
19270
19271 Import :=
19272 Make_Pragma (Loc,
19273 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
19274 Pragma_Argument_Associations => New_List (
19275 Make_Pragma_Argument_Association (Loc,
19276 Expression => Make_Identifier (Loc, Name_Intrinsic)),
19277 Make_Pragma_Argument_Association (Loc,
19278 Expression => Make_Identifier (Loc, Nam))));
19279
19280 Insert_After (N, Import);
19281 Insert_After (N, Func);
19282 end Declare_Shift_Operator;
19283
19284 -- Start of processing for Provide_Shift_Operators
19285
19286 begin
19287 GNAT_Pragma;
19288 Check_Arg_Count (1);
19289 Check_Arg_Is_Local_Name (Arg1);
19290
19291 Arg1 := Get_Pragma_Arg (Arg1);
19292
19293 -- We must have an entity name
19294
19295 if not Is_Entity_Name (Arg1) then
19296 Error_Pragma_Arg
19297 ("pragma % must apply to integer first subtype", Arg1);
19298 end if;
19299
19300 -- If no Entity, means there was a prior error so ignore
19301
19302 if Present (Entity (Arg1)) then
19303 Ent := Entity (Arg1);
19304
19305 -- Apply error checks
19306
19307 if not Is_First_Subtype (Ent) then
19308 Error_Pragma_Arg
19309 ("cannot apply pragma %",
19310 "\& is not a first subtype",
19311 Arg1);
19312
19313 elsif not Is_Integer_Type (Ent) then
19314 Error_Pragma_Arg
19315 ("cannot apply pragma %",
19316 "\& is not an integer type",
19317 Arg1);
19318
19319 elsif Has_Shift_Operator (Ent) then
19320 Error_Pragma_Arg
19321 ("cannot apply pragma %",
19322 "\& already has declared shift operators",
19323 Arg1);
19324
19325 elsif Is_Frozen (Ent) then
19326 Error_Pragma_Arg
19327 ("pragma % appears too late",
19328 "\& is already frozen",
19329 Arg1);
19330 end if;
19331
19332 -- Now declare the operators. We do this during analysis rather
19333 -- than expansion, since we want the operators available if we
19334 -- are operating in -gnatc or ASIS mode.
19335
19336 Declare_Shift_Operator (Name_Rotate_Left);
19337 Declare_Shift_Operator (Name_Rotate_Right);
19338 Declare_Shift_Operator (Name_Shift_Left);
19339 Declare_Shift_Operator (Name_Shift_Right);
19340 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
19341 end if;
19342 end Provide_Shift_Operators;
19343
19344 ------------------
19345 -- Psect_Object --
19346 ------------------
19347
19348 -- pragma Psect_Object (
19349 -- [Internal =>] LOCAL_NAME,
19350 -- [, [External =>] EXTERNAL_SYMBOL]
19351 -- [, [Size =>] EXTERNAL_SYMBOL]);
19352
19353 when Pragma_Psect_Object | Pragma_Common_Object =>
19354 Psect_Object : declare
19355 Args : Args_List (1 .. 3);
19356 Names : constant Name_List (1 .. 3) := (
19357 Name_Internal,
19358 Name_External,
19359 Name_Size);
19360
19361 Internal : Node_Id renames Args (1);
19362 External : Node_Id renames Args (2);
19363 Size : Node_Id renames Args (3);
19364
19365 Def_Id : Entity_Id;
19366
19367 procedure Check_Arg (Arg : Node_Id);
19368 -- Checks that argument is either a string literal or an
19369 -- identifier, and posts error message if not.
19370
19371 ---------------
19372 -- Check_Arg --
19373 ---------------
19374
19375 procedure Check_Arg (Arg : Node_Id) is
19376 begin
19377 if not Nkind_In (Original_Node (Arg),
19378 N_String_Literal,
19379 N_Identifier)
19380 then
19381 Error_Pragma_Arg
19382 ("inappropriate argument for pragma %", Arg);
19383 end if;
19384 end Check_Arg;
19385
19386 -- Start of processing for Common_Object/Psect_Object
19387
19388 begin
19389 GNAT_Pragma;
19390 Gather_Associations (Names, Args);
19391 Process_Extended_Import_Export_Internal_Arg (Internal);
19392
19393 Def_Id := Entity (Internal);
19394
19395 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
19396 Error_Pragma_Arg
19397 ("pragma% must designate an object", Internal);
19398 end if;
19399
19400 Check_Arg (Internal);
19401
19402 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
19403 Error_Pragma_Arg
19404 ("cannot use pragma% for imported/exported object",
19405 Internal);
19406 end if;
19407
19408 if Is_Concurrent_Type (Etype (Internal)) then
19409 Error_Pragma_Arg
19410 ("cannot specify pragma % for task/protected object",
19411 Internal);
19412 end if;
19413
19414 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
19415 or else
19416 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
19417 then
19418 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
19419 end if;
19420
19421 if Ekind (Def_Id) = E_Constant then
19422 Error_Pragma_Arg
19423 ("cannot specify pragma % for a constant", Internal);
19424 end if;
19425
19426 if Is_Record_Type (Etype (Internal)) then
19427 declare
19428 Ent : Entity_Id;
19429 Decl : Entity_Id;
19430
19431 begin
19432 Ent := First_Entity (Etype (Internal));
19433 while Present (Ent) loop
19434 Decl := Declaration_Node (Ent);
19435
19436 if Ekind (Ent) = E_Component
19437 and then Nkind (Decl) = N_Component_Declaration
19438 and then Present (Expression (Decl))
19439 and then Warn_On_Export_Import
19440 then
19441 Error_Msg_N
19442 ("?x?object for pragma % has defaults", Internal);
19443 exit;
19444
19445 else
19446 Next_Entity (Ent);
19447 end if;
19448 end loop;
19449 end;
19450 end if;
19451
19452 if Present (Size) then
19453 Check_Arg (Size);
19454 end if;
19455
19456 if Present (External) then
19457 Check_Arg_Is_External_Name (External);
19458 end if;
19459
19460 -- If all error tests pass, link pragma on to the rep item chain
19461
19462 Record_Rep_Item (Def_Id, N);
19463 end Psect_Object;
19464
19465 ----------
19466 -- Pure --
19467 ----------
19468
19469 -- pragma Pure [(library_unit_NAME)];
19470
19471 when Pragma_Pure => Pure : declare
19472 Ent : Entity_Id;
19473
19474 begin
19475 Check_Ada_83_Warning;
19476
19477 -- If the pragma comes from a subprogram instantiation, nothing to
19478 -- check, this can happen at any level of nesting.
19479
19480 if Is_Wrapper_Package (Current_Scope) then
19481 return;
19482 else
19483 Check_Valid_Library_Unit_Pragma;
19484 end if;
19485
19486 if Nkind (N) = N_Null_Statement then
19487 return;
19488 end if;
19489
19490 Ent := Find_Lib_Unit_Name;
19491
19492 -- A pragma that applies to a Ghost entity becomes Ghost for the
19493 -- purposes of legality checks and removal of ignored Ghost code.
19494
19495 Mark_Pragma_As_Ghost (N, Ent);
19496
19497 if not Debug_Flag_U then
19498 Set_Is_Pure (Ent);
19499 Set_Has_Pragma_Pure (Ent);
19500 Set_Suppress_Elaboration_Warnings (Ent);
19501 end if;
19502 end Pure;
19503
19504 -------------------
19505 -- Pure_Function --
19506 -------------------
19507
19508 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
19509
19510 when Pragma_Pure_Function => Pure_Function : declare
19511 Def_Id : Entity_Id;
19512 E : Entity_Id;
19513 E_Id : Node_Id;
19514 Effective : Boolean := False;
19515
19516 begin
19517 GNAT_Pragma;
19518 Check_Arg_Count (1);
19519 Check_Optional_Identifier (Arg1, Name_Entity);
19520 Check_Arg_Is_Local_Name (Arg1);
19521 E_Id := Get_Pragma_Arg (Arg1);
19522
19523 if Error_Posted (E_Id) then
19524 return;
19525 end if;
19526
19527 -- Loop through homonyms (overloadings) of referenced entity
19528
19529 E := Entity (E_Id);
19530
19531 -- A pragma that applies to a Ghost entity becomes Ghost for the
19532 -- purposes of legality checks and removal of ignored Ghost code.
19533
19534 Mark_Pragma_As_Ghost (N, E);
19535
19536 if Present (E) then
19537 loop
19538 Def_Id := Get_Base_Subprogram (E);
19539
19540 if not Ekind_In (Def_Id, E_Function,
19541 E_Generic_Function,
19542 E_Operator)
19543 then
19544 Error_Pragma_Arg
19545 ("pragma% requires a function name", Arg1);
19546 end if;
19547
19548 Set_Is_Pure (Def_Id);
19549
19550 if not Has_Pragma_Pure_Function (Def_Id) then
19551 Set_Has_Pragma_Pure_Function (Def_Id);
19552 Effective := True;
19553 end if;
19554
19555 exit when From_Aspect_Specification (N);
19556 E := Homonym (E);
19557 exit when No (E) or else Scope (E) /= Current_Scope;
19558 end loop;
19559
19560 if not Effective
19561 and then Warn_On_Redundant_Constructs
19562 then
19563 Error_Msg_NE
19564 ("pragma Pure_Function on& is redundant?r?",
19565 N, Entity (E_Id));
19566 end if;
19567 end if;
19568 end Pure_Function;
19569
19570 --------------------
19571 -- Queuing_Policy --
19572 --------------------
19573
19574 -- pragma Queuing_Policy (policy_IDENTIFIER);
19575
19576 when Pragma_Queuing_Policy => declare
19577 QP : Character;
19578
19579 begin
19580 Check_Ada_83_Warning;
19581 Check_Arg_Count (1);
19582 Check_No_Identifiers;
19583 Check_Arg_Is_Queuing_Policy (Arg1);
19584 Check_Valid_Configuration_Pragma;
19585 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
19586 QP := Fold_Upper (Name_Buffer (1));
19587
19588 if Queuing_Policy /= ' '
19589 and then Queuing_Policy /= QP
19590 then
19591 Error_Msg_Sloc := Queuing_Policy_Sloc;
19592 Error_Pragma ("queuing policy incompatible with policy#");
19593
19594 -- Set new policy, but always preserve System_Location since we
19595 -- like the error message with the run time name.
19596
19597 else
19598 Queuing_Policy := QP;
19599
19600 if Queuing_Policy_Sloc /= System_Location then
19601 Queuing_Policy_Sloc := Loc;
19602 end if;
19603 end if;
19604 end;
19605
19606 --------------
19607 -- Rational --
19608 --------------
19609
19610 -- pragma Rational, for compatibility with foreign compiler
19611
19612 when Pragma_Rational =>
19613 Set_Rational_Profile;
19614
19615 ---------------------
19616 -- Refined_Depends --
19617 ---------------------
19618
19619 -- pragma Refined_Depends (DEPENDENCY_RELATION);
19620
19621 -- DEPENDENCY_RELATION ::=
19622 -- null
19623 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
19624
19625 -- DEPENDENCY_CLAUSE ::=
19626 -- OUTPUT_LIST =>[+] INPUT_LIST
19627 -- | NULL_DEPENDENCY_CLAUSE
19628
19629 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19630
19631 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19632
19633 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19634
19635 -- OUTPUT ::= NAME | FUNCTION_RESULT
19636 -- INPUT ::= NAME
19637
19638 -- where FUNCTION_RESULT is a function Result attribute_reference
19639
19640 -- Characteristics:
19641
19642 -- * Analysis - The annotation undergoes initial checks to verify
19643 -- the legal placement and context. Secondary checks fully analyze
19644 -- the dependency clauses/global list in:
19645
19646 -- Analyze_Refined_Depends_In_Decl_Part
19647
19648 -- * Expansion - None.
19649
19650 -- * Template - The annotation utilizes the generic template of the
19651 -- related subprogram body.
19652
19653 -- * Globals - Capture of global references must occur after full
19654 -- analysis.
19655
19656 -- * Instance - The annotation is instantiated automatically when
19657 -- the related generic subprogram body is instantiated.
19658
19659 when Pragma_Refined_Depends => Refined_Depends : declare
19660 Body_Id : Entity_Id;
19661 Legal : Boolean;
19662 Spec_Id : Entity_Id;
19663
19664 begin
19665 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
19666
19667 if Legal then
19668
19669 -- Chain the pragma on the contract for further processing by
19670 -- Analyze_Refined_Depends_In_Decl_Part.
19671
19672 Add_Contract_Item (N, Body_Id);
19673
19674 -- The legality checks of pragmas Refined_Depends and
19675 -- Refined_Global are affected by the SPARK mode in effect and
19676 -- the volatility of the context. In addition these two pragmas
19677 -- are subject to an inherent order:
19678
19679 -- 1) Refined_Global
19680 -- 2) Refined_Depends
19681
19682 -- Analyze all these pragmas in the order outlined above
19683
19684 Analyze_If_Present (Pragma_SPARK_Mode);
19685 Analyze_If_Present (Pragma_Volatile_Function);
19686 Analyze_If_Present (Pragma_Refined_Global);
19687 Analyze_Refined_Depends_In_Decl_Part (N);
19688 end if;
19689 end Refined_Depends;
19690
19691 --------------------
19692 -- Refined_Global --
19693 --------------------
19694
19695 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19696
19697 -- GLOBAL_SPECIFICATION ::=
19698 -- null
19699 -- | (GLOBAL_LIST)
19700 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
19701
19702 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19703
19704 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19705 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19706 -- GLOBAL_ITEM ::= NAME
19707
19708 -- Characteristics:
19709
19710 -- * Analysis - The annotation undergoes initial checks to verify
19711 -- the legal placement and context. Secondary checks fully analyze
19712 -- the dependency clauses/global list in:
19713
19714 -- Analyze_Refined_Global_In_Decl_Part
19715
19716 -- * Expansion - None.
19717
19718 -- * Template - The annotation utilizes the generic template of the
19719 -- related subprogram body.
19720
19721 -- * Globals - Capture of global references must occur after full
19722 -- analysis.
19723
19724 -- * Instance - The annotation is instantiated automatically when
19725 -- the related generic subprogram body is instantiated.
19726
19727 when Pragma_Refined_Global => Refined_Global : declare
19728 Body_Id : Entity_Id;
19729 Legal : Boolean;
19730 Spec_Id : Entity_Id;
19731
19732 begin
19733 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
19734
19735 if Legal then
19736
19737 -- Chain the pragma on the contract for further processing by
19738 -- Analyze_Refined_Global_In_Decl_Part.
19739
19740 Add_Contract_Item (N, Body_Id);
19741
19742 -- The legality checks of pragmas Refined_Depends and
19743 -- Refined_Global are affected by the SPARK mode in effect and
19744 -- the volatility of the context. In addition these two pragmas
19745 -- are subject to an inherent order:
19746
19747 -- 1) Refined_Global
19748 -- 2) Refined_Depends
19749
19750 -- Analyze all these pragmas in the order outlined above
19751
19752 Analyze_If_Present (Pragma_SPARK_Mode);
19753 Analyze_If_Present (Pragma_Volatile_Function);
19754 Analyze_Refined_Global_In_Decl_Part (N);
19755 Analyze_If_Present (Pragma_Refined_Depends);
19756 end if;
19757 end Refined_Global;
19758
19759 ------------------
19760 -- Refined_Post --
19761 ------------------
19762
19763 -- pragma Refined_Post (boolean_EXPRESSION);
19764
19765 -- Characteristics:
19766
19767 -- * Analysis - The annotation is fully analyzed immediately upon
19768 -- elaboration as it cannot forward reference entities.
19769
19770 -- * Expansion - The annotation is expanded during the expansion of
19771 -- the related subprogram body contract as performed in:
19772
19773 -- Expand_Subprogram_Contract
19774
19775 -- * Template - The annotation utilizes the generic template of the
19776 -- related subprogram body.
19777
19778 -- * Globals - Capture of global references must occur after full
19779 -- analysis.
19780
19781 -- * Instance - The annotation is instantiated automatically when
19782 -- the related generic subprogram body is instantiated.
19783
19784 when Pragma_Refined_Post => Refined_Post : declare
19785 Body_Id : Entity_Id;
19786 Legal : Boolean;
19787 Spec_Id : Entity_Id;
19788
19789 begin
19790 Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal);
19791
19792 -- Fully analyze the pragma when it appears inside a subprogram
19793 -- body because it cannot benefit from forward references.
19794
19795 if Legal then
19796
19797 -- Chain the pragma on the contract for completeness
19798
19799 Add_Contract_Item (N, Body_Id);
19800
19801 -- The legality checks of pragma Refined_Post are affected by
19802 -- the SPARK mode in effect and the volatility of the context.
19803 -- Analyze all pragmas in a specific order.
19804
19805 Analyze_If_Present (Pragma_SPARK_Mode);
19806 Analyze_If_Present (Pragma_Volatile_Function);
19807 Analyze_Pre_Post_Condition_In_Decl_Part (N);
19808
19809 -- Currently it is not possible to inline pre/postconditions on
19810 -- a subprogram subject to pragma Inline_Always.
19811
19812 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
19813 end if;
19814 end Refined_Post;
19815
19816 -------------------
19817 -- Refined_State --
19818 -------------------
19819
19820 -- pragma Refined_State (REFINEMENT_LIST);
19821
19822 -- REFINEMENT_LIST ::=
19823 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19824
19825 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19826
19827 -- CONSTITUENT_LIST ::=
19828 -- null
19829 -- | CONSTITUENT
19830 -- | (CONSTITUENT {, CONSTITUENT})
19831
19832 -- CONSTITUENT ::= object_NAME | state_NAME
19833
19834 -- Characteristics:
19835
19836 -- * Analysis - The annotation undergoes initial checks to verify
19837 -- the legal placement and context. Secondary checks preanalyze the
19838 -- refinement clauses in:
19839
19840 -- Analyze_Refined_State_In_Decl_Part
19841
19842 -- * Expansion - None.
19843
19844 -- * Template - The annotation utilizes the template of the related
19845 -- package body.
19846
19847 -- * Globals - Capture of global references must occur after full
19848 -- analysis.
19849
19850 -- * Instance - The annotation is instantiated automatically when
19851 -- the related generic package body is instantiated.
19852
19853 when Pragma_Refined_State => Refined_State : declare
19854 Pack_Decl : Node_Id;
19855 Spec_Id : Entity_Id;
19856
19857 begin
19858 GNAT_Pragma;
19859 Check_No_Identifiers;
19860 Check_Arg_Count (1);
19861
19862 Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True);
19863
19864 -- Ensure the proper placement of the pragma. Refined states must
19865 -- be associated with a package body.
19866
19867 if Nkind (Pack_Decl) = N_Package_Body then
19868 null;
19869
19870 -- Otherwise the pragma is associated with an illegal construct
19871
19872 else
19873 Pragma_Misplaced;
19874 return;
19875 end if;
19876
19877 Spec_Id := Corresponding_Spec (Pack_Decl);
19878
19879 -- Chain the pragma on the contract for further processing by
19880 -- Analyze_Refined_State_In_Decl_Part.
19881
19882 Add_Contract_Item (N, Defining_Entity (Pack_Decl));
19883
19884 -- The legality checks of pragma Refined_State are affected by the
19885 -- SPARK mode in effect. Analyze all pragmas in a specific order.
19886
19887 Analyze_If_Present (Pragma_SPARK_Mode);
19888
19889 -- A pragma that applies to a Ghost entity becomes Ghost for the
19890 -- purposes of legality checks and removal of ignored Ghost code.
19891
19892 Mark_Pragma_As_Ghost (N, Spec_Id);
19893
19894 -- State refinement is allowed only when the corresponding package
19895 -- declaration has non-null pragma Abstract_State. Refinement not
19896 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19897
19898 if SPARK_Mode /= Off
19899 and then
19900 (No (Abstract_States (Spec_Id))
19901 or else Has_Null_Abstract_State (Spec_Id))
19902 then
19903 Error_Msg_NE
19904 ("useless refinement, package & does not define abstract "
19905 & "states", N, Spec_Id);
19906 return;
19907 end if;
19908 end Refined_State;
19909
19910 -----------------------
19911 -- Relative_Deadline --
19912 -----------------------
19913
19914 -- pragma Relative_Deadline (time_span_EXPRESSION);
19915
19916 when Pragma_Relative_Deadline => Relative_Deadline : declare
19917 P : constant Node_Id := Parent (N);
19918 Arg : Node_Id;
19919
19920 begin
19921 Ada_2005_Pragma;
19922 Check_No_Identifiers;
19923 Check_Arg_Count (1);
19924
19925 Arg := Get_Pragma_Arg (Arg1);
19926
19927 -- The expression must be analyzed in the special manner described
19928 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19929
19930 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
19931
19932 -- Subprogram case
19933
19934 if Nkind (P) = N_Subprogram_Body then
19935 Check_In_Main_Program;
19936
19937 -- Only Task and subprogram cases allowed
19938
19939 elsif Nkind (P) /= N_Task_Definition then
19940 Pragma_Misplaced;
19941 end if;
19942
19943 -- Check duplicate pragma before we set the corresponding flag
19944
19945 if Has_Relative_Deadline_Pragma (P) then
19946 Error_Pragma ("duplicate pragma% not allowed");
19947 end if;
19948
19949 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19950 -- Relative_Deadline pragma node cannot be inserted in the Rep
19951 -- Item chain of Ent since it is rewritten by the expander as a
19952 -- procedure call statement that will break the chain.
19953
19954 Set_Has_Relative_Deadline_Pragma (P);
19955 end Relative_Deadline;
19956
19957 ------------------------
19958 -- Remote_Access_Type --
19959 ------------------------
19960
19961 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19962
19963 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
19964 E : Entity_Id;
19965
19966 begin
19967 GNAT_Pragma;
19968 Check_Arg_Count (1);
19969 Check_Optional_Identifier (Arg1, Name_Entity);
19970 Check_Arg_Is_Local_Name (Arg1);
19971
19972 E := Entity (Get_Pragma_Arg (Arg1));
19973
19974 -- A pragma that applies to a Ghost entity becomes Ghost for the
19975 -- purposes of legality checks and removal of ignored Ghost code.
19976
19977 Mark_Pragma_As_Ghost (N, E);
19978
19979 if Nkind (Parent (E)) = N_Formal_Type_Declaration
19980 and then Ekind (E) = E_General_Access_Type
19981 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
19982 and then Scope (Root_Type (Directly_Designated_Type (E)))
19983 = Scope (E)
19984 and then Is_Valid_Remote_Object_Type
19985 (Root_Type (Directly_Designated_Type (E)))
19986 then
19987 Set_Is_Remote_Types (E);
19988
19989 else
19990 Error_Pragma_Arg
19991 ("pragma% applies only to formal access to classwide types",
19992 Arg1);
19993 end if;
19994 end Remote_Access_Type;
19995
19996 ---------------------------
19997 -- Remote_Call_Interface --
19998 ---------------------------
19999
20000 -- pragma Remote_Call_Interface [(library_unit_NAME)];
20001
20002 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
20003 Cunit_Node : Node_Id;
20004 Cunit_Ent : Entity_Id;
20005 K : Node_Kind;
20006
20007 begin
20008 Check_Ada_83_Warning;
20009 Check_Valid_Library_Unit_Pragma;
20010
20011 if Nkind (N) = N_Null_Statement then
20012 return;
20013 end if;
20014
20015 Cunit_Node := Cunit (Current_Sem_Unit);
20016 K := Nkind (Unit (Cunit_Node));
20017 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20018
20019 -- A pragma that applies to a Ghost entity becomes Ghost for the
20020 -- purposes of legality checks and removal of ignored Ghost code.
20021
20022 Mark_Pragma_As_Ghost (N, Cunit_Ent);
20023
20024 if K = N_Package_Declaration
20025 or else K = N_Generic_Package_Declaration
20026 or else K = N_Subprogram_Declaration
20027 or else K = N_Generic_Subprogram_Declaration
20028 or else (K = N_Subprogram_Body
20029 and then Acts_As_Spec (Unit (Cunit_Node)))
20030 then
20031 null;
20032 else
20033 Error_Pragma (
20034 "pragma% must apply to package or subprogram declaration");
20035 end if;
20036
20037 Set_Is_Remote_Call_Interface (Cunit_Ent);
20038 end Remote_Call_Interface;
20039
20040 ------------------
20041 -- Remote_Types --
20042 ------------------
20043
20044 -- pragma Remote_Types [(library_unit_NAME)];
20045
20046 when Pragma_Remote_Types => Remote_Types : declare
20047 Cunit_Node : Node_Id;
20048 Cunit_Ent : Entity_Id;
20049
20050 begin
20051 Check_Ada_83_Warning;
20052 Check_Valid_Library_Unit_Pragma;
20053
20054 if Nkind (N) = N_Null_Statement then
20055 return;
20056 end if;
20057
20058 Cunit_Node := Cunit (Current_Sem_Unit);
20059 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20060
20061 -- A pragma that applies to a Ghost entity becomes Ghost for the
20062 -- purposes of legality checks and removal of ignored Ghost code.
20063
20064 Mark_Pragma_As_Ghost (N, Cunit_Ent);
20065
20066 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
20067 N_Generic_Package_Declaration)
20068 then
20069 Error_Pragma
20070 ("pragma% can only apply to a package declaration");
20071 end if;
20072
20073 Set_Is_Remote_Types (Cunit_Ent);
20074 end Remote_Types;
20075
20076 ---------------
20077 -- Ravenscar --
20078 ---------------
20079
20080 -- pragma Ravenscar;
20081
20082 when Pragma_Ravenscar =>
20083 GNAT_Pragma;
20084 Check_Arg_Count (0);
20085 Check_Valid_Configuration_Pragma;
20086 Set_Ravenscar_Profile (Ravenscar, N);
20087
20088 if Warn_On_Obsolescent_Feature then
20089 Error_Msg_N
20090 ("pragma Ravenscar is an obsolescent feature?j?", N);
20091 Error_Msg_N
20092 ("|use pragma Profile (Ravenscar) instead?j?", N);
20093 end if;
20094
20095 -------------------------
20096 -- Restricted_Run_Time --
20097 -------------------------
20098
20099 -- pragma Restricted_Run_Time;
20100
20101 when Pragma_Restricted_Run_Time =>
20102 GNAT_Pragma;
20103 Check_Arg_Count (0);
20104 Check_Valid_Configuration_Pragma;
20105 Set_Profile_Restrictions
20106 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
20107
20108 if Warn_On_Obsolescent_Feature then
20109 Error_Msg_N
20110 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
20111 N);
20112 Error_Msg_N
20113 ("|use pragma Profile (Restricted) instead?j?", N);
20114 end if;
20115
20116 ------------------
20117 -- Restrictions --
20118 ------------------
20119
20120 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
20121
20122 -- RESTRICTION ::=
20123 -- restriction_IDENTIFIER
20124 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20125
20126 when Pragma_Restrictions =>
20127 Process_Restrictions_Or_Restriction_Warnings
20128 (Warn => Treat_Restrictions_As_Warnings);
20129
20130 --------------------------
20131 -- Restriction_Warnings --
20132 --------------------------
20133
20134 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
20135
20136 -- RESTRICTION ::=
20137 -- restriction_IDENTIFIER
20138 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20139
20140 when Pragma_Restriction_Warnings =>
20141 GNAT_Pragma;
20142 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
20143
20144 ----------------
20145 -- Reviewable --
20146 ----------------
20147
20148 -- pragma Reviewable;
20149
20150 when Pragma_Reviewable =>
20151 Check_Ada_83_Warning;
20152 Check_Arg_Count (0);
20153
20154 -- Call dummy debugging function rv. This is done to assist front
20155 -- end debugging. By placing a Reviewable pragma in the source
20156 -- program, a breakpoint on rv catches this place in the source,
20157 -- allowing convenient stepping to the point of interest.
20158
20159 rv;
20160
20161 --------------------------
20162 -- Short_Circuit_And_Or --
20163 --------------------------
20164
20165 -- pragma Short_Circuit_And_Or;
20166
20167 when Pragma_Short_Circuit_And_Or =>
20168 GNAT_Pragma;
20169 Check_Arg_Count (0);
20170 Check_Valid_Configuration_Pragma;
20171 Short_Circuit_And_Or := True;
20172
20173 -------------------
20174 -- Share_Generic --
20175 -------------------
20176
20177 -- pragma Share_Generic (GNAME {, GNAME});
20178
20179 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
20180
20181 when Pragma_Share_Generic =>
20182 GNAT_Pragma;
20183 Process_Generic_List;
20184
20185 ------------
20186 -- Shared --
20187 ------------
20188
20189 -- pragma Shared (LOCAL_NAME);
20190
20191 when Pragma_Shared =>
20192 GNAT_Pragma;
20193 Process_Atomic_Independent_Shared_Volatile;
20194
20195 --------------------
20196 -- Shared_Passive --
20197 --------------------
20198
20199 -- pragma Shared_Passive [(library_unit_NAME)];
20200
20201 -- Set the flag Is_Shared_Passive of program unit name entity
20202
20203 when Pragma_Shared_Passive => Shared_Passive : declare
20204 Cunit_Node : Node_Id;
20205 Cunit_Ent : Entity_Id;
20206
20207 begin
20208 Check_Ada_83_Warning;
20209 Check_Valid_Library_Unit_Pragma;
20210
20211 if Nkind (N) = N_Null_Statement then
20212 return;
20213 end if;
20214
20215 Cunit_Node := Cunit (Current_Sem_Unit);
20216 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
20217
20218 -- A pragma that applies to a Ghost entity becomes Ghost for the
20219 -- purposes of legality checks and removal of ignored Ghost code.
20220
20221 Mark_Pragma_As_Ghost (N, Cunit_Ent);
20222
20223 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
20224 N_Generic_Package_Declaration)
20225 then
20226 Error_Pragma
20227 ("pragma% can only apply to a package declaration");
20228 end if;
20229
20230 Set_Is_Shared_Passive (Cunit_Ent);
20231 end Shared_Passive;
20232
20233 -----------------------
20234 -- Short_Descriptors --
20235 -----------------------
20236
20237 -- pragma Short_Descriptors;
20238
20239 -- Recognize and validate, but otherwise ignore
20240
20241 when Pragma_Short_Descriptors =>
20242 GNAT_Pragma;
20243 Check_Arg_Count (0);
20244 Check_Valid_Configuration_Pragma;
20245
20246 ------------------------------
20247 -- Simple_Storage_Pool_Type --
20248 ------------------------------
20249
20250 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
20251
20252 when Pragma_Simple_Storage_Pool_Type =>
20253 Simple_Storage_Pool_Type : declare
20254 Typ : Entity_Id;
20255 Type_Id : Node_Id;
20256
20257 begin
20258 GNAT_Pragma;
20259 Check_Arg_Count (1);
20260 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20261
20262 Type_Id := Get_Pragma_Arg (Arg1);
20263 Find_Type (Type_Id);
20264 Typ := Entity (Type_Id);
20265
20266 if Typ = Any_Type then
20267 return;
20268 end if;
20269
20270 -- A pragma that applies to a Ghost entity becomes Ghost for the
20271 -- purposes of legality checks and removal of ignored Ghost code.
20272
20273 Mark_Pragma_As_Ghost (N, Typ);
20274
20275 -- We require the pragma to apply to a type declared in a package
20276 -- declaration, but not (immediately) within a package body.
20277
20278 if Ekind (Current_Scope) /= E_Package
20279 or else In_Package_Body (Current_Scope)
20280 then
20281 Error_Pragma
20282 ("pragma% can only apply to type declared immediately "
20283 & "within a package declaration");
20284 end if;
20285
20286 -- A simple storage pool type must be an immutably limited record
20287 -- or private type. If the pragma is given for a private type,
20288 -- the full type is similarly restricted (which is checked later
20289 -- in Freeze_Entity).
20290
20291 if Is_Record_Type (Typ)
20292 and then not Is_Limited_View (Typ)
20293 then
20294 Error_Pragma
20295 ("pragma% can only apply to explicitly limited record type");
20296
20297 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
20298 Error_Pragma
20299 ("pragma% can only apply to a private type that is limited");
20300
20301 elsif not Is_Record_Type (Typ)
20302 and then not Is_Private_Type (Typ)
20303 then
20304 Error_Pragma
20305 ("pragma% can only apply to limited record or private type");
20306 end if;
20307
20308 Record_Rep_Item (Typ, N);
20309 end Simple_Storage_Pool_Type;
20310
20311 ----------------------
20312 -- Source_File_Name --
20313 ----------------------
20314
20315 -- There are five forms for this pragma:
20316
20317 -- pragma Source_File_Name (
20318 -- [UNIT_NAME =>] unit_NAME,
20319 -- BODY_FILE_NAME => STRING_LITERAL
20320 -- [, [INDEX =>] INTEGER_LITERAL]);
20321
20322 -- pragma Source_File_Name (
20323 -- [UNIT_NAME =>] unit_NAME,
20324 -- SPEC_FILE_NAME => STRING_LITERAL
20325 -- [, [INDEX =>] INTEGER_LITERAL]);
20326
20327 -- pragma Source_File_Name (
20328 -- BODY_FILE_NAME => STRING_LITERAL
20329 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20330 -- [, CASING => CASING_SPEC]);
20331
20332 -- pragma Source_File_Name (
20333 -- SPEC_FILE_NAME => STRING_LITERAL
20334 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20335 -- [, CASING => CASING_SPEC]);
20336
20337 -- pragma Source_File_Name (
20338 -- SUBUNIT_FILE_NAME => STRING_LITERAL
20339 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20340 -- [, CASING => CASING_SPEC]);
20341
20342 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
20343
20344 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
20345 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
20346 -- only be used when no project file is used, while SFNP can only be
20347 -- used when a project file is used.
20348
20349 -- No processing here. Processing was completed during parsing, since
20350 -- we need to have file names set as early as possible. Units are
20351 -- loaded well before semantic processing starts.
20352
20353 -- The only processing we defer to this point is the check for
20354 -- correct placement.
20355
20356 when Pragma_Source_File_Name =>
20357 GNAT_Pragma;
20358 Check_Valid_Configuration_Pragma;
20359
20360 ------------------------------
20361 -- Source_File_Name_Project --
20362 ------------------------------
20363
20364 -- See Source_File_Name for syntax
20365
20366 -- No processing here. Processing was completed during parsing, since
20367 -- we need to have file names set as early as possible. Units are
20368 -- loaded well before semantic processing starts.
20369
20370 -- The only processing we defer to this point is the check for
20371 -- correct placement.
20372
20373 when Pragma_Source_File_Name_Project =>
20374 GNAT_Pragma;
20375 Check_Valid_Configuration_Pragma;
20376
20377 -- Check that a pragma Source_File_Name_Project is used only in a
20378 -- configuration pragmas file.
20379
20380 -- Pragmas Source_File_Name_Project should only be generated by
20381 -- the Project Manager in configuration pragmas files.
20382
20383 -- This is really an ugly test. It seems to depend on some
20384 -- accidental and undocumented property. At the very least it
20385 -- needs to be documented, but it would be better to have a
20386 -- clean way of testing if we are in a configuration file???
20387
20388 if Present (Parent (N)) then
20389 Error_Pragma
20390 ("pragma% can only appear in a configuration pragmas file");
20391 end if;
20392
20393 ----------------------
20394 -- Source_Reference --
20395 ----------------------
20396
20397 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
20398
20399 -- Nothing to do, all processing completed in Par.Prag, since we need
20400 -- the information for possible parser messages that are output.
20401
20402 when Pragma_Source_Reference =>
20403 GNAT_Pragma;
20404
20405 ----------------
20406 -- SPARK_Mode --
20407 ----------------
20408
20409 -- pragma SPARK_Mode [(On | Off)];
20410
20411 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
20412 Mode_Id : SPARK_Mode_Type;
20413
20414 procedure Check_Pragma_Conformance
20415 (Context_Pragma : Node_Id;
20416 Entity : Entity_Id;
20417 Entity_Pragma : Node_Id);
20418 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
20419 -- conformance of pragma N depending the following scenarios:
20420 --
20421 -- If pragma Context_Pragma is not Empty, verify that pragma N is
20422 -- compatible with the pragma Context_Pragma that was inherited
20423 -- from the context:
20424 -- * If the mode of Context_Pragma is ON, then the new mode can
20425 -- be anything.
20426 -- * If the mode of Context_Pragma is OFF, then the only allowed
20427 -- new mode is also OFF. Emit error if this is not the case.
20428 --
20429 -- If Entity is not Empty, verify that pragma N is compatible with
20430 -- pragma Entity_Pragma that belongs to Entity.
20431 -- * If Entity_Pragma is Empty, always issue an error as this
20432 -- corresponds to the case where a previous section of Entity
20433 -- has no SPARK_Mode set.
20434 -- * If the mode of Entity_Pragma is ON, then the new mode can
20435 -- be anything.
20436 -- * If the mode of Entity_Pragma is OFF, then the only allowed
20437 -- new mode is also OFF. Emit error if this is not the case.
20438
20439 procedure Check_Library_Level_Entity (E : Entity_Id);
20440 -- Subsidiary to routines Process_xxx. Verify that the related
20441 -- entity E subject to pragma SPARK_Mode is library-level.
20442
20443 procedure Process_Body (Decl : Node_Id);
20444 -- Verify the legality of pragma SPARK_Mode when it appears as the
20445 -- top of the body declarations of entry, package, protected unit,
20446 -- subprogram or task unit body denoted by Decl.
20447
20448 procedure Process_Overloadable (Decl : Node_Id);
20449 -- Verify the legality of pragma SPARK_Mode when it applies to an
20450 -- entry or [generic] subprogram declaration denoted by Decl.
20451
20452 procedure Process_Private_Part (Decl : Node_Id);
20453 -- Verify the legality of pragma SPARK_Mode when it appears at the
20454 -- top of the private declarations of a package spec, protected or
20455 -- task unit declaration denoted by Decl.
20456
20457 procedure Process_Statement_Part (Decl : Node_Id);
20458 -- Verify the legality of pragma SPARK_Mode when it appears at the
20459 -- top of the statement sequence of a package body denoted by node
20460 -- Decl.
20461
20462 procedure Process_Visible_Part (Decl : Node_Id);
20463 -- Verify the legality of pragma SPARK_Mode when it appears at the
20464 -- top of the visible declarations of a package spec, protected or
20465 -- task unit declaration denoted by Decl. The routine is also used
20466 -- on protected or task units declared without a definition.
20467
20468 procedure Set_SPARK_Context;
20469 -- Subsidiary to routines Process_xxx. Set the global variables
20470 -- which represent the mode of the context from pragma N. Ensure
20471 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
20472
20473 ------------------------------
20474 -- Check_Pragma_Conformance --
20475 ------------------------------
20476
20477 procedure Check_Pragma_Conformance
20478 (Context_Pragma : Node_Id;
20479 Entity : Entity_Id;
20480 Entity_Pragma : Node_Id)
20481 is
20482 Err_Id : Entity_Id;
20483 Err_N : Node_Id;
20484
20485 begin
20486 -- The current pragma may appear without an argument. If this
20487 -- is the case, associate all error messages with the pragma
20488 -- itself.
20489
20490 if Present (Arg1) then
20491 Err_N := Arg1;
20492 else
20493 Err_N := N;
20494 end if;
20495
20496 -- The mode of the current pragma is compared against that of
20497 -- an enclosing context.
20498
20499 if Present (Context_Pragma) then
20500 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
20501
20502 -- Issue an error if the new mode is less restrictive than
20503 -- that of the context.
20504
20505 if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off
20506 and then Get_SPARK_Mode_From_Annotation (N) = On
20507 then
20508 Error_Msg_N
20509 ("cannot change SPARK_Mode from Off to On", Err_N);
20510 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
20511 Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N);
20512 raise Pragma_Exit;
20513 end if;
20514 end if;
20515
20516 -- The mode of the current pragma is compared against that of
20517 -- an initial package, protected type, subprogram or task type
20518 -- declaration.
20519
20520 if Present (Entity) then
20521
20522 -- A simple protected or task type is transformed into an
20523 -- anonymous type whose name cannot be used to issue error
20524 -- messages. Recover the original entity of the type.
20525
20526 if Ekind_In (Entity, E_Protected_Type, E_Task_Type) then
20527 Err_Id :=
20528 Defining_Entity
20529 (Original_Node (Unit_Declaration_Node (Entity)));
20530 else
20531 Err_Id := Entity;
20532 end if;
20533
20534 -- Both the initial declaration and the completion carry
20535 -- SPARK_Mode pragmas.
20536
20537 if Present (Entity_Pragma) then
20538 pragma Assert (Nkind (Entity_Pragma) = N_Pragma);
20539
20540 -- Issue an error if the new mode is less restrictive
20541 -- than that of the initial declaration.
20542
20543 if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off
20544 and then Get_SPARK_Mode_From_Annotation (N) = On
20545 then
20546 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
20547 Error_Msg_Sloc := Sloc (Entity_Pragma);
20548 Error_Msg_NE
20549 ("\value Off was set for SPARK_Mode on&#",
20550 Err_N, Err_Id);
20551 raise Pragma_Exit;
20552 end if;
20553
20554 -- Otherwise the initial declaration lacks a SPARK_Mode
20555 -- pragma in which case the current pragma is illegal as
20556 -- it cannot "complete".
20557
20558 else
20559 Error_Msg_N ("incorrect use of SPARK_Mode", Err_N);
20560 Error_Msg_Sloc := Sloc (Err_Id);
20561 Error_Msg_NE
20562 ("\no value was set for SPARK_Mode on&#",
20563 Err_N, Err_Id);
20564 raise Pragma_Exit;
20565 end if;
20566 end if;
20567 end Check_Pragma_Conformance;
20568
20569 --------------------------------
20570 -- Check_Library_Level_Entity --
20571 --------------------------------
20572
20573 procedure Check_Library_Level_Entity (E : Entity_Id) is
20574 procedure Add_Entity_To_Name_Buffer;
20575 -- Add the E_Kind of entity E to the name buffer
20576
20577 -------------------------------
20578 -- Add_Entity_To_Name_Buffer --
20579 -------------------------------
20580
20581 procedure Add_Entity_To_Name_Buffer is
20582 begin
20583 if Ekind_In (E, E_Entry, E_Entry_Family) then
20584 Add_Str_To_Name_Buffer ("entry");
20585
20586 elsif Ekind_In (E, E_Generic_Package,
20587 E_Package,
20588 E_Package_Body)
20589 then
20590 Add_Str_To_Name_Buffer ("package");
20591
20592 elsif Ekind_In (E, E_Protected_Body, E_Protected_Type) then
20593 Add_Str_To_Name_Buffer ("protected type");
20594
20595 elsif Ekind_In (E, E_Function,
20596 E_Generic_Function,
20597 E_Generic_Procedure,
20598 E_Procedure,
20599 E_Subprogram_Body)
20600 then
20601 Add_Str_To_Name_Buffer ("subprogram");
20602
20603 else
20604 pragma Assert (Ekind_In (E, E_Task_Body, E_Task_Type));
20605 Add_Str_To_Name_Buffer ("task type");
20606 end if;
20607 end Add_Entity_To_Name_Buffer;
20608
20609 -- Local variables
20610
20611 Msg_1 : constant String := "incorrect placement of pragma%";
20612 Msg_2 : Name_Id;
20613
20614 -- Start of processing for Check_Library_Level_Entity
20615
20616 begin
20617 if not Is_Library_Level_Entity (E) then
20618 Error_Msg_Name_1 := Pname;
20619 Error_Msg_N (Fix_Error (Msg_1), N);
20620
20621 Name_Len := 0;
20622 Add_Str_To_Name_Buffer ("\& is not a library-level ");
20623 Add_Entity_To_Name_Buffer;
20624
20625 Msg_2 := Name_Find;
20626 Error_Msg_NE (Get_Name_String (Msg_2), N, E);
20627
20628 raise Pragma_Exit;
20629 end if;
20630 end Check_Library_Level_Entity;
20631
20632 ------------------
20633 -- Process_Body --
20634 ------------------
20635
20636 procedure Process_Body (Decl : Node_Id) is
20637 Body_Id : constant Entity_Id := Defining_Entity (Decl);
20638 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
20639
20640 begin
20641 -- Ignore pragma when applied to the special body created for
20642 -- inlining, recognized by its internal name _Parent.
20643
20644 if Chars (Body_Id) = Name_uParent then
20645 return;
20646 end if;
20647
20648 Check_Library_Level_Entity (Body_Id);
20649
20650 -- For entry bodies, verify the legality against:
20651 -- * The mode of the context
20652 -- * The mode of the spec (if any)
20653
20654 if Nkind_In (Decl, N_Entry_Body, N_Subprogram_Body) then
20655
20656 -- A stand alone subprogram body
20657
20658 if Body_Id = Spec_Id then
20659 Check_Pragma_Conformance
20660 (Context_Pragma => SPARK_Pragma (Body_Id),
20661 Entity => Empty,
20662 Entity_Pragma => Empty);
20663
20664 -- An entry or subprogram body that completes a previous
20665 -- declaration.
20666
20667 else
20668 Check_Pragma_Conformance
20669 (Context_Pragma => SPARK_Pragma (Body_Id),
20670 Entity => Spec_Id,
20671 Entity_Pragma => SPARK_Pragma (Spec_Id));
20672 end if;
20673
20674 Set_SPARK_Context;
20675 Set_SPARK_Pragma (Body_Id, N);
20676 Set_SPARK_Pragma_Inherited (Body_Id, False);
20677
20678 -- For package bodies, verify the legality against:
20679 -- * The mode of the context
20680 -- * The mode of the private part
20681
20682 -- This case is separated from protected and task bodies
20683 -- because the statement part of the package body inherits
20684 -- the mode of the body declarations.
20685
20686 elsif Nkind (Decl) = N_Package_Body then
20687 Check_Pragma_Conformance
20688 (Context_Pragma => SPARK_Pragma (Body_Id),
20689 Entity => Spec_Id,
20690 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
20691
20692 Set_SPARK_Context;
20693 Set_SPARK_Pragma (Body_Id, N);
20694 Set_SPARK_Pragma_Inherited (Body_Id, False);
20695 Set_SPARK_Aux_Pragma (Body_Id, N);
20696 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
20697
20698 -- For protected and task bodies, verify the legality against:
20699 -- * The mode of the context
20700 -- * The mode of the private part
20701
20702 else
20703 pragma Assert
20704 (Nkind_In (Decl, N_Protected_Body, N_Task_Body));
20705
20706 Check_Pragma_Conformance
20707 (Context_Pragma => SPARK_Pragma (Body_Id),
20708 Entity => Spec_Id,
20709 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id));
20710
20711 Set_SPARK_Context;
20712 Set_SPARK_Pragma (Body_Id, N);
20713 Set_SPARK_Pragma_Inherited (Body_Id, False);
20714 end if;
20715 end Process_Body;
20716
20717 --------------------------
20718 -- Process_Overloadable --
20719 --------------------------
20720
20721 procedure Process_Overloadable (Decl : Node_Id) is
20722 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
20723 Spec_Typ : constant Entity_Id := Etype (Spec_Id);
20724
20725 begin
20726 Check_Library_Level_Entity (Spec_Id);
20727
20728 -- Verify the legality against:
20729 -- * The mode of the context
20730
20731 Check_Pragma_Conformance
20732 (Context_Pragma => SPARK_Pragma (Spec_Id),
20733 Entity => Empty,
20734 Entity_Pragma => Empty);
20735
20736 Set_SPARK_Pragma (Spec_Id, N);
20737 Set_SPARK_Pragma_Inherited (Spec_Id, False);
20738
20739 -- When the pragma applies to the anonymous object created for
20740 -- a single task type, decorate the type as well. This scenario
20741 -- arises when the single task type lacks a task definition,
20742 -- therefore there is no issue with respect to a potential
20743 -- pragma SPARK_Mode in the private part.
20744
20745 -- task type Anon_Task_Typ;
20746 -- Obj : Anon_Task_Typ;
20747 -- pragma SPARK_Mode ...;
20748
20749 if Is_Single_Task_Object (Spec_Id) then
20750 Set_SPARK_Pragma (Spec_Typ, N);
20751 Set_SPARK_Pragma_Inherited (Spec_Typ, False);
20752 Set_SPARK_Aux_Pragma (Spec_Typ, N);
20753 Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True);
20754 end if;
20755 end Process_Overloadable;
20756
20757 --------------------------
20758 -- Process_Private_Part --
20759 --------------------------
20760
20761 procedure Process_Private_Part (Decl : Node_Id) is
20762 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
20763
20764 begin
20765 Check_Library_Level_Entity (Spec_Id);
20766
20767 -- Verify the legality against:
20768 -- * The mode of the visible declarations
20769
20770 Check_Pragma_Conformance
20771 (Context_Pragma => Empty,
20772 Entity => Spec_Id,
20773 Entity_Pragma => SPARK_Pragma (Spec_Id));
20774
20775 Set_SPARK_Context;
20776 Set_SPARK_Aux_Pragma (Spec_Id, N);
20777 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
20778 end Process_Private_Part;
20779
20780 ----------------------------
20781 -- Process_Statement_Part --
20782 ----------------------------
20783
20784 procedure Process_Statement_Part (Decl : Node_Id) is
20785 Body_Id : constant Entity_Id := Defining_Entity (Decl);
20786
20787 begin
20788 Check_Library_Level_Entity (Body_Id);
20789
20790 -- Verify the legality against:
20791 -- * The mode of the body declarations
20792
20793 Check_Pragma_Conformance
20794 (Context_Pragma => Empty,
20795 Entity => Body_Id,
20796 Entity_Pragma => SPARK_Pragma (Body_Id));
20797
20798 Set_SPARK_Context;
20799 Set_SPARK_Aux_Pragma (Body_Id, N);
20800 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
20801 end Process_Statement_Part;
20802
20803 --------------------------
20804 -- Process_Visible_Part --
20805 --------------------------
20806
20807 procedure Process_Visible_Part (Decl : Node_Id) is
20808 Spec_Id : constant Entity_Id := Defining_Entity (Decl);
20809 Obj_Id : Entity_Id;
20810
20811 begin
20812 Check_Library_Level_Entity (Spec_Id);
20813
20814 -- Verify the legality against:
20815 -- * The mode of the context
20816
20817 Check_Pragma_Conformance
20818 (Context_Pragma => SPARK_Pragma (Spec_Id),
20819 Entity => Empty,
20820 Entity_Pragma => Empty);
20821
20822 -- A task unit declared without a definition does not set the
20823 -- SPARK_Mode of the context because the task does not have any
20824 -- entries that could inherit the mode.
20825
20826 if not Nkind_In (Decl, N_Single_Task_Declaration,
20827 N_Task_Type_Declaration)
20828 then
20829 Set_SPARK_Context;
20830 end if;
20831
20832 Set_SPARK_Pragma (Spec_Id, N);
20833 Set_SPARK_Pragma_Inherited (Spec_Id, False);
20834 Set_SPARK_Aux_Pragma (Spec_Id, N);
20835 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
20836
20837 -- When the pragma applies to a single protected or task type,
20838 -- decorate the corresponding anonymous object as well.
20839
20840 -- protected Anon_Prot_Typ is
20841 -- pragma SPARK_Mode ...;
20842 -- ...
20843 -- end Anon_Prot_Typ;
20844
20845 -- Obj : Anon_Prot_Typ;
20846
20847 if Is_Single_Concurrent_Type (Spec_Id) then
20848 Obj_Id := Anonymous_Object (Spec_Id);
20849
20850 Set_SPARK_Pragma (Obj_Id, N);
20851 Set_SPARK_Pragma_Inherited (Obj_Id, False);
20852 end if;
20853 end Process_Visible_Part;
20854
20855 -----------------------
20856 -- Set_SPARK_Context --
20857 -----------------------
20858
20859 procedure Set_SPARK_Context is
20860 begin
20861 SPARK_Mode := Mode_Id;
20862 SPARK_Mode_Pragma := N;
20863
20864 if SPARK_Mode = On then
20865 Dynamic_Elaboration_Checks := False;
20866 end if;
20867 end Set_SPARK_Context;
20868
20869 -- Local variables
20870
20871 Context : Node_Id;
20872 Mode : Name_Id;
20873 Stmt : Node_Id;
20874
20875 -- Start of processing for Do_SPARK_Mode
20876
20877 begin
20878 -- When a SPARK_Mode pragma appears inside an instantiation whose
20879 -- enclosing context has SPARK_Mode set to "off", the pragma has
20880 -- no semantic effect.
20881
20882 if Ignore_Pragma_SPARK_Mode then
20883 Rewrite (N, Make_Null_Statement (Loc));
20884 Analyze (N);
20885 return;
20886 end if;
20887
20888 GNAT_Pragma;
20889 Check_No_Identifiers;
20890 Check_At_Most_N_Arguments (1);
20891
20892 -- Check the legality of the mode (no argument = ON)
20893
20894 if Arg_Count = 1 then
20895 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20896 Mode := Chars (Get_Pragma_Arg (Arg1));
20897 else
20898 Mode := Name_On;
20899 end if;
20900
20901 Mode_Id := Get_SPARK_Mode_Type (Mode);
20902 Context := Parent (N);
20903
20904 -- The pragma appears in a configuration pragmas file
20905
20906 if No (Context) then
20907 Check_Valid_Configuration_Pragma;
20908
20909 if Present (SPARK_Mode_Pragma) then
20910 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
20911 Error_Msg_N ("pragma% duplicates pragma declared#", N);
20912 raise Pragma_Exit;
20913 end if;
20914
20915 Set_SPARK_Context;
20916
20917 -- The pragma acts as a configuration pragma in a compilation unit
20918
20919 -- pragma SPARK_Mode ...;
20920 -- package Pack is ...;
20921
20922 elsif Nkind (Context) = N_Compilation_Unit
20923 and then List_Containing (N) = Context_Items (Context)
20924 then
20925 Check_Valid_Configuration_Pragma;
20926 Set_SPARK_Context;
20927
20928 -- Otherwise the placement of the pragma within the tree dictates
20929 -- its associated construct. Inspect the declarative list where
20930 -- the pragma resides to find a potential construct.
20931
20932 else
20933 Stmt := Prev (N);
20934 while Present (Stmt) loop
20935
20936 -- Skip prior pragmas, but check for duplicates. Note that
20937 -- this also takes care of pragmas generated for aspects.
20938
20939 if Nkind (Stmt) = N_Pragma then
20940 if Pragma_Name (Stmt) = Pname then
20941 Error_Msg_Name_1 := Pname;
20942 Error_Msg_Sloc := Sloc (Stmt);
20943 Error_Msg_N ("pragma% duplicates pragma declared#", N);
20944 raise Pragma_Exit;
20945 end if;
20946
20947 -- The pragma applies to an expression function that has
20948 -- already been rewritten into a subprogram declaration.
20949
20950 -- function Expr_Func return ... is (...);
20951 -- pragma SPARK_Mode ...;
20952
20953 elsif Nkind (Stmt) = N_Subprogram_Declaration
20954 and then Nkind (Original_Node (Stmt)) =
20955 N_Expression_Function
20956 then
20957 Process_Overloadable (Stmt);
20958 return;
20959
20960 -- The pragma applies to the anonymous object created for a
20961 -- single concurrent type.
20962
20963 -- protected type Anon_Prot_Typ ...;
20964 -- Obj : Anon_Prot_Typ;
20965 -- pragma SPARK_Mode ...;
20966
20967 elsif Nkind (Stmt) = N_Object_Declaration
20968 and then Is_Single_Concurrent_Object
20969 (Defining_Entity (Stmt))
20970 then
20971 Process_Overloadable (Stmt);
20972 return;
20973
20974 -- Skip internally generated code
20975
20976 elsif not Comes_From_Source (Stmt) then
20977 null;
20978
20979 -- The pragma applies to an entry or [generic] subprogram
20980 -- declaration.
20981
20982 -- entry Ent ...;
20983 -- pragma SPARK_Mode ...;
20984
20985 -- [generic]
20986 -- procedure Proc ...;
20987 -- pragma SPARK_Mode ...;
20988
20989 elsif Nkind_In (Stmt, N_Generic_Subprogram_Declaration,
20990 N_Subprogram_Declaration)
20991 or else (Nkind (Stmt) = N_Entry_Declaration
20992 and then Is_Protected_Type
20993 (Scope (Defining_Entity (Stmt))))
20994 then
20995 Process_Overloadable (Stmt);
20996 return;
20997
20998 -- Otherwise the pragma does not apply to a legal construct
20999 -- or it does not appear at the top of a declarative or a
21000 -- statement list. Issue an error and stop the analysis.
21001
21002 else
21003 Pragma_Misplaced;
21004 exit;
21005 end if;
21006
21007 Prev (Stmt);
21008 end loop;
21009
21010 -- The pragma applies to a package or a subprogram that acts as
21011 -- a compilation unit.
21012
21013 -- procedure Proc ...;
21014 -- pragma SPARK_Mode ...;
21015
21016 if Nkind (Context) = N_Compilation_Unit_Aux then
21017 Context := Unit (Parent (Context));
21018 end if;
21019
21020 -- The pragma appears at the top of entry, package, protected
21021 -- unit, subprogram or task unit body declarations.
21022
21023 -- entry Ent when ... is
21024 -- pragma SPARK_Mode ...;
21025
21026 -- package body Pack is
21027 -- pragma SPARK_Mode ...;
21028
21029 -- procedure Proc ... is
21030 -- pragma SPARK_Mode;
21031
21032 -- protected body Prot is
21033 -- pragma SPARK_Mode ...;
21034
21035 if Nkind_In (Context, N_Entry_Body,
21036 N_Package_Body,
21037 N_Protected_Body,
21038 N_Subprogram_Body,
21039 N_Task_Body)
21040 then
21041 Process_Body (Context);
21042
21043 -- The pragma appears at the top of the visible or private
21044 -- declaration of a package spec, protected or task unit.
21045
21046 -- package Pack is
21047 -- pragma SPARK_Mode ...;
21048 -- private
21049 -- pragma SPARK_Mode ...;
21050
21051 -- protected [type] Prot is
21052 -- pragma SPARK_Mode ...;
21053 -- private
21054 -- pragma SPARK_Mode ...;
21055
21056 elsif Nkind_In (Context, N_Package_Specification,
21057 N_Protected_Definition,
21058 N_Task_Definition)
21059 then
21060 if List_Containing (N) = Visible_Declarations (Context) then
21061 Process_Visible_Part (Parent (Context));
21062 else
21063 Process_Private_Part (Parent (Context));
21064 end if;
21065
21066 -- The pragma appears at the top of package body statements
21067
21068 -- package body Pack is
21069 -- begin
21070 -- pragma SPARK_Mode;
21071
21072 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
21073 and then Nkind (Parent (Context)) = N_Package_Body
21074 then
21075 Process_Statement_Part (Parent (Context));
21076
21077 -- The pragma appeared as an aspect of a [generic] subprogram
21078 -- declaration that acts as a compilation unit.
21079
21080 -- [generic]
21081 -- procedure Proc ...;
21082 -- pragma SPARK_Mode ...;
21083
21084 elsif Nkind_In (Context, N_Generic_Subprogram_Declaration,
21085 N_Subprogram_Declaration)
21086 then
21087 Process_Overloadable (Context);
21088
21089 -- The pragma does not apply to a legal construct, issue error
21090
21091 else
21092 Pragma_Misplaced;
21093 end if;
21094 end if;
21095 end Do_SPARK_Mode;
21096
21097 --------------------------------
21098 -- Static_Elaboration_Desired --
21099 --------------------------------
21100
21101 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
21102
21103 when Pragma_Static_Elaboration_Desired =>
21104 GNAT_Pragma;
21105 Check_At_Most_N_Arguments (1);
21106
21107 if Is_Compilation_Unit (Current_Scope)
21108 and then Ekind (Current_Scope) = E_Package
21109 then
21110 Set_Static_Elaboration_Desired (Current_Scope, True);
21111 else
21112 Error_Pragma ("pragma% must apply to a library-level package");
21113 end if;
21114
21115 ------------------
21116 -- Storage_Size --
21117 ------------------
21118
21119 -- pragma Storage_Size (EXPRESSION);
21120
21121 when Pragma_Storage_Size => Storage_Size : declare
21122 P : constant Node_Id := Parent (N);
21123 Arg : Node_Id;
21124
21125 begin
21126 Check_No_Identifiers;
21127 Check_Arg_Count (1);
21128
21129 -- The expression must be analyzed in the special manner described
21130 -- in "Handling of Default Expressions" in sem.ads.
21131
21132 Arg := Get_Pragma_Arg (Arg1);
21133 Preanalyze_Spec_Expression (Arg, Any_Integer);
21134
21135 if not Is_OK_Static_Expression (Arg) then
21136 Check_Restriction (Static_Storage_Size, Arg);
21137 end if;
21138
21139 if Nkind (P) /= N_Task_Definition then
21140 Pragma_Misplaced;
21141 return;
21142
21143 else
21144 if Has_Storage_Size_Pragma (P) then
21145 Error_Pragma ("duplicate pragma% not allowed");
21146 else
21147 Set_Has_Storage_Size_Pragma (P, True);
21148 end if;
21149
21150 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
21151 end if;
21152 end Storage_Size;
21153
21154 ------------------
21155 -- Storage_Unit --
21156 ------------------
21157
21158 -- pragma Storage_Unit (NUMERIC_LITERAL);
21159
21160 -- Only permitted argument is System'Storage_Unit value
21161
21162 when Pragma_Storage_Unit =>
21163 Check_No_Identifiers;
21164 Check_Arg_Count (1);
21165 Check_Arg_Is_Integer_Literal (Arg1);
21166
21167 if Intval (Get_Pragma_Arg (Arg1)) /=
21168 UI_From_Int (Ttypes.System_Storage_Unit)
21169 then
21170 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
21171 Error_Pragma_Arg
21172 ("the only allowed argument for pragma% is ^", Arg1);
21173 end if;
21174
21175 --------------------
21176 -- Stream_Convert --
21177 --------------------
21178
21179 -- pragma Stream_Convert (
21180 -- [Entity =>] type_LOCAL_NAME,
21181 -- [Read =>] function_NAME,
21182 -- [Write =>] function NAME);
21183
21184 when Pragma_Stream_Convert => Stream_Convert : declare
21185
21186 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
21187 -- Check that the given argument is the name of a local function
21188 -- of one argument that is not overloaded earlier in the current
21189 -- local scope. A check is also made that the argument is a
21190 -- function with one parameter.
21191
21192 --------------------------------------
21193 -- Check_OK_Stream_Convert_Function --
21194 --------------------------------------
21195
21196 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
21197 Ent : Entity_Id;
21198
21199 begin
21200 Check_Arg_Is_Local_Name (Arg);
21201 Ent := Entity (Get_Pragma_Arg (Arg));
21202
21203 if Has_Homonym (Ent) then
21204 Error_Pragma_Arg
21205 ("argument for pragma% may not be overloaded", Arg);
21206 end if;
21207
21208 if Ekind (Ent) /= E_Function
21209 or else No (First_Formal (Ent))
21210 or else Present (Next_Formal (First_Formal (Ent)))
21211 then
21212 Error_Pragma_Arg
21213 ("argument for pragma% must be function of one argument",
21214 Arg);
21215 end if;
21216 end Check_OK_Stream_Convert_Function;
21217
21218 -- Start of processing for Stream_Convert
21219
21220 begin
21221 GNAT_Pragma;
21222 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
21223 Check_Arg_Count (3);
21224 Check_Optional_Identifier (Arg1, Name_Entity);
21225 Check_Optional_Identifier (Arg2, Name_Read);
21226 Check_Optional_Identifier (Arg3, Name_Write);
21227 Check_Arg_Is_Local_Name (Arg1);
21228 Check_OK_Stream_Convert_Function (Arg2);
21229 Check_OK_Stream_Convert_Function (Arg3);
21230
21231 declare
21232 Typ : constant Entity_Id :=
21233 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
21234 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
21235 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
21236
21237 begin
21238 Check_First_Subtype (Arg1);
21239
21240 -- Check for too early or too late. Note that we don't enforce
21241 -- the rule about primitive operations in this case, since, as
21242 -- is the case for explicit stream attributes themselves, these
21243 -- restrictions are not appropriate. Note that the chaining of
21244 -- the pragma by Rep_Item_Too_Late is actually the critical
21245 -- processing done for this pragma.
21246
21247 if Rep_Item_Too_Early (Typ, N)
21248 or else
21249 Rep_Item_Too_Late (Typ, N, FOnly => True)
21250 then
21251 return;
21252 end if;
21253
21254 -- Return if previous error
21255
21256 if Etype (Typ) = Any_Type
21257 or else
21258 Etype (Read) = Any_Type
21259 or else
21260 Etype (Write) = Any_Type
21261 then
21262 return;
21263 end if;
21264
21265 -- Error checks
21266
21267 if Underlying_Type (Etype (Read)) /= Typ then
21268 Error_Pragma_Arg
21269 ("incorrect return type for function&", Arg2);
21270 end if;
21271
21272 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
21273 Error_Pragma_Arg
21274 ("incorrect parameter type for function&", Arg3);
21275 end if;
21276
21277 if Underlying_Type (Etype (First_Formal (Read))) /=
21278 Underlying_Type (Etype (Write))
21279 then
21280 Error_Pragma_Arg
21281 ("result type of & does not match Read parameter type",
21282 Arg3);
21283 end if;
21284 end;
21285 end Stream_Convert;
21286
21287 ------------------
21288 -- Style_Checks --
21289 ------------------
21290
21291 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21292
21293 -- This is processed by the parser since some of the style checks
21294 -- take place during source scanning and parsing. This means that
21295 -- we don't need to issue error messages here.
21296
21297 when Pragma_Style_Checks => Style_Checks : declare
21298 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21299 S : String_Id;
21300 C : Char_Code;
21301
21302 begin
21303 GNAT_Pragma;
21304 Check_No_Identifiers;
21305
21306 -- Two argument form
21307
21308 if Arg_Count = 2 then
21309 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21310
21311 declare
21312 E_Id : Node_Id;
21313 E : Entity_Id;
21314
21315 begin
21316 E_Id := Get_Pragma_Arg (Arg2);
21317 Analyze (E_Id);
21318
21319 if not Is_Entity_Name (E_Id) then
21320 Error_Pragma_Arg
21321 ("second argument of pragma% must be entity name",
21322 Arg2);
21323 end if;
21324
21325 E := Entity (E_Id);
21326
21327 if not Ignore_Style_Checks_Pragmas then
21328 if E = Any_Id then
21329 return;
21330 else
21331 loop
21332 Set_Suppress_Style_Checks
21333 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
21334 exit when No (Homonym (E));
21335 E := Homonym (E);
21336 end loop;
21337 end if;
21338 end if;
21339 end;
21340
21341 -- One argument form
21342
21343 else
21344 Check_Arg_Count (1);
21345
21346 if Nkind (A) = N_String_Literal then
21347 S := Strval (A);
21348
21349 declare
21350 Slen : constant Natural := Natural (String_Length (S));
21351 Options : String (1 .. Slen);
21352 J : Positive;
21353
21354 begin
21355 J := 1;
21356 loop
21357 C := Get_String_Char (S, Pos (J));
21358 exit when not In_Character_Range (C);
21359 Options (J) := Get_Character (C);
21360
21361 -- If at end of string, set options. As per discussion
21362 -- above, no need to check for errors, since we issued
21363 -- them in the parser.
21364
21365 if J = Slen then
21366 if not Ignore_Style_Checks_Pragmas then
21367 Set_Style_Check_Options (Options);
21368 end if;
21369
21370 exit;
21371 end if;
21372
21373 J := J + 1;
21374 end loop;
21375 end;
21376
21377 elsif Nkind (A) = N_Identifier then
21378 if Chars (A) = Name_All_Checks then
21379 if not Ignore_Style_Checks_Pragmas then
21380 if GNAT_Mode then
21381 Set_GNAT_Style_Check_Options;
21382 else
21383 Set_Default_Style_Check_Options;
21384 end if;
21385 end if;
21386
21387 elsif Chars (A) = Name_On then
21388 if not Ignore_Style_Checks_Pragmas then
21389 Style_Check := True;
21390 end if;
21391
21392 elsif Chars (A) = Name_Off then
21393 if not Ignore_Style_Checks_Pragmas then
21394 Style_Check := False;
21395 end if;
21396 end if;
21397 end if;
21398 end if;
21399 end Style_Checks;
21400
21401 --------------
21402 -- Subtitle --
21403 --------------
21404
21405 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
21406
21407 when Pragma_Subtitle =>
21408 GNAT_Pragma;
21409 Check_Arg_Count (1);
21410 Check_Optional_Identifier (Arg1, Name_Subtitle);
21411 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
21412 Store_Note (N);
21413
21414 --------------
21415 -- Suppress --
21416 --------------
21417
21418 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
21419
21420 when Pragma_Suppress =>
21421 Process_Suppress_Unsuppress (Suppress_Case => True);
21422
21423 ------------------
21424 -- Suppress_All --
21425 ------------------
21426
21427 -- pragma Suppress_All;
21428
21429 -- The only check made here is that the pragma has no arguments.
21430 -- There are no placement rules, and the processing required (setting
21431 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
21432 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
21433 -- then creates and inserts a pragma Suppress (All_Checks).
21434
21435 when Pragma_Suppress_All =>
21436 GNAT_Pragma;
21437 Check_Arg_Count (0);
21438
21439 -------------------------
21440 -- Suppress_Debug_Info --
21441 -------------------------
21442
21443 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
21444
21445 when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare
21446 Nam_Id : Entity_Id;
21447
21448 begin
21449 GNAT_Pragma;
21450 Check_Arg_Count (1);
21451 Check_Optional_Identifier (Arg1, Name_Entity);
21452 Check_Arg_Is_Local_Name (Arg1);
21453
21454 Nam_Id := Entity (Get_Pragma_Arg (Arg1));
21455
21456 -- A pragma that applies to a Ghost entity becomes Ghost for the
21457 -- purposes of legality checks and removal of ignored Ghost code.
21458
21459 Mark_Pragma_As_Ghost (N, Nam_Id);
21460 Set_Debug_Info_Off (Nam_Id);
21461 end Suppress_Debug_Info;
21462
21463 ----------------------------------
21464 -- Suppress_Exception_Locations --
21465 ----------------------------------
21466
21467 -- pragma Suppress_Exception_Locations;
21468
21469 when Pragma_Suppress_Exception_Locations =>
21470 GNAT_Pragma;
21471 Check_Arg_Count (0);
21472 Check_Valid_Configuration_Pragma;
21473 Exception_Locations_Suppressed := True;
21474
21475 -----------------------------
21476 -- Suppress_Initialization --
21477 -----------------------------
21478
21479 -- pragma Suppress_Initialization ([Entity =>] type_Name);
21480
21481 when Pragma_Suppress_Initialization => Suppress_Init : declare
21482 E : Entity_Id;
21483 E_Id : Node_Id;
21484
21485 begin
21486 GNAT_Pragma;
21487 Check_Arg_Count (1);
21488 Check_Optional_Identifier (Arg1, Name_Entity);
21489 Check_Arg_Is_Local_Name (Arg1);
21490
21491 E_Id := Get_Pragma_Arg (Arg1);
21492
21493 if Etype (E_Id) = Any_Type then
21494 return;
21495 end if;
21496
21497 E := Entity (E_Id);
21498
21499 -- A pragma that applies to a Ghost entity becomes Ghost for the
21500 -- purposes of legality checks and removal of ignored Ghost code.
21501
21502 Mark_Pragma_As_Ghost (N, E);
21503
21504 if not Is_Type (E) and then Ekind (E) /= E_Variable then
21505 Error_Pragma_Arg
21506 ("pragma% requires variable, type or subtype", Arg1);
21507 end if;
21508
21509 if Rep_Item_Too_Early (E, N)
21510 or else
21511 Rep_Item_Too_Late (E, N, FOnly => True)
21512 then
21513 return;
21514 end if;
21515
21516 -- For incomplete/private type, set flag on full view
21517
21518 if Is_Incomplete_Or_Private_Type (E) then
21519 if No (Full_View (Base_Type (E))) then
21520 Error_Pragma_Arg
21521 ("argument of pragma% cannot be an incomplete type", Arg1);
21522 else
21523 Set_Suppress_Initialization (Full_View (Base_Type (E)));
21524 end if;
21525
21526 -- For first subtype, set flag on base type
21527
21528 elsif Is_First_Subtype (E) then
21529 Set_Suppress_Initialization (Base_Type (E));
21530
21531 -- For other than first subtype, set flag on subtype or variable
21532
21533 else
21534 Set_Suppress_Initialization (E);
21535 end if;
21536 end Suppress_Init;
21537
21538 -----------------
21539 -- System_Name --
21540 -----------------
21541
21542 -- pragma System_Name (DIRECT_NAME);
21543
21544 -- Syntax check: one argument, which must be the identifier GNAT or
21545 -- the identifier GCC, no other identifiers are acceptable.
21546
21547 when Pragma_System_Name =>
21548 GNAT_Pragma;
21549 Check_No_Identifiers;
21550 Check_Arg_Count (1);
21551 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
21552
21553 -----------------------------
21554 -- Task_Dispatching_Policy --
21555 -----------------------------
21556
21557 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
21558
21559 when Pragma_Task_Dispatching_Policy => declare
21560 DP : Character;
21561
21562 begin
21563 Check_Ada_83_Warning;
21564 Check_Arg_Count (1);
21565 Check_No_Identifiers;
21566 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
21567 Check_Valid_Configuration_Pragma;
21568 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21569 DP := Fold_Upper (Name_Buffer (1));
21570
21571 if Task_Dispatching_Policy /= ' '
21572 and then Task_Dispatching_Policy /= DP
21573 then
21574 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
21575 Error_Pragma
21576 ("task dispatching policy incompatible with policy#");
21577
21578 -- Set new policy, but always preserve System_Location since we
21579 -- like the error message with the run time name.
21580
21581 else
21582 Task_Dispatching_Policy := DP;
21583
21584 if Task_Dispatching_Policy_Sloc /= System_Location then
21585 Task_Dispatching_Policy_Sloc := Loc;
21586 end if;
21587 end if;
21588 end;
21589
21590 ---------------
21591 -- Task_Info --
21592 ---------------
21593
21594 -- pragma Task_Info (EXPRESSION);
21595
21596 when Pragma_Task_Info => Task_Info : declare
21597 P : constant Node_Id := Parent (N);
21598 Ent : Entity_Id;
21599
21600 begin
21601 GNAT_Pragma;
21602
21603 if Warn_On_Obsolescent_Feature then
21604 Error_Msg_N
21605 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
21606 & "instead?j?", N);
21607 end if;
21608
21609 if Nkind (P) /= N_Task_Definition then
21610 Error_Pragma ("pragma% must appear in task definition");
21611 end if;
21612
21613 Check_No_Identifiers;
21614 Check_Arg_Count (1);
21615
21616 Analyze_And_Resolve
21617 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
21618
21619 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
21620 return;
21621 end if;
21622
21623 Ent := Defining_Identifier (Parent (P));
21624
21625 -- Check duplicate pragma before we chain the pragma in the Rep
21626 -- Item chain of Ent.
21627
21628 if Has_Rep_Pragma
21629 (Ent, Name_Task_Info, Check_Parents => False)
21630 then
21631 Error_Pragma ("duplicate pragma% not allowed");
21632 end if;
21633
21634 Record_Rep_Item (Ent, N);
21635 end Task_Info;
21636
21637 ---------------
21638 -- Task_Name --
21639 ---------------
21640
21641 -- pragma Task_Name (string_EXPRESSION);
21642
21643 when Pragma_Task_Name => Task_Name : declare
21644 P : constant Node_Id := Parent (N);
21645 Arg : Node_Id;
21646 Ent : Entity_Id;
21647
21648 begin
21649 Check_No_Identifiers;
21650 Check_Arg_Count (1);
21651
21652 Arg := Get_Pragma_Arg (Arg1);
21653
21654 -- The expression is used in the call to Create_Task, and must be
21655 -- expanded there, not in the context of the current spec. It must
21656 -- however be analyzed to capture global references, in case it
21657 -- appears in a generic context.
21658
21659 Preanalyze_And_Resolve (Arg, Standard_String);
21660
21661 if Nkind (P) /= N_Task_Definition then
21662 Pragma_Misplaced;
21663 end if;
21664
21665 Ent := Defining_Identifier (Parent (P));
21666
21667 -- Check duplicate pragma before we chain the pragma in the Rep
21668 -- Item chain of Ent.
21669
21670 if Has_Rep_Pragma
21671 (Ent, Name_Task_Name, Check_Parents => False)
21672 then
21673 Error_Pragma ("duplicate pragma% not allowed");
21674 end if;
21675
21676 Record_Rep_Item (Ent, N);
21677 end Task_Name;
21678
21679 ------------------
21680 -- Task_Storage --
21681 ------------------
21682
21683 -- pragma Task_Storage (
21684 -- [Task_Type =>] LOCAL_NAME,
21685 -- [Top_Guard =>] static_integer_EXPRESSION);
21686
21687 when Pragma_Task_Storage => Task_Storage : declare
21688 Args : Args_List (1 .. 2);
21689 Names : constant Name_List (1 .. 2) := (
21690 Name_Task_Type,
21691 Name_Top_Guard);
21692
21693 Task_Type : Node_Id renames Args (1);
21694 Top_Guard : Node_Id renames Args (2);
21695
21696 Ent : Entity_Id;
21697
21698 begin
21699 GNAT_Pragma;
21700 Gather_Associations (Names, Args);
21701
21702 if No (Task_Type) then
21703 Error_Pragma
21704 ("missing task_type argument for pragma%");
21705 end if;
21706
21707 Check_Arg_Is_Local_Name (Task_Type);
21708
21709 Ent := Entity (Task_Type);
21710
21711 if not Is_Task_Type (Ent) then
21712 Error_Pragma_Arg
21713 ("argument for pragma% must be task type", Task_Type);
21714 end if;
21715
21716 if No (Top_Guard) then
21717 Error_Pragma_Arg
21718 ("pragma% takes two arguments", Task_Type);
21719 else
21720 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
21721 end if;
21722
21723 Check_First_Subtype (Task_Type);
21724
21725 if Rep_Item_Too_Late (Ent, N) then
21726 raise Pragma_Exit;
21727 end if;
21728 end Task_Storage;
21729
21730 ---------------
21731 -- Test_Case --
21732 ---------------
21733
21734 -- pragma Test_Case
21735 -- ([Name =>] Static_String_EXPRESSION
21736 -- ,[Mode =>] MODE_TYPE
21737 -- [, Requires => Boolean_EXPRESSION]
21738 -- [, Ensures => Boolean_EXPRESSION]);
21739
21740 -- MODE_TYPE ::= Nominal | Robustness
21741
21742 -- Characteristics:
21743
21744 -- * Analysis - The annotation undergoes initial checks to verify
21745 -- the legal placement and context. Secondary checks preanalyze the
21746 -- expressions in:
21747
21748 -- Analyze_Test_Case_In_Decl_Part
21749
21750 -- * Expansion - None.
21751
21752 -- * Template - The annotation utilizes the generic template of the
21753 -- related subprogram when it is:
21754
21755 -- aspect on subprogram declaration
21756
21757 -- The annotation must prepare its own template when it is:
21758
21759 -- pragma on subprogram declaration
21760
21761 -- * Globals - Capture of global references must occur after full
21762 -- analysis.
21763
21764 -- * Instance - The annotation is instantiated automatically when
21765 -- the related generic subprogram is instantiated except for the
21766 -- "pragma on subprogram declaration" case. In that scenario the
21767 -- annotation must instantiate itself.
21768
21769 when Pragma_Test_Case => Test_Case : declare
21770 procedure Check_Distinct_Name (Subp_Id : Entity_Id);
21771 -- Ensure that the contract of subprogram Subp_Id does not contain
21772 -- another Test_Case pragma with the same Name as the current one.
21773
21774 -------------------------
21775 -- Check_Distinct_Name --
21776 -------------------------
21777
21778 procedure Check_Distinct_Name (Subp_Id : Entity_Id) is
21779 Items : constant Node_Id := Contract (Subp_Id);
21780 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
21781 Prag : Node_Id;
21782
21783 begin
21784 -- Inspect all Test_Case pragma of the related subprogram
21785 -- looking for one with a duplicate "Name" argument.
21786
21787 if Present (Items) then
21788 Prag := Contract_Test_Cases (Items);
21789 while Present (Prag) loop
21790 if Pragma_Name (Prag) = Name_Test_Case
21791 and then Prag /= N
21792 and then String_Equal
21793 (Name, Get_Name_From_CTC_Pragma (Prag))
21794 then
21795 Error_Msg_Sloc := Sloc (Prag);
21796 Error_Pragma ("name for pragma % is already used #");
21797 end if;
21798
21799 Prag := Next_Pragma (Prag);
21800 end loop;
21801 end if;
21802 end Check_Distinct_Name;
21803
21804 -- Local variables
21805
21806 Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit));
21807 Asp_Arg : Node_Id;
21808 Context : Node_Id;
21809 Subp_Decl : Node_Id;
21810 Subp_Id : Entity_Id;
21811
21812 -- Start of processing for Test_Case
21813
21814 begin
21815 GNAT_Pragma;
21816 Check_At_Least_N_Arguments (2);
21817 Check_At_Most_N_Arguments (4);
21818 Check_Arg_Order
21819 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
21820
21821 -- Argument "Name"
21822
21823 Check_Optional_Identifier (Arg1, Name_Name);
21824 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
21825
21826 -- Argument "Mode"
21827
21828 Check_Optional_Identifier (Arg2, Name_Mode);
21829 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
21830
21831 -- Arguments "Requires" and "Ensures"
21832
21833 if Present (Arg3) then
21834 if Present (Arg4) then
21835 Check_Identifier (Arg3, Name_Requires);
21836 Check_Identifier (Arg4, Name_Ensures);
21837 else
21838 Check_Identifier_Is_One_Of
21839 (Arg3, Name_Requires, Name_Ensures);
21840 end if;
21841 end if;
21842
21843 -- Pragma Test_Case must be associated with a subprogram declared
21844 -- in a library-level package. First determine whether the current
21845 -- compilation unit is a legal context.
21846
21847 if Nkind_In (Pack_Decl, N_Package_Declaration,
21848 N_Generic_Package_Declaration)
21849 then
21850 null;
21851
21852 -- Otherwise the placement is illegal
21853
21854 else
21855 Error_Pragma
21856 ("pragma % must be specified within a package declaration");
21857 return;
21858 end if;
21859
21860 Subp_Decl := Find_Related_Declaration_Or_Body (N);
21861
21862 -- Find the enclosing context
21863
21864 Context := Parent (Subp_Decl);
21865
21866 if Present (Context) then
21867 Context := Parent (Context);
21868 end if;
21869
21870 -- Verify the placement of the pragma
21871
21872 if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then
21873 Error_Pragma
21874 ("pragma % cannot be applied to abstract subprogram");
21875 return;
21876
21877 elsif Nkind (Subp_Decl) = N_Entry_Declaration then
21878 Error_Pragma ("pragma % cannot be applied to entry");
21879 return;
21880
21881 -- The context is a [generic] subprogram declared at the top level
21882 -- of the [generic] package unit.
21883
21884 elsif Nkind_In (Subp_Decl, N_Generic_Subprogram_Declaration,
21885 N_Subprogram_Declaration)
21886 and then Present (Context)
21887 and then Nkind_In (Context, N_Generic_Package_Declaration,
21888 N_Package_Declaration)
21889 then
21890 null;
21891
21892 -- Otherwise the placement is illegal
21893
21894 else
21895 Error_Pragma
21896 ("pragma % must be applied to a library-level subprogram "
21897 & "declaration");
21898 return;
21899 end if;
21900
21901 Subp_Id := Defining_Entity (Subp_Decl);
21902
21903 -- Chain the pragma on the contract for further processing by
21904 -- Analyze_Test_Case_In_Decl_Part.
21905
21906 Add_Contract_Item (N, Subp_Id);
21907
21908 -- A pragma that applies to a Ghost entity becomes Ghost for the
21909 -- purposes of legality checks and removal of ignored Ghost code.
21910
21911 Mark_Pragma_As_Ghost (N, Subp_Id);
21912
21913 -- Preanalyze the original aspect argument "Name" for ASIS or for
21914 -- a generic subprogram to properly capture global references.
21915
21916 if ASIS_Mode or else Is_Generic_Subprogram (Subp_Id) then
21917 Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True);
21918
21919 if Present (Asp_Arg) then
21920
21921 -- The argument appears with an identifier in association
21922 -- form.
21923
21924 if Nkind (Asp_Arg) = N_Component_Association then
21925 Asp_Arg := Expression (Asp_Arg);
21926 end if;
21927
21928 Check_Expr_Is_OK_Static_Expression
21929 (Asp_Arg, Standard_String);
21930 end if;
21931 end if;
21932
21933 -- Ensure that the all Test_Case pragmas of the related subprogram
21934 -- have distinct names.
21935
21936 Check_Distinct_Name (Subp_Id);
21937
21938 -- Fully analyze the pragma when it appears inside an entry
21939 -- or subprogram body because it cannot benefit from forward
21940 -- references.
21941
21942 if Nkind_In (Subp_Decl, N_Entry_Body,
21943 N_Subprogram_Body,
21944 N_Subprogram_Body_Stub)
21945 then
21946 -- The legality checks of pragma Test_Case are affected by the
21947 -- SPARK mode in effect and the volatility of the context.
21948 -- Analyze all pragmas in a specific order.
21949
21950 Analyze_If_Present (Pragma_SPARK_Mode);
21951 Analyze_If_Present (Pragma_Volatile_Function);
21952 Analyze_Test_Case_In_Decl_Part (N);
21953 end if;
21954 end Test_Case;
21955
21956 --------------------------
21957 -- Thread_Local_Storage --
21958 --------------------------
21959
21960 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
21961
21962 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
21963 E : Entity_Id;
21964 Id : Node_Id;
21965
21966 begin
21967 GNAT_Pragma;
21968 Check_Arg_Count (1);
21969 Check_Optional_Identifier (Arg1, Name_Entity);
21970 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21971
21972 Id := Get_Pragma_Arg (Arg1);
21973 Analyze (Id);
21974
21975 if not Is_Entity_Name (Id)
21976 or else Ekind (Entity (Id)) /= E_Variable
21977 then
21978 Error_Pragma_Arg ("local variable name required", Arg1);
21979 end if;
21980
21981 E := Entity (Id);
21982
21983 -- A pragma that applies to a Ghost entity becomes Ghost for the
21984 -- purposes of legality checks and removal of ignored Ghost code.
21985
21986 Mark_Pragma_As_Ghost (N, E);
21987
21988 if Rep_Item_Too_Early (E, N)
21989 or else
21990 Rep_Item_Too_Late (E, N)
21991 then
21992 raise Pragma_Exit;
21993 end if;
21994
21995 Set_Has_Pragma_Thread_Local_Storage (E);
21996 Set_Has_Gigi_Rep_Item (E);
21997 end Thread_Local_Storage;
21998
21999 ----------------
22000 -- Time_Slice --
22001 ----------------
22002
22003 -- pragma Time_Slice (static_duration_EXPRESSION);
22004
22005 when Pragma_Time_Slice => Time_Slice : declare
22006 Val : Ureal;
22007 Nod : Node_Id;
22008
22009 begin
22010 GNAT_Pragma;
22011 Check_Arg_Count (1);
22012 Check_No_Identifiers;
22013 Check_In_Main_Program;
22014 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
22015
22016 if not Error_Posted (Arg1) then
22017 Nod := Next (N);
22018 while Present (Nod) loop
22019 if Nkind (Nod) = N_Pragma
22020 and then Pragma_Name (Nod) = Name_Time_Slice
22021 then
22022 Error_Msg_Name_1 := Pname;
22023 Error_Msg_N ("duplicate pragma% not permitted", Nod);
22024 end if;
22025
22026 Next (Nod);
22027 end loop;
22028 end if;
22029
22030 -- Process only if in main unit
22031
22032 if Get_Source_Unit (Loc) = Main_Unit then
22033 Opt.Time_Slice_Set := True;
22034 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
22035
22036 if Val <= Ureal_0 then
22037 Opt.Time_Slice_Value := 0;
22038
22039 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
22040 Opt.Time_Slice_Value := 1_000_000_000;
22041
22042 else
22043 Opt.Time_Slice_Value :=
22044 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
22045 end if;
22046 end if;
22047 end Time_Slice;
22048
22049 -----------
22050 -- Title --
22051 -----------
22052
22053 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
22054
22055 -- TITLING_OPTION ::=
22056 -- [Title =>] STRING_LITERAL
22057 -- | [Subtitle =>] STRING_LITERAL
22058
22059 when Pragma_Title => Title : declare
22060 Args : Args_List (1 .. 2);
22061 Names : constant Name_List (1 .. 2) := (
22062 Name_Title,
22063 Name_Subtitle);
22064
22065 begin
22066 GNAT_Pragma;
22067 Gather_Associations (Names, Args);
22068 Store_Note (N);
22069
22070 for J in 1 .. 2 loop
22071 if Present (Args (J)) then
22072 Check_Arg_Is_OK_Static_Expression
22073 (Args (J), Standard_String);
22074 end if;
22075 end loop;
22076 end Title;
22077
22078 ----------------------------
22079 -- Type_Invariant[_Class] --
22080 ----------------------------
22081
22082 -- pragma Type_Invariant[_Class]
22083 -- ([Entity =>] type_LOCAL_NAME,
22084 -- [Check =>] EXPRESSION);
22085
22086 when Pragma_Type_Invariant |
22087 Pragma_Type_Invariant_Class =>
22088 Type_Invariant : declare
22089 I_Pragma : Node_Id;
22090
22091 begin
22092 Check_Arg_Count (2);
22093
22094 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
22095 -- setting Class_Present for the Type_Invariant_Class case.
22096
22097 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
22098 I_Pragma := New_Copy (N);
22099 Set_Pragma_Identifier
22100 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
22101 Rewrite (N, I_Pragma);
22102 Set_Analyzed (N, False);
22103 Analyze (N);
22104 end Type_Invariant;
22105
22106 ---------------------
22107 -- Unchecked_Union --
22108 ---------------------
22109
22110 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
22111
22112 when Pragma_Unchecked_Union => Unchecked_Union : declare
22113 Assoc : constant Node_Id := Arg1;
22114 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
22115 Clist : Node_Id;
22116 Comp : Node_Id;
22117 Tdef : Node_Id;
22118 Typ : Entity_Id;
22119 Variant : Node_Id;
22120 Vpart : Node_Id;
22121
22122 begin
22123 Ada_2005_Pragma;
22124 Check_No_Identifiers;
22125 Check_Arg_Count (1);
22126 Check_Arg_Is_Local_Name (Arg1);
22127
22128 Find_Type (Type_Id);
22129
22130 Typ := Entity (Type_Id);
22131
22132 -- A pragma that applies to a Ghost entity becomes Ghost for the
22133 -- purposes of legality checks and removal of ignored Ghost code.
22134
22135 Mark_Pragma_As_Ghost (N, Typ);
22136
22137 if Typ = Any_Type
22138 or else Rep_Item_Too_Early (Typ, N)
22139 then
22140 return;
22141 else
22142 Typ := Underlying_Type (Typ);
22143 end if;
22144
22145 if Rep_Item_Too_Late (Typ, N) then
22146 return;
22147 end if;
22148
22149 Check_First_Subtype (Arg1);
22150
22151 -- Note remaining cases are references to a type in the current
22152 -- declarative part. If we find an error, we post the error on
22153 -- the relevant type declaration at an appropriate point.
22154
22155 if not Is_Record_Type (Typ) then
22156 Error_Msg_N ("unchecked union must be record type", Typ);
22157 return;
22158
22159 elsif Is_Tagged_Type (Typ) then
22160 Error_Msg_N ("unchecked union must not be tagged", Typ);
22161 return;
22162
22163 elsif not Has_Discriminants (Typ) then
22164 Error_Msg_N
22165 ("unchecked union must have one discriminant", Typ);
22166 return;
22167
22168 -- Note: in previous versions of GNAT we used to check for limited
22169 -- types and give an error, but in fact the standard does allow
22170 -- Unchecked_Union on limited types, so this check was removed.
22171
22172 -- Similarly, GNAT used to require that all discriminants have
22173 -- default values, but this is not mandated by the RM.
22174
22175 -- Proceed with basic error checks completed
22176
22177 else
22178 Tdef := Type_Definition (Declaration_Node (Typ));
22179 Clist := Component_List (Tdef);
22180
22181 -- Check presence of component list and variant part
22182
22183 if No (Clist) or else No (Variant_Part (Clist)) then
22184 Error_Msg_N
22185 ("unchecked union must have variant part", Tdef);
22186 return;
22187 end if;
22188
22189 -- Check components
22190
22191 Comp := First (Component_Items (Clist));
22192 while Present (Comp) loop
22193 Check_Component (Comp, Typ);
22194 Next (Comp);
22195 end loop;
22196
22197 -- Check variant part
22198
22199 Vpart := Variant_Part (Clist);
22200
22201 Variant := First (Variants (Vpart));
22202 while Present (Variant) loop
22203 Check_Variant (Variant, Typ);
22204 Next (Variant);
22205 end loop;
22206 end if;
22207
22208 Set_Is_Unchecked_Union (Typ);
22209 Set_Convention (Typ, Convention_C);
22210 Set_Has_Unchecked_Union (Base_Type (Typ));
22211 Set_Is_Unchecked_Union (Base_Type (Typ));
22212 end Unchecked_Union;
22213
22214 ------------------------
22215 -- Unimplemented_Unit --
22216 ------------------------
22217
22218 -- pragma Unimplemented_Unit;
22219
22220 -- Note: this only gives an error if we are generating code, or if
22221 -- we are in a generic library unit (where the pragma appears in the
22222 -- body, not in the spec).
22223
22224 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
22225 Cunitent : constant Entity_Id :=
22226 Cunit_Entity (Get_Source_Unit (Loc));
22227 Ent_Kind : constant Entity_Kind :=
22228 Ekind (Cunitent);
22229
22230 begin
22231 GNAT_Pragma;
22232 Check_Arg_Count (0);
22233
22234 if Operating_Mode = Generate_Code
22235 or else Ent_Kind = E_Generic_Function
22236 or else Ent_Kind = E_Generic_Procedure
22237 or else Ent_Kind = E_Generic_Package
22238 then
22239 Get_Name_String (Chars (Cunitent));
22240 Set_Casing (Mixed_Case);
22241 Write_Str (Name_Buffer (1 .. Name_Len));
22242 Write_Str (" is not supported in this configuration");
22243 Write_Eol;
22244 raise Unrecoverable_Error;
22245 end if;
22246 end Unimplemented_Unit;
22247
22248 ------------------------
22249 -- Universal_Aliasing --
22250 ------------------------
22251
22252 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
22253
22254 when Pragma_Universal_Aliasing => Universal_Alias : declare
22255 E_Id : Entity_Id;
22256
22257 begin
22258 GNAT_Pragma;
22259 Check_Arg_Count (1);
22260 Check_Optional_Identifier (Arg2, Name_Entity);
22261 Check_Arg_Is_Local_Name (Arg1);
22262 E_Id := Entity (Get_Pragma_Arg (Arg1));
22263
22264 if E_Id = Any_Type then
22265 return;
22266 elsif No (E_Id) or else not Is_Type (E_Id) then
22267 Error_Pragma_Arg ("pragma% requires type", Arg1);
22268 end if;
22269
22270 -- A pragma that applies to a Ghost entity becomes Ghost for the
22271 -- purposes of legality checks and removal of ignored Ghost code.
22272
22273 Mark_Pragma_As_Ghost (N, E_Id);
22274 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
22275 Record_Rep_Item (E_Id, N);
22276 end Universal_Alias;
22277
22278 --------------------
22279 -- Universal_Data --
22280 --------------------
22281
22282 -- pragma Universal_Data [(library_unit_NAME)];
22283
22284 when Pragma_Universal_Data =>
22285 GNAT_Pragma;
22286
22287 -- If this is a configuration pragma, then set the universal
22288 -- addressing option, otherwise confirm that the pragma satisfies
22289 -- the requirements of library unit pragma placement and leave it
22290 -- to the GNAAMP back end to detect the pragma (avoids transitive
22291 -- setting of the option due to withed units).
22292
22293 if Is_Configuration_Pragma then
22294 Universal_Addressing_On_AAMP := True;
22295 else
22296 Check_Valid_Library_Unit_Pragma;
22297 end if;
22298
22299 if not AAMP_On_Target then
22300 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
22301 end if;
22302
22303 ----------------
22304 -- Unmodified --
22305 ----------------
22306
22307 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
22308
22309 when Pragma_Unmodified => Unmodified : declare
22310 Arg : Node_Id;
22311 Arg_Expr : Node_Id;
22312 Arg_Id : Entity_Id;
22313
22314 Ghost_Error_Posted : Boolean := False;
22315 -- Flag set when an error concerning the illegal mix of Ghost and
22316 -- non-Ghost variables is emitted.
22317
22318 Ghost_Id : Entity_Id := Empty;
22319 -- The entity of the first Ghost variable encountered while
22320 -- processing the arguments of the pragma.
22321
22322 begin
22323 GNAT_Pragma;
22324 Check_At_Least_N_Arguments (1);
22325
22326 -- Loop through arguments
22327
22328 Arg := Arg1;
22329 while Present (Arg) loop
22330 Check_No_Identifier (Arg);
22331
22332 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
22333 -- in fact generate reference, so that the entity will have a
22334 -- reference, which will inhibit any warnings about it not
22335 -- being referenced, and also properly show up in the ali file
22336 -- as a reference. But this reference is recorded before the
22337 -- Has_Pragma_Unreferenced flag is set, so that no warning is
22338 -- generated for this reference.
22339
22340 Check_Arg_Is_Local_Name (Arg);
22341 Arg_Expr := Get_Pragma_Arg (Arg);
22342
22343 if Is_Entity_Name (Arg_Expr) then
22344 Arg_Id := Entity (Arg_Expr);
22345
22346 if Is_Assignable (Arg_Id) then
22347 Set_Has_Pragma_Unmodified (Arg_Id);
22348
22349 -- A pragma that applies to a Ghost entity becomes Ghost
22350 -- for the purposes of legality checks and removal of
22351 -- ignored Ghost code.
22352
22353 Mark_Pragma_As_Ghost (N, Arg_Id);
22354
22355 -- Capture the entity of the first Ghost variable being
22356 -- processed for error detection purposes.
22357
22358 if Is_Ghost_Entity (Arg_Id) then
22359 if No (Ghost_Id) then
22360 Ghost_Id := Arg_Id;
22361 end if;
22362
22363 -- Otherwise the variable is non-Ghost. It is illegal
22364 -- to mix references to Ghost and non-Ghost entities
22365 -- (SPARK RM 6.9).
22366
22367 elsif Present (Ghost_Id)
22368 and then not Ghost_Error_Posted
22369 then
22370 Ghost_Error_Posted := True;
22371
22372 Error_Msg_Name_1 := Pname;
22373 Error_Msg_N
22374 ("pragma % cannot mention ghost and non-ghost "
22375 & "variables", N);
22376
22377 Error_Msg_Sloc := Sloc (Ghost_Id);
22378 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
22379
22380 Error_Msg_Sloc := Sloc (Arg_Id);
22381 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
22382 end if;
22383
22384 -- Otherwise the pragma referenced an illegal entity
22385
22386 else
22387 Error_Pragma_Arg
22388 ("pragma% can only be applied to a variable", Arg_Expr);
22389 end if;
22390 end if;
22391
22392 Next (Arg);
22393 end loop;
22394 end Unmodified;
22395
22396 ------------------
22397 -- Unreferenced --
22398 ------------------
22399
22400 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
22401
22402 -- or when used in a context clause:
22403
22404 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
22405
22406 when Pragma_Unreferenced => Unreferenced : declare
22407 Arg : Node_Id;
22408 Arg_Expr : Node_Id;
22409 Arg_Id : Entity_Id;
22410 Citem : Node_Id;
22411
22412 Ghost_Error_Posted : Boolean := False;
22413 -- Flag set when an error concerning the illegal mix of Ghost and
22414 -- non-Ghost names is emitted.
22415
22416 Ghost_Id : Entity_Id := Empty;
22417 -- The entity of the first Ghost name encountered while processing
22418 -- the arguments of the pragma.
22419
22420 begin
22421 GNAT_Pragma;
22422 Check_At_Least_N_Arguments (1);
22423
22424 -- Check case of appearing within context clause
22425
22426 if Is_In_Context_Clause then
22427
22428 -- The arguments must all be units mentioned in a with clause
22429 -- in the same context clause. Note we already checked (in
22430 -- Par.Prag) that the arguments are either identifiers or
22431 -- selected components.
22432
22433 Arg := Arg1;
22434 while Present (Arg) loop
22435 Citem := First (List_Containing (N));
22436 while Citem /= N loop
22437 Arg_Expr := Get_Pragma_Arg (Arg);
22438
22439 if Nkind (Citem) = N_With_Clause
22440 and then Same_Name (Name (Citem), Arg_Expr)
22441 then
22442 Set_Has_Pragma_Unreferenced
22443 (Cunit_Entity
22444 (Get_Source_Unit
22445 (Library_Unit (Citem))));
22446 Set_Elab_Unit_Name (Arg_Expr, Name (Citem));
22447 exit;
22448 end if;
22449
22450 Next (Citem);
22451 end loop;
22452
22453 if Citem = N then
22454 Error_Pragma_Arg
22455 ("argument of pragma% is not withed unit", Arg);
22456 end if;
22457
22458 Next (Arg);
22459 end loop;
22460
22461 -- Case of not in list of context items
22462
22463 else
22464 Arg := Arg1;
22465 while Present (Arg) loop
22466 Check_No_Identifier (Arg);
22467
22468 -- Note: the analyze call done by Check_Arg_Is_Local_Name
22469 -- will in fact generate reference, so that the entity will
22470 -- have a reference, which will inhibit any warnings about
22471 -- it not being referenced, and also properly show up in the
22472 -- ali file as a reference. But this reference is recorded
22473 -- before the Has_Pragma_Unreferenced flag is set, so that
22474 -- no warning is generated for this reference.
22475
22476 Check_Arg_Is_Local_Name (Arg);
22477 Arg_Expr := Get_Pragma_Arg (Arg);
22478
22479 if Is_Entity_Name (Arg_Expr) then
22480 Arg_Id := Entity (Arg_Expr);
22481
22482 -- If the entity is overloaded, the pragma applies to the
22483 -- most recent overloading, as documented. In this case,
22484 -- name resolution does not generate a reference, so it
22485 -- must be done here explicitly.
22486
22487 if Is_Overloaded (Arg_Expr) then
22488 Generate_Reference (Arg_Id, N);
22489 end if;
22490
22491 Set_Has_Pragma_Unreferenced (Arg_Id);
22492
22493 -- A pragma that applies to a Ghost entity becomes Ghost
22494 -- for the purposes of legality checks and removal of
22495 -- ignored Ghost code.
22496
22497 Mark_Pragma_As_Ghost (N, Arg_Id);
22498
22499 -- Capture the entity of the first Ghost name being
22500 -- processed for error detection purposes.
22501
22502 if Is_Ghost_Entity (Arg_Id) then
22503 if No (Ghost_Id) then
22504 Ghost_Id := Arg_Id;
22505 end if;
22506
22507 -- Otherwise the name is non-Ghost. It is illegal to mix
22508 -- references to Ghost and non-Ghost entities
22509 -- (SPARK RM 6.9).
22510
22511 elsif Present (Ghost_Id)
22512 and then not Ghost_Error_Posted
22513 then
22514 Ghost_Error_Posted := True;
22515
22516 Error_Msg_Name_1 := Pname;
22517 Error_Msg_N
22518 ("pragma % cannot mention ghost and non-ghost names",
22519 N);
22520
22521 Error_Msg_Sloc := Sloc (Ghost_Id);
22522 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
22523
22524 Error_Msg_Sloc := Sloc (Arg_Id);
22525 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
22526 end if;
22527 end if;
22528
22529 Next (Arg);
22530 end loop;
22531 end if;
22532 end Unreferenced;
22533
22534 --------------------------
22535 -- Unreferenced_Objects --
22536 --------------------------
22537
22538 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
22539
22540 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
22541 Arg : Node_Id;
22542 Arg_Expr : Node_Id;
22543 Arg_Id : Entity_Id;
22544
22545 Ghost_Error_Posted : Boolean := False;
22546 -- Flag set when an error concerning the illegal mix of Ghost and
22547 -- non-Ghost types is emitted.
22548
22549 Ghost_Id : Entity_Id := Empty;
22550 -- The entity of the first Ghost type encountered while processing
22551 -- the arguments of the pragma.
22552
22553 begin
22554 GNAT_Pragma;
22555 Check_At_Least_N_Arguments (1);
22556
22557 Arg := Arg1;
22558 while Present (Arg) loop
22559 Check_No_Identifier (Arg);
22560 Check_Arg_Is_Local_Name (Arg);
22561 Arg_Expr := Get_Pragma_Arg (Arg);
22562
22563 if Is_Entity_Name (Arg_Expr) then
22564 Arg_Id := Entity (Arg_Expr);
22565
22566 if Is_Type (Arg_Id) then
22567 Set_Has_Pragma_Unreferenced_Objects (Arg_Id);
22568
22569 -- A pragma that applies to a Ghost entity becomes Ghost
22570 -- for the purposes of legality checks and removal of
22571 -- ignored Ghost code.
22572
22573 Mark_Pragma_As_Ghost (N, Arg_Id);
22574
22575 -- Capture the entity of the first Ghost type being
22576 -- processed for error detection purposes.
22577
22578 if Is_Ghost_Entity (Arg_Id) then
22579 if No (Ghost_Id) then
22580 Ghost_Id := Arg_Id;
22581 end if;
22582
22583 -- Otherwise the type is non-Ghost. It is illegal to mix
22584 -- references to Ghost and non-Ghost entities
22585 -- (SPARK RM 6.9).
22586
22587 elsif Present (Ghost_Id)
22588 and then not Ghost_Error_Posted
22589 then
22590 Ghost_Error_Posted := True;
22591
22592 Error_Msg_Name_1 := Pname;
22593 Error_Msg_N
22594 ("pragma % cannot mention ghost and non-ghost types",
22595 N);
22596
22597 Error_Msg_Sloc := Sloc (Ghost_Id);
22598 Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id);
22599
22600 Error_Msg_Sloc := Sloc (Arg_Id);
22601 Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id);
22602 end if;
22603 else
22604 Error_Pragma_Arg
22605 ("argument for pragma% must be type or subtype", Arg);
22606 end if;
22607 else
22608 Error_Pragma_Arg
22609 ("argument for pragma% must be type or subtype", Arg);
22610 end if;
22611
22612 Next (Arg);
22613 end loop;
22614 end Unreferenced_Objects;
22615
22616 ------------------------------
22617 -- Unreserve_All_Interrupts --
22618 ------------------------------
22619
22620 -- pragma Unreserve_All_Interrupts;
22621
22622 when Pragma_Unreserve_All_Interrupts =>
22623 GNAT_Pragma;
22624 Check_Arg_Count (0);
22625
22626 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
22627 Unreserve_All_Interrupts := True;
22628 end if;
22629
22630 ----------------
22631 -- Unsuppress --
22632 ----------------
22633
22634 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
22635
22636 when Pragma_Unsuppress =>
22637 Ada_2005_Pragma;
22638 Process_Suppress_Unsuppress (Suppress_Case => False);
22639
22640 ----------------------------
22641 -- Unevaluated_Use_Of_Old --
22642 ----------------------------
22643
22644 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
22645
22646 when Pragma_Unevaluated_Use_Of_Old =>
22647 GNAT_Pragma;
22648 Check_Arg_Count (1);
22649 Check_No_Identifiers;
22650 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
22651
22652 -- Suppress/Unsuppress can appear as a configuration pragma, or in
22653 -- a declarative part or a package spec.
22654
22655 if not Is_Configuration_Pragma then
22656 Check_Is_In_Decl_Part_Or_Package_Spec;
22657 end if;
22658
22659 -- Store proper setting of Uneval_Old
22660
22661 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
22662 Uneval_Old := Fold_Upper (Name_Buffer (1));
22663
22664 -------------------
22665 -- Use_VADS_Size --
22666 -------------------
22667
22668 -- pragma Use_VADS_Size;
22669
22670 when Pragma_Use_VADS_Size =>
22671 GNAT_Pragma;
22672 Check_Arg_Count (0);
22673 Check_Valid_Configuration_Pragma;
22674 Use_VADS_Size := True;
22675
22676 ---------------------
22677 -- Validity_Checks --
22678 ---------------------
22679
22680 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22681
22682 when Pragma_Validity_Checks => Validity_Checks : declare
22683 A : constant Node_Id := Get_Pragma_Arg (Arg1);
22684 S : String_Id;
22685 C : Char_Code;
22686
22687 begin
22688 GNAT_Pragma;
22689 Check_Arg_Count (1);
22690 Check_No_Identifiers;
22691
22692 -- Pragma always active unless in CodePeer or GNATprove modes,
22693 -- which use a fixed configuration of validity checks.
22694
22695 if not (CodePeer_Mode or GNATprove_Mode) then
22696 if Nkind (A) = N_String_Literal then
22697 S := Strval (A);
22698
22699 declare
22700 Slen : constant Natural := Natural (String_Length (S));
22701 Options : String (1 .. Slen);
22702 J : Positive;
22703
22704 begin
22705 -- Couldn't we use a for loop here over Options'Range???
22706
22707 J := 1;
22708 loop
22709 C := Get_String_Char (S, Pos (J));
22710
22711 -- This is a weird test, it skips setting validity
22712 -- checks entirely if any element of S is out of
22713 -- range of Character, what is that about ???
22714
22715 exit when not In_Character_Range (C);
22716 Options (J) := Get_Character (C);
22717
22718 if J = Slen then
22719 Set_Validity_Check_Options (Options);
22720 exit;
22721 else
22722 J := J + 1;
22723 end if;
22724 end loop;
22725 end;
22726
22727 elsif Nkind (A) = N_Identifier then
22728 if Chars (A) = Name_All_Checks then
22729 Set_Validity_Check_Options ("a");
22730 elsif Chars (A) = Name_On then
22731 Validity_Checks_On := True;
22732 elsif Chars (A) = Name_Off then
22733 Validity_Checks_On := False;
22734 end if;
22735 end if;
22736 end if;
22737 end Validity_Checks;
22738
22739 --------------
22740 -- Volatile --
22741 --------------
22742
22743 -- pragma Volatile (LOCAL_NAME);
22744
22745 when Pragma_Volatile =>
22746 Process_Atomic_Independent_Shared_Volatile;
22747
22748 -------------------------
22749 -- Volatile_Components --
22750 -------------------------
22751
22752 -- pragma Volatile_Components (array_LOCAL_NAME);
22753
22754 -- Volatile is handled by the same circuit as Atomic_Components
22755
22756 --------------------------
22757 -- Volatile_Full_Access --
22758 --------------------------
22759
22760 -- pragma Volatile_Full_Access (LOCAL_NAME);
22761
22762 when Pragma_Volatile_Full_Access =>
22763 GNAT_Pragma;
22764 Process_Atomic_Independent_Shared_Volatile;
22765
22766 -----------------------
22767 -- Volatile_Function --
22768 -----------------------
22769
22770 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
22771
22772 when Pragma_Volatile_Function => Volatile_Function : declare
22773 Over_Id : Entity_Id;
22774 Spec_Id : Entity_Id;
22775 Subp_Decl : Node_Id;
22776
22777 begin
22778 GNAT_Pragma;
22779 Check_No_Identifiers;
22780 Check_At_Most_N_Arguments (1);
22781
22782 Subp_Decl :=
22783 Find_Related_Declaration_Or_Body (N, Do_Checks => True);
22784
22785 -- Generic subprogram
22786
22787 if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then
22788 null;
22789
22790 -- Body acts as spec
22791
22792 elsif Nkind (Subp_Decl) = N_Subprogram_Body
22793 and then No (Corresponding_Spec (Subp_Decl))
22794 then
22795 null;
22796
22797 -- Body stub acts as spec
22798
22799 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
22800 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
22801 then
22802 null;
22803
22804 -- Subprogram
22805
22806 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then
22807 null;
22808
22809 else
22810 Pragma_Misplaced;
22811 return;
22812 end if;
22813
22814 Spec_Id := Unique_Defining_Entity (Subp_Decl);
22815
22816 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
22817 Pragma_Misplaced;
22818 return;
22819 end if;
22820
22821 -- Chain the pragma on the contract for completeness
22822
22823 Add_Contract_Item (N, Spec_Id);
22824
22825 -- The legality checks of pragma Volatile_Function are affected by
22826 -- the SPARK mode in effect. Analyze all pragmas in a specific
22827 -- order.
22828
22829 Analyze_If_Present (Pragma_SPARK_Mode);
22830
22831 -- A pragma that applies to a Ghost entity becomes Ghost for the
22832 -- purposes of legality checks and removal of ignored Ghost code.
22833
22834 Mark_Pragma_As_Ghost (N, Spec_Id);
22835
22836 -- A volatile function cannot override a non-volatile function
22837 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
22838 -- in New_Overloaded_Entity, however at that point the pragma has
22839 -- not been processed yet.
22840
22841 Over_Id := Overridden_Operation (Spec_Id);
22842
22843 if Present (Over_Id)
22844 and then not Is_Volatile_Function (Over_Id)
22845 then
22846 Error_Msg_N
22847 ("incompatible volatile function values in effect", Spec_Id);
22848
22849 Error_Msg_Sloc := Sloc (Over_Id);
22850 Error_Msg_N
22851 ("\& declared # with Volatile_Function value False",
22852 Spec_Id);
22853
22854 Error_Msg_Sloc := Sloc (Spec_Id);
22855 Error_Msg_N
22856 ("\overridden # with Volatile_Function value True",
22857 Spec_Id);
22858 end if;
22859
22860 -- Analyze the Boolean expression (if any)
22861
22862 if Present (Arg1) then
22863 Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1));
22864 end if;
22865 end Volatile_Function;
22866
22867 ----------------------
22868 -- Warning_As_Error --
22869 ----------------------
22870
22871 -- pragma Warning_As_Error (static_string_EXPRESSION);
22872
22873 when Pragma_Warning_As_Error =>
22874 GNAT_Pragma;
22875 Check_Arg_Count (1);
22876 Check_No_Identifiers;
22877 Check_Valid_Configuration_Pragma;
22878
22879 if not Is_Static_String_Expression (Arg1) then
22880 Error_Pragma_Arg
22881 ("argument of pragma% must be static string expression",
22882 Arg1);
22883
22884 -- OK static string expression
22885
22886 else
22887 Acquire_Warning_Match_String (Arg1);
22888 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
22889 Warnings_As_Errors (Warnings_As_Errors_Count) :=
22890 new String'(Name_Buffer (1 .. Name_Len));
22891 end if;
22892
22893 --------------
22894 -- Warnings --
22895 --------------
22896
22897 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
22898
22899 -- DETAILS ::= On | Off
22900 -- DETAILS ::= On | Off, local_NAME
22901 -- DETAILS ::= static_string_EXPRESSION
22902 -- DETAILS ::= On | Off, static_string_EXPRESSION
22903
22904 -- TOOL_NAME ::= GNAT | GNATProve
22905
22906 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
22907
22908 -- Note: If the first argument matches an allowed tool name, it is
22909 -- always considered to be a tool name, even if there is a string
22910 -- variable of that name.
22911
22912 -- Note if the second argument of DETAILS is a local_NAME then the
22913 -- second form is always understood. If the intention is to use
22914 -- the fourth form, then you can write NAME & "" to force the
22915 -- intepretation as a static_string_EXPRESSION.
22916
22917 when Pragma_Warnings => Warnings : declare
22918 Reason : String_Id;
22919
22920 begin
22921 GNAT_Pragma;
22922 Check_At_Least_N_Arguments (1);
22923
22924 -- See if last argument is labeled Reason. If so, make sure we
22925 -- have a string literal or a concatenation of string literals,
22926 -- and acquire the REASON string. Then remove the REASON argument
22927 -- by decreasing Num_Args by one; Remaining processing looks only
22928 -- at first Num_Args arguments).
22929
22930 declare
22931 Last_Arg : constant Node_Id :=
22932 Last (Pragma_Argument_Associations (N));
22933
22934 begin
22935 if Nkind (Last_Arg) = N_Pragma_Argument_Association
22936 and then Chars (Last_Arg) = Name_Reason
22937 then
22938 Start_String;
22939 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
22940 Reason := End_String;
22941 Arg_Count := Arg_Count - 1;
22942
22943 -- Not allowed in compiler units (bootstrap issues)
22944
22945 Check_Compiler_Unit ("Reason for pragma Warnings", N);
22946
22947 -- No REASON string, set null string as reason
22948
22949 else
22950 Reason := Null_String_Id;
22951 end if;
22952 end;
22953
22954 -- Now proceed with REASON taken care of and eliminated
22955
22956 Check_No_Identifiers;
22957
22958 -- If debug flag -gnatd.i is set, pragma is ignored
22959
22960 if Debug_Flag_Dot_I then
22961 return;
22962 end if;
22963
22964 -- Process various forms of the pragma
22965
22966 declare
22967 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22968 Shifted_Args : List_Id;
22969
22970 begin
22971 -- See if first argument is a tool name, currently either
22972 -- GNAT or GNATprove. If so, either ignore the pragma if the
22973 -- tool used does not match, or continue as if no tool name
22974 -- was given otherwise, by shifting the arguments.
22975
22976 if Nkind (Argx) = N_Identifier
22977 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
22978 then
22979 if Chars (Argx) = Name_Gnat then
22980 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
22981 Rewrite (N, Make_Null_Statement (Loc));
22982 Analyze (N);
22983 raise Pragma_Exit;
22984 end if;
22985
22986 elsif Chars (Argx) = Name_Gnatprove then
22987 if not GNATprove_Mode then
22988 Rewrite (N, Make_Null_Statement (Loc));
22989 Analyze (N);
22990 raise Pragma_Exit;
22991 end if;
22992
22993 else
22994 raise Program_Error;
22995 end if;
22996
22997 -- At this point, the pragma Warnings applies to the tool,
22998 -- so continue with shifted arguments.
22999
23000 Arg_Count := Arg_Count - 1;
23001
23002 if Arg_Count = 1 then
23003 Shifted_Args := New_List (New_Copy (Arg2));
23004 elsif Arg_Count = 2 then
23005 Shifted_Args := New_List (New_Copy (Arg2),
23006 New_Copy (Arg3));
23007 elsif Arg_Count = 3 then
23008 Shifted_Args := New_List (New_Copy (Arg2),
23009 New_Copy (Arg3),
23010 New_Copy (Arg4));
23011 else
23012 raise Program_Error;
23013 end if;
23014
23015 Rewrite (N,
23016 Make_Pragma (Loc,
23017 Chars => Name_Warnings,
23018 Pragma_Argument_Associations => Shifted_Args));
23019 Analyze (N);
23020 raise Pragma_Exit;
23021 end if;
23022
23023 -- One argument case
23024
23025 if Arg_Count = 1 then
23026
23027 -- On/Off one argument case was processed by parser
23028
23029 if Nkind (Argx) = N_Identifier
23030 and then Nam_In (Chars (Argx), Name_On, Name_Off)
23031 then
23032 null;
23033
23034 -- One argument case must be ON/OFF or static string expr
23035
23036 elsif not Is_Static_String_Expression (Arg1) then
23037 Error_Pragma_Arg
23038 ("argument of pragma% must be On/Off or static string "
23039 & "expression", Arg1);
23040
23041 -- One argument string expression case
23042
23043 else
23044 declare
23045 Lit : constant Node_Id := Expr_Value_S (Argx);
23046 Str : constant String_Id := Strval (Lit);
23047 Len : constant Nat := String_Length (Str);
23048 C : Char_Code;
23049 J : Nat;
23050 OK : Boolean;
23051 Chr : Character;
23052
23053 begin
23054 J := 1;
23055 while J <= Len loop
23056 C := Get_String_Char (Str, J);
23057 OK := In_Character_Range (C);
23058
23059 if OK then
23060 Chr := Get_Character (C);
23061
23062 -- Dash case: only -Wxxx is accepted
23063
23064 if J = 1
23065 and then J < Len
23066 and then Chr = '-'
23067 then
23068 J := J + 1;
23069 C := Get_String_Char (Str, J);
23070 Chr := Get_Character (C);
23071 exit when Chr = 'W';
23072 OK := False;
23073
23074 -- Dot case
23075
23076 elsif J < Len and then Chr = '.' then
23077 J := J + 1;
23078 C := Get_String_Char (Str, J);
23079 Chr := Get_Character (C);
23080
23081 if not Set_Dot_Warning_Switch (Chr) then
23082 Error_Pragma_Arg
23083 ("invalid warning switch character "
23084 & '.' & Chr, Arg1);
23085 end if;
23086
23087 -- Non-Dot case
23088
23089 else
23090 OK := Set_Warning_Switch (Chr);
23091 end if;
23092 end if;
23093
23094 if not OK then
23095 Error_Pragma_Arg
23096 ("invalid warning switch character " & Chr,
23097 Arg1);
23098 end if;
23099
23100 J := J + 1;
23101 end loop;
23102 end;
23103 end if;
23104
23105 -- Two or more arguments (must be two)
23106
23107 else
23108 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23109 Check_Arg_Count (2);
23110
23111 declare
23112 E_Id : Node_Id;
23113 E : Entity_Id;
23114 Err : Boolean;
23115
23116 begin
23117 E_Id := Get_Pragma_Arg (Arg2);
23118 Analyze (E_Id);
23119
23120 -- In the expansion of an inlined body, a reference to
23121 -- the formal may be wrapped in a conversion if the
23122 -- actual is a conversion. Retrieve the real entity name.
23123
23124 if (In_Instance_Body or In_Inlined_Body)
23125 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
23126 then
23127 E_Id := Expression (E_Id);
23128 end if;
23129
23130 -- Entity name case
23131
23132 if Is_Entity_Name (E_Id) then
23133 E := Entity (E_Id);
23134
23135 if E = Any_Id then
23136 return;
23137 else
23138 loop
23139 Set_Warnings_Off
23140 (E, (Chars (Get_Pragma_Arg (Arg1)) =
23141 Name_Off));
23142
23143 -- For OFF case, make entry in warnings off
23144 -- pragma table for later processing. But we do
23145 -- not do that within an instance, since these
23146 -- warnings are about what is needed in the
23147 -- template, not an instance of it.
23148
23149 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
23150 and then Warn_On_Warnings_Off
23151 and then not In_Instance
23152 then
23153 Warnings_Off_Pragmas.Append ((N, E, Reason));
23154 end if;
23155
23156 if Is_Enumeration_Type (E) then
23157 declare
23158 Lit : Entity_Id;
23159 begin
23160 Lit := First_Literal (E);
23161 while Present (Lit) loop
23162 Set_Warnings_Off (Lit);
23163 Next_Literal (Lit);
23164 end loop;
23165 end;
23166 end if;
23167
23168 exit when No (Homonym (E));
23169 E := Homonym (E);
23170 end loop;
23171 end if;
23172
23173 -- Error if not entity or static string expression case
23174
23175 elsif not Is_Static_String_Expression (Arg2) then
23176 Error_Pragma_Arg
23177 ("second argument of pragma% must be entity name "
23178 & "or static string expression", Arg2);
23179
23180 -- Static string expression case
23181
23182 else
23183 Acquire_Warning_Match_String (Arg2);
23184
23185 -- Note on configuration pragma case: If this is a
23186 -- configuration pragma, then for an OFF pragma, we
23187 -- just set Config True in the call, which is all
23188 -- that needs to be done. For the case of ON, this
23189 -- is normally an error, unless it is canceling the
23190 -- effect of a previous OFF pragma in the same file.
23191 -- In any other case, an error will be signalled (ON
23192 -- with no matching OFF).
23193
23194 -- Note: We set Used if we are inside a generic to
23195 -- disable the test that the non-config case actually
23196 -- cancels a warning. That's because we can't be sure
23197 -- there isn't an instantiation in some other unit
23198 -- where a warning is suppressed.
23199
23200 -- We could do a little better here by checking if the
23201 -- generic unit we are inside is public, but for now
23202 -- we don't bother with that refinement.
23203
23204 if Chars (Argx) = Name_Off then
23205 Set_Specific_Warning_Off
23206 (Loc, Name_Buffer (1 .. Name_Len), Reason,
23207 Config => Is_Configuration_Pragma,
23208 Used => Inside_A_Generic or else In_Instance);
23209
23210 elsif Chars (Argx) = Name_On then
23211 Set_Specific_Warning_On
23212 (Loc, Name_Buffer (1 .. Name_Len), Err);
23213
23214 if Err then
23215 Error_Msg
23216 ("??pragma Warnings On with no matching "
23217 & "Warnings Off", Loc);
23218 end if;
23219 end if;
23220 end if;
23221 end;
23222 end if;
23223 end;
23224 end Warnings;
23225
23226 -------------------
23227 -- Weak_External --
23228 -------------------
23229
23230 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
23231
23232 when Pragma_Weak_External => Weak_External : declare
23233 Ent : Entity_Id;
23234
23235 begin
23236 GNAT_Pragma;
23237 Check_Arg_Count (1);
23238 Check_Optional_Identifier (Arg1, Name_Entity);
23239 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23240 Ent := Entity (Get_Pragma_Arg (Arg1));
23241
23242 if Rep_Item_Too_Early (Ent, N) then
23243 return;
23244 else
23245 Ent := Underlying_Type (Ent);
23246 end if;
23247
23248 -- The only processing required is to link this item on to the
23249 -- list of rep items for the given entity. This is accomplished
23250 -- by the call to Rep_Item_Too_Late (when no error is detected
23251 -- and False is returned).
23252
23253 if Rep_Item_Too_Late (Ent, N) then
23254 return;
23255 else
23256 Set_Has_Gigi_Rep_Item (Ent);
23257 end if;
23258 end Weak_External;
23259
23260 -----------------------------
23261 -- Wide_Character_Encoding --
23262 -----------------------------
23263
23264 -- pragma Wide_Character_Encoding (IDENTIFIER);
23265
23266 when Pragma_Wide_Character_Encoding =>
23267 GNAT_Pragma;
23268
23269 -- Nothing to do, handled in parser. Note that we do not enforce
23270 -- configuration pragma placement, this pragma can appear at any
23271 -- place in the source, allowing mixed encodings within a single
23272 -- source program.
23273
23274 null;
23275
23276 --------------------
23277 -- Unknown_Pragma --
23278 --------------------
23279
23280 -- Should be impossible, since the case of an unknown pragma is
23281 -- separately processed before the case statement is entered.
23282
23283 when Unknown_Pragma =>
23284 raise Program_Error;
23285 end case;
23286
23287 -- AI05-0144: detect dangerous order dependence. Disabled for now,
23288 -- until AI is formally approved.
23289
23290 -- Check_Order_Dependence;
23291
23292 exception
23293 when Pragma_Exit => null;
23294 end Analyze_Pragma;
23295
23296 ---------------------------------------------
23297 -- Analyze_Pre_Post_Condition_In_Decl_Part --
23298 ---------------------------------------------
23299
23300 procedure Analyze_Pre_Post_Condition_In_Decl_Part
23301 (N : Node_Id;
23302 Freeze_Id : Entity_Id := Empty)
23303 is
23304 Disp_Typ : Entity_Id;
23305 -- The dispatching type of the subprogram subject to the pre- or
23306 -- postcondition.
23307
23308 function Check_References (Nod : Node_Id) return Traverse_Result;
23309 -- Check that expression Nod does not mention non-primitives of the
23310 -- type, global objects of the type, or other illegalities described
23311 -- and implied by AI12-0113.
23312
23313 ----------------------
23314 -- Check_References --
23315 ----------------------
23316
23317 function Check_References (Nod : Node_Id) return Traverse_Result is
23318 begin
23319 if Nkind (Nod) = N_Function_Call
23320 and then Is_Entity_Name (Name (Nod))
23321 then
23322 declare
23323 Func : constant Entity_Id := Entity (Name (Nod));
23324 Form : Entity_Id;
23325
23326 begin
23327 -- An operation of the type must be a primitive
23328
23329 if No (Find_Dispatching_Type (Func)) then
23330 Form := First_Formal (Func);
23331 while Present (Form) loop
23332 if Etype (Form) = Disp_Typ then
23333 Error_Msg_NE
23334 ("operation in class-wide condition must be "
23335 & "primitive of &", Nod, Disp_Typ);
23336 end if;
23337
23338 Next_Formal (Form);
23339 end loop;
23340
23341 -- A return object of the type is illegal as well
23342
23343 if Etype (Func) = Disp_Typ
23344 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
23345 then
23346 Error_Msg_NE
23347 ("operation in class-wide condition must be primitive "
23348 & "of &", Nod, Disp_Typ);
23349 end if;
23350 end if;
23351 end;
23352
23353 elsif Is_Entity_Name (Nod)
23354 and then
23355 (Etype (Nod) = Disp_Typ
23356 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
23357 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
23358 then
23359 Error_Msg_NE
23360 ("object in class-wide condition must be formal of type &",
23361 Nod, Disp_Typ);
23362
23363 elsif Nkind (Nod) = N_Explicit_Dereference
23364 and then (Etype (Nod) = Disp_Typ
23365 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
23366 and then (not Is_Entity_Name (Prefix (Nod))
23367 or else not Is_Formal (Entity (Prefix (Nod))))
23368 then
23369 Error_Msg_NE
23370 ("operation in class-wide condition must be primitive of &",
23371 Nod, Disp_Typ);
23372 end if;
23373
23374 return OK;
23375 end Check_References;
23376
23377 procedure Check_Class_Wide_Condition is
23378 new Traverse_Proc (Check_References);
23379
23380 -- Local variables
23381
23382 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
23383 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
23384 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
23385
23386 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
23387
23388 Errors : Nat;
23389 Restore_Scope : Boolean := False;
23390
23391 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
23392
23393 begin
23394 -- Do not analyze the pragma multiple times
23395
23396 if Is_Analyzed_Pragma (N) then
23397 return;
23398 end if;
23399
23400 -- Set the Ghost mode in effect from the pragma. Due to the delayed
23401 -- analysis of the pragma, the Ghost mode at point of declaration and
23402 -- point of analysis may not necessarily be the same. Use the mode in
23403 -- effect at the point of declaration.
23404
23405 Set_Ghost_Mode (N);
23406
23407 -- Ensure that the subprogram and its formals are visible when analyzing
23408 -- the expression of the pragma.
23409
23410 if not In_Open_Scopes (Spec_Id) then
23411 Restore_Scope := True;
23412 Push_Scope (Spec_Id);
23413
23414 if Is_Generic_Subprogram (Spec_Id) then
23415 Install_Generic_Formals (Spec_Id);
23416 else
23417 Install_Formals (Spec_Id);
23418 end if;
23419 end if;
23420
23421 Errors := Serious_Errors_Detected;
23422 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
23423
23424 -- Emit a clarification message when the expression contains at least
23425 -- one undefined reference, possibly due to contract "freezing".
23426
23427 if Errors /= Serious_Errors_Detected
23428 and then Present (Freeze_Id)
23429 and then Has_Undefined_Reference (Expr)
23430 then
23431 Contract_Freeze_Error (Spec_Id, Freeze_Id);
23432 end if;
23433
23434 if Class_Present (N) then
23435
23436 -- Verify that a class-wide condition is legal, i.e. the operation is
23437 -- a primitive of a tagged type. Note that a generic subprogram is
23438 -- not a primitive operation.
23439
23440 Disp_Typ := Find_Dispatching_Type (Spec_Id);
23441
23442 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
23443 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
23444
23445 if From_Aspect_Specification (N) then
23446 Error_Msg_N
23447 ("aspect % can only be specified for a primitive operation "
23448 & "of a tagged type", Corresponding_Aspect (N));
23449
23450 -- The pragma is a source construct
23451
23452 else
23453 Error_Msg_N
23454 ("pragma % can only be specified for a primitive operation "
23455 & "of a tagged type", N);
23456 end if;
23457
23458 -- Remaining semantic checks require a full tree traversal
23459
23460 else
23461 Check_Class_Wide_Condition (Expr);
23462 end if;
23463
23464 end if;
23465
23466 if Restore_Scope then
23467 End_Scope;
23468 end if;
23469
23470 -- Currently it is not possible to inline pre/postconditions on a
23471 -- subprogram subject to pragma Inline_Always.
23472
23473 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
23474 Ghost_Mode := Save_Ghost_Mode;
23475
23476 Set_Is_Analyzed_Pragma (N);
23477 end Analyze_Pre_Post_Condition_In_Decl_Part;
23478
23479 ------------------------------------------
23480 -- Analyze_Refined_Depends_In_Decl_Part --
23481 ------------------------------------------
23482
23483 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
23484 Body_Inputs : Elist_Id := No_Elist;
23485 Body_Outputs : Elist_Id := No_Elist;
23486 -- The inputs and outputs of the subprogram body synthesized from pragma
23487 -- Refined_Depends.
23488
23489 Dependencies : List_Id := No_List;
23490 Depends : Node_Id;
23491 -- The corresponding Depends pragma along with its clauses
23492
23493 Matched_Items : Elist_Id := No_Elist;
23494 -- A list containing the entities of all successfully matched items
23495 -- found in pragma Depends.
23496
23497 Refinements : List_Id := No_List;
23498 -- The clauses of pragma Refined_Depends
23499
23500 Spec_Id : Entity_Id;
23501 -- The entity of the subprogram subject to pragma Refined_Depends
23502
23503 Spec_Inputs : Elist_Id := No_Elist;
23504 Spec_Outputs : Elist_Id := No_Elist;
23505 -- The inputs and outputs of the subprogram spec synthesized from pragma
23506 -- Depends.
23507
23508 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
23509 -- Try to match a single dependency clause Dep_Clause against one or
23510 -- more refinement clauses found in list Refinements. Each successful
23511 -- match eliminates at least one refinement clause from Refinements.
23512
23513 procedure Check_Output_States;
23514 -- Determine whether pragma Depends contains an output state with a
23515 -- visible refinement and if so, ensure that pragma Refined_Depends
23516 -- mentions all its constituents as outputs.
23517
23518 procedure Normalize_Clauses (Clauses : List_Id);
23519 -- Given a list of dependence or refinement clauses Clauses, normalize
23520 -- each clause by creating multiple dependencies with exactly one input
23521 -- and one output.
23522
23523 procedure Report_Extra_Clauses;
23524 -- Emit an error for each extra clause found in list Refinements
23525
23526 -----------------------------
23527 -- Check_Dependency_Clause --
23528 -----------------------------
23529
23530 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
23531 Dep_Input : constant Node_Id := Expression (Dep_Clause);
23532 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
23533
23534 function Is_In_Out_State_Clause return Boolean;
23535 -- Determine whether dependence clause Dep_Clause denotes an abstract
23536 -- state that depends on itself (State => State).
23537
23538 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
23539 -- Determine whether item Item denotes an abstract state with visible
23540 -- null refinement.
23541
23542 procedure Match_Items
23543 (Dep_Item : Node_Id;
23544 Ref_Item : Node_Id;
23545 Matched : out Boolean);
23546 -- Try to match dependence item Dep_Item against refinement item
23547 -- Ref_Item. To match against a possible null refinement (see 2, 7),
23548 -- set Ref_Item to Empty. Flag Matched is set to True when one of
23549 -- the following conformance scenarios is in effect:
23550 -- 1) Both items denote null
23551 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
23552 -- 3) Both items denote attribute 'Result
23553 -- 4) Both items denote the same object
23554 -- 5) Both items denote the same formal parameter
23555 -- 6) Both items denote the same current instance of a type
23556 -- 7) Both items denote the same discriminant
23557 -- 8) Dep_Item is an abstract state with visible null refinement
23558 -- and Ref_Item denotes null.
23559 -- 9) Dep_Item is an abstract state with visible null refinement
23560 -- and Ref_Item is Empty (special case).
23561 -- 10) Dep_Item is an abstract state with visible non-null
23562 -- refinement and Ref_Item denotes one of its constituents.
23563 -- 11) Dep_Item is an abstract state without a visible refinement
23564 -- and Ref_Item denotes the same state.
23565 -- When scenario 10 is in effect, the entity of the abstract state
23566 -- denoted by Dep_Item is added to list Refined_States.
23567
23568 procedure Record_Item (Item_Id : Entity_Id);
23569 -- Store the entity of an item denoted by Item_Id in Matched_Items
23570
23571 ----------------------------
23572 -- Is_In_Out_State_Clause --
23573 ----------------------------
23574
23575 function Is_In_Out_State_Clause return Boolean is
23576 Dep_Input_Id : Entity_Id;
23577 Dep_Output_Id : Entity_Id;
23578
23579 begin
23580 -- Detect the following clause:
23581 -- State => State
23582
23583 if Is_Entity_Name (Dep_Input)
23584 and then Is_Entity_Name (Dep_Output)
23585 then
23586 -- Handle abstract views generated for limited with clauses
23587
23588 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
23589 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
23590
23591 return
23592 Ekind (Dep_Input_Id) = E_Abstract_State
23593 and then Dep_Input_Id = Dep_Output_Id;
23594 else
23595 return False;
23596 end if;
23597 end Is_In_Out_State_Clause;
23598
23599 ---------------------------
23600 -- Is_Null_Refined_State --
23601 ---------------------------
23602
23603 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
23604 Item_Id : Entity_Id;
23605
23606 begin
23607 if Is_Entity_Name (Item) then
23608
23609 -- Handle abstract views generated for limited with clauses
23610
23611 Item_Id := Available_View (Entity_Of (Item));
23612
23613 return
23614 Ekind (Item_Id) = E_Abstract_State
23615 and then Has_Null_Visible_Refinement (Item_Id);
23616 else
23617 return False;
23618 end if;
23619 end Is_Null_Refined_State;
23620
23621 -----------------
23622 -- Match_Items --
23623 -----------------
23624
23625 procedure Match_Items
23626 (Dep_Item : Node_Id;
23627 Ref_Item : Node_Id;
23628 Matched : out Boolean)
23629 is
23630 Dep_Item_Id : Entity_Id;
23631 Ref_Item_Id : Entity_Id;
23632
23633 begin
23634 -- Assume that the two items do not match
23635
23636 Matched := False;
23637
23638 -- A null matches null or Empty (special case)
23639
23640 if Nkind (Dep_Item) = N_Null
23641 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
23642 then
23643 Matched := True;
23644
23645 -- Attribute 'Result matches attribute 'Result
23646
23647 elsif Is_Attribute_Result (Dep_Item)
23648 and then Is_Attribute_Result (Dep_Item)
23649 then
23650 Matched := True;
23651
23652 -- Abstract states, current instances of concurrent types,
23653 -- discriminants, formal parameters and objects.
23654
23655 elsif Is_Entity_Name (Dep_Item) then
23656
23657 -- Handle abstract views generated for limited with clauses
23658
23659 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
23660
23661 if Ekind (Dep_Item_Id) = E_Abstract_State then
23662
23663 -- An abstract state with visible null refinement matches
23664 -- null or Empty (special case).
23665
23666 if Has_Null_Visible_Refinement (Dep_Item_Id)
23667 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
23668 then
23669 Record_Item (Dep_Item_Id);
23670 Matched := True;
23671
23672 -- An abstract state with visible non-null refinement
23673 -- matches one of its constituents.
23674
23675 elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then
23676 if Is_Entity_Name (Ref_Item) then
23677 Ref_Item_Id := Entity_Of (Ref_Item);
23678
23679 if Ekind_In (Ref_Item_Id, E_Abstract_State,
23680 E_Constant,
23681 E_Variable)
23682 and then Present (Encapsulating_State (Ref_Item_Id))
23683 and then Encapsulating_State (Ref_Item_Id) =
23684 Dep_Item_Id
23685 then
23686 Record_Item (Dep_Item_Id);
23687 Matched := True;
23688 end if;
23689 end if;
23690
23691 -- An abstract state without a visible refinement matches
23692 -- itself.
23693
23694 elsif Is_Entity_Name (Ref_Item)
23695 and then Entity_Of (Ref_Item) = Dep_Item_Id
23696 then
23697 Record_Item (Dep_Item_Id);
23698 Matched := True;
23699 end if;
23700
23701 -- A current instance of a concurrent type, discriminant,
23702 -- formal parameter or an object matches itself.
23703
23704 elsif Is_Entity_Name (Ref_Item)
23705 and then Entity_Of (Ref_Item) = Dep_Item_Id
23706 then
23707 Record_Item (Dep_Item_Id);
23708 Matched := True;
23709 end if;
23710 end if;
23711 end Match_Items;
23712
23713 -----------------
23714 -- Record_Item --
23715 -----------------
23716
23717 procedure Record_Item (Item_Id : Entity_Id) is
23718 begin
23719 if not Contains (Matched_Items, Item_Id) then
23720 Append_New_Elmt (Item_Id, Matched_Items);
23721 end if;
23722 end Record_Item;
23723
23724 -- Local variables
23725
23726 Clause_Matched : Boolean := False;
23727 Dummy : Boolean := False;
23728 Inputs_Match : Boolean;
23729 Next_Ref_Clause : Node_Id;
23730 Outputs_Match : Boolean;
23731 Ref_Clause : Node_Id;
23732 Ref_Input : Node_Id;
23733 Ref_Output : Node_Id;
23734
23735 -- Start of processing for Check_Dependency_Clause
23736
23737 begin
23738 -- Do not perform this check in an instance because it was already
23739 -- performed successfully in the generic template.
23740
23741 if Is_Generic_Instance (Spec_Id) then
23742 return;
23743 end if;
23744
23745 -- Examine all refinement clauses and compare them against the
23746 -- dependence clause.
23747
23748 Ref_Clause := First (Refinements);
23749 while Present (Ref_Clause) loop
23750 Next_Ref_Clause := Next (Ref_Clause);
23751
23752 -- Obtain the attributes of the current refinement clause
23753
23754 Ref_Input := Expression (Ref_Clause);
23755 Ref_Output := First (Choices (Ref_Clause));
23756
23757 -- The current refinement clause matches the dependence clause
23758 -- when both outputs match and both inputs match. See routine
23759 -- Match_Items for all possible conformance scenarios.
23760
23761 -- Depends Dep_Output => Dep_Input
23762 -- ^ ^
23763 -- match ? match ?
23764 -- v v
23765 -- Refined_Depends Ref_Output => Ref_Input
23766
23767 Match_Items
23768 (Dep_Item => Dep_Input,
23769 Ref_Item => Ref_Input,
23770 Matched => Inputs_Match);
23771
23772 Match_Items
23773 (Dep_Item => Dep_Output,
23774 Ref_Item => Ref_Output,
23775 Matched => Outputs_Match);
23776
23777 -- An In_Out state clause may be matched against a refinement with
23778 -- a null input or null output as long as the non-null side of the
23779 -- relation contains a valid constituent of the In_Out_State.
23780
23781 if Is_In_Out_State_Clause then
23782
23783 -- Depends => (State => State)
23784 -- Refined_Depends => (null => Constit) -- OK
23785
23786 if Inputs_Match
23787 and then not Outputs_Match
23788 and then Nkind (Ref_Output) = N_Null
23789 then
23790 Outputs_Match := True;
23791 end if;
23792
23793 -- Depends => (State => State)
23794 -- Refined_Depends => (Constit => null) -- OK
23795
23796 if not Inputs_Match
23797 and then Outputs_Match
23798 and then Nkind (Ref_Input) = N_Null
23799 then
23800 Inputs_Match := True;
23801 end if;
23802 end if;
23803
23804 -- The current refinement clause is legally constructed following
23805 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
23806 -- the pool of candidates. The seach continues because a single
23807 -- dependence clause may have multiple matching refinements.
23808
23809 if Inputs_Match and Outputs_Match then
23810 Clause_Matched := True;
23811 Remove (Ref_Clause);
23812 end if;
23813
23814 Ref_Clause := Next_Ref_Clause;
23815 end loop;
23816
23817 -- Depending on the order or composition of refinement clauses, an
23818 -- In_Out state clause may not be directly refinable.
23819
23820 -- Depends => ((Output, State) => (Input, State))
23821 -- Refined_State => (State => (Constit_1, Constit_2))
23822 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
23823
23824 -- Matching normalized clause (State => State) fails because there is
23825 -- no direct refinement capable of satisfying this relation. Another
23826 -- similar case arises when clauses (Constit_1 => Input) and (Output
23827 -- => Constit_2) are matched first, leaving no candidates for clause
23828 -- (State => State). Both scenarios are legal as long as one of the
23829 -- previous clauses mentioned a valid constituent of State.
23830
23831 if not Clause_Matched
23832 and then Is_In_Out_State_Clause
23833 and then
23834 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
23835 then
23836 Clause_Matched := True;
23837 end if;
23838
23839 -- A clause where the input is an abstract state with visible null
23840 -- refinement is implicitly matched when the output has already been
23841 -- matched in a previous clause.
23842
23843 -- Depends => (Output => State) -- implicitly OK
23844 -- Refined_State => (State => null)
23845 -- Refined_Depends => (Output => ...)
23846
23847 if not Clause_Matched
23848 and then Is_Null_Refined_State (Dep_Input)
23849 and then Is_Entity_Name (Dep_Output)
23850 and then
23851 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
23852 then
23853 Clause_Matched := True;
23854 end if;
23855
23856 -- A clause where the output is an abstract state with visible null
23857 -- refinement is implicitly matched when the input has already been
23858 -- matched in a previous clause.
23859
23860 -- Depends => (State => Input) -- implicitly OK
23861 -- Refined_State => (State => null)
23862 -- Refined_Depends => (... => Input)
23863
23864 if not Clause_Matched
23865 and then Is_Null_Refined_State (Dep_Output)
23866 and then Is_Entity_Name (Dep_Input)
23867 and then
23868 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
23869 then
23870 Clause_Matched := True;
23871 end if;
23872
23873 -- At this point either all refinement clauses have been examined or
23874 -- pragma Refined_Depends contains a solitary null. Only an abstract
23875 -- state with null refinement can possibly match these cases.
23876
23877 -- Depends => (State => null)
23878 -- Refined_State => (State => null)
23879 -- Refined_Depends => null -- OK
23880
23881 if not Clause_Matched then
23882 Match_Items
23883 (Dep_Item => Dep_Input,
23884 Ref_Item => Empty,
23885 Matched => Inputs_Match);
23886
23887 Match_Items
23888 (Dep_Item => Dep_Output,
23889 Ref_Item => Empty,
23890 Matched => Outputs_Match);
23891
23892 Clause_Matched := Inputs_Match and Outputs_Match;
23893 end if;
23894
23895 -- If the contents of Refined_Depends are legal, then the current
23896 -- dependence clause should be satisfied either by an explicit match
23897 -- or by one of the special cases.
23898
23899 if not Clause_Matched then
23900 SPARK_Msg_NE
23901 (Fix_Msg (Spec_Id, "dependence clause of subprogram & has no "
23902 & "matching refinement in body"), Dep_Clause, Spec_Id);
23903 end if;
23904 end Check_Dependency_Clause;
23905
23906 -------------------------
23907 -- Check_Output_States --
23908 -------------------------
23909
23910 procedure Check_Output_States is
23911 procedure Check_Constituent_Usage (State_Id : Entity_Id);
23912 -- Determine whether all constituents of state State_Id with visible
23913 -- refinement are used as outputs in pragma Refined_Depends. Emit an
23914 -- error if this is not the case.
23915
23916 -----------------------------
23917 -- Check_Constituent_Usage --
23918 -----------------------------
23919
23920 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
23921 Constits : constant Elist_Id :=
23922 Refinement_Constituents (State_Id);
23923 Constit_Elmt : Elmt_Id;
23924 Constit_Id : Entity_Id;
23925 Posted : Boolean := False;
23926
23927 begin
23928 if Present (Constits) then
23929 Constit_Elmt := First_Elmt (Constits);
23930 while Present (Constit_Elmt) loop
23931 Constit_Id := Node (Constit_Elmt);
23932
23933 -- The constituent acts as an input (SPARK RM 7.2.5(3))
23934
23935 if Present (Body_Inputs)
23936 and then Appears_In (Body_Inputs, Constit_Id)
23937 then
23938 Error_Msg_Name_1 := Chars (State_Id);
23939 SPARK_Msg_NE
23940 ("constituent & of state % must act as output in "
23941 & "dependence refinement", N, Constit_Id);
23942
23943 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
23944
23945 elsif No (Body_Outputs)
23946 or else not Appears_In (Body_Outputs, Constit_Id)
23947 then
23948 if not Posted then
23949 Posted := True;
23950 SPARK_Msg_NE
23951 ("output state & must be replaced by all its "
23952 & "constituents in dependence refinement",
23953 N, State_Id);
23954 end if;
23955
23956 SPARK_Msg_NE
23957 ("\constituent & is missing in output list",
23958 N, Constit_Id);
23959 end if;
23960
23961 Next_Elmt (Constit_Elmt);
23962 end loop;
23963 end if;
23964 end Check_Constituent_Usage;
23965
23966 -- Local variables
23967
23968 Item : Node_Id;
23969 Item_Elmt : Elmt_Id;
23970 Item_Id : Entity_Id;
23971
23972 -- Start of processing for Check_Output_States
23973
23974 begin
23975 -- Do not perform this check in an instance because it was already
23976 -- performed successfully in the generic template.
23977
23978 if Is_Generic_Instance (Spec_Id) then
23979 null;
23980
23981 -- Inspect the outputs of pragma Depends looking for a state with a
23982 -- visible refinement.
23983
23984 elsif Present (Spec_Outputs) then
23985 Item_Elmt := First_Elmt (Spec_Outputs);
23986 while Present (Item_Elmt) loop
23987 Item := Node (Item_Elmt);
23988
23989 -- Deal with the mixed nature of the input and output lists
23990
23991 if Nkind (Item) = N_Defining_Identifier then
23992 Item_Id := Item;
23993 else
23994 Item_Id := Available_View (Entity_Of (Item));
23995 end if;
23996
23997 if Ekind (Item_Id) = E_Abstract_State then
23998
23999 -- The state acts as an input-output, skip it
24000
24001 if Present (Spec_Inputs)
24002 and then Appears_In (Spec_Inputs, Item_Id)
24003 then
24004 null;
24005
24006 -- Ensure that all of the constituents are utilized as
24007 -- outputs in pragma Refined_Depends.
24008
24009 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
24010 Check_Constituent_Usage (Item_Id);
24011 end if;
24012 end if;
24013
24014 Next_Elmt (Item_Elmt);
24015 end loop;
24016 end if;
24017 end Check_Output_States;
24018
24019 -----------------------
24020 -- Normalize_Clauses --
24021 -----------------------
24022
24023 procedure Normalize_Clauses (Clauses : List_Id) is
24024 procedure Normalize_Inputs (Clause : Node_Id);
24025 -- Normalize clause Clause by creating multiple clauses for each
24026 -- input item of Clause. It is assumed that Clause has exactly one
24027 -- output. The transformation is as follows:
24028 --
24029 -- Output => (Input_1, Input_2) -- original
24030 --
24031 -- Output => Input_1 -- normalizations
24032 -- Output => Input_2
24033
24034 procedure Normalize_Outputs (Clause : Node_Id);
24035 -- Normalize clause Clause by creating multiple clause for each
24036 -- output item of Clause. The transformation is as follows:
24037 --
24038 -- (Output_1, Output_2) => Input -- original
24039 --
24040 -- Output_1 => Input -- normalization
24041 -- Output_2 => Input
24042
24043 ----------------------
24044 -- Normalize_Inputs --
24045 ----------------------
24046
24047 procedure Normalize_Inputs (Clause : Node_Id) is
24048 Inputs : constant Node_Id := Expression (Clause);
24049 Loc : constant Source_Ptr := Sloc (Clause);
24050 Output : constant List_Id := Choices (Clause);
24051 Last_Input : Node_Id;
24052 Input : Node_Id;
24053 New_Clause : Node_Id;
24054 Next_Input : Node_Id;
24055
24056 begin
24057 -- Normalization is performed only when the original clause has
24058 -- more than one input. Multiple inputs appear as an aggregate.
24059
24060 if Nkind (Inputs) = N_Aggregate then
24061 Last_Input := Last (Expressions (Inputs));
24062
24063 -- Create a new clause for each input
24064
24065 Input := First (Expressions (Inputs));
24066 while Present (Input) loop
24067 Next_Input := Next (Input);
24068
24069 -- Unhook the current input from the original input list
24070 -- because it will be relocated to a new clause.
24071
24072 Remove (Input);
24073
24074 -- Special processing for the last input. At this point the
24075 -- original aggregate has been stripped down to one element.
24076 -- Replace the aggregate by the element itself.
24077
24078 if Input = Last_Input then
24079 Rewrite (Inputs, Input);
24080
24081 -- Generate a clause of the form:
24082 -- Output => Input
24083
24084 else
24085 New_Clause :=
24086 Make_Component_Association (Loc,
24087 Choices => New_Copy_List_Tree (Output),
24088 Expression => Input);
24089
24090 -- The new clause contains replicated content that has
24091 -- already been analyzed, mark the clause as analyzed.
24092
24093 Set_Analyzed (New_Clause);
24094 Insert_After (Clause, New_Clause);
24095 end if;
24096
24097 Input := Next_Input;
24098 end loop;
24099 end if;
24100 end Normalize_Inputs;
24101
24102 -----------------------
24103 -- Normalize_Outputs --
24104 -----------------------
24105
24106 procedure Normalize_Outputs (Clause : Node_Id) is
24107 Inputs : constant Node_Id := Expression (Clause);
24108 Loc : constant Source_Ptr := Sloc (Clause);
24109 Outputs : constant Node_Id := First (Choices (Clause));
24110 Last_Output : Node_Id;
24111 New_Clause : Node_Id;
24112 Next_Output : Node_Id;
24113 Output : Node_Id;
24114
24115 begin
24116 -- Multiple outputs appear as an aggregate. Nothing to do when
24117 -- the clause has exactly one output.
24118
24119 if Nkind (Outputs) = N_Aggregate then
24120 Last_Output := Last (Expressions (Outputs));
24121
24122 -- Create a clause for each output. Note that each time a new
24123 -- clause is created, the original output list slowly shrinks
24124 -- until there is one item left.
24125
24126 Output := First (Expressions (Outputs));
24127 while Present (Output) loop
24128 Next_Output := Next (Output);
24129
24130 -- Unhook the output from the original output list as it
24131 -- will be relocated to a new clause.
24132
24133 Remove (Output);
24134
24135 -- Special processing for the last output. At this point
24136 -- the original aggregate has been stripped down to one
24137 -- element. Replace the aggregate by the element itself.
24138
24139 if Output = Last_Output then
24140 Rewrite (Outputs, Output);
24141
24142 else
24143 -- Generate a clause of the form:
24144 -- (Output => Inputs)
24145
24146 New_Clause :=
24147 Make_Component_Association (Loc,
24148 Choices => New_List (Output),
24149 Expression => New_Copy_Tree (Inputs));
24150
24151 -- The new clause contains replicated content that has
24152 -- already been analyzed. There is not need to reanalyze
24153 -- them.
24154
24155 Set_Analyzed (New_Clause);
24156 Insert_After (Clause, New_Clause);
24157 end if;
24158
24159 Output := Next_Output;
24160 end loop;
24161 end if;
24162 end Normalize_Outputs;
24163
24164 -- Local variables
24165
24166 Clause : Node_Id;
24167
24168 -- Start of processing for Normalize_Clauses
24169
24170 begin
24171 Clause := First (Clauses);
24172 while Present (Clause) loop
24173 Normalize_Outputs (Clause);
24174 Next (Clause);
24175 end loop;
24176
24177 Clause := First (Clauses);
24178 while Present (Clause) loop
24179 Normalize_Inputs (Clause);
24180 Next (Clause);
24181 end loop;
24182 end Normalize_Clauses;
24183
24184 --------------------------
24185 -- Report_Extra_Clauses --
24186 --------------------------
24187
24188 procedure Report_Extra_Clauses is
24189 Clause : Node_Id;
24190
24191 begin
24192 -- Do not perform this check in an instance because it was already
24193 -- performed successfully in the generic template.
24194
24195 if Is_Generic_Instance (Spec_Id) then
24196 null;
24197
24198 elsif Present (Refinements) then
24199 Clause := First (Refinements);
24200 while Present (Clause) loop
24201
24202 -- Do not complain about a null input refinement, since a null
24203 -- input legitimately matches anything.
24204
24205 if Nkind (Clause) = N_Component_Association
24206 and then Nkind (Expression (Clause)) = N_Null
24207 then
24208 null;
24209
24210 else
24211 SPARK_Msg_N
24212 ("unmatched or extra clause in dependence refinement",
24213 Clause);
24214 end if;
24215
24216 Next (Clause);
24217 end loop;
24218 end if;
24219 end Report_Extra_Clauses;
24220
24221 -- Local variables
24222
24223 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24224 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
24225 Errors : constant Nat := Serious_Errors_Detected;
24226 Clause : Node_Id;
24227 Deps : Node_Id;
24228 Dummy : Boolean;
24229 Refs : Node_Id;
24230
24231 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
24232
24233 begin
24234 -- Do not analyze the pragma multiple times
24235
24236 if Is_Analyzed_Pragma (N) then
24237 return;
24238 end if;
24239
24240 Spec_Id := Unique_Defining_Entity (Body_Decl);
24241
24242 -- Use the anonymous object as the proper spec when Refined_Depends
24243 -- applies to the body of a single task type. The object carries the
24244 -- proper Chars as well as all non-refined versions of pragmas.
24245
24246 if Is_Single_Concurrent_Type (Spec_Id) then
24247 Spec_Id := Anonymous_Object (Spec_Id);
24248 end if;
24249
24250 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
24251
24252 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
24253 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
24254
24255 if No (Depends) then
24256 SPARK_Msg_NE
24257 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
24258 & "& lacks aspect or pragma Depends"), N, Spec_Id);
24259 goto Leave;
24260 end if;
24261
24262 Deps := Expression (Get_Argument (Depends, Spec_Id));
24263
24264 -- A null dependency relation renders the refinement useless because it
24265 -- cannot possibly mention abstract states with visible refinement. Note
24266 -- that the inverse is not true as states may be refined to null
24267 -- (SPARK RM 7.2.5(2)).
24268
24269 if Nkind (Deps) = N_Null then
24270 SPARK_Msg_NE
24271 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
24272 & "depend on abstract state with visible refinement"), N, Spec_Id);
24273 goto Leave;
24274 end if;
24275
24276 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
24277 -- This ensures that the categorization of all refined dependency items
24278 -- is consistent with their role.
24279
24280 Analyze_Depends_In_Decl_Part (N);
24281
24282 -- Do not match dependencies against refinements if Refined_Depends is
24283 -- illegal to avoid emitting misleading error.
24284
24285 if Serious_Errors_Detected = Errors then
24286
24287 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
24288 -- the inputs and outputs of the subprogram spec and body to verify
24289 -- the use of states with visible refinement and their constituents.
24290
24291 if No (Get_Pragma (Spec_Id, Pragma_Global))
24292 or else No (Get_Pragma (Body_Id, Pragma_Refined_Global))
24293 then
24294 Collect_Subprogram_Inputs_Outputs
24295 (Subp_Id => Spec_Id,
24296 Synthesize => True,
24297 Subp_Inputs => Spec_Inputs,
24298 Subp_Outputs => Spec_Outputs,
24299 Global_Seen => Dummy);
24300
24301 Collect_Subprogram_Inputs_Outputs
24302 (Subp_Id => Body_Id,
24303 Synthesize => True,
24304 Subp_Inputs => Body_Inputs,
24305 Subp_Outputs => Body_Outputs,
24306 Global_Seen => Dummy);
24307
24308 -- For an output state with a visible refinement, ensure that all
24309 -- constituents appear as outputs in the dependency refinement.
24310
24311 Check_Output_States;
24312 end if;
24313
24314 -- Matching is disabled in ASIS because clauses are not normalized as
24315 -- this is a tree altering activity similar to expansion.
24316
24317 if ASIS_Mode then
24318 goto Leave;
24319 end if;
24320
24321 -- Multiple dependency clauses appear as component associations of an
24322 -- aggregate. Note that the clauses are copied because the algorithm
24323 -- modifies them and this should not be visible in Depends.
24324
24325 pragma Assert (Nkind (Deps) = N_Aggregate);
24326 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
24327 Normalize_Clauses (Dependencies);
24328
24329 Refs := Expression (Get_Argument (N, Spec_Id));
24330
24331 if Nkind (Refs) = N_Null then
24332 Refinements := No_List;
24333
24334 -- Multiple dependency clauses appear as component associations of an
24335 -- aggregate. Note that the clauses are copied because the algorithm
24336 -- modifies them and this should not be visible in Refined_Depends.
24337
24338 else pragma Assert (Nkind (Refs) = N_Aggregate);
24339 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
24340 Normalize_Clauses (Refinements);
24341 end if;
24342
24343 -- At this point the clauses of pragmas Depends and Refined_Depends
24344 -- have been normalized into simple dependencies between one output
24345 -- and one input. Examine all clauses of pragma Depends looking for
24346 -- matching clauses in pragma Refined_Depends.
24347
24348 Clause := First (Dependencies);
24349 while Present (Clause) loop
24350 Check_Dependency_Clause (Clause);
24351 Next (Clause);
24352 end loop;
24353
24354 if Serious_Errors_Detected = Errors then
24355 Report_Extra_Clauses;
24356 end if;
24357 end if;
24358
24359 <<Leave>>
24360 Set_Is_Analyzed_Pragma (N);
24361 end Analyze_Refined_Depends_In_Decl_Part;
24362
24363 -----------------------------------------
24364 -- Analyze_Refined_Global_In_Decl_Part --
24365 -----------------------------------------
24366
24367 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
24368 Global : Node_Id;
24369 -- The corresponding Global pragma
24370
24371 Has_In_State : Boolean := False;
24372 Has_In_Out_State : Boolean := False;
24373 Has_Out_State : Boolean := False;
24374 Has_Proof_In_State : Boolean := False;
24375 -- These flags are set when the corresponding Global pragma has a state
24376 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
24377 -- refinement.
24378
24379 Has_Null_State : Boolean := False;
24380 -- This flag is set when the corresponding Global pragma has at least
24381 -- one state with a null refinement.
24382
24383 In_Constits : Elist_Id := No_Elist;
24384 In_Out_Constits : Elist_Id := No_Elist;
24385 Out_Constits : Elist_Id := No_Elist;
24386 Proof_In_Constits : Elist_Id := No_Elist;
24387 -- These lists contain the entities of all Input, In_Out, Output and
24388 -- Proof_In constituents that appear in Refined_Global and participate
24389 -- in state refinement.
24390
24391 In_Items : Elist_Id := No_Elist;
24392 In_Out_Items : Elist_Id := No_Elist;
24393 Out_Items : Elist_Id := No_Elist;
24394 Proof_In_Items : Elist_Id := No_Elist;
24395 -- These list contain the entities of all Input, In_Out, Output and
24396 -- Proof_In items defined in the corresponding Global pragma.
24397
24398 Spec_Id : Entity_Id;
24399 -- The entity of the subprogram subject to pragma Refined_Global
24400
24401 States : Elist_Id := No_Elist;
24402 -- A list of all states with visible refinement found in pragma Global
24403
24404 procedure Check_In_Out_States;
24405 -- Determine whether the corresponding Global pragma mentions In_Out
24406 -- states with visible refinement and if so, ensure that one of the
24407 -- following completions apply to the constituents of the state:
24408 -- 1) there is at least one constituent of mode In_Out
24409 -- 2) there is at least one Input and one Output constituent
24410 -- 3) not all constituents are present and one of them is of mode
24411 -- Output.
24412 -- This routine may remove elements from In_Constits, In_Out_Constits,
24413 -- Out_Constits and Proof_In_Constits.
24414
24415 procedure Check_Input_States;
24416 -- Determine whether the corresponding Global pragma mentions Input
24417 -- states with visible refinement and if so, ensure that at least one of
24418 -- its constituents appears as an Input item in Refined_Global.
24419 -- This routine may remove elements from In_Constits, In_Out_Constits,
24420 -- Out_Constits and Proof_In_Constits.
24421
24422 procedure Check_Output_States;
24423 -- Determine whether the corresponding Global pragma mentions Output
24424 -- states with visible refinement and if so, ensure that all of its
24425 -- constituents appear as Output items in Refined_Global.
24426 -- This routine may remove elements from In_Constits, In_Out_Constits,
24427 -- Out_Constits and Proof_In_Constits.
24428
24429 procedure Check_Proof_In_States;
24430 -- Determine whether the corresponding Global pragma mentions Proof_In
24431 -- states with visible refinement and if so, ensure that at least one of
24432 -- its constituents appears as a Proof_In item in Refined_Global.
24433 -- This routine may remove elements from In_Constits, In_Out_Constits,
24434 -- Out_Constits and Proof_In_Constits.
24435
24436 procedure Check_Refined_Global_List
24437 (List : Node_Id;
24438 Global_Mode : Name_Id := Name_Input);
24439 -- Verify the legality of a single global list declaration. Global_Mode
24440 -- denotes the current mode in effect.
24441
24442 procedure Collect_Global_Items
24443 (List : Node_Id;
24444 Mode : Name_Id := Name_Input);
24445 -- Gather all input, in out, output and Proof_In items from node List
24446 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
24447 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
24448 -- and Has_Proof_In_State are set when there is at least one abstract
24449 -- state with visible refinement available in the corresponding mode.
24450 -- Flag Has_Null_State is set when at least state has a null refinement.
24451 -- Mode enotes the current global mode in effect.
24452
24453 function Present_Then_Remove
24454 (List : Elist_Id;
24455 Item : Entity_Id) return Boolean;
24456 -- Search List for a particular entity Item. If Item has been found,
24457 -- remove it from List. This routine is used to strip lists In_Constits,
24458 -- In_Out_Constits and Out_Constits of valid constituents.
24459
24460 procedure Report_Extra_Constituents;
24461 -- Emit an error for each constituent found in lists In_Constits,
24462 -- In_Out_Constits and Out_Constits.
24463
24464 -------------------------
24465 -- Check_In_Out_States --
24466 -------------------------
24467
24468 procedure Check_In_Out_States is
24469 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24470 -- Determine whether one of the following coverage scenarios is in
24471 -- effect:
24472 -- 1) there is at least one constituent of mode In_Out or Output
24473 -- 2) there is at least one pair of constituents with modes Input
24474 -- and Output, or Proof_In and Output.
24475 -- 3) there is at least one constituent of mode Output and not all
24476 -- constituents are present.
24477 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
24478
24479 -----------------------------
24480 -- Check_Constituent_Usage --
24481 -----------------------------
24482
24483 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24484 Constits : constant Elist_Id :=
24485 Refinement_Constituents (State_Id);
24486 Constit_Elmt : Elmt_Id;
24487 Constit_Id : Entity_Id;
24488 Has_Missing : Boolean := False;
24489 In_Out_Seen : Boolean := False;
24490 Input_Seen : Boolean := False;
24491 Output_Seen : Boolean := False;
24492 Proof_In_Seen : Boolean := False;
24493
24494 begin
24495 -- Process all the constituents of the state and note their modes
24496 -- within the global refinement.
24497
24498 if Present (Constits) then
24499 Constit_Elmt := First_Elmt (Constits);
24500 while Present (Constit_Elmt) loop
24501 Constit_Id := Node (Constit_Elmt);
24502
24503 if Present_Then_Remove (In_Constits, Constit_Id) then
24504 Input_Seen := True;
24505
24506 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
24507 In_Out_Seen := True;
24508
24509 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
24510 Output_Seen := True;
24511
24512 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
24513 then
24514 Proof_In_Seen := True;
24515
24516 else
24517 Has_Missing := True;
24518 end if;
24519
24520 Next_Elmt (Constit_Elmt);
24521 end loop;
24522 end if;
24523
24524 -- An In_Out constituent is a valid completion
24525
24526 if In_Out_Seen then
24527 null;
24528
24529 -- A pair of one Input/Proof_In and one Output constituent is a
24530 -- valid completion.
24531
24532 elsif (Input_Seen or Proof_In_Seen) and Output_Seen then
24533 null;
24534
24535 elsif Output_Seen then
24536
24537 -- A single Output constituent is a valid completion only when
24538 -- some of the other constituents are missing.
24539
24540 if Has_Missing then
24541 null;
24542
24543 -- Otherwise all constituents are of mode Output
24544
24545 else
24546 SPARK_Msg_NE
24547 ("global refinement of state & must include at least one "
24548 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
24549 N, State_Id);
24550 end if;
24551
24552 -- The state lacks a completion
24553
24554 elsif not Input_Seen
24555 and not In_Out_Seen
24556 and not Output_Seen
24557 and not Proof_In_Seen
24558 then
24559 SPARK_Msg_NE
24560 ("missing global refinement of state &", N, State_Id);
24561
24562 -- Otherwise the state has a malformed completion where at least
24563 -- one of the constituents has a different mode.
24564
24565 else
24566 SPARK_Msg_NE
24567 ("global refinement of state & redefines the mode of its "
24568 & "constituents", N, State_Id);
24569 end if;
24570 end Check_Constituent_Usage;
24571
24572 -- Local variables
24573
24574 Item_Elmt : Elmt_Id;
24575 Item_Id : Entity_Id;
24576
24577 -- Start of processing for Check_In_Out_States
24578
24579 begin
24580 -- Do not perform this check in an instance because it was already
24581 -- performed successfully in the generic template.
24582
24583 if Is_Generic_Instance (Spec_Id) then
24584 null;
24585
24586 -- Inspect the In_Out items of the corresponding Global pragma
24587 -- looking for a state with a visible refinement.
24588
24589 elsif Has_In_Out_State and then Present (In_Out_Items) then
24590 Item_Elmt := First_Elmt (In_Out_Items);
24591 while Present (Item_Elmt) loop
24592 Item_Id := Node (Item_Elmt);
24593
24594 -- Ensure that one of the three coverage variants is satisfied
24595
24596 if Ekind (Item_Id) = E_Abstract_State
24597 and then Has_Non_Null_Visible_Refinement (Item_Id)
24598 then
24599 Check_Constituent_Usage (Item_Id);
24600 end if;
24601
24602 Next_Elmt (Item_Elmt);
24603 end loop;
24604 end if;
24605 end Check_In_Out_States;
24606
24607 ------------------------
24608 -- Check_Input_States --
24609 ------------------------
24610
24611 procedure Check_Input_States is
24612 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24613 -- Determine whether at least one constituent of state State_Id with
24614 -- visible refinement is used and has mode Input. Ensure that the
24615 -- remaining constituents do not have In_Out or Output modes. Emit an
24616 -- error if this is not the case (SPARK RM 7.2.4(5)).
24617
24618 -----------------------------
24619 -- Check_Constituent_Usage --
24620 -----------------------------
24621
24622 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24623 Constits : constant Elist_Id :=
24624 Refinement_Constituents (State_Id);
24625 Constit_Elmt : Elmt_Id;
24626 Constit_Id : Entity_Id;
24627 In_Seen : Boolean := False;
24628
24629 begin
24630 if Present (Constits) then
24631 Constit_Elmt := First_Elmt (Constits);
24632 while Present (Constit_Elmt) loop
24633 Constit_Id := Node (Constit_Elmt);
24634
24635 -- At least one of the constituents appears as an Input
24636
24637 if Present_Then_Remove (In_Constits, Constit_Id) then
24638 In_Seen := True;
24639
24640 -- A Proof_In constituent can refine an Input state as long
24641 -- as there is at least one Input constituent present.
24642
24643 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id)
24644 then
24645 null;
24646
24647 -- The constituent appears in the global refinement, but has
24648 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
24649
24650 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
24651 or else Present_Then_Remove (Out_Constits, Constit_Id)
24652 then
24653 Error_Msg_Name_1 := Chars (State_Id);
24654 SPARK_Msg_NE
24655 ("constituent & of state % must have mode `Input` in "
24656 & "global refinement", N, Constit_Id);
24657 end if;
24658
24659 Next_Elmt (Constit_Elmt);
24660 end loop;
24661 end if;
24662
24663 -- Not one of the constituents appeared as Input
24664
24665 if not In_Seen then
24666 SPARK_Msg_NE
24667 ("global refinement of state & must include at least one "
24668 & "constituent of mode `Input`", N, State_Id);
24669 end if;
24670 end Check_Constituent_Usage;
24671
24672 -- Local variables
24673
24674 Item_Elmt : Elmt_Id;
24675 Item_Id : Entity_Id;
24676
24677 -- Start of processing for Check_Input_States
24678
24679 begin
24680 -- Do not perform this check in an instance because it was already
24681 -- performed successfully in the generic template.
24682
24683 if Is_Generic_Instance (Spec_Id) then
24684 null;
24685
24686 -- Inspect the Input items of the corresponding Global pragma looking
24687 -- for a state with a visible refinement.
24688
24689 elsif Has_In_State and then Present (In_Items) then
24690 Item_Elmt := First_Elmt (In_Items);
24691 while Present (Item_Elmt) loop
24692 Item_Id := Node (Item_Elmt);
24693
24694 -- Ensure that at least one of the constituents is utilized and
24695 -- is of mode Input.
24696
24697 if Ekind (Item_Id) = E_Abstract_State
24698 and then Has_Non_Null_Visible_Refinement (Item_Id)
24699 then
24700 Check_Constituent_Usage (Item_Id);
24701 end if;
24702
24703 Next_Elmt (Item_Elmt);
24704 end loop;
24705 end if;
24706 end Check_Input_States;
24707
24708 -------------------------
24709 -- Check_Output_States --
24710 -------------------------
24711
24712 procedure Check_Output_States is
24713 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24714 -- Determine whether all constituents of state State_Id with visible
24715 -- refinement are used and have mode Output. Emit an error if this is
24716 -- not the case (SPARK RM 7.2.4(5)).
24717
24718 -----------------------------
24719 -- Check_Constituent_Usage --
24720 -----------------------------
24721
24722 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24723 Constits : constant Elist_Id :=
24724 Refinement_Constituents (State_Id);
24725 Constit_Elmt : Elmt_Id;
24726 Constit_Id : Entity_Id;
24727 Posted : Boolean := False;
24728
24729 begin
24730 if Present (Constits) then
24731 Constit_Elmt := First_Elmt (Constits);
24732 while Present (Constit_Elmt) loop
24733 Constit_Id := Node (Constit_Elmt);
24734
24735 if Present_Then_Remove (Out_Constits, Constit_Id) then
24736 null;
24737
24738 -- The constituent appears in the global refinement, but has
24739 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
24740
24741 elsif Present_Then_Remove (In_Constits, Constit_Id)
24742 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
24743 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
24744 then
24745 Error_Msg_Name_1 := Chars (State_Id);
24746 SPARK_Msg_NE
24747 ("constituent & of state % must have mode `Output` in "
24748 & "global refinement", N, Constit_Id);
24749
24750 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24751
24752 else
24753 if not Posted then
24754 Posted := True;
24755 SPARK_Msg_NE
24756 ("`Output` state & must be replaced by all its "
24757 & "constituents in global refinement", N, State_Id);
24758 end if;
24759
24760 SPARK_Msg_NE
24761 ("\constituent & is missing in output list",
24762 N, Constit_Id);
24763 end if;
24764
24765 Next_Elmt (Constit_Elmt);
24766 end loop;
24767 end if;
24768 end Check_Constituent_Usage;
24769
24770 -- Local variables
24771
24772 Item_Elmt : Elmt_Id;
24773 Item_Id : Entity_Id;
24774
24775 -- Start of processing for Check_Output_States
24776
24777 begin
24778 -- Do not perform this check in an instance because it was already
24779 -- performed successfully in the generic template.
24780
24781 if Is_Generic_Instance (Spec_Id) then
24782 null;
24783
24784 -- Inspect the Output items of the corresponding Global pragma
24785 -- looking for a state with a visible refinement.
24786
24787 elsif Has_Out_State and then Present (Out_Items) then
24788 Item_Elmt := First_Elmt (Out_Items);
24789 while Present (Item_Elmt) loop
24790 Item_Id := Node (Item_Elmt);
24791
24792 -- Ensure that all of the constituents are utilized and they
24793 -- have mode Output.
24794
24795 if Ekind (Item_Id) = E_Abstract_State
24796 and then Has_Non_Null_Visible_Refinement (Item_Id)
24797 then
24798 Check_Constituent_Usage (Item_Id);
24799 end if;
24800
24801 Next_Elmt (Item_Elmt);
24802 end loop;
24803 end if;
24804 end Check_Output_States;
24805
24806 ---------------------------
24807 -- Check_Proof_In_States --
24808 ---------------------------
24809
24810 procedure Check_Proof_In_States is
24811 procedure Check_Constituent_Usage (State_Id : Entity_Id);
24812 -- Determine whether at least one constituent of state State_Id with
24813 -- visible refinement is used and has mode Proof_In. Ensure that the
24814 -- remaining constituents do not have Input, In_Out or Output modes.
24815 -- Emit an error of this is not the case (SPARK RM 7.2.4(5)).
24816
24817 -----------------------------
24818 -- Check_Constituent_Usage --
24819 -----------------------------
24820
24821 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
24822 Constits : constant Elist_Id :=
24823 Refinement_Constituents (State_Id);
24824 Constit_Elmt : Elmt_Id;
24825 Constit_Id : Entity_Id;
24826 Proof_In_Seen : Boolean := False;
24827
24828 begin
24829 if Present (Constits) then
24830 Constit_Elmt := First_Elmt (Constits);
24831 while Present (Constit_Elmt) loop
24832 Constit_Id := Node (Constit_Elmt);
24833
24834 -- At least one of the constituents appears as Proof_In
24835
24836 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
24837 Proof_In_Seen := True;
24838
24839 -- The constituent appears in the global refinement, but has
24840 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
24841
24842 elsif Present_Then_Remove (In_Constits, Constit_Id)
24843 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
24844 or else Present_Then_Remove (Out_Constits, Constit_Id)
24845 then
24846 Error_Msg_Name_1 := Chars (State_Id);
24847 SPARK_Msg_NE
24848 ("constituent & of state % must have mode `Proof_In` "
24849 & "in global refinement", N, Constit_Id);
24850 end if;
24851
24852 Next_Elmt (Constit_Elmt);
24853 end loop;
24854 end if;
24855
24856 -- Not one of the constituents appeared as Proof_In
24857
24858 if not Proof_In_Seen then
24859 SPARK_Msg_NE
24860 ("global refinement of state & must include at least one "
24861 & "constituent of mode `Proof_In`", N, State_Id);
24862 end if;
24863 end Check_Constituent_Usage;
24864
24865 -- Local variables
24866
24867 Item_Elmt : Elmt_Id;
24868 Item_Id : Entity_Id;
24869
24870 -- Start of processing for Check_Proof_In_States
24871
24872 begin
24873 -- Do not perform this check in an instance because it was already
24874 -- performed successfully in the generic template.
24875
24876 if Is_Generic_Instance (Spec_Id) then
24877 null;
24878
24879 -- Inspect the Proof_In items of the corresponding Global pragma
24880 -- looking for a state with a visible refinement.
24881
24882 elsif Has_Proof_In_State and then Present (Proof_In_Items) then
24883 Item_Elmt := First_Elmt (Proof_In_Items);
24884 while Present (Item_Elmt) loop
24885 Item_Id := Node (Item_Elmt);
24886
24887 -- Ensure that at least one of the constituents is utilized and
24888 -- is of mode Proof_In
24889
24890 if Ekind (Item_Id) = E_Abstract_State
24891 and then Has_Non_Null_Visible_Refinement (Item_Id)
24892 then
24893 Check_Constituent_Usage (Item_Id);
24894 end if;
24895
24896 Next_Elmt (Item_Elmt);
24897 end loop;
24898 end if;
24899 end Check_Proof_In_States;
24900
24901 -------------------------------
24902 -- Check_Refined_Global_List --
24903 -------------------------------
24904
24905 procedure Check_Refined_Global_List
24906 (List : Node_Id;
24907 Global_Mode : Name_Id := Name_Input)
24908 is
24909 procedure Check_Refined_Global_Item
24910 (Item : Node_Id;
24911 Global_Mode : Name_Id);
24912 -- Verify the legality of a single global item declaration. Parameter
24913 -- Global_Mode denotes the current mode in effect.
24914
24915 -------------------------------
24916 -- Check_Refined_Global_Item --
24917 -------------------------------
24918
24919 procedure Check_Refined_Global_Item
24920 (Item : Node_Id;
24921 Global_Mode : Name_Id)
24922 is
24923 Item_Id : constant Entity_Id := Entity_Of (Item);
24924
24925 procedure Inconsistent_Mode_Error (Expect : Name_Id);
24926 -- Issue a common error message for all mode mismatches. Expect
24927 -- denotes the expected mode.
24928
24929 -----------------------------
24930 -- Inconsistent_Mode_Error --
24931 -----------------------------
24932
24933 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
24934 begin
24935 SPARK_Msg_NE
24936 ("global item & has inconsistent modes", Item, Item_Id);
24937
24938 Error_Msg_Name_1 := Global_Mode;
24939 Error_Msg_Name_2 := Expect;
24940 SPARK_Msg_N ("\expected mode %, found mode %", Item);
24941 end Inconsistent_Mode_Error;
24942
24943 -- Start of processing for Check_Refined_Global_Item
24944
24945 begin
24946 -- When the state or object acts as a constituent of another
24947 -- state with a visible refinement, collect it for the state
24948 -- completeness checks performed later on. Note that the item
24949 -- acts as a constituent only when the encapsulating state is
24950 -- present in pragma Global.
24951
24952 if Ekind_In (Item_Id, E_Abstract_State, E_Constant, E_Variable)
24953 and then Present (Encapsulating_State (Item_Id))
24954 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
24955 and then Contains (States, Encapsulating_State (Item_Id))
24956 then
24957 if Global_Mode = Name_Input then
24958 Append_New_Elmt (Item_Id, In_Constits);
24959
24960 elsif Global_Mode = Name_In_Out then
24961 Append_New_Elmt (Item_Id, In_Out_Constits);
24962
24963 elsif Global_Mode = Name_Output then
24964 Append_New_Elmt (Item_Id, Out_Constits);
24965
24966 elsif Global_Mode = Name_Proof_In then
24967 Append_New_Elmt (Item_Id, Proof_In_Constits);
24968 end if;
24969
24970 -- When not a constituent, ensure that both occurrences of the
24971 -- item in pragmas Global and Refined_Global match.
24972
24973 elsif Contains (In_Items, Item_Id) then
24974 if Global_Mode /= Name_Input then
24975 Inconsistent_Mode_Error (Name_Input);
24976 end if;
24977
24978 elsif Contains (In_Out_Items, Item_Id) then
24979 if Global_Mode /= Name_In_Out then
24980 Inconsistent_Mode_Error (Name_In_Out);
24981 end if;
24982
24983 elsif Contains (Out_Items, Item_Id) then
24984 if Global_Mode /= Name_Output then
24985 Inconsistent_Mode_Error (Name_Output);
24986 end if;
24987
24988 elsif Contains (Proof_In_Items, Item_Id) then
24989 null;
24990
24991 -- The item does not appear in the corresponding Global pragma,
24992 -- it must be an extra (SPARK RM 7.2.4(3)).
24993
24994 else
24995 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
24996 end if;
24997 end Check_Refined_Global_Item;
24998
24999 -- Local variables
25000
25001 Item : Node_Id;
25002
25003 -- Start of processing for Check_Refined_Global_List
25004
25005 begin
25006 -- Do not perform this check in an instance because it was already
25007 -- performed successfully in the generic template.
25008
25009 if Is_Generic_Instance (Spec_Id) then
25010 null;
25011
25012 elsif Nkind (List) = N_Null then
25013 null;
25014
25015 -- Single global item declaration
25016
25017 elsif Nkind_In (List, N_Expanded_Name,
25018 N_Identifier,
25019 N_Selected_Component)
25020 then
25021 Check_Refined_Global_Item (List, Global_Mode);
25022
25023 -- Simple global list or moded global list declaration
25024
25025 elsif Nkind (List) = N_Aggregate then
25026
25027 -- The declaration of a simple global list appear as a collection
25028 -- of expressions.
25029
25030 if Present (Expressions (List)) then
25031 Item := First (Expressions (List));
25032 while Present (Item) loop
25033 Check_Refined_Global_Item (Item, Global_Mode);
25034 Next (Item);
25035 end loop;
25036
25037 -- The declaration of a moded global list appears as a collection
25038 -- of component associations where individual choices denote
25039 -- modes.
25040
25041 elsif Present (Component_Associations (List)) then
25042 Item := First (Component_Associations (List));
25043 while Present (Item) loop
25044 Check_Refined_Global_List
25045 (List => Expression (Item),
25046 Global_Mode => Chars (First (Choices (Item))));
25047
25048 Next (Item);
25049 end loop;
25050
25051 -- Invalid tree
25052
25053 else
25054 raise Program_Error;
25055 end if;
25056
25057 -- Invalid list
25058
25059 else
25060 raise Program_Error;
25061 end if;
25062 end Check_Refined_Global_List;
25063
25064 --------------------------
25065 -- Collect_Global_Items --
25066 --------------------------
25067
25068 procedure Collect_Global_Items
25069 (List : Node_Id;
25070 Mode : Name_Id := Name_Input)
25071 is
25072 procedure Collect_Global_Item
25073 (Item : Node_Id;
25074 Item_Mode : Name_Id);
25075 -- Add a single item to the appropriate list. Item_Mode denotes the
25076 -- current mode in effect.
25077
25078 -------------------------
25079 -- Collect_Global_Item --
25080 -------------------------
25081
25082 procedure Collect_Global_Item
25083 (Item : Node_Id;
25084 Item_Mode : Name_Id)
25085 is
25086 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
25087 -- The above handles abstract views of variables and states built
25088 -- for limited with clauses.
25089
25090 begin
25091 -- Signal that the global list contains at least one abstract
25092 -- state with a visible refinement. Note that the refinement may
25093 -- be null in which case there are no constituents.
25094
25095 if Ekind (Item_Id) = E_Abstract_State then
25096 if Has_Null_Visible_Refinement (Item_Id) then
25097 Has_Null_State := True;
25098
25099 elsif Has_Non_Null_Visible_Refinement (Item_Id) then
25100 Append_New_Elmt (Item_Id, States);
25101
25102 if Item_Mode = Name_Input then
25103 Has_In_State := True;
25104 elsif Item_Mode = Name_In_Out then
25105 Has_In_Out_State := True;
25106 elsif Item_Mode = Name_Output then
25107 Has_Out_State := True;
25108 elsif Item_Mode = Name_Proof_In then
25109 Has_Proof_In_State := True;
25110 end if;
25111 end if;
25112 end if;
25113
25114 -- Add the item to the proper list
25115
25116 if Item_Mode = Name_Input then
25117 Append_New_Elmt (Item_Id, In_Items);
25118 elsif Item_Mode = Name_In_Out then
25119 Append_New_Elmt (Item_Id, In_Out_Items);
25120 elsif Item_Mode = Name_Output then
25121 Append_New_Elmt (Item_Id, Out_Items);
25122 elsif Item_Mode = Name_Proof_In then
25123 Append_New_Elmt (Item_Id, Proof_In_Items);
25124 end if;
25125 end Collect_Global_Item;
25126
25127 -- Local variables
25128
25129 Item : Node_Id;
25130
25131 -- Start of processing for Collect_Global_Items
25132
25133 begin
25134 if Nkind (List) = N_Null then
25135 null;
25136
25137 -- Single global item declaration
25138
25139 elsif Nkind_In (List, N_Expanded_Name,
25140 N_Identifier,
25141 N_Selected_Component)
25142 then
25143 Collect_Global_Item (List, Mode);
25144
25145 -- Single global list or moded global list declaration
25146
25147 elsif Nkind (List) = N_Aggregate then
25148
25149 -- The declaration of a simple global list appear as a collection
25150 -- of expressions.
25151
25152 if Present (Expressions (List)) then
25153 Item := First (Expressions (List));
25154 while Present (Item) loop
25155 Collect_Global_Item (Item, Mode);
25156 Next (Item);
25157 end loop;
25158
25159 -- The declaration of a moded global list appears as a collection
25160 -- of component associations where individual choices denote mode.
25161
25162 elsif Present (Component_Associations (List)) then
25163 Item := First (Component_Associations (List));
25164 while Present (Item) loop
25165 Collect_Global_Items
25166 (List => Expression (Item),
25167 Mode => Chars (First (Choices (Item))));
25168
25169 Next (Item);
25170 end loop;
25171
25172 -- Invalid tree
25173
25174 else
25175 raise Program_Error;
25176 end if;
25177
25178 -- To accomodate partial decoration of disabled SPARK features, this
25179 -- routine may be called with illegal input. If this is the case, do
25180 -- not raise Program_Error.
25181
25182 else
25183 null;
25184 end if;
25185 end Collect_Global_Items;
25186
25187 -------------------------
25188 -- Present_Then_Remove --
25189 -------------------------
25190
25191 function Present_Then_Remove
25192 (List : Elist_Id;
25193 Item : Entity_Id) return Boolean
25194 is
25195 Elmt : Elmt_Id;
25196
25197 begin
25198 if Present (List) then
25199 Elmt := First_Elmt (List);
25200 while Present (Elmt) loop
25201 if Node (Elmt) = Item then
25202 Remove_Elmt (List, Elmt);
25203 return True;
25204 end if;
25205
25206 Next_Elmt (Elmt);
25207 end loop;
25208 end if;
25209
25210 return False;
25211 end Present_Then_Remove;
25212
25213 -------------------------------
25214 -- Report_Extra_Constituents --
25215 -------------------------------
25216
25217 procedure Report_Extra_Constituents is
25218 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
25219 -- Emit an error for every element of List
25220
25221 ---------------------------------------
25222 -- Report_Extra_Constituents_In_List --
25223 ---------------------------------------
25224
25225 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
25226 Constit_Elmt : Elmt_Id;
25227
25228 begin
25229 if Present (List) then
25230 Constit_Elmt := First_Elmt (List);
25231 while Present (Constit_Elmt) loop
25232 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
25233 Next_Elmt (Constit_Elmt);
25234 end loop;
25235 end if;
25236 end Report_Extra_Constituents_In_List;
25237
25238 -- Start of processing for Report_Extra_Constituents
25239
25240 begin
25241 -- Do not perform this check in an instance because it was already
25242 -- performed successfully in the generic template.
25243
25244 if Is_Generic_Instance (Spec_Id) then
25245 null;
25246
25247 else
25248 Report_Extra_Constituents_In_List (In_Constits);
25249 Report_Extra_Constituents_In_List (In_Out_Constits);
25250 Report_Extra_Constituents_In_List (Out_Constits);
25251 Report_Extra_Constituents_In_List (Proof_In_Constits);
25252 end if;
25253 end Report_Extra_Constituents;
25254
25255 -- Local variables
25256
25257 Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
25258 Errors : constant Nat := Serious_Errors_Detected;
25259 Items : Node_Id;
25260
25261 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
25262
25263 begin
25264 -- Do not analyze the pragma multiple times
25265
25266 if Is_Analyzed_Pragma (N) then
25267 return;
25268 end if;
25269
25270 Spec_Id := Unique_Defining_Entity (Body_Decl);
25271
25272 -- Use the anonymous object as the proper spec when Refined_Global
25273 -- applies to the body of a single task type. The object carries the
25274 -- proper Chars as well as all non-refined versions of pragmas.
25275
25276 if Is_Single_Concurrent_Type (Spec_Id) then
25277 Spec_Id := Anonymous_Object (Spec_Id);
25278 end if;
25279
25280 Global := Get_Pragma (Spec_Id, Pragma_Global);
25281 Items := Expression (Get_Argument (N, Spec_Id));
25282
25283 -- The subprogram declaration lacks pragma Global. This renders
25284 -- Refined_Global useless as there is nothing to refine.
25285
25286 if No (Global) then
25287 SPARK_Msg_NE
25288 (Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram "
25289 & "& lacks aspect or pragma Global"), N, Spec_Id);
25290 goto Leave;
25291 end if;
25292
25293 -- Extract all relevant items from the corresponding Global pragma
25294
25295 Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id)));
25296
25297 -- Package and subprogram bodies are instantiated individually in
25298 -- a separate compiler pass. Due to this mode of instantiation, the
25299 -- refinement of a state may no longer be visible when a subprogram
25300 -- body contract is instantiated. Since the generic template is legal,
25301 -- do not perform this check in the instance to circumvent this oddity.
25302
25303 if Is_Generic_Instance (Spec_Id) then
25304 null;
25305
25306 -- Non-instance case
25307
25308 else
25309 -- The corresponding Global pragma must mention at least one state
25310 -- witha visible refinement at the point Refined_Global is processed.
25311 -- States with null refinements need Refined_Global pragma
25312 -- (SPARK RM 7.2.4(2)).
25313
25314 if not Has_In_State
25315 and then not Has_In_Out_State
25316 and then not Has_Out_State
25317 and then not Has_Proof_In_State
25318 and then not Has_Null_State
25319 then
25320 SPARK_Msg_NE
25321 (Fix_Msg (Spec_Id, "useless refinement, subprogram & does not "
25322 & "depend on abstract state with visible refinement"),
25323 N, Spec_Id);
25324 goto Leave;
25325
25326 -- The global refinement of inputs and outputs cannot be null when
25327 -- the corresponding Global pragma contains at least one item except
25328 -- in the case where we have states with null refinements.
25329
25330 elsif Nkind (Items) = N_Null
25331 and then
25332 (Present (In_Items)
25333 or else Present (In_Out_Items)
25334 or else Present (Out_Items)
25335 or else Present (Proof_In_Items))
25336 and then not Has_Null_State
25337 then
25338 SPARK_Msg_NE
25339 (Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has "
25340 & "global items"), N, Spec_Id);
25341 goto Leave;
25342 end if;
25343 end if;
25344
25345 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
25346 -- This ensures that the categorization of all refined global items is
25347 -- consistent with their role.
25348
25349 Analyze_Global_In_Decl_Part (N);
25350
25351 -- Perform all refinement checks with respect to completeness and mode
25352 -- matching.
25353
25354 if Serious_Errors_Detected = Errors then
25355 Check_Refined_Global_List (Items);
25356 end if;
25357
25358 -- For Input states with visible refinement, at least one constituent
25359 -- must be used as an Input in the global refinement.
25360
25361 if Serious_Errors_Detected = Errors then
25362 Check_Input_States;
25363 end if;
25364
25365 -- Verify all possible completion variants for In_Out states with
25366 -- visible refinement.
25367
25368 if Serious_Errors_Detected = Errors then
25369 Check_In_Out_States;
25370 end if;
25371
25372 -- For Output states with visible refinement, all constituents must be
25373 -- used as Outputs in the global refinement.
25374
25375 if Serious_Errors_Detected = Errors then
25376 Check_Output_States;
25377 end if;
25378
25379 -- For Proof_In states with visible refinement, at least one constituent
25380 -- must be used as Proof_In in the global refinement.
25381
25382 if Serious_Errors_Detected = Errors then
25383 Check_Proof_In_States;
25384 end if;
25385
25386 -- Emit errors for all constituents that belong to other states with
25387 -- visible refinement that do not appear in Global.
25388
25389 if Serious_Errors_Detected = Errors then
25390 Report_Extra_Constituents;
25391 end if;
25392
25393 <<Leave>>
25394 Set_Is_Analyzed_Pragma (N);
25395 end Analyze_Refined_Global_In_Decl_Part;
25396
25397 ----------------------------------------
25398 -- Analyze_Refined_State_In_Decl_Part --
25399 ----------------------------------------
25400
25401 procedure Analyze_Refined_State_In_Decl_Part
25402 (N : Node_Id;
25403 Freeze_Id : Entity_Id := Empty)
25404 is
25405 Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N);
25406 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
25407 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
25408
25409 Available_States : Elist_Id := No_Elist;
25410 -- A list of all abstract states defined in the package declaration that
25411 -- are available for refinement. The list is used to report unrefined
25412 -- states.
25413
25414 Body_States : Elist_Id := No_Elist;
25415 -- A list of all hidden states that appear in the body of the related
25416 -- package. The list is used to report unused hidden states.
25417
25418 Constituents_Seen : Elist_Id := No_Elist;
25419 -- A list that contains all constituents processed so far. The list is
25420 -- used to detect multiple uses of the same constituent.
25421
25422 Freeze_Posted : Boolean := False;
25423 -- A flag that controls the output of a freezing-related error (see use
25424 -- below).
25425
25426 Refined_States_Seen : Elist_Id := No_Elist;
25427 -- A list that contains all refined states processed so far. The list is
25428 -- used to detect duplicate refinements.
25429
25430 procedure Analyze_Refinement_Clause (Clause : Node_Id);
25431 -- Perform full analysis of a single refinement clause
25432
25433 procedure Report_Unrefined_States (States : Elist_Id);
25434 -- Emit errors for all unrefined abstract states found in list States
25435
25436 -------------------------------
25437 -- Analyze_Refinement_Clause --
25438 -------------------------------
25439
25440 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
25441 AR_Constit : Entity_Id := Empty;
25442 AW_Constit : Entity_Id := Empty;
25443 ER_Constit : Entity_Id := Empty;
25444 EW_Constit : Entity_Id := Empty;
25445 -- The entities of external constituents that contain one of the
25446 -- following enabled properties: Async_Readers, Async_Writers,
25447 -- Effective_Reads and Effective_Writes.
25448
25449 External_Constit_Seen : Boolean := False;
25450 -- Flag used to mark when at least one external constituent is part
25451 -- of the state refinement.
25452
25453 Non_Null_Seen : Boolean := False;
25454 Null_Seen : Boolean := False;
25455 -- Flags used to detect multiple uses of null in a single clause or a
25456 -- mixture of null and non-null constituents.
25457
25458 Part_Of_Constits : Elist_Id := No_Elist;
25459 -- A list of all candidate constituents subject to indicator Part_Of
25460 -- where the encapsulating state is the current state.
25461
25462 State : Node_Id;
25463 State_Id : Entity_Id;
25464 -- The current state being refined
25465
25466 procedure Analyze_Constituent (Constit : Node_Id);
25467 -- Perform full analysis of a single constituent
25468
25469 procedure Check_External_Property
25470 (Prop_Nam : Name_Id;
25471 Enabled : Boolean;
25472 Constit : Entity_Id);
25473 -- Determine whether a property denoted by name Prop_Nam is present
25474 -- in the refined state. Emit an error if this is not the case. Flag
25475 -- Enabled should be set when the property applies to the refined
25476 -- state. Constit denotes the constituent (if any) which introduces
25477 -- the property in the refinement.
25478
25479 procedure Match_State;
25480 -- Determine whether the state being refined appears in list
25481 -- Available_States. Emit an error when attempting to re-refine the
25482 -- state or when the state is not defined in the package declaration,
25483 -- otherwise remove the state from Available_States.
25484
25485 procedure Report_Unused_Constituents (Constits : Elist_Id);
25486 -- Emit errors for all unused Part_Of constituents in list Constits
25487
25488 -------------------------
25489 -- Analyze_Constituent --
25490 -------------------------
25491
25492 procedure Analyze_Constituent (Constit : Node_Id) is
25493 procedure Match_Constituent (Constit_Id : Entity_Id);
25494 -- Determine whether constituent Constit denoted by its entity
25495 -- Constit_Id appears in Body_States. Emit an error when the
25496 -- constituent is not a valid hidden state of the related package
25497 -- or when it is used more than once. Otherwise remove the
25498 -- constituent from Body_States.
25499
25500 -----------------------
25501 -- Match_Constituent --
25502 -----------------------
25503
25504 procedure Match_Constituent (Constit_Id : Entity_Id) is
25505 procedure Collect_Constituent;
25506 -- Verify the legality of constituent Constit_Id and add it to
25507 -- the refinements of State_Id.
25508
25509 -------------------------
25510 -- Collect_Constituent --
25511 -------------------------
25512
25513 procedure Collect_Constituent is
25514 Constits : Elist_Id;
25515
25516 begin
25517 -- The Ghost policy in effect at the point of abstract state
25518 -- declaration and constituent must match (SPARK RM 6.9(15))
25519
25520 Check_Ghost_Refinement
25521 (State, State_Id, Constit, Constit_Id);
25522
25523 -- A synchronized state must be refined by a synchronized
25524 -- object or another synchronized state (SPARK RM 9.6).
25525
25526 if Is_Synchronized_State (State_Id)
25527 and then not Is_Synchronized_Object (Constit_Id)
25528 and then not Is_Synchronized_State (Constit_Id)
25529 then
25530 SPARK_Msg_NE
25531 ("constituent of synchronized state & must be "
25532 & "synchronized", Constit, State_Id);
25533 end if;
25534
25535 -- Add the constituent to the list of processed items to aid
25536 -- with the detection of duplicates.
25537
25538 Append_New_Elmt (Constit_Id, Constituents_Seen);
25539
25540 -- Collect the constituent in the list of refinement items
25541 -- and establish a relation between the refined state and
25542 -- the item.
25543
25544 Constits := Refinement_Constituents (State_Id);
25545
25546 if No (Constits) then
25547 Constits := New_Elmt_List;
25548 Set_Refinement_Constituents (State_Id, Constits);
25549 end if;
25550
25551 Append_Elmt (Constit_Id, Constits);
25552 Set_Encapsulating_State (Constit_Id, State_Id);
25553
25554 -- The state has at least one legal constituent, mark the
25555 -- start of the refinement region. The region ends when the
25556 -- body declarations end (see routine Analyze_Declarations).
25557
25558 Set_Has_Visible_Refinement (State_Id);
25559
25560 -- When the constituent is external, save its relevant
25561 -- property for further checks.
25562
25563 if Async_Readers_Enabled (Constit_Id) then
25564 AR_Constit := Constit_Id;
25565 External_Constit_Seen := True;
25566 end if;
25567
25568 if Async_Writers_Enabled (Constit_Id) then
25569 AW_Constit := Constit_Id;
25570 External_Constit_Seen := True;
25571 end if;
25572
25573 if Effective_Reads_Enabled (Constit_Id) then
25574 ER_Constit := Constit_Id;
25575 External_Constit_Seen := True;
25576 end if;
25577
25578 if Effective_Writes_Enabled (Constit_Id) then
25579 EW_Constit := Constit_Id;
25580 External_Constit_Seen := True;
25581 end if;
25582 end Collect_Constituent;
25583
25584 -- Local variables
25585
25586 State_Elmt : Elmt_Id;
25587
25588 -- Start of processing for Match_Constituent
25589
25590 begin
25591 -- Detect a duplicate use of a constituent
25592
25593 if Contains (Constituents_Seen, Constit_Id) then
25594 SPARK_Msg_NE
25595 ("duplicate use of constituent &", Constit, Constit_Id);
25596 return;
25597 end if;
25598
25599 -- The constituent is subject to a Part_Of indicator
25600
25601 if Present (Encapsulating_State (Constit_Id)) then
25602 if Encapsulating_State (Constit_Id) = State_Id then
25603 Remove (Part_Of_Constits, Constit_Id);
25604 Collect_Constituent;
25605
25606 -- The constituent is part of another state and is used
25607 -- incorrectly in the refinement of the current state.
25608
25609 else
25610 Error_Msg_Name_1 := Chars (State_Id);
25611 SPARK_Msg_NE
25612 ("& cannot act as constituent of state %",
25613 Constit, Constit_Id);
25614 SPARK_Msg_NE
25615 ("\Part_Of indicator specifies encapsulator &",
25616 Constit, Encapsulating_State (Constit_Id));
25617 end if;
25618
25619 -- The only other source of legal constituents is the body
25620 -- state space of the related package.
25621
25622 else
25623 if Present (Body_States) then
25624 State_Elmt := First_Elmt (Body_States);
25625 while Present (State_Elmt) loop
25626
25627 -- Consume a valid constituent to signal that it has
25628 -- been encountered.
25629
25630 if Node (State_Elmt) = Constit_Id then
25631 Remove_Elmt (Body_States, State_Elmt);
25632 Collect_Constituent;
25633 return;
25634 end if;
25635
25636 Next_Elmt (State_Elmt);
25637 end loop;
25638 end if;
25639
25640 -- Constants are part of the hidden state of a package, but
25641 -- the compiler cannot determine whether they have variable
25642 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
25643 -- hidden state. Accept the constant quietly even if it is
25644 -- a visible state or lacks a Part_Of indicator.
25645
25646 if Ekind (Constit_Id) = E_Constant then
25647 Collect_Constituent;
25648
25649 -- If we get here, then the constituent is not a hidden
25650 -- state of the related package and may not be used in a
25651 -- refinement (SPARK RM 7.2.2(9)).
25652
25653 else
25654 Error_Msg_Name_1 := Chars (Spec_Id);
25655 SPARK_Msg_NE
25656 ("cannot use & in refinement, constituent is not a "
25657 & "hidden state of package %", Constit, Constit_Id);
25658 end if;
25659 end if;
25660 end Match_Constituent;
25661
25662 -- Local variables
25663
25664 Constit_Id : Entity_Id;
25665 Constits : Elist_Id;
25666
25667 -- Start of processing for Analyze_Constituent
25668
25669 begin
25670 -- Detect multiple uses of null in a single refinement clause or a
25671 -- mixture of null and non-null constituents.
25672
25673 if Nkind (Constit) = N_Null then
25674 if Null_Seen then
25675 SPARK_Msg_N
25676 ("multiple null constituents not allowed", Constit);
25677
25678 elsif Non_Null_Seen then
25679 SPARK_Msg_N
25680 ("cannot mix null and non-null constituents", Constit);
25681
25682 else
25683 Null_Seen := True;
25684
25685 -- Collect the constituent in the list of refinement items
25686
25687 Constits := Refinement_Constituents (State_Id);
25688
25689 if No (Constits) then
25690 Constits := New_Elmt_List;
25691 Set_Refinement_Constituents (State_Id, Constits);
25692 end if;
25693
25694 Append_Elmt (Constit, Constits);
25695
25696 -- The state has at least one legal constituent, mark the
25697 -- start of the refinement region. The region ends when the
25698 -- body declarations end (see Analyze_Declarations).
25699
25700 Set_Has_Visible_Refinement (State_Id);
25701 end if;
25702
25703 -- Non-null constituents
25704
25705 else
25706 Non_Null_Seen := True;
25707
25708 if Null_Seen then
25709 SPARK_Msg_N
25710 ("cannot mix null and non-null constituents", Constit);
25711 end if;
25712
25713 Analyze (Constit);
25714 Resolve_State (Constit);
25715
25716 -- Ensure that the constituent denotes a valid state or a
25717 -- whole object (SPARK RM 7.2.2(5)).
25718
25719 if Is_Entity_Name (Constit) then
25720 Constit_Id := Entity_Of (Constit);
25721
25722 -- When a constituent is declared after a subprogram body
25723 -- that caused "freezing" of the related contract where
25724 -- pragma Refined_State resides, the constituent appears
25725 -- undefined and carries Any_Id as its entity.
25726
25727 -- package body Pack
25728 -- with Refined_State => (State => Constit)
25729 -- is
25730 -- procedure Proc
25731 -- with Refined_Global => (Input => Constit)
25732 -- is
25733 -- ...
25734 -- end Proc;
25735
25736 -- Constit : ...;
25737 -- end Pack;
25738
25739 if Constit_Id = Any_Id then
25740 SPARK_Msg_NE ("& is undefined", Constit, Constit_Id);
25741
25742 -- Emit a specialized info message when the contract of
25743 -- the related package body was "frozen" by another body.
25744 -- Note that it is not possible to precisely identify why
25745 -- the constituent is undefined because it is not visible
25746 -- when pragma Refined_State is analyzed. This message is
25747 -- a reasonable approximation.
25748
25749 if Present (Freeze_Id) and then not Freeze_Posted then
25750 Freeze_Posted := True;
25751
25752 Error_Msg_Name_1 := Chars (Body_Id);
25753 Error_Msg_Sloc := Sloc (Freeze_Id);
25754 SPARK_Msg_NE
25755 ("body & declared # freezes the contract of %",
25756 N, Freeze_Id);
25757 SPARK_Msg_N
25758 ("\all constituents must be declared before body #",
25759 N);
25760
25761 -- A misplaced constituent is a critical error because
25762 -- pragma Refined_Depends or Refined_Global depends on
25763 -- the proper link between a state and a constituent.
25764 -- Stop the compilation, as this leads to a multitude
25765 -- of misleading cascaded errors.
25766
25767 raise Program_Error;
25768 end if;
25769
25770 -- The constituent is a valid state or object
25771
25772 elsif Ekind_In (Constit_Id, E_Abstract_State,
25773 E_Constant,
25774 E_Variable)
25775 then
25776 Match_Constituent (Constit_Id);
25777
25778 -- The variable may eventually become a constituent of a
25779 -- single protected/task type. Record the reference now
25780 -- and verify its legality when analyzing the contract of
25781 -- the variable (SPARK RM 9.3).
25782
25783 if Ekind (Constit_Id) = E_Variable then
25784 Record_Possible_Part_Of_Reference
25785 (Var_Id => Constit_Id,
25786 Ref => Constit);
25787 end if;
25788
25789 -- Otherwise the constituent is illegal
25790
25791 else
25792 SPARK_Msg_NE
25793 ("constituent & must denote object or state",
25794 Constit, Constit_Id);
25795 end if;
25796
25797 -- The constituent is illegal
25798
25799 else
25800 SPARK_Msg_N ("malformed constituent", Constit);
25801 end if;
25802 end if;
25803 end Analyze_Constituent;
25804
25805 -----------------------------
25806 -- Check_External_Property --
25807 -----------------------------
25808
25809 procedure Check_External_Property
25810 (Prop_Nam : Name_Id;
25811 Enabled : Boolean;
25812 Constit : Entity_Id)
25813 is
25814 begin
25815 -- The property is missing in the declaration of the state, but
25816 -- a constituent is introducing it in the state refinement
25817 -- (SPARK RM 7.2.8(2)).
25818
25819 if not Enabled and then Present (Constit) then
25820 Error_Msg_Name_1 := Prop_Nam;
25821 Error_Msg_Name_2 := Chars (State_Id);
25822 SPARK_Msg_NE
25823 ("constituent & introduces external property % in refinement "
25824 & "of state %", State, Constit);
25825
25826 Error_Msg_Sloc := Sloc (State_Id);
25827 SPARK_Msg_N
25828 ("\property is missing in abstract state declaration #",
25829 State);
25830 end if;
25831 end Check_External_Property;
25832
25833 -----------------
25834 -- Match_State --
25835 -----------------
25836
25837 procedure Match_State is
25838 State_Elmt : Elmt_Id;
25839
25840 begin
25841 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
25842
25843 if Contains (Refined_States_Seen, State_Id) then
25844 SPARK_Msg_NE
25845 ("duplicate refinement of state &", State, State_Id);
25846 return;
25847 end if;
25848
25849 -- Inspect the abstract states defined in the package declaration
25850 -- looking for a match.
25851
25852 State_Elmt := First_Elmt (Available_States);
25853 while Present (State_Elmt) loop
25854
25855 -- A valid abstract state is being refined in the body. Add
25856 -- the state to the list of processed refined states to aid
25857 -- with the detection of duplicate refinements. Remove the
25858 -- state from Available_States to signal that it has already
25859 -- been refined.
25860
25861 if Node (State_Elmt) = State_Id then
25862 Append_New_Elmt (State_Id, Refined_States_Seen);
25863 Remove_Elmt (Available_States, State_Elmt);
25864 return;
25865 end if;
25866
25867 Next_Elmt (State_Elmt);
25868 end loop;
25869
25870 -- If we get here, we are refining a state that is not defined in
25871 -- the package declaration.
25872
25873 Error_Msg_Name_1 := Chars (Spec_Id);
25874 SPARK_Msg_NE
25875 ("cannot refine state, & is not defined in package %",
25876 State, State_Id);
25877 end Match_State;
25878
25879 --------------------------------
25880 -- Report_Unused_Constituents --
25881 --------------------------------
25882
25883 procedure Report_Unused_Constituents (Constits : Elist_Id) is
25884 Constit_Elmt : Elmt_Id;
25885 Constit_Id : Entity_Id;
25886 Posted : Boolean := False;
25887
25888 begin
25889 if Present (Constits) then
25890 Constit_Elmt := First_Elmt (Constits);
25891 while Present (Constit_Elmt) loop
25892 Constit_Id := Node (Constit_Elmt);
25893
25894 -- Generate an error message of the form:
25895
25896 -- state ... has unused Part_Of constituents
25897 -- abstract state ... defined at ...
25898 -- constant ... defined at ...
25899 -- variable ... defined at ...
25900
25901 if not Posted then
25902 Posted := True;
25903 SPARK_Msg_NE
25904 ("state & has unused Part_Of constituents",
25905 State, State_Id);
25906 end if;
25907
25908 Error_Msg_Sloc := Sloc (Constit_Id);
25909
25910 if Ekind (Constit_Id) = E_Abstract_State then
25911 SPARK_Msg_NE
25912 ("\abstract state & defined #", State, Constit_Id);
25913
25914 elsif Ekind (Constit_Id) = E_Constant then
25915 SPARK_Msg_NE
25916 ("\constant & defined #", State, Constit_Id);
25917
25918 else
25919 pragma Assert (Ekind (Constit_Id) = E_Variable);
25920 SPARK_Msg_NE ("\variable & defined #", State, Constit_Id);
25921 end if;
25922
25923 Next_Elmt (Constit_Elmt);
25924 end loop;
25925 end if;
25926 end Report_Unused_Constituents;
25927
25928 -- Local declarations
25929
25930 Body_Ref : Node_Id;
25931 Body_Ref_Elmt : Elmt_Id;
25932 Constit : Node_Id;
25933 Extra_State : Node_Id;
25934
25935 -- Start of processing for Analyze_Refinement_Clause
25936
25937 begin
25938 -- A refinement clause appears as a component association where the
25939 -- sole choice is the state and the expressions are the constituents.
25940 -- This is a syntax error, always report.
25941
25942 if Nkind (Clause) /= N_Component_Association then
25943 Error_Msg_N ("malformed state refinement clause", Clause);
25944 return;
25945 end if;
25946
25947 -- Analyze the state name of a refinement clause
25948
25949 State := First (Choices (Clause));
25950
25951 Analyze (State);
25952 Resolve_State (State);
25953
25954 -- Ensure that the state name denotes a valid abstract state that is
25955 -- defined in the spec of the related package.
25956
25957 if Is_Entity_Name (State) then
25958 State_Id := Entity_Of (State);
25959
25960 -- When the abstract state is undefined, it appears as Any_Id. Do
25961 -- not continue with the analysis of the clause.
25962
25963 if State_Id = Any_Id then
25964 return;
25965
25966 -- Catch any attempts to re-refine a state or refine a state that
25967 -- is not defined in the package declaration.
25968
25969 elsif Ekind (State_Id) = E_Abstract_State then
25970 Match_State;
25971
25972 else
25973 SPARK_Msg_NE ("& must denote abstract state", State, State_Id);
25974 return;
25975 end if;
25976
25977 -- References to a state with visible refinement are illegal.
25978 -- When nested packages are involved, detecting such references is
25979 -- tricky because pragma Refined_State is analyzed later than the
25980 -- offending pragma Depends or Global. References that occur in
25981 -- such nested context are stored in a list. Emit errors for all
25982 -- references found in Body_References (SPARK RM 6.1.4(8)).
25983
25984 if Present (Body_References (State_Id)) then
25985 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
25986 while Present (Body_Ref_Elmt) loop
25987 Body_Ref := Node (Body_Ref_Elmt);
25988
25989 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
25990 Error_Msg_Sloc := Sloc (State);
25991 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
25992
25993 Next_Elmt (Body_Ref_Elmt);
25994 end loop;
25995 end if;
25996
25997 -- The state name is illegal. This is a syntax error, always report.
25998
25999 else
26000 Error_Msg_N ("malformed state name in refinement clause", State);
26001 return;
26002 end if;
26003
26004 -- A refinement clause may only refine one state at a time
26005
26006 Extra_State := Next (State);
26007
26008 if Present (Extra_State) then
26009 SPARK_Msg_N
26010 ("refinement clause cannot cover multiple states", Extra_State);
26011 end if;
26012
26013 -- Replicate the Part_Of constituents of the refined state because
26014 -- the algorithm will consume items.
26015
26016 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
26017
26018 -- Analyze all constituents of the refinement. Multiple constituents
26019 -- appear as an aggregate.
26020
26021 Constit := Expression (Clause);
26022
26023 if Nkind (Constit) = N_Aggregate then
26024 if Present (Component_Associations (Constit)) then
26025 SPARK_Msg_N
26026 ("constituents of refinement clause must appear in "
26027 & "positional form", Constit);
26028
26029 else pragma Assert (Present (Expressions (Constit)));
26030 Constit := First (Expressions (Constit));
26031 while Present (Constit) loop
26032 Analyze_Constituent (Constit);
26033 Next (Constit);
26034 end loop;
26035 end if;
26036
26037 -- Various forms of a single constituent. Note that these may include
26038 -- malformed constituents.
26039
26040 else
26041 Analyze_Constituent (Constit);
26042 end if;
26043
26044 -- Verify that external constituents do not introduce new external
26045 -- property in the state refinement (SPARK RM 7.2.8(2)).
26046
26047 if Is_External_State (State_Id) then
26048 Check_External_Property
26049 (Prop_Nam => Name_Async_Readers,
26050 Enabled => Async_Readers_Enabled (State_Id),
26051 Constit => AR_Constit);
26052
26053 Check_External_Property
26054 (Prop_Nam => Name_Async_Writers,
26055 Enabled => Async_Writers_Enabled (State_Id),
26056 Constit => AW_Constit);
26057
26058 Check_External_Property
26059 (Prop_Nam => Name_Effective_Reads,
26060 Enabled => Effective_Reads_Enabled (State_Id),
26061 Constit => ER_Constit);
26062
26063 Check_External_Property
26064 (Prop_Nam => Name_Effective_Writes,
26065 Enabled => Effective_Writes_Enabled (State_Id),
26066 Constit => EW_Constit);
26067
26068 -- When a refined state is not external, it should not have external
26069 -- constituents (SPARK RM 7.2.8(1)).
26070
26071 elsif External_Constit_Seen then
26072 SPARK_Msg_NE
26073 ("non-external state & cannot contain external constituents in "
26074 & "refinement", State, State_Id);
26075 end if;
26076
26077 -- Ensure that all Part_Of candidate constituents have been mentioned
26078 -- in the refinement clause.
26079
26080 Report_Unused_Constituents (Part_Of_Constits);
26081 end Analyze_Refinement_Clause;
26082
26083 -----------------------------
26084 -- Report_Unrefined_States --
26085 -----------------------------
26086
26087 procedure Report_Unrefined_States (States : Elist_Id) is
26088 State_Elmt : Elmt_Id;
26089
26090 begin
26091 if Present (States) then
26092 State_Elmt := First_Elmt (States);
26093 while Present (State_Elmt) loop
26094 SPARK_Msg_N
26095 ("abstract state & must be refined", Node (State_Elmt));
26096
26097 Next_Elmt (State_Elmt);
26098 end loop;
26099 end if;
26100 end Report_Unrefined_States;
26101
26102 -- Local declarations
26103
26104 Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
26105 Clause : Node_Id;
26106
26107 -- Start of processing for Analyze_Refined_State_In_Decl_Part
26108
26109 begin
26110 -- Do not analyze the pragma multiple times
26111
26112 if Is_Analyzed_Pragma (N) then
26113 return;
26114 end if;
26115
26116 -- Replicate the abstract states declared by the package because the
26117 -- matching algorithm will consume states.
26118
26119 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
26120
26121 -- Gather all abstract states and objects declared in the visible
26122 -- state space of the package body. These items must be utilized as
26123 -- constituents in a state refinement.
26124
26125 Body_States := Collect_Body_States (Body_Id);
26126
26127 -- Multiple non-null state refinements appear as an aggregate
26128
26129 if Nkind (Clauses) = N_Aggregate then
26130 if Present (Expressions (Clauses)) then
26131 SPARK_Msg_N
26132 ("state refinements must appear as component associations",
26133 Clauses);
26134
26135 else pragma Assert (Present (Component_Associations (Clauses)));
26136 Clause := First (Component_Associations (Clauses));
26137 while Present (Clause) loop
26138 Analyze_Refinement_Clause (Clause);
26139 Next (Clause);
26140 end loop;
26141 end if;
26142
26143 -- Various forms of a single state refinement. Note that these may
26144 -- include malformed refinements.
26145
26146 else
26147 Analyze_Refinement_Clause (Clauses);
26148 end if;
26149
26150 -- List all abstract states that were left unrefined
26151
26152 Report_Unrefined_States (Available_States);
26153
26154 Set_Is_Analyzed_Pragma (N);
26155 end Analyze_Refined_State_In_Decl_Part;
26156
26157 ------------------------------------
26158 -- Analyze_Test_Case_In_Decl_Part --
26159 ------------------------------------
26160
26161 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is
26162 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
26163 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
26164
26165 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id);
26166 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
26167 -- denoted by Arg_Nam.
26168
26169 ------------------------------
26170 -- Preanalyze_Test_Case_Arg --
26171 ------------------------------
26172
26173 procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is
26174 Arg : Node_Id;
26175
26176 begin
26177 -- Preanalyze the original aspect argument for ASIS or for a generic
26178 -- subprogram to properly capture global references.
26179
26180 if ASIS_Mode or else Is_Generic_Subprogram (Spec_Id) then
26181 Arg :=
26182 Test_Case_Arg
26183 (Prag => N,
26184 Arg_Nam => Arg_Nam,
26185 From_Aspect => True);
26186
26187 if Present (Arg) then
26188 Preanalyze_Assert_Expression
26189 (Expression (Arg), Standard_Boolean);
26190 end if;
26191 end if;
26192
26193 Arg := Test_Case_Arg (N, Arg_Nam);
26194
26195 if Present (Arg) then
26196 Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean);
26197 end if;
26198 end Preanalyze_Test_Case_Arg;
26199
26200 -- Local variables
26201
26202 Restore_Scope : Boolean := False;
26203
26204 -- Start of processing for Analyze_Test_Case_In_Decl_Part
26205
26206 begin
26207 -- Do not analyze the pragma multiple times
26208
26209 if Is_Analyzed_Pragma (N) then
26210 return;
26211 end if;
26212
26213 -- Ensure that the formal parameters are visible when analyzing all
26214 -- clauses. This falls out of the general rule of aspects pertaining
26215 -- to subprogram declarations.
26216
26217 if not In_Open_Scopes (Spec_Id) then
26218 Restore_Scope := True;
26219 Push_Scope (Spec_Id);
26220
26221 if Is_Generic_Subprogram (Spec_Id) then
26222 Install_Generic_Formals (Spec_Id);
26223 else
26224 Install_Formals (Spec_Id);
26225 end if;
26226 end if;
26227
26228 Preanalyze_Test_Case_Arg (Name_Requires);
26229 Preanalyze_Test_Case_Arg (Name_Ensures);
26230
26231 if Restore_Scope then
26232 End_Scope;
26233 end if;
26234
26235 -- Currently it is not possible to inline pre/postconditions on a
26236 -- subprogram subject to pragma Inline_Always.
26237
26238 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
26239
26240 Set_Is_Analyzed_Pragma (N);
26241 end Analyze_Test_Case_In_Decl_Part;
26242
26243 ----------------
26244 -- Appears_In --
26245 ----------------
26246
26247 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
26248 Elmt : Elmt_Id;
26249 Id : Entity_Id;
26250
26251 begin
26252 if Present (List) then
26253 Elmt := First_Elmt (List);
26254 while Present (Elmt) loop
26255 if Nkind (Node (Elmt)) = N_Defining_Identifier then
26256 Id := Node (Elmt);
26257 else
26258 Id := Entity_Of (Node (Elmt));
26259 end if;
26260
26261 if Id = Item_Id then
26262 return True;
26263 end if;
26264
26265 Next_Elmt (Elmt);
26266 end loop;
26267 end if;
26268
26269 return False;
26270 end Appears_In;
26271
26272 -----------------------------------
26273 -- Build_Pragma_Check_Equivalent --
26274 -----------------------------------
26275
26276 function Build_Pragma_Check_Equivalent
26277 (Prag : Node_Id;
26278 Subp_Id : Entity_Id := Empty;
26279 Inher_Id : Entity_Id := Empty;
26280 Keep_Pragma_Id : Boolean := False) return Node_Id
26281 is
26282 Map : Elist_Id;
26283 -- List containing the following mappings
26284 -- * Formal parameters of inherited subprogram Inher_Id and subprogram
26285 -- Subp_Id.
26286 --
26287 -- * The dispatching type of Inher_Id and the dispatching type of
26288 -- Subp_Id.
26289 --
26290 -- * Primitives of the dispatching type of Inher_Id and primitives of
26291 -- the dispatching type of Subp_Id.
26292
26293 function Replace_Entity (N : Node_Id) return Traverse_Result;
26294 -- Replace reference to formal of inherited operation or to primitive
26295 -- operation of root type, with corresponding entity for derived type.
26296
26297 function Suppress_Reference (N : Node_Id) return Traverse_Result;
26298 -- Detect whether node N references a formal parameter subject to
26299 -- pragma Unreferenced. If this is the case, set Comes_From_Source
26300 -- to False to suppress the generation of a reference when analyzing
26301 -- N later on.
26302
26303 --------------------
26304 -- Replace_Entity --
26305 --------------------
26306
26307 function Replace_Entity (N : Node_Id) return Traverse_Result is
26308 Elmt : Elmt_Id;
26309 New_E : Entity_Id;
26310
26311 begin
26312 if Nkind (N) = N_Identifier
26313 and then Present (Entity (N))
26314 and then
26315 (Is_Formal (Entity (N)) or else Is_Subprogram (Entity (N)))
26316 and then
26317 (Nkind (Parent (N)) /= N_Attribute_Reference
26318 or else Attribute_Name (Parent (N)) /= Name_Class)
26319 then
26320 -- The replacement does not apply to dispatching calls within the
26321 -- condition, but only to calls whose static tag is that of the
26322 -- parent type.
26323
26324 if Is_Subprogram (Entity (N))
26325 and then Nkind (Parent (N)) = N_Function_Call
26326 and then Present (Controlling_Argument (Parent (N)))
26327 then
26328 return OK;
26329 end if;
26330
26331 -- Loop to find out if entity has a renaming
26332
26333 New_E := Empty;
26334 Elmt := First_Elmt (Map);
26335 while Present (Elmt) loop
26336 if Node (Elmt) = Entity (N) then
26337 New_E := Node (Next_Elmt (Elmt));
26338 exit;
26339 end if;
26340
26341 Next_Elmt (Elmt);
26342 end loop;
26343
26344 if Present (New_E) then
26345 Rewrite (N, New_Occurrence_Of (New_E, Sloc (N)));
26346 end if;
26347
26348 -- Check that there are no calls left to abstract operations if
26349 -- the current subprogram is not abstract.
26350
26351 if Nkind (Parent (N)) = N_Function_Call
26352 and then N = Name (Parent (N))
26353 and then not Is_Abstract_Subprogram (Subp_Id)
26354 and then Is_Abstract_Subprogram (Entity (N))
26355 then
26356 Error_Msg_Sloc := Sloc (Current_Scope);
26357 Error_Msg_NE
26358 ("cannot call abstract subprogram in inherited condition "
26359 & "for&#", N, Current_Scope);
26360 end if;
26361
26362 -- Update type of function call node, which should be the same as
26363 -- the function's return type.
26364
26365 if Is_Subprogram (Entity (N))
26366 and then Nkind (Parent (N)) = N_Function_Call
26367 then
26368 Set_Etype (Parent (N), Etype (Entity (N)));
26369 end if;
26370
26371 -- The whole expression will be reanalyzed
26372
26373 elsif Nkind (N) in N_Has_Etype then
26374 Set_Analyzed (N, False);
26375 end if;
26376
26377 return OK;
26378 end Replace_Entity;
26379
26380 ------------------------
26381 -- Suppress_Reference --
26382 ------------------------
26383
26384 function Suppress_Reference (N : Node_Id) return Traverse_Result is
26385 Formal : Entity_Id;
26386
26387 begin
26388 if Is_Entity_Name (N) and then Present (Entity (N)) then
26389 Formal := Entity (N);
26390
26391 -- The formal parameter is subject to pragma Unreferenced.
26392 -- Prevent the generation of a reference by resetting the
26393 -- Comes_From_Source flag.
26394
26395 if Is_Formal (Formal)
26396 and then Has_Pragma_Unreferenced (Formal)
26397 then
26398 Set_Comes_From_Source (N, False);
26399 end if;
26400 end if;
26401
26402 return OK;
26403 end Suppress_Reference;
26404
26405 procedure Replace_Condition_Entities is
26406 new Traverse_Proc (Replace_Entity);
26407
26408 procedure Suppress_References is
26409 new Traverse_Proc (Suppress_Reference);
26410
26411 -- Local variables
26412
26413 Loc : constant Source_Ptr := Sloc (Prag);
26414 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
26415 Check_Prag : Node_Id;
26416 Inher_Formal : Entity_Id;
26417 Msg_Arg : Node_Id;
26418 Nam : Name_Id;
26419 Subp_Formal : Entity_Id;
26420
26421 -- Start of processing for Build_Pragma_Check_Equivalent
26422
26423 begin
26424 Map := No_Elist;
26425
26426 -- When the pre- or postcondition is inherited, map the formals of the
26427 -- inherited subprogram to those of the current subprogram. In addition,
26428 -- map primitive operations of the parent type into the corresponding
26429 -- primitive operations of the descendant.
26430
26431 if Present (Inher_Id) then
26432 pragma Assert (Present (Subp_Id));
26433
26434 Map := New_Elmt_List;
26435
26436 -- Create a mapping <inherited formal> => <subprogram formal>
26437
26438 Inher_Formal := First_Formal (Inher_Id);
26439 Subp_Formal := First_Formal (Subp_Id);
26440 while Present (Inher_Formal) and then Present (Subp_Formal) loop
26441 Append_Elmt (Inher_Formal, Map);
26442 Append_Elmt (Subp_Formal, Map);
26443
26444 Next_Formal (Inher_Formal);
26445 Next_Formal (Subp_Formal);
26446 end loop;
26447
26448 -- Map primitive operations of the parent type to the corresponding
26449 -- operations of the descendant. Note that the descendant type may
26450 -- not be frozen yet, so we cannot use the dispatch table directly.
26451
26452 -- Note : the construction of the map involves a full traversal of
26453 -- the list of primitive operations, as well as a scan of the
26454 -- declarations in the scope of the operation. Given that class-wide
26455 -- conditions are typically short expressions, it might be much more
26456 -- efficient to collect the identifiers in the expression first, and
26457 -- then determine the ones that have to be mapped. Optimization ???
26458
26459 Primitive_Mapping : declare
26460 function Overridden_Ancestor (S : Entity_Id) return Entity_Id;
26461 -- Given the controlling type of the overridden operation and a
26462 -- primitive of the current type, find the corresponding operation
26463 -- of the parent type.
26464
26465 -------------------------
26466 -- Overridden_Ancestor --
26467 -------------------------
26468
26469 function Overridden_Ancestor (S : Entity_Id) return Entity_Id is
26470 Par : constant Entity_Id := Find_Dispatching_Type (Inher_Id);
26471 Anc : Entity_Id;
26472
26473 begin
26474 Anc := S;
26475
26476 -- Locate the ancestor subprogram with the proper controlling
26477 -- type.
26478
26479 while Present (Overridden_Operation (Anc)) loop
26480 Anc := Overridden_Operation (Anc);
26481 exit when Find_Dispatching_Type (Anc) = Par;
26482 end loop;
26483
26484 return Anc;
26485 end Overridden_Ancestor;
26486
26487 -- Local variables
26488
26489 Old_Typ : constant Entity_Id := Find_Dispatching_Type (Inher_Id);
26490 Typ : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
26491 Decl : Node_Id;
26492 Old_Elmt : Elmt_Id;
26493 Old_Prim : Entity_Id;
26494 Prim : Entity_Id;
26495
26496 -- Start of processing for Primitive_Mapping
26497
26498 begin
26499 Decl := First (List_Containing (Unit_Declaration_Node (Subp_Id)));
26500
26501 -- Look for primitive operations of the current type that have
26502 -- overridden an operation of the type related to the original
26503 -- class-wide precondition. There may be several intermediate
26504 -- overridings between them.
26505
26506 while Present (Decl) loop
26507 if Nkind_In (Decl, N_Abstract_Subprogram_Declaration,
26508 N_Subprogram_Declaration)
26509 then
26510 Prim := Defining_Entity (Decl);
26511
26512 if Is_Subprogram (Prim)
26513 and then Present (Overridden_Operation (Prim))
26514 and then Find_Dispatching_Type (Prim) = Typ
26515 then
26516 Old_Prim := Overridden_Ancestor (Prim);
26517
26518 Append_Elmt (Old_Prim, Map);
26519 Append_Elmt (Prim, Map);
26520 end if;
26521 end if;
26522
26523 Next (Decl);
26524 end loop;
26525
26526 -- Now examine inherited operations. These do not override, but
26527 -- have an alias, which is the entity used in a call. In turn
26528 -- that alias may be inherited or comes from source, in which
26529 -- case it may override an earlier operation. We only need to
26530 -- examine inherited functions, that may appear within the
26531 -- inherited expression.
26532
26533 Prim := First_Entity (Scope (Subp_Id));
26534 while Present (Prim) loop
26535 if not Comes_From_Source (Prim)
26536 and then Ekind (Prim) = E_Function
26537 and then Present (Alias (Prim))
26538 then
26539 Old_Prim := Alias (Prim);
26540
26541 if Comes_From_Source (Old_Prim) then
26542 Old_Prim := Overridden_Ancestor (Old_Prim);
26543
26544 else
26545 while Present (Alias (Old_Prim))
26546 and then Scope (Old_Prim) /= Scope (Inher_Id)
26547 loop
26548 Old_Prim := Alias (Old_Prim);
26549
26550 if Comes_From_Source (Old_Prim) then
26551 Old_Prim := Overridden_Ancestor (Old_Prim);
26552 exit;
26553 end if;
26554 end loop;
26555 end if;
26556
26557 Append_Elmt (Old_Prim, Map);
26558 Append_Elmt (Prim, Map);
26559 end if;
26560
26561 Next_Entity (Prim);
26562 end loop;
26563
26564 -- If the parent operation is an interface operation, the
26565 -- overriding indicator is not present. Instead, we get from
26566 -- the interface operation the primitive of the current type
26567 -- that implements it.
26568
26569 if Is_Interface (Old_Typ) then
26570 Old_Elmt := First_Elmt (Collect_Primitive_Operations (Old_Typ));
26571 while Present (Old_Elmt) loop
26572 Old_Prim := Node (Old_Elmt);
26573 Prim := Find_Primitive_Covering_Interface (Typ, Old_Prim);
26574
26575 if Present (Prim) then
26576 Append_Elmt (Old_Prim, Map);
26577 Append_Elmt (Prim, Map);
26578 end if;
26579
26580 Next_Elmt (Old_Elmt);
26581 end loop;
26582 end if;
26583
26584 if Map /= No_Elist then
26585 Append_Elmt (Old_Typ, Map);
26586 Append_Elmt (Typ, Map);
26587 end if;
26588 end Primitive_Mapping;
26589 end if;
26590
26591 -- Copy the original pragma while performing substitutions (if
26592 -- applicable).
26593
26594 Check_Prag := New_Copy_Tree (Source => Prag);
26595
26596 if Map /= No_Elist then
26597 Replace_Condition_Entities (Check_Prag);
26598 end if;
26599
26600 -- Mark the pragma as being internally generated and reset the Analyzed
26601 -- flag.
26602
26603 Set_Analyzed (Check_Prag, False);
26604 Set_Comes_From_Source (Check_Prag, False);
26605
26606 -- The tree of the original pragma may contain references to the
26607 -- formal parameters of the related subprogram. At the same time
26608 -- the corresponding body may mark the formals as unreferenced:
26609
26610 -- procedure Proc (Formal : ...)
26611 -- with Pre => Formal ...;
26612
26613 -- procedure Proc (Formal : ...) is
26614 -- pragma Unreferenced (Formal);
26615 -- ...
26616
26617 -- This creates problems because all pragma Check equivalents are
26618 -- analyzed at the end of the body declarations. Since all source
26619 -- references have already been accounted for, reset any references
26620 -- to such formals in the generated pragma Check equivalent.
26621
26622 Suppress_References (Check_Prag);
26623
26624 if Present (Corresponding_Aspect (Prag)) then
26625 Nam := Chars (Identifier (Corresponding_Aspect (Prag)));
26626 else
26627 Nam := Prag_Nam;
26628 end if;
26629
26630 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
26631 -- the copied pragma in the newly created pragma, convert the copy into
26632 -- pragma Check by correcting the name and adding a check_kind argument.
26633
26634 if not Keep_Pragma_Id then
26635 Set_Class_Present (Check_Prag, False);
26636
26637 Set_Pragma_Identifier
26638 (Check_Prag, Make_Identifier (Loc, Name_Check));
26639
26640 Prepend_To (Pragma_Argument_Associations (Check_Prag),
26641 Make_Pragma_Argument_Association (Loc,
26642 Expression => Make_Identifier (Loc, Nam)));
26643 end if;
26644
26645 -- Update the error message when the pragma is inherited
26646
26647 if Present (Inher_Id) then
26648 Msg_Arg := Last (Pragma_Argument_Associations (Check_Prag));
26649
26650 if Chars (Msg_Arg) = Name_Message then
26651 String_To_Name_Buffer (Strval (Expression (Msg_Arg)));
26652
26653 -- Insert "inherited" to improve the error message
26654
26655 if Name_Buffer (1 .. 8) = "failed p" then
26656 Insert_Str_In_Name_Buffer ("inherited ", 8);
26657 Set_Strval (Expression (Msg_Arg), String_From_Name_Buffer);
26658 end if;
26659 end if;
26660 end if;
26661
26662 return Check_Prag;
26663 end Build_Pragma_Check_Equivalent;
26664
26665 -----------------------------
26666 -- Check_Applicable_Policy --
26667 -----------------------------
26668
26669 procedure Check_Applicable_Policy (N : Node_Id) is
26670 PP : Node_Id;
26671 Policy : Name_Id;
26672
26673 Ename : constant Name_Id := Original_Aspect_Pragma_Name (N);
26674
26675 begin
26676 -- No effect if not valid assertion kind name
26677
26678 if not Is_Valid_Assertion_Kind (Ename) then
26679 return;
26680 end if;
26681
26682 -- Loop through entries in check policy list
26683
26684 PP := Opt.Check_Policy_List;
26685 while Present (PP) loop
26686 declare
26687 PPA : constant List_Id := Pragma_Argument_Associations (PP);
26688 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
26689
26690 begin
26691 if Ename = Pnm
26692 or else Pnm = Name_Assertion
26693 or else (Pnm = Name_Statement_Assertions
26694 and then Nam_In (Ename, Name_Assert,
26695 Name_Assert_And_Cut,
26696 Name_Assume,
26697 Name_Loop_Invariant,
26698 Name_Loop_Variant))
26699 then
26700 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
26701
26702 case Policy is
26703 when Name_Off | Name_Ignore =>
26704 Set_Is_Ignored (N, True);
26705 Set_Is_Checked (N, False);
26706
26707 when Name_On | Name_Check =>
26708 Set_Is_Checked (N, True);
26709 Set_Is_Ignored (N, False);
26710
26711 when Name_Disable =>
26712 Set_Is_Ignored (N, True);
26713 Set_Is_Checked (N, False);
26714 Set_Is_Disabled (N, True);
26715
26716 -- That should be exhaustive, the null here is a defence
26717 -- against a malformed tree from previous errors.
26718
26719 when others =>
26720 null;
26721 end case;
26722
26723 return;
26724 end if;
26725
26726 PP := Next_Pragma (PP);
26727 end;
26728 end loop;
26729
26730 -- If there are no specific entries that matched, then we let the
26731 -- setting of assertions govern. Note that this provides the needed
26732 -- compatibility with the RM for the cases of assertion, invariant,
26733 -- precondition, predicate, and postcondition.
26734
26735 if Assertions_Enabled then
26736 Set_Is_Checked (N, True);
26737 Set_Is_Ignored (N, False);
26738 else
26739 Set_Is_Checked (N, False);
26740 Set_Is_Ignored (N, True);
26741 end if;
26742 end Check_Applicable_Policy;
26743
26744 -------------------------------
26745 -- Check_External_Properties --
26746 -------------------------------
26747
26748 procedure Check_External_Properties
26749 (Item : Node_Id;
26750 AR : Boolean;
26751 AW : Boolean;
26752 ER : Boolean;
26753 EW : Boolean)
26754 is
26755 begin
26756 -- All properties enabled
26757
26758 if AR and AW and ER and EW then
26759 null;
26760
26761 -- Async_Readers + Effective_Writes
26762 -- Async_Readers + Async_Writers + Effective_Writes
26763
26764 elsif AR and EW and not ER then
26765 null;
26766
26767 -- Async_Writers + Effective_Reads
26768 -- Async_Readers + Async_Writers + Effective_Reads
26769
26770 elsif AW and ER and not EW then
26771 null;
26772
26773 -- Async_Readers + Async_Writers
26774
26775 elsif AR and AW and not ER and not EW then
26776 null;
26777
26778 -- Async_Readers
26779
26780 elsif AR and not AW and not ER and not EW then
26781 null;
26782
26783 -- Async_Writers
26784
26785 elsif AW and not AR and not ER and not EW then
26786 null;
26787
26788 else
26789 SPARK_Msg_N
26790 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
26791 Item);
26792 end if;
26793 end Check_External_Properties;
26794
26795 ----------------
26796 -- Check_Kind --
26797 ----------------
26798
26799 function Check_Kind (Nam : Name_Id) return Name_Id is
26800 PP : Node_Id;
26801
26802 begin
26803 -- Loop through entries in check policy list
26804
26805 PP := Opt.Check_Policy_List;
26806 while Present (PP) loop
26807 declare
26808 PPA : constant List_Id := Pragma_Argument_Associations (PP);
26809 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
26810
26811 begin
26812 if Nam = Pnm
26813 or else (Pnm = Name_Assertion
26814 and then Is_Valid_Assertion_Kind (Nam))
26815 or else (Pnm = Name_Statement_Assertions
26816 and then Nam_In (Nam, Name_Assert,
26817 Name_Assert_And_Cut,
26818 Name_Assume,
26819 Name_Loop_Invariant,
26820 Name_Loop_Variant))
26821 then
26822 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
26823 when Name_On | Name_Check =>
26824 return Name_Check;
26825 when Name_Off | Name_Ignore =>
26826 return Name_Ignore;
26827 when Name_Disable =>
26828 return Name_Disable;
26829 when others =>
26830 raise Program_Error;
26831 end case;
26832
26833 else
26834 PP := Next_Pragma (PP);
26835 end if;
26836 end;
26837 end loop;
26838
26839 -- If there are no specific entries that matched, then we let the
26840 -- setting of assertions govern. Note that this provides the needed
26841 -- compatibility with the RM for the cases of assertion, invariant,
26842 -- precondition, predicate, and postcondition.
26843
26844 if Assertions_Enabled then
26845 return Name_Check;
26846 else
26847 return Name_Ignore;
26848 end if;
26849 end Check_Kind;
26850
26851 ---------------------------
26852 -- Check_Missing_Part_Of --
26853 ---------------------------
26854
26855 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
26856 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
26857 -- Determine whether a package denoted by Pack_Id declares at least one
26858 -- visible state.
26859
26860 -----------------------
26861 -- Has_Visible_State --
26862 -----------------------
26863
26864 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
26865 Item_Id : Entity_Id;
26866
26867 begin
26868 -- Traverse the entity chain of the package trying to find at least
26869 -- one visible abstract state, variable or a package [instantiation]
26870 -- that declares a visible state.
26871
26872 Item_Id := First_Entity (Pack_Id);
26873 while Present (Item_Id)
26874 and then not In_Private_Part (Item_Id)
26875 loop
26876 -- Do not consider internally generated items
26877
26878 if not Comes_From_Source (Item_Id) then
26879 null;
26880
26881 -- A visible state has been found
26882
26883 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
26884 return True;
26885
26886 -- Recursively peek into nested packages and instantiations
26887
26888 elsif Ekind (Item_Id) = E_Package
26889 and then Has_Visible_State (Item_Id)
26890 then
26891 return True;
26892 end if;
26893
26894 Next_Entity (Item_Id);
26895 end loop;
26896
26897 return False;
26898 end Has_Visible_State;
26899
26900 -- Local variables
26901
26902 Pack_Id : Entity_Id;
26903 Placement : State_Space_Kind;
26904
26905 -- Start of processing for Check_Missing_Part_Of
26906
26907 begin
26908 -- Do not consider abstract states, variables or package instantiations
26909 -- coming from an instance as those always inherit the Part_Of indicator
26910 -- of the instance itself.
26911
26912 if In_Instance then
26913 return;
26914
26915 -- Do not consider internally generated entities as these can never
26916 -- have a Part_Of indicator.
26917
26918 elsif not Comes_From_Source (Item_Id) then
26919 return;
26920
26921 -- Perform these checks only when SPARK_Mode is enabled as they will
26922 -- interfere with standard Ada rules and produce false positives.
26923
26924 elsif SPARK_Mode /= On then
26925 return;
26926
26927 -- Do not consider constants, because the compiler cannot accurately
26928 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
26929 -- act as a hidden state of a package.
26930
26931 elsif Ekind (Item_Id) = E_Constant then
26932 return;
26933 end if;
26934
26935 -- Find where the abstract state, variable or package instantiation
26936 -- lives with respect to the state space.
26937
26938 Find_Placement_In_State_Space
26939 (Item_Id => Item_Id,
26940 Placement => Placement,
26941 Pack_Id => Pack_Id);
26942
26943 -- Items that appear in a non-package construct (subprogram, block, etc)
26944 -- do not require a Part_Of indicator because they can never act as a
26945 -- hidden state.
26946
26947 if Placement = Not_In_Package then
26948 null;
26949
26950 -- An item declared in the body state space of a package always act as a
26951 -- constituent and does not need explicit Part_Of indicator.
26952
26953 elsif Placement = Body_State_Space then
26954 null;
26955
26956 -- In general an item declared in the visible state space of a package
26957 -- does not require a Part_Of indicator. The only exception is when the
26958 -- related package is a private child unit in which case Part_Of must
26959 -- denote a state in the parent unit or in one of its descendants.
26960
26961 elsif Placement = Visible_State_Space then
26962 if Is_Child_Unit (Pack_Id)
26963 and then Is_Private_Descendant (Pack_Id)
26964 then
26965 -- A package instantiation does not need a Part_Of indicator when
26966 -- the related generic template has no visible state.
26967
26968 if Ekind (Item_Id) = E_Package
26969 and then Is_Generic_Instance (Item_Id)
26970 and then not Has_Visible_State (Item_Id)
26971 then
26972 null;
26973
26974 -- All other cases require Part_Of
26975
26976 else
26977 Error_Msg_N
26978 ("indicator Part_Of is required in this context "
26979 & "(SPARK RM 7.2.6(3))", Item_Id);
26980 Error_Msg_Name_1 := Chars (Pack_Id);
26981 Error_Msg_N
26982 ("\& is declared in the visible part of private child "
26983 & "unit %", Item_Id);
26984 end if;
26985 end if;
26986
26987 -- When the item appears in the private state space of a packge, it must
26988 -- be a part of some state declared by the said package.
26989
26990 else pragma Assert (Placement = Private_State_Space);
26991
26992 -- The related package does not declare a state, the item cannot act
26993 -- as a Part_Of constituent.
26994
26995 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
26996 null;
26997
26998 -- A package instantiation does not need a Part_Of indicator when the
26999 -- related generic template has no visible state.
27000
27001 elsif Ekind (Pack_Id) = E_Package
27002 and then Is_Generic_Instance (Pack_Id)
27003 and then not Has_Visible_State (Pack_Id)
27004 then
27005 null;
27006
27007 -- All other cases require Part_Of
27008
27009 else
27010 Error_Msg_N
27011 ("indicator Part_Of is required in this context "
27012 & "(SPARK RM 7.2.6(2))", Item_Id);
27013 Error_Msg_Name_1 := Chars (Pack_Id);
27014 Error_Msg_N
27015 ("\& is declared in the private part of package %", Item_Id);
27016 end if;
27017 end if;
27018 end Check_Missing_Part_Of;
27019
27020 ---------------------------------------------------
27021 -- Check_Postcondition_Use_In_Inlined_Subprogram --
27022 ---------------------------------------------------
27023
27024 procedure Check_Postcondition_Use_In_Inlined_Subprogram
27025 (Prag : Node_Id;
27026 Spec_Id : Entity_Id)
27027 is
27028 begin
27029 if Warn_On_Redundant_Constructs
27030 and then Has_Pragma_Inline_Always (Spec_Id)
27031 then
27032 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
27033
27034 if From_Aspect_Specification (Prag) then
27035 Error_Msg_NE
27036 ("aspect % not enforced on inlined subprogram &?r?",
27037 Corresponding_Aspect (Prag), Spec_Id);
27038 else
27039 Error_Msg_NE
27040 ("pragma % not enforced on inlined subprogram &?r?",
27041 Prag, Spec_Id);
27042 end if;
27043 end if;
27044 end Check_Postcondition_Use_In_Inlined_Subprogram;
27045
27046 -------------------------------------
27047 -- Check_State_And_Constituent_Use --
27048 -------------------------------------
27049
27050 procedure Check_State_And_Constituent_Use
27051 (States : Elist_Id;
27052 Constits : Elist_Id;
27053 Context : Node_Id)
27054 is
27055 function Find_Encapsulating_State
27056 (Constit_Id : Entity_Id) return Entity_Id;
27057 -- Given the entity of a constituent, try to find a corresponding
27058 -- encapsulating state that appears in the same context. The routine
27059 -- returns Empty is no such state is found.
27060
27061 ------------------------------
27062 -- Find_Encapsulating_State --
27063 ------------------------------
27064
27065 function Find_Encapsulating_State
27066 (Constit_Id : Entity_Id) return Entity_Id
27067 is
27068 State_Id : Entity_Id;
27069
27070 begin
27071 -- Since a constituent may be part of a larger constituent set, climb
27072 -- the encapsulating state chain looking for a state that appears in
27073 -- the same context.
27074
27075 State_Id := Encapsulating_State (Constit_Id);
27076 while Present (State_Id) loop
27077 if Contains (States, State_Id) then
27078 return State_Id;
27079 end if;
27080
27081 State_Id := Encapsulating_State (State_Id);
27082 end loop;
27083
27084 return Empty;
27085 end Find_Encapsulating_State;
27086
27087 -- Local variables
27088
27089 Constit_Elmt : Elmt_Id;
27090 Constit_Id : Entity_Id;
27091 State_Id : Entity_Id;
27092
27093 -- Start of processing for Check_State_And_Constituent_Use
27094
27095 begin
27096 -- Nothing to do if there are no states or constituents
27097
27098 if No (States) or else No (Constits) then
27099 return;
27100 end if;
27101
27102 -- Inspect the list of constituents and try to determine whether its
27103 -- encapsulating state is in list States.
27104
27105 Constit_Elmt := First_Elmt (Constits);
27106 while Present (Constit_Elmt) loop
27107 Constit_Id := Node (Constit_Elmt);
27108
27109 -- Determine whether the constituent is part of an encapsulating
27110 -- state that appears in the same context and if this is the case,
27111 -- emit an error (SPARK RM 7.2.6(7)).
27112
27113 State_Id := Find_Encapsulating_State (Constit_Id);
27114
27115 if Present (State_Id) then
27116 Error_Msg_Name_1 := Chars (Constit_Id);
27117 SPARK_Msg_NE
27118 ("cannot mention state & and its constituent % in the same "
27119 & "context", Context, State_Id);
27120 exit;
27121 end if;
27122
27123 Next_Elmt (Constit_Elmt);
27124 end loop;
27125 end Check_State_And_Constituent_Use;
27126
27127 ---------------------------------------------
27128 -- Collect_Inherited_Class_Wide_Conditions --
27129 ---------------------------------------------
27130
27131 procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is
27132 Parent_Subp : constant Entity_Id := Overridden_Operation (Subp);
27133 Prags : constant Node_Id := Contract (Parent_Subp);
27134 In_Spec_Expr : Boolean;
27135 Installed : Boolean;
27136 Prag : Node_Id;
27137 New_Prag : Node_Id;
27138
27139 begin
27140 Installed := False;
27141
27142 -- Iterate over the contract of the overridden subprogram to find all
27143 -- inherited class-wide pre- and postconditions.
27144
27145 if Present (Prags) then
27146 Prag := Pre_Post_Conditions (Prags);
27147
27148 while Present (Prag) loop
27149 if Nam_In (Pragma_Name (Prag), Name_Precondition,
27150 Name_Postcondition)
27151 and then Class_Present (Prag)
27152 then
27153 -- The generated pragma must be analyzed in the context of
27154 -- the subprogram, to make its formals visible. In addition,
27155 -- we must inhibit freezing and full analysis because the
27156 -- controlling type of the subprogram is not frozen yet, and
27157 -- may have further primitives.
27158
27159 if not Installed then
27160 Installed := True;
27161 Push_Scope (Subp);
27162 Install_Formals (Subp);
27163 In_Spec_Expr := In_Spec_Expression;
27164 In_Spec_Expression := True;
27165 end if;
27166
27167 New_Prag :=
27168 Build_Pragma_Check_Equivalent
27169 (Prag, Subp, Parent_Subp, Keep_Pragma_Id => True);
27170
27171 Insert_After (Unit_Declaration_Node (Subp), New_Prag);
27172 Preanalyze (New_Prag);
27173
27174 -- Prevent further analysis in subsequent processing of the
27175 -- current list of declarations
27176
27177 Set_Analyzed (New_Prag);
27178 end if;
27179
27180 Prag := Next_Pragma (Prag);
27181 end loop;
27182
27183 if Installed then
27184 In_Spec_Expression := In_Spec_Expr;
27185 End_Scope;
27186 end if;
27187 end if;
27188 end Collect_Inherited_Class_Wide_Conditions;
27189
27190 ---------------------------------------
27191 -- Collect_Subprogram_Inputs_Outputs --
27192 ---------------------------------------
27193
27194 procedure Collect_Subprogram_Inputs_Outputs
27195 (Subp_Id : Entity_Id;
27196 Synthesize : Boolean := False;
27197 Subp_Inputs : in out Elist_Id;
27198 Subp_Outputs : in out Elist_Id;
27199 Global_Seen : out Boolean)
27200 is
27201 procedure Collect_Dependency_Clause (Clause : Node_Id);
27202 -- Collect all relevant items from a dependency clause
27203
27204 procedure Collect_Global_List
27205 (List : Node_Id;
27206 Mode : Name_Id := Name_Input);
27207 -- Collect all relevant items from a global list
27208
27209 -------------------------------
27210 -- Collect_Dependency_Clause --
27211 -------------------------------
27212
27213 procedure Collect_Dependency_Clause (Clause : Node_Id) is
27214 procedure Collect_Dependency_Item
27215 (Item : Node_Id;
27216 Is_Input : Boolean);
27217 -- Add an item to the proper subprogram input or output collection
27218
27219 -----------------------------
27220 -- Collect_Dependency_Item --
27221 -----------------------------
27222
27223 procedure Collect_Dependency_Item
27224 (Item : Node_Id;
27225 Is_Input : Boolean)
27226 is
27227 Extra : Node_Id;
27228
27229 begin
27230 -- Nothing to collect when the item is null
27231
27232 if Nkind (Item) = N_Null then
27233 null;
27234
27235 -- Ditto for attribute 'Result
27236
27237 elsif Is_Attribute_Result (Item) then
27238 null;
27239
27240 -- Multiple items appear as an aggregate
27241
27242 elsif Nkind (Item) = N_Aggregate then
27243 Extra := First (Expressions (Item));
27244 while Present (Extra) loop
27245 Collect_Dependency_Item (Extra, Is_Input);
27246 Next (Extra);
27247 end loop;
27248
27249 -- Otherwise this is a solitary item
27250
27251 else
27252 if Is_Input then
27253 Append_New_Elmt (Item, Subp_Inputs);
27254 else
27255 Append_New_Elmt (Item, Subp_Outputs);
27256 end if;
27257 end if;
27258 end Collect_Dependency_Item;
27259
27260 -- Start of processing for Collect_Dependency_Clause
27261
27262 begin
27263 if Nkind (Clause) = N_Null then
27264 null;
27265
27266 -- A dependency cause appears as component association
27267
27268 elsif Nkind (Clause) = N_Component_Association then
27269 Collect_Dependency_Item
27270 (Item => Expression (Clause),
27271 Is_Input => True);
27272
27273 Collect_Dependency_Item
27274 (Item => First (Choices (Clause)),
27275 Is_Input => False);
27276
27277 -- To accomodate partial decoration of disabled SPARK features, this
27278 -- routine may be called with illegal input. If this is the case, do
27279 -- not raise Program_Error.
27280
27281 else
27282 null;
27283 end if;
27284 end Collect_Dependency_Clause;
27285
27286 -------------------------
27287 -- Collect_Global_List --
27288 -------------------------
27289
27290 procedure Collect_Global_List
27291 (List : Node_Id;
27292 Mode : Name_Id := Name_Input)
27293 is
27294 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
27295 -- Add an item to the proper subprogram input or output collection
27296
27297 -------------------------
27298 -- Collect_Global_Item --
27299 -------------------------
27300
27301 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
27302 begin
27303 if Nam_In (Mode, Name_In_Out, Name_Input) then
27304 Append_New_Elmt (Item, Subp_Inputs);
27305 end if;
27306
27307 if Nam_In (Mode, Name_In_Out, Name_Output) then
27308 Append_New_Elmt (Item, Subp_Outputs);
27309 end if;
27310 end Collect_Global_Item;
27311
27312 -- Local variables
27313
27314 Assoc : Node_Id;
27315 Item : Node_Id;
27316
27317 -- Start of processing for Collect_Global_List
27318
27319 begin
27320 if Nkind (List) = N_Null then
27321 null;
27322
27323 -- Single global item declaration
27324
27325 elsif Nkind_In (List, N_Expanded_Name,
27326 N_Identifier,
27327 N_Selected_Component)
27328 then
27329 Collect_Global_Item (List, Mode);
27330
27331 -- Simple global list or moded global list declaration
27332
27333 elsif Nkind (List) = N_Aggregate then
27334 if Present (Expressions (List)) then
27335 Item := First (Expressions (List));
27336 while Present (Item) loop
27337 Collect_Global_Item (Item, Mode);
27338 Next (Item);
27339 end loop;
27340
27341 else
27342 Assoc := First (Component_Associations (List));
27343 while Present (Assoc) loop
27344 Collect_Global_List
27345 (List => Expression (Assoc),
27346 Mode => Chars (First (Choices (Assoc))));
27347 Next (Assoc);
27348 end loop;
27349 end if;
27350
27351 -- To accomodate partial decoration of disabled SPARK features, this
27352 -- routine may be called with illegal input. If this is the case, do
27353 -- not raise Program_Error.
27354
27355 else
27356 null;
27357 end if;
27358 end Collect_Global_List;
27359
27360 -- Local variables
27361
27362 Clause : Node_Id;
27363 Clauses : Node_Id;
27364 Depends : Node_Id;
27365 Formal : Entity_Id;
27366 Global : Node_Id;
27367 Spec_Id : Entity_Id;
27368 Subp_Decl : Node_Id;
27369 Typ : Entity_Id;
27370
27371 -- Start of processing for Collect_Subprogram_Inputs_Outputs
27372
27373 begin
27374 Global_Seen := False;
27375
27376 -- Process all formal parameters of entries, [generic] subprograms, and
27377 -- their bodies.
27378
27379 if Ekind_In (Subp_Id, E_Entry,
27380 E_Entry_Family,
27381 E_Function,
27382 E_Generic_Function,
27383 E_Generic_Procedure,
27384 E_Procedure,
27385 E_Subprogram_Body)
27386 then
27387 Subp_Decl := Unit_Declaration_Node (Subp_Id);
27388 Spec_Id := Unique_Defining_Entity (Subp_Decl);
27389
27390 -- Process all [generic] formal parameters
27391
27392 Formal := First_Entity (Spec_Id);
27393 while Present (Formal) loop
27394 if Ekind_In (Formal, E_Generic_In_Parameter,
27395 E_In_Out_Parameter,
27396 E_In_Parameter)
27397 then
27398 Append_New_Elmt (Formal, Subp_Inputs);
27399 end if;
27400
27401 if Ekind_In (Formal, E_Generic_In_Out_Parameter,
27402 E_In_Out_Parameter,
27403 E_Out_Parameter)
27404 then
27405 Append_New_Elmt (Formal, Subp_Outputs);
27406
27407 -- Out parameters can act as inputs when the related type is
27408 -- tagged, unconstrained array, unconstrained record, or record
27409 -- with unconstrained components.
27410
27411 if Ekind (Formal) = E_Out_Parameter
27412 and then Is_Unconstrained_Or_Tagged_Item (Formal)
27413 then
27414 Append_New_Elmt (Formal, Subp_Inputs);
27415 end if;
27416 end if;
27417
27418 Next_Entity (Formal);
27419 end loop;
27420
27421 -- Otherwise the input denotes a task type, a task body, or the
27422 -- anonymous object created for a single task type.
27423
27424 elsif Ekind_In (Subp_Id, E_Task_Type, E_Task_Body)
27425 or else Is_Single_Task_Object (Subp_Id)
27426 then
27427 Subp_Decl := Declaration_Node (Subp_Id);
27428 Spec_Id := Unique_Defining_Entity (Subp_Decl);
27429 end if;
27430
27431 -- When processing an entry, subprogram or task body, look for pragmas
27432 -- Refined_Depends and Refined_Global as they specify the inputs and
27433 -- outputs.
27434
27435 if Is_Entry_Body (Subp_Id)
27436 or else Ekind_In (Subp_Id, E_Subprogram_Body, E_Task_Body)
27437 then
27438 Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends);
27439 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
27440
27441 -- Subprogram declaration or stand alone body case, look for pragmas
27442 -- Depends and Global
27443
27444 else
27445 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
27446 Global := Get_Pragma (Spec_Id, Pragma_Global);
27447 end if;
27448
27449 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
27450 -- because it provides finer granularity of inputs and outputs.
27451
27452 if Present (Global) then
27453 Global_Seen := True;
27454 Collect_Global_List (Expression (Get_Argument (Global, Spec_Id)));
27455
27456 -- When the related subprogram lacks pragma [Refined_]Global, fall back
27457 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
27458 -- the inputs and outputs from [Refined_]Depends.
27459
27460 elsif Synthesize and then Present (Depends) then
27461 Clauses := Expression (Get_Argument (Depends, Spec_Id));
27462
27463 -- Multiple dependency clauses appear as an aggregate
27464
27465 if Nkind (Clauses) = N_Aggregate then
27466 Clause := First (Component_Associations (Clauses));
27467 while Present (Clause) loop
27468 Collect_Dependency_Clause (Clause);
27469 Next (Clause);
27470 end loop;
27471
27472 -- Otherwise this is a single dependency clause
27473
27474 else
27475 Collect_Dependency_Clause (Clauses);
27476 end if;
27477 end if;
27478
27479 -- The current instance of a protected type acts as a formal parameter
27480 -- of mode IN for functions and IN OUT for entries and procedures
27481 -- (SPARK RM 6.1.4).
27482
27483 if Ekind (Scope (Spec_Id)) = E_Protected_Type then
27484 Typ := Scope (Spec_Id);
27485
27486 -- Use the anonymous object when the type is single protected
27487
27488 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
27489 Typ := Anonymous_Object (Typ);
27490 end if;
27491
27492 Append_New_Elmt (Typ, Subp_Inputs);
27493
27494 if Ekind_In (Spec_Id, E_Entry, E_Entry_Family, E_Procedure) then
27495 Append_New_Elmt (Typ, Subp_Outputs);
27496 end if;
27497
27498 -- The current instance of a task type acts as a formal parameter of
27499 -- mode IN OUT (SPARK RM 6.1.4).
27500
27501 elsif Ekind (Spec_Id) = E_Task_Type then
27502 Typ := Spec_Id;
27503
27504 -- Use the anonymous object when the type is single task
27505
27506 if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then
27507 Typ := Anonymous_Object (Typ);
27508 end if;
27509
27510 Append_New_Elmt (Typ, Subp_Inputs);
27511 Append_New_Elmt (Typ, Subp_Outputs);
27512
27513 elsif Is_Single_Task_Object (Spec_Id) then
27514 Append_New_Elmt (Spec_Id, Subp_Inputs);
27515 Append_New_Elmt (Spec_Id, Subp_Outputs);
27516 end if;
27517 end Collect_Subprogram_Inputs_Outputs;
27518
27519 ---------------------------
27520 -- Contract_Freeze_Error --
27521 ---------------------------
27522
27523 procedure Contract_Freeze_Error
27524 (Contract_Id : Entity_Id;
27525 Freeze_Id : Entity_Id)
27526 is
27527 begin
27528 Error_Msg_Name_1 := Chars (Contract_Id);
27529 Error_Msg_Sloc := Sloc (Freeze_Id);
27530
27531 SPARK_Msg_NE
27532 ("body & declared # freezes the contract of%", Contract_Id, Freeze_Id);
27533 SPARK_Msg_N
27534 ("\all contractual items must be declared before body #", Contract_Id);
27535 end Contract_Freeze_Error;
27536
27537 ---------------------------------
27538 -- Delay_Config_Pragma_Analyze --
27539 ---------------------------------
27540
27541 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
27542 begin
27543 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
27544 Name_Priority_Specific_Dispatching);
27545 end Delay_Config_Pragma_Analyze;
27546
27547 -----------------------
27548 -- Duplication_Error --
27549 -----------------------
27550
27551 procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is
27552 Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag);
27553 Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev);
27554
27555 begin
27556 Error_Msg_Sloc := Sloc (Prev);
27557 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag);
27558
27559 -- Emit a precise message to distinguish between source pragmas and
27560 -- pragmas generated from aspects. The ordering of the two pragmas is
27561 -- the following:
27562
27563 -- Prev -- ok
27564 -- Prag -- duplicate
27565
27566 -- No error is emitted when both pragmas come from aspects because this
27567 -- is already detected by the general aspect analysis mechanism.
27568
27569 if Prag_From_Asp and Prev_From_Asp then
27570 null;
27571 elsif Prag_From_Asp then
27572 Error_Msg_N ("aspect % duplicates pragma declared #", Prag);
27573 elsif Prev_From_Asp then
27574 Error_Msg_N ("pragma % duplicates aspect declared #", Prag);
27575 else
27576 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
27577 end if;
27578 end Duplication_Error;
27579
27580 --------------------------
27581 -- Find_Related_Context --
27582 --------------------------
27583
27584 function Find_Related_Context
27585 (Prag : Node_Id;
27586 Do_Checks : Boolean := False) return Node_Id
27587 is
27588 Stmt : Node_Id;
27589
27590 begin
27591 Stmt := Prev (Prag);
27592 while Present (Stmt) loop
27593
27594 -- Skip prior pragmas, but check for duplicates
27595
27596 if Nkind (Stmt) = N_Pragma then
27597 if Do_Checks and then Pragma_Name (Stmt) = Pragma_Name (Prag) then
27598 Duplication_Error
27599 (Prag => Prag,
27600 Prev => Stmt);
27601 end if;
27602
27603 -- Skip internally generated code
27604
27605 elsif not Comes_From_Source (Stmt) then
27606
27607 -- The anonymous object created for a single concurrent type is a
27608 -- suitable context.
27609
27610 if Nkind (Stmt) = N_Object_Declaration
27611 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
27612 then
27613 return Stmt;
27614 end if;
27615
27616 -- Return the current source construct
27617
27618 else
27619 return Stmt;
27620 end if;
27621
27622 Prev (Stmt);
27623 end loop;
27624
27625 return Empty;
27626 end Find_Related_Context;
27627
27628 --------------------------------------
27629 -- Find_Related_Declaration_Or_Body --
27630 --------------------------------------
27631
27632 function Find_Related_Declaration_Or_Body
27633 (Prag : Node_Id;
27634 Do_Checks : Boolean := False) return Node_Id
27635 is
27636 Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag);
27637
27638 procedure Expression_Function_Error;
27639 -- Emit an error concerning pragma Prag that illegaly applies to an
27640 -- expression function.
27641
27642 -------------------------------
27643 -- Expression_Function_Error --
27644 -------------------------------
27645
27646 procedure Expression_Function_Error is
27647 begin
27648 Error_Msg_Name_1 := Prag_Nam;
27649
27650 -- Emit a precise message to distinguish between source pragmas and
27651 -- pragmas generated from aspects.
27652
27653 if From_Aspect_Specification (Prag) then
27654 Error_Msg_N
27655 ("aspect % cannot apply to a stand alone expression function",
27656 Prag);
27657 else
27658 Error_Msg_N
27659 ("pragma % cannot apply to a stand alone expression function",
27660 Prag);
27661 end if;
27662 end Expression_Function_Error;
27663
27664 -- Local variables
27665
27666 Context : constant Node_Id := Parent (Prag);
27667 Stmt : Node_Id;
27668
27669 Look_For_Body : constant Boolean :=
27670 Nam_In (Prag_Nam, Name_Refined_Depends,
27671 Name_Refined_Global,
27672 Name_Refined_Post);
27673 -- Refinement pragmas must be associated with a subprogram body [stub]
27674
27675 -- Start of processing for Find_Related_Declaration_Or_Body
27676
27677 begin
27678 Stmt := Prev (Prag);
27679 while Present (Stmt) loop
27680
27681 -- Skip prior pragmas, but check for duplicates. Pragmas produced
27682 -- by splitting a complex pre/postcondition are not considered to
27683 -- be duplicates.
27684
27685 if Nkind (Stmt) = N_Pragma then
27686 if Do_Checks
27687 and then not Split_PPC (Stmt)
27688 and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam
27689 then
27690 Duplication_Error
27691 (Prag => Prag,
27692 Prev => Stmt);
27693 end if;
27694
27695 -- Emit an error when a refinement pragma appears on an expression
27696 -- function without a completion.
27697
27698 elsif Do_Checks
27699 and then Look_For_Body
27700 and then Nkind (Stmt) = N_Subprogram_Declaration
27701 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
27702 and then not Has_Completion (Defining_Entity (Stmt))
27703 then
27704 Expression_Function_Error;
27705 return Empty;
27706
27707 -- The refinement pragma applies to a subprogram body stub
27708
27709 elsif Look_For_Body
27710 and then Nkind (Stmt) = N_Subprogram_Body_Stub
27711 then
27712 return Stmt;
27713
27714 -- Skip internally generated code
27715
27716 elsif not Comes_From_Source (Stmt) then
27717
27718 -- The anonymous object created for a single concurrent type is a
27719 -- suitable context.
27720
27721 if Nkind (Stmt) = N_Object_Declaration
27722 and then Is_Single_Concurrent_Object (Defining_Entity (Stmt))
27723 then
27724 return Stmt;
27725
27726 elsif Nkind (Stmt) = N_Subprogram_Declaration then
27727
27728 -- The subprogram declaration is an internally generated spec
27729 -- for an expression function.
27730
27731 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
27732 return Stmt;
27733
27734 -- The subprogram is actually an instance housed within an
27735 -- anonymous wrapper package.
27736
27737 elsif Present (Generic_Parent (Specification (Stmt))) then
27738 return Stmt;
27739 end if;
27740 end if;
27741
27742 -- Return the current construct which is either a subprogram body,
27743 -- a subprogram declaration or is illegal.
27744
27745 else
27746 return Stmt;
27747 end if;
27748
27749 Prev (Stmt);
27750 end loop;
27751
27752 -- If we fall through, then the pragma was either the first declaration
27753 -- or it was preceded by other pragmas and no source constructs.
27754
27755 -- The pragma is associated with a library-level subprogram
27756
27757 if Nkind (Context) = N_Compilation_Unit_Aux then
27758 return Unit (Parent (Context));
27759
27760 -- The pragma appears inside the declarations of an entry body
27761
27762 elsif Nkind (Context) = N_Entry_Body then
27763 return Context;
27764
27765 -- The pragma appears inside the statements of a subprogram body. This
27766 -- placement is the result of subprogram contract expansion.
27767
27768 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
27769 return Parent (Context);
27770
27771 -- The pragma appears inside the declarative part of a subprogram body
27772
27773 elsif Nkind (Context) = N_Subprogram_Body then
27774 return Context;
27775
27776 -- The pragma appears inside the declarative part of a task body
27777
27778 elsif Nkind (Context) = N_Task_Body then
27779 return Context;
27780
27781 -- The pragma is a byproduct of aspect expansion, return the related
27782 -- context of the original aspect. This case has a lower priority as
27783 -- the above circuitry pinpoints precisely the related context.
27784
27785 elsif Present (Corresponding_Aspect (Prag)) then
27786 return Parent (Corresponding_Aspect (Prag));
27787
27788 -- No candidate subprogram [body] found
27789
27790 else
27791 return Empty;
27792 end if;
27793 end Find_Related_Declaration_Or_Body;
27794
27795 ----------------------------------
27796 -- Find_Related_Package_Or_Body --
27797 ----------------------------------
27798
27799 function Find_Related_Package_Or_Body
27800 (Prag : Node_Id;
27801 Do_Checks : Boolean := False) return Node_Id
27802 is
27803 Context : constant Node_Id := Parent (Prag);
27804 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
27805 Stmt : Node_Id;
27806
27807 begin
27808 Stmt := Prev (Prag);
27809 while Present (Stmt) loop
27810
27811 -- Skip prior pragmas, but check for duplicates
27812
27813 if Nkind (Stmt) = N_Pragma then
27814 if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then
27815 Duplication_Error
27816 (Prag => Prag,
27817 Prev => Stmt);
27818 end if;
27819
27820 -- Skip internally generated code
27821
27822 elsif not Comes_From_Source (Stmt) then
27823 if Nkind (Stmt) = N_Subprogram_Declaration then
27824
27825 -- The subprogram declaration is an internally generated spec
27826 -- for an expression function.
27827
27828 if Nkind (Original_Node (Stmt)) = N_Expression_Function then
27829 return Stmt;
27830
27831 -- The subprogram is actually an instance housed within an
27832 -- anonymous wrapper package.
27833
27834 elsif Present (Generic_Parent (Specification (Stmt))) then
27835 return Stmt;
27836 end if;
27837 end if;
27838
27839 -- Return the current source construct which is illegal
27840
27841 else
27842 return Stmt;
27843 end if;
27844
27845 Prev (Stmt);
27846 end loop;
27847
27848 -- If we fall through, then the pragma was either the first declaration
27849 -- or it was preceded by other pragmas and no source constructs.
27850
27851 -- The pragma is associated with a package. The immediate context in
27852 -- this case is the specification of the package.
27853
27854 if Nkind (Context) = N_Package_Specification then
27855 return Parent (Context);
27856
27857 -- The pragma appears in the declarations of a package body
27858
27859 elsif Nkind (Context) = N_Package_Body then
27860 return Context;
27861
27862 -- The pragma appears in the statements of a package body
27863
27864 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
27865 and then Nkind (Parent (Context)) = N_Package_Body
27866 then
27867 return Parent (Context);
27868
27869 -- The pragma is a byproduct of aspect expansion, return the related
27870 -- context of the original aspect. This case has a lower priority as
27871 -- the above circuitry pinpoints precisely the related context.
27872
27873 elsif Present (Corresponding_Aspect (Prag)) then
27874 return Parent (Corresponding_Aspect (Prag));
27875
27876 -- No candidate packge [body] found
27877
27878 else
27879 return Empty;
27880 end if;
27881 end Find_Related_Package_Or_Body;
27882
27883 ------------------
27884 -- Get_Argument --
27885 ------------------
27886
27887 function Get_Argument
27888 (Prag : Node_Id;
27889 Context_Id : Entity_Id := Empty) return Node_Id
27890 is
27891 Args : constant List_Id := Pragma_Argument_Associations (Prag);
27892
27893 begin
27894 -- Use the expression of the original aspect when compiling for ASIS or
27895 -- when analyzing the template of a generic unit. In both cases the
27896 -- aspect's tree must be decorated to allow for ASIS queries or to save
27897 -- the global references in the generic context.
27898
27899 if From_Aspect_Specification (Prag)
27900 and then (ASIS_Mode or else (Present (Context_Id)
27901 and then Is_Generic_Unit (Context_Id)))
27902 then
27903 return Corresponding_Aspect (Prag);
27904
27905 -- Otherwise use the expression of the pragma
27906
27907 elsif Present (Args) then
27908 return First (Args);
27909
27910 else
27911 return Empty;
27912 end if;
27913 end Get_Argument;
27914
27915 -------------------------
27916 -- Get_Base_Subprogram --
27917 -------------------------
27918
27919 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
27920 Result : Entity_Id;
27921
27922 begin
27923 -- Follow subprogram renaming chain
27924
27925 Result := Def_Id;
27926
27927 if Is_Subprogram (Result)
27928 and then
27929 Nkind (Parent (Declaration_Node (Result))) =
27930 N_Subprogram_Renaming_Declaration
27931 and then Present (Alias (Result))
27932 then
27933 Result := Alias (Result);
27934 end if;
27935
27936 return Result;
27937 end Get_Base_Subprogram;
27938
27939 -----------------------
27940 -- Get_SPARK_Mode_Type --
27941 -----------------------
27942
27943 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
27944 begin
27945 if N = Name_On then
27946 return On;
27947 elsif N = Name_Off then
27948 return Off;
27949
27950 -- Any other argument is illegal
27951
27952 else
27953 raise Program_Error;
27954 end if;
27955 end Get_SPARK_Mode_Type;
27956
27957 ------------------------------------
27958 -- Get_SPARK_Mode_From_Annotation --
27959 ------------------------------------
27960
27961 function Get_SPARK_Mode_From_Annotation
27962 (N : Node_Id) return SPARK_Mode_Type
27963 is
27964 Mode : Node_Id;
27965
27966 begin
27967 if Nkind (N) = N_Aspect_Specification then
27968 Mode := Expression (N);
27969
27970 else pragma Assert (Nkind (N) = N_Pragma);
27971 Mode := First (Pragma_Argument_Associations (N));
27972
27973 if Present (Mode) then
27974 Mode := Get_Pragma_Arg (Mode);
27975 end if;
27976 end if;
27977
27978 -- Aspect or pragma SPARK_Mode specifies an explicit mode
27979
27980 if Present (Mode) then
27981 if Nkind (Mode) = N_Identifier then
27982 return Get_SPARK_Mode_Type (Chars (Mode));
27983
27984 -- In case of a malformed aspect or pragma, return the default None
27985
27986 else
27987 return None;
27988 end if;
27989
27990 -- Otherwise the lack of an expression defaults SPARK_Mode to On
27991
27992 else
27993 return On;
27994 end if;
27995 end Get_SPARK_Mode_From_Annotation;
27996
27997 ---------------------------
27998 -- Has_Extra_Parentheses --
27999 ---------------------------
28000
28001 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
28002 Expr : Node_Id;
28003
28004 begin
28005 -- The aggregate should not have an expression list because a clause
28006 -- is always interpreted as a component association. The only way an
28007 -- expression list can sneak in is by adding extra parentheses around
28008 -- the individual clauses:
28009
28010 -- Depends (Output => Input) -- proper form
28011 -- Depends ((Output => Input)) -- extra parentheses
28012
28013 -- Since the extra parentheses are not allowed by the syntax of the
28014 -- pragma, flag them now to avoid emitting misleading errors down the
28015 -- line.
28016
28017 if Nkind (Clause) = N_Aggregate
28018 and then Present (Expressions (Clause))
28019 then
28020 Expr := First (Expressions (Clause));
28021 while Present (Expr) loop
28022
28023 -- A dependency clause surrounded by extra parentheses appears
28024 -- as an aggregate of component associations with an optional
28025 -- Paren_Count set.
28026
28027 if Nkind (Expr) = N_Aggregate
28028 and then Present (Component_Associations (Expr))
28029 then
28030 SPARK_Msg_N
28031 ("dependency clause contains extra parentheses", Expr);
28032
28033 -- Otherwise the expression is a malformed construct
28034
28035 else
28036 SPARK_Msg_N ("malformed dependency clause", Expr);
28037 end if;
28038
28039 Next (Expr);
28040 end loop;
28041
28042 return True;
28043 end if;
28044
28045 return False;
28046 end Has_Extra_Parentheses;
28047
28048 ----------------
28049 -- Initialize --
28050 ----------------
28051
28052 procedure Initialize is
28053 begin
28054 Externals.Init;
28055 end Initialize;
28056
28057 --------
28058 -- ip --
28059 --------
28060
28061 procedure ip is
28062 begin
28063 Dummy := Dummy + 1;
28064 end ip;
28065
28066 -----------------------------
28067 -- Is_Config_Static_String --
28068 -----------------------------
28069
28070 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
28071
28072 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
28073 -- This is an internal recursive function that is just like the outer
28074 -- function except that it adds the string to the name buffer rather
28075 -- than placing the string in the name buffer.
28076
28077 ------------------------------
28078 -- Add_Config_Static_String --
28079 ------------------------------
28080
28081 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
28082 N : Node_Id;
28083 C : Char_Code;
28084
28085 begin
28086 N := Arg;
28087
28088 if Nkind (N) = N_Op_Concat then
28089 if Add_Config_Static_String (Left_Opnd (N)) then
28090 N := Right_Opnd (N);
28091 else
28092 return False;
28093 end if;
28094 end if;
28095
28096 if Nkind (N) /= N_String_Literal then
28097 Error_Msg_N ("string literal expected for pragma argument", N);
28098 return False;
28099
28100 else
28101 for J in 1 .. String_Length (Strval (N)) loop
28102 C := Get_String_Char (Strval (N), J);
28103
28104 if not In_Character_Range (C) then
28105 Error_Msg
28106 ("string literal contains invalid wide character",
28107 Sloc (N) + 1 + Source_Ptr (J));
28108 return False;
28109 end if;
28110
28111 Add_Char_To_Name_Buffer (Get_Character (C));
28112 end loop;
28113 end if;
28114
28115 return True;
28116 end Add_Config_Static_String;
28117
28118 -- Start of processing for Is_Config_Static_String
28119
28120 begin
28121 Name_Len := 0;
28122
28123 return Add_Config_Static_String (Arg);
28124 end Is_Config_Static_String;
28125
28126 ---------------------
28127 -- Is_CCT_Instance --
28128 ---------------------
28129
28130 function Is_CCT_Instance
28131 (Ref_Id : Entity_Id;
28132 Context_Id : Entity_Id) return Boolean
28133 is
28134 S : Entity_Id;
28135 Typ : Entity_Id;
28136
28137 begin
28138 -- When the reference denotes a single protected type, the context is
28139 -- either a protected subprogram or its body.
28140
28141 if Is_Single_Protected_Object (Ref_Id) then
28142 Typ := Scope (Context_Id);
28143
28144 return
28145 Ekind (Typ) = E_Protected_Type
28146 and then Present (Anonymous_Object (Typ))
28147 and then Anonymous_Object (Typ) = Ref_Id;
28148
28149 -- When the reference denotes a single task type, the context is either
28150 -- the same type or if inside the body, the anonymous task type.
28151
28152 elsif Is_Single_Task_Object (Ref_Id) then
28153 if Ekind (Context_Id) = E_Task_Type then
28154 return
28155 Present (Anonymous_Object (Context_Id))
28156 and then Anonymous_Object (Context_Id) = Ref_Id;
28157 else
28158 return Ref_Id = Context_Id;
28159 end if;
28160
28161 -- Otherwise the reference denotes a protected or a task type. Climb the
28162 -- scope chain looking for an enclosing concurrent type that matches the
28163 -- referenced entity.
28164
28165 else
28166 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
28167
28168 S := Current_Scope;
28169 while Present (S) and then S /= Standard_Standard loop
28170 if Ekind_In (S, E_Protected_Type, E_Task_Type)
28171 and then S = Ref_Id
28172 then
28173 return True;
28174 end if;
28175
28176 S := Scope (S);
28177 end loop;
28178 end if;
28179
28180 return False;
28181 end Is_CCT_Instance;
28182
28183 -------------------------------
28184 -- Is_Elaboration_SPARK_Mode --
28185 -------------------------------
28186
28187 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
28188 begin
28189 pragma Assert
28190 (Nkind (N) = N_Pragma
28191 and then Pragma_Name (N) = Name_SPARK_Mode
28192 and then Is_List_Member (N));
28193
28194 -- Pragma SPARK_Mode affects the elaboration of a package body when it
28195 -- appears in the statement part of the body.
28196
28197 return
28198 Present (Parent (N))
28199 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
28200 and then List_Containing (N) = Statements (Parent (N))
28201 and then Present (Parent (Parent (N)))
28202 and then Nkind (Parent (Parent (N))) = N_Package_Body;
28203 end Is_Elaboration_SPARK_Mode;
28204
28205 -----------------------
28206 -- Is_Enabled_Pragma --
28207 -----------------------
28208
28209 function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is
28210 Arg : Node_Id;
28211
28212 begin
28213 if Present (Prag) then
28214 Arg := First (Pragma_Argument_Associations (Prag));
28215
28216 if Present (Arg) then
28217 return Is_True (Expr_Value (Get_Pragma_Arg (Arg)));
28218
28219 -- The lack of a Boolean argument automatically enables the pragma
28220
28221 else
28222 return True;
28223 end if;
28224
28225 -- The pragma is missing, therefore it is not enabled
28226
28227 else
28228 return False;
28229 end if;
28230 end Is_Enabled_Pragma;
28231
28232 -----------------------------------------
28233 -- Is_Non_Significant_Pragma_Reference --
28234 -----------------------------------------
28235
28236 -- This function makes use of the following static table which indicates
28237 -- whether appearance of some name in a given pragma is to be considered
28238 -- as a reference for the purposes of warnings about unreferenced objects.
28239
28240 -- -1 indicates that appearence in any argument is significant
28241 -- 0 indicates that appearance in any argument is not significant
28242 -- +n indicates that appearance as argument n is significant, but all
28243 -- other arguments are not significant
28244 -- 9n arguments from n on are significant, before n insignificant
28245
28246 Sig_Flags : constant array (Pragma_Id) of Int :=
28247 (Pragma_Abort_Defer => -1,
28248 Pragma_Abstract_State => -1,
28249 Pragma_Ada_83 => -1,
28250 Pragma_Ada_95 => -1,
28251 Pragma_Ada_05 => -1,
28252 Pragma_Ada_2005 => -1,
28253 Pragma_Ada_12 => -1,
28254 Pragma_Ada_2012 => -1,
28255 Pragma_All_Calls_Remote => -1,
28256 Pragma_Allow_Integer_Address => -1,
28257 Pragma_Annotate => 93,
28258 Pragma_Assert => -1,
28259 Pragma_Assert_And_Cut => -1,
28260 Pragma_Assertion_Policy => 0,
28261 Pragma_Assume => -1,
28262 Pragma_Assume_No_Invalid_Values => 0,
28263 Pragma_Async_Readers => 0,
28264 Pragma_Async_Writers => 0,
28265 Pragma_Asynchronous => 0,
28266 Pragma_Atomic => 0,
28267 Pragma_Atomic_Components => 0,
28268 Pragma_Attach_Handler => -1,
28269 Pragma_Attribute_Definition => 92,
28270 Pragma_Check => -1,
28271 Pragma_Check_Float_Overflow => 0,
28272 Pragma_Check_Name => 0,
28273 Pragma_Check_Policy => 0,
28274 Pragma_CPP_Class => 0,
28275 Pragma_CPP_Constructor => 0,
28276 Pragma_CPP_Virtual => 0,
28277 Pragma_CPP_Vtable => 0,
28278 Pragma_CPU => -1,
28279 Pragma_C_Pass_By_Copy => 0,
28280 Pragma_Comment => -1,
28281 Pragma_Common_Object => 0,
28282 Pragma_Compile_Time_Error => -1,
28283 Pragma_Compile_Time_Warning => -1,
28284 Pragma_Compiler_Unit => -1,
28285 Pragma_Compiler_Unit_Warning => -1,
28286 Pragma_Complete_Representation => 0,
28287 Pragma_Complex_Representation => 0,
28288 Pragma_Component_Alignment => 0,
28289 Pragma_Constant_After_Elaboration => 0,
28290 Pragma_Contract_Cases => -1,
28291 Pragma_Controlled => 0,
28292 Pragma_Convention => 0,
28293 Pragma_Convention_Identifier => 0,
28294 Pragma_Debug => -1,
28295 Pragma_Debug_Policy => 0,
28296 Pragma_Detect_Blocking => 0,
28297 Pragma_Default_Initial_Condition => -1,
28298 Pragma_Default_Scalar_Storage_Order => 0,
28299 Pragma_Default_Storage_Pool => 0,
28300 Pragma_Depends => -1,
28301 Pragma_Disable_Atomic_Synchronization => 0,
28302 Pragma_Discard_Names => 0,
28303 Pragma_Dispatching_Domain => -1,
28304 Pragma_Effective_Reads => 0,
28305 Pragma_Effective_Writes => 0,
28306 Pragma_Elaborate => 0,
28307 Pragma_Elaborate_All => 0,
28308 Pragma_Elaborate_Body => 0,
28309 Pragma_Elaboration_Checks => 0,
28310 Pragma_Eliminate => 0,
28311 Pragma_Enable_Atomic_Synchronization => 0,
28312 Pragma_Export => -1,
28313 Pragma_Export_Function => -1,
28314 Pragma_Export_Object => -1,
28315 Pragma_Export_Procedure => -1,
28316 Pragma_Export_Value => -1,
28317 Pragma_Export_Valued_Procedure => -1,
28318 Pragma_Extend_System => -1,
28319 Pragma_Extensions_Allowed => 0,
28320 Pragma_Extensions_Visible => 0,
28321 Pragma_External => -1,
28322 Pragma_Favor_Top_Level => 0,
28323 Pragma_External_Name_Casing => 0,
28324 Pragma_Fast_Math => 0,
28325 Pragma_Finalize_Storage_Only => 0,
28326 Pragma_Ghost => 0,
28327 Pragma_Global => -1,
28328 Pragma_Ident => -1,
28329 Pragma_Ignore_Pragma => 0,
28330 Pragma_Implementation_Defined => -1,
28331 Pragma_Implemented => -1,
28332 Pragma_Implicit_Packing => 0,
28333 Pragma_Import => 93,
28334 Pragma_Import_Function => 0,
28335 Pragma_Import_Object => 0,
28336 Pragma_Import_Procedure => 0,
28337 Pragma_Import_Valued_Procedure => 0,
28338 Pragma_Independent => 0,
28339 Pragma_Independent_Components => 0,
28340 Pragma_Initial_Condition => -1,
28341 Pragma_Initialize_Scalars => 0,
28342 Pragma_Initializes => -1,
28343 Pragma_Inline => 0,
28344 Pragma_Inline_Always => 0,
28345 Pragma_Inline_Generic => 0,
28346 Pragma_Inspection_Point => -1,
28347 Pragma_Interface => 92,
28348 Pragma_Interface_Name => 0,
28349 Pragma_Interrupt_Handler => -1,
28350 Pragma_Interrupt_Priority => -1,
28351 Pragma_Interrupt_State => -1,
28352 Pragma_Invariant => -1,
28353 Pragma_Keep_Names => 0,
28354 Pragma_License => 0,
28355 Pragma_Link_With => -1,
28356 Pragma_Linker_Alias => -1,
28357 Pragma_Linker_Constructor => -1,
28358 Pragma_Linker_Destructor => -1,
28359 Pragma_Linker_Options => -1,
28360 Pragma_Linker_Section => 0,
28361 Pragma_List => 0,
28362 Pragma_Lock_Free => 0,
28363 Pragma_Locking_Policy => 0,
28364 Pragma_Loop_Invariant => -1,
28365 Pragma_Loop_Optimize => 0,
28366 Pragma_Loop_Variant => -1,
28367 Pragma_Machine_Attribute => -1,
28368 Pragma_Main => -1,
28369 Pragma_Main_Storage => -1,
28370 Pragma_Memory_Size => 0,
28371 Pragma_No_Return => 0,
28372 Pragma_No_Body => 0,
28373 Pragma_No_Elaboration_Code_All => 0,
28374 Pragma_No_Inline => 0,
28375 Pragma_No_Run_Time => -1,
28376 Pragma_No_Strict_Aliasing => -1,
28377 Pragma_No_Tagged_Streams => 0,
28378 Pragma_Normalize_Scalars => 0,
28379 Pragma_Obsolescent => 0,
28380 Pragma_Optimize => 0,
28381 Pragma_Optimize_Alignment => 0,
28382 Pragma_Overflow_Mode => 0,
28383 Pragma_Overriding_Renamings => 0,
28384 Pragma_Ordered => 0,
28385 Pragma_Pack => 0,
28386 Pragma_Page => 0,
28387 Pragma_Part_Of => 0,
28388 Pragma_Partition_Elaboration_Policy => 0,
28389 Pragma_Passive => 0,
28390 Pragma_Persistent_BSS => 0,
28391 Pragma_Polling => 0,
28392 Pragma_Prefix_Exception_Messages => 0,
28393 Pragma_Post => -1,
28394 Pragma_Postcondition => -1,
28395 Pragma_Post_Class => -1,
28396 Pragma_Pre => -1,
28397 Pragma_Precondition => -1,
28398 Pragma_Predicate => -1,
28399 Pragma_Predicate_Failure => -1,
28400 Pragma_Preelaborable_Initialization => -1,
28401 Pragma_Preelaborate => 0,
28402 Pragma_Pre_Class => -1,
28403 Pragma_Priority => -1,
28404 Pragma_Priority_Specific_Dispatching => 0,
28405 Pragma_Profile => 0,
28406 Pragma_Profile_Warnings => 0,
28407 Pragma_Propagate_Exceptions => 0,
28408 Pragma_Provide_Shift_Operators => 0,
28409 Pragma_Psect_Object => 0,
28410 Pragma_Pure => 0,
28411 Pragma_Pure_Function => 0,
28412 Pragma_Queuing_Policy => 0,
28413 Pragma_Rational => 0,
28414 Pragma_Ravenscar => 0,
28415 Pragma_Refined_Depends => -1,
28416 Pragma_Refined_Global => -1,
28417 Pragma_Refined_Post => -1,
28418 Pragma_Refined_State => -1,
28419 Pragma_Relative_Deadline => 0,
28420 Pragma_Remote_Access_Type => -1,
28421 Pragma_Remote_Call_Interface => -1,
28422 Pragma_Remote_Types => -1,
28423 Pragma_Restricted_Run_Time => 0,
28424 Pragma_Restriction_Warnings => 0,
28425 Pragma_Restrictions => 0,
28426 Pragma_Reviewable => -1,
28427 Pragma_Short_Circuit_And_Or => 0,
28428 Pragma_Share_Generic => 0,
28429 Pragma_Shared => 0,
28430 Pragma_Shared_Passive => 0,
28431 Pragma_Short_Descriptors => 0,
28432 Pragma_Simple_Storage_Pool_Type => 0,
28433 Pragma_Source_File_Name => 0,
28434 Pragma_Source_File_Name_Project => 0,
28435 Pragma_Source_Reference => 0,
28436 Pragma_SPARK_Mode => 0,
28437 Pragma_Storage_Size => -1,
28438 Pragma_Storage_Unit => 0,
28439 Pragma_Static_Elaboration_Desired => 0,
28440 Pragma_Stream_Convert => 0,
28441 Pragma_Style_Checks => 0,
28442 Pragma_Subtitle => 0,
28443 Pragma_Suppress => 0,
28444 Pragma_Suppress_Exception_Locations => 0,
28445 Pragma_Suppress_All => 0,
28446 Pragma_Suppress_Debug_Info => 0,
28447 Pragma_Suppress_Initialization => 0,
28448 Pragma_System_Name => 0,
28449 Pragma_Task_Dispatching_Policy => 0,
28450 Pragma_Task_Info => -1,
28451 Pragma_Task_Name => -1,
28452 Pragma_Task_Storage => -1,
28453 Pragma_Test_Case => -1,
28454 Pragma_Thread_Local_Storage => -1,
28455 Pragma_Time_Slice => -1,
28456 Pragma_Title => 0,
28457 Pragma_Type_Invariant => -1,
28458 Pragma_Type_Invariant_Class => -1,
28459 Pragma_Unchecked_Union => 0,
28460 Pragma_Unimplemented_Unit => 0,
28461 Pragma_Universal_Aliasing => 0,
28462 Pragma_Universal_Data => 0,
28463 Pragma_Unmodified => 0,
28464 Pragma_Unreferenced => 0,
28465 Pragma_Unreferenced_Objects => 0,
28466 Pragma_Unreserve_All_Interrupts => 0,
28467 Pragma_Unsuppress => 0,
28468 Pragma_Unevaluated_Use_Of_Old => 0,
28469 Pragma_Use_VADS_Size => 0,
28470 Pragma_Validity_Checks => 0,
28471 Pragma_Volatile => 0,
28472 Pragma_Volatile_Components => 0,
28473 Pragma_Volatile_Full_Access => 0,
28474 Pragma_Volatile_Function => 0,
28475 Pragma_Warning_As_Error => 0,
28476 Pragma_Warnings => 0,
28477 Pragma_Weak_External => 0,
28478 Pragma_Wide_Character_Encoding => 0,
28479 Unknown_Pragma => 0);
28480
28481 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
28482 Id : Pragma_Id;
28483 P : Node_Id;
28484 C : Int;
28485 AN : Nat;
28486
28487 function Arg_No return Nat;
28488 -- Returns an integer showing what argument we are in. A value of
28489 -- zero means we are not in any of the arguments.
28490
28491 ------------
28492 -- Arg_No --
28493 ------------
28494
28495 function Arg_No return Nat is
28496 A : Node_Id;
28497 N : Nat;
28498
28499 begin
28500 A := First (Pragma_Argument_Associations (Parent (P)));
28501 N := 1;
28502 loop
28503 if No (A) then
28504 return 0;
28505 elsif A = P then
28506 return N;
28507 end if;
28508
28509 Next (A);
28510 N := N + 1;
28511 end loop;
28512 end Arg_No;
28513
28514 -- Start of processing for Non_Significant_Pragma_Reference
28515
28516 begin
28517 P := Parent (N);
28518
28519 if Nkind (P) /= N_Pragma_Argument_Association then
28520 return False;
28521
28522 else
28523 Id := Get_Pragma_Id (Parent (P));
28524 C := Sig_Flags (Id);
28525 AN := Arg_No;
28526
28527 if AN = 0 then
28528 return False;
28529 end if;
28530
28531 case C is
28532 when -1 =>
28533 return False;
28534
28535 when 0 =>
28536 return True;
28537
28538 when 92 .. 99 =>
28539 return AN < (C - 90);
28540
28541 when others =>
28542 return AN /= C;
28543 end case;
28544 end if;
28545 end Is_Non_Significant_Pragma_Reference;
28546
28547 ------------------------------
28548 -- Is_Pragma_String_Literal --
28549 ------------------------------
28550
28551 -- This function returns true if the corresponding pragma argument is a
28552 -- static string expression. These are the only cases in which string
28553 -- literals can appear as pragma arguments. We also allow a string literal
28554 -- as the first argument to pragma Assert (although it will of course
28555 -- always generate a type error).
28556
28557 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
28558 Pragn : constant Node_Id := Parent (Par);
28559 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
28560 Pname : constant Name_Id := Pragma_Name (Pragn);
28561 Argn : Natural;
28562 N : Node_Id;
28563
28564 begin
28565 Argn := 1;
28566 N := First (Assoc);
28567 loop
28568 exit when N = Par;
28569 Argn := Argn + 1;
28570 Next (N);
28571 end loop;
28572
28573 if Pname = Name_Assert then
28574 return True;
28575
28576 elsif Pname = Name_Export then
28577 return Argn > 2;
28578
28579 elsif Pname = Name_Ident then
28580 return Argn = 1;
28581
28582 elsif Pname = Name_Import then
28583 return Argn > 2;
28584
28585 elsif Pname = Name_Interface_Name then
28586 return Argn > 1;
28587
28588 elsif Pname = Name_Linker_Alias then
28589 return Argn = 2;
28590
28591 elsif Pname = Name_Linker_Section then
28592 return Argn = 2;
28593
28594 elsif Pname = Name_Machine_Attribute then
28595 return Argn = 2;
28596
28597 elsif Pname = Name_Source_File_Name then
28598 return True;
28599
28600 elsif Pname = Name_Source_Reference then
28601 return Argn = 2;
28602
28603 elsif Pname = Name_Title then
28604 return True;
28605
28606 elsif Pname = Name_Subtitle then
28607 return True;
28608
28609 else
28610 return False;
28611 end if;
28612 end Is_Pragma_String_Literal;
28613
28614 ---------------------------
28615 -- Is_Private_SPARK_Mode --
28616 ---------------------------
28617
28618 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
28619 begin
28620 pragma Assert
28621 (Nkind (N) = N_Pragma
28622 and then Pragma_Name (N) = Name_SPARK_Mode
28623 and then Is_List_Member (N));
28624
28625 -- For pragma SPARK_Mode to be private, it has to appear in the private
28626 -- declarations of a package.
28627
28628 return
28629 Present (Parent (N))
28630 and then Nkind (Parent (N)) = N_Package_Specification
28631 and then List_Containing (N) = Private_Declarations (Parent (N));
28632 end Is_Private_SPARK_Mode;
28633
28634 -------------------------------------
28635 -- Is_Unconstrained_Or_Tagged_Item --
28636 -------------------------------------
28637
28638 function Is_Unconstrained_Or_Tagged_Item
28639 (Item : Entity_Id) return Boolean
28640 is
28641 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
28642 -- Determine whether record type Typ has at least one unconstrained
28643 -- component.
28644
28645 ---------------------------------
28646 -- Has_Unconstrained_Component --
28647 ---------------------------------
28648
28649 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
28650 Comp : Entity_Id;
28651
28652 begin
28653 Comp := First_Component (Typ);
28654 while Present (Comp) loop
28655 if Is_Unconstrained_Or_Tagged_Item (Comp) then
28656 return True;
28657 end if;
28658
28659 Next_Component (Comp);
28660 end loop;
28661
28662 return False;
28663 end Has_Unconstrained_Component;
28664
28665 -- Local variables
28666
28667 Typ : constant Entity_Id := Etype (Item);
28668
28669 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
28670
28671 begin
28672 if Is_Tagged_Type (Typ) then
28673 return True;
28674
28675 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
28676 return True;
28677
28678 elsif Is_Record_Type (Typ) then
28679 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
28680 return True;
28681 else
28682 return Has_Unconstrained_Component (Typ);
28683 end if;
28684
28685 elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
28686 return True;
28687
28688 else
28689 return False;
28690 end if;
28691 end Is_Unconstrained_Or_Tagged_Item;
28692
28693 -----------------------------
28694 -- Is_Valid_Assertion_Kind --
28695 -----------------------------
28696
28697 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
28698 begin
28699 case Nam is
28700 when
28701 -- RM defined
28702
28703 Name_Assert |
28704 Name_Assertion_Policy |
28705 Name_Static_Predicate |
28706 Name_Dynamic_Predicate |
28707 Name_Pre |
28708 Name_uPre |
28709 Name_Post |
28710 Name_uPost |
28711 Name_Type_Invariant |
28712 Name_uType_Invariant |
28713
28714 -- Impl defined
28715
28716 Name_Assert_And_Cut |
28717 Name_Assume |
28718 Name_Contract_Cases |
28719 Name_Debug |
28720 Name_Default_Initial_Condition |
28721 Name_Ghost |
28722 Name_Initial_Condition |
28723 Name_Invariant |
28724 Name_uInvariant |
28725 Name_Loop_Invariant |
28726 Name_Loop_Variant |
28727 Name_Postcondition |
28728 Name_Precondition |
28729 Name_Predicate |
28730 Name_Refined_Post |
28731 Name_Statement_Assertions => return True;
28732
28733 when others => return False;
28734 end case;
28735 end Is_Valid_Assertion_Kind;
28736
28737 --------------------------------------
28738 -- Process_Compilation_Unit_Pragmas --
28739 --------------------------------------
28740
28741 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
28742 begin
28743 -- A special check for pragma Suppress_All, a very strange DEC pragma,
28744 -- strange because it comes at the end of the unit. Rational has the
28745 -- same name for a pragma, but treats it as a program unit pragma, In
28746 -- GNAT we just decide to allow it anywhere at all. If it appeared then
28747 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
28748 -- node, and we insert a pragma Suppress (All_Checks) at the start of
28749 -- the context clause to ensure the correct processing.
28750
28751 if Has_Pragma_Suppress_All (N) then
28752 Prepend_To (Context_Items (N),
28753 Make_Pragma (Sloc (N),
28754 Chars => Name_Suppress,
28755 Pragma_Argument_Associations => New_List (
28756 Make_Pragma_Argument_Association (Sloc (N),
28757 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
28758 end if;
28759
28760 -- Nothing else to do at the current time
28761
28762 end Process_Compilation_Unit_Pragmas;
28763
28764 ------------------------------------
28765 -- Record_Possible_Body_Reference --
28766 ------------------------------------
28767
28768 procedure Record_Possible_Body_Reference
28769 (State_Id : Entity_Id;
28770 Ref : Node_Id)
28771 is
28772 Context : Node_Id;
28773 Spec_Id : Entity_Id;
28774
28775 begin
28776 -- Ensure that we are dealing with a reference to a state
28777
28778 pragma Assert (Ekind (State_Id) = E_Abstract_State);
28779
28780 -- Climb the tree starting from the reference looking for a package body
28781 -- whose spec declares the referenced state. This criteria automatically
28782 -- excludes references in package specs which are legal. Note that it is
28783 -- not wise to emit an error now as the package body may lack pragma
28784 -- Refined_State or the referenced state may not be mentioned in the
28785 -- refinement. This approach avoids the generation of misleading errors.
28786
28787 Context := Ref;
28788 while Present (Context) loop
28789 if Nkind (Context) = N_Package_Body then
28790 Spec_Id := Corresponding_Spec (Context);
28791
28792 if Present (Abstract_States (Spec_Id))
28793 and then Contains (Abstract_States (Spec_Id), State_Id)
28794 then
28795 if No (Body_References (State_Id)) then
28796 Set_Body_References (State_Id, New_Elmt_List);
28797 end if;
28798
28799 Append_Elmt (Ref, To => Body_References (State_Id));
28800 exit;
28801 end if;
28802 end if;
28803
28804 Context := Parent (Context);
28805 end loop;
28806 end Record_Possible_Body_Reference;
28807
28808 ------------------------------------------
28809 -- Relocate_Pragmas_To_Anonymous_Object --
28810 ------------------------------------------
28811
28812 procedure Relocate_Pragmas_To_Anonymous_Object
28813 (Typ_Decl : Node_Id;
28814 Obj_Decl : Node_Id)
28815 is
28816 Decl : Node_Id;
28817 Def : Node_Id;
28818 Next_Decl : Node_Id;
28819
28820 begin
28821 if Nkind (Typ_Decl) = N_Protected_Type_Declaration then
28822 Def := Protected_Definition (Typ_Decl);
28823 else
28824 pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration);
28825 Def := Task_Definition (Typ_Decl);
28826 end if;
28827
28828 -- The concurrent definition has a visible declaration list. Inspect it
28829 -- and relocate all canidate pragmas.
28830
28831 if Present (Def) and then Present (Visible_Declarations (Def)) then
28832 Decl := First (Visible_Declarations (Def));
28833 while Present (Decl) loop
28834
28835 -- Preserve the following declaration for iteration purposes due
28836 -- to possible relocation of a pragma.
28837
28838 Next_Decl := Next (Decl);
28839
28840 if Nkind (Decl) = N_Pragma
28841 and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl))
28842 then
28843 Remove (Decl);
28844 Insert_After (Obj_Decl, Decl);
28845
28846 -- Skip internally generated code
28847
28848 elsif not Comes_From_Source (Decl) then
28849 null;
28850
28851 -- No candidate pragmas are available for relocation
28852
28853 else
28854 exit;
28855 end if;
28856
28857 Decl := Next_Decl;
28858 end loop;
28859 end if;
28860 end Relocate_Pragmas_To_Anonymous_Object;
28861
28862 ------------------------------
28863 -- Relocate_Pragmas_To_Body --
28864 ------------------------------
28865
28866 procedure Relocate_Pragmas_To_Body
28867 (Subp_Body : Node_Id;
28868 Target_Body : Node_Id := Empty)
28869 is
28870 procedure Relocate_Pragma (Prag : Node_Id);
28871 -- Remove a single pragma from its current list and add it to the
28872 -- declarations of the proper body (either Subp_Body or Target_Body).
28873
28874 ---------------------
28875 -- Relocate_Pragma --
28876 ---------------------
28877
28878 procedure Relocate_Pragma (Prag : Node_Id) is
28879 Decls : List_Id;
28880 Target : Node_Id;
28881
28882 begin
28883 -- When subprogram stubs or expression functions are involves, the
28884 -- destination declaration list belongs to the proper body.
28885
28886 if Present (Target_Body) then
28887 Target := Target_Body;
28888 else
28889 Target := Subp_Body;
28890 end if;
28891
28892 Decls := Declarations (Target);
28893
28894 if No (Decls) then
28895 Decls := New_List;
28896 Set_Declarations (Target, Decls);
28897 end if;
28898
28899 -- Unhook the pragma from its current list
28900
28901 Remove (Prag);
28902 Prepend (Prag, Decls);
28903 end Relocate_Pragma;
28904
28905 -- Local variables
28906
28907 Body_Id : constant Entity_Id :=
28908 Defining_Unit_Name (Specification (Subp_Body));
28909 Next_Stmt : Node_Id;
28910 Stmt : Node_Id;
28911
28912 -- Start of processing for Relocate_Pragmas_To_Body
28913
28914 begin
28915 -- Do not process a body that comes from a separate unit as no construct
28916 -- can possibly follow it.
28917
28918 if not Is_List_Member (Subp_Body) then
28919 return;
28920
28921 -- Do not relocate pragmas that follow a stub if the stub does not have
28922 -- a proper body.
28923
28924 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
28925 and then No (Target_Body)
28926 then
28927 return;
28928
28929 -- Do not process internally generated routine _Postconditions
28930
28931 elsif Ekind (Body_Id) = E_Procedure
28932 and then Chars (Body_Id) = Name_uPostconditions
28933 then
28934 return;
28935 end if;
28936
28937 -- Look at what is following the body. We are interested in certain kind
28938 -- of pragmas (either from source or byproducts of expansion) that can
28939 -- apply to a body [stub].
28940
28941 Stmt := Next (Subp_Body);
28942 while Present (Stmt) loop
28943
28944 -- Preserve the following statement for iteration purposes due to a
28945 -- possible relocation of a pragma.
28946
28947 Next_Stmt := Next (Stmt);
28948
28949 -- Move a candidate pragma following the body to the declarations of
28950 -- the body.
28951
28952 if Nkind (Stmt) = N_Pragma
28953 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
28954 then
28955 Relocate_Pragma (Stmt);
28956
28957 -- Skip internally generated code
28958
28959 elsif not Comes_From_Source (Stmt) then
28960 null;
28961
28962 -- No candidate pragmas are available for relocation
28963
28964 else
28965 exit;
28966 end if;
28967
28968 Stmt := Next_Stmt;
28969 end loop;
28970 end Relocate_Pragmas_To_Body;
28971
28972 -------------------
28973 -- Resolve_State --
28974 -------------------
28975
28976 procedure Resolve_State (N : Node_Id) is
28977 Func : Entity_Id;
28978 State : Entity_Id;
28979
28980 begin
28981 if Is_Entity_Name (N) and then Present (Entity (N)) then
28982 Func := Entity (N);
28983
28984 -- Handle overloading of state names by functions. Traverse the
28985 -- homonym chain looking for an abstract state.
28986
28987 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
28988 State := Homonym (Func);
28989 while Present (State) loop
28990
28991 -- Resolve the overloading by setting the proper entity of the
28992 -- reference to that of the state.
28993
28994 if Ekind (State) = E_Abstract_State then
28995 Set_Etype (N, Standard_Void_Type);
28996 Set_Entity (N, State);
28997 Set_Associated_Node (N, State);
28998 return;
28999 end if;
29000
29001 State := Homonym (State);
29002 end loop;
29003
29004 -- A function can never act as a state. If the homonym chain does
29005 -- not contain a corresponding state, then something went wrong in
29006 -- the overloading mechanism.
29007
29008 raise Program_Error;
29009 end if;
29010 end if;
29011 end Resolve_State;
29012
29013 ----------------------------
29014 -- Rewrite_Assertion_Kind --
29015 ----------------------------
29016
29017 procedure Rewrite_Assertion_Kind (N : Node_Id) is
29018 Nam : Name_Id;
29019
29020 begin
29021 if Nkind (N) = N_Attribute_Reference
29022 and then Attribute_Name (N) = Name_Class
29023 and then Nkind (Prefix (N)) = N_Identifier
29024 then
29025 case Chars (Prefix (N)) is
29026 when Name_Pre =>
29027 Nam := Name_uPre;
29028 when Name_Post =>
29029 Nam := Name_uPost;
29030 when Name_Type_Invariant =>
29031 Nam := Name_uType_Invariant;
29032 when Name_Invariant =>
29033 Nam := Name_uInvariant;
29034 when others =>
29035 return;
29036 end case;
29037
29038 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
29039 end if;
29040 end Rewrite_Assertion_Kind;
29041
29042 --------
29043 -- rv --
29044 --------
29045
29046 procedure rv is
29047 begin
29048 Dummy := Dummy + 1;
29049 end rv;
29050
29051 --------------------------------
29052 -- Set_Encoded_Interface_Name --
29053 --------------------------------
29054
29055 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
29056 Str : constant String_Id := Strval (S);
29057 Len : constant Nat := String_Length (Str);
29058 CC : Char_Code;
29059 C : Character;
29060 J : Pos;
29061
29062 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
29063
29064 procedure Encode;
29065 -- Stores encoded value of character code CC. The encoding we use an
29066 -- underscore followed by four lower case hex digits.
29067
29068 ------------
29069 -- Encode --
29070 ------------
29071
29072 procedure Encode is
29073 begin
29074 Store_String_Char (Get_Char_Code ('_'));
29075 Store_String_Char
29076 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
29077 Store_String_Char
29078 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
29079 Store_String_Char
29080 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
29081 Store_String_Char
29082 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
29083 end Encode;
29084
29085 -- Start of processing for Set_Encoded_Interface_Name
29086
29087 begin
29088 -- If first character is asterisk, this is a link name, and we leave it
29089 -- completely unmodified. We also ignore null strings (the latter case
29090 -- happens only in error cases).
29091
29092 if Len = 0
29093 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
29094 then
29095 Set_Interface_Name (E, S);
29096
29097 else
29098 J := 1;
29099 loop
29100 CC := Get_String_Char (Str, J);
29101
29102 exit when not In_Character_Range (CC);
29103
29104 C := Get_Character (CC);
29105
29106 exit when C /= '_' and then C /= '$'
29107 and then C not in '0' .. '9'
29108 and then C not in 'a' .. 'z'
29109 and then C not in 'A' .. 'Z';
29110
29111 if J = Len then
29112 Set_Interface_Name (E, S);
29113 return;
29114
29115 else
29116 J := J + 1;
29117 end if;
29118 end loop;
29119
29120 -- Here we need to encode. The encoding we use as follows:
29121 -- three underscores + four hex digits (lower case)
29122
29123 Start_String;
29124
29125 for J in 1 .. String_Length (Str) loop
29126 CC := Get_String_Char (Str, J);
29127
29128 if not In_Character_Range (CC) then
29129 Encode;
29130 else
29131 C := Get_Character (CC);
29132
29133 if C = '_' or else C = '$'
29134 or else C in '0' .. '9'
29135 or else C in 'a' .. 'z'
29136 or else C in 'A' .. 'Z'
29137 then
29138 Store_String_Char (CC);
29139 else
29140 Encode;
29141 end if;
29142 end if;
29143 end loop;
29144
29145 Set_Interface_Name (E,
29146 Make_String_Literal (Sloc (S),
29147 Strval => End_String));
29148 end if;
29149 end Set_Encoded_Interface_Name;
29150
29151 ------------------------
29152 -- Set_Elab_Unit_Name --
29153 ------------------------
29154
29155 procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is
29156 Pref : Node_Id;
29157 Scop : Entity_Id;
29158
29159 begin
29160 if Nkind (N) = N_Identifier
29161 and then Nkind (With_Item) = N_Identifier
29162 then
29163 Set_Entity (N, Entity (With_Item));
29164
29165 elsif Nkind (N) = N_Selected_Component then
29166 Change_Selected_Component_To_Expanded_Name (N);
29167 Set_Entity (N, Entity (With_Item));
29168 Set_Entity (Selector_Name (N), Entity (N));
29169
29170 Pref := Prefix (N);
29171 Scop := Scope (Entity (N));
29172 while Nkind (Pref) = N_Selected_Component loop
29173 Change_Selected_Component_To_Expanded_Name (Pref);
29174 Set_Entity (Selector_Name (Pref), Scop);
29175 Set_Entity (Pref, Scop);
29176 Pref := Prefix (Pref);
29177 Scop := Scope (Scop);
29178 end loop;
29179
29180 Set_Entity (Pref, Scop);
29181 end if;
29182
29183 Generate_Reference (Entity (With_Item), N, Set_Ref => False);
29184 end Set_Elab_Unit_Name;
29185
29186 -------------------
29187 -- Test_Case_Arg --
29188 -------------------
29189
29190 function Test_Case_Arg
29191 (Prag : Node_Id;
29192 Arg_Nam : Name_Id;
29193 From_Aspect : Boolean := False) return Node_Id
29194 is
29195 Aspect : constant Node_Id := Corresponding_Aspect (Prag);
29196 Arg : Node_Id;
29197 Args : Node_Id;
29198
29199 begin
29200 pragma Assert (Nam_In (Arg_Nam, Name_Ensures,
29201 Name_Mode,
29202 Name_Name,
29203 Name_Requires));
29204
29205 -- The caller requests the aspect argument
29206
29207 if From_Aspect then
29208 if Present (Aspect)
29209 and then Nkind (Expression (Aspect)) = N_Aggregate
29210 then
29211 Args := Expression (Aspect);
29212
29213 -- "Name" and "Mode" may appear without an identifier as a
29214 -- positional association.
29215
29216 if Present (Expressions (Args)) then
29217 Arg := First (Expressions (Args));
29218
29219 if Present (Arg) and then Arg_Nam = Name_Name then
29220 return Arg;
29221 end if;
29222
29223 -- Skip "Name"
29224
29225 Arg := Next (Arg);
29226
29227 if Present (Arg) and then Arg_Nam = Name_Mode then
29228 return Arg;
29229 end if;
29230 end if;
29231
29232 -- Some or all arguments may appear as component associatons
29233
29234 if Present (Component_Associations (Args)) then
29235 Arg := First (Component_Associations (Args));
29236 while Present (Arg) loop
29237 if Chars (First (Choices (Arg))) = Arg_Nam then
29238 return Arg;
29239 end if;
29240
29241 Next (Arg);
29242 end loop;
29243 end if;
29244 end if;
29245
29246 -- Otherwise retrieve the argument directly from the pragma
29247
29248 else
29249 Arg := First (Pragma_Argument_Associations (Prag));
29250
29251 if Present (Arg) and then Arg_Nam = Name_Name then
29252 return Arg;
29253 end if;
29254
29255 -- Skip argument "Name"
29256
29257 Arg := Next (Arg);
29258
29259 if Present (Arg) and then Arg_Nam = Name_Mode then
29260 return Arg;
29261 end if;
29262
29263 -- Skip argument "Mode"
29264
29265 Arg := Next (Arg);
29266
29267 -- Arguments "Requires" and "Ensures" are optional and may not be
29268 -- present at all.
29269
29270 while Present (Arg) loop
29271 if Chars (Arg) = Arg_Nam then
29272 return Arg;
29273 end if;
29274
29275 Next (Arg);
29276 end loop;
29277 end if;
29278
29279 return Empty;
29280 end Test_Case_Arg;
29281
29282 end Sem_Prag;