sem_ch3.adb, [...]: Minor reformatting.
[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, Refined_Post and Refined_Pre. Find the
240 -- declaration of the related subprogram [body or stub] subject to pragma
241 -- Prag. If flag Do_Checks is set, the routine reports duplicate pragmas
242 -- and detects improper use of refinement pragmas in stand alone expression
243 -- functions. 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, Refined_Post and
248 -- Refined_Pre yield N_Subprogram_Body or N_Subprogram_Body_Stub nodes
249 -- or Empty if 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 Rewrite_Assertion_Kind (N : Node_Id);
281 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
282 -- then it is rewritten as an identifier with the corresponding special
283 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
284 -- Check, Check_Policy.
285
286 procedure rv;
287 -- This is a dummy function called by the processing for pragma Reviewable.
288 -- It is there for assisting front end debugging. By placing a Reviewable
289 -- pragma in the source program, a breakpoint on rv catches this place in
290 -- the source, allowing convenient stepping to the point of interest.
291
292 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
293 -- Place semantic information on the argument of an Elaborate/Elaborate_All
294 -- pragma. Entity name for unit and its parents is taken from item in
295 -- previous with_clause that mentions the unit.
296
297 --------------
298 -- Add_Item --
299 --------------
300
301 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
302 begin
303 if No (To_List) then
304 To_List := New_Elmt_List;
305 end if;
306
307 Append_Elmt (Item, To_List);
308 end Add_Item;
309
310 -------------------------------
311 -- Adjust_External_Name_Case --
312 -------------------------------
313
314 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
315 CC : Char_Code;
316
317 begin
318 -- Adjust case of literal if required
319
320 if Opt.External_Name_Exp_Casing = As_Is then
321 return N;
322
323 else
324 -- Copy existing string
325
326 Start_String;
327
328 -- Set proper casing
329
330 for J in 1 .. String_Length (Strval (N)) loop
331 CC := Get_String_Char (Strval (N), J);
332
333 if Opt.External_Name_Exp_Casing = Uppercase
334 and then CC >= Get_Char_Code ('a')
335 and then CC <= Get_Char_Code ('z')
336 then
337 Store_String_Char (CC - 32);
338
339 elsif Opt.External_Name_Exp_Casing = Lowercase
340 and then CC >= Get_Char_Code ('A')
341 and then CC <= Get_Char_Code ('Z')
342 then
343 Store_String_Char (CC + 32);
344
345 else
346 Store_String_Char (CC);
347 end if;
348 end loop;
349
350 return
351 Make_String_Literal (Sloc (N),
352 Strval => End_String);
353 end if;
354 end Adjust_External_Name_Case;
355
356 -----------------------------------------
357 -- Analyze_Contract_Cases_In_Decl_Part --
358 -----------------------------------------
359
360 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
361 Others_Seen : Boolean := False;
362
363 procedure Analyze_Contract_Case (CCase : Node_Id);
364 -- Verify the legality of a single contract case
365
366 ---------------------------
367 -- Analyze_Contract_Case --
368 ---------------------------
369
370 procedure Analyze_Contract_Case (CCase : Node_Id) is
371 Case_Guard : Node_Id;
372 Conseq : Node_Id;
373 Extra_Guard : Node_Id;
374
375 begin
376 if Nkind (CCase) = N_Component_Association then
377 Case_Guard := First (Choices (CCase));
378 Conseq := Expression (CCase);
379
380 -- Each contract case must have exactly one case guard
381
382 Extra_Guard := Next (Case_Guard);
383
384 if Present (Extra_Guard) then
385 Error_Msg_N
386 ("contract case may have only one case guard", Extra_Guard);
387 end if;
388
389 -- Check the placement of "others" (if available)
390
391 if Nkind (Case_Guard) = N_Others_Choice then
392 if Others_Seen then
393 Error_Msg_N
394 ("only one others choice allowed in aspect Contract_Cases",
395 Case_Guard);
396 else
397 Others_Seen := True;
398 end if;
399
400 elsif Others_Seen then
401 Error_Msg_N
402 ("others must be the last choice in aspect Contract_Cases",
403 N);
404 end if;
405
406 -- Preanalyze the case guard and consequence
407
408 if Nkind (Case_Guard) /= N_Others_Choice then
409 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
410 end if;
411
412 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
413
414 -- The contract case is malformed
415
416 else
417 Error_Msg_N ("wrong syntax in contract case", CCase);
418 end if;
419 end Analyze_Contract_Case;
420
421 -- Local variables
422
423 All_Cases : Node_Id;
424 CCase : Node_Id;
425 Subp_Decl : Node_Id;
426 Subp_Id : Entity_Id;
427
428 Restore_Scope : Boolean := False;
429 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
430
431 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
432
433 begin
434 Set_Analyzed (N);
435
436 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
437 Subp_Id := Defining_Entity (Subp_Decl);
438 All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
439
440 -- Multiple contract cases appear in aggregate form
441
442 if Nkind (All_Cases) = N_Aggregate then
443 if No (Component_Associations (All_Cases)) then
444 Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
445
446 -- Individual contract cases appear as component associations
447
448 else
449 -- Ensure that the formal parameters are visible when analyzing
450 -- all clauses. This falls out of the general rule of aspects
451 -- pertaining to subprogram declarations. Skip the installation
452 -- for subprogram bodies because the formals are already visible.
453
454 if not In_Open_Scopes (Subp_Id) then
455 Restore_Scope := True;
456 Push_Scope (Subp_Id);
457 Install_Formals (Subp_Id);
458 end if;
459
460 CCase := First (Component_Associations (All_Cases));
461 while Present (CCase) loop
462 Analyze_Contract_Case (CCase);
463 Next (CCase);
464 end loop;
465
466 if Restore_Scope then
467 End_Scope;
468 end if;
469 end if;
470
471 else
472 Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
473 end if;
474 end Analyze_Contract_Cases_In_Decl_Part;
475
476 ----------------------------------
477 -- Analyze_Depends_In_Decl_Part --
478 ----------------------------------
479
480 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
481 Loc : constant Source_Ptr := Sloc (N);
482
483 All_Inputs_Seen : Elist_Id := No_Elist;
484 -- A list containing the entities of all the inputs processed so far.
485 -- The list is populated with unique entities because the same input
486 -- may appear in multiple input lists.
487
488 All_Outputs_Seen : Elist_Id := No_Elist;
489 -- A list containing the entities of all the outputs processed so far.
490 -- The list is populated with unique entities because output items are
491 -- unique in a dependence relation.
492
493 Global_Seen : Boolean := False;
494 -- A flag set when pragma Global has been processed
495
496 Null_Output_Seen : Boolean := False;
497 -- A flag used to track the legality of a null output
498
499 Result_Seen : Boolean := False;
500 -- A flag set when Subp_Id'Result is processed
501
502 Spec_Id : Entity_Id;
503 -- The entity of the subprogram subject to pragma [Refined_]Depends
504
505 Subp_Id : Entity_Id;
506 -- The entity of the subprogram [body or stub] subject to pragma
507 -- [Refined_]Depends.
508
509 Subp_Inputs : Elist_Id := No_Elist;
510 Subp_Outputs : Elist_Id := No_Elist;
511 -- Two lists containing the full set of inputs and output of the related
512 -- subprograms. Note that these lists contain both nodes and entities.
513
514 procedure Analyze_Dependency_Clause
515 (Clause : Node_Id;
516 Is_Last : Boolean);
517 -- Verify the legality of a single dependency clause. Flag Is_Last
518 -- denotes whether Clause is the last clause in the relation.
519
520 procedure Check_Function_Return;
521 -- Verify that Funtion'Result appears as one of the outputs
522
523 procedure Check_Mode
524 (Item : Node_Id;
525 Item_Id : Entity_Id;
526 Is_Input : Boolean;
527 Self_Ref : Boolean);
528 -- Ensure that an item has a proper IN, IN OUT, or OUT mode depending
529 -- on its function. If this is not the case, emit an error. Item and
530 -- Item_Id denote the attributes of an item. Flag Is_Input should be set
531 -- when item comes from an input list. Flag Self_Ref should be set when
532 -- the item is an output and the dependency clause has operator "+".
533
534 procedure Check_Usage
535 (Subp_Items : Elist_Id;
536 Used_Items : Elist_Id;
537 Is_Input : Boolean);
538 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
539 -- error if this is not the case.
540
541 procedure Normalize_Clause (Clause : Node_Id);
542 -- Remove a self-dependency "+" from the input list of a clause. Split
543 -- a clause with multiple outputs into multiple clauses with a single
544 -- output.
545
546 -------------------------------
547 -- Analyze_Dependency_Clause --
548 -------------------------------
549
550 procedure Analyze_Dependency_Clause
551 (Clause : Node_Id;
552 Is_Last : Boolean)
553 is
554 procedure Analyze_Input_List (Inputs : Node_Id);
555 -- Verify the legality of a single input list
556
557 procedure Analyze_Input_Output
558 (Item : Node_Id;
559 Is_Input : Boolean;
560 Self_Ref : Boolean;
561 Top_Level : Boolean;
562 Seen : in out Elist_Id;
563 Null_Seen : in out Boolean);
564 -- Verify the legality of a single input or output item. Flag
565 -- Is_Input should be set whenever Item is an input, False when it
566 -- denotes an output. Flag Self_Ref should be set when the item is an
567 -- output and the dependency clause has a "+". Flag Top_Level should
568 -- be set whenever Item appears immediately within an input or output
569 -- list. Seen is a collection of all abstract states, variables and
570 -- formals processed so far. Flag Null_Seen denotes whether a null
571 -- input or output has been encountered.
572
573 ------------------------
574 -- Analyze_Input_List --
575 ------------------------
576
577 procedure Analyze_Input_List (Inputs : Node_Id) is
578 Inputs_Seen : Elist_Id := No_Elist;
579 -- A list containing the entities of all inputs that appear in the
580 -- current input list.
581
582 Null_Input_Seen : Boolean := False;
583 -- A flag used to track the legality of a null input
584
585 Input : Node_Id;
586
587 begin
588 -- Multiple inputs appear as an aggregate
589
590 if Nkind (Inputs) = N_Aggregate then
591 if Present (Component_Associations (Inputs)) then
592 Error_Msg_N
593 ("nested dependency relations not allowed", Inputs);
594
595 elsif Present (Expressions (Inputs)) then
596 Input := First (Expressions (Inputs));
597 while Present (Input) loop
598 Analyze_Input_Output
599 (Item => Input,
600 Is_Input => True,
601 Self_Ref => False,
602 Top_Level => False,
603 Seen => Inputs_Seen,
604 Null_Seen => Null_Input_Seen);
605
606 Next (Input);
607 end loop;
608
609 else
610 Error_Msg_N ("malformed input dependency list", Inputs);
611 end if;
612
613 -- Process a solitary input
614
615 else
616 Analyze_Input_Output
617 (Item => Inputs,
618 Is_Input => True,
619 Self_Ref => False,
620 Top_Level => False,
621 Seen => Inputs_Seen,
622 Null_Seen => Null_Input_Seen);
623 end if;
624
625 -- Detect an illegal dependency clause of the form
626
627 -- (null =>[+] null)
628
629 if Null_Output_Seen and then Null_Input_Seen then
630 Error_Msg_N
631 ("null dependency clause cannot have a null input list",
632 Inputs);
633 end if;
634 end Analyze_Input_List;
635
636 --------------------------
637 -- Analyze_Input_Output --
638 --------------------------
639
640 procedure Analyze_Input_Output
641 (Item : Node_Id;
642 Is_Input : Boolean;
643 Self_Ref : Boolean;
644 Top_Level : Boolean;
645 Seen : in out Elist_Id;
646 Null_Seen : in out Boolean)
647 is
648 Is_Output : constant Boolean := not Is_Input;
649 Grouped : Node_Id;
650 Item_Id : Entity_Id;
651
652 begin
653 -- Multiple input or output items appear as an aggregate
654
655 if Nkind (Item) = N_Aggregate then
656 if not Top_Level then
657 Error_Msg_N ("nested grouping of items not allowed", Item);
658
659 elsif Present (Component_Associations (Item)) then
660 Error_Msg_N
661 ("nested dependency relations not allowed", Item);
662
663 -- Recursively analyze the grouped items
664
665 elsif Present (Expressions (Item)) then
666 Grouped := First (Expressions (Item));
667 while Present (Grouped) loop
668 Analyze_Input_Output
669 (Item => Grouped,
670 Is_Input => Is_Input,
671 Self_Ref => Self_Ref,
672 Top_Level => False,
673 Seen => Seen,
674 Null_Seen => Null_Seen);
675
676 Next (Grouped);
677 end loop;
678
679 else
680 Error_Msg_N ("malformed dependency list", Item);
681 end if;
682
683 -- Process Function'Result in the context of a dependency clause
684
685 elsif Is_Attribute_Result (Item) then
686
687 -- It is sufficent to analyze the prefix of 'Result in order to
688 -- establish legality of the attribute.
689
690 Analyze (Prefix (Item));
691
692 -- The prefix of 'Result must denote the function for which
693 -- pragma Depends applies.
694
695 if not Is_Entity_Name (Prefix (Item))
696 or else Ekind (Spec_Id) /= E_Function
697 or else Entity (Prefix (Item)) /= Spec_Id
698 then
699 Error_Msg_Name_1 := Name_Result;
700 Error_Msg_N
701 ("prefix of attribute % must denote the enclosing "
702 & "function", Item);
703
704 -- Function'Result is allowed to appear on the output side of a
705 -- dependency clause.
706
707 elsif Is_Input then
708 Error_Msg_N ("function result cannot act as input", Item);
709
710 else
711 Result_Seen := True;
712 end if;
713
714 -- Detect multiple uses of null in a single dependency list or
715 -- throughout the whole relation. Verify the placement of a null
716 -- output list relative to the other clauses.
717
718 elsif Nkind (Item) = N_Null then
719 if Null_Seen then
720 Error_Msg_N
721 ("multiple null dependency relations not allowed", Item);
722 else
723 Null_Seen := True;
724
725 if Is_Output and then not Is_Last then
726 Error_Msg_N
727 ("null output list must be the last clause in a "
728 & "dependency relation", Item);
729 end if;
730 end if;
731
732 -- Default case
733
734 else
735 Analyze (Item);
736
737 -- Find the entity of the item. If this is a renaming, climb
738 -- the renaming chain to reach the root object. Renamings of
739 -- non-entire objects do not yield an entity (Empty).
740
741 Item_Id := Entity_Of (Item);
742
743 if Present (Item_Id) then
744 if Ekind_In (Item_Id, E_Abstract_State,
745 E_In_Parameter,
746 E_In_Out_Parameter,
747 E_Out_Parameter,
748 E_Variable)
749 then
750 -- Ensure that the item is of the correct mode depending
751 -- on its function.
752
753 Check_Mode (Item, Item_Id, Is_Input, Self_Ref);
754
755 -- Detect multiple uses of the same state, variable or
756 -- formal parameter. If this is not the case, add the
757 -- item to the list of processed relations.
758
759 if Contains (Seen, Item_Id) then
760 Error_Msg_N ("duplicate use of item", Item);
761 else
762 Add_Item (Item_Id, Seen);
763 end if;
764
765 -- Detect illegal use of an input related to a null
766 -- output. Such input items cannot appear in other
767 -- input lists.
768
769 if Is_Input
770 and then Null_Output_Seen
771 and then Contains (All_Inputs_Seen, Item_Id)
772 then
773 Error_Msg_N
774 ("input of a null output list appears in multiple "
775 & "input lists", Item);
776 end if;
777
778 -- Add an input or a self-referential output to the list
779 -- of all processed inputs.
780
781 if Is_Input or else Self_Ref then
782 Add_Item (Item_Id, All_Inputs_Seen);
783 end if;
784
785 if Ekind (Item_Id) = E_Abstract_State then
786
787 -- The state acts as a constituent of some other
788 -- state. Ensure that the other state is a proper
789 -- ancestor of the item.
790
791 if Present (Refined_State (Item_Id)) then
792 if not Is_Part_Of
793 (Item_Id, Refined_State (Item_Id))
794 then
795 Error_Msg_Name_1 :=
796 Chars (Refined_State (Item_Id));
797 Error_Msg_NE
798 ("state & is not a valid constituent of "
799 & "ancestor state %", Item, Item_Id);
800 return;
801 end if;
802
803 -- An abstract state with visible refinement cannot
804 -- appear in pragma [Refined_]Global as its place must
805 -- be taken by some of its constituents.
806
807 elsif Has_Visible_Refinement (Item_Id) then
808 Error_Msg_NE
809 ("cannot mention state & in global refinement, "
810 & "use its constituents instead", Item, Item_Id);
811 return;
812 end if;
813 end if;
814
815 -- When the item renames an entire object, replace the
816 -- item with a reference to the object.
817
818 if Present (Renamed_Object (Entity (Item))) then
819 Rewrite (Item,
820 New_Reference_To (Item_Id, Sloc (Item)));
821 Analyze (Item);
822 end if;
823
824 -- All other input/output items are illegal
825
826 else
827 Error_Msg_N
828 ("item must denote variable, state or formal "
829 & "parameter", Item);
830 end if;
831
832 -- All other input/output items are illegal
833
834 else
835 Error_Msg_N
836 ("item must denote variable, state or formal parameter",
837 Item);
838 end if;
839 end if;
840 end Analyze_Input_Output;
841
842 -- Local variables
843
844 Inputs : Node_Id;
845 Output : Node_Id;
846 Self_Ref : Boolean;
847
848 -- Start of processing for Analyze_Dependency_Clause
849
850 begin
851 Inputs := Expression (Clause);
852 Self_Ref := False;
853
854 -- An input list with a self-dependency appears as operator "+" where
855 -- the actuals inputs are the right operand.
856
857 if Nkind (Inputs) = N_Op_Plus then
858 Inputs := Right_Opnd (Inputs);
859 Self_Ref := True;
860 end if;
861
862 -- Process the output_list of a dependency_clause
863
864 Output := First (Choices (Clause));
865 while Present (Output) loop
866 Analyze_Input_Output
867 (Item => Output,
868 Is_Input => False,
869 Self_Ref => Self_Ref,
870 Top_Level => True,
871 Seen => All_Outputs_Seen,
872 Null_Seen => Null_Output_Seen);
873
874 Next (Output);
875 end loop;
876
877 -- Process the input_list of a dependency_clause
878
879 Analyze_Input_List (Inputs);
880 end Analyze_Dependency_Clause;
881
882 ----------------------------
883 -- Check_Function_Return --
884 ----------------------------
885
886 procedure Check_Function_Return is
887 begin
888 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
889 Error_Msg_NE
890 ("result of & must appear in exactly one output list",
891 N, Spec_Id);
892 end if;
893 end Check_Function_Return;
894
895 ----------------
896 -- Check_Mode --
897 ----------------
898
899 procedure Check_Mode
900 (Item : Node_Id;
901 Item_Id : Entity_Id;
902 Is_Input : Boolean;
903 Self_Ref : Boolean)
904 is
905 begin
906 -- Input
907
908 if Is_Input then
909
910 -- IN and IN OUT parameters already have the proper mode to act
911 -- as input. OUT parameters are valid inputs only when their type
912 -- is unconstrained or tagged as their discriminants, array bouns
913 -- or tags can be read. In general, states and variables are
914 -- considered to have mode IN OUT unless they are moded by pragma
915 -- [Refined_]Global. In that case, the item must appear in an
916 -- input global list.
917
918 if (Ekind (Item_Id) = E_Out_Parameter
919 and then not Is_Unconstrained_Or_Tagged_Item (Item_Id))
920 or else
921 (Global_Seen and then not Appears_In (Subp_Inputs, Item_Id))
922 then
923 Error_Msg_NE
924 ("item & must have mode IN or `IN OUT`", Item, Item_Id);
925 end if;
926
927 -- Self-referential output
928
929 elsif Self_Ref then
930
931 -- In general, states and variables are considered to have mode
932 -- IN OUT unless they are explicitly moded by pragma [Refined_]
933 -- Global. If this is the case, then the item must appear in both
934 -- an input and output global list.
935
936 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
937 if Global_Seen
938 and then not
939 (Appears_In (Subp_Inputs, Item_Id)
940 and then
941 Appears_In (Subp_Outputs, Item_Id))
942 then
943 Error_Msg_NE
944 ("item & must have mode `IN OUT`", Item, Item_Id);
945 end if;
946
947 -- A self-referential OUT parameter of an unconstrained or tagged
948 -- type acts as an input because the discriminants, array bounds
949 -- or the tag may be read. Note that the presence of [Refined_]
950 -- Global is not significant here because the item is a parameter.
951
952 elsif Ekind (Item_Id) = E_Out_Parameter
953 and then Is_Unconstrained_Or_Tagged_Item (Item_Id)
954 then
955 null;
956
957 -- The remaining cases are IN, IN OUT, and OUT parameters. To
958 -- qualify as self-referential item, the parameter must be of
959 -- mode IN OUT.
960
961 elsif Ekind (Item_Id) /= E_In_Out_Parameter then
962 Error_Msg_NE ("item & must have mode `IN OUT`", Item, Item_Id);
963 end if;
964
965 -- Output
966
967 -- IN OUT and OUT parameters already have the proper mode to act as
968 -- output. In general, states and variables are considered to have
969 -- mode IN OUT unless they are moded by pragma [Refined_]Global. In
970 -- that case, the item must appear in an output global list.
971
972 elsif Ekind (Item_Id) = E_In_Parameter
973 or else
974 (Global_Seen and then not Appears_In (Subp_Outputs, Item_Id))
975 then
976 Error_Msg_NE
977 ("item & must have mode OUT or `IN OUT`", Item, Item_Id);
978 end if;
979 end Check_Mode;
980
981 -----------------
982 -- Check_Usage --
983 -----------------
984
985 procedure Check_Usage
986 (Subp_Items : Elist_Id;
987 Used_Items : Elist_Id;
988 Is_Input : Boolean)
989 is
990 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
991 -- Emit an error concerning the erroneous usage of an item
992
993 -----------------
994 -- Usage_Error --
995 -----------------
996
997 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
998 begin
999 if Is_Input then
1000 Error_Msg_NE
1001 ("item & must appear in at least one input list of aspect "
1002 & "Depends", Item, Item_Id);
1003 else
1004 Error_Msg_NE
1005 ("item & must appear in exactly one output list of aspect "
1006 & "Depends", Item, Item_Id);
1007 end if;
1008 end Usage_Error;
1009
1010 -- Local variables
1011
1012 Elmt : Elmt_Id;
1013 Item : Node_Id;
1014 Item_Id : Entity_Id;
1015
1016 -- Start of processing for Check_Usage
1017
1018 begin
1019 if No (Subp_Items) then
1020 return;
1021 end if;
1022
1023 -- Each input or output of the subprogram must appear in a dependency
1024 -- relation.
1025
1026 Elmt := First_Elmt (Subp_Items);
1027 while Present (Elmt) loop
1028 Item := Node (Elmt);
1029
1030 if Nkind (Item) = N_Defining_Identifier then
1031 Item_Id := Item;
1032 else
1033 Item_Id := Entity (Item);
1034 end if;
1035
1036 -- The item does not appear in a dependency
1037
1038 if not Contains (Used_Items, Item_Id) then
1039 if Is_Formal (Item_Id) then
1040 Usage_Error (Item, Item_Id);
1041
1042 -- States and global variables are not used properly only when
1043 -- the subprogram is subject to pragma Global.
1044
1045 elsif Global_Seen then
1046 Usage_Error (Item, Item_Id);
1047 end if;
1048 end if;
1049
1050 Next_Elmt (Elmt);
1051 end loop;
1052 end Check_Usage;
1053
1054 ----------------------
1055 -- Normalize_Clause --
1056 ----------------------
1057
1058 procedure Normalize_Clause (Clause : Node_Id) is
1059 procedure Create_Or_Modify_Clause
1060 (Output : Node_Id;
1061 Outputs : Node_Id;
1062 Inputs : Node_Id;
1063 After : Node_Id;
1064 In_Place : Boolean;
1065 Multiple : Boolean);
1066 -- Create a brand new clause to represent the self-reference or
1067 -- modify the input and/or output lists of an existing clause. Output
1068 -- denotes a self-referencial output. Outputs is the output list of a
1069 -- clause. Inputs is the input list of a clause. After denotes the
1070 -- clause after which the new clause is to be inserted. Flag In_Place
1071 -- should be set when normalizing the last output of an output list.
1072 -- Flag Multiple should be set when Output comes from a list with
1073 -- multiple items.
1074
1075 procedure Split_Multiple_Outputs;
1076 -- If Clause contains more than one output, split the clause into
1077 -- multiple clauses with a single output. All new clauses are added
1078 -- after Clause.
1079
1080 -----------------------------
1081 -- Create_Or_Modify_Clause --
1082 -----------------------------
1083
1084 procedure Create_Or_Modify_Clause
1085 (Output : Node_Id;
1086 Outputs : Node_Id;
1087 Inputs : Node_Id;
1088 After : Node_Id;
1089 In_Place : Boolean;
1090 Multiple : Boolean)
1091 is
1092 procedure Propagate_Output
1093 (Output : Node_Id;
1094 Inputs : Node_Id);
1095 -- Handle the various cases of output propagation to the input
1096 -- list. Output denotes a self-referencial output item. Inputs is
1097 -- the input list of a clause.
1098
1099 ----------------------
1100 -- Propagate_Output --
1101 ----------------------
1102
1103 procedure Propagate_Output
1104 (Output : Node_Id;
1105 Inputs : Node_Id)
1106 is
1107 function In_Input_List
1108 (Item : Entity_Id;
1109 Inputs : List_Id) return Boolean;
1110 -- Determine whether a particulat item appears in the input
1111 -- list of a clause.
1112
1113 -------------------
1114 -- In_Input_List --
1115 -------------------
1116
1117 function In_Input_List
1118 (Item : Entity_Id;
1119 Inputs : List_Id) return Boolean
1120 is
1121 Elmt : Node_Id;
1122
1123 begin
1124 Elmt := First (Inputs);
1125 while Present (Elmt) loop
1126 if Entity_Of (Elmt) = Item then
1127 return True;
1128 end if;
1129
1130 Next (Elmt);
1131 end loop;
1132
1133 return False;
1134 end In_Input_List;
1135
1136 -- Local variables
1137
1138 Output_Id : constant Entity_Id := Entity_Of (Output);
1139 Grouped : List_Id;
1140
1141 -- Start of processing for Propagate_Output
1142
1143 begin
1144 -- The clause is of the form:
1145
1146 -- (Output =>+ null)
1147
1148 -- Remove the null input and replace it with a copy of the
1149 -- output:
1150
1151 -- (Output => Output)
1152
1153 if Nkind (Inputs) = N_Null then
1154 Rewrite (Inputs, New_Copy_Tree (Output));
1155
1156 -- The clause is of the form:
1157
1158 -- (Output =>+ (Input1, ..., InputN))
1159
1160 -- Determine whether the output is not already mentioned in the
1161 -- input list and if not, add it to the list of inputs:
1162
1163 -- (Output => (Output, Input1, ..., InputN))
1164
1165 elsif Nkind (Inputs) = N_Aggregate then
1166 Grouped := Expressions (Inputs);
1167
1168 if not In_Input_List
1169 (Item => Output_Id,
1170 Inputs => Grouped)
1171 then
1172 Prepend_To (Grouped, New_Copy_Tree (Output));
1173 end if;
1174
1175 -- The clause is of the form:
1176
1177 -- (Output =>+ Input)
1178
1179 -- If the input does not mention the output, group the two
1180 -- together:
1181
1182 -- (Output => (Output, Input))
1183
1184 elsif Entity_Of (Inputs) /= Output_Id then
1185 Rewrite (Inputs,
1186 Make_Aggregate (Loc,
1187 Expressions => New_List (
1188 New_Copy_Tree (Output),
1189 New_Copy_Tree (Inputs))));
1190 end if;
1191 end Propagate_Output;
1192
1193 -- Local variables
1194
1195 Loc : constant Source_Ptr := Sloc (Clause);
1196 New_Clause : Node_Id;
1197
1198 -- Start of processing for Create_Or_Modify_Clause
1199
1200 begin
1201 -- A null output depending on itself does not require any
1202 -- normalization.
1203
1204 if Nkind (Output) = N_Null then
1205 return;
1206
1207 -- A function result cannot depend on itself because it cannot
1208 -- appear in the input list of a relation.
1209
1210 elsif Is_Attribute_Result (Output) then
1211 Error_Msg_N ("function result cannot depend on itself", Output);
1212 return;
1213 end if;
1214
1215 -- When performing the transformation in place, simply add the
1216 -- output to the list of inputs (if not already there). This case
1217 -- arises when dealing with the last output of an output list -
1218 -- we perform the normalization in place to avoid generating a
1219 -- malformed tree.
1220
1221 if In_Place then
1222 Propagate_Output (Output, Inputs);
1223
1224 -- A list with multiple outputs is slowly trimmed until only
1225 -- one element remains. When this happens, replace the
1226 -- aggregate with the element itself.
1227
1228 if Multiple then
1229 Remove (Output);
1230 Rewrite (Outputs, Output);
1231 end if;
1232
1233 -- Default case
1234
1235 else
1236 -- Unchain the output from its output list as it will appear in
1237 -- a new clause. Note that we cannot simply rewrite the output
1238 -- as null because this will violate the semantics of pragma
1239 -- Depends.
1240
1241 Remove (Output);
1242
1243 -- Generate a new clause of the form:
1244 -- (Output => Inputs)
1245
1246 New_Clause :=
1247 Make_Component_Association (Loc,
1248 Choices => New_List (Output),
1249 Expression => New_Copy_Tree (Inputs));
1250
1251 -- The new clause contains replicated content that has already
1252 -- been analyzed. There is not need to reanalyze it or
1253 -- renormalize it again.
1254
1255 Set_Analyzed (New_Clause);
1256
1257 Propagate_Output
1258 (Output => First (Choices (New_Clause)),
1259 Inputs => Expression (New_Clause));
1260
1261 Insert_After (After, New_Clause);
1262 end if;
1263 end Create_Or_Modify_Clause;
1264
1265 ----------------------------
1266 -- Split_Multiple_Outputs --
1267 ----------------------------
1268
1269 procedure Split_Multiple_Outputs is
1270 Inputs : constant Node_Id := Expression (Clause);
1271 Loc : constant Source_Ptr := Sloc (Clause);
1272 Outputs : constant Node_Id := First (Choices (Clause));
1273 Last_Output : Node_Id;
1274 Next_Output : Node_Id;
1275 Output : Node_Id;
1276 Split : Node_Id;
1277
1278 -- Start of processing for Split_Multiple_Outputs
1279
1280 begin
1281 -- Multiple outputs appear as an aggregate. Nothing to do when
1282 -- the clause has exactly one output.
1283
1284 if Nkind (Outputs) = N_Aggregate then
1285 Last_Output := Last (Expressions (Outputs));
1286
1287 -- Create a clause for each output. Note that each time a new
1288 -- clause is created, the original output list slowly shrinks
1289 -- until there is one item left.
1290
1291 Output := First (Expressions (Outputs));
1292 while Present (Output) loop
1293 Next_Output := Next (Output);
1294
1295 -- Unhook the output from the original output list as it
1296 -- will be relocated to a new clause.
1297
1298 Remove (Output);
1299
1300 -- Special processing for the last output. At this point
1301 -- the original aggregate has been stripped down to one
1302 -- element. Replace the aggregate by the element itself.
1303
1304 if Output = Last_Output then
1305 Rewrite (Outputs, Output);
1306
1307 else
1308 -- Generate a clause of the form:
1309 -- (Output => Inputs)
1310
1311 Split :=
1312 Make_Component_Association (Loc,
1313 Choices => New_List (Output),
1314 Expression => New_Copy_Tree (Inputs));
1315
1316 -- The new clause contains replicated content that has
1317 -- already been analyzed. There is not need to reanalyze
1318 -- them.
1319
1320 Set_Analyzed (Split);
1321 Insert_After (Clause, Split);
1322 end if;
1323
1324 Output := Next_Output;
1325 end loop;
1326 end if;
1327 end Split_Multiple_Outputs;
1328
1329 -- Local variables
1330
1331 Outputs : constant Node_Id := First (Choices (Clause));
1332 Inputs : Node_Id;
1333 Last_Output : Node_Id;
1334 Next_Output : Node_Id;
1335 Output : Node_Id;
1336
1337 -- Start of processing for Normalize_Clause
1338
1339 begin
1340 -- A self-dependency appears as operator "+". Remove the "+" from the
1341 -- tree by moving the real inputs to their proper place.
1342
1343 if Nkind (Expression (Clause)) = N_Op_Plus then
1344 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1345 Inputs := Expression (Clause);
1346
1347 -- Multiple outputs appear as an aggregate
1348
1349 if Nkind (Outputs) = N_Aggregate then
1350 Last_Output := Last (Expressions (Outputs));
1351
1352 Output := First (Expressions (Outputs));
1353 while Present (Output) loop
1354
1355 -- Normalization may remove an output from its list,
1356 -- preserve the subsequent output now.
1357
1358 Next_Output := Next (Output);
1359
1360 Create_Or_Modify_Clause
1361 (Output => Output,
1362 Outputs => Outputs,
1363 Inputs => Inputs,
1364 After => Clause,
1365 In_Place => Output = Last_Output,
1366 Multiple => True);
1367
1368 Output := Next_Output;
1369 end loop;
1370
1371 -- Solitary output
1372
1373 else
1374 Create_Or_Modify_Clause
1375 (Output => Outputs,
1376 Outputs => Empty,
1377 Inputs => Inputs,
1378 After => Empty,
1379 In_Place => True,
1380 Multiple => False);
1381 end if;
1382 end if;
1383
1384 -- Split a clause with multiple outputs into multiple clauses with a
1385 -- single output.
1386
1387 Split_Multiple_Outputs;
1388 end Normalize_Clause;
1389
1390 -- Local variables
1391
1392 Clause : Node_Id;
1393 Errors : Nat;
1394 Last_Clause : Node_Id;
1395 Subp_Decl : Node_Id;
1396
1397 Restore_Scope : Boolean := False;
1398 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1399
1400 -- Start of processing for Analyze_Depends_In_Decl_Part
1401
1402 begin
1403 Set_Analyzed (N);
1404
1405 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1406 Subp_Id := Defining_Entity (Subp_Decl);
1407
1408 -- The logic in this routine is used to analyze both pragma Depends and
1409 -- pragma Refined_Depends since they have the same syntax and base
1410 -- semantics. Find the entity of the corresponding spec when analyzing
1411 -- Refined_Depends.
1412
1413 if Nkind (Subp_Decl) = N_Subprogram_Body
1414 and then not Acts_As_Spec (Subp_Decl)
1415 then
1416 Spec_Id := Corresponding_Spec (Subp_Decl);
1417
1418 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub then
1419 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1420
1421 else
1422 Spec_Id := Subp_Id;
1423 end if;
1424
1425 Clause := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
1426
1427 -- Empty dependency list
1428
1429 if Nkind (Clause) = N_Null then
1430
1431 -- Gather all states, variables and formal parameters that the
1432 -- subprogram may depend on. These items are obtained from the
1433 -- parameter profile or pragma [Refined_]Global (if available).
1434
1435 Collect_Subprogram_Inputs_Outputs
1436 (Subp_Id => Subp_Id,
1437 Subp_Inputs => Subp_Inputs,
1438 Subp_Outputs => Subp_Outputs,
1439 Global_Seen => Global_Seen);
1440
1441 -- Verify that every input or output of the subprogram appear in a
1442 -- dependency.
1443
1444 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1445 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1446 Check_Function_Return;
1447
1448 -- Dependency clauses appear as component associations of an aggregate
1449
1450 elsif Nkind (Clause) = N_Aggregate
1451 and then Present (Component_Associations (Clause))
1452 then
1453 Last_Clause := Last (Component_Associations (Clause));
1454
1455 -- Gather all states, variables and formal parameters that the
1456 -- subprogram may depend on. These items are obtained from the
1457 -- parameter profile or pragma [Refined_]Global (if available).
1458
1459 Collect_Subprogram_Inputs_Outputs
1460 (Subp_Id => Subp_Id,
1461 Subp_Inputs => Subp_Inputs,
1462 Subp_Outputs => Subp_Outputs,
1463 Global_Seen => Global_Seen);
1464
1465 -- Ensure that the formal parameters are visible when analyzing all
1466 -- clauses. This falls out of the general rule of aspects pertaining
1467 -- to subprogram declarations. Skip the installation for subprogram
1468 -- bodies because the formals are already visible.
1469
1470 if not In_Open_Scopes (Spec_Id) then
1471 Restore_Scope := True;
1472 Push_Scope (Spec_Id);
1473 Install_Formals (Spec_Id);
1474 end if;
1475
1476 Clause := First (Component_Associations (Clause));
1477 while Present (Clause) loop
1478 Errors := Serious_Errors_Detected;
1479
1480 -- Normalization may create extra clauses that contain replicated
1481 -- input and output names. There is no need to reanalyze them.
1482
1483 if not Analyzed (Clause) then
1484 Set_Analyzed (Clause);
1485
1486 Analyze_Dependency_Clause
1487 (Clause => Clause,
1488 Is_Last => Clause = Last_Clause);
1489 end if;
1490
1491 -- Do not normalize an erroneous clause because the inputs and/or
1492 -- outputs may denote illegal items.
1493
1494 if Serious_Errors_Detected = Errors then
1495 Normalize_Clause (Clause);
1496 end if;
1497
1498 Next (Clause);
1499 end loop;
1500
1501 if Restore_Scope then
1502 End_Scope;
1503 end if;
1504
1505 -- Verify that every input or output of the subprogram appear in a
1506 -- dependency.
1507
1508 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1509 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1510 Check_Function_Return;
1511
1512 -- The top level dependency relation is malformed
1513
1514 else
1515 Error_Msg_N ("malformed dependency relation", Clause);
1516 end if;
1517 end Analyze_Depends_In_Decl_Part;
1518
1519 ---------------------------------
1520 -- Analyze_Global_In_Decl_Part --
1521 ---------------------------------
1522
1523 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1524 Seen : Elist_Id := No_Elist;
1525 -- A list containing the entities of all the items processed so far. It
1526 -- plays a role in detecting distinct entities.
1527
1528 Spec_Id : Entity_Id;
1529 -- The entity of the subprogram subject to pragma [Refined_]Global
1530
1531 Subp_Id : Entity_Id;
1532 -- The entity of the subprogram [body or stub] subject to pragma
1533 -- [Refined_]Global.
1534
1535 In_Out_Seen : Boolean := False;
1536 Input_Seen : Boolean := False;
1537 Output_Seen : Boolean := False;
1538 Proof_Seen : Boolean := False;
1539 -- Flags used to verify the consistency of modes
1540
1541 procedure Analyze_Global_List
1542 (List : Node_Id;
1543 Global_Mode : Name_Id := Name_Input);
1544 -- Verify the legality of a single global list declaration. Global_Mode
1545 -- denotes the current mode in effect.
1546
1547 -------------------------
1548 -- Analyze_Global_List --
1549 -------------------------
1550
1551 procedure Analyze_Global_List
1552 (List : Node_Id;
1553 Global_Mode : Name_Id := Name_Input)
1554 is
1555 procedure Analyze_Global_Item
1556 (Item : Node_Id;
1557 Global_Mode : Name_Id);
1558 -- Verify the legality of a single global item declaration.
1559 -- Global_Mode denotes the current mode in effect.
1560
1561 procedure Check_Duplicate_Mode
1562 (Mode : Node_Id;
1563 Status : in out Boolean);
1564 -- Flag Status denotes whether a particular mode has been seen while
1565 -- processing a global list. This routine verifies that Mode is not a
1566 -- duplicate mode and sets the flag Status.
1567
1568 procedure Check_Mode_Restriction_In_Enclosing_Context
1569 (Item : Node_Id;
1570 Item_Id : Entity_Id);
1571 -- Verify that an item of mode In_Out or Output does not appear as an
1572 -- input in the Global aspect of an enclosing subprogram. If this is
1573 -- the case, emit an error. Item and Item_Id are respectively the
1574 -- item and its entity.
1575
1576 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1577 -- Mode denotes either In_Out or Output. Depending on the kind of the
1578 -- related subprogram, emit an error if those two modes apply to a
1579 -- function.
1580
1581 -------------------------
1582 -- Analyze_Global_Item --
1583 -------------------------
1584
1585 procedure Analyze_Global_Item
1586 (Item : Node_Id;
1587 Global_Mode : Name_Id)
1588 is
1589 Item_Id : Entity_Id;
1590
1591 begin
1592 -- Detect one of the following cases
1593
1594 -- with Global => (null, Name)
1595 -- with Global => (Name_1, null, Name_2)
1596 -- with Global => (Name, null)
1597
1598 if Nkind (Item) = N_Null then
1599 Error_Msg_N ("cannot mix null and non-null global items", Item);
1600 return;
1601 end if;
1602
1603 Analyze (Item);
1604
1605 -- Find the entity of the item. If this is a renaming, climb the
1606 -- renaming chain to reach the root object. Renamings of non-
1607 -- entire objects do not yield an entity (Empty).
1608
1609 Item_Id := Entity_Of (Item);
1610
1611 if Present (Item_Id) then
1612
1613 -- A global item may denote a formal parameter of an enclosing
1614 -- subprogram. Do this check first to provide a better error
1615 -- diagnostic.
1616
1617 if Is_Formal (Item_Id) then
1618 if Scope (Item_Id) = Spec_Id then
1619 Error_Msg_N
1620 ("global item cannot reference formal parameter", Item);
1621 return;
1622 end if;
1623
1624 -- The only legal references are those to abstract states and
1625 -- variables.
1626
1627 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1628 Error_Msg_N
1629 ("global item must denote variable or state", Item);
1630 return;
1631 end if;
1632
1633 if Ekind (Item_Id) = E_Abstract_State then
1634
1635 -- The state acts as a constituent of some other state.
1636 -- Ensure that the other state is a proper ancestor of the
1637 -- item.
1638
1639 if Present (Refined_State (Item_Id)) then
1640 if not Is_Part_Of (Item_Id, Refined_State (Item_Id)) then
1641 Error_Msg_Name_1 := Chars (Refined_State (Item_Id));
1642 Error_Msg_NE
1643 ("state & is not a valid constituent of ancestor "
1644 & "state %", Item, Item_Id);
1645 return;
1646 end if;
1647
1648 -- An abstract state with visible refinement cannot appear
1649 -- in pragma [Refined_]Global as its place must be taken by
1650 -- some of its constituents.
1651
1652 elsif Has_Visible_Refinement (Item_Id) then
1653 Error_Msg_NE
1654 ("cannot mention state & in global refinement, use its "
1655 & "constituents instead", Item, Item_Id);
1656 return;
1657 end if;
1658 end if;
1659
1660 -- When the item renames an entire object, replace the item
1661 -- with a reference to the object.
1662
1663 if Present (Renamed_Object (Entity (Item))) then
1664 Rewrite (Item, New_Reference_To (Item_Id, Sloc (Item)));
1665 Analyze (Item);
1666 end if;
1667
1668 -- Some form of illegal construct masquerading as a name
1669
1670 else
1671 Error_Msg_N ("global item must denote variable or state", Item);
1672 return;
1673 end if;
1674
1675 -- At this point we know that the global item is one of the two
1676 -- valid choices. Perform mode- and usage-specific checks.
1677
1678 if Ekind (Item_Id) = E_Abstract_State
1679 and then Is_External_State (Item_Id)
1680 then
1681 -- A global item of mode In_Out or Output cannot denote an
1682 -- external Input_Only state.
1683
1684 if Is_Input_Only_State (Item_Id)
1685 and then Nam_In (Global_Mode, Name_In_Out, Name_Output)
1686 then
1687 Error_Msg_N
1688 ("global item of mode In_Out or Output cannot reference "
1689 & "External Input_Only state", Item);
1690
1691 -- A global item of mode In_Out or Input cannot reference an
1692 -- external Output_Only state.
1693
1694 elsif Is_Output_Only_State (Item_Id)
1695 and then Nam_In (Global_Mode, Name_In_Out, Name_Input)
1696 then
1697 Error_Msg_N
1698 ("global item of mode In_Out or Input cannot reference "
1699 & "External Output_Only state", Item);
1700 end if;
1701 end if;
1702
1703 -- Verify that an output does not appear as an input in an
1704 -- enclosing subprogram.
1705
1706 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1707 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1708 end if;
1709
1710 -- The same entity might be referenced through various way. Check
1711 -- the entity of the item rather than the item itself.
1712
1713 if Contains (Seen, Item_Id) then
1714 Error_Msg_N ("duplicate global item", Item);
1715
1716 -- Add the entity of the current item to the list of processed
1717 -- items.
1718
1719 else
1720 Add_Item (Item_Id, Seen);
1721 end if;
1722 end Analyze_Global_Item;
1723
1724 --------------------------
1725 -- Check_Duplicate_Mode --
1726 --------------------------
1727
1728 procedure Check_Duplicate_Mode
1729 (Mode : Node_Id;
1730 Status : in out Boolean)
1731 is
1732 begin
1733 if Status then
1734 Error_Msg_N ("duplicate global mode", Mode);
1735 end if;
1736
1737 Status := True;
1738 end Check_Duplicate_Mode;
1739
1740 -------------------------------------------------
1741 -- Check_Mode_Restriction_In_Enclosing_Context --
1742 -------------------------------------------------
1743
1744 procedure Check_Mode_Restriction_In_Enclosing_Context
1745 (Item : Node_Id;
1746 Item_Id : Entity_Id)
1747 is
1748 Context : Entity_Id;
1749 Dummy : Boolean;
1750 Inputs : Elist_Id := No_Elist;
1751 Outputs : Elist_Id := No_Elist;
1752
1753 begin
1754 -- Traverse the scope stack looking for enclosing subprograms
1755 -- subject to pragma [Refined_]Global.
1756
1757 Context := Scope (Subp_Id);
1758 while Present (Context) and then Context /= Standard_Standard loop
1759 if Is_Subprogram (Context)
1760 and then Present (Get_Pragma (Context, Pragma_Global))
1761 then
1762 Collect_Subprogram_Inputs_Outputs
1763 (Subp_Id => Context,
1764 Subp_Inputs => Inputs,
1765 Subp_Outputs => Outputs,
1766 Global_Seen => Dummy);
1767
1768 -- The item is classified as In_Out or Output but appears as
1769 -- an Input in an enclosing subprogram.
1770
1771 if Appears_In (Inputs, Item_Id)
1772 and then not Appears_In (Outputs, Item_Id)
1773 then
1774 Error_Msg_NE
1775 ("global item & cannot have mode In_Out or Output",
1776 Item, Item_Id);
1777 Error_Msg_NE
1778 ("\item already appears as input of subprogram &",
1779 Item, Context);
1780
1781 -- Stop the traversal once an error has been detected
1782
1783 exit;
1784 end if;
1785 end if;
1786
1787 Context := Scope (Context);
1788 end loop;
1789 end Check_Mode_Restriction_In_Enclosing_Context;
1790
1791 ----------------------------------------
1792 -- Check_Mode_Restriction_In_Function --
1793 ----------------------------------------
1794
1795 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
1796 begin
1797 if Ekind (Spec_Id) = E_Function then
1798 Error_Msg_N
1799 ("global mode & not applicable to functions", Mode);
1800 end if;
1801 end Check_Mode_Restriction_In_Function;
1802
1803 -- Local variables
1804
1805 Assoc : Node_Id;
1806 Item : Node_Id;
1807 Mode : Node_Id;
1808
1809 -- Start of processing for Analyze_Global_List
1810
1811 begin
1812 if Nkind (List) = N_Null then
1813 null;
1814
1815 -- Single global item declaration
1816
1817 elsif Nkind_In (List, N_Expanded_Name,
1818 N_Identifier,
1819 N_Selected_Component)
1820 then
1821 Analyze_Global_Item (List, Global_Mode);
1822
1823 -- Simple global list or moded global list declaration
1824
1825 elsif Nkind (List) = N_Aggregate then
1826
1827 -- The declaration of a simple global list appear as a collection
1828 -- of expressions.
1829
1830 if Present (Expressions (List)) then
1831 if Present (Component_Associations (List)) then
1832 Error_Msg_N
1833 ("cannot mix moded and non-moded global lists", List);
1834 end if;
1835
1836 Item := First (Expressions (List));
1837 while Present (Item) loop
1838 Analyze_Global_Item (Item, Global_Mode);
1839
1840 Next (Item);
1841 end loop;
1842
1843 -- The declaration of a moded global list appears as a collection
1844 -- of component associations where individual choices denote
1845 -- modes.
1846
1847 elsif Present (Component_Associations (List)) then
1848 if Present (Expressions (List)) then
1849 Error_Msg_N
1850 ("cannot mix moded and non-moded global lists", List);
1851 end if;
1852
1853 Assoc := First (Component_Associations (List));
1854 while Present (Assoc) loop
1855 Mode := First (Choices (Assoc));
1856
1857 if Nkind (Mode) = N_Identifier then
1858 if Chars (Mode) = Name_In_Out then
1859 Check_Duplicate_Mode (Mode, In_Out_Seen);
1860 Check_Mode_Restriction_In_Function (Mode);
1861
1862 elsif Chars (Mode) = Name_Input then
1863 Check_Duplicate_Mode (Mode, Input_Seen);
1864
1865 elsif Chars (Mode) = Name_Output then
1866 Check_Duplicate_Mode (Mode, Output_Seen);
1867 Check_Mode_Restriction_In_Function (Mode);
1868
1869 elsif Chars (Mode) = Name_Proof_In then
1870 Check_Duplicate_Mode (Mode, Proof_Seen);
1871
1872 else
1873 Error_Msg_N ("invalid mode selector", Mode);
1874 end if;
1875
1876 else
1877 Error_Msg_N ("invalid mode selector", Mode);
1878 end if;
1879
1880 -- Items in a moded list appear as a collection of
1881 -- expressions. Reuse the existing machinery to analyze
1882 -- them.
1883
1884 Analyze_Global_List
1885 (List => Expression (Assoc),
1886 Global_Mode => Chars (Mode));
1887
1888 Next (Assoc);
1889 end loop;
1890
1891 -- Invalid tree
1892
1893 else
1894 raise Program_Error;
1895 end if;
1896
1897 -- Any other attempt to declare a global item is erroneous
1898
1899 else
1900 Error_Msg_N ("malformed global list declaration", List);
1901 end if;
1902 end Analyze_Global_List;
1903
1904 -- Local variables
1905
1906 Items : Node_Id;
1907 Subp_Decl : Node_Id;
1908
1909 Restore_Scope : Boolean := False;
1910 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
1911
1912 -- Start of processing for Analyze_Global_In_Decl_List
1913
1914 begin
1915 Set_Analyzed (N);
1916
1917 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1918 Subp_Id := Defining_Entity (Subp_Decl);
1919
1920 -- The logic in this routine is used to analyze both pragma Global and
1921 -- pragma Refined_Global since they have the same syntax and base
1922 -- semantics. Find the entity of the corresponding spec when analyzing
1923 -- Refined_Global.
1924
1925 if Nkind (Subp_Decl) = N_Subprogram_Body
1926 and then not Acts_As_Spec (Subp_Decl)
1927 then
1928 Spec_Id := Corresponding_Spec (Subp_Decl);
1929
1930 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub then
1931 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1932
1933 else
1934 Spec_Id := Subp_Id;
1935 end if;
1936
1937 Items := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
1938
1939 -- There is nothing to be done for a null global list
1940
1941 if Nkind (Items) = N_Null then
1942 null;
1943
1944 -- Analyze the various forms of global lists and items. Note that some
1945 -- of these may be malformed in which case the analysis emits error
1946 -- messages.
1947
1948 else
1949 -- Ensure that the formal parameters are visible when processing an
1950 -- item. This falls out of the general rule of aspects pertaining to
1951 -- subprogram declarations.
1952
1953 if not In_Open_Scopes (Spec_Id) then
1954 Restore_Scope := True;
1955 Push_Scope (Spec_Id);
1956 Install_Formals (Spec_Id);
1957 end if;
1958
1959 Analyze_Global_List (Items);
1960
1961 if Restore_Scope then
1962 End_Scope;
1963 end if;
1964 end if;
1965 end Analyze_Global_In_Decl_Part;
1966
1967 --------------------------------------
1968 -- Analyze_Initializes_In_Decl_Part --
1969 --------------------------------------
1970
1971 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
1972 Pack_Spec : constant Node_Id := Parent (N);
1973 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Pack_Spec));
1974
1975 Items_Seen : Elist_Id := No_Elist;
1976 -- A list of all initialization items processed so far. This list is
1977 -- used to detect duplicate items.
1978
1979 Non_Null_Seen : Boolean := False;
1980 Null_Seen : Boolean := False;
1981 -- Flags used to check the legality of a null initialization list
1982
1983 States_And_Vars : Elist_Id := No_Elist;
1984 -- A list of all abstract states and variables declared in the visible
1985 -- declarations of the related package. This list is used to detect the
1986 -- legality of initialization items.
1987
1988 procedure Analyze_Initialization_Item (Item : Node_Id);
1989 -- Verify the legality of a single initialization item
1990
1991 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
1992 -- Verify the legality of a single initialization item followed by a
1993 -- list of input items.
1994
1995 procedure Collect_States_And_Variables;
1996 -- Inspect the visible declarations of the related package and gather
1997 -- the entities of all abstract states and variables in States_And_Vars.
1998
1999 ---------------------------------
2000 -- Analyze_Initialization_Item --
2001 ---------------------------------
2002
2003 procedure Analyze_Initialization_Item (Item : Node_Id) is
2004 Item_Id : Entity_Id;
2005
2006 begin
2007 -- A package with null initialization list is not allowed to have
2008 -- additional initializations.
2009
2010 if Null_Seen then
2011 Error_Msg_NE ("package & has null initialization", Item, Pack_Id);
2012
2013 -- Null initialization list
2014
2015 elsif Nkind (Item) = N_Null then
2016
2017 -- Catch a case where a null initialization item appears in a list
2018 -- of non-null items.
2019
2020 if Non_Null_Seen then
2021 Error_Msg_NE
2022 ("package & has non-null initialization", Item, Pack_Id);
2023 else
2024 Null_Seen := True;
2025 end if;
2026
2027 -- Initialization item
2028
2029 else
2030 Non_Null_Seen := True;
2031
2032 Analyze (Item);
2033
2034 if Is_Entity_Name (Item) then
2035 Item_Id := Entity (Item);
2036
2037 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2038
2039 -- The state or variable must be declared in the visible
2040 -- declarations of the package.
2041
2042 if not Contains (States_And_Vars, Item_Id) then
2043 Error_Msg_Name_1 := Chars (Pack_Id);
2044 Error_Msg_NE
2045 ("initialization item & must appear in the visible "
2046 & "declarations of package %", Item, Item_Id);
2047
2048 -- Detect a duplicate use of the same initialization item
2049
2050 elsif Contains (Items_Seen, Item_Id) then
2051 Error_Msg_N ("duplicate initialization item", Item);
2052
2053 -- The item is legal, add it to the list of processed states
2054 -- and variables.
2055
2056 else
2057 Add_Item (Item_Id, Items_Seen);
2058 end if;
2059
2060 -- The item references something that is not a state or a
2061 -- variable.
2062
2063 else
2064 Error_Msg_N
2065 ("initialization item must denote variable or state",
2066 Item);
2067 end if;
2068
2069 -- Some form of illegal construct masquerading as a name
2070
2071 else
2072 Error_Msg_N
2073 ("initialization item must denote variable or state", Item);
2074 end if;
2075 end if;
2076 end Analyze_Initialization_Item;
2077
2078 ---------------------------------------------
2079 -- Analyze_Initialization_Item_With_Inputs --
2080 ---------------------------------------------
2081
2082 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2083 Inputs_Seen : Elist_Id := No_Elist;
2084 -- A list of all inputs processed so far. This list is used to detect
2085 -- duplicate uses of an input.
2086
2087 Non_Null_Seen : Boolean := False;
2088 Null_Seen : Boolean := False;
2089 -- Flags used to check the legality of an input list
2090
2091 procedure Analyze_Input_Item (Input : Node_Id);
2092 -- Verify the legality of a single input item
2093
2094 ------------------------
2095 -- Analyze_Input_Item --
2096 ------------------------
2097
2098 procedure Analyze_Input_Item (Input : Node_Id) is
2099 Input_Id : Entity_Id;
2100
2101 begin
2102 -- An initialization item with null inputs is not allowed to have
2103 -- assitional inputs.
2104
2105 if Null_Seen then
2106 Error_Msg_N ("item has null input list", Item);
2107
2108 -- Null input list
2109
2110 elsif Nkind (Input) = N_Null then
2111
2112 -- Catch a case where a null input appears in a list of non-
2113 -- null inpits.
2114
2115 if Non_Null_Seen then
2116 Error_Msg_N ("item has non-null input list", Item);
2117 else
2118 Null_Seen := True;
2119 end if;
2120
2121 -- Input item
2122
2123 else
2124 Non_Null_Seen := True;
2125
2126 Analyze (Input);
2127
2128 if Is_Entity_Name (Input) then
2129 Input_Id := Entity (Input);
2130
2131 if Ekind_In (Input_Id, E_Abstract_State, E_Variable) then
2132
2133 -- The input cannot denote states or variables declared
2134 -- within the visible declarations of the package.
2135
2136 if Contains (States_And_Vars, Input_Id) then
2137 Error_Msg_Name_1 := Chars (Pack_Id);
2138 Error_Msg_NE
2139 ("input item & cannot denote a visible variable or "
2140 & "state of package %", Input, Input_Id);
2141
2142 -- Detect a duplicate use of the same input item
2143
2144 elsif Contains (Inputs_Seen, Input_Id) then
2145 Error_Msg_N ("duplicate input item", Input);
2146
2147 -- The input is legal, add it to the list of processed
2148 -- inputs.
2149
2150 else
2151 Add_Item (Input_Id, Inputs_Seen);
2152 end if;
2153
2154 -- The input references something that is not a state or a
2155 -- variable.
2156
2157 else
2158 Error_Msg_N
2159 ("input item must denote variable or state", Input);
2160 end if;
2161
2162 -- Some form of illegal construct masquerading as a name
2163
2164 else
2165 Error_Msg_N
2166 ("input item must denote variable or state", Input);
2167 end if;
2168 end if;
2169 end Analyze_Input_Item;
2170
2171 -- Local variables
2172
2173 Inputs : constant Node_Id := Expression (Item);
2174 Elmt : Node_Id;
2175 Input : Node_Id;
2176
2177 Name_Seen : Boolean := False;
2178 -- A flag used to detect multiple item names
2179
2180 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2181
2182 begin
2183 -- Inspect the name of an item with inputs
2184
2185 Elmt := First (Choices (Item));
2186 while Present (Elmt) loop
2187 if Name_Seen then
2188 Error_Msg_N ("only one item allowed in initialization", Elmt);
2189
2190 else
2191 Name_Seen := True;
2192 Analyze_Initialization_Item (Elmt);
2193 end if;
2194
2195 Next (Elmt);
2196 end loop;
2197
2198 -- Multiple input items appear as an aggregate
2199
2200 if Nkind (Inputs) = N_Aggregate then
2201 if Present (Expressions (Inputs)) then
2202 Input := First (Expressions (Inputs));
2203 while Present (Input) loop
2204 Analyze_Input_Item (Input);
2205
2206 Next (Input);
2207 end loop;
2208 end if;
2209
2210 if Present (Component_Associations (Inputs)) then
2211 Error_Msg_N
2212 ("inputs must appear in named association form", Inputs);
2213 end if;
2214
2215 -- Single input item
2216
2217 else
2218 Analyze_Input_Item (Inputs);
2219 end if;
2220 end Analyze_Initialization_Item_With_Inputs;
2221
2222 ----------------------------------
2223 -- Collect_States_And_Variables --
2224 ----------------------------------
2225
2226 procedure Collect_States_And_Variables is
2227 Decl : Node_Id;
2228
2229 begin
2230 -- Collect the abstract states defined in the package (if any)
2231
2232 if Present (Abstract_States (Pack_Id)) then
2233 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2234 end if;
2235
2236 -- Collect all variables the appear in the visible declarations of
2237 -- the related package.
2238
2239 if Present (Visible_Declarations (Pack_Spec)) then
2240 Decl := First (Visible_Declarations (Pack_Spec));
2241 while Present (Decl) loop
2242 if Nkind (Decl) = N_Object_Declaration
2243 and then Ekind (Defining_Entity (Decl)) = E_Variable
2244 and then Comes_From_Source (Decl)
2245 then
2246 Add_Item (Defining_Entity (Decl), States_And_Vars);
2247 end if;
2248
2249 Next (Decl);
2250 end loop;
2251 end if;
2252 end Collect_States_And_Variables;
2253
2254 -- Local variables
2255
2256 Inits : constant Node_Id :=
2257 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2258 Init : Node_Id;
2259
2260 -- Start of processing for Analyze_Initializes_In_Decl_Part
2261
2262 begin
2263 Set_Analyzed (N);
2264
2265 -- Initialize the various lists used during analysis
2266
2267 Collect_States_And_Variables;
2268
2269 -- Multiple initialization clauses appear as an aggregate
2270
2271 if Nkind (Inits) = N_Aggregate then
2272 if Present (Expressions (Inits)) then
2273 Init := First (Expressions (Inits));
2274 while Present (Init) loop
2275 Analyze_Initialization_Item (Init);
2276
2277 Next (Init);
2278 end loop;
2279 end if;
2280
2281 if Present (Component_Associations (Inits)) then
2282 Init := First (Component_Associations (Inits));
2283 while Present (Init) loop
2284 Analyze_Initialization_Item_With_Inputs (Init);
2285
2286 Next (Init);
2287 end loop;
2288 end if;
2289
2290 -- Various forms of a single initialization clause. Note that these may
2291 -- include malformed initializations.
2292
2293 else
2294 Analyze_Initialization_Item (Inits);
2295 end if;
2296 end Analyze_Initializes_In_Decl_Part;
2297
2298 --------------------
2299 -- Analyze_Pragma --
2300 --------------------
2301
2302 procedure Analyze_Pragma (N : Node_Id) is
2303 Loc : constant Source_Ptr := Sloc (N);
2304 Prag_Id : Pragma_Id;
2305
2306 Pname : Name_Id;
2307 -- Name of the source pragma, or name of the corresponding aspect for
2308 -- pragmas which originate in a source aspect. In the latter case, the
2309 -- name may be different from the pragma name.
2310
2311 Pragma_Exit : exception;
2312 -- This exception is used to exit pragma processing completely. It is
2313 -- used when an error is detected, and no further processing is
2314 -- required. It is also used if an earlier error has left the tree in
2315 -- a state where the pragma should not be processed.
2316
2317 Arg_Count : Nat;
2318 -- Number of pragma argument associations
2319
2320 Arg1 : Node_Id;
2321 Arg2 : Node_Id;
2322 Arg3 : Node_Id;
2323 Arg4 : Node_Id;
2324 -- First four pragma arguments (pragma argument association nodes, or
2325 -- Empty if the corresponding argument does not exist).
2326
2327 type Name_List is array (Natural range <>) of Name_Id;
2328 type Args_List is array (Natural range <>) of Node_Id;
2329 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2330
2331 procedure Ada_2005_Pragma;
2332 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2333 -- Ada 95 mode, these are implementation defined pragmas, so should be
2334 -- caught by the No_Implementation_Pragmas restriction.
2335
2336 procedure Ada_2012_Pragma;
2337 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2338 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2339 -- should be caught by the No_Implementation_Pragmas restriction.
2340
2341 procedure Analyze_Refined_Pragma
2342 (Spec_Id : out Entity_Id;
2343 Body_Id : out Entity_Id;
2344 Legal : out Boolean);
2345 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2346 -- Refined_Global, Refined_Post and Refined_Pre. Check the placement and
2347 -- related context of the pragma. Spec_Id is the entity of the related
2348 -- subprogram. Body_Id is the entity of the subprogram body. Flag Legal
2349 -- is set when the pragma is properly placed.
2350
2351 procedure Check_Ada_83_Warning;
2352 -- Issues a warning message for the current pragma if operating in Ada
2353 -- 83 mode (used for language pragmas that are not a standard part of
2354 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
2355 -- of 95 pragma.
2356
2357 procedure Check_Arg_Count (Required : Nat);
2358 -- Check argument count for pragma is equal to given parameter. If not,
2359 -- then issue an error message and raise Pragma_Exit.
2360
2361 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2362 -- Arg which can either be a pragma argument association, in which case
2363 -- the check is applied to the expression of the association or an
2364 -- expression directly.
2365
2366 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
2367 -- Check that an argument has the right form for an EXTERNAL_NAME
2368 -- parameter of an extended import/export pragma. The rule is that the
2369 -- name must be an identifier or string literal (in Ada 83 mode) or a
2370 -- static string expression (in Ada 95 mode).
2371
2372 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
2373 -- Check the specified argument Arg to make sure that it is an
2374 -- identifier. If not give error and raise Pragma_Exit.
2375
2376 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
2377 -- Check the specified argument Arg to make sure that it is an integer
2378 -- literal. If not give error and raise Pragma_Exit.
2379
2380 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
2381 -- Check the specified argument Arg to make sure that it has the proper
2382 -- syntactic form for a local name and meets the semantic requirements
2383 -- for a local name. The local name is analyzed as part of the
2384 -- processing for this call. In addition, the local name is required
2385 -- to represent an entity at the library level.
2386
2387 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
2388 -- Check the specified argument Arg to make sure that it has the proper
2389 -- syntactic form for a local name and meets the semantic requirements
2390 -- for a local name. The local name is analyzed as part of the
2391 -- processing for this call.
2392
2393 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
2394 -- Check the specified argument Arg to make sure that it is a valid
2395 -- locking policy name. If not give error and raise Pragma_Exit.
2396
2397 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
2398 -- Check the specified argument Arg to make sure that it is a valid
2399 -- elaboration policy name. If not give error and raise Pragma_Exit.
2400
2401 procedure Check_Arg_Is_One_Of
2402 (Arg : Node_Id;
2403 N1, N2 : Name_Id);
2404 procedure Check_Arg_Is_One_Of
2405 (Arg : Node_Id;
2406 N1, N2, N3 : Name_Id);
2407 procedure Check_Arg_Is_One_Of
2408 (Arg : Node_Id;
2409 N1, N2, N3, N4 : Name_Id);
2410 procedure Check_Arg_Is_One_Of
2411 (Arg : Node_Id;
2412 N1, N2, N3, N4, N5 : Name_Id);
2413 -- Check the specified argument Arg to make sure that it is an
2414 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2415 -- present). If not then give error and raise Pragma_Exit.
2416
2417 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
2418 -- Check the specified argument Arg to make sure that it is a valid
2419 -- queuing policy name. If not give error and raise Pragma_Exit.
2420
2421 procedure Check_Arg_Is_Static_Expression
2422 (Arg : Node_Id;
2423 Typ : Entity_Id := Empty);
2424 -- Check the specified argument Arg to make sure that it is a static
2425 -- expression of the given type (i.e. it will be analyzed and resolved
2426 -- using this type, which can be any valid argument to Resolve, e.g.
2427 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2428 -- Typ is left Empty, then any static expression is allowed.
2429
2430 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
2431 -- Check the specified argument Arg to make sure that it is a valid task
2432 -- dispatching policy name. If not give error and raise Pragma_Exit.
2433
2434 procedure Check_Arg_Order (Names : Name_List);
2435 -- Checks for an instance of two arguments with identifiers for the
2436 -- current pragma which are not in the sequence indicated by Names,
2437 -- and if so, generates a fatal message about bad order of arguments.
2438
2439 procedure Check_At_Least_N_Arguments (N : Nat);
2440 -- Check there are at least N arguments present
2441
2442 procedure Check_At_Most_N_Arguments (N : Nat);
2443 -- Check there are no more than N arguments present
2444
2445 procedure Check_Component
2446 (Comp : Node_Id;
2447 UU_Typ : Entity_Id;
2448 In_Variant_Part : Boolean := False);
2449 -- Examine an Unchecked_Union component for correct use of per-object
2450 -- constrained subtypes, and for restrictions on finalizable components.
2451 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2452 -- should be set when Comp comes from a record variant.
2453
2454 procedure Check_Declaration_Order (States : Node_Id; Inits : Node_Id);
2455 -- Subsidiary routine to the analysis of pragmas Abstract_State and
2456 -- Initializes. Determine whether pragma Abstract_State denoted by
2457 -- States is defined earlier than pragma Initializes denoted by Inits.
2458
2459 procedure Check_Duplicate_Pragma (E : Entity_Id);
2460 -- Check if a rep item of the same name as the current pragma is already
2461 -- chained as a rep pragma to the given entity. If so give a message
2462 -- about the duplicate, and then raise Pragma_Exit so does not return.
2463
2464 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2465 -- Nam is an N_String_Literal node containing the external name set by
2466 -- an Import or Export pragma (or extended Import or Export pragma).
2467 -- This procedure checks for possible duplications if this is the export
2468 -- case, and if found, issues an appropriate error message.
2469
2470 procedure Check_Expr_Is_Static_Expression
2471 (Expr : Node_Id;
2472 Typ : Entity_Id := Empty);
2473 -- Check the specified expression Expr to make sure that it is a static
2474 -- expression of the given type (i.e. it will be analyzed and resolved
2475 -- using this type, which can be any valid argument to Resolve, e.g.
2476 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2477 -- Typ is left Empty, then any static expression is allowed.
2478
2479 procedure Check_First_Subtype (Arg : Node_Id);
2480 -- Checks that Arg, whose expression is an entity name, references a
2481 -- first subtype.
2482
2483 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2484 -- Checks that the given argument has an identifier, and if so, requires
2485 -- it to match the given identifier name. If there is no identifier, or
2486 -- a non-matching identifier, then an error message is given and
2487 -- Pragma_Exit is raised.
2488
2489 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2490 -- Checks that the given argument has an identifier, and if so, requires
2491 -- it to match one of the given identifier names. If there is no
2492 -- identifier, or a non-matching identifier, then an error message is
2493 -- given and Pragma_Exit is raised.
2494
2495 procedure Check_In_Main_Program;
2496 -- Common checks for pragmas that appear within a main program
2497 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2498
2499 procedure Check_Interrupt_Or_Attach_Handler;
2500 -- Common processing for first argument of pragma Interrupt_Handler or
2501 -- pragma Attach_Handler.
2502
2503 procedure Check_Loop_Pragma_Placement;
2504 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
2505 -- appear immediately within a construct restricted to loops.
2506
2507 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2508 -- Check that pragma appears in a declarative part, or in a package
2509 -- specification, i.e. that it does not occur in a statement sequence
2510 -- in a body.
2511
2512 procedure Check_No_Identifier (Arg : Node_Id);
2513 -- Checks that the given argument does not have an identifier. If
2514 -- an identifier is present, then an error message is issued, and
2515 -- Pragma_Exit is raised.
2516
2517 procedure Check_No_Identifiers;
2518 -- Checks that none of the arguments to the pragma has an identifier.
2519 -- If any argument has an identifier, then an error message is issued,
2520 -- and Pragma_Exit is raised.
2521
2522 procedure Check_No_Link_Name;
2523 -- Checks that no link name is specified
2524
2525 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
2526 -- Checks if the given argument has an identifier, and if so, requires
2527 -- it to match the given identifier name. If there is a non-matching
2528 -- identifier, then an error message is given and Pragma_Exit is raised.
2529
2530 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
2531 -- Checks if the given argument has an identifier, and if so, requires
2532 -- it to match the given identifier name. If there is a non-matching
2533 -- identifier, then an error message is given and Pragma_Exit is raised.
2534 -- In this version of the procedure, the identifier name is given as
2535 -- a string with lower case letters.
2536
2537 procedure Check_Pre_Post;
2538 -- Called to perform checks for Pre, Pre_Class, Post, Post_Class
2539 -- pragmas. These are processed by transformation to equivalent
2540 -- Precondition and Postcondition pragmas, but Pre and Post need an
2541 -- additional check that they are not used in a subprogram body when
2542 -- there is a separate spec present.
2543
2544 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
2545 -- Called to process a precondition or postcondition pragma. There are
2546 -- three cases:
2547 --
2548 -- The pragma appears after a subprogram spec
2549 --
2550 -- If the corresponding check is not enabled, the pragma is analyzed
2551 -- but otherwise ignored and control returns with In_Body set False.
2552 --
2553 -- If the check is enabled, then the first step is to analyze the
2554 -- pragma, but this is skipped if the subprogram spec appears within
2555 -- a package specification (because this is the case where we delay
2556 -- analysis till the end of the spec). Then (whether or not it was
2557 -- analyzed), the pragma is chained to the subprogram in question
2558 -- (using Pre_Post_Conditions and Next_Pragma) and control returns
2559 -- to the caller with In_Body set False.
2560 --
2561 -- The pragma appears at the start of subprogram body declarations
2562 --
2563 -- In this case an immediate return to the caller is made with
2564 -- In_Body set True, and the pragma is NOT analyzed.
2565 --
2566 -- In all other cases, an error message for bad placement is given
2567
2568 procedure Check_Static_Constraint (Constr : Node_Id);
2569 -- Constr is a constraint from an N_Subtype_Indication node from a
2570 -- component constraint in an Unchecked_Union type. This routine checks
2571 -- that the constraint is static as required by the restrictions for
2572 -- Unchecked_Union.
2573
2574 procedure Check_Test_Case;
2575 -- Called to process a test-case pragma. It starts with checking pragma
2576 -- arguments, and the rest of the treatment is similar to the one for
2577 -- pre- and postcondition in Check_Precondition_Postcondition, except
2578 -- the placement rules for the test-case pragma are stricter. These
2579 -- pragmas may only occur after a subprogram spec declared directly
2580 -- in a package spec unit. In this case, the pragma is chained to the
2581 -- subprogram in question (using Contract_Test_Cases and Next_Pragma)
2582 -- and analysis of the pragma is delayed till the end of the spec. In
2583 -- all other cases, an error message for bad placement is given.
2584
2585 procedure Check_Valid_Configuration_Pragma;
2586 -- Legality checks for placement of a configuration pragma
2587
2588 procedure Check_Valid_Library_Unit_Pragma;
2589 -- Legality checks for library unit pragmas. A special case arises for
2590 -- pragmas in generic instances that come from copies of the original
2591 -- library unit pragmas in the generic templates. In the case of other
2592 -- than library level instantiations these can appear in contexts which
2593 -- would normally be invalid (they only apply to the original template
2594 -- and to library level instantiations), and they are simply ignored,
2595 -- which is implemented by rewriting them as null statements.
2596
2597 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
2598 -- Check an Unchecked_Union variant for lack of nested variants and
2599 -- presence of at least one component. UU_Typ is the related Unchecked_
2600 -- Union type.
2601
2602 procedure Error_Pragma (Msg : String);
2603 pragma No_Return (Error_Pragma);
2604 -- Outputs error message for current pragma. The message contains a %
2605 -- that will be replaced with the pragma name, and the flag is placed
2606 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2607 -- calls Fix_Error (see spec of that procedure for details).
2608
2609 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
2610 pragma No_Return (Error_Pragma_Arg);
2611 -- Outputs error message for current pragma. The message may contain
2612 -- a % that will be replaced with the pragma name. The parameter Arg
2613 -- may either be a pragma argument association, in which case the flag
2614 -- is placed on the expression of this association, or an expression,
2615 -- in which case the flag is placed directly on the expression. The
2616 -- message is placed using Error_Msg_N, so the message may also contain
2617 -- an & insertion character which will reference the given Arg value.
2618 -- After placing the message, Pragma_Exit is raised. Note: this routine
2619 -- calls Fix_Error (see spec of that procedure for details).
2620
2621 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
2622 pragma No_Return (Error_Pragma_Arg);
2623 -- Similar to above form of Error_Pragma_Arg except that two messages
2624 -- are provided, the second is a continuation comment starting with \.
2625
2626 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
2627 pragma No_Return (Error_Pragma_Arg_Ident);
2628 -- Outputs error message for current pragma. The message may contain
2629 -- a % that will be replaced with the pragma name. The parameter Arg
2630 -- must be a pragma argument association with a non-empty identifier
2631 -- (i.e. its Chars field must be set), and the error message is placed
2632 -- on the identifier. The message is placed using Error_Msg_N so
2633 -- the message may also contain an & insertion character which will
2634 -- reference the identifier. After placing the message, Pragma_Exit
2635 -- is raised. Note: this routine calls Fix_Error (see spec of that
2636 -- procedure for details).
2637
2638 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
2639 pragma No_Return (Error_Pragma_Ref);
2640 -- Outputs error message for current pragma. The message may contain
2641 -- a % that will be replaced with the pragma name. The parameter Ref
2642 -- must be an entity whose name can be referenced by & and sloc by #.
2643 -- After placing the message, Pragma_Exit is raised. Note: this routine
2644 -- calls Fix_Error (see spec of that procedure for details).
2645
2646 function Find_Lib_Unit_Name return Entity_Id;
2647 -- Used for a library unit pragma to find the entity to which the
2648 -- library unit pragma applies, returns the entity found.
2649
2650 procedure Find_Program_Unit_Name (Id : Node_Id);
2651 -- If the pragma is a compilation unit pragma, the id must denote the
2652 -- compilation unit in the same compilation, and the pragma must appear
2653 -- in the list of preceding or trailing pragmas. If it is a program
2654 -- unit pragma that is not a compilation unit pragma, then the
2655 -- identifier must be visible.
2656
2657 function Find_Unique_Parameterless_Procedure
2658 (Name : Entity_Id;
2659 Arg : Node_Id) return Entity_Id;
2660 -- Used for a procedure pragma to find the unique parameterless
2661 -- procedure identified by Name, returns it if it exists, otherwise
2662 -- errors out and uses Arg as the pragma argument for the message.
2663
2664 procedure Fix_Error (Msg : in out String);
2665 -- This is called prior to issuing an error message. Msg is a string
2666 -- that typically contains the substring "pragma". If the pragma comes
2667 -- from an aspect, each such "pragma" substring is replaced with the
2668 -- characters "aspect", and Error_Msg_Name_1 is set to the name of the
2669 -- aspect (which may be different from the pragma name). If the current
2670 -- pragma results from rewriting another pragma, then Error_Msg_Name_1
2671 -- is set to the original pragma name.
2672
2673 procedure Gather_Associations
2674 (Names : Name_List;
2675 Args : out Args_List);
2676 -- This procedure is used to gather the arguments for a pragma that
2677 -- permits arbitrary ordering of parameters using the normal rules
2678 -- for named and positional parameters. The Names argument is a list
2679 -- of Name_Id values that corresponds to the allowed pragma argument
2680 -- association identifiers in order. The result returned in Args is
2681 -- a list of corresponding expressions that are the pragma arguments.
2682 -- Note that this is a list of expressions, not of pragma argument
2683 -- associations (Gather_Associations has completely checked all the
2684 -- optional identifiers when it returns). An entry in Args is Empty
2685 -- on return if the corresponding argument is not present.
2686
2687 procedure GNAT_Pragma;
2688 -- Called for all GNAT defined pragmas to check the relevant restriction
2689 -- (No_Implementation_Pragmas).
2690
2691 procedure S14_Pragma;
2692 -- Called for all pragmas defined for formal verification to check that
2693 -- the S14_Extensions flag is set.
2694 -- This name needs fixing ??? There is no such thing as an
2695 -- "S14_Extensions" flag ???
2696
2697 function Is_Before_First_Decl
2698 (Pragma_Node : Node_Id;
2699 Decls : List_Id) return Boolean;
2700 -- Return True if Pragma_Node is before the first declarative item in
2701 -- Decls where Decls is the list of declarative items.
2702
2703 function Is_Configuration_Pragma return Boolean;
2704 -- Determines if the placement of the current pragma is appropriate
2705 -- for a configuration pragma.
2706
2707 function Is_In_Context_Clause return Boolean;
2708 -- Returns True if pragma appears within the context clause of a unit,
2709 -- and False for any other placement (does not generate any messages).
2710
2711 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
2712 -- Analyzes the argument, and determines if it is a static string
2713 -- expression, returns True if so, False if non-static or not String.
2714
2715 procedure Pragma_Misplaced;
2716 pragma No_Return (Pragma_Misplaced);
2717 -- Issue fatal error message for misplaced pragma
2718
2719 procedure Process_Atomic_Shared_Volatile;
2720 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
2721 -- Shared is an obsolete Ada 83 pragma, treated as being identical
2722 -- in effect to pragma Atomic.
2723
2724 procedure Process_Compile_Time_Warning_Or_Error;
2725 -- Common processing for Compile_Time_Error and Compile_Time_Warning
2726
2727 procedure Process_Convention
2728 (C : out Convention_Id;
2729 Ent : out Entity_Id);
2730 -- Common processing for Convention, Interface, Import and Export.
2731 -- Checks first two arguments of pragma, and sets the appropriate
2732 -- convention value in the specified entity or entities. On return
2733 -- C is the convention, Ent is the referenced entity.
2734
2735 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
2736 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
2737 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
2738
2739 procedure Process_Extended_Import_Export_Exception_Pragma
2740 (Arg_Internal : Node_Id;
2741 Arg_External : Node_Id;
2742 Arg_Form : Node_Id;
2743 Arg_Code : Node_Id);
2744 -- Common processing for the pragmas Import/Export_Exception. The three
2745 -- arguments correspond to the three named parameters of the pragma. An
2746 -- argument is empty if the corresponding parameter is not present in
2747 -- the pragma.
2748
2749 procedure Process_Extended_Import_Export_Object_Pragma
2750 (Arg_Internal : Node_Id;
2751 Arg_External : Node_Id;
2752 Arg_Size : Node_Id);
2753 -- Common processing for the pragmas Import/Export_Object. The three
2754 -- arguments correspond to the three named parameters of the pragmas. An
2755 -- argument is empty if the corresponding parameter is not present in
2756 -- the pragma.
2757
2758 procedure Process_Extended_Import_Export_Internal_Arg
2759 (Arg_Internal : Node_Id := Empty);
2760 -- Common processing for all extended Import and Export pragmas. The
2761 -- argument is the pragma parameter for the Internal argument. If
2762 -- Arg_Internal is empty or inappropriate, an error message is posted.
2763 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
2764 -- set to identify the referenced entity.
2765
2766 procedure Process_Extended_Import_Export_Subprogram_Pragma
2767 (Arg_Internal : Node_Id;
2768 Arg_External : Node_Id;
2769 Arg_Parameter_Types : Node_Id;
2770 Arg_Result_Type : Node_Id := Empty;
2771 Arg_Mechanism : Node_Id;
2772 Arg_Result_Mechanism : Node_Id := Empty;
2773 Arg_First_Optional_Parameter : Node_Id := Empty);
2774 -- Common processing for all extended Import and Export pragmas applying
2775 -- to subprograms. The caller omits any arguments that do not apply to
2776 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
2777 -- only in the Import_Function and Export_Function cases). The argument
2778 -- names correspond to the allowed pragma association identifiers.
2779
2780 procedure Process_Generic_List;
2781 -- Common processing for Share_Generic and Inline_Generic
2782
2783 procedure Process_Import_Or_Interface;
2784 -- Common processing for Import of Interface
2785
2786 procedure Process_Import_Predefined_Type;
2787 -- Processing for completing a type with pragma Import. This is used
2788 -- to declare types that match predefined C types, especially for cases
2789 -- without corresponding Ada predefined type.
2790
2791 type Inline_Status is (Suppressed, Disabled, Enabled);
2792 -- Inline status of a subprogram, indicated as follows:
2793 -- Suppressed: inlining is suppressed for the subprogram
2794 -- Disabled: no inlining is requested for the subprogram
2795 -- Enabled: inlining is requested/required for the subprogram
2796
2797 procedure Process_Inline (Status : Inline_Status);
2798 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
2799 -- indicates the inline status specified by the pragma.
2800
2801 procedure Process_Interface_Name
2802 (Subprogram_Def : Entity_Id;
2803 Ext_Arg : Node_Id;
2804 Link_Arg : Node_Id);
2805 -- Given the last two arguments of pragma Import, pragma Export, or
2806 -- pragma Interface_Name, performs validity checks and sets the
2807 -- Interface_Name field of the given subprogram entity to the
2808 -- appropriate external or link name, depending on the arguments given.
2809 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
2810 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
2811 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
2812 -- nor Link_Arg is present, the interface name is set to the default
2813 -- from the subprogram name.
2814
2815 procedure Process_Interrupt_Or_Attach_Handler;
2816 -- Common processing for Interrupt and Attach_Handler pragmas
2817
2818 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
2819 -- Common processing for Restrictions and Restriction_Warnings pragmas.
2820 -- Warn is True for Restriction_Warnings, or for Restrictions if the
2821 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
2822 -- is not set in the Restrictions case.
2823
2824 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
2825 -- Common processing for Suppress and Unsuppress. The boolean parameter
2826 -- Suppress_Case is True for the Suppress case, and False for the
2827 -- Unsuppress case.
2828
2829 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
2830 -- This procedure sets the Is_Exported flag for the given entity,
2831 -- checking that the entity was not previously imported. Arg is
2832 -- the argument that specified the entity. A check is also made
2833 -- for exporting inappropriate entities.
2834
2835 procedure Set_Extended_Import_Export_External_Name
2836 (Internal_Ent : Entity_Id;
2837 Arg_External : Node_Id);
2838 -- Common processing for all extended import export pragmas. The first
2839 -- argument, Internal_Ent, is the internal entity, which has already
2840 -- been checked for validity by the caller. Arg_External is from the
2841 -- Import or Export pragma, and may be null if no External parameter
2842 -- was present. If Arg_External is present and is a non-null string
2843 -- (a null string is treated as the default), then the Interface_Name
2844 -- field of Internal_Ent is set appropriately.
2845
2846 procedure Set_Imported (E : Entity_Id);
2847 -- This procedure sets the Is_Imported flag for the given entity,
2848 -- checking that it is not previously exported or imported.
2849
2850 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
2851 -- Mech is a parameter passing mechanism (see Import_Function syntax
2852 -- for MECHANISM_NAME). This routine checks that the mechanism argument
2853 -- has the right form, and if not issues an error message. If the
2854 -- argument has the right form then the Mechanism field of Ent is
2855 -- set appropriately.
2856
2857 procedure Set_Rational_Profile;
2858 -- Activate the set of configuration pragmas and permissions that make
2859 -- up the Rational profile.
2860
2861 procedure Set_Ravenscar_Profile (N : Node_Id);
2862 -- Activate the set of configuration pragmas and restrictions that make
2863 -- up the Ravenscar Profile. N is the corresponding pragma node, which
2864 -- is used for error messages on any constructs that violate the
2865 -- profile.
2866
2867 ---------------------
2868 -- Ada_2005_Pragma --
2869 ---------------------
2870
2871 procedure Ada_2005_Pragma is
2872 begin
2873 if Ada_Version <= Ada_95 then
2874 Check_Restriction (No_Implementation_Pragmas, N);
2875 end if;
2876 end Ada_2005_Pragma;
2877
2878 ---------------------
2879 -- Ada_2012_Pragma --
2880 ---------------------
2881
2882 procedure Ada_2012_Pragma is
2883 begin
2884 if Ada_Version <= Ada_2005 then
2885 Check_Restriction (No_Implementation_Pragmas, N);
2886 end if;
2887 end Ada_2012_Pragma;
2888
2889 ----------------------------
2890 -- Analyze_Refined_Pragma --
2891 ----------------------------
2892
2893 procedure Analyze_Refined_Pragma
2894 (Spec_Id : out Entity_Id;
2895 Body_Id : out Entity_Id;
2896 Legal : out Boolean)
2897 is
2898 Body_Decl : Node_Id;
2899 Pack_Spec : Node_Id;
2900 Spec_Decl : Node_Id;
2901
2902 begin
2903 -- Assume that the pragma is illegal
2904
2905 Spec_Id := Empty;
2906 Body_Id := Empty;
2907 Legal := False;
2908
2909 GNAT_Pragma;
2910 Check_Arg_Count (1);
2911 Check_No_Identifiers;
2912
2913 -- Verify the placement of the pragma and check for duplicates. The
2914 -- pragma must apply to a subprogram body [stub].
2915
2916 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
2917
2918 if not Nkind_In (Body_Decl, N_Subprogram_Body,
2919 N_Subprogram_Body_Stub)
2920 then
2921 Pragma_Misplaced;
2922 return;
2923 end if;
2924
2925 Body_Id := Defining_Entity (Body_Decl);
2926
2927 -- The body [stub] must not act as a spec, in other words it has to
2928 -- be paired with a corresponding spec.
2929
2930 if Nkind (Body_Decl) = N_Subprogram_Body then
2931 Spec_Id := Corresponding_Spec (Body_Decl);
2932 else
2933 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
2934 end if;
2935
2936 if No (Spec_Id) then
2937 Error_Pragma ("pragma % cannot apply to a stand alone body");
2938 return;
2939 end if;
2940
2941 -- The pragma may only apply to the body [stub] of a subprogram
2942 -- declared in the visible part of a package. Retrieve the context of
2943 -- the subprogram declaration.
2944
2945 Spec_Decl := Parent (Parent (Spec_Id));
2946
2947 pragma Assert
2948 (Nkind_In (Spec_Decl, N_Abstract_Subprogram_Declaration,
2949 N_Generic_Subprogram_Declaration,
2950 N_Subprogram_Declaration));
2951
2952 Pack_Spec := Parent (Spec_Decl);
2953
2954 if Nkind (Pack_Spec) /= N_Package_Specification
2955 or else List_Containing (Spec_Decl) /=
2956 Visible_Declarations (Pack_Spec)
2957 then
2958 Error_Pragma
2959 ("pragma % must apply to the body of a visible subprogram");
2960 return;
2961 end if;
2962
2963 -- If we get here, then the pragma is legal
2964
2965 Legal := True;
2966 end Analyze_Refined_Pragma;
2967
2968 --------------------------
2969 -- Check_Ada_83_Warning --
2970 --------------------------
2971
2972 procedure Check_Ada_83_Warning is
2973 begin
2974 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2975 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
2976 end if;
2977 end Check_Ada_83_Warning;
2978
2979 ---------------------
2980 -- Check_Arg_Count --
2981 ---------------------
2982
2983 procedure Check_Arg_Count (Required : Nat) is
2984 begin
2985 if Arg_Count /= Required then
2986 Error_Pragma ("wrong number of arguments for pragma%");
2987 end if;
2988 end Check_Arg_Count;
2989
2990 --------------------------------
2991 -- Check_Arg_Is_External_Name --
2992 --------------------------------
2993
2994 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
2995 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2996
2997 begin
2998 if Nkind (Argx) = N_Identifier then
2999 return;
3000
3001 else
3002 Analyze_And_Resolve (Argx, Standard_String);
3003
3004 if Is_OK_Static_Expression (Argx) then
3005 return;
3006
3007 elsif Etype (Argx) = Any_Type then
3008 raise Pragma_Exit;
3009
3010 -- An interesting special case, if we have a string literal and
3011 -- we are in Ada 83 mode, then we allow it even though it will
3012 -- not be flagged as static. This allows expected Ada 83 mode
3013 -- use of external names which are string literals, even though
3014 -- technically these are not static in Ada 83.
3015
3016 elsif Ada_Version = Ada_83
3017 and then Nkind (Argx) = N_String_Literal
3018 then
3019 return;
3020
3021 -- Static expression that raises Constraint_Error. This has
3022 -- already been flagged, so just exit from pragma processing.
3023
3024 elsif Is_Static_Expression (Argx) then
3025 raise Pragma_Exit;
3026
3027 -- Here we have a real error (non-static expression)
3028
3029 else
3030 Error_Msg_Name_1 := Pname;
3031
3032 declare
3033 Msg : String :=
3034 "argument for pragma% must be a identifier or "
3035 & "static string expression!";
3036 begin
3037 Fix_Error (Msg);
3038 Flag_Non_Static_Expr (Msg, Argx);
3039 raise Pragma_Exit;
3040 end;
3041 end if;
3042 end if;
3043 end Check_Arg_Is_External_Name;
3044
3045 -----------------------------
3046 -- Check_Arg_Is_Identifier --
3047 -----------------------------
3048
3049 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3050 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3051 begin
3052 if Nkind (Argx) /= N_Identifier then
3053 Error_Pragma_Arg
3054 ("argument for pragma% must be identifier", Argx);
3055 end if;
3056 end Check_Arg_Is_Identifier;
3057
3058 ----------------------------------
3059 -- Check_Arg_Is_Integer_Literal --
3060 ----------------------------------
3061
3062 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3063 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3064 begin
3065 if Nkind (Argx) /= N_Integer_Literal then
3066 Error_Pragma_Arg
3067 ("argument for pragma% must be integer literal", Argx);
3068 end if;
3069 end Check_Arg_Is_Integer_Literal;
3070
3071 -------------------------------------------
3072 -- Check_Arg_Is_Library_Level_Local_Name --
3073 -------------------------------------------
3074
3075 -- LOCAL_NAME ::=
3076 -- DIRECT_NAME
3077 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3078 -- | library_unit_NAME
3079
3080 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3081 begin
3082 Check_Arg_Is_Local_Name (Arg);
3083
3084 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3085 and then Comes_From_Source (N)
3086 then
3087 Error_Pragma_Arg
3088 ("argument for pragma% must be library level entity", Arg);
3089 end if;
3090 end Check_Arg_Is_Library_Level_Local_Name;
3091
3092 -----------------------------
3093 -- Check_Arg_Is_Local_Name --
3094 -----------------------------
3095
3096 -- LOCAL_NAME ::=
3097 -- DIRECT_NAME
3098 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3099 -- | library_unit_NAME
3100
3101 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3102 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3103
3104 begin
3105 Analyze (Argx);
3106
3107 if Nkind (Argx) not in N_Direct_Name
3108 and then (Nkind (Argx) /= N_Attribute_Reference
3109 or else Present (Expressions (Argx))
3110 or else Nkind (Prefix (Argx)) /= N_Identifier)
3111 and then (not Is_Entity_Name (Argx)
3112 or else not Is_Compilation_Unit (Entity (Argx)))
3113 then
3114 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3115 end if;
3116
3117 -- No further check required if not an entity name
3118
3119 if not Is_Entity_Name (Argx) then
3120 null;
3121
3122 else
3123 declare
3124 OK : Boolean;
3125 Ent : constant Entity_Id := Entity (Argx);
3126 Scop : constant Entity_Id := Scope (Ent);
3127
3128 begin
3129 -- Case of a pragma applied to a compilation unit: pragma must
3130 -- occur immediately after the program unit in the compilation.
3131
3132 if Is_Compilation_Unit (Ent) then
3133 declare
3134 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3135
3136 begin
3137 -- Case of pragma placed immediately after spec
3138
3139 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3140 OK := True;
3141
3142 -- Case of pragma placed immediately after body
3143
3144 elsif Nkind (Decl) = N_Subprogram_Declaration
3145 and then Present (Corresponding_Body (Decl))
3146 then
3147 OK := Parent (N) =
3148 Aux_Decls_Node
3149 (Parent (Unit_Declaration_Node
3150 (Corresponding_Body (Decl))));
3151
3152 -- All other cases are illegal
3153
3154 else
3155 OK := False;
3156 end if;
3157 end;
3158
3159 -- Special restricted placement rule from 10.2.1(11.8/2)
3160
3161 elsif Is_Generic_Formal (Ent)
3162 and then Prag_Id = Pragma_Preelaborable_Initialization
3163 then
3164 OK := List_Containing (N) =
3165 Generic_Formal_Declarations
3166 (Unit_Declaration_Node (Scop));
3167
3168 -- Default case, just check that the pragma occurs in the scope
3169 -- of the entity denoted by the name.
3170
3171 else
3172 OK := Current_Scope = Scop;
3173 end if;
3174
3175 if not OK then
3176 Error_Pragma_Arg
3177 ("pragma% argument must be in same declarative part", Arg);
3178 end if;
3179 end;
3180 end if;
3181 end Check_Arg_Is_Local_Name;
3182
3183 ---------------------------------
3184 -- Check_Arg_Is_Locking_Policy --
3185 ---------------------------------
3186
3187 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3188 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3189
3190 begin
3191 Check_Arg_Is_Identifier (Argx);
3192
3193 if not Is_Locking_Policy_Name (Chars (Argx)) then
3194 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3195 end if;
3196 end Check_Arg_Is_Locking_Policy;
3197
3198 -----------------------------------------------
3199 -- Check_Arg_Is_Partition_Elaboration_Policy --
3200 -----------------------------------------------
3201
3202 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3203 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3204
3205 begin
3206 Check_Arg_Is_Identifier (Argx);
3207
3208 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3209 Error_Pragma_Arg
3210 ("& is not a valid partition elaboration policy name", Argx);
3211 end if;
3212 end Check_Arg_Is_Partition_Elaboration_Policy;
3213
3214 -------------------------
3215 -- Check_Arg_Is_One_Of --
3216 -------------------------
3217
3218 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3219 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3220
3221 begin
3222 Check_Arg_Is_Identifier (Argx);
3223
3224 if not Nam_In (Chars (Argx), N1, N2) then
3225 Error_Msg_Name_2 := N1;
3226 Error_Msg_Name_3 := N2;
3227 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
3228 end if;
3229 end Check_Arg_Is_One_Of;
3230
3231 procedure Check_Arg_Is_One_Of
3232 (Arg : Node_Id;
3233 N1, N2, N3 : Name_Id)
3234 is
3235 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3236
3237 begin
3238 Check_Arg_Is_Identifier (Argx);
3239
3240 if not Nam_In (Chars (Argx), N1, N2, N3) then
3241 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3242 end if;
3243 end Check_Arg_Is_One_Of;
3244
3245 procedure Check_Arg_Is_One_Of
3246 (Arg : Node_Id;
3247 N1, N2, N3, N4 : Name_Id)
3248 is
3249 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3250
3251 begin
3252 Check_Arg_Is_Identifier (Argx);
3253
3254 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3255 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3256 end if;
3257 end Check_Arg_Is_One_Of;
3258
3259 procedure Check_Arg_Is_One_Of
3260 (Arg : Node_Id;
3261 N1, N2, N3, N4, N5 : Name_Id)
3262 is
3263 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3264
3265 begin
3266 Check_Arg_Is_Identifier (Argx);
3267
3268 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
3269 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3270 end if;
3271 end Check_Arg_Is_One_Of;
3272
3273 ---------------------------------
3274 -- Check_Arg_Is_Queuing_Policy --
3275 ---------------------------------
3276
3277 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
3278 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3279
3280 begin
3281 Check_Arg_Is_Identifier (Argx);
3282
3283 if not Is_Queuing_Policy_Name (Chars (Argx)) then
3284 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
3285 end if;
3286 end Check_Arg_Is_Queuing_Policy;
3287
3288 ------------------------------------
3289 -- Check_Arg_Is_Static_Expression --
3290 ------------------------------------
3291
3292 procedure Check_Arg_Is_Static_Expression
3293 (Arg : Node_Id;
3294 Typ : Entity_Id := Empty)
3295 is
3296 begin
3297 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
3298 end Check_Arg_Is_Static_Expression;
3299
3300 ------------------------------------------
3301 -- Check_Arg_Is_Task_Dispatching_Policy --
3302 ------------------------------------------
3303
3304 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
3305 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3306
3307 begin
3308 Check_Arg_Is_Identifier (Argx);
3309
3310 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
3311 Error_Pragma_Arg
3312 ("& is not a valid task dispatching policy name", Argx);
3313 end if;
3314 end Check_Arg_Is_Task_Dispatching_Policy;
3315
3316 ---------------------
3317 -- Check_Arg_Order --
3318 ---------------------
3319
3320 procedure Check_Arg_Order (Names : Name_List) is
3321 Arg : Node_Id;
3322
3323 Highest_So_Far : Natural := 0;
3324 -- Highest index in Names seen do far
3325
3326 begin
3327 Arg := Arg1;
3328 for J in 1 .. Arg_Count loop
3329 if Chars (Arg) /= No_Name then
3330 for K in Names'Range loop
3331 if Chars (Arg) = Names (K) then
3332 if K < Highest_So_Far then
3333 Error_Msg_Name_1 := Pname;
3334 Error_Msg_N
3335 ("parameters out of order for pragma%", Arg);
3336 Error_Msg_Name_1 := Names (K);
3337 Error_Msg_Name_2 := Names (Highest_So_Far);
3338 Error_Msg_N ("\% must appear before %", Arg);
3339 raise Pragma_Exit;
3340
3341 else
3342 Highest_So_Far := K;
3343 end if;
3344 end if;
3345 end loop;
3346 end if;
3347
3348 Arg := Next (Arg);
3349 end loop;
3350 end Check_Arg_Order;
3351
3352 --------------------------------
3353 -- Check_At_Least_N_Arguments --
3354 --------------------------------
3355
3356 procedure Check_At_Least_N_Arguments (N : Nat) is
3357 begin
3358 if Arg_Count < N then
3359 Error_Pragma ("too few arguments for pragma%");
3360 end if;
3361 end Check_At_Least_N_Arguments;
3362
3363 -------------------------------
3364 -- Check_At_Most_N_Arguments --
3365 -------------------------------
3366
3367 procedure Check_At_Most_N_Arguments (N : Nat) is
3368 Arg : Node_Id;
3369 begin
3370 if Arg_Count > N then
3371 Arg := Arg1;
3372 for J in 1 .. N loop
3373 Next (Arg);
3374 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
3375 end loop;
3376 end if;
3377 end Check_At_Most_N_Arguments;
3378
3379 ---------------------
3380 -- Check_Component --
3381 ---------------------
3382
3383 procedure Check_Component
3384 (Comp : Node_Id;
3385 UU_Typ : Entity_Id;
3386 In_Variant_Part : Boolean := False)
3387 is
3388 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
3389 Sindic : constant Node_Id :=
3390 Subtype_Indication (Component_Definition (Comp));
3391 Typ : constant Entity_Id := Etype (Comp_Id);
3392
3393 begin
3394 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
3395 -- object constraint, then the component type shall be an Unchecked_
3396 -- Union.
3397
3398 if Nkind (Sindic) = N_Subtype_Indication
3399 and then Has_Per_Object_Constraint (Comp_Id)
3400 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
3401 then
3402 Error_Msg_N
3403 ("component subtype subject to per-object constraint "
3404 & "must be an Unchecked_Union", Comp);
3405
3406 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
3407 -- the body of a generic unit, or within the body of any of its
3408 -- descendant library units, no part of the type of a component
3409 -- declared in a variant_part of the unchecked union type shall be of
3410 -- a formal private type or formal private extension declared within
3411 -- the formal part of the generic unit.
3412
3413 elsif Ada_Version >= Ada_2012
3414 and then In_Generic_Body (UU_Typ)
3415 and then In_Variant_Part
3416 and then Is_Private_Type (Typ)
3417 and then Is_Generic_Type (Typ)
3418 then
3419 Error_Msg_N
3420 ("component of unchecked union cannot be of generic type", Comp);
3421
3422 elsif Needs_Finalization (Typ) then
3423 Error_Msg_N
3424 ("component of unchecked union cannot be controlled", Comp);
3425
3426 elsif Has_Task (Typ) then
3427 Error_Msg_N
3428 ("component of unchecked union cannot have tasks", Comp);
3429 end if;
3430 end Check_Component;
3431
3432 -----------------------------
3433 -- Check_Declaration_Order --
3434 -----------------------------
3435
3436 procedure Check_Declaration_Order (States : Node_Id; Inits : Node_Id) is
3437 procedure Check_Aspect_Specification_Order;
3438 -- Inspect the aspect specifications of the context to determine the
3439 -- proper order.
3440
3441 --------------------------------------
3442 -- Check_Aspect_Specification_Order --
3443 --------------------------------------
3444
3445 procedure Check_Aspect_Specification_Order is
3446 Asp_I : constant Node_Id := Corresponding_Aspect (Inits);
3447 Asp_S : constant Node_Id := Corresponding_Aspect (States);
3448 Asp : Node_Id;
3449
3450 States_Seen : Boolean := False;
3451
3452 begin
3453 -- Both aspects must be part of the same aspect specification list
3454
3455 pragma Assert (List_Containing (Asp_I) = List_Containing (Asp_S));
3456
3457 Asp := First (List_Containing (Asp_I));
3458 while Present (Asp) loop
3459 if Get_Aspect_Id (Asp) = Aspect_Abstract_State then
3460 States_Seen := True;
3461
3462 elsif Get_Aspect_Id (Asp) = Aspect_Initializes then
3463 if not States_Seen then
3464 Error_Msg_N
3465 ("aspect % must come before aspect %", States);
3466 end if;
3467
3468 exit;
3469 end if;
3470
3471 Next (Asp);
3472 end loop;
3473 end Check_Aspect_Specification_Order;
3474
3475 -- Local variables
3476
3477 Stmt : Node_Id;
3478
3479 -- Start of processing for Check_Declaration_Order
3480
3481 begin
3482 -- Cannot check the order if one of the pragmas is missing
3483
3484 if No (States) or else No (Inits) then
3485 return;
3486 end if;
3487
3488 -- Set up the error names in case the order is incorrect
3489
3490 Error_Msg_Name_1 := Name_Abstract_State;
3491 Error_Msg_Name_2 := Name_Initializes;
3492
3493 if From_Aspect_Specification (States) then
3494
3495 -- Both pragmas are actually aspects, check their declaration
3496 -- order in the associated aspect specification list. Otherwise
3497 -- States is an aspect and Inits a source pragma.
3498
3499 if From_Aspect_Specification (Inits) then
3500 Check_Aspect_Specification_Order;
3501 end if;
3502
3503 -- Abstract_States is a source pragma
3504
3505 else
3506 if From_Aspect_Specification (Inits) then
3507 Error_Msg_N ("pragma % cannot come after aspect %", States);
3508
3509 -- Both pragmas are source constructs. Try to reach States from
3510 -- Inits by traversing the declarations backwards.
3511
3512 else
3513 Stmt := Prev (Inits);
3514 while Present (Stmt) loop
3515
3516 -- The order is ok, Abstract_States is first followed by
3517 -- Initializes.
3518
3519 if Nkind (Stmt) = N_Pragma
3520 and then Pragma_Name (Stmt) = Name_Abstract_State
3521 then
3522 return;
3523 end if;
3524
3525 Prev (Stmt);
3526 end loop;
3527
3528 -- If we get here, then the pragmas are out of order
3529
3530 Error_Msg_N ("pragma % cannot come after pragma %", States);
3531 end if;
3532 end if;
3533 end Check_Declaration_Order;
3534
3535 ----------------------------
3536 -- Check_Duplicate_Pragma --
3537 ----------------------------
3538
3539 procedure Check_Duplicate_Pragma (E : Entity_Id) is
3540 Id : Entity_Id := E;
3541 P : Node_Id;
3542
3543 begin
3544 -- Nothing to do if this pragma comes from an aspect specification,
3545 -- since we could not be duplicating a pragma, and we dealt with the
3546 -- case of duplicated aspects in Analyze_Aspect_Specifications.
3547
3548 if From_Aspect_Specification (N) then
3549 return;
3550 end if;
3551
3552 -- Otherwise current pragma may duplicate previous pragma or a
3553 -- previously given aspect specification or attribute definition
3554 -- clause for the same pragma.
3555
3556 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
3557
3558 if Present (P) then
3559 Error_Msg_Name_1 := Pragma_Name (N);
3560 Error_Msg_Sloc := Sloc (P);
3561
3562 -- For a single protected or a single task object, the error is
3563 -- issued on the original entity.
3564
3565 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
3566 Id := Defining_Identifier (Original_Node (Parent (Id)));
3567 end if;
3568
3569 if Nkind (P) = N_Aspect_Specification
3570 or else From_Aspect_Specification (P)
3571 then
3572 Error_Msg_NE ("aspect% for & previously given#", N, Id);
3573 else
3574 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
3575 end if;
3576
3577 raise Pragma_Exit;
3578 end if;
3579 end Check_Duplicate_Pragma;
3580
3581 ----------------------------------
3582 -- Check_Duplicated_Export_Name --
3583 ----------------------------------
3584
3585 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
3586 String_Val : constant String_Id := Strval (Nam);
3587
3588 begin
3589 -- We are only interested in the export case, and in the case of
3590 -- generics, it is the instance, not the template, that is the
3591 -- problem (the template will generate a warning in any case).
3592
3593 if not Inside_A_Generic
3594 and then (Prag_Id = Pragma_Export
3595 or else
3596 Prag_Id = Pragma_Export_Procedure
3597 or else
3598 Prag_Id = Pragma_Export_Valued_Procedure
3599 or else
3600 Prag_Id = Pragma_Export_Function)
3601 then
3602 for J in Externals.First .. Externals.Last loop
3603 if String_Equal (String_Val, Strval (Externals.Table (J))) then
3604 Error_Msg_Sloc := Sloc (Externals.Table (J));
3605 Error_Msg_N ("external name duplicates name given#", Nam);
3606 exit;
3607 end if;
3608 end loop;
3609
3610 Externals.Append (Nam);
3611 end if;
3612 end Check_Duplicated_Export_Name;
3613
3614 -------------------------------------
3615 -- Check_Expr_Is_Static_Expression --
3616 -------------------------------------
3617
3618 procedure Check_Expr_Is_Static_Expression
3619 (Expr : Node_Id;
3620 Typ : Entity_Id := Empty)
3621 is
3622 begin
3623 if Present (Typ) then
3624 Analyze_And_Resolve (Expr, Typ);
3625 else
3626 Analyze_And_Resolve (Expr);
3627 end if;
3628
3629 if Is_OK_Static_Expression (Expr) then
3630 return;
3631
3632 elsif Etype (Expr) = Any_Type then
3633 raise Pragma_Exit;
3634
3635 -- An interesting special case, if we have a string literal and we
3636 -- are in Ada 83 mode, then we allow it even though it will not be
3637 -- flagged as static. This allows the use of Ada 95 pragmas like
3638 -- Import in Ada 83 mode. They will of course be flagged with
3639 -- warnings as usual, but will not cause errors.
3640
3641 elsif Ada_Version = Ada_83
3642 and then Nkind (Expr) = N_String_Literal
3643 then
3644 return;
3645
3646 -- Static expression that raises Constraint_Error. This has already
3647 -- been flagged, so just exit from pragma processing.
3648
3649 elsif Is_Static_Expression (Expr) then
3650 raise Pragma_Exit;
3651
3652 -- Finally, we have a real error
3653
3654 else
3655 Error_Msg_Name_1 := Pname;
3656
3657 declare
3658 Msg : String :=
3659 "argument for pragma% must be a static expression!";
3660 begin
3661 Fix_Error (Msg);
3662 Flag_Non_Static_Expr (Msg, Expr);
3663 end;
3664
3665 raise Pragma_Exit;
3666 end if;
3667 end Check_Expr_Is_Static_Expression;
3668
3669 -------------------------
3670 -- Check_First_Subtype --
3671 -------------------------
3672
3673 procedure Check_First_Subtype (Arg : Node_Id) is
3674 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3675 Ent : constant Entity_Id := Entity (Argx);
3676
3677 begin
3678 if Is_First_Subtype (Ent) then
3679 null;
3680
3681 elsif Is_Type (Ent) then
3682 Error_Pragma_Arg
3683 ("pragma% cannot apply to subtype", Argx);
3684
3685 elsif Is_Object (Ent) then
3686 Error_Pragma_Arg
3687 ("pragma% cannot apply to object, requires a type", Argx);
3688
3689 else
3690 Error_Pragma_Arg
3691 ("pragma% cannot apply to&, requires a type", Argx);
3692 end if;
3693 end Check_First_Subtype;
3694
3695 ----------------------
3696 -- Check_Identifier --
3697 ----------------------
3698
3699 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
3700 begin
3701 if Present (Arg)
3702 and then Nkind (Arg) = N_Pragma_Argument_Association
3703 then
3704 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
3705 Error_Msg_Name_1 := Pname;
3706 Error_Msg_Name_2 := Id;
3707 Error_Msg_N ("pragma% argument expects identifier%", Arg);
3708 raise Pragma_Exit;
3709 end if;
3710 end if;
3711 end Check_Identifier;
3712
3713 --------------------------------
3714 -- Check_Identifier_Is_One_Of --
3715 --------------------------------
3716
3717 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3718 begin
3719 if Present (Arg)
3720 and then Nkind (Arg) = N_Pragma_Argument_Association
3721 then
3722 if Chars (Arg) = No_Name then
3723 Error_Msg_Name_1 := Pname;
3724 Error_Msg_N ("pragma% argument expects an identifier", Arg);
3725 raise Pragma_Exit;
3726
3727 elsif Chars (Arg) /= N1
3728 and then Chars (Arg) /= N2
3729 then
3730 Error_Msg_Name_1 := Pname;
3731 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
3732 raise Pragma_Exit;
3733 end if;
3734 end if;
3735 end Check_Identifier_Is_One_Of;
3736
3737 ---------------------------
3738 -- Check_In_Main_Program --
3739 ---------------------------
3740
3741 procedure Check_In_Main_Program is
3742 P : constant Node_Id := Parent (N);
3743
3744 begin
3745 -- Must be at in subprogram body
3746
3747 if Nkind (P) /= N_Subprogram_Body then
3748 Error_Pragma ("% pragma allowed only in subprogram");
3749
3750 -- Otherwise warn if obviously not main program
3751
3752 elsif Present (Parameter_Specifications (Specification (P)))
3753 or else not Is_Compilation_Unit (Defining_Entity (P))
3754 then
3755 Error_Msg_Name_1 := Pname;
3756 Error_Msg_N
3757 ("??pragma% is only effective in main program", N);
3758 end if;
3759 end Check_In_Main_Program;
3760
3761 ---------------------------------------
3762 -- Check_Interrupt_Or_Attach_Handler --
3763 ---------------------------------------
3764
3765 procedure Check_Interrupt_Or_Attach_Handler is
3766 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
3767 Handler_Proc, Proc_Scope : Entity_Id;
3768
3769 begin
3770 Analyze (Arg1_X);
3771
3772 if Prag_Id = Pragma_Interrupt_Handler then
3773 Check_Restriction (No_Dynamic_Attachment, N);
3774 end if;
3775
3776 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
3777 Proc_Scope := Scope (Handler_Proc);
3778
3779 -- On AAMP only, a pragma Interrupt_Handler is supported for
3780 -- nonprotected parameterless procedures.
3781
3782 if not AAMP_On_Target
3783 or else Prag_Id = Pragma_Attach_Handler
3784 then
3785 if Ekind (Proc_Scope) /= E_Protected_Type then
3786 Error_Pragma_Arg
3787 ("argument of pragma% must be protected procedure", Arg1);
3788 end if;
3789
3790 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
3791 Error_Pragma ("pragma% must be in protected definition");
3792 end if;
3793 end if;
3794
3795 if not Is_Library_Level_Entity (Proc_Scope)
3796 or else (AAMP_On_Target
3797 and then not Is_Library_Level_Entity (Handler_Proc))
3798 then
3799 Error_Pragma_Arg
3800 ("argument for pragma% must be library level entity", Arg1);
3801 end if;
3802
3803 -- AI05-0033: A pragma cannot appear within a generic body, because
3804 -- instance can be in a nested scope. The check that protected type
3805 -- is itself a library-level declaration is done elsewhere.
3806
3807 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
3808 -- handle code prior to AI-0033. Analysis tools typically are not
3809 -- interested in this pragma in any case, so no need to worry too
3810 -- much about its placement.
3811
3812 if Inside_A_Generic then
3813 if Ekind (Scope (Current_Scope)) = E_Generic_Package
3814 and then In_Package_Body (Scope (Current_Scope))
3815 and then not Relaxed_RM_Semantics
3816 then
3817 Error_Pragma ("pragma% cannot be used inside a generic");
3818 end if;
3819 end if;
3820 end Check_Interrupt_Or_Attach_Handler;
3821
3822 ---------------------------------
3823 -- Check_Loop_Pragma_Placement --
3824 ---------------------------------
3825
3826 procedure Check_Loop_Pragma_Placement is
3827 procedure Placement_Error (Constr : Node_Id);
3828 pragma No_Return (Placement_Error);
3829 -- Node Constr denotes the last loop restricted construct before we
3830 -- encountered an illegal relation between enclosing constructs. Emit
3831 -- an error depending on what Constr was.
3832
3833 ---------------------
3834 -- Placement_Error --
3835 ---------------------
3836
3837 procedure Placement_Error (Constr : Node_Id) is
3838 begin
3839 if Nkind (Constr) = N_Pragma then
3840 Error_Pragma
3841 ("pragma % must appear immediately within the statements "
3842 & "of a loop");
3843 else
3844 Error_Pragma_Arg
3845 ("block containing pragma % must appear immediately within "
3846 & "the statements of a loop", Constr);
3847 end if;
3848 end Placement_Error;
3849
3850 -- Local declarations
3851
3852 Prev : Node_Id;
3853 Stmt : Node_Id;
3854
3855 -- Start of processing for Check_Loop_Pragma_Placement
3856
3857 begin
3858 Prev := N;
3859 Stmt := Parent (N);
3860 while Present (Stmt) loop
3861
3862 -- The pragma or previous block must appear immediately within the
3863 -- current block's declarative or statement part.
3864
3865 if Nkind (Stmt) = N_Block_Statement then
3866 if (No (Declarations (Stmt))
3867 or else List_Containing (Prev) /= Declarations (Stmt))
3868 and then
3869 List_Containing (Prev) /=
3870 Statements (Handled_Statement_Sequence (Stmt))
3871 then
3872 Placement_Error (Prev);
3873 return;
3874
3875 -- Keep inspecting the parents because we are now within a
3876 -- chain of nested blocks.
3877
3878 else
3879 Prev := Stmt;
3880 Stmt := Parent (Stmt);
3881 end if;
3882
3883 -- The pragma or previous block must appear immediately within the
3884 -- statements of the loop.
3885
3886 elsif Nkind (Stmt) = N_Loop_Statement then
3887 if List_Containing (Prev) /= Statements (Stmt) then
3888 Placement_Error (Prev);
3889 end if;
3890
3891 -- Stop the traversal because we reached the innermost loop
3892 -- regardless of whether we encountered an error or not.
3893
3894 return;
3895
3896 -- Ignore a handled statement sequence. Note that this node may
3897 -- be related to a subprogram body in which case we will emit an
3898 -- error on the next iteration of the search.
3899
3900 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
3901 Stmt := Parent (Stmt);
3902
3903 -- Any other statement breaks the chain from the pragma to the
3904 -- loop.
3905
3906 else
3907 Placement_Error (Prev);
3908 return;
3909 end if;
3910 end loop;
3911 end Check_Loop_Pragma_Placement;
3912
3913 -------------------------------------------
3914 -- Check_Is_In_Decl_Part_Or_Package_Spec --
3915 -------------------------------------------
3916
3917 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
3918 P : Node_Id;
3919
3920 begin
3921 P := Parent (N);
3922 loop
3923 if No (P) then
3924 exit;
3925
3926 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
3927 exit;
3928
3929 elsif Nkind_In (P, N_Package_Specification,
3930 N_Block_Statement)
3931 then
3932 return;
3933
3934 -- Note: the following tests seem a little peculiar, because
3935 -- they test for bodies, but if we were in the statement part
3936 -- of the body, we would already have hit the handled statement
3937 -- sequence, so the only way we get here is by being in the
3938 -- declarative part of the body.
3939
3940 elsif Nkind_In (P, N_Subprogram_Body,
3941 N_Package_Body,
3942 N_Task_Body,
3943 N_Entry_Body)
3944 then
3945 return;
3946 end if;
3947
3948 P := Parent (P);
3949 end loop;
3950
3951 Error_Pragma ("pragma% is not in declarative part or package spec");
3952 end Check_Is_In_Decl_Part_Or_Package_Spec;
3953
3954 -------------------------
3955 -- Check_No_Identifier --
3956 -------------------------
3957
3958 procedure Check_No_Identifier (Arg : Node_Id) is
3959 begin
3960 if Nkind (Arg) = N_Pragma_Argument_Association
3961 and then Chars (Arg) /= No_Name
3962 then
3963 Error_Pragma_Arg_Ident
3964 ("pragma% does not permit identifier& here", Arg);
3965 end if;
3966 end Check_No_Identifier;
3967
3968 --------------------------
3969 -- Check_No_Identifiers --
3970 --------------------------
3971
3972 procedure Check_No_Identifiers is
3973 Arg_Node : Node_Id;
3974 begin
3975 Arg_Node := Arg1;
3976 for J in 1 .. Arg_Count loop
3977 Check_No_Identifier (Arg_Node);
3978 Next (Arg_Node);
3979 end loop;
3980 end Check_No_Identifiers;
3981
3982 ------------------------
3983 -- Check_No_Link_Name --
3984 ------------------------
3985
3986 procedure Check_No_Link_Name is
3987 begin
3988 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
3989 Arg4 := Arg3;
3990 end if;
3991
3992 if Present (Arg4) then
3993 Error_Pragma_Arg
3994 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
3995 end if;
3996 end Check_No_Link_Name;
3997
3998 -------------------------------
3999 -- Check_Optional_Identifier --
4000 -------------------------------
4001
4002 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4003 begin
4004 if Present (Arg)
4005 and then Nkind (Arg) = N_Pragma_Argument_Association
4006 and then Chars (Arg) /= No_Name
4007 then
4008 if Chars (Arg) /= Id then
4009 Error_Msg_Name_1 := Pname;
4010 Error_Msg_Name_2 := Id;
4011 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4012 raise Pragma_Exit;
4013 end if;
4014 end if;
4015 end Check_Optional_Identifier;
4016
4017 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4018 begin
4019 Name_Buffer (1 .. Id'Length) := Id;
4020 Name_Len := Id'Length;
4021 Check_Optional_Identifier (Arg, Name_Find);
4022 end Check_Optional_Identifier;
4023
4024 --------------------
4025 -- Check_Pre_Post --
4026 --------------------
4027
4028 procedure Check_Pre_Post is
4029 P : Node_Id;
4030 PO : Node_Id;
4031
4032 begin
4033 if not Is_List_Member (N) then
4034 Pragma_Misplaced;
4035 end if;
4036
4037 -- If we are within an inlined body, the legality of the pragma
4038 -- has been checked already.
4039
4040 if In_Inlined_Body then
4041 return;
4042 end if;
4043
4044 -- Search prior declarations
4045
4046 P := N;
4047 while Present (Prev (P)) loop
4048 P := Prev (P);
4049
4050 -- If the previous node is a generic subprogram, do not go to to
4051 -- the original node, which is the unanalyzed tree: we need to
4052 -- attach the pre/postconditions to the analyzed version at this
4053 -- point. They get propagated to the original tree when analyzing
4054 -- the corresponding body.
4055
4056 if Nkind (P) not in N_Generic_Declaration then
4057 PO := Original_Node (P);
4058 else
4059 PO := P;
4060 end if;
4061
4062 -- Skip past prior pragma
4063
4064 if Nkind (PO) = N_Pragma then
4065 null;
4066
4067 -- Skip stuff not coming from source
4068
4069 elsif not Comes_From_Source (PO) then
4070
4071 -- The condition may apply to a subprogram instantiation
4072
4073 if Nkind (PO) = N_Subprogram_Declaration
4074 and then Present (Generic_Parent (Specification (PO)))
4075 then
4076 return;
4077
4078 elsif Nkind (PO) = N_Subprogram_Declaration
4079 and then In_Instance
4080 then
4081 return;
4082
4083 -- For all other cases of non source code, do nothing
4084
4085 else
4086 null;
4087 end if;
4088
4089 -- Only remaining possibility is subprogram declaration
4090
4091 else
4092 return;
4093 end if;
4094 end loop;
4095
4096 -- If we fall through loop, pragma is at start of list, so see if it
4097 -- is at the start of declarations of a subprogram body.
4098
4099 PO := Parent (N);
4100
4101 if Nkind (PO) = N_Subprogram_Body
4102 and then List_Containing (N) = Declarations (PO)
4103 then
4104 -- This is only allowed if there is no separate specification
4105
4106 if Present (Corresponding_Spec (PO)) then
4107 Error_Pragma
4108 ("pragma% must apply to subprogram specification");
4109 end if;
4110
4111 return;
4112 end if;
4113 end Check_Pre_Post;
4114
4115 --------------------------------------
4116 -- Check_Precondition_Postcondition --
4117 --------------------------------------
4118
4119 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
4120 P : Node_Id;
4121 PO : Node_Id;
4122
4123 procedure Chain_PPC (PO : Node_Id);
4124 -- If PO is an entry or a [generic] subprogram declaration node, then
4125 -- the precondition/postcondition applies to this subprogram and the
4126 -- processing for the pragma is completed. Otherwise the pragma is
4127 -- misplaced.
4128
4129 ---------------
4130 -- Chain_PPC --
4131 ---------------
4132
4133 procedure Chain_PPC (PO : Node_Id) is
4134 S : Entity_Id;
4135
4136 begin
4137 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
4138 if not From_Aspect_Specification (N) then
4139 Error_Pragma
4140 ("pragma% cannot be applied to abstract subprogram");
4141
4142 elsif Class_Present (N) then
4143 null;
4144
4145 else
4146 Error_Pragma
4147 ("aspect % requires ''Class for abstract subprogram");
4148 end if;
4149
4150 -- AI05-0230: The same restriction applies to null procedures. For
4151 -- compatibility with earlier uses of the Ada pragma, apply this
4152 -- rule only to aspect specifications.
4153
4154 -- The above discrepency needs documentation. Robert is dubious
4155 -- about whether it is a good idea ???
4156
4157 elsif Nkind (PO) = N_Subprogram_Declaration
4158 and then Nkind (Specification (PO)) = N_Procedure_Specification
4159 and then Null_Present (Specification (PO))
4160 and then From_Aspect_Specification (N)
4161 and then not Class_Present (N)
4162 then
4163 Error_Pragma
4164 ("aspect % requires ''Class for null procedure");
4165
4166 -- Pre/postconditions are legal on a subprogram body if it is not
4167 -- a completion of a declaration. They are also legal on a stub
4168 -- with no previous declarations (this is checked when processing
4169 -- the corresponding aspects).
4170
4171 elsif Nkind (PO) = N_Subprogram_Body
4172 and then Acts_As_Spec (PO)
4173 then
4174 null;
4175
4176 elsif Nkind (PO) = N_Subprogram_Body_Stub then
4177 null;
4178
4179 elsif not Nkind_In (PO, N_Subprogram_Declaration,
4180 N_Expression_Function,
4181 N_Generic_Subprogram_Declaration,
4182 N_Entry_Declaration)
4183 then
4184 Pragma_Misplaced;
4185 end if;
4186
4187 -- Here if we have [generic] subprogram or entry declaration
4188
4189 if Nkind (PO) = N_Entry_Declaration then
4190 S := Defining_Entity (PO);
4191 else
4192 S := Defining_Unit_Name (Specification (PO));
4193
4194 if Nkind (S) = N_Defining_Program_Unit_Name then
4195 S := Defining_Identifier (S);
4196 end if;
4197 end if;
4198
4199 -- Note: we do not analyze the pragma at this point. Instead we
4200 -- delay this analysis until the end of the declarative part in
4201 -- which the pragma appears. This implements the required delay
4202 -- in this analysis, allowing forward references. The analysis
4203 -- happens at the end of Analyze_Declarations.
4204
4205 -- Chain spec PPC pragma to list for subprogram
4206
4207 Add_Contract_Item (N, S);
4208
4209 -- Return indicating spec case
4210
4211 In_Body := False;
4212 return;
4213 end Chain_PPC;
4214
4215 -- Start of processing for Check_Precondition_Postcondition
4216
4217 begin
4218 if not Is_List_Member (N) then
4219 Pragma_Misplaced;
4220 end if;
4221
4222 -- Preanalyze message argument if present. Visibility in this
4223 -- argument is established at the point of pragma occurrence.
4224
4225 if Arg_Count = 2 then
4226 Check_Optional_Identifier (Arg2, Name_Message);
4227 Preanalyze_Spec_Expression
4228 (Get_Pragma_Arg (Arg2), Standard_String);
4229 end if;
4230
4231 -- For a pragma PPC in the extended main source unit, record enabled
4232 -- status in SCO.
4233
4234 if Is_Checked (N) and then not Split_PPC (N) then
4235 Set_SCO_Pragma_Enabled (Loc);
4236 end if;
4237
4238 -- If we are within an inlined body, the legality of the pragma
4239 -- has been checked already.
4240
4241 if In_Inlined_Body then
4242 In_Body := True;
4243 return;
4244 end if;
4245
4246 -- Search prior declarations
4247
4248 P := N;
4249 while Present (Prev (P)) loop
4250 P := Prev (P);
4251
4252 -- If the previous node is a generic subprogram, do not go to to
4253 -- the original node, which is the unanalyzed tree: we need to
4254 -- attach the pre/postconditions to the analyzed version at this
4255 -- point. They get propagated to the original tree when analyzing
4256 -- the corresponding body.
4257
4258 if Nkind (P) not in N_Generic_Declaration then
4259 PO := Original_Node (P);
4260 else
4261 PO := P;
4262 end if;
4263
4264 -- Skip past prior pragma
4265
4266 if Nkind (PO) = N_Pragma then
4267 null;
4268
4269 -- Skip stuff not coming from source
4270
4271 elsif not Comes_From_Source (PO) then
4272
4273 -- The condition may apply to a subprogram instantiation
4274
4275 if Nkind (PO) = N_Subprogram_Declaration
4276 and then Present (Generic_Parent (Specification (PO)))
4277 then
4278 Chain_PPC (PO);
4279 return;
4280
4281 elsif Nkind (PO) = N_Subprogram_Declaration
4282 and then In_Instance
4283 then
4284 Chain_PPC (PO);
4285 return;
4286
4287 -- For all other cases of non source code, do nothing
4288
4289 else
4290 null;
4291 end if;
4292
4293 -- Only remaining possibility is subprogram declaration
4294
4295 else
4296 Chain_PPC (PO);
4297 return;
4298 end if;
4299 end loop;
4300
4301 -- If we fall through loop, pragma is at start of list, so see if it
4302 -- is at the start of declarations of a subprogram body.
4303
4304 PO := Parent (N);
4305
4306 if Nkind (PO) = N_Subprogram_Body
4307 and then List_Containing (N) = Declarations (PO)
4308 then
4309 if Operating_Mode /= Generate_Code or else Inside_A_Generic then
4310
4311 -- Analyze pragma expression for correctness and for ASIS use
4312
4313 Preanalyze_Assert_Expression
4314 (Get_Pragma_Arg (Arg1), Standard_Boolean);
4315
4316 -- In ASIS mode, for a pragma generated from a source aspect,
4317 -- also analyze the original aspect expression.
4318
4319 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
4320 Preanalyze_Assert_Expression
4321 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
4322 end if;
4323 end if;
4324
4325 -- Retain a copy of the pre- or postcondition pragma for formal
4326 -- verification purposes. The copy is needed because the pragma is
4327 -- expanded into other constructs which are not acceptable in the
4328 -- N_Contract node.
4329
4330 if Acts_As_Spec (PO)
4331 and then (SPARK_Mode or Formal_Extensions)
4332 then
4333 declare
4334 Prag : constant Node_Id := New_Copy_Tree (N);
4335
4336 begin
4337 -- Preanalyze the pragma
4338
4339 Preanalyze_Assert_Expression
4340 (Get_Pragma_Arg
4341 (First (Pragma_Argument_Associations (Prag))),
4342 Standard_Boolean);
4343
4344 -- Preanalyze the corresponding aspect (if any)
4345
4346 if Present (Corresponding_Aspect (Prag)) then
4347 Preanalyze_Assert_Expression
4348 (Expression (Corresponding_Aspect (Prag)),
4349 Standard_Boolean);
4350 end if;
4351
4352 -- Chain the copy on the contract of the body
4353
4354 Add_Contract_Item
4355 (Prag, Defining_Unit_Name (Specification (PO)));
4356 end;
4357 end if;
4358
4359 In_Body := True;
4360 return;
4361
4362 -- See if it is in the pragmas after a library level subprogram
4363
4364 elsif Nkind (PO) = N_Compilation_Unit_Aux then
4365
4366 -- In formal verification mode, analyze pragma expression for
4367 -- correctness, as it is not expanded later. Ditto in ASIS_Mode
4368 -- where there is no later point at which the aspect will be
4369 -- analyzed.
4370
4371 if SPARK_Mode or else ASIS_Mode then
4372 Analyze_Pre_Post_Condition_In_Decl_Part
4373 (N, Defining_Entity (Unit (Parent (PO))));
4374 end if;
4375
4376 Chain_PPC (Unit (Parent (PO)));
4377 return;
4378 end if;
4379
4380 -- If we fall through, pragma was misplaced
4381
4382 Pragma_Misplaced;
4383 end Check_Precondition_Postcondition;
4384
4385 -----------------------------
4386 -- Check_Static_Constraint --
4387 -----------------------------
4388
4389 -- Note: for convenience in writing this procedure, in addition to
4390 -- the officially (i.e. by spec) allowed argument which is always a
4391 -- constraint, it also allows ranges and discriminant associations.
4392 -- Above is not clear ???
4393
4394 procedure Check_Static_Constraint (Constr : Node_Id) is
4395
4396 procedure Require_Static (E : Node_Id);
4397 -- Require given expression to be static expression
4398
4399 --------------------
4400 -- Require_Static --
4401 --------------------
4402
4403 procedure Require_Static (E : Node_Id) is
4404 begin
4405 if not Is_OK_Static_Expression (E) then
4406 Flag_Non_Static_Expr
4407 ("non-static constraint not allowed in Unchecked_Union!", E);
4408 raise Pragma_Exit;
4409 end if;
4410 end Require_Static;
4411
4412 -- Start of processing for Check_Static_Constraint
4413
4414 begin
4415 case Nkind (Constr) is
4416 when N_Discriminant_Association =>
4417 Require_Static (Expression (Constr));
4418
4419 when N_Range =>
4420 Require_Static (Low_Bound (Constr));
4421 Require_Static (High_Bound (Constr));
4422
4423 when N_Attribute_Reference =>
4424 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
4425 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
4426
4427 when N_Range_Constraint =>
4428 Check_Static_Constraint (Range_Expression (Constr));
4429
4430 when N_Index_Or_Discriminant_Constraint =>
4431 declare
4432 IDC : Entity_Id;
4433 begin
4434 IDC := First (Constraints (Constr));
4435 while Present (IDC) loop
4436 Check_Static_Constraint (IDC);
4437 Next (IDC);
4438 end loop;
4439 end;
4440
4441 when others =>
4442 null;
4443 end case;
4444 end Check_Static_Constraint;
4445
4446 ---------------------
4447 -- Check_Test_Case --
4448 ---------------------
4449
4450 procedure Check_Test_Case is
4451 P : Node_Id;
4452 PO : Node_Id;
4453
4454 procedure Chain_CTC (PO : Node_Id);
4455 -- If PO is a [generic] subprogram declaration node, then the
4456 -- test-case applies to this subprogram and the processing for
4457 -- the pragma is completed. Otherwise the pragma is misplaced.
4458
4459 ---------------
4460 -- Chain_CTC --
4461 ---------------
4462
4463 procedure Chain_CTC (PO : Node_Id) is
4464 S : Entity_Id;
4465
4466 begin
4467 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
4468 Error_Pragma
4469 ("pragma% cannot be applied to abstract subprogram");
4470
4471 elsif Nkind (PO) = N_Entry_Declaration then
4472 Error_Pragma ("pragma% cannot be applied to entry");
4473
4474 elsif not Nkind_In (PO, N_Subprogram_Declaration,
4475 N_Generic_Subprogram_Declaration)
4476 then
4477 Pragma_Misplaced;
4478 end if;
4479
4480 -- Here if we have [generic] subprogram declaration
4481
4482 S := Defining_Unit_Name (Specification (PO));
4483
4484 -- Note: we do not analyze the pragma at this point. Instead we
4485 -- delay this analysis until the end of the declarative part in
4486 -- which the pragma appears. This implements the required delay
4487 -- in this analysis, allowing forward references. The analysis
4488 -- happens at the end of Analyze_Declarations.
4489
4490 -- There should not be another test-case with the same name
4491 -- associated to this subprogram.
4492
4493 declare
4494 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
4495 CTC : Node_Id;
4496
4497 begin
4498 CTC := Contract_Test_Cases (Contract (S));
4499 while Present (CTC) loop
4500
4501 -- Omit pragma Contract_Cases because it does not introduce
4502 -- a unique case name and it does not follow the syntax of
4503 -- Test_Case.
4504
4505 if Pragma_Name (CTC) = Name_Contract_Cases then
4506 null;
4507
4508 elsif String_Equal
4509 (Name, Get_Name_From_CTC_Pragma (CTC))
4510 then
4511 Error_Msg_Sloc := Sloc (CTC);
4512 Error_Pragma ("name for pragma% is already used#");
4513 end if;
4514
4515 CTC := Next_Pragma (CTC);
4516 end loop;
4517 end;
4518
4519 -- Chain spec CTC pragma to list for subprogram
4520
4521 Add_Contract_Item (N, S);
4522 end Chain_CTC;
4523
4524 -- Start of processing for Check_Test_Case
4525
4526 begin
4527 -- First check pragma arguments
4528
4529 Check_At_Least_N_Arguments (2);
4530 Check_At_Most_N_Arguments (4);
4531 Check_Arg_Order
4532 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
4533
4534 Check_Optional_Identifier (Arg1, Name_Name);
4535 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
4536
4537 -- In ASIS mode, for a pragma generated from a source aspect, also
4538 -- analyze the original aspect expression.
4539
4540 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
4541 Check_Expr_Is_Static_Expression
4542 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
4543 end if;
4544
4545 Check_Optional_Identifier (Arg2, Name_Mode);
4546 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
4547
4548 if Arg_Count = 4 then
4549 Check_Identifier (Arg3, Name_Requires);
4550 Check_Identifier (Arg4, Name_Ensures);
4551
4552 elsif Arg_Count = 3 then
4553 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
4554 end if;
4555
4556 -- Check pragma placement
4557
4558 if not Is_List_Member (N) then
4559 Pragma_Misplaced;
4560 end if;
4561
4562 -- Test-case should only appear in package spec unit
4563
4564 if Get_Source_Unit (N) = No_Unit
4565 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
4566 N_Package_Declaration,
4567 N_Generic_Package_Declaration)
4568 then
4569 Pragma_Misplaced;
4570 end if;
4571
4572 -- Search prior declarations
4573
4574 P := N;
4575 while Present (Prev (P)) loop
4576 P := Prev (P);
4577
4578 -- If the previous node is a generic subprogram, do not go to to
4579 -- the original node, which is the unanalyzed tree: we need to
4580 -- attach the test-case to the analyzed version at this point.
4581 -- They get propagated to the original tree when analyzing the
4582 -- corresponding body.
4583
4584 if Nkind (P) not in N_Generic_Declaration then
4585 PO := Original_Node (P);
4586 else
4587 PO := P;
4588 end if;
4589
4590 -- Skip past prior pragma
4591
4592 if Nkind (PO) = N_Pragma then
4593 null;
4594
4595 -- Skip stuff not coming from source
4596
4597 elsif not Comes_From_Source (PO) then
4598 null;
4599
4600 -- Only remaining possibility is subprogram declaration. First
4601 -- check that it is declared directly in a package declaration.
4602 -- This may be either the package declaration for the current unit
4603 -- being defined or a local package declaration.
4604
4605 elsif not Present (Parent (Parent (PO)))
4606 or else not Present (Parent (Parent (Parent (PO))))
4607 or else not Nkind_In (Parent (Parent (PO)),
4608 N_Package_Declaration,
4609 N_Generic_Package_Declaration)
4610 then
4611 Pragma_Misplaced;
4612
4613 else
4614 Chain_CTC (PO);
4615 return;
4616 end if;
4617 end loop;
4618
4619 -- If we fall through, pragma was misplaced
4620
4621 Pragma_Misplaced;
4622 end Check_Test_Case;
4623
4624 --------------------------------------
4625 -- Check_Valid_Configuration_Pragma --
4626 --------------------------------------
4627
4628 -- A configuration pragma must appear in the context clause of a
4629 -- compilation unit, and only other pragmas may precede it. Note that
4630 -- the test also allows use in a configuration pragma file.
4631
4632 procedure Check_Valid_Configuration_Pragma is
4633 begin
4634 if not Is_Configuration_Pragma then
4635 Error_Pragma ("incorrect placement for configuration pragma%");
4636 end if;
4637 end Check_Valid_Configuration_Pragma;
4638
4639 -------------------------------------
4640 -- Check_Valid_Library_Unit_Pragma --
4641 -------------------------------------
4642
4643 procedure Check_Valid_Library_Unit_Pragma is
4644 Plist : List_Id;
4645 Parent_Node : Node_Id;
4646 Unit_Name : Entity_Id;
4647 Unit_Kind : Node_Kind;
4648 Unit_Node : Node_Id;
4649 Sindex : Source_File_Index;
4650
4651 begin
4652 if not Is_List_Member (N) then
4653 Pragma_Misplaced;
4654
4655 else
4656 Plist := List_Containing (N);
4657 Parent_Node := Parent (Plist);
4658
4659 if Parent_Node = Empty then
4660 Pragma_Misplaced;
4661
4662 -- Case of pragma appearing after a compilation unit. In this case
4663 -- it must have an argument with the corresponding name and must
4664 -- be part of the following pragmas of its parent.
4665
4666 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
4667 if Plist /= Pragmas_After (Parent_Node) then
4668 Pragma_Misplaced;
4669
4670 elsif Arg_Count = 0 then
4671 Error_Pragma
4672 ("argument required if outside compilation unit");
4673
4674 else
4675 Check_No_Identifiers;
4676 Check_Arg_Count (1);
4677 Unit_Node := Unit (Parent (Parent_Node));
4678 Unit_Kind := Nkind (Unit_Node);
4679
4680 Analyze (Get_Pragma_Arg (Arg1));
4681
4682 if Unit_Kind = N_Generic_Subprogram_Declaration
4683 or else Unit_Kind = N_Subprogram_Declaration
4684 then
4685 Unit_Name := Defining_Entity (Unit_Node);
4686
4687 elsif Unit_Kind in N_Generic_Instantiation then
4688 Unit_Name := Defining_Entity (Unit_Node);
4689
4690 else
4691 Unit_Name := Cunit_Entity (Current_Sem_Unit);
4692 end if;
4693
4694 if Chars (Unit_Name) /=
4695 Chars (Entity (Get_Pragma_Arg (Arg1)))
4696 then
4697 Error_Pragma_Arg
4698 ("pragma% argument is not current unit name", Arg1);
4699 end if;
4700
4701 if Ekind (Unit_Name) = E_Package
4702 and then Present (Renamed_Entity (Unit_Name))
4703 then
4704 Error_Pragma ("pragma% not allowed for renamed package");
4705 end if;
4706 end if;
4707
4708 -- Pragma appears other than after a compilation unit
4709
4710 else
4711 -- Here we check for the generic instantiation case and also
4712 -- for the case of processing a generic formal package. We
4713 -- detect these cases by noting that the Sloc on the node
4714 -- does not belong to the current compilation unit.
4715
4716 Sindex := Source_Index (Current_Sem_Unit);
4717
4718 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
4719 Rewrite (N, Make_Null_Statement (Loc));
4720 return;
4721
4722 -- If before first declaration, the pragma applies to the
4723 -- enclosing unit, and the name if present must be this name.
4724
4725 elsif Is_Before_First_Decl (N, Plist) then
4726 Unit_Node := Unit_Declaration_Node (Current_Scope);
4727 Unit_Kind := Nkind (Unit_Node);
4728
4729 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
4730 Pragma_Misplaced;
4731
4732 elsif Unit_Kind = N_Subprogram_Body
4733 and then not Acts_As_Spec (Unit_Node)
4734 then
4735 Pragma_Misplaced;
4736
4737 elsif Nkind (Parent_Node) = N_Package_Body then
4738 Pragma_Misplaced;
4739
4740 elsif Nkind (Parent_Node) = N_Package_Specification
4741 and then Plist = Private_Declarations (Parent_Node)
4742 then
4743 Pragma_Misplaced;
4744
4745 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
4746 or else Nkind (Parent_Node) =
4747 N_Generic_Subprogram_Declaration)
4748 and then Plist = Generic_Formal_Declarations (Parent_Node)
4749 then
4750 Pragma_Misplaced;
4751
4752 elsif Arg_Count > 0 then
4753 Analyze (Get_Pragma_Arg (Arg1));
4754
4755 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
4756 Error_Pragma_Arg
4757 ("name in pragma% must be enclosing unit", Arg1);
4758 end if;
4759
4760 -- It is legal to have no argument in this context
4761
4762 else
4763 return;
4764 end if;
4765
4766 -- Error if not before first declaration. This is because a
4767 -- library unit pragma argument must be the name of a library
4768 -- unit (RM 10.1.5(7)), but the only names permitted in this
4769 -- context are (RM 10.1.5(6)) names of subprogram declarations,
4770 -- generic subprogram declarations or generic instantiations.
4771
4772 else
4773 Error_Pragma
4774 ("pragma% misplaced, must be before first declaration");
4775 end if;
4776 end if;
4777 end if;
4778 end Check_Valid_Library_Unit_Pragma;
4779
4780 -------------------
4781 -- Check_Variant --
4782 -------------------
4783
4784 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
4785 Clist : constant Node_Id := Component_List (Variant);
4786 Comp : Node_Id;
4787
4788 begin
4789 Comp := First (Component_Items (Clist));
4790 while Present (Comp) loop
4791 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
4792 Next (Comp);
4793 end loop;
4794 end Check_Variant;
4795
4796 ------------------
4797 -- Error_Pragma --
4798 ------------------
4799
4800 procedure Error_Pragma (Msg : String) is
4801 MsgF : String := Msg;
4802 begin
4803 Error_Msg_Name_1 := Pname;
4804 Fix_Error (MsgF);
4805 Error_Msg_N (MsgF, N);
4806 raise Pragma_Exit;
4807 end Error_Pragma;
4808
4809 ----------------------
4810 -- Error_Pragma_Arg --
4811 ----------------------
4812
4813 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
4814 MsgF : String := Msg;
4815 begin
4816 Error_Msg_Name_1 := Pname;
4817 Fix_Error (MsgF);
4818 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
4819 raise Pragma_Exit;
4820 end Error_Pragma_Arg;
4821
4822 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
4823 MsgF : String := Msg1;
4824 begin
4825 Error_Msg_Name_1 := Pname;
4826 Fix_Error (MsgF);
4827 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
4828 Error_Pragma_Arg (Msg2, Arg);
4829 end Error_Pragma_Arg;
4830
4831 ----------------------------
4832 -- Error_Pragma_Arg_Ident --
4833 ----------------------------
4834
4835 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
4836 MsgF : String := Msg;
4837 begin
4838 Error_Msg_Name_1 := Pname;
4839 Fix_Error (MsgF);
4840 Error_Msg_N (MsgF, Arg);
4841 raise Pragma_Exit;
4842 end Error_Pragma_Arg_Ident;
4843
4844 ----------------------
4845 -- Error_Pragma_Ref --
4846 ----------------------
4847
4848 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
4849 MsgF : String := Msg;
4850 begin
4851 Error_Msg_Name_1 := Pname;
4852 Fix_Error (MsgF);
4853 Error_Msg_Sloc := Sloc (Ref);
4854 Error_Msg_NE (MsgF, N, Ref);
4855 raise Pragma_Exit;
4856 end Error_Pragma_Ref;
4857
4858 ------------------------
4859 -- Find_Lib_Unit_Name --
4860 ------------------------
4861
4862 function Find_Lib_Unit_Name return Entity_Id is
4863 begin
4864 -- Return inner compilation unit entity, for case of nested
4865 -- categorization pragmas. This happens in generic unit.
4866
4867 if Nkind (Parent (N)) = N_Package_Specification
4868 and then Defining_Entity (Parent (N)) /= Current_Scope
4869 then
4870 return Defining_Entity (Parent (N));
4871 else
4872 return Current_Scope;
4873 end if;
4874 end Find_Lib_Unit_Name;
4875
4876 ----------------------------
4877 -- Find_Program_Unit_Name --
4878 ----------------------------
4879
4880 procedure Find_Program_Unit_Name (Id : Node_Id) is
4881 Unit_Name : Entity_Id;
4882 Unit_Kind : Node_Kind;
4883 P : constant Node_Id := Parent (N);
4884
4885 begin
4886 if Nkind (P) = N_Compilation_Unit then
4887 Unit_Kind := Nkind (Unit (P));
4888
4889 if Unit_Kind = N_Subprogram_Declaration
4890 or else Unit_Kind = N_Package_Declaration
4891 or else Unit_Kind in N_Generic_Declaration
4892 then
4893 Unit_Name := Defining_Entity (Unit (P));
4894
4895 if Chars (Id) = Chars (Unit_Name) then
4896 Set_Entity (Id, Unit_Name);
4897 Set_Etype (Id, Etype (Unit_Name));
4898 else
4899 Set_Etype (Id, Any_Type);
4900 Error_Pragma
4901 ("cannot find program unit referenced by pragma%");
4902 end if;
4903
4904 else
4905 Set_Etype (Id, Any_Type);
4906 Error_Pragma ("pragma% inapplicable to this unit");
4907 end if;
4908
4909 else
4910 Analyze (Id);
4911 end if;
4912 end Find_Program_Unit_Name;
4913
4914 -----------------------------------------
4915 -- Find_Unique_Parameterless_Procedure --
4916 -----------------------------------------
4917
4918 function Find_Unique_Parameterless_Procedure
4919 (Name : Entity_Id;
4920 Arg : Node_Id) return Entity_Id
4921 is
4922 Proc : Entity_Id := Empty;
4923
4924 begin
4925 -- The body of this procedure needs some comments ???
4926
4927 if not Is_Entity_Name (Name) then
4928 Error_Pragma_Arg
4929 ("argument of pragma% must be entity name", Arg);
4930
4931 elsif not Is_Overloaded (Name) then
4932 Proc := Entity (Name);
4933
4934 if Ekind (Proc) /= E_Procedure
4935 or else Present (First_Formal (Proc))
4936 then
4937 Error_Pragma_Arg
4938 ("argument of pragma% must be parameterless procedure", Arg);
4939 end if;
4940
4941 else
4942 declare
4943 Found : Boolean := False;
4944 It : Interp;
4945 Index : Interp_Index;
4946
4947 begin
4948 Get_First_Interp (Name, Index, It);
4949 while Present (It.Nam) loop
4950 Proc := It.Nam;
4951
4952 if Ekind (Proc) = E_Procedure
4953 and then No (First_Formal (Proc))
4954 then
4955 if not Found then
4956 Found := True;
4957 Set_Entity (Name, Proc);
4958 Set_Is_Overloaded (Name, False);
4959 else
4960 Error_Pragma_Arg
4961 ("ambiguous handler name for pragma% ", Arg);
4962 end if;
4963 end if;
4964
4965 Get_Next_Interp (Index, It);
4966 end loop;
4967
4968 if not Found then
4969 Error_Pragma_Arg
4970 ("argument of pragma% must be parameterless procedure",
4971 Arg);
4972 else
4973 Proc := Entity (Name);
4974 end if;
4975 end;
4976 end if;
4977
4978 return Proc;
4979 end Find_Unique_Parameterless_Procedure;
4980
4981 ---------------
4982 -- Fix_Error --
4983 ---------------
4984
4985 procedure Fix_Error (Msg : in out String) is
4986 begin
4987 -- If we have a rewriting of another pragma, go to that pragma
4988
4989 if Is_Rewrite_Substitution (N)
4990 and then Nkind (Original_Node (N)) = N_Pragma
4991 then
4992 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
4993 end if;
4994
4995 -- Case where pragma comes from an aspect specification
4996
4997 if From_Aspect_Specification (N) then
4998
4999 -- Change appearence of "pragma" in message to "aspect"
5000
5001 for J in Msg'First .. Msg'Last - 5 loop
5002 if Msg (J .. J + 5) = "pragma" then
5003 Msg (J .. J + 5) := "aspect";
5004 end if;
5005 end loop;
5006
5007 -- Get name from corresponding aspect
5008
5009 Error_Msg_Name_1 := Original_Aspect_Name (N);
5010 end if;
5011 end Fix_Error;
5012
5013 -------------------------
5014 -- Gather_Associations --
5015 -------------------------
5016
5017 procedure Gather_Associations
5018 (Names : Name_List;
5019 Args : out Args_List)
5020 is
5021 Arg : Node_Id;
5022
5023 begin
5024 -- Initialize all parameters to Empty
5025
5026 for J in Args'Range loop
5027 Args (J) := Empty;
5028 end loop;
5029
5030 -- That's all we have to do if there are no argument associations
5031
5032 if No (Pragma_Argument_Associations (N)) then
5033 return;
5034 end if;
5035
5036 -- Otherwise first deal with any positional parameters present
5037
5038 Arg := First (Pragma_Argument_Associations (N));
5039 for Index in Args'Range loop
5040 exit when No (Arg) or else Chars (Arg) /= No_Name;
5041 Args (Index) := Get_Pragma_Arg (Arg);
5042 Next (Arg);
5043 end loop;
5044
5045 -- Positional parameters all processed, if any left, then we
5046 -- have too many positional parameters.
5047
5048 if Present (Arg) and then Chars (Arg) = No_Name then
5049 Error_Pragma_Arg
5050 ("too many positional associations for pragma%", Arg);
5051 end if;
5052
5053 -- Process named parameters if any are present
5054
5055 while Present (Arg) loop
5056 if Chars (Arg) = No_Name then
5057 Error_Pragma_Arg
5058 ("positional association cannot follow named association",
5059 Arg);
5060
5061 else
5062 for Index in Names'Range loop
5063 if Names (Index) = Chars (Arg) then
5064 if Present (Args (Index)) then
5065 Error_Pragma_Arg
5066 ("duplicate argument association for pragma%", Arg);
5067 else
5068 Args (Index) := Get_Pragma_Arg (Arg);
5069 exit;
5070 end if;
5071 end if;
5072
5073 if Index = Names'Last then
5074 Error_Msg_Name_1 := Pname;
5075 Error_Msg_N ("pragma% does not allow & argument", Arg);
5076
5077 -- Check for possible misspelling
5078
5079 for Index1 in Names'Range loop
5080 if Is_Bad_Spelling_Of
5081 (Chars (Arg), Names (Index1))
5082 then
5083 Error_Msg_Name_1 := Names (Index1);
5084 Error_Msg_N -- CODEFIX
5085 ("\possible misspelling of%", Arg);
5086 exit;
5087 end if;
5088 end loop;
5089
5090 raise Pragma_Exit;
5091 end if;
5092 end loop;
5093 end if;
5094
5095 Next (Arg);
5096 end loop;
5097 end Gather_Associations;
5098
5099 -----------------
5100 -- GNAT_Pragma --
5101 -----------------
5102
5103 procedure GNAT_Pragma is
5104 begin
5105 -- We need to check the No_Implementation_Pragmas restriction for
5106 -- the case of a pragma from source. Note that the case of aspects
5107 -- generating corresponding pragmas marks these pragmas as not being
5108 -- from source, so this test also catches that case.
5109
5110 if Comes_From_Source (N) then
5111 Check_Restriction (No_Implementation_Pragmas, N);
5112 end if;
5113 end GNAT_Pragma;
5114
5115 --------------------------
5116 -- Is_Before_First_Decl --
5117 --------------------------
5118
5119 function Is_Before_First_Decl
5120 (Pragma_Node : Node_Id;
5121 Decls : List_Id) return Boolean
5122 is
5123 Item : Node_Id := First (Decls);
5124
5125 begin
5126 -- Only other pragmas can come before this pragma
5127
5128 loop
5129 if No (Item) or else Nkind (Item) /= N_Pragma then
5130 return False;
5131
5132 elsif Item = Pragma_Node then
5133 return True;
5134 end if;
5135
5136 Next (Item);
5137 end loop;
5138 end Is_Before_First_Decl;
5139
5140 -----------------------------
5141 -- Is_Configuration_Pragma --
5142 -----------------------------
5143
5144 -- A configuration pragma must appear in the context clause of a
5145 -- compilation unit, and only other pragmas may precede it. Note that
5146 -- the test below also permits use in a configuration pragma file.
5147
5148 function Is_Configuration_Pragma return Boolean is
5149 Lis : constant List_Id := List_Containing (N);
5150 Par : constant Node_Id := Parent (N);
5151 Prg : Node_Id;
5152
5153 begin
5154 -- If no parent, then we are in the configuration pragma file,
5155 -- so the placement is definitely appropriate.
5156
5157 if No (Par) then
5158 return True;
5159
5160 -- Otherwise we must be in the context clause of a compilation unit
5161 -- and the only thing allowed before us in the context list is more
5162 -- configuration pragmas.
5163
5164 elsif Nkind (Par) = N_Compilation_Unit
5165 and then Context_Items (Par) = Lis
5166 then
5167 Prg := First (Lis);
5168
5169 loop
5170 if Prg = N then
5171 return True;
5172 elsif Nkind (Prg) /= N_Pragma then
5173 return False;
5174 end if;
5175
5176 Next (Prg);
5177 end loop;
5178
5179 else
5180 return False;
5181 end if;
5182 end Is_Configuration_Pragma;
5183
5184 --------------------------
5185 -- Is_In_Context_Clause --
5186 --------------------------
5187
5188 function Is_In_Context_Clause return Boolean is
5189 Plist : List_Id;
5190 Parent_Node : Node_Id;
5191
5192 begin
5193 if not Is_List_Member (N) then
5194 return False;
5195
5196 else
5197 Plist := List_Containing (N);
5198 Parent_Node := Parent (Plist);
5199
5200 if Parent_Node = Empty
5201 or else Nkind (Parent_Node) /= N_Compilation_Unit
5202 or else Context_Items (Parent_Node) /= Plist
5203 then
5204 return False;
5205 end if;
5206 end if;
5207
5208 return True;
5209 end Is_In_Context_Clause;
5210
5211 ---------------------------------
5212 -- Is_Static_String_Expression --
5213 ---------------------------------
5214
5215 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
5216 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
5217
5218 begin
5219 Analyze_And_Resolve (Argx);
5220 return Is_OK_Static_Expression (Argx)
5221 and then Nkind (Argx) = N_String_Literal;
5222 end Is_Static_String_Expression;
5223
5224 ----------------------
5225 -- Pragma_Misplaced --
5226 ----------------------
5227
5228 procedure Pragma_Misplaced is
5229 begin
5230 Error_Pragma ("incorrect placement of pragma%");
5231 end Pragma_Misplaced;
5232
5233 ------------------------------------
5234 -- Process_Atomic_Shared_Volatile --
5235 ------------------------------------
5236
5237 procedure Process_Atomic_Shared_Volatile is
5238 E_Id : Node_Id;
5239 E : Entity_Id;
5240 D : Node_Id;
5241 K : Node_Kind;
5242 Utyp : Entity_Id;
5243
5244 procedure Set_Atomic (E : Entity_Id);
5245 -- Set given type as atomic, and if no explicit alignment was given,
5246 -- set alignment to unknown, since back end knows what the alignment
5247 -- requirements are for atomic arrays. Note: this step is necessary
5248 -- for derived types.
5249
5250 ----------------
5251 -- Set_Atomic --
5252 ----------------
5253
5254 procedure Set_Atomic (E : Entity_Id) is
5255 begin
5256 Set_Is_Atomic (E);
5257
5258 if not Has_Alignment_Clause (E) then
5259 Set_Alignment (E, Uint_0);
5260 end if;
5261 end Set_Atomic;
5262
5263 -- Start of processing for Process_Atomic_Shared_Volatile
5264
5265 begin
5266 Check_Ada_83_Warning;
5267 Check_No_Identifiers;
5268 Check_Arg_Count (1);
5269 Check_Arg_Is_Local_Name (Arg1);
5270 E_Id := Get_Pragma_Arg (Arg1);
5271
5272 if Etype (E_Id) = Any_Type then
5273 return;
5274 end if;
5275
5276 E := Entity (E_Id);
5277 D := Declaration_Node (E);
5278 K := Nkind (D);
5279
5280 -- Check duplicate before we chain ourselves!
5281
5282 Check_Duplicate_Pragma (E);
5283
5284 -- Now check appropriateness of the entity
5285
5286 if Is_Type (E) then
5287 if Rep_Item_Too_Early (E, N)
5288 or else
5289 Rep_Item_Too_Late (E, N)
5290 then
5291 return;
5292 else
5293 Check_First_Subtype (Arg1);
5294 end if;
5295
5296 if Prag_Id /= Pragma_Volatile then
5297 Set_Atomic (E);
5298 Set_Atomic (Underlying_Type (E));
5299 Set_Atomic (Base_Type (E));
5300 end if;
5301
5302 -- Attribute belongs on the base type. If the view of the type is
5303 -- currently private, it also belongs on the underlying type.
5304
5305 Set_Is_Volatile (Base_Type (E));
5306 Set_Is_Volatile (Underlying_Type (E));
5307
5308 Set_Treat_As_Volatile (E);
5309 Set_Treat_As_Volatile (Underlying_Type (E));
5310
5311 elsif K = N_Object_Declaration
5312 or else (K = N_Component_Declaration
5313 and then Original_Record_Component (E) = E)
5314 then
5315 if Rep_Item_Too_Late (E, N) then
5316 return;
5317 end if;
5318
5319 if Prag_Id /= Pragma_Volatile then
5320 Set_Is_Atomic (E);
5321
5322 -- If the object declaration has an explicit initialization, a
5323 -- temporary may have to be created to hold the expression, to
5324 -- ensure that access to the object remain atomic.
5325
5326 if Nkind (Parent (E)) = N_Object_Declaration
5327 and then Present (Expression (Parent (E)))
5328 then
5329 Set_Has_Delayed_Freeze (E);
5330 end if;
5331
5332 -- An interesting improvement here. If an object of composite
5333 -- type X is declared atomic, and the type X isn't, that's a
5334 -- pity, since it may not have appropriate alignment etc. We
5335 -- can rescue this in the special case where the object and
5336 -- type are in the same unit by just setting the type as
5337 -- atomic, so that the back end will process it as atomic.
5338
5339 -- Note: we used to do this for elementary types as well,
5340 -- but that turns out to be a bad idea and can have unwanted
5341 -- effects, most notably if the type is elementary, the object
5342 -- a simple component within a record, and both are in a spec:
5343 -- every object of this type in the entire program will be
5344 -- treated as atomic, thus incurring a potentially costly
5345 -- synchronization operation for every access.
5346
5347 -- Of course it would be best if the back end could just adjust
5348 -- the alignment etc for the specific object, but that's not
5349 -- something we are capable of doing at this point.
5350
5351 Utyp := Underlying_Type (Etype (E));
5352
5353 if Present (Utyp)
5354 and then Is_Composite_Type (Utyp)
5355 and then Sloc (E) > No_Location
5356 and then Sloc (Utyp) > No_Location
5357 and then
5358 Get_Source_File_Index (Sloc (E)) =
5359 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
5360 then
5361 Set_Is_Atomic (Underlying_Type (Etype (E)));
5362 end if;
5363 end if;
5364
5365 Set_Is_Volatile (E);
5366 Set_Treat_As_Volatile (E);
5367
5368 else
5369 Error_Pragma_Arg
5370 ("inappropriate entity for pragma%", Arg1);
5371 end if;
5372 end Process_Atomic_Shared_Volatile;
5373
5374 -------------------------------------------
5375 -- Process_Compile_Time_Warning_Or_Error --
5376 -------------------------------------------
5377
5378 procedure Process_Compile_Time_Warning_Or_Error is
5379 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
5380
5381 begin
5382 Check_Arg_Count (2);
5383 Check_No_Identifiers;
5384 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
5385 Analyze_And_Resolve (Arg1x, Standard_Boolean);
5386
5387 if Compile_Time_Known_Value (Arg1x) then
5388 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
5389 declare
5390 Str : constant String_Id :=
5391 Strval (Get_Pragma_Arg (Arg2));
5392 Len : constant Int := String_Length (Str);
5393 Cont : Boolean;
5394 Ptr : Nat;
5395 CC : Char_Code;
5396 C : Character;
5397 Cent : constant Entity_Id :=
5398 Cunit_Entity (Current_Sem_Unit);
5399
5400 Force : constant Boolean :=
5401 Prag_Id = Pragma_Compile_Time_Warning
5402 and then
5403 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
5404 and then (Ekind (Cent) /= E_Package
5405 or else not In_Private_Part (Cent));
5406 -- Set True if this is the warning case, and we are in the
5407 -- visible part of a package spec, or in a subprogram spec,
5408 -- in which case we want to force the client to see the
5409 -- warning, even though it is not in the main unit.
5410
5411 begin
5412 -- Loop through segments of message separated by line feeds.
5413 -- We output these segments as separate messages with
5414 -- continuation marks for all but the first.
5415
5416 Cont := False;
5417 Ptr := 1;
5418 loop
5419 Error_Msg_Strlen := 0;
5420
5421 -- Loop to copy characters from argument to error message
5422 -- string buffer.
5423
5424 loop
5425 exit when Ptr > Len;
5426 CC := Get_String_Char (Str, Ptr);
5427 Ptr := Ptr + 1;
5428
5429 -- Ignore wide chars ??? else store character
5430
5431 if In_Character_Range (CC) then
5432 C := Get_Character (CC);
5433 exit when C = ASCII.LF;
5434 Error_Msg_Strlen := Error_Msg_Strlen + 1;
5435 Error_Msg_String (Error_Msg_Strlen) := C;
5436 end if;
5437 end loop;
5438
5439 -- Here with one line ready to go
5440
5441 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
5442
5443 -- If this is a warning in a spec, then we want clients
5444 -- to see the warning, so mark the message with the
5445 -- special sequence !! to force the warning. In the case
5446 -- of a package spec, we do not force this if we are in
5447 -- the private part of the spec.
5448
5449 if Force then
5450 if Cont = False then
5451 Error_Msg_N ("<~!!", Arg1);
5452 Cont := True;
5453 else
5454 Error_Msg_N ("\<~!!", Arg1);
5455 end if;
5456
5457 -- Error, rather than warning, or in a body, so we do not
5458 -- need to force visibility for client (error will be
5459 -- output in any case, and this is the situation in which
5460 -- we do not want a client to get a warning, since the
5461 -- warning is in the body or the spec private part).
5462
5463 else
5464 if Cont = False then
5465 Error_Msg_N ("<~", Arg1);
5466 Cont := True;
5467 else
5468 Error_Msg_N ("\<~", Arg1);
5469 end if;
5470 end if;
5471
5472 exit when Ptr > Len;
5473 end loop;
5474 end;
5475 end if;
5476 end if;
5477 end Process_Compile_Time_Warning_Or_Error;
5478
5479 ------------------------
5480 -- Process_Convention --
5481 ------------------------
5482
5483 procedure Process_Convention
5484 (C : out Convention_Id;
5485 Ent : out Entity_Id)
5486 is
5487 Id : Node_Id;
5488 E : Entity_Id;
5489 E1 : Entity_Id;
5490 Cname : Name_Id;
5491 Comp_Unit : Unit_Number_Type;
5492
5493 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
5494 -- Called if we have more than one Export/Import/Convention pragma.
5495 -- This is generally illegal, but we have a special case of allowing
5496 -- Import and Interface to coexist if they specify the convention in
5497 -- a consistent manner. We are allowed to do this, since Interface is
5498 -- an implementation defined pragma, and we choose to do it since we
5499 -- know Rational allows this combination. S is the entity id of the
5500 -- subprogram in question. This procedure also sets the special flag
5501 -- Import_Interface_Present in both pragmas in the case where we do
5502 -- have matching Import and Interface pragmas.
5503
5504 procedure Set_Convention_From_Pragma (E : Entity_Id);
5505 -- Set convention in entity E, and also flag that the entity has a
5506 -- convention pragma. If entity is for a private or incomplete type,
5507 -- also set convention and flag on underlying type. This procedure
5508 -- also deals with the special case of C_Pass_By_Copy convention.
5509
5510 -------------------------------
5511 -- Diagnose_Multiple_Pragmas --
5512 -------------------------------
5513
5514 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
5515 Pdec : constant Node_Id := Declaration_Node (S);
5516 Decl : Node_Id;
5517 Err : Boolean;
5518
5519 function Same_Convention (Decl : Node_Id) return Boolean;
5520 -- Decl is a pragma node. This function returns True if this
5521 -- pragma has a first argument that is an identifier with a
5522 -- Chars field corresponding to the Convention_Id C.
5523
5524 function Same_Name (Decl : Node_Id) return Boolean;
5525 -- Decl is a pragma node. This function returns True if this
5526 -- pragma has a second argument that is an identifier with a
5527 -- Chars field that matches the Chars of the current subprogram.
5528
5529 ---------------------
5530 -- Same_Convention --
5531 ---------------------
5532
5533 function Same_Convention (Decl : Node_Id) return Boolean is
5534 Arg1 : constant Node_Id :=
5535 First (Pragma_Argument_Associations (Decl));
5536
5537 begin
5538 if Present (Arg1) then
5539 declare
5540 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
5541 begin
5542 if Nkind (Arg) = N_Identifier
5543 and then Is_Convention_Name (Chars (Arg))
5544 and then Get_Convention_Id (Chars (Arg)) = C
5545 then
5546 return True;
5547 end if;
5548 end;
5549 end if;
5550
5551 return False;
5552 end Same_Convention;
5553
5554 ---------------
5555 -- Same_Name --
5556 ---------------
5557
5558 function Same_Name (Decl : Node_Id) return Boolean is
5559 Arg1 : constant Node_Id :=
5560 First (Pragma_Argument_Associations (Decl));
5561 Arg2 : Node_Id;
5562
5563 begin
5564 if No (Arg1) then
5565 return False;
5566 end if;
5567
5568 Arg2 := Next (Arg1);
5569
5570 if No (Arg2) then
5571 return False;
5572 end if;
5573
5574 declare
5575 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
5576 begin
5577 if Nkind (Arg) = N_Identifier
5578 and then Chars (Arg) = Chars (S)
5579 then
5580 return True;
5581 end if;
5582 end;
5583
5584 return False;
5585 end Same_Name;
5586
5587 -- Start of processing for Diagnose_Multiple_Pragmas
5588
5589 begin
5590 Err := True;
5591
5592 -- Definitely give message if we have Convention/Export here
5593
5594 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
5595 null;
5596
5597 -- If we have an Import or Export, scan back from pragma to
5598 -- find any previous pragma applying to the same procedure.
5599 -- The scan will be terminated by the start of the list, or
5600 -- hitting the subprogram declaration. This won't allow one
5601 -- pragma to appear in the public part and one in the private
5602 -- part, but that seems very unlikely in practice.
5603
5604 else
5605 Decl := Prev (N);
5606 while Present (Decl) and then Decl /= Pdec loop
5607
5608 -- Look for pragma with same name as us
5609
5610 if Nkind (Decl) = N_Pragma
5611 and then Same_Name (Decl)
5612 then
5613 -- Give error if same as our pragma or Export/Convention
5614
5615 if Nam_In (Pragma_Name (Decl), Name_Export,
5616 Name_Convention,
5617 Pragma_Name (N))
5618 then
5619 exit;
5620
5621 -- Case of Import/Interface or the other way round
5622
5623 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
5624 Name_Import)
5625 then
5626 -- Here we know that we have Import and Interface. It
5627 -- doesn't matter which way round they are. See if
5628 -- they specify the same convention. If so, all OK,
5629 -- and set special flags to stop other messages
5630
5631 if Same_Convention (Decl) then
5632 Set_Import_Interface_Present (N);
5633 Set_Import_Interface_Present (Decl);
5634 Err := False;
5635
5636 -- If different conventions, special message
5637
5638 else
5639 Error_Msg_Sloc := Sloc (Decl);
5640 Error_Pragma_Arg
5641 ("convention differs from that given#", Arg1);
5642 return;
5643 end if;
5644 end if;
5645 end if;
5646
5647 Next (Decl);
5648 end loop;
5649 end if;
5650
5651 -- Give message if needed if we fall through those tests
5652 -- except on Relaxed_RM_Semantics where we let go: either this
5653 -- is a case accepted/ignored by other Ada compilers (e.g.
5654 -- a mix of Convention and Import), or another error will be
5655 -- generated later (e.g. using both Import and Export).
5656
5657 if Err and not Relaxed_RM_Semantics then
5658 Error_Pragma_Arg
5659 ("at most one Convention/Export/Import pragma is allowed",
5660 Arg2);
5661 end if;
5662 end Diagnose_Multiple_Pragmas;
5663
5664 --------------------------------
5665 -- Set_Convention_From_Pragma --
5666 --------------------------------
5667
5668 procedure Set_Convention_From_Pragma (E : Entity_Id) is
5669 begin
5670 -- Ada 2005 (AI-430): Check invalid attempt to change convention
5671 -- for an overridden dispatching operation. Technically this is
5672 -- an amendment and should only be done in Ada 2005 mode. However,
5673 -- this is clearly a mistake, since the problem that is addressed
5674 -- by this AI is that there is a clear gap in the RM!
5675
5676 if Is_Dispatching_Operation (E)
5677 and then Present (Overridden_Operation (E))
5678 and then C /= Convention (Overridden_Operation (E))
5679 then
5680 -- An attempt to override a subprogram with a ghost subprogram
5681 -- appears as a mismatch in conventions.
5682
5683 if C = Convention_Ghost then
5684 Error_Msg_N ("ghost subprogram & cannot be overriding", E);
5685 else
5686 Error_Pragma_Arg
5687 ("cannot change convention for overridden dispatching "
5688 & "operation", Arg1);
5689 end if;
5690 end if;
5691
5692 -- Special checks for Convention_Stdcall
5693
5694 if C = Convention_Stdcall then
5695
5696 -- A dispatching call is not allowed. A dispatching subprogram
5697 -- cannot be used to interface to the Win32 API, so in fact
5698 -- this check does not impose any effective restriction.
5699
5700 if Is_Dispatching_Operation (E) then
5701 Error_Msg_Sloc := Sloc (E);
5702
5703 -- Note: make this unconditional so that if there is more
5704 -- than one call to which the pragma applies, we get a
5705 -- message for each call. Also don't use Error_Pragma,
5706 -- so that we get multiple messages!
5707
5708 Error_Msg_N
5709 ("dispatching subprogram# cannot use Stdcall convention!",
5710 Arg1);
5711
5712 -- Subprogram is allowed, but not a generic subprogram
5713
5714 elsif not Is_Subprogram (E)
5715 and then not Is_Generic_Subprogram (E)
5716
5717 -- A variable is OK
5718
5719 and then Ekind (E) /= E_Variable
5720
5721 -- An access to subprogram is also allowed
5722
5723 and then not
5724 (Is_Access_Type (E)
5725 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
5726
5727 -- Allow internal call to set convention of subprogram type
5728
5729 and then not (Ekind (E) = E_Subprogram_Type)
5730 then
5731 Error_Pragma_Arg
5732 ("second argument of pragma% must be subprogram (type)",
5733 Arg2);
5734 end if;
5735 end if;
5736
5737 -- Set the convention
5738
5739 Set_Convention (E, C);
5740 Set_Has_Convention_Pragma (E);
5741
5742 if Is_Incomplete_Or_Private_Type (E)
5743 and then Present (Underlying_Type (E))
5744 then
5745 Set_Convention (Underlying_Type (E), C);
5746 Set_Has_Convention_Pragma (Underlying_Type (E), True);
5747 end if;
5748
5749 -- A class-wide type should inherit the convention of the specific
5750 -- root type (although this isn't specified clearly by the RM).
5751
5752 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
5753 Set_Convention (Class_Wide_Type (E), C);
5754 end if;
5755
5756 -- If the entity is a record type, then check for special case of
5757 -- C_Pass_By_Copy, which is treated the same as C except that the
5758 -- special record flag is set. This convention is only permitted
5759 -- on record types (see AI95-00131).
5760
5761 if Cname = Name_C_Pass_By_Copy then
5762 if Is_Record_Type (E) then
5763 Set_C_Pass_By_Copy (Base_Type (E));
5764 elsif Is_Incomplete_Or_Private_Type (E)
5765 and then Is_Record_Type (Underlying_Type (E))
5766 then
5767 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
5768 else
5769 Error_Pragma_Arg
5770 ("C_Pass_By_Copy convention allowed only for record type",
5771 Arg2);
5772 end if;
5773 end if;
5774
5775 -- If the entity is a derived boolean type, check for the special
5776 -- case of convention C, C++, or Fortran, where we consider any
5777 -- nonzero value to represent true.
5778
5779 if Is_Discrete_Type (E)
5780 and then Root_Type (Etype (E)) = Standard_Boolean
5781 and then
5782 (C = Convention_C
5783 or else
5784 C = Convention_CPP
5785 or else
5786 C = Convention_Fortran)
5787 then
5788 Set_Nonzero_Is_True (Base_Type (E));
5789 end if;
5790 end Set_Convention_From_Pragma;
5791
5792 -- Start of processing for Process_Convention
5793
5794 begin
5795 Check_At_Least_N_Arguments (2);
5796 Check_Optional_Identifier (Arg1, Name_Convention);
5797 Check_Arg_Is_Identifier (Arg1);
5798 Cname := Chars (Get_Pragma_Arg (Arg1));
5799
5800 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
5801 -- tested again below to set the critical flag).
5802
5803 if Cname = Name_C_Pass_By_Copy then
5804 C := Convention_C;
5805
5806 -- Otherwise we must have something in the standard convention list
5807
5808 elsif Is_Convention_Name (Cname) then
5809 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
5810
5811 -- In DEC VMS, it seems that there is an undocumented feature that
5812 -- any unrecognized convention is treated as the default, which for
5813 -- us is convention C. It does not seem so terrible to do this
5814 -- unconditionally, silently in the VMS case, and with a warning
5815 -- in the non-VMS case.
5816
5817 else
5818 if Warn_On_Export_Import and not OpenVMS_On_Target then
5819 Error_Msg_N
5820 ("??unrecognized convention name, C assumed",
5821 Get_Pragma_Arg (Arg1));
5822 end if;
5823
5824 C := Convention_C;
5825 end if;
5826
5827 Check_Optional_Identifier (Arg2, Name_Entity);
5828 Check_Arg_Is_Local_Name (Arg2);
5829
5830 Id := Get_Pragma_Arg (Arg2);
5831 Analyze (Id);
5832
5833 if not Is_Entity_Name (Id) then
5834 Error_Pragma_Arg ("entity name required", Arg2);
5835 end if;
5836
5837 E := Entity (Id);
5838
5839 -- Set entity to return
5840
5841 Ent := E;
5842
5843 -- Ada_Pass_By_Copy special checking
5844
5845 if C = Convention_Ada_Pass_By_Copy then
5846 if not Is_First_Subtype (E) then
5847 Error_Pragma_Arg
5848 ("convention `Ada_Pass_By_Copy` only allowed for types",
5849 Arg2);
5850 end if;
5851
5852 if Is_By_Reference_Type (E) then
5853 Error_Pragma_Arg
5854 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
5855 & "type", Arg1);
5856 end if;
5857 end if;
5858
5859 -- Ada_Pass_By_Reference special checking
5860
5861 if C = Convention_Ada_Pass_By_Reference then
5862 if not Is_First_Subtype (E) then
5863 Error_Pragma_Arg
5864 ("convention `Ada_Pass_By_Reference` only allowed for types",
5865 Arg2);
5866 end if;
5867
5868 if Is_By_Copy_Type (E) then
5869 Error_Pragma_Arg
5870 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
5871 & "type", Arg1);
5872 end if;
5873 end if;
5874
5875 -- Ghost special checking
5876
5877 if Is_Ghost_Subprogram (E)
5878 and then Present (Overridden_Operation (E))
5879 then
5880 Error_Msg_N ("ghost subprogram & cannot be overriding", E);
5881 end if;
5882
5883 -- Go to renamed subprogram if present, since convention applies to
5884 -- the actual renamed entity, not to the renaming entity. If the
5885 -- subprogram is inherited, go to parent subprogram.
5886
5887 if Is_Subprogram (E)
5888 and then Present (Alias (E))
5889 then
5890 if Nkind (Parent (Declaration_Node (E))) =
5891 N_Subprogram_Renaming_Declaration
5892 then
5893 if Scope (E) /= Scope (Alias (E)) then
5894 Error_Pragma_Ref
5895 ("cannot apply pragma% to non-local entity&#", E);
5896 end if;
5897
5898 E := Alias (E);
5899
5900 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
5901 N_Private_Extension_Declaration)
5902 and then Scope (E) = Scope (Alias (E))
5903 then
5904 E := Alias (E);
5905
5906 -- Return the parent subprogram the entity was inherited from
5907
5908 Ent := E;
5909 end if;
5910 end if;
5911
5912 -- Check that we are not applying this to a specless body
5913 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
5914 -- compilers.
5915
5916 if Is_Subprogram (E)
5917 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
5918 and then not Relaxed_RM_Semantics
5919 then
5920 Error_Pragma
5921 ("pragma% requires separate spec and must come before body");
5922 end if;
5923
5924 -- Check that we are not applying this to a named constant
5925
5926 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
5927 Error_Msg_Name_1 := Pname;
5928 Error_Msg_N
5929 ("cannot apply pragma% to named constant!",
5930 Get_Pragma_Arg (Arg2));
5931 Error_Pragma_Arg
5932 ("\supply appropriate type for&!", Arg2);
5933 end if;
5934
5935 if Ekind (E) = E_Enumeration_Literal then
5936 Error_Pragma ("enumeration literal not allowed for pragma%");
5937 end if;
5938
5939 -- Check for rep item appearing too early or too late
5940
5941 if Etype (E) = Any_Type
5942 or else Rep_Item_Too_Early (E, N)
5943 then
5944 raise Pragma_Exit;
5945
5946 elsif Present (Underlying_Type (E)) then
5947 E := Underlying_Type (E);
5948 end if;
5949
5950 if Rep_Item_Too_Late (E, N) then
5951 raise Pragma_Exit;
5952 end if;
5953
5954 if Has_Convention_Pragma (E) then
5955 Diagnose_Multiple_Pragmas (E);
5956
5957 elsif Convention (E) = Convention_Protected
5958 or else Ekind (Scope (E)) = E_Protected_Type
5959 then
5960 Error_Pragma_Arg
5961 ("a protected operation cannot be given a different convention",
5962 Arg2);
5963 end if;
5964
5965 -- For Intrinsic, a subprogram is required
5966
5967 if C = Convention_Intrinsic
5968 and then not Is_Subprogram (E)
5969 and then not Is_Generic_Subprogram (E)
5970 then
5971 Error_Pragma_Arg
5972 ("second argument of pragma% must be a subprogram", Arg2);
5973 end if;
5974
5975 -- Deal with non-subprogram cases
5976
5977 if not Is_Subprogram (E)
5978 and then not Is_Generic_Subprogram (E)
5979 then
5980 Set_Convention_From_Pragma (E);
5981
5982 if Is_Type (E) then
5983 Check_First_Subtype (Arg2);
5984 Set_Convention_From_Pragma (Base_Type (E));
5985
5986 -- For access subprograms, we must set the convention on the
5987 -- internally generated directly designated type as well.
5988
5989 if Ekind (E) = E_Access_Subprogram_Type then
5990 Set_Convention_From_Pragma (Directly_Designated_Type (E));
5991 end if;
5992 end if;
5993
5994 -- For the subprogram case, set proper convention for all homonyms
5995 -- in same scope and the same declarative part, i.e. the same
5996 -- compilation unit.
5997
5998 else
5999 Comp_Unit := Get_Source_Unit (E);
6000 Set_Convention_From_Pragma (E);
6001
6002 -- Treat a pragma Import as an implicit body, and pragma import
6003 -- as implicit reference (for navigation in GPS).
6004
6005 if Prag_Id = Pragma_Import then
6006 Generate_Reference (E, Id, 'b');
6007
6008 -- For exported entities we restrict the generation of references
6009 -- to entities exported to foreign languages since entities
6010 -- exported to Ada do not provide further information to GPS and
6011 -- add undesired references to the output of the gnatxref tool.
6012
6013 elsif Prag_Id = Pragma_Export
6014 and then Convention (E) /= Convention_Ada
6015 then
6016 Generate_Reference (E, Id, 'i');
6017 end if;
6018
6019 -- If the pragma comes from from an aspect, it only applies to the
6020 -- given entity, not its homonyms.
6021
6022 if From_Aspect_Specification (N) then
6023 return;
6024 end if;
6025
6026 -- Otherwise Loop through the homonyms of the pragma argument's
6027 -- entity, an apply convention to those in the current scope.
6028
6029 E1 := Ent;
6030
6031 loop
6032 E1 := Homonym (E1);
6033 exit when No (E1) or else Scope (E1) /= Current_Scope;
6034
6035 -- Ignore entry for which convention is already set
6036
6037 if Has_Convention_Pragma (E1) then
6038 goto Continue;
6039 end if;
6040
6041 -- Do not set the pragma on inherited operations or on formal
6042 -- subprograms.
6043
6044 if Comes_From_Source (E1)
6045 and then Comp_Unit = Get_Source_Unit (E1)
6046 and then not Is_Formal_Subprogram (E1)
6047 and then Nkind (Original_Node (Parent (E1))) /=
6048 N_Full_Type_Declaration
6049 then
6050 if Present (Alias (E1))
6051 and then Scope (E1) /= Scope (Alias (E1))
6052 then
6053 Error_Pragma_Ref
6054 ("cannot apply pragma% to non-local entity& declared#",
6055 E1);
6056 end if;
6057
6058 Set_Convention_From_Pragma (E1);
6059
6060 if Prag_Id = Pragma_Import then
6061 Generate_Reference (E1, Id, 'b');
6062 end if;
6063 end if;
6064
6065 <<Continue>>
6066 null;
6067 end loop;
6068 end if;
6069 end Process_Convention;
6070
6071 ----------------------------------------
6072 -- Process_Disable_Enable_Atomic_Sync --
6073 ----------------------------------------
6074
6075 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
6076 begin
6077 Check_No_Identifiers;
6078 Check_At_Most_N_Arguments (1);
6079
6080 -- Modeled internally as
6081 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
6082
6083 Rewrite (N,
6084 Make_Pragma (Loc,
6085 Pragma_Identifier =>
6086 Make_Identifier (Loc, Nam),
6087 Pragma_Argument_Associations => New_List (
6088 Make_Pragma_Argument_Association (Loc,
6089 Expression =>
6090 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
6091
6092 if Present (Arg1) then
6093 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
6094 end if;
6095
6096 Analyze (N);
6097 end Process_Disable_Enable_Atomic_Sync;
6098
6099 -----------------------------------------------------
6100 -- Process_Extended_Import_Export_Exception_Pragma --
6101 -----------------------------------------------------
6102
6103 procedure Process_Extended_Import_Export_Exception_Pragma
6104 (Arg_Internal : Node_Id;
6105 Arg_External : Node_Id;
6106 Arg_Form : Node_Id;
6107 Arg_Code : Node_Id)
6108 is
6109 Def_Id : Entity_Id;
6110 Code_Val : Uint;
6111
6112 begin
6113 if not OpenVMS_On_Target then
6114 Error_Pragma
6115 ("??pragma% ignored (applies only to Open'V'M'S)");
6116 end if;
6117
6118 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6119 Def_Id := Entity (Arg_Internal);
6120
6121 if Ekind (Def_Id) /= E_Exception then
6122 Error_Pragma_Arg
6123 ("pragma% must refer to declared exception", Arg_Internal);
6124 end if;
6125
6126 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
6127
6128 if Present (Arg_Form) then
6129 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
6130 end if;
6131
6132 if Present (Arg_Form)
6133 and then Chars (Arg_Form) = Name_Ada
6134 then
6135 null;
6136 else
6137 Set_Is_VMS_Exception (Def_Id);
6138 Set_Exception_Code (Def_Id, No_Uint);
6139 end if;
6140
6141 if Present (Arg_Code) then
6142 if not Is_VMS_Exception (Def_Id) then
6143 Error_Pragma_Arg
6144 ("Code option for pragma% not allowed for Ada case",
6145 Arg_Code);
6146 end if;
6147
6148 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
6149 Code_Val := Expr_Value (Arg_Code);
6150
6151 if not UI_Is_In_Int_Range (Code_Val) then
6152 Error_Pragma_Arg
6153 ("Code option for pragma% must be in 32-bit range",
6154 Arg_Code);
6155
6156 else
6157 Set_Exception_Code (Def_Id, Code_Val);
6158 end if;
6159 end if;
6160 end Process_Extended_Import_Export_Exception_Pragma;
6161
6162 -------------------------------------------------
6163 -- Process_Extended_Import_Export_Internal_Arg --
6164 -------------------------------------------------
6165
6166 procedure Process_Extended_Import_Export_Internal_Arg
6167 (Arg_Internal : Node_Id := Empty)
6168 is
6169 begin
6170 if No (Arg_Internal) then
6171 Error_Pragma ("Internal parameter required for pragma%");
6172 end if;
6173
6174 if Nkind (Arg_Internal) = N_Identifier then
6175 null;
6176
6177 elsif Nkind (Arg_Internal) = N_Operator_Symbol
6178 and then (Prag_Id = Pragma_Import_Function
6179 or else
6180 Prag_Id = Pragma_Export_Function)
6181 then
6182 null;
6183
6184 else
6185 Error_Pragma_Arg
6186 ("wrong form for Internal parameter for pragma%", Arg_Internal);
6187 end if;
6188
6189 Check_Arg_Is_Local_Name (Arg_Internal);
6190 end Process_Extended_Import_Export_Internal_Arg;
6191
6192 --------------------------------------------------
6193 -- Process_Extended_Import_Export_Object_Pragma --
6194 --------------------------------------------------
6195
6196 procedure Process_Extended_Import_Export_Object_Pragma
6197 (Arg_Internal : Node_Id;
6198 Arg_External : Node_Id;
6199 Arg_Size : Node_Id)
6200 is
6201 Def_Id : Entity_Id;
6202
6203 begin
6204 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6205 Def_Id := Entity (Arg_Internal);
6206
6207 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
6208 Error_Pragma_Arg
6209 ("pragma% must designate an object", Arg_Internal);
6210 end if;
6211
6212 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
6213 or else
6214 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
6215 then
6216 Error_Pragma_Arg
6217 ("previous Common/Psect_Object applies, pragma % not permitted",
6218 Arg_Internal);
6219 end if;
6220
6221 if Rep_Item_Too_Late (Def_Id, N) then
6222 raise Pragma_Exit;
6223 end if;
6224
6225 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
6226
6227 if Present (Arg_Size) then
6228 Check_Arg_Is_External_Name (Arg_Size);
6229 end if;
6230
6231 -- Export_Object case
6232
6233 if Prag_Id = Pragma_Export_Object then
6234 if not Is_Library_Level_Entity (Def_Id) then
6235 Error_Pragma_Arg
6236 ("argument for pragma% must be library level entity",
6237 Arg_Internal);
6238 end if;
6239
6240 if Ekind (Current_Scope) = E_Generic_Package then
6241 Error_Pragma ("pragma& cannot appear in a generic unit");
6242 end if;
6243
6244 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
6245 Error_Pragma_Arg
6246 ("exported object must have compile time known size",
6247 Arg_Internal);
6248 end if;
6249
6250 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
6251 Error_Msg_N ("??duplicate Export_Object pragma", N);
6252 else
6253 Set_Exported (Def_Id, Arg_Internal);
6254 end if;
6255
6256 -- Import_Object case
6257
6258 else
6259 if Is_Concurrent_Type (Etype (Def_Id)) then
6260 Error_Pragma_Arg
6261 ("cannot use pragma% for task/protected object",
6262 Arg_Internal);
6263 end if;
6264
6265 if Ekind (Def_Id) = E_Constant then
6266 Error_Pragma_Arg
6267 ("cannot import a constant", Arg_Internal);
6268 end if;
6269
6270 if Warn_On_Export_Import
6271 and then Has_Discriminants (Etype (Def_Id))
6272 then
6273 Error_Msg_N
6274 ("imported value must be initialized??", Arg_Internal);
6275 end if;
6276
6277 if Warn_On_Export_Import
6278 and then Is_Access_Type (Etype (Def_Id))
6279 then
6280 Error_Pragma_Arg
6281 ("cannot import object of an access type??", Arg_Internal);
6282 end if;
6283
6284 if Warn_On_Export_Import
6285 and then Is_Imported (Def_Id)
6286 then
6287 Error_Msg_N ("??duplicate Import_Object pragma", N);
6288
6289 -- Check for explicit initialization present. Note that an
6290 -- initialization generated by the code generator, e.g. for an
6291 -- access type, does not count here.
6292
6293 elsif Present (Expression (Parent (Def_Id)))
6294 and then
6295 Comes_From_Source
6296 (Original_Node (Expression (Parent (Def_Id))))
6297 then
6298 Error_Msg_Sloc := Sloc (Def_Id);
6299 Error_Pragma_Arg
6300 ("imported entities cannot be initialized (RM B.1(24))",
6301 "\no initialization allowed for & declared#", Arg1);
6302 else
6303 Set_Imported (Def_Id);
6304 Note_Possible_Modification (Arg_Internal, Sure => False);
6305 end if;
6306 end if;
6307 end Process_Extended_Import_Export_Object_Pragma;
6308
6309 ------------------------------------------------------
6310 -- Process_Extended_Import_Export_Subprogram_Pragma --
6311 ------------------------------------------------------
6312
6313 procedure Process_Extended_Import_Export_Subprogram_Pragma
6314 (Arg_Internal : Node_Id;
6315 Arg_External : Node_Id;
6316 Arg_Parameter_Types : Node_Id;
6317 Arg_Result_Type : Node_Id := Empty;
6318 Arg_Mechanism : Node_Id;
6319 Arg_Result_Mechanism : Node_Id := Empty;
6320 Arg_First_Optional_Parameter : Node_Id := Empty)
6321 is
6322 Ent : Entity_Id;
6323 Def_Id : Entity_Id;
6324 Hom_Id : Entity_Id;
6325 Formal : Entity_Id;
6326 Ambiguous : Boolean;
6327 Match : Boolean;
6328 Dval : Node_Id;
6329
6330 function Same_Base_Type
6331 (Ptype : Node_Id;
6332 Formal : Entity_Id) return Boolean;
6333 -- Determines if Ptype references the type of Formal. Note that only
6334 -- the base types need to match according to the spec. Ptype here is
6335 -- the argument from the pragma, which is either a type name, or an
6336 -- access attribute.
6337
6338 --------------------
6339 -- Same_Base_Type --
6340 --------------------
6341
6342 function Same_Base_Type
6343 (Ptype : Node_Id;
6344 Formal : Entity_Id) return Boolean
6345 is
6346 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
6347 Pref : Node_Id;
6348
6349 begin
6350 -- Case where pragma argument is typ'Access
6351
6352 if Nkind (Ptype) = N_Attribute_Reference
6353 and then Attribute_Name (Ptype) = Name_Access
6354 then
6355 Pref := Prefix (Ptype);
6356 Find_Type (Pref);
6357
6358 if not Is_Entity_Name (Pref)
6359 or else Entity (Pref) = Any_Type
6360 then
6361 raise Pragma_Exit;
6362 end if;
6363
6364 -- We have a match if the corresponding argument is of an
6365 -- anonymous access type, and its designated type matches the
6366 -- type of the prefix of the access attribute
6367
6368 return Ekind (Ftyp) = E_Anonymous_Access_Type
6369 and then Base_Type (Entity (Pref)) =
6370 Base_Type (Etype (Designated_Type (Ftyp)));
6371
6372 -- Case where pragma argument is a type name
6373
6374 else
6375 Find_Type (Ptype);
6376
6377 if not Is_Entity_Name (Ptype)
6378 or else Entity (Ptype) = Any_Type
6379 then
6380 raise Pragma_Exit;
6381 end if;
6382
6383 -- We have a match if the corresponding argument is of the type
6384 -- given in the pragma (comparing base types)
6385
6386 return Base_Type (Entity (Ptype)) = Ftyp;
6387 end if;
6388 end Same_Base_Type;
6389
6390 -- Start of processing for
6391 -- Process_Extended_Import_Export_Subprogram_Pragma
6392
6393 begin
6394 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
6395 Ent := Empty;
6396 Ambiguous := False;
6397
6398 -- Loop through homonyms (overloadings) of the entity
6399
6400 Hom_Id := Entity (Arg_Internal);
6401 while Present (Hom_Id) loop
6402 Def_Id := Get_Base_Subprogram (Hom_Id);
6403
6404 -- We need a subprogram in the current scope
6405
6406 if not Is_Subprogram (Def_Id)
6407 or else Scope (Def_Id) /= Current_Scope
6408 then
6409 null;
6410
6411 else
6412 Match := True;
6413
6414 -- Pragma cannot apply to subprogram body
6415
6416 if Is_Subprogram (Def_Id)
6417 and then Nkind (Parent (Declaration_Node (Def_Id))) =
6418 N_Subprogram_Body
6419 then
6420 Error_Pragma
6421 ("pragma% requires separate spec"
6422 & " and must come before body");
6423 end if;
6424
6425 -- Test result type if given, note that the result type
6426 -- parameter can only be present for the function cases.
6427
6428 if Present (Arg_Result_Type)
6429 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
6430 then
6431 Match := False;
6432
6433 elsif Etype (Def_Id) /= Standard_Void_Type
6434 and then
6435 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
6436 then
6437 Match := False;
6438
6439 -- Test parameter types if given. Note that this parameter
6440 -- has not been analyzed (and must not be, since it is
6441 -- semantic nonsense), so we get it as the parser left it.
6442
6443 elsif Present (Arg_Parameter_Types) then
6444 Check_Matching_Types : declare
6445 Formal : Entity_Id;
6446 Ptype : Node_Id;
6447
6448 begin
6449 Formal := First_Formal (Def_Id);
6450
6451 if Nkind (Arg_Parameter_Types) = N_Null then
6452 if Present (Formal) then
6453 Match := False;
6454 end if;
6455
6456 -- A list of one type, e.g. (List) is parsed as
6457 -- a parenthesized expression.
6458
6459 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
6460 and then Paren_Count (Arg_Parameter_Types) = 1
6461 then
6462 if No (Formal)
6463 or else Present (Next_Formal (Formal))
6464 then
6465 Match := False;
6466 else
6467 Match :=
6468 Same_Base_Type (Arg_Parameter_Types, Formal);
6469 end if;
6470
6471 -- A list of more than one type is parsed as a aggregate
6472
6473 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
6474 and then Paren_Count (Arg_Parameter_Types) = 0
6475 then
6476 Ptype := First (Expressions (Arg_Parameter_Types));
6477 while Present (Ptype) or else Present (Formal) loop
6478 if No (Ptype)
6479 or else No (Formal)
6480 or else not Same_Base_Type (Ptype, Formal)
6481 then
6482 Match := False;
6483 exit;
6484 else
6485 Next_Formal (Formal);
6486 Next (Ptype);
6487 end if;
6488 end loop;
6489
6490 -- Anything else is of the wrong form
6491
6492 else
6493 Error_Pragma_Arg
6494 ("wrong form for Parameter_Types parameter",
6495 Arg_Parameter_Types);
6496 end if;
6497 end Check_Matching_Types;
6498 end if;
6499
6500 -- Match is now False if the entry we found did not match
6501 -- either a supplied Parameter_Types or Result_Types argument
6502
6503 if Match then
6504 if No (Ent) then
6505 Ent := Def_Id;
6506
6507 -- Ambiguous case, the flag Ambiguous shows if we already
6508 -- detected this and output the initial messages.
6509
6510 else
6511 if not Ambiguous then
6512 Ambiguous := True;
6513 Error_Msg_Name_1 := Pname;
6514 Error_Msg_N
6515 ("pragma% does not uniquely identify subprogram!",
6516 N);
6517 Error_Msg_Sloc := Sloc (Ent);
6518 Error_Msg_N ("matching subprogram #!", N);
6519 Ent := Empty;
6520 end if;
6521
6522 Error_Msg_Sloc := Sloc (Def_Id);
6523 Error_Msg_N ("matching subprogram #!", N);
6524 end if;
6525 end if;
6526 end if;
6527
6528 Hom_Id := Homonym (Hom_Id);
6529 end loop;
6530
6531 -- See if we found an entry
6532
6533 if No (Ent) then
6534 if not Ambiguous then
6535 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
6536 Error_Pragma
6537 ("pragma% cannot be given for generic subprogram");
6538 else
6539 Error_Pragma
6540 ("pragma% does not identify local subprogram");
6541 end if;
6542 end if;
6543
6544 return;
6545 end if;
6546
6547 -- Import pragmas must be for imported entities
6548
6549 if Prag_Id = Pragma_Import_Function
6550 or else
6551 Prag_Id = Pragma_Import_Procedure
6552 or else
6553 Prag_Id = Pragma_Import_Valued_Procedure
6554 then
6555 if not Is_Imported (Ent) then
6556 Error_Pragma
6557 ("pragma Import or Interface must precede pragma%");
6558 end if;
6559
6560 -- Here we have the Export case which can set the entity as exported
6561
6562 -- But does not do so if the specified external name is null, since
6563 -- that is taken as a signal in DEC Ada 83 (with which we want to be
6564 -- compatible) to request no external name.
6565
6566 elsif Nkind (Arg_External) = N_String_Literal
6567 and then String_Length (Strval (Arg_External)) = 0
6568 then
6569 null;
6570
6571 -- In all other cases, set entity as exported
6572
6573 else
6574 Set_Exported (Ent, Arg_Internal);
6575 end if;
6576
6577 -- Special processing for Valued_Procedure cases
6578
6579 if Prag_Id = Pragma_Import_Valued_Procedure
6580 or else
6581 Prag_Id = Pragma_Export_Valued_Procedure
6582 then
6583 Formal := First_Formal (Ent);
6584
6585 if No (Formal) then
6586 Error_Pragma ("at least one parameter required for pragma%");
6587
6588 elsif Ekind (Formal) /= E_Out_Parameter then
6589 Error_Pragma ("first parameter must have mode out for pragma%");
6590
6591 else
6592 Set_Is_Valued_Procedure (Ent);
6593 end if;
6594 end if;
6595
6596 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
6597
6598 -- Process Result_Mechanism argument if present. We have already
6599 -- checked that this is only allowed for the function case.
6600
6601 if Present (Arg_Result_Mechanism) then
6602 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
6603 end if;
6604
6605 -- Process Mechanism parameter if present. Note that this parameter
6606 -- is not analyzed, and must not be analyzed since it is semantic
6607 -- nonsense, so we get it in exactly as the parser left it.
6608
6609 if Present (Arg_Mechanism) then
6610 declare
6611 Formal : Entity_Id;
6612 Massoc : Node_Id;
6613 Mname : Node_Id;
6614 Choice : Node_Id;
6615
6616 begin
6617 -- A single mechanism association without a formal parameter
6618 -- name is parsed as a parenthesized expression. All other
6619 -- cases are parsed as aggregates, so we rewrite the single
6620 -- parameter case as an aggregate for consistency.
6621
6622 if Nkind (Arg_Mechanism) /= N_Aggregate
6623 and then Paren_Count (Arg_Mechanism) = 1
6624 then
6625 Rewrite (Arg_Mechanism,
6626 Make_Aggregate (Sloc (Arg_Mechanism),
6627 Expressions => New_List (
6628 Relocate_Node (Arg_Mechanism))));
6629 end if;
6630
6631 -- Case of only mechanism name given, applies to all formals
6632
6633 if Nkind (Arg_Mechanism) /= N_Aggregate then
6634 Formal := First_Formal (Ent);
6635 while Present (Formal) loop
6636 Set_Mechanism_Value (Formal, Arg_Mechanism);
6637 Next_Formal (Formal);
6638 end loop;
6639
6640 -- Case of list of mechanism associations given
6641
6642 else
6643 if Null_Record_Present (Arg_Mechanism) then
6644 Error_Pragma_Arg
6645 ("inappropriate form for Mechanism parameter",
6646 Arg_Mechanism);
6647 end if;
6648
6649 -- Deal with positional ones first
6650
6651 Formal := First_Formal (Ent);
6652
6653 if Present (Expressions (Arg_Mechanism)) then
6654 Mname := First (Expressions (Arg_Mechanism));
6655 while Present (Mname) loop
6656 if No (Formal) then
6657 Error_Pragma_Arg
6658 ("too many mechanism associations", Mname);
6659 end if;
6660
6661 Set_Mechanism_Value (Formal, Mname);
6662 Next_Formal (Formal);
6663 Next (Mname);
6664 end loop;
6665 end if;
6666
6667 -- Deal with named entries
6668
6669 if Present (Component_Associations (Arg_Mechanism)) then
6670 Massoc := First (Component_Associations (Arg_Mechanism));
6671 while Present (Massoc) loop
6672 Choice := First (Choices (Massoc));
6673
6674 if Nkind (Choice) /= N_Identifier
6675 or else Present (Next (Choice))
6676 then
6677 Error_Pragma_Arg
6678 ("incorrect form for mechanism association",
6679 Massoc);
6680 end if;
6681
6682 Formal := First_Formal (Ent);
6683 loop
6684 if No (Formal) then
6685 Error_Pragma_Arg
6686 ("parameter name & not present", Choice);
6687 end if;
6688
6689 if Chars (Choice) = Chars (Formal) then
6690 Set_Mechanism_Value
6691 (Formal, Expression (Massoc));
6692
6693 -- Set entity on identifier (needed by ASIS)
6694
6695 Set_Entity (Choice, Formal);
6696
6697 exit;
6698 end if;
6699
6700 Next_Formal (Formal);
6701 end loop;
6702
6703 Next (Massoc);
6704 end loop;
6705 end if;
6706 end if;
6707 end;
6708 end if;
6709
6710 -- Process First_Optional_Parameter argument if present. We have
6711 -- already checked that this is only allowed for the Import case.
6712
6713 if Present (Arg_First_Optional_Parameter) then
6714 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
6715 Error_Pragma_Arg
6716 ("first optional parameter must be formal parameter name",
6717 Arg_First_Optional_Parameter);
6718 end if;
6719
6720 Formal := First_Formal (Ent);
6721 loop
6722 if No (Formal) then
6723 Error_Pragma_Arg
6724 ("specified formal parameter& not found",
6725 Arg_First_Optional_Parameter);
6726 end if;
6727
6728 exit when Chars (Formal) =
6729 Chars (Arg_First_Optional_Parameter);
6730
6731 Next_Formal (Formal);
6732 end loop;
6733
6734 Set_First_Optional_Parameter (Ent, Formal);
6735
6736 -- Check specified and all remaining formals have right form
6737
6738 while Present (Formal) loop
6739 if Ekind (Formal) /= E_In_Parameter then
6740 Error_Msg_NE
6741 ("optional formal& is not of mode in!",
6742 Arg_First_Optional_Parameter, Formal);
6743
6744 else
6745 Dval := Default_Value (Formal);
6746
6747 if No (Dval) then
6748 Error_Msg_NE
6749 ("optional formal& does not have default value!",
6750 Arg_First_Optional_Parameter, Formal);
6751
6752 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
6753 null;
6754
6755 else
6756 Error_Msg_FE
6757 ("default value for optional formal& is non-static!",
6758 Arg_First_Optional_Parameter, Formal);
6759 end if;
6760 end if;
6761
6762 Set_Is_Optional_Parameter (Formal);
6763 Next_Formal (Formal);
6764 end loop;
6765 end if;
6766 end Process_Extended_Import_Export_Subprogram_Pragma;
6767
6768 --------------------------
6769 -- Process_Generic_List --
6770 --------------------------
6771
6772 procedure Process_Generic_List is
6773 Arg : Node_Id;
6774 Exp : Node_Id;
6775
6776 begin
6777 Check_No_Identifiers;
6778 Check_At_Least_N_Arguments (1);
6779
6780 -- Check all arguments are names of generic units or instances
6781
6782 Arg := Arg1;
6783 while Present (Arg) loop
6784 Exp := Get_Pragma_Arg (Arg);
6785 Analyze (Exp);
6786
6787 if not Is_Entity_Name (Exp)
6788 or else
6789 (not Is_Generic_Instance (Entity (Exp))
6790 and then
6791 not Is_Generic_Unit (Entity (Exp)))
6792 then
6793 Error_Pragma_Arg
6794 ("pragma% argument must be name of generic unit/instance",
6795 Arg);
6796 end if;
6797
6798 Next (Arg);
6799 end loop;
6800 end Process_Generic_List;
6801
6802 ------------------------------------
6803 -- Process_Import_Predefined_Type --
6804 ------------------------------------
6805
6806 procedure Process_Import_Predefined_Type is
6807 Loc : constant Source_Ptr := Sloc (N);
6808 Elmt : Elmt_Id;
6809 Ftyp : Node_Id := Empty;
6810 Decl : Node_Id;
6811 Def : Node_Id;
6812 Nam : Name_Id;
6813
6814 begin
6815 String_To_Name_Buffer (Strval (Expression (Arg3)));
6816 Nam := Name_Find;
6817
6818 Elmt := First_Elmt (Predefined_Float_Types);
6819 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
6820 Next_Elmt (Elmt);
6821 end loop;
6822
6823 Ftyp := Node (Elmt);
6824
6825 if Present (Ftyp) then
6826
6827 -- Don't build a derived type declaration, because predefined C
6828 -- types have no declaration anywhere, so cannot really be named.
6829 -- Instead build a full type declaration, starting with an
6830 -- appropriate type definition is built
6831
6832 if Is_Floating_Point_Type (Ftyp) then
6833 Def := Make_Floating_Point_Definition (Loc,
6834 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
6835 Make_Real_Range_Specification (Loc,
6836 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
6837 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
6838
6839 -- Should never have a predefined type we cannot handle
6840
6841 else
6842 raise Program_Error;
6843 end if;
6844
6845 -- Build and insert a Full_Type_Declaration, which will be
6846 -- analyzed as soon as this list entry has been analyzed.
6847
6848 Decl := Make_Full_Type_Declaration (Loc,
6849 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
6850 Type_Definition => Def);
6851
6852 Insert_After (N, Decl);
6853 Mark_Rewrite_Insertion (Decl);
6854
6855 else
6856 Error_Pragma_Arg ("no matching type found for pragma%",
6857 Arg2);
6858 end if;
6859 end Process_Import_Predefined_Type;
6860
6861 ---------------------------------
6862 -- Process_Import_Or_Interface --
6863 ---------------------------------
6864
6865 procedure Process_Import_Or_Interface is
6866 C : Convention_Id;
6867 Def_Id : Entity_Id;
6868 Hom_Id : Entity_Id;
6869
6870 begin
6871 Process_Convention (C, Def_Id);
6872 Kill_Size_Check_Code (Def_Id);
6873 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
6874
6875 if Ekind_In (Def_Id, E_Variable, E_Constant) then
6876
6877 -- We do not permit Import to apply to a renaming declaration
6878
6879 if Present (Renamed_Object (Def_Id)) then
6880 Error_Pragma_Arg
6881 ("pragma% not allowed for object renaming", Arg2);
6882
6883 -- User initialization is not allowed for imported object, but
6884 -- the object declaration may contain a default initialization,
6885 -- that will be discarded. Note that an explicit initialization
6886 -- only counts if it comes from source, otherwise it is simply
6887 -- the code generator making an implicit initialization explicit.
6888
6889 elsif Present (Expression (Parent (Def_Id)))
6890 and then Comes_From_Source (Expression (Parent (Def_Id)))
6891 then
6892 Error_Msg_Sloc := Sloc (Def_Id);
6893 Error_Pragma_Arg
6894 ("no initialization allowed for declaration of& #",
6895 "\imported entities cannot be initialized (RM B.1(24))",
6896 Arg2);
6897
6898 else
6899 Set_Imported (Def_Id);
6900 Process_Interface_Name (Def_Id, Arg3, Arg4);
6901
6902 -- Note that we do not set Is_Public here. That's because we
6903 -- only want to set it if there is no address clause, and we
6904 -- don't know that yet, so we delay that processing till
6905 -- freeze time.
6906
6907 -- pragma Import completes deferred constants
6908
6909 if Ekind (Def_Id) = E_Constant then
6910 Set_Has_Completion (Def_Id);
6911 end if;
6912
6913 -- It is not possible to import a constant of an unconstrained
6914 -- array type (e.g. string) because there is no simple way to
6915 -- write a meaningful subtype for it.
6916
6917 if Is_Array_Type (Etype (Def_Id))
6918 and then not Is_Constrained (Etype (Def_Id))
6919 then
6920 Error_Msg_NE
6921 ("imported constant& must have a constrained subtype",
6922 N, Def_Id);
6923 end if;
6924 end if;
6925
6926 elsif Is_Subprogram (Def_Id)
6927 or else Is_Generic_Subprogram (Def_Id)
6928 then
6929 -- If the name is overloaded, pragma applies to all of the denoted
6930 -- entities in the same declarative part, unless the pragma comes
6931 -- from an aspect specification.
6932
6933 Hom_Id := Def_Id;
6934 while Present (Hom_Id) loop
6935
6936 Def_Id := Get_Base_Subprogram (Hom_Id);
6937
6938 -- Ignore inherited subprograms because the pragma will apply
6939 -- to the parent operation, which is the one called.
6940
6941 if Is_Overloadable (Def_Id)
6942 and then Present (Alias (Def_Id))
6943 then
6944 null;
6945
6946 -- If it is not a subprogram, it must be in an outer scope and
6947 -- pragma does not apply.
6948
6949 elsif not Is_Subprogram (Def_Id)
6950 and then not Is_Generic_Subprogram (Def_Id)
6951 then
6952 null;
6953
6954 -- The pragma does not apply to primitives of interfaces
6955
6956 elsif Is_Dispatching_Operation (Def_Id)
6957 and then Present (Find_Dispatching_Type (Def_Id))
6958 and then Is_Interface (Find_Dispatching_Type (Def_Id))
6959 then
6960 null;
6961
6962 -- Verify that the homonym is in the same declarative part (not
6963 -- just the same scope). If the pragma comes from an aspect
6964 -- specification we know that it is part of the declaration.
6965
6966 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
6967 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
6968 and then not From_Aspect_Specification (N)
6969 then
6970 exit;
6971
6972 else
6973 Set_Imported (Def_Id);
6974
6975 -- Reject an Import applied to an abstract subprogram
6976
6977 if Is_Subprogram (Def_Id)
6978 and then Is_Abstract_Subprogram (Def_Id)
6979 then
6980 Error_Msg_Sloc := Sloc (Def_Id);
6981 Error_Msg_NE
6982 ("cannot import abstract subprogram& declared#",
6983 Arg2, Def_Id);
6984 end if;
6985
6986 -- Special processing for Convention_Intrinsic
6987
6988 if C = Convention_Intrinsic then
6989
6990 -- Link_Name argument not allowed for intrinsic
6991
6992 Check_No_Link_Name;
6993
6994 Set_Is_Intrinsic_Subprogram (Def_Id);
6995
6996 -- If no external name is present, then check that this
6997 -- is a valid intrinsic subprogram. If an external name
6998 -- is present, then this is handled by the back end.
6999
7000 if No (Arg3) then
7001 Check_Intrinsic_Subprogram
7002 (Def_Id, Get_Pragma_Arg (Arg2));
7003 end if;
7004 end if;
7005
7006 -- All interfaced procedures need an external symbol created
7007 -- for them since they are always referenced from another
7008 -- object file.
7009
7010 Set_Is_Public (Def_Id);
7011
7012 -- Verify that the subprogram does not have a completion
7013 -- through a renaming declaration. For other completions the
7014 -- pragma appears as a too late representation.
7015
7016 declare
7017 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
7018
7019 begin
7020 if Present (Decl)
7021 and then Nkind (Decl) = N_Subprogram_Declaration
7022 and then Present (Corresponding_Body (Decl))
7023 and then Nkind (Unit_Declaration_Node
7024 (Corresponding_Body (Decl))) =
7025 N_Subprogram_Renaming_Declaration
7026 then
7027 Error_Msg_Sloc := Sloc (Def_Id);
7028 Error_Msg_NE
7029 ("cannot import&, renaming already provided for "
7030 & "declaration #", N, Def_Id);
7031 end if;
7032 end;
7033
7034 Set_Has_Completion (Def_Id);
7035 Process_Interface_Name (Def_Id, Arg3, Arg4);
7036 end if;
7037
7038 if Is_Compilation_Unit (Hom_Id) then
7039
7040 -- Its possible homonyms are not affected by the pragma.
7041 -- Such homonyms might be present in the context of other
7042 -- units being compiled.
7043
7044 exit;
7045
7046 elsif From_Aspect_Specification (N) then
7047 exit;
7048
7049 else
7050 Hom_Id := Homonym (Hom_Id);
7051 end if;
7052 end loop;
7053
7054 -- When the convention is Java or CIL, we also allow Import to
7055 -- be given for packages, generic packages, exceptions, record
7056 -- components, and access to subprograms.
7057
7058 elsif (C = Convention_Java or else C = Convention_CIL)
7059 and then
7060 (Is_Package_Or_Generic_Package (Def_Id)
7061 or else Ekind (Def_Id) = E_Exception
7062 or else Ekind (Def_Id) = E_Access_Subprogram_Type
7063 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
7064 then
7065 Set_Imported (Def_Id);
7066 Set_Is_Public (Def_Id);
7067 Process_Interface_Name (Def_Id, Arg3, Arg4);
7068
7069 -- Import a CPP class
7070
7071 elsif C = Convention_CPP
7072 and then (Is_Record_Type (Def_Id)
7073 or else Ekind (Def_Id) = E_Incomplete_Type)
7074 then
7075 if Ekind (Def_Id) = E_Incomplete_Type then
7076 if Present (Full_View (Def_Id)) then
7077 Def_Id := Full_View (Def_Id);
7078
7079 else
7080 Error_Msg_N
7081 ("cannot import 'C'P'P type before full declaration seen",
7082 Get_Pragma_Arg (Arg2));
7083
7084 -- Although we have reported the error we decorate it as
7085 -- CPP_Class to avoid reporting spurious errors
7086
7087 Set_Is_CPP_Class (Def_Id);
7088 return;
7089 end if;
7090 end if;
7091
7092 -- Types treated as CPP classes must be declared limited (note:
7093 -- this used to be a warning but there is no real benefit to it
7094 -- since we did effectively intend to treat the type as limited
7095 -- anyway).
7096
7097 if not Is_Limited_Type (Def_Id) then
7098 Error_Msg_N
7099 ("imported 'C'P'P type must be limited",
7100 Get_Pragma_Arg (Arg2));
7101 end if;
7102
7103 if Etype (Def_Id) /= Def_Id
7104 and then not Is_CPP_Class (Root_Type (Def_Id))
7105 then
7106 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
7107 end if;
7108
7109 Set_Is_CPP_Class (Def_Id);
7110
7111 -- Imported CPP types must not have discriminants (because C++
7112 -- classes do not have discriminants).
7113
7114 if Has_Discriminants (Def_Id) then
7115 Error_Msg_N
7116 ("imported 'C'P'P type cannot have discriminants",
7117 First (Discriminant_Specifications
7118 (Declaration_Node (Def_Id))));
7119 end if;
7120
7121 -- Check that components of imported CPP types do not have default
7122 -- expressions. For private types this check is performed when the
7123 -- full view is analyzed (see Process_Full_View).
7124
7125 if not Is_Private_Type (Def_Id) then
7126 Check_CPP_Type_Has_No_Defaults (Def_Id);
7127 end if;
7128
7129 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
7130 Check_No_Link_Name;
7131 Check_Arg_Count (3);
7132 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7133
7134 Process_Import_Predefined_Type;
7135
7136 else
7137 Error_Pragma_Arg
7138 ("second argument of pragma% must be object, subprogram "
7139 & "or incomplete type",
7140 Arg2);
7141 end if;
7142
7143 -- If this pragma applies to a compilation unit, then the unit, which
7144 -- is a subprogram, does not require (or allow) a body. We also do
7145 -- not need to elaborate imported procedures.
7146
7147 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
7148 declare
7149 Cunit : constant Node_Id := Parent (Parent (N));
7150 begin
7151 Set_Body_Required (Cunit, False);
7152 end;
7153 end if;
7154 end Process_Import_Or_Interface;
7155
7156 --------------------
7157 -- Process_Inline --
7158 --------------------
7159
7160 procedure Process_Inline (Status : Inline_Status) is
7161 Assoc : Node_Id;
7162 Decl : Node_Id;
7163 Subp_Id : Node_Id;
7164 Subp : Entity_Id;
7165 Applies : Boolean;
7166
7167 Effective : Boolean := False;
7168 -- Set True if inline has some effect, i.e. if there is at least one
7169 -- subprogram set as inlined as a result of the use of the pragma.
7170
7171 procedure Make_Inline (Subp : Entity_Id);
7172 -- Subp is the defining unit name of the subprogram declaration. Set
7173 -- the flag, as well as the flag in the corresponding body, if there
7174 -- is one present.
7175
7176 procedure Set_Inline_Flags (Subp : Entity_Id);
7177 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
7178 -- Has_Pragma_Inline_Always for the Inline_Always case.
7179
7180 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
7181 -- Returns True if it can be determined at this stage that inlining
7182 -- is not possible, for example if the body is available and contains
7183 -- exception handlers, we prevent inlining, since otherwise we can
7184 -- get undefined symbols at link time. This function also emits a
7185 -- warning if front-end inlining is enabled and the pragma appears
7186 -- too late.
7187 --
7188 -- ??? is business with link symbols still valid, or does it relate
7189 -- to front end ZCX which is being phased out ???
7190
7191 ---------------------------
7192 -- Inlining_Not_Possible --
7193 ---------------------------
7194
7195 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
7196 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
7197 Stats : Node_Id;
7198
7199 begin
7200 if Nkind (Decl) = N_Subprogram_Body then
7201 Stats := Handled_Statement_Sequence (Decl);
7202 return Present (Exception_Handlers (Stats))
7203 or else Present (At_End_Proc (Stats));
7204
7205 elsif Nkind (Decl) = N_Subprogram_Declaration
7206 and then Present (Corresponding_Body (Decl))
7207 then
7208 if Front_End_Inlining
7209 and then Analyzed (Corresponding_Body (Decl))
7210 then
7211 Error_Msg_N ("pragma appears too late, ignored??", N);
7212 return True;
7213
7214 -- If the subprogram is a renaming as body, the body is just a
7215 -- call to the renamed subprogram, and inlining is trivially
7216 -- possible.
7217
7218 elsif
7219 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
7220 N_Subprogram_Renaming_Declaration
7221 then
7222 return False;
7223
7224 else
7225 Stats :=
7226 Handled_Statement_Sequence
7227 (Unit_Declaration_Node (Corresponding_Body (Decl)));
7228
7229 return
7230 Present (Exception_Handlers (Stats))
7231 or else Present (At_End_Proc (Stats));
7232 end if;
7233
7234 else
7235 -- If body is not available, assume the best, the check is
7236 -- performed again when compiling enclosing package bodies.
7237
7238 return False;
7239 end if;
7240 end Inlining_Not_Possible;
7241
7242 -----------------
7243 -- Make_Inline --
7244 -----------------
7245
7246 procedure Make_Inline (Subp : Entity_Id) is
7247 Kind : constant Entity_Kind := Ekind (Subp);
7248 Inner_Subp : Entity_Id := Subp;
7249
7250 begin
7251 -- Ignore if bad type, avoid cascaded error
7252
7253 if Etype (Subp) = Any_Type then
7254 Applies := True;
7255 return;
7256
7257 -- Ignore if all inlining is suppressed
7258
7259 elsif Suppress_All_Inlining then
7260 Applies := True;
7261 return;
7262
7263 -- If inlining is not possible, for now do not treat as an error
7264
7265 elsif Status /= Suppressed
7266 and then Inlining_Not_Possible (Subp)
7267 then
7268 Applies := True;
7269 return;
7270
7271 -- Here we have a candidate for inlining, but we must exclude
7272 -- derived operations. Otherwise we would end up trying to inline
7273 -- a phantom declaration, and the result would be to drag in a
7274 -- body which has no direct inlining associated with it. That
7275 -- would not only be inefficient but would also result in the
7276 -- backend doing cross-unit inlining in cases where it was
7277 -- definitely inappropriate to do so.
7278
7279 -- However, a simple Comes_From_Source test is insufficient, since
7280 -- we do want to allow inlining of generic instances which also do
7281 -- not come from source. We also need to recognize specs generated
7282 -- by the front-end for bodies that carry the pragma. Finally,
7283 -- predefined operators do not come from source but are not
7284 -- inlineable either.
7285
7286 elsif Is_Generic_Instance (Subp)
7287 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
7288 then
7289 null;
7290
7291 elsif not Comes_From_Source (Subp)
7292 and then Scope (Subp) /= Standard_Standard
7293 then
7294 Applies := True;
7295 return;
7296 end if;
7297
7298 -- The referenced entity must either be the enclosing entity, or
7299 -- an entity declared within the current open scope.
7300
7301 if Present (Scope (Subp))
7302 and then Scope (Subp) /= Current_Scope
7303 and then Subp /= Current_Scope
7304 then
7305 Error_Pragma_Arg
7306 ("argument of% must be entity in current scope", Assoc);
7307 return;
7308 end if;
7309
7310 -- Processing for procedure, operator or function. If subprogram
7311 -- is aliased (as for an instance) indicate that the renamed
7312 -- entity (if declared in the same unit) is inlined.
7313
7314 if Is_Subprogram (Subp) then
7315 Inner_Subp := Ultimate_Alias (Inner_Subp);
7316
7317 if In_Same_Source_Unit (Subp, Inner_Subp) then
7318 Set_Inline_Flags (Inner_Subp);
7319
7320 Decl := Parent (Parent (Inner_Subp));
7321
7322 if Nkind (Decl) = N_Subprogram_Declaration
7323 and then Present (Corresponding_Body (Decl))
7324 then
7325 Set_Inline_Flags (Corresponding_Body (Decl));
7326
7327 elsif Is_Generic_Instance (Subp) then
7328
7329 -- Indicate that the body needs to be created for
7330 -- inlining subsequent calls. The instantiation node
7331 -- follows the declaration of the wrapper package
7332 -- created for it.
7333
7334 if Scope (Subp) /= Standard_Standard
7335 and then
7336 Need_Subprogram_Instance_Body
7337 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
7338 Subp)
7339 then
7340 null;
7341 end if;
7342
7343 -- Inline is a program unit pragma (RM 10.1.5) and cannot
7344 -- appear in a formal part to apply to a formal subprogram.
7345 -- Do not apply check within an instance or a formal package
7346 -- the test will have been applied to the original generic.
7347
7348 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
7349 and then List_Containing (Decl) = List_Containing (N)
7350 and then not In_Instance
7351 then
7352 Error_Msg_N
7353 ("Inline cannot apply to a formal subprogram", N);
7354
7355 -- If Subp is a renaming, it is the renamed entity that
7356 -- will appear in any call, and be inlined. However, for
7357 -- ASIS uses it is convenient to indicate that the renaming
7358 -- itself is an inlined subprogram, so that some gnatcheck
7359 -- rules can be applied in the absence of expansion.
7360
7361 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
7362 Set_Inline_Flags (Subp);
7363 end if;
7364 end if;
7365
7366 Applies := True;
7367
7368 -- For a generic subprogram set flag as well, for use at the point
7369 -- of instantiation, to determine whether the body should be
7370 -- generated.
7371
7372 elsif Is_Generic_Subprogram (Subp) then
7373 Set_Inline_Flags (Subp);
7374 Applies := True;
7375
7376 -- Literals are by definition inlined
7377
7378 elsif Kind = E_Enumeration_Literal then
7379 null;
7380
7381 -- Anything else is an error
7382
7383 else
7384 Error_Pragma_Arg
7385 ("expect subprogram name for pragma%", Assoc);
7386 end if;
7387 end Make_Inline;
7388
7389 ----------------------
7390 -- Set_Inline_Flags --
7391 ----------------------
7392
7393 procedure Set_Inline_Flags (Subp : Entity_Id) is
7394 begin
7395 -- First set the Has_Pragma_XXX flags and issue the appropriate
7396 -- errors and warnings for suspicious combinations.
7397
7398 if Prag_Id = Pragma_No_Inline then
7399 if Has_Pragma_Inline_Always (Subp) then
7400 Error_Msg_N
7401 ("Inline_Always and No_Inline are mutually exclusive", N);
7402 elsif Has_Pragma_Inline (Subp) then
7403 Error_Msg_NE
7404 ("Inline and No_Inline both specified for& ??",
7405 N, Entity (Subp_Id));
7406 end if;
7407
7408 Set_Has_Pragma_No_Inline (Subp);
7409 else
7410 if Prag_Id = Pragma_Inline_Always then
7411 if Has_Pragma_No_Inline (Subp) then
7412 Error_Msg_N
7413 ("Inline_Always and No_Inline are mutually exclusive",
7414 N);
7415 end if;
7416
7417 Set_Has_Pragma_Inline_Always (Subp);
7418 else
7419 if Has_Pragma_No_Inline (Subp) then
7420 Error_Msg_NE
7421 ("Inline and No_Inline both specified for& ??",
7422 N, Entity (Subp_Id));
7423 end if;
7424 end if;
7425
7426 if not Has_Pragma_Inline (Subp) then
7427 Set_Has_Pragma_Inline (Subp);
7428 Effective := True;
7429 end if;
7430 end if;
7431
7432 -- Then adjust the Is_Inlined flag. It can never be set if the
7433 -- subprogram is subject to pragma No_Inline.
7434
7435 case Status is
7436 when Suppressed =>
7437 Set_Is_Inlined (Subp, False);
7438 when Disabled =>
7439 null;
7440 when Enabled =>
7441 if not Has_Pragma_No_Inline (Subp) then
7442 Set_Is_Inlined (Subp, True);
7443 end if;
7444 end case;
7445 end Set_Inline_Flags;
7446
7447 -- Start of processing for Process_Inline
7448
7449 begin
7450 Check_No_Identifiers;
7451 Check_At_Least_N_Arguments (1);
7452
7453 if Status = Enabled then
7454 Inline_Processing_Required := True;
7455 end if;
7456
7457 Assoc := Arg1;
7458 while Present (Assoc) loop
7459 Subp_Id := Get_Pragma_Arg (Assoc);
7460 Analyze (Subp_Id);
7461 Applies := False;
7462
7463 if Is_Entity_Name (Subp_Id) then
7464 Subp := Entity (Subp_Id);
7465
7466 if Subp = Any_Id then
7467
7468 -- If previous error, avoid cascaded errors
7469
7470 Check_Error_Detected;
7471 Applies := True;
7472 Effective := True;
7473
7474 else
7475 Make_Inline (Subp);
7476
7477 -- For the pragma case, climb homonym chain. This is
7478 -- what implements allowing the pragma in the renaming
7479 -- case, with the result applying to the ancestors, and
7480 -- also allows Inline to apply to all previous homonyms.
7481
7482 if not From_Aspect_Specification (N) then
7483 while Present (Homonym (Subp))
7484 and then Scope (Homonym (Subp)) = Current_Scope
7485 loop
7486 Make_Inline (Homonym (Subp));
7487 Subp := Homonym (Subp);
7488 end loop;
7489 end if;
7490 end if;
7491 end if;
7492
7493 if not Applies then
7494 Error_Pragma_Arg
7495 ("inappropriate argument for pragma%", Assoc);
7496
7497 elsif not Effective
7498 and then Warn_On_Redundant_Constructs
7499 and then not (Status = Suppressed or else Suppress_All_Inlining)
7500 then
7501 if Inlining_Not_Possible (Subp) then
7502 Error_Msg_NE
7503 ("pragma Inline for& is ignored?r?",
7504 N, Entity (Subp_Id));
7505 else
7506 Error_Msg_NE
7507 ("pragma Inline for& is redundant?r?",
7508 N, Entity (Subp_Id));
7509 end if;
7510 end if;
7511
7512 Next (Assoc);
7513 end loop;
7514 end Process_Inline;
7515
7516 ----------------------------
7517 -- Process_Interface_Name --
7518 ----------------------------
7519
7520 procedure Process_Interface_Name
7521 (Subprogram_Def : Entity_Id;
7522 Ext_Arg : Node_Id;
7523 Link_Arg : Node_Id)
7524 is
7525 Ext_Nam : Node_Id;
7526 Link_Nam : Node_Id;
7527 String_Val : String_Id;
7528
7529 procedure Check_Form_Of_Interface_Name
7530 (SN : Node_Id;
7531 Ext_Name_Case : Boolean);
7532 -- SN is a string literal node for an interface name. This routine
7533 -- performs some minimal checks that the name is reasonable. In
7534 -- particular that no spaces or other obviously incorrect characters
7535 -- appear. This is only a warning, since any characters are allowed.
7536 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
7537
7538 ----------------------------------
7539 -- Check_Form_Of_Interface_Name --
7540 ----------------------------------
7541
7542 procedure Check_Form_Of_Interface_Name
7543 (SN : Node_Id;
7544 Ext_Name_Case : Boolean)
7545 is
7546 S : constant String_Id := Strval (Expr_Value_S (SN));
7547 SL : constant Nat := String_Length (S);
7548 C : Char_Code;
7549
7550 begin
7551 if SL = 0 then
7552 Error_Msg_N ("interface name cannot be null string", SN);
7553 end if;
7554
7555 for J in 1 .. SL loop
7556 C := Get_String_Char (S, J);
7557
7558 -- Look for dubious character and issue unconditional warning.
7559 -- Definitely dubious if not in character range.
7560
7561 if not In_Character_Range (C)
7562
7563 -- For all cases except CLI target,
7564 -- commas, spaces and slashes are dubious (in CLI, we use
7565 -- commas and backslashes in external names to specify
7566 -- assembly version and public key, while slashes and spaces
7567 -- can be used in names to mark nested classes and
7568 -- valuetypes).
7569
7570 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
7571 and then (Get_Character (C) = ','
7572 or else
7573 Get_Character (C) = '\'))
7574 or else (VM_Target /= CLI_Target
7575 and then (Get_Character (C) = ' '
7576 or else
7577 Get_Character (C) = '/'))
7578 then
7579 Error_Msg
7580 ("??interface name contains illegal character",
7581 Sloc (SN) + Source_Ptr (J));
7582 end if;
7583 end loop;
7584 end Check_Form_Of_Interface_Name;
7585
7586 -- Start of processing for Process_Interface_Name
7587
7588 begin
7589 if No (Link_Arg) then
7590 if No (Ext_Arg) then
7591 if VM_Target = CLI_Target
7592 and then Ekind (Subprogram_Def) = E_Package
7593 and then Nkind (Parent (Subprogram_Def)) =
7594 N_Package_Specification
7595 and then Present (Generic_Parent (Parent (Subprogram_Def)))
7596 then
7597 Set_Interface_Name
7598 (Subprogram_Def,
7599 Interface_Name
7600 (Generic_Parent (Parent (Subprogram_Def))));
7601 end if;
7602
7603 return;
7604
7605 elsif Chars (Ext_Arg) = Name_Link_Name then
7606 Ext_Nam := Empty;
7607 Link_Nam := Expression (Ext_Arg);
7608
7609 else
7610 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
7611 Ext_Nam := Expression (Ext_Arg);
7612 Link_Nam := Empty;
7613 end if;
7614
7615 else
7616 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
7617 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
7618 Ext_Nam := Expression (Ext_Arg);
7619 Link_Nam := Expression (Link_Arg);
7620 end if;
7621
7622 -- Check expressions for external name and link name are static
7623
7624 if Present (Ext_Nam) then
7625 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
7626 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
7627
7628 -- Verify that external name is not the name of a local entity,
7629 -- which would hide the imported one and could lead to run-time
7630 -- surprises. The problem can only arise for entities declared in
7631 -- a package body (otherwise the external name is fully qualified
7632 -- and will not conflict).
7633
7634 declare
7635 Nam : Name_Id;
7636 E : Entity_Id;
7637 Par : Node_Id;
7638
7639 begin
7640 if Prag_Id = Pragma_Import then
7641 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
7642 Nam := Name_Find;
7643 E := Entity_Id (Get_Name_Table_Info (Nam));
7644
7645 if Nam /= Chars (Subprogram_Def)
7646 and then Present (E)
7647 and then not Is_Overloadable (E)
7648 and then Is_Immediately_Visible (E)
7649 and then not Is_Imported (E)
7650 and then Ekind (Scope (E)) = E_Package
7651 then
7652 Par := Parent (E);
7653 while Present (Par) loop
7654 if Nkind (Par) = N_Package_Body then
7655 Error_Msg_Sloc := Sloc (E);
7656 Error_Msg_NE
7657 ("imported entity is hidden by & declared#",
7658 Ext_Arg, E);
7659 exit;
7660 end if;
7661
7662 Par := Parent (Par);
7663 end loop;
7664 end if;
7665 end if;
7666 end;
7667 end if;
7668
7669 if Present (Link_Nam) then
7670 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
7671 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
7672 end if;
7673
7674 -- If there is no link name, just set the external name
7675
7676 if No (Link_Nam) then
7677 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
7678
7679 -- For the Link_Name case, the given literal is preceded by an
7680 -- asterisk, which indicates to GCC that the given name should be
7681 -- taken literally, and in particular that no prepending of
7682 -- underlines should occur, even in systems where this is the
7683 -- normal default.
7684
7685 else
7686 Start_String;
7687
7688 if VM_Target = No_VM then
7689 Store_String_Char (Get_Char_Code ('*'));
7690 end if;
7691
7692 String_Val := Strval (Expr_Value_S (Link_Nam));
7693 Store_String_Chars (String_Val);
7694 Link_Nam :=
7695 Make_String_Literal (Sloc (Link_Nam),
7696 Strval => End_String);
7697 end if;
7698
7699 -- Set the interface name. If the entity is a generic instance, use
7700 -- its alias, which is the callable entity.
7701
7702 if Is_Generic_Instance (Subprogram_Def) then
7703 Set_Encoded_Interface_Name
7704 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
7705 else
7706 Set_Encoded_Interface_Name
7707 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
7708 end if;
7709
7710 -- We allow duplicated export names in CIL/Java, as they are always
7711 -- enclosed in a namespace that differentiates them, and overloaded
7712 -- entities are supported by the VM.
7713
7714 if Convention (Subprogram_Def) /= Convention_CIL
7715 and then
7716 Convention (Subprogram_Def) /= Convention_Java
7717 then
7718 Check_Duplicated_Export_Name (Link_Nam);
7719 end if;
7720 end Process_Interface_Name;
7721
7722 -----------------------------------------
7723 -- Process_Interrupt_Or_Attach_Handler --
7724 -----------------------------------------
7725
7726 procedure Process_Interrupt_Or_Attach_Handler is
7727 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
7728 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
7729 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
7730
7731 begin
7732 Set_Is_Interrupt_Handler (Handler_Proc);
7733
7734 -- If the pragma is not associated with a handler procedure within a
7735 -- protected type, then it must be for a nonprotected procedure for
7736 -- the AAMP target, in which case we don't associate a representation
7737 -- item with the procedure's scope.
7738
7739 if Ekind (Proc_Scope) = E_Protected_Type then
7740 if Prag_Id = Pragma_Interrupt_Handler
7741 or else
7742 Prag_Id = Pragma_Attach_Handler
7743 then
7744 Record_Rep_Item (Proc_Scope, N);
7745 end if;
7746 end if;
7747 end Process_Interrupt_Or_Attach_Handler;
7748
7749 --------------------------------------------------
7750 -- Process_Restrictions_Or_Restriction_Warnings --
7751 --------------------------------------------------
7752
7753 -- Note: some of the simple identifier cases were handled in par-prag,
7754 -- but it is harmless (and more straightforward) to simply handle all
7755 -- cases here, even if it means we repeat a bit of work in some cases.
7756
7757 procedure Process_Restrictions_Or_Restriction_Warnings
7758 (Warn : Boolean)
7759 is
7760 Arg : Node_Id;
7761 R_Id : Restriction_Id;
7762 Id : Name_Id;
7763 Expr : Node_Id;
7764 Val : Uint;
7765
7766 begin
7767 -- Ignore all Restrictions pragmas in CodePeer mode
7768
7769 if CodePeer_Mode then
7770 return;
7771 end if;
7772
7773 Check_Ada_83_Warning;
7774 Check_At_Least_N_Arguments (1);
7775 Check_Valid_Configuration_Pragma;
7776
7777 Arg := Arg1;
7778 while Present (Arg) loop
7779 Id := Chars (Arg);
7780 Expr := Get_Pragma_Arg (Arg);
7781
7782 -- Case of no restriction identifier present
7783
7784 if Id = No_Name then
7785 if Nkind (Expr) /= N_Identifier then
7786 Error_Pragma_Arg
7787 ("invalid form for restriction", Arg);
7788 end if;
7789
7790 R_Id :=
7791 Get_Restriction_Id
7792 (Process_Restriction_Synonyms (Expr));
7793
7794 if R_Id not in All_Boolean_Restrictions then
7795 Error_Msg_Name_1 := Pname;
7796 Error_Msg_N
7797 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
7798
7799 -- Check for possible misspelling
7800
7801 for J in Restriction_Id loop
7802 declare
7803 Rnm : constant String := Restriction_Id'Image (J);
7804
7805 begin
7806 Name_Buffer (1 .. Rnm'Length) := Rnm;
7807 Name_Len := Rnm'Length;
7808 Set_Casing (All_Lower_Case);
7809
7810 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
7811 Set_Casing
7812 (Identifier_Casing (Current_Source_File));
7813 Error_Msg_String (1 .. Rnm'Length) :=
7814 Name_Buffer (1 .. Name_Len);
7815 Error_Msg_Strlen := Rnm'Length;
7816 Error_Msg_N -- CODEFIX
7817 ("\possible misspelling of ""~""",
7818 Get_Pragma_Arg (Arg));
7819 exit;
7820 end if;
7821 end;
7822 end loop;
7823
7824 raise Pragma_Exit;
7825 end if;
7826
7827 if Implementation_Restriction (R_Id) then
7828 Check_Restriction (No_Implementation_Restrictions, Arg);
7829 end if;
7830
7831 -- Special processing for No_Elaboration_Code restriction
7832
7833 if R_Id = No_Elaboration_Code then
7834
7835 -- Restriction is only recognized within a configuration
7836 -- pragma file, or within a unit of the main extended
7837 -- program. Note: the test for Main_Unit is needed to
7838 -- properly include the case of configuration pragma files.
7839
7840 if not (Current_Sem_Unit = Main_Unit
7841 or else In_Extended_Main_Source_Unit (N))
7842 then
7843 return;
7844
7845 -- Don't allow in a subunit unless already specified in
7846 -- body or spec.
7847
7848 elsif Nkind (Parent (N)) = N_Compilation_Unit
7849 and then Nkind (Unit (Parent (N))) = N_Subunit
7850 and then not Restriction_Active (No_Elaboration_Code)
7851 then
7852 Error_Msg_N
7853 ("invalid specification of ""No_Elaboration_Code""",
7854 N);
7855 Error_Msg_N
7856 ("\restriction cannot be specified in a subunit", N);
7857 Error_Msg_N
7858 ("\unless also specified in body or spec", N);
7859 return;
7860
7861 -- If we have a No_Elaboration_Code pragma that we
7862 -- accept, then it needs to be added to the configuration
7863 -- restrcition set so that we get proper application to
7864 -- other units in the main extended source as required.
7865
7866 else
7867 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
7868 end if;
7869 end if;
7870
7871 -- If this is a warning, then set the warning unless we already
7872 -- have a real restriction active (we never want a warning to
7873 -- override a real restriction).
7874
7875 if Warn then
7876 if not Restriction_Active (R_Id) then
7877 Set_Restriction (R_Id, N);
7878 Restriction_Warnings (R_Id) := True;
7879 end if;
7880
7881 -- If real restriction case, then set it and make sure that the
7882 -- restriction warning flag is off, since a real restriction
7883 -- always overrides a warning.
7884
7885 else
7886 Set_Restriction (R_Id, N);
7887 Restriction_Warnings (R_Id) := False;
7888 end if;
7889
7890 -- Check for obsolescent restrictions in Ada 2005 mode
7891
7892 if not Warn
7893 and then Ada_Version >= Ada_2005
7894 and then (R_Id = No_Asynchronous_Control
7895 or else
7896 R_Id = No_Unchecked_Deallocation
7897 or else
7898 R_Id = No_Unchecked_Conversion)
7899 then
7900 Check_Restriction (No_Obsolescent_Features, N);
7901 end if;
7902
7903 -- A very special case that must be processed here: pragma
7904 -- Restrictions (No_Exceptions) turns off all run-time
7905 -- checking. This is a bit dubious in terms of the formal
7906 -- language definition, but it is what is intended by RM
7907 -- H.4(12). Restriction_Warnings never affects generated code
7908 -- so this is done only in the real restriction case.
7909
7910 -- Atomic_Synchronization is not a real check, so it is not
7911 -- affected by this processing).
7912
7913 if R_Id = No_Exceptions and then not Warn then
7914 for J in Scope_Suppress.Suppress'Range loop
7915 if J /= Atomic_Synchronization then
7916 Scope_Suppress.Suppress (J) := True;
7917 end if;
7918 end loop;
7919 end if;
7920
7921 -- Case of No_Dependence => unit-name. Note that the parser
7922 -- already made the necessary entry in the No_Dependence table.
7923
7924 elsif Id = Name_No_Dependence then
7925 if not OK_No_Dependence_Unit_Name (Expr) then
7926 raise Pragma_Exit;
7927 end if;
7928
7929 -- Case of No_Specification_Of_Aspect => Identifier.
7930
7931 elsif Id = Name_No_Specification_Of_Aspect then
7932 declare
7933 A_Id : Aspect_Id;
7934
7935 begin
7936 if Nkind (Expr) /= N_Identifier then
7937 A_Id := No_Aspect;
7938 else
7939 A_Id := Get_Aspect_Id (Chars (Expr));
7940 end if;
7941
7942 if A_Id = No_Aspect then
7943 Error_Pragma_Arg ("invalid restriction name", Arg);
7944 else
7945 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
7946 end if;
7947 end;
7948
7949 elsif Id = Name_No_Use_Of_Attribute then
7950 if Nkind (Expr) /= N_Identifier
7951 or else not Is_Attribute_Name (Chars (Expr))
7952 then
7953 Error_Msg_N ("unknown attribute name?", Expr);
7954
7955 else
7956 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
7957 end if;
7958
7959 elsif Id = Name_No_Use_Of_Pragma then
7960 if Nkind (Expr) /= N_Identifier
7961 or else not Is_Pragma_Name (Chars (Expr))
7962 then
7963 Error_Msg_N ("unknown pragma name?", Expr);
7964
7965 else
7966 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
7967 end if;
7968
7969 -- All other cases of restriction identifier present
7970
7971 else
7972 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
7973 Analyze_And_Resolve (Expr, Any_Integer);
7974
7975 if R_Id not in All_Parameter_Restrictions then
7976 Error_Pragma_Arg
7977 ("invalid restriction parameter identifier", Arg);
7978
7979 elsif not Is_OK_Static_Expression (Expr) then
7980 Flag_Non_Static_Expr
7981 ("value must be static expression!", Expr);
7982 raise Pragma_Exit;
7983
7984 elsif not Is_Integer_Type (Etype (Expr))
7985 or else Expr_Value (Expr) < 0
7986 then
7987 Error_Pragma_Arg
7988 ("value must be non-negative integer", Arg);
7989 end if;
7990
7991 -- Restriction pragma is active
7992
7993 Val := Expr_Value (Expr);
7994
7995 if not UI_Is_In_Int_Range (Val) then
7996 Error_Pragma_Arg
7997 ("pragma ignored, value too large??", Arg);
7998 end if;
7999
8000 -- Warning case. If the real restriction is active, then we
8001 -- ignore the request, since warning never overrides a real
8002 -- restriction. Otherwise we set the proper warning. Note that
8003 -- this circuit sets the warning again if it is already set,
8004 -- which is what we want, since the constant may have changed.
8005
8006 if Warn then
8007 if not Restriction_Active (R_Id) then
8008 Set_Restriction
8009 (R_Id, N, Integer (UI_To_Int (Val)));
8010 Restriction_Warnings (R_Id) := True;
8011 end if;
8012
8013 -- Real restriction case, set restriction and make sure warning
8014 -- flag is off since real restriction always overrides warning.
8015
8016 else
8017 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
8018 Restriction_Warnings (R_Id) := False;
8019 end if;
8020 end if;
8021
8022 Next (Arg);
8023 end loop;
8024 end Process_Restrictions_Or_Restriction_Warnings;
8025
8026 ---------------------------------
8027 -- Process_Suppress_Unsuppress --
8028 ---------------------------------
8029
8030 -- Note: this procedure makes entries in the check suppress data
8031 -- structures managed by Sem. See spec of package Sem for full
8032 -- details on how we handle recording of check suppression.
8033
8034 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
8035 C : Check_Id;
8036 E_Id : Node_Id;
8037 E : Entity_Id;
8038
8039 In_Package_Spec : constant Boolean :=
8040 Is_Package_Or_Generic_Package (Current_Scope)
8041 and then not In_Package_Body (Current_Scope);
8042
8043 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
8044 -- Used to suppress a single check on the given entity
8045
8046 --------------------------------
8047 -- Suppress_Unsuppress_Echeck --
8048 --------------------------------
8049
8050 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
8051 begin
8052 -- Check for error of trying to set atomic synchronization for
8053 -- a non-atomic variable.
8054
8055 if C = Atomic_Synchronization
8056 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
8057 then
8058 Error_Msg_N
8059 ("pragma & requires atomic type or variable",
8060 Pragma_Identifier (Original_Node (N)));
8061 end if;
8062
8063 Set_Checks_May_Be_Suppressed (E);
8064
8065 if In_Package_Spec then
8066 Push_Global_Suppress_Stack_Entry
8067 (Entity => E,
8068 Check => C,
8069 Suppress => Suppress_Case);
8070 else
8071 Push_Local_Suppress_Stack_Entry
8072 (Entity => E,
8073 Check => C,
8074 Suppress => Suppress_Case);
8075 end if;
8076
8077 -- If this is a first subtype, and the base type is distinct,
8078 -- then also set the suppress flags on the base type.
8079
8080 if Is_First_Subtype (E) and then Etype (E) /= E then
8081 Suppress_Unsuppress_Echeck (Etype (E), C);
8082 end if;
8083 end Suppress_Unsuppress_Echeck;
8084
8085 -- Start of processing for Process_Suppress_Unsuppress
8086
8087 begin
8088 -- Ignore pragma Suppress/Unsuppress in CodePeer and SPARK modes on
8089 -- user code: we want to generate checks for analysis purposes, as
8090 -- set respectively by -gnatC and -gnatd.F
8091
8092 if (CodePeer_Mode or SPARK_Mode) and then Comes_From_Source (N) then
8093 return;
8094 end if;
8095
8096 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
8097 -- declarative part or a package spec (RM 11.5(5)).
8098
8099 if not Is_Configuration_Pragma then
8100 Check_Is_In_Decl_Part_Or_Package_Spec;
8101 end if;
8102
8103 Check_At_Least_N_Arguments (1);
8104 Check_At_Most_N_Arguments (2);
8105 Check_No_Identifier (Arg1);
8106 Check_Arg_Is_Identifier (Arg1);
8107
8108 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
8109
8110 if C = No_Check_Id then
8111 Error_Pragma_Arg
8112 ("argument of pragma% is not valid check name", Arg1);
8113 end if;
8114
8115 if Arg_Count = 1 then
8116
8117 -- Make an entry in the local scope suppress table. This is the
8118 -- table that directly shows the current value of the scope
8119 -- suppress check for any check id value.
8120
8121 if C = All_Checks then
8122
8123 -- For All_Checks, we set all specific predefined checks with
8124 -- the exception of Elaboration_Check, which is handled
8125 -- specially because of not wanting All_Checks to have the
8126 -- effect of deactivating static elaboration order processing.
8127 -- Atomic_Synchronization is also not affected, since this is
8128 -- not a real check.
8129
8130 for J in Scope_Suppress.Suppress'Range loop
8131 if J /= Elaboration_Check
8132 and then
8133 J /= Atomic_Synchronization
8134 then
8135 Scope_Suppress.Suppress (J) := Suppress_Case;
8136 end if;
8137 end loop;
8138
8139 -- If not All_Checks, and predefined check, then set appropriate
8140 -- scope entry. Note that we will set Elaboration_Check if this
8141 -- is explicitly specified. Atomic_Synchronization is allowed
8142 -- only if internally generated and entity is atomic.
8143
8144 elsif C in Predefined_Check_Id
8145 and then (not Comes_From_Source (N)
8146 or else C /= Atomic_Synchronization)
8147 then
8148 Scope_Suppress.Suppress (C) := Suppress_Case;
8149 end if;
8150
8151 -- Also make an entry in the Local_Entity_Suppress table
8152
8153 Push_Local_Suppress_Stack_Entry
8154 (Entity => Empty,
8155 Check => C,
8156 Suppress => Suppress_Case);
8157
8158 -- Case of two arguments present, where the check is suppressed for
8159 -- a specified entity (given as the second argument of the pragma)
8160
8161 else
8162 -- This is obsolescent in Ada 2005 mode
8163
8164 if Ada_Version >= Ada_2005 then
8165 Check_Restriction (No_Obsolescent_Features, Arg2);
8166 end if;
8167
8168 Check_Optional_Identifier (Arg2, Name_On);
8169 E_Id := Get_Pragma_Arg (Arg2);
8170 Analyze (E_Id);
8171
8172 if not Is_Entity_Name (E_Id) then
8173 Error_Pragma_Arg
8174 ("second argument of pragma% must be entity name", Arg2);
8175 end if;
8176
8177 E := Entity (E_Id);
8178
8179 if E = Any_Id then
8180 return;
8181 end if;
8182
8183 -- Enforce RM 11.5(7) which requires that for a pragma that
8184 -- appears within a package spec, the named entity must be
8185 -- within the package spec. We allow the package name itself
8186 -- to be mentioned since that makes sense, although it is not
8187 -- strictly allowed by 11.5(7).
8188
8189 if In_Package_Spec
8190 and then E /= Current_Scope
8191 and then Scope (E) /= Current_Scope
8192 then
8193 Error_Pragma_Arg
8194 ("entity in pragma% is not in package spec (RM 11.5(7))",
8195 Arg2);
8196 end if;
8197
8198 -- Loop through homonyms. As noted below, in the case of a package
8199 -- spec, only homonyms within the package spec are considered.
8200
8201 loop
8202 Suppress_Unsuppress_Echeck (E, C);
8203
8204 if Is_Generic_Instance (E)
8205 and then Is_Subprogram (E)
8206 and then Present (Alias (E))
8207 then
8208 Suppress_Unsuppress_Echeck (Alias (E), C);
8209 end if;
8210
8211 -- Move to next homonym if not aspect spec case
8212
8213 exit when From_Aspect_Specification (N);
8214 E := Homonym (E);
8215 exit when No (E);
8216
8217 -- If we are within a package specification, the pragma only
8218 -- applies to homonyms in the same scope.
8219
8220 exit when In_Package_Spec
8221 and then Scope (E) /= Current_Scope;
8222 end loop;
8223 end if;
8224 end Process_Suppress_Unsuppress;
8225
8226 ------------------
8227 -- Set_Exported --
8228 ------------------
8229
8230 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
8231 begin
8232 if Is_Imported (E) then
8233 Error_Pragma_Arg
8234 ("cannot export entity& that was previously imported", Arg);
8235
8236 elsif Present (Address_Clause (E))
8237 and then not Relaxed_RM_Semantics
8238 then
8239 Error_Pragma_Arg
8240 ("cannot export entity& that has an address clause", Arg);
8241 end if;
8242
8243 Set_Is_Exported (E);
8244
8245 -- Generate a reference for entity explicitly, because the
8246 -- identifier may be overloaded and name resolution will not
8247 -- generate one.
8248
8249 Generate_Reference (E, Arg);
8250
8251 -- Deal with exporting non-library level entity
8252
8253 if not Is_Library_Level_Entity (E) then
8254
8255 -- Not allowed at all for subprograms
8256
8257 if Is_Subprogram (E) then
8258 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
8259
8260 -- Otherwise set public and statically allocated
8261
8262 else
8263 Set_Is_Public (E);
8264 Set_Is_Statically_Allocated (E);
8265
8266 -- Warn if the corresponding W flag is set and the pragma comes
8267 -- from source. The latter may not be true e.g. on VMS where we
8268 -- expand export pragmas for exception codes associated with
8269 -- imported or exported exceptions. We do not want to generate
8270 -- a warning for something that the user did not write.
8271
8272 if Warn_On_Export_Import
8273 and then Comes_From_Source (Arg)
8274 then
8275 Error_Msg_NE
8276 ("?x?& has been made static as a result of Export",
8277 Arg, E);
8278 Error_Msg_N
8279 ("\?x?this usage is non-standard and non-portable",
8280 Arg);
8281 end if;
8282 end if;
8283 end if;
8284
8285 if Warn_On_Export_Import and then Is_Type (E) then
8286 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
8287 end if;
8288
8289 if Warn_On_Export_Import and Inside_A_Generic then
8290 Error_Msg_NE
8291 ("all instances of& will have the same external name?x?",
8292 Arg, E);
8293 end if;
8294 end Set_Exported;
8295
8296 ----------------------------------------------
8297 -- Set_Extended_Import_Export_External_Name --
8298 ----------------------------------------------
8299
8300 procedure Set_Extended_Import_Export_External_Name
8301 (Internal_Ent : Entity_Id;
8302 Arg_External : Node_Id)
8303 is
8304 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
8305 New_Name : Node_Id;
8306
8307 begin
8308 if No (Arg_External) then
8309 return;
8310 end if;
8311
8312 Check_Arg_Is_External_Name (Arg_External);
8313
8314 if Nkind (Arg_External) = N_String_Literal then
8315 if String_Length (Strval (Arg_External)) = 0 then
8316 return;
8317 else
8318 New_Name := Adjust_External_Name_Case (Arg_External);
8319 end if;
8320
8321 elsif Nkind (Arg_External) = N_Identifier then
8322 New_Name := Get_Default_External_Name (Arg_External);
8323
8324 -- Check_Arg_Is_External_Name should let through only identifiers and
8325 -- string literals or static string expressions (which are folded to
8326 -- string literals).
8327
8328 else
8329 raise Program_Error;
8330 end if;
8331
8332 -- If we already have an external name set (by a prior normal Import
8333 -- or Export pragma), then the external names must match
8334
8335 if Present (Interface_Name (Internal_Ent)) then
8336 Check_Matching_Internal_Names : declare
8337 S1 : constant String_Id := Strval (Old_Name);
8338 S2 : constant String_Id := Strval (New_Name);
8339
8340 procedure Mismatch;
8341 pragma No_Return (Mismatch);
8342 -- Called if names do not match
8343
8344 --------------
8345 -- Mismatch --
8346 --------------
8347
8348 procedure Mismatch is
8349 begin
8350 Error_Msg_Sloc := Sloc (Old_Name);
8351 Error_Pragma_Arg
8352 ("external name does not match that given #",
8353 Arg_External);
8354 end Mismatch;
8355
8356 -- Start of processing for Check_Matching_Internal_Names
8357
8358 begin
8359 if String_Length (S1) /= String_Length (S2) then
8360 Mismatch;
8361
8362 else
8363 for J in 1 .. String_Length (S1) loop
8364 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
8365 Mismatch;
8366 end if;
8367 end loop;
8368 end if;
8369 end Check_Matching_Internal_Names;
8370
8371 -- Otherwise set the given name
8372
8373 else
8374 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
8375 Check_Duplicated_Export_Name (New_Name);
8376 end if;
8377 end Set_Extended_Import_Export_External_Name;
8378
8379 ------------------
8380 -- Set_Imported --
8381 ------------------
8382
8383 procedure Set_Imported (E : Entity_Id) is
8384 begin
8385 -- Error message if already imported or exported
8386
8387 if Is_Exported (E) or else Is_Imported (E) then
8388
8389 -- Error if being set Exported twice
8390
8391 if Is_Exported (E) then
8392 Error_Msg_NE ("entity& was previously exported", N, E);
8393
8394 -- Ignore error in CodePeer mode where we treat all imported
8395 -- subprograms as unknown.
8396
8397 elsif CodePeer_Mode then
8398 goto OK;
8399
8400 -- OK if Import/Interface case
8401
8402 elsif Import_Interface_Present (N) then
8403 goto OK;
8404
8405 -- Error if being set Imported twice
8406
8407 else
8408 Error_Msg_NE ("entity& was previously imported", N, E);
8409 end if;
8410
8411 Error_Msg_Name_1 := Pname;
8412 Error_Msg_N
8413 ("\(pragma% applies to all previous entities)", N);
8414
8415 Error_Msg_Sloc := Sloc (E);
8416 Error_Msg_NE ("\import not allowed for& declared#", N, E);
8417
8418 -- Here if not previously imported or exported, OK to import
8419
8420 else
8421 Set_Is_Imported (E);
8422
8423 -- If the entity is an object that is not at the library level,
8424 -- then it is statically allocated. We do not worry about objects
8425 -- with address clauses in this context since they are not really
8426 -- imported in the linker sense.
8427
8428 if Is_Object (E)
8429 and then not Is_Library_Level_Entity (E)
8430 and then No (Address_Clause (E))
8431 then
8432 Set_Is_Statically_Allocated (E);
8433 end if;
8434 end if;
8435
8436 <<OK>> null;
8437 end Set_Imported;
8438
8439 -------------------------
8440 -- Set_Mechanism_Value --
8441 -------------------------
8442
8443 -- Note: the mechanism name has not been analyzed (and cannot indeed be
8444 -- analyzed, since it is semantic nonsense), so we get it in the exact
8445 -- form created by the parser.
8446
8447 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
8448 Class : Node_Id;
8449 Param : Node_Id;
8450 Mech_Name_Id : Name_Id;
8451
8452 procedure Bad_Class;
8453 pragma No_Return (Bad_Class);
8454 -- Signal bad descriptor class name
8455
8456 procedure Bad_Mechanism;
8457 pragma No_Return (Bad_Mechanism);
8458 -- Signal bad mechanism name
8459
8460 ---------------
8461 -- Bad_Class --
8462 ---------------
8463
8464 procedure Bad_Class is
8465 begin
8466 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
8467 end Bad_Class;
8468
8469 -------------------------
8470 -- Bad_Mechanism_Value --
8471 -------------------------
8472
8473 procedure Bad_Mechanism is
8474 begin
8475 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
8476 end Bad_Mechanism;
8477
8478 -- Start of processing for Set_Mechanism_Value
8479
8480 begin
8481 if Mechanism (Ent) /= Default_Mechanism then
8482 Error_Msg_NE
8483 ("mechanism for & has already been set", Mech_Name, Ent);
8484 end if;
8485
8486 -- MECHANISM_NAME ::= value | reference | descriptor |
8487 -- short_descriptor
8488
8489 if Nkind (Mech_Name) = N_Identifier then
8490 if Chars (Mech_Name) = Name_Value then
8491 Set_Mechanism (Ent, By_Copy);
8492 return;
8493
8494 elsif Chars (Mech_Name) = Name_Reference then
8495 Set_Mechanism (Ent, By_Reference);
8496 return;
8497
8498 elsif Chars (Mech_Name) = Name_Descriptor then
8499 Check_VMS (Mech_Name);
8500
8501 -- Descriptor => Short_Descriptor if pragma was given
8502
8503 if Short_Descriptors then
8504 Set_Mechanism (Ent, By_Short_Descriptor);
8505 else
8506 Set_Mechanism (Ent, By_Descriptor);
8507 end if;
8508
8509 return;
8510
8511 elsif Chars (Mech_Name) = Name_Short_Descriptor then
8512 Check_VMS (Mech_Name);
8513 Set_Mechanism (Ent, By_Short_Descriptor);
8514 return;
8515
8516 elsif Chars (Mech_Name) = Name_Copy then
8517 Error_Pragma_Arg
8518 ("bad mechanism name, Value assumed", Mech_Name);
8519
8520 else
8521 Bad_Mechanism;
8522 end if;
8523
8524 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
8525 -- short_descriptor (CLASS_NAME)
8526 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8527
8528 -- Note: this form is parsed as an indexed component
8529
8530 elsif Nkind (Mech_Name) = N_Indexed_Component then
8531 Class := First (Expressions (Mech_Name));
8532
8533 if Nkind (Prefix (Mech_Name)) /= N_Identifier
8534 or else
8535 not Nam_In (Chars (Prefix (Mech_Name)), Name_Descriptor,
8536 Name_Short_Descriptor)
8537 or else Present (Next (Class))
8538 then
8539 Bad_Mechanism;
8540 else
8541 Mech_Name_Id := Chars (Prefix (Mech_Name));
8542
8543 -- Change Descriptor => Short_Descriptor if pragma was given
8544
8545 if Mech_Name_Id = Name_Descriptor
8546 and then Short_Descriptors
8547 then
8548 Mech_Name_Id := Name_Short_Descriptor;
8549 end if;
8550 end if;
8551
8552 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
8553 -- short_descriptor (Class => CLASS_NAME)
8554 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8555
8556 -- Note: this form is parsed as a function call
8557
8558 elsif Nkind (Mech_Name) = N_Function_Call then
8559 Param := First (Parameter_Associations (Mech_Name));
8560
8561 if Nkind (Name (Mech_Name)) /= N_Identifier
8562 or else
8563 not Nam_In (Chars (Name (Mech_Name)), Name_Descriptor,
8564 Name_Short_Descriptor)
8565 or else Present (Next (Param))
8566 or else No (Selector_Name (Param))
8567 or else Chars (Selector_Name (Param)) /= Name_Class
8568 then
8569 Bad_Mechanism;
8570 else
8571 Class := Explicit_Actual_Parameter (Param);
8572 Mech_Name_Id := Chars (Name (Mech_Name));
8573 end if;
8574
8575 else
8576 Bad_Mechanism;
8577 end if;
8578
8579 -- Fall through here with Class set to descriptor class name
8580
8581 Check_VMS (Mech_Name);
8582
8583 if Nkind (Class) /= N_Identifier then
8584 Bad_Class;
8585
8586 elsif Mech_Name_Id = Name_Descriptor
8587 and then Chars (Class) = Name_UBS
8588 then
8589 Set_Mechanism (Ent, By_Descriptor_UBS);
8590
8591 elsif Mech_Name_Id = Name_Descriptor
8592 and then Chars (Class) = Name_UBSB
8593 then
8594 Set_Mechanism (Ent, By_Descriptor_UBSB);
8595
8596 elsif Mech_Name_Id = Name_Descriptor
8597 and then Chars (Class) = Name_UBA
8598 then
8599 Set_Mechanism (Ent, By_Descriptor_UBA);
8600
8601 elsif Mech_Name_Id = Name_Descriptor
8602 and then Chars (Class) = Name_S
8603 then
8604 Set_Mechanism (Ent, By_Descriptor_S);
8605
8606 elsif Mech_Name_Id = Name_Descriptor
8607 and then Chars (Class) = Name_SB
8608 then
8609 Set_Mechanism (Ent, By_Descriptor_SB);
8610
8611 elsif Mech_Name_Id = Name_Descriptor
8612 and then Chars (Class) = Name_A
8613 then
8614 Set_Mechanism (Ent, By_Descriptor_A);
8615
8616 elsif Mech_Name_Id = Name_Descriptor
8617 and then Chars (Class) = Name_NCA
8618 then
8619 Set_Mechanism (Ent, By_Descriptor_NCA);
8620
8621 elsif Mech_Name_Id = Name_Short_Descriptor
8622 and then Chars (Class) = Name_UBS
8623 then
8624 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
8625
8626 elsif Mech_Name_Id = Name_Short_Descriptor
8627 and then Chars (Class) = Name_UBSB
8628 then
8629 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
8630
8631 elsif Mech_Name_Id = Name_Short_Descriptor
8632 and then Chars (Class) = Name_UBA
8633 then
8634 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
8635
8636 elsif Mech_Name_Id = Name_Short_Descriptor
8637 and then Chars (Class) = Name_S
8638 then
8639 Set_Mechanism (Ent, By_Short_Descriptor_S);
8640
8641 elsif Mech_Name_Id = Name_Short_Descriptor
8642 and then Chars (Class) = Name_SB
8643 then
8644 Set_Mechanism (Ent, By_Short_Descriptor_SB);
8645
8646 elsif Mech_Name_Id = Name_Short_Descriptor
8647 and then Chars (Class) = Name_A
8648 then
8649 Set_Mechanism (Ent, By_Short_Descriptor_A);
8650
8651 elsif Mech_Name_Id = Name_Short_Descriptor
8652 and then Chars (Class) = Name_NCA
8653 then
8654 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
8655
8656 else
8657 Bad_Class;
8658 end if;
8659 end Set_Mechanism_Value;
8660
8661 --------------------------
8662 -- Set_Rational_Profile --
8663 --------------------------
8664
8665 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
8666 -- and extension to the semantics of renaming declarations.
8667
8668 procedure Set_Rational_Profile is
8669 begin
8670 Implicit_Packing := True;
8671 Overriding_Renamings := True;
8672 Use_VADS_Size := True;
8673 end Set_Rational_Profile;
8674
8675 ---------------------------
8676 -- Set_Ravenscar_Profile --
8677 ---------------------------
8678
8679 -- The tasks to be done here are
8680
8681 -- Set required policies
8682
8683 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
8684 -- pragma Locking_Policy (Ceiling_Locking)
8685
8686 -- Set Detect_Blocking mode
8687
8688 -- Set required restrictions (see System.Rident for detailed list)
8689
8690 -- Set the No_Dependence rules
8691 -- No_Dependence => Ada.Asynchronous_Task_Control
8692 -- No_Dependence => Ada.Calendar
8693 -- No_Dependence => Ada.Execution_Time.Group_Budget
8694 -- No_Dependence => Ada.Execution_Time.Timers
8695 -- No_Dependence => Ada.Task_Attributes
8696 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
8697
8698 procedure Set_Ravenscar_Profile (N : Node_Id) is
8699 Prefix_Entity : Entity_Id;
8700 Selector_Entity : Entity_Id;
8701 Prefix_Node : Node_Id;
8702 Node : Node_Id;
8703
8704 begin
8705 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
8706
8707 if Task_Dispatching_Policy /= ' '
8708 and then Task_Dispatching_Policy /= 'F'
8709 then
8710 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
8711 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
8712
8713 -- Set the FIFO_Within_Priorities policy, but always preserve
8714 -- System_Location since we like the error message with the run time
8715 -- name.
8716
8717 else
8718 Task_Dispatching_Policy := 'F';
8719
8720 if Task_Dispatching_Policy_Sloc /= System_Location then
8721 Task_Dispatching_Policy_Sloc := Loc;
8722 end if;
8723 end if;
8724
8725 -- pragma Locking_Policy (Ceiling_Locking)
8726
8727 if Locking_Policy /= ' '
8728 and then Locking_Policy /= 'C'
8729 then
8730 Error_Msg_Sloc := Locking_Policy_Sloc;
8731 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
8732
8733 -- Set the Ceiling_Locking policy, but preserve System_Location since
8734 -- we like the error message with the run time name.
8735
8736 else
8737 Locking_Policy := 'C';
8738
8739 if Locking_Policy_Sloc /= System_Location then
8740 Locking_Policy_Sloc := Loc;
8741 end if;
8742 end if;
8743
8744 -- pragma Detect_Blocking
8745
8746 Detect_Blocking := True;
8747
8748 -- Set the corresponding restrictions
8749
8750 Set_Profile_Restrictions
8751 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
8752
8753 -- Set the No_Dependence restrictions
8754
8755 -- The following No_Dependence restrictions:
8756 -- No_Dependence => Ada.Asynchronous_Task_Control
8757 -- No_Dependence => Ada.Calendar
8758 -- No_Dependence => Ada.Task_Attributes
8759 -- are already set by previous call to Set_Profile_Restrictions.
8760
8761 -- Set the following restrictions which were added to Ada 2005:
8762 -- No_Dependence => Ada.Execution_Time.Group_Budget
8763 -- No_Dependence => Ada.Execution_Time.Timers
8764
8765 if Ada_Version >= Ada_2005 then
8766 Name_Buffer (1 .. 3) := "ada";
8767 Name_Len := 3;
8768
8769 Prefix_Entity := Make_Identifier (Loc, Name_Find);
8770
8771 Name_Buffer (1 .. 14) := "execution_time";
8772 Name_Len := 14;
8773
8774 Selector_Entity := Make_Identifier (Loc, Name_Find);
8775
8776 Prefix_Node :=
8777 Make_Selected_Component
8778 (Sloc => Loc,
8779 Prefix => Prefix_Entity,
8780 Selector_Name => Selector_Entity);
8781
8782 Name_Buffer (1 .. 13) := "group_budgets";
8783 Name_Len := 13;
8784
8785 Selector_Entity := Make_Identifier (Loc, Name_Find);
8786
8787 Node :=
8788 Make_Selected_Component
8789 (Sloc => Loc,
8790 Prefix => Prefix_Node,
8791 Selector_Name => Selector_Entity);
8792
8793 Set_Restriction_No_Dependence
8794 (Unit => Node,
8795 Warn => Treat_Restrictions_As_Warnings,
8796 Profile => Ravenscar);
8797
8798 Name_Buffer (1 .. 6) := "timers";
8799 Name_Len := 6;
8800
8801 Selector_Entity := Make_Identifier (Loc, Name_Find);
8802
8803 Node :=
8804 Make_Selected_Component
8805 (Sloc => Loc,
8806 Prefix => Prefix_Node,
8807 Selector_Name => Selector_Entity);
8808
8809 Set_Restriction_No_Dependence
8810 (Unit => Node,
8811 Warn => Treat_Restrictions_As_Warnings,
8812 Profile => Ravenscar);
8813 end if;
8814
8815 -- Set the following restrictions which was added to Ada 2012 (see
8816 -- AI-0171):
8817 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
8818
8819 if Ada_Version >= Ada_2012 then
8820 Name_Buffer (1 .. 6) := "system";
8821 Name_Len := 6;
8822
8823 Prefix_Entity := Make_Identifier (Loc, Name_Find);
8824
8825 Name_Buffer (1 .. 15) := "multiprocessors";
8826 Name_Len := 15;
8827
8828 Selector_Entity := Make_Identifier (Loc, Name_Find);
8829
8830 Prefix_Node :=
8831 Make_Selected_Component
8832 (Sloc => Loc,
8833 Prefix => Prefix_Entity,
8834 Selector_Name => Selector_Entity);
8835
8836 Name_Buffer (1 .. 19) := "dispatching_domains";
8837 Name_Len := 19;
8838
8839 Selector_Entity := Make_Identifier (Loc, Name_Find);
8840
8841 Node :=
8842 Make_Selected_Component
8843 (Sloc => Loc,
8844 Prefix => Prefix_Node,
8845 Selector_Name => Selector_Entity);
8846
8847 Set_Restriction_No_Dependence
8848 (Unit => Node,
8849 Warn => Treat_Restrictions_As_Warnings,
8850 Profile => Ravenscar);
8851 end if;
8852 end Set_Ravenscar_Profile;
8853
8854 ----------------
8855 -- S14_Pragma --
8856 ----------------
8857
8858 procedure S14_Pragma is
8859 begin
8860 if not Formal_Extensions then
8861 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
8862 end if;
8863 end S14_Pragma;
8864
8865 -- Start of processing for Analyze_Pragma
8866
8867 begin
8868 -- The following code is a defense against recursion. Not clear that
8869 -- this can happen legitimately, but perhaps some error situations
8870 -- can cause it, and we did see this recursion during testing.
8871
8872 if Analyzed (N) then
8873 return;
8874 else
8875 Set_Analyzed (N, True);
8876 end if;
8877
8878 -- Deal with unrecognized pragma
8879
8880 Pname := Pragma_Name (N);
8881
8882 if not Is_Pragma_Name (Pname) then
8883 if Warn_On_Unrecognized_Pragma then
8884 Error_Msg_Name_1 := Pname;
8885 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
8886
8887 for PN in First_Pragma_Name .. Last_Pragma_Name loop
8888 if Is_Bad_Spelling_Of (Pname, PN) then
8889 Error_Msg_Name_1 := PN;
8890 Error_Msg_N -- CODEFIX
8891 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
8892 exit;
8893 end if;
8894 end loop;
8895 end if;
8896
8897 return;
8898 end if;
8899
8900 -- Here to start processing for recognized pragma
8901
8902 Prag_Id := Get_Pragma_Id (Pname);
8903 Pname := Original_Aspect_Name (N);
8904
8905 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
8906 -- is already set, indicating that we have already checked the policy
8907 -- at the right point. This happens for example in the case of a pragma
8908 -- that is derived from an Aspect.
8909
8910 if Is_Ignored (N) or else Is_Checked (N) then
8911 null;
8912
8913 -- For a pragma that is a rewriting of another pragma, copy the
8914 -- Is_Checked/Is_Ignored status from the rewritten pragma.
8915
8916 elsif Is_Rewrite_Substitution (N)
8917 and then Nkind (Original_Node (N)) = N_Pragma
8918 and then Original_Node (N) /= N
8919 then
8920 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
8921 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
8922
8923 -- Otherwise query the applicable policy at this point
8924
8925 else
8926 Check_Applicable_Policy (N);
8927
8928 -- If pragma is disabled, rewrite as NULL and skip analysis
8929
8930 if Is_Disabled (N) then
8931 Rewrite (N, Make_Null_Statement (Loc));
8932 Analyze (N);
8933 raise Pragma_Exit;
8934 end if;
8935 end if;
8936
8937 -- Preset arguments
8938
8939 Arg_Count := 0;
8940 Arg1 := Empty;
8941 Arg2 := Empty;
8942 Arg3 := Empty;
8943 Arg4 := Empty;
8944
8945 if Present (Pragma_Argument_Associations (N)) then
8946 Arg_Count := List_Length (Pragma_Argument_Associations (N));
8947 Arg1 := First (Pragma_Argument_Associations (N));
8948
8949 if Present (Arg1) then
8950 Arg2 := Next (Arg1);
8951
8952 if Present (Arg2) then
8953 Arg3 := Next (Arg2);
8954
8955 if Present (Arg3) then
8956 Arg4 := Next (Arg3);
8957 end if;
8958 end if;
8959 end if;
8960 end if;
8961
8962 Check_Restriction_No_Use_Of_Pragma (N);
8963
8964 -- An enumeration type defines the pragmas that are supported by the
8965 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
8966 -- into the corresponding enumeration value for the following case.
8967
8968 case Prag_Id is
8969
8970 -----------------
8971 -- Abort_Defer --
8972 -----------------
8973
8974 -- pragma Abort_Defer;
8975
8976 when Pragma_Abort_Defer =>
8977 GNAT_Pragma;
8978 Check_Arg_Count (0);
8979
8980 -- The only required semantic processing is to check the
8981 -- placement. This pragma must appear at the start of the
8982 -- statement sequence of a handled sequence of statements.
8983
8984 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
8985 or else N /= First (Statements (Parent (N)))
8986 then
8987 Pragma_Misplaced;
8988 end if;
8989
8990 --------------------
8991 -- Abstract_State --
8992 --------------------
8993
8994 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
8995
8996 -- ABSTRACT_STATE_LIST ::=
8997 -- null
8998 -- | STATE_NAME_WITH_OPTIONS
8999 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
9000
9001 -- STATE_NAME_WITH_OPTIONS ::=
9002 -- state_NAME
9003 -- | (state_NAME with OPTION_LIST)
9004
9005 -- OPTION_LIST ::= OPTION {, OPTION}
9006
9007 -- OPTION ::= SIMPLE_OPTION | NAME_VALUE_OPTION
9008
9009 -- SIMPLE_OPTION ::=
9010 -- External | Non_Volatile | Input_Only | Output_Only
9011
9012 -- NAME_VALUE_OPTION ::= Part_Of => abstract_state_NAME
9013
9014 when Pragma_Abstract_State => Abstract_State : declare
9015 Pack_Id : Entity_Id;
9016
9017 -- Flags used to verify the consistency of states
9018
9019 Non_Null_Seen : Boolean := False;
9020 Null_Seen : Boolean := False;
9021
9022 procedure Analyze_Abstract_State (State : Node_Id);
9023 -- Verify the legality of a single state declaration. Create and
9024 -- decorate a state abstraction entity and introduce it into the
9025 -- visibility chain.
9026
9027 ----------------------------
9028 -- Analyze_Abstract_State --
9029 ----------------------------
9030
9031 procedure Analyze_Abstract_State (State : Node_Id) is
9032 procedure Check_Duplicate_Option
9033 (Opt : Node_Id;
9034 Status : in out Boolean);
9035 -- Flag Status denotes whether a particular option has been
9036 -- seen while processing a state. This routine verifies that
9037 -- Opt is not a duplicate property and sets the flag Status.
9038
9039 ----------------------------
9040 -- Check_Duplicate_Option --
9041 ----------------------------
9042
9043 procedure Check_Duplicate_Option
9044 (Opt : Node_Id;
9045 Status : in out Boolean)
9046 is
9047 begin
9048 if Status then
9049 Error_Msg_N ("duplicate state option", Opt);
9050 end if;
9051
9052 Status := True;
9053 end Check_Duplicate_Option;
9054
9055 -- Local variables
9056
9057 Errors : constant Nat := Serious_Errors_Detected;
9058 Loc : constant Source_Ptr := Sloc (State);
9059 Assoc : Node_Id;
9060 Id : Entity_Id;
9061 Is_Null : Boolean := False;
9062 Name : Name_Id;
9063 Opt : Node_Id;
9064 Par_State : Node_Id;
9065
9066 -- Flags used to verify the consistency of options
9067
9068 External_Seen : Boolean := False;
9069 Input_Seen : Boolean := False;
9070 Non_Volatile_Seen : Boolean := False;
9071 Output_Seen : Boolean := False;
9072 Part_Of_Seen : Boolean := False;
9073
9074 -- Start of processing for Analyze_Abstract_State
9075
9076 begin
9077 -- A package with a null abstract state is not allowed to
9078 -- declare additional states.
9079
9080 if Null_Seen then
9081 Error_Msg_NE
9082 ("package & has null abstract state", State, Pack_Id);
9083
9084 -- Null states appear as internally generated entities
9085
9086 elsif Nkind (State) = N_Null then
9087 Name := New_Internal_Name ('S');
9088 Is_Null := True;
9089 Null_Seen := True;
9090
9091 -- Catch a case where a null state appears in a list of
9092 -- non-null states.
9093
9094 if Non_Null_Seen then
9095 Error_Msg_NE
9096 ("package & has non-null abstract state",
9097 State, Pack_Id);
9098 end if;
9099
9100 -- Simple state declaration
9101
9102 elsif Nkind (State) = N_Identifier then
9103 Name := Chars (State);
9104 Non_Null_Seen := True;
9105
9106 -- State declaration with various options. This construct
9107 -- appears as an extension aggregate in the tree.
9108
9109 elsif Nkind (State) = N_Extension_Aggregate then
9110 if Nkind (Ancestor_Part (State)) = N_Identifier then
9111 Name := Chars (Ancestor_Part (State));
9112 Non_Null_Seen := True;
9113 else
9114 Error_Msg_N
9115 ("state name must be an identifier",
9116 Ancestor_Part (State));
9117 end if;
9118
9119 -- Process options External, Input_Only, Output_Only and
9120 -- Volatile. Ensure that none of them appear more than once.
9121
9122 Opt := First (Expressions (State));
9123 while Present (Opt) loop
9124 if Nkind (Opt) = N_Identifier then
9125 if Chars (Opt) = Name_External then
9126 Check_Duplicate_Option (Opt, External_Seen);
9127 elsif Chars (Opt) = Name_Input_Only then
9128 Check_Duplicate_Option (Opt, Input_Seen);
9129 elsif Chars (Opt) = Name_Output_Only then
9130 Check_Duplicate_Option (Opt, Output_Seen);
9131 elsif Chars (Opt) = Name_Non_Volatile then
9132 Check_Duplicate_Option (Opt, Non_Volatile_Seen);
9133
9134 -- Ensure that the abstract state component of option
9135 -- Part_Of has not been omitted.
9136
9137 elsif Chars (Opt) = Name_Part_Of then
9138 Error_Msg_N
9139 ("option Part_Of requires an abstract state",
9140 Opt);
9141 else
9142 Error_Msg_N ("invalid state option", Opt);
9143 end if;
9144 else
9145 Error_Msg_N ("invalid state option", Opt);
9146 end if;
9147
9148 Next (Opt);
9149 end loop;
9150
9151 -- External may appear on its own or with exactly one option
9152 -- Input_Only or Output_Only, but not both.
9153
9154 if External_Seen
9155 and then Input_Seen
9156 and then Output_Seen
9157 then
9158 Error_Msg_N
9159 ("option External requires exactly one option "
9160 & "Input_Only or Output_Only", State);
9161 end if;
9162
9163 -- Either Input_Only or Output_Only require External
9164
9165 if (Input_Seen or Output_Seen)
9166 and then not External_Seen
9167 then
9168 Error_Msg_N
9169 ("options Input_Only and Output_Only require option "
9170 & "External", State);
9171 end if;
9172
9173 -- Option Part_Of appears as a component association
9174
9175 Assoc := First (Component_Associations (State));
9176 while Present (Assoc) loop
9177 Opt := First (Choices (Assoc));
9178 while Present (Opt) loop
9179 if Nkind (Opt) = N_Identifier
9180 and then Chars (Opt) = Name_Part_Of
9181 then
9182 Check_Duplicate_Option (Opt, Part_Of_Seen);
9183 else
9184 Error_Msg_N ("invalid state option", Opt);
9185 end if;
9186
9187 Next (Opt);
9188 end loop;
9189
9190 -- Part_Of must denote a parent state. Ensure that the
9191 -- tree is not malformed by checking the expression of
9192 -- the component association.
9193
9194 Par_State := Expression (Assoc);
9195 pragma Assert (Present (Par_State));
9196
9197 Analyze (Par_State);
9198
9199 -- Part_Of specified a legal state
9200
9201 if Is_Entity_Name (Par_State)
9202 and then Present (Entity (Par_State))
9203 and then Ekind (Entity (Par_State)) = E_Abstract_State
9204 then
9205 null;
9206 else
9207 Error_Msg_N
9208 ("option Part_Of must denote an abstract state",
9209 Par_State);
9210 end if;
9211
9212 Next (Assoc);
9213 end loop;
9214
9215 -- Any other attempt to declare a state is erroneous
9216
9217 else
9218 Error_Msg_N ("malformed abstract state declaration", State);
9219 end if;
9220
9221 -- Do not generate a state abstraction entity if it was not
9222 -- properly declared.
9223
9224 if Serious_Errors_Detected > Errors then
9225 return;
9226 end if;
9227
9228 -- The generated state abstraction reuses the same characters
9229 -- from the original state declaration. Decorate the entity.
9230
9231 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
9232 Set_Comes_From_Source (Id, not Is_Null);
9233 Set_Parent (Id, State);
9234 Set_Ekind (Id, E_Abstract_State);
9235 Set_Etype (Id, Standard_Void_Type);
9236 Set_Refined_State (Id, Empty);
9237 Set_Refinement_Constituents (Id, New_Elmt_List);
9238
9239 -- Every non-null state must be nameable and resolvable the
9240 -- same way a constant is.
9241
9242 if not Is_Null then
9243 Push_Scope (Pack_Id);
9244 Enter_Name (Id);
9245 Pop_Scope;
9246 end if;
9247
9248 -- Verify whether the state introduces an illegal hidden state
9249 -- within a package subject to a null abstract state.
9250
9251 if Formal_Extensions then
9252 Check_No_Hidden_State (Id);
9253 end if;
9254
9255 -- Associate the state with its related package
9256
9257 if No (Abstract_States (Pack_Id)) then
9258 Set_Abstract_States (Pack_Id, New_Elmt_List);
9259 end if;
9260
9261 Append_Elmt (Id, Abstract_States (Pack_Id));
9262 end Analyze_Abstract_State;
9263
9264 -- Local variables
9265
9266 Context : constant Node_Id := Parent (Parent (N));
9267 State : Node_Id;
9268
9269 -- Start of processing for Abstract_State
9270
9271 begin
9272 GNAT_Pragma;
9273 S14_Pragma;
9274 Check_Arg_Count (1);
9275
9276 -- Ensure the proper placement of the pragma. Abstract states must
9277 -- be associated with a package declaration.
9278
9279 if not Nkind_In (Context, N_Generic_Package_Declaration,
9280 N_Package_Declaration)
9281 then
9282 Pragma_Misplaced;
9283 return;
9284 end if;
9285
9286 Pack_Id := Defining_Entity (Context);
9287 Add_Contract_Item (N, Pack_Id);
9288
9289 -- Verify the declaration order of pragmas Abstract_State and
9290 -- Initializes.
9291
9292 Check_Declaration_Order
9293 (States => N,
9294 Inits => Get_Pragma (Pack_Id, Pragma_Initializes));
9295
9296 State := Expression (Arg1);
9297
9298 -- Multiple abstract states appear as an aggregate
9299
9300 if Nkind (State) = N_Aggregate then
9301 State := First (Expressions (State));
9302 while Present (State) loop
9303 Analyze_Abstract_State (State);
9304
9305 Next (State);
9306 end loop;
9307
9308 -- Various forms of a single abstract state. Note that these may
9309 -- include malformed state declarations.
9310
9311 else
9312 Analyze_Abstract_State (State);
9313 end if;
9314 end Abstract_State;
9315
9316 ------------
9317 -- Ada_83 --
9318 ------------
9319
9320 -- pragma Ada_83;
9321
9322 -- Note: this pragma also has some specific processing in Par.Prag
9323 -- because we want to set the Ada version mode during parsing.
9324
9325 when Pragma_Ada_83 =>
9326 GNAT_Pragma;
9327 Check_Arg_Count (0);
9328
9329 -- We really should check unconditionally for proper configuration
9330 -- pragma placement, since we really don't want mixed Ada modes
9331 -- within a single unit, and the GNAT reference manual has always
9332 -- said this was a configuration pragma, but we did not check and
9333 -- are hesitant to add the check now.
9334
9335 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
9336 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
9337 -- or Ada 2012 mode.
9338
9339 if Ada_Version >= Ada_2005 then
9340 Check_Valid_Configuration_Pragma;
9341 end if;
9342
9343 -- Now set Ada 83 mode
9344
9345 Ada_Version := Ada_83;
9346 Ada_Version_Explicit := Ada_83;
9347 Ada_Version_Pragma := N;
9348
9349 ------------
9350 -- Ada_95 --
9351 ------------
9352
9353 -- pragma Ada_95;
9354
9355 -- Note: this pragma also has some specific processing in Par.Prag
9356 -- because we want to set the Ada 83 version mode during parsing.
9357
9358 when Pragma_Ada_95 =>
9359 GNAT_Pragma;
9360 Check_Arg_Count (0);
9361
9362 -- We really should check unconditionally for proper configuration
9363 -- pragma placement, since we really don't want mixed Ada modes
9364 -- within a single unit, and the GNAT reference manual has always
9365 -- said this was a configuration pragma, but we did not check and
9366 -- are hesitant to add the check now.
9367
9368 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
9369 -- or Ada 95, so we must check if we are in Ada 2005 mode.
9370
9371 if Ada_Version >= Ada_2005 then
9372 Check_Valid_Configuration_Pragma;
9373 end if;
9374
9375 -- Now set Ada 95 mode
9376
9377 Ada_Version := Ada_95;
9378 Ada_Version_Explicit := Ada_95;
9379 Ada_Version_Pragma := N;
9380
9381 ---------------------
9382 -- Ada_05/Ada_2005 --
9383 ---------------------
9384
9385 -- pragma Ada_05;
9386 -- pragma Ada_05 (LOCAL_NAME);
9387
9388 -- pragma Ada_2005;
9389 -- pragma Ada_2005 (LOCAL_NAME):
9390
9391 -- Note: these pragmas also have some specific processing in Par.Prag
9392 -- because we want to set the Ada 2005 version mode during parsing.
9393
9394 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
9395 E_Id : Node_Id;
9396
9397 begin
9398 GNAT_Pragma;
9399
9400 if Arg_Count = 1 then
9401 Check_Arg_Is_Local_Name (Arg1);
9402 E_Id := Get_Pragma_Arg (Arg1);
9403
9404 if Etype (E_Id) = Any_Type then
9405 return;
9406 end if;
9407
9408 Set_Is_Ada_2005_Only (Entity (E_Id));
9409 Record_Rep_Item (Entity (E_Id), N);
9410
9411 else
9412 Check_Arg_Count (0);
9413
9414 -- For Ada_2005 we unconditionally enforce the documented
9415 -- configuration pragma placement, since we do not want to
9416 -- tolerate mixed modes in a unit involving Ada 2005. That
9417 -- would cause real difficulties for those cases where there
9418 -- are incompatibilities between Ada 95 and Ada 2005.
9419
9420 Check_Valid_Configuration_Pragma;
9421
9422 -- Now set appropriate Ada mode
9423
9424 Ada_Version := Ada_2005;
9425 Ada_Version_Explicit := Ada_2005;
9426 Ada_Version_Pragma := N;
9427 end if;
9428 end;
9429
9430 ---------------------
9431 -- Ada_12/Ada_2012 --
9432 ---------------------
9433
9434 -- pragma Ada_12;
9435 -- pragma Ada_12 (LOCAL_NAME);
9436
9437 -- pragma Ada_2012;
9438 -- pragma Ada_2012 (LOCAL_NAME):
9439
9440 -- Note: these pragmas also have some specific processing in Par.Prag
9441 -- because we want to set the Ada 2012 version mode during parsing.
9442
9443 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
9444 E_Id : Node_Id;
9445
9446 begin
9447 GNAT_Pragma;
9448
9449 if Arg_Count = 1 then
9450 Check_Arg_Is_Local_Name (Arg1);
9451 E_Id := Get_Pragma_Arg (Arg1);
9452
9453 if Etype (E_Id) = Any_Type then
9454 return;
9455 end if;
9456
9457 Set_Is_Ada_2012_Only (Entity (E_Id));
9458 Record_Rep_Item (Entity (E_Id), N);
9459
9460 else
9461 Check_Arg_Count (0);
9462
9463 -- For Ada_2012 we unconditionally enforce the documented
9464 -- configuration pragma placement, since we do not want to
9465 -- tolerate mixed modes in a unit involving Ada 2012. That
9466 -- would cause real difficulties for those cases where there
9467 -- are incompatibilities between Ada 95 and Ada 2012. We could
9468 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
9469
9470 Check_Valid_Configuration_Pragma;
9471
9472 -- Now set appropriate Ada mode
9473
9474 Ada_Version := Ada_2012;
9475 Ada_Version_Explicit := Ada_2012;
9476 Ada_Version_Pragma := N;
9477 end if;
9478 end;
9479
9480 ----------------------
9481 -- All_Calls_Remote --
9482 ----------------------
9483
9484 -- pragma All_Calls_Remote [(library_package_NAME)];
9485
9486 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
9487 Lib_Entity : Entity_Id;
9488
9489 begin
9490 Check_Ada_83_Warning;
9491 Check_Valid_Library_Unit_Pragma;
9492
9493 if Nkind (N) = N_Null_Statement then
9494 return;
9495 end if;
9496
9497 Lib_Entity := Find_Lib_Unit_Name;
9498
9499 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
9500
9501 if Present (Lib_Entity)
9502 and then not Debug_Flag_U
9503 then
9504 if not Is_Remote_Call_Interface (Lib_Entity) then
9505 Error_Pragma ("pragma% only apply to rci unit");
9506
9507 -- Set flag for entity of the library unit
9508
9509 else
9510 Set_Has_All_Calls_Remote (Lib_Entity);
9511 end if;
9512
9513 end if;
9514 end All_Calls_Remote;
9515
9516 --------------
9517 -- Annotate --
9518 --------------
9519
9520 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
9521 -- ARG ::= NAME | EXPRESSION
9522
9523 -- The first two arguments are by convention intended to refer to an
9524 -- external tool and a tool-specific function. These arguments are
9525 -- not analyzed.
9526
9527 when Pragma_Annotate => Annotate : declare
9528 Arg : Node_Id;
9529 Exp : Node_Id;
9530
9531 begin
9532 GNAT_Pragma;
9533 Check_At_Least_N_Arguments (1);
9534 Check_Arg_Is_Identifier (Arg1);
9535 Check_No_Identifiers;
9536 Store_Note (N);
9537
9538 -- Second parameter is optional, it is never analyzed
9539
9540 if No (Arg2) then
9541 null;
9542
9543 -- Here if we have a second parameter
9544
9545 else
9546 -- Second parameter must be identifier
9547
9548 Check_Arg_Is_Identifier (Arg2);
9549
9550 -- Process remaining parameters if any
9551
9552 Arg := Next (Arg2);
9553 while Present (Arg) loop
9554 Exp := Get_Pragma_Arg (Arg);
9555 Analyze (Exp);
9556
9557 if Is_Entity_Name (Exp) then
9558 null;
9559
9560 -- For string literals, we assume Standard_String as the
9561 -- type, unless the string contains wide or wide_wide
9562 -- characters.
9563
9564 elsif Nkind (Exp) = N_String_Literal then
9565 if Has_Wide_Wide_Character (Exp) then
9566 Resolve (Exp, Standard_Wide_Wide_String);
9567 elsif Has_Wide_Character (Exp) then
9568 Resolve (Exp, Standard_Wide_String);
9569 else
9570 Resolve (Exp, Standard_String);
9571 end if;
9572
9573 elsif Is_Overloaded (Exp) then
9574 Error_Pragma_Arg
9575 ("ambiguous argument for pragma%", Exp);
9576
9577 else
9578 Resolve (Exp);
9579 end if;
9580
9581 Next (Arg);
9582 end loop;
9583 end if;
9584 end Annotate;
9585
9586 -------------------------------------------------
9587 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
9588 -------------------------------------------------
9589
9590 -- pragma Assert
9591 -- ( [Check => ] Boolean_EXPRESSION
9592 -- [, [Message =>] Static_String_EXPRESSION]);
9593
9594 -- pragma Assert_And_Cut
9595 -- ( [Check => ] Boolean_EXPRESSION
9596 -- [, [Message =>] Static_String_EXPRESSION]);
9597
9598 -- pragma Assume
9599 -- ( [Check => ] Boolean_EXPRESSION
9600 -- [, [Message =>] Static_String_EXPRESSION]);
9601
9602 -- pragma Loop_Invariant
9603 -- ( [Check => ] Boolean_EXPRESSION
9604 -- [, [Message =>] Static_String_EXPRESSION]);
9605
9606 when Pragma_Assert |
9607 Pragma_Assert_And_Cut |
9608 Pragma_Assume |
9609 Pragma_Loop_Invariant =>
9610 Assert : declare
9611 Expr : Node_Id;
9612 Newa : List_Id;
9613
9614 begin
9615 -- Assert is an Ada 2005 RM-defined pragma
9616
9617 if Prag_Id = Pragma_Assert then
9618 Ada_2005_Pragma;
9619
9620 -- The remaining ones are GNAT pragmas
9621
9622 else
9623 GNAT_Pragma;
9624 end if;
9625
9626 Check_At_Least_N_Arguments (1);
9627 Check_At_Most_N_Arguments (2);
9628 Check_Arg_Order ((Name_Check, Name_Message));
9629 Check_Optional_Identifier (Arg1, Name_Check);
9630
9631 -- Special processing for Loop_Invariant
9632
9633 if Prag_Id = Pragma_Loop_Invariant then
9634
9635 -- Check restricted placement, must be within a loop
9636
9637 Check_Loop_Pragma_Placement;
9638
9639 -- Do preanalyze to deal with embedded Loop_Entry attribute
9640
9641 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
9642 end if;
9643
9644 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
9645 -- a corresponding Check pragma:
9646
9647 -- pragma Check (name, condition [, msg]);
9648
9649 -- Where name is the identifier matching the pragma name. So
9650 -- rewrite pragma in this manner, transfer the message argument
9651 -- if present, and analyze the result
9652
9653 -- Note: When dealing with a semantically analyzed tree, the
9654 -- information that a Check node N corresponds to a source Assert,
9655 -- Assume, or Assert_And_Cut pragma can be retrieved from the
9656 -- pragma kind of Original_Node(N).
9657
9658 Expr := Get_Pragma_Arg (Arg1);
9659 Newa := New_List (
9660 Make_Pragma_Argument_Association (Loc,
9661 Expression => Make_Identifier (Loc, Pname)),
9662 Make_Pragma_Argument_Association (Sloc (Expr),
9663 Expression => Expr));
9664
9665 if Arg_Count > 1 then
9666 Check_Optional_Identifier (Arg2, Name_Message);
9667 Append_To (Newa, New_Copy_Tree (Arg2));
9668 end if;
9669
9670 -- Rewrite as Check pragma
9671
9672 Rewrite (N,
9673 Make_Pragma (Loc,
9674 Chars => Name_Check,
9675 Pragma_Argument_Associations => Newa));
9676 Analyze (N);
9677 end Assert;
9678
9679 ----------------------
9680 -- Assertion_Policy --
9681 ----------------------
9682
9683 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
9684
9685 -- The following form is Ada 2012 only, but we allow it in all modes
9686
9687 -- Pragma Assertion_Policy (
9688 -- ASSERTION_KIND => POLICY_IDENTIFIER
9689 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
9690
9691 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
9692
9693 -- RM_ASSERTION_KIND ::= Assert |
9694 -- Static_Predicate |
9695 -- Dynamic_Predicate |
9696 -- Pre |
9697 -- Pre'Class |
9698 -- Post |
9699 -- Post'Class |
9700 -- Type_Invariant |
9701 -- Type_Invariant'Class
9702
9703 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
9704 -- Assume |
9705 -- Contract_Cases |
9706 -- Debug |
9707 -- Loop_Invariant |
9708 -- Loop_Variant |
9709 -- Postcondition |
9710 -- Precondition |
9711 -- Predicate |
9712 -- Refined_Post |
9713 -- Refined_Pre |
9714 -- Statement_Assertions
9715
9716 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
9717 -- ID_ASSERTION_KIND list contains implementation-defined additions
9718 -- recognized by GNAT. The effect is to control the behavior of
9719 -- identically named aspects and pragmas, depending on the specified
9720 -- policy identifier:
9721
9722 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
9723
9724 -- Note: Check and Ignore are language-defined. Disable is a GNAT
9725 -- implementation defined addition that results in totally ignoring
9726 -- the corresponding assertion. If Disable is specified, then the
9727 -- argument of the assertion is not even analyzed. This is useful
9728 -- when the aspect/pragma argument references entities in a with'ed
9729 -- package that is replaced by a dummy package in the final build.
9730
9731 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
9732 -- and Type_Invariant'Class were recognized by the parser and
9733 -- transformed into references to the special internal identifiers
9734 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
9735 -- processing is required here.
9736
9737 when Pragma_Assertion_Policy => Assertion_Policy : declare
9738 LocP : Source_Ptr;
9739 Policy : Node_Id;
9740 Arg : Node_Id;
9741 Kind : Name_Id;
9742
9743 begin
9744 Ada_2005_Pragma;
9745
9746 -- This can always appear as a configuration pragma
9747
9748 if Is_Configuration_Pragma then
9749 null;
9750
9751 -- It can also appear in a declarative part or package spec in Ada
9752 -- 2012 mode. We allow this in other modes, but in that case we
9753 -- consider that we have an Ada 2012 pragma on our hands.
9754
9755 else
9756 Check_Is_In_Decl_Part_Or_Package_Spec;
9757 Ada_2012_Pragma;
9758 end if;
9759
9760 -- One argument case with no identifier (first form above)
9761
9762 if Arg_Count = 1
9763 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
9764 or else Chars (Arg1) = No_Name)
9765 then
9766 Check_Arg_Is_One_Of
9767 (Arg1, Name_Check, Name_Disable, Name_Ignore);
9768
9769 -- Treat one argument Assertion_Policy as equivalent to:
9770
9771 -- pragma Check_Policy (Assertion, policy)
9772
9773 -- So rewrite pragma in that manner and link on to the chain
9774 -- of Check_Policy pragmas, marking the pragma as analyzed.
9775
9776 Policy := Get_Pragma_Arg (Arg1);
9777
9778 Rewrite (N,
9779 Make_Pragma (Loc,
9780 Chars => Name_Check_Policy,
9781 Pragma_Argument_Associations => New_List (
9782 Make_Pragma_Argument_Association (Loc,
9783 Expression => Make_Identifier (Loc, Name_Assertion)),
9784
9785 Make_Pragma_Argument_Association (Loc,
9786 Expression =>
9787 Make_Identifier (Sloc (Policy), Chars (Policy))))));
9788 Analyze (N);
9789
9790 -- Here if we have two or more arguments
9791
9792 else
9793 Check_At_Least_N_Arguments (1);
9794 Ada_2012_Pragma;
9795
9796 -- Loop through arguments
9797
9798 Arg := Arg1;
9799 while Present (Arg) loop
9800 LocP := Sloc (Arg);
9801
9802 -- Kind must be specified
9803
9804 if Nkind (Arg) /= N_Pragma_Argument_Association
9805 or else Chars (Arg) = No_Name
9806 then
9807 Error_Pragma_Arg
9808 ("missing assertion kind for pragma%", Arg);
9809 end if;
9810
9811 -- Check Kind and Policy have allowed forms
9812
9813 Kind := Chars (Arg);
9814
9815 if not Is_Valid_Assertion_Kind (Kind) then
9816 Error_Pragma_Arg
9817 ("invalid assertion kind for pragma%", Arg);
9818 end if;
9819
9820 Check_Arg_Is_One_Of
9821 (Arg, Name_Check, Name_Disable, Name_Ignore);
9822
9823 -- We rewrite the Assertion_Policy pragma as a series of
9824 -- Check_Policy pragmas:
9825
9826 -- Check_Policy (Kind, Policy);
9827
9828 Insert_Action (N,
9829 Make_Pragma (LocP,
9830 Chars => Name_Check_Policy,
9831 Pragma_Argument_Associations => New_List (
9832 Make_Pragma_Argument_Association (LocP,
9833 Expression => Make_Identifier (LocP, Kind)),
9834 Make_Pragma_Argument_Association (LocP,
9835 Expression => Get_Pragma_Arg (Arg)))));
9836
9837 Arg := Next (Arg);
9838 end loop;
9839
9840 -- Rewrite the Assertion_Policy pragma as null since we have
9841 -- now inserted all the equivalent Check pragmas.
9842
9843 Rewrite (N, Make_Null_Statement (Loc));
9844 Analyze (N);
9845 end if;
9846 end Assertion_Policy;
9847
9848 ------------------------------
9849 -- Assume_No_Invalid_Values --
9850 ------------------------------
9851
9852 -- pragma Assume_No_Invalid_Values (On | Off);
9853
9854 when Pragma_Assume_No_Invalid_Values =>
9855 GNAT_Pragma;
9856 Check_Valid_Configuration_Pragma;
9857 Check_Arg_Count (1);
9858 Check_No_Identifiers;
9859 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9860
9861 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9862 Assume_No_Invalid_Values := True;
9863 else
9864 Assume_No_Invalid_Values := False;
9865 end if;
9866
9867 --------------------------
9868 -- Attribute_Definition --
9869 --------------------------
9870
9871 -- pragma Attribute_Definition
9872 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
9873 -- [Entity =>] LOCAL_NAME,
9874 -- [Expression =>] EXPRESSION | NAME);
9875
9876 when Pragma_Attribute_Definition => Attribute_Definition : declare
9877 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
9878 Aname : Name_Id;
9879
9880 begin
9881 GNAT_Pragma;
9882 Check_Arg_Count (3);
9883 Check_Optional_Identifier (Arg1, "attribute");
9884 Check_Optional_Identifier (Arg2, "entity");
9885 Check_Optional_Identifier (Arg3, "expression");
9886
9887 if Nkind (Attribute_Designator) /= N_Identifier then
9888 Error_Msg_N ("attribute name expected", Attribute_Designator);
9889 return;
9890 end if;
9891
9892 Check_Arg_Is_Local_Name (Arg2);
9893
9894 -- If the attribute is not recognized, then issue a warning (not
9895 -- an error), and ignore the pragma.
9896
9897 Aname := Chars (Attribute_Designator);
9898
9899 if not Is_Attribute_Name (Aname) then
9900 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
9901 return;
9902 end if;
9903
9904 -- Otherwise, rewrite the pragma as an attribute definition clause
9905
9906 Rewrite (N,
9907 Make_Attribute_Definition_Clause (Loc,
9908 Name => Get_Pragma_Arg (Arg2),
9909 Chars => Aname,
9910 Expression => Get_Pragma_Arg (Arg3)));
9911 Analyze (N);
9912 end Attribute_Definition;
9913
9914 ---------------
9915 -- AST_Entry --
9916 ---------------
9917
9918 -- pragma AST_Entry (entry_IDENTIFIER);
9919
9920 when Pragma_AST_Entry => AST_Entry : declare
9921 Ent : Node_Id;
9922
9923 begin
9924 GNAT_Pragma;
9925 Check_VMS (N);
9926 Check_Arg_Count (1);
9927 Check_No_Identifiers;
9928 Check_Arg_Is_Local_Name (Arg1);
9929 Ent := Entity (Get_Pragma_Arg (Arg1));
9930
9931 -- Note: the implementation of the AST_Entry pragma could handle
9932 -- the entry family case fine, but for now we are consistent with
9933 -- the DEC rules, and do not allow the pragma, which of course
9934 -- has the effect of also forbidding the attribute.
9935
9936 if Ekind (Ent) /= E_Entry then
9937 Error_Pragma_Arg
9938 ("pragma% argument must be simple entry name", Arg1);
9939
9940 elsif Is_AST_Entry (Ent) then
9941 Error_Pragma_Arg
9942 ("duplicate % pragma for entry", Arg1);
9943
9944 elsif Has_Homonym (Ent) then
9945 Error_Pragma_Arg
9946 ("pragma% argument cannot specify overloaded entry", Arg1);
9947
9948 else
9949 declare
9950 FF : constant Entity_Id := First_Formal (Ent);
9951
9952 begin
9953 if Present (FF) then
9954 if Present (Next_Formal (FF)) then
9955 Error_Pragma_Arg
9956 ("entry for pragma% can have only one argument",
9957 Arg1);
9958
9959 elsif Parameter_Mode (FF) /= E_In_Parameter then
9960 Error_Pragma_Arg
9961 ("entry parameter for pragma% must have mode IN",
9962 Arg1);
9963 end if;
9964 end if;
9965 end;
9966
9967 Set_Is_AST_Entry (Ent);
9968 end if;
9969 end AST_Entry;
9970
9971 ------------------
9972 -- Asynchronous --
9973 ------------------
9974
9975 -- pragma Asynchronous (LOCAL_NAME);
9976
9977 when Pragma_Asynchronous => Asynchronous : declare
9978 Nm : Entity_Id;
9979 C_Ent : Entity_Id;
9980 L : List_Id;
9981 S : Node_Id;
9982 N : Node_Id;
9983 Formal : Entity_Id;
9984
9985 procedure Process_Async_Pragma;
9986 -- Common processing for procedure and access-to-procedure case
9987
9988 --------------------------
9989 -- Process_Async_Pragma --
9990 --------------------------
9991
9992 procedure Process_Async_Pragma is
9993 begin
9994 if No (L) then
9995 Set_Is_Asynchronous (Nm);
9996 return;
9997 end if;
9998
9999 -- The formals should be of mode IN (RM E.4.1(6))
10000
10001 S := First (L);
10002 while Present (S) loop
10003 Formal := Defining_Identifier (S);
10004
10005 if Nkind (Formal) = N_Defining_Identifier
10006 and then Ekind (Formal) /= E_In_Parameter
10007 then
10008 Error_Pragma_Arg
10009 ("pragma% procedure can only have IN parameter",
10010 Arg1);
10011 end if;
10012
10013 Next (S);
10014 end loop;
10015
10016 Set_Is_Asynchronous (Nm);
10017 end Process_Async_Pragma;
10018
10019 -- Start of processing for pragma Asynchronous
10020
10021 begin
10022 Check_Ada_83_Warning;
10023 Check_No_Identifiers;
10024 Check_Arg_Count (1);
10025 Check_Arg_Is_Local_Name (Arg1);
10026
10027 if Debug_Flag_U then
10028 return;
10029 end if;
10030
10031 C_Ent := Cunit_Entity (Current_Sem_Unit);
10032 Analyze (Get_Pragma_Arg (Arg1));
10033 Nm := Entity (Get_Pragma_Arg (Arg1));
10034
10035 if not Is_Remote_Call_Interface (C_Ent)
10036 and then not Is_Remote_Types (C_Ent)
10037 then
10038 -- This pragma should only appear in an RCI or Remote Types
10039 -- unit (RM E.4.1(4)).
10040
10041 Error_Pragma
10042 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
10043 end if;
10044
10045 if Ekind (Nm) = E_Procedure
10046 and then Nkind (Parent (Nm)) = N_Procedure_Specification
10047 then
10048 if not Is_Remote_Call_Interface (Nm) then
10049 Error_Pragma_Arg
10050 ("pragma% cannot be applied on non-remote procedure",
10051 Arg1);
10052 end if;
10053
10054 L := Parameter_Specifications (Parent (Nm));
10055 Process_Async_Pragma;
10056 return;
10057
10058 elsif Ekind (Nm) = E_Function then
10059 Error_Pragma_Arg
10060 ("pragma% cannot be applied to function", Arg1);
10061
10062 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
10063 if Is_Record_Type (Nm) then
10064
10065 -- A record type that is the Equivalent_Type for a remote
10066 -- access-to-subprogram type.
10067
10068 N := Declaration_Node (Corresponding_Remote_Type (Nm));
10069
10070 else
10071 -- A non-expanded RAS type (distribution is not enabled)
10072
10073 N := Declaration_Node (Nm);
10074 end if;
10075
10076 if Nkind (N) = N_Full_Type_Declaration
10077 and then Nkind (Type_Definition (N)) =
10078 N_Access_Procedure_Definition
10079 then
10080 L := Parameter_Specifications (Type_Definition (N));
10081 Process_Async_Pragma;
10082
10083 if Is_Asynchronous (Nm)
10084 and then Expander_Active
10085 and then Get_PCS_Name /= Name_No_DSA
10086 then
10087 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
10088 end if;
10089
10090 else
10091 Error_Pragma_Arg
10092 ("pragma% cannot reference access-to-function type",
10093 Arg1);
10094 end if;
10095
10096 -- Only other possibility is Access-to-class-wide type
10097
10098 elsif Is_Access_Type (Nm)
10099 and then Is_Class_Wide_Type (Designated_Type (Nm))
10100 then
10101 Check_First_Subtype (Arg1);
10102 Set_Is_Asynchronous (Nm);
10103 if Expander_Active then
10104 RACW_Type_Is_Asynchronous (Nm);
10105 end if;
10106
10107 else
10108 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
10109 end if;
10110 end Asynchronous;
10111
10112 ------------
10113 -- Atomic --
10114 ------------
10115
10116 -- pragma Atomic (LOCAL_NAME);
10117
10118 when Pragma_Atomic =>
10119 Process_Atomic_Shared_Volatile;
10120
10121 -----------------------
10122 -- Atomic_Components --
10123 -----------------------
10124
10125 -- pragma Atomic_Components (array_LOCAL_NAME);
10126
10127 -- This processing is shared by Volatile_Components
10128
10129 when Pragma_Atomic_Components |
10130 Pragma_Volatile_Components =>
10131
10132 Atomic_Components : declare
10133 E_Id : Node_Id;
10134 E : Entity_Id;
10135 D : Node_Id;
10136 K : Node_Kind;
10137
10138 begin
10139 Check_Ada_83_Warning;
10140 Check_No_Identifiers;
10141 Check_Arg_Count (1);
10142 Check_Arg_Is_Local_Name (Arg1);
10143 E_Id := Get_Pragma_Arg (Arg1);
10144
10145 if Etype (E_Id) = Any_Type then
10146 return;
10147 end if;
10148
10149 E := Entity (E_Id);
10150
10151 Check_Duplicate_Pragma (E);
10152
10153 if Rep_Item_Too_Early (E, N)
10154 or else
10155 Rep_Item_Too_Late (E, N)
10156 then
10157 return;
10158 end if;
10159
10160 D := Declaration_Node (E);
10161 K := Nkind (D);
10162
10163 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
10164 or else
10165 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
10166 and then Nkind (D) = N_Object_Declaration
10167 and then Nkind (Object_Definition (D)) =
10168 N_Constrained_Array_Definition)
10169 then
10170 -- The flag is set on the object, or on the base type
10171
10172 if Nkind (D) /= N_Object_Declaration then
10173 E := Base_Type (E);
10174 end if;
10175
10176 Set_Has_Volatile_Components (E);
10177
10178 if Prag_Id = Pragma_Atomic_Components then
10179 Set_Has_Atomic_Components (E);
10180 end if;
10181
10182 else
10183 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
10184 end if;
10185 end Atomic_Components;
10186
10187 --------------------
10188 -- Attach_Handler --
10189 --------------------
10190
10191 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
10192
10193 when Pragma_Attach_Handler =>
10194 Check_Ada_83_Warning;
10195 Check_No_Identifiers;
10196 Check_Arg_Count (2);
10197
10198 if No_Run_Time_Mode then
10199 Error_Msg_CRT ("Attach_Handler pragma", N);
10200 else
10201 Check_Interrupt_Or_Attach_Handler;
10202
10203 -- The expression that designates the attribute may depend on a
10204 -- discriminant, and is therefore a per-object expression, to
10205 -- be expanded in the init proc. If expansion is enabled, then
10206 -- perform semantic checks on a copy only.
10207
10208 if Expander_Active then
10209 declare
10210 Temp : constant Node_Id :=
10211 New_Copy_Tree (Get_Pragma_Arg (Arg2));
10212 begin
10213 Set_Parent (Temp, N);
10214 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
10215 end;
10216
10217 else
10218 Analyze (Get_Pragma_Arg (Arg2));
10219 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
10220 end if;
10221
10222 Process_Interrupt_Or_Attach_Handler;
10223 end if;
10224
10225 --------------------
10226 -- C_Pass_By_Copy --
10227 --------------------
10228
10229 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
10230
10231 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
10232 Arg : Node_Id;
10233 Val : Uint;
10234
10235 begin
10236 GNAT_Pragma;
10237 Check_Valid_Configuration_Pragma;
10238 Check_Arg_Count (1);
10239 Check_Optional_Identifier (Arg1, "max_size");
10240
10241 Arg := Get_Pragma_Arg (Arg1);
10242 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
10243
10244 Val := Expr_Value (Arg);
10245
10246 if Val <= 0 then
10247 Error_Pragma_Arg
10248 ("maximum size for pragma% must be positive", Arg1);
10249
10250 elsif UI_Is_In_Int_Range (Val) then
10251 Default_C_Record_Mechanism := UI_To_Int (Val);
10252
10253 -- If a giant value is given, Int'Last will do well enough.
10254 -- If sometime someone complains that a record larger than
10255 -- two gigabytes is not copied, we will worry about it then!
10256
10257 else
10258 Default_C_Record_Mechanism := Mechanism_Type'Last;
10259 end if;
10260 end C_Pass_By_Copy;
10261
10262 -----------
10263 -- Check --
10264 -----------
10265
10266 -- pragma Check ([Name =>] CHECK_KIND,
10267 -- [Check =>] Boolean_EXPRESSION
10268 -- [,[Message =>] String_EXPRESSION]);
10269
10270 -- CHECK_KIND ::= IDENTIFIER |
10271 -- Pre'Class |
10272 -- Post'Class |
10273 -- Invariant'Class |
10274 -- Type_Invariant'Class
10275
10276 -- The identifiers Assertions and Statement_Assertions are not
10277 -- allowed, since they have special meaning for Check_Policy.
10278
10279 when Pragma_Check => Check : declare
10280 Expr : Node_Id;
10281 Eloc : Source_Ptr;
10282 Cname : Name_Id;
10283 Str : Node_Id;
10284
10285 begin
10286 GNAT_Pragma;
10287 Check_At_Least_N_Arguments (2);
10288 Check_At_Most_N_Arguments (3);
10289 Check_Optional_Identifier (Arg1, Name_Name);
10290 Check_Optional_Identifier (Arg2, Name_Check);
10291
10292 if Arg_Count = 3 then
10293 Check_Optional_Identifier (Arg3, Name_Message);
10294 Str := Get_Pragma_Arg (Arg3);
10295 end if;
10296
10297 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
10298 Check_Arg_Is_Identifier (Arg1);
10299 Cname := Chars (Get_Pragma_Arg (Arg1));
10300
10301 -- Check forbidden name Assertions or Statement_Assertions
10302
10303 case Cname is
10304 when Name_Assertions =>
10305 Error_Pragma_Arg
10306 ("""Assertions"" is not allowed as a check kind "
10307 & "for pragma%", Arg1);
10308
10309 when Name_Statement_Assertions =>
10310 Error_Pragma_Arg
10311 ("""Statement_Assertions"" is not allowed as a check kind "
10312 & "for pragma%", Arg1);
10313
10314 when others =>
10315 null;
10316 end case;
10317
10318 -- Check applicable policy. We skip this if Checked/Ignored status
10319 -- is already set (e.g. in the casse of a pragma from an aspect).
10320
10321 if Is_Checked (N) or else Is_Ignored (N) then
10322 null;
10323
10324 -- For a non-source pragma that is a rewriting of another pragma,
10325 -- copy the Is_Checked/Ignored status from the rewritten pragma.
10326
10327 elsif Is_Rewrite_Substitution (N)
10328 and then Nkind (Original_Node (N)) = N_Pragma
10329 and then Original_Node (N) /= N
10330 then
10331 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10332 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10333
10334 -- Otherwise query the applicable policy at this point
10335
10336 else
10337 case Check_Kind (Cname) is
10338 when Name_Ignore =>
10339 Set_Is_Ignored (N, True);
10340 Set_Is_Checked (N, False);
10341
10342 when Name_Check =>
10343 Set_Is_Ignored (N, False);
10344 Set_Is_Checked (N, True);
10345
10346 -- For disable, rewrite pragma as null statement and skip
10347 -- rest of the analysis of the pragma.
10348
10349 when Name_Disable =>
10350 Rewrite (N, Make_Null_Statement (Loc));
10351 Analyze (N);
10352 raise Pragma_Exit;
10353
10354 -- No other possibilities
10355
10356 when others =>
10357 raise Program_Error;
10358 end case;
10359 end if;
10360
10361 -- If check kind was not Disable, then continue pragma analysis
10362
10363 Expr := Get_Pragma_Arg (Arg2);
10364
10365 -- Deal with SCO generation
10366
10367 case Cname is
10368 when Name_Predicate |
10369 Name_Invariant =>
10370
10371 -- Nothing to do: since checks occur in client units,
10372 -- the SCO for the aspect in the declaration unit is
10373 -- conservatively always enabled.
10374
10375 null;
10376
10377 when others =>
10378
10379 if Is_Checked (N) and then not Split_PPC (N) then
10380
10381 -- Mark aspect/pragma SCO as enabled
10382
10383 Set_SCO_Pragma_Enabled (Loc);
10384 end if;
10385 end case;
10386
10387 -- Deal with analyzing the string argument.
10388
10389 if Arg_Count = 3 then
10390
10391 -- If checks are not on we don't want any expansion (since
10392 -- such expansion would not get properly deleted) but
10393 -- we do want to analyze (to get proper references).
10394 -- The Preanalyze_And_Resolve routine does just what we want
10395
10396 if Is_Ignored (N) then
10397 Preanalyze_And_Resolve (Str, Standard_String);
10398
10399 -- Otherwise we need a proper analysis and expansion
10400
10401 else
10402 Analyze_And_Resolve (Str, Standard_String);
10403 end if;
10404 end if;
10405
10406 -- Now you might think we could just do the same with the Boolean
10407 -- expression if checks are off (and expansion is on) and then
10408 -- rewrite the check as a null statement. This would work but we
10409 -- would lose the useful warnings about an assertion being bound
10410 -- to fail even if assertions are turned off.
10411
10412 -- So instead we wrap the boolean expression in an if statement
10413 -- that looks like:
10414
10415 -- if False and then condition then
10416 -- null;
10417 -- end if;
10418
10419 -- The reason we do this rewriting during semantic analysis rather
10420 -- than as part of normal expansion is that we cannot analyze and
10421 -- expand the code for the boolean expression directly, or it may
10422 -- cause insertion of actions that would escape the attempt to
10423 -- suppress the check code.
10424
10425 -- Note that the Sloc for the if statement corresponds to the
10426 -- argument condition, not the pragma itself. The reason for
10427 -- this is that we may generate a warning if the condition is
10428 -- False at compile time, and we do not want to delete this
10429 -- warning when we delete the if statement.
10430
10431 if Expander_Active and Is_Ignored (N) then
10432 Eloc := Sloc (Expr);
10433
10434 Rewrite (N,
10435 Make_If_Statement (Eloc,
10436 Condition =>
10437 Make_And_Then (Eloc,
10438 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
10439 Right_Opnd => Expr),
10440 Then_Statements => New_List (
10441 Make_Null_Statement (Eloc))));
10442
10443 In_Assertion_Expr := In_Assertion_Expr + 1;
10444 Analyze (N);
10445 In_Assertion_Expr := In_Assertion_Expr - 1;
10446
10447 -- Check is active or expansion not active. In these cases we can
10448 -- just go ahead and analyze the boolean with no worries.
10449
10450 else
10451 In_Assertion_Expr := In_Assertion_Expr + 1;
10452 Analyze_And_Resolve (Expr, Any_Boolean);
10453 In_Assertion_Expr := In_Assertion_Expr - 1;
10454 end if;
10455 end Check;
10456
10457 --------------------------
10458 -- Check_Float_Overflow --
10459 --------------------------
10460
10461 -- pragma Check_Float_Overflow;
10462
10463 when Pragma_Check_Float_Overflow =>
10464 GNAT_Pragma;
10465 Check_Valid_Configuration_Pragma;
10466 Check_Arg_Count (0);
10467 Check_Float_Overflow := True;
10468
10469 ----------------
10470 -- Check_Name --
10471 ----------------
10472
10473 -- pragma Check_Name (check_IDENTIFIER);
10474
10475 when Pragma_Check_Name =>
10476 GNAT_Pragma;
10477 Check_No_Identifiers;
10478 Check_Valid_Configuration_Pragma;
10479 Check_Arg_Count (1);
10480 Check_Arg_Is_Identifier (Arg1);
10481
10482 declare
10483 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10484
10485 begin
10486 for J in Check_Names.First .. Check_Names.Last loop
10487 if Check_Names.Table (J) = Nam then
10488 return;
10489 end if;
10490 end loop;
10491
10492 Check_Names.Append (Nam);
10493 end;
10494
10495 ------------------
10496 -- Check_Policy --
10497 ------------------
10498
10499 -- This is the old style syntax, which is still allowed in all modes:
10500
10501 -- pragma Check_Policy ([Name =>] CHECK_KIND
10502 -- [Policy =>] POLICY_IDENTIFIER);
10503
10504 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
10505
10506 -- CHECK_KIND ::= IDENTIFIER |
10507 -- Pre'Class |
10508 -- Post'Class |
10509 -- Type_Invariant'Class |
10510 -- Invariant'Class
10511
10512 -- This is the new style syntax, compatible with Assertion_Policy
10513 -- and also allowed in all modes.
10514
10515 -- Pragma Check_Policy (
10516 -- CHECK_KIND => POLICY_IDENTIFIER
10517 -- {, CHECK_KIND => POLICY_IDENTIFIER});
10518
10519 -- Note: the identifiers Name and Policy are not allowed as
10520 -- Check_Kind values. This avoids ambiguities between the old and
10521 -- new form syntax.
10522
10523 when Pragma_Check_Policy => Check_Policy : declare
10524 Kind : Node_Id;
10525
10526 begin
10527 GNAT_Pragma;
10528 Check_At_Least_N_Arguments (1);
10529
10530 -- A Check_Policy pragma can appear either as a configuration
10531 -- pragma, or in a declarative part or a package spec (see RM
10532 -- 11.5(5) for rules for Suppress/Unsuppress which are also
10533 -- followed for Check_Policy).
10534
10535 if not Is_Configuration_Pragma then
10536 Check_Is_In_Decl_Part_Or_Package_Spec;
10537 end if;
10538
10539 -- Figure out if we have the old or new syntax. We have the
10540 -- old syntax if the first argument has no identifier, or the
10541 -- identifier is Name.
10542
10543 if Nkind (Arg1) /= N_Pragma_Argument_Association
10544 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
10545 then
10546 -- Old syntax
10547
10548 Check_Arg_Count (2);
10549 Check_Optional_Identifier (Arg1, Name_Name);
10550 Kind := Get_Pragma_Arg (Arg1);
10551 Rewrite_Assertion_Kind (Kind);
10552 Check_Arg_Is_Identifier (Arg1);
10553
10554 -- Check forbidden check kind
10555
10556 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
10557 Error_Msg_Name_2 := Chars (Kind);
10558 Error_Pragma_Arg
10559 ("pragma% does not allow% as check name", Arg1);
10560 end if;
10561
10562 -- Check policy
10563
10564 Check_Optional_Identifier (Arg2, Name_Policy);
10565 Check_Arg_Is_One_Of
10566 (Arg2,
10567 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
10568
10569 -- And chain pragma on the Check_Policy_List for search
10570
10571 Set_Next_Pragma (N, Opt.Check_Policy_List);
10572 Opt.Check_Policy_List := N;
10573
10574 -- For the new syntax, what we do is to convert each argument to
10575 -- an old syntax equivalent. We do that because we want to chain
10576 -- old style Check_Policy pragmas for the search (we don't want
10577 -- to have to deal with multiple arguments in the search).
10578
10579 else
10580 declare
10581 Arg : Node_Id;
10582 Argx : Node_Id;
10583 LocP : Source_Ptr;
10584
10585 begin
10586 Arg := Arg1;
10587 while Present (Arg) loop
10588 LocP := Sloc (Arg);
10589 Argx := Get_Pragma_Arg (Arg);
10590
10591 -- Kind must be specified
10592
10593 if Nkind (Arg) /= N_Pragma_Argument_Association
10594 or else Chars (Arg) = No_Name
10595 then
10596 Error_Pragma_Arg
10597 ("missing assertion kind for pragma%", Arg);
10598 end if;
10599
10600 -- Construct equivalent old form syntax Check_Policy
10601 -- pragma and insert it to get remaining checks.
10602
10603 Insert_Action (N,
10604 Make_Pragma (LocP,
10605 Chars => Name_Check_Policy,
10606 Pragma_Argument_Associations => New_List (
10607 Make_Pragma_Argument_Association (LocP,
10608 Expression =>
10609 Make_Identifier (LocP, Chars (Arg))),
10610 Make_Pragma_Argument_Association (Sloc (Argx),
10611 Expression => Argx))));
10612
10613 Arg := Next (Arg);
10614 end loop;
10615
10616 -- Rewrite original Check_Policy pragma to null, since we
10617 -- have converted it into a series of old syntax pragmas.
10618
10619 Rewrite (N, Make_Null_Statement (Loc));
10620 Analyze (N);
10621 end;
10622 end if;
10623 end Check_Policy;
10624
10625 ---------------------
10626 -- CIL_Constructor --
10627 ---------------------
10628
10629 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
10630
10631 -- Processing for this pragma is shared with Java_Constructor
10632
10633 -------------
10634 -- Comment --
10635 -------------
10636
10637 -- pragma Comment (static_string_EXPRESSION)
10638
10639 -- Processing for pragma Comment shares the circuitry for pragma
10640 -- Ident. The only differences are that Ident enforces a limit of 31
10641 -- characters on its argument, and also enforces limitations on
10642 -- placement for DEC compatibility. Pragma Comment shares neither of
10643 -- these restrictions.
10644
10645 -------------------
10646 -- Common_Object --
10647 -------------------
10648
10649 -- pragma Common_Object (
10650 -- [Internal =>] LOCAL_NAME
10651 -- [, [External =>] EXTERNAL_SYMBOL]
10652 -- [, [Size =>] EXTERNAL_SYMBOL]);
10653
10654 -- Processing for this pragma is shared with Psect_Object
10655
10656 ------------------------
10657 -- Compile_Time_Error --
10658 ------------------------
10659
10660 -- pragma Compile_Time_Error
10661 -- (boolean_EXPRESSION, static_string_EXPRESSION);
10662
10663 when Pragma_Compile_Time_Error =>
10664 GNAT_Pragma;
10665 Process_Compile_Time_Warning_Or_Error;
10666
10667 --------------------------
10668 -- Compile_Time_Warning --
10669 --------------------------
10670
10671 -- pragma Compile_Time_Warning
10672 -- (boolean_EXPRESSION, static_string_EXPRESSION);
10673
10674 when Pragma_Compile_Time_Warning =>
10675 GNAT_Pragma;
10676 Process_Compile_Time_Warning_Or_Error;
10677
10678 -------------------
10679 -- Compiler_Unit --
10680 -------------------
10681
10682 when Pragma_Compiler_Unit =>
10683 GNAT_Pragma;
10684 Check_Arg_Count (0);
10685 Set_Is_Compiler_Unit (Get_Source_Unit (N));
10686
10687 -----------------------------
10688 -- Complete_Representation --
10689 -----------------------------
10690
10691 -- pragma Complete_Representation;
10692
10693 when Pragma_Complete_Representation =>
10694 GNAT_Pragma;
10695 Check_Arg_Count (0);
10696
10697 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
10698 Error_Pragma
10699 ("pragma & must appear within record representation clause");
10700 end if;
10701
10702 ----------------------------
10703 -- Complex_Representation --
10704 ----------------------------
10705
10706 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
10707
10708 when Pragma_Complex_Representation => Complex_Representation : declare
10709 E_Id : Entity_Id;
10710 E : Entity_Id;
10711 Ent : Entity_Id;
10712
10713 begin
10714 GNAT_Pragma;
10715 Check_Arg_Count (1);
10716 Check_Optional_Identifier (Arg1, Name_Entity);
10717 Check_Arg_Is_Local_Name (Arg1);
10718 E_Id := Get_Pragma_Arg (Arg1);
10719
10720 if Etype (E_Id) = Any_Type then
10721 return;
10722 end if;
10723
10724 E := Entity (E_Id);
10725
10726 if not Is_Record_Type (E) then
10727 Error_Pragma_Arg
10728 ("argument for pragma% must be record type", Arg1);
10729 end if;
10730
10731 Ent := First_Entity (E);
10732
10733 if No (Ent)
10734 or else No (Next_Entity (Ent))
10735 or else Present (Next_Entity (Next_Entity (Ent)))
10736 or else not Is_Floating_Point_Type (Etype (Ent))
10737 or else Etype (Ent) /= Etype (Next_Entity (Ent))
10738 then
10739 Error_Pragma_Arg
10740 ("record for pragma% must have two fields of the same "
10741 & "floating-point type", Arg1);
10742
10743 else
10744 Set_Has_Complex_Representation (Base_Type (E));
10745
10746 -- We need to treat the type has having a non-standard
10747 -- representation, for back-end purposes, even though in
10748 -- general a complex will have the default representation
10749 -- of a record with two real components.
10750
10751 Set_Has_Non_Standard_Rep (Base_Type (E));
10752 end if;
10753 end Complex_Representation;
10754
10755 -------------------------
10756 -- Component_Alignment --
10757 -------------------------
10758
10759 -- pragma Component_Alignment (
10760 -- [Form =>] ALIGNMENT_CHOICE
10761 -- [, [Name =>] type_LOCAL_NAME]);
10762 --
10763 -- ALIGNMENT_CHOICE ::=
10764 -- Component_Size
10765 -- | Component_Size_4
10766 -- | Storage_Unit
10767 -- | Default
10768
10769 when Pragma_Component_Alignment => Component_AlignmentP : declare
10770 Args : Args_List (1 .. 2);
10771 Names : constant Name_List (1 .. 2) := (
10772 Name_Form,
10773 Name_Name);
10774
10775 Form : Node_Id renames Args (1);
10776 Name : Node_Id renames Args (2);
10777
10778 Atype : Component_Alignment_Kind;
10779 Typ : Entity_Id;
10780
10781 begin
10782 GNAT_Pragma;
10783 Gather_Associations (Names, Args);
10784
10785 if No (Form) then
10786 Error_Pragma ("missing Form argument for pragma%");
10787 end if;
10788
10789 Check_Arg_Is_Identifier (Form);
10790
10791 -- Get proper alignment, note that Default = Component_Size on all
10792 -- machines we have so far, and we want to set this value rather
10793 -- than the default value to indicate that it has been explicitly
10794 -- set (and thus will not get overridden by the default component
10795 -- alignment for the current scope)
10796
10797 if Chars (Form) = Name_Component_Size then
10798 Atype := Calign_Component_Size;
10799
10800 elsif Chars (Form) = Name_Component_Size_4 then
10801 Atype := Calign_Component_Size_4;
10802
10803 elsif Chars (Form) = Name_Default then
10804 Atype := Calign_Component_Size;
10805
10806 elsif Chars (Form) = Name_Storage_Unit then
10807 Atype := Calign_Storage_Unit;
10808
10809 else
10810 Error_Pragma_Arg
10811 ("invalid Form parameter for pragma%", Form);
10812 end if;
10813
10814 -- Case with no name, supplied, affects scope table entry
10815
10816 if No (Name) then
10817 Scope_Stack.Table
10818 (Scope_Stack.Last).Component_Alignment_Default := Atype;
10819
10820 -- Case of name supplied
10821
10822 else
10823 Check_Arg_Is_Local_Name (Name);
10824 Find_Type (Name);
10825 Typ := Entity (Name);
10826
10827 if Typ = Any_Type
10828 or else Rep_Item_Too_Early (Typ, N)
10829 then
10830 return;
10831 else
10832 Typ := Underlying_Type (Typ);
10833 end if;
10834
10835 if not Is_Record_Type (Typ)
10836 and then not Is_Array_Type (Typ)
10837 then
10838 Error_Pragma_Arg
10839 ("Name parameter of pragma% must identify record or "
10840 & "array type", Name);
10841 end if;
10842
10843 -- An explicit Component_Alignment pragma overrides an
10844 -- implicit pragma Pack, but not an explicit one.
10845
10846 if not Has_Pragma_Pack (Base_Type (Typ)) then
10847 Set_Is_Packed (Base_Type (Typ), False);
10848 Set_Component_Alignment (Base_Type (Typ), Atype);
10849 end if;
10850 end if;
10851 end Component_AlignmentP;
10852
10853 --------------------
10854 -- Contract_Cases --
10855 --------------------
10856
10857 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
10858
10859 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
10860
10861 -- CASE_GUARD ::= boolean_EXPRESSION | others
10862
10863 -- CONSEQUENCE ::= boolean_EXPRESSION
10864
10865 when Pragma_Contract_Cases => Contract_Cases : declare
10866 Subp_Decl : Node_Id;
10867
10868 begin
10869 GNAT_Pragma;
10870 Check_Arg_Count (1);
10871
10872 -- Ensure the proper placement of the pragma. Contract_Cases must
10873 -- be associated with a subprogram declaration or a body that acts
10874 -- as a spec.
10875
10876 Subp_Decl :=
10877 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
10878
10879 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
10880 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
10881 or else not Acts_As_Spec (Subp_Decl))
10882 then
10883 Pragma_Misplaced;
10884 return;
10885 end if;
10886
10887 -- The pragma is analyzed at the end of the declarative part which
10888 -- contains the related subprogram. Reset the analyzed flag.
10889
10890 Set_Analyzed (N, False);
10891
10892 -- When the pragma appears on a subprogram body, perform the full
10893 -- analysis now.
10894
10895 if Nkind (Subp_Decl) = N_Subprogram_Body then
10896 Analyze_Contract_Cases_In_Decl_Part (N);
10897
10898 -- When Contract_Cases applies to a subprogram compilation unit,
10899 -- the corresponding pragma is placed after the unit's declaration
10900 -- node and needs to be analyzed immediately.
10901
10902 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
10903 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
10904 then
10905 Analyze_Contract_Cases_In_Decl_Part (N);
10906 end if;
10907
10908 -- Chain the pragma on the contract for further processing
10909
10910 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
10911 end Contract_Cases;
10912
10913 ----------------
10914 -- Controlled --
10915 ----------------
10916
10917 -- pragma Controlled (first_subtype_LOCAL_NAME);
10918
10919 when Pragma_Controlled => Controlled : declare
10920 Arg : Node_Id;
10921
10922 begin
10923 Check_No_Identifiers;
10924 Check_Arg_Count (1);
10925 Check_Arg_Is_Local_Name (Arg1);
10926 Arg := Get_Pragma_Arg (Arg1);
10927
10928 if not Is_Entity_Name (Arg)
10929 or else not Is_Access_Type (Entity (Arg))
10930 then
10931 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10932 else
10933 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
10934 end if;
10935 end Controlled;
10936
10937 ----------------
10938 -- Convention --
10939 ----------------
10940
10941 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
10942 -- [Entity =>] LOCAL_NAME);
10943
10944 when Pragma_Convention => Convention : declare
10945 C : Convention_Id;
10946 E : Entity_Id;
10947 pragma Warnings (Off, C);
10948 pragma Warnings (Off, E);
10949 begin
10950 Check_Arg_Order ((Name_Convention, Name_Entity));
10951 Check_Ada_83_Warning;
10952 Check_Arg_Count (2);
10953 Process_Convention (C, E);
10954 end Convention;
10955
10956 ---------------------------
10957 -- Convention_Identifier --
10958 ---------------------------
10959
10960 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
10961 -- [Convention =>] convention_IDENTIFIER);
10962
10963 when Pragma_Convention_Identifier => Convention_Identifier : declare
10964 Idnam : Name_Id;
10965 Cname : Name_Id;
10966
10967 begin
10968 GNAT_Pragma;
10969 Check_Arg_Order ((Name_Name, Name_Convention));
10970 Check_Arg_Count (2);
10971 Check_Optional_Identifier (Arg1, Name_Name);
10972 Check_Optional_Identifier (Arg2, Name_Convention);
10973 Check_Arg_Is_Identifier (Arg1);
10974 Check_Arg_Is_Identifier (Arg2);
10975 Idnam := Chars (Get_Pragma_Arg (Arg1));
10976 Cname := Chars (Get_Pragma_Arg (Arg2));
10977
10978 if Is_Convention_Name (Cname) then
10979 Record_Convention_Identifier
10980 (Idnam, Get_Convention_Id (Cname));
10981 else
10982 Error_Pragma_Arg
10983 ("second arg for % pragma must be convention", Arg2);
10984 end if;
10985 end Convention_Identifier;
10986
10987 ---------------
10988 -- CPP_Class --
10989 ---------------
10990
10991 -- pragma CPP_Class ([Entity =>] local_NAME)
10992
10993 when Pragma_CPP_Class => CPP_Class : declare
10994 begin
10995 GNAT_Pragma;
10996
10997 if Warn_On_Obsolescent_Feature then
10998 Error_Msg_N
10999 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
11000 & "effect; replace it by pragma import?j?", N);
11001 end if;
11002
11003 Check_Arg_Count (1);
11004
11005 Rewrite (N,
11006 Make_Pragma (Loc,
11007 Chars => Name_Import,
11008 Pragma_Argument_Associations => New_List (
11009 Make_Pragma_Argument_Association (Loc,
11010 Expression => Make_Identifier (Loc, Name_CPP)),
11011 New_Copy (First (Pragma_Argument_Associations (N))))));
11012 Analyze (N);
11013 end CPP_Class;
11014
11015 ---------------------
11016 -- CPP_Constructor --
11017 ---------------------
11018
11019 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
11020 -- [, [External_Name =>] static_string_EXPRESSION ]
11021 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11022
11023 when Pragma_CPP_Constructor => CPP_Constructor : declare
11024 Elmt : Elmt_Id;
11025 Id : Entity_Id;
11026 Def_Id : Entity_Id;
11027 Tag_Typ : Entity_Id;
11028
11029 begin
11030 GNAT_Pragma;
11031 Check_At_Least_N_Arguments (1);
11032 Check_At_Most_N_Arguments (3);
11033 Check_Optional_Identifier (Arg1, Name_Entity);
11034 Check_Arg_Is_Local_Name (Arg1);
11035
11036 Id := Get_Pragma_Arg (Arg1);
11037 Find_Program_Unit_Name (Id);
11038
11039 -- If we did not find the name, we are done
11040
11041 if Etype (Id) = Any_Type then
11042 return;
11043 end if;
11044
11045 Def_Id := Entity (Id);
11046
11047 -- Check if already defined as constructor
11048
11049 if Is_Constructor (Def_Id) then
11050 Error_Msg_N
11051 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
11052 return;
11053 end if;
11054
11055 if Ekind (Def_Id) = E_Function
11056 and then (Is_CPP_Class (Etype (Def_Id))
11057 or else (Is_Class_Wide_Type (Etype (Def_Id))
11058 and then
11059 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
11060 then
11061 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
11062 Error_Msg_N
11063 ("'C'P'P constructor must be defined in the scope of "
11064 & "its returned type", Arg1);
11065 end if;
11066
11067 if Arg_Count >= 2 then
11068 Set_Imported (Def_Id);
11069 Set_Is_Public (Def_Id);
11070 Process_Interface_Name (Def_Id, Arg2, Arg3);
11071 end if;
11072
11073 Set_Has_Completion (Def_Id);
11074 Set_Is_Constructor (Def_Id);
11075 Set_Convention (Def_Id, Convention_CPP);
11076
11077 -- Imported C++ constructors are not dispatching primitives
11078 -- because in C++ they don't have a dispatch table slot.
11079 -- However, in Ada the constructor has the profile of a
11080 -- function that returns a tagged type and therefore it has
11081 -- been treated as a primitive operation during semantic
11082 -- analysis. We now remove it from the list of primitive
11083 -- operations of the type.
11084
11085 if Is_Tagged_Type (Etype (Def_Id))
11086 and then not Is_Class_Wide_Type (Etype (Def_Id))
11087 and then Is_Dispatching_Operation (Def_Id)
11088 then
11089 Tag_Typ := Etype (Def_Id);
11090
11091 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
11092 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
11093 Next_Elmt (Elmt);
11094 end loop;
11095
11096 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
11097 Set_Is_Dispatching_Operation (Def_Id, False);
11098 end if;
11099
11100 -- For backward compatibility, if the constructor returns a
11101 -- class wide type, and we internally change the return type to
11102 -- the corresponding root type.
11103
11104 if Is_Class_Wide_Type (Etype (Def_Id)) then
11105 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
11106 end if;
11107 else
11108 Error_Pragma_Arg
11109 ("pragma% requires function returning a 'C'P'P_Class type",
11110 Arg1);
11111 end if;
11112 end CPP_Constructor;
11113
11114 -----------------
11115 -- CPP_Virtual --
11116 -----------------
11117
11118 when Pragma_CPP_Virtual => CPP_Virtual : declare
11119 begin
11120 GNAT_Pragma;
11121
11122 if Warn_On_Obsolescent_Feature then
11123 Error_Msg_N
11124 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
11125 & "effect?j?", N);
11126 end if;
11127 end CPP_Virtual;
11128
11129 ----------------
11130 -- CPP_Vtable --
11131 ----------------
11132
11133 when Pragma_CPP_Vtable => CPP_Vtable : declare
11134 begin
11135 GNAT_Pragma;
11136
11137 if Warn_On_Obsolescent_Feature then
11138 Error_Msg_N
11139 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
11140 & "effect?j?", N);
11141 end if;
11142 end CPP_Vtable;
11143
11144 ---------
11145 -- CPU --
11146 ---------
11147
11148 -- pragma CPU (EXPRESSION);
11149
11150 when Pragma_CPU => CPU : declare
11151 P : constant Node_Id := Parent (N);
11152 Arg : Node_Id;
11153 Ent : Entity_Id;
11154
11155 begin
11156 Ada_2012_Pragma;
11157 Check_No_Identifiers;
11158 Check_Arg_Count (1);
11159
11160 -- Subprogram case
11161
11162 if Nkind (P) = N_Subprogram_Body then
11163 Check_In_Main_Program;
11164
11165 Arg := Get_Pragma_Arg (Arg1);
11166 Analyze_And_Resolve (Arg, Any_Integer);
11167
11168 Ent := Defining_Unit_Name (Specification (P));
11169
11170 if Nkind (Ent) = N_Defining_Program_Unit_Name then
11171 Ent := Defining_Identifier (Ent);
11172 end if;
11173
11174 -- Must be static
11175
11176 if not Is_Static_Expression (Arg) then
11177 Flag_Non_Static_Expr
11178 ("main subprogram affinity is not static!", Arg);
11179 raise Pragma_Exit;
11180
11181 -- If constraint error, then we already signalled an error
11182
11183 elsif Raises_Constraint_Error (Arg) then
11184 null;
11185
11186 -- Otherwise check in range
11187
11188 else
11189 declare
11190 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
11191 -- This is the entity System.Multiprocessors.CPU_Range;
11192
11193 Val : constant Uint := Expr_Value (Arg);
11194
11195 begin
11196 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
11197 or else
11198 Val > Expr_Value (Type_High_Bound (CPU_Id))
11199 then
11200 Error_Pragma_Arg
11201 ("main subprogram CPU is out of range", Arg1);
11202 end if;
11203 end;
11204 end if;
11205
11206 Set_Main_CPU
11207 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11208
11209 -- Task case
11210
11211 elsif Nkind (P) = N_Task_Definition then
11212 Arg := Get_Pragma_Arg (Arg1);
11213 Ent := Defining_Identifier (Parent (P));
11214
11215 -- The expression must be analyzed in the special manner
11216 -- described in "Handling of Default and Per-Object
11217 -- Expressions" in sem.ads.
11218
11219 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
11220
11221 -- Anything else is incorrect
11222
11223 else
11224 Pragma_Misplaced;
11225 end if;
11226
11227 -- Check duplicate pragma before we chain the pragma in the Rep
11228 -- Item chain of Ent.
11229
11230 Check_Duplicate_Pragma (Ent);
11231 Record_Rep_Item (Ent, N);
11232 end CPU;
11233
11234 -----------
11235 -- Debug --
11236 -----------
11237
11238 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
11239
11240 when Pragma_Debug => Debug : declare
11241 Cond : Node_Id;
11242 Call : Node_Id;
11243
11244 begin
11245 GNAT_Pragma;
11246
11247 -- The condition for executing the call is that the expander
11248 -- is active and that we are not ignoring this debug pragma.
11249
11250 Cond :=
11251 New_Occurrence_Of
11252 (Boolean_Literals
11253 (Expander_Active and then not Is_Ignored (N)),
11254 Loc);
11255
11256 if not Is_Ignored (N) then
11257 Set_SCO_Pragma_Enabled (Loc);
11258 end if;
11259
11260 if Arg_Count = 2 then
11261 Cond :=
11262 Make_And_Then (Loc,
11263 Left_Opnd => Relocate_Node (Cond),
11264 Right_Opnd => Get_Pragma_Arg (Arg1));
11265 Call := Get_Pragma_Arg (Arg2);
11266 else
11267 Call := Get_Pragma_Arg (Arg1);
11268 end if;
11269
11270 if Nkind_In (Call,
11271 N_Indexed_Component,
11272 N_Function_Call,
11273 N_Identifier,
11274 N_Expanded_Name,
11275 N_Selected_Component)
11276 then
11277 -- If this pragma Debug comes from source, its argument was
11278 -- parsed as a name form (which is syntactically identical).
11279 -- In a generic context a parameterless call will be left as
11280 -- an expanded name (if global) or selected_component if local.
11281 -- Change it to a procedure call statement now.
11282
11283 Change_Name_To_Procedure_Call_Statement (Call);
11284
11285 elsif Nkind (Call) = N_Procedure_Call_Statement then
11286
11287 -- Already in the form of a procedure call statement: nothing
11288 -- to do (could happen in case of an internally generated
11289 -- pragma Debug).
11290
11291 null;
11292
11293 else
11294 -- All other cases: diagnose error
11295
11296 Error_Msg
11297 ("argument of pragma ""Debug"" is not procedure call",
11298 Sloc (Call));
11299 return;
11300 end if;
11301
11302 -- Rewrite into a conditional with an appropriate condition. We
11303 -- wrap the procedure call in a block so that overhead from e.g.
11304 -- use of the secondary stack does not generate execution overhead
11305 -- for suppressed conditions.
11306
11307 -- Normally the analysis that follows will freeze the subprogram
11308 -- being called. However, if the call is to a null procedure,
11309 -- we want to freeze it before creating the block, because the
11310 -- analysis that follows may be done with expansion disabled, in
11311 -- which case the body will not be generated, leading to spurious
11312 -- errors.
11313
11314 if Nkind (Call) = N_Procedure_Call_Statement
11315 and then Is_Entity_Name (Name (Call))
11316 then
11317 Analyze (Name (Call));
11318 Freeze_Before (N, Entity (Name (Call)));
11319 end if;
11320
11321 Rewrite (N, Make_Implicit_If_Statement (N,
11322 Condition => Cond,
11323 Then_Statements => New_List (
11324 Make_Block_Statement (Loc,
11325 Handled_Statement_Sequence =>
11326 Make_Handled_Sequence_Of_Statements (Loc,
11327 Statements => New_List (Relocate_Node (Call)))))));
11328 Analyze (N);
11329 end Debug;
11330
11331 ------------------
11332 -- Debug_Policy --
11333 ------------------
11334
11335 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
11336
11337 when Pragma_Debug_Policy =>
11338 GNAT_Pragma;
11339 Check_Arg_Count (1);
11340 Check_No_Identifiers;
11341 Check_Arg_Is_Identifier (Arg1);
11342
11343 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
11344 -- rewrite it that way, and let the rest of the checking come
11345 -- from analyzing the rewritten pragma.
11346
11347 Rewrite (N,
11348 Make_Pragma (Loc,
11349 Chars => Name_Check_Policy,
11350 Pragma_Argument_Associations => New_List (
11351 Make_Pragma_Argument_Association (Loc,
11352 Expression => Make_Identifier (Loc, Name_Debug)),
11353
11354 Make_Pragma_Argument_Association (Loc,
11355 Expression => Get_Pragma_Arg (Arg1)))));
11356 Analyze (N);
11357
11358 -------------
11359 -- Depends --
11360 -------------
11361
11362 -- pragma Depends (DEPENDENCY_RELATION);
11363
11364 -- DEPENDENCY_RELATION ::=
11365 -- null
11366 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
11367
11368 -- DEPENDENCY_CLAUSE ::=
11369 -- OUTPUT_LIST =>[+] INPUT_LIST
11370 -- | NULL_DEPENDENCY_CLAUSE
11371
11372 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
11373
11374 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
11375
11376 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
11377
11378 -- OUTPUT ::= NAME | FUNCTION_RESULT
11379 -- INPUT ::= NAME
11380
11381 -- where FUNCTION_RESULT is a function Result attribute_reference
11382
11383 when Pragma_Depends => Depends : declare
11384 Subp_Decl : Node_Id;
11385
11386 begin
11387 GNAT_Pragma;
11388 S14_Pragma;
11389 Check_Arg_Count (1);
11390
11391 -- Ensure the proper placement of the pragma. Depends must be
11392 -- associated with a subprogram declaration or a body that acts
11393 -- as a spec.
11394
11395 Subp_Decl :=
11396 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
11397
11398 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
11399 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
11400 or else not Acts_As_Spec (Subp_Decl))
11401 then
11402 Pragma_Misplaced;
11403 return;
11404 end if;
11405
11406 -- When the pragma appears on a subprogram body, perform the full
11407 -- analysis now.
11408
11409 if Nkind (Subp_Decl) = N_Subprogram_Body then
11410 Analyze_Depends_In_Decl_Part (N);
11411
11412 -- When Depends applies to a subprogram compilation unit, the
11413 -- corresponding pragma is placed after the unit's declaration
11414 -- node and needs to be analyzed immediately.
11415
11416 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
11417 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
11418 then
11419 Analyze_Depends_In_Decl_Part (N);
11420 end if;
11421
11422 -- Chain the pragma on the contract for further processing
11423
11424 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
11425 end Depends;
11426
11427 ---------------------
11428 -- Detect_Blocking --
11429 ---------------------
11430
11431 -- pragma Detect_Blocking;
11432
11433 when Pragma_Detect_Blocking =>
11434 Ada_2005_Pragma;
11435 Check_Arg_Count (0);
11436 Check_Valid_Configuration_Pragma;
11437 Detect_Blocking := True;
11438
11439 --------------------------
11440 -- Default_Storage_Pool --
11441 --------------------------
11442
11443 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
11444
11445 when Pragma_Default_Storage_Pool =>
11446 Ada_2012_Pragma;
11447 Check_Arg_Count (1);
11448
11449 -- Default_Storage_Pool can appear as a configuration pragma, or
11450 -- in a declarative part or a package spec.
11451
11452 if not Is_Configuration_Pragma then
11453 Check_Is_In_Decl_Part_Or_Package_Spec;
11454 end if;
11455
11456 -- Case of Default_Storage_Pool (null);
11457
11458 if Nkind (Expression (Arg1)) = N_Null then
11459 Analyze (Expression (Arg1));
11460
11461 -- This is an odd case, this is not really an expression, so
11462 -- we don't have a type for it. So just set the type to Empty.
11463
11464 Set_Etype (Expression (Arg1), Empty);
11465
11466 -- Case of Default_Storage_Pool (storage_pool_NAME);
11467
11468 else
11469 -- If it's a configuration pragma, then the only allowed
11470 -- argument is "null".
11471
11472 if Is_Configuration_Pragma then
11473 Error_Pragma_Arg ("NULL expected", Arg1);
11474 end if;
11475
11476 -- The expected type for a non-"null" argument is
11477 -- Root_Storage_Pool'Class.
11478
11479 Analyze_And_Resolve
11480 (Get_Pragma_Arg (Arg1),
11481 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
11482 end if;
11483
11484 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
11485 -- for an access type will use this information to set the
11486 -- appropriate attributes of the access type.
11487
11488 Default_Pool := Expression (Arg1);
11489
11490 ------------------------------------
11491 -- Disable_Atomic_Synchronization --
11492 ------------------------------------
11493
11494 -- pragma Disable_Atomic_Synchronization [(Entity)];
11495
11496 when Pragma_Disable_Atomic_Synchronization =>
11497 GNAT_Pragma;
11498 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
11499
11500 -------------------
11501 -- Discard_Names --
11502 -------------------
11503
11504 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
11505
11506 when Pragma_Discard_Names => Discard_Names : declare
11507 E : Entity_Id;
11508 E_Id : Entity_Id;
11509
11510 begin
11511 Check_Ada_83_Warning;
11512
11513 -- Deal with configuration pragma case
11514
11515 if Arg_Count = 0 and then Is_Configuration_Pragma then
11516 Global_Discard_Names := True;
11517 return;
11518
11519 -- Otherwise, check correct appropriate context
11520
11521 else
11522 Check_Is_In_Decl_Part_Or_Package_Spec;
11523
11524 if Arg_Count = 0 then
11525
11526 -- If there is no parameter, then from now on this pragma
11527 -- applies to any enumeration, exception or tagged type
11528 -- defined in the current declarative part, and recursively
11529 -- to any nested scope.
11530
11531 Set_Discard_Names (Current_Scope);
11532 return;
11533
11534 else
11535 Check_Arg_Count (1);
11536 Check_Optional_Identifier (Arg1, Name_On);
11537 Check_Arg_Is_Local_Name (Arg1);
11538
11539 E_Id := Get_Pragma_Arg (Arg1);
11540
11541 if Etype (E_Id) = Any_Type then
11542 return;
11543 else
11544 E := Entity (E_Id);
11545 end if;
11546
11547 if (Is_First_Subtype (E)
11548 and then
11549 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
11550 or else Ekind (E) = E_Exception
11551 then
11552 Set_Discard_Names (E);
11553 Record_Rep_Item (E, N);
11554
11555 else
11556 Error_Pragma_Arg
11557 ("inappropriate entity for pragma%", Arg1);
11558 end if;
11559
11560 end if;
11561 end if;
11562 end Discard_Names;
11563
11564 ------------------------
11565 -- Dispatching_Domain --
11566 ------------------------
11567
11568 -- pragma Dispatching_Domain (EXPRESSION);
11569
11570 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
11571 P : constant Node_Id := Parent (N);
11572 Arg : Node_Id;
11573 Ent : Entity_Id;
11574
11575 begin
11576 Ada_2012_Pragma;
11577 Check_No_Identifiers;
11578 Check_Arg_Count (1);
11579
11580 -- This pragma is born obsolete, but not the aspect
11581
11582 if not From_Aspect_Specification (N) then
11583 Check_Restriction
11584 (No_Obsolescent_Features, Pragma_Identifier (N));
11585 end if;
11586
11587 if Nkind (P) = N_Task_Definition then
11588 Arg := Get_Pragma_Arg (Arg1);
11589 Ent := Defining_Identifier (Parent (P));
11590
11591 -- The expression must be analyzed in the special manner
11592 -- described in "Handling of Default and Per-Object
11593 -- Expressions" in sem.ads.
11594
11595 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
11596
11597 -- Check duplicate pragma before we chain the pragma in the Rep
11598 -- Item chain of Ent.
11599
11600 Check_Duplicate_Pragma (Ent);
11601 Record_Rep_Item (Ent, N);
11602
11603 -- Anything else is incorrect
11604
11605 else
11606 Pragma_Misplaced;
11607 end if;
11608 end Dispatching_Domain;
11609
11610 ---------------
11611 -- Elaborate --
11612 ---------------
11613
11614 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
11615
11616 when Pragma_Elaborate => Elaborate : declare
11617 Arg : Node_Id;
11618 Citem : Node_Id;
11619
11620 begin
11621 -- Pragma must be in context items list of a compilation unit
11622
11623 if not Is_In_Context_Clause then
11624 Pragma_Misplaced;
11625 end if;
11626
11627 -- Must be at least one argument
11628
11629 if Arg_Count = 0 then
11630 Error_Pragma ("pragma% requires at least one argument");
11631 end if;
11632
11633 -- In Ada 83 mode, there can be no items following it in the
11634 -- context list except other pragmas and implicit with clauses
11635 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
11636 -- placement rule does not apply.
11637
11638 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
11639 Citem := Next (N);
11640 while Present (Citem) loop
11641 if Nkind (Citem) = N_Pragma
11642 or else (Nkind (Citem) = N_With_Clause
11643 and then Implicit_With (Citem))
11644 then
11645 null;
11646 else
11647 Error_Pragma
11648 ("(Ada 83) pragma% must be at end of context clause");
11649 end if;
11650
11651 Next (Citem);
11652 end loop;
11653 end if;
11654
11655 -- Finally, the arguments must all be units mentioned in a with
11656 -- clause in the same context clause. Note we already checked (in
11657 -- Par.Prag) that the arguments are all identifiers or selected
11658 -- components.
11659
11660 Arg := Arg1;
11661 Outer : while Present (Arg) loop
11662 Citem := First (List_Containing (N));
11663 Inner : while Citem /= N loop
11664 if Nkind (Citem) = N_With_Clause
11665 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
11666 then
11667 Set_Elaborate_Present (Citem, True);
11668 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
11669 Generate_Reference (Entity (Name (Citem)), Citem);
11670
11671 -- With the pragma present, elaboration calls on
11672 -- subprograms from the named unit need no further
11673 -- checks, as long as the pragma appears in the current
11674 -- compilation unit. If the pragma appears in some unit
11675 -- in the context, there might still be a need for an
11676 -- Elaborate_All_Desirable from the current compilation
11677 -- to the named unit, so we keep the check enabled.
11678
11679 if In_Extended_Main_Source_Unit (N) then
11680 Set_Suppress_Elaboration_Warnings
11681 (Entity (Name (Citem)));
11682 end if;
11683
11684 exit Inner;
11685 end if;
11686
11687 Next (Citem);
11688 end loop Inner;
11689
11690 if Citem = N then
11691 Error_Pragma_Arg
11692 ("argument of pragma% is not withed unit", Arg);
11693 end if;
11694
11695 Next (Arg);
11696 end loop Outer;
11697
11698 -- Give a warning if operating in static mode with -gnatwl
11699 -- (elaboration warnings enabled) switch set.
11700
11701 if Elab_Warnings and not Dynamic_Elaboration_Checks then
11702 Error_Msg_N
11703 ("?l?use of pragma Elaborate may not be safe", N);
11704 Error_Msg_N
11705 ("?l?use pragma Elaborate_All instead if possible", N);
11706 end if;
11707 end Elaborate;
11708
11709 -------------------
11710 -- Elaborate_All --
11711 -------------------
11712
11713 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
11714
11715 when Pragma_Elaborate_All => Elaborate_All : declare
11716 Arg : Node_Id;
11717 Citem : Node_Id;
11718
11719 begin
11720 Check_Ada_83_Warning;
11721
11722 -- Pragma must be in context items list of a compilation unit
11723
11724 if not Is_In_Context_Clause then
11725 Pragma_Misplaced;
11726 end if;
11727
11728 -- Must be at least one argument
11729
11730 if Arg_Count = 0 then
11731 Error_Pragma ("pragma% requires at least one argument");
11732 end if;
11733
11734 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
11735 -- have to appear at the end of the context clause, but may
11736 -- appear mixed in with other items, even in Ada 83 mode.
11737
11738 -- Final check: the arguments must all be units mentioned in
11739 -- a with clause in the same context clause. Note that we
11740 -- already checked (in Par.Prag) that all the arguments are
11741 -- either identifiers or selected components.
11742
11743 Arg := Arg1;
11744 Outr : while Present (Arg) loop
11745 Citem := First (List_Containing (N));
11746 Innr : while Citem /= N loop
11747 if Nkind (Citem) = N_With_Clause
11748 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
11749 then
11750 Set_Elaborate_All_Present (Citem, True);
11751 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
11752
11753 -- Suppress warnings and elaboration checks on the named
11754 -- unit if the pragma is in the current compilation, as
11755 -- for pragma Elaborate.
11756
11757 if In_Extended_Main_Source_Unit (N) then
11758 Set_Suppress_Elaboration_Warnings
11759 (Entity (Name (Citem)));
11760 end if;
11761 exit Innr;
11762 end if;
11763
11764 Next (Citem);
11765 end loop Innr;
11766
11767 if Citem = N then
11768 Set_Error_Posted (N);
11769 Error_Pragma_Arg
11770 ("argument of pragma% is not withed unit", Arg);
11771 end if;
11772
11773 Next (Arg);
11774 end loop Outr;
11775 end Elaborate_All;
11776
11777 --------------------
11778 -- Elaborate_Body --
11779 --------------------
11780
11781 -- pragma Elaborate_Body [( library_unit_NAME )];
11782
11783 when Pragma_Elaborate_Body => Elaborate_Body : declare
11784 Cunit_Node : Node_Id;
11785 Cunit_Ent : Entity_Id;
11786
11787 begin
11788 Check_Ada_83_Warning;
11789 Check_Valid_Library_Unit_Pragma;
11790
11791 if Nkind (N) = N_Null_Statement then
11792 return;
11793 end if;
11794
11795 Cunit_Node := Cunit (Current_Sem_Unit);
11796 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11797
11798 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
11799 N_Subprogram_Body)
11800 then
11801 Error_Pragma ("pragma% must refer to a spec, not a body");
11802 else
11803 Set_Body_Required (Cunit_Node, True);
11804 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
11805
11806 -- If we are in dynamic elaboration mode, then we suppress
11807 -- elaboration warnings for the unit, since it is definitely
11808 -- fine NOT to do dynamic checks at the first level (and such
11809 -- checks will be suppressed because no elaboration boolean
11810 -- is created for Elaborate_Body packages).
11811
11812 -- But in the static model of elaboration, Elaborate_Body is
11813 -- definitely NOT good enough to ensure elaboration safety on
11814 -- its own, since the body may WITH other units that are not
11815 -- safe from an elaboration point of view, so a client must
11816 -- still do an Elaborate_All on such units.
11817
11818 -- Debug flag -gnatdD restores the old behavior of 3.13, where
11819 -- Elaborate_Body always suppressed elab warnings.
11820
11821 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
11822 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
11823 end if;
11824 end if;
11825 end Elaborate_Body;
11826
11827 ------------------------
11828 -- Elaboration_Checks --
11829 ------------------------
11830
11831 -- pragma Elaboration_Checks (Static | Dynamic);
11832
11833 when Pragma_Elaboration_Checks =>
11834 GNAT_Pragma;
11835 Check_Arg_Count (1);
11836 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
11837 Dynamic_Elaboration_Checks :=
11838 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
11839
11840 ---------------
11841 -- Eliminate --
11842 ---------------
11843
11844 -- pragma Eliminate (
11845 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
11846 -- [,[Entity =>] IDENTIFIER |
11847 -- SELECTED_COMPONENT |
11848 -- STRING_LITERAL]
11849 -- [, OVERLOADING_RESOLUTION]);
11850
11851 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
11852 -- SOURCE_LOCATION
11853
11854 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
11855 -- FUNCTION_PROFILE
11856
11857 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
11858
11859 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
11860 -- Result_Type => result_SUBTYPE_NAME]
11861
11862 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
11863 -- SUBTYPE_NAME ::= STRING_LITERAL
11864
11865 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
11866 -- SOURCE_TRACE ::= STRING_LITERAL
11867
11868 when Pragma_Eliminate => Eliminate : declare
11869 Args : Args_List (1 .. 5);
11870 Names : constant Name_List (1 .. 5) := (
11871 Name_Unit_Name,
11872 Name_Entity,
11873 Name_Parameter_Types,
11874 Name_Result_Type,
11875 Name_Source_Location);
11876
11877 Unit_Name : Node_Id renames Args (1);
11878 Entity : Node_Id renames Args (2);
11879 Parameter_Types : Node_Id renames Args (3);
11880 Result_Type : Node_Id renames Args (4);
11881 Source_Location : Node_Id renames Args (5);
11882
11883 begin
11884 GNAT_Pragma;
11885 Check_Valid_Configuration_Pragma;
11886 Gather_Associations (Names, Args);
11887
11888 if No (Unit_Name) then
11889 Error_Pragma ("missing Unit_Name argument for pragma%");
11890 end if;
11891
11892 if No (Entity)
11893 and then (Present (Parameter_Types)
11894 or else
11895 Present (Result_Type)
11896 or else
11897 Present (Source_Location))
11898 then
11899 Error_Pragma ("missing Entity argument for pragma%");
11900 end if;
11901
11902 if (Present (Parameter_Types)
11903 or else
11904 Present (Result_Type))
11905 and then
11906 Present (Source_Location)
11907 then
11908 Error_Pragma
11909 ("parameter profile and source location cannot be used "
11910 & "together in pragma%");
11911 end if;
11912
11913 Process_Eliminate_Pragma
11914 (N,
11915 Unit_Name,
11916 Entity,
11917 Parameter_Types,
11918 Result_Type,
11919 Source_Location);
11920 end Eliminate;
11921
11922 -----------------------------------
11923 -- Enable_Atomic_Synchronization --
11924 -----------------------------------
11925
11926 -- pragma Enable_Atomic_Synchronization [(Entity)];
11927
11928 when Pragma_Enable_Atomic_Synchronization =>
11929 GNAT_Pragma;
11930 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
11931
11932 ------------
11933 -- Export --
11934 ------------
11935
11936 -- pragma Export (
11937 -- [ Convention =>] convention_IDENTIFIER,
11938 -- [ Entity =>] local_NAME
11939 -- [, [External_Name =>] static_string_EXPRESSION ]
11940 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11941
11942 when Pragma_Export => Export : declare
11943 C : Convention_Id;
11944 Def_Id : Entity_Id;
11945
11946 pragma Warnings (Off, C);
11947
11948 begin
11949 Check_Ada_83_Warning;
11950 Check_Arg_Order
11951 ((Name_Convention,
11952 Name_Entity,
11953 Name_External_Name,
11954 Name_Link_Name));
11955
11956 Check_At_Least_N_Arguments (2);
11957 Check_At_Most_N_Arguments (4);
11958 Process_Convention (C, Def_Id);
11959
11960 if Ekind (Def_Id) /= E_Constant then
11961 Note_Possible_Modification
11962 (Get_Pragma_Arg (Arg2), Sure => False);
11963 end if;
11964
11965 Process_Interface_Name (Def_Id, Arg3, Arg4);
11966 Set_Exported (Def_Id, Arg2);
11967
11968 -- If the entity is a deferred constant, propagate the information
11969 -- to the full view, because gigi elaborates the full view only.
11970
11971 if Ekind (Def_Id) = E_Constant
11972 and then Present (Full_View (Def_Id))
11973 then
11974 declare
11975 Id2 : constant Entity_Id := Full_View (Def_Id);
11976 begin
11977 Set_Is_Exported (Id2, Is_Exported (Def_Id));
11978 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
11979 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
11980 end;
11981 end if;
11982 end Export;
11983
11984 ----------------------
11985 -- Export_Exception --
11986 ----------------------
11987
11988 -- pragma Export_Exception (
11989 -- [Internal =>] LOCAL_NAME
11990 -- [, [External =>] EXTERNAL_SYMBOL]
11991 -- [, [Form =>] Ada | VMS]
11992 -- [, [Code =>] static_integer_EXPRESSION]);
11993
11994 when Pragma_Export_Exception => Export_Exception : declare
11995 Args : Args_List (1 .. 4);
11996 Names : constant Name_List (1 .. 4) := (
11997 Name_Internal,
11998 Name_External,
11999 Name_Form,
12000 Name_Code);
12001
12002 Internal : Node_Id renames Args (1);
12003 External : Node_Id renames Args (2);
12004 Form : Node_Id renames Args (3);
12005 Code : Node_Id renames Args (4);
12006
12007 begin
12008 GNAT_Pragma;
12009
12010 if Inside_A_Generic then
12011 Error_Pragma ("pragma% cannot be used for generic entities");
12012 end if;
12013
12014 Gather_Associations (Names, Args);
12015 Process_Extended_Import_Export_Exception_Pragma (
12016 Arg_Internal => Internal,
12017 Arg_External => External,
12018 Arg_Form => Form,
12019 Arg_Code => Code);
12020
12021 if not Is_VMS_Exception (Entity (Internal)) then
12022 Set_Exported (Entity (Internal), Internal);
12023 end if;
12024 end Export_Exception;
12025
12026 ---------------------
12027 -- Export_Function --
12028 ---------------------
12029
12030 -- pragma Export_Function (
12031 -- [Internal =>] LOCAL_NAME
12032 -- [, [External =>] EXTERNAL_SYMBOL]
12033 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12034 -- [, [Result_Type =>] TYPE_DESIGNATOR]
12035 -- [, [Mechanism =>] MECHANISM]
12036 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
12037
12038 -- EXTERNAL_SYMBOL ::=
12039 -- IDENTIFIER
12040 -- | static_string_EXPRESSION
12041
12042 -- PARAMETER_TYPES ::=
12043 -- null
12044 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12045
12046 -- TYPE_DESIGNATOR ::=
12047 -- subtype_NAME
12048 -- | subtype_Name ' Access
12049
12050 -- MECHANISM ::=
12051 -- MECHANISM_NAME
12052 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12053
12054 -- MECHANISM_ASSOCIATION ::=
12055 -- [formal_parameter_NAME =>] MECHANISM_NAME
12056
12057 -- MECHANISM_NAME ::=
12058 -- Value
12059 -- | Reference
12060 -- | Descriptor [([Class =>] CLASS_NAME)]
12061
12062 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12063
12064 when Pragma_Export_Function => Export_Function : declare
12065 Args : Args_List (1 .. 6);
12066 Names : constant Name_List (1 .. 6) := (
12067 Name_Internal,
12068 Name_External,
12069 Name_Parameter_Types,
12070 Name_Result_Type,
12071 Name_Mechanism,
12072 Name_Result_Mechanism);
12073
12074 Internal : Node_Id renames Args (1);
12075 External : Node_Id renames Args (2);
12076 Parameter_Types : Node_Id renames Args (3);
12077 Result_Type : Node_Id renames Args (4);
12078 Mechanism : Node_Id renames Args (5);
12079 Result_Mechanism : Node_Id renames Args (6);
12080
12081 begin
12082 GNAT_Pragma;
12083 Gather_Associations (Names, Args);
12084 Process_Extended_Import_Export_Subprogram_Pragma (
12085 Arg_Internal => Internal,
12086 Arg_External => External,
12087 Arg_Parameter_Types => Parameter_Types,
12088 Arg_Result_Type => Result_Type,
12089 Arg_Mechanism => Mechanism,
12090 Arg_Result_Mechanism => Result_Mechanism);
12091 end Export_Function;
12092
12093 -------------------
12094 -- Export_Object --
12095 -------------------
12096
12097 -- pragma Export_Object (
12098 -- [Internal =>] LOCAL_NAME
12099 -- [, [External =>] EXTERNAL_SYMBOL]
12100 -- [, [Size =>] EXTERNAL_SYMBOL]);
12101
12102 -- EXTERNAL_SYMBOL ::=
12103 -- IDENTIFIER
12104 -- | static_string_EXPRESSION
12105
12106 -- PARAMETER_TYPES ::=
12107 -- null
12108 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12109
12110 -- TYPE_DESIGNATOR ::=
12111 -- subtype_NAME
12112 -- | subtype_Name ' Access
12113
12114 -- MECHANISM ::=
12115 -- MECHANISM_NAME
12116 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12117
12118 -- MECHANISM_ASSOCIATION ::=
12119 -- [formal_parameter_NAME =>] MECHANISM_NAME
12120
12121 -- MECHANISM_NAME ::=
12122 -- Value
12123 -- | Reference
12124 -- | Descriptor [([Class =>] CLASS_NAME)]
12125
12126 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12127
12128 when Pragma_Export_Object => Export_Object : declare
12129 Args : Args_List (1 .. 3);
12130 Names : constant Name_List (1 .. 3) := (
12131 Name_Internal,
12132 Name_External,
12133 Name_Size);
12134
12135 Internal : Node_Id renames Args (1);
12136 External : Node_Id renames Args (2);
12137 Size : Node_Id renames Args (3);
12138
12139 begin
12140 GNAT_Pragma;
12141 Gather_Associations (Names, Args);
12142 Process_Extended_Import_Export_Object_Pragma (
12143 Arg_Internal => Internal,
12144 Arg_External => External,
12145 Arg_Size => Size);
12146 end Export_Object;
12147
12148 ----------------------
12149 -- Export_Procedure --
12150 ----------------------
12151
12152 -- pragma Export_Procedure (
12153 -- [Internal =>] LOCAL_NAME
12154 -- [, [External =>] EXTERNAL_SYMBOL]
12155 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12156 -- [, [Mechanism =>] MECHANISM]);
12157
12158 -- EXTERNAL_SYMBOL ::=
12159 -- IDENTIFIER
12160 -- | static_string_EXPRESSION
12161
12162 -- PARAMETER_TYPES ::=
12163 -- null
12164 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12165
12166 -- TYPE_DESIGNATOR ::=
12167 -- subtype_NAME
12168 -- | subtype_Name ' Access
12169
12170 -- MECHANISM ::=
12171 -- MECHANISM_NAME
12172 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12173
12174 -- MECHANISM_ASSOCIATION ::=
12175 -- [formal_parameter_NAME =>] MECHANISM_NAME
12176
12177 -- MECHANISM_NAME ::=
12178 -- Value
12179 -- | Reference
12180 -- | Descriptor [([Class =>] CLASS_NAME)]
12181
12182 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12183
12184 when Pragma_Export_Procedure => Export_Procedure : declare
12185 Args : Args_List (1 .. 4);
12186 Names : constant Name_List (1 .. 4) := (
12187 Name_Internal,
12188 Name_External,
12189 Name_Parameter_Types,
12190 Name_Mechanism);
12191
12192 Internal : Node_Id renames Args (1);
12193 External : Node_Id renames Args (2);
12194 Parameter_Types : Node_Id renames Args (3);
12195 Mechanism : Node_Id renames Args (4);
12196
12197 begin
12198 GNAT_Pragma;
12199 Gather_Associations (Names, Args);
12200 Process_Extended_Import_Export_Subprogram_Pragma (
12201 Arg_Internal => Internal,
12202 Arg_External => External,
12203 Arg_Parameter_Types => Parameter_Types,
12204 Arg_Mechanism => Mechanism);
12205 end Export_Procedure;
12206
12207 ------------------
12208 -- Export_Value --
12209 ------------------
12210
12211 -- pragma Export_Value (
12212 -- [Value =>] static_integer_EXPRESSION,
12213 -- [Link_Name =>] static_string_EXPRESSION);
12214
12215 when Pragma_Export_Value =>
12216 GNAT_Pragma;
12217 Check_Arg_Order ((Name_Value, Name_Link_Name));
12218 Check_Arg_Count (2);
12219
12220 Check_Optional_Identifier (Arg1, Name_Value);
12221 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12222
12223 Check_Optional_Identifier (Arg2, Name_Link_Name);
12224 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
12225
12226 -----------------------------
12227 -- Export_Valued_Procedure --
12228 -----------------------------
12229
12230 -- pragma Export_Valued_Procedure (
12231 -- [Internal =>] LOCAL_NAME
12232 -- [, [External =>] EXTERNAL_SYMBOL,]
12233 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12234 -- [, [Mechanism =>] MECHANISM]);
12235
12236 -- EXTERNAL_SYMBOL ::=
12237 -- IDENTIFIER
12238 -- | static_string_EXPRESSION
12239
12240 -- PARAMETER_TYPES ::=
12241 -- null
12242 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12243
12244 -- TYPE_DESIGNATOR ::=
12245 -- subtype_NAME
12246 -- | subtype_Name ' Access
12247
12248 -- MECHANISM ::=
12249 -- MECHANISM_NAME
12250 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12251
12252 -- MECHANISM_ASSOCIATION ::=
12253 -- [formal_parameter_NAME =>] MECHANISM_NAME
12254
12255 -- MECHANISM_NAME ::=
12256 -- Value
12257 -- | Reference
12258 -- | Descriptor [([Class =>] CLASS_NAME)]
12259
12260 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12261
12262 when Pragma_Export_Valued_Procedure =>
12263 Export_Valued_Procedure : declare
12264 Args : Args_List (1 .. 4);
12265 Names : constant Name_List (1 .. 4) := (
12266 Name_Internal,
12267 Name_External,
12268 Name_Parameter_Types,
12269 Name_Mechanism);
12270
12271 Internal : Node_Id renames Args (1);
12272 External : Node_Id renames Args (2);
12273 Parameter_Types : Node_Id renames Args (3);
12274 Mechanism : Node_Id renames Args (4);
12275
12276 begin
12277 GNAT_Pragma;
12278 Gather_Associations (Names, Args);
12279 Process_Extended_Import_Export_Subprogram_Pragma (
12280 Arg_Internal => Internal,
12281 Arg_External => External,
12282 Arg_Parameter_Types => Parameter_Types,
12283 Arg_Mechanism => Mechanism);
12284 end Export_Valued_Procedure;
12285
12286 -------------------
12287 -- Extend_System --
12288 -------------------
12289
12290 -- pragma Extend_System ([Name =>] Identifier);
12291
12292 when Pragma_Extend_System => Extend_System : declare
12293 begin
12294 GNAT_Pragma;
12295 Check_Valid_Configuration_Pragma;
12296 Check_Arg_Count (1);
12297 Check_Optional_Identifier (Arg1, Name_Name);
12298 Check_Arg_Is_Identifier (Arg1);
12299
12300 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12301
12302 if Name_Len > 4
12303 and then Name_Buffer (1 .. 4) = "aux_"
12304 then
12305 if Present (System_Extend_Pragma_Arg) then
12306 if Chars (Get_Pragma_Arg (Arg1)) =
12307 Chars (Expression (System_Extend_Pragma_Arg))
12308 then
12309 null;
12310 else
12311 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
12312 Error_Pragma ("pragma% conflicts with that #");
12313 end if;
12314
12315 else
12316 System_Extend_Pragma_Arg := Arg1;
12317
12318 if not GNAT_Mode then
12319 System_Extend_Unit := Arg1;
12320 end if;
12321 end if;
12322 else
12323 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
12324 end if;
12325 end Extend_System;
12326
12327 ------------------------
12328 -- Extensions_Allowed --
12329 ------------------------
12330
12331 -- pragma Extensions_Allowed (ON | OFF);
12332
12333 when Pragma_Extensions_Allowed =>
12334 GNAT_Pragma;
12335 Check_Arg_Count (1);
12336 Check_No_Identifiers;
12337 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12338
12339 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
12340 Extensions_Allowed := True;
12341 Ada_Version := Ada_Version_Type'Last;
12342
12343 else
12344 Extensions_Allowed := False;
12345 Ada_Version := Ada_Version_Explicit;
12346 Ada_Version_Pragma := Empty;
12347 end if;
12348
12349 --------------
12350 -- External --
12351 --------------
12352
12353 -- pragma External (
12354 -- [ Convention =>] convention_IDENTIFIER,
12355 -- [ Entity =>] local_NAME
12356 -- [, [External_Name =>] static_string_EXPRESSION ]
12357 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12358
12359 when Pragma_External => External : declare
12360 Def_Id : Entity_Id;
12361
12362 C : Convention_Id;
12363 pragma Warnings (Off, C);
12364
12365 begin
12366 GNAT_Pragma;
12367 Check_Arg_Order
12368 ((Name_Convention,
12369 Name_Entity,
12370 Name_External_Name,
12371 Name_Link_Name));
12372 Check_At_Least_N_Arguments (2);
12373 Check_At_Most_N_Arguments (4);
12374 Process_Convention (C, Def_Id);
12375 Note_Possible_Modification
12376 (Get_Pragma_Arg (Arg2), Sure => False);
12377 Process_Interface_Name (Def_Id, Arg3, Arg4);
12378 Set_Exported (Def_Id, Arg2);
12379 end External;
12380
12381 --------------------------
12382 -- External_Name_Casing --
12383 --------------------------
12384
12385 -- pragma External_Name_Casing (
12386 -- UPPERCASE | LOWERCASE
12387 -- [, AS_IS | UPPERCASE | LOWERCASE]);
12388
12389 when Pragma_External_Name_Casing => External_Name_Casing : declare
12390 begin
12391 GNAT_Pragma;
12392 Check_No_Identifiers;
12393
12394 if Arg_Count = 2 then
12395 Check_Arg_Is_One_Of
12396 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
12397
12398 case Chars (Get_Pragma_Arg (Arg2)) is
12399 when Name_As_Is =>
12400 Opt.External_Name_Exp_Casing := As_Is;
12401
12402 when Name_Uppercase =>
12403 Opt.External_Name_Exp_Casing := Uppercase;
12404
12405 when Name_Lowercase =>
12406 Opt.External_Name_Exp_Casing := Lowercase;
12407
12408 when others =>
12409 null;
12410 end case;
12411
12412 else
12413 Check_Arg_Count (1);
12414 end if;
12415
12416 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
12417
12418 case Chars (Get_Pragma_Arg (Arg1)) is
12419 when Name_Uppercase =>
12420 Opt.External_Name_Imp_Casing := Uppercase;
12421
12422 when Name_Lowercase =>
12423 Opt.External_Name_Imp_Casing := Lowercase;
12424
12425 when others =>
12426 null;
12427 end case;
12428 end External_Name_Casing;
12429
12430 ---------------
12431 -- Fast_Math --
12432 ---------------
12433
12434 -- pragma Fast_Math;
12435
12436 when Pragma_Fast_Math =>
12437 GNAT_Pragma;
12438 Check_No_Identifiers;
12439 Check_Valid_Configuration_Pragma;
12440 Fast_Math := True;
12441
12442 --------------------------
12443 -- Favor_Top_Level --
12444 --------------------------
12445
12446 -- pragma Favor_Top_Level (type_NAME);
12447
12448 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
12449 Named_Entity : Entity_Id;
12450
12451 begin
12452 GNAT_Pragma;
12453 Check_No_Identifiers;
12454 Check_Arg_Count (1);
12455 Check_Arg_Is_Local_Name (Arg1);
12456 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
12457
12458 -- If it's an access-to-subprogram type (in particular, not a
12459 -- subtype), set the flag on that type.
12460
12461 if Is_Access_Subprogram_Type (Named_Entity) then
12462 Set_Can_Use_Internal_Rep (Named_Entity, False);
12463
12464 -- Otherwise it's an error (name denotes the wrong sort of entity)
12465
12466 else
12467 Error_Pragma_Arg
12468 ("access-to-subprogram type expected",
12469 Get_Pragma_Arg (Arg1));
12470 end if;
12471 end Favor_Top_Level;
12472
12473 ---------------------------
12474 -- Finalize_Storage_Only --
12475 ---------------------------
12476
12477 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
12478
12479 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
12480 Assoc : constant Node_Id := Arg1;
12481 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
12482 Typ : Entity_Id;
12483
12484 begin
12485 GNAT_Pragma;
12486 Check_No_Identifiers;
12487 Check_Arg_Count (1);
12488 Check_Arg_Is_Local_Name (Arg1);
12489
12490 Find_Type (Type_Id);
12491 Typ := Entity (Type_Id);
12492
12493 if Typ = Any_Type
12494 or else Rep_Item_Too_Early (Typ, N)
12495 then
12496 return;
12497 else
12498 Typ := Underlying_Type (Typ);
12499 end if;
12500
12501 if not Is_Controlled (Typ) then
12502 Error_Pragma ("pragma% must specify controlled type");
12503 end if;
12504
12505 Check_First_Subtype (Arg1);
12506
12507 if Finalize_Storage_Only (Typ) then
12508 Error_Pragma ("duplicate pragma%, only one allowed");
12509
12510 elsif not Rep_Item_Too_Late (Typ, N) then
12511 Set_Finalize_Storage_Only (Base_Type (Typ), True);
12512 end if;
12513 end Finalize_Storage;
12514
12515 --------------------------
12516 -- Float_Representation --
12517 --------------------------
12518
12519 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
12520
12521 -- FLOAT_REP ::= VAX_Float | IEEE_Float
12522
12523 when Pragma_Float_Representation => Float_Representation : declare
12524 Argx : Node_Id;
12525 Digs : Nat;
12526 Ent : Entity_Id;
12527
12528 begin
12529 GNAT_Pragma;
12530
12531 if Arg_Count = 1 then
12532 Check_Valid_Configuration_Pragma;
12533 else
12534 Check_Arg_Count (2);
12535 Check_Optional_Identifier (Arg2, Name_Entity);
12536 Check_Arg_Is_Local_Name (Arg2);
12537 end if;
12538
12539 Check_No_Identifier (Arg1);
12540 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
12541
12542 if not OpenVMS_On_Target then
12543 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
12544 Error_Pragma
12545 ("??pragma% ignored (applies only to Open'V'M'S)");
12546 end if;
12547
12548 return;
12549 end if;
12550
12551 -- One argument case
12552
12553 if Arg_Count = 1 then
12554 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
12555 if Opt.Float_Format = 'I' then
12556 Error_Pragma ("'I'E'E'E format previously specified");
12557 end if;
12558
12559 Opt.Float_Format := 'V';
12560
12561 else
12562 if Opt.Float_Format = 'V' then
12563 Error_Pragma ("'V'A'X format previously specified");
12564 end if;
12565
12566 Opt.Float_Format := 'I';
12567 end if;
12568
12569 Set_Standard_Fpt_Formats;
12570
12571 -- Two argument case
12572
12573 else
12574 Argx := Get_Pragma_Arg (Arg2);
12575
12576 if not Is_Entity_Name (Argx)
12577 or else not Is_Floating_Point_Type (Entity (Argx))
12578 then
12579 Error_Pragma_Arg
12580 ("second argument of% pragma must be floating-point type",
12581 Arg2);
12582 end if;
12583
12584 Ent := Entity (Argx);
12585 Digs := UI_To_Int (Digits_Value (Ent));
12586
12587 -- Two arguments, VAX_Float case
12588
12589 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
12590 case Digs is
12591 when 6 => Set_F_Float (Ent);
12592 when 9 => Set_D_Float (Ent);
12593 when 15 => Set_G_Float (Ent);
12594
12595 when others =>
12596 Error_Pragma_Arg
12597 ("wrong digits value, must be 6,9 or 15", Arg2);
12598 end case;
12599
12600 -- Two arguments, IEEE_Float case
12601
12602 else
12603 case Digs is
12604 when 6 => Set_IEEE_Short (Ent);
12605 when 15 => Set_IEEE_Long (Ent);
12606
12607 when others =>
12608 Error_Pragma_Arg
12609 ("wrong digits value, must be 6 or 15", Arg2);
12610 end case;
12611 end if;
12612 end if;
12613 end Float_Representation;
12614
12615 ------------
12616 -- Global --
12617 ------------
12618
12619 -- pragma Global (GLOBAL_SPECIFICATION);
12620
12621 -- GLOBAL_SPECIFICATION ::=
12622 -- null
12623 -- | GLOBAL_LIST
12624 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
12625
12626 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
12627
12628 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
12629 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
12630 -- GLOBAL_ITEM ::= NAME
12631
12632 when Pragma_Global => Global : declare
12633 Subp_Decl : Node_Id;
12634
12635 begin
12636 GNAT_Pragma;
12637 S14_Pragma;
12638 Check_Arg_Count (1);
12639
12640 -- Ensure the proper placement of the pragma. Global must be
12641 -- associated with a subprogram declaration or a body that acts
12642 -- as a spec.
12643
12644 Subp_Decl :=
12645 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12646
12647 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
12648 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
12649 or else not Acts_As_Spec (Subp_Decl))
12650 then
12651 Pragma_Misplaced;
12652 return;
12653 end if;
12654
12655 -- When the pragma appears on a subprogram body, perform the full
12656 -- analysis now.
12657
12658 if Nkind (Subp_Decl) = N_Subprogram_Body then
12659 Analyze_Global_In_Decl_Part (N);
12660
12661 -- When Global applies to a subprogram compilation unit, the
12662 -- corresponding pragma is placed after the unit's declaration
12663 -- node and needs to be analyzed immediately.
12664
12665 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
12666 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
12667 then
12668 Analyze_Global_In_Decl_Part (N);
12669 end if;
12670
12671 -- Chain the pragma on the contract for further processing
12672
12673 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12674 end Global;
12675
12676 -----------
12677 -- Ident --
12678 -----------
12679
12680 -- pragma Ident (static_string_EXPRESSION)
12681
12682 -- Note: pragma Comment shares this processing. Pragma Comment is
12683 -- identical to Ident, except that the restriction of the argument to
12684 -- 31 characters and the placement restrictions are not enforced for
12685 -- pragma Comment.
12686
12687 when Pragma_Ident | Pragma_Comment => Ident : declare
12688 Str : Node_Id;
12689
12690 begin
12691 GNAT_Pragma;
12692 Check_Arg_Count (1);
12693 Check_No_Identifiers;
12694 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12695 Store_Note (N);
12696
12697 -- For pragma Ident, preserve DEC compatibility by requiring the
12698 -- pragma to appear in a declarative part or package spec.
12699
12700 if Prag_Id = Pragma_Ident then
12701 Check_Is_In_Decl_Part_Or_Package_Spec;
12702 end if;
12703
12704 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
12705
12706 declare
12707 CS : Node_Id;
12708 GP : Node_Id;
12709
12710 begin
12711 GP := Parent (Parent (N));
12712
12713 if Nkind_In (GP, N_Package_Declaration,
12714 N_Generic_Package_Declaration)
12715 then
12716 GP := Parent (GP);
12717 end if;
12718
12719 -- If we have a compilation unit, then record the ident value,
12720 -- checking for improper duplication.
12721
12722 if Nkind (GP) = N_Compilation_Unit then
12723 CS := Ident_String (Current_Sem_Unit);
12724
12725 if Present (CS) then
12726
12727 -- For Ident, we do not permit multiple instances
12728
12729 if Prag_Id = Pragma_Ident then
12730 Error_Pragma ("duplicate% pragma not permitted");
12731
12732 -- For Comment, we concatenate the string, unless we want
12733 -- to preserve the tree structure for ASIS.
12734
12735 elsif not ASIS_Mode then
12736 Start_String (Strval (CS));
12737 Store_String_Char (' ');
12738 Store_String_Chars (Strval (Str));
12739 Set_Strval (CS, End_String);
12740 end if;
12741
12742 else
12743 -- In VMS, the effect of IDENT is achieved by passing
12744 -- --identification=name as a --for-linker switch.
12745
12746 if OpenVMS_On_Target then
12747 Start_String;
12748 Store_String_Chars
12749 ("--for-linker=--identification=");
12750 String_To_Name_Buffer (Strval (Str));
12751 Store_String_Chars (Name_Buffer (1 .. Name_Len));
12752
12753 -- Only the last processed IDENT is saved. The main
12754 -- purpose is so an IDENT associated with a main
12755 -- procedure will be used in preference to an IDENT
12756 -- associated with a with'd package.
12757
12758 Replace_Linker_Option_String
12759 (End_String, "--for-linker=--identification=");
12760 end if;
12761
12762 Set_Ident_String (Current_Sem_Unit, Str);
12763 end if;
12764
12765 -- For subunits, we just ignore the Ident, since in GNAT these
12766 -- are not separate object files, and hence not separate units
12767 -- in the unit table.
12768
12769 elsif Nkind (GP) = N_Subunit then
12770 null;
12771
12772 -- Otherwise we have a misplaced pragma Ident, but we ignore
12773 -- this if we are in an instantiation, since it comes from
12774 -- a generic, and has no relevance to the instantiation.
12775
12776 elsif Prag_Id = Pragma_Ident then
12777 if Instantiation_Location (Loc) = No_Location then
12778 Error_Pragma ("pragma% only allowed at outer level");
12779 end if;
12780 end if;
12781 end;
12782 end Ident;
12783
12784 ----------------------------
12785 -- Implementation_Defined --
12786 ----------------------------
12787
12788 -- pragma Implementation_Defined (local_NAME);
12789
12790 -- Marks previously declared entity as implementation defined. For
12791 -- an overloaded entity, applies to the most recent homonym.
12792
12793 -- pragma Implementation_Defined;
12794
12795 -- The form with no arguments appears anywhere within a scope, most
12796 -- typically a package spec, and indicates that all entities that are
12797 -- defined within the package spec are Implementation_Defined.
12798
12799 when Pragma_Implementation_Defined => Implementation_Defined : declare
12800 Ent : Entity_Id;
12801
12802 begin
12803 GNAT_Pragma;
12804 Check_No_Identifiers;
12805
12806 -- Form with no arguments
12807
12808 if Arg_Count = 0 then
12809 Set_Is_Implementation_Defined (Current_Scope);
12810
12811 -- Form with one argument
12812
12813 else
12814 Check_Arg_Count (1);
12815 Check_Arg_Is_Local_Name (Arg1);
12816 Ent := Entity (Get_Pragma_Arg (Arg1));
12817 Set_Is_Implementation_Defined (Ent);
12818 end if;
12819 end Implementation_Defined;
12820
12821 -----------------
12822 -- Implemented --
12823 -----------------
12824
12825 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
12826
12827 -- IMPLEMENTATION_KIND ::=
12828 -- By_Entry | By_Protected_Procedure | By_Any | Optional
12829
12830 -- "By_Any" and "Optional" are treated as synonyms in order to
12831 -- support Ada 2012 aspect Synchronization.
12832
12833 when Pragma_Implemented => Implemented : declare
12834 Proc_Id : Entity_Id;
12835 Typ : Entity_Id;
12836
12837 begin
12838 Ada_2012_Pragma;
12839 Check_Arg_Count (2);
12840 Check_No_Identifiers;
12841 Check_Arg_Is_Identifier (Arg1);
12842 Check_Arg_Is_Local_Name (Arg1);
12843 Check_Arg_Is_One_Of (Arg2,
12844 Name_By_Any,
12845 Name_By_Entry,
12846 Name_By_Protected_Procedure,
12847 Name_Optional);
12848
12849 -- Extract the name of the local procedure
12850
12851 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
12852
12853 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
12854 -- primitive procedure of a synchronized tagged type.
12855
12856 if Ekind (Proc_Id) = E_Procedure
12857 and then Is_Primitive (Proc_Id)
12858 and then Present (First_Formal (Proc_Id))
12859 then
12860 Typ := Etype (First_Formal (Proc_Id));
12861
12862 if Is_Tagged_Type (Typ)
12863 and then
12864
12865 -- Check for a protected, a synchronized or a task interface
12866
12867 ((Is_Interface (Typ)
12868 and then Is_Synchronized_Interface (Typ))
12869
12870 -- Check for a protected type or a task type that implements
12871 -- an interface.
12872
12873 or else
12874 (Is_Concurrent_Record_Type (Typ)
12875 and then Present (Interfaces (Typ)))
12876
12877 -- Check for a private record extension with keyword
12878 -- "synchronized".
12879
12880 or else
12881 (Ekind_In (Typ, E_Record_Type_With_Private,
12882 E_Record_Subtype_With_Private)
12883 and then Synchronized_Present (Parent (Typ))))
12884 then
12885 null;
12886 else
12887 Error_Pragma_Arg
12888 ("controlling formal must be of synchronized tagged type",
12889 Arg1);
12890 return;
12891 end if;
12892
12893 -- Procedures declared inside a protected type must be accepted
12894
12895 elsif Ekind (Proc_Id) = E_Procedure
12896 and then Is_Protected_Type (Scope (Proc_Id))
12897 then
12898 null;
12899
12900 -- The first argument is not a primitive procedure
12901
12902 else
12903 Error_Pragma_Arg
12904 ("pragma % must be applied to a primitive procedure", Arg1);
12905 return;
12906 end if;
12907
12908 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
12909 -- By_Protected_Procedure to the primitive procedure of a task
12910 -- interface.
12911
12912 if Chars (Arg2) = Name_By_Protected_Procedure
12913 and then Is_Interface (Typ)
12914 and then Is_Task_Interface (Typ)
12915 then
12916 Error_Pragma_Arg
12917 ("implementation kind By_Protected_Procedure cannot be "
12918 & "applied to a task interface primitive", Arg2);
12919 return;
12920 end if;
12921
12922 Record_Rep_Item (Proc_Id, N);
12923 end Implemented;
12924
12925 ----------------------
12926 -- Implicit_Packing --
12927 ----------------------
12928
12929 -- pragma Implicit_Packing;
12930
12931 when Pragma_Implicit_Packing =>
12932 GNAT_Pragma;
12933 Check_Arg_Count (0);
12934 Implicit_Packing := True;
12935
12936 ------------
12937 -- Import --
12938 ------------
12939
12940 -- pragma Import (
12941 -- [Convention =>] convention_IDENTIFIER,
12942 -- [Entity =>] local_NAME
12943 -- [, [External_Name =>] static_string_EXPRESSION ]
12944 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12945
12946 when Pragma_Import =>
12947 Check_Ada_83_Warning;
12948 Check_Arg_Order
12949 ((Name_Convention,
12950 Name_Entity,
12951 Name_External_Name,
12952 Name_Link_Name));
12953
12954 Check_At_Least_N_Arguments (2);
12955 Check_At_Most_N_Arguments (4);
12956 Process_Import_Or_Interface;
12957
12958 ----------------------
12959 -- Import_Exception --
12960 ----------------------
12961
12962 -- pragma Import_Exception (
12963 -- [Internal =>] LOCAL_NAME
12964 -- [, [External =>] EXTERNAL_SYMBOL]
12965 -- [, [Form =>] Ada | VMS]
12966 -- [, [Code =>] static_integer_EXPRESSION]);
12967
12968 when Pragma_Import_Exception => Import_Exception : declare
12969 Args : Args_List (1 .. 4);
12970 Names : constant Name_List (1 .. 4) := (
12971 Name_Internal,
12972 Name_External,
12973 Name_Form,
12974 Name_Code);
12975
12976 Internal : Node_Id renames Args (1);
12977 External : Node_Id renames Args (2);
12978 Form : Node_Id renames Args (3);
12979 Code : Node_Id renames Args (4);
12980
12981 begin
12982 GNAT_Pragma;
12983 Gather_Associations (Names, Args);
12984
12985 if Present (External) and then Present (Code) then
12986 Error_Pragma
12987 ("cannot give both External and Code options for pragma%");
12988 end if;
12989
12990 Process_Extended_Import_Export_Exception_Pragma (
12991 Arg_Internal => Internal,
12992 Arg_External => External,
12993 Arg_Form => Form,
12994 Arg_Code => Code);
12995
12996 if not Is_VMS_Exception (Entity (Internal)) then
12997 Set_Imported (Entity (Internal));
12998 end if;
12999 end Import_Exception;
13000
13001 ---------------------
13002 -- Import_Function --
13003 ---------------------
13004
13005 -- pragma Import_Function (
13006 -- [Internal =>] LOCAL_NAME,
13007 -- [, [External =>] EXTERNAL_SYMBOL]
13008 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13009 -- [, [Result_Type =>] SUBTYPE_MARK]
13010 -- [, [Mechanism =>] MECHANISM]
13011 -- [, [Result_Mechanism =>] MECHANISM_NAME]
13012 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
13013
13014 -- EXTERNAL_SYMBOL ::=
13015 -- IDENTIFIER
13016 -- | static_string_EXPRESSION
13017
13018 -- PARAMETER_TYPES ::=
13019 -- null
13020 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13021
13022 -- TYPE_DESIGNATOR ::=
13023 -- subtype_NAME
13024 -- | subtype_Name ' Access
13025
13026 -- MECHANISM ::=
13027 -- MECHANISM_NAME
13028 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13029
13030 -- MECHANISM_ASSOCIATION ::=
13031 -- [formal_parameter_NAME =>] MECHANISM_NAME
13032
13033 -- MECHANISM_NAME ::=
13034 -- Value
13035 -- | Reference
13036 -- | Descriptor [([Class =>] CLASS_NAME)]
13037
13038 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13039
13040 when Pragma_Import_Function => Import_Function : declare
13041 Args : Args_List (1 .. 7);
13042 Names : constant Name_List (1 .. 7) := (
13043 Name_Internal,
13044 Name_External,
13045 Name_Parameter_Types,
13046 Name_Result_Type,
13047 Name_Mechanism,
13048 Name_Result_Mechanism,
13049 Name_First_Optional_Parameter);
13050
13051 Internal : Node_Id renames Args (1);
13052 External : Node_Id renames Args (2);
13053 Parameter_Types : Node_Id renames Args (3);
13054 Result_Type : Node_Id renames Args (4);
13055 Mechanism : Node_Id renames Args (5);
13056 Result_Mechanism : Node_Id renames Args (6);
13057 First_Optional_Parameter : Node_Id renames Args (7);
13058
13059 begin
13060 GNAT_Pragma;
13061 Gather_Associations (Names, Args);
13062 Process_Extended_Import_Export_Subprogram_Pragma (
13063 Arg_Internal => Internal,
13064 Arg_External => External,
13065 Arg_Parameter_Types => Parameter_Types,
13066 Arg_Result_Type => Result_Type,
13067 Arg_Mechanism => Mechanism,
13068 Arg_Result_Mechanism => Result_Mechanism,
13069 Arg_First_Optional_Parameter => First_Optional_Parameter);
13070 end Import_Function;
13071
13072 -------------------
13073 -- Import_Object --
13074 -------------------
13075
13076 -- pragma Import_Object (
13077 -- [Internal =>] LOCAL_NAME
13078 -- [, [External =>] EXTERNAL_SYMBOL]
13079 -- [, [Size =>] EXTERNAL_SYMBOL]);
13080
13081 -- EXTERNAL_SYMBOL ::=
13082 -- IDENTIFIER
13083 -- | static_string_EXPRESSION
13084
13085 when Pragma_Import_Object => Import_Object : declare
13086 Args : Args_List (1 .. 3);
13087 Names : constant Name_List (1 .. 3) := (
13088 Name_Internal,
13089 Name_External,
13090 Name_Size);
13091
13092 Internal : Node_Id renames Args (1);
13093 External : Node_Id renames Args (2);
13094 Size : Node_Id renames Args (3);
13095
13096 begin
13097 GNAT_Pragma;
13098 Gather_Associations (Names, Args);
13099 Process_Extended_Import_Export_Object_Pragma (
13100 Arg_Internal => Internal,
13101 Arg_External => External,
13102 Arg_Size => Size);
13103 end Import_Object;
13104
13105 ----------------------
13106 -- Import_Procedure --
13107 ----------------------
13108
13109 -- pragma Import_Procedure (
13110 -- [Internal =>] LOCAL_NAME
13111 -- [, [External =>] EXTERNAL_SYMBOL]
13112 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13113 -- [, [Mechanism =>] MECHANISM]
13114 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
13115
13116 -- EXTERNAL_SYMBOL ::=
13117 -- IDENTIFIER
13118 -- | static_string_EXPRESSION
13119
13120 -- PARAMETER_TYPES ::=
13121 -- null
13122 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13123
13124 -- TYPE_DESIGNATOR ::=
13125 -- subtype_NAME
13126 -- | subtype_Name ' Access
13127
13128 -- MECHANISM ::=
13129 -- MECHANISM_NAME
13130 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13131
13132 -- MECHANISM_ASSOCIATION ::=
13133 -- [formal_parameter_NAME =>] MECHANISM_NAME
13134
13135 -- MECHANISM_NAME ::=
13136 -- Value
13137 -- | Reference
13138 -- | Descriptor [([Class =>] CLASS_NAME)]
13139
13140 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13141
13142 when Pragma_Import_Procedure => Import_Procedure : declare
13143 Args : Args_List (1 .. 5);
13144 Names : constant Name_List (1 .. 5) := (
13145 Name_Internal,
13146 Name_External,
13147 Name_Parameter_Types,
13148 Name_Mechanism,
13149 Name_First_Optional_Parameter);
13150
13151 Internal : Node_Id renames Args (1);
13152 External : Node_Id renames Args (2);
13153 Parameter_Types : Node_Id renames Args (3);
13154 Mechanism : Node_Id renames Args (4);
13155 First_Optional_Parameter : Node_Id renames Args (5);
13156
13157 begin
13158 GNAT_Pragma;
13159 Gather_Associations (Names, Args);
13160 Process_Extended_Import_Export_Subprogram_Pragma (
13161 Arg_Internal => Internal,
13162 Arg_External => External,
13163 Arg_Parameter_Types => Parameter_Types,
13164 Arg_Mechanism => Mechanism,
13165 Arg_First_Optional_Parameter => First_Optional_Parameter);
13166 end Import_Procedure;
13167
13168 -----------------------------
13169 -- Import_Valued_Procedure --
13170 -----------------------------
13171
13172 -- pragma Import_Valued_Procedure (
13173 -- [Internal =>] LOCAL_NAME
13174 -- [, [External =>] EXTERNAL_SYMBOL]
13175 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13176 -- [, [Mechanism =>] MECHANISM]
13177 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
13178
13179 -- EXTERNAL_SYMBOL ::=
13180 -- IDENTIFIER
13181 -- | static_string_EXPRESSION
13182
13183 -- PARAMETER_TYPES ::=
13184 -- null
13185 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13186
13187 -- TYPE_DESIGNATOR ::=
13188 -- subtype_NAME
13189 -- | subtype_Name ' Access
13190
13191 -- MECHANISM ::=
13192 -- MECHANISM_NAME
13193 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13194
13195 -- MECHANISM_ASSOCIATION ::=
13196 -- [formal_parameter_NAME =>] MECHANISM_NAME
13197
13198 -- MECHANISM_NAME ::=
13199 -- Value
13200 -- | Reference
13201 -- | Descriptor [([Class =>] CLASS_NAME)]
13202
13203 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13204
13205 when Pragma_Import_Valued_Procedure =>
13206 Import_Valued_Procedure : declare
13207 Args : Args_List (1 .. 5);
13208 Names : constant Name_List (1 .. 5) := (
13209 Name_Internal,
13210 Name_External,
13211 Name_Parameter_Types,
13212 Name_Mechanism,
13213 Name_First_Optional_Parameter);
13214
13215 Internal : Node_Id renames Args (1);
13216 External : Node_Id renames Args (2);
13217 Parameter_Types : Node_Id renames Args (3);
13218 Mechanism : Node_Id renames Args (4);
13219 First_Optional_Parameter : Node_Id renames Args (5);
13220
13221 begin
13222 GNAT_Pragma;
13223 Gather_Associations (Names, Args);
13224 Process_Extended_Import_Export_Subprogram_Pragma (
13225 Arg_Internal => Internal,
13226 Arg_External => External,
13227 Arg_Parameter_Types => Parameter_Types,
13228 Arg_Mechanism => Mechanism,
13229 Arg_First_Optional_Parameter => First_Optional_Parameter);
13230 end Import_Valued_Procedure;
13231
13232 -----------------
13233 -- Independent --
13234 -----------------
13235
13236 -- pragma Independent (LOCAL_NAME);
13237
13238 when Pragma_Independent => Independent : declare
13239 E_Id : Node_Id;
13240 E : Entity_Id;
13241 D : Node_Id;
13242 K : Node_Kind;
13243
13244 begin
13245 Check_Ada_83_Warning;
13246 Ada_2012_Pragma;
13247 Check_No_Identifiers;
13248 Check_Arg_Count (1);
13249 Check_Arg_Is_Local_Name (Arg1);
13250 E_Id := Get_Pragma_Arg (Arg1);
13251
13252 if Etype (E_Id) = Any_Type then
13253 return;
13254 end if;
13255
13256 E := Entity (E_Id);
13257 D := Declaration_Node (E);
13258 K := Nkind (D);
13259
13260 -- Check duplicate before we chain ourselves!
13261
13262 Check_Duplicate_Pragma (E);
13263
13264 -- Check appropriate entity
13265
13266 if Is_Type (E) then
13267 if Rep_Item_Too_Early (E, N)
13268 or else
13269 Rep_Item_Too_Late (E, N)
13270 then
13271 return;
13272 else
13273 Check_First_Subtype (Arg1);
13274 end if;
13275
13276 elsif K = N_Object_Declaration
13277 or else (K = N_Component_Declaration
13278 and then Original_Record_Component (E) = E)
13279 then
13280 if Rep_Item_Too_Late (E, N) then
13281 return;
13282 end if;
13283
13284 else
13285 Error_Pragma_Arg
13286 ("inappropriate entity for pragma%", Arg1);
13287 end if;
13288
13289 Independence_Checks.Append ((N, E));
13290 end Independent;
13291
13292 ----------------------------
13293 -- Independent_Components --
13294 ----------------------------
13295
13296 -- pragma Atomic_Components (array_LOCAL_NAME);
13297
13298 -- This processing is shared by Volatile_Components
13299
13300 when Pragma_Independent_Components => Independent_Components : declare
13301 E_Id : Node_Id;
13302 E : Entity_Id;
13303 D : Node_Id;
13304 K : Node_Kind;
13305
13306 begin
13307 Check_Ada_83_Warning;
13308 Ada_2012_Pragma;
13309 Check_No_Identifiers;
13310 Check_Arg_Count (1);
13311 Check_Arg_Is_Local_Name (Arg1);
13312 E_Id := Get_Pragma_Arg (Arg1);
13313
13314 if Etype (E_Id) = Any_Type then
13315 return;
13316 end if;
13317
13318 E := Entity (E_Id);
13319
13320 -- Check duplicate before we chain ourselves!
13321
13322 Check_Duplicate_Pragma (E);
13323
13324 -- Check appropriate entity
13325
13326 if Rep_Item_Too_Early (E, N)
13327 or else
13328 Rep_Item_Too_Late (E, N)
13329 then
13330 return;
13331 end if;
13332
13333 D := Declaration_Node (E);
13334 K := Nkind (D);
13335
13336 if K = N_Full_Type_Declaration
13337 and then (Is_Array_Type (E) or else Is_Record_Type (E))
13338 then
13339 Independence_Checks.Append ((N, E));
13340 Set_Has_Independent_Components (Base_Type (E));
13341
13342 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
13343 and then Nkind (D) = N_Object_Declaration
13344 and then Nkind (Object_Definition (D)) =
13345 N_Constrained_Array_Definition
13346 then
13347 Independence_Checks.Append ((N, E));
13348 Set_Has_Independent_Components (E);
13349
13350 else
13351 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
13352 end if;
13353 end Independent_Components;
13354
13355 ------------------------
13356 -- Initialize_Scalars --
13357 ------------------------
13358
13359 -- pragma Initialize_Scalars;
13360
13361 when Pragma_Initialize_Scalars =>
13362 GNAT_Pragma;
13363 Check_Arg_Count (0);
13364 Check_Valid_Configuration_Pragma;
13365 Check_Restriction (No_Initialize_Scalars, N);
13366
13367 -- Initialize_Scalars creates false positives in CodePeer, and
13368 -- incorrect negative results in SPARK mode, so ignore this pragma
13369 -- in these modes.
13370
13371 if not Restriction_Active (No_Initialize_Scalars)
13372 and then not (CodePeer_Mode or SPARK_Mode)
13373 then
13374 Init_Or_Norm_Scalars := True;
13375 Initialize_Scalars := True;
13376 end if;
13377
13378 -----------------
13379 -- Initializes --
13380 -----------------
13381
13382 -- pragma Initializes (INITIALIZATION_SPEC);
13383
13384 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
13385
13386 -- INITIALIZATION_LIST ::=
13387 -- INITIALIZATION_ITEM
13388 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
13389
13390 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
13391
13392 -- INPUT_LIST ::=
13393 -- null
13394 -- | INPUT
13395 -- | (INPUT {, INPUT})
13396
13397 -- INPUT ::= name
13398
13399 when Pragma_Initializes => Initializes : declare
13400 Context : constant Node_Id := Parent (Parent (N));
13401 Pack_Id : Entity_Id;
13402 Stmt : Node_Id;
13403
13404 begin
13405 GNAT_Pragma;
13406 S14_Pragma;
13407 Check_Arg_Count (1);
13408
13409 -- Ensure the proper placement of the pragma. Initializes must be
13410 -- associated with a package declaration.
13411
13412 if not Nkind_In (Context, N_Generic_Package_Declaration,
13413 N_Package_Declaration)
13414 then
13415 Pragma_Misplaced;
13416 return;
13417 end if;
13418
13419 Stmt := Prev (N);
13420 while Present (Stmt) loop
13421
13422 -- Skip prior pragmas, but check for duplicates
13423
13424 if Nkind (Stmt) = N_Pragma then
13425 if Pragma_Name (Stmt) = Pname then
13426 Error_Msg_Name_1 := Pname;
13427 Error_Msg_Sloc := Sloc (Stmt);
13428 Error_Msg_N ("pragma % duplicates pragma declared #", N);
13429 end if;
13430
13431 -- Skip internally generated code
13432
13433 elsif not Comes_From_Source (Stmt) then
13434 null;
13435
13436 -- The pragma does not apply to a legal construct, issue an
13437 -- error and stop the analysis.
13438
13439 else
13440 Pragma_Misplaced;
13441 return;
13442 end if;
13443
13444 Stmt := Prev (Stmt);
13445 end loop;
13446
13447 -- The pragma must be analyzed at the end of the visible
13448 -- declarations of the related package. Save the pragma for later
13449 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
13450 -- contract of the package.
13451
13452 Pack_Id := Defining_Entity (Context);
13453 Add_Contract_Item (N, Pack_Id);
13454
13455 -- Verify the declaration order of pragmas Abstract_State and
13456 -- Initializes.
13457
13458 Check_Declaration_Order
13459 (States => Get_Pragma (Pack_Id, Pragma_Abstract_State),
13460 Inits => N);
13461 end Initializes;
13462
13463 ------------
13464 -- Inline --
13465 ------------
13466
13467 -- pragma Inline ( NAME {, NAME} );
13468
13469 when Pragma_Inline =>
13470
13471 -- Inline status is Enabled if inlining option is active
13472
13473 if Inline_Active then
13474 Process_Inline (Enabled);
13475 else
13476 Process_Inline (Disabled);
13477 end if;
13478
13479 -------------------
13480 -- Inline_Always --
13481 -------------------
13482
13483 -- pragma Inline_Always ( NAME {, NAME} );
13484
13485 when Pragma_Inline_Always =>
13486 GNAT_Pragma;
13487
13488 -- Pragma always active unless in CodePeer or SPARK mode, since
13489 -- this causes walk order issues.
13490
13491 if not (CodePeer_Mode or SPARK_Mode) then
13492 Process_Inline (Enabled);
13493 end if;
13494
13495 --------------------
13496 -- Inline_Generic --
13497 --------------------
13498
13499 -- pragma Inline_Generic (NAME {, NAME});
13500
13501 when Pragma_Inline_Generic =>
13502 GNAT_Pragma;
13503 Process_Generic_List;
13504
13505 ----------------------
13506 -- Inspection_Point --
13507 ----------------------
13508
13509 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
13510
13511 when Pragma_Inspection_Point => Inspection_Point : declare
13512 Arg : Node_Id;
13513 Exp : Node_Id;
13514
13515 begin
13516 if Arg_Count > 0 then
13517 Arg := Arg1;
13518 loop
13519 Exp := Get_Pragma_Arg (Arg);
13520 Analyze (Exp);
13521
13522 if not Is_Entity_Name (Exp)
13523 or else not Is_Object (Entity (Exp))
13524 then
13525 Error_Pragma_Arg ("object name required", Arg);
13526 end if;
13527
13528 Next (Arg);
13529 exit when No (Arg);
13530 end loop;
13531 end if;
13532 end Inspection_Point;
13533
13534 ---------------
13535 -- Interface --
13536 ---------------
13537
13538 -- pragma Interface (
13539 -- [ Convention =>] convention_IDENTIFIER,
13540 -- [ Entity =>] local_NAME
13541 -- [, [External_Name =>] static_string_EXPRESSION ]
13542 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13543
13544 when Pragma_Interface =>
13545 GNAT_Pragma;
13546 Check_Arg_Order
13547 ((Name_Convention,
13548 Name_Entity,
13549 Name_External_Name,
13550 Name_Link_Name));
13551 Check_At_Least_N_Arguments (2);
13552 Check_At_Most_N_Arguments (4);
13553 Process_Import_Or_Interface;
13554
13555 -- In Ada 2005, the permission to use Interface (a reserved word)
13556 -- as a pragma name is considered an obsolescent feature, and this
13557 -- pragma was already obsolescent in Ada 95.
13558
13559 if Ada_Version >= Ada_95 then
13560 Check_Restriction
13561 (No_Obsolescent_Features, Pragma_Identifier (N));
13562
13563 if Warn_On_Obsolescent_Feature then
13564 Error_Msg_N
13565 ("pragma Interface is an obsolescent feature?j?", N);
13566 Error_Msg_N
13567 ("|use pragma Import instead?j?", N);
13568 end if;
13569 end if;
13570
13571 --------------------
13572 -- Interface_Name --
13573 --------------------
13574
13575 -- pragma Interface_Name (
13576 -- [ Entity =>] local_NAME
13577 -- [,[External_Name =>] static_string_EXPRESSION ]
13578 -- [,[Link_Name =>] static_string_EXPRESSION ]);
13579
13580 when Pragma_Interface_Name => Interface_Name : declare
13581 Id : Node_Id;
13582 Def_Id : Entity_Id;
13583 Hom_Id : Entity_Id;
13584 Found : Boolean;
13585
13586 begin
13587 GNAT_Pragma;
13588 Check_Arg_Order
13589 ((Name_Entity, Name_External_Name, Name_Link_Name));
13590 Check_At_Least_N_Arguments (2);
13591 Check_At_Most_N_Arguments (3);
13592 Id := Get_Pragma_Arg (Arg1);
13593 Analyze (Id);
13594
13595 -- This is obsolete from Ada 95 on, but it is an implementation
13596 -- defined pragma, so we do not consider that it violates the
13597 -- restriction (No_Obsolescent_Features).
13598
13599 if Ada_Version >= Ada_95 then
13600 if Warn_On_Obsolescent_Feature then
13601 Error_Msg_N
13602 ("pragma Interface_Name is an obsolescent feature?j?", N);
13603 Error_Msg_N
13604 ("|use pragma Import instead?j?", N);
13605 end if;
13606 end if;
13607
13608 if not Is_Entity_Name (Id) then
13609 Error_Pragma_Arg
13610 ("first argument for pragma% must be entity name", Arg1);
13611 elsif Etype (Id) = Any_Type then
13612 return;
13613 else
13614 Def_Id := Entity (Id);
13615 end if;
13616
13617 -- Special DEC-compatible processing for the object case, forces
13618 -- object to be imported.
13619
13620 if Ekind (Def_Id) = E_Variable then
13621 Kill_Size_Check_Code (Def_Id);
13622 Note_Possible_Modification (Id, Sure => False);
13623
13624 -- Initialization is not allowed for imported variable
13625
13626 if Present (Expression (Parent (Def_Id)))
13627 and then Comes_From_Source (Expression (Parent (Def_Id)))
13628 then
13629 Error_Msg_Sloc := Sloc (Def_Id);
13630 Error_Pragma_Arg
13631 ("no initialization allowed for declaration of& #",
13632 Arg2);
13633
13634 else
13635 -- For compatibility, support VADS usage of providing both
13636 -- pragmas Interface and Interface_Name to obtain the effect
13637 -- of a single Import pragma.
13638
13639 if Is_Imported (Def_Id)
13640 and then Present (First_Rep_Item (Def_Id))
13641 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
13642 and then
13643 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
13644 then
13645 null;
13646 else
13647 Set_Imported (Def_Id);
13648 end if;
13649
13650 Set_Is_Public (Def_Id);
13651 Process_Interface_Name (Def_Id, Arg2, Arg3);
13652 end if;
13653
13654 -- Otherwise must be subprogram
13655
13656 elsif not Is_Subprogram (Def_Id) then
13657 Error_Pragma_Arg
13658 ("argument of pragma% is not subprogram", Arg1);
13659
13660 else
13661 Check_At_Most_N_Arguments (3);
13662 Hom_Id := Def_Id;
13663 Found := False;
13664
13665 -- Loop through homonyms
13666
13667 loop
13668 Def_Id := Get_Base_Subprogram (Hom_Id);
13669
13670 if Is_Imported (Def_Id) then
13671 Process_Interface_Name (Def_Id, Arg2, Arg3);
13672 Found := True;
13673 end if;
13674
13675 exit when From_Aspect_Specification (N);
13676 Hom_Id := Homonym (Hom_Id);
13677
13678 exit when No (Hom_Id)
13679 or else Scope (Hom_Id) /= Current_Scope;
13680 end loop;
13681
13682 if not Found then
13683 Error_Pragma_Arg
13684 ("argument of pragma% is not imported subprogram",
13685 Arg1);
13686 end if;
13687 end if;
13688 end Interface_Name;
13689
13690 -----------------------
13691 -- Interrupt_Handler --
13692 -----------------------
13693
13694 -- pragma Interrupt_Handler (handler_NAME);
13695
13696 when Pragma_Interrupt_Handler =>
13697 Check_Ada_83_Warning;
13698 Check_Arg_Count (1);
13699 Check_No_Identifiers;
13700
13701 if No_Run_Time_Mode then
13702 Error_Msg_CRT ("Interrupt_Handler pragma", N);
13703 else
13704 Check_Interrupt_Or_Attach_Handler;
13705 Process_Interrupt_Or_Attach_Handler;
13706 end if;
13707
13708 ------------------------
13709 -- Interrupt_Priority --
13710 ------------------------
13711
13712 -- pragma Interrupt_Priority [(EXPRESSION)];
13713
13714 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
13715 P : constant Node_Id := Parent (N);
13716 Arg : Node_Id;
13717 Ent : Entity_Id;
13718
13719 begin
13720 Check_Ada_83_Warning;
13721
13722 if Arg_Count /= 0 then
13723 Arg := Get_Pragma_Arg (Arg1);
13724 Check_Arg_Count (1);
13725 Check_No_Identifiers;
13726
13727 -- The expression must be analyzed in the special manner
13728 -- described in "Handling of Default and Per-Object
13729 -- Expressions" in sem.ads.
13730
13731 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
13732 end if;
13733
13734 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
13735 Pragma_Misplaced;
13736 return;
13737
13738 else
13739 Ent := Defining_Identifier (Parent (P));
13740
13741 -- Check duplicate pragma before we chain the pragma in the Rep
13742 -- Item chain of Ent.
13743
13744 Check_Duplicate_Pragma (Ent);
13745 Record_Rep_Item (Ent, N);
13746 end if;
13747 end Interrupt_Priority;
13748
13749 ---------------------
13750 -- Interrupt_State --
13751 ---------------------
13752
13753 -- pragma Interrupt_State (
13754 -- [Name =>] INTERRUPT_ID,
13755 -- [State =>] INTERRUPT_STATE);
13756
13757 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
13758 -- INTERRUPT_STATE => System | Runtime | User
13759
13760 -- Note: if the interrupt id is given as an identifier, then it must
13761 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
13762 -- given as a static integer expression which must be in the range of
13763 -- Ada.Interrupts.Interrupt_ID.
13764
13765 when Pragma_Interrupt_State => Interrupt_State : declare
13766
13767 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
13768 -- This is the entity Ada.Interrupts.Interrupt_ID;
13769
13770 State_Type : Character;
13771 -- Set to 's'/'r'/'u' for System/Runtime/User
13772
13773 IST_Num : Pos;
13774 -- Index to entry in Interrupt_States table
13775
13776 Int_Val : Uint;
13777 -- Value of interrupt
13778
13779 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
13780 -- The first argument to the pragma
13781
13782 Int_Ent : Entity_Id;
13783 -- Interrupt entity in Ada.Interrupts.Names
13784
13785 begin
13786 GNAT_Pragma;
13787 Check_Arg_Order ((Name_Name, Name_State));
13788 Check_Arg_Count (2);
13789
13790 Check_Optional_Identifier (Arg1, Name_Name);
13791 Check_Optional_Identifier (Arg2, Name_State);
13792 Check_Arg_Is_Identifier (Arg2);
13793
13794 -- First argument is identifier
13795
13796 if Nkind (Arg1X) = N_Identifier then
13797
13798 -- Search list of names in Ada.Interrupts.Names
13799
13800 Int_Ent := First_Entity (RTE (RE_Names));
13801 loop
13802 if No (Int_Ent) then
13803 Error_Pragma_Arg ("invalid interrupt name", Arg1);
13804
13805 elsif Chars (Int_Ent) = Chars (Arg1X) then
13806 Int_Val := Expr_Value (Constant_Value (Int_Ent));
13807 exit;
13808 end if;
13809
13810 Next_Entity (Int_Ent);
13811 end loop;
13812
13813 -- First argument is not an identifier, so it must be a static
13814 -- expression of type Ada.Interrupts.Interrupt_ID.
13815
13816 else
13817 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
13818 Int_Val := Expr_Value (Arg1X);
13819
13820 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
13821 or else
13822 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
13823 then
13824 Error_Pragma_Arg
13825 ("value not in range of type "
13826 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
13827 end if;
13828 end if;
13829
13830 -- Check OK state
13831
13832 case Chars (Get_Pragma_Arg (Arg2)) is
13833 when Name_Runtime => State_Type := 'r';
13834 when Name_System => State_Type := 's';
13835 when Name_User => State_Type := 'u';
13836
13837 when others =>
13838 Error_Pragma_Arg ("invalid interrupt state", Arg2);
13839 end case;
13840
13841 -- Check if entry is already stored
13842
13843 IST_Num := Interrupt_States.First;
13844 loop
13845 -- If entry not found, add it
13846
13847 if IST_Num > Interrupt_States.Last then
13848 Interrupt_States.Append
13849 ((Interrupt_Number => UI_To_Int (Int_Val),
13850 Interrupt_State => State_Type,
13851 Pragma_Loc => Loc));
13852 exit;
13853
13854 -- Case of entry for the same entry
13855
13856 elsif Int_Val = Interrupt_States.Table (IST_Num).
13857 Interrupt_Number
13858 then
13859 -- If state matches, done, no need to make redundant entry
13860
13861 exit when
13862 State_Type = Interrupt_States.Table (IST_Num).
13863 Interrupt_State;
13864
13865 -- Otherwise if state does not match, error
13866
13867 Error_Msg_Sloc :=
13868 Interrupt_States.Table (IST_Num).Pragma_Loc;
13869 Error_Pragma_Arg
13870 ("state conflicts with that given #", Arg2);
13871 exit;
13872 end if;
13873
13874 IST_Num := IST_Num + 1;
13875 end loop;
13876 end Interrupt_State;
13877
13878 ---------------
13879 -- Invariant --
13880 ---------------
13881
13882 -- pragma Invariant
13883 -- ([Entity =>] type_LOCAL_NAME,
13884 -- [Check =>] EXPRESSION
13885 -- [,[Message =>] String_Expression]);
13886
13887 when Pragma_Invariant => Invariant : declare
13888 Type_Id : Node_Id;
13889 Typ : Entity_Id;
13890 PDecl : Node_Id;
13891
13892 Discard : Boolean;
13893 pragma Unreferenced (Discard);
13894
13895 begin
13896 GNAT_Pragma;
13897 Check_At_Least_N_Arguments (2);
13898 Check_At_Most_N_Arguments (3);
13899 Check_Optional_Identifier (Arg1, Name_Entity);
13900 Check_Optional_Identifier (Arg2, Name_Check);
13901
13902 if Arg_Count = 3 then
13903 Check_Optional_Identifier (Arg3, Name_Message);
13904 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
13905 end if;
13906
13907 Check_Arg_Is_Local_Name (Arg1);
13908
13909 Type_Id := Get_Pragma_Arg (Arg1);
13910 Find_Type (Type_Id);
13911 Typ := Entity (Type_Id);
13912
13913 if Typ = Any_Type then
13914 return;
13915
13916 -- An invariant must apply to a private type, or appear in the
13917 -- private part of a package spec and apply to a completion.
13918
13919 elsif Ekind_In (Typ, E_Private_Type,
13920 E_Record_Type_With_Private,
13921 E_Limited_Private_Type)
13922 then
13923 null;
13924
13925 elsif In_Private_Part (Current_Scope)
13926 and then Has_Private_Declaration (Typ)
13927 then
13928 null;
13929
13930 elsif In_Private_Part (Current_Scope) then
13931 Error_Pragma_Arg
13932 ("pragma% only allowed for private type declared in "
13933 & "visible part", Arg1);
13934
13935 else
13936 Error_Pragma_Arg
13937 ("pragma% only allowed for private type", Arg1);
13938 end if;
13939
13940 -- Note that the type has at least one invariant, and also that
13941 -- it has inheritable invariants if we have Invariant'Class
13942 -- or Type_Invariant'Class. Build the corresponding invariant
13943 -- procedure declaration, so that calls to it can be generated
13944 -- before the body is built (e.g. within an expression function).
13945
13946 PDecl := Build_Invariant_Procedure_Declaration (Typ);
13947
13948 Insert_After (N, PDecl);
13949 Analyze (PDecl);
13950
13951 if Class_Present (N) then
13952 Set_Has_Inheritable_Invariants (Typ);
13953 end if;
13954
13955 -- The remaining processing is simply to link the pragma on to
13956 -- the rep item chain, for processing when the type is frozen.
13957 -- This is accomplished by a call to Rep_Item_Too_Late.
13958
13959 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13960 end Invariant;
13961
13962 ----------------------
13963 -- Java_Constructor --
13964 ----------------------
13965
13966 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
13967
13968 -- Also handles pragma CIL_Constructor
13969
13970 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
13971 Java_Constructor : declare
13972 Convention : Convention_Id;
13973 Def_Id : Entity_Id;
13974 Hom_Id : Entity_Id;
13975 Id : Entity_Id;
13976 This_Formal : Entity_Id;
13977
13978 begin
13979 GNAT_Pragma;
13980 Check_Arg_Count (1);
13981 Check_Optional_Identifier (Arg1, Name_Entity);
13982 Check_Arg_Is_Local_Name (Arg1);
13983
13984 Id := Get_Pragma_Arg (Arg1);
13985 Find_Program_Unit_Name (Id);
13986
13987 -- If we did not find the name, we are done
13988
13989 if Etype (Id) = Any_Type then
13990 return;
13991 end if;
13992
13993 -- Check wrong use of pragma in wrong VM target
13994
13995 if VM_Target = No_VM then
13996 return;
13997
13998 elsif VM_Target = CLI_Target
13999 and then Prag_Id = Pragma_Java_Constructor
14000 then
14001 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
14002
14003 elsif VM_Target = JVM_Target
14004 and then Prag_Id = Pragma_CIL_Constructor
14005 then
14006 Error_Pragma ("must use pragma 'Java_'Constructor");
14007 end if;
14008
14009 case Prag_Id is
14010 when Pragma_CIL_Constructor => Convention := Convention_CIL;
14011 when Pragma_Java_Constructor => Convention := Convention_Java;
14012 when others => null;
14013 end case;
14014
14015 Hom_Id := Entity (Id);
14016
14017 -- Loop through homonyms
14018
14019 loop
14020 Def_Id := Get_Base_Subprogram (Hom_Id);
14021
14022 -- The constructor is required to be a function
14023
14024 if Ekind (Def_Id) /= E_Function then
14025 if VM_Target = JVM_Target then
14026 Error_Pragma_Arg
14027 ("pragma% requires function returning a 'Java access "
14028 & "type", Def_Id);
14029 else
14030 Error_Pragma_Arg
14031 ("pragma% requires function returning a 'C'I'L access "
14032 & "type", Def_Id);
14033 end if;
14034 end if;
14035
14036 -- Check arguments: For tagged type the first formal must be
14037 -- named "this" and its type must be a named access type
14038 -- designating a class-wide tagged type that has convention
14039 -- CIL/Java. The first formal must also have a null default
14040 -- value. For example:
14041
14042 -- type Typ is tagged ...
14043 -- type Ref is access all Typ;
14044 -- pragma Convention (CIL, Typ);
14045
14046 -- function New_Typ (This : Ref) return Ref;
14047 -- function New_Typ (This : Ref; I : Integer) return Ref;
14048 -- pragma Cil_Constructor (New_Typ);
14049
14050 -- Reason: The first formal must NOT be a primitive of the
14051 -- tagged type.
14052
14053 -- This rule also applies to constructors of delegates used
14054 -- to interface with standard target libraries. For example:
14055
14056 -- type Delegate is access procedure ...
14057 -- pragma Import (CIL, Delegate, ...);
14058
14059 -- function new_Delegate
14060 -- (This : Delegate := null; ... ) return Delegate;
14061
14062 -- For value-types this rule does not apply.
14063
14064 if not Is_Value_Type (Etype (Def_Id)) then
14065 if No (First_Formal (Def_Id)) then
14066 Error_Msg_Name_1 := Pname;
14067 Error_Msg_N ("% function must have parameters", Def_Id);
14068 return;
14069 end if;
14070
14071 -- In the JRE library we have several occurrences in which
14072 -- the "this" parameter is not the first formal.
14073
14074 This_Formal := First_Formal (Def_Id);
14075
14076 -- In the JRE library we have several occurrences in which
14077 -- the "this" parameter is not the first formal. Search for
14078 -- it.
14079
14080 if VM_Target = JVM_Target then
14081 while Present (This_Formal)
14082 and then Get_Name_String (Chars (This_Formal)) /= "this"
14083 loop
14084 Next_Formal (This_Formal);
14085 end loop;
14086
14087 if No (This_Formal) then
14088 This_Formal := First_Formal (Def_Id);
14089 end if;
14090 end if;
14091
14092 -- Warning: The first parameter should be named "this".
14093 -- We temporarily allow it because we have the following
14094 -- case in the Java runtime (file s-osinte.ads) ???
14095
14096 -- function new_Thread
14097 -- (Self_Id : System.Address) return Thread_Id;
14098 -- pragma Java_Constructor (new_Thread);
14099
14100 if VM_Target = JVM_Target
14101 and then Get_Name_String (Chars (First_Formal (Def_Id)))
14102 = "self_id"
14103 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
14104 then
14105 null;
14106
14107 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
14108 Error_Msg_Name_1 := Pname;
14109 Error_Msg_N
14110 ("first formal of % function must be named `this`",
14111 Parent (This_Formal));
14112
14113 elsif not Is_Access_Type (Etype (This_Formal)) then
14114 Error_Msg_Name_1 := Pname;
14115 Error_Msg_N
14116 ("first formal of % function must be an access type",
14117 Parameter_Type (Parent (This_Formal)));
14118
14119 -- For delegates the type of the first formal must be a
14120 -- named access-to-subprogram type (see previous example)
14121
14122 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
14123 and then Ekind (Etype (This_Formal))
14124 /= E_Access_Subprogram_Type
14125 then
14126 Error_Msg_Name_1 := Pname;
14127 Error_Msg_N
14128 ("first formal of % function must be a named access "
14129 & "to subprogram type",
14130 Parameter_Type (Parent (This_Formal)));
14131
14132 -- Warning: We should reject anonymous access types because
14133 -- the constructor must not be handled as a primitive of the
14134 -- tagged type. We temporarily allow it because this profile
14135 -- is currently generated by cil2ada???
14136
14137 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
14138 and then not Ekind_In (Etype (This_Formal),
14139 E_Access_Type,
14140 E_General_Access_Type,
14141 E_Anonymous_Access_Type)
14142 then
14143 Error_Msg_Name_1 := Pname;
14144 Error_Msg_N
14145 ("first formal of % function must be a named access "
14146 & "type", Parameter_Type (Parent (This_Formal)));
14147
14148 elsif Atree.Convention
14149 (Designated_Type (Etype (This_Formal))) /= Convention
14150 then
14151 Error_Msg_Name_1 := Pname;
14152
14153 if Convention = Convention_Java then
14154 Error_Msg_N
14155 ("pragma% requires convention 'Cil in designated "
14156 & "type", Parameter_Type (Parent (This_Formal)));
14157 else
14158 Error_Msg_N
14159 ("pragma% requires convention 'Java in designated "
14160 & "type", Parameter_Type (Parent (This_Formal)));
14161 end if;
14162
14163 elsif No (Expression (Parent (This_Formal)))
14164 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
14165 then
14166 Error_Msg_Name_1 := Pname;
14167 Error_Msg_N
14168 ("pragma% requires first formal with default `null`",
14169 Parameter_Type (Parent (This_Formal)));
14170 end if;
14171 end if;
14172
14173 -- Check result type: the constructor must be a function
14174 -- returning:
14175 -- * a value type (only allowed in the CIL compiler)
14176 -- * an access-to-subprogram type with convention Java/CIL
14177 -- * an access-type designating a type that has convention
14178 -- Java/CIL.
14179
14180 if Is_Value_Type (Etype (Def_Id)) then
14181 null;
14182
14183 -- Access-to-subprogram type with convention Java/CIL
14184
14185 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
14186 if Atree.Convention (Etype (Def_Id)) /= Convention then
14187 if Convention = Convention_Java then
14188 Error_Pragma_Arg
14189 ("pragma% requires function returning a 'Java "
14190 & "access type", Arg1);
14191 else
14192 pragma Assert (Convention = Convention_CIL);
14193 Error_Pragma_Arg
14194 ("pragma% requires function returning a 'C'I'L "
14195 & "access type", Arg1);
14196 end if;
14197 end if;
14198
14199 elsif Ekind (Etype (Def_Id)) in Access_Kind then
14200 if not Ekind_In (Etype (Def_Id), E_Access_Type,
14201 E_General_Access_Type)
14202 or else
14203 Atree.Convention
14204 (Designated_Type (Etype (Def_Id))) /= Convention
14205 then
14206 Error_Msg_Name_1 := Pname;
14207
14208 if Convention = Convention_Java then
14209 Error_Pragma_Arg
14210 ("pragma% requires function returning a named "
14211 & "'Java access type", Arg1);
14212 else
14213 Error_Pragma_Arg
14214 ("pragma% requires function returning a named "
14215 & "'C'I'L access type", Arg1);
14216 end if;
14217 end if;
14218 end if;
14219
14220 Set_Is_Constructor (Def_Id);
14221 Set_Convention (Def_Id, Convention);
14222 Set_Is_Imported (Def_Id);
14223
14224 exit when From_Aspect_Specification (N);
14225 Hom_Id := Homonym (Hom_Id);
14226
14227 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
14228 end loop;
14229 end Java_Constructor;
14230
14231 ----------------------
14232 -- Java_Interface --
14233 ----------------------
14234
14235 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
14236
14237 when Pragma_Java_Interface => Java_Interface : declare
14238 Arg : Node_Id;
14239 Typ : Entity_Id;
14240
14241 begin
14242 GNAT_Pragma;
14243 Check_Arg_Count (1);
14244 Check_Optional_Identifier (Arg1, Name_Entity);
14245 Check_Arg_Is_Local_Name (Arg1);
14246
14247 Arg := Get_Pragma_Arg (Arg1);
14248 Analyze (Arg);
14249
14250 if Etype (Arg) = Any_Type then
14251 return;
14252 end if;
14253
14254 if not Is_Entity_Name (Arg)
14255 or else not Is_Type (Entity (Arg))
14256 then
14257 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
14258 end if;
14259
14260 Typ := Underlying_Type (Entity (Arg));
14261
14262 -- For now simply check some of the semantic constraints on the
14263 -- type. This currently leaves out some restrictions on interface
14264 -- types, namely that the parent type must be java.lang.Object.Typ
14265 -- and that all primitives of the type should be declared
14266 -- abstract. ???
14267
14268 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
14269 Error_Pragma_Arg
14270 ("pragma% requires an abstract tagged type", Arg1);
14271
14272 elsif not Has_Discriminants (Typ)
14273 or else Ekind (Etype (First_Discriminant (Typ)))
14274 /= E_Anonymous_Access_Type
14275 or else
14276 not Is_Class_Wide_Type
14277 (Designated_Type (Etype (First_Discriminant (Typ))))
14278 then
14279 Error_Pragma_Arg
14280 ("type must have a class-wide access discriminant", Arg1);
14281 end if;
14282 end Java_Interface;
14283
14284 ----------------
14285 -- Keep_Names --
14286 ----------------
14287
14288 -- pragma Keep_Names ([On => ] local_NAME);
14289
14290 when Pragma_Keep_Names => Keep_Names : declare
14291 Arg : Node_Id;
14292
14293 begin
14294 GNAT_Pragma;
14295 Check_Arg_Count (1);
14296 Check_Optional_Identifier (Arg1, Name_On);
14297 Check_Arg_Is_Local_Name (Arg1);
14298
14299 Arg := Get_Pragma_Arg (Arg1);
14300 Analyze (Arg);
14301
14302 if Etype (Arg) = Any_Type then
14303 return;
14304 end if;
14305
14306 if not Is_Entity_Name (Arg)
14307 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
14308 then
14309 Error_Pragma_Arg
14310 ("pragma% requires a local enumeration type", Arg1);
14311 end if;
14312
14313 Set_Discard_Names (Entity (Arg), False);
14314 end Keep_Names;
14315
14316 -------------
14317 -- License --
14318 -------------
14319
14320 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
14321
14322 when Pragma_License =>
14323 GNAT_Pragma;
14324 Check_Arg_Count (1);
14325 Check_No_Identifiers;
14326 Check_Valid_Configuration_Pragma;
14327 Check_Arg_Is_Identifier (Arg1);
14328
14329 declare
14330 Sind : constant Source_File_Index :=
14331 Source_Index (Current_Sem_Unit);
14332
14333 begin
14334 case Chars (Get_Pragma_Arg (Arg1)) is
14335 when Name_GPL =>
14336 Set_License (Sind, GPL);
14337
14338 when Name_Modified_GPL =>
14339 Set_License (Sind, Modified_GPL);
14340
14341 when Name_Restricted =>
14342 Set_License (Sind, Restricted);
14343
14344 when Name_Unrestricted =>
14345 Set_License (Sind, Unrestricted);
14346
14347 when others =>
14348 Error_Pragma_Arg ("invalid license name", Arg1);
14349 end case;
14350 end;
14351
14352 ---------------
14353 -- Link_With --
14354 ---------------
14355
14356 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
14357
14358 when Pragma_Link_With => Link_With : declare
14359 Arg : Node_Id;
14360
14361 begin
14362 GNAT_Pragma;
14363
14364 if Operating_Mode = Generate_Code
14365 and then In_Extended_Main_Source_Unit (N)
14366 then
14367 Check_At_Least_N_Arguments (1);
14368 Check_No_Identifiers;
14369 Check_Is_In_Decl_Part_Or_Package_Spec;
14370 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14371 Start_String;
14372
14373 Arg := Arg1;
14374 while Present (Arg) loop
14375 Check_Arg_Is_Static_Expression (Arg, Standard_String);
14376
14377 -- Store argument, converting sequences of spaces to a
14378 -- single null character (this is one of the differences
14379 -- in processing between Link_With and Linker_Options).
14380
14381 Arg_Store : declare
14382 C : constant Char_Code := Get_Char_Code (' ');
14383 S : constant String_Id :=
14384 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
14385 L : constant Nat := String_Length (S);
14386 F : Nat := 1;
14387
14388 procedure Skip_Spaces;
14389 -- Advance F past any spaces
14390
14391 -----------------
14392 -- Skip_Spaces --
14393 -----------------
14394
14395 procedure Skip_Spaces is
14396 begin
14397 while F <= L and then Get_String_Char (S, F) = C loop
14398 F := F + 1;
14399 end loop;
14400 end Skip_Spaces;
14401
14402 -- Start of processing for Arg_Store
14403
14404 begin
14405 Skip_Spaces; -- skip leading spaces
14406
14407 -- Loop through characters, changing any embedded
14408 -- sequence of spaces to a single null character (this
14409 -- is how Link_With/Linker_Options differ)
14410
14411 while F <= L loop
14412 if Get_String_Char (S, F) = C then
14413 Skip_Spaces;
14414 exit when F > L;
14415 Store_String_Char (ASCII.NUL);
14416
14417 else
14418 Store_String_Char (Get_String_Char (S, F));
14419 F := F + 1;
14420 end if;
14421 end loop;
14422 end Arg_Store;
14423
14424 Arg := Next (Arg);
14425
14426 if Present (Arg) then
14427 Store_String_Char (ASCII.NUL);
14428 end if;
14429 end loop;
14430
14431 Store_Linker_Option_String (End_String);
14432 end if;
14433 end Link_With;
14434
14435 ------------------
14436 -- Linker_Alias --
14437 ------------------
14438
14439 -- pragma Linker_Alias (
14440 -- [Entity =>] LOCAL_NAME
14441 -- [Target =>] static_string_EXPRESSION);
14442
14443 when Pragma_Linker_Alias =>
14444 GNAT_Pragma;
14445 Check_Arg_Order ((Name_Entity, Name_Target));
14446 Check_Arg_Count (2);
14447 Check_Optional_Identifier (Arg1, Name_Entity);
14448 Check_Optional_Identifier (Arg2, Name_Target);
14449 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14450 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
14451
14452 -- The only processing required is to link this item on to the
14453 -- list of rep items for the given entity. This is accomplished
14454 -- by the call to Rep_Item_Too_Late (when no error is detected
14455 -- and False is returned).
14456
14457 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
14458 return;
14459 else
14460 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
14461 end if;
14462
14463 ------------------------
14464 -- Linker_Constructor --
14465 ------------------------
14466
14467 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
14468
14469 -- Code is shared with Linker_Destructor
14470
14471 -----------------------
14472 -- Linker_Destructor --
14473 -----------------------
14474
14475 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
14476
14477 when Pragma_Linker_Constructor |
14478 Pragma_Linker_Destructor =>
14479 Linker_Constructor : declare
14480 Arg1_X : Node_Id;
14481 Proc : Entity_Id;
14482
14483 begin
14484 GNAT_Pragma;
14485 Check_Arg_Count (1);
14486 Check_No_Identifiers;
14487 Check_Arg_Is_Local_Name (Arg1);
14488 Arg1_X := Get_Pragma_Arg (Arg1);
14489 Analyze (Arg1_X);
14490 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
14491
14492 if not Is_Library_Level_Entity (Proc) then
14493 Error_Pragma_Arg
14494 ("argument for pragma% must be library level entity", Arg1);
14495 end if;
14496
14497 -- The only processing required is to link this item on to the
14498 -- list of rep items for the given entity. This is accomplished
14499 -- by the call to Rep_Item_Too_Late (when no error is detected
14500 -- and False is returned).
14501
14502 if Rep_Item_Too_Late (Proc, N) then
14503 return;
14504 else
14505 Set_Has_Gigi_Rep_Item (Proc);
14506 end if;
14507 end Linker_Constructor;
14508
14509 --------------------
14510 -- Linker_Options --
14511 --------------------
14512
14513 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
14514
14515 when Pragma_Linker_Options => Linker_Options : declare
14516 Arg : Node_Id;
14517
14518 begin
14519 Check_Ada_83_Warning;
14520 Check_No_Identifiers;
14521 Check_Arg_Count (1);
14522 Check_Is_In_Decl_Part_Or_Package_Spec;
14523 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14524 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
14525
14526 Arg := Arg2;
14527 while Present (Arg) loop
14528 Check_Arg_Is_Static_Expression (Arg, Standard_String);
14529 Store_String_Char (ASCII.NUL);
14530 Store_String_Chars
14531 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
14532 Arg := Next (Arg);
14533 end loop;
14534
14535 if Operating_Mode = Generate_Code
14536 and then In_Extended_Main_Source_Unit (N)
14537 then
14538 Store_Linker_Option_String (End_String);
14539 end if;
14540 end Linker_Options;
14541
14542 --------------------
14543 -- Linker_Section --
14544 --------------------
14545
14546 -- pragma Linker_Section (
14547 -- [Entity =>] LOCAL_NAME
14548 -- [Section =>] static_string_EXPRESSION);
14549
14550 when Pragma_Linker_Section =>
14551 GNAT_Pragma;
14552 Check_Arg_Order ((Name_Entity, Name_Section));
14553 Check_Arg_Count (2);
14554 Check_Optional_Identifier (Arg1, Name_Entity);
14555 Check_Optional_Identifier (Arg2, Name_Section);
14556 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14557 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
14558
14559 -- This pragma applies to objects and types
14560
14561 if not Is_Object (Entity (Get_Pragma_Arg (Arg1)))
14562 and then not Is_Type (Entity (Get_Pragma_Arg (Arg1)))
14563 then
14564 Error_Pragma_Arg
14565 ("pragma% applies only to objects and types", Arg1);
14566 end if;
14567
14568 -- The only processing required is to link this item on to the
14569 -- list of rep items for the given entity. This is accomplished
14570 -- by the call to Rep_Item_Too_Late (when no error is detected
14571 -- and False is returned).
14572
14573 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
14574 return;
14575 else
14576 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
14577 end if;
14578
14579 ----------
14580 -- List --
14581 ----------
14582
14583 -- pragma List (On | Off)
14584
14585 -- There is nothing to do here, since we did all the processing for
14586 -- this pragma in Par.Prag (so that it works properly even in syntax
14587 -- only mode).
14588
14589 when Pragma_List =>
14590 null;
14591
14592 ---------------
14593 -- Lock_Free --
14594 ---------------
14595
14596 -- pragma Lock_Free [(Boolean_EXPRESSION)];
14597
14598 when Pragma_Lock_Free => Lock_Free : declare
14599 P : constant Node_Id := Parent (N);
14600 Arg : Node_Id;
14601 Ent : Entity_Id;
14602 Val : Boolean;
14603
14604 begin
14605 Check_No_Identifiers;
14606 Check_At_Most_N_Arguments (1);
14607
14608 -- Protected definition case
14609
14610 if Nkind (P) = N_Protected_Definition then
14611 Ent := Defining_Identifier (Parent (P));
14612
14613 -- One argument
14614
14615 if Arg_Count = 1 then
14616 Arg := Get_Pragma_Arg (Arg1);
14617 Val := Is_True (Static_Boolean (Arg));
14618
14619 -- No arguments (expression is considered to be True)
14620
14621 else
14622 Val := True;
14623 end if;
14624
14625 -- Check duplicate pragma before we chain the pragma in the Rep
14626 -- Item chain of Ent.
14627
14628 Check_Duplicate_Pragma (Ent);
14629 Record_Rep_Item (Ent, N);
14630 Set_Uses_Lock_Free (Ent, Val);
14631
14632 -- Anything else is incorrect placement
14633
14634 else
14635 Pragma_Misplaced;
14636 end if;
14637 end Lock_Free;
14638
14639 --------------------
14640 -- Locking_Policy --
14641 --------------------
14642
14643 -- pragma Locking_Policy (policy_IDENTIFIER);
14644
14645 when Pragma_Locking_Policy => declare
14646 subtype LP_Range is Name_Id
14647 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
14648 LP_Val : LP_Range;
14649 LP : Character;
14650
14651 begin
14652 Check_Ada_83_Warning;
14653 Check_Arg_Count (1);
14654 Check_No_Identifiers;
14655 Check_Arg_Is_Locking_Policy (Arg1);
14656 Check_Valid_Configuration_Pragma;
14657 LP_Val := Chars (Get_Pragma_Arg (Arg1));
14658
14659 case LP_Val is
14660 when Name_Ceiling_Locking =>
14661 LP := 'C';
14662 when Name_Inheritance_Locking =>
14663 LP := 'I';
14664 when Name_Concurrent_Readers_Locking =>
14665 LP := 'R';
14666 end case;
14667
14668 if Locking_Policy /= ' '
14669 and then Locking_Policy /= LP
14670 then
14671 Error_Msg_Sloc := Locking_Policy_Sloc;
14672 Error_Pragma ("locking policy incompatible with policy#");
14673
14674 -- Set new policy, but always preserve System_Location since we
14675 -- like the error message with the run time name.
14676
14677 else
14678 Locking_Policy := LP;
14679
14680 if Locking_Policy_Sloc /= System_Location then
14681 Locking_Policy_Sloc := Loc;
14682 end if;
14683 end if;
14684 end;
14685
14686 ----------------
14687 -- Long_Float --
14688 ----------------
14689
14690 -- pragma Long_Float (D_Float | G_Float);
14691
14692 when Pragma_Long_Float => Long_Float : declare
14693 begin
14694 GNAT_Pragma;
14695 Check_Valid_Configuration_Pragma;
14696 Check_Arg_Count (1);
14697 Check_No_Identifier (Arg1);
14698 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
14699
14700 if not OpenVMS_On_Target then
14701 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
14702 end if;
14703
14704 -- D_Float case
14705
14706 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
14707 if Opt.Float_Format_Long = 'G' then
14708 Error_Pragma_Arg
14709 ("G_Float previously specified", Arg1);
14710
14711 elsif Current_Sem_Unit /= Main_Unit
14712 and then Opt.Float_Format_Long /= 'D'
14713 then
14714 Error_Pragma_Arg
14715 ("main unit not compiled with pragma Long_Float (D_Float)",
14716 "\pragma% must be used consistently for whole partition",
14717 Arg1);
14718
14719 else
14720 Opt.Float_Format_Long := 'D';
14721 end if;
14722
14723 -- G_Float case (this is the default, does not need overriding)
14724
14725 else
14726 if Opt.Float_Format_Long = 'D' then
14727 Error_Pragma ("D_Float previously specified");
14728
14729 elsif Current_Sem_Unit /= Main_Unit
14730 and then Opt.Float_Format_Long /= 'G'
14731 then
14732 Error_Pragma_Arg
14733 ("main unit not compiled with pragma Long_Float (G_Float)",
14734 "\pragma% must be used consistently for whole partition",
14735 Arg1);
14736
14737 else
14738 Opt.Float_Format_Long := 'G';
14739 end if;
14740 end if;
14741
14742 Set_Standard_Fpt_Formats;
14743 end Long_Float;
14744
14745 -------------------
14746 -- Loop_Optimize --
14747 -------------------
14748
14749 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
14750
14751 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
14752
14753 when Pragma_Loop_Optimize => Loop_Optimize : declare
14754 Hint : Node_Id;
14755
14756 begin
14757 GNAT_Pragma;
14758 Check_At_Least_N_Arguments (1);
14759 Check_No_Identifiers;
14760
14761 Hint := First (Pragma_Argument_Associations (N));
14762 while Present (Hint) loop
14763 Check_Arg_Is_One_Of (Hint,
14764 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
14765 Next (Hint);
14766 end loop;
14767
14768 Check_Loop_Pragma_Placement;
14769 end Loop_Optimize;
14770
14771 ------------------
14772 -- Loop_Variant --
14773 ------------------
14774
14775 -- pragma Loop_Variant
14776 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
14777
14778 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
14779
14780 -- CHANGE_DIRECTION ::= Increases | Decreases
14781
14782 when Pragma_Loop_Variant => Loop_Variant : declare
14783 Variant : Node_Id;
14784
14785 begin
14786 GNAT_Pragma;
14787 Check_At_Least_N_Arguments (1);
14788 Check_Loop_Pragma_Placement;
14789
14790 -- Process all increasing / decreasing expressions
14791
14792 Variant := First (Pragma_Argument_Associations (N));
14793 while Present (Variant) loop
14794 if not Nam_In (Chars (Variant), Name_Decreases,
14795 Name_Increases)
14796 then
14797 Error_Pragma_Arg ("wrong change modifier", Variant);
14798 end if;
14799
14800 Preanalyze_Assert_Expression
14801 (Expression (Variant), Any_Discrete);
14802
14803 Next (Variant);
14804 end loop;
14805 end Loop_Variant;
14806
14807 -----------------------
14808 -- Machine_Attribute --
14809 -----------------------
14810
14811 -- pragma Machine_Attribute (
14812 -- [Entity =>] LOCAL_NAME,
14813 -- [Attribute_Name =>] static_string_EXPRESSION
14814 -- [, [Info =>] static_EXPRESSION] );
14815
14816 when Pragma_Machine_Attribute => Machine_Attribute : declare
14817 Def_Id : Entity_Id;
14818
14819 begin
14820 GNAT_Pragma;
14821 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
14822
14823 if Arg_Count = 3 then
14824 Check_Optional_Identifier (Arg3, Name_Info);
14825 Check_Arg_Is_Static_Expression (Arg3);
14826 else
14827 Check_Arg_Count (2);
14828 end if;
14829
14830 Check_Optional_Identifier (Arg1, Name_Entity);
14831 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
14832 Check_Arg_Is_Local_Name (Arg1);
14833 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
14834 Def_Id := Entity (Get_Pragma_Arg (Arg1));
14835
14836 if Is_Access_Type (Def_Id) then
14837 Def_Id := Designated_Type (Def_Id);
14838 end if;
14839
14840 if Rep_Item_Too_Early (Def_Id, N) then
14841 return;
14842 end if;
14843
14844 Def_Id := Underlying_Type (Def_Id);
14845
14846 -- The only processing required is to link this item on to the
14847 -- list of rep items for the given entity. This is accomplished
14848 -- by the call to Rep_Item_Too_Late (when no error is detected
14849 -- and False is returned).
14850
14851 if Rep_Item_Too_Late (Def_Id, N) then
14852 return;
14853 else
14854 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
14855 end if;
14856 end Machine_Attribute;
14857
14858 ----------
14859 -- Main --
14860 ----------
14861
14862 -- pragma Main
14863 -- (MAIN_OPTION [, MAIN_OPTION]);
14864
14865 -- MAIN_OPTION ::=
14866 -- [STACK_SIZE =>] static_integer_EXPRESSION
14867 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
14868 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
14869
14870 when Pragma_Main => Main : declare
14871 Args : Args_List (1 .. 3);
14872 Names : constant Name_List (1 .. 3) := (
14873 Name_Stack_Size,
14874 Name_Task_Stack_Size_Default,
14875 Name_Time_Slicing_Enabled);
14876
14877 Nod : Node_Id;
14878
14879 begin
14880 GNAT_Pragma;
14881 Gather_Associations (Names, Args);
14882
14883 for J in 1 .. 2 loop
14884 if Present (Args (J)) then
14885 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
14886 end if;
14887 end loop;
14888
14889 if Present (Args (3)) then
14890 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
14891 end if;
14892
14893 Nod := Next (N);
14894 while Present (Nod) loop
14895 if Nkind (Nod) = N_Pragma
14896 and then Pragma_Name (Nod) = Name_Main
14897 then
14898 Error_Msg_Name_1 := Pname;
14899 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14900 end if;
14901
14902 Next (Nod);
14903 end loop;
14904 end Main;
14905
14906 ------------------
14907 -- Main_Storage --
14908 ------------------
14909
14910 -- pragma Main_Storage
14911 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
14912
14913 -- MAIN_STORAGE_OPTION ::=
14914 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
14915 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
14916
14917 when Pragma_Main_Storage => Main_Storage : declare
14918 Args : Args_List (1 .. 2);
14919 Names : constant Name_List (1 .. 2) := (
14920 Name_Working_Storage,
14921 Name_Top_Guard);
14922
14923 Nod : Node_Id;
14924
14925 begin
14926 GNAT_Pragma;
14927 Gather_Associations (Names, Args);
14928
14929 for J in 1 .. 2 loop
14930 if Present (Args (J)) then
14931 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
14932 end if;
14933 end loop;
14934
14935 Check_In_Main_Program;
14936
14937 Nod := Next (N);
14938 while Present (Nod) loop
14939 if Nkind (Nod) = N_Pragma
14940 and then Pragma_Name (Nod) = Name_Main_Storage
14941 then
14942 Error_Msg_Name_1 := Pname;
14943 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14944 end if;
14945
14946 Next (Nod);
14947 end loop;
14948 end Main_Storage;
14949
14950 -----------------
14951 -- Memory_Size --
14952 -----------------
14953
14954 -- pragma Memory_Size (NUMERIC_LITERAL)
14955
14956 when Pragma_Memory_Size =>
14957 GNAT_Pragma;
14958
14959 -- Memory size is simply ignored
14960
14961 Check_No_Identifiers;
14962 Check_Arg_Count (1);
14963 Check_Arg_Is_Integer_Literal (Arg1);
14964
14965 -------------
14966 -- No_Body --
14967 -------------
14968
14969 -- pragma No_Body;
14970
14971 -- The only correct use of this pragma is on its own in a file, in
14972 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
14973 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
14974 -- check for a file containing nothing but a No_Body pragma). If we
14975 -- attempt to process it during normal semantics processing, it means
14976 -- it was misplaced.
14977
14978 when Pragma_No_Body =>
14979 GNAT_Pragma;
14980 Pragma_Misplaced;
14981
14982 ---------------
14983 -- No_Inline --
14984 ---------------
14985
14986 -- pragma No_Inline ( NAME {, NAME} );
14987
14988 when Pragma_No_Inline =>
14989 GNAT_Pragma;
14990 Process_Inline (Suppressed);
14991
14992 ---------------
14993 -- No_Return --
14994 ---------------
14995
14996 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
14997
14998 when Pragma_No_Return => No_Return : declare
14999 Id : Node_Id;
15000 E : Entity_Id;
15001 Found : Boolean;
15002 Arg : Node_Id;
15003
15004 begin
15005 Ada_2005_Pragma;
15006 Check_At_Least_N_Arguments (1);
15007
15008 -- Loop through arguments of pragma
15009
15010 Arg := Arg1;
15011 while Present (Arg) loop
15012 Check_Arg_Is_Local_Name (Arg);
15013 Id := Get_Pragma_Arg (Arg);
15014 Analyze (Id);
15015
15016 if not Is_Entity_Name (Id) then
15017 Error_Pragma_Arg ("entity name required", Arg);
15018 end if;
15019
15020 if Etype (Id) = Any_Type then
15021 raise Pragma_Exit;
15022 end if;
15023
15024 -- Loop to find matching procedures
15025
15026 E := Entity (Id);
15027 Found := False;
15028 while Present (E)
15029 and then Scope (E) = Current_Scope
15030 loop
15031 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
15032 Set_No_Return (E);
15033
15034 -- Set flag on any alias as well
15035
15036 if Is_Overloadable (E) and then Present (Alias (E)) then
15037 Set_No_Return (Alias (E));
15038 end if;
15039
15040 Found := True;
15041 end if;
15042
15043 exit when From_Aspect_Specification (N);
15044 E := Homonym (E);
15045 end loop;
15046
15047 if not Found then
15048 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
15049 end if;
15050
15051 Next (Arg);
15052 end loop;
15053 end No_Return;
15054
15055 -----------------
15056 -- No_Run_Time --
15057 -----------------
15058
15059 -- pragma No_Run_Time;
15060
15061 -- Note: this pragma is retained for backwards compatibility. See
15062 -- body of Rtsfind for full details on its handling.
15063
15064 when Pragma_No_Run_Time =>
15065 GNAT_Pragma;
15066 Check_Valid_Configuration_Pragma;
15067 Check_Arg_Count (0);
15068
15069 No_Run_Time_Mode := True;
15070 Configurable_Run_Time_Mode := True;
15071
15072 -- Set Duration to 32 bits if word size is 32
15073
15074 if Ttypes.System_Word_Size = 32 then
15075 Duration_32_Bits_On_Target := True;
15076 end if;
15077
15078 -- Set appropriate restrictions
15079
15080 Set_Restriction (No_Finalization, N);
15081 Set_Restriction (No_Exception_Handlers, N);
15082 Set_Restriction (Max_Tasks, N, 0);
15083 Set_Restriction (No_Tasking, N);
15084
15085 ------------------------
15086 -- No_Strict_Aliasing --
15087 ------------------------
15088
15089 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
15090
15091 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
15092 E_Id : Entity_Id;
15093
15094 begin
15095 GNAT_Pragma;
15096 Check_At_Most_N_Arguments (1);
15097
15098 if Arg_Count = 0 then
15099 Check_Valid_Configuration_Pragma;
15100 Opt.No_Strict_Aliasing := True;
15101
15102 else
15103 Check_Optional_Identifier (Arg2, Name_Entity);
15104 Check_Arg_Is_Local_Name (Arg1);
15105 E_Id := Entity (Get_Pragma_Arg (Arg1));
15106
15107 if E_Id = Any_Type then
15108 return;
15109 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
15110 Error_Pragma_Arg ("pragma% requires access type", Arg1);
15111 end if;
15112
15113 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
15114 end if;
15115 end No_Strict_Aliasing;
15116
15117 -----------------------
15118 -- Normalize_Scalars --
15119 -----------------------
15120
15121 -- pragma Normalize_Scalars;
15122
15123 when Pragma_Normalize_Scalars =>
15124 Check_Ada_83_Warning;
15125 Check_Arg_Count (0);
15126 Check_Valid_Configuration_Pragma;
15127
15128 -- Normalize_Scalars creates false positives in CodePeer, and
15129 -- incorrect negative results in SPARK mode, so ignore this pragma
15130 -- in these modes.
15131
15132 if not (CodePeer_Mode or SPARK_Mode) then
15133 Normalize_Scalars := True;
15134 Init_Or_Norm_Scalars := True;
15135 end if;
15136
15137 -----------------
15138 -- Obsolescent --
15139 -----------------
15140
15141 -- pragma Obsolescent;
15142
15143 -- pragma Obsolescent (
15144 -- [Message =>] static_string_EXPRESSION
15145 -- [,[Version =>] Ada_05]]);
15146
15147 -- pragma Obsolescent (
15148 -- [Entity =>] NAME
15149 -- [,[Message =>] static_string_EXPRESSION
15150 -- [,[Version =>] Ada_05]] );
15151
15152 when Pragma_Obsolescent => Obsolescent : declare
15153 Ename : Node_Id;
15154 Decl : Node_Id;
15155
15156 procedure Set_Obsolescent (E : Entity_Id);
15157 -- Given an entity Ent, mark it as obsolescent if appropriate
15158
15159 ---------------------
15160 -- Set_Obsolescent --
15161 ---------------------
15162
15163 procedure Set_Obsolescent (E : Entity_Id) is
15164 Active : Boolean;
15165 Ent : Entity_Id;
15166 S : String_Id;
15167
15168 begin
15169 Active := True;
15170 Ent := E;
15171
15172 -- Entity name was given
15173
15174 if Present (Ename) then
15175
15176 -- If entity name matches, we are fine. Save entity in
15177 -- pragma argument, for ASIS use.
15178
15179 if Chars (Ename) = Chars (Ent) then
15180 Set_Entity (Ename, Ent);
15181 Generate_Reference (Ent, Ename);
15182
15183 -- If entity name does not match, only possibility is an
15184 -- enumeration literal from an enumeration type declaration.
15185
15186 elsif Ekind (Ent) /= E_Enumeration_Type then
15187 Error_Pragma
15188 ("pragma % entity name does not match declaration");
15189
15190 else
15191 Ent := First_Literal (E);
15192 loop
15193 if No (Ent) then
15194 Error_Pragma
15195 ("pragma % entity name does not match any "
15196 & "enumeration literal");
15197
15198 elsif Chars (Ent) = Chars (Ename) then
15199 Set_Entity (Ename, Ent);
15200 Generate_Reference (Ent, Ename);
15201 exit;
15202
15203 else
15204 Ent := Next_Literal (Ent);
15205 end if;
15206 end loop;
15207 end if;
15208 end if;
15209
15210 -- Ent points to entity to be marked
15211
15212 if Arg_Count >= 1 then
15213
15214 -- Deal with static string argument
15215
15216 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
15217 S := Strval (Get_Pragma_Arg (Arg1));
15218
15219 for J in 1 .. String_Length (S) loop
15220 if not In_Character_Range (Get_String_Char (S, J)) then
15221 Error_Pragma_Arg
15222 ("pragma% argument does not allow wide characters",
15223 Arg1);
15224 end if;
15225 end loop;
15226
15227 Obsolescent_Warnings.Append
15228 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
15229
15230 -- Check for Ada_05 parameter
15231
15232 if Arg_Count /= 1 then
15233 Check_Arg_Count (2);
15234
15235 declare
15236 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
15237
15238 begin
15239 Check_Arg_Is_Identifier (Argx);
15240
15241 if Chars (Argx) /= Name_Ada_05 then
15242 Error_Msg_Name_2 := Name_Ada_05;
15243 Error_Pragma_Arg
15244 ("only allowed argument for pragma% is %", Argx);
15245 end if;
15246
15247 if Ada_Version_Explicit < Ada_2005
15248 or else not Warn_On_Ada_2005_Compatibility
15249 then
15250 Active := False;
15251 end if;
15252 end;
15253 end if;
15254 end if;
15255
15256 -- Set flag if pragma active
15257
15258 if Active then
15259 Set_Is_Obsolescent (Ent);
15260 end if;
15261
15262 return;
15263 end Set_Obsolescent;
15264
15265 -- Start of processing for pragma Obsolescent
15266
15267 begin
15268 GNAT_Pragma;
15269
15270 Check_At_Most_N_Arguments (3);
15271
15272 -- See if first argument specifies an entity name
15273
15274 if Arg_Count >= 1
15275 and then
15276 (Chars (Arg1) = Name_Entity
15277 or else
15278 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
15279 N_Identifier,
15280 N_Operator_Symbol))
15281 then
15282 Ename := Get_Pragma_Arg (Arg1);
15283
15284 -- Eliminate first argument, so we can share processing
15285
15286 Arg1 := Arg2;
15287 Arg2 := Arg3;
15288 Arg_Count := Arg_Count - 1;
15289
15290 -- No Entity name argument given
15291
15292 else
15293 Ename := Empty;
15294 end if;
15295
15296 if Arg_Count >= 1 then
15297 Check_Optional_Identifier (Arg1, Name_Message);
15298
15299 if Arg_Count = 2 then
15300 Check_Optional_Identifier (Arg2, Name_Version);
15301 end if;
15302 end if;
15303
15304 -- Get immediately preceding declaration
15305
15306 Decl := Prev (N);
15307 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
15308 Prev (Decl);
15309 end loop;
15310
15311 -- Cases where we do not follow anything other than another pragma
15312
15313 if No (Decl) then
15314
15315 -- First case: library level compilation unit declaration with
15316 -- the pragma immediately following the declaration.
15317
15318 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
15319 Set_Obsolescent
15320 (Defining_Entity (Unit (Parent (Parent (N)))));
15321 return;
15322
15323 -- Case 2: library unit placement for package
15324
15325 else
15326 declare
15327 Ent : constant Entity_Id := Find_Lib_Unit_Name;
15328 begin
15329 if Is_Package_Or_Generic_Package (Ent) then
15330 Set_Obsolescent (Ent);
15331 return;
15332 end if;
15333 end;
15334 end if;
15335
15336 -- Cases where we must follow a declaration
15337
15338 else
15339 if Nkind (Decl) not in N_Declaration
15340 and then Nkind (Decl) not in N_Later_Decl_Item
15341 and then Nkind (Decl) not in N_Generic_Declaration
15342 and then Nkind (Decl) not in N_Renaming_Declaration
15343 then
15344 Error_Pragma
15345 ("pragma% misplaced, "
15346 & "must immediately follow a declaration");
15347
15348 else
15349 Set_Obsolescent (Defining_Entity (Decl));
15350 return;
15351 end if;
15352 end if;
15353 end Obsolescent;
15354
15355 --------------
15356 -- Optimize --
15357 --------------
15358
15359 -- pragma Optimize (Time | Space | Off);
15360
15361 -- The actual check for optimize is done in Gigi. Note that this
15362 -- pragma does not actually change the optimization setting, it
15363 -- simply checks that it is consistent with the pragma.
15364
15365 when Pragma_Optimize =>
15366 Check_No_Identifiers;
15367 Check_Arg_Count (1);
15368 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
15369
15370 ------------------------
15371 -- Optimize_Alignment --
15372 ------------------------
15373
15374 -- pragma Optimize_Alignment (Time | Space | Off);
15375
15376 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
15377 GNAT_Pragma;
15378 Check_No_Identifiers;
15379 Check_Arg_Count (1);
15380 Check_Valid_Configuration_Pragma;
15381
15382 declare
15383 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
15384 begin
15385 case Nam is
15386 when Name_Time =>
15387 Opt.Optimize_Alignment := 'T';
15388 when Name_Space =>
15389 Opt.Optimize_Alignment := 'S';
15390 when Name_Off =>
15391 Opt.Optimize_Alignment := 'O';
15392 when others =>
15393 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
15394 end case;
15395 end;
15396
15397 -- Set indication that mode is set locally. If we are in fact in a
15398 -- configuration pragma file, this setting is harmless since the
15399 -- switch will get reset anyway at the start of each unit.
15400
15401 Optimize_Alignment_Local := True;
15402 end Optimize_Alignment;
15403
15404 -------------
15405 -- Ordered --
15406 -------------
15407
15408 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
15409
15410 when Pragma_Ordered => Ordered : declare
15411 Assoc : constant Node_Id := Arg1;
15412 Type_Id : Node_Id;
15413 Typ : Entity_Id;
15414
15415 begin
15416 GNAT_Pragma;
15417 Check_No_Identifiers;
15418 Check_Arg_Count (1);
15419 Check_Arg_Is_Local_Name (Arg1);
15420
15421 Type_Id := Get_Pragma_Arg (Assoc);
15422 Find_Type (Type_Id);
15423 Typ := Entity (Type_Id);
15424
15425 if Typ = Any_Type then
15426 return;
15427 else
15428 Typ := Underlying_Type (Typ);
15429 end if;
15430
15431 if not Is_Enumeration_Type (Typ) then
15432 Error_Pragma ("pragma% must specify enumeration type");
15433 end if;
15434
15435 Check_First_Subtype (Arg1);
15436 Set_Has_Pragma_Ordered (Base_Type (Typ));
15437 end Ordered;
15438
15439 -------------------
15440 -- Overflow_Mode --
15441 -------------------
15442
15443 -- pragma Overflow_Mode
15444 -- ([General => ] MODE [, [Assertions => ] MODE]);
15445
15446 -- MODE := STRICT | MINIMIZED | ELIMINATED
15447
15448 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
15449 -- since System.Bignums makes this assumption. This is true of nearly
15450 -- all (all?) targets.
15451
15452 when Pragma_Overflow_Mode => Overflow_Mode : declare
15453 function Get_Overflow_Mode
15454 (Name : Name_Id;
15455 Arg : Node_Id) return Overflow_Mode_Type;
15456 -- Function to process one pragma argument, Arg. If an identifier
15457 -- is present, it must be Name. Mode type is returned if a valid
15458 -- argument exists, otherwise an error is signalled.
15459
15460 -----------------------
15461 -- Get_Overflow_Mode --
15462 -----------------------
15463
15464 function Get_Overflow_Mode
15465 (Name : Name_Id;
15466 Arg : Node_Id) return Overflow_Mode_Type
15467 is
15468 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
15469
15470 begin
15471 Check_Optional_Identifier (Arg, Name);
15472 Check_Arg_Is_Identifier (Argx);
15473
15474 if Chars (Argx) = Name_Strict then
15475 return Strict;
15476
15477 elsif Chars (Argx) = Name_Minimized then
15478 return Minimized;
15479
15480 elsif Chars (Argx) = Name_Eliminated then
15481 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
15482 Error_Pragma_Arg
15483 ("Eliminated not implemented on this target", Argx);
15484 else
15485 return Eliminated;
15486 end if;
15487
15488 else
15489 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
15490 end if;
15491 end Get_Overflow_Mode;
15492
15493 -- Start of processing for Overflow_Mode
15494
15495 begin
15496 GNAT_Pragma;
15497 Check_At_Least_N_Arguments (1);
15498 Check_At_Most_N_Arguments (2);
15499
15500 -- Process first argument
15501
15502 Scope_Suppress.Overflow_Mode_General :=
15503 Get_Overflow_Mode (Name_General, Arg1);
15504
15505 -- Case of only one argument
15506
15507 if Arg_Count = 1 then
15508 Scope_Suppress.Overflow_Mode_Assertions :=
15509 Scope_Suppress.Overflow_Mode_General;
15510
15511 -- Case of two arguments present
15512
15513 else
15514 Scope_Suppress.Overflow_Mode_Assertions :=
15515 Get_Overflow_Mode (Name_Assertions, Arg2);
15516 end if;
15517 end Overflow_Mode;
15518
15519 --------------------------
15520 -- Overriding Renamings --
15521 --------------------------
15522
15523 -- pragma Overriding_Renamings;
15524
15525 when Pragma_Overriding_Renamings =>
15526 GNAT_Pragma;
15527 Check_Arg_Count (0);
15528 Check_Valid_Configuration_Pragma;
15529 Overriding_Renamings := True;
15530
15531 ----------
15532 -- Pack --
15533 ----------
15534
15535 -- pragma Pack (first_subtype_LOCAL_NAME);
15536
15537 when Pragma_Pack => Pack : declare
15538 Assoc : constant Node_Id := Arg1;
15539 Type_Id : Node_Id;
15540 Typ : Entity_Id;
15541 Ctyp : Entity_Id;
15542 Ignore : Boolean := False;
15543
15544 begin
15545 Check_No_Identifiers;
15546 Check_Arg_Count (1);
15547 Check_Arg_Is_Local_Name (Arg1);
15548
15549 Type_Id := Get_Pragma_Arg (Assoc);
15550 Find_Type (Type_Id);
15551 Typ := Entity (Type_Id);
15552
15553 if Typ = Any_Type
15554 or else Rep_Item_Too_Early (Typ, N)
15555 then
15556 return;
15557 else
15558 Typ := Underlying_Type (Typ);
15559 end if;
15560
15561 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
15562 Error_Pragma ("pragma% must specify array or record type");
15563 end if;
15564
15565 Check_First_Subtype (Arg1);
15566 Check_Duplicate_Pragma (Typ);
15567
15568 -- Array type
15569
15570 if Is_Array_Type (Typ) then
15571 Ctyp := Component_Type (Typ);
15572
15573 -- Ignore pack that does nothing
15574
15575 if Known_Static_Esize (Ctyp)
15576 and then Known_Static_RM_Size (Ctyp)
15577 and then Esize (Ctyp) = RM_Size (Ctyp)
15578 and then Addressable (Esize (Ctyp))
15579 then
15580 Ignore := True;
15581 end if;
15582
15583 -- Process OK pragma Pack. Note that if there is a separate
15584 -- component clause present, the Pack will be cancelled. This
15585 -- processing is in Freeze.
15586
15587 if not Rep_Item_Too_Late (Typ, N) then
15588
15589 -- In the context of static code analysis, we do not need
15590 -- complex front-end expansions related to pragma Pack,
15591 -- so disable handling of pragma Pack in these cases.
15592
15593 if CodePeer_Mode or SPARK_Mode then
15594 null;
15595
15596 -- Don't attempt any packing for VM targets. We possibly
15597 -- could deal with some cases of array bit-packing, but we
15598 -- don't bother, since this is not a typical kind of
15599 -- representation in the VM context anyway (and would not
15600 -- for example work nicely with the debugger).
15601
15602 elsif VM_Target /= No_VM then
15603 if not GNAT_Mode then
15604 Error_Pragma
15605 ("??pragma% ignored in this configuration");
15606 end if;
15607
15608 -- Normal case where we do the pack action
15609
15610 else
15611 if not Ignore then
15612 Set_Is_Packed (Base_Type (Typ));
15613 Set_Has_Non_Standard_Rep (Base_Type (Typ));
15614 end if;
15615
15616 Set_Has_Pragma_Pack (Base_Type (Typ));
15617 end if;
15618 end if;
15619
15620 -- For record types, the pack is always effective
15621
15622 else pragma Assert (Is_Record_Type (Typ));
15623 if not Rep_Item_Too_Late (Typ, N) then
15624
15625 -- Ignore pack request with warning in VM mode (skip warning
15626 -- if we are compiling GNAT run time library).
15627
15628 if VM_Target /= No_VM then
15629 if not GNAT_Mode then
15630 Error_Pragma
15631 ("??pragma% ignored in this configuration");
15632 end if;
15633
15634 -- Normal case of pack request active
15635
15636 else
15637 Set_Is_Packed (Base_Type (Typ));
15638 Set_Has_Pragma_Pack (Base_Type (Typ));
15639 Set_Has_Non_Standard_Rep (Base_Type (Typ));
15640 end if;
15641 end if;
15642 end if;
15643 end Pack;
15644
15645 ----------
15646 -- Page --
15647 ----------
15648
15649 -- pragma Page;
15650
15651 -- There is nothing to do here, since we did all the processing for
15652 -- this pragma in Par.Prag (so that it works properly even in syntax
15653 -- only mode).
15654
15655 when Pragma_Page =>
15656 null;
15657
15658 ----------------------------------
15659 -- Partition_Elaboration_Policy --
15660 ----------------------------------
15661
15662 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
15663
15664 when Pragma_Partition_Elaboration_Policy => declare
15665 subtype PEP_Range is Name_Id
15666 range First_Partition_Elaboration_Policy_Name
15667 .. Last_Partition_Elaboration_Policy_Name;
15668 PEP_Val : PEP_Range;
15669 PEP : Character;
15670
15671 begin
15672 Ada_2005_Pragma;
15673 Check_Arg_Count (1);
15674 Check_No_Identifiers;
15675 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
15676 Check_Valid_Configuration_Pragma;
15677 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
15678
15679 case PEP_Val is
15680 when Name_Concurrent =>
15681 PEP := 'C';
15682 when Name_Sequential =>
15683 PEP := 'S';
15684 end case;
15685
15686 if Partition_Elaboration_Policy /= ' '
15687 and then Partition_Elaboration_Policy /= PEP
15688 then
15689 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
15690 Error_Pragma
15691 ("partition elaboration policy incompatible with policy#");
15692
15693 -- Set new policy, but always preserve System_Location since we
15694 -- like the error message with the run time name.
15695
15696 else
15697 Partition_Elaboration_Policy := PEP;
15698
15699 if Partition_Elaboration_Policy_Sloc /= System_Location then
15700 Partition_Elaboration_Policy_Sloc := Loc;
15701 end if;
15702 end if;
15703 end;
15704
15705 -------------
15706 -- Passive --
15707 -------------
15708
15709 -- pragma Passive [(PASSIVE_FORM)];
15710
15711 -- PASSIVE_FORM ::= Semaphore | No
15712
15713 when Pragma_Passive =>
15714 GNAT_Pragma;
15715
15716 if Nkind (Parent (N)) /= N_Task_Definition then
15717 Error_Pragma ("pragma% must be within task definition");
15718 end if;
15719
15720 if Arg_Count /= 0 then
15721 Check_Arg_Count (1);
15722 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
15723 end if;
15724
15725 ----------------------------------
15726 -- Preelaborable_Initialization --
15727 ----------------------------------
15728
15729 -- pragma Preelaborable_Initialization (DIRECT_NAME);
15730
15731 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
15732 Ent : Entity_Id;
15733
15734 begin
15735 Ada_2005_Pragma;
15736 Check_Arg_Count (1);
15737 Check_No_Identifiers;
15738 Check_Arg_Is_Identifier (Arg1);
15739 Check_Arg_Is_Local_Name (Arg1);
15740 Check_First_Subtype (Arg1);
15741 Ent := Entity (Get_Pragma_Arg (Arg1));
15742
15743 -- The pragma may come from an aspect on a private declaration,
15744 -- even if the freeze point at which this is analyzed in the
15745 -- private part after the full view.
15746
15747 if Has_Private_Declaration (Ent)
15748 and then From_Aspect_Specification (N)
15749 then
15750 null;
15751
15752 elsif Is_Private_Type (Ent)
15753 or else Is_Protected_Type (Ent)
15754 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
15755 then
15756 null;
15757
15758 else
15759 Error_Pragma_Arg
15760 ("pragma % can only be applied to private, formal derived or "
15761 & "protected type",
15762 Arg1);
15763 end if;
15764
15765 -- Give an error if the pragma is applied to a protected type that
15766 -- does not qualify (due to having entries, or due to components
15767 -- that do not qualify).
15768
15769 if Is_Protected_Type (Ent)
15770 and then not Has_Preelaborable_Initialization (Ent)
15771 then
15772 Error_Msg_N
15773 ("protected type & does not have preelaborable "
15774 & "initialization", Ent);
15775
15776 -- Otherwise mark the type as definitely having preelaborable
15777 -- initialization.
15778
15779 else
15780 Set_Known_To_Have_Preelab_Init (Ent);
15781 end if;
15782
15783 if Has_Pragma_Preelab_Init (Ent)
15784 and then Warn_On_Redundant_Constructs
15785 then
15786 Error_Pragma ("?r?duplicate pragma%!");
15787 else
15788 Set_Has_Pragma_Preelab_Init (Ent);
15789 end if;
15790 end Preelab_Init;
15791
15792 --------------------
15793 -- Persistent_BSS --
15794 --------------------
15795
15796 -- pragma Persistent_BSS [(object_NAME)];
15797
15798 when Pragma_Persistent_BSS => Persistent_BSS : declare
15799 Decl : Node_Id;
15800 Ent : Entity_Id;
15801 Prag : Node_Id;
15802
15803 begin
15804 GNAT_Pragma;
15805 Check_At_Most_N_Arguments (1);
15806
15807 -- Case of application to specific object (one argument)
15808
15809 if Arg_Count = 1 then
15810 Check_Arg_Is_Library_Level_Local_Name (Arg1);
15811
15812 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
15813 or else not
15814 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
15815 E_Constant)
15816 then
15817 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
15818 end if;
15819
15820 Ent := Entity (Get_Pragma_Arg (Arg1));
15821 Decl := Parent (Ent);
15822
15823 -- Check for duplication before inserting in list of
15824 -- representation items.
15825
15826 Check_Duplicate_Pragma (Ent);
15827
15828 if Rep_Item_Too_Late (Ent, N) then
15829 return;
15830 end if;
15831
15832 if Present (Expression (Decl)) then
15833 Error_Pragma_Arg
15834 ("object for pragma% cannot have initialization", Arg1);
15835 end if;
15836
15837 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
15838 Error_Pragma_Arg
15839 ("object type for pragma% is not potentially persistent",
15840 Arg1);
15841 end if;
15842
15843 Prag :=
15844 Make_Linker_Section_Pragma
15845 (Ent, Sloc (N), ".persistent.bss");
15846 Insert_After (N, Prag);
15847 Analyze (Prag);
15848
15849 -- Case of use as configuration pragma with no arguments
15850
15851 else
15852 Check_Valid_Configuration_Pragma;
15853 Persistent_BSS_Mode := True;
15854 end if;
15855 end Persistent_BSS;
15856
15857 -------------
15858 -- Polling --
15859 -------------
15860
15861 -- pragma Polling (ON | OFF);
15862
15863 when Pragma_Polling =>
15864 GNAT_Pragma;
15865 Check_Arg_Count (1);
15866 Check_No_Identifiers;
15867 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
15868 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
15869
15870 ------------------
15871 -- Post[_Class] --
15872 ------------------
15873
15874 -- pragma Post (Boolean_EXPRESSION);
15875 -- pragma Post_Class (Boolean_EXPRESSION);
15876
15877 when Pragma_Post | Pragma_Post_Class => Post : declare
15878 PC_Pragma : Node_Id;
15879
15880 begin
15881 GNAT_Pragma;
15882 Check_Arg_Count (1);
15883 Check_No_Identifiers;
15884 Check_Pre_Post;
15885
15886 -- Rewrite Post[_Class] pragma as Precondition pragma setting the
15887 -- flag Class_Present to True for the Post_Class case.
15888
15889 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
15890 PC_Pragma := New_Copy (N);
15891 Set_Pragma_Identifier
15892 (PC_Pragma, Make_Identifier (Loc, Name_Postcondition));
15893 Rewrite (N, PC_Pragma);
15894 Set_Analyzed (N, False);
15895 Analyze (N);
15896 end Post;
15897
15898 -------------------
15899 -- Postcondition --
15900 -------------------
15901
15902 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
15903 -- [,[Message =>] String_EXPRESSION]);
15904
15905 when Pragma_Postcondition => Postcondition : declare
15906 In_Body : Boolean;
15907
15908 begin
15909 GNAT_Pragma;
15910 Check_At_Least_N_Arguments (1);
15911 Check_At_Most_N_Arguments (2);
15912 Check_Optional_Identifier (Arg1, Name_Check);
15913
15914 -- Verify the proper placement of the pragma. The remainder of the
15915 -- processing is found in Sem_Ch6/Sem_Ch7.
15916
15917 Check_Precondition_Postcondition (In_Body);
15918
15919 -- When the pragma is a source construct appearing inside a body,
15920 -- preanalyze the boolean_expression to detect illegal forward
15921 -- references:
15922
15923 -- procedure P is
15924 -- pragma Postcondition (X'Old ...);
15925 -- X : ...
15926
15927 if Comes_From_Source (N) and then In_Body then
15928 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
15929 end if;
15930 end Postcondition;
15931
15932 -----------------
15933 -- Pre[_Class] --
15934 -----------------
15935
15936 -- pragma Pre (Boolean_EXPRESSION);
15937 -- pragma Pre_Class (Boolean_EXPRESSION);
15938
15939 when Pragma_Pre | Pragma_Pre_Class => Pre : declare
15940 PC_Pragma : Node_Id;
15941
15942 begin
15943 GNAT_Pragma;
15944 Check_Arg_Count (1);
15945 Check_No_Identifiers;
15946 Check_Pre_Post;
15947
15948 -- Rewrite Pre[_Class] pragma as Precondition pragma setting the
15949 -- flag Class_Present to True for the Pre_Class case.
15950
15951 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
15952 PC_Pragma := New_Copy (N);
15953 Set_Pragma_Identifier
15954 (PC_Pragma, Make_Identifier (Loc, Name_Precondition));
15955 Rewrite (N, PC_Pragma);
15956 Set_Analyzed (N, False);
15957 Analyze (N);
15958 end Pre;
15959
15960 ------------------
15961 -- Precondition --
15962 ------------------
15963
15964 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
15965 -- [,[Message =>] String_EXPRESSION]);
15966
15967 when Pragma_Precondition => Precondition : declare
15968 In_Body : Boolean;
15969
15970 begin
15971 GNAT_Pragma;
15972 Check_At_Least_N_Arguments (1);
15973 Check_At_Most_N_Arguments (2);
15974 Check_Optional_Identifier (Arg1, Name_Check);
15975 Check_Precondition_Postcondition (In_Body);
15976
15977 -- If in spec, nothing more to do. If in body, then we convert
15978 -- the pragma to an equivalent pragma Check. That works fine since
15979 -- pragma Check will analyze the condition in the proper context.
15980
15981 -- The form of the pragma Check is either:
15982
15983 -- pragma Check (Precondition, cond [, msg])
15984 -- or
15985 -- pragma Check (Pre, cond [, msg])
15986
15987 -- We use the Pre form if this pragma derived from a Pre aspect.
15988 -- This is needed to make sure that the right set of Policy
15989 -- pragmas are checked.
15990
15991 if In_Body then
15992
15993 -- Rewrite as Check pragma
15994
15995 Rewrite (N,
15996 Make_Pragma (Loc,
15997 Chars => Name_Check,
15998 Pragma_Argument_Associations => New_List (
15999 Make_Pragma_Argument_Association (Loc,
16000 Expression => Make_Identifier (Loc, Pname)),
16001
16002 Make_Pragma_Argument_Association (Sloc (Arg1),
16003 Expression =>
16004 Relocate_Node (Get_Pragma_Arg (Arg1))))));
16005
16006 if Arg_Count = 2 then
16007 Append_To (Pragma_Argument_Associations (N),
16008 Make_Pragma_Argument_Association (Sloc (Arg2),
16009 Expression =>
16010 Relocate_Node (Get_Pragma_Arg (Arg2))));
16011 end if;
16012
16013 Analyze (N);
16014 end if;
16015 end Precondition;
16016
16017 ---------------
16018 -- Predicate --
16019 ---------------
16020
16021 -- pragma Predicate
16022 -- ([Entity =>] type_LOCAL_NAME,
16023 -- [Check =>] boolean_EXPRESSION);
16024
16025 when Pragma_Predicate => Predicate : declare
16026 Type_Id : Node_Id;
16027 Typ : Entity_Id;
16028
16029 Discard : Boolean;
16030 pragma Unreferenced (Discard);
16031
16032 begin
16033 GNAT_Pragma;
16034 Check_Arg_Count (2);
16035 Check_Optional_Identifier (Arg1, Name_Entity);
16036 Check_Optional_Identifier (Arg2, Name_Check);
16037
16038 Check_Arg_Is_Local_Name (Arg1);
16039
16040 Type_Id := Get_Pragma_Arg (Arg1);
16041 Find_Type (Type_Id);
16042 Typ := Entity (Type_Id);
16043
16044 if Typ = Any_Type then
16045 return;
16046 end if;
16047
16048 -- The remaining processing is simply to link the pragma on to
16049 -- the rep item chain, for processing when the type is frozen.
16050 -- This is accomplished by a call to Rep_Item_Too_Late. We also
16051 -- mark the type as having predicates.
16052
16053 Set_Has_Predicates (Typ);
16054 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
16055 end Predicate;
16056
16057 ------------------
16058 -- Preelaborate --
16059 ------------------
16060
16061 -- pragma Preelaborate [(library_unit_NAME)];
16062
16063 -- Set the flag Is_Preelaborated of program unit name entity
16064
16065 when Pragma_Preelaborate => Preelaborate : declare
16066 Pa : constant Node_Id := Parent (N);
16067 Pk : constant Node_Kind := Nkind (Pa);
16068 Ent : Entity_Id;
16069
16070 begin
16071 Check_Ada_83_Warning;
16072 Check_Valid_Library_Unit_Pragma;
16073
16074 if Nkind (N) = N_Null_Statement then
16075 return;
16076 end if;
16077
16078 Ent := Find_Lib_Unit_Name;
16079 Check_Duplicate_Pragma (Ent);
16080
16081 -- This filters out pragmas inside generic parents that show up
16082 -- inside instantiations. Pragmas that come from aspects in the
16083 -- unit are not ignored.
16084
16085 if Present (Ent) then
16086 if Pk = N_Package_Specification
16087 and then Present (Generic_Parent (Pa))
16088 and then not From_Aspect_Specification (N)
16089 then
16090 null;
16091
16092 else
16093 if not Debug_Flag_U then
16094 Set_Is_Preelaborated (Ent);
16095 Set_Suppress_Elaboration_Warnings (Ent);
16096 end if;
16097 end if;
16098 end if;
16099 end Preelaborate;
16100
16101 ---------------------
16102 -- Preelaborate_05 --
16103 ---------------------
16104
16105 -- pragma Preelaborate_05 [(library_unit_NAME)];
16106
16107 -- This pragma is useable only in GNAT_Mode, where it is used like
16108 -- pragma Preelaborate but it is only effective in Ada 2005 mode
16109 -- (otherwise it is ignored). This is used to implement AI-362 which
16110 -- recategorizes some run-time packages in Ada 2005 mode.
16111
16112 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
16113 Ent : Entity_Id;
16114
16115 begin
16116 GNAT_Pragma;
16117 Check_Valid_Library_Unit_Pragma;
16118
16119 if not GNAT_Mode then
16120 Error_Pragma ("pragma% only available in GNAT mode");
16121 end if;
16122
16123 if Nkind (N) = N_Null_Statement then
16124 return;
16125 end if;
16126
16127 -- This is one of the few cases where we need to test the value of
16128 -- Ada_Version_Explicit rather than Ada_Version (which is always
16129 -- set to Ada_2012 in a predefined unit), we need to know the
16130 -- explicit version set to know if this pragma is active.
16131
16132 if Ada_Version_Explicit >= Ada_2005 then
16133 Ent := Find_Lib_Unit_Name;
16134 Set_Is_Preelaborated (Ent);
16135 Set_Suppress_Elaboration_Warnings (Ent);
16136 end if;
16137 end Preelaborate_05;
16138
16139 --------------
16140 -- Priority --
16141 --------------
16142
16143 -- pragma Priority (EXPRESSION);
16144
16145 when Pragma_Priority => Priority : declare
16146 P : constant Node_Id := Parent (N);
16147 Arg : Node_Id;
16148 Ent : Entity_Id;
16149
16150 begin
16151 Check_No_Identifiers;
16152 Check_Arg_Count (1);
16153
16154 -- Subprogram case
16155
16156 if Nkind (P) = N_Subprogram_Body then
16157 Check_In_Main_Program;
16158
16159 Ent := Defining_Unit_Name (Specification (P));
16160
16161 if Nkind (Ent) = N_Defining_Program_Unit_Name then
16162 Ent := Defining_Identifier (Ent);
16163 end if;
16164
16165 Arg := Get_Pragma_Arg (Arg1);
16166 Analyze_And_Resolve (Arg, Standard_Integer);
16167
16168 -- Must be static
16169
16170 if not Is_Static_Expression (Arg) then
16171 Flag_Non_Static_Expr
16172 ("main subprogram priority is not static!", Arg);
16173 raise Pragma_Exit;
16174
16175 -- If constraint error, then we already signalled an error
16176
16177 elsif Raises_Constraint_Error (Arg) then
16178 null;
16179
16180 -- Otherwise check in range
16181
16182 else
16183 declare
16184 Val : constant Uint := Expr_Value (Arg);
16185
16186 begin
16187 if Val < 0
16188 or else Val > Expr_Value (Expression
16189 (Parent (RTE (RE_Max_Priority))))
16190 then
16191 Error_Pragma_Arg
16192 ("main subprogram priority is out of range", Arg1);
16193 end if;
16194 end;
16195 end if;
16196
16197 Set_Main_Priority
16198 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
16199
16200 -- Load an arbitrary entity from System.Tasking.Stages or
16201 -- System.Tasking.Restricted.Stages (depending on the
16202 -- supported profile) to make sure that one of these packages
16203 -- is implicitly with'ed, since we need to have the tasking
16204 -- run time active for the pragma Priority to have any effect.
16205 -- Previously with with'ed the package System.Tasking, but
16206 -- this package does not trigger the required initialization
16207 -- of the run-time library.
16208
16209 declare
16210 Discard : Entity_Id;
16211 pragma Warnings (Off, Discard);
16212 begin
16213 if Restricted_Profile then
16214 Discard := RTE (RE_Activate_Restricted_Tasks);
16215 else
16216 Discard := RTE (RE_Activate_Tasks);
16217 end if;
16218 end;
16219
16220 -- Task or Protected, must be of type Integer
16221
16222 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
16223 Arg := Get_Pragma_Arg (Arg1);
16224 Ent := Defining_Identifier (Parent (P));
16225
16226 -- The expression must be analyzed in the special manner
16227 -- described in "Handling of Default and Per-Object
16228 -- Expressions" in sem.ads.
16229
16230 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
16231
16232 if not Is_Static_Expression (Arg) then
16233 Check_Restriction (Static_Priorities, Arg);
16234 end if;
16235
16236 -- Anything else is incorrect
16237
16238 else
16239 Pragma_Misplaced;
16240 end if;
16241
16242 -- Check duplicate pragma before we chain the pragma in the Rep
16243 -- Item chain of Ent.
16244
16245 Check_Duplicate_Pragma (Ent);
16246 Record_Rep_Item (Ent, N);
16247 end Priority;
16248
16249 -----------------------------------
16250 -- Priority_Specific_Dispatching --
16251 -----------------------------------
16252
16253 -- pragma Priority_Specific_Dispatching (
16254 -- policy_IDENTIFIER,
16255 -- first_priority_EXPRESSION,
16256 -- last_priority_EXPRESSION);
16257
16258 when Pragma_Priority_Specific_Dispatching =>
16259 Priority_Specific_Dispatching : declare
16260 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
16261 -- This is the entity System.Any_Priority;
16262
16263 DP : Character;
16264 Lower_Bound : Node_Id;
16265 Upper_Bound : Node_Id;
16266 Lower_Val : Uint;
16267 Upper_Val : Uint;
16268
16269 begin
16270 Ada_2005_Pragma;
16271 Check_Arg_Count (3);
16272 Check_No_Identifiers;
16273 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16274 Check_Valid_Configuration_Pragma;
16275 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16276 DP := Fold_Upper (Name_Buffer (1));
16277
16278 Lower_Bound := Get_Pragma_Arg (Arg2);
16279 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
16280 Lower_Val := Expr_Value (Lower_Bound);
16281
16282 Upper_Bound := Get_Pragma_Arg (Arg3);
16283 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
16284 Upper_Val := Expr_Value (Upper_Bound);
16285
16286 -- It is not allowed to use Task_Dispatching_Policy and
16287 -- Priority_Specific_Dispatching in the same partition.
16288
16289 if Task_Dispatching_Policy /= ' ' then
16290 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16291 Error_Pragma
16292 ("pragma% incompatible with Task_Dispatching_Policy#");
16293
16294 -- Check lower bound in range
16295
16296 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
16297 or else
16298 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
16299 then
16300 Error_Pragma_Arg
16301 ("first_priority is out of range", Arg2);
16302
16303 -- Check upper bound in range
16304
16305 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
16306 or else
16307 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
16308 then
16309 Error_Pragma_Arg
16310 ("last_priority is out of range", Arg3);
16311
16312 -- Check that the priority range is valid
16313
16314 elsif Lower_Val > Upper_Val then
16315 Error_Pragma
16316 ("last_priority_expression must be greater than or equal to "
16317 & "first_priority_expression");
16318
16319 -- Store the new policy, but always preserve System_Location since
16320 -- we like the error message with the run-time name.
16321
16322 else
16323 -- Check overlapping in the priority ranges specified in other
16324 -- Priority_Specific_Dispatching pragmas within the same
16325 -- partition. We can only check those we know about!
16326
16327 for J in
16328 Specific_Dispatching.First .. Specific_Dispatching.Last
16329 loop
16330 if Specific_Dispatching.Table (J).First_Priority in
16331 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
16332 or else Specific_Dispatching.Table (J).Last_Priority in
16333 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
16334 then
16335 Error_Msg_Sloc :=
16336 Specific_Dispatching.Table (J).Pragma_Loc;
16337 Error_Pragma
16338 ("priority range overlaps with "
16339 & "Priority_Specific_Dispatching#");
16340 end if;
16341 end loop;
16342
16343 -- The use of Priority_Specific_Dispatching is incompatible
16344 -- with Task_Dispatching_Policy.
16345
16346 if Task_Dispatching_Policy /= ' ' then
16347 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16348 Error_Pragma
16349 ("Priority_Specific_Dispatching incompatible "
16350 & "with Task_Dispatching_Policy#");
16351 end if;
16352
16353 -- The use of Priority_Specific_Dispatching forces ceiling
16354 -- locking policy.
16355
16356 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
16357 Error_Msg_Sloc := Locking_Policy_Sloc;
16358 Error_Pragma
16359 ("Priority_Specific_Dispatching incompatible "
16360 & "with Locking_Policy#");
16361
16362 -- Set the Ceiling_Locking policy, but preserve System_Location
16363 -- since we like the error message with the run time name.
16364
16365 else
16366 Locking_Policy := 'C';
16367
16368 if Locking_Policy_Sloc /= System_Location then
16369 Locking_Policy_Sloc := Loc;
16370 end if;
16371 end if;
16372
16373 -- Add entry in the table
16374
16375 Specific_Dispatching.Append
16376 ((Dispatching_Policy => DP,
16377 First_Priority => UI_To_Int (Lower_Val),
16378 Last_Priority => UI_To_Int (Upper_Val),
16379 Pragma_Loc => Loc));
16380 end if;
16381 end Priority_Specific_Dispatching;
16382
16383 -------------
16384 -- Profile --
16385 -------------
16386
16387 -- pragma Profile (profile_IDENTIFIER);
16388
16389 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
16390
16391 when Pragma_Profile =>
16392 Ada_2005_Pragma;
16393 Check_Arg_Count (1);
16394 Check_Valid_Configuration_Pragma;
16395 Check_No_Identifiers;
16396
16397 declare
16398 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
16399
16400 begin
16401 if Chars (Argx) = Name_Ravenscar then
16402 Set_Ravenscar_Profile (N);
16403
16404 elsif Chars (Argx) = Name_Restricted then
16405 Set_Profile_Restrictions
16406 (Restricted,
16407 N, Warn => Treat_Restrictions_As_Warnings);
16408
16409 elsif Chars (Argx) = Name_Rational then
16410 Set_Rational_Profile;
16411
16412 elsif Chars (Argx) = Name_No_Implementation_Extensions then
16413 Set_Profile_Restrictions
16414 (No_Implementation_Extensions,
16415 N, Warn => Treat_Restrictions_As_Warnings);
16416
16417 else
16418 Error_Pragma_Arg ("& is not a valid profile", Argx);
16419 end if;
16420 end;
16421
16422 ----------------------
16423 -- Profile_Warnings --
16424 ----------------------
16425
16426 -- pragma Profile_Warnings (profile_IDENTIFIER);
16427
16428 -- profile_IDENTIFIER => Restricted | Ravenscar
16429
16430 when Pragma_Profile_Warnings =>
16431 GNAT_Pragma;
16432 Check_Arg_Count (1);
16433 Check_Valid_Configuration_Pragma;
16434 Check_No_Identifiers;
16435
16436 declare
16437 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
16438
16439 begin
16440 if Chars (Argx) = Name_Ravenscar then
16441 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
16442
16443 elsif Chars (Argx) = Name_Restricted then
16444 Set_Profile_Restrictions (Restricted, N, Warn => True);
16445
16446 elsif Chars (Argx) = Name_No_Implementation_Extensions then
16447 Set_Profile_Restrictions
16448 (No_Implementation_Extensions, N, Warn => True);
16449
16450 else
16451 Error_Pragma_Arg ("& is not a valid profile", Argx);
16452 end if;
16453 end;
16454
16455 --------------------------
16456 -- Propagate_Exceptions --
16457 --------------------------
16458
16459 -- pragma Propagate_Exceptions;
16460
16461 -- Note: this pragma is obsolete and has no effect
16462
16463 when Pragma_Propagate_Exceptions =>
16464 GNAT_Pragma;
16465 Check_Arg_Count (0);
16466
16467 if Warn_On_Obsolescent_Feature then
16468 Error_Msg_N
16469 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
16470 "and has no effect?j?", N);
16471 end if;
16472
16473 ------------------
16474 -- Psect_Object --
16475 ------------------
16476
16477 -- pragma Psect_Object (
16478 -- [Internal =>] LOCAL_NAME,
16479 -- [, [External =>] EXTERNAL_SYMBOL]
16480 -- [, [Size =>] EXTERNAL_SYMBOL]);
16481
16482 when Pragma_Psect_Object | Pragma_Common_Object =>
16483 Psect_Object : declare
16484 Args : Args_List (1 .. 3);
16485 Names : constant Name_List (1 .. 3) := (
16486 Name_Internal,
16487 Name_External,
16488 Name_Size);
16489
16490 Internal : Node_Id renames Args (1);
16491 External : Node_Id renames Args (2);
16492 Size : Node_Id renames Args (3);
16493
16494 Def_Id : Entity_Id;
16495
16496 procedure Check_Too_Long (Arg : Node_Id);
16497 -- Posts message if the argument is an identifier with more
16498 -- than 31 characters, or a string literal with more than
16499 -- 31 characters, and we are operating under VMS
16500
16501 --------------------
16502 -- Check_Too_Long --
16503 --------------------
16504
16505 procedure Check_Too_Long (Arg : Node_Id) is
16506 X : constant Node_Id := Original_Node (Arg);
16507
16508 begin
16509 if not Nkind_In (X, N_String_Literal, N_Identifier) then
16510 Error_Pragma_Arg
16511 ("inappropriate argument for pragma %", Arg);
16512 end if;
16513
16514 if OpenVMS_On_Target then
16515 if (Nkind (X) = N_String_Literal
16516 and then String_Length (Strval (X)) > 31)
16517 or else
16518 (Nkind (X) = N_Identifier
16519 and then Length_Of_Name (Chars (X)) > 31)
16520 then
16521 Error_Pragma_Arg
16522 ("argument for pragma % is longer than 31 characters",
16523 Arg);
16524 end if;
16525 end if;
16526 end Check_Too_Long;
16527
16528 -- Start of processing for Common_Object/Psect_Object
16529
16530 begin
16531 GNAT_Pragma;
16532 Gather_Associations (Names, Args);
16533 Process_Extended_Import_Export_Internal_Arg (Internal);
16534
16535 Def_Id := Entity (Internal);
16536
16537 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
16538 Error_Pragma_Arg
16539 ("pragma% must designate an object", Internal);
16540 end if;
16541
16542 Check_Too_Long (Internal);
16543
16544 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
16545 Error_Pragma_Arg
16546 ("cannot use pragma% for imported/exported object",
16547 Internal);
16548 end if;
16549
16550 if Is_Concurrent_Type (Etype (Internal)) then
16551 Error_Pragma_Arg
16552 ("cannot specify pragma % for task/protected object",
16553 Internal);
16554 end if;
16555
16556 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
16557 or else
16558 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
16559 then
16560 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
16561 end if;
16562
16563 if Ekind (Def_Id) = E_Constant then
16564 Error_Pragma_Arg
16565 ("cannot specify pragma % for a constant", Internal);
16566 end if;
16567
16568 if Is_Record_Type (Etype (Internal)) then
16569 declare
16570 Ent : Entity_Id;
16571 Decl : Entity_Id;
16572
16573 begin
16574 Ent := First_Entity (Etype (Internal));
16575 while Present (Ent) loop
16576 Decl := Declaration_Node (Ent);
16577
16578 if Ekind (Ent) = E_Component
16579 and then Nkind (Decl) = N_Component_Declaration
16580 and then Present (Expression (Decl))
16581 and then Warn_On_Export_Import
16582 then
16583 Error_Msg_N
16584 ("?x?object for pragma % has defaults", Internal);
16585 exit;
16586
16587 else
16588 Next_Entity (Ent);
16589 end if;
16590 end loop;
16591 end;
16592 end if;
16593
16594 if Present (Size) then
16595 Check_Too_Long (Size);
16596 end if;
16597
16598 if Present (External) then
16599 Check_Arg_Is_External_Name (External);
16600 Check_Too_Long (External);
16601 end if;
16602
16603 -- If all error tests pass, link pragma on to the rep item chain
16604
16605 Record_Rep_Item (Def_Id, N);
16606 end Psect_Object;
16607
16608 ----------
16609 -- Pure --
16610 ----------
16611
16612 -- pragma Pure [(library_unit_NAME)];
16613
16614 when Pragma_Pure => Pure : declare
16615 Ent : Entity_Id;
16616
16617 begin
16618 Check_Ada_83_Warning;
16619 Check_Valid_Library_Unit_Pragma;
16620
16621 if Nkind (N) = N_Null_Statement then
16622 return;
16623 end if;
16624
16625 Ent := Find_Lib_Unit_Name;
16626 Set_Is_Pure (Ent);
16627 Set_Has_Pragma_Pure (Ent);
16628 Set_Suppress_Elaboration_Warnings (Ent);
16629 end Pure;
16630
16631 -------------
16632 -- Pure_05 --
16633 -------------
16634
16635 -- pragma Pure_05 [(library_unit_NAME)];
16636
16637 -- This pragma is useable only in GNAT_Mode, where it is used like
16638 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
16639 -- it is ignored). It may be used after a pragma Preelaborate, in
16640 -- which case it overrides the effect of the pragma Preelaborate.
16641 -- This is used to implement AI-362 which recategorizes some run-time
16642 -- packages in Ada 2005 mode.
16643
16644 when Pragma_Pure_05 => Pure_05 : declare
16645 Ent : Entity_Id;
16646
16647 begin
16648 GNAT_Pragma;
16649 Check_Valid_Library_Unit_Pragma;
16650
16651 if not GNAT_Mode then
16652 Error_Pragma ("pragma% only available in GNAT mode");
16653 end if;
16654
16655 if Nkind (N) = N_Null_Statement then
16656 return;
16657 end if;
16658
16659 -- This is one of the few cases where we need to test the value of
16660 -- Ada_Version_Explicit rather than Ada_Version (which is always
16661 -- set to Ada_2012 in a predefined unit), we need to know the
16662 -- explicit version set to know if this pragma is active.
16663
16664 if Ada_Version_Explicit >= Ada_2005 then
16665 Ent := Find_Lib_Unit_Name;
16666 Set_Is_Preelaborated (Ent, False);
16667 Set_Is_Pure (Ent);
16668 Set_Suppress_Elaboration_Warnings (Ent);
16669 end if;
16670 end Pure_05;
16671
16672 -------------
16673 -- Pure_12 --
16674 -------------
16675
16676 -- pragma Pure_12 [(library_unit_NAME)];
16677
16678 -- This pragma is useable only in GNAT_Mode, where it is used like
16679 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
16680 -- it is ignored). It may be used after a pragma Preelaborate, in
16681 -- which case it overrides the effect of the pragma Preelaborate.
16682 -- This is used to implement AI05-0212 which recategorizes some
16683 -- run-time packages in Ada 2012 mode.
16684
16685 when Pragma_Pure_12 => Pure_12 : declare
16686 Ent : Entity_Id;
16687
16688 begin
16689 GNAT_Pragma;
16690 Check_Valid_Library_Unit_Pragma;
16691
16692 if not GNAT_Mode then
16693 Error_Pragma ("pragma% only available in GNAT mode");
16694 end if;
16695
16696 if Nkind (N) = N_Null_Statement then
16697 return;
16698 end if;
16699
16700 -- This is one of the few cases where we need to test the value of
16701 -- Ada_Version_Explicit rather than Ada_Version (which is always
16702 -- set to Ada_2012 in a predefined unit), we need to know the
16703 -- explicit version set to know if this pragma is active.
16704
16705 if Ada_Version_Explicit >= Ada_2012 then
16706 Ent := Find_Lib_Unit_Name;
16707 Set_Is_Preelaborated (Ent, False);
16708 Set_Is_Pure (Ent);
16709 Set_Suppress_Elaboration_Warnings (Ent);
16710 end if;
16711 end Pure_12;
16712
16713 -------------------
16714 -- Pure_Function --
16715 -------------------
16716
16717 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
16718
16719 when Pragma_Pure_Function => Pure_Function : declare
16720 E_Id : Node_Id;
16721 E : Entity_Id;
16722 Def_Id : Entity_Id;
16723 Effective : Boolean := False;
16724
16725 begin
16726 GNAT_Pragma;
16727 Check_Arg_Count (1);
16728 Check_Optional_Identifier (Arg1, Name_Entity);
16729 Check_Arg_Is_Local_Name (Arg1);
16730 E_Id := Get_Pragma_Arg (Arg1);
16731
16732 if Error_Posted (E_Id) then
16733 return;
16734 end if;
16735
16736 -- Loop through homonyms (overloadings) of referenced entity
16737
16738 E := Entity (E_Id);
16739
16740 if Present (E) then
16741 loop
16742 Def_Id := Get_Base_Subprogram (E);
16743
16744 if not Ekind_In (Def_Id, E_Function,
16745 E_Generic_Function,
16746 E_Operator)
16747 then
16748 Error_Pragma_Arg
16749 ("pragma% requires a function name", Arg1);
16750 end if;
16751
16752 Set_Is_Pure (Def_Id);
16753
16754 if not Has_Pragma_Pure_Function (Def_Id) then
16755 Set_Has_Pragma_Pure_Function (Def_Id);
16756 Effective := True;
16757 end if;
16758
16759 exit when From_Aspect_Specification (N);
16760 E := Homonym (E);
16761 exit when No (E) or else Scope (E) /= Current_Scope;
16762 end loop;
16763
16764 if not Effective
16765 and then Warn_On_Redundant_Constructs
16766 then
16767 Error_Msg_NE
16768 ("pragma Pure_Function on& is redundant?r?",
16769 N, Entity (E_Id));
16770 end if;
16771 end if;
16772 end Pure_Function;
16773
16774 --------------------
16775 -- Queuing_Policy --
16776 --------------------
16777
16778 -- pragma Queuing_Policy (policy_IDENTIFIER);
16779
16780 when Pragma_Queuing_Policy => declare
16781 QP : Character;
16782
16783 begin
16784 Check_Ada_83_Warning;
16785 Check_Arg_Count (1);
16786 Check_No_Identifiers;
16787 Check_Arg_Is_Queuing_Policy (Arg1);
16788 Check_Valid_Configuration_Pragma;
16789 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16790 QP := Fold_Upper (Name_Buffer (1));
16791
16792 if Queuing_Policy /= ' '
16793 and then Queuing_Policy /= QP
16794 then
16795 Error_Msg_Sloc := Queuing_Policy_Sloc;
16796 Error_Pragma ("queuing policy incompatible with policy#");
16797
16798 -- Set new policy, but always preserve System_Location since we
16799 -- like the error message with the run time name.
16800
16801 else
16802 Queuing_Policy := QP;
16803
16804 if Queuing_Policy_Sloc /= System_Location then
16805 Queuing_Policy_Sloc := Loc;
16806 end if;
16807 end if;
16808 end;
16809
16810 --------------
16811 -- Rational --
16812 --------------
16813
16814 -- pragma Rational, for compatibility with foreign compiler
16815
16816 when Pragma_Rational =>
16817 Set_Rational_Profile;
16818
16819 ------------------------------------
16820 -- Refined_Depends/Refined_Global --
16821 ------------------------------------
16822
16823 -- pragma Refined_Depends (DEPENDENCY_RELATION);
16824
16825 -- DEPENDENCY_RELATION ::=
16826 -- null
16827 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
16828
16829 -- DEPENDENCY_CLAUSE ::=
16830 -- OUTPUT_LIST =>[+] INPUT_LIST
16831 -- | NULL_DEPENDENCY_CLAUSE
16832
16833 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
16834
16835 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
16836
16837 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
16838
16839 -- OUTPUT ::= NAME | FUNCTION_RESULT
16840 -- INPUT ::= NAME
16841
16842 -- where FUNCTION_RESULT is a function Result attribute_reference
16843
16844 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
16845
16846 -- GLOBAL_SPECIFICATION ::=
16847 -- null
16848 -- | GLOBAL_LIST
16849 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
16850
16851 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16852
16853 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16854 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16855 -- GLOBAL_ITEM ::= NAME
16856
16857 when Pragma_Refined_Depends |
16858 Pragma_Refined_Global => Refined_Depends_Global :
16859 declare
16860 Body_Id : Entity_Id;
16861 Legal : Boolean;
16862 Spec_Id : Entity_Id;
16863
16864 begin
16865 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
16866
16867 -- Save the pragma in the contract of the subprogram body. The
16868 -- remaining analysis is performed at the end of the enclosing
16869 -- declarations.
16870
16871 if Legal then
16872 Add_Contract_Item (N, Body_Id);
16873 end if;
16874 end Refined_Depends_Global;
16875
16876 ------------------------------
16877 -- Refined_Post/Refined_Pre --
16878 ------------------------------
16879
16880 -- pragma Refined_Post (boolean_EXPRESSION);
16881 -- pragma Refined_Pre (boolean_EXPRESSION);
16882
16883 when Pragma_Refined_Post |
16884 Pragma_Refined_Pre => Refined_Pre_Post :
16885 declare
16886 Body_Id : Entity_Id;
16887 Legal : Boolean;
16888 Spec_Id : Entity_Id;
16889
16890 begin
16891 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
16892
16893 -- Analyze the boolean expression as a "spec expression"
16894
16895 if Legal then
16896 Analyze_Pre_Post_Condition_In_Decl_Part (N, Spec_Id);
16897 end if;
16898 end Refined_Pre_Post;
16899
16900 -------------------
16901 -- Refined_State --
16902 -------------------
16903
16904 -- pragma Refined_State (REFINEMENT_LIST);
16905
16906 -- REFINEMENT_LIST ::=
16907 -- REFINEMENT_CLAUSE
16908 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
16909
16910 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
16911
16912 -- CONSTITUENT_LIST ::=
16913 -- null
16914 -- | CONSTITUENT
16915 -- | (CONSTITUENT {, CONSTITUENT})
16916
16917 -- CONSTITUENT ::= object_NAME | state_NAME
16918
16919 when Pragma_Refined_State => Refined_State : declare
16920 Context : constant Node_Id := Parent (N);
16921 Spec_Id : Entity_Id;
16922 Stmt : Node_Id;
16923
16924 begin
16925 GNAT_Pragma;
16926 S14_Pragma;
16927 Check_Arg_Count (1);
16928
16929 -- Ensure the proper placement of the pragma. Refined states must
16930 -- be associated with a package body.
16931
16932 if Nkind (Context) /= N_Package_Body then
16933 Pragma_Misplaced;
16934 return;
16935 end if;
16936
16937 Stmt := Prev (N);
16938 while Present (Stmt) loop
16939
16940 -- Skip prior pragmas, but check for duplicates
16941
16942 if Nkind (Stmt) = N_Pragma then
16943 if Pragma_Name (Stmt) = Pname then
16944 Error_Msg_Name_1 := Pname;
16945 Error_Msg_Sloc := Sloc (Stmt);
16946 Error_Msg_N ("pragma % duplicates pragma declared #", N);
16947 end if;
16948
16949 -- Skip internally generated code
16950
16951 elsif not Comes_From_Source (Stmt) then
16952 null;
16953
16954 -- The pragma does not apply to a legal construct, issue an
16955 -- error and stop the analysis.
16956
16957 else
16958 Pragma_Misplaced;
16959 return;
16960 end if;
16961
16962 Stmt := Prev (Stmt);
16963 end loop;
16964
16965 -- State refinement is allowed only when the corresponding package
16966 -- declaration has a non-null pragma Abstract_State.
16967
16968 Spec_Id := Corresponding_Spec (Context);
16969
16970 if No (Abstract_States (Spec_Id))
16971 or else Has_Null_Abstract_State (Spec_Id)
16972 then
16973 Error_Msg_NE
16974 ("useless refinement, package & does not define abstract "
16975 & "states", N, Spec_Id);
16976 return;
16977 end if;
16978
16979 -- The pragma must be analyzed at the end of the declarations as
16980 -- it has visibility over the whole declarative region. Save the
16981 -- pragma for later (see Analyze_Refined_Depends_In_Decl_Part) by
16982 -- adding it to the contract of the package body.
16983
16984 Add_Contract_Item (N, Defining_Entity (Context));
16985 end Refined_State;
16986
16987 -----------------------
16988 -- Relative_Deadline --
16989 -----------------------
16990
16991 -- pragma Relative_Deadline (time_span_EXPRESSION);
16992
16993 when Pragma_Relative_Deadline => Relative_Deadline : declare
16994 P : constant Node_Id := Parent (N);
16995 Arg : Node_Id;
16996
16997 begin
16998 Ada_2005_Pragma;
16999 Check_No_Identifiers;
17000 Check_Arg_Count (1);
17001
17002 Arg := Get_Pragma_Arg (Arg1);
17003
17004 -- The expression must be analyzed in the special manner described
17005 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
17006
17007 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
17008
17009 -- Subprogram case
17010
17011 if Nkind (P) = N_Subprogram_Body then
17012 Check_In_Main_Program;
17013
17014 -- Only Task and subprogram cases allowed
17015
17016 elsif Nkind (P) /= N_Task_Definition then
17017 Pragma_Misplaced;
17018 end if;
17019
17020 -- Check duplicate pragma before we set the corresponding flag
17021
17022 if Has_Relative_Deadline_Pragma (P) then
17023 Error_Pragma ("duplicate pragma% not allowed");
17024 end if;
17025
17026 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
17027 -- Relative_Deadline pragma node cannot be inserted in the Rep
17028 -- Item chain of Ent since it is rewritten by the expander as a
17029 -- procedure call statement that will break the chain.
17030
17031 Set_Has_Relative_Deadline_Pragma (P, True);
17032 end Relative_Deadline;
17033
17034 ------------------------
17035 -- Remote_Access_Type --
17036 ------------------------
17037
17038 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
17039
17040 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
17041 E : Entity_Id;
17042
17043 begin
17044 GNAT_Pragma;
17045 Check_Arg_Count (1);
17046 Check_Optional_Identifier (Arg1, Name_Entity);
17047 Check_Arg_Is_Local_Name (Arg1);
17048
17049 E := Entity (Get_Pragma_Arg (Arg1));
17050
17051 if Nkind (Parent (E)) = N_Formal_Type_Declaration
17052 and then Ekind (E) = E_General_Access_Type
17053 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
17054 and then Scope (Root_Type (Directly_Designated_Type (E)))
17055 = Scope (E)
17056 and then Is_Valid_Remote_Object_Type
17057 (Root_Type (Directly_Designated_Type (E)))
17058 then
17059 Set_Is_Remote_Types (E);
17060
17061 else
17062 Error_Pragma_Arg
17063 ("pragma% applies only to formal access to classwide types",
17064 Arg1);
17065 end if;
17066 end Remote_Access_Type;
17067
17068 ---------------------------
17069 -- Remote_Call_Interface --
17070 ---------------------------
17071
17072 -- pragma Remote_Call_Interface [(library_unit_NAME)];
17073
17074 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
17075 Cunit_Node : Node_Id;
17076 Cunit_Ent : Entity_Id;
17077 K : Node_Kind;
17078
17079 begin
17080 Check_Ada_83_Warning;
17081 Check_Valid_Library_Unit_Pragma;
17082
17083 if Nkind (N) = N_Null_Statement then
17084 return;
17085 end if;
17086
17087 Cunit_Node := Cunit (Current_Sem_Unit);
17088 K := Nkind (Unit (Cunit_Node));
17089 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
17090
17091 if K = N_Package_Declaration
17092 or else K = N_Generic_Package_Declaration
17093 or else K = N_Subprogram_Declaration
17094 or else K = N_Generic_Subprogram_Declaration
17095 or else (K = N_Subprogram_Body
17096 and then Acts_As_Spec (Unit (Cunit_Node)))
17097 then
17098 null;
17099 else
17100 Error_Pragma (
17101 "pragma% must apply to package or subprogram declaration");
17102 end if;
17103
17104 Set_Is_Remote_Call_Interface (Cunit_Ent);
17105 end Remote_Call_Interface;
17106
17107 ------------------
17108 -- Remote_Types --
17109 ------------------
17110
17111 -- pragma Remote_Types [(library_unit_NAME)];
17112
17113 when Pragma_Remote_Types => Remote_Types : declare
17114 Cunit_Node : Node_Id;
17115 Cunit_Ent : Entity_Id;
17116
17117 begin
17118 Check_Ada_83_Warning;
17119 Check_Valid_Library_Unit_Pragma;
17120
17121 if Nkind (N) = N_Null_Statement then
17122 return;
17123 end if;
17124
17125 Cunit_Node := Cunit (Current_Sem_Unit);
17126 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
17127
17128 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
17129 N_Generic_Package_Declaration)
17130 then
17131 Error_Pragma
17132 ("pragma% can only apply to a package declaration");
17133 end if;
17134
17135 Set_Is_Remote_Types (Cunit_Ent);
17136 end Remote_Types;
17137
17138 ---------------
17139 -- Ravenscar --
17140 ---------------
17141
17142 -- pragma Ravenscar;
17143
17144 when Pragma_Ravenscar =>
17145 GNAT_Pragma;
17146 Check_Arg_Count (0);
17147 Check_Valid_Configuration_Pragma;
17148 Set_Ravenscar_Profile (N);
17149
17150 if Warn_On_Obsolescent_Feature then
17151 Error_Msg_N
17152 ("pragma Ravenscar is an obsolescent feature?j?", N);
17153 Error_Msg_N
17154 ("|use pragma Profile (Ravenscar) instead?j?", N);
17155 end if;
17156
17157 -------------------------
17158 -- Restricted_Run_Time --
17159 -------------------------
17160
17161 -- pragma Restricted_Run_Time;
17162
17163 when Pragma_Restricted_Run_Time =>
17164 GNAT_Pragma;
17165 Check_Arg_Count (0);
17166 Check_Valid_Configuration_Pragma;
17167 Set_Profile_Restrictions
17168 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
17169
17170 if Warn_On_Obsolescent_Feature then
17171 Error_Msg_N
17172 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
17173 N);
17174 Error_Msg_N
17175 ("|use pragma Profile (Restricted) instead?j?", N);
17176 end if;
17177
17178 ------------------
17179 -- Restrictions --
17180 ------------------
17181
17182 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
17183
17184 -- RESTRICTION ::=
17185 -- restriction_IDENTIFIER
17186 -- | restriction_parameter_IDENTIFIER => EXPRESSION
17187
17188 when Pragma_Restrictions =>
17189 Process_Restrictions_Or_Restriction_Warnings
17190 (Warn => Treat_Restrictions_As_Warnings);
17191
17192 --------------------------
17193 -- Restriction_Warnings --
17194 --------------------------
17195
17196 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
17197
17198 -- RESTRICTION ::=
17199 -- restriction_IDENTIFIER
17200 -- | restriction_parameter_IDENTIFIER => EXPRESSION
17201
17202 when Pragma_Restriction_Warnings =>
17203 GNAT_Pragma;
17204 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
17205
17206 ----------------
17207 -- Reviewable --
17208 ----------------
17209
17210 -- pragma Reviewable;
17211
17212 when Pragma_Reviewable =>
17213 Check_Ada_83_Warning;
17214 Check_Arg_Count (0);
17215
17216 -- Call dummy debugging function rv. This is done to assist front
17217 -- end debugging. By placing a Reviewable pragma in the source
17218 -- program, a breakpoint on rv catches this place in the source,
17219 -- allowing convenient stepping to the point of interest.
17220
17221 rv;
17222
17223 --------------------------
17224 -- Short_Circuit_And_Or --
17225 --------------------------
17226
17227 -- pragma Short_Circuit_And_Or;
17228
17229 when Pragma_Short_Circuit_And_Or =>
17230 GNAT_Pragma;
17231 Check_Arg_Count (0);
17232 Check_Valid_Configuration_Pragma;
17233 Short_Circuit_And_Or := True;
17234
17235 -------------------
17236 -- Share_Generic --
17237 -------------------
17238
17239 -- pragma Share_Generic (GNAME {, GNAME});
17240
17241 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
17242
17243 when Pragma_Share_Generic =>
17244 GNAT_Pragma;
17245 Process_Generic_List;
17246
17247 ------------
17248 -- Shared --
17249 ------------
17250
17251 -- pragma Shared (LOCAL_NAME);
17252
17253 when Pragma_Shared =>
17254 GNAT_Pragma;
17255 Process_Atomic_Shared_Volatile;
17256
17257 --------------------
17258 -- Shared_Passive --
17259 --------------------
17260
17261 -- pragma Shared_Passive [(library_unit_NAME)];
17262
17263 -- Set the flag Is_Shared_Passive of program unit name entity
17264
17265 when Pragma_Shared_Passive => Shared_Passive : declare
17266 Cunit_Node : Node_Id;
17267 Cunit_Ent : Entity_Id;
17268
17269 begin
17270 Check_Ada_83_Warning;
17271 Check_Valid_Library_Unit_Pragma;
17272
17273 if Nkind (N) = N_Null_Statement then
17274 return;
17275 end if;
17276
17277 Cunit_Node := Cunit (Current_Sem_Unit);
17278 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
17279
17280 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
17281 N_Generic_Package_Declaration)
17282 then
17283 Error_Pragma
17284 ("pragma% can only apply to a package declaration");
17285 end if;
17286
17287 Set_Is_Shared_Passive (Cunit_Ent);
17288 end Shared_Passive;
17289
17290 -----------------------
17291 -- Short_Descriptors --
17292 -----------------------
17293
17294 -- pragma Short_Descriptors;
17295
17296 when Pragma_Short_Descriptors =>
17297 GNAT_Pragma;
17298 Check_Arg_Count (0);
17299 Check_Valid_Configuration_Pragma;
17300 Short_Descriptors := True;
17301
17302 ------------------------------
17303 -- Simple_Storage_Pool_Type --
17304 ------------------------------
17305
17306 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
17307
17308 when Pragma_Simple_Storage_Pool_Type =>
17309 Simple_Storage_Pool_Type : declare
17310 Type_Id : Node_Id;
17311 Typ : Entity_Id;
17312
17313 begin
17314 GNAT_Pragma;
17315 Check_Arg_Count (1);
17316 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17317
17318 Type_Id := Get_Pragma_Arg (Arg1);
17319 Find_Type (Type_Id);
17320 Typ := Entity (Type_Id);
17321
17322 if Typ = Any_Type then
17323 return;
17324 end if;
17325
17326 -- We require the pragma to apply to a type declared in a package
17327 -- declaration, but not (immediately) within a package body.
17328
17329 if Ekind (Current_Scope) /= E_Package
17330 or else In_Package_Body (Current_Scope)
17331 then
17332 Error_Pragma
17333 ("pragma% can only apply to type declared immediately "
17334 & "within a package declaration");
17335 end if;
17336
17337 -- A simple storage pool type must be an immutably limited record
17338 -- or private type. If the pragma is given for a private type,
17339 -- the full type is similarly restricted (which is checked later
17340 -- in Freeze_Entity).
17341
17342 if Is_Record_Type (Typ)
17343 and then not Is_Immutably_Limited_Type (Typ)
17344 then
17345 Error_Pragma
17346 ("pragma% can only apply to explicitly limited record type");
17347
17348 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
17349 Error_Pragma
17350 ("pragma% can only apply to a private type that is limited");
17351
17352 elsif not Is_Record_Type (Typ)
17353 and then not Is_Private_Type (Typ)
17354 then
17355 Error_Pragma
17356 ("pragma% can only apply to limited record or private type");
17357 end if;
17358
17359 Record_Rep_Item (Typ, N);
17360 end Simple_Storage_Pool_Type;
17361
17362 ----------------------
17363 -- Source_File_Name --
17364 ----------------------
17365
17366 -- There are five forms for this pragma:
17367
17368 -- pragma Source_File_Name (
17369 -- [UNIT_NAME =>] unit_NAME,
17370 -- BODY_FILE_NAME => STRING_LITERAL
17371 -- [, [INDEX =>] INTEGER_LITERAL]);
17372
17373 -- pragma Source_File_Name (
17374 -- [UNIT_NAME =>] unit_NAME,
17375 -- SPEC_FILE_NAME => STRING_LITERAL
17376 -- [, [INDEX =>] INTEGER_LITERAL]);
17377
17378 -- pragma Source_File_Name (
17379 -- BODY_FILE_NAME => STRING_LITERAL
17380 -- [, DOT_REPLACEMENT => STRING_LITERAL]
17381 -- [, CASING => CASING_SPEC]);
17382
17383 -- pragma Source_File_Name (
17384 -- SPEC_FILE_NAME => STRING_LITERAL
17385 -- [, DOT_REPLACEMENT => STRING_LITERAL]
17386 -- [, CASING => CASING_SPEC]);
17387
17388 -- pragma Source_File_Name (
17389 -- SUBUNIT_FILE_NAME => STRING_LITERAL
17390 -- [, DOT_REPLACEMENT => STRING_LITERAL]
17391 -- [, CASING => CASING_SPEC]);
17392
17393 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
17394
17395 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
17396 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
17397 -- only be used when no project file is used, while SFNP can only be
17398 -- used when a project file is used.
17399
17400 -- No processing here. Processing was completed during parsing, since
17401 -- we need to have file names set as early as possible. Units are
17402 -- loaded well before semantic processing starts.
17403
17404 -- The only processing we defer to this point is the check for
17405 -- correct placement.
17406
17407 when Pragma_Source_File_Name =>
17408 GNAT_Pragma;
17409 Check_Valid_Configuration_Pragma;
17410
17411 ------------------------------
17412 -- Source_File_Name_Project --
17413 ------------------------------
17414
17415 -- See Source_File_Name for syntax
17416
17417 -- No processing here. Processing was completed during parsing, since
17418 -- we need to have file names set as early as possible. Units are
17419 -- loaded well before semantic processing starts.
17420
17421 -- The only processing we defer to this point is the check for
17422 -- correct placement.
17423
17424 when Pragma_Source_File_Name_Project =>
17425 GNAT_Pragma;
17426 Check_Valid_Configuration_Pragma;
17427
17428 -- Check that a pragma Source_File_Name_Project is used only in a
17429 -- configuration pragmas file.
17430
17431 -- Pragmas Source_File_Name_Project should only be generated by
17432 -- the Project Manager in configuration pragmas files.
17433
17434 -- This is really an ugly test. It seems to depend on some
17435 -- accidental and undocumented property. At the very least it
17436 -- needs to be documented, but it would be better to have a
17437 -- clean way of testing if we are in a configuration file???
17438
17439 if Present (Parent (N)) then
17440 Error_Pragma
17441 ("pragma% can only appear in a configuration pragmas file");
17442 end if;
17443
17444 ----------------------
17445 -- Source_Reference --
17446 ----------------------
17447
17448 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
17449
17450 -- Nothing to do, all processing completed in Par.Prag, since we need
17451 -- the information for possible parser messages that are output.
17452
17453 when Pragma_Source_Reference =>
17454 GNAT_Pragma;
17455
17456 ----------------
17457 -- SPARK_Mode --
17458 ----------------
17459
17460 -- pragma SPARK_Mode [(On | Off | Auto)];
17461
17462 when Pragma_SPARK_Mode => SPARK_Mod : declare
17463 procedure Chain_Pragma (Context : Entity_Id; Prag : Node_Id);
17464 -- Associate a SPARK_Mode pragma with the context where it lives.
17465 -- If the context is a package spec or a body, the routine checks
17466 -- the consistency between modes of visible/private declarations
17467 -- and body declarations/statements.
17468
17469 procedure Check_Spark_Mode_Conformance
17470 (Governing_Id : Entity_Id;
17471 New_Id : Entity_Id);
17472 -- Verify the "monotonicity" of SPARK modes between two entities.
17473 -- The order of modes is Off < Auto < On. Governing_Id establishes
17474 -- the mode of the context. New_Id attempts to redefine the known
17475 -- mode.
17476
17477 procedure Check_Pragma_Conformance
17478 (Governing_Mode : Node_Id;
17479 New_Mode : Node_Id);
17480 -- Verify the "monotonicity" of two SPARK_Mode pragmas. The order
17481 -- of modes is Off < Auto < On. Governing_Mode is the established
17482 -- mode dictated by the context. New_Mode attempts to redefine the
17483 -- governing mode.
17484
17485 function Get_SPARK_Mode_Name (Id : SPARK_Mode_Id) return Name_Id;
17486 -- Convert a value of type SPARK_Mode_Id into a corresponding name
17487
17488 ------------------
17489 -- Chain_Pragma --
17490 ------------------
17491
17492 procedure Chain_Pragma (Context : Entity_Id; Prag : Node_Id) is
17493 Existing_Prag : constant Node_Id :=
17494 SPARK_Mode_Pragmas (Context);
17495 begin
17496 -- The context does not have a prior mode defined
17497
17498 if No (Existing_Prag) then
17499 Set_SPARK_Mode_Pragmas (Context, Prag);
17500
17501 -- Chain the new mode on the list of SPARK_Mode pragmas. Verify
17502 -- the consistency between the existing mode and the new one.
17503
17504 else
17505 Set_Next_Pragma (Existing_Prag, Prag);
17506
17507 Check_Pragma_Conformance
17508 (Governing_Mode => Existing_Prag,
17509 New_Mode => Prag);
17510 end if;
17511 end Chain_Pragma;
17512
17513 ----------------------------------
17514 -- Check_Spark_Mode_Conformance --
17515 ----------------------------------
17516
17517 procedure Check_Spark_Mode_Conformance
17518 (Governing_Id : Entity_Id;
17519 New_Id : Entity_Id)
17520 is
17521 Gov_Prag : constant Node_Id :=
17522 SPARK_Mode_Pragmas (Governing_Id);
17523 New_Prag : constant Node_Id := SPARK_Mode_Pragmas (New_Id);
17524
17525 begin
17526 -- Nothing to do when one or both entities lack a mode
17527
17528 if No (Gov_Prag) or else No (New_Prag) then
17529 return;
17530 end if;
17531
17532 -- Do not compare the modes of a package spec and body when the
17533 -- spec mode appears in the private part. In this case the spec
17534 -- mode does not affect the body.
17535
17536 if Ekind_In (Governing_Id, E_Generic_Package, E_Package)
17537 and then Ekind (New_Id) = E_Package_Body
17538 and then Is_Private_SPARK_Mode (Gov_Prag)
17539 then
17540 null;
17541
17542 -- Test the pragmas
17543
17544 else
17545 Check_Pragma_Conformance
17546 (Governing_Mode => Gov_Prag,
17547 New_Mode => New_Prag);
17548 end if;
17549 end Check_Spark_Mode_Conformance;
17550
17551 ------------------------------
17552 -- Check_Pragma_Conformance --
17553 ------------------------------
17554
17555 procedure Check_Pragma_Conformance
17556 (Governing_Mode : Node_Id;
17557 New_Mode : Node_Id)
17558 is
17559 Gov_M : constant SPARK_Mode_Id :=
17560 Get_SPARK_Mode_Id (Governing_Mode);
17561 New_M : constant SPARK_Mode_Id := Get_SPARK_Mode_Id (New_Mode);
17562
17563 begin
17564 -- The new mode is less restrictive than the established mode
17565
17566 if Gov_M < New_M then
17567 Error_Msg_Name_1 := Get_SPARK_Mode_Name (New_M);
17568 Error_Msg_N ("cannot define 'S'P'A'R'K mode %", New_Mode);
17569
17570 Error_Msg_Name_1 := Get_SPARK_Mode_Name (Gov_M);
17571 Error_Msg_Sloc := Sloc (Governing_Mode);
17572 Error_Msg_N
17573 ("\mode is less restrictive than mode % defined #",
17574 New_Mode);
17575 end if;
17576 end Check_Pragma_Conformance;
17577
17578 -------------------------
17579 -- Get_SPARK_Mode_Name --
17580 -------------------------
17581
17582 function Get_SPARK_Mode_Name (Id : SPARK_Mode_Id) return Name_Id is
17583 begin
17584 if Id = SPARK_On then
17585 return Name_On;
17586 elsif Id = SPARK_Off then
17587 return Name_Off;
17588 elsif Id = SPARK_Auto then
17589 return Name_Auto;
17590
17591 -- Mode "None" should never be used in error message generation
17592
17593 else
17594 raise Program_Error;
17595 end if;
17596 end Get_SPARK_Mode_Name;
17597
17598 -- Local variables
17599
17600 Body_Id : Entity_Id;
17601 Context : Node_Id;
17602 Mode : Name_Id;
17603 Mode_Id : SPARK_Mode_Id;
17604 Spec_Id : Entity_Id;
17605 Stmt : Node_Id;
17606
17607 -- Start of processing for SPARK_Mode
17608
17609 begin
17610 GNAT_Pragma;
17611 Check_No_Identifiers;
17612 Check_At_Most_N_Arguments (1);
17613
17614 -- Check the legality of the mode
17615
17616 if Arg_Count = 1 then
17617 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off, Name_Auto);
17618 Mode := Chars (Get_Pragma_Arg (Arg1));
17619
17620 -- A SPARK_Mode without an argument defaults to "On"
17621
17622 else
17623 Mode := Name_On;
17624 end if;
17625
17626 Mode_Id := Get_SPARK_Mode_Id (Mode);
17627 Context := Parent (N);
17628
17629 -- The pragma appears in a configuration file
17630
17631 if No (Context) then
17632 Check_Valid_Configuration_Pragma;
17633 Global_SPARK_Mode := Mode_Id;
17634
17635 -- When the pragma is placed before the declaration of a unit, it
17636 -- configures the whole unit.
17637
17638 elsif Nkind (Context) = N_Compilation_Unit then
17639 Check_Valid_Configuration_Pragma;
17640 Set_SPARK_Mode_Pragma (Current_Sem_Unit, N);
17641
17642 -- The pragma applies to a [library unit] subprogram or package
17643
17644 else
17645 -- Mode "Auto" cannot be used in nested subprograms or packages
17646
17647 if Mode_Id = SPARK_Auto then
17648 Error_Pragma_Arg
17649 ("mode `Auto` can only apply to the configuration variant "
17650 & "of pragma %", Arg1);
17651 end if;
17652
17653 -- Verify the placement of the pragma with respect to package
17654 -- or subprogram declarations and detect duplicates.
17655
17656 Stmt := Prev (N);
17657 while Present (Stmt) loop
17658
17659 -- Skip prior pragmas, but check for duplicates
17660
17661 if Nkind (Stmt) = N_Pragma then
17662 if Pragma_Name (Stmt) = Pname then
17663 Error_Msg_Name_1 := Pname;
17664 Error_Msg_Sloc := Sloc (Stmt);
17665 Error_Msg_N
17666 ("pragma % duplicates pragma declared #", N);
17667 end if;
17668
17669 -- Skip internally generated code
17670
17671 elsif not Comes_From_Source (Stmt) then
17672 null;
17673
17674 -- The pragma applies to a package or subprogram declaration
17675
17676 elsif Nkind_In (Stmt, N_Generic_Package_Declaration,
17677 N_Generic_Subprogram_Declaration,
17678 N_Package_Declaration,
17679 N_Subprogram_Declaration)
17680 then
17681 Spec_Id := Defining_Unit_Name (Specification (Stmt));
17682 Chain_Pragma (Spec_Id, N);
17683 return;
17684
17685 -- The pragma does not apply to a legal construct, issue an
17686 -- error and stop the analysis.
17687
17688 else
17689 Pragma_Misplaced;
17690 exit;
17691 end if;
17692
17693 Stmt := Prev (Stmt);
17694 end loop;
17695
17696 -- Handle all cases where the pragma is actually an aspect and
17697 -- applies to a library-level package spec, body or subprogram.
17698
17699 -- function F ... with SPARK_Mode => ...;
17700 -- package P with SPARK_Mode => ...;
17701 -- package body P with SPARK_Mode => ... is
17702
17703 -- The following circuitry simply prepares the proper context
17704 -- for the general pragma processing mechanism below.
17705
17706 if Nkind (Context) = N_Compilation_Unit_Aux then
17707 Context := Unit (Parent (Context));
17708
17709 if Nkind_In (Context, N_Package_Declaration,
17710 N_Subprogram_Declaration)
17711 then
17712 Context := Specification (Context);
17713 end if;
17714 end if;
17715
17716 -- The pragma is at the top level of a package spec or appears
17717 -- as an aspect on a subprogram.
17718
17719 -- function F ... with SPARK_Mode => ...;
17720
17721 -- package P is
17722 -- pragma SPARK_Mode;
17723
17724 if Nkind_In (Context, N_Function_Specification,
17725 N_Package_Specification,
17726 N_Procedure_Specification)
17727 then
17728 Spec_Id := Defining_Unit_Name (Context);
17729 Chain_Pragma (Spec_Id, N);
17730
17731 -- The pragma is immediately within a package or subprogram
17732 -- body.
17733
17734 -- function F ... is
17735 -- pragma SPARK_Mode;
17736
17737 -- package body P is
17738 -- pragma SPARK_Mode;
17739
17740 elsif Nkind_In (Context, N_Package_Body,
17741 N_Subprogram_Body)
17742 then
17743 Spec_Id := Corresponding_Spec (Context);
17744
17745 if Nkind (Context) = N_Subprogram_Body then
17746 Context := Specification (Context);
17747 end if;
17748
17749 Body_Id := Defining_Unit_Name (Context);
17750
17751 Chain_Pragma (Body_Id, N);
17752
17753 -- Verify that the SPARK modes are consistent between
17754 -- body and spec, if any.
17755
17756 if Present (Spec_Id) then
17757 Check_Spark_Mode_Conformance (Spec_Id, Body_Id);
17758 end if;
17759
17760 -- The pragma applies to the statements of a package body
17761
17762 -- package body P is
17763 -- begin
17764 -- pragma SPARK_Mode;
17765
17766 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
17767 and then Nkind (Parent (Context)) = N_Package_Body
17768 then
17769 Context := Parent (Context);
17770 Spec_Id := Corresponding_Spec (Context);
17771 Body_Id := Defining_Unit_Name (Context);
17772
17773 Chain_Pragma (Body_Id, N);
17774 Check_Spark_Mode_Conformance (Spec_Id, Body_Id);
17775
17776 -- The pragma does not apply to a legal construct, issue error
17777
17778 else
17779 Pragma_Misplaced;
17780 end if;
17781 end if;
17782 end SPARK_Mod;
17783
17784 --------------------------------
17785 -- Static_Elaboration_Desired --
17786 --------------------------------
17787
17788 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
17789
17790 when Pragma_Static_Elaboration_Desired =>
17791 GNAT_Pragma;
17792 Check_At_Most_N_Arguments (1);
17793
17794 if Is_Compilation_Unit (Current_Scope)
17795 and then Ekind (Current_Scope) = E_Package
17796 then
17797 Set_Static_Elaboration_Desired (Current_Scope, True);
17798 else
17799 Error_Pragma ("pragma% must apply to a library-level package");
17800 end if;
17801
17802 ------------------
17803 -- Storage_Size --
17804 ------------------
17805
17806 -- pragma Storage_Size (EXPRESSION);
17807
17808 when Pragma_Storage_Size => Storage_Size : declare
17809 P : constant Node_Id := Parent (N);
17810 Arg : Node_Id;
17811
17812 begin
17813 Check_No_Identifiers;
17814 Check_Arg_Count (1);
17815
17816 -- The expression must be analyzed in the special manner described
17817 -- in "Handling of Default Expressions" in sem.ads.
17818
17819 Arg := Get_Pragma_Arg (Arg1);
17820 Preanalyze_Spec_Expression (Arg, Any_Integer);
17821
17822 if not Is_Static_Expression (Arg) then
17823 Check_Restriction (Static_Storage_Size, Arg);
17824 end if;
17825
17826 if Nkind (P) /= N_Task_Definition then
17827 Pragma_Misplaced;
17828 return;
17829
17830 else
17831 if Has_Storage_Size_Pragma (P) then
17832 Error_Pragma ("duplicate pragma% not allowed");
17833 else
17834 Set_Has_Storage_Size_Pragma (P, True);
17835 end if;
17836
17837 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
17838 end if;
17839 end Storage_Size;
17840
17841 ------------------
17842 -- Storage_Unit --
17843 ------------------
17844
17845 -- pragma Storage_Unit (NUMERIC_LITERAL);
17846
17847 -- Only permitted argument is System'Storage_Unit value
17848
17849 when Pragma_Storage_Unit =>
17850 Check_No_Identifiers;
17851 Check_Arg_Count (1);
17852 Check_Arg_Is_Integer_Literal (Arg1);
17853
17854 if Intval (Get_Pragma_Arg (Arg1)) /=
17855 UI_From_Int (Ttypes.System_Storage_Unit)
17856 then
17857 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
17858 Error_Pragma_Arg
17859 ("the only allowed argument for pragma% is ^", Arg1);
17860 end if;
17861
17862 --------------------
17863 -- Stream_Convert --
17864 --------------------
17865
17866 -- pragma Stream_Convert (
17867 -- [Entity =>] type_LOCAL_NAME,
17868 -- [Read =>] function_NAME,
17869 -- [Write =>] function NAME);
17870
17871 when Pragma_Stream_Convert => Stream_Convert : declare
17872
17873 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
17874 -- Check that the given argument is the name of a local function
17875 -- of one argument that is not overloaded earlier in the current
17876 -- local scope. A check is also made that the argument is a
17877 -- function with one parameter.
17878
17879 --------------------------------------
17880 -- Check_OK_Stream_Convert_Function --
17881 --------------------------------------
17882
17883 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
17884 Ent : Entity_Id;
17885
17886 begin
17887 Check_Arg_Is_Local_Name (Arg);
17888 Ent := Entity (Get_Pragma_Arg (Arg));
17889
17890 if Has_Homonym (Ent) then
17891 Error_Pragma_Arg
17892 ("argument for pragma% may not be overloaded", Arg);
17893 end if;
17894
17895 if Ekind (Ent) /= E_Function
17896 or else No (First_Formal (Ent))
17897 or else Present (Next_Formal (First_Formal (Ent)))
17898 then
17899 Error_Pragma_Arg
17900 ("argument for pragma% must be function of one argument",
17901 Arg);
17902 end if;
17903 end Check_OK_Stream_Convert_Function;
17904
17905 -- Start of processing for Stream_Convert
17906
17907 begin
17908 GNAT_Pragma;
17909 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
17910 Check_Arg_Count (3);
17911 Check_Optional_Identifier (Arg1, Name_Entity);
17912 Check_Optional_Identifier (Arg2, Name_Read);
17913 Check_Optional_Identifier (Arg3, Name_Write);
17914 Check_Arg_Is_Local_Name (Arg1);
17915 Check_OK_Stream_Convert_Function (Arg2);
17916 Check_OK_Stream_Convert_Function (Arg3);
17917
17918 declare
17919 Typ : constant Entity_Id :=
17920 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
17921 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
17922 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
17923
17924 begin
17925 Check_First_Subtype (Arg1);
17926
17927 -- Check for too early or too late. Note that we don't enforce
17928 -- the rule about primitive operations in this case, since, as
17929 -- is the case for explicit stream attributes themselves, these
17930 -- restrictions are not appropriate. Note that the chaining of
17931 -- the pragma by Rep_Item_Too_Late is actually the critical
17932 -- processing done for this pragma.
17933
17934 if Rep_Item_Too_Early (Typ, N)
17935 or else
17936 Rep_Item_Too_Late (Typ, N, FOnly => True)
17937 then
17938 return;
17939 end if;
17940
17941 -- Return if previous error
17942
17943 if Etype (Typ) = Any_Type
17944 or else
17945 Etype (Read) = Any_Type
17946 or else
17947 Etype (Write) = Any_Type
17948 then
17949 return;
17950 end if;
17951
17952 -- Error checks
17953
17954 if Underlying_Type (Etype (Read)) /= Typ then
17955 Error_Pragma_Arg
17956 ("incorrect return type for function&", Arg2);
17957 end if;
17958
17959 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
17960 Error_Pragma_Arg
17961 ("incorrect parameter type for function&", Arg3);
17962 end if;
17963
17964 if Underlying_Type (Etype (First_Formal (Read))) /=
17965 Underlying_Type (Etype (Write))
17966 then
17967 Error_Pragma_Arg
17968 ("result type of & does not match Read parameter type",
17969 Arg3);
17970 end if;
17971 end;
17972 end Stream_Convert;
17973
17974 ------------------
17975 -- Style_Checks --
17976 ------------------
17977
17978 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
17979
17980 -- This is processed by the parser since some of the style checks
17981 -- take place during source scanning and parsing. This means that
17982 -- we don't need to issue error messages here.
17983
17984 when Pragma_Style_Checks => Style_Checks : declare
17985 A : constant Node_Id := Get_Pragma_Arg (Arg1);
17986 S : String_Id;
17987 C : Char_Code;
17988
17989 begin
17990 GNAT_Pragma;
17991 Check_No_Identifiers;
17992
17993 -- Two argument form
17994
17995 if Arg_Count = 2 then
17996 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17997
17998 declare
17999 E_Id : Node_Id;
18000 E : Entity_Id;
18001
18002 begin
18003 E_Id := Get_Pragma_Arg (Arg2);
18004 Analyze (E_Id);
18005
18006 if not Is_Entity_Name (E_Id) then
18007 Error_Pragma_Arg
18008 ("second argument of pragma% must be entity name",
18009 Arg2);
18010 end if;
18011
18012 E := Entity (E_Id);
18013
18014 if not Ignore_Style_Checks_Pragmas then
18015 if E = Any_Id then
18016 return;
18017 else
18018 loop
18019 Set_Suppress_Style_Checks
18020 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
18021 exit when No (Homonym (E));
18022 E := Homonym (E);
18023 end loop;
18024 end if;
18025 end if;
18026 end;
18027
18028 -- One argument form
18029
18030 else
18031 Check_Arg_Count (1);
18032
18033 if Nkind (A) = N_String_Literal then
18034 S := Strval (A);
18035
18036 declare
18037 Slen : constant Natural := Natural (String_Length (S));
18038 Options : String (1 .. Slen);
18039 J : Natural;
18040
18041 begin
18042 J := 1;
18043 loop
18044 C := Get_String_Char (S, Int (J));
18045 exit when not In_Character_Range (C);
18046 Options (J) := Get_Character (C);
18047
18048 -- If at end of string, set options. As per discussion
18049 -- above, no need to check for errors, since we issued
18050 -- them in the parser.
18051
18052 if J = Slen then
18053 if not Ignore_Style_Checks_Pragmas then
18054 Set_Style_Check_Options (Options);
18055 end if;
18056
18057 exit;
18058 end if;
18059
18060 J := J + 1;
18061 end loop;
18062 end;
18063
18064 elsif Nkind (A) = N_Identifier then
18065 if Chars (A) = Name_All_Checks then
18066 if not Ignore_Style_Checks_Pragmas then
18067 if GNAT_Mode then
18068 Set_GNAT_Style_Check_Options;
18069 else
18070 Set_Default_Style_Check_Options;
18071 end if;
18072 end if;
18073
18074 elsif Chars (A) = Name_On then
18075 if not Ignore_Style_Checks_Pragmas then
18076 Style_Check := True;
18077 end if;
18078
18079 elsif Chars (A) = Name_Off then
18080 if not Ignore_Style_Checks_Pragmas then
18081 Style_Check := False;
18082 end if;
18083 end if;
18084 end if;
18085 end if;
18086 end Style_Checks;
18087
18088 --------------
18089 -- Subtitle --
18090 --------------
18091
18092 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
18093
18094 when Pragma_Subtitle =>
18095 GNAT_Pragma;
18096 Check_Arg_Count (1);
18097 Check_Optional_Identifier (Arg1, Name_Subtitle);
18098 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
18099 Store_Note (N);
18100
18101 --------------
18102 -- Suppress --
18103 --------------
18104
18105 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
18106
18107 when Pragma_Suppress =>
18108 Process_Suppress_Unsuppress (True);
18109
18110 ------------------
18111 -- Suppress_All --
18112 ------------------
18113
18114 -- pragma Suppress_All;
18115
18116 -- The only check made here is that the pragma has no arguments.
18117 -- There are no placement rules, and the processing required (setting
18118 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
18119 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
18120 -- then creates and inserts a pragma Suppress (All_Checks).
18121
18122 when Pragma_Suppress_All =>
18123 GNAT_Pragma;
18124 Check_Arg_Count (0);
18125
18126 -------------------------
18127 -- Suppress_Debug_Info --
18128 -------------------------
18129
18130 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
18131
18132 when Pragma_Suppress_Debug_Info =>
18133 GNAT_Pragma;
18134 Check_Arg_Count (1);
18135 Check_Optional_Identifier (Arg1, Name_Entity);
18136 Check_Arg_Is_Local_Name (Arg1);
18137 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
18138
18139 ----------------------------------
18140 -- Suppress_Exception_Locations --
18141 ----------------------------------
18142
18143 -- pragma Suppress_Exception_Locations;
18144
18145 when Pragma_Suppress_Exception_Locations =>
18146 GNAT_Pragma;
18147 Check_Arg_Count (0);
18148 Check_Valid_Configuration_Pragma;
18149 Exception_Locations_Suppressed := True;
18150
18151 -----------------------------
18152 -- Suppress_Initialization --
18153 -----------------------------
18154
18155 -- pragma Suppress_Initialization ([Entity =>] type_Name);
18156
18157 when Pragma_Suppress_Initialization => Suppress_Init : declare
18158 E_Id : Node_Id;
18159 E : Entity_Id;
18160
18161 begin
18162 GNAT_Pragma;
18163 Check_Arg_Count (1);
18164 Check_Optional_Identifier (Arg1, Name_Entity);
18165 Check_Arg_Is_Local_Name (Arg1);
18166
18167 E_Id := Get_Pragma_Arg (Arg1);
18168
18169 if Etype (E_Id) = Any_Type then
18170 return;
18171 end if;
18172
18173 E := Entity (E_Id);
18174
18175 if not Is_Type (E) then
18176 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
18177 end if;
18178
18179 if Rep_Item_Too_Early (E, N)
18180 or else
18181 Rep_Item_Too_Late (E, N, FOnly => True)
18182 then
18183 return;
18184 end if;
18185
18186 -- For incomplete/private type, set flag on full view
18187
18188 if Is_Incomplete_Or_Private_Type (E) then
18189 if No (Full_View (Base_Type (E))) then
18190 Error_Pragma_Arg
18191 ("argument of pragma% cannot be an incomplete type", Arg1);
18192 else
18193 Set_Suppress_Initialization (Full_View (Base_Type (E)));
18194 end if;
18195
18196 -- For first subtype, set flag on base type
18197
18198 elsif Is_First_Subtype (E) then
18199 Set_Suppress_Initialization (Base_Type (E));
18200
18201 -- For other than first subtype, set flag on subtype itself
18202
18203 else
18204 Set_Suppress_Initialization (E);
18205 end if;
18206 end Suppress_Init;
18207
18208 -----------------
18209 -- System_Name --
18210 -----------------
18211
18212 -- pragma System_Name (DIRECT_NAME);
18213
18214 -- Syntax check: one argument, which must be the identifier GNAT or
18215 -- the identifier GCC, no other identifiers are acceptable.
18216
18217 when Pragma_System_Name =>
18218 GNAT_Pragma;
18219 Check_No_Identifiers;
18220 Check_Arg_Count (1);
18221 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
18222
18223 -----------------------------
18224 -- Task_Dispatching_Policy --
18225 -----------------------------
18226
18227 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
18228
18229 when Pragma_Task_Dispatching_Policy => declare
18230 DP : Character;
18231
18232 begin
18233 Check_Ada_83_Warning;
18234 Check_Arg_Count (1);
18235 Check_No_Identifiers;
18236 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18237 Check_Valid_Configuration_Pragma;
18238 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18239 DP := Fold_Upper (Name_Buffer (1));
18240
18241 if Task_Dispatching_Policy /= ' '
18242 and then Task_Dispatching_Policy /= DP
18243 then
18244 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18245 Error_Pragma
18246 ("task dispatching policy incompatible with policy#");
18247
18248 -- Set new policy, but always preserve System_Location since we
18249 -- like the error message with the run time name.
18250
18251 else
18252 Task_Dispatching_Policy := DP;
18253
18254 if Task_Dispatching_Policy_Sloc /= System_Location then
18255 Task_Dispatching_Policy_Sloc := Loc;
18256 end if;
18257 end if;
18258 end;
18259
18260 ---------------
18261 -- Task_Info --
18262 ---------------
18263
18264 -- pragma Task_Info (EXPRESSION);
18265
18266 when Pragma_Task_Info => Task_Info : declare
18267 P : constant Node_Id := Parent (N);
18268 Ent : Entity_Id;
18269
18270 begin
18271 GNAT_Pragma;
18272
18273 if Nkind (P) /= N_Task_Definition then
18274 Error_Pragma ("pragma% must appear in task definition");
18275 end if;
18276
18277 Check_No_Identifiers;
18278 Check_Arg_Count (1);
18279
18280 Analyze_And_Resolve
18281 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
18282
18283 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
18284 return;
18285 end if;
18286
18287 Ent := Defining_Identifier (Parent (P));
18288
18289 -- Check duplicate pragma before we chain the pragma in the Rep
18290 -- Item chain of Ent.
18291
18292 if Has_Rep_Pragma
18293 (Ent, Name_Task_Info, Check_Parents => False)
18294 then
18295 Error_Pragma ("duplicate pragma% not allowed");
18296 end if;
18297
18298 Record_Rep_Item (Ent, N);
18299 end Task_Info;
18300
18301 ---------------
18302 -- Task_Name --
18303 ---------------
18304
18305 -- pragma Task_Name (string_EXPRESSION);
18306
18307 when Pragma_Task_Name => Task_Name : declare
18308 P : constant Node_Id := Parent (N);
18309 Arg : Node_Id;
18310 Ent : Entity_Id;
18311
18312 begin
18313 Check_No_Identifiers;
18314 Check_Arg_Count (1);
18315
18316 Arg := Get_Pragma_Arg (Arg1);
18317
18318 -- The expression is used in the call to Create_Task, and must be
18319 -- expanded there, not in the context of the current spec. It must
18320 -- however be analyzed to capture global references, in case it
18321 -- appears in a generic context.
18322
18323 Preanalyze_And_Resolve (Arg, Standard_String);
18324
18325 if Nkind (P) /= N_Task_Definition then
18326 Pragma_Misplaced;
18327 end if;
18328
18329 Ent := Defining_Identifier (Parent (P));
18330
18331 -- Check duplicate pragma before we chain the pragma in the Rep
18332 -- Item chain of Ent.
18333
18334 if Has_Rep_Pragma
18335 (Ent, Name_Task_Name, Check_Parents => False)
18336 then
18337 Error_Pragma ("duplicate pragma% not allowed");
18338 end if;
18339
18340 Record_Rep_Item (Ent, N);
18341 end Task_Name;
18342
18343 ------------------
18344 -- Task_Storage --
18345 ------------------
18346
18347 -- pragma Task_Storage (
18348 -- [Task_Type =>] LOCAL_NAME,
18349 -- [Top_Guard =>] static_integer_EXPRESSION);
18350
18351 when Pragma_Task_Storage => Task_Storage : declare
18352 Args : Args_List (1 .. 2);
18353 Names : constant Name_List (1 .. 2) := (
18354 Name_Task_Type,
18355 Name_Top_Guard);
18356
18357 Task_Type : Node_Id renames Args (1);
18358 Top_Guard : Node_Id renames Args (2);
18359
18360 Ent : Entity_Id;
18361
18362 begin
18363 GNAT_Pragma;
18364 Gather_Associations (Names, Args);
18365
18366 if No (Task_Type) then
18367 Error_Pragma
18368 ("missing task_type argument for pragma%");
18369 end if;
18370
18371 Check_Arg_Is_Local_Name (Task_Type);
18372
18373 Ent := Entity (Task_Type);
18374
18375 if not Is_Task_Type (Ent) then
18376 Error_Pragma_Arg
18377 ("argument for pragma% must be task type", Task_Type);
18378 end if;
18379
18380 if No (Top_Guard) then
18381 Error_Pragma_Arg
18382 ("pragma% takes two arguments", Task_Type);
18383 else
18384 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
18385 end if;
18386
18387 Check_First_Subtype (Task_Type);
18388
18389 if Rep_Item_Too_Late (Ent, N) then
18390 raise Pragma_Exit;
18391 end if;
18392 end Task_Storage;
18393
18394 ---------------
18395 -- Test_Case --
18396 ---------------
18397
18398 -- pragma Test_Case
18399 -- ([Name =>] Static_String_EXPRESSION
18400 -- ,[Mode =>] MODE_TYPE
18401 -- [, Requires => Boolean_EXPRESSION]
18402 -- [, Ensures => Boolean_EXPRESSION]);
18403
18404 -- MODE_TYPE ::= Nominal | Robustness
18405
18406 when Pragma_Test_Case =>
18407 GNAT_Pragma;
18408 Check_Test_Case;
18409
18410 --------------------------
18411 -- Thread_Local_Storage --
18412 --------------------------
18413
18414 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
18415
18416 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
18417 Id : Node_Id;
18418 E : Entity_Id;
18419
18420 begin
18421 GNAT_Pragma;
18422 Check_Arg_Count (1);
18423 Check_Optional_Identifier (Arg1, Name_Entity);
18424 Check_Arg_Is_Library_Level_Local_Name (Arg1);
18425
18426 Id := Get_Pragma_Arg (Arg1);
18427 Analyze (Id);
18428
18429 if not Is_Entity_Name (Id)
18430 or else Ekind (Entity (Id)) /= E_Variable
18431 then
18432 Error_Pragma_Arg ("local variable name required", Arg1);
18433 end if;
18434
18435 E := Entity (Id);
18436
18437 if Rep_Item_Too_Early (E, N)
18438 or else Rep_Item_Too_Late (E, N)
18439 then
18440 raise Pragma_Exit;
18441 end if;
18442
18443 Set_Has_Pragma_Thread_Local_Storage (E);
18444 Set_Has_Gigi_Rep_Item (E);
18445 end Thread_Local_Storage;
18446
18447 ----------------
18448 -- Time_Slice --
18449 ----------------
18450
18451 -- pragma Time_Slice (static_duration_EXPRESSION);
18452
18453 when Pragma_Time_Slice => Time_Slice : declare
18454 Val : Ureal;
18455 Nod : Node_Id;
18456
18457 begin
18458 GNAT_Pragma;
18459 Check_Arg_Count (1);
18460 Check_No_Identifiers;
18461 Check_In_Main_Program;
18462 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
18463
18464 if not Error_Posted (Arg1) then
18465 Nod := Next (N);
18466 while Present (Nod) loop
18467 if Nkind (Nod) = N_Pragma
18468 and then Pragma_Name (Nod) = Name_Time_Slice
18469 then
18470 Error_Msg_Name_1 := Pname;
18471 Error_Msg_N ("duplicate pragma% not permitted", Nod);
18472 end if;
18473
18474 Next (Nod);
18475 end loop;
18476 end if;
18477
18478 -- Process only if in main unit
18479
18480 if Get_Source_Unit (Loc) = Main_Unit then
18481 Opt.Time_Slice_Set := True;
18482 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
18483
18484 if Val <= Ureal_0 then
18485 Opt.Time_Slice_Value := 0;
18486
18487 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
18488 Opt.Time_Slice_Value := 1_000_000_000;
18489
18490 else
18491 Opt.Time_Slice_Value :=
18492 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
18493 end if;
18494 end if;
18495 end Time_Slice;
18496
18497 -----------
18498 -- Title --
18499 -----------
18500
18501 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
18502
18503 -- TITLING_OPTION ::=
18504 -- [Title =>] STRING_LITERAL
18505 -- | [Subtitle =>] STRING_LITERAL
18506
18507 when Pragma_Title => Title : declare
18508 Args : Args_List (1 .. 2);
18509 Names : constant Name_List (1 .. 2) := (
18510 Name_Title,
18511 Name_Subtitle);
18512
18513 begin
18514 GNAT_Pragma;
18515 Gather_Associations (Names, Args);
18516 Store_Note (N);
18517
18518 for J in 1 .. 2 loop
18519 if Present (Args (J)) then
18520 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
18521 end if;
18522 end loop;
18523 end Title;
18524
18525 ----------------------------
18526 -- Type_Invariant[_Class] --
18527 ----------------------------
18528
18529 -- pragma Type_Invariant[_Class]
18530 -- ([Entity =>] type_LOCAL_NAME,
18531 -- [Check =>] EXPRESSION);
18532
18533 when Pragma_Type_Invariant |
18534 Pragma_Type_Invariant_Class =>
18535 Type_Invariant : declare
18536 I_Pragma : Node_Id;
18537
18538 begin
18539 Check_Arg_Count (2);
18540
18541 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
18542 -- setting Class_Present for the Type_Invariant_Class case.
18543
18544 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
18545 I_Pragma := New_Copy (N);
18546 Set_Pragma_Identifier
18547 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
18548 Rewrite (N, I_Pragma);
18549 Set_Analyzed (N, False);
18550 Analyze (N);
18551 end Type_Invariant;
18552
18553 ---------------------
18554 -- Unchecked_Union --
18555 ---------------------
18556
18557 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
18558
18559 when Pragma_Unchecked_Union => Unchecked_Union : declare
18560 Assoc : constant Node_Id := Arg1;
18561 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
18562 Typ : Entity_Id;
18563 Tdef : Node_Id;
18564 Clist : Node_Id;
18565 Vpart : Node_Id;
18566 Comp : Node_Id;
18567 Variant : Node_Id;
18568
18569 begin
18570 Ada_2005_Pragma;
18571 Check_No_Identifiers;
18572 Check_Arg_Count (1);
18573 Check_Arg_Is_Local_Name (Arg1);
18574
18575 Find_Type (Type_Id);
18576
18577 Typ := Entity (Type_Id);
18578
18579 if Typ = Any_Type
18580 or else Rep_Item_Too_Early (Typ, N)
18581 then
18582 return;
18583 else
18584 Typ := Underlying_Type (Typ);
18585 end if;
18586
18587 if Rep_Item_Too_Late (Typ, N) then
18588 return;
18589 end if;
18590
18591 Check_First_Subtype (Arg1);
18592
18593 -- Note remaining cases are references to a type in the current
18594 -- declarative part. If we find an error, we post the error on
18595 -- the relevant type declaration at an appropriate point.
18596
18597 if not Is_Record_Type (Typ) then
18598 Error_Msg_N ("unchecked union must be record type", Typ);
18599 return;
18600
18601 elsif Is_Tagged_Type (Typ) then
18602 Error_Msg_N ("unchecked union must not be tagged", Typ);
18603 return;
18604
18605 elsif not Has_Discriminants (Typ) then
18606 Error_Msg_N
18607 ("unchecked union must have one discriminant", Typ);
18608 return;
18609
18610 -- Note: in previous versions of GNAT we used to check for limited
18611 -- types and give an error, but in fact the standard does allow
18612 -- Unchecked_Union on limited types, so this check was removed.
18613
18614 -- Similarly, GNAT used to require that all discriminants have
18615 -- default values, but this is not mandated by the RM.
18616
18617 -- Proceed with basic error checks completed
18618
18619 else
18620 Tdef := Type_Definition (Declaration_Node (Typ));
18621 Clist := Component_List (Tdef);
18622
18623 -- Check presence of component list and variant part
18624
18625 if No (Clist) or else No (Variant_Part (Clist)) then
18626 Error_Msg_N
18627 ("unchecked union must have variant part", Tdef);
18628 return;
18629 end if;
18630
18631 -- Check components
18632
18633 Comp := First (Component_Items (Clist));
18634 while Present (Comp) loop
18635 Check_Component (Comp, Typ);
18636 Next (Comp);
18637 end loop;
18638
18639 -- Check variant part
18640
18641 Vpart := Variant_Part (Clist);
18642
18643 Variant := First (Variants (Vpart));
18644 while Present (Variant) loop
18645 Check_Variant (Variant, Typ);
18646 Next (Variant);
18647 end loop;
18648 end if;
18649
18650 Set_Is_Unchecked_Union (Typ);
18651 Set_Convention (Typ, Convention_C);
18652 Set_Has_Unchecked_Union (Base_Type (Typ));
18653 Set_Is_Unchecked_Union (Base_Type (Typ));
18654 end Unchecked_Union;
18655
18656 ------------------------
18657 -- Unimplemented_Unit --
18658 ------------------------
18659
18660 -- pragma Unimplemented_Unit;
18661
18662 -- Note: this only gives an error if we are generating code, or if
18663 -- we are in a generic library unit (where the pragma appears in the
18664 -- body, not in the spec).
18665
18666 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
18667 Cunitent : constant Entity_Id :=
18668 Cunit_Entity (Get_Source_Unit (Loc));
18669 Ent_Kind : constant Entity_Kind :=
18670 Ekind (Cunitent);
18671
18672 begin
18673 GNAT_Pragma;
18674 Check_Arg_Count (0);
18675
18676 if Operating_Mode = Generate_Code
18677 or else Ent_Kind = E_Generic_Function
18678 or else Ent_Kind = E_Generic_Procedure
18679 or else Ent_Kind = E_Generic_Package
18680 then
18681 Get_Name_String (Chars (Cunitent));
18682 Set_Casing (Mixed_Case);
18683 Write_Str (Name_Buffer (1 .. Name_Len));
18684 Write_Str (" is not supported in this configuration");
18685 Write_Eol;
18686 raise Unrecoverable_Error;
18687 end if;
18688 end Unimplemented_Unit;
18689
18690 ------------------------
18691 -- Universal_Aliasing --
18692 ------------------------
18693
18694 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
18695
18696 when Pragma_Universal_Aliasing => Universal_Alias : declare
18697 E_Id : Entity_Id;
18698
18699 begin
18700 GNAT_Pragma;
18701 Check_Arg_Count (1);
18702 Check_Optional_Identifier (Arg2, Name_Entity);
18703 Check_Arg_Is_Local_Name (Arg1);
18704 E_Id := Entity (Get_Pragma_Arg (Arg1));
18705
18706 if E_Id = Any_Type then
18707 return;
18708 elsif No (E_Id) or else not Is_Type (E_Id) then
18709 Error_Pragma_Arg ("pragma% requires type", Arg1);
18710 end if;
18711
18712 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
18713 Record_Rep_Item (E_Id, N);
18714 end Universal_Alias;
18715
18716 --------------------
18717 -- Universal_Data --
18718 --------------------
18719
18720 -- pragma Universal_Data [(library_unit_NAME)];
18721
18722 when Pragma_Universal_Data =>
18723 GNAT_Pragma;
18724
18725 -- If this is a configuration pragma, then set the universal
18726 -- addressing option, otherwise confirm that the pragma satisfies
18727 -- the requirements of library unit pragma placement and leave it
18728 -- to the GNAAMP back end to detect the pragma (avoids transitive
18729 -- setting of the option due to withed units).
18730
18731 if Is_Configuration_Pragma then
18732 Universal_Addressing_On_AAMP := True;
18733 else
18734 Check_Valid_Library_Unit_Pragma;
18735 end if;
18736
18737 if not AAMP_On_Target then
18738 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
18739 end if;
18740
18741 ----------------
18742 -- Unmodified --
18743 ----------------
18744
18745 -- pragma Unmodified (local_Name {, local_Name});
18746
18747 when Pragma_Unmodified => Unmodified : declare
18748 Arg_Node : Node_Id;
18749 Arg_Expr : Node_Id;
18750 Arg_Ent : Entity_Id;
18751
18752 begin
18753 GNAT_Pragma;
18754 Check_At_Least_N_Arguments (1);
18755
18756 -- Loop through arguments
18757
18758 Arg_Node := Arg1;
18759 while Present (Arg_Node) loop
18760 Check_No_Identifier (Arg_Node);
18761
18762 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
18763 -- in fact generate reference, so that the entity will have a
18764 -- reference, which will inhibit any warnings about it not
18765 -- being referenced, and also properly show up in the ali file
18766 -- as a reference. But this reference is recorded before the
18767 -- Has_Pragma_Unreferenced flag is set, so that no warning is
18768 -- generated for this reference.
18769
18770 Check_Arg_Is_Local_Name (Arg_Node);
18771 Arg_Expr := Get_Pragma_Arg (Arg_Node);
18772
18773 if Is_Entity_Name (Arg_Expr) then
18774 Arg_Ent := Entity (Arg_Expr);
18775
18776 if not Is_Assignable (Arg_Ent) then
18777 Error_Pragma_Arg
18778 ("pragma% can only be applied to a variable",
18779 Arg_Expr);
18780 else
18781 Set_Has_Pragma_Unmodified (Arg_Ent);
18782 end if;
18783 end if;
18784
18785 Next (Arg_Node);
18786 end loop;
18787 end Unmodified;
18788
18789 ------------------
18790 -- Unreferenced --
18791 ------------------
18792
18793 -- pragma Unreferenced (local_Name {, local_Name});
18794
18795 -- or when used in a context clause:
18796
18797 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
18798
18799 when Pragma_Unreferenced => Unreferenced : declare
18800 Arg_Node : Node_Id;
18801 Arg_Expr : Node_Id;
18802 Arg_Ent : Entity_Id;
18803 Citem : Node_Id;
18804
18805 begin
18806 GNAT_Pragma;
18807 Check_At_Least_N_Arguments (1);
18808
18809 -- Check case of appearing within context clause
18810
18811 if Is_In_Context_Clause then
18812
18813 -- The arguments must all be units mentioned in a with clause
18814 -- in the same context clause. Note we already checked (in
18815 -- Par.Prag) that the arguments are either identifiers or
18816 -- selected components.
18817
18818 Arg_Node := Arg1;
18819 while Present (Arg_Node) loop
18820 Citem := First (List_Containing (N));
18821 while Citem /= N loop
18822 if Nkind (Citem) = N_With_Clause
18823 and then
18824 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
18825 then
18826 Set_Has_Pragma_Unreferenced
18827 (Cunit_Entity
18828 (Get_Source_Unit
18829 (Library_Unit (Citem))));
18830 Set_Unit_Name
18831 (Get_Pragma_Arg (Arg_Node), Name (Citem));
18832 exit;
18833 end if;
18834
18835 Next (Citem);
18836 end loop;
18837
18838 if Citem = N then
18839 Error_Pragma_Arg
18840 ("argument of pragma% is not withed unit", Arg_Node);
18841 end if;
18842
18843 Next (Arg_Node);
18844 end loop;
18845
18846 -- Case of not in list of context items
18847
18848 else
18849 Arg_Node := Arg1;
18850 while Present (Arg_Node) loop
18851 Check_No_Identifier (Arg_Node);
18852
18853 -- Note: the analyze call done by Check_Arg_Is_Local_Name
18854 -- will in fact generate reference, so that the entity will
18855 -- have a reference, which will inhibit any warnings about
18856 -- it not being referenced, and also properly show up in the
18857 -- ali file as a reference. But this reference is recorded
18858 -- before the Has_Pragma_Unreferenced flag is set, so that
18859 -- no warning is generated for this reference.
18860
18861 Check_Arg_Is_Local_Name (Arg_Node);
18862 Arg_Expr := Get_Pragma_Arg (Arg_Node);
18863
18864 if Is_Entity_Name (Arg_Expr) then
18865 Arg_Ent := Entity (Arg_Expr);
18866
18867 -- If the entity is overloaded, the pragma applies to the
18868 -- most recent overloading, as documented. In this case,
18869 -- name resolution does not generate a reference, so it
18870 -- must be done here explicitly.
18871
18872 if Is_Overloaded (Arg_Expr) then
18873 Generate_Reference (Arg_Ent, N);
18874 end if;
18875
18876 Set_Has_Pragma_Unreferenced (Arg_Ent);
18877 end if;
18878
18879 Next (Arg_Node);
18880 end loop;
18881 end if;
18882 end Unreferenced;
18883
18884 --------------------------
18885 -- Unreferenced_Objects --
18886 --------------------------
18887
18888 -- pragma Unreferenced_Objects (local_Name {, local_Name});
18889
18890 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
18891 Arg_Node : Node_Id;
18892 Arg_Expr : Node_Id;
18893
18894 begin
18895 GNAT_Pragma;
18896 Check_At_Least_N_Arguments (1);
18897
18898 Arg_Node := Arg1;
18899 while Present (Arg_Node) loop
18900 Check_No_Identifier (Arg_Node);
18901 Check_Arg_Is_Local_Name (Arg_Node);
18902 Arg_Expr := Get_Pragma_Arg (Arg_Node);
18903
18904 if not Is_Entity_Name (Arg_Expr)
18905 or else not Is_Type (Entity (Arg_Expr))
18906 then
18907 Error_Pragma_Arg
18908 ("argument for pragma% must be type or subtype", Arg_Node);
18909 end if;
18910
18911 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
18912 Next (Arg_Node);
18913 end loop;
18914 end Unreferenced_Objects;
18915
18916 ------------------------------
18917 -- Unreserve_All_Interrupts --
18918 ------------------------------
18919
18920 -- pragma Unreserve_All_Interrupts;
18921
18922 when Pragma_Unreserve_All_Interrupts =>
18923 GNAT_Pragma;
18924 Check_Arg_Count (0);
18925
18926 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
18927 Unreserve_All_Interrupts := True;
18928 end if;
18929
18930 ----------------
18931 -- Unsuppress --
18932 ----------------
18933
18934 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
18935
18936 when Pragma_Unsuppress =>
18937 Ada_2005_Pragma;
18938 Process_Suppress_Unsuppress (False);
18939
18940 -------------------
18941 -- Use_VADS_Size --
18942 -------------------
18943
18944 -- pragma Use_VADS_Size;
18945
18946 when Pragma_Use_VADS_Size =>
18947 GNAT_Pragma;
18948 Check_Arg_Count (0);
18949 Check_Valid_Configuration_Pragma;
18950 Use_VADS_Size := True;
18951
18952 ---------------------
18953 -- Validity_Checks --
18954 ---------------------
18955
18956 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
18957
18958 when Pragma_Validity_Checks => Validity_Checks : declare
18959 A : constant Node_Id := Get_Pragma_Arg (Arg1);
18960 S : String_Id;
18961 C : Char_Code;
18962
18963 begin
18964 GNAT_Pragma;
18965 Check_Arg_Count (1);
18966 Check_No_Identifiers;
18967
18968 if Nkind (A) = N_String_Literal then
18969 S := Strval (A);
18970
18971 declare
18972 Slen : constant Natural := Natural (String_Length (S));
18973 Options : String (1 .. Slen);
18974 J : Natural;
18975
18976 begin
18977 J := 1;
18978 loop
18979 C := Get_String_Char (S, Int (J));
18980 exit when not In_Character_Range (C);
18981 Options (J) := Get_Character (C);
18982
18983 if J = Slen then
18984 Set_Validity_Check_Options (Options);
18985 exit;
18986 else
18987 J := J + 1;
18988 end if;
18989 end loop;
18990 end;
18991
18992 elsif Nkind (A) = N_Identifier then
18993 if Chars (A) = Name_All_Checks then
18994 Set_Validity_Check_Options ("a");
18995 elsif Chars (A) = Name_On then
18996 Validity_Checks_On := True;
18997 elsif Chars (A) = Name_Off then
18998 Validity_Checks_On := False;
18999 end if;
19000 end if;
19001 end Validity_Checks;
19002
19003 --------------
19004 -- Volatile --
19005 --------------
19006
19007 -- pragma Volatile (LOCAL_NAME);
19008
19009 when Pragma_Volatile =>
19010 Process_Atomic_Shared_Volatile;
19011
19012 -------------------------
19013 -- Volatile_Components --
19014 -------------------------
19015
19016 -- pragma Volatile_Components (array_LOCAL_NAME);
19017
19018 -- Volatile is handled by the same circuit as Atomic_Components
19019
19020 --------------
19021 -- Warnings --
19022 --------------
19023
19024 -- pragma Warnings (On | Off [,REASON]);
19025 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
19026 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
19027 -- pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
19028
19029 -- REASON ::= Reason => Static_String_Expression
19030
19031 when Pragma_Warnings => Warnings : begin
19032 GNAT_Pragma;
19033 Check_At_Least_N_Arguments (1);
19034
19035 -- See if last argument is labeled Reason. If so, make sure we
19036 -- have a static string expression, but otherwise just ignore
19037 -- the REASON argument by decreasing Num_Args by 1 (all the
19038 -- remaining tests look only at the first Num_Args arguments).
19039
19040 declare
19041 Last_Arg : constant Node_Id :=
19042 Last (Pragma_Argument_Associations (N));
19043 begin
19044 if Nkind (Last_Arg) = N_Pragma_Argument_Association
19045 and then Chars (Last_Arg) = Name_Reason
19046 then
19047 Check_Arg_Is_Static_Expression (Last_Arg, Standard_String);
19048 Arg_Count := Arg_Count - 1;
19049
19050 -- Not allowed in compiler units (bootstrap issues)
19051
19052 Check_Compiler_Unit (N);
19053 end if;
19054 end;
19055
19056 -- Now proceed with REASON taken care of and eliminated
19057
19058 Check_No_Identifiers;
19059
19060 -- If debug flag -gnatd.i is set, pragma is ignored
19061
19062 if Debug_Flag_Dot_I then
19063 return;
19064 end if;
19065
19066 -- Process various forms of the pragma
19067
19068 declare
19069 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
19070
19071 begin
19072 -- One argument case
19073
19074 if Arg_Count = 1 then
19075
19076 -- On/Off one argument case was processed by parser
19077
19078 if Nkind (Argx) = N_Identifier
19079 and then Nam_In (Chars (Argx), Name_On, Name_Off)
19080 then
19081 null;
19082
19083 -- One argument case must be ON/OFF or static string expr
19084
19085 elsif not Is_Static_String_Expression (Arg1) then
19086 Error_Pragma_Arg
19087 ("argument of pragma% must be On/Off or static string "
19088 & "expression", Arg1);
19089
19090 -- One argument string expression case
19091
19092 else
19093 declare
19094 Lit : constant Node_Id := Expr_Value_S (Argx);
19095 Str : constant String_Id := Strval (Lit);
19096 Len : constant Nat := String_Length (Str);
19097 C : Char_Code;
19098 J : Nat;
19099 OK : Boolean;
19100 Chr : Character;
19101
19102 begin
19103 J := 1;
19104 while J <= Len loop
19105 C := Get_String_Char (Str, J);
19106 OK := In_Character_Range (C);
19107
19108 if OK then
19109 Chr := Get_Character (C);
19110
19111 -- Dash case: only -Wxxx is accepted
19112
19113 if J = 1
19114 and then J < Len
19115 and then Chr = '-'
19116 then
19117 J := J + 1;
19118 C := Get_String_Char (Str, J);
19119 Chr := Get_Character (C);
19120 exit when Chr = 'W';
19121 OK := False;
19122
19123 -- Dot case
19124
19125 elsif J < Len and then Chr = '.' then
19126 J := J + 1;
19127 C := Get_String_Char (Str, J);
19128 Chr := Get_Character (C);
19129
19130 if not Set_Dot_Warning_Switch (Chr) then
19131 Error_Pragma_Arg
19132 ("invalid warning switch character "
19133 & '.' & Chr, Arg1);
19134 end if;
19135
19136 -- Non-Dot case
19137
19138 else
19139 OK := Set_Warning_Switch (Chr);
19140 end if;
19141 end if;
19142
19143 if not OK then
19144 Error_Pragma_Arg
19145 ("invalid warning switch character " & Chr,
19146 Arg1);
19147 end if;
19148
19149 J := J + 1;
19150 end loop;
19151 end;
19152 end if;
19153
19154 -- Two or more arguments (must be two)
19155
19156 else
19157 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19158 Check_At_Most_N_Arguments (2);
19159
19160 declare
19161 E_Id : Node_Id;
19162 E : Entity_Id;
19163 Err : Boolean;
19164
19165 begin
19166 E_Id := Get_Pragma_Arg (Arg2);
19167 Analyze (E_Id);
19168
19169 -- In the expansion of an inlined body, a reference to
19170 -- the formal may be wrapped in a conversion if the
19171 -- actual is a conversion. Retrieve the real entity name.
19172
19173 if (In_Instance_Body or In_Inlined_Body)
19174 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
19175 then
19176 E_Id := Expression (E_Id);
19177 end if;
19178
19179 -- Entity name case
19180
19181 if Is_Entity_Name (E_Id) then
19182 E := Entity (E_Id);
19183
19184 if E = Any_Id then
19185 return;
19186 else
19187 loop
19188 Set_Warnings_Off
19189 (E, (Chars (Get_Pragma_Arg (Arg1)) =
19190 Name_Off));
19191
19192 -- For OFF case, make entry in warnings off
19193 -- pragma table for later processing. But we do
19194 -- not do that within an instance, since these
19195 -- warnings are about what is needed in the
19196 -- template, not an instance of it.
19197
19198 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
19199 and then Warn_On_Warnings_Off
19200 and then not In_Instance
19201 then
19202 Warnings_Off_Pragmas.Append ((N, E));
19203 end if;
19204
19205 if Is_Enumeration_Type (E) then
19206 declare
19207 Lit : Entity_Id;
19208 begin
19209 Lit := First_Literal (E);
19210 while Present (Lit) loop
19211 Set_Warnings_Off (Lit);
19212 Next_Literal (Lit);
19213 end loop;
19214 end;
19215 end if;
19216
19217 exit when No (Homonym (E));
19218 E := Homonym (E);
19219 end loop;
19220 end if;
19221
19222 -- Error if not entity or static string literal case
19223
19224 elsif not Is_Static_String_Expression (Arg2) then
19225 Error_Pragma_Arg
19226 ("second argument of pragma% must be entity name "
19227 & "or static string expression", Arg2);
19228
19229 -- String literal case
19230
19231 else
19232 String_To_Name_Buffer
19233 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
19234
19235 -- Note on configuration pragma case: If this is a
19236 -- configuration pragma, then for an OFF pragma, we
19237 -- just set Config True in the call, which is all
19238 -- that needs to be done. For the case of ON, this
19239 -- is normally an error, unless it is canceling the
19240 -- effect of a previous OFF pragma in the same file.
19241 -- In any other case, an error will be signalled (ON
19242 -- with no matching OFF).
19243
19244 -- Note: We set Used if we are inside a generic to
19245 -- disable the test that the non-config case actually
19246 -- cancels a warning. That's because we can't be sure
19247 -- there isn't an instantiation in some other unit
19248 -- where a warning is suppressed.
19249
19250 -- We could do a little better here by checking if the
19251 -- generic unit we are inside is public, but for now
19252 -- we don't bother with that refinement.
19253
19254 if Chars (Argx) = Name_Off then
19255 Set_Specific_Warning_Off
19256 (Loc, Name_Buffer (1 .. Name_Len),
19257 Config => Is_Configuration_Pragma,
19258 Used => Inside_A_Generic or else In_Instance);
19259
19260 elsif Chars (Argx) = Name_On then
19261 Set_Specific_Warning_On
19262 (Loc, Name_Buffer (1 .. Name_Len), Err);
19263
19264 if Err then
19265 Error_Msg
19266 ("??pragma Warnings On with no matching "
19267 & "Warnings Off", Loc);
19268 end if;
19269 end if;
19270 end if;
19271 end;
19272 end if;
19273 end;
19274 end Warnings;
19275
19276 -------------------
19277 -- Weak_External --
19278 -------------------
19279
19280 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
19281
19282 when Pragma_Weak_External => Weak_External : declare
19283 Ent : Entity_Id;
19284
19285 begin
19286 GNAT_Pragma;
19287 Check_Arg_Count (1);
19288 Check_Optional_Identifier (Arg1, Name_Entity);
19289 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19290 Ent := Entity (Get_Pragma_Arg (Arg1));
19291
19292 if Rep_Item_Too_Early (Ent, N) then
19293 return;
19294 else
19295 Ent := Underlying_Type (Ent);
19296 end if;
19297
19298 -- The only processing required is to link this item on to the
19299 -- list of rep items for the given entity. This is accomplished
19300 -- by the call to Rep_Item_Too_Late (when no error is detected
19301 -- and False is returned).
19302
19303 if Rep_Item_Too_Late (Ent, N) then
19304 return;
19305 else
19306 Set_Has_Gigi_Rep_Item (Ent);
19307 end if;
19308 end Weak_External;
19309
19310 -----------------------------
19311 -- Wide_Character_Encoding --
19312 -----------------------------
19313
19314 -- pragma Wide_Character_Encoding (IDENTIFIER);
19315
19316 when Pragma_Wide_Character_Encoding =>
19317 GNAT_Pragma;
19318
19319 -- Nothing to do, handled in parser. Note that we do not enforce
19320 -- configuration pragma placement, this pragma can appear at any
19321 -- place in the source, allowing mixed encodings within a single
19322 -- source program.
19323
19324 null;
19325
19326 --------------------
19327 -- Unknown_Pragma --
19328 --------------------
19329
19330 -- Should be impossible, since the case of an unknown pragma is
19331 -- separately processed before the case statement is entered.
19332
19333 when Unknown_Pragma =>
19334 raise Program_Error;
19335 end case;
19336
19337 -- AI05-0144: detect dangerous order dependence. Disabled for now,
19338 -- until AI is formally approved.
19339
19340 -- Check_Order_Dependence;
19341
19342 exception
19343 when Pragma_Exit => null;
19344 end Analyze_Pragma;
19345
19346 ---------------------------------------------
19347 -- Analyze_Pre_Post_Condition_In_Decl_Part --
19348 ---------------------------------------------
19349
19350 procedure Analyze_Pre_Post_Condition_In_Decl_Part
19351 (Prag : Node_Id;
19352 Subp_Id : Entity_Id)
19353 is
19354 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (Prag));
19355 Nam : constant Name_Id := Original_Aspect_Name (Prag);
19356 Expr : Node_Id;
19357
19358 Restore_Scope : Boolean := False;
19359 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
19360
19361 begin
19362 -- Ensure that the subprogram and its formals are visible when analyzing
19363 -- the expression of the pragma.
19364
19365 if not In_Open_Scopes (Subp_Id) then
19366 Restore_Scope := True;
19367 Push_Scope (Subp_Id);
19368 Install_Formals (Subp_Id);
19369 end if;
19370
19371 -- Preanalyze the boolean expression, we treat this as a spec expression
19372 -- (i.e. similar to a default expression).
19373
19374 Expr := Get_Pragma_Arg (Arg1);
19375
19376 -- In ASIS mode, for a pragma generated from a source aspect, analyze
19377 -- the original aspect expression, which is shared with the generated
19378 -- pragma.
19379
19380 if ASIS_Mode and then Present (Corresponding_Aspect (Prag)) then
19381 Expr := Expression (Corresponding_Aspect (Prag));
19382 end if;
19383
19384 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
19385
19386 -- For a class-wide condition, a reference to a controlling formal must
19387 -- be interpreted as having the class-wide type (or an access to such)
19388 -- so that the inherited condition can be properly applied to any
19389 -- overriding operation (see ARM12 6.6.1 (7)).
19390
19391 if Class_Present (Prag) then
19392 Class_Wide_Condition : declare
19393 T : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
19394
19395 ACW : Entity_Id := Empty;
19396 -- Access to T'class, created if there is a controlling formal
19397 -- that is an access parameter.
19398
19399 function Get_ACW return Entity_Id;
19400 -- If the expression has a reference to an controlling access
19401 -- parameter, create an access to T'class for the necessary
19402 -- conversions if one does not exist.
19403
19404 function Process (N : Node_Id) return Traverse_Result;
19405 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
19406 -- aspect for a primitive subprogram of a tagged type T, a name
19407 -- that denotes a formal parameter of type T is interpreted as
19408 -- having type T'Class. Similarly, a name that denotes a formal
19409 -- accessparameter of type access-to-T is interpreted as having
19410 -- type access-to-T'Class. This ensures the expression is well-
19411 -- defined for a primitive subprogram of a type descended from T.
19412 -- Note that this replacement is not done for selector names in
19413 -- parameter associations. These carry an entity for reference
19414 -- purposes, but semantically they are just identifiers.
19415
19416 -------------
19417 -- Get_ACW --
19418 -------------
19419
19420 function Get_ACW return Entity_Id is
19421 Loc : constant Source_Ptr := Sloc (Prag);
19422 Decl : Node_Id;
19423
19424 begin
19425 if No (ACW) then
19426 Decl :=
19427 Make_Full_Type_Declaration (Loc,
19428 Defining_Identifier => Make_Temporary (Loc, 'T'),
19429 Type_Definition =>
19430 Make_Access_To_Object_Definition (Loc,
19431 Subtype_Indication =>
19432 New_Occurrence_Of (Class_Wide_Type (T), Loc),
19433 All_Present => True));
19434
19435 Insert_Before (Unit_Declaration_Node (Subp_Id), Decl);
19436 Analyze (Decl);
19437 ACW := Defining_Identifier (Decl);
19438 Freeze_Before (Unit_Declaration_Node (Subp_Id), ACW);
19439 end if;
19440
19441 return ACW;
19442 end Get_ACW;
19443
19444 -------------
19445 -- Process --
19446 -------------
19447
19448 function Process (N : Node_Id) return Traverse_Result is
19449 Loc : constant Source_Ptr := Sloc (N);
19450 Typ : Entity_Id;
19451
19452 begin
19453 if Is_Entity_Name (N)
19454 and then Present (Entity (N))
19455 and then Is_Formal (Entity (N))
19456 and then Nkind (Parent (N)) /= N_Type_Conversion
19457 and then
19458 (Nkind (Parent (N)) /= N_Parameter_Association
19459 or else N /= Selector_Name (Parent (N)))
19460 then
19461 if Etype (Entity (N)) = T then
19462 Typ := Class_Wide_Type (T);
19463
19464 elsif Is_Access_Type (Etype (Entity (N)))
19465 and then Designated_Type (Etype (Entity (N))) = T
19466 then
19467 Typ := Get_ACW;
19468 else
19469 Typ := Empty;
19470 end if;
19471
19472 if Present (Typ) then
19473 Rewrite (N,
19474 Make_Type_Conversion (Loc,
19475 Subtype_Mark =>
19476 New_Occurrence_Of (Typ, Loc),
19477 Expression => New_Occurrence_Of (Entity (N), Loc)));
19478 Set_Etype (N, Typ);
19479 end if;
19480 end if;
19481
19482 return OK;
19483 end Process;
19484
19485 procedure Replace_Type is new Traverse_Proc (Process);
19486
19487 -- Start of processing for Class_Wide_Condition
19488
19489 begin
19490 if not Present (T) then
19491
19492 -- Pre'Class/Post'Class aspect cases
19493
19494 if From_Aspect_Specification (Prag) then
19495 if Nam = Name_uPre then
19496 Error_Msg_Name_1 := Name_Pre;
19497 else
19498 Error_Msg_Name_1 := Name_Post;
19499 end if;
19500
19501 Error_Msg_Name_2 := Name_Class;
19502
19503 Error_Msg_N
19504 ("aspect `%''%` can only be specified for a primitive "
19505 & "operation of a tagged type",
19506 Corresponding_Aspect (Prag));
19507
19508 -- Pre_Class, Post_Class pragma cases
19509
19510 else
19511 if Nam = Name_uPre then
19512 Error_Msg_Name_1 := Name_Pre_Class;
19513 else
19514 Error_Msg_Name_1 := Name_Post_Class;
19515 end if;
19516
19517 Error_Msg_N
19518 ("pragma% can only be specified for a primitive "
19519 & "operation of a tagged type",
19520 Corresponding_Aspect (Prag));
19521 end if;
19522 end if;
19523
19524 Replace_Type (Get_Pragma_Arg (Arg1));
19525 end Class_Wide_Condition;
19526 end if;
19527
19528 -- Remove the subprogram from the scope stack now that the pre-analysis
19529 -- of the precondition/postcondition is done.
19530
19531 if Restore_Scope then
19532 End_Scope;
19533 end if;
19534 end Analyze_Pre_Post_Condition_In_Decl_Part;
19535
19536 ------------------------------------------
19537 -- Analyze_Refined_Depends_In_Decl_Part --
19538 ------------------------------------------
19539
19540 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
19541 Dependencies : List_Id := No_List;
19542 Depends : Node_Id;
19543 -- The corresponding Depends pragma along with its clauses
19544
19545 Global : Node_Id := Empty;
19546 -- The corresponding Refined_Global pragma (if any)
19547
19548 Out_Items : Elist_Id := No_Elist;
19549 -- All output items as defined in pragma Refined_Global (if any)
19550
19551 Refinements : List_Id := No_List;
19552 -- The clauses of pragma Refined_Depends
19553
19554 Spec_Id : Entity_Id;
19555 -- The entity of the subprogram subject to pragma Refined_Depends
19556
19557 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
19558 -- Verify the legality of a single clause
19559
19560 procedure Report_Extra_Clauses;
19561 -- Emit an error for each extra clause the appears in Refined_Depends
19562
19563 -----------------------------
19564 -- Check_Dependency_Clause --
19565 -----------------------------
19566
19567 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
19568 function Inputs_Match
19569 (Ref_Clause : Node_Id;
19570 Do_Checks : Boolean) return Boolean;
19571 -- Determine whether the inputs of clause Dep_Clause match those of
19572 -- clause Ref_Clause. If flag Do_Checks is set, the routine reports
19573 -- missed or extra input items.
19574
19575 function Output_Constituents (State_Id : Entity_Id) return Elist_Id;
19576 -- Given a state denoted by State_Id, return a list of all output
19577 -- constituents that may be referenced within Refined_Depends. The
19578 -- contents of the list depend on whethe Refined_Global is present.
19579
19580 procedure Report_Unused_Constituents (Constits : Elist_Id);
19581 -- Emit errors for all constituents found in list Constits
19582
19583 ------------------
19584 -- Inputs_Match --
19585 ------------------
19586
19587 function Inputs_Match
19588 (Ref_Clause : Node_Id;
19589 Do_Checks : Boolean) return Boolean
19590 is
19591 Ref_Inputs : List_Id;
19592 -- The input list of the refinement clause
19593
19594 function Is_Matching_Input (Dep_Input : Node_Id) return Boolean;
19595 -- Determine whether input Dep_Input matches one of the inputs of
19596 -- clause Ref_Clause.
19597
19598 procedure Report_Extra_Inputs;
19599 -- Emit errors for all extra inputs that appear in Ref_Clause
19600
19601 -----------------------
19602 -- Is_Matching_Input --
19603 -----------------------
19604
19605 function Is_Matching_Input (Dep_Input : Node_Id) return Boolean is
19606 procedure Match_Error (Msg : String; N : Node_Id);
19607 -- Emit a matching error if flag Do_Checks is set
19608
19609 -----------------
19610 -- Match_Error --
19611 -----------------
19612
19613 procedure Match_Error (Msg : String; N : Node_Id) is
19614 begin
19615 if Do_Checks then
19616 Error_Msg_N (Msg, N);
19617 end if;
19618 end Match_Error;
19619
19620 -- Local variables
19621
19622 Dep_Id : Node_Id;
19623 Next_Ref_Input : Node_Id;
19624 Ref_Id : Entity_Id;
19625 Ref_Input : Node_Id;
19626
19627 Has_Constituent : Boolean := False;
19628 -- Flag set when the refinement input list contains at least
19629 -- one constituent of the state denoted by Dep_Id.
19630
19631 Has_Null_State : Boolean := False;
19632 -- Flag set when the dependency input is a state with a null
19633 -- refinement.
19634
19635 Has_Refined_State : Boolean := False;
19636 -- Flag set when the dependency input is a state with visible
19637 -- refinement.
19638
19639 -- Start of processing for Is_Matching_Input
19640
19641 begin
19642 -- Match a null input with another null input
19643
19644 if Nkind (Dep_Input) = N_Null then
19645 if Nkind (Expression (Ref_Clause)) = N_Null then
19646 return True;
19647 else
19648 Match_Error
19649 ("null input cannot be matched in corresponding "
19650 & "refinement clause", Dep_Input);
19651 end if;
19652
19653 -- The remaining cases are formal parameters, variables and
19654 -- states.
19655
19656 else
19657 Dep_Id := Entity_Of (Dep_Input);
19658
19659 -- Inspect all inputs of the refinement clause and attempt
19660 -- to match against the inputs of the dependance clause.
19661
19662 Ref_Input := First (Ref_Inputs);
19663 while Present (Ref_Input) loop
19664
19665 -- Store the next input now because a match will remove
19666 -- it from the list.
19667
19668 Next_Ref_Input := Next (Ref_Input);
19669
19670 if Ekind (Dep_Id) = E_Abstract_State then
19671
19672 -- A state with a null refinement matches either a
19673 -- null input list or nothing at all (no input):
19674
19675 -- Refined_State (State => null)
19676
19677 -- No input
19678
19679 -- Depends => (<output> => (State, Input))
19680 -- Refined_Depends => (<output> => Input -- OK
19681
19682 -- Null input list
19683
19684 -- Depends => (<output> => State)
19685 -- Refined_Depends => (<output> => null) -- OK
19686
19687 if Has_Null_Refinement (Dep_Id) then
19688 Has_Null_State := True;
19689
19690 -- Remove the matching null from the pool of
19691 -- candidates.
19692
19693 if Nkind (Ref_Input) = N_Null then
19694 Remove (Ref_Input);
19695 end if;
19696
19697 return True;
19698
19699 -- The state has a non-null refinement in which case
19700 -- remove all the matching constituents of the state:
19701
19702 -- Refined_State => (State => (C1, C2))
19703 -- Depends => (<output> => State)
19704 -- Refined_Depends => (<output> => (C1, C2))
19705
19706 elsif Has_Non_Null_Refinement (Dep_Id) then
19707 Has_Refined_State := True;
19708
19709 if Is_Entity_Name (Ref_Input) then
19710 Ref_Id := Entity_Of (Ref_Input);
19711
19712 -- The input of the refinement clause is a valid
19713 -- constituent of the state. Remove the input
19714 -- from the pool of candidates. Note that the
19715 -- search continues because the state may be
19716 -- represented by multiple constituents.
19717
19718 if Ekind_In (Ref_Id, E_Abstract_State,
19719 E_Variable)
19720 and then Present (Refined_State (Ref_Id))
19721 and then Refined_State (Ref_Id) = Dep_Id
19722 then
19723 Has_Constituent := True;
19724 Remove (Ref_Input);
19725 end if;
19726 end if;
19727 end if;
19728
19729 -- Formal parameters and variables are matched on
19730 -- entities. If this is the case, remove the input from
19731 -- the candidate list.
19732
19733 elsif Is_Entity_Name (Ref_Input)
19734 and then Entity_Of (Ref_Input) = Dep_Id
19735 then
19736 Remove (Ref_Input);
19737 return True;
19738 end if;
19739
19740 Ref_Input := Next_Ref_Input;
19741 end loop;
19742 end if;
19743
19744 -- A state with visible refinement was matched against one or
19745 -- more of its constituents.
19746
19747 if Has_Constituent then
19748 return True;
19749
19750 -- A state with a null refinement matched null or nothing
19751
19752 elsif Has_Null_State then
19753 return True;
19754
19755 -- The input of a dependence clause does not have a matching
19756 -- input in the refinement clause, emit an error.
19757
19758 else
19759 Match_Error
19760 ("input cannot be matched in corresponding refinement "
19761 & "clause", Dep_Input);
19762
19763 if Has_Refined_State then
19764 Match_Error
19765 ("\check the use of constituents in dependence "
19766 & "refinement", Dep_Input);
19767 end if;
19768
19769 return False;
19770 end if;
19771 end Is_Matching_Input;
19772
19773 -------------------------
19774 -- Report_Extra_Inputs --
19775 -------------------------
19776
19777 procedure Report_Extra_Inputs is
19778 Input : Node_Id;
19779
19780 begin
19781 if Present (Ref_Inputs) and then Do_Checks then
19782 Input := First (Ref_Inputs);
19783 while Present (Input) loop
19784 Error_Msg_N
19785 ("unmatched or extra input in refinement clause",
19786 Input);
19787
19788 Next (Input);
19789 end loop;
19790 end if;
19791 end Report_Extra_Inputs;
19792
19793 -- Local variables
19794
19795 Dep_Inputs : constant Node_Id := Expression (Dep_Clause);
19796 Inputs : constant Node_Id := Expression (Ref_Clause);
19797 Dep_Input : Node_Id;
19798 Result : Boolean;
19799
19800 -- Start of processing for Inputs_Match
19801
19802 begin
19803 -- Construct a list of all refinement inputs. Note that the input
19804 -- list is copied because the algorithm modifies its contents and
19805 -- this should not be visible in Refined_Depends.
19806
19807 if Nkind (Inputs) = N_Aggregate then
19808 Ref_Inputs := New_Copy_List (Expressions (Inputs));
19809 else
19810 Ref_Inputs := New_List (Inputs);
19811 end if;
19812
19813 -- Depending on whether the original dependency clause mentions
19814 -- states with visible refinement, the corresponding refinement
19815 -- clause may differ greatly in structure and contents:
19816
19817 -- State with null refinement
19818
19819 -- Refined_State => (State => null)
19820 -- Depends => (<output> => State)
19821 -- Refined_Depends => (<output> => null)
19822
19823 -- Depends => (<output> => (State, Input))
19824 -- Refined_Depends => (<output> => Input)
19825
19826 -- Depends => (<output> => (Input_1, State, Input_2))
19827 -- Refined_Depends => (<output> => (Input_1, Input_2))
19828
19829 -- State with non-null refinement
19830
19831 -- Refined_State => (State_1 => (C1, C2))
19832 -- Depends => (<output> => State)
19833 -- Refined_Depends => (<output> => C1)
19834 -- or
19835 -- Refined_Depends => (<output> => (C1, C2))
19836
19837 if Nkind (Dep_Inputs) = N_Aggregate then
19838 Dep_Input := First (Expressions (Dep_Inputs));
19839 while Present (Dep_Input) loop
19840 if not Is_Matching_Input (Dep_Input) then
19841 Result := False;
19842 end if;
19843
19844 Next (Dep_Input);
19845 end loop;
19846
19847 Result := True;
19848
19849 -- Solitary input
19850
19851 else
19852 Result := Is_Matching_Input (Dep_Inputs);
19853 end if;
19854
19855 Report_Extra_Inputs;
19856 return Result;
19857 end Inputs_Match;
19858
19859 -------------------------
19860 -- Output_Constituents --
19861 -------------------------
19862
19863 function Output_Constituents (State_Id : Entity_Id) return Elist_Id is
19864 Item_Elmt : Elmt_Id;
19865 Item_Id : Entity_Id;
19866 Result : Elist_Id := No_Elist;
19867
19868 begin
19869 -- The related subprogram is subject to pragma Refined_Global. All
19870 -- usable output constituents are defined in its output item list.
19871
19872 if Present (Global) then
19873 Item_Elmt := First_Elmt (Out_Items);
19874 while Present (Item_Elmt) loop
19875 Item_Id := Node (Item_Elmt);
19876
19877 -- The constituent is part of the refinement of the input
19878 -- state, add it to the result list.
19879
19880 if Refined_State (Item_Id) = State_Id then
19881 Add_Item (Item_Id, Result);
19882 end if;
19883
19884 Next_Elmt (Item_Elmt);
19885 end loop;
19886
19887 -- When pragma Refined_Global is not present, the usable output
19888 -- constituents are all the constituents as defined in pragma
19889 -- Refined_State. Note that the elements are copied because the
19890 -- algorithm trims the list and this should not be reflected in
19891 -- the state itself.
19892
19893 else
19894 Result := New_Copy_Elist (Refinement_Constituents (State_Id));
19895 end if;
19896
19897 return Result;
19898 end Output_Constituents;
19899
19900 --------------------------------
19901 -- Report_Unused_Constituents --
19902 --------------------------------
19903
19904 procedure Report_Unused_Constituents (Constits : Elist_Id) is
19905 Constit : Entity_Id;
19906 Elmt : Elmt_Id;
19907 Posted : Boolean := False;
19908
19909 begin
19910 if Present (Constits) then
19911 Elmt := First_Elmt (Constits);
19912 while Present (Elmt) loop
19913 Constit := Node (Elmt);
19914
19915 -- A constituent must always refine a state
19916
19917 pragma Assert (Present (Refined_State (Constit)));
19918
19919 -- When a state has a visible refinement and its mode is
19920 -- Output_Only, all its constituents must be used as
19921 -- outputs.
19922
19923 if not Posted then
19924 Posted := True;
19925 Error_Msg_NE
19926 ("output only state & must be replaced by all its "
19927 & "constituents in dependence refinement",
19928 N, Refined_State (Constit));
19929 end if;
19930
19931 Error_Msg_NE
19932 ("\ constituent & is missing in output list", N, Constit);
19933
19934 Next_Elmt (Elmt);
19935 end loop;
19936 end if;
19937 end Report_Unused_Constituents;
19938
19939 -- Local variables
19940
19941 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
19942 Dep_Id : Entity_Id;
19943 Matching_Clause : Node_Id := Empty;
19944 Next_Ref_Clause : Node_Id;
19945 Ref_Clause : Node_Id;
19946 Ref_Id : Entity_Id;
19947 Ref_Output : Node_Id;
19948
19949 Has_Constituent : Boolean := False;
19950 -- Flag set when the refinement output list contains at least one
19951 -- constituent of the state denoted by Dep_Id.
19952
19953 Has_Null_State : Boolean := False;
19954 -- Flag set when the output of clause Dep_Clause is a state with a
19955 -- null refinement.
19956
19957 Has_Refined_State : Boolean := False;
19958 -- Flag set when the output of clause Dep_Clause is a state with
19959 -- visible refinement.
19960
19961 Out_Constits : Elist_Id := No_Elist;
19962 -- This list contains the entities all output constituents of state
19963 -- Dep_Id as defined in pragma Refined_State.
19964
19965 -- Start of processing for Check_Dependency_Clause
19966
19967 begin
19968 -- The analysis of pragma Depends should produce normalized clauses
19969 -- with exactly one output. This is important because output items
19970 -- are unique in the whole dependance relation and can be used as
19971 -- keys.
19972
19973 pragma Assert (No (Next (Dep_Output)));
19974
19975 -- Inspect all clauses of Refined_Depends and attempt to match the
19976 -- output of Dep_Clause against an output from the refinement clauses
19977 -- set.
19978
19979 Ref_Clause := First (Refinements);
19980 while Present (Ref_Clause) loop
19981 Matching_Clause := Empty;
19982
19983 -- Store the next clause now because a match will trim the list of
19984 -- refinement clauses and this side effect should not be visible
19985 -- in pragma Refined_Depends.
19986
19987 Next_Ref_Clause := Next (Ref_Clause);
19988
19989 -- The analysis of pragma Refined_Depends should produce
19990 -- normalized clauses with exactly one output.
19991
19992 Ref_Output := First (Choices (Ref_Clause));
19993 pragma Assert (No (Next (Ref_Output)));
19994
19995 -- Two null output lists match if their inputs match
19996
19997 if Nkind (Dep_Output) = N_Null
19998 and then Nkind (Ref_Output) = N_Null
19999 then
20000 Matching_Clause := Ref_Clause;
20001 exit;
20002
20003 -- Two function 'Result attributes match if their inputs match.
20004 -- Note that there is no need to compare the two prefixes because
20005 -- the attributes cannot denote anything but the related function.
20006
20007 elsif Is_Attribute_Result (Dep_Output)
20008 and then Is_Attribute_Result (Ref_Output)
20009 then
20010 Matching_Clause := Ref_Clause;
20011 exit;
20012
20013 -- The remaining cases are formal parameters, variables and states
20014
20015 elsif Is_Entity_Name (Dep_Output) then
20016 Dep_Id := Entity_Of (Dep_Output);
20017
20018 if Ekind (Dep_Id) = E_Abstract_State then
20019
20020 -- A state with a null refinement matches either a null
20021 -- output list or nothing at all (no clause):
20022
20023 -- Refined_State => (State => null)
20024
20025 -- No clause
20026
20027 -- Depends => (State => null)
20028 -- Refined_Depends => null -- OK
20029
20030 -- Null output list
20031
20032 -- Depends => (State => <input>)
20033 -- Refined_Depends => (null => <input>) -- OK
20034
20035 if Has_Null_Refinement (Dep_Id) then
20036 Has_Null_State := True;
20037
20038 -- When a state with null refinement matches a null
20039 -- output, compare their inputs.
20040
20041 if Nkind (Ref_Output) = N_Null then
20042 Matching_Clause := Ref_Clause;
20043 end if;
20044
20045 exit;
20046
20047 -- The state has a non-null refinement in which case the
20048 -- match is based on constituents and inputs. A state with
20049 -- multiple output constituents may match multiple clauses:
20050
20051 -- Refined_State => (State => (C1, C2))
20052 -- Depends => (State => <input>)
20053 -- Refined_Depends => ((C1, C2) => <input>)
20054
20055 -- When normalized, the above becomes:
20056
20057 -- Refined_Depends => (C1 => <input>,
20058 -- C2 => <input>)
20059
20060 elsif Has_Non_Null_Refinement (Dep_Id) then
20061 Has_Refined_State := True;
20062
20063 -- Store the entities of all output constituents of an
20064 -- Output_Only state with visible refinement.
20065
20066 if No (Out_Constits)
20067 and then Is_Output_Only_State (Dep_Id)
20068 then
20069 Out_Constits := Output_Constituents (Dep_Id);
20070 end if;
20071
20072 if Is_Entity_Name (Ref_Output) then
20073 Ref_Id := Entity_Of (Ref_Output);
20074
20075 -- The output of the refinement clause is a valid
20076 -- constituent of the state. Remove the clause from
20077 -- the pool of candidates if both input lists match.
20078 -- Note that the search continues because one clause
20079 -- may have been normalized into multiple clauses as
20080 -- per the example above.
20081
20082 if Ekind_In (Ref_Id, E_Abstract_State, E_Variable)
20083 and then Present (Refined_State (Ref_Id))
20084 and then Refined_State (Ref_Id) = Dep_Id
20085 and then Inputs_Match
20086 (Ref_Clause, Do_Checks => False)
20087 then
20088 Has_Constituent := True;
20089 Remove (Ref_Clause);
20090
20091 -- The matching constituent may act as an output
20092 -- for an Output_Only state. Remove the item from
20093 -- the available output constituents.
20094
20095 Remove (Out_Constits, Ref_Id);
20096 end if;
20097 end if;
20098 end if;
20099
20100 -- Formal parameters and variables match when their inputs
20101 -- match.
20102
20103 elsif Is_Entity_Name (Ref_Output)
20104 and then Entity_Of (Ref_Output) = Dep_Id
20105 then
20106 Matching_Clause := Ref_Clause;
20107 exit;
20108 end if;
20109 end if;
20110
20111 Ref_Clause := Next_Ref_Clause;
20112 end loop;
20113
20114 -- Handle the case where pragma Depends contains one or more clauses
20115 -- that only mention states with null refinements. In that case the
20116 -- corresponding pragma Refined_Depends may have a null relation.
20117
20118 -- Refined_State => (State => null)
20119 -- Depends => (State => null)
20120 -- Refined_Depends => null -- OK
20121
20122 if No (Refinements) and then Is_Entity_Name (Dep_Output) then
20123 Dep_Id := Entity_Of (Dep_Output);
20124
20125 if Ekind (Dep_Id) = E_Abstract_State
20126 and then Has_Null_Refinement (Dep_Id)
20127 then
20128 Has_Null_State := True;
20129 end if;
20130 end if;
20131
20132 -- The above search produced a match based on unique output. Ensure
20133 -- that the inputs match as well and if they do, remove the clause
20134 -- from the pool of candidates.
20135
20136 if Present (Matching_Clause) then
20137 if Inputs_Match (Matching_Clause, Do_Checks => True) then
20138 Remove (Matching_Clause);
20139 end if;
20140
20141 -- A state with a visible refinement was matched against one or
20142 -- more clauses containing appropriate constituents.
20143
20144 elsif Has_Constituent then
20145 null;
20146
20147 -- A state with a null refinement did not warrant a clause
20148
20149 elsif Has_Null_State then
20150 null;
20151
20152 -- The dependence relation of pragma Refined_Depends does not contain
20153 -- a matching clause, emit an error.
20154
20155 else
20156 Error_Msg_NE
20157 ("dependence clause of subprogram & has no matching refinement "
20158 & "in body", Ref_Clause, Spec_Id);
20159
20160 if Has_Refined_State then
20161 Error_Msg_N
20162 ("\check the use of constituents in dependence refinement",
20163 Ref_Clause);
20164 end if;
20165 end if;
20166
20167 -- Emit errors for all unused constituents of an Output_Only state
20168 -- with visible refinement.
20169
20170 Report_Unused_Constituents (Out_Constits);
20171 end Check_Dependency_Clause;
20172
20173 --------------------------
20174 -- Report_Extra_Clauses --
20175 --------------------------
20176
20177 procedure Report_Extra_Clauses is
20178 Clause : Node_Id;
20179
20180 begin
20181 if Present (Refinements) then
20182 Clause := First (Refinements);
20183 while Present (Clause) loop
20184 Error_Msg_N
20185 ("unmatched or extra clause in dependence refinement",
20186 Clause);
20187
20188 Next (Clause);
20189 end loop;
20190 end if;
20191 end Report_Extra_Clauses;
20192
20193 -- Local variables
20194
20195 Body_Decl : constant Node_Id := Parent (N);
20196 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
20197 Errors : constant Nat := Serious_Errors_Detected;
20198 Clause : Node_Id;
20199 Deps : Node_Id;
20200 Refs : Node_Id;
20201
20202 -- The following are dummy variables that capture unused output of
20203 -- routine Collect_Global_Items.
20204
20205 D1, D2 : Elist_Id := No_Elist;
20206 D3, D4, D5, D6 : Boolean;
20207
20208 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
20209
20210 begin
20211 Spec_Id := Corresponding_Spec (Body_Decl);
20212 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
20213
20214 -- The subprogram declarations lacks pragma Depends. This renders
20215 -- Refined_Depends useless as there is nothing to refine.
20216
20217 if No (Depends) then
20218 Error_Msg_NE
20219 ("useless refinement, subprogram & lacks dependence clauses",
20220 N, Spec_Id);
20221 return;
20222 end if;
20223
20224 Deps := Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
20225
20226 -- A null dependency relation renders the refinement useless because it
20227 -- cannot possibly mention abstract states with visible refinement. Note
20228 -- that the inverse is not true as states may be refined to null.
20229
20230 if Nkind (Deps) = N_Null then
20231 Error_Msg_NE
20232 ("useless refinement, subprogram & does not depend on abstract "
20233 & "state with visible refinement", N, Spec_Id);
20234 return;
20235 end if;
20236
20237 -- Multiple dependency clauses appear as component associations of an
20238 -- aggregate.
20239
20240 pragma Assert (Nkind (Deps) = N_Aggregate);
20241 Dependencies := Component_Associations (Deps);
20242
20243 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
20244 -- This ensures that the categorization of all refined dependency items
20245 -- is consistent with their role.
20246
20247 Analyze_Depends_In_Decl_Part (N);
20248 Refs := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
20249
20250 if Serious_Errors_Detected = Errors then
20251
20252 -- The related subprogram may be subject to pragma Refined_Global. If
20253 -- this is the case, gather all output items. These are needed when
20254 -- verifying the use of constituents that apply to output states with
20255 -- visible refinement.
20256
20257 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
20258
20259 if Present (Global) then
20260 Collect_Global_Items
20261 (Prag => Global,
20262 In_Items => D1,
20263 In_Out_Items => D2,
20264 Out_Items => Out_Items,
20265 Has_In_State => D3,
20266 Has_In_Out_State => D4,
20267 Has_Out_State => D5,
20268 Has_Null_State => D6);
20269 end if;
20270
20271 if Nkind (Refs) = N_Null then
20272 Refinements := No_List;
20273
20274 -- Multiple dependeny clauses appear as component associations of an
20275 -- aggregate. Note that the clauses are copied because the algorithm
20276 -- modifies them and this should not be visible in Refined_Depends.
20277
20278 else pragma Assert (Nkind (Refs) = N_Aggregate);
20279 Refinements := New_Copy_List (Component_Associations (Refs));
20280 end if;
20281
20282 -- Inspect all the clauses of pragma Depends trying to find a
20283 -- matching clause in pragma Refined_Depends. The approach is to use
20284 -- the sole output of a clause as a key. Output items are unique in a
20285 -- dependence relation. Clause normalization also ensured that all
20286 -- clauses have exactly on output. Depending on what the key is, one
20287 -- or more refinement clauses may satisfy the dependency clause. Each
20288 -- time a dependency clause is matched, its related refinement clause
20289 -- is consumed. In the end, two things may happen:
20290
20291 -- 1) A clause of pragma Depends was not matched in which case
20292 -- Check_Dependency_Clause reports the error.
20293
20294 -- 2) Refined_Depends has an extra clause in which case the error
20295 -- is reported by Report_Extra_Clauses.
20296
20297 Clause := First (Dependencies);
20298 while Present (Clause) loop
20299 Check_Dependency_Clause (Clause);
20300
20301 Next (Clause);
20302 end loop;
20303 end if;
20304
20305 if Serious_Errors_Detected = Errors then
20306 Report_Extra_Clauses;
20307 end if;
20308 end Analyze_Refined_Depends_In_Decl_Part;
20309
20310 -----------------------------------------
20311 -- Analyze_Refined_Global_In_Decl_Part --
20312 -----------------------------------------
20313
20314 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
20315 Global : Node_Id;
20316 -- The corresponding Global pragma
20317
20318 Has_In_State : Boolean := False;
20319 Has_In_Out_State : Boolean := False;
20320 Has_Out_State : Boolean := False;
20321 -- These flags are set when the corresponding Global pragma has a state
20322 -- of mode Input, In_Out and Output respectively with a visible
20323 -- refinement.
20324
20325 Has_Null_State : Boolean := False;
20326 -- This flag is set when the corresponding Global pragma has at least
20327 -- one state with a null refinement.
20328
20329 In_Constits : Elist_Id := No_Elist;
20330 In_Out_Constits : Elist_Id := No_Elist;
20331 Out_Constits : Elist_Id := No_Elist;
20332 -- These lists contain the entities of all Input, In_Out and Output
20333 -- constituents that appear in Refined_Global and participate in state
20334 -- refinement.
20335
20336 In_Items : Elist_Id := No_Elist;
20337 In_Out_Items : Elist_Id := No_Elist;
20338 Out_Items : Elist_Id := No_Elist;
20339 -- These list contain the entities of all Input, In_Out and Output items
20340 -- defined in the corresponding Global pragma.
20341
20342 procedure Check_In_Out_States;
20343 -- Determine whether the corresponding Global pragma mentions In_Out
20344 -- states with visible refinement and if so, ensure that one of the
20345 -- following completions apply to the constituents of the state:
20346 -- 1) there is at least one constituent of mode In_Out
20347 -- 2) there is at least one Input and one Output constituent
20348 -- 3) not all constituents are present and one of them is of mode
20349 -- Output.
20350 -- This routine may remove elements from In_Constits, In_Out_Constits
20351 -- and Out_Constits.
20352
20353 procedure Check_Input_States;
20354 -- Determine whether the corresponding Global pragma mentions Input
20355 -- states with visible refinement and if so, ensure that at least one of
20356 -- its constituents appears as an Input item in Refined_Global.
20357 -- This routine may remove elements from In_Constits, In_Out_Constits
20358 -- and Out_Constits.
20359
20360 procedure Check_Output_States;
20361 -- Determine whether the corresponding Global pragma mentions Output
20362 -- states with visible refinement and if so, ensure that all of its
20363 -- constituents appear as Output items in Refined_Global. This routine
20364 -- may remove elements from In_Constits, In_Out_Constits and
20365 -- Out_Constits.
20366
20367 procedure Check_Refined_Global_List
20368 (List : Node_Id;
20369 Global_Mode : Name_Id := Name_Input);
20370 -- Verify the legality of a single global list declaration. Global_Mode
20371 -- denotes the current mode in effect.
20372
20373 function Present_Then_Remove
20374 (List : Elist_Id;
20375 Item : Entity_Id) return Boolean;
20376 -- Search List for a particular entity Item. If Item has been found,
20377 -- remove it from List. This routine is used to strip lists In_Constits,
20378 -- In_Out_Constits and Out_Constits of valid constituents.
20379
20380 procedure Report_Extra_Constituents;
20381 -- Emit an error for each constituent found in lists In_Constits,
20382 -- In_Out_Constits and Out_Constits.
20383
20384 -------------------------
20385 -- Check_In_Out_States --
20386 -------------------------
20387
20388 procedure Check_In_Out_States is
20389 procedure Check_Constituent_Usage (State_Id : Entity_Id);
20390 -- Determine whether one of the following coverage scenarios is in
20391 -- effect:
20392 -- 1) there is at least one constituent of mode In_Out
20393 -- 2) there is at least one Input and one Output constituent
20394 -- 3) not all constituents are present and one of them is of mode
20395 -- Output.
20396 -- If this is not the case, emit an error.
20397
20398 -----------------------------
20399 -- Check_Constituent_Usage --
20400 -----------------------------
20401
20402 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
20403 Constit_Elmt : Elmt_Id;
20404 Constit_Id : Entity_Id;
20405 Has_Missing : Boolean := False;
20406 In_Out_Seen : Boolean := False;
20407 In_Seen : Boolean := False;
20408 Out_Seen : Boolean := False;
20409
20410 begin
20411 -- Process all the constituents of the state and note their modes
20412 -- within the global refinement.
20413
20414 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
20415 while Present (Constit_Elmt) loop
20416 Constit_Id := Node (Constit_Elmt);
20417
20418 if Present_Then_Remove (In_Constits, Constit_Id) then
20419 In_Seen := True;
20420
20421 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
20422 In_Out_Seen := True;
20423
20424 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
20425 Out_Seen := True;
20426
20427 else
20428 Has_Missing := True;
20429 end if;
20430
20431 Next_Elmt (Constit_Elmt);
20432 end loop;
20433
20434 -- A single In_Out constituent is a valid completion
20435
20436 if In_Out_Seen then
20437 null;
20438
20439 -- A pair of one Input and one Output constituent is a valid
20440 -- completion.
20441
20442 elsif In_Seen and then Out_Seen then
20443 null;
20444
20445 -- A single Output constituent is a valid completion only when
20446 -- some of the other constituents are missing.
20447
20448 elsif Has_Missing and then Out_Seen then
20449 null;
20450
20451 else
20452 Error_Msg_NE
20453 ("global refinement of state & redefines the mode of its "
20454 & "constituents", N, State_Id);
20455 end if;
20456 end Check_Constituent_Usage;
20457
20458 -- Local variables
20459
20460 Item_Elmt : Elmt_Id;
20461 Item_Id : Entity_Id;
20462
20463 -- Start of processing for Check_In_Out_States
20464
20465 begin
20466 -- Inspect the In_Out items of the corresponding Global pragma
20467 -- looking for a state with a visible refinement.
20468
20469 if Has_In_Out_State and then Present (In_Out_Items) then
20470 Item_Elmt := First_Elmt (In_Out_Items);
20471 while Present (Item_Elmt) loop
20472 Item_Id := Node (Item_Elmt);
20473
20474 -- Ensure that one of the three coverage variants is satisfied
20475
20476 if Ekind (Item_Id) = E_Abstract_State
20477 and then Has_Non_Null_Refinement (Item_Id)
20478 then
20479 Check_Constituent_Usage (Item_Id);
20480 end if;
20481
20482 Next_Elmt (Item_Elmt);
20483 end loop;
20484 end if;
20485 end Check_In_Out_States;
20486
20487 ------------------------
20488 -- Check_Input_States --
20489 ------------------------
20490
20491 procedure Check_Input_States is
20492 procedure Check_Constituent_Usage (State_Id : Entity_Id);
20493 -- Determine whether at least one constituent of state State_Id with
20494 -- visible refinement is used and has mode Input. Ensure that the
20495 -- remaining constituents do not have In_Out or Output modes.
20496
20497 -----------------------------
20498 -- Check_Constituent_Usage --
20499 -----------------------------
20500
20501 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
20502 Constit_Elmt : Elmt_Id;
20503 Constit_Id : Entity_Id;
20504 In_Seen : Boolean := False;
20505
20506 begin
20507 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
20508 while Present (Constit_Elmt) loop
20509 Constit_Id := Node (Constit_Elmt);
20510
20511 -- At least one of the constituents appears as an Input
20512
20513 if Present_Then_Remove (In_Constits, Constit_Id) then
20514 In_Seen := True;
20515
20516 -- The constituent appears in the global refinement, but has
20517 -- mode In_Out or Output.
20518
20519 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
20520 or else Present_Then_Remove (Out_Constits, Constit_Id)
20521 then
20522 Error_Msg_Name_1 := Chars (State_Id);
20523 Error_Msg_NE
20524 ("constituent & of state % must have mode Input in global "
20525 & "refinement", N, Constit_Id);
20526 end if;
20527
20528 Next_Elmt (Constit_Elmt);
20529 end loop;
20530
20531 -- Not one of the constituents appeared as Input
20532
20533 if not In_Seen then
20534 Error_Msg_NE
20535 ("global refinement of state & must include at least one "
20536 & "constituent of mode Input", N, State_Id);
20537 end if;
20538 end Check_Constituent_Usage;
20539
20540 -- Local variables
20541
20542 Item_Elmt : Elmt_Id;
20543 Item_Id : Entity_Id;
20544
20545 -- Start of processing for Check_Input_States
20546
20547 begin
20548 -- Inspect the Input items of the corresponding Global pragma
20549 -- looking for a state with a visible refinement.
20550
20551 if Has_In_State and then Present (In_Items) then
20552 Item_Elmt := First_Elmt (In_Items);
20553 while Present (Item_Elmt) loop
20554 Item_Id := Node (Item_Elmt);
20555
20556 -- Ensure that at least one of the constituents is utilized and
20557 -- is of mode Input.
20558
20559 if Ekind (Item_Id) = E_Abstract_State
20560 and then Has_Non_Null_Refinement (Item_Id)
20561 then
20562 Check_Constituent_Usage (Item_Id);
20563 end if;
20564
20565 Next_Elmt (Item_Elmt);
20566 end loop;
20567 end if;
20568 end Check_Input_States;
20569
20570 -------------------------
20571 -- Check_Output_States --
20572 -------------------------
20573
20574 procedure Check_Output_States is
20575 procedure Check_Constituent_Usage (State_Id : Entity_Id);
20576 -- Determine whether all constituents of state State_Id with visible
20577 -- refinement are used and have mode Output. Emit an error if this is
20578 -- not the case.
20579
20580 -----------------------------
20581 -- Check_Constituent_Usage --
20582 -----------------------------
20583
20584 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
20585 Constit_Elmt : Elmt_Id;
20586 Constit_Id : Entity_Id;
20587
20588 begin
20589 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
20590 while Present (Constit_Elmt) loop
20591 Constit_Id := Node (Constit_Elmt);
20592
20593 if Present_Then_Remove (Out_Constits, Constit_Id) then
20594 null;
20595
20596 else
20597 Remove (In_Constits, Constit_Id);
20598 Remove (In_Out_Constits, Constit_Id);
20599
20600 Error_Msg_Name_1 := Chars (State_Id);
20601 Error_Msg_NE
20602 ("constituent & of state % must have mode Output in "
20603 & "global refinement", N, Constit_Id);
20604 end if;
20605
20606 Next_Elmt (Constit_Elmt);
20607 end loop;
20608 end Check_Constituent_Usage;
20609
20610 -- Local variables
20611
20612 Item_Elmt : Elmt_Id;
20613 Item_Id : Entity_Id;
20614
20615 -- Start of processing for Check_Output_States
20616
20617 begin
20618 -- Inspect the Output items of the corresponding Global pragma
20619 -- looking for a state with a visible refinement.
20620
20621 if Has_Out_State and then Present (Out_Items) then
20622 Item_Elmt := First_Elmt (Out_Items);
20623 while Present (Item_Elmt) loop
20624 Item_Id := Node (Item_Elmt);
20625
20626 -- Ensure that all of the constituents are utilized and they
20627 -- have mode Output.
20628
20629 if Ekind (Item_Id) = E_Abstract_State
20630 and then Has_Non_Null_Refinement (Item_Id)
20631 then
20632 Check_Constituent_Usage (Item_Id);
20633 end if;
20634
20635 Next_Elmt (Item_Elmt);
20636 end loop;
20637 end if;
20638 end Check_Output_States;
20639
20640 -------------------------------
20641 -- Check_Refined_Global_List --
20642 -------------------------------
20643
20644 procedure Check_Refined_Global_List
20645 (List : Node_Id;
20646 Global_Mode : Name_Id := Name_Input)
20647 is
20648 procedure Check_Refined_Global_Item
20649 (Item : Node_Id;
20650 Global_Mode : Name_Id);
20651 -- Verify the legality of a single global item declaration. Parameter
20652 -- Global_Mode denotes the current mode in effect.
20653
20654 -------------------------------
20655 -- Check_Refined_Global_Item --
20656 -------------------------------
20657
20658 procedure Check_Refined_Global_Item
20659 (Item : Node_Id;
20660 Global_Mode : Name_Id)
20661 is
20662 procedure Add_Constituent (Item_Id : Entity_Id);
20663 -- Add a single constituent to one of the three constituent lists
20664 -- depending on Global_Mode.
20665
20666 procedure Check_Matching_Modes (Item_Id : Entity_Id);
20667 -- Verify that the global modes of item Item_Id are the same in
20668 -- both pragmas Global and Refined_Global.
20669
20670 ---------------------
20671 -- Add_Constituent --
20672 ---------------------
20673
20674 procedure Add_Constituent (Item_Id : Entity_Id) is
20675 begin
20676 if Global_Mode = Name_Input then
20677 Add_Item (Item_Id, In_Constits);
20678
20679 elsif Global_Mode = Name_In_Out then
20680 Add_Item (Item_Id, In_Out_Constits);
20681
20682 elsif Global_Mode = Name_Output then
20683 Add_Item (Item_Id, Out_Constits);
20684 end if;
20685 end Add_Constituent;
20686
20687 --------------------------
20688 -- Check_Matching_Modes --
20689 --------------------------
20690
20691 procedure Check_Matching_Modes (Item_Id : Entity_Id) is
20692 procedure Inconsistent_Mode_Error (Expect : Name_Id);
20693 -- Issue a common error message for all mode mismatche. Expect
20694 -- denotes the expected mode.
20695
20696 -----------------------------
20697 -- Inconsistent_Mode_Error --
20698 -----------------------------
20699
20700 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
20701 begin
20702 Error_Msg_NE
20703 ("global item & has inconsistent modes", Item, Item_Id);
20704
20705 Error_Msg_Name_1 := Global_Mode;
20706 Error_Msg_N ("\ expected mode %", Item);
20707
20708 Error_Msg_Name_1 := Expect;
20709 Error_Msg_N ("\ found mode %", Item);
20710 end Inconsistent_Mode_Error;
20711
20712 -- Start processing for Check_Matching_Modes
20713
20714 begin
20715 if Contains (In_Items, Item_Id) then
20716 if Global_Mode /= Name_Input then
20717 Inconsistent_Mode_Error (Name_Input);
20718 end if;
20719
20720 elsif Contains (In_Out_Items, Item_Id) then
20721 if Global_Mode /= Name_In_Out then
20722 Inconsistent_Mode_Error (Name_In_Out);
20723 end if;
20724
20725 elsif Contains (Out_Items, Item_Id) then
20726 if Global_Mode /= Name_Output then
20727 Inconsistent_Mode_Error (Name_Output);
20728 end if;
20729
20730 -- The item does not appear in the corresponding Global aspect,
20731 -- it must be an extra.
20732
20733 else
20734 Error_Msg_NE ("extra global item &", Item, Item_Id);
20735 end if;
20736 end Check_Matching_Modes;
20737
20738 -- Local variables
20739
20740 Item_Id : constant Entity_Id := Entity_Of (Item);
20741
20742 -- Start of processing for Check_Refined_Global_Item
20743
20744 begin
20745 if Ekind (Item_Id) = E_Abstract_State then
20746
20747 -- The state is neither a constituent of an ancestor state nor
20748 -- has a visible refinement. Ensure that the modes of both its
20749 -- occurrences in Global and Refined_Global match.
20750
20751 if No (Refined_State (Item_Id))
20752 and then not Has_Visible_Refinement (Item_Id)
20753 then
20754 Check_Matching_Modes (Item_Id);
20755 end if;
20756
20757 else pragma Assert (Ekind (Item_Id) = E_Variable);
20758
20759 -- The variable acts as a constituent of a state, collect it
20760 -- for the state completeness checks performed later on.
20761
20762 if Present (Refined_State (Item_Id)) then
20763 Add_Constituent (Item_Id);
20764
20765 -- The variable is not a constituent. Ensure that the modes of
20766 -- both its occurrences in Global and Refined_Global match.
20767
20768 else
20769 Check_Matching_Modes (Item_Id);
20770 end if;
20771 end if;
20772 end Check_Refined_Global_Item;
20773
20774 -- Local variables
20775
20776 Item : Node_Id;
20777
20778 -- Start of processing for Check_Refined_Global_List
20779
20780 begin
20781 if Nkind (List) = N_Null then
20782 null;
20783
20784 -- Single global item declaration
20785
20786 elsif Nkind_In (List, N_Expanded_Name,
20787 N_Identifier,
20788 N_Selected_Component)
20789 then
20790 Check_Refined_Global_Item (List, Global_Mode);
20791
20792 -- Simple global list or moded global list declaration
20793
20794 elsif Nkind (List) = N_Aggregate then
20795
20796 -- The declaration of a simple global list appear as a collection
20797 -- of expressions.
20798
20799 if Present (Expressions (List)) then
20800 Item := First (Expressions (List));
20801 while Present (Item) loop
20802 Check_Refined_Global_Item (Item, Global_Mode);
20803
20804 Next (Item);
20805 end loop;
20806
20807 -- The declaration of a moded global list appears as a collection
20808 -- of component associations where individual choices denote
20809 -- modes.
20810
20811 elsif Present (Component_Associations (List)) then
20812 Item := First (Component_Associations (List));
20813 while Present (Item) loop
20814 Check_Refined_Global_List
20815 (List => Expression (Item),
20816 Global_Mode => Chars (First (Choices (Item))));
20817
20818 Next (Item);
20819 end loop;
20820
20821 -- Invalid tree
20822
20823 else
20824 raise Program_Error;
20825 end if;
20826
20827 -- Invalid list
20828
20829 else
20830 raise Program_Error;
20831 end if;
20832 end Check_Refined_Global_List;
20833
20834 -------------------------
20835 -- Present_Then_Remove --
20836 -------------------------
20837
20838 function Present_Then_Remove
20839 (List : Elist_Id;
20840 Item : Entity_Id) return Boolean
20841 is
20842 Elmt : Elmt_Id;
20843
20844 begin
20845 if Present (List) then
20846 Elmt := First_Elmt (List);
20847 while Present (Elmt) loop
20848 if Node (Elmt) = Item then
20849 Remove_Elmt (List, Elmt);
20850 return True;
20851 end if;
20852
20853 Next_Elmt (Elmt);
20854 end loop;
20855 end if;
20856
20857 return False;
20858 end Present_Then_Remove;
20859
20860 -------------------------------
20861 -- Report_Extra_Constituents --
20862 -------------------------------
20863
20864 procedure Report_Extra_Constituents is
20865 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
20866 -- Emit an error for every element of List
20867
20868 ---------------------------------------
20869 -- Report_Extra_Constituents_In_List --
20870 ---------------------------------------
20871
20872 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
20873 Constit_Elmt : Elmt_Id;
20874
20875 begin
20876 if Present (List) then
20877 Constit_Elmt := First_Elmt (List);
20878 while Present (Constit_Elmt) loop
20879 Error_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
20880 Next_Elmt (Constit_Elmt);
20881 end loop;
20882 end if;
20883 end Report_Extra_Constituents_In_List;
20884
20885 -- Start of processing for Report_Extra_Constituents
20886
20887 begin
20888 Report_Extra_Constituents_In_List (In_Constits);
20889 Report_Extra_Constituents_In_List (In_Out_Constits);
20890 Report_Extra_Constituents_In_List (Out_Constits);
20891 end Report_Extra_Constituents;
20892
20893 -- Local variables
20894
20895 Body_Decl : constant Node_Id := Parent (N);
20896 Errors : constant Nat := Serious_Errors_Detected;
20897 Items : constant Node_Id :=
20898 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
20899 Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl);
20900
20901 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
20902
20903 begin
20904 Global := Get_Pragma (Spec_Id, Pragma_Global);
20905
20906 -- The subprogram declaration lacks pragma Global. This renders
20907 -- Refined_Global useless as there is nothing to refine.
20908
20909 if No (Global) then
20910 Error_Msg_NE
20911 ("useless refinement, subprogram & lacks global items", N, Spec_Id);
20912 return;
20913 end if;
20914
20915 -- Extract all relevant items from the corresponding Global pragma
20916
20917 Collect_Global_Items
20918 (Prag => Global,
20919 In_Items => In_Items,
20920 In_Out_Items => In_Out_Items,
20921 Out_Items => Out_Items,
20922 Has_In_State => Has_In_State,
20923 Has_In_Out_State => Has_In_Out_State,
20924 Has_Out_State => Has_Out_State,
20925 Has_Null_State => Has_Null_State);
20926
20927 -- The corresponding Global pragma must mention at least one state with
20928 -- a visible refinement at the point Refined_Global is processed. States
20929 -- with null refinements warrant a Refined_Global pragma.
20930
20931 if not Has_In_State
20932 and then not Has_In_Out_State
20933 and then not Has_Out_State
20934 and then not Has_Null_State
20935 then
20936 Error_Msg_NE
20937 ("useless refinement, subprogram & does not mention abstract state "
20938 & "with visible refinement", N, Spec_Id);
20939 return;
20940 end if;
20941
20942 -- The global refinement of inputs and outputs cannot be null when the
20943 -- corresponding Global pragma contains at least one item except in the
20944 -- case where we have states with null refinements.
20945
20946 if Nkind (Items) = N_Null
20947 and then
20948 (Present (In_Items)
20949 or else Present (In_Out_Items)
20950 or else Present (Out_Items))
20951 and then not Has_Null_State
20952 then
20953 Error_Msg_NE
20954 ("refinement cannot be null, subprogram & has global items",
20955 N, Spec_Id);
20956 return;
20957 end if;
20958
20959 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
20960 -- This ensures that the categorization of all refined global items is
20961 -- consistent with their role.
20962
20963 Analyze_Global_In_Decl_Part (N);
20964
20965 -- Perform all refinement checks with respect to completeness and mode
20966 -- matching.
20967
20968 if Serious_Errors_Detected = Errors then
20969 Check_Refined_Global_List (Items);
20970 end if;
20971
20972 -- For Input states with visible refinement, at least one constituent
20973 -- must be used as an Input in the global refinement.
20974
20975 if Serious_Errors_Detected = Errors then
20976 Check_Input_States;
20977 end if;
20978
20979 -- Verify all possible completion variants for In_Out states with
20980 -- visible refinement.
20981
20982 if Serious_Errors_Detected = Errors then
20983 Check_In_Out_States;
20984 end if;
20985
20986 -- For Output states with visible refinement, all constituents must be
20987 -- used as Outputs in the global refinement.
20988
20989 if Serious_Errors_Detected = Errors then
20990 Check_Output_States;
20991 end if;
20992
20993 -- Emit errors for all constituents that belong to other states with
20994 -- visible refinement that do not appear in Global.
20995
20996 if Serious_Errors_Detected = Errors then
20997 Report_Extra_Constituents;
20998 end if;
20999 end Analyze_Refined_Global_In_Decl_Part;
21000
21001 ----------------------------------------
21002 -- Analyze_Refined_State_In_Decl_Part --
21003 ----------------------------------------
21004
21005 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
21006 Pack_Body : constant Node_Id := Parent (N);
21007 Spec_Id : constant Entity_Id := Corresponding_Spec (Pack_Body);
21008
21009 Abstr_States : Elist_Id := No_Elist;
21010 -- A list of all abstract states defined in the package declaration. The
21011 -- list is used to report unrefined states.
21012
21013 Constituents_Seen : Elist_Id := No_Elist;
21014 -- A list that contains all constituents processed so far. The list is
21015 -- used to detect multiple uses of the same constituent.
21016
21017 Hidden_States : Elist_Id := No_Elist;
21018 -- A list of all hidden states (abstract states and variables) that
21019 -- appear in the package spec and body. The list is used to report
21020 -- unused hidden states.
21021
21022 Refined_States_Seen : Elist_Id := No_Elist;
21023 -- A list that contains all refined states processed so far. The list is
21024 -- used to detect duplicate refinements.
21025
21026 procedure Analyze_Refinement_Clause (Clause : Node_Id);
21027 -- Perform full analysis of a single refinement clause
21028
21029 procedure Collect_Hidden_States;
21030 -- Gather the entities of all hidden states that appear in the spec and
21031 -- body of the related package in Hidden_States.
21032
21033 procedure Report_Unrefined_States;
21034 -- Emit errors for all abstract states that have not been refined by
21035 -- the pragma.
21036
21037 procedure Report_Unused_Hidden_States;
21038 -- Emit errors for all hidden states of the related package that do not
21039 -- participate in a refinement.
21040
21041 -------------------------------
21042 -- Analyze_Refinement_Clause --
21043 -------------------------------
21044
21045 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
21046 State_Id : Entity_Id := Empty;
21047 -- The entity of the state being refined in the current clause
21048
21049 Non_Null_Seen : Boolean := False;
21050 Null_Seen : Boolean := False;
21051 -- Flags used to detect multiple uses of null in a single clause or a
21052 -- mixture of null and non-null constituents.
21053
21054 procedure Analyze_Constituent (Constit : Node_Id);
21055 -- Perform full analysis of a single constituent
21056
21057 procedure Check_Matching_State
21058 (State : Node_Id;
21059 State_Id : Entity_Id);
21060 -- Determine whether state State denoted by its name State_Id appears
21061 -- in Abstr_States. Emit an error when attempting to re-refine the
21062 -- state or when the state is not defined in the package declaration.
21063 -- Otherwise remove the state from Abstr_States.
21064
21065 -------------------------
21066 -- Analyze_Constituent --
21067 -------------------------
21068
21069 procedure Analyze_Constituent (Constit : Node_Id) is
21070 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
21071 -- Determine whether constituent Constit denoted by its entity
21072 -- Constit_Id appears in Hidden_States. Emit an error when the
21073 -- constituent is not a valid hidden state of the related package
21074 -- or when it is used more than once. Otherwise remove the
21075 -- constituent from Hidden_States.
21076
21077 --------------------------------
21078 -- Check_Matching_Constituent --
21079 --------------------------------
21080
21081 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
21082 State_Elmt : Elmt_Id;
21083
21084 begin
21085 -- Detect a duplicate use of a constituent
21086
21087 if Contains (Constituents_Seen, Constit_Id) then
21088 Error_Msg_NE
21089 ("duplicate use of constituent &", Constit, Constit_Id);
21090 return;
21091 end if;
21092
21093 -- Inspect the hidden states of the related package looking for
21094 -- a match.
21095
21096 State_Elmt := First_Elmt (Hidden_States);
21097 while Present (State_Elmt) loop
21098
21099 -- A valid hidden state or variable participates in a
21100 -- refinement. Add the constituent to the list of processed
21101 -- items to aid with the detection of duplicate constituent
21102 -- use. Remove the constituent from Hidden_States to signal
21103 -- that it has already been used.
21104
21105 if Node (State_Elmt) = Constit_Id then
21106 Add_Item (Constit_Id, Constituents_Seen);
21107 Remove_Elmt (Hidden_States, State_Elmt);
21108
21109 -- Collect the constituent in the list of refinement
21110 -- items. Establish a relation between the refined state
21111 -- and its constituent.
21112
21113 Append_Elmt
21114 (Constit_Id, Refinement_Constituents (State_Id));
21115 Set_Refined_State (Constit_Id, State_Id);
21116
21117 -- The state has at least one legal constituent, mark the
21118 -- start of the refinement region. The region ends when
21119 -- the body declarations end (see Analyze_Declarations).
21120
21121 Set_Has_Visible_Refinement (State_Id);
21122
21123 return;
21124 end if;
21125
21126 Next_Elmt (State_Elmt);
21127 end loop;
21128
21129 -- If we get here, we are refining a state that is not hidden
21130 -- with respect to the related package.
21131
21132 Error_Msg_Name_1 := Chars (Spec_Id);
21133 Error_Msg_NE
21134 ("cannot use & in refinement, constituent is not a hidden "
21135 & "state of package %", Constit, Constit_Id);
21136 end Check_Matching_Constituent;
21137
21138 -- Local variables
21139
21140 Constit_Id : Entity_Id;
21141
21142 -- Start of processing for Analyze_Constituent
21143
21144 begin
21145 -- Detect multiple uses of null in a single refinement clause or a
21146 -- mixture of null and non-null constituents.
21147
21148 if Nkind (Constit) = N_Null then
21149 if Null_Seen then
21150 Error_Msg_N
21151 ("multiple null constituents not allowed", Constit);
21152
21153 elsif Non_Null_Seen then
21154 Error_Msg_N
21155 ("cannot mix null and non-null constituents", Constit);
21156
21157 else
21158 Null_Seen := True;
21159
21160 -- Collect the constituent in the list of refinement items
21161
21162 Append_Elmt (Constit, Refinement_Constituents (State_Id));
21163
21164 -- The state has at least one legal constituent, mark the
21165 -- start of the refinement region. The region ends when the
21166 -- body declarations end (see Analyze_Declarations).
21167
21168 Set_Has_Visible_Refinement (State_Id);
21169 end if;
21170
21171 -- Non-null constituents
21172
21173 else
21174 Non_Null_Seen := True;
21175
21176 if Null_Seen then
21177 Error_Msg_N
21178 ("cannot mix null and non-null constituents", Constit);
21179 end if;
21180
21181 Analyze (Constit);
21182
21183 -- Ensure that the constituent denotes a valid state or a
21184 -- whole variable.
21185
21186 if Is_Entity_Name (Constit) then
21187 Constit_Id := Entity (Constit);
21188
21189 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
21190 Check_Matching_Constituent (Constit_Id);
21191 else
21192 Error_Msg_NE
21193 ("constituent & must denote a variable or state",
21194 Constit, Constit_Id);
21195 end if;
21196
21197 -- The constituent is illegal
21198
21199 else
21200 Error_Msg_N ("malformed constituent", Constit);
21201 end if;
21202 end if;
21203 end Analyze_Constituent;
21204
21205 --------------------------
21206 -- Check_Matching_State --
21207 --------------------------
21208
21209 procedure Check_Matching_State
21210 (State : Node_Id;
21211 State_Id : Entity_Id)
21212 is
21213 State_Elmt : Elmt_Id;
21214
21215 begin
21216 -- Detect a duplicate refinement of a state
21217
21218 if Contains (Refined_States_Seen, State_Id) then
21219 Error_Msg_NE
21220 ("duplicate refinement of state &", State, State_Id);
21221 return;
21222 end if;
21223
21224 -- Inspect the abstract states defined in the package declaration
21225 -- looking for a match.
21226
21227 State_Elmt := First_Elmt (Abstr_States);
21228 while Present (State_Elmt) loop
21229
21230 -- A valid abstract state is being refined in the body. Add
21231 -- the state to the list of processed refined states to aid
21232 -- with the detection of duplicate refinements. Remove the
21233 -- state from Abstr_States to signal that it has already been
21234 -- refined.
21235
21236 if Node (State_Elmt) = State_Id then
21237 Add_Item (State_Id, Refined_States_Seen);
21238 Remove_Elmt (Abstr_States, State_Elmt);
21239
21240 return;
21241 end if;
21242
21243 Next_Elmt (State_Elmt);
21244 end loop;
21245
21246 -- If we get here, we are refining a state that is not defined in
21247 -- the package declaration.
21248
21249 Error_Msg_Name_1 := Chars (Spec_Id);
21250 Error_Msg_NE
21251 ("cannot refine state, & is not defined in package %",
21252 State, State_Id);
21253 end Check_Matching_State;
21254
21255 -- Local declarations
21256
21257 Constit : Node_Id;
21258 State : Node_Id;
21259
21260 -- Start of processing for Analyze_Refinement_Clause
21261
21262 begin
21263 -- Analyze the state name of a refinement clause
21264
21265 State := First (Choices (Clause));
21266 while Present (State) loop
21267 if Present (State_Id) then
21268 Error_Msg_N
21269 ("refinement clause cannot cover multiple states", State);
21270
21271 else
21272 Analyze (State);
21273
21274 -- Ensure that the state name denotes a valid abstract state
21275 -- that is defined in the spec of the related package.
21276
21277 if Is_Entity_Name (State) then
21278 State_Id := Entity (State);
21279
21280 -- Catch any attempts to re-refine a state or refine a
21281 -- state that is not defined in the package declaration.
21282
21283 if Ekind (State_Id) = E_Abstract_State then
21284 Check_Matching_State (State, State_Id);
21285 else
21286 Error_Msg_NE
21287 ("& must denote an abstract state", State, State_Id);
21288 end if;
21289
21290 -- The state name is illegal
21291
21292 else
21293 Error_Msg_N
21294 ("malformed state name in refinement clause", State);
21295 end if;
21296 end if;
21297
21298 Next (State);
21299 end loop;
21300
21301 -- Analyze all constituents of the refinement. Multiple constituents
21302 -- appear as an aggregate.
21303
21304 Constit := Expression (Clause);
21305
21306 if Nkind (Constit) = N_Aggregate then
21307 if Present (Component_Associations (Constit)) then
21308 Error_Msg_N
21309 ("constituents of refinement clause must appear in "
21310 & "positional form", Constit);
21311
21312 else pragma Assert (Present (Expressions (Constit)));
21313 Constit := First (Expressions (Constit));
21314 while Present (Constit) loop
21315 Analyze_Constituent (Constit);
21316
21317 Next (Constit);
21318 end loop;
21319 end if;
21320
21321 -- Various forms of a single constituent. Note that these may include
21322 -- malformed constituents.
21323
21324 else
21325 Analyze_Constituent (Constit);
21326 end if;
21327 end Analyze_Refinement_Clause;
21328
21329 ---------------------------
21330 -- Collect_Hidden_States --
21331 ---------------------------
21332
21333 procedure Collect_Hidden_States is
21334 procedure Collect_Hidden_States_In_Decls (Decls : List_Id);
21335 -- Find all hidden states that appear in declarative list Decls and
21336 -- append their entities to Result.
21337
21338 ------------------------------------
21339 -- Collect_Hidden_States_In_Decls --
21340 ------------------------------------
21341
21342 procedure Collect_Hidden_States_In_Decls (Decls : List_Id) is
21343 procedure Collect_Abstract_States (States : Elist_Id);
21344 -- Copy the abstract states defined in list States to list Result
21345
21346 -----------------------------
21347 -- Collect_Abstract_States --
21348 -----------------------------
21349
21350 procedure Collect_Abstract_States (States : Elist_Id) is
21351 State_Elmt : Elmt_Id;
21352
21353 begin
21354 State_Elmt := First_Elmt (States);
21355 while Present (State_Elmt) loop
21356 Add_Item (Node (State_Elmt), Hidden_States);
21357
21358 Next_Elmt (State_Elmt);
21359 end loop;
21360 end Collect_Abstract_States;
21361
21362 -- Local variables
21363
21364 Decl : Node_Id;
21365
21366 -- Start of processing for Collect_Hidden_States_In_Decls
21367
21368 begin
21369 Decl := First (Decls);
21370 while Present (Decl) loop
21371
21372 -- Source objects (non-constants) are valid hidden states
21373
21374 if Nkind (Decl) = N_Object_Declaration
21375 and then Ekind (Defining_Entity (Decl)) = E_Variable
21376 and then Comes_From_Source (Decl)
21377 then
21378 Add_Item (Defining_Entity (Decl), Hidden_States);
21379
21380 -- Gather the abstract states of a package along with all
21381 -- hidden states in its visible declarations.
21382
21383 elsif Nkind (Decl) = N_Package_Declaration then
21384 Collect_Abstract_States
21385 (Abstract_States (Defining_Entity (Decl)));
21386
21387 Collect_Hidden_States_In_Decls
21388 (Visible_Declarations (Specification (Decl)));
21389 end if;
21390
21391 Next (Decl);
21392 end loop;
21393 end Collect_Hidden_States_In_Decls;
21394
21395 -- Local variables
21396
21397 Pack_Spec : constant Node_Id := Parent (Spec_Id);
21398
21399 -- Start of processing for Collect_Hidden_States
21400
21401 begin
21402 -- Process the private declarations of the package spec and the
21403 -- declarations of the body.
21404
21405 Collect_Hidden_States_In_Decls (Private_Declarations (Pack_Spec));
21406 Collect_Hidden_States_In_Decls (Declarations (Pack_Body));
21407 end Collect_Hidden_States;
21408
21409 -----------------------------
21410 -- Report_Unrefined_States --
21411 -----------------------------
21412
21413 procedure Report_Unrefined_States is
21414 State_Elmt : Elmt_Id;
21415
21416 begin
21417 if Present (Abstr_States) then
21418 State_Elmt := First_Elmt (Abstr_States);
21419 while Present (State_Elmt) loop
21420 Error_Msg_N
21421 ("abstract state & must be refined", Node (State_Elmt));
21422
21423 Next_Elmt (State_Elmt);
21424 end loop;
21425 end if;
21426 end Report_Unrefined_States;
21427
21428 ---------------------------------
21429 -- Report_Unused_Hidden_States --
21430 ---------------------------------
21431
21432 procedure Report_Unused_Hidden_States is
21433 Posted : Boolean := False;
21434 State_Elmt : Elmt_Id;
21435 State_Id : Entity_Id;
21436
21437 begin
21438 if Present (Hidden_States) then
21439 State_Elmt := First_Elmt (Hidden_States);
21440 while Present (State_Elmt) loop
21441 State_Id := Node (State_Elmt);
21442
21443 -- Generate an error message of the form:
21444
21445 -- package ... has unused hidden states
21446 -- abstract state ... defined at ...
21447 -- variable ... defined at ...
21448
21449 if not Posted then
21450 Posted := True;
21451 Error_Msg_NE
21452 ("package & has unused hidden states", N, Spec_Id);
21453 end if;
21454
21455 Error_Msg_Sloc := Sloc (State_Id);
21456
21457 if Ekind (State_Id) = E_Abstract_State then
21458 Error_Msg_NE ("\ abstract state & defined #", N, State_Id);
21459 else
21460 Error_Msg_NE ("\ variable & defined #", N, State_Id);
21461 end if;
21462
21463 Next_Elmt (State_Elmt);
21464 end loop;
21465 end if;
21466 end Report_Unused_Hidden_States;
21467
21468 -- Local declarations
21469
21470 Clauses : constant Node_Id :=
21471 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
21472 Clause : Node_Id;
21473
21474 -- Start of processing for Analyze_Refined_State_In_Decl_Part
21475
21476 begin
21477 Set_Analyzed (N);
21478
21479 -- Initialize the various lists used during analysis
21480
21481 Abstr_States := New_Copy_Elist (Abstract_States (Spec_Id));
21482 Collect_Hidden_States;
21483
21484 -- Multiple state refinements appear as an aggregate
21485
21486 if Nkind (Clauses) = N_Aggregate then
21487 if Present (Expressions (Clauses)) then
21488 Error_Msg_N
21489 ("state refinements must appear as component associations",
21490 Clauses);
21491
21492 else pragma Assert (Present (Component_Associations (Clauses)));
21493 Clause := First (Component_Associations (Clauses));
21494 while Present (Clause) loop
21495 Analyze_Refinement_Clause (Clause);
21496
21497 Next (Clause);
21498 end loop;
21499 end if;
21500
21501 -- Various forms of a single state refinement. Note that these may
21502 -- include malformed refinements.
21503
21504 else
21505 Analyze_Refinement_Clause (Clauses);
21506 end if;
21507
21508 -- Ensure that all abstract states have been refined and all hidden
21509 -- states of the related package unilized in refinements.
21510
21511 Report_Unrefined_States;
21512 Report_Unused_Hidden_States;
21513 end Analyze_Refined_State_In_Decl_Part;
21514
21515 ------------------------------------
21516 -- Analyze_Test_Case_In_Decl_Part --
21517 ------------------------------------
21518
21519 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
21520 begin
21521 -- Install formals and push subprogram spec onto scope stack so that we
21522 -- can see the formals from the pragma.
21523
21524 Push_Scope (S);
21525 Install_Formals (S);
21526
21527 -- Preanalyze the boolean expressions, we treat these as spec
21528 -- expressions (i.e. similar to a default expression).
21529
21530 if Pragma_Name (N) = Name_Test_Case then
21531 Preanalyze_CTC_Args
21532 (N,
21533 Get_Requires_From_CTC_Pragma (N),
21534 Get_Ensures_From_CTC_Pragma (N));
21535 end if;
21536
21537 -- Remove the subprogram from the scope stack now that the pre-analysis
21538 -- of the expressions in the contract case or test case is done.
21539
21540 End_Scope;
21541 end Analyze_Test_Case_In_Decl_Part;
21542
21543 ----------------
21544 -- Appears_In --
21545 ----------------
21546
21547 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
21548 Elmt : Elmt_Id;
21549 Id : Entity_Id;
21550
21551 begin
21552 if Present (List) then
21553 Elmt := First_Elmt (List);
21554 while Present (Elmt) loop
21555 if Nkind (Node (Elmt)) = N_Defining_Identifier then
21556 Id := Node (Elmt);
21557 else
21558 Id := Entity (Node (Elmt));
21559 end if;
21560
21561 if Id = Item_Id then
21562 return True;
21563 end if;
21564
21565 Next_Elmt (Elmt);
21566 end loop;
21567 end if;
21568
21569 return False;
21570 end Appears_In;
21571
21572 ----------------
21573 -- Check_Kind --
21574 ----------------
21575
21576 function Check_Kind (Nam : Name_Id) return Name_Id is
21577 PP : Node_Id;
21578
21579 begin
21580 -- Loop through entries in check policy list
21581
21582 PP := Opt.Check_Policy_List;
21583 while Present (PP) loop
21584 declare
21585 PPA : constant List_Id := Pragma_Argument_Associations (PP);
21586 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
21587
21588 begin
21589 if Nam = Pnm
21590 or else (Pnm = Name_Assertion
21591 and then Is_Valid_Assertion_Kind (Nam))
21592 or else (Pnm = Name_Statement_Assertions
21593 and then Nam_In (Nam, Name_Assert,
21594 Name_Assert_And_Cut,
21595 Name_Assume,
21596 Name_Loop_Invariant))
21597 then
21598 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
21599 when Name_On | Name_Check =>
21600 return Name_Check;
21601 when Name_Off | Name_Ignore =>
21602 return Name_Ignore;
21603 when Name_Disable =>
21604 return Name_Disable;
21605 when others =>
21606 raise Program_Error;
21607 end case;
21608
21609 else
21610 PP := Next_Pragma (PP);
21611 end if;
21612 end;
21613 end loop;
21614
21615 -- If there are no specific entries that matched, then we let the
21616 -- setting of assertions govern. Note that this provides the needed
21617 -- compatibility with the RM for the cases of assertion, invariant,
21618 -- precondition, predicate, and postcondition.
21619
21620 if Assertions_Enabled then
21621 return Name_Check;
21622 else
21623 return Name_Ignore;
21624 end if;
21625 end Check_Kind;
21626
21627 -----------------------------
21628 -- Check_Applicable_Policy --
21629 -----------------------------
21630
21631 procedure Check_Applicable_Policy (N : Node_Id) is
21632 PP : Node_Id;
21633 Policy : Name_Id;
21634
21635 Ename : constant Name_Id := Original_Aspect_Name (N);
21636
21637 begin
21638 -- No effect if not valid assertion kind name
21639
21640 if not Is_Valid_Assertion_Kind (Ename) then
21641 return;
21642 end if;
21643
21644 -- Loop through entries in check policy list
21645
21646 PP := Opt.Check_Policy_List;
21647 while Present (PP) loop
21648 declare
21649 PPA : constant List_Id := Pragma_Argument_Associations (PP);
21650 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
21651
21652 begin
21653 if Ename = Pnm
21654 or else Pnm = Name_Assertion
21655 or else (Pnm = Name_Statement_Assertions
21656 and then (Ename = Name_Assert or else
21657 Ename = Name_Assert_And_Cut or else
21658 Ename = Name_Assume or else
21659 Ename = Name_Loop_Invariant))
21660 then
21661 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
21662
21663 case Policy is
21664 when Name_Off | Name_Ignore =>
21665 Set_Is_Ignored (N, True);
21666 Set_Is_Checked (N, False);
21667
21668 when Name_On | Name_Check =>
21669 Set_Is_Checked (N, True);
21670 Set_Is_Ignored (N, False);
21671
21672 when Name_Disable =>
21673 Set_Is_Ignored (N, True);
21674 Set_Is_Checked (N, False);
21675 Set_Is_Disabled (N, True);
21676
21677 -- That should be exhaustive, the null here is a defence
21678 -- against a malformed tree from previous errors.
21679
21680 when others =>
21681 null;
21682 end case;
21683
21684 return;
21685 end if;
21686
21687 PP := Next_Pragma (PP);
21688 end;
21689 end loop;
21690
21691 -- If there are no specific entries that matched, then we let the
21692 -- setting of assertions govern. Note that this provides the needed
21693 -- compatibility with the RM for the cases of assertion, invariant,
21694 -- precondition, predicate, and postcondition.
21695
21696 if Assertions_Enabled then
21697 Set_Is_Checked (N, True);
21698 Set_Is_Ignored (N, False);
21699 else
21700 Set_Is_Checked (N, False);
21701 Set_Is_Ignored (N, True);
21702 end if;
21703 end Check_Applicable_Policy;
21704
21705 --------------------------
21706 -- Collect_Global_Items --
21707 --------------------------
21708
21709 procedure Collect_Global_Items
21710 (Prag : Node_Id;
21711 In_Items : in out Elist_Id;
21712 In_Out_Items : in out Elist_Id;
21713 Out_Items : in out Elist_Id;
21714 Has_In_State : out Boolean;
21715 Has_In_Out_State : out Boolean;
21716 Has_Out_State : out Boolean;
21717 Has_Null_State : out Boolean)
21718 is
21719 procedure Process_Global_List
21720 (List : Node_Id;
21721 Mode : Name_Id := Name_Input);
21722 -- Collect all items housed in a global list. Formal Mode denotes the
21723 -- current mode in effect.
21724
21725 -------------------------
21726 -- Process_Global_List --
21727 -------------------------
21728
21729 procedure Process_Global_List
21730 (List : Node_Id;
21731 Mode : Name_Id := Name_Input)
21732 is
21733 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id);
21734 -- Add a single item to the appropriate list. Formal Mode denotes the
21735 -- current mode in effect.
21736
21737 -------------------------
21738 -- Process_Global_Item --
21739 -------------------------
21740
21741 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
21742 Item_Id : constant Entity_Id := Entity_Of (Item);
21743
21744 begin
21745 -- Signal that the global list contains at least one abstract
21746 -- state with a visible refinement. Note that the refinement may
21747 -- be null in which case there are no constituents.
21748
21749 if Ekind (Item_Id) = E_Abstract_State then
21750 if Has_Null_Refinement (Item_Id) then
21751 Has_Null_State := True;
21752
21753 elsif Has_Non_Null_Refinement (Item_Id) then
21754 if Mode = Name_Input then
21755 Has_In_State := True;
21756 elsif Mode = Name_In_Out then
21757 Has_In_Out_State := True;
21758 elsif Mode = Name_Output then
21759 Has_Out_State := True;
21760 end if;
21761 end if;
21762 end if;
21763
21764 -- Add the item to the proper list
21765
21766 if Mode = Name_Input then
21767 Add_Item (Item_Id, In_Items);
21768 elsif Mode = Name_In_Out then
21769 Add_Item (Item_Id, In_Out_Items);
21770 elsif Mode = Name_Output then
21771 Add_Item (Item_Id, Out_Items);
21772 end if;
21773 end Process_Global_Item;
21774
21775 -- Local variables
21776
21777 Item : Node_Id;
21778
21779 -- Start of processing for Process_Global_List
21780
21781 begin
21782 if Nkind (List) = N_Null then
21783 null;
21784
21785 -- Single global item declaration
21786
21787 elsif Nkind_In (List, N_Expanded_Name,
21788 N_Identifier,
21789 N_Selected_Component)
21790 then
21791 Process_Global_Item (List, Mode);
21792
21793 -- Single global list or moded global list declaration
21794
21795 elsif Nkind (List) = N_Aggregate then
21796
21797 -- The declaration of a simple global list appear as a collection
21798 -- of expressions.
21799
21800 if Present (Expressions (List)) then
21801 Item := First (Expressions (List));
21802 while Present (Item) loop
21803 Process_Global_Item (Item, Mode);
21804
21805 Next (Item);
21806 end loop;
21807
21808 -- The declaration of a moded global list appears as a collection
21809 -- of component associations where individual choices denote mode.
21810
21811 elsif Present (Component_Associations (List)) then
21812 Item := First (Component_Associations (List));
21813 while Present (Item) loop
21814 Process_Global_List
21815 (List => Expression (Item),
21816 Mode => Chars (First (Choices (Item))));
21817
21818 Next (Item);
21819 end loop;
21820
21821 -- Invalid tree
21822
21823 else
21824 raise Program_Error;
21825 end if;
21826
21827 -- Invalid list
21828
21829 else
21830 raise Program_Error;
21831 end if;
21832 end Process_Global_List;
21833
21834 -- Local variables
21835
21836 Items : constant Node_Id :=
21837 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
21838
21839 -- Start of processing for Collect_Global_Items
21840
21841 begin
21842 -- Assume that no states have been encountered
21843
21844 Has_In_State := False;
21845 Has_In_Out_State := False;
21846 Has_Out_State := False;
21847 Has_Null_State := False;
21848
21849 Process_Global_List (Items);
21850 end Collect_Global_Items;
21851
21852 ---------------------------------------
21853 -- Collect_Subprogram_Inputs_Outputs --
21854 ---------------------------------------
21855
21856 procedure Collect_Subprogram_Inputs_Outputs
21857 (Subp_Id : Entity_Id;
21858 Subp_Inputs : in out Elist_Id;
21859 Subp_Outputs : in out Elist_Id;
21860 Global_Seen : out Boolean)
21861 is
21862 procedure Collect_Global_List
21863 (List : Node_Id;
21864 Mode : Name_Id := Name_Input);
21865 -- Collect all relevant items from a global list
21866
21867 -------------------------
21868 -- Collect_Global_List --
21869 -------------------------
21870
21871 procedure Collect_Global_List
21872 (List : Node_Id;
21873 Mode : Name_Id := Name_Input)
21874 is
21875 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
21876 -- Add an item to the proper subprogram input or output collection
21877
21878 -------------------------
21879 -- Collect_Global_Item --
21880 -------------------------
21881
21882 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
21883 begin
21884 if Nam_In (Mode, Name_In_Out, Name_Input) then
21885 Add_Item (Item, Subp_Inputs);
21886 end if;
21887
21888 if Nam_In (Mode, Name_In_Out, Name_Output) then
21889 Add_Item (Item, Subp_Outputs);
21890 end if;
21891 end Collect_Global_Item;
21892
21893 -- Local variables
21894
21895 Assoc : Node_Id;
21896 Item : Node_Id;
21897
21898 -- Start of processing for Collect_Global_List
21899
21900 begin
21901 if Nkind (List) = N_Null then
21902 null;
21903
21904 -- Single global item declaration
21905
21906 elsif Nkind_In (List, N_Expanded_Name,
21907 N_Identifier,
21908 N_Selected_Component)
21909 then
21910 Collect_Global_Item (List, Mode);
21911
21912 -- Simple global list or moded global list declaration
21913
21914 elsif Nkind (List) = N_Aggregate then
21915 if Present (Expressions (List)) then
21916 Item := First (Expressions (List));
21917 while Present (Item) loop
21918 Collect_Global_Item (Item, Mode);
21919 Next (Item);
21920 end loop;
21921
21922 else
21923 Assoc := First (Component_Associations (List));
21924 while Present (Assoc) loop
21925 Collect_Global_List
21926 (List => Expression (Assoc),
21927 Mode => Chars (First (Choices (Assoc))));
21928 Next (Assoc);
21929 end loop;
21930 end if;
21931
21932 -- Invalid list
21933
21934 else
21935 raise Program_Error;
21936 end if;
21937 end Collect_Global_List;
21938
21939 -- Local variables
21940
21941 Formal : Entity_Id;
21942 Global : Node_Id;
21943 List : Node_Id;
21944 Spec_Id : Entity_Id;
21945
21946 -- Start of processing for Collect_Subprogram_Inputs_Outputs
21947
21948 begin
21949 Global_Seen := False;
21950
21951 -- Find the entity of the corresponding spec when processing a body
21952
21953 if Ekind (Subp_Id) = E_Subprogram_Body then
21954 Spec_Id := Corresponding_Spec (Parent (Parent (Subp_Id)));
21955 else
21956 Spec_Id := Subp_Id;
21957 end if;
21958
21959 -- Process all formal parameters
21960
21961 Formal := First_Formal (Spec_Id);
21962 while Present (Formal) loop
21963 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
21964 Add_Item (Formal, Subp_Inputs);
21965 end if;
21966
21967 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
21968 Add_Item (Formal, Subp_Outputs);
21969
21970 -- Out parameters can act as inputs when the related type is
21971 -- tagged, unconstrained array, unconstrained record or record
21972 -- with unconstrained components.
21973
21974 if Ekind (Formal) = E_Out_Parameter
21975 and then Is_Unconstrained_Or_Tagged_Item (Formal)
21976 then
21977 Add_Item (Formal, Subp_Inputs);
21978 end if;
21979 end if;
21980
21981 Next_Formal (Formal);
21982 end loop;
21983
21984 -- When processing a subprogram body, look for pragma Refined_Global as
21985 -- it provides finer granularity of inputs and outputs.
21986
21987 if Ekind (Subp_Id) = E_Subprogram_Body then
21988 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
21989
21990 -- Subprogram declaration case, look for pragma Global
21991
21992 else
21993 Global := Get_Pragma (Spec_Id, Pragma_Global);
21994 end if;
21995
21996 if Present (Global) then
21997 Global_Seen := True;
21998 List := Expression (First (Pragma_Argument_Associations (Global)));
21999
22000 -- The pragma may not have been analyzed because of the arbitrary
22001 -- declaration order of aspects. Make sure that it is analyzed for
22002 -- the purposes of item extraction.
22003
22004 if not Analyzed (List) then
22005 if Pragma_Name (Global) = Name_Refined_Global then
22006 Analyze_Refined_Global_In_Decl_Part (Global);
22007 else
22008 Analyze_Global_In_Decl_Part (Global);
22009 end if;
22010 end if;
22011
22012 -- Nothing to be done for a null global list
22013
22014 if Nkind (List) /= N_Null then
22015 Collect_Global_List (List);
22016 end if;
22017 end if;
22018 end Collect_Subprogram_Inputs_Outputs;
22019
22020 ---------------------------------
22021 -- Delay_Config_Pragma_Analyze --
22022 ---------------------------------
22023
22024 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
22025 begin
22026 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
22027 Name_Priority_Specific_Dispatching);
22028 end Delay_Config_Pragma_Analyze;
22029
22030 -------------------------------------
22031 -- Find_Related_Subprogram_Or_Body --
22032 -------------------------------------
22033
22034 function Find_Related_Subprogram_Or_Body
22035 (Prag : Node_Id;
22036 Do_Checks : Boolean := False) return Node_Id
22037 is
22038 Context : constant Node_Id := Parent (Prag);
22039 Nam : constant Name_Id := Pragma_Name (Prag);
22040 Stmt : Node_Id;
22041
22042 Look_For_Body : constant Boolean :=
22043 Nam_In (Nam, Name_Refined_Depends,
22044 Name_Refined_Global,
22045 Name_Refined_Post,
22046 Name_Refined_Pre);
22047 -- Refinement pragmas must be associated with a subprogram body [stub]
22048
22049 begin
22050 pragma Assert (Nkind (Prag) = N_Pragma);
22051
22052 -- If the pragma is a byproduct of aspect expansion, return the related
22053 -- context of the original aspect.
22054
22055 if Present (Corresponding_Aspect (Prag)) then
22056 return Parent (Corresponding_Aspect (Prag));
22057 end if;
22058
22059 -- Otherwise the pragma is a source construct, most likely part of a
22060 -- declarative list. Skip preceding declarations while looking for a
22061 -- proper subprogram declaration.
22062
22063 pragma Assert (Is_List_Member (Prag));
22064
22065 Stmt := Prev (Prag);
22066 while Present (Stmt) loop
22067
22068 -- Skip prior pragmas, but check for duplicates
22069
22070 if Nkind (Stmt) = N_Pragma then
22071 if Do_Checks and then Pragma_Name (Stmt) = Nam then
22072 Error_Msg_Name_1 := Nam;
22073 Error_Msg_Sloc := Sloc (Stmt);
22074 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
22075 end if;
22076
22077 -- Emit an error when a refinement pragma appears on an expression
22078 -- function without a completion.
22079
22080 elsif Do_Checks
22081 and then Look_For_Body
22082 and then Nkind (Stmt) = N_Subprogram_Declaration
22083 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
22084 and then not Has_Completion (Defining_Entity (Stmt))
22085 then
22086 Error_Msg_Name_1 := Nam;
22087 Error_Msg_N
22088 ("pragma % cannot apply to a stand alone expression function",
22089 Prag);
22090
22091 return Empty;
22092
22093 -- The refinement pragma applies to a subprogram body stub
22094
22095 elsif Look_For_Body
22096 and then Nkind (Stmt) = N_Subprogram_Body_Stub
22097 then
22098 return Stmt;
22099
22100 -- Skip internally generated code
22101
22102 elsif not Comes_From_Source (Stmt) then
22103 null;
22104
22105 -- Return the current construct which is either a subprogram body,
22106 -- a subprogram declaration or is illegal.
22107
22108 else
22109 return Stmt;
22110 end if;
22111
22112 Prev (Stmt);
22113 end loop;
22114
22115 -- If we fall through, then the pragma was either the first declaration
22116 -- or it was preceded by other pragmas and no source constructs.
22117
22118 -- The pragma is associated with a library-level subprogram
22119
22120 if Nkind (Context) = N_Compilation_Unit_Aux then
22121 return Unit (Parent (Context));
22122
22123 -- The pragma appears inside the declarative part of a subprogram body
22124
22125 elsif Nkind (Context) = N_Subprogram_Body then
22126 return Context;
22127
22128 -- No candidate subprogram [body] found
22129
22130 else
22131 return Empty;
22132 end if;
22133 end Find_Related_Subprogram_Or_Body;
22134
22135 -------------------------
22136 -- Get_Base_Subprogram --
22137 -------------------------
22138
22139 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
22140 Result : Entity_Id;
22141
22142 begin
22143 -- Follow subprogram renaming chain
22144
22145 Result := Def_Id;
22146
22147 if Is_Subprogram (Result)
22148 and then
22149 Nkind (Parent (Declaration_Node (Result))) =
22150 N_Subprogram_Renaming_Declaration
22151 and then Present (Alias (Result))
22152 then
22153 Result := Alias (Result);
22154 end if;
22155
22156 return Result;
22157 end Get_Base_Subprogram;
22158
22159 -----------------------
22160 -- Get_SPARK_Mode_Id --
22161 -----------------------
22162
22163 function Get_SPARK_Mode_Id (N : Name_Id) return SPARK_Mode_Id is
22164 begin
22165 if N = Name_On then
22166 return SPARK_On;
22167 elsif N = Name_Off then
22168 return SPARK_Off;
22169 elsif N = Name_Auto then
22170 return SPARK_Auto;
22171
22172 -- Any other argument is erroneous
22173
22174 else
22175 raise Program_Error;
22176 end if;
22177 end Get_SPARK_Mode_Id;
22178
22179 -----------------------
22180 -- Get_SPARK_Mode_Id --
22181 -----------------------
22182
22183 function Get_SPARK_Mode_Id (N : Node_Id) return SPARK_Mode_Id is
22184 Args : List_Id;
22185 Mode : Node_Id;
22186
22187 begin
22188 pragma Assert (Nkind (N) = N_Pragma);
22189 Args := Pragma_Argument_Associations (N);
22190
22191 -- Extract the mode from the argument list
22192
22193 if Present (Args) then
22194 Mode := First (Pragma_Argument_Associations (N));
22195 return Get_SPARK_Mode_Id (Chars (Get_Pragma_Arg (Mode)));
22196
22197 -- When SPARK_Mode appears without an argument, the default is ON
22198
22199 else
22200 return SPARK_On;
22201 end if;
22202 end Get_SPARK_Mode_Id;
22203
22204 ----------------
22205 -- Initialize --
22206 ----------------
22207
22208 procedure Initialize is
22209 begin
22210 Externals.Init;
22211 end Initialize;
22212
22213 -----------------------------
22214 -- Is_Config_Static_String --
22215 -----------------------------
22216
22217 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
22218
22219 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
22220 -- This is an internal recursive function that is just like the outer
22221 -- function except that it adds the string to the name buffer rather
22222 -- than placing the string in the name buffer.
22223
22224 ------------------------------
22225 -- Add_Config_Static_String --
22226 ------------------------------
22227
22228 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
22229 N : Node_Id;
22230 C : Char_Code;
22231
22232 begin
22233 N := Arg;
22234
22235 if Nkind (N) = N_Op_Concat then
22236 if Add_Config_Static_String (Left_Opnd (N)) then
22237 N := Right_Opnd (N);
22238 else
22239 return False;
22240 end if;
22241 end if;
22242
22243 if Nkind (N) /= N_String_Literal then
22244 Error_Msg_N ("string literal expected for pragma argument", N);
22245 return False;
22246
22247 else
22248 for J in 1 .. String_Length (Strval (N)) loop
22249 C := Get_String_Char (Strval (N), J);
22250
22251 if not In_Character_Range (C) then
22252 Error_Msg
22253 ("string literal contains invalid wide character",
22254 Sloc (N) + 1 + Source_Ptr (J));
22255 return False;
22256 end if;
22257
22258 Add_Char_To_Name_Buffer (Get_Character (C));
22259 end loop;
22260 end if;
22261
22262 return True;
22263 end Add_Config_Static_String;
22264
22265 -- Start of processing for Is_Config_Static_String
22266
22267 begin
22268 Name_Len := 0;
22269
22270 return Add_Config_Static_String (Arg);
22271 end Is_Config_Static_String;
22272
22273 -------------------------------
22274 -- Is_Elaboration_SPARK_Mode --
22275 -------------------------------
22276
22277 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
22278 begin
22279 pragma Assert
22280 (Nkind (N) = N_Pragma
22281 and then Pragma_Name (N) = Name_SPARK_Mode
22282 and then Is_List_Member (N));
22283
22284 -- Pragma SPARK_Mode affects the elaboration of a package body when it
22285 -- appears in the statement part of the body.
22286
22287 return
22288 Present (Parent (N))
22289 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
22290 and then List_Containing (N) = Statements (Parent (N))
22291 and then Present (Parent (Parent (N)))
22292 and then Nkind (Parent (Parent (N))) = N_Package_Body;
22293 end Is_Elaboration_SPARK_Mode;
22294
22295 -----------------------------------------
22296 -- Is_Non_Significant_Pragma_Reference --
22297 -----------------------------------------
22298
22299 -- This function makes use of the following static table which indicates
22300 -- whether appearance of some name in a given pragma is to be considered
22301 -- as a reference for the purposes of warnings about unreferenced objects.
22302
22303 -- -1 indicates that references in any argument position are significant
22304 -- 0 indicates that appearance in any argument is not significant
22305 -- +n indicates that appearance as argument n is significant, but all
22306 -- other arguments are not significant
22307 -- 99 special processing required (e.g. for pragma Check)
22308
22309 Sig_Flags : constant array (Pragma_Id) of Int :=
22310 (Pragma_AST_Entry => -1,
22311 Pragma_Abort_Defer => -1,
22312 Pragma_Abstract_State => -1,
22313 Pragma_Ada_83 => -1,
22314 Pragma_Ada_95 => -1,
22315 Pragma_Ada_05 => -1,
22316 Pragma_Ada_2005 => -1,
22317 Pragma_Ada_12 => -1,
22318 Pragma_Ada_2012 => -1,
22319 Pragma_All_Calls_Remote => -1,
22320 Pragma_Annotate => -1,
22321 Pragma_Assert => -1,
22322 Pragma_Assert_And_Cut => -1,
22323 Pragma_Assertion_Policy => 0,
22324 Pragma_Assume => -1,
22325 Pragma_Assume_No_Invalid_Values => 0,
22326 Pragma_Attribute_Definition => +3,
22327 Pragma_Asynchronous => -1,
22328 Pragma_Atomic => 0,
22329 Pragma_Atomic_Components => 0,
22330 Pragma_Attach_Handler => -1,
22331 Pragma_Check => 99,
22332 Pragma_Check_Float_Overflow => 0,
22333 Pragma_Check_Name => 0,
22334 Pragma_Check_Policy => 0,
22335 Pragma_CIL_Constructor => -1,
22336 Pragma_CPP_Class => 0,
22337 Pragma_CPP_Constructor => 0,
22338 Pragma_CPP_Virtual => 0,
22339 Pragma_CPP_Vtable => 0,
22340 Pragma_CPU => -1,
22341 Pragma_C_Pass_By_Copy => 0,
22342 Pragma_Comment => 0,
22343 Pragma_Common_Object => -1,
22344 Pragma_Compile_Time_Error => -1,
22345 Pragma_Compile_Time_Warning => -1,
22346 Pragma_Compiler_Unit => 0,
22347 Pragma_Complete_Representation => 0,
22348 Pragma_Complex_Representation => 0,
22349 Pragma_Component_Alignment => -1,
22350 Pragma_Contract_Cases => -1,
22351 Pragma_Controlled => 0,
22352 Pragma_Convention => 0,
22353 Pragma_Convention_Identifier => 0,
22354 Pragma_Debug => -1,
22355 Pragma_Debug_Policy => 0,
22356 Pragma_Detect_Blocking => -1,
22357 Pragma_Default_Storage_Pool => -1,
22358 Pragma_Depends => -1,
22359 Pragma_Disable_Atomic_Synchronization => -1,
22360 Pragma_Discard_Names => 0,
22361 Pragma_Dispatching_Domain => -1,
22362 Pragma_Elaborate => -1,
22363 Pragma_Elaborate_All => -1,
22364 Pragma_Elaborate_Body => -1,
22365 Pragma_Elaboration_Checks => -1,
22366 Pragma_Eliminate => -1,
22367 Pragma_Enable_Atomic_Synchronization => -1,
22368 Pragma_Export => -1,
22369 Pragma_Export_Exception => -1,
22370 Pragma_Export_Function => -1,
22371 Pragma_Export_Object => -1,
22372 Pragma_Export_Procedure => -1,
22373 Pragma_Export_Value => -1,
22374 Pragma_Export_Valued_Procedure => -1,
22375 Pragma_Extend_System => -1,
22376 Pragma_Extensions_Allowed => -1,
22377 Pragma_External => -1,
22378 Pragma_Favor_Top_Level => -1,
22379 Pragma_External_Name_Casing => -1,
22380 Pragma_Fast_Math => -1,
22381 Pragma_Finalize_Storage_Only => 0,
22382 Pragma_Float_Representation => 0,
22383 Pragma_Global => -1,
22384 Pragma_Ident => -1,
22385 Pragma_Implementation_Defined => -1,
22386 Pragma_Implemented => -1,
22387 Pragma_Implicit_Packing => 0,
22388 Pragma_Import => +2,
22389 Pragma_Import_Exception => 0,
22390 Pragma_Import_Function => 0,
22391 Pragma_Import_Object => 0,
22392 Pragma_Import_Procedure => 0,
22393 Pragma_Import_Valued_Procedure => 0,
22394 Pragma_Independent => 0,
22395 Pragma_Independent_Components => 0,
22396 Pragma_Initialize_Scalars => -1,
22397 Pragma_Initializes => -1,
22398 Pragma_Inline => 0,
22399 Pragma_Inline_Always => 0,
22400 Pragma_Inline_Generic => 0,
22401 Pragma_Inspection_Point => -1,
22402 Pragma_Interface => +2,
22403 Pragma_Interface_Name => +2,
22404 Pragma_Interrupt_Handler => -1,
22405 Pragma_Interrupt_Priority => -1,
22406 Pragma_Interrupt_State => -1,
22407 Pragma_Invariant => -1,
22408 Pragma_Java_Constructor => -1,
22409 Pragma_Java_Interface => -1,
22410 Pragma_Keep_Names => 0,
22411 Pragma_License => -1,
22412 Pragma_Link_With => -1,
22413 Pragma_Linker_Alias => -1,
22414 Pragma_Linker_Constructor => -1,
22415 Pragma_Linker_Destructor => -1,
22416 Pragma_Linker_Options => -1,
22417 Pragma_Linker_Section => -1,
22418 Pragma_List => -1,
22419 Pragma_Lock_Free => -1,
22420 Pragma_Locking_Policy => -1,
22421 Pragma_Long_Float => -1,
22422 Pragma_Loop_Invariant => -1,
22423 Pragma_Loop_Optimize => -1,
22424 Pragma_Loop_Variant => -1,
22425 Pragma_Machine_Attribute => -1,
22426 Pragma_Main => -1,
22427 Pragma_Main_Storage => -1,
22428 Pragma_Memory_Size => -1,
22429 Pragma_No_Return => 0,
22430 Pragma_No_Body => 0,
22431 Pragma_No_Inline => 0,
22432 Pragma_No_Run_Time => -1,
22433 Pragma_No_Strict_Aliasing => -1,
22434 Pragma_Normalize_Scalars => -1,
22435 Pragma_Obsolescent => 0,
22436 Pragma_Optimize => -1,
22437 Pragma_Optimize_Alignment => -1,
22438 Pragma_Overflow_Mode => 0,
22439 Pragma_Overriding_Renamings => 0,
22440 Pragma_Ordered => 0,
22441 Pragma_Pack => 0,
22442 Pragma_Page => -1,
22443 Pragma_Partition_Elaboration_Policy => -1,
22444 Pragma_Passive => -1,
22445 Pragma_Persistent_BSS => 0,
22446 Pragma_Polling => -1,
22447 Pragma_Post => -1,
22448 Pragma_Postcondition => -1,
22449 Pragma_Post_Class => -1,
22450 Pragma_Pre => -1,
22451 Pragma_Precondition => -1,
22452 Pragma_Predicate => -1,
22453 Pragma_Preelaborable_Initialization => -1,
22454 Pragma_Preelaborate => -1,
22455 Pragma_Preelaborate_05 => -1,
22456 Pragma_Pre_Class => -1,
22457 Pragma_Priority => -1,
22458 Pragma_Priority_Specific_Dispatching => -1,
22459 Pragma_Profile => 0,
22460 Pragma_Profile_Warnings => 0,
22461 Pragma_Propagate_Exceptions => -1,
22462 Pragma_Psect_Object => -1,
22463 Pragma_Pure => -1,
22464 Pragma_Pure_05 => -1,
22465 Pragma_Pure_12 => -1,
22466 Pragma_Pure_Function => -1,
22467 Pragma_Queuing_Policy => -1,
22468 Pragma_Rational => -1,
22469 Pragma_Ravenscar => -1,
22470 Pragma_Refined_Depends => -1,
22471 Pragma_Refined_Global => -1,
22472 Pragma_Refined_Post => -1,
22473 Pragma_Refined_Pre => -1,
22474 Pragma_Refined_State => -1,
22475 Pragma_Relative_Deadline => -1,
22476 Pragma_Remote_Access_Type => -1,
22477 Pragma_Remote_Call_Interface => -1,
22478 Pragma_Remote_Types => -1,
22479 Pragma_Restricted_Run_Time => -1,
22480 Pragma_Restriction_Warnings => -1,
22481 Pragma_Restrictions => -1,
22482 Pragma_Reviewable => -1,
22483 Pragma_Short_Circuit_And_Or => -1,
22484 Pragma_Share_Generic => -1,
22485 Pragma_Shared => -1,
22486 Pragma_Shared_Passive => -1,
22487 Pragma_Short_Descriptors => 0,
22488 Pragma_Simple_Storage_Pool_Type => 0,
22489 Pragma_Source_File_Name => -1,
22490 Pragma_Source_File_Name_Project => -1,
22491 Pragma_Source_Reference => -1,
22492 Pragma_SPARK_Mode => 0,
22493 Pragma_Storage_Size => -1,
22494 Pragma_Storage_Unit => -1,
22495 Pragma_Static_Elaboration_Desired => -1,
22496 Pragma_Stream_Convert => -1,
22497 Pragma_Style_Checks => -1,
22498 Pragma_Subtitle => -1,
22499 Pragma_Suppress => 0,
22500 Pragma_Suppress_Exception_Locations => 0,
22501 Pragma_Suppress_All => -1,
22502 Pragma_Suppress_Debug_Info => 0,
22503 Pragma_Suppress_Initialization => 0,
22504 Pragma_System_Name => -1,
22505 Pragma_Task_Dispatching_Policy => -1,
22506 Pragma_Task_Info => -1,
22507 Pragma_Task_Name => -1,
22508 Pragma_Task_Storage => 0,
22509 Pragma_Test_Case => -1,
22510 Pragma_Thread_Local_Storage => 0,
22511 Pragma_Time_Slice => -1,
22512 Pragma_Title => -1,
22513 Pragma_Type_Invariant => -1,
22514 Pragma_Type_Invariant_Class => -1,
22515 Pragma_Unchecked_Union => 0,
22516 Pragma_Unimplemented_Unit => -1,
22517 Pragma_Universal_Aliasing => -1,
22518 Pragma_Universal_Data => -1,
22519 Pragma_Unmodified => -1,
22520 Pragma_Unreferenced => -1,
22521 Pragma_Unreferenced_Objects => -1,
22522 Pragma_Unreserve_All_Interrupts => -1,
22523 Pragma_Unsuppress => 0,
22524 Pragma_Use_VADS_Size => -1,
22525 Pragma_Validity_Checks => -1,
22526 Pragma_Volatile => 0,
22527 Pragma_Volatile_Components => 0,
22528 Pragma_Warnings => -1,
22529 Pragma_Weak_External => -1,
22530 Pragma_Wide_Character_Encoding => 0,
22531 Unknown_Pragma => 0);
22532
22533 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
22534 Id : Pragma_Id;
22535 P : Node_Id;
22536 C : Int;
22537 A : Node_Id;
22538
22539 begin
22540 P := Parent (N);
22541
22542 if Nkind (P) /= N_Pragma_Argument_Association then
22543 return False;
22544
22545 else
22546 Id := Get_Pragma_Id (Parent (P));
22547 C := Sig_Flags (Id);
22548
22549 case C is
22550 when -1 =>
22551 return False;
22552
22553 when 0 =>
22554 return True;
22555
22556 when 99 =>
22557 case Id is
22558
22559 -- For pragma Check, the first argument is not significant,
22560 -- the second and the third (if present) arguments are
22561 -- significant.
22562
22563 when Pragma_Check =>
22564 return
22565 P = First (Pragma_Argument_Associations (Parent (P)));
22566
22567 when others =>
22568 raise Program_Error;
22569 end case;
22570
22571 when others =>
22572 A := First (Pragma_Argument_Associations (Parent (P)));
22573 for J in 1 .. C - 1 loop
22574 if No (A) then
22575 return False;
22576 end if;
22577
22578 Next (A);
22579 end loop;
22580
22581 return A = P; -- is this wrong way round ???
22582 end case;
22583 end if;
22584 end Is_Non_Significant_Pragma_Reference;
22585
22586 ----------------
22587 -- Is_Part_Of --
22588 ----------------
22589
22590 function Is_Part_Of
22591 (State : Entity_Id;
22592 Ancestor : Entity_Id) return Boolean
22593 is
22594 Options : constant Node_Id := Parent (State);
22595 Name : Node_Id;
22596 Option : Node_Id;
22597 Value : Node_Id;
22598
22599 begin
22600 -- A state declaration with option Part_Of appears as an extension
22601 -- aggregate with component associations.
22602
22603 if Nkind (Options) = N_Extension_Aggregate then
22604 Option := First (Component_Associations (Options));
22605 while Present (Option) loop
22606 Name := First (Choices (Option));
22607 Value := Expression (Option);
22608
22609 if Chars (Name) = Name_Part_Of then
22610 return Entity (Value) = Ancestor;
22611 end if;
22612
22613 Next (Option);
22614 end loop;
22615 end if;
22616
22617 return False;
22618 end Is_Part_Of;
22619
22620 ------------------------------
22621 -- Is_Pragma_String_Literal --
22622 ------------------------------
22623
22624 -- This function returns true if the corresponding pragma argument is a
22625 -- static string expression. These are the only cases in which string
22626 -- literals can appear as pragma arguments. We also allow a string literal
22627 -- as the first argument to pragma Assert (although it will of course
22628 -- always generate a type error).
22629
22630 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
22631 Pragn : constant Node_Id := Parent (Par);
22632 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
22633 Pname : constant Name_Id := Pragma_Name (Pragn);
22634 Argn : Natural;
22635 N : Node_Id;
22636
22637 begin
22638 Argn := 1;
22639 N := First (Assoc);
22640 loop
22641 exit when N = Par;
22642 Argn := Argn + 1;
22643 Next (N);
22644 end loop;
22645
22646 if Pname = Name_Assert then
22647 return True;
22648
22649 elsif Pname = Name_Export then
22650 return Argn > 2;
22651
22652 elsif Pname = Name_Ident then
22653 return Argn = 1;
22654
22655 elsif Pname = Name_Import then
22656 return Argn > 2;
22657
22658 elsif Pname = Name_Interface_Name then
22659 return Argn > 1;
22660
22661 elsif Pname = Name_Linker_Alias then
22662 return Argn = 2;
22663
22664 elsif Pname = Name_Linker_Section then
22665 return Argn = 2;
22666
22667 elsif Pname = Name_Machine_Attribute then
22668 return Argn = 2;
22669
22670 elsif Pname = Name_Source_File_Name then
22671 return True;
22672
22673 elsif Pname = Name_Source_Reference then
22674 return Argn = 2;
22675
22676 elsif Pname = Name_Title then
22677 return True;
22678
22679 elsif Pname = Name_Subtitle then
22680 return True;
22681
22682 else
22683 return False;
22684 end if;
22685 end Is_Pragma_String_Literal;
22686
22687 ---------------------------
22688 -- Is_Private_SPARK_Mode --
22689 ---------------------------
22690
22691 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
22692 begin
22693 pragma Assert
22694 (Nkind (N) = N_Pragma
22695 and then Pragma_Name (N) = Name_SPARK_Mode
22696 and then Is_List_Member (N));
22697
22698 -- For pragma SPARK_Mode to be private, it has to appear in the private
22699 -- declarations of a package.
22700
22701 return
22702 Present (Parent (N))
22703 and then Nkind (Parent (N)) = N_Package_Specification
22704 and then List_Containing (N) = Private_Declarations (Parent (N));
22705 end Is_Private_SPARK_Mode;
22706
22707 -------------------------------------
22708 -- Is_Unconstrained_Or_Tagged_Item --
22709 -------------------------------------
22710
22711 function Is_Unconstrained_Or_Tagged_Item
22712 (Item : Entity_Id) return Boolean
22713 is
22714 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
22715 -- Determine whether record type Typ has at least one unconstrained
22716 -- component.
22717
22718 ---------------------------------
22719 -- Has_Unconstrained_Component --
22720 ---------------------------------
22721
22722 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
22723 Comp : Entity_Id;
22724
22725 begin
22726 Comp := First_Component (Typ);
22727 while Present (Comp) loop
22728 if Is_Unconstrained_Or_Tagged_Item (Comp) then
22729 return True;
22730 end if;
22731
22732 Next_Component (Comp);
22733 end loop;
22734
22735 return False;
22736 end Has_Unconstrained_Component;
22737
22738 -- Local variables
22739
22740 Typ : constant Entity_Id := Etype (Item);
22741
22742 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
22743
22744 begin
22745 if Is_Tagged_Type (Typ) then
22746 return True;
22747
22748 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
22749 return True;
22750
22751 elsif Is_Record_Type (Typ) then
22752 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
22753 return True;
22754 else
22755 return Has_Unconstrained_Component (Typ);
22756 end if;
22757
22758 else
22759 return False;
22760 end if;
22761 end Is_Unconstrained_Or_Tagged_Item;
22762
22763 -----------------------------
22764 -- Is_Valid_Assertion_Kind --
22765 -----------------------------
22766
22767 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
22768 begin
22769 case Nam is
22770 when
22771 -- RM defined
22772
22773 Name_Assert |
22774 Name_Static_Predicate |
22775 Name_Dynamic_Predicate |
22776 Name_Pre |
22777 Name_uPre |
22778 Name_Post |
22779 Name_uPost |
22780 Name_Type_Invariant |
22781 Name_uType_Invariant |
22782
22783 -- Impl defined
22784
22785 Name_Assert_And_Cut |
22786 Name_Assume |
22787 Name_Contract_Cases |
22788 Name_Debug |
22789 Name_Invariant |
22790 Name_uInvariant |
22791 Name_Loop_Invariant |
22792 Name_Loop_Variant |
22793 Name_Postcondition |
22794 Name_Precondition |
22795 Name_Predicate |
22796 Name_Refined_Post |
22797 Name_Refined_Pre |
22798 Name_Statement_Assertions => return True;
22799
22800 when others => return False;
22801 end case;
22802 end Is_Valid_Assertion_Kind;
22803
22804 -----------------------------------------
22805 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
22806 -----------------------------------------
22807
22808 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
22809 Aspects : constant List_Id := New_List;
22810 Loc : constant Source_Ptr := Sloc (Decl);
22811 Or_Decl : constant Node_Id := Original_Node (Decl);
22812
22813 Original_Aspects : List_Id;
22814 -- To capture global references, a copy of the created aspects must be
22815 -- inserted in the original tree.
22816
22817 Prag : Node_Id;
22818 Prag_Arg_Ass : Node_Id;
22819 Prag_Id : Pragma_Id;
22820
22821 begin
22822 -- Check for any PPC pragmas that appear within Decl
22823
22824 Prag := Next (Decl);
22825 while Nkind (Prag) = N_Pragma loop
22826 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
22827
22828 case Prag_Id is
22829 when Pragma_Postcondition | Pragma_Precondition =>
22830 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
22831
22832 -- Make an aspect from any PPC pragma
22833
22834 Append_To (Aspects,
22835 Make_Aspect_Specification (Loc,
22836 Identifier =>
22837 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
22838 Expression =>
22839 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
22840
22841 -- Generate the analysis information in the pragma expression
22842 -- and then set the pragma node analyzed to avoid any further
22843 -- analysis.
22844
22845 Analyze (Expression (Prag_Arg_Ass));
22846 Set_Analyzed (Prag, True);
22847
22848 when others => null;
22849 end case;
22850
22851 Next (Prag);
22852 end loop;
22853
22854 -- Set all new aspects into the generic declaration node
22855
22856 if Is_Non_Empty_List (Aspects) then
22857
22858 -- Create the list of aspects to be inserted in the original tree
22859
22860 Original_Aspects := Copy_Separate_List (Aspects);
22861
22862 -- Check if Decl already has aspects
22863
22864 -- Attach the new lists of aspects to both the generic copy and the
22865 -- original tree.
22866
22867 if Has_Aspects (Decl) then
22868 Append_List (Aspects, Aspect_Specifications (Decl));
22869 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
22870
22871 else
22872 Set_Parent (Aspects, Decl);
22873 Set_Aspect_Specifications (Decl, Aspects);
22874 Set_Parent (Original_Aspects, Or_Decl);
22875 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
22876 end if;
22877 end if;
22878 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
22879
22880 -------------------------
22881 -- Preanalyze_CTC_Args --
22882 -------------------------
22883
22884 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
22885 begin
22886 -- Preanalyze the boolean expressions, we treat these as spec
22887 -- expressions (i.e. similar to a default expression).
22888
22889 if Present (Arg_Req) then
22890 Preanalyze_Assert_Expression
22891 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
22892
22893 -- In ASIS mode, for a pragma generated from a source aspect, also
22894 -- analyze the original aspect expression.
22895
22896 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
22897 Preanalyze_Assert_Expression
22898 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
22899 end if;
22900 end if;
22901
22902 if Present (Arg_Ens) then
22903 Preanalyze_Assert_Expression
22904 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
22905
22906 -- In ASIS mode, for a pragma generated from a source aspect, also
22907 -- analyze the original aspect expression.
22908
22909 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
22910 Preanalyze_Assert_Expression
22911 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
22912 end if;
22913 end if;
22914 end Preanalyze_CTC_Args;
22915
22916 --------------------------------------
22917 -- Process_Compilation_Unit_Pragmas --
22918 --------------------------------------
22919
22920 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
22921 begin
22922 -- A special check for pragma Suppress_All, a very strange DEC pragma,
22923 -- strange because it comes at the end of the unit. Rational has the
22924 -- same name for a pragma, but treats it as a program unit pragma, In
22925 -- GNAT we just decide to allow it anywhere at all. If it appeared then
22926 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
22927 -- node, and we insert a pragma Suppress (All_Checks) at the start of
22928 -- the context clause to ensure the correct processing.
22929
22930 if Has_Pragma_Suppress_All (N) then
22931 Prepend_To (Context_Items (N),
22932 Make_Pragma (Sloc (N),
22933 Chars => Name_Suppress,
22934 Pragma_Argument_Associations => New_List (
22935 Make_Pragma_Argument_Association (Sloc (N),
22936 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
22937 end if;
22938
22939 -- Nothing else to do at the current time!
22940
22941 end Process_Compilation_Unit_Pragmas;
22942
22943 ------------------------------
22944 -- Relocate_Pragmas_To_Body --
22945 ------------------------------
22946
22947 procedure Relocate_Pragmas_To_Body
22948 (Subp_Body : Node_Id;
22949 Target_Body : Node_Id := Empty)
22950 is
22951 procedure Relocate_Pragma (Prag : Node_Id);
22952 -- Remove a single pragma from its current list and add it to the
22953 -- declarations of the proper body (either Subp_Body or Target_Body).
22954
22955 ---------------------
22956 -- Relocate_Pragma --
22957 ---------------------
22958
22959 procedure Relocate_Pragma (Prag : Node_Id) is
22960 Decls : List_Id;
22961 Target : Node_Id;
22962
22963 begin
22964 -- When subprogram stubs or expression functions are involves, the
22965 -- destination declaration list belongs to the proper body.
22966
22967 if Present (Target_Body) then
22968 Target := Target_Body;
22969 else
22970 Target := Subp_Body;
22971 end if;
22972
22973 Decls := Declarations (Target);
22974
22975 if No (Decls) then
22976 Decls := New_List;
22977 Set_Declarations (Target, Decls);
22978 end if;
22979
22980 -- Unhook the pragma from its current list
22981
22982 Remove (Prag);
22983 Prepend (Prag, Decls);
22984 end Relocate_Pragma;
22985
22986 -- Local variables
22987
22988 Body_Id : constant Entity_Id :=
22989 Defining_Unit_Name (Specification (Subp_Body));
22990 Next_Stmt : Node_Id;
22991 Stmt : Node_Id;
22992
22993 -- Start of processing for Relocate_Pragmas_To_Body
22994
22995 begin
22996 -- Do not process a body that comes from a separate unit as no construct
22997 -- can possibly follow it.
22998
22999 if not Is_List_Member (Subp_Body) then
23000 return;
23001
23002 -- Do not relocate pragmas that follow a stub if the stub does not have
23003 -- a proper body.
23004
23005 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
23006 and then No (Target_Body)
23007 then
23008 return;
23009
23010 -- Do not process internally generated routine _Postconditions
23011
23012 elsif Ekind (Body_Id) = E_Procedure
23013 and then Chars (Body_Id) = Name_uPostconditions
23014 then
23015 return;
23016 end if;
23017
23018 -- Look at what is following the body. We are interested in certain kind
23019 -- of pragmas (either from source or byproducts of expansion) that can
23020 -- apply to a body [stub].
23021
23022 Stmt := Next (Subp_Body);
23023 while Present (Stmt) loop
23024
23025 -- Preserve the following statement for iteration purposes due to a
23026 -- possible relocation of a pragma.
23027
23028 Next_Stmt := Next (Stmt);
23029
23030 -- Move a candidate pragma following the body to the declarations of
23031 -- the body.
23032
23033 if Nkind (Stmt) = N_Pragma
23034 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
23035 then
23036 Relocate_Pragma (Stmt);
23037
23038 -- Skip internally generated code
23039
23040 elsif not Comes_From_Source (Stmt) then
23041 null;
23042
23043 -- No candidate pragmas are available for relocation
23044
23045 else
23046 exit;
23047 end if;
23048
23049 Stmt := Next_Stmt;
23050 end loop;
23051 end Relocate_Pragmas_To_Body;
23052
23053 ----------------------------
23054 -- Rewrite_Assertion_Kind --
23055 ----------------------------
23056
23057 procedure Rewrite_Assertion_Kind (N : Node_Id) is
23058 Nam : Name_Id;
23059
23060 begin
23061 if Nkind (N) = N_Attribute_Reference
23062 and then Attribute_Name (N) = Name_Class
23063 and then Nkind (Prefix (N)) = N_Identifier
23064 then
23065 case Chars (Prefix (N)) is
23066 when Name_Pre =>
23067 Nam := Name_uPre;
23068 when Name_Post =>
23069 Nam := Name_uPost;
23070 when Name_Type_Invariant =>
23071 Nam := Name_uType_Invariant;
23072 when Name_Invariant =>
23073 Nam := Name_uInvariant;
23074 when others =>
23075 return;
23076 end case;
23077
23078 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
23079 end if;
23080 end Rewrite_Assertion_Kind;
23081
23082 --------
23083 -- rv --
23084 --------
23085
23086 procedure rv is
23087 begin
23088 null;
23089 end rv;
23090
23091 --------------------------------
23092 -- Set_Encoded_Interface_Name --
23093 --------------------------------
23094
23095 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
23096 Str : constant String_Id := Strval (S);
23097 Len : constant Int := String_Length (Str);
23098 CC : Char_Code;
23099 C : Character;
23100 J : Int;
23101
23102 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
23103
23104 procedure Encode;
23105 -- Stores encoded value of character code CC. The encoding we use an
23106 -- underscore followed by four lower case hex digits.
23107
23108 ------------
23109 -- Encode --
23110 ------------
23111
23112 procedure Encode is
23113 begin
23114 Store_String_Char (Get_Char_Code ('_'));
23115 Store_String_Char
23116 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
23117 Store_String_Char
23118 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
23119 Store_String_Char
23120 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
23121 Store_String_Char
23122 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
23123 end Encode;
23124
23125 -- Start of processing for Set_Encoded_Interface_Name
23126
23127 begin
23128 -- If first character is asterisk, this is a link name, and we leave it
23129 -- completely unmodified. We also ignore null strings (the latter case
23130 -- happens only in error cases) and no encoding should occur for Java or
23131 -- AAMP interface names.
23132
23133 if Len = 0
23134 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
23135 or else VM_Target /= No_VM
23136 or else AAMP_On_Target
23137 then
23138 Set_Interface_Name (E, S);
23139
23140 else
23141 J := 1;
23142 loop
23143 CC := Get_String_Char (Str, J);
23144
23145 exit when not In_Character_Range (CC);
23146
23147 C := Get_Character (CC);
23148
23149 exit when C /= '_' and then C /= '$'
23150 and then C not in '0' .. '9'
23151 and then C not in 'a' .. 'z'
23152 and then C not in 'A' .. 'Z';
23153
23154 if J = Len then
23155 Set_Interface_Name (E, S);
23156 return;
23157
23158 else
23159 J := J + 1;
23160 end if;
23161 end loop;
23162
23163 -- Here we need to encode. The encoding we use as follows:
23164 -- three underscores + four hex digits (lower case)
23165
23166 Start_String;
23167
23168 for J in 1 .. String_Length (Str) loop
23169 CC := Get_String_Char (Str, J);
23170
23171 if not In_Character_Range (CC) then
23172 Encode;
23173 else
23174 C := Get_Character (CC);
23175
23176 if C = '_' or else C = '$'
23177 or else C in '0' .. '9'
23178 or else C in 'a' .. 'z'
23179 or else C in 'A' .. 'Z'
23180 then
23181 Store_String_Char (CC);
23182 else
23183 Encode;
23184 end if;
23185 end if;
23186 end loop;
23187
23188 Set_Interface_Name (E,
23189 Make_String_Literal (Sloc (S),
23190 Strval => End_String));
23191 end if;
23192 end Set_Encoded_Interface_Name;
23193
23194 -------------------
23195 -- Set_Unit_Name --
23196 -------------------
23197
23198 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
23199 Pref : Node_Id;
23200 Scop : Entity_Id;
23201
23202 begin
23203 if Nkind (N) = N_Identifier
23204 and then Nkind (With_Item) = N_Identifier
23205 then
23206 Set_Entity (N, Entity (With_Item));
23207
23208 elsif Nkind (N) = N_Selected_Component then
23209 Change_Selected_Component_To_Expanded_Name (N);
23210 Set_Entity (N, Entity (With_Item));
23211 Set_Entity (Selector_Name (N), Entity (N));
23212
23213 Pref := Prefix (N);
23214 Scop := Scope (Entity (N));
23215 while Nkind (Pref) = N_Selected_Component loop
23216 Change_Selected_Component_To_Expanded_Name (Pref);
23217 Set_Entity (Selector_Name (Pref), Scop);
23218 Set_Entity (Pref, Scop);
23219 Pref := Prefix (Pref);
23220 Scop := Scope (Scop);
23221 end loop;
23222
23223 Set_Entity (Pref, Scop);
23224 end if;
23225 end Set_Unit_Name;
23226
23227 end Sem_Prag;