33f24075d6fc89ccd501a446aa8d15b147f0c4b9
[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-2013, 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 Csets; use Csets;
37 with Debug; use Debug;
38 with Einfo; use Einfo;
39 with Elists; use Elists;
40 with Errout; use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze; use Freeze;
44 with Lib; use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
50 with Opt; use Opt;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
56 with Sem; use Sem;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Stringt; use Stringt;
79 with Stylesw; use Stylesw;
80 with Table;
81 with Targparm; use Targparm;
82 with Tbuild; use Tbuild;
83 with Ttypes;
84 with Uintp; use Uintp;
85 with Uname; use Uname;
86 with Urealp; use Urealp;
87 with Validsw; use Validsw;
88 with Warnsw; use Warnsw;
89
90 package body Sem_Prag is
91
92 ----------------------------------------------
93 -- Common Handling of Import-Export Pragmas --
94 ----------------------------------------------
95
96 -- In the following section, a number of Import_xxx and Export_xxx pragmas
97 -- are defined by GNAT. These are compatible with the DEC pragmas of the
98 -- same name, and all have the following common form and processing:
99
100 -- pragma Export_xxx
101 -- [Internal =>] LOCAL_NAME
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
104
105 -- pragma Import_xxx
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
109
110 -- EXTERNAL_SYMBOL ::=
111 -- IDENTIFIER
112 -- | static_string_EXPRESSION
113
114 -- The internal LOCAL_NAME designates the entity that is imported or
115 -- exported, and must refer to an entity in the current declarative
116 -- part (as required by the rules for LOCAL_NAME).
117
118 -- The external linker name is designated by the External parameter if
119 -- given, or the Internal parameter if not (if there is no External
120 -- parameter, the External parameter is a copy of the Internal name).
121
122 -- If the External parameter is given as a string, then this string is
123 -- treated as an external name (exactly as though it had been given as an
124 -- External_Name parameter for a normal Import pragma).
125
126 -- If the External parameter is given as an identifier (or there is no
127 -- External parameter, so that the Internal identifier is used), then
128 -- the external name is the characters of the identifier, translated
129 -- to all upper case letters for OpenVMS versions of GNAT, and to all
130 -- lower case letters for all other versions
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 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
171 -- Subsidiary routine to the analysis of pragmas Depends, Global and
172 -- Refined_State. Append an entity to a list. If the list is empty, create
173 -- a new list.
174
175 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
176 -- This routine is used for possible casing adjustment of an explicit
177 -- external name supplied as a string literal (the node N), according to
178 -- the casing requirement of Opt.External_Name_Casing. If this is set to
179 -- As_Is, then the string literal is returned unchanged, but if it is set
180 -- to Uppercase or Lowercase, then a new string literal with appropriate
181 -- casing is constructed.
182
183 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
184 -- Subsidiary to the analysis of pragma Global and pragma Depends. Query
185 -- whether a particular item appears in a mixed list of nodes and entities.
186 -- It is assumed that all nodes in the list have entities.
187
188 function Check_Kind (Nam : Name_Id) return Name_Id;
189 -- This function is used in connection with pragmas Assert, Check,
190 -- and assertion aspects and pragmas, to determine if Check pragmas
191 -- (or corresponding assertion aspects or pragmas) are currently active
192 -- as determined by the presence of -gnata on the command line (which
193 -- sets the default), and the appearance of pragmas Check_Policy and
194 -- Assertion_Policy as configuration pragmas either in a configuration
195 -- pragma file, or at the start of the current unit, or locally given
196 -- Check_Policy and Assertion_Policy pragmas that are currently active.
197 --
198 -- The value returned is one of the names Check, Ignore, Disable (On
199 -- returns Check, and Off returns Ignore).
200 --
201 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
202 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
203 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
204 -- _Post, _Invariant, or _Type_Invariant, which are special names used
205 -- in identifiers to represent these attribute references.
206
207 procedure Collect_Global_Items
208 (Prag : Node_Id;
209 In_Items : in out Elist_Id;
210 In_Out_Items : in out Elist_Id;
211 Out_Items : in out Elist_Id;
212 Has_In_State : out Boolean;
213 Has_In_Out_State : out Boolean;
214 Has_Out_State : out Boolean;
215 Has_Null_State : out Boolean);
216 -- Subsidiary to the analysis of pragma Refined_Depends/Refined_Global.
217 -- Prag denotes pragma [Refined_]Global. Gather all input, in out and
218 -- output items of Prag in lists In_Items, In_Out_Items and Out_Items.
219 -- Flags Has_In_State, Has_In_Out_State and Has_Out_State are set when
220 -- there is at least one abstract state with visible refinement available
221 -- in the corresponding mode. Flag Has_Null_State is set when at least
222 -- state has a null refinement.
223
224 procedure Collect_Subprogram_Inputs_Outputs
225 (Subp_Id : Entity_Id;
226 Subp_Inputs : in out Elist_Id;
227 Subp_Outputs : in out Elist_Id;
228 Global_Seen : out Boolean);
229 -- Subsidiary to the analysis of pragma Depends, Global, Refined_Depends
230 -- and Refined_Global. Gather all inputs and outputs of subprogram Subp_Id
231 -- in lists Subp_Inputs and Subp_Outputs. If the case where the subprogram
232 -- has no inputs and/oroutputs, the returned list is No_Elist. Global_Seen
233 -- is set when the related subprogram has pragma [Refined_]Global.
234
235 function Find_Related_Subprogram_Or_Body
236 (Prag : Node_Id;
237 Do_Checks : Boolean := False) return Node_Id;
238 -- Subsidiary to the analysis of pragmas Contract_Cases, Depends, Global,
239 -- Refined_Depends, Refined_Global and Refined_Post. Find the declaration
240 -- of the related subprogram [body or stub] subject to pragma Prag. If flag
241 -- Do_Checks is set, the routine reports duplicate pragmas and detects
242 -- improper use of refinement pragmas in stand alone expression functions.
243 -- The returned value depends on the related pragma as follows:
244 -- 1) Pragmas Contract_Cases, Depends and Global yield the corresponding
245 -- N_Subprogram_Declaration node or if the pragma applies to a stand
246 -- alone body, the N_Subprogram_Body node or Empty if illegal.
247 -- 2) Pragmas Refined_Depends, Refined_Global and Refined_Post yield
248 -- N_Subprogram_Body or N_Subprogram_Body_Stub nodes or Empty if
249 -- illegal.
250
251 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
252 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
253 -- original one, following the renaming chain) is returned. Otherwise the
254 -- entity is returned unchanged. Should be in Einfo???
255
256 function Get_SPARK_Mode_Id (N : Name_Id) return SPARK_Mode_Id;
257 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
258 -- Get_SPARK_Mode_Id. Convert a name into a corresponding value of type
259 -- SPARK_Mode_Id.
260
261 function Is_Part_Of
262 (State : Entity_Id;
263 Ancestor : Entity_Id) return Boolean;
264 -- Subsidiary to the processing of pragma Refined_Depends and pragma
265 -- Refined_Global. Determine whether abstract state State is part of an
266 -- ancestor abstract state Ancestor. For this relationship to hold, State
267 -- must have option Part_Of in its Abstract_State definition.
268
269 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
270 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
271 -- pragma Depends. Determine whether the type of dependency item Item is
272 -- tagged, unconstrained array, unconstrained record or a record with at
273 -- least one unconstrained component.
274
275 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
276 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
277 -- of a Test_Case pragma if present (possibly Empty). We treat these as
278 -- spec expressions (i.e. similar to a default expression).
279
280 procedure Record_Possible_Body_Reference
281 (Item : Node_Id;
282 Item_Id : Entity_Id);
283 -- Given an entity reference (Item) and the corresponding Entity (Item_Id),
284 -- determines if we have a body reference to an abstract state, which may
285 -- be illegal if the state is refined within the body.
286
287 procedure Rewrite_Assertion_Kind (N : Node_Id);
288 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
289 -- then it is rewritten as an identifier with the corresponding special
290 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
291 -- Check, Check_Policy.
292
293 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
294 -- Place semantic information on the argument of an Elaborate/Elaborate_All
295 -- pragma. Entity name for unit and its parents is taken from item in
296 -- previous with_clause that mentions the unit.
297
298 procedure rv;
299 -- This is a dummy function called by the processing for pragma Reviewable.
300 -- It is there for assisting front end debugging. By placing a Reviewable
301 -- pragma in the source program, a breakpoint on rv catches this place in
302 -- the source, allowing convenient stepping to the point of interest.
303
304 --------------
305 -- Add_Item --
306 --------------
307
308 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
309 begin
310 if No (To_List) then
311 To_List := New_Elmt_List;
312 end if;
313
314 Append_Elmt (Item, To_List);
315 end Add_Item;
316
317 -------------------------------
318 -- Adjust_External_Name_Case --
319 -------------------------------
320
321 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
322 CC : Char_Code;
323
324 begin
325 -- Adjust case of literal if required
326
327 if Opt.External_Name_Exp_Casing = As_Is then
328 return N;
329
330 else
331 -- Copy existing string
332
333 Start_String;
334
335 -- Set proper casing
336
337 for J in 1 .. String_Length (Strval (N)) loop
338 CC := Get_String_Char (Strval (N), J);
339
340 if Opt.External_Name_Exp_Casing = Uppercase
341 and then CC >= Get_Char_Code ('a')
342 and then CC <= Get_Char_Code ('z')
343 then
344 Store_String_Char (CC - 32);
345
346 elsif Opt.External_Name_Exp_Casing = Lowercase
347 and then CC >= Get_Char_Code ('A')
348 and then CC <= Get_Char_Code ('Z')
349 then
350 Store_String_Char (CC + 32);
351
352 else
353 Store_String_Char (CC);
354 end if;
355 end loop;
356
357 return
358 Make_String_Literal (Sloc (N),
359 Strval => End_String);
360 end if;
361 end Adjust_External_Name_Case;
362
363 -----------------------------------------
364 -- Analyze_Contract_Cases_In_Decl_Part --
365 -----------------------------------------
366
367 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
368 Others_Seen : Boolean := False;
369
370 procedure Analyze_Contract_Case (CCase : Node_Id);
371 -- Verify the legality of a single contract case
372
373 ---------------------------
374 -- Analyze_Contract_Case --
375 ---------------------------
376
377 procedure Analyze_Contract_Case (CCase : Node_Id) is
378 Case_Guard : Node_Id;
379 Conseq : Node_Id;
380 Extra_Guard : Node_Id;
381
382 begin
383 if Nkind (CCase) = N_Component_Association then
384 Case_Guard := First (Choices (CCase));
385 Conseq := Expression (CCase);
386
387 -- Each contract case must have exactly one case guard
388
389 Extra_Guard := Next (Case_Guard);
390
391 if Present (Extra_Guard) then
392 Error_Msg_N
393 ("contract case may have only one case guard", Extra_Guard);
394 end if;
395
396 -- Check the placement of "others" (if available)
397
398 if Nkind (Case_Guard) = N_Others_Choice then
399 if Others_Seen then
400 Error_Msg_N
401 ("only one others choice allowed in aspect Contract_Cases",
402 Case_Guard);
403 else
404 Others_Seen := True;
405 end if;
406
407 elsif Others_Seen then
408 Error_Msg_N
409 ("others must be the last choice in aspect Contract_Cases",
410 N);
411 end if;
412
413 -- Preanalyze the case guard and consequence
414
415 if Nkind (Case_Guard) /= N_Others_Choice then
416 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
417 end if;
418
419 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
420
421 -- The contract case is malformed
422
423 else
424 Error_Msg_N ("wrong syntax in contract case", CCase);
425 end if;
426 end Analyze_Contract_Case;
427
428 -- Local variables
429
430 All_Cases : Node_Id;
431 CCase : Node_Id;
432 Subp_Decl : Node_Id;
433 Subp_Id : Entity_Id;
434
435 Restore_Scope : Boolean := False;
436 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
437
438 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
439
440 begin
441 Set_Analyzed (N);
442
443 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
444 Subp_Id := Defining_Entity (Subp_Decl);
445 All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
446
447 -- Multiple contract cases appear in aggregate form
448
449 if Nkind (All_Cases) = N_Aggregate then
450 if No (Component_Associations (All_Cases)) then
451 Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
452
453 -- Individual contract cases appear as component associations
454
455 else
456 -- Ensure that the formal parameters are visible when analyzing
457 -- all clauses. This falls out of the general rule of aspects
458 -- pertaining to subprogram declarations. Skip the installation
459 -- for subprogram bodies because the formals are already visible.
460
461 if not In_Open_Scopes (Subp_Id) then
462 Restore_Scope := True;
463 Push_Scope (Subp_Id);
464 Install_Formals (Subp_Id);
465 end if;
466
467 CCase := First (Component_Associations (All_Cases));
468 while Present (CCase) loop
469 Analyze_Contract_Case (CCase);
470 Next (CCase);
471 end loop;
472
473 if Restore_Scope then
474 End_Scope;
475 end if;
476 end if;
477
478 else
479 Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
480 end if;
481 end Analyze_Contract_Cases_In_Decl_Part;
482
483 ----------------------------------
484 -- Analyze_Depends_In_Decl_Part --
485 ----------------------------------
486
487 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
488 Loc : constant Source_Ptr := Sloc (N);
489
490 All_Inputs_Seen : Elist_Id := No_Elist;
491 -- A list containing the entities of all the inputs processed so far.
492 -- The list is populated with unique entities because the same input
493 -- may appear in multiple input lists.
494
495 All_Outputs_Seen : Elist_Id := No_Elist;
496 -- A list containing the entities of all the outputs processed so far.
497 -- The list is populated with unique entities because output items are
498 -- unique in a dependence relation.
499
500 Global_Seen : Boolean := False;
501 -- A flag set when pragma Global has been processed
502
503 Null_Output_Seen : Boolean := False;
504 -- A flag used to track the legality of a null output
505
506 Result_Seen : Boolean := False;
507 -- A flag set when Subp_Id'Result is processed
508
509 Spec_Id : Entity_Id;
510 -- The entity of the subprogram subject to pragma [Refined_]Depends
511
512 Subp_Id : Entity_Id;
513 -- The entity of the subprogram [body or stub] subject to pragma
514 -- [Refined_]Depends.
515
516 Subp_Inputs : Elist_Id := No_Elist;
517 Subp_Outputs : Elist_Id := No_Elist;
518 -- Two lists containing the full set of inputs and output of the related
519 -- subprograms. Note that these lists contain both nodes and entities.
520
521 procedure Analyze_Dependency_Clause
522 (Clause : Node_Id;
523 Is_Last : Boolean);
524 -- Verify the legality of a single dependency clause. Flag Is_Last
525 -- denotes whether Clause is the last clause in the relation.
526
527 procedure Check_Function_Return;
528 -- Verify that Funtion'Result appears as one of the outputs
529
530 procedure Check_Mode
531 (Item : Node_Id;
532 Item_Id : Entity_Id;
533 Is_Input : Boolean;
534 Self_Ref : Boolean);
535 -- Ensure that an item has a proper IN, IN OUT, or OUT mode depending
536 -- on its function. If this is not the case, emit an error. Item and
537 -- Item_Id denote the attributes of an item. Flag Is_Input should be set
538 -- when item comes from an input list. Flag Self_Ref should be set when
539 -- the item is an output and the dependency clause has operator "+".
540
541 procedure Check_Usage
542 (Subp_Items : Elist_Id;
543 Used_Items : Elist_Id;
544 Is_Input : Boolean);
545 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
546 -- error if this is not the case.
547
548 procedure Normalize_Clause (Clause : Node_Id);
549 -- Remove a self-dependency "+" from the input list of a clause. Split
550 -- a clause with multiple outputs into multiple clauses with a single
551 -- output.
552
553 -------------------------------
554 -- Analyze_Dependency_Clause --
555 -------------------------------
556
557 procedure Analyze_Dependency_Clause
558 (Clause : Node_Id;
559 Is_Last : Boolean)
560 is
561 procedure Analyze_Input_List (Inputs : Node_Id);
562 -- Verify the legality of a single input list
563
564 procedure Analyze_Input_Output
565 (Item : Node_Id;
566 Is_Input : Boolean;
567 Self_Ref : Boolean;
568 Top_Level : Boolean;
569 Seen : in out Elist_Id;
570 Null_Seen : in out Boolean;
571 Non_Null_Seen : in out Boolean);
572 -- Verify the legality of a single input or output item. Flag
573 -- Is_Input should be set whenever Item is an input, False when it
574 -- denotes an output. Flag Self_Ref should be set when the item is an
575 -- output and the dependency clause has a "+". Flag Top_Level should
576 -- be set whenever Item appears immediately within an input or output
577 -- list. Seen is a collection of all abstract states, variables and
578 -- formals processed so far. Flag Null_Seen denotes whether a null
579 -- input or output has been encountered. Flag Non_Null_Seen denotes
580 -- whether a non-null input or output has been encountered.
581
582 ------------------------
583 -- Analyze_Input_List --
584 ------------------------
585
586 procedure Analyze_Input_List (Inputs : Node_Id) is
587 Inputs_Seen : Elist_Id := No_Elist;
588 -- A list containing the entities of all inputs that appear in the
589 -- current input list.
590
591 Non_Null_Input_Seen : Boolean := False;
592 Null_Input_Seen : Boolean := False;
593 -- Flags used to check the legality of an input list
594
595 Input : Node_Id;
596
597 begin
598 -- Multiple inputs appear as an aggregate
599
600 if Nkind (Inputs) = N_Aggregate then
601 if Present (Component_Associations (Inputs)) then
602 Error_Msg_N
603 ("nested dependency relations not allowed", Inputs);
604
605 elsif Present (Expressions (Inputs)) then
606 Input := First (Expressions (Inputs));
607 while Present (Input) loop
608 Analyze_Input_Output
609 (Item => Input,
610 Is_Input => True,
611 Self_Ref => False,
612 Top_Level => False,
613 Seen => Inputs_Seen,
614 Null_Seen => Null_Input_Seen,
615 Non_Null_Seen => Non_Null_Input_Seen);
616
617 Next (Input);
618 end loop;
619
620 else
621 Error_Msg_N ("malformed input dependency list", Inputs);
622 end if;
623
624 -- Process a solitary input
625
626 else
627 Analyze_Input_Output
628 (Item => Inputs,
629 Is_Input => True,
630 Self_Ref => False,
631 Top_Level => False,
632 Seen => Inputs_Seen,
633 Null_Seen => Null_Input_Seen,
634 Non_Null_Seen => Non_Null_Input_Seen);
635 end if;
636
637 -- Detect an illegal dependency clause of the form
638
639 -- (null =>[+] null)
640
641 if Null_Output_Seen and then Null_Input_Seen then
642 Error_Msg_N
643 ("null dependency clause cannot have a null input list",
644 Inputs);
645 end if;
646 end Analyze_Input_List;
647
648 --------------------------
649 -- Analyze_Input_Output --
650 --------------------------
651
652 procedure Analyze_Input_Output
653 (Item : Node_Id;
654 Is_Input : Boolean;
655 Self_Ref : Boolean;
656 Top_Level : Boolean;
657 Seen : in out Elist_Id;
658 Null_Seen : in out Boolean;
659 Non_Null_Seen : in out Boolean)
660 is
661 Is_Output : constant Boolean := not Is_Input;
662 Grouped : Node_Id;
663 Item_Id : Entity_Id;
664
665 begin
666 -- Multiple input or output items appear as an aggregate
667
668 if Nkind (Item) = N_Aggregate then
669 if not Top_Level then
670 Error_Msg_N ("nested grouping of items not allowed", Item);
671
672 elsif Present (Component_Associations (Item)) then
673 Error_Msg_N
674 ("nested dependency relations not allowed", Item);
675
676 -- Recursively analyze the grouped items
677
678 elsif Present (Expressions (Item)) then
679 Grouped := First (Expressions (Item));
680 while Present (Grouped) loop
681 Analyze_Input_Output
682 (Item => Grouped,
683 Is_Input => Is_Input,
684 Self_Ref => Self_Ref,
685 Top_Level => False,
686 Seen => Seen,
687 Null_Seen => Null_Seen,
688 Non_Null_Seen => Non_Null_Seen);
689
690 Next (Grouped);
691 end loop;
692
693 else
694 Error_Msg_N ("malformed dependency list", Item);
695 end if;
696
697 -- Process Function'Result in the context of a dependency clause
698
699 elsif Is_Attribute_Result (Item) then
700 Non_Null_Seen := True;
701
702 -- It is sufficent to analyze the prefix of 'Result in order to
703 -- establish legality of the attribute.
704
705 Analyze (Prefix (Item));
706
707 -- The prefix of 'Result must denote the function for which
708 -- pragma Depends applies.
709
710 if not Is_Entity_Name (Prefix (Item))
711 or else Ekind (Spec_Id) /= E_Function
712 or else Entity (Prefix (Item)) /= Spec_Id
713 then
714 Error_Msg_Name_1 := Name_Result;
715 Error_Msg_N
716 ("prefix of attribute % must denote the enclosing "
717 & "function", Item);
718
719 -- Function'Result is allowed to appear on the output side of a
720 -- dependency clause.
721
722 elsif Is_Input then
723 Error_Msg_N ("function result cannot act as input", Item);
724
725 elsif Null_Seen then
726 Error_Msg_N
727 ("cannot mix null and non-null dependency items", Item);
728
729 else
730 Result_Seen := True;
731 end if;
732
733 -- Detect multiple uses of null in a single dependency list or
734 -- throughout the whole relation. Verify the placement of a null
735 -- output list relative to the other clauses.
736
737 elsif Nkind (Item) = N_Null then
738 if Null_Seen then
739 Error_Msg_N
740 ("multiple null dependency relations not allowed", Item);
741
742 elsif Non_Null_Seen then
743 Error_Msg_N
744 ("cannot mix null and non-null dependency items", Item);
745
746 else
747 Null_Seen := True;
748
749 if Is_Output then
750 if not Is_Last then
751 Error_Msg_N
752 ("null output list must be the last clause in a "
753 & "dependency relation", Item);
754
755 -- Catch a useless dependence of the form:
756 -- null =>+ ...
757
758 elsif Self_Ref then
759 Error_Msg_N
760 ("useless dependence, null depends on itself", Item);
761 end if;
762 end if;
763 end if;
764
765 -- Default case
766
767 else
768 Non_Null_Seen := True;
769
770 if Null_Seen then
771 Error_Msg_N ("cannot mix null and non-null items", Item);
772 end if;
773
774 Analyze (Item);
775
776 -- Find the entity of the item. If this is a renaming, climb
777 -- the renaming chain to reach the root object. Renamings of
778 -- non-entire objects do not yield an entity (Empty).
779
780 Item_Id := Entity_Of (Item);
781
782 Record_Possible_Body_Reference (Item, Item_Id);
783
784 if Present (Item_Id) then
785 if Ekind_In (Item_Id, E_Abstract_State,
786 E_In_Parameter,
787 E_In_Out_Parameter,
788 E_Out_Parameter,
789 E_Variable)
790 then
791 -- Ensure that the item is of the correct mode depending
792 -- on its function.
793
794 Check_Mode (Item, Item_Id, Is_Input, Self_Ref);
795
796 -- Detect multiple uses of the same state, variable or
797 -- formal parameter. If this is not the case, add the
798 -- item to the list of processed relations.
799
800 if Contains (Seen, Item_Id) then
801 Error_Msg_N ("duplicate use of item", Item);
802 else
803 Add_Item (Item_Id, Seen);
804 end if;
805
806 -- Detect illegal use of an input related to a null
807 -- output. Such input items cannot appear in other
808 -- input lists.
809
810 if Is_Input
811 and then Null_Output_Seen
812 and then Contains (All_Inputs_Seen, Item_Id)
813 then
814 Error_Msg_N
815 ("input of a null output list appears in multiple "
816 & "input lists", Item);
817 end if;
818
819 -- Add an input or a self-referential output to the list
820 -- of all processed inputs.
821
822 if Is_Input or else Self_Ref then
823 Add_Item (Item_Id, All_Inputs_Seen);
824 end if;
825
826 if Ekind (Item_Id) = E_Abstract_State then
827
828 -- The state acts as a constituent of some other
829 -- state. Ensure that the other state is a proper
830 -- ancestor of the item.
831
832 if Present (Refined_State (Item_Id)) then
833 if not Is_Part_Of
834 (Item_Id, Refined_State (Item_Id))
835 then
836 Error_Msg_Name_1 :=
837 Chars (Refined_State (Item_Id));
838 Error_Msg_NE
839 ("state & is not a valid constituent of "
840 & "ancestor state %", Item, Item_Id);
841 return;
842 end if;
843
844 -- An abstract state with visible refinement cannot
845 -- appear in pragma [Refined_]Global as its place must
846 -- be taken by some of its constituents.
847
848 elsif Has_Visible_Refinement (Item_Id) then
849 Error_Msg_NE
850 ("cannot mention state & in global refinement, "
851 & "use its constituents instead", Item, Item_Id);
852 return;
853 end if;
854 end if;
855
856 -- When the item renames an entire object, replace the
857 -- item with a reference to the object.
858
859 if Present (Renamed_Object (Entity (Item))) then
860 Rewrite (Item,
861 New_Reference_To (Item_Id, Sloc (Item)));
862 Analyze (Item);
863 end if;
864
865 -- All other input/output items are illegal
866
867 else
868 Error_Msg_N
869 ("item must denote variable, state or formal "
870 & "parameter", Item);
871 end if;
872
873 -- All other input/output items are illegal
874
875 else
876 Error_Msg_N
877 ("item must denote variable, state or formal parameter",
878 Item);
879 end if;
880 end if;
881 end Analyze_Input_Output;
882
883 -- Local variables
884
885 Inputs : Node_Id;
886 Output : Node_Id;
887 Self_Ref : Boolean;
888
889 Non_Null_Output_Seen : Boolean := False;
890 -- Flag used to check the legality of an output list
891
892 -- Start of processing for Analyze_Dependency_Clause
893
894 begin
895 Inputs := Expression (Clause);
896 Self_Ref := False;
897
898 -- An input list with a self-dependency appears as operator "+" where
899 -- the actuals inputs are the right operand.
900
901 if Nkind (Inputs) = N_Op_Plus then
902 Inputs := Right_Opnd (Inputs);
903 Self_Ref := True;
904 end if;
905
906 -- Process the output_list of a dependency_clause
907
908 Output := First (Choices (Clause));
909 while Present (Output) loop
910 Analyze_Input_Output
911 (Item => Output,
912 Is_Input => False,
913 Self_Ref => Self_Ref,
914 Top_Level => True,
915 Seen => All_Outputs_Seen,
916 Null_Seen => Null_Output_Seen,
917 Non_Null_Seen => Non_Null_Output_Seen);
918
919 Next (Output);
920 end loop;
921
922 -- Process the input_list of a dependency_clause
923
924 Analyze_Input_List (Inputs);
925 end Analyze_Dependency_Clause;
926
927 ----------------------------
928 -- Check_Function_Return --
929 ----------------------------
930
931 procedure Check_Function_Return is
932 begin
933 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
934 Error_Msg_NE
935 ("result of & must appear in exactly one output list",
936 N, Spec_Id);
937 end if;
938 end Check_Function_Return;
939
940 ----------------
941 -- Check_Mode --
942 ----------------
943
944 procedure Check_Mode
945 (Item : Node_Id;
946 Item_Id : Entity_Id;
947 Is_Input : Boolean;
948 Self_Ref : Boolean)
949 is
950 begin
951 -- Input
952
953 if Is_Input then
954
955 -- IN and IN OUT parameters already have the proper mode to act
956 -- as input. OUT parameters are valid inputs only when their type
957 -- is unconstrained or tagged as their discriminants, array bouns
958 -- or tags can be read. In general, states and variables are
959 -- considered to have mode IN OUT unless they are classified by
960 -- pragma [Refined_]Global. In that case, the item must appear in
961 -- an input global list.
962
963 if (Ekind (Item_Id) = E_Out_Parameter
964 and then not Is_Unconstrained_Or_Tagged_Item (Item_Id))
965 or else
966 (Global_Seen and then not Appears_In (Subp_Inputs, Item_Id))
967 then
968 Error_Msg_NE
969 ("item & must have mode IN or `IN OUT`", Item, Item_Id);
970 end if;
971
972 -- Self-referential output
973
974 elsif Self_Ref then
975
976 -- In general, states and variables are considered to have mode
977 -- IN OUT unless they are explicitly moded by pragma [Refined_]
978 -- Global. If this is the case, then the item must appear in both
979 -- an input and output global list.
980
981 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
982 if Global_Seen
983 and then not
984 (Appears_In (Subp_Inputs, Item_Id)
985 and then
986 Appears_In (Subp_Outputs, Item_Id))
987 then
988 Error_Msg_NE
989 ("item & must have mode `IN OUT`", Item, Item_Id);
990 end if;
991
992 -- A self-referential OUT parameter of an unconstrained or tagged
993 -- type acts as an input because the discriminants, array bounds
994 -- or the tag may be read. Note that the presence of [Refined_]
995 -- Global is not significant here because the item is a parameter.
996
997 elsif Ekind (Item_Id) = E_Out_Parameter
998 and then Is_Unconstrained_Or_Tagged_Item (Item_Id)
999 then
1000 null;
1001
1002 -- The remaining cases are IN, IN OUT, and OUT parameters. To
1003 -- qualify as self-referential item, the parameter must be of
1004 -- mode IN OUT.
1005
1006 elsif Ekind (Item_Id) /= E_In_Out_Parameter then
1007 Error_Msg_NE ("item & must have mode `IN OUT`", Item, Item_Id);
1008 end if;
1009
1010 -- Output
1011
1012 -- IN OUT and OUT parameters already have the proper mode to act as
1013 -- output. In general, states and variables are considered to have
1014 -- mode IN OUT unless they are moded by pragma [Refined_]Global. In
1015 -- that case, the item must appear in an output global list.
1016
1017 elsif Ekind (Item_Id) = E_In_Parameter
1018 or else
1019 (Global_Seen and then not Appears_In (Subp_Outputs, Item_Id))
1020 then
1021 Error_Msg_NE
1022 ("item & must have mode OUT or `IN OUT`", Item, Item_Id);
1023 end if;
1024 end Check_Mode;
1025
1026 -----------------
1027 -- Check_Usage --
1028 -----------------
1029
1030 procedure Check_Usage
1031 (Subp_Items : Elist_Id;
1032 Used_Items : Elist_Id;
1033 Is_Input : Boolean)
1034 is
1035 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1036 -- Emit an error concerning the erroneous usage of an item
1037
1038 -----------------
1039 -- Usage_Error --
1040 -----------------
1041
1042 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1043 begin
1044 if Is_Input then
1045 Error_Msg_NE
1046 ("item & must appear in at least one input list of aspect "
1047 & "Depends", Item, Item_Id);
1048 else
1049 Error_Msg_NE
1050 ("item & must appear in exactly one output list of aspect "
1051 & "Depends", Item, Item_Id);
1052 end if;
1053 end Usage_Error;
1054
1055 -- Local variables
1056
1057 Elmt : Elmt_Id;
1058 Item : Node_Id;
1059 Item_Id : Entity_Id;
1060
1061 -- Start of processing for Check_Usage
1062
1063 begin
1064 if No (Subp_Items) then
1065 return;
1066 end if;
1067
1068 -- Each input or output of the subprogram must appear in a dependency
1069 -- relation.
1070
1071 Elmt := First_Elmt (Subp_Items);
1072 while Present (Elmt) loop
1073 Item := Node (Elmt);
1074
1075 if Nkind (Item) = N_Defining_Identifier then
1076 Item_Id := Item;
1077 else
1078 Item_Id := Entity (Item);
1079 end if;
1080
1081 -- The item does not appear in a dependency
1082
1083 if not Contains (Used_Items, Item_Id) then
1084 if Is_Formal (Item_Id) then
1085 Usage_Error (Item, Item_Id);
1086
1087 -- States and global variables are not used properly only when
1088 -- the subprogram is subject to pragma Global.
1089
1090 elsif Global_Seen then
1091 Usage_Error (Item, Item_Id);
1092 end if;
1093 end if;
1094
1095 Next_Elmt (Elmt);
1096 end loop;
1097 end Check_Usage;
1098
1099 ----------------------
1100 -- Normalize_Clause --
1101 ----------------------
1102
1103 procedure Normalize_Clause (Clause : Node_Id) is
1104 procedure Create_Or_Modify_Clause
1105 (Output : Node_Id;
1106 Outputs : Node_Id;
1107 Inputs : Node_Id;
1108 After : Node_Id;
1109 In_Place : Boolean;
1110 Multiple : Boolean);
1111 -- Create a brand new clause to represent the self-reference or
1112 -- modify the input and/or output lists of an existing clause. Output
1113 -- denotes a self-referencial output. Outputs is the output list of a
1114 -- clause. Inputs is the input list of a clause. After denotes the
1115 -- clause after which the new clause is to be inserted. Flag In_Place
1116 -- should be set when normalizing the last output of an output list.
1117 -- Flag Multiple should be set when Output comes from a list with
1118 -- multiple items.
1119
1120 procedure Split_Multiple_Outputs;
1121 -- If Clause contains more than one output, split the clause into
1122 -- multiple clauses with a single output. All new clauses are added
1123 -- after Clause.
1124
1125 -----------------------------
1126 -- Create_Or_Modify_Clause --
1127 -----------------------------
1128
1129 procedure Create_Or_Modify_Clause
1130 (Output : Node_Id;
1131 Outputs : Node_Id;
1132 Inputs : Node_Id;
1133 After : Node_Id;
1134 In_Place : Boolean;
1135 Multiple : Boolean)
1136 is
1137 procedure Propagate_Output
1138 (Output : Node_Id;
1139 Inputs : Node_Id);
1140 -- Handle the various cases of output propagation to the input
1141 -- list. Output denotes a self-referencial output item. Inputs is
1142 -- the input list of a clause.
1143
1144 ----------------------
1145 -- Propagate_Output --
1146 ----------------------
1147
1148 procedure Propagate_Output
1149 (Output : Node_Id;
1150 Inputs : Node_Id)
1151 is
1152 function In_Input_List
1153 (Item : Entity_Id;
1154 Inputs : List_Id) return Boolean;
1155 -- Determine whether a particulat item appears in the input
1156 -- list of a clause.
1157
1158 -------------------
1159 -- In_Input_List --
1160 -------------------
1161
1162 function In_Input_List
1163 (Item : Entity_Id;
1164 Inputs : List_Id) return Boolean
1165 is
1166 Elmt : Node_Id;
1167
1168 begin
1169 Elmt := First (Inputs);
1170 while Present (Elmt) loop
1171 if Entity_Of (Elmt) = Item then
1172 return True;
1173 end if;
1174
1175 Next (Elmt);
1176 end loop;
1177
1178 return False;
1179 end In_Input_List;
1180
1181 -- Local variables
1182
1183 Output_Id : constant Entity_Id := Entity_Of (Output);
1184 Grouped : List_Id;
1185
1186 -- Start of processing for Propagate_Output
1187
1188 begin
1189 -- The clause is of the form:
1190
1191 -- (Output =>+ null)
1192
1193 -- Remove the null input and replace it with a copy of the
1194 -- output:
1195
1196 -- (Output => Output)
1197
1198 if Nkind (Inputs) = N_Null then
1199 Rewrite (Inputs, New_Copy_Tree (Output));
1200
1201 -- The clause is of the form:
1202
1203 -- (Output =>+ (Input1, ..., InputN))
1204
1205 -- Determine whether the output is not already mentioned in the
1206 -- input list and if not, add it to the list of inputs:
1207
1208 -- (Output => (Output, Input1, ..., InputN))
1209
1210 elsif Nkind (Inputs) = N_Aggregate then
1211 Grouped := Expressions (Inputs);
1212
1213 if not In_Input_List
1214 (Item => Output_Id,
1215 Inputs => Grouped)
1216 then
1217 Prepend_To (Grouped, New_Copy_Tree (Output));
1218 end if;
1219
1220 -- The clause is of the form:
1221
1222 -- (Output =>+ Input)
1223
1224 -- If the input does not mention the output, group the two
1225 -- together:
1226
1227 -- (Output => (Output, Input))
1228
1229 elsif Entity_Of (Inputs) /= Output_Id then
1230 Rewrite (Inputs,
1231 Make_Aggregate (Loc,
1232 Expressions => New_List (
1233 New_Copy_Tree (Output),
1234 New_Copy_Tree (Inputs))));
1235 end if;
1236 end Propagate_Output;
1237
1238 -- Local variables
1239
1240 Loc : constant Source_Ptr := Sloc (Clause);
1241 New_Clause : Node_Id;
1242
1243 -- Start of processing for Create_Or_Modify_Clause
1244
1245 begin
1246 -- A null output depending on itself does not require any
1247 -- normalization.
1248
1249 if Nkind (Output) = N_Null then
1250 return;
1251
1252 -- A function result cannot depend on itself because it cannot
1253 -- appear in the input list of a relation.
1254
1255 elsif Is_Attribute_Result (Output) then
1256 Error_Msg_N ("function result cannot depend on itself", Output);
1257 return;
1258 end if;
1259
1260 -- When performing the transformation in place, simply add the
1261 -- output to the list of inputs (if not already there). This case
1262 -- arises when dealing with the last output of an output list -
1263 -- we perform the normalization in place to avoid generating a
1264 -- malformed tree.
1265
1266 if In_Place then
1267 Propagate_Output (Output, Inputs);
1268
1269 -- A list with multiple outputs is slowly trimmed until only
1270 -- one element remains. When this happens, replace the
1271 -- aggregate with the element itself.
1272
1273 if Multiple then
1274 Remove (Output);
1275 Rewrite (Outputs, Output);
1276 end if;
1277
1278 -- Default case
1279
1280 else
1281 -- Unchain the output from its output list as it will appear in
1282 -- a new clause. Note that we cannot simply rewrite the output
1283 -- as null because this will violate the semantics of pragma
1284 -- Depends.
1285
1286 Remove (Output);
1287
1288 -- Generate a new clause of the form:
1289 -- (Output => Inputs)
1290
1291 New_Clause :=
1292 Make_Component_Association (Loc,
1293 Choices => New_List (Output),
1294 Expression => New_Copy_Tree (Inputs));
1295
1296 -- The new clause contains replicated content that has already
1297 -- been analyzed. There is not need to reanalyze it or
1298 -- renormalize it again.
1299
1300 Set_Analyzed (New_Clause);
1301
1302 Propagate_Output
1303 (Output => First (Choices (New_Clause)),
1304 Inputs => Expression (New_Clause));
1305
1306 Insert_After (After, New_Clause);
1307 end if;
1308 end Create_Or_Modify_Clause;
1309
1310 ----------------------------
1311 -- Split_Multiple_Outputs --
1312 ----------------------------
1313
1314 procedure Split_Multiple_Outputs is
1315 Inputs : constant Node_Id := Expression (Clause);
1316 Loc : constant Source_Ptr := Sloc (Clause);
1317 Outputs : constant Node_Id := First (Choices (Clause));
1318 Last_Output : Node_Id;
1319 Next_Output : Node_Id;
1320 Output : Node_Id;
1321 Split : Node_Id;
1322
1323 -- Start of processing for Split_Multiple_Outputs
1324
1325 begin
1326 -- Multiple outputs appear as an aggregate. Nothing to do when
1327 -- the clause has exactly one output.
1328
1329 if Nkind (Outputs) = N_Aggregate then
1330 Last_Output := Last (Expressions (Outputs));
1331
1332 -- Create a clause for each output. Note that each time a new
1333 -- clause is created, the original output list slowly shrinks
1334 -- until there is one item left.
1335
1336 Output := First (Expressions (Outputs));
1337 while Present (Output) loop
1338 Next_Output := Next (Output);
1339
1340 -- Unhook the output from the original output list as it
1341 -- will be relocated to a new clause.
1342
1343 Remove (Output);
1344
1345 -- Special processing for the last output. At this point
1346 -- the original aggregate has been stripped down to one
1347 -- element. Replace the aggregate by the element itself.
1348
1349 if Output = Last_Output then
1350 Rewrite (Outputs, Output);
1351
1352 else
1353 -- Generate a clause of the form:
1354 -- (Output => Inputs)
1355
1356 Split :=
1357 Make_Component_Association (Loc,
1358 Choices => New_List (Output),
1359 Expression => New_Copy_Tree (Inputs));
1360
1361 -- The new clause contains replicated content that has
1362 -- already been analyzed. There is not need to reanalyze
1363 -- them.
1364
1365 Set_Analyzed (Split);
1366 Insert_After (Clause, Split);
1367 end if;
1368
1369 Output := Next_Output;
1370 end loop;
1371 end if;
1372 end Split_Multiple_Outputs;
1373
1374 -- Local variables
1375
1376 Outputs : constant Node_Id := First (Choices (Clause));
1377 Inputs : Node_Id;
1378 Last_Output : Node_Id;
1379 Next_Output : Node_Id;
1380 Output : Node_Id;
1381
1382 -- Start of processing for Normalize_Clause
1383
1384 begin
1385 -- A self-dependency appears as operator "+". Remove the "+" from the
1386 -- tree by moving the real inputs to their proper place.
1387
1388 if Nkind (Expression (Clause)) = N_Op_Plus then
1389 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1390 Inputs := Expression (Clause);
1391
1392 -- Multiple outputs appear as an aggregate
1393
1394 if Nkind (Outputs) = N_Aggregate then
1395 Last_Output := Last (Expressions (Outputs));
1396
1397 Output := First (Expressions (Outputs));
1398 while Present (Output) loop
1399
1400 -- Normalization may remove an output from its list,
1401 -- preserve the subsequent output now.
1402
1403 Next_Output := Next (Output);
1404
1405 Create_Or_Modify_Clause
1406 (Output => Output,
1407 Outputs => Outputs,
1408 Inputs => Inputs,
1409 After => Clause,
1410 In_Place => Output = Last_Output,
1411 Multiple => True);
1412
1413 Output := Next_Output;
1414 end loop;
1415
1416 -- Solitary output
1417
1418 else
1419 Create_Or_Modify_Clause
1420 (Output => Outputs,
1421 Outputs => Empty,
1422 Inputs => Inputs,
1423 After => Empty,
1424 In_Place => True,
1425 Multiple => False);
1426 end if;
1427 end if;
1428
1429 -- Split a clause with multiple outputs into multiple clauses with a
1430 -- single output.
1431
1432 Split_Multiple_Outputs;
1433 end Normalize_Clause;
1434
1435 -- Local variables
1436
1437 Clause : Node_Id;
1438 Errors : Nat;
1439 Last_Clause : Node_Id;
1440 Subp_Decl : Node_Id;
1441
1442 Restore_Scope : Boolean := False;
1443 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1444
1445 -- Start of processing for Analyze_Depends_In_Decl_Part
1446
1447 begin
1448 Set_Analyzed (N);
1449
1450 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1451 Subp_Id := Defining_Entity (Subp_Decl);
1452
1453 -- The logic in this routine is used to analyze both pragma Depends and
1454 -- pragma Refined_Depends since they have the same syntax and base
1455 -- semantics. Find the entity of the corresponding spec when analyzing
1456 -- Refined_Depends.
1457
1458 if Nkind (Subp_Decl) = N_Subprogram_Body
1459 and then not Acts_As_Spec (Subp_Decl)
1460 then
1461 Spec_Id := Corresponding_Spec (Subp_Decl);
1462
1463 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub then
1464 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1465
1466 else
1467 Spec_Id := Subp_Id;
1468 end if;
1469
1470 Clause := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
1471
1472 -- Empty dependency list
1473
1474 if Nkind (Clause) = N_Null then
1475
1476 -- Gather all states, variables and formal parameters that the
1477 -- subprogram may depend on. These items are obtained from the
1478 -- parameter profile or pragma [Refined_]Global (if available).
1479
1480 Collect_Subprogram_Inputs_Outputs
1481 (Subp_Id => Subp_Id,
1482 Subp_Inputs => Subp_Inputs,
1483 Subp_Outputs => Subp_Outputs,
1484 Global_Seen => Global_Seen);
1485
1486 -- Verify that every input or output of the subprogram appear in a
1487 -- dependency.
1488
1489 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1490 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1491 Check_Function_Return;
1492
1493 -- Dependency clauses appear as component associations of an aggregate
1494
1495 elsif Nkind (Clause) = N_Aggregate
1496 and then Present (Component_Associations (Clause))
1497 then
1498 Last_Clause := Last (Component_Associations (Clause));
1499
1500 -- Gather all states, variables and formal parameters that the
1501 -- subprogram may depend on. These items are obtained from the
1502 -- parameter profile or pragma [Refined_]Global (if available).
1503
1504 Collect_Subprogram_Inputs_Outputs
1505 (Subp_Id => Subp_Id,
1506 Subp_Inputs => Subp_Inputs,
1507 Subp_Outputs => Subp_Outputs,
1508 Global_Seen => Global_Seen);
1509
1510 -- Ensure that the formal parameters are visible when analyzing all
1511 -- clauses. This falls out of the general rule of aspects pertaining
1512 -- to subprogram declarations. Skip the installation for subprogram
1513 -- bodies because the formals are already visible.
1514
1515 if not In_Open_Scopes (Spec_Id) then
1516 Restore_Scope := True;
1517 Push_Scope (Spec_Id);
1518 Install_Formals (Spec_Id);
1519 end if;
1520
1521 Clause := First (Component_Associations (Clause));
1522 while Present (Clause) loop
1523 Errors := Serious_Errors_Detected;
1524
1525 -- Normalization may create extra clauses that contain replicated
1526 -- input and output names. There is no need to reanalyze them.
1527
1528 if not Analyzed (Clause) then
1529 Set_Analyzed (Clause);
1530
1531 Analyze_Dependency_Clause
1532 (Clause => Clause,
1533 Is_Last => Clause = Last_Clause);
1534 end if;
1535
1536 -- Do not normalize an erroneous clause because the inputs and/or
1537 -- outputs may denote illegal items.
1538
1539 if Serious_Errors_Detected = Errors then
1540 Normalize_Clause (Clause);
1541 end if;
1542
1543 Next (Clause);
1544 end loop;
1545
1546 if Restore_Scope then
1547 End_Scope;
1548 end if;
1549
1550 -- Verify that every input or output of the subprogram appear in a
1551 -- dependency.
1552
1553 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1554 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1555 Check_Function_Return;
1556
1557 -- The top level dependency relation is malformed
1558
1559 else
1560 Error_Msg_N ("malformed dependency relation", Clause);
1561 end if;
1562 end Analyze_Depends_In_Decl_Part;
1563
1564 ---------------------------------
1565 -- Analyze_Global_In_Decl_Part --
1566 ---------------------------------
1567
1568 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1569 Seen : Elist_Id := No_Elist;
1570 -- A list containing the entities of all the items processed so far. It
1571 -- plays a role in detecting distinct entities.
1572
1573 Spec_Id : Entity_Id;
1574 -- The entity of the subprogram subject to pragma [Refined_]Global
1575
1576 Subp_Id : Entity_Id;
1577 -- The entity of the subprogram [body or stub] subject to pragma
1578 -- [Refined_]Global.
1579
1580 In_Out_Seen : Boolean := False;
1581 Input_Seen : Boolean := False;
1582 Output_Seen : Boolean := False;
1583 Proof_Seen : Boolean := False;
1584 -- Flags used to verify the consistency of modes
1585
1586 procedure Analyze_Global_List
1587 (List : Node_Id;
1588 Global_Mode : Name_Id := Name_Input);
1589 -- Verify the legality of a single global list declaration. Global_Mode
1590 -- denotes the current mode in effect.
1591
1592 -------------------------
1593 -- Analyze_Global_List --
1594 -------------------------
1595
1596 procedure Analyze_Global_List
1597 (List : Node_Id;
1598 Global_Mode : Name_Id := Name_Input)
1599 is
1600 procedure Analyze_Global_Item
1601 (Item : Node_Id;
1602 Global_Mode : Name_Id);
1603 -- Verify the legality of a single global item declaration.
1604 -- Global_Mode denotes the current mode in effect.
1605
1606 procedure Check_Duplicate_Mode
1607 (Mode : Node_Id;
1608 Status : in out Boolean);
1609 -- Flag Status denotes whether a particular mode has been seen while
1610 -- processing a global list. This routine verifies that Mode is not a
1611 -- duplicate mode and sets the flag Status.
1612
1613 procedure Check_Mode_Restriction_In_Enclosing_Context
1614 (Item : Node_Id;
1615 Item_Id : Entity_Id);
1616 -- Verify that an item of mode In_Out or Output does not appear as an
1617 -- input in the Global aspect of an enclosing subprogram. If this is
1618 -- the case, emit an error. Item and Item_Id are respectively the
1619 -- item and its entity.
1620
1621 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1622 -- Mode denotes either In_Out or Output. Depending on the kind of the
1623 -- related subprogram, emit an error if those two modes apply to a
1624 -- function.
1625
1626 -------------------------
1627 -- Analyze_Global_Item --
1628 -------------------------
1629
1630 procedure Analyze_Global_Item
1631 (Item : Node_Id;
1632 Global_Mode : Name_Id)
1633 is
1634 Item_Id : Entity_Id;
1635
1636 begin
1637 -- Detect one of the following cases
1638
1639 -- with Global => (null, Name)
1640 -- with Global => (Name_1, null, Name_2)
1641 -- with Global => (Name, null)
1642
1643 if Nkind (Item) = N_Null then
1644 Error_Msg_N ("cannot mix null and non-null global items", Item);
1645 return;
1646 end if;
1647
1648 Analyze (Item);
1649
1650 -- Find the entity of the item. If this is a renaming, climb the
1651 -- renaming chain to reach the root object. Renamings of non-
1652 -- entire objects do not yield an entity (Empty).
1653
1654 Item_Id := Entity_Of (Item);
1655
1656 if Present (Item_Id) then
1657 Record_Possible_Body_Reference (Item, Item_Id);
1658
1659 -- A global item may denote a formal parameter of an enclosing
1660 -- subprogram. Do this check first to provide a better error
1661 -- diagnostic.
1662
1663 if Is_Formal (Item_Id) then
1664 if Scope (Item_Id) = Spec_Id then
1665 Error_Msg_N
1666 ("global item cannot reference formal parameter", Item);
1667 return;
1668 end if;
1669
1670 -- The only legal references are those to abstract states and
1671 -- variables.
1672
1673 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1674 Error_Msg_N
1675 ("global item must denote variable or state", Item);
1676 return;
1677 end if;
1678
1679 if Ekind (Item_Id) = E_Abstract_State then
1680
1681 -- The state acts as a constituent of some other state.
1682 -- Ensure that the other state is a proper ancestor of the
1683 -- item.
1684
1685 if Present (Refined_State (Item_Id)) then
1686 if not Is_Part_Of (Item_Id, Refined_State (Item_Id)) then
1687 Error_Msg_Name_1 := Chars (Refined_State (Item_Id));
1688 Error_Msg_NE
1689 ("state & is not a valid constituent of ancestor "
1690 & "state %", Item, Item_Id);
1691 return;
1692 end if;
1693
1694 -- An abstract state with visible refinement cannot appear
1695 -- in pragma [Refined_]Global as its place must be taken by
1696 -- some of its constituents.
1697
1698 elsif Has_Visible_Refinement (Item_Id) then
1699 Error_Msg_NE
1700 ("cannot mention state & in global refinement, use its "
1701 & "constituents instead", Item, Item_Id);
1702 return;
1703 end if;
1704 end if;
1705
1706 -- When the item renames an entire object, replace the item
1707 -- with a reference to the object.
1708
1709 if Present (Renamed_Object (Entity (Item))) then
1710 Rewrite (Item, New_Reference_To (Item_Id, Sloc (Item)));
1711 Analyze (Item);
1712 end if;
1713
1714 -- Some form of illegal construct masquerading as a name
1715
1716 else
1717 Error_Msg_N ("global item must denote variable or state", Item);
1718 return;
1719 end if;
1720
1721 -- At this point we know that the global item is one of the two
1722 -- valid choices. Perform mode- and usage-specific checks.
1723
1724 if Ekind (Item_Id) = E_Abstract_State
1725 and then Is_External_State (Item_Id)
1726 then
1727 -- A global item of mode In_Out or Output cannot denote an
1728 -- external Input_Only state.
1729
1730 if Is_Input_Only_State (Item_Id)
1731 and then Nam_In (Global_Mode, Name_In_Out, Name_Output)
1732 then
1733 Error_Msg_N
1734 ("global item of mode In_Out or Output cannot reference "
1735 & "External Input_Only state", Item);
1736
1737 -- A global item of mode In_Out or Input cannot reference an
1738 -- external Output_Only state.
1739
1740 elsif Is_Output_Only_State (Item_Id)
1741 and then Nam_In (Global_Mode, Name_In_Out, Name_Input)
1742 then
1743 Error_Msg_N
1744 ("global item of mode In_Out or Input cannot reference "
1745 & "External Output_Only state", Item);
1746 end if;
1747 end if;
1748
1749 -- Verify that an output does not appear as an input in an
1750 -- enclosing subprogram.
1751
1752 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1753 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1754 end if;
1755
1756 -- The same entity might be referenced through various way. Check
1757 -- the entity of the item rather than the item itself.
1758
1759 if Contains (Seen, Item_Id) then
1760 Error_Msg_N ("duplicate global item", Item);
1761
1762 -- Add the entity of the current item to the list of processed
1763 -- items.
1764
1765 else
1766 Add_Item (Item_Id, Seen);
1767 end if;
1768 end Analyze_Global_Item;
1769
1770 --------------------------
1771 -- Check_Duplicate_Mode --
1772 --------------------------
1773
1774 procedure Check_Duplicate_Mode
1775 (Mode : Node_Id;
1776 Status : in out Boolean)
1777 is
1778 begin
1779 if Status then
1780 Error_Msg_N ("duplicate global mode", Mode);
1781 end if;
1782
1783 Status := True;
1784 end Check_Duplicate_Mode;
1785
1786 -------------------------------------------------
1787 -- Check_Mode_Restriction_In_Enclosing_Context --
1788 -------------------------------------------------
1789
1790 procedure Check_Mode_Restriction_In_Enclosing_Context
1791 (Item : Node_Id;
1792 Item_Id : Entity_Id)
1793 is
1794 Context : Entity_Id;
1795 Dummy : Boolean;
1796 Inputs : Elist_Id := No_Elist;
1797 Outputs : Elist_Id := No_Elist;
1798
1799 begin
1800 -- Traverse the scope stack looking for enclosing subprograms
1801 -- subject to pragma [Refined_]Global.
1802
1803 Context := Scope (Subp_Id);
1804 while Present (Context) and then Context /= Standard_Standard loop
1805 if Is_Subprogram (Context)
1806 and then Present (Get_Pragma (Context, Pragma_Global))
1807 then
1808 Collect_Subprogram_Inputs_Outputs
1809 (Subp_Id => Context,
1810 Subp_Inputs => Inputs,
1811 Subp_Outputs => Outputs,
1812 Global_Seen => Dummy);
1813
1814 -- The item is classified as In_Out or Output but appears as
1815 -- an Input in an enclosing subprogram.
1816
1817 if Appears_In (Inputs, Item_Id)
1818 and then not Appears_In (Outputs, Item_Id)
1819 then
1820 Error_Msg_NE
1821 ("global item & cannot have mode In_Out or Output",
1822 Item, Item_Id);
1823 Error_Msg_NE
1824 ("\item already appears as input of subprogram &",
1825 Item, Context);
1826
1827 -- Stop the traversal once an error has been detected
1828
1829 exit;
1830 end if;
1831 end if;
1832
1833 Context := Scope (Context);
1834 end loop;
1835 end Check_Mode_Restriction_In_Enclosing_Context;
1836
1837 ----------------------------------------
1838 -- Check_Mode_Restriction_In_Function --
1839 ----------------------------------------
1840
1841 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
1842 begin
1843 if Ekind (Spec_Id) = E_Function then
1844 Error_Msg_N
1845 ("global mode & not applicable to functions", Mode);
1846 end if;
1847 end Check_Mode_Restriction_In_Function;
1848
1849 -- Local variables
1850
1851 Assoc : Node_Id;
1852 Item : Node_Id;
1853 Mode : Node_Id;
1854
1855 -- Start of processing for Analyze_Global_List
1856
1857 begin
1858 if Nkind (List) = N_Null then
1859 Set_Analyzed (List);
1860
1861 -- Single global item declaration
1862
1863 elsif Nkind_In (List, N_Expanded_Name,
1864 N_Identifier,
1865 N_Selected_Component)
1866 then
1867 Analyze_Global_Item (List, Global_Mode);
1868
1869 -- Simple global list or moded global list declaration
1870
1871 elsif Nkind (List) = N_Aggregate then
1872 Set_Analyzed (List);
1873
1874 -- The declaration of a simple global list appear as a collection
1875 -- of expressions.
1876
1877 if Present (Expressions (List)) then
1878 if Present (Component_Associations (List)) then
1879 Error_Msg_N
1880 ("cannot mix moded and non-moded global lists", List);
1881 end if;
1882
1883 Item := First (Expressions (List));
1884 while Present (Item) loop
1885 Analyze_Global_Item (Item, Global_Mode);
1886
1887 Next (Item);
1888 end loop;
1889
1890 -- The declaration of a moded global list appears as a collection
1891 -- of component associations where individual choices denote
1892 -- modes.
1893
1894 elsif Present (Component_Associations (List)) then
1895 if Present (Expressions (List)) then
1896 Error_Msg_N
1897 ("cannot mix moded and non-moded global lists", List);
1898 end if;
1899
1900 Assoc := First (Component_Associations (List));
1901 while Present (Assoc) loop
1902 Mode := First (Choices (Assoc));
1903
1904 if Nkind (Mode) = N_Identifier then
1905 if Chars (Mode) = Name_In_Out then
1906 Check_Duplicate_Mode (Mode, In_Out_Seen);
1907 Check_Mode_Restriction_In_Function (Mode);
1908
1909 elsif Chars (Mode) = Name_Input then
1910 Check_Duplicate_Mode (Mode, Input_Seen);
1911
1912 elsif Chars (Mode) = Name_Output then
1913 Check_Duplicate_Mode (Mode, Output_Seen);
1914 Check_Mode_Restriction_In_Function (Mode);
1915
1916 elsif Chars (Mode) = Name_Proof_In then
1917 Check_Duplicate_Mode (Mode, Proof_Seen);
1918
1919 else
1920 Error_Msg_N ("invalid mode selector", Mode);
1921 end if;
1922
1923 else
1924 Error_Msg_N ("invalid mode selector", Mode);
1925 end if;
1926
1927 -- Items in a moded list appear as a collection of
1928 -- expressions. Reuse the existing machinery to analyze
1929 -- them.
1930
1931 Analyze_Global_List
1932 (List => Expression (Assoc),
1933 Global_Mode => Chars (Mode));
1934
1935 Next (Assoc);
1936 end loop;
1937
1938 -- Invalid tree
1939
1940 else
1941 raise Program_Error;
1942 end if;
1943
1944 -- Any other attempt to declare a global item is erroneous
1945
1946 else
1947 Error_Msg_N ("malformed global list declaration", List);
1948 end if;
1949 end Analyze_Global_List;
1950
1951 -- Local variables
1952
1953 Items : Node_Id;
1954 Subp_Decl : Node_Id;
1955
1956 Restore_Scope : Boolean := False;
1957 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
1958
1959 -- Start of processing for Analyze_Global_In_Decl_List
1960
1961 begin
1962 Set_Analyzed (N);
1963
1964 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1965 Subp_Id := Defining_Entity (Subp_Decl);
1966
1967 -- The logic in this routine is used to analyze both pragma Global and
1968 -- pragma Refined_Global since they have the same syntax and base
1969 -- semantics. Find the entity of the corresponding spec when analyzing
1970 -- Refined_Global.
1971
1972 if Nkind (Subp_Decl) = N_Subprogram_Body
1973 and then not Acts_As_Spec (Subp_Decl)
1974 then
1975 Spec_Id := Corresponding_Spec (Subp_Decl);
1976
1977 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub then
1978 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1979
1980 else
1981 Spec_Id := Subp_Id;
1982 end if;
1983
1984 Items := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
1985
1986 -- There is nothing to be done for a null global list
1987
1988 if Nkind (Items) = N_Null then
1989 Set_Analyzed (Items);
1990
1991 -- Analyze the various forms of global lists and items. Note that some
1992 -- of these may be malformed in which case the analysis emits error
1993 -- messages.
1994
1995 else
1996 -- Ensure that the formal parameters are visible when processing an
1997 -- item. This falls out of the general rule of aspects pertaining to
1998 -- subprogram declarations.
1999
2000 if not In_Open_Scopes (Spec_Id) then
2001 Restore_Scope := True;
2002 Push_Scope (Spec_Id);
2003 Install_Formals (Spec_Id);
2004 end if;
2005
2006 Analyze_Global_List (Items);
2007
2008 if Restore_Scope then
2009 End_Scope;
2010 end if;
2011 end if;
2012 end Analyze_Global_In_Decl_Part;
2013
2014 --------------------------------------------
2015 -- Analyze_Initial_Condition_In_Decl_Part --
2016 --------------------------------------------
2017
2018 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2019 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Parent (N)));
2020 Prag_Init : constant Node_Id :=
2021 Get_Pragma (Pack_Id, Pragma_Initializes);
2022 -- The related pragma Initializes
2023
2024 Vars : Elist_Id := No_Elist;
2025 -- A list of all variables declared in pragma Initializes
2026
2027 procedure Collect_Variables;
2028 -- Inspect the initialization list of pragma Initializes and collect the
2029 -- entities of all variables declared within the related package.
2030
2031 function Match_Variable (N : Node_Id) return Traverse_Result;
2032 -- Determine whether arbitrary node N denotes a variable declared in the
2033 -- visible declarations of the related package.
2034
2035 procedure Report_Unused_Variables;
2036 -- Emit errors for all variables found in list Vars
2037
2038 -----------------------
2039 -- Collect_Variables --
2040 -----------------------
2041
2042 procedure Collect_Variables is
2043 procedure Collect_Variable (Item : Node_Id);
2044 -- Determine whether Item denotes a variable that appears in the
2045 -- related package and if it does, add it to list Vars.
2046
2047 ----------------------
2048 -- Collect_Variable --
2049 ----------------------
2050
2051 procedure Collect_Variable (Item : Node_Id) is
2052 Item_Id : Entity_Id;
2053
2054 begin
2055 if Is_Entity_Name (Item) and then Present (Entity (Item)) then
2056 Item_Id := Entity (Item);
2057
2058 -- The item is a variable declared in the related package
2059
2060 if Ekind (Item_Id) = E_Variable
2061 and then Scope (Item_Id) = Pack_Id
2062 then
2063 Add_Item (Item_Id, Vars);
2064 end if;
2065 end if;
2066 end Collect_Variable;
2067
2068 -- Local variables
2069
2070 Inits : constant Node_Id :=
2071 Get_Pragma_Arg
2072 (First (Pragma_Argument_Associations (Prag_Init)));
2073 Init : Node_Id;
2074
2075 -- Start of processing for Collect_Variables
2076
2077 begin
2078 -- Multiple initialization items appear as an aggregate
2079
2080 if Nkind (Inits) = N_Aggregate
2081 and then Present (Expressions (Inits))
2082 then
2083 Init := First (Expressions (Inits));
2084 while Present (Init) loop
2085 Collect_Variable (Init);
2086
2087 Next (Init);
2088 end loop;
2089
2090 -- Single initialization item
2091
2092 else
2093 Collect_Variable (Inits);
2094 end if;
2095 end Collect_Variables;
2096
2097 --------------------
2098 -- Match_Variable --
2099 --------------------
2100
2101 function Match_Variable (N : Node_Id) return Traverse_Result is
2102 Var_Id : Entity_Id;
2103
2104 begin
2105 -- Find a variable declared within the related package and try to
2106 -- remove it from the list of collected variables found in pragma
2107 -- Initializes.
2108
2109 if Is_Entity_Name (N)
2110 and then Present (Entity (N))
2111 then
2112 Var_Id := Entity (N);
2113
2114 if Ekind (Var_Id) = E_Variable
2115 and then Scope (Var_Id) = Pack_Id
2116 then
2117 Remove (Vars, Var_Id);
2118 end if;
2119 end if;
2120
2121 return OK;
2122 end Match_Variable;
2123
2124 procedure Match_Variables is new Traverse_Proc (Match_Variable);
2125
2126 -----------------------------
2127 -- Report_Unused_Variables --
2128 -----------------------------
2129
2130 procedure Report_Unused_Variables is
2131 Posted : Boolean := False;
2132 Var_Elmt : Elmt_Id;
2133 Var_Id : Entity_Id;
2134
2135 begin
2136 if Present (Vars) then
2137 Var_Elmt := First_Elmt (Vars);
2138 while Present (Var_Elmt) loop
2139 Var_Id := Node (Var_Elmt);
2140
2141 if not Posted then
2142 Posted := True;
2143 Error_Msg_Name_1 := Name_Initial_Condition;
2144 Error_Msg_N
2145 ("expression of % must mention the following variables",
2146 N);
2147 end if;
2148
2149 Error_Msg_Sloc := Sloc (Var_Id);
2150 Error_Msg_NE ("\ & declared #", N, Var_Id);
2151
2152 Next_Elmt (Var_Elmt);
2153 end loop;
2154 end if;
2155 end Report_Unused_Variables;
2156
2157 Expr : constant Node_Id :=
2158 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2159 Errors : constant Nat := Serious_Errors_Detected;
2160
2161 -- Start of processing for Analyze_Initial_Condition_In_Decl_Part
2162
2163 begin
2164 Set_Analyzed (N);
2165
2166 -- Pragma Initial_Condition depends on the names enumerated in pragma
2167 -- Initializes. Without those, the analysis cannot take place.
2168
2169 if No (Prag_Init) then
2170 Error_Msg_Name_1 := Name_Initial_Condition;
2171 Error_Msg_Name_2 := Name_Initializes;
2172
2173 Error_Msg_N ("% requires the presence of aspect or pragma %", N);
2174 return;
2175 end if;
2176
2177 -- The expression is preanalyzed because it has not been moved to its
2178 -- final place yet. A direct analysis may generate sife effects and this
2179 -- is not desired at this point.
2180
2181 Preanalyze_And_Resolve (Expr, Standard_Boolean);
2182
2183 -- Perform variable matching only when the expression is legal
2184
2185 if Serious_Errors_Detected = Errors then
2186 Collect_Variables;
2187
2188 -- Verify that all variables mentioned in pragma Initializes are used
2189 -- in the expression of pragma Initial_Condition.
2190
2191 Match_Variables (Expr);
2192 end if;
2193
2194 -- Emit errors for all variables that should participate in the
2195 -- expression of pragma Initial_Condition.
2196
2197 if Serious_Errors_Detected = Errors then
2198 Report_Unused_Variables;
2199 end if;
2200 end Analyze_Initial_Condition_In_Decl_Part;
2201
2202 --------------------------------------
2203 -- Analyze_Initializes_In_Decl_Part --
2204 --------------------------------------
2205
2206 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2207 Pack_Spec : constant Node_Id := Parent (N);
2208 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Pack_Spec));
2209
2210 Items_Seen : Elist_Id := No_Elist;
2211 -- A list of all initialization items processed so far. This list is
2212 -- used to detect duplicate items.
2213
2214 Non_Null_Seen : Boolean := False;
2215 Null_Seen : Boolean := False;
2216 -- Flags used to check the legality of a null initialization list
2217
2218 States_And_Vars : Elist_Id := No_Elist;
2219 -- A list of all abstract states and variables declared in the visible
2220 -- declarations of the related package. This list is used to detect the
2221 -- legality of initialization items.
2222
2223 procedure Analyze_Initialization_Item (Item : Node_Id);
2224 -- Verify the legality of a single initialization item
2225
2226 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2227 -- Verify the legality of a single initialization item followed by a
2228 -- list of input items.
2229
2230 procedure Collect_States_And_Variables;
2231 -- Inspect the visible declarations of the related package and gather
2232 -- the entities of all abstract states and variables in States_And_Vars.
2233
2234 ---------------------------------
2235 -- Analyze_Initialization_Item --
2236 ---------------------------------
2237
2238 procedure Analyze_Initialization_Item (Item : Node_Id) is
2239 Item_Id : Entity_Id;
2240
2241 begin
2242 -- Null initialization list
2243
2244 if Nkind (Item) = N_Null then
2245 if Null_Seen then
2246 Error_Msg_N ("multiple null initializations not allowed", Item);
2247
2248 elsif Non_Null_Seen then
2249 Error_Msg_N
2250 ("cannot mix null and non-null initialization items", Item);
2251 else
2252 Null_Seen := True;
2253 end if;
2254
2255 -- Initialization item
2256
2257 else
2258 Non_Null_Seen := True;
2259
2260 if Null_Seen then
2261 Error_Msg_N
2262 ("cannot mix null and non-null initialization items", Item);
2263 end if;
2264
2265 Analyze (Item);
2266
2267 if Is_Entity_Name (Item) then
2268 Item_Id := Entity (Item);
2269
2270 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2271
2272 -- The state or variable must be declared in the visible
2273 -- declarations of the package.
2274
2275 if not Contains (States_And_Vars, Item_Id) then
2276 Error_Msg_Name_1 := Chars (Pack_Id);
2277 Error_Msg_NE
2278 ("initialization item & must appear in the visible "
2279 & "declarations of package %", Item, Item_Id);
2280
2281 -- Detect a duplicate use of the same initialization item
2282
2283 elsif Contains (Items_Seen, Item_Id) then
2284 Error_Msg_N ("duplicate initialization item", Item);
2285
2286 -- The item is legal, add it to the list of processed states
2287 -- and variables.
2288
2289 else
2290 Add_Item (Item_Id, Items_Seen);
2291 end if;
2292
2293 -- The item references something that is not a state or a
2294 -- variable.
2295
2296 else
2297 Error_Msg_N
2298 ("initialization item must denote variable or state",
2299 Item);
2300 end if;
2301
2302 -- Some form of illegal construct masquerading as a name
2303
2304 else
2305 Error_Msg_N
2306 ("initialization item must denote variable or state", Item);
2307 end if;
2308 end if;
2309 end Analyze_Initialization_Item;
2310
2311 ---------------------------------------------
2312 -- Analyze_Initialization_Item_With_Inputs --
2313 ---------------------------------------------
2314
2315 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2316 Inputs_Seen : Elist_Id := No_Elist;
2317 -- A list of all inputs processed so far. This list is used to detect
2318 -- duplicate uses of an input.
2319
2320 Non_Null_Seen : Boolean := False;
2321 Null_Seen : Boolean := False;
2322 -- Flags used to check the legality of an input list
2323
2324 procedure Analyze_Input_Item (Input : Node_Id);
2325 -- Verify the legality of a single input item
2326
2327 ------------------------
2328 -- Analyze_Input_Item --
2329 ------------------------
2330
2331 procedure Analyze_Input_Item (Input : Node_Id) is
2332 Input_Id : Entity_Id;
2333
2334 begin
2335 -- Null input list
2336
2337 if Nkind (Input) = N_Null then
2338 if Null_Seen then
2339 Error_Msg_N
2340 ("multiple null initializations not allowed", Item);
2341
2342 elsif Non_Null_Seen then
2343 Error_Msg_N
2344 ("cannot mix null and non-null initialization item", Item);
2345 else
2346 Null_Seen := True;
2347 end if;
2348
2349 -- Input item
2350
2351 else
2352 Non_Null_Seen := True;
2353
2354 if Null_Seen then
2355 Error_Msg_N
2356 ("cannot mix null and non-null initialization item", Item);
2357 end if;
2358
2359 Analyze (Input);
2360
2361 if Is_Entity_Name (Input) then
2362 Input_Id := Entity (Input);
2363
2364 if Ekind_In (Input_Id, E_Abstract_State, E_Variable) then
2365
2366 -- The input cannot denote states or variables declared
2367 -- within the related package.
2368
2369 if In_Same_Code_Unit (Item, Input_Id) then
2370 Error_Msg_Name_1 := Chars (Pack_Id);
2371 Error_Msg_NE
2372 ("input item & cannot denote a visible variable or "
2373 & "state of package %", Input, Input_Id);
2374
2375 -- Detect a duplicate use of the same input item
2376
2377 elsif Contains (Inputs_Seen, Input_Id) then
2378 Error_Msg_N ("duplicate input item", Input);
2379
2380 -- Input is legal, add it to the list of processed inputs
2381
2382 else
2383 Add_Item (Input_Id, Inputs_Seen);
2384 end if;
2385
2386 -- The input references something that is not a state or a
2387 -- variable.
2388
2389 else
2390 Error_Msg_N
2391 ("input item must denote variable or state", Input);
2392 end if;
2393
2394 -- Some form of illegal construct masquerading as a name
2395
2396 else
2397 Error_Msg_N
2398 ("input item must denote variable or state", Input);
2399 end if;
2400 end if;
2401 end Analyze_Input_Item;
2402
2403 -- Local variables
2404
2405 Inputs : constant Node_Id := Expression (Item);
2406 Elmt : Node_Id;
2407 Input : Node_Id;
2408
2409 Name_Seen : Boolean := False;
2410 -- A flag used to detect multiple item names
2411
2412 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2413
2414 begin
2415 -- Inspect the name of an item with inputs
2416
2417 Elmt := First (Choices (Item));
2418 while Present (Elmt) loop
2419 if Name_Seen then
2420 Error_Msg_N ("only one item allowed in initialization", Elmt);
2421 else
2422 Name_Seen := True;
2423 Analyze_Initialization_Item (Elmt);
2424 end if;
2425
2426 Next (Elmt);
2427 end loop;
2428
2429 -- Multiple input items appear as an aggregate
2430
2431 if Nkind (Inputs) = N_Aggregate then
2432 if Present (Expressions (Inputs)) then
2433 Input := First (Expressions (Inputs));
2434 while Present (Input) loop
2435 Analyze_Input_Item (Input);
2436 Next (Input);
2437 end loop;
2438 end if;
2439
2440 if Present (Component_Associations (Inputs)) then
2441 Error_Msg_N
2442 ("inputs must appear in named association form", Inputs);
2443 end if;
2444
2445 -- Single input item
2446
2447 else
2448 Analyze_Input_Item (Inputs);
2449 end if;
2450 end Analyze_Initialization_Item_With_Inputs;
2451
2452 ----------------------------------
2453 -- Collect_States_And_Variables --
2454 ----------------------------------
2455
2456 procedure Collect_States_And_Variables is
2457 Decl : Node_Id;
2458
2459 begin
2460 -- Collect the abstract states defined in the package (if any)
2461
2462 if Present (Abstract_States (Pack_Id)) then
2463 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2464 end if;
2465
2466 -- Collect all variables the appear in the visible declarations of
2467 -- the related package.
2468
2469 if Present (Visible_Declarations (Pack_Spec)) then
2470 Decl := First (Visible_Declarations (Pack_Spec));
2471 while Present (Decl) loop
2472 if Nkind (Decl) = N_Object_Declaration
2473 and then Ekind (Defining_Entity (Decl)) = E_Variable
2474 and then Comes_From_Source (Decl)
2475 then
2476 Add_Item (Defining_Entity (Decl), States_And_Vars);
2477 end if;
2478
2479 Next (Decl);
2480 end loop;
2481 end if;
2482 end Collect_States_And_Variables;
2483
2484 -- Local variables
2485
2486 Inits : constant Node_Id :=
2487 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2488 Init : Node_Id;
2489
2490 -- Start of processing for Analyze_Initializes_In_Decl_Part
2491
2492 begin
2493 Set_Analyzed (N);
2494
2495 -- Initialize the various lists used during analysis
2496
2497 Collect_States_And_Variables;
2498
2499 -- Multiple initialization clauses appear as an aggregate
2500
2501 if Nkind (Inits) = N_Aggregate then
2502 if Present (Expressions (Inits)) then
2503 Init := First (Expressions (Inits));
2504 while Present (Init) loop
2505 Analyze_Initialization_Item (Init);
2506
2507 Next (Init);
2508 end loop;
2509 end if;
2510
2511 if Present (Component_Associations (Inits)) then
2512 Init := First (Component_Associations (Inits));
2513 while Present (Init) loop
2514 Analyze_Initialization_Item_With_Inputs (Init);
2515
2516 Next (Init);
2517 end loop;
2518 end if;
2519
2520 -- Various forms of a single initialization clause. Note that these may
2521 -- include malformed initializations.
2522
2523 else
2524 Analyze_Initialization_Item (Inits);
2525 end if;
2526 end Analyze_Initializes_In_Decl_Part;
2527
2528 --------------------
2529 -- Analyze_Pragma --
2530 --------------------
2531
2532 procedure Analyze_Pragma (N : Node_Id) is
2533 Loc : constant Source_Ptr := Sloc (N);
2534 Prag_Id : Pragma_Id;
2535
2536 Pname : Name_Id;
2537 -- Name of the source pragma, or name of the corresponding aspect for
2538 -- pragmas which originate in a source aspect. In the latter case, the
2539 -- name may be different from the pragma name.
2540
2541 Pragma_Exit : exception;
2542 -- This exception is used to exit pragma processing completely. It is
2543 -- used when an error is detected, and no further processing is
2544 -- required. It is also used if an earlier error has left the tree in
2545 -- a state where the pragma should not be processed.
2546
2547 Arg_Count : Nat;
2548 -- Number of pragma argument associations
2549
2550 Arg1 : Node_Id;
2551 Arg2 : Node_Id;
2552 Arg3 : Node_Id;
2553 Arg4 : Node_Id;
2554 -- First four pragma arguments (pragma argument association nodes, or
2555 -- Empty if the corresponding argument does not exist).
2556
2557 type Name_List is array (Natural range <>) of Name_Id;
2558 type Args_List is array (Natural range <>) of Node_Id;
2559 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2560
2561 procedure Ada_2005_Pragma;
2562 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2563 -- Ada 95 mode, these are implementation defined pragmas, so should be
2564 -- caught by the No_Implementation_Pragmas restriction.
2565
2566 procedure Ada_2012_Pragma;
2567 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2568 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2569 -- should be caught by the No_Implementation_Pragmas restriction.
2570
2571 procedure Analyze_Refined_Pragma
2572 (Spec_Id : out Entity_Id;
2573 Body_Id : out Entity_Id;
2574 Legal : out Boolean);
2575 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2576 -- Refined_Global and Refined_Post. Check the placement and related
2577 -- context of the pragma. Spec_Id is the entity of the related
2578 -- subprogram. Body_Id is the entity of the subprogram body. Flag Legal
2579 -- is set when the pragma is properly placed.
2580
2581 procedure Check_Ada_83_Warning;
2582 -- Issues a warning message for the current pragma if operating in Ada
2583 -- 83 mode (used for language pragmas that are not a standard part of
2584 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
2585 -- of 95 pragma.
2586
2587 procedure Check_Arg_Count (Required : Nat);
2588 -- Check argument count for pragma is equal to given parameter. If not,
2589 -- then issue an error message and raise Pragma_Exit.
2590
2591 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2592 -- Arg which can either be a pragma argument association, in which case
2593 -- the check is applied to the expression of the association or an
2594 -- expression directly.
2595
2596 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
2597 -- Check that an argument has the right form for an EXTERNAL_NAME
2598 -- parameter of an extended import/export pragma. The rule is that the
2599 -- name must be an identifier or string literal (in Ada 83 mode) or a
2600 -- static string expression (in Ada 95 mode).
2601
2602 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
2603 -- Check the specified argument Arg to make sure that it is an
2604 -- identifier. If not give error and raise Pragma_Exit.
2605
2606 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
2607 -- Check the specified argument Arg to make sure that it is an integer
2608 -- literal. If not give error and raise Pragma_Exit.
2609
2610 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
2611 -- Check the specified argument Arg to make sure that it has the proper
2612 -- syntactic form for a local name and meets the semantic requirements
2613 -- for a local name. The local name is analyzed as part of the
2614 -- processing for this call. In addition, the local name is required
2615 -- to represent an entity at the library level.
2616
2617 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
2618 -- Check the specified argument Arg to make sure that it has the proper
2619 -- syntactic form for a local name and meets the semantic requirements
2620 -- for a local name. The local name is analyzed as part of the
2621 -- processing for this call.
2622
2623 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
2624 -- Check the specified argument Arg to make sure that it is a valid
2625 -- locking policy name. If not give error and raise Pragma_Exit.
2626
2627 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
2628 -- Check the specified argument Arg to make sure that it is a valid
2629 -- elaboration policy name. If not give error and raise Pragma_Exit.
2630
2631 procedure Check_Arg_Is_One_Of
2632 (Arg : Node_Id;
2633 N1, N2 : Name_Id);
2634 procedure Check_Arg_Is_One_Of
2635 (Arg : Node_Id;
2636 N1, N2, N3 : Name_Id);
2637 procedure Check_Arg_Is_One_Of
2638 (Arg : Node_Id;
2639 N1, N2, N3, N4 : Name_Id);
2640 procedure Check_Arg_Is_One_Of
2641 (Arg : Node_Id;
2642 N1, N2, N3, N4, N5 : Name_Id);
2643 -- Check the specified argument Arg to make sure that it is an
2644 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2645 -- present). If not then give error and raise Pragma_Exit.
2646
2647 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
2648 -- Check the specified argument Arg to make sure that it is a valid
2649 -- queuing policy name. If not give error and raise Pragma_Exit.
2650
2651 procedure Check_Arg_Is_Static_Expression
2652 (Arg : Node_Id;
2653 Typ : Entity_Id := Empty);
2654 -- Check the specified argument Arg to make sure that it is a static
2655 -- expression of the given type (i.e. it will be analyzed and resolved
2656 -- using this type, which can be any valid argument to Resolve, e.g.
2657 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2658 -- Typ is left Empty, then any static expression is allowed.
2659
2660 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
2661 -- Check the specified argument Arg to make sure that it is a valid task
2662 -- dispatching policy name. If not give error and raise Pragma_Exit.
2663
2664 procedure Check_Arg_Order (Names : Name_List);
2665 -- Checks for an instance of two arguments with identifiers for the
2666 -- current pragma which are not in the sequence indicated by Names,
2667 -- and if so, generates a fatal message about bad order of arguments.
2668
2669 procedure Check_At_Least_N_Arguments (N : Nat);
2670 -- Check there are at least N arguments present
2671
2672 procedure Check_At_Most_N_Arguments (N : Nat);
2673 -- Check there are no more than N arguments present
2674
2675 procedure Check_Component
2676 (Comp : Node_Id;
2677 UU_Typ : Entity_Id;
2678 In_Variant_Part : Boolean := False);
2679 -- Examine an Unchecked_Union component for correct use of per-object
2680 -- constrained subtypes, and for restrictions on finalizable components.
2681 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2682 -- should be set when Comp comes from a record variant.
2683
2684 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id);
2685 -- Subsidiary routine to the analysis of pragmas Abstract_State,
2686 -- Initial_Condition and Initializes. Determine whether pragma First
2687 -- appears before pragma Second. If this is not the case, emit an error.
2688
2689 procedure Check_Duplicate_Pragma (E : Entity_Id);
2690 -- Check if a rep item of the same name as the current pragma is already
2691 -- chained as a rep pragma to the given entity. If so give a message
2692 -- about the duplicate, and then raise Pragma_Exit so does not return.
2693
2694 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2695 -- Nam is an N_String_Literal node containing the external name set by
2696 -- an Import or Export pragma (or extended Import or Export pragma).
2697 -- This procedure checks for possible duplications if this is the export
2698 -- case, and if found, issues an appropriate error message.
2699
2700 procedure Check_Expr_Is_Static_Expression
2701 (Expr : Node_Id;
2702 Typ : Entity_Id := Empty);
2703 -- Check the specified expression Expr to make sure that it is a static
2704 -- expression of the given type (i.e. it will be analyzed and resolved
2705 -- using this type, which can be any valid argument to Resolve, e.g.
2706 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2707 -- Typ is left Empty, then any static expression is allowed.
2708
2709 procedure Check_First_Subtype (Arg : Node_Id);
2710 -- Checks that Arg, whose expression is an entity name, references a
2711 -- first subtype.
2712
2713 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2714 -- Checks that the given argument has an identifier, and if so, requires
2715 -- it to match the given identifier name. If there is no identifier, or
2716 -- a non-matching identifier, then an error message is given and
2717 -- Pragma_Exit is raised.
2718
2719 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2720 -- Checks that the given argument has an identifier, and if so, requires
2721 -- it to match one of the given identifier names. If there is no
2722 -- identifier, or a non-matching identifier, then an error message is
2723 -- given and Pragma_Exit is raised.
2724
2725 procedure Check_In_Main_Program;
2726 -- Common checks for pragmas that appear within a main program
2727 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2728
2729 procedure Check_Interrupt_Or_Attach_Handler;
2730 -- Common processing for first argument of pragma Interrupt_Handler or
2731 -- pragma Attach_Handler.
2732
2733 procedure Check_Loop_Pragma_Placement;
2734 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
2735 -- appear immediately within a construct restricted to loops.
2736
2737 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2738 -- Check that pragma appears in a declarative part, or in a package
2739 -- specification, i.e. that it does not occur in a statement sequence
2740 -- in a body.
2741
2742 procedure Check_No_Identifier (Arg : Node_Id);
2743 -- Checks that the given argument does not have an identifier. If
2744 -- an identifier is present, then an error message is issued, and
2745 -- Pragma_Exit is raised.
2746
2747 procedure Check_No_Identifiers;
2748 -- Checks that none of the arguments to the pragma has an identifier.
2749 -- If any argument has an identifier, then an error message is issued,
2750 -- and Pragma_Exit is raised.
2751
2752 procedure Check_No_Link_Name;
2753 -- Checks that no link name is specified
2754
2755 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
2756 -- Checks if the given argument has an identifier, and if so, requires
2757 -- it to match the given identifier name. If there is a non-matching
2758 -- identifier, then an error message is given and Pragma_Exit is raised.
2759
2760 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
2761 -- Checks if the given argument has an identifier, and if so, requires
2762 -- it to match the given identifier name. If there is a non-matching
2763 -- identifier, then an error message is given and Pragma_Exit is raised.
2764 -- In this version of the procedure, the identifier name is given as
2765 -- a string with lower case letters.
2766
2767 procedure Check_Pre_Post;
2768 -- Called to perform checks for Pre, Pre_Class, Post, Post_Class
2769 -- pragmas. These are processed by transformation to equivalent
2770 -- Precondition and Postcondition pragmas, but Pre and Post need an
2771 -- additional check that they are not used in a subprogram body when
2772 -- there is a separate spec present.
2773
2774 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
2775 -- Called to process a precondition or postcondition pragma. There are
2776 -- three cases:
2777 --
2778 -- The pragma appears after a subprogram spec
2779 --
2780 -- If the corresponding check is not enabled, the pragma is analyzed
2781 -- but otherwise ignored and control returns with In_Body set False.
2782 --
2783 -- If the check is enabled, then the first step is to analyze the
2784 -- pragma, but this is skipped if the subprogram spec appears within
2785 -- a package specification (because this is the case where we delay
2786 -- analysis till the end of the spec). Then (whether or not it was
2787 -- analyzed), the pragma is chained to the subprogram in question
2788 -- (using Pre_Post_Conditions and Next_Pragma) and control returns
2789 -- to the caller with In_Body set False.
2790 --
2791 -- The pragma appears at the start of subprogram body declarations
2792 --
2793 -- In this case an immediate return to the caller is made with
2794 -- In_Body set True, and the pragma is NOT analyzed.
2795 --
2796 -- In all other cases, an error message for bad placement is given
2797
2798 procedure Check_Static_Constraint (Constr : Node_Id);
2799 -- Constr is a constraint from an N_Subtype_Indication node from a
2800 -- component constraint in an Unchecked_Union type. This routine checks
2801 -- that the constraint is static as required by the restrictions for
2802 -- Unchecked_Union.
2803
2804 procedure Check_Test_Case;
2805 -- Called to process a test-case pragma. It starts with checking pragma
2806 -- arguments, and the rest of the treatment is similar to the one for
2807 -- pre- and postcondition in Check_Precondition_Postcondition, except
2808 -- the placement rules for the test-case pragma are stricter. These
2809 -- pragmas may only occur after a subprogram spec declared directly
2810 -- in a package spec unit. In this case, the pragma is chained to the
2811 -- subprogram in question (using Contract_Test_Cases and Next_Pragma)
2812 -- and analysis of the pragma is delayed till the end of the spec. In
2813 -- all other cases, an error message for bad placement is given.
2814
2815 procedure Check_Valid_Configuration_Pragma;
2816 -- Legality checks for placement of a configuration pragma
2817
2818 procedure Check_Valid_Library_Unit_Pragma;
2819 -- Legality checks for library unit pragmas. A special case arises for
2820 -- pragmas in generic instances that come from copies of the original
2821 -- library unit pragmas in the generic templates. In the case of other
2822 -- than library level instantiations these can appear in contexts which
2823 -- would normally be invalid (they only apply to the original template
2824 -- and to library level instantiations), and they are simply ignored,
2825 -- which is implemented by rewriting them as null statements.
2826
2827 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
2828 -- Check an Unchecked_Union variant for lack of nested variants and
2829 -- presence of at least one component. UU_Typ is the related Unchecked_
2830 -- Union type.
2831
2832 procedure Error_Pragma (Msg : String);
2833 pragma No_Return (Error_Pragma);
2834 -- Outputs error message for current pragma. The message contains a %
2835 -- that will be replaced with the pragma name, and the flag is placed
2836 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2837 -- calls Fix_Error (see spec of that procedure for details).
2838
2839 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
2840 pragma No_Return (Error_Pragma_Arg);
2841 -- Outputs error message for current pragma. The message may contain
2842 -- a % that will be replaced with the pragma name. The parameter Arg
2843 -- may either be a pragma argument association, in which case the flag
2844 -- is placed on the expression of this association, or an expression,
2845 -- in which case the flag is placed directly on the expression. The
2846 -- message is placed using Error_Msg_N, so the message may also contain
2847 -- an & insertion character which will reference the given Arg value.
2848 -- After placing the message, Pragma_Exit is raised. Note: this routine
2849 -- calls Fix_Error (see spec of that procedure for details).
2850
2851 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
2852 pragma No_Return (Error_Pragma_Arg);
2853 -- Similar to above form of Error_Pragma_Arg except that two messages
2854 -- are provided, the second is a continuation comment starting with \.
2855
2856 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
2857 pragma No_Return (Error_Pragma_Arg_Ident);
2858 -- Outputs error message for current pragma. The message may contain
2859 -- a % that will be replaced with the pragma name. The parameter Arg
2860 -- must be a pragma argument association with a non-empty identifier
2861 -- (i.e. its Chars field must be set), and the error message is placed
2862 -- on the identifier. The message is placed using Error_Msg_N so
2863 -- the message may also contain an & insertion character which will
2864 -- reference the identifier. After placing the message, Pragma_Exit
2865 -- is raised. Note: this routine calls Fix_Error (see spec of that
2866 -- procedure for details).
2867
2868 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
2869 pragma No_Return (Error_Pragma_Ref);
2870 -- Outputs error message for current pragma. The message may contain
2871 -- a % that will be replaced with the pragma name. The parameter Ref
2872 -- must be an entity whose name can be referenced by & and sloc by #.
2873 -- After placing the message, Pragma_Exit is raised. Note: this routine
2874 -- calls Fix_Error (see spec of that procedure for details).
2875
2876 function Find_Lib_Unit_Name return Entity_Id;
2877 -- Used for a library unit pragma to find the entity to which the
2878 -- library unit pragma applies, returns the entity found.
2879
2880 procedure Find_Program_Unit_Name (Id : Node_Id);
2881 -- If the pragma is a compilation unit pragma, the id must denote the
2882 -- compilation unit in the same compilation, and the pragma must appear
2883 -- in the list of preceding or trailing pragmas. If it is a program
2884 -- unit pragma that is not a compilation unit pragma, then the
2885 -- identifier must be visible.
2886
2887 function Find_Unique_Parameterless_Procedure
2888 (Name : Entity_Id;
2889 Arg : Node_Id) return Entity_Id;
2890 -- Used for a procedure pragma to find the unique parameterless
2891 -- procedure identified by Name, returns it if it exists, otherwise
2892 -- errors out and uses Arg as the pragma argument for the message.
2893
2894 procedure Fix_Error (Msg : in out String);
2895 -- This is called prior to issuing an error message. Msg is a string
2896 -- that typically contains the substring "pragma". If the pragma comes
2897 -- from an aspect, each such "pragma" substring is replaced with the
2898 -- characters "aspect", and Error_Msg_Name_1 is set to the name of the
2899 -- aspect (which may be different from the pragma name). If the current
2900 -- pragma results from rewriting another pragma, then Error_Msg_Name_1
2901 -- is set to the original pragma name.
2902
2903 procedure Gather_Associations
2904 (Names : Name_List;
2905 Args : out Args_List);
2906 -- This procedure is used to gather the arguments for a pragma that
2907 -- permits arbitrary ordering of parameters using the normal rules
2908 -- for named and positional parameters. The Names argument is a list
2909 -- of Name_Id values that corresponds to the allowed pragma argument
2910 -- association identifiers in order. The result returned in Args is
2911 -- a list of corresponding expressions that are the pragma arguments.
2912 -- Note that this is a list of expressions, not of pragma argument
2913 -- associations (Gather_Associations has completely checked all the
2914 -- optional identifiers when it returns). An entry in Args is Empty
2915 -- on return if the corresponding argument is not present.
2916
2917 procedure GNAT_Pragma;
2918 -- Called for all GNAT defined pragmas to check the relevant restriction
2919 -- (No_Implementation_Pragmas).
2920
2921 procedure S14_Pragma;
2922 -- Called for all pragmas defined for formal verification to check that
2923 -- the S14_Extensions flag is set.
2924 -- This name needs fixing ??? There is no such thing as an
2925 -- "S14_Extensions" flag ???
2926
2927 function Is_Before_First_Decl
2928 (Pragma_Node : Node_Id;
2929 Decls : List_Id) return Boolean;
2930 -- Return True if Pragma_Node is before the first declarative item in
2931 -- Decls where Decls is the list of declarative items.
2932
2933 function Is_Configuration_Pragma return Boolean;
2934 -- Determines if the placement of the current pragma is appropriate
2935 -- for a configuration pragma.
2936
2937 function Is_In_Context_Clause return Boolean;
2938 -- Returns True if pragma appears within the context clause of a unit,
2939 -- and False for any other placement (does not generate any messages).
2940
2941 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
2942 -- Analyzes the argument, and determines if it is a static string
2943 -- expression, returns True if so, False if non-static or not String.
2944
2945 procedure Pragma_Misplaced;
2946 pragma No_Return (Pragma_Misplaced);
2947 -- Issue fatal error message for misplaced pragma
2948
2949 procedure Process_Atomic_Shared_Volatile;
2950 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
2951 -- Shared is an obsolete Ada 83 pragma, treated as being identical
2952 -- in effect to pragma Atomic.
2953
2954 procedure Process_Compile_Time_Warning_Or_Error;
2955 -- Common processing for Compile_Time_Error and Compile_Time_Warning
2956
2957 procedure Process_Convention
2958 (C : out Convention_Id;
2959 Ent : out Entity_Id);
2960 -- Common processing for Convention, Interface, Import and Export.
2961 -- Checks first two arguments of pragma, and sets the appropriate
2962 -- convention value in the specified entity or entities. On return
2963 -- C is the convention, Ent is the referenced entity.
2964
2965 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
2966 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
2967 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
2968
2969 procedure Process_Extended_Import_Export_Exception_Pragma
2970 (Arg_Internal : Node_Id;
2971 Arg_External : Node_Id;
2972 Arg_Form : Node_Id;
2973 Arg_Code : Node_Id);
2974 -- Common processing for the pragmas Import/Export_Exception. The three
2975 -- arguments correspond to the three named parameters of the pragma. An
2976 -- argument is empty if the corresponding parameter is not present in
2977 -- the pragma.
2978
2979 procedure Process_Extended_Import_Export_Object_Pragma
2980 (Arg_Internal : Node_Id;
2981 Arg_External : Node_Id;
2982 Arg_Size : Node_Id);
2983 -- Common processing for the pragmas Import/Export_Object. The three
2984 -- arguments correspond to the three named parameters of the pragmas. An
2985 -- argument is empty if the corresponding parameter is not present in
2986 -- the pragma.
2987
2988 procedure Process_Extended_Import_Export_Internal_Arg
2989 (Arg_Internal : Node_Id := Empty);
2990 -- Common processing for all extended Import and Export pragmas. The
2991 -- argument is the pragma parameter for the Internal argument. If
2992 -- Arg_Internal is empty or inappropriate, an error message is posted.
2993 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
2994 -- set to identify the referenced entity.
2995
2996 procedure Process_Extended_Import_Export_Subprogram_Pragma
2997 (Arg_Internal : Node_Id;
2998 Arg_External : Node_Id;
2999 Arg_Parameter_Types : Node_Id;
3000 Arg_Result_Type : Node_Id := Empty;
3001 Arg_Mechanism : Node_Id;
3002 Arg_Result_Mechanism : Node_Id := Empty;
3003 Arg_First_Optional_Parameter : Node_Id := Empty);
3004 -- Common processing for all extended Import and Export pragmas applying
3005 -- to subprograms. The caller omits any arguments that do not apply to
3006 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3007 -- only in the Import_Function and Export_Function cases). The argument
3008 -- names correspond to the allowed pragma association identifiers.
3009
3010 procedure Process_Generic_List;
3011 -- Common processing for Share_Generic and Inline_Generic
3012
3013 procedure Process_Import_Or_Interface;
3014 -- Common processing for Import of Interface
3015
3016 procedure Process_Import_Predefined_Type;
3017 -- Processing for completing a type with pragma Import. This is used
3018 -- to declare types that match predefined C types, especially for cases
3019 -- without corresponding Ada predefined type.
3020
3021 type Inline_Status is (Suppressed, Disabled, Enabled);
3022 -- Inline status of a subprogram, indicated as follows:
3023 -- Suppressed: inlining is suppressed for the subprogram
3024 -- Disabled: no inlining is requested for the subprogram
3025 -- Enabled: inlining is requested/required for the subprogram
3026
3027 procedure Process_Inline (Status : Inline_Status);
3028 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3029 -- indicates the inline status specified by the pragma.
3030
3031 procedure Process_Interface_Name
3032 (Subprogram_Def : Entity_Id;
3033 Ext_Arg : Node_Id;
3034 Link_Arg : Node_Id);
3035 -- Given the last two arguments of pragma Import, pragma Export, or
3036 -- pragma Interface_Name, performs validity checks and sets the
3037 -- Interface_Name field of the given subprogram entity to the
3038 -- appropriate external or link name, depending on the arguments given.
3039 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3040 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3041 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3042 -- nor Link_Arg is present, the interface name is set to the default
3043 -- from the subprogram name.
3044
3045 procedure Process_Interrupt_Or_Attach_Handler;
3046 -- Common processing for Interrupt and Attach_Handler pragmas
3047
3048 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3049 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3050 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3051 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3052 -- is not set in the Restrictions case.
3053
3054 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3055 -- Common processing for Suppress and Unsuppress. The boolean parameter
3056 -- Suppress_Case is True for the Suppress case, and False for the
3057 -- Unsuppress case.
3058
3059 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3060 -- This procedure sets the Is_Exported flag for the given entity,
3061 -- checking that the entity was not previously imported. Arg is
3062 -- the argument that specified the entity. A check is also made
3063 -- for exporting inappropriate entities.
3064
3065 procedure Set_Extended_Import_Export_External_Name
3066 (Internal_Ent : Entity_Id;
3067 Arg_External : Node_Id);
3068 -- Common processing for all extended import export pragmas. The first
3069 -- argument, Internal_Ent, is the internal entity, which has already
3070 -- been checked for validity by the caller. Arg_External is from the
3071 -- Import or Export pragma, and may be null if no External parameter
3072 -- was present. If Arg_External is present and is a non-null string
3073 -- (a null string is treated as the default), then the Interface_Name
3074 -- field of Internal_Ent is set appropriately.
3075
3076 procedure Set_Imported (E : Entity_Id);
3077 -- This procedure sets the Is_Imported flag for the given entity,
3078 -- checking that it is not previously exported or imported.
3079
3080 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3081 -- Mech is a parameter passing mechanism (see Import_Function syntax
3082 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3083 -- has the right form, and if not issues an error message. If the
3084 -- argument has the right form then the Mechanism field of Ent is
3085 -- set appropriately.
3086
3087 procedure Set_Rational_Profile;
3088 -- Activate the set of configuration pragmas and permissions that make
3089 -- up the Rational profile.
3090
3091 procedure Set_Ravenscar_Profile (N : Node_Id);
3092 -- Activate the set of configuration pragmas and restrictions that make
3093 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3094 -- is used for error messages on any constructs that violate the
3095 -- profile.
3096
3097 ---------------------
3098 -- Ada_2005_Pragma --
3099 ---------------------
3100
3101 procedure Ada_2005_Pragma is
3102 begin
3103 if Ada_Version <= Ada_95 then
3104 Check_Restriction (No_Implementation_Pragmas, N);
3105 end if;
3106 end Ada_2005_Pragma;
3107
3108 ---------------------
3109 -- Ada_2012_Pragma --
3110 ---------------------
3111
3112 procedure Ada_2012_Pragma is
3113 begin
3114 if Ada_Version <= Ada_2005 then
3115 Check_Restriction (No_Implementation_Pragmas, N);
3116 end if;
3117 end Ada_2012_Pragma;
3118
3119 ----------------------------
3120 -- Analyze_Refined_Pragma --
3121 ----------------------------
3122
3123 procedure Analyze_Refined_Pragma
3124 (Spec_Id : out Entity_Id;
3125 Body_Id : out Entity_Id;
3126 Legal : out Boolean)
3127 is
3128 Body_Decl : Node_Id;
3129 Pack_Spec : Node_Id;
3130 Spec_Decl : Node_Id;
3131
3132 begin
3133 -- Assume that the pragma is illegal
3134
3135 Spec_Id := Empty;
3136 Body_Id := Empty;
3137 Legal := False;
3138
3139 GNAT_Pragma;
3140 Check_Arg_Count (1);
3141 Check_No_Identifiers;
3142
3143 -- Verify the placement of the pragma and check for duplicates. The
3144 -- pragma must apply to a subprogram body [stub].
3145
3146 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3147
3148 if not Nkind_In (Body_Decl, N_Subprogram_Body,
3149 N_Subprogram_Body_Stub)
3150 then
3151 Pragma_Misplaced;
3152 return;
3153 end if;
3154
3155 Body_Id := Defining_Entity (Body_Decl);
3156
3157 -- The body [stub] must not act as a spec, in other words it has to
3158 -- be paired with a corresponding spec.
3159
3160 if Nkind (Body_Decl) = N_Subprogram_Body then
3161 Spec_Id := Corresponding_Spec (Body_Decl);
3162 else
3163 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
3164 end if;
3165
3166 if No (Spec_Id) then
3167 Error_Pragma ("pragma % cannot apply to a stand alone body");
3168 return;
3169 end if;
3170
3171 -- The pragma may only apply to the body [stub] of a subprogram
3172 -- declared in the visible part of a package. Retrieve the context of
3173 -- the subprogram declaration.
3174
3175 Spec_Decl := Parent (Parent (Spec_Id));
3176
3177 pragma Assert
3178 (Nkind_In (Spec_Decl, N_Abstract_Subprogram_Declaration,
3179 N_Generic_Subprogram_Declaration,
3180 N_Subprogram_Declaration));
3181
3182 Pack_Spec := Parent (Spec_Decl);
3183
3184 if Nkind (Pack_Spec) /= N_Package_Specification
3185 or else List_Containing (Spec_Decl) /=
3186 Visible_Declarations (Pack_Spec)
3187 then
3188 Error_Pragma
3189 ("pragma % must apply to the body of a visible subprogram");
3190 return;
3191 end if;
3192
3193 -- If we get here, then the pragma is legal
3194
3195 Legal := True;
3196 end Analyze_Refined_Pragma;
3197
3198 --------------------------
3199 -- Check_Ada_83_Warning --
3200 --------------------------
3201
3202 procedure Check_Ada_83_Warning is
3203 begin
3204 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3205 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3206 end if;
3207 end Check_Ada_83_Warning;
3208
3209 ---------------------
3210 -- Check_Arg_Count --
3211 ---------------------
3212
3213 procedure Check_Arg_Count (Required : Nat) is
3214 begin
3215 if Arg_Count /= Required then
3216 Error_Pragma ("wrong number of arguments for pragma%");
3217 end if;
3218 end Check_Arg_Count;
3219
3220 --------------------------------
3221 -- Check_Arg_Is_External_Name --
3222 --------------------------------
3223
3224 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3225 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3226
3227 begin
3228 if Nkind (Argx) = N_Identifier then
3229 return;
3230
3231 else
3232 Analyze_And_Resolve (Argx, Standard_String);
3233
3234 if Is_OK_Static_Expression (Argx) then
3235 return;
3236
3237 elsif Etype (Argx) = Any_Type then
3238 raise Pragma_Exit;
3239
3240 -- An interesting special case, if we have a string literal and
3241 -- we are in Ada 83 mode, then we allow it even though it will
3242 -- not be flagged as static. This allows expected Ada 83 mode
3243 -- use of external names which are string literals, even though
3244 -- technically these are not static in Ada 83.
3245
3246 elsif Ada_Version = Ada_83
3247 and then Nkind (Argx) = N_String_Literal
3248 then
3249 return;
3250
3251 -- Static expression that raises Constraint_Error. This has
3252 -- already been flagged, so just exit from pragma processing.
3253
3254 elsif Is_Static_Expression (Argx) then
3255 raise Pragma_Exit;
3256
3257 -- Here we have a real error (non-static expression)
3258
3259 else
3260 Error_Msg_Name_1 := Pname;
3261
3262 declare
3263 Msg : String :=
3264 "argument for pragma% must be a identifier or "
3265 & "static string expression!";
3266 begin
3267 Fix_Error (Msg);
3268 Flag_Non_Static_Expr (Msg, Argx);
3269 raise Pragma_Exit;
3270 end;
3271 end if;
3272 end if;
3273 end Check_Arg_Is_External_Name;
3274
3275 -----------------------------
3276 -- Check_Arg_Is_Identifier --
3277 -----------------------------
3278
3279 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3280 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3281 begin
3282 if Nkind (Argx) /= N_Identifier then
3283 Error_Pragma_Arg
3284 ("argument for pragma% must be identifier", Argx);
3285 end if;
3286 end Check_Arg_Is_Identifier;
3287
3288 ----------------------------------
3289 -- Check_Arg_Is_Integer_Literal --
3290 ----------------------------------
3291
3292 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3293 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3294 begin
3295 if Nkind (Argx) /= N_Integer_Literal then
3296 Error_Pragma_Arg
3297 ("argument for pragma% must be integer literal", Argx);
3298 end if;
3299 end Check_Arg_Is_Integer_Literal;
3300
3301 -------------------------------------------
3302 -- Check_Arg_Is_Library_Level_Local_Name --
3303 -------------------------------------------
3304
3305 -- LOCAL_NAME ::=
3306 -- DIRECT_NAME
3307 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3308 -- | library_unit_NAME
3309
3310 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3311 begin
3312 Check_Arg_Is_Local_Name (Arg);
3313
3314 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3315 and then Comes_From_Source (N)
3316 then
3317 Error_Pragma_Arg
3318 ("argument for pragma% must be library level entity", Arg);
3319 end if;
3320 end Check_Arg_Is_Library_Level_Local_Name;
3321
3322 -----------------------------
3323 -- Check_Arg_Is_Local_Name --
3324 -----------------------------
3325
3326 -- LOCAL_NAME ::=
3327 -- DIRECT_NAME
3328 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3329 -- | library_unit_NAME
3330
3331 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3332 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3333
3334 begin
3335 Analyze (Argx);
3336
3337 if Nkind (Argx) not in N_Direct_Name
3338 and then (Nkind (Argx) /= N_Attribute_Reference
3339 or else Present (Expressions (Argx))
3340 or else Nkind (Prefix (Argx)) /= N_Identifier)
3341 and then (not Is_Entity_Name (Argx)
3342 or else not Is_Compilation_Unit (Entity (Argx)))
3343 then
3344 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3345 end if;
3346
3347 -- No further check required if not an entity name
3348
3349 if not Is_Entity_Name (Argx) then
3350 null;
3351
3352 else
3353 declare
3354 OK : Boolean;
3355 Ent : constant Entity_Id := Entity (Argx);
3356 Scop : constant Entity_Id := Scope (Ent);
3357
3358 begin
3359 -- Case of a pragma applied to a compilation unit: pragma must
3360 -- occur immediately after the program unit in the compilation.
3361
3362 if Is_Compilation_Unit (Ent) then
3363 declare
3364 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3365
3366 begin
3367 -- Case of pragma placed immediately after spec
3368
3369 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3370 OK := True;
3371
3372 -- Case of pragma placed immediately after body
3373
3374 elsif Nkind (Decl) = N_Subprogram_Declaration
3375 and then Present (Corresponding_Body (Decl))
3376 then
3377 OK := Parent (N) =
3378 Aux_Decls_Node
3379 (Parent (Unit_Declaration_Node
3380 (Corresponding_Body (Decl))));
3381
3382 -- All other cases are illegal
3383
3384 else
3385 OK := False;
3386 end if;
3387 end;
3388
3389 -- Special restricted placement rule from 10.2.1(11.8/2)
3390
3391 elsif Is_Generic_Formal (Ent)
3392 and then Prag_Id = Pragma_Preelaborable_Initialization
3393 then
3394 OK := List_Containing (N) =
3395 Generic_Formal_Declarations
3396 (Unit_Declaration_Node (Scop));
3397
3398 -- Default case, just check that the pragma occurs in the scope
3399 -- of the entity denoted by the name.
3400
3401 else
3402 OK := Current_Scope = Scop;
3403 end if;
3404
3405 if not OK then
3406 Error_Pragma_Arg
3407 ("pragma% argument must be in same declarative part", Arg);
3408 end if;
3409 end;
3410 end if;
3411 end Check_Arg_Is_Local_Name;
3412
3413 ---------------------------------
3414 -- Check_Arg_Is_Locking_Policy --
3415 ---------------------------------
3416
3417 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3418 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3419
3420 begin
3421 Check_Arg_Is_Identifier (Argx);
3422
3423 if not Is_Locking_Policy_Name (Chars (Argx)) then
3424 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3425 end if;
3426 end Check_Arg_Is_Locking_Policy;
3427
3428 -----------------------------------------------
3429 -- Check_Arg_Is_Partition_Elaboration_Policy --
3430 -----------------------------------------------
3431
3432 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3433 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3434
3435 begin
3436 Check_Arg_Is_Identifier (Argx);
3437
3438 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3439 Error_Pragma_Arg
3440 ("& is not a valid partition elaboration policy name", Argx);
3441 end if;
3442 end Check_Arg_Is_Partition_Elaboration_Policy;
3443
3444 -------------------------
3445 -- Check_Arg_Is_One_Of --
3446 -------------------------
3447
3448 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3449 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3450
3451 begin
3452 Check_Arg_Is_Identifier (Argx);
3453
3454 if not Nam_In (Chars (Argx), N1, N2) then
3455 Error_Msg_Name_2 := N1;
3456 Error_Msg_Name_3 := N2;
3457 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
3458 end if;
3459 end Check_Arg_Is_One_Of;
3460
3461 procedure Check_Arg_Is_One_Of
3462 (Arg : Node_Id;
3463 N1, N2, N3 : Name_Id)
3464 is
3465 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3466
3467 begin
3468 Check_Arg_Is_Identifier (Argx);
3469
3470 if not Nam_In (Chars (Argx), N1, N2, N3) then
3471 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3472 end if;
3473 end Check_Arg_Is_One_Of;
3474
3475 procedure Check_Arg_Is_One_Of
3476 (Arg : Node_Id;
3477 N1, N2, N3, N4 : Name_Id)
3478 is
3479 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3480
3481 begin
3482 Check_Arg_Is_Identifier (Argx);
3483
3484 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3485 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3486 end if;
3487 end Check_Arg_Is_One_Of;
3488
3489 procedure Check_Arg_Is_One_Of
3490 (Arg : Node_Id;
3491 N1, N2, N3, N4, N5 : Name_Id)
3492 is
3493 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3494
3495 begin
3496 Check_Arg_Is_Identifier (Argx);
3497
3498 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
3499 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3500 end if;
3501 end Check_Arg_Is_One_Of;
3502
3503 ---------------------------------
3504 -- Check_Arg_Is_Queuing_Policy --
3505 ---------------------------------
3506
3507 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
3508 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3509
3510 begin
3511 Check_Arg_Is_Identifier (Argx);
3512
3513 if not Is_Queuing_Policy_Name (Chars (Argx)) then
3514 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
3515 end if;
3516 end Check_Arg_Is_Queuing_Policy;
3517
3518 ------------------------------------
3519 -- Check_Arg_Is_Static_Expression --
3520 ------------------------------------
3521
3522 procedure Check_Arg_Is_Static_Expression
3523 (Arg : Node_Id;
3524 Typ : Entity_Id := Empty)
3525 is
3526 begin
3527 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
3528 end Check_Arg_Is_Static_Expression;
3529
3530 ------------------------------------------
3531 -- Check_Arg_Is_Task_Dispatching_Policy --
3532 ------------------------------------------
3533
3534 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
3535 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3536
3537 begin
3538 Check_Arg_Is_Identifier (Argx);
3539
3540 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
3541 Error_Pragma_Arg
3542 ("& is not a valid task dispatching policy name", Argx);
3543 end if;
3544 end Check_Arg_Is_Task_Dispatching_Policy;
3545
3546 ---------------------
3547 -- Check_Arg_Order --
3548 ---------------------
3549
3550 procedure Check_Arg_Order (Names : Name_List) is
3551 Arg : Node_Id;
3552
3553 Highest_So_Far : Natural := 0;
3554 -- Highest index in Names seen do far
3555
3556 begin
3557 Arg := Arg1;
3558 for J in 1 .. Arg_Count loop
3559 if Chars (Arg) /= No_Name then
3560 for K in Names'Range loop
3561 if Chars (Arg) = Names (K) then
3562 if K < Highest_So_Far then
3563 Error_Msg_Name_1 := Pname;
3564 Error_Msg_N
3565 ("parameters out of order for pragma%", Arg);
3566 Error_Msg_Name_1 := Names (K);
3567 Error_Msg_Name_2 := Names (Highest_So_Far);
3568 Error_Msg_N ("\% must appear before %", Arg);
3569 raise Pragma_Exit;
3570
3571 else
3572 Highest_So_Far := K;
3573 end if;
3574 end if;
3575 end loop;
3576 end if;
3577
3578 Arg := Next (Arg);
3579 end loop;
3580 end Check_Arg_Order;
3581
3582 --------------------------------
3583 -- Check_At_Least_N_Arguments --
3584 --------------------------------
3585
3586 procedure Check_At_Least_N_Arguments (N : Nat) is
3587 begin
3588 if Arg_Count < N then
3589 Error_Pragma ("too few arguments for pragma%");
3590 end if;
3591 end Check_At_Least_N_Arguments;
3592
3593 -------------------------------
3594 -- Check_At_Most_N_Arguments --
3595 -------------------------------
3596
3597 procedure Check_At_Most_N_Arguments (N : Nat) is
3598 Arg : Node_Id;
3599 begin
3600 if Arg_Count > N then
3601 Arg := Arg1;
3602 for J in 1 .. N loop
3603 Next (Arg);
3604 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
3605 end loop;
3606 end if;
3607 end Check_At_Most_N_Arguments;
3608
3609 ---------------------
3610 -- Check_Component --
3611 ---------------------
3612
3613 procedure Check_Component
3614 (Comp : Node_Id;
3615 UU_Typ : Entity_Id;
3616 In_Variant_Part : Boolean := False)
3617 is
3618 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
3619 Sindic : constant Node_Id :=
3620 Subtype_Indication (Component_Definition (Comp));
3621 Typ : constant Entity_Id := Etype (Comp_Id);
3622
3623 begin
3624 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
3625 -- object constraint, then the component type shall be an Unchecked_
3626 -- Union.
3627
3628 if Nkind (Sindic) = N_Subtype_Indication
3629 and then Has_Per_Object_Constraint (Comp_Id)
3630 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
3631 then
3632 Error_Msg_N
3633 ("component subtype subject to per-object constraint "
3634 & "must be an Unchecked_Union", Comp);
3635
3636 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
3637 -- the body of a generic unit, or within the body of any of its
3638 -- descendant library units, no part of the type of a component
3639 -- declared in a variant_part of the unchecked union type shall be of
3640 -- a formal private type or formal private extension declared within
3641 -- the formal part of the generic unit.
3642
3643 elsif Ada_Version >= Ada_2012
3644 and then In_Generic_Body (UU_Typ)
3645 and then In_Variant_Part
3646 and then Is_Private_Type (Typ)
3647 and then Is_Generic_Type (Typ)
3648 then
3649 Error_Msg_N
3650 ("component of unchecked union cannot be of generic type", Comp);
3651
3652 elsif Needs_Finalization (Typ) then
3653 Error_Msg_N
3654 ("component of unchecked union cannot be controlled", Comp);
3655
3656 elsif Has_Task (Typ) then
3657 Error_Msg_N
3658 ("component of unchecked union cannot have tasks", Comp);
3659 end if;
3660 end Check_Component;
3661
3662 -----------------------------
3663 -- Check_Declaration_Order --
3664 -----------------------------
3665
3666 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id) is
3667 procedure Check_Aspect_Specification_Order;
3668 -- Inspect the aspect specifications of the context to determine the
3669 -- proper order.
3670
3671 --------------------------------------
3672 -- Check_Aspect_Specification_Order --
3673 --------------------------------------
3674
3675 procedure Check_Aspect_Specification_Order is
3676 Asp_First : constant Node_Id := Corresponding_Aspect (First);
3677 Asp_Second : constant Node_Id := Corresponding_Aspect (Second);
3678 Asp : Node_Id;
3679
3680 begin
3681 -- Both aspects must be part of the same aspect specification list
3682
3683 pragma Assert
3684 (List_Containing (Asp_First) = List_Containing (Asp_Second));
3685
3686 -- Try to reach Second starting from First in a left to right
3687 -- traversal of the aspect specifications.
3688
3689 Asp := Next (Asp_First);
3690 while Present (Asp) loop
3691
3692 -- The order is ok, First is followed by Second
3693
3694 if Asp = Asp_Second then
3695 return;
3696 end if;
3697
3698 Next (Asp);
3699 end loop;
3700
3701 -- If we get here, then the aspects are out of order
3702
3703 Error_Msg_N ("aspect % cannot come after aspect %", First);
3704 end Check_Aspect_Specification_Order;
3705
3706 -- Local variables
3707
3708 Stmt : Node_Id;
3709
3710 -- Start of processing for Check_Declaration_Order
3711
3712 begin
3713 -- Cannot check the order if one of the pragmas is missing
3714
3715 if No (First) or else No (Second) then
3716 return;
3717 end if;
3718
3719 -- Set up the error names in case the order is incorrect
3720
3721 Error_Msg_Name_1 := Pragma_Name (First);
3722 Error_Msg_Name_2 := Pragma_Name (Second);
3723
3724 if From_Aspect_Specification (First) then
3725
3726 -- Both pragmas are actually aspects, check their declaration
3727 -- order in the associated aspect specification list. Otherwise
3728 -- First is an aspect and Second a source pragma.
3729
3730 if From_Aspect_Specification (Second) then
3731 Check_Aspect_Specification_Order;
3732 end if;
3733
3734 -- Abstract_States is a source pragma
3735
3736 else
3737 if From_Aspect_Specification (Second) then
3738 Error_Msg_N ("pragma % cannot come after aspect %", First);
3739
3740 -- Both pragmas are source constructs. Try to reach First from
3741 -- Second by traversing the declarations backwards.
3742
3743 else
3744 Stmt := Prev (Second);
3745 while Present (Stmt) loop
3746
3747 -- The order is ok, First is followed by Second
3748
3749 if Stmt = First then
3750 return;
3751 end if;
3752
3753 Prev (Stmt);
3754 end loop;
3755
3756 -- If we get here, then the pragmas are out of order
3757
3758 Error_Msg_N ("pragma % cannot come after pragma %", First);
3759 end if;
3760 end if;
3761 end Check_Declaration_Order;
3762
3763 ----------------------------
3764 -- Check_Duplicate_Pragma --
3765 ----------------------------
3766
3767 procedure Check_Duplicate_Pragma (E : Entity_Id) is
3768 Id : Entity_Id := E;
3769 P : Node_Id;
3770
3771 begin
3772 -- Nothing to do if this pragma comes from an aspect specification,
3773 -- since we could not be duplicating a pragma, and we dealt with the
3774 -- case of duplicated aspects in Analyze_Aspect_Specifications.
3775
3776 if From_Aspect_Specification (N) then
3777 return;
3778 end if;
3779
3780 -- Otherwise current pragma may duplicate previous pragma or a
3781 -- previously given aspect specification or attribute definition
3782 -- clause for the same pragma.
3783
3784 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
3785
3786 if Present (P) then
3787 Error_Msg_Name_1 := Pragma_Name (N);
3788 Error_Msg_Sloc := Sloc (P);
3789
3790 -- For a single protected or a single task object, the error is
3791 -- issued on the original entity.
3792
3793 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
3794 Id := Defining_Identifier (Original_Node (Parent (Id)));
3795 end if;
3796
3797 if Nkind (P) = N_Aspect_Specification
3798 or else From_Aspect_Specification (P)
3799 then
3800 Error_Msg_NE ("aspect% for & previously given#", N, Id);
3801 else
3802 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
3803 end if;
3804
3805 raise Pragma_Exit;
3806 end if;
3807 end Check_Duplicate_Pragma;
3808
3809 ----------------------------------
3810 -- Check_Duplicated_Export_Name --
3811 ----------------------------------
3812
3813 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
3814 String_Val : constant String_Id := Strval (Nam);
3815
3816 begin
3817 -- We are only interested in the export case, and in the case of
3818 -- generics, it is the instance, not the template, that is the
3819 -- problem (the template will generate a warning in any case).
3820
3821 if not Inside_A_Generic
3822 and then (Prag_Id = Pragma_Export
3823 or else
3824 Prag_Id = Pragma_Export_Procedure
3825 or else
3826 Prag_Id = Pragma_Export_Valued_Procedure
3827 or else
3828 Prag_Id = Pragma_Export_Function)
3829 then
3830 for J in Externals.First .. Externals.Last loop
3831 if String_Equal (String_Val, Strval (Externals.Table (J))) then
3832 Error_Msg_Sloc := Sloc (Externals.Table (J));
3833 Error_Msg_N ("external name duplicates name given#", Nam);
3834 exit;
3835 end if;
3836 end loop;
3837
3838 Externals.Append (Nam);
3839 end if;
3840 end Check_Duplicated_Export_Name;
3841
3842 -------------------------------------
3843 -- Check_Expr_Is_Static_Expression --
3844 -------------------------------------
3845
3846 procedure Check_Expr_Is_Static_Expression
3847 (Expr : Node_Id;
3848 Typ : Entity_Id := Empty)
3849 is
3850 begin
3851 if Present (Typ) then
3852 Analyze_And_Resolve (Expr, Typ);
3853 else
3854 Analyze_And_Resolve (Expr);
3855 end if;
3856
3857 if Is_OK_Static_Expression (Expr) then
3858 return;
3859
3860 elsif Etype (Expr) = Any_Type then
3861 raise Pragma_Exit;
3862
3863 -- An interesting special case, if we have a string literal and we
3864 -- are in Ada 83 mode, then we allow it even though it will not be
3865 -- flagged as static. This allows the use of Ada 95 pragmas like
3866 -- Import in Ada 83 mode. They will of course be flagged with
3867 -- warnings as usual, but will not cause errors.
3868
3869 elsif Ada_Version = Ada_83
3870 and then Nkind (Expr) = N_String_Literal
3871 then
3872 return;
3873
3874 -- Static expression that raises Constraint_Error. This has already
3875 -- been flagged, so just exit from pragma processing.
3876
3877 elsif Is_Static_Expression (Expr) then
3878 raise Pragma_Exit;
3879
3880 -- Finally, we have a real error
3881
3882 else
3883 Error_Msg_Name_1 := Pname;
3884
3885 declare
3886 Msg : String :=
3887 "argument for pragma% must be a static expression!";
3888 begin
3889 Fix_Error (Msg);
3890 Flag_Non_Static_Expr (Msg, Expr);
3891 end;
3892
3893 raise Pragma_Exit;
3894 end if;
3895 end Check_Expr_Is_Static_Expression;
3896
3897 -------------------------
3898 -- Check_First_Subtype --
3899 -------------------------
3900
3901 procedure Check_First_Subtype (Arg : Node_Id) is
3902 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3903 Ent : constant Entity_Id := Entity (Argx);
3904
3905 begin
3906 if Is_First_Subtype (Ent) then
3907 null;
3908
3909 elsif Is_Type (Ent) then
3910 Error_Pragma_Arg
3911 ("pragma% cannot apply to subtype", Argx);
3912
3913 elsif Is_Object (Ent) then
3914 Error_Pragma_Arg
3915 ("pragma% cannot apply to object, requires a type", Argx);
3916
3917 else
3918 Error_Pragma_Arg
3919 ("pragma% cannot apply to&, requires a type", Argx);
3920 end if;
3921 end Check_First_Subtype;
3922
3923 ----------------------
3924 -- Check_Identifier --
3925 ----------------------
3926
3927 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
3928 begin
3929 if Present (Arg)
3930 and then Nkind (Arg) = N_Pragma_Argument_Association
3931 then
3932 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
3933 Error_Msg_Name_1 := Pname;
3934 Error_Msg_Name_2 := Id;
3935 Error_Msg_N ("pragma% argument expects identifier%", Arg);
3936 raise Pragma_Exit;
3937 end if;
3938 end if;
3939 end Check_Identifier;
3940
3941 --------------------------------
3942 -- Check_Identifier_Is_One_Of --
3943 --------------------------------
3944
3945 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3946 begin
3947 if Present (Arg)
3948 and then Nkind (Arg) = N_Pragma_Argument_Association
3949 then
3950 if Chars (Arg) = No_Name then
3951 Error_Msg_Name_1 := Pname;
3952 Error_Msg_N ("pragma% argument expects an identifier", Arg);
3953 raise Pragma_Exit;
3954
3955 elsif Chars (Arg) /= N1
3956 and then Chars (Arg) /= N2
3957 then
3958 Error_Msg_Name_1 := Pname;
3959 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
3960 raise Pragma_Exit;
3961 end if;
3962 end if;
3963 end Check_Identifier_Is_One_Of;
3964
3965 ---------------------------
3966 -- Check_In_Main_Program --
3967 ---------------------------
3968
3969 procedure Check_In_Main_Program is
3970 P : constant Node_Id := Parent (N);
3971
3972 begin
3973 -- Must be at in subprogram body
3974
3975 if Nkind (P) /= N_Subprogram_Body then
3976 Error_Pragma ("% pragma allowed only in subprogram");
3977
3978 -- Otherwise warn if obviously not main program
3979
3980 elsif Present (Parameter_Specifications (Specification (P)))
3981 or else not Is_Compilation_Unit (Defining_Entity (P))
3982 then
3983 Error_Msg_Name_1 := Pname;
3984 Error_Msg_N
3985 ("??pragma% is only effective in main program", N);
3986 end if;
3987 end Check_In_Main_Program;
3988
3989 ---------------------------------------
3990 -- Check_Interrupt_Or_Attach_Handler --
3991 ---------------------------------------
3992
3993 procedure Check_Interrupt_Or_Attach_Handler is
3994 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
3995 Handler_Proc, Proc_Scope : Entity_Id;
3996
3997 begin
3998 Analyze (Arg1_X);
3999
4000 if Prag_Id = Pragma_Interrupt_Handler then
4001 Check_Restriction (No_Dynamic_Attachment, N);
4002 end if;
4003
4004 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4005 Proc_Scope := Scope (Handler_Proc);
4006
4007 -- On AAMP only, a pragma Interrupt_Handler is supported for
4008 -- nonprotected parameterless procedures.
4009
4010 if not AAMP_On_Target
4011 or else Prag_Id = Pragma_Attach_Handler
4012 then
4013 if Ekind (Proc_Scope) /= E_Protected_Type then
4014 Error_Pragma_Arg
4015 ("argument of pragma% must be protected procedure", Arg1);
4016 end if;
4017
4018 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
4019 Error_Pragma ("pragma% must be in protected definition");
4020 end if;
4021 end if;
4022
4023 if not Is_Library_Level_Entity (Proc_Scope)
4024 or else (AAMP_On_Target
4025 and then not Is_Library_Level_Entity (Handler_Proc))
4026 then
4027 Error_Pragma_Arg
4028 ("argument for pragma% must be library level entity", Arg1);
4029 end if;
4030
4031 -- AI05-0033: A pragma cannot appear within a generic body, because
4032 -- instance can be in a nested scope. The check that protected type
4033 -- is itself a library-level declaration is done elsewhere.
4034
4035 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4036 -- handle code prior to AI-0033. Analysis tools typically are not
4037 -- interested in this pragma in any case, so no need to worry too
4038 -- much about its placement.
4039
4040 if Inside_A_Generic then
4041 if Ekind (Scope (Current_Scope)) = E_Generic_Package
4042 and then In_Package_Body (Scope (Current_Scope))
4043 and then not Relaxed_RM_Semantics
4044 then
4045 Error_Pragma ("pragma% cannot be used inside a generic");
4046 end if;
4047 end if;
4048 end Check_Interrupt_Or_Attach_Handler;
4049
4050 ---------------------------------
4051 -- Check_Loop_Pragma_Placement --
4052 ---------------------------------
4053
4054 procedure Check_Loop_Pragma_Placement is
4055 procedure Placement_Error (Constr : Node_Id);
4056 pragma No_Return (Placement_Error);
4057 -- Node Constr denotes the last loop restricted construct before we
4058 -- encountered an illegal relation between enclosing constructs. Emit
4059 -- an error depending on what Constr was.
4060
4061 ---------------------
4062 -- Placement_Error --
4063 ---------------------
4064
4065 procedure Placement_Error (Constr : Node_Id) is
4066 begin
4067 if Nkind (Constr) = N_Pragma then
4068 Error_Pragma
4069 ("pragma % must appear immediately within the statements "
4070 & "of a loop");
4071 else
4072 Error_Pragma_Arg
4073 ("block containing pragma % must appear immediately within "
4074 & "the statements of a loop", Constr);
4075 end if;
4076 end Placement_Error;
4077
4078 -- Local declarations
4079
4080 Prev : Node_Id;
4081 Stmt : Node_Id;
4082
4083 -- Start of processing for Check_Loop_Pragma_Placement
4084
4085 begin
4086 Prev := N;
4087 Stmt := Parent (N);
4088 while Present (Stmt) loop
4089
4090 -- The pragma or previous block must appear immediately within the
4091 -- current block's declarative or statement part.
4092
4093 if Nkind (Stmt) = N_Block_Statement then
4094 if (No (Declarations (Stmt))
4095 or else List_Containing (Prev) /= Declarations (Stmt))
4096 and then
4097 List_Containing (Prev) /=
4098 Statements (Handled_Statement_Sequence (Stmt))
4099 then
4100 Placement_Error (Prev);
4101 return;
4102
4103 -- Keep inspecting the parents because we are now within a
4104 -- chain of nested blocks.
4105
4106 else
4107 Prev := Stmt;
4108 Stmt := Parent (Stmt);
4109 end if;
4110
4111 -- The pragma or previous block must appear immediately within the
4112 -- statements of the loop.
4113
4114 elsif Nkind (Stmt) = N_Loop_Statement then
4115 if List_Containing (Prev) /= Statements (Stmt) then
4116 Placement_Error (Prev);
4117 end if;
4118
4119 -- Stop the traversal because we reached the innermost loop
4120 -- regardless of whether we encountered an error or not.
4121
4122 return;
4123
4124 -- Ignore a handled statement sequence. Note that this node may
4125 -- be related to a subprogram body in which case we will emit an
4126 -- error on the next iteration of the search.
4127
4128 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4129 Stmt := Parent (Stmt);
4130
4131 -- Any other statement breaks the chain from the pragma to the
4132 -- loop.
4133
4134 else
4135 Placement_Error (Prev);
4136 return;
4137 end if;
4138 end loop;
4139 end Check_Loop_Pragma_Placement;
4140
4141 -------------------------------------------
4142 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4143 -------------------------------------------
4144
4145 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4146 P : Node_Id;
4147
4148 begin
4149 P := Parent (N);
4150 loop
4151 if No (P) then
4152 exit;
4153
4154 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4155 exit;
4156
4157 elsif Nkind_In (P, N_Package_Specification,
4158 N_Block_Statement)
4159 then
4160 return;
4161
4162 -- Note: the following tests seem a little peculiar, because
4163 -- they test for bodies, but if we were in the statement part
4164 -- of the body, we would already have hit the handled statement
4165 -- sequence, so the only way we get here is by being in the
4166 -- declarative part of the body.
4167
4168 elsif Nkind_In (P, N_Subprogram_Body,
4169 N_Package_Body,
4170 N_Task_Body,
4171 N_Entry_Body)
4172 then
4173 return;
4174 end if;
4175
4176 P := Parent (P);
4177 end loop;
4178
4179 Error_Pragma ("pragma% is not in declarative part or package spec");
4180 end Check_Is_In_Decl_Part_Or_Package_Spec;
4181
4182 -------------------------
4183 -- Check_No_Identifier --
4184 -------------------------
4185
4186 procedure Check_No_Identifier (Arg : Node_Id) is
4187 begin
4188 if Nkind (Arg) = N_Pragma_Argument_Association
4189 and then Chars (Arg) /= No_Name
4190 then
4191 Error_Pragma_Arg_Ident
4192 ("pragma% does not permit identifier& here", Arg);
4193 end if;
4194 end Check_No_Identifier;
4195
4196 --------------------------
4197 -- Check_No_Identifiers --
4198 --------------------------
4199
4200 procedure Check_No_Identifiers is
4201 Arg_Node : Node_Id;
4202 begin
4203 Arg_Node := Arg1;
4204 for J in 1 .. Arg_Count loop
4205 Check_No_Identifier (Arg_Node);
4206 Next (Arg_Node);
4207 end loop;
4208 end Check_No_Identifiers;
4209
4210 ------------------------
4211 -- Check_No_Link_Name --
4212 ------------------------
4213
4214 procedure Check_No_Link_Name is
4215 begin
4216 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
4217 Arg4 := Arg3;
4218 end if;
4219
4220 if Present (Arg4) then
4221 Error_Pragma_Arg
4222 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
4223 end if;
4224 end Check_No_Link_Name;
4225
4226 -------------------------------
4227 -- Check_Optional_Identifier --
4228 -------------------------------
4229
4230 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4231 begin
4232 if Present (Arg)
4233 and then Nkind (Arg) = N_Pragma_Argument_Association
4234 and then Chars (Arg) /= No_Name
4235 then
4236 if Chars (Arg) /= Id then
4237 Error_Msg_Name_1 := Pname;
4238 Error_Msg_Name_2 := Id;
4239 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4240 raise Pragma_Exit;
4241 end if;
4242 end if;
4243 end Check_Optional_Identifier;
4244
4245 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4246 begin
4247 Name_Buffer (1 .. Id'Length) := Id;
4248 Name_Len := Id'Length;
4249 Check_Optional_Identifier (Arg, Name_Find);
4250 end Check_Optional_Identifier;
4251
4252 --------------------
4253 -- Check_Pre_Post --
4254 --------------------
4255
4256 procedure Check_Pre_Post is
4257 P : Node_Id;
4258 PO : Node_Id;
4259
4260 begin
4261 if not Is_List_Member (N) then
4262 Pragma_Misplaced;
4263 end if;
4264
4265 -- If we are within an inlined body, the legality of the pragma
4266 -- has been checked already.
4267
4268 if In_Inlined_Body then
4269 return;
4270 end if;
4271
4272 -- Search prior declarations
4273
4274 P := N;
4275 while Present (Prev (P)) loop
4276 P := Prev (P);
4277
4278 -- If the previous node is a generic subprogram, do not go to to
4279 -- the original node, which is the unanalyzed tree: we need to
4280 -- attach the pre/postconditions to the analyzed version at this
4281 -- point. They get propagated to the original tree when analyzing
4282 -- the corresponding body.
4283
4284 if Nkind (P) not in N_Generic_Declaration then
4285 PO := Original_Node (P);
4286 else
4287 PO := P;
4288 end if;
4289
4290 -- Skip past prior pragma
4291
4292 if Nkind (PO) = N_Pragma then
4293 null;
4294
4295 -- Skip stuff not coming from source
4296
4297 elsif not Comes_From_Source (PO) then
4298
4299 -- The condition may apply to a subprogram instantiation
4300
4301 if Nkind (PO) = N_Subprogram_Declaration
4302 and then Present (Generic_Parent (Specification (PO)))
4303 then
4304 return;
4305
4306 elsif Nkind (PO) = N_Subprogram_Declaration
4307 and then In_Instance
4308 then
4309 return;
4310
4311 -- For all other cases of non source code, do nothing
4312
4313 else
4314 null;
4315 end if;
4316
4317 -- Only remaining possibility is subprogram declaration
4318
4319 else
4320 return;
4321 end if;
4322 end loop;
4323
4324 -- If we fall through loop, pragma is at start of list, so see if it
4325 -- is at the start of declarations of a subprogram body.
4326
4327 PO := Parent (N);
4328
4329 if Nkind (PO) = N_Subprogram_Body
4330 and then List_Containing (N) = Declarations (PO)
4331 then
4332 -- This is only allowed if there is no separate specification
4333
4334 if Present (Corresponding_Spec (PO)) then
4335 Error_Pragma
4336 ("pragma% must apply to subprogram specification");
4337 end if;
4338
4339 return;
4340 end if;
4341 end Check_Pre_Post;
4342
4343 --------------------------------------
4344 -- Check_Precondition_Postcondition --
4345 --------------------------------------
4346
4347 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
4348 P : Node_Id;
4349 PO : Node_Id;
4350
4351 procedure Chain_PPC (PO : Node_Id);
4352 -- If PO is an entry or a [generic] subprogram declaration node, then
4353 -- the precondition/postcondition applies to this subprogram and the
4354 -- processing for the pragma is completed. Otherwise the pragma is
4355 -- misplaced.
4356
4357 ---------------
4358 -- Chain_PPC --
4359 ---------------
4360
4361 procedure Chain_PPC (PO : Node_Id) is
4362 S : Entity_Id;
4363
4364 begin
4365 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
4366 if not From_Aspect_Specification (N) then
4367 Error_Pragma
4368 ("pragma% cannot be applied to abstract subprogram");
4369
4370 elsif Class_Present (N) then
4371 null;
4372
4373 else
4374 Error_Pragma
4375 ("aspect % requires ''Class for abstract subprogram");
4376 end if;
4377
4378 -- AI05-0230: The same restriction applies to null procedures. For
4379 -- compatibility with earlier uses of the Ada pragma, apply this
4380 -- rule only to aspect specifications.
4381
4382 -- The above discrepency needs documentation. Robert is dubious
4383 -- about whether it is a good idea ???
4384
4385 elsif Nkind (PO) = N_Subprogram_Declaration
4386 and then Nkind (Specification (PO)) = N_Procedure_Specification
4387 and then Null_Present (Specification (PO))
4388 and then From_Aspect_Specification (N)
4389 and then not Class_Present (N)
4390 then
4391 Error_Pragma
4392 ("aspect % requires ''Class for null procedure");
4393
4394 -- Pre/postconditions are legal on a subprogram body if it is not
4395 -- a completion of a declaration. They are also legal on a stub
4396 -- with no previous declarations (this is checked when processing
4397 -- the corresponding aspects).
4398
4399 elsif Nkind (PO) = N_Subprogram_Body
4400 and then Acts_As_Spec (PO)
4401 then
4402 null;
4403
4404 elsif Nkind (PO) = N_Subprogram_Body_Stub then
4405 null;
4406
4407 elsif not Nkind_In (PO, N_Subprogram_Declaration,
4408 N_Expression_Function,
4409 N_Generic_Subprogram_Declaration,
4410 N_Entry_Declaration)
4411 then
4412 Pragma_Misplaced;
4413 end if;
4414
4415 -- Here if we have [generic] subprogram or entry declaration
4416
4417 if Nkind (PO) = N_Entry_Declaration then
4418 S := Defining_Entity (PO);
4419 else
4420 S := Defining_Unit_Name (Specification (PO));
4421
4422 if Nkind (S) = N_Defining_Program_Unit_Name then
4423 S := Defining_Identifier (S);
4424 end if;
4425 end if;
4426
4427 -- Note: we do not analyze the pragma at this point. Instead we
4428 -- delay this analysis until the end of the declarative part in
4429 -- which the pragma appears. This implements the required delay
4430 -- in this analysis, allowing forward references. The analysis
4431 -- happens at the end of Analyze_Declarations.
4432
4433 -- Chain spec PPC pragma to list for subprogram
4434
4435 Add_Contract_Item (N, S);
4436
4437 -- Return indicating spec case
4438
4439 In_Body := False;
4440 return;
4441 end Chain_PPC;
4442
4443 -- Start of processing for Check_Precondition_Postcondition
4444
4445 begin
4446 if not Is_List_Member (N) then
4447 Pragma_Misplaced;
4448 end if;
4449
4450 -- Preanalyze message argument if present. Visibility in this
4451 -- argument is established at the point of pragma occurrence.
4452
4453 if Arg_Count = 2 then
4454 Check_Optional_Identifier (Arg2, Name_Message);
4455 Preanalyze_Spec_Expression
4456 (Get_Pragma_Arg (Arg2), Standard_String);
4457 end if;
4458
4459 -- For a pragma PPC in the extended main source unit, record enabled
4460 -- status in SCO.
4461
4462 if Is_Checked (N) and then not Split_PPC (N) then
4463 Set_SCO_Pragma_Enabled (Loc);
4464 end if;
4465
4466 -- If we are within an inlined body, the legality of the pragma
4467 -- has been checked already.
4468
4469 if In_Inlined_Body then
4470 In_Body := True;
4471 return;
4472 end if;
4473
4474 -- Search prior declarations
4475
4476 P := N;
4477 while Present (Prev (P)) loop
4478 P := Prev (P);
4479
4480 -- If the previous node is a generic subprogram, do not go to to
4481 -- the original node, which is the unanalyzed tree: we need to
4482 -- attach the pre/postconditions to the analyzed version at this
4483 -- point. They get propagated to the original tree when analyzing
4484 -- the corresponding body.
4485
4486 if Nkind (P) not in N_Generic_Declaration then
4487 PO := Original_Node (P);
4488 else
4489 PO := P;
4490 end if;
4491
4492 -- Skip past prior pragma
4493
4494 if Nkind (PO) = N_Pragma then
4495 null;
4496
4497 -- Skip stuff not coming from source
4498
4499 elsif not Comes_From_Source (PO) then
4500
4501 -- The condition may apply to a subprogram instantiation
4502
4503 if Nkind (PO) = N_Subprogram_Declaration
4504 and then Present (Generic_Parent (Specification (PO)))
4505 then
4506 Chain_PPC (PO);
4507 return;
4508
4509 elsif Nkind (PO) = N_Subprogram_Declaration
4510 and then In_Instance
4511 then
4512 Chain_PPC (PO);
4513 return;
4514
4515 -- For all other cases of non source code, do nothing
4516
4517 else
4518 null;
4519 end if;
4520
4521 -- Only remaining possibility is subprogram declaration
4522
4523 else
4524 Chain_PPC (PO);
4525 return;
4526 end if;
4527 end loop;
4528
4529 -- If we fall through loop, pragma is at start of list, so see if it
4530 -- is at the start of declarations of a subprogram body.
4531
4532 PO := Parent (N);
4533
4534 if Nkind (PO) = N_Subprogram_Body
4535 and then List_Containing (N) = Declarations (PO)
4536 then
4537 if Operating_Mode /= Generate_Code or else Inside_A_Generic then
4538
4539 -- Analyze pragma expression for correctness and for ASIS use
4540
4541 Preanalyze_Assert_Expression
4542 (Get_Pragma_Arg (Arg1), Standard_Boolean);
4543
4544 -- In ASIS mode, for a pragma generated from a source aspect,
4545 -- also analyze the original aspect expression.
4546
4547 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
4548 Preanalyze_Assert_Expression
4549 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
4550 end if;
4551 end if;
4552
4553 -- Retain a copy of the pre- or postcondition pragma for formal
4554 -- verification purposes. The copy is needed because the pragma is
4555 -- expanded into other constructs which are not acceptable in the
4556 -- N_Contract node.
4557
4558 if Acts_As_Spec (PO)
4559 and then (SPARK_Mode or Formal_Extensions)
4560 then
4561 declare
4562 Prag : constant Node_Id := New_Copy_Tree (N);
4563
4564 begin
4565 -- Preanalyze the pragma
4566
4567 Preanalyze_Assert_Expression
4568 (Get_Pragma_Arg
4569 (First (Pragma_Argument_Associations (Prag))),
4570 Standard_Boolean);
4571
4572 -- Preanalyze the corresponding aspect (if any)
4573
4574 if Present (Corresponding_Aspect (Prag)) then
4575 Preanalyze_Assert_Expression
4576 (Expression (Corresponding_Aspect (Prag)),
4577 Standard_Boolean);
4578 end if;
4579
4580 -- Chain the copy on the contract of the body
4581
4582 Add_Contract_Item
4583 (Prag, Defining_Unit_Name (Specification (PO)));
4584 end;
4585 end if;
4586
4587 In_Body := True;
4588 return;
4589
4590 -- See if it is in the pragmas after a library level subprogram
4591
4592 elsif Nkind (PO) = N_Compilation_Unit_Aux then
4593
4594 -- In formal verification mode, analyze pragma expression for
4595 -- correctness, as it is not expanded later. Ditto in ASIS_Mode
4596 -- where there is no later point at which the aspect will be
4597 -- analyzed.
4598
4599 if SPARK_Mode or else ASIS_Mode then
4600 Analyze_Pre_Post_Condition_In_Decl_Part
4601 (N, Defining_Entity (Unit (Parent (PO))));
4602 end if;
4603
4604 Chain_PPC (Unit (Parent (PO)));
4605 return;
4606 end if;
4607
4608 -- If we fall through, pragma was misplaced
4609
4610 Pragma_Misplaced;
4611 end Check_Precondition_Postcondition;
4612
4613 -----------------------------
4614 -- Check_Static_Constraint --
4615 -----------------------------
4616
4617 -- Note: for convenience in writing this procedure, in addition to
4618 -- the officially (i.e. by spec) allowed argument which is always a
4619 -- constraint, it also allows ranges and discriminant associations.
4620 -- Above is not clear ???
4621
4622 procedure Check_Static_Constraint (Constr : Node_Id) is
4623
4624 procedure Require_Static (E : Node_Id);
4625 -- Require given expression to be static expression
4626
4627 --------------------
4628 -- Require_Static --
4629 --------------------
4630
4631 procedure Require_Static (E : Node_Id) is
4632 begin
4633 if not Is_OK_Static_Expression (E) then
4634 Flag_Non_Static_Expr
4635 ("non-static constraint not allowed in Unchecked_Union!", E);
4636 raise Pragma_Exit;
4637 end if;
4638 end Require_Static;
4639
4640 -- Start of processing for Check_Static_Constraint
4641
4642 begin
4643 case Nkind (Constr) is
4644 when N_Discriminant_Association =>
4645 Require_Static (Expression (Constr));
4646
4647 when N_Range =>
4648 Require_Static (Low_Bound (Constr));
4649 Require_Static (High_Bound (Constr));
4650
4651 when N_Attribute_Reference =>
4652 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
4653 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
4654
4655 when N_Range_Constraint =>
4656 Check_Static_Constraint (Range_Expression (Constr));
4657
4658 when N_Index_Or_Discriminant_Constraint =>
4659 declare
4660 IDC : Entity_Id;
4661 begin
4662 IDC := First (Constraints (Constr));
4663 while Present (IDC) loop
4664 Check_Static_Constraint (IDC);
4665 Next (IDC);
4666 end loop;
4667 end;
4668
4669 when others =>
4670 null;
4671 end case;
4672 end Check_Static_Constraint;
4673
4674 ---------------------
4675 -- Check_Test_Case --
4676 ---------------------
4677
4678 procedure Check_Test_Case is
4679 P : Node_Id;
4680 PO : Node_Id;
4681
4682 procedure Chain_CTC (PO : Node_Id);
4683 -- If PO is a [generic] subprogram declaration node, then the
4684 -- test-case applies to this subprogram and the processing for
4685 -- the pragma is completed. Otherwise the pragma is misplaced.
4686
4687 ---------------
4688 -- Chain_CTC --
4689 ---------------
4690
4691 procedure Chain_CTC (PO : Node_Id) is
4692 S : Entity_Id;
4693
4694 begin
4695 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
4696 Error_Pragma
4697 ("pragma% cannot be applied to abstract subprogram");
4698
4699 elsif Nkind (PO) = N_Entry_Declaration then
4700 Error_Pragma ("pragma% cannot be applied to entry");
4701
4702 elsif not Nkind_In (PO, N_Subprogram_Declaration,
4703 N_Generic_Subprogram_Declaration)
4704 then
4705 Pragma_Misplaced;
4706 end if;
4707
4708 -- Here if we have [generic] subprogram declaration
4709
4710 S := Defining_Unit_Name (Specification (PO));
4711
4712 -- Note: we do not analyze the pragma at this point. Instead we
4713 -- delay this analysis until the end of the declarative part in
4714 -- which the pragma appears. This implements the required delay
4715 -- in this analysis, allowing forward references. The analysis
4716 -- happens at the end of Analyze_Declarations.
4717
4718 -- There should not be another test-case with the same name
4719 -- associated to this subprogram.
4720
4721 declare
4722 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
4723 CTC : Node_Id;
4724
4725 begin
4726 CTC := Contract_Test_Cases (Contract (S));
4727 while Present (CTC) loop
4728
4729 -- Omit pragma Contract_Cases because it does not introduce
4730 -- a unique case name and it does not follow the syntax of
4731 -- Test_Case.
4732
4733 if Pragma_Name (CTC) = Name_Contract_Cases then
4734 null;
4735
4736 elsif String_Equal
4737 (Name, Get_Name_From_CTC_Pragma (CTC))
4738 then
4739 Error_Msg_Sloc := Sloc (CTC);
4740 Error_Pragma ("name for pragma% is already used#");
4741 end if;
4742
4743 CTC := Next_Pragma (CTC);
4744 end loop;
4745 end;
4746
4747 -- Chain spec CTC pragma to list for subprogram
4748
4749 Add_Contract_Item (N, S);
4750 end Chain_CTC;
4751
4752 -- Start of processing for Check_Test_Case
4753
4754 begin
4755 -- First check pragma arguments
4756
4757 Check_At_Least_N_Arguments (2);
4758 Check_At_Most_N_Arguments (4);
4759 Check_Arg_Order
4760 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
4761
4762 Check_Optional_Identifier (Arg1, Name_Name);
4763 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
4764
4765 -- In ASIS mode, for a pragma generated from a source aspect, also
4766 -- analyze the original aspect expression.
4767
4768 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
4769 Check_Expr_Is_Static_Expression
4770 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
4771 end if;
4772
4773 Check_Optional_Identifier (Arg2, Name_Mode);
4774 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
4775
4776 if Arg_Count = 4 then
4777 Check_Identifier (Arg3, Name_Requires);
4778 Check_Identifier (Arg4, Name_Ensures);
4779
4780 elsif Arg_Count = 3 then
4781 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
4782 end if;
4783
4784 -- Check pragma placement
4785
4786 if not Is_List_Member (N) then
4787 Pragma_Misplaced;
4788 end if;
4789
4790 -- Test-case should only appear in package spec unit
4791
4792 if Get_Source_Unit (N) = No_Unit
4793 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
4794 N_Package_Declaration,
4795 N_Generic_Package_Declaration)
4796 then
4797 Pragma_Misplaced;
4798 end if;
4799
4800 -- Search prior declarations
4801
4802 P := N;
4803 while Present (Prev (P)) loop
4804 P := Prev (P);
4805
4806 -- If the previous node is a generic subprogram, do not go to to
4807 -- the original node, which is the unanalyzed tree: we need to
4808 -- attach the test-case to the analyzed version at this point.
4809 -- They get propagated to the original tree when analyzing the
4810 -- corresponding body.
4811
4812 if Nkind (P) not in N_Generic_Declaration then
4813 PO := Original_Node (P);
4814 else
4815 PO := P;
4816 end if;
4817
4818 -- Skip past prior pragma
4819
4820 if Nkind (PO) = N_Pragma then
4821 null;
4822
4823 -- Skip stuff not coming from source
4824
4825 elsif not Comes_From_Source (PO) then
4826 null;
4827
4828 -- Only remaining possibility is subprogram declaration. First
4829 -- check that it is declared directly in a package declaration.
4830 -- This may be either the package declaration for the current unit
4831 -- being defined or a local package declaration.
4832
4833 elsif not Present (Parent (Parent (PO)))
4834 or else not Present (Parent (Parent (Parent (PO))))
4835 or else not Nkind_In (Parent (Parent (PO)),
4836 N_Package_Declaration,
4837 N_Generic_Package_Declaration)
4838 then
4839 Pragma_Misplaced;
4840
4841 else
4842 Chain_CTC (PO);
4843 return;
4844 end if;
4845 end loop;
4846
4847 -- If we fall through, pragma was misplaced
4848
4849 Pragma_Misplaced;
4850 end Check_Test_Case;
4851
4852 --------------------------------------
4853 -- Check_Valid_Configuration_Pragma --
4854 --------------------------------------
4855
4856 -- A configuration pragma must appear in the context clause of a
4857 -- compilation unit, and only other pragmas may precede it. Note that
4858 -- the test also allows use in a configuration pragma file.
4859
4860 procedure Check_Valid_Configuration_Pragma is
4861 begin
4862 if not Is_Configuration_Pragma then
4863 Error_Pragma ("incorrect placement for configuration pragma%");
4864 end if;
4865 end Check_Valid_Configuration_Pragma;
4866
4867 -------------------------------------
4868 -- Check_Valid_Library_Unit_Pragma --
4869 -------------------------------------
4870
4871 procedure Check_Valid_Library_Unit_Pragma is
4872 Plist : List_Id;
4873 Parent_Node : Node_Id;
4874 Unit_Name : Entity_Id;
4875 Unit_Kind : Node_Kind;
4876 Unit_Node : Node_Id;
4877 Sindex : Source_File_Index;
4878
4879 begin
4880 if not Is_List_Member (N) then
4881 Pragma_Misplaced;
4882
4883 else
4884 Plist := List_Containing (N);
4885 Parent_Node := Parent (Plist);
4886
4887 if Parent_Node = Empty then
4888 Pragma_Misplaced;
4889
4890 -- Case of pragma appearing after a compilation unit. In this case
4891 -- it must have an argument with the corresponding name and must
4892 -- be part of the following pragmas of its parent.
4893
4894 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
4895 if Plist /= Pragmas_After (Parent_Node) then
4896 Pragma_Misplaced;
4897
4898 elsif Arg_Count = 0 then
4899 Error_Pragma
4900 ("argument required if outside compilation unit");
4901
4902 else
4903 Check_No_Identifiers;
4904 Check_Arg_Count (1);
4905 Unit_Node := Unit (Parent (Parent_Node));
4906 Unit_Kind := Nkind (Unit_Node);
4907
4908 Analyze (Get_Pragma_Arg (Arg1));
4909
4910 if Unit_Kind = N_Generic_Subprogram_Declaration
4911 or else Unit_Kind = N_Subprogram_Declaration
4912 then
4913 Unit_Name := Defining_Entity (Unit_Node);
4914
4915 elsif Unit_Kind in N_Generic_Instantiation then
4916 Unit_Name := Defining_Entity (Unit_Node);
4917
4918 else
4919 Unit_Name := Cunit_Entity (Current_Sem_Unit);
4920 end if;
4921
4922 if Chars (Unit_Name) /=
4923 Chars (Entity (Get_Pragma_Arg (Arg1)))
4924 then
4925 Error_Pragma_Arg
4926 ("pragma% argument is not current unit name", Arg1);
4927 end if;
4928
4929 if Ekind (Unit_Name) = E_Package
4930 and then Present (Renamed_Entity (Unit_Name))
4931 then
4932 Error_Pragma ("pragma% not allowed for renamed package");
4933 end if;
4934 end if;
4935
4936 -- Pragma appears other than after a compilation unit
4937
4938 else
4939 -- Here we check for the generic instantiation case and also
4940 -- for the case of processing a generic formal package. We
4941 -- detect these cases by noting that the Sloc on the node
4942 -- does not belong to the current compilation unit.
4943
4944 Sindex := Source_Index (Current_Sem_Unit);
4945
4946 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
4947 Rewrite (N, Make_Null_Statement (Loc));
4948 return;
4949
4950 -- If before first declaration, the pragma applies to the
4951 -- enclosing unit, and the name if present must be this name.
4952
4953 elsif Is_Before_First_Decl (N, Plist) then
4954 Unit_Node := Unit_Declaration_Node (Current_Scope);
4955 Unit_Kind := Nkind (Unit_Node);
4956
4957 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
4958 Pragma_Misplaced;
4959
4960 elsif Unit_Kind = N_Subprogram_Body
4961 and then not Acts_As_Spec (Unit_Node)
4962 then
4963 Pragma_Misplaced;
4964
4965 elsif Nkind (Parent_Node) = N_Package_Body then
4966 Pragma_Misplaced;
4967
4968 elsif Nkind (Parent_Node) = N_Package_Specification
4969 and then Plist = Private_Declarations (Parent_Node)
4970 then
4971 Pragma_Misplaced;
4972
4973 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
4974 or else Nkind (Parent_Node) =
4975 N_Generic_Subprogram_Declaration)
4976 and then Plist = Generic_Formal_Declarations (Parent_Node)
4977 then
4978 Pragma_Misplaced;
4979
4980 elsif Arg_Count > 0 then
4981 Analyze (Get_Pragma_Arg (Arg1));
4982
4983 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
4984 Error_Pragma_Arg
4985 ("name in pragma% must be enclosing unit", Arg1);
4986 end if;
4987
4988 -- It is legal to have no argument in this context
4989
4990 else
4991 return;
4992 end if;
4993
4994 -- Error if not before first declaration. This is because a
4995 -- library unit pragma argument must be the name of a library
4996 -- unit (RM 10.1.5(7)), but the only names permitted in this
4997 -- context are (RM 10.1.5(6)) names of subprogram declarations,
4998 -- generic subprogram declarations or generic instantiations.
4999
5000 else
5001 Error_Pragma
5002 ("pragma% misplaced, must be before first declaration");
5003 end if;
5004 end if;
5005 end if;
5006 end Check_Valid_Library_Unit_Pragma;
5007
5008 -------------------
5009 -- Check_Variant --
5010 -------------------
5011
5012 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5013 Clist : constant Node_Id := Component_List (Variant);
5014 Comp : Node_Id;
5015
5016 begin
5017 Comp := First (Component_Items (Clist));
5018 while Present (Comp) loop
5019 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5020 Next (Comp);
5021 end loop;
5022 end Check_Variant;
5023
5024 ------------------
5025 -- Error_Pragma --
5026 ------------------
5027
5028 procedure Error_Pragma (Msg : String) is
5029 MsgF : String := Msg;
5030 begin
5031 Error_Msg_Name_1 := Pname;
5032 Fix_Error (MsgF);
5033 Error_Msg_N (MsgF, N);
5034 raise Pragma_Exit;
5035 end Error_Pragma;
5036
5037 ----------------------
5038 -- Error_Pragma_Arg --
5039 ----------------------
5040
5041 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5042 MsgF : String := Msg;
5043 begin
5044 Error_Msg_Name_1 := Pname;
5045 Fix_Error (MsgF);
5046 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
5047 raise Pragma_Exit;
5048 end Error_Pragma_Arg;
5049
5050 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
5051 MsgF : String := Msg1;
5052 begin
5053 Error_Msg_Name_1 := Pname;
5054 Fix_Error (MsgF);
5055 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
5056 Error_Pragma_Arg (Msg2, Arg);
5057 end Error_Pragma_Arg;
5058
5059 ----------------------------
5060 -- Error_Pragma_Arg_Ident --
5061 ----------------------------
5062
5063 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5064 MsgF : String := Msg;
5065 begin
5066 Error_Msg_Name_1 := Pname;
5067 Fix_Error (MsgF);
5068 Error_Msg_N (MsgF, Arg);
5069 raise Pragma_Exit;
5070 end Error_Pragma_Arg_Ident;
5071
5072 ----------------------
5073 -- Error_Pragma_Ref --
5074 ----------------------
5075
5076 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5077 MsgF : String := Msg;
5078 begin
5079 Error_Msg_Name_1 := Pname;
5080 Fix_Error (MsgF);
5081 Error_Msg_Sloc := Sloc (Ref);
5082 Error_Msg_NE (MsgF, N, Ref);
5083 raise Pragma_Exit;
5084 end Error_Pragma_Ref;
5085
5086 ------------------------
5087 -- Find_Lib_Unit_Name --
5088 ------------------------
5089
5090 function Find_Lib_Unit_Name return Entity_Id is
5091 begin
5092 -- Return inner compilation unit entity, for case of nested
5093 -- categorization pragmas. This happens in generic unit.
5094
5095 if Nkind (Parent (N)) = N_Package_Specification
5096 and then Defining_Entity (Parent (N)) /= Current_Scope
5097 then
5098 return Defining_Entity (Parent (N));
5099 else
5100 return Current_Scope;
5101 end if;
5102 end Find_Lib_Unit_Name;
5103
5104 ----------------------------
5105 -- Find_Program_Unit_Name --
5106 ----------------------------
5107
5108 procedure Find_Program_Unit_Name (Id : Node_Id) is
5109 Unit_Name : Entity_Id;
5110 Unit_Kind : Node_Kind;
5111 P : constant Node_Id := Parent (N);
5112
5113 begin
5114 if Nkind (P) = N_Compilation_Unit then
5115 Unit_Kind := Nkind (Unit (P));
5116
5117 if Unit_Kind = N_Subprogram_Declaration
5118 or else Unit_Kind = N_Package_Declaration
5119 or else Unit_Kind in N_Generic_Declaration
5120 then
5121 Unit_Name := Defining_Entity (Unit (P));
5122
5123 if Chars (Id) = Chars (Unit_Name) then
5124 Set_Entity (Id, Unit_Name);
5125 Set_Etype (Id, Etype (Unit_Name));
5126 else
5127 Set_Etype (Id, Any_Type);
5128 Error_Pragma
5129 ("cannot find program unit referenced by pragma%");
5130 end if;
5131
5132 else
5133 Set_Etype (Id, Any_Type);
5134 Error_Pragma ("pragma% inapplicable to this unit");
5135 end if;
5136
5137 else
5138 Analyze (Id);
5139 end if;
5140 end Find_Program_Unit_Name;
5141
5142 -----------------------------------------
5143 -- Find_Unique_Parameterless_Procedure --
5144 -----------------------------------------
5145
5146 function Find_Unique_Parameterless_Procedure
5147 (Name : Entity_Id;
5148 Arg : Node_Id) return Entity_Id
5149 is
5150 Proc : Entity_Id := Empty;
5151
5152 begin
5153 -- The body of this procedure needs some comments ???
5154
5155 if not Is_Entity_Name (Name) then
5156 Error_Pragma_Arg
5157 ("argument of pragma% must be entity name", Arg);
5158
5159 elsif not Is_Overloaded (Name) then
5160 Proc := Entity (Name);
5161
5162 if Ekind (Proc) /= E_Procedure
5163 or else Present (First_Formal (Proc))
5164 then
5165 Error_Pragma_Arg
5166 ("argument of pragma% must be parameterless procedure", Arg);
5167 end if;
5168
5169 else
5170 declare
5171 Found : Boolean := False;
5172 It : Interp;
5173 Index : Interp_Index;
5174
5175 begin
5176 Get_First_Interp (Name, Index, It);
5177 while Present (It.Nam) loop
5178 Proc := It.Nam;
5179
5180 if Ekind (Proc) = E_Procedure
5181 and then No (First_Formal (Proc))
5182 then
5183 if not Found then
5184 Found := True;
5185 Set_Entity (Name, Proc);
5186 Set_Is_Overloaded (Name, False);
5187 else
5188 Error_Pragma_Arg
5189 ("ambiguous handler name for pragma% ", Arg);
5190 end if;
5191 end if;
5192
5193 Get_Next_Interp (Index, It);
5194 end loop;
5195
5196 if not Found then
5197 Error_Pragma_Arg
5198 ("argument of pragma% must be parameterless procedure",
5199 Arg);
5200 else
5201 Proc := Entity (Name);
5202 end if;
5203 end;
5204 end if;
5205
5206 return Proc;
5207 end Find_Unique_Parameterless_Procedure;
5208
5209 ---------------
5210 -- Fix_Error --
5211 ---------------
5212
5213 procedure Fix_Error (Msg : in out String) is
5214 begin
5215 -- If we have a rewriting of another pragma, go to that pragma
5216
5217 if Is_Rewrite_Substitution (N)
5218 and then Nkind (Original_Node (N)) = N_Pragma
5219 then
5220 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5221 end if;
5222
5223 -- Case where pragma comes from an aspect specification
5224
5225 if From_Aspect_Specification (N) then
5226
5227 -- Change appearence of "pragma" in message to "aspect"
5228
5229 for J in Msg'First .. Msg'Last - 5 loop
5230 if Msg (J .. J + 5) = "pragma" then
5231 Msg (J .. J + 5) := "aspect";
5232 end if;
5233 end loop;
5234
5235 -- Get name from corresponding aspect
5236
5237 Error_Msg_Name_1 := Original_Aspect_Name (N);
5238 end if;
5239 end Fix_Error;
5240
5241 -------------------------
5242 -- Gather_Associations --
5243 -------------------------
5244
5245 procedure Gather_Associations
5246 (Names : Name_List;
5247 Args : out Args_List)
5248 is
5249 Arg : Node_Id;
5250
5251 begin
5252 -- Initialize all parameters to Empty
5253
5254 for J in Args'Range loop
5255 Args (J) := Empty;
5256 end loop;
5257
5258 -- That's all we have to do if there are no argument associations
5259
5260 if No (Pragma_Argument_Associations (N)) then
5261 return;
5262 end if;
5263
5264 -- Otherwise first deal with any positional parameters present
5265
5266 Arg := First (Pragma_Argument_Associations (N));
5267 for Index in Args'Range loop
5268 exit when No (Arg) or else Chars (Arg) /= No_Name;
5269 Args (Index) := Get_Pragma_Arg (Arg);
5270 Next (Arg);
5271 end loop;
5272
5273 -- Positional parameters all processed, if any left, then we
5274 -- have too many positional parameters.
5275
5276 if Present (Arg) and then Chars (Arg) = No_Name then
5277 Error_Pragma_Arg
5278 ("too many positional associations for pragma%", Arg);
5279 end if;
5280
5281 -- Process named parameters if any are present
5282
5283 while Present (Arg) loop
5284 if Chars (Arg) = No_Name then
5285 Error_Pragma_Arg
5286 ("positional association cannot follow named association",
5287 Arg);
5288
5289 else
5290 for Index in Names'Range loop
5291 if Names (Index) = Chars (Arg) then
5292 if Present (Args (Index)) then
5293 Error_Pragma_Arg
5294 ("duplicate argument association for pragma%", Arg);
5295 else
5296 Args (Index) := Get_Pragma_Arg (Arg);
5297 exit;
5298 end if;
5299 end if;
5300
5301 if Index = Names'Last then
5302 Error_Msg_Name_1 := Pname;
5303 Error_Msg_N ("pragma% does not allow & argument", Arg);
5304
5305 -- Check for possible misspelling
5306
5307 for Index1 in Names'Range loop
5308 if Is_Bad_Spelling_Of
5309 (Chars (Arg), Names (Index1))
5310 then
5311 Error_Msg_Name_1 := Names (Index1);
5312 Error_Msg_N -- CODEFIX
5313 ("\possible misspelling of%", Arg);
5314 exit;
5315 end if;
5316 end loop;
5317
5318 raise Pragma_Exit;
5319 end if;
5320 end loop;
5321 end if;
5322
5323 Next (Arg);
5324 end loop;
5325 end Gather_Associations;
5326
5327 -----------------
5328 -- GNAT_Pragma --
5329 -----------------
5330
5331 procedure GNAT_Pragma is
5332 begin
5333 -- We need to check the No_Implementation_Pragmas restriction for
5334 -- the case of a pragma from source. Note that the case of aspects
5335 -- generating corresponding pragmas marks these pragmas as not being
5336 -- from source, so this test also catches that case.
5337
5338 if Comes_From_Source (N) then
5339 Check_Restriction (No_Implementation_Pragmas, N);
5340 end if;
5341 end GNAT_Pragma;
5342
5343 --------------------------
5344 -- Is_Before_First_Decl --
5345 --------------------------
5346
5347 function Is_Before_First_Decl
5348 (Pragma_Node : Node_Id;
5349 Decls : List_Id) return Boolean
5350 is
5351 Item : Node_Id := First (Decls);
5352
5353 begin
5354 -- Only other pragmas can come before this pragma
5355
5356 loop
5357 if No (Item) or else Nkind (Item) /= N_Pragma then
5358 return False;
5359
5360 elsif Item = Pragma_Node then
5361 return True;
5362 end if;
5363
5364 Next (Item);
5365 end loop;
5366 end Is_Before_First_Decl;
5367
5368 -----------------------------
5369 -- Is_Configuration_Pragma --
5370 -----------------------------
5371
5372 -- A configuration pragma must appear in the context clause of a
5373 -- compilation unit, and only other pragmas may precede it. Note that
5374 -- the test below also permits use in a configuration pragma file.
5375
5376 function Is_Configuration_Pragma return Boolean is
5377 Lis : constant List_Id := List_Containing (N);
5378 Par : constant Node_Id := Parent (N);
5379 Prg : Node_Id;
5380
5381 begin
5382 -- If no parent, then we are in the configuration pragma file,
5383 -- so the placement is definitely appropriate.
5384
5385 if No (Par) then
5386 return True;
5387
5388 -- Otherwise we must be in the context clause of a compilation unit
5389 -- and the only thing allowed before us in the context list is more
5390 -- configuration pragmas.
5391
5392 elsif Nkind (Par) = N_Compilation_Unit
5393 and then Context_Items (Par) = Lis
5394 then
5395 Prg := First (Lis);
5396
5397 loop
5398 if Prg = N then
5399 return True;
5400 elsif Nkind (Prg) /= N_Pragma then
5401 return False;
5402 end if;
5403
5404 Next (Prg);
5405 end loop;
5406
5407 else
5408 return False;
5409 end if;
5410 end Is_Configuration_Pragma;
5411
5412 --------------------------
5413 -- Is_In_Context_Clause --
5414 --------------------------
5415
5416 function Is_In_Context_Clause return Boolean is
5417 Plist : List_Id;
5418 Parent_Node : Node_Id;
5419
5420 begin
5421 if not Is_List_Member (N) then
5422 return False;
5423
5424 else
5425 Plist := List_Containing (N);
5426 Parent_Node := Parent (Plist);
5427
5428 if Parent_Node = Empty
5429 or else Nkind (Parent_Node) /= N_Compilation_Unit
5430 or else Context_Items (Parent_Node) /= Plist
5431 then
5432 return False;
5433 end if;
5434 end if;
5435
5436 return True;
5437 end Is_In_Context_Clause;
5438
5439 ---------------------------------
5440 -- Is_Static_String_Expression --
5441 ---------------------------------
5442
5443 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
5444 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5445
5446 begin
5447 Analyze_And_Resolve (Argx);
5448 return Is_OK_Static_Expression (Argx)
5449 and then Nkind (Argx) = N_String_Literal;
5450 end Is_Static_String_Expression;
5451
5452 ----------------------
5453 -- Pragma_Misplaced --
5454 ----------------------
5455
5456 procedure Pragma_Misplaced is
5457 begin
5458 Error_Pragma ("incorrect placement of pragma%");
5459 end Pragma_Misplaced;
5460
5461 ------------------------------------
5462 -- Process_Atomic_Shared_Volatile --
5463 ------------------------------------
5464
5465 procedure Process_Atomic_Shared_Volatile is
5466 E_Id : Node_Id;
5467 E : Entity_Id;
5468 D : Node_Id;
5469 K : Node_Kind;
5470 Utyp : Entity_Id;
5471
5472 procedure Set_Atomic (E : Entity_Id);
5473 -- Set given type as atomic, and if no explicit alignment was given,
5474 -- set alignment to unknown, since back end knows what the alignment
5475 -- requirements are for atomic arrays. Note: this step is necessary
5476 -- for derived types.
5477
5478 ----------------
5479 -- Set_Atomic --
5480 ----------------
5481
5482 procedure Set_Atomic (E : Entity_Id) is
5483 begin
5484 Set_Is_Atomic (E);
5485
5486 if not Has_Alignment_Clause (E) then
5487 Set_Alignment (E, Uint_0);
5488 end if;
5489 end Set_Atomic;
5490
5491 -- Start of processing for Process_Atomic_Shared_Volatile
5492
5493 begin
5494 Check_Ada_83_Warning;
5495 Check_No_Identifiers;
5496 Check_Arg_Count (1);
5497 Check_Arg_Is_Local_Name (Arg1);
5498 E_Id := Get_Pragma_Arg (Arg1);
5499
5500 if Etype (E_Id) = Any_Type then
5501 return;
5502 end if;
5503
5504 E := Entity (E_Id);
5505 D := Declaration_Node (E);
5506 K := Nkind (D);
5507
5508 -- Check duplicate before we chain ourselves!
5509
5510 Check_Duplicate_Pragma (E);
5511
5512 -- Now check appropriateness of the entity
5513
5514 if Is_Type (E) then
5515 if Rep_Item_Too_Early (E, N)
5516 or else
5517 Rep_Item_Too_Late (E, N)
5518 then
5519 return;
5520 else
5521 Check_First_Subtype (Arg1);
5522 end if;
5523
5524 if Prag_Id /= Pragma_Volatile then
5525 Set_Atomic (E);
5526 Set_Atomic (Underlying_Type (E));
5527 Set_Atomic (Base_Type (E));
5528 end if;
5529
5530 -- Attribute belongs on the base type. If the view of the type is
5531 -- currently private, it also belongs on the underlying type.
5532
5533 Set_Is_Volatile (Base_Type (E));
5534 Set_Is_Volatile (Underlying_Type (E));
5535
5536 Set_Treat_As_Volatile (E);
5537 Set_Treat_As_Volatile (Underlying_Type (E));
5538
5539 elsif K = N_Object_Declaration
5540 or else (K = N_Component_Declaration
5541 and then Original_Record_Component (E) = E)
5542 then
5543 if Rep_Item_Too_Late (E, N) then
5544 return;
5545 end if;
5546
5547 if Prag_Id /= Pragma_Volatile then
5548 Set_Is_Atomic (E);
5549
5550 -- If the object declaration has an explicit initialization, a
5551 -- temporary may have to be created to hold the expression, to
5552 -- ensure that access to the object remain atomic.
5553
5554 if Nkind (Parent (E)) = N_Object_Declaration
5555 and then Present (Expression (Parent (E)))
5556 then
5557 Set_Has_Delayed_Freeze (E);
5558 end if;
5559
5560 -- An interesting improvement here. If an object of composite
5561 -- type X is declared atomic, and the type X isn't, that's a
5562 -- pity, since it may not have appropriate alignment etc. We
5563 -- can rescue this in the special case where the object and
5564 -- type are in the same unit by just setting the type as
5565 -- atomic, so that the back end will process it as atomic.
5566
5567 -- Note: we used to do this for elementary types as well,
5568 -- but that turns out to be a bad idea and can have unwanted
5569 -- effects, most notably if the type is elementary, the object
5570 -- a simple component within a record, and both are in a spec:
5571 -- every object of this type in the entire program will be
5572 -- treated as atomic, thus incurring a potentially costly
5573 -- synchronization operation for every access.
5574
5575 -- Of course it would be best if the back end could just adjust
5576 -- the alignment etc for the specific object, but that's not
5577 -- something we are capable of doing at this point.
5578
5579 Utyp := Underlying_Type (Etype (E));
5580
5581 if Present (Utyp)
5582 and then Is_Composite_Type (Utyp)
5583 and then Sloc (E) > No_Location
5584 and then Sloc (Utyp) > No_Location
5585 and then
5586 Get_Source_File_Index (Sloc (E)) =
5587 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
5588 then
5589 Set_Is_Atomic (Underlying_Type (Etype (E)));
5590 end if;
5591 end if;
5592
5593 Set_Is_Volatile (E);
5594 Set_Treat_As_Volatile (E);
5595
5596 else
5597 Error_Pragma_Arg
5598 ("inappropriate entity for pragma%", Arg1);
5599 end if;
5600 end Process_Atomic_Shared_Volatile;
5601
5602 -------------------------------------------
5603 -- Process_Compile_Time_Warning_Or_Error --
5604 -------------------------------------------
5605
5606 procedure Process_Compile_Time_Warning_Or_Error is
5607 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
5608
5609 begin
5610 Check_Arg_Count (2);
5611 Check_No_Identifiers;
5612 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
5613 Analyze_And_Resolve (Arg1x, Standard_Boolean);
5614
5615 if Compile_Time_Known_Value (Arg1x) then
5616 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
5617 declare
5618 Str : constant String_Id :=
5619 Strval (Get_Pragma_Arg (Arg2));
5620 Len : constant Int := String_Length (Str);
5621 Cont : Boolean;
5622 Ptr : Nat;
5623 CC : Char_Code;
5624 C : Character;
5625 Cent : constant Entity_Id :=
5626 Cunit_Entity (Current_Sem_Unit);
5627
5628 Force : constant Boolean :=
5629 Prag_Id = Pragma_Compile_Time_Warning
5630 and then
5631 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
5632 and then (Ekind (Cent) /= E_Package
5633 or else not In_Private_Part (Cent));
5634 -- Set True if this is the warning case, and we are in the
5635 -- visible part of a package spec, or in a subprogram spec,
5636 -- in which case we want to force the client to see the
5637 -- warning, even though it is not in the main unit.
5638
5639 begin
5640 -- Loop through segments of message separated by line feeds.
5641 -- We output these segments as separate messages with
5642 -- continuation marks for all but the first.
5643
5644 Cont := False;
5645 Ptr := 1;
5646 loop
5647 Error_Msg_Strlen := 0;
5648
5649 -- Loop to copy characters from argument to error message
5650 -- string buffer.
5651
5652 loop
5653 exit when Ptr > Len;
5654 CC := Get_String_Char (Str, Ptr);
5655 Ptr := Ptr + 1;
5656
5657 -- Ignore wide chars ??? else store character
5658
5659 if In_Character_Range (CC) then
5660 C := Get_Character (CC);
5661 exit when C = ASCII.LF;
5662 Error_Msg_Strlen := Error_Msg_Strlen + 1;
5663 Error_Msg_String (Error_Msg_Strlen) := C;
5664 end if;
5665 end loop;
5666
5667 -- Here with one line ready to go
5668
5669 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
5670
5671 -- If this is a warning in a spec, then we want clients
5672 -- to see the warning, so mark the message with the
5673 -- special sequence !! to force the warning. In the case
5674 -- of a package spec, we do not force this if we are in
5675 -- the private part of the spec.
5676
5677 if Force then
5678 if Cont = False then
5679 Error_Msg_N ("<~!!", Arg1);
5680 Cont := True;
5681 else
5682 Error_Msg_N ("\<~!!", Arg1);
5683 end if;
5684
5685 -- Error, rather than warning, or in a body, so we do not
5686 -- need to force visibility for client (error will be
5687 -- output in any case, and this is the situation in which
5688 -- we do not want a client to get a warning, since the
5689 -- warning is in the body or the spec private part).
5690
5691 else
5692 if Cont = False then
5693 Error_Msg_N ("<~", Arg1);
5694 Cont := True;
5695 else
5696 Error_Msg_N ("\<~", Arg1);
5697 end if;
5698 end if;
5699
5700 exit when Ptr > Len;
5701 end loop;
5702 end;
5703 end if;
5704 end if;
5705 end Process_Compile_Time_Warning_Or_Error;
5706
5707 ------------------------
5708 -- Process_Convention --
5709 ------------------------
5710
5711 procedure Process_Convention
5712 (C : out Convention_Id;
5713 Ent : out Entity_Id)
5714 is
5715 Id : Node_Id;
5716 E : Entity_Id;
5717 E1 : Entity_Id;
5718 Cname : Name_Id;
5719 Comp_Unit : Unit_Number_Type;
5720
5721 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
5722 -- Called if we have more than one Export/Import/Convention pragma.
5723 -- This is generally illegal, but we have a special case of allowing
5724 -- Import and Interface to coexist if they specify the convention in
5725 -- a consistent manner. We are allowed to do this, since Interface is
5726 -- an implementation defined pragma, and we choose to do it since we
5727 -- know Rational allows this combination. S is the entity id of the
5728 -- subprogram in question. This procedure also sets the special flag
5729 -- Import_Interface_Present in both pragmas in the case where we do
5730 -- have matching Import and Interface pragmas.
5731
5732 procedure Set_Convention_From_Pragma (E : Entity_Id);
5733 -- Set convention in entity E, and also flag that the entity has a
5734 -- convention pragma. If entity is for a private or incomplete type,
5735 -- also set convention and flag on underlying type. This procedure
5736 -- also deals with the special case of C_Pass_By_Copy convention.
5737
5738 -------------------------------
5739 -- Diagnose_Multiple_Pragmas --
5740 -------------------------------
5741
5742 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
5743 Pdec : constant Node_Id := Declaration_Node (S);
5744 Decl : Node_Id;
5745 Err : Boolean;
5746
5747 function Same_Convention (Decl : Node_Id) return Boolean;
5748 -- Decl is a pragma node. This function returns True if this
5749 -- pragma has a first argument that is an identifier with a
5750 -- Chars field corresponding to the Convention_Id C.
5751
5752 function Same_Name (Decl : Node_Id) return Boolean;
5753 -- Decl is a pragma node. This function returns True if this
5754 -- pragma has a second argument that is an identifier with a
5755 -- Chars field that matches the Chars of the current subprogram.
5756
5757 ---------------------
5758 -- Same_Convention --
5759 ---------------------
5760
5761 function Same_Convention (Decl : Node_Id) return Boolean is
5762 Arg1 : constant Node_Id :=
5763 First (Pragma_Argument_Associations (Decl));
5764
5765 begin
5766 if Present (Arg1) then
5767 declare
5768 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
5769 begin
5770 if Nkind (Arg) = N_Identifier
5771 and then Is_Convention_Name (Chars (Arg))
5772 and then Get_Convention_Id (Chars (Arg)) = C
5773 then
5774 return True;
5775 end if;
5776 end;
5777 end if;
5778
5779 return False;
5780 end Same_Convention;
5781
5782 ---------------
5783 -- Same_Name --
5784 ---------------
5785
5786 function Same_Name (Decl : Node_Id) return Boolean is
5787 Arg1 : constant Node_Id :=
5788 First (Pragma_Argument_Associations (Decl));
5789 Arg2 : Node_Id;
5790
5791 begin
5792 if No (Arg1) then
5793 return False;
5794 end if;
5795
5796 Arg2 := Next (Arg1);
5797
5798 if No (Arg2) then
5799 return False;
5800 end if;
5801
5802 declare
5803 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
5804 begin
5805 if Nkind (Arg) = N_Identifier
5806 and then Chars (Arg) = Chars (S)
5807 then
5808 return True;
5809 end if;
5810 end;
5811
5812 return False;
5813 end Same_Name;
5814
5815 -- Start of processing for Diagnose_Multiple_Pragmas
5816
5817 begin
5818 Err := True;
5819
5820 -- Definitely give message if we have Convention/Export here
5821
5822 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
5823 null;
5824
5825 -- If we have an Import or Export, scan back from pragma to
5826 -- find any previous pragma applying to the same procedure.
5827 -- The scan will be terminated by the start of the list, or
5828 -- hitting the subprogram declaration. This won't allow one
5829 -- pragma to appear in the public part and one in the private
5830 -- part, but that seems very unlikely in practice.
5831
5832 else
5833 Decl := Prev (N);
5834 while Present (Decl) and then Decl /= Pdec loop
5835
5836 -- Look for pragma with same name as us
5837
5838 if Nkind (Decl) = N_Pragma
5839 and then Same_Name (Decl)
5840 then
5841 -- Give error if same as our pragma or Export/Convention
5842
5843 if Nam_In (Pragma_Name (Decl), Name_Export,
5844 Name_Convention,
5845 Pragma_Name (N))
5846 then
5847 exit;
5848
5849 -- Case of Import/Interface or the other way round
5850
5851 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
5852 Name_Import)
5853 then
5854 -- Here we know that we have Import and Interface. It
5855 -- doesn't matter which way round they are. See if
5856 -- they specify the same convention. If so, all OK,
5857 -- and set special flags to stop other messages
5858
5859 if Same_Convention (Decl) then
5860 Set_Import_Interface_Present (N);
5861 Set_Import_Interface_Present (Decl);
5862 Err := False;
5863
5864 -- If different conventions, special message
5865
5866 else
5867 Error_Msg_Sloc := Sloc (Decl);
5868 Error_Pragma_Arg
5869 ("convention differs from that given#", Arg1);
5870 return;
5871 end if;
5872 end if;
5873 end if;
5874
5875 Next (Decl);
5876 end loop;
5877 end if;
5878
5879 -- Give message if needed if we fall through those tests
5880 -- except on Relaxed_RM_Semantics where we let go: either this
5881 -- is a case accepted/ignored by other Ada compilers (e.g.
5882 -- a mix of Convention and Import), or another error will be
5883 -- generated later (e.g. using both Import and Export).
5884
5885 if Err and not Relaxed_RM_Semantics then
5886 Error_Pragma_Arg
5887 ("at most one Convention/Export/Import pragma is allowed",
5888 Arg2);
5889 end if;
5890 end Diagnose_Multiple_Pragmas;
5891
5892 --------------------------------
5893 -- Set_Convention_From_Pragma --
5894 --------------------------------
5895
5896 procedure Set_Convention_From_Pragma (E : Entity_Id) is
5897 begin
5898 -- Ada 2005 (AI-430): Check invalid attempt to change convention
5899 -- for an overridden dispatching operation. Technically this is
5900 -- an amendment and should only be done in Ada 2005 mode. However,
5901 -- this is clearly a mistake, since the problem that is addressed
5902 -- by this AI is that there is a clear gap in the RM!
5903
5904 if Is_Dispatching_Operation (E)
5905 and then Present (Overridden_Operation (E))
5906 and then C /= Convention (Overridden_Operation (E))
5907 then
5908 -- An attempt to override a subprogram with a ghost subprogram
5909 -- appears as a mismatch in conventions.
5910
5911 if C = Convention_Ghost then
5912 Error_Msg_N ("ghost subprogram & cannot be overriding", E);
5913 else
5914 Error_Pragma_Arg
5915 ("cannot change convention for overridden dispatching "
5916 & "operation", Arg1);
5917 end if;
5918 end if;
5919
5920 -- Special checks for Convention_Stdcall
5921
5922 if C = Convention_Stdcall then
5923
5924 -- A dispatching call is not allowed. A dispatching subprogram
5925 -- cannot be used to interface to the Win32 API, so in fact
5926 -- this check does not impose any effective restriction.
5927
5928 if Is_Dispatching_Operation (E) then
5929 Error_Msg_Sloc := Sloc (E);
5930
5931 -- Note: make this unconditional so that if there is more
5932 -- than one call to which the pragma applies, we get a
5933 -- message for each call. Also don't use Error_Pragma,
5934 -- so that we get multiple messages!
5935
5936 Error_Msg_N
5937 ("dispatching subprogram# cannot use Stdcall convention!",
5938 Arg1);
5939
5940 -- Subprogram is allowed, but not a generic subprogram
5941
5942 elsif not Is_Subprogram (E)
5943 and then not Is_Generic_Subprogram (E)
5944
5945 -- A variable is OK
5946
5947 and then Ekind (E) /= E_Variable
5948
5949 -- An access to subprogram is also allowed
5950
5951 and then not
5952 (Is_Access_Type (E)
5953 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
5954
5955 -- Allow internal call to set convention of subprogram type
5956
5957 and then not (Ekind (E) = E_Subprogram_Type)
5958 then
5959 Error_Pragma_Arg
5960 ("second argument of pragma% must be subprogram (type)",
5961 Arg2);
5962 end if;
5963 end if;
5964
5965 -- Set the convention
5966
5967 Set_Convention (E, C);
5968 Set_Has_Convention_Pragma (E);
5969
5970 if Is_Incomplete_Or_Private_Type (E)
5971 and then Present (Underlying_Type (E))
5972 then
5973 Set_Convention (Underlying_Type (E), C);
5974 Set_Has_Convention_Pragma (Underlying_Type (E), True);
5975 end if;
5976
5977 -- A class-wide type should inherit the convention of the specific
5978 -- root type (although this isn't specified clearly by the RM).
5979
5980 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
5981 Set_Convention (Class_Wide_Type (E), C);
5982 end if;
5983
5984 -- If the entity is a record type, then check for special case of
5985 -- C_Pass_By_Copy, which is treated the same as C except that the
5986 -- special record flag is set. This convention is only permitted
5987 -- on record types (see AI95-00131).
5988
5989 if Cname = Name_C_Pass_By_Copy then
5990 if Is_Record_Type (E) then
5991 Set_C_Pass_By_Copy (Base_Type (E));
5992 elsif Is_Incomplete_Or_Private_Type (E)
5993 and then Is_Record_Type (Underlying_Type (E))
5994 then
5995 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
5996 else
5997 Error_Pragma_Arg
5998 ("C_Pass_By_Copy convention allowed only for record type",
5999 Arg2);
6000 end if;
6001 end if;
6002
6003 -- If the entity is a derived boolean type, check for the special
6004 -- case of convention C, C++, or Fortran, where we consider any
6005 -- nonzero value to represent true.
6006
6007 if Is_Discrete_Type (E)
6008 and then Root_Type (Etype (E)) = Standard_Boolean
6009 and then
6010 (C = Convention_C
6011 or else
6012 C = Convention_CPP
6013 or else
6014 C = Convention_Fortran)
6015 then
6016 Set_Nonzero_Is_True (Base_Type (E));
6017 end if;
6018 end Set_Convention_From_Pragma;
6019
6020 -- Start of processing for Process_Convention
6021
6022 begin
6023 Check_At_Least_N_Arguments (2);
6024 Check_Optional_Identifier (Arg1, Name_Convention);
6025 Check_Arg_Is_Identifier (Arg1);
6026 Cname := Chars (Get_Pragma_Arg (Arg1));
6027
6028 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6029 -- tested again below to set the critical flag).
6030
6031 if Cname = Name_C_Pass_By_Copy then
6032 C := Convention_C;
6033
6034 -- Otherwise we must have something in the standard convention list
6035
6036 elsif Is_Convention_Name (Cname) then
6037 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
6038
6039 -- In DEC VMS, it seems that there is an undocumented feature that
6040 -- any unrecognized convention is treated as the default, which for
6041 -- us is convention C. It does not seem so terrible to do this
6042 -- unconditionally, silently in the VMS case, and with a warning
6043 -- in the non-VMS case.
6044
6045 else
6046 if Warn_On_Export_Import and not OpenVMS_On_Target then
6047 Error_Msg_N
6048 ("??unrecognized convention name, C assumed",
6049 Get_Pragma_Arg (Arg1));
6050 end if;
6051
6052 C := Convention_C;
6053 end if;
6054
6055 Check_Optional_Identifier (Arg2, Name_Entity);
6056 Check_Arg_Is_Local_Name (Arg2);
6057
6058 Id := Get_Pragma_Arg (Arg2);
6059 Analyze (Id);
6060
6061 if not Is_Entity_Name (Id) then
6062 Error_Pragma_Arg ("entity name required", Arg2);
6063 end if;
6064
6065 E := Entity (Id);
6066
6067 -- Set entity to return
6068
6069 Ent := E;
6070
6071 -- Ada_Pass_By_Copy special checking
6072
6073 if C = Convention_Ada_Pass_By_Copy then
6074 if not Is_First_Subtype (E) then
6075 Error_Pragma_Arg
6076 ("convention `Ada_Pass_By_Copy` only allowed for types",
6077 Arg2);
6078 end if;
6079
6080 if Is_By_Reference_Type (E) then
6081 Error_Pragma_Arg
6082 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6083 & "type", Arg1);
6084 end if;
6085 end if;
6086
6087 -- Ada_Pass_By_Reference special checking
6088
6089 if C = Convention_Ada_Pass_By_Reference then
6090 if not Is_First_Subtype (E) then
6091 Error_Pragma_Arg
6092 ("convention `Ada_Pass_By_Reference` only allowed for types",
6093 Arg2);
6094 end if;
6095
6096 if Is_By_Copy_Type (E) then
6097 Error_Pragma_Arg
6098 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6099 & "type", Arg1);
6100 end if;
6101 end if;
6102
6103 -- Ghost special checking
6104
6105 if Is_Ghost_Subprogram (E)
6106 and then Present (Overridden_Operation (E))
6107 then
6108 Error_Msg_N ("ghost subprogram & cannot be overriding", E);
6109 end if;
6110
6111 -- Go to renamed subprogram if present, since convention applies to
6112 -- the actual renamed entity, not to the renaming entity. If the
6113 -- subprogram is inherited, go to parent subprogram.
6114
6115 if Is_Subprogram (E)
6116 and then Present (Alias (E))
6117 then
6118 if Nkind (Parent (Declaration_Node (E))) =
6119 N_Subprogram_Renaming_Declaration
6120 then
6121 if Scope (E) /= Scope (Alias (E)) then
6122 Error_Pragma_Ref
6123 ("cannot apply pragma% to non-local entity&#", E);
6124 end if;
6125
6126 E := Alias (E);
6127
6128 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6129 N_Private_Extension_Declaration)
6130 and then Scope (E) = Scope (Alias (E))
6131 then
6132 E := Alias (E);
6133
6134 -- Return the parent subprogram the entity was inherited from
6135
6136 Ent := E;
6137 end if;
6138 end if;
6139
6140 -- Check that we are not applying this to a specless body
6141 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
6142 -- compilers.
6143
6144 if Is_Subprogram (E)
6145 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6146 and then not Relaxed_RM_Semantics
6147 then
6148 Error_Pragma
6149 ("pragma% requires separate spec and must come before body");
6150 end if;
6151
6152 -- Check that we are not applying this to a named constant
6153
6154 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6155 Error_Msg_Name_1 := Pname;
6156 Error_Msg_N
6157 ("cannot apply pragma% to named constant!",
6158 Get_Pragma_Arg (Arg2));
6159 Error_Pragma_Arg
6160 ("\supply appropriate type for&!", Arg2);
6161 end if;
6162
6163 if Ekind (E) = E_Enumeration_Literal then
6164 Error_Pragma ("enumeration literal not allowed for pragma%");
6165 end if;
6166
6167 -- Check for rep item appearing too early or too late
6168
6169 if Etype (E) = Any_Type
6170 or else Rep_Item_Too_Early (E, N)
6171 then
6172 raise Pragma_Exit;
6173
6174 elsif Present (Underlying_Type (E)) then
6175 E := Underlying_Type (E);
6176 end if;
6177
6178 if Rep_Item_Too_Late (E, N) then
6179 raise Pragma_Exit;
6180 end if;
6181
6182 if Has_Convention_Pragma (E) then
6183 Diagnose_Multiple_Pragmas (E);
6184
6185 elsif Convention (E) = Convention_Protected
6186 or else Ekind (Scope (E)) = E_Protected_Type
6187 then
6188 Error_Pragma_Arg
6189 ("a protected operation cannot be given a different convention",
6190 Arg2);
6191 end if;
6192
6193 -- For Intrinsic, a subprogram is required
6194
6195 if C = Convention_Intrinsic
6196 and then not Is_Subprogram (E)
6197 and then not Is_Generic_Subprogram (E)
6198 then
6199 Error_Pragma_Arg
6200 ("second argument of pragma% must be a subprogram", Arg2);
6201 end if;
6202
6203 -- Deal with non-subprogram cases
6204
6205 if not Is_Subprogram (E)
6206 and then not Is_Generic_Subprogram (E)
6207 then
6208 Set_Convention_From_Pragma (E);
6209
6210 if Is_Type (E) then
6211 Check_First_Subtype (Arg2);
6212 Set_Convention_From_Pragma (Base_Type (E));
6213
6214 -- For access subprograms, we must set the convention on the
6215 -- internally generated directly designated type as well.
6216
6217 if Ekind (E) = E_Access_Subprogram_Type then
6218 Set_Convention_From_Pragma (Directly_Designated_Type (E));
6219 end if;
6220 end if;
6221
6222 -- For the subprogram case, set proper convention for all homonyms
6223 -- in same scope and the same declarative part, i.e. the same
6224 -- compilation unit.
6225
6226 else
6227 Comp_Unit := Get_Source_Unit (E);
6228 Set_Convention_From_Pragma (E);
6229
6230 -- Treat a pragma Import as an implicit body, and pragma import
6231 -- as implicit reference (for navigation in GPS).
6232
6233 if Prag_Id = Pragma_Import then
6234 Generate_Reference (E, Id, 'b');
6235
6236 -- For exported entities we restrict the generation of references
6237 -- to entities exported to foreign languages since entities
6238 -- exported to Ada do not provide further information to GPS and
6239 -- add undesired references to the output of the gnatxref tool.
6240
6241 elsif Prag_Id = Pragma_Export
6242 and then Convention (E) /= Convention_Ada
6243 then
6244 Generate_Reference (E, Id, 'i');
6245 end if;
6246
6247 -- If the pragma comes from from an aspect, it only applies to the
6248 -- given entity, not its homonyms.
6249
6250 if From_Aspect_Specification (N) then
6251 return;
6252 end if;
6253
6254 -- Otherwise Loop through the homonyms of the pragma argument's
6255 -- entity, an apply convention to those in the current scope.
6256
6257 E1 := Ent;
6258
6259 loop
6260 E1 := Homonym (E1);
6261 exit when No (E1) or else Scope (E1) /= Current_Scope;
6262
6263 -- Ignore entry for which convention is already set
6264
6265 if Has_Convention_Pragma (E1) then
6266 goto Continue;
6267 end if;
6268
6269 -- Do not set the pragma on inherited operations or on formal
6270 -- subprograms.
6271
6272 if Comes_From_Source (E1)
6273 and then Comp_Unit = Get_Source_Unit (E1)
6274 and then not Is_Formal_Subprogram (E1)
6275 and then Nkind (Original_Node (Parent (E1))) /=
6276 N_Full_Type_Declaration
6277 then
6278 if Present (Alias (E1))
6279 and then Scope (E1) /= Scope (Alias (E1))
6280 then
6281 Error_Pragma_Ref
6282 ("cannot apply pragma% to non-local entity& declared#",
6283 E1);
6284 end if;
6285
6286 Set_Convention_From_Pragma (E1);
6287
6288 if Prag_Id = Pragma_Import then
6289 Generate_Reference (E1, Id, 'b');
6290 end if;
6291 end if;
6292
6293 <<Continue>>
6294 null;
6295 end loop;
6296 end if;
6297 end Process_Convention;
6298
6299 ----------------------------------------
6300 -- Process_Disable_Enable_Atomic_Sync --
6301 ----------------------------------------
6302
6303 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
6304 begin
6305 Check_No_Identifiers;
6306 Check_At_Most_N_Arguments (1);
6307
6308 -- Modeled internally as
6309 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
6310
6311 Rewrite (N,
6312 Make_Pragma (Loc,
6313 Pragma_Identifier =>
6314 Make_Identifier (Loc, Nam),
6315 Pragma_Argument_Associations => New_List (
6316 Make_Pragma_Argument_Association (Loc,
6317 Expression =>
6318 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
6319
6320 if Present (Arg1) then
6321 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
6322 end if;
6323
6324 Analyze (N);
6325 end Process_Disable_Enable_Atomic_Sync;
6326
6327 -----------------------------------------------------
6328 -- Process_Extended_Import_Export_Exception_Pragma --
6329 -----------------------------------------------------
6330
6331 procedure Process_Extended_Import_Export_Exception_Pragma
6332 (Arg_Internal : Node_Id;
6333 Arg_External : Node_Id;
6334 Arg_Form : Node_Id;
6335 Arg_Code : Node_Id)
6336 is
6337 Def_Id : Entity_Id;
6338 Code_Val : Uint;
6339
6340 begin
6341 if not OpenVMS_On_Target then
6342 Error_Pragma
6343 ("??pragma% ignored (applies only to Open'V'M'S)");
6344 end if;
6345
6346 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6347 Def_Id := Entity (Arg_Internal);
6348
6349 if Ekind (Def_Id) /= E_Exception then
6350 Error_Pragma_Arg
6351 ("pragma% must refer to declared exception", Arg_Internal);
6352 end if;
6353
6354 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
6355
6356 if Present (Arg_Form) then
6357 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
6358 end if;
6359
6360 if Present (Arg_Form)
6361 and then Chars (Arg_Form) = Name_Ada
6362 then
6363 null;
6364 else
6365 Set_Is_VMS_Exception (Def_Id);
6366 Set_Exception_Code (Def_Id, No_Uint);
6367 end if;
6368
6369 if Present (Arg_Code) then
6370 if not Is_VMS_Exception (Def_Id) then
6371 Error_Pragma_Arg
6372 ("Code option for pragma% not allowed for Ada case",
6373 Arg_Code);
6374 end if;
6375
6376 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
6377 Code_Val := Expr_Value (Arg_Code);
6378
6379 if not UI_Is_In_Int_Range (Code_Val) then
6380 Error_Pragma_Arg
6381 ("Code option for pragma% must be in 32-bit range",
6382 Arg_Code);
6383
6384 else
6385 Set_Exception_Code (Def_Id, Code_Val);
6386 end if;
6387 end if;
6388 end Process_Extended_Import_Export_Exception_Pragma;
6389
6390 -------------------------------------------------
6391 -- Process_Extended_Import_Export_Internal_Arg --
6392 -------------------------------------------------
6393
6394 procedure Process_Extended_Import_Export_Internal_Arg
6395 (Arg_Internal : Node_Id := Empty)
6396 is
6397 begin
6398 if No (Arg_Internal) then
6399 Error_Pragma ("Internal parameter required for pragma%");
6400 end if;
6401
6402 if Nkind (Arg_Internal) = N_Identifier then
6403 null;
6404
6405 elsif Nkind (Arg_Internal) = N_Operator_Symbol
6406 and then (Prag_Id = Pragma_Import_Function
6407 or else
6408 Prag_Id = Pragma_Export_Function)
6409 then
6410 null;
6411
6412 else
6413 Error_Pragma_Arg
6414 ("wrong form for Internal parameter for pragma%", Arg_Internal);
6415 end if;
6416
6417 Check_Arg_Is_Local_Name (Arg_Internal);
6418 end Process_Extended_Import_Export_Internal_Arg;
6419
6420 --------------------------------------------------
6421 -- Process_Extended_Import_Export_Object_Pragma --
6422 --------------------------------------------------
6423
6424 procedure Process_Extended_Import_Export_Object_Pragma
6425 (Arg_Internal : Node_Id;
6426 Arg_External : Node_Id;
6427 Arg_Size : Node_Id)
6428 is
6429 Def_Id : Entity_Id;
6430
6431 begin
6432 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6433 Def_Id := Entity (Arg_Internal);
6434
6435 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
6436 Error_Pragma_Arg
6437 ("pragma% must designate an object", Arg_Internal);
6438 end if;
6439
6440 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
6441 or else
6442 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
6443 then
6444 Error_Pragma_Arg
6445 ("previous Common/Psect_Object applies, pragma % not permitted",
6446 Arg_Internal);
6447 end if;
6448
6449 if Rep_Item_Too_Late (Def_Id, N) then
6450 raise Pragma_Exit;
6451 end if;
6452
6453 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
6454
6455 if Present (Arg_Size) then
6456 Check_Arg_Is_External_Name (Arg_Size);
6457 end if;
6458
6459 -- Export_Object case
6460
6461 if Prag_Id = Pragma_Export_Object then
6462 if not Is_Library_Level_Entity (Def_Id) then
6463 Error_Pragma_Arg
6464 ("argument for pragma% must be library level entity",
6465 Arg_Internal);
6466 end if;
6467
6468 if Ekind (Current_Scope) = E_Generic_Package then
6469 Error_Pragma ("pragma& cannot appear in a generic unit");
6470 end if;
6471
6472 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
6473 Error_Pragma_Arg
6474 ("exported object must have compile time known size",
6475 Arg_Internal);
6476 end if;
6477
6478 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
6479 Error_Msg_N ("??duplicate Export_Object pragma", N);
6480 else
6481 Set_Exported (Def_Id, Arg_Internal);
6482 end if;
6483
6484 -- Import_Object case
6485
6486 else
6487 if Is_Concurrent_Type (Etype (Def_Id)) then
6488 Error_Pragma_Arg
6489 ("cannot use pragma% for task/protected object",
6490 Arg_Internal);
6491 end if;
6492
6493 if Ekind (Def_Id) = E_Constant then
6494 Error_Pragma_Arg
6495 ("cannot import a constant", Arg_Internal);
6496 end if;
6497
6498 if Warn_On_Export_Import
6499 and then Has_Discriminants (Etype (Def_Id))
6500 then
6501 Error_Msg_N
6502 ("imported value must be initialized??", Arg_Internal);
6503 end if;
6504
6505 if Warn_On_Export_Import
6506 and then Is_Access_Type (Etype (Def_Id))
6507 then
6508 Error_Pragma_Arg
6509 ("cannot import object of an access type??", Arg_Internal);
6510 end if;
6511
6512 if Warn_On_Export_Import
6513 and then Is_Imported (Def_Id)
6514 then
6515 Error_Msg_N ("??duplicate Import_Object pragma", N);
6516
6517 -- Check for explicit initialization present. Note that an
6518 -- initialization generated by the code generator, e.g. for an
6519 -- access type, does not count here.
6520
6521 elsif Present (Expression (Parent (Def_Id)))
6522 and then
6523 Comes_From_Source
6524 (Original_Node (Expression (Parent (Def_Id))))
6525 then
6526 Error_Msg_Sloc := Sloc (Def_Id);
6527 Error_Pragma_Arg
6528 ("imported entities cannot be initialized (RM B.1(24))",
6529 "\no initialization allowed for & declared#", Arg1);
6530 else
6531 Set_Imported (Def_Id);
6532 Note_Possible_Modification (Arg_Internal, Sure => False);
6533 end if;
6534 end if;
6535 end Process_Extended_Import_Export_Object_Pragma;
6536
6537 ------------------------------------------------------
6538 -- Process_Extended_Import_Export_Subprogram_Pragma --
6539 ------------------------------------------------------
6540
6541 procedure Process_Extended_Import_Export_Subprogram_Pragma
6542 (Arg_Internal : Node_Id;
6543 Arg_External : Node_Id;
6544 Arg_Parameter_Types : Node_Id;
6545 Arg_Result_Type : Node_Id := Empty;
6546 Arg_Mechanism : Node_Id;
6547 Arg_Result_Mechanism : Node_Id := Empty;
6548 Arg_First_Optional_Parameter : Node_Id := Empty)
6549 is
6550 Ent : Entity_Id;
6551 Def_Id : Entity_Id;
6552 Hom_Id : Entity_Id;
6553 Formal : Entity_Id;
6554 Ambiguous : Boolean;
6555 Match : Boolean;
6556 Dval : Node_Id;
6557
6558 function Same_Base_Type
6559 (Ptype : Node_Id;
6560 Formal : Entity_Id) return Boolean;
6561 -- Determines if Ptype references the type of Formal. Note that only
6562 -- the base types need to match according to the spec. Ptype here is
6563 -- the argument from the pragma, which is either a type name, or an
6564 -- access attribute.
6565
6566 --------------------
6567 -- Same_Base_Type --
6568 --------------------
6569
6570 function Same_Base_Type
6571 (Ptype : Node_Id;
6572 Formal : Entity_Id) return Boolean
6573 is
6574 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
6575 Pref : Node_Id;
6576
6577 begin
6578 -- Case where pragma argument is typ'Access
6579
6580 if Nkind (Ptype) = N_Attribute_Reference
6581 and then Attribute_Name (Ptype) = Name_Access
6582 then
6583 Pref := Prefix (Ptype);
6584 Find_Type (Pref);
6585
6586 if not Is_Entity_Name (Pref)
6587 or else Entity (Pref) = Any_Type
6588 then
6589 raise Pragma_Exit;
6590 end if;
6591
6592 -- We have a match if the corresponding argument is of an
6593 -- anonymous access type, and its designated type matches the
6594 -- type of the prefix of the access attribute
6595
6596 return Ekind (Ftyp) = E_Anonymous_Access_Type
6597 and then Base_Type (Entity (Pref)) =
6598 Base_Type (Etype (Designated_Type (Ftyp)));
6599
6600 -- Case where pragma argument is a type name
6601
6602 else
6603 Find_Type (Ptype);
6604
6605 if not Is_Entity_Name (Ptype)
6606 or else Entity (Ptype) = Any_Type
6607 then
6608 raise Pragma_Exit;
6609 end if;
6610
6611 -- We have a match if the corresponding argument is of the type
6612 -- given in the pragma (comparing base types)
6613
6614 return Base_Type (Entity (Ptype)) = Ftyp;
6615 end if;
6616 end Same_Base_Type;
6617
6618 -- Start of processing for
6619 -- Process_Extended_Import_Export_Subprogram_Pragma
6620
6621 begin
6622 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6623 Ent := Empty;
6624 Ambiguous := False;
6625
6626 -- Loop through homonyms (overloadings) of the entity
6627
6628 Hom_Id := Entity (Arg_Internal);
6629 while Present (Hom_Id) loop
6630 Def_Id := Get_Base_Subprogram (Hom_Id);
6631
6632 -- We need a subprogram in the current scope
6633
6634 if not Is_Subprogram (Def_Id)
6635 or else Scope (Def_Id) /= Current_Scope
6636 then
6637 null;
6638
6639 else
6640 Match := True;
6641
6642 -- Pragma cannot apply to subprogram body
6643
6644 if Is_Subprogram (Def_Id)
6645 and then Nkind (Parent (Declaration_Node (Def_Id))) =
6646 N_Subprogram_Body
6647 then
6648 Error_Pragma
6649 ("pragma% requires separate spec"
6650 & " and must come before body");
6651 end if;
6652
6653 -- Test result type if given, note that the result type
6654 -- parameter can only be present for the function cases.
6655
6656 if Present (Arg_Result_Type)
6657 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
6658 then
6659 Match := False;
6660
6661 elsif Etype (Def_Id) /= Standard_Void_Type
6662 and then
6663 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
6664 then
6665 Match := False;
6666
6667 -- Test parameter types if given. Note that this parameter
6668 -- has not been analyzed (and must not be, since it is
6669 -- semantic nonsense), so we get it as the parser left it.
6670
6671 elsif Present (Arg_Parameter_Types) then
6672 Check_Matching_Types : declare
6673 Formal : Entity_Id;
6674 Ptype : Node_Id;
6675
6676 begin
6677 Formal := First_Formal (Def_Id);
6678
6679 if Nkind (Arg_Parameter_Types) = N_Null then
6680 if Present (Formal) then
6681 Match := False;
6682 end if;
6683
6684 -- A list of one type, e.g. (List) is parsed as
6685 -- a parenthesized expression.
6686
6687 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
6688 and then Paren_Count (Arg_Parameter_Types) = 1
6689 then
6690 if No (Formal)
6691 or else Present (Next_Formal (Formal))
6692 then
6693 Match := False;
6694 else
6695 Match :=
6696 Same_Base_Type (Arg_Parameter_Types, Formal);
6697 end if;
6698
6699 -- A list of more than one type is parsed as a aggregate
6700
6701 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
6702 and then Paren_Count (Arg_Parameter_Types) = 0
6703 then
6704 Ptype := First (Expressions (Arg_Parameter_Types));
6705 while Present (Ptype) or else Present (Formal) loop
6706 if No (Ptype)
6707 or else No (Formal)
6708 or else not Same_Base_Type (Ptype, Formal)
6709 then
6710 Match := False;
6711 exit;
6712 else
6713 Next_Formal (Formal);
6714 Next (Ptype);
6715 end if;
6716 end loop;
6717
6718 -- Anything else is of the wrong form
6719
6720 else
6721 Error_Pragma_Arg
6722 ("wrong form for Parameter_Types parameter",
6723 Arg_Parameter_Types);
6724 end if;
6725 end Check_Matching_Types;
6726 end if;
6727
6728 -- Match is now False if the entry we found did not match
6729 -- either a supplied Parameter_Types or Result_Types argument
6730
6731 if Match then
6732 if No (Ent) then
6733 Ent := Def_Id;
6734
6735 -- Ambiguous case, the flag Ambiguous shows if we already
6736 -- detected this and output the initial messages.
6737
6738 else
6739 if not Ambiguous then
6740 Ambiguous := True;
6741 Error_Msg_Name_1 := Pname;
6742 Error_Msg_N
6743 ("pragma% does not uniquely identify subprogram!",
6744 N);
6745 Error_Msg_Sloc := Sloc (Ent);
6746 Error_Msg_N ("matching subprogram #!", N);
6747 Ent := Empty;
6748 end if;
6749
6750 Error_Msg_Sloc := Sloc (Def_Id);
6751 Error_Msg_N ("matching subprogram #!", N);
6752 end if;
6753 end if;
6754 end if;
6755
6756 Hom_Id := Homonym (Hom_Id);
6757 end loop;
6758
6759 -- See if we found an entry
6760
6761 if No (Ent) then
6762 if not Ambiguous then
6763 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
6764 Error_Pragma
6765 ("pragma% cannot be given for generic subprogram");
6766 else
6767 Error_Pragma
6768 ("pragma% does not identify local subprogram");
6769 end if;
6770 end if;
6771
6772 return;
6773 end if;
6774
6775 -- Import pragmas must be for imported entities
6776
6777 if Prag_Id = Pragma_Import_Function
6778 or else
6779 Prag_Id = Pragma_Import_Procedure
6780 or else
6781 Prag_Id = Pragma_Import_Valued_Procedure
6782 then
6783 if not Is_Imported (Ent) then
6784 Error_Pragma
6785 ("pragma Import or Interface must precede pragma%");
6786 end if;
6787
6788 -- Here we have the Export case which can set the entity as exported
6789
6790 -- But does not do so if the specified external name is null, since
6791 -- that is taken as a signal in DEC Ada 83 (with which we want to be
6792 -- compatible) to request no external name.
6793
6794 elsif Nkind (Arg_External) = N_String_Literal
6795 and then String_Length (Strval (Arg_External)) = 0
6796 then
6797 null;
6798
6799 -- In all other cases, set entity as exported
6800
6801 else
6802 Set_Exported (Ent, Arg_Internal);
6803 end if;
6804
6805 -- Special processing for Valued_Procedure cases
6806
6807 if Prag_Id = Pragma_Import_Valued_Procedure
6808 or else
6809 Prag_Id = Pragma_Export_Valued_Procedure
6810 then
6811 Formal := First_Formal (Ent);
6812
6813 if No (Formal) then
6814 Error_Pragma ("at least one parameter required for pragma%");
6815
6816 elsif Ekind (Formal) /= E_Out_Parameter then
6817 Error_Pragma ("first parameter must have mode out for pragma%");
6818
6819 else
6820 Set_Is_Valued_Procedure (Ent);
6821 end if;
6822 end if;
6823
6824 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
6825
6826 -- Process Result_Mechanism argument if present. We have already
6827 -- checked that this is only allowed for the function case.
6828
6829 if Present (Arg_Result_Mechanism) then
6830 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
6831 end if;
6832
6833 -- Process Mechanism parameter if present. Note that this parameter
6834 -- is not analyzed, and must not be analyzed since it is semantic
6835 -- nonsense, so we get it in exactly as the parser left it.
6836
6837 if Present (Arg_Mechanism) then
6838 declare
6839 Formal : Entity_Id;
6840 Massoc : Node_Id;
6841 Mname : Node_Id;
6842 Choice : Node_Id;
6843
6844 begin
6845 -- A single mechanism association without a formal parameter
6846 -- name is parsed as a parenthesized expression. All other
6847 -- cases are parsed as aggregates, so we rewrite the single
6848 -- parameter case as an aggregate for consistency.
6849
6850 if Nkind (Arg_Mechanism) /= N_Aggregate
6851 and then Paren_Count (Arg_Mechanism) = 1
6852 then
6853 Rewrite (Arg_Mechanism,
6854 Make_Aggregate (Sloc (Arg_Mechanism),
6855 Expressions => New_List (
6856 Relocate_Node (Arg_Mechanism))));
6857 end if;
6858
6859 -- Case of only mechanism name given, applies to all formals
6860
6861 if Nkind (Arg_Mechanism) /= N_Aggregate then
6862 Formal := First_Formal (Ent);
6863 while Present (Formal) loop
6864 Set_Mechanism_Value (Formal, Arg_Mechanism);
6865 Next_Formal (Formal);
6866 end loop;
6867
6868 -- Case of list of mechanism associations given
6869
6870 else
6871 if Null_Record_Present (Arg_Mechanism) then
6872 Error_Pragma_Arg
6873 ("inappropriate form for Mechanism parameter",
6874 Arg_Mechanism);
6875 end if;
6876
6877 -- Deal with positional ones first
6878
6879 Formal := First_Formal (Ent);
6880
6881 if Present (Expressions (Arg_Mechanism)) then
6882 Mname := First (Expressions (Arg_Mechanism));
6883 while Present (Mname) loop
6884 if No (Formal) then
6885 Error_Pragma_Arg
6886 ("too many mechanism associations", Mname);
6887 end if;
6888
6889 Set_Mechanism_Value (Formal, Mname);
6890 Next_Formal (Formal);
6891 Next (Mname);
6892 end loop;
6893 end if;
6894
6895 -- Deal with named entries
6896
6897 if Present (Component_Associations (Arg_Mechanism)) then
6898 Massoc := First (Component_Associations (Arg_Mechanism));
6899 while Present (Massoc) loop
6900 Choice := First (Choices (Massoc));
6901
6902 if Nkind (Choice) /= N_Identifier
6903 or else Present (Next (Choice))
6904 then
6905 Error_Pragma_Arg
6906 ("incorrect form for mechanism association",
6907 Massoc);
6908 end if;
6909
6910 Formal := First_Formal (Ent);
6911 loop
6912 if No (Formal) then
6913 Error_Pragma_Arg
6914 ("parameter name & not present", Choice);
6915 end if;
6916
6917 if Chars (Choice) = Chars (Formal) then
6918 Set_Mechanism_Value
6919 (Formal, Expression (Massoc));
6920
6921 -- Set entity on identifier (needed by ASIS)
6922
6923 Set_Entity (Choice, Formal);
6924
6925 exit;
6926 end if;
6927
6928 Next_Formal (Formal);
6929 end loop;
6930
6931 Next (Massoc);
6932 end loop;
6933 end if;
6934 end if;
6935 end;
6936 end if;
6937
6938 -- Process First_Optional_Parameter argument if present. We have
6939 -- already checked that this is only allowed for the Import case.
6940
6941 if Present (Arg_First_Optional_Parameter) then
6942 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
6943 Error_Pragma_Arg
6944 ("first optional parameter must be formal parameter name",
6945 Arg_First_Optional_Parameter);
6946 end if;
6947
6948 Formal := First_Formal (Ent);
6949 loop
6950 if No (Formal) then
6951 Error_Pragma_Arg
6952 ("specified formal parameter& not found",
6953 Arg_First_Optional_Parameter);
6954 end if;
6955
6956 exit when Chars (Formal) =
6957 Chars (Arg_First_Optional_Parameter);
6958
6959 Next_Formal (Formal);
6960 end loop;
6961
6962 Set_First_Optional_Parameter (Ent, Formal);
6963
6964 -- Check specified and all remaining formals have right form
6965
6966 while Present (Formal) loop
6967 if Ekind (Formal) /= E_In_Parameter then
6968 Error_Msg_NE
6969 ("optional formal& is not of mode in!",
6970 Arg_First_Optional_Parameter, Formal);
6971
6972 else
6973 Dval := Default_Value (Formal);
6974
6975 if No (Dval) then
6976 Error_Msg_NE
6977 ("optional formal& does not have default value!",
6978 Arg_First_Optional_Parameter, Formal);
6979
6980 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
6981 null;
6982
6983 else
6984 Error_Msg_FE
6985 ("default value for optional formal& is non-static!",
6986 Arg_First_Optional_Parameter, Formal);
6987 end if;
6988 end if;
6989
6990 Set_Is_Optional_Parameter (Formal);
6991 Next_Formal (Formal);
6992 end loop;
6993 end if;
6994 end Process_Extended_Import_Export_Subprogram_Pragma;
6995
6996 --------------------------
6997 -- Process_Generic_List --
6998 --------------------------
6999
7000 procedure Process_Generic_List is
7001 Arg : Node_Id;
7002 Exp : Node_Id;
7003
7004 begin
7005 Check_No_Identifiers;
7006 Check_At_Least_N_Arguments (1);
7007
7008 -- Check all arguments are names of generic units or instances
7009
7010 Arg := Arg1;
7011 while Present (Arg) loop
7012 Exp := Get_Pragma_Arg (Arg);
7013 Analyze (Exp);
7014
7015 if not Is_Entity_Name (Exp)
7016 or else
7017 (not Is_Generic_Instance (Entity (Exp))
7018 and then
7019 not Is_Generic_Unit (Entity (Exp)))
7020 then
7021 Error_Pragma_Arg
7022 ("pragma% argument must be name of generic unit/instance",
7023 Arg);
7024 end if;
7025
7026 Next (Arg);
7027 end loop;
7028 end Process_Generic_List;
7029
7030 ------------------------------------
7031 -- Process_Import_Predefined_Type --
7032 ------------------------------------
7033
7034 procedure Process_Import_Predefined_Type is
7035 Loc : constant Source_Ptr := Sloc (N);
7036 Elmt : Elmt_Id;
7037 Ftyp : Node_Id := Empty;
7038 Decl : Node_Id;
7039 Def : Node_Id;
7040 Nam : Name_Id;
7041
7042 begin
7043 String_To_Name_Buffer (Strval (Expression (Arg3)));
7044 Nam := Name_Find;
7045
7046 Elmt := First_Elmt (Predefined_Float_Types);
7047 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7048 Next_Elmt (Elmt);
7049 end loop;
7050
7051 Ftyp := Node (Elmt);
7052
7053 if Present (Ftyp) then
7054
7055 -- Don't build a derived type declaration, because predefined C
7056 -- types have no declaration anywhere, so cannot really be named.
7057 -- Instead build a full type declaration, starting with an
7058 -- appropriate type definition is built
7059
7060 if Is_Floating_Point_Type (Ftyp) then
7061 Def := Make_Floating_Point_Definition (Loc,
7062 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
7063 Make_Real_Range_Specification (Loc,
7064 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
7065 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
7066
7067 -- Should never have a predefined type we cannot handle
7068
7069 else
7070 raise Program_Error;
7071 end if;
7072
7073 -- Build and insert a Full_Type_Declaration, which will be
7074 -- analyzed as soon as this list entry has been analyzed.
7075
7076 Decl := Make_Full_Type_Declaration (Loc,
7077 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7078 Type_Definition => Def);
7079
7080 Insert_After (N, Decl);
7081 Mark_Rewrite_Insertion (Decl);
7082
7083 else
7084 Error_Pragma_Arg ("no matching type found for pragma%",
7085 Arg2);
7086 end if;
7087 end Process_Import_Predefined_Type;
7088
7089 ---------------------------------
7090 -- Process_Import_Or_Interface --
7091 ---------------------------------
7092
7093 procedure Process_Import_Or_Interface is
7094 C : Convention_Id;
7095 Def_Id : Entity_Id;
7096 Hom_Id : Entity_Id;
7097
7098 begin
7099 Process_Convention (C, Def_Id);
7100 Kill_Size_Check_Code (Def_Id);
7101 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7102
7103 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7104
7105 -- We do not permit Import to apply to a renaming declaration
7106
7107 if Present (Renamed_Object (Def_Id)) then
7108 Error_Pragma_Arg
7109 ("pragma% not allowed for object renaming", Arg2);
7110
7111 -- User initialization is not allowed for imported object, but
7112 -- the object declaration may contain a default initialization,
7113 -- that will be discarded. Note that an explicit initialization
7114 -- only counts if it comes from source, otherwise it is simply
7115 -- the code generator making an implicit initialization explicit.
7116
7117 elsif Present (Expression (Parent (Def_Id)))
7118 and then Comes_From_Source (Expression (Parent (Def_Id)))
7119 then
7120 Error_Msg_Sloc := Sloc (Def_Id);
7121 Error_Pragma_Arg
7122 ("no initialization allowed for declaration of& #",
7123 "\imported entities cannot be initialized (RM B.1(24))",
7124 Arg2);
7125
7126 else
7127 Set_Imported (Def_Id);
7128 Process_Interface_Name (Def_Id, Arg3, Arg4);
7129
7130 -- Note that we do not set Is_Public here. That's because we
7131 -- only want to set it if there is no address clause, and we
7132 -- don't know that yet, so we delay that processing till
7133 -- freeze time.
7134
7135 -- pragma Import completes deferred constants
7136
7137 if Ekind (Def_Id) = E_Constant then
7138 Set_Has_Completion (Def_Id);
7139 end if;
7140
7141 -- It is not possible to import a constant of an unconstrained
7142 -- array type (e.g. string) because there is no simple way to
7143 -- write a meaningful subtype for it.
7144
7145 if Is_Array_Type (Etype (Def_Id))
7146 and then not Is_Constrained (Etype (Def_Id))
7147 then
7148 Error_Msg_NE
7149 ("imported constant& must have a constrained subtype",
7150 N, Def_Id);
7151 end if;
7152 end if;
7153
7154 elsif Is_Subprogram (Def_Id)
7155 or else Is_Generic_Subprogram (Def_Id)
7156 then
7157 -- If the name is overloaded, pragma applies to all of the denoted
7158 -- entities in the same declarative part, unless the pragma comes
7159 -- from an aspect specification.
7160
7161 Hom_Id := Def_Id;
7162 while Present (Hom_Id) loop
7163
7164 Def_Id := Get_Base_Subprogram (Hom_Id);
7165
7166 -- Ignore inherited subprograms because the pragma will apply
7167 -- to the parent operation, which is the one called.
7168
7169 if Is_Overloadable (Def_Id)
7170 and then Present (Alias (Def_Id))
7171 then
7172 null;
7173
7174 -- If it is not a subprogram, it must be in an outer scope and
7175 -- pragma does not apply.
7176
7177 elsif not Is_Subprogram (Def_Id)
7178 and then not Is_Generic_Subprogram (Def_Id)
7179 then
7180 null;
7181
7182 -- The pragma does not apply to primitives of interfaces
7183
7184 elsif Is_Dispatching_Operation (Def_Id)
7185 and then Present (Find_Dispatching_Type (Def_Id))
7186 and then Is_Interface (Find_Dispatching_Type (Def_Id))
7187 then
7188 null;
7189
7190 -- Verify that the homonym is in the same declarative part (not
7191 -- just the same scope). If the pragma comes from an aspect
7192 -- specification we know that it is part of the declaration.
7193
7194 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
7195 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7196 and then not From_Aspect_Specification (N)
7197 then
7198 exit;
7199
7200 else
7201 Set_Imported (Def_Id);
7202
7203 -- Reject an Import applied to an abstract subprogram
7204
7205 if Is_Subprogram (Def_Id)
7206 and then Is_Abstract_Subprogram (Def_Id)
7207 then
7208 Error_Msg_Sloc := Sloc (Def_Id);
7209 Error_Msg_NE
7210 ("cannot import abstract subprogram& declared#",
7211 Arg2, Def_Id);
7212 end if;
7213
7214 -- Special processing for Convention_Intrinsic
7215
7216 if C = Convention_Intrinsic then
7217
7218 -- Link_Name argument not allowed for intrinsic
7219
7220 Check_No_Link_Name;
7221
7222 Set_Is_Intrinsic_Subprogram (Def_Id);
7223
7224 -- If no external name is present, then check that this
7225 -- is a valid intrinsic subprogram. If an external name
7226 -- is present, then this is handled by the back end.
7227
7228 if No (Arg3) then
7229 Check_Intrinsic_Subprogram
7230 (Def_Id, Get_Pragma_Arg (Arg2));
7231 end if;
7232 end if;
7233
7234 -- All interfaced procedures need an external symbol created
7235 -- for them since they are always referenced from another
7236 -- object file.
7237
7238 Set_Is_Public (Def_Id);
7239
7240 -- Verify that the subprogram does not have a completion
7241 -- through a renaming declaration. For other completions the
7242 -- pragma appears as a too late representation.
7243
7244 declare
7245 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
7246
7247 begin
7248 if Present (Decl)
7249 and then Nkind (Decl) = N_Subprogram_Declaration
7250 and then Present (Corresponding_Body (Decl))
7251 and then Nkind (Unit_Declaration_Node
7252 (Corresponding_Body (Decl))) =
7253 N_Subprogram_Renaming_Declaration
7254 then
7255 Error_Msg_Sloc := Sloc (Def_Id);
7256 Error_Msg_NE
7257 ("cannot import&, renaming already provided for "
7258 & "declaration #", N, Def_Id);
7259 end if;
7260 end;
7261
7262 Set_Has_Completion (Def_Id);
7263 Process_Interface_Name (Def_Id, Arg3, Arg4);
7264 end if;
7265
7266 if Is_Compilation_Unit (Hom_Id) then
7267
7268 -- Its possible homonyms are not affected by the pragma.
7269 -- Such homonyms might be present in the context of other
7270 -- units being compiled.
7271
7272 exit;
7273
7274 elsif From_Aspect_Specification (N) then
7275 exit;
7276
7277 else
7278 Hom_Id := Homonym (Hom_Id);
7279 end if;
7280 end loop;
7281
7282 -- When the convention is Java or CIL, we also allow Import to
7283 -- be given for packages, generic packages, exceptions, record
7284 -- components, and access to subprograms.
7285
7286 elsif (C = Convention_Java or else C = Convention_CIL)
7287 and then
7288 (Is_Package_Or_Generic_Package (Def_Id)
7289 or else Ekind (Def_Id) = E_Exception
7290 or else Ekind (Def_Id) = E_Access_Subprogram_Type
7291 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
7292 then
7293 Set_Imported (Def_Id);
7294 Set_Is_Public (Def_Id);
7295 Process_Interface_Name (Def_Id, Arg3, Arg4);
7296
7297 -- Import a CPP class
7298
7299 elsif C = Convention_CPP
7300 and then (Is_Record_Type (Def_Id)
7301 or else Ekind (Def_Id) = E_Incomplete_Type)
7302 then
7303 if Ekind (Def_Id) = E_Incomplete_Type then
7304 if Present (Full_View (Def_Id)) then
7305 Def_Id := Full_View (Def_Id);
7306
7307 else
7308 Error_Msg_N
7309 ("cannot import 'C'P'P type before full declaration seen",
7310 Get_Pragma_Arg (Arg2));
7311
7312 -- Although we have reported the error we decorate it as
7313 -- CPP_Class to avoid reporting spurious errors
7314
7315 Set_Is_CPP_Class (Def_Id);
7316 return;
7317 end if;
7318 end if;
7319
7320 -- Types treated as CPP classes must be declared limited (note:
7321 -- this used to be a warning but there is no real benefit to it
7322 -- since we did effectively intend to treat the type as limited
7323 -- anyway).
7324
7325 if not Is_Limited_Type (Def_Id) then
7326 Error_Msg_N
7327 ("imported 'C'P'P type must be limited",
7328 Get_Pragma_Arg (Arg2));
7329 end if;
7330
7331 if Etype (Def_Id) /= Def_Id
7332 and then not Is_CPP_Class (Root_Type (Def_Id))
7333 then
7334 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
7335 end if;
7336
7337 Set_Is_CPP_Class (Def_Id);
7338
7339 -- Imported CPP types must not have discriminants (because C++
7340 -- classes do not have discriminants).
7341
7342 if Has_Discriminants (Def_Id) then
7343 Error_Msg_N
7344 ("imported 'C'P'P type cannot have discriminants",
7345 First (Discriminant_Specifications
7346 (Declaration_Node (Def_Id))));
7347 end if;
7348
7349 -- Check that components of imported CPP types do not have default
7350 -- expressions. For private types this check is performed when the
7351 -- full view is analyzed (see Process_Full_View).
7352
7353 if not Is_Private_Type (Def_Id) then
7354 Check_CPP_Type_Has_No_Defaults (Def_Id);
7355 end if;
7356
7357 -- Import a CPP exception
7358
7359 elsif C = Convention_CPP
7360 and then Ekind (Def_Id) = E_Exception
7361 then
7362 if No (Arg3) then
7363 Error_Pragma_Arg
7364 ("'External_'Name arguments is required for 'Cpp exception",
7365 Arg3);
7366 else
7367 -- As only a string is allowed, Check_Arg_Is_External_Name
7368 -- isn't called.
7369 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7370 end if;
7371
7372 if Present (Arg4) then
7373 Error_Pragma_Arg
7374 ("Link_Name argument not allowed for imported Cpp exception",
7375 Arg4);
7376 end if;
7377
7378 -- Do not call Set_Interface_Name as the name of the exception
7379 -- shouldn't be modified (and in particular it shouldn't be
7380 -- the External_Name). For exceptions, the External_Name is the
7381 -- name of the RTTI structure.
7382
7383 -- ??? Emit an error if pragma Import/Export_Exception is present
7384
7385 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
7386 Check_No_Link_Name;
7387 Check_Arg_Count (3);
7388 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7389
7390 Process_Import_Predefined_Type;
7391
7392 else
7393 Error_Pragma_Arg
7394 ("second argument of pragma% must be object, subprogram "
7395 & "or incomplete type",
7396 Arg2);
7397 end if;
7398
7399 -- If this pragma applies to a compilation unit, then the unit, which
7400 -- is a subprogram, does not require (or allow) a body. We also do
7401 -- not need to elaborate imported procedures.
7402
7403 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
7404 declare
7405 Cunit : constant Node_Id := Parent (Parent (N));
7406 begin
7407 Set_Body_Required (Cunit, False);
7408 end;
7409 end if;
7410 end Process_Import_Or_Interface;
7411
7412 --------------------
7413 -- Process_Inline --
7414 --------------------
7415
7416 procedure Process_Inline (Status : Inline_Status) is
7417 Assoc : Node_Id;
7418 Decl : Node_Id;
7419 Subp_Id : Node_Id;
7420 Subp : Entity_Id;
7421 Applies : Boolean;
7422
7423 Effective : Boolean := False;
7424 -- Set True if inline has some effect, i.e. if there is at least one
7425 -- subprogram set as inlined as a result of the use of the pragma.
7426
7427 procedure Make_Inline (Subp : Entity_Id);
7428 -- Subp is the defining unit name of the subprogram declaration. Set
7429 -- the flag, as well as the flag in the corresponding body, if there
7430 -- is one present.
7431
7432 procedure Set_Inline_Flags (Subp : Entity_Id);
7433 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
7434 -- Has_Pragma_Inline_Always for the Inline_Always case.
7435
7436 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
7437 -- Returns True if it can be determined at this stage that inlining
7438 -- is not possible, for example if the body is available and contains
7439 -- exception handlers, we prevent inlining, since otherwise we can
7440 -- get undefined symbols at link time. This function also emits a
7441 -- warning if front-end inlining is enabled and the pragma appears
7442 -- too late.
7443 --
7444 -- ??? is business with link symbols still valid, or does it relate
7445 -- to front end ZCX which is being phased out ???
7446
7447 ---------------------------
7448 -- Inlining_Not_Possible --
7449 ---------------------------
7450
7451 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
7452 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7453 Stats : Node_Id;
7454
7455 begin
7456 if Nkind (Decl) = N_Subprogram_Body then
7457 Stats := Handled_Statement_Sequence (Decl);
7458 return Present (Exception_Handlers (Stats))
7459 or else Present (At_End_Proc (Stats));
7460
7461 elsif Nkind (Decl) = N_Subprogram_Declaration
7462 and then Present (Corresponding_Body (Decl))
7463 then
7464 if Front_End_Inlining
7465 and then Analyzed (Corresponding_Body (Decl))
7466 then
7467 Error_Msg_N ("pragma appears too late, ignored??", N);
7468 return True;
7469
7470 -- If the subprogram is a renaming as body, the body is just a
7471 -- call to the renamed subprogram, and inlining is trivially
7472 -- possible.
7473
7474 elsif
7475 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
7476 N_Subprogram_Renaming_Declaration
7477 then
7478 return False;
7479
7480 else
7481 Stats :=
7482 Handled_Statement_Sequence
7483 (Unit_Declaration_Node (Corresponding_Body (Decl)));
7484
7485 return
7486 Present (Exception_Handlers (Stats))
7487 or else Present (At_End_Proc (Stats));
7488 end if;
7489
7490 else
7491 -- If body is not available, assume the best, the check is
7492 -- performed again when compiling enclosing package bodies.
7493
7494 return False;
7495 end if;
7496 end Inlining_Not_Possible;
7497
7498 -----------------
7499 -- Make_Inline --
7500 -----------------
7501
7502 procedure Make_Inline (Subp : Entity_Id) is
7503 Kind : constant Entity_Kind := Ekind (Subp);
7504 Inner_Subp : Entity_Id := Subp;
7505
7506 begin
7507 -- Ignore if bad type, avoid cascaded error
7508
7509 if Etype (Subp) = Any_Type then
7510 Applies := True;
7511 return;
7512
7513 -- Ignore if all inlining is suppressed
7514
7515 elsif Suppress_All_Inlining then
7516 Applies := True;
7517 return;
7518
7519 -- If inlining is not possible, for now do not treat as an error
7520
7521 elsif Status /= Suppressed
7522 and then Inlining_Not_Possible (Subp)
7523 then
7524 Applies := True;
7525 return;
7526
7527 -- Here we have a candidate for inlining, but we must exclude
7528 -- derived operations. Otherwise we would end up trying to inline
7529 -- a phantom declaration, and the result would be to drag in a
7530 -- body which has no direct inlining associated with it. That
7531 -- would not only be inefficient but would also result in the
7532 -- backend doing cross-unit inlining in cases where it was
7533 -- definitely inappropriate to do so.
7534
7535 -- However, a simple Comes_From_Source test is insufficient, since
7536 -- we do want to allow inlining of generic instances which also do
7537 -- not come from source. We also need to recognize specs generated
7538 -- by the front-end for bodies that carry the pragma. Finally,
7539 -- predefined operators do not come from source but are not
7540 -- inlineable either.
7541
7542 elsif Is_Generic_Instance (Subp)
7543 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
7544 then
7545 null;
7546
7547 elsif not Comes_From_Source (Subp)
7548 and then Scope (Subp) /= Standard_Standard
7549 then
7550 Applies := True;
7551 return;
7552 end if;
7553
7554 -- The referenced entity must either be the enclosing entity, or
7555 -- an entity declared within the current open scope.
7556
7557 if Present (Scope (Subp))
7558 and then Scope (Subp) /= Current_Scope
7559 and then Subp /= Current_Scope
7560 then
7561 Error_Pragma_Arg
7562 ("argument of% must be entity in current scope", Assoc);
7563 return;
7564 end if;
7565
7566 -- Processing for procedure, operator or function. If subprogram
7567 -- is aliased (as for an instance) indicate that the renamed
7568 -- entity (if declared in the same unit) is inlined.
7569
7570 if Is_Subprogram (Subp) then
7571 Inner_Subp := Ultimate_Alias (Inner_Subp);
7572
7573 if In_Same_Source_Unit (Subp, Inner_Subp) then
7574 Set_Inline_Flags (Inner_Subp);
7575
7576 Decl := Parent (Parent (Inner_Subp));
7577
7578 if Nkind (Decl) = N_Subprogram_Declaration
7579 and then Present (Corresponding_Body (Decl))
7580 then
7581 Set_Inline_Flags (Corresponding_Body (Decl));
7582
7583 elsif Is_Generic_Instance (Subp) then
7584
7585 -- Indicate that the body needs to be created for
7586 -- inlining subsequent calls. The instantiation node
7587 -- follows the declaration of the wrapper package
7588 -- created for it.
7589
7590 if Scope (Subp) /= Standard_Standard
7591 and then
7592 Need_Subprogram_Instance_Body
7593 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
7594 Subp)
7595 then
7596 null;
7597 end if;
7598
7599 -- Inline is a program unit pragma (RM 10.1.5) and cannot
7600 -- appear in a formal part to apply to a formal subprogram.
7601 -- Do not apply check within an instance or a formal package
7602 -- the test will have been applied to the original generic.
7603
7604 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
7605 and then List_Containing (Decl) = List_Containing (N)
7606 and then not In_Instance
7607 then
7608 Error_Msg_N
7609 ("Inline cannot apply to a formal subprogram", N);
7610
7611 -- If Subp is a renaming, it is the renamed entity that
7612 -- will appear in any call, and be inlined. However, for
7613 -- ASIS uses it is convenient to indicate that the renaming
7614 -- itself is an inlined subprogram, so that some gnatcheck
7615 -- rules can be applied in the absence of expansion.
7616
7617 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
7618 Set_Inline_Flags (Subp);
7619 end if;
7620 end if;
7621
7622 Applies := True;
7623
7624 -- For a generic subprogram set flag as well, for use at the point
7625 -- of instantiation, to determine whether the body should be
7626 -- generated.
7627
7628 elsif Is_Generic_Subprogram (Subp) then
7629 Set_Inline_Flags (Subp);
7630 Applies := True;
7631
7632 -- Literals are by definition inlined
7633
7634 elsif Kind = E_Enumeration_Literal then
7635 null;
7636
7637 -- Anything else is an error
7638
7639 else
7640 Error_Pragma_Arg
7641 ("expect subprogram name for pragma%", Assoc);
7642 end if;
7643 end Make_Inline;
7644
7645 ----------------------
7646 -- Set_Inline_Flags --
7647 ----------------------
7648
7649 procedure Set_Inline_Flags (Subp : Entity_Id) is
7650 begin
7651 -- First set the Has_Pragma_XXX flags and issue the appropriate
7652 -- errors and warnings for suspicious combinations.
7653
7654 if Prag_Id = Pragma_No_Inline then
7655 if Has_Pragma_Inline_Always (Subp) then
7656 Error_Msg_N
7657 ("Inline_Always and No_Inline are mutually exclusive", N);
7658 elsif Has_Pragma_Inline (Subp) then
7659 Error_Msg_NE
7660 ("Inline and No_Inline both specified for& ??",
7661 N, Entity (Subp_Id));
7662 end if;
7663
7664 Set_Has_Pragma_No_Inline (Subp);
7665 else
7666 if Prag_Id = Pragma_Inline_Always then
7667 if Has_Pragma_No_Inline (Subp) then
7668 Error_Msg_N
7669 ("Inline_Always and No_Inline are mutually exclusive",
7670 N);
7671 end if;
7672
7673 Set_Has_Pragma_Inline_Always (Subp);
7674 else
7675 if Has_Pragma_No_Inline (Subp) then
7676 Error_Msg_NE
7677 ("Inline and No_Inline both specified for& ??",
7678 N, Entity (Subp_Id));
7679 end if;
7680 end if;
7681
7682 if not Has_Pragma_Inline (Subp) then
7683 Set_Has_Pragma_Inline (Subp);
7684 Effective := True;
7685 end if;
7686 end if;
7687
7688 -- Then adjust the Is_Inlined flag. It can never be set if the
7689 -- subprogram is subject to pragma No_Inline.
7690
7691 case Status is
7692 when Suppressed =>
7693 Set_Is_Inlined (Subp, False);
7694 when Disabled =>
7695 null;
7696 when Enabled =>
7697 if not Has_Pragma_No_Inline (Subp) then
7698 Set_Is_Inlined (Subp, True);
7699 end if;
7700 end case;
7701 end Set_Inline_Flags;
7702
7703 -- Start of processing for Process_Inline
7704
7705 begin
7706 Check_No_Identifiers;
7707 Check_At_Least_N_Arguments (1);
7708
7709 if Status = Enabled then
7710 Inline_Processing_Required := True;
7711 end if;
7712
7713 Assoc := Arg1;
7714 while Present (Assoc) loop
7715 Subp_Id := Get_Pragma_Arg (Assoc);
7716 Analyze (Subp_Id);
7717 Applies := False;
7718
7719 if Is_Entity_Name (Subp_Id) then
7720 Subp := Entity (Subp_Id);
7721
7722 if Subp = Any_Id then
7723
7724 -- If previous error, avoid cascaded errors
7725
7726 Check_Error_Detected;
7727 Applies := True;
7728 Effective := True;
7729
7730 else
7731 Make_Inline (Subp);
7732
7733 -- For the pragma case, climb homonym chain. This is
7734 -- what implements allowing the pragma in the renaming
7735 -- case, with the result applying to the ancestors, and
7736 -- also allows Inline to apply to all previous homonyms.
7737
7738 if not From_Aspect_Specification (N) then
7739 while Present (Homonym (Subp))
7740 and then Scope (Homonym (Subp)) = Current_Scope
7741 loop
7742 Make_Inline (Homonym (Subp));
7743 Subp := Homonym (Subp);
7744 end loop;
7745 end if;
7746 end if;
7747 end if;
7748
7749 if not Applies then
7750 Error_Pragma_Arg
7751 ("inappropriate argument for pragma%", Assoc);
7752
7753 elsif not Effective
7754 and then Warn_On_Redundant_Constructs
7755 and then not (Status = Suppressed or else Suppress_All_Inlining)
7756 then
7757 if Inlining_Not_Possible (Subp) then
7758 Error_Msg_NE
7759 ("pragma Inline for& is ignored?r?",
7760 N, Entity (Subp_Id));
7761 else
7762 Error_Msg_NE
7763 ("pragma Inline for& is redundant?r?",
7764 N, Entity (Subp_Id));
7765 end if;
7766 end if;
7767
7768 Next (Assoc);
7769 end loop;
7770 end Process_Inline;
7771
7772 ----------------------------
7773 -- Process_Interface_Name --
7774 ----------------------------
7775
7776 procedure Process_Interface_Name
7777 (Subprogram_Def : Entity_Id;
7778 Ext_Arg : Node_Id;
7779 Link_Arg : Node_Id)
7780 is
7781 Ext_Nam : Node_Id;
7782 Link_Nam : Node_Id;
7783 String_Val : String_Id;
7784
7785 procedure Check_Form_Of_Interface_Name
7786 (SN : Node_Id;
7787 Ext_Name_Case : Boolean);
7788 -- SN is a string literal node for an interface name. This routine
7789 -- performs some minimal checks that the name is reasonable. In
7790 -- particular that no spaces or other obviously incorrect characters
7791 -- appear. This is only a warning, since any characters are allowed.
7792 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
7793
7794 ----------------------------------
7795 -- Check_Form_Of_Interface_Name --
7796 ----------------------------------
7797
7798 procedure Check_Form_Of_Interface_Name
7799 (SN : Node_Id;
7800 Ext_Name_Case : Boolean)
7801 is
7802 S : constant String_Id := Strval (Expr_Value_S (SN));
7803 SL : constant Nat := String_Length (S);
7804 C : Char_Code;
7805
7806 begin
7807 if SL = 0 then
7808 Error_Msg_N ("interface name cannot be null string", SN);
7809 end if;
7810
7811 for J in 1 .. SL loop
7812 C := Get_String_Char (S, J);
7813
7814 -- Look for dubious character and issue unconditional warning.
7815 -- Definitely dubious if not in character range.
7816
7817 if not In_Character_Range (C)
7818
7819 -- For all cases except CLI target,
7820 -- commas, spaces and slashes are dubious (in CLI, we use
7821 -- commas and backslashes in external names to specify
7822 -- assembly version and public key, while slashes and spaces
7823 -- can be used in names to mark nested classes and
7824 -- valuetypes).
7825
7826 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
7827 and then (Get_Character (C) = ','
7828 or else
7829 Get_Character (C) = '\'))
7830 or else (VM_Target /= CLI_Target
7831 and then (Get_Character (C) = ' '
7832 or else
7833 Get_Character (C) = '/'))
7834 then
7835 Error_Msg
7836 ("??interface name contains illegal character",
7837 Sloc (SN) + Source_Ptr (J));
7838 end if;
7839 end loop;
7840 end Check_Form_Of_Interface_Name;
7841
7842 -- Start of processing for Process_Interface_Name
7843
7844 begin
7845 if No (Link_Arg) then
7846 if No (Ext_Arg) then
7847 if VM_Target = CLI_Target
7848 and then Ekind (Subprogram_Def) = E_Package
7849 and then Nkind (Parent (Subprogram_Def)) =
7850 N_Package_Specification
7851 and then Present (Generic_Parent (Parent (Subprogram_Def)))
7852 then
7853 Set_Interface_Name
7854 (Subprogram_Def,
7855 Interface_Name
7856 (Generic_Parent (Parent (Subprogram_Def))));
7857 end if;
7858
7859 return;
7860
7861 elsif Chars (Ext_Arg) = Name_Link_Name then
7862 Ext_Nam := Empty;
7863 Link_Nam := Expression (Ext_Arg);
7864
7865 else
7866 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
7867 Ext_Nam := Expression (Ext_Arg);
7868 Link_Nam := Empty;
7869 end if;
7870
7871 else
7872 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
7873 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
7874 Ext_Nam := Expression (Ext_Arg);
7875 Link_Nam := Expression (Link_Arg);
7876 end if;
7877
7878 -- Check expressions for external name and link name are static
7879
7880 if Present (Ext_Nam) then
7881 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
7882 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
7883
7884 -- Verify that external name is not the name of a local entity,
7885 -- which would hide the imported one and could lead to run-time
7886 -- surprises. The problem can only arise for entities declared in
7887 -- a package body (otherwise the external name is fully qualified
7888 -- and will not conflict).
7889
7890 declare
7891 Nam : Name_Id;
7892 E : Entity_Id;
7893 Par : Node_Id;
7894
7895 begin
7896 if Prag_Id = Pragma_Import then
7897 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
7898 Nam := Name_Find;
7899 E := Entity_Id (Get_Name_Table_Info (Nam));
7900
7901 if Nam /= Chars (Subprogram_Def)
7902 and then Present (E)
7903 and then not Is_Overloadable (E)
7904 and then Is_Immediately_Visible (E)
7905 and then not Is_Imported (E)
7906 and then Ekind (Scope (E)) = E_Package
7907 then
7908 Par := Parent (E);
7909 while Present (Par) loop
7910 if Nkind (Par) = N_Package_Body then
7911 Error_Msg_Sloc := Sloc (E);
7912 Error_Msg_NE
7913 ("imported entity is hidden by & declared#",
7914 Ext_Arg, E);
7915 exit;
7916 end if;
7917
7918 Par := Parent (Par);
7919 end loop;
7920 end if;
7921 end if;
7922 end;
7923 end if;
7924
7925 if Present (Link_Nam) then
7926 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
7927 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
7928 end if;
7929
7930 -- If there is no link name, just set the external name
7931
7932 if No (Link_Nam) then
7933 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
7934
7935 -- For the Link_Name case, the given literal is preceded by an
7936 -- asterisk, which indicates to GCC that the given name should be
7937 -- taken literally, and in particular that no prepending of
7938 -- underlines should occur, even in systems where this is the
7939 -- normal default.
7940
7941 else
7942 Start_String;
7943
7944 if VM_Target = No_VM then
7945 Store_String_Char (Get_Char_Code ('*'));
7946 end if;
7947
7948 String_Val := Strval (Expr_Value_S (Link_Nam));
7949 Store_String_Chars (String_Val);
7950 Link_Nam :=
7951 Make_String_Literal (Sloc (Link_Nam),
7952 Strval => End_String);
7953 end if;
7954
7955 -- Set the interface name. If the entity is a generic instance, use
7956 -- its alias, which is the callable entity.
7957
7958 if Is_Generic_Instance (Subprogram_Def) then
7959 Set_Encoded_Interface_Name
7960 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
7961 else
7962 Set_Encoded_Interface_Name
7963 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
7964 end if;
7965
7966 -- We allow duplicated export names in CIL/Java, as they are always
7967 -- enclosed in a namespace that differentiates them, and overloaded
7968 -- entities are supported by the VM.
7969
7970 if Convention (Subprogram_Def) /= Convention_CIL
7971 and then
7972 Convention (Subprogram_Def) /= Convention_Java
7973 then
7974 Check_Duplicated_Export_Name (Link_Nam);
7975 end if;
7976 end Process_Interface_Name;
7977
7978 -----------------------------------------
7979 -- Process_Interrupt_Or_Attach_Handler --
7980 -----------------------------------------
7981
7982 procedure Process_Interrupt_Or_Attach_Handler is
7983 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
7984 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
7985 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
7986
7987 begin
7988 Set_Is_Interrupt_Handler (Handler_Proc);
7989
7990 -- If the pragma is not associated with a handler procedure within a
7991 -- protected type, then it must be for a nonprotected procedure for
7992 -- the AAMP target, in which case we don't associate a representation
7993 -- item with the procedure's scope.
7994
7995 if Ekind (Proc_Scope) = E_Protected_Type then
7996 if Prag_Id = Pragma_Interrupt_Handler
7997 or else
7998 Prag_Id = Pragma_Attach_Handler
7999 then
8000 Record_Rep_Item (Proc_Scope, N);
8001 end if;
8002 end if;
8003 end Process_Interrupt_Or_Attach_Handler;
8004
8005 --------------------------------------------------
8006 -- Process_Restrictions_Or_Restriction_Warnings --
8007 --------------------------------------------------
8008
8009 -- Note: some of the simple identifier cases were handled in par-prag,
8010 -- but it is harmless (and more straightforward) to simply handle all
8011 -- cases here, even if it means we repeat a bit of work in some cases.
8012
8013 procedure Process_Restrictions_Or_Restriction_Warnings
8014 (Warn : Boolean)
8015 is
8016 Arg : Node_Id;
8017 R_Id : Restriction_Id;
8018 Id : Name_Id;
8019 Expr : Node_Id;
8020 Val : Uint;
8021
8022 begin
8023 -- Ignore all Restrictions pragmas in CodePeer mode
8024
8025 if CodePeer_Mode then
8026 return;
8027 end if;
8028
8029 Check_Ada_83_Warning;
8030 Check_At_Least_N_Arguments (1);
8031 Check_Valid_Configuration_Pragma;
8032
8033 Arg := Arg1;
8034 while Present (Arg) loop
8035 Id := Chars (Arg);
8036 Expr := Get_Pragma_Arg (Arg);
8037
8038 -- Case of no restriction identifier present
8039
8040 if Id = No_Name then
8041 if Nkind (Expr) /= N_Identifier then
8042 Error_Pragma_Arg
8043 ("invalid form for restriction", Arg);
8044 end if;
8045
8046 R_Id :=
8047 Get_Restriction_Id
8048 (Process_Restriction_Synonyms (Expr));
8049
8050 if R_Id not in All_Boolean_Restrictions then
8051 Error_Msg_Name_1 := Pname;
8052 Error_Msg_N
8053 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8054
8055 -- Check for possible misspelling
8056
8057 for J in Restriction_Id loop
8058 declare
8059 Rnm : constant String := Restriction_Id'Image (J);
8060
8061 begin
8062 Name_Buffer (1 .. Rnm'Length) := Rnm;
8063 Name_Len := Rnm'Length;
8064 Set_Casing (All_Lower_Case);
8065
8066 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
8067 Set_Casing
8068 (Identifier_Casing (Current_Source_File));
8069 Error_Msg_String (1 .. Rnm'Length) :=
8070 Name_Buffer (1 .. Name_Len);
8071 Error_Msg_Strlen := Rnm'Length;
8072 Error_Msg_N -- CODEFIX
8073 ("\possible misspelling of ""~""",
8074 Get_Pragma_Arg (Arg));
8075 exit;
8076 end if;
8077 end;
8078 end loop;
8079
8080 raise Pragma_Exit;
8081 end if;
8082
8083 if Implementation_Restriction (R_Id) then
8084 Check_Restriction (No_Implementation_Restrictions, Arg);
8085 end if;
8086
8087 -- Special processing for No_Elaboration_Code restriction
8088
8089 if R_Id = No_Elaboration_Code then
8090
8091 -- Restriction is only recognized within a configuration
8092 -- pragma file, or within a unit of the main extended
8093 -- program. Note: the test for Main_Unit is needed to
8094 -- properly include the case of configuration pragma files.
8095
8096 if not (Current_Sem_Unit = Main_Unit
8097 or else In_Extended_Main_Source_Unit (N))
8098 then
8099 return;
8100
8101 -- Don't allow in a subunit unless already specified in
8102 -- body or spec.
8103
8104 elsif Nkind (Parent (N)) = N_Compilation_Unit
8105 and then Nkind (Unit (Parent (N))) = N_Subunit
8106 and then not Restriction_Active (No_Elaboration_Code)
8107 then
8108 Error_Msg_N
8109 ("invalid specification of ""No_Elaboration_Code""",
8110 N);
8111 Error_Msg_N
8112 ("\restriction cannot be specified in a subunit", N);
8113 Error_Msg_N
8114 ("\unless also specified in body or spec", N);
8115 return;
8116
8117 -- If we have a No_Elaboration_Code pragma that we
8118 -- accept, then it needs to be added to the configuration
8119 -- restrcition set so that we get proper application to
8120 -- other units in the main extended source as required.
8121
8122 else
8123 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
8124 end if;
8125 end if;
8126
8127 -- If this is a warning, then set the warning unless we already
8128 -- have a real restriction active (we never want a warning to
8129 -- override a real restriction).
8130
8131 if Warn then
8132 if not Restriction_Active (R_Id) then
8133 Set_Restriction (R_Id, N);
8134 Restriction_Warnings (R_Id) := True;
8135 end if;
8136
8137 -- If real restriction case, then set it and make sure that the
8138 -- restriction warning flag is off, since a real restriction
8139 -- always overrides a warning.
8140
8141 else
8142 Set_Restriction (R_Id, N);
8143 Restriction_Warnings (R_Id) := False;
8144 end if;
8145
8146 -- Check for obsolescent restrictions in Ada 2005 mode
8147
8148 if not Warn
8149 and then Ada_Version >= Ada_2005
8150 and then (R_Id = No_Asynchronous_Control
8151 or else
8152 R_Id = No_Unchecked_Deallocation
8153 or else
8154 R_Id = No_Unchecked_Conversion)
8155 then
8156 Check_Restriction (No_Obsolescent_Features, N);
8157 end if;
8158
8159 -- A very special case that must be processed here: pragma
8160 -- Restrictions (No_Exceptions) turns off all run-time
8161 -- checking. This is a bit dubious in terms of the formal
8162 -- language definition, but it is what is intended by RM
8163 -- H.4(12). Restriction_Warnings never affects generated code
8164 -- so this is done only in the real restriction case.
8165
8166 -- Atomic_Synchronization is not a real check, so it is not
8167 -- affected by this processing).
8168
8169 if R_Id = No_Exceptions and then not Warn then
8170 for J in Scope_Suppress.Suppress'Range loop
8171 if J /= Atomic_Synchronization then
8172 Scope_Suppress.Suppress (J) := True;
8173 end if;
8174 end loop;
8175 end if;
8176
8177 -- Case of No_Dependence => unit-name. Note that the parser
8178 -- already made the necessary entry in the No_Dependence table.
8179
8180 elsif Id = Name_No_Dependence then
8181 if not OK_No_Dependence_Unit_Name (Expr) then
8182 raise Pragma_Exit;
8183 end if;
8184
8185 -- Case of No_Specification_Of_Aspect => Identifier.
8186
8187 elsif Id = Name_No_Specification_Of_Aspect then
8188 declare
8189 A_Id : Aspect_Id;
8190
8191 begin
8192 if Nkind (Expr) /= N_Identifier then
8193 A_Id := No_Aspect;
8194 else
8195 A_Id := Get_Aspect_Id (Chars (Expr));
8196 end if;
8197
8198 if A_Id = No_Aspect then
8199 Error_Pragma_Arg ("invalid restriction name", Arg);
8200 else
8201 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
8202 end if;
8203 end;
8204
8205 elsif Id = Name_No_Use_Of_Attribute then
8206 if Nkind (Expr) /= N_Identifier
8207 or else not Is_Attribute_Name (Chars (Expr))
8208 then
8209 Error_Msg_N ("unknown attribute name?", Expr);
8210
8211 else
8212 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
8213 end if;
8214
8215 elsif Id = Name_No_Use_Of_Pragma then
8216 if Nkind (Expr) /= N_Identifier
8217 or else not Is_Pragma_Name (Chars (Expr))
8218 then
8219 Error_Msg_N ("unknown pragma name?", Expr);
8220
8221 else
8222 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
8223 end if;
8224
8225 -- All other cases of restriction identifier present
8226
8227 else
8228 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
8229 Analyze_And_Resolve (Expr, Any_Integer);
8230
8231 if R_Id not in All_Parameter_Restrictions then
8232 Error_Pragma_Arg
8233 ("invalid restriction parameter identifier", Arg);
8234
8235 elsif not Is_OK_Static_Expression (Expr) then
8236 Flag_Non_Static_Expr
8237 ("value must be static expression!", Expr);
8238 raise Pragma_Exit;
8239
8240 elsif not Is_Integer_Type (Etype (Expr))
8241 or else Expr_Value (Expr) < 0
8242 then
8243 Error_Pragma_Arg
8244 ("value must be non-negative integer", Arg);
8245 end if;
8246
8247 -- Restriction pragma is active
8248
8249 Val := Expr_Value (Expr);
8250
8251 if not UI_Is_In_Int_Range (Val) then
8252 Error_Pragma_Arg
8253 ("pragma ignored, value too large??", Arg);
8254 end if;
8255
8256 -- Warning case. If the real restriction is active, then we
8257 -- ignore the request, since warning never overrides a real
8258 -- restriction. Otherwise we set the proper warning. Note that
8259 -- this circuit sets the warning again if it is already set,
8260 -- which is what we want, since the constant may have changed.
8261
8262 if Warn then
8263 if not Restriction_Active (R_Id) then
8264 Set_Restriction
8265 (R_Id, N, Integer (UI_To_Int (Val)));
8266 Restriction_Warnings (R_Id) := True;
8267 end if;
8268
8269 -- Real restriction case, set restriction and make sure warning
8270 -- flag is off since real restriction always overrides warning.
8271
8272 else
8273 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
8274 Restriction_Warnings (R_Id) := False;
8275 end if;
8276 end if;
8277
8278 Next (Arg);
8279 end loop;
8280 end Process_Restrictions_Or_Restriction_Warnings;
8281
8282 ---------------------------------
8283 -- Process_Suppress_Unsuppress --
8284 ---------------------------------
8285
8286 -- Note: this procedure makes entries in the check suppress data
8287 -- structures managed by Sem. See spec of package Sem for full
8288 -- details on how we handle recording of check suppression.
8289
8290 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
8291 C : Check_Id;
8292 E_Id : Node_Id;
8293 E : Entity_Id;
8294
8295 In_Package_Spec : constant Boolean :=
8296 Is_Package_Or_Generic_Package (Current_Scope)
8297 and then not In_Package_Body (Current_Scope);
8298
8299 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
8300 -- Used to suppress a single check on the given entity
8301
8302 --------------------------------
8303 -- Suppress_Unsuppress_Echeck --
8304 --------------------------------
8305
8306 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
8307 begin
8308 -- Check for error of trying to set atomic synchronization for
8309 -- a non-atomic variable.
8310
8311 if C = Atomic_Synchronization
8312 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
8313 then
8314 Error_Msg_N
8315 ("pragma & requires atomic type or variable",
8316 Pragma_Identifier (Original_Node (N)));
8317 end if;
8318
8319 Set_Checks_May_Be_Suppressed (E);
8320
8321 if In_Package_Spec then
8322 Push_Global_Suppress_Stack_Entry
8323 (Entity => E,
8324 Check => C,
8325 Suppress => Suppress_Case);
8326 else
8327 Push_Local_Suppress_Stack_Entry
8328 (Entity => E,
8329 Check => C,
8330 Suppress => Suppress_Case);
8331 end if;
8332
8333 -- If this is a first subtype, and the base type is distinct,
8334 -- then also set the suppress flags on the base type.
8335
8336 if Is_First_Subtype (E) and then Etype (E) /= E then
8337 Suppress_Unsuppress_Echeck (Etype (E), C);
8338 end if;
8339 end Suppress_Unsuppress_Echeck;
8340
8341 -- Start of processing for Process_Suppress_Unsuppress
8342
8343 begin
8344 -- Ignore pragma Suppress/Unsuppress in CodePeer and SPARK modes on
8345 -- user code: we want to generate checks for analysis purposes, as
8346 -- set respectively by -gnatC and -gnatd.F
8347
8348 if (CodePeer_Mode or SPARK_Mode) and then Comes_From_Source (N) then
8349 return;
8350 end if;
8351
8352 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
8353 -- declarative part or a package spec (RM 11.5(5)).
8354
8355 if not Is_Configuration_Pragma then
8356 Check_Is_In_Decl_Part_Or_Package_Spec;
8357 end if;
8358
8359 Check_At_Least_N_Arguments (1);
8360 Check_At_Most_N_Arguments (2);
8361 Check_No_Identifier (Arg1);
8362 Check_Arg_Is_Identifier (Arg1);
8363
8364 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
8365
8366 if C = No_Check_Id then
8367 Error_Pragma_Arg
8368 ("argument of pragma% is not valid check name", Arg1);
8369 end if;
8370
8371 if Arg_Count = 1 then
8372
8373 -- Make an entry in the local scope suppress table. This is the
8374 -- table that directly shows the current value of the scope
8375 -- suppress check for any check id value.
8376
8377 if C = All_Checks then
8378
8379 -- For All_Checks, we set all specific predefined checks with
8380 -- the exception of Elaboration_Check, which is handled
8381 -- specially because of not wanting All_Checks to have the
8382 -- effect of deactivating static elaboration order processing.
8383 -- Atomic_Synchronization is also not affected, since this is
8384 -- not a real check.
8385
8386 for J in Scope_Suppress.Suppress'Range loop
8387 if J /= Elaboration_Check
8388 and then
8389 J /= Atomic_Synchronization
8390 then
8391 Scope_Suppress.Suppress (J) := Suppress_Case;
8392 end if;
8393 end loop;
8394
8395 -- If not All_Checks, and predefined check, then set appropriate
8396 -- scope entry. Note that we will set Elaboration_Check if this
8397 -- is explicitly specified. Atomic_Synchronization is allowed
8398 -- only if internally generated and entity is atomic.
8399
8400 elsif C in Predefined_Check_Id
8401 and then (not Comes_From_Source (N)
8402 or else C /= Atomic_Synchronization)
8403 then
8404 Scope_Suppress.Suppress (C) := Suppress_Case;
8405 end if;
8406
8407 -- Also make an entry in the Local_Entity_Suppress table
8408
8409 Push_Local_Suppress_Stack_Entry
8410 (Entity => Empty,
8411 Check => C,
8412 Suppress => Suppress_Case);
8413
8414 -- Case of two arguments present, where the check is suppressed for
8415 -- a specified entity (given as the second argument of the pragma)
8416
8417 else
8418 -- This is obsolescent in Ada 2005 mode
8419
8420 if Ada_Version >= Ada_2005 then
8421 Check_Restriction (No_Obsolescent_Features, Arg2);
8422 end if;
8423
8424 Check_Optional_Identifier (Arg2, Name_On);
8425 E_Id := Get_Pragma_Arg (Arg2);
8426 Analyze (E_Id);
8427
8428 if not Is_Entity_Name (E_Id) then
8429 Error_Pragma_Arg
8430 ("second argument of pragma% must be entity name", Arg2);
8431 end if;
8432
8433 E := Entity (E_Id);
8434
8435 if E = Any_Id then
8436 return;
8437 end if;
8438
8439 -- Enforce RM 11.5(7) which requires that for a pragma that
8440 -- appears within a package spec, the named entity must be
8441 -- within the package spec. We allow the package name itself
8442 -- to be mentioned since that makes sense, although it is not
8443 -- strictly allowed by 11.5(7).
8444
8445 if In_Package_Spec
8446 and then E /= Current_Scope
8447 and then Scope (E) /= Current_Scope
8448 then
8449 Error_Pragma_Arg
8450 ("entity in pragma% is not in package spec (RM 11.5(7))",
8451 Arg2);
8452 end if;
8453
8454 -- Loop through homonyms. As noted below, in the case of a package
8455 -- spec, only homonyms within the package spec are considered.
8456
8457 loop
8458 Suppress_Unsuppress_Echeck (E, C);
8459
8460 if Is_Generic_Instance (E)
8461 and then Is_Subprogram (E)
8462 and then Present (Alias (E))
8463 then
8464 Suppress_Unsuppress_Echeck (Alias (E), C);
8465 end if;
8466
8467 -- Move to next homonym if not aspect spec case
8468
8469 exit when From_Aspect_Specification (N);
8470 E := Homonym (E);
8471 exit when No (E);
8472
8473 -- If we are within a package specification, the pragma only
8474 -- applies to homonyms in the same scope.
8475
8476 exit when In_Package_Spec
8477 and then Scope (E) /= Current_Scope;
8478 end loop;
8479 end if;
8480 end Process_Suppress_Unsuppress;
8481
8482 ------------------
8483 -- Set_Exported --
8484 ------------------
8485
8486 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
8487 begin
8488 if Is_Imported (E) then
8489 Error_Pragma_Arg
8490 ("cannot export entity& that was previously imported", Arg);
8491
8492 elsif Present (Address_Clause (E))
8493 and then not Relaxed_RM_Semantics
8494 then
8495 Error_Pragma_Arg
8496 ("cannot export entity& that has an address clause", Arg);
8497 end if;
8498
8499 Set_Is_Exported (E);
8500
8501 -- Generate a reference for entity explicitly, because the
8502 -- identifier may be overloaded and name resolution will not
8503 -- generate one.
8504
8505 Generate_Reference (E, Arg);
8506
8507 -- Deal with exporting non-library level entity
8508
8509 if not Is_Library_Level_Entity (E) then
8510
8511 -- Not allowed at all for subprograms
8512
8513 if Is_Subprogram (E) then
8514 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
8515
8516 -- Otherwise set public and statically allocated
8517
8518 else
8519 Set_Is_Public (E);
8520 Set_Is_Statically_Allocated (E);
8521
8522 -- Warn if the corresponding W flag is set and the pragma comes
8523 -- from source. The latter may not be true e.g. on VMS where we
8524 -- expand export pragmas for exception codes associated with
8525 -- imported or exported exceptions. We do not want to generate
8526 -- a warning for something that the user did not write.
8527
8528 if Warn_On_Export_Import
8529 and then Comes_From_Source (Arg)
8530 then
8531 Error_Msg_NE
8532 ("?x?& has been made static as a result of Export",
8533 Arg, E);
8534 Error_Msg_N
8535 ("\?x?this usage is non-standard and non-portable",
8536 Arg);
8537 end if;
8538 end if;
8539 end if;
8540
8541 if Warn_On_Export_Import and then Is_Type (E) then
8542 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
8543 end if;
8544
8545 if Warn_On_Export_Import and Inside_A_Generic then
8546 Error_Msg_NE
8547 ("all instances of& will have the same external name?x?",
8548 Arg, E);
8549 end if;
8550 end Set_Exported;
8551
8552 ----------------------------------------------
8553 -- Set_Extended_Import_Export_External_Name --
8554 ----------------------------------------------
8555
8556 procedure Set_Extended_Import_Export_External_Name
8557 (Internal_Ent : Entity_Id;
8558 Arg_External : Node_Id)
8559 is
8560 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
8561 New_Name : Node_Id;
8562
8563 begin
8564 if No (Arg_External) then
8565 return;
8566 end if;
8567
8568 Check_Arg_Is_External_Name (Arg_External);
8569
8570 if Nkind (Arg_External) = N_String_Literal then
8571 if String_Length (Strval (Arg_External)) = 0 then
8572 return;
8573 else
8574 New_Name := Adjust_External_Name_Case (Arg_External);
8575 end if;
8576
8577 elsif Nkind (Arg_External) = N_Identifier then
8578 New_Name := Get_Default_External_Name (Arg_External);
8579
8580 -- Check_Arg_Is_External_Name should let through only identifiers and
8581 -- string literals or static string expressions (which are folded to
8582 -- string literals).
8583
8584 else
8585 raise Program_Error;
8586 end if;
8587
8588 -- If we already have an external name set (by a prior normal Import
8589 -- or Export pragma), then the external names must match
8590
8591 if Present (Interface_Name (Internal_Ent)) then
8592 Check_Matching_Internal_Names : declare
8593 S1 : constant String_Id := Strval (Old_Name);
8594 S2 : constant String_Id := Strval (New_Name);
8595
8596 procedure Mismatch;
8597 pragma No_Return (Mismatch);
8598 -- Called if names do not match
8599
8600 --------------
8601 -- Mismatch --
8602 --------------
8603
8604 procedure Mismatch is
8605 begin
8606 Error_Msg_Sloc := Sloc (Old_Name);
8607 Error_Pragma_Arg
8608 ("external name does not match that given #",
8609 Arg_External);
8610 end Mismatch;
8611
8612 -- Start of processing for Check_Matching_Internal_Names
8613
8614 begin
8615 if String_Length (S1) /= String_Length (S2) then
8616 Mismatch;
8617
8618 else
8619 for J in 1 .. String_Length (S1) loop
8620 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
8621 Mismatch;
8622 end if;
8623 end loop;
8624 end if;
8625 end Check_Matching_Internal_Names;
8626
8627 -- Otherwise set the given name
8628
8629 else
8630 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
8631 Check_Duplicated_Export_Name (New_Name);
8632 end if;
8633 end Set_Extended_Import_Export_External_Name;
8634
8635 ------------------
8636 -- Set_Imported --
8637 ------------------
8638
8639 procedure Set_Imported (E : Entity_Id) is
8640 begin
8641 -- Error message if already imported or exported
8642
8643 if Is_Exported (E) or else Is_Imported (E) then
8644
8645 -- Error if being set Exported twice
8646
8647 if Is_Exported (E) then
8648 Error_Msg_NE ("entity& was previously exported", N, E);
8649
8650 -- Ignore error in CodePeer mode where we treat all imported
8651 -- subprograms as unknown.
8652
8653 elsif CodePeer_Mode then
8654 goto OK;
8655
8656 -- OK if Import/Interface case
8657
8658 elsif Import_Interface_Present (N) then
8659 goto OK;
8660
8661 -- Error if being set Imported twice
8662
8663 else
8664 Error_Msg_NE ("entity& was previously imported", N, E);
8665 end if;
8666
8667 Error_Msg_Name_1 := Pname;
8668 Error_Msg_N
8669 ("\(pragma% applies to all previous entities)", N);
8670
8671 Error_Msg_Sloc := Sloc (E);
8672 Error_Msg_NE ("\import not allowed for& declared#", N, E);
8673
8674 -- Here if not previously imported or exported, OK to import
8675
8676 else
8677 Set_Is_Imported (E);
8678
8679 -- If the entity is an object that is not at the library level,
8680 -- then it is statically allocated. We do not worry about objects
8681 -- with address clauses in this context since they are not really
8682 -- imported in the linker sense.
8683
8684 if Is_Object (E)
8685 and then not Is_Library_Level_Entity (E)
8686 and then No (Address_Clause (E))
8687 then
8688 Set_Is_Statically_Allocated (E);
8689 end if;
8690 end if;
8691
8692 <<OK>> null;
8693 end Set_Imported;
8694
8695 -------------------------
8696 -- Set_Mechanism_Value --
8697 -------------------------
8698
8699 -- Note: the mechanism name has not been analyzed (and cannot indeed be
8700 -- analyzed, since it is semantic nonsense), so we get it in the exact
8701 -- form created by the parser.
8702
8703 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
8704 Class : Node_Id;
8705 Param : Node_Id;
8706 Mech_Name_Id : Name_Id;
8707
8708 procedure Bad_Class;
8709 pragma No_Return (Bad_Class);
8710 -- Signal bad descriptor class name
8711
8712 procedure Bad_Mechanism;
8713 pragma No_Return (Bad_Mechanism);
8714 -- Signal bad mechanism name
8715
8716 ---------------
8717 -- Bad_Class --
8718 ---------------
8719
8720 procedure Bad_Class is
8721 begin
8722 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
8723 end Bad_Class;
8724
8725 -------------------------
8726 -- Bad_Mechanism_Value --
8727 -------------------------
8728
8729 procedure Bad_Mechanism is
8730 begin
8731 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
8732 end Bad_Mechanism;
8733
8734 -- Start of processing for Set_Mechanism_Value
8735
8736 begin
8737 if Mechanism (Ent) /= Default_Mechanism then
8738 Error_Msg_NE
8739 ("mechanism for & has already been set", Mech_Name, Ent);
8740 end if;
8741
8742 -- MECHANISM_NAME ::= value | reference | descriptor |
8743 -- short_descriptor
8744
8745 if Nkind (Mech_Name) = N_Identifier then
8746 if Chars (Mech_Name) = Name_Value then
8747 Set_Mechanism (Ent, By_Copy);
8748 return;
8749
8750 elsif Chars (Mech_Name) = Name_Reference then
8751 Set_Mechanism (Ent, By_Reference);
8752 return;
8753
8754 elsif Chars (Mech_Name) = Name_Descriptor then
8755 Check_VMS (Mech_Name);
8756
8757 -- Descriptor => Short_Descriptor if pragma was given
8758
8759 if Short_Descriptors then
8760 Set_Mechanism (Ent, By_Short_Descriptor);
8761 else
8762 Set_Mechanism (Ent, By_Descriptor);
8763 end if;
8764
8765 return;
8766
8767 elsif Chars (Mech_Name) = Name_Short_Descriptor then
8768 Check_VMS (Mech_Name);
8769 Set_Mechanism (Ent, By_Short_Descriptor);
8770 return;
8771
8772 elsif Chars (Mech_Name) = Name_Copy then
8773 Error_Pragma_Arg
8774 ("bad mechanism name, Value assumed", Mech_Name);
8775
8776 else
8777 Bad_Mechanism;
8778 end if;
8779
8780 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
8781 -- short_descriptor (CLASS_NAME)
8782 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8783
8784 -- Note: this form is parsed as an indexed component
8785
8786 elsif Nkind (Mech_Name) = N_Indexed_Component then
8787 Class := First (Expressions (Mech_Name));
8788
8789 if Nkind (Prefix (Mech_Name)) /= N_Identifier
8790 or else
8791 not Nam_In (Chars (Prefix (Mech_Name)), Name_Descriptor,
8792 Name_Short_Descriptor)
8793 or else Present (Next (Class))
8794 then
8795 Bad_Mechanism;
8796 else
8797 Mech_Name_Id := Chars (Prefix (Mech_Name));
8798
8799 -- Change Descriptor => Short_Descriptor if pragma was given
8800
8801 if Mech_Name_Id = Name_Descriptor
8802 and then Short_Descriptors
8803 then
8804 Mech_Name_Id := Name_Short_Descriptor;
8805 end if;
8806 end if;
8807
8808 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
8809 -- short_descriptor (Class => CLASS_NAME)
8810 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8811
8812 -- Note: this form is parsed as a function call
8813
8814 elsif Nkind (Mech_Name) = N_Function_Call then
8815 Param := First (Parameter_Associations (Mech_Name));
8816
8817 if Nkind (Name (Mech_Name)) /= N_Identifier
8818 or else
8819 not Nam_In (Chars (Name (Mech_Name)), Name_Descriptor,
8820 Name_Short_Descriptor)
8821 or else Present (Next (Param))
8822 or else No (Selector_Name (Param))
8823 or else Chars (Selector_Name (Param)) /= Name_Class
8824 then
8825 Bad_Mechanism;
8826 else
8827 Class := Explicit_Actual_Parameter (Param);
8828 Mech_Name_Id := Chars (Name (Mech_Name));
8829 end if;
8830
8831 else
8832 Bad_Mechanism;
8833 end if;
8834
8835 -- Fall through here with Class set to descriptor class name
8836
8837 Check_VMS (Mech_Name);
8838
8839 if Nkind (Class) /= N_Identifier then
8840 Bad_Class;
8841
8842 elsif Mech_Name_Id = Name_Descriptor
8843 and then Chars (Class) = Name_UBS
8844 then
8845 Set_Mechanism (Ent, By_Descriptor_UBS);
8846
8847 elsif Mech_Name_Id = Name_Descriptor
8848 and then Chars (Class) = Name_UBSB
8849 then
8850 Set_Mechanism (Ent, By_Descriptor_UBSB);
8851
8852 elsif Mech_Name_Id = Name_Descriptor
8853 and then Chars (Class) = Name_UBA
8854 then
8855 Set_Mechanism (Ent, By_Descriptor_UBA);
8856
8857 elsif Mech_Name_Id = Name_Descriptor
8858 and then Chars (Class) = Name_S
8859 then
8860 Set_Mechanism (Ent, By_Descriptor_S);
8861
8862 elsif Mech_Name_Id = Name_Descriptor
8863 and then Chars (Class) = Name_SB
8864 then
8865 Set_Mechanism (Ent, By_Descriptor_SB);
8866
8867 elsif Mech_Name_Id = Name_Descriptor
8868 and then Chars (Class) = Name_A
8869 then
8870 Set_Mechanism (Ent, By_Descriptor_A);
8871
8872 elsif Mech_Name_Id = Name_Descriptor
8873 and then Chars (Class) = Name_NCA
8874 then
8875 Set_Mechanism (Ent, By_Descriptor_NCA);
8876
8877 elsif Mech_Name_Id = Name_Short_Descriptor
8878 and then Chars (Class) = Name_UBS
8879 then
8880 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
8881
8882 elsif Mech_Name_Id = Name_Short_Descriptor
8883 and then Chars (Class) = Name_UBSB
8884 then
8885 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
8886
8887 elsif Mech_Name_Id = Name_Short_Descriptor
8888 and then Chars (Class) = Name_UBA
8889 then
8890 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
8891
8892 elsif Mech_Name_Id = Name_Short_Descriptor
8893 and then Chars (Class) = Name_S
8894 then
8895 Set_Mechanism (Ent, By_Short_Descriptor_S);
8896
8897 elsif Mech_Name_Id = Name_Short_Descriptor
8898 and then Chars (Class) = Name_SB
8899 then
8900 Set_Mechanism (Ent, By_Short_Descriptor_SB);
8901
8902 elsif Mech_Name_Id = Name_Short_Descriptor
8903 and then Chars (Class) = Name_A
8904 then
8905 Set_Mechanism (Ent, By_Short_Descriptor_A);
8906
8907 elsif Mech_Name_Id = Name_Short_Descriptor
8908 and then Chars (Class) = Name_NCA
8909 then
8910 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
8911
8912 else
8913 Bad_Class;
8914 end if;
8915 end Set_Mechanism_Value;
8916
8917 --------------------------
8918 -- Set_Rational_Profile --
8919 --------------------------
8920
8921 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
8922 -- and extension to the semantics of renaming declarations.
8923
8924 procedure Set_Rational_Profile is
8925 begin
8926 Implicit_Packing := True;
8927 Overriding_Renamings := True;
8928 Use_VADS_Size := True;
8929 end Set_Rational_Profile;
8930
8931 ---------------------------
8932 -- Set_Ravenscar_Profile --
8933 ---------------------------
8934
8935 -- The tasks to be done here are
8936
8937 -- Set required policies
8938
8939 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
8940 -- pragma Locking_Policy (Ceiling_Locking)
8941
8942 -- Set Detect_Blocking mode
8943
8944 -- Set required restrictions (see System.Rident for detailed list)
8945
8946 -- Set the No_Dependence rules
8947 -- No_Dependence => Ada.Asynchronous_Task_Control
8948 -- No_Dependence => Ada.Calendar
8949 -- No_Dependence => Ada.Execution_Time.Group_Budget
8950 -- No_Dependence => Ada.Execution_Time.Timers
8951 -- No_Dependence => Ada.Task_Attributes
8952 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
8953
8954 procedure Set_Ravenscar_Profile (N : Node_Id) is
8955 Prefix_Entity : Entity_Id;
8956 Selector_Entity : Entity_Id;
8957 Prefix_Node : Node_Id;
8958 Node : Node_Id;
8959
8960 begin
8961 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
8962
8963 if Task_Dispatching_Policy /= ' '
8964 and then Task_Dispatching_Policy /= 'F'
8965 then
8966 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
8967 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
8968
8969 -- Set the FIFO_Within_Priorities policy, but always preserve
8970 -- System_Location since we like the error message with the run time
8971 -- name.
8972
8973 else
8974 Task_Dispatching_Policy := 'F';
8975
8976 if Task_Dispatching_Policy_Sloc /= System_Location then
8977 Task_Dispatching_Policy_Sloc := Loc;
8978 end if;
8979 end if;
8980
8981 -- pragma Locking_Policy (Ceiling_Locking)
8982
8983 if Locking_Policy /= ' '
8984 and then Locking_Policy /= 'C'
8985 then
8986 Error_Msg_Sloc := Locking_Policy_Sloc;
8987 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
8988
8989 -- Set the Ceiling_Locking policy, but preserve System_Location since
8990 -- we like the error message with the run time name.
8991
8992 else
8993 Locking_Policy := 'C';
8994
8995 if Locking_Policy_Sloc /= System_Location then
8996 Locking_Policy_Sloc := Loc;
8997 end if;
8998 end if;
8999
9000 -- pragma Detect_Blocking
9001
9002 Detect_Blocking := True;
9003
9004 -- Set the corresponding restrictions
9005
9006 Set_Profile_Restrictions
9007 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9008
9009 -- Set the No_Dependence restrictions
9010
9011 -- The following No_Dependence restrictions:
9012 -- No_Dependence => Ada.Asynchronous_Task_Control
9013 -- No_Dependence => Ada.Calendar
9014 -- No_Dependence => Ada.Task_Attributes
9015 -- are already set by previous call to Set_Profile_Restrictions.
9016
9017 -- Set the following restrictions which were added to Ada 2005:
9018 -- No_Dependence => Ada.Execution_Time.Group_Budget
9019 -- No_Dependence => Ada.Execution_Time.Timers
9020
9021 if Ada_Version >= Ada_2005 then
9022 Name_Buffer (1 .. 3) := "ada";
9023 Name_Len := 3;
9024
9025 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9026
9027 Name_Buffer (1 .. 14) := "execution_time";
9028 Name_Len := 14;
9029
9030 Selector_Entity := Make_Identifier (Loc, Name_Find);
9031
9032 Prefix_Node :=
9033 Make_Selected_Component
9034 (Sloc => Loc,
9035 Prefix => Prefix_Entity,
9036 Selector_Name => Selector_Entity);
9037
9038 Name_Buffer (1 .. 13) := "group_budgets";
9039 Name_Len := 13;
9040
9041 Selector_Entity := Make_Identifier (Loc, Name_Find);
9042
9043 Node :=
9044 Make_Selected_Component
9045 (Sloc => Loc,
9046 Prefix => Prefix_Node,
9047 Selector_Name => Selector_Entity);
9048
9049 Set_Restriction_No_Dependence
9050 (Unit => Node,
9051 Warn => Treat_Restrictions_As_Warnings,
9052 Profile => Ravenscar);
9053
9054 Name_Buffer (1 .. 6) := "timers";
9055 Name_Len := 6;
9056
9057 Selector_Entity := Make_Identifier (Loc, Name_Find);
9058
9059 Node :=
9060 Make_Selected_Component
9061 (Sloc => Loc,
9062 Prefix => Prefix_Node,
9063 Selector_Name => Selector_Entity);
9064
9065 Set_Restriction_No_Dependence
9066 (Unit => Node,
9067 Warn => Treat_Restrictions_As_Warnings,
9068 Profile => Ravenscar);
9069 end if;
9070
9071 -- Set the following restrictions which was added to Ada 2012 (see
9072 -- AI-0171):
9073 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9074
9075 if Ada_Version >= Ada_2012 then
9076 Name_Buffer (1 .. 6) := "system";
9077 Name_Len := 6;
9078
9079 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9080
9081 Name_Buffer (1 .. 15) := "multiprocessors";
9082 Name_Len := 15;
9083
9084 Selector_Entity := Make_Identifier (Loc, Name_Find);
9085
9086 Prefix_Node :=
9087 Make_Selected_Component
9088 (Sloc => Loc,
9089 Prefix => Prefix_Entity,
9090 Selector_Name => Selector_Entity);
9091
9092 Name_Buffer (1 .. 19) := "dispatching_domains";
9093 Name_Len := 19;
9094
9095 Selector_Entity := Make_Identifier (Loc, Name_Find);
9096
9097 Node :=
9098 Make_Selected_Component
9099 (Sloc => Loc,
9100 Prefix => Prefix_Node,
9101 Selector_Name => Selector_Entity);
9102
9103 Set_Restriction_No_Dependence
9104 (Unit => Node,
9105 Warn => Treat_Restrictions_As_Warnings,
9106 Profile => Ravenscar);
9107 end if;
9108 end Set_Ravenscar_Profile;
9109
9110 ----------------
9111 -- S14_Pragma --
9112 ----------------
9113
9114 procedure S14_Pragma is
9115 begin
9116 if not Formal_Extensions then
9117 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
9118 end if;
9119 end S14_Pragma;
9120
9121 -- Start of processing for Analyze_Pragma
9122
9123 begin
9124 -- The following code is a defense against recursion. Not clear that
9125 -- this can happen legitimately, but perhaps some error situations
9126 -- can cause it, and we did see this recursion during testing.
9127
9128 if Analyzed (N) then
9129 return;
9130 else
9131 Set_Analyzed (N, True);
9132 end if;
9133
9134 -- Deal with unrecognized pragma
9135
9136 Pname := Pragma_Name (N);
9137
9138 if not Is_Pragma_Name (Pname) then
9139 if Warn_On_Unrecognized_Pragma then
9140 Error_Msg_Name_1 := Pname;
9141 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
9142
9143 for PN in First_Pragma_Name .. Last_Pragma_Name loop
9144 if Is_Bad_Spelling_Of (Pname, PN) then
9145 Error_Msg_Name_1 := PN;
9146 Error_Msg_N -- CODEFIX
9147 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
9148 exit;
9149 end if;
9150 end loop;
9151 end if;
9152
9153 return;
9154 end if;
9155
9156 -- Here to start processing for recognized pragma
9157
9158 Prag_Id := Get_Pragma_Id (Pname);
9159 Pname := Original_Aspect_Name (N);
9160
9161 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9162 -- is already set, indicating that we have already checked the policy
9163 -- at the right point. This happens for example in the case of a pragma
9164 -- that is derived from an Aspect.
9165
9166 if Is_Ignored (N) or else Is_Checked (N) then
9167 null;
9168
9169 -- For a pragma that is a rewriting of another pragma, copy the
9170 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9171
9172 elsif Is_Rewrite_Substitution (N)
9173 and then Nkind (Original_Node (N)) = N_Pragma
9174 and then Original_Node (N) /= N
9175 then
9176 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
9177 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
9178
9179 -- Otherwise query the applicable policy at this point
9180
9181 else
9182 Check_Applicable_Policy (N);
9183
9184 -- If pragma is disabled, rewrite as NULL and skip analysis
9185
9186 if Is_Disabled (N) then
9187 Rewrite (N, Make_Null_Statement (Loc));
9188 Analyze (N);
9189 raise Pragma_Exit;
9190 end if;
9191 end if;
9192
9193 -- Preset arguments
9194
9195 Arg_Count := 0;
9196 Arg1 := Empty;
9197 Arg2 := Empty;
9198 Arg3 := Empty;
9199 Arg4 := Empty;
9200
9201 if Present (Pragma_Argument_Associations (N)) then
9202 Arg_Count := List_Length (Pragma_Argument_Associations (N));
9203 Arg1 := First (Pragma_Argument_Associations (N));
9204
9205 if Present (Arg1) then
9206 Arg2 := Next (Arg1);
9207
9208 if Present (Arg2) then
9209 Arg3 := Next (Arg2);
9210
9211 if Present (Arg3) then
9212 Arg4 := Next (Arg3);
9213 end if;
9214 end if;
9215 end if;
9216 end if;
9217
9218 Check_Restriction_No_Use_Of_Pragma (N);
9219
9220 -- An enumeration type defines the pragmas that are supported by the
9221 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
9222 -- into the corresponding enumeration value for the following case.
9223
9224 case Prag_Id is
9225
9226 -----------------
9227 -- Abort_Defer --
9228 -----------------
9229
9230 -- pragma Abort_Defer;
9231
9232 when Pragma_Abort_Defer =>
9233 GNAT_Pragma;
9234 Check_Arg_Count (0);
9235
9236 -- The only required semantic processing is to check the
9237 -- placement. This pragma must appear at the start of the
9238 -- statement sequence of a handled sequence of statements.
9239
9240 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
9241 or else N /= First (Statements (Parent (N)))
9242 then
9243 Pragma_Misplaced;
9244 end if;
9245
9246 --------------------
9247 -- Abstract_State --
9248 --------------------
9249
9250 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
9251
9252 -- ABSTRACT_STATE_LIST ::=
9253 -- null
9254 -- | STATE_NAME_WITH_OPTIONS
9255 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
9256
9257 -- STATE_NAME_WITH_OPTIONS ::=
9258 -- state_NAME
9259 -- | (state_NAME with OPTION_LIST)
9260
9261 -- OPTION_LIST ::= OPTION {, OPTION}
9262
9263 -- OPTION ::= SIMPLE_OPTION | NAME_VALUE_OPTION
9264
9265 -- SIMPLE_OPTION ::=
9266 -- External | Non_Volatile | Input_Only | Output_Only
9267
9268 -- NAME_VALUE_OPTION ::= Part_Of => abstract_state_NAME
9269
9270 when Pragma_Abstract_State => Abstract_State : declare
9271 Pack_Id : Entity_Id;
9272
9273 -- Flags used to verify the consistency of states
9274
9275 Non_Null_Seen : Boolean := False;
9276 Null_Seen : Boolean := False;
9277
9278 procedure Analyze_Abstract_State (State : Node_Id);
9279 -- Verify the legality of a single state declaration. Create and
9280 -- decorate a state abstraction entity and introduce it into the
9281 -- visibility chain.
9282
9283 ----------------------------
9284 -- Analyze_Abstract_State --
9285 ----------------------------
9286
9287 procedure Analyze_Abstract_State (State : Node_Id) is
9288 procedure Check_Duplicate_Option
9289 (Opt : Node_Id;
9290 Status : in out Boolean);
9291 -- Flag Status denotes whether a particular option has been
9292 -- seen while processing a state. This routine verifies that
9293 -- Opt is not a duplicate property and sets the flag Status.
9294
9295 ----------------------------
9296 -- Check_Duplicate_Option --
9297 ----------------------------
9298
9299 procedure Check_Duplicate_Option
9300 (Opt : Node_Id;
9301 Status : in out Boolean)
9302 is
9303 begin
9304 if Status then
9305 Error_Msg_N ("duplicate state option", Opt);
9306 end if;
9307
9308 Status := True;
9309 end Check_Duplicate_Option;
9310
9311 -- Local variables
9312
9313 Errors : constant Nat := Serious_Errors_Detected;
9314 Loc : constant Source_Ptr := Sloc (State);
9315 Assoc : Node_Id;
9316 Id : Entity_Id;
9317 Is_Null : Boolean := False;
9318 Name : Name_Id;
9319 Opt : Node_Id;
9320 Par_State : Node_Id;
9321
9322 -- Flags used to verify the consistency of options
9323
9324 External_Seen : Boolean := False;
9325 Input_Seen : Boolean := False;
9326 Non_Volatile_Seen : Boolean := False;
9327 Output_Seen : Boolean := False;
9328 Part_Of_Seen : Boolean := False;
9329
9330 -- Start of processing for Analyze_Abstract_State
9331
9332 begin
9333 -- A package with a null abstract state is not allowed to
9334 -- declare additional states.
9335
9336 if Null_Seen then
9337 Error_Msg_NE
9338 ("package & has null abstract state", State, Pack_Id);
9339
9340 -- Null states appear as internally generated entities
9341
9342 elsif Nkind (State) = N_Null then
9343 Name := New_Internal_Name ('S');
9344 Is_Null := True;
9345 Null_Seen := True;
9346
9347 -- Catch a case where a null state appears in a list of
9348 -- non-null states.
9349
9350 if Non_Null_Seen then
9351 Error_Msg_NE
9352 ("package & has non-null abstract state",
9353 State, Pack_Id);
9354 end if;
9355
9356 -- Simple state declaration
9357
9358 elsif Nkind (State) = N_Identifier then
9359 Name := Chars (State);
9360 Non_Null_Seen := True;
9361
9362 -- State declaration with various options. This construct
9363 -- appears as an extension aggregate in the tree.
9364
9365 elsif Nkind (State) = N_Extension_Aggregate then
9366 if Nkind (Ancestor_Part (State)) = N_Identifier then
9367 Name := Chars (Ancestor_Part (State));
9368 Non_Null_Seen := True;
9369 else
9370 Error_Msg_N
9371 ("state name must be an identifier",
9372 Ancestor_Part (State));
9373 end if;
9374
9375 -- Process options External, Input_Only, Output_Only and
9376 -- Volatile. Ensure that none of them appear more than once.
9377
9378 Opt := First (Expressions (State));
9379 while Present (Opt) loop
9380 if Nkind (Opt) = N_Identifier then
9381 if Chars (Opt) = Name_External then
9382 Check_Duplicate_Option (Opt, External_Seen);
9383 elsif Chars (Opt) = Name_Input_Only then
9384 Check_Duplicate_Option (Opt, Input_Seen);
9385 elsif Chars (Opt) = Name_Output_Only then
9386 Check_Duplicate_Option (Opt, Output_Seen);
9387 elsif Chars (Opt) = Name_Non_Volatile then
9388 Check_Duplicate_Option (Opt, Non_Volatile_Seen);
9389
9390 -- Ensure that the abstract state component of option
9391 -- Part_Of has not been omitted.
9392
9393 elsif Chars (Opt) = Name_Part_Of then
9394 Error_Msg_N
9395 ("option Part_Of requires an abstract state",
9396 Opt);
9397 else
9398 Error_Msg_N ("invalid state option", Opt);
9399 end if;
9400 else
9401 Error_Msg_N ("invalid state option", Opt);
9402 end if;
9403
9404 Next (Opt);
9405 end loop;
9406
9407 -- External may appear on its own or with exactly one option
9408 -- Input_Only or Output_Only, but not both.
9409
9410 if External_Seen
9411 and then Input_Seen
9412 and then Output_Seen
9413 then
9414 Error_Msg_N
9415 ("option External requires exactly one option "
9416 & "Input_Only or Output_Only", State);
9417 end if;
9418
9419 -- Either Input_Only or Output_Only require External
9420
9421 if (Input_Seen or Output_Seen)
9422 and then not External_Seen
9423 then
9424 Error_Msg_N
9425 ("options Input_Only and Output_Only require option "
9426 & "External", State);
9427 end if;
9428
9429 -- Option Part_Of appears as a component association
9430
9431 Assoc := First (Component_Associations (State));
9432 while Present (Assoc) loop
9433 Opt := First (Choices (Assoc));
9434 while Present (Opt) loop
9435 if Nkind (Opt) = N_Identifier
9436 and then Chars (Opt) = Name_Part_Of
9437 then
9438 Check_Duplicate_Option (Opt, Part_Of_Seen);
9439 else
9440 Error_Msg_N ("invalid state option", Opt);
9441 end if;
9442
9443 Next (Opt);
9444 end loop;
9445
9446 -- Part_Of must denote a parent state. Ensure that the
9447 -- tree is not malformed by checking the expression of
9448 -- the component association.
9449
9450 Par_State := Expression (Assoc);
9451 pragma Assert (Present (Par_State));
9452
9453 Analyze (Par_State);
9454
9455 -- Part_Of specified a legal state
9456
9457 if Is_Entity_Name (Par_State)
9458 and then Present (Entity (Par_State))
9459 and then Ekind (Entity (Par_State)) = E_Abstract_State
9460 then
9461 null;
9462 else
9463 Error_Msg_N
9464 ("option Part_Of must denote an abstract state",
9465 Par_State);
9466 end if;
9467
9468 Next (Assoc);
9469 end loop;
9470
9471 -- Any other attempt to declare a state is erroneous
9472
9473 else
9474 Error_Msg_N ("malformed abstract state declaration", State);
9475 end if;
9476
9477 -- Do not generate a state abstraction entity if it was not
9478 -- properly declared.
9479
9480 if Serious_Errors_Detected > Errors then
9481 return;
9482 end if;
9483
9484 -- The generated state abstraction reuses the same characters
9485 -- from the original state declaration. Decorate the entity.
9486
9487 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
9488 Set_Comes_From_Source (Id, not Is_Null);
9489 Set_Parent (Id, State);
9490 Set_Ekind (Id, E_Abstract_State);
9491 Set_Etype (Id, Standard_Void_Type);
9492 Set_Refined_State (Id, Empty);
9493 Set_Refinement_Constituents (Id, New_Elmt_List);
9494
9495 -- Every non-null state must be nameable and resolvable the
9496 -- same way a constant is.
9497
9498 if not Is_Null then
9499 Push_Scope (Pack_Id);
9500 Enter_Name (Id);
9501 Pop_Scope;
9502 end if;
9503
9504 -- Verify whether the state introduces an illegal hidden state
9505 -- within a package subject to a null abstract state.
9506
9507 if Formal_Extensions then
9508 Check_No_Hidden_State (Id);
9509 end if;
9510
9511 -- Associate the state with its related package
9512
9513 if No (Abstract_States (Pack_Id)) then
9514 Set_Abstract_States (Pack_Id, New_Elmt_List);
9515 end if;
9516
9517 Append_Elmt (Id, Abstract_States (Pack_Id));
9518 end Analyze_Abstract_State;
9519
9520 -- Local variables
9521
9522 Context : constant Node_Id := Parent (Parent (N));
9523 State : Node_Id;
9524
9525 -- Start of processing for Abstract_State
9526
9527 begin
9528 GNAT_Pragma;
9529 S14_Pragma;
9530 Check_Arg_Count (1);
9531
9532 -- Ensure the proper placement of the pragma. Abstract states must
9533 -- be associated with a package declaration.
9534
9535 if not Nkind_In (Context, N_Generic_Package_Declaration,
9536 N_Package_Declaration)
9537 then
9538 Pragma_Misplaced;
9539 return;
9540 end if;
9541
9542 Pack_Id := Defining_Entity (Context);
9543 Add_Contract_Item (N, Pack_Id);
9544
9545 -- Verify the declaration order of pragmas Abstract_State and
9546 -- Initializes.
9547
9548 Check_Declaration_Order
9549 (First => N,
9550 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
9551
9552 State := Expression (Arg1);
9553
9554 -- Multiple abstract states appear as an aggregate
9555
9556 if Nkind (State) = N_Aggregate then
9557 State := First (Expressions (State));
9558 while Present (State) loop
9559 Analyze_Abstract_State (State);
9560
9561 Next (State);
9562 end loop;
9563
9564 -- Various forms of a single abstract state. Note that these may
9565 -- include malformed state declarations.
9566
9567 else
9568 Analyze_Abstract_State (State);
9569 end if;
9570 end Abstract_State;
9571
9572 ------------
9573 -- Ada_83 --
9574 ------------
9575
9576 -- pragma Ada_83;
9577
9578 -- Note: this pragma also has some specific processing in Par.Prag
9579 -- because we want to set the Ada version mode during parsing.
9580
9581 when Pragma_Ada_83 =>
9582 GNAT_Pragma;
9583 Check_Arg_Count (0);
9584
9585 -- We really should check unconditionally for proper configuration
9586 -- pragma placement, since we really don't want mixed Ada modes
9587 -- within a single unit, and the GNAT reference manual has always
9588 -- said this was a configuration pragma, but we did not check and
9589 -- are hesitant to add the check now.
9590
9591 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
9592 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
9593 -- or Ada 2012 mode.
9594
9595 if Ada_Version >= Ada_2005 then
9596 Check_Valid_Configuration_Pragma;
9597 end if;
9598
9599 -- Now set Ada 83 mode
9600
9601 Ada_Version := Ada_83;
9602 Ada_Version_Explicit := Ada_83;
9603 Ada_Version_Pragma := N;
9604
9605 ------------
9606 -- Ada_95 --
9607 ------------
9608
9609 -- pragma Ada_95;
9610
9611 -- Note: this pragma also has some specific processing in Par.Prag
9612 -- because we want to set the Ada 83 version mode during parsing.
9613
9614 when Pragma_Ada_95 =>
9615 GNAT_Pragma;
9616 Check_Arg_Count (0);
9617
9618 -- We really should check unconditionally for proper configuration
9619 -- pragma placement, since we really don't want mixed Ada modes
9620 -- within a single unit, and the GNAT reference manual has always
9621 -- said this was a configuration pragma, but we did not check and
9622 -- are hesitant to add the check now.
9623
9624 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
9625 -- or Ada 95, so we must check if we are in Ada 2005 mode.
9626
9627 if Ada_Version >= Ada_2005 then
9628 Check_Valid_Configuration_Pragma;
9629 end if;
9630
9631 -- Now set Ada 95 mode
9632
9633 Ada_Version := Ada_95;
9634 Ada_Version_Explicit := Ada_95;
9635 Ada_Version_Pragma := N;
9636
9637 ---------------------
9638 -- Ada_05/Ada_2005 --
9639 ---------------------
9640
9641 -- pragma Ada_05;
9642 -- pragma Ada_05 (LOCAL_NAME);
9643
9644 -- pragma Ada_2005;
9645 -- pragma Ada_2005 (LOCAL_NAME):
9646
9647 -- Note: these pragmas also have some specific processing in Par.Prag
9648 -- because we want to set the Ada 2005 version mode during parsing.
9649
9650 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
9651 E_Id : Node_Id;
9652
9653 begin
9654 GNAT_Pragma;
9655
9656 if Arg_Count = 1 then
9657 Check_Arg_Is_Local_Name (Arg1);
9658 E_Id := Get_Pragma_Arg (Arg1);
9659
9660 if Etype (E_Id) = Any_Type then
9661 return;
9662 end if;
9663
9664 Set_Is_Ada_2005_Only (Entity (E_Id));
9665 Record_Rep_Item (Entity (E_Id), N);
9666
9667 else
9668 Check_Arg_Count (0);
9669
9670 -- For Ada_2005 we unconditionally enforce the documented
9671 -- configuration pragma placement, since we do not want to
9672 -- tolerate mixed modes in a unit involving Ada 2005. That
9673 -- would cause real difficulties for those cases where there
9674 -- are incompatibilities between Ada 95 and Ada 2005.
9675
9676 Check_Valid_Configuration_Pragma;
9677
9678 -- Now set appropriate Ada mode
9679
9680 Ada_Version := Ada_2005;
9681 Ada_Version_Explicit := Ada_2005;
9682 Ada_Version_Pragma := N;
9683 end if;
9684 end;
9685
9686 ---------------------
9687 -- Ada_12/Ada_2012 --
9688 ---------------------
9689
9690 -- pragma Ada_12;
9691 -- pragma Ada_12 (LOCAL_NAME);
9692
9693 -- pragma Ada_2012;
9694 -- pragma Ada_2012 (LOCAL_NAME):
9695
9696 -- Note: these pragmas also have some specific processing in Par.Prag
9697 -- because we want to set the Ada 2012 version mode during parsing.
9698
9699 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
9700 E_Id : Node_Id;
9701
9702 begin
9703 GNAT_Pragma;
9704
9705 if Arg_Count = 1 then
9706 Check_Arg_Is_Local_Name (Arg1);
9707 E_Id := Get_Pragma_Arg (Arg1);
9708
9709 if Etype (E_Id) = Any_Type then
9710 return;
9711 end if;
9712
9713 Set_Is_Ada_2012_Only (Entity (E_Id));
9714 Record_Rep_Item (Entity (E_Id), N);
9715
9716 else
9717 Check_Arg_Count (0);
9718
9719 -- For Ada_2012 we unconditionally enforce the documented
9720 -- configuration pragma placement, since we do not want to
9721 -- tolerate mixed modes in a unit involving Ada 2012. That
9722 -- would cause real difficulties for those cases where there
9723 -- are incompatibilities between Ada 95 and Ada 2012. We could
9724 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
9725
9726 Check_Valid_Configuration_Pragma;
9727
9728 -- Now set appropriate Ada mode
9729
9730 Ada_Version := Ada_2012;
9731 Ada_Version_Explicit := Ada_2012;
9732 Ada_Version_Pragma := N;
9733 end if;
9734 end;
9735
9736 ----------------------
9737 -- All_Calls_Remote --
9738 ----------------------
9739
9740 -- pragma All_Calls_Remote [(library_package_NAME)];
9741
9742 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
9743 Lib_Entity : Entity_Id;
9744
9745 begin
9746 Check_Ada_83_Warning;
9747 Check_Valid_Library_Unit_Pragma;
9748
9749 if Nkind (N) = N_Null_Statement then
9750 return;
9751 end if;
9752
9753 Lib_Entity := Find_Lib_Unit_Name;
9754
9755 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
9756
9757 if Present (Lib_Entity)
9758 and then not Debug_Flag_U
9759 then
9760 if not Is_Remote_Call_Interface (Lib_Entity) then
9761 Error_Pragma ("pragma% only apply to rci unit");
9762
9763 -- Set flag for entity of the library unit
9764
9765 else
9766 Set_Has_All_Calls_Remote (Lib_Entity);
9767 end if;
9768
9769 end if;
9770 end All_Calls_Remote;
9771
9772 --------------
9773 -- Annotate --
9774 --------------
9775
9776 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
9777 -- ARG ::= NAME | EXPRESSION
9778
9779 -- The first two arguments are by convention intended to refer to an
9780 -- external tool and a tool-specific function. These arguments are
9781 -- not analyzed.
9782
9783 when Pragma_Annotate => Annotate : declare
9784 Arg : Node_Id;
9785 Exp : Node_Id;
9786
9787 begin
9788 GNAT_Pragma;
9789 Check_At_Least_N_Arguments (1);
9790 Check_Arg_Is_Identifier (Arg1);
9791 Check_No_Identifiers;
9792 Store_Note (N);
9793
9794 -- Second parameter is optional, it is never analyzed
9795
9796 if No (Arg2) then
9797 null;
9798
9799 -- Here if we have a second parameter
9800
9801 else
9802 -- Second parameter must be identifier
9803
9804 Check_Arg_Is_Identifier (Arg2);
9805
9806 -- Process remaining parameters if any
9807
9808 Arg := Next (Arg2);
9809 while Present (Arg) loop
9810 Exp := Get_Pragma_Arg (Arg);
9811 Analyze (Exp);
9812
9813 if Is_Entity_Name (Exp) then
9814 null;
9815
9816 -- For string literals, we assume Standard_String as the
9817 -- type, unless the string contains wide or wide_wide
9818 -- characters.
9819
9820 elsif Nkind (Exp) = N_String_Literal then
9821 if Has_Wide_Wide_Character (Exp) then
9822 Resolve (Exp, Standard_Wide_Wide_String);
9823 elsif Has_Wide_Character (Exp) then
9824 Resolve (Exp, Standard_Wide_String);
9825 else
9826 Resolve (Exp, Standard_String);
9827 end if;
9828
9829 elsif Is_Overloaded (Exp) then
9830 Error_Pragma_Arg
9831 ("ambiguous argument for pragma%", Exp);
9832
9833 else
9834 Resolve (Exp);
9835 end if;
9836
9837 Next (Arg);
9838 end loop;
9839 end if;
9840 end Annotate;
9841
9842 -------------------------------------------------
9843 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
9844 -------------------------------------------------
9845
9846 -- pragma Assert
9847 -- ( [Check => ] Boolean_EXPRESSION
9848 -- [, [Message =>] Static_String_EXPRESSION]);
9849
9850 -- pragma Assert_And_Cut
9851 -- ( [Check => ] Boolean_EXPRESSION
9852 -- [, [Message =>] Static_String_EXPRESSION]);
9853
9854 -- pragma Assume
9855 -- ( [Check => ] Boolean_EXPRESSION
9856 -- [, [Message =>] Static_String_EXPRESSION]);
9857
9858 -- pragma Loop_Invariant
9859 -- ( [Check => ] Boolean_EXPRESSION
9860 -- [, [Message =>] Static_String_EXPRESSION]);
9861
9862 when Pragma_Assert |
9863 Pragma_Assert_And_Cut |
9864 Pragma_Assume |
9865 Pragma_Loop_Invariant =>
9866 Assert : declare
9867 Expr : Node_Id;
9868 Newa : List_Id;
9869
9870 begin
9871 -- Assert is an Ada 2005 RM-defined pragma
9872
9873 if Prag_Id = Pragma_Assert then
9874 Ada_2005_Pragma;
9875
9876 -- The remaining ones are GNAT pragmas
9877
9878 else
9879 GNAT_Pragma;
9880 end if;
9881
9882 Check_At_Least_N_Arguments (1);
9883 Check_At_Most_N_Arguments (2);
9884 Check_Arg_Order ((Name_Check, Name_Message));
9885 Check_Optional_Identifier (Arg1, Name_Check);
9886
9887 -- Special processing for Loop_Invariant
9888
9889 if Prag_Id = Pragma_Loop_Invariant then
9890
9891 -- Check restricted placement, must be within a loop
9892
9893 Check_Loop_Pragma_Placement;
9894
9895 -- Do preanalyze to deal with embedded Loop_Entry attribute
9896
9897 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
9898 end if;
9899
9900 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
9901 -- a corresponding Check pragma:
9902
9903 -- pragma Check (name, condition [, msg]);
9904
9905 -- Where name is the identifier matching the pragma name. So
9906 -- rewrite pragma in this manner, transfer the message argument
9907 -- if present, and analyze the result
9908
9909 -- Note: When dealing with a semantically analyzed tree, the
9910 -- information that a Check node N corresponds to a source Assert,
9911 -- Assume, or Assert_And_Cut pragma can be retrieved from the
9912 -- pragma kind of Original_Node(N).
9913
9914 Expr := Get_Pragma_Arg (Arg1);
9915 Newa := New_List (
9916 Make_Pragma_Argument_Association (Loc,
9917 Expression => Make_Identifier (Loc, Pname)),
9918 Make_Pragma_Argument_Association (Sloc (Expr),
9919 Expression => Expr));
9920
9921 if Arg_Count > 1 then
9922 Check_Optional_Identifier (Arg2, Name_Message);
9923 Append_To (Newa, New_Copy_Tree (Arg2));
9924 end if;
9925
9926 -- Rewrite as Check pragma
9927
9928 Rewrite (N,
9929 Make_Pragma (Loc,
9930 Chars => Name_Check,
9931 Pragma_Argument_Associations => Newa));
9932 Analyze (N);
9933 end Assert;
9934
9935 ----------------------
9936 -- Assertion_Policy --
9937 ----------------------
9938
9939 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
9940
9941 -- The following form is Ada 2012 only, but we allow it in all modes
9942
9943 -- Pragma Assertion_Policy (
9944 -- ASSERTION_KIND => POLICY_IDENTIFIER
9945 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
9946
9947 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
9948
9949 -- RM_ASSERTION_KIND ::= Assert |
9950 -- Static_Predicate |
9951 -- Dynamic_Predicate |
9952 -- Pre |
9953 -- Pre'Class |
9954 -- Post |
9955 -- Post'Class |
9956 -- Type_Invariant |
9957 -- Type_Invariant'Class
9958
9959 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
9960 -- Assume |
9961 -- Contract_Cases |
9962 -- Debug |
9963 -- Initial_Condition |
9964 -- Loop_Invariant |
9965 -- Loop_Variant |
9966 -- Postcondition |
9967 -- Precondition |
9968 -- Predicate |
9969 -- Refined_Post |
9970 -- Statement_Assertions
9971
9972 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
9973 -- ID_ASSERTION_KIND list contains implementation-defined additions
9974 -- recognized by GNAT. The effect is to control the behavior of
9975 -- identically named aspects and pragmas, depending on the specified
9976 -- policy identifier:
9977
9978 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
9979
9980 -- Note: Check and Ignore are language-defined. Disable is a GNAT
9981 -- implementation defined addition that results in totally ignoring
9982 -- the corresponding assertion. If Disable is specified, then the
9983 -- argument of the assertion is not even analyzed. This is useful
9984 -- when the aspect/pragma argument references entities in a with'ed
9985 -- package that is replaced by a dummy package in the final build.
9986
9987 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
9988 -- and Type_Invariant'Class were recognized by the parser and
9989 -- transformed into references to the special internal identifiers
9990 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
9991 -- processing is required here.
9992
9993 when Pragma_Assertion_Policy => Assertion_Policy : declare
9994 LocP : Source_Ptr;
9995 Policy : Node_Id;
9996 Arg : Node_Id;
9997 Kind : Name_Id;
9998
9999 begin
10000 Ada_2005_Pragma;
10001
10002 -- This can always appear as a configuration pragma
10003
10004 if Is_Configuration_Pragma then
10005 null;
10006
10007 -- It can also appear in a declarative part or package spec in Ada
10008 -- 2012 mode. We allow this in other modes, but in that case we
10009 -- consider that we have an Ada 2012 pragma on our hands.
10010
10011 else
10012 Check_Is_In_Decl_Part_Or_Package_Spec;
10013 Ada_2012_Pragma;
10014 end if;
10015
10016 -- One argument case with no identifier (first form above)
10017
10018 if Arg_Count = 1
10019 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
10020 or else Chars (Arg1) = No_Name)
10021 then
10022 Check_Arg_Is_One_Of
10023 (Arg1, Name_Check, Name_Disable, Name_Ignore);
10024
10025 -- Treat one argument Assertion_Policy as equivalent to:
10026
10027 -- pragma Check_Policy (Assertion, policy)
10028
10029 -- So rewrite pragma in that manner and link on to the chain
10030 -- of Check_Policy pragmas, marking the pragma as analyzed.
10031
10032 Policy := Get_Pragma_Arg (Arg1);
10033
10034 Rewrite (N,
10035 Make_Pragma (Loc,
10036 Chars => Name_Check_Policy,
10037 Pragma_Argument_Associations => New_List (
10038 Make_Pragma_Argument_Association (Loc,
10039 Expression => Make_Identifier (Loc, Name_Assertion)),
10040
10041 Make_Pragma_Argument_Association (Loc,
10042 Expression =>
10043 Make_Identifier (Sloc (Policy), Chars (Policy))))));
10044 Analyze (N);
10045
10046 -- Here if we have two or more arguments
10047
10048 else
10049 Check_At_Least_N_Arguments (1);
10050 Ada_2012_Pragma;
10051
10052 -- Loop through arguments
10053
10054 Arg := Arg1;
10055 while Present (Arg) loop
10056 LocP := Sloc (Arg);
10057
10058 -- Kind must be specified
10059
10060 if Nkind (Arg) /= N_Pragma_Argument_Association
10061 or else Chars (Arg) = No_Name
10062 then
10063 Error_Pragma_Arg
10064 ("missing assertion kind for pragma%", Arg);
10065 end if;
10066
10067 -- Check Kind and Policy have allowed forms
10068
10069 Kind := Chars (Arg);
10070
10071 if not Is_Valid_Assertion_Kind (Kind) then
10072 Error_Pragma_Arg
10073 ("invalid assertion kind for pragma%", Arg);
10074 end if;
10075
10076 Check_Arg_Is_One_Of
10077 (Arg, Name_Check, Name_Disable, Name_Ignore);
10078
10079 -- We rewrite the Assertion_Policy pragma as a series of
10080 -- Check_Policy pragmas:
10081
10082 -- Check_Policy (Kind, Policy);
10083
10084 Insert_Action (N,
10085 Make_Pragma (LocP,
10086 Chars => Name_Check_Policy,
10087 Pragma_Argument_Associations => New_List (
10088 Make_Pragma_Argument_Association (LocP,
10089 Expression => Make_Identifier (LocP, Kind)),
10090 Make_Pragma_Argument_Association (LocP,
10091 Expression => Get_Pragma_Arg (Arg)))));
10092
10093 Arg := Next (Arg);
10094 end loop;
10095
10096 -- Rewrite the Assertion_Policy pragma as null since we have
10097 -- now inserted all the equivalent Check pragmas.
10098
10099 Rewrite (N, Make_Null_Statement (Loc));
10100 Analyze (N);
10101 end if;
10102 end Assertion_Policy;
10103
10104 ------------------------------
10105 -- Assume_No_Invalid_Values --
10106 ------------------------------
10107
10108 -- pragma Assume_No_Invalid_Values (On | Off);
10109
10110 when Pragma_Assume_No_Invalid_Values =>
10111 GNAT_Pragma;
10112 Check_Valid_Configuration_Pragma;
10113 Check_Arg_Count (1);
10114 Check_No_Identifiers;
10115 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10116
10117 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
10118 Assume_No_Invalid_Values := True;
10119 else
10120 Assume_No_Invalid_Values := False;
10121 end if;
10122
10123 --------------------------
10124 -- Attribute_Definition --
10125 --------------------------
10126
10127 -- pragma Attribute_Definition
10128 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
10129 -- [Entity =>] LOCAL_NAME,
10130 -- [Expression =>] EXPRESSION | NAME);
10131
10132 when Pragma_Attribute_Definition => Attribute_Definition : declare
10133 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
10134 Aname : Name_Id;
10135
10136 begin
10137 GNAT_Pragma;
10138 Check_Arg_Count (3);
10139 Check_Optional_Identifier (Arg1, "attribute");
10140 Check_Optional_Identifier (Arg2, "entity");
10141 Check_Optional_Identifier (Arg3, "expression");
10142
10143 if Nkind (Attribute_Designator) /= N_Identifier then
10144 Error_Msg_N ("attribute name expected", Attribute_Designator);
10145 return;
10146 end if;
10147
10148 Check_Arg_Is_Local_Name (Arg2);
10149
10150 -- If the attribute is not recognized, then issue a warning (not
10151 -- an error), and ignore the pragma.
10152
10153 Aname := Chars (Attribute_Designator);
10154
10155 if not Is_Attribute_Name (Aname) then
10156 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
10157 return;
10158 end if;
10159
10160 -- Otherwise, rewrite the pragma as an attribute definition clause
10161
10162 Rewrite (N,
10163 Make_Attribute_Definition_Clause (Loc,
10164 Name => Get_Pragma_Arg (Arg2),
10165 Chars => Aname,
10166 Expression => Get_Pragma_Arg (Arg3)));
10167 Analyze (N);
10168 end Attribute_Definition;
10169
10170 ---------------
10171 -- AST_Entry --
10172 ---------------
10173
10174 -- pragma AST_Entry (entry_IDENTIFIER);
10175
10176 when Pragma_AST_Entry => AST_Entry : declare
10177 Ent : Node_Id;
10178
10179 begin
10180 GNAT_Pragma;
10181 Check_VMS (N);
10182 Check_Arg_Count (1);
10183 Check_No_Identifiers;
10184 Check_Arg_Is_Local_Name (Arg1);
10185 Ent := Entity (Get_Pragma_Arg (Arg1));
10186
10187 -- Note: the implementation of the AST_Entry pragma could handle
10188 -- the entry family case fine, but for now we are consistent with
10189 -- the DEC rules, and do not allow the pragma, which of course
10190 -- has the effect of also forbidding the attribute.
10191
10192 if Ekind (Ent) /= E_Entry then
10193 Error_Pragma_Arg
10194 ("pragma% argument must be simple entry name", Arg1);
10195
10196 elsif Is_AST_Entry (Ent) then
10197 Error_Pragma_Arg
10198 ("duplicate % pragma for entry", Arg1);
10199
10200 elsif Has_Homonym (Ent) then
10201 Error_Pragma_Arg
10202 ("pragma% argument cannot specify overloaded entry", Arg1);
10203
10204 else
10205 declare
10206 FF : constant Entity_Id := First_Formal (Ent);
10207
10208 begin
10209 if Present (FF) then
10210 if Present (Next_Formal (FF)) then
10211 Error_Pragma_Arg
10212 ("entry for pragma% can have only one argument",
10213 Arg1);
10214
10215 elsif Parameter_Mode (FF) /= E_In_Parameter then
10216 Error_Pragma_Arg
10217 ("entry parameter for pragma% must have mode IN",
10218 Arg1);
10219 end if;
10220 end if;
10221 end;
10222
10223 Set_Is_AST_Entry (Ent);
10224 end if;
10225 end AST_Entry;
10226
10227 ------------------
10228 -- Asynchronous --
10229 ------------------
10230
10231 -- pragma Asynchronous (LOCAL_NAME);
10232
10233 when Pragma_Asynchronous => Asynchronous : declare
10234 Nm : Entity_Id;
10235 C_Ent : Entity_Id;
10236 L : List_Id;
10237 S : Node_Id;
10238 N : Node_Id;
10239 Formal : Entity_Id;
10240
10241 procedure Process_Async_Pragma;
10242 -- Common processing for procedure and access-to-procedure case
10243
10244 --------------------------
10245 -- Process_Async_Pragma --
10246 --------------------------
10247
10248 procedure Process_Async_Pragma is
10249 begin
10250 if No (L) then
10251 Set_Is_Asynchronous (Nm);
10252 return;
10253 end if;
10254
10255 -- The formals should be of mode IN (RM E.4.1(6))
10256
10257 S := First (L);
10258 while Present (S) loop
10259 Formal := Defining_Identifier (S);
10260
10261 if Nkind (Formal) = N_Defining_Identifier
10262 and then Ekind (Formal) /= E_In_Parameter
10263 then
10264 Error_Pragma_Arg
10265 ("pragma% procedure can only have IN parameter",
10266 Arg1);
10267 end if;
10268
10269 Next (S);
10270 end loop;
10271
10272 Set_Is_Asynchronous (Nm);
10273 end Process_Async_Pragma;
10274
10275 -- Start of processing for pragma Asynchronous
10276
10277 begin
10278 Check_Ada_83_Warning;
10279 Check_No_Identifiers;
10280 Check_Arg_Count (1);
10281 Check_Arg_Is_Local_Name (Arg1);
10282
10283 if Debug_Flag_U then
10284 return;
10285 end if;
10286
10287 C_Ent := Cunit_Entity (Current_Sem_Unit);
10288 Analyze (Get_Pragma_Arg (Arg1));
10289 Nm := Entity (Get_Pragma_Arg (Arg1));
10290
10291 if not Is_Remote_Call_Interface (C_Ent)
10292 and then not Is_Remote_Types (C_Ent)
10293 then
10294 -- This pragma should only appear in an RCI or Remote Types
10295 -- unit (RM E.4.1(4)).
10296
10297 Error_Pragma
10298 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
10299 end if;
10300
10301 if Ekind (Nm) = E_Procedure
10302 and then Nkind (Parent (Nm)) = N_Procedure_Specification
10303 then
10304 if not Is_Remote_Call_Interface (Nm) then
10305 Error_Pragma_Arg
10306 ("pragma% cannot be applied on non-remote procedure",
10307 Arg1);
10308 end if;
10309
10310 L := Parameter_Specifications (Parent (Nm));
10311 Process_Async_Pragma;
10312 return;
10313
10314 elsif Ekind (Nm) = E_Function then
10315 Error_Pragma_Arg
10316 ("pragma% cannot be applied to function", Arg1);
10317
10318 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
10319 if Is_Record_Type (Nm) then
10320
10321 -- A record type that is the Equivalent_Type for a remote
10322 -- access-to-subprogram type.
10323
10324 N := Declaration_Node (Corresponding_Remote_Type (Nm));
10325
10326 else
10327 -- A non-expanded RAS type (distribution is not enabled)
10328
10329 N := Declaration_Node (Nm);
10330 end if;
10331
10332 if Nkind (N) = N_Full_Type_Declaration
10333 and then Nkind (Type_Definition (N)) =
10334 N_Access_Procedure_Definition
10335 then
10336 L := Parameter_Specifications (Type_Definition (N));
10337 Process_Async_Pragma;
10338
10339 if Is_Asynchronous (Nm)
10340 and then Expander_Active
10341 and then Get_PCS_Name /= Name_No_DSA
10342 then
10343 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
10344 end if;
10345
10346 else
10347 Error_Pragma_Arg
10348 ("pragma% cannot reference access-to-function type",
10349 Arg1);
10350 end if;
10351
10352 -- Only other possibility is Access-to-class-wide type
10353
10354 elsif Is_Access_Type (Nm)
10355 and then Is_Class_Wide_Type (Designated_Type (Nm))
10356 then
10357 Check_First_Subtype (Arg1);
10358 Set_Is_Asynchronous (Nm);
10359 if Expander_Active then
10360 RACW_Type_Is_Asynchronous (Nm);
10361 end if;
10362
10363 else
10364 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
10365 end if;
10366 end Asynchronous;
10367
10368 ------------
10369 -- Atomic --
10370 ------------
10371
10372 -- pragma Atomic (LOCAL_NAME);
10373
10374 when Pragma_Atomic =>
10375 Process_Atomic_Shared_Volatile;
10376
10377 -----------------------
10378 -- Atomic_Components --
10379 -----------------------
10380
10381 -- pragma Atomic_Components (array_LOCAL_NAME);
10382
10383 -- This processing is shared by Volatile_Components
10384
10385 when Pragma_Atomic_Components |
10386 Pragma_Volatile_Components =>
10387
10388 Atomic_Components : declare
10389 E_Id : Node_Id;
10390 E : Entity_Id;
10391 D : Node_Id;
10392 K : Node_Kind;
10393
10394 begin
10395 Check_Ada_83_Warning;
10396 Check_No_Identifiers;
10397 Check_Arg_Count (1);
10398 Check_Arg_Is_Local_Name (Arg1);
10399 E_Id := Get_Pragma_Arg (Arg1);
10400
10401 if Etype (E_Id) = Any_Type then
10402 return;
10403 end if;
10404
10405 E := Entity (E_Id);
10406
10407 Check_Duplicate_Pragma (E);
10408
10409 if Rep_Item_Too_Early (E, N)
10410 or else
10411 Rep_Item_Too_Late (E, N)
10412 then
10413 return;
10414 end if;
10415
10416 D := Declaration_Node (E);
10417 K := Nkind (D);
10418
10419 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
10420 or else
10421 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
10422 and then Nkind (D) = N_Object_Declaration
10423 and then Nkind (Object_Definition (D)) =
10424 N_Constrained_Array_Definition)
10425 then
10426 -- The flag is set on the object, or on the base type
10427
10428 if Nkind (D) /= N_Object_Declaration then
10429 E := Base_Type (E);
10430 end if;
10431
10432 Set_Has_Volatile_Components (E);
10433
10434 if Prag_Id = Pragma_Atomic_Components then
10435 Set_Has_Atomic_Components (E);
10436 end if;
10437
10438 else
10439 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
10440 end if;
10441 end Atomic_Components;
10442
10443 --------------------
10444 -- Attach_Handler --
10445 --------------------
10446
10447 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
10448
10449 when Pragma_Attach_Handler =>
10450 Check_Ada_83_Warning;
10451 Check_No_Identifiers;
10452 Check_Arg_Count (2);
10453
10454 if No_Run_Time_Mode then
10455 Error_Msg_CRT ("Attach_Handler pragma", N);
10456 else
10457 Check_Interrupt_Or_Attach_Handler;
10458
10459 -- The expression that designates the attribute may depend on a
10460 -- discriminant, and is therefore a per-object expression, to
10461 -- be expanded in the init proc. If expansion is enabled, then
10462 -- perform semantic checks on a copy only.
10463
10464 if Expander_Active then
10465 declare
10466 Temp : constant Node_Id :=
10467 New_Copy_Tree (Get_Pragma_Arg (Arg2));
10468 begin
10469 Set_Parent (Temp, N);
10470 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
10471 end;
10472
10473 else
10474 Analyze (Get_Pragma_Arg (Arg2));
10475 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
10476 end if;
10477
10478 Process_Interrupt_Or_Attach_Handler;
10479 end if;
10480
10481 --------------------
10482 -- C_Pass_By_Copy --
10483 --------------------
10484
10485 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
10486
10487 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
10488 Arg : Node_Id;
10489 Val : Uint;
10490
10491 begin
10492 GNAT_Pragma;
10493 Check_Valid_Configuration_Pragma;
10494 Check_Arg_Count (1);
10495 Check_Optional_Identifier (Arg1, "max_size");
10496
10497 Arg := Get_Pragma_Arg (Arg1);
10498 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
10499
10500 Val := Expr_Value (Arg);
10501
10502 if Val <= 0 then
10503 Error_Pragma_Arg
10504 ("maximum size for pragma% must be positive", Arg1);
10505
10506 elsif UI_Is_In_Int_Range (Val) then
10507 Default_C_Record_Mechanism := UI_To_Int (Val);
10508
10509 -- If a giant value is given, Int'Last will do well enough.
10510 -- If sometime someone complains that a record larger than
10511 -- two gigabytes is not copied, we will worry about it then!
10512
10513 else
10514 Default_C_Record_Mechanism := Mechanism_Type'Last;
10515 end if;
10516 end C_Pass_By_Copy;
10517
10518 -----------
10519 -- Check --
10520 -----------
10521
10522 -- pragma Check ([Name =>] CHECK_KIND,
10523 -- [Check =>] Boolean_EXPRESSION
10524 -- [,[Message =>] String_EXPRESSION]);
10525
10526 -- CHECK_KIND ::= IDENTIFIER |
10527 -- Pre'Class |
10528 -- Post'Class |
10529 -- Invariant'Class |
10530 -- Type_Invariant'Class
10531
10532 -- The identifiers Assertions and Statement_Assertions are not
10533 -- allowed, since they have special meaning for Check_Policy.
10534
10535 when Pragma_Check => Check : declare
10536 Expr : Node_Id;
10537 Eloc : Source_Ptr;
10538 Cname : Name_Id;
10539 Str : Node_Id;
10540
10541 begin
10542 GNAT_Pragma;
10543 Check_At_Least_N_Arguments (2);
10544 Check_At_Most_N_Arguments (3);
10545 Check_Optional_Identifier (Arg1, Name_Name);
10546 Check_Optional_Identifier (Arg2, Name_Check);
10547
10548 if Arg_Count = 3 then
10549 Check_Optional_Identifier (Arg3, Name_Message);
10550 Str := Get_Pragma_Arg (Arg3);
10551 end if;
10552
10553 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
10554 Check_Arg_Is_Identifier (Arg1);
10555 Cname := Chars (Get_Pragma_Arg (Arg1));
10556
10557 -- Check forbidden name Assertions or Statement_Assertions
10558
10559 case Cname is
10560 when Name_Assertions =>
10561 Error_Pragma_Arg
10562 ("""Assertions"" is not allowed as a check kind "
10563 & "for pragma%", Arg1);
10564
10565 when Name_Statement_Assertions =>
10566 Error_Pragma_Arg
10567 ("""Statement_Assertions"" is not allowed as a check kind "
10568 & "for pragma%", Arg1);
10569
10570 when others =>
10571 null;
10572 end case;
10573
10574 -- Check applicable policy. We skip this if Checked/Ignored status
10575 -- is already set (e.g. in the casse of a pragma from an aspect).
10576
10577 if Is_Checked (N) or else Is_Ignored (N) then
10578 null;
10579
10580 -- For a non-source pragma that is a rewriting of another pragma,
10581 -- copy the Is_Checked/Ignored status from the rewritten pragma.
10582
10583 elsif Is_Rewrite_Substitution (N)
10584 and then Nkind (Original_Node (N)) = N_Pragma
10585 and then Original_Node (N) /= N
10586 then
10587 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10588 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10589
10590 -- Otherwise query the applicable policy at this point
10591
10592 else
10593 case Check_Kind (Cname) is
10594 when Name_Ignore =>
10595 Set_Is_Ignored (N, True);
10596 Set_Is_Checked (N, False);
10597
10598 when Name_Check =>
10599 Set_Is_Ignored (N, False);
10600 Set_Is_Checked (N, True);
10601
10602 -- For disable, rewrite pragma as null statement and skip
10603 -- rest of the analysis of the pragma.
10604
10605 when Name_Disable =>
10606 Rewrite (N, Make_Null_Statement (Loc));
10607 Analyze (N);
10608 raise Pragma_Exit;
10609
10610 -- No other possibilities
10611
10612 when others =>
10613 raise Program_Error;
10614 end case;
10615 end if;
10616
10617 -- If check kind was not Disable, then continue pragma analysis
10618
10619 Expr := Get_Pragma_Arg (Arg2);
10620
10621 -- Deal with SCO generation
10622
10623 case Cname is
10624 when Name_Predicate |
10625 Name_Invariant =>
10626
10627 -- Nothing to do: since checks occur in client units,
10628 -- the SCO for the aspect in the declaration unit is
10629 -- conservatively always enabled.
10630
10631 null;
10632
10633 when others =>
10634
10635 if Is_Checked (N) and then not Split_PPC (N) then
10636
10637 -- Mark aspect/pragma SCO as enabled
10638
10639 Set_SCO_Pragma_Enabled (Loc);
10640 end if;
10641 end case;
10642
10643 -- Deal with analyzing the string argument.
10644
10645 if Arg_Count = 3 then
10646
10647 -- If checks are not on we don't want any expansion (since
10648 -- such expansion would not get properly deleted) but
10649 -- we do want to analyze (to get proper references).
10650 -- The Preanalyze_And_Resolve routine does just what we want
10651
10652 if Is_Ignored (N) then
10653 Preanalyze_And_Resolve (Str, Standard_String);
10654
10655 -- Otherwise we need a proper analysis and expansion
10656
10657 else
10658 Analyze_And_Resolve (Str, Standard_String);
10659 end if;
10660 end if;
10661
10662 -- Now you might think we could just do the same with the Boolean
10663 -- expression if checks are off (and expansion is on) and then
10664 -- rewrite the check as a null statement. This would work but we
10665 -- would lose the useful warnings about an assertion being bound
10666 -- to fail even if assertions are turned off.
10667
10668 -- So instead we wrap the boolean expression in an if statement
10669 -- that looks like:
10670
10671 -- if False and then condition then
10672 -- null;
10673 -- end if;
10674
10675 -- The reason we do this rewriting during semantic analysis rather
10676 -- than as part of normal expansion is that we cannot analyze and
10677 -- expand the code for the boolean expression directly, or it may
10678 -- cause insertion of actions that would escape the attempt to
10679 -- suppress the check code.
10680
10681 -- Note that the Sloc for the if statement corresponds to the
10682 -- argument condition, not the pragma itself. The reason for
10683 -- this is that we may generate a warning if the condition is
10684 -- False at compile time, and we do not want to delete this
10685 -- warning when we delete the if statement.
10686
10687 if Expander_Active and Is_Ignored (N) then
10688 Eloc := Sloc (Expr);
10689
10690 Rewrite (N,
10691 Make_If_Statement (Eloc,
10692 Condition =>
10693 Make_And_Then (Eloc,
10694 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
10695 Right_Opnd => Expr),
10696 Then_Statements => New_List (
10697 Make_Null_Statement (Eloc))));
10698
10699 In_Assertion_Expr := In_Assertion_Expr + 1;
10700 Analyze (N);
10701 In_Assertion_Expr := In_Assertion_Expr - 1;
10702
10703 -- Check is active or expansion not active. In these cases we can
10704 -- just go ahead and analyze the boolean with no worries.
10705
10706 else
10707 In_Assertion_Expr := In_Assertion_Expr + 1;
10708 Analyze_And_Resolve (Expr, Any_Boolean);
10709 In_Assertion_Expr := In_Assertion_Expr - 1;
10710 end if;
10711 end Check;
10712
10713 --------------------------
10714 -- Check_Float_Overflow --
10715 --------------------------
10716
10717 -- pragma Check_Float_Overflow;
10718
10719 when Pragma_Check_Float_Overflow =>
10720 GNAT_Pragma;
10721 Check_Valid_Configuration_Pragma;
10722 Check_Arg_Count (0);
10723 Check_Float_Overflow := True;
10724
10725 ----------------
10726 -- Check_Name --
10727 ----------------
10728
10729 -- pragma Check_Name (check_IDENTIFIER);
10730
10731 when Pragma_Check_Name =>
10732 GNAT_Pragma;
10733 Check_No_Identifiers;
10734 Check_Valid_Configuration_Pragma;
10735 Check_Arg_Count (1);
10736 Check_Arg_Is_Identifier (Arg1);
10737
10738 declare
10739 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10740
10741 begin
10742 for J in Check_Names.First .. Check_Names.Last loop
10743 if Check_Names.Table (J) = Nam then
10744 return;
10745 end if;
10746 end loop;
10747
10748 Check_Names.Append (Nam);
10749 end;
10750
10751 ------------------
10752 -- Check_Policy --
10753 ------------------
10754
10755 -- This is the old style syntax, which is still allowed in all modes:
10756
10757 -- pragma Check_Policy ([Name =>] CHECK_KIND
10758 -- [Policy =>] POLICY_IDENTIFIER);
10759
10760 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
10761
10762 -- CHECK_KIND ::= IDENTIFIER |
10763 -- Pre'Class |
10764 -- Post'Class |
10765 -- Type_Invariant'Class |
10766 -- Invariant'Class
10767
10768 -- This is the new style syntax, compatible with Assertion_Policy
10769 -- and also allowed in all modes.
10770
10771 -- Pragma Check_Policy (
10772 -- CHECK_KIND => POLICY_IDENTIFIER
10773 -- {, CHECK_KIND => POLICY_IDENTIFIER});
10774
10775 -- Note: the identifiers Name and Policy are not allowed as
10776 -- Check_Kind values. This avoids ambiguities between the old and
10777 -- new form syntax.
10778
10779 when Pragma_Check_Policy => Check_Policy : declare
10780 Kind : Node_Id;
10781
10782 begin
10783 GNAT_Pragma;
10784 Check_At_Least_N_Arguments (1);
10785
10786 -- A Check_Policy pragma can appear either as a configuration
10787 -- pragma, or in a declarative part or a package spec (see RM
10788 -- 11.5(5) for rules for Suppress/Unsuppress which are also
10789 -- followed for Check_Policy).
10790
10791 if not Is_Configuration_Pragma then
10792 Check_Is_In_Decl_Part_Or_Package_Spec;
10793 end if;
10794
10795 -- Figure out if we have the old or new syntax. We have the
10796 -- old syntax if the first argument has no identifier, or the
10797 -- identifier is Name.
10798
10799 if Nkind (Arg1) /= N_Pragma_Argument_Association
10800 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
10801 then
10802 -- Old syntax
10803
10804 Check_Arg_Count (2);
10805 Check_Optional_Identifier (Arg1, Name_Name);
10806 Kind := Get_Pragma_Arg (Arg1);
10807 Rewrite_Assertion_Kind (Kind);
10808 Check_Arg_Is_Identifier (Arg1);
10809
10810 -- Check forbidden check kind
10811
10812 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
10813 Error_Msg_Name_2 := Chars (Kind);
10814 Error_Pragma_Arg
10815 ("pragma% does not allow% as check name", Arg1);
10816 end if;
10817
10818 -- Check policy
10819
10820 Check_Optional_Identifier (Arg2, Name_Policy);
10821 Check_Arg_Is_One_Of
10822 (Arg2,
10823 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
10824
10825 -- And chain pragma on the Check_Policy_List for search
10826
10827 Set_Next_Pragma (N, Opt.Check_Policy_List);
10828 Opt.Check_Policy_List := N;
10829
10830 -- For the new syntax, what we do is to convert each argument to
10831 -- an old syntax equivalent. We do that because we want to chain
10832 -- old style Check_Policy pragmas for the search (we don't want
10833 -- to have to deal with multiple arguments in the search).
10834
10835 else
10836 declare
10837 Arg : Node_Id;
10838 Argx : Node_Id;
10839 LocP : Source_Ptr;
10840
10841 begin
10842 Arg := Arg1;
10843 while Present (Arg) loop
10844 LocP := Sloc (Arg);
10845 Argx := Get_Pragma_Arg (Arg);
10846
10847 -- Kind must be specified
10848
10849 if Nkind (Arg) /= N_Pragma_Argument_Association
10850 or else Chars (Arg) = No_Name
10851 then
10852 Error_Pragma_Arg
10853 ("missing assertion kind for pragma%", Arg);
10854 end if;
10855
10856 -- Construct equivalent old form syntax Check_Policy
10857 -- pragma and insert it to get remaining checks.
10858
10859 Insert_Action (N,
10860 Make_Pragma (LocP,
10861 Chars => Name_Check_Policy,
10862 Pragma_Argument_Associations => New_List (
10863 Make_Pragma_Argument_Association (LocP,
10864 Expression =>
10865 Make_Identifier (LocP, Chars (Arg))),
10866 Make_Pragma_Argument_Association (Sloc (Argx),
10867 Expression => Argx))));
10868
10869 Arg := Next (Arg);
10870 end loop;
10871
10872 -- Rewrite original Check_Policy pragma to null, since we
10873 -- have converted it into a series of old syntax pragmas.
10874
10875 Rewrite (N, Make_Null_Statement (Loc));
10876 Analyze (N);
10877 end;
10878 end if;
10879 end Check_Policy;
10880
10881 ---------------------
10882 -- CIL_Constructor --
10883 ---------------------
10884
10885 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
10886
10887 -- Processing for this pragma is shared with Java_Constructor
10888
10889 -------------
10890 -- Comment --
10891 -------------
10892
10893 -- pragma Comment (static_string_EXPRESSION)
10894
10895 -- Processing for pragma Comment shares the circuitry for pragma
10896 -- Ident. The only differences are that Ident enforces a limit of 31
10897 -- characters on its argument, and also enforces limitations on
10898 -- placement for DEC compatibility. Pragma Comment shares neither of
10899 -- these restrictions.
10900
10901 -------------------
10902 -- Common_Object --
10903 -------------------
10904
10905 -- pragma Common_Object (
10906 -- [Internal =>] LOCAL_NAME
10907 -- [, [External =>] EXTERNAL_SYMBOL]
10908 -- [, [Size =>] EXTERNAL_SYMBOL]);
10909
10910 -- Processing for this pragma is shared with Psect_Object
10911
10912 ------------------------
10913 -- Compile_Time_Error --
10914 ------------------------
10915
10916 -- pragma Compile_Time_Error
10917 -- (boolean_EXPRESSION, static_string_EXPRESSION);
10918
10919 when Pragma_Compile_Time_Error =>
10920 GNAT_Pragma;
10921 Process_Compile_Time_Warning_Or_Error;
10922
10923 --------------------------
10924 -- Compile_Time_Warning --
10925 --------------------------
10926
10927 -- pragma Compile_Time_Warning
10928 -- (boolean_EXPRESSION, static_string_EXPRESSION);
10929
10930 when Pragma_Compile_Time_Warning =>
10931 GNAT_Pragma;
10932 Process_Compile_Time_Warning_Or_Error;
10933
10934 -------------------
10935 -- Compiler_Unit --
10936 -------------------
10937
10938 when Pragma_Compiler_Unit =>
10939 GNAT_Pragma;
10940 Check_Arg_Count (0);
10941 Set_Is_Compiler_Unit (Get_Source_Unit (N));
10942
10943 -----------------------------
10944 -- Complete_Representation --
10945 -----------------------------
10946
10947 -- pragma Complete_Representation;
10948
10949 when Pragma_Complete_Representation =>
10950 GNAT_Pragma;
10951 Check_Arg_Count (0);
10952
10953 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
10954 Error_Pragma
10955 ("pragma & must appear within record representation clause");
10956 end if;
10957
10958 ----------------------------
10959 -- Complex_Representation --
10960 ----------------------------
10961
10962 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
10963
10964 when Pragma_Complex_Representation => Complex_Representation : declare
10965 E_Id : Entity_Id;
10966 E : Entity_Id;
10967 Ent : Entity_Id;
10968
10969 begin
10970 GNAT_Pragma;
10971 Check_Arg_Count (1);
10972 Check_Optional_Identifier (Arg1, Name_Entity);
10973 Check_Arg_Is_Local_Name (Arg1);
10974 E_Id := Get_Pragma_Arg (Arg1);
10975
10976 if Etype (E_Id) = Any_Type then
10977 return;
10978 end if;
10979
10980 E := Entity (E_Id);
10981
10982 if not Is_Record_Type (E) then
10983 Error_Pragma_Arg
10984 ("argument for pragma% must be record type", Arg1);
10985 end if;
10986
10987 Ent := First_Entity (E);
10988
10989 if No (Ent)
10990 or else No (Next_Entity (Ent))
10991 or else Present (Next_Entity (Next_Entity (Ent)))
10992 or else not Is_Floating_Point_Type (Etype (Ent))
10993 or else Etype (Ent) /= Etype (Next_Entity (Ent))
10994 then
10995 Error_Pragma_Arg
10996 ("record for pragma% must have two fields of the same "
10997 & "floating-point type", Arg1);
10998
10999 else
11000 Set_Has_Complex_Representation (Base_Type (E));
11001
11002 -- We need to treat the type has having a non-standard
11003 -- representation, for back-end purposes, even though in
11004 -- general a complex will have the default representation
11005 -- of a record with two real components.
11006
11007 Set_Has_Non_Standard_Rep (Base_Type (E));
11008 end if;
11009 end Complex_Representation;
11010
11011 -------------------------
11012 -- Component_Alignment --
11013 -------------------------
11014
11015 -- pragma Component_Alignment (
11016 -- [Form =>] ALIGNMENT_CHOICE
11017 -- [, [Name =>] type_LOCAL_NAME]);
11018 --
11019 -- ALIGNMENT_CHOICE ::=
11020 -- Component_Size
11021 -- | Component_Size_4
11022 -- | Storage_Unit
11023 -- | Default
11024
11025 when Pragma_Component_Alignment => Component_AlignmentP : declare
11026 Args : Args_List (1 .. 2);
11027 Names : constant Name_List (1 .. 2) := (
11028 Name_Form,
11029 Name_Name);
11030
11031 Form : Node_Id renames Args (1);
11032 Name : Node_Id renames Args (2);
11033
11034 Atype : Component_Alignment_Kind;
11035 Typ : Entity_Id;
11036
11037 begin
11038 GNAT_Pragma;
11039 Gather_Associations (Names, Args);
11040
11041 if No (Form) then
11042 Error_Pragma ("missing Form argument for pragma%");
11043 end if;
11044
11045 Check_Arg_Is_Identifier (Form);
11046
11047 -- Get proper alignment, note that Default = Component_Size on all
11048 -- machines we have so far, and we want to set this value rather
11049 -- than the default value to indicate that it has been explicitly
11050 -- set (and thus will not get overridden by the default component
11051 -- alignment for the current scope)
11052
11053 if Chars (Form) = Name_Component_Size then
11054 Atype := Calign_Component_Size;
11055
11056 elsif Chars (Form) = Name_Component_Size_4 then
11057 Atype := Calign_Component_Size_4;
11058
11059 elsif Chars (Form) = Name_Default then
11060 Atype := Calign_Component_Size;
11061
11062 elsif Chars (Form) = Name_Storage_Unit then
11063 Atype := Calign_Storage_Unit;
11064
11065 else
11066 Error_Pragma_Arg
11067 ("invalid Form parameter for pragma%", Form);
11068 end if;
11069
11070 -- Case with no name, supplied, affects scope table entry
11071
11072 if No (Name) then
11073 Scope_Stack.Table
11074 (Scope_Stack.Last).Component_Alignment_Default := Atype;
11075
11076 -- Case of name supplied
11077
11078 else
11079 Check_Arg_Is_Local_Name (Name);
11080 Find_Type (Name);
11081 Typ := Entity (Name);
11082
11083 if Typ = Any_Type
11084 or else Rep_Item_Too_Early (Typ, N)
11085 then
11086 return;
11087 else
11088 Typ := Underlying_Type (Typ);
11089 end if;
11090
11091 if not Is_Record_Type (Typ)
11092 and then not Is_Array_Type (Typ)
11093 then
11094 Error_Pragma_Arg
11095 ("Name parameter of pragma% must identify record or "
11096 & "array type", Name);
11097 end if;
11098
11099 -- An explicit Component_Alignment pragma overrides an
11100 -- implicit pragma Pack, but not an explicit one.
11101
11102 if not Has_Pragma_Pack (Base_Type (Typ)) then
11103 Set_Is_Packed (Base_Type (Typ), False);
11104 Set_Component_Alignment (Base_Type (Typ), Atype);
11105 end if;
11106 end if;
11107 end Component_AlignmentP;
11108
11109 --------------------
11110 -- Contract_Cases --
11111 --------------------
11112
11113 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
11114
11115 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
11116
11117 -- CASE_GUARD ::= boolean_EXPRESSION | others
11118
11119 -- CONSEQUENCE ::= boolean_EXPRESSION
11120
11121 when Pragma_Contract_Cases => Contract_Cases : declare
11122 Subp_Decl : Node_Id;
11123
11124 begin
11125 GNAT_Pragma;
11126 Check_Arg_Count (1);
11127
11128 -- The pragma is analyzed at the end of the declarative part which
11129 -- contains the related subprogram. Reset the analyzed flag.
11130
11131 Set_Analyzed (N, False);
11132
11133 -- Ensure the proper placement of the pragma. Contract_Cases must
11134 -- be associated with a subprogram declaration or a body that acts
11135 -- as a spec.
11136
11137 Subp_Decl :=
11138 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
11139
11140 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
11141 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
11142 or else not Acts_As_Spec (Subp_Decl))
11143 then
11144 Pragma_Misplaced;
11145 return;
11146 end if;
11147
11148 -- When the pragma appears on a subprogram body, perform the full
11149 -- analysis now.
11150
11151 if Nkind (Subp_Decl) = N_Subprogram_Body then
11152 Analyze_Contract_Cases_In_Decl_Part (N);
11153
11154 -- When Contract_Cases applies to a subprogram compilation unit,
11155 -- the corresponding pragma is placed after the unit's declaration
11156 -- node and needs to be analyzed immediately.
11157
11158 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
11159 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
11160 then
11161 Analyze_Contract_Cases_In_Decl_Part (N);
11162 end if;
11163
11164 -- Chain the pragma on the contract for further processing
11165
11166 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
11167 end Contract_Cases;
11168
11169 ----------------
11170 -- Controlled --
11171 ----------------
11172
11173 -- pragma Controlled (first_subtype_LOCAL_NAME);
11174
11175 when Pragma_Controlled => Controlled : declare
11176 Arg : Node_Id;
11177
11178 begin
11179 Check_No_Identifiers;
11180 Check_Arg_Count (1);
11181 Check_Arg_Is_Local_Name (Arg1);
11182 Arg := Get_Pragma_Arg (Arg1);
11183
11184 if not Is_Entity_Name (Arg)
11185 or else not Is_Access_Type (Entity (Arg))
11186 then
11187 Error_Pragma_Arg ("pragma% requires access type", Arg1);
11188 else
11189 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
11190 end if;
11191 end Controlled;
11192
11193 ----------------
11194 -- Convention --
11195 ----------------
11196
11197 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
11198 -- [Entity =>] LOCAL_NAME);
11199
11200 when Pragma_Convention => Convention : declare
11201 C : Convention_Id;
11202 E : Entity_Id;
11203 pragma Warnings (Off, C);
11204 pragma Warnings (Off, E);
11205 begin
11206 Check_Arg_Order ((Name_Convention, Name_Entity));
11207 Check_Ada_83_Warning;
11208 Check_Arg_Count (2);
11209 Process_Convention (C, E);
11210 end Convention;
11211
11212 ---------------------------
11213 -- Convention_Identifier --
11214 ---------------------------
11215
11216 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
11217 -- [Convention =>] convention_IDENTIFIER);
11218
11219 when Pragma_Convention_Identifier => Convention_Identifier : declare
11220 Idnam : Name_Id;
11221 Cname : Name_Id;
11222
11223 begin
11224 GNAT_Pragma;
11225 Check_Arg_Order ((Name_Name, Name_Convention));
11226 Check_Arg_Count (2);
11227 Check_Optional_Identifier (Arg1, Name_Name);
11228 Check_Optional_Identifier (Arg2, Name_Convention);
11229 Check_Arg_Is_Identifier (Arg1);
11230 Check_Arg_Is_Identifier (Arg2);
11231 Idnam := Chars (Get_Pragma_Arg (Arg1));
11232 Cname := Chars (Get_Pragma_Arg (Arg2));
11233
11234 if Is_Convention_Name (Cname) then
11235 Record_Convention_Identifier
11236 (Idnam, Get_Convention_Id (Cname));
11237 else
11238 Error_Pragma_Arg
11239 ("second arg for % pragma must be convention", Arg2);
11240 end if;
11241 end Convention_Identifier;
11242
11243 ---------------
11244 -- CPP_Class --
11245 ---------------
11246
11247 -- pragma CPP_Class ([Entity =>] local_NAME)
11248
11249 when Pragma_CPP_Class => CPP_Class : declare
11250 begin
11251 GNAT_Pragma;
11252
11253 if Warn_On_Obsolescent_Feature then
11254 Error_Msg_N
11255 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
11256 & "effect; replace it by pragma import?j?", N);
11257 end if;
11258
11259 Check_Arg_Count (1);
11260
11261 Rewrite (N,
11262 Make_Pragma (Loc,
11263 Chars => Name_Import,
11264 Pragma_Argument_Associations => New_List (
11265 Make_Pragma_Argument_Association (Loc,
11266 Expression => Make_Identifier (Loc, Name_CPP)),
11267 New_Copy (First (Pragma_Argument_Associations (N))))));
11268 Analyze (N);
11269 end CPP_Class;
11270
11271 ---------------------
11272 -- CPP_Constructor --
11273 ---------------------
11274
11275 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
11276 -- [, [External_Name =>] static_string_EXPRESSION ]
11277 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11278
11279 when Pragma_CPP_Constructor => CPP_Constructor : declare
11280 Elmt : Elmt_Id;
11281 Id : Entity_Id;
11282 Def_Id : Entity_Id;
11283 Tag_Typ : Entity_Id;
11284
11285 begin
11286 GNAT_Pragma;
11287 Check_At_Least_N_Arguments (1);
11288 Check_At_Most_N_Arguments (3);
11289 Check_Optional_Identifier (Arg1, Name_Entity);
11290 Check_Arg_Is_Local_Name (Arg1);
11291
11292 Id := Get_Pragma_Arg (Arg1);
11293 Find_Program_Unit_Name (Id);
11294
11295 -- If we did not find the name, we are done
11296
11297 if Etype (Id) = Any_Type then
11298 return;
11299 end if;
11300
11301 Def_Id := Entity (Id);
11302
11303 -- Check if already defined as constructor
11304
11305 if Is_Constructor (Def_Id) then
11306 Error_Msg_N
11307 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
11308 return;
11309 end if;
11310
11311 if Ekind (Def_Id) = E_Function
11312 and then (Is_CPP_Class (Etype (Def_Id))
11313 or else (Is_Class_Wide_Type (Etype (Def_Id))
11314 and then
11315 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
11316 then
11317 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
11318 Error_Msg_N
11319 ("'C'P'P constructor must be defined in the scope of "
11320 & "its returned type", Arg1);
11321 end if;
11322
11323 if Arg_Count >= 2 then
11324 Set_Imported (Def_Id);
11325 Set_Is_Public (Def_Id);
11326 Process_Interface_Name (Def_Id, Arg2, Arg3);
11327 end if;
11328
11329 Set_Has_Completion (Def_Id);
11330 Set_Is_Constructor (Def_Id);
11331 Set_Convention (Def_Id, Convention_CPP);
11332
11333 -- Imported C++ constructors are not dispatching primitives
11334 -- because in C++ they don't have a dispatch table slot.
11335 -- However, in Ada the constructor has the profile of a
11336 -- function that returns a tagged type and therefore it has
11337 -- been treated as a primitive operation during semantic
11338 -- analysis. We now remove it from the list of primitive
11339 -- operations of the type.
11340
11341 if Is_Tagged_Type (Etype (Def_Id))
11342 and then not Is_Class_Wide_Type (Etype (Def_Id))
11343 and then Is_Dispatching_Operation (Def_Id)
11344 then
11345 Tag_Typ := Etype (Def_Id);
11346
11347 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
11348 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
11349 Next_Elmt (Elmt);
11350 end loop;
11351
11352 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
11353 Set_Is_Dispatching_Operation (Def_Id, False);
11354 end if;
11355
11356 -- For backward compatibility, if the constructor returns a
11357 -- class wide type, and we internally change the return type to
11358 -- the corresponding root type.
11359
11360 if Is_Class_Wide_Type (Etype (Def_Id)) then
11361 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
11362 end if;
11363 else
11364 Error_Pragma_Arg
11365 ("pragma% requires function returning a 'C'P'P_Class type",
11366 Arg1);
11367 end if;
11368 end CPP_Constructor;
11369
11370 -----------------
11371 -- CPP_Virtual --
11372 -----------------
11373
11374 when Pragma_CPP_Virtual => CPP_Virtual : declare
11375 begin
11376 GNAT_Pragma;
11377
11378 if Warn_On_Obsolescent_Feature then
11379 Error_Msg_N
11380 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
11381 & "effect?j?", N);
11382 end if;
11383 end CPP_Virtual;
11384
11385 ----------------
11386 -- CPP_Vtable --
11387 ----------------
11388
11389 when Pragma_CPP_Vtable => CPP_Vtable : declare
11390 begin
11391 GNAT_Pragma;
11392
11393 if Warn_On_Obsolescent_Feature then
11394 Error_Msg_N
11395 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
11396 & "effect?j?", N);
11397 end if;
11398 end CPP_Vtable;
11399
11400 ---------
11401 -- CPU --
11402 ---------
11403
11404 -- pragma CPU (EXPRESSION);
11405
11406 when Pragma_CPU => CPU : declare
11407 P : constant Node_Id := Parent (N);
11408 Arg : Node_Id;
11409 Ent : Entity_Id;
11410
11411 begin
11412 Ada_2012_Pragma;
11413 Check_No_Identifiers;
11414 Check_Arg_Count (1);
11415
11416 -- Subprogram case
11417
11418 if Nkind (P) = N_Subprogram_Body then
11419 Check_In_Main_Program;
11420
11421 Arg := Get_Pragma_Arg (Arg1);
11422 Analyze_And_Resolve (Arg, Any_Integer);
11423
11424 Ent := Defining_Unit_Name (Specification (P));
11425
11426 if Nkind (Ent) = N_Defining_Program_Unit_Name then
11427 Ent := Defining_Identifier (Ent);
11428 end if;
11429
11430 -- Must be static
11431
11432 if not Is_Static_Expression (Arg) then
11433 Flag_Non_Static_Expr
11434 ("main subprogram affinity is not static!", Arg);
11435 raise Pragma_Exit;
11436
11437 -- If constraint error, then we already signalled an error
11438
11439 elsif Raises_Constraint_Error (Arg) then
11440 null;
11441
11442 -- Otherwise check in range
11443
11444 else
11445 declare
11446 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
11447 -- This is the entity System.Multiprocessors.CPU_Range;
11448
11449 Val : constant Uint := Expr_Value (Arg);
11450
11451 begin
11452 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
11453 or else
11454 Val > Expr_Value (Type_High_Bound (CPU_Id))
11455 then
11456 Error_Pragma_Arg
11457 ("main subprogram CPU is out of range", Arg1);
11458 end if;
11459 end;
11460 end if;
11461
11462 Set_Main_CPU
11463 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11464
11465 -- Task case
11466
11467 elsif Nkind (P) = N_Task_Definition then
11468 Arg := Get_Pragma_Arg (Arg1);
11469 Ent := Defining_Identifier (Parent (P));
11470
11471 -- The expression must be analyzed in the special manner
11472 -- described in "Handling of Default and Per-Object
11473 -- Expressions" in sem.ads.
11474
11475 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
11476
11477 -- Anything else is incorrect
11478
11479 else
11480 Pragma_Misplaced;
11481 end if;
11482
11483 -- Check duplicate pragma before we chain the pragma in the Rep
11484 -- Item chain of Ent.
11485
11486 Check_Duplicate_Pragma (Ent);
11487 Record_Rep_Item (Ent, N);
11488 end CPU;
11489
11490 -----------
11491 -- Debug --
11492 -----------
11493
11494 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
11495
11496 when Pragma_Debug => Debug : declare
11497 Cond : Node_Id;
11498 Call : Node_Id;
11499
11500 begin
11501 GNAT_Pragma;
11502
11503 -- The condition for executing the call is that the expander
11504 -- is active and that we are not ignoring this debug pragma.
11505
11506 Cond :=
11507 New_Occurrence_Of
11508 (Boolean_Literals
11509 (Expander_Active and then not Is_Ignored (N)),
11510 Loc);
11511
11512 if not Is_Ignored (N) then
11513 Set_SCO_Pragma_Enabled (Loc);
11514 end if;
11515
11516 if Arg_Count = 2 then
11517 Cond :=
11518 Make_And_Then (Loc,
11519 Left_Opnd => Relocate_Node (Cond),
11520 Right_Opnd => Get_Pragma_Arg (Arg1));
11521 Call := Get_Pragma_Arg (Arg2);
11522 else
11523 Call := Get_Pragma_Arg (Arg1);
11524 end if;
11525
11526 if Nkind_In (Call,
11527 N_Indexed_Component,
11528 N_Function_Call,
11529 N_Identifier,
11530 N_Expanded_Name,
11531 N_Selected_Component)
11532 then
11533 -- If this pragma Debug comes from source, its argument was
11534 -- parsed as a name form (which is syntactically identical).
11535 -- In a generic context a parameterless call will be left as
11536 -- an expanded name (if global) or selected_component if local.
11537 -- Change it to a procedure call statement now.
11538
11539 Change_Name_To_Procedure_Call_Statement (Call);
11540
11541 elsif Nkind (Call) = N_Procedure_Call_Statement then
11542
11543 -- Already in the form of a procedure call statement: nothing
11544 -- to do (could happen in case of an internally generated
11545 -- pragma Debug).
11546
11547 null;
11548
11549 else
11550 -- All other cases: diagnose error
11551
11552 Error_Msg
11553 ("argument of pragma ""Debug"" is not procedure call",
11554 Sloc (Call));
11555 return;
11556 end if;
11557
11558 -- Rewrite into a conditional with an appropriate condition. We
11559 -- wrap the procedure call in a block so that overhead from e.g.
11560 -- use of the secondary stack does not generate execution overhead
11561 -- for suppressed conditions.
11562
11563 -- Normally the analysis that follows will freeze the subprogram
11564 -- being called. However, if the call is to a null procedure,
11565 -- we want to freeze it before creating the block, because the
11566 -- analysis that follows may be done with expansion disabled, in
11567 -- which case the body will not be generated, leading to spurious
11568 -- errors.
11569
11570 if Nkind (Call) = N_Procedure_Call_Statement
11571 and then Is_Entity_Name (Name (Call))
11572 then
11573 Analyze (Name (Call));
11574 Freeze_Before (N, Entity (Name (Call)));
11575 end if;
11576
11577 Rewrite (N, Make_Implicit_If_Statement (N,
11578 Condition => Cond,
11579 Then_Statements => New_List (
11580 Make_Block_Statement (Loc,
11581 Handled_Statement_Sequence =>
11582 Make_Handled_Sequence_Of_Statements (Loc,
11583 Statements => New_List (Relocate_Node (Call)))))));
11584 Analyze (N);
11585 end Debug;
11586
11587 ------------------
11588 -- Debug_Policy --
11589 ------------------
11590
11591 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
11592
11593 when Pragma_Debug_Policy =>
11594 GNAT_Pragma;
11595 Check_Arg_Count (1);
11596 Check_No_Identifiers;
11597 Check_Arg_Is_Identifier (Arg1);
11598
11599 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
11600 -- rewrite it that way, and let the rest of the checking come
11601 -- from analyzing the rewritten pragma.
11602
11603 Rewrite (N,
11604 Make_Pragma (Loc,
11605 Chars => Name_Check_Policy,
11606 Pragma_Argument_Associations => New_List (
11607 Make_Pragma_Argument_Association (Loc,
11608 Expression => Make_Identifier (Loc, Name_Debug)),
11609
11610 Make_Pragma_Argument_Association (Loc,
11611 Expression => Get_Pragma_Arg (Arg1)))));
11612 Analyze (N);
11613
11614 -------------
11615 -- Depends --
11616 -------------
11617
11618 -- pragma Depends (DEPENDENCY_RELATION);
11619
11620 -- DEPENDENCY_RELATION ::=
11621 -- null
11622 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
11623
11624 -- DEPENDENCY_CLAUSE ::=
11625 -- OUTPUT_LIST =>[+] INPUT_LIST
11626 -- | NULL_DEPENDENCY_CLAUSE
11627
11628 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
11629
11630 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
11631
11632 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
11633
11634 -- OUTPUT ::= NAME | FUNCTION_RESULT
11635 -- INPUT ::= NAME
11636
11637 -- where FUNCTION_RESULT is a function Result attribute_reference
11638
11639 when Pragma_Depends => Depends : declare
11640 Subp_Decl : Node_Id;
11641
11642 begin
11643 GNAT_Pragma;
11644 S14_Pragma;
11645 Check_Arg_Count (1);
11646
11647 -- Ensure the proper placement of the pragma. Depends must be
11648 -- associated with a subprogram declaration or a body that acts
11649 -- as a spec.
11650
11651 Subp_Decl :=
11652 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
11653
11654 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
11655 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
11656 or else not Acts_As_Spec (Subp_Decl))
11657 then
11658 Pragma_Misplaced;
11659 return;
11660 end if;
11661
11662 -- When the pragma appears on a subprogram body, perform the full
11663 -- analysis now.
11664
11665 if Nkind (Subp_Decl) = N_Subprogram_Body then
11666 Analyze_Depends_In_Decl_Part (N);
11667
11668 -- When Depends applies to a subprogram compilation unit, the
11669 -- corresponding pragma is placed after the unit's declaration
11670 -- node and needs to be analyzed immediately.
11671
11672 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
11673 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
11674 then
11675 Analyze_Depends_In_Decl_Part (N);
11676 end if;
11677
11678 -- Chain the pragma on the contract for further processing
11679
11680 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
11681 end Depends;
11682
11683 ---------------------
11684 -- Detect_Blocking --
11685 ---------------------
11686
11687 -- pragma Detect_Blocking;
11688
11689 when Pragma_Detect_Blocking =>
11690 Ada_2005_Pragma;
11691 Check_Arg_Count (0);
11692 Check_Valid_Configuration_Pragma;
11693 Detect_Blocking := True;
11694
11695 --------------------------
11696 -- Default_Storage_Pool --
11697 --------------------------
11698
11699 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
11700
11701 when Pragma_Default_Storage_Pool =>
11702 Ada_2012_Pragma;
11703 Check_Arg_Count (1);
11704
11705 -- Default_Storage_Pool can appear as a configuration pragma, or
11706 -- in a declarative part or a package spec.
11707
11708 if not Is_Configuration_Pragma then
11709 Check_Is_In_Decl_Part_Or_Package_Spec;
11710 end if;
11711
11712 -- Case of Default_Storage_Pool (null);
11713
11714 if Nkind (Expression (Arg1)) = N_Null then
11715 Analyze (Expression (Arg1));
11716
11717 -- This is an odd case, this is not really an expression, so
11718 -- we don't have a type for it. So just set the type to Empty.
11719
11720 Set_Etype (Expression (Arg1), Empty);
11721
11722 -- Case of Default_Storage_Pool (storage_pool_NAME);
11723
11724 else
11725 -- If it's a configuration pragma, then the only allowed
11726 -- argument is "null".
11727
11728 if Is_Configuration_Pragma then
11729 Error_Pragma_Arg ("NULL expected", Arg1);
11730 end if;
11731
11732 -- The expected type for a non-"null" argument is
11733 -- Root_Storage_Pool'Class.
11734
11735 Analyze_And_Resolve
11736 (Get_Pragma_Arg (Arg1),
11737 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
11738 end if;
11739
11740 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
11741 -- for an access type will use this information to set the
11742 -- appropriate attributes of the access type.
11743
11744 Default_Pool := Expression (Arg1);
11745
11746 ------------------------------------
11747 -- Disable_Atomic_Synchronization --
11748 ------------------------------------
11749
11750 -- pragma Disable_Atomic_Synchronization [(Entity)];
11751
11752 when Pragma_Disable_Atomic_Synchronization =>
11753 GNAT_Pragma;
11754 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
11755
11756 -------------------
11757 -- Discard_Names --
11758 -------------------
11759
11760 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
11761
11762 when Pragma_Discard_Names => Discard_Names : declare
11763 E : Entity_Id;
11764 E_Id : Entity_Id;
11765
11766 begin
11767 Check_Ada_83_Warning;
11768
11769 -- Deal with configuration pragma case
11770
11771 if Arg_Count = 0 and then Is_Configuration_Pragma then
11772 Global_Discard_Names := True;
11773 return;
11774
11775 -- Otherwise, check correct appropriate context
11776
11777 else
11778 Check_Is_In_Decl_Part_Or_Package_Spec;
11779
11780 if Arg_Count = 0 then
11781
11782 -- If there is no parameter, then from now on this pragma
11783 -- applies to any enumeration, exception or tagged type
11784 -- defined in the current declarative part, and recursively
11785 -- to any nested scope.
11786
11787 Set_Discard_Names (Current_Scope);
11788 return;
11789
11790 else
11791 Check_Arg_Count (1);
11792 Check_Optional_Identifier (Arg1, Name_On);
11793 Check_Arg_Is_Local_Name (Arg1);
11794
11795 E_Id := Get_Pragma_Arg (Arg1);
11796
11797 if Etype (E_Id) = Any_Type then
11798 return;
11799 else
11800 E := Entity (E_Id);
11801 end if;
11802
11803 if (Is_First_Subtype (E)
11804 and then
11805 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
11806 or else Ekind (E) = E_Exception
11807 then
11808 Set_Discard_Names (E);
11809 Record_Rep_Item (E, N);
11810
11811 else
11812 Error_Pragma_Arg
11813 ("inappropriate entity for pragma%", Arg1);
11814 end if;
11815
11816 end if;
11817 end if;
11818 end Discard_Names;
11819
11820 ------------------------
11821 -- Dispatching_Domain --
11822 ------------------------
11823
11824 -- pragma Dispatching_Domain (EXPRESSION);
11825
11826 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
11827 P : constant Node_Id := Parent (N);
11828 Arg : Node_Id;
11829 Ent : Entity_Id;
11830
11831 begin
11832 Ada_2012_Pragma;
11833 Check_No_Identifiers;
11834 Check_Arg_Count (1);
11835
11836 -- This pragma is born obsolete, but not the aspect
11837
11838 if not From_Aspect_Specification (N) then
11839 Check_Restriction
11840 (No_Obsolescent_Features, Pragma_Identifier (N));
11841 end if;
11842
11843 if Nkind (P) = N_Task_Definition then
11844 Arg := Get_Pragma_Arg (Arg1);
11845 Ent := Defining_Identifier (Parent (P));
11846
11847 -- The expression must be analyzed in the special manner
11848 -- described in "Handling of Default and Per-Object
11849 -- Expressions" in sem.ads.
11850
11851 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
11852
11853 -- Check duplicate pragma before we chain the pragma in the Rep
11854 -- Item chain of Ent.
11855
11856 Check_Duplicate_Pragma (Ent);
11857 Record_Rep_Item (Ent, N);
11858
11859 -- Anything else is incorrect
11860
11861 else
11862 Pragma_Misplaced;
11863 end if;
11864 end Dispatching_Domain;
11865
11866 ---------------
11867 -- Elaborate --
11868 ---------------
11869
11870 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
11871
11872 when Pragma_Elaborate => Elaborate : declare
11873 Arg : Node_Id;
11874 Citem : Node_Id;
11875
11876 begin
11877 -- Pragma must be in context items list of a compilation unit
11878
11879 if not Is_In_Context_Clause then
11880 Pragma_Misplaced;
11881 end if;
11882
11883 -- Must be at least one argument
11884
11885 if Arg_Count = 0 then
11886 Error_Pragma ("pragma% requires at least one argument");
11887 end if;
11888
11889 -- In Ada 83 mode, there can be no items following it in the
11890 -- context list except other pragmas and implicit with clauses
11891 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
11892 -- placement rule does not apply.
11893
11894 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
11895 Citem := Next (N);
11896 while Present (Citem) loop
11897 if Nkind (Citem) = N_Pragma
11898 or else (Nkind (Citem) = N_With_Clause
11899 and then Implicit_With (Citem))
11900 then
11901 null;
11902 else
11903 Error_Pragma
11904 ("(Ada 83) pragma% must be at end of context clause");
11905 end if;
11906
11907 Next (Citem);
11908 end loop;
11909 end if;
11910
11911 -- Finally, the arguments must all be units mentioned in a with
11912 -- clause in the same context clause. Note we already checked (in
11913 -- Par.Prag) that the arguments are all identifiers or selected
11914 -- components.
11915
11916 Arg := Arg1;
11917 Outer : while Present (Arg) loop
11918 Citem := First (List_Containing (N));
11919 Inner : while Citem /= N loop
11920 if Nkind (Citem) = N_With_Clause
11921 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
11922 then
11923 Set_Elaborate_Present (Citem, True);
11924 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
11925 Generate_Reference (Entity (Name (Citem)), Citem);
11926
11927 -- With the pragma present, elaboration calls on
11928 -- subprograms from the named unit need no further
11929 -- checks, as long as the pragma appears in the current
11930 -- compilation unit. If the pragma appears in some unit
11931 -- in the context, there might still be a need for an
11932 -- Elaborate_All_Desirable from the current compilation
11933 -- to the named unit, so we keep the check enabled.
11934
11935 if In_Extended_Main_Source_Unit (N) then
11936 Set_Suppress_Elaboration_Warnings
11937 (Entity (Name (Citem)));
11938 end if;
11939
11940 exit Inner;
11941 end if;
11942
11943 Next (Citem);
11944 end loop Inner;
11945
11946 if Citem = N then
11947 Error_Pragma_Arg
11948 ("argument of pragma% is not withed unit", Arg);
11949 end if;
11950
11951 Next (Arg);
11952 end loop Outer;
11953
11954 -- Give a warning if operating in static mode with -gnatwl
11955 -- (elaboration warnings enabled) switch set.
11956
11957 if Elab_Warnings and not Dynamic_Elaboration_Checks then
11958 Error_Msg_N
11959 ("?l?use of pragma Elaborate may not be safe", N);
11960 Error_Msg_N
11961 ("?l?use pragma Elaborate_All instead if possible", N);
11962 end if;
11963 end Elaborate;
11964
11965 -------------------
11966 -- Elaborate_All --
11967 -------------------
11968
11969 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
11970
11971 when Pragma_Elaborate_All => Elaborate_All : declare
11972 Arg : Node_Id;
11973 Citem : Node_Id;
11974
11975 begin
11976 Check_Ada_83_Warning;
11977
11978 -- Pragma must be in context items list of a compilation unit
11979
11980 if not Is_In_Context_Clause then
11981 Pragma_Misplaced;
11982 end if;
11983
11984 -- Must be at least one argument
11985
11986 if Arg_Count = 0 then
11987 Error_Pragma ("pragma% requires at least one argument");
11988 end if;
11989
11990 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
11991 -- have to appear at the end of the context clause, but may
11992 -- appear mixed in with other items, even in Ada 83 mode.
11993
11994 -- Final check: the arguments must all be units mentioned in
11995 -- a with clause in the same context clause. Note that we
11996 -- already checked (in Par.Prag) that all the arguments are
11997 -- either identifiers or selected components.
11998
11999 Arg := Arg1;
12000 Outr : while Present (Arg) loop
12001 Citem := First (List_Containing (N));
12002 Innr : while Citem /= N loop
12003 if Nkind (Citem) = N_With_Clause
12004 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
12005 then
12006 Set_Elaborate_All_Present (Citem, True);
12007 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
12008
12009 -- Suppress warnings and elaboration checks on the named
12010 -- unit if the pragma is in the current compilation, as
12011 -- for pragma Elaborate.
12012
12013 if In_Extended_Main_Source_Unit (N) then
12014 Set_Suppress_Elaboration_Warnings
12015 (Entity (Name (Citem)));
12016 end if;
12017 exit Innr;
12018 end if;
12019
12020 Next (Citem);
12021 end loop Innr;
12022
12023 if Citem = N then
12024 Set_Error_Posted (N);
12025 Error_Pragma_Arg
12026 ("argument of pragma% is not withed unit", Arg);
12027 end if;
12028
12029 Next (Arg);
12030 end loop Outr;
12031 end Elaborate_All;
12032
12033 --------------------
12034 -- Elaborate_Body --
12035 --------------------
12036
12037 -- pragma Elaborate_Body [( library_unit_NAME )];
12038
12039 when Pragma_Elaborate_Body => Elaborate_Body : declare
12040 Cunit_Node : Node_Id;
12041 Cunit_Ent : Entity_Id;
12042
12043 begin
12044 Check_Ada_83_Warning;
12045 Check_Valid_Library_Unit_Pragma;
12046
12047 if Nkind (N) = N_Null_Statement then
12048 return;
12049 end if;
12050
12051 Cunit_Node := Cunit (Current_Sem_Unit);
12052 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12053
12054 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
12055 N_Subprogram_Body)
12056 then
12057 Error_Pragma ("pragma% must refer to a spec, not a body");
12058 else
12059 Set_Body_Required (Cunit_Node, True);
12060 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
12061
12062 -- If we are in dynamic elaboration mode, then we suppress
12063 -- elaboration warnings for the unit, since it is definitely
12064 -- fine NOT to do dynamic checks at the first level (and such
12065 -- checks will be suppressed because no elaboration boolean
12066 -- is created for Elaborate_Body packages).
12067
12068 -- But in the static model of elaboration, Elaborate_Body is
12069 -- definitely NOT good enough to ensure elaboration safety on
12070 -- its own, since the body may WITH other units that are not
12071 -- safe from an elaboration point of view, so a client must
12072 -- still do an Elaborate_All on such units.
12073
12074 -- Debug flag -gnatdD restores the old behavior of 3.13, where
12075 -- Elaborate_Body always suppressed elab warnings.
12076
12077 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
12078 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
12079 end if;
12080 end if;
12081 end Elaborate_Body;
12082
12083 ------------------------
12084 -- Elaboration_Checks --
12085 ------------------------
12086
12087 -- pragma Elaboration_Checks (Static | Dynamic);
12088
12089 when Pragma_Elaboration_Checks =>
12090 GNAT_Pragma;
12091 Check_Arg_Count (1);
12092 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
12093 Dynamic_Elaboration_Checks :=
12094 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
12095
12096 ---------------
12097 -- Eliminate --
12098 ---------------
12099
12100 -- pragma Eliminate (
12101 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
12102 -- [,[Entity =>] IDENTIFIER |
12103 -- SELECTED_COMPONENT |
12104 -- STRING_LITERAL]
12105 -- [, OVERLOADING_RESOLUTION]);
12106
12107 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
12108 -- SOURCE_LOCATION
12109
12110 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
12111 -- FUNCTION_PROFILE
12112
12113 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
12114
12115 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
12116 -- Result_Type => result_SUBTYPE_NAME]
12117
12118 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
12119 -- SUBTYPE_NAME ::= STRING_LITERAL
12120
12121 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
12122 -- SOURCE_TRACE ::= STRING_LITERAL
12123
12124 when Pragma_Eliminate => Eliminate : declare
12125 Args : Args_List (1 .. 5);
12126 Names : constant Name_List (1 .. 5) := (
12127 Name_Unit_Name,
12128 Name_Entity,
12129 Name_Parameter_Types,
12130 Name_Result_Type,
12131 Name_Source_Location);
12132
12133 Unit_Name : Node_Id renames Args (1);
12134 Entity : Node_Id renames Args (2);
12135 Parameter_Types : Node_Id renames Args (3);
12136 Result_Type : Node_Id renames Args (4);
12137 Source_Location : Node_Id renames Args (5);
12138
12139 begin
12140 GNAT_Pragma;
12141 Check_Valid_Configuration_Pragma;
12142 Gather_Associations (Names, Args);
12143
12144 if No (Unit_Name) then
12145 Error_Pragma ("missing Unit_Name argument for pragma%");
12146 end if;
12147
12148 if No (Entity)
12149 and then (Present (Parameter_Types)
12150 or else
12151 Present (Result_Type)
12152 or else
12153 Present (Source_Location))
12154 then
12155 Error_Pragma ("missing Entity argument for pragma%");
12156 end if;
12157
12158 if (Present (Parameter_Types)
12159 or else
12160 Present (Result_Type))
12161 and then
12162 Present (Source_Location)
12163 then
12164 Error_Pragma
12165 ("parameter profile and source location cannot be used "
12166 & "together in pragma%");
12167 end if;
12168
12169 Process_Eliminate_Pragma
12170 (N,
12171 Unit_Name,
12172 Entity,
12173 Parameter_Types,
12174 Result_Type,
12175 Source_Location);
12176 end Eliminate;
12177
12178 -----------------------------------
12179 -- Enable_Atomic_Synchronization --
12180 -----------------------------------
12181
12182 -- pragma Enable_Atomic_Synchronization [(Entity)];
12183
12184 when Pragma_Enable_Atomic_Synchronization =>
12185 GNAT_Pragma;
12186 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
12187
12188 ------------
12189 -- Export --
12190 ------------
12191
12192 -- pragma Export (
12193 -- [ Convention =>] convention_IDENTIFIER,
12194 -- [ Entity =>] local_NAME
12195 -- [, [External_Name =>] static_string_EXPRESSION ]
12196 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12197
12198 when Pragma_Export => Export : declare
12199 C : Convention_Id;
12200 Def_Id : Entity_Id;
12201
12202 pragma Warnings (Off, C);
12203
12204 begin
12205 Check_Ada_83_Warning;
12206 Check_Arg_Order
12207 ((Name_Convention,
12208 Name_Entity,
12209 Name_External_Name,
12210 Name_Link_Name));
12211
12212 Check_At_Least_N_Arguments (2);
12213 Check_At_Most_N_Arguments (4);
12214 Process_Convention (C, Def_Id);
12215
12216 if Ekind (Def_Id) /= E_Constant then
12217 Note_Possible_Modification
12218 (Get_Pragma_Arg (Arg2), Sure => False);
12219 end if;
12220
12221 Process_Interface_Name (Def_Id, Arg3, Arg4);
12222 Set_Exported (Def_Id, Arg2);
12223
12224 -- If the entity is a deferred constant, propagate the information
12225 -- to the full view, because gigi elaborates the full view only.
12226
12227 if Ekind (Def_Id) = E_Constant
12228 and then Present (Full_View (Def_Id))
12229 then
12230 declare
12231 Id2 : constant Entity_Id := Full_View (Def_Id);
12232 begin
12233 Set_Is_Exported (Id2, Is_Exported (Def_Id));
12234 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
12235 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
12236 end;
12237 end if;
12238 end Export;
12239
12240 ----------------------
12241 -- Export_Exception --
12242 ----------------------
12243
12244 -- pragma Export_Exception (
12245 -- [Internal =>] LOCAL_NAME
12246 -- [, [External =>] EXTERNAL_SYMBOL]
12247 -- [, [Form =>] Ada | VMS]
12248 -- [, [Code =>] static_integer_EXPRESSION]);
12249
12250 when Pragma_Export_Exception => Export_Exception : declare
12251 Args : Args_List (1 .. 4);
12252 Names : constant Name_List (1 .. 4) := (
12253 Name_Internal,
12254 Name_External,
12255 Name_Form,
12256 Name_Code);
12257
12258 Internal : Node_Id renames Args (1);
12259 External : Node_Id renames Args (2);
12260 Form : Node_Id renames Args (3);
12261 Code : Node_Id renames Args (4);
12262
12263 begin
12264 GNAT_Pragma;
12265
12266 if Inside_A_Generic then
12267 Error_Pragma ("pragma% cannot be used for generic entities");
12268 end if;
12269
12270 Gather_Associations (Names, Args);
12271 Process_Extended_Import_Export_Exception_Pragma (
12272 Arg_Internal => Internal,
12273 Arg_External => External,
12274 Arg_Form => Form,
12275 Arg_Code => Code);
12276
12277 if not Is_VMS_Exception (Entity (Internal)) then
12278 Set_Exported (Entity (Internal), Internal);
12279 end if;
12280 end Export_Exception;
12281
12282 ---------------------
12283 -- Export_Function --
12284 ---------------------
12285
12286 -- pragma Export_Function (
12287 -- [Internal =>] LOCAL_NAME
12288 -- [, [External =>] EXTERNAL_SYMBOL]
12289 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12290 -- [, [Result_Type =>] TYPE_DESIGNATOR]
12291 -- [, [Mechanism =>] MECHANISM]
12292 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
12293
12294 -- EXTERNAL_SYMBOL ::=
12295 -- IDENTIFIER
12296 -- | static_string_EXPRESSION
12297
12298 -- PARAMETER_TYPES ::=
12299 -- null
12300 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12301
12302 -- TYPE_DESIGNATOR ::=
12303 -- subtype_NAME
12304 -- | subtype_Name ' Access
12305
12306 -- MECHANISM ::=
12307 -- MECHANISM_NAME
12308 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12309
12310 -- MECHANISM_ASSOCIATION ::=
12311 -- [formal_parameter_NAME =>] MECHANISM_NAME
12312
12313 -- MECHANISM_NAME ::=
12314 -- Value
12315 -- | Reference
12316 -- | Descriptor [([Class =>] CLASS_NAME)]
12317
12318 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12319
12320 when Pragma_Export_Function => Export_Function : declare
12321 Args : Args_List (1 .. 6);
12322 Names : constant Name_List (1 .. 6) := (
12323 Name_Internal,
12324 Name_External,
12325 Name_Parameter_Types,
12326 Name_Result_Type,
12327 Name_Mechanism,
12328 Name_Result_Mechanism);
12329
12330 Internal : Node_Id renames Args (1);
12331 External : Node_Id renames Args (2);
12332 Parameter_Types : Node_Id renames Args (3);
12333 Result_Type : Node_Id renames Args (4);
12334 Mechanism : Node_Id renames Args (5);
12335 Result_Mechanism : Node_Id renames Args (6);
12336
12337 begin
12338 GNAT_Pragma;
12339 Gather_Associations (Names, Args);
12340 Process_Extended_Import_Export_Subprogram_Pragma (
12341 Arg_Internal => Internal,
12342 Arg_External => External,
12343 Arg_Parameter_Types => Parameter_Types,
12344 Arg_Result_Type => Result_Type,
12345 Arg_Mechanism => Mechanism,
12346 Arg_Result_Mechanism => Result_Mechanism);
12347 end Export_Function;
12348
12349 -------------------
12350 -- Export_Object --
12351 -------------------
12352
12353 -- pragma Export_Object (
12354 -- [Internal =>] LOCAL_NAME
12355 -- [, [External =>] EXTERNAL_SYMBOL]
12356 -- [, [Size =>] EXTERNAL_SYMBOL]);
12357
12358 -- EXTERNAL_SYMBOL ::=
12359 -- IDENTIFIER
12360 -- | static_string_EXPRESSION
12361
12362 -- PARAMETER_TYPES ::=
12363 -- null
12364 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12365
12366 -- TYPE_DESIGNATOR ::=
12367 -- subtype_NAME
12368 -- | subtype_Name ' Access
12369
12370 -- MECHANISM ::=
12371 -- MECHANISM_NAME
12372 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12373
12374 -- MECHANISM_ASSOCIATION ::=
12375 -- [formal_parameter_NAME =>] MECHANISM_NAME
12376
12377 -- MECHANISM_NAME ::=
12378 -- Value
12379 -- | Reference
12380 -- | Descriptor [([Class =>] CLASS_NAME)]
12381
12382 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12383
12384 when Pragma_Export_Object => Export_Object : declare
12385 Args : Args_List (1 .. 3);
12386 Names : constant Name_List (1 .. 3) := (
12387 Name_Internal,
12388 Name_External,
12389 Name_Size);
12390
12391 Internal : Node_Id renames Args (1);
12392 External : Node_Id renames Args (2);
12393 Size : Node_Id renames Args (3);
12394
12395 begin
12396 GNAT_Pragma;
12397 Gather_Associations (Names, Args);
12398 Process_Extended_Import_Export_Object_Pragma (
12399 Arg_Internal => Internal,
12400 Arg_External => External,
12401 Arg_Size => Size);
12402 end Export_Object;
12403
12404 ----------------------
12405 -- Export_Procedure --
12406 ----------------------
12407
12408 -- pragma Export_Procedure (
12409 -- [Internal =>] LOCAL_NAME
12410 -- [, [External =>] EXTERNAL_SYMBOL]
12411 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12412 -- [, [Mechanism =>] MECHANISM]);
12413
12414 -- EXTERNAL_SYMBOL ::=
12415 -- IDENTIFIER
12416 -- | static_string_EXPRESSION
12417
12418 -- PARAMETER_TYPES ::=
12419 -- null
12420 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12421
12422 -- TYPE_DESIGNATOR ::=
12423 -- subtype_NAME
12424 -- | subtype_Name ' Access
12425
12426 -- MECHANISM ::=
12427 -- MECHANISM_NAME
12428 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12429
12430 -- MECHANISM_ASSOCIATION ::=
12431 -- [formal_parameter_NAME =>] MECHANISM_NAME
12432
12433 -- MECHANISM_NAME ::=
12434 -- Value
12435 -- | Reference
12436 -- | Descriptor [([Class =>] CLASS_NAME)]
12437
12438 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12439
12440 when Pragma_Export_Procedure => Export_Procedure : declare
12441 Args : Args_List (1 .. 4);
12442 Names : constant Name_List (1 .. 4) := (
12443 Name_Internal,
12444 Name_External,
12445 Name_Parameter_Types,
12446 Name_Mechanism);
12447
12448 Internal : Node_Id renames Args (1);
12449 External : Node_Id renames Args (2);
12450 Parameter_Types : Node_Id renames Args (3);
12451 Mechanism : Node_Id renames Args (4);
12452
12453 begin
12454 GNAT_Pragma;
12455 Gather_Associations (Names, Args);
12456 Process_Extended_Import_Export_Subprogram_Pragma (
12457 Arg_Internal => Internal,
12458 Arg_External => External,
12459 Arg_Parameter_Types => Parameter_Types,
12460 Arg_Mechanism => Mechanism);
12461 end Export_Procedure;
12462
12463 ------------------
12464 -- Export_Value --
12465 ------------------
12466
12467 -- pragma Export_Value (
12468 -- [Value =>] static_integer_EXPRESSION,
12469 -- [Link_Name =>] static_string_EXPRESSION);
12470
12471 when Pragma_Export_Value =>
12472 GNAT_Pragma;
12473 Check_Arg_Order ((Name_Value, Name_Link_Name));
12474 Check_Arg_Count (2);
12475
12476 Check_Optional_Identifier (Arg1, Name_Value);
12477 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12478
12479 Check_Optional_Identifier (Arg2, Name_Link_Name);
12480 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12481
12482 -----------------------------
12483 -- Export_Valued_Procedure --
12484 -----------------------------
12485
12486 -- pragma Export_Valued_Procedure (
12487 -- [Internal =>] LOCAL_NAME
12488 -- [, [External =>] EXTERNAL_SYMBOL,]
12489 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12490 -- [, [Mechanism =>] MECHANISM]);
12491
12492 -- EXTERNAL_SYMBOL ::=
12493 -- IDENTIFIER
12494 -- | static_string_EXPRESSION
12495
12496 -- PARAMETER_TYPES ::=
12497 -- null
12498 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12499
12500 -- TYPE_DESIGNATOR ::=
12501 -- subtype_NAME
12502 -- | subtype_Name ' Access
12503
12504 -- MECHANISM ::=
12505 -- MECHANISM_NAME
12506 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12507
12508 -- MECHANISM_ASSOCIATION ::=
12509 -- [formal_parameter_NAME =>] MECHANISM_NAME
12510
12511 -- MECHANISM_NAME ::=
12512 -- Value
12513 -- | Reference
12514 -- | Descriptor [([Class =>] CLASS_NAME)]
12515
12516 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12517
12518 when Pragma_Export_Valued_Procedure =>
12519 Export_Valued_Procedure : declare
12520 Args : Args_List (1 .. 4);
12521 Names : constant Name_List (1 .. 4) := (
12522 Name_Internal,
12523 Name_External,
12524 Name_Parameter_Types,
12525 Name_Mechanism);
12526
12527 Internal : Node_Id renames Args (1);
12528 External : Node_Id renames Args (2);
12529 Parameter_Types : Node_Id renames Args (3);
12530 Mechanism : Node_Id renames Args (4);
12531
12532 begin
12533 GNAT_Pragma;
12534 Gather_Associations (Names, Args);
12535 Process_Extended_Import_Export_Subprogram_Pragma (
12536 Arg_Internal => Internal,
12537 Arg_External => External,
12538 Arg_Parameter_Types => Parameter_Types,
12539 Arg_Mechanism => Mechanism);
12540 end Export_Valued_Procedure;
12541
12542 -------------------
12543 -- Extend_System --
12544 -------------------
12545
12546 -- pragma Extend_System ([Name =>] Identifier);
12547
12548 when Pragma_Extend_System => Extend_System : declare
12549 begin
12550 GNAT_Pragma;
12551 Check_Valid_Configuration_Pragma;
12552 Check_Arg_Count (1);
12553 Check_Optional_Identifier (Arg1, Name_Name);
12554 Check_Arg_Is_Identifier (Arg1);
12555
12556 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12557
12558 if Name_Len > 4
12559 and then Name_Buffer (1 .. 4) = "aux_"
12560 then
12561 if Present (System_Extend_Pragma_Arg) then
12562 if Chars (Get_Pragma_Arg (Arg1)) =
12563 Chars (Expression (System_Extend_Pragma_Arg))
12564 then
12565 null;
12566 else
12567 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
12568 Error_Pragma ("pragma% conflicts with that #");
12569 end if;
12570
12571 else
12572 System_Extend_Pragma_Arg := Arg1;
12573
12574 if not GNAT_Mode then
12575 System_Extend_Unit := Arg1;
12576 end if;
12577 end if;
12578 else
12579 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
12580 end if;
12581 end Extend_System;
12582
12583 ------------------------
12584 -- Extensions_Allowed --
12585 ------------------------
12586
12587 -- pragma Extensions_Allowed (ON | OFF);
12588
12589 when Pragma_Extensions_Allowed =>
12590 GNAT_Pragma;
12591 Check_Arg_Count (1);
12592 Check_No_Identifiers;
12593 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12594
12595 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
12596 Extensions_Allowed := True;
12597 Ada_Version := Ada_Version_Type'Last;
12598
12599 else
12600 Extensions_Allowed := False;
12601 Ada_Version := Ada_Version_Explicit;
12602 Ada_Version_Pragma := Empty;
12603 end if;
12604
12605 --------------
12606 -- External --
12607 --------------
12608
12609 -- pragma External (
12610 -- [ Convention =>] convention_IDENTIFIER,
12611 -- [ Entity =>] local_NAME
12612 -- [, [External_Name =>] static_string_EXPRESSION ]
12613 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12614
12615 when Pragma_External => External : declare
12616 Def_Id : Entity_Id;
12617
12618 C : Convention_Id;
12619 pragma Warnings (Off, C);
12620
12621 begin
12622 GNAT_Pragma;
12623 Check_Arg_Order
12624 ((Name_Convention,
12625 Name_Entity,
12626 Name_External_Name,
12627 Name_Link_Name));
12628 Check_At_Least_N_Arguments (2);
12629 Check_At_Most_N_Arguments (4);
12630 Process_Convention (C, Def_Id);
12631 Note_Possible_Modification
12632 (Get_Pragma_Arg (Arg2), Sure => False);
12633 Process_Interface_Name (Def_Id, Arg3, Arg4);
12634 Set_Exported (Def_Id, Arg2);
12635 end External;
12636
12637 --------------------------
12638 -- External_Name_Casing --
12639 --------------------------
12640
12641 -- pragma External_Name_Casing (
12642 -- UPPERCASE | LOWERCASE
12643 -- [, AS_IS | UPPERCASE | LOWERCASE]);
12644
12645 when Pragma_External_Name_Casing => External_Name_Casing : declare
12646 begin
12647 GNAT_Pragma;
12648 Check_No_Identifiers;
12649
12650 if Arg_Count = 2 then
12651 Check_Arg_Is_One_Of
12652 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
12653
12654 case Chars (Get_Pragma_Arg (Arg2)) is
12655 when Name_As_Is =>
12656 Opt.External_Name_Exp_Casing := As_Is;
12657
12658 when Name_Uppercase =>
12659 Opt.External_Name_Exp_Casing := Uppercase;
12660
12661 when Name_Lowercase =>
12662 Opt.External_Name_Exp_Casing := Lowercase;
12663
12664 when others =>
12665 null;
12666 end case;
12667
12668 else
12669 Check_Arg_Count (1);
12670 end if;
12671
12672 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
12673
12674 case Chars (Get_Pragma_Arg (Arg1)) is
12675 when Name_Uppercase =>
12676 Opt.External_Name_Imp_Casing := Uppercase;
12677
12678 when Name_Lowercase =>
12679 Opt.External_Name_Imp_Casing := Lowercase;
12680
12681 when others =>
12682 null;
12683 end case;
12684 end External_Name_Casing;
12685
12686 ---------------
12687 -- Fast_Math --
12688 ---------------
12689
12690 -- pragma Fast_Math;
12691
12692 when Pragma_Fast_Math =>
12693 GNAT_Pragma;
12694 Check_No_Identifiers;
12695 Check_Valid_Configuration_Pragma;
12696 Fast_Math := True;
12697
12698 --------------------------
12699 -- Favor_Top_Level --
12700 --------------------------
12701
12702 -- pragma Favor_Top_Level (type_NAME);
12703
12704 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
12705 Named_Entity : Entity_Id;
12706
12707 begin
12708 GNAT_Pragma;
12709 Check_No_Identifiers;
12710 Check_Arg_Count (1);
12711 Check_Arg_Is_Local_Name (Arg1);
12712 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
12713
12714 -- If it's an access-to-subprogram type (in particular, not a
12715 -- subtype), set the flag on that type.
12716
12717 if Is_Access_Subprogram_Type (Named_Entity) then
12718 Set_Can_Use_Internal_Rep (Named_Entity, False);
12719
12720 -- Otherwise it's an error (name denotes the wrong sort of entity)
12721
12722 else
12723 Error_Pragma_Arg
12724 ("access-to-subprogram type expected",
12725 Get_Pragma_Arg (Arg1));
12726 end if;
12727 end Favor_Top_Level;
12728
12729 ---------------------------
12730 -- Finalize_Storage_Only --
12731 ---------------------------
12732
12733 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
12734
12735 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
12736 Assoc : constant Node_Id := Arg1;
12737 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
12738 Typ : Entity_Id;
12739
12740 begin
12741 GNAT_Pragma;
12742 Check_No_Identifiers;
12743 Check_Arg_Count (1);
12744 Check_Arg_Is_Local_Name (Arg1);
12745
12746 Find_Type (Type_Id);
12747 Typ := Entity (Type_Id);
12748
12749 if Typ = Any_Type
12750 or else Rep_Item_Too_Early (Typ, N)
12751 then
12752 return;
12753 else
12754 Typ := Underlying_Type (Typ);
12755 end if;
12756
12757 if not Is_Controlled (Typ) then
12758 Error_Pragma ("pragma% must specify controlled type");
12759 end if;
12760
12761 Check_First_Subtype (Arg1);
12762
12763 if Finalize_Storage_Only (Typ) then
12764 Error_Pragma ("duplicate pragma%, only one allowed");
12765
12766 elsif not Rep_Item_Too_Late (Typ, N) then
12767 Set_Finalize_Storage_Only (Base_Type (Typ), True);
12768 end if;
12769 end Finalize_Storage;
12770
12771 --------------------------
12772 -- Float_Representation --
12773 --------------------------
12774
12775 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
12776
12777 -- FLOAT_REP ::= VAX_Float | IEEE_Float
12778
12779 when Pragma_Float_Representation => Float_Representation : declare
12780 Argx : Node_Id;
12781 Digs : Nat;
12782 Ent : Entity_Id;
12783
12784 begin
12785 GNAT_Pragma;
12786
12787 if Arg_Count = 1 then
12788 Check_Valid_Configuration_Pragma;
12789 else
12790 Check_Arg_Count (2);
12791 Check_Optional_Identifier (Arg2, Name_Entity);
12792 Check_Arg_Is_Local_Name (Arg2);
12793 end if;
12794
12795 Check_No_Identifier (Arg1);
12796 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
12797
12798 if not OpenVMS_On_Target then
12799 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
12800 Error_Pragma
12801 ("??pragma% ignored (applies only to Open'V'M'S)");
12802 end if;
12803
12804 return;
12805 end if;
12806
12807 -- One argument case
12808
12809 if Arg_Count = 1 then
12810 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
12811 if Opt.Float_Format = 'I' then
12812 Error_Pragma ("'I'E'E'E format previously specified");
12813 end if;
12814
12815 Opt.Float_Format := 'V';
12816
12817 else
12818 if Opt.Float_Format = 'V' then
12819 Error_Pragma ("'V'A'X format previously specified");
12820 end if;
12821
12822 Opt.Float_Format := 'I';
12823 end if;
12824
12825 Set_Standard_Fpt_Formats;
12826
12827 -- Two argument case
12828
12829 else
12830 Argx := Get_Pragma_Arg (Arg2);
12831
12832 if not Is_Entity_Name (Argx)
12833 or else not Is_Floating_Point_Type (Entity (Argx))
12834 then
12835 Error_Pragma_Arg
12836 ("second argument of% pragma must be floating-point type",
12837 Arg2);
12838 end if;
12839
12840 Ent := Entity (Argx);
12841 Digs := UI_To_Int (Digits_Value (Ent));
12842
12843 -- Two arguments, VAX_Float case
12844
12845 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
12846 case Digs is
12847 when 6 => Set_F_Float (Ent);
12848 when 9 => Set_D_Float (Ent);
12849 when 15 => Set_G_Float (Ent);
12850
12851 when others =>
12852 Error_Pragma_Arg
12853 ("wrong digits value, must be 6,9 or 15", Arg2);
12854 end case;
12855
12856 -- Two arguments, IEEE_Float case
12857
12858 else
12859 case Digs is
12860 when 6 => Set_IEEE_Short (Ent);
12861 when 15 => Set_IEEE_Long (Ent);
12862
12863 when others =>
12864 Error_Pragma_Arg
12865 ("wrong digits value, must be 6 or 15", Arg2);
12866 end case;
12867 end if;
12868 end if;
12869 end Float_Representation;
12870
12871 ------------
12872 -- Global --
12873 ------------
12874
12875 -- pragma Global (GLOBAL_SPECIFICATION);
12876
12877 -- GLOBAL_SPECIFICATION ::=
12878 -- null
12879 -- | GLOBAL_LIST
12880 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
12881
12882 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
12883
12884 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
12885 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
12886 -- GLOBAL_ITEM ::= NAME
12887
12888 when Pragma_Global => Global : declare
12889 Subp_Decl : Node_Id;
12890
12891 begin
12892 GNAT_Pragma;
12893 S14_Pragma;
12894 Check_Arg_Count (1);
12895
12896 -- Ensure the proper placement of the pragma. Global must be
12897 -- associated with a subprogram declaration or a body that acts
12898 -- as a spec.
12899
12900 Subp_Decl :=
12901 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12902
12903 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
12904 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
12905 or else not Acts_As_Spec (Subp_Decl))
12906 then
12907 Pragma_Misplaced;
12908 return;
12909 end if;
12910
12911 -- When the pragma appears on a subprogram body, perform the full
12912 -- analysis now.
12913
12914 if Nkind (Subp_Decl) = N_Subprogram_Body then
12915 Analyze_Global_In_Decl_Part (N);
12916
12917 -- When Global applies to a subprogram compilation unit, the
12918 -- corresponding pragma is placed after the unit's declaration
12919 -- node and needs to be analyzed immediately.
12920
12921 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
12922 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
12923 then
12924 Analyze_Global_In_Decl_Part (N);
12925 end if;
12926
12927 -- Chain the pragma on the contract for further processing
12928
12929 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12930 end Global;
12931
12932 -----------
12933 -- Ident --
12934 -----------
12935
12936 -- pragma Ident (static_string_EXPRESSION)
12937
12938 -- Note: pragma Comment shares this processing. Pragma Comment is
12939 -- identical to Ident, except that the restriction of the argument to
12940 -- 31 characters and the placement restrictions are not enforced for
12941 -- pragma Comment.
12942
12943 when Pragma_Ident | Pragma_Comment => Ident : declare
12944 Str : Node_Id;
12945
12946 begin
12947 GNAT_Pragma;
12948 Check_Arg_Count (1);
12949 Check_No_Identifiers;
12950 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12951 Store_Note (N);
12952
12953 -- For pragma Ident, preserve DEC compatibility by requiring the
12954 -- pragma to appear in a declarative part or package spec.
12955
12956 if Prag_Id = Pragma_Ident then
12957 Check_Is_In_Decl_Part_Or_Package_Spec;
12958 end if;
12959
12960 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
12961
12962 declare
12963 CS : Node_Id;
12964 GP : Node_Id;
12965
12966 begin
12967 GP := Parent (Parent (N));
12968
12969 if Nkind_In (GP, N_Package_Declaration,
12970 N_Generic_Package_Declaration)
12971 then
12972 GP := Parent (GP);
12973 end if;
12974
12975 -- If we have a compilation unit, then record the ident value,
12976 -- checking for improper duplication.
12977
12978 if Nkind (GP) = N_Compilation_Unit then
12979 CS := Ident_String (Current_Sem_Unit);
12980
12981 if Present (CS) then
12982
12983 -- For Ident, we do not permit multiple instances
12984
12985 if Prag_Id = Pragma_Ident then
12986 Error_Pragma ("duplicate% pragma not permitted");
12987
12988 -- For Comment, we concatenate the string, unless we want
12989 -- to preserve the tree structure for ASIS.
12990
12991 elsif not ASIS_Mode then
12992 Start_String (Strval (CS));
12993 Store_String_Char (' ');
12994 Store_String_Chars (Strval (Str));
12995 Set_Strval (CS, End_String);
12996 end if;
12997
12998 else
12999 -- In VMS, the effect of IDENT is achieved by passing
13000 -- --identification=name as a --for-linker switch.
13001
13002 if OpenVMS_On_Target then
13003 Start_String;
13004 Store_String_Chars
13005 ("--for-linker=--identification=");
13006 String_To_Name_Buffer (Strval (Str));
13007 Store_String_Chars (Name_Buffer (1 .. Name_Len));
13008
13009 -- Only the last processed IDENT is saved. The main
13010 -- purpose is so an IDENT associated with a main
13011 -- procedure will be used in preference to an IDENT
13012 -- associated with a with'd package.
13013
13014 Replace_Linker_Option_String
13015 (End_String, "--for-linker=--identification=");
13016 end if;
13017
13018 Set_Ident_String (Current_Sem_Unit, Str);
13019 end if;
13020
13021 -- For subunits, we just ignore the Ident, since in GNAT these
13022 -- are not separate object files, and hence not separate units
13023 -- in the unit table.
13024
13025 elsif Nkind (GP) = N_Subunit then
13026 null;
13027
13028 -- Otherwise we have a misplaced pragma Ident, but we ignore
13029 -- this if we are in an instantiation, since it comes from
13030 -- a generic, and has no relevance to the instantiation.
13031
13032 elsif Prag_Id = Pragma_Ident then
13033 if Instantiation_Location (Loc) = No_Location then
13034 Error_Pragma ("pragma% only allowed at outer level");
13035 end if;
13036 end if;
13037 end;
13038 end Ident;
13039
13040 ----------------------------
13041 -- Implementation_Defined --
13042 ----------------------------
13043
13044 -- pragma Implementation_Defined (local_NAME);
13045
13046 -- Marks previously declared entity as implementation defined. For
13047 -- an overloaded entity, applies to the most recent homonym.
13048
13049 -- pragma Implementation_Defined;
13050
13051 -- The form with no arguments appears anywhere within a scope, most
13052 -- typically a package spec, and indicates that all entities that are
13053 -- defined within the package spec are Implementation_Defined.
13054
13055 when Pragma_Implementation_Defined => Implementation_Defined : declare
13056 Ent : Entity_Id;
13057
13058 begin
13059 GNAT_Pragma;
13060 Check_No_Identifiers;
13061
13062 -- Form with no arguments
13063
13064 if Arg_Count = 0 then
13065 Set_Is_Implementation_Defined (Current_Scope);
13066
13067 -- Form with one argument
13068
13069 else
13070 Check_Arg_Count (1);
13071 Check_Arg_Is_Local_Name (Arg1);
13072 Ent := Entity (Get_Pragma_Arg (Arg1));
13073 Set_Is_Implementation_Defined (Ent);
13074 end if;
13075 end Implementation_Defined;
13076
13077 -----------------
13078 -- Implemented --
13079 -----------------
13080
13081 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
13082
13083 -- IMPLEMENTATION_KIND ::=
13084 -- By_Entry | By_Protected_Procedure | By_Any | Optional
13085
13086 -- "By_Any" and "Optional" are treated as synonyms in order to
13087 -- support Ada 2012 aspect Synchronization.
13088
13089 when Pragma_Implemented => Implemented : declare
13090 Proc_Id : Entity_Id;
13091 Typ : Entity_Id;
13092
13093 begin
13094 Ada_2012_Pragma;
13095 Check_Arg_Count (2);
13096 Check_No_Identifiers;
13097 Check_Arg_Is_Identifier (Arg1);
13098 Check_Arg_Is_Local_Name (Arg1);
13099 Check_Arg_Is_One_Of (Arg2,
13100 Name_By_Any,
13101 Name_By_Entry,
13102 Name_By_Protected_Procedure,
13103 Name_Optional);
13104
13105 -- Extract the name of the local procedure
13106
13107 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
13108
13109 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
13110 -- primitive procedure of a synchronized tagged type.
13111
13112 if Ekind (Proc_Id) = E_Procedure
13113 and then Is_Primitive (Proc_Id)
13114 and then Present (First_Formal (Proc_Id))
13115 then
13116 Typ := Etype (First_Formal (Proc_Id));
13117
13118 if Is_Tagged_Type (Typ)
13119 and then
13120
13121 -- Check for a protected, a synchronized or a task interface
13122
13123 ((Is_Interface (Typ)
13124 and then Is_Synchronized_Interface (Typ))
13125
13126 -- Check for a protected type or a task type that implements
13127 -- an interface.
13128
13129 or else
13130 (Is_Concurrent_Record_Type (Typ)
13131 and then Present (Interfaces (Typ)))
13132
13133 -- Check for a private record extension with keyword
13134 -- "synchronized".
13135
13136 or else
13137 (Ekind_In (Typ, E_Record_Type_With_Private,
13138 E_Record_Subtype_With_Private)
13139 and then Synchronized_Present (Parent (Typ))))
13140 then
13141 null;
13142 else
13143 Error_Pragma_Arg
13144 ("controlling formal must be of synchronized tagged type",
13145 Arg1);
13146 return;
13147 end if;
13148
13149 -- Procedures declared inside a protected type must be accepted
13150
13151 elsif Ekind (Proc_Id) = E_Procedure
13152 and then Is_Protected_Type (Scope (Proc_Id))
13153 then
13154 null;
13155
13156 -- The first argument is not a primitive procedure
13157
13158 else
13159 Error_Pragma_Arg
13160 ("pragma % must be applied to a primitive procedure", Arg1);
13161 return;
13162 end if;
13163
13164 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
13165 -- By_Protected_Procedure to the primitive procedure of a task
13166 -- interface.
13167
13168 if Chars (Arg2) = Name_By_Protected_Procedure
13169 and then Is_Interface (Typ)
13170 and then Is_Task_Interface (Typ)
13171 then
13172 Error_Pragma_Arg
13173 ("implementation kind By_Protected_Procedure cannot be "
13174 & "applied to a task interface primitive", Arg2);
13175 return;
13176 end if;
13177
13178 Record_Rep_Item (Proc_Id, N);
13179 end Implemented;
13180
13181 ----------------------
13182 -- Implicit_Packing --
13183 ----------------------
13184
13185 -- pragma Implicit_Packing;
13186
13187 when Pragma_Implicit_Packing =>
13188 GNAT_Pragma;
13189 Check_Arg_Count (0);
13190 Implicit_Packing := True;
13191
13192 ------------
13193 -- Import --
13194 ------------
13195
13196 -- pragma Import (
13197 -- [Convention =>] convention_IDENTIFIER,
13198 -- [Entity =>] local_NAME
13199 -- [, [External_Name =>] static_string_EXPRESSION ]
13200 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13201
13202 when Pragma_Import =>
13203 Check_Ada_83_Warning;
13204 Check_Arg_Order
13205 ((Name_Convention,
13206 Name_Entity,
13207 Name_External_Name,
13208 Name_Link_Name));
13209
13210 Check_At_Least_N_Arguments (2);
13211 Check_At_Most_N_Arguments (4);
13212 Process_Import_Or_Interface;
13213
13214 ----------------------
13215 -- Import_Exception --
13216 ----------------------
13217
13218 -- pragma Import_Exception (
13219 -- [Internal =>] LOCAL_NAME
13220 -- [, [External =>] EXTERNAL_SYMBOL]
13221 -- [, [Form =>] Ada | VMS]
13222 -- [, [Code =>] static_integer_EXPRESSION]);
13223
13224 when Pragma_Import_Exception => Import_Exception : declare
13225 Args : Args_List (1 .. 4);
13226 Names : constant Name_List (1 .. 4) := (
13227 Name_Internal,
13228 Name_External,
13229 Name_Form,
13230 Name_Code);
13231
13232 Internal : Node_Id renames Args (1);
13233 External : Node_Id renames Args (2);
13234 Form : Node_Id renames Args (3);
13235 Code : Node_Id renames Args (4);
13236
13237 begin
13238 GNAT_Pragma;
13239 Gather_Associations (Names, Args);
13240
13241 if Present (External) and then Present (Code) then
13242 Error_Pragma
13243 ("cannot give both External and Code options for pragma%");
13244 end if;
13245
13246 Process_Extended_Import_Export_Exception_Pragma (
13247 Arg_Internal => Internal,
13248 Arg_External => External,
13249 Arg_Form => Form,
13250 Arg_Code => Code);
13251
13252 if not Is_VMS_Exception (Entity (Internal)) then
13253 Set_Imported (Entity (Internal));
13254 end if;
13255 end Import_Exception;
13256
13257 ---------------------
13258 -- Import_Function --
13259 ---------------------
13260
13261 -- pragma Import_Function (
13262 -- [Internal =>] LOCAL_NAME,
13263 -- [, [External =>] EXTERNAL_SYMBOL]
13264 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13265 -- [, [Result_Type =>] SUBTYPE_MARK]
13266 -- [, [Mechanism =>] MECHANISM]
13267 -- [, [Result_Mechanism =>] MECHANISM_NAME]
13268 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
13269
13270 -- EXTERNAL_SYMBOL ::=
13271 -- IDENTIFIER
13272 -- | static_string_EXPRESSION
13273
13274 -- PARAMETER_TYPES ::=
13275 -- null
13276 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13277
13278 -- TYPE_DESIGNATOR ::=
13279 -- subtype_NAME
13280 -- | subtype_Name ' Access
13281
13282 -- MECHANISM ::=
13283 -- MECHANISM_NAME
13284 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13285
13286 -- MECHANISM_ASSOCIATION ::=
13287 -- [formal_parameter_NAME =>] MECHANISM_NAME
13288
13289 -- MECHANISM_NAME ::=
13290 -- Value
13291 -- | Reference
13292 -- | Descriptor [([Class =>] CLASS_NAME)]
13293
13294 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13295
13296 when Pragma_Import_Function => Import_Function : declare
13297 Args : Args_List (1 .. 7);
13298 Names : constant Name_List (1 .. 7) := (
13299 Name_Internal,
13300 Name_External,
13301 Name_Parameter_Types,
13302 Name_Result_Type,
13303 Name_Mechanism,
13304 Name_Result_Mechanism,
13305 Name_First_Optional_Parameter);
13306
13307 Internal : Node_Id renames Args (1);
13308 External : Node_Id renames Args (2);
13309 Parameter_Types : Node_Id renames Args (3);
13310 Result_Type : Node_Id renames Args (4);
13311 Mechanism : Node_Id renames Args (5);
13312 Result_Mechanism : Node_Id renames Args (6);
13313 First_Optional_Parameter : Node_Id renames Args (7);
13314
13315 begin
13316 GNAT_Pragma;
13317 Gather_Associations (Names, Args);
13318 Process_Extended_Import_Export_Subprogram_Pragma (
13319 Arg_Internal => Internal,
13320 Arg_External => External,
13321 Arg_Parameter_Types => Parameter_Types,
13322 Arg_Result_Type => Result_Type,
13323 Arg_Mechanism => Mechanism,
13324 Arg_Result_Mechanism => Result_Mechanism,
13325 Arg_First_Optional_Parameter => First_Optional_Parameter);
13326 end Import_Function;
13327
13328 -------------------
13329 -- Import_Object --
13330 -------------------
13331
13332 -- pragma Import_Object (
13333 -- [Internal =>] LOCAL_NAME
13334 -- [, [External =>] EXTERNAL_SYMBOL]
13335 -- [, [Size =>] EXTERNAL_SYMBOL]);
13336
13337 -- EXTERNAL_SYMBOL ::=
13338 -- IDENTIFIER
13339 -- | static_string_EXPRESSION
13340
13341 when Pragma_Import_Object => Import_Object : declare
13342 Args : Args_List (1 .. 3);
13343 Names : constant Name_List (1 .. 3) := (
13344 Name_Internal,
13345 Name_External,
13346 Name_Size);
13347
13348 Internal : Node_Id renames Args (1);
13349 External : Node_Id renames Args (2);
13350 Size : Node_Id renames Args (3);
13351
13352 begin
13353 GNAT_Pragma;
13354 Gather_Associations (Names, Args);
13355 Process_Extended_Import_Export_Object_Pragma (
13356 Arg_Internal => Internal,
13357 Arg_External => External,
13358 Arg_Size => Size);
13359 end Import_Object;
13360
13361 ----------------------
13362 -- Import_Procedure --
13363 ----------------------
13364
13365 -- pragma Import_Procedure (
13366 -- [Internal =>] LOCAL_NAME
13367 -- [, [External =>] EXTERNAL_SYMBOL]
13368 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13369 -- [, [Mechanism =>] MECHANISM]
13370 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
13371
13372 -- EXTERNAL_SYMBOL ::=
13373 -- IDENTIFIER
13374 -- | static_string_EXPRESSION
13375
13376 -- PARAMETER_TYPES ::=
13377 -- null
13378 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13379
13380 -- TYPE_DESIGNATOR ::=
13381 -- subtype_NAME
13382 -- | subtype_Name ' Access
13383
13384 -- MECHANISM ::=
13385 -- MECHANISM_NAME
13386 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13387
13388 -- MECHANISM_ASSOCIATION ::=
13389 -- [formal_parameter_NAME =>] MECHANISM_NAME
13390
13391 -- MECHANISM_NAME ::=
13392 -- Value
13393 -- | Reference
13394 -- | Descriptor [([Class =>] CLASS_NAME)]
13395
13396 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13397
13398 when Pragma_Import_Procedure => Import_Procedure : declare
13399 Args : Args_List (1 .. 5);
13400 Names : constant Name_List (1 .. 5) := (
13401 Name_Internal,
13402 Name_External,
13403 Name_Parameter_Types,
13404 Name_Mechanism,
13405 Name_First_Optional_Parameter);
13406
13407 Internal : Node_Id renames Args (1);
13408 External : Node_Id renames Args (2);
13409 Parameter_Types : Node_Id renames Args (3);
13410 Mechanism : Node_Id renames Args (4);
13411 First_Optional_Parameter : Node_Id renames Args (5);
13412
13413 begin
13414 GNAT_Pragma;
13415 Gather_Associations (Names, Args);
13416 Process_Extended_Import_Export_Subprogram_Pragma (
13417 Arg_Internal => Internal,
13418 Arg_External => External,
13419 Arg_Parameter_Types => Parameter_Types,
13420 Arg_Mechanism => Mechanism,
13421 Arg_First_Optional_Parameter => First_Optional_Parameter);
13422 end Import_Procedure;
13423
13424 -----------------------------
13425 -- Import_Valued_Procedure --
13426 -----------------------------
13427
13428 -- pragma Import_Valued_Procedure (
13429 -- [Internal =>] LOCAL_NAME
13430 -- [, [External =>] EXTERNAL_SYMBOL]
13431 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13432 -- [, [Mechanism =>] MECHANISM]
13433 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
13434
13435 -- EXTERNAL_SYMBOL ::=
13436 -- IDENTIFIER
13437 -- | static_string_EXPRESSION
13438
13439 -- PARAMETER_TYPES ::=
13440 -- null
13441 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13442
13443 -- TYPE_DESIGNATOR ::=
13444 -- subtype_NAME
13445 -- | subtype_Name ' Access
13446
13447 -- MECHANISM ::=
13448 -- MECHANISM_NAME
13449 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13450
13451 -- MECHANISM_ASSOCIATION ::=
13452 -- [formal_parameter_NAME =>] MECHANISM_NAME
13453
13454 -- MECHANISM_NAME ::=
13455 -- Value
13456 -- | Reference
13457 -- | Descriptor [([Class =>] CLASS_NAME)]
13458
13459 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13460
13461 when Pragma_Import_Valued_Procedure =>
13462 Import_Valued_Procedure : declare
13463 Args : Args_List (1 .. 5);
13464 Names : constant Name_List (1 .. 5) := (
13465 Name_Internal,
13466 Name_External,
13467 Name_Parameter_Types,
13468 Name_Mechanism,
13469 Name_First_Optional_Parameter);
13470
13471 Internal : Node_Id renames Args (1);
13472 External : Node_Id renames Args (2);
13473 Parameter_Types : Node_Id renames Args (3);
13474 Mechanism : Node_Id renames Args (4);
13475 First_Optional_Parameter : Node_Id renames Args (5);
13476
13477 begin
13478 GNAT_Pragma;
13479 Gather_Associations (Names, Args);
13480 Process_Extended_Import_Export_Subprogram_Pragma (
13481 Arg_Internal => Internal,
13482 Arg_External => External,
13483 Arg_Parameter_Types => Parameter_Types,
13484 Arg_Mechanism => Mechanism,
13485 Arg_First_Optional_Parameter => First_Optional_Parameter);
13486 end Import_Valued_Procedure;
13487
13488 -----------------
13489 -- Independent --
13490 -----------------
13491
13492 -- pragma Independent (LOCAL_NAME);
13493
13494 when Pragma_Independent => Independent : declare
13495 E_Id : Node_Id;
13496 E : Entity_Id;
13497 D : Node_Id;
13498 K : Node_Kind;
13499
13500 begin
13501 Check_Ada_83_Warning;
13502 Ada_2012_Pragma;
13503 Check_No_Identifiers;
13504 Check_Arg_Count (1);
13505 Check_Arg_Is_Local_Name (Arg1);
13506 E_Id := Get_Pragma_Arg (Arg1);
13507
13508 if Etype (E_Id) = Any_Type then
13509 return;
13510 end if;
13511
13512 E := Entity (E_Id);
13513 D := Declaration_Node (E);
13514 K := Nkind (D);
13515
13516 -- Check duplicate before we chain ourselves!
13517
13518 Check_Duplicate_Pragma (E);
13519
13520 -- Check appropriate entity
13521
13522 if Is_Type (E) then
13523 if Rep_Item_Too_Early (E, N)
13524 or else
13525 Rep_Item_Too_Late (E, N)
13526 then
13527 return;
13528 else
13529 Check_First_Subtype (Arg1);
13530 end if;
13531
13532 elsif K = N_Object_Declaration
13533 or else (K = N_Component_Declaration
13534 and then Original_Record_Component (E) = E)
13535 then
13536 if Rep_Item_Too_Late (E, N) then
13537 return;
13538 end if;
13539
13540 else
13541 Error_Pragma_Arg
13542 ("inappropriate entity for pragma%", Arg1);
13543 end if;
13544
13545 Independence_Checks.Append ((N, E));
13546 end Independent;
13547
13548 ----------------------------
13549 -- Independent_Components --
13550 ----------------------------
13551
13552 -- pragma Atomic_Components (array_LOCAL_NAME);
13553
13554 -- This processing is shared by Volatile_Components
13555
13556 when Pragma_Independent_Components => Independent_Components : declare
13557 E_Id : Node_Id;
13558 E : Entity_Id;
13559 D : Node_Id;
13560 K : Node_Kind;
13561
13562 begin
13563 Check_Ada_83_Warning;
13564 Ada_2012_Pragma;
13565 Check_No_Identifiers;
13566 Check_Arg_Count (1);
13567 Check_Arg_Is_Local_Name (Arg1);
13568 E_Id := Get_Pragma_Arg (Arg1);
13569
13570 if Etype (E_Id) = Any_Type then
13571 return;
13572 end if;
13573
13574 E := Entity (E_Id);
13575
13576 -- Check duplicate before we chain ourselves!
13577
13578 Check_Duplicate_Pragma (E);
13579
13580 -- Check appropriate entity
13581
13582 if Rep_Item_Too_Early (E, N)
13583 or else
13584 Rep_Item_Too_Late (E, N)
13585 then
13586 return;
13587 end if;
13588
13589 D := Declaration_Node (E);
13590 K := Nkind (D);
13591
13592 if K = N_Full_Type_Declaration
13593 and then (Is_Array_Type (E) or else Is_Record_Type (E))
13594 then
13595 Independence_Checks.Append ((N, E));
13596 Set_Has_Independent_Components (Base_Type (E));
13597
13598 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
13599 and then Nkind (D) = N_Object_Declaration
13600 and then Nkind (Object_Definition (D)) =
13601 N_Constrained_Array_Definition
13602 then
13603 Independence_Checks.Append ((N, E));
13604 Set_Has_Independent_Components (E);
13605
13606 else
13607 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13608 end if;
13609 end Independent_Components;
13610
13611 -----------------------
13612 -- Initial_Condition --
13613 -----------------------
13614
13615 -- pragma Initial_Condition (boolean_EXPRESSION);
13616
13617 when Pragma_Initial_Condition => Initial_Condition : declare
13618 Context : constant Node_Id := Parent (Parent (N));
13619 Pack_Id : Entity_Id;
13620 Stmt : Node_Id;
13621
13622 begin
13623 GNAT_Pragma;
13624 S14_Pragma;
13625 Check_Arg_Count (1);
13626
13627 -- Ensure the proper placement of the pragma. Initial_Condition
13628 -- must be associated with a package declaration.
13629
13630 if not Nkind_In (Context, N_Generic_Package_Declaration,
13631 N_Package_Declaration)
13632 then
13633 Pragma_Misplaced;
13634 return;
13635 end if;
13636
13637 Stmt := Prev (N);
13638 while Present (Stmt) loop
13639
13640 -- Skip prior pragmas, but check for duplicates
13641
13642 if Nkind (Stmt) = N_Pragma then
13643 if Pragma_Name (Stmt) = Pname then
13644 Error_Msg_Name_1 := Pname;
13645 Error_Msg_Sloc := Sloc (Stmt);
13646 Error_Msg_N ("pragma % duplicates pragma declared #", N);
13647 end if;
13648
13649 -- Skip internally generated code
13650
13651 elsif not Comes_From_Source (Stmt) then
13652 null;
13653
13654 -- The pragma does not apply to a legal construct, issue an
13655 -- error and stop the analysis.
13656
13657 else
13658 Pragma_Misplaced;
13659 return;
13660 end if;
13661
13662 Stmt := Prev (Stmt);
13663 end loop;
13664
13665 -- The pragma must be analyzed at the end of the visible
13666 -- declarations of the related package. Save the pragma for later
13667 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
13668 -- the contract of the package.
13669
13670 Pack_Id := Defining_Entity (Context);
13671 Add_Contract_Item (N, Pack_Id);
13672
13673 -- Verify the declaration order of pragma Initial_Condition with
13674 -- respect to pragmas Abstract_State and Initializes.
13675
13676 Check_Declaration_Order
13677 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
13678 Second => N);
13679
13680 Check_Declaration_Order
13681 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
13682 Second => N);
13683 end Initial_Condition;
13684
13685 ------------------------
13686 -- Initialize_Scalars --
13687 ------------------------
13688
13689 -- pragma Initialize_Scalars;
13690
13691 when Pragma_Initialize_Scalars =>
13692 GNAT_Pragma;
13693 Check_Arg_Count (0);
13694 Check_Valid_Configuration_Pragma;
13695 Check_Restriction (No_Initialize_Scalars, N);
13696
13697 -- Initialize_Scalars creates false positives in CodePeer, and
13698 -- incorrect negative results in SPARK mode, so ignore this pragma
13699 -- in these modes.
13700
13701 if not Restriction_Active (No_Initialize_Scalars)
13702 and then not (CodePeer_Mode or SPARK_Mode)
13703 then
13704 Init_Or_Norm_Scalars := True;
13705 Initialize_Scalars := True;
13706 end if;
13707
13708 -----------------
13709 -- Initializes --
13710 -----------------
13711
13712 -- pragma Initializes (INITIALIZATION_SPEC);
13713
13714 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
13715
13716 -- INITIALIZATION_LIST ::=
13717 -- INITIALIZATION_ITEM
13718 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
13719
13720 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
13721
13722 -- INPUT_LIST ::=
13723 -- null
13724 -- | INPUT
13725 -- | (INPUT {, INPUT})
13726
13727 -- INPUT ::= name
13728
13729 when Pragma_Initializes => Initializes : declare
13730 Context : constant Node_Id := Parent (Parent (N));
13731 Pack_Id : Entity_Id;
13732 Stmt : Node_Id;
13733
13734 begin
13735 GNAT_Pragma;
13736 S14_Pragma;
13737 Check_Arg_Count (1);
13738
13739 -- Ensure the proper placement of the pragma. Initializes must be
13740 -- associated with a package declaration.
13741
13742 if not Nkind_In (Context, N_Generic_Package_Declaration,
13743 N_Package_Declaration)
13744 then
13745 Pragma_Misplaced;
13746 return;
13747 end if;
13748
13749 Stmt := Prev (N);
13750 while Present (Stmt) loop
13751
13752 -- Skip prior pragmas, but check for duplicates
13753
13754 if Nkind (Stmt) = N_Pragma then
13755 if Pragma_Name (Stmt) = Pname then
13756 Error_Msg_Name_1 := Pname;
13757 Error_Msg_Sloc := Sloc (Stmt);
13758 Error_Msg_N ("pragma % duplicates pragma declared #", N);
13759 end if;
13760
13761 -- Skip internally generated code
13762
13763 elsif not Comes_From_Source (Stmt) then
13764 null;
13765
13766 -- The pragma does not apply to a legal construct, issue an
13767 -- error and stop the analysis.
13768
13769 else
13770 Pragma_Misplaced;
13771 return;
13772 end if;
13773
13774 Stmt := Prev (Stmt);
13775 end loop;
13776
13777 -- The pragma must be analyzed at the end of the visible
13778 -- declarations of the related package. Save the pragma for later
13779 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
13780 -- contract of the package.
13781
13782 Pack_Id := Defining_Entity (Context);
13783 Add_Contract_Item (N, Pack_Id);
13784
13785 -- Verify the declaration order of pragmas Abstract_State and
13786 -- Initializes.
13787
13788 Check_Declaration_Order
13789 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
13790 Second => N);
13791 end Initializes;
13792
13793 ------------
13794 -- Inline --
13795 ------------
13796
13797 -- pragma Inline ( NAME {, NAME} );
13798
13799 when Pragma_Inline =>
13800
13801 -- Inline status is Enabled if inlining option is active
13802
13803 if Inline_Active then
13804 Process_Inline (Enabled);
13805 else
13806 Process_Inline (Disabled);
13807 end if;
13808
13809 -------------------
13810 -- Inline_Always --
13811 -------------------
13812
13813 -- pragma Inline_Always ( NAME {, NAME} );
13814
13815 when Pragma_Inline_Always =>
13816 GNAT_Pragma;
13817
13818 -- Pragma always active unless in CodePeer or SPARK mode, since
13819 -- this causes walk order issues.
13820
13821 if not (CodePeer_Mode or SPARK_Mode) then
13822 Process_Inline (Enabled);
13823 end if;
13824
13825 --------------------
13826 -- Inline_Generic --
13827 --------------------
13828
13829 -- pragma Inline_Generic (NAME {, NAME});
13830
13831 when Pragma_Inline_Generic =>
13832 GNAT_Pragma;
13833 Process_Generic_List;
13834
13835 ----------------------
13836 -- Inspection_Point --
13837 ----------------------
13838
13839 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
13840
13841 when Pragma_Inspection_Point => Inspection_Point : declare
13842 Arg : Node_Id;
13843 Exp : Node_Id;
13844
13845 begin
13846 if Arg_Count > 0 then
13847 Arg := Arg1;
13848 loop
13849 Exp := Get_Pragma_Arg (Arg);
13850 Analyze (Exp);
13851
13852 if not Is_Entity_Name (Exp)
13853 or else not Is_Object (Entity (Exp))
13854 then
13855 Error_Pragma_Arg ("object name required", Arg);
13856 end if;
13857
13858 Next (Arg);
13859 exit when No (Arg);
13860 end loop;
13861 end if;
13862 end Inspection_Point;
13863
13864 ---------------
13865 -- Interface --
13866 ---------------
13867
13868 -- pragma Interface (
13869 -- [ Convention =>] convention_IDENTIFIER,
13870 -- [ Entity =>] local_NAME
13871 -- [, [External_Name =>] static_string_EXPRESSION ]
13872 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13873
13874 when Pragma_Interface =>
13875 GNAT_Pragma;
13876 Check_Arg_Order
13877 ((Name_Convention,
13878 Name_Entity,
13879 Name_External_Name,
13880 Name_Link_Name));
13881 Check_At_Least_N_Arguments (2);
13882 Check_At_Most_N_Arguments (4);
13883 Process_Import_Or_Interface;
13884
13885 -- In Ada 2005, the permission to use Interface (a reserved word)
13886 -- as a pragma name is considered an obsolescent feature, and this
13887 -- pragma was already obsolescent in Ada 95.
13888
13889 if Ada_Version >= Ada_95 then
13890 Check_Restriction
13891 (No_Obsolescent_Features, Pragma_Identifier (N));
13892
13893 if Warn_On_Obsolescent_Feature then
13894 Error_Msg_N
13895 ("pragma Interface is an obsolescent feature?j?", N);
13896 Error_Msg_N
13897 ("|use pragma Import instead?j?", N);
13898 end if;
13899 end if;
13900
13901 --------------------
13902 -- Interface_Name --
13903 --------------------
13904
13905 -- pragma Interface_Name (
13906 -- [ Entity =>] local_NAME
13907 -- [,[External_Name =>] static_string_EXPRESSION ]
13908 -- [,[Link_Name =>] static_string_EXPRESSION ]);
13909
13910 when Pragma_Interface_Name => Interface_Name : declare
13911 Id : Node_Id;
13912 Def_Id : Entity_Id;
13913 Hom_Id : Entity_Id;
13914 Found : Boolean;
13915
13916 begin
13917 GNAT_Pragma;
13918 Check_Arg_Order
13919 ((Name_Entity, Name_External_Name, Name_Link_Name));
13920 Check_At_Least_N_Arguments (2);
13921 Check_At_Most_N_Arguments (3);
13922 Id := Get_Pragma_Arg (Arg1);
13923 Analyze (Id);
13924
13925 -- This is obsolete from Ada 95 on, but it is an implementation
13926 -- defined pragma, so we do not consider that it violates the
13927 -- restriction (No_Obsolescent_Features).
13928
13929 if Ada_Version >= Ada_95 then
13930 if Warn_On_Obsolescent_Feature then
13931 Error_Msg_N
13932 ("pragma Interface_Name is an obsolescent feature?j?", N);
13933 Error_Msg_N
13934 ("|use pragma Import instead?j?", N);
13935 end if;
13936 end if;
13937
13938 if not Is_Entity_Name (Id) then
13939 Error_Pragma_Arg
13940 ("first argument for pragma% must be entity name", Arg1);
13941 elsif Etype (Id) = Any_Type then
13942 return;
13943 else
13944 Def_Id := Entity (Id);
13945 end if;
13946
13947 -- Special DEC-compatible processing for the object case, forces
13948 -- object to be imported.
13949
13950 if Ekind (Def_Id) = E_Variable then
13951 Kill_Size_Check_Code (Def_Id);
13952 Note_Possible_Modification (Id, Sure => False);
13953
13954 -- Initialization is not allowed for imported variable
13955
13956 if Present (Expression (Parent (Def_Id)))
13957 and then Comes_From_Source (Expression (Parent (Def_Id)))
13958 then
13959 Error_Msg_Sloc := Sloc (Def_Id);
13960 Error_Pragma_Arg
13961 ("no initialization allowed for declaration of& #",
13962 Arg2);
13963
13964 else
13965 -- For compatibility, support VADS usage of providing both
13966 -- pragmas Interface and Interface_Name to obtain the effect
13967 -- of a single Import pragma.
13968
13969 if Is_Imported (Def_Id)
13970 and then Present (First_Rep_Item (Def_Id))
13971 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
13972 and then
13973 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
13974 then
13975 null;
13976 else
13977 Set_Imported (Def_Id);
13978 end if;
13979
13980 Set_Is_Public (Def_Id);
13981 Process_Interface_Name (Def_Id, Arg2, Arg3);
13982 end if;
13983
13984 -- Otherwise must be subprogram
13985
13986 elsif not Is_Subprogram (Def_Id) then
13987 Error_Pragma_Arg
13988 ("argument of pragma% is not subprogram", Arg1);
13989
13990 else
13991 Check_At_Most_N_Arguments (3);
13992 Hom_Id := Def_Id;
13993 Found := False;
13994
13995 -- Loop through homonyms
13996
13997 loop
13998 Def_Id := Get_Base_Subprogram (Hom_Id);
13999
14000 if Is_Imported (Def_Id) then
14001 Process_Interface_Name (Def_Id, Arg2, Arg3);
14002 Found := True;
14003 end if;
14004
14005 exit when From_Aspect_Specification (N);
14006 Hom_Id := Homonym (Hom_Id);
14007
14008 exit when No (Hom_Id)
14009 or else Scope (Hom_Id) /= Current_Scope;
14010 end loop;
14011
14012 if not Found then
14013 Error_Pragma_Arg
14014 ("argument of pragma% is not imported subprogram",
14015 Arg1);
14016 end if;
14017 end if;
14018 end Interface_Name;
14019
14020 -----------------------
14021 -- Interrupt_Handler --
14022 -----------------------
14023
14024 -- pragma Interrupt_Handler (handler_NAME);
14025
14026 when Pragma_Interrupt_Handler =>
14027 Check_Ada_83_Warning;
14028 Check_Arg_Count (1);
14029 Check_No_Identifiers;
14030
14031 if No_Run_Time_Mode then
14032 Error_Msg_CRT ("Interrupt_Handler pragma", N);
14033 else
14034 Check_Interrupt_Or_Attach_Handler;
14035 Process_Interrupt_Or_Attach_Handler;
14036 end if;
14037
14038 ------------------------
14039 -- Interrupt_Priority --
14040 ------------------------
14041
14042 -- pragma Interrupt_Priority [(EXPRESSION)];
14043
14044 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
14045 P : constant Node_Id := Parent (N);
14046 Arg : Node_Id;
14047 Ent : Entity_Id;
14048
14049 begin
14050 Check_Ada_83_Warning;
14051
14052 if Arg_Count /= 0 then
14053 Arg := Get_Pragma_Arg (Arg1);
14054 Check_Arg_Count (1);
14055 Check_No_Identifiers;
14056
14057 -- The expression must be analyzed in the special manner
14058 -- described in "Handling of Default and Per-Object
14059 -- Expressions" in sem.ads.
14060
14061 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
14062 end if;
14063
14064 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
14065 Pragma_Misplaced;
14066 return;
14067
14068 else
14069 Ent := Defining_Identifier (Parent (P));
14070
14071 -- Check duplicate pragma before we chain the pragma in the Rep
14072 -- Item chain of Ent.
14073
14074 Check_Duplicate_Pragma (Ent);
14075 Record_Rep_Item (Ent, N);
14076 end if;
14077 end Interrupt_Priority;
14078
14079 ---------------------
14080 -- Interrupt_State --
14081 ---------------------
14082
14083 -- pragma Interrupt_State (
14084 -- [Name =>] INTERRUPT_ID,
14085 -- [State =>] INTERRUPT_STATE);
14086
14087 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
14088 -- INTERRUPT_STATE => System | Runtime | User
14089
14090 -- Note: if the interrupt id is given as an identifier, then it must
14091 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
14092 -- given as a static integer expression which must be in the range of
14093 -- Ada.Interrupts.Interrupt_ID.
14094
14095 when Pragma_Interrupt_State => Interrupt_State : declare
14096
14097 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
14098 -- This is the entity Ada.Interrupts.Interrupt_ID;
14099
14100 State_Type : Character;
14101 -- Set to 's'/'r'/'u' for System/Runtime/User
14102
14103 IST_Num : Pos;
14104 -- Index to entry in Interrupt_States table
14105
14106 Int_Val : Uint;
14107 -- Value of interrupt
14108
14109 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
14110 -- The first argument to the pragma
14111
14112 Int_Ent : Entity_Id;
14113 -- Interrupt entity in Ada.Interrupts.Names
14114
14115 begin
14116 GNAT_Pragma;
14117 Check_Arg_Order ((Name_Name, Name_State));
14118 Check_Arg_Count (2);
14119
14120 Check_Optional_Identifier (Arg1, Name_Name);
14121 Check_Optional_Identifier (Arg2, Name_State);
14122 Check_Arg_Is_Identifier (Arg2);
14123
14124 -- First argument is identifier
14125
14126 if Nkind (Arg1X) = N_Identifier then
14127
14128 -- Search list of names in Ada.Interrupts.Names
14129
14130 Int_Ent := First_Entity (RTE (RE_Names));
14131 loop
14132 if No (Int_Ent) then
14133 Error_Pragma_Arg ("invalid interrupt name", Arg1);
14134
14135 elsif Chars (Int_Ent) = Chars (Arg1X) then
14136 Int_Val := Expr_Value (Constant_Value (Int_Ent));
14137 exit;
14138 end if;
14139
14140 Next_Entity (Int_Ent);
14141 end loop;
14142
14143 -- First argument is not an identifier, so it must be a static
14144 -- expression of type Ada.Interrupts.Interrupt_ID.
14145
14146 else
14147 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
14148 Int_Val := Expr_Value (Arg1X);
14149
14150 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
14151 or else
14152 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
14153 then
14154 Error_Pragma_Arg
14155 ("value not in range of type "
14156 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
14157 end if;
14158 end if;
14159
14160 -- Check OK state
14161
14162 case Chars (Get_Pragma_Arg (Arg2)) is
14163 when Name_Runtime => State_Type := 'r';
14164 when Name_System => State_Type := 's';
14165 when Name_User => State_Type := 'u';
14166
14167 when others =>
14168 Error_Pragma_Arg ("invalid interrupt state", Arg2);
14169 end case;
14170
14171 -- Check if entry is already stored
14172
14173 IST_Num := Interrupt_States.First;
14174 loop
14175 -- If entry not found, add it
14176
14177 if IST_Num > Interrupt_States.Last then
14178 Interrupt_States.Append
14179 ((Interrupt_Number => UI_To_Int (Int_Val),
14180 Interrupt_State => State_Type,
14181 Pragma_Loc => Loc));
14182 exit;
14183
14184 -- Case of entry for the same entry
14185
14186 elsif Int_Val = Interrupt_States.Table (IST_Num).
14187 Interrupt_Number
14188 then
14189 -- If state matches, done, no need to make redundant entry
14190
14191 exit when
14192 State_Type = Interrupt_States.Table (IST_Num).
14193 Interrupt_State;
14194
14195 -- Otherwise if state does not match, error
14196
14197 Error_Msg_Sloc :=
14198 Interrupt_States.Table (IST_Num).Pragma_Loc;
14199 Error_Pragma_Arg
14200 ("state conflicts with that given #", Arg2);
14201 exit;
14202 end if;
14203
14204 IST_Num := IST_Num + 1;
14205 end loop;
14206 end Interrupt_State;
14207
14208 ---------------
14209 -- Invariant --
14210 ---------------
14211
14212 -- pragma Invariant
14213 -- ([Entity =>] type_LOCAL_NAME,
14214 -- [Check =>] EXPRESSION
14215 -- [,[Message =>] String_Expression]);
14216
14217 when Pragma_Invariant => Invariant : declare
14218 Type_Id : Node_Id;
14219 Typ : Entity_Id;
14220 PDecl : Node_Id;
14221
14222 Discard : Boolean;
14223 pragma Unreferenced (Discard);
14224
14225 begin
14226 GNAT_Pragma;
14227 Check_At_Least_N_Arguments (2);
14228 Check_At_Most_N_Arguments (3);
14229 Check_Optional_Identifier (Arg1, Name_Entity);
14230 Check_Optional_Identifier (Arg2, Name_Check);
14231
14232 if Arg_Count = 3 then
14233 Check_Optional_Identifier (Arg3, Name_Message);
14234 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
14235 end if;
14236
14237 Check_Arg_Is_Local_Name (Arg1);
14238
14239 Type_Id := Get_Pragma_Arg (Arg1);
14240 Find_Type (Type_Id);
14241 Typ := Entity (Type_Id);
14242
14243 if Typ = Any_Type then
14244 return;
14245
14246 -- An invariant must apply to a private type, or appear in the
14247 -- private part of a package spec and apply to a completion.
14248
14249 elsif Ekind_In (Typ, E_Private_Type,
14250 E_Record_Type_With_Private,
14251 E_Limited_Private_Type)
14252 then
14253 null;
14254
14255 elsif In_Private_Part (Current_Scope)
14256 and then Has_Private_Declaration (Typ)
14257 then
14258 null;
14259
14260 elsif In_Private_Part (Current_Scope) then
14261 Error_Pragma_Arg
14262 ("pragma% only allowed for private type declared in "
14263 & "visible part", Arg1);
14264
14265 else
14266 Error_Pragma_Arg
14267 ("pragma% only allowed for private type", Arg1);
14268 end if;
14269
14270 -- Note that the type has at least one invariant, and also that
14271 -- it has inheritable invariants if we have Invariant'Class
14272 -- or Type_Invariant'Class. Build the corresponding invariant
14273 -- procedure declaration, so that calls to it can be generated
14274 -- before the body is built (e.g. within an expression function).
14275
14276 PDecl := Build_Invariant_Procedure_Declaration (Typ);
14277
14278 Insert_After (N, PDecl);
14279 Analyze (PDecl);
14280
14281 if Class_Present (N) then
14282 Set_Has_Inheritable_Invariants (Typ);
14283 end if;
14284
14285 -- The remaining processing is simply to link the pragma on to
14286 -- the rep item chain, for processing when the type is frozen.
14287 -- This is accomplished by a call to Rep_Item_Too_Late.
14288
14289 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
14290 end Invariant;
14291
14292 ----------------------
14293 -- Java_Constructor --
14294 ----------------------
14295
14296 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
14297
14298 -- Also handles pragma CIL_Constructor
14299
14300 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
14301 Java_Constructor : declare
14302 Convention : Convention_Id;
14303 Def_Id : Entity_Id;
14304 Hom_Id : Entity_Id;
14305 Id : Entity_Id;
14306 This_Formal : Entity_Id;
14307
14308 begin
14309 GNAT_Pragma;
14310 Check_Arg_Count (1);
14311 Check_Optional_Identifier (Arg1, Name_Entity);
14312 Check_Arg_Is_Local_Name (Arg1);
14313
14314 Id := Get_Pragma_Arg (Arg1);
14315 Find_Program_Unit_Name (Id);
14316
14317 -- If we did not find the name, we are done
14318
14319 if Etype (Id) = Any_Type then
14320 return;
14321 end if;
14322
14323 -- Check wrong use of pragma in wrong VM target
14324
14325 if VM_Target = No_VM then
14326 return;
14327
14328 elsif VM_Target = CLI_Target
14329 and then Prag_Id = Pragma_Java_Constructor
14330 then
14331 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
14332
14333 elsif VM_Target = JVM_Target
14334 and then Prag_Id = Pragma_CIL_Constructor
14335 then
14336 Error_Pragma ("must use pragma 'Java_'Constructor");
14337 end if;
14338
14339 case Prag_Id is
14340 when Pragma_CIL_Constructor => Convention := Convention_CIL;
14341 when Pragma_Java_Constructor => Convention := Convention_Java;
14342 when others => null;
14343 end case;
14344
14345 Hom_Id := Entity (Id);
14346
14347 -- Loop through homonyms
14348
14349 loop
14350 Def_Id := Get_Base_Subprogram (Hom_Id);
14351
14352 -- The constructor is required to be a function
14353
14354 if Ekind (Def_Id) /= E_Function then
14355 if VM_Target = JVM_Target then
14356 Error_Pragma_Arg
14357 ("pragma% requires function returning a 'Java access "
14358 & "type", Def_Id);
14359 else
14360 Error_Pragma_Arg
14361 ("pragma% requires function returning a 'C'I'L access "
14362 & "type", Def_Id);
14363 end if;
14364 end if;
14365
14366 -- Check arguments: For tagged type the first formal must be
14367 -- named "this" and its type must be a named access type
14368 -- designating a class-wide tagged type that has convention
14369 -- CIL/Java. The first formal must also have a null default
14370 -- value. For example:
14371
14372 -- type Typ is tagged ...
14373 -- type Ref is access all Typ;
14374 -- pragma Convention (CIL, Typ);
14375
14376 -- function New_Typ (This : Ref) return Ref;
14377 -- function New_Typ (This : Ref; I : Integer) return Ref;
14378 -- pragma Cil_Constructor (New_Typ);
14379
14380 -- Reason: The first formal must NOT be a primitive of the
14381 -- tagged type.
14382
14383 -- This rule also applies to constructors of delegates used
14384 -- to interface with standard target libraries. For example:
14385
14386 -- type Delegate is access procedure ...
14387 -- pragma Import (CIL, Delegate, ...);
14388
14389 -- function new_Delegate
14390 -- (This : Delegate := null; ... ) return Delegate;
14391
14392 -- For value-types this rule does not apply.
14393
14394 if not Is_Value_Type (Etype (Def_Id)) then
14395 if No (First_Formal (Def_Id)) then
14396 Error_Msg_Name_1 := Pname;
14397 Error_Msg_N ("% function must have parameters", Def_Id);
14398 return;
14399 end if;
14400
14401 -- In the JRE library we have several occurrences in which
14402 -- the "this" parameter is not the first formal.
14403
14404 This_Formal := First_Formal (Def_Id);
14405
14406 -- In the JRE library we have several occurrences in which
14407 -- the "this" parameter is not the first formal. Search for
14408 -- it.
14409
14410 if VM_Target = JVM_Target then
14411 while Present (This_Formal)
14412 and then Get_Name_String (Chars (This_Formal)) /= "this"
14413 loop
14414 Next_Formal (This_Formal);
14415 end loop;
14416
14417 if No (This_Formal) then
14418 This_Formal := First_Formal (Def_Id);
14419 end if;
14420 end if;
14421
14422 -- Warning: The first parameter should be named "this".
14423 -- We temporarily allow it because we have the following
14424 -- case in the Java runtime (file s-osinte.ads) ???
14425
14426 -- function new_Thread
14427 -- (Self_Id : System.Address) return Thread_Id;
14428 -- pragma Java_Constructor (new_Thread);
14429
14430 if VM_Target = JVM_Target
14431 and then Get_Name_String (Chars (First_Formal (Def_Id)))
14432 = "self_id"
14433 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
14434 then
14435 null;
14436
14437 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
14438 Error_Msg_Name_1 := Pname;
14439 Error_Msg_N
14440 ("first formal of % function must be named `this`",
14441 Parent (This_Formal));
14442
14443 elsif not Is_Access_Type (Etype (This_Formal)) then
14444 Error_Msg_Name_1 := Pname;
14445 Error_Msg_N
14446 ("first formal of % function must be an access type",
14447 Parameter_Type (Parent (This_Formal)));
14448
14449 -- For delegates the type of the first formal must be a
14450 -- named access-to-subprogram type (see previous example)
14451
14452 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
14453 and then Ekind (Etype (This_Formal))
14454 /= E_Access_Subprogram_Type
14455 then
14456 Error_Msg_Name_1 := Pname;
14457 Error_Msg_N
14458 ("first formal of % function must be a named access "
14459 & "to subprogram type",
14460 Parameter_Type (Parent (This_Formal)));
14461
14462 -- Warning: We should reject anonymous access types because
14463 -- the constructor must not be handled as a primitive of the
14464 -- tagged type. We temporarily allow it because this profile
14465 -- is currently generated by cil2ada???
14466
14467 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
14468 and then not Ekind_In (Etype (This_Formal),
14469 E_Access_Type,
14470 E_General_Access_Type,
14471 E_Anonymous_Access_Type)
14472 then
14473 Error_Msg_Name_1 := Pname;
14474 Error_Msg_N
14475 ("first formal of % function must be a named access "
14476 & "type", Parameter_Type (Parent (This_Formal)));
14477
14478 elsif Atree.Convention
14479 (Designated_Type (Etype (This_Formal))) /= Convention
14480 then
14481 Error_Msg_Name_1 := Pname;
14482
14483 if Convention = Convention_Java then
14484 Error_Msg_N
14485 ("pragma% requires convention 'Cil in designated "
14486 & "type", Parameter_Type (Parent (This_Formal)));
14487 else
14488 Error_Msg_N
14489 ("pragma% requires convention 'Java in designated "
14490 & "type", Parameter_Type (Parent (This_Formal)));
14491 end if;
14492
14493 elsif No (Expression (Parent (This_Formal)))
14494 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
14495 then
14496 Error_Msg_Name_1 := Pname;
14497 Error_Msg_N
14498 ("pragma% requires first formal with default `null`",
14499 Parameter_Type (Parent (This_Formal)));
14500 end if;
14501 end if;
14502
14503 -- Check result type: the constructor must be a function
14504 -- returning:
14505 -- * a value type (only allowed in the CIL compiler)
14506 -- * an access-to-subprogram type with convention Java/CIL
14507 -- * an access-type designating a type that has convention
14508 -- Java/CIL.
14509
14510 if Is_Value_Type (Etype (Def_Id)) then
14511 null;
14512
14513 -- Access-to-subprogram type with convention Java/CIL
14514
14515 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
14516 if Atree.Convention (Etype (Def_Id)) /= Convention then
14517 if Convention = Convention_Java then
14518 Error_Pragma_Arg
14519 ("pragma% requires function returning a 'Java "
14520 & "access type", Arg1);
14521 else
14522 pragma Assert (Convention = Convention_CIL);
14523 Error_Pragma_Arg
14524 ("pragma% requires function returning a 'C'I'L "
14525 & "access type", Arg1);
14526 end if;
14527 end if;
14528
14529 elsif Ekind (Etype (Def_Id)) in Access_Kind then
14530 if not Ekind_In (Etype (Def_Id), E_Access_Type,
14531 E_General_Access_Type)
14532 or else
14533 Atree.Convention
14534 (Designated_Type (Etype (Def_Id))) /= Convention
14535 then
14536 Error_Msg_Name_1 := Pname;
14537
14538 if Convention = Convention_Java then
14539 Error_Pragma_Arg
14540 ("pragma% requires function returning a named "
14541 & "'Java access type", Arg1);
14542 else
14543 Error_Pragma_Arg
14544 ("pragma% requires function returning a named "
14545 & "'C'I'L access type", Arg1);
14546 end if;
14547 end if;
14548 end if;
14549
14550 Set_Is_Constructor (Def_Id);
14551 Set_Convention (Def_Id, Convention);
14552 Set_Is_Imported (Def_Id);
14553
14554 exit when From_Aspect_Specification (N);
14555 Hom_Id := Homonym (Hom_Id);
14556
14557 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
14558 end loop;
14559 end Java_Constructor;
14560
14561 ----------------------
14562 -- Java_Interface --
14563 ----------------------
14564
14565 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
14566
14567 when Pragma_Java_Interface => Java_Interface : declare
14568 Arg : Node_Id;
14569 Typ : Entity_Id;
14570
14571 begin
14572 GNAT_Pragma;
14573 Check_Arg_Count (1);
14574 Check_Optional_Identifier (Arg1, Name_Entity);
14575 Check_Arg_Is_Local_Name (Arg1);
14576
14577 Arg := Get_Pragma_Arg (Arg1);
14578 Analyze (Arg);
14579
14580 if Etype (Arg) = Any_Type then
14581 return;
14582 end if;
14583
14584 if not Is_Entity_Name (Arg)
14585 or else not Is_Type (Entity (Arg))
14586 then
14587 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
14588 end if;
14589
14590 Typ := Underlying_Type (Entity (Arg));
14591
14592 -- For now simply check some of the semantic constraints on the
14593 -- type. This currently leaves out some restrictions on interface
14594 -- types, namely that the parent type must be java.lang.Object.Typ
14595 -- and that all primitives of the type should be declared
14596 -- abstract. ???
14597
14598 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
14599 Error_Pragma_Arg
14600 ("pragma% requires an abstract tagged type", Arg1);
14601
14602 elsif not Has_Discriminants (Typ)
14603 or else Ekind (Etype (First_Discriminant (Typ)))
14604 /= E_Anonymous_Access_Type
14605 or else
14606 not Is_Class_Wide_Type
14607 (Designated_Type (Etype (First_Discriminant (Typ))))
14608 then
14609 Error_Pragma_Arg
14610 ("type must have a class-wide access discriminant", Arg1);
14611 end if;
14612 end Java_Interface;
14613
14614 ----------------
14615 -- Keep_Names --
14616 ----------------
14617
14618 -- pragma Keep_Names ([On => ] local_NAME);
14619
14620 when Pragma_Keep_Names => Keep_Names : declare
14621 Arg : Node_Id;
14622
14623 begin
14624 GNAT_Pragma;
14625 Check_Arg_Count (1);
14626 Check_Optional_Identifier (Arg1, Name_On);
14627 Check_Arg_Is_Local_Name (Arg1);
14628
14629 Arg := Get_Pragma_Arg (Arg1);
14630 Analyze (Arg);
14631
14632 if Etype (Arg) = Any_Type then
14633 return;
14634 end if;
14635
14636 if not Is_Entity_Name (Arg)
14637 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
14638 then
14639 Error_Pragma_Arg
14640 ("pragma% requires a local enumeration type", Arg1);
14641 end if;
14642
14643 Set_Discard_Names (Entity (Arg), False);
14644 end Keep_Names;
14645
14646 -------------
14647 -- License --
14648 -------------
14649
14650 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
14651
14652 when Pragma_License =>
14653 GNAT_Pragma;
14654 Check_Arg_Count (1);
14655 Check_No_Identifiers;
14656 Check_Valid_Configuration_Pragma;
14657 Check_Arg_Is_Identifier (Arg1);
14658
14659 declare
14660 Sind : constant Source_File_Index :=
14661 Source_Index (Current_Sem_Unit);
14662
14663 begin
14664 case Chars (Get_Pragma_Arg (Arg1)) is
14665 when Name_GPL =>
14666 Set_License (Sind, GPL);
14667
14668 when Name_Modified_GPL =>
14669 Set_License (Sind, Modified_GPL);
14670
14671 when Name_Restricted =>
14672 Set_License (Sind, Restricted);
14673
14674 when Name_Unrestricted =>
14675 Set_License (Sind, Unrestricted);
14676
14677 when others =>
14678 Error_Pragma_Arg ("invalid license name", Arg1);
14679 end case;
14680 end;
14681
14682 ---------------
14683 -- Link_With --
14684 ---------------
14685
14686 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
14687
14688 when Pragma_Link_With => Link_With : declare
14689 Arg : Node_Id;
14690
14691 begin
14692 GNAT_Pragma;
14693
14694 if Operating_Mode = Generate_Code
14695 and then In_Extended_Main_Source_Unit (N)
14696 then
14697 Check_At_Least_N_Arguments (1);
14698 Check_No_Identifiers;
14699 Check_Is_In_Decl_Part_Or_Package_Spec;
14700 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14701 Start_String;
14702
14703 Arg := Arg1;
14704 while Present (Arg) loop
14705 Check_Arg_Is_Static_Expression (Arg, Standard_String);
14706
14707 -- Store argument, converting sequences of spaces to a
14708 -- single null character (this is one of the differences
14709 -- in processing between Link_With and Linker_Options).
14710
14711 Arg_Store : declare
14712 C : constant Char_Code := Get_Char_Code (' ');
14713 S : constant String_Id :=
14714 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
14715 L : constant Nat := String_Length (S);
14716 F : Nat := 1;
14717
14718 procedure Skip_Spaces;
14719 -- Advance F past any spaces
14720
14721 -----------------
14722 -- Skip_Spaces --
14723 -----------------
14724
14725 procedure Skip_Spaces is
14726 begin
14727 while F <= L and then Get_String_Char (S, F) = C loop
14728 F := F + 1;
14729 end loop;
14730 end Skip_Spaces;
14731
14732 -- Start of processing for Arg_Store
14733
14734 begin
14735 Skip_Spaces; -- skip leading spaces
14736
14737 -- Loop through characters, changing any embedded
14738 -- sequence of spaces to a single null character (this
14739 -- is how Link_With/Linker_Options differ)
14740
14741 while F <= L loop
14742 if Get_String_Char (S, F) = C then
14743 Skip_Spaces;
14744 exit when F > L;
14745 Store_String_Char (ASCII.NUL);
14746
14747 else
14748 Store_String_Char (Get_String_Char (S, F));
14749 F := F + 1;
14750 end if;
14751 end loop;
14752 end Arg_Store;
14753
14754 Arg := Next (Arg);
14755
14756 if Present (Arg) then
14757 Store_String_Char (ASCII.NUL);
14758 end if;
14759 end loop;
14760
14761 Store_Linker_Option_String (End_String);
14762 end if;
14763 end Link_With;
14764
14765 ------------------
14766 -- Linker_Alias --
14767 ------------------
14768
14769 -- pragma Linker_Alias (
14770 -- [Entity =>] LOCAL_NAME
14771 -- [Target =>] static_string_EXPRESSION);
14772
14773 when Pragma_Linker_Alias =>
14774 GNAT_Pragma;
14775 Check_Arg_Order ((Name_Entity, Name_Target));
14776 Check_Arg_Count (2);
14777 Check_Optional_Identifier (Arg1, Name_Entity);
14778 Check_Optional_Identifier (Arg2, Name_Target);
14779 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14780 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
14781
14782 -- The only processing required is to link this item on to the
14783 -- list of rep items for the given entity. This is accomplished
14784 -- by the call to Rep_Item_Too_Late (when no error is detected
14785 -- and False is returned).
14786
14787 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
14788 return;
14789 else
14790 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
14791 end if;
14792
14793 ------------------------
14794 -- Linker_Constructor --
14795 ------------------------
14796
14797 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
14798
14799 -- Code is shared with Linker_Destructor
14800
14801 -----------------------
14802 -- Linker_Destructor --
14803 -----------------------
14804
14805 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
14806
14807 when Pragma_Linker_Constructor |
14808 Pragma_Linker_Destructor =>
14809 Linker_Constructor : declare
14810 Arg1_X : Node_Id;
14811 Proc : Entity_Id;
14812
14813 begin
14814 GNAT_Pragma;
14815 Check_Arg_Count (1);
14816 Check_No_Identifiers;
14817 Check_Arg_Is_Local_Name (Arg1);
14818 Arg1_X := Get_Pragma_Arg (Arg1);
14819 Analyze (Arg1_X);
14820 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
14821
14822 if not Is_Library_Level_Entity (Proc) then
14823 Error_Pragma_Arg
14824 ("argument for pragma% must be library level entity", Arg1);
14825 end if;
14826
14827 -- The only processing required is to link this item on to the
14828 -- list of rep items for the given entity. This is accomplished
14829 -- by the call to Rep_Item_Too_Late (when no error is detected
14830 -- and False is returned).
14831
14832 if Rep_Item_Too_Late (Proc, N) then
14833 return;
14834 else
14835 Set_Has_Gigi_Rep_Item (Proc);
14836 end if;
14837 end Linker_Constructor;
14838
14839 --------------------
14840 -- Linker_Options --
14841 --------------------
14842
14843 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
14844
14845 when Pragma_Linker_Options => Linker_Options : declare
14846 Arg : Node_Id;
14847
14848 begin
14849 Check_Ada_83_Warning;
14850 Check_No_Identifiers;
14851 Check_Arg_Count (1);
14852 Check_Is_In_Decl_Part_Or_Package_Spec;
14853 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14854 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
14855
14856 Arg := Arg2;
14857 while Present (Arg) loop
14858 Check_Arg_Is_Static_Expression (Arg, Standard_String);
14859 Store_String_Char (ASCII.NUL);
14860 Store_String_Chars
14861 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
14862 Arg := Next (Arg);
14863 end loop;
14864
14865 if Operating_Mode = Generate_Code
14866 and then In_Extended_Main_Source_Unit (N)
14867 then
14868 Store_Linker_Option_String (End_String);
14869 end if;
14870 end Linker_Options;
14871
14872 --------------------
14873 -- Linker_Section --
14874 --------------------
14875
14876 -- pragma Linker_Section (
14877 -- [Entity =>] LOCAL_NAME
14878 -- [Section =>] static_string_EXPRESSION);
14879
14880 when Pragma_Linker_Section =>
14881 GNAT_Pragma;
14882 Check_Arg_Order ((Name_Entity, Name_Section));
14883 Check_Arg_Count (2);
14884 Check_Optional_Identifier (Arg1, Name_Entity);
14885 Check_Optional_Identifier (Arg2, Name_Section);
14886 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14887 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
14888
14889 -- This pragma applies to objects and types
14890
14891 if not Is_Object (Entity (Get_Pragma_Arg (Arg1)))
14892 and then not Is_Type (Entity (Get_Pragma_Arg (Arg1)))
14893 then
14894 Error_Pragma_Arg
14895 ("pragma% applies only to objects and types", Arg1);
14896 end if;
14897
14898 -- The only processing required is to link this item on to the
14899 -- list of rep items for the given entity. This is accomplished
14900 -- by the call to Rep_Item_Too_Late (when no error is detected
14901 -- and False is returned).
14902
14903 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
14904 return;
14905 else
14906 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
14907 end if;
14908
14909 ----------
14910 -- List --
14911 ----------
14912
14913 -- pragma List (On | Off)
14914
14915 -- There is nothing to do here, since we did all the processing for
14916 -- this pragma in Par.Prag (so that it works properly even in syntax
14917 -- only mode).
14918
14919 when Pragma_List =>
14920 null;
14921
14922 ---------------
14923 -- Lock_Free --
14924 ---------------
14925
14926 -- pragma Lock_Free [(Boolean_EXPRESSION)];
14927
14928 when Pragma_Lock_Free => Lock_Free : declare
14929 P : constant Node_Id := Parent (N);
14930 Arg : Node_Id;
14931 Ent : Entity_Id;
14932 Val : Boolean;
14933
14934 begin
14935 Check_No_Identifiers;
14936 Check_At_Most_N_Arguments (1);
14937
14938 -- Protected definition case
14939
14940 if Nkind (P) = N_Protected_Definition then
14941 Ent := Defining_Identifier (Parent (P));
14942
14943 -- One argument
14944
14945 if Arg_Count = 1 then
14946 Arg := Get_Pragma_Arg (Arg1);
14947 Val := Is_True (Static_Boolean (Arg));
14948
14949 -- No arguments (expression is considered to be True)
14950
14951 else
14952 Val := True;
14953 end if;
14954
14955 -- Check duplicate pragma before we chain the pragma in the Rep
14956 -- Item chain of Ent.
14957
14958 Check_Duplicate_Pragma (Ent);
14959 Record_Rep_Item (Ent, N);
14960 Set_Uses_Lock_Free (Ent, Val);
14961
14962 -- Anything else is incorrect placement
14963
14964 else
14965 Pragma_Misplaced;
14966 end if;
14967 end Lock_Free;
14968
14969 --------------------
14970 -- Locking_Policy --
14971 --------------------
14972
14973 -- pragma Locking_Policy (policy_IDENTIFIER);
14974
14975 when Pragma_Locking_Policy => declare
14976 subtype LP_Range is Name_Id
14977 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
14978 LP_Val : LP_Range;
14979 LP : Character;
14980
14981 begin
14982 Check_Ada_83_Warning;
14983 Check_Arg_Count (1);
14984 Check_No_Identifiers;
14985 Check_Arg_Is_Locking_Policy (Arg1);
14986 Check_Valid_Configuration_Pragma;
14987 LP_Val := Chars (Get_Pragma_Arg (Arg1));
14988
14989 case LP_Val is
14990 when Name_Ceiling_Locking =>
14991 LP := 'C';
14992 when Name_Inheritance_Locking =>
14993 LP := 'I';
14994 when Name_Concurrent_Readers_Locking =>
14995 LP := 'R';
14996 end case;
14997
14998 if Locking_Policy /= ' '
14999 and then Locking_Policy /= LP
15000 then
15001 Error_Msg_Sloc := Locking_Policy_Sloc;
15002 Error_Pragma ("locking policy incompatible with policy#");
15003
15004 -- Set new policy, but always preserve System_Location since we
15005 -- like the error message with the run time name.
15006
15007 else
15008 Locking_Policy := LP;
15009
15010 if Locking_Policy_Sloc /= System_Location then
15011 Locking_Policy_Sloc := Loc;
15012 end if;
15013 end if;
15014 end;
15015
15016 ----------------
15017 -- Long_Float --
15018 ----------------
15019
15020 -- pragma Long_Float (D_Float | G_Float);
15021
15022 when Pragma_Long_Float => Long_Float : declare
15023 begin
15024 GNAT_Pragma;
15025 Check_Valid_Configuration_Pragma;
15026 Check_Arg_Count (1);
15027 Check_No_Identifier (Arg1);
15028 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
15029
15030 if not OpenVMS_On_Target then
15031 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
15032 end if;
15033
15034 -- D_Float case
15035
15036 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
15037 if Opt.Float_Format_Long = 'G' then
15038 Error_Pragma_Arg
15039 ("G_Float previously specified", Arg1);
15040
15041 elsif Current_Sem_Unit /= Main_Unit
15042 and then Opt.Float_Format_Long /= 'D'
15043 then
15044 Error_Pragma_Arg
15045 ("main unit not compiled with pragma Long_Float (D_Float)",
15046 "\pragma% must be used consistently for whole partition",
15047 Arg1);
15048
15049 else
15050 Opt.Float_Format_Long := 'D';
15051 end if;
15052
15053 -- G_Float case (this is the default, does not need overriding)
15054
15055 else
15056 if Opt.Float_Format_Long = 'D' then
15057 Error_Pragma ("D_Float previously specified");
15058
15059 elsif Current_Sem_Unit /= Main_Unit
15060 and then Opt.Float_Format_Long /= 'G'
15061 then
15062 Error_Pragma_Arg
15063 ("main unit not compiled with pragma Long_Float (G_Float)",
15064 "\pragma% must be used consistently for whole partition",
15065 Arg1);
15066
15067 else
15068 Opt.Float_Format_Long := 'G';
15069 end if;
15070 end if;
15071
15072 Set_Standard_Fpt_Formats;
15073 end Long_Float;
15074
15075 -------------------
15076 -- Loop_Optimize --
15077 -------------------
15078
15079 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
15080
15081 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
15082
15083 when Pragma_Loop_Optimize => Loop_Optimize : declare
15084 Hint : Node_Id;
15085
15086 begin
15087 GNAT_Pragma;
15088 Check_At_Least_N_Arguments (1);
15089 Check_No_Identifiers;
15090
15091 Hint := First (Pragma_Argument_Associations (N));
15092 while Present (Hint) loop
15093 Check_Arg_Is_One_Of (Hint,
15094 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
15095 Next (Hint);
15096 end loop;
15097
15098 Check_Loop_Pragma_Placement;
15099 end Loop_Optimize;
15100
15101 ------------------
15102 -- Loop_Variant --
15103 ------------------
15104
15105 -- pragma Loop_Variant
15106 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
15107
15108 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
15109
15110 -- CHANGE_DIRECTION ::= Increases | Decreases
15111
15112 when Pragma_Loop_Variant => Loop_Variant : declare
15113 Variant : Node_Id;
15114
15115 begin
15116 GNAT_Pragma;
15117 Check_At_Least_N_Arguments (1);
15118 Check_Loop_Pragma_Placement;
15119
15120 -- Process all increasing / decreasing expressions
15121
15122 Variant := First (Pragma_Argument_Associations (N));
15123 while Present (Variant) loop
15124 if not Nam_In (Chars (Variant), Name_Decreases,
15125 Name_Increases)
15126 then
15127 Error_Pragma_Arg ("wrong change modifier", Variant);
15128 end if;
15129
15130 Preanalyze_Assert_Expression
15131 (Expression (Variant), Any_Discrete);
15132
15133 Next (Variant);
15134 end loop;
15135 end Loop_Variant;
15136
15137 -----------------------
15138 -- Machine_Attribute --
15139 -----------------------
15140
15141 -- pragma Machine_Attribute (
15142 -- [Entity =>] LOCAL_NAME,
15143 -- [Attribute_Name =>] static_string_EXPRESSION
15144 -- [, [Info =>] static_EXPRESSION] );
15145
15146 when Pragma_Machine_Attribute => Machine_Attribute : declare
15147 Def_Id : Entity_Id;
15148
15149 begin
15150 GNAT_Pragma;
15151 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
15152
15153 if Arg_Count = 3 then
15154 Check_Optional_Identifier (Arg3, Name_Info);
15155 Check_Arg_Is_Static_Expression (Arg3);
15156 else
15157 Check_Arg_Count (2);
15158 end if;
15159
15160 Check_Optional_Identifier (Arg1, Name_Entity);
15161 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
15162 Check_Arg_Is_Local_Name (Arg1);
15163 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
15164 Def_Id := Entity (Get_Pragma_Arg (Arg1));
15165
15166 if Is_Access_Type (Def_Id) then
15167 Def_Id := Designated_Type (Def_Id);
15168 end if;
15169
15170 if Rep_Item_Too_Early (Def_Id, N) then
15171 return;
15172 end if;
15173
15174 Def_Id := Underlying_Type (Def_Id);
15175
15176 -- The only processing required is to link this item on to the
15177 -- list of rep items for the given entity. This is accomplished
15178 -- by the call to Rep_Item_Too_Late (when no error is detected
15179 -- and False is returned).
15180
15181 if Rep_Item_Too_Late (Def_Id, N) then
15182 return;
15183 else
15184 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
15185 end if;
15186 end Machine_Attribute;
15187
15188 ----------
15189 -- Main --
15190 ----------
15191
15192 -- pragma Main
15193 -- (MAIN_OPTION [, MAIN_OPTION]);
15194
15195 -- MAIN_OPTION ::=
15196 -- [STACK_SIZE =>] static_integer_EXPRESSION
15197 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
15198 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
15199
15200 when Pragma_Main => Main : declare
15201 Args : Args_List (1 .. 3);
15202 Names : constant Name_List (1 .. 3) := (
15203 Name_Stack_Size,
15204 Name_Task_Stack_Size_Default,
15205 Name_Time_Slicing_Enabled);
15206
15207 Nod : Node_Id;
15208
15209 begin
15210 GNAT_Pragma;
15211 Gather_Associations (Names, Args);
15212
15213 for J in 1 .. 2 loop
15214 if Present (Args (J)) then
15215 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
15216 end if;
15217 end loop;
15218
15219 if Present (Args (3)) then
15220 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
15221 end if;
15222
15223 Nod := Next (N);
15224 while Present (Nod) loop
15225 if Nkind (Nod) = N_Pragma
15226 and then Pragma_Name (Nod) = Name_Main
15227 then
15228 Error_Msg_Name_1 := Pname;
15229 Error_Msg_N ("duplicate pragma% not permitted", Nod);
15230 end if;
15231
15232 Next (Nod);
15233 end loop;
15234 end Main;
15235
15236 ------------------
15237 -- Main_Storage --
15238 ------------------
15239
15240 -- pragma Main_Storage
15241 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
15242
15243 -- MAIN_STORAGE_OPTION ::=
15244 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
15245 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
15246
15247 when Pragma_Main_Storage => Main_Storage : declare
15248 Args : Args_List (1 .. 2);
15249 Names : constant Name_List (1 .. 2) := (
15250 Name_Working_Storage,
15251 Name_Top_Guard);
15252
15253 Nod : Node_Id;
15254
15255 begin
15256 GNAT_Pragma;
15257 Gather_Associations (Names, Args);
15258
15259 for J in 1 .. 2 loop
15260 if Present (Args (J)) then
15261 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
15262 end if;
15263 end loop;
15264
15265 Check_In_Main_Program;
15266
15267 Nod := Next (N);
15268 while Present (Nod) loop
15269 if Nkind (Nod) = N_Pragma
15270 and then Pragma_Name (Nod) = Name_Main_Storage
15271 then
15272 Error_Msg_Name_1 := Pname;
15273 Error_Msg_N ("duplicate pragma% not permitted", Nod);
15274 end if;
15275
15276 Next (Nod);
15277 end loop;
15278 end Main_Storage;
15279
15280 -----------------
15281 -- Memory_Size --
15282 -----------------
15283
15284 -- pragma Memory_Size (NUMERIC_LITERAL)
15285
15286 when Pragma_Memory_Size =>
15287 GNAT_Pragma;
15288
15289 -- Memory size is simply ignored
15290
15291 Check_No_Identifiers;
15292 Check_Arg_Count (1);
15293 Check_Arg_Is_Integer_Literal (Arg1);
15294
15295 -------------
15296 -- No_Body --
15297 -------------
15298
15299 -- pragma No_Body;
15300
15301 -- The only correct use of this pragma is on its own in a file, in
15302 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
15303 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
15304 -- check for a file containing nothing but a No_Body pragma). If we
15305 -- attempt to process it during normal semantics processing, it means
15306 -- it was misplaced.
15307
15308 when Pragma_No_Body =>
15309 GNAT_Pragma;
15310 Pragma_Misplaced;
15311
15312 ---------------
15313 -- No_Inline --
15314 ---------------
15315
15316 -- pragma No_Inline ( NAME {, NAME} );
15317
15318 when Pragma_No_Inline =>
15319 GNAT_Pragma;
15320 Process_Inline (Suppressed);
15321
15322 ---------------
15323 -- No_Return --
15324 ---------------
15325
15326 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
15327
15328 when Pragma_No_Return => No_Return : declare
15329 Id : Node_Id;
15330 E : Entity_Id;
15331 Found : Boolean;
15332 Arg : Node_Id;
15333
15334 begin
15335 Ada_2005_Pragma;
15336 Check_At_Least_N_Arguments (1);
15337
15338 -- Loop through arguments of pragma
15339
15340 Arg := Arg1;
15341 while Present (Arg) loop
15342 Check_Arg_Is_Local_Name (Arg);
15343 Id := Get_Pragma_Arg (Arg);
15344 Analyze (Id);
15345
15346 if not Is_Entity_Name (Id) then
15347 Error_Pragma_Arg ("entity name required", Arg);
15348 end if;
15349
15350 if Etype (Id) = Any_Type then
15351 raise Pragma_Exit;
15352 end if;
15353
15354 -- Loop to find matching procedures
15355
15356 E := Entity (Id);
15357 Found := False;
15358 while Present (E)
15359 and then Scope (E) = Current_Scope
15360 loop
15361 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
15362 Set_No_Return (E);
15363
15364 -- Set flag on any alias as well
15365
15366 if Is_Overloadable (E) and then Present (Alias (E)) then
15367 Set_No_Return (Alias (E));
15368 end if;
15369
15370 Found := True;
15371 end if;
15372
15373 exit when From_Aspect_Specification (N);
15374 E := Homonym (E);
15375 end loop;
15376
15377 if not Found then
15378 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
15379 end if;
15380
15381 Next (Arg);
15382 end loop;
15383 end No_Return;
15384
15385 -----------------
15386 -- No_Run_Time --
15387 -----------------
15388
15389 -- pragma No_Run_Time;
15390
15391 -- Note: this pragma is retained for backwards compatibility. See
15392 -- body of Rtsfind for full details on its handling.
15393
15394 when Pragma_No_Run_Time =>
15395 GNAT_Pragma;
15396 Check_Valid_Configuration_Pragma;
15397 Check_Arg_Count (0);
15398
15399 No_Run_Time_Mode := True;
15400 Configurable_Run_Time_Mode := True;
15401
15402 -- Set Duration to 32 bits if word size is 32
15403
15404 if Ttypes.System_Word_Size = 32 then
15405 Duration_32_Bits_On_Target := True;
15406 end if;
15407
15408 -- Set appropriate restrictions
15409
15410 Set_Restriction (No_Finalization, N);
15411 Set_Restriction (No_Exception_Handlers, N);
15412 Set_Restriction (Max_Tasks, N, 0);
15413 Set_Restriction (No_Tasking, N);
15414
15415 ------------------------
15416 -- No_Strict_Aliasing --
15417 ------------------------
15418
15419 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
15420
15421 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
15422 E_Id : Entity_Id;
15423
15424 begin
15425 GNAT_Pragma;
15426 Check_At_Most_N_Arguments (1);
15427
15428 if Arg_Count = 0 then
15429 Check_Valid_Configuration_Pragma;
15430 Opt.No_Strict_Aliasing := True;
15431
15432 else
15433 Check_Optional_Identifier (Arg2, Name_Entity);
15434 Check_Arg_Is_Local_Name (Arg1);
15435 E_Id := Entity (Get_Pragma_Arg (Arg1));
15436
15437 if E_Id = Any_Type then
15438 return;
15439 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
15440 Error_Pragma_Arg ("pragma% requires access type", Arg1);
15441 end if;
15442
15443 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
15444 end if;
15445 end No_Strict_Aliasing;
15446
15447 -----------------------
15448 -- Normalize_Scalars --
15449 -----------------------
15450
15451 -- pragma Normalize_Scalars;
15452
15453 when Pragma_Normalize_Scalars =>
15454 Check_Ada_83_Warning;
15455 Check_Arg_Count (0);
15456 Check_Valid_Configuration_Pragma;
15457
15458 -- Normalize_Scalars creates false positives in CodePeer, and
15459 -- incorrect negative results in SPARK mode, so ignore this pragma
15460 -- in these modes.
15461
15462 if not (CodePeer_Mode or SPARK_Mode) then
15463 Normalize_Scalars := True;
15464 Init_Or_Norm_Scalars := True;
15465 end if;
15466
15467 -----------------
15468 -- Obsolescent --
15469 -----------------
15470
15471 -- pragma Obsolescent;
15472
15473 -- pragma Obsolescent (
15474 -- [Message =>] static_string_EXPRESSION
15475 -- [,[Version =>] Ada_05]]);
15476
15477 -- pragma Obsolescent (
15478 -- [Entity =>] NAME
15479 -- [,[Message =>] static_string_EXPRESSION
15480 -- [,[Version =>] Ada_05]] );
15481
15482 when Pragma_Obsolescent => Obsolescent : declare
15483 Ename : Node_Id;
15484 Decl : Node_Id;
15485
15486 procedure Set_Obsolescent (E : Entity_Id);
15487 -- Given an entity Ent, mark it as obsolescent if appropriate
15488
15489 ---------------------
15490 -- Set_Obsolescent --
15491 ---------------------
15492
15493 procedure Set_Obsolescent (E : Entity_Id) is
15494 Active : Boolean;
15495 Ent : Entity_Id;
15496 S : String_Id;
15497
15498 begin
15499 Active := True;
15500 Ent := E;
15501
15502 -- Entity name was given
15503
15504 if Present (Ename) then
15505
15506 -- If entity name matches, we are fine. Save entity in
15507 -- pragma argument, for ASIS use.
15508
15509 if Chars (Ename) = Chars (Ent) then
15510 Set_Entity (Ename, Ent);
15511 Generate_Reference (Ent, Ename);
15512
15513 -- If entity name does not match, only possibility is an
15514 -- enumeration literal from an enumeration type declaration.
15515
15516 elsif Ekind (Ent) /= E_Enumeration_Type then
15517 Error_Pragma
15518 ("pragma % entity name does not match declaration");
15519
15520 else
15521 Ent := First_Literal (E);
15522 loop
15523 if No (Ent) then
15524 Error_Pragma
15525 ("pragma % entity name does not match any "
15526 & "enumeration literal");
15527
15528 elsif Chars (Ent) = Chars (Ename) then
15529 Set_Entity (Ename, Ent);
15530 Generate_Reference (Ent, Ename);
15531 exit;
15532
15533 else
15534 Ent := Next_Literal (Ent);
15535 end if;
15536 end loop;
15537 end if;
15538 end if;
15539
15540 -- Ent points to entity to be marked
15541
15542 if Arg_Count >= 1 then
15543
15544 -- Deal with static string argument
15545
15546 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
15547 S := Strval (Get_Pragma_Arg (Arg1));
15548
15549 for J in 1 .. String_Length (S) loop
15550 if not In_Character_Range (Get_String_Char (S, J)) then
15551 Error_Pragma_Arg
15552 ("pragma% argument does not allow wide characters",
15553 Arg1);
15554 end if;
15555 end loop;
15556
15557 Obsolescent_Warnings.Append
15558 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
15559
15560 -- Check for Ada_05 parameter
15561
15562 if Arg_Count /= 1 then
15563 Check_Arg_Count (2);
15564
15565 declare
15566 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
15567
15568 begin
15569 Check_Arg_Is_Identifier (Argx);
15570
15571 if Chars (Argx) /= Name_Ada_05 then
15572 Error_Msg_Name_2 := Name_Ada_05;
15573 Error_Pragma_Arg
15574 ("only allowed argument for pragma% is %", Argx);
15575 end if;
15576
15577 if Ada_Version_Explicit < Ada_2005
15578 or else not Warn_On_Ada_2005_Compatibility
15579 then
15580 Active := False;
15581 end if;
15582 end;
15583 end if;
15584 end if;
15585
15586 -- Set flag if pragma active
15587
15588 if Active then
15589 Set_Is_Obsolescent (Ent);
15590 end if;
15591
15592 return;
15593 end Set_Obsolescent;
15594
15595 -- Start of processing for pragma Obsolescent
15596
15597 begin
15598 GNAT_Pragma;
15599
15600 Check_At_Most_N_Arguments (3);
15601
15602 -- See if first argument specifies an entity name
15603
15604 if Arg_Count >= 1
15605 and then
15606 (Chars (Arg1) = Name_Entity
15607 or else
15608 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
15609 N_Identifier,
15610 N_Operator_Symbol))
15611 then
15612 Ename := Get_Pragma_Arg (Arg1);
15613
15614 -- Eliminate first argument, so we can share processing
15615
15616 Arg1 := Arg2;
15617 Arg2 := Arg3;
15618 Arg_Count := Arg_Count - 1;
15619
15620 -- No Entity name argument given
15621
15622 else
15623 Ename := Empty;
15624 end if;
15625
15626 if Arg_Count >= 1 then
15627 Check_Optional_Identifier (Arg1, Name_Message);
15628
15629 if Arg_Count = 2 then
15630 Check_Optional_Identifier (Arg2, Name_Version);
15631 end if;
15632 end if;
15633
15634 -- Get immediately preceding declaration
15635
15636 Decl := Prev (N);
15637 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
15638 Prev (Decl);
15639 end loop;
15640
15641 -- Cases where we do not follow anything other than another pragma
15642
15643 if No (Decl) then
15644
15645 -- First case: library level compilation unit declaration with
15646 -- the pragma immediately following the declaration.
15647
15648 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
15649 Set_Obsolescent
15650 (Defining_Entity (Unit (Parent (Parent (N)))));
15651 return;
15652
15653 -- Case 2: library unit placement for package
15654
15655 else
15656 declare
15657 Ent : constant Entity_Id := Find_Lib_Unit_Name;
15658 begin
15659 if Is_Package_Or_Generic_Package (Ent) then
15660 Set_Obsolescent (Ent);
15661 return;
15662 end if;
15663 end;
15664 end if;
15665
15666 -- Cases where we must follow a declaration
15667
15668 else
15669 if Nkind (Decl) not in N_Declaration
15670 and then Nkind (Decl) not in N_Later_Decl_Item
15671 and then Nkind (Decl) not in N_Generic_Declaration
15672 and then Nkind (Decl) not in N_Renaming_Declaration
15673 then
15674 Error_Pragma
15675 ("pragma% misplaced, "
15676 & "must immediately follow a declaration");
15677
15678 else
15679 Set_Obsolescent (Defining_Entity (Decl));
15680 return;
15681 end if;
15682 end if;
15683 end Obsolescent;
15684
15685 --------------
15686 -- Optimize --
15687 --------------
15688
15689 -- pragma Optimize (Time | Space | Off);
15690
15691 -- The actual check for optimize is done in Gigi. Note that this
15692 -- pragma does not actually change the optimization setting, it
15693 -- simply checks that it is consistent with the pragma.
15694
15695 when Pragma_Optimize =>
15696 Check_No_Identifiers;
15697 Check_Arg_Count (1);
15698 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
15699
15700 ------------------------
15701 -- Optimize_Alignment --
15702 ------------------------
15703
15704 -- pragma Optimize_Alignment (Time | Space | Off);
15705
15706 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
15707 GNAT_Pragma;
15708 Check_No_Identifiers;
15709 Check_Arg_Count (1);
15710 Check_Valid_Configuration_Pragma;
15711
15712 declare
15713 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
15714 begin
15715 case Nam is
15716 when Name_Time =>
15717 Opt.Optimize_Alignment := 'T';
15718 when Name_Space =>
15719 Opt.Optimize_Alignment := 'S';
15720 when Name_Off =>
15721 Opt.Optimize_Alignment := 'O';
15722 when others =>
15723 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
15724 end case;
15725 end;
15726
15727 -- Set indication that mode is set locally. If we are in fact in a
15728 -- configuration pragma file, this setting is harmless since the
15729 -- switch will get reset anyway at the start of each unit.
15730
15731 Optimize_Alignment_Local := True;
15732 end Optimize_Alignment;
15733
15734 -------------
15735 -- Ordered --
15736 -------------
15737
15738 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
15739
15740 when Pragma_Ordered => Ordered : declare
15741 Assoc : constant Node_Id := Arg1;
15742 Type_Id : Node_Id;
15743 Typ : Entity_Id;
15744
15745 begin
15746 GNAT_Pragma;
15747 Check_No_Identifiers;
15748 Check_Arg_Count (1);
15749 Check_Arg_Is_Local_Name (Arg1);
15750
15751 Type_Id := Get_Pragma_Arg (Assoc);
15752 Find_Type (Type_Id);
15753 Typ := Entity (Type_Id);
15754
15755 if Typ = Any_Type then
15756 return;
15757 else
15758 Typ := Underlying_Type (Typ);
15759 end if;
15760
15761 if not Is_Enumeration_Type (Typ) then
15762 Error_Pragma ("pragma% must specify enumeration type");
15763 end if;
15764
15765 Check_First_Subtype (Arg1);
15766 Set_Has_Pragma_Ordered (Base_Type (Typ));
15767 end Ordered;
15768
15769 -------------------
15770 -- Overflow_Mode --
15771 -------------------
15772
15773 -- pragma Overflow_Mode
15774 -- ([General => ] MODE [, [Assertions => ] MODE]);
15775
15776 -- MODE := STRICT | MINIMIZED | ELIMINATED
15777
15778 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
15779 -- since System.Bignums makes this assumption. This is true of nearly
15780 -- all (all?) targets.
15781
15782 when Pragma_Overflow_Mode => Overflow_Mode : declare
15783 function Get_Overflow_Mode
15784 (Name : Name_Id;
15785 Arg : Node_Id) return Overflow_Mode_Type;
15786 -- Function to process one pragma argument, Arg. If an identifier
15787 -- is present, it must be Name. Mode type is returned if a valid
15788 -- argument exists, otherwise an error is signalled.
15789
15790 -----------------------
15791 -- Get_Overflow_Mode --
15792 -----------------------
15793
15794 function Get_Overflow_Mode
15795 (Name : Name_Id;
15796 Arg : Node_Id) return Overflow_Mode_Type
15797 is
15798 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
15799
15800 begin
15801 Check_Optional_Identifier (Arg, Name);
15802 Check_Arg_Is_Identifier (Argx);
15803
15804 if Chars (Argx) = Name_Strict then
15805 return Strict;
15806
15807 elsif Chars (Argx) = Name_Minimized then
15808 return Minimized;
15809
15810 elsif Chars (Argx) = Name_Eliminated then
15811 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
15812 Error_Pragma_Arg
15813 ("Eliminated not implemented on this target", Argx);
15814 else
15815 return Eliminated;
15816 end if;
15817
15818 else
15819 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
15820 end if;
15821 end Get_Overflow_Mode;
15822
15823 -- Start of processing for Overflow_Mode
15824
15825 begin
15826 GNAT_Pragma;
15827 Check_At_Least_N_Arguments (1);
15828 Check_At_Most_N_Arguments (2);
15829
15830 -- Process first argument
15831
15832 Scope_Suppress.Overflow_Mode_General :=
15833 Get_Overflow_Mode (Name_General, Arg1);
15834
15835 -- Case of only one argument
15836
15837 if Arg_Count = 1 then
15838 Scope_Suppress.Overflow_Mode_Assertions :=
15839 Scope_Suppress.Overflow_Mode_General;
15840
15841 -- Case of two arguments present
15842
15843 else
15844 Scope_Suppress.Overflow_Mode_Assertions :=
15845 Get_Overflow_Mode (Name_Assertions, Arg2);
15846 end if;
15847 end Overflow_Mode;
15848
15849 --------------------------
15850 -- Overriding Renamings --
15851 --------------------------
15852
15853 -- pragma Overriding_Renamings;
15854
15855 when Pragma_Overriding_Renamings =>
15856 GNAT_Pragma;
15857 Check_Arg_Count (0);
15858 Check_Valid_Configuration_Pragma;
15859 Overriding_Renamings := True;
15860
15861 ----------
15862 -- Pack --
15863 ----------
15864
15865 -- pragma Pack (first_subtype_LOCAL_NAME);
15866
15867 when Pragma_Pack => Pack : declare
15868 Assoc : constant Node_Id := Arg1;
15869 Type_Id : Node_Id;
15870 Typ : Entity_Id;
15871 Ctyp : Entity_Id;
15872 Ignore : Boolean := False;
15873
15874 begin
15875 Check_No_Identifiers;
15876 Check_Arg_Count (1);
15877 Check_Arg_Is_Local_Name (Arg1);
15878
15879 Type_Id := Get_Pragma_Arg (Assoc);
15880 Find_Type (Type_Id);
15881 Typ := Entity (Type_Id);
15882
15883 if Typ = Any_Type
15884 or else Rep_Item_Too_Early (Typ, N)
15885 then
15886 return;
15887 else
15888 Typ := Underlying_Type (Typ);
15889 end if;
15890
15891 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
15892 Error_Pragma ("pragma% must specify array or record type");
15893 end if;
15894
15895 Check_First_Subtype (Arg1);
15896 Check_Duplicate_Pragma (Typ);
15897
15898 -- Array type
15899
15900 if Is_Array_Type (Typ) then
15901 Ctyp := Component_Type (Typ);
15902
15903 -- Ignore pack that does nothing
15904
15905 if Known_Static_Esize (Ctyp)
15906 and then Known_Static_RM_Size (Ctyp)
15907 and then Esize (Ctyp) = RM_Size (Ctyp)
15908 and then Addressable (Esize (Ctyp))
15909 then
15910 Ignore := True;
15911 end if;
15912
15913 -- Process OK pragma Pack. Note that if there is a separate
15914 -- component clause present, the Pack will be cancelled. This
15915 -- processing is in Freeze.
15916
15917 if not Rep_Item_Too_Late (Typ, N) then
15918
15919 -- In the context of static code analysis, we do not need
15920 -- complex front-end expansions related to pragma Pack,
15921 -- so disable handling of pragma Pack in these cases.
15922
15923 if CodePeer_Mode or SPARK_Mode then
15924 null;
15925
15926 -- Don't attempt any packing for VM targets. We possibly
15927 -- could deal with some cases of array bit-packing, but we
15928 -- don't bother, since this is not a typical kind of
15929 -- representation in the VM context anyway (and would not
15930 -- for example work nicely with the debugger).
15931
15932 elsif VM_Target /= No_VM then
15933 if not GNAT_Mode then
15934 Error_Pragma
15935 ("??pragma% ignored in this configuration");
15936 end if;
15937
15938 -- Normal case where we do the pack action
15939
15940 else
15941 if not Ignore then
15942 Set_Is_Packed (Base_Type (Typ));
15943 Set_Has_Non_Standard_Rep (Base_Type (Typ));
15944 end if;
15945
15946 Set_Has_Pragma_Pack (Base_Type (Typ));
15947 end if;
15948 end if;
15949
15950 -- For record types, the pack is always effective
15951
15952 else pragma Assert (Is_Record_Type (Typ));
15953 if not Rep_Item_Too_Late (Typ, N) then
15954
15955 -- Ignore pack request with warning in VM mode (skip warning
15956 -- if we are compiling GNAT run time library).
15957
15958 if VM_Target /= No_VM then
15959 if not GNAT_Mode then
15960 Error_Pragma
15961 ("??pragma% ignored in this configuration");
15962 end if;
15963
15964 -- Normal case of pack request active
15965
15966 else
15967 Set_Is_Packed (Base_Type (Typ));
15968 Set_Has_Pragma_Pack (Base_Type (Typ));
15969 Set_Has_Non_Standard_Rep (Base_Type (Typ));
15970 end if;
15971 end if;
15972 end if;
15973 end Pack;
15974
15975 ----------
15976 -- Page --
15977 ----------
15978
15979 -- pragma Page;
15980
15981 -- There is nothing to do here, since we did all the processing for
15982 -- this pragma in Par.Prag (so that it works properly even in syntax
15983 -- only mode).
15984
15985 when Pragma_Page =>
15986 null;
15987
15988 ----------------------------------
15989 -- Partition_Elaboration_Policy --
15990 ----------------------------------
15991
15992 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
15993
15994 when Pragma_Partition_Elaboration_Policy => declare
15995 subtype PEP_Range is Name_Id
15996 range First_Partition_Elaboration_Policy_Name
15997 .. Last_Partition_Elaboration_Policy_Name;
15998 PEP_Val : PEP_Range;
15999 PEP : Character;
16000
16001 begin
16002 Ada_2005_Pragma;
16003 Check_Arg_Count (1);
16004 Check_No_Identifiers;
16005 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
16006 Check_Valid_Configuration_Pragma;
16007 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
16008
16009 case PEP_Val is
16010 when Name_Concurrent =>
16011 PEP := 'C';
16012 when Name_Sequential =>
16013 PEP := 'S';
16014 end case;
16015
16016 if Partition_Elaboration_Policy /= ' '
16017 and then Partition_Elaboration_Policy /= PEP
16018 then
16019 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
16020 Error_Pragma
16021 ("partition elaboration policy incompatible with policy#");
16022
16023 -- Set new policy, but always preserve System_Location since we
16024 -- like the error message with the run time name.
16025
16026 else
16027 Partition_Elaboration_Policy := PEP;
16028
16029 if Partition_Elaboration_Policy_Sloc /= System_Location then
16030 Partition_Elaboration_Policy_Sloc := Loc;
16031 end if;
16032 end if;
16033 end;
16034
16035 -------------
16036 -- Passive --
16037 -------------
16038
16039 -- pragma Passive [(PASSIVE_FORM)];
16040
16041 -- PASSIVE_FORM ::= Semaphore | No
16042
16043 when Pragma_Passive =>
16044 GNAT_Pragma;
16045
16046 if Nkind (Parent (N)) /= N_Task_Definition then
16047 Error_Pragma ("pragma% must be within task definition");
16048 end if;
16049
16050 if Arg_Count /= 0 then
16051 Check_Arg_Count (1);
16052 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
16053 end if;
16054
16055 ----------------------------------
16056 -- Preelaborable_Initialization --
16057 ----------------------------------
16058
16059 -- pragma Preelaborable_Initialization (DIRECT_NAME);
16060
16061 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
16062 Ent : Entity_Id;
16063
16064 begin
16065 Ada_2005_Pragma;
16066 Check_Arg_Count (1);
16067 Check_No_Identifiers;
16068 Check_Arg_Is_Identifier (Arg1);
16069 Check_Arg_Is_Local_Name (Arg1);
16070 Check_First_Subtype (Arg1);
16071 Ent := Entity (Get_Pragma_Arg (Arg1));
16072
16073 -- The pragma may come from an aspect on a private declaration,
16074 -- even if the freeze point at which this is analyzed in the
16075 -- private part after the full view.
16076
16077 if Has_Private_Declaration (Ent)
16078 and then From_Aspect_Specification (N)
16079 then
16080 null;
16081
16082 elsif Is_Private_Type (Ent)
16083 or else Is_Protected_Type (Ent)
16084 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
16085 then
16086 null;
16087
16088 else
16089 Error_Pragma_Arg
16090 ("pragma % can only be applied to private, formal derived or "
16091 & "protected type",
16092 Arg1);
16093 end if;
16094
16095 -- Give an error if the pragma is applied to a protected type that
16096 -- does not qualify (due to having entries, or due to components
16097 -- that do not qualify).
16098
16099 if Is_Protected_Type (Ent)
16100 and then not Has_Preelaborable_Initialization (Ent)
16101 then
16102 Error_Msg_N
16103 ("protected type & does not have preelaborable "
16104 & "initialization", Ent);
16105
16106 -- Otherwise mark the type as definitely having preelaborable
16107 -- initialization.
16108
16109 else
16110 Set_Known_To_Have_Preelab_Init (Ent);
16111 end if;
16112
16113 if Has_Pragma_Preelab_Init (Ent)
16114 and then Warn_On_Redundant_Constructs
16115 then
16116 Error_Pragma ("?r?duplicate pragma%!");
16117 else
16118 Set_Has_Pragma_Preelab_Init (Ent);
16119 end if;
16120 end Preelab_Init;
16121
16122 --------------------
16123 -- Persistent_BSS --
16124 --------------------
16125
16126 -- pragma Persistent_BSS [(object_NAME)];
16127
16128 when Pragma_Persistent_BSS => Persistent_BSS : declare
16129 Decl : Node_Id;
16130 Ent : Entity_Id;
16131 Prag : Node_Id;
16132
16133 begin
16134 GNAT_Pragma;
16135 Check_At_Most_N_Arguments (1);
16136
16137 -- Case of application to specific object (one argument)
16138
16139 if Arg_Count = 1 then
16140 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16141
16142 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
16143 or else not
16144 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
16145 E_Constant)
16146 then
16147 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
16148 end if;
16149
16150 Ent := Entity (Get_Pragma_Arg (Arg1));
16151 Decl := Parent (Ent);
16152
16153 -- Check for duplication before inserting in list of
16154 -- representation items.
16155
16156 Check_Duplicate_Pragma (Ent);
16157
16158 if Rep_Item_Too_Late (Ent, N) then
16159 return;
16160 end if;
16161
16162 if Present (Expression (Decl)) then
16163 Error_Pragma_Arg
16164 ("object for pragma% cannot have initialization", Arg1);
16165 end if;
16166
16167 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
16168 Error_Pragma_Arg
16169 ("object type for pragma% is not potentially persistent",
16170 Arg1);
16171 end if;
16172
16173 Prag :=
16174 Make_Linker_Section_Pragma
16175 (Ent, Sloc (N), ".persistent.bss");
16176 Insert_After (N, Prag);
16177 Analyze (Prag);
16178
16179 -- Case of use as configuration pragma with no arguments
16180
16181 else
16182 Check_Valid_Configuration_Pragma;
16183 Persistent_BSS_Mode := True;
16184 end if;
16185 end Persistent_BSS;
16186
16187 -------------
16188 -- Polling --
16189 -------------
16190
16191 -- pragma Polling (ON | OFF);
16192
16193 when Pragma_Polling =>
16194 GNAT_Pragma;
16195 Check_Arg_Count (1);
16196 Check_No_Identifiers;
16197 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16198 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
16199
16200 ------------------
16201 -- Post[_Class] --
16202 ------------------
16203
16204 -- pragma Post (Boolean_EXPRESSION);
16205 -- pragma Post_Class (Boolean_EXPRESSION);
16206
16207 when Pragma_Post | Pragma_Post_Class => Post : declare
16208 PC_Pragma : Node_Id;
16209
16210 begin
16211 GNAT_Pragma;
16212 Check_Arg_Count (1);
16213 Check_No_Identifiers;
16214 Check_Pre_Post;
16215
16216 -- Rewrite Post[_Class] pragma as Precondition pragma setting the
16217 -- flag Class_Present to True for the Post_Class case.
16218
16219 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
16220 PC_Pragma := New_Copy (N);
16221 Set_Pragma_Identifier
16222 (PC_Pragma, Make_Identifier (Loc, Name_Postcondition));
16223 Rewrite (N, PC_Pragma);
16224 Set_Analyzed (N, False);
16225 Analyze (N);
16226 end Post;
16227
16228 -------------------
16229 -- Postcondition --
16230 -------------------
16231
16232 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
16233 -- [,[Message =>] String_EXPRESSION]);
16234
16235 when Pragma_Postcondition => Postcondition : declare
16236 In_Body : Boolean;
16237
16238 begin
16239 GNAT_Pragma;
16240 Check_At_Least_N_Arguments (1);
16241 Check_At_Most_N_Arguments (2);
16242 Check_Optional_Identifier (Arg1, Name_Check);
16243
16244 -- Verify the proper placement of the pragma. The remainder of the
16245 -- processing is found in Sem_Ch6/Sem_Ch7.
16246
16247 Check_Precondition_Postcondition (In_Body);
16248
16249 -- When the pragma is a source construct appearing inside a body,
16250 -- preanalyze the boolean_expression to detect illegal forward
16251 -- references:
16252
16253 -- procedure P is
16254 -- pragma Postcondition (X'Old ...);
16255 -- X : ...
16256
16257 if Comes_From_Source (N) and then In_Body then
16258 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
16259 end if;
16260 end Postcondition;
16261
16262 -----------------
16263 -- Pre[_Class] --
16264 -----------------
16265
16266 -- pragma Pre (Boolean_EXPRESSION);
16267 -- pragma Pre_Class (Boolean_EXPRESSION);
16268
16269 when Pragma_Pre | Pragma_Pre_Class => Pre : declare
16270 PC_Pragma : Node_Id;
16271
16272 begin
16273 GNAT_Pragma;
16274 Check_Arg_Count (1);
16275 Check_No_Identifiers;
16276 Check_Pre_Post;
16277
16278 -- Rewrite Pre[_Class] pragma as Precondition pragma setting the
16279 -- flag Class_Present to True for the Pre_Class case.
16280
16281 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
16282 PC_Pragma := New_Copy (N);
16283 Set_Pragma_Identifier
16284 (PC_Pragma, Make_Identifier (Loc, Name_Precondition));
16285 Rewrite (N, PC_Pragma);
16286 Set_Analyzed (N, False);
16287 Analyze (N);
16288 end Pre;
16289
16290 ------------------
16291 -- Precondition --
16292 ------------------
16293
16294 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
16295 -- [,[Message =>] String_EXPRESSION]);
16296
16297 when Pragma_Precondition => Precondition : declare
16298 In_Body : Boolean;
16299
16300 begin
16301 GNAT_Pragma;
16302 Check_At_Least_N_Arguments (1);
16303 Check_At_Most_N_Arguments (2);
16304 Check_Optional_Identifier (Arg1, Name_Check);
16305 Check_Precondition_Postcondition (In_Body);
16306
16307 -- If in spec, nothing more to do. If in body, then we convert
16308 -- the pragma to an equivalent pragma Check. That works fine since
16309 -- pragma Check will analyze the condition in the proper context.
16310
16311 -- The form of the pragma Check is either:
16312
16313 -- pragma Check (Precondition, cond [, msg])
16314 -- or
16315 -- pragma Check (Pre, cond [, msg])
16316
16317 -- We use the Pre form if this pragma derived from a Pre aspect.
16318 -- This is needed to make sure that the right set of Policy
16319 -- pragmas are checked.
16320
16321 if In_Body then
16322
16323 -- Rewrite as Check pragma
16324
16325 Rewrite (N,
16326 Make_Pragma (Loc,
16327 Chars => Name_Check,
16328 Pragma_Argument_Associations => New_List (
16329 Make_Pragma_Argument_Association (Loc,
16330 Expression => Make_Identifier (Loc, Pname)),
16331
16332 Make_Pragma_Argument_Association (Sloc (Arg1),
16333 Expression =>
16334 Relocate_Node (Get_Pragma_Arg (Arg1))))));
16335
16336 if Arg_Count = 2 then
16337 Append_To (Pragma_Argument_Associations (N),
16338 Make_Pragma_Argument_Association (Sloc (Arg2),
16339 Expression =>
16340 Relocate_Node (Get_Pragma_Arg (Arg2))));
16341 end if;
16342
16343 Analyze (N);
16344 end if;
16345 end Precondition;
16346
16347 ---------------
16348 -- Predicate --
16349 ---------------
16350
16351 -- pragma Predicate
16352 -- ([Entity =>] type_LOCAL_NAME,
16353 -- [Check =>] boolean_EXPRESSION);
16354
16355 when Pragma_Predicate => Predicate : declare
16356 Type_Id : Node_Id;
16357 Typ : Entity_Id;
16358
16359 Discard : Boolean;
16360 pragma Unreferenced (Discard);
16361
16362 begin
16363 GNAT_Pragma;
16364 Check_Arg_Count (2);
16365 Check_Optional_Identifier (Arg1, Name_Entity);
16366 Check_Optional_Identifier (Arg2, Name_Check);
16367
16368 Check_Arg_Is_Local_Name (Arg1);
16369
16370 Type_Id := Get_Pragma_Arg (Arg1);
16371 Find_Type (Type_Id);
16372 Typ := Entity (Type_Id);
16373
16374 if Typ = Any_Type then
16375 return;
16376 end if;
16377
16378 -- The remaining processing is simply to link the pragma on to
16379 -- the rep item chain, for processing when the type is frozen.
16380 -- This is accomplished by a call to Rep_Item_Too_Late. We also
16381 -- mark the type as having predicates.
16382
16383 Set_Has_Predicates (Typ);
16384 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
16385 end Predicate;
16386
16387 ------------------
16388 -- Preelaborate --
16389 ------------------
16390
16391 -- pragma Preelaborate [(library_unit_NAME)];
16392
16393 -- Set the flag Is_Preelaborated of program unit name entity
16394
16395 when Pragma_Preelaborate => Preelaborate : declare
16396 Pa : constant Node_Id := Parent (N);
16397 Pk : constant Node_Kind := Nkind (Pa);
16398 Ent : Entity_Id;
16399
16400 begin
16401 Check_Ada_83_Warning;
16402 Check_Valid_Library_Unit_Pragma;
16403
16404 if Nkind (N) = N_Null_Statement then
16405 return;
16406 end if;
16407
16408 Ent := Find_Lib_Unit_Name;
16409 Check_Duplicate_Pragma (Ent);
16410
16411 -- This filters out pragmas inside generic parents that show up
16412 -- inside instantiations. Pragmas that come from aspects in the
16413 -- unit are not ignored.
16414
16415 if Present (Ent) then
16416 if Pk = N_Package_Specification
16417 and then Present (Generic_Parent (Pa))
16418 and then not From_Aspect_Specification (N)
16419 then
16420 null;
16421
16422 else
16423 if not Debug_Flag_U then
16424 Set_Is_Preelaborated (Ent);
16425 Set_Suppress_Elaboration_Warnings (Ent);
16426 end if;
16427 end if;
16428 end if;
16429 end Preelaborate;
16430
16431 ---------------------
16432 -- Preelaborate_05 --
16433 ---------------------
16434
16435 -- pragma Preelaborate_05 [(library_unit_NAME)];
16436
16437 -- This pragma is useable only in GNAT_Mode, where it is used like
16438 -- pragma Preelaborate but it is only effective in Ada 2005 mode
16439 -- (otherwise it is ignored). This is used to implement AI-362 which
16440 -- recategorizes some run-time packages in Ada 2005 mode.
16441
16442 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
16443 Ent : Entity_Id;
16444
16445 begin
16446 GNAT_Pragma;
16447 Check_Valid_Library_Unit_Pragma;
16448
16449 if not GNAT_Mode then
16450 Error_Pragma ("pragma% only available in GNAT mode");
16451 end if;
16452
16453 if Nkind (N) = N_Null_Statement then
16454 return;
16455 end if;
16456
16457 -- This is one of the few cases where we need to test the value of
16458 -- Ada_Version_Explicit rather than Ada_Version (which is always
16459 -- set to Ada_2012 in a predefined unit), we need to know the
16460 -- explicit version set to know if this pragma is active.
16461
16462 if Ada_Version_Explicit >= Ada_2005 then
16463 Ent := Find_Lib_Unit_Name;
16464 Set_Is_Preelaborated (Ent);
16465 Set_Suppress_Elaboration_Warnings (Ent);
16466 end if;
16467 end Preelaborate_05;
16468
16469 --------------
16470 -- Priority --
16471 --------------
16472
16473 -- pragma Priority (EXPRESSION);
16474
16475 when Pragma_Priority => Priority : declare
16476 P : constant Node_Id := Parent (N);
16477 Arg : Node_Id;
16478 Ent : Entity_Id;
16479
16480 begin
16481 Check_No_Identifiers;
16482 Check_Arg_Count (1);
16483
16484 -- Subprogram case
16485
16486 if Nkind (P) = N_Subprogram_Body then
16487 Check_In_Main_Program;
16488
16489 Ent := Defining_Unit_Name (Specification (P));
16490
16491 if Nkind (Ent) = N_Defining_Program_Unit_Name then
16492 Ent := Defining_Identifier (Ent);
16493 end if;
16494
16495 Arg := Get_Pragma_Arg (Arg1);
16496 Analyze_And_Resolve (Arg, Standard_Integer);
16497
16498 -- Must be static
16499
16500 if not Is_Static_Expression (Arg) then
16501 Flag_Non_Static_Expr
16502 ("main subprogram priority is not static!", Arg);
16503 raise Pragma_Exit;
16504
16505 -- If constraint error, then we already signalled an error
16506
16507 elsif Raises_Constraint_Error (Arg) then
16508 null;
16509
16510 -- Otherwise check in range
16511
16512 else
16513 declare
16514 Val : constant Uint := Expr_Value (Arg);
16515
16516 begin
16517 if Val < 0
16518 or else Val > Expr_Value (Expression
16519 (Parent (RTE (RE_Max_Priority))))
16520 then
16521 Error_Pragma_Arg
16522 ("main subprogram priority is out of range", Arg1);
16523 end if;
16524 end;
16525 end if;
16526
16527 Set_Main_Priority
16528 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
16529
16530 -- Load an arbitrary entity from System.Tasking.Stages or
16531 -- System.Tasking.Restricted.Stages (depending on the
16532 -- supported profile) to make sure that one of these packages
16533 -- is implicitly with'ed, since we need to have the tasking
16534 -- run time active for the pragma Priority to have any effect.
16535 -- Previously with with'ed the package System.Tasking, but
16536 -- this package does not trigger the required initialization
16537 -- of the run-time library.
16538
16539 declare
16540 Discard : Entity_Id;
16541 pragma Warnings (Off, Discard);
16542 begin
16543 if Restricted_Profile then
16544 Discard := RTE (RE_Activate_Restricted_Tasks);
16545 else
16546 Discard := RTE (RE_Activate_Tasks);
16547 end if;
16548 end;
16549
16550 -- Task or Protected, must be of type Integer
16551
16552 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
16553 Arg := Get_Pragma_Arg (Arg1);
16554 Ent := Defining_Identifier (Parent (P));
16555
16556 -- The expression must be analyzed in the special manner
16557 -- described in "Handling of Default and Per-Object
16558 -- Expressions" in sem.ads.
16559
16560 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
16561
16562 if not Is_Static_Expression (Arg) then
16563 Check_Restriction (Static_Priorities, Arg);
16564 end if;
16565
16566 -- Anything else is incorrect
16567
16568 else
16569 Pragma_Misplaced;
16570 end if;
16571
16572 -- Check duplicate pragma before we chain the pragma in the Rep
16573 -- Item chain of Ent.
16574
16575 Check_Duplicate_Pragma (Ent);
16576 Record_Rep_Item (Ent, N);
16577 end Priority;
16578
16579 -----------------------------------
16580 -- Priority_Specific_Dispatching --
16581 -----------------------------------
16582
16583 -- pragma Priority_Specific_Dispatching (
16584 -- policy_IDENTIFIER,
16585 -- first_priority_EXPRESSION,
16586 -- last_priority_EXPRESSION);
16587
16588 when Pragma_Priority_Specific_Dispatching =>
16589 Priority_Specific_Dispatching : declare
16590 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
16591 -- This is the entity System.Any_Priority;
16592
16593 DP : Character;
16594 Lower_Bound : Node_Id;
16595 Upper_Bound : Node_Id;
16596 Lower_Val : Uint;
16597 Upper_Val : Uint;
16598
16599 begin
16600 Ada_2005_Pragma;
16601 Check_Arg_Count (3);
16602 Check_No_Identifiers;
16603 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16604 Check_Valid_Configuration_Pragma;
16605 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16606 DP := Fold_Upper (Name_Buffer (1));
16607
16608 Lower_Bound := Get_Pragma_Arg (Arg2);
16609 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
16610 Lower_Val := Expr_Value (Lower_Bound);
16611
16612 Upper_Bound := Get_Pragma_Arg (Arg3);
16613 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
16614 Upper_Val := Expr_Value (Upper_Bound);
16615
16616 -- It is not allowed to use Task_Dispatching_Policy and
16617 -- Priority_Specific_Dispatching in the same partition.
16618
16619 if Task_Dispatching_Policy /= ' ' then
16620 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16621 Error_Pragma
16622 ("pragma% incompatible with Task_Dispatching_Policy#");
16623
16624 -- Check lower bound in range
16625
16626 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
16627 or else
16628 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
16629 then
16630 Error_Pragma_Arg
16631 ("first_priority is out of range", Arg2);
16632
16633 -- Check upper bound in range
16634
16635 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
16636 or else
16637 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
16638 then
16639 Error_Pragma_Arg
16640 ("last_priority is out of range", Arg3);
16641
16642 -- Check that the priority range is valid
16643
16644 elsif Lower_Val > Upper_Val then
16645 Error_Pragma
16646 ("last_priority_expression must be greater than or equal to "
16647 & "first_priority_expression");
16648
16649 -- Store the new policy, but always preserve System_Location since
16650 -- we like the error message with the run-time name.
16651
16652 else
16653 -- Check overlapping in the priority ranges specified in other
16654 -- Priority_Specific_Dispatching pragmas within the same
16655 -- partition. We can only check those we know about!
16656
16657 for J in
16658 Specific_Dispatching.First .. Specific_Dispatching.Last
16659 loop
16660 if Specific_Dispatching.Table (J).First_Priority in
16661 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
16662 or else Specific_Dispatching.Table (J).Last_Priority in
16663 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
16664 then
16665 Error_Msg_Sloc :=
16666 Specific_Dispatching.Table (J).Pragma_Loc;
16667 Error_Pragma
16668 ("priority range overlaps with "
16669 & "Priority_Specific_Dispatching#");
16670 end if;
16671 end loop;
16672
16673 -- The use of Priority_Specific_Dispatching is incompatible
16674 -- with Task_Dispatching_Policy.
16675
16676 if Task_Dispatching_Policy /= ' ' then
16677 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16678 Error_Pragma
16679 ("Priority_Specific_Dispatching incompatible "
16680 & "with Task_Dispatching_Policy#");
16681 end if;
16682
16683 -- The use of Priority_Specific_Dispatching forces ceiling
16684 -- locking policy.
16685
16686 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
16687 Error_Msg_Sloc := Locking_Policy_Sloc;
16688 Error_Pragma
16689 ("Priority_Specific_Dispatching incompatible "
16690 & "with Locking_Policy#");
16691
16692 -- Set the Ceiling_Locking policy, but preserve System_Location
16693 -- since we like the error message with the run time name.
16694
16695 else
16696 Locking_Policy := 'C';
16697
16698 if Locking_Policy_Sloc /= System_Location then
16699 Locking_Policy_Sloc := Loc;
16700 end if;
16701 end if;
16702
16703 -- Add entry in the table
16704
16705 Specific_Dispatching.Append
16706 ((Dispatching_Policy => DP,
16707 First_Priority => UI_To_Int (Lower_Val),
16708 Last_Priority => UI_To_Int (Upper_Val),
16709 Pragma_Loc => Loc));
16710 end if;
16711 end Priority_Specific_Dispatching;
16712
16713 -------------
16714 -- Profile --
16715 -------------
16716
16717 -- pragma Profile (profile_IDENTIFIER);
16718
16719 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
16720
16721 when Pragma_Profile =>
16722 Ada_2005_Pragma;
16723 Check_Arg_Count (1);
16724 Check_Valid_Configuration_Pragma;
16725 Check_No_Identifiers;
16726
16727 declare
16728 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
16729
16730 begin
16731 if Chars (Argx) = Name_Ravenscar then
16732 Set_Ravenscar_Profile (N);
16733
16734 elsif Chars (Argx) = Name_Restricted then
16735 Set_Profile_Restrictions
16736 (Restricted,
16737 N, Warn => Treat_Restrictions_As_Warnings);
16738
16739 elsif Chars (Argx) = Name_Rational then
16740 Set_Rational_Profile;
16741
16742 elsif Chars (Argx) = Name_No_Implementation_Extensions then
16743 Set_Profile_Restrictions
16744 (No_Implementation_Extensions,
16745 N, Warn => Treat_Restrictions_As_Warnings);
16746
16747 else
16748 Error_Pragma_Arg ("& is not a valid profile", Argx);
16749 end if;
16750 end;
16751
16752 ----------------------
16753 -- Profile_Warnings --
16754 ----------------------
16755
16756 -- pragma Profile_Warnings (profile_IDENTIFIER);
16757
16758 -- profile_IDENTIFIER => Restricted | Ravenscar
16759
16760 when Pragma_Profile_Warnings =>
16761 GNAT_Pragma;
16762 Check_Arg_Count (1);
16763 Check_Valid_Configuration_Pragma;
16764 Check_No_Identifiers;
16765
16766 declare
16767 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
16768
16769 begin
16770 if Chars (Argx) = Name_Ravenscar then
16771 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
16772
16773 elsif Chars (Argx) = Name_Restricted then
16774 Set_Profile_Restrictions (Restricted, N, Warn => True);
16775
16776 elsif Chars (Argx) = Name_No_Implementation_Extensions then
16777 Set_Profile_Restrictions
16778 (No_Implementation_Extensions, N, Warn => True);
16779
16780 else
16781 Error_Pragma_Arg ("& is not a valid profile", Argx);
16782 end if;
16783 end;
16784
16785 --------------------------
16786 -- Propagate_Exceptions --
16787 --------------------------
16788
16789 -- pragma Propagate_Exceptions;
16790
16791 -- Note: this pragma is obsolete and has no effect
16792
16793 when Pragma_Propagate_Exceptions =>
16794 GNAT_Pragma;
16795 Check_Arg_Count (0);
16796
16797 if Warn_On_Obsolescent_Feature then
16798 Error_Msg_N
16799 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
16800 "and has no effect?j?", N);
16801 end if;
16802
16803 ------------------
16804 -- Psect_Object --
16805 ------------------
16806
16807 -- pragma Psect_Object (
16808 -- [Internal =>] LOCAL_NAME,
16809 -- [, [External =>] EXTERNAL_SYMBOL]
16810 -- [, [Size =>] EXTERNAL_SYMBOL]);
16811
16812 when Pragma_Psect_Object | Pragma_Common_Object =>
16813 Psect_Object : declare
16814 Args : Args_List (1 .. 3);
16815 Names : constant Name_List (1 .. 3) := (
16816 Name_Internal,
16817 Name_External,
16818 Name_Size);
16819
16820 Internal : Node_Id renames Args (1);
16821 External : Node_Id renames Args (2);
16822 Size : Node_Id renames Args (3);
16823
16824 Def_Id : Entity_Id;
16825
16826 procedure Check_Too_Long (Arg : Node_Id);
16827 -- Posts message if the argument is an identifier with more
16828 -- than 31 characters, or a string literal with more than
16829 -- 31 characters, and we are operating under VMS
16830
16831 --------------------
16832 -- Check_Too_Long --
16833 --------------------
16834
16835 procedure Check_Too_Long (Arg : Node_Id) is
16836 X : constant Node_Id := Original_Node (Arg);
16837
16838 begin
16839 if not Nkind_In (X, N_String_Literal, N_Identifier) then
16840 Error_Pragma_Arg
16841 ("inappropriate argument for pragma %", Arg);
16842 end if;
16843
16844 if OpenVMS_On_Target then
16845 if (Nkind (X) = N_String_Literal
16846 and then String_Length (Strval (X)) > 31)
16847 or else
16848 (Nkind (X) = N_Identifier
16849 and then Length_Of_Name (Chars (X)) > 31)
16850 then
16851 Error_Pragma_Arg
16852 ("argument for pragma % is longer than 31 characters",
16853 Arg);
16854 end if;
16855 end if;
16856 end Check_Too_Long;
16857
16858 -- Start of processing for Common_Object/Psect_Object
16859
16860 begin
16861 GNAT_Pragma;
16862 Gather_Associations (Names, Args);
16863 Process_Extended_Import_Export_Internal_Arg (Internal);
16864
16865 Def_Id := Entity (Internal);
16866
16867 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
16868 Error_Pragma_Arg
16869 ("pragma% must designate an object", Internal);
16870 end if;
16871
16872 Check_Too_Long (Internal);
16873
16874 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
16875 Error_Pragma_Arg
16876 ("cannot use pragma% for imported/exported object",
16877 Internal);
16878 end if;
16879
16880 if Is_Concurrent_Type (Etype (Internal)) then
16881 Error_Pragma_Arg
16882 ("cannot specify pragma % for task/protected object",
16883 Internal);
16884 end if;
16885
16886 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
16887 or else
16888 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
16889 then
16890 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
16891 end if;
16892
16893 if Ekind (Def_Id) = E_Constant then
16894 Error_Pragma_Arg
16895 ("cannot specify pragma % for a constant", Internal);
16896 end if;
16897
16898 if Is_Record_Type (Etype (Internal)) then
16899 declare
16900 Ent : Entity_Id;
16901 Decl : Entity_Id;
16902
16903 begin
16904 Ent := First_Entity (Etype (Internal));
16905 while Present (Ent) loop
16906 Decl := Declaration_Node (Ent);
16907
16908 if Ekind (Ent) = E_Component
16909 and then Nkind (Decl) = N_Component_Declaration
16910 and then Present (Expression (Decl))
16911 and then Warn_On_Export_Import
16912 then
16913 Error_Msg_N
16914 ("?x?object for pragma % has defaults", Internal);
16915 exit;
16916
16917 else
16918 Next_Entity (Ent);
16919 end if;
16920 end loop;
16921 end;
16922 end if;
16923
16924 if Present (Size) then
16925 Check_Too_Long (Size);
16926 end if;
16927
16928 if Present (External) then
16929 Check_Arg_Is_External_Name (External);
16930 Check_Too_Long (External);
16931 end if;
16932
16933 -- If all error tests pass, link pragma on to the rep item chain
16934
16935 Record_Rep_Item (Def_Id, N);
16936 end Psect_Object;
16937
16938 ----------
16939 -- Pure --
16940 ----------
16941
16942 -- pragma Pure [(library_unit_NAME)];
16943
16944 when Pragma_Pure => Pure : declare
16945 Ent : Entity_Id;
16946
16947 begin
16948 Check_Ada_83_Warning;
16949 Check_Valid_Library_Unit_Pragma;
16950
16951 if Nkind (N) = N_Null_Statement then
16952 return;
16953 end if;
16954
16955 Ent := Find_Lib_Unit_Name;
16956 Set_Is_Pure (Ent);
16957 Set_Has_Pragma_Pure (Ent);
16958 Set_Suppress_Elaboration_Warnings (Ent);
16959 end Pure;
16960
16961 -------------
16962 -- Pure_05 --
16963 -------------
16964
16965 -- pragma Pure_05 [(library_unit_NAME)];
16966
16967 -- This pragma is useable only in GNAT_Mode, where it is used like
16968 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
16969 -- it is ignored). It may be used after a pragma Preelaborate, in
16970 -- which case it overrides the effect of the pragma Preelaborate.
16971 -- This is used to implement AI-362 which recategorizes some run-time
16972 -- packages in Ada 2005 mode.
16973
16974 when Pragma_Pure_05 => Pure_05 : declare
16975 Ent : Entity_Id;
16976
16977 begin
16978 GNAT_Pragma;
16979 Check_Valid_Library_Unit_Pragma;
16980
16981 if not GNAT_Mode then
16982 Error_Pragma ("pragma% only available in GNAT mode");
16983 end if;
16984
16985 if Nkind (N) = N_Null_Statement then
16986 return;
16987 end if;
16988
16989 -- This is one of the few cases where we need to test the value of
16990 -- Ada_Version_Explicit rather than Ada_Version (which is always
16991 -- set to Ada_2012 in a predefined unit), we need to know the
16992 -- explicit version set to know if this pragma is active.
16993
16994 if Ada_Version_Explicit >= Ada_2005 then
16995 Ent := Find_Lib_Unit_Name;
16996 Set_Is_Preelaborated (Ent, False);
16997 Set_Is_Pure (Ent);
16998 Set_Suppress_Elaboration_Warnings (Ent);
16999 end if;
17000 end Pure_05;
17001
17002 -------------
17003 -- Pure_12 --
17004 -------------
17005
17006 -- pragma Pure_12 [(library_unit_NAME)];
17007
17008 -- This pragma is useable only in GNAT_Mode, where it is used like
17009 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
17010 -- it is ignored). It may be used after a pragma Preelaborate, in
17011 -- which case it overrides the effect of the pragma Preelaborate.
17012 -- This is used to implement AI05-0212 which recategorizes some
17013 -- run-time packages in Ada 2012 mode.
17014
17015 when Pragma_Pure_12 => Pure_12 : declare
17016 Ent : Entity_Id;
17017
17018 begin
17019 GNAT_Pragma;
17020 Check_Valid_Library_Unit_Pragma;
17021
17022 if not GNAT_Mode then
17023 Error_Pragma ("pragma% only available in GNAT mode");
17024 end if;
17025
17026 if Nkind (N) = N_Null_Statement then
17027 return;
17028 end if;
17029
17030 -- This is one of the few cases where we need to test the value of
17031 -- Ada_Version_Explicit rather than Ada_Version (which is always
17032 -- set to Ada_2012 in a predefined unit), we need to know the
17033 -- explicit version set to know if this pragma is active.
17034
17035 if Ada_Version_Explicit >= Ada_2012 then
17036 Ent := Find_Lib_Unit_Name;
17037 Set_Is_Preelaborated (Ent, False);
17038 Set_Is_Pure (Ent);
17039 Set_Suppress_Elaboration_Warnings (Ent);
17040 end if;
17041 end Pure_12;
17042
17043 -------------------
17044 -- Pure_Function --
17045 -------------------
17046
17047 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
17048
17049 when Pragma_Pure_Function => Pure_Function : declare
17050 E_Id : Node_Id;
17051 E : Entity_Id;
17052 Def_Id : Entity_Id;
17053 Effective : Boolean := False;
17054
17055 begin
17056 GNAT_Pragma;
17057 Check_Arg_Count (1);
17058 Check_Optional_Identifier (Arg1, Name_Entity);
17059 Check_Arg_Is_Local_Name (Arg1);
17060 E_Id := Get_Pragma_Arg (Arg1);
17061
17062 if Error_Posted (E_Id) then
17063 return;
17064 end if;
17065
17066 -- Loop through homonyms (overloadings) of referenced entity
17067
17068 E := Entity (E_Id);
17069
17070 if Present (E) then
17071 loop
17072 Def_Id := Get_Base_Subprogram (E);
17073
17074 if not Ekind_In (Def_Id, E_Function,
17075 E_Generic_Function,
17076 E_Operator)
17077 then
17078 Error_Pragma_Arg
17079 ("pragma% requires a function name", Arg1);
17080 end if;
17081
17082 Set_Is_Pure (Def_Id);
17083
17084 if not Has_Pragma_Pure_Function (Def_Id) then
17085 Set_Has_Pragma_Pure_Function (Def_Id);
17086 Effective := True;
17087 end if;
17088
17089 exit when From_Aspect_Specification (N);
17090 E := Homonym (E);
17091 exit when No (E) or else Scope (E) /= Current_Scope;
17092 end loop;
17093
17094 if not Effective
17095 and then Warn_On_Redundant_Constructs
17096 then
17097 Error_Msg_NE
17098 ("pragma Pure_Function on& is redundant?r?",
17099 N, Entity (E_Id));
17100 end if;
17101 end if;
17102 end Pure_Function;
17103
17104 --------------------
17105 -- Queuing_Policy --
17106 --------------------
17107
17108 -- pragma Queuing_Policy (policy_IDENTIFIER);
17109
17110 when Pragma_Queuing_Policy => declare
17111 QP : Character;
17112
17113 begin
17114 Check_Ada_83_Warning;
17115 Check_Arg_Count (1);
17116 Check_No_Identifiers;
17117 Check_Arg_Is_Queuing_Policy (Arg1);
17118 Check_Valid_Configuration_Pragma;
17119 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
17120 QP := Fold_Upper (Name_Buffer (1));
17121
17122 if Queuing_Policy /= ' '
17123 and then Queuing_Policy /= QP
17124 then
17125 Error_Msg_Sloc := Queuing_Policy_Sloc;
17126 Error_Pragma ("queuing policy incompatible with policy#");
17127
17128 -- Set new policy, but always preserve System_Location since we
17129 -- like the error message with the run time name.
17130
17131 else
17132 Queuing_Policy := QP;
17133
17134 if Queuing_Policy_Sloc /= System_Location then
17135 Queuing_Policy_Sloc := Loc;
17136 end if;
17137 end if;
17138 end;
17139
17140 --------------
17141 -- Rational --
17142 --------------
17143
17144 -- pragma Rational, for compatibility with foreign compiler
17145
17146 when Pragma_Rational =>
17147 Set_Rational_Profile;
17148
17149 ------------------------------------
17150 -- Refined_Depends/Refined_Global --
17151 ------------------------------------
17152
17153 -- pragma Refined_Depends (DEPENDENCY_RELATION);
17154
17155 -- DEPENDENCY_RELATION ::=
17156 -- null
17157 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
17158
17159 -- DEPENDENCY_CLAUSE ::=
17160 -- OUTPUT_LIST =>[+] INPUT_LIST
17161 -- | NULL_DEPENDENCY_CLAUSE
17162
17163 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
17164
17165 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
17166
17167 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
17168
17169 -- OUTPUT ::= NAME | FUNCTION_RESULT
17170 -- INPUT ::= NAME
17171
17172 -- where FUNCTION_RESULT is a function Result attribute_reference
17173
17174 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
17175
17176 -- GLOBAL_SPECIFICATION ::=
17177 -- null
17178 -- | GLOBAL_LIST
17179 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
17180
17181 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
17182
17183 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
17184 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
17185 -- GLOBAL_ITEM ::= NAME
17186
17187 when Pragma_Refined_Depends |
17188 Pragma_Refined_Global => Refined_Depends_Global :
17189 declare
17190 Body_Id : Entity_Id;
17191 Legal : Boolean;
17192 Spec_Id : Entity_Id;
17193
17194 begin
17195 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
17196
17197 -- Save the pragma in the contract of the subprogram body. The
17198 -- remaining analysis is performed at the end of the enclosing
17199 -- declarations.
17200
17201 if Legal then
17202 Add_Contract_Item (N, Body_Id);
17203 end if;
17204 end Refined_Depends_Global;
17205
17206 ------------------
17207 -- Refined_Post --
17208 ------------------
17209
17210 -- pragma Refined_Post (boolean_EXPRESSION);
17211
17212 when Pragma_Refined_Post => Refined_Post : declare
17213 Body_Id : Entity_Id;
17214 Legal : Boolean;
17215 Spec_Id : Entity_Id;
17216
17217 begin
17218 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
17219
17220 -- Analyze the boolean expression as a "spec expression"
17221
17222 if Legal then
17223 Analyze_Pre_Post_Condition_In_Decl_Part (N, Spec_Id);
17224 end if;
17225 end Refined_Post;
17226
17227 -------------------
17228 -- Refined_State --
17229 -------------------
17230
17231 -- pragma Refined_State (REFINEMENT_LIST);
17232
17233 -- REFINEMENT_LIST ::=
17234 -- REFINEMENT_CLAUSE
17235 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
17236
17237 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
17238
17239 -- CONSTITUENT_LIST ::=
17240 -- null
17241 -- | CONSTITUENT
17242 -- | (CONSTITUENT {, CONSTITUENT})
17243
17244 -- CONSTITUENT ::= object_NAME | state_NAME
17245
17246 when Pragma_Refined_State => Refined_State : declare
17247 Context : constant Node_Id := Parent (N);
17248 Spec_Id : Entity_Id;
17249 Stmt : Node_Id;
17250
17251 begin
17252 GNAT_Pragma;
17253 S14_Pragma;
17254 Check_Arg_Count (1);
17255
17256 -- Ensure the proper placement of the pragma. Refined states must
17257 -- be associated with a package body.
17258
17259 if Nkind (Context) /= N_Package_Body then
17260 Pragma_Misplaced;
17261 return;
17262 end if;
17263
17264 Stmt := Prev (N);
17265 while Present (Stmt) loop
17266
17267 -- Skip prior pragmas, but check for duplicates
17268
17269 if Nkind (Stmt) = N_Pragma then
17270 if Pragma_Name (Stmt) = Pname then
17271 Error_Msg_Name_1 := Pname;
17272 Error_Msg_Sloc := Sloc (Stmt);
17273 Error_Msg_N ("pragma % duplicates pragma declared #", N);
17274 end if;
17275
17276 -- Skip internally generated code
17277
17278 elsif not Comes_From_Source (Stmt) then
17279 null;
17280
17281 -- The pragma does not apply to a legal construct, issue an
17282 -- error and stop the analysis.
17283
17284 else
17285 Pragma_Misplaced;
17286 return;
17287 end if;
17288
17289 Stmt := Prev (Stmt);
17290 end loop;
17291
17292 -- State refinement is allowed only when the corresponding package
17293 -- declaration has a non-null pragma Abstract_State.
17294
17295 Spec_Id := Corresponding_Spec (Context);
17296
17297 if No (Abstract_States (Spec_Id))
17298 or else Has_Null_Abstract_State (Spec_Id)
17299 then
17300 Error_Msg_NE
17301 ("useless refinement, package & does not define abstract "
17302 & "states", N, Spec_Id);
17303 return;
17304 end if;
17305
17306 -- The pragma must be analyzed at the end of the declarations as
17307 -- it has visibility over the whole declarative region. Save the
17308 -- pragma for later (see Analyze_Refined_Depends_In_Decl_Part) by
17309 -- adding it to the contract of the package body.
17310
17311 Add_Contract_Item (N, Defining_Entity (Context));
17312 end Refined_State;
17313
17314 -----------------------
17315 -- Relative_Deadline --
17316 -----------------------
17317
17318 -- pragma Relative_Deadline (time_span_EXPRESSION);
17319
17320 when Pragma_Relative_Deadline => Relative_Deadline : declare
17321 P : constant Node_Id := Parent (N);
17322 Arg : Node_Id;
17323
17324 begin
17325 Ada_2005_Pragma;
17326 Check_No_Identifiers;
17327 Check_Arg_Count (1);
17328
17329 Arg := Get_Pragma_Arg (Arg1);
17330
17331 -- The expression must be analyzed in the special manner described
17332 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
17333
17334 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
17335
17336 -- Subprogram case
17337
17338 if Nkind (P) = N_Subprogram_Body then
17339 Check_In_Main_Program;
17340
17341 -- Only Task and subprogram cases allowed
17342
17343 elsif Nkind (P) /= N_Task_Definition then
17344 Pragma_Misplaced;
17345 end if;
17346
17347 -- Check duplicate pragma before we set the corresponding flag
17348
17349 if Has_Relative_Deadline_Pragma (P) then
17350 Error_Pragma ("duplicate pragma% not allowed");
17351 end if;
17352
17353 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
17354 -- Relative_Deadline pragma node cannot be inserted in the Rep
17355 -- Item chain of Ent since it is rewritten by the expander as a
17356 -- procedure call statement that will break the chain.
17357
17358 Set_Has_Relative_Deadline_Pragma (P, True);
17359 end Relative_Deadline;
17360
17361 ------------------------
17362 -- Remote_Access_Type --
17363 ------------------------
17364
17365 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
17366
17367 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
17368 E : Entity_Id;
17369
17370 begin
17371 GNAT_Pragma;
17372 Check_Arg_Count (1);
17373 Check_Optional_Identifier (Arg1, Name_Entity);
17374 Check_Arg_Is_Local_Name (Arg1);
17375
17376 E := Entity (Get_Pragma_Arg (Arg1));
17377
17378 if Nkind (Parent (E)) = N_Formal_Type_Declaration
17379 and then Ekind (E) = E_General_Access_Type
17380 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
17381 and then Scope (Root_Type (Directly_Designated_Type (E)))
17382 = Scope (E)
17383 and then Is_Valid_Remote_Object_Type
17384 (Root_Type (Directly_Designated_Type (E)))
17385 then
17386 Set_Is_Remote_Types (E);
17387
17388 else
17389 Error_Pragma_Arg
17390 ("pragma% applies only to formal access to classwide types",
17391 Arg1);
17392 end if;
17393 end Remote_Access_Type;
17394
17395 ---------------------------
17396 -- Remote_Call_Interface --
17397 ---------------------------
17398
17399 -- pragma Remote_Call_Interface [(library_unit_NAME)];
17400
17401 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
17402 Cunit_Node : Node_Id;
17403 Cunit_Ent : Entity_Id;
17404 K : Node_Kind;
17405
17406 begin
17407 Check_Ada_83_Warning;
17408 Check_Valid_Library_Unit_Pragma;
17409
17410 if Nkind (N) = N_Null_Statement then
17411 return;
17412 end if;
17413
17414 Cunit_Node := Cunit (Current_Sem_Unit);
17415 K := Nkind (Unit (Cunit_Node));
17416 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
17417
17418 if K = N_Package_Declaration
17419 or else K = N_Generic_Package_Declaration
17420 or else K = N_Subprogram_Declaration
17421 or else K = N_Generic_Subprogram_Declaration
17422 or else (K = N_Subprogram_Body
17423 and then Acts_As_Spec (Unit (Cunit_Node)))
17424 then
17425 null;
17426 else
17427 Error_Pragma (
17428 "pragma% must apply to package or subprogram declaration");
17429 end if;
17430
17431 Set_Is_Remote_Call_Interface (Cunit_Ent);
17432 end Remote_Call_Interface;
17433
17434 ------------------
17435 -- Remote_Types --
17436 ------------------
17437
17438 -- pragma Remote_Types [(library_unit_NAME)];
17439
17440 when Pragma_Remote_Types => Remote_Types : declare
17441 Cunit_Node : Node_Id;
17442 Cunit_Ent : Entity_Id;
17443
17444 begin
17445 Check_Ada_83_Warning;
17446 Check_Valid_Library_Unit_Pragma;
17447
17448 if Nkind (N) = N_Null_Statement then
17449 return;
17450 end if;
17451
17452 Cunit_Node := Cunit (Current_Sem_Unit);
17453 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
17454
17455 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
17456 N_Generic_Package_Declaration)
17457 then
17458 Error_Pragma
17459 ("pragma% can only apply to a package declaration");
17460 end if;
17461
17462 Set_Is_Remote_Types (Cunit_Ent);
17463 end Remote_Types;
17464
17465 ---------------
17466 -- Ravenscar --
17467 ---------------
17468
17469 -- pragma Ravenscar;
17470
17471 when Pragma_Ravenscar =>
17472 GNAT_Pragma;
17473 Check_Arg_Count (0);
17474 Check_Valid_Configuration_Pragma;
17475 Set_Ravenscar_Profile (N);
17476
17477 if Warn_On_Obsolescent_Feature then
17478 Error_Msg_N
17479 ("pragma Ravenscar is an obsolescent feature?j?", N);
17480 Error_Msg_N
17481 ("|use pragma Profile (Ravenscar) instead?j?", N);
17482 end if;
17483
17484 -------------------------
17485 -- Restricted_Run_Time --
17486 -------------------------
17487
17488 -- pragma Restricted_Run_Time;
17489
17490 when Pragma_Restricted_Run_Time =>
17491 GNAT_Pragma;
17492 Check_Arg_Count (0);
17493 Check_Valid_Configuration_Pragma;
17494 Set_Profile_Restrictions
17495 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
17496
17497 if Warn_On_Obsolescent_Feature then
17498 Error_Msg_N
17499 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
17500 N);
17501 Error_Msg_N
17502 ("|use pragma Profile (Restricted) instead?j?", N);
17503 end if;
17504
17505 ------------------
17506 -- Restrictions --
17507 ------------------
17508
17509 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
17510
17511 -- RESTRICTION ::=
17512 -- restriction_IDENTIFIER
17513 -- | restriction_parameter_IDENTIFIER => EXPRESSION
17514
17515 when Pragma_Restrictions =>
17516 Process_Restrictions_Or_Restriction_Warnings
17517 (Warn => Treat_Restrictions_As_Warnings);
17518
17519 --------------------------
17520 -- Restriction_Warnings --
17521 --------------------------
17522
17523 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
17524
17525 -- RESTRICTION ::=
17526 -- restriction_IDENTIFIER
17527 -- | restriction_parameter_IDENTIFIER => EXPRESSION
17528
17529 when Pragma_Restriction_Warnings =>
17530 GNAT_Pragma;
17531 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
17532
17533 ----------------
17534 -- Reviewable --
17535 ----------------
17536
17537 -- pragma Reviewable;
17538
17539 when Pragma_Reviewable =>
17540 Check_Ada_83_Warning;
17541 Check_Arg_Count (0);
17542
17543 -- Call dummy debugging function rv. This is done to assist front
17544 -- end debugging. By placing a Reviewable pragma in the source
17545 -- program, a breakpoint on rv catches this place in the source,
17546 -- allowing convenient stepping to the point of interest.
17547
17548 rv;
17549
17550 --------------------------
17551 -- Short_Circuit_And_Or --
17552 --------------------------
17553
17554 -- pragma Short_Circuit_And_Or;
17555
17556 when Pragma_Short_Circuit_And_Or =>
17557 GNAT_Pragma;
17558 Check_Arg_Count (0);
17559 Check_Valid_Configuration_Pragma;
17560 Short_Circuit_And_Or := True;
17561
17562 -------------------
17563 -- Share_Generic --
17564 -------------------
17565
17566 -- pragma Share_Generic (GNAME {, GNAME});
17567
17568 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
17569
17570 when Pragma_Share_Generic =>
17571 GNAT_Pragma;
17572 Process_Generic_List;
17573
17574 ------------
17575 -- Shared --
17576 ------------
17577
17578 -- pragma Shared (LOCAL_NAME);
17579
17580 when Pragma_Shared =>
17581 GNAT_Pragma;
17582 Process_Atomic_Shared_Volatile;
17583
17584 --------------------
17585 -- Shared_Passive --
17586 --------------------
17587
17588 -- pragma Shared_Passive [(library_unit_NAME)];
17589
17590 -- Set the flag Is_Shared_Passive of program unit name entity
17591
17592 when Pragma_Shared_Passive => Shared_Passive : declare
17593 Cunit_Node : Node_Id;
17594 Cunit_Ent : Entity_Id;
17595
17596 begin
17597 Check_Ada_83_Warning;
17598 Check_Valid_Library_Unit_Pragma;
17599
17600 if Nkind (N) = N_Null_Statement then
17601 return;
17602 end if;
17603
17604 Cunit_Node := Cunit (Current_Sem_Unit);
17605 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
17606
17607 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
17608 N_Generic_Package_Declaration)
17609 then
17610 Error_Pragma
17611 ("pragma% can only apply to a package declaration");
17612 end if;
17613
17614 Set_Is_Shared_Passive (Cunit_Ent);
17615 end Shared_Passive;
17616
17617 -----------------------
17618 -- Short_Descriptors --
17619 -----------------------
17620
17621 -- pragma Short_Descriptors;
17622
17623 when Pragma_Short_Descriptors =>
17624 GNAT_Pragma;
17625 Check_Arg_Count (0);
17626 Check_Valid_Configuration_Pragma;
17627 Short_Descriptors := True;
17628
17629 ------------------------------
17630 -- Simple_Storage_Pool_Type --
17631 ------------------------------
17632
17633 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
17634
17635 when Pragma_Simple_Storage_Pool_Type =>
17636 Simple_Storage_Pool_Type : declare
17637 Type_Id : Node_Id;
17638 Typ : Entity_Id;
17639
17640 begin
17641 GNAT_Pragma;
17642 Check_Arg_Count (1);
17643 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17644
17645 Type_Id := Get_Pragma_Arg (Arg1);
17646 Find_Type (Type_Id);
17647 Typ := Entity (Type_Id);
17648
17649 if Typ = Any_Type then
17650 return;
17651 end if;
17652
17653 -- We require the pragma to apply to a type declared in a package
17654 -- declaration, but not (immediately) within a package body.
17655
17656 if Ekind (Current_Scope) /= E_Package
17657 or else In_Package_Body (Current_Scope)
17658 then
17659 Error_Pragma
17660 ("pragma% can only apply to type declared immediately "
17661 & "within a package declaration");
17662 end if;
17663
17664 -- A simple storage pool type must be an immutably limited record
17665 -- or private type. If the pragma is given for a private type,
17666 -- the full type is similarly restricted (which is checked later
17667 -- in Freeze_Entity).
17668
17669 if Is_Record_Type (Typ)
17670 and then not Is_Limited_View (Typ)
17671 then
17672 Error_Pragma
17673 ("pragma% can only apply to explicitly limited record type");
17674
17675 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
17676 Error_Pragma
17677 ("pragma% can only apply to a private type that is limited");
17678
17679 elsif not Is_Record_Type (Typ)
17680 and then not Is_Private_Type (Typ)
17681 then
17682 Error_Pragma
17683 ("pragma% can only apply to limited record or private type");
17684 end if;
17685
17686 Record_Rep_Item (Typ, N);
17687 end Simple_Storage_Pool_Type;
17688
17689 ----------------------
17690 -- Source_File_Name --
17691 ----------------------
17692
17693 -- There are five forms for this pragma:
17694
17695 -- pragma Source_File_Name (
17696 -- [UNIT_NAME =>] unit_NAME,
17697 -- BODY_FILE_NAME => STRING_LITERAL
17698 -- [, [INDEX =>] INTEGER_LITERAL]);
17699
17700 -- pragma Source_File_Name (
17701 -- [UNIT_NAME =>] unit_NAME,
17702 -- SPEC_FILE_NAME => STRING_LITERAL
17703 -- [, [INDEX =>] INTEGER_LITERAL]);
17704
17705 -- pragma Source_File_Name (
17706 -- BODY_FILE_NAME => STRING_LITERAL
17707 -- [, DOT_REPLACEMENT => STRING_LITERAL]
17708 -- [, CASING => CASING_SPEC]);
17709
17710 -- pragma Source_File_Name (
17711 -- SPEC_FILE_NAME => STRING_LITERAL
17712 -- [, DOT_REPLACEMENT => STRING_LITERAL]
17713 -- [, CASING => CASING_SPEC]);
17714
17715 -- pragma Source_File_Name (
17716 -- SUBUNIT_FILE_NAME => STRING_LITERAL
17717 -- [, DOT_REPLACEMENT => STRING_LITERAL]
17718 -- [, CASING => CASING_SPEC]);
17719
17720 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
17721
17722 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
17723 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
17724 -- only be used when no project file is used, while SFNP can only be
17725 -- used when a project file is used.
17726
17727 -- No processing here. Processing was completed during parsing, since
17728 -- we need to have file names set as early as possible. Units are
17729 -- loaded well before semantic processing starts.
17730
17731 -- The only processing we defer to this point is the check for
17732 -- correct placement.
17733
17734 when Pragma_Source_File_Name =>
17735 GNAT_Pragma;
17736 Check_Valid_Configuration_Pragma;
17737
17738 ------------------------------
17739 -- Source_File_Name_Project --
17740 ------------------------------
17741
17742 -- See Source_File_Name for syntax
17743
17744 -- No processing here. Processing was completed during parsing, since
17745 -- we need to have file names set as early as possible. Units are
17746 -- loaded well before semantic processing starts.
17747
17748 -- The only processing we defer to this point is the check for
17749 -- correct placement.
17750
17751 when Pragma_Source_File_Name_Project =>
17752 GNAT_Pragma;
17753 Check_Valid_Configuration_Pragma;
17754
17755 -- Check that a pragma Source_File_Name_Project is used only in a
17756 -- configuration pragmas file.
17757
17758 -- Pragmas Source_File_Name_Project should only be generated by
17759 -- the Project Manager in configuration pragmas files.
17760
17761 -- This is really an ugly test. It seems to depend on some
17762 -- accidental and undocumented property. At the very least it
17763 -- needs to be documented, but it would be better to have a
17764 -- clean way of testing if we are in a configuration file???
17765
17766 if Present (Parent (N)) then
17767 Error_Pragma
17768 ("pragma% can only appear in a configuration pragmas file");
17769 end if;
17770
17771 ----------------------
17772 -- Source_Reference --
17773 ----------------------
17774
17775 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
17776
17777 -- Nothing to do, all processing completed in Par.Prag, since we need
17778 -- the information for possible parser messages that are output.
17779
17780 when Pragma_Source_Reference =>
17781 GNAT_Pragma;
17782
17783 ----------------
17784 -- SPARK_Mode --
17785 ----------------
17786
17787 -- pragma SPARK_Mode [(On | Off | Auto)];
17788
17789 when Pragma_SPARK_Mode => SPARK_Mod : declare
17790 procedure Chain_Pragma (Context : Entity_Id; Prag : Node_Id);
17791 -- Associate a SPARK_Mode pragma with the context where it lives.
17792 -- If the context is a package spec or a body, the routine checks
17793 -- the consistency between modes of visible/private declarations
17794 -- and body declarations/statements.
17795
17796 procedure Check_Spark_Mode_Conformance
17797 (Governing_Id : Entity_Id;
17798 New_Id : Entity_Id);
17799 -- Verify the "monotonicity" of SPARK modes between two entities.
17800 -- The order of modes is Off < Auto < On. Governing_Id establishes
17801 -- the mode of the context. New_Id attempts to redefine the known
17802 -- mode.
17803
17804 procedure Check_Pragma_Conformance
17805 (Governing_Mode : Node_Id;
17806 New_Mode : Node_Id);
17807 -- Verify the "monotonicity" of two SPARK_Mode pragmas. The order
17808 -- of modes is Off < Auto < On. Governing_Mode is the established
17809 -- mode dictated by the context. New_Mode attempts to redefine the
17810 -- governing mode.
17811
17812 function Get_SPARK_Mode_Name (Id : SPARK_Mode_Id) return Name_Id;
17813 -- Convert a value of type SPARK_Mode_Id into a corresponding name
17814
17815 ------------------
17816 -- Chain_Pragma --
17817 ------------------
17818
17819 procedure Chain_Pragma (Context : Entity_Id; Prag : Node_Id) is
17820 Existing_Prag : constant Node_Id :=
17821 SPARK_Mode_Pragmas (Context);
17822 begin
17823 -- The context does not have a prior mode defined
17824
17825 if No (Existing_Prag) then
17826 Set_SPARK_Mode_Pragmas (Context, Prag);
17827
17828 -- Chain the new mode on the list of SPARK_Mode pragmas. Verify
17829 -- the consistency between the existing mode and the new one.
17830
17831 else
17832 Set_Next_Pragma (Existing_Prag, Prag);
17833
17834 Check_Pragma_Conformance
17835 (Governing_Mode => Existing_Prag,
17836 New_Mode => Prag);
17837 end if;
17838 end Chain_Pragma;
17839
17840 ----------------------------------
17841 -- Check_Spark_Mode_Conformance --
17842 ----------------------------------
17843
17844 procedure Check_Spark_Mode_Conformance
17845 (Governing_Id : Entity_Id;
17846 New_Id : Entity_Id)
17847 is
17848 Gov_Prag : constant Node_Id :=
17849 SPARK_Mode_Pragmas (Governing_Id);
17850 New_Prag : constant Node_Id := SPARK_Mode_Pragmas (New_Id);
17851
17852 begin
17853 -- Nothing to do when one or both entities lack a mode
17854
17855 if No (Gov_Prag) or else No (New_Prag) then
17856 return;
17857 end if;
17858
17859 -- Do not compare the modes of a package spec and body when the
17860 -- spec mode appears in the private part. In this case the spec
17861 -- mode does not affect the body.
17862
17863 if Ekind_In (Governing_Id, E_Generic_Package, E_Package)
17864 and then Ekind (New_Id) = E_Package_Body
17865 and then Is_Private_SPARK_Mode (Gov_Prag)
17866 then
17867 null;
17868
17869 -- Test the pragmas
17870
17871 else
17872 Check_Pragma_Conformance
17873 (Governing_Mode => Gov_Prag,
17874 New_Mode => New_Prag);
17875 end if;
17876 end Check_Spark_Mode_Conformance;
17877
17878 ------------------------------
17879 -- Check_Pragma_Conformance --
17880 ------------------------------
17881
17882 procedure Check_Pragma_Conformance
17883 (Governing_Mode : Node_Id;
17884 New_Mode : Node_Id)
17885 is
17886 Gov_M : constant SPARK_Mode_Id :=
17887 Get_SPARK_Mode_Id (Governing_Mode);
17888 New_M : constant SPARK_Mode_Id := Get_SPARK_Mode_Id (New_Mode);
17889
17890 begin
17891 -- The new mode is less restrictive than the established mode
17892
17893 if Gov_M < New_M then
17894 Error_Msg_Name_1 := Get_SPARK_Mode_Name (New_M);
17895 Error_Msg_N ("cannot define 'S'P'A'R'K mode %", New_Mode);
17896
17897 Error_Msg_Name_1 := Get_SPARK_Mode_Name (Gov_M);
17898 Error_Msg_Sloc := Sloc (Governing_Mode);
17899 Error_Msg_N
17900 ("\mode is less restrictive than mode % defined #",
17901 New_Mode);
17902 end if;
17903 end Check_Pragma_Conformance;
17904
17905 -------------------------
17906 -- Get_SPARK_Mode_Name --
17907 -------------------------
17908
17909 function Get_SPARK_Mode_Name (Id : SPARK_Mode_Id) return Name_Id is
17910 begin
17911 if Id = SPARK_On then
17912 return Name_On;
17913 elsif Id = SPARK_Off then
17914 return Name_Off;
17915 elsif Id = SPARK_Auto then
17916 return Name_Auto;
17917
17918 -- Mode "None" should never be used in error message generation
17919
17920 else
17921 raise Program_Error;
17922 end if;
17923 end Get_SPARK_Mode_Name;
17924
17925 -- Local variables
17926
17927 Body_Id : Entity_Id;
17928 Context : Node_Id;
17929 Mode : Name_Id;
17930 Mode_Id : SPARK_Mode_Id;
17931 Spec_Id : Entity_Id;
17932 Stmt : Node_Id;
17933
17934 -- Start of processing for SPARK_Mode
17935
17936 begin
17937 GNAT_Pragma;
17938 Check_No_Identifiers;
17939 Check_At_Most_N_Arguments (1);
17940
17941 -- Check the legality of the mode
17942
17943 if Arg_Count = 1 then
17944 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off, Name_Auto);
17945 Mode := Chars (Get_Pragma_Arg (Arg1));
17946
17947 -- A SPARK_Mode without an argument defaults to "On"
17948
17949 else
17950 Mode := Name_On;
17951 end if;
17952
17953 Mode_Id := Get_SPARK_Mode_Id (Mode);
17954 Context := Parent (N);
17955
17956 -- The pragma appears in a configuration file
17957
17958 if No (Context) then
17959 Check_Valid_Configuration_Pragma;
17960 Global_SPARK_Mode := Mode_Id;
17961
17962 -- When the pragma is placed before the declaration of a unit, it
17963 -- configures the whole unit.
17964
17965 elsif Nkind (Context) = N_Compilation_Unit then
17966 Check_Valid_Configuration_Pragma;
17967 Set_SPARK_Mode_Pragma (Current_Sem_Unit, N);
17968
17969 -- The pragma applies to a [library unit] subprogram or package
17970
17971 else
17972 -- Mode "Auto" cannot be used in nested subprograms or packages
17973
17974 if Mode_Id = SPARK_Auto then
17975 Error_Pragma_Arg
17976 ("mode `Auto` can only apply to the configuration variant "
17977 & "of pragma %", Arg1);
17978 end if;
17979
17980 -- Verify the placement of the pragma with respect to package
17981 -- or subprogram declarations and detect duplicates.
17982
17983 Stmt := Prev (N);
17984 while Present (Stmt) loop
17985
17986 -- Skip prior pragmas, but check for duplicates
17987
17988 if Nkind (Stmt) = N_Pragma then
17989 if Pragma_Name (Stmt) = Pname then
17990 Error_Msg_Name_1 := Pname;
17991 Error_Msg_Sloc := Sloc (Stmt);
17992 Error_Msg_N
17993 ("pragma % duplicates pragma declared #", N);
17994 end if;
17995
17996 -- Skip internally generated code
17997
17998 elsif not Comes_From_Source (Stmt) then
17999 null;
18000
18001 -- The pragma applies to a package or subprogram declaration
18002
18003 elsif Nkind_In (Stmt, N_Generic_Package_Declaration,
18004 N_Generic_Subprogram_Declaration,
18005 N_Package_Declaration,
18006 N_Subprogram_Declaration)
18007 then
18008 Spec_Id := Defining_Unit_Name (Specification (Stmt));
18009 Chain_Pragma (Spec_Id, N);
18010 return;
18011
18012 -- The pragma does not apply to a legal construct, issue an
18013 -- error and stop the analysis.
18014
18015 else
18016 Pragma_Misplaced;
18017 exit;
18018 end if;
18019
18020 Stmt := Prev (Stmt);
18021 end loop;
18022
18023 -- Handle all cases where the pragma is actually an aspect and
18024 -- applies to a library-level package spec, body or subprogram.
18025
18026 -- function F ... with SPARK_Mode => ...;
18027 -- package P with SPARK_Mode => ...;
18028 -- package body P with SPARK_Mode => ... is
18029
18030 -- The following circuitry simply prepares the proper context
18031 -- for the general pragma processing mechanism below.
18032
18033 if Nkind (Context) = N_Compilation_Unit_Aux then
18034 Context := Unit (Parent (Context));
18035
18036 if Nkind_In (Context, N_Package_Declaration,
18037 N_Subprogram_Declaration)
18038 then
18039 Context := Specification (Context);
18040 end if;
18041 end if;
18042
18043 -- The pragma is at the top level of a package spec or appears
18044 -- as an aspect on a subprogram.
18045
18046 -- function F ... with SPARK_Mode => ...;
18047
18048 -- package P is
18049 -- pragma SPARK_Mode;
18050
18051 if Nkind_In (Context, N_Function_Specification,
18052 N_Package_Specification,
18053 N_Procedure_Specification)
18054 then
18055 Spec_Id := Defining_Unit_Name (Context);
18056 Chain_Pragma (Spec_Id, N);
18057
18058 -- The pragma is immediately within a package or subprogram
18059 -- body.
18060
18061 -- function F ... is
18062 -- pragma SPARK_Mode;
18063
18064 -- package body P is
18065 -- pragma SPARK_Mode;
18066
18067 elsif Nkind_In (Context, N_Package_Body,
18068 N_Subprogram_Body)
18069 then
18070 Spec_Id := Corresponding_Spec (Context);
18071
18072 if Nkind (Context) = N_Subprogram_Body then
18073 Context := Specification (Context);
18074 end if;
18075
18076 Body_Id := Defining_Unit_Name (Context);
18077
18078 Chain_Pragma (Body_Id, N);
18079
18080 -- Verify that the SPARK modes are consistent between
18081 -- body and spec, if any.
18082
18083 if Present (Spec_Id) then
18084 Check_Spark_Mode_Conformance (Spec_Id, Body_Id);
18085 end if;
18086
18087 -- The pragma applies to the statements of a package body
18088
18089 -- package body P is
18090 -- begin
18091 -- pragma SPARK_Mode;
18092
18093 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
18094 and then Nkind (Parent (Context)) = N_Package_Body
18095 then
18096 Context := Parent (Context);
18097 Spec_Id := Corresponding_Spec (Context);
18098 Body_Id := Defining_Unit_Name (Context);
18099
18100 Chain_Pragma (Body_Id, N);
18101 Check_Spark_Mode_Conformance (Spec_Id, Body_Id);
18102
18103 -- The pragma does not apply to a legal construct, issue error
18104
18105 else
18106 Pragma_Misplaced;
18107 end if;
18108 end if;
18109 end SPARK_Mod;
18110
18111 --------------------------------
18112 -- Static_Elaboration_Desired --
18113 --------------------------------
18114
18115 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
18116
18117 when Pragma_Static_Elaboration_Desired =>
18118 GNAT_Pragma;
18119 Check_At_Most_N_Arguments (1);
18120
18121 if Is_Compilation_Unit (Current_Scope)
18122 and then Ekind (Current_Scope) = E_Package
18123 then
18124 Set_Static_Elaboration_Desired (Current_Scope, True);
18125 else
18126 Error_Pragma ("pragma% must apply to a library-level package");
18127 end if;
18128
18129 ------------------
18130 -- Storage_Size --
18131 ------------------
18132
18133 -- pragma Storage_Size (EXPRESSION);
18134
18135 when Pragma_Storage_Size => Storage_Size : declare
18136 P : constant Node_Id := Parent (N);
18137 Arg : Node_Id;
18138
18139 begin
18140 Check_No_Identifiers;
18141 Check_Arg_Count (1);
18142
18143 -- The expression must be analyzed in the special manner described
18144 -- in "Handling of Default Expressions" in sem.ads.
18145
18146 Arg := Get_Pragma_Arg (Arg1);
18147 Preanalyze_Spec_Expression (Arg, Any_Integer);
18148
18149 if not Is_Static_Expression (Arg) then
18150 Check_Restriction (Static_Storage_Size, Arg);
18151 end if;
18152
18153 if Nkind (P) /= N_Task_Definition then
18154 Pragma_Misplaced;
18155 return;
18156
18157 else
18158 if Has_Storage_Size_Pragma (P) then
18159 Error_Pragma ("duplicate pragma% not allowed");
18160 else
18161 Set_Has_Storage_Size_Pragma (P, True);
18162 end if;
18163
18164 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
18165 end if;
18166 end Storage_Size;
18167
18168 ------------------
18169 -- Storage_Unit --
18170 ------------------
18171
18172 -- pragma Storage_Unit (NUMERIC_LITERAL);
18173
18174 -- Only permitted argument is System'Storage_Unit value
18175
18176 when Pragma_Storage_Unit =>
18177 Check_No_Identifiers;
18178 Check_Arg_Count (1);
18179 Check_Arg_Is_Integer_Literal (Arg1);
18180
18181 if Intval (Get_Pragma_Arg (Arg1)) /=
18182 UI_From_Int (Ttypes.System_Storage_Unit)
18183 then
18184 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
18185 Error_Pragma_Arg
18186 ("the only allowed argument for pragma% is ^", Arg1);
18187 end if;
18188
18189 --------------------
18190 -- Stream_Convert --
18191 --------------------
18192
18193 -- pragma Stream_Convert (
18194 -- [Entity =>] type_LOCAL_NAME,
18195 -- [Read =>] function_NAME,
18196 -- [Write =>] function NAME);
18197
18198 when Pragma_Stream_Convert => Stream_Convert : declare
18199
18200 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
18201 -- Check that the given argument is the name of a local function
18202 -- of one argument that is not overloaded earlier in the current
18203 -- local scope. A check is also made that the argument is a
18204 -- function with one parameter.
18205
18206 --------------------------------------
18207 -- Check_OK_Stream_Convert_Function --
18208 --------------------------------------
18209
18210 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
18211 Ent : Entity_Id;
18212
18213 begin
18214 Check_Arg_Is_Local_Name (Arg);
18215 Ent := Entity (Get_Pragma_Arg (Arg));
18216
18217 if Has_Homonym (Ent) then
18218 Error_Pragma_Arg
18219 ("argument for pragma% may not be overloaded", Arg);
18220 end if;
18221
18222 if Ekind (Ent) /= E_Function
18223 or else No (First_Formal (Ent))
18224 or else Present (Next_Formal (First_Formal (Ent)))
18225 then
18226 Error_Pragma_Arg
18227 ("argument for pragma% must be function of one argument",
18228 Arg);
18229 end if;
18230 end Check_OK_Stream_Convert_Function;
18231
18232 -- Start of processing for Stream_Convert
18233
18234 begin
18235 GNAT_Pragma;
18236 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
18237 Check_Arg_Count (3);
18238 Check_Optional_Identifier (Arg1, Name_Entity);
18239 Check_Optional_Identifier (Arg2, Name_Read);
18240 Check_Optional_Identifier (Arg3, Name_Write);
18241 Check_Arg_Is_Local_Name (Arg1);
18242 Check_OK_Stream_Convert_Function (Arg2);
18243 Check_OK_Stream_Convert_Function (Arg3);
18244
18245 declare
18246 Typ : constant Entity_Id :=
18247 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
18248 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
18249 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
18250
18251 begin
18252 Check_First_Subtype (Arg1);
18253
18254 -- Check for too early or too late. Note that we don't enforce
18255 -- the rule about primitive operations in this case, since, as
18256 -- is the case for explicit stream attributes themselves, these
18257 -- restrictions are not appropriate. Note that the chaining of
18258 -- the pragma by Rep_Item_Too_Late is actually the critical
18259 -- processing done for this pragma.
18260
18261 if Rep_Item_Too_Early (Typ, N)
18262 or else
18263 Rep_Item_Too_Late (Typ, N, FOnly => True)
18264 then
18265 return;
18266 end if;
18267
18268 -- Return if previous error
18269
18270 if Etype (Typ) = Any_Type
18271 or else
18272 Etype (Read) = Any_Type
18273 or else
18274 Etype (Write) = Any_Type
18275 then
18276 return;
18277 end if;
18278
18279 -- Error checks
18280
18281 if Underlying_Type (Etype (Read)) /= Typ then
18282 Error_Pragma_Arg
18283 ("incorrect return type for function&", Arg2);
18284 end if;
18285
18286 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
18287 Error_Pragma_Arg
18288 ("incorrect parameter type for function&", Arg3);
18289 end if;
18290
18291 if Underlying_Type (Etype (First_Formal (Read))) /=
18292 Underlying_Type (Etype (Write))
18293 then
18294 Error_Pragma_Arg
18295 ("result type of & does not match Read parameter type",
18296 Arg3);
18297 end if;
18298 end;
18299 end Stream_Convert;
18300
18301 ------------------
18302 -- Style_Checks --
18303 ------------------
18304
18305 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
18306
18307 -- This is processed by the parser since some of the style checks
18308 -- take place during source scanning and parsing. This means that
18309 -- we don't need to issue error messages here.
18310
18311 when Pragma_Style_Checks => Style_Checks : declare
18312 A : constant Node_Id := Get_Pragma_Arg (Arg1);
18313 S : String_Id;
18314 C : Char_Code;
18315
18316 begin
18317 GNAT_Pragma;
18318 Check_No_Identifiers;
18319
18320 -- Two argument form
18321
18322 if Arg_Count = 2 then
18323 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
18324
18325 declare
18326 E_Id : Node_Id;
18327 E : Entity_Id;
18328
18329 begin
18330 E_Id := Get_Pragma_Arg (Arg2);
18331 Analyze (E_Id);
18332
18333 if not Is_Entity_Name (E_Id) then
18334 Error_Pragma_Arg
18335 ("second argument of pragma% must be entity name",
18336 Arg2);
18337 end if;
18338
18339 E := Entity (E_Id);
18340
18341 if not Ignore_Style_Checks_Pragmas then
18342 if E = Any_Id then
18343 return;
18344 else
18345 loop
18346 Set_Suppress_Style_Checks
18347 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
18348 exit when No (Homonym (E));
18349 E := Homonym (E);
18350 end loop;
18351 end if;
18352 end if;
18353 end;
18354
18355 -- One argument form
18356
18357 else
18358 Check_Arg_Count (1);
18359
18360 if Nkind (A) = N_String_Literal then
18361 S := Strval (A);
18362
18363 declare
18364 Slen : constant Natural := Natural (String_Length (S));
18365 Options : String (1 .. Slen);
18366 J : Natural;
18367
18368 begin
18369 J := 1;
18370 loop
18371 C := Get_String_Char (S, Int (J));
18372 exit when not In_Character_Range (C);
18373 Options (J) := Get_Character (C);
18374
18375 -- If at end of string, set options. As per discussion
18376 -- above, no need to check for errors, since we issued
18377 -- them in the parser.
18378
18379 if J = Slen then
18380 if not Ignore_Style_Checks_Pragmas then
18381 Set_Style_Check_Options (Options);
18382 end if;
18383
18384 exit;
18385 end if;
18386
18387 J := J + 1;
18388 end loop;
18389 end;
18390
18391 elsif Nkind (A) = N_Identifier then
18392 if Chars (A) = Name_All_Checks then
18393 if not Ignore_Style_Checks_Pragmas then
18394 if GNAT_Mode then
18395 Set_GNAT_Style_Check_Options;
18396 else
18397 Set_Default_Style_Check_Options;
18398 end if;
18399 end if;
18400
18401 elsif Chars (A) = Name_On then
18402 if not Ignore_Style_Checks_Pragmas then
18403 Style_Check := True;
18404 end if;
18405
18406 elsif Chars (A) = Name_Off then
18407 if not Ignore_Style_Checks_Pragmas then
18408 Style_Check := False;
18409 end if;
18410 end if;
18411 end if;
18412 end if;
18413 end Style_Checks;
18414
18415 --------------
18416 -- Subtitle --
18417 --------------
18418
18419 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
18420
18421 when Pragma_Subtitle =>
18422 GNAT_Pragma;
18423 Check_Arg_Count (1);
18424 Check_Optional_Identifier (Arg1, Name_Subtitle);
18425 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
18426 Store_Note (N);
18427
18428 --------------
18429 -- Suppress --
18430 --------------
18431
18432 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
18433
18434 when Pragma_Suppress =>
18435 Process_Suppress_Unsuppress (True);
18436
18437 ------------------
18438 -- Suppress_All --
18439 ------------------
18440
18441 -- pragma Suppress_All;
18442
18443 -- The only check made here is that the pragma has no arguments.
18444 -- There are no placement rules, and the processing required (setting
18445 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
18446 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
18447 -- then creates and inserts a pragma Suppress (All_Checks).
18448
18449 when Pragma_Suppress_All =>
18450 GNAT_Pragma;
18451 Check_Arg_Count (0);
18452
18453 -------------------------
18454 -- Suppress_Debug_Info --
18455 -------------------------
18456
18457 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
18458
18459 when Pragma_Suppress_Debug_Info =>
18460 GNAT_Pragma;
18461 Check_Arg_Count (1);
18462 Check_Optional_Identifier (Arg1, Name_Entity);
18463 Check_Arg_Is_Local_Name (Arg1);
18464 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
18465
18466 ----------------------------------
18467 -- Suppress_Exception_Locations --
18468 ----------------------------------
18469
18470 -- pragma Suppress_Exception_Locations;
18471
18472 when Pragma_Suppress_Exception_Locations =>
18473 GNAT_Pragma;
18474 Check_Arg_Count (0);
18475 Check_Valid_Configuration_Pragma;
18476 Exception_Locations_Suppressed := True;
18477
18478 -----------------------------
18479 -- Suppress_Initialization --
18480 -----------------------------
18481
18482 -- pragma Suppress_Initialization ([Entity =>] type_Name);
18483
18484 when Pragma_Suppress_Initialization => Suppress_Init : declare
18485 E_Id : Node_Id;
18486 E : Entity_Id;
18487
18488 begin
18489 GNAT_Pragma;
18490 Check_Arg_Count (1);
18491 Check_Optional_Identifier (Arg1, Name_Entity);
18492 Check_Arg_Is_Local_Name (Arg1);
18493
18494 E_Id := Get_Pragma_Arg (Arg1);
18495
18496 if Etype (E_Id) = Any_Type then
18497 return;
18498 end if;
18499
18500 E := Entity (E_Id);
18501
18502 if not Is_Type (E) then
18503 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
18504 end if;
18505
18506 if Rep_Item_Too_Early (E, N)
18507 or else
18508 Rep_Item_Too_Late (E, N, FOnly => True)
18509 then
18510 return;
18511 end if;
18512
18513 -- For incomplete/private type, set flag on full view
18514
18515 if Is_Incomplete_Or_Private_Type (E) then
18516 if No (Full_View (Base_Type (E))) then
18517 Error_Pragma_Arg
18518 ("argument of pragma% cannot be an incomplete type", Arg1);
18519 else
18520 Set_Suppress_Initialization (Full_View (Base_Type (E)));
18521 end if;
18522
18523 -- For first subtype, set flag on base type
18524
18525 elsif Is_First_Subtype (E) then
18526 Set_Suppress_Initialization (Base_Type (E));
18527
18528 -- For other than first subtype, set flag on subtype itself
18529
18530 else
18531 Set_Suppress_Initialization (E);
18532 end if;
18533 end Suppress_Init;
18534
18535 -----------------
18536 -- System_Name --
18537 -----------------
18538
18539 -- pragma System_Name (DIRECT_NAME);
18540
18541 -- Syntax check: one argument, which must be the identifier GNAT or
18542 -- the identifier GCC, no other identifiers are acceptable.
18543
18544 when Pragma_System_Name =>
18545 GNAT_Pragma;
18546 Check_No_Identifiers;
18547 Check_Arg_Count (1);
18548 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
18549
18550 -----------------------------
18551 -- Task_Dispatching_Policy --
18552 -----------------------------
18553
18554 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
18555
18556 when Pragma_Task_Dispatching_Policy => declare
18557 DP : Character;
18558
18559 begin
18560 Check_Ada_83_Warning;
18561 Check_Arg_Count (1);
18562 Check_No_Identifiers;
18563 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18564 Check_Valid_Configuration_Pragma;
18565 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18566 DP := Fold_Upper (Name_Buffer (1));
18567
18568 if Task_Dispatching_Policy /= ' '
18569 and then Task_Dispatching_Policy /= DP
18570 then
18571 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18572 Error_Pragma
18573 ("task dispatching policy incompatible with policy#");
18574
18575 -- Set new policy, but always preserve System_Location since we
18576 -- like the error message with the run time name.
18577
18578 else
18579 Task_Dispatching_Policy := DP;
18580
18581 if Task_Dispatching_Policy_Sloc /= System_Location then
18582 Task_Dispatching_Policy_Sloc := Loc;
18583 end if;
18584 end if;
18585 end;
18586
18587 ---------------
18588 -- Task_Info --
18589 ---------------
18590
18591 -- pragma Task_Info (EXPRESSION);
18592
18593 when Pragma_Task_Info => Task_Info : declare
18594 P : constant Node_Id := Parent (N);
18595 Ent : Entity_Id;
18596
18597 begin
18598 GNAT_Pragma;
18599
18600 if Nkind (P) /= N_Task_Definition then
18601 Error_Pragma ("pragma% must appear in task definition");
18602 end if;
18603
18604 Check_No_Identifiers;
18605 Check_Arg_Count (1);
18606
18607 Analyze_And_Resolve
18608 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
18609
18610 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
18611 return;
18612 end if;
18613
18614 Ent := Defining_Identifier (Parent (P));
18615
18616 -- Check duplicate pragma before we chain the pragma in the Rep
18617 -- Item chain of Ent.
18618
18619 if Has_Rep_Pragma
18620 (Ent, Name_Task_Info, Check_Parents => False)
18621 then
18622 Error_Pragma ("duplicate pragma% not allowed");
18623 end if;
18624
18625 Record_Rep_Item (Ent, N);
18626 end Task_Info;
18627
18628 ---------------
18629 -- Task_Name --
18630 ---------------
18631
18632 -- pragma Task_Name (string_EXPRESSION);
18633
18634 when Pragma_Task_Name => Task_Name : declare
18635 P : constant Node_Id := Parent (N);
18636 Arg : Node_Id;
18637 Ent : Entity_Id;
18638
18639 begin
18640 Check_No_Identifiers;
18641 Check_Arg_Count (1);
18642
18643 Arg := Get_Pragma_Arg (Arg1);
18644
18645 -- The expression is used in the call to Create_Task, and must be
18646 -- expanded there, not in the context of the current spec. It must
18647 -- however be analyzed to capture global references, in case it
18648 -- appears in a generic context.
18649
18650 Preanalyze_And_Resolve (Arg, Standard_String);
18651
18652 if Nkind (P) /= N_Task_Definition then
18653 Pragma_Misplaced;
18654 end if;
18655
18656 Ent := Defining_Identifier (Parent (P));
18657
18658 -- Check duplicate pragma before we chain the pragma in the Rep
18659 -- Item chain of Ent.
18660
18661 if Has_Rep_Pragma
18662 (Ent, Name_Task_Name, Check_Parents => False)
18663 then
18664 Error_Pragma ("duplicate pragma% not allowed");
18665 end if;
18666
18667 Record_Rep_Item (Ent, N);
18668 end Task_Name;
18669
18670 ------------------
18671 -- Task_Storage --
18672 ------------------
18673
18674 -- pragma Task_Storage (
18675 -- [Task_Type =>] LOCAL_NAME,
18676 -- [Top_Guard =>] static_integer_EXPRESSION);
18677
18678 when Pragma_Task_Storage => Task_Storage : declare
18679 Args : Args_List (1 .. 2);
18680 Names : constant Name_List (1 .. 2) := (
18681 Name_Task_Type,
18682 Name_Top_Guard);
18683
18684 Task_Type : Node_Id renames Args (1);
18685 Top_Guard : Node_Id renames Args (2);
18686
18687 Ent : Entity_Id;
18688
18689 begin
18690 GNAT_Pragma;
18691 Gather_Associations (Names, Args);
18692
18693 if No (Task_Type) then
18694 Error_Pragma
18695 ("missing task_type argument for pragma%");
18696 end if;
18697
18698 Check_Arg_Is_Local_Name (Task_Type);
18699
18700 Ent := Entity (Task_Type);
18701
18702 if not Is_Task_Type (Ent) then
18703 Error_Pragma_Arg
18704 ("argument for pragma% must be task type", Task_Type);
18705 end if;
18706
18707 if No (Top_Guard) then
18708 Error_Pragma_Arg
18709 ("pragma% takes two arguments", Task_Type);
18710 else
18711 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
18712 end if;
18713
18714 Check_First_Subtype (Task_Type);
18715
18716 if Rep_Item_Too_Late (Ent, N) then
18717 raise Pragma_Exit;
18718 end if;
18719 end Task_Storage;
18720
18721 ---------------
18722 -- Test_Case --
18723 ---------------
18724
18725 -- pragma Test_Case
18726 -- ([Name =>] Static_String_EXPRESSION
18727 -- ,[Mode =>] MODE_TYPE
18728 -- [, Requires => Boolean_EXPRESSION]
18729 -- [, Ensures => Boolean_EXPRESSION]);
18730
18731 -- MODE_TYPE ::= Nominal | Robustness
18732
18733 when Pragma_Test_Case =>
18734 GNAT_Pragma;
18735 Check_Test_Case;
18736
18737 --------------------------
18738 -- Thread_Local_Storage --
18739 --------------------------
18740
18741 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
18742
18743 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
18744 Id : Node_Id;
18745 E : Entity_Id;
18746
18747 begin
18748 GNAT_Pragma;
18749 Check_Arg_Count (1);
18750 Check_Optional_Identifier (Arg1, Name_Entity);
18751 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18752
18753 Id := Get_Pragma_Arg (Arg1);
18754 Analyze (Id);
18755
18756 if not Is_Entity_Name (Id)
18757 or else Ekind (Entity (Id)) /= E_Variable
18758 then
18759 Error_Pragma_Arg ("local variable name required", Arg1);
18760 end if;
18761
18762 E := Entity (Id);
18763
18764 if Rep_Item_Too_Early (E, N)
18765 or else Rep_Item_Too_Late (E, N)
18766 then
18767 raise Pragma_Exit;
18768 end if;
18769
18770 Set_Has_Pragma_Thread_Local_Storage (E);
18771 Set_Has_Gigi_Rep_Item (E);
18772 end Thread_Local_Storage;
18773
18774 ----------------
18775 -- Time_Slice --
18776 ----------------
18777
18778 -- pragma Time_Slice (static_duration_EXPRESSION);
18779
18780 when Pragma_Time_Slice => Time_Slice : declare
18781 Val : Ureal;
18782 Nod : Node_Id;
18783
18784 begin
18785 GNAT_Pragma;
18786 Check_Arg_Count (1);
18787 Check_No_Identifiers;
18788 Check_In_Main_Program;
18789 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
18790
18791 if not Error_Posted (Arg1) then
18792 Nod := Next (N);
18793 while Present (Nod) loop
18794 if Nkind (Nod) = N_Pragma
18795 and then Pragma_Name (Nod) = Name_Time_Slice
18796 then
18797 Error_Msg_Name_1 := Pname;
18798 Error_Msg_N ("duplicate pragma% not permitted", Nod);
18799 end if;
18800
18801 Next (Nod);
18802 end loop;
18803 end if;
18804
18805 -- Process only if in main unit
18806
18807 if Get_Source_Unit (Loc) = Main_Unit then
18808 Opt.Time_Slice_Set := True;
18809 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
18810
18811 if Val <= Ureal_0 then
18812 Opt.Time_Slice_Value := 0;
18813
18814 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
18815 Opt.Time_Slice_Value := 1_000_000_000;
18816
18817 else
18818 Opt.Time_Slice_Value :=
18819 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
18820 end if;
18821 end if;
18822 end Time_Slice;
18823
18824 -----------
18825 -- Title --
18826 -----------
18827
18828 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
18829
18830 -- TITLING_OPTION ::=
18831 -- [Title =>] STRING_LITERAL
18832 -- | [Subtitle =>] STRING_LITERAL
18833
18834 when Pragma_Title => Title : declare
18835 Args : Args_List (1 .. 2);
18836 Names : constant Name_List (1 .. 2) := (
18837 Name_Title,
18838 Name_Subtitle);
18839
18840 begin
18841 GNAT_Pragma;
18842 Gather_Associations (Names, Args);
18843 Store_Note (N);
18844
18845 for J in 1 .. 2 loop
18846 if Present (Args (J)) then
18847 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
18848 end if;
18849 end loop;
18850 end Title;
18851
18852 ----------------------------
18853 -- Type_Invariant[_Class] --
18854 ----------------------------
18855
18856 -- pragma Type_Invariant[_Class]
18857 -- ([Entity =>] type_LOCAL_NAME,
18858 -- [Check =>] EXPRESSION);
18859
18860 when Pragma_Type_Invariant |
18861 Pragma_Type_Invariant_Class =>
18862 Type_Invariant : declare
18863 I_Pragma : Node_Id;
18864
18865 begin
18866 Check_Arg_Count (2);
18867
18868 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
18869 -- setting Class_Present for the Type_Invariant_Class case.
18870
18871 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
18872 I_Pragma := New_Copy (N);
18873 Set_Pragma_Identifier
18874 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
18875 Rewrite (N, I_Pragma);
18876 Set_Analyzed (N, False);
18877 Analyze (N);
18878 end Type_Invariant;
18879
18880 ---------------------
18881 -- Unchecked_Union --
18882 ---------------------
18883
18884 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
18885
18886 when Pragma_Unchecked_Union => Unchecked_Union : declare
18887 Assoc : constant Node_Id := Arg1;
18888 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
18889 Typ : Entity_Id;
18890 Tdef : Node_Id;
18891 Clist : Node_Id;
18892 Vpart : Node_Id;
18893 Comp : Node_Id;
18894 Variant : Node_Id;
18895
18896 begin
18897 Ada_2005_Pragma;
18898 Check_No_Identifiers;
18899 Check_Arg_Count (1);
18900 Check_Arg_Is_Local_Name (Arg1);
18901
18902 Find_Type (Type_Id);
18903
18904 Typ := Entity (Type_Id);
18905
18906 if Typ = Any_Type
18907 or else Rep_Item_Too_Early (Typ, N)
18908 then
18909 return;
18910 else
18911 Typ := Underlying_Type (Typ);
18912 end if;
18913
18914 if Rep_Item_Too_Late (Typ, N) then
18915 return;
18916 end if;
18917
18918 Check_First_Subtype (Arg1);
18919
18920 -- Note remaining cases are references to a type in the current
18921 -- declarative part. If we find an error, we post the error on
18922 -- the relevant type declaration at an appropriate point.
18923
18924 if not Is_Record_Type (Typ) then
18925 Error_Msg_N ("unchecked union must be record type", Typ);
18926 return;
18927
18928 elsif Is_Tagged_Type (Typ) then
18929 Error_Msg_N ("unchecked union must not be tagged", Typ);
18930 return;
18931
18932 elsif not Has_Discriminants (Typ) then
18933 Error_Msg_N
18934 ("unchecked union must have one discriminant", Typ);
18935 return;
18936
18937 -- Note: in previous versions of GNAT we used to check for limited
18938 -- types and give an error, but in fact the standard does allow
18939 -- Unchecked_Union on limited types, so this check was removed.
18940
18941 -- Similarly, GNAT used to require that all discriminants have
18942 -- default values, but this is not mandated by the RM.
18943
18944 -- Proceed with basic error checks completed
18945
18946 else
18947 Tdef := Type_Definition (Declaration_Node (Typ));
18948 Clist := Component_List (Tdef);
18949
18950 -- Check presence of component list and variant part
18951
18952 if No (Clist) or else No (Variant_Part (Clist)) then
18953 Error_Msg_N
18954 ("unchecked union must have variant part", Tdef);
18955 return;
18956 end if;
18957
18958 -- Check components
18959
18960 Comp := First (Component_Items (Clist));
18961 while Present (Comp) loop
18962 Check_Component (Comp, Typ);
18963 Next (Comp);
18964 end loop;
18965
18966 -- Check variant part
18967
18968 Vpart := Variant_Part (Clist);
18969
18970 Variant := First (Variants (Vpart));
18971 while Present (Variant) loop
18972 Check_Variant (Variant, Typ);
18973 Next (Variant);
18974 end loop;
18975 end if;
18976
18977 Set_Is_Unchecked_Union (Typ);
18978 Set_Convention (Typ, Convention_C);
18979 Set_Has_Unchecked_Union (Base_Type (Typ));
18980 Set_Is_Unchecked_Union (Base_Type (Typ));
18981 end Unchecked_Union;
18982
18983 ------------------------
18984 -- Unimplemented_Unit --
18985 ------------------------
18986
18987 -- pragma Unimplemented_Unit;
18988
18989 -- Note: this only gives an error if we are generating code, or if
18990 -- we are in a generic library unit (where the pragma appears in the
18991 -- body, not in the spec).
18992
18993 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
18994 Cunitent : constant Entity_Id :=
18995 Cunit_Entity (Get_Source_Unit (Loc));
18996 Ent_Kind : constant Entity_Kind :=
18997 Ekind (Cunitent);
18998
18999 begin
19000 GNAT_Pragma;
19001 Check_Arg_Count (0);
19002
19003 if Operating_Mode = Generate_Code
19004 or else Ent_Kind = E_Generic_Function
19005 or else Ent_Kind = E_Generic_Procedure
19006 or else Ent_Kind = E_Generic_Package
19007 then
19008 Get_Name_String (Chars (Cunitent));
19009 Set_Casing (Mixed_Case);
19010 Write_Str (Name_Buffer (1 .. Name_Len));
19011 Write_Str (" is not supported in this configuration");
19012 Write_Eol;
19013 raise Unrecoverable_Error;
19014 end if;
19015 end Unimplemented_Unit;
19016
19017 ------------------------
19018 -- Universal_Aliasing --
19019 ------------------------
19020
19021 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
19022
19023 when Pragma_Universal_Aliasing => Universal_Alias : declare
19024 E_Id : Entity_Id;
19025
19026 begin
19027 GNAT_Pragma;
19028 Check_Arg_Count (1);
19029 Check_Optional_Identifier (Arg2, Name_Entity);
19030 Check_Arg_Is_Local_Name (Arg1);
19031 E_Id := Entity (Get_Pragma_Arg (Arg1));
19032
19033 if E_Id = Any_Type then
19034 return;
19035 elsif No (E_Id) or else not Is_Type (E_Id) then
19036 Error_Pragma_Arg ("pragma% requires type", Arg1);
19037 end if;
19038
19039 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
19040 Record_Rep_Item (E_Id, N);
19041 end Universal_Alias;
19042
19043 --------------------
19044 -- Universal_Data --
19045 --------------------
19046
19047 -- pragma Universal_Data [(library_unit_NAME)];
19048
19049 when Pragma_Universal_Data =>
19050 GNAT_Pragma;
19051
19052 -- If this is a configuration pragma, then set the universal
19053 -- addressing option, otherwise confirm that the pragma satisfies
19054 -- the requirements of library unit pragma placement and leave it
19055 -- to the GNAAMP back end to detect the pragma (avoids transitive
19056 -- setting of the option due to withed units).
19057
19058 if Is_Configuration_Pragma then
19059 Universal_Addressing_On_AAMP := True;
19060 else
19061 Check_Valid_Library_Unit_Pragma;
19062 end if;
19063
19064 if not AAMP_On_Target then
19065 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
19066 end if;
19067
19068 ----------------
19069 -- Unmodified --
19070 ----------------
19071
19072 -- pragma Unmodified (local_Name {, local_Name});
19073
19074 when Pragma_Unmodified => Unmodified : declare
19075 Arg_Node : Node_Id;
19076 Arg_Expr : Node_Id;
19077 Arg_Ent : Entity_Id;
19078
19079 begin
19080 GNAT_Pragma;
19081 Check_At_Least_N_Arguments (1);
19082
19083 -- Loop through arguments
19084
19085 Arg_Node := Arg1;
19086 while Present (Arg_Node) loop
19087 Check_No_Identifier (Arg_Node);
19088
19089 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
19090 -- in fact generate reference, so that the entity will have a
19091 -- reference, which will inhibit any warnings about it not
19092 -- being referenced, and also properly show up in the ali file
19093 -- as a reference. But this reference is recorded before the
19094 -- Has_Pragma_Unreferenced flag is set, so that no warning is
19095 -- generated for this reference.
19096
19097 Check_Arg_Is_Local_Name (Arg_Node);
19098 Arg_Expr := Get_Pragma_Arg (Arg_Node);
19099
19100 if Is_Entity_Name (Arg_Expr) then
19101 Arg_Ent := Entity (Arg_Expr);
19102
19103 if not Is_Assignable (Arg_Ent) then
19104 Error_Pragma_Arg
19105 ("pragma% can only be applied to a variable",
19106 Arg_Expr);
19107 else
19108 Set_Has_Pragma_Unmodified (Arg_Ent);
19109 end if;
19110 end if;
19111
19112 Next (Arg_Node);
19113 end loop;
19114 end Unmodified;
19115
19116 ------------------
19117 -- Unreferenced --
19118 ------------------
19119
19120 -- pragma Unreferenced (local_Name {, local_Name});
19121
19122 -- or when used in a context clause:
19123
19124 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
19125
19126 when Pragma_Unreferenced => Unreferenced : declare
19127 Arg_Node : Node_Id;
19128 Arg_Expr : Node_Id;
19129 Arg_Ent : Entity_Id;
19130 Citem : Node_Id;
19131
19132 begin
19133 GNAT_Pragma;
19134 Check_At_Least_N_Arguments (1);
19135
19136 -- Check case of appearing within context clause
19137
19138 if Is_In_Context_Clause then
19139
19140 -- The arguments must all be units mentioned in a with clause
19141 -- in the same context clause. Note we already checked (in
19142 -- Par.Prag) that the arguments are either identifiers or
19143 -- selected components.
19144
19145 Arg_Node := Arg1;
19146 while Present (Arg_Node) loop
19147 Citem := First (List_Containing (N));
19148 while Citem /= N loop
19149 if Nkind (Citem) = N_With_Clause
19150 and then
19151 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
19152 then
19153 Set_Has_Pragma_Unreferenced
19154 (Cunit_Entity
19155 (Get_Source_Unit
19156 (Library_Unit (Citem))));
19157 Set_Unit_Name
19158 (Get_Pragma_Arg (Arg_Node), Name (Citem));
19159 exit;
19160 end if;
19161
19162 Next (Citem);
19163 end loop;
19164
19165 if Citem = N then
19166 Error_Pragma_Arg
19167 ("argument of pragma% is not withed unit", Arg_Node);
19168 end if;
19169
19170 Next (Arg_Node);
19171 end loop;
19172
19173 -- Case of not in list of context items
19174
19175 else
19176 Arg_Node := Arg1;
19177 while Present (Arg_Node) loop
19178 Check_No_Identifier (Arg_Node);
19179
19180 -- Note: the analyze call done by Check_Arg_Is_Local_Name
19181 -- will in fact generate reference, so that the entity will
19182 -- have a reference, which will inhibit any warnings about
19183 -- it not being referenced, and also properly show up in the
19184 -- ali file as a reference. But this reference is recorded
19185 -- before the Has_Pragma_Unreferenced flag is set, so that
19186 -- no warning is generated for this reference.
19187
19188 Check_Arg_Is_Local_Name (Arg_Node);
19189 Arg_Expr := Get_Pragma_Arg (Arg_Node);
19190
19191 if Is_Entity_Name (Arg_Expr) then
19192 Arg_Ent := Entity (Arg_Expr);
19193
19194 -- If the entity is overloaded, the pragma applies to the
19195 -- most recent overloading, as documented. In this case,
19196 -- name resolution does not generate a reference, so it
19197 -- must be done here explicitly.
19198
19199 if Is_Overloaded (Arg_Expr) then
19200 Generate_Reference (Arg_Ent, N);
19201 end if;
19202
19203 Set_Has_Pragma_Unreferenced (Arg_Ent);
19204 end if;
19205
19206 Next (Arg_Node);
19207 end loop;
19208 end if;
19209 end Unreferenced;
19210
19211 --------------------------
19212 -- Unreferenced_Objects --
19213 --------------------------
19214
19215 -- pragma Unreferenced_Objects (local_Name {, local_Name});
19216
19217 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
19218 Arg_Node : Node_Id;
19219 Arg_Expr : Node_Id;
19220
19221 begin
19222 GNAT_Pragma;
19223 Check_At_Least_N_Arguments (1);
19224
19225 Arg_Node := Arg1;
19226 while Present (Arg_Node) loop
19227 Check_No_Identifier (Arg_Node);
19228 Check_Arg_Is_Local_Name (Arg_Node);
19229 Arg_Expr := Get_Pragma_Arg (Arg_Node);
19230
19231 if not Is_Entity_Name (Arg_Expr)
19232 or else not Is_Type (Entity (Arg_Expr))
19233 then
19234 Error_Pragma_Arg
19235 ("argument for pragma% must be type or subtype", Arg_Node);
19236 end if;
19237
19238 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
19239 Next (Arg_Node);
19240 end loop;
19241 end Unreferenced_Objects;
19242
19243 ------------------------------
19244 -- Unreserve_All_Interrupts --
19245 ------------------------------
19246
19247 -- pragma Unreserve_All_Interrupts;
19248
19249 when Pragma_Unreserve_All_Interrupts =>
19250 GNAT_Pragma;
19251 Check_Arg_Count (0);
19252
19253 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
19254 Unreserve_All_Interrupts := True;
19255 end if;
19256
19257 ----------------
19258 -- Unsuppress --
19259 ----------------
19260
19261 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
19262
19263 when Pragma_Unsuppress =>
19264 Ada_2005_Pragma;
19265 Process_Suppress_Unsuppress (False);
19266
19267 -------------------
19268 -- Use_VADS_Size --
19269 -------------------
19270
19271 -- pragma Use_VADS_Size;
19272
19273 when Pragma_Use_VADS_Size =>
19274 GNAT_Pragma;
19275 Check_Arg_Count (0);
19276 Check_Valid_Configuration_Pragma;
19277 Use_VADS_Size := True;
19278
19279 ---------------------
19280 -- Validity_Checks --
19281 ---------------------
19282
19283 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
19284
19285 when Pragma_Validity_Checks => Validity_Checks : declare
19286 A : constant Node_Id := Get_Pragma_Arg (Arg1);
19287 S : String_Id;
19288 C : Char_Code;
19289
19290 begin
19291 GNAT_Pragma;
19292 Check_Arg_Count (1);
19293 Check_No_Identifiers;
19294
19295 if Nkind (A) = N_String_Literal then
19296 S := Strval (A);
19297
19298 declare
19299 Slen : constant Natural := Natural (String_Length (S));
19300 Options : String (1 .. Slen);
19301 J : Natural;
19302
19303 begin
19304 J := 1;
19305 loop
19306 C := Get_String_Char (S, Int (J));
19307 exit when not In_Character_Range (C);
19308 Options (J) := Get_Character (C);
19309
19310 if J = Slen then
19311 Set_Validity_Check_Options (Options);
19312 exit;
19313 else
19314 J := J + 1;
19315 end if;
19316 end loop;
19317 end;
19318
19319 elsif Nkind (A) = N_Identifier then
19320 if Chars (A) = Name_All_Checks then
19321 Set_Validity_Check_Options ("a");
19322 elsif Chars (A) = Name_On then
19323 Validity_Checks_On := True;
19324 elsif Chars (A) = Name_Off then
19325 Validity_Checks_On := False;
19326 end if;
19327 end if;
19328 end Validity_Checks;
19329
19330 --------------
19331 -- Volatile --
19332 --------------
19333
19334 -- pragma Volatile (LOCAL_NAME);
19335
19336 when Pragma_Volatile =>
19337 Process_Atomic_Shared_Volatile;
19338
19339 -------------------------
19340 -- Volatile_Components --
19341 -------------------------
19342
19343 -- pragma Volatile_Components (array_LOCAL_NAME);
19344
19345 -- Volatile is handled by the same circuit as Atomic_Components
19346
19347 --------------
19348 -- Warnings --
19349 --------------
19350
19351 -- pragma Warnings (On | Off [,REASON]);
19352 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
19353 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
19354 -- pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
19355
19356 -- REASON ::= Reason => Static_String_Expression
19357
19358 when Pragma_Warnings => Warnings : begin
19359 GNAT_Pragma;
19360 Check_At_Least_N_Arguments (1);
19361
19362 -- See if last argument is labeled Reason. If so, make sure we
19363 -- have a static string expression, but otherwise just ignore
19364 -- the REASON argument by decreasing Num_Args by 1 (all the
19365 -- remaining tests look only at the first Num_Args arguments).
19366
19367 declare
19368 Last_Arg : constant Node_Id :=
19369 Last (Pragma_Argument_Associations (N));
19370 begin
19371 if Nkind (Last_Arg) = N_Pragma_Argument_Association
19372 and then Chars (Last_Arg) = Name_Reason
19373 then
19374 Check_Arg_Is_Static_Expression (Last_Arg, Standard_String);
19375 Arg_Count := Arg_Count - 1;
19376
19377 -- Not allowed in compiler units (bootstrap issues)
19378
19379 Check_Compiler_Unit (N);
19380 end if;
19381 end;
19382
19383 -- Now proceed with REASON taken care of and eliminated
19384
19385 Check_No_Identifiers;
19386
19387 -- If debug flag -gnatd.i is set, pragma is ignored
19388
19389 if Debug_Flag_Dot_I then
19390 return;
19391 end if;
19392
19393 -- Process various forms of the pragma
19394
19395 declare
19396 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19397
19398 begin
19399 -- One argument case
19400
19401 if Arg_Count = 1 then
19402
19403 -- On/Off one argument case was processed by parser
19404
19405 if Nkind (Argx) = N_Identifier
19406 and then Nam_In (Chars (Argx), Name_On, Name_Off)
19407 then
19408 null;
19409
19410 -- One argument case must be ON/OFF or static string expr
19411
19412 elsif not Is_Static_String_Expression (Arg1) then
19413 Error_Pragma_Arg
19414 ("argument of pragma% must be On/Off or static string "
19415 & "expression", Arg1);
19416
19417 -- One argument string expression case
19418
19419 else
19420 declare
19421 Lit : constant Node_Id := Expr_Value_S (Argx);
19422 Str : constant String_Id := Strval (Lit);
19423 Len : constant Nat := String_Length (Str);
19424 C : Char_Code;
19425 J : Nat;
19426 OK : Boolean;
19427 Chr : Character;
19428
19429 begin
19430 J := 1;
19431 while J <= Len loop
19432 C := Get_String_Char (Str, J);
19433 OK := In_Character_Range (C);
19434
19435 if OK then
19436 Chr := Get_Character (C);
19437
19438 -- Dash case: only -Wxxx is accepted
19439
19440 if J = 1
19441 and then J < Len
19442 and then Chr = '-'
19443 then
19444 J := J + 1;
19445 C := Get_String_Char (Str, J);
19446 Chr := Get_Character (C);
19447 exit when Chr = 'W';
19448 OK := False;
19449
19450 -- Dot case
19451
19452 elsif J < Len and then Chr = '.' then
19453 J := J + 1;
19454 C := Get_String_Char (Str, J);
19455 Chr := Get_Character (C);
19456
19457 if not Set_Dot_Warning_Switch (Chr) then
19458 Error_Pragma_Arg
19459 ("invalid warning switch character "
19460 & '.' & Chr, Arg1);
19461 end if;
19462
19463 -- Non-Dot case
19464
19465 else
19466 OK := Set_Warning_Switch (Chr);
19467 end if;
19468 end if;
19469
19470 if not OK then
19471 Error_Pragma_Arg
19472 ("invalid warning switch character " & Chr,
19473 Arg1);
19474 end if;
19475
19476 J := J + 1;
19477 end loop;
19478 end;
19479 end if;
19480
19481 -- Two or more arguments (must be two)
19482
19483 else
19484 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19485 Check_At_Most_N_Arguments (2);
19486
19487 declare
19488 E_Id : Node_Id;
19489 E : Entity_Id;
19490 Err : Boolean;
19491
19492 begin
19493 E_Id := Get_Pragma_Arg (Arg2);
19494 Analyze (E_Id);
19495
19496 -- In the expansion of an inlined body, a reference to
19497 -- the formal may be wrapped in a conversion if the
19498 -- actual is a conversion. Retrieve the real entity name.
19499
19500 if (In_Instance_Body or In_Inlined_Body)
19501 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
19502 then
19503 E_Id := Expression (E_Id);
19504 end if;
19505
19506 -- Entity name case
19507
19508 if Is_Entity_Name (E_Id) then
19509 E := Entity (E_Id);
19510
19511 if E = Any_Id then
19512 return;
19513 else
19514 loop
19515 Set_Warnings_Off
19516 (E, (Chars (Get_Pragma_Arg (Arg1)) =
19517 Name_Off));
19518
19519 -- For OFF case, make entry in warnings off
19520 -- pragma table for later processing. But we do
19521 -- not do that within an instance, since these
19522 -- warnings are about what is needed in the
19523 -- template, not an instance of it.
19524
19525 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
19526 and then Warn_On_Warnings_Off
19527 and then not In_Instance
19528 then
19529 Warnings_Off_Pragmas.Append ((N, E));
19530 end if;
19531
19532 if Is_Enumeration_Type (E) then
19533 declare
19534 Lit : Entity_Id;
19535 begin
19536 Lit := First_Literal (E);
19537 while Present (Lit) loop
19538 Set_Warnings_Off (Lit);
19539 Next_Literal (Lit);
19540 end loop;
19541 end;
19542 end if;
19543
19544 exit when No (Homonym (E));
19545 E := Homonym (E);
19546 end loop;
19547 end if;
19548
19549 -- Error if not entity or static string literal case
19550
19551 elsif not Is_Static_String_Expression (Arg2) then
19552 Error_Pragma_Arg
19553 ("second argument of pragma% must be entity name "
19554 & "or static string expression", Arg2);
19555
19556 -- String literal case
19557
19558 else
19559 String_To_Name_Buffer
19560 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
19561
19562 -- Note on configuration pragma case: If this is a
19563 -- configuration pragma, then for an OFF pragma, we
19564 -- just set Config True in the call, which is all
19565 -- that needs to be done. For the case of ON, this
19566 -- is normally an error, unless it is canceling the
19567 -- effect of a previous OFF pragma in the same file.
19568 -- In any other case, an error will be signalled (ON
19569 -- with no matching OFF).
19570
19571 -- Note: We set Used if we are inside a generic to
19572 -- disable the test that the non-config case actually
19573 -- cancels a warning. That's because we can't be sure
19574 -- there isn't an instantiation in some other unit
19575 -- where a warning is suppressed.
19576
19577 -- We could do a little better here by checking if the
19578 -- generic unit we are inside is public, but for now
19579 -- we don't bother with that refinement.
19580
19581 if Chars (Argx) = Name_Off then
19582 Set_Specific_Warning_Off
19583 (Loc, Name_Buffer (1 .. Name_Len),
19584 Config => Is_Configuration_Pragma,
19585 Used => Inside_A_Generic or else In_Instance);
19586
19587 elsif Chars (Argx) = Name_On then
19588 Set_Specific_Warning_On
19589 (Loc, Name_Buffer (1 .. Name_Len), Err);
19590
19591 if Err then
19592 Error_Msg
19593 ("??pragma Warnings On with no matching "
19594 & "Warnings Off", Loc);
19595 end if;
19596 end if;
19597 end if;
19598 end;
19599 end if;
19600 end;
19601 end Warnings;
19602
19603 -------------------
19604 -- Weak_External --
19605 -------------------
19606
19607 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
19608
19609 when Pragma_Weak_External => Weak_External : declare
19610 Ent : Entity_Id;
19611
19612 begin
19613 GNAT_Pragma;
19614 Check_Arg_Count (1);
19615 Check_Optional_Identifier (Arg1, Name_Entity);
19616 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19617 Ent := Entity (Get_Pragma_Arg (Arg1));
19618
19619 if Rep_Item_Too_Early (Ent, N) then
19620 return;
19621 else
19622 Ent := Underlying_Type (Ent);
19623 end if;
19624
19625 -- The only processing required is to link this item on to the
19626 -- list of rep items for the given entity. This is accomplished
19627 -- by the call to Rep_Item_Too_Late (when no error is detected
19628 -- and False is returned).
19629
19630 if Rep_Item_Too_Late (Ent, N) then
19631 return;
19632 else
19633 Set_Has_Gigi_Rep_Item (Ent);
19634 end if;
19635 end Weak_External;
19636
19637 -----------------------------
19638 -- Wide_Character_Encoding --
19639 -----------------------------
19640
19641 -- pragma Wide_Character_Encoding (IDENTIFIER);
19642
19643 when Pragma_Wide_Character_Encoding =>
19644 GNAT_Pragma;
19645
19646 -- Nothing to do, handled in parser. Note that we do not enforce
19647 -- configuration pragma placement, this pragma can appear at any
19648 -- place in the source, allowing mixed encodings within a single
19649 -- source program.
19650
19651 null;
19652
19653 --------------------
19654 -- Unknown_Pragma --
19655 --------------------
19656
19657 -- Should be impossible, since the case of an unknown pragma is
19658 -- separately processed before the case statement is entered.
19659
19660 when Unknown_Pragma =>
19661 raise Program_Error;
19662 end case;
19663
19664 -- AI05-0144: detect dangerous order dependence. Disabled for now,
19665 -- until AI is formally approved.
19666
19667 -- Check_Order_Dependence;
19668
19669 exception
19670 when Pragma_Exit => null;
19671 end Analyze_Pragma;
19672
19673 ---------------------------------------------
19674 -- Analyze_Pre_Post_Condition_In_Decl_Part --
19675 ---------------------------------------------
19676
19677 procedure Analyze_Pre_Post_Condition_In_Decl_Part
19678 (Prag : Node_Id;
19679 Subp_Id : Entity_Id)
19680 is
19681 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (Prag));
19682 Nam : constant Name_Id := Original_Aspect_Name (Prag);
19683 Expr : Node_Id;
19684
19685 Restore_Scope : Boolean := False;
19686 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
19687
19688 begin
19689 -- Ensure that the subprogram and its formals are visible when analyzing
19690 -- the expression of the pragma.
19691
19692 if not In_Open_Scopes (Subp_Id) then
19693 Restore_Scope := True;
19694 Push_Scope (Subp_Id);
19695 Install_Formals (Subp_Id);
19696 end if;
19697
19698 -- Preanalyze the boolean expression, we treat this as a spec expression
19699 -- (i.e. similar to a default expression).
19700
19701 Expr := Get_Pragma_Arg (Arg1);
19702
19703 -- In ASIS mode, for a pragma generated from a source aspect, analyze
19704 -- the original aspect expression, which is shared with the generated
19705 -- pragma.
19706
19707 if ASIS_Mode and then Present (Corresponding_Aspect (Prag)) then
19708 Expr := Expression (Corresponding_Aspect (Prag));
19709 end if;
19710
19711 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
19712
19713 -- For a class-wide condition, a reference to a controlling formal must
19714 -- be interpreted as having the class-wide type (or an access to such)
19715 -- so that the inherited condition can be properly applied to any
19716 -- overriding operation (see ARM12 6.6.1 (7)).
19717
19718 if Class_Present (Prag) then
19719 Class_Wide_Condition : declare
19720 T : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
19721
19722 ACW : Entity_Id := Empty;
19723 -- Access to T'class, created if there is a controlling formal
19724 -- that is an access parameter.
19725
19726 function Get_ACW return Entity_Id;
19727 -- If the expression has a reference to an controlling access
19728 -- parameter, create an access to T'class for the necessary
19729 -- conversions if one does not exist.
19730
19731 function Process (N : Node_Id) return Traverse_Result;
19732 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
19733 -- aspect for a primitive subprogram of a tagged type T, a name
19734 -- that denotes a formal parameter of type T is interpreted as
19735 -- having type T'Class. Similarly, a name that denotes a formal
19736 -- accessparameter of type access-to-T is interpreted as having
19737 -- type access-to-T'Class. This ensures the expression is well-
19738 -- defined for a primitive subprogram of a type descended from T.
19739 -- Note that this replacement is not done for selector names in
19740 -- parameter associations. These carry an entity for reference
19741 -- purposes, but semantically they are just identifiers.
19742
19743 -------------
19744 -- Get_ACW --
19745 -------------
19746
19747 function Get_ACW return Entity_Id is
19748 Loc : constant Source_Ptr := Sloc (Prag);
19749 Decl : Node_Id;
19750
19751 begin
19752 if No (ACW) then
19753 Decl :=
19754 Make_Full_Type_Declaration (Loc,
19755 Defining_Identifier => Make_Temporary (Loc, 'T'),
19756 Type_Definition =>
19757 Make_Access_To_Object_Definition (Loc,
19758 Subtype_Indication =>
19759 New_Occurrence_Of (Class_Wide_Type (T), Loc),
19760 All_Present => True));
19761
19762 Insert_Before (Unit_Declaration_Node (Subp_Id), Decl);
19763 Analyze (Decl);
19764 ACW := Defining_Identifier (Decl);
19765 Freeze_Before (Unit_Declaration_Node (Subp_Id), ACW);
19766 end if;
19767
19768 return ACW;
19769 end Get_ACW;
19770
19771 -------------
19772 -- Process --
19773 -------------
19774
19775 function Process (N : Node_Id) return Traverse_Result is
19776 Loc : constant Source_Ptr := Sloc (N);
19777 Typ : Entity_Id;
19778
19779 begin
19780 if Is_Entity_Name (N)
19781 and then Present (Entity (N))
19782 and then Is_Formal (Entity (N))
19783 and then Nkind (Parent (N)) /= N_Type_Conversion
19784 and then
19785 (Nkind (Parent (N)) /= N_Parameter_Association
19786 or else N /= Selector_Name (Parent (N)))
19787 then
19788 if Etype (Entity (N)) = T then
19789 Typ := Class_Wide_Type (T);
19790
19791 elsif Is_Access_Type (Etype (Entity (N)))
19792 and then Designated_Type (Etype (Entity (N))) = T
19793 then
19794 Typ := Get_ACW;
19795 else
19796 Typ := Empty;
19797 end if;
19798
19799 if Present (Typ) then
19800 Rewrite (N,
19801 Make_Type_Conversion (Loc,
19802 Subtype_Mark =>
19803 New_Occurrence_Of (Typ, Loc),
19804 Expression => New_Occurrence_Of (Entity (N), Loc)));
19805 Set_Etype (N, Typ);
19806 end if;
19807 end if;
19808
19809 return OK;
19810 end Process;
19811
19812 procedure Replace_Type is new Traverse_Proc (Process);
19813
19814 -- Start of processing for Class_Wide_Condition
19815
19816 begin
19817 if not Present (T) then
19818
19819 -- Pre'Class/Post'Class aspect cases
19820
19821 if From_Aspect_Specification (Prag) then
19822 if Nam = Name_uPre then
19823 Error_Msg_Name_1 := Name_Pre;
19824 else
19825 Error_Msg_Name_1 := Name_Post;
19826 end if;
19827
19828 Error_Msg_Name_2 := Name_Class;
19829
19830 Error_Msg_N
19831 ("aspect `%''%` can only be specified for a primitive "
19832 & "operation of a tagged type",
19833 Corresponding_Aspect (Prag));
19834
19835 -- Pre_Class, Post_Class pragma cases
19836
19837 else
19838 if Nam = Name_uPre then
19839 Error_Msg_Name_1 := Name_Pre_Class;
19840 else
19841 Error_Msg_Name_1 := Name_Post_Class;
19842 end if;
19843
19844 Error_Msg_N
19845 ("pragma% can only be specified for a primitive "
19846 & "operation of a tagged type",
19847 Corresponding_Aspect (Prag));
19848 end if;
19849 end if;
19850
19851 Replace_Type (Get_Pragma_Arg (Arg1));
19852 end Class_Wide_Condition;
19853 end if;
19854
19855 -- Remove the subprogram from the scope stack now that the pre-analysis
19856 -- of the precondition/postcondition is done.
19857
19858 if Restore_Scope then
19859 End_Scope;
19860 end if;
19861 end Analyze_Pre_Post_Condition_In_Decl_Part;
19862
19863 ------------------------------------------
19864 -- Analyze_Refined_Depends_In_Decl_Part --
19865 ------------------------------------------
19866
19867 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
19868 Dependencies : List_Id := No_List;
19869 Depends : Node_Id;
19870 -- The corresponding Depends pragma along with its clauses
19871
19872 Global : Node_Id := Empty;
19873 -- The corresponding Refined_Global pragma (if any)
19874
19875 Out_Items : Elist_Id := No_Elist;
19876 -- All output items as defined in pragma Refined_Global (if any)
19877
19878 Refinements : List_Id := No_List;
19879 -- The clauses of pragma Refined_Depends
19880
19881 Spec_Id : Entity_Id;
19882 -- The entity of the subprogram subject to pragma Refined_Depends
19883
19884 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
19885 -- Verify the legality of a single clause
19886
19887 procedure Report_Extra_Clauses;
19888 -- Emit an error for each extra clause the appears in Refined_Depends
19889
19890 -----------------------------
19891 -- Check_Dependency_Clause --
19892 -----------------------------
19893
19894 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
19895 function Inputs_Match
19896 (Ref_Clause : Node_Id;
19897 Do_Checks : Boolean) return Boolean;
19898 -- Determine whether the inputs of clause Dep_Clause match those of
19899 -- clause Ref_Clause. If flag Do_Checks is set, the routine reports
19900 -- missed or extra input items.
19901
19902 function Output_Constituents (State_Id : Entity_Id) return Elist_Id;
19903 -- Given a state denoted by State_Id, return a list of all output
19904 -- constituents that may be referenced within Refined_Depends. The
19905 -- contents of the list depend on whethe Refined_Global is present.
19906
19907 procedure Report_Unused_Constituents (Constits : Elist_Id);
19908 -- Emit errors for all constituents found in list Constits
19909
19910 ------------------
19911 -- Inputs_Match --
19912 ------------------
19913
19914 function Inputs_Match
19915 (Ref_Clause : Node_Id;
19916 Do_Checks : Boolean) return Boolean
19917 is
19918 Ref_Inputs : List_Id;
19919 -- The input list of the refinement clause
19920
19921 function Is_Matching_Input (Dep_Input : Node_Id) return Boolean;
19922 -- Determine whether input Dep_Input matches one of the inputs of
19923 -- clause Ref_Clause.
19924
19925 procedure Report_Extra_Inputs;
19926 -- Emit errors for all extra inputs that appear in Ref_Clause
19927
19928 -----------------------
19929 -- Is_Matching_Input --
19930 -----------------------
19931
19932 function Is_Matching_Input (Dep_Input : Node_Id) return Boolean is
19933 procedure Match_Error (Msg : String; N : Node_Id);
19934 -- Emit a matching error if flag Do_Checks is set
19935
19936 -----------------
19937 -- Match_Error --
19938 -----------------
19939
19940 procedure Match_Error (Msg : String; N : Node_Id) is
19941 begin
19942 if Do_Checks then
19943 Error_Msg_N (Msg, N);
19944 end if;
19945 end Match_Error;
19946
19947 -- Local variables
19948
19949 Dep_Id : Node_Id;
19950 Next_Ref_Input : Node_Id;
19951 Ref_Id : Entity_Id;
19952 Ref_Input : Node_Id;
19953
19954 Has_Constituent : Boolean := False;
19955 -- Flag set when the refinement input list contains at least
19956 -- one constituent of the state denoted by Dep_Id.
19957
19958 Has_Null_State : Boolean := False;
19959 -- Flag set when the dependency input is a state with a null
19960 -- refinement.
19961
19962 Has_Refined_State : Boolean := False;
19963 -- Flag set when the dependency input is a state with visible
19964 -- refinement.
19965
19966 -- Start of processing for Is_Matching_Input
19967
19968 begin
19969 -- Match a null input with another null input
19970
19971 if Nkind (Dep_Input) = N_Null then
19972 Ref_Input := First (Ref_Inputs);
19973
19974 -- Remove the matching null from the pool of candidates
19975
19976 if Nkind (Ref_Input) = N_Null then
19977 Remove (Ref_Input);
19978 return True;
19979
19980 else
19981 Match_Error
19982 ("null input cannot be matched in corresponding "
19983 & "refinement clause", Dep_Input);
19984 end if;
19985
19986 -- Remaining cases are formal parameters, variables, and states
19987
19988 else
19989 Dep_Id := Entity_Of (Dep_Input);
19990
19991 -- Inspect all inputs of the refinement clause and attempt
19992 -- to match against the inputs of the dependence clause.
19993
19994 Ref_Input := First (Ref_Inputs);
19995 while Present (Ref_Input) loop
19996
19997 -- Store the next input now because a match will remove
19998 -- it from the list.
19999
20000 Next_Ref_Input := Next (Ref_Input);
20001
20002 if Ekind (Dep_Id) = E_Abstract_State then
20003
20004 -- A state with a null refinement matches either a
20005 -- null input list or nothing at all (no input):
20006
20007 -- Refined_State => (State => null)
20008
20009 -- No input
20010
20011 -- Depends => (<output> => (State, Input))
20012 -- Refined_Depends => (<output> => Input) -- OK
20013
20014 -- Null input list
20015
20016 -- Depends => (<output> => State)
20017 -- Refined_Depends => (<output> => null) -- OK
20018
20019 if Has_Null_Refinement (Dep_Id) then
20020 Has_Null_State := True;
20021
20022 -- Remove the matching null from the pool of
20023 -- candidates.
20024
20025 if Nkind (Ref_Input) = N_Null then
20026 Remove (Ref_Input);
20027 end if;
20028
20029 return True;
20030
20031 -- The state has a non-null refinement in which case
20032 -- remove all the matching constituents of the state:
20033
20034 -- Refined_State => (State => (C1, C2))
20035 -- Depends => (<output> => State)
20036 -- Refined_Depends => (<output> => (C1, C2))
20037
20038 elsif Has_Non_Null_Refinement (Dep_Id) then
20039 Has_Refined_State := True;
20040
20041 -- Ref_Input is an entity name
20042
20043 if Is_Entity_Name (Ref_Input) then
20044 Ref_Id := Entity_Of (Ref_Input);
20045
20046 -- The input of the refinement clause is a valid
20047 -- constituent of the state. Remove the input
20048 -- from the pool of candidates. Note that the
20049 -- search continues because the state may be
20050 -- represented by multiple constituents.
20051
20052 if Ekind_In (Ref_Id, E_Abstract_State,
20053 E_Variable)
20054 and then Present (Refined_State (Ref_Id))
20055 and then Refined_State (Ref_Id) = Dep_Id
20056 then
20057 Has_Constituent := True;
20058 Remove (Ref_Input);
20059 end if;
20060 end if;
20061 end if;
20062
20063 -- Formal parameters and variables are matched on
20064 -- entities. If this is the case, remove the input from
20065 -- the candidate list.
20066
20067 elsif Is_Entity_Name (Ref_Input)
20068 and then Entity_Of (Ref_Input) = Dep_Id
20069 then
20070 Remove (Ref_Input);
20071 return True;
20072 end if;
20073
20074 Ref_Input := Next_Ref_Input;
20075 end loop;
20076
20077 -- When a state with a null refinement appears as the last
20078 -- input, it matches nothing:
20079
20080 -- Refined_State => (State => null)
20081 -- Depends => (<output> => (Input, State))
20082 -- Refined_Depends => (<output> => Input) -- OK
20083
20084 if Ekind (Dep_Id) = E_Abstract_State
20085 and then Has_Null_Refinement (Dep_Id)
20086 and then No (Ref_Input)
20087 then
20088 Has_Null_State := True;
20089 end if;
20090 end if;
20091
20092 -- A state with visible refinement was matched against one or
20093 -- more of its constituents.
20094
20095 if Has_Constituent then
20096 return True;
20097
20098 -- A state with a null refinement matched null or nothing
20099
20100 elsif Has_Null_State then
20101 return True;
20102
20103 -- The input of a dependence clause does not have a matching
20104 -- input in the refinement clause, emit an error.
20105
20106 else
20107 Match_Error
20108 ("input cannot be matched in corresponding refinement "
20109 & "clause", Dep_Input);
20110
20111 if Has_Refined_State then
20112 Match_Error
20113 ("\check the use of constituents in dependence "
20114 & "refinement", Dep_Input);
20115 end if;
20116
20117 return False;
20118 end if;
20119 end Is_Matching_Input;
20120
20121 -------------------------
20122 -- Report_Extra_Inputs --
20123 -------------------------
20124
20125 procedure Report_Extra_Inputs is
20126 Input : Node_Id;
20127
20128 begin
20129 if Present (Ref_Inputs) and then Do_Checks then
20130 Input := First (Ref_Inputs);
20131 while Present (Input) loop
20132 Error_Msg_N
20133 ("unmatched or extra input in refinement clause",
20134 Input);
20135
20136 Next (Input);
20137 end loop;
20138 end if;
20139 end Report_Extra_Inputs;
20140
20141 -- Local variables
20142
20143 Dep_Inputs : constant Node_Id := Expression (Dep_Clause);
20144 Inputs : constant Node_Id := Expression (Ref_Clause);
20145 Dep_Input : Node_Id;
20146 Result : Boolean;
20147
20148 -- Start of processing for Inputs_Match
20149
20150 begin
20151 -- Construct a list of all refinement inputs. Note that the input
20152 -- list is copied because the algorithm modifies its contents and
20153 -- this should not be visible in Refined_Depends.
20154
20155 if Nkind (Inputs) = N_Aggregate then
20156 Ref_Inputs := New_Copy_List (Expressions (Inputs));
20157 else
20158 Ref_Inputs := New_List (Inputs);
20159 end if;
20160
20161 -- Depending on whether the original dependency clause mentions
20162 -- states with visible refinement, the corresponding refinement
20163 -- clause may differ greatly in structure and contents:
20164
20165 -- State with null refinement
20166
20167 -- Refined_State => (State => null)
20168 -- Depends => (<output> => State)
20169 -- Refined_Depends => (<output> => null)
20170
20171 -- Depends => (<output> => (State, Input))
20172 -- Refined_Depends => (<output> => Input)
20173
20174 -- Depends => (<output> => (Input_1, State, Input_2))
20175 -- Refined_Depends => (<output> => (Input_1, Input_2))
20176
20177 -- State with non-null refinement
20178
20179 -- Refined_State => (State_1 => (C1, C2))
20180 -- Depends => (<output> => State)
20181 -- Refined_Depends => (<output> => C1)
20182 -- or
20183 -- Refined_Depends => (<output> => (C1, C2))
20184
20185 if Nkind (Dep_Inputs) = N_Aggregate then
20186 Dep_Input := First (Expressions (Dep_Inputs));
20187 while Present (Dep_Input) loop
20188 if not Is_Matching_Input (Dep_Input) then
20189 Result := False;
20190 end if;
20191
20192 Next (Dep_Input);
20193 end loop;
20194
20195 Result := True;
20196
20197 -- Solitary input
20198
20199 else
20200 Result := Is_Matching_Input (Dep_Inputs);
20201 end if;
20202
20203 Report_Extra_Inputs;
20204 return Result;
20205 end Inputs_Match;
20206
20207 -------------------------
20208 -- Output_Constituents --
20209 -------------------------
20210
20211 function Output_Constituents (State_Id : Entity_Id) return Elist_Id is
20212 Item_Elmt : Elmt_Id;
20213 Item_Id : Entity_Id;
20214 Result : Elist_Id := No_Elist;
20215
20216 begin
20217 -- The related subprogram is subject to pragma Refined_Global. All
20218 -- usable output constituents are defined in its output item list.
20219
20220 if Present (Global) then
20221 Item_Elmt := First_Elmt (Out_Items);
20222 while Present (Item_Elmt) loop
20223 Item_Id := Node (Item_Elmt);
20224
20225 -- The constituent is part of the refinement of the input
20226 -- state, add it to the result list.
20227
20228 if Refined_State (Item_Id) = State_Id then
20229 Add_Item (Item_Id, Result);
20230 end if;
20231
20232 Next_Elmt (Item_Elmt);
20233 end loop;
20234
20235 -- When pragma Refined_Global is not present, the usable output
20236 -- constituents are all the constituents as defined in pragma
20237 -- Refined_State. Note that the elements are copied because the
20238 -- algorithm trims the list and this should not be reflected in
20239 -- the state itself.
20240
20241 else
20242 Result := New_Copy_Elist (Refinement_Constituents (State_Id));
20243 end if;
20244
20245 return Result;
20246 end Output_Constituents;
20247
20248 --------------------------------
20249 -- Report_Unused_Constituents --
20250 --------------------------------
20251
20252 procedure Report_Unused_Constituents (Constits : Elist_Id) is
20253 Constit : Entity_Id;
20254 Elmt : Elmt_Id;
20255 Posted : Boolean := False;
20256
20257 begin
20258 if Present (Constits) then
20259 Elmt := First_Elmt (Constits);
20260 while Present (Elmt) loop
20261 Constit := Node (Elmt);
20262
20263 -- A constituent must always refine a state
20264
20265 pragma Assert (Present (Refined_State (Constit)));
20266
20267 -- When a state has a visible refinement and its mode is
20268 -- Output_Only, all its constituents must be used as
20269 -- outputs.
20270
20271 if not Posted then
20272 Posted := True;
20273 Error_Msg_NE
20274 ("output only state & must be replaced by all its "
20275 & "constituents in dependence refinement",
20276 N, Refined_State (Constit));
20277 end if;
20278
20279 Error_Msg_NE
20280 ("\ constituent & is missing in output list", N, Constit);
20281
20282 Next_Elmt (Elmt);
20283 end loop;
20284 end if;
20285 end Report_Unused_Constituents;
20286
20287 -- Local variables
20288
20289 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
20290 Dep_Id : Entity_Id;
20291 Matching_Clause : Node_Id := Empty;
20292 Next_Ref_Clause : Node_Id;
20293 Ref_Clause : Node_Id;
20294 Ref_Id : Entity_Id;
20295 Ref_Output : Node_Id;
20296
20297 Has_Constituent : Boolean := False;
20298 -- Flag set when the refinement output list contains at least one
20299 -- constituent of the state denoted by Dep_Id.
20300
20301 Has_Null_State : Boolean := False;
20302 -- Flag set when the output of clause Dep_Clause is a state with a
20303 -- null refinement.
20304
20305 Has_Refined_State : Boolean := False;
20306 -- Flag set when the output of clause Dep_Clause is a state with
20307 -- visible refinement.
20308
20309 Out_Constits : Elist_Id := No_Elist;
20310 -- This list contains the entities all output constituents of state
20311 -- Dep_Id as defined in pragma Refined_State.
20312
20313 -- Start of processing for Check_Dependency_Clause
20314
20315 begin
20316 -- The analysis of pragma Depends should produce normalized clauses
20317 -- with exactly one output. This is important because output items
20318 -- are unique in the whole dependence relation and can be used as
20319 -- keys.
20320
20321 pragma Assert (No (Next (Dep_Output)));
20322
20323 -- Inspect all clauses of Refined_Depends and attempt to match the
20324 -- output of Dep_Clause against an output from the refinement clauses
20325 -- set.
20326
20327 Ref_Clause := First (Refinements);
20328 while Present (Ref_Clause) loop
20329 Matching_Clause := Empty;
20330
20331 -- Store the next clause now because a match will trim the list of
20332 -- refinement clauses and this side effect should not be visible
20333 -- in pragma Refined_Depends.
20334
20335 Next_Ref_Clause := Next (Ref_Clause);
20336
20337 -- The analysis of pragma Refined_Depends should produce
20338 -- normalized clauses with exactly one output.
20339
20340 Ref_Output := First (Choices (Ref_Clause));
20341 pragma Assert (No (Next (Ref_Output)));
20342
20343 -- Two null output lists match if their inputs match
20344
20345 if Nkind (Dep_Output) = N_Null
20346 and then Nkind (Ref_Output) = N_Null
20347 then
20348 Matching_Clause := Ref_Clause;
20349 exit;
20350
20351 -- Two function 'Result attributes match if their inputs match.
20352 -- Note that there is no need to compare the two prefixes because
20353 -- the attributes cannot denote anything but the related function.
20354
20355 elsif Is_Attribute_Result (Dep_Output)
20356 and then Is_Attribute_Result (Ref_Output)
20357 then
20358 Matching_Clause := Ref_Clause;
20359 exit;
20360
20361 -- The remaining cases are formal parameters, variables and states
20362
20363 elsif Is_Entity_Name (Dep_Output) then
20364 Dep_Id := Entity_Of (Dep_Output);
20365
20366 if Ekind (Dep_Id) = E_Abstract_State then
20367
20368 -- A state with a null refinement matches either a null
20369 -- output list or nothing at all (no clause):
20370
20371 -- Refined_State => (State => null)
20372
20373 -- No clause
20374
20375 -- Depends => (State => null)
20376 -- Refined_Depends => null -- OK
20377
20378 -- Null output list
20379
20380 -- Depends => (State => <input>)
20381 -- Refined_Depends => (null => <input>) -- OK
20382
20383 if Has_Null_Refinement (Dep_Id) then
20384 Has_Null_State := True;
20385
20386 -- When a state with null refinement matches a null
20387 -- output, compare their inputs.
20388
20389 if Nkind (Ref_Output) = N_Null then
20390 Matching_Clause := Ref_Clause;
20391 end if;
20392
20393 exit;
20394
20395 -- The state has a non-null refinement in which case the
20396 -- match is based on constituents and inputs. A state with
20397 -- multiple output constituents may match multiple clauses:
20398
20399 -- Refined_State => (State => (C1, C2))
20400 -- Depends => (State => <input>)
20401 -- Refined_Depends => ((C1, C2) => <input>)
20402
20403 -- When normalized, the above becomes:
20404
20405 -- Refined_Depends => (C1 => <input>,
20406 -- C2 => <input>)
20407
20408 elsif Has_Non_Null_Refinement (Dep_Id) then
20409 Has_Refined_State := True;
20410
20411 -- Store the entities of all output constituents of an
20412 -- Output_Only state with visible refinement.
20413
20414 if No (Out_Constits)
20415 and then Is_Output_Only_State (Dep_Id)
20416 then
20417 Out_Constits := Output_Constituents (Dep_Id);
20418 end if;
20419
20420 if Is_Entity_Name (Ref_Output) then
20421 Ref_Id := Entity_Of (Ref_Output);
20422
20423 -- The output of the refinement clause is a valid
20424 -- constituent of the state. Remove the clause from
20425 -- the pool of candidates if both input lists match.
20426 -- Note that the search continues because one clause
20427 -- may have been normalized into multiple clauses as
20428 -- per the example above.
20429
20430 if Ekind_In (Ref_Id, E_Abstract_State, E_Variable)
20431 and then Present (Refined_State (Ref_Id))
20432 and then Refined_State (Ref_Id) = Dep_Id
20433 and then Inputs_Match
20434 (Ref_Clause, Do_Checks => False)
20435 then
20436 Has_Constituent := True;
20437 Remove (Ref_Clause);
20438
20439 -- The matching constituent may act as an output
20440 -- for an Output_Only state. Remove the item from
20441 -- the available output constituents.
20442
20443 Remove (Out_Constits, Ref_Id);
20444 end if;
20445 end if;
20446 end if;
20447
20448 -- Formal parameters and variables match if their inputs match
20449
20450 elsif Is_Entity_Name (Ref_Output)
20451 and then Entity_Of (Ref_Output) = Dep_Id
20452 then
20453 Matching_Clause := Ref_Clause;
20454 exit;
20455 end if;
20456 end if;
20457
20458 Ref_Clause := Next_Ref_Clause;
20459 end loop;
20460
20461 -- Handle the case where pragma Depends contains one or more clauses
20462 -- that only mention states with null refinements. In that case the
20463 -- corresponding pragma Refined_Depends may have a null relation.
20464
20465 -- Refined_State => (State => null)
20466 -- Depends => (State => null)
20467 -- Refined_Depends => null -- OK
20468
20469 if No (Refinements) and then Is_Entity_Name (Dep_Output) then
20470 Dep_Id := Entity_Of (Dep_Output);
20471
20472 if Ekind (Dep_Id) = E_Abstract_State
20473 and then Has_Null_Refinement (Dep_Id)
20474 then
20475 Has_Null_State := True;
20476 end if;
20477 end if;
20478
20479 -- The above search produced a match based on unique output. Ensure
20480 -- that the inputs match as well and if they do, remove the clause
20481 -- from the pool of candidates.
20482
20483 if Present (Matching_Clause) then
20484 if Inputs_Match (Matching_Clause, Do_Checks => True) then
20485 Remove (Matching_Clause);
20486 end if;
20487
20488 -- A state with a visible refinement was matched against one or
20489 -- more clauses containing appropriate constituents.
20490
20491 elsif Has_Constituent then
20492 null;
20493
20494 -- A state with a null refinement did not warrant a clause
20495
20496 elsif Has_Null_State then
20497 null;
20498
20499 -- The dependence relation of pragma Refined_Depends does not contain
20500 -- a matching clause, emit an error.
20501
20502 else
20503 Error_Msg_NE
20504 ("dependence clause of subprogram & has no matching refinement "
20505 & "in body", Ref_Clause, Spec_Id);
20506
20507 if Has_Refined_State then
20508 Error_Msg_N
20509 ("\check the use of constituents in dependence refinement",
20510 Ref_Clause);
20511 end if;
20512 end if;
20513
20514 -- Emit errors for all unused constituents of an Output_Only state
20515 -- with visible refinement.
20516
20517 Report_Unused_Constituents (Out_Constits);
20518 end Check_Dependency_Clause;
20519
20520 --------------------------
20521 -- Report_Extra_Clauses --
20522 --------------------------
20523
20524 procedure Report_Extra_Clauses is
20525 Clause : Node_Id;
20526
20527 begin
20528 if Present (Refinements) then
20529 Clause := First (Refinements);
20530 while Present (Clause) loop
20531
20532 -- Do not complain about a null input refinement, since a null
20533 -- input legitimately matches anything.
20534
20535 if Nkind (Clause) /= N_Component_Association
20536 or else Nkind (Expression (Clause)) /= N_Null
20537 then
20538 Error_Msg_N
20539 ("unmatched or extra clause in dependence refinement",
20540 Clause);
20541 end if;
20542
20543 Next (Clause);
20544 end loop;
20545 end if;
20546 end Report_Extra_Clauses;
20547
20548 -- Local variables
20549
20550 Body_Decl : constant Node_Id := Parent (N);
20551 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
20552 Errors : constant Nat := Serious_Errors_Detected;
20553 Clause : Node_Id;
20554 Deps : Node_Id;
20555 Refs : Node_Id;
20556
20557 -- The following are dummy variables that capture unused output of
20558 -- routine Collect_Global_Items.
20559
20560 D1, D2 : Elist_Id := No_Elist;
20561 D3, D4, D5, D6 : Boolean;
20562
20563 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
20564
20565 begin
20566 Spec_Id := Corresponding_Spec (Body_Decl);
20567 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
20568
20569 -- The subprogram declarations lacks pragma Depends. This renders
20570 -- Refined_Depends useless as there is nothing to refine.
20571
20572 if No (Depends) then
20573 Error_Msg_NE
20574 ("useless refinement, subprogram & lacks dependence clauses",
20575 N, Spec_Id);
20576 return;
20577 end if;
20578
20579 Deps := Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
20580
20581 -- A null dependency relation renders the refinement useless because it
20582 -- cannot possibly mention abstract states with visible refinement. Note
20583 -- that the inverse is not true as states may be refined to null.
20584
20585 if Nkind (Deps) = N_Null then
20586 Error_Msg_NE
20587 ("useless refinement, subprogram & does not depend on abstract "
20588 & "state with visible refinement", N, Spec_Id);
20589 return;
20590 end if;
20591
20592 -- Multiple dependency clauses appear as component associations of an
20593 -- aggregate.
20594
20595 pragma Assert (Nkind (Deps) = N_Aggregate);
20596 Dependencies := Component_Associations (Deps);
20597
20598 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
20599 -- This ensures that the categorization of all refined dependency items
20600 -- is consistent with their role.
20601
20602 Analyze_Depends_In_Decl_Part (N);
20603 Refs := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
20604
20605 if Serious_Errors_Detected = Errors then
20606
20607 -- The related subprogram may be subject to pragma Refined_Global. If
20608 -- this is the case, gather all output items. These are needed when
20609 -- verifying the use of constituents that apply to output states with
20610 -- visible refinement.
20611
20612 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
20613
20614 if Present (Global) then
20615 Collect_Global_Items
20616 (Prag => Global,
20617 In_Items => D1,
20618 In_Out_Items => D2,
20619 Out_Items => Out_Items,
20620 Has_In_State => D3,
20621 Has_In_Out_State => D4,
20622 Has_Out_State => D5,
20623 Has_Null_State => D6);
20624 end if;
20625
20626 if Nkind (Refs) = N_Null then
20627 Refinements := No_List;
20628
20629 -- Multiple dependency clauses appear as component associations of an
20630 -- aggregate. Note that the clauses are copied because the algorithm
20631 -- modifies them and this should not be visible in Refined_Depends.
20632
20633 else pragma Assert (Nkind (Refs) = N_Aggregate);
20634 Refinements := New_Copy_List (Component_Associations (Refs));
20635 end if;
20636
20637 -- Inspect all the clauses of pragma Depends looking for a matching
20638 -- clause in pragma Refined_Depends. The approach is to use the
20639 -- sole output of a clause as a key. Output items are unique in a
20640 -- dependence relation. Clause normalization also ensured that all
20641 -- clauses have exactly one output. Depending on what the key is, one
20642 -- or more refinement clauses may satisfy the dependency clause. Each
20643 -- time a dependency clause is matched, its related refinement clause
20644 -- is consumed. In the end, two things may happen:
20645
20646 -- 1) A clause of pragma Depends was not matched in which case
20647 -- Check_Dependency_Clause reports the error.
20648
20649 -- 2) Refined_Depends has an extra clause in which case the error
20650 -- is reported by Report_Extra_Clauses.
20651
20652 Clause := First (Dependencies);
20653 while Present (Clause) loop
20654 Check_Dependency_Clause (Clause);
20655 Next (Clause);
20656 end loop;
20657 end if;
20658
20659 if Serious_Errors_Detected = Errors then
20660 Report_Extra_Clauses;
20661 end if;
20662 end Analyze_Refined_Depends_In_Decl_Part;
20663
20664 -----------------------------------------
20665 -- Analyze_Refined_Global_In_Decl_Part --
20666 -----------------------------------------
20667
20668 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
20669 Global : Node_Id;
20670 -- The corresponding Global pragma
20671
20672 Has_In_State : Boolean := False;
20673 Has_In_Out_State : Boolean := False;
20674 Has_Out_State : Boolean := False;
20675 -- These flags are set when the corresponding Global pragma has a state
20676 -- of mode Input, In_Out and Output respectively with a visible
20677 -- refinement.
20678
20679 Has_Null_State : Boolean := False;
20680 -- This flag is set when the corresponding Global pragma has at least
20681 -- one state with a null refinement.
20682
20683 In_Constits : Elist_Id := No_Elist;
20684 In_Out_Constits : Elist_Id := No_Elist;
20685 Out_Constits : Elist_Id := No_Elist;
20686 -- These lists contain the entities of all Input, In_Out and Output
20687 -- constituents that appear in Refined_Global and participate in state
20688 -- refinement.
20689
20690 In_Items : Elist_Id := No_Elist;
20691 In_Out_Items : Elist_Id := No_Elist;
20692 Out_Items : Elist_Id := No_Elist;
20693 -- These list contain the entities of all Input, In_Out and Output items
20694 -- defined in the corresponding Global pragma.
20695
20696 procedure Check_In_Out_States;
20697 -- Determine whether the corresponding Global pragma mentions In_Out
20698 -- states with visible refinement and if so, ensure that one of the
20699 -- following completions apply to the constituents of the state:
20700 -- 1) there is at least one constituent of mode In_Out
20701 -- 2) there is at least one Input and one Output constituent
20702 -- 3) not all constituents are present and one of them is of mode
20703 -- Output.
20704 -- This routine may remove elements from In_Constits, In_Out_Constits
20705 -- and Out_Constits.
20706
20707 procedure Check_Input_States;
20708 -- Determine whether the corresponding Global pragma mentions Input
20709 -- states with visible refinement and if so, ensure that at least one of
20710 -- its constituents appears as an Input item in Refined_Global.
20711 -- This routine may remove elements from In_Constits, In_Out_Constits
20712 -- and Out_Constits.
20713
20714 procedure Check_Output_States;
20715 -- Determine whether the corresponding Global pragma mentions Output
20716 -- states with visible refinement and if so, ensure that all of its
20717 -- constituents appear as Output items in Refined_Global. This routine
20718 -- may remove elements from In_Constits, In_Out_Constits and
20719 -- Out_Constits.
20720
20721 procedure Check_Refined_Global_List
20722 (List : Node_Id;
20723 Global_Mode : Name_Id := Name_Input);
20724 -- Verify the legality of a single global list declaration. Global_Mode
20725 -- denotes the current mode in effect.
20726
20727 function Present_Then_Remove
20728 (List : Elist_Id;
20729 Item : Entity_Id) return Boolean;
20730 -- Search List for a particular entity Item. If Item has been found,
20731 -- remove it from List. This routine is used to strip lists In_Constits,
20732 -- In_Out_Constits and Out_Constits of valid constituents.
20733
20734 procedure Report_Extra_Constituents;
20735 -- Emit an error for each constituent found in lists In_Constits,
20736 -- In_Out_Constits and Out_Constits.
20737
20738 -------------------------
20739 -- Check_In_Out_States --
20740 -------------------------
20741
20742 procedure Check_In_Out_States is
20743 procedure Check_Constituent_Usage (State_Id : Entity_Id);
20744 -- Determine whether one of the following coverage scenarios is in
20745 -- effect:
20746 -- 1) there is at least one constituent of mode In_Out
20747 -- 2) there is at least one Input and one Output constituent
20748 -- 3) not all constituents are present and one of them is of mode
20749 -- Output.
20750 -- If this is not the case, emit an error.
20751
20752 -----------------------------
20753 -- Check_Constituent_Usage --
20754 -----------------------------
20755
20756 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
20757 Constit_Elmt : Elmt_Id;
20758 Constit_Id : Entity_Id;
20759 Has_Missing : Boolean := False;
20760 In_Out_Seen : Boolean := False;
20761 In_Seen : Boolean := False;
20762 Out_Seen : Boolean := False;
20763
20764 begin
20765 -- Process all the constituents of the state and note their modes
20766 -- within the global refinement.
20767
20768 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
20769 while Present (Constit_Elmt) loop
20770 Constit_Id := Node (Constit_Elmt);
20771
20772 if Present_Then_Remove (In_Constits, Constit_Id) then
20773 In_Seen := True;
20774
20775 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
20776 In_Out_Seen := True;
20777
20778 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
20779 Out_Seen := True;
20780
20781 else
20782 Has_Missing := True;
20783 end if;
20784
20785 Next_Elmt (Constit_Elmt);
20786 end loop;
20787
20788 -- A single In_Out constituent is a valid completion
20789
20790 if In_Out_Seen then
20791 null;
20792
20793 -- A pair of one Input and one Output constituent is a valid
20794 -- completion.
20795
20796 elsif In_Seen and then Out_Seen then
20797 null;
20798
20799 -- A single Output constituent is a valid completion only when
20800 -- some of the other constituents are missing.
20801
20802 elsif Has_Missing and then Out_Seen then
20803 null;
20804
20805 else
20806 Error_Msg_NE
20807 ("global refinement of state & redefines the mode of its "
20808 & "constituents", N, State_Id);
20809 end if;
20810 end Check_Constituent_Usage;
20811
20812 -- Local variables
20813
20814 Item_Elmt : Elmt_Id;
20815 Item_Id : Entity_Id;
20816
20817 -- Start of processing for Check_In_Out_States
20818
20819 begin
20820 -- Inspect the In_Out items of the corresponding Global pragma
20821 -- looking for a state with a visible refinement.
20822
20823 if Has_In_Out_State and then Present (In_Out_Items) then
20824 Item_Elmt := First_Elmt (In_Out_Items);
20825 while Present (Item_Elmt) loop
20826 Item_Id := Node (Item_Elmt);
20827
20828 -- Ensure that one of the three coverage variants is satisfied
20829
20830 if Ekind (Item_Id) = E_Abstract_State
20831 and then Has_Non_Null_Refinement (Item_Id)
20832 then
20833 Check_Constituent_Usage (Item_Id);
20834 end if;
20835
20836 Next_Elmt (Item_Elmt);
20837 end loop;
20838 end if;
20839 end Check_In_Out_States;
20840
20841 ------------------------
20842 -- Check_Input_States --
20843 ------------------------
20844
20845 procedure Check_Input_States is
20846 procedure Check_Constituent_Usage (State_Id : Entity_Id);
20847 -- Determine whether at least one constituent of state State_Id with
20848 -- visible refinement is used and has mode Input. Ensure that the
20849 -- remaining constituents do not have In_Out or Output modes.
20850
20851 -----------------------------
20852 -- Check_Constituent_Usage --
20853 -----------------------------
20854
20855 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
20856 Constit_Elmt : Elmt_Id;
20857 Constit_Id : Entity_Id;
20858 In_Seen : Boolean := False;
20859
20860 begin
20861 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
20862 while Present (Constit_Elmt) loop
20863 Constit_Id := Node (Constit_Elmt);
20864
20865 -- At least one of the constituents appears as an Input
20866
20867 if Present_Then_Remove (In_Constits, Constit_Id) then
20868 In_Seen := True;
20869
20870 -- The constituent appears in the global refinement, but has
20871 -- mode In_Out or Output.
20872
20873 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
20874 or else Present_Then_Remove (Out_Constits, Constit_Id)
20875 then
20876 Error_Msg_Name_1 := Chars (State_Id);
20877 Error_Msg_NE
20878 ("constituent & of state % must have mode Input in global "
20879 & "refinement", N, Constit_Id);
20880 end if;
20881
20882 Next_Elmt (Constit_Elmt);
20883 end loop;
20884
20885 -- Not one of the constituents appeared as Input
20886
20887 if not In_Seen then
20888 Error_Msg_NE
20889 ("global refinement of state & must include at least one "
20890 & "constituent of mode Input", N, State_Id);
20891 end if;
20892 end Check_Constituent_Usage;
20893
20894 -- Local variables
20895
20896 Item_Elmt : Elmt_Id;
20897 Item_Id : Entity_Id;
20898
20899 -- Start of processing for Check_Input_States
20900
20901 begin
20902 -- Inspect the Input items of the corresponding Global pragma
20903 -- looking for a state with a visible refinement.
20904
20905 if Has_In_State and then Present (In_Items) then
20906 Item_Elmt := First_Elmt (In_Items);
20907 while Present (Item_Elmt) loop
20908 Item_Id := Node (Item_Elmt);
20909
20910 -- Ensure that at least one of the constituents is utilized and
20911 -- is of mode Input.
20912
20913 if Ekind (Item_Id) = E_Abstract_State
20914 and then Has_Non_Null_Refinement (Item_Id)
20915 then
20916 Check_Constituent_Usage (Item_Id);
20917 end if;
20918
20919 Next_Elmt (Item_Elmt);
20920 end loop;
20921 end if;
20922 end Check_Input_States;
20923
20924 -------------------------
20925 -- Check_Output_States --
20926 -------------------------
20927
20928 procedure Check_Output_States is
20929 procedure Check_Constituent_Usage (State_Id : Entity_Id);
20930 -- Determine whether all constituents of state State_Id with visible
20931 -- refinement are used and have mode Output. Emit an error if this is
20932 -- not the case.
20933
20934 -----------------------------
20935 -- Check_Constituent_Usage --
20936 -----------------------------
20937
20938 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
20939 Constit_Elmt : Elmt_Id;
20940 Constit_Id : Entity_Id;
20941
20942 begin
20943 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
20944 while Present (Constit_Elmt) loop
20945 Constit_Id := Node (Constit_Elmt);
20946
20947 if Present_Then_Remove (Out_Constits, Constit_Id) then
20948 null;
20949
20950 else
20951 Remove (In_Constits, Constit_Id);
20952 Remove (In_Out_Constits, Constit_Id);
20953
20954 Error_Msg_Name_1 := Chars (State_Id);
20955 Error_Msg_NE
20956 ("constituent & of state % must have mode Output in "
20957 & "global refinement", N, Constit_Id);
20958 end if;
20959
20960 Next_Elmt (Constit_Elmt);
20961 end loop;
20962 end Check_Constituent_Usage;
20963
20964 -- Local variables
20965
20966 Item_Elmt : Elmt_Id;
20967 Item_Id : Entity_Id;
20968
20969 -- Start of processing for Check_Output_States
20970
20971 begin
20972 -- Inspect the Output items of the corresponding Global pragma
20973 -- looking for a state with a visible refinement.
20974
20975 if Has_Out_State and then Present (Out_Items) then
20976 Item_Elmt := First_Elmt (Out_Items);
20977 while Present (Item_Elmt) loop
20978 Item_Id := Node (Item_Elmt);
20979
20980 -- Ensure that all of the constituents are utilized and they
20981 -- have mode Output.
20982
20983 if Ekind (Item_Id) = E_Abstract_State
20984 and then Has_Non_Null_Refinement (Item_Id)
20985 then
20986 Check_Constituent_Usage (Item_Id);
20987 end if;
20988
20989 Next_Elmt (Item_Elmt);
20990 end loop;
20991 end if;
20992 end Check_Output_States;
20993
20994 -------------------------------
20995 -- Check_Refined_Global_List --
20996 -------------------------------
20997
20998 procedure Check_Refined_Global_List
20999 (List : Node_Id;
21000 Global_Mode : Name_Id := Name_Input)
21001 is
21002 procedure Check_Refined_Global_Item
21003 (Item : Node_Id;
21004 Global_Mode : Name_Id);
21005 -- Verify the legality of a single global item declaration. Parameter
21006 -- Global_Mode denotes the current mode in effect.
21007
21008 -------------------------------
21009 -- Check_Refined_Global_Item --
21010 -------------------------------
21011
21012 procedure Check_Refined_Global_Item
21013 (Item : Node_Id;
21014 Global_Mode : Name_Id)
21015 is
21016 procedure Add_Constituent (Item_Id : Entity_Id);
21017 -- Add a single constituent to one of the three constituent lists
21018 -- depending on Global_Mode.
21019
21020 procedure Check_Matching_Modes (Item_Id : Entity_Id);
21021 -- Verify that the global modes of item Item_Id are the same in
21022 -- both pragmas Global and Refined_Global.
21023
21024 ---------------------
21025 -- Add_Constituent --
21026 ---------------------
21027
21028 procedure Add_Constituent (Item_Id : Entity_Id) is
21029 begin
21030 if Global_Mode = Name_Input then
21031 Add_Item (Item_Id, In_Constits);
21032
21033 elsif Global_Mode = Name_In_Out then
21034 Add_Item (Item_Id, In_Out_Constits);
21035
21036 elsif Global_Mode = Name_Output then
21037 Add_Item (Item_Id, Out_Constits);
21038 end if;
21039 end Add_Constituent;
21040
21041 --------------------------
21042 -- Check_Matching_Modes --
21043 --------------------------
21044
21045 procedure Check_Matching_Modes (Item_Id : Entity_Id) is
21046 procedure Inconsistent_Mode_Error (Expect : Name_Id);
21047 -- Issue a common error message for all mode mismatche. Expect
21048 -- denotes the expected mode.
21049
21050 -----------------------------
21051 -- Inconsistent_Mode_Error --
21052 -----------------------------
21053
21054 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
21055 begin
21056 Error_Msg_NE
21057 ("global item & has inconsistent modes", Item, Item_Id);
21058
21059 Error_Msg_Name_1 := Global_Mode;
21060 Error_Msg_N ("\ expected mode %", Item);
21061
21062 Error_Msg_Name_1 := Expect;
21063 Error_Msg_N ("\ found mode %", Item);
21064 end Inconsistent_Mode_Error;
21065
21066 -- Start processing for Check_Matching_Modes
21067
21068 begin
21069 if Contains (In_Items, Item_Id) then
21070 if Global_Mode /= Name_Input then
21071 Inconsistent_Mode_Error (Name_Input);
21072 end if;
21073
21074 elsif Contains (In_Out_Items, Item_Id) then
21075 if Global_Mode /= Name_In_Out then
21076 Inconsistent_Mode_Error (Name_In_Out);
21077 end if;
21078
21079 elsif Contains (Out_Items, Item_Id) then
21080 if Global_Mode /= Name_Output then
21081 Inconsistent_Mode_Error (Name_Output);
21082 end if;
21083
21084 -- The item does not appear in the corresponding Global aspect,
21085 -- it must be an extra.
21086
21087 else
21088 Error_Msg_NE ("extra global item &", Item, Item_Id);
21089 end if;
21090 end Check_Matching_Modes;
21091
21092 -- Local variables
21093
21094 Item_Id : constant Entity_Id := Entity_Of (Item);
21095
21096 -- Start of processing for Check_Refined_Global_Item
21097
21098 begin
21099 if Ekind (Item_Id) = E_Abstract_State then
21100
21101 -- The state is neither a constituent of an ancestor state nor
21102 -- has a visible refinement. Ensure that the modes of both its
21103 -- occurrences in Global and Refined_Global match.
21104
21105 if No (Refined_State (Item_Id))
21106 and then not Has_Visible_Refinement (Item_Id)
21107 then
21108 Check_Matching_Modes (Item_Id);
21109 end if;
21110
21111 else pragma Assert (Ekind (Item_Id) = E_Variable);
21112
21113 -- The variable acts as a constituent of a state, collect it
21114 -- for the state completeness checks performed later on.
21115
21116 if Present (Refined_State (Item_Id)) then
21117 Add_Constituent (Item_Id);
21118
21119 -- The variable is not a constituent. Ensure that the modes of
21120 -- both its occurrences in Global and Refined_Global match.
21121
21122 else
21123 Check_Matching_Modes (Item_Id);
21124 end if;
21125 end if;
21126 end Check_Refined_Global_Item;
21127
21128 -- Local variables
21129
21130 Item : Node_Id;
21131
21132 -- Start of processing for Check_Refined_Global_List
21133
21134 begin
21135 if Nkind (List) = N_Null then
21136 null;
21137
21138 -- Single global item declaration
21139
21140 elsif Nkind_In (List, N_Expanded_Name,
21141 N_Identifier,
21142 N_Selected_Component)
21143 then
21144 Check_Refined_Global_Item (List, Global_Mode);
21145
21146 -- Simple global list or moded global list declaration
21147
21148 elsif Nkind (List) = N_Aggregate then
21149
21150 -- The declaration of a simple global list appear as a collection
21151 -- of expressions.
21152
21153 if Present (Expressions (List)) then
21154 Item := First (Expressions (List));
21155 while Present (Item) loop
21156 Check_Refined_Global_Item (Item, Global_Mode);
21157
21158 Next (Item);
21159 end loop;
21160
21161 -- The declaration of a moded global list appears as a collection
21162 -- of component associations where individual choices denote
21163 -- modes.
21164
21165 elsif Present (Component_Associations (List)) then
21166 Item := First (Component_Associations (List));
21167 while Present (Item) loop
21168 Check_Refined_Global_List
21169 (List => Expression (Item),
21170 Global_Mode => Chars (First (Choices (Item))));
21171
21172 Next (Item);
21173 end loop;
21174
21175 -- Invalid tree
21176
21177 else
21178 raise Program_Error;
21179 end if;
21180
21181 -- Invalid list
21182
21183 else
21184 raise Program_Error;
21185 end if;
21186 end Check_Refined_Global_List;
21187
21188 -------------------------
21189 -- Present_Then_Remove --
21190 -------------------------
21191
21192 function Present_Then_Remove
21193 (List : Elist_Id;
21194 Item : Entity_Id) return Boolean
21195 is
21196 Elmt : Elmt_Id;
21197
21198 begin
21199 if Present (List) then
21200 Elmt := First_Elmt (List);
21201 while Present (Elmt) loop
21202 if Node (Elmt) = Item then
21203 Remove_Elmt (List, Elmt);
21204 return True;
21205 end if;
21206
21207 Next_Elmt (Elmt);
21208 end loop;
21209 end if;
21210
21211 return False;
21212 end Present_Then_Remove;
21213
21214 -------------------------------
21215 -- Report_Extra_Constituents --
21216 -------------------------------
21217
21218 procedure Report_Extra_Constituents is
21219 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
21220 -- Emit an error for every element of List
21221
21222 ---------------------------------------
21223 -- Report_Extra_Constituents_In_List --
21224 ---------------------------------------
21225
21226 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
21227 Constit_Elmt : Elmt_Id;
21228
21229 begin
21230 if Present (List) then
21231 Constit_Elmt := First_Elmt (List);
21232 while Present (Constit_Elmt) loop
21233 Error_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
21234 Next_Elmt (Constit_Elmt);
21235 end loop;
21236 end if;
21237 end Report_Extra_Constituents_In_List;
21238
21239 -- Start of processing for Report_Extra_Constituents
21240
21241 begin
21242 Report_Extra_Constituents_In_List (In_Constits);
21243 Report_Extra_Constituents_In_List (In_Out_Constits);
21244 Report_Extra_Constituents_In_List (Out_Constits);
21245 end Report_Extra_Constituents;
21246
21247 -- Local variables
21248
21249 Body_Decl : constant Node_Id := Parent (N);
21250 Errors : constant Nat := Serious_Errors_Detected;
21251 Items : constant Node_Id :=
21252 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
21253 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
21254
21255 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
21256
21257 begin
21258 Global := Get_Pragma (Spec_Id, Pragma_Global);
21259
21260 -- The subprogram declaration lacks pragma Global. This renders
21261 -- Refined_Global useless as there is nothing to refine.
21262
21263 if No (Global) then
21264 Error_Msg_NE
21265 ("useless refinement, subprogram & lacks global items", N, Spec_Id);
21266 return;
21267 end if;
21268
21269 -- Extract all relevant items from the corresponding Global pragma
21270
21271 Collect_Global_Items
21272 (Prag => Global,
21273 In_Items => In_Items,
21274 In_Out_Items => In_Out_Items,
21275 Out_Items => Out_Items,
21276 Has_In_State => Has_In_State,
21277 Has_In_Out_State => Has_In_Out_State,
21278 Has_Out_State => Has_Out_State,
21279 Has_Null_State => Has_Null_State);
21280
21281 -- The corresponding Global pragma must mention at least one state with
21282 -- a visible refinement at the point Refined_Global is processed. States
21283 -- with null refinements warrant a Refined_Global pragma.
21284
21285 if not Has_In_State
21286 and then not Has_In_Out_State
21287 and then not Has_Out_State
21288 and then not Has_Null_State
21289 then
21290 Error_Msg_NE
21291 ("useless refinement, subprogram & does not mention abstract state "
21292 & "with visible refinement", N, Spec_Id);
21293 return;
21294 end if;
21295
21296 -- The global refinement of inputs and outputs cannot be null when the
21297 -- corresponding Global pragma contains at least one item except in the
21298 -- case where we have states with null refinements.
21299
21300 if Nkind (Items) = N_Null
21301 and then
21302 (Present (In_Items)
21303 or else Present (In_Out_Items)
21304 or else Present (Out_Items))
21305 and then not Has_Null_State
21306 then
21307 Error_Msg_NE
21308 ("refinement cannot be null, subprogram & has global items",
21309 N, Spec_Id);
21310 return;
21311 end if;
21312
21313 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
21314 -- This ensures that the categorization of all refined global items is
21315 -- consistent with their role.
21316
21317 Analyze_Global_In_Decl_Part (N);
21318
21319 -- Perform all refinement checks with respect to completeness and mode
21320 -- matching.
21321
21322 if Serious_Errors_Detected = Errors then
21323 Check_Refined_Global_List (Items);
21324 end if;
21325
21326 -- For Input states with visible refinement, at least one constituent
21327 -- must be used as an Input in the global refinement.
21328
21329 if Serious_Errors_Detected = Errors then
21330 Check_Input_States;
21331 end if;
21332
21333 -- Verify all possible completion variants for In_Out states with
21334 -- visible refinement.
21335
21336 if Serious_Errors_Detected = Errors then
21337 Check_In_Out_States;
21338 end if;
21339
21340 -- For Output states with visible refinement, all constituents must be
21341 -- used as Outputs in the global refinement.
21342
21343 if Serious_Errors_Detected = Errors then
21344 Check_Output_States;
21345 end if;
21346
21347 -- Emit errors for all constituents that belong to other states with
21348 -- visible refinement that do not appear in Global.
21349
21350 if Serious_Errors_Detected = Errors then
21351 Report_Extra_Constituents;
21352 end if;
21353 end Analyze_Refined_Global_In_Decl_Part;
21354
21355 ----------------------------------------
21356 -- Analyze_Refined_State_In_Decl_Part --
21357 ----------------------------------------
21358
21359 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
21360 Pack_Body : constant Node_Id := Parent (N);
21361 Spec_Id : constant Entity_Id := Corresponding_Spec (Pack_Body);
21362
21363 Abstr_States : Elist_Id := No_Elist;
21364 -- A list of all abstract states defined in the package declaration. The
21365 -- list is used to report unrefined states.
21366
21367 Constituents_Seen : Elist_Id := No_Elist;
21368 -- A list that contains all constituents processed so far. The list is
21369 -- used to detect multiple uses of the same constituent.
21370
21371 Hidden_States : Elist_Id := No_Elist;
21372 -- A list of all hidden states (abstract states and variables) that
21373 -- appear in the package spec and body. The list is used to report
21374 -- unused hidden states.
21375
21376 Refined_States_Seen : Elist_Id := No_Elist;
21377 -- A list that contains all refined states processed so far. The list is
21378 -- used to detect duplicate refinements.
21379
21380 procedure Analyze_Refinement_Clause (Clause : Node_Id);
21381 -- Perform full analysis of a single refinement clause
21382
21383 procedure Collect_Hidden_States;
21384 -- Gather the entities of all hidden states that appear in the spec and
21385 -- body of the related package in Hidden_States.
21386
21387 procedure Report_Unrefined_States;
21388 -- Emit errors for all abstract states that have not been refined by
21389 -- the pragma.
21390
21391 procedure Report_Unused_Hidden_States;
21392 -- Emit errors for all hidden states of the related package that do not
21393 -- participate in a refinement.
21394
21395 -------------------------------
21396 -- Analyze_Refinement_Clause --
21397 -------------------------------
21398
21399 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
21400 State_Id : Entity_Id := Empty;
21401 -- The entity of the state being refined in the current clause
21402
21403 Non_Null_Seen : Boolean := False;
21404 Null_Seen : Boolean := False;
21405 -- Flags used to detect multiple uses of null in a single clause or a
21406 -- mixture of null and non-null constituents.
21407
21408 procedure Analyze_Constituent (Constit : Node_Id);
21409 -- Perform full analysis of a single constituent
21410
21411 procedure Check_Matching_State
21412 (State : Node_Id;
21413 State_Id : Entity_Id);
21414 -- Determine whether state State denoted by its name State_Id appears
21415 -- in Abstr_States. Emit an error when attempting to re-refine the
21416 -- state or when the state is not defined in the package declaration.
21417 -- Otherwise remove the state from Abstr_States.
21418
21419 -------------------------
21420 -- Analyze_Constituent --
21421 -------------------------
21422
21423 procedure Analyze_Constituent (Constit : Node_Id) is
21424 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
21425 -- Determine whether constituent Constit denoted by its entity
21426 -- Constit_Id appears in Hidden_States. Emit an error when the
21427 -- constituent is not a valid hidden state of the related package
21428 -- or when it is used more than once. Otherwise remove the
21429 -- constituent from Hidden_States.
21430
21431 --------------------------------
21432 -- Check_Matching_Constituent --
21433 --------------------------------
21434
21435 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
21436 State_Elmt : Elmt_Id;
21437
21438 begin
21439 -- Detect a duplicate use of a constituent
21440
21441 if Contains (Constituents_Seen, Constit_Id) then
21442 Error_Msg_NE
21443 ("duplicate use of constituent &", Constit, Constit_Id);
21444 return;
21445
21446 -- A state can act as a constituent only when it is part of
21447 -- another state. This relation is expressed by option Part_Of
21448 -- of pragma Abstract_State.
21449
21450 elsif Ekind (Constit_Id) = E_Abstract_State then
21451 if not Is_Part_Of (Constit_Id, State_Id) then
21452 Error_Msg_Name_1 := Chars (State_Id);
21453 Error_Msg_NE
21454 ("state & is not a valid constituent of ancestor "
21455 & "state %", Constit, Constit_Id);
21456 return;
21457
21458 -- The constituent has the proper Part_Of option, but may
21459 -- not appear in the immediate hidden state of the related
21460 -- package. This case arises when the constituent comes from
21461 -- a private child or a private sibling. Recognize these
21462 -- scenarios to avoid generating a bogus error message.
21463
21464 elsif Is_Child_Or_Sibling
21465 (Pack_1 => Scope (State_Id),
21466 Pack_2 => Scope (Constit_Id),
21467 Private_Child => True)
21468 then
21469 return;
21470 end if;
21471 end if;
21472
21473 -- Inspect the hidden states of the related package looking for
21474 -- a match.
21475
21476 if Present (Hidden_States) then
21477 State_Elmt := First_Elmt (Hidden_States);
21478 while Present (State_Elmt) loop
21479
21480 -- A valid hidden state or variable acts as a constituent
21481
21482 if Node (State_Elmt) = Constit_Id then
21483
21484 -- Add the constituent to the lis of processed items
21485 -- to aid with the detection of duplicates. Remove the
21486 -- constituent from Hidden_States to signal that it
21487 -- has already been matched.
21488
21489 Add_Item (Constit_Id, Constituents_Seen);
21490 Remove_Elmt (Hidden_States, State_Elmt);
21491
21492 -- Collect the constituent in the list of refinement
21493 -- items. Establish a relation between the refined
21494 -- state and its constituent.
21495
21496 Append_Elmt
21497 (Constit_Id, Refinement_Constituents (State_Id));
21498 Set_Refined_State (Constit_Id, State_Id);
21499
21500 -- The state has at least one legal constituent, mark
21501 -- the start of the refinement region. The region ends
21502 -- when the body declarations end (see routine
21503 -- Analyze_Declarations).
21504
21505 Set_Has_Visible_Refinement (State_Id);
21506
21507 return;
21508 end if;
21509
21510 Next_Elmt (State_Elmt);
21511 end loop;
21512 end if;
21513
21514 -- If we get here, we are refining a state that is not hidden
21515 -- with respect to the related package.
21516
21517 Error_Msg_Name_1 := Chars (Spec_Id);
21518 Error_Msg_NE
21519 ("cannot use & in refinement, constituent is not a hidden "
21520 & "state of package %", Constit, Constit_Id);
21521 end Check_Matching_Constituent;
21522
21523 -- Local variables
21524
21525 Constit_Id : Entity_Id;
21526
21527 -- Start of processing for Analyze_Constituent
21528
21529 begin
21530 -- Detect multiple uses of null in a single refinement clause or a
21531 -- mixture of null and non-null constituents.
21532
21533 if Nkind (Constit) = N_Null then
21534 if Null_Seen then
21535 Error_Msg_N
21536 ("multiple null constituents not allowed", Constit);
21537
21538 elsif Non_Null_Seen then
21539 Error_Msg_N
21540 ("cannot mix null and non-null constituents", Constit);
21541
21542 else
21543 Null_Seen := True;
21544
21545 -- Collect the constituent in the list of refinement items
21546
21547 Append_Elmt (Constit, Refinement_Constituents (State_Id));
21548
21549 -- The state has at least one legal constituent, mark the
21550 -- start of the refinement region. The region ends when the
21551 -- body declarations end (see Analyze_Declarations).
21552
21553 Set_Has_Visible_Refinement (State_Id);
21554 end if;
21555
21556 -- Non-null constituents
21557
21558 else
21559 Non_Null_Seen := True;
21560
21561 if Null_Seen then
21562 Error_Msg_N
21563 ("cannot mix null and non-null constituents", Constit);
21564 end if;
21565
21566 Analyze (Constit);
21567
21568 -- Ensure that the constituent denotes a valid state or a
21569 -- whole variable.
21570
21571 if Is_Entity_Name (Constit) then
21572 Constit_Id := Entity (Constit);
21573
21574 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
21575 Check_Matching_Constituent (Constit_Id);
21576
21577 else
21578 Error_Msg_NE
21579 ("constituent & must denote a variable or state",
21580 Constit, Constit_Id);
21581 end if;
21582
21583 -- The constituent is illegal
21584
21585 else
21586 Error_Msg_N ("malformed constituent", Constit);
21587 end if;
21588 end if;
21589 end Analyze_Constituent;
21590
21591 --------------------------
21592 -- Check_Matching_State --
21593 --------------------------
21594
21595 procedure Check_Matching_State
21596 (State : Node_Id;
21597 State_Id : Entity_Id)
21598 is
21599 State_Elmt : Elmt_Id;
21600
21601 begin
21602 -- Detect a duplicate refinement of a state
21603
21604 if Contains (Refined_States_Seen, State_Id) then
21605 Error_Msg_NE
21606 ("duplicate refinement of state &", State, State_Id);
21607 return;
21608 end if;
21609
21610 -- Inspect the abstract states defined in the package declaration
21611 -- looking for a match.
21612
21613 State_Elmt := First_Elmt (Abstr_States);
21614 while Present (State_Elmt) loop
21615
21616 -- A valid abstract state is being refined in the body. Add
21617 -- the state to the list of processed refined states to aid
21618 -- with the detection of duplicate refinements. Remove the
21619 -- state from Abstr_States to signal that it has already been
21620 -- refined.
21621
21622 if Node (State_Elmt) = State_Id then
21623 Add_Item (State_Id, Refined_States_Seen);
21624 Remove_Elmt (Abstr_States, State_Elmt);
21625 return;
21626 end if;
21627
21628 Next_Elmt (State_Elmt);
21629 end loop;
21630
21631 -- If we get here, we are refining a state that is not defined in
21632 -- the package declaration.
21633
21634 Error_Msg_Name_1 := Chars (Spec_Id);
21635 Error_Msg_NE
21636 ("cannot refine state, & is not defined in package %",
21637 State, State_Id);
21638 end Check_Matching_State;
21639
21640 -- Local declarations
21641
21642 Constit : Node_Id;
21643 State : Node_Id;
21644
21645 -- Start of processing for Analyze_Refinement_Clause
21646
21647 begin
21648 -- Analyze the state name of a refinement clause
21649
21650 State := First (Choices (Clause));
21651 while Present (State) loop
21652 if Present (State_Id) then
21653 Error_Msg_N
21654 ("refinement clause cannot cover multiple states", State);
21655
21656 else
21657 Analyze (State);
21658
21659 -- Ensure that the state name denotes a valid abstract state
21660 -- that is defined in the spec of the related package.
21661
21662 if Is_Entity_Name (State) then
21663 State_Id := Entity (State);
21664
21665 -- Catch any attempts to re-refine a state or refine a
21666 -- state that is not defined in the package declaration.
21667
21668 if Ekind (State_Id) = E_Abstract_State then
21669 Check_Matching_State (State, State_Id);
21670 else
21671 Error_Msg_NE
21672 ("& must denote an abstract state", State, State_Id);
21673 end if;
21674
21675 -- Enforce SPARK RM (6.1.5(4)): A global item shall not
21676 -- denote a state abstraction whose refinement is visible
21677 -- (a state abstraction cannot be named within its enclosing
21678 -- package's body other than in its refinement).
21679
21680 if Has_Body_References (State_Id) then
21681 declare
21682 Ref : Elmt_Id;
21683 Nod : Node_Id;
21684 begin
21685 Ref := First_Elmt (Body_References (State_Id));
21686 while Present (Ref) loop
21687 Nod := Node (Ref);
21688 Error_Msg_N
21689 ("global reference to & not allowed "
21690 & "(SPARK RM 6.1.5(4))", Nod);
21691 Error_Msg_Sloc := Sloc (State);
21692 Error_Msg_N ("\refinement of & is visible#", Nod);
21693 Next_Elmt (Ref);
21694 end loop;
21695 end;
21696 end if;
21697
21698 -- The state name is illegal
21699
21700 else
21701 Error_Msg_N
21702 ("malformed state name in refinement clause", State);
21703 end if;
21704 end if;
21705
21706 Next (State);
21707 end loop;
21708
21709 -- Analyze all constituents of the refinement. Multiple constituents
21710 -- appear as an aggregate.
21711
21712 Constit := Expression (Clause);
21713
21714 if Nkind (Constit) = N_Aggregate then
21715 if Present (Component_Associations (Constit)) then
21716 Error_Msg_N
21717 ("constituents of refinement clause must appear in "
21718 & "positional form", Constit);
21719
21720 else pragma Assert (Present (Expressions (Constit)));
21721 Constit := First (Expressions (Constit));
21722 while Present (Constit) loop
21723 Analyze_Constituent (Constit);
21724
21725 Next (Constit);
21726 end loop;
21727 end if;
21728
21729 -- Various forms of a single constituent. Note that these may include
21730 -- malformed constituents.
21731
21732 else
21733 Analyze_Constituent (Constit);
21734 end if;
21735 end Analyze_Refinement_Clause;
21736
21737 ---------------------------
21738 -- Collect_Hidden_States --
21739 ---------------------------
21740
21741 procedure Collect_Hidden_States is
21742 procedure Collect_Hidden_States_In_Decls (Decls : List_Id);
21743 -- Find all hidden states that appear in declarative list Decls and
21744 -- append their entities to Result.
21745
21746 ------------------------------------
21747 -- Collect_Hidden_States_In_Decls --
21748 ------------------------------------
21749
21750 procedure Collect_Hidden_States_In_Decls (Decls : List_Id) is
21751 procedure Collect_Abstract_States (States : Elist_Id);
21752 -- Copy the abstract states defined in list States to list Result
21753
21754 -----------------------------
21755 -- Collect_Abstract_States --
21756 -----------------------------
21757
21758 procedure Collect_Abstract_States (States : Elist_Id) is
21759 State_Elmt : Elmt_Id;
21760
21761 begin
21762 State_Elmt := First_Elmt (States);
21763 while Present (State_Elmt) loop
21764 Add_Item (Node (State_Elmt), Hidden_States);
21765
21766 Next_Elmt (State_Elmt);
21767 end loop;
21768 end Collect_Abstract_States;
21769
21770 -- Local variables
21771
21772 Decl : Node_Id;
21773
21774 -- Start of processing for Collect_Hidden_States_In_Decls
21775
21776 begin
21777 Decl := First (Decls);
21778 while Present (Decl) loop
21779
21780 -- Source objects (non-constants) are valid hidden states
21781
21782 if Nkind (Decl) = N_Object_Declaration
21783 and then Ekind (Defining_Entity (Decl)) = E_Variable
21784 and then Comes_From_Source (Decl)
21785 then
21786 Add_Item (Defining_Entity (Decl), Hidden_States);
21787
21788 -- Gather the abstract states of a package along with all
21789 -- hidden states in its visible declarations.
21790
21791 elsif Nkind (Decl) = N_Package_Declaration then
21792 Collect_Abstract_States
21793 (Abstract_States (Defining_Entity (Decl)));
21794
21795 Collect_Hidden_States_In_Decls
21796 (Visible_Declarations (Specification (Decl)));
21797 end if;
21798
21799 Next (Decl);
21800 end loop;
21801 end Collect_Hidden_States_In_Decls;
21802
21803 -- Local variables
21804
21805 Pack_Spec : constant Node_Id := Package_Specification (Spec_Id);
21806
21807 -- Start of processing for Collect_Hidden_States
21808
21809 begin
21810 -- Process the private declarations of the package spec and the
21811 -- declarations of the body.
21812
21813 Collect_Hidden_States_In_Decls (Private_Declarations (Pack_Spec));
21814 Collect_Hidden_States_In_Decls (Declarations (Pack_Body));
21815 end Collect_Hidden_States;
21816
21817 -----------------------------
21818 -- Report_Unrefined_States --
21819 -----------------------------
21820
21821 procedure Report_Unrefined_States is
21822 State_Elmt : Elmt_Id;
21823
21824 begin
21825 if Present (Abstr_States) then
21826 State_Elmt := First_Elmt (Abstr_States);
21827 while Present (State_Elmt) loop
21828 Error_Msg_N
21829 ("abstract state & must be refined", Node (State_Elmt));
21830
21831 Next_Elmt (State_Elmt);
21832 end loop;
21833 end if;
21834 end Report_Unrefined_States;
21835
21836 ---------------------------------
21837 -- Report_Unused_Hidden_States --
21838 ---------------------------------
21839
21840 procedure Report_Unused_Hidden_States is
21841 Posted : Boolean := False;
21842 State_Elmt : Elmt_Id;
21843 State_Id : Entity_Id;
21844
21845 begin
21846 if Present (Hidden_States) then
21847 State_Elmt := First_Elmt (Hidden_States);
21848 while Present (State_Elmt) loop
21849 State_Id := Node (State_Elmt);
21850
21851 -- Generate an error message of the form:
21852
21853 -- package ... has unused hidden states
21854 -- abstract state ... defined at ...
21855 -- variable ... defined at ...
21856
21857 if not Posted then
21858 Posted := True;
21859 Error_Msg_NE
21860 ("package & has unused hidden states", N, Spec_Id);
21861 end if;
21862
21863 Error_Msg_Sloc := Sloc (State_Id);
21864
21865 if Ekind (State_Id) = E_Abstract_State then
21866 Error_Msg_NE ("\ abstract state & defined #", N, State_Id);
21867 else
21868 Error_Msg_NE ("\ variable & defined #", N, State_Id);
21869 end if;
21870
21871 Next_Elmt (State_Elmt);
21872 end loop;
21873 end if;
21874 end Report_Unused_Hidden_States;
21875
21876 -- Local declarations
21877
21878 Clauses : constant Node_Id :=
21879 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
21880 Clause : Node_Id;
21881
21882 -- Start of processing for Analyze_Refined_State_In_Decl_Part
21883
21884 begin
21885 Set_Analyzed (N);
21886
21887 -- Initialize the various lists used during analysis
21888
21889 Abstr_States := New_Copy_Elist (Abstract_States (Spec_Id));
21890 Collect_Hidden_States;
21891
21892 -- Multiple state refinements appear as an aggregate
21893
21894 if Nkind (Clauses) = N_Aggregate then
21895 if Present (Expressions (Clauses)) then
21896 Error_Msg_N
21897 ("state refinements must appear as component associations",
21898 Clauses);
21899
21900 else pragma Assert (Present (Component_Associations (Clauses)));
21901 Clause := First (Component_Associations (Clauses));
21902 while Present (Clause) loop
21903 Analyze_Refinement_Clause (Clause);
21904
21905 Next (Clause);
21906 end loop;
21907 end if;
21908
21909 -- Various forms of a single state refinement. Note that these may
21910 -- include malformed refinements.
21911
21912 else
21913 Analyze_Refinement_Clause (Clauses);
21914 end if;
21915
21916 -- Ensure that all abstract states have been refined and all hidden
21917 -- states of the related package unilized in refinements.
21918
21919 Report_Unrefined_States;
21920 Report_Unused_Hidden_States;
21921 end Analyze_Refined_State_In_Decl_Part;
21922
21923 ------------------------------------
21924 -- Analyze_Test_Case_In_Decl_Part --
21925 ------------------------------------
21926
21927 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
21928 begin
21929 -- Install formals and push subprogram spec onto scope stack so that we
21930 -- can see the formals from the pragma.
21931
21932 Push_Scope (S);
21933 Install_Formals (S);
21934
21935 -- Preanalyze the boolean expressions, we treat these as spec
21936 -- expressions (i.e. similar to a default expression).
21937
21938 if Pragma_Name (N) = Name_Test_Case then
21939 Preanalyze_CTC_Args
21940 (N,
21941 Get_Requires_From_CTC_Pragma (N),
21942 Get_Ensures_From_CTC_Pragma (N));
21943 end if;
21944
21945 -- Remove the subprogram from the scope stack now that the pre-analysis
21946 -- of the expressions in the contract case or test case is done.
21947
21948 End_Scope;
21949 end Analyze_Test_Case_In_Decl_Part;
21950
21951 ----------------
21952 -- Appears_In --
21953 ----------------
21954
21955 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
21956 Elmt : Elmt_Id;
21957 Id : Entity_Id;
21958
21959 begin
21960 if Present (List) then
21961 Elmt := First_Elmt (List);
21962 while Present (Elmt) loop
21963 if Nkind (Node (Elmt)) = N_Defining_Identifier then
21964 Id := Node (Elmt);
21965 else
21966 Id := Entity (Node (Elmt));
21967 end if;
21968
21969 if Id = Item_Id then
21970 return True;
21971 end if;
21972
21973 Next_Elmt (Elmt);
21974 end loop;
21975 end if;
21976
21977 return False;
21978 end Appears_In;
21979
21980 ----------------
21981 -- Check_Kind --
21982 ----------------
21983
21984 function Check_Kind (Nam : Name_Id) return Name_Id is
21985 PP : Node_Id;
21986
21987 begin
21988 -- Loop through entries in check policy list
21989
21990 PP := Opt.Check_Policy_List;
21991 while Present (PP) loop
21992 declare
21993 PPA : constant List_Id := Pragma_Argument_Associations (PP);
21994 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
21995
21996 begin
21997 if Nam = Pnm
21998 or else (Pnm = Name_Assertion
21999 and then Is_Valid_Assertion_Kind (Nam))
22000 or else (Pnm = Name_Statement_Assertions
22001 and then Nam_In (Nam, Name_Assert,
22002 Name_Assert_And_Cut,
22003 Name_Assume,
22004 Name_Loop_Invariant))
22005 then
22006 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
22007 when Name_On | Name_Check =>
22008 return Name_Check;
22009 when Name_Off | Name_Ignore =>
22010 return Name_Ignore;
22011 when Name_Disable =>
22012 return Name_Disable;
22013 when others =>
22014 raise Program_Error;
22015 end case;
22016
22017 else
22018 PP := Next_Pragma (PP);
22019 end if;
22020 end;
22021 end loop;
22022
22023 -- If there are no specific entries that matched, then we let the
22024 -- setting of assertions govern. Note that this provides the needed
22025 -- compatibility with the RM for the cases of assertion, invariant,
22026 -- precondition, predicate, and postcondition.
22027
22028 if Assertions_Enabled then
22029 return Name_Check;
22030 else
22031 return Name_Ignore;
22032 end if;
22033 end Check_Kind;
22034
22035 -----------------------------
22036 -- Check_Applicable_Policy --
22037 -----------------------------
22038
22039 procedure Check_Applicable_Policy (N : Node_Id) is
22040 PP : Node_Id;
22041 Policy : Name_Id;
22042
22043 Ename : constant Name_Id := Original_Aspect_Name (N);
22044
22045 begin
22046 -- No effect if not valid assertion kind name
22047
22048 if not Is_Valid_Assertion_Kind (Ename) then
22049 return;
22050 end if;
22051
22052 -- Loop through entries in check policy list
22053
22054 PP := Opt.Check_Policy_List;
22055 while Present (PP) loop
22056 declare
22057 PPA : constant List_Id := Pragma_Argument_Associations (PP);
22058 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
22059
22060 begin
22061 if Ename = Pnm
22062 or else Pnm = Name_Assertion
22063 or else (Pnm = Name_Statement_Assertions
22064 and then (Ename = Name_Assert or else
22065 Ename = Name_Assert_And_Cut or else
22066 Ename = Name_Assume or else
22067 Ename = Name_Loop_Invariant))
22068 then
22069 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
22070
22071 case Policy is
22072 when Name_Off | Name_Ignore =>
22073 Set_Is_Ignored (N, True);
22074 Set_Is_Checked (N, False);
22075
22076 when Name_On | Name_Check =>
22077 Set_Is_Checked (N, True);
22078 Set_Is_Ignored (N, False);
22079
22080 when Name_Disable =>
22081 Set_Is_Ignored (N, True);
22082 Set_Is_Checked (N, False);
22083 Set_Is_Disabled (N, True);
22084
22085 -- That should be exhaustive, the null here is a defence
22086 -- against a malformed tree from previous errors.
22087
22088 when others =>
22089 null;
22090 end case;
22091
22092 return;
22093 end if;
22094
22095 PP := Next_Pragma (PP);
22096 end;
22097 end loop;
22098
22099 -- If there are no specific entries that matched, then we let the
22100 -- setting of assertions govern. Note that this provides the needed
22101 -- compatibility with the RM for the cases of assertion, invariant,
22102 -- precondition, predicate, and postcondition.
22103
22104 if Assertions_Enabled then
22105 Set_Is_Checked (N, True);
22106 Set_Is_Ignored (N, False);
22107 else
22108 Set_Is_Checked (N, False);
22109 Set_Is_Ignored (N, True);
22110 end if;
22111 end Check_Applicable_Policy;
22112
22113 --------------------------
22114 -- Collect_Global_Items --
22115 --------------------------
22116
22117 procedure Collect_Global_Items
22118 (Prag : Node_Id;
22119 In_Items : in out Elist_Id;
22120 In_Out_Items : in out Elist_Id;
22121 Out_Items : in out Elist_Id;
22122 Has_In_State : out Boolean;
22123 Has_In_Out_State : out Boolean;
22124 Has_Out_State : out Boolean;
22125 Has_Null_State : out Boolean)
22126 is
22127 procedure Process_Global_List
22128 (List : Node_Id;
22129 Mode : Name_Id := Name_Input);
22130 -- Collect all items housed in a global list. Formal Mode denotes the
22131 -- current mode in effect.
22132
22133 -------------------------
22134 -- Process_Global_List --
22135 -------------------------
22136
22137 procedure Process_Global_List
22138 (List : Node_Id;
22139 Mode : Name_Id := Name_Input)
22140 is
22141 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id);
22142 -- Add a single item to the appropriate list. Formal Mode denotes the
22143 -- current mode in effect.
22144
22145 -------------------------
22146 -- Process_Global_Item --
22147 -------------------------
22148
22149 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
22150 Item_Id : constant Entity_Id := Entity_Of (Item);
22151
22152 begin
22153 -- Signal that the global list contains at least one abstract
22154 -- state with a visible refinement. Note that the refinement may
22155 -- be null in which case there are no constituents.
22156
22157 if Ekind (Item_Id) = E_Abstract_State then
22158 if Has_Null_Refinement (Item_Id) then
22159 Has_Null_State := True;
22160
22161 elsif Has_Non_Null_Refinement (Item_Id) then
22162 if Mode = Name_Input then
22163 Has_In_State := True;
22164 elsif Mode = Name_In_Out then
22165 Has_In_Out_State := True;
22166 elsif Mode = Name_Output then
22167 Has_Out_State := True;
22168 end if;
22169 end if;
22170 end if;
22171
22172 -- Add the item to the proper list
22173
22174 if Mode = Name_Input then
22175 Add_Item (Item_Id, In_Items);
22176 elsif Mode = Name_In_Out then
22177 Add_Item (Item_Id, In_Out_Items);
22178 elsif Mode = Name_Output then
22179 Add_Item (Item_Id, Out_Items);
22180 end if;
22181 end Process_Global_Item;
22182
22183 -- Local variables
22184
22185 Item : Node_Id;
22186
22187 -- Start of processing for Process_Global_List
22188
22189 begin
22190 if Nkind (List) = N_Null then
22191 null;
22192
22193 -- Single global item declaration
22194
22195 elsif Nkind_In (List, N_Expanded_Name,
22196 N_Identifier,
22197 N_Selected_Component)
22198 then
22199 Process_Global_Item (List, Mode);
22200
22201 -- Single global list or moded global list declaration
22202
22203 elsif Nkind (List) = N_Aggregate then
22204
22205 -- The declaration of a simple global list appear as a collection
22206 -- of expressions.
22207
22208 if Present (Expressions (List)) then
22209 Item := First (Expressions (List));
22210 while Present (Item) loop
22211 Process_Global_Item (Item, Mode);
22212
22213 Next (Item);
22214 end loop;
22215
22216 -- The declaration of a moded global list appears as a collection
22217 -- of component associations where individual choices denote mode.
22218
22219 elsif Present (Component_Associations (List)) then
22220 Item := First (Component_Associations (List));
22221 while Present (Item) loop
22222 Process_Global_List
22223 (List => Expression (Item),
22224 Mode => Chars (First (Choices (Item))));
22225
22226 Next (Item);
22227 end loop;
22228
22229 -- Invalid tree
22230
22231 else
22232 raise Program_Error;
22233 end if;
22234
22235 -- Invalid list
22236
22237 else
22238 raise Program_Error;
22239 end if;
22240 end Process_Global_List;
22241
22242 -- Local variables
22243
22244 Items : constant Node_Id :=
22245 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
22246
22247 -- Start of processing for Collect_Global_Items
22248
22249 begin
22250 -- Assume that no states have been encountered
22251
22252 Has_In_State := False;
22253 Has_In_Out_State := False;
22254 Has_Out_State := False;
22255 Has_Null_State := False;
22256
22257 Process_Global_List (Items);
22258 end Collect_Global_Items;
22259
22260 ---------------------------------------
22261 -- Collect_Subprogram_Inputs_Outputs --
22262 ---------------------------------------
22263
22264 procedure Collect_Subprogram_Inputs_Outputs
22265 (Subp_Id : Entity_Id;
22266 Subp_Inputs : in out Elist_Id;
22267 Subp_Outputs : in out Elist_Id;
22268 Global_Seen : out Boolean)
22269 is
22270 procedure Collect_Global_List
22271 (List : Node_Id;
22272 Mode : Name_Id := Name_Input);
22273 -- Collect all relevant items from a global list
22274
22275 -------------------------
22276 -- Collect_Global_List --
22277 -------------------------
22278
22279 procedure Collect_Global_List
22280 (List : Node_Id;
22281 Mode : Name_Id := Name_Input)
22282 is
22283 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
22284 -- Add an item to the proper subprogram input or output collection
22285
22286 -------------------------
22287 -- Collect_Global_Item --
22288 -------------------------
22289
22290 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
22291 begin
22292 if Nam_In (Mode, Name_In_Out, Name_Input) then
22293 Add_Item (Item, Subp_Inputs);
22294 end if;
22295
22296 if Nam_In (Mode, Name_In_Out, Name_Output) then
22297 Add_Item (Item, Subp_Outputs);
22298 end if;
22299 end Collect_Global_Item;
22300
22301 -- Local variables
22302
22303 Assoc : Node_Id;
22304 Item : Node_Id;
22305
22306 -- Start of processing for Collect_Global_List
22307
22308 begin
22309 if Nkind (List) = N_Null then
22310 null;
22311
22312 -- Single global item declaration
22313
22314 elsif Nkind_In (List, N_Expanded_Name,
22315 N_Identifier,
22316 N_Selected_Component)
22317 then
22318 Collect_Global_Item (List, Mode);
22319
22320 -- Simple global list or moded global list declaration
22321
22322 elsif Nkind (List) = N_Aggregate then
22323 if Present (Expressions (List)) then
22324 Item := First (Expressions (List));
22325 while Present (Item) loop
22326 Collect_Global_Item (Item, Mode);
22327 Next (Item);
22328 end loop;
22329
22330 else
22331 Assoc := First (Component_Associations (List));
22332 while Present (Assoc) loop
22333 Collect_Global_List
22334 (List => Expression (Assoc),
22335 Mode => Chars (First (Choices (Assoc))));
22336 Next (Assoc);
22337 end loop;
22338 end if;
22339
22340 -- Invalid list
22341
22342 else
22343 raise Program_Error;
22344 end if;
22345 end Collect_Global_List;
22346
22347 -- Local variables
22348
22349 Formal : Entity_Id;
22350 Global : Node_Id;
22351 List : Node_Id;
22352 Spec_Id : Entity_Id;
22353
22354 -- Start of processing for Collect_Subprogram_Inputs_Outputs
22355
22356 begin
22357 Global_Seen := False;
22358
22359 -- Find the entity of the corresponding spec when processing a body
22360
22361 if Ekind (Subp_Id) = E_Subprogram_Body then
22362 Spec_Id := Corresponding_Spec (Parent (Parent (Subp_Id)));
22363 else
22364 Spec_Id := Subp_Id;
22365 end if;
22366
22367 -- Process all formal parameters
22368
22369 Formal := First_Formal (Spec_Id);
22370 while Present (Formal) loop
22371 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
22372 Add_Item (Formal, Subp_Inputs);
22373 end if;
22374
22375 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
22376 Add_Item (Formal, Subp_Outputs);
22377
22378 -- Out parameters can act as inputs when the related type is
22379 -- tagged, unconstrained array, unconstrained record or record
22380 -- with unconstrained components.
22381
22382 if Ekind (Formal) = E_Out_Parameter
22383 and then Is_Unconstrained_Or_Tagged_Item (Formal)
22384 then
22385 Add_Item (Formal, Subp_Inputs);
22386 end if;
22387 end if;
22388
22389 Next_Formal (Formal);
22390 end loop;
22391
22392 -- When processing a subprogram body, look for pragma Refined_Global as
22393 -- it provides finer granularity of inputs and outputs.
22394
22395 if Ekind (Subp_Id) = E_Subprogram_Body then
22396 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
22397
22398 -- Subprogram declaration case, look for pragma Global
22399
22400 else
22401 Global := Get_Pragma (Spec_Id, Pragma_Global);
22402 end if;
22403
22404 if Present (Global) then
22405 Global_Seen := True;
22406 List := Expression (First (Pragma_Argument_Associations (Global)));
22407
22408 -- The pragma may not have been analyzed because of the arbitrary
22409 -- declaration order of aspects. Make sure that it is analyzed for
22410 -- the purposes of item extraction.
22411
22412 if not Analyzed (List) then
22413 if Pragma_Name (Global) = Name_Refined_Global then
22414 Analyze_Refined_Global_In_Decl_Part (Global);
22415 else
22416 Analyze_Global_In_Decl_Part (Global);
22417 end if;
22418 end if;
22419
22420 -- Nothing to be done for a null global list
22421
22422 if Nkind (List) /= N_Null then
22423 Collect_Global_List (List);
22424 end if;
22425 end if;
22426 end Collect_Subprogram_Inputs_Outputs;
22427
22428 ---------------------------------
22429 -- Delay_Config_Pragma_Analyze --
22430 ---------------------------------
22431
22432 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
22433 begin
22434 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
22435 Name_Priority_Specific_Dispatching);
22436 end Delay_Config_Pragma_Analyze;
22437
22438 -------------------------------------
22439 -- Find_Related_Subprogram_Or_Body --
22440 -------------------------------------
22441
22442 function Find_Related_Subprogram_Or_Body
22443 (Prag : Node_Id;
22444 Do_Checks : Boolean := False) return Node_Id
22445 is
22446 Context : constant Node_Id := Parent (Prag);
22447 Nam : constant Name_Id := Pragma_Name (Prag);
22448 Stmt : Node_Id;
22449
22450 Look_For_Body : constant Boolean :=
22451 Nam_In (Nam, Name_Refined_Depends,
22452 Name_Refined_Global,
22453 Name_Refined_Post);
22454 -- Refinement pragmas must be associated with a subprogram body [stub]
22455
22456 begin
22457 pragma Assert (Nkind (Prag) = N_Pragma);
22458
22459 -- If the pragma is a byproduct of aspect expansion, return the related
22460 -- context of the original aspect.
22461
22462 if Present (Corresponding_Aspect (Prag)) then
22463 return Parent (Corresponding_Aspect (Prag));
22464 end if;
22465
22466 -- Otherwise the pragma is a source construct, most likely part of a
22467 -- declarative list. Skip preceding declarations while looking for a
22468 -- proper subprogram declaration.
22469
22470 pragma Assert (Is_List_Member (Prag));
22471
22472 Stmt := Prev (Prag);
22473 while Present (Stmt) loop
22474
22475 -- Skip prior pragmas, but check for duplicates
22476
22477 if Nkind (Stmt) = N_Pragma then
22478 if Do_Checks and then Pragma_Name (Stmt) = Nam then
22479 Error_Msg_Name_1 := Nam;
22480 Error_Msg_Sloc := Sloc (Stmt);
22481 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
22482 end if;
22483
22484 -- Emit an error when a refinement pragma appears on an expression
22485 -- function without a completion.
22486
22487 elsif Do_Checks
22488 and then Look_For_Body
22489 and then Nkind (Stmt) = N_Subprogram_Declaration
22490 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
22491 and then not Has_Completion (Defining_Entity (Stmt))
22492 then
22493 Error_Msg_Name_1 := Nam;
22494 Error_Msg_N
22495 ("pragma % cannot apply to a stand alone expression function",
22496 Prag);
22497
22498 return Empty;
22499
22500 -- The refinement pragma applies to a subprogram body stub
22501
22502 elsif Look_For_Body
22503 and then Nkind (Stmt) = N_Subprogram_Body_Stub
22504 then
22505 return Stmt;
22506
22507 -- Skip internally generated code
22508
22509 elsif not Comes_From_Source (Stmt) then
22510 null;
22511
22512 -- Return the current construct which is either a subprogram body,
22513 -- a subprogram declaration or is illegal.
22514
22515 else
22516 return Stmt;
22517 end if;
22518
22519 Prev (Stmt);
22520 end loop;
22521
22522 -- If we fall through, then the pragma was either the first declaration
22523 -- or it was preceded by other pragmas and no source constructs.
22524
22525 -- The pragma is associated with a library-level subprogram
22526
22527 if Nkind (Context) = N_Compilation_Unit_Aux then
22528 return Unit (Parent (Context));
22529
22530 -- The pragma appears inside the declarative part of a subprogram body
22531
22532 elsif Nkind (Context) = N_Subprogram_Body then
22533 return Context;
22534
22535 -- No candidate subprogram [body] found
22536
22537 else
22538 return Empty;
22539 end if;
22540 end Find_Related_Subprogram_Or_Body;
22541
22542 -------------------------
22543 -- Get_Base_Subprogram --
22544 -------------------------
22545
22546 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
22547 Result : Entity_Id;
22548
22549 begin
22550 -- Follow subprogram renaming chain
22551
22552 Result := Def_Id;
22553
22554 if Is_Subprogram (Result)
22555 and then
22556 Nkind (Parent (Declaration_Node (Result))) =
22557 N_Subprogram_Renaming_Declaration
22558 and then Present (Alias (Result))
22559 then
22560 Result := Alias (Result);
22561 end if;
22562
22563 return Result;
22564 end Get_Base_Subprogram;
22565
22566 -----------------------
22567 -- Get_SPARK_Mode_Id --
22568 -----------------------
22569
22570 function Get_SPARK_Mode_Id (N : Name_Id) return SPARK_Mode_Id is
22571 begin
22572 if N = Name_On then
22573 return SPARK_On;
22574 elsif N = Name_Off then
22575 return SPARK_Off;
22576 elsif N = Name_Auto then
22577 return SPARK_Auto;
22578
22579 -- Any other argument is erroneous
22580
22581 else
22582 raise Program_Error;
22583 end if;
22584 end Get_SPARK_Mode_Id;
22585
22586 -----------------------
22587 -- Get_SPARK_Mode_Id --
22588 -----------------------
22589
22590 function Get_SPARK_Mode_Id (N : Node_Id) return SPARK_Mode_Id is
22591 Args : List_Id;
22592 Mode : Node_Id;
22593
22594 begin
22595 pragma Assert (Nkind (N) = N_Pragma);
22596 Args := Pragma_Argument_Associations (N);
22597
22598 -- Extract the mode from the argument list
22599
22600 if Present (Args) then
22601 Mode := First (Pragma_Argument_Associations (N));
22602 return Get_SPARK_Mode_Id (Chars (Get_Pragma_Arg (Mode)));
22603
22604 -- When SPARK_Mode appears without an argument, the default is ON
22605
22606 else
22607 return SPARK_On;
22608 end if;
22609 end Get_SPARK_Mode_Id;
22610
22611 ----------------
22612 -- Initialize --
22613 ----------------
22614
22615 procedure Initialize is
22616 begin
22617 Externals.Init;
22618 end Initialize;
22619
22620 -----------------------------
22621 -- Is_Config_Static_String --
22622 -----------------------------
22623
22624 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
22625
22626 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
22627 -- This is an internal recursive function that is just like the outer
22628 -- function except that it adds the string to the name buffer rather
22629 -- than placing the string in the name buffer.
22630
22631 ------------------------------
22632 -- Add_Config_Static_String --
22633 ------------------------------
22634
22635 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
22636 N : Node_Id;
22637 C : Char_Code;
22638
22639 begin
22640 N := Arg;
22641
22642 if Nkind (N) = N_Op_Concat then
22643 if Add_Config_Static_String (Left_Opnd (N)) then
22644 N := Right_Opnd (N);
22645 else
22646 return False;
22647 end if;
22648 end if;
22649
22650 if Nkind (N) /= N_String_Literal then
22651 Error_Msg_N ("string literal expected for pragma argument", N);
22652 return False;
22653
22654 else
22655 for J in 1 .. String_Length (Strval (N)) loop
22656 C := Get_String_Char (Strval (N), J);
22657
22658 if not In_Character_Range (C) then
22659 Error_Msg
22660 ("string literal contains invalid wide character",
22661 Sloc (N) + 1 + Source_Ptr (J));
22662 return False;
22663 end if;
22664
22665 Add_Char_To_Name_Buffer (Get_Character (C));
22666 end loop;
22667 end if;
22668
22669 return True;
22670 end Add_Config_Static_String;
22671
22672 -- Start of processing for Is_Config_Static_String
22673
22674 begin
22675 Name_Len := 0;
22676
22677 return Add_Config_Static_String (Arg);
22678 end Is_Config_Static_String;
22679
22680 -------------------------------
22681 -- Is_Elaboration_SPARK_Mode --
22682 -------------------------------
22683
22684 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
22685 begin
22686 pragma Assert
22687 (Nkind (N) = N_Pragma
22688 and then Pragma_Name (N) = Name_SPARK_Mode
22689 and then Is_List_Member (N));
22690
22691 -- Pragma SPARK_Mode affects the elaboration of a package body when it
22692 -- appears in the statement part of the body.
22693
22694 return
22695 Present (Parent (N))
22696 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
22697 and then List_Containing (N) = Statements (Parent (N))
22698 and then Present (Parent (Parent (N)))
22699 and then Nkind (Parent (Parent (N))) = N_Package_Body;
22700 end Is_Elaboration_SPARK_Mode;
22701
22702 -----------------------------------------
22703 -- Is_Non_Significant_Pragma_Reference --
22704 -----------------------------------------
22705
22706 -- This function makes use of the following static table which indicates
22707 -- whether appearance of some name in a given pragma is to be considered
22708 -- as a reference for the purposes of warnings about unreferenced objects.
22709
22710 -- -1 indicates that references in any argument position are significant
22711 -- 0 indicates that appearance in any argument is not significant
22712 -- +n indicates that appearance as argument n is significant, but all
22713 -- other arguments are not significant
22714 -- 99 special processing required (e.g. for pragma Check)
22715
22716 Sig_Flags : constant array (Pragma_Id) of Int :=
22717 (Pragma_AST_Entry => -1,
22718 Pragma_Abort_Defer => -1,
22719 Pragma_Abstract_State => -1,
22720 Pragma_Ada_83 => -1,
22721 Pragma_Ada_95 => -1,
22722 Pragma_Ada_05 => -1,
22723 Pragma_Ada_2005 => -1,
22724 Pragma_Ada_12 => -1,
22725 Pragma_Ada_2012 => -1,
22726 Pragma_All_Calls_Remote => -1,
22727 Pragma_Annotate => -1,
22728 Pragma_Assert => -1,
22729 Pragma_Assert_And_Cut => -1,
22730 Pragma_Assertion_Policy => 0,
22731 Pragma_Assume => -1,
22732 Pragma_Assume_No_Invalid_Values => 0,
22733 Pragma_Attribute_Definition => +3,
22734 Pragma_Asynchronous => -1,
22735 Pragma_Atomic => 0,
22736 Pragma_Atomic_Components => 0,
22737 Pragma_Attach_Handler => -1,
22738 Pragma_Check => 99,
22739 Pragma_Check_Float_Overflow => 0,
22740 Pragma_Check_Name => 0,
22741 Pragma_Check_Policy => 0,
22742 Pragma_CIL_Constructor => -1,
22743 Pragma_CPP_Class => 0,
22744 Pragma_CPP_Constructor => 0,
22745 Pragma_CPP_Virtual => 0,
22746 Pragma_CPP_Vtable => 0,
22747 Pragma_CPU => -1,
22748 Pragma_C_Pass_By_Copy => 0,
22749 Pragma_Comment => 0,
22750 Pragma_Common_Object => -1,
22751 Pragma_Compile_Time_Error => -1,
22752 Pragma_Compile_Time_Warning => -1,
22753 Pragma_Compiler_Unit => 0,
22754 Pragma_Complete_Representation => 0,
22755 Pragma_Complex_Representation => 0,
22756 Pragma_Component_Alignment => -1,
22757 Pragma_Contract_Cases => -1,
22758 Pragma_Controlled => 0,
22759 Pragma_Convention => 0,
22760 Pragma_Convention_Identifier => 0,
22761 Pragma_Debug => -1,
22762 Pragma_Debug_Policy => 0,
22763 Pragma_Detect_Blocking => -1,
22764 Pragma_Default_Storage_Pool => -1,
22765 Pragma_Depends => -1,
22766 Pragma_Disable_Atomic_Synchronization => -1,
22767 Pragma_Discard_Names => 0,
22768 Pragma_Dispatching_Domain => -1,
22769 Pragma_Elaborate => -1,
22770 Pragma_Elaborate_All => -1,
22771 Pragma_Elaborate_Body => -1,
22772 Pragma_Elaboration_Checks => -1,
22773 Pragma_Eliminate => -1,
22774 Pragma_Enable_Atomic_Synchronization => -1,
22775 Pragma_Export => -1,
22776 Pragma_Export_Exception => -1,
22777 Pragma_Export_Function => -1,
22778 Pragma_Export_Object => -1,
22779 Pragma_Export_Procedure => -1,
22780 Pragma_Export_Value => -1,
22781 Pragma_Export_Valued_Procedure => -1,
22782 Pragma_Extend_System => -1,
22783 Pragma_Extensions_Allowed => -1,
22784 Pragma_External => -1,
22785 Pragma_Favor_Top_Level => -1,
22786 Pragma_External_Name_Casing => -1,
22787 Pragma_Fast_Math => -1,
22788 Pragma_Finalize_Storage_Only => 0,
22789 Pragma_Float_Representation => 0,
22790 Pragma_Global => -1,
22791 Pragma_Ident => -1,
22792 Pragma_Implementation_Defined => -1,
22793 Pragma_Implemented => -1,
22794 Pragma_Implicit_Packing => 0,
22795 Pragma_Import => +2,
22796 Pragma_Import_Exception => 0,
22797 Pragma_Import_Function => 0,
22798 Pragma_Import_Object => 0,
22799 Pragma_Import_Procedure => 0,
22800 Pragma_Import_Valued_Procedure => 0,
22801 Pragma_Independent => 0,
22802 Pragma_Independent_Components => 0,
22803 Pragma_Initial_Condition => -1,
22804 Pragma_Initialize_Scalars => -1,
22805 Pragma_Initializes => -1,
22806 Pragma_Inline => 0,
22807 Pragma_Inline_Always => 0,
22808 Pragma_Inline_Generic => 0,
22809 Pragma_Inspection_Point => -1,
22810 Pragma_Interface => +2,
22811 Pragma_Interface_Name => +2,
22812 Pragma_Interrupt_Handler => -1,
22813 Pragma_Interrupt_Priority => -1,
22814 Pragma_Interrupt_State => -1,
22815 Pragma_Invariant => -1,
22816 Pragma_Java_Constructor => -1,
22817 Pragma_Java_Interface => -1,
22818 Pragma_Keep_Names => 0,
22819 Pragma_License => -1,
22820 Pragma_Link_With => -1,
22821 Pragma_Linker_Alias => -1,
22822 Pragma_Linker_Constructor => -1,
22823 Pragma_Linker_Destructor => -1,
22824 Pragma_Linker_Options => -1,
22825 Pragma_Linker_Section => -1,
22826 Pragma_List => -1,
22827 Pragma_Lock_Free => -1,
22828 Pragma_Locking_Policy => -1,
22829 Pragma_Long_Float => -1,
22830 Pragma_Loop_Invariant => -1,
22831 Pragma_Loop_Optimize => -1,
22832 Pragma_Loop_Variant => -1,
22833 Pragma_Machine_Attribute => -1,
22834 Pragma_Main => -1,
22835 Pragma_Main_Storage => -1,
22836 Pragma_Memory_Size => -1,
22837 Pragma_No_Return => 0,
22838 Pragma_No_Body => 0,
22839 Pragma_No_Inline => 0,
22840 Pragma_No_Run_Time => -1,
22841 Pragma_No_Strict_Aliasing => -1,
22842 Pragma_Normalize_Scalars => -1,
22843 Pragma_Obsolescent => 0,
22844 Pragma_Optimize => -1,
22845 Pragma_Optimize_Alignment => -1,
22846 Pragma_Overflow_Mode => 0,
22847 Pragma_Overriding_Renamings => 0,
22848 Pragma_Ordered => 0,
22849 Pragma_Pack => 0,
22850 Pragma_Page => -1,
22851 Pragma_Partition_Elaboration_Policy => -1,
22852 Pragma_Passive => -1,
22853 Pragma_Persistent_BSS => 0,
22854 Pragma_Polling => -1,
22855 Pragma_Post => -1,
22856 Pragma_Postcondition => -1,
22857 Pragma_Post_Class => -1,
22858 Pragma_Pre => -1,
22859 Pragma_Precondition => -1,
22860 Pragma_Predicate => -1,
22861 Pragma_Preelaborable_Initialization => -1,
22862 Pragma_Preelaborate => -1,
22863 Pragma_Preelaborate_05 => -1,
22864 Pragma_Pre_Class => -1,
22865 Pragma_Priority => -1,
22866 Pragma_Priority_Specific_Dispatching => -1,
22867 Pragma_Profile => 0,
22868 Pragma_Profile_Warnings => 0,
22869 Pragma_Propagate_Exceptions => -1,
22870 Pragma_Psect_Object => -1,
22871 Pragma_Pure => -1,
22872 Pragma_Pure_05 => -1,
22873 Pragma_Pure_12 => -1,
22874 Pragma_Pure_Function => -1,
22875 Pragma_Queuing_Policy => -1,
22876 Pragma_Rational => -1,
22877 Pragma_Ravenscar => -1,
22878 Pragma_Refined_Depends => -1,
22879 Pragma_Refined_Global => -1,
22880 Pragma_Refined_Post => -1,
22881 Pragma_Refined_State => -1,
22882 Pragma_Relative_Deadline => -1,
22883 Pragma_Remote_Access_Type => -1,
22884 Pragma_Remote_Call_Interface => -1,
22885 Pragma_Remote_Types => -1,
22886 Pragma_Restricted_Run_Time => -1,
22887 Pragma_Restriction_Warnings => -1,
22888 Pragma_Restrictions => -1,
22889 Pragma_Reviewable => -1,
22890 Pragma_Short_Circuit_And_Or => -1,
22891 Pragma_Share_Generic => -1,
22892 Pragma_Shared => -1,
22893 Pragma_Shared_Passive => -1,
22894 Pragma_Short_Descriptors => 0,
22895 Pragma_Simple_Storage_Pool_Type => 0,
22896 Pragma_Source_File_Name => -1,
22897 Pragma_Source_File_Name_Project => -1,
22898 Pragma_Source_Reference => -1,
22899 Pragma_SPARK_Mode => 0,
22900 Pragma_Storage_Size => -1,
22901 Pragma_Storage_Unit => -1,
22902 Pragma_Static_Elaboration_Desired => -1,
22903 Pragma_Stream_Convert => -1,
22904 Pragma_Style_Checks => -1,
22905 Pragma_Subtitle => -1,
22906 Pragma_Suppress => 0,
22907 Pragma_Suppress_Exception_Locations => 0,
22908 Pragma_Suppress_All => -1,
22909 Pragma_Suppress_Debug_Info => 0,
22910 Pragma_Suppress_Initialization => 0,
22911 Pragma_System_Name => -1,
22912 Pragma_Task_Dispatching_Policy => -1,
22913 Pragma_Task_Info => -1,
22914 Pragma_Task_Name => -1,
22915 Pragma_Task_Storage => 0,
22916 Pragma_Test_Case => -1,
22917 Pragma_Thread_Local_Storage => 0,
22918 Pragma_Time_Slice => -1,
22919 Pragma_Title => -1,
22920 Pragma_Type_Invariant => -1,
22921 Pragma_Type_Invariant_Class => -1,
22922 Pragma_Unchecked_Union => 0,
22923 Pragma_Unimplemented_Unit => -1,
22924 Pragma_Universal_Aliasing => -1,
22925 Pragma_Universal_Data => -1,
22926 Pragma_Unmodified => -1,
22927 Pragma_Unreferenced => -1,
22928 Pragma_Unreferenced_Objects => -1,
22929 Pragma_Unreserve_All_Interrupts => -1,
22930 Pragma_Unsuppress => 0,
22931 Pragma_Use_VADS_Size => -1,
22932 Pragma_Validity_Checks => -1,
22933 Pragma_Volatile => 0,
22934 Pragma_Volatile_Components => 0,
22935 Pragma_Warnings => -1,
22936 Pragma_Weak_External => -1,
22937 Pragma_Wide_Character_Encoding => 0,
22938 Unknown_Pragma => 0);
22939
22940 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
22941 Id : Pragma_Id;
22942 P : Node_Id;
22943 C : Int;
22944 A : Node_Id;
22945
22946 begin
22947 P := Parent (N);
22948
22949 if Nkind (P) /= N_Pragma_Argument_Association then
22950 return False;
22951
22952 else
22953 Id := Get_Pragma_Id (Parent (P));
22954 C := Sig_Flags (Id);
22955
22956 case C is
22957 when -1 =>
22958 return False;
22959
22960 when 0 =>
22961 return True;
22962
22963 when 99 =>
22964 case Id is
22965
22966 -- For pragma Check, the first argument is not significant,
22967 -- the second and the third (if present) arguments are
22968 -- significant.
22969
22970 when Pragma_Check =>
22971 return
22972 P = First (Pragma_Argument_Associations (Parent (P)));
22973
22974 when others =>
22975 raise Program_Error;
22976 end case;
22977
22978 when others =>
22979 A := First (Pragma_Argument_Associations (Parent (P)));
22980 for J in 1 .. C - 1 loop
22981 if No (A) then
22982 return False;
22983 end if;
22984
22985 Next (A);
22986 end loop;
22987
22988 return A = P; -- is this wrong way round ???
22989 end case;
22990 end if;
22991 end Is_Non_Significant_Pragma_Reference;
22992
22993 ----------------
22994 -- Is_Part_Of --
22995 ----------------
22996
22997 function Is_Part_Of
22998 (State : Entity_Id;
22999 Ancestor : Entity_Id) return Boolean
23000 is
23001 Options : constant Node_Id := Parent (State);
23002 Name : Node_Id;
23003 Option : Node_Id;
23004 Value : Node_Id;
23005
23006 begin
23007 -- A state declaration with option Part_Of appears as an extension
23008 -- aggregate with component associations.
23009
23010 if Nkind (Options) = N_Extension_Aggregate then
23011 Option := First (Component_Associations (Options));
23012 while Present (Option) loop
23013 Name := First (Choices (Option));
23014 Value := Expression (Option);
23015
23016 if Chars (Name) = Name_Part_Of then
23017 return Entity (Value) = Ancestor;
23018 end if;
23019
23020 Next (Option);
23021 end loop;
23022 end if;
23023
23024 return False;
23025 end Is_Part_Of;
23026
23027 ------------------------------
23028 -- Is_Pragma_String_Literal --
23029 ------------------------------
23030
23031 -- This function returns true if the corresponding pragma argument is a
23032 -- static string expression. These are the only cases in which string
23033 -- literals can appear as pragma arguments. We also allow a string literal
23034 -- as the first argument to pragma Assert (although it will of course
23035 -- always generate a type error).
23036
23037 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
23038 Pragn : constant Node_Id := Parent (Par);
23039 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
23040 Pname : constant Name_Id := Pragma_Name (Pragn);
23041 Argn : Natural;
23042 N : Node_Id;
23043
23044 begin
23045 Argn := 1;
23046 N := First (Assoc);
23047 loop
23048 exit when N = Par;
23049 Argn := Argn + 1;
23050 Next (N);
23051 end loop;
23052
23053 if Pname = Name_Assert then
23054 return True;
23055
23056 elsif Pname = Name_Export then
23057 return Argn > 2;
23058
23059 elsif Pname = Name_Ident then
23060 return Argn = 1;
23061
23062 elsif Pname = Name_Import then
23063 return Argn > 2;
23064
23065 elsif Pname = Name_Interface_Name then
23066 return Argn > 1;
23067
23068 elsif Pname = Name_Linker_Alias then
23069 return Argn = 2;
23070
23071 elsif Pname = Name_Linker_Section then
23072 return Argn = 2;
23073
23074 elsif Pname = Name_Machine_Attribute then
23075 return Argn = 2;
23076
23077 elsif Pname = Name_Source_File_Name then
23078 return True;
23079
23080 elsif Pname = Name_Source_Reference then
23081 return Argn = 2;
23082
23083 elsif Pname = Name_Title then
23084 return True;
23085
23086 elsif Pname = Name_Subtitle then
23087 return True;
23088
23089 else
23090 return False;
23091 end if;
23092 end Is_Pragma_String_Literal;
23093
23094 ---------------------------
23095 -- Is_Private_SPARK_Mode --
23096 ---------------------------
23097
23098 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
23099 begin
23100 pragma Assert
23101 (Nkind (N) = N_Pragma
23102 and then Pragma_Name (N) = Name_SPARK_Mode
23103 and then Is_List_Member (N));
23104
23105 -- For pragma SPARK_Mode to be private, it has to appear in the private
23106 -- declarations of a package.
23107
23108 return
23109 Present (Parent (N))
23110 and then Nkind (Parent (N)) = N_Package_Specification
23111 and then List_Containing (N) = Private_Declarations (Parent (N));
23112 end Is_Private_SPARK_Mode;
23113
23114 -------------------------------------
23115 -- Is_Unconstrained_Or_Tagged_Item --
23116 -------------------------------------
23117
23118 function Is_Unconstrained_Or_Tagged_Item
23119 (Item : Entity_Id) return Boolean
23120 is
23121 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
23122 -- Determine whether record type Typ has at least one unconstrained
23123 -- component.
23124
23125 ---------------------------------
23126 -- Has_Unconstrained_Component --
23127 ---------------------------------
23128
23129 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
23130 Comp : Entity_Id;
23131
23132 begin
23133 Comp := First_Component (Typ);
23134 while Present (Comp) loop
23135 if Is_Unconstrained_Or_Tagged_Item (Comp) then
23136 return True;
23137 end if;
23138
23139 Next_Component (Comp);
23140 end loop;
23141
23142 return False;
23143 end Has_Unconstrained_Component;
23144
23145 -- Local variables
23146
23147 Typ : constant Entity_Id := Etype (Item);
23148
23149 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
23150
23151 begin
23152 if Is_Tagged_Type (Typ) then
23153 return True;
23154
23155 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
23156 return True;
23157
23158 elsif Is_Record_Type (Typ) then
23159 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
23160 return True;
23161 else
23162 return Has_Unconstrained_Component (Typ);
23163 end if;
23164
23165 else
23166 return False;
23167 end if;
23168 end Is_Unconstrained_Or_Tagged_Item;
23169
23170 -----------------------------
23171 -- Is_Valid_Assertion_Kind --
23172 -----------------------------
23173
23174 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
23175 begin
23176 case Nam is
23177 when
23178 -- RM defined
23179
23180 Name_Assert |
23181 Name_Static_Predicate |
23182 Name_Dynamic_Predicate |
23183 Name_Pre |
23184 Name_uPre |
23185 Name_Post |
23186 Name_uPost |
23187 Name_Type_Invariant |
23188 Name_uType_Invariant |
23189
23190 -- Impl defined
23191
23192 Name_Assert_And_Cut |
23193 Name_Assume |
23194 Name_Contract_Cases |
23195 Name_Debug |
23196 Name_Initial_Condition |
23197 Name_Invariant |
23198 Name_uInvariant |
23199 Name_Loop_Invariant |
23200 Name_Loop_Variant |
23201 Name_Postcondition |
23202 Name_Precondition |
23203 Name_Predicate |
23204 Name_Refined_Post |
23205 Name_Statement_Assertions => return True;
23206
23207 when others => return False;
23208 end case;
23209 end Is_Valid_Assertion_Kind;
23210
23211 -----------------------------------------
23212 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
23213 -----------------------------------------
23214
23215 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
23216 Aspects : constant List_Id := New_List;
23217 Loc : constant Source_Ptr := Sloc (Decl);
23218 Or_Decl : constant Node_Id := Original_Node (Decl);
23219
23220 Original_Aspects : List_Id;
23221 -- To capture global references, a copy of the created aspects must be
23222 -- inserted in the original tree.
23223
23224 Prag : Node_Id;
23225 Prag_Arg_Ass : Node_Id;
23226 Prag_Id : Pragma_Id;
23227
23228 begin
23229 -- Check for any PPC pragmas that appear within Decl
23230
23231 Prag := Next (Decl);
23232 while Nkind (Prag) = N_Pragma loop
23233 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
23234
23235 case Prag_Id is
23236 when Pragma_Postcondition | Pragma_Precondition =>
23237 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
23238
23239 -- Make an aspect from any PPC pragma
23240
23241 Append_To (Aspects,
23242 Make_Aspect_Specification (Loc,
23243 Identifier =>
23244 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
23245 Expression =>
23246 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
23247
23248 -- Generate the analysis information in the pragma expression
23249 -- and then set the pragma node analyzed to avoid any further
23250 -- analysis.
23251
23252 Analyze (Expression (Prag_Arg_Ass));
23253 Set_Analyzed (Prag, True);
23254
23255 when others => null;
23256 end case;
23257
23258 Next (Prag);
23259 end loop;
23260
23261 -- Set all new aspects into the generic declaration node
23262
23263 if Is_Non_Empty_List (Aspects) then
23264
23265 -- Create the list of aspects to be inserted in the original tree
23266
23267 Original_Aspects := Copy_Separate_List (Aspects);
23268
23269 -- Check if Decl already has aspects
23270
23271 -- Attach the new lists of aspects to both the generic copy and the
23272 -- original tree.
23273
23274 if Has_Aspects (Decl) then
23275 Append_List (Aspects, Aspect_Specifications (Decl));
23276 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
23277
23278 else
23279 Set_Parent (Aspects, Decl);
23280 Set_Aspect_Specifications (Decl, Aspects);
23281 Set_Parent (Original_Aspects, Or_Decl);
23282 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
23283 end if;
23284 end if;
23285 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
23286
23287 -------------------------
23288 -- Preanalyze_CTC_Args --
23289 -------------------------
23290
23291 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
23292 begin
23293 -- Preanalyze the boolean expressions, we treat these as spec
23294 -- expressions (i.e. similar to a default expression).
23295
23296 if Present (Arg_Req) then
23297 Preanalyze_Assert_Expression
23298 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
23299
23300 -- In ASIS mode, for a pragma generated from a source aspect, also
23301 -- analyze the original aspect expression.
23302
23303 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
23304 Preanalyze_Assert_Expression
23305 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
23306 end if;
23307 end if;
23308
23309 if Present (Arg_Ens) then
23310 Preanalyze_Assert_Expression
23311 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
23312
23313 -- In ASIS mode, for a pragma generated from a source aspect, also
23314 -- analyze the original aspect expression.
23315
23316 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
23317 Preanalyze_Assert_Expression
23318 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
23319 end if;
23320 end if;
23321 end Preanalyze_CTC_Args;
23322
23323 --------------------------------------
23324 -- Process_Compilation_Unit_Pragmas --
23325 --------------------------------------
23326
23327 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
23328 begin
23329 -- A special check for pragma Suppress_All, a very strange DEC pragma,
23330 -- strange because it comes at the end of the unit. Rational has the
23331 -- same name for a pragma, but treats it as a program unit pragma, In
23332 -- GNAT we just decide to allow it anywhere at all. If it appeared then
23333 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
23334 -- node, and we insert a pragma Suppress (All_Checks) at the start of
23335 -- the context clause to ensure the correct processing.
23336
23337 if Has_Pragma_Suppress_All (N) then
23338 Prepend_To (Context_Items (N),
23339 Make_Pragma (Sloc (N),
23340 Chars => Name_Suppress,
23341 Pragma_Argument_Associations => New_List (
23342 Make_Pragma_Argument_Association (Sloc (N),
23343 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
23344 end if;
23345
23346 -- Nothing else to do at the current time!
23347
23348 end Process_Compilation_Unit_Pragmas;
23349
23350 ------------------------------------
23351 -- Record_Possible_Body_Reference --
23352 ------------------------------------
23353
23354 procedure Record_Possible_Body_Reference
23355 (Item : Node_Id;
23356 Item_Id : Entity_Id)
23357 is
23358 begin
23359 if In_Package_Body
23360 and then Ekind (Item_Id) = E_Abstract_State
23361 then
23362 if not Has_Body_References (Item_Id) then
23363 Set_Has_Body_References (Item_Id, True);
23364 Set_Body_References (Item_Id, New_Elmt_List);
23365 end if;
23366
23367 Append_Elmt (Item, Body_References (Item_Id));
23368 end if;
23369 end Record_Possible_Body_Reference;
23370
23371 ------------------------------
23372 -- Relocate_Pragmas_To_Body --
23373 ------------------------------
23374
23375 procedure Relocate_Pragmas_To_Body
23376 (Subp_Body : Node_Id;
23377 Target_Body : Node_Id := Empty)
23378 is
23379 procedure Relocate_Pragma (Prag : Node_Id);
23380 -- Remove a single pragma from its current list and add it to the
23381 -- declarations of the proper body (either Subp_Body or Target_Body).
23382
23383 ---------------------
23384 -- Relocate_Pragma --
23385 ---------------------
23386
23387 procedure Relocate_Pragma (Prag : Node_Id) is
23388 Decls : List_Id;
23389 Target : Node_Id;
23390
23391 begin
23392 -- When subprogram stubs or expression functions are involves, the
23393 -- destination declaration list belongs to the proper body.
23394
23395 if Present (Target_Body) then
23396 Target := Target_Body;
23397 else
23398 Target := Subp_Body;
23399 end if;
23400
23401 Decls := Declarations (Target);
23402
23403 if No (Decls) then
23404 Decls := New_List;
23405 Set_Declarations (Target, Decls);
23406 end if;
23407
23408 -- Unhook the pragma from its current list
23409
23410 Remove (Prag);
23411 Prepend (Prag, Decls);
23412 end Relocate_Pragma;
23413
23414 -- Local variables
23415
23416 Body_Id : constant Entity_Id :=
23417 Defining_Unit_Name (Specification (Subp_Body));
23418 Next_Stmt : Node_Id;
23419 Stmt : Node_Id;
23420
23421 -- Start of processing for Relocate_Pragmas_To_Body
23422
23423 begin
23424 -- Do not process a body that comes from a separate unit as no construct
23425 -- can possibly follow it.
23426
23427 if not Is_List_Member (Subp_Body) then
23428 return;
23429
23430 -- Do not relocate pragmas that follow a stub if the stub does not have
23431 -- a proper body.
23432
23433 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
23434 and then No (Target_Body)
23435 then
23436 return;
23437
23438 -- Do not process internally generated routine _Postconditions
23439
23440 elsif Ekind (Body_Id) = E_Procedure
23441 and then Chars (Body_Id) = Name_uPostconditions
23442 then
23443 return;
23444 end if;
23445
23446 -- Look at what is following the body. We are interested in certain kind
23447 -- of pragmas (either from source or byproducts of expansion) that can
23448 -- apply to a body [stub].
23449
23450 Stmt := Next (Subp_Body);
23451 while Present (Stmt) loop
23452
23453 -- Preserve the following statement for iteration purposes due to a
23454 -- possible relocation of a pragma.
23455
23456 Next_Stmt := Next (Stmt);
23457
23458 -- Move a candidate pragma following the body to the declarations of
23459 -- the body.
23460
23461 if Nkind (Stmt) = N_Pragma
23462 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
23463 then
23464 Relocate_Pragma (Stmt);
23465
23466 -- Skip internally generated code
23467
23468 elsif not Comes_From_Source (Stmt) then
23469 null;
23470
23471 -- No candidate pragmas are available for relocation
23472
23473 else
23474 exit;
23475 end if;
23476
23477 Stmt := Next_Stmt;
23478 end loop;
23479 end Relocate_Pragmas_To_Body;
23480
23481 ----------------------------
23482 -- Rewrite_Assertion_Kind --
23483 ----------------------------
23484
23485 procedure Rewrite_Assertion_Kind (N : Node_Id) is
23486 Nam : Name_Id;
23487
23488 begin
23489 if Nkind (N) = N_Attribute_Reference
23490 and then Attribute_Name (N) = Name_Class
23491 and then Nkind (Prefix (N)) = N_Identifier
23492 then
23493 case Chars (Prefix (N)) is
23494 when Name_Pre =>
23495 Nam := Name_uPre;
23496 when Name_Post =>
23497 Nam := Name_uPost;
23498 when Name_Type_Invariant =>
23499 Nam := Name_uType_Invariant;
23500 when Name_Invariant =>
23501 Nam := Name_uInvariant;
23502 when others =>
23503 return;
23504 end case;
23505
23506 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
23507 end if;
23508 end Rewrite_Assertion_Kind;
23509
23510 --------
23511 -- rv --
23512 --------
23513
23514 procedure rv is
23515 begin
23516 null;
23517 end rv;
23518
23519 --------------------------------
23520 -- Set_Encoded_Interface_Name --
23521 --------------------------------
23522
23523 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
23524 Str : constant String_Id := Strval (S);
23525 Len : constant Int := String_Length (Str);
23526 CC : Char_Code;
23527 C : Character;
23528 J : Int;
23529
23530 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
23531
23532 procedure Encode;
23533 -- Stores encoded value of character code CC. The encoding we use an
23534 -- underscore followed by four lower case hex digits.
23535
23536 ------------
23537 -- Encode --
23538 ------------
23539
23540 procedure Encode is
23541 begin
23542 Store_String_Char (Get_Char_Code ('_'));
23543 Store_String_Char
23544 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
23545 Store_String_Char
23546 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
23547 Store_String_Char
23548 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
23549 Store_String_Char
23550 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
23551 end Encode;
23552
23553 -- Start of processing for Set_Encoded_Interface_Name
23554
23555 begin
23556 -- If first character is asterisk, this is a link name, and we leave it
23557 -- completely unmodified. We also ignore null strings (the latter case
23558 -- happens only in error cases) and no encoding should occur for Java or
23559 -- AAMP interface names.
23560
23561 if Len = 0
23562 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
23563 or else VM_Target /= No_VM
23564 or else AAMP_On_Target
23565 then
23566 Set_Interface_Name (E, S);
23567
23568 else
23569 J := 1;
23570 loop
23571 CC := Get_String_Char (Str, J);
23572
23573 exit when not In_Character_Range (CC);
23574
23575 C := Get_Character (CC);
23576
23577 exit when C /= '_' and then C /= '$'
23578 and then C not in '0' .. '9'
23579 and then C not in 'a' .. 'z'
23580 and then C not in 'A' .. 'Z';
23581
23582 if J = Len then
23583 Set_Interface_Name (E, S);
23584 return;
23585
23586 else
23587 J := J + 1;
23588 end if;
23589 end loop;
23590
23591 -- Here we need to encode. The encoding we use as follows:
23592 -- three underscores + four hex digits (lower case)
23593
23594 Start_String;
23595
23596 for J in 1 .. String_Length (Str) loop
23597 CC := Get_String_Char (Str, J);
23598
23599 if not In_Character_Range (CC) then
23600 Encode;
23601 else
23602 C := Get_Character (CC);
23603
23604 if C = '_' or else C = '$'
23605 or else C in '0' .. '9'
23606 or else C in 'a' .. 'z'
23607 or else C in 'A' .. 'Z'
23608 then
23609 Store_String_Char (CC);
23610 else
23611 Encode;
23612 end if;
23613 end if;
23614 end loop;
23615
23616 Set_Interface_Name (E,
23617 Make_String_Literal (Sloc (S),
23618 Strval => End_String));
23619 end if;
23620 end Set_Encoded_Interface_Name;
23621
23622 -------------------
23623 -- Set_Unit_Name --
23624 -------------------
23625
23626 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
23627 Pref : Node_Id;
23628 Scop : Entity_Id;
23629
23630 begin
23631 if Nkind (N) = N_Identifier
23632 and then Nkind (With_Item) = N_Identifier
23633 then
23634 Set_Entity (N, Entity (With_Item));
23635
23636 elsif Nkind (N) = N_Selected_Component then
23637 Change_Selected_Component_To_Expanded_Name (N);
23638 Set_Entity (N, Entity (With_Item));
23639 Set_Entity (Selector_Name (N), Entity (N));
23640
23641 Pref := Prefix (N);
23642 Scop := Scope (Entity (N));
23643 while Nkind (Pref) = N_Selected_Component loop
23644 Change_Selected_Component_To_Expanded_Name (Pref);
23645 Set_Entity (Selector_Name (Pref), Scop);
23646 Set_Entity (Pref, Scop);
23647 Pref := Prefix (Pref);
23648 Scop := Scope (Scop);
23649 end loop;
23650
23651 Set_Entity (Pref, Scop);
23652 end if;
23653 end Set_Unit_Name;
23654
23655 end Sem_Prag;