2f04875b286dc6e06a49ca5e37616fa165879aca
[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-2014, 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 Output; use Output;
51 with Par_SCO; use Par_SCO;
52 with Restrict; use Restrict;
53 with Rident; use Rident;
54 with Rtsfind; use Rtsfind;
55 with Sem; use Sem;
56 with Sem_Aux; use Sem_Aux;
57 with Sem_Ch3; use Sem_Ch3;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch12; use Sem_Ch12;
61 with Sem_Ch13; use Sem_Ch13;
62 with Sem_Disp; use Sem_Disp;
63 with Sem_Dist; use Sem_Dist;
64 with Sem_Elim; use Sem_Elim;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Mech; use Sem_Mech;
68 with Sem_Res; use Sem_Res;
69 with Sem_Type; use Sem_Type;
70 with Sem_Util; use Sem_Util;
71 with Sem_VFpt; use Sem_VFpt;
72 with Sem_Warn; use Sem_Warn;
73 with Stand; use Stand;
74 with Sinfo; use Sinfo;
75 with Sinfo.CN; use Sinfo.CN;
76 with Sinput; use Sinput;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
79 with Table;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
82 with Ttypes;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
88
89 package body Sem_Prag is
90
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
94
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
98
99 -- pragma Export_xxx
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
103
104 -- pragma Import_xxx
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
108
109 -- EXTERNAL_SYMBOL ::=
110 -- IDENTIFIER
111 -- | static_string_EXPRESSION
112
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
116
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
120
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
124
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
130
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
134
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
140
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
144
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
148
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
152
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
156
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
164
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
168
169 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
170 -- Subsidiary routine to the analysis of pragmas Depends, Global and
171 -- Refined_State. Append an entity to a list. If the list is empty, create
172 -- a new list.
173
174 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
175 -- This routine is used for possible casing adjustment of an explicit
176 -- external name supplied as a string literal (the node N), according to
177 -- the casing requirement of Opt.External_Name_Casing. If this is set to
178 -- As_Is, then the string literal is returned unchanged, but if it is set
179 -- to Uppercase or Lowercase, then a new string literal with appropriate
180 -- casing is constructed.
181
182 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
183 -- Subsidiary to the analysis of pragma Global and pragma Depends. Query
184 -- whether a particular item appears in a mixed list of nodes and entities.
185 -- It is assumed that all nodes in the list have entities.
186
187 function Check_Kind (Nam : Name_Id) return Name_Id;
188 -- This function is used in connection with pragmas Assert, Check,
189 -- and assertion aspects and pragmas, to determine if Check pragmas
190 -- (or corresponding assertion aspects or pragmas) are currently active
191 -- as determined by the presence of -gnata on the command line (which
192 -- sets the default), and the appearance of pragmas Check_Policy and
193 -- Assertion_Policy as configuration pragmas either in a configuration
194 -- pragma file, or at the start of the current unit, or locally given
195 -- Check_Policy and Assertion_Policy pragmas that are currently active.
196 --
197 -- The value returned is one of the names Check, Ignore, Disable (On
198 -- returns Check, and Off returns Ignore).
199 --
200 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
201 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
202 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
203 -- _Post, _Invariant, or _Type_Invariant, which are special names used
204 -- in identifiers to represent these attribute references.
205
206 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id);
207 -- In ASIS mode we need to analyze the original expression in the aspect
208 -- specification. For Initializes, Global, and related SPARK aspects, the
209 -- expression has a sui-generis syntax which may be a list, an expression,
210 -- or an aggregate.
211
212 procedure Check_State_And_Constituent_Use
213 (States : Elist_Id;
214 Constits : Elist_Id;
215 Context : Node_Id);
216 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
217 -- Global and Initializes. Determine whether a state from list States and a
218 -- corresponding constituent from list Constits (if any) appear in the same
219 -- context denoted by Context. If this is the case, emit an error.
220
221 procedure Collect_Global_Items
222 (Prag : Node_Id;
223 In_Items : in out Elist_Id;
224 In_Out_Items : in out Elist_Id;
225 Out_Items : in out Elist_Id;
226 Proof_In_Items : in out Elist_Id;
227 Has_In_State : out Boolean;
228 Has_In_Out_State : out Boolean;
229 Has_Out_State : out Boolean;
230 Has_Proof_In_State : out Boolean;
231 Has_Null_State : out Boolean);
232 -- Subsidiary to the analysis of pragma Refined_Depends/Refined_Global.
233 -- Prag denotes pragma [Refined_]Global. Gather all input, in out, output
234 -- and Proof_In items of Prag in lists In_Items, In_Out_Items, Out_Items
235 -- and Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
236 -- and Has_Proof_In_State are set when there is at least one abstract state
237 -- with visible refinement available in the corresponding mode. Flag
238 -- Has_Null_State is set when at least state has a null refinement.
239
240 function Find_Related_Subprogram_Or_Body
241 (Prag : Node_Id;
242 Do_Checks : Boolean := False) return Node_Id;
243 -- Subsidiary to the analysis of pragmas Contract_Cases, Depends, Global,
244 -- Refined_Depends, Refined_Global and Refined_Post. Find the declaration
245 -- of the related subprogram [body or stub] subject to pragma Prag. If flag
246 -- Do_Checks is set, the routine reports duplicate pragmas and detects
247 -- improper use of refinement pragmas in stand alone expression functions.
248 -- The returned value depends on the related pragma as follows:
249 -- 1) Pragmas Contract_Cases, Depends and Global yield the corresponding
250 -- N_Subprogram_Declaration node or if the pragma applies to a stand
251 -- alone body, the N_Subprogram_Body node or Empty if illegal.
252 -- 2) Pragmas Refined_Depends, Refined_Global and Refined_Post yield
253 -- N_Subprogram_Body or N_Subprogram_Body_Stub nodes or Empty if
254 -- illegal.
255
256 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
257 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
258 -- original one, following the renaming chain) is returned. Otherwise the
259 -- entity is returned unchanged. Should be in Einfo???
260
261 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type;
262 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
263 -- Get_SPARK_Mode_Type. Convert a name into a corresponding value of type
264 -- SPARK_Mode_Type.
265
266 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean;
267 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
268 -- Determine whether dependency clause Clause is surrounded by extra
269 -- parentheses. If this is the case, issue an error message.
270
271 function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
272 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
273 -- pragma Depends. Determine whether the type of dependency item Item is
274 -- tagged, unconstrained array, unconstrained record or a record with at
275 -- least one unconstrained component.
276
277 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
278 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
279 -- of a Test_Case pragma if present (possibly Empty). We treat these as
280 -- spec expressions (i.e. similar to a default expression).
281
282 procedure Record_Possible_Body_Reference
283 (State_Id : Entity_Id;
284 Ref : Node_Id);
285 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
286 -- Global. Given an abstract state denoted by State_Id and a reference Ref
287 -- to it, determine whether the reference appears in a package body that
288 -- will eventually refine the state. If this is the case, record the
289 -- reference for future checks (see Analyze_Refined_State_In_Decls).
290
291 procedure Resolve_State (N : Node_Id);
292 -- Handle the overloading of state names by functions. When N denotes a
293 -- function, this routine finds the corresponding state and sets the entity
294 -- of N to that of the state.
295
296 procedure Rewrite_Assertion_Kind (N : Node_Id);
297 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
298 -- then it is rewritten as an identifier with the corresponding special
299 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
300 -- Check, Check_Policy.
301
302 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
303 -- Place semantic information on the argument of an Elaborate/Elaborate_All
304 -- pragma. Entity name for unit and its parents is taken from item in
305 -- previous with_clause that mentions the unit.
306
307 Dummy : Integer := 0;
308 pragma Volatile (Dummy);
309 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
310
311 procedure ip;
312 pragma No_Inline (ip);
313 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
314 -- is just to help debugging the front end. If a pragma Inspection_Point
315 -- is added to a source program, then breaking on ip will get you to that
316 -- point in the program.
317
318 procedure rv;
319 pragma No_Inline (rv);
320 -- This is a dummy function called by the processing for pragma Reviewable.
321 -- It is there for assisting front end debugging. By placing a Reviewable
322 -- pragma in the source program, a breakpoint on rv catches this place in
323 -- the source, allowing convenient stepping to the point of interest.
324
325 --------------
326 -- Add_Item --
327 --------------
328
329 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
330 begin
331 if No (To_List) then
332 To_List := New_Elmt_List;
333 end if;
334
335 Append_Elmt (Item, To_List);
336 end Add_Item;
337
338 -------------------------------
339 -- Adjust_External_Name_Case --
340 -------------------------------
341
342 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
343 CC : Char_Code;
344
345 begin
346 -- Adjust case of literal if required
347
348 if Opt.External_Name_Exp_Casing = As_Is then
349 return N;
350
351 else
352 -- Copy existing string
353
354 Start_String;
355
356 -- Set proper casing
357
358 for J in 1 .. String_Length (Strval (N)) loop
359 CC := Get_String_Char (Strval (N), J);
360
361 if Opt.External_Name_Exp_Casing = Uppercase
362 and then CC >= Get_Char_Code ('a')
363 and then CC <= Get_Char_Code ('z')
364 then
365 Store_String_Char (CC - 32);
366
367 elsif Opt.External_Name_Exp_Casing = Lowercase
368 and then CC >= Get_Char_Code ('A')
369 and then CC <= Get_Char_Code ('Z')
370 then
371 Store_String_Char (CC + 32);
372
373 else
374 Store_String_Char (CC);
375 end if;
376 end loop;
377
378 return
379 Make_String_Literal (Sloc (N),
380 Strval => End_String);
381 end if;
382 end Adjust_External_Name_Case;
383
384 -----------------------------------------
385 -- Analyze_Contract_Cases_In_Decl_Part --
386 -----------------------------------------
387
388 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
389 Others_Seen : Boolean := False;
390
391 procedure Analyze_Contract_Case (CCase : Node_Id);
392 -- Verify the legality of a single contract case
393
394 ---------------------------
395 -- Analyze_Contract_Case --
396 ---------------------------
397
398 procedure Analyze_Contract_Case (CCase : Node_Id) is
399 Case_Guard : Node_Id;
400 Conseq : Node_Id;
401 Extra_Guard : Node_Id;
402
403 begin
404 if Nkind (CCase) = N_Component_Association then
405 Case_Guard := First (Choices (CCase));
406 Conseq := Expression (CCase);
407
408 -- Each contract case must have exactly one case guard
409
410 Extra_Guard := Next (Case_Guard);
411
412 if Present (Extra_Guard) then
413 Error_Msg_N
414 ("contract case must have exactly one case guard",
415 Extra_Guard);
416 end if;
417
418 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
419
420 if Nkind (Case_Guard) = N_Others_Choice then
421 if Others_Seen then
422 Error_Msg_N
423 ("only one others choice allowed in contract cases",
424 Case_Guard);
425 else
426 Others_Seen := True;
427 end if;
428
429 elsif Others_Seen then
430 Error_Msg_N
431 ("others must be the last choice in contract cases", N);
432 end if;
433
434 -- Preanalyze the case guard and consequence
435
436 if Nkind (Case_Guard) /= N_Others_Choice then
437 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
438 end if;
439
440 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
441
442 -- The contract case is malformed
443
444 else
445 Error_Msg_N ("wrong syntax in contract case", CCase);
446 end if;
447 end Analyze_Contract_Case;
448
449 -- Local variables
450
451 All_Cases : Node_Id;
452 CCase : Node_Id;
453 Subp_Decl : Node_Id;
454 Subp_Id : Entity_Id;
455
456 Restore_Scope : Boolean := False;
457 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
458
459 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
460
461 begin
462 Set_Analyzed (N);
463
464 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
465 Subp_Id := Defining_Entity (Subp_Decl);
466 All_Cases := Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
467
468 -- Single and multiple contract cases must appear in aggregate form. If
469 -- this is not the case, then either the parser of the analysis of the
470 -- pragma failed to produce an aggregate.
471
472 pragma Assert (Nkind (All_Cases) = N_Aggregate);
473
474 if No (Component_Associations (All_Cases)) then
475 Error_Msg_N ("wrong syntax for constract cases", N);
476
477 -- Individual contract cases appear as component associations
478
479 else
480 -- Ensure that the formal parameters are visible when analyzing all
481 -- clauses. This falls out of the general rule of aspects pertaining
482 -- to subprogram declarations. Skip the installation for subprogram
483 -- bodies because the formals are already visible.
484
485 if not In_Open_Scopes (Subp_Id) then
486 Restore_Scope := True;
487 Push_Scope (Subp_Id);
488 Install_Formals (Subp_Id);
489 end if;
490
491 CCase := First (Component_Associations (All_Cases));
492 while Present (CCase) loop
493 Analyze_Contract_Case (CCase);
494 Next (CCase);
495 end loop;
496
497 if Restore_Scope then
498 End_Scope;
499 end if;
500 end if;
501 end Analyze_Contract_Cases_In_Decl_Part;
502
503 ----------------------------------
504 -- Analyze_Depends_In_Decl_Part --
505 ----------------------------------
506
507 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
508 Loc : constant Source_Ptr := Sloc (N);
509
510 All_Inputs_Seen : Elist_Id := No_Elist;
511 -- A list containing the entities of all the inputs processed so far.
512 -- The list is populated with unique entities because the same input
513 -- may appear in multiple input lists.
514
515 All_Outputs_Seen : Elist_Id := No_Elist;
516 -- A list containing the entities of all the outputs processed so far.
517 -- The list is populated with unique entities because output items are
518 -- unique in a dependence relation.
519
520 Constits_Seen : Elist_Id := No_Elist;
521 -- A list containing the entities of all constituents processed so far.
522 -- It aids in detecting illegal usage of a state and a corresponding
523 -- constituent in pragma [Refinde_]Depends.
524
525 Global_Seen : Boolean := False;
526 -- A flag set when pragma Global has been processed
527
528 Null_Output_Seen : Boolean := False;
529 -- A flag used to track the legality of a null output
530
531 Result_Seen : Boolean := False;
532 -- A flag set when Subp_Id'Result is processed
533
534 Spec_Id : Entity_Id;
535 -- The entity of the subprogram subject to pragma [Refined_]Depends
536
537 States_Seen : Elist_Id := No_Elist;
538 -- A list containing the entities of all states processed so far. It
539 -- helps in detecting illegal usage of a state and a corresponding
540 -- constituent in pragma [Refined_]Depends.
541
542 Subp_Id : Entity_Id;
543 -- The entity of the subprogram [body or stub] subject to pragma
544 -- [Refined_]Depends.
545
546 Subp_Inputs : Elist_Id := No_Elist;
547 Subp_Outputs : Elist_Id := No_Elist;
548 -- Two lists containing the full set of inputs and output of the related
549 -- subprograms. Note that these lists contain both nodes and entities.
550
551 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id);
552 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
553 -- to the name buffer. The individual kinds are as follows:
554 -- E_Abstract_State - "state"
555 -- E_In_Parameter - "parameter"
556 -- E_In_Out_Parameter - "parameter"
557 -- E_Out_Parameter - "parameter"
558 -- E_Variable - "global"
559
560 procedure Analyze_Dependency_Clause
561 (Clause : Node_Id;
562 Is_Last : Boolean);
563 -- Verify the legality of a single dependency clause. Flag Is_Last
564 -- denotes whether Clause is the last clause in the relation.
565
566 procedure Check_Function_Return;
567 -- Verify that Funtion'Result appears as one of the outputs
568 -- (SPARK RM 6.1.5(10)).
569
570 procedure Check_Role
571 (Item : Node_Id;
572 Item_Id : Entity_Id;
573 Is_Input : Boolean;
574 Self_Ref : Boolean);
575 -- Ensure that an item fulfils its designated input and/or output role
576 -- as specified by pragma Global (if any) or the enclosing context. If
577 -- this is not the case, emit an error. Item and Item_Id denote the
578 -- attributes of an item. Flag Is_Input should be set when item comes
579 -- from an input list. Flag Self_Ref should be set when the item is an
580 -- output and the dependency clause has operator "+".
581
582 procedure Check_Usage
583 (Subp_Items : Elist_Id;
584 Used_Items : Elist_Id;
585 Is_Input : Boolean);
586 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
587 -- error if this is not the case.
588
589 procedure Normalize_Clause (Clause : Node_Id);
590 -- Remove a self-dependency "+" from the input list of a clause. Split
591 -- a clause with multiple outputs into multiple clauses with a single
592 -- output.
593
594 -----------------------------
595 -- Add_Item_To_Name_Buffer --
596 -----------------------------
597
598 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
599 begin
600 if Ekind (Item_Id) = E_Abstract_State then
601 Add_Str_To_Name_Buffer ("state");
602
603 elsif Is_Formal (Item_Id) then
604 Add_Str_To_Name_Buffer ("parameter");
605
606 elsif Ekind (Item_Id) = E_Variable then
607 Add_Str_To_Name_Buffer ("global");
608
609 -- The routine should not be called with non-SPARK items
610
611 else
612 raise Program_Error;
613 end if;
614 end Add_Item_To_Name_Buffer;
615
616 -------------------------------
617 -- Analyze_Dependency_Clause --
618 -------------------------------
619
620 procedure Analyze_Dependency_Clause
621 (Clause : Node_Id;
622 Is_Last : Boolean)
623 is
624 procedure Analyze_Input_List (Inputs : Node_Id);
625 -- Verify the legality of a single input list
626
627 procedure Analyze_Input_Output
628 (Item : Node_Id;
629 Is_Input : Boolean;
630 Self_Ref : Boolean;
631 Top_Level : Boolean;
632 Seen : in out Elist_Id;
633 Null_Seen : in out Boolean;
634 Non_Null_Seen : in out Boolean);
635 -- Verify the legality of a single input or output item. Flag
636 -- Is_Input should be set whenever Item is an input, False when it
637 -- denotes an output. Flag Self_Ref should be set when the item is an
638 -- output and the dependency clause has a "+". Flag Top_Level should
639 -- be set whenever Item appears immediately within an input or output
640 -- list. Seen is a collection of all abstract states, variables and
641 -- formals processed so far. Flag Null_Seen denotes whether a null
642 -- input or output has been encountered. Flag Non_Null_Seen denotes
643 -- whether a non-null input or output has been encountered.
644
645 ------------------------
646 -- Analyze_Input_List --
647 ------------------------
648
649 procedure Analyze_Input_List (Inputs : Node_Id) is
650 Inputs_Seen : Elist_Id := No_Elist;
651 -- A list containing the entities of all inputs that appear in the
652 -- current input list.
653
654 Non_Null_Input_Seen : Boolean := False;
655 Null_Input_Seen : Boolean := False;
656 -- Flags used to check the legality of an input list
657
658 Input : Node_Id;
659
660 begin
661 -- Multiple inputs appear as an aggregate
662
663 if Nkind (Inputs) = N_Aggregate then
664 if Present (Component_Associations (Inputs)) then
665 SPARK_Msg_N
666 ("nested dependency relations not allowed", Inputs);
667
668 elsif Present (Expressions (Inputs)) then
669 Input := First (Expressions (Inputs));
670 while Present (Input) loop
671 Analyze_Input_Output
672 (Item => Input,
673 Is_Input => True,
674 Self_Ref => False,
675 Top_Level => False,
676 Seen => Inputs_Seen,
677 Null_Seen => Null_Input_Seen,
678 Non_Null_Seen => Non_Null_Input_Seen);
679
680 Next (Input);
681 end loop;
682
683 -- Syntax error, always report
684
685 else
686 Error_Msg_N ("malformed input dependency list", Inputs);
687 end if;
688
689 -- Process a solitary input
690
691 else
692 Analyze_Input_Output
693 (Item => Inputs,
694 Is_Input => True,
695 Self_Ref => False,
696 Top_Level => False,
697 Seen => Inputs_Seen,
698 Null_Seen => Null_Input_Seen,
699 Non_Null_Seen => Non_Null_Input_Seen);
700 end if;
701
702 -- Detect an illegal dependency clause of the form
703
704 -- (null =>[+] null)
705
706 if Null_Output_Seen and then Null_Input_Seen then
707 SPARK_Msg_N
708 ("null dependency clause cannot have a null input list",
709 Inputs);
710 end if;
711 end Analyze_Input_List;
712
713 --------------------------
714 -- Analyze_Input_Output --
715 --------------------------
716
717 procedure Analyze_Input_Output
718 (Item : Node_Id;
719 Is_Input : Boolean;
720 Self_Ref : Boolean;
721 Top_Level : Boolean;
722 Seen : in out Elist_Id;
723 Null_Seen : in out Boolean;
724 Non_Null_Seen : in out Boolean)
725 is
726 Is_Output : constant Boolean := not Is_Input;
727 Grouped : Node_Id;
728 Item_Id : Entity_Id;
729
730 begin
731 -- Multiple input or output items appear as an aggregate
732
733 if Nkind (Item) = N_Aggregate then
734 if not Top_Level then
735 SPARK_Msg_N ("nested grouping of items not allowed", Item);
736
737 elsif Present (Component_Associations (Item)) then
738 SPARK_Msg_N
739 ("nested dependency relations not allowed", Item);
740
741 -- Recursively analyze the grouped items
742
743 elsif Present (Expressions (Item)) then
744 Grouped := First (Expressions (Item));
745 while Present (Grouped) loop
746 Analyze_Input_Output
747 (Item => Grouped,
748 Is_Input => Is_Input,
749 Self_Ref => Self_Ref,
750 Top_Level => False,
751 Seen => Seen,
752 Null_Seen => Null_Seen,
753 Non_Null_Seen => Non_Null_Seen);
754
755 Next (Grouped);
756 end loop;
757
758 -- Syntax error, always report
759
760 else
761 Error_Msg_N ("malformed dependency list", Item);
762 end if;
763
764 -- Process Function'Result in the context of a dependency clause
765
766 elsif Is_Attribute_Result (Item) then
767 Non_Null_Seen := True;
768
769 -- It is sufficent to analyze the prefix of 'Result in order to
770 -- establish legality of the attribute.
771
772 Analyze (Prefix (Item));
773
774 -- The prefix of 'Result must denote the function for which
775 -- pragma Depends applies (SPARK RM 6.1.5(11)).
776
777 if not Is_Entity_Name (Prefix (Item))
778 or else Ekind (Spec_Id) /= E_Function
779 or else Entity (Prefix (Item)) /= Spec_Id
780 then
781 Error_Msg_Name_1 := Name_Result;
782 SPARK_Msg_N
783 ("prefix of attribute % must denote the enclosing "
784 & "function", Item);
785
786 -- Function'Result is allowed to appear on the output side of a
787 -- dependency clause (SPARK RM 6.1.5(6)).
788
789 elsif Is_Input then
790 SPARK_Msg_N ("function result cannot act as input", Item);
791
792 elsif Null_Seen then
793 SPARK_Msg_N
794 ("cannot mix null and non-null dependency items", Item);
795
796 else
797 Result_Seen := True;
798 end if;
799
800 -- Detect multiple uses of null in a single dependency list or
801 -- throughout the whole relation. Verify the placement of a null
802 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
803
804 elsif Nkind (Item) = N_Null then
805 if Null_Seen then
806 SPARK_Msg_N
807 ("multiple null dependency relations not allowed", Item);
808
809 elsif Non_Null_Seen then
810 SPARK_Msg_N
811 ("cannot mix null and non-null dependency items", Item);
812
813 else
814 Null_Seen := True;
815
816 if Is_Output then
817 if not Is_Last then
818 SPARK_Msg_N
819 ("null output list must be the last clause in a "
820 & "dependency relation", Item);
821
822 -- Catch a useless dependence of the form:
823 -- null =>+ ...
824
825 elsif Self_Ref then
826 SPARK_Msg_N
827 ("useless dependence, null depends on itself", Item);
828 end if;
829 end if;
830 end if;
831
832 -- Default case
833
834 else
835 Non_Null_Seen := True;
836
837 if Null_Seen then
838 SPARK_Msg_N ("cannot mix null and non-null items", Item);
839 end if;
840
841 Analyze (Item);
842 Resolve_State (Item);
843
844 -- Find the entity of the item. If this is a renaming, climb
845 -- the renaming chain to reach the root object. Renamings of
846 -- non-entire objects do not yield an entity (Empty).
847
848 Item_Id := Entity_Of (Item);
849
850 if Present (Item_Id) then
851 if Ekind_In (Item_Id, E_Abstract_State,
852 E_In_Parameter,
853 E_In_Out_Parameter,
854 E_Out_Parameter,
855 E_Variable)
856 then
857 -- Ensure that the item fulfils its role as input and/or
858 -- output as specified by pragma Global or the enclosing
859 -- context.
860
861 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
862
863 -- Detect multiple uses of the same state, variable or
864 -- formal parameter. If this is not the case, add the
865 -- item to the list of processed relations.
866
867 if Contains (Seen, Item_Id) then
868 SPARK_Msg_NE
869 ("duplicate use of item &", Item, Item_Id);
870 else
871 Add_Item (Item_Id, Seen);
872 end if;
873
874 -- Detect illegal use of an input related to a null
875 -- output. Such input items cannot appear in other
876 -- input lists (SPARK RM 6.1.5(13)).
877
878 if Is_Input
879 and then Null_Output_Seen
880 and then Contains (All_Inputs_Seen, Item_Id)
881 then
882 SPARK_Msg_N
883 ("input of a null output list cannot appear in "
884 & "multiple input lists", Item);
885 end if;
886
887 -- Add an input or a self-referential output to the list
888 -- of all processed inputs.
889
890 if Is_Input or else Self_Ref then
891 Add_Item (Item_Id, All_Inputs_Seen);
892 end if;
893
894 -- State related checks (SPARK RM 6.1.5(3))
895
896 if Ekind (Item_Id) = E_Abstract_State then
897 if Has_Visible_Refinement (Item_Id) then
898 SPARK_Msg_NE
899 ("cannot mention state & in global refinement",
900 Item, Item_Id);
901 SPARK_Msg_N
902 ("\use its constituents instead", Item);
903 return;
904
905 -- If the reference to the abstract state appears in
906 -- an enclosing package body that will eventually
907 -- refine the state, record the reference for future
908 -- checks.
909
910 else
911 Record_Possible_Body_Reference
912 (State_Id => Item_Id,
913 Ref => Item);
914 end if;
915 end if;
916
917 -- When the item renames an entire object, replace the
918 -- item with a reference to the object.
919
920 if Present (Renamed_Object (Entity (Item))) then
921 Rewrite (Item,
922 New_Occurrence_Of (Item_Id, Sloc (Item)));
923 Analyze (Item);
924 end if;
925
926 -- Add the entity of the current item to the list of
927 -- processed items.
928
929 if Ekind (Item_Id) = E_Abstract_State then
930 Add_Item (Item_Id, States_Seen);
931 end if;
932
933 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
934 and then Present (Encapsulating_State (Item_Id))
935 then
936 Add_Item (Item_Id, Constits_Seen);
937 end if;
938
939 -- All other input/output items are illegal
940 -- (SPARK RM 6.1.5(1)).
941
942 else
943 SPARK_Msg_N
944 ("item must denote parameter, variable, or state",
945 Item);
946 end if;
947
948 -- All other input/output items are illegal
949 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
950
951 else
952 Error_Msg_N
953 ("item must denote parameter, variable, or state", Item);
954 end if;
955 end if;
956 end Analyze_Input_Output;
957
958 -- Local variables
959
960 Inputs : Node_Id;
961 Output : Node_Id;
962 Self_Ref : Boolean;
963
964 Non_Null_Output_Seen : Boolean := False;
965 -- Flag used to check the legality of an output list
966
967 -- Start of processing for Analyze_Dependency_Clause
968
969 begin
970 Inputs := Expression (Clause);
971 Self_Ref := False;
972
973 -- An input list with a self-dependency appears as operator "+" where
974 -- the actuals inputs are the right operand.
975
976 if Nkind (Inputs) = N_Op_Plus then
977 Inputs := Right_Opnd (Inputs);
978 Self_Ref := True;
979 end if;
980
981 -- Process the output_list of a dependency_clause
982
983 Output := First (Choices (Clause));
984 while Present (Output) loop
985 Analyze_Input_Output
986 (Item => Output,
987 Is_Input => False,
988 Self_Ref => Self_Ref,
989 Top_Level => True,
990 Seen => All_Outputs_Seen,
991 Null_Seen => Null_Output_Seen,
992 Non_Null_Seen => Non_Null_Output_Seen);
993
994 Next (Output);
995 end loop;
996
997 -- Process the input_list of a dependency_clause
998
999 Analyze_Input_List (Inputs);
1000 end Analyze_Dependency_Clause;
1001
1002 ---------------------------
1003 -- Check_Function_Return --
1004 ---------------------------
1005
1006 procedure Check_Function_Return is
1007 begin
1008 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
1009 SPARK_Msg_NE
1010 ("result of & must appear in exactly one output list",
1011 N, Spec_Id);
1012 end if;
1013 end Check_Function_Return;
1014
1015 ----------------
1016 -- Check_Role --
1017 ----------------
1018
1019 procedure Check_Role
1020 (Item : Node_Id;
1021 Item_Id : Entity_Id;
1022 Is_Input : Boolean;
1023 Self_Ref : Boolean)
1024 is
1025 procedure Find_Role
1026 (Item_Is_Input : out Boolean;
1027 Item_Is_Output : out Boolean);
1028 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1029 -- Item_Is_Output are set depending on the role.
1030
1031 procedure Role_Error
1032 (Item_Is_Input : Boolean;
1033 Item_Is_Output : Boolean);
1034 -- Emit an error message concerning the incorrect use of Item in
1035 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1036 -- denote whether the item is an input and/or an output.
1037
1038 ---------------
1039 -- Find_Role --
1040 ---------------
1041
1042 procedure Find_Role
1043 (Item_Is_Input : out Boolean;
1044 Item_Is_Output : out Boolean)
1045 is
1046 begin
1047 Item_Is_Input := False;
1048 Item_Is_Output := False;
1049
1050 -- Abstract state cases
1051
1052 if Ekind (Item_Id) = E_Abstract_State then
1053
1054 -- When pragma Global is present, the mode of the state may be
1055 -- further constrained by setting a more restrictive mode.
1056
1057 if Global_Seen then
1058 if Appears_In (Subp_Inputs, Item_Id) then
1059 Item_Is_Input := True;
1060 end if;
1061
1062 if Appears_In (Subp_Outputs, Item_Id) then
1063 Item_Is_Output := True;
1064 end if;
1065
1066 -- Otherwise the state has a default IN OUT mode
1067
1068 else
1069 Item_Is_Input := True;
1070 Item_Is_Output := True;
1071 end if;
1072
1073 -- Parameter cases
1074
1075 elsif Ekind (Item_Id) = E_In_Parameter then
1076 Item_Is_Input := True;
1077
1078 elsif Ekind (Item_Id) = E_In_Out_Parameter then
1079 Item_Is_Input := True;
1080 Item_Is_Output := True;
1081
1082 elsif Ekind (Item_Id) = E_Out_Parameter then
1083 if Scope (Item_Id) = Spec_Id then
1084
1085 -- An OUT parameter of the related subprogram has mode IN
1086 -- if its type is unconstrained or tagged because array
1087 -- bounds, discriminants or tags can be read.
1088
1089 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1090 Item_Is_Input := True;
1091 end if;
1092
1093 Item_Is_Output := True;
1094
1095 -- An OUT parameter of an enclosing subprogram behaves as a
1096 -- read-write variable in which case the mode is IN OUT.
1097
1098 else
1099 Item_Is_Input := True;
1100 Item_Is_Output := True;
1101 end if;
1102
1103 -- Variable cases
1104
1105 else pragma Assert (Ekind (Item_Id) = E_Variable);
1106
1107 -- When pragma Global is present, the mode of the variable may
1108 -- be further constrained by setting a more restrictive mode.
1109
1110 if Global_Seen then
1111
1112 -- A variable has mode IN when its type is unconstrained or
1113 -- tagged because array bounds, discriminants or tags can be
1114 -- read.
1115
1116 if Appears_In (Subp_Inputs, Item_Id)
1117 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1118 then
1119 Item_Is_Input := True;
1120 end if;
1121
1122 if Appears_In (Subp_Outputs, Item_Id) then
1123 Item_Is_Output := True;
1124 end if;
1125
1126 -- Otherwise the variable has a default IN OUT mode
1127
1128 else
1129 Item_Is_Input := True;
1130 Item_Is_Output := True;
1131 end if;
1132 end if;
1133 end Find_Role;
1134
1135 ----------------
1136 -- Role_Error --
1137 ----------------
1138
1139 procedure Role_Error
1140 (Item_Is_Input : Boolean;
1141 Item_Is_Output : Boolean)
1142 is
1143 Error_Msg : Name_Id;
1144
1145 begin
1146 Name_Len := 0;
1147
1148 -- When the item is not part of the input and the output set of
1149 -- the related subprogram, then it appears as extra in pragma
1150 -- [Refined_]Depends.
1151
1152 if not Item_Is_Input and then not Item_Is_Output then
1153 Add_Item_To_Name_Buffer (Item_Id);
1154 Add_Str_To_Name_Buffer
1155 (" & cannot appear in dependence relation");
1156
1157 Error_Msg := Name_Find;
1158 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1159
1160 Error_Msg_Name_1 := Chars (Subp_Id);
1161 SPARK_Msg_NE
1162 ("\& is not part of the input or output set of subprogram %",
1163 Item, Item_Id);
1164
1165 -- The mode of the item and its role in pragma [Refined_]Depends
1166 -- are in conflict. Construct a detailed message explaining the
1167 -- illegality (SPARK RM 6.1.5(5-6)).
1168
1169 else
1170 if Item_Is_Input then
1171 Add_Str_To_Name_Buffer ("read-only");
1172 else
1173 Add_Str_To_Name_Buffer ("write-only");
1174 end if;
1175
1176 Add_Char_To_Name_Buffer (' ');
1177 Add_Item_To_Name_Buffer (Item_Id);
1178 Add_Str_To_Name_Buffer (" & cannot appear as ");
1179
1180 if Item_Is_Input then
1181 Add_Str_To_Name_Buffer ("output");
1182 else
1183 Add_Str_To_Name_Buffer ("input");
1184 end if;
1185
1186 Add_Str_To_Name_Buffer (" in dependence relation");
1187 Error_Msg := Name_Find;
1188 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1189 end if;
1190 end Role_Error;
1191
1192 -- Local variables
1193
1194 Item_Is_Input : Boolean;
1195 Item_Is_Output : Boolean;
1196
1197 -- Start of processing for Check_Role
1198
1199 begin
1200 Find_Role (Item_Is_Input, Item_Is_Output);
1201
1202 -- Input item
1203
1204 if Is_Input then
1205 if not Item_Is_Input then
1206 Role_Error (Item_Is_Input, Item_Is_Output);
1207 end if;
1208
1209 -- Self-referential item
1210
1211 elsif Self_Ref then
1212 if not Item_Is_Input or else not Item_Is_Output then
1213 Role_Error (Item_Is_Input, Item_Is_Output);
1214 end if;
1215
1216 -- Output item
1217
1218 elsif not Item_Is_Output then
1219 Role_Error (Item_Is_Input, Item_Is_Output);
1220 end if;
1221 end Check_Role;
1222
1223 -----------------
1224 -- Check_Usage --
1225 -----------------
1226
1227 procedure Check_Usage
1228 (Subp_Items : Elist_Id;
1229 Used_Items : Elist_Id;
1230 Is_Input : Boolean)
1231 is
1232 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1233 -- Emit an error concerning the illegal usage of an item
1234
1235 -----------------
1236 -- Usage_Error --
1237 -----------------
1238
1239 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1240 Error_Msg : Name_Id;
1241
1242 begin
1243 -- Input case
1244
1245 if Is_Input then
1246
1247 -- Unconstrained and tagged items are not part of the explicit
1248 -- input set of the related subprogram, they do not have to be
1249 -- present in a dependence relation and should not be flagged
1250 -- (SPARK RM 6.1.5(8)).
1251
1252 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1253 Name_Len := 0;
1254
1255 Add_Item_To_Name_Buffer (Item_Id);
1256 Add_Str_To_Name_Buffer
1257 (" & must appear in at least one input dependence list");
1258
1259 Error_Msg := Name_Find;
1260 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1261 end if;
1262
1263 -- Output case (SPARK RM 6.1.5(10))
1264
1265 else
1266 Name_Len := 0;
1267
1268 Add_Item_To_Name_Buffer (Item_Id);
1269 Add_Str_To_Name_Buffer
1270 (" & must appear in exactly one output dependence list");
1271
1272 Error_Msg := Name_Find;
1273 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1274 end if;
1275 end Usage_Error;
1276
1277 -- Local variables
1278
1279 Elmt : Elmt_Id;
1280 Item : Node_Id;
1281 Item_Id : Entity_Id;
1282
1283 -- Start of processing for Check_Usage
1284
1285 begin
1286 if No (Subp_Items) then
1287 return;
1288 end if;
1289
1290 -- Each input or output of the subprogram must appear in a dependency
1291 -- relation.
1292
1293 Elmt := First_Elmt (Subp_Items);
1294 while Present (Elmt) loop
1295 Item := Node (Elmt);
1296
1297 if Nkind (Item) = N_Defining_Identifier then
1298 Item_Id := Item;
1299 else
1300 Item_Id := Entity_Of (Item);
1301 end if;
1302
1303 -- The item does not appear in a dependency
1304
1305 if Present (Item_Id)
1306 and then not Contains (Used_Items, Item_Id)
1307 then
1308 if Is_Formal (Item_Id) then
1309 Usage_Error (Item, Item_Id);
1310
1311 -- States and global variables are not used properly only when
1312 -- the subprogram is subject to pragma Global.
1313
1314 elsif Global_Seen then
1315 Usage_Error (Item, Item_Id);
1316 end if;
1317 end if;
1318
1319 Next_Elmt (Elmt);
1320 end loop;
1321 end Check_Usage;
1322
1323 ----------------------
1324 -- Normalize_Clause --
1325 ----------------------
1326
1327 procedure Normalize_Clause (Clause : Node_Id) is
1328 procedure Create_Or_Modify_Clause
1329 (Output : Node_Id;
1330 Outputs : Node_Id;
1331 Inputs : Node_Id;
1332 After : Node_Id;
1333 In_Place : Boolean;
1334 Multiple : Boolean);
1335 -- Create a brand new clause to represent the self-reference or
1336 -- modify the input and/or output lists of an existing clause. Output
1337 -- denotes a self-referencial output. Outputs is the output list of a
1338 -- clause. Inputs is the input list of a clause. After denotes the
1339 -- clause after which the new clause is to be inserted. Flag In_Place
1340 -- should be set when normalizing the last output of an output list.
1341 -- Flag Multiple should be set when Output comes from a list with
1342 -- multiple items.
1343
1344 procedure Normalize_Outputs;
1345 -- If Clause contains more than one output, split the clause into
1346 -- multiple clauses with a single output. All new clauses are added
1347 -- after Clause.
1348
1349 -----------------------------
1350 -- Create_Or_Modify_Clause --
1351 -----------------------------
1352
1353 procedure Create_Or_Modify_Clause
1354 (Output : Node_Id;
1355 Outputs : Node_Id;
1356 Inputs : Node_Id;
1357 After : Node_Id;
1358 In_Place : Boolean;
1359 Multiple : Boolean)
1360 is
1361 procedure Propagate_Output
1362 (Output : Node_Id;
1363 Inputs : Node_Id);
1364 -- Handle the various cases of output propagation to the input
1365 -- list. Output denotes a self-referencial output item. Inputs is
1366 -- the input list of a clause.
1367
1368 ----------------------
1369 -- Propagate_Output --
1370 ----------------------
1371
1372 procedure Propagate_Output
1373 (Output : Node_Id;
1374 Inputs : Node_Id)
1375 is
1376 function In_Input_List
1377 (Item : Entity_Id;
1378 Inputs : List_Id) return Boolean;
1379 -- Determine whether a particulat item appears in the input
1380 -- list of a clause.
1381
1382 -------------------
1383 -- In_Input_List --
1384 -------------------
1385
1386 function In_Input_List
1387 (Item : Entity_Id;
1388 Inputs : List_Id) return Boolean
1389 is
1390 Elmt : Node_Id;
1391
1392 begin
1393 Elmt := First (Inputs);
1394 while Present (Elmt) loop
1395 if Entity_Of (Elmt) = Item then
1396 return True;
1397 end if;
1398
1399 Next (Elmt);
1400 end loop;
1401
1402 return False;
1403 end In_Input_List;
1404
1405 -- Local variables
1406
1407 Output_Id : constant Entity_Id := Entity_Of (Output);
1408 Grouped : List_Id;
1409
1410 -- Start of processing for Propagate_Output
1411
1412 begin
1413 -- The clause is of the form:
1414
1415 -- (Output =>+ null)
1416
1417 -- Remove the null input and replace it with a copy of the
1418 -- output:
1419
1420 -- (Output => Output)
1421
1422 if Nkind (Inputs) = N_Null then
1423 Rewrite (Inputs, New_Copy_Tree (Output));
1424
1425 -- The clause is of the form:
1426
1427 -- (Output =>+ (Input1, ..., InputN))
1428
1429 -- Determine whether the output is not already mentioned in the
1430 -- input list and if not, add it to the list of inputs:
1431
1432 -- (Output => (Output, Input1, ..., InputN))
1433
1434 elsif Nkind (Inputs) = N_Aggregate then
1435 Grouped := Expressions (Inputs);
1436
1437 if not In_Input_List
1438 (Item => Output_Id,
1439 Inputs => Grouped)
1440 then
1441 Prepend_To (Grouped, New_Copy_Tree (Output));
1442 end if;
1443
1444 -- The clause is of the form:
1445
1446 -- (Output =>+ Input)
1447
1448 -- If the input does not mention the output, group the two
1449 -- together:
1450
1451 -- (Output => (Output, Input))
1452
1453 elsif Entity_Of (Inputs) /= Output_Id then
1454 Rewrite (Inputs,
1455 Make_Aggregate (Loc,
1456 Expressions => New_List (
1457 New_Copy_Tree (Output),
1458 New_Copy_Tree (Inputs))));
1459 end if;
1460 end Propagate_Output;
1461
1462 -- Local variables
1463
1464 Loc : constant Source_Ptr := Sloc (Clause);
1465 New_Clause : Node_Id;
1466
1467 -- Start of processing for Create_Or_Modify_Clause
1468
1469 begin
1470 -- A null output depending on itself does not require any
1471 -- normalization.
1472
1473 if Nkind (Output) = N_Null then
1474 return;
1475
1476 -- A function result cannot depend on itself because it cannot
1477 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1478
1479 elsif Is_Attribute_Result (Output) then
1480 SPARK_Msg_N ("function result cannot depend on itself", Output);
1481 return;
1482 end if;
1483
1484 -- When performing the transformation in place, simply add the
1485 -- output to the list of inputs (if not already there). This case
1486 -- arises when dealing with the last output of an output list -
1487 -- we perform the normalization in place to avoid generating a
1488 -- malformed tree.
1489
1490 if In_Place then
1491 Propagate_Output (Output, Inputs);
1492
1493 -- A list with multiple outputs is slowly trimmed until only
1494 -- one element remains. When this happens, replace the
1495 -- aggregate with the element itself.
1496
1497 if Multiple then
1498 Remove (Output);
1499 Rewrite (Outputs, Output);
1500 end if;
1501
1502 -- Default case
1503
1504 else
1505 -- Unchain the output from its output list as it will appear in
1506 -- a new clause. Note that we cannot simply rewrite the output
1507 -- as null because this will violate the semantics of pragma
1508 -- Depends.
1509
1510 Remove (Output);
1511
1512 -- Generate a new clause of the form:
1513 -- (Output => Inputs)
1514
1515 New_Clause :=
1516 Make_Component_Association (Loc,
1517 Choices => New_List (Output),
1518 Expression => New_Copy_Tree (Inputs));
1519
1520 -- The new clause contains replicated content that has already
1521 -- been analyzed. There is not need to reanalyze it or
1522 -- renormalize it again.
1523
1524 Set_Analyzed (New_Clause);
1525
1526 Propagate_Output
1527 (Output => First (Choices (New_Clause)),
1528 Inputs => Expression (New_Clause));
1529
1530 Insert_After (After, New_Clause);
1531 end if;
1532 end Create_Or_Modify_Clause;
1533
1534 -----------------------
1535 -- Normalize_Outputs --
1536 -----------------------
1537
1538 procedure Normalize_Outputs is
1539 Inputs : constant Node_Id := Expression (Clause);
1540 Loc : constant Source_Ptr := Sloc (Clause);
1541 Outputs : constant Node_Id := First (Choices (Clause));
1542 Last_Output : Node_Id;
1543 New_Clause : Node_Id;
1544 Next_Output : Node_Id;
1545 Output : Node_Id;
1546
1547 begin
1548 -- Multiple outputs appear as an aggregate. Nothing to do when
1549 -- the clause has exactly one output.
1550
1551 if Nkind (Outputs) = N_Aggregate then
1552 Last_Output := Last (Expressions (Outputs));
1553
1554 -- Create a clause for each output. Note that each time a new
1555 -- clause is created, the original output list slowly shrinks
1556 -- until there is one item left.
1557
1558 Output := First (Expressions (Outputs));
1559 while Present (Output) loop
1560 Next_Output := Next (Output);
1561
1562 -- Unhook the output from the original output list as it
1563 -- will be relocated to a new clause.
1564
1565 Remove (Output);
1566
1567 -- Special processing for the last output. At this point
1568 -- the original aggregate has been stripped down to one
1569 -- element. Replace the aggregate by the element itself.
1570
1571 if Output = Last_Output then
1572 Rewrite (Outputs, Output);
1573
1574 else
1575 -- Generate a clause of the form:
1576 -- (Output => Inputs)
1577
1578 New_Clause :=
1579 Make_Component_Association (Loc,
1580 Choices => New_List (Output),
1581 Expression => New_Copy_Tree (Inputs));
1582
1583 -- The new clause contains replicated content that has
1584 -- already been analyzed. There is not need to reanalyze
1585 -- them.
1586
1587 Set_Analyzed (New_Clause);
1588 Insert_After (Clause, New_Clause);
1589 end if;
1590
1591 Output := Next_Output;
1592 end loop;
1593 end if;
1594 end Normalize_Outputs;
1595
1596 -- Local variables
1597
1598 Outputs : constant Node_Id := First (Choices (Clause));
1599 Inputs : Node_Id;
1600 Last_Output : Node_Id;
1601 Next_Output : Node_Id;
1602 Output : Node_Id;
1603
1604 -- Start of processing for Normalize_Clause
1605
1606 begin
1607 -- A self-dependency appears as operator "+". Remove the "+" from the
1608 -- tree by moving the real inputs to their proper place.
1609
1610 if Nkind (Expression (Clause)) = N_Op_Plus then
1611 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1612 Inputs := Expression (Clause);
1613
1614 -- Multiple outputs appear as an aggregate
1615
1616 if Nkind (Outputs) = N_Aggregate then
1617 Last_Output := Last (Expressions (Outputs));
1618
1619 Output := First (Expressions (Outputs));
1620 while Present (Output) loop
1621
1622 -- Normalization may remove an output from its list,
1623 -- preserve the subsequent output now.
1624
1625 Next_Output := Next (Output);
1626
1627 Create_Or_Modify_Clause
1628 (Output => Output,
1629 Outputs => Outputs,
1630 Inputs => Inputs,
1631 After => Clause,
1632 In_Place => Output = Last_Output,
1633 Multiple => True);
1634
1635 Output := Next_Output;
1636 end loop;
1637
1638 -- Solitary output
1639
1640 else
1641 Create_Or_Modify_Clause
1642 (Output => Outputs,
1643 Outputs => Empty,
1644 Inputs => Inputs,
1645 After => Empty,
1646 In_Place => True,
1647 Multiple => False);
1648 end if;
1649 end if;
1650
1651 -- Split a clause with multiple outputs into multiple clauses with a
1652 -- single output.
1653
1654 Normalize_Outputs;
1655 end Normalize_Clause;
1656
1657 -- Local variables
1658
1659 Deps : constant Node_Id :=
1660 Get_Pragma_Arg
1661 (First (Pragma_Argument_Associations (N)));
1662 Clause : Node_Id;
1663 Errors : Nat;
1664 Last_Clause : Node_Id;
1665 Subp_Decl : Node_Id;
1666
1667 Restore_Scope : Boolean := False;
1668 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1669
1670 -- Start of processing for Analyze_Depends_In_Decl_Part
1671
1672 begin
1673 Set_Analyzed (N);
1674
1675 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1676 Subp_Id := Defining_Entity (Subp_Decl);
1677
1678 -- The logic in this routine is used to analyze both pragma Depends and
1679 -- pragma Refined_Depends since they have the same syntax and base
1680 -- semantics. Find the entity of the corresponding spec when analyzing
1681 -- Refined_Depends.
1682
1683 if Nkind (Subp_Decl) = N_Subprogram_Body
1684 and then Present (Corresponding_Spec (Subp_Decl))
1685 then
1686 Spec_Id := Corresponding_Spec (Subp_Decl);
1687
1688 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
1689 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
1690 then
1691 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1692
1693 else
1694 Spec_Id := Subp_Id;
1695 end if;
1696
1697 -- Empty dependency list
1698
1699 if Nkind (Deps) = N_Null then
1700
1701 -- Gather all states, variables and formal parameters that the
1702 -- subprogram may depend on. These items are obtained from the
1703 -- parameter profile or pragma [Refined_]Global (if available).
1704
1705 Collect_Subprogram_Inputs_Outputs
1706 (Subp_Id => Subp_Id,
1707 Subp_Inputs => Subp_Inputs,
1708 Subp_Outputs => Subp_Outputs,
1709 Global_Seen => Global_Seen);
1710
1711 -- Verify that every input or output of the subprogram appear in a
1712 -- dependency.
1713
1714 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1715 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1716 Check_Function_Return;
1717
1718 -- Dependency clauses appear as component associations of an aggregate
1719
1720 elsif Nkind (Deps) = N_Aggregate then
1721
1722 -- Do not attempt to perform analysis of a syntactically illegal
1723 -- clause as this will lead to misleading errors.
1724
1725 if Has_Extra_Parentheses (Deps) then
1726 return;
1727 end if;
1728
1729 if Present (Component_Associations (Deps)) then
1730 Last_Clause := Last (Component_Associations (Deps));
1731
1732 -- Gather all states, variables and formal parameters that the
1733 -- subprogram may depend on. These items are obtained from the
1734 -- parameter profile or pragma [Refined_]Global (if available).
1735
1736 Collect_Subprogram_Inputs_Outputs
1737 (Subp_Id => Subp_Id,
1738 Subp_Inputs => Subp_Inputs,
1739 Subp_Outputs => Subp_Outputs,
1740 Global_Seen => Global_Seen);
1741
1742 -- Ensure that the formal parameters are visible when analyzing
1743 -- all clauses. This falls out of the general rule of aspects
1744 -- pertaining to subprogram declarations. Skip the installation
1745 -- for subprogram bodies because the formals are already visible.
1746
1747 if not In_Open_Scopes (Spec_Id) then
1748 Restore_Scope := True;
1749 Push_Scope (Spec_Id);
1750 Install_Formals (Spec_Id);
1751 end if;
1752
1753 Clause := First (Component_Associations (Deps));
1754 while Present (Clause) loop
1755 Errors := Serious_Errors_Detected;
1756
1757 -- Normalization may create extra clauses that contain
1758 -- replicated input and output names. There is no need to
1759 -- reanalyze them.
1760
1761 if not Analyzed (Clause) then
1762 Set_Analyzed (Clause);
1763
1764 Analyze_Dependency_Clause
1765 (Clause => Clause,
1766 Is_Last => Clause = Last_Clause);
1767 end if;
1768
1769 -- Do not normalize a clause if errors were detected (count
1770 -- of Serious_Errors has increased) because the inputs and/or
1771 -- outputs may denote illegal items. Normalization is disabled
1772 -- in ASIS mode as it alters the tree by introducing new nodes
1773 -- similar to expansion.
1774
1775 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1776 Normalize_Clause (Clause);
1777 end if;
1778
1779 Next (Clause);
1780 end loop;
1781
1782 if Restore_Scope then
1783 End_Scope;
1784 end if;
1785
1786 -- Verify that every input or output of the subprogram appear in a
1787 -- dependency.
1788
1789 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1790 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1791 Check_Function_Return;
1792
1793 -- The dependency list is malformed. This is a syntax error, always
1794 -- report.
1795
1796 else
1797 Error_Msg_N ("malformed dependency relation", Deps);
1798 return;
1799 end if;
1800
1801 -- The top level dependency relation is malformed. This is a syntax
1802 -- error, always report.
1803
1804 else
1805 Error_Msg_N ("malformed dependency relation", Deps);
1806 return;
1807 end if;
1808
1809 -- Ensure that a state and a corresponding constituent do not appear
1810 -- together in pragma [Refined_]Depends.
1811
1812 Check_State_And_Constituent_Use
1813 (States => States_Seen,
1814 Constits => Constits_Seen,
1815 Context => N);
1816 end Analyze_Depends_In_Decl_Part;
1817
1818 --------------------------------------------
1819 -- Analyze_External_Property_In_Decl_Part --
1820 --------------------------------------------
1821
1822 procedure Analyze_External_Property_In_Decl_Part
1823 (N : Node_Id;
1824 Expr_Val : out Boolean)
1825 is
1826 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1827 Obj_Id : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1));
1828 Expr : constant Node_Id := Get_Pragma_Arg (Next (Arg1));
1829
1830 begin
1831 Error_Msg_Name_1 := Pragma_Name (N);
1832
1833 -- An external property pragma must apply to a volatile object other
1834 -- than a formal subprogram parameter (SPARK RM 7.1.3(2)). The check
1835 -- is performed at the end of the declarative region due to a possible
1836 -- out-of-order arrangement of pragmas:
1837
1838 -- Obj : ...;
1839 -- pragma Async_Readers (Obj);
1840 -- pragma Volatile (Obj);
1841
1842 if not Is_SPARK_Volatile (Obj_Id) then
1843 SPARK_Msg_N
1844 ("external property % must apply to a volatile object", N);
1845 end if;
1846
1847 -- Ensure that the Boolean expression (if present) is static. A missing
1848 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1849
1850 Expr_Val := True;
1851
1852 if Present (Expr) then
1853 Analyze_And_Resolve (Expr, Standard_Boolean);
1854
1855 if Is_OK_Static_Expression (Expr) then
1856 Expr_Val := Is_True (Expr_Value (Expr));
1857 else
1858 SPARK_Msg_N ("expression of % must be static", Expr);
1859 end if;
1860 end if;
1861 end Analyze_External_Property_In_Decl_Part;
1862
1863 ---------------------------------
1864 -- Analyze_Global_In_Decl_Part --
1865 ---------------------------------
1866
1867 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1868 Constits_Seen : Elist_Id := No_Elist;
1869 -- A list containing the entities of all constituents processed so far.
1870 -- It aids in detecting illegal usage of a state and a corresponding
1871 -- constituent in pragma [Refinde_]Global.
1872
1873 Seen : Elist_Id := No_Elist;
1874 -- A list containing the entities of all the items processed so far. It
1875 -- plays a role in detecting distinct entities.
1876
1877 Spec_Id : Entity_Id;
1878 -- The entity of the subprogram subject to pragma [Refined_]Global
1879
1880 States_Seen : Elist_Id := No_Elist;
1881 -- A list containing the entities of all states processed so far. It
1882 -- helps in detecting illegal usage of a state and a corresponding
1883 -- constituent in pragma [Refined_]Global.
1884
1885 Subp_Id : Entity_Id;
1886 -- The entity of the subprogram [body or stub] subject to pragma
1887 -- [Refined_]Global.
1888
1889 In_Out_Seen : Boolean := False;
1890 Input_Seen : Boolean := False;
1891 Output_Seen : Boolean := False;
1892 Proof_Seen : Boolean := False;
1893 -- Flags used to verify the consistency of modes
1894
1895 procedure Analyze_Global_List
1896 (List : Node_Id;
1897 Global_Mode : Name_Id := Name_Input);
1898 -- Verify the legality of a single global list declaration. Global_Mode
1899 -- denotes the current mode in effect.
1900
1901 -------------------------
1902 -- Analyze_Global_List --
1903 -------------------------
1904
1905 procedure Analyze_Global_List
1906 (List : Node_Id;
1907 Global_Mode : Name_Id := Name_Input)
1908 is
1909 procedure Analyze_Global_Item
1910 (Item : Node_Id;
1911 Global_Mode : Name_Id);
1912 -- Verify the legality of a single global item declaration.
1913 -- Global_Mode denotes the current mode in effect.
1914
1915 procedure Check_Duplicate_Mode
1916 (Mode : Node_Id;
1917 Status : in out Boolean);
1918 -- Flag Status denotes whether a particular mode has been seen while
1919 -- processing a global list. This routine verifies that Mode is not a
1920 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1921
1922 procedure Check_Mode_Restriction_In_Enclosing_Context
1923 (Item : Node_Id;
1924 Item_Id : Entity_Id);
1925 -- Verify that an item of mode In_Out or Output does not appear as an
1926 -- input in the Global aspect of an enclosing subprogram. If this is
1927 -- the case, emit an error. Item and Item_Id are respectively the
1928 -- item and its entity.
1929
1930 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1931 -- Mode denotes either In_Out or Output. Depending on the kind of the
1932 -- related subprogram, emit an error if those two modes apply to a
1933 -- function (SPARK RM 6.1.4(10)).
1934
1935 -------------------------
1936 -- Analyze_Global_Item --
1937 -------------------------
1938
1939 procedure Analyze_Global_Item
1940 (Item : Node_Id;
1941 Global_Mode : Name_Id)
1942 is
1943 Item_Id : Entity_Id;
1944
1945 begin
1946 -- Detect one of the following cases
1947
1948 -- with Global => (null, Name)
1949 -- with Global => (Name_1, null, Name_2)
1950 -- with Global => (Name, null)
1951
1952 if Nkind (Item) = N_Null then
1953 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
1954 return;
1955 end if;
1956
1957 Analyze (Item);
1958 Resolve_State (Item);
1959
1960 -- Find the entity of the item. If this is a renaming, climb the
1961 -- renaming chain to reach the root object. Renamings of non-
1962 -- entire objects do not yield an entity (Empty).
1963
1964 Item_Id := Entity_Of (Item);
1965
1966 if Present (Item_Id) then
1967
1968 -- A global item may denote a formal parameter of an enclosing
1969 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
1970 -- provide a better error diagnostic.
1971
1972 if Is_Formal (Item_Id) then
1973 if Scope (Item_Id) = Spec_Id then
1974 SPARK_Msg_NE
1975 ("global item cannot reference parameter of subprogram",
1976 Item, Spec_Id);
1977 return;
1978 end if;
1979
1980 -- A constant cannot act as a global item (SPARK RM 6.1.4(7)).
1981 -- Do this check first to provide a better error diagnostic.
1982
1983 elsif Ekind (Item_Id) = E_Constant then
1984 SPARK_Msg_N ("global item cannot denote a constant", Item);
1985
1986 -- The only legal references are those to abstract states and
1987 -- variables (SPARK RM 6.1.4(4)).
1988
1989 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1990 SPARK_Msg_N
1991 ("global item must denote variable or state", Item);
1992 return;
1993 end if;
1994
1995 -- State related checks
1996
1997 if Ekind (Item_Id) = E_Abstract_State then
1998
1999 -- An abstract state with visible refinement cannot appear
2000 -- in pragma [Refined_]Global as its place must be taken by
2001 -- some of its constituents (SPARK RM 6.1.4(8)).
2002
2003 if Has_Visible_Refinement (Item_Id) then
2004 SPARK_Msg_NE
2005 ("cannot mention state & in global refinement",
2006 Item, Item_Id);
2007 SPARK_Msg_N ("\use its constituents instead", Item);
2008 return;
2009
2010 -- If the reference to the abstract state appears in an
2011 -- enclosing package body that will eventually refine the
2012 -- state, record the reference for future checks.
2013
2014 else
2015 Record_Possible_Body_Reference
2016 (State_Id => Item_Id,
2017 Ref => Item);
2018 end if;
2019
2020 -- Variable related checks. These are only relevant when
2021 -- SPARK_Mode is on as they are not standard Ada legality
2022 -- rules.
2023
2024 elsif SPARK_Mode = On and then Is_SPARK_Volatile (Item_Id) then
2025
2026 -- A volatile object cannot appear as a global item of a
2027 -- function (SPARK RM 7.1.3(9)).
2028
2029 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2030 Error_Msg_NE
2031 ("volatile object & cannot act as global item of a "
2032 & "function", Item, Item_Id);
2033 return;
2034
2035 -- A volatile object with property Effective_Reads set to
2036 -- True must have mode Output or In_Out.
2037
2038 elsif Effective_Reads_Enabled (Item_Id)
2039 and then Global_Mode = Name_Input
2040 then
2041 Error_Msg_NE
2042 ("volatile object & with property Effective_Reads must "
2043 & "have mode In_Out or Output (SPARK RM 7.1.3(11))",
2044 Item, Item_Id);
2045 return;
2046 end if;
2047 end if;
2048
2049 -- When the item renames an entire object, replace the item
2050 -- with a reference to the object.
2051
2052 if Present (Renamed_Object (Entity (Item))) then
2053 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2054 Analyze (Item);
2055 end if;
2056
2057 -- Some form of illegal construct masquerading as a name
2058 -- (SPARK RM 6.1.4(4)).
2059
2060 else
2061 Error_Msg_N ("global item must denote variable or state", Item);
2062 return;
2063 end if;
2064
2065 -- Verify that an output does not appear as an input in an
2066 -- enclosing subprogram.
2067
2068 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2069 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
2070 end if;
2071
2072 -- The same entity might be referenced through various way.
2073 -- Check the entity of the item rather than the item itself
2074 -- (SPARK RM 6.1.4(11)).
2075
2076 if Contains (Seen, Item_Id) then
2077 SPARK_Msg_N ("duplicate global item", Item);
2078
2079 -- Add the entity of the current item to the list of processed
2080 -- items.
2081
2082 else
2083 Add_Item (Item_Id, Seen);
2084
2085 if Ekind (Item_Id) = E_Abstract_State then
2086 Add_Item (Item_Id, States_Seen);
2087 end if;
2088
2089 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
2090 and then Present (Encapsulating_State (Item_Id))
2091 then
2092 Add_Item (Item_Id, Constits_Seen);
2093 end if;
2094 end if;
2095 end Analyze_Global_Item;
2096
2097 --------------------------
2098 -- Check_Duplicate_Mode --
2099 --------------------------
2100
2101 procedure Check_Duplicate_Mode
2102 (Mode : Node_Id;
2103 Status : in out Boolean)
2104 is
2105 begin
2106 if Status then
2107 SPARK_Msg_N ("duplicate global mode", Mode);
2108 end if;
2109
2110 Status := True;
2111 end Check_Duplicate_Mode;
2112
2113 -------------------------------------------------
2114 -- Check_Mode_Restriction_In_Enclosing_Context --
2115 -------------------------------------------------
2116
2117 procedure Check_Mode_Restriction_In_Enclosing_Context
2118 (Item : Node_Id;
2119 Item_Id : Entity_Id)
2120 is
2121 Context : Entity_Id;
2122 Dummy : Boolean;
2123 Inputs : Elist_Id := No_Elist;
2124 Outputs : Elist_Id := No_Elist;
2125
2126 begin
2127 -- Traverse the scope stack looking for enclosing subprograms
2128 -- subject to pragma [Refined_]Global.
2129
2130 Context := Scope (Subp_Id);
2131 while Present (Context) and then Context /= Standard_Standard loop
2132 if Is_Subprogram (Context)
2133 and then
2134 (Present (Get_Pragma (Context, Pragma_Global))
2135 or else
2136 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2137 then
2138 Collect_Subprogram_Inputs_Outputs
2139 (Subp_Id => Context,
2140 Subp_Inputs => Inputs,
2141 Subp_Outputs => Outputs,
2142 Global_Seen => Dummy);
2143
2144 -- The item is classified as In_Out or Output but appears as
2145 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2146
2147 if Appears_In (Inputs, Item_Id)
2148 and then not Appears_In (Outputs, Item_Id)
2149 then
2150 SPARK_Msg_NE
2151 ("global item & cannot have mode In_Out or Output",
2152 Item, Item_Id);
2153 SPARK_Msg_NE
2154 ("\item already appears as input of subprogram &",
2155 Item, Context);
2156
2157 -- Stop the traversal once an error has been detected
2158
2159 exit;
2160 end if;
2161 end if;
2162
2163 Context := Scope (Context);
2164 end loop;
2165 end Check_Mode_Restriction_In_Enclosing_Context;
2166
2167 ----------------------------------------
2168 -- Check_Mode_Restriction_In_Function --
2169 ----------------------------------------
2170
2171 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2172 begin
2173 if Ekind (Spec_Id) = E_Function then
2174 SPARK_Msg_N
2175 ("global mode & is not applicable to functions", Mode);
2176 end if;
2177 end Check_Mode_Restriction_In_Function;
2178
2179 -- Local variables
2180
2181 Assoc : Node_Id;
2182 Item : Node_Id;
2183 Mode : Node_Id;
2184
2185 -- Start of processing for Analyze_Global_List
2186
2187 begin
2188 if Nkind (List) = N_Null then
2189 Set_Analyzed (List);
2190
2191 -- Single global item declaration
2192
2193 elsif Nkind_In (List, N_Expanded_Name,
2194 N_Identifier,
2195 N_Selected_Component)
2196 then
2197 Analyze_Global_Item (List, Global_Mode);
2198
2199 -- Simple global list or moded global list declaration
2200
2201 elsif Nkind (List) = N_Aggregate then
2202 Set_Analyzed (List);
2203
2204 -- The declaration of a simple global list appear as a collection
2205 -- of expressions.
2206
2207 if Present (Expressions (List)) then
2208 if Present (Component_Associations (List)) then
2209 SPARK_Msg_N
2210 ("cannot mix moded and non-moded global lists", List);
2211 end if;
2212
2213 Item := First (Expressions (List));
2214 while Present (Item) loop
2215 Analyze_Global_Item (Item, Global_Mode);
2216
2217 Next (Item);
2218 end loop;
2219
2220 -- The declaration of a moded global list appears as a collection
2221 -- of component associations where individual choices denote
2222 -- modes.
2223
2224 elsif Present (Component_Associations (List)) then
2225 if Present (Expressions (List)) then
2226 SPARK_Msg_N
2227 ("cannot mix moded and non-moded global lists", List);
2228 end if;
2229
2230 Assoc := First (Component_Associations (List));
2231 while Present (Assoc) loop
2232 Mode := First (Choices (Assoc));
2233
2234 if Nkind (Mode) = N_Identifier then
2235 if Chars (Mode) = Name_In_Out then
2236 Check_Duplicate_Mode (Mode, In_Out_Seen);
2237 Check_Mode_Restriction_In_Function (Mode);
2238
2239 elsif Chars (Mode) = Name_Input then
2240 Check_Duplicate_Mode (Mode, Input_Seen);
2241
2242 elsif Chars (Mode) = Name_Output then
2243 Check_Duplicate_Mode (Mode, Output_Seen);
2244 Check_Mode_Restriction_In_Function (Mode);
2245
2246 elsif Chars (Mode) = Name_Proof_In then
2247 Check_Duplicate_Mode (Mode, Proof_Seen);
2248
2249 else
2250 SPARK_Msg_N ("invalid mode selector", Mode);
2251 end if;
2252
2253 else
2254 SPARK_Msg_N ("invalid mode selector", Mode);
2255 end if;
2256
2257 -- Items in a moded list appear as a collection of
2258 -- expressions. Reuse the existing machinery to analyze
2259 -- them.
2260
2261 Analyze_Global_List
2262 (List => Expression (Assoc),
2263 Global_Mode => Chars (Mode));
2264
2265 Next (Assoc);
2266 end loop;
2267
2268 -- Invalid tree
2269
2270 else
2271 raise Program_Error;
2272 end if;
2273
2274 -- Any other attempt to declare a global item is illegal. This is a
2275 -- syntax error, always report.
2276
2277 else
2278 Error_Msg_N ("malformed global list", List);
2279 end if;
2280 end Analyze_Global_List;
2281
2282 -- Local variables
2283
2284 Items : constant Node_Id :=
2285 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2286 Subp_Decl : Node_Id;
2287
2288 Restore_Scope : Boolean := False;
2289 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
2290
2291 -- Start of processing for Analyze_Global_In_Decl_List
2292
2293 begin
2294 Set_Analyzed (N);
2295 Check_SPARK_Aspect_For_ASIS (N);
2296
2297 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
2298 Subp_Id := Defining_Entity (Subp_Decl);
2299
2300 -- The logic in this routine is used to analyze both pragma Global and
2301 -- pragma Refined_Global since they have the same syntax and base
2302 -- semantics. Find the entity of the corresponding spec when analyzing
2303 -- Refined_Global.
2304
2305 if Nkind (Subp_Decl) = N_Subprogram_Body
2306 and then Present (Corresponding_Spec (Subp_Decl))
2307 then
2308 Spec_Id := Corresponding_Spec (Subp_Decl);
2309
2310 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
2311 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
2312 then
2313 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
2314
2315 else
2316 Spec_Id := Subp_Id;
2317 end if;
2318
2319 -- There is nothing to be done for a null global list
2320
2321 if Nkind (Items) = N_Null then
2322 Set_Analyzed (Items);
2323
2324 -- Analyze the various forms of global lists and items. Note that some
2325 -- of these may be malformed in which case the analysis emits error
2326 -- messages.
2327
2328 else
2329 -- Ensure that the formal parameters are visible when processing an
2330 -- item. This falls out of the general rule of aspects pertaining to
2331 -- subprogram declarations.
2332
2333 if not In_Open_Scopes (Spec_Id) then
2334 Restore_Scope := True;
2335 Push_Scope (Spec_Id);
2336 Install_Formals (Spec_Id);
2337 end if;
2338
2339 Analyze_Global_List (Items);
2340
2341 if Restore_Scope then
2342 End_Scope;
2343 end if;
2344 end if;
2345
2346 -- Ensure that a state and a corresponding constituent do not appear
2347 -- together in pragma [Refined_]Global.
2348
2349 Check_State_And_Constituent_Use
2350 (States => States_Seen,
2351 Constits => Constits_Seen,
2352 Context => N);
2353 end Analyze_Global_In_Decl_Part;
2354
2355 --------------------------------------------
2356 -- Analyze_Initial_Condition_In_Decl_Part --
2357 --------------------------------------------
2358
2359 procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is
2360 Expr : constant Node_Id :=
2361 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2362
2363 begin
2364 Set_Analyzed (N);
2365
2366 -- The expression is preanalyzed because it has not been moved to its
2367 -- final place yet. A direct analysis may generate side effects and this
2368 -- is not desired at this point.
2369
2370 Preanalyze_And_Resolve (Expr, Standard_Boolean);
2371 end Analyze_Initial_Condition_In_Decl_Part;
2372
2373 --------------------------------------
2374 -- Analyze_Initializes_In_Decl_Part --
2375 --------------------------------------
2376
2377 procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is
2378 Pack_Spec : constant Node_Id := Parent (N);
2379 Pack_Id : constant Entity_Id := Defining_Entity (Parent (Pack_Spec));
2380
2381 Constits_Seen : Elist_Id := No_Elist;
2382 -- A list containing the entities of all constituents processed so far.
2383 -- It aids in detecting illegal usage of a state and a corresponding
2384 -- constituent in pragma Initializes.
2385
2386 Items_Seen : Elist_Id := No_Elist;
2387 -- A list of all initialization items processed so far. This list is
2388 -- used to detect duplicate items.
2389
2390 Non_Null_Seen : Boolean := False;
2391 Null_Seen : Boolean := False;
2392 -- Flags used to check the legality of a null initialization list
2393
2394 States_And_Vars : Elist_Id := No_Elist;
2395 -- A list of all abstract states and variables declared in the visible
2396 -- declarations of the related package. This list is used to detect the
2397 -- legality of initialization items.
2398
2399 States_Seen : Elist_Id := No_Elist;
2400 -- A list containing the entities of all states processed so far. It
2401 -- helps in detecting illegal usage of a state and a corresponding
2402 -- constituent in pragma Initializes.
2403
2404 procedure Analyze_Initialization_Item (Item : Node_Id);
2405 -- Verify the legality of a single initialization item
2406
2407 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id);
2408 -- Verify the legality of a single initialization item followed by a
2409 -- list of input items.
2410
2411 procedure Collect_States_And_Variables;
2412 -- Inspect the visible declarations of the related package and gather
2413 -- the entities of all abstract states and variables in States_And_Vars.
2414
2415 ---------------------------------
2416 -- Analyze_Initialization_Item --
2417 ---------------------------------
2418
2419 procedure Analyze_Initialization_Item (Item : Node_Id) is
2420 Item_Id : Entity_Id;
2421
2422 begin
2423 -- Null initialization list
2424
2425 if Nkind (Item) = N_Null then
2426 if Null_Seen then
2427 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2428
2429 elsif Non_Null_Seen then
2430 SPARK_Msg_N
2431 ("cannot mix null and non-null initialization items", Item);
2432 else
2433 Null_Seen := True;
2434 end if;
2435
2436 -- Initialization item
2437
2438 else
2439 Non_Null_Seen := True;
2440
2441 if Null_Seen then
2442 SPARK_Msg_N
2443 ("cannot mix null and non-null initialization items", Item);
2444 end if;
2445
2446 Analyze (Item);
2447 Resolve_State (Item);
2448
2449 if Is_Entity_Name (Item) then
2450 Item_Id := Entity_Of (Item);
2451
2452 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2453
2454 -- The state or variable must be declared in the visible
2455 -- declarations of the package (SPARK RM 7.1.5(7)).
2456
2457 if not Contains (States_And_Vars, Item_Id) then
2458 Error_Msg_Name_1 := Chars (Pack_Id);
2459 SPARK_Msg_NE
2460 ("initialization item & must appear in the visible "
2461 & "declarations of package %", Item, Item_Id);
2462
2463 -- Detect a duplicate use of the same initialization item
2464 -- (SPARK RM 7.1.5(5)).
2465
2466 elsif Contains (Items_Seen, Item_Id) then
2467 SPARK_Msg_N ("duplicate initialization item", Item);
2468
2469 -- The item is legal, add it to the list of processed states
2470 -- and variables.
2471
2472 else
2473 Add_Item (Item_Id, Items_Seen);
2474
2475 if Ekind (Item_Id) = E_Abstract_State then
2476 Add_Item (Item_Id, States_Seen);
2477 end if;
2478
2479 if Present (Encapsulating_State (Item_Id)) then
2480 Add_Item (Item_Id, Constits_Seen);
2481 end if;
2482 end if;
2483
2484 -- The item references something that is not a state or a
2485 -- variable (SPARK RM 7.1.5(3)).
2486
2487 else
2488 SPARK_Msg_N
2489 ("initialization item must denote variable or state",
2490 Item);
2491 end if;
2492
2493 -- Some form of illegal construct masquerading as a name
2494 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2495
2496 else
2497 Error_Msg_N
2498 ("initialization item must denote variable or state", Item);
2499 end if;
2500 end if;
2501 end Analyze_Initialization_Item;
2502
2503 ---------------------------------------------
2504 -- Analyze_Initialization_Item_With_Inputs --
2505 ---------------------------------------------
2506
2507 procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is
2508 Inputs_Seen : Elist_Id := No_Elist;
2509 -- A list of all inputs processed so far. This list is used to detect
2510 -- duplicate uses of an input.
2511
2512 Non_Null_Seen : Boolean := False;
2513 Null_Seen : Boolean := False;
2514 -- Flags used to check the legality of an input list
2515
2516 procedure Analyze_Input_Item (Input : Node_Id);
2517 -- Verify the legality of a single input item
2518
2519 ------------------------
2520 -- Analyze_Input_Item --
2521 ------------------------
2522
2523 procedure Analyze_Input_Item (Input : Node_Id) is
2524 Input_Id : Entity_Id;
2525
2526 begin
2527 -- Null input list
2528
2529 if Nkind (Input) = N_Null then
2530 if Null_Seen then
2531 SPARK_Msg_N
2532 ("multiple null initializations not allowed", Item);
2533
2534 elsif Non_Null_Seen then
2535 SPARK_Msg_N
2536 ("cannot mix null and non-null initialization item", Item);
2537 else
2538 Null_Seen := True;
2539 end if;
2540
2541 -- Input item
2542
2543 else
2544 Non_Null_Seen := True;
2545
2546 if Null_Seen then
2547 SPARK_Msg_N
2548 ("cannot mix null and non-null initialization item", Item);
2549 end if;
2550
2551 Analyze (Input);
2552 Resolve_State (Input);
2553
2554 if Is_Entity_Name (Input) then
2555 Input_Id := Entity_Of (Input);
2556
2557 if Ekind_In (Input_Id, E_Abstract_State,
2558 E_In_Parameter,
2559 E_In_Out_Parameter,
2560 E_Out_Parameter,
2561 E_Variable)
2562 then
2563 -- The input cannot denote states or variables declared
2564 -- within the related package.
2565
2566 if Within_Scope (Input_Id, Current_Scope) then
2567 Error_Msg_Name_1 := Chars (Pack_Id);
2568 SPARK_Msg_NE
2569 ("input item & cannot denote a visible variable or "
2570 & "state of package % (SPARK RM 7.1.5(4))",
2571 Input, Input_Id);
2572
2573 -- Detect a duplicate use of the same input item
2574 -- (SPARK RM 7.1.5(5)).
2575
2576 elsif Contains (Inputs_Seen, Input_Id) then
2577 SPARK_Msg_N ("duplicate input item", Input);
2578
2579 -- Input is legal, add it to the list of processed inputs
2580
2581 else
2582 Add_Item (Input_Id, Inputs_Seen);
2583
2584 if Ekind (Input_Id) = E_Abstract_State then
2585 Add_Item (Input_Id, States_Seen);
2586 end if;
2587
2588 if Ekind_In (Input_Id, E_Abstract_State, E_Variable)
2589 and then Present (Encapsulating_State (Input_Id))
2590 then
2591 Add_Item (Input_Id, Constits_Seen);
2592 end if;
2593 end if;
2594
2595 -- The input references something that is not a state or a
2596 -- variable (SPARK RM 7.1.5(3)).
2597
2598 else
2599 SPARK_Msg_N
2600 ("input item must denote variable or state", Input);
2601 end if;
2602
2603 -- Some form of illegal construct masquerading as a name
2604 -- (SPARK RM 7.1.5(3)).
2605
2606 else
2607 SPARK_Msg_N
2608 ("input item must denote variable or state", Input);
2609 end if;
2610 end if;
2611 end Analyze_Input_Item;
2612
2613 -- Local variables
2614
2615 Inputs : constant Node_Id := Expression (Item);
2616 Elmt : Node_Id;
2617 Input : Node_Id;
2618
2619 Name_Seen : Boolean := False;
2620 -- A flag used to detect multiple item names
2621
2622 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2623
2624 begin
2625 -- Inspect the name of an item with inputs
2626
2627 Elmt := First (Choices (Item));
2628 while Present (Elmt) loop
2629 if Name_Seen then
2630 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2631 else
2632 Name_Seen := True;
2633 Analyze_Initialization_Item (Elmt);
2634 end if;
2635
2636 Next (Elmt);
2637 end loop;
2638
2639 -- Multiple input items appear as an aggregate
2640
2641 if Nkind (Inputs) = N_Aggregate then
2642 if Present (Expressions (Inputs)) then
2643 Input := First (Expressions (Inputs));
2644 while Present (Input) loop
2645 Analyze_Input_Item (Input);
2646 Next (Input);
2647 end loop;
2648 end if;
2649
2650 if Present (Component_Associations (Inputs)) then
2651 SPARK_Msg_N
2652 ("inputs must appear in named association form", Inputs);
2653 end if;
2654
2655 -- Single input item
2656
2657 else
2658 Analyze_Input_Item (Inputs);
2659 end if;
2660 end Analyze_Initialization_Item_With_Inputs;
2661
2662 ----------------------------------
2663 -- Collect_States_And_Variables --
2664 ----------------------------------
2665
2666 procedure Collect_States_And_Variables is
2667 Decl : Node_Id;
2668
2669 begin
2670 -- Collect the abstract states defined in the package (if any)
2671
2672 if Present (Abstract_States (Pack_Id)) then
2673 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2674 end if;
2675
2676 -- Collect all variables the appear in the visible declarations of
2677 -- the related package.
2678
2679 if Present (Visible_Declarations (Pack_Spec)) then
2680 Decl := First (Visible_Declarations (Pack_Spec));
2681 while Present (Decl) loop
2682 if Nkind (Decl) = N_Object_Declaration
2683 and then Ekind (Defining_Entity (Decl)) = E_Variable
2684 and then Comes_From_Source (Decl)
2685 then
2686 Add_Item (Defining_Entity (Decl), States_And_Vars);
2687 end if;
2688
2689 Next (Decl);
2690 end loop;
2691 end if;
2692 end Collect_States_And_Variables;
2693
2694 -- Local variables
2695
2696 Inits : constant Node_Id :=
2697 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2698 Init : Node_Id;
2699
2700 -- Start of processing for Analyze_Initializes_In_Decl_Part
2701
2702 begin
2703 Set_Analyzed (N);
2704
2705 Check_SPARK_Aspect_For_ASIS (N);
2706
2707 -- Nothing to do when the initialization list is empty
2708
2709 if Nkind (Inits) = N_Null then
2710 return;
2711 end if;
2712
2713 -- Single and multiple initialization clauses appear as an aggregate. If
2714 -- this is not the case, then either the parser or the analysis of the
2715 -- pragma failed to produce an aggregate.
2716
2717 pragma Assert (Nkind (Inits) = N_Aggregate);
2718
2719 -- Initialize the various lists used during analysis
2720
2721 Collect_States_And_Variables;
2722
2723 if Present (Expressions (Inits)) then
2724 Init := First (Expressions (Inits));
2725 while Present (Init) loop
2726 Analyze_Initialization_Item (Init);
2727 Next (Init);
2728 end loop;
2729 end if;
2730
2731 if Present (Component_Associations (Inits)) then
2732 Init := First (Component_Associations (Inits));
2733 while Present (Init) loop
2734 Analyze_Initialization_Item_With_Inputs (Init);
2735 Next (Init);
2736 end loop;
2737 end if;
2738
2739 -- Ensure that a state and a corresponding constituent do not appear
2740 -- together in pragma Initializes.
2741
2742 Check_State_And_Constituent_Use
2743 (States => States_Seen,
2744 Constits => Constits_Seen,
2745 Context => N);
2746 end Analyze_Initializes_In_Decl_Part;
2747
2748 --------------------
2749 -- Analyze_Pragma --
2750 --------------------
2751
2752 procedure Analyze_Pragma (N : Node_Id) is
2753 Loc : constant Source_Ptr := Sloc (N);
2754 Prag_Id : Pragma_Id;
2755
2756 Pname : Name_Id;
2757 -- Name of the source pragma, or name of the corresponding aspect for
2758 -- pragmas which originate in a source aspect. In the latter case, the
2759 -- name may be different from the pragma name.
2760
2761 Pragma_Exit : exception;
2762 -- This exception is used to exit pragma processing completely. It
2763 -- is used when an error is detected, and no further processing is
2764 -- required. It is also used if an earlier error has left the tree in
2765 -- a state where the pragma should not be processed.
2766
2767 Arg_Count : Nat;
2768 -- Number of pragma argument associations
2769
2770 Arg1 : Node_Id;
2771 Arg2 : Node_Id;
2772 Arg3 : Node_Id;
2773 Arg4 : Node_Id;
2774 -- First four pragma arguments (pragma argument association nodes, or
2775 -- Empty if the corresponding argument does not exist).
2776
2777 type Name_List is array (Natural range <>) of Name_Id;
2778 type Args_List is array (Natural range <>) of Node_Id;
2779 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2780
2781 -----------------------
2782 -- Local Subprograms --
2783 -----------------------
2784
2785 procedure Acquire_Warning_Match_String (Arg : Node_Id);
2786 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
2787 -- get the given string argument, and place it in Name_Buffer, adding
2788 -- leading and trailing asterisks if they are not already present. The
2789 -- caller has already checked that Arg is a static string expression.
2790
2791 procedure Ada_2005_Pragma;
2792 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2793 -- Ada 95 mode, these are implementation defined pragmas, so should be
2794 -- caught by the No_Implementation_Pragmas restriction.
2795
2796 procedure Ada_2012_Pragma;
2797 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2798 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2799 -- should be caught by the No_Implementation_Pragmas restriction.
2800
2801 procedure Analyze_Part_Of
2802 (Item_Id : Entity_Id;
2803 State : Node_Id;
2804 Indic : Node_Id;
2805 Legal : out Boolean);
2806 -- Subsidiary to the analysis of pragmas Abstract_State and Part_Of.
2807 -- Perform full analysis of indicator Part_Of. Item_Id is the entity of
2808 -- an abstract state, variable or package instantiation. State is the
2809 -- encapsulating state. Indic is the Part_Of indicator. Flag Legal is
2810 -- set when the indicator is legal.
2811
2812 procedure Analyze_Refined_Pragma
2813 (Spec_Id : out Entity_Id;
2814 Body_Id : out Entity_Id;
2815 Legal : out Boolean);
2816 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2817 -- Refined_Global and Refined_Post. Check the placement and related
2818 -- context of the pragma. Spec_Id is the entity of the related
2819 -- subprogram. Body_Id is the entity of the subprogram body. Flag
2820 -- Legal is set when the pragma is properly placed.
2821
2822 procedure Check_Ada_83_Warning;
2823 -- Issues a warning message for the current pragma if operating in Ada
2824 -- 83 mode (used for language pragmas that are not a standard part of
2825 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
2826 -- of 95 pragma.
2827
2828 procedure Check_Arg_Count (Required : Nat);
2829 -- Check argument count for pragma is equal to given parameter. If not,
2830 -- then issue an error message and raise Pragma_Exit.
2831
2832 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2833 -- Arg which can either be a pragma argument association, in which case
2834 -- the check is applied to the expression of the association or an
2835 -- expression directly.
2836
2837 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
2838 -- Check that an argument has the right form for an EXTERNAL_NAME
2839 -- parameter of an extended import/export pragma. The rule is that the
2840 -- name must be an identifier or string literal (in Ada 83 mode) or a
2841 -- static string expression (in Ada 95 mode).
2842
2843 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
2844 -- Check the specified argument Arg to make sure that it is an
2845 -- identifier. If not give error and raise Pragma_Exit.
2846
2847 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
2848 -- Check the specified argument Arg to make sure that it is an integer
2849 -- literal. If not give error and raise Pragma_Exit.
2850
2851 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
2852 -- Check the specified argument Arg to make sure that it has the proper
2853 -- syntactic form for a local name and meets the semantic requirements
2854 -- for a local name. The local name is analyzed as part of the
2855 -- processing for this call. In addition, the local name is required
2856 -- to represent an entity at the library level.
2857
2858 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
2859 -- Check the specified argument Arg to make sure that it has the proper
2860 -- syntactic form for a local name and meets the semantic requirements
2861 -- for a local name. The local name is analyzed as part of the
2862 -- processing for this call.
2863
2864 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
2865 -- Check the specified argument Arg to make sure that it is a valid
2866 -- locking policy name. If not give error and raise Pragma_Exit.
2867
2868 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
2869 -- Check the specified argument Arg to make sure that it is a valid
2870 -- elaboration policy name. If not give error and raise Pragma_Exit.
2871
2872 procedure Check_Arg_Is_One_Of
2873 (Arg : Node_Id;
2874 N1, N2 : Name_Id);
2875 procedure Check_Arg_Is_One_Of
2876 (Arg : Node_Id;
2877 N1, N2, N3 : Name_Id);
2878 procedure Check_Arg_Is_One_Of
2879 (Arg : Node_Id;
2880 N1, N2, N3, N4 : Name_Id);
2881 procedure Check_Arg_Is_One_Of
2882 (Arg : Node_Id;
2883 N1, N2, N3, N4, N5 : Name_Id);
2884 -- Check the specified argument Arg to make sure that it is an
2885 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2886 -- present). If not then give error and raise Pragma_Exit.
2887
2888 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
2889 -- Check the specified argument Arg to make sure that it is a valid
2890 -- queuing policy name. If not give error and raise Pragma_Exit.
2891
2892 procedure Check_Arg_Is_OK_Static_Expression
2893 (Arg : Node_Id;
2894 Typ : Entity_Id := Empty);
2895 -- Check the specified argument Arg to make sure that it is a static
2896 -- expression of the given type (i.e. it will be analyzed and resolved
2897 -- using this type, which can be any valid argument to Resolve, e.g.
2898 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2899 -- Typ is left Empty, then any static expression is allowed. Includes
2900 -- checking that the argument does not raise Constraint_Error.
2901
2902 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
2903 -- Check the specified argument Arg to make sure that it is a valid task
2904 -- dispatching policy name. If not give error and raise Pragma_Exit.
2905
2906 procedure Check_Arg_Order (Names : Name_List);
2907 -- Checks for an instance of two arguments with identifiers for the
2908 -- current pragma which are not in the sequence indicated by Names,
2909 -- and if so, generates a fatal message about bad order of arguments.
2910
2911 procedure Check_At_Least_N_Arguments (N : Nat);
2912 -- Check there are at least N arguments present
2913
2914 procedure Check_At_Most_N_Arguments (N : Nat);
2915 -- Check there are no more than N arguments present
2916
2917 procedure Check_Component
2918 (Comp : Node_Id;
2919 UU_Typ : Entity_Id;
2920 In_Variant_Part : Boolean := False);
2921 -- Examine an Unchecked_Union component for correct use of per-object
2922 -- constrained subtypes, and for restrictions on finalizable components.
2923 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2924 -- should be set when Comp comes from a record variant.
2925
2926 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id);
2927 -- Subsidiary routine to the analysis of pragmas Abstract_State,
2928 -- Initial_Condition and Initializes. Determine whether pragma First
2929 -- appears before pragma Second. If this is not the case, emit an error.
2930
2931 procedure Check_Duplicate_Pragma (E : Entity_Id);
2932 -- Check if a rep item of the same name as the current pragma is already
2933 -- chained as a rep pragma to the given entity. If so give a message
2934 -- about the duplicate, and then raise Pragma_Exit so does not return.
2935 -- Note that if E is a type, then this routine avoids flagging a pragma
2936 -- which applies to a parent type from which E is derived.
2937
2938 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2939 -- Nam is an N_String_Literal node containing the external name set by
2940 -- an Import or Export pragma (or extended Import or Export pragma).
2941 -- This procedure checks for possible duplications if this is the export
2942 -- case, and if found, issues an appropriate error message.
2943
2944 procedure Check_Expr_Is_OK_Static_Expression
2945 (Expr : Node_Id;
2946 Typ : Entity_Id := Empty);
2947 -- Check the specified expression Expr to make sure that it is a static
2948 -- expression of the given type (i.e. it will be analyzed and resolved
2949 -- using this type, which can be any valid argument to Resolve, e.g.
2950 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2951 -- Typ is left Empty, then any static expression is allowed. Includes
2952 -- checking that the expression does not raise Constraint_Error.
2953
2954 procedure Check_First_Subtype (Arg : Node_Id);
2955 -- Checks that Arg, whose expression is an entity name, references a
2956 -- first subtype.
2957
2958 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2959 -- Checks that the given argument has an identifier, and if so, requires
2960 -- it to match the given identifier name. If there is no identifier, or
2961 -- a non-matching identifier, then an error message is given and
2962 -- Pragma_Exit is raised.
2963
2964 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2965 -- Checks that the given argument has an identifier, and if so, requires
2966 -- it to match one of the given identifier names. If there is no
2967 -- identifier, or a non-matching identifier, then an error message is
2968 -- given and Pragma_Exit is raised.
2969
2970 procedure Check_In_Main_Program;
2971 -- Common checks for pragmas that appear within a main program
2972 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2973
2974 procedure Check_Interrupt_Or_Attach_Handler;
2975 -- Common processing for first argument of pragma Interrupt_Handler or
2976 -- pragma Attach_Handler.
2977
2978 procedure Check_Loop_Pragma_Placement;
2979 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
2980 -- appear immediately within a construct restricted to loops, and that
2981 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
2982
2983 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2984 -- Check that pragma appears in a declarative part, or in a package
2985 -- specification, i.e. that it does not occur in a statement sequence
2986 -- in a body.
2987
2988 procedure Check_No_Identifier (Arg : Node_Id);
2989 -- Checks that the given argument does not have an identifier. If
2990 -- an identifier is present, then an error message is issued, and
2991 -- Pragma_Exit is raised.
2992
2993 procedure Check_No_Identifiers;
2994 -- Checks that none of the arguments to the pragma has an identifier.
2995 -- If any argument has an identifier, then an error message is issued,
2996 -- and Pragma_Exit is raised.
2997
2998 procedure Check_No_Link_Name;
2999 -- Checks that no link name is specified
3000
3001 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
3002 -- Checks if the given argument has an identifier, and if so, requires
3003 -- it to match the given identifier name. If there is a non-matching
3004 -- identifier, then an error message is given and Pragma_Exit is raised.
3005
3006 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
3007 -- Checks if the given argument has an identifier, and if so, requires
3008 -- it to match the given identifier name. If there is a non-matching
3009 -- identifier, then an error message is given and Pragma_Exit is raised.
3010 -- In this version of the procedure, the identifier name is given as
3011 -- a string with lower case letters.
3012
3013 procedure Check_Pre_Post;
3014 -- Called to perform checks for Pre, Pre_Class, Post, Post_Class
3015 -- pragmas. These are processed by transformation to equivalent
3016 -- Precondition and Postcondition pragmas, but Pre and Post need an
3017 -- additional check that they are not used in a subprogram body when
3018 -- there is a separate spec present.
3019
3020 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
3021 -- Called to process a precondition or postcondition pragma. There are
3022 -- three cases:
3023 --
3024 -- The pragma appears after a subprogram spec
3025 --
3026 -- If the corresponding check is not enabled, the pragma is analyzed
3027 -- but otherwise ignored and control returns with In_Body set False.
3028 --
3029 -- If the check is enabled, then the first step is to analyze the
3030 -- pragma, but this is skipped if the subprogram spec appears within
3031 -- a package specification (because this is the case where we delay
3032 -- analysis till the end of the spec). Then (whether or not it was
3033 -- analyzed), the pragma is chained to the subprogram in question
3034 -- (using Pre_Post_Conditions and Next_Pragma) and control returns
3035 -- to the caller with In_Body set False.
3036 --
3037 -- The pragma appears at the start of subprogram body declarations
3038 --
3039 -- In this case an immediate return to the caller is made with
3040 -- In_Body set True, and the pragma is NOT analyzed.
3041 --
3042 -- In all other cases, an error message for bad placement is given
3043
3044 procedure Check_Static_Constraint (Constr : Node_Id);
3045 -- Constr is a constraint from an N_Subtype_Indication node from a
3046 -- component constraint in an Unchecked_Union type. This routine checks
3047 -- that the constraint is static as required by the restrictions for
3048 -- Unchecked_Union.
3049
3050 procedure Check_Test_Case;
3051 -- Called to process a test-case pragma. It starts with checking pragma
3052 -- arguments, and the rest of the treatment is similar to the one for
3053 -- pre- and postcondition in Check_Precondition_Postcondition, except
3054 -- the placement rules for the test-case pragma are stricter. These
3055 -- pragmas may only occur after a subprogram spec declared directly
3056 -- in a package spec unit. In this case, the pragma is chained to the
3057 -- subprogram in question (using Contract_Test_Cases and Next_Pragma)
3058 -- and analysis of the pragma is delayed till the end of the spec. In
3059 -- all other cases, an error message for bad placement is given.
3060
3061 procedure Check_Valid_Configuration_Pragma;
3062 -- Legality checks for placement of a configuration pragma
3063
3064 procedure Check_Valid_Library_Unit_Pragma;
3065 -- Legality checks for library unit pragmas. A special case arises for
3066 -- pragmas in generic instances that come from copies of the original
3067 -- library unit pragmas in the generic templates. In the case of other
3068 -- than library level instantiations these can appear in contexts which
3069 -- would normally be invalid (they only apply to the original template
3070 -- and to library level instantiations), and they are simply ignored,
3071 -- which is implemented by rewriting them as null statements.
3072
3073 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
3074 -- Check an Unchecked_Union variant for lack of nested variants and
3075 -- presence of at least one component. UU_Typ is the related Unchecked_
3076 -- Union type.
3077
3078 procedure Ensure_Aggregate_Form (Arg : Node_Id);
3079 -- Subsidiary routine to the processing of pragmas Abstract_State,
3080 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3081 -- Refined_Global and Refined_State. Transform argument Arg into an
3082 -- aggregate if not one already. N_Null is never transformed.
3083
3084 procedure Error_Pragma (Msg : String);
3085 pragma No_Return (Error_Pragma);
3086 -- Outputs error message for current pragma. The message contains a %
3087 -- that will be replaced with the pragma name, and the flag is placed
3088 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3089 -- calls Fix_Error (see spec of that procedure for details).
3090
3091 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
3092 pragma No_Return (Error_Pragma_Arg);
3093 -- Outputs error message for current pragma. The message may contain
3094 -- a % that will be replaced with the pragma name. The parameter Arg
3095 -- may either be a pragma argument association, in which case the flag
3096 -- is placed on the expression of this association, or an expression,
3097 -- in which case the flag is placed directly on the expression. The
3098 -- message is placed using Error_Msg_N, so the message may also contain
3099 -- an & insertion character which will reference the given Arg value.
3100 -- After placing the message, Pragma_Exit is raised. Note: this routine
3101 -- calls Fix_Error (see spec of that procedure for details).
3102
3103 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
3104 pragma No_Return (Error_Pragma_Arg);
3105 -- Similar to above form of Error_Pragma_Arg except that two messages
3106 -- are provided, the second is a continuation comment starting with \.
3107
3108 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
3109 pragma No_Return (Error_Pragma_Arg_Ident);
3110 -- Outputs error message for current pragma. The message may contain a %
3111 -- that will be replaced with the pragma name. The parameter Arg must be
3112 -- a pragma argument association with a non-empty identifier (i.e. its
3113 -- Chars field must be set), and the error message is placed on the
3114 -- identifier. The message is placed using Error_Msg_N so the message
3115 -- may also contain an & insertion character which will reference
3116 -- the identifier. After placing the message, Pragma_Exit is raised.
3117 -- Note: this routine calls Fix_Error (see spec of that procedure for
3118 -- details).
3119
3120 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
3121 pragma No_Return (Error_Pragma_Ref);
3122 -- Outputs error message for current pragma. The message may contain
3123 -- a % that will be replaced with the pragma name. The parameter Ref
3124 -- must be an entity whose name can be referenced by & and sloc by #.
3125 -- After placing the message, Pragma_Exit is raised. Note: this routine
3126 -- calls Fix_Error (see spec of that procedure for details).
3127
3128 function Find_Lib_Unit_Name return Entity_Id;
3129 -- Used for a library unit pragma to find the entity to which the
3130 -- library unit pragma applies, returns the entity found.
3131
3132 procedure Find_Program_Unit_Name (Id : Node_Id);
3133 -- If the pragma is a compilation unit pragma, the id must denote the
3134 -- compilation unit in the same compilation, and the pragma must appear
3135 -- in the list of preceding or trailing pragmas. If it is a program
3136 -- unit pragma that is not a compilation unit pragma, then the
3137 -- identifier must be visible.
3138
3139 function Find_Unique_Parameterless_Procedure
3140 (Name : Entity_Id;
3141 Arg : Node_Id) return Entity_Id;
3142 -- Used for a procedure pragma to find the unique parameterless
3143 -- procedure identified by Name, returns it if it exists, otherwise
3144 -- errors out and uses Arg as the pragma argument for the message.
3145
3146 function Fix_Error (Msg : String) return String;
3147 -- This is called prior to issuing an error message. Msg is the normal
3148 -- error message issued in the pragma case. This routine checks for the
3149 -- case of a pragma coming from an aspect in the source, and returns a
3150 -- message suitable for the aspect case as follows:
3151 --
3152 -- Each substring "pragma" is replaced by "aspect"
3153 --
3154 -- If "argument of" is at the start of the error message text, it is
3155 -- replaced by "entity for".
3156 --
3157 -- If "argument" is at the start of the error message text, it is
3158 -- replaced by "entity".
3159 --
3160 -- So for example, "argument of pragma X must be discrete type"
3161 -- returns "entity for aspect X must be a discrete type".
3162
3163 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3164 -- be different from the pragma name). If the current pragma results
3165 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3166 -- original pragma name.
3167
3168 procedure Gather_Associations
3169 (Names : Name_List;
3170 Args : out Args_List);
3171 -- This procedure is used to gather the arguments for a pragma that
3172 -- permits arbitrary ordering of parameters using the normal rules
3173 -- for named and positional parameters. The Names argument is a list
3174 -- of Name_Id values that corresponds to the allowed pragma argument
3175 -- association identifiers in order. The result returned in Args is
3176 -- a list of corresponding expressions that are the pragma arguments.
3177 -- Note that this is a list of expressions, not of pragma argument
3178 -- associations (Gather_Associations has completely checked all the
3179 -- optional identifiers when it returns). An entry in Args is Empty
3180 -- on return if the corresponding argument is not present.
3181
3182 procedure GNAT_Pragma;
3183 -- Called for all GNAT defined pragmas to check the relevant restriction
3184 -- (No_Implementation_Pragmas).
3185
3186 function Is_Before_First_Decl
3187 (Pragma_Node : Node_Id;
3188 Decls : List_Id) return Boolean;
3189 -- Return True if Pragma_Node is before the first declarative item in
3190 -- Decls where Decls is the list of declarative items.
3191
3192 function Is_Configuration_Pragma return Boolean;
3193 -- Determines if the placement of the current pragma is appropriate
3194 -- for a configuration pragma.
3195
3196 function Is_In_Context_Clause return Boolean;
3197 -- Returns True if pragma appears within the context clause of a unit,
3198 -- and False for any other placement (does not generate any messages).
3199
3200 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
3201 -- Analyzes the argument, and determines if it is a static string
3202 -- expression, returns True if so, False if non-static or not String.
3203
3204 procedure Pragma_Misplaced;
3205 pragma No_Return (Pragma_Misplaced);
3206 -- Issue fatal error message for misplaced pragma
3207
3208 procedure Process_Atomic_Shared_Volatile;
3209 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
3210 -- Shared is an obsolete Ada 83 pragma, treated as being identical
3211 -- in effect to pragma Atomic.
3212
3213 procedure Process_Compile_Time_Warning_Or_Error;
3214 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3215
3216 procedure Process_Convention
3217 (C : out Convention_Id;
3218 Ent : out Entity_Id);
3219 -- Common processing for Convention, Interface, Import and Export.
3220 -- Checks first two arguments of pragma, and sets the appropriate
3221 -- convention value in the specified entity or entities. On return
3222 -- C is the convention, Ent is the referenced entity.
3223
3224 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
3225 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3226 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3227
3228 procedure Process_Extended_Import_Export_Exception_Pragma
3229 (Arg_Internal : Node_Id;
3230 Arg_External : Node_Id;
3231 Arg_Form : Node_Id;
3232 Arg_Code : Node_Id);
3233 -- Common processing for the pragmas Import/Export_Exception. The three
3234 -- arguments correspond to the three named parameters of the pragma. An
3235 -- argument is empty if the corresponding parameter is not present in
3236 -- the pragma.
3237
3238 procedure Process_Extended_Import_Export_Object_Pragma
3239 (Arg_Internal : Node_Id;
3240 Arg_External : Node_Id;
3241 Arg_Size : Node_Id);
3242 -- Common processing for the pragmas Import/Export_Object. The three
3243 -- arguments correspond to the three named parameters of the pragmas. An
3244 -- argument is empty if the corresponding parameter is not present in
3245 -- the pragma.
3246
3247 procedure Process_Extended_Import_Export_Internal_Arg
3248 (Arg_Internal : Node_Id := Empty);
3249 -- Common processing for all extended Import and Export pragmas. The
3250 -- argument is the pragma parameter for the Internal argument. If
3251 -- Arg_Internal is empty or inappropriate, an error message is posted.
3252 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3253 -- set to identify the referenced entity.
3254
3255 procedure Process_Extended_Import_Export_Subprogram_Pragma
3256 (Arg_Internal : Node_Id;
3257 Arg_External : Node_Id;
3258 Arg_Parameter_Types : Node_Id;
3259 Arg_Result_Type : Node_Id := Empty;
3260 Arg_Mechanism : Node_Id;
3261 Arg_Result_Mechanism : Node_Id := Empty;
3262 Arg_First_Optional_Parameter : Node_Id := Empty);
3263 -- Common processing for all extended Import and Export pragmas applying
3264 -- to subprograms. The caller omits any arguments that do not apply to
3265 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3266 -- only in the Import_Function and Export_Function cases). The argument
3267 -- names correspond to the allowed pragma association identifiers.
3268
3269 procedure Process_Generic_List;
3270 -- Common processing for Share_Generic and Inline_Generic
3271
3272 procedure Process_Import_Or_Interface;
3273 -- Common processing for Import of Interface
3274
3275 procedure Process_Import_Predefined_Type;
3276 -- Processing for completing a type with pragma Import. This is used
3277 -- to declare types that match predefined C types, especially for cases
3278 -- without corresponding Ada predefined type.
3279
3280 type Inline_Status is (Suppressed, Disabled, Enabled);
3281 -- Inline status of a subprogram, indicated as follows:
3282 -- Suppressed: inlining is suppressed for the subprogram
3283 -- Disabled: no inlining is requested for the subprogram
3284 -- Enabled: inlining is requested/required for the subprogram
3285
3286 procedure Process_Inline (Status : Inline_Status);
3287 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3288 -- indicates the inline status specified by the pragma.
3289
3290 procedure Process_Interface_Name
3291 (Subprogram_Def : Entity_Id;
3292 Ext_Arg : Node_Id;
3293 Link_Arg : Node_Id);
3294 -- Given the last two arguments of pragma Import, pragma Export, or
3295 -- pragma Interface_Name, performs validity checks and sets the
3296 -- Interface_Name field of the given subprogram entity to the
3297 -- appropriate external or link name, depending on the arguments given.
3298 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3299 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3300 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3301 -- nor Link_Arg is present, the interface name is set to the default
3302 -- from the subprogram name.
3303
3304 procedure Process_Interrupt_Or_Attach_Handler;
3305 -- Common processing for Interrupt and Attach_Handler pragmas
3306
3307 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
3308 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3309 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3310 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3311 -- is not set in the Restrictions case.
3312
3313 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
3314 -- Common processing for Suppress and Unsuppress. The boolean parameter
3315 -- Suppress_Case is True for the Suppress case, and False for the
3316 -- Unsuppress case.
3317
3318 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
3319 -- This procedure sets the Is_Exported flag for the given entity,
3320 -- checking that the entity was not previously imported. Arg is
3321 -- the argument that specified the entity. A check is also made
3322 -- for exporting inappropriate entities.
3323
3324 procedure Set_Extended_Import_Export_External_Name
3325 (Internal_Ent : Entity_Id;
3326 Arg_External : Node_Id);
3327 -- Common processing for all extended import export pragmas. The first
3328 -- argument, Internal_Ent, is the internal entity, which has already
3329 -- been checked for validity by the caller. Arg_External is from the
3330 -- Import or Export pragma, and may be null if no External parameter
3331 -- was present. If Arg_External is present and is a non-null string
3332 -- (a null string is treated as the default), then the Interface_Name
3333 -- field of Internal_Ent is set appropriately.
3334
3335 procedure Set_Imported (E : Entity_Id);
3336 -- This procedure sets the Is_Imported flag for the given entity,
3337 -- checking that it is not previously exported or imported.
3338
3339 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
3340 -- Mech is a parameter passing mechanism (see Import_Function syntax
3341 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3342 -- has the right form, and if not issues an error message. If the
3343 -- argument has the right form then the Mechanism field of Ent is
3344 -- set appropriately.
3345
3346 procedure Set_Rational_Profile;
3347 -- Activate the set of configuration pragmas and permissions that make
3348 -- up the Rational profile.
3349
3350 procedure Set_Ravenscar_Profile (N : Node_Id);
3351 -- Activate the set of configuration pragmas and restrictions that make
3352 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3353 -- is used for error messages on any constructs violating the profile.
3354
3355 ----------------------------------
3356 -- Acquire_Warning_Match_String --
3357 ----------------------------------
3358
3359 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3360 begin
3361 String_To_Name_Buffer
3362 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3363
3364 -- Add asterisk at start if not already there
3365
3366 if Name_Len > 0 and then Name_Buffer (1) /= '*' then
3367 Name_Buffer (2 .. Name_Len + 1) :=
3368 Name_Buffer (1 .. Name_Len);
3369 Name_Buffer (1) := '*';
3370 Name_Len := Name_Len + 1;
3371 end if;
3372
3373 -- Add asterisk at end if not already there
3374
3375 if Name_Buffer (Name_Len) /= '*' then
3376 Name_Len := Name_Len + 1;
3377 Name_Buffer (Name_Len) := '*';
3378 end if;
3379 end Acquire_Warning_Match_String;
3380
3381 ---------------------
3382 -- Ada_2005_Pragma --
3383 ---------------------
3384
3385 procedure Ada_2005_Pragma is
3386 begin
3387 if Ada_Version <= Ada_95 then
3388 Check_Restriction (No_Implementation_Pragmas, N);
3389 end if;
3390 end Ada_2005_Pragma;
3391
3392 ---------------------
3393 -- Ada_2012_Pragma --
3394 ---------------------
3395
3396 procedure Ada_2012_Pragma is
3397 begin
3398 if Ada_Version <= Ada_2005 then
3399 Check_Restriction (No_Implementation_Pragmas, N);
3400 end if;
3401 end Ada_2012_Pragma;
3402
3403 ---------------------
3404 -- Analyze_Part_Of --
3405 ---------------------
3406
3407 procedure Analyze_Part_Of
3408 (Item_Id : Entity_Id;
3409 State : Node_Id;
3410 Indic : Node_Id;
3411 Legal : out Boolean)
3412 is
3413 Pack_Id : Entity_Id;
3414 Placement : State_Space_Kind;
3415 Parent_Unit : Entity_Id;
3416 State_Id : Entity_Id;
3417
3418 begin
3419 -- Assume that the pragma/option is illegal
3420
3421 Legal := False;
3422
3423 if Nkind_In (State, N_Expanded_Name,
3424 N_Identifier,
3425 N_Selected_Component)
3426 then
3427 Analyze (State);
3428 Resolve_State (State);
3429
3430 if Is_Entity_Name (State)
3431 and then Ekind (Entity (State)) = E_Abstract_State
3432 then
3433 State_Id := Entity (State);
3434
3435 else
3436 SPARK_Msg_N
3437 ("indicator Part_Of must denote an abstract state", State);
3438 return;
3439 end if;
3440
3441 -- This is a syntax error, always report
3442
3443 else
3444 Error_Msg_N
3445 ("indicator Part_Of must denote an abstract state", State);
3446 return;
3447 end if;
3448
3449 -- Determine where the state, variable or the package instantiation
3450 -- lives with respect to the enclosing packages or package bodies (if
3451 -- any). This placement dictates the legality of the encapsulating
3452 -- state.
3453
3454 Find_Placement_In_State_Space
3455 (Item_Id => Item_Id,
3456 Placement => Placement,
3457 Pack_Id => Pack_Id);
3458
3459 -- The item appears in a non-package construct with a declarative
3460 -- part (subprogram, block, etc). As such, the item is not allowed
3461 -- to be a part of an encapsulating state because the item is not
3462 -- visible.
3463
3464 if Placement = Not_In_Package then
3465 SPARK_Msg_N
3466 ("indicator Part_Of cannot appear in this context "
3467 & "(SPARK RM 7.2.6(5))", Indic);
3468 Error_Msg_Name_1 := Chars (Scope (State_Id));
3469 SPARK_Msg_NE
3470 ("\& is not part of the hidden state of package %",
3471 Indic, Item_Id);
3472
3473 -- The item appears in the visible state space of some package. In
3474 -- general this scenario does not warrant Part_Of except when the
3475 -- package is a private child unit and the encapsulating state is
3476 -- declared in a parent unit or a public descendant of that parent
3477 -- unit.
3478
3479 elsif Placement = Visible_State_Space then
3480 if Is_Child_Unit (Pack_Id)
3481 and then Is_Private_Descendant (Pack_Id)
3482 then
3483 -- A variable or state abstraction which is part of the
3484 -- visible state of a private child unit (or a public
3485 -- descendant thereof) shall have its Part_Of indicator
3486 -- specified; the Part_Of indicator shall denote a state
3487 -- abstraction declared by either the parent unit of the
3488 -- private unit or by a public descendant of that parent unit.
3489
3490 -- Find nearest nearest private ancestor (which can be the
3491 -- current unit itself).
3492
3493 Parent_Unit := Pack_Id;
3494 while Present (Parent_Unit) loop
3495 exit when Private_Present
3496 (Parent (Unit_Declaration_Node (Parent_Unit)));
3497 Parent_Unit := Scope (Parent_Unit);
3498 end loop;
3499
3500 Parent_Unit := Scope (Parent_Unit);
3501
3502 if not Is_Child_Or_Sibling (Pack_Id, Scope (State_Id)) then
3503 SPARK_Msg_NE
3504 ("indicator Part_Of must denote an abstract state of& "
3505 & "or public descendant (SPARK RM 7.2.6(3))",
3506 Indic, Parent_Unit);
3507
3508 elsif Scope (State_Id) = Parent_Unit
3509 or else (Is_Ancestor_Package (Parent_Unit, Scope (State_Id))
3510 and then
3511 not Is_Private_Descendant (Scope (State_Id)))
3512 then
3513 null;
3514
3515 else
3516 SPARK_Msg_NE
3517 ("indicator Part_Of must denote an abstract state of& "
3518 & "or public descendant (SPARK RM 7.2.6(3))",
3519 Indic, Parent_Unit);
3520 end if;
3521
3522 -- Indicator Part_Of is not needed when the related package is not
3523 -- a private child unit or a public descendant thereof.
3524
3525 else
3526 SPARK_Msg_N
3527 ("indicator Part_Of cannot appear in this context "
3528 & "(SPARK RM 7.2.6(5))", Indic);
3529 Error_Msg_Name_1 := Chars (Pack_Id);
3530 SPARK_Msg_NE
3531 ("\& is declared in the visible part of package %",
3532 Indic, Item_Id);
3533 end if;
3534
3535 -- When the item appears in the private state space of a package, the
3536 -- encapsulating state must be declared in the same package.
3537
3538 elsif Placement = Private_State_Space then
3539 if Scope (State_Id) /= Pack_Id then
3540 SPARK_Msg_NE
3541 ("indicator Part_Of must designate an abstract state of "
3542 & "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id);
3543 Error_Msg_Name_1 := Chars (Pack_Id);
3544 SPARK_Msg_NE
3545 ("\& is declared in the private part of package %",
3546 Indic, Item_Id);
3547 end if;
3548
3549 -- Items declared in the body state space of a package do not need
3550 -- Part_Of indicators as the refinement has already been seen.
3551
3552 else
3553 SPARK_Msg_N
3554 ("indicator Part_Of cannot appear in this context "
3555 & "(SPARK RM 7.2.6(5))", Indic);
3556
3557 if Scope (State_Id) = Pack_Id then
3558 Error_Msg_Name_1 := Chars (Pack_Id);
3559 SPARK_Msg_NE
3560 ("\& is declared in the body of package %", Indic, Item_Id);
3561 end if;
3562 end if;
3563
3564 Legal := True;
3565 end Analyze_Part_Of;
3566
3567 ----------------------------
3568 -- Analyze_Refined_Pragma --
3569 ----------------------------
3570
3571 procedure Analyze_Refined_Pragma
3572 (Spec_Id : out Entity_Id;
3573 Body_Id : out Entity_Id;
3574 Legal : out Boolean)
3575 is
3576 Body_Decl : Node_Id;
3577 Spec_Decl : Node_Id;
3578
3579 begin
3580 -- Assume that the pragma is illegal
3581
3582 Spec_Id := Empty;
3583 Body_Id := Empty;
3584 Legal := False;
3585
3586 GNAT_Pragma;
3587 Check_Arg_Count (1);
3588 Check_No_Identifiers;
3589
3590 if Nam_In (Pname, Name_Refined_Depends,
3591 Name_Refined_Global,
3592 Name_Refined_State)
3593 then
3594 Ensure_Aggregate_Form (Arg1);
3595 end if;
3596
3597 -- Verify the placement of the pragma and check for duplicates. The
3598 -- pragma must apply to a subprogram body [stub].
3599
3600 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3601
3602 -- Extract the entities of the spec and body
3603
3604 if Nkind (Body_Decl) = N_Subprogram_Body then
3605 Body_Id := Defining_Entity (Body_Decl);
3606 Spec_Id := Corresponding_Spec (Body_Decl);
3607
3608 elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
3609 Body_Id := Defining_Entity (Body_Decl);
3610 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
3611
3612 else
3613 Pragma_Misplaced;
3614 return;
3615 end if;
3616
3617 -- The pragma must apply to the second declaration of a subprogram.
3618 -- In other words, the body [stub] cannot acts as a spec.
3619
3620 if No (Spec_Id) then
3621 Error_Pragma ("pragma % cannot apply to a stand alone body");
3622 return;
3623
3624 -- Catch the case where the subprogram body is a subunit and acts as
3625 -- the third declaration of the subprogram.
3626
3627 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
3628 Error_Pragma ("pragma % cannot apply to a subunit");
3629 return;
3630 end if;
3631
3632 -- The pragma can only apply to the body [stub] of a subprogram
3633 -- declared in the visible part of a package. Retrieve the context of
3634 -- the subprogram declaration.
3635
3636 Spec_Decl := Parent (Parent (Spec_Id));
3637
3638 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
3639 Error_Pragma
3640 ("pragma % must apply to the body of a subprogram declared in a "
3641 & "package specification");
3642 return;
3643 end if;
3644
3645 -- If we get here, then the pragma is legal
3646
3647 Legal := True;
3648 end Analyze_Refined_Pragma;
3649
3650 --------------------------
3651 -- Check_Ada_83_Warning --
3652 --------------------------
3653
3654 procedure Check_Ada_83_Warning is
3655 begin
3656 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3657 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3658 end if;
3659 end Check_Ada_83_Warning;
3660
3661 ---------------------
3662 -- Check_Arg_Count --
3663 ---------------------
3664
3665 procedure Check_Arg_Count (Required : Nat) is
3666 begin
3667 if Arg_Count /= Required then
3668 Error_Pragma ("wrong number of arguments for pragma%");
3669 end if;
3670 end Check_Arg_Count;
3671
3672 --------------------------------
3673 -- Check_Arg_Is_External_Name --
3674 --------------------------------
3675
3676 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3677 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3678
3679 begin
3680 if Nkind (Argx) = N_Identifier then
3681 return;
3682
3683 else
3684 Analyze_And_Resolve (Argx, Standard_String);
3685
3686 if Is_OK_Static_Expression (Argx) then
3687 return;
3688
3689 elsif Etype (Argx) = Any_Type then
3690 raise Pragma_Exit;
3691
3692 -- An interesting special case, if we have a string literal and
3693 -- we are in Ada 83 mode, then we allow it even though it will
3694 -- not be flagged as static. This allows expected Ada 83 mode
3695 -- use of external names which are string literals, even though
3696 -- technically these are not static in Ada 83.
3697
3698 elsif Ada_Version = Ada_83
3699 and then Nkind (Argx) = N_String_Literal
3700 then
3701 return;
3702
3703 -- Static expression that raises Constraint_Error. This has
3704 -- already been flagged, so just exit from pragma processing.
3705
3706 elsif Is_OK_Static_Expression (Argx) then
3707 raise Pragma_Exit;
3708
3709 -- Here we have a real error (non-static expression)
3710
3711 else
3712 Error_Msg_Name_1 := Pname;
3713
3714 declare
3715 Msg : constant String :=
3716 "argument for pragma% must be a identifier or "
3717 & "static string expression!";
3718 begin
3719 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
3720 raise Pragma_Exit;
3721 end;
3722 end if;
3723 end if;
3724 end Check_Arg_Is_External_Name;
3725
3726 -----------------------------
3727 -- Check_Arg_Is_Identifier --
3728 -----------------------------
3729
3730 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3731 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3732 begin
3733 if Nkind (Argx) /= N_Identifier then
3734 Error_Pragma_Arg
3735 ("argument for pragma% must be identifier", Argx);
3736 end if;
3737 end Check_Arg_Is_Identifier;
3738
3739 ----------------------------------
3740 -- Check_Arg_Is_Integer_Literal --
3741 ----------------------------------
3742
3743 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3744 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3745 begin
3746 if Nkind (Argx) /= N_Integer_Literal then
3747 Error_Pragma_Arg
3748 ("argument for pragma% must be integer literal", Argx);
3749 end if;
3750 end Check_Arg_Is_Integer_Literal;
3751
3752 -------------------------------------------
3753 -- Check_Arg_Is_Library_Level_Local_Name --
3754 -------------------------------------------
3755
3756 -- LOCAL_NAME ::=
3757 -- DIRECT_NAME
3758 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3759 -- | library_unit_NAME
3760
3761 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3762 begin
3763 Check_Arg_Is_Local_Name (Arg);
3764
3765 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3766 and then Comes_From_Source (N)
3767 then
3768 Error_Pragma_Arg
3769 ("argument for pragma% must be library level entity", Arg);
3770 end if;
3771 end Check_Arg_Is_Library_Level_Local_Name;
3772
3773 -----------------------------
3774 -- Check_Arg_Is_Local_Name --
3775 -----------------------------
3776
3777 -- LOCAL_NAME ::=
3778 -- DIRECT_NAME
3779 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3780 -- | library_unit_NAME
3781
3782 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3783 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3784
3785 begin
3786 Analyze (Argx);
3787
3788 if Nkind (Argx) not in N_Direct_Name
3789 and then (Nkind (Argx) /= N_Attribute_Reference
3790 or else Present (Expressions (Argx))
3791 or else Nkind (Prefix (Argx)) /= N_Identifier)
3792 and then (not Is_Entity_Name (Argx)
3793 or else not Is_Compilation_Unit (Entity (Argx)))
3794 then
3795 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3796 end if;
3797
3798 -- No further check required if not an entity name
3799
3800 if not Is_Entity_Name (Argx) then
3801 null;
3802
3803 else
3804 declare
3805 OK : Boolean;
3806 Ent : constant Entity_Id := Entity (Argx);
3807 Scop : constant Entity_Id := Scope (Ent);
3808
3809 begin
3810 -- Case of a pragma applied to a compilation unit: pragma must
3811 -- occur immediately after the program unit in the compilation.
3812
3813 if Is_Compilation_Unit (Ent) then
3814 declare
3815 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3816
3817 begin
3818 -- Case of pragma placed immediately after spec
3819
3820 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3821 OK := True;
3822
3823 -- Case of pragma placed immediately after body
3824
3825 elsif Nkind (Decl) = N_Subprogram_Declaration
3826 and then Present (Corresponding_Body (Decl))
3827 then
3828 OK := Parent (N) =
3829 Aux_Decls_Node
3830 (Parent (Unit_Declaration_Node
3831 (Corresponding_Body (Decl))));
3832
3833 -- All other cases are illegal
3834
3835 else
3836 OK := False;
3837 end if;
3838 end;
3839
3840 -- Special restricted placement rule from 10.2.1(11.8/2)
3841
3842 elsif Is_Generic_Formal (Ent)
3843 and then Prag_Id = Pragma_Preelaborable_Initialization
3844 then
3845 OK := List_Containing (N) =
3846 Generic_Formal_Declarations
3847 (Unit_Declaration_Node (Scop));
3848
3849 -- If this is an aspect applied to a subprogram body, the
3850 -- pragma is inserted in its declarative part.
3851
3852 elsif From_Aspect_Specification (N)
3853 and then
3854 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
3855 and then Ent = Current_Scope
3856 then
3857 OK := True;
3858
3859 -- If the aspect is a predicate (possibly others ???) and the
3860 -- context is a record type, this is a discriminant expression
3861 -- within a type declaration, that freezes the predicated
3862 -- subtype.
3863
3864 elsif From_Aspect_Specification (N)
3865 and then Prag_Id = Pragma_Predicate
3866 and then Ekind (Current_Scope) = E_Record_Type
3867 and then Scop = Scope (Current_Scope)
3868 then
3869 OK := True;
3870
3871 -- Default case, just check that the pragma occurs in the scope
3872 -- of the entity denoted by the name.
3873
3874 else
3875 OK := Current_Scope = Scop;
3876 end if;
3877
3878 if not OK then
3879 Error_Pragma_Arg
3880 ("pragma% argument must be in same declarative part", Arg);
3881 end if;
3882 end;
3883 end if;
3884 end Check_Arg_Is_Local_Name;
3885
3886 ---------------------------------
3887 -- Check_Arg_Is_Locking_Policy --
3888 ---------------------------------
3889
3890 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3892
3893 begin
3894 Check_Arg_Is_Identifier (Argx);
3895
3896 if not Is_Locking_Policy_Name (Chars (Argx)) then
3897 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3898 end if;
3899 end Check_Arg_Is_Locking_Policy;
3900
3901 -----------------------------------------------
3902 -- Check_Arg_Is_Partition_Elaboration_Policy --
3903 -----------------------------------------------
3904
3905 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3906 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3907
3908 begin
3909 Check_Arg_Is_Identifier (Argx);
3910
3911 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3912 Error_Pragma_Arg
3913 ("& is not a valid partition elaboration policy name", Argx);
3914 end if;
3915 end Check_Arg_Is_Partition_Elaboration_Policy;
3916
3917 -------------------------
3918 -- Check_Arg_Is_One_Of --
3919 -------------------------
3920
3921 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3922 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3923
3924 begin
3925 Check_Arg_Is_Identifier (Argx);
3926
3927 if not Nam_In (Chars (Argx), N1, N2) then
3928 Error_Msg_Name_2 := N1;
3929 Error_Msg_Name_3 := N2;
3930 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
3931 end if;
3932 end Check_Arg_Is_One_Of;
3933
3934 procedure Check_Arg_Is_One_Of
3935 (Arg : Node_Id;
3936 N1, N2, N3 : Name_Id)
3937 is
3938 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3939
3940 begin
3941 Check_Arg_Is_Identifier (Argx);
3942
3943 if not Nam_In (Chars (Argx), N1, N2, N3) then
3944 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3945 end if;
3946 end Check_Arg_Is_One_Of;
3947
3948 procedure Check_Arg_Is_One_Of
3949 (Arg : Node_Id;
3950 N1, N2, N3, N4 : Name_Id)
3951 is
3952 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3953
3954 begin
3955 Check_Arg_Is_Identifier (Argx);
3956
3957 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3958 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3959 end if;
3960 end Check_Arg_Is_One_Of;
3961
3962 procedure Check_Arg_Is_One_Of
3963 (Arg : Node_Id;
3964 N1, N2, N3, N4, N5 : Name_Id)
3965 is
3966 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3967
3968 begin
3969 Check_Arg_Is_Identifier (Argx);
3970
3971 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
3972 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3973 end if;
3974 end Check_Arg_Is_One_Of;
3975
3976 ---------------------------------
3977 -- Check_Arg_Is_Queuing_Policy --
3978 ---------------------------------
3979
3980 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
3981 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3982
3983 begin
3984 Check_Arg_Is_Identifier (Argx);
3985
3986 if not Is_Queuing_Policy_Name (Chars (Argx)) then
3987 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
3988 end if;
3989 end Check_Arg_Is_Queuing_Policy;
3990
3991 ---------------------------------------
3992 -- Check_Arg_Is_OK_Static_Expression --
3993 ---------------------------------------
3994
3995 procedure Check_Arg_Is_OK_Static_Expression
3996 (Arg : Node_Id;
3997 Typ : Entity_Id := Empty)
3998 is
3999 begin
4000 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
4001 end Check_Arg_Is_OK_Static_Expression;
4002
4003 ------------------------------------------
4004 -- Check_Arg_Is_Task_Dispatching_Policy --
4005 ------------------------------------------
4006
4007 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4008 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4009
4010 begin
4011 Check_Arg_Is_Identifier (Argx);
4012
4013 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4014 Error_Pragma_Arg
4015 ("& is not an allowed task dispatching policy name", Argx);
4016 end if;
4017 end Check_Arg_Is_Task_Dispatching_Policy;
4018
4019 ---------------------
4020 -- Check_Arg_Order --
4021 ---------------------
4022
4023 procedure Check_Arg_Order (Names : Name_List) is
4024 Arg : Node_Id;
4025
4026 Highest_So_Far : Natural := 0;
4027 -- Highest index in Names seen do far
4028
4029 begin
4030 Arg := Arg1;
4031 for J in 1 .. Arg_Count loop
4032 if Chars (Arg) /= No_Name then
4033 for K in Names'Range loop
4034 if Chars (Arg) = Names (K) then
4035 if K < Highest_So_Far then
4036 Error_Msg_Name_1 := Pname;
4037 Error_Msg_N
4038 ("parameters out of order for pragma%", Arg);
4039 Error_Msg_Name_1 := Names (K);
4040 Error_Msg_Name_2 := Names (Highest_So_Far);
4041 Error_Msg_N ("\% must appear before %", Arg);
4042 raise Pragma_Exit;
4043
4044 else
4045 Highest_So_Far := K;
4046 end if;
4047 end if;
4048 end loop;
4049 end if;
4050
4051 Arg := Next (Arg);
4052 end loop;
4053 end Check_Arg_Order;
4054
4055 --------------------------------
4056 -- Check_At_Least_N_Arguments --
4057 --------------------------------
4058
4059 procedure Check_At_Least_N_Arguments (N : Nat) is
4060 begin
4061 if Arg_Count < N then
4062 Error_Pragma ("too few arguments for pragma%");
4063 end if;
4064 end Check_At_Least_N_Arguments;
4065
4066 -------------------------------
4067 -- Check_At_Most_N_Arguments --
4068 -------------------------------
4069
4070 procedure Check_At_Most_N_Arguments (N : Nat) is
4071 Arg : Node_Id;
4072 begin
4073 if Arg_Count > N then
4074 Arg := Arg1;
4075 for J in 1 .. N loop
4076 Next (Arg);
4077 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4078 end loop;
4079 end if;
4080 end Check_At_Most_N_Arguments;
4081
4082 ---------------------
4083 -- Check_Component --
4084 ---------------------
4085
4086 procedure Check_Component
4087 (Comp : Node_Id;
4088 UU_Typ : Entity_Id;
4089 In_Variant_Part : Boolean := False)
4090 is
4091 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
4092 Sindic : constant Node_Id :=
4093 Subtype_Indication (Component_Definition (Comp));
4094 Typ : constant Entity_Id := Etype (Comp_Id);
4095
4096 begin
4097 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4098 -- object constraint, then the component type shall be an Unchecked_
4099 -- Union.
4100
4101 if Nkind (Sindic) = N_Subtype_Indication
4102 and then Has_Per_Object_Constraint (Comp_Id)
4103 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
4104 then
4105 Error_Msg_N
4106 ("component subtype subject to per-object constraint "
4107 & "must be an Unchecked_Union", Comp);
4108
4109 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4110 -- the body of a generic unit, or within the body of any of its
4111 -- descendant library units, no part of the type of a component
4112 -- declared in a variant_part of the unchecked union type shall be of
4113 -- a formal private type or formal private extension declared within
4114 -- the formal part of the generic unit.
4115
4116 elsif Ada_Version >= Ada_2012
4117 and then In_Generic_Body (UU_Typ)
4118 and then In_Variant_Part
4119 and then Is_Private_Type (Typ)
4120 and then Is_Generic_Type (Typ)
4121 then
4122 Error_Msg_N
4123 ("component of unchecked union cannot be of generic type", Comp);
4124
4125 elsif Needs_Finalization (Typ) then
4126 Error_Msg_N
4127 ("component of unchecked union cannot be controlled", Comp);
4128
4129 elsif Has_Task (Typ) then
4130 Error_Msg_N
4131 ("component of unchecked union cannot have tasks", Comp);
4132 end if;
4133 end Check_Component;
4134
4135 -----------------------------
4136 -- Check_Declaration_Order --
4137 -----------------------------
4138
4139 procedure Check_Declaration_Order (First : Node_Id; Second : Node_Id) is
4140 procedure Check_Aspect_Specification_Order;
4141 -- Inspect the aspect specifications of the context to determine the
4142 -- proper order.
4143
4144 --------------------------------------
4145 -- Check_Aspect_Specification_Order --
4146 --------------------------------------
4147
4148 procedure Check_Aspect_Specification_Order is
4149 Asp_First : constant Node_Id := Corresponding_Aspect (First);
4150 Asp_Second : constant Node_Id := Corresponding_Aspect (Second);
4151 Asp : Node_Id;
4152
4153 begin
4154 -- Both aspects must be part of the same aspect specification list
4155
4156 pragma Assert
4157 (List_Containing (Asp_First) = List_Containing (Asp_Second));
4158
4159 -- Try to reach Second starting from First in a left to right
4160 -- traversal of the aspect specifications.
4161
4162 Asp := Next (Asp_First);
4163 while Present (Asp) loop
4164
4165 -- The order is ok, First is followed by Second
4166
4167 if Asp = Asp_Second then
4168 return;
4169 end if;
4170
4171 Next (Asp);
4172 end loop;
4173
4174 -- If we get here, then the aspects are out of order
4175
4176 SPARK_Msg_N ("aspect % cannot come after aspect %", First);
4177 end Check_Aspect_Specification_Order;
4178
4179 -- Local variables
4180
4181 Stmt : Node_Id;
4182
4183 -- Start of processing for Check_Declaration_Order
4184
4185 begin
4186 -- Cannot check the order if one of the pragmas is missing
4187
4188 if No (First) or else No (Second) then
4189 return;
4190 end if;
4191
4192 -- Set up the error names in case the order is incorrect
4193
4194 Error_Msg_Name_1 := Pragma_Name (First);
4195 Error_Msg_Name_2 := Pragma_Name (Second);
4196
4197 if From_Aspect_Specification (First) then
4198
4199 -- Both pragmas are actually aspects, check their declaration
4200 -- order in the associated aspect specification list. Otherwise
4201 -- First is an aspect and Second a source pragma.
4202
4203 if From_Aspect_Specification (Second) then
4204 Check_Aspect_Specification_Order;
4205 end if;
4206
4207 -- Abstract_States is a source pragma
4208
4209 else
4210 if From_Aspect_Specification (Second) then
4211 SPARK_Msg_N ("pragma % cannot come after aspect %", First);
4212
4213 -- Both pragmas are source constructs. Try to reach First from
4214 -- Second by traversing the declarations backwards.
4215
4216 else
4217 Stmt := Prev (Second);
4218 while Present (Stmt) loop
4219
4220 -- The order is ok, First is followed by Second
4221
4222 if Stmt = First then
4223 return;
4224 end if;
4225
4226 Prev (Stmt);
4227 end loop;
4228
4229 -- If we get here, then the pragmas are out of order
4230
4231 SPARK_Msg_N ("pragma % cannot come after pragma %", First);
4232 end if;
4233 end if;
4234 end Check_Declaration_Order;
4235
4236 ----------------------------
4237 -- Check_Duplicate_Pragma --
4238 ----------------------------
4239
4240 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4241 Id : Entity_Id := E;
4242 P : Node_Id;
4243
4244 begin
4245 -- Nothing to do if this pragma comes from an aspect specification,
4246 -- since we could not be duplicating a pragma, and we dealt with the
4247 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4248
4249 if From_Aspect_Specification (N) then
4250 return;
4251 end if;
4252
4253 -- Otherwise current pragma may duplicate previous pragma or a
4254 -- previously given aspect specification or attribute definition
4255 -- clause for the same pragma.
4256
4257 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
4258
4259 if Present (P) then
4260
4261 -- If the entity is a type, then we have to make sure that the
4262 -- ostensible duplicate is not for a parent type from which this
4263 -- type is derived.
4264
4265 if Is_Type (E) then
4266 if Nkind (P) = N_Pragma then
4267 declare
4268 Args : constant List_Id :=
4269 Pragma_Argument_Associations (P);
4270 begin
4271 if Present (Args)
4272 and then Is_Entity_Name (Expression (First (Args)))
4273 and then Is_Type (Entity (Expression (First (Args))))
4274 and then Entity (Expression (First (Args))) /= E
4275 then
4276 return;
4277 end if;
4278 end;
4279
4280 elsif Nkind (P) = N_Aspect_Specification
4281 and then Is_Type (Entity (P))
4282 and then Entity (P) /= E
4283 then
4284 return;
4285 end if;
4286 end if;
4287
4288 -- Here we have a definite duplicate
4289
4290 Error_Msg_Name_1 := Pragma_Name (N);
4291 Error_Msg_Sloc := Sloc (P);
4292
4293 -- For a single protected or a single task object, the error is
4294 -- issued on the original entity.
4295
4296 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4297 Id := Defining_Identifier (Original_Node (Parent (Id)));
4298 end if;
4299
4300 if Nkind (P) = N_Aspect_Specification
4301 or else From_Aspect_Specification (P)
4302 then
4303 Error_Msg_NE ("aspect% for & previously given#", N, Id);
4304 else
4305 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
4306 end if;
4307
4308 raise Pragma_Exit;
4309 end if;
4310 end Check_Duplicate_Pragma;
4311
4312 ----------------------------------
4313 -- Check_Duplicated_Export_Name --
4314 ----------------------------------
4315
4316 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
4317 String_Val : constant String_Id := Strval (Nam);
4318
4319 begin
4320 -- We are only interested in the export case, and in the case of
4321 -- generics, it is the instance, not the template, that is the
4322 -- problem (the template will generate a warning in any case).
4323
4324 if not Inside_A_Generic
4325 and then (Prag_Id = Pragma_Export
4326 or else
4327 Prag_Id = Pragma_Export_Procedure
4328 or else
4329 Prag_Id = Pragma_Export_Valued_Procedure
4330 or else
4331 Prag_Id = Pragma_Export_Function)
4332 then
4333 for J in Externals.First .. Externals.Last loop
4334 if String_Equal (String_Val, Strval (Externals.Table (J))) then
4335 Error_Msg_Sloc := Sloc (Externals.Table (J));
4336 Error_Msg_N ("external name duplicates name given#", Nam);
4337 exit;
4338 end if;
4339 end loop;
4340
4341 Externals.Append (Nam);
4342 end if;
4343 end Check_Duplicated_Export_Name;
4344
4345 ----------------------------------------
4346 -- Check_Expr_Is_OK_Static_Expression --
4347 ----------------------------------------
4348
4349 procedure Check_Expr_Is_OK_Static_Expression
4350 (Expr : Node_Id;
4351 Typ : Entity_Id := Empty)
4352 is
4353 begin
4354 if Present (Typ) then
4355 Analyze_And_Resolve (Expr, Typ);
4356 else
4357 Analyze_And_Resolve (Expr);
4358 end if;
4359
4360 if Is_OK_Static_Expression (Expr) then
4361 return;
4362
4363 elsif Etype (Expr) = Any_Type then
4364 raise Pragma_Exit;
4365
4366 -- An interesting special case, if we have a string literal and we
4367 -- are in Ada 83 mode, then we allow it even though it will not be
4368 -- flagged as static. This allows the use of Ada 95 pragmas like
4369 -- Import in Ada 83 mode. They will of course be flagged with
4370 -- warnings as usual, but will not cause errors.
4371
4372 elsif Ada_Version = Ada_83
4373 and then Nkind (Expr) = N_String_Literal
4374 then
4375 return;
4376
4377 -- Static expression that raises Constraint_Error. This has already
4378 -- been flagged, so just exit from pragma processing.
4379
4380 elsif Is_OK_Static_Expression (Expr) then
4381 raise Pragma_Exit;
4382
4383 -- Finally, we have a real error
4384
4385 else
4386 Error_Msg_Name_1 := Pname;
4387 Flag_Non_Static_Expr
4388 (Fix_Error ("argument for pragma% must be a static expression!"),
4389 Expr);
4390 raise Pragma_Exit;
4391 end if;
4392 end Check_Expr_Is_OK_Static_Expression;
4393
4394 -------------------------
4395 -- Check_First_Subtype --
4396 -------------------------
4397
4398 procedure Check_First_Subtype (Arg : Node_Id) is
4399 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4400 Ent : constant Entity_Id := Entity (Argx);
4401
4402 begin
4403 if Is_First_Subtype (Ent) then
4404 null;
4405
4406 elsif Is_Type (Ent) then
4407 Error_Pragma_Arg
4408 ("pragma% cannot apply to subtype", Argx);
4409
4410 elsif Is_Object (Ent) then
4411 Error_Pragma_Arg
4412 ("pragma% cannot apply to object, requires a type", Argx);
4413
4414 else
4415 Error_Pragma_Arg
4416 ("pragma% cannot apply to&, requires a type", Argx);
4417 end if;
4418 end Check_First_Subtype;
4419
4420 ----------------------
4421 -- Check_Identifier --
4422 ----------------------
4423
4424 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
4425 begin
4426 if Present (Arg)
4427 and then Nkind (Arg) = N_Pragma_Argument_Association
4428 then
4429 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
4430 Error_Msg_Name_1 := Pname;
4431 Error_Msg_Name_2 := Id;
4432 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4433 raise Pragma_Exit;
4434 end if;
4435 end if;
4436 end Check_Identifier;
4437
4438 --------------------------------
4439 -- Check_Identifier_Is_One_Of --
4440 --------------------------------
4441
4442 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4443 begin
4444 if Present (Arg)
4445 and then Nkind (Arg) = N_Pragma_Argument_Association
4446 then
4447 if Chars (Arg) = No_Name then
4448 Error_Msg_Name_1 := Pname;
4449 Error_Msg_N ("pragma% argument expects an identifier", Arg);
4450 raise Pragma_Exit;
4451
4452 elsif Chars (Arg) /= N1
4453 and then Chars (Arg) /= N2
4454 then
4455 Error_Msg_Name_1 := Pname;
4456 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
4457 raise Pragma_Exit;
4458 end if;
4459 end if;
4460 end Check_Identifier_Is_One_Of;
4461
4462 ---------------------------
4463 -- Check_In_Main_Program --
4464 ---------------------------
4465
4466 procedure Check_In_Main_Program is
4467 P : constant Node_Id := Parent (N);
4468
4469 begin
4470 -- Must be at in subprogram body
4471
4472 if Nkind (P) /= N_Subprogram_Body then
4473 Error_Pragma ("% pragma allowed only in subprogram");
4474
4475 -- Otherwise warn if obviously not main program
4476
4477 elsif Present (Parameter_Specifications (Specification (P)))
4478 or else not Is_Compilation_Unit (Defining_Entity (P))
4479 then
4480 Error_Msg_Name_1 := Pname;
4481 Error_Msg_N
4482 ("??pragma% is only effective in main program", N);
4483 end if;
4484 end Check_In_Main_Program;
4485
4486 ---------------------------------------
4487 -- Check_Interrupt_Or_Attach_Handler --
4488 ---------------------------------------
4489
4490 procedure Check_Interrupt_Or_Attach_Handler is
4491 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4492 Handler_Proc, Proc_Scope : Entity_Id;
4493
4494 begin
4495 Analyze (Arg1_X);
4496
4497 if Prag_Id = Pragma_Interrupt_Handler then
4498 Check_Restriction (No_Dynamic_Attachment, N);
4499 end if;
4500
4501 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4502 Proc_Scope := Scope (Handler_Proc);
4503
4504 -- On AAMP only, a pragma Interrupt_Handler is supported for
4505 -- nonprotected parameterless procedures.
4506
4507 if not AAMP_On_Target
4508 or else Prag_Id = Pragma_Attach_Handler
4509 then
4510 if Ekind (Proc_Scope) /= E_Protected_Type then
4511 Error_Pragma_Arg
4512 ("argument of pragma% must be protected procedure", Arg1);
4513 end if;
4514
4515 -- For pragma case (as opposed to access case), check placement.
4516 -- We don't need to do that for aspects, because we have the
4517 -- check that they aspect applies an appropriate procedure.
4518
4519 if not From_Aspect_Specification (N)
4520 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
4521 then
4522 Error_Pragma ("pragma% must be in protected definition");
4523 end if;
4524 end if;
4525
4526 if not Is_Library_Level_Entity (Proc_Scope)
4527 or else (AAMP_On_Target
4528 and then not Is_Library_Level_Entity (Handler_Proc))
4529 then
4530 Error_Pragma_Arg
4531 ("argument for pragma% must be library level entity", Arg1);
4532 end if;
4533
4534 -- AI05-0033: A pragma cannot appear within a generic body, because
4535 -- instance can be in a nested scope. The check that protected type
4536 -- is itself a library-level declaration is done elsewhere.
4537
4538 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4539 -- handle code prior to AI-0033. Analysis tools typically are not
4540 -- interested in this pragma in any case, so no need to worry too
4541 -- much about its placement.
4542
4543 if Inside_A_Generic then
4544 if Ekind (Scope (Current_Scope)) = E_Generic_Package
4545 and then In_Package_Body (Scope (Current_Scope))
4546 and then not Relaxed_RM_Semantics
4547 then
4548 Error_Pragma ("pragma% cannot be used inside a generic");
4549 end if;
4550 end if;
4551 end Check_Interrupt_Or_Attach_Handler;
4552
4553 ---------------------------------
4554 -- Check_Loop_Pragma_Placement --
4555 ---------------------------------
4556
4557 procedure Check_Loop_Pragma_Placement is
4558 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id);
4559 -- Verify whether the current pragma is properly grouped with other
4560 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
4561 -- related loop where the pragma appears.
4562
4563 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean;
4564 -- Determine whether an arbitrary statement Stmt denotes pragma
4565 -- Loop_Invariant or Loop_Variant.
4566
4567 procedure Placement_Error (Constr : Node_Id);
4568 pragma No_Return (Placement_Error);
4569 -- Node Constr denotes the last loop restricted construct before we
4570 -- encountered an illegal relation between enclosing constructs. Emit
4571 -- an error depending on what Constr was.
4572
4573 --------------------------------
4574 -- Check_Loop_Pragma_Grouping --
4575 --------------------------------
4576
4577 procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is
4578 Stop_Search : exception;
4579 -- This exception is used to terminate the recursive descent of
4580 -- routine Check_Grouping.
4581
4582 procedure Check_Grouping (L : List_Id);
4583 -- Find the first group of pragmas in list L and if successful,
4584 -- ensure that the current pragma is part of that group. The
4585 -- routine raises Stop_Search once such a check is performed to
4586 -- halt the recursive descent.
4587
4588 procedure Grouping_Error (Prag : Node_Id);
4589 pragma No_Return (Grouping_Error);
4590 -- Emit an error concerning the current pragma indicating that it
4591 -- should be placed after pragma Prag.
4592
4593 --------------------
4594 -- Check_Grouping --
4595 --------------------
4596
4597 procedure Check_Grouping (L : List_Id) is
4598 HSS : Node_Id;
4599 Prag : Node_Id;
4600 Stmt : Node_Id;
4601
4602 begin
4603 -- Inspect the list of declarations or statements looking for
4604 -- the first grouping of pragmas:
4605
4606 -- loop
4607 -- pragma Loop_Invariant ...;
4608 -- pragma Loop_Variant ...;
4609 -- . . . -- (1)
4610 -- pragma Loop_Variant ...; -- current pragma
4611
4612 -- If the current pragma is not in the grouping, then it must
4613 -- either appear in a different declarative or statement list
4614 -- or the construct at (1) is separating the pragma from the
4615 -- grouping.
4616
4617 Stmt := First (L);
4618 while Present (Stmt) loop
4619
4620 -- Pragmas Loop_Invariant and Loop_Variant may only appear
4621 -- inside a loop or a block housed inside a loop. Inspect
4622 -- the declarations and statements of the block as they may
4623 -- contain the first grouping.
4624
4625 if Nkind (Stmt) = N_Block_Statement then
4626 HSS := Handled_Statement_Sequence (Stmt);
4627
4628 Check_Grouping (Declarations (Stmt));
4629
4630 if Present (HSS) then
4631 Check_Grouping (Statements (HSS));
4632 end if;
4633
4634 -- First pragma of the first topmost grouping has been found
4635
4636 elsif Is_Loop_Pragma (Stmt) then
4637
4638 -- The group and the current pragma are not in the same
4639 -- declarative or statement list.
4640
4641 if List_Containing (Stmt) /= List_Containing (N) then
4642 Grouping_Error (Stmt);
4643
4644 -- Try to reach the current pragma from the first pragma
4645 -- of the grouping while skipping other members:
4646
4647 -- pragma Loop_Invariant ...; -- first pragma
4648 -- pragma Loop_Variant ...; -- member
4649 -- . . .
4650 -- pragma Loop_Variant ...; -- current pragma
4651
4652 else
4653 while Present (Stmt) loop
4654
4655 -- The current pragma is either the first pragma
4656 -- of the group or is a member of the group. Stop
4657 -- the search as the placement is legal.
4658
4659 if Stmt = N then
4660 raise Stop_Search;
4661
4662 -- Skip group members, but keep track of the last
4663 -- pragma in the group.
4664
4665 elsif Is_Loop_Pragma (Stmt) then
4666 Prag := Stmt;
4667
4668 -- A non-pragma is separating the group from the
4669 -- current pragma, the placement is illegal.
4670
4671 else
4672 Grouping_Error (Prag);
4673 end if;
4674
4675 Next (Stmt);
4676 end loop;
4677
4678 -- If the traversal did not reach the current pragma,
4679 -- then the list must be malformed.
4680
4681 raise Program_Error;
4682 end if;
4683 end if;
4684
4685 Next (Stmt);
4686 end loop;
4687 end Check_Grouping;
4688
4689 --------------------
4690 -- Grouping_Error --
4691 --------------------
4692
4693 procedure Grouping_Error (Prag : Node_Id) is
4694 begin
4695 Error_Msg_Sloc := Sloc (Prag);
4696 Error_Pragma ("pragma% must appear next to pragma#");
4697 end Grouping_Error;
4698
4699 -- Start of processing for Check_Loop_Pragma_Grouping
4700
4701 begin
4702 -- Inspect the statements of the loop or nested blocks housed
4703 -- within to determine whether the current pragma is part of the
4704 -- first topmost grouping of Loop_Invariant and Loop_Variant.
4705
4706 Check_Grouping (Statements (Loop_Stmt));
4707
4708 exception
4709 when Stop_Search => null;
4710 end Check_Loop_Pragma_Grouping;
4711
4712 --------------------
4713 -- Is_Loop_Pragma --
4714 --------------------
4715
4716 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
4717 begin
4718 -- Inspect the original node as Loop_Invariant and Loop_Variant
4719 -- pragmas are rewritten to null when assertions are disabled.
4720
4721 if Nkind (Original_Node (Stmt)) = N_Pragma then
4722 return
4723 Nam_In (Pragma_Name (Original_Node (Stmt)),
4724 Name_Loop_Invariant,
4725 Name_Loop_Variant);
4726 else
4727 return False;
4728 end if;
4729 end Is_Loop_Pragma;
4730
4731 ---------------------
4732 -- Placement_Error --
4733 ---------------------
4734
4735 procedure Placement_Error (Constr : Node_Id) is
4736 LA : constant String := " with Loop_Entry";
4737
4738 begin
4739 if Prag_Id = Pragma_Assert then
4740 Error_Msg_String (1 .. LA'Length) := LA;
4741 Error_Msg_Strlen := LA'Length;
4742 else
4743 Error_Msg_Strlen := 0;
4744 end if;
4745
4746 if Nkind (Constr) = N_Pragma then
4747 Error_Pragma
4748 ("pragma %~ must appear immediately within the statements "
4749 & "of a loop");
4750 else
4751 Error_Pragma_Arg
4752 ("block containing pragma %~ must appear immediately within "
4753 & "the statements of a loop", Constr);
4754 end if;
4755 end Placement_Error;
4756
4757 -- Local declarations
4758
4759 Prev : Node_Id;
4760 Stmt : Node_Id;
4761
4762 -- Start of processing for Check_Loop_Pragma_Placement
4763
4764 begin
4765 -- Check that pragma appears immediately within a loop statement,
4766 -- ignoring intervening block statements.
4767
4768 Prev := N;
4769 Stmt := Parent (N);
4770 while Present (Stmt) loop
4771
4772 -- The pragma or previous block must appear immediately within the
4773 -- current block's declarative or statement part.
4774
4775 if Nkind (Stmt) = N_Block_Statement then
4776 if (No (Declarations (Stmt))
4777 or else List_Containing (Prev) /= Declarations (Stmt))
4778 and then
4779 List_Containing (Prev) /=
4780 Statements (Handled_Statement_Sequence (Stmt))
4781 then
4782 Placement_Error (Prev);
4783 return;
4784
4785 -- Keep inspecting the parents because we are now within a
4786 -- chain of nested blocks.
4787
4788 else
4789 Prev := Stmt;
4790 Stmt := Parent (Stmt);
4791 end if;
4792
4793 -- The pragma or previous block must appear immediately within the
4794 -- statements of the loop.
4795
4796 elsif Nkind (Stmt) = N_Loop_Statement then
4797 if List_Containing (Prev) /= Statements (Stmt) then
4798 Placement_Error (Prev);
4799 end if;
4800
4801 -- Stop the traversal because we reached the innermost loop
4802 -- regardless of whether we encountered an error or not.
4803
4804 exit;
4805
4806 -- Ignore a handled statement sequence. Note that this node may
4807 -- be related to a subprogram body in which case we will emit an
4808 -- error on the next iteration of the search.
4809
4810 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4811 Stmt := Parent (Stmt);
4812
4813 -- Any other statement breaks the chain from the pragma to the
4814 -- loop.
4815
4816 else
4817 Placement_Error (Prev);
4818 return;
4819 end if;
4820 end loop;
4821
4822 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4823 -- grouped together with other such pragmas.
4824
4825 if Is_Loop_Pragma (N) then
4826
4827 -- The previous check should have located the related loop
4828
4829 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
4830 Check_Loop_Pragma_Grouping (Stmt);
4831 end if;
4832 end Check_Loop_Pragma_Placement;
4833
4834 -------------------------------------------
4835 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4836 -------------------------------------------
4837
4838 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4839 P : Node_Id;
4840
4841 begin
4842 P := Parent (N);
4843 loop
4844 if No (P) then
4845 exit;
4846
4847 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4848 exit;
4849
4850 elsif Nkind_In (P, N_Package_Specification,
4851 N_Block_Statement)
4852 then
4853 return;
4854
4855 -- Note: the following tests seem a little peculiar, because
4856 -- they test for bodies, but if we were in the statement part
4857 -- of the body, we would already have hit the handled statement
4858 -- sequence, so the only way we get here is by being in the
4859 -- declarative part of the body.
4860
4861 elsif Nkind_In (P, N_Subprogram_Body,
4862 N_Package_Body,
4863 N_Task_Body,
4864 N_Entry_Body)
4865 then
4866 return;
4867 end if;
4868
4869 P := Parent (P);
4870 end loop;
4871
4872 Error_Pragma ("pragma% is not in declarative part or package spec");
4873 end Check_Is_In_Decl_Part_Or_Package_Spec;
4874
4875 -------------------------
4876 -- Check_No_Identifier --
4877 -------------------------
4878
4879 procedure Check_No_Identifier (Arg : Node_Id) is
4880 begin
4881 if Nkind (Arg) = N_Pragma_Argument_Association
4882 and then Chars (Arg) /= No_Name
4883 then
4884 Error_Pragma_Arg_Ident
4885 ("pragma% does not permit identifier& here", Arg);
4886 end if;
4887 end Check_No_Identifier;
4888
4889 --------------------------
4890 -- Check_No_Identifiers --
4891 --------------------------
4892
4893 procedure Check_No_Identifiers is
4894 Arg_Node : Node_Id;
4895 begin
4896 Arg_Node := Arg1;
4897 for J in 1 .. Arg_Count loop
4898 Check_No_Identifier (Arg_Node);
4899 Next (Arg_Node);
4900 end loop;
4901 end Check_No_Identifiers;
4902
4903 ------------------------
4904 -- Check_No_Link_Name --
4905 ------------------------
4906
4907 procedure Check_No_Link_Name is
4908 begin
4909 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
4910 Arg4 := Arg3;
4911 end if;
4912
4913 if Present (Arg4) then
4914 Error_Pragma_Arg
4915 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
4916 end if;
4917 end Check_No_Link_Name;
4918
4919 -------------------------------
4920 -- Check_Optional_Identifier --
4921 -------------------------------
4922
4923 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4924 begin
4925 if Present (Arg)
4926 and then Nkind (Arg) = N_Pragma_Argument_Association
4927 and then Chars (Arg) /= No_Name
4928 then
4929 if Chars (Arg) /= Id then
4930 Error_Msg_Name_1 := Pname;
4931 Error_Msg_Name_2 := Id;
4932 Error_Msg_N ("pragma% argument expects identifier%", Arg);
4933 raise Pragma_Exit;
4934 end if;
4935 end if;
4936 end Check_Optional_Identifier;
4937
4938 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4939 begin
4940 Name_Buffer (1 .. Id'Length) := Id;
4941 Name_Len := Id'Length;
4942 Check_Optional_Identifier (Arg, Name_Find);
4943 end Check_Optional_Identifier;
4944
4945 --------------------
4946 -- Check_Pre_Post --
4947 --------------------
4948
4949 procedure Check_Pre_Post is
4950 P : Node_Id;
4951 PO : Node_Id;
4952
4953 begin
4954 if not Is_List_Member (N) then
4955 Pragma_Misplaced;
4956 end if;
4957
4958 -- If we are within an inlined body, the legality of the pragma
4959 -- has been checked already.
4960
4961 if In_Inlined_Body then
4962 return;
4963 end if;
4964
4965 -- Search prior declarations
4966
4967 P := N;
4968 while Present (Prev (P)) loop
4969 P := Prev (P);
4970
4971 -- If the previous node is a generic subprogram, do not go to to
4972 -- the original node, which is the unanalyzed tree: we need to
4973 -- attach the pre/postconditions to the analyzed version at this
4974 -- point. They get propagated to the original tree when analyzing
4975 -- the corresponding body.
4976
4977 if Nkind (P) not in N_Generic_Declaration then
4978 PO := Original_Node (P);
4979 else
4980 PO := P;
4981 end if;
4982
4983 -- Skip past prior pragma
4984
4985 if Nkind (PO) = N_Pragma then
4986 null;
4987
4988 -- Skip stuff not coming from source
4989
4990 elsif not Comes_From_Source (PO) then
4991
4992 -- The condition may apply to a subprogram instantiation
4993
4994 if Nkind (PO) = N_Subprogram_Declaration
4995 and then Present (Generic_Parent (Specification (PO)))
4996 then
4997 return;
4998
4999 elsif Nkind (PO) = N_Subprogram_Declaration
5000 and then In_Instance
5001 then
5002 return;
5003
5004 -- For all other cases of non source code, do nothing
5005
5006 else
5007 null;
5008 end if;
5009
5010 -- Only remaining possibility is subprogram declaration
5011
5012 else
5013 return;
5014 end if;
5015 end loop;
5016
5017 -- If we fall through loop, pragma is at start of list, so see if it
5018 -- is at the start of declarations of a subprogram body.
5019
5020 PO := Parent (N);
5021
5022 if Nkind (PO) = N_Subprogram_Body
5023 and then List_Containing (N) = Declarations (PO)
5024 then
5025 -- This is only allowed if there is no separate specification
5026
5027 if Present (Corresponding_Spec (PO)) then
5028 Error_Pragma
5029 ("pragma% must apply to subprogram specification");
5030 end if;
5031
5032 return;
5033 end if;
5034 end Check_Pre_Post;
5035
5036 --------------------------------------
5037 -- Check_Precondition_Postcondition --
5038 --------------------------------------
5039
5040 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
5041 P : Node_Id;
5042 PO : Node_Id;
5043
5044 procedure Chain_PPC (PO : Node_Id);
5045 -- If PO is an entry or a [generic] subprogram declaration node, then
5046 -- the precondition/postcondition applies to this subprogram and the
5047 -- processing for the pragma is completed. Otherwise the pragma is
5048 -- misplaced.
5049
5050 ---------------
5051 -- Chain_PPC --
5052 ---------------
5053
5054 procedure Chain_PPC (PO : Node_Id) is
5055 S : Entity_Id;
5056
5057 begin
5058 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5059 if not From_Aspect_Specification (N) then
5060 Error_Pragma
5061 ("pragma% cannot be applied to abstract subprogram");
5062
5063 elsif Class_Present (N) then
5064 null;
5065
5066 else
5067 Error_Pragma
5068 ("aspect % requires ''Class for abstract subprogram");
5069 end if;
5070
5071 -- AI05-0230: The same restriction applies to null procedures. For
5072 -- compatibility with earlier uses of the Ada pragma, apply this
5073 -- rule only to aspect specifications.
5074
5075 -- The above discrepency needs documentation. Robert is dubious
5076 -- about whether it is a good idea ???
5077
5078 elsif Nkind (PO) = N_Subprogram_Declaration
5079 and then Nkind (Specification (PO)) = N_Procedure_Specification
5080 and then Null_Present (Specification (PO))
5081 and then From_Aspect_Specification (N)
5082 and then not Class_Present (N)
5083 then
5084 Error_Pragma
5085 ("aspect % requires ''Class for null procedure");
5086
5087 -- Pre/postconditions are legal on a subprogram body if it is not
5088 -- a completion of a declaration. They are also legal on a stub
5089 -- with no previous declarations (this is checked when processing
5090 -- the corresponding aspects).
5091
5092 elsif Nkind (PO) = N_Subprogram_Body
5093 and then Acts_As_Spec (PO)
5094 then
5095 null;
5096
5097 elsif Nkind (PO) = N_Subprogram_Body_Stub then
5098 null;
5099
5100 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5101 N_Expression_Function,
5102 N_Generic_Subprogram_Declaration,
5103 N_Entry_Declaration)
5104 then
5105 Pragma_Misplaced;
5106 end if;
5107
5108 -- Here if we have [generic] subprogram or entry declaration
5109
5110 if Nkind (PO) = N_Entry_Declaration then
5111 S := Defining_Entity (PO);
5112 else
5113 S := Defining_Unit_Name (Specification (PO));
5114
5115 if Nkind (S) = N_Defining_Program_Unit_Name then
5116 S := Defining_Identifier (S);
5117 end if;
5118 end if;
5119
5120 -- Note: we do not analyze the pragma at this point. Instead we
5121 -- delay this analysis until the end of the declarative part in
5122 -- which the pragma appears. This implements the required delay
5123 -- in this analysis, allowing forward references. The analysis
5124 -- happens at the end of Analyze_Declarations.
5125
5126 -- Chain spec PPC pragma to list for subprogram
5127
5128 Add_Contract_Item (N, S);
5129
5130 -- Return indicating spec case
5131
5132 In_Body := False;
5133 return;
5134 end Chain_PPC;
5135
5136 -- Start of processing for Check_Precondition_Postcondition
5137
5138 begin
5139 if not Is_List_Member (N) then
5140 Pragma_Misplaced;
5141 end if;
5142
5143 -- Preanalyze message argument if present. Visibility in this
5144 -- argument is established at the point of pragma occurrence.
5145
5146 if Arg_Count = 2 then
5147 Check_Optional_Identifier (Arg2, Name_Message);
5148 Preanalyze_Spec_Expression
5149 (Get_Pragma_Arg (Arg2), Standard_String);
5150 end if;
5151
5152 -- For a pragma PPC in the extended main source unit, record enabled
5153 -- status in SCO.
5154
5155 if Is_Checked (N) and then not Split_PPC (N) then
5156 Set_SCO_Pragma_Enabled (Loc);
5157 end if;
5158
5159 -- If we are within an inlined body, the legality of the pragma
5160 -- has been checked already.
5161
5162 if In_Inlined_Body then
5163 In_Body := True;
5164 return;
5165 end if;
5166
5167 -- Search prior declarations
5168
5169 P := N;
5170 while Present (Prev (P)) loop
5171 P := Prev (P);
5172
5173 -- If the previous node is a generic subprogram, do not go to to
5174 -- the original node, which is the unanalyzed tree: we need to
5175 -- attach the pre/postconditions to the analyzed version at this
5176 -- point. They get propagated to the original tree when analyzing
5177 -- the corresponding body.
5178
5179 if Nkind (P) not in N_Generic_Declaration then
5180 PO := Original_Node (P);
5181 else
5182 PO := P;
5183 end if;
5184
5185 -- Skip past prior pragma
5186
5187 if Nkind (PO) = N_Pragma then
5188 null;
5189
5190 -- Skip stuff not coming from source
5191
5192 elsif not Comes_From_Source (PO) then
5193
5194 -- The condition may apply to a subprogram instantiation
5195
5196 if Nkind (PO) = N_Subprogram_Declaration
5197 and then Present (Generic_Parent (Specification (PO)))
5198 then
5199 Chain_PPC (PO);
5200 return;
5201
5202 elsif Nkind (PO) = N_Subprogram_Declaration
5203 and then In_Instance
5204 then
5205 Chain_PPC (PO);
5206 return;
5207
5208 -- For all other cases of non source code, do nothing
5209
5210 else
5211 null;
5212 end if;
5213
5214 -- Only remaining possibility is subprogram declaration
5215
5216 else
5217 Chain_PPC (PO);
5218 return;
5219 end if;
5220 end loop;
5221
5222 -- If we fall through loop, pragma is at start of list, so see if it
5223 -- is at the start of declarations of a subprogram body.
5224
5225 PO := Parent (N);
5226
5227 if Nkind (PO) = N_Subprogram_Body
5228 and then List_Containing (N) = Declarations (PO)
5229 then
5230 if Operating_Mode /= Generate_Code or else Inside_A_Generic then
5231
5232 -- Analyze pragma expression for correctness and for ASIS use
5233
5234 Preanalyze_Assert_Expression
5235 (Get_Pragma_Arg (Arg1), Standard_Boolean);
5236
5237 -- In ASIS mode, for a pragma generated from a source aspect,
5238 -- also analyze the original aspect expression.
5239
5240 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5241 Preanalyze_Assert_Expression
5242 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
5243 end if;
5244 end if;
5245
5246 -- Retain copy of the pre/postcondition pragma in GNATprove mode.
5247 -- The copy is needed because the pragma is expanded into other
5248 -- constructs which are not acceptable in the N_Contract node.
5249
5250 if Acts_As_Spec (PO) and then GNATprove_Mode then
5251 declare
5252 Prag : constant Node_Id := New_Copy_Tree (N);
5253
5254 begin
5255 -- Preanalyze the pragma
5256
5257 Preanalyze_Assert_Expression
5258 (Get_Pragma_Arg
5259 (First (Pragma_Argument_Associations (Prag))),
5260 Standard_Boolean);
5261
5262 -- Preanalyze the corresponding aspect (if any)
5263
5264 if Present (Corresponding_Aspect (Prag)) then
5265 Preanalyze_Assert_Expression
5266 (Expression (Corresponding_Aspect (Prag)),
5267 Standard_Boolean);
5268 end if;
5269
5270 -- Chain the copy on the contract of the body
5271
5272 Add_Contract_Item
5273 (Prag, Defining_Unit_Name (Specification (PO)));
5274 end;
5275 end if;
5276
5277 In_Body := True;
5278 return;
5279
5280 -- See if it is in the pragmas after a library level subprogram
5281
5282 elsif Nkind (PO) = N_Compilation_Unit_Aux then
5283
5284 -- In GNATprove mode, analyze pragma expression for correctness,
5285 -- as it is not expanded later. Ditto in ASIS_Mode where there is
5286 -- no later point at which the aspect will be analyzed.
5287
5288 if GNATprove_Mode or ASIS_Mode then
5289 Analyze_Pre_Post_Condition_In_Decl_Part
5290 (N, Defining_Entity (Unit (Parent (PO))));
5291 end if;
5292
5293 Chain_PPC (Unit (Parent (PO)));
5294 return;
5295 end if;
5296
5297 -- If we fall through, pragma was misplaced
5298
5299 Pragma_Misplaced;
5300 end Check_Precondition_Postcondition;
5301
5302 -----------------------------
5303 -- Check_Static_Constraint --
5304 -----------------------------
5305
5306 -- Note: for convenience in writing this procedure, in addition to
5307 -- the officially (i.e. by spec) allowed argument which is always a
5308 -- constraint, it also allows ranges and discriminant associations.
5309 -- Above is not clear ???
5310
5311 procedure Check_Static_Constraint (Constr : Node_Id) is
5312
5313 procedure Require_Static (E : Node_Id);
5314 -- Require given expression to be static expression
5315
5316 --------------------
5317 -- Require_Static --
5318 --------------------
5319
5320 procedure Require_Static (E : Node_Id) is
5321 begin
5322 if not Is_OK_Static_Expression (E) then
5323 Flag_Non_Static_Expr
5324 ("non-static constraint not allowed in Unchecked_Union!", E);
5325 raise Pragma_Exit;
5326 end if;
5327 end Require_Static;
5328
5329 -- Start of processing for Check_Static_Constraint
5330
5331 begin
5332 case Nkind (Constr) is
5333 when N_Discriminant_Association =>
5334 Require_Static (Expression (Constr));
5335
5336 when N_Range =>
5337 Require_Static (Low_Bound (Constr));
5338 Require_Static (High_Bound (Constr));
5339
5340 when N_Attribute_Reference =>
5341 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5342 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5343
5344 when N_Range_Constraint =>
5345 Check_Static_Constraint (Range_Expression (Constr));
5346
5347 when N_Index_Or_Discriminant_Constraint =>
5348 declare
5349 IDC : Entity_Id;
5350 begin
5351 IDC := First (Constraints (Constr));
5352 while Present (IDC) loop
5353 Check_Static_Constraint (IDC);
5354 Next (IDC);
5355 end loop;
5356 end;
5357
5358 when others =>
5359 null;
5360 end case;
5361 end Check_Static_Constraint;
5362
5363 ---------------------
5364 -- Check_Test_Case --
5365 ---------------------
5366
5367 procedure Check_Test_Case is
5368 P : Node_Id;
5369 PO : Node_Id;
5370
5371 procedure Chain_CTC (PO : Node_Id);
5372 -- If PO is a [generic] subprogram declaration node, then the
5373 -- test-case applies to this subprogram and the processing for
5374 -- the pragma is completed. Otherwise the pragma is misplaced.
5375
5376 ---------------
5377 -- Chain_CTC --
5378 ---------------
5379
5380 procedure Chain_CTC (PO : Node_Id) is
5381 S : Entity_Id;
5382
5383 begin
5384 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5385 Error_Pragma
5386 ("pragma% cannot be applied to abstract subprogram");
5387
5388 elsif Nkind (PO) = N_Entry_Declaration then
5389 Error_Pragma ("pragma% cannot be applied to entry");
5390
5391 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5392 N_Generic_Subprogram_Declaration)
5393 then
5394 Pragma_Misplaced;
5395 end if;
5396
5397 -- Here if we have [generic] subprogram declaration
5398
5399 S := Defining_Unit_Name (Specification (PO));
5400
5401 -- Note: we do not analyze the pragma at this point. Instead we
5402 -- delay this analysis until the end of the declarative part in
5403 -- which the pragma appears. This implements the required delay
5404 -- in this analysis, allowing forward references. The analysis
5405 -- happens at the end of Analyze_Declarations.
5406
5407 -- There should not be another test-case with the same name
5408 -- associated to this subprogram.
5409
5410 declare
5411 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
5412 CTC : Node_Id;
5413
5414 begin
5415 CTC := Contract_Test_Cases (Contract (S));
5416 while Present (CTC) loop
5417
5418 -- Omit pragma Contract_Cases because it does not introduce
5419 -- a unique case name and it does not follow the syntax of
5420 -- Test_Case.
5421
5422 if Pragma_Name (CTC) = Name_Contract_Cases then
5423 null;
5424
5425 elsif String_Equal
5426 (Name, Get_Name_From_CTC_Pragma (CTC))
5427 then
5428 Error_Msg_Sloc := Sloc (CTC);
5429 Error_Pragma ("name for pragma% is already used#");
5430 end if;
5431
5432 CTC := Next_Pragma (CTC);
5433 end loop;
5434 end;
5435
5436 -- Chain spec CTC pragma to list for subprogram
5437
5438 Add_Contract_Item (N, S);
5439 end Chain_CTC;
5440
5441 -- Start of processing for Check_Test_Case
5442
5443 begin
5444 -- First check pragma arguments
5445
5446 Check_At_Least_N_Arguments (2);
5447 Check_At_Most_N_Arguments (4);
5448 Check_Arg_Order
5449 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
5450
5451 Check_Optional_Identifier (Arg1, Name_Name);
5452 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
5453
5454 -- In ASIS mode, for a pragma generated from a source aspect, also
5455 -- analyze the original aspect expression.
5456
5457 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5458 Check_Expr_Is_OK_Static_Expression
5459 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
5460 end if;
5461
5462 Check_Optional_Identifier (Arg2, Name_Mode);
5463 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
5464
5465 if Arg_Count = 4 then
5466 Check_Identifier (Arg3, Name_Requires);
5467 Check_Identifier (Arg4, Name_Ensures);
5468
5469 elsif Arg_Count = 3 then
5470 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
5471 end if;
5472
5473 -- Check pragma placement
5474
5475 if not Is_List_Member (N) then
5476 Pragma_Misplaced;
5477 end if;
5478
5479 -- Test-case should only appear in package spec unit
5480
5481 if Get_Source_Unit (N) = No_Unit
5482 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
5483 N_Package_Declaration,
5484 N_Generic_Package_Declaration)
5485 then
5486 Pragma_Misplaced;
5487 end if;
5488
5489 -- Search prior declarations
5490
5491 P := N;
5492 while Present (Prev (P)) loop
5493 P := Prev (P);
5494
5495 -- If the previous node is a generic subprogram, do not go to to
5496 -- the original node, which is the unanalyzed tree: we need to
5497 -- attach the test-case to the analyzed version at this point.
5498 -- They get propagated to the original tree when analyzing the
5499 -- corresponding body.
5500
5501 if Nkind (P) not in N_Generic_Declaration then
5502 PO := Original_Node (P);
5503 else
5504 PO := P;
5505 end if;
5506
5507 -- Skip past prior pragma
5508
5509 if Nkind (PO) = N_Pragma then
5510 null;
5511
5512 -- Skip stuff not coming from source
5513
5514 elsif not Comes_From_Source (PO) then
5515 null;
5516
5517 -- Only remaining possibility is subprogram declaration. First
5518 -- check that it is declared directly in a package declaration.
5519 -- This may be either the package declaration for the current unit
5520 -- being defined or a local package declaration.
5521
5522 elsif not Present (Parent (Parent (PO)))
5523 or else not Present (Parent (Parent (Parent (PO))))
5524 or else not Nkind_In (Parent (Parent (PO)),
5525 N_Package_Declaration,
5526 N_Generic_Package_Declaration)
5527 then
5528 Pragma_Misplaced;
5529
5530 else
5531 Chain_CTC (PO);
5532 return;
5533 end if;
5534 end loop;
5535
5536 -- If we fall through, pragma was misplaced
5537
5538 Pragma_Misplaced;
5539 end Check_Test_Case;
5540
5541 --------------------------------------
5542 -- Check_Valid_Configuration_Pragma --
5543 --------------------------------------
5544
5545 -- A configuration pragma must appear in the context clause of a
5546 -- compilation unit, and only other pragmas may precede it. Note that
5547 -- the test also allows use in a configuration pragma file.
5548
5549 procedure Check_Valid_Configuration_Pragma is
5550 begin
5551 if not Is_Configuration_Pragma then
5552 Error_Pragma ("incorrect placement for configuration pragma%");
5553 end if;
5554 end Check_Valid_Configuration_Pragma;
5555
5556 -------------------------------------
5557 -- Check_Valid_Library_Unit_Pragma --
5558 -------------------------------------
5559
5560 procedure Check_Valid_Library_Unit_Pragma is
5561 Plist : List_Id;
5562 Parent_Node : Node_Id;
5563 Unit_Name : Entity_Id;
5564 Unit_Kind : Node_Kind;
5565 Unit_Node : Node_Id;
5566 Sindex : Source_File_Index;
5567
5568 begin
5569 if not Is_List_Member (N) then
5570 Pragma_Misplaced;
5571
5572 else
5573 Plist := List_Containing (N);
5574 Parent_Node := Parent (Plist);
5575
5576 if Parent_Node = Empty then
5577 Pragma_Misplaced;
5578
5579 -- Case of pragma appearing after a compilation unit. In this case
5580 -- it must have an argument with the corresponding name and must
5581 -- be part of the following pragmas of its parent.
5582
5583 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5584 if Plist /= Pragmas_After (Parent_Node) then
5585 Pragma_Misplaced;
5586
5587 elsif Arg_Count = 0 then
5588 Error_Pragma
5589 ("argument required if outside compilation unit");
5590
5591 else
5592 Check_No_Identifiers;
5593 Check_Arg_Count (1);
5594 Unit_Node := Unit (Parent (Parent_Node));
5595 Unit_Kind := Nkind (Unit_Node);
5596
5597 Analyze (Get_Pragma_Arg (Arg1));
5598
5599 if Unit_Kind = N_Generic_Subprogram_Declaration
5600 or else Unit_Kind = N_Subprogram_Declaration
5601 then
5602 Unit_Name := Defining_Entity (Unit_Node);
5603
5604 elsif Unit_Kind in N_Generic_Instantiation then
5605 Unit_Name := Defining_Entity (Unit_Node);
5606
5607 else
5608 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5609 end if;
5610
5611 if Chars (Unit_Name) /=
5612 Chars (Entity (Get_Pragma_Arg (Arg1)))
5613 then
5614 Error_Pragma_Arg
5615 ("pragma% argument is not current unit name", Arg1);
5616 end if;
5617
5618 if Ekind (Unit_Name) = E_Package
5619 and then Present (Renamed_Entity (Unit_Name))
5620 then
5621 Error_Pragma ("pragma% not allowed for renamed package");
5622 end if;
5623 end if;
5624
5625 -- Pragma appears other than after a compilation unit
5626
5627 else
5628 -- Here we check for the generic instantiation case and also
5629 -- for the case of processing a generic formal package. We
5630 -- detect these cases by noting that the Sloc on the node
5631 -- does not belong to the current compilation unit.
5632
5633 Sindex := Source_Index (Current_Sem_Unit);
5634
5635 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5636 Rewrite (N, Make_Null_Statement (Loc));
5637 return;
5638
5639 -- If before first declaration, the pragma applies to the
5640 -- enclosing unit, and the name if present must be this name.
5641
5642 elsif Is_Before_First_Decl (N, Plist) then
5643 Unit_Node := Unit_Declaration_Node (Current_Scope);
5644 Unit_Kind := Nkind (Unit_Node);
5645
5646 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5647 Pragma_Misplaced;
5648
5649 elsif Unit_Kind = N_Subprogram_Body
5650 and then not Acts_As_Spec (Unit_Node)
5651 then
5652 Pragma_Misplaced;
5653
5654 elsif Nkind (Parent_Node) = N_Package_Body then
5655 Pragma_Misplaced;
5656
5657 elsif Nkind (Parent_Node) = N_Package_Specification
5658 and then Plist = Private_Declarations (Parent_Node)
5659 then
5660 Pragma_Misplaced;
5661
5662 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
5663 or else Nkind (Parent_Node) =
5664 N_Generic_Subprogram_Declaration)
5665 and then Plist = Generic_Formal_Declarations (Parent_Node)
5666 then
5667 Pragma_Misplaced;
5668
5669 elsif Arg_Count > 0 then
5670 Analyze (Get_Pragma_Arg (Arg1));
5671
5672 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5673 Error_Pragma_Arg
5674 ("name in pragma% must be enclosing unit", Arg1);
5675 end if;
5676
5677 -- It is legal to have no argument in this context
5678
5679 else
5680 return;
5681 end if;
5682
5683 -- Error if not before first declaration. This is because a
5684 -- library unit pragma argument must be the name of a library
5685 -- unit (RM 10.1.5(7)), but the only names permitted in this
5686 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5687 -- generic subprogram declarations or generic instantiations.
5688
5689 else
5690 Error_Pragma
5691 ("pragma% misplaced, must be before first declaration");
5692 end if;
5693 end if;
5694 end if;
5695 end Check_Valid_Library_Unit_Pragma;
5696
5697 -------------------
5698 -- Check_Variant --
5699 -------------------
5700
5701 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5702 Clist : constant Node_Id := Component_List (Variant);
5703 Comp : Node_Id;
5704
5705 begin
5706 Comp := First (Component_Items (Clist));
5707 while Present (Comp) loop
5708 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5709 Next (Comp);
5710 end loop;
5711 end Check_Variant;
5712
5713 ---------------------------
5714 -- Ensure_Aggregate_Form --
5715 ---------------------------
5716
5717 procedure Ensure_Aggregate_Form (Arg : Node_Id) is
5718 Expr : constant Node_Id := Get_Pragma_Arg (Arg);
5719 Loc : constant Source_Ptr := Sloc (Arg);
5720 Nam : constant Name_Id := Chars (Arg);
5721 Comps : List_Id := No_List;
5722 Exprs : List_Id := No_List;
5723
5724 begin
5725 -- The argument is already in aggregate form, but the presence of a
5726 -- name causes this to be interpreted as a named association which in
5727 -- turn must be converted into an aggregate.
5728
5729 -- pragma Global (In_Out => (A, B, C))
5730 -- ^ ^
5731 -- name aggregate
5732
5733 -- pragma Global ((In_Out => (A, B, C)))
5734 -- ^ ^
5735 -- aggregate aggregate
5736
5737 if Nkind (Expr) = N_Aggregate then
5738 if Nam = No_Name then
5739 return;
5740 end if;
5741
5742 -- Do not transform a null argument into an aggregate as N_Null has
5743 -- special meaning in formal verification pragmas.
5744
5745 elsif Nkind (Expr) = N_Null then
5746 return;
5747 end if;
5748
5749 -- Positional argument is transformed into an aggregate with an
5750 -- Expressions list.
5751
5752 if Nam = No_Name then
5753 Exprs := New_List (Relocate_Node (Expr));
5754
5755 -- An associative argument is transformed into an aggregate with
5756 -- Component_Associations.
5757
5758 else
5759 Comps := New_List (
5760 Make_Component_Association (Loc,
5761 Choices => New_List (Make_Identifier (Loc, Chars (Arg))),
5762 Expression => Relocate_Node (Expr)));
5763
5764 end if;
5765
5766 -- Remove the pragma argument name as this information has been
5767 -- captured in the aggregate.
5768
5769 Set_Chars (Arg, No_Name);
5770
5771 Set_Expression (Arg,
5772 Make_Aggregate (Loc,
5773 Component_Associations => Comps,
5774 Expressions => Exprs));
5775 end Ensure_Aggregate_Form;
5776
5777 ------------------
5778 -- Error_Pragma --
5779 ------------------
5780
5781 procedure Error_Pragma (Msg : String) is
5782 begin
5783 Error_Msg_Name_1 := Pname;
5784 Error_Msg_N (Fix_Error (Msg), N);
5785 raise Pragma_Exit;
5786 end Error_Pragma;
5787
5788 ----------------------
5789 -- Error_Pragma_Arg --
5790 ----------------------
5791
5792 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5793 begin
5794 Error_Msg_Name_1 := Pname;
5795 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5796 raise Pragma_Exit;
5797 end Error_Pragma_Arg;
5798
5799 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
5800 begin
5801 Error_Msg_Name_1 := Pname;
5802 Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg));
5803 Error_Pragma_Arg (Msg2, Arg);
5804 end Error_Pragma_Arg;
5805
5806 ----------------------------
5807 -- Error_Pragma_Arg_Ident --
5808 ----------------------------
5809
5810 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5811 begin
5812 Error_Msg_Name_1 := Pname;
5813 Error_Msg_N (Fix_Error (Msg), Arg);
5814 raise Pragma_Exit;
5815 end Error_Pragma_Arg_Ident;
5816
5817 ----------------------
5818 -- Error_Pragma_Ref --
5819 ----------------------
5820
5821 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5822 begin
5823 Error_Msg_Name_1 := Pname;
5824 Error_Msg_Sloc := Sloc (Ref);
5825 Error_Msg_NE (Fix_Error (Msg), N, Ref);
5826 raise Pragma_Exit;
5827 end Error_Pragma_Ref;
5828
5829 ------------------------
5830 -- Find_Lib_Unit_Name --
5831 ------------------------
5832
5833 function Find_Lib_Unit_Name return Entity_Id is
5834 begin
5835 -- Return inner compilation unit entity, for case of nested
5836 -- categorization pragmas. This happens in generic unit.
5837
5838 if Nkind (Parent (N)) = N_Package_Specification
5839 and then Defining_Entity (Parent (N)) /= Current_Scope
5840 then
5841 return Defining_Entity (Parent (N));
5842 else
5843 return Current_Scope;
5844 end if;
5845 end Find_Lib_Unit_Name;
5846
5847 ----------------------------
5848 -- Find_Program_Unit_Name --
5849 ----------------------------
5850
5851 procedure Find_Program_Unit_Name (Id : Node_Id) is
5852 Unit_Name : Entity_Id;
5853 Unit_Kind : Node_Kind;
5854 P : constant Node_Id := Parent (N);
5855
5856 begin
5857 if Nkind (P) = N_Compilation_Unit then
5858 Unit_Kind := Nkind (Unit (P));
5859
5860 if Unit_Kind = N_Subprogram_Declaration
5861 or else Unit_Kind = N_Package_Declaration
5862 or else Unit_Kind in N_Generic_Declaration
5863 then
5864 Unit_Name := Defining_Entity (Unit (P));
5865
5866 if Chars (Id) = Chars (Unit_Name) then
5867 Set_Entity (Id, Unit_Name);
5868 Set_Etype (Id, Etype (Unit_Name));
5869 else
5870 Set_Etype (Id, Any_Type);
5871 Error_Pragma
5872 ("cannot find program unit referenced by pragma%");
5873 end if;
5874
5875 else
5876 Set_Etype (Id, Any_Type);
5877 Error_Pragma ("pragma% inapplicable to this unit");
5878 end if;
5879
5880 else
5881 Analyze (Id);
5882 end if;
5883 end Find_Program_Unit_Name;
5884
5885 -----------------------------------------
5886 -- Find_Unique_Parameterless_Procedure --
5887 -----------------------------------------
5888
5889 function Find_Unique_Parameterless_Procedure
5890 (Name : Entity_Id;
5891 Arg : Node_Id) return Entity_Id
5892 is
5893 Proc : Entity_Id := Empty;
5894
5895 begin
5896 -- The body of this procedure needs some comments ???
5897
5898 if not Is_Entity_Name (Name) then
5899 Error_Pragma_Arg
5900 ("argument of pragma% must be entity name", Arg);
5901
5902 elsif not Is_Overloaded (Name) then
5903 Proc := Entity (Name);
5904
5905 if Ekind (Proc) /= E_Procedure
5906 or else Present (First_Formal (Proc))
5907 then
5908 Error_Pragma_Arg
5909 ("argument of pragma% must be parameterless procedure", Arg);
5910 end if;
5911
5912 else
5913 declare
5914 Found : Boolean := False;
5915 It : Interp;
5916 Index : Interp_Index;
5917
5918 begin
5919 Get_First_Interp (Name, Index, It);
5920 while Present (It.Nam) loop
5921 Proc := It.Nam;
5922
5923 if Ekind (Proc) = E_Procedure
5924 and then No (First_Formal (Proc))
5925 then
5926 if not Found then
5927 Found := True;
5928 Set_Entity (Name, Proc);
5929 Set_Is_Overloaded (Name, False);
5930 else
5931 Error_Pragma_Arg
5932 ("ambiguous handler name for pragma% ", Arg);
5933 end if;
5934 end if;
5935
5936 Get_Next_Interp (Index, It);
5937 end loop;
5938
5939 if not Found then
5940 Error_Pragma_Arg
5941 ("argument of pragma% must be parameterless procedure",
5942 Arg);
5943 else
5944 Proc := Entity (Name);
5945 end if;
5946 end;
5947 end if;
5948
5949 return Proc;
5950 end Find_Unique_Parameterless_Procedure;
5951
5952 ---------------
5953 -- Fix_Error --
5954 ---------------
5955
5956 function Fix_Error (Msg : String) return String is
5957 Res : String (Msg'Range) := Msg;
5958 Res_Last : Natural := Msg'Last;
5959 J : Natural;
5960
5961 begin
5962 -- If we have a rewriting of another pragma, go to that pragma
5963
5964 if Is_Rewrite_Substitution (N)
5965 and then Nkind (Original_Node (N)) = N_Pragma
5966 then
5967 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5968 end if;
5969
5970 -- Case where pragma comes from an aspect specification
5971
5972 if From_Aspect_Specification (N) then
5973
5974 -- Change appearence of "pragma" in message to "aspect"
5975
5976 J := Res'First;
5977 while J <= Res_Last - 5 loop
5978 if Res (J .. J + 5) = "pragma" then
5979 Res (J .. J + 5) := "aspect";
5980 J := J + 6;
5981
5982 else
5983 J := J + 1;
5984 end if;
5985 end loop;
5986
5987 -- Change "argument of" at start of message to "entity for"
5988
5989 if Res'Length > 11
5990 and then Res (Res'First .. Res'First + 10) = "argument of"
5991 then
5992 Res (Res'First .. Res'First + 9) := "entity for";
5993 Res (Res'First + 10 .. Res_Last - 1) :=
5994 Res (Res'First + 11 .. Res_Last);
5995 Res_Last := Res_Last - 1;
5996 end if;
5997
5998 -- Change "argument" at start of message to "entity"
5999
6000 if Res'Length > 8
6001 and then Res (Res'First .. Res'First + 7) = "argument"
6002 then
6003 Res (Res'First .. Res'First + 5) := "entity";
6004 Res (Res'First + 6 .. Res_Last - 2) :=
6005 Res (Res'First + 8 .. Res_Last);
6006 Res_Last := Res_Last - 2;
6007 end if;
6008
6009 -- Get name from corresponding aspect
6010
6011 Error_Msg_Name_1 := Original_Aspect_Name (N);
6012 end if;
6013
6014 -- Return possibly modified message
6015
6016 return Res (Res'First .. Res_Last);
6017 end Fix_Error;
6018
6019 -------------------------
6020 -- Gather_Associations --
6021 -------------------------
6022
6023 procedure Gather_Associations
6024 (Names : Name_List;
6025 Args : out Args_List)
6026 is
6027 Arg : Node_Id;
6028
6029 begin
6030 -- Initialize all parameters to Empty
6031
6032 for J in Args'Range loop
6033 Args (J) := Empty;
6034 end loop;
6035
6036 -- That's all we have to do if there are no argument associations
6037
6038 if No (Pragma_Argument_Associations (N)) then
6039 return;
6040 end if;
6041
6042 -- Otherwise first deal with any positional parameters present
6043
6044 Arg := First (Pragma_Argument_Associations (N));
6045 for Index in Args'Range loop
6046 exit when No (Arg) or else Chars (Arg) /= No_Name;
6047 Args (Index) := Get_Pragma_Arg (Arg);
6048 Next (Arg);
6049 end loop;
6050
6051 -- Positional parameters all processed, if any left, then we
6052 -- have too many positional parameters.
6053
6054 if Present (Arg) and then Chars (Arg) = No_Name then
6055 Error_Pragma_Arg
6056 ("too many positional associations for pragma%", Arg);
6057 end if;
6058
6059 -- Process named parameters if any are present
6060
6061 while Present (Arg) loop
6062 if Chars (Arg) = No_Name then
6063 Error_Pragma_Arg
6064 ("positional association cannot follow named association",
6065 Arg);
6066
6067 else
6068 for Index in Names'Range loop
6069 if Names (Index) = Chars (Arg) then
6070 if Present (Args (Index)) then
6071 Error_Pragma_Arg
6072 ("duplicate argument association for pragma%", Arg);
6073 else
6074 Args (Index) := Get_Pragma_Arg (Arg);
6075 exit;
6076 end if;
6077 end if;
6078
6079 if Index = Names'Last then
6080 Error_Msg_Name_1 := Pname;
6081 Error_Msg_N ("pragma% does not allow & argument", Arg);
6082
6083 -- Check for possible misspelling
6084
6085 for Index1 in Names'Range loop
6086 if Is_Bad_Spelling_Of
6087 (Chars (Arg), Names (Index1))
6088 then
6089 Error_Msg_Name_1 := Names (Index1);
6090 Error_Msg_N -- CODEFIX
6091 ("\possible misspelling of%", Arg);
6092 exit;
6093 end if;
6094 end loop;
6095
6096 raise Pragma_Exit;
6097 end if;
6098 end loop;
6099 end if;
6100
6101 Next (Arg);
6102 end loop;
6103 end Gather_Associations;
6104
6105 -----------------
6106 -- GNAT_Pragma --
6107 -----------------
6108
6109 procedure GNAT_Pragma is
6110 begin
6111 -- We need to check the No_Implementation_Pragmas restriction for
6112 -- the case of a pragma from source. Note that the case of aspects
6113 -- generating corresponding pragmas marks these pragmas as not being
6114 -- from source, so this test also catches that case.
6115
6116 if Comes_From_Source (N) then
6117 Check_Restriction (No_Implementation_Pragmas, N);
6118 end if;
6119 end GNAT_Pragma;
6120
6121 --------------------------
6122 -- Is_Before_First_Decl --
6123 --------------------------
6124
6125 function Is_Before_First_Decl
6126 (Pragma_Node : Node_Id;
6127 Decls : List_Id) return Boolean
6128 is
6129 Item : Node_Id := First (Decls);
6130
6131 begin
6132 -- Only other pragmas can come before this pragma
6133
6134 loop
6135 if No (Item) or else Nkind (Item) /= N_Pragma then
6136 return False;
6137
6138 elsif Item = Pragma_Node then
6139 return True;
6140 end if;
6141
6142 Next (Item);
6143 end loop;
6144 end Is_Before_First_Decl;
6145
6146 -----------------------------
6147 -- Is_Configuration_Pragma --
6148 -----------------------------
6149
6150 -- A configuration pragma must appear in the context clause of a
6151 -- compilation unit, and only other pragmas may precede it. Note that
6152 -- the test below also permits use in a configuration pragma file.
6153
6154 function Is_Configuration_Pragma return Boolean is
6155 Lis : constant List_Id := List_Containing (N);
6156 Par : constant Node_Id := Parent (N);
6157 Prg : Node_Id;
6158
6159 begin
6160 -- If no parent, then we are in the configuration pragma file,
6161 -- so the placement is definitely appropriate.
6162
6163 if No (Par) then
6164 return True;
6165
6166 -- Otherwise we must be in the context clause of a compilation unit
6167 -- and the only thing allowed before us in the context list is more
6168 -- configuration pragmas.
6169
6170 elsif Nkind (Par) = N_Compilation_Unit
6171 and then Context_Items (Par) = Lis
6172 then
6173 Prg := First (Lis);
6174
6175 loop
6176 if Prg = N then
6177 return True;
6178 elsif Nkind (Prg) /= N_Pragma then
6179 return False;
6180 end if;
6181
6182 Next (Prg);
6183 end loop;
6184
6185 else
6186 return False;
6187 end if;
6188 end Is_Configuration_Pragma;
6189
6190 --------------------------
6191 -- Is_In_Context_Clause --
6192 --------------------------
6193
6194 function Is_In_Context_Clause return Boolean is
6195 Plist : List_Id;
6196 Parent_Node : Node_Id;
6197
6198 begin
6199 if not Is_List_Member (N) then
6200 return False;
6201
6202 else
6203 Plist := List_Containing (N);
6204 Parent_Node := Parent (Plist);
6205
6206 if Parent_Node = Empty
6207 or else Nkind (Parent_Node) /= N_Compilation_Unit
6208 or else Context_Items (Parent_Node) /= Plist
6209 then
6210 return False;
6211 end if;
6212 end if;
6213
6214 return True;
6215 end Is_In_Context_Clause;
6216
6217 ---------------------------------
6218 -- Is_Static_String_Expression --
6219 ---------------------------------
6220
6221 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6222 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
6223
6224 begin
6225 Analyze_And_Resolve (Argx);
6226 return Is_OK_Static_Expression (Argx)
6227 and then Nkind (Argx) = N_String_Literal;
6228 end Is_Static_String_Expression;
6229
6230 ----------------------
6231 -- Pragma_Misplaced --
6232 ----------------------
6233
6234 procedure Pragma_Misplaced is
6235 begin
6236 Error_Pragma ("incorrect placement of pragma%");
6237 end Pragma_Misplaced;
6238
6239 ------------------------------------
6240 -- Process_Atomic_Shared_Volatile --
6241 ------------------------------------
6242
6243 procedure Process_Atomic_Shared_Volatile is
6244 E_Id : Node_Id;
6245 E : Entity_Id;
6246 D : Node_Id;
6247 K : Node_Kind;
6248 Utyp : Entity_Id;
6249
6250 procedure Set_Atomic (E : Entity_Id);
6251 -- Set given type as atomic, and if no explicit alignment was given,
6252 -- set alignment to unknown, since back end knows what the alignment
6253 -- requirements are for atomic arrays. Note: this step is necessary
6254 -- for derived types.
6255
6256 ----------------
6257 -- Set_Atomic --
6258 ----------------
6259
6260 procedure Set_Atomic (E : Entity_Id) is
6261 begin
6262 Set_Is_Atomic (E);
6263
6264 if not Has_Alignment_Clause (E) then
6265 Set_Alignment (E, Uint_0);
6266 end if;
6267 end Set_Atomic;
6268
6269 -- Start of processing for Process_Atomic_Shared_Volatile
6270
6271 begin
6272 Check_Ada_83_Warning;
6273 Check_No_Identifiers;
6274 Check_Arg_Count (1);
6275 Check_Arg_Is_Local_Name (Arg1);
6276 E_Id := Get_Pragma_Arg (Arg1);
6277
6278 if Etype (E_Id) = Any_Type then
6279 return;
6280 end if;
6281
6282 E := Entity (E_Id);
6283 D := Declaration_Node (E);
6284 K := Nkind (D);
6285
6286 -- Check duplicate before we chain ourselves
6287
6288 Check_Duplicate_Pragma (E);
6289
6290 -- Now check appropriateness of the entity
6291
6292 if Is_Type (E) then
6293 if Rep_Item_Too_Early (E, N)
6294 or else
6295 Rep_Item_Too_Late (E, N)
6296 then
6297 return;
6298 else
6299 Check_First_Subtype (Arg1);
6300 end if;
6301
6302 if Prag_Id /= Pragma_Volatile then
6303 Set_Atomic (E);
6304 Set_Atomic (Underlying_Type (E));
6305 Set_Atomic (Base_Type (E));
6306 end if;
6307
6308 -- Attribute belongs on the base type. If the view of the type is
6309 -- currently private, it also belongs on the underlying type.
6310
6311 Set_Is_Volatile (Base_Type (E));
6312 Set_Is_Volatile (Underlying_Type (E));
6313
6314 Set_Treat_As_Volatile (E);
6315 Set_Treat_As_Volatile (Underlying_Type (E));
6316
6317 elsif K = N_Object_Declaration
6318 or else (K = N_Component_Declaration
6319 and then Original_Record_Component (E) = E)
6320 then
6321 if Rep_Item_Too_Late (E, N) then
6322 return;
6323 end if;
6324
6325 if Prag_Id /= Pragma_Volatile then
6326 Set_Is_Atomic (E);
6327
6328 -- If the object declaration has an explicit initialization, a
6329 -- temporary may have to be created to hold the expression, to
6330 -- ensure that access to the object remain atomic.
6331
6332 if Nkind (Parent (E)) = N_Object_Declaration
6333 and then Present (Expression (Parent (E)))
6334 then
6335 Set_Has_Delayed_Freeze (E);
6336 end if;
6337
6338 -- An interesting improvement here. If an object of composite
6339 -- type X is declared atomic, and the type X isn't, that's a
6340 -- pity, since it may not have appropriate alignment etc. We
6341 -- can rescue this in the special case where the object and
6342 -- type are in the same unit by just setting the type as
6343 -- atomic, so that the back end will process it as atomic.
6344
6345 -- Note: we used to do this for elementary types as well,
6346 -- but that turns out to be a bad idea and can have unwanted
6347 -- effects, most notably if the type is elementary, the object
6348 -- a simple component within a record, and both are in a spec:
6349 -- every object of this type in the entire program will be
6350 -- treated as atomic, thus incurring a potentially costly
6351 -- synchronization operation for every access.
6352
6353 -- Of course it would be best if the back end could just adjust
6354 -- the alignment etc for the specific object, but that's not
6355 -- something we are capable of doing at this point.
6356
6357 Utyp := Underlying_Type (Etype (E));
6358
6359 if Present (Utyp)
6360 and then Is_Composite_Type (Utyp)
6361 and then Sloc (E) > No_Location
6362 and then Sloc (Utyp) > No_Location
6363 and then
6364 Get_Source_File_Index (Sloc (E)) =
6365 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
6366 then
6367 Set_Is_Atomic (Underlying_Type (Etype (E)));
6368 end if;
6369 end if;
6370
6371 Set_Is_Volatile (E);
6372 Set_Treat_As_Volatile (E);
6373
6374 else
6375 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6376 end if;
6377
6378 -- The following check is only relevant when SPARK_Mode is on as
6379 -- this is not a standard Ada legality rule. Pragma Volatile can
6380 -- only apply to a full type declaration or an object declaration
6381 -- (SPARK RM C.6(1)).
6382
6383 if SPARK_Mode = On
6384 and then Prag_Id = Pragma_Volatile
6385 and then not Nkind_In (K, N_Full_Type_Declaration,
6386 N_Object_Declaration)
6387 then
6388 Error_Pragma_Arg
6389 ("argument of pragma % must denote a full type or object "
6390 & "declaration", Arg1);
6391 end if;
6392 end Process_Atomic_Shared_Volatile;
6393
6394 -------------------------------------------
6395 -- Process_Compile_Time_Warning_Or_Error --
6396 -------------------------------------------
6397
6398 procedure Process_Compile_Time_Warning_Or_Error is
6399 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
6400
6401 begin
6402 Check_Arg_Count (2);
6403 Check_No_Identifiers;
6404 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
6405 Analyze_And_Resolve (Arg1x, Standard_Boolean);
6406
6407 if Compile_Time_Known_Value (Arg1x) then
6408 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6409 declare
6410 Str : constant String_Id :=
6411 Strval (Get_Pragma_Arg (Arg2));
6412 Len : constant Int := String_Length (Str);
6413 Cont : Boolean;
6414 Ptr : Nat;
6415 CC : Char_Code;
6416 C : Character;
6417 Cent : constant Entity_Id :=
6418 Cunit_Entity (Current_Sem_Unit);
6419
6420 Force : constant Boolean :=
6421 Prag_Id = Pragma_Compile_Time_Warning
6422 and then
6423 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
6424 and then (Ekind (Cent) /= E_Package
6425 or else not In_Private_Part (Cent));
6426 -- Set True if this is the warning case, and we are in the
6427 -- visible part of a package spec, or in a subprogram spec,
6428 -- in which case we want to force the client to see the
6429 -- warning, even though it is not in the main unit.
6430
6431 begin
6432 -- Loop through segments of message separated by line feeds.
6433 -- We output these segments as separate messages with
6434 -- continuation marks for all but the first.
6435
6436 Cont := False;
6437 Ptr := 1;
6438 loop
6439 Error_Msg_Strlen := 0;
6440
6441 -- Loop to copy characters from argument to error message
6442 -- string buffer.
6443
6444 loop
6445 exit when Ptr > Len;
6446 CC := Get_String_Char (Str, Ptr);
6447 Ptr := Ptr + 1;
6448
6449 -- Ignore wide chars ??? else store character
6450
6451 if In_Character_Range (CC) then
6452 C := Get_Character (CC);
6453 exit when C = ASCII.LF;
6454 Error_Msg_Strlen := Error_Msg_Strlen + 1;
6455 Error_Msg_String (Error_Msg_Strlen) := C;
6456 end if;
6457 end loop;
6458
6459 -- Here with one line ready to go
6460
6461 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
6462
6463 -- If this is a warning in a spec, then we want clients
6464 -- to see the warning, so mark the message with the
6465 -- special sequence !! to force the warning. In the case
6466 -- of a package spec, we do not force this if we are in
6467 -- the private part of the spec.
6468
6469 if Force then
6470 if Cont = False then
6471 Error_Msg_N ("<<~!!", Arg1);
6472 Cont := True;
6473 else
6474 Error_Msg_N ("\<<~!!", Arg1);
6475 end if;
6476
6477 -- Error, rather than warning, or in a body, so we do not
6478 -- need to force visibility for client (error will be
6479 -- output in any case, and this is the situation in which
6480 -- we do not want a client to get a warning, since the
6481 -- warning is in the body or the spec private part).
6482
6483 else
6484 if Cont = False then
6485 Error_Msg_N ("<<~", Arg1);
6486 Cont := True;
6487 else
6488 Error_Msg_N ("\<<~", Arg1);
6489 end if;
6490 end if;
6491
6492 exit when Ptr > Len;
6493 end loop;
6494 end;
6495 end if;
6496 end if;
6497 end Process_Compile_Time_Warning_Or_Error;
6498
6499 ------------------------
6500 -- Process_Convention --
6501 ------------------------
6502
6503 procedure Process_Convention
6504 (C : out Convention_Id;
6505 Ent : out Entity_Id)
6506 is
6507 Id : Node_Id;
6508 E : Entity_Id;
6509 E1 : Entity_Id;
6510 Cname : Name_Id;
6511 Comp_Unit : Unit_Number_Type;
6512
6513 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
6514 -- Called if we have more than one Export/Import/Convention pragma.
6515 -- This is generally illegal, but we have a special case of allowing
6516 -- Import and Interface to coexist if they specify the convention in
6517 -- a consistent manner. We are allowed to do this, since Interface is
6518 -- an implementation defined pragma, and we choose to do it since we
6519 -- know Rational allows this combination. S is the entity id of the
6520 -- subprogram in question. This procedure also sets the special flag
6521 -- Import_Interface_Present in both pragmas in the case where we do
6522 -- have matching Import and Interface pragmas.
6523
6524 procedure Set_Convention_From_Pragma (E : Entity_Id);
6525 -- Set convention in entity E, and also flag that the entity has a
6526 -- convention pragma. If entity is for a private or incomplete type,
6527 -- also set convention and flag on underlying type. This procedure
6528 -- also deals with the special case of C_Pass_By_Copy convention,
6529 -- and error checks for inappropriate convention specification.
6530
6531 -------------------------------
6532 -- Diagnose_Multiple_Pragmas --
6533 -------------------------------
6534
6535 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6536 Pdec : constant Node_Id := Declaration_Node (S);
6537 Decl : Node_Id;
6538 Err : Boolean;
6539
6540 function Same_Convention (Decl : Node_Id) return Boolean;
6541 -- Decl is a pragma node. This function returns True if this
6542 -- pragma has a first argument that is an identifier with a
6543 -- Chars field corresponding to the Convention_Id C.
6544
6545 function Same_Name (Decl : Node_Id) return Boolean;
6546 -- Decl is a pragma node. This function returns True if this
6547 -- pragma has a second argument that is an identifier with a
6548 -- Chars field that matches the Chars of the current subprogram.
6549
6550 ---------------------
6551 -- Same_Convention --
6552 ---------------------
6553
6554 function Same_Convention (Decl : Node_Id) return Boolean is
6555 Arg1 : constant Node_Id :=
6556 First (Pragma_Argument_Associations (Decl));
6557
6558 begin
6559 if Present (Arg1) then
6560 declare
6561 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6562 begin
6563 if Nkind (Arg) = N_Identifier
6564 and then Is_Convention_Name (Chars (Arg))
6565 and then Get_Convention_Id (Chars (Arg)) = C
6566 then
6567 return True;
6568 end if;
6569 end;
6570 end if;
6571
6572 return False;
6573 end Same_Convention;
6574
6575 ---------------
6576 -- Same_Name --
6577 ---------------
6578
6579 function Same_Name (Decl : Node_Id) return Boolean is
6580 Arg1 : constant Node_Id :=
6581 First (Pragma_Argument_Associations (Decl));
6582 Arg2 : Node_Id;
6583
6584 begin
6585 if No (Arg1) then
6586 return False;
6587 end if;
6588
6589 Arg2 := Next (Arg1);
6590
6591 if No (Arg2) then
6592 return False;
6593 end if;
6594
6595 declare
6596 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6597 begin
6598 if Nkind (Arg) = N_Identifier
6599 and then Chars (Arg) = Chars (S)
6600 then
6601 return True;
6602 end if;
6603 end;
6604
6605 return False;
6606 end Same_Name;
6607
6608 -- Start of processing for Diagnose_Multiple_Pragmas
6609
6610 begin
6611 Err := True;
6612
6613 -- Definitely give message if we have Convention/Export here
6614
6615 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
6616 null;
6617
6618 -- If we have an Import or Export, scan back from pragma to
6619 -- find any previous pragma applying to the same procedure.
6620 -- The scan will be terminated by the start of the list, or
6621 -- hitting the subprogram declaration. This won't allow one
6622 -- pragma to appear in the public part and one in the private
6623 -- part, but that seems very unlikely in practice.
6624
6625 else
6626 Decl := Prev (N);
6627 while Present (Decl) and then Decl /= Pdec loop
6628
6629 -- Look for pragma with same name as us
6630
6631 if Nkind (Decl) = N_Pragma
6632 and then Same_Name (Decl)
6633 then
6634 -- Give error if same as our pragma or Export/Convention
6635
6636 if Nam_In (Pragma_Name (Decl), Name_Export,
6637 Name_Convention,
6638 Pragma_Name (N))
6639 then
6640 exit;
6641
6642 -- Case of Import/Interface or the other way round
6643
6644 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
6645 Name_Import)
6646 then
6647 -- Here we know that we have Import and Interface. It
6648 -- doesn't matter which way round they are. See if
6649 -- they specify the same convention. If so, all OK,
6650 -- and set special flags to stop other messages
6651
6652 if Same_Convention (Decl) then
6653 Set_Import_Interface_Present (N);
6654 Set_Import_Interface_Present (Decl);
6655 Err := False;
6656
6657 -- If different conventions, special message
6658
6659 else
6660 Error_Msg_Sloc := Sloc (Decl);
6661 Error_Pragma_Arg
6662 ("convention differs from that given#", Arg1);
6663 return;
6664 end if;
6665 end if;
6666 end if;
6667
6668 Next (Decl);
6669 end loop;
6670 end if;
6671
6672 -- Give message if needed if we fall through those tests
6673 -- except on Relaxed_RM_Semantics where we let go: either this
6674 -- is a case accepted/ignored by other Ada compilers (e.g.
6675 -- a mix of Convention and Import), or another error will be
6676 -- generated later (e.g. using both Import and Export).
6677
6678 if Err and not Relaxed_RM_Semantics then
6679 Error_Pragma_Arg
6680 ("at most one Convention/Export/Import pragma is allowed",
6681 Arg2);
6682 end if;
6683 end Diagnose_Multiple_Pragmas;
6684
6685 --------------------------------
6686 -- Set_Convention_From_Pragma --
6687 --------------------------------
6688
6689 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6690 begin
6691 -- Ghost convention is allowed only for functions
6692
6693 if Ekind (E) /= E_Function and then C = Convention_Ghost then
6694 Error_Msg_N
6695 ("& may not have Ghost convention", E);
6696 Error_Msg_N
6697 ("\only functions are permitted to have Ghost convention",
6698 E);
6699 return;
6700 end if;
6701
6702 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6703 -- for an overridden dispatching operation. Technically this is
6704 -- an amendment and should only be done in Ada 2005 mode. However,
6705 -- this is clearly a mistake, since the problem that is addressed
6706 -- by this AI is that there is a clear gap in the RM.
6707
6708 if Is_Dispatching_Operation (E)
6709 and then Present (Overridden_Operation (E))
6710 and then C /= Convention (Overridden_Operation (E))
6711 then
6712 -- An attempt to override a function with a ghost function
6713 -- appears as a mismatch in conventions.
6714
6715 if C = Convention_Ghost then
6716 Error_Msg_N ("ghost function & cannot be overriding", E);
6717 else
6718 Error_Pragma_Arg
6719 ("cannot change convention for overridden dispatching "
6720 & "operation", Arg1);
6721 end if;
6722 end if;
6723
6724 -- Special checks for Convention_Stdcall
6725
6726 if C = Convention_Stdcall then
6727
6728 -- A dispatching call is not allowed. A dispatching subprogram
6729 -- cannot be used to interface to the Win32 API, so in fact
6730 -- this check does not impose any effective restriction.
6731
6732 if Is_Dispatching_Operation (E) then
6733 Error_Msg_Sloc := Sloc (E);
6734
6735 -- Note: make this unconditional so that if there is more
6736 -- than one call to which the pragma applies, we get a
6737 -- message for each call. Also don't use Error_Pragma,
6738 -- so that we get multiple messages.
6739
6740 Error_Msg_N
6741 ("dispatching subprogram# cannot use Stdcall convention!",
6742 Arg1);
6743
6744 -- Subprogram is allowed, but not a generic subprogram
6745
6746 elsif not Is_Subprogram (E)
6747 and then not Is_Generic_Subprogram (E)
6748
6749 -- A variable is OK
6750
6751 and then Ekind (E) /= E_Variable
6752
6753 -- An access to subprogram is also allowed
6754
6755 and then not
6756 (Is_Access_Type (E)
6757 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
6758
6759 -- Allow internal call to set convention of subprogram type
6760
6761 and then not (Ekind (E) = E_Subprogram_Type)
6762 then
6763 Error_Pragma_Arg
6764 ("second argument of pragma% must be subprogram (type)",
6765 Arg2);
6766 end if;
6767 end if;
6768
6769 -- Set the convention
6770
6771 Set_Convention (E, C);
6772 Set_Has_Convention_Pragma (E);
6773
6774 -- For the case of a record base type, also set the convention of
6775 -- any anonymous access types declared in the record which do not
6776 -- currently have a specified convention.
6777
6778 if Is_Record_Type (E) and then Is_Base_Type (E) then
6779 declare
6780 Comp : Node_Id;
6781
6782 begin
6783 Comp := First_Component (E);
6784 while Present (Comp) loop
6785 if Present (Etype (Comp))
6786 and then Ekind_In (Etype (Comp),
6787 E_Anonymous_Access_Type,
6788 E_Anonymous_Access_Subprogram_Type)
6789 and then not Has_Convention_Pragma (Comp)
6790 then
6791 Set_Convention (Comp, C);
6792 end if;
6793
6794 Next_Component (Comp);
6795 end loop;
6796 end;
6797 end if;
6798
6799 -- Deal with incomplete/private type case, where underlying type
6800 -- is available, so set convention of that underlying type.
6801
6802 if Is_Incomplete_Or_Private_Type (E)
6803 and then Present (Underlying_Type (E))
6804 then
6805 Set_Convention (Underlying_Type (E), C);
6806 Set_Has_Convention_Pragma (Underlying_Type (E), True);
6807 end if;
6808
6809 -- A class-wide type should inherit the convention of the specific
6810 -- root type (although this isn't specified clearly by the RM).
6811
6812 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
6813 Set_Convention (Class_Wide_Type (E), C);
6814 end if;
6815
6816 -- If the entity is a record type, then check for special case of
6817 -- C_Pass_By_Copy, which is treated the same as C except that the
6818 -- special record flag is set. This convention is only permitted
6819 -- on record types (see AI95-00131).
6820
6821 if Cname = Name_C_Pass_By_Copy then
6822 if Is_Record_Type (E) then
6823 Set_C_Pass_By_Copy (Base_Type (E));
6824 elsif Is_Incomplete_Or_Private_Type (E)
6825 and then Is_Record_Type (Underlying_Type (E))
6826 then
6827 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
6828 else
6829 Error_Pragma_Arg
6830 ("C_Pass_By_Copy convention allowed only for record type",
6831 Arg2);
6832 end if;
6833 end if;
6834
6835 -- If the entity is a derived boolean type, check for the special
6836 -- case of convention C, C++, or Fortran, where we consider any
6837 -- nonzero value to represent true.
6838
6839 if Is_Discrete_Type (E)
6840 and then Root_Type (Etype (E)) = Standard_Boolean
6841 and then
6842 (C = Convention_C
6843 or else
6844 C = Convention_CPP
6845 or else
6846 C = Convention_Fortran)
6847 then
6848 Set_Nonzero_Is_True (Base_Type (E));
6849 end if;
6850 end Set_Convention_From_Pragma;
6851
6852 -- Start of processing for Process_Convention
6853
6854 begin
6855 Check_At_Least_N_Arguments (2);
6856 Check_Optional_Identifier (Arg1, Name_Convention);
6857 Check_Arg_Is_Identifier (Arg1);
6858 Cname := Chars (Get_Pragma_Arg (Arg1));
6859
6860 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6861 -- tested again below to set the critical flag).
6862
6863 if Cname = Name_C_Pass_By_Copy then
6864 C := Convention_C;
6865
6866 -- Otherwise we must have something in the standard convention list
6867
6868 elsif Is_Convention_Name (Cname) then
6869 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
6870
6871 -- In DEC VMS, it seems that there is an undocumented feature that
6872 -- any unrecognized convention is treated as the default, which for
6873 -- us is convention C. It does not seem so terrible to do this
6874 -- unconditionally, silently in the VMS case, and with a warning
6875 -- in the non-VMS case.
6876
6877 else
6878 if Warn_On_Export_Import and not OpenVMS_On_Target then
6879 Error_Msg_N
6880 ("??unrecognized convention name, C assumed",
6881 Get_Pragma_Arg (Arg1));
6882 end if;
6883
6884 C := Convention_C;
6885 end if;
6886
6887 Check_Optional_Identifier (Arg2, Name_Entity);
6888 Check_Arg_Is_Local_Name (Arg2);
6889
6890 Id := Get_Pragma_Arg (Arg2);
6891 Analyze (Id);
6892
6893 if not Is_Entity_Name (Id) then
6894 Error_Pragma_Arg ("entity name required", Arg2);
6895 end if;
6896
6897 E := Entity (Id);
6898
6899 -- Set entity to return
6900
6901 Ent := E;
6902
6903 -- Ada_Pass_By_Copy special checking
6904
6905 if C = Convention_Ada_Pass_By_Copy then
6906 if not Is_First_Subtype (E) then
6907 Error_Pragma_Arg
6908 ("convention `Ada_Pass_By_Copy` only allowed for types",
6909 Arg2);
6910 end if;
6911
6912 if Is_By_Reference_Type (E) then
6913 Error_Pragma_Arg
6914 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6915 & "type", Arg1);
6916 end if;
6917 end if;
6918
6919 -- Ada_Pass_By_Reference special checking
6920
6921 if C = Convention_Ada_Pass_By_Reference then
6922 if not Is_First_Subtype (E) then
6923 Error_Pragma_Arg
6924 ("convention `Ada_Pass_By_Reference` only allowed for types",
6925 Arg2);
6926 end if;
6927
6928 if Is_By_Copy_Type (E) then
6929 Error_Pragma_Arg
6930 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6931 & "type", Arg1);
6932 end if;
6933 end if;
6934
6935 -- Ghost special checking
6936
6937 if Is_Ghost_Subprogram (E)
6938 and then Present (Overridden_Operation (E))
6939 then
6940 Error_Msg_N ("ghost function & cannot be overriding", E);
6941 end if;
6942
6943 -- Go to renamed subprogram if present, since convention applies to
6944 -- the actual renamed entity, not to the renaming entity. If the
6945 -- subprogram is inherited, go to parent subprogram.
6946
6947 if Is_Subprogram (E)
6948 and then Present (Alias (E))
6949 then
6950 if Nkind (Parent (Declaration_Node (E))) =
6951 N_Subprogram_Renaming_Declaration
6952 then
6953 if Scope (E) /= Scope (Alias (E)) then
6954 Error_Pragma_Ref
6955 ("cannot apply pragma% to non-local entity&#", E);
6956 end if;
6957
6958 E := Alias (E);
6959
6960 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6961 N_Private_Extension_Declaration)
6962 and then Scope (E) = Scope (Alias (E))
6963 then
6964 E := Alias (E);
6965
6966 -- Return the parent subprogram the entity was inherited from
6967
6968 Ent := E;
6969 end if;
6970 end if;
6971
6972 -- Check that we are not applying this to a specless body
6973 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
6974 -- compilers.
6975
6976 if Is_Subprogram (E)
6977 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6978 and then not Relaxed_RM_Semantics
6979 then
6980 Error_Pragma
6981 ("pragma% requires separate spec and must come before body");
6982 end if;
6983
6984 -- Check that we are not applying this to a named constant
6985
6986 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6987 Error_Msg_Name_1 := Pname;
6988 Error_Msg_N
6989 ("cannot apply pragma% to named constant!",
6990 Get_Pragma_Arg (Arg2));
6991 Error_Pragma_Arg
6992 ("\supply appropriate type for&!", Arg2);
6993 end if;
6994
6995 if Ekind (E) = E_Enumeration_Literal then
6996 Error_Pragma ("enumeration literal not allowed for pragma%");
6997 end if;
6998
6999 -- Check for rep item appearing too early or too late
7000
7001 if Etype (E) = Any_Type
7002 or else Rep_Item_Too_Early (E, N)
7003 then
7004 raise Pragma_Exit;
7005
7006 elsif Present (Underlying_Type (E)) then
7007 E := Underlying_Type (E);
7008 end if;
7009
7010 if Rep_Item_Too_Late (E, N) then
7011 raise Pragma_Exit;
7012 end if;
7013
7014 if Has_Convention_Pragma (E) then
7015 Diagnose_Multiple_Pragmas (E);
7016
7017 elsif Convention (E) = Convention_Protected
7018 or else Ekind (Scope (E)) = E_Protected_Type
7019 then
7020 Error_Pragma_Arg
7021 ("a protected operation cannot be given a different convention",
7022 Arg2);
7023 end if;
7024
7025 -- For Intrinsic, a subprogram is required
7026
7027 if C = Convention_Intrinsic
7028 and then not Is_Subprogram (E)
7029 and then not Is_Generic_Subprogram (E)
7030 then
7031 Error_Pragma_Arg
7032 ("second argument of pragma% must be a subprogram", Arg2);
7033 end if;
7034
7035 -- Deal with non-subprogram cases
7036
7037 if not Is_Subprogram (E)
7038 and then not Is_Generic_Subprogram (E)
7039 then
7040 Set_Convention_From_Pragma (E);
7041
7042 if Is_Type (E) then
7043 Check_First_Subtype (Arg2);
7044 Set_Convention_From_Pragma (Base_Type (E));
7045
7046 -- For access subprograms, we must set the convention on the
7047 -- internally generated directly designated type as well.
7048
7049 if Ekind (E) = E_Access_Subprogram_Type then
7050 Set_Convention_From_Pragma (Directly_Designated_Type (E));
7051 end if;
7052 end if;
7053
7054 -- For the subprogram case, set proper convention for all homonyms
7055 -- in same scope and the same declarative part, i.e. the same
7056 -- compilation unit.
7057
7058 else
7059 Comp_Unit := Get_Source_Unit (E);
7060 Set_Convention_From_Pragma (E);
7061
7062 -- Treat a pragma Import as an implicit body, and pragma import
7063 -- as implicit reference (for navigation in GPS).
7064
7065 if Prag_Id = Pragma_Import then
7066 Generate_Reference (E, Id, 'b');
7067
7068 -- For exported entities we restrict the generation of references
7069 -- to entities exported to foreign languages since entities
7070 -- exported to Ada do not provide further information to GPS and
7071 -- add undesired references to the output of the gnatxref tool.
7072
7073 elsif Prag_Id = Pragma_Export
7074 and then Convention (E) /= Convention_Ada
7075 then
7076 Generate_Reference (E, Id, 'i');
7077 end if;
7078
7079 -- If the pragma comes from from an aspect, it only applies to the
7080 -- given entity, not its homonyms.
7081
7082 if From_Aspect_Specification (N) then
7083 return;
7084 end if;
7085
7086 -- Otherwise Loop through the homonyms of the pragma argument's
7087 -- entity, an apply convention to those in the current scope.
7088
7089 E1 := Ent;
7090
7091 loop
7092 E1 := Homonym (E1);
7093 exit when No (E1) or else Scope (E1) /= Current_Scope;
7094
7095 -- Ignore entry for which convention is already set
7096
7097 if Has_Convention_Pragma (E1) then
7098 goto Continue;
7099 end if;
7100
7101 -- Do not set the pragma on inherited operations or on formal
7102 -- subprograms.
7103
7104 if Comes_From_Source (E1)
7105 and then Comp_Unit = Get_Source_Unit (E1)
7106 and then not Is_Formal_Subprogram (E1)
7107 and then Nkind (Original_Node (Parent (E1))) /=
7108 N_Full_Type_Declaration
7109 then
7110 if Present (Alias (E1))
7111 and then Scope (E1) /= Scope (Alias (E1))
7112 then
7113 Error_Pragma_Ref
7114 ("cannot apply pragma% to non-local entity& declared#",
7115 E1);
7116 end if;
7117
7118 Set_Convention_From_Pragma (E1);
7119
7120 if Prag_Id = Pragma_Import then
7121 Generate_Reference (E1, Id, 'b');
7122 end if;
7123 end if;
7124
7125 <<Continue>>
7126 null;
7127 end loop;
7128 end if;
7129 end Process_Convention;
7130
7131 ----------------------------------------
7132 -- Process_Disable_Enable_Atomic_Sync --
7133 ----------------------------------------
7134
7135 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7136 begin
7137 Check_No_Identifiers;
7138 Check_At_Most_N_Arguments (1);
7139
7140 -- Modeled internally as
7141 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7142
7143 Rewrite (N,
7144 Make_Pragma (Loc,
7145 Pragma_Identifier =>
7146 Make_Identifier (Loc, Nam),
7147 Pragma_Argument_Associations => New_List (
7148 Make_Pragma_Argument_Association (Loc,
7149 Expression =>
7150 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7151
7152 if Present (Arg1) then
7153 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7154 end if;
7155
7156 Analyze (N);
7157 end Process_Disable_Enable_Atomic_Sync;
7158
7159 -----------------------------------------------------
7160 -- Process_Extended_Import_Export_Exception_Pragma --
7161 -----------------------------------------------------
7162
7163 procedure Process_Extended_Import_Export_Exception_Pragma
7164 (Arg_Internal : Node_Id;
7165 Arg_External : Node_Id;
7166 Arg_Form : Node_Id;
7167 Arg_Code : Node_Id)
7168 is
7169 Def_Id : Entity_Id;
7170 Code_Val : Uint;
7171
7172 begin
7173 if not OpenVMS_On_Target then
7174 Error_Pragma
7175 ("??pragma% ignored (applies only to Open'V'M'S)");
7176 end if;
7177
7178 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7179 Def_Id := Entity (Arg_Internal);
7180
7181 if Ekind (Def_Id) /= E_Exception then
7182 Error_Pragma_Arg
7183 ("pragma% must refer to declared exception", Arg_Internal);
7184 end if;
7185
7186 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7187
7188 if Present (Arg_Form) then
7189 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
7190 end if;
7191
7192 if Present (Arg_Form)
7193 and then Chars (Arg_Form) = Name_Ada
7194 then
7195 null;
7196 else
7197 Set_Is_VMS_Exception (Def_Id);
7198 Set_Exception_Code (Def_Id, No_Uint);
7199 end if;
7200
7201 if Present (Arg_Code) then
7202 if not Is_VMS_Exception (Def_Id) then
7203 Error_Pragma_Arg
7204 ("Code option for pragma% not allowed for Ada case",
7205 Arg_Code);
7206 end if;
7207
7208 Check_Arg_Is_OK_Static_Expression (Arg_Code, Any_Integer);
7209 Code_Val := Expr_Value (Arg_Code);
7210
7211 if not UI_Is_In_Int_Range (Code_Val) then
7212 Error_Pragma_Arg
7213 ("Code option for pragma% must be in 32-bit range",
7214 Arg_Code);
7215
7216 else
7217 Set_Exception_Code (Def_Id, Code_Val);
7218 end if;
7219 end if;
7220 end Process_Extended_Import_Export_Exception_Pragma;
7221
7222 -------------------------------------------------
7223 -- Process_Extended_Import_Export_Internal_Arg --
7224 -------------------------------------------------
7225
7226 procedure Process_Extended_Import_Export_Internal_Arg
7227 (Arg_Internal : Node_Id := Empty)
7228 is
7229 begin
7230 if No (Arg_Internal) then
7231 Error_Pragma ("Internal parameter required for pragma%");
7232 end if;
7233
7234 if Nkind (Arg_Internal) = N_Identifier then
7235 null;
7236
7237 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7238 and then (Prag_Id = Pragma_Import_Function
7239 or else
7240 Prag_Id = Pragma_Export_Function)
7241 then
7242 null;
7243
7244 else
7245 Error_Pragma_Arg
7246 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7247 end if;
7248
7249 Check_Arg_Is_Local_Name (Arg_Internal);
7250 end Process_Extended_Import_Export_Internal_Arg;
7251
7252 --------------------------------------------------
7253 -- Process_Extended_Import_Export_Object_Pragma --
7254 --------------------------------------------------
7255
7256 procedure Process_Extended_Import_Export_Object_Pragma
7257 (Arg_Internal : Node_Id;
7258 Arg_External : Node_Id;
7259 Arg_Size : Node_Id)
7260 is
7261 Def_Id : Entity_Id;
7262
7263 begin
7264 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7265 Def_Id := Entity (Arg_Internal);
7266
7267 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7268 Error_Pragma_Arg
7269 ("pragma% must designate an object", Arg_Internal);
7270 end if;
7271
7272 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7273 or else
7274 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7275 then
7276 Error_Pragma_Arg
7277 ("previous Common/Psect_Object applies, pragma % not permitted",
7278 Arg_Internal);
7279 end if;
7280
7281 if Rep_Item_Too_Late (Def_Id, N) then
7282 raise Pragma_Exit;
7283 end if;
7284
7285 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7286
7287 if Present (Arg_Size) then
7288 Check_Arg_Is_External_Name (Arg_Size);
7289 end if;
7290
7291 -- Export_Object case
7292
7293 if Prag_Id = Pragma_Export_Object then
7294 if not Is_Library_Level_Entity (Def_Id) then
7295 Error_Pragma_Arg
7296 ("argument for pragma% must be library level entity",
7297 Arg_Internal);
7298 end if;
7299
7300 if Ekind (Current_Scope) = E_Generic_Package then
7301 Error_Pragma ("pragma& cannot appear in a generic unit");
7302 end if;
7303
7304 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7305 Error_Pragma_Arg
7306 ("exported object must have compile time known size",
7307 Arg_Internal);
7308 end if;
7309
7310 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7311 Error_Msg_N ("??duplicate Export_Object pragma", N);
7312 else
7313 Set_Exported (Def_Id, Arg_Internal);
7314 end if;
7315
7316 -- Import_Object case
7317
7318 else
7319 if Is_Concurrent_Type (Etype (Def_Id)) then
7320 Error_Pragma_Arg
7321 ("cannot use pragma% for task/protected object",
7322 Arg_Internal);
7323 end if;
7324
7325 if Ekind (Def_Id) = E_Constant then
7326 Error_Pragma_Arg
7327 ("cannot import a constant", Arg_Internal);
7328 end if;
7329
7330 if Warn_On_Export_Import
7331 and then Has_Discriminants (Etype (Def_Id))
7332 then
7333 Error_Msg_N
7334 ("imported value must be initialized??", Arg_Internal);
7335 end if;
7336
7337 if Warn_On_Export_Import
7338 and then Is_Access_Type (Etype (Def_Id))
7339 then
7340 Error_Pragma_Arg
7341 ("cannot import object of an access type??", Arg_Internal);
7342 end if;
7343
7344 if Warn_On_Export_Import
7345 and then Is_Imported (Def_Id)
7346 then
7347 Error_Msg_N ("??duplicate Import_Object pragma", N);
7348
7349 -- Check for explicit initialization present. Note that an
7350 -- initialization generated by the code generator, e.g. for an
7351 -- access type, does not count here.
7352
7353 elsif Present (Expression (Parent (Def_Id)))
7354 and then
7355 Comes_From_Source
7356 (Original_Node (Expression (Parent (Def_Id))))
7357 then
7358 Error_Msg_Sloc := Sloc (Def_Id);
7359 Error_Pragma_Arg
7360 ("imported entities cannot be initialized (RM B.1(24))",
7361 "\no initialization allowed for & declared#", Arg1);
7362 else
7363 Set_Imported (Def_Id);
7364 Note_Possible_Modification (Arg_Internal, Sure => False);
7365 end if;
7366 end if;
7367 end Process_Extended_Import_Export_Object_Pragma;
7368
7369 ------------------------------------------------------
7370 -- Process_Extended_Import_Export_Subprogram_Pragma --
7371 ------------------------------------------------------
7372
7373 procedure Process_Extended_Import_Export_Subprogram_Pragma
7374 (Arg_Internal : Node_Id;
7375 Arg_External : Node_Id;
7376 Arg_Parameter_Types : Node_Id;
7377 Arg_Result_Type : Node_Id := Empty;
7378 Arg_Mechanism : Node_Id;
7379 Arg_Result_Mechanism : Node_Id := Empty;
7380 Arg_First_Optional_Parameter : Node_Id := Empty)
7381 is
7382 Ent : Entity_Id;
7383 Def_Id : Entity_Id;
7384 Hom_Id : Entity_Id;
7385 Formal : Entity_Id;
7386 Ambiguous : Boolean;
7387 Match : Boolean;
7388 Dval : Node_Id;
7389
7390 function Same_Base_Type
7391 (Ptype : Node_Id;
7392 Formal : Entity_Id) return Boolean;
7393 -- Determines if Ptype references the type of Formal. Note that only
7394 -- the base types need to match according to the spec. Ptype here is
7395 -- the argument from the pragma, which is either a type name, or an
7396 -- access attribute.
7397
7398 --------------------
7399 -- Same_Base_Type --
7400 --------------------
7401
7402 function Same_Base_Type
7403 (Ptype : Node_Id;
7404 Formal : Entity_Id) return Boolean
7405 is
7406 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
7407 Pref : Node_Id;
7408
7409 begin
7410 -- Case where pragma argument is typ'Access
7411
7412 if Nkind (Ptype) = N_Attribute_Reference
7413 and then Attribute_Name (Ptype) = Name_Access
7414 then
7415 Pref := Prefix (Ptype);
7416 Find_Type (Pref);
7417
7418 if not Is_Entity_Name (Pref)
7419 or else Entity (Pref) = Any_Type
7420 then
7421 raise Pragma_Exit;
7422 end if;
7423
7424 -- We have a match if the corresponding argument is of an
7425 -- anonymous access type, and its designated type matches the
7426 -- type of the prefix of the access attribute
7427
7428 return Ekind (Ftyp) = E_Anonymous_Access_Type
7429 and then Base_Type (Entity (Pref)) =
7430 Base_Type (Etype (Designated_Type (Ftyp)));
7431
7432 -- Case where pragma argument is a type name
7433
7434 else
7435 Find_Type (Ptype);
7436
7437 if not Is_Entity_Name (Ptype)
7438 or else Entity (Ptype) = Any_Type
7439 then
7440 raise Pragma_Exit;
7441 end if;
7442
7443 -- We have a match if the corresponding argument is of the type
7444 -- given in the pragma (comparing base types)
7445
7446 return Base_Type (Entity (Ptype)) = Ftyp;
7447 end if;
7448 end Same_Base_Type;
7449
7450 -- Start of processing for
7451 -- Process_Extended_Import_Export_Subprogram_Pragma
7452
7453 begin
7454 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7455 Ent := Empty;
7456 Ambiguous := False;
7457
7458 -- Loop through homonyms (overloadings) of the entity
7459
7460 Hom_Id := Entity (Arg_Internal);
7461 while Present (Hom_Id) loop
7462 Def_Id := Get_Base_Subprogram (Hom_Id);
7463
7464 -- We need a subprogram in the current scope
7465
7466 if not Is_Subprogram (Def_Id)
7467 or else Scope (Def_Id) /= Current_Scope
7468 then
7469 null;
7470
7471 else
7472 Match := True;
7473
7474 -- Pragma cannot apply to subprogram body
7475
7476 if Is_Subprogram (Def_Id)
7477 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7478 N_Subprogram_Body
7479 then
7480 Error_Pragma
7481 ("pragma% requires separate spec"
7482 & " and must come before body");
7483 end if;
7484
7485 -- Test result type if given, note that the result type
7486 -- parameter can only be present for the function cases.
7487
7488 if Present (Arg_Result_Type)
7489 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7490 then
7491 Match := False;
7492
7493 elsif Etype (Def_Id) /= Standard_Void_Type
7494 and then
7495 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
7496 then
7497 Match := False;
7498
7499 -- Test parameter types if given. Note that this parameter
7500 -- has not been analyzed (and must not be, since it is
7501 -- semantic nonsense), so we get it as the parser left it.
7502
7503 elsif Present (Arg_Parameter_Types) then
7504 Check_Matching_Types : declare
7505 Formal : Entity_Id;
7506 Ptype : Node_Id;
7507
7508 begin
7509 Formal := First_Formal (Def_Id);
7510
7511 if Nkind (Arg_Parameter_Types) = N_Null then
7512 if Present (Formal) then
7513 Match := False;
7514 end if;
7515
7516 -- A list of one type, e.g. (List) is parsed as
7517 -- a parenthesized expression.
7518
7519 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7520 and then Paren_Count (Arg_Parameter_Types) = 1
7521 then
7522 if No (Formal)
7523 or else Present (Next_Formal (Formal))
7524 then
7525 Match := False;
7526 else
7527 Match :=
7528 Same_Base_Type (Arg_Parameter_Types, Formal);
7529 end if;
7530
7531 -- A list of more than one type is parsed as a aggregate
7532
7533 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7534 and then Paren_Count (Arg_Parameter_Types) = 0
7535 then
7536 Ptype := First (Expressions (Arg_Parameter_Types));
7537 while Present (Ptype) or else Present (Formal) loop
7538 if No (Ptype)
7539 or else No (Formal)
7540 or else not Same_Base_Type (Ptype, Formal)
7541 then
7542 Match := False;
7543 exit;
7544 else
7545 Next_Formal (Formal);
7546 Next (Ptype);
7547 end if;
7548 end loop;
7549
7550 -- Anything else is of the wrong form
7551
7552 else
7553 Error_Pragma_Arg
7554 ("wrong form for Parameter_Types parameter",
7555 Arg_Parameter_Types);
7556 end if;
7557 end Check_Matching_Types;
7558 end if;
7559
7560 -- Match is now False if the entry we found did not match
7561 -- either a supplied Parameter_Types or Result_Types argument
7562
7563 if Match then
7564 if No (Ent) then
7565 Ent := Def_Id;
7566
7567 -- Ambiguous case, the flag Ambiguous shows if we already
7568 -- detected this and output the initial messages.
7569
7570 else
7571 if not Ambiguous then
7572 Ambiguous := True;
7573 Error_Msg_Name_1 := Pname;
7574 Error_Msg_N
7575 ("pragma% does not uniquely identify subprogram!",
7576 N);
7577 Error_Msg_Sloc := Sloc (Ent);
7578 Error_Msg_N ("matching subprogram #!", N);
7579 Ent := Empty;
7580 end if;
7581
7582 Error_Msg_Sloc := Sloc (Def_Id);
7583 Error_Msg_N ("matching subprogram #!", N);
7584 end if;
7585 end if;
7586 end if;
7587
7588 Hom_Id := Homonym (Hom_Id);
7589 end loop;
7590
7591 -- See if we found an entry
7592
7593 if No (Ent) then
7594 if not Ambiguous then
7595 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7596 Error_Pragma
7597 ("pragma% cannot be given for generic subprogram");
7598 else
7599 Error_Pragma
7600 ("pragma% does not identify local subprogram");
7601 end if;
7602 end if;
7603
7604 return;
7605 end if;
7606
7607 -- Import pragmas must be for imported entities
7608
7609 if Prag_Id = Pragma_Import_Function
7610 or else
7611 Prag_Id = Pragma_Import_Procedure
7612 or else
7613 Prag_Id = Pragma_Import_Valued_Procedure
7614 then
7615 if not Is_Imported (Ent) then
7616 Error_Pragma
7617 ("pragma Import or Interface must precede pragma%");
7618 end if;
7619
7620 -- Here we have the Export case which can set the entity as exported
7621
7622 -- But does not do so if the specified external name is null, since
7623 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7624 -- compatible) to request no external name.
7625
7626 elsif Nkind (Arg_External) = N_String_Literal
7627 and then String_Length (Strval (Arg_External)) = 0
7628 then
7629 null;
7630
7631 -- In all other cases, set entity as exported
7632
7633 else
7634 Set_Exported (Ent, Arg_Internal);
7635 end if;
7636
7637 -- Special processing for Valued_Procedure cases
7638
7639 if Prag_Id = Pragma_Import_Valued_Procedure
7640 or else
7641 Prag_Id = Pragma_Export_Valued_Procedure
7642 then
7643 Formal := First_Formal (Ent);
7644
7645 if No (Formal) then
7646 Error_Pragma ("at least one parameter required for pragma%");
7647
7648 elsif Ekind (Formal) /= E_Out_Parameter then
7649 Error_Pragma ("first parameter must have mode out for pragma%");
7650
7651 else
7652 Set_Is_Valued_Procedure (Ent);
7653 end if;
7654 end if;
7655
7656 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7657
7658 -- Process Result_Mechanism argument if present. We have already
7659 -- checked that this is only allowed for the function case.
7660
7661 if Present (Arg_Result_Mechanism) then
7662 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
7663 end if;
7664
7665 -- Process Mechanism parameter if present. Note that this parameter
7666 -- is not analyzed, and must not be analyzed since it is semantic
7667 -- nonsense, so we get it in exactly as the parser left it.
7668
7669 if Present (Arg_Mechanism) then
7670 declare
7671 Formal : Entity_Id;
7672 Massoc : Node_Id;
7673 Mname : Node_Id;
7674 Choice : Node_Id;
7675
7676 begin
7677 -- A single mechanism association without a formal parameter
7678 -- name is parsed as a parenthesized expression. All other
7679 -- cases are parsed as aggregates, so we rewrite the single
7680 -- parameter case as an aggregate for consistency.
7681
7682 if Nkind (Arg_Mechanism) /= N_Aggregate
7683 and then Paren_Count (Arg_Mechanism) = 1
7684 then
7685 Rewrite (Arg_Mechanism,
7686 Make_Aggregate (Sloc (Arg_Mechanism),
7687 Expressions => New_List (
7688 Relocate_Node (Arg_Mechanism))));
7689 end if;
7690
7691 -- Case of only mechanism name given, applies to all formals
7692
7693 if Nkind (Arg_Mechanism) /= N_Aggregate then
7694 Formal := First_Formal (Ent);
7695 while Present (Formal) loop
7696 Set_Mechanism_Value (Formal, Arg_Mechanism);
7697 Next_Formal (Formal);
7698 end loop;
7699
7700 -- Case of list of mechanism associations given
7701
7702 else
7703 if Null_Record_Present (Arg_Mechanism) then
7704 Error_Pragma_Arg
7705 ("inappropriate form for Mechanism parameter",
7706 Arg_Mechanism);
7707 end if;
7708
7709 -- Deal with positional ones first
7710
7711 Formal := First_Formal (Ent);
7712
7713 if Present (Expressions (Arg_Mechanism)) then
7714 Mname := First (Expressions (Arg_Mechanism));
7715 while Present (Mname) loop
7716 if No (Formal) then
7717 Error_Pragma_Arg
7718 ("too many mechanism associations", Mname);
7719 end if;
7720
7721 Set_Mechanism_Value (Formal, Mname);
7722 Next_Formal (Formal);
7723 Next (Mname);
7724 end loop;
7725 end if;
7726
7727 -- Deal with named entries
7728
7729 if Present (Component_Associations (Arg_Mechanism)) then
7730 Massoc := First (Component_Associations (Arg_Mechanism));
7731 while Present (Massoc) loop
7732 Choice := First (Choices (Massoc));
7733
7734 if Nkind (Choice) /= N_Identifier
7735 or else Present (Next (Choice))
7736 then
7737 Error_Pragma_Arg
7738 ("incorrect form for mechanism association",
7739 Massoc);
7740 end if;
7741
7742 Formal := First_Formal (Ent);
7743 loop
7744 if No (Formal) then
7745 Error_Pragma_Arg
7746 ("parameter name & not present", Choice);
7747 end if;
7748
7749 if Chars (Choice) = Chars (Formal) then
7750 Set_Mechanism_Value
7751 (Formal, Expression (Massoc));
7752
7753 -- Set entity on identifier (needed by ASIS)
7754
7755 Set_Entity (Choice, Formal);
7756
7757 exit;
7758 end if;
7759
7760 Next_Formal (Formal);
7761 end loop;
7762
7763 Next (Massoc);
7764 end loop;
7765 end if;
7766 end if;
7767 end;
7768 end if;
7769
7770 -- Process First_Optional_Parameter argument if present. We have
7771 -- already checked that this is only allowed for the Import case.
7772
7773 if Present (Arg_First_Optional_Parameter) then
7774 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
7775 Error_Pragma_Arg
7776 ("first optional parameter must be formal parameter name",
7777 Arg_First_Optional_Parameter);
7778 end if;
7779
7780 Formal := First_Formal (Ent);
7781 loop
7782 if No (Formal) then
7783 Error_Pragma_Arg
7784 ("specified formal parameter& not found",
7785 Arg_First_Optional_Parameter);
7786 end if;
7787
7788 exit when Chars (Formal) =
7789 Chars (Arg_First_Optional_Parameter);
7790
7791 Next_Formal (Formal);
7792 end loop;
7793
7794 Set_First_Optional_Parameter (Ent, Formal);
7795
7796 -- Check specified and all remaining formals have right form
7797
7798 while Present (Formal) loop
7799 if Ekind (Formal) /= E_In_Parameter then
7800 Error_Msg_NE
7801 ("optional formal& is not of mode in!",
7802 Arg_First_Optional_Parameter, Formal);
7803
7804 else
7805 Dval := Default_Value (Formal);
7806
7807 if No (Dval) then
7808 Error_Msg_NE
7809 ("optional formal& does not have default value!",
7810 Arg_First_Optional_Parameter, Formal);
7811
7812 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
7813 null;
7814
7815 else
7816 Error_Msg_FE
7817 ("default value for optional formal& is non-static!",
7818 Arg_First_Optional_Parameter, Formal);
7819 end if;
7820 end if;
7821
7822 Set_Is_Optional_Parameter (Formal);
7823 Next_Formal (Formal);
7824 end loop;
7825 end if;
7826 end Process_Extended_Import_Export_Subprogram_Pragma;
7827
7828 --------------------------
7829 -- Process_Generic_List --
7830 --------------------------
7831
7832 procedure Process_Generic_List is
7833 Arg : Node_Id;
7834 Exp : Node_Id;
7835
7836 begin
7837 Check_No_Identifiers;
7838 Check_At_Least_N_Arguments (1);
7839
7840 -- Check all arguments are names of generic units or instances
7841
7842 Arg := Arg1;
7843 while Present (Arg) loop
7844 Exp := Get_Pragma_Arg (Arg);
7845 Analyze (Exp);
7846
7847 if not Is_Entity_Name (Exp)
7848 or else
7849 (not Is_Generic_Instance (Entity (Exp))
7850 and then
7851 not Is_Generic_Unit (Entity (Exp)))
7852 then
7853 Error_Pragma_Arg
7854 ("pragma% argument must be name of generic unit/instance",
7855 Arg);
7856 end if;
7857
7858 Next (Arg);
7859 end loop;
7860 end Process_Generic_List;
7861
7862 ------------------------------------
7863 -- Process_Import_Predefined_Type --
7864 ------------------------------------
7865
7866 procedure Process_Import_Predefined_Type is
7867 Loc : constant Source_Ptr := Sloc (N);
7868 Elmt : Elmt_Id;
7869 Ftyp : Node_Id := Empty;
7870 Decl : Node_Id;
7871 Def : Node_Id;
7872 Nam : Name_Id;
7873
7874 begin
7875 String_To_Name_Buffer (Strval (Expression (Arg3)));
7876 Nam := Name_Find;
7877
7878 Elmt := First_Elmt (Predefined_Float_Types);
7879 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7880 Next_Elmt (Elmt);
7881 end loop;
7882
7883 Ftyp := Node (Elmt);
7884
7885 if Present (Ftyp) then
7886
7887 -- Don't build a derived type declaration, because predefined C
7888 -- types have no declaration anywhere, so cannot really be named.
7889 -- Instead build a full type declaration, starting with an
7890 -- appropriate type definition is built
7891
7892 if Is_Floating_Point_Type (Ftyp) then
7893 Def := Make_Floating_Point_Definition (Loc,
7894 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
7895 Make_Real_Range_Specification (Loc,
7896 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
7897 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
7898
7899 -- Should never have a predefined type we cannot handle
7900
7901 else
7902 raise Program_Error;
7903 end if;
7904
7905 -- Build and insert a Full_Type_Declaration, which will be
7906 -- analyzed as soon as this list entry has been analyzed.
7907
7908 Decl := Make_Full_Type_Declaration (Loc,
7909 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7910 Type_Definition => Def);
7911
7912 Insert_After (N, Decl);
7913 Mark_Rewrite_Insertion (Decl);
7914
7915 else
7916 Error_Pragma_Arg ("no matching type found for pragma%",
7917 Arg2);
7918 end if;
7919 end Process_Import_Predefined_Type;
7920
7921 ---------------------------------
7922 -- Process_Import_Or_Interface --
7923 ---------------------------------
7924
7925 procedure Process_Import_Or_Interface is
7926 C : Convention_Id;
7927 Def_Id : Entity_Id;
7928 Hom_Id : Entity_Id;
7929
7930 begin
7931 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7932 -- pragma Import (Entity, "external name");
7933
7934 if Relaxed_RM_Semantics
7935 and then Arg_Count = 2
7936 and then Prag_Id = Pragma_Import
7937 and then Nkind (Expression (Arg2)) = N_String_Literal
7938 then
7939 C := Convention_C;
7940 Def_Id := Get_Pragma_Arg (Arg1);
7941 Analyze (Def_Id);
7942
7943 if not Is_Entity_Name (Def_Id) then
7944 Error_Pragma_Arg ("entity name required", Arg1);
7945 end if;
7946
7947 Def_Id := Entity (Def_Id);
7948 Kill_Size_Check_Code (Def_Id);
7949 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
7950
7951 else
7952 Process_Convention (C, Def_Id);
7953 Kill_Size_Check_Code (Def_Id);
7954 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7955 end if;
7956
7957 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7958
7959 -- We do not permit Import to apply to a renaming declaration
7960
7961 if Present (Renamed_Object (Def_Id)) then
7962 Error_Pragma_Arg
7963 ("pragma% not allowed for object renaming", Arg2);
7964
7965 -- User initialization is not allowed for imported object, but
7966 -- the object declaration may contain a default initialization,
7967 -- that will be discarded. Note that an explicit initialization
7968 -- only counts if it comes from source, otherwise it is simply
7969 -- the code generator making an implicit initialization explicit.
7970
7971 elsif Present (Expression (Parent (Def_Id)))
7972 and then Comes_From_Source (Expression (Parent (Def_Id)))
7973 then
7974 Error_Msg_Sloc := Sloc (Def_Id);
7975 Error_Pragma_Arg
7976 ("no initialization allowed for declaration of& #",
7977 "\imported entities cannot be initialized (RM B.1(24))",
7978 Arg2);
7979
7980 else
7981 Set_Imported (Def_Id);
7982 Process_Interface_Name (Def_Id, Arg3, Arg4);
7983
7984 -- Note that we do not set Is_Public here. That's because we
7985 -- only want to set it if there is no address clause, and we
7986 -- don't know that yet, so we delay that processing till
7987 -- freeze time.
7988
7989 -- pragma Import completes deferred constants
7990
7991 if Ekind (Def_Id) = E_Constant then
7992 Set_Has_Completion (Def_Id);
7993 end if;
7994
7995 -- It is not possible to import a constant of an unconstrained
7996 -- array type (e.g. string) because there is no simple way to
7997 -- write a meaningful subtype for it.
7998
7999 if Is_Array_Type (Etype (Def_Id))
8000 and then not Is_Constrained (Etype (Def_Id))
8001 then
8002 Error_Msg_NE
8003 ("imported constant& must have a constrained subtype",
8004 N, Def_Id);
8005 end if;
8006 end if;
8007
8008 elsif Is_Subprogram (Def_Id)
8009 or else Is_Generic_Subprogram (Def_Id)
8010 then
8011 -- If the name is overloaded, pragma applies to all of the denoted
8012 -- entities in the same declarative part, unless the pragma comes
8013 -- from an aspect specification or was generated by the compiler
8014 -- (such as for pragma Provide_Shift_Operators).
8015
8016 Hom_Id := Def_Id;
8017 while Present (Hom_Id) loop
8018
8019 Def_Id := Get_Base_Subprogram (Hom_Id);
8020
8021 -- Ignore inherited subprograms because the pragma will apply
8022 -- to the parent operation, which is the one called.
8023
8024 if Is_Overloadable (Def_Id)
8025 and then Present (Alias (Def_Id))
8026 then
8027 null;
8028
8029 -- If it is not a subprogram, it must be in an outer scope and
8030 -- pragma does not apply.
8031
8032 elsif not Is_Subprogram (Def_Id)
8033 and then not Is_Generic_Subprogram (Def_Id)
8034 then
8035 null;
8036
8037 -- The pragma does not apply to primitives of interfaces
8038
8039 elsif Is_Dispatching_Operation (Def_Id)
8040 and then Present (Find_Dispatching_Type (Def_Id))
8041 and then Is_Interface (Find_Dispatching_Type (Def_Id))
8042 then
8043 null;
8044
8045 -- Verify that the homonym is in the same declarative part (not
8046 -- just the same scope). If the pragma comes from an aspect
8047 -- specification we know that it is part of the declaration.
8048
8049 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
8050 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8051 and then not From_Aspect_Specification (N)
8052 then
8053 exit;
8054
8055 else
8056 Set_Imported (Def_Id);
8057
8058 -- Reject an Import applied to an abstract subprogram
8059
8060 if Is_Subprogram (Def_Id)
8061 and then Is_Abstract_Subprogram (Def_Id)
8062 then
8063 Error_Msg_Sloc := Sloc (Def_Id);
8064 Error_Msg_NE
8065 ("cannot import abstract subprogram& declared#",
8066 Arg2, Def_Id);
8067 end if;
8068
8069 -- Special processing for Convention_Intrinsic
8070
8071 if C = Convention_Intrinsic then
8072
8073 -- Link_Name argument not allowed for intrinsic
8074
8075 Check_No_Link_Name;
8076
8077 Set_Is_Intrinsic_Subprogram (Def_Id);
8078
8079 -- If no external name is present, then check that this
8080 -- is a valid intrinsic subprogram. If an external name
8081 -- is present, then this is handled by the back end.
8082
8083 if No (Arg3) then
8084 Check_Intrinsic_Subprogram
8085 (Def_Id, Get_Pragma_Arg (Arg2));
8086 end if;
8087 end if;
8088
8089 -- Verify that the subprogram does not have a completion
8090 -- through a renaming declaration. For other completions the
8091 -- pragma appears as a too late representation.
8092
8093 declare
8094 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
8095
8096 begin
8097 if Present (Decl)
8098 and then Nkind (Decl) = N_Subprogram_Declaration
8099 and then Present (Corresponding_Body (Decl))
8100 and then Nkind (Unit_Declaration_Node
8101 (Corresponding_Body (Decl))) =
8102 N_Subprogram_Renaming_Declaration
8103 then
8104 Error_Msg_Sloc := Sloc (Def_Id);
8105 Error_Msg_NE
8106 ("cannot import&, renaming already provided for "
8107 & "declaration #", N, Def_Id);
8108 end if;
8109 end;
8110
8111 Set_Has_Completion (Def_Id);
8112 Process_Interface_Name (Def_Id, Arg3, Arg4);
8113 end if;
8114
8115 if Is_Compilation_Unit (Hom_Id) then
8116
8117 -- Its possible homonyms are not affected by the pragma.
8118 -- Such homonyms might be present in the context of other
8119 -- units being compiled.
8120
8121 exit;
8122
8123 elsif From_Aspect_Specification (N) then
8124 exit;
8125
8126 -- If the pragma was created by the compiler, then we don't
8127 -- want it to apply to other homonyms. This kind of case can
8128 -- occur when using pragma Provide_Shift_Operators, which
8129 -- generates implicit shift and rotate operators with Import
8130 -- pragmas that might apply to earlier explicit or implicit
8131 -- declarations marked with Import (for example, coming from
8132 -- an earlier pragma Provide_Shift_Operators for another type),
8133 -- and we don't generally want other homonyms being treated
8134 -- as imported or the pragma flagged as an illegal duplicate.
8135
8136 elsif not Comes_From_Source (N) then
8137 exit;
8138
8139 else
8140 Hom_Id := Homonym (Hom_Id);
8141 end if;
8142 end loop;
8143
8144 -- When the convention is Java or CIL, we also allow Import to
8145 -- be given for packages, generic packages, exceptions, record
8146 -- components, and access to subprograms.
8147
8148 elsif (C = Convention_Java or else C = Convention_CIL)
8149 and then
8150 (Is_Package_Or_Generic_Package (Def_Id)
8151 or else Ekind (Def_Id) = E_Exception
8152 or else Ekind (Def_Id) = E_Access_Subprogram_Type
8153 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
8154 then
8155 Set_Imported (Def_Id);
8156 Set_Is_Public (Def_Id);
8157 Process_Interface_Name (Def_Id, Arg3, Arg4);
8158
8159 -- Import a CPP class
8160
8161 elsif C = Convention_CPP
8162 and then (Is_Record_Type (Def_Id)
8163 or else Ekind (Def_Id) = E_Incomplete_Type)
8164 then
8165 if Ekind (Def_Id) = E_Incomplete_Type then
8166 if Present (Full_View (Def_Id)) then
8167 Def_Id := Full_View (Def_Id);
8168
8169 else
8170 Error_Msg_N
8171 ("cannot import 'C'P'P type before full declaration seen",
8172 Get_Pragma_Arg (Arg2));
8173
8174 -- Although we have reported the error we decorate it as
8175 -- CPP_Class to avoid reporting spurious errors
8176
8177 Set_Is_CPP_Class (Def_Id);
8178 return;
8179 end if;
8180 end if;
8181
8182 -- Types treated as CPP classes must be declared limited (note:
8183 -- this used to be a warning but there is no real benefit to it
8184 -- since we did effectively intend to treat the type as limited
8185 -- anyway).
8186
8187 if not Is_Limited_Type (Def_Id) then
8188 Error_Msg_N
8189 ("imported 'C'P'P type must be limited",
8190 Get_Pragma_Arg (Arg2));
8191 end if;
8192
8193 if Etype (Def_Id) /= Def_Id
8194 and then not Is_CPP_Class (Root_Type (Def_Id))
8195 then
8196 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8197 end if;
8198
8199 Set_Is_CPP_Class (Def_Id);
8200
8201 -- Imported CPP types must not have discriminants (because C++
8202 -- classes do not have discriminants).
8203
8204 if Has_Discriminants (Def_Id) then
8205 Error_Msg_N
8206 ("imported 'C'P'P type cannot have discriminants",
8207 First (Discriminant_Specifications
8208 (Declaration_Node (Def_Id))));
8209 end if;
8210
8211 -- Check that components of imported CPP types do not have default
8212 -- expressions. For private types this check is performed when the
8213 -- full view is analyzed (see Process_Full_View).
8214
8215 if not Is_Private_Type (Def_Id) then
8216 Check_CPP_Type_Has_No_Defaults (Def_Id);
8217 end if;
8218
8219 -- Import a CPP exception
8220
8221 elsif C = Convention_CPP
8222 and then Ekind (Def_Id) = E_Exception
8223 then
8224 if No (Arg3) then
8225 Error_Pragma_Arg
8226 ("'External_'Name arguments is required for 'Cpp exception",
8227 Arg3);
8228 else
8229 -- As only a string is allowed, Check_Arg_Is_External_Name
8230 -- isn't called.
8231
8232 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8233 end if;
8234
8235 if Present (Arg4) then
8236 Error_Pragma_Arg
8237 ("Link_Name argument not allowed for imported Cpp exception",
8238 Arg4);
8239 end if;
8240
8241 -- Do not call Set_Interface_Name as the name of the exception
8242 -- shouldn't be modified (and in particular it shouldn't be
8243 -- the External_Name). For exceptions, the External_Name is the
8244 -- name of the RTTI structure.
8245
8246 -- ??? Emit an error if pragma Import/Export_Exception is present
8247
8248 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8249 Check_No_Link_Name;
8250 Check_Arg_Count (3);
8251 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8252
8253 Process_Import_Predefined_Type;
8254
8255 else
8256 Error_Pragma_Arg
8257 ("second argument of pragma% must be object, subprogram "
8258 & "or incomplete type",
8259 Arg2);
8260 end if;
8261
8262 -- If this pragma applies to a compilation unit, then the unit, which
8263 -- is a subprogram, does not require (or allow) a body. We also do
8264 -- not need to elaborate imported procedures.
8265
8266 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8267 declare
8268 Cunit : constant Node_Id := Parent (Parent (N));
8269 begin
8270 Set_Body_Required (Cunit, False);
8271 end;
8272 end if;
8273 end Process_Import_Or_Interface;
8274
8275 --------------------
8276 -- Process_Inline --
8277 --------------------
8278
8279 procedure Process_Inline (Status : Inline_Status) is
8280 Assoc : Node_Id;
8281 Decl : Node_Id;
8282 Subp_Id : Node_Id;
8283 Subp : Entity_Id;
8284 Applies : Boolean;
8285
8286 Effective : Boolean := False;
8287 -- Set True if inline has some effect, i.e. if there is at least one
8288 -- subprogram set as inlined as a result of the use of the pragma.
8289
8290 procedure Make_Inline (Subp : Entity_Id);
8291 -- Subp is the defining unit name of the subprogram declaration. Set
8292 -- the flag, as well as the flag in the corresponding body, if there
8293 -- is one present.
8294
8295 procedure Set_Inline_Flags (Subp : Entity_Id);
8296 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8297 -- Has_Pragma_Inline_Always for the Inline_Always case.
8298
8299 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
8300 -- Returns True if it can be determined at this stage that inlining
8301 -- is not possible, for example if the body is available and contains
8302 -- exception handlers, we prevent inlining, since otherwise we can
8303 -- get undefined symbols at link time. This function also emits a
8304 -- warning if front-end inlining is enabled and the pragma appears
8305 -- too late.
8306 --
8307 -- ??? is business with link symbols still valid, or does it relate
8308 -- to front end ZCX which is being phased out ???
8309
8310 ---------------------------
8311 -- Inlining_Not_Possible --
8312 ---------------------------
8313
8314 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8315 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
8316 Stats : Node_Id;
8317
8318 begin
8319 if Nkind (Decl) = N_Subprogram_Body then
8320 Stats := Handled_Statement_Sequence (Decl);
8321 return Present (Exception_Handlers (Stats))
8322 or else Present (At_End_Proc (Stats));
8323
8324 elsif Nkind (Decl) = N_Subprogram_Declaration
8325 and then Present (Corresponding_Body (Decl))
8326 then
8327 if Front_End_Inlining
8328 and then Analyzed (Corresponding_Body (Decl))
8329 then
8330 Error_Msg_N ("pragma appears too late, ignored??", N);
8331 return True;
8332
8333 -- If the subprogram is a renaming as body, the body is just a
8334 -- call to the renamed subprogram, and inlining is trivially
8335 -- possible.
8336
8337 elsif
8338 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8339 N_Subprogram_Renaming_Declaration
8340 then
8341 return False;
8342
8343 else
8344 Stats :=
8345 Handled_Statement_Sequence
8346 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8347
8348 return
8349 Present (Exception_Handlers (Stats))
8350 or else Present (At_End_Proc (Stats));
8351 end if;
8352
8353 else
8354 -- If body is not available, assume the best, the check is
8355 -- performed again when compiling enclosing package bodies.
8356
8357 return False;
8358 end if;
8359 end Inlining_Not_Possible;
8360
8361 -----------------
8362 -- Make_Inline --
8363 -----------------
8364
8365 procedure Make_Inline (Subp : Entity_Id) is
8366 Kind : constant Entity_Kind := Ekind (Subp);
8367 Inner_Subp : Entity_Id := Subp;
8368
8369 begin
8370 -- Ignore if bad type, avoid cascaded error
8371
8372 if Etype (Subp) = Any_Type then
8373 Applies := True;
8374 return;
8375
8376 -- Ignore if all inlining is suppressed
8377
8378 elsif Suppress_All_Inlining then
8379 Applies := True;
8380 return;
8381
8382 -- If inlining is not possible, for now do not treat as an error
8383
8384 elsif Status /= Suppressed
8385 and then Inlining_Not_Possible (Subp)
8386 then
8387 Applies := True;
8388 return;
8389
8390 -- Here we have a candidate for inlining, but we must exclude
8391 -- derived operations. Otherwise we would end up trying to inline
8392 -- a phantom declaration, and the result would be to drag in a
8393 -- body which has no direct inlining associated with it. That
8394 -- would not only be inefficient but would also result in the
8395 -- backend doing cross-unit inlining in cases where it was
8396 -- definitely inappropriate to do so.
8397
8398 -- However, a simple Comes_From_Source test is insufficient, since
8399 -- we do want to allow inlining of generic instances which also do
8400 -- not come from source. We also need to recognize specs generated
8401 -- by the front-end for bodies that carry the pragma. Finally,
8402 -- predefined operators do not come from source but are not
8403 -- inlineable either.
8404
8405 elsif Is_Generic_Instance (Subp)
8406 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8407 then
8408 null;
8409
8410 elsif not Comes_From_Source (Subp)
8411 and then Scope (Subp) /= Standard_Standard
8412 then
8413 Applies := True;
8414 return;
8415 end if;
8416
8417 -- The referenced entity must either be the enclosing entity, or
8418 -- an entity declared within the current open scope.
8419
8420 if Present (Scope (Subp))
8421 and then Scope (Subp) /= Current_Scope
8422 and then Subp /= Current_Scope
8423 then
8424 Error_Pragma_Arg
8425 ("argument of% must be entity in current scope", Assoc);
8426 return;
8427 end if;
8428
8429 -- Processing for procedure, operator or function. If subprogram
8430 -- is aliased (as for an instance) indicate that the renamed
8431 -- entity (if declared in the same unit) is inlined.
8432
8433 if Is_Subprogram (Subp) then
8434 Inner_Subp := Ultimate_Alias (Inner_Subp);
8435
8436 if In_Same_Source_Unit (Subp, Inner_Subp) then
8437 Set_Inline_Flags (Inner_Subp);
8438
8439 Decl := Parent (Parent (Inner_Subp));
8440
8441 if Nkind (Decl) = N_Subprogram_Declaration
8442 and then Present (Corresponding_Body (Decl))
8443 then
8444 Set_Inline_Flags (Corresponding_Body (Decl));
8445
8446 elsif Is_Generic_Instance (Subp) then
8447
8448 -- Indicate that the body needs to be created for
8449 -- inlining subsequent calls. The instantiation node
8450 -- follows the declaration of the wrapper package
8451 -- created for it.
8452
8453 if Scope (Subp) /= Standard_Standard
8454 and then
8455 Need_Subprogram_Instance_Body
8456 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
8457 Subp)
8458 then
8459 null;
8460 end if;
8461
8462 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8463 -- appear in a formal part to apply to a formal subprogram.
8464 -- Do not apply check within an instance or a formal package
8465 -- the test will have been applied to the original generic.
8466
8467 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8468 and then List_Containing (Decl) = List_Containing (N)
8469 and then not In_Instance
8470 then
8471 Error_Msg_N
8472 ("Inline cannot apply to a formal subprogram", N);
8473
8474 -- If Subp is a renaming, it is the renamed entity that
8475 -- will appear in any call, and be inlined. However, for
8476 -- ASIS uses it is convenient to indicate that the renaming
8477 -- itself is an inlined subprogram, so that some gnatcheck
8478 -- rules can be applied in the absence of expansion.
8479
8480 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8481 Set_Inline_Flags (Subp);
8482 end if;
8483 end if;
8484
8485 Applies := True;
8486
8487 -- For a generic subprogram set flag as well, for use at the point
8488 -- of instantiation, to determine whether the body should be
8489 -- generated.
8490
8491 elsif Is_Generic_Subprogram (Subp) then
8492 Set_Inline_Flags (Subp);
8493 Applies := True;
8494
8495 -- Literals are by definition inlined
8496
8497 elsif Kind = E_Enumeration_Literal then
8498 null;
8499
8500 -- Anything else is an error
8501
8502 else
8503 Error_Pragma_Arg
8504 ("expect subprogram name for pragma%", Assoc);
8505 end if;
8506 end Make_Inline;
8507
8508 ----------------------
8509 -- Set_Inline_Flags --
8510 ----------------------
8511
8512 procedure Set_Inline_Flags (Subp : Entity_Id) is
8513 begin
8514 -- First set the Has_Pragma_XXX flags and issue the appropriate
8515 -- errors and warnings for suspicious combinations.
8516
8517 if Prag_Id = Pragma_No_Inline then
8518 if Has_Pragma_Inline_Always (Subp) then
8519 Error_Msg_N
8520 ("Inline_Always and No_Inline are mutually exclusive", N);
8521 elsif Has_Pragma_Inline (Subp) then
8522 Error_Msg_NE
8523 ("Inline and No_Inline both specified for& ??",
8524 N, Entity (Subp_Id));
8525 end if;
8526
8527 Set_Has_Pragma_No_Inline (Subp);
8528 else
8529 if Prag_Id = Pragma_Inline_Always then
8530 if Has_Pragma_No_Inline (Subp) then
8531 Error_Msg_N
8532 ("Inline_Always and No_Inline are mutually exclusive",
8533 N);
8534 end if;
8535
8536 Set_Has_Pragma_Inline_Always (Subp);
8537 else
8538 if Has_Pragma_No_Inline (Subp) then
8539 Error_Msg_NE
8540 ("Inline and No_Inline both specified for& ??",
8541 N, Entity (Subp_Id));
8542 end if;
8543 end if;
8544
8545 if not Has_Pragma_Inline (Subp) then
8546 Set_Has_Pragma_Inline (Subp);
8547 Effective := True;
8548 end if;
8549 end if;
8550
8551 -- Then adjust the Is_Inlined flag. It can never be set if the
8552 -- subprogram is subject to pragma No_Inline.
8553
8554 case Status is
8555 when Suppressed =>
8556 Set_Is_Inlined (Subp, False);
8557 when Disabled =>
8558 null;
8559 when Enabled =>
8560 if not Has_Pragma_No_Inline (Subp) then
8561 Set_Is_Inlined (Subp, True);
8562 end if;
8563 end case;
8564 end Set_Inline_Flags;
8565
8566 -- Start of processing for Process_Inline
8567
8568 begin
8569 Check_No_Identifiers;
8570 Check_At_Least_N_Arguments (1);
8571
8572 if Status = Enabled then
8573 Inline_Processing_Required := True;
8574 end if;
8575
8576 Assoc := Arg1;
8577 while Present (Assoc) loop
8578 Subp_Id := Get_Pragma_Arg (Assoc);
8579 Analyze (Subp_Id);
8580 Applies := False;
8581
8582 if Is_Entity_Name (Subp_Id) then
8583 Subp := Entity (Subp_Id);
8584
8585 if Subp = Any_Id then
8586
8587 -- If previous error, avoid cascaded errors
8588
8589 Check_Error_Detected;
8590 Applies := True;
8591 Effective := True;
8592
8593 else
8594 Make_Inline (Subp);
8595
8596 -- For the pragma case, climb homonym chain. This is
8597 -- what implements allowing the pragma in the renaming
8598 -- case, with the result applying to the ancestors, and
8599 -- also allows Inline to apply to all previous homonyms.
8600
8601 if not From_Aspect_Specification (N) then
8602 while Present (Homonym (Subp))
8603 and then Scope (Homonym (Subp)) = Current_Scope
8604 loop
8605 Make_Inline (Homonym (Subp));
8606 Subp := Homonym (Subp);
8607 end loop;
8608 end if;
8609 end if;
8610 end if;
8611
8612 if not Applies then
8613 Error_Pragma_Arg
8614 ("inappropriate argument for pragma%", Assoc);
8615
8616 elsif not Effective
8617 and then Warn_On_Redundant_Constructs
8618 and then not (Status = Suppressed or else Suppress_All_Inlining)
8619 then
8620 if Inlining_Not_Possible (Subp) then
8621 Error_Msg_NE
8622 ("pragma Inline for& is ignored?r?",
8623 N, Entity (Subp_Id));
8624 else
8625 Error_Msg_NE
8626 ("pragma Inline for& is redundant?r?",
8627 N, Entity (Subp_Id));
8628 end if;
8629 end if;
8630
8631 Next (Assoc);
8632 end loop;
8633 end Process_Inline;
8634
8635 ----------------------------
8636 -- Process_Interface_Name --
8637 ----------------------------
8638
8639 procedure Process_Interface_Name
8640 (Subprogram_Def : Entity_Id;
8641 Ext_Arg : Node_Id;
8642 Link_Arg : Node_Id)
8643 is
8644 Ext_Nam : Node_Id;
8645 Link_Nam : Node_Id;
8646 String_Val : String_Id;
8647
8648 procedure Check_Form_Of_Interface_Name
8649 (SN : Node_Id;
8650 Ext_Name_Case : Boolean);
8651 -- SN is a string literal node for an interface name. This routine
8652 -- performs some minimal checks that the name is reasonable. In
8653 -- particular that no spaces or other obviously incorrect characters
8654 -- appear. This is only a warning, since any characters are allowed.
8655 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
8656
8657 ----------------------------------
8658 -- Check_Form_Of_Interface_Name --
8659 ----------------------------------
8660
8661 procedure Check_Form_Of_Interface_Name
8662 (SN : Node_Id;
8663 Ext_Name_Case : Boolean)
8664 is
8665 S : constant String_Id := Strval (Expr_Value_S (SN));
8666 SL : constant Nat := String_Length (S);
8667 C : Char_Code;
8668
8669 begin
8670 if SL = 0 then
8671 Error_Msg_N ("interface name cannot be null string", SN);
8672 end if;
8673
8674 for J in 1 .. SL loop
8675 C := Get_String_Char (S, J);
8676
8677 -- Look for dubious character and issue unconditional warning.
8678 -- Definitely dubious if not in character range.
8679
8680 if not In_Character_Range (C)
8681
8682 -- For all cases except CLI target,
8683 -- commas, spaces and slashes are dubious (in CLI, we use
8684 -- commas and backslashes in external names to specify
8685 -- assembly version and public key, while slashes and spaces
8686 -- can be used in names to mark nested classes and
8687 -- valuetypes).
8688
8689 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
8690 and then (Get_Character (C) = ','
8691 or else
8692 Get_Character (C) = '\'))
8693 or else (VM_Target /= CLI_Target
8694 and then (Get_Character (C) = ' '
8695 or else
8696 Get_Character (C) = '/'))
8697 then
8698 Error_Msg
8699 ("??interface name contains illegal character",
8700 Sloc (SN) + Source_Ptr (J));
8701 end if;
8702 end loop;
8703 end Check_Form_Of_Interface_Name;
8704
8705 -- Start of processing for Process_Interface_Name
8706
8707 begin
8708 if No (Link_Arg) then
8709 if No (Ext_Arg) then
8710 if VM_Target = CLI_Target
8711 and then Ekind (Subprogram_Def) = E_Package
8712 and then Nkind (Parent (Subprogram_Def)) =
8713 N_Package_Specification
8714 and then Present (Generic_Parent (Parent (Subprogram_Def)))
8715 then
8716 Set_Interface_Name
8717 (Subprogram_Def,
8718 Interface_Name
8719 (Generic_Parent (Parent (Subprogram_Def))));
8720 end if;
8721
8722 return;
8723
8724 elsif Chars (Ext_Arg) = Name_Link_Name then
8725 Ext_Nam := Empty;
8726 Link_Nam := Expression (Ext_Arg);
8727
8728 else
8729 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8730 Ext_Nam := Expression (Ext_Arg);
8731 Link_Nam := Empty;
8732 end if;
8733
8734 else
8735 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8736 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
8737 Ext_Nam := Expression (Ext_Arg);
8738 Link_Nam := Expression (Link_Arg);
8739 end if;
8740
8741 -- Check expressions for external name and link name are static
8742
8743 if Present (Ext_Nam) then
8744 Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String);
8745 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
8746
8747 -- Verify that external name is not the name of a local entity,
8748 -- which would hide the imported one and could lead to run-time
8749 -- surprises. The problem can only arise for entities declared in
8750 -- a package body (otherwise the external name is fully qualified
8751 -- and will not conflict).
8752
8753 declare
8754 Nam : Name_Id;
8755 E : Entity_Id;
8756 Par : Node_Id;
8757
8758 begin
8759 if Prag_Id = Pragma_Import then
8760 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8761 Nam := Name_Find;
8762 E := Entity_Id (Get_Name_Table_Info (Nam));
8763
8764 if Nam /= Chars (Subprogram_Def)
8765 and then Present (E)
8766 and then not Is_Overloadable (E)
8767 and then Is_Immediately_Visible (E)
8768 and then not Is_Imported (E)
8769 and then Ekind (Scope (E)) = E_Package
8770 then
8771 Par := Parent (E);
8772 while Present (Par) loop
8773 if Nkind (Par) = N_Package_Body then
8774 Error_Msg_Sloc := Sloc (E);
8775 Error_Msg_NE
8776 ("imported entity is hidden by & declared#",
8777 Ext_Arg, E);
8778 exit;
8779 end if;
8780
8781 Par := Parent (Par);
8782 end loop;
8783 end if;
8784 end if;
8785 end;
8786 end if;
8787
8788 if Present (Link_Nam) then
8789 Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String);
8790 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
8791 end if;
8792
8793 -- If there is no link name, just set the external name
8794
8795 if No (Link_Nam) then
8796 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
8797
8798 -- For the Link_Name case, the given literal is preceded by an
8799 -- asterisk, which indicates to GCC that the given name should be
8800 -- taken literally, and in particular that no prepending of
8801 -- underlines should occur, even in systems where this is the
8802 -- normal default.
8803
8804 else
8805 Start_String;
8806
8807 if VM_Target = No_VM then
8808 Store_String_Char (Get_Char_Code ('*'));
8809 end if;
8810
8811 String_Val := Strval (Expr_Value_S (Link_Nam));
8812 Store_String_Chars (String_Val);
8813 Link_Nam :=
8814 Make_String_Literal (Sloc (Link_Nam),
8815 Strval => End_String);
8816 end if;
8817
8818 -- Set the interface name. If the entity is a generic instance, use
8819 -- its alias, which is the callable entity.
8820
8821 if Is_Generic_Instance (Subprogram_Def) then
8822 Set_Encoded_Interface_Name
8823 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8824 else
8825 Set_Encoded_Interface_Name
8826 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
8827 end if;
8828
8829 -- We allow duplicated export names in CIL/Java, as they are always
8830 -- enclosed in a namespace that differentiates them, and overloaded
8831 -- entities are supported by the VM.
8832
8833 if Convention (Subprogram_Def) /= Convention_CIL
8834 and then
8835 Convention (Subprogram_Def) /= Convention_Java
8836 then
8837 Check_Duplicated_Export_Name (Link_Nam);
8838 end if;
8839 end Process_Interface_Name;
8840
8841 -----------------------------------------
8842 -- Process_Interrupt_Or_Attach_Handler --
8843 -----------------------------------------
8844
8845 procedure Process_Interrupt_Or_Attach_Handler is
8846 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
8847 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
8848 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
8849
8850 begin
8851 Set_Is_Interrupt_Handler (Handler_Proc);
8852
8853 -- If the pragma is not associated with a handler procedure within a
8854 -- protected type, then it must be for a nonprotected procedure for
8855 -- the AAMP target, in which case we don't associate a representation
8856 -- item with the procedure's scope.
8857
8858 if Ekind (Proc_Scope) = E_Protected_Type then
8859 if Prag_Id = Pragma_Interrupt_Handler
8860 or else
8861 Prag_Id = Pragma_Attach_Handler
8862 then
8863 Record_Rep_Item (Proc_Scope, N);
8864 end if;
8865 end if;
8866 end Process_Interrupt_Or_Attach_Handler;
8867
8868 --------------------------------------------------
8869 -- Process_Restrictions_Or_Restriction_Warnings --
8870 --------------------------------------------------
8871
8872 -- Note: some of the simple identifier cases were handled in par-prag,
8873 -- but it is harmless (and more straightforward) to simply handle all
8874 -- cases here, even if it means we repeat a bit of work in some cases.
8875
8876 procedure Process_Restrictions_Or_Restriction_Warnings
8877 (Warn : Boolean)
8878 is
8879 Arg : Node_Id;
8880 R_Id : Restriction_Id;
8881 Id : Name_Id;
8882 Expr : Node_Id;
8883 Val : Uint;
8884
8885 begin
8886 -- Ignore all Restrictions pragmas in CodePeer mode
8887
8888 if CodePeer_Mode then
8889 return;
8890 end if;
8891
8892 Check_Ada_83_Warning;
8893 Check_At_Least_N_Arguments (1);
8894 Check_Valid_Configuration_Pragma;
8895
8896 Arg := Arg1;
8897 while Present (Arg) loop
8898 Id := Chars (Arg);
8899 Expr := Get_Pragma_Arg (Arg);
8900
8901 -- Case of no restriction identifier present
8902
8903 if Id = No_Name then
8904 if Nkind (Expr) /= N_Identifier then
8905 Error_Pragma_Arg
8906 ("invalid form for restriction", Arg);
8907 end if;
8908
8909 R_Id :=
8910 Get_Restriction_Id
8911 (Process_Restriction_Synonyms (Expr));
8912
8913 if R_Id not in All_Boolean_Restrictions then
8914 Error_Msg_Name_1 := Pname;
8915 Error_Msg_N
8916 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8917
8918 -- Check for possible misspelling
8919
8920 for J in Restriction_Id loop
8921 declare
8922 Rnm : constant String := Restriction_Id'Image (J);
8923
8924 begin
8925 Name_Buffer (1 .. Rnm'Length) := Rnm;
8926 Name_Len := Rnm'Length;
8927 Set_Casing (All_Lower_Case);
8928
8929 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
8930 Set_Casing
8931 (Identifier_Casing (Current_Source_File));
8932 Error_Msg_String (1 .. Rnm'Length) :=
8933 Name_Buffer (1 .. Name_Len);
8934 Error_Msg_Strlen := Rnm'Length;
8935 Error_Msg_N -- CODEFIX
8936 ("\possible misspelling of ""~""",
8937 Get_Pragma_Arg (Arg));
8938 exit;
8939 end if;
8940 end;
8941 end loop;
8942
8943 raise Pragma_Exit;
8944 end if;
8945
8946 if Implementation_Restriction (R_Id) then
8947 Check_Restriction (No_Implementation_Restrictions, Arg);
8948 end if;
8949
8950 -- Special processing for No_Elaboration_Code restriction
8951
8952 if R_Id = No_Elaboration_Code then
8953
8954 -- Restriction is only recognized within a configuration
8955 -- pragma file, or within a unit of the main extended
8956 -- program. Note: the test for Main_Unit is needed to
8957 -- properly include the case of configuration pragma files.
8958
8959 if not (Current_Sem_Unit = Main_Unit
8960 or else In_Extended_Main_Source_Unit (N))
8961 then
8962 return;
8963
8964 -- Don't allow in a subunit unless already specified in
8965 -- body or spec.
8966
8967 elsif Nkind (Parent (N)) = N_Compilation_Unit
8968 and then Nkind (Unit (Parent (N))) = N_Subunit
8969 and then not Restriction_Active (No_Elaboration_Code)
8970 then
8971 Error_Msg_N
8972 ("invalid specification of ""No_Elaboration_Code""",
8973 N);
8974 Error_Msg_N
8975 ("\restriction cannot be specified in a subunit", N);
8976 Error_Msg_N
8977 ("\unless also specified in body or spec", N);
8978 return;
8979
8980 -- If we have a No_Elaboration_Code pragma that we
8981 -- accept, then it needs to be added to the configuration
8982 -- restrcition set so that we get proper application to
8983 -- other units in the main extended source as required.
8984
8985 else
8986 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
8987 end if;
8988 end if;
8989
8990 -- If this is a warning, then set the warning unless we already
8991 -- have a real restriction active (we never want a warning to
8992 -- override a real restriction).
8993
8994 if Warn then
8995 if not Restriction_Active (R_Id) then
8996 Set_Restriction (R_Id, N);
8997 Restriction_Warnings (R_Id) := True;
8998 end if;
8999
9000 -- If real restriction case, then set it and make sure that the
9001 -- restriction warning flag is off, since a real restriction
9002 -- always overrides a warning.
9003
9004 else
9005 Set_Restriction (R_Id, N);
9006 Restriction_Warnings (R_Id) := False;
9007 end if;
9008
9009 -- Check for obsolescent restrictions in Ada 2005 mode
9010
9011 if not Warn
9012 and then Ada_Version >= Ada_2005
9013 and then (R_Id = No_Asynchronous_Control
9014 or else
9015 R_Id = No_Unchecked_Deallocation
9016 or else
9017 R_Id = No_Unchecked_Conversion)
9018 then
9019 Check_Restriction (No_Obsolescent_Features, N);
9020 end if;
9021
9022 -- A very special case that must be processed here: pragma
9023 -- Restrictions (No_Exceptions) turns off all run-time
9024 -- checking. This is a bit dubious in terms of the formal
9025 -- language definition, but it is what is intended by RM
9026 -- H.4(12). Restriction_Warnings never affects generated code
9027 -- so this is done only in the real restriction case.
9028
9029 -- Atomic_Synchronization is not a real check, so it is not
9030 -- affected by this processing).
9031
9032 if R_Id = No_Exceptions and then not Warn then
9033 for J in Scope_Suppress.Suppress'Range loop
9034 if J /= Atomic_Synchronization then
9035 Scope_Suppress.Suppress (J) := True;
9036 end if;
9037 end loop;
9038 end if;
9039
9040 -- Case of No_Dependence => unit-name. Note that the parser
9041 -- already made the necessary entry in the No_Dependence table.
9042
9043 elsif Id = Name_No_Dependence then
9044 if not OK_No_Dependence_Unit_Name (Expr) then
9045 raise Pragma_Exit;
9046 end if;
9047
9048 -- Case of No_Specification_Of_Aspect => Identifier.
9049
9050 elsif Id = Name_No_Specification_Of_Aspect then
9051 declare
9052 A_Id : Aspect_Id;
9053
9054 begin
9055 if Nkind (Expr) /= N_Identifier then
9056 A_Id := No_Aspect;
9057 else
9058 A_Id := Get_Aspect_Id (Chars (Expr));
9059 end if;
9060
9061 if A_Id = No_Aspect then
9062 Error_Pragma_Arg ("invalid restriction name", Arg);
9063 else
9064 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
9065 end if;
9066 end;
9067
9068 elsif Id = Name_No_Use_Of_Attribute then
9069 if Nkind (Expr) /= N_Identifier
9070 or else not Is_Attribute_Name (Chars (Expr))
9071 then
9072 Error_Msg_N ("unknown attribute name??", Expr);
9073
9074 else
9075 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
9076 end if;
9077
9078 elsif Id = Name_No_Use_Of_Pragma then
9079 if Nkind (Expr) /= N_Identifier
9080 or else not Is_Pragma_Name (Chars (Expr))
9081 then
9082 Error_Msg_N ("unknown pragma name??", Expr);
9083
9084 else
9085 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
9086 end if;
9087
9088 -- All other cases of restriction identifier present
9089
9090 else
9091 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
9092 Analyze_And_Resolve (Expr, Any_Integer);
9093
9094 if R_Id not in All_Parameter_Restrictions then
9095 Error_Pragma_Arg
9096 ("invalid restriction parameter identifier", Arg);
9097
9098 elsif not Is_OK_Static_Expression (Expr) then
9099 Flag_Non_Static_Expr
9100 ("value must be static expression!", Expr);
9101 raise Pragma_Exit;
9102
9103 elsif not Is_Integer_Type (Etype (Expr))
9104 or else Expr_Value (Expr) < 0
9105 then
9106 Error_Pragma_Arg
9107 ("value must be non-negative integer", Arg);
9108 end if;
9109
9110 -- Restriction pragma is active
9111
9112 Val := Expr_Value (Expr);
9113
9114 if not UI_Is_In_Int_Range (Val) then
9115 Error_Pragma_Arg
9116 ("pragma ignored, value too large??", Arg);
9117 end if;
9118
9119 -- Warning case. If the real restriction is active, then we
9120 -- ignore the request, since warning never overrides a real
9121 -- restriction. Otherwise we set the proper warning. Note that
9122 -- this circuit sets the warning again if it is already set,
9123 -- which is what we want, since the constant may have changed.
9124
9125 if Warn then
9126 if not Restriction_Active (R_Id) then
9127 Set_Restriction
9128 (R_Id, N, Integer (UI_To_Int (Val)));
9129 Restriction_Warnings (R_Id) := True;
9130 end if;
9131
9132 -- Real restriction case, set restriction and make sure warning
9133 -- flag is off since real restriction always overrides warning.
9134
9135 else
9136 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9137 Restriction_Warnings (R_Id) := False;
9138 end if;
9139 end if;
9140
9141 Next (Arg);
9142 end loop;
9143 end Process_Restrictions_Or_Restriction_Warnings;
9144
9145 ---------------------------------
9146 -- Process_Suppress_Unsuppress --
9147 ---------------------------------
9148
9149 -- Note: this procedure makes entries in the check suppress data
9150 -- structures managed by Sem. See spec of package Sem for full
9151 -- details on how we handle recording of check suppression.
9152
9153 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9154 C : Check_Id;
9155 E_Id : Node_Id;
9156 E : Entity_Id;
9157
9158 In_Package_Spec : constant Boolean :=
9159 Is_Package_Or_Generic_Package (Current_Scope)
9160 and then not In_Package_Body (Current_Scope);
9161
9162 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9163 -- Used to suppress a single check on the given entity
9164
9165 --------------------------------
9166 -- Suppress_Unsuppress_Echeck --
9167 --------------------------------
9168
9169 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9170 begin
9171 -- Check for error of trying to set atomic synchronization for
9172 -- a non-atomic variable.
9173
9174 if C = Atomic_Synchronization
9175 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9176 then
9177 Error_Msg_N
9178 ("pragma & requires atomic type or variable",
9179 Pragma_Identifier (Original_Node (N)));
9180 end if;
9181
9182 Set_Checks_May_Be_Suppressed (E);
9183
9184 if In_Package_Spec then
9185 Push_Global_Suppress_Stack_Entry
9186 (Entity => E,
9187 Check => C,
9188 Suppress => Suppress_Case);
9189 else
9190 Push_Local_Suppress_Stack_Entry
9191 (Entity => E,
9192 Check => C,
9193 Suppress => Suppress_Case);
9194 end if;
9195
9196 -- If this is a first subtype, and the base type is distinct,
9197 -- then also set the suppress flags on the base type.
9198
9199 if Is_First_Subtype (E) and then Etype (E) /= E then
9200 Suppress_Unsuppress_Echeck (Etype (E), C);
9201 end if;
9202 end Suppress_Unsuppress_Echeck;
9203
9204 -- Start of processing for Process_Suppress_Unsuppress
9205
9206 begin
9207 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9208 -- on user code: we want to generate checks for analysis purposes, as
9209 -- set respectively by -gnatC and -gnatd.F
9210
9211 if (CodePeer_Mode or GNATprove_Mode)
9212 and then Comes_From_Source (N)
9213 then
9214 return;
9215 end if;
9216
9217 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9218 -- declarative part or a package spec (RM 11.5(5)).
9219
9220 if not Is_Configuration_Pragma then
9221 Check_Is_In_Decl_Part_Or_Package_Spec;
9222 end if;
9223
9224 Check_At_Least_N_Arguments (1);
9225 Check_At_Most_N_Arguments (2);
9226 Check_No_Identifier (Arg1);
9227 Check_Arg_Is_Identifier (Arg1);
9228
9229 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9230
9231 if C = No_Check_Id then
9232 Error_Pragma_Arg
9233 ("argument of pragma% is not valid check name", Arg1);
9234 end if;
9235
9236 if Arg_Count = 1 then
9237
9238 -- Make an entry in the local scope suppress table. This is the
9239 -- table that directly shows the current value of the scope
9240 -- suppress check for any check id value.
9241
9242 if C = All_Checks then
9243
9244 -- For All_Checks, we set all specific predefined checks with
9245 -- the exception of Elaboration_Check, which is handled
9246 -- specially because of not wanting All_Checks to have the
9247 -- effect of deactivating static elaboration order processing.
9248 -- Atomic_Synchronization is also not affected, since this is
9249 -- not a real check.
9250
9251 for J in Scope_Suppress.Suppress'Range loop
9252 if J /= Elaboration_Check
9253 and then
9254 J /= Atomic_Synchronization
9255 then
9256 Scope_Suppress.Suppress (J) := Suppress_Case;
9257 end if;
9258 end loop;
9259
9260 -- If not All_Checks, and predefined check, then set appropriate
9261 -- scope entry. Note that we will set Elaboration_Check if this
9262 -- is explicitly specified. Atomic_Synchronization is allowed
9263 -- only if internally generated and entity is atomic.
9264
9265 elsif C in Predefined_Check_Id
9266 and then (not Comes_From_Source (N)
9267 or else C /= Atomic_Synchronization)
9268 then
9269 Scope_Suppress.Suppress (C) := Suppress_Case;
9270 end if;
9271
9272 -- Also make an entry in the Local_Entity_Suppress table
9273
9274 Push_Local_Suppress_Stack_Entry
9275 (Entity => Empty,
9276 Check => C,
9277 Suppress => Suppress_Case);
9278
9279 -- Case of two arguments present, where the check is suppressed for
9280 -- a specified entity (given as the second argument of the pragma)
9281
9282 else
9283 -- This is obsolescent in Ada 2005 mode
9284
9285 if Ada_Version >= Ada_2005 then
9286 Check_Restriction (No_Obsolescent_Features, Arg2);
9287 end if;
9288
9289 Check_Optional_Identifier (Arg2, Name_On);
9290 E_Id := Get_Pragma_Arg (Arg2);
9291 Analyze (E_Id);
9292
9293 if not Is_Entity_Name (E_Id) then
9294 Error_Pragma_Arg
9295 ("second argument of pragma% must be entity name", Arg2);
9296 end if;
9297
9298 E := Entity (E_Id);
9299
9300 if E = Any_Id then
9301 return;
9302 end if;
9303
9304 -- Enforce RM 11.5(7) which requires that for a pragma that
9305 -- appears within a package spec, the named entity must be
9306 -- within the package spec. We allow the package name itself
9307 -- to be mentioned since that makes sense, although it is not
9308 -- strictly allowed by 11.5(7).
9309
9310 if In_Package_Spec
9311 and then E /= Current_Scope
9312 and then Scope (E) /= Current_Scope
9313 then
9314 Error_Pragma_Arg
9315 ("entity in pragma% is not in package spec (RM 11.5(7))",
9316 Arg2);
9317 end if;
9318
9319 -- Loop through homonyms. As noted below, in the case of a package
9320 -- spec, only homonyms within the package spec are considered.
9321
9322 loop
9323 Suppress_Unsuppress_Echeck (E, C);
9324
9325 if Is_Generic_Instance (E)
9326 and then Is_Subprogram (E)
9327 and then Present (Alias (E))
9328 then
9329 Suppress_Unsuppress_Echeck (Alias (E), C);
9330 end if;
9331
9332 -- Move to next homonym if not aspect spec case
9333
9334 exit when From_Aspect_Specification (N);
9335 E := Homonym (E);
9336 exit when No (E);
9337
9338 -- If we are within a package specification, the pragma only
9339 -- applies to homonyms in the same scope.
9340
9341 exit when In_Package_Spec
9342 and then Scope (E) /= Current_Scope;
9343 end loop;
9344 end if;
9345 end Process_Suppress_Unsuppress;
9346
9347 ------------------
9348 -- Set_Exported --
9349 ------------------
9350
9351 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
9352 begin
9353 if Is_Imported (E) then
9354 Error_Pragma_Arg
9355 ("cannot export entity& that was previously imported", Arg);
9356
9357 elsif Present (Address_Clause (E))
9358 and then not Relaxed_RM_Semantics
9359 then
9360 Error_Pragma_Arg
9361 ("cannot export entity& that has an address clause", Arg);
9362 end if;
9363
9364 Set_Is_Exported (E);
9365
9366 -- Generate a reference for entity explicitly, because the
9367 -- identifier may be overloaded and name resolution will not
9368 -- generate one.
9369
9370 Generate_Reference (E, Arg);
9371
9372 -- Deal with exporting non-library level entity
9373
9374 if not Is_Library_Level_Entity (E) then
9375
9376 -- Not allowed at all for subprograms
9377
9378 if Is_Subprogram (E) then
9379 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
9380
9381 -- Otherwise set public and statically allocated
9382
9383 else
9384 Set_Is_Public (E);
9385 Set_Is_Statically_Allocated (E);
9386
9387 -- Warn if the corresponding W flag is set and the pragma comes
9388 -- from source. The latter may not be true e.g. on VMS where we
9389 -- expand export pragmas for exception codes associated with
9390 -- imported or exported exceptions. We do not want to generate
9391 -- a warning for something that the user did not write.
9392
9393 if Warn_On_Export_Import
9394 and then Comes_From_Source (Arg)
9395 then
9396 Error_Msg_NE
9397 ("?x?& has been made static as a result of Export",
9398 Arg, E);
9399 Error_Msg_N
9400 ("\?x?this usage is non-standard and non-portable",
9401 Arg);
9402 end if;
9403 end if;
9404 end if;
9405
9406 if Warn_On_Export_Import and then Is_Type (E) then
9407 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
9408 end if;
9409
9410 if Warn_On_Export_Import and Inside_A_Generic then
9411 Error_Msg_NE
9412 ("all instances of& will have the same external name?x?",
9413 Arg, E);
9414 end if;
9415 end Set_Exported;
9416
9417 ----------------------------------------------
9418 -- Set_Extended_Import_Export_External_Name --
9419 ----------------------------------------------
9420
9421 procedure Set_Extended_Import_Export_External_Name
9422 (Internal_Ent : Entity_Id;
9423 Arg_External : Node_Id)
9424 is
9425 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9426 New_Name : Node_Id;
9427
9428 begin
9429 if No (Arg_External) then
9430 return;
9431 end if;
9432
9433 Check_Arg_Is_External_Name (Arg_External);
9434
9435 if Nkind (Arg_External) = N_String_Literal then
9436 if String_Length (Strval (Arg_External)) = 0 then
9437 return;
9438 else
9439 New_Name := Adjust_External_Name_Case (Arg_External);
9440 end if;
9441
9442 elsif Nkind (Arg_External) = N_Identifier then
9443 New_Name := Get_Default_External_Name (Arg_External);
9444
9445 -- Check_Arg_Is_External_Name should let through only identifiers and
9446 -- string literals or static string expressions (which are folded to
9447 -- string literals).
9448
9449 else
9450 raise Program_Error;
9451 end if;
9452
9453 -- If we already have an external name set (by a prior normal Import
9454 -- or Export pragma), then the external names must match
9455
9456 if Present (Interface_Name (Internal_Ent)) then
9457
9458 -- Ignore mismatching names in CodePeer mode, to support some
9459 -- old compilers which would export the same procedure under
9460 -- different names, e.g:
9461 -- procedure P;
9462 -- pragma Export_Procedure (P, "a");
9463 -- pragma Export_Procedure (P, "b");
9464
9465 if CodePeer_Mode then
9466 return;
9467 end if;
9468
9469 Check_Matching_Internal_Names : declare
9470 S1 : constant String_Id := Strval (Old_Name);
9471 S2 : constant String_Id := Strval (New_Name);
9472
9473 procedure Mismatch;
9474 pragma No_Return (Mismatch);
9475 -- Called if names do not match
9476
9477 --------------
9478 -- Mismatch --
9479 --------------
9480
9481 procedure Mismatch is
9482 begin
9483 Error_Msg_Sloc := Sloc (Old_Name);
9484 Error_Pragma_Arg
9485 ("external name does not match that given #",
9486 Arg_External);
9487 end Mismatch;
9488
9489 -- Start of processing for Check_Matching_Internal_Names
9490
9491 begin
9492 if String_Length (S1) /= String_Length (S2) then
9493 Mismatch;
9494
9495 else
9496 for J in 1 .. String_Length (S1) loop
9497 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9498 Mismatch;
9499 end if;
9500 end loop;
9501 end if;
9502 end Check_Matching_Internal_Names;
9503
9504 -- Otherwise set the given name
9505
9506 else
9507 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9508 Check_Duplicated_Export_Name (New_Name);
9509 end if;
9510 end Set_Extended_Import_Export_External_Name;
9511
9512 ------------------
9513 -- Set_Imported --
9514 ------------------
9515
9516 procedure Set_Imported (E : Entity_Id) is
9517 begin
9518 -- Error message if already imported or exported
9519
9520 if Is_Exported (E) or else Is_Imported (E) then
9521
9522 -- Error if being set Exported twice
9523
9524 if Is_Exported (E) then
9525 Error_Msg_NE ("entity& was previously exported", N, E);
9526
9527 -- Ignore error in CodePeer mode where we treat all imported
9528 -- subprograms as unknown.
9529
9530 elsif CodePeer_Mode then
9531 goto OK;
9532
9533 -- OK if Import/Interface case
9534
9535 elsif Import_Interface_Present (N) then
9536 goto OK;
9537
9538 -- Error if being set Imported twice
9539
9540 else
9541 Error_Msg_NE ("entity& was previously imported", N, E);
9542 end if;
9543
9544 Error_Msg_Name_1 := Pname;
9545 Error_Msg_N
9546 ("\(pragma% applies to all previous entities)", N);
9547
9548 Error_Msg_Sloc := Sloc (E);
9549 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9550
9551 -- Here if not previously imported or exported, OK to import
9552
9553 else
9554 Set_Is_Imported (E);
9555
9556 -- For subprogram, set Import_Pragma field
9557
9558 if Is_Subprogram (E) then
9559 Set_Import_Pragma (E, N);
9560 end if;
9561
9562 -- If the entity is an object that is not at the library level,
9563 -- then it is statically allocated. We do not worry about objects
9564 -- with address clauses in this context since they are not really
9565 -- imported in the linker sense.
9566
9567 if Is_Object (E)
9568 and then not Is_Library_Level_Entity (E)
9569 and then No (Address_Clause (E))
9570 then
9571 Set_Is_Statically_Allocated (E);
9572 end if;
9573 end if;
9574
9575 <<OK>> null;
9576 end Set_Imported;
9577
9578 -------------------------
9579 -- Set_Mechanism_Value --
9580 -------------------------
9581
9582 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9583 -- analyzed, since it is semantic nonsense), so we get it in the exact
9584 -- form created by the parser.
9585
9586 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9587 Class : Node_Id;
9588 Param : Node_Id;
9589 Mech_Name_Id : Name_Id;
9590
9591 procedure Bad_Class;
9592 pragma No_Return (Bad_Class);
9593 -- Signal bad descriptor class name
9594
9595 procedure Bad_Mechanism;
9596 pragma No_Return (Bad_Mechanism);
9597 -- Signal bad mechanism name
9598
9599 ---------------
9600 -- Bad_Class --
9601 ---------------
9602
9603 procedure Bad_Class is
9604 begin
9605 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
9606 end Bad_Class;
9607
9608 -------------------------
9609 -- Bad_Mechanism_Value --
9610 -------------------------
9611
9612 procedure Bad_Mechanism is
9613 begin
9614 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9615 end Bad_Mechanism;
9616
9617 -- Start of processing for Set_Mechanism_Value
9618
9619 begin
9620 if Mechanism (Ent) /= Default_Mechanism then
9621 Error_Msg_NE
9622 ("mechanism for & has already been set", Mech_Name, Ent);
9623 end if;
9624
9625 -- MECHANISM_NAME ::= value | reference | descriptor |
9626 -- short_descriptor
9627
9628 if Nkind (Mech_Name) = N_Identifier then
9629 if Chars (Mech_Name) = Name_Value then
9630 Set_Mechanism (Ent, By_Copy);
9631 return;
9632
9633 elsif Chars (Mech_Name) = Name_Reference then
9634 Set_Mechanism (Ent, By_Reference);
9635 return;
9636
9637 elsif Chars (Mech_Name) = Name_Descriptor then
9638 Check_VMS (Mech_Name);
9639
9640 -- Descriptor => Short_Descriptor if pragma was given
9641
9642 if Short_Descriptors then
9643 Set_Mechanism (Ent, By_Short_Descriptor);
9644 else
9645 Set_Mechanism (Ent, By_Descriptor);
9646 end if;
9647
9648 return;
9649
9650 elsif Chars (Mech_Name) = Name_Short_Descriptor then
9651 Check_VMS (Mech_Name);
9652 Set_Mechanism (Ent, By_Short_Descriptor);
9653 return;
9654
9655 elsif Chars (Mech_Name) = Name_Copy then
9656 Error_Pragma_Arg
9657 ("bad mechanism name, Value assumed", Mech_Name);
9658
9659 else
9660 Bad_Mechanism;
9661 end if;
9662
9663 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
9664 -- short_descriptor (CLASS_NAME)
9665 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9666
9667 -- Note: this form is parsed as an indexed component
9668
9669 elsif Nkind (Mech_Name) = N_Indexed_Component then
9670 Class := First (Expressions (Mech_Name));
9671
9672 if Nkind (Prefix (Mech_Name)) /= N_Identifier
9673 or else
9674 not Nam_In (Chars (Prefix (Mech_Name)), Name_Descriptor,
9675 Name_Short_Descriptor)
9676 or else Present (Next (Class))
9677 then
9678 Bad_Mechanism;
9679 else
9680 Mech_Name_Id := Chars (Prefix (Mech_Name));
9681
9682 -- Change Descriptor => Short_Descriptor if pragma was given
9683
9684 if Mech_Name_Id = Name_Descriptor
9685 and then Short_Descriptors
9686 then
9687 Mech_Name_Id := Name_Short_Descriptor;
9688 end if;
9689 end if;
9690
9691 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
9692 -- short_descriptor (Class => CLASS_NAME)
9693 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9694
9695 -- Note: this form is parsed as a function call
9696
9697 elsif Nkind (Mech_Name) = N_Function_Call then
9698 Param := First (Parameter_Associations (Mech_Name));
9699
9700 if Nkind (Name (Mech_Name)) /= N_Identifier
9701 or else
9702 not Nam_In (Chars (Name (Mech_Name)), Name_Descriptor,
9703 Name_Short_Descriptor)
9704 or else Present (Next (Param))
9705 or else No (Selector_Name (Param))
9706 or else Chars (Selector_Name (Param)) /= Name_Class
9707 then
9708 Bad_Mechanism;
9709 else
9710 Class := Explicit_Actual_Parameter (Param);
9711 Mech_Name_Id := Chars (Name (Mech_Name));
9712 end if;
9713
9714 else
9715 Bad_Mechanism;
9716 end if;
9717
9718 -- Fall through here with Class set to descriptor class name
9719
9720 Check_VMS (Mech_Name);
9721
9722 if Nkind (Class) /= N_Identifier then
9723 Bad_Class;
9724
9725 elsif Mech_Name_Id = Name_Descriptor
9726 and then Chars (Class) = Name_UBS
9727 then
9728 Set_Mechanism (Ent, By_Descriptor_UBS);
9729
9730 elsif Mech_Name_Id = Name_Descriptor
9731 and then Chars (Class) = Name_UBSB
9732 then
9733 Set_Mechanism (Ent, By_Descriptor_UBSB);
9734
9735 elsif Mech_Name_Id = Name_Descriptor
9736 and then Chars (Class) = Name_UBA
9737 then
9738 Set_Mechanism (Ent, By_Descriptor_UBA);
9739
9740 elsif Mech_Name_Id = Name_Descriptor
9741 and then Chars (Class) = Name_S
9742 then
9743 Set_Mechanism (Ent, By_Descriptor_S);
9744
9745 elsif Mech_Name_Id = Name_Descriptor
9746 and then Chars (Class) = Name_SB
9747 then
9748 Set_Mechanism (Ent, By_Descriptor_SB);
9749
9750 elsif Mech_Name_Id = Name_Descriptor
9751 and then Chars (Class) = Name_A
9752 then
9753 Set_Mechanism (Ent, By_Descriptor_A);
9754
9755 elsif Mech_Name_Id = Name_Descriptor
9756 and then Chars (Class) = Name_NCA
9757 then
9758 Set_Mechanism (Ent, By_Descriptor_NCA);
9759
9760 elsif Mech_Name_Id = Name_Short_Descriptor
9761 and then Chars (Class) = Name_UBS
9762 then
9763 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
9764
9765 elsif Mech_Name_Id = Name_Short_Descriptor
9766 and then Chars (Class) = Name_UBSB
9767 then
9768 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
9769
9770 elsif Mech_Name_Id = Name_Short_Descriptor
9771 and then Chars (Class) = Name_UBA
9772 then
9773 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
9774
9775 elsif Mech_Name_Id = Name_Short_Descriptor
9776 and then Chars (Class) = Name_S
9777 then
9778 Set_Mechanism (Ent, By_Short_Descriptor_S);
9779
9780 elsif Mech_Name_Id = Name_Short_Descriptor
9781 and then Chars (Class) = Name_SB
9782 then
9783 Set_Mechanism (Ent, By_Short_Descriptor_SB);
9784
9785 elsif Mech_Name_Id = Name_Short_Descriptor
9786 and then Chars (Class) = Name_A
9787 then
9788 Set_Mechanism (Ent, By_Short_Descriptor_A);
9789
9790 elsif Mech_Name_Id = Name_Short_Descriptor
9791 and then Chars (Class) = Name_NCA
9792 then
9793 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
9794
9795 else
9796 Bad_Class;
9797 end if;
9798 end Set_Mechanism_Value;
9799
9800 --------------------------
9801 -- Set_Rational_Profile --
9802 --------------------------
9803
9804 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9805 -- and extension to the semantics of renaming declarations.
9806
9807 procedure Set_Rational_Profile is
9808 begin
9809 Implicit_Packing := True;
9810 Overriding_Renamings := True;
9811 Use_VADS_Size := True;
9812 end Set_Rational_Profile;
9813
9814 ---------------------------
9815 -- Set_Ravenscar_Profile --
9816 ---------------------------
9817
9818 -- The tasks to be done here are
9819
9820 -- Set required policies
9821
9822 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9823 -- pragma Locking_Policy (Ceiling_Locking)
9824
9825 -- Set Detect_Blocking mode
9826
9827 -- Set required restrictions (see System.Rident for detailed list)
9828
9829 -- Set the No_Dependence rules
9830 -- No_Dependence => Ada.Asynchronous_Task_Control
9831 -- No_Dependence => Ada.Calendar
9832 -- No_Dependence => Ada.Execution_Time.Group_Budget
9833 -- No_Dependence => Ada.Execution_Time.Timers
9834 -- No_Dependence => Ada.Task_Attributes
9835 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9836
9837 procedure Set_Ravenscar_Profile (N : Node_Id) is
9838 Prefix_Entity : Entity_Id;
9839 Selector_Entity : Entity_Id;
9840 Prefix_Node : Node_Id;
9841 Node : Node_Id;
9842
9843 begin
9844 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9845
9846 if Task_Dispatching_Policy /= ' '
9847 and then Task_Dispatching_Policy /= 'F'
9848 then
9849 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9850 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9851
9852 -- Set the FIFO_Within_Priorities policy, but always preserve
9853 -- System_Location since we like the error message with the run time
9854 -- name.
9855
9856 else
9857 Task_Dispatching_Policy := 'F';
9858
9859 if Task_Dispatching_Policy_Sloc /= System_Location then
9860 Task_Dispatching_Policy_Sloc := Loc;
9861 end if;
9862 end if;
9863
9864 -- pragma Locking_Policy (Ceiling_Locking)
9865
9866 if Locking_Policy /= ' '
9867 and then Locking_Policy /= 'C'
9868 then
9869 Error_Msg_Sloc := Locking_Policy_Sloc;
9870 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9871
9872 -- Set the Ceiling_Locking policy, but preserve System_Location since
9873 -- we like the error message with the run time name.
9874
9875 else
9876 Locking_Policy := 'C';
9877
9878 if Locking_Policy_Sloc /= System_Location then
9879 Locking_Policy_Sloc := Loc;
9880 end if;
9881 end if;
9882
9883 -- pragma Detect_Blocking
9884
9885 Detect_Blocking := True;
9886
9887 -- Set the corresponding restrictions
9888
9889 Set_Profile_Restrictions
9890 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9891
9892 -- Set the No_Dependence restrictions
9893
9894 -- The following No_Dependence restrictions:
9895 -- No_Dependence => Ada.Asynchronous_Task_Control
9896 -- No_Dependence => Ada.Calendar
9897 -- No_Dependence => Ada.Task_Attributes
9898 -- are already set by previous call to Set_Profile_Restrictions.
9899
9900 -- Set the following restrictions which were added to Ada 2005:
9901 -- No_Dependence => Ada.Execution_Time.Group_Budget
9902 -- No_Dependence => Ada.Execution_Time.Timers
9903
9904 if Ada_Version >= Ada_2005 then
9905 Name_Buffer (1 .. 3) := "ada";
9906 Name_Len := 3;
9907
9908 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9909
9910 Name_Buffer (1 .. 14) := "execution_time";
9911 Name_Len := 14;
9912
9913 Selector_Entity := Make_Identifier (Loc, Name_Find);
9914
9915 Prefix_Node :=
9916 Make_Selected_Component
9917 (Sloc => Loc,
9918 Prefix => Prefix_Entity,
9919 Selector_Name => Selector_Entity);
9920
9921 Name_Buffer (1 .. 13) := "group_budgets";
9922 Name_Len := 13;
9923
9924 Selector_Entity := Make_Identifier (Loc, Name_Find);
9925
9926 Node :=
9927 Make_Selected_Component
9928 (Sloc => Loc,
9929 Prefix => Prefix_Node,
9930 Selector_Name => Selector_Entity);
9931
9932 Set_Restriction_No_Dependence
9933 (Unit => Node,
9934 Warn => Treat_Restrictions_As_Warnings,
9935 Profile => Ravenscar);
9936
9937 Name_Buffer (1 .. 6) := "timers";
9938 Name_Len := 6;
9939
9940 Selector_Entity := Make_Identifier (Loc, Name_Find);
9941
9942 Node :=
9943 Make_Selected_Component
9944 (Sloc => Loc,
9945 Prefix => Prefix_Node,
9946 Selector_Name => Selector_Entity);
9947
9948 Set_Restriction_No_Dependence
9949 (Unit => Node,
9950 Warn => Treat_Restrictions_As_Warnings,
9951 Profile => Ravenscar);
9952 end if;
9953
9954 -- Set the following restrictions which was added to Ada 2012 (see
9955 -- AI-0171):
9956 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9957
9958 if Ada_Version >= Ada_2012 then
9959 Name_Buffer (1 .. 6) := "system";
9960 Name_Len := 6;
9961
9962 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9963
9964 Name_Buffer (1 .. 15) := "multiprocessors";
9965 Name_Len := 15;
9966
9967 Selector_Entity := Make_Identifier (Loc, Name_Find);
9968
9969 Prefix_Node :=
9970 Make_Selected_Component
9971 (Sloc => Loc,
9972 Prefix => Prefix_Entity,
9973 Selector_Name => Selector_Entity);
9974
9975 Name_Buffer (1 .. 19) := "dispatching_domains";
9976 Name_Len := 19;
9977
9978 Selector_Entity := Make_Identifier (Loc, Name_Find);
9979
9980 Node :=
9981 Make_Selected_Component
9982 (Sloc => Loc,
9983 Prefix => Prefix_Node,
9984 Selector_Name => Selector_Entity);
9985
9986 Set_Restriction_No_Dependence
9987 (Unit => Node,
9988 Warn => Treat_Restrictions_As_Warnings,
9989 Profile => Ravenscar);
9990 end if;
9991 end Set_Ravenscar_Profile;
9992
9993 -- Start of processing for Analyze_Pragma
9994
9995 begin
9996 -- The following code is a defense against recursion. Not clear that
9997 -- this can happen legitimately, but perhaps some error situations
9998 -- can cause it, and we did see this recursion during testing.
9999
10000 if Analyzed (N) then
10001 return;
10002 else
10003 Set_Analyzed (N, True);
10004 end if;
10005
10006 -- Deal with unrecognized pragma
10007
10008 Pname := Pragma_Name (N);
10009
10010 if not Is_Pragma_Name (Pname) then
10011 if Warn_On_Unrecognized_Pragma then
10012 Error_Msg_Name_1 := Pname;
10013 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
10014
10015 for PN in First_Pragma_Name .. Last_Pragma_Name loop
10016 if Is_Bad_Spelling_Of (Pname, PN) then
10017 Error_Msg_Name_1 := PN;
10018 Error_Msg_N -- CODEFIX
10019 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
10020 exit;
10021 end if;
10022 end loop;
10023 end if;
10024
10025 return;
10026 end if;
10027
10028 -- Here to start processing for recognized pragma
10029
10030 Prag_Id := Get_Pragma_Id (Pname);
10031 Pname := Original_Aspect_Name (N);
10032
10033 -- Capture setting of Opt.Uneval_Old
10034
10035 case Opt.Uneval_Old is
10036 when 'A' =>
10037 Set_Uneval_Old_Accept (N);
10038 when 'E' =>
10039 null;
10040 when 'W' =>
10041 Set_Uneval_Old_Warn (N);
10042 when others =>
10043 raise Program_Error;
10044 end case;
10045
10046 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10047 -- is already set, indicating that we have already checked the policy
10048 -- at the right point. This happens for example in the case of a pragma
10049 -- that is derived from an Aspect.
10050
10051 if Is_Ignored (N) or else Is_Checked (N) then
10052 null;
10053
10054 -- For a pragma that is a rewriting of another pragma, copy the
10055 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10056
10057 elsif Is_Rewrite_Substitution (N)
10058 and then Nkind (Original_Node (N)) = N_Pragma
10059 and then Original_Node (N) /= N
10060 then
10061 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10062 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10063
10064 -- Otherwise query the applicable policy at this point
10065
10066 else
10067 Check_Applicable_Policy (N);
10068
10069 -- If pragma is disabled, rewrite as NULL and skip analysis
10070
10071 if Is_Disabled (N) then
10072 Rewrite (N, Make_Null_Statement (Loc));
10073 Analyze (N);
10074 raise Pragma_Exit;
10075 end if;
10076 end if;
10077
10078 -- Preset arguments
10079
10080 Arg_Count := 0;
10081 Arg1 := Empty;
10082 Arg2 := Empty;
10083 Arg3 := Empty;
10084 Arg4 := Empty;
10085
10086 if Present (Pragma_Argument_Associations (N)) then
10087 Arg_Count := List_Length (Pragma_Argument_Associations (N));
10088 Arg1 := First (Pragma_Argument_Associations (N));
10089
10090 if Present (Arg1) then
10091 Arg2 := Next (Arg1);
10092
10093 if Present (Arg2) then
10094 Arg3 := Next (Arg2);
10095
10096 if Present (Arg3) then
10097 Arg4 := Next (Arg3);
10098 end if;
10099 end if;
10100 end if;
10101 end if;
10102
10103 Check_Restriction_No_Use_Of_Pragma (N);
10104
10105 -- An enumeration type defines the pragmas that are supported by the
10106 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10107 -- into the corresponding enumeration value for the following case.
10108
10109 case Prag_Id is
10110
10111 -----------------
10112 -- Abort_Defer --
10113 -----------------
10114
10115 -- pragma Abort_Defer;
10116
10117 when Pragma_Abort_Defer =>
10118 GNAT_Pragma;
10119 Check_Arg_Count (0);
10120
10121 -- The only required semantic processing is to check the
10122 -- placement. This pragma must appear at the start of the
10123 -- statement sequence of a handled sequence of statements.
10124
10125 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
10126 or else N /= First (Statements (Parent (N)))
10127 then
10128 Pragma_Misplaced;
10129 end if;
10130
10131 --------------------
10132 -- Abstract_State --
10133 --------------------
10134
10135 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10136
10137 -- ABSTRACT_STATE_LIST ::=
10138 -- null
10139 -- | STATE_NAME_WITH_OPTIONS
10140 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
10141
10142 -- STATE_NAME_WITH_OPTIONS ::=
10143 -- STATE_NAME
10144 -- | (STATE_NAME with OPTION_LIST)
10145
10146 -- OPTION_LIST ::= OPTION {, OPTION}
10147
10148 -- OPTION ::=
10149 -- SIMPLE_OPTION
10150 -- | NAME_VALUE_OPTION
10151
10152 -- SIMPLE_OPTION ::= identifier
10153
10154 -- NAME_VALUE_OPTION ::=
10155 -- Part_Of => ABSTRACT_STATE
10156 -- | External [=> EXTERNAL_PROPERTY_LIST]
10157
10158 -- EXTERNAL_PROPERTY_LIST ::=
10159 -- EXTERNAL_PROPERTY
10160 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
10161
10162 -- EXTERNAL_PROPERTY ::=
10163 -- Async_Readers [=> boolean_EXPRESSION]
10164 -- | Async_Writers [=> boolean_EXPRESSION]
10165 -- | Effective_Reads [=> boolean_EXPRESSION]
10166 -- | Effective_Writes [=> boolean_EXPRESSION]
10167 -- others => boolean_EXPRESSION
10168
10169 -- STATE_NAME ::= defining_identifier
10170
10171 -- ABSTRACT_STATE ::= name
10172
10173 when Pragma_Abstract_State => Abstract_State : declare
10174 Missing_Parentheses : Boolean := False;
10175 -- Flag set when a state declaration with options is not properly
10176 -- parenthesized.
10177
10178 -- Flags used to verify the consistency of states
10179
10180 Non_Null_Seen : Boolean := False;
10181 Null_Seen : Boolean := False;
10182
10183 Pack_Id : Entity_Id;
10184 -- Entity of related package when pragma Abstract_State appears
10185
10186 procedure Analyze_Abstract_State (State : Node_Id);
10187 -- Verify the legality of a single state declaration. Create and
10188 -- decorate a state abstraction entity and introduce it into the
10189 -- visibility chain.
10190
10191 ----------------------------
10192 -- Analyze_Abstract_State --
10193 ----------------------------
10194
10195 procedure Analyze_Abstract_State (State : Node_Id) is
10196
10197 -- Flags used to verify the consistency of options
10198
10199 AR_Seen : Boolean := False;
10200 AW_Seen : Boolean := False;
10201 ER_Seen : Boolean := False;
10202 EW_Seen : Boolean := False;
10203 External_Seen : Boolean := False;
10204 Others_Seen : Boolean := False;
10205 Part_Of_Seen : Boolean := False;
10206
10207 -- Flags used to store the static value of all external states'
10208 -- expressions.
10209
10210 AR_Val : Boolean := False;
10211 AW_Val : Boolean := False;
10212 ER_Val : Boolean := False;
10213 EW_Val : Boolean := False;
10214
10215 State_Id : Entity_Id := Empty;
10216 -- The entity to be generated for the current state declaration
10217
10218 procedure Analyze_External_Option (Opt : Node_Id);
10219 -- Verify the legality of option External
10220
10221 procedure Analyze_External_Property
10222 (Prop : Node_Id;
10223 Expr : Node_Id := Empty);
10224 -- Verify the legailty of a single external property. Prop
10225 -- denotes the external property. Expr is the expression used
10226 -- to set the property.
10227
10228 procedure Analyze_Part_Of_Option (Opt : Node_Id);
10229 -- Verify the legality of option Part_Of
10230
10231 procedure Check_Duplicate_Option
10232 (Opt : Node_Id;
10233 Status : in out Boolean);
10234 -- Flag Status denotes whether a particular option has been
10235 -- seen while processing a state. This routine verifies that
10236 -- Opt is not a duplicate option and sets the flag Status
10237 -- (SPARK RM 7.1.4(1)).
10238
10239 procedure Check_Duplicate_Property
10240 (Prop : Node_Id;
10241 Status : in out Boolean);
10242 -- Flag Status denotes whether a particular property has been
10243 -- seen while processing option External. This routine verifies
10244 -- that Prop is not a duplicate property and sets flag Status.
10245 -- Opt is not a duplicate property and sets the flag Status.
10246 -- (SPARK RM 7.1.4(2))
10247
10248 procedure Create_Abstract_State
10249 (Nam : Name_Id;
10250 Decl : Node_Id;
10251 Loc : Source_Ptr;
10252 Is_Null : Boolean);
10253 -- Generate an abstract state entity with name Nam and enter it
10254 -- into visibility. Decl is the "declaration" of the state as
10255 -- it appears in pragma Abstract_State. Loc is the location of
10256 -- the related state "declaration". Flag Is_Null should be set
10257 -- when the associated Abstract_State pragma defines a null
10258 -- state.
10259
10260 -----------------------------
10261 -- Analyze_External_Option --
10262 -----------------------------
10263
10264 procedure Analyze_External_Option (Opt : Node_Id) is
10265 Errors : constant Nat := Serious_Errors_Detected;
10266 Prop : Node_Id;
10267 Props : Node_Id := Empty;
10268
10269 begin
10270 Check_Duplicate_Option (Opt, External_Seen);
10271
10272 if Nkind (Opt) = N_Component_Association then
10273 Props := Expression (Opt);
10274 end if;
10275
10276 -- External state with properties
10277
10278 if Present (Props) then
10279
10280 -- Multiple properties appear as an aggregate
10281
10282 if Nkind (Props) = N_Aggregate then
10283
10284 -- Simple property form
10285
10286 Prop := First (Expressions (Props));
10287 while Present (Prop) loop
10288 Analyze_External_Property (Prop);
10289 Next (Prop);
10290 end loop;
10291
10292 -- Property with expression form
10293
10294 Prop := First (Component_Associations (Props));
10295 while Present (Prop) loop
10296 Analyze_External_Property
10297 (Prop => First (Choices (Prop)),
10298 Expr => Expression (Prop));
10299
10300 Next (Prop);
10301 end loop;
10302
10303 -- Single property
10304
10305 else
10306 Analyze_External_Property (Props);
10307 end if;
10308
10309 -- An external state defined without any properties defaults
10310 -- all properties to True.
10311
10312 else
10313 AR_Val := True;
10314 AW_Val := True;
10315 ER_Val := True;
10316 EW_Val := True;
10317 end if;
10318
10319 -- Once all external properties have been processed, verify
10320 -- their mutual interaction. Do not perform the check when
10321 -- at least one of the properties is illegal as this will
10322 -- produce a bogus error.
10323
10324 if Errors = Serious_Errors_Detected then
10325 Check_External_Properties
10326 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10327 end if;
10328 end Analyze_External_Option;
10329
10330 -------------------------------
10331 -- Analyze_External_Property --
10332 -------------------------------
10333
10334 procedure Analyze_External_Property
10335 (Prop : Node_Id;
10336 Expr : Node_Id := Empty)
10337 is
10338 Expr_Val : Boolean;
10339
10340 begin
10341 -- Check the placement of "others" (if available)
10342
10343 if Nkind (Prop) = N_Others_Choice then
10344 if Others_Seen then
10345 SPARK_Msg_N
10346 ("only one others choice allowed in option External",
10347 Prop);
10348 else
10349 Others_Seen := True;
10350 end if;
10351
10352 elsif Others_Seen then
10353 SPARK_Msg_N
10354 ("others must be the last property in option External",
10355 Prop);
10356
10357 -- The only remaining legal options are the four predefined
10358 -- external properties.
10359
10360 elsif Nkind (Prop) = N_Identifier
10361 and then Nam_In (Chars (Prop), Name_Async_Readers,
10362 Name_Async_Writers,
10363 Name_Effective_Reads,
10364 Name_Effective_Writes)
10365 then
10366 null;
10367
10368 -- Otherwise the construct is not a valid property
10369
10370 else
10371 SPARK_Msg_N ("invalid external state property", Prop);
10372 return;
10373 end if;
10374
10375 -- Ensure that the expression of the external state property
10376 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10377
10378 if Present (Expr) then
10379 Analyze_And_Resolve (Expr, Standard_Boolean);
10380
10381 if Is_OK_Static_Expression (Expr) then
10382 Expr_Val := Is_True (Expr_Value (Expr));
10383 else
10384 SPARK_Msg_N
10385 ("expression of external state property must be "
10386 & "static", Expr);
10387 end if;
10388
10389 -- The lack of expression defaults the property to True
10390
10391 else
10392 Expr_Val := True;
10393 end if;
10394
10395 -- Named properties
10396
10397 if Nkind (Prop) = N_Identifier then
10398 if Chars (Prop) = Name_Async_Readers then
10399 Check_Duplicate_Property (Prop, AR_Seen);
10400 AR_Val := Expr_Val;
10401
10402 elsif Chars (Prop) = Name_Async_Writers then
10403 Check_Duplicate_Property (Prop, AW_Seen);
10404 AW_Val := Expr_Val;
10405
10406 elsif Chars (Prop) = Name_Effective_Reads then
10407 Check_Duplicate_Property (Prop, ER_Seen);
10408 ER_Val := Expr_Val;
10409
10410 else
10411 Check_Duplicate_Property (Prop, EW_Seen);
10412 EW_Val := Expr_Val;
10413 end if;
10414
10415 -- The handling of property "others" must take into account
10416 -- all other named properties that have been encountered so
10417 -- far. Only those that have not been seen are affected by
10418 -- "others".
10419
10420 else
10421 if not AR_Seen then
10422 AR_Val := Expr_Val;
10423 end if;
10424
10425 if not AW_Seen then
10426 AW_Val := Expr_Val;
10427 end if;
10428
10429 if not ER_Seen then
10430 ER_Val := Expr_Val;
10431 end if;
10432
10433 if not EW_Seen then
10434 EW_Val := Expr_Val;
10435 end if;
10436 end if;
10437 end Analyze_External_Property;
10438
10439 ----------------------------
10440 -- Analyze_Part_Of_Option --
10441 ----------------------------
10442
10443 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10444 Encaps : constant Node_Id := Expression (Opt);
10445 Encaps_Id : Entity_Id;
10446 Legal : Boolean;
10447
10448 begin
10449 Check_Duplicate_Option (Opt, Part_Of_Seen);
10450
10451 Analyze_Part_Of
10452 (Item_Id => State_Id,
10453 State => Encaps,
10454 Indic => First (Choices (Opt)),
10455 Legal => Legal);
10456
10457 -- The Part_Of indicator turns an abstract state into a
10458 -- constituent of the encapsulating state.
10459
10460 if Legal then
10461 Encaps_Id := Entity (Encaps);
10462
10463 Append_Elmt (State_Id, Part_Of_Constituents (Encaps_Id));
10464 Set_Encapsulating_State (State_Id, Encaps_Id);
10465 end if;
10466 end Analyze_Part_Of_Option;
10467
10468 ----------------------------
10469 -- Check_Duplicate_Option --
10470 ----------------------------
10471
10472 procedure Check_Duplicate_Option
10473 (Opt : Node_Id;
10474 Status : in out Boolean)
10475 is
10476 begin
10477 if Status then
10478 SPARK_Msg_N ("duplicate state option", Opt);
10479 end if;
10480
10481 Status := True;
10482 end Check_Duplicate_Option;
10483
10484 ------------------------------
10485 -- Check_Duplicate_Property --
10486 ------------------------------
10487
10488 procedure Check_Duplicate_Property
10489 (Prop : Node_Id;
10490 Status : in out Boolean)
10491 is
10492 begin
10493 if Status then
10494 SPARK_Msg_N ("duplicate external property", Prop);
10495 end if;
10496
10497 Status := True;
10498 end Check_Duplicate_Property;
10499
10500 ---------------------------
10501 -- Create_Abstract_State --
10502 ---------------------------
10503
10504 procedure Create_Abstract_State
10505 (Nam : Name_Id;
10506 Decl : Node_Id;
10507 Loc : Source_Ptr;
10508 Is_Null : Boolean)
10509 is
10510 begin
10511 -- The abstract state may be semi-declared when the related
10512 -- package was withed through a limited with clause. In that
10513 -- case reuse the entity to fully declare the state.
10514
10515 if Present (Decl) and then Present (Entity (Decl)) then
10516 State_Id := Entity (Decl);
10517
10518 -- Otherwise the elaboration of pragma Abstract_State
10519 -- declares the state.
10520
10521 else
10522 State_Id := Make_Defining_Identifier (Loc, Nam);
10523
10524 if Present (Decl) then
10525 Set_Entity (Decl, State_Id);
10526 end if;
10527 end if;
10528
10529 -- Null states never come from source
10530
10531 Set_Comes_From_Source (State_Id, not Is_Null);
10532 Set_Parent (State_Id, State);
10533 Set_Ekind (State_Id, E_Abstract_State);
10534 Set_Etype (State_Id, Standard_Void_Type);
10535 Set_Encapsulating_State (State_Id, Empty);
10536 Set_Refinement_Constituents (State_Id, New_Elmt_List);
10537 Set_Part_Of_Constituents (State_Id, New_Elmt_List);
10538
10539 -- Establish a link between the state declaration and the
10540 -- abstract state entity. Note that a null state remains as
10541 -- N_Null and does not carry any linkages.
10542
10543 if not Is_Null then
10544 if Present (Decl) then
10545 Set_Entity (Decl, State_Id);
10546 Set_Etype (Decl, Standard_Void_Type);
10547 end if;
10548
10549 -- Every non-null state must be defined, nameable and
10550 -- resolvable.
10551
10552 Push_Scope (Pack_Id);
10553 Generate_Definition (State_Id);
10554 Enter_Name (State_Id);
10555 Pop_Scope;
10556 end if;
10557 end Create_Abstract_State;
10558
10559 -- Local variables
10560
10561 Opt : Node_Id;
10562 Opt_Nam : Node_Id;
10563
10564 -- Start of processing for Analyze_Abstract_State
10565
10566 begin
10567 -- A package with a null abstract state is not allowed to
10568 -- declare additional states.
10569
10570 if Null_Seen then
10571 SPARK_Msg_NE
10572 ("package & has null abstract state", State, Pack_Id);
10573
10574 -- Null states appear as internally generated entities
10575
10576 elsif Nkind (State) = N_Null then
10577 Create_Abstract_State
10578 (Nam => New_Internal_Name ('S'),
10579 Decl => Empty,
10580 Loc => Sloc (State),
10581 Is_Null => True);
10582 Null_Seen := True;
10583
10584 -- Catch a case where a null state appears in a list of
10585 -- non-null states.
10586
10587 if Non_Null_Seen then
10588 SPARK_Msg_NE
10589 ("package & has non-null abstract state",
10590 State, Pack_Id);
10591 end if;
10592
10593 -- Simple state declaration
10594
10595 elsif Nkind (State) = N_Identifier then
10596 Create_Abstract_State
10597 (Nam => Chars (State),
10598 Decl => State,
10599 Loc => Sloc (State),
10600 Is_Null => False);
10601 Non_Null_Seen := True;
10602
10603 -- State declaration with various options. This construct
10604 -- appears as an extension aggregate in the tree.
10605
10606 elsif Nkind (State) = N_Extension_Aggregate then
10607 if Nkind (Ancestor_Part (State)) = N_Identifier then
10608 Create_Abstract_State
10609 (Nam => Chars (Ancestor_Part (State)),
10610 Decl => Ancestor_Part (State),
10611 Loc => Sloc (Ancestor_Part (State)),
10612 Is_Null => False);
10613 Non_Null_Seen := True;
10614 else
10615 SPARK_Msg_N
10616 ("state name must be an identifier",
10617 Ancestor_Part (State));
10618 end if;
10619
10620 -- Catch an attempt to introduce a simple option which is
10621 -- currently not allowed. An exception to this is External
10622 -- defined without any properties.
10623
10624 Opt := First (Expressions (State));
10625 while Present (Opt) loop
10626 if Nkind (Opt) = N_Identifier then
10627 if Chars (Opt) = Name_External then
10628 Analyze_External_Option (Opt);
10629
10630 -- Option Part_Of without an encapsulating state is
10631 -- illegal. (SPARK RM 7.1.4(9)).
10632
10633 elsif Chars (Opt) = Name_Part_Of then
10634 SPARK_Msg_N
10635 ("indicator Part_Of must denote an abstract "
10636 & "state", Opt);
10637
10638 -- Do not emit an error message when a previous state
10639 -- declaration with options was not parenthesized as
10640 -- the option is actually another state declaration.
10641 --
10642 -- with Abstract_State
10643 -- (State_1 with ..., -- missing parentheses
10644 -- (State_2 with ...),
10645 -- State_3) -- ok state declaration
10646
10647 elsif Missing_Parentheses then
10648 null;
10649
10650 -- Otherwise the option is not allowed. Note that it
10651 -- is not possible to distinguish between an option
10652 -- and a state declaration when a previous state with
10653 -- options not properly parentheses.
10654 --
10655 -- with Abstract_State
10656 -- (State_1 with ..., -- missing parentheses
10657 -- State_2); -- could be an option
10658
10659 else
10660 SPARK_Msg_N
10661 ("simple option not allowed in state declaration",
10662 Opt);
10663 end if;
10664
10665 -- Catch a case where missing parentheses around a state
10666 -- declaration with options cause a subsequent state
10667 -- declaration with options to be treated as an option.
10668 --
10669 -- with Abstract_State
10670 -- (State_1 with ..., -- missing parentheses
10671 -- (State_2 with ...))
10672
10673 elsif Nkind (Opt) = N_Extension_Aggregate then
10674 Missing_Parentheses := True;
10675 SPARK_Msg_N
10676 ("state declaration must be parenthesized",
10677 Ancestor_Part (State));
10678
10679 -- Otherwise the option is malformed
10680
10681 else
10682 SPARK_Msg_N ("malformed option", Opt);
10683 end if;
10684
10685 Next (Opt);
10686 end loop;
10687
10688 -- Options External and Part_Of appear as component
10689 -- associations.
10690
10691 Opt := First (Component_Associations (State));
10692 while Present (Opt) loop
10693 Opt_Nam := First (Choices (Opt));
10694
10695 if Nkind (Opt_Nam) = N_Identifier then
10696 if Chars (Opt_Nam) = Name_External then
10697 Analyze_External_Option (Opt);
10698
10699 elsif Chars (Opt_Nam) = Name_Part_Of then
10700 Analyze_Part_Of_Option (Opt);
10701
10702 else
10703 SPARK_Msg_N ("invalid state option", Opt);
10704 end if;
10705 else
10706 SPARK_Msg_N ("invalid state option", Opt);
10707 end if;
10708
10709 Next (Opt);
10710 end loop;
10711
10712 -- Any other attempt to declare a state is illegal. This is a
10713 -- syntax error, always report.
10714
10715 else
10716 Error_Msg_N ("malformed abstract state declaration", State);
10717 return;
10718 end if;
10719
10720 -- Guard against a junk state. In such cases no entity is
10721 -- generated and the subsequent checks cannot be applied.
10722
10723 if Present (State_Id) then
10724
10725 -- Verify whether the state does not introduce an illegal
10726 -- hidden state within a package subject to a null abstract
10727 -- state.
10728
10729 Check_No_Hidden_State (State_Id);
10730
10731 -- Check whether the lack of option Part_Of agrees with the
10732 -- placement of the abstract state with respect to the state
10733 -- space.
10734
10735 if not Part_Of_Seen then
10736 Check_Missing_Part_Of (State_Id);
10737 end if;
10738
10739 -- Associate the state with its related package
10740
10741 if No (Abstract_States (Pack_Id)) then
10742 Set_Abstract_States (Pack_Id, New_Elmt_List);
10743 end if;
10744
10745 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10746 end if;
10747 end Analyze_Abstract_State;
10748
10749 -- Local variables
10750
10751 Context : constant Node_Id := Parent (Parent (N));
10752 State : Node_Id;
10753
10754 -- Start of processing for Abstract_State
10755
10756 begin
10757 GNAT_Pragma;
10758 Check_Arg_Count (1);
10759 Ensure_Aggregate_Form (Arg1);
10760
10761 -- Ensure the proper placement of the pragma. Abstract states must
10762 -- be associated with a package declaration.
10763
10764 if not Nkind_In (Context, N_Generic_Package_Declaration,
10765 N_Package_Declaration)
10766 then
10767 Pragma_Misplaced;
10768 return;
10769 end if;
10770
10771 State := Expression (Arg1);
10772 Pack_Id := Defining_Entity (Context);
10773
10774 -- Multiple non-null abstract states appear as an aggregate
10775
10776 if Nkind (State) = N_Aggregate then
10777 State := First (Expressions (State));
10778 while Present (State) loop
10779 Analyze_Abstract_State (State);
10780 Next (State);
10781 end loop;
10782
10783 -- Various forms of a single abstract state. Note that these may
10784 -- include malformed state declarations.
10785
10786 else
10787 Analyze_Abstract_State (State);
10788 end if;
10789
10790 -- Save the pragma for retrieval by other tools
10791
10792 Add_Contract_Item (N, Pack_Id);
10793
10794 -- Verify the declaration order of pragmas Abstract_State and
10795 -- Initializes.
10796
10797 Check_Declaration_Order
10798 (First => N,
10799 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
10800 end Abstract_State;
10801
10802 ------------
10803 -- Ada_83 --
10804 ------------
10805
10806 -- pragma Ada_83;
10807
10808 -- Note: this pragma also has some specific processing in Par.Prag
10809 -- because we want to set the Ada version mode during parsing.
10810
10811 when Pragma_Ada_83 =>
10812 GNAT_Pragma;
10813 Check_Arg_Count (0);
10814
10815 -- We really should check unconditionally for proper configuration
10816 -- pragma placement, since we really don't want mixed Ada modes
10817 -- within a single unit, and the GNAT reference manual has always
10818 -- said this was a configuration pragma, but we did not check and
10819 -- are hesitant to add the check now.
10820
10821 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10822 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10823 -- or Ada 2012 mode.
10824
10825 if Ada_Version >= Ada_2005 then
10826 Check_Valid_Configuration_Pragma;
10827 end if;
10828
10829 -- Now set Ada 83 mode
10830
10831 Ada_Version := Ada_83;
10832 Ada_Version_Explicit := Ada_83;
10833 Ada_Version_Pragma := N;
10834
10835 ------------
10836 -- Ada_95 --
10837 ------------
10838
10839 -- pragma Ada_95;
10840
10841 -- Note: this pragma also has some specific processing in Par.Prag
10842 -- because we want to set the Ada 83 version mode during parsing.
10843
10844 when Pragma_Ada_95 =>
10845 GNAT_Pragma;
10846 Check_Arg_Count (0);
10847
10848 -- We really should check unconditionally for proper configuration
10849 -- pragma placement, since we really don't want mixed Ada modes
10850 -- within a single unit, and the GNAT reference manual has always
10851 -- said this was a configuration pragma, but we did not check and
10852 -- are hesitant to add the check now.
10853
10854 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10855 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10856
10857 if Ada_Version >= Ada_2005 then
10858 Check_Valid_Configuration_Pragma;
10859 end if;
10860
10861 -- Now set Ada 95 mode
10862
10863 Ada_Version := Ada_95;
10864 Ada_Version_Explicit := Ada_95;
10865 Ada_Version_Pragma := N;
10866
10867 ---------------------
10868 -- Ada_05/Ada_2005 --
10869 ---------------------
10870
10871 -- pragma Ada_05;
10872 -- pragma Ada_05 (LOCAL_NAME);
10873
10874 -- pragma Ada_2005;
10875 -- pragma Ada_2005 (LOCAL_NAME):
10876
10877 -- Note: these pragmas also have some specific processing in Par.Prag
10878 -- because we want to set the Ada 2005 version mode during parsing.
10879
10880 -- The one argument form is used for managing the transition from
10881 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10882 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10883 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10884 -- mode, a preference rule is established which does not choose
10885 -- such an entity unless it is unambiguously specified. This avoids
10886 -- extra subprograms marked this way from generating ambiguities in
10887 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10888 -- intended for exclusive use in the GNAT run-time library.
10889
10890 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
10891 E_Id : Node_Id;
10892
10893 begin
10894 GNAT_Pragma;
10895
10896 if Arg_Count = 1 then
10897 Check_Arg_Is_Local_Name (Arg1);
10898 E_Id := Get_Pragma_Arg (Arg1);
10899
10900 if Etype (E_Id) = Any_Type then
10901 return;
10902 end if;
10903
10904 Set_Is_Ada_2005_Only (Entity (E_Id));
10905 Record_Rep_Item (Entity (E_Id), N);
10906
10907 else
10908 Check_Arg_Count (0);
10909
10910 -- For Ada_2005 we unconditionally enforce the documented
10911 -- configuration pragma placement, since we do not want to
10912 -- tolerate mixed modes in a unit involving Ada 2005. That
10913 -- would cause real difficulties for those cases where there
10914 -- are incompatibilities between Ada 95 and Ada 2005.
10915
10916 Check_Valid_Configuration_Pragma;
10917
10918 -- Now set appropriate Ada mode
10919
10920 Ada_Version := Ada_2005;
10921 Ada_Version_Explicit := Ada_2005;
10922 Ada_Version_Pragma := N;
10923 end if;
10924 end;
10925
10926 ---------------------
10927 -- Ada_12/Ada_2012 --
10928 ---------------------
10929
10930 -- pragma Ada_12;
10931 -- pragma Ada_12 (LOCAL_NAME);
10932
10933 -- pragma Ada_2012;
10934 -- pragma Ada_2012 (LOCAL_NAME):
10935
10936 -- Note: these pragmas also have some specific processing in Par.Prag
10937 -- because we want to set the Ada 2012 version mode during parsing.
10938
10939 -- The one argument form is used for managing the transition from Ada
10940 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
10941 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
10942 -- mode will generate a warning. In addition, in any pre-Ada_2012
10943 -- mode, a preference rule is established which does not choose
10944 -- such an entity unless it is unambiguously specified. This avoids
10945 -- extra subprograms marked this way from generating ambiguities in
10946 -- otherwise legal pre-Ada_2012 programs. The one argument form is
10947 -- intended for exclusive use in the GNAT run-time library.
10948
10949 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
10950 E_Id : Node_Id;
10951
10952 begin
10953 GNAT_Pragma;
10954
10955 if Arg_Count = 1 then
10956 Check_Arg_Is_Local_Name (Arg1);
10957 E_Id := Get_Pragma_Arg (Arg1);
10958
10959 if Etype (E_Id) = Any_Type then
10960 return;
10961 end if;
10962
10963 Set_Is_Ada_2012_Only (Entity (E_Id));
10964 Record_Rep_Item (Entity (E_Id), N);
10965
10966 else
10967 Check_Arg_Count (0);
10968
10969 -- For Ada_2012 we unconditionally enforce the documented
10970 -- configuration pragma placement, since we do not want to
10971 -- tolerate mixed modes in a unit involving Ada 2012. That
10972 -- would cause real difficulties for those cases where there
10973 -- are incompatibilities between Ada 95 and Ada 2012. We could
10974 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
10975
10976 Check_Valid_Configuration_Pragma;
10977
10978 -- Now set appropriate Ada mode
10979
10980 Ada_Version := Ada_2012;
10981 Ada_Version_Explicit := Ada_2012;
10982 Ada_Version_Pragma := N;
10983 end if;
10984 end;
10985
10986 ----------------------
10987 -- All_Calls_Remote --
10988 ----------------------
10989
10990 -- pragma All_Calls_Remote [(library_package_NAME)];
10991
10992 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
10993 Lib_Entity : Entity_Id;
10994
10995 begin
10996 Check_Ada_83_Warning;
10997 Check_Valid_Library_Unit_Pragma;
10998
10999 if Nkind (N) = N_Null_Statement then
11000 return;
11001 end if;
11002
11003 Lib_Entity := Find_Lib_Unit_Name;
11004
11005 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11006
11007 if Present (Lib_Entity)
11008 and then not Debug_Flag_U
11009 then
11010 if not Is_Remote_Call_Interface (Lib_Entity) then
11011 Error_Pragma ("pragma% only apply to rci unit");
11012
11013 -- Set flag for entity of the library unit
11014
11015 else
11016 Set_Has_All_Calls_Remote (Lib_Entity);
11017 end if;
11018
11019 end if;
11020 end All_Calls_Remote;
11021
11022 ---------------------------
11023 -- Allow_Integer_Address --
11024 ---------------------------
11025
11026 -- pragma Allow_Integer_Address;
11027
11028 when Pragma_Allow_Integer_Address =>
11029 GNAT_Pragma;
11030 Check_Valid_Configuration_Pragma;
11031 Check_Arg_Count (0);
11032
11033 -- If Address is a private type, then set the flag to allow
11034 -- integer address values. If Address is not private (e.g. on
11035 -- VMS, where it is an integer type), then this pragma has no
11036 -- purpose, so it is simply ignored.
11037
11038 if Opt.Address_Is_Private then
11039 Opt.Allow_Integer_Address := True;
11040 end if;
11041
11042 --------------
11043 -- Annotate --
11044 --------------
11045
11046 -- pragma Annotate
11047 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11048 -- ARG ::= NAME | EXPRESSION
11049
11050 -- The first two arguments are by convention intended to refer to an
11051 -- external tool and a tool-specific function. These arguments are
11052 -- not analyzed.
11053
11054 when Pragma_Annotate => Annotate : declare
11055 Arg : Node_Id;
11056 Exp : Node_Id;
11057
11058 begin
11059 GNAT_Pragma;
11060 Check_At_Least_N_Arguments (1);
11061
11062 -- See if last argument is Entity => local_Name, and if so process
11063 -- and then remove it for remaining processing.
11064
11065 declare
11066 Last_Arg : constant Node_Id :=
11067 Last (Pragma_Argument_Associations (N));
11068
11069 begin
11070 if Nkind (Last_Arg) = N_Pragma_Argument_Association
11071 and then Chars (Last_Arg) = Name_Entity
11072 then
11073 Check_Arg_Is_Local_Name (Last_Arg);
11074 Arg_Count := Arg_Count - 1;
11075
11076 -- Not allowed in compiler units (bootstrap issues)
11077
11078 Check_Compiler_Unit ("Entity for pragma Annotate", N);
11079 end if;
11080 end;
11081
11082 -- Continue processing with last argument removed for now
11083
11084 Check_Arg_Is_Identifier (Arg1);
11085 Check_No_Identifiers;
11086 Store_Note (N);
11087
11088 -- Second parameter is optional, it is never analyzed
11089
11090 if No (Arg2) then
11091 null;
11092
11093 -- Here if we have a second parameter
11094
11095 else
11096 -- Second parameter must be identifier
11097
11098 Check_Arg_Is_Identifier (Arg2);
11099
11100 -- Process remaining parameters if any
11101
11102 Arg := Next (Arg2);
11103 while Present (Arg) loop
11104 Exp := Get_Pragma_Arg (Arg);
11105 Analyze (Exp);
11106
11107 if Is_Entity_Name (Exp) then
11108 null;
11109
11110 -- For string literals, we assume Standard_String as the
11111 -- type, unless the string contains wide or wide_wide
11112 -- characters.
11113
11114 elsif Nkind (Exp) = N_String_Literal then
11115 if Has_Wide_Wide_Character (Exp) then
11116 Resolve (Exp, Standard_Wide_Wide_String);
11117 elsif Has_Wide_Character (Exp) then
11118 Resolve (Exp, Standard_Wide_String);
11119 else
11120 Resolve (Exp, Standard_String);
11121 end if;
11122
11123 elsif Is_Overloaded (Exp) then
11124 Error_Pragma_Arg
11125 ("ambiguous argument for pragma%", Exp);
11126
11127 else
11128 Resolve (Exp);
11129 end if;
11130
11131 Next (Arg);
11132 end loop;
11133 end if;
11134 end Annotate;
11135
11136 -------------------------------------------------
11137 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11138 -------------------------------------------------
11139
11140 -- pragma Assert
11141 -- ( [Check => ] Boolean_EXPRESSION
11142 -- [, [Message =>] Static_String_EXPRESSION]);
11143
11144 -- pragma Assert_And_Cut
11145 -- ( [Check => ] Boolean_EXPRESSION
11146 -- [, [Message =>] Static_String_EXPRESSION]);
11147
11148 -- pragma Assume
11149 -- ( [Check => ] Boolean_EXPRESSION
11150 -- [, [Message =>] Static_String_EXPRESSION]);
11151
11152 -- pragma Loop_Invariant
11153 -- ( [Check => ] Boolean_EXPRESSION
11154 -- [, [Message =>] Static_String_EXPRESSION]);
11155
11156 when Pragma_Assert |
11157 Pragma_Assert_And_Cut |
11158 Pragma_Assume |
11159 Pragma_Loop_Invariant =>
11160 Assert : declare
11161 Expr : Node_Id;
11162 Newa : List_Id;
11163
11164 Has_Loop_Entry : Boolean;
11165 -- Set True by
11166
11167 function Contains_Loop_Entry return Boolean;
11168 -- Tests if Expr contains a Loop_Entry attribute reference
11169
11170 -------------------------
11171 -- Contains_Loop_Entry --
11172 -------------------------
11173
11174 function Contains_Loop_Entry return Boolean is
11175 function Process (N : Node_Id) return Traverse_Result;
11176 -- Process function for traversal to look for Loop_Entry
11177
11178 -------------
11179 -- Process --
11180 -------------
11181
11182 function Process (N : Node_Id) return Traverse_Result is
11183 begin
11184 if Nkind (N) = N_Attribute_Reference
11185 and then Attribute_Name (N) = Name_Loop_Entry
11186 then
11187 Has_Loop_Entry := True;
11188 return Abandon;
11189 else
11190 return OK;
11191 end if;
11192 end Process;
11193
11194 procedure Traverse is new Traverse_Proc (Process);
11195
11196 -- Start of processing for Contains_Loop_Entry
11197
11198 begin
11199 Has_Loop_Entry := False;
11200 Traverse (Expr);
11201 return Has_Loop_Entry;
11202 end Contains_Loop_Entry;
11203
11204 -- Start of processing for Assert
11205
11206 begin
11207 -- Assert is an Ada 2005 RM-defined pragma
11208
11209 if Prag_Id = Pragma_Assert then
11210 Ada_2005_Pragma;
11211
11212 -- The remaining ones are GNAT pragmas
11213
11214 else
11215 GNAT_Pragma;
11216 end if;
11217
11218 Check_At_Least_N_Arguments (1);
11219 Check_At_Most_N_Arguments (2);
11220 Check_Arg_Order ((Name_Check, Name_Message));
11221 Check_Optional_Identifier (Arg1, Name_Check);
11222 Expr := Get_Pragma_Arg (Arg1);
11223
11224 -- Special processing for Loop_Invariant or for other cases if
11225 -- a Loop_Entry attribute is present.
11226
11227 if Prag_Id = Pragma_Loop_Invariant
11228 or else Contains_Loop_Entry
11229 then
11230 -- Check restricted placement, must be within a loop
11231
11232 Check_Loop_Pragma_Placement;
11233
11234 -- Do preanalyze to deal with embedded Loop_Entry attribute
11235
11236 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
11237 end if;
11238
11239 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11240 -- a corresponding Check pragma:
11241
11242 -- pragma Check (name, condition [, msg]);
11243
11244 -- Where name is the identifier matching the pragma name. So
11245 -- rewrite pragma in this manner, transfer the message argument
11246 -- if present, and analyze the result
11247
11248 -- Note: When dealing with a semantically analyzed tree, the
11249 -- information that a Check node N corresponds to a source Assert,
11250 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11251 -- pragma kind of Original_Node(N).
11252
11253 Newa := New_List (
11254 Make_Pragma_Argument_Association (Loc,
11255 Expression => Make_Identifier (Loc, Pname)),
11256 Make_Pragma_Argument_Association (Sloc (Expr),
11257 Expression => Expr));
11258
11259 if Arg_Count > 1 then
11260 Check_Optional_Identifier (Arg2, Name_Message);
11261 Append_To (Newa, New_Copy_Tree (Arg2));
11262 end if;
11263
11264 -- Rewrite as Check pragma
11265
11266 Rewrite (N,
11267 Make_Pragma (Loc,
11268 Chars => Name_Check,
11269 Pragma_Argument_Associations => Newa));
11270 Analyze (N);
11271 end Assert;
11272
11273 ----------------------
11274 -- Assertion_Policy --
11275 ----------------------
11276
11277 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11278
11279 -- The following form is Ada 2012 only, but we allow it in all modes
11280
11281 -- Pragma Assertion_Policy (
11282 -- ASSERTION_KIND => POLICY_IDENTIFIER
11283 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11284
11285 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11286
11287 -- RM_ASSERTION_KIND ::= Assert |
11288 -- Static_Predicate |
11289 -- Dynamic_Predicate |
11290 -- Pre |
11291 -- Pre'Class |
11292 -- Post |
11293 -- Post'Class |
11294 -- Type_Invariant |
11295 -- Type_Invariant'Class
11296
11297 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11298 -- Assume |
11299 -- Contract_Cases |
11300 -- Debug |
11301 -- Initial_Condition |
11302 -- Loop_Invariant |
11303 -- Loop_Variant |
11304 -- Postcondition |
11305 -- Precondition |
11306 -- Predicate |
11307 -- Refined_Post |
11308 -- Statement_Assertions
11309
11310 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11311 -- ID_ASSERTION_KIND list contains implementation-defined additions
11312 -- recognized by GNAT. The effect is to control the behavior of
11313 -- identically named aspects and pragmas, depending on the specified
11314 -- policy identifier:
11315
11316 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11317
11318 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11319 -- implementation defined addition that results in totally ignoring
11320 -- the corresponding assertion. If Disable is specified, then the
11321 -- argument of the assertion is not even analyzed. This is useful
11322 -- when the aspect/pragma argument references entities in a with'ed
11323 -- package that is replaced by a dummy package in the final build.
11324
11325 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11326 -- and Type_Invariant'Class were recognized by the parser and
11327 -- transformed into references to the special internal identifiers
11328 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11329 -- processing is required here.
11330
11331 when Pragma_Assertion_Policy => Assertion_Policy : declare
11332 LocP : Source_Ptr;
11333 Policy : Node_Id;
11334 Arg : Node_Id;
11335 Kind : Name_Id;
11336
11337 begin
11338 Ada_2005_Pragma;
11339
11340 -- This can always appear as a configuration pragma
11341
11342 if Is_Configuration_Pragma then
11343 null;
11344
11345 -- It can also appear in a declarative part or package spec in Ada
11346 -- 2012 mode. We allow this in other modes, but in that case we
11347 -- consider that we have an Ada 2012 pragma on our hands.
11348
11349 else
11350 Check_Is_In_Decl_Part_Or_Package_Spec;
11351 Ada_2012_Pragma;
11352 end if;
11353
11354 -- One argument case with no identifier (first form above)
11355
11356 if Arg_Count = 1
11357 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
11358 or else Chars (Arg1) = No_Name)
11359 then
11360 Check_Arg_Is_One_Of
11361 (Arg1, Name_Check, Name_Disable, Name_Ignore);
11362
11363 -- Treat one argument Assertion_Policy as equivalent to:
11364
11365 -- pragma Check_Policy (Assertion, policy)
11366
11367 -- So rewrite pragma in that manner and link on to the chain
11368 -- of Check_Policy pragmas, marking the pragma as analyzed.
11369
11370 Policy := Get_Pragma_Arg (Arg1);
11371
11372 Rewrite (N,
11373 Make_Pragma (Loc,
11374 Chars => Name_Check_Policy,
11375 Pragma_Argument_Associations => New_List (
11376 Make_Pragma_Argument_Association (Loc,
11377 Expression => Make_Identifier (Loc, Name_Assertion)),
11378
11379 Make_Pragma_Argument_Association (Loc,
11380 Expression =>
11381 Make_Identifier (Sloc (Policy), Chars (Policy))))));
11382 Analyze (N);
11383
11384 -- Here if we have two or more arguments
11385
11386 else
11387 Check_At_Least_N_Arguments (1);
11388 Ada_2012_Pragma;
11389
11390 -- Loop through arguments
11391
11392 Arg := Arg1;
11393 while Present (Arg) loop
11394 LocP := Sloc (Arg);
11395
11396 -- Kind must be specified
11397
11398 if Nkind (Arg) /= N_Pragma_Argument_Association
11399 or else Chars (Arg) = No_Name
11400 then
11401 Error_Pragma_Arg
11402 ("missing assertion kind for pragma%", Arg);
11403 end if;
11404
11405 -- Check Kind and Policy have allowed forms
11406
11407 Kind := Chars (Arg);
11408
11409 if not Is_Valid_Assertion_Kind (Kind) then
11410 Error_Pragma_Arg
11411 ("invalid assertion kind for pragma%", Arg);
11412 end if;
11413
11414 Check_Arg_Is_One_Of
11415 (Arg, Name_Check, Name_Disable, Name_Ignore);
11416
11417 -- We rewrite the Assertion_Policy pragma as a series of
11418 -- Check_Policy pragmas:
11419
11420 -- Check_Policy (Kind, Policy);
11421
11422 Insert_Action (N,
11423 Make_Pragma (LocP,
11424 Chars => Name_Check_Policy,
11425 Pragma_Argument_Associations => New_List (
11426 Make_Pragma_Argument_Association (LocP,
11427 Expression => Make_Identifier (LocP, Kind)),
11428 Make_Pragma_Argument_Association (LocP,
11429 Expression => Get_Pragma_Arg (Arg)))));
11430
11431 Arg := Next (Arg);
11432 end loop;
11433
11434 -- Rewrite the Assertion_Policy pragma as null since we have
11435 -- now inserted all the equivalent Check pragmas.
11436
11437 Rewrite (N, Make_Null_Statement (Loc));
11438 Analyze (N);
11439 end if;
11440 end Assertion_Policy;
11441
11442 ------------------------------
11443 -- Assume_No_Invalid_Values --
11444 ------------------------------
11445
11446 -- pragma Assume_No_Invalid_Values (On | Off);
11447
11448 when Pragma_Assume_No_Invalid_Values =>
11449 GNAT_Pragma;
11450 Check_Valid_Configuration_Pragma;
11451 Check_Arg_Count (1);
11452 Check_No_Identifiers;
11453 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11454
11455 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11456 Assume_No_Invalid_Values := True;
11457 else
11458 Assume_No_Invalid_Values := False;
11459 end if;
11460
11461 --------------------------
11462 -- Attribute_Definition --
11463 --------------------------
11464
11465 -- pragma Attribute_Definition
11466 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11467 -- [Entity =>] LOCAL_NAME,
11468 -- [Expression =>] EXPRESSION | NAME);
11469
11470 when Pragma_Attribute_Definition => Attribute_Definition : declare
11471 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11472 Aname : Name_Id;
11473
11474 begin
11475 GNAT_Pragma;
11476 Check_Arg_Count (3);
11477 Check_Optional_Identifier (Arg1, "attribute");
11478 Check_Optional_Identifier (Arg2, "entity");
11479 Check_Optional_Identifier (Arg3, "expression");
11480
11481 if Nkind (Attribute_Designator) /= N_Identifier then
11482 Error_Msg_N ("attribute name expected", Attribute_Designator);
11483 return;
11484 end if;
11485
11486 Check_Arg_Is_Local_Name (Arg2);
11487
11488 -- If the attribute is not recognized, then issue a warning (not
11489 -- an error), and ignore the pragma.
11490
11491 Aname := Chars (Attribute_Designator);
11492
11493 if not Is_Attribute_Name (Aname) then
11494 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11495 return;
11496 end if;
11497
11498 -- Otherwise, rewrite the pragma as an attribute definition clause
11499
11500 Rewrite (N,
11501 Make_Attribute_Definition_Clause (Loc,
11502 Name => Get_Pragma_Arg (Arg2),
11503 Chars => Aname,
11504 Expression => Get_Pragma_Arg (Arg3)));
11505 Analyze (N);
11506 end Attribute_Definition;
11507
11508 ---------------
11509 -- AST_Entry --
11510 ---------------
11511
11512 -- pragma AST_Entry (entry_IDENTIFIER);
11513
11514 when Pragma_AST_Entry => AST_Entry : declare
11515 Ent : Node_Id;
11516
11517 begin
11518 GNAT_Pragma;
11519 Check_VMS (N);
11520 Check_Arg_Count (1);
11521 Check_No_Identifiers;
11522 Check_Arg_Is_Local_Name (Arg1);
11523 Ent := Entity (Get_Pragma_Arg (Arg1));
11524
11525 -- Note: the implementation of the AST_Entry pragma could handle
11526 -- the entry family case fine, but for now we are consistent with
11527 -- the DEC rules, and do not allow the pragma, which of course
11528 -- has the effect of also forbidding the attribute.
11529
11530 if Ekind (Ent) /= E_Entry then
11531 Error_Pragma_Arg
11532 ("pragma% argument must be simple entry name", Arg1);
11533
11534 elsif Is_AST_Entry (Ent) then
11535 Error_Pragma_Arg
11536 ("duplicate % pragma for entry", Arg1);
11537
11538 elsif Has_Homonym (Ent) then
11539 Error_Pragma_Arg
11540 ("pragma% argument cannot specify overloaded entry", Arg1);
11541
11542 else
11543 declare
11544 FF : constant Entity_Id := First_Formal (Ent);
11545
11546 begin
11547 if Present (FF) then
11548 if Present (Next_Formal (FF)) then
11549 Error_Pragma_Arg
11550 ("entry for pragma% can have only one argument",
11551 Arg1);
11552
11553 elsif Parameter_Mode (FF) /= E_In_Parameter then
11554 Error_Pragma_Arg
11555 ("entry parameter for pragma% must have mode IN",
11556 Arg1);
11557 end if;
11558 end if;
11559 end;
11560
11561 Set_Is_AST_Entry (Ent);
11562 end if;
11563 end AST_Entry;
11564
11565 ------------------------------------------------------------------
11566 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11567 ------------------------------------------------------------------
11568
11569 -- pragma Asynch_Readers ( object_LOCAL_NAME [, FLAG] );
11570 -- pragma Asynch_Writers ( object_LOCAL_NAME [, FLAG] );
11571 -- pragma Effective_Reads ( object_LOCAL_NAME [, FLAG] );
11572 -- pragma Effective_Writes ( object_LOCAL_NAME [, FLAG] );
11573
11574 -- FLAG ::= boolean_EXPRESSION
11575
11576 when Pragma_Async_Readers |
11577 Pragma_Async_Writers |
11578 Pragma_Effective_Reads |
11579 Pragma_Effective_Writes =>
11580 Async_Effective : declare
11581 Duplic : Node_Id;
11582 Expr : Node_Id;
11583 Obj : Node_Id;
11584 Obj_Id : Entity_Id;
11585
11586 begin
11587 GNAT_Pragma;
11588 Check_No_Identifiers;
11589 Check_At_Least_N_Arguments (1);
11590 Check_At_Most_N_Arguments (2);
11591 Check_Arg_Is_Local_Name (Arg1);
11592 Error_Msg_Name_1 := Pname;
11593
11594 Obj := Get_Pragma_Arg (Arg1);
11595 Expr := Get_Pragma_Arg (Arg2);
11596
11597 -- Perform minimal verification to ensure that the argument is at
11598 -- least a variable. Subsequent finer grained checks will be done
11599 -- at the end of the declarative region the contains the pragma.
11600
11601 if Is_Entity_Name (Obj)
11602 and then Present (Entity (Obj))
11603 and then Ekind (Entity (Obj)) = E_Variable
11604 then
11605 Obj_Id := Entity (Obj);
11606
11607 -- Detect a duplicate pragma. Note that it is not efficient to
11608 -- examine preceding statements as Boolean aspects may appear
11609 -- anywhere between the related object declaration and its
11610 -- freeze point. As an alternative, inspect the contents of the
11611 -- variable contract.
11612
11613 Duplic := Get_Pragma (Obj_Id, Prag_Id);
11614
11615 if Present (Duplic) then
11616 Error_Msg_Sloc := Sloc (Duplic);
11617 Error_Msg_N ("pragma % duplicates pragma declared #", N);
11618
11619 -- No duplicate detected
11620
11621 else
11622 if Present (Expr) then
11623 Preanalyze_And_Resolve (Expr, Standard_Boolean);
11624 end if;
11625
11626 -- Chain the pragma on the contract for further processing
11627
11628 Add_Contract_Item (N, Obj_Id);
11629 end if;
11630 else
11631 Error_Pragma ("pragma % must apply to a volatile object");
11632 end if;
11633 end Async_Effective;
11634
11635 ------------------
11636 -- Asynchronous --
11637 ------------------
11638
11639 -- pragma Asynchronous (LOCAL_NAME);
11640
11641 when Pragma_Asynchronous => Asynchronous : declare
11642 Nm : Entity_Id;
11643 C_Ent : Entity_Id;
11644 L : List_Id;
11645 S : Node_Id;
11646 N : Node_Id;
11647 Formal : Entity_Id;
11648
11649 procedure Process_Async_Pragma;
11650 -- Common processing for procedure and access-to-procedure case
11651
11652 --------------------------
11653 -- Process_Async_Pragma --
11654 --------------------------
11655
11656 procedure Process_Async_Pragma is
11657 begin
11658 if No (L) then
11659 Set_Is_Asynchronous (Nm);
11660 return;
11661 end if;
11662
11663 -- The formals should be of mode IN (RM E.4.1(6))
11664
11665 S := First (L);
11666 while Present (S) loop
11667 Formal := Defining_Identifier (S);
11668
11669 if Nkind (Formal) = N_Defining_Identifier
11670 and then Ekind (Formal) /= E_In_Parameter
11671 then
11672 Error_Pragma_Arg
11673 ("pragma% procedure can only have IN parameter",
11674 Arg1);
11675 end if;
11676
11677 Next (S);
11678 end loop;
11679
11680 Set_Is_Asynchronous (Nm);
11681 end Process_Async_Pragma;
11682
11683 -- Start of processing for pragma Asynchronous
11684
11685 begin
11686 Check_Ada_83_Warning;
11687 Check_No_Identifiers;
11688 Check_Arg_Count (1);
11689 Check_Arg_Is_Local_Name (Arg1);
11690
11691 if Debug_Flag_U then
11692 return;
11693 end if;
11694
11695 C_Ent := Cunit_Entity (Current_Sem_Unit);
11696 Analyze (Get_Pragma_Arg (Arg1));
11697 Nm := Entity (Get_Pragma_Arg (Arg1));
11698
11699 if not Is_Remote_Call_Interface (C_Ent)
11700 and then not Is_Remote_Types (C_Ent)
11701 then
11702 -- This pragma should only appear in an RCI or Remote Types
11703 -- unit (RM E.4.1(4)).
11704
11705 Error_Pragma
11706 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11707 end if;
11708
11709 if Ekind (Nm) = E_Procedure
11710 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11711 then
11712 if not Is_Remote_Call_Interface (Nm) then
11713 Error_Pragma_Arg
11714 ("pragma% cannot be applied on non-remote procedure",
11715 Arg1);
11716 end if;
11717
11718 L := Parameter_Specifications (Parent (Nm));
11719 Process_Async_Pragma;
11720 return;
11721
11722 elsif Ekind (Nm) = E_Function then
11723 Error_Pragma_Arg
11724 ("pragma% cannot be applied to function", Arg1);
11725
11726 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11727 if Is_Record_Type (Nm) then
11728
11729 -- A record type that is the Equivalent_Type for a remote
11730 -- access-to-subprogram type.
11731
11732 N := Declaration_Node (Corresponding_Remote_Type (Nm));
11733
11734 else
11735 -- A non-expanded RAS type (distribution is not enabled)
11736
11737 N := Declaration_Node (Nm);
11738 end if;
11739
11740 if Nkind (N) = N_Full_Type_Declaration
11741 and then Nkind (Type_Definition (N)) =
11742 N_Access_Procedure_Definition
11743 then
11744 L := Parameter_Specifications (Type_Definition (N));
11745 Process_Async_Pragma;
11746
11747 if Is_Asynchronous (Nm)
11748 and then Expander_Active
11749 and then Get_PCS_Name /= Name_No_DSA
11750 then
11751 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11752 end if;
11753
11754 else
11755 Error_Pragma_Arg
11756 ("pragma% cannot reference access-to-function type",
11757 Arg1);
11758 end if;
11759
11760 -- Only other possibility is Access-to-class-wide type
11761
11762 elsif Is_Access_Type (Nm)
11763 and then Is_Class_Wide_Type (Designated_Type (Nm))
11764 then
11765 Check_First_Subtype (Arg1);
11766 Set_Is_Asynchronous (Nm);
11767 if Expander_Active then
11768 RACW_Type_Is_Asynchronous (Nm);
11769 end if;
11770
11771 else
11772 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11773 end if;
11774 end Asynchronous;
11775
11776 ------------
11777 -- Atomic --
11778 ------------
11779
11780 -- pragma Atomic (LOCAL_NAME);
11781
11782 when Pragma_Atomic =>
11783 Process_Atomic_Shared_Volatile;
11784
11785 -----------------------
11786 -- Atomic_Components --
11787 -----------------------
11788
11789 -- pragma Atomic_Components (array_LOCAL_NAME);
11790
11791 -- This processing is shared by Volatile_Components
11792
11793 when Pragma_Atomic_Components |
11794 Pragma_Volatile_Components =>
11795
11796 Atomic_Components : declare
11797 E_Id : Node_Id;
11798 E : Entity_Id;
11799 D : Node_Id;
11800 K : Node_Kind;
11801
11802 begin
11803 Check_Ada_83_Warning;
11804 Check_No_Identifiers;
11805 Check_Arg_Count (1);
11806 Check_Arg_Is_Local_Name (Arg1);
11807 E_Id := Get_Pragma_Arg (Arg1);
11808
11809 if Etype (E_Id) = Any_Type then
11810 return;
11811 end if;
11812
11813 E := Entity (E_Id);
11814
11815 Check_Duplicate_Pragma (E);
11816
11817 if Rep_Item_Too_Early (E, N)
11818 or else
11819 Rep_Item_Too_Late (E, N)
11820 then
11821 return;
11822 end if;
11823
11824 D := Declaration_Node (E);
11825 K := Nkind (D);
11826
11827 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
11828 or else
11829 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11830 and then Nkind (D) = N_Object_Declaration
11831 and then Nkind (Object_Definition (D)) =
11832 N_Constrained_Array_Definition)
11833 then
11834 -- The flag is set on the object, or on the base type
11835
11836 if Nkind (D) /= N_Object_Declaration then
11837 E := Base_Type (E);
11838 end if;
11839
11840 Set_Has_Volatile_Components (E);
11841
11842 if Prag_Id = Pragma_Atomic_Components then
11843 Set_Has_Atomic_Components (E);
11844 end if;
11845
11846 else
11847 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11848 end if;
11849 end Atomic_Components;
11850
11851 --------------------
11852 -- Attach_Handler --
11853 --------------------
11854
11855 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11856
11857 when Pragma_Attach_Handler =>
11858 Check_Ada_83_Warning;
11859 Check_No_Identifiers;
11860 Check_Arg_Count (2);
11861
11862 if No_Run_Time_Mode then
11863 Error_Msg_CRT ("Attach_Handler pragma", N);
11864 else
11865 Check_Interrupt_Or_Attach_Handler;
11866
11867 -- The expression that designates the attribute may depend on a
11868 -- discriminant, and is therefore a per-object expression, to
11869 -- be expanded in the init proc. If expansion is enabled, then
11870 -- perform semantic checks on a copy only.
11871
11872 declare
11873 Temp : Node_Id;
11874 Typ : Node_Id;
11875 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
11876
11877 begin
11878 -- In Relaxed_RM_Semantics mode, we allow any static
11879 -- integer value, for compatibility with other compilers.
11880
11881 if Relaxed_RM_Semantics
11882 and then Nkind (Parg2) = N_Integer_Literal
11883 then
11884 Typ := Standard_Integer;
11885 else
11886 Typ := RTE (RE_Interrupt_ID);
11887 end if;
11888
11889 if Expander_Active then
11890 Temp := New_Copy_Tree (Parg2);
11891 Set_Parent (Temp, N);
11892 Preanalyze_And_Resolve (Temp, Typ);
11893 else
11894 Analyze (Parg2);
11895 Resolve (Parg2, Typ);
11896 end if;
11897 end;
11898
11899 Process_Interrupt_Or_Attach_Handler;
11900 end if;
11901
11902 --------------------
11903 -- C_Pass_By_Copy --
11904 --------------------
11905
11906 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11907
11908 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
11909 Arg : Node_Id;
11910 Val : Uint;
11911
11912 begin
11913 GNAT_Pragma;
11914 Check_Valid_Configuration_Pragma;
11915 Check_Arg_Count (1);
11916 Check_Optional_Identifier (Arg1, "max_size");
11917
11918 Arg := Get_Pragma_Arg (Arg1);
11919 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
11920
11921 Val := Expr_Value (Arg);
11922
11923 if Val <= 0 then
11924 Error_Pragma_Arg
11925 ("maximum size for pragma% must be positive", Arg1);
11926
11927 elsif UI_Is_In_Int_Range (Val) then
11928 Default_C_Record_Mechanism := UI_To_Int (Val);
11929
11930 -- If a giant value is given, Int'Last will do well enough.
11931 -- If sometime someone complains that a record larger than
11932 -- two gigabytes is not copied, we will worry about it then.
11933
11934 else
11935 Default_C_Record_Mechanism := Mechanism_Type'Last;
11936 end if;
11937 end C_Pass_By_Copy;
11938
11939 -----------
11940 -- Check --
11941 -----------
11942
11943 -- pragma Check ([Name =>] CHECK_KIND,
11944 -- [Check =>] Boolean_EXPRESSION
11945 -- [,[Message =>] String_EXPRESSION]);
11946
11947 -- CHECK_KIND ::= IDENTIFIER |
11948 -- Pre'Class |
11949 -- Post'Class |
11950 -- Invariant'Class |
11951 -- Type_Invariant'Class
11952
11953 -- The identifiers Assertions and Statement_Assertions are not
11954 -- allowed, since they have special meaning for Check_Policy.
11955
11956 when Pragma_Check => Check : declare
11957 Expr : Node_Id;
11958 Eloc : Source_Ptr;
11959 Cname : Name_Id;
11960 Str : Node_Id;
11961
11962 begin
11963 GNAT_Pragma;
11964 Check_At_Least_N_Arguments (2);
11965 Check_At_Most_N_Arguments (3);
11966 Check_Optional_Identifier (Arg1, Name_Name);
11967 Check_Optional_Identifier (Arg2, Name_Check);
11968
11969 if Arg_Count = 3 then
11970 Check_Optional_Identifier (Arg3, Name_Message);
11971 Str := Get_Pragma_Arg (Arg3);
11972 end if;
11973
11974 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
11975 Check_Arg_Is_Identifier (Arg1);
11976 Cname := Chars (Get_Pragma_Arg (Arg1));
11977
11978 -- Check forbidden name Assertions or Statement_Assertions
11979
11980 case Cname is
11981 when Name_Assertions =>
11982 Error_Pragma_Arg
11983 ("""Assertions"" is not allowed as a check kind "
11984 & "for pragma%", Arg1);
11985
11986 when Name_Statement_Assertions =>
11987 Error_Pragma_Arg
11988 ("""Statement_Assertions"" is not allowed as a check kind "
11989 & "for pragma%", Arg1);
11990
11991 when others =>
11992 null;
11993 end case;
11994
11995 -- Check applicable policy. We skip this if Checked/Ignored status
11996 -- is already set (e.g. in the casse of a pragma from an aspect).
11997
11998 if Is_Checked (N) or else Is_Ignored (N) then
11999 null;
12000
12001 -- For a non-source pragma that is a rewriting of another pragma,
12002 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12003
12004 elsif Is_Rewrite_Substitution (N)
12005 and then Nkind (Original_Node (N)) = N_Pragma
12006 and then Original_Node (N) /= N
12007 then
12008 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12009 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12010
12011 -- Otherwise query the applicable policy at this point
12012
12013 else
12014 case Check_Kind (Cname) is
12015 when Name_Ignore =>
12016 Set_Is_Ignored (N, True);
12017 Set_Is_Checked (N, False);
12018
12019 when Name_Check =>
12020 Set_Is_Ignored (N, False);
12021 Set_Is_Checked (N, True);
12022
12023 -- For disable, rewrite pragma as null statement and skip
12024 -- rest of the analysis of the pragma.
12025
12026 when Name_Disable =>
12027 Rewrite (N, Make_Null_Statement (Loc));
12028 Analyze (N);
12029 raise Pragma_Exit;
12030
12031 -- No other possibilities
12032
12033 when others =>
12034 raise Program_Error;
12035 end case;
12036 end if;
12037
12038 -- If check kind was not Disable, then continue pragma analysis
12039
12040 Expr := Get_Pragma_Arg (Arg2);
12041
12042 -- Deal with SCO generation
12043
12044 case Cname is
12045 when Name_Predicate |
12046 Name_Invariant =>
12047
12048 -- Nothing to do: since checks occur in client units,
12049 -- the SCO for the aspect in the declaration unit is
12050 -- conservatively always enabled.
12051
12052 null;
12053
12054 when others =>
12055
12056 if Is_Checked (N) and then not Split_PPC (N) then
12057
12058 -- Mark aspect/pragma SCO as enabled
12059
12060 Set_SCO_Pragma_Enabled (Loc);
12061 end if;
12062 end case;
12063
12064 -- Deal with analyzing the string argument.
12065
12066 if Arg_Count = 3 then
12067
12068 -- If checks are not on we don't want any expansion (since
12069 -- such expansion would not get properly deleted) but
12070 -- we do want to analyze (to get proper references).
12071 -- The Preanalyze_And_Resolve routine does just what we want
12072
12073 if Is_Ignored (N) then
12074 Preanalyze_And_Resolve (Str, Standard_String);
12075
12076 -- Otherwise we need a proper analysis and expansion
12077
12078 else
12079 Analyze_And_Resolve (Str, Standard_String);
12080 end if;
12081 end if;
12082
12083 -- Now you might think we could just do the same with the Boolean
12084 -- expression if checks are off (and expansion is on) and then
12085 -- rewrite the check as a null statement. This would work but we
12086 -- would lose the useful warnings about an assertion being bound
12087 -- to fail even if assertions are turned off.
12088
12089 -- So instead we wrap the boolean expression in an if statement
12090 -- that looks like:
12091
12092 -- if False and then condition then
12093 -- null;
12094 -- end if;
12095
12096 -- The reason we do this rewriting during semantic analysis rather
12097 -- than as part of normal expansion is that we cannot analyze and
12098 -- expand the code for the boolean expression directly, or it may
12099 -- cause insertion of actions that would escape the attempt to
12100 -- suppress the check code.
12101
12102 -- Note that the Sloc for the if statement corresponds to the
12103 -- argument condition, not the pragma itself. The reason for
12104 -- this is that we may generate a warning if the condition is
12105 -- False at compile time, and we do not want to delete this
12106 -- warning when we delete the if statement.
12107
12108 if Expander_Active and Is_Ignored (N) then
12109 Eloc := Sloc (Expr);
12110
12111 Rewrite (N,
12112 Make_If_Statement (Eloc,
12113 Condition =>
12114 Make_And_Then (Eloc,
12115 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
12116 Right_Opnd => Expr),
12117 Then_Statements => New_List (
12118 Make_Null_Statement (Eloc))));
12119
12120 In_Assertion_Expr := In_Assertion_Expr + 1;
12121 Analyze (N);
12122 In_Assertion_Expr := In_Assertion_Expr - 1;
12123
12124 -- Check is active or expansion not active. In these cases we can
12125 -- just go ahead and analyze the boolean with no worries.
12126
12127 else
12128 In_Assertion_Expr := In_Assertion_Expr + 1;
12129 Analyze_And_Resolve (Expr, Any_Boolean);
12130 In_Assertion_Expr := In_Assertion_Expr - 1;
12131 end if;
12132 end Check;
12133
12134 --------------------------
12135 -- Check_Float_Overflow --
12136 --------------------------
12137
12138 -- pragma Check_Float_Overflow;
12139
12140 when Pragma_Check_Float_Overflow =>
12141 GNAT_Pragma;
12142 Check_Valid_Configuration_Pragma;
12143 Check_Arg_Count (0);
12144 Check_Float_Overflow := True;
12145
12146 ----------------
12147 -- Check_Name --
12148 ----------------
12149
12150 -- pragma Check_Name (check_IDENTIFIER);
12151
12152 when Pragma_Check_Name =>
12153 GNAT_Pragma;
12154 Check_No_Identifiers;
12155 Check_Valid_Configuration_Pragma;
12156 Check_Arg_Count (1);
12157 Check_Arg_Is_Identifier (Arg1);
12158
12159 declare
12160 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12161
12162 begin
12163 for J in Check_Names.First .. Check_Names.Last loop
12164 if Check_Names.Table (J) = Nam then
12165 return;
12166 end if;
12167 end loop;
12168
12169 Check_Names.Append (Nam);
12170 end;
12171
12172 ------------------
12173 -- Check_Policy --
12174 ------------------
12175
12176 -- This is the old style syntax, which is still allowed in all modes:
12177
12178 -- pragma Check_Policy ([Name =>] CHECK_KIND
12179 -- [Policy =>] POLICY_IDENTIFIER);
12180
12181 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12182
12183 -- CHECK_KIND ::= IDENTIFIER |
12184 -- Pre'Class |
12185 -- Post'Class |
12186 -- Type_Invariant'Class |
12187 -- Invariant'Class
12188
12189 -- This is the new style syntax, compatible with Assertion_Policy
12190 -- and also allowed in all modes.
12191
12192 -- Pragma Check_Policy (
12193 -- CHECK_KIND => POLICY_IDENTIFIER
12194 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12195
12196 -- Note: the identifiers Name and Policy are not allowed as
12197 -- Check_Kind values. This avoids ambiguities between the old and
12198 -- new form syntax.
12199
12200 when Pragma_Check_Policy => Check_Policy : declare
12201 Kind : Node_Id;
12202
12203 begin
12204 GNAT_Pragma;
12205 Check_At_Least_N_Arguments (1);
12206
12207 -- A Check_Policy pragma can appear either as a configuration
12208 -- pragma, or in a declarative part or a package spec (see RM
12209 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12210 -- followed for Check_Policy).
12211
12212 if not Is_Configuration_Pragma then
12213 Check_Is_In_Decl_Part_Or_Package_Spec;
12214 end if;
12215
12216 -- Figure out if we have the old or new syntax. We have the
12217 -- old syntax if the first argument has no identifier, or the
12218 -- identifier is Name.
12219
12220 if Nkind (Arg1) /= N_Pragma_Argument_Association
12221 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
12222 then
12223 -- Old syntax
12224
12225 Check_Arg_Count (2);
12226 Check_Optional_Identifier (Arg1, Name_Name);
12227 Kind := Get_Pragma_Arg (Arg1);
12228 Rewrite_Assertion_Kind (Kind);
12229 Check_Arg_Is_Identifier (Arg1);
12230
12231 -- Check forbidden check kind
12232
12233 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
12234 Error_Msg_Name_2 := Chars (Kind);
12235 Error_Pragma_Arg
12236 ("pragma% does not allow% as check name", Arg1);
12237 end if;
12238
12239 -- Check policy
12240
12241 Check_Optional_Identifier (Arg2, Name_Policy);
12242 Check_Arg_Is_One_Of
12243 (Arg2,
12244 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
12245
12246 -- And chain pragma on the Check_Policy_List for search
12247
12248 Set_Next_Pragma (N, Opt.Check_Policy_List);
12249 Opt.Check_Policy_List := N;
12250
12251 -- For the new syntax, what we do is to convert each argument to
12252 -- an old syntax equivalent. We do that because we want to chain
12253 -- old style Check_Policy pragmas for the search (we don't want
12254 -- to have to deal with multiple arguments in the search).
12255
12256 else
12257 declare
12258 Arg : Node_Id;
12259 Argx : Node_Id;
12260 LocP : Source_Ptr;
12261
12262 begin
12263 Arg := Arg1;
12264 while Present (Arg) loop
12265 LocP := Sloc (Arg);
12266 Argx := Get_Pragma_Arg (Arg);
12267
12268 -- Kind must be specified
12269
12270 if Nkind (Arg) /= N_Pragma_Argument_Association
12271 or else Chars (Arg) = No_Name
12272 then
12273 Error_Pragma_Arg
12274 ("missing assertion kind for pragma%", Arg);
12275 end if;
12276
12277 -- Construct equivalent old form syntax Check_Policy
12278 -- pragma and insert it to get remaining checks.
12279
12280 Insert_Action (N,
12281 Make_Pragma (LocP,
12282 Chars => Name_Check_Policy,
12283 Pragma_Argument_Associations => New_List (
12284 Make_Pragma_Argument_Association (LocP,
12285 Expression =>
12286 Make_Identifier (LocP, Chars (Arg))),
12287 Make_Pragma_Argument_Association (Sloc (Argx),
12288 Expression => Argx))));
12289
12290 Arg := Next (Arg);
12291 end loop;
12292
12293 -- Rewrite original Check_Policy pragma to null, since we
12294 -- have converted it into a series of old syntax pragmas.
12295
12296 Rewrite (N, Make_Null_Statement (Loc));
12297 Analyze (N);
12298 end;
12299 end if;
12300 end Check_Policy;
12301
12302 ---------------------
12303 -- CIL_Constructor --
12304 ---------------------
12305
12306 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
12307
12308 -- Processing for this pragma is shared with Java_Constructor
12309
12310 -------------
12311 -- Comment --
12312 -------------
12313
12314 -- pragma Comment (static_string_EXPRESSION)
12315
12316 -- Processing for pragma Comment shares the circuitry for pragma
12317 -- Ident. The only differences are that Ident enforces a limit of 31
12318 -- characters on its argument, and also enforces limitations on
12319 -- placement for DEC compatibility. Pragma Comment shares neither of
12320 -- these restrictions.
12321
12322 -------------------
12323 -- Common_Object --
12324 -------------------
12325
12326 -- pragma Common_Object (
12327 -- [Internal =>] LOCAL_NAME
12328 -- [, [External =>] EXTERNAL_SYMBOL]
12329 -- [, [Size =>] EXTERNAL_SYMBOL]);
12330
12331 -- Processing for this pragma is shared with Psect_Object
12332
12333 ------------------------
12334 -- Compile_Time_Error --
12335 ------------------------
12336
12337 -- pragma Compile_Time_Error
12338 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12339
12340 when Pragma_Compile_Time_Error =>
12341 GNAT_Pragma;
12342 Process_Compile_Time_Warning_Or_Error;
12343
12344 --------------------------
12345 -- Compile_Time_Warning --
12346 --------------------------
12347
12348 -- pragma Compile_Time_Warning
12349 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12350
12351 when Pragma_Compile_Time_Warning =>
12352 GNAT_Pragma;
12353 Process_Compile_Time_Warning_Or_Error;
12354
12355 ---------------------------
12356 -- Compiler_Unit_Warning --
12357 ---------------------------
12358
12359 -- pragma Compiler_Unit_Warning;
12360
12361 -- Historical note
12362
12363 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12364 -- errors not warnings. This means that we had introduced a big extra
12365 -- inertia to compiler changes, since even if we implemented a new
12366 -- feature, and even if all versions to be used for bootstrapping
12367 -- implemented this new feature, we could not use it, since old
12368 -- compilers would give errors for using this feature in units
12369 -- having Compiler_Unit pragmas.
12370
12371 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12372 -- problem. We no longer have any units mentioning Compiler_Unit,
12373 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12374 -- and thus generates a warning which can be ignored. So that deals
12375 -- with the problem of old compilers not implementing the newer form
12376 -- of the pragma.
12377
12378 -- Newer compilers recognize the new pragma, but generate warning
12379 -- messages instead of errors, which again can be ignored in the
12380 -- case of an old compiler which implements a wanted new feature
12381 -- but at the time felt like warning about it for older compilers.
12382
12383 -- We retain Compiler_Unit so that new compilers can be used to build
12384 -- older run-times that use this pragma. That's an unusual case, but
12385 -- it's easy enough to handle, so why not?
12386
12387 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
12388 GNAT_Pragma;
12389 Check_Arg_Count (0);
12390
12391 -- Only recognized in main unit
12392
12393 if Current_Sem_Unit = Main_Unit then
12394 Compiler_Unit := True;
12395 end if;
12396
12397 -----------------------------
12398 -- Complete_Representation --
12399 -----------------------------
12400
12401 -- pragma Complete_Representation;
12402
12403 when Pragma_Complete_Representation =>
12404 GNAT_Pragma;
12405 Check_Arg_Count (0);
12406
12407 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
12408 Error_Pragma
12409 ("pragma & must appear within record representation clause");
12410 end if;
12411
12412 ----------------------------
12413 -- Complex_Representation --
12414 ----------------------------
12415
12416 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12417
12418 when Pragma_Complex_Representation => Complex_Representation : declare
12419 E_Id : Entity_Id;
12420 E : Entity_Id;
12421 Ent : Entity_Id;
12422
12423 begin
12424 GNAT_Pragma;
12425 Check_Arg_Count (1);
12426 Check_Optional_Identifier (Arg1, Name_Entity);
12427 Check_Arg_Is_Local_Name (Arg1);
12428 E_Id := Get_Pragma_Arg (Arg1);
12429
12430 if Etype (E_Id) = Any_Type then
12431 return;
12432 end if;
12433
12434 E := Entity (E_Id);
12435
12436 if not Is_Record_Type (E) then
12437 Error_Pragma_Arg
12438 ("argument for pragma% must be record type", Arg1);
12439 end if;
12440
12441 Ent := First_Entity (E);
12442
12443 if No (Ent)
12444 or else No (Next_Entity (Ent))
12445 or else Present (Next_Entity (Next_Entity (Ent)))
12446 or else not Is_Floating_Point_Type (Etype (Ent))
12447 or else Etype (Ent) /= Etype (Next_Entity (Ent))
12448 then
12449 Error_Pragma_Arg
12450 ("record for pragma% must have two fields of the same "
12451 & "floating-point type", Arg1);
12452
12453 else
12454 Set_Has_Complex_Representation (Base_Type (E));
12455
12456 -- We need to treat the type has having a non-standard
12457 -- representation, for back-end purposes, even though in
12458 -- general a complex will have the default representation
12459 -- of a record with two real components.
12460
12461 Set_Has_Non_Standard_Rep (Base_Type (E));
12462 end if;
12463 end Complex_Representation;
12464
12465 -------------------------
12466 -- Component_Alignment --
12467 -------------------------
12468
12469 -- pragma Component_Alignment (
12470 -- [Form =>] ALIGNMENT_CHOICE
12471 -- [, [Name =>] type_LOCAL_NAME]);
12472 --
12473 -- ALIGNMENT_CHOICE ::=
12474 -- Component_Size
12475 -- | Component_Size_4
12476 -- | Storage_Unit
12477 -- | Default
12478
12479 when Pragma_Component_Alignment => Component_AlignmentP : declare
12480 Args : Args_List (1 .. 2);
12481 Names : constant Name_List (1 .. 2) := (
12482 Name_Form,
12483 Name_Name);
12484
12485 Form : Node_Id renames Args (1);
12486 Name : Node_Id renames Args (2);
12487
12488 Atype : Component_Alignment_Kind;
12489 Typ : Entity_Id;
12490
12491 begin
12492 GNAT_Pragma;
12493 Gather_Associations (Names, Args);
12494
12495 if No (Form) then
12496 Error_Pragma ("missing Form argument for pragma%");
12497 end if;
12498
12499 Check_Arg_Is_Identifier (Form);
12500
12501 -- Get proper alignment, note that Default = Component_Size on all
12502 -- machines we have so far, and we want to set this value rather
12503 -- than the default value to indicate that it has been explicitly
12504 -- set (and thus will not get overridden by the default component
12505 -- alignment for the current scope)
12506
12507 if Chars (Form) = Name_Component_Size then
12508 Atype := Calign_Component_Size;
12509
12510 elsif Chars (Form) = Name_Component_Size_4 then
12511 Atype := Calign_Component_Size_4;
12512
12513 elsif Chars (Form) = Name_Default then
12514 Atype := Calign_Component_Size;
12515
12516 elsif Chars (Form) = Name_Storage_Unit then
12517 Atype := Calign_Storage_Unit;
12518
12519 else
12520 Error_Pragma_Arg
12521 ("invalid Form parameter for pragma%", Form);
12522 end if;
12523
12524 -- Case with no name, supplied, affects scope table entry
12525
12526 if No (Name) then
12527 Scope_Stack.Table
12528 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12529
12530 -- Case of name supplied
12531
12532 else
12533 Check_Arg_Is_Local_Name (Name);
12534 Find_Type (Name);
12535 Typ := Entity (Name);
12536
12537 if Typ = Any_Type
12538 or else Rep_Item_Too_Early (Typ, N)
12539 then
12540 return;
12541 else
12542 Typ := Underlying_Type (Typ);
12543 end if;
12544
12545 if not Is_Record_Type (Typ)
12546 and then not Is_Array_Type (Typ)
12547 then
12548 Error_Pragma_Arg
12549 ("Name parameter of pragma% must identify record or "
12550 & "array type", Name);
12551 end if;
12552
12553 -- An explicit Component_Alignment pragma overrides an
12554 -- implicit pragma Pack, but not an explicit one.
12555
12556 if not Has_Pragma_Pack (Base_Type (Typ)) then
12557 Set_Is_Packed (Base_Type (Typ), False);
12558 Set_Component_Alignment (Base_Type (Typ), Atype);
12559 end if;
12560 end if;
12561 end Component_AlignmentP;
12562
12563 --------------------
12564 -- Contract_Cases --
12565 --------------------
12566
12567 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12568
12569 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12570
12571 -- CASE_GUARD ::= boolean_EXPRESSION | others
12572
12573 -- CONSEQUENCE ::= boolean_EXPRESSION
12574
12575 when Pragma_Contract_Cases => Contract_Cases : declare
12576 Subp_Decl : Node_Id;
12577
12578 begin
12579 GNAT_Pragma;
12580 Check_Arg_Count (1);
12581 Ensure_Aggregate_Form (Arg1);
12582
12583 -- The pragma is analyzed at the end of the declarative part which
12584 -- contains the related subprogram. Reset the analyzed flag.
12585
12586 Set_Analyzed (N, False);
12587
12588 -- Ensure the proper placement of the pragma. Contract_Cases must
12589 -- be associated with a subprogram declaration or a body that acts
12590 -- as a spec.
12591
12592 Subp_Decl :=
12593 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12594
12595 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
12596 null;
12597
12598 -- Body acts as spec
12599
12600 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12601 and then No (Corresponding_Spec (Subp_Decl))
12602 then
12603 null;
12604
12605 -- Body stub acts as spec
12606
12607 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12608 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12609 then
12610 null;
12611
12612 else
12613 Pragma_Misplaced;
12614 return;
12615 end if;
12616
12617 -- When the pragma appears on a subprogram body, perform the full
12618 -- analysis now.
12619
12620 if Nkind (Subp_Decl) = N_Subprogram_Body then
12621 Analyze_Contract_Cases_In_Decl_Part (N);
12622
12623 -- When Contract_Cases applies to a subprogram compilation unit,
12624 -- the corresponding pragma is placed after the unit's declaration
12625 -- node and needs to be analyzed immediately.
12626
12627 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
12628 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
12629 then
12630 Analyze_Contract_Cases_In_Decl_Part (N);
12631 end if;
12632
12633 -- Chain the pragma on the contract for further processing
12634
12635 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12636 end Contract_Cases;
12637
12638 ----------------
12639 -- Controlled --
12640 ----------------
12641
12642 -- pragma Controlled (first_subtype_LOCAL_NAME);
12643
12644 when Pragma_Controlled => Controlled : declare
12645 Arg : Node_Id;
12646
12647 begin
12648 Check_No_Identifiers;
12649 Check_Arg_Count (1);
12650 Check_Arg_Is_Local_Name (Arg1);
12651 Arg := Get_Pragma_Arg (Arg1);
12652
12653 if not Is_Entity_Name (Arg)
12654 or else not Is_Access_Type (Entity (Arg))
12655 then
12656 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12657 else
12658 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
12659 end if;
12660 end Controlled;
12661
12662 ----------------
12663 -- Convention --
12664 ----------------
12665
12666 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12667 -- [Entity =>] LOCAL_NAME);
12668
12669 when Pragma_Convention => Convention : declare
12670 C : Convention_Id;
12671 E : Entity_Id;
12672 pragma Warnings (Off, C);
12673 pragma Warnings (Off, E);
12674 begin
12675 Check_Arg_Order ((Name_Convention, Name_Entity));
12676 Check_Ada_83_Warning;
12677 Check_Arg_Count (2);
12678 Process_Convention (C, E);
12679 end Convention;
12680
12681 ---------------------------
12682 -- Convention_Identifier --
12683 ---------------------------
12684
12685 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12686 -- [Convention =>] convention_IDENTIFIER);
12687
12688 when Pragma_Convention_Identifier => Convention_Identifier : declare
12689 Idnam : Name_Id;
12690 Cname : Name_Id;
12691
12692 begin
12693 GNAT_Pragma;
12694 Check_Arg_Order ((Name_Name, Name_Convention));
12695 Check_Arg_Count (2);
12696 Check_Optional_Identifier (Arg1, Name_Name);
12697 Check_Optional_Identifier (Arg2, Name_Convention);
12698 Check_Arg_Is_Identifier (Arg1);
12699 Check_Arg_Is_Identifier (Arg2);
12700 Idnam := Chars (Get_Pragma_Arg (Arg1));
12701 Cname := Chars (Get_Pragma_Arg (Arg2));
12702
12703 if Is_Convention_Name (Cname) then
12704 Record_Convention_Identifier
12705 (Idnam, Get_Convention_Id (Cname));
12706 else
12707 Error_Pragma_Arg
12708 ("second arg for % pragma must be convention", Arg2);
12709 end if;
12710 end Convention_Identifier;
12711
12712 ---------------
12713 -- CPP_Class --
12714 ---------------
12715
12716 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12717
12718 when Pragma_CPP_Class => CPP_Class : declare
12719 begin
12720 GNAT_Pragma;
12721
12722 if Warn_On_Obsolescent_Feature then
12723 Error_Msg_N
12724 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12725 & "effect; replace it by pragma import?j?", N);
12726 end if;
12727
12728 Check_Arg_Count (1);
12729
12730 Rewrite (N,
12731 Make_Pragma (Loc,
12732 Chars => Name_Import,
12733 Pragma_Argument_Associations => New_List (
12734 Make_Pragma_Argument_Association (Loc,
12735 Expression => Make_Identifier (Loc, Name_CPP)),
12736 New_Copy (First (Pragma_Argument_Associations (N))))));
12737 Analyze (N);
12738 end CPP_Class;
12739
12740 ---------------------
12741 -- CPP_Constructor --
12742 ---------------------
12743
12744 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12745 -- [, [External_Name =>] static_string_EXPRESSION ]
12746 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12747
12748 when Pragma_CPP_Constructor => CPP_Constructor : declare
12749 Elmt : Elmt_Id;
12750 Id : Entity_Id;
12751 Def_Id : Entity_Id;
12752 Tag_Typ : Entity_Id;
12753
12754 begin
12755 GNAT_Pragma;
12756 Check_At_Least_N_Arguments (1);
12757 Check_At_Most_N_Arguments (3);
12758 Check_Optional_Identifier (Arg1, Name_Entity);
12759 Check_Arg_Is_Local_Name (Arg1);
12760
12761 Id := Get_Pragma_Arg (Arg1);
12762 Find_Program_Unit_Name (Id);
12763
12764 -- If we did not find the name, we are done
12765
12766 if Etype (Id) = Any_Type then
12767 return;
12768 end if;
12769
12770 Def_Id := Entity (Id);
12771
12772 -- Check if already defined as constructor
12773
12774 if Is_Constructor (Def_Id) then
12775 Error_Msg_N
12776 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
12777 return;
12778 end if;
12779
12780 if Ekind (Def_Id) = E_Function
12781 and then (Is_CPP_Class (Etype (Def_Id))
12782 or else (Is_Class_Wide_Type (Etype (Def_Id))
12783 and then
12784 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
12785 then
12786 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
12787 Error_Msg_N
12788 ("'C'P'P constructor must be defined in the scope of "
12789 & "its returned type", Arg1);
12790 end if;
12791
12792 if Arg_Count >= 2 then
12793 Set_Imported (Def_Id);
12794 Set_Is_Public (Def_Id);
12795 Process_Interface_Name (Def_Id, Arg2, Arg3);
12796 end if;
12797
12798 Set_Has_Completion (Def_Id);
12799 Set_Is_Constructor (Def_Id);
12800 Set_Convention (Def_Id, Convention_CPP);
12801
12802 -- Imported C++ constructors are not dispatching primitives
12803 -- because in C++ they don't have a dispatch table slot.
12804 -- However, in Ada the constructor has the profile of a
12805 -- function that returns a tagged type and therefore it has
12806 -- been treated as a primitive operation during semantic
12807 -- analysis. We now remove it from the list of primitive
12808 -- operations of the type.
12809
12810 if Is_Tagged_Type (Etype (Def_Id))
12811 and then not Is_Class_Wide_Type (Etype (Def_Id))
12812 and then Is_Dispatching_Operation (Def_Id)
12813 then
12814 Tag_Typ := Etype (Def_Id);
12815
12816 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
12817 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
12818 Next_Elmt (Elmt);
12819 end loop;
12820
12821 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
12822 Set_Is_Dispatching_Operation (Def_Id, False);
12823 end if;
12824
12825 -- For backward compatibility, if the constructor returns a
12826 -- class wide type, and we internally change the return type to
12827 -- the corresponding root type.
12828
12829 if Is_Class_Wide_Type (Etype (Def_Id)) then
12830 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
12831 end if;
12832 else
12833 Error_Pragma_Arg
12834 ("pragma% requires function returning a 'C'P'P_Class type",
12835 Arg1);
12836 end if;
12837 end CPP_Constructor;
12838
12839 -----------------
12840 -- CPP_Virtual --
12841 -----------------
12842
12843 when Pragma_CPP_Virtual => CPP_Virtual : declare
12844 begin
12845 GNAT_Pragma;
12846
12847 if Warn_On_Obsolescent_Feature then
12848 Error_Msg_N
12849 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12850 & "effect?j?", N);
12851 end if;
12852 end CPP_Virtual;
12853
12854 ----------------
12855 -- CPP_Vtable --
12856 ----------------
12857
12858 when Pragma_CPP_Vtable => CPP_Vtable : declare
12859 begin
12860 GNAT_Pragma;
12861
12862 if Warn_On_Obsolescent_Feature then
12863 Error_Msg_N
12864 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12865 & "effect?j?", N);
12866 end if;
12867 end CPP_Vtable;
12868
12869 ---------
12870 -- CPU --
12871 ---------
12872
12873 -- pragma CPU (EXPRESSION);
12874
12875 when Pragma_CPU => CPU : declare
12876 P : constant Node_Id := Parent (N);
12877 Arg : Node_Id;
12878 Ent : Entity_Id;
12879
12880 begin
12881 Ada_2012_Pragma;
12882 Check_No_Identifiers;
12883 Check_Arg_Count (1);
12884
12885 -- Subprogram case
12886
12887 if Nkind (P) = N_Subprogram_Body then
12888 Check_In_Main_Program;
12889
12890 Arg := Get_Pragma_Arg (Arg1);
12891 Analyze_And_Resolve (Arg, Any_Integer);
12892
12893 Ent := Defining_Unit_Name (Specification (P));
12894
12895 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12896 Ent := Defining_Identifier (Ent);
12897 end if;
12898
12899 -- Must be static
12900
12901 if not Is_OK_Static_Expression (Arg) then
12902 Flag_Non_Static_Expr
12903 ("main subprogram affinity is not static!", Arg);
12904 raise Pragma_Exit;
12905
12906 -- If constraint error, then we already signalled an error
12907
12908 elsif Raises_Constraint_Error (Arg) then
12909 null;
12910
12911 -- Otherwise check in range
12912
12913 else
12914 declare
12915 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
12916 -- This is the entity System.Multiprocessors.CPU_Range;
12917
12918 Val : constant Uint := Expr_Value (Arg);
12919
12920 begin
12921 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
12922 or else
12923 Val > Expr_Value (Type_High_Bound (CPU_Id))
12924 then
12925 Error_Pragma_Arg
12926 ("main subprogram CPU is out of range", Arg1);
12927 end if;
12928 end;
12929 end if;
12930
12931 Set_Main_CPU
12932 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12933
12934 -- Task case
12935
12936 elsif Nkind (P) = N_Task_Definition then
12937 Arg := Get_Pragma_Arg (Arg1);
12938 Ent := Defining_Identifier (Parent (P));
12939
12940 -- The expression must be analyzed in the special manner
12941 -- described in "Handling of Default and Per-Object
12942 -- Expressions" in sem.ads.
12943
12944 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
12945
12946 -- Anything else is incorrect
12947
12948 else
12949 Pragma_Misplaced;
12950 end if;
12951
12952 -- Check duplicate pragma before we chain the pragma in the Rep
12953 -- Item chain of Ent.
12954
12955 Check_Duplicate_Pragma (Ent);
12956 Record_Rep_Item (Ent, N);
12957 end CPU;
12958
12959 -----------
12960 -- Debug --
12961 -----------
12962
12963 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12964
12965 when Pragma_Debug => Debug : declare
12966 Cond : Node_Id;
12967 Call : Node_Id;
12968
12969 begin
12970 GNAT_Pragma;
12971
12972 -- The condition for executing the call is that the expander
12973 -- is active and that we are not ignoring this debug pragma.
12974
12975 Cond :=
12976 New_Occurrence_Of
12977 (Boolean_Literals
12978 (Expander_Active and then not Is_Ignored (N)),
12979 Loc);
12980
12981 if not Is_Ignored (N) then
12982 Set_SCO_Pragma_Enabled (Loc);
12983 end if;
12984
12985 if Arg_Count = 2 then
12986 Cond :=
12987 Make_And_Then (Loc,
12988 Left_Opnd => Relocate_Node (Cond),
12989 Right_Opnd => Get_Pragma_Arg (Arg1));
12990 Call := Get_Pragma_Arg (Arg2);
12991 else
12992 Call := Get_Pragma_Arg (Arg1);
12993 end if;
12994
12995 if Nkind_In (Call,
12996 N_Indexed_Component,
12997 N_Function_Call,
12998 N_Identifier,
12999 N_Expanded_Name,
13000 N_Selected_Component)
13001 then
13002 -- If this pragma Debug comes from source, its argument was
13003 -- parsed as a name form (which is syntactically identical).
13004 -- In a generic context a parameterless call will be left as
13005 -- an expanded name (if global) or selected_component if local.
13006 -- Change it to a procedure call statement now.
13007
13008 Change_Name_To_Procedure_Call_Statement (Call);
13009
13010 elsif Nkind (Call) = N_Procedure_Call_Statement then
13011
13012 -- Already in the form of a procedure call statement: nothing
13013 -- to do (could happen in case of an internally generated
13014 -- pragma Debug).
13015
13016 null;
13017
13018 else
13019 -- All other cases: diagnose error
13020
13021 Error_Msg
13022 ("argument of pragma ""Debug"" is not procedure call",
13023 Sloc (Call));
13024 return;
13025 end if;
13026
13027 -- Rewrite into a conditional with an appropriate condition. We
13028 -- wrap the procedure call in a block so that overhead from e.g.
13029 -- use of the secondary stack does not generate execution overhead
13030 -- for suppressed conditions.
13031
13032 -- Normally the analysis that follows will freeze the subprogram
13033 -- being called. However, if the call is to a null procedure,
13034 -- we want to freeze it before creating the block, because the
13035 -- analysis that follows may be done with expansion disabled, in
13036 -- which case the body will not be generated, leading to spurious
13037 -- errors.
13038
13039 if Nkind (Call) = N_Procedure_Call_Statement
13040 and then Is_Entity_Name (Name (Call))
13041 then
13042 Analyze (Name (Call));
13043 Freeze_Before (N, Entity (Name (Call)));
13044 end if;
13045
13046 Rewrite (N,
13047 Make_Implicit_If_Statement (N,
13048 Condition => Cond,
13049 Then_Statements => New_List (
13050 Make_Block_Statement (Loc,
13051 Handled_Statement_Sequence =>
13052 Make_Handled_Sequence_Of_Statements (Loc,
13053 Statements => New_List (Relocate_Node (Call)))))));
13054 Analyze (N);
13055
13056 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13057 -- after analysis of the normally rewritten node, to capture all
13058 -- references to entities, which avoids issuing wrong warnings
13059 -- about unused entities.
13060
13061 if GNATprove_Mode then
13062 Rewrite (N, Make_Null_Statement (Loc));
13063 end if;
13064 end Debug;
13065
13066 ------------------
13067 -- Debug_Policy --
13068 ------------------
13069
13070 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13071
13072 when Pragma_Debug_Policy =>
13073 GNAT_Pragma;
13074 Check_Arg_Count (1);
13075 Check_No_Identifiers;
13076 Check_Arg_Is_Identifier (Arg1);
13077
13078 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13079 -- rewrite it that way, and let the rest of the checking come
13080 -- from analyzing the rewritten pragma.
13081
13082 Rewrite (N,
13083 Make_Pragma (Loc,
13084 Chars => Name_Check_Policy,
13085 Pragma_Argument_Associations => New_List (
13086 Make_Pragma_Argument_Association (Loc,
13087 Expression => Make_Identifier (Loc, Name_Debug)),
13088
13089 Make_Pragma_Argument_Association (Loc,
13090 Expression => Get_Pragma_Arg (Arg1)))));
13091 Analyze (N);
13092
13093 -------------
13094 -- Depends --
13095 -------------
13096
13097 -- pragma Depends (DEPENDENCY_RELATION);
13098
13099 -- DEPENDENCY_RELATION ::=
13100 -- null
13101 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
13102
13103 -- DEPENDENCY_CLAUSE ::=
13104 -- OUTPUT_LIST =>[+] INPUT_LIST
13105 -- | NULL_DEPENDENCY_CLAUSE
13106
13107 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13108
13109 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13110
13111 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13112
13113 -- OUTPUT ::= NAME | FUNCTION_RESULT
13114 -- INPUT ::= NAME
13115
13116 -- where FUNCTION_RESULT is a function Result attribute_reference
13117
13118 when Pragma_Depends => Depends : declare
13119 Subp_Decl : Node_Id;
13120
13121 begin
13122 GNAT_Pragma;
13123 Check_Arg_Count (1);
13124 Ensure_Aggregate_Form (Arg1);
13125
13126 -- Ensure the proper placement of the pragma. Depends must be
13127 -- associated with a subprogram declaration or a body that acts
13128 -- as a spec.
13129
13130 Subp_Decl :=
13131 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
13132
13133 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
13134 null;
13135
13136 -- Body acts as spec
13137
13138 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13139 and then No (Corresponding_Spec (Subp_Decl))
13140 then
13141 null;
13142
13143 -- Body stub acts as spec
13144
13145 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13146 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13147 then
13148 null;
13149
13150 else
13151 Pragma_Misplaced;
13152 return;
13153 end if;
13154
13155 -- When the pragma appears on a subprogram body, perform the full
13156 -- analysis now.
13157
13158 if Nkind (Subp_Decl) = N_Subprogram_Body then
13159 Analyze_Depends_In_Decl_Part (N);
13160
13161 -- When Depends applies to a subprogram compilation unit, the
13162 -- corresponding pragma is placed after the unit's declaration
13163 -- node and needs to be analyzed immediately.
13164
13165 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
13166 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
13167 then
13168 Analyze_Depends_In_Decl_Part (N);
13169 end if;
13170
13171 -- Chain the pragma on the contract for further processing
13172
13173 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13174 end Depends;
13175
13176 ---------------------
13177 -- Detect_Blocking --
13178 ---------------------
13179
13180 -- pragma Detect_Blocking;
13181
13182 when Pragma_Detect_Blocking =>
13183 Ada_2005_Pragma;
13184 Check_Arg_Count (0);
13185 Check_Valid_Configuration_Pragma;
13186 Detect_Blocking := True;
13187
13188 ----------------------------------
13189 -- Default_Scalar_Storage_Order --
13190 ----------------------------------
13191
13192 -- pragma Default_Scalar_Storage_Order
13193 -- (High_Order_First | Low_Order_First);
13194
13195 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
13196 Default : Character;
13197
13198 begin
13199 GNAT_Pragma;
13200 Check_Arg_Count (1);
13201
13202 -- Default_Scalar_Storage_Order can appear as a configuration
13203 -- pragma, or in a declarative part of a package spec.
13204
13205 if not Is_Configuration_Pragma then
13206 Check_Is_In_Decl_Part_Or_Package_Spec;
13207 end if;
13208
13209 Check_No_Identifiers;
13210 Check_Arg_Is_One_Of
13211 (Arg1, Name_High_Order_First, Name_Low_Order_First);
13212 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13213 Default := Fold_Upper (Name_Buffer (1));
13214
13215 if not Support_Nondefault_SSO_On_Target
13216 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
13217 then
13218 if Warn_On_Unrecognized_Pragma then
13219 Error_Msg_N
13220 ("non-default Scalar_Storage_Order not supported "
13221 & "on target?g?", N);
13222 Error_Msg_N
13223 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
13224 end if;
13225
13226 -- Here set the specified default
13227
13228 else
13229 Opt.Default_SSO := Default;
13230 end if;
13231 end DSSO;
13232
13233 --------------------------
13234 -- Default_Storage_Pool --
13235 --------------------------
13236
13237 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13238
13239 when Pragma_Default_Storage_Pool =>
13240 Ada_2012_Pragma;
13241 Check_Arg_Count (1);
13242
13243 -- Default_Storage_Pool can appear as a configuration pragma, or
13244 -- in a declarative part of a package spec.
13245
13246 if not Is_Configuration_Pragma then
13247 Check_Is_In_Decl_Part_Or_Package_Spec;
13248 end if;
13249
13250 -- Case of Default_Storage_Pool (null);
13251
13252 if Nkind (Expression (Arg1)) = N_Null then
13253 Analyze (Expression (Arg1));
13254
13255 -- This is an odd case, this is not really an expression, so
13256 -- we don't have a type for it. So just set the type to Empty.
13257
13258 Set_Etype (Expression (Arg1), Empty);
13259
13260 -- Case of Default_Storage_Pool (storage_pool_NAME);
13261
13262 else
13263 -- If it's a configuration pragma, then the only allowed
13264 -- argument is "null".
13265
13266 if Is_Configuration_Pragma then
13267 Error_Pragma_Arg ("NULL expected", Arg1);
13268 end if;
13269
13270 -- The expected type for a non-"null" argument is
13271 -- Root_Storage_Pool'Class.
13272
13273 Analyze_And_Resolve
13274 (Get_Pragma_Arg (Arg1),
13275 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
13276 end if;
13277
13278 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
13279 -- for an access type will use this information to set the
13280 -- appropriate attributes of the access type.
13281
13282 Default_Pool := Expression (Arg1);
13283
13284 ------------------------------------
13285 -- Disable_Atomic_Synchronization --
13286 ------------------------------------
13287
13288 -- pragma Disable_Atomic_Synchronization [(Entity)];
13289
13290 when Pragma_Disable_Atomic_Synchronization =>
13291 GNAT_Pragma;
13292 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
13293
13294 -------------------
13295 -- Discard_Names --
13296 -------------------
13297
13298 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13299
13300 when Pragma_Discard_Names => Discard_Names : declare
13301 E : Entity_Id;
13302 E_Id : Entity_Id;
13303
13304 begin
13305 Check_Ada_83_Warning;
13306
13307 -- Deal with configuration pragma case
13308
13309 if Arg_Count = 0 and then Is_Configuration_Pragma then
13310 Global_Discard_Names := True;
13311 return;
13312
13313 -- Otherwise, check correct appropriate context
13314
13315 else
13316 Check_Is_In_Decl_Part_Or_Package_Spec;
13317
13318 if Arg_Count = 0 then
13319
13320 -- If there is no parameter, then from now on this pragma
13321 -- applies to any enumeration, exception or tagged type
13322 -- defined in the current declarative part, and recursively
13323 -- to any nested scope.
13324
13325 Set_Discard_Names (Current_Scope);
13326 return;
13327
13328 else
13329 Check_Arg_Count (1);
13330 Check_Optional_Identifier (Arg1, Name_On);
13331 Check_Arg_Is_Local_Name (Arg1);
13332
13333 E_Id := Get_Pragma_Arg (Arg1);
13334
13335 if Etype (E_Id) = Any_Type then
13336 return;
13337 else
13338 E := Entity (E_Id);
13339 end if;
13340
13341 if (Is_First_Subtype (E)
13342 and then
13343 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
13344 or else Ekind (E) = E_Exception
13345 then
13346 Set_Discard_Names (E);
13347 Record_Rep_Item (E, N);
13348
13349 else
13350 Error_Pragma_Arg
13351 ("inappropriate entity for pragma%", Arg1);
13352 end if;
13353
13354 end if;
13355 end if;
13356 end Discard_Names;
13357
13358 ------------------------
13359 -- Dispatching_Domain --
13360 ------------------------
13361
13362 -- pragma Dispatching_Domain (EXPRESSION);
13363
13364 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
13365 P : constant Node_Id := Parent (N);
13366 Arg : Node_Id;
13367 Ent : Entity_Id;
13368
13369 begin
13370 Ada_2012_Pragma;
13371 Check_No_Identifiers;
13372 Check_Arg_Count (1);
13373
13374 -- This pragma is born obsolete, but not the aspect
13375
13376 if not From_Aspect_Specification (N) then
13377 Check_Restriction
13378 (No_Obsolescent_Features, Pragma_Identifier (N));
13379 end if;
13380
13381 if Nkind (P) = N_Task_Definition then
13382 Arg := Get_Pragma_Arg (Arg1);
13383 Ent := Defining_Identifier (Parent (P));
13384
13385 -- The expression must be analyzed in the special manner
13386 -- described in "Handling of Default and Per-Object
13387 -- Expressions" in sem.ads.
13388
13389 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
13390
13391 -- Check duplicate pragma before we chain the pragma in the Rep
13392 -- Item chain of Ent.
13393
13394 Check_Duplicate_Pragma (Ent);
13395 Record_Rep_Item (Ent, N);
13396
13397 -- Anything else is incorrect
13398
13399 else
13400 Pragma_Misplaced;
13401 end if;
13402 end Dispatching_Domain;
13403
13404 ---------------
13405 -- Elaborate --
13406 ---------------
13407
13408 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13409
13410 when Pragma_Elaborate => Elaborate : declare
13411 Arg : Node_Id;
13412 Citem : Node_Id;
13413
13414 begin
13415 -- Pragma must be in context items list of a compilation unit
13416
13417 if not Is_In_Context_Clause then
13418 Pragma_Misplaced;
13419 end if;
13420
13421 -- Must be at least one argument
13422
13423 if Arg_Count = 0 then
13424 Error_Pragma ("pragma% requires at least one argument");
13425 end if;
13426
13427 -- In Ada 83 mode, there can be no items following it in the
13428 -- context list except other pragmas and implicit with clauses
13429 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13430 -- placement rule does not apply.
13431
13432 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
13433 Citem := Next (N);
13434 while Present (Citem) loop
13435 if Nkind (Citem) = N_Pragma
13436 or else (Nkind (Citem) = N_With_Clause
13437 and then Implicit_With (Citem))
13438 then
13439 null;
13440 else
13441 Error_Pragma
13442 ("(Ada 83) pragma% must be at end of context clause");
13443 end if;
13444
13445 Next (Citem);
13446 end loop;
13447 end if;
13448
13449 -- Finally, the arguments must all be units mentioned in a with
13450 -- clause in the same context clause. Note we already checked (in
13451 -- Par.Prag) that the arguments are all identifiers or selected
13452 -- components.
13453
13454 Arg := Arg1;
13455 Outer : while Present (Arg) loop
13456 Citem := First (List_Containing (N));
13457 Inner : while Citem /= N loop
13458 if Nkind (Citem) = N_With_Clause
13459 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13460 then
13461 Set_Elaborate_Present (Citem, True);
13462 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13463 Generate_Reference (Entity (Name (Citem)), Citem);
13464
13465 -- With the pragma present, elaboration calls on
13466 -- subprograms from the named unit need no further
13467 -- checks, as long as the pragma appears in the current
13468 -- compilation unit. If the pragma appears in some unit
13469 -- in the context, there might still be a need for an
13470 -- Elaborate_All_Desirable from the current compilation
13471 -- to the named unit, so we keep the check enabled.
13472
13473 if In_Extended_Main_Source_Unit (N) then
13474 Set_Suppress_Elaboration_Warnings
13475 (Entity (Name (Citem)));
13476 end if;
13477
13478 exit Inner;
13479 end if;
13480
13481 Next (Citem);
13482 end loop Inner;
13483
13484 if Citem = N then
13485 Error_Pragma_Arg
13486 ("argument of pragma% is not withed unit", Arg);
13487 end if;
13488
13489 Next (Arg);
13490 end loop Outer;
13491
13492 -- Give a warning if operating in static mode with one of the
13493 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
13494
13495 if Elab_Warnings and not Dynamic_Elaboration_Checks then
13496 Error_Msg_N
13497 ("?l?use of pragma Elaborate may not be safe", N);
13498 Error_Msg_N
13499 ("?l?use pragma Elaborate_All instead if possible", N);
13500 end if;
13501 end Elaborate;
13502
13503 -------------------
13504 -- Elaborate_All --
13505 -------------------
13506
13507 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
13508
13509 when Pragma_Elaborate_All => Elaborate_All : declare
13510 Arg : Node_Id;
13511 Citem : Node_Id;
13512
13513 begin
13514 Check_Ada_83_Warning;
13515
13516 -- Pragma must be in context items list of a compilation unit
13517
13518 if not Is_In_Context_Clause then
13519 Pragma_Misplaced;
13520 end if;
13521
13522 -- Must be at least one argument
13523
13524 if Arg_Count = 0 then
13525 Error_Pragma ("pragma% requires at least one argument");
13526 end if;
13527
13528 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13529 -- have to appear at the end of the context clause, but may
13530 -- appear mixed in with other items, even in Ada 83 mode.
13531
13532 -- Final check: the arguments must all be units mentioned in
13533 -- a with clause in the same context clause. Note that we
13534 -- already checked (in Par.Prag) that all the arguments are
13535 -- either identifiers or selected components.
13536
13537 Arg := Arg1;
13538 Outr : while Present (Arg) loop
13539 Citem := First (List_Containing (N));
13540 Innr : while Citem /= N loop
13541 if Nkind (Citem) = N_With_Clause
13542 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
13543 then
13544 Set_Elaborate_All_Present (Citem, True);
13545 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13546
13547 -- Suppress warnings and elaboration checks on the named
13548 -- unit if the pragma is in the current compilation, as
13549 -- for pragma Elaborate.
13550
13551 if In_Extended_Main_Source_Unit (N) then
13552 Set_Suppress_Elaboration_Warnings
13553 (Entity (Name (Citem)));
13554 end if;
13555 exit Innr;
13556 end if;
13557
13558 Next (Citem);
13559 end loop Innr;
13560
13561 if Citem = N then
13562 Set_Error_Posted (N);
13563 Error_Pragma_Arg
13564 ("argument of pragma% is not withed unit", Arg);
13565 end if;
13566
13567 Next (Arg);
13568 end loop Outr;
13569 end Elaborate_All;
13570
13571 --------------------
13572 -- Elaborate_Body --
13573 --------------------
13574
13575 -- pragma Elaborate_Body [( library_unit_NAME )];
13576
13577 when Pragma_Elaborate_Body => Elaborate_Body : declare
13578 Cunit_Node : Node_Id;
13579 Cunit_Ent : Entity_Id;
13580
13581 begin
13582 Check_Ada_83_Warning;
13583 Check_Valid_Library_Unit_Pragma;
13584
13585 if Nkind (N) = N_Null_Statement then
13586 return;
13587 end if;
13588
13589 Cunit_Node := Cunit (Current_Sem_Unit);
13590 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13591
13592 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
13593 N_Subprogram_Body)
13594 then
13595 Error_Pragma ("pragma% must refer to a spec, not a body");
13596 else
13597 Set_Body_Required (Cunit_Node, True);
13598 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
13599
13600 -- If we are in dynamic elaboration mode, then we suppress
13601 -- elaboration warnings for the unit, since it is definitely
13602 -- fine NOT to do dynamic checks at the first level (and such
13603 -- checks will be suppressed because no elaboration boolean
13604 -- is created for Elaborate_Body packages).
13605
13606 -- But in the static model of elaboration, Elaborate_Body is
13607 -- definitely NOT good enough to ensure elaboration safety on
13608 -- its own, since the body may WITH other units that are not
13609 -- safe from an elaboration point of view, so a client must
13610 -- still do an Elaborate_All on such units.
13611
13612 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13613 -- Elaborate_Body always suppressed elab warnings.
13614
13615 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
13616 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
13617 end if;
13618 end if;
13619 end Elaborate_Body;
13620
13621 ------------------------
13622 -- Elaboration_Checks --
13623 ------------------------
13624
13625 -- pragma Elaboration_Checks (Static | Dynamic);
13626
13627 when Pragma_Elaboration_Checks =>
13628 GNAT_Pragma;
13629 Check_Arg_Count (1);
13630 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
13631 Dynamic_Elaboration_Checks :=
13632 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
13633
13634 ---------------
13635 -- Eliminate --
13636 ---------------
13637
13638 -- pragma Eliminate (
13639 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13640 -- [,[Entity =>] IDENTIFIER |
13641 -- SELECTED_COMPONENT |
13642 -- STRING_LITERAL]
13643 -- [, OVERLOADING_RESOLUTION]);
13644
13645 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13646 -- SOURCE_LOCATION
13647
13648 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13649 -- FUNCTION_PROFILE
13650
13651 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13652
13653 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13654 -- Result_Type => result_SUBTYPE_NAME]
13655
13656 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13657 -- SUBTYPE_NAME ::= STRING_LITERAL
13658
13659 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13660 -- SOURCE_TRACE ::= STRING_LITERAL
13661
13662 when Pragma_Eliminate => Eliminate : declare
13663 Args : Args_List (1 .. 5);
13664 Names : constant Name_List (1 .. 5) := (
13665 Name_Unit_Name,
13666 Name_Entity,
13667 Name_Parameter_Types,
13668 Name_Result_Type,
13669 Name_Source_Location);
13670
13671 Unit_Name : Node_Id renames Args (1);
13672 Entity : Node_Id renames Args (2);
13673 Parameter_Types : Node_Id renames Args (3);
13674 Result_Type : Node_Id renames Args (4);
13675 Source_Location : Node_Id renames Args (5);
13676
13677 begin
13678 GNAT_Pragma;
13679 Check_Valid_Configuration_Pragma;
13680 Gather_Associations (Names, Args);
13681
13682 if No (Unit_Name) then
13683 Error_Pragma ("missing Unit_Name argument for pragma%");
13684 end if;
13685
13686 if No (Entity)
13687 and then (Present (Parameter_Types)
13688 or else
13689 Present (Result_Type)
13690 or else
13691 Present (Source_Location))
13692 then
13693 Error_Pragma ("missing Entity argument for pragma%");
13694 end if;
13695
13696 if (Present (Parameter_Types)
13697 or else
13698 Present (Result_Type))
13699 and then
13700 Present (Source_Location)
13701 then
13702 Error_Pragma
13703 ("parameter profile and source location cannot be used "
13704 & "together in pragma%");
13705 end if;
13706
13707 Process_Eliminate_Pragma
13708 (N,
13709 Unit_Name,
13710 Entity,
13711 Parameter_Types,
13712 Result_Type,
13713 Source_Location);
13714 end Eliminate;
13715
13716 -----------------------------------
13717 -- Enable_Atomic_Synchronization --
13718 -----------------------------------
13719
13720 -- pragma Enable_Atomic_Synchronization [(Entity)];
13721
13722 when Pragma_Enable_Atomic_Synchronization =>
13723 GNAT_Pragma;
13724 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
13725
13726 ------------
13727 -- Export --
13728 ------------
13729
13730 -- pragma Export (
13731 -- [ Convention =>] convention_IDENTIFIER,
13732 -- [ Entity =>] LOCAL_NAME
13733 -- [, [External_Name =>] static_string_EXPRESSION ]
13734 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13735
13736 when Pragma_Export => Export : declare
13737 C : Convention_Id;
13738 Def_Id : Entity_Id;
13739
13740 pragma Warnings (Off, C);
13741
13742 begin
13743 Check_Ada_83_Warning;
13744 Check_Arg_Order
13745 ((Name_Convention,
13746 Name_Entity,
13747 Name_External_Name,
13748 Name_Link_Name));
13749
13750 Check_At_Least_N_Arguments (2);
13751 Check_At_Most_N_Arguments (4);
13752
13753 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13754 -- pragma Export (Entity, "external name");
13755
13756 if Relaxed_RM_Semantics
13757 and then Arg_Count = 2
13758 and then Nkind (Expression (Arg2)) = N_String_Literal
13759 then
13760 C := Convention_C;
13761 Def_Id := Get_Pragma_Arg (Arg1);
13762 Analyze (Def_Id);
13763
13764 if not Is_Entity_Name (Def_Id) then
13765 Error_Pragma_Arg ("entity name required", Arg1);
13766 end if;
13767
13768 Def_Id := Entity (Def_Id);
13769 Set_Exported (Def_Id, Arg1);
13770
13771 else
13772 Process_Convention (C, Def_Id);
13773
13774 if Ekind (Def_Id) /= E_Constant then
13775 Note_Possible_Modification
13776 (Get_Pragma_Arg (Arg2), Sure => False);
13777 end if;
13778
13779 Process_Interface_Name (Def_Id, Arg3, Arg4);
13780 Set_Exported (Def_Id, Arg2);
13781 end if;
13782
13783 -- If the entity is a deferred constant, propagate the information
13784 -- to the full view, because gigi elaborates the full view only.
13785
13786 if Ekind (Def_Id) = E_Constant
13787 and then Present (Full_View (Def_Id))
13788 then
13789 declare
13790 Id2 : constant Entity_Id := Full_View (Def_Id);
13791 begin
13792 Set_Is_Exported (Id2, Is_Exported (Def_Id));
13793 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
13794 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
13795 end;
13796 end if;
13797 end Export;
13798
13799 ----------------------
13800 -- Export_Exception --
13801 ----------------------
13802
13803 -- pragma Export_Exception (
13804 -- [Internal =>] LOCAL_NAME
13805 -- [, [External =>] EXTERNAL_SYMBOL]
13806 -- [, [Form =>] Ada | VMS]
13807 -- [, [Code =>] static_integer_EXPRESSION]);
13808
13809 when Pragma_Export_Exception => Export_Exception : declare
13810 Args : Args_List (1 .. 4);
13811 Names : constant Name_List (1 .. 4) := (
13812 Name_Internal,
13813 Name_External,
13814 Name_Form,
13815 Name_Code);
13816
13817 Internal : Node_Id renames Args (1);
13818 External : Node_Id renames Args (2);
13819 Form : Node_Id renames Args (3);
13820 Code : Node_Id renames Args (4);
13821
13822 begin
13823 GNAT_Pragma;
13824
13825 if Inside_A_Generic then
13826 Error_Pragma ("pragma% cannot be used for generic entities");
13827 end if;
13828
13829 Gather_Associations (Names, Args);
13830 Process_Extended_Import_Export_Exception_Pragma (
13831 Arg_Internal => Internal,
13832 Arg_External => External,
13833 Arg_Form => Form,
13834 Arg_Code => Code);
13835
13836 if not Is_VMS_Exception (Entity (Internal)) then
13837 Set_Exported (Entity (Internal), Internal);
13838 end if;
13839 end Export_Exception;
13840
13841 ---------------------
13842 -- Export_Function --
13843 ---------------------
13844
13845 -- pragma Export_Function (
13846 -- [Internal =>] LOCAL_NAME
13847 -- [, [External =>] EXTERNAL_SYMBOL]
13848 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13849 -- [, [Result_Type =>] TYPE_DESIGNATOR]
13850 -- [, [Mechanism =>] MECHANISM]
13851 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
13852
13853 -- EXTERNAL_SYMBOL ::=
13854 -- IDENTIFIER
13855 -- | static_string_EXPRESSION
13856
13857 -- PARAMETER_TYPES ::=
13858 -- null
13859 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13860
13861 -- TYPE_DESIGNATOR ::=
13862 -- subtype_NAME
13863 -- | subtype_Name ' Access
13864
13865 -- MECHANISM ::=
13866 -- MECHANISM_NAME
13867 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13868
13869 -- MECHANISM_ASSOCIATION ::=
13870 -- [formal_parameter_NAME =>] MECHANISM_NAME
13871
13872 -- MECHANISM_NAME ::=
13873 -- Value
13874 -- | Reference
13875 -- | Descriptor [([Class =>] CLASS_NAME)]
13876
13877 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13878
13879 when Pragma_Export_Function => Export_Function : declare
13880 Args : Args_List (1 .. 6);
13881 Names : constant Name_List (1 .. 6) := (
13882 Name_Internal,
13883 Name_External,
13884 Name_Parameter_Types,
13885 Name_Result_Type,
13886 Name_Mechanism,
13887 Name_Result_Mechanism);
13888
13889 Internal : Node_Id renames Args (1);
13890 External : Node_Id renames Args (2);
13891 Parameter_Types : Node_Id renames Args (3);
13892 Result_Type : Node_Id renames Args (4);
13893 Mechanism : Node_Id renames Args (5);
13894 Result_Mechanism : Node_Id renames Args (6);
13895
13896 begin
13897 GNAT_Pragma;
13898 Gather_Associations (Names, Args);
13899 Process_Extended_Import_Export_Subprogram_Pragma (
13900 Arg_Internal => Internal,
13901 Arg_External => External,
13902 Arg_Parameter_Types => Parameter_Types,
13903 Arg_Result_Type => Result_Type,
13904 Arg_Mechanism => Mechanism,
13905 Arg_Result_Mechanism => Result_Mechanism);
13906 end Export_Function;
13907
13908 -------------------
13909 -- Export_Object --
13910 -------------------
13911
13912 -- pragma Export_Object (
13913 -- [Internal =>] LOCAL_NAME
13914 -- [, [External =>] EXTERNAL_SYMBOL]
13915 -- [, [Size =>] EXTERNAL_SYMBOL]);
13916
13917 -- EXTERNAL_SYMBOL ::=
13918 -- IDENTIFIER
13919 -- | static_string_EXPRESSION
13920
13921 -- PARAMETER_TYPES ::=
13922 -- null
13923 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13924
13925 -- TYPE_DESIGNATOR ::=
13926 -- subtype_NAME
13927 -- | subtype_Name ' Access
13928
13929 -- MECHANISM ::=
13930 -- MECHANISM_NAME
13931 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13932
13933 -- MECHANISM_ASSOCIATION ::=
13934 -- [formal_parameter_NAME =>] MECHANISM_NAME
13935
13936 -- MECHANISM_NAME ::=
13937 -- Value
13938 -- | Reference
13939 -- | Descriptor [([Class =>] CLASS_NAME)]
13940
13941 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13942
13943 when Pragma_Export_Object => Export_Object : declare
13944 Args : Args_List (1 .. 3);
13945 Names : constant Name_List (1 .. 3) := (
13946 Name_Internal,
13947 Name_External,
13948 Name_Size);
13949
13950 Internal : Node_Id renames Args (1);
13951 External : Node_Id renames Args (2);
13952 Size : Node_Id renames Args (3);
13953
13954 begin
13955 GNAT_Pragma;
13956 Gather_Associations (Names, Args);
13957 Process_Extended_Import_Export_Object_Pragma (
13958 Arg_Internal => Internal,
13959 Arg_External => External,
13960 Arg_Size => Size);
13961 end Export_Object;
13962
13963 ----------------------
13964 -- Export_Procedure --
13965 ----------------------
13966
13967 -- pragma Export_Procedure (
13968 -- [Internal =>] LOCAL_NAME
13969 -- [, [External =>] EXTERNAL_SYMBOL]
13970 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13971 -- [, [Mechanism =>] MECHANISM]);
13972
13973 -- EXTERNAL_SYMBOL ::=
13974 -- IDENTIFIER
13975 -- | static_string_EXPRESSION
13976
13977 -- PARAMETER_TYPES ::=
13978 -- null
13979 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13980
13981 -- TYPE_DESIGNATOR ::=
13982 -- subtype_NAME
13983 -- | subtype_Name ' Access
13984
13985 -- MECHANISM ::=
13986 -- MECHANISM_NAME
13987 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13988
13989 -- MECHANISM_ASSOCIATION ::=
13990 -- [formal_parameter_NAME =>] MECHANISM_NAME
13991
13992 -- MECHANISM_NAME ::=
13993 -- Value
13994 -- | Reference
13995 -- | Descriptor [([Class =>] CLASS_NAME)]
13996
13997 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13998
13999 when Pragma_Export_Procedure => Export_Procedure : declare
14000 Args : Args_List (1 .. 4);
14001 Names : constant Name_List (1 .. 4) := (
14002 Name_Internal,
14003 Name_External,
14004 Name_Parameter_Types,
14005 Name_Mechanism);
14006
14007 Internal : Node_Id renames Args (1);
14008 External : Node_Id renames Args (2);
14009 Parameter_Types : Node_Id renames Args (3);
14010 Mechanism : Node_Id renames Args (4);
14011
14012 begin
14013 GNAT_Pragma;
14014 Gather_Associations (Names, Args);
14015 Process_Extended_Import_Export_Subprogram_Pragma (
14016 Arg_Internal => Internal,
14017 Arg_External => External,
14018 Arg_Parameter_Types => Parameter_Types,
14019 Arg_Mechanism => Mechanism);
14020 end Export_Procedure;
14021
14022 ------------------
14023 -- Export_Value --
14024 ------------------
14025
14026 -- pragma Export_Value (
14027 -- [Value =>] static_integer_EXPRESSION,
14028 -- [Link_Name =>] static_string_EXPRESSION);
14029
14030 when Pragma_Export_Value =>
14031 GNAT_Pragma;
14032 Check_Arg_Order ((Name_Value, Name_Link_Name));
14033 Check_Arg_Count (2);
14034
14035 Check_Optional_Identifier (Arg1, Name_Value);
14036 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
14037
14038 Check_Optional_Identifier (Arg2, Name_Link_Name);
14039 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
14040
14041 -----------------------------
14042 -- Export_Valued_Procedure --
14043 -----------------------------
14044
14045 -- pragma Export_Valued_Procedure (
14046 -- [Internal =>] LOCAL_NAME
14047 -- [, [External =>] EXTERNAL_SYMBOL,]
14048 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14049 -- [, [Mechanism =>] MECHANISM]);
14050
14051 -- EXTERNAL_SYMBOL ::=
14052 -- IDENTIFIER
14053 -- | static_string_EXPRESSION
14054
14055 -- PARAMETER_TYPES ::=
14056 -- null
14057 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14058
14059 -- TYPE_DESIGNATOR ::=
14060 -- subtype_NAME
14061 -- | subtype_Name ' Access
14062
14063 -- MECHANISM ::=
14064 -- MECHANISM_NAME
14065 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14066
14067 -- MECHANISM_ASSOCIATION ::=
14068 -- [formal_parameter_NAME =>] MECHANISM_NAME
14069
14070 -- MECHANISM_NAME ::=
14071 -- Value
14072 -- | Reference
14073 -- | Descriptor [([Class =>] CLASS_NAME)]
14074
14075 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
14076
14077 when Pragma_Export_Valued_Procedure =>
14078 Export_Valued_Procedure : declare
14079 Args : Args_List (1 .. 4);
14080 Names : constant Name_List (1 .. 4) := (
14081 Name_Internal,
14082 Name_External,
14083 Name_Parameter_Types,
14084 Name_Mechanism);
14085
14086 Internal : Node_Id renames Args (1);
14087 External : Node_Id renames Args (2);
14088 Parameter_Types : Node_Id renames Args (3);
14089 Mechanism : Node_Id renames Args (4);
14090
14091 begin
14092 GNAT_Pragma;
14093 Gather_Associations (Names, Args);
14094 Process_Extended_Import_Export_Subprogram_Pragma (
14095 Arg_Internal => Internal,
14096 Arg_External => External,
14097 Arg_Parameter_Types => Parameter_Types,
14098 Arg_Mechanism => Mechanism);
14099 end Export_Valued_Procedure;
14100
14101 -------------------
14102 -- Extend_System --
14103 -------------------
14104
14105 -- pragma Extend_System ([Name =>] Identifier);
14106
14107 when Pragma_Extend_System => Extend_System : declare
14108 begin
14109 GNAT_Pragma;
14110 Check_Valid_Configuration_Pragma;
14111 Check_Arg_Count (1);
14112 Check_Optional_Identifier (Arg1, Name_Name);
14113 Check_Arg_Is_Identifier (Arg1);
14114
14115 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14116
14117 if Name_Len > 4
14118 and then Name_Buffer (1 .. 4) = "aux_"
14119 then
14120 if Present (System_Extend_Pragma_Arg) then
14121 if Chars (Get_Pragma_Arg (Arg1)) =
14122 Chars (Expression (System_Extend_Pragma_Arg))
14123 then
14124 null;
14125 else
14126 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
14127 Error_Pragma ("pragma% conflicts with that #");
14128 end if;
14129
14130 else
14131 System_Extend_Pragma_Arg := Arg1;
14132
14133 if not GNAT_Mode then
14134 System_Extend_Unit := Arg1;
14135 end if;
14136 end if;
14137 else
14138 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
14139 end if;
14140 end Extend_System;
14141
14142 ------------------------
14143 -- Extensions_Allowed --
14144 ------------------------
14145
14146 -- pragma Extensions_Allowed (ON | OFF);
14147
14148 when Pragma_Extensions_Allowed =>
14149 GNAT_Pragma;
14150 Check_Arg_Count (1);
14151 Check_No_Identifiers;
14152 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14153
14154 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
14155 Extensions_Allowed := True;
14156 Ada_Version := Ada_Version_Type'Last;
14157
14158 else
14159 Extensions_Allowed := False;
14160 Ada_Version := Ada_Version_Explicit;
14161 Ada_Version_Pragma := Empty;
14162 end if;
14163
14164 --------------
14165 -- External --
14166 --------------
14167
14168 -- pragma External (
14169 -- [ Convention =>] convention_IDENTIFIER,
14170 -- [ Entity =>] LOCAL_NAME
14171 -- [, [External_Name =>] static_string_EXPRESSION ]
14172 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14173
14174 when Pragma_External => External : declare
14175 Def_Id : Entity_Id;
14176
14177 C : Convention_Id;
14178 pragma Warnings (Off, C);
14179
14180 begin
14181 GNAT_Pragma;
14182 Check_Arg_Order
14183 ((Name_Convention,
14184 Name_Entity,
14185 Name_External_Name,
14186 Name_Link_Name));
14187 Check_At_Least_N_Arguments (2);
14188 Check_At_Most_N_Arguments (4);
14189 Process_Convention (C, Def_Id);
14190 Note_Possible_Modification
14191 (Get_Pragma_Arg (Arg2), Sure => False);
14192 Process_Interface_Name (Def_Id, Arg3, Arg4);
14193 Set_Exported (Def_Id, Arg2);
14194 end External;
14195
14196 --------------------------
14197 -- External_Name_Casing --
14198 --------------------------
14199
14200 -- pragma External_Name_Casing (
14201 -- UPPERCASE | LOWERCASE
14202 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14203
14204 when Pragma_External_Name_Casing => External_Name_Casing : declare
14205 begin
14206 GNAT_Pragma;
14207 Check_No_Identifiers;
14208
14209 if Arg_Count = 2 then
14210 Check_Arg_Is_One_Of
14211 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
14212
14213 case Chars (Get_Pragma_Arg (Arg2)) is
14214 when Name_As_Is =>
14215 Opt.External_Name_Exp_Casing := As_Is;
14216
14217 when Name_Uppercase =>
14218 Opt.External_Name_Exp_Casing := Uppercase;
14219
14220 when Name_Lowercase =>
14221 Opt.External_Name_Exp_Casing := Lowercase;
14222
14223 when others =>
14224 null;
14225 end case;
14226
14227 else
14228 Check_Arg_Count (1);
14229 end if;
14230
14231 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
14232
14233 case Chars (Get_Pragma_Arg (Arg1)) is
14234 when Name_Uppercase =>
14235 Opt.External_Name_Imp_Casing := Uppercase;
14236
14237 when Name_Lowercase =>
14238 Opt.External_Name_Imp_Casing := Lowercase;
14239
14240 when others =>
14241 null;
14242 end case;
14243 end External_Name_Casing;
14244
14245 ---------------
14246 -- Fast_Math --
14247 ---------------
14248
14249 -- pragma Fast_Math;
14250
14251 when Pragma_Fast_Math =>
14252 GNAT_Pragma;
14253 Check_No_Identifiers;
14254 Check_Valid_Configuration_Pragma;
14255 Fast_Math := True;
14256
14257 --------------------------
14258 -- Favor_Top_Level --
14259 --------------------------
14260
14261 -- pragma Favor_Top_Level (type_NAME);
14262
14263 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
14264 Named_Entity : Entity_Id;
14265
14266 begin
14267 GNAT_Pragma;
14268 Check_No_Identifiers;
14269 Check_Arg_Count (1);
14270 Check_Arg_Is_Local_Name (Arg1);
14271 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
14272
14273 -- If it's an access-to-subprogram type (in particular, not a
14274 -- subtype), set the flag on that type.
14275
14276 if Is_Access_Subprogram_Type (Named_Entity) then
14277 Set_Can_Use_Internal_Rep (Named_Entity, False);
14278
14279 -- Otherwise it's an error (name denotes the wrong sort of entity)
14280
14281 else
14282 Error_Pragma_Arg
14283 ("access-to-subprogram type expected",
14284 Get_Pragma_Arg (Arg1));
14285 end if;
14286 end Favor_Top_Level;
14287
14288 ---------------------------
14289 -- Finalize_Storage_Only --
14290 ---------------------------
14291
14292 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14293
14294 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
14295 Assoc : constant Node_Id := Arg1;
14296 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
14297 Typ : Entity_Id;
14298
14299 begin
14300 GNAT_Pragma;
14301 Check_No_Identifiers;
14302 Check_Arg_Count (1);
14303 Check_Arg_Is_Local_Name (Arg1);
14304
14305 Find_Type (Type_Id);
14306 Typ := Entity (Type_Id);
14307
14308 if Typ = Any_Type
14309 or else Rep_Item_Too_Early (Typ, N)
14310 then
14311 return;
14312 else
14313 Typ := Underlying_Type (Typ);
14314 end if;
14315
14316 if not Is_Controlled (Typ) then
14317 Error_Pragma ("pragma% must specify controlled type");
14318 end if;
14319
14320 Check_First_Subtype (Arg1);
14321
14322 if Finalize_Storage_Only (Typ) then
14323 Error_Pragma ("duplicate pragma%, only one allowed");
14324
14325 elsif not Rep_Item_Too_Late (Typ, N) then
14326 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14327 end if;
14328 end Finalize_Storage;
14329
14330 --------------------------
14331 -- Float_Representation --
14332 --------------------------
14333
14334 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
14335
14336 -- FLOAT_REP ::= VAX_Float | IEEE_Float
14337
14338 when Pragma_Float_Representation => Float_Representation : declare
14339 Argx : Node_Id;
14340 Digs : Nat;
14341 Ent : Entity_Id;
14342
14343 begin
14344 GNAT_Pragma;
14345
14346 if Arg_Count = 1 then
14347 Check_Valid_Configuration_Pragma;
14348 else
14349 Check_Arg_Count (2);
14350 Check_Optional_Identifier (Arg2, Name_Entity);
14351 Check_Arg_Is_Local_Name (Arg2);
14352 end if;
14353
14354 Check_No_Identifier (Arg1);
14355 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
14356
14357 if not OpenVMS_On_Target then
14358 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
14359 Error_Pragma
14360 ("??pragma% ignored (applies only to Open'V'M'S)");
14361 end if;
14362
14363 return;
14364 end if;
14365
14366 -- One argument case
14367
14368 if Arg_Count = 1 then
14369 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
14370 if Opt.Float_Format = 'I' then
14371 Error_Pragma ("'I'E'E'E format previously specified");
14372 end if;
14373
14374 Opt.Float_Format := 'V';
14375
14376 else
14377 if Opt.Float_Format = 'V' then
14378 Error_Pragma ("'V'A'X format previously specified");
14379 end if;
14380
14381 Opt.Float_Format := 'I';
14382 end if;
14383
14384 Set_Standard_Fpt_Formats;
14385
14386 -- Two argument case
14387
14388 else
14389 Argx := Get_Pragma_Arg (Arg2);
14390
14391 if not Is_Entity_Name (Argx)
14392 or else not Is_Floating_Point_Type (Entity (Argx))
14393 then
14394 Error_Pragma_Arg
14395 ("second argument of% pragma must be floating-point type",
14396 Arg2);
14397 end if;
14398
14399 Ent := Entity (Argx);
14400 Digs := UI_To_Int (Digits_Value (Ent));
14401
14402 -- Two arguments, VAX_Float case
14403
14404 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
14405 case Digs is
14406 when 6 => Set_F_Float (Ent);
14407 when 9 => Set_D_Float (Ent);
14408 when 15 => Set_G_Float (Ent);
14409
14410 when others =>
14411 Error_Pragma_Arg
14412 ("wrong digits value, must be 6,9 or 15", Arg2);
14413 end case;
14414
14415 -- Two arguments, IEEE_Float case
14416
14417 else
14418 case Digs is
14419 when 6 => Set_IEEE_Short (Ent);
14420 when 15 => Set_IEEE_Long (Ent);
14421
14422 when others =>
14423 Error_Pragma_Arg
14424 ("wrong digits value, must be 6 or 15", Arg2);
14425 end case;
14426 end if;
14427 end if;
14428 end Float_Representation;
14429
14430 ------------
14431 -- Global --
14432 ------------
14433
14434 -- pragma Global (GLOBAL_SPECIFICATION);
14435
14436 -- GLOBAL_SPECIFICATION ::=
14437 -- null
14438 -- | GLOBAL_LIST
14439 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14440
14441 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14442
14443 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14444 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14445 -- GLOBAL_ITEM ::= NAME
14446
14447 when Pragma_Global => Global : declare
14448 Subp_Decl : Node_Id;
14449
14450 begin
14451 GNAT_Pragma;
14452 Check_Arg_Count (1);
14453 Ensure_Aggregate_Form (Arg1);
14454
14455 -- Ensure the proper placement of the pragma. Global must be
14456 -- associated with a subprogram declaration or a body that acts
14457 -- as a spec.
14458
14459 Subp_Decl :=
14460 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
14461
14462 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
14463 null;
14464
14465 -- Body acts as spec
14466
14467 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14468 and then No (Corresponding_Spec (Subp_Decl))
14469 then
14470 null;
14471
14472 -- Body stub acts as spec
14473
14474 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14475 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14476 then
14477 null;
14478
14479 else
14480 Pragma_Misplaced;
14481 return;
14482 end if;
14483
14484 -- When the pragma appears on a subprogram body, perform the full
14485 -- analysis now.
14486
14487 if Nkind (Subp_Decl) = N_Subprogram_Body then
14488 Analyze_Global_In_Decl_Part (N);
14489
14490 -- When Global applies to a subprogram compilation unit, the
14491 -- corresponding pragma is placed after the unit's declaration
14492 -- node and needs to be analyzed immediately.
14493
14494 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
14495 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
14496 then
14497 Analyze_Global_In_Decl_Part (N);
14498 end if;
14499
14500 -- Chain the pragma on the contract for further processing
14501
14502 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14503 end Global;
14504
14505 -----------
14506 -- Ident --
14507 -----------
14508
14509 -- pragma Ident (static_string_EXPRESSION)
14510
14511 -- Note: pragma Comment shares this processing. Pragma Comment is
14512 -- identical to Ident, except that the restriction of the argument to
14513 -- 31 characters and the placement restrictions are not enforced for
14514 -- pragma Comment.
14515
14516 when Pragma_Ident | Pragma_Comment => Ident : declare
14517 Str : Node_Id;
14518
14519 begin
14520 GNAT_Pragma;
14521 Check_Arg_Count (1);
14522 Check_No_Identifiers;
14523 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
14524 Store_Note (N);
14525
14526 -- For pragma Ident, preserve DEC compatibility by requiring the
14527 -- pragma to appear in a declarative part or package spec.
14528
14529 if Prag_Id = Pragma_Ident then
14530 Check_Is_In_Decl_Part_Or_Package_Spec;
14531 end if;
14532
14533 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
14534
14535 declare
14536 CS : Node_Id;
14537 GP : Node_Id;
14538
14539 begin
14540 GP := Parent (Parent (N));
14541
14542 if Nkind_In (GP, N_Package_Declaration,
14543 N_Generic_Package_Declaration)
14544 then
14545 GP := Parent (GP);
14546 end if;
14547
14548 -- If we have a compilation unit, then record the ident value,
14549 -- checking for improper duplication.
14550
14551 if Nkind (GP) = N_Compilation_Unit then
14552 CS := Ident_String (Current_Sem_Unit);
14553
14554 if Present (CS) then
14555
14556 -- For Ident, we do not permit multiple instances
14557
14558 if Prag_Id = Pragma_Ident then
14559 Error_Pragma ("duplicate% pragma not permitted");
14560
14561 -- For Comment, we concatenate the string, unless we want
14562 -- to preserve the tree structure for ASIS.
14563
14564 elsif not ASIS_Mode then
14565 Start_String (Strval (CS));
14566 Store_String_Char (' ');
14567 Store_String_Chars (Strval (Str));
14568 Set_Strval (CS, End_String);
14569 end if;
14570
14571 else
14572 -- In VMS, the effect of IDENT is achieved by passing
14573 -- --identification=name as a --for-linker switch.
14574
14575 if OpenVMS_On_Target then
14576 Start_String;
14577 Store_String_Chars
14578 ("--for-linker=--identification=");
14579 String_To_Name_Buffer (Strval (Str));
14580 Store_String_Chars (Name_Buffer (1 .. Name_Len));
14581
14582 -- Only the last processed IDENT is saved. The main
14583 -- purpose is so an IDENT associated with a main
14584 -- procedure will be used in preference to an IDENT
14585 -- associated with a with'd package.
14586
14587 Replace_Linker_Option_String
14588 (End_String, "--for-linker=--identification=");
14589 end if;
14590
14591 Set_Ident_String (Current_Sem_Unit, Str);
14592 end if;
14593
14594 -- For subunits, we just ignore the Ident, since in GNAT these
14595 -- are not separate object files, and hence not separate units
14596 -- in the unit table.
14597
14598 elsif Nkind (GP) = N_Subunit then
14599 null;
14600
14601 -- Otherwise we have a misplaced pragma Ident, but we ignore
14602 -- this if we are in an instantiation, since it comes from
14603 -- a generic, and has no relevance to the instantiation.
14604
14605 elsif Prag_Id = Pragma_Ident then
14606 if Instantiation_Location (Loc) = No_Location then
14607 Error_Pragma ("pragma% only allowed at outer level");
14608 end if;
14609 end if;
14610 end;
14611 end Ident;
14612
14613 ----------------------------
14614 -- Implementation_Defined --
14615 ----------------------------
14616
14617 -- pragma Implementation_Defined (LOCAL_NAME);
14618
14619 -- Marks previously declared entity as implementation defined. For
14620 -- an overloaded entity, applies to the most recent homonym.
14621
14622 -- pragma Implementation_Defined;
14623
14624 -- The form with no arguments appears anywhere within a scope, most
14625 -- typically a package spec, and indicates that all entities that are
14626 -- defined within the package spec are Implementation_Defined.
14627
14628 when Pragma_Implementation_Defined => Implementation_Defined : declare
14629 Ent : Entity_Id;
14630
14631 begin
14632 GNAT_Pragma;
14633 Check_No_Identifiers;
14634
14635 -- Form with no arguments
14636
14637 if Arg_Count = 0 then
14638 Set_Is_Implementation_Defined (Current_Scope);
14639
14640 -- Form with one argument
14641
14642 else
14643 Check_Arg_Count (1);
14644 Check_Arg_Is_Local_Name (Arg1);
14645 Ent := Entity (Get_Pragma_Arg (Arg1));
14646 Set_Is_Implementation_Defined (Ent);
14647 end if;
14648 end Implementation_Defined;
14649
14650 -----------------
14651 -- Implemented --
14652 -----------------
14653
14654 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14655
14656 -- IMPLEMENTATION_KIND ::=
14657 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14658
14659 -- "By_Any" and "Optional" are treated as synonyms in order to
14660 -- support Ada 2012 aspect Synchronization.
14661
14662 when Pragma_Implemented => Implemented : declare
14663 Proc_Id : Entity_Id;
14664 Typ : Entity_Id;
14665
14666 begin
14667 Ada_2012_Pragma;
14668 Check_Arg_Count (2);
14669 Check_No_Identifiers;
14670 Check_Arg_Is_Identifier (Arg1);
14671 Check_Arg_Is_Local_Name (Arg1);
14672 Check_Arg_Is_One_Of (Arg2,
14673 Name_By_Any,
14674 Name_By_Entry,
14675 Name_By_Protected_Procedure,
14676 Name_Optional);
14677
14678 -- Extract the name of the local procedure
14679
14680 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
14681
14682 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14683 -- primitive procedure of a synchronized tagged type.
14684
14685 if Ekind (Proc_Id) = E_Procedure
14686 and then Is_Primitive (Proc_Id)
14687 and then Present (First_Formal (Proc_Id))
14688 then
14689 Typ := Etype (First_Formal (Proc_Id));
14690
14691 if Is_Tagged_Type (Typ)
14692 and then
14693
14694 -- Check for a protected, a synchronized or a task interface
14695
14696 ((Is_Interface (Typ)
14697 and then Is_Synchronized_Interface (Typ))
14698
14699 -- Check for a protected type or a task type that implements
14700 -- an interface.
14701
14702 or else
14703 (Is_Concurrent_Record_Type (Typ)
14704 and then Present (Interfaces (Typ)))
14705
14706 -- Check for a private record extension with keyword
14707 -- "synchronized".
14708
14709 or else
14710 (Ekind_In (Typ, E_Record_Type_With_Private,
14711 E_Record_Subtype_With_Private)
14712 and then Synchronized_Present (Parent (Typ))))
14713 then
14714 null;
14715 else
14716 Error_Pragma_Arg
14717 ("controlling formal must be of synchronized tagged type",
14718 Arg1);
14719 return;
14720 end if;
14721
14722 -- Procedures declared inside a protected type must be accepted
14723
14724 elsif Ekind (Proc_Id) = E_Procedure
14725 and then Is_Protected_Type (Scope (Proc_Id))
14726 then
14727 null;
14728
14729 -- The first argument is not a primitive procedure
14730
14731 else
14732 Error_Pragma_Arg
14733 ("pragma % must be applied to a primitive procedure", Arg1);
14734 return;
14735 end if;
14736
14737 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
14738 -- By_Protected_Procedure to the primitive procedure of a task
14739 -- interface.
14740
14741 if Chars (Arg2) = Name_By_Protected_Procedure
14742 and then Is_Interface (Typ)
14743 and then Is_Task_Interface (Typ)
14744 then
14745 Error_Pragma_Arg
14746 ("implementation kind By_Protected_Procedure cannot be "
14747 & "applied to a task interface primitive", Arg2);
14748 return;
14749 end if;
14750
14751 Record_Rep_Item (Proc_Id, N);
14752 end Implemented;
14753
14754 ----------------------
14755 -- Implicit_Packing --
14756 ----------------------
14757
14758 -- pragma Implicit_Packing;
14759
14760 when Pragma_Implicit_Packing =>
14761 GNAT_Pragma;
14762 Check_Arg_Count (0);
14763 Implicit_Packing := True;
14764
14765 ------------
14766 -- Import --
14767 ------------
14768
14769 -- pragma Import (
14770 -- [Convention =>] convention_IDENTIFIER,
14771 -- [Entity =>] LOCAL_NAME
14772 -- [, [External_Name =>] static_string_EXPRESSION ]
14773 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14774
14775 when Pragma_Import =>
14776 Check_Ada_83_Warning;
14777 Check_Arg_Order
14778 ((Name_Convention,
14779 Name_Entity,
14780 Name_External_Name,
14781 Name_Link_Name));
14782
14783 Check_At_Least_N_Arguments (2);
14784 Check_At_Most_N_Arguments (4);
14785 Process_Import_Or_Interface;
14786
14787 ----------------------
14788 -- Import_Exception --
14789 ----------------------
14790
14791 -- pragma Import_Exception (
14792 -- [Internal =>] LOCAL_NAME
14793 -- [, [External =>] EXTERNAL_SYMBOL]
14794 -- [, [Form =>] Ada | VMS]
14795 -- [, [Code =>] static_integer_EXPRESSION]);
14796
14797 when Pragma_Import_Exception => Import_Exception : declare
14798 Args : Args_List (1 .. 4);
14799 Names : constant Name_List (1 .. 4) := (
14800 Name_Internal,
14801 Name_External,
14802 Name_Form,
14803 Name_Code);
14804
14805 Internal : Node_Id renames Args (1);
14806 External : Node_Id renames Args (2);
14807 Form : Node_Id renames Args (3);
14808 Code : Node_Id renames Args (4);
14809
14810 begin
14811 GNAT_Pragma;
14812 Gather_Associations (Names, Args);
14813
14814 if Present (External) and then Present (Code) then
14815 Error_Pragma
14816 ("cannot give both External and Code options for pragma%");
14817 end if;
14818
14819 Process_Extended_Import_Export_Exception_Pragma (
14820 Arg_Internal => Internal,
14821 Arg_External => External,
14822 Arg_Form => Form,
14823 Arg_Code => Code);
14824
14825 if not Is_VMS_Exception (Entity (Internal)) then
14826 Set_Imported (Entity (Internal));
14827 end if;
14828 end Import_Exception;
14829
14830 ---------------------
14831 -- Import_Function --
14832 ---------------------
14833
14834 -- pragma Import_Function (
14835 -- [Internal =>] LOCAL_NAME,
14836 -- [, [External =>] EXTERNAL_SYMBOL]
14837 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14838 -- [, [Result_Type =>] SUBTYPE_MARK]
14839 -- [, [Mechanism =>] MECHANISM]
14840 -- [, [Result_Mechanism =>] MECHANISM_NAME]
14841 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
14842
14843 -- EXTERNAL_SYMBOL ::=
14844 -- IDENTIFIER
14845 -- | static_string_EXPRESSION
14846
14847 -- PARAMETER_TYPES ::=
14848 -- null
14849 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14850
14851 -- TYPE_DESIGNATOR ::=
14852 -- subtype_NAME
14853 -- | subtype_Name ' Access
14854
14855 -- MECHANISM ::=
14856 -- MECHANISM_NAME
14857 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14858
14859 -- MECHANISM_ASSOCIATION ::=
14860 -- [formal_parameter_NAME =>] MECHANISM_NAME
14861
14862 -- MECHANISM_NAME ::=
14863 -- Value
14864 -- | Reference
14865 -- | Descriptor [([Class =>] CLASS_NAME)]
14866
14867 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
14868
14869 when Pragma_Import_Function => Import_Function : declare
14870 Args : Args_List (1 .. 7);
14871 Names : constant Name_List (1 .. 7) := (
14872 Name_Internal,
14873 Name_External,
14874 Name_Parameter_Types,
14875 Name_Result_Type,
14876 Name_Mechanism,
14877 Name_Result_Mechanism,
14878 Name_First_Optional_Parameter);
14879
14880 Internal : Node_Id renames Args (1);
14881 External : Node_Id renames Args (2);
14882 Parameter_Types : Node_Id renames Args (3);
14883 Result_Type : Node_Id renames Args (4);
14884 Mechanism : Node_Id renames Args (5);
14885 Result_Mechanism : Node_Id renames Args (6);
14886 First_Optional_Parameter : Node_Id renames Args (7);
14887
14888 begin
14889 GNAT_Pragma;
14890 Gather_Associations (Names, Args);
14891 Process_Extended_Import_Export_Subprogram_Pragma (
14892 Arg_Internal => Internal,
14893 Arg_External => External,
14894 Arg_Parameter_Types => Parameter_Types,
14895 Arg_Result_Type => Result_Type,
14896 Arg_Mechanism => Mechanism,
14897 Arg_Result_Mechanism => Result_Mechanism,
14898 Arg_First_Optional_Parameter => First_Optional_Parameter);
14899 end Import_Function;
14900
14901 -------------------
14902 -- Import_Object --
14903 -------------------
14904
14905 -- pragma Import_Object (
14906 -- [Internal =>] LOCAL_NAME
14907 -- [, [External =>] EXTERNAL_SYMBOL]
14908 -- [, [Size =>] EXTERNAL_SYMBOL]);
14909
14910 -- EXTERNAL_SYMBOL ::=
14911 -- IDENTIFIER
14912 -- | static_string_EXPRESSION
14913
14914 when Pragma_Import_Object => Import_Object : declare
14915 Args : Args_List (1 .. 3);
14916 Names : constant Name_List (1 .. 3) := (
14917 Name_Internal,
14918 Name_External,
14919 Name_Size);
14920
14921 Internal : Node_Id renames Args (1);
14922 External : Node_Id renames Args (2);
14923 Size : Node_Id renames Args (3);
14924
14925 begin
14926 GNAT_Pragma;
14927 Gather_Associations (Names, Args);
14928 Process_Extended_Import_Export_Object_Pragma (
14929 Arg_Internal => Internal,
14930 Arg_External => External,
14931 Arg_Size => Size);
14932 end Import_Object;
14933
14934 ----------------------
14935 -- Import_Procedure --
14936 ----------------------
14937
14938 -- pragma Import_Procedure (
14939 -- [Internal =>] LOCAL_NAME
14940 -- [, [External =>] EXTERNAL_SYMBOL]
14941 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14942 -- [, [Mechanism =>] MECHANISM]
14943 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
14944
14945 -- EXTERNAL_SYMBOL ::=
14946 -- IDENTIFIER
14947 -- | static_string_EXPRESSION
14948
14949 -- PARAMETER_TYPES ::=
14950 -- null
14951 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14952
14953 -- TYPE_DESIGNATOR ::=
14954 -- subtype_NAME
14955 -- | subtype_Name ' Access
14956
14957 -- MECHANISM ::=
14958 -- MECHANISM_NAME
14959 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14960
14961 -- MECHANISM_ASSOCIATION ::=
14962 -- [formal_parameter_NAME =>] MECHANISM_NAME
14963
14964 -- MECHANISM_NAME ::=
14965 -- Value
14966 -- | Reference
14967 -- | Descriptor [([Class =>] CLASS_NAME)]
14968
14969 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
14970
14971 when Pragma_Import_Procedure => Import_Procedure : declare
14972 Args : Args_List (1 .. 5);
14973 Names : constant Name_List (1 .. 5) := (
14974 Name_Internal,
14975 Name_External,
14976 Name_Parameter_Types,
14977 Name_Mechanism,
14978 Name_First_Optional_Parameter);
14979
14980 Internal : Node_Id renames Args (1);
14981 External : Node_Id renames Args (2);
14982 Parameter_Types : Node_Id renames Args (3);
14983 Mechanism : Node_Id renames Args (4);
14984 First_Optional_Parameter : Node_Id renames Args (5);
14985
14986 begin
14987 GNAT_Pragma;
14988 Gather_Associations (Names, Args);
14989 Process_Extended_Import_Export_Subprogram_Pragma (
14990 Arg_Internal => Internal,
14991 Arg_External => External,
14992 Arg_Parameter_Types => Parameter_Types,
14993 Arg_Mechanism => Mechanism,
14994 Arg_First_Optional_Parameter => First_Optional_Parameter);
14995 end Import_Procedure;
14996
14997 -----------------------------
14998 -- Import_Valued_Procedure --
14999 -----------------------------
15000
15001 -- pragma Import_Valued_Procedure (
15002 -- [Internal =>] LOCAL_NAME
15003 -- [, [External =>] EXTERNAL_SYMBOL]
15004 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15005 -- [, [Mechanism =>] MECHANISM]
15006 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
15007
15008 -- EXTERNAL_SYMBOL ::=
15009 -- IDENTIFIER
15010 -- | static_string_EXPRESSION
15011
15012 -- PARAMETER_TYPES ::=
15013 -- null
15014 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15015
15016 -- TYPE_DESIGNATOR ::=
15017 -- subtype_NAME
15018 -- | subtype_Name ' Access
15019
15020 -- MECHANISM ::=
15021 -- MECHANISM_NAME
15022 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15023
15024 -- MECHANISM_ASSOCIATION ::=
15025 -- [formal_parameter_NAME =>] MECHANISM_NAME
15026
15027 -- MECHANISM_NAME ::=
15028 -- Value
15029 -- | Reference
15030 -- | Descriptor [([Class =>] CLASS_NAME)]
15031
15032 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
15033
15034 when Pragma_Import_Valued_Procedure =>
15035 Import_Valued_Procedure : declare
15036 Args : Args_List (1 .. 5);
15037 Names : constant Name_List (1 .. 5) := (
15038 Name_Internal,
15039 Name_External,
15040 Name_Parameter_Types,
15041 Name_Mechanism,
15042 Name_First_Optional_Parameter);
15043
15044 Internal : Node_Id renames Args (1);
15045 External : Node_Id renames Args (2);
15046 Parameter_Types : Node_Id renames Args (3);
15047 Mechanism : Node_Id renames Args (4);
15048 First_Optional_Parameter : Node_Id renames Args (5);
15049
15050 begin
15051 GNAT_Pragma;
15052 Gather_Associations (Names, Args);
15053 Process_Extended_Import_Export_Subprogram_Pragma (
15054 Arg_Internal => Internal,
15055 Arg_External => External,
15056 Arg_Parameter_Types => Parameter_Types,
15057 Arg_Mechanism => Mechanism,
15058 Arg_First_Optional_Parameter => First_Optional_Parameter);
15059 end Import_Valued_Procedure;
15060
15061 -----------------
15062 -- Independent --
15063 -----------------
15064
15065 -- pragma Independent (record_component_LOCAL_NAME);
15066
15067 when Pragma_Independent => Independent : declare
15068 E_Id : Node_Id;
15069 E : Entity_Id;
15070
15071 begin
15072 Check_Ada_83_Warning;
15073 Ada_2012_Pragma;
15074 Check_No_Identifiers;
15075 Check_Arg_Count (1);
15076 Check_Arg_Is_Local_Name (Arg1);
15077 E_Id := Get_Pragma_Arg (Arg1);
15078
15079 if Etype (E_Id) = Any_Type then
15080 return;
15081 end if;
15082
15083 E := Entity (E_Id);
15084
15085 -- Check we have a record component. We have not yet setup
15086 -- components fully, so identify by syntactic structure.
15087
15088 if Nkind (Declaration_Node (E)) /= N_Component_Declaration then
15089 Error_Pragma_Arg
15090 ("argument for pragma% must be record component", Arg1);
15091 end if;
15092
15093 -- Check duplicate before we chain ourselves
15094
15095 Check_Duplicate_Pragma (E);
15096
15097 -- Chain pragma
15098
15099 if Rep_Item_Too_Early (E, N)
15100 or else
15101 Rep_Item_Too_Late (E, N)
15102 then
15103 return;
15104 end if;
15105
15106 -- Set flag in component
15107
15108 Set_Is_Independent (E);
15109
15110 Independence_Checks.Append ((N, E));
15111 end Independent;
15112
15113 ----------------------------
15114 -- Independent_Components --
15115 ----------------------------
15116
15117 -- pragma Atomic_Components (array_LOCAL_NAME);
15118
15119 -- This processing is shared by Volatile_Components
15120
15121 when Pragma_Independent_Components => Independent_Components : declare
15122 E_Id : Node_Id;
15123 E : Entity_Id;
15124 D : Node_Id;
15125 K : Node_Kind;
15126 C : Node_Id;
15127
15128 begin
15129 Check_Ada_83_Warning;
15130 Ada_2012_Pragma;
15131 Check_No_Identifiers;
15132 Check_Arg_Count (1);
15133 Check_Arg_Is_Local_Name (Arg1);
15134 E_Id := Get_Pragma_Arg (Arg1);
15135
15136 if Etype (E_Id) = Any_Type then
15137 return;
15138 end if;
15139
15140 E := Entity (E_Id);
15141
15142 -- Check duplicate before we chain ourselves
15143
15144 Check_Duplicate_Pragma (E);
15145
15146 -- Check appropriate entity
15147
15148 if Rep_Item_Too_Early (E, N)
15149 or else
15150 Rep_Item_Too_Late (E, N)
15151 then
15152 return;
15153 end if;
15154
15155 D := Declaration_Node (E);
15156 K := Nkind (D);
15157
15158 if K = N_Full_Type_Declaration
15159 and then (Is_Array_Type (E) or else Is_Record_Type (E))
15160 then
15161 Independence_Checks.Append ((N, Base_Type (E)));
15162 Set_Has_Independent_Components (Base_Type (E));
15163
15164 -- For record type, set all components independent
15165
15166 if Is_Record_Type (E) then
15167 C := First_Component (E);
15168 while Present (C) loop
15169 Set_Is_Independent (C);
15170 Next_Component (C);
15171 end loop;
15172 end if;
15173
15174 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15175 and then Nkind (D) = N_Object_Declaration
15176 and then Nkind (Object_Definition (D)) =
15177 N_Constrained_Array_Definition
15178 then
15179 Independence_Checks.Append ((N, Base_Type (Etype (E))));
15180 Set_Has_Independent_Components (Base_Type (Etype (E)));
15181
15182 else
15183 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
15184 end if;
15185 end Independent_Components;
15186
15187 -----------------------
15188 -- Initial_Condition --
15189 -----------------------
15190
15191 -- pragma Initial_Condition (boolean_EXPRESSION);
15192
15193 when Pragma_Initial_Condition => Initial_Condition : declare
15194 Context : constant Node_Id := Parent (Parent (N));
15195 Pack_Id : Entity_Id;
15196 Stmt : Node_Id;
15197
15198 begin
15199 GNAT_Pragma;
15200 Check_Arg_Count (1);
15201
15202 -- Ensure the proper placement of the pragma. Initial_Condition
15203 -- must be associated with a package declaration.
15204
15205 if not Nkind_In (Context, N_Generic_Package_Declaration,
15206 N_Package_Declaration)
15207 then
15208 Pragma_Misplaced;
15209 return;
15210 end if;
15211
15212 Stmt := Prev (N);
15213 while Present (Stmt) loop
15214
15215 -- Skip prior pragmas, but check for duplicates
15216
15217 if Nkind (Stmt) = N_Pragma then
15218 if Pragma_Name (Stmt) = Pname then
15219 Error_Msg_Name_1 := Pname;
15220 Error_Msg_Sloc := Sloc (Stmt);
15221 Error_Msg_N ("pragma % duplicates pragma declared #", N);
15222 end if;
15223
15224 -- Skip internally generated code
15225
15226 elsif not Comes_From_Source (Stmt) then
15227 null;
15228
15229 -- The pragma does not apply to a legal construct, issue an
15230 -- error and stop the analysis.
15231
15232 else
15233 Pragma_Misplaced;
15234 return;
15235 end if;
15236
15237 Stmt := Prev (Stmt);
15238 end loop;
15239
15240 -- The pragma must be analyzed at the end of the visible
15241 -- declarations of the related package. Save the pragma for later
15242 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
15243 -- the contract of the package.
15244
15245 Pack_Id := Defining_Entity (Context);
15246 Add_Contract_Item (N, Pack_Id);
15247
15248 -- Verify the declaration order of pragma Initial_Condition with
15249 -- respect to pragmas Abstract_State and Initializes when SPARK
15250 -- checks are enabled.
15251
15252 if SPARK_Mode /= Off then
15253 Check_Declaration_Order
15254 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15255 Second => N);
15256
15257 Check_Declaration_Order
15258 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
15259 Second => N);
15260 end if;
15261 end Initial_Condition;
15262
15263 ------------------------
15264 -- Initialize_Scalars --
15265 ------------------------
15266
15267 -- pragma Initialize_Scalars;
15268
15269 when Pragma_Initialize_Scalars =>
15270 GNAT_Pragma;
15271 Check_Arg_Count (0);
15272 Check_Valid_Configuration_Pragma;
15273 Check_Restriction (No_Initialize_Scalars, N);
15274
15275 -- Initialize_Scalars creates false positives in CodePeer, and
15276 -- incorrect negative results in GNATprove mode, so ignore this
15277 -- pragma in these modes.
15278
15279 if not Restriction_Active (No_Initialize_Scalars)
15280 and then not (CodePeer_Mode or GNATprove_Mode)
15281 then
15282 Init_Or_Norm_Scalars := True;
15283 Initialize_Scalars := True;
15284 end if;
15285
15286 -----------------
15287 -- Initializes --
15288 -----------------
15289
15290 -- pragma Initializes (INITIALIZATION_SPEC);
15291
15292 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
15293
15294 -- INITIALIZATION_LIST ::=
15295 -- INITIALIZATION_ITEM
15296 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15297
15298 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15299
15300 -- INPUT_LIST ::=
15301 -- null
15302 -- | INPUT
15303 -- | (INPUT {, INPUT})
15304
15305 -- INPUT ::= name
15306
15307 when Pragma_Initializes => Initializes : declare
15308 Context : constant Node_Id := Parent (Parent (N));
15309 Pack_Id : Entity_Id;
15310 Stmt : Node_Id;
15311
15312 begin
15313 GNAT_Pragma;
15314 Check_Arg_Count (1);
15315 Ensure_Aggregate_Form (Arg1);
15316
15317 -- Ensure the proper placement of the pragma. Initializes must be
15318 -- associated with a package declaration.
15319
15320 if not Nkind_In (Context, N_Generic_Package_Declaration,
15321 N_Package_Declaration)
15322 then
15323 Pragma_Misplaced;
15324 return;
15325 end if;
15326
15327 Stmt := Prev (N);
15328 while Present (Stmt) loop
15329
15330 -- Skip prior pragmas, but check for duplicates
15331
15332 if Nkind (Stmt) = N_Pragma then
15333 if Pragma_Name (Stmt) = Pname then
15334 Error_Msg_Name_1 := Pname;
15335 Error_Msg_Sloc := Sloc (Stmt);
15336 Error_Msg_N ("pragma % duplicates pragma declared #", N);
15337 end if;
15338
15339 -- Skip internally generated code
15340
15341 elsif not Comes_From_Source (Stmt) then
15342 null;
15343
15344 -- The pragma does not apply to a legal construct, issue an
15345 -- error and stop the analysis.
15346
15347 else
15348 Pragma_Misplaced;
15349 return;
15350 end if;
15351
15352 Stmt := Prev (Stmt);
15353 end loop;
15354
15355 -- The pragma must be analyzed at the end of the visible
15356 -- declarations of the related package. Save the pragma for later
15357 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
15358 -- contract of the package.
15359
15360 Pack_Id := Defining_Entity (Context);
15361 Add_Contract_Item (N, Pack_Id);
15362
15363 -- Verify the declaration order of pragmas Abstract_State and
15364 -- Initializes when SPARK checks are enabled.
15365
15366 if SPARK_Mode /= Off then
15367 Check_Declaration_Order
15368 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15369 Second => N);
15370 end if;
15371 end Initializes;
15372
15373 ------------
15374 -- Inline --
15375 ------------
15376
15377 -- pragma Inline ( NAME {, NAME} );
15378
15379 when Pragma_Inline =>
15380
15381 -- Inline status is Enabled if inlining option is active
15382
15383 if Inline_Active then
15384 Process_Inline (Enabled);
15385 else
15386 Process_Inline (Disabled);
15387 end if;
15388
15389 -------------------
15390 -- Inline_Always --
15391 -------------------
15392
15393 -- pragma Inline_Always ( NAME {, NAME} );
15394
15395 when Pragma_Inline_Always =>
15396 GNAT_Pragma;
15397
15398 -- Pragma always active unless in CodePeer mode. It is disabled
15399 -- in CodePeer mode because inlining is not helpful, and enabling
15400 -- if caused walk order issues.
15401
15402 -- Historical note: this pragma used to be disabled in GNATprove
15403 -- mode as well, but that was odd since walk order should not be
15404 -- an issue in that case.
15405
15406 if not CodePeer_Mode then
15407 Process_Inline (Enabled);
15408 end if;
15409
15410 --------------------
15411 -- Inline_Generic --
15412 --------------------
15413
15414 -- pragma Inline_Generic (NAME {, NAME});
15415
15416 when Pragma_Inline_Generic =>
15417 GNAT_Pragma;
15418 Process_Generic_List;
15419
15420 ----------------------
15421 -- Inspection_Point --
15422 ----------------------
15423
15424 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
15425
15426 when Pragma_Inspection_Point => Inspection_Point : declare
15427 Arg : Node_Id;
15428 Exp : Node_Id;
15429
15430 begin
15431 ip;
15432
15433 if Arg_Count > 0 then
15434 Arg := Arg1;
15435 loop
15436 Exp := Get_Pragma_Arg (Arg);
15437 Analyze (Exp);
15438
15439 if not Is_Entity_Name (Exp)
15440 or else not Is_Object (Entity (Exp))
15441 then
15442 Error_Pragma_Arg ("object name required", Arg);
15443 end if;
15444
15445 Next (Arg);
15446 exit when No (Arg);
15447 end loop;
15448 end if;
15449 end Inspection_Point;
15450
15451 ---------------
15452 -- Interface --
15453 ---------------
15454
15455 -- pragma Interface (
15456 -- [ Convention =>] convention_IDENTIFIER,
15457 -- [ Entity =>] LOCAL_NAME
15458 -- [, [External_Name =>] static_string_EXPRESSION ]
15459 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15460
15461 when Pragma_Interface =>
15462 GNAT_Pragma;
15463 Check_Arg_Order
15464 ((Name_Convention,
15465 Name_Entity,
15466 Name_External_Name,
15467 Name_Link_Name));
15468 Check_At_Least_N_Arguments (2);
15469 Check_At_Most_N_Arguments (4);
15470 Process_Import_Or_Interface;
15471
15472 -- In Ada 2005, the permission to use Interface (a reserved word)
15473 -- as a pragma name is considered an obsolescent feature, and this
15474 -- pragma was already obsolescent in Ada 95.
15475
15476 if Ada_Version >= Ada_95 then
15477 Check_Restriction
15478 (No_Obsolescent_Features, Pragma_Identifier (N));
15479
15480 if Warn_On_Obsolescent_Feature then
15481 Error_Msg_N
15482 ("pragma Interface is an obsolescent feature?j?", N);
15483 Error_Msg_N
15484 ("|use pragma Import instead?j?", N);
15485 end if;
15486 end if;
15487
15488 --------------------
15489 -- Interface_Name --
15490 --------------------
15491
15492 -- pragma Interface_Name (
15493 -- [ Entity =>] LOCAL_NAME
15494 -- [,[External_Name =>] static_string_EXPRESSION ]
15495 -- [,[Link_Name =>] static_string_EXPRESSION ]);
15496
15497 when Pragma_Interface_Name => Interface_Name : declare
15498 Id : Node_Id;
15499 Def_Id : Entity_Id;
15500 Hom_Id : Entity_Id;
15501 Found : Boolean;
15502
15503 begin
15504 GNAT_Pragma;
15505 Check_Arg_Order
15506 ((Name_Entity, Name_External_Name, Name_Link_Name));
15507 Check_At_Least_N_Arguments (2);
15508 Check_At_Most_N_Arguments (3);
15509 Id := Get_Pragma_Arg (Arg1);
15510 Analyze (Id);
15511
15512 -- This is obsolete from Ada 95 on, but it is an implementation
15513 -- defined pragma, so we do not consider that it violates the
15514 -- restriction (No_Obsolescent_Features).
15515
15516 if Ada_Version >= Ada_95 then
15517 if Warn_On_Obsolescent_Feature then
15518 Error_Msg_N
15519 ("pragma Interface_Name is an obsolescent feature?j?", N);
15520 Error_Msg_N
15521 ("|use pragma Import instead?j?", N);
15522 end if;
15523 end if;
15524
15525 if not Is_Entity_Name (Id) then
15526 Error_Pragma_Arg
15527 ("first argument for pragma% must be entity name", Arg1);
15528 elsif Etype (Id) = Any_Type then
15529 return;
15530 else
15531 Def_Id := Entity (Id);
15532 end if;
15533
15534 -- Special DEC-compatible processing for the object case, forces
15535 -- object to be imported.
15536
15537 if Ekind (Def_Id) = E_Variable then
15538 Kill_Size_Check_Code (Def_Id);
15539 Note_Possible_Modification (Id, Sure => False);
15540
15541 -- Initialization is not allowed for imported variable
15542
15543 if Present (Expression (Parent (Def_Id)))
15544 and then Comes_From_Source (Expression (Parent (Def_Id)))
15545 then
15546 Error_Msg_Sloc := Sloc (Def_Id);
15547 Error_Pragma_Arg
15548 ("no initialization allowed for declaration of& #",
15549 Arg2);
15550
15551 else
15552 -- For compatibility, support VADS usage of providing both
15553 -- pragmas Interface and Interface_Name to obtain the effect
15554 -- of a single Import pragma.
15555
15556 if Is_Imported (Def_Id)
15557 and then Present (First_Rep_Item (Def_Id))
15558 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
15559 and then
15560 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
15561 then
15562 null;
15563 else
15564 Set_Imported (Def_Id);
15565 end if;
15566
15567 Set_Is_Public (Def_Id);
15568 Process_Interface_Name (Def_Id, Arg2, Arg3);
15569 end if;
15570
15571 -- Otherwise must be subprogram
15572
15573 elsif not Is_Subprogram (Def_Id) then
15574 Error_Pragma_Arg
15575 ("argument of pragma% is not subprogram", Arg1);
15576
15577 else
15578 Check_At_Most_N_Arguments (3);
15579 Hom_Id := Def_Id;
15580 Found := False;
15581
15582 -- Loop through homonyms
15583
15584 loop
15585 Def_Id := Get_Base_Subprogram (Hom_Id);
15586
15587 if Is_Imported (Def_Id) then
15588 Process_Interface_Name (Def_Id, Arg2, Arg3);
15589 Found := True;
15590 end if;
15591
15592 exit when From_Aspect_Specification (N);
15593 Hom_Id := Homonym (Hom_Id);
15594
15595 exit when No (Hom_Id)
15596 or else Scope (Hom_Id) /= Current_Scope;
15597 end loop;
15598
15599 if not Found then
15600 Error_Pragma_Arg
15601 ("argument of pragma% is not imported subprogram",
15602 Arg1);
15603 end if;
15604 end if;
15605 end Interface_Name;
15606
15607 -----------------------
15608 -- Interrupt_Handler --
15609 -----------------------
15610
15611 -- pragma Interrupt_Handler (handler_NAME);
15612
15613 when Pragma_Interrupt_Handler =>
15614 Check_Ada_83_Warning;
15615 Check_Arg_Count (1);
15616 Check_No_Identifiers;
15617
15618 if No_Run_Time_Mode then
15619 Error_Msg_CRT ("Interrupt_Handler pragma", N);
15620 else
15621 Check_Interrupt_Or_Attach_Handler;
15622 Process_Interrupt_Or_Attach_Handler;
15623 end if;
15624
15625 ------------------------
15626 -- Interrupt_Priority --
15627 ------------------------
15628
15629 -- pragma Interrupt_Priority [(EXPRESSION)];
15630
15631 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
15632 P : constant Node_Id := Parent (N);
15633 Arg : Node_Id;
15634 Ent : Entity_Id;
15635
15636 begin
15637 Check_Ada_83_Warning;
15638
15639 if Arg_Count /= 0 then
15640 Arg := Get_Pragma_Arg (Arg1);
15641 Check_Arg_Count (1);
15642 Check_No_Identifiers;
15643
15644 -- The expression must be analyzed in the special manner
15645 -- described in "Handling of Default and Per-Object
15646 -- Expressions" in sem.ads.
15647
15648 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
15649 end if;
15650
15651 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
15652 Pragma_Misplaced;
15653 return;
15654
15655 else
15656 Ent := Defining_Identifier (Parent (P));
15657
15658 -- Check duplicate pragma before we chain the pragma in the Rep
15659 -- Item chain of Ent.
15660
15661 Check_Duplicate_Pragma (Ent);
15662 Record_Rep_Item (Ent, N);
15663 end if;
15664 end Interrupt_Priority;
15665
15666 ---------------------
15667 -- Interrupt_State --
15668 ---------------------
15669
15670 -- pragma Interrupt_State (
15671 -- [Name =>] INTERRUPT_ID,
15672 -- [State =>] INTERRUPT_STATE);
15673
15674 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15675 -- INTERRUPT_STATE => System | Runtime | User
15676
15677 -- Note: if the interrupt id is given as an identifier, then it must
15678 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
15679 -- given as a static integer expression which must be in the range of
15680 -- Ada.Interrupts.Interrupt_ID.
15681
15682 when Pragma_Interrupt_State => Interrupt_State : declare
15683 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
15684 -- This is the entity Ada.Interrupts.Interrupt_ID;
15685
15686 State_Type : Character;
15687 -- Set to 's'/'r'/'u' for System/Runtime/User
15688
15689 IST_Num : Pos;
15690 -- Index to entry in Interrupt_States table
15691
15692 Int_Val : Uint;
15693 -- Value of interrupt
15694
15695 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
15696 -- The first argument to the pragma
15697
15698 Int_Ent : Entity_Id;
15699 -- Interrupt entity in Ada.Interrupts.Names
15700
15701 begin
15702 GNAT_Pragma;
15703 Check_Arg_Order ((Name_Name, Name_State));
15704 Check_Arg_Count (2);
15705
15706 Check_Optional_Identifier (Arg1, Name_Name);
15707 Check_Optional_Identifier (Arg2, Name_State);
15708 Check_Arg_Is_Identifier (Arg2);
15709
15710 -- First argument is identifier
15711
15712 if Nkind (Arg1X) = N_Identifier then
15713
15714 -- Search list of names in Ada.Interrupts.Names
15715
15716 Int_Ent := First_Entity (RTE (RE_Names));
15717 loop
15718 if No (Int_Ent) then
15719 Error_Pragma_Arg ("invalid interrupt name", Arg1);
15720
15721 elsif Chars (Int_Ent) = Chars (Arg1X) then
15722 Int_Val := Expr_Value (Constant_Value (Int_Ent));
15723 exit;
15724 end if;
15725
15726 Next_Entity (Int_Ent);
15727 end loop;
15728
15729 -- First argument is not an identifier, so it must be a static
15730 -- expression of type Ada.Interrupts.Interrupt_ID.
15731
15732 else
15733 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15734 Int_Val := Expr_Value (Arg1X);
15735
15736 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
15737 or else
15738 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
15739 then
15740 Error_Pragma_Arg
15741 ("value not in range of type "
15742 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
15743 end if;
15744 end if;
15745
15746 -- Check OK state
15747
15748 case Chars (Get_Pragma_Arg (Arg2)) is
15749 when Name_Runtime => State_Type := 'r';
15750 when Name_System => State_Type := 's';
15751 when Name_User => State_Type := 'u';
15752
15753 when others =>
15754 Error_Pragma_Arg ("invalid interrupt state", Arg2);
15755 end case;
15756
15757 -- Check if entry is already stored
15758
15759 IST_Num := Interrupt_States.First;
15760 loop
15761 -- If entry not found, add it
15762
15763 if IST_Num > Interrupt_States.Last then
15764 Interrupt_States.Append
15765 ((Interrupt_Number => UI_To_Int (Int_Val),
15766 Interrupt_State => State_Type,
15767 Pragma_Loc => Loc));
15768 exit;
15769
15770 -- Case of entry for the same entry
15771
15772 elsif Int_Val = Interrupt_States.Table (IST_Num).
15773 Interrupt_Number
15774 then
15775 -- If state matches, done, no need to make redundant entry
15776
15777 exit when
15778 State_Type = Interrupt_States.Table (IST_Num).
15779 Interrupt_State;
15780
15781 -- Otherwise if state does not match, error
15782
15783 Error_Msg_Sloc :=
15784 Interrupt_States.Table (IST_Num).Pragma_Loc;
15785 Error_Pragma_Arg
15786 ("state conflicts with that given #", Arg2);
15787 exit;
15788 end if;
15789
15790 IST_Num := IST_Num + 1;
15791 end loop;
15792 end Interrupt_State;
15793
15794 ---------------
15795 -- Invariant --
15796 ---------------
15797
15798 -- pragma Invariant
15799 -- ([Entity =>] type_LOCAL_NAME,
15800 -- [Check =>] EXPRESSION
15801 -- [,[Message =>] String_Expression]);
15802
15803 when Pragma_Invariant => Invariant : declare
15804 Type_Id : Node_Id;
15805 Typ : Entity_Id;
15806 PDecl : Node_Id;
15807 Discard : Boolean;
15808
15809 begin
15810 GNAT_Pragma;
15811 Check_At_Least_N_Arguments (2);
15812 Check_At_Most_N_Arguments (3);
15813 Check_Optional_Identifier (Arg1, Name_Entity);
15814 Check_Optional_Identifier (Arg2, Name_Check);
15815
15816 if Arg_Count = 3 then
15817 Check_Optional_Identifier (Arg3, Name_Message);
15818 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
15819 end if;
15820
15821 Check_Arg_Is_Local_Name (Arg1);
15822
15823 Type_Id := Get_Pragma_Arg (Arg1);
15824 Find_Type (Type_Id);
15825 Typ := Entity (Type_Id);
15826
15827 if Typ = Any_Type then
15828 return;
15829
15830 -- An invariant must apply to a private type, or appear in the
15831 -- private part of a package spec and apply to a completion.
15832 -- a class-wide invariant can only appear on a private declaration
15833 -- or private extension, not a completion.
15834
15835 elsif Ekind_In (Typ, E_Private_Type,
15836 E_Record_Type_With_Private,
15837 E_Limited_Private_Type)
15838 then
15839 null;
15840
15841 elsif In_Private_Part (Current_Scope)
15842 and then Has_Private_Declaration (Typ)
15843 and then not Class_Present (N)
15844 then
15845 null;
15846
15847 elsif In_Private_Part (Current_Scope) then
15848 Error_Pragma_Arg
15849 ("pragma% only allowed for private type declared in "
15850 & "visible part", Arg1);
15851
15852 else
15853 Error_Pragma_Arg
15854 ("pragma% only allowed for private type", Arg1);
15855 end if;
15856
15857 -- Note that the type has at least one invariant, and also that
15858 -- it has inheritable invariants if we have Invariant'Class
15859 -- or Type_Invariant'Class. Build the corresponding invariant
15860 -- procedure declaration, so that calls to it can be generated
15861 -- before the body is built (e.g. within an expression function).
15862
15863 PDecl := Build_Invariant_Procedure_Declaration (Typ);
15864
15865 Insert_After (N, PDecl);
15866 Analyze (PDecl);
15867
15868 if Class_Present (N) then
15869 Set_Has_Inheritable_Invariants (Typ);
15870 end if;
15871
15872 -- The remaining processing is simply to link the pragma on to
15873 -- the rep item chain, for processing when the type is frozen.
15874 -- This is accomplished by a call to Rep_Item_Too_Late.
15875
15876 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15877 end Invariant;
15878
15879 ----------------------
15880 -- Java_Constructor --
15881 ----------------------
15882
15883 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15884
15885 -- Also handles pragma CIL_Constructor
15886
15887 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
15888 Java_Constructor : declare
15889 Convention : Convention_Id;
15890 Def_Id : Entity_Id;
15891 Hom_Id : Entity_Id;
15892 Id : Entity_Id;
15893 This_Formal : Entity_Id;
15894
15895 begin
15896 GNAT_Pragma;
15897 Check_Arg_Count (1);
15898 Check_Optional_Identifier (Arg1, Name_Entity);
15899 Check_Arg_Is_Local_Name (Arg1);
15900
15901 Id := Get_Pragma_Arg (Arg1);
15902 Find_Program_Unit_Name (Id);
15903
15904 -- If we did not find the name, we are done
15905
15906 if Etype (Id) = Any_Type then
15907 return;
15908 end if;
15909
15910 -- Check wrong use of pragma in wrong VM target
15911
15912 if VM_Target = No_VM then
15913 return;
15914
15915 elsif VM_Target = CLI_Target
15916 and then Prag_Id = Pragma_Java_Constructor
15917 then
15918 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
15919
15920 elsif VM_Target = JVM_Target
15921 and then Prag_Id = Pragma_CIL_Constructor
15922 then
15923 Error_Pragma ("must use pragma 'Java_'Constructor");
15924 end if;
15925
15926 case Prag_Id is
15927 when Pragma_CIL_Constructor => Convention := Convention_CIL;
15928 when Pragma_Java_Constructor => Convention := Convention_Java;
15929 when others => null;
15930 end case;
15931
15932 Hom_Id := Entity (Id);
15933
15934 -- Loop through homonyms
15935
15936 loop
15937 Def_Id := Get_Base_Subprogram (Hom_Id);
15938
15939 -- The constructor is required to be a function
15940
15941 if Ekind (Def_Id) /= E_Function then
15942 if VM_Target = JVM_Target then
15943 Error_Pragma_Arg
15944 ("pragma% requires function returning a 'Java access "
15945 & "type", Def_Id);
15946 else
15947 Error_Pragma_Arg
15948 ("pragma% requires function returning a 'C'I'L access "
15949 & "type", Def_Id);
15950 end if;
15951 end if;
15952
15953 -- Check arguments: For tagged type the first formal must be
15954 -- named "this" and its type must be a named access type
15955 -- designating a class-wide tagged type that has convention
15956 -- CIL/Java. The first formal must also have a null default
15957 -- value. For example:
15958
15959 -- type Typ is tagged ...
15960 -- type Ref is access all Typ;
15961 -- pragma Convention (CIL, Typ);
15962
15963 -- function New_Typ (This : Ref) return Ref;
15964 -- function New_Typ (This : Ref; I : Integer) return Ref;
15965 -- pragma Cil_Constructor (New_Typ);
15966
15967 -- Reason: The first formal must NOT be a primitive of the
15968 -- tagged type.
15969
15970 -- This rule also applies to constructors of delegates used
15971 -- to interface with standard target libraries. For example:
15972
15973 -- type Delegate is access procedure ...
15974 -- pragma Import (CIL, Delegate, ...);
15975
15976 -- function new_Delegate
15977 -- (This : Delegate := null; ... ) return Delegate;
15978
15979 -- For value-types this rule does not apply.
15980
15981 if not Is_Value_Type (Etype (Def_Id)) then
15982 if No (First_Formal (Def_Id)) then
15983 Error_Msg_Name_1 := Pname;
15984 Error_Msg_N ("% function must have parameters", Def_Id);
15985 return;
15986 end if;
15987
15988 -- In the JRE library we have several occurrences in which
15989 -- the "this" parameter is not the first formal.
15990
15991 This_Formal := First_Formal (Def_Id);
15992
15993 -- In the JRE library we have several occurrences in which
15994 -- the "this" parameter is not the first formal. Search for
15995 -- it.
15996
15997 if VM_Target = JVM_Target then
15998 while Present (This_Formal)
15999 and then Get_Name_String (Chars (This_Formal)) /= "this"
16000 loop
16001 Next_Formal (This_Formal);
16002 end loop;
16003
16004 if No (This_Formal) then
16005 This_Formal := First_Formal (Def_Id);
16006 end if;
16007 end if;
16008
16009 -- Warning: The first parameter should be named "this".
16010 -- We temporarily allow it because we have the following
16011 -- case in the Java runtime (file s-osinte.ads) ???
16012
16013 -- function new_Thread
16014 -- (Self_Id : System.Address) return Thread_Id;
16015 -- pragma Java_Constructor (new_Thread);
16016
16017 if VM_Target = JVM_Target
16018 and then Get_Name_String (Chars (First_Formal (Def_Id)))
16019 = "self_id"
16020 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
16021 then
16022 null;
16023
16024 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
16025 Error_Msg_Name_1 := Pname;
16026 Error_Msg_N
16027 ("first formal of % function must be named `this`",
16028 Parent (This_Formal));
16029
16030 elsif not Is_Access_Type (Etype (This_Formal)) then
16031 Error_Msg_Name_1 := Pname;
16032 Error_Msg_N
16033 ("first formal of % function must be an access type",
16034 Parameter_Type (Parent (This_Formal)));
16035
16036 -- For delegates the type of the first formal must be a
16037 -- named access-to-subprogram type (see previous example)
16038
16039 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
16040 and then Ekind (Etype (This_Formal))
16041 /= E_Access_Subprogram_Type
16042 then
16043 Error_Msg_Name_1 := Pname;
16044 Error_Msg_N
16045 ("first formal of % function must be a named access "
16046 & "to subprogram type",
16047 Parameter_Type (Parent (This_Formal)));
16048
16049 -- Warning: We should reject anonymous access types because
16050 -- the constructor must not be handled as a primitive of the
16051 -- tagged type. We temporarily allow it because this profile
16052 -- is currently generated by cil2ada???
16053
16054 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
16055 and then not Ekind_In (Etype (This_Formal),
16056 E_Access_Type,
16057 E_General_Access_Type,
16058 E_Anonymous_Access_Type)
16059 then
16060 Error_Msg_Name_1 := Pname;
16061 Error_Msg_N
16062 ("first formal of % function must be a named access "
16063 & "type", Parameter_Type (Parent (This_Formal)));
16064
16065 elsif Atree.Convention
16066 (Designated_Type (Etype (This_Formal))) /= Convention
16067 then
16068 Error_Msg_Name_1 := Pname;
16069
16070 if Convention = Convention_Java then
16071 Error_Msg_N
16072 ("pragma% requires convention 'Cil in designated "
16073 & "type", Parameter_Type (Parent (This_Formal)));
16074 else
16075 Error_Msg_N
16076 ("pragma% requires convention 'Java in designated "
16077 & "type", Parameter_Type (Parent (This_Formal)));
16078 end if;
16079
16080 elsif No (Expression (Parent (This_Formal)))
16081 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
16082 then
16083 Error_Msg_Name_1 := Pname;
16084 Error_Msg_N
16085 ("pragma% requires first formal with default `null`",
16086 Parameter_Type (Parent (This_Formal)));
16087 end if;
16088 end if;
16089
16090 -- Check result type: the constructor must be a function
16091 -- returning:
16092 -- * a value type (only allowed in the CIL compiler)
16093 -- * an access-to-subprogram type with convention Java/CIL
16094 -- * an access-type designating a type that has convention
16095 -- Java/CIL.
16096
16097 if Is_Value_Type (Etype (Def_Id)) then
16098 null;
16099
16100 -- Access-to-subprogram type with convention Java/CIL
16101
16102 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
16103 if Atree.Convention (Etype (Def_Id)) /= Convention then
16104 if Convention = Convention_Java then
16105 Error_Pragma_Arg
16106 ("pragma% requires function returning a 'Java "
16107 & "access type", Arg1);
16108 else
16109 pragma Assert (Convention = Convention_CIL);
16110 Error_Pragma_Arg
16111 ("pragma% requires function returning a 'C'I'L "
16112 & "access type", Arg1);
16113 end if;
16114 end if;
16115
16116 elsif Is_Access_Type (Etype (Def_Id)) then
16117 if not Ekind_In (Etype (Def_Id), E_Access_Type,
16118 E_General_Access_Type)
16119 or else
16120 Atree.Convention
16121 (Designated_Type (Etype (Def_Id))) /= Convention
16122 then
16123 Error_Msg_Name_1 := Pname;
16124
16125 if Convention = Convention_Java then
16126 Error_Pragma_Arg
16127 ("pragma% requires function returning a named "
16128 & "'Java access type", Arg1);
16129 else
16130 Error_Pragma_Arg
16131 ("pragma% requires function returning a named "
16132 & "'C'I'L access type", Arg1);
16133 end if;
16134 end if;
16135 end if;
16136
16137 Set_Is_Constructor (Def_Id);
16138 Set_Convention (Def_Id, Convention);
16139 Set_Is_Imported (Def_Id);
16140
16141 exit when From_Aspect_Specification (N);
16142 Hom_Id := Homonym (Hom_Id);
16143
16144 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
16145 end loop;
16146 end Java_Constructor;
16147
16148 ----------------------
16149 -- Java_Interface --
16150 ----------------------
16151
16152 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
16153
16154 when Pragma_Java_Interface => Java_Interface : declare
16155 Arg : Node_Id;
16156 Typ : Entity_Id;
16157
16158 begin
16159 GNAT_Pragma;
16160 Check_Arg_Count (1);
16161 Check_Optional_Identifier (Arg1, Name_Entity);
16162 Check_Arg_Is_Local_Name (Arg1);
16163
16164 Arg := Get_Pragma_Arg (Arg1);
16165 Analyze (Arg);
16166
16167 if Etype (Arg) = Any_Type then
16168 return;
16169 end if;
16170
16171 if not Is_Entity_Name (Arg)
16172 or else not Is_Type (Entity (Arg))
16173 then
16174 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
16175 end if;
16176
16177 Typ := Underlying_Type (Entity (Arg));
16178
16179 -- For now simply check some of the semantic constraints on the
16180 -- type. This currently leaves out some restrictions on interface
16181 -- types, namely that the parent type must be java.lang.Object.Typ
16182 -- and that all primitives of the type should be declared
16183 -- abstract. ???
16184
16185 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
16186 Error_Pragma_Arg
16187 ("pragma% requires an abstract tagged type", Arg1);
16188
16189 elsif not Has_Discriminants (Typ)
16190 or else Ekind (Etype (First_Discriminant (Typ)))
16191 /= E_Anonymous_Access_Type
16192 or else
16193 not Is_Class_Wide_Type
16194 (Designated_Type (Etype (First_Discriminant (Typ))))
16195 then
16196 Error_Pragma_Arg
16197 ("type must have a class-wide access discriminant", Arg1);
16198 end if;
16199 end Java_Interface;
16200
16201 ----------------
16202 -- Keep_Names --
16203 ----------------
16204
16205 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16206
16207 when Pragma_Keep_Names => Keep_Names : declare
16208 Arg : Node_Id;
16209
16210 begin
16211 GNAT_Pragma;
16212 Check_Arg_Count (1);
16213 Check_Optional_Identifier (Arg1, Name_On);
16214 Check_Arg_Is_Local_Name (Arg1);
16215
16216 Arg := Get_Pragma_Arg (Arg1);
16217 Analyze (Arg);
16218
16219 if Etype (Arg) = Any_Type then
16220 return;
16221 end if;
16222
16223 if not Is_Entity_Name (Arg)
16224 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
16225 then
16226 Error_Pragma_Arg
16227 ("pragma% requires a local enumeration type", Arg1);
16228 end if;
16229
16230 Set_Discard_Names (Entity (Arg), False);
16231 end Keep_Names;
16232
16233 -------------
16234 -- License --
16235 -------------
16236
16237 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16238
16239 when Pragma_License =>
16240 GNAT_Pragma;
16241 Check_Arg_Count (1);
16242 Check_No_Identifiers;
16243 Check_Valid_Configuration_Pragma;
16244 Check_Arg_Is_Identifier (Arg1);
16245
16246 declare
16247 Sind : constant Source_File_Index :=
16248 Source_Index (Current_Sem_Unit);
16249
16250 begin
16251 case Chars (Get_Pragma_Arg (Arg1)) is
16252 when Name_GPL =>
16253 Set_License (Sind, GPL);
16254
16255 when Name_Modified_GPL =>
16256 Set_License (Sind, Modified_GPL);
16257
16258 when Name_Restricted =>
16259 Set_License (Sind, Restricted);
16260
16261 when Name_Unrestricted =>
16262 Set_License (Sind, Unrestricted);
16263
16264 when others =>
16265 Error_Pragma_Arg ("invalid license name", Arg1);
16266 end case;
16267 end;
16268
16269 ---------------
16270 -- Link_With --
16271 ---------------
16272
16273 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16274
16275 when Pragma_Link_With => Link_With : declare
16276 Arg : Node_Id;
16277
16278 begin
16279 GNAT_Pragma;
16280
16281 if Operating_Mode = Generate_Code
16282 and then In_Extended_Main_Source_Unit (N)
16283 then
16284 Check_At_Least_N_Arguments (1);
16285 Check_No_Identifiers;
16286 Check_Is_In_Decl_Part_Or_Package_Spec;
16287 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16288 Start_String;
16289
16290 Arg := Arg1;
16291 while Present (Arg) loop
16292 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16293
16294 -- Store argument, converting sequences of spaces to a
16295 -- single null character (this is one of the differences
16296 -- in processing between Link_With and Linker_Options).
16297
16298 Arg_Store : declare
16299 C : constant Char_Code := Get_Char_Code (' ');
16300 S : constant String_Id :=
16301 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
16302 L : constant Nat := String_Length (S);
16303 F : Nat := 1;
16304
16305 procedure Skip_Spaces;
16306 -- Advance F past any spaces
16307
16308 -----------------
16309 -- Skip_Spaces --
16310 -----------------
16311
16312 procedure Skip_Spaces is
16313 begin
16314 while F <= L and then Get_String_Char (S, F) = C loop
16315 F := F + 1;
16316 end loop;
16317 end Skip_Spaces;
16318
16319 -- Start of processing for Arg_Store
16320
16321 begin
16322 Skip_Spaces; -- skip leading spaces
16323
16324 -- Loop through characters, changing any embedded
16325 -- sequence of spaces to a single null character (this
16326 -- is how Link_With/Linker_Options differ)
16327
16328 while F <= L loop
16329 if Get_String_Char (S, F) = C then
16330 Skip_Spaces;
16331 exit when F > L;
16332 Store_String_Char (ASCII.NUL);
16333
16334 else
16335 Store_String_Char (Get_String_Char (S, F));
16336 F := F + 1;
16337 end if;
16338 end loop;
16339 end Arg_Store;
16340
16341 Arg := Next (Arg);
16342
16343 if Present (Arg) then
16344 Store_String_Char (ASCII.NUL);
16345 end if;
16346 end loop;
16347
16348 Store_Linker_Option_String (End_String);
16349 end if;
16350 end Link_With;
16351
16352 ------------------
16353 -- Linker_Alias --
16354 ------------------
16355
16356 -- pragma Linker_Alias (
16357 -- [Entity =>] LOCAL_NAME
16358 -- [Target =>] static_string_EXPRESSION);
16359
16360 when Pragma_Linker_Alias =>
16361 GNAT_Pragma;
16362 Check_Arg_Order ((Name_Entity, Name_Target));
16363 Check_Arg_Count (2);
16364 Check_Optional_Identifier (Arg1, Name_Entity);
16365 Check_Optional_Identifier (Arg2, Name_Target);
16366 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16367 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16368
16369 -- The only processing required is to link this item on to the
16370 -- list of rep items for the given entity. This is accomplished
16371 -- by the call to Rep_Item_Too_Late (when no error is detected
16372 -- and False is returned).
16373
16374 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16375 return;
16376 else
16377 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16378 end if;
16379
16380 ------------------------
16381 -- Linker_Constructor --
16382 ------------------------
16383
16384 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16385
16386 -- Code is shared with Linker_Destructor
16387
16388 -----------------------
16389 -- Linker_Destructor --
16390 -----------------------
16391
16392 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16393
16394 when Pragma_Linker_Constructor |
16395 Pragma_Linker_Destructor =>
16396 Linker_Constructor : declare
16397 Arg1_X : Node_Id;
16398 Proc : Entity_Id;
16399
16400 begin
16401 GNAT_Pragma;
16402 Check_Arg_Count (1);
16403 Check_No_Identifiers;
16404 Check_Arg_Is_Local_Name (Arg1);
16405 Arg1_X := Get_Pragma_Arg (Arg1);
16406 Analyze (Arg1_X);
16407 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16408
16409 if not Is_Library_Level_Entity (Proc) then
16410 Error_Pragma_Arg
16411 ("argument for pragma% must be library level entity", Arg1);
16412 end if;
16413
16414 -- The only processing required is to link this item on to the
16415 -- list of rep items for the given entity. This is accomplished
16416 -- by the call to Rep_Item_Too_Late (when no error is detected
16417 -- and False is returned).
16418
16419 if Rep_Item_Too_Late (Proc, N) then
16420 return;
16421 else
16422 Set_Has_Gigi_Rep_Item (Proc);
16423 end if;
16424 end Linker_Constructor;
16425
16426 --------------------
16427 -- Linker_Options --
16428 --------------------
16429
16430 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16431
16432 when Pragma_Linker_Options => Linker_Options : declare
16433 Arg : Node_Id;
16434
16435 begin
16436 Check_Ada_83_Warning;
16437 Check_No_Identifiers;
16438 Check_Arg_Count (1);
16439 Check_Is_In_Decl_Part_Or_Package_Spec;
16440 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
16441 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
16442
16443 Arg := Arg2;
16444 while Present (Arg) loop
16445 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16446 Store_String_Char (ASCII.NUL);
16447 Store_String_Chars
16448 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16449 Arg := Next (Arg);
16450 end loop;
16451
16452 if Operating_Mode = Generate_Code
16453 and then In_Extended_Main_Source_Unit (N)
16454 then
16455 Store_Linker_Option_String (End_String);
16456 end if;
16457 end Linker_Options;
16458
16459 --------------------
16460 -- Linker_Section --
16461 --------------------
16462
16463 -- pragma Linker_Section (
16464 -- [Entity =>] LOCAL_NAME
16465 -- [Section =>] static_string_EXPRESSION);
16466
16467 when Pragma_Linker_Section => Linker_Section : declare
16468 Arg : Node_Id;
16469 Ent : Entity_Id;
16470
16471 begin
16472 GNAT_Pragma;
16473 Check_Arg_Order ((Name_Entity, Name_Section));
16474 Check_Arg_Count (2);
16475 Check_Optional_Identifier (Arg1, Name_Entity);
16476 Check_Optional_Identifier (Arg2, Name_Section);
16477 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16478 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16479
16480 -- Check kind of entity
16481
16482 Arg := Get_Pragma_Arg (Arg1);
16483 Ent := Entity (Arg);
16484
16485 case Ekind (Ent) is
16486
16487 -- Objects (constants and variables) and types. For these cases
16488 -- all we need to do is to set the Linker_Section_pragma field.
16489
16490 when E_Constant | E_Variable | Type_Kind =>
16491 Set_Linker_Section_Pragma (Ent, N);
16492
16493 -- Subprograms
16494
16495 when Subprogram_Kind =>
16496
16497 -- Aspect case, entity already set
16498
16499 if From_Aspect_Specification (N) then
16500 Set_Linker_Section_Pragma
16501 (Entity (Corresponding_Aspect (N)), N);
16502
16503 -- Pragma case, we must climb the homonym chain, but skip
16504 -- any for which the linker section is already set.
16505
16506 else
16507 loop
16508 if No (Linker_Section_Pragma (Ent)) then
16509 Set_Linker_Section_Pragma (Ent, N);
16510 end if;
16511
16512 Ent := Homonym (Ent);
16513 exit when No (Ent)
16514 or else Scope (Ent) /= Current_Scope;
16515 end loop;
16516 end if;
16517
16518 -- All other cases are illegal
16519
16520 when others =>
16521 Error_Pragma_Arg
16522 ("pragma% applies only to objects, subprograms, and types",
16523 Arg1);
16524 end case;
16525 end Linker_Section;
16526
16527 ----------
16528 -- List --
16529 ----------
16530
16531 -- pragma List (On | Off)
16532
16533 -- There is nothing to do here, since we did all the processing for
16534 -- this pragma in Par.Prag (so that it works properly even in syntax
16535 -- only mode).
16536
16537 when Pragma_List =>
16538 null;
16539
16540 ---------------
16541 -- Lock_Free --
16542 ---------------
16543
16544 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16545
16546 when Pragma_Lock_Free => Lock_Free : declare
16547 P : constant Node_Id := Parent (N);
16548 Arg : Node_Id;
16549 Ent : Entity_Id;
16550 Val : Boolean;
16551
16552 begin
16553 Check_No_Identifiers;
16554 Check_At_Most_N_Arguments (1);
16555
16556 -- Protected definition case
16557
16558 if Nkind (P) = N_Protected_Definition then
16559 Ent := Defining_Identifier (Parent (P));
16560
16561 -- One argument
16562
16563 if Arg_Count = 1 then
16564 Arg := Get_Pragma_Arg (Arg1);
16565 Val := Is_True (Static_Boolean (Arg));
16566
16567 -- No arguments (expression is considered to be True)
16568
16569 else
16570 Val := True;
16571 end if;
16572
16573 -- Check duplicate pragma before we chain the pragma in the Rep
16574 -- Item chain of Ent.
16575
16576 Check_Duplicate_Pragma (Ent);
16577 Record_Rep_Item (Ent, N);
16578 Set_Uses_Lock_Free (Ent, Val);
16579
16580 -- Anything else is incorrect placement
16581
16582 else
16583 Pragma_Misplaced;
16584 end if;
16585 end Lock_Free;
16586
16587 --------------------
16588 -- Locking_Policy --
16589 --------------------
16590
16591 -- pragma Locking_Policy (policy_IDENTIFIER);
16592
16593 when Pragma_Locking_Policy => declare
16594 subtype LP_Range is Name_Id
16595 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
16596 LP_Val : LP_Range;
16597 LP : Character;
16598
16599 begin
16600 Check_Ada_83_Warning;
16601 Check_Arg_Count (1);
16602 Check_No_Identifiers;
16603 Check_Arg_Is_Locking_Policy (Arg1);
16604 Check_Valid_Configuration_Pragma;
16605 LP_Val := Chars (Get_Pragma_Arg (Arg1));
16606
16607 case LP_Val is
16608 when Name_Ceiling_Locking =>
16609 LP := 'C';
16610 when Name_Inheritance_Locking =>
16611 LP := 'I';
16612 when Name_Concurrent_Readers_Locking =>
16613 LP := 'R';
16614 end case;
16615
16616 if Locking_Policy /= ' '
16617 and then Locking_Policy /= LP
16618 then
16619 Error_Msg_Sloc := Locking_Policy_Sloc;
16620 Error_Pragma ("locking policy incompatible with policy#");
16621
16622 -- Set new policy, but always preserve System_Location since we
16623 -- like the error message with the run time name.
16624
16625 else
16626 Locking_Policy := LP;
16627
16628 if Locking_Policy_Sloc /= System_Location then
16629 Locking_Policy_Sloc := Loc;
16630 end if;
16631 end if;
16632 end;
16633
16634 ----------------
16635 -- Long_Float --
16636 ----------------
16637
16638 -- pragma Long_Float (D_Float | G_Float);
16639
16640 when Pragma_Long_Float => Long_Float : declare
16641 begin
16642 GNAT_Pragma;
16643 Check_Valid_Configuration_Pragma;
16644 Check_Arg_Count (1);
16645 Check_No_Identifier (Arg1);
16646 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
16647
16648 if not OpenVMS_On_Target then
16649 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
16650 end if;
16651
16652 -- D_Float case
16653
16654 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
16655 if Opt.Float_Format_Long = 'G' then
16656 Error_Pragma_Arg
16657 ("G_Float previously specified", Arg1);
16658
16659 elsif Current_Sem_Unit /= Main_Unit
16660 and then Opt.Float_Format_Long /= 'D'
16661 then
16662 Error_Pragma_Arg
16663 ("main unit not compiled with pragma Long_Float (D_Float)",
16664 "\pragma% must be used consistently for whole partition",
16665 Arg1);
16666
16667 else
16668 Opt.Float_Format_Long := 'D';
16669 end if;
16670
16671 -- G_Float case (this is the default, does not need overriding)
16672
16673 else
16674 if Opt.Float_Format_Long = 'D' then
16675 Error_Pragma ("D_Float previously specified");
16676
16677 elsif Current_Sem_Unit /= Main_Unit
16678 and then Opt.Float_Format_Long /= 'G'
16679 then
16680 Error_Pragma_Arg
16681 ("main unit not compiled with pragma Long_Float (G_Float)",
16682 "\pragma% must be used consistently for whole partition",
16683 Arg1);
16684
16685 else
16686 Opt.Float_Format_Long := 'G';
16687 end if;
16688 end if;
16689
16690 Set_Standard_Fpt_Formats;
16691 end Long_Float;
16692
16693 -------------------
16694 -- Loop_Optimize --
16695 -------------------
16696
16697 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16698
16699 -- OPTIMIZATION_HINT ::=
16700 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16701
16702 when Pragma_Loop_Optimize => Loop_Optimize : declare
16703 Hint : Node_Id;
16704
16705 begin
16706 GNAT_Pragma;
16707 Check_At_Least_N_Arguments (1);
16708 Check_No_Identifiers;
16709
16710 Hint := First (Pragma_Argument_Associations (N));
16711 while Present (Hint) loop
16712 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
16713 Name_No_Unroll,
16714 Name_Unroll,
16715 Name_No_Vector,
16716 Name_Vector);
16717 Next (Hint);
16718 end loop;
16719
16720 Check_Loop_Pragma_Placement;
16721 end Loop_Optimize;
16722
16723 ------------------
16724 -- Loop_Variant --
16725 ------------------
16726
16727 -- pragma Loop_Variant
16728 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16729
16730 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16731
16732 -- CHANGE_DIRECTION ::= Increases | Decreases
16733
16734 when Pragma_Loop_Variant => Loop_Variant : declare
16735 Variant : Node_Id;
16736
16737 begin
16738 GNAT_Pragma;
16739 Check_At_Least_N_Arguments (1);
16740 Check_Loop_Pragma_Placement;
16741
16742 -- Process all increasing / decreasing expressions
16743
16744 Variant := First (Pragma_Argument_Associations (N));
16745 while Present (Variant) loop
16746 if not Nam_In (Chars (Variant), Name_Decreases,
16747 Name_Increases)
16748 then
16749 Error_Pragma_Arg ("wrong change modifier", Variant);
16750 end if;
16751
16752 Preanalyze_Assert_Expression
16753 (Expression (Variant), Any_Discrete);
16754
16755 Next (Variant);
16756 end loop;
16757 end Loop_Variant;
16758
16759 -----------------------
16760 -- Machine_Attribute --
16761 -----------------------
16762
16763 -- pragma Machine_Attribute (
16764 -- [Entity =>] LOCAL_NAME,
16765 -- [Attribute_Name =>] static_string_EXPRESSION
16766 -- [, [Info =>] static_EXPRESSION] );
16767
16768 when Pragma_Machine_Attribute => Machine_Attribute : declare
16769 Def_Id : Entity_Id;
16770
16771 begin
16772 GNAT_Pragma;
16773 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
16774
16775 if Arg_Count = 3 then
16776 Check_Optional_Identifier (Arg3, Name_Info);
16777 Check_Arg_Is_OK_Static_Expression (Arg3);
16778 else
16779 Check_Arg_Count (2);
16780 end if;
16781
16782 Check_Optional_Identifier (Arg1, Name_Entity);
16783 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
16784 Check_Arg_Is_Local_Name (Arg1);
16785 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
16786 Def_Id := Entity (Get_Pragma_Arg (Arg1));
16787
16788 if Is_Access_Type (Def_Id) then
16789 Def_Id := Designated_Type (Def_Id);
16790 end if;
16791
16792 if Rep_Item_Too_Early (Def_Id, N) then
16793 return;
16794 end if;
16795
16796 Def_Id := Underlying_Type (Def_Id);
16797
16798 -- The only processing required is to link this item on to the
16799 -- list of rep items for the given entity. This is accomplished
16800 -- by the call to Rep_Item_Too_Late (when no error is detected
16801 -- and False is returned).
16802
16803 if Rep_Item_Too_Late (Def_Id, N) then
16804 return;
16805 else
16806 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16807 end if;
16808 end Machine_Attribute;
16809
16810 ----------
16811 -- Main --
16812 ----------
16813
16814 -- pragma Main
16815 -- (MAIN_OPTION [, MAIN_OPTION]);
16816
16817 -- MAIN_OPTION ::=
16818 -- [STACK_SIZE =>] static_integer_EXPRESSION
16819 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16820 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16821
16822 when Pragma_Main => Main : declare
16823 Args : Args_List (1 .. 3);
16824 Names : constant Name_List (1 .. 3) := (
16825 Name_Stack_Size,
16826 Name_Task_Stack_Size_Default,
16827 Name_Time_Slicing_Enabled);
16828
16829 Nod : Node_Id;
16830
16831 begin
16832 GNAT_Pragma;
16833 Gather_Associations (Names, Args);
16834
16835 for J in 1 .. 2 loop
16836 if Present (Args (J)) then
16837 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16838 end if;
16839 end loop;
16840
16841 if Present (Args (3)) then
16842 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
16843 end if;
16844
16845 Nod := Next (N);
16846 while Present (Nod) loop
16847 if Nkind (Nod) = N_Pragma
16848 and then Pragma_Name (Nod) = Name_Main
16849 then
16850 Error_Msg_Name_1 := Pname;
16851 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16852 end if;
16853
16854 Next (Nod);
16855 end loop;
16856 end Main;
16857
16858 ------------------
16859 -- Main_Storage --
16860 ------------------
16861
16862 -- pragma Main_Storage
16863 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16864
16865 -- MAIN_STORAGE_OPTION ::=
16866 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16867 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
16868
16869 when Pragma_Main_Storage => Main_Storage : declare
16870 Args : Args_List (1 .. 2);
16871 Names : constant Name_List (1 .. 2) := (
16872 Name_Working_Storage,
16873 Name_Top_Guard);
16874
16875 Nod : Node_Id;
16876
16877 begin
16878 GNAT_Pragma;
16879 Gather_Associations (Names, Args);
16880
16881 for J in 1 .. 2 loop
16882 if Present (Args (J)) then
16883 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16884 end if;
16885 end loop;
16886
16887 Check_In_Main_Program;
16888
16889 Nod := Next (N);
16890 while Present (Nod) loop
16891 if Nkind (Nod) = N_Pragma
16892 and then Pragma_Name (Nod) = Name_Main_Storage
16893 then
16894 Error_Msg_Name_1 := Pname;
16895 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16896 end if;
16897
16898 Next (Nod);
16899 end loop;
16900 end Main_Storage;
16901
16902 -----------------
16903 -- Memory_Size --
16904 -----------------
16905
16906 -- pragma Memory_Size (NUMERIC_LITERAL)
16907
16908 when Pragma_Memory_Size =>
16909 GNAT_Pragma;
16910
16911 -- Memory size is simply ignored
16912
16913 Check_No_Identifiers;
16914 Check_Arg_Count (1);
16915 Check_Arg_Is_Integer_Literal (Arg1);
16916
16917 -------------
16918 -- No_Body --
16919 -------------
16920
16921 -- pragma No_Body;
16922
16923 -- The only correct use of this pragma is on its own in a file, in
16924 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
16925 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
16926 -- check for a file containing nothing but a No_Body pragma). If we
16927 -- attempt to process it during normal semantics processing, it means
16928 -- it was misplaced.
16929
16930 when Pragma_No_Body =>
16931 GNAT_Pragma;
16932 Pragma_Misplaced;
16933
16934 ---------------
16935 -- No_Inline --
16936 ---------------
16937
16938 -- pragma No_Inline ( NAME {, NAME} );
16939
16940 when Pragma_No_Inline =>
16941 GNAT_Pragma;
16942 Process_Inline (Suppressed);
16943
16944 ---------------
16945 -- No_Return --
16946 ---------------
16947
16948 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16949
16950 when Pragma_No_Return => No_Return : declare
16951 Id : Node_Id;
16952 E : Entity_Id;
16953 Found : Boolean;
16954 Arg : Node_Id;
16955
16956 begin
16957 Ada_2005_Pragma;
16958 Check_At_Least_N_Arguments (1);
16959
16960 -- Loop through arguments of pragma
16961
16962 Arg := Arg1;
16963 while Present (Arg) loop
16964 Check_Arg_Is_Local_Name (Arg);
16965 Id := Get_Pragma_Arg (Arg);
16966 Analyze (Id);
16967
16968 if not Is_Entity_Name (Id) then
16969 Error_Pragma_Arg ("entity name required", Arg);
16970 end if;
16971
16972 if Etype (Id) = Any_Type then
16973 raise Pragma_Exit;
16974 end if;
16975
16976 -- Loop to find matching procedures
16977
16978 E := Entity (Id);
16979 Found := False;
16980 while Present (E)
16981 and then Scope (E) = Current_Scope
16982 loop
16983 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
16984 Set_No_Return (E);
16985
16986 -- Set flag on any alias as well
16987
16988 if Is_Overloadable (E) and then Present (Alias (E)) then
16989 Set_No_Return (Alias (E));
16990 end if;
16991
16992 Found := True;
16993 end if;
16994
16995 exit when From_Aspect_Specification (N);
16996 E := Homonym (E);
16997 end loop;
16998
16999 -- If entity in not in current scope it may be the enclosing
17000 -- suprogram body to which the aspect applies.
17001
17002 if not Found then
17003 if Entity (Id) = Current_Scope
17004 and then From_Aspect_Specification (N)
17005 then
17006 Set_No_Return (Entity (Id));
17007 else
17008 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
17009 end if;
17010 end if;
17011
17012 Next (Arg);
17013 end loop;
17014 end No_Return;
17015
17016 -----------------
17017 -- No_Run_Time --
17018 -----------------
17019
17020 -- pragma No_Run_Time;
17021
17022 -- Note: this pragma is retained for backwards compatibility. See
17023 -- body of Rtsfind for full details on its handling.
17024
17025 when Pragma_No_Run_Time =>
17026 GNAT_Pragma;
17027 Check_Valid_Configuration_Pragma;
17028 Check_Arg_Count (0);
17029
17030 No_Run_Time_Mode := True;
17031 Configurable_Run_Time_Mode := True;
17032
17033 -- Set Duration to 32 bits if word size is 32
17034
17035 if Ttypes.System_Word_Size = 32 then
17036 Duration_32_Bits_On_Target := True;
17037 end if;
17038
17039 -- Set appropriate restrictions
17040
17041 Set_Restriction (No_Finalization, N);
17042 Set_Restriction (No_Exception_Handlers, N);
17043 Set_Restriction (Max_Tasks, N, 0);
17044 Set_Restriction (No_Tasking, N);
17045
17046 ------------------------
17047 -- No_Strict_Aliasing --
17048 ------------------------
17049
17050 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17051
17052 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
17053 E_Id : Entity_Id;
17054
17055 begin
17056 GNAT_Pragma;
17057 Check_At_Most_N_Arguments (1);
17058
17059 if Arg_Count = 0 then
17060 Check_Valid_Configuration_Pragma;
17061 Opt.No_Strict_Aliasing := True;
17062
17063 else
17064 Check_Optional_Identifier (Arg2, Name_Entity);
17065 Check_Arg_Is_Local_Name (Arg1);
17066 E_Id := Entity (Get_Pragma_Arg (Arg1));
17067
17068 if E_Id = Any_Type then
17069 return;
17070 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
17071 Error_Pragma_Arg ("pragma% requires access type", Arg1);
17072 end if;
17073
17074 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
17075 end if;
17076 end No_Strict_Aliasing;
17077
17078 -----------------------
17079 -- Normalize_Scalars --
17080 -----------------------
17081
17082 -- pragma Normalize_Scalars;
17083
17084 when Pragma_Normalize_Scalars =>
17085 Check_Ada_83_Warning;
17086 Check_Arg_Count (0);
17087 Check_Valid_Configuration_Pragma;
17088
17089 -- Normalize_Scalars creates false positives in CodePeer, and
17090 -- incorrect negative results in GNATprove mode, so ignore this
17091 -- pragma in these modes.
17092
17093 if not (CodePeer_Mode or GNATprove_Mode) then
17094 Normalize_Scalars := True;
17095 Init_Or_Norm_Scalars := True;
17096 end if;
17097
17098 -----------------
17099 -- Obsolescent --
17100 -----------------
17101
17102 -- pragma Obsolescent;
17103
17104 -- pragma Obsolescent (
17105 -- [Message =>] static_string_EXPRESSION
17106 -- [,[Version =>] Ada_05]]);
17107
17108 -- pragma Obsolescent (
17109 -- [Entity =>] NAME
17110 -- [,[Message =>] static_string_EXPRESSION
17111 -- [,[Version =>] Ada_05]] );
17112
17113 when Pragma_Obsolescent => Obsolescent : declare
17114 Ename : Node_Id;
17115 Decl : Node_Id;
17116
17117 procedure Set_Obsolescent (E : Entity_Id);
17118 -- Given an entity Ent, mark it as obsolescent if appropriate
17119
17120 ---------------------
17121 -- Set_Obsolescent --
17122 ---------------------
17123
17124 procedure Set_Obsolescent (E : Entity_Id) is
17125 Active : Boolean;
17126 Ent : Entity_Id;
17127 S : String_Id;
17128
17129 begin
17130 Active := True;
17131 Ent := E;
17132
17133 -- Entity name was given
17134
17135 if Present (Ename) then
17136
17137 -- If entity name matches, we are fine. Save entity in
17138 -- pragma argument, for ASIS use.
17139
17140 if Chars (Ename) = Chars (Ent) then
17141 Set_Entity (Ename, Ent);
17142 Generate_Reference (Ent, Ename);
17143
17144 -- If entity name does not match, only possibility is an
17145 -- enumeration literal from an enumeration type declaration.
17146
17147 elsif Ekind (Ent) /= E_Enumeration_Type then
17148 Error_Pragma
17149 ("pragma % entity name does not match declaration");
17150
17151 else
17152 Ent := First_Literal (E);
17153 loop
17154 if No (Ent) then
17155 Error_Pragma
17156 ("pragma % entity name does not match any "
17157 & "enumeration literal");
17158
17159 elsif Chars (Ent) = Chars (Ename) then
17160 Set_Entity (Ename, Ent);
17161 Generate_Reference (Ent, Ename);
17162 exit;
17163
17164 else
17165 Ent := Next_Literal (Ent);
17166 end if;
17167 end loop;
17168 end if;
17169 end if;
17170
17171 -- Ent points to entity to be marked
17172
17173 if Arg_Count >= 1 then
17174
17175 -- Deal with static string argument
17176
17177 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17178 S := Strval (Get_Pragma_Arg (Arg1));
17179
17180 for J in 1 .. String_Length (S) loop
17181 if not In_Character_Range (Get_String_Char (S, J)) then
17182 Error_Pragma_Arg
17183 ("pragma% argument does not allow wide characters",
17184 Arg1);
17185 end if;
17186 end loop;
17187
17188 Obsolescent_Warnings.Append
17189 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
17190
17191 -- Check for Ada_05 parameter
17192
17193 if Arg_Count /= 1 then
17194 Check_Arg_Count (2);
17195
17196 declare
17197 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
17198
17199 begin
17200 Check_Arg_Is_Identifier (Argx);
17201
17202 if Chars (Argx) /= Name_Ada_05 then
17203 Error_Msg_Name_2 := Name_Ada_05;
17204 Error_Pragma_Arg
17205 ("only allowed argument for pragma% is %", Argx);
17206 end if;
17207
17208 if Ada_Version_Explicit < Ada_2005
17209 or else not Warn_On_Ada_2005_Compatibility
17210 then
17211 Active := False;
17212 end if;
17213 end;
17214 end if;
17215 end if;
17216
17217 -- Set flag if pragma active
17218
17219 if Active then
17220 Set_Is_Obsolescent (Ent);
17221 end if;
17222
17223 return;
17224 end Set_Obsolescent;
17225
17226 -- Start of processing for pragma Obsolescent
17227
17228 begin
17229 GNAT_Pragma;
17230
17231 Check_At_Most_N_Arguments (3);
17232
17233 -- See if first argument specifies an entity name
17234
17235 if Arg_Count >= 1
17236 and then
17237 (Chars (Arg1) = Name_Entity
17238 or else
17239 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
17240 N_Identifier,
17241 N_Operator_Symbol))
17242 then
17243 Ename := Get_Pragma_Arg (Arg1);
17244
17245 -- Eliminate first argument, so we can share processing
17246
17247 Arg1 := Arg2;
17248 Arg2 := Arg3;
17249 Arg_Count := Arg_Count - 1;
17250
17251 -- No Entity name argument given
17252
17253 else
17254 Ename := Empty;
17255 end if;
17256
17257 if Arg_Count >= 1 then
17258 Check_Optional_Identifier (Arg1, Name_Message);
17259
17260 if Arg_Count = 2 then
17261 Check_Optional_Identifier (Arg2, Name_Version);
17262 end if;
17263 end if;
17264
17265 -- Get immediately preceding declaration
17266
17267 Decl := Prev (N);
17268 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17269 Prev (Decl);
17270 end loop;
17271
17272 -- Cases where we do not follow anything other than another pragma
17273
17274 if No (Decl) then
17275
17276 -- First case: library level compilation unit declaration with
17277 -- the pragma immediately following the declaration.
17278
17279 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17280 Set_Obsolescent
17281 (Defining_Entity (Unit (Parent (Parent (N)))));
17282 return;
17283
17284 -- Case 2: library unit placement for package
17285
17286 else
17287 declare
17288 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17289 begin
17290 if Is_Package_Or_Generic_Package (Ent) then
17291 Set_Obsolescent (Ent);
17292 return;
17293 end if;
17294 end;
17295 end if;
17296
17297 -- Cases where we must follow a declaration
17298
17299 else
17300 if Nkind (Decl) not in N_Declaration
17301 and then Nkind (Decl) not in N_Later_Decl_Item
17302 and then Nkind (Decl) not in N_Generic_Declaration
17303 and then Nkind (Decl) not in N_Renaming_Declaration
17304 then
17305 Error_Pragma
17306 ("pragma% misplaced, "
17307 & "must immediately follow a declaration");
17308
17309 else
17310 Set_Obsolescent (Defining_Entity (Decl));
17311 return;
17312 end if;
17313 end if;
17314 end Obsolescent;
17315
17316 --------------
17317 -- Optimize --
17318 --------------
17319
17320 -- pragma Optimize (Time | Space | Off);
17321
17322 -- The actual check for optimize is done in Gigi. Note that this
17323 -- pragma does not actually change the optimization setting, it
17324 -- simply checks that it is consistent with the pragma.
17325
17326 when Pragma_Optimize =>
17327 Check_No_Identifiers;
17328 Check_Arg_Count (1);
17329 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
17330
17331 ------------------------
17332 -- Optimize_Alignment --
17333 ------------------------
17334
17335 -- pragma Optimize_Alignment (Time | Space | Off);
17336
17337 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17338 GNAT_Pragma;
17339 Check_No_Identifiers;
17340 Check_Arg_Count (1);
17341 Check_Valid_Configuration_Pragma;
17342
17343 declare
17344 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17345 begin
17346 case Nam is
17347 when Name_Time =>
17348 Opt.Optimize_Alignment := 'T';
17349 when Name_Space =>
17350 Opt.Optimize_Alignment := 'S';
17351 when Name_Off =>
17352 Opt.Optimize_Alignment := 'O';
17353 when others =>
17354 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
17355 end case;
17356 end;
17357
17358 -- Set indication that mode is set locally. If we are in fact in a
17359 -- configuration pragma file, this setting is harmless since the
17360 -- switch will get reset anyway at the start of each unit.
17361
17362 Optimize_Alignment_Local := True;
17363 end Optimize_Alignment;
17364
17365 -------------
17366 -- Ordered --
17367 -------------
17368
17369 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17370
17371 when Pragma_Ordered => Ordered : declare
17372 Assoc : constant Node_Id := Arg1;
17373 Type_Id : Node_Id;
17374 Typ : Entity_Id;
17375
17376 begin
17377 GNAT_Pragma;
17378 Check_No_Identifiers;
17379 Check_Arg_Count (1);
17380 Check_Arg_Is_Local_Name (Arg1);
17381
17382 Type_Id := Get_Pragma_Arg (Assoc);
17383 Find_Type (Type_Id);
17384 Typ := Entity (Type_Id);
17385
17386 if Typ = Any_Type then
17387 return;
17388 else
17389 Typ := Underlying_Type (Typ);
17390 end if;
17391
17392 if not Is_Enumeration_Type (Typ) then
17393 Error_Pragma ("pragma% must specify enumeration type");
17394 end if;
17395
17396 Check_First_Subtype (Arg1);
17397 Set_Has_Pragma_Ordered (Base_Type (Typ));
17398 end Ordered;
17399
17400 -------------------
17401 -- Overflow_Mode --
17402 -------------------
17403
17404 -- pragma Overflow_Mode
17405 -- ([General => ] MODE [, [Assertions => ] MODE]);
17406
17407 -- MODE := STRICT | MINIMIZED | ELIMINATED
17408
17409 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17410 -- since System.Bignums makes this assumption. This is true of nearly
17411 -- all (all?) targets.
17412
17413 when Pragma_Overflow_Mode => Overflow_Mode : declare
17414 function Get_Overflow_Mode
17415 (Name : Name_Id;
17416 Arg : Node_Id) return Overflow_Mode_Type;
17417 -- Function to process one pragma argument, Arg. If an identifier
17418 -- is present, it must be Name. Mode type is returned if a valid
17419 -- argument exists, otherwise an error is signalled.
17420
17421 -----------------------
17422 -- Get_Overflow_Mode --
17423 -----------------------
17424
17425 function Get_Overflow_Mode
17426 (Name : Name_Id;
17427 Arg : Node_Id) return Overflow_Mode_Type
17428 is
17429 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17430
17431 begin
17432 Check_Optional_Identifier (Arg, Name);
17433 Check_Arg_Is_Identifier (Argx);
17434
17435 if Chars (Argx) = Name_Strict then
17436 return Strict;
17437
17438 elsif Chars (Argx) = Name_Minimized then
17439 return Minimized;
17440
17441 elsif Chars (Argx) = Name_Eliminated then
17442 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
17443 Error_Pragma_Arg
17444 ("Eliminated not implemented on this target", Argx);
17445 else
17446 return Eliminated;
17447 end if;
17448
17449 else
17450 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
17451 end if;
17452 end Get_Overflow_Mode;
17453
17454 -- Start of processing for Overflow_Mode
17455
17456 begin
17457 GNAT_Pragma;
17458 Check_At_Least_N_Arguments (1);
17459 Check_At_Most_N_Arguments (2);
17460
17461 -- Process first argument
17462
17463 Scope_Suppress.Overflow_Mode_General :=
17464 Get_Overflow_Mode (Name_General, Arg1);
17465
17466 -- Case of only one argument
17467
17468 if Arg_Count = 1 then
17469 Scope_Suppress.Overflow_Mode_Assertions :=
17470 Scope_Suppress.Overflow_Mode_General;
17471
17472 -- Case of two arguments present
17473
17474 else
17475 Scope_Suppress.Overflow_Mode_Assertions :=
17476 Get_Overflow_Mode (Name_Assertions, Arg2);
17477 end if;
17478 end Overflow_Mode;
17479
17480 --------------------------
17481 -- Overriding Renamings --
17482 --------------------------
17483
17484 -- pragma Overriding_Renamings;
17485
17486 when Pragma_Overriding_Renamings =>
17487 GNAT_Pragma;
17488 Check_Arg_Count (0);
17489 Check_Valid_Configuration_Pragma;
17490 Overriding_Renamings := True;
17491
17492 ----------
17493 -- Pack --
17494 ----------
17495
17496 -- pragma Pack (first_subtype_LOCAL_NAME);
17497
17498 when Pragma_Pack => Pack : declare
17499 Assoc : constant Node_Id := Arg1;
17500 Type_Id : Node_Id;
17501 Typ : Entity_Id;
17502 Ctyp : Entity_Id;
17503 Ignore : Boolean := False;
17504
17505 begin
17506 Check_No_Identifiers;
17507 Check_Arg_Count (1);
17508 Check_Arg_Is_Local_Name (Arg1);
17509 Type_Id := Get_Pragma_Arg (Assoc);
17510
17511 if not Is_Entity_Name (Type_Id)
17512 or else not Is_Type (Entity (Type_Id))
17513 then
17514 Error_Pragma_Arg
17515 ("argument for pragma% must be type or subtype", Arg1);
17516 end if;
17517
17518 Find_Type (Type_Id);
17519 Typ := Entity (Type_Id);
17520
17521 if Typ = Any_Type
17522 or else Rep_Item_Too_Early (Typ, N)
17523 then
17524 return;
17525 else
17526 Typ := Underlying_Type (Typ);
17527 end if;
17528
17529 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
17530 Error_Pragma ("pragma% must specify array or record type");
17531 end if;
17532
17533 Check_First_Subtype (Arg1);
17534 Check_Duplicate_Pragma (Typ);
17535
17536 -- Array type
17537
17538 if Is_Array_Type (Typ) then
17539 Ctyp := Component_Type (Typ);
17540
17541 -- Ignore pack that does nothing
17542
17543 if Known_Static_Esize (Ctyp)
17544 and then Known_Static_RM_Size (Ctyp)
17545 and then Esize (Ctyp) = RM_Size (Ctyp)
17546 and then Addressable (Esize (Ctyp))
17547 then
17548 Ignore := True;
17549 end if;
17550
17551 -- Process OK pragma Pack. Note that if there is a separate
17552 -- component clause present, the Pack will be cancelled. This
17553 -- processing is in Freeze.
17554
17555 if not Rep_Item_Too_Late (Typ, N) then
17556
17557 -- In CodePeer mode, we do not need complex front-end
17558 -- expansions related to pragma Pack, so disable handling
17559 -- of pragma Pack.
17560
17561 if CodePeer_Mode then
17562 null;
17563
17564 -- Don't attempt any packing for VM targets. We possibly
17565 -- could deal with some cases of array bit-packing, but we
17566 -- don't bother, since this is not a typical kind of
17567 -- representation in the VM context anyway (and would not
17568 -- for example work nicely with the debugger).
17569
17570 elsif VM_Target /= No_VM then
17571 if not GNAT_Mode then
17572 Error_Pragma
17573 ("??pragma% ignored in this configuration");
17574 end if;
17575
17576 -- Normal case where we do the pack action
17577
17578 else
17579 if not Ignore then
17580 Set_Is_Packed (Base_Type (Typ));
17581 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17582 end if;
17583
17584 Set_Has_Pragma_Pack (Base_Type (Typ));
17585 end if;
17586 end if;
17587
17588 -- For record types, the pack is always effective
17589
17590 else pragma Assert (Is_Record_Type (Typ));
17591 if not Rep_Item_Too_Late (Typ, N) then
17592
17593 -- Ignore pack request with warning in VM mode (skip warning
17594 -- if we are compiling GNAT run time library).
17595
17596 if VM_Target /= No_VM then
17597 if not GNAT_Mode then
17598 Error_Pragma
17599 ("??pragma% ignored in this configuration");
17600 end if;
17601
17602 -- Normal case of pack request active
17603
17604 else
17605 Set_Is_Packed (Base_Type (Typ));
17606 Set_Has_Pragma_Pack (Base_Type (Typ));
17607 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17608 end if;
17609 end if;
17610 end if;
17611 end Pack;
17612
17613 ----------
17614 -- Page --
17615 ----------
17616
17617 -- pragma Page;
17618
17619 -- There is nothing to do here, since we did all the processing for
17620 -- this pragma in Par.Prag (so that it works properly even in syntax
17621 -- only mode).
17622
17623 when Pragma_Page =>
17624 null;
17625
17626 -------------
17627 -- Part_Of --
17628 -------------
17629
17630 -- pragma Part_Of (ABSTRACT_STATE);
17631
17632 -- ABSTRACT_STATE ::= NAME
17633
17634 when Pragma_Part_Of => Part_Of : declare
17635 procedure Propagate_Part_Of
17636 (Pack_Id : Entity_Id;
17637 State_Id : Entity_Id;
17638 Instance : Node_Id);
17639 -- Propagate the Part_Of indicator to all abstract states and
17640 -- variables declared in the visible state space of a package
17641 -- denoted by Pack_Id. State_Id is the encapsulating state.
17642 -- Instance is the package instantiation node.
17643
17644 -----------------------
17645 -- Propagate_Part_Of --
17646 -----------------------
17647
17648 procedure Propagate_Part_Of
17649 (Pack_Id : Entity_Id;
17650 State_Id : Entity_Id;
17651 Instance : Node_Id)
17652 is
17653 Has_Item : Boolean := False;
17654 -- Flag set when the visible state space contains at least one
17655 -- abstract state or variable.
17656
17657 procedure Propagate_Part_Of (Pack_Id : Entity_Id);
17658 -- Propagate the Part_Of indicator to all abstract states and
17659 -- variables declared in the visible state space of a package
17660 -- denoted by Pack_Id.
17661
17662 -----------------------
17663 -- Propagate_Part_Of --
17664 -----------------------
17665
17666 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
17667 Item_Id : Entity_Id;
17668
17669 begin
17670 -- Traverse the entity chain of the package and set relevant
17671 -- attributes of abstract states and variables declared in
17672 -- the visible state space of the package.
17673
17674 Item_Id := First_Entity (Pack_Id);
17675 while Present (Item_Id)
17676 and then not In_Private_Part (Item_Id)
17677 loop
17678 -- Do not consider internally generated items
17679
17680 if not Comes_From_Source (Item_Id) then
17681 null;
17682
17683 -- The Part_Of indicator turns an abstract state or
17684 -- variable into a constituent of the encapsulating
17685 -- state.
17686
17687 elsif Ekind_In (Item_Id, E_Abstract_State,
17688 E_Variable)
17689 then
17690 Has_Item := True;
17691
17692 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17693 Set_Encapsulating_State (Item_Id, State_Id);
17694
17695 -- Recursively handle nested packages and instantiations
17696
17697 elsif Ekind (Item_Id) = E_Package then
17698 Propagate_Part_Of (Item_Id);
17699 end if;
17700
17701 Next_Entity (Item_Id);
17702 end loop;
17703 end Propagate_Part_Of;
17704
17705 -- Start of processing for Propagate_Part_Of
17706
17707 begin
17708 Propagate_Part_Of (Pack_Id);
17709
17710 -- Detect a package instantiation that is subject to a Part_Of
17711 -- indicator, but has no visible state.
17712
17713 if not Has_Item then
17714 SPARK_Msg_NE
17715 ("package instantiation & has Part_Of indicator but "
17716 & "lacks visible state", Instance, Pack_Id);
17717 end if;
17718 end Propagate_Part_Of;
17719
17720 -- Local variables
17721
17722 Item_Id : Entity_Id;
17723 Legal : Boolean;
17724 State : Node_Id;
17725 State_Id : Entity_Id;
17726 Stmt : Node_Id;
17727
17728 -- Start of processing for Part_Of
17729
17730 begin
17731 GNAT_Pragma;
17732 Check_Arg_Count (1);
17733
17734 -- Ensure the proper placement of the pragma. Part_Of must appear
17735 -- on a variable declaration or a package instantiation.
17736
17737 Stmt := Prev (N);
17738 while Present (Stmt) loop
17739
17740 -- Skip prior pragmas, but check for duplicates
17741
17742 if Nkind (Stmt) = N_Pragma then
17743 if Pragma_Name (Stmt) = Pname then
17744 Error_Msg_Name_1 := Pname;
17745 Error_Msg_Sloc := Sloc (Stmt);
17746 Error_Msg_N ("pragma% duplicates pragma declared#", N);
17747 end if;
17748
17749 -- Skip internally generated code
17750
17751 elsif not Comes_From_Source (Stmt) then
17752 null;
17753
17754 -- The pragma applies to an object declaration (possibly a
17755 -- variable) or a package instantiation. Stop the traversal
17756 -- and continue the analysis.
17757
17758 elsif Nkind_In (Stmt, N_Object_Declaration,
17759 N_Package_Instantiation)
17760 then
17761 exit;
17762
17763 -- The pragma does not apply to a legal construct, issue an
17764 -- error and stop the analysis.
17765
17766 else
17767 Pragma_Misplaced;
17768 return;
17769 end if;
17770
17771 Stmt := Prev (Stmt);
17772 end loop;
17773
17774 -- When the context is an object declaration, ensure that we are
17775 -- dealing with a variable.
17776
17777 if Nkind (Stmt) = N_Object_Declaration
17778 and then Ekind (Defining_Entity (Stmt)) /= E_Variable
17779 then
17780 SPARK_Msg_N ("indicator Part_Of must apply to a variable", N);
17781 return;
17782 end if;
17783
17784 -- Extract the entity of the related object declaration or package
17785 -- instantiation. In the case of the instantiation, use the entity
17786 -- of the instance spec.
17787
17788 if Nkind (Stmt) = N_Package_Instantiation then
17789 Stmt := Instance_Spec (Stmt);
17790 end if;
17791
17792 Item_Id := Defining_Entity (Stmt);
17793 State := Get_Pragma_Arg (Arg1);
17794
17795 -- Detect any discrepancies between the placement of the object
17796 -- or package instantiation with respect to state space and the
17797 -- encapsulating state.
17798
17799 Analyze_Part_Of
17800 (Item_Id => Item_Id,
17801 State => State,
17802 Indic => N,
17803 Legal => Legal);
17804
17805 if Legal then
17806 State_Id := Entity (State);
17807
17808 -- Add the pragma to the contract of the item. This aids with
17809 -- the detection of a missing but required Part_Of indicator.
17810
17811 Add_Contract_Item (N, Item_Id);
17812
17813 -- The Part_Of indicator turns a variable into a constituent
17814 -- of the encapsulating state.
17815
17816 if Ekind (Item_Id) = E_Variable then
17817 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17818 Set_Encapsulating_State (Item_Id, State_Id);
17819
17820 -- Propagate the Part_Of indicator to the visible state space
17821 -- of the package instantiation.
17822
17823 else
17824 Propagate_Part_Of
17825 (Pack_Id => Item_Id,
17826 State_Id => State_Id,
17827 Instance => Stmt);
17828 end if;
17829 end if;
17830 end Part_Of;
17831
17832 ----------------------------------
17833 -- Partition_Elaboration_Policy --
17834 ----------------------------------
17835
17836 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
17837
17838 when Pragma_Partition_Elaboration_Policy => declare
17839 subtype PEP_Range is Name_Id
17840 range First_Partition_Elaboration_Policy_Name
17841 .. Last_Partition_Elaboration_Policy_Name;
17842 PEP_Val : PEP_Range;
17843 PEP : Character;
17844
17845 begin
17846 Ada_2005_Pragma;
17847 Check_Arg_Count (1);
17848 Check_No_Identifiers;
17849 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
17850 Check_Valid_Configuration_Pragma;
17851 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
17852
17853 case PEP_Val is
17854 when Name_Concurrent =>
17855 PEP := 'C';
17856 when Name_Sequential =>
17857 PEP := 'S';
17858 end case;
17859
17860 if Partition_Elaboration_Policy /= ' '
17861 and then Partition_Elaboration_Policy /= PEP
17862 then
17863 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
17864 Error_Pragma
17865 ("partition elaboration policy incompatible with policy#");
17866
17867 -- Set new policy, but always preserve System_Location since we
17868 -- like the error message with the run time name.
17869
17870 else
17871 Partition_Elaboration_Policy := PEP;
17872
17873 if Partition_Elaboration_Policy_Sloc /= System_Location then
17874 Partition_Elaboration_Policy_Sloc := Loc;
17875 end if;
17876 end if;
17877 end;
17878
17879 -------------
17880 -- Passive --
17881 -------------
17882
17883 -- pragma Passive [(PASSIVE_FORM)];
17884
17885 -- PASSIVE_FORM ::= Semaphore | No
17886
17887 when Pragma_Passive =>
17888 GNAT_Pragma;
17889
17890 if Nkind (Parent (N)) /= N_Task_Definition then
17891 Error_Pragma ("pragma% must be within task definition");
17892 end if;
17893
17894 if Arg_Count /= 0 then
17895 Check_Arg_Count (1);
17896 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
17897 end if;
17898
17899 ----------------------------------
17900 -- Preelaborable_Initialization --
17901 ----------------------------------
17902
17903 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17904
17905 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
17906 Ent : Entity_Id;
17907
17908 begin
17909 Ada_2005_Pragma;
17910 Check_Arg_Count (1);
17911 Check_No_Identifiers;
17912 Check_Arg_Is_Identifier (Arg1);
17913 Check_Arg_Is_Local_Name (Arg1);
17914 Check_First_Subtype (Arg1);
17915 Ent := Entity (Get_Pragma_Arg (Arg1));
17916
17917 -- The pragma may come from an aspect on a private declaration,
17918 -- even if the freeze point at which this is analyzed in the
17919 -- private part after the full view.
17920
17921 if Has_Private_Declaration (Ent)
17922 and then From_Aspect_Specification (N)
17923 then
17924 null;
17925
17926 elsif Is_Private_Type (Ent)
17927 or else Is_Protected_Type (Ent)
17928 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
17929 then
17930 null;
17931
17932 else
17933 Error_Pragma_Arg
17934 ("pragma % can only be applied to private, formal derived or "
17935 & "protected type",
17936 Arg1);
17937 end if;
17938
17939 -- Give an error if the pragma is applied to a protected type that
17940 -- does not qualify (due to having entries, or due to components
17941 -- that do not qualify).
17942
17943 if Is_Protected_Type (Ent)
17944 and then not Has_Preelaborable_Initialization (Ent)
17945 then
17946 Error_Msg_N
17947 ("protected type & does not have preelaborable "
17948 & "initialization", Ent);
17949
17950 -- Otherwise mark the type as definitely having preelaborable
17951 -- initialization.
17952
17953 else
17954 Set_Known_To_Have_Preelab_Init (Ent);
17955 end if;
17956
17957 if Has_Pragma_Preelab_Init (Ent)
17958 and then Warn_On_Redundant_Constructs
17959 then
17960 Error_Pragma ("?r?duplicate pragma%!");
17961 else
17962 Set_Has_Pragma_Preelab_Init (Ent);
17963 end if;
17964 end Preelab_Init;
17965
17966 --------------------
17967 -- Persistent_BSS --
17968 --------------------
17969
17970 -- pragma Persistent_BSS [(object_NAME)];
17971
17972 when Pragma_Persistent_BSS => Persistent_BSS : declare
17973 Decl : Node_Id;
17974 Ent : Entity_Id;
17975 Prag : Node_Id;
17976
17977 begin
17978 GNAT_Pragma;
17979 Check_At_Most_N_Arguments (1);
17980
17981 -- Case of application to specific object (one argument)
17982
17983 if Arg_Count = 1 then
17984 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17985
17986 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
17987 or else not
17988 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
17989 E_Constant)
17990 then
17991 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
17992 end if;
17993
17994 Ent := Entity (Get_Pragma_Arg (Arg1));
17995 Decl := Parent (Ent);
17996
17997 -- Check for duplication before inserting in list of
17998 -- representation items.
17999
18000 Check_Duplicate_Pragma (Ent);
18001
18002 if Rep_Item_Too_Late (Ent, N) then
18003 return;
18004 end if;
18005
18006 if Present (Expression (Decl)) then
18007 Error_Pragma_Arg
18008 ("object for pragma% cannot have initialization", Arg1);
18009 end if;
18010
18011 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
18012 Error_Pragma_Arg
18013 ("object type for pragma% is not potentially persistent",
18014 Arg1);
18015 end if;
18016
18017 Prag :=
18018 Make_Linker_Section_Pragma
18019 (Ent, Sloc (N), ".persistent.bss");
18020 Insert_After (N, Prag);
18021 Analyze (Prag);
18022
18023 -- Case of use as configuration pragma with no arguments
18024
18025 else
18026 Check_Valid_Configuration_Pragma;
18027 Persistent_BSS_Mode := True;
18028 end if;
18029 end Persistent_BSS;
18030
18031 -------------
18032 -- Polling --
18033 -------------
18034
18035 -- pragma Polling (ON | OFF);
18036
18037 when Pragma_Polling =>
18038 GNAT_Pragma;
18039 Check_Arg_Count (1);
18040 Check_No_Identifiers;
18041 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
18042 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
18043
18044 ------------------
18045 -- Post[_Class] --
18046 ------------------
18047
18048 -- pragma Post (Boolean_EXPRESSION);
18049 -- pragma Post_Class (Boolean_EXPRESSION);
18050
18051 when Pragma_Post | Pragma_Post_Class => Post : declare
18052 PC_Pragma : Node_Id;
18053
18054 begin
18055 GNAT_Pragma;
18056 Check_Arg_Count (1);
18057 Check_No_Identifiers;
18058 Check_Pre_Post;
18059
18060 -- Rewrite Post[_Class] pragma as Postcondition pragma setting the
18061 -- flag Class_Present to True for the Post_Class case.
18062
18063 Set_Class_Present (N, Prag_Id = Pragma_Post_Class);
18064 PC_Pragma := New_Copy (N);
18065 Set_Pragma_Identifier
18066 (PC_Pragma, Make_Identifier (Loc, Name_Postcondition));
18067 Rewrite (N, PC_Pragma);
18068 Set_Analyzed (N, False);
18069 Analyze (N);
18070 end Post;
18071
18072 -------------------
18073 -- Postcondition --
18074 -------------------
18075
18076 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18077 -- [,[Message =>] String_EXPRESSION]);
18078
18079 when Pragma_Postcondition => Postcondition : declare
18080 In_Body : Boolean;
18081
18082 begin
18083 GNAT_Pragma;
18084 Check_At_Least_N_Arguments (1);
18085 Check_At_Most_N_Arguments (2);
18086 Check_Optional_Identifier (Arg1, Name_Check);
18087
18088 -- Verify the proper placement of the pragma. The remainder of the
18089 -- processing is found in Sem_Ch6/Sem_Ch7.
18090
18091 Check_Precondition_Postcondition (In_Body);
18092
18093 -- When the pragma is a source construct appearing inside a body,
18094 -- preanalyze the boolean_expression to detect illegal forward
18095 -- references:
18096
18097 -- procedure P is
18098 -- pragma Postcondition (X'Old ...);
18099 -- X : ...
18100
18101 if Comes_From_Source (N) and then In_Body then
18102 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
18103 end if;
18104 end Postcondition;
18105
18106 -----------------
18107 -- Pre[_Class] --
18108 -----------------
18109
18110 -- pragma Pre (Boolean_EXPRESSION);
18111 -- pragma Pre_Class (Boolean_EXPRESSION);
18112
18113 when Pragma_Pre | Pragma_Pre_Class => Pre : declare
18114 PC_Pragma : Node_Id;
18115
18116 begin
18117 GNAT_Pragma;
18118 Check_Arg_Count (1);
18119 Check_No_Identifiers;
18120 Check_Pre_Post;
18121
18122 -- Rewrite Pre[_Class] pragma as Precondition pragma setting the
18123 -- flag Class_Present to True for the Pre_Class case.
18124
18125 Set_Class_Present (N, Prag_Id = Pragma_Pre_Class);
18126 PC_Pragma := New_Copy (N);
18127 Set_Pragma_Identifier
18128 (PC_Pragma, Make_Identifier (Loc, Name_Precondition));
18129 Rewrite (N, PC_Pragma);
18130 Set_Analyzed (N, False);
18131 Analyze (N);
18132 end Pre;
18133
18134 ------------------
18135 -- Precondition --
18136 ------------------
18137
18138 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18139 -- [,[Message =>] String_EXPRESSION]);
18140
18141 when Pragma_Precondition => Precondition : declare
18142 In_Body : Boolean;
18143
18144 begin
18145 GNAT_Pragma;
18146 Check_At_Least_N_Arguments (1);
18147 Check_At_Most_N_Arguments (2);
18148 Check_Optional_Identifier (Arg1, Name_Check);
18149 Check_Precondition_Postcondition (In_Body);
18150
18151 -- If in spec, nothing more to do. If in body, then we convert
18152 -- the pragma to an equivalent pragma Check. That works fine since
18153 -- pragma Check will analyze the condition in the proper context.
18154
18155 -- The form of the pragma Check is either:
18156
18157 -- pragma Check (Precondition, cond [, msg])
18158 -- or
18159 -- pragma Check (Pre, cond [, msg])
18160
18161 -- We use the Pre form if this pragma derived from a Pre aspect.
18162 -- This is needed to make sure that the right set of Policy
18163 -- pragmas are checked.
18164
18165 if In_Body then
18166
18167 -- Rewrite as Check pragma
18168
18169 Rewrite (N,
18170 Make_Pragma (Loc,
18171 Chars => Name_Check,
18172 Pragma_Argument_Associations => New_List (
18173 Make_Pragma_Argument_Association (Loc,
18174 Expression => Make_Identifier (Loc, Pname)),
18175
18176 Make_Pragma_Argument_Association (Sloc (Arg1),
18177 Expression =>
18178 Relocate_Node (Get_Pragma_Arg (Arg1))))));
18179
18180 if Arg_Count = 2 then
18181 Append_To (Pragma_Argument_Associations (N),
18182 Make_Pragma_Argument_Association (Sloc (Arg2),
18183 Expression =>
18184 Relocate_Node (Get_Pragma_Arg (Arg2))));
18185 end if;
18186
18187 Analyze (N);
18188 end if;
18189 end Precondition;
18190
18191 ---------------
18192 -- Predicate --
18193 ---------------
18194
18195 -- pragma Predicate
18196 -- ([Entity =>] type_LOCAL_NAME,
18197 -- [Check =>] boolean_EXPRESSION);
18198
18199 when Pragma_Predicate => Predicate : declare
18200 Type_Id : Node_Id;
18201 Typ : Entity_Id;
18202 Discard : Boolean;
18203
18204 begin
18205 GNAT_Pragma;
18206 Check_Arg_Count (2);
18207 Check_Optional_Identifier (Arg1, Name_Entity);
18208 Check_Optional_Identifier (Arg2, Name_Check);
18209
18210 Check_Arg_Is_Local_Name (Arg1);
18211
18212 Type_Id := Get_Pragma_Arg (Arg1);
18213 Find_Type (Type_Id);
18214 Typ := Entity (Type_Id);
18215
18216 if Typ = Any_Type then
18217 return;
18218 end if;
18219
18220 -- The remaining processing is simply to link the pragma on to
18221 -- the rep item chain, for processing when the type is frozen.
18222 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18223 -- mark the type as having predicates.
18224
18225 Set_Has_Predicates (Typ);
18226 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18227 end Predicate;
18228
18229 ------------------
18230 -- Preelaborate --
18231 ------------------
18232
18233 -- pragma Preelaborate [(library_unit_NAME)];
18234
18235 -- Set the flag Is_Preelaborated of program unit name entity
18236
18237 when Pragma_Preelaborate => Preelaborate : declare
18238 Pa : constant Node_Id := Parent (N);
18239 Pk : constant Node_Kind := Nkind (Pa);
18240 Ent : Entity_Id;
18241
18242 begin
18243 Check_Ada_83_Warning;
18244 Check_Valid_Library_Unit_Pragma;
18245
18246 if Nkind (N) = N_Null_Statement then
18247 return;
18248 end if;
18249
18250 Ent := Find_Lib_Unit_Name;
18251 Check_Duplicate_Pragma (Ent);
18252
18253 -- This filters out pragmas inside generic parents that show up
18254 -- inside instantiations. Pragmas that come from aspects in the
18255 -- unit are not ignored.
18256
18257 if Present (Ent) then
18258 if Pk = N_Package_Specification
18259 and then Present (Generic_Parent (Pa))
18260 and then not From_Aspect_Specification (N)
18261 then
18262 null;
18263
18264 else
18265 if not Debug_Flag_U then
18266 Set_Is_Preelaborated (Ent);
18267 Set_Suppress_Elaboration_Warnings (Ent);
18268 end if;
18269 end if;
18270 end if;
18271 end Preelaborate;
18272
18273 --------------
18274 -- Priority --
18275 --------------
18276
18277 -- pragma Priority (EXPRESSION);
18278
18279 when Pragma_Priority => Priority : declare
18280 P : constant Node_Id := Parent (N);
18281 Arg : Node_Id;
18282 Ent : Entity_Id;
18283
18284 begin
18285 Check_No_Identifiers;
18286 Check_Arg_Count (1);
18287
18288 -- Subprogram case
18289
18290 if Nkind (P) = N_Subprogram_Body then
18291 Check_In_Main_Program;
18292
18293 Ent := Defining_Unit_Name (Specification (P));
18294
18295 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18296 Ent := Defining_Identifier (Ent);
18297 end if;
18298
18299 Arg := Get_Pragma_Arg (Arg1);
18300 Analyze_And_Resolve (Arg, Standard_Integer);
18301
18302 -- Must be static
18303
18304 if not Is_OK_Static_Expression (Arg) then
18305 Flag_Non_Static_Expr
18306 ("main subprogram priority is not static!", Arg);
18307 raise Pragma_Exit;
18308
18309 -- If constraint error, then we already signalled an error
18310
18311 elsif Raises_Constraint_Error (Arg) then
18312 null;
18313
18314 -- Otherwise check in range except if Relaxed_RM_Semantics
18315 -- where we ignore the value if out of range.
18316
18317 else
18318 declare
18319 Val : constant Uint := Expr_Value (Arg);
18320 begin
18321 if not Relaxed_RM_Semantics
18322 and then
18323 (Val < 0
18324 or else Val > Expr_Value (Expression
18325 (Parent (RTE (RE_Max_Priority)))))
18326 then
18327 Error_Pragma_Arg
18328 ("main subprogram priority is out of range", Arg1);
18329 else
18330 Set_Main_Priority
18331 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
18332 end if;
18333 end;
18334 end if;
18335
18336 -- Load an arbitrary entity from System.Tasking.Stages or
18337 -- System.Tasking.Restricted.Stages (depending on the
18338 -- supported profile) to make sure that one of these packages
18339 -- is implicitly with'ed, since we need to have the tasking
18340 -- run time active for the pragma Priority to have any effect.
18341 -- Previously we with'ed the package System.Tasking, but this
18342 -- package does not trigger the required initialization of the
18343 -- run-time library.
18344
18345 declare
18346 Discard : Entity_Id;
18347 pragma Warnings (Off, Discard);
18348 begin
18349 if Restricted_Profile then
18350 Discard := RTE (RE_Activate_Restricted_Tasks);
18351 else
18352 Discard := RTE (RE_Activate_Tasks);
18353 end if;
18354 end;
18355
18356 -- Task or Protected, must be of type Integer
18357
18358 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18359 Arg := Get_Pragma_Arg (Arg1);
18360 Ent := Defining_Identifier (Parent (P));
18361
18362 -- The expression must be analyzed in the special manner
18363 -- described in "Handling of Default and Per-Object
18364 -- Expressions" in sem.ads.
18365
18366 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18367
18368 if not Is_Static_Expression (Arg) then
18369 Check_Restriction (Static_Priorities, Arg);
18370 end if;
18371
18372 -- Anything else is incorrect
18373
18374 else
18375 Pragma_Misplaced;
18376 end if;
18377
18378 -- Check duplicate pragma before we chain the pragma in the Rep
18379 -- Item chain of Ent.
18380
18381 Check_Duplicate_Pragma (Ent);
18382 Record_Rep_Item (Ent, N);
18383 end Priority;
18384
18385 -----------------------------------
18386 -- Priority_Specific_Dispatching --
18387 -----------------------------------
18388
18389 -- pragma Priority_Specific_Dispatching (
18390 -- policy_IDENTIFIER,
18391 -- first_priority_EXPRESSION,
18392 -- last_priority_EXPRESSION);
18393
18394 when Pragma_Priority_Specific_Dispatching =>
18395 Priority_Specific_Dispatching : declare
18396 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
18397 -- This is the entity System.Any_Priority;
18398
18399 DP : Character;
18400 Lower_Bound : Node_Id;
18401 Upper_Bound : Node_Id;
18402 Lower_Val : Uint;
18403 Upper_Val : Uint;
18404
18405 begin
18406 Ada_2005_Pragma;
18407 Check_Arg_Count (3);
18408 Check_No_Identifiers;
18409 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
18410 Check_Valid_Configuration_Pragma;
18411 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18412 DP := Fold_Upper (Name_Buffer (1));
18413
18414 Lower_Bound := Get_Pragma_Arg (Arg2);
18415 Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer);
18416 Lower_Val := Expr_Value (Lower_Bound);
18417
18418 Upper_Bound := Get_Pragma_Arg (Arg3);
18419 Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer);
18420 Upper_Val := Expr_Value (Upper_Bound);
18421
18422 -- It is not allowed to use Task_Dispatching_Policy and
18423 -- Priority_Specific_Dispatching in the same partition.
18424
18425 if Task_Dispatching_Policy /= ' ' then
18426 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18427 Error_Pragma
18428 ("pragma% incompatible with Task_Dispatching_Policy#");
18429
18430 -- Check lower bound in range
18431
18432 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18433 or else
18434 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
18435 then
18436 Error_Pragma_Arg
18437 ("first_priority is out of range", Arg2);
18438
18439 -- Check upper bound in range
18440
18441 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18442 or else
18443 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
18444 then
18445 Error_Pragma_Arg
18446 ("last_priority is out of range", Arg3);
18447
18448 -- Check that the priority range is valid
18449
18450 elsif Lower_Val > Upper_Val then
18451 Error_Pragma
18452 ("last_priority_expression must be greater than or equal to "
18453 & "first_priority_expression");
18454
18455 -- Store the new policy, but always preserve System_Location since
18456 -- we like the error message with the run-time name.
18457
18458 else
18459 -- Check overlapping in the priority ranges specified in other
18460 -- Priority_Specific_Dispatching pragmas within the same
18461 -- partition. We can only check those we know about.
18462
18463 for J in
18464 Specific_Dispatching.First .. Specific_Dispatching.Last
18465 loop
18466 if Specific_Dispatching.Table (J).First_Priority in
18467 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18468 or else Specific_Dispatching.Table (J).Last_Priority in
18469 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
18470 then
18471 Error_Msg_Sloc :=
18472 Specific_Dispatching.Table (J).Pragma_Loc;
18473 Error_Pragma
18474 ("priority range overlaps with "
18475 & "Priority_Specific_Dispatching#");
18476 end if;
18477 end loop;
18478
18479 -- The use of Priority_Specific_Dispatching is incompatible
18480 -- with Task_Dispatching_Policy.
18481
18482 if Task_Dispatching_Policy /= ' ' then
18483 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18484 Error_Pragma
18485 ("Priority_Specific_Dispatching incompatible "
18486 & "with Task_Dispatching_Policy#");
18487 end if;
18488
18489 -- The use of Priority_Specific_Dispatching forces ceiling
18490 -- locking policy.
18491
18492 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
18493 Error_Msg_Sloc := Locking_Policy_Sloc;
18494 Error_Pragma
18495 ("Priority_Specific_Dispatching incompatible "
18496 & "with Locking_Policy#");
18497
18498 -- Set the Ceiling_Locking policy, but preserve System_Location
18499 -- since we like the error message with the run time name.
18500
18501 else
18502 Locking_Policy := 'C';
18503
18504 if Locking_Policy_Sloc /= System_Location then
18505 Locking_Policy_Sloc := Loc;
18506 end if;
18507 end if;
18508
18509 -- Add entry in the table
18510
18511 Specific_Dispatching.Append
18512 ((Dispatching_Policy => DP,
18513 First_Priority => UI_To_Int (Lower_Val),
18514 Last_Priority => UI_To_Int (Upper_Val),
18515 Pragma_Loc => Loc));
18516 end if;
18517 end Priority_Specific_Dispatching;
18518
18519 -------------
18520 -- Profile --
18521 -------------
18522
18523 -- pragma Profile (profile_IDENTIFIER);
18524
18525 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18526
18527 when Pragma_Profile =>
18528 Ada_2005_Pragma;
18529 Check_Arg_Count (1);
18530 Check_Valid_Configuration_Pragma;
18531 Check_No_Identifiers;
18532
18533 declare
18534 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18535
18536 begin
18537 if Chars (Argx) = Name_Ravenscar then
18538 Set_Ravenscar_Profile (N);
18539
18540 elsif Chars (Argx) = Name_Restricted then
18541 Set_Profile_Restrictions
18542 (Restricted,
18543 N, Warn => Treat_Restrictions_As_Warnings);
18544
18545 elsif Chars (Argx) = Name_Rational then
18546 Set_Rational_Profile;
18547
18548 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18549 Set_Profile_Restrictions
18550 (No_Implementation_Extensions,
18551 N, Warn => Treat_Restrictions_As_Warnings);
18552
18553 else
18554 Error_Pragma_Arg ("& is not a valid profile", Argx);
18555 end if;
18556 end;
18557
18558 ----------------------
18559 -- Profile_Warnings --
18560 ----------------------
18561
18562 -- pragma Profile_Warnings (profile_IDENTIFIER);
18563
18564 -- profile_IDENTIFIER => Restricted | Ravenscar
18565
18566 when Pragma_Profile_Warnings =>
18567 GNAT_Pragma;
18568 Check_Arg_Count (1);
18569 Check_Valid_Configuration_Pragma;
18570 Check_No_Identifiers;
18571
18572 declare
18573 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18574
18575 begin
18576 if Chars (Argx) = Name_Ravenscar then
18577 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
18578
18579 elsif Chars (Argx) = Name_Restricted then
18580 Set_Profile_Restrictions (Restricted, N, Warn => True);
18581
18582 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18583 Set_Profile_Restrictions
18584 (No_Implementation_Extensions, N, Warn => True);
18585
18586 else
18587 Error_Pragma_Arg ("& is not a valid profile", Argx);
18588 end if;
18589 end;
18590
18591 --------------------------
18592 -- Propagate_Exceptions --
18593 --------------------------
18594
18595 -- pragma Propagate_Exceptions;
18596
18597 -- Note: this pragma is obsolete and has no effect
18598
18599 when Pragma_Propagate_Exceptions =>
18600 GNAT_Pragma;
18601 Check_Arg_Count (0);
18602
18603 if Warn_On_Obsolescent_Feature then
18604 Error_Msg_N
18605 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18606 "and has no effect?j?", N);
18607 end if;
18608
18609 -----------------------------
18610 -- Provide_Shift_Operators --
18611 -----------------------------
18612
18613 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18614
18615 when Pragma_Provide_Shift_Operators =>
18616 Provide_Shift_Operators : declare
18617 Ent : Entity_Id;
18618
18619 procedure Declare_Shift_Operator (Nam : Name_Id);
18620 -- Insert declaration and pragma Instrinsic for named shift op
18621
18622 ----------------------------
18623 -- Declare_Shift_Operator --
18624 ----------------------------
18625
18626 procedure Declare_Shift_Operator (Nam : Name_Id) is
18627 Func : Node_Id;
18628 Import : Node_Id;
18629
18630 begin
18631 Func :=
18632 Make_Subprogram_Declaration (Loc,
18633 Make_Function_Specification (Loc,
18634 Defining_Unit_Name =>
18635 Make_Defining_Identifier (Loc, Chars => Nam),
18636
18637 Result_Definition =>
18638 Make_Identifier (Loc, Chars => Chars (Ent)),
18639
18640 Parameter_Specifications => New_List (
18641 Make_Parameter_Specification (Loc,
18642 Defining_Identifier =>
18643 Make_Defining_Identifier (Loc, Name_Value),
18644 Parameter_Type =>
18645 Make_Identifier (Loc, Chars => Chars (Ent))),
18646
18647 Make_Parameter_Specification (Loc,
18648 Defining_Identifier =>
18649 Make_Defining_Identifier (Loc, Name_Amount),
18650 Parameter_Type =>
18651 New_Occurrence_Of (Standard_Natural, Loc)))));
18652
18653 Import :=
18654 Make_Pragma (Loc,
18655 Pragma_Identifier => Make_Identifier (Loc, Name_Import),
18656 Pragma_Argument_Associations => New_List (
18657 Make_Pragma_Argument_Association (Loc,
18658 Expression => Make_Identifier (Loc, Name_Intrinsic)),
18659 Make_Pragma_Argument_Association (Loc,
18660 Expression => Make_Identifier (Loc, Nam))));
18661
18662 Insert_After (N, Import);
18663 Insert_After (N, Func);
18664 end Declare_Shift_Operator;
18665
18666 -- Start of processing for Provide_Shift_Operators
18667
18668 begin
18669 GNAT_Pragma;
18670 Check_Arg_Count (1);
18671 Check_Arg_Is_Local_Name (Arg1);
18672
18673 Arg1 := Get_Pragma_Arg (Arg1);
18674
18675 -- We must have an entity name
18676
18677 if not Is_Entity_Name (Arg1) then
18678 Error_Pragma_Arg
18679 ("pragma % must apply to integer first subtype", Arg1);
18680 end if;
18681
18682 -- If no Entity, means there was a prior error so ignore
18683
18684 if Present (Entity (Arg1)) then
18685 Ent := Entity (Arg1);
18686
18687 -- Apply error checks
18688
18689 if not Is_First_Subtype (Ent) then
18690 Error_Pragma_Arg
18691 ("cannot apply pragma %",
18692 "\& is not a first subtype",
18693 Arg1);
18694
18695 elsif not Is_Integer_Type (Ent) then
18696 Error_Pragma_Arg
18697 ("cannot apply pragma %",
18698 "\& is not an integer type",
18699 Arg1);
18700
18701 elsif Has_Shift_Operator (Ent) then
18702 Error_Pragma_Arg
18703 ("cannot apply pragma %",
18704 "\& already has declared shift operators",
18705 Arg1);
18706
18707 elsif Is_Frozen (Ent) then
18708 Error_Pragma_Arg
18709 ("pragma % appears too late",
18710 "\& is already frozen",
18711 Arg1);
18712 end if;
18713
18714 -- Now declare the operators. We do this during analysis rather
18715 -- than expansion, since we want the operators available if we
18716 -- are operating in -gnatc or ASIS mode.
18717
18718 Declare_Shift_Operator (Name_Rotate_Left);
18719 Declare_Shift_Operator (Name_Rotate_Right);
18720 Declare_Shift_Operator (Name_Shift_Left);
18721 Declare_Shift_Operator (Name_Shift_Right);
18722 Declare_Shift_Operator (Name_Shift_Right_Arithmetic);
18723 end if;
18724 end Provide_Shift_Operators;
18725
18726 ------------------
18727 -- Psect_Object --
18728 ------------------
18729
18730 -- pragma Psect_Object (
18731 -- [Internal =>] LOCAL_NAME,
18732 -- [, [External =>] EXTERNAL_SYMBOL]
18733 -- [, [Size =>] EXTERNAL_SYMBOL]);
18734
18735 when Pragma_Psect_Object | Pragma_Common_Object =>
18736 Psect_Object : declare
18737 Args : Args_List (1 .. 3);
18738 Names : constant Name_List (1 .. 3) := (
18739 Name_Internal,
18740 Name_External,
18741 Name_Size);
18742
18743 Internal : Node_Id renames Args (1);
18744 External : Node_Id renames Args (2);
18745 Size : Node_Id renames Args (3);
18746
18747 Def_Id : Entity_Id;
18748
18749 procedure Check_Too_Long (Arg : Node_Id);
18750 -- Posts message if the argument is an identifier with more
18751 -- than 31 characters, or a string literal with more than
18752 -- 31 characters, and we are operating under VMS
18753
18754 --------------------
18755 -- Check_Too_Long --
18756 --------------------
18757
18758 procedure Check_Too_Long (Arg : Node_Id) is
18759 X : constant Node_Id := Original_Node (Arg);
18760
18761 begin
18762 if not Nkind_In (X, N_String_Literal, N_Identifier) then
18763 Error_Pragma_Arg
18764 ("inappropriate argument for pragma %", Arg);
18765 end if;
18766
18767 if OpenVMS_On_Target then
18768 if (Nkind (X) = N_String_Literal
18769 and then String_Length (Strval (X)) > 31)
18770 or else
18771 (Nkind (X) = N_Identifier
18772 and then Length_Of_Name (Chars (X)) > 31)
18773 then
18774 Error_Pragma_Arg
18775 ("argument for pragma % is longer than 31 characters",
18776 Arg);
18777 end if;
18778 end if;
18779 end Check_Too_Long;
18780
18781 -- Start of processing for Common_Object/Psect_Object
18782
18783 begin
18784 GNAT_Pragma;
18785 Gather_Associations (Names, Args);
18786 Process_Extended_Import_Export_Internal_Arg (Internal);
18787
18788 Def_Id := Entity (Internal);
18789
18790 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
18791 Error_Pragma_Arg
18792 ("pragma% must designate an object", Internal);
18793 end if;
18794
18795 Check_Too_Long (Internal);
18796
18797 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
18798 Error_Pragma_Arg
18799 ("cannot use pragma% for imported/exported object",
18800 Internal);
18801 end if;
18802
18803 if Is_Concurrent_Type (Etype (Internal)) then
18804 Error_Pragma_Arg
18805 ("cannot specify pragma % for task/protected object",
18806 Internal);
18807 end if;
18808
18809 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
18810 or else
18811 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
18812 then
18813 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
18814 end if;
18815
18816 if Ekind (Def_Id) = E_Constant then
18817 Error_Pragma_Arg
18818 ("cannot specify pragma % for a constant", Internal);
18819 end if;
18820
18821 if Is_Record_Type (Etype (Internal)) then
18822 declare
18823 Ent : Entity_Id;
18824 Decl : Entity_Id;
18825
18826 begin
18827 Ent := First_Entity (Etype (Internal));
18828 while Present (Ent) loop
18829 Decl := Declaration_Node (Ent);
18830
18831 if Ekind (Ent) = E_Component
18832 and then Nkind (Decl) = N_Component_Declaration
18833 and then Present (Expression (Decl))
18834 and then Warn_On_Export_Import
18835 then
18836 Error_Msg_N
18837 ("?x?object for pragma % has defaults", Internal);
18838 exit;
18839
18840 else
18841 Next_Entity (Ent);
18842 end if;
18843 end loop;
18844 end;
18845 end if;
18846
18847 if Present (Size) then
18848 Check_Too_Long (Size);
18849 end if;
18850
18851 if Present (External) then
18852 Check_Arg_Is_External_Name (External);
18853 Check_Too_Long (External);
18854 end if;
18855
18856 -- If all error tests pass, link pragma on to the rep item chain
18857
18858 Record_Rep_Item (Def_Id, N);
18859 end Psect_Object;
18860
18861 ----------
18862 -- Pure --
18863 ----------
18864
18865 -- pragma Pure [(library_unit_NAME)];
18866
18867 when Pragma_Pure => Pure : declare
18868 Ent : Entity_Id;
18869
18870 begin
18871 Check_Ada_83_Warning;
18872 Check_Valid_Library_Unit_Pragma;
18873
18874 if Nkind (N) = N_Null_Statement then
18875 return;
18876 end if;
18877
18878 Ent := Find_Lib_Unit_Name;
18879 Set_Is_Pure (Ent);
18880 Set_Has_Pragma_Pure (Ent);
18881 Set_Suppress_Elaboration_Warnings (Ent);
18882 end Pure;
18883
18884 -------------------
18885 -- Pure_Function --
18886 -------------------
18887
18888 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18889
18890 when Pragma_Pure_Function => Pure_Function : declare
18891 E_Id : Node_Id;
18892 E : Entity_Id;
18893 Def_Id : Entity_Id;
18894 Effective : Boolean := False;
18895
18896 begin
18897 GNAT_Pragma;
18898 Check_Arg_Count (1);
18899 Check_Optional_Identifier (Arg1, Name_Entity);
18900 Check_Arg_Is_Local_Name (Arg1);
18901 E_Id := Get_Pragma_Arg (Arg1);
18902
18903 if Error_Posted (E_Id) then
18904 return;
18905 end if;
18906
18907 -- Loop through homonyms (overloadings) of referenced entity
18908
18909 E := Entity (E_Id);
18910
18911 if Present (E) then
18912 loop
18913 Def_Id := Get_Base_Subprogram (E);
18914
18915 if not Ekind_In (Def_Id, E_Function,
18916 E_Generic_Function,
18917 E_Operator)
18918 then
18919 Error_Pragma_Arg
18920 ("pragma% requires a function name", Arg1);
18921 end if;
18922
18923 Set_Is_Pure (Def_Id);
18924
18925 if not Has_Pragma_Pure_Function (Def_Id) then
18926 Set_Has_Pragma_Pure_Function (Def_Id);
18927 Effective := True;
18928 end if;
18929
18930 exit when From_Aspect_Specification (N);
18931 E := Homonym (E);
18932 exit when No (E) or else Scope (E) /= Current_Scope;
18933 end loop;
18934
18935 if not Effective
18936 and then Warn_On_Redundant_Constructs
18937 then
18938 Error_Msg_NE
18939 ("pragma Pure_Function on& is redundant?r?",
18940 N, Entity (E_Id));
18941 end if;
18942 end if;
18943 end Pure_Function;
18944
18945 --------------------
18946 -- Queuing_Policy --
18947 --------------------
18948
18949 -- pragma Queuing_Policy (policy_IDENTIFIER);
18950
18951 when Pragma_Queuing_Policy => declare
18952 QP : Character;
18953
18954 begin
18955 Check_Ada_83_Warning;
18956 Check_Arg_Count (1);
18957 Check_No_Identifiers;
18958 Check_Arg_Is_Queuing_Policy (Arg1);
18959 Check_Valid_Configuration_Pragma;
18960 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
18961 QP := Fold_Upper (Name_Buffer (1));
18962
18963 if Queuing_Policy /= ' '
18964 and then Queuing_Policy /= QP
18965 then
18966 Error_Msg_Sloc := Queuing_Policy_Sloc;
18967 Error_Pragma ("queuing policy incompatible with policy#");
18968
18969 -- Set new policy, but always preserve System_Location since we
18970 -- like the error message with the run time name.
18971
18972 else
18973 Queuing_Policy := QP;
18974
18975 if Queuing_Policy_Sloc /= System_Location then
18976 Queuing_Policy_Sloc := Loc;
18977 end if;
18978 end if;
18979 end;
18980
18981 --------------
18982 -- Rational --
18983 --------------
18984
18985 -- pragma Rational, for compatibility with foreign compiler
18986
18987 when Pragma_Rational =>
18988 Set_Rational_Profile;
18989
18990 ------------------------------------
18991 -- Refined_Depends/Refined_Global --
18992 ------------------------------------
18993
18994 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18995
18996 -- DEPENDENCY_RELATION ::=
18997 -- null
18998 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
18999
19000 -- DEPENDENCY_CLAUSE ::=
19001 -- OUTPUT_LIST =>[+] INPUT_LIST
19002 -- | NULL_DEPENDENCY_CLAUSE
19003
19004 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19005
19006 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19007
19008 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19009
19010 -- OUTPUT ::= NAME | FUNCTION_RESULT
19011 -- INPUT ::= NAME
19012
19013 -- where FUNCTION_RESULT is a function Result attribute_reference
19014
19015 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19016
19017 -- GLOBAL_SPECIFICATION ::=
19018 -- null
19019 -- | GLOBAL_LIST
19020 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
19021
19022 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19023
19024 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19025 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19026 -- GLOBAL_ITEM ::= NAME
19027
19028 when Pragma_Refined_Depends |
19029 Pragma_Refined_Global => Refined_Depends_Global :
19030 declare
19031 Body_Id : Entity_Id;
19032 Legal : Boolean;
19033 Spec_Id : Entity_Id;
19034
19035 begin
19036 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
19037
19038 -- Save the pragma in the contract of the subprogram body. The
19039 -- remaining analysis is performed at the end of the enclosing
19040 -- declarations.
19041
19042 if Legal then
19043 Add_Contract_Item (N, Body_Id);
19044 end if;
19045 end Refined_Depends_Global;
19046
19047 ------------------
19048 -- Refined_Post --
19049 ------------------
19050
19051 -- pragma Refined_Post (boolean_EXPRESSION);
19052
19053 when Pragma_Refined_Post => Refined_Post : declare
19054 Body_Id : Entity_Id;
19055 Legal : Boolean;
19056 Result_Seen : Boolean := False;
19057 Spec_Id : Entity_Id;
19058
19059 begin
19060 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
19061
19062 -- Analyze the boolean expression as a "spec expression"
19063
19064 if Legal then
19065 Analyze_Pre_Post_Condition_In_Decl_Part (N, Spec_Id);
19066
19067 -- Verify that the refined postcondition mentions attribute
19068 -- 'Result and its expression introduces a post-state.
19069
19070 if Warn_On_Suspicious_Contract
19071 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
19072 then
19073 Check_Result_And_Post_State (N, Result_Seen);
19074
19075 if not Result_Seen then
19076 Error_Pragma
19077 ("pragma % does not mention function result?T?");
19078 end if;
19079 end if;
19080
19081 -- Chain the pragma on the contract for easy retrieval
19082
19083 Add_Contract_Item (N, Body_Id);
19084 end if;
19085 end Refined_Post;
19086
19087 -------------------
19088 -- Refined_State --
19089 -------------------
19090
19091 -- pragma Refined_State (REFINEMENT_LIST);
19092
19093 -- REFINEMENT_LIST ::=
19094 -- REFINEMENT_CLAUSE
19095 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19096
19097 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19098
19099 -- CONSTITUENT_LIST ::=
19100 -- null
19101 -- | CONSTITUENT
19102 -- | (CONSTITUENT {, CONSTITUENT})
19103
19104 -- CONSTITUENT ::= object_NAME | state_NAME
19105
19106 when Pragma_Refined_State => Refined_State : declare
19107 Context : constant Node_Id := Parent (N);
19108 Spec_Id : Entity_Id;
19109 Stmt : Node_Id;
19110
19111 begin
19112 GNAT_Pragma;
19113 Check_Arg_Count (1);
19114
19115 -- Ensure the proper placement of the pragma. Refined states must
19116 -- be associated with a package body.
19117
19118 if Nkind (Context) /= N_Package_Body then
19119 Pragma_Misplaced;
19120 return;
19121 end if;
19122
19123 Stmt := Prev (N);
19124 while Present (Stmt) loop
19125
19126 -- Skip prior pragmas, but check for duplicates
19127
19128 if Nkind (Stmt) = N_Pragma then
19129 if Pragma_Name (Stmt) = Pname then
19130 Error_Msg_Name_1 := Pname;
19131 Error_Msg_Sloc := Sloc (Stmt);
19132 Error_Msg_N ("pragma % duplicates pragma declared #", N);
19133 end if;
19134
19135 -- Skip internally generated code
19136
19137 elsif not Comes_From_Source (Stmt) then
19138 null;
19139
19140 -- The pragma does not apply to a legal construct, issue an
19141 -- error and stop the analysis.
19142
19143 else
19144 Pragma_Misplaced;
19145 return;
19146 end if;
19147
19148 Stmt := Prev (Stmt);
19149 end loop;
19150
19151 Spec_Id := Corresponding_Spec (Context);
19152
19153 -- State refinement is allowed only when the corresponding package
19154 -- declaration has non-null pragma Abstract_State. Refinement not
19155 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19156
19157 if SPARK_Mode /= Off
19158 and then
19159 (No (Abstract_States (Spec_Id))
19160 or else Has_Null_Abstract_State (Spec_Id))
19161 then
19162 Error_Msg_NE
19163 ("useless refinement, package & does not define abstract "
19164 & "states", N, Spec_Id);
19165 return;
19166 end if;
19167
19168 -- The pragma must be analyzed at the end of the declarations as
19169 -- it has visibility over the whole declarative region. Save the
19170 -- pragma for later (see Analyze_Refined_Depends_In_Decl_Part) by
19171 -- adding it to the contract of the package body.
19172
19173 Add_Contract_Item (N, Defining_Entity (Context));
19174 end Refined_State;
19175
19176 -----------------------
19177 -- Relative_Deadline --
19178 -----------------------
19179
19180 -- pragma Relative_Deadline (time_span_EXPRESSION);
19181
19182 when Pragma_Relative_Deadline => Relative_Deadline : declare
19183 P : constant Node_Id := Parent (N);
19184 Arg : Node_Id;
19185
19186 begin
19187 Ada_2005_Pragma;
19188 Check_No_Identifiers;
19189 Check_Arg_Count (1);
19190
19191 Arg := Get_Pragma_Arg (Arg1);
19192
19193 -- The expression must be analyzed in the special manner described
19194 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19195
19196 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
19197
19198 -- Subprogram case
19199
19200 if Nkind (P) = N_Subprogram_Body then
19201 Check_In_Main_Program;
19202
19203 -- Only Task and subprogram cases allowed
19204
19205 elsif Nkind (P) /= N_Task_Definition then
19206 Pragma_Misplaced;
19207 end if;
19208
19209 -- Check duplicate pragma before we set the corresponding flag
19210
19211 if Has_Relative_Deadline_Pragma (P) then
19212 Error_Pragma ("duplicate pragma% not allowed");
19213 end if;
19214
19215 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19216 -- Relative_Deadline pragma node cannot be inserted in the Rep
19217 -- Item chain of Ent since it is rewritten by the expander as a
19218 -- procedure call statement that will break the chain.
19219
19220 Set_Has_Relative_Deadline_Pragma (P, True);
19221 end Relative_Deadline;
19222
19223 ------------------------
19224 -- Remote_Access_Type --
19225 ------------------------
19226
19227 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19228
19229 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
19230 E : Entity_Id;
19231
19232 begin
19233 GNAT_Pragma;
19234 Check_Arg_Count (1);
19235 Check_Optional_Identifier (Arg1, Name_Entity);
19236 Check_Arg_Is_Local_Name (Arg1);
19237
19238 E := Entity (Get_Pragma_Arg (Arg1));
19239
19240 if Nkind (Parent (E)) = N_Formal_Type_Declaration
19241 and then Ekind (E) = E_General_Access_Type
19242 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
19243 and then Scope (Root_Type (Directly_Designated_Type (E)))
19244 = Scope (E)
19245 and then Is_Valid_Remote_Object_Type
19246 (Root_Type (Directly_Designated_Type (E)))
19247 then
19248 Set_Is_Remote_Types (E);
19249
19250 else
19251 Error_Pragma_Arg
19252 ("pragma% applies only to formal access to classwide types",
19253 Arg1);
19254 end if;
19255 end Remote_Access_Type;
19256
19257 ---------------------------
19258 -- Remote_Call_Interface --
19259 ---------------------------
19260
19261 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19262
19263 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
19264 Cunit_Node : Node_Id;
19265 Cunit_Ent : Entity_Id;
19266 K : Node_Kind;
19267
19268 begin
19269 Check_Ada_83_Warning;
19270 Check_Valid_Library_Unit_Pragma;
19271
19272 if Nkind (N) = N_Null_Statement then
19273 return;
19274 end if;
19275
19276 Cunit_Node := Cunit (Current_Sem_Unit);
19277 K := Nkind (Unit (Cunit_Node));
19278 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19279
19280 if K = N_Package_Declaration
19281 or else K = N_Generic_Package_Declaration
19282 or else K = N_Subprogram_Declaration
19283 or else K = N_Generic_Subprogram_Declaration
19284 or else (K = N_Subprogram_Body
19285 and then Acts_As_Spec (Unit (Cunit_Node)))
19286 then
19287 null;
19288 else
19289 Error_Pragma (
19290 "pragma% must apply to package or subprogram declaration");
19291 end if;
19292
19293 Set_Is_Remote_Call_Interface (Cunit_Ent);
19294 end Remote_Call_Interface;
19295
19296 ------------------
19297 -- Remote_Types --
19298 ------------------
19299
19300 -- pragma Remote_Types [(library_unit_NAME)];
19301
19302 when Pragma_Remote_Types => Remote_Types : declare
19303 Cunit_Node : Node_Id;
19304 Cunit_Ent : Entity_Id;
19305
19306 begin
19307 Check_Ada_83_Warning;
19308 Check_Valid_Library_Unit_Pragma;
19309
19310 if Nkind (N) = N_Null_Statement then
19311 return;
19312 end if;
19313
19314 Cunit_Node := Cunit (Current_Sem_Unit);
19315 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19316
19317 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19318 N_Generic_Package_Declaration)
19319 then
19320 Error_Pragma
19321 ("pragma% can only apply to a package declaration");
19322 end if;
19323
19324 Set_Is_Remote_Types (Cunit_Ent);
19325 end Remote_Types;
19326
19327 ---------------
19328 -- Ravenscar --
19329 ---------------
19330
19331 -- pragma Ravenscar;
19332
19333 when Pragma_Ravenscar =>
19334 GNAT_Pragma;
19335 Check_Arg_Count (0);
19336 Check_Valid_Configuration_Pragma;
19337 Set_Ravenscar_Profile (N);
19338
19339 if Warn_On_Obsolescent_Feature then
19340 Error_Msg_N
19341 ("pragma Ravenscar is an obsolescent feature?j?", N);
19342 Error_Msg_N
19343 ("|use pragma Profile (Ravenscar) instead?j?", N);
19344 end if;
19345
19346 -------------------------
19347 -- Restricted_Run_Time --
19348 -------------------------
19349
19350 -- pragma Restricted_Run_Time;
19351
19352 when Pragma_Restricted_Run_Time =>
19353 GNAT_Pragma;
19354 Check_Arg_Count (0);
19355 Check_Valid_Configuration_Pragma;
19356 Set_Profile_Restrictions
19357 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
19358
19359 if Warn_On_Obsolescent_Feature then
19360 Error_Msg_N
19361 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
19362 N);
19363 Error_Msg_N
19364 ("|use pragma Profile (Restricted) instead?j?", N);
19365 end if;
19366
19367 ------------------
19368 -- Restrictions --
19369 ------------------
19370
19371 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
19372
19373 -- RESTRICTION ::=
19374 -- restriction_IDENTIFIER
19375 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19376
19377 when Pragma_Restrictions =>
19378 Process_Restrictions_Or_Restriction_Warnings
19379 (Warn => Treat_Restrictions_As_Warnings);
19380
19381 --------------------------
19382 -- Restriction_Warnings --
19383 --------------------------
19384
19385 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
19386
19387 -- RESTRICTION ::=
19388 -- restriction_IDENTIFIER
19389 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19390
19391 when Pragma_Restriction_Warnings =>
19392 GNAT_Pragma;
19393 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
19394
19395 ----------------
19396 -- Reviewable --
19397 ----------------
19398
19399 -- pragma Reviewable;
19400
19401 when Pragma_Reviewable =>
19402 Check_Ada_83_Warning;
19403 Check_Arg_Count (0);
19404
19405 -- Call dummy debugging function rv. This is done to assist front
19406 -- end debugging. By placing a Reviewable pragma in the source
19407 -- program, a breakpoint on rv catches this place in the source,
19408 -- allowing convenient stepping to the point of interest.
19409
19410 rv;
19411
19412 --------------------------
19413 -- Short_Circuit_And_Or --
19414 --------------------------
19415
19416 -- pragma Short_Circuit_And_Or;
19417
19418 when Pragma_Short_Circuit_And_Or =>
19419 GNAT_Pragma;
19420 Check_Arg_Count (0);
19421 Check_Valid_Configuration_Pragma;
19422 Short_Circuit_And_Or := True;
19423
19424 -------------------
19425 -- Share_Generic --
19426 -------------------
19427
19428 -- pragma Share_Generic (GNAME {, GNAME});
19429
19430 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
19431
19432 when Pragma_Share_Generic =>
19433 GNAT_Pragma;
19434 Process_Generic_List;
19435
19436 ------------
19437 -- Shared --
19438 ------------
19439
19440 -- pragma Shared (LOCAL_NAME);
19441
19442 when Pragma_Shared =>
19443 GNAT_Pragma;
19444 Process_Atomic_Shared_Volatile;
19445
19446 --------------------
19447 -- Shared_Passive --
19448 --------------------
19449
19450 -- pragma Shared_Passive [(library_unit_NAME)];
19451
19452 -- Set the flag Is_Shared_Passive of program unit name entity
19453
19454 when Pragma_Shared_Passive => Shared_Passive : declare
19455 Cunit_Node : Node_Id;
19456 Cunit_Ent : Entity_Id;
19457
19458 begin
19459 Check_Ada_83_Warning;
19460 Check_Valid_Library_Unit_Pragma;
19461
19462 if Nkind (N) = N_Null_Statement then
19463 return;
19464 end if;
19465
19466 Cunit_Node := Cunit (Current_Sem_Unit);
19467 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19468
19469 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19470 N_Generic_Package_Declaration)
19471 then
19472 Error_Pragma
19473 ("pragma% can only apply to a package declaration");
19474 end if;
19475
19476 Set_Is_Shared_Passive (Cunit_Ent);
19477 end Shared_Passive;
19478
19479 -----------------------
19480 -- Short_Descriptors --
19481 -----------------------
19482
19483 -- pragma Short_Descriptors;
19484
19485 when Pragma_Short_Descriptors =>
19486 GNAT_Pragma;
19487 Check_Arg_Count (0);
19488 Check_Valid_Configuration_Pragma;
19489 Short_Descriptors := True;
19490
19491 ------------------------------
19492 -- Simple_Storage_Pool_Type --
19493 ------------------------------
19494
19495 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
19496
19497 when Pragma_Simple_Storage_Pool_Type =>
19498 Simple_Storage_Pool_Type : declare
19499 Type_Id : Node_Id;
19500 Typ : Entity_Id;
19501
19502 begin
19503 GNAT_Pragma;
19504 Check_Arg_Count (1);
19505 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19506
19507 Type_Id := Get_Pragma_Arg (Arg1);
19508 Find_Type (Type_Id);
19509 Typ := Entity (Type_Id);
19510
19511 if Typ = Any_Type then
19512 return;
19513 end if;
19514
19515 -- We require the pragma to apply to a type declared in a package
19516 -- declaration, but not (immediately) within a package body.
19517
19518 if Ekind (Current_Scope) /= E_Package
19519 or else In_Package_Body (Current_Scope)
19520 then
19521 Error_Pragma
19522 ("pragma% can only apply to type declared immediately "
19523 & "within a package declaration");
19524 end if;
19525
19526 -- A simple storage pool type must be an immutably limited record
19527 -- or private type. If the pragma is given for a private type,
19528 -- the full type is similarly restricted (which is checked later
19529 -- in Freeze_Entity).
19530
19531 if Is_Record_Type (Typ)
19532 and then not Is_Limited_View (Typ)
19533 then
19534 Error_Pragma
19535 ("pragma% can only apply to explicitly limited record type");
19536
19537 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
19538 Error_Pragma
19539 ("pragma% can only apply to a private type that is limited");
19540
19541 elsif not Is_Record_Type (Typ)
19542 and then not Is_Private_Type (Typ)
19543 then
19544 Error_Pragma
19545 ("pragma% can only apply to limited record or private type");
19546 end if;
19547
19548 Record_Rep_Item (Typ, N);
19549 end Simple_Storage_Pool_Type;
19550
19551 ----------------------
19552 -- Source_File_Name --
19553 ----------------------
19554
19555 -- There are five forms for this pragma:
19556
19557 -- pragma Source_File_Name (
19558 -- [UNIT_NAME =>] unit_NAME,
19559 -- BODY_FILE_NAME => STRING_LITERAL
19560 -- [, [INDEX =>] INTEGER_LITERAL]);
19561
19562 -- pragma Source_File_Name (
19563 -- [UNIT_NAME =>] unit_NAME,
19564 -- SPEC_FILE_NAME => STRING_LITERAL
19565 -- [, [INDEX =>] INTEGER_LITERAL]);
19566
19567 -- pragma Source_File_Name (
19568 -- BODY_FILE_NAME => STRING_LITERAL
19569 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19570 -- [, CASING => CASING_SPEC]);
19571
19572 -- pragma Source_File_Name (
19573 -- SPEC_FILE_NAME => STRING_LITERAL
19574 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19575 -- [, CASING => CASING_SPEC]);
19576
19577 -- pragma Source_File_Name (
19578 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19579 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19580 -- [, CASING => CASING_SPEC]);
19581
19582 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
19583
19584 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
19585 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
19586 -- only be used when no project file is used, while SFNP can only be
19587 -- used when a project file is used.
19588
19589 -- No processing here. Processing was completed during parsing, since
19590 -- we need to have file names set as early as possible. Units are
19591 -- loaded well before semantic processing starts.
19592
19593 -- The only processing we defer to this point is the check for
19594 -- correct placement.
19595
19596 when Pragma_Source_File_Name =>
19597 GNAT_Pragma;
19598 Check_Valid_Configuration_Pragma;
19599
19600 ------------------------------
19601 -- Source_File_Name_Project --
19602 ------------------------------
19603
19604 -- See Source_File_Name for syntax
19605
19606 -- No processing here. Processing was completed during parsing, since
19607 -- we need to have file names set as early as possible. Units are
19608 -- loaded well before semantic processing starts.
19609
19610 -- The only processing we defer to this point is the check for
19611 -- correct placement.
19612
19613 when Pragma_Source_File_Name_Project =>
19614 GNAT_Pragma;
19615 Check_Valid_Configuration_Pragma;
19616
19617 -- Check that a pragma Source_File_Name_Project is used only in a
19618 -- configuration pragmas file.
19619
19620 -- Pragmas Source_File_Name_Project should only be generated by
19621 -- the Project Manager in configuration pragmas files.
19622
19623 -- This is really an ugly test. It seems to depend on some
19624 -- accidental and undocumented property. At the very least it
19625 -- needs to be documented, but it would be better to have a
19626 -- clean way of testing if we are in a configuration file???
19627
19628 if Present (Parent (N)) then
19629 Error_Pragma
19630 ("pragma% can only appear in a configuration pragmas file");
19631 end if;
19632
19633 ----------------------
19634 -- Source_Reference --
19635 ----------------------
19636
19637 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19638
19639 -- Nothing to do, all processing completed in Par.Prag, since we need
19640 -- the information for possible parser messages that are output.
19641
19642 when Pragma_Source_Reference =>
19643 GNAT_Pragma;
19644
19645 ----------------
19646 -- SPARK_Mode --
19647 ----------------
19648
19649 -- pragma SPARK_Mode [(On | Off)];
19650
19651 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
19652 Body_Id : Entity_Id;
19653 Context : Node_Id;
19654 Mode : Name_Id;
19655 Mode_Id : SPARK_Mode_Type;
19656 Spec_Id : Entity_Id;
19657 Stmt : Node_Id;
19658
19659 procedure Check_Pragma_Conformance
19660 (Context_Pragma : Node_Id;
19661 Entity_Pragma : Node_Id;
19662 Entity : Entity_Id);
19663 -- If Context_Pragma is not Empty, verify that the new pragma N
19664 -- is compatible with the pragma Context_Pragma that was inherited
19665 -- from the context:
19666 -- . if Context_Pragma is ON, then the new mode can be anything
19667 -- . if Context_Pragma is OFF, then the only allowed new mode is
19668 -- also OFF.
19669 --
19670 -- If Entity is not Empty, verify that the new pragma N is
19671 -- compatible with Entity_Pragma, the SPARK_Mode previously set
19672 -- for Entity (which may be Empty):
19673 -- . if Entity_Pragma is ON, then the new mode can be anything
19674 -- . if Entity_Pragma is OFF, then the only allowed new mode is
19675 -- also OFF.
19676 -- . if Entity_Pragma is Empty, we always issue an error, as this
19677 -- corresponds to a case where a previous section of Entity
19678 -- had no SPARK_Mode set.
19679
19680 procedure Check_Library_Level_Entity (E : Entity_Id);
19681 -- Verify that pragma is applied to library-level entity E
19682
19683 ------------------------------
19684 -- Check_Pragma_Conformance --
19685 ------------------------------
19686
19687 procedure Check_Pragma_Conformance
19688 (Context_Pragma : Node_Id;
19689 Entity_Pragma : Node_Id;
19690 Entity : Entity_Id)
19691 is
19692 begin
19693 if Present (Context_Pragma) then
19694 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
19695
19696 -- New mode less restrictive than the established mode
19697
19698 if Get_SPARK_Mode_From_Pragma (Context_Pragma) = Off
19699 and then Mode_Id = On
19700 then
19701 Error_Msg_N
19702 ("cannot change SPARK_Mode from Off to On", Arg1);
19703 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19704 Error_Msg_N ("\SPARK_Mode was set to Off#", Arg1);
19705 raise Pragma_Exit;
19706 end if;
19707 end if;
19708
19709 if Present (Entity) then
19710 if Present (Entity_Pragma) then
19711 if Get_SPARK_Mode_From_Pragma (Entity_Pragma) = Off
19712 and then Mode_Id = On
19713 then
19714 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19715 Error_Msg_Sloc := Sloc (Entity_Pragma);
19716 Error_Msg_NE
19717 ("\value Off was set for SPARK_Mode on&#",
19718 Arg1, Entity);
19719 raise Pragma_Exit;
19720 end if;
19721
19722 else
19723 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19724 Error_Msg_Sloc := Sloc (Entity);
19725 Error_Msg_NE
19726 ("\no value was set for SPARK_Mode on&#",
19727 Arg1, Entity);
19728 raise Pragma_Exit;
19729 end if;
19730 end if;
19731 end Check_Pragma_Conformance;
19732
19733 --------------------------------
19734 -- Check_Library_Level_Entity --
19735 --------------------------------
19736
19737 procedure Check_Library_Level_Entity (E : Entity_Id) is
19738 MsgF : constant String := "incorrect placement of pragma%";
19739
19740 begin
19741 if not Is_Library_Level_Entity (E) then
19742 Error_Msg_Name_1 := Pname;
19743 Error_Msg_N (Fix_Error (MsgF), N);
19744
19745 if Ekind_In (E, E_Generic_Package,
19746 E_Package,
19747 E_Package_Body)
19748 then
19749 Error_Msg_NE
19750 ("\& is not a library-level package", N, E);
19751 else
19752 Error_Msg_NE
19753 ("\& is not a library-level subprogram", N, E);
19754 end if;
19755
19756 raise Pragma_Exit;
19757 end if;
19758 end Check_Library_Level_Entity;
19759
19760 -- Start of processing for Do_SPARK_Mode
19761
19762 begin
19763 GNAT_Pragma;
19764 Check_No_Identifiers;
19765 Check_At_Most_N_Arguments (1);
19766
19767 -- Check the legality of the mode (no argument = ON)
19768
19769 if Arg_Count = 1 then
19770 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19771 Mode := Chars (Get_Pragma_Arg (Arg1));
19772 else
19773 Mode := Name_On;
19774 end if;
19775
19776 Mode_Id := Get_SPARK_Mode_Type (Mode);
19777 Context := Parent (N);
19778
19779 -- Packages and subprograms declared in a generic unit cannot be
19780 -- subject to the pragma.
19781
19782 if Inside_A_Generic then
19783 Error_Pragma ("incorrect placement of pragma% in a generic");
19784
19785 -- The pragma appears in a configuration pragmas file
19786
19787 elsif No (Context) then
19788 Check_Valid_Configuration_Pragma;
19789
19790 if Present (SPARK_Mode_Pragma) then
19791 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19792 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19793 raise Pragma_Exit;
19794 end if;
19795
19796 SPARK_Mode_Pragma := N;
19797 SPARK_Mode := Mode_Id;
19798
19799 -- When the pragma is placed before the declaration of a unit, it
19800 -- configures the whole unit.
19801
19802 elsif Nkind (Context) = N_Compilation_Unit then
19803 Check_Valid_Configuration_Pragma;
19804
19805 if Nkind (Unit (Context)) in N_Generic_Declaration
19806 or else (Present (Library_Unit (Context))
19807 and then Nkind (Unit (Library_Unit (Context))) in
19808 N_Generic_Declaration)
19809 then
19810 Error_Pragma ("incorrect placement of pragma% in a generic");
19811 end if;
19812
19813 SPARK_Mode_Pragma := N;
19814 SPARK_Mode := Mode_Id;
19815
19816 -- The pragma applies to a [library unit] subprogram or package
19817
19818 else
19819 -- Verify the placement of the pragma with respect to package
19820 -- or subprogram declarations and detect duplicates.
19821
19822 Stmt := Prev (N);
19823 while Present (Stmt) loop
19824
19825 -- Skip prior pragmas, but check for duplicates
19826
19827 if Nkind (Stmt) = N_Pragma then
19828 if Pragma_Name (Stmt) = Pname then
19829 Error_Msg_Name_1 := Pname;
19830 Error_Msg_Sloc := Sloc (Stmt);
19831 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19832 raise Pragma_Exit;
19833 end if;
19834
19835 elsif Nkind (Stmt) in N_Generic_Declaration then
19836 Error_Pragma
19837 ("incorrect placement of pragma% on a generic");
19838
19839 -- The pragma applies to a package declaration
19840
19841 elsif Nkind (Stmt) = N_Package_Declaration then
19842 Spec_Id := Defining_Entity (Stmt);
19843 Check_Library_Level_Entity (Spec_Id);
19844 Check_Pragma_Conformance
19845 (Context_Pragma => SPARK_Pragma (Spec_Id),
19846 Entity_Pragma => Empty,
19847 Entity => Empty);
19848
19849 Set_SPARK_Pragma (Spec_Id, N);
19850 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19851 Set_SPARK_Aux_Pragma (Spec_Id, N);
19852 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
19853 return;
19854
19855 -- The pragma applies to a subprogram declaration
19856
19857 elsif Nkind (Stmt) = N_Subprogram_Declaration then
19858 Spec_Id := Defining_Entity (Stmt);
19859 Check_Library_Level_Entity (Spec_Id);
19860 Check_Pragma_Conformance
19861 (Context_Pragma => SPARK_Pragma (Spec_Id),
19862 Entity_Pragma => Empty,
19863 Entity => Empty);
19864
19865 Set_SPARK_Pragma (Spec_Id, N);
19866 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19867 return;
19868
19869 -- Skip internally generated code
19870
19871 elsif not Comes_From_Source (Stmt) then
19872 null;
19873
19874 -- The pragma does not apply to a legal construct, issue an
19875 -- error and stop the analysis.
19876
19877 else
19878 Pragma_Misplaced;
19879 exit;
19880 end if;
19881
19882 Stmt := Prev (Stmt);
19883 end loop;
19884
19885 -- Handle all cases where the pragma is actually an aspect and
19886 -- applies to a library-level package spec, body or subprogram.
19887
19888 -- function F ... with SPARK_Mode => ...;
19889 -- package P with SPARK_Mode => ...;
19890 -- package body P with SPARK_Mode => ... is
19891
19892 -- The following circuitry simply prepares the proper context
19893 -- for the general pragma processing mechanism below.
19894
19895 if Nkind (Context) = N_Compilation_Unit_Aux then
19896 Context := Unit (Parent (Context));
19897
19898 if Nkind_In (Context, N_Package_Declaration,
19899 N_Subprogram_Declaration)
19900 then
19901 Context := Specification (Context);
19902 end if;
19903 end if;
19904
19905 -- The pragma is at the top level of a package spec
19906
19907 -- package P is
19908 -- pragma SPARK_Mode;
19909
19910 -- or
19911
19912 -- package P is
19913 -- ...
19914 -- private
19915 -- pragma SPARK_Mode;
19916
19917 if Nkind (Context) = N_Package_Specification then
19918 Spec_Id := Defining_Entity (Context);
19919
19920 -- Pragma applies to private part
19921
19922 if List_Containing (N) = Private_Declarations (Context) then
19923 Check_Library_Level_Entity (Spec_Id);
19924 Check_Pragma_Conformance
19925 (Context_Pragma => Empty,
19926 Entity_Pragma => SPARK_Pragma (Spec_Id),
19927 Entity => Spec_Id);
19928 SPARK_Mode_Pragma := N;
19929 SPARK_Mode := Mode_Id;
19930
19931 Set_SPARK_Aux_Pragma (Spec_Id, N);
19932 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
19933
19934 -- Pragma applies to public part
19935
19936 else
19937 Check_Library_Level_Entity (Spec_Id);
19938 Check_Pragma_Conformance
19939 (Context_Pragma => SPARK_Pragma (Spec_Id),
19940 Entity_Pragma => Empty,
19941 Entity => Empty);
19942 SPARK_Mode_Pragma := N;
19943 SPARK_Mode := Mode_Id;
19944
19945 Set_SPARK_Pragma (Spec_Id, N);
19946 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19947 Set_SPARK_Aux_Pragma (Spec_Id, N);
19948 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True);
19949 end if;
19950
19951 -- The pragma appears as an aspect on a subprogram.
19952
19953 -- function F ... with SPARK_Mode => ...;
19954
19955 elsif Nkind_In (Context, N_Function_Specification,
19956 N_Procedure_Specification)
19957 then
19958 Spec_Id := Defining_Entity (Context);
19959 Check_Library_Level_Entity (Spec_Id);
19960 Check_Pragma_Conformance
19961 (Context_Pragma => SPARK_Pragma (Spec_Id),
19962 Entity_Pragma => Empty,
19963 Entity => Empty);
19964 Set_SPARK_Pragma (Spec_Id, N);
19965 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19966
19967 -- Pragma is immediately within a package body
19968
19969 -- package body P is
19970 -- pragma SPARK_Mode;
19971
19972 elsif Nkind (Context) = N_Package_Body then
19973 Spec_Id := Corresponding_Spec (Context);
19974 Body_Id := Defining_Entity (Context);
19975 Check_Library_Level_Entity (Body_Id);
19976 Check_Pragma_Conformance
19977 (Context_Pragma => SPARK_Pragma (Body_Id),
19978 Entity_Pragma => SPARK_Aux_Pragma (Spec_Id),
19979 Entity => Spec_Id);
19980 SPARK_Mode_Pragma := N;
19981 SPARK_Mode := Mode_Id;
19982
19983 Set_SPARK_Pragma (Body_Id, N);
19984 Set_SPARK_Pragma_Inherited (Body_Id, False);
19985 Set_SPARK_Aux_Pragma (Body_Id, N);
19986 Set_SPARK_Aux_Pragma_Inherited (Body_Id, True);
19987
19988 -- Pragma is immediately within a subprogram body
19989
19990 -- function F ... is
19991 -- pragma SPARK_Mode;
19992
19993 elsif Nkind (Context) = N_Subprogram_Body then
19994 Spec_Id := Corresponding_Spec (Context);
19995 Context := Specification (Context);
19996 Body_Id := Defining_Entity (Context);
19997
19998 -- Ignore pragma when applied to the special body created
19999 -- for inlining, recognized by its internal name _Parent.
20000
20001 if Chars (Body_Id) = Name_uParent then
20002 return;
20003 end if;
20004
20005 Check_Library_Level_Entity (Body_Id);
20006
20007 if Present (Spec_Id) then
20008 Check_Pragma_Conformance
20009 (Context_Pragma => SPARK_Pragma (Body_Id),
20010 Entity_Pragma => SPARK_Pragma (Spec_Id),
20011 Entity => Spec_Id);
20012 else
20013 Check_Pragma_Conformance
20014 (Context_Pragma => SPARK_Pragma (Body_Id),
20015 Entity_Pragma => Empty,
20016 Entity => Empty);
20017 end if;
20018
20019 SPARK_Mode_Pragma := N;
20020 SPARK_Mode := Mode_Id;
20021
20022 Set_SPARK_Pragma (Body_Id, N);
20023 Set_SPARK_Pragma_Inherited (Body_Id, False);
20024
20025 -- The pragma applies to the statements of a package body
20026
20027 -- package body P is
20028 -- begin
20029 -- pragma SPARK_Mode;
20030
20031 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
20032 and then Nkind (Parent (Context)) = N_Package_Body
20033 then
20034 Context := Parent (Context);
20035 Spec_Id := Corresponding_Spec (Context);
20036 Body_Id := Defining_Entity (Context);
20037 Check_Library_Level_Entity (Body_Id);
20038 Check_Pragma_Conformance
20039 (Context_Pragma => Empty,
20040 Entity_Pragma => SPARK_Pragma (Body_Id),
20041 Entity => Body_Id);
20042 SPARK_Mode_Pragma := N;
20043 SPARK_Mode := Mode_Id;
20044
20045 Set_SPARK_Aux_Pragma (Body_Id, N);
20046 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
20047
20048 -- The pragma does not apply to a legal construct, issue error
20049
20050 else
20051 Pragma_Misplaced;
20052 end if;
20053 end if;
20054 end Do_SPARK_Mode;
20055
20056 --------------------------------
20057 -- Static_Elaboration_Desired --
20058 --------------------------------
20059
20060 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
20061
20062 when Pragma_Static_Elaboration_Desired =>
20063 GNAT_Pragma;
20064 Check_At_Most_N_Arguments (1);
20065
20066 if Is_Compilation_Unit (Current_Scope)
20067 and then Ekind (Current_Scope) = E_Package
20068 then
20069 Set_Static_Elaboration_Desired (Current_Scope, True);
20070 else
20071 Error_Pragma ("pragma% must apply to a library-level package");
20072 end if;
20073
20074 ------------------
20075 -- Storage_Size --
20076 ------------------
20077
20078 -- pragma Storage_Size (EXPRESSION);
20079
20080 when Pragma_Storage_Size => Storage_Size : declare
20081 P : constant Node_Id := Parent (N);
20082 Arg : Node_Id;
20083
20084 begin
20085 Check_No_Identifiers;
20086 Check_Arg_Count (1);
20087
20088 -- The expression must be analyzed in the special manner described
20089 -- in "Handling of Default Expressions" in sem.ads.
20090
20091 Arg := Get_Pragma_Arg (Arg1);
20092 Preanalyze_Spec_Expression (Arg, Any_Integer);
20093
20094 if not Is_OK_Static_Expression (Arg) then
20095 Check_Restriction (Static_Storage_Size, Arg);
20096 end if;
20097
20098 if Nkind (P) /= N_Task_Definition then
20099 Pragma_Misplaced;
20100 return;
20101
20102 else
20103 if Has_Storage_Size_Pragma (P) then
20104 Error_Pragma ("duplicate pragma% not allowed");
20105 else
20106 Set_Has_Storage_Size_Pragma (P, True);
20107 end if;
20108
20109 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
20110 end if;
20111 end Storage_Size;
20112
20113 ------------------
20114 -- Storage_Unit --
20115 ------------------
20116
20117 -- pragma Storage_Unit (NUMERIC_LITERAL);
20118
20119 -- Only permitted argument is System'Storage_Unit value
20120
20121 when Pragma_Storage_Unit =>
20122 Check_No_Identifiers;
20123 Check_Arg_Count (1);
20124 Check_Arg_Is_Integer_Literal (Arg1);
20125
20126 if Intval (Get_Pragma_Arg (Arg1)) /=
20127 UI_From_Int (Ttypes.System_Storage_Unit)
20128 then
20129 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
20130 Error_Pragma_Arg
20131 ("the only allowed argument for pragma% is ^", Arg1);
20132 end if;
20133
20134 --------------------
20135 -- Stream_Convert --
20136 --------------------
20137
20138 -- pragma Stream_Convert (
20139 -- [Entity =>] type_LOCAL_NAME,
20140 -- [Read =>] function_NAME,
20141 -- [Write =>] function NAME);
20142
20143 when Pragma_Stream_Convert => Stream_Convert : declare
20144
20145 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
20146 -- Check that the given argument is the name of a local function
20147 -- of one argument that is not overloaded earlier in the current
20148 -- local scope. A check is also made that the argument is a
20149 -- function with one parameter.
20150
20151 --------------------------------------
20152 -- Check_OK_Stream_Convert_Function --
20153 --------------------------------------
20154
20155 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
20156 Ent : Entity_Id;
20157
20158 begin
20159 Check_Arg_Is_Local_Name (Arg);
20160 Ent := Entity (Get_Pragma_Arg (Arg));
20161
20162 if Has_Homonym (Ent) then
20163 Error_Pragma_Arg
20164 ("argument for pragma% may not be overloaded", Arg);
20165 end if;
20166
20167 if Ekind (Ent) /= E_Function
20168 or else No (First_Formal (Ent))
20169 or else Present (Next_Formal (First_Formal (Ent)))
20170 then
20171 Error_Pragma_Arg
20172 ("argument for pragma% must be function of one argument",
20173 Arg);
20174 end if;
20175 end Check_OK_Stream_Convert_Function;
20176
20177 -- Start of processing for Stream_Convert
20178
20179 begin
20180 GNAT_Pragma;
20181 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
20182 Check_Arg_Count (3);
20183 Check_Optional_Identifier (Arg1, Name_Entity);
20184 Check_Optional_Identifier (Arg2, Name_Read);
20185 Check_Optional_Identifier (Arg3, Name_Write);
20186 Check_Arg_Is_Local_Name (Arg1);
20187 Check_OK_Stream_Convert_Function (Arg2);
20188 Check_OK_Stream_Convert_Function (Arg3);
20189
20190 declare
20191 Typ : constant Entity_Id :=
20192 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
20193 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
20194 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
20195
20196 begin
20197 Check_First_Subtype (Arg1);
20198
20199 -- Check for too early or too late. Note that we don't enforce
20200 -- the rule about primitive operations in this case, since, as
20201 -- is the case for explicit stream attributes themselves, these
20202 -- restrictions are not appropriate. Note that the chaining of
20203 -- the pragma by Rep_Item_Too_Late is actually the critical
20204 -- processing done for this pragma.
20205
20206 if Rep_Item_Too_Early (Typ, N)
20207 or else
20208 Rep_Item_Too_Late (Typ, N, FOnly => True)
20209 then
20210 return;
20211 end if;
20212
20213 -- Return if previous error
20214
20215 if Etype (Typ) = Any_Type
20216 or else
20217 Etype (Read) = Any_Type
20218 or else
20219 Etype (Write) = Any_Type
20220 then
20221 return;
20222 end if;
20223
20224 -- Error checks
20225
20226 if Underlying_Type (Etype (Read)) /= Typ then
20227 Error_Pragma_Arg
20228 ("incorrect return type for function&", Arg2);
20229 end if;
20230
20231 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
20232 Error_Pragma_Arg
20233 ("incorrect parameter type for function&", Arg3);
20234 end if;
20235
20236 if Underlying_Type (Etype (First_Formal (Read))) /=
20237 Underlying_Type (Etype (Write))
20238 then
20239 Error_Pragma_Arg
20240 ("result type of & does not match Read parameter type",
20241 Arg3);
20242 end if;
20243 end;
20244 end Stream_Convert;
20245
20246 ------------------
20247 -- Style_Checks --
20248 ------------------
20249
20250 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
20251
20252 -- This is processed by the parser since some of the style checks
20253 -- take place during source scanning and parsing. This means that
20254 -- we don't need to issue error messages here.
20255
20256 when Pragma_Style_Checks => Style_Checks : declare
20257 A : constant Node_Id := Get_Pragma_Arg (Arg1);
20258 S : String_Id;
20259 C : Char_Code;
20260
20261 begin
20262 GNAT_Pragma;
20263 Check_No_Identifiers;
20264
20265 -- Two argument form
20266
20267 if Arg_Count = 2 then
20268 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20269
20270 declare
20271 E_Id : Node_Id;
20272 E : Entity_Id;
20273
20274 begin
20275 E_Id := Get_Pragma_Arg (Arg2);
20276 Analyze (E_Id);
20277
20278 if not Is_Entity_Name (E_Id) then
20279 Error_Pragma_Arg
20280 ("second argument of pragma% must be entity name",
20281 Arg2);
20282 end if;
20283
20284 E := Entity (E_Id);
20285
20286 if not Ignore_Style_Checks_Pragmas then
20287 if E = Any_Id then
20288 return;
20289 else
20290 loop
20291 Set_Suppress_Style_Checks
20292 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
20293 exit when No (Homonym (E));
20294 E := Homonym (E);
20295 end loop;
20296 end if;
20297 end if;
20298 end;
20299
20300 -- One argument form
20301
20302 else
20303 Check_Arg_Count (1);
20304
20305 if Nkind (A) = N_String_Literal then
20306 S := Strval (A);
20307
20308 declare
20309 Slen : constant Natural := Natural (String_Length (S));
20310 Options : String (1 .. Slen);
20311 J : Natural;
20312
20313 begin
20314 J := 1;
20315 loop
20316 C := Get_String_Char (S, Int (J));
20317 exit when not In_Character_Range (C);
20318 Options (J) := Get_Character (C);
20319
20320 -- If at end of string, set options. As per discussion
20321 -- above, no need to check for errors, since we issued
20322 -- them in the parser.
20323
20324 if J = Slen then
20325 if not Ignore_Style_Checks_Pragmas then
20326 Set_Style_Check_Options (Options);
20327 end if;
20328
20329 exit;
20330 end if;
20331
20332 J := J + 1;
20333 end loop;
20334 end;
20335
20336 elsif Nkind (A) = N_Identifier then
20337 if Chars (A) = Name_All_Checks then
20338 if not Ignore_Style_Checks_Pragmas then
20339 if GNAT_Mode then
20340 Set_GNAT_Style_Check_Options;
20341 else
20342 Set_Default_Style_Check_Options;
20343 end if;
20344 end if;
20345
20346 elsif Chars (A) = Name_On then
20347 if not Ignore_Style_Checks_Pragmas then
20348 Style_Check := True;
20349 end if;
20350
20351 elsif Chars (A) = Name_Off then
20352 if not Ignore_Style_Checks_Pragmas then
20353 Style_Check := False;
20354 end if;
20355 end if;
20356 end if;
20357 end if;
20358 end Style_Checks;
20359
20360 --------------
20361 -- Subtitle --
20362 --------------
20363
20364 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
20365
20366 when Pragma_Subtitle =>
20367 GNAT_Pragma;
20368 Check_Arg_Count (1);
20369 Check_Optional_Identifier (Arg1, Name_Subtitle);
20370 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20371 Store_Note (N);
20372
20373 --------------
20374 -- Suppress --
20375 --------------
20376
20377 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
20378
20379 when Pragma_Suppress =>
20380 Process_Suppress_Unsuppress (True);
20381
20382 ------------------
20383 -- Suppress_All --
20384 ------------------
20385
20386 -- pragma Suppress_All;
20387
20388 -- The only check made here is that the pragma has no arguments.
20389 -- There are no placement rules, and the processing required (setting
20390 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
20391 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
20392 -- then creates and inserts a pragma Suppress (All_Checks).
20393
20394 when Pragma_Suppress_All =>
20395 GNAT_Pragma;
20396 Check_Arg_Count (0);
20397
20398 -------------------------
20399 -- Suppress_Debug_Info --
20400 -------------------------
20401
20402 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
20403
20404 when Pragma_Suppress_Debug_Info =>
20405 GNAT_Pragma;
20406 Check_Arg_Count (1);
20407 Check_Optional_Identifier (Arg1, Name_Entity);
20408 Check_Arg_Is_Local_Name (Arg1);
20409 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
20410
20411 ----------------------------------
20412 -- Suppress_Exception_Locations --
20413 ----------------------------------
20414
20415 -- pragma Suppress_Exception_Locations;
20416
20417 when Pragma_Suppress_Exception_Locations =>
20418 GNAT_Pragma;
20419 Check_Arg_Count (0);
20420 Check_Valid_Configuration_Pragma;
20421 Exception_Locations_Suppressed := True;
20422
20423 -----------------------------
20424 -- Suppress_Initialization --
20425 -----------------------------
20426
20427 -- pragma Suppress_Initialization ([Entity =>] type_Name);
20428
20429 when Pragma_Suppress_Initialization => Suppress_Init : declare
20430 E_Id : Node_Id;
20431 E : Entity_Id;
20432
20433 begin
20434 GNAT_Pragma;
20435 Check_Arg_Count (1);
20436 Check_Optional_Identifier (Arg1, Name_Entity);
20437 Check_Arg_Is_Local_Name (Arg1);
20438
20439 E_Id := Get_Pragma_Arg (Arg1);
20440
20441 if Etype (E_Id) = Any_Type then
20442 return;
20443 end if;
20444
20445 E := Entity (E_Id);
20446
20447 if not Is_Type (E) then
20448 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
20449 end if;
20450
20451 if Rep_Item_Too_Early (E, N)
20452 or else
20453 Rep_Item_Too_Late (E, N, FOnly => True)
20454 then
20455 return;
20456 end if;
20457
20458 -- For incomplete/private type, set flag on full view
20459
20460 if Is_Incomplete_Or_Private_Type (E) then
20461 if No (Full_View (Base_Type (E))) then
20462 Error_Pragma_Arg
20463 ("argument of pragma% cannot be an incomplete type", Arg1);
20464 else
20465 Set_Suppress_Initialization (Full_View (Base_Type (E)));
20466 end if;
20467
20468 -- For first subtype, set flag on base type
20469
20470 elsif Is_First_Subtype (E) then
20471 Set_Suppress_Initialization (Base_Type (E));
20472
20473 -- For other than first subtype, set flag on subtype itself
20474
20475 else
20476 Set_Suppress_Initialization (E);
20477 end if;
20478 end Suppress_Init;
20479
20480 -----------------
20481 -- System_Name --
20482 -----------------
20483
20484 -- pragma System_Name (DIRECT_NAME);
20485
20486 -- Syntax check: one argument, which must be the identifier GNAT or
20487 -- the identifier GCC, no other identifiers are acceptable.
20488
20489 when Pragma_System_Name =>
20490 GNAT_Pragma;
20491 Check_No_Identifiers;
20492 Check_Arg_Count (1);
20493 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
20494
20495 -----------------------------
20496 -- Task_Dispatching_Policy --
20497 -----------------------------
20498
20499 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
20500
20501 when Pragma_Task_Dispatching_Policy => declare
20502 DP : Character;
20503
20504 begin
20505 Check_Ada_83_Warning;
20506 Check_Arg_Count (1);
20507 Check_No_Identifiers;
20508 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
20509 Check_Valid_Configuration_Pragma;
20510 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
20511 DP := Fold_Upper (Name_Buffer (1));
20512
20513 if Task_Dispatching_Policy /= ' '
20514 and then Task_Dispatching_Policy /= DP
20515 then
20516 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20517 Error_Pragma
20518 ("task dispatching policy incompatible with policy#");
20519
20520 -- Set new policy, but always preserve System_Location since we
20521 -- like the error message with the run time name.
20522
20523 else
20524 Task_Dispatching_Policy := DP;
20525
20526 if Task_Dispatching_Policy_Sloc /= System_Location then
20527 Task_Dispatching_Policy_Sloc := Loc;
20528 end if;
20529 end if;
20530 end;
20531
20532 ---------------
20533 -- Task_Info --
20534 ---------------
20535
20536 -- pragma Task_Info (EXPRESSION);
20537
20538 when Pragma_Task_Info => Task_Info : declare
20539 P : constant Node_Id := Parent (N);
20540 Ent : Entity_Id;
20541
20542 begin
20543 GNAT_Pragma;
20544
20545 if Warn_On_Obsolescent_Feature then
20546 Error_Msg_N
20547 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20548 & "instead?j?", N);
20549 end if;
20550
20551 if Nkind (P) /= N_Task_Definition then
20552 Error_Pragma ("pragma% must appear in task definition");
20553 end if;
20554
20555 Check_No_Identifiers;
20556 Check_Arg_Count (1);
20557
20558 Analyze_And_Resolve
20559 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
20560
20561 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
20562 return;
20563 end if;
20564
20565 Ent := Defining_Identifier (Parent (P));
20566
20567 -- Check duplicate pragma before we chain the pragma in the Rep
20568 -- Item chain of Ent.
20569
20570 if Has_Rep_Pragma
20571 (Ent, Name_Task_Info, Check_Parents => False)
20572 then
20573 Error_Pragma ("duplicate pragma% not allowed");
20574 end if;
20575
20576 Record_Rep_Item (Ent, N);
20577 end Task_Info;
20578
20579 ---------------
20580 -- Task_Name --
20581 ---------------
20582
20583 -- pragma Task_Name (string_EXPRESSION);
20584
20585 when Pragma_Task_Name => Task_Name : declare
20586 P : constant Node_Id := Parent (N);
20587 Arg : Node_Id;
20588 Ent : Entity_Id;
20589
20590 begin
20591 Check_No_Identifiers;
20592 Check_Arg_Count (1);
20593
20594 Arg := Get_Pragma_Arg (Arg1);
20595
20596 -- The expression is used in the call to Create_Task, and must be
20597 -- expanded there, not in the context of the current spec. It must
20598 -- however be analyzed to capture global references, in case it
20599 -- appears in a generic context.
20600
20601 Preanalyze_And_Resolve (Arg, Standard_String);
20602
20603 if Nkind (P) /= N_Task_Definition then
20604 Pragma_Misplaced;
20605 end if;
20606
20607 Ent := Defining_Identifier (Parent (P));
20608
20609 -- Check duplicate pragma before we chain the pragma in the Rep
20610 -- Item chain of Ent.
20611
20612 if Has_Rep_Pragma
20613 (Ent, Name_Task_Name, Check_Parents => False)
20614 then
20615 Error_Pragma ("duplicate pragma% not allowed");
20616 end if;
20617
20618 Record_Rep_Item (Ent, N);
20619 end Task_Name;
20620
20621 ------------------
20622 -- Task_Storage --
20623 ------------------
20624
20625 -- pragma Task_Storage (
20626 -- [Task_Type =>] LOCAL_NAME,
20627 -- [Top_Guard =>] static_integer_EXPRESSION);
20628
20629 when Pragma_Task_Storage => Task_Storage : declare
20630 Args : Args_List (1 .. 2);
20631 Names : constant Name_List (1 .. 2) := (
20632 Name_Task_Type,
20633 Name_Top_Guard);
20634
20635 Task_Type : Node_Id renames Args (1);
20636 Top_Guard : Node_Id renames Args (2);
20637
20638 Ent : Entity_Id;
20639
20640 begin
20641 GNAT_Pragma;
20642 Gather_Associations (Names, Args);
20643
20644 if No (Task_Type) then
20645 Error_Pragma
20646 ("missing task_type argument for pragma%");
20647 end if;
20648
20649 Check_Arg_Is_Local_Name (Task_Type);
20650
20651 Ent := Entity (Task_Type);
20652
20653 if not Is_Task_Type (Ent) then
20654 Error_Pragma_Arg
20655 ("argument for pragma% must be task type", Task_Type);
20656 end if;
20657
20658 if No (Top_Guard) then
20659 Error_Pragma_Arg
20660 ("pragma% takes two arguments", Task_Type);
20661 else
20662 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
20663 end if;
20664
20665 Check_First_Subtype (Task_Type);
20666
20667 if Rep_Item_Too_Late (Ent, N) then
20668 raise Pragma_Exit;
20669 end if;
20670 end Task_Storage;
20671
20672 ---------------
20673 -- Test_Case --
20674 ---------------
20675
20676 -- pragma Test_Case
20677 -- ([Name =>] Static_String_EXPRESSION
20678 -- ,[Mode =>] MODE_TYPE
20679 -- [, Requires => Boolean_EXPRESSION]
20680 -- [, Ensures => Boolean_EXPRESSION]);
20681
20682 -- MODE_TYPE ::= Nominal | Robustness
20683
20684 when Pragma_Test_Case =>
20685 GNAT_Pragma;
20686 Check_Test_Case;
20687
20688 --------------------------
20689 -- Thread_Local_Storage --
20690 --------------------------
20691
20692 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20693
20694 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
20695 Id : Node_Id;
20696 E : Entity_Id;
20697
20698 begin
20699 GNAT_Pragma;
20700 Check_Arg_Count (1);
20701 Check_Optional_Identifier (Arg1, Name_Entity);
20702 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20703
20704 Id := Get_Pragma_Arg (Arg1);
20705 Analyze (Id);
20706
20707 if not Is_Entity_Name (Id)
20708 or else Ekind (Entity (Id)) /= E_Variable
20709 then
20710 Error_Pragma_Arg ("local variable name required", Arg1);
20711 end if;
20712
20713 E := Entity (Id);
20714
20715 if Rep_Item_Too_Early (E, N)
20716 or else Rep_Item_Too_Late (E, N)
20717 then
20718 raise Pragma_Exit;
20719 end if;
20720
20721 Set_Has_Pragma_Thread_Local_Storage (E);
20722 Set_Has_Gigi_Rep_Item (E);
20723 end Thread_Local_Storage;
20724
20725 ----------------
20726 -- Time_Slice --
20727 ----------------
20728
20729 -- pragma Time_Slice (static_duration_EXPRESSION);
20730
20731 when Pragma_Time_Slice => Time_Slice : declare
20732 Val : Ureal;
20733 Nod : Node_Id;
20734
20735 begin
20736 GNAT_Pragma;
20737 Check_Arg_Count (1);
20738 Check_No_Identifiers;
20739 Check_In_Main_Program;
20740 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
20741
20742 if not Error_Posted (Arg1) then
20743 Nod := Next (N);
20744 while Present (Nod) loop
20745 if Nkind (Nod) = N_Pragma
20746 and then Pragma_Name (Nod) = Name_Time_Slice
20747 then
20748 Error_Msg_Name_1 := Pname;
20749 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20750 end if;
20751
20752 Next (Nod);
20753 end loop;
20754 end if;
20755
20756 -- Process only if in main unit
20757
20758 if Get_Source_Unit (Loc) = Main_Unit then
20759 Opt.Time_Slice_Set := True;
20760 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
20761
20762 if Val <= Ureal_0 then
20763 Opt.Time_Slice_Value := 0;
20764
20765 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
20766 Opt.Time_Slice_Value := 1_000_000_000;
20767
20768 else
20769 Opt.Time_Slice_Value :=
20770 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
20771 end if;
20772 end if;
20773 end Time_Slice;
20774
20775 -----------
20776 -- Title --
20777 -----------
20778
20779 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20780
20781 -- TITLING_OPTION ::=
20782 -- [Title =>] STRING_LITERAL
20783 -- | [Subtitle =>] STRING_LITERAL
20784
20785 when Pragma_Title => Title : declare
20786 Args : Args_List (1 .. 2);
20787 Names : constant Name_List (1 .. 2) := (
20788 Name_Title,
20789 Name_Subtitle);
20790
20791 begin
20792 GNAT_Pragma;
20793 Gather_Associations (Names, Args);
20794 Store_Note (N);
20795
20796 for J in 1 .. 2 loop
20797 if Present (Args (J)) then
20798 Check_Arg_Is_OK_Static_Expression
20799 (Args (J), Standard_String);
20800 end if;
20801 end loop;
20802 end Title;
20803
20804 ----------------------------
20805 -- Type_Invariant[_Class] --
20806 ----------------------------
20807
20808 -- pragma Type_Invariant[_Class]
20809 -- ([Entity =>] type_LOCAL_NAME,
20810 -- [Check =>] EXPRESSION);
20811
20812 when Pragma_Type_Invariant |
20813 Pragma_Type_Invariant_Class =>
20814 Type_Invariant : declare
20815 I_Pragma : Node_Id;
20816
20817 begin
20818 Check_Arg_Count (2);
20819
20820 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20821 -- setting Class_Present for the Type_Invariant_Class case.
20822
20823 Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class);
20824 I_Pragma := New_Copy (N);
20825 Set_Pragma_Identifier
20826 (I_Pragma, Make_Identifier (Loc, Name_Invariant));
20827 Rewrite (N, I_Pragma);
20828 Set_Analyzed (N, False);
20829 Analyze (N);
20830 end Type_Invariant;
20831
20832 ---------------------
20833 -- Unchecked_Union --
20834 ---------------------
20835
20836 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20837
20838 when Pragma_Unchecked_Union => Unchecked_Union : declare
20839 Assoc : constant Node_Id := Arg1;
20840 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
20841 Typ : Entity_Id;
20842 Tdef : Node_Id;
20843 Clist : Node_Id;
20844 Vpart : Node_Id;
20845 Comp : Node_Id;
20846 Variant : Node_Id;
20847
20848 begin
20849 Ada_2005_Pragma;
20850 Check_No_Identifiers;
20851 Check_Arg_Count (1);
20852 Check_Arg_Is_Local_Name (Arg1);
20853
20854 Find_Type (Type_Id);
20855
20856 Typ := Entity (Type_Id);
20857
20858 if Typ = Any_Type
20859 or else Rep_Item_Too_Early (Typ, N)
20860 then
20861 return;
20862 else
20863 Typ := Underlying_Type (Typ);
20864 end if;
20865
20866 if Rep_Item_Too_Late (Typ, N) then
20867 return;
20868 end if;
20869
20870 Check_First_Subtype (Arg1);
20871
20872 -- Note remaining cases are references to a type in the current
20873 -- declarative part. If we find an error, we post the error on
20874 -- the relevant type declaration at an appropriate point.
20875
20876 if not Is_Record_Type (Typ) then
20877 Error_Msg_N ("unchecked union must be record type", Typ);
20878 return;
20879
20880 elsif Is_Tagged_Type (Typ) then
20881 Error_Msg_N ("unchecked union must not be tagged", Typ);
20882 return;
20883
20884 elsif not Has_Discriminants (Typ) then
20885 Error_Msg_N
20886 ("unchecked union must have one discriminant", Typ);
20887 return;
20888
20889 -- Note: in previous versions of GNAT we used to check for limited
20890 -- types and give an error, but in fact the standard does allow
20891 -- Unchecked_Union on limited types, so this check was removed.
20892
20893 -- Similarly, GNAT used to require that all discriminants have
20894 -- default values, but this is not mandated by the RM.
20895
20896 -- Proceed with basic error checks completed
20897
20898 else
20899 Tdef := Type_Definition (Declaration_Node (Typ));
20900 Clist := Component_List (Tdef);
20901
20902 -- Check presence of component list and variant part
20903
20904 if No (Clist) or else No (Variant_Part (Clist)) then
20905 Error_Msg_N
20906 ("unchecked union must have variant part", Tdef);
20907 return;
20908 end if;
20909
20910 -- Check components
20911
20912 Comp := First (Component_Items (Clist));
20913 while Present (Comp) loop
20914 Check_Component (Comp, Typ);
20915 Next (Comp);
20916 end loop;
20917
20918 -- Check variant part
20919
20920 Vpart := Variant_Part (Clist);
20921
20922 Variant := First (Variants (Vpart));
20923 while Present (Variant) loop
20924 Check_Variant (Variant, Typ);
20925 Next (Variant);
20926 end loop;
20927 end if;
20928
20929 Set_Is_Unchecked_Union (Typ);
20930 Set_Convention (Typ, Convention_C);
20931 Set_Has_Unchecked_Union (Base_Type (Typ));
20932 Set_Is_Unchecked_Union (Base_Type (Typ));
20933 end Unchecked_Union;
20934
20935 ------------------------
20936 -- Unimplemented_Unit --
20937 ------------------------
20938
20939 -- pragma Unimplemented_Unit;
20940
20941 -- Note: this only gives an error if we are generating code, or if
20942 -- we are in a generic library unit (where the pragma appears in the
20943 -- body, not in the spec).
20944
20945 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
20946 Cunitent : constant Entity_Id :=
20947 Cunit_Entity (Get_Source_Unit (Loc));
20948 Ent_Kind : constant Entity_Kind :=
20949 Ekind (Cunitent);
20950
20951 begin
20952 GNAT_Pragma;
20953 Check_Arg_Count (0);
20954
20955 if Operating_Mode = Generate_Code
20956 or else Ent_Kind = E_Generic_Function
20957 or else Ent_Kind = E_Generic_Procedure
20958 or else Ent_Kind = E_Generic_Package
20959 then
20960 Get_Name_String (Chars (Cunitent));
20961 Set_Casing (Mixed_Case);
20962 Write_Str (Name_Buffer (1 .. Name_Len));
20963 Write_Str (" is not supported in this configuration");
20964 Write_Eol;
20965 raise Unrecoverable_Error;
20966 end if;
20967 end Unimplemented_Unit;
20968
20969 ------------------------
20970 -- Universal_Aliasing --
20971 ------------------------
20972
20973 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20974
20975 when Pragma_Universal_Aliasing => Universal_Alias : declare
20976 E_Id : Entity_Id;
20977
20978 begin
20979 GNAT_Pragma;
20980 Check_Arg_Count (1);
20981 Check_Optional_Identifier (Arg2, Name_Entity);
20982 Check_Arg_Is_Local_Name (Arg1);
20983 E_Id := Entity (Get_Pragma_Arg (Arg1));
20984
20985 if E_Id = Any_Type then
20986 return;
20987 elsif No (E_Id) or else not Is_Type (E_Id) then
20988 Error_Pragma_Arg ("pragma% requires type", Arg1);
20989 end if;
20990
20991 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
20992 Record_Rep_Item (E_Id, N);
20993 end Universal_Alias;
20994
20995 --------------------
20996 -- Universal_Data --
20997 --------------------
20998
20999 -- pragma Universal_Data [(library_unit_NAME)];
21000
21001 when Pragma_Universal_Data =>
21002 GNAT_Pragma;
21003
21004 -- If this is a configuration pragma, then set the universal
21005 -- addressing option, otherwise confirm that the pragma satisfies
21006 -- the requirements of library unit pragma placement and leave it
21007 -- to the GNAAMP back end to detect the pragma (avoids transitive
21008 -- setting of the option due to withed units).
21009
21010 if Is_Configuration_Pragma then
21011 Universal_Addressing_On_AAMP := True;
21012 else
21013 Check_Valid_Library_Unit_Pragma;
21014 end if;
21015
21016 if not AAMP_On_Target then
21017 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
21018 end if;
21019
21020 ----------------
21021 -- Unmodified --
21022 ----------------
21023
21024 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
21025
21026 when Pragma_Unmodified => Unmodified : declare
21027 Arg_Node : Node_Id;
21028 Arg_Expr : Node_Id;
21029 Arg_Ent : Entity_Id;
21030
21031 begin
21032 GNAT_Pragma;
21033 Check_At_Least_N_Arguments (1);
21034
21035 -- Loop through arguments
21036
21037 Arg_Node := Arg1;
21038 while Present (Arg_Node) loop
21039 Check_No_Identifier (Arg_Node);
21040
21041 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
21042 -- in fact generate reference, so that the entity will have a
21043 -- reference, which will inhibit any warnings about it not
21044 -- being referenced, and also properly show up in the ali file
21045 -- as a reference. But this reference is recorded before the
21046 -- Has_Pragma_Unreferenced flag is set, so that no warning is
21047 -- generated for this reference.
21048
21049 Check_Arg_Is_Local_Name (Arg_Node);
21050 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21051
21052 if Is_Entity_Name (Arg_Expr) then
21053 Arg_Ent := Entity (Arg_Expr);
21054
21055 if not Is_Assignable (Arg_Ent) then
21056 Error_Pragma_Arg
21057 ("pragma% can only be applied to a variable",
21058 Arg_Expr);
21059 else
21060 Set_Has_Pragma_Unmodified (Arg_Ent);
21061 end if;
21062 end if;
21063
21064 Next (Arg_Node);
21065 end loop;
21066 end Unmodified;
21067
21068 ------------------
21069 -- Unreferenced --
21070 ------------------
21071
21072 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
21073
21074 -- or when used in a context clause:
21075
21076 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
21077
21078 when Pragma_Unreferenced => Unreferenced : declare
21079 Arg_Node : Node_Id;
21080 Arg_Expr : Node_Id;
21081 Arg_Ent : Entity_Id;
21082 Citem : Node_Id;
21083
21084 begin
21085 GNAT_Pragma;
21086 Check_At_Least_N_Arguments (1);
21087
21088 -- Check case of appearing within context clause
21089
21090 if Is_In_Context_Clause then
21091
21092 -- The arguments must all be units mentioned in a with clause
21093 -- in the same context clause. Note we already checked (in
21094 -- Par.Prag) that the arguments are either identifiers or
21095 -- selected components.
21096
21097 Arg_Node := Arg1;
21098 while Present (Arg_Node) loop
21099 Citem := First (List_Containing (N));
21100 while Citem /= N loop
21101 if Nkind (Citem) = N_With_Clause
21102 and then
21103 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
21104 then
21105 Set_Has_Pragma_Unreferenced
21106 (Cunit_Entity
21107 (Get_Source_Unit
21108 (Library_Unit (Citem))));
21109 Set_Unit_Name
21110 (Get_Pragma_Arg (Arg_Node), Name (Citem));
21111 exit;
21112 end if;
21113
21114 Next (Citem);
21115 end loop;
21116
21117 if Citem = N then
21118 Error_Pragma_Arg
21119 ("argument of pragma% is not withed unit", Arg_Node);
21120 end if;
21121
21122 Next (Arg_Node);
21123 end loop;
21124
21125 -- Case of not in list of context items
21126
21127 else
21128 Arg_Node := Arg1;
21129 while Present (Arg_Node) loop
21130 Check_No_Identifier (Arg_Node);
21131
21132 -- Note: the analyze call done by Check_Arg_Is_Local_Name
21133 -- will in fact generate reference, so that the entity will
21134 -- have a reference, which will inhibit any warnings about
21135 -- it not being referenced, and also properly show up in the
21136 -- ali file as a reference. But this reference is recorded
21137 -- before the Has_Pragma_Unreferenced flag is set, so that
21138 -- no warning is generated for this reference.
21139
21140 Check_Arg_Is_Local_Name (Arg_Node);
21141 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21142
21143 if Is_Entity_Name (Arg_Expr) then
21144 Arg_Ent := Entity (Arg_Expr);
21145
21146 -- If the entity is overloaded, the pragma applies to the
21147 -- most recent overloading, as documented. In this case,
21148 -- name resolution does not generate a reference, so it
21149 -- must be done here explicitly.
21150
21151 if Is_Overloaded (Arg_Expr) then
21152 Generate_Reference (Arg_Ent, N);
21153 end if;
21154
21155 Set_Has_Pragma_Unreferenced (Arg_Ent);
21156 end if;
21157
21158 Next (Arg_Node);
21159 end loop;
21160 end if;
21161 end Unreferenced;
21162
21163 --------------------------
21164 -- Unreferenced_Objects --
21165 --------------------------
21166
21167 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
21168
21169 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
21170 Arg_Node : Node_Id;
21171 Arg_Expr : Node_Id;
21172
21173 begin
21174 GNAT_Pragma;
21175 Check_At_Least_N_Arguments (1);
21176
21177 Arg_Node := Arg1;
21178 while Present (Arg_Node) loop
21179 Check_No_Identifier (Arg_Node);
21180 Check_Arg_Is_Local_Name (Arg_Node);
21181 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21182
21183 if not Is_Entity_Name (Arg_Expr)
21184 or else not Is_Type (Entity (Arg_Expr))
21185 then
21186 Error_Pragma_Arg
21187 ("argument for pragma% must be type or subtype", Arg_Node);
21188 end if;
21189
21190 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
21191 Next (Arg_Node);
21192 end loop;
21193 end Unreferenced_Objects;
21194
21195 ------------------------------
21196 -- Unreserve_All_Interrupts --
21197 ------------------------------
21198
21199 -- pragma Unreserve_All_Interrupts;
21200
21201 when Pragma_Unreserve_All_Interrupts =>
21202 GNAT_Pragma;
21203 Check_Arg_Count (0);
21204
21205 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
21206 Unreserve_All_Interrupts := True;
21207 end if;
21208
21209 ----------------
21210 -- Unsuppress --
21211 ----------------
21212
21213 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
21214
21215 when Pragma_Unsuppress =>
21216 Ada_2005_Pragma;
21217 Process_Suppress_Unsuppress (False);
21218
21219 ----------------------------
21220 -- Unevaluated_Use_Of_Old --
21221 ----------------------------
21222
21223 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
21224
21225 when Pragma_Unevaluated_Use_Of_Old =>
21226 GNAT_Pragma;
21227 Check_Arg_Count (1);
21228 Check_No_Identifiers;
21229 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
21230
21231 -- Suppress/Unsuppress can appear as a configuration pragma, or in
21232 -- a declarative part or a package spec.
21233
21234 if not Is_Configuration_Pragma then
21235 Check_Is_In_Decl_Part_Or_Package_Spec;
21236 end if;
21237
21238 -- Store proper setting of Uneval_Old
21239
21240 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21241 Uneval_Old := Fold_Upper (Name_Buffer (1));
21242
21243 -------------------
21244 -- Use_VADS_Size --
21245 -------------------
21246
21247 -- pragma Use_VADS_Size;
21248
21249 when Pragma_Use_VADS_Size =>
21250 GNAT_Pragma;
21251 Check_Arg_Count (0);
21252 Check_Valid_Configuration_Pragma;
21253 Use_VADS_Size := True;
21254
21255 ---------------------
21256 -- Validity_Checks --
21257 ---------------------
21258
21259 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21260
21261 when Pragma_Validity_Checks => Validity_Checks : declare
21262 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21263 S : String_Id;
21264 C : Char_Code;
21265
21266 begin
21267 GNAT_Pragma;
21268 Check_Arg_Count (1);
21269 Check_No_Identifiers;
21270
21271 -- Pragma always active unless in CodePeer or GNATprove modes,
21272 -- which use a fixed configuration of validity checks.
21273
21274 if not (CodePeer_Mode or GNATprove_Mode) then
21275 if Nkind (A) = N_String_Literal then
21276 S := Strval (A);
21277
21278 declare
21279 Slen : constant Natural := Natural (String_Length (S));
21280 Options : String (1 .. Slen);
21281 J : Natural;
21282
21283 begin
21284 -- Couldn't we use a for loop here over Options'Range???
21285
21286 J := 1;
21287 loop
21288 C := Get_String_Char (S, Int (J));
21289
21290 -- This is a weird test, it skips setting validity
21291 -- checks entirely if any element of S is out of
21292 -- range of Character, what is that about ???
21293
21294 exit when not In_Character_Range (C);
21295 Options (J) := Get_Character (C);
21296
21297 if J = Slen then
21298 Set_Validity_Check_Options (Options);
21299 exit;
21300 else
21301 J := J + 1;
21302 end if;
21303 end loop;
21304 end;
21305
21306 elsif Nkind (A) = N_Identifier then
21307 if Chars (A) = Name_All_Checks then
21308 Set_Validity_Check_Options ("a");
21309 elsif Chars (A) = Name_On then
21310 Validity_Checks_On := True;
21311 elsif Chars (A) = Name_Off then
21312 Validity_Checks_On := False;
21313 end if;
21314 end if;
21315 end if;
21316 end Validity_Checks;
21317
21318 --------------
21319 -- Volatile --
21320 --------------
21321
21322 -- pragma Volatile (LOCAL_NAME);
21323
21324 when Pragma_Volatile =>
21325 Process_Atomic_Shared_Volatile;
21326
21327 -------------------------
21328 -- Volatile_Components --
21329 -------------------------
21330
21331 -- pragma Volatile_Components (array_LOCAL_NAME);
21332
21333 -- Volatile is handled by the same circuit as Atomic_Components
21334
21335 ----------------------
21336 -- Warning_As_Error --
21337 ----------------------
21338
21339 when Pragma_Warning_As_Error =>
21340 GNAT_Pragma;
21341 Check_Arg_Count (1);
21342 Check_No_Identifiers;
21343 Check_Valid_Configuration_Pragma;
21344
21345 if not Is_Static_String_Expression (Arg1) then
21346 Error_Pragma_Arg
21347 ("argument of pragma% must be static string expression",
21348 Arg1);
21349
21350 -- OK static string expression
21351
21352 else
21353 Acquire_Warning_Match_String (Arg1);
21354 Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1;
21355 Warnings_As_Errors (Warnings_As_Errors_Count) :=
21356 new String'(Name_Buffer (1 .. Name_Len));
21357 end if;
21358
21359 --------------
21360 -- Warnings --
21361 --------------
21362
21363 -- pragma Warnings (On | Off [,REASON]);
21364 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
21365 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
21366 -- pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
21367
21368 -- REASON ::= Reason => Static_String_Expression
21369
21370 when Pragma_Warnings => Warnings : declare
21371 Reason : String_Id;
21372
21373 begin
21374 GNAT_Pragma;
21375 Check_At_Least_N_Arguments (1);
21376
21377 -- See if last argument is labeled Reason. If so, make sure we
21378 -- have a static string expression, and acquire the REASON string.
21379 -- Then remove the REASON argument by decreasing Num_Args by one;
21380 -- Remaining processing looks only at first Num_Args arguments).
21381
21382 declare
21383 Last_Arg : constant Node_Id :=
21384 Last (Pragma_Argument_Associations (N));
21385
21386 begin
21387 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21388 and then Chars (Last_Arg) = Name_Reason
21389 then
21390 Start_String;
21391 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21392 Reason := End_String;
21393 Arg_Count := Arg_Count - 1;
21394
21395 -- Not allowed in compiler units (bootstrap issues)
21396
21397 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21398
21399 -- No REASON string, set null string as reason
21400
21401 else
21402 Reason := Null_String_Id;
21403 end if;
21404 end;
21405
21406 -- Now proceed with REASON taken care of and eliminated
21407
21408 Check_No_Identifiers;
21409
21410 -- If debug flag -gnatd.i is set, pragma is ignored
21411
21412 if Debug_Flag_Dot_I then
21413 return;
21414 end if;
21415
21416 -- Process various forms of the pragma
21417
21418 declare
21419 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21420
21421 begin
21422 -- One argument case
21423
21424 if Arg_Count = 1 then
21425
21426 -- On/Off one argument case was processed by parser
21427
21428 if Nkind (Argx) = N_Identifier
21429 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21430 then
21431 null;
21432
21433 -- One argument case must be ON/OFF or static string expr
21434
21435 elsif not Is_Static_String_Expression (Arg1) then
21436 Error_Pragma_Arg
21437 ("argument of pragma% must be On/Off or static string "
21438 & "expression", Arg1);
21439
21440 -- One argument string expression case
21441
21442 else
21443 declare
21444 Lit : constant Node_Id := Expr_Value_S (Argx);
21445 Str : constant String_Id := Strval (Lit);
21446 Len : constant Nat := String_Length (Str);
21447 C : Char_Code;
21448 J : Nat;
21449 OK : Boolean;
21450 Chr : Character;
21451
21452 begin
21453 J := 1;
21454 while J <= Len loop
21455 C := Get_String_Char (Str, J);
21456 OK := In_Character_Range (C);
21457
21458 if OK then
21459 Chr := Get_Character (C);
21460
21461 -- Dash case: only -Wxxx is accepted
21462
21463 if J = 1
21464 and then J < Len
21465 and then Chr = '-'
21466 then
21467 J := J + 1;
21468 C := Get_String_Char (Str, J);
21469 Chr := Get_Character (C);
21470 exit when Chr = 'W';
21471 OK := False;
21472
21473 -- Dot case
21474
21475 elsif J < Len and then Chr = '.' then
21476 J := J + 1;
21477 C := Get_String_Char (Str, J);
21478 Chr := Get_Character (C);
21479
21480 if not Set_Dot_Warning_Switch (Chr) then
21481 Error_Pragma_Arg
21482 ("invalid warning switch character "
21483 & '.' & Chr, Arg1);
21484 end if;
21485
21486 -- Non-Dot case
21487
21488 else
21489 OK := Set_Warning_Switch (Chr);
21490 end if;
21491 end if;
21492
21493 if not OK then
21494 Error_Pragma_Arg
21495 ("invalid warning switch character " & Chr,
21496 Arg1);
21497 end if;
21498
21499 J := J + 1;
21500 end loop;
21501 end;
21502 end if;
21503
21504 -- Two or more arguments (must be two)
21505
21506 else
21507 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21508 Check_Arg_Count (2);
21509
21510 declare
21511 E_Id : Node_Id;
21512 E : Entity_Id;
21513 Err : Boolean;
21514
21515 begin
21516 E_Id := Get_Pragma_Arg (Arg2);
21517 Analyze (E_Id);
21518
21519 -- In the expansion of an inlined body, a reference to
21520 -- the formal may be wrapped in a conversion if the
21521 -- actual is a conversion. Retrieve the real entity name.
21522
21523 if (In_Instance_Body or In_Inlined_Body)
21524 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21525 then
21526 E_Id := Expression (E_Id);
21527 end if;
21528
21529 -- Entity name case
21530
21531 if Is_Entity_Name (E_Id) then
21532 E := Entity (E_Id);
21533
21534 if E = Any_Id then
21535 return;
21536 else
21537 loop
21538 Set_Warnings_Off
21539 (E, (Chars (Get_Pragma_Arg (Arg1)) =
21540 Name_Off));
21541
21542 -- For OFF case, make entry in warnings off
21543 -- pragma table for later processing. But we do
21544 -- not do that within an instance, since these
21545 -- warnings are about what is needed in the
21546 -- template, not an instance of it.
21547
21548 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21549 and then Warn_On_Warnings_Off
21550 and then not In_Instance
21551 then
21552 Warnings_Off_Pragmas.Append ((N, E, Reason));
21553 end if;
21554
21555 if Is_Enumeration_Type (E) then
21556 declare
21557 Lit : Entity_Id;
21558 begin
21559 Lit := First_Literal (E);
21560 while Present (Lit) loop
21561 Set_Warnings_Off (Lit);
21562 Next_Literal (Lit);
21563 end loop;
21564 end;
21565 end if;
21566
21567 exit when No (Homonym (E));
21568 E := Homonym (E);
21569 end loop;
21570 end if;
21571
21572 -- Error if not entity or static string expression case
21573
21574 elsif not Is_Static_String_Expression (Arg2) then
21575 Error_Pragma_Arg
21576 ("second argument of pragma% must be entity name "
21577 & "or static string expression", Arg2);
21578
21579 -- Static string expression case
21580
21581 else
21582 Acquire_Warning_Match_String (Arg2);
21583
21584 -- Note on configuration pragma case: If this is a
21585 -- configuration pragma, then for an OFF pragma, we
21586 -- just set Config True in the call, which is all
21587 -- that needs to be done. For the case of ON, this
21588 -- is normally an error, unless it is canceling the
21589 -- effect of a previous OFF pragma in the same file.
21590 -- In any other case, an error will be signalled (ON
21591 -- with no matching OFF).
21592
21593 -- Note: We set Used if we are inside a generic to
21594 -- disable the test that the non-config case actually
21595 -- cancels a warning. That's because we can't be sure
21596 -- there isn't an instantiation in some other unit
21597 -- where a warning is suppressed.
21598
21599 -- We could do a little better here by checking if the
21600 -- generic unit we are inside is public, but for now
21601 -- we don't bother with that refinement.
21602
21603 if Chars (Argx) = Name_Off then
21604 Set_Specific_Warning_Off
21605 (Loc, Name_Buffer (1 .. Name_Len), Reason,
21606 Config => Is_Configuration_Pragma,
21607 Used => Inside_A_Generic or else In_Instance);
21608
21609 elsif Chars (Argx) = Name_On then
21610 Set_Specific_Warning_On
21611 (Loc, Name_Buffer (1 .. Name_Len), Err);
21612
21613 if Err then
21614 Error_Msg
21615 ("??pragma Warnings On with no matching "
21616 & "Warnings Off", Loc);
21617 end if;
21618 end if;
21619 end if;
21620 end;
21621 end if;
21622 end;
21623 end Warnings;
21624
21625 -------------------
21626 -- Weak_External --
21627 -------------------
21628
21629 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21630
21631 when Pragma_Weak_External => Weak_External : declare
21632 Ent : Entity_Id;
21633
21634 begin
21635 GNAT_Pragma;
21636 Check_Arg_Count (1);
21637 Check_Optional_Identifier (Arg1, Name_Entity);
21638 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21639 Ent := Entity (Get_Pragma_Arg (Arg1));
21640
21641 if Rep_Item_Too_Early (Ent, N) then
21642 return;
21643 else
21644 Ent := Underlying_Type (Ent);
21645 end if;
21646
21647 -- The only processing required is to link this item on to the
21648 -- list of rep items for the given entity. This is accomplished
21649 -- by the call to Rep_Item_Too_Late (when no error is detected
21650 -- and False is returned).
21651
21652 if Rep_Item_Too_Late (Ent, N) then
21653 return;
21654 else
21655 Set_Has_Gigi_Rep_Item (Ent);
21656 end if;
21657 end Weak_External;
21658
21659 -----------------------------
21660 -- Wide_Character_Encoding --
21661 -----------------------------
21662
21663 -- pragma Wide_Character_Encoding (IDENTIFIER);
21664
21665 when Pragma_Wide_Character_Encoding =>
21666 GNAT_Pragma;
21667
21668 -- Nothing to do, handled in parser. Note that we do not enforce
21669 -- configuration pragma placement, this pragma can appear at any
21670 -- place in the source, allowing mixed encodings within a single
21671 -- source program.
21672
21673 null;
21674
21675 --------------------
21676 -- Unknown_Pragma --
21677 --------------------
21678
21679 -- Should be impossible, since the case of an unknown pragma is
21680 -- separately processed before the case statement is entered.
21681
21682 when Unknown_Pragma =>
21683 raise Program_Error;
21684 end case;
21685
21686 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21687 -- until AI is formally approved.
21688
21689 -- Check_Order_Dependence;
21690
21691 exception
21692 when Pragma_Exit => null;
21693 end Analyze_Pragma;
21694
21695 ---------------------------------------------
21696 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21697 ---------------------------------------------
21698
21699 procedure Analyze_Pre_Post_Condition_In_Decl_Part
21700 (Prag : Node_Id;
21701 Subp_Id : Entity_Id)
21702 is
21703 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (Prag));
21704 Nam : constant Name_Id := Original_Aspect_Name (Prag);
21705 Expr : Node_Id;
21706
21707 Restore_Scope : Boolean := False;
21708 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
21709
21710 begin
21711 -- Ensure that the subprogram and its formals are visible when analyzing
21712 -- the expression of the pragma.
21713
21714 if not In_Open_Scopes (Subp_Id) then
21715 Restore_Scope := True;
21716 Push_Scope (Subp_Id);
21717 Install_Formals (Subp_Id);
21718 end if;
21719
21720 -- Preanalyze the boolean expression, we treat this as a spec expression
21721 -- (i.e. similar to a default expression).
21722
21723 Expr := Get_Pragma_Arg (Arg1);
21724
21725 -- In ASIS mode, for a pragma generated from a source aspect, analyze
21726 -- the original aspect expression, which is shared with the generated
21727 -- pragma.
21728
21729 if ASIS_Mode and then Present (Corresponding_Aspect (Prag)) then
21730 Expr := Expression (Corresponding_Aspect (Prag));
21731 end if;
21732
21733 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
21734
21735 -- For a class-wide condition, a reference to a controlling formal must
21736 -- be interpreted as having the class-wide type (or an access to such)
21737 -- so that the inherited condition can be properly applied to any
21738 -- overriding operation (see ARM12 6.6.1 (7)).
21739
21740 if Class_Present (Prag) then
21741 Class_Wide_Condition : declare
21742 T : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
21743
21744 ACW : Entity_Id := Empty;
21745 -- Access to T'class, created if there is a controlling formal
21746 -- that is an access parameter.
21747
21748 function Get_ACW return Entity_Id;
21749 -- If the expression has a reference to an controlling access
21750 -- parameter, create an access to T'class for the necessary
21751 -- conversions if one does not exist.
21752
21753 function Process (N : Node_Id) return Traverse_Result;
21754 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
21755 -- aspect for a primitive subprogram of a tagged type T, a name
21756 -- that denotes a formal parameter of type T is interpreted as
21757 -- having type T'Class. Similarly, a name that denotes a formal
21758 -- accessparameter of type access-to-T is interpreted as having
21759 -- type access-to-T'Class. This ensures the expression is well-
21760 -- defined for a primitive subprogram of a type descended from T.
21761 -- Note that this replacement is not done for selector names in
21762 -- parameter associations. These carry an entity for reference
21763 -- purposes, but semantically they are just identifiers.
21764
21765 -------------
21766 -- Get_ACW --
21767 -------------
21768
21769 function Get_ACW return Entity_Id is
21770 Loc : constant Source_Ptr := Sloc (Prag);
21771 Decl : Node_Id;
21772
21773 begin
21774 if No (ACW) then
21775 Decl :=
21776 Make_Full_Type_Declaration (Loc,
21777 Defining_Identifier => Make_Temporary (Loc, 'T'),
21778 Type_Definition =>
21779 Make_Access_To_Object_Definition (Loc,
21780 Subtype_Indication =>
21781 New_Occurrence_Of (Class_Wide_Type (T), Loc),
21782 All_Present => True));
21783
21784 Insert_Before (Unit_Declaration_Node (Subp_Id), Decl);
21785 Analyze (Decl);
21786 ACW := Defining_Identifier (Decl);
21787 Freeze_Before (Unit_Declaration_Node (Subp_Id), ACW);
21788 end if;
21789
21790 return ACW;
21791 end Get_ACW;
21792
21793 -------------
21794 -- Process --
21795 -------------
21796
21797 function Process (N : Node_Id) return Traverse_Result is
21798 Loc : constant Source_Ptr := Sloc (N);
21799 Typ : Entity_Id;
21800
21801 begin
21802 if Is_Entity_Name (N)
21803 and then Present (Entity (N))
21804 and then Is_Formal (Entity (N))
21805 and then Nkind (Parent (N)) /= N_Type_Conversion
21806 and then
21807 (Nkind (Parent (N)) /= N_Parameter_Association
21808 or else N /= Selector_Name (Parent (N)))
21809 then
21810 if Etype (Entity (N)) = T then
21811 Typ := Class_Wide_Type (T);
21812
21813 elsif Is_Access_Type (Etype (Entity (N)))
21814 and then Designated_Type (Etype (Entity (N))) = T
21815 then
21816 Typ := Get_ACW;
21817 else
21818 Typ := Empty;
21819 end if;
21820
21821 if Present (Typ) then
21822 Rewrite (N,
21823 Make_Type_Conversion (Loc,
21824 Subtype_Mark =>
21825 New_Occurrence_Of (Typ, Loc),
21826 Expression => New_Occurrence_Of (Entity (N), Loc)));
21827 Set_Etype (N, Typ);
21828 end if;
21829 end if;
21830
21831 return OK;
21832 end Process;
21833
21834 procedure Replace_Type is new Traverse_Proc (Process);
21835
21836 -- Start of processing for Class_Wide_Condition
21837
21838 begin
21839 if not Present (T) then
21840
21841 -- Pre'Class/Post'Class aspect cases
21842
21843 if From_Aspect_Specification (Prag) then
21844 if Nam = Name_uPre then
21845 Error_Msg_Name_1 := Name_Pre;
21846 else
21847 Error_Msg_Name_1 := Name_Post;
21848 end if;
21849
21850 Error_Msg_Name_2 := Name_Class;
21851
21852 Error_Msg_N
21853 ("aspect `%''%` can only be specified for a primitive "
21854 & "operation of a tagged type",
21855 Corresponding_Aspect (Prag));
21856
21857 -- Pre_Class, Post_Class pragma cases
21858
21859 else
21860 if Nam = Name_uPre then
21861 Error_Msg_Name_1 := Name_Pre_Class;
21862 else
21863 Error_Msg_Name_1 := Name_Post_Class;
21864 end if;
21865
21866 Error_Msg_N
21867 ("pragma% can only be specified for a primitive "
21868 & "operation of a tagged type",
21869 Corresponding_Aspect (Prag));
21870 end if;
21871 end if;
21872
21873 Replace_Type (Get_Pragma_Arg (Arg1));
21874 end Class_Wide_Condition;
21875 end if;
21876
21877 -- Remove the subprogram from the scope stack now that the pre-analysis
21878 -- of the precondition/postcondition is done.
21879
21880 if Restore_Scope then
21881 End_Scope;
21882 end if;
21883 end Analyze_Pre_Post_Condition_In_Decl_Part;
21884
21885 ------------------------------------------
21886 -- Analyze_Refined_Depends_In_Decl_Part --
21887 ------------------------------------------
21888
21889 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21890 Dependencies : List_Id := No_List;
21891 Depends : Node_Id;
21892 -- The corresponding Depends pragma along with its clauses
21893
21894 Matched_Items : Elist_Id := No_Elist;
21895 -- A list containing the entities of all successfully matched items
21896 -- found in pragma Depends.
21897
21898 Refinements : List_Id := No_List;
21899 -- The clauses of pragma Refined_Depends
21900
21901 Spec_Id : Entity_Id;
21902 -- The entity of the subprogram subject to pragma Refined_Depends
21903
21904 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
21905 -- Try to match a single dependency clause Dep_Clause against one or
21906 -- more refinement clauses found in list Refinements. Each successful
21907 -- match eliminates at least one refinement clause from Refinements.
21908
21909 procedure Normalize_Clauses (Clauses : List_Id);
21910 -- Given a list of dependence or refinement clauses Clauses, normalize
21911 -- each clause by creating multiple dependencies with exactly one input
21912 -- and one output.
21913
21914 procedure Report_Extra_Clauses;
21915 -- Emit an error for each extra clause found in list Refinements
21916
21917 -----------------------------
21918 -- Check_Dependency_Clause --
21919 -----------------------------
21920
21921 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
21922 Dep_Input : constant Node_Id := Expression (Dep_Clause);
21923 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
21924
21925 function Is_In_Out_State_Clause return Boolean;
21926 -- Determine whether dependence clause Dep_Clause denotes an abstract
21927 -- state that depends on itself (State => State).
21928
21929 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
21930 -- Determine whether item Item denotes an abstract state with visible
21931 -- null refinement.
21932
21933 procedure Match_Items
21934 (Dep_Item : Node_Id;
21935 Ref_Item : Node_Id;
21936 Matched : out Boolean);
21937 -- Try to match dependence item Dep_Item against refinement item
21938 -- Ref_Item. To match against a possible null refinement (see 2, 7),
21939 -- set Ref_Item to Empty. Flag Matched is set to True when one of
21940 -- the following conformance scenarios is in effect:
21941 -- 1) Both items denote null
21942 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
21943 -- 3) Both items denote attribute 'Result
21944 -- 4) Both items denote the same formal parameter
21945 -- 5) Both items denote the same variable
21946 -- 6) Dep_Item is an abstract state with visible null refinement
21947 -- and Ref_Item denotes null.
21948 -- 7) Dep_Item is an abstract state with visible null refinement
21949 -- and Ref_Item is Empty (special case).
21950 -- 8) Dep_Item is an abstract state with visible non-null
21951 -- refinement and Ref_Item denotes one of its constituents.
21952 -- 9) Dep_Item is an abstract state without a visible refinement
21953 -- and Ref_Item denotes the same state.
21954 -- When scenario 8 is in effect, the entity of the abstract state
21955 -- denoted by Dep_Item is added to list Refined_States.
21956
21957 procedure Record_Item (Item_Id : Entity_Id);
21958 -- Store the entity of an item denoted by Item_Id in Matched_Items
21959
21960 ----------------------------
21961 -- Is_In_Out_State_Clause --
21962 ----------------------------
21963
21964 function Is_In_Out_State_Clause return Boolean is
21965 Dep_Input_Id : Entity_Id;
21966 Dep_Output_Id : Entity_Id;
21967
21968 begin
21969 -- Detect the following clause:
21970 -- State => State
21971
21972 if Is_Entity_Name (Dep_Input)
21973 and then Is_Entity_Name (Dep_Output)
21974 then
21975 -- Handle abstract views generated for limited with clauses
21976
21977 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
21978 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
21979
21980 return
21981 Ekind (Dep_Input_Id) = E_Abstract_State
21982 and then Dep_Input_Id = Dep_Output_Id;
21983 else
21984 return False;
21985 end if;
21986 end Is_In_Out_State_Clause;
21987
21988 ---------------------------
21989 -- Is_Null_Refined_State --
21990 ---------------------------
21991
21992 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
21993 Item_Id : Entity_Id;
21994
21995 begin
21996 if Is_Entity_Name (Item) then
21997
21998 -- Handle abstract views generated for limited with clauses
21999
22000 Item_Id := Available_View (Entity_Of (Item));
22001
22002 return Ekind (Item_Id) = E_Abstract_State
22003 and then Has_Null_Refinement (Item_Id);
22004
22005 else
22006 return False;
22007 end if;
22008 end Is_Null_Refined_State;
22009
22010 -----------------
22011 -- Match_Items --
22012 -----------------
22013
22014 procedure Match_Items
22015 (Dep_Item : Node_Id;
22016 Ref_Item : Node_Id;
22017 Matched : out Boolean)
22018 is
22019 Dep_Item_Id : Entity_Id;
22020 Ref_Item_Id : Entity_Id;
22021
22022 begin
22023 -- Assume that the two items do not match
22024
22025 Matched := False;
22026
22027 -- A null matches null or Empty (special case)
22028
22029 if Nkind (Dep_Item) = N_Null
22030 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
22031 then
22032 Matched := True;
22033
22034 -- Attribute 'Result matches attribute 'Result
22035
22036 elsif Is_Attribute_Result (Dep_Item)
22037 and then Is_Attribute_Result (Dep_Item)
22038 then
22039 Matched := True;
22040
22041 -- Abstract states, formal parameters and variables
22042
22043 elsif Is_Entity_Name (Dep_Item) then
22044
22045 -- Handle abstract views generated for limited with clauses
22046
22047 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
22048
22049 if Ekind (Dep_Item_Id) = E_Abstract_State then
22050
22051 -- An abstract state with visible null refinement matches
22052 -- null or Empty (special case).
22053
22054 if Has_Null_Refinement (Dep_Item_Id)
22055 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
22056 then
22057 Record_Item (Dep_Item_Id);
22058 Matched := True;
22059
22060 -- An abstract state with visible non-null refinement
22061 -- matches one of its constituents.
22062
22063 elsif Has_Non_Null_Refinement (Dep_Item_Id) then
22064 if Is_Entity_Name (Ref_Item) then
22065 Ref_Item_Id := Entity_Of (Ref_Item);
22066
22067 if Ekind_In (Ref_Item_Id, E_Abstract_State, E_Variable)
22068 and then Present (Encapsulating_State (Ref_Item_Id))
22069 and then Encapsulating_State (Ref_Item_Id) =
22070 Dep_Item_Id
22071 then
22072 Record_Item (Dep_Item_Id);
22073 Matched := True;
22074 end if;
22075 end if;
22076
22077 -- An abstract state without a visible refinement matches
22078 -- itself.
22079
22080 elsif Is_Entity_Name (Ref_Item)
22081 and then Entity_Of (Ref_Item) = Dep_Item_Id
22082 then
22083 Record_Item (Dep_Item_Id);
22084 Matched := True;
22085 end if;
22086
22087 -- A formal parameter or a variable matches itself
22088
22089 elsif Is_Entity_Name (Ref_Item)
22090 and then Entity_Of (Ref_Item) = Dep_Item_Id
22091 then
22092 Record_Item (Dep_Item_Id);
22093 Matched := True;
22094 end if;
22095 end if;
22096 end Match_Items;
22097
22098 -----------------
22099 -- Record_Item --
22100 -----------------
22101
22102 procedure Record_Item (Item_Id : Entity_Id) is
22103 begin
22104 if not Contains (Matched_Items, Item_Id) then
22105 Add_Item (Item_Id, Matched_Items);
22106 end if;
22107 end Record_Item;
22108
22109 -- Local variables
22110
22111 Clause_Matched : Boolean := False;
22112 Dummy : Boolean := False;
22113 Inputs_Match : Boolean;
22114 Next_Ref_Clause : Node_Id;
22115 Outputs_Match : Boolean;
22116 Ref_Clause : Node_Id;
22117 Ref_Input : Node_Id;
22118 Ref_Output : Node_Id;
22119
22120 -- Start of processing for Check_Dependency_Clause
22121
22122 begin
22123 -- Examine all refinement clauses and compare them against the
22124 -- dependence clause.
22125
22126 Ref_Clause := First (Refinements);
22127 while Present (Ref_Clause) loop
22128 Next_Ref_Clause := Next (Ref_Clause);
22129
22130 -- Obtain the attributes of the current refinement clause
22131
22132 Ref_Input := Expression (Ref_Clause);
22133 Ref_Output := First (Choices (Ref_Clause));
22134
22135 -- The current refinement clause matches the dependence clause
22136 -- when both outputs match and both inputs match. See routine
22137 -- Match_Items for all possible conformance scenarios.
22138
22139 -- Depends Dep_Output => Dep_Input
22140 -- ^ ^
22141 -- match ? match ?
22142 -- v v
22143 -- Refined_Depends Ref_Output => Ref_Input
22144
22145 Match_Items
22146 (Dep_Item => Dep_Input,
22147 Ref_Item => Ref_Input,
22148 Matched => Inputs_Match);
22149
22150 Match_Items
22151 (Dep_Item => Dep_Output,
22152 Ref_Item => Ref_Output,
22153 Matched => Outputs_Match);
22154
22155 -- An In_Out state clause may be matched against a refinement with
22156 -- a null input or null output as long as the non-null side of the
22157 -- relation contains a valid constituent of the In_Out_State.
22158
22159 if Is_In_Out_State_Clause then
22160
22161 -- Depends => (State => State)
22162 -- Refined_Depends => (null => Constit) -- OK
22163
22164 if Inputs_Match
22165 and then not Outputs_Match
22166 and then Nkind (Ref_Output) = N_Null
22167 then
22168 Outputs_Match := True;
22169 end if;
22170
22171 -- Depends => (State => State)
22172 -- Refined_Depends => (Constit => null) -- OK
22173
22174 if not Inputs_Match
22175 and then Outputs_Match
22176 and then Nkind (Ref_Input) = N_Null
22177 then
22178 Inputs_Match := True;
22179 end if;
22180 end if;
22181
22182 -- The current refinement clause is legally constructed following
22183 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
22184 -- the pool of candidates. The seach continues because a single
22185 -- dependence clause may have multiple matching refinements.
22186
22187 if Inputs_Match and then Outputs_Match then
22188 Clause_Matched := True;
22189 Remove (Ref_Clause);
22190 end if;
22191
22192 Ref_Clause := Next_Ref_Clause;
22193 end loop;
22194
22195 -- Depending on the order or composition of refinement clauses, an
22196 -- In_Out state clause may not be directly refinable.
22197
22198 -- Depends => ((Output, State) => (Input, State))
22199 -- Refined_State => (State => (Constit_1, Constit_2))
22200 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
22201
22202 -- Matching normalized clause (State => State) fails because there is
22203 -- no direct refinement capable of satisfying this relation. Another
22204 -- similar case arises when clauses (Constit_1 => Input) and (Output
22205 -- => Constit_2) are matched first, leaving no candidates for clause
22206 -- (State => State). Both scenarios are legal as long as one of the
22207 -- previous clauses mentioned a valid constituent of State.
22208
22209 if not Clause_Matched
22210 and then Is_In_Out_State_Clause
22211 and then
22212 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22213 then
22214 Clause_Matched := True;
22215 end if;
22216
22217 -- A clause where the input is an abstract state with visible null
22218 -- refinement is implicitly matched when the output has already been
22219 -- matched in a previous clause.
22220
22221 -- Depends => (Output => State) -- implicitly OK
22222 -- Refined_State => (State => null)
22223 -- Refined_Depends => (Output => ...)
22224
22225 if not Clause_Matched
22226 and then Is_Null_Refined_State (Dep_Input)
22227 and then Is_Entity_Name (Dep_Output)
22228 and then
22229 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
22230 then
22231 Clause_Matched := True;
22232 end if;
22233
22234 -- A clause where the output is an abstract state with visible null
22235 -- refinement is implicitly matched when the input has already been
22236 -- matched in a previous clause.
22237
22238 -- Depends => (State => Input) -- implicitly OK
22239 -- Refined_State => (State => null)
22240 -- Refined_Depends => (... => Input)
22241
22242 if not Clause_Matched
22243 and then Is_Null_Refined_State (Dep_Output)
22244 and then Is_Entity_Name (Dep_Input)
22245 and then
22246 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22247 then
22248 Clause_Matched := True;
22249 end if;
22250
22251 -- At this point either all refinement clauses have been examined or
22252 -- pragma Refined_Depends contains a solitary null. Only an abstract
22253 -- state with null refinement can possibly match these cases.
22254
22255 -- Depends => (State => null)
22256 -- Refined_State => (State => null)
22257 -- Refined_Depends => null -- OK
22258
22259 if not Clause_Matched then
22260 Match_Items
22261 (Dep_Item => Dep_Input,
22262 Ref_Item => Empty,
22263 Matched => Inputs_Match);
22264
22265 Match_Items
22266 (Dep_Item => Dep_Output,
22267 Ref_Item => Empty,
22268 Matched => Outputs_Match);
22269
22270 Clause_Matched := Inputs_Match and Outputs_Match;
22271 end if;
22272
22273 -- If the contents of Refined_Depends are legal, then the current
22274 -- dependence clause should be satisfied either by an explicit match
22275 -- or by one of the special cases.
22276
22277 if not Clause_Matched then
22278 SPARK_Msg_NE
22279 ("dependence clause of subprogram & has no matching refinement "
22280 & "in body", Dep_Clause, Spec_Id);
22281 end if;
22282 end Check_Dependency_Clause;
22283
22284 -----------------------
22285 -- Normalize_Clauses --
22286 -----------------------
22287
22288 procedure Normalize_Clauses (Clauses : List_Id) is
22289 procedure Normalize_Inputs (Clause : Node_Id);
22290 -- Normalize clause Clause by creating multiple clauses for each
22291 -- input item of Clause. It is assumed that Clause has exactly one
22292 -- output. The transformation is as follows:
22293 --
22294 -- Output => (Input_1, Input_2) -- original
22295 --
22296 -- Output => Input_1 -- normalizations
22297 -- Output => Input_2
22298
22299 ----------------------
22300 -- Normalize_Inputs --
22301 ----------------------
22302
22303 procedure Normalize_Inputs (Clause : Node_Id) is
22304 Inputs : constant Node_Id := Expression (Clause);
22305 Loc : constant Source_Ptr := Sloc (Clause);
22306 Output : constant List_Id := Choices (Clause);
22307 Last_Input : Node_Id;
22308 Input : Node_Id;
22309 New_Clause : Node_Id;
22310 Next_Input : Node_Id;
22311
22312 begin
22313 -- Normalization is performed only when the original clause has
22314 -- more than one input. Multiple inputs appear as an aggregate.
22315
22316 if Nkind (Inputs) = N_Aggregate then
22317 Last_Input := Last (Expressions (Inputs));
22318
22319 -- Create a new clause for each input
22320
22321 Input := First (Expressions (Inputs));
22322 while Present (Input) loop
22323 Next_Input := Next (Input);
22324
22325 -- Unhook the current input from the original input list
22326 -- because it will be relocated to a new clause.
22327
22328 Remove (Input);
22329
22330 -- Special processing for the last input. At this point the
22331 -- original aggregate has been stripped down to one element.
22332 -- Replace the aggregate by the element itself.
22333
22334 if Input = Last_Input then
22335 Rewrite (Inputs, Input);
22336
22337 -- Generate a clause of the form:
22338 -- Output => Input
22339
22340 else
22341 New_Clause :=
22342 Make_Component_Association (Loc,
22343 Choices => New_Copy_List_Tree (Output),
22344 Expression => Input);
22345
22346 -- The new clause contains replicated content that has
22347 -- already been analyzed, mark the clause as analyzed.
22348
22349 Set_Analyzed (New_Clause);
22350 Insert_After (Clause, New_Clause);
22351 end if;
22352
22353 Input := Next_Input;
22354 end loop;
22355 end if;
22356 end Normalize_Inputs;
22357
22358 -- Local variables
22359
22360 Clause : Node_Id;
22361
22362 -- Start of processing for Normalize_Clauses
22363
22364 begin
22365 Clause := First (Clauses);
22366 while Present (Clause) loop
22367 Normalize_Inputs (Clause);
22368 Next (Clause);
22369 end loop;
22370 end Normalize_Clauses;
22371
22372 --------------------------
22373 -- Report_Extra_Clauses --
22374 --------------------------
22375
22376 procedure Report_Extra_Clauses is
22377 Clause : Node_Id;
22378
22379 begin
22380 if Present (Refinements) then
22381 Clause := First (Refinements);
22382 while Present (Clause) loop
22383
22384 -- Do not complain about a null input refinement, since a null
22385 -- input legitimately matches anything.
22386
22387 if Nkind (Clause) /= N_Component_Association
22388 or else Nkind (Expression (Clause)) /= N_Null
22389 then
22390 SPARK_Msg_N
22391 ("unmatched or extra clause in dependence refinement",
22392 Clause);
22393 end if;
22394
22395 Next (Clause);
22396 end loop;
22397 end if;
22398 end Report_Extra_Clauses;
22399
22400 -- Local variables
22401
22402 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
22403 Errors : constant Nat := Serious_Errors_Detected;
22404 Refs : constant Node_Id :=
22405 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
22406 Clause : Node_Id;
22407 Deps : Node_Id;
22408
22409 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22410
22411 begin
22412 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
22413 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
22414 else
22415 Spec_Id := Corresponding_Spec (Body_Decl);
22416 end if;
22417
22418 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
22419
22420 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22421 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22422
22423 if No (Depends) then
22424 SPARK_Msg_NE
22425 ("useless refinement, declaration of subprogram & lacks aspect or "
22426 & "pragma Depends", N, Spec_Id);
22427 return;
22428 end if;
22429
22430 Deps := Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
22431
22432 -- A null dependency relation renders the refinement useless because it
22433 -- cannot possibly mention abstract states with visible refinement. Note
22434 -- that the inverse is not true as states may be refined to null
22435 -- (SPARK RM 7.2.5(2)).
22436
22437 if Nkind (Deps) = N_Null then
22438 SPARK_Msg_NE
22439 ("useless refinement, subprogram & does not depend on abstract "
22440 & "state with visible refinement", N, Spec_Id);
22441 return;
22442 end if;
22443
22444 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
22445 -- This ensures that the categorization of all refined dependency items
22446 -- is consistent with their role.
22447
22448 Analyze_Depends_In_Decl_Part (N);
22449
22450 -- Do not match dependencies against refinements if Refined_Depends is
22451 -- illegal to avoid emitting misleading error.
22452
22453 if Serious_Errors_Detected = Errors then
22454
22455 -- Multiple dependency clauses appear as component associations of an
22456 -- aggregate. Note that the clauses are copied because the algorithm
22457 -- modifies them and this should not be visible in Depends.
22458
22459 pragma Assert (Nkind (Deps) = N_Aggregate);
22460 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
22461 Normalize_Clauses (Dependencies);
22462
22463 if Nkind (Refs) = N_Null then
22464 Refinements := No_List;
22465
22466 -- Multiple dependency clauses appear as component associations of an
22467 -- aggregate. Note that the clauses are copied because the algorithm
22468 -- modifies them and this should not be visible in Refined_Depends.
22469
22470 else pragma Assert (Nkind (Refs) = N_Aggregate);
22471 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
22472 Normalize_Clauses (Refinements);
22473 end if;
22474
22475 -- At this point the clauses of pragmas Depends and Refined_Depends
22476 -- have been normalized into simple dependencies between one output
22477 -- and one input. Examine all clauses of pragma Depends looking for
22478 -- matching clauses in pragma Refined_Depends.
22479
22480 Clause := First (Dependencies);
22481 while Present (Clause) loop
22482 Check_Dependency_Clause (Clause);
22483 Next (Clause);
22484 end loop;
22485
22486 if Serious_Errors_Detected = Errors then
22487 Report_Extra_Clauses;
22488 end if;
22489 end if;
22490 end Analyze_Refined_Depends_In_Decl_Part;
22491
22492 -----------------------------------------
22493 -- Analyze_Refined_Global_In_Decl_Part --
22494 -----------------------------------------
22495
22496 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
22497 Global : Node_Id;
22498 -- The corresponding Global pragma
22499
22500 Has_In_State : Boolean := False;
22501 Has_In_Out_State : Boolean := False;
22502 Has_Out_State : Boolean := False;
22503 Has_Proof_In_State : Boolean := False;
22504 -- These flags are set when the corresponding Global pragma has a state
22505 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
22506 -- refinement.
22507
22508 Has_Null_State : Boolean := False;
22509 -- This flag is set when the corresponding Global pragma has at least
22510 -- one state with a null refinement.
22511
22512 In_Constits : Elist_Id := No_Elist;
22513 In_Out_Constits : Elist_Id := No_Elist;
22514 Out_Constits : Elist_Id := No_Elist;
22515 Proof_In_Constits : Elist_Id := No_Elist;
22516 -- These lists contain the entities of all Input, In_Out, Output and
22517 -- Proof_In constituents that appear in Refined_Global and participate
22518 -- in state refinement.
22519
22520 In_Items : Elist_Id := No_Elist;
22521 In_Out_Items : Elist_Id := No_Elist;
22522 Out_Items : Elist_Id := No_Elist;
22523 Proof_In_Items : Elist_Id := No_Elist;
22524 -- These list contain the entities of all Input, In_Out, Output and
22525 -- Proof_In items defined in the corresponding Global pragma.
22526
22527 procedure Check_In_Out_States;
22528 -- Determine whether the corresponding Global pragma mentions In_Out
22529 -- states with visible refinement and if so, ensure that one of the
22530 -- following completions apply to the constituents of the state:
22531 -- 1) there is at least one constituent of mode In_Out
22532 -- 2) there is at least one Input and one Output constituent
22533 -- 3) not all constituents are present and one of them is of mode
22534 -- Output.
22535 -- This routine may remove elements from In_Constits, In_Out_Constits,
22536 -- Out_Constits and Proof_In_Constits.
22537
22538 procedure Check_Input_States;
22539 -- Determine whether the corresponding Global pragma mentions Input
22540 -- states with visible refinement and if so, ensure that at least one of
22541 -- its constituents appears as an Input item in Refined_Global.
22542 -- This routine may remove elements from In_Constits, In_Out_Constits,
22543 -- Out_Constits and Proof_In_Constits.
22544
22545 procedure Check_Output_States;
22546 -- Determine whether the corresponding Global pragma mentions Output
22547 -- states with visible refinement and if so, ensure that all of its
22548 -- constituents appear as Output items in Refined_Global.
22549 -- This routine may remove elements from In_Constits, In_Out_Constits,
22550 -- Out_Constits and Proof_In_Constits.
22551
22552 procedure Check_Proof_In_States;
22553 -- Determine whether the corresponding Global pragma mentions Proof_In
22554 -- states with visible refinement and if so, ensure that at least one of
22555 -- its constituents appears as a Proof_In item in Refined_Global.
22556 -- This routine may remove elements from In_Constits, In_Out_Constits,
22557 -- Out_Constits and Proof_In_Constits.
22558
22559 procedure Check_Refined_Global_List
22560 (List : Node_Id;
22561 Global_Mode : Name_Id := Name_Input);
22562 -- Verify the legality of a single global list declaration. Global_Mode
22563 -- denotes the current mode in effect.
22564
22565 function Present_Then_Remove
22566 (List : Elist_Id;
22567 Item : Entity_Id) return Boolean;
22568 -- Search List for a particular entity Item. If Item has been found,
22569 -- remove it from List. This routine is used to strip lists In_Constits,
22570 -- In_Out_Constits and Out_Constits of valid constituents.
22571
22572 procedure Report_Extra_Constituents;
22573 -- Emit an error for each constituent found in lists In_Constits,
22574 -- In_Out_Constits and Out_Constits.
22575
22576 -------------------------
22577 -- Check_In_Out_States --
22578 -------------------------
22579
22580 procedure Check_In_Out_States is
22581 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22582 -- Determine whether one of the following coverage scenarios is in
22583 -- effect:
22584 -- 1) there is at least one constituent of mode In_Out
22585 -- 2) there is at least one Input and one Output constituent
22586 -- 3) not all constituents are present and one of them is of mode
22587 -- Output.
22588 -- If this is not the case, emit an error.
22589
22590 -----------------------------
22591 -- Check_Constituent_Usage --
22592 -----------------------------
22593
22594 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22595 Constit_Elmt : Elmt_Id;
22596 Constit_Id : Entity_Id;
22597 Has_Missing : Boolean := False;
22598 In_Out_Seen : Boolean := False;
22599 In_Seen : Boolean := False;
22600 Out_Seen : Boolean := False;
22601
22602 begin
22603 -- Process all the constituents of the state and note their modes
22604 -- within the global refinement.
22605
22606 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22607 while Present (Constit_Elmt) loop
22608 Constit_Id := Node (Constit_Elmt);
22609
22610 if Present_Then_Remove (In_Constits, Constit_Id) then
22611 In_Seen := True;
22612
22613 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
22614 In_Out_Seen := True;
22615
22616 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
22617 Out_Seen := True;
22618
22619 -- A Proof_In constituent cannot participate in the completion
22620 -- of an Output state (SPARK RM 7.2.4(5)).
22621
22622 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22623 Error_Msg_Name_1 := Chars (State_Id);
22624 SPARK_Msg_NE
22625 ("constituent & of state % must have mode Input, In_Out "
22626 & "or Output in global refinement",
22627 N, Constit_Id);
22628
22629 else
22630 Has_Missing := True;
22631 end if;
22632
22633 Next_Elmt (Constit_Elmt);
22634 end loop;
22635
22636 -- A single In_Out constituent is a valid completion
22637
22638 if In_Out_Seen then
22639 null;
22640
22641 -- A pair of one Input and one Output constituent is a valid
22642 -- completion.
22643
22644 elsif In_Seen and then Out_Seen then
22645 null;
22646
22647 -- A single Output constituent is a valid completion only when
22648 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
22649
22650 elsif Has_Missing and then Out_Seen then
22651 null;
22652
22653 else
22654 SPARK_Msg_NE
22655 ("global refinement of state & redefines the mode of its "
22656 & "constituents", N, State_Id);
22657 end if;
22658 end Check_Constituent_Usage;
22659
22660 -- Local variables
22661
22662 Item_Elmt : Elmt_Id;
22663 Item_Id : Entity_Id;
22664
22665 -- Start of processing for Check_In_Out_States
22666
22667 begin
22668 -- Inspect the In_Out items of the corresponding Global pragma
22669 -- looking for a state with a visible refinement.
22670
22671 if Has_In_Out_State and then Present (In_Out_Items) then
22672 Item_Elmt := First_Elmt (In_Out_Items);
22673 while Present (Item_Elmt) loop
22674 Item_Id := Node (Item_Elmt);
22675
22676 -- Ensure that one of the three coverage variants is satisfied
22677
22678 if Ekind (Item_Id) = E_Abstract_State
22679 and then Has_Non_Null_Refinement (Item_Id)
22680 then
22681 Check_Constituent_Usage (Item_Id);
22682 end if;
22683
22684 Next_Elmt (Item_Elmt);
22685 end loop;
22686 end if;
22687 end Check_In_Out_States;
22688
22689 ------------------------
22690 -- Check_Input_States --
22691 ------------------------
22692
22693 procedure Check_Input_States is
22694 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22695 -- Determine whether at least one constituent of state State_Id with
22696 -- visible refinement is used and has mode Input. Ensure that the
22697 -- remaining constituents do not have In_Out, Output or Proof_In
22698 -- modes.
22699
22700 -----------------------------
22701 -- Check_Constituent_Usage --
22702 -----------------------------
22703
22704 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22705 Constit_Elmt : Elmt_Id;
22706 Constit_Id : Entity_Id;
22707 In_Seen : Boolean := False;
22708
22709 begin
22710 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22711 while Present (Constit_Elmt) loop
22712 Constit_Id := Node (Constit_Elmt);
22713
22714 -- At least one of the constituents appears as an Input
22715
22716 if Present_Then_Remove (In_Constits, Constit_Id) then
22717 In_Seen := True;
22718
22719 -- The constituent appears in the global refinement, but has
22720 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
22721
22722 elsif Present_Then_Remove (In_Out_Constits, Constit_Id)
22723 or else Present_Then_Remove (Out_Constits, Constit_Id)
22724 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22725 then
22726 Error_Msg_Name_1 := Chars (State_Id);
22727 SPARK_Msg_NE
22728 ("constituent & of state % must have mode Input in global "
22729 & "refinement", N, Constit_Id);
22730 end if;
22731
22732 Next_Elmt (Constit_Elmt);
22733 end loop;
22734
22735 -- Not one of the constituents appeared as Input
22736
22737 if not In_Seen then
22738 SPARK_Msg_NE
22739 ("global refinement of state & must include at least one "
22740 & "constituent of mode Input", N, State_Id);
22741 end if;
22742 end Check_Constituent_Usage;
22743
22744 -- Local variables
22745
22746 Item_Elmt : Elmt_Id;
22747 Item_Id : Entity_Id;
22748
22749 -- Start of processing for Check_Input_States
22750
22751 begin
22752 -- Inspect the Input items of the corresponding Global pragma
22753 -- looking for a state with a visible refinement.
22754
22755 if Has_In_State and then Present (In_Items) then
22756 Item_Elmt := First_Elmt (In_Items);
22757 while Present (Item_Elmt) loop
22758 Item_Id := Node (Item_Elmt);
22759
22760 -- Ensure that at least one of the constituents is utilized and
22761 -- is of mode Input.
22762
22763 if Ekind (Item_Id) = E_Abstract_State
22764 and then Has_Non_Null_Refinement (Item_Id)
22765 then
22766 Check_Constituent_Usage (Item_Id);
22767 end if;
22768
22769 Next_Elmt (Item_Elmt);
22770 end loop;
22771 end if;
22772 end Check_Input_States;
22773
22774 -------------------------
22775 -- Check_Output_States --
22776 -------------------------
22777
22778 procedure Check_Output_States is
22779 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22780 -- Determine whether all constituents of state State_Id with visible
22781 -- refinement are used and have mode Output. Emit an error if this is
22782 -- not the case.
22783
22784 -----------------------------
22785 -- Check_Constituent_Usage --
22786 -----------------------------
22787
22788 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22789 Constit_Elmt : Elmt_Id;
22790 Constit_Id : Entity_Id;
22791 Posted : Boolean := False;
22792
22793 begin
22794 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22795 while Present (Constit_Elmt) loop
22796 Constit_Id := Node (Constit_Elmt);
22797
22798 if Present_Then_Remove (Out_Constits, Constit_Id) then
22799 null;
22800
22801 -- The constituent appears in the global refinement, but has
22802 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
22803
22804 elsif Present_Then_Remove (In_Constits, Constit_Id)
22805 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22806 or else Present_Then_Remove (Proof_In_Constits, Constit_Id)
22807 then
22808 Error_Msg_Name_1 := Chars (State_Id);
22809 SPARK_Msg_NE
22810 ("constituent & of state % must have mode Output in "
22811 & "global refinement", N, Constit_Id);
22812
22813 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22814
22815 else
22816 if not Posted then
22817 Posted := True;
22818 SPARK_Msg_NE
22819 ("output state & must be replaced by all its "
22820 & "constituents in global refinement", N, State_Id);
22821 end if;
22822
22823 SPARK_Msg_NE
22824 ("\constituent & is missing in output list",
22825 N, Constit_Id);
22826 end if;
22827
22828 Next_Elmt (Constit_Elmt);
22829 end loop;
22830 end Check_Constituent_Usage;
22831
22832 -- Local variables
22833
22834 Item_Elmt : Elmt_Id;
22835 Item_Id : Entity_Id;
22836
22837 -- Start of processing for Check_Output_States
22838
22839 begin
22840 -- Inspect the Output items of the corresponding Global pragma
22841 -- looking for a state with a visible refinement.
22842
22843 if Has_Out_State and then Present (Out_Items) then
22844 Item_Elmt := First_Elmt (Out_Items);
22845 while Present (Item_Elmt) loop
22846 Item_Id := Node (Item_Elmt);
22847
22848 -- Ensure that all of the constituents are utilized and they
22849 -- have mode Output.
22850
22851 if Ekind (Item_Id) = E_Abstract_State
22852 and then Has_Non_Null_Refinement (Item_Id)
22853 then
22854 Check_Constituent_Usage (Item_Id);
22855 end if;
22856
22857 Next_Elmt (Item_Elmt);
22858 end loop;
22859 end if;
22860 end Check_Output_States;
22861
22862 ---------------------------
22863 -- Check_Proof_In_States --
22864 ---------------------------
22865
22866 procedure Check_Proof_In_States is
22867 procedure Check_Constituent_Usage (State_Id : Entity_Id);
22868 -- Determine whether at least one constituent of state State_Id with
22869 -- visible refinement is used and has mode Proof_In. Ensure that the
22870 -- remaining constituents do not have Input, In_Out or Output modes.
22871
22872 -----------------------------
22873 -- Check_Constituent_Usage --
22874 -----------------------------
22875
22876 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22877 Constit_Elmt : Elmt_Id;
22878 Constit_Id : Entity_Id;
22879 Proof_In_Seen : Boolean := False;
22880
22881 begin
22882 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22883 while Present (Constit_Elmt) loop
22884 Constit_Id := Node (Constit_Elmt);
22885
22886 -- At least one of the constituents appears as Proof_In
22887
22888 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22889 Proof_In_Seen := True;
22890
22891 -- The constituent appears in the global refinement, but has
22892 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
22893
22894 elsif Present_Then_Remove (In_Constits, Constit_Id)
22895 or else Present_Then_Remove (In_Out_Constits, Constit_Id)
22896 or else Present_Then_Remove (Out_Constits, Constit_Id)
22897 then
22898 Error_Msg_Name_1 := Chars (State_Id);
22899 SPARK_Msg_NE
22900 ("constituent & of state % must have mode Proof_In in "
22901 & "global refinement", N, Constit_Id);
22902 end if;
22903
22904 Next_Elmt (Constit_Elmt);
22905 end loop;
22906
22907 -- Not one of the constituents appeared as Proof_In
22908
22909 if not Proof_In_Seen then
22910 SPARK_Msg_NE
22911 ("global refinement of state & must include at least one "
22912 & "constituent of mode Proof_In", N, State_Id);
22913 end if;
22914 end Check_Constituent_Usage;
22915
22916 -- Local variables
22917
22918 Item_Elmt : Elmt_Id;
22919 Item_Id : Entity_Id;
22920
22921 -- Start of processing for Check_Proof_In_States
22922
22923 begin
22924 -- Inspect the Proof_In items of the corresponding Global pragma
22925 -- looking for a state with a visible refinement.
22926
22927 if Has_Proof_In_State and then Present (Proof_In_Items) then
22928 Item_Elmt := First_Elmt (Proof_In_Items);
22929 while Present (Item_Elmt) loop
22930 Item_Id := Node (Item_Elmt);
22931
22932 -- Ensure that at least one of the constituents is utilized and
22933 -- is of mode Proof_In
22934
22935 if Ekind (Item_Id) = E_Abstract_State
22936 and then Has_Non_Null_Refinement (Item_Id)
22937 then
22938 Check_Constituent_Usage (Item_Id);
22939 end if;
22940
22941 Next_Elmt (Item_Elmt);
22942 end loop;
22943 end if;
22944 end Check_Proof_In_States;
22945
22946 -------------------------------
22947 -- Check_Refined_Global_List --
22948 -------------------------------
22949
22950 procedure Check_Refined_Global_List
22951 (List : Node_Id;
22952 Global_Mode : Name_Id := Name_Input)
22953 is
22954 procedure Check_Refined_Global_Item
22955 (Item : Node_Id;
22956 Global_Mode : Name_Id);
22957 -- Verify the legality of a single global item declaration. Parameter
22958 -- Global_Mode denotes the current mode in effect.
22959
22960 -------------------------------
22961 -- Check_Refined_Global_Item --
22962 -------------------------------
22963
22964 procedure Check_Refined_Global_Item
22965 (Item : Node_Id;
22966 Global_Mode : Name_Id)
22967 is
22968 Item_Id : constant Entity_Id := Entity_Of (Item);
22969
22970 procedure Inconsistent_Mode_Error (Expect : Name_Id);
22971 -- Issue a common error message for all mode mismatches. Expect
22972 -- denotes the expected mode.
22973
22974 -----------------------------
22975 -- Inconsistent_Mode_Error --
22976 -----------------------------
22977
22978 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
22979 begin
22980 SPARK_Msg_NE
22981 ("global item & has inconsistent modes", Item, Item_Id);
22982
22983 Error_Msg_Name_1 := Global_Mode;
22984 Error_Msg_Name_2 := Expect;
22985 SPARK_Msg_N ("\expected mode %, found mode %", Item);
22986 end Inconsistent_Mode_Error;
22987
22988 -- Start of processing for Check_Refined_Global_Item
22989
22990 begin
22991 -- When the state or variable acts as a constituent of another
22992 -- state with a visible refinement, collect it for the state
22993 -- completeness checks performed later on.
22994
22995 if Present (Encapsulating_State (Item_Id))
22996 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
22997 then
22998 if Global_Mode = Name_Input then
22999 Add_Item (Item_Id, In_Constits);
23000
23001 elsif Global_Mode = Name_In_Out then
23002 Add_Item (Item_Id, In_Out_Constits);
23003
23004 elsif Global_Mode = Name_Output then
23005 Add_Item (Item_Id, Out_Constits);
23006
23007 elsif Global_Mode = Name_Proof_In then
23008 Add_Item (Item_Id, Proof_In_Constits);
23009 end if;
23010
23011 -- When not a constituent, ensure that both occurrences of the
23012 -- item in pragmas Global and Refined_Global match.
23013
23014 elsif Contains (In_Items, Item_Id) then
23015 if Global_Mode /= Name_Input then
23016 Inconsistent_Mode_Error (Name_Input);
23017 end if;
23018
23019 elsif Contains (In_Out_Items, Item_Id) then
23020 if Global_Mode /= Name_In_Out then
23021 Inconsistent_Mode_Error (Name_In_Out);
23022 end if;
23023
23024 elsif Contains (Out_Items, Item_Id) then
23025 if Global_Mode /= Name_Output then
23026 Inconsistent_Mode_Error (Name_Output);
23027 end if;
23028
23029 elsif Contains (Proof_In_Items, Item_Id) then
23030 null;
23031
23032 -- The item does not appear in the corresponding Global pragma,
23033 -- it must be an extra (SPARK RM 7.2.4(3)).
23034
23035 else
23036 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
23037 end if;
23038 end Check_Refined_Global_Item;
23039
23040 -- Local variables
23041
23042 Item : Node_Id;
23043
23044 -- Start of processing for Check_Refined_Global_List
23045
23046 begin
23047 if Nkind (List) = N_Null then
23048 null;
23049
23050 -- Single global item declaration
23051
23052 elsif Nkind_In (List, N_Expanded_Name,
23053 N_Identifier,
23054 N_Selected_Component)
23055 then
23056 Check_Refined_Global_Item (List, Global_Mode);
23057
23058 -- Simple global list or moded global list declaration
23059
23060 elsif Nkind (List) = N_Aggregate then
23061
23062 -- The declaration of a simple global list appear as a collection
23063 -- of expressions.
23064
23065 if Present (Expressions (List)) then
23066 Item := First (Expressions (List));
23067 while Present (Item) loop
23068 Check_Refined_Global_Item (Item, Global_Mode);
23069
23070 Next (Item);
23071 end loop;
23072
23073 -- The declaration of a moded global list appears as a collection
23074 -- of component associations where individual choices denote
23075 -- modes.
23076
23077 elsif Present (Component_Associations (List)) then
23078 Item := First (Component_Associations (List));
23079 while Present (Item) loop
23080 Check_Refined_Global_List
23081 (List => Expression (Item),
23082 Global_Mode => Chars (First (Choices (Item))));
23083
23084 Next (Item);
23085 end loop;
23086
23087 -- Invalid tree
23088
23089 else
23090 raise Program_Error;
23091 end if;
23092
23093 -- Invalid list
23094
23095 else
23096 raise Program_Error;
23097 end if;
23098 end Check_Refined_Global_List;
23099
23100 -------------------------
23101 -- Present_Then_Remove --
23102 -------------------------
23103
23104 function Present_Then_Remove
23105 (List : Elist_Id;
23106 Item : Entity_Id) return Boolean
23107 is
23108 Elmt : Elmt_Id;
23109
23110 begin
23111 if Present (List) then
23112 Elmt := First_Elmt (List);
23113 while Present (Elmt) loop
23114 if Node (Elmt) = Item then
23115 Remove_Elmt (List, Elmt);
23116 return True;
23117 end if;
23118
23119 Next_Elmt (Elmt);
23120 end loop;
23121 end if;
23122
23123 return False;
23124 end Present_Then_Remove;
23125
23126 -------------------------------
23127 -- Report_Extra_Constituents --
23128 -------------------------------
23129
23130 procedure Report_Extra_Constituents is
23131 procedure Report_Extra_Constituents_In_List (List : Elist_Id);
23132 -- Emit an error for every element of List
23133
23134 ---------------------------------------
23135 -- Report_Extra_Constituents_In_List --
23136 ---------------------------------------
23137
23138 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
23139 Constit_Elmt : Elmt_Id;
23140
23141 begin
23142 if Present (List) then
23143 Constit_Elmt := First_Elmt (List);
23144 while Present (Constit_Elmt) loop
23145 SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt));
23146 Next_Elmt (Constit_Elmt);
23147 end loop;
23148 end if;
23149 end Report_Extra_Constituents_In_List;
23150
23151 -- Start of processing for Report_Extra_Constituents
23152
23153 begin
23154 Report_Extra_Constituents_In_List (In_Constits);
23155 Report_Extra_Constituents_In_List (In_Out_Constits);
23156 Report_Extra_Constituents_In_List (Out_Constits);
23157 Report_Extra_Constituents_In_List (Proof_In_Constits);
23158 end Report_Extra_Constituents;
23159
23160 -- Local variables
23161
23162 Body_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
23163 Errors : constant Nat := Serious_Errors_Detected;
23164 Items : constant Node_Id :=
23165 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
23166 Spec_Id : Entity_Id;
23167
23168 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23169
23170 begin
23171 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
23172 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
23173 else
23174 Spec_Id := Corresponding_Spec (Body_Decl);
23175 end if;
23176
23177 Global := Get_Pragma (Spec_Id, Pragma_Global);
23178
23179 -- The subprogram declaration lacks pragma Global. This renders
23180 -- Refined_Global useless as there is nothing to refine.
23181
23182 if No (Global) then
23183 SPARK_Msg_NE
23184 ("useless refinement, declaration of subprogram & lacks aspect or "
23185 & "pragma Global", N, Spec_Id);
23186 return;
23187 end if;
23188
23189 -- Extract all relevant items from the corresponding Global pragma
23190
23191 Collect_Global_Items
23192 (Prag => Global,
23193 In_Items => In_Items,
23194 In_Out_Items => In_Out_Items,
23195 Out_Items => Out_Items,
23196 Proof_In_Items => Proof_In_Items,
23197 Has_In_State => Has_In_State,
23198 Has_In_Out_State => Has_In_Out_State,
23199 Has_Out_State => Has_Out_State,
23200 Has_Proof_In_State => Has_Proof_In_State,
23201 Has_Null_State => Has_Null_State);
23202
23203 -- Corresponding Global pragma must mention at least one state witha
23204 -- visible refinement at the point Refined_Global is processed. States
23205 -- with null refinements need Refined_Global pragma (SPARK RM 7.2.4(2)).
23206
23207 if not Has_In_State
23208 and then not Has_In_Out_State
23209 and then not Has_Out_State
23210 and then not Has_Proof_In_State
23211 and then not Has_Null_State
23212 then
23213 SPARK_Msg_NE
23214 ("useless refinement, subprogram & does not depend on abstract "
23215 & "state with visible refinement", N, Spec_Id);
23216 return;
23217 end if;
23218
23219 -- The global refinement of inputs and outputs cannot be null when the
23220 -- corresponding Global pragma contains at least one item except in the
23221 -- case where we have states with null refinements.
23222
23223 if Nkind (Items) = N_Null
23224 and then
23225 (Present (In_Items)
23226 or else Present (In_Out_Items)
23227 or else Present (Out_Items)
23228 or else Present (Proof_In_Items))
23229 and then not Has_Null_State
23230 then
23231 SPARK_Msg_NE
23232 ("refinement cannot be null, subprogram & has global items",
23233 N, Spec_Id);
23234 return;
23235 end if;
23236
23237 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
23238 -- This ensures that the categorization of all refined global items is
23239 -- consistent with their role.
23240
23241 Analyze_Global_In_Decl_Part (N);
23242
23243 -- Perform all refinement checks with respect to completeness and mode
23244 -- matching.
23245
23246 if Serious_Errors_Detected = Errors then
23247 Check_Refined_Global_List (Items);
23248 end if;
23249
23250 -- For Input states with visible refinement, at least one constituent
23251 -- must be used as an Input in the global refinement.
23252
23253 if Serious_Errors_Detected = Errors then
23254 Check_Input_States;
23255 end if;
23256
23257 -- Verify all possible completion variants for In_Out states with
23258 -- visible refinement.
23259
23260 if Serious_Errors_Detected = Errors then
23261 Check_In_Out_States;
23262 end if;
23263
23264 -- For Output states with visible refinement, all constituents must be
23265 -- used as Outputs in the global refinement.
23266
23267 if Serious_Errors_Detected = Errors then
23268 Check_Output_States;
23269 end if;
23270
23271 -- For Proof_In states with visible refinement, at least one constituent
23272 -- must be used as Proof_In in the global refinement.
23273
23274 if Serious_Errors_Detected = Errors then
23275 Check_Proof_In_States;
23276 end if;
23277
23278 -- Emit errors for all constituents that belong to other states with
23279 -- visible refinement that do not appear in Global.
23280
23281 if Serious_Errors_Detected = Errors then
23282 Report_Extra_Constituents;
23283 end if;
23284 end Analyze_Refined_Global_In_Decl_Part;
23285
23286 ----------------------------------------
23287 -- Analyze_Refined_State_In_Decl_Part --
23288 ----------------------------------------
23289
23290 procedure Analyze_Refined_State_In_Decl_Part (N : Node_Id) is
23291 Available_States : Elist_Id := No_Elist;
23292 -- A list of all abstract states defined in the package declaration that
23293 -- are available for refinement. The list is used to report unrefined
23294 -- states.
23295
23296 Body_Id : Entity_Id;
23297 -- The body entity of the package subject to pragma Refined_State
23298
23299 Body_States : Elist_Id := No_Elist;
23300 -- A list of all hidden states that appear in the body of the related
23301 -- package. The list is used to report unused hidden states.
23302
23303 Constituents_Seen : Elist_Id := No_Elist;
23304 -- A list that contains all constituents processed so far. The list is
23305 -- used to detect multiple uses of the same constituent.
23306
23307 Refined_States_Seen : Elist_Id := No_Elist;
23308 -- A list that contains all refined states processed so far. The list is
23309 -- used to detect duplicate refinements.
23310
23311 Spec_Id : Entity_Id;
23312 -- The spec entity of the package subject to pragma Refined_State
23313
23314 procedure Analyze_Refinement_Clause (Clause : Node_Id);
23315 -- Perform full analysis of a single refinement clause
23316
23317 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id;
23318 -- Gather the entities of all abstract states and variables declared in
23319 -- the body state space of package Pack_Id.
23320
23321 procedure Report_Unrefined_States (States : Elist_Id);
23322 -- Emit errors for all unrefined abstract states found in list States
23323
23324 procedure Report_Unused_States (States : Elist_Id);
23325 -- Emit errors for all unused states found in list States
23326
23327 -------------------------------
23328 -- Analyze_Refinement_Clause --
23329 -------------------------------
23330
23331 procedure Analyze_Refinement_Clause (Clause : Node_Id) is
23332 AR_Constit : Entity_Id := Empty;
23333 AW_Constit : Entity_Id := Empty;
23334 ER_Constit : Entity_Id := Empty;
23335 EW_Constit : Entity_Id := Empty;
23336 -- The entities of external constituents that contain one of the
23337 -- following enabled properties: Async_Readers, Async_Writers,
23338 -- Effective_Reads and Effective_Writes.
23339
23340 External_Constit_Seen : Boolean := False;
23341 -- Flag used to mark when at least one external constituent is part
23342 -- of the state refinement.
23343
23344 Non_Null_Seen : Boolean := False;
23345 Null_Seen : Boolean := False;
23346 -- Flags used to detect multiple uses of null in a single clause or a
23347 -- mixture of null and non-null constituents.
23348
23349 Part_Of_Constits : Elist_Id := No_Elist;
23350 -- A list of all candidate constituents subject to indicator Part_Of
23351 -- where the encapsulating state is the current state.
23352
23353 State : Node_Id;
23354 State_Id : Entity_Id;
23355 -- The current state being refined
23356
23357 procedure Analyze_Constituent (Constit : Node_Id);
23358 -- Perform full analysis of a single constituent
23359
23360 procedure Check_External_Property
23361 (Prop_Nam : Name_Id;
23362 Enabled : Boolean;
23363 Constit : Entity_Id);
23364 -- Determine whether a property denoted by name Prop_Nam is present
23365 -- in both the refined state and constituent Constit. Flag Enabled
23366 -- should be set when the property applies to the refined state. If
23367 -- this is not the case, emit an error message.
23368
23369 procedure Check_Matching_State;
23370 -- Determine whether the state being refined appears in list
23371 -- Available_States. Emit an error when attempting to re-refine the
23372 -- state or when the state is not defined in the package declaration,
23373 -- otherwise remove the state from Available_States.
23374
23375 procedure Report_Unused_Constituents (Constits : Elist_Id);
23376 -- Emit errors for all unused Part_Of constituents in list Constits
23377
23378 -------------------------
23379 -- Analyze_Constituent --
23380 -------------------------
23381
23382 procedure Analyze_Constituent (Constit : Node_Id) is
23383 procedure Check_Matching_Constituent (Constit_Id : Entity_Id);
23384 -- Determine whether constituent Constit denoted by its entity
23385 -- Constit_Id appears in Hidden_States. Emit an error when the
23386 -- constituent is not a valid hidden state of the related package
23387 -- or when it is used more than once. Otherwise remove the
23388 -- constituent from Hidden_States.
23389
23390 --------------------------------
23391 -- Check_Matching_Constituent --
23392 --------------------------------
23393
23394 procedure Check_Matching_Constituent (Constit_Id : Entity_Id) is
23395 procedure Collect_Constituent;
23396 -- Add constituent Constit_Id to the refinements of State_Id
23397
23398 -------------------------
23399 -- Collect_Constituent --
23400 -------------------------
23401
23402 procedure Collect_Constituent is
23403 begin
23404 -- Add the constituent to the list of processed items to aid
23405 -- with the detection of duplicates.
23406
23407 Add_Item (Constit_Id, Constituents_Seen);
23408
23409 -- Collect the constituent in the list of refinement items
23410 -- and establish a relation between the refined state and
23411 -- the item.
23412
23413 Append_Elmt (Constit_Id, Refinement_Constituents (State_Id));
23414 Set_Encapsulating_State (Constit_Id, State_Id);
23415
23416 -- The state has at least one legal constituent, mark the
23417 -- start of the refinement region. The region ends when the
23418 -- body declarations end (see routine Analyze_Declarations).
23419
23420 Set_Has_Visible_Refinement (State_Id);
23421
23422 -- When the constituent is external, save its relevant
23423 -- property for further checks.
23424
23425 if Async_Readers_Enabled (Constit_Id) then
23426 AR_Constit := Constit_Id;
23427 External_Constit_Seen := True;
23428 end if;
23429
23430 if Async_Writers_Enabled (Constit_Id) then
23431 AW_Constit := Constit_Id;
23432 External_Constit_Seen := True;
23433 end if;
23434
23435 if Effective_Reads_Enabled (Constit_Id) then
23436 ER_Constit := Constit_Id;
23437 External_Constit_Seen := True;
23438 end if;
23439
23440 if Effective_Writes_Enabled (Constit_Id) then
23441 EW_Constit := Constit_Id;
23442 External_Constit_Seen := True;
23443 end if;
23444 end Collect_Constituent;
23445
23446 -- Local variables
23447
23448 State_Elmt : Elmt_Id;
23449
23450 -- Start of processing for Check_Matching_Constituent
23451
23452 begin
23453 -- Detect a duplicate use of a constituent
23454
23455 if Contains (Constituents_Seen, Constit_Id) then
23456 SPARK_Msg_NE
23457 ("duplicate use of constituent &", Constit, Constit_Id);
23458 return;
23459 end if;
23460
23461 -- The constituent is subject to a Part_Of indicator
23462
23463 if Present (Encapsulating_State (Constit_Id)) then
23464 if Encapsulating_State (Constit_Id) = State_Id then
23465 Remove (Part_Of_Constits, Constit_Id);
23466 Collect_Constituent;
23467
23468 -- The constituent is part of another state and is used
23469 -- incorrectly in the refinement of the current state.
23470
23471 else
23472 Error_Msg_Name_1 := Chars (State_Id);
23473 SPARK_Msg_NE
23474 ("& cannot act as constituent of state %",
23475 Constit, Constit_Id);
23476 SPARK_Msg_NE
23477 ("\Part_Of indicator specifies & as encapsulating "
23478 & "state", Constit, Encapsulating_State (Constit_Id));
23479 end if;
23480
23481 -- The only other source of legal constituents is the body
23482 -- state space of the related package.
23483
23484 else
23485 if Present (Body_States) then
23486 State_Elmt := First_Elmt (Body_States);
23487 while Present (State_Elmt) loop
23488
23489 -- Consume a valid constituent to signal that it has
23490 -- been encountered.
23491
23492 if Node (State_Elmt) = Constit_Id then
23493 Remove_Elmt (Body_States, State_Elmt);
23494 Collect_Constituent;
23495 return;
23496 end if;
23497
23498 Next_Elmt (State_Elmt);
23499 end loop;
23500 end if;
23501
23502 -- If we get here, then the constituent is not a hidden
23503 -- state of the related package and may not be used in a
23504 -- refinement (SPARK RM 7.2.2(9)).
23505
23506 Error_Msg_Name_1 := Chars (Spec_Id);
23507 SPARK_Msg_NE
23508 ("cannot use & in refinement, constituent is not a hidden "
23509 & "state of package %", Constit, Constit_Id);
23510 end if;
23511 end Check_Matching_Constituent;
23512
23513 -- Local variables
23514
23515 Constit_Id : Entity_Id;
23516
23517 -- Start of processing for Analyze_Constituent
23518
23519 begin
23520 -- Detect multiple uses of null in a single refinement clause or a
23521 -- mixture of null and non-null constituents.
23522
23523 if Nkind (Constit) = N_Null then
23524 if Null_Seen then
23525 SPARK_Msg_N
23526 ("multiple null constituents not allowed", Constit);
23527
23528 elsif Non_Null_Seen then
23529 SPARK_Msg_N
23530 ("cannot mix null and non-null constituents", Constit);
23531
23532 else
23533 Null_Seen := True;
23534
23535 -- Collect the constituent in the list of refinement items
23536
23537 Append_Elmt (Constit, Refinement_Constituents (State_Id));
23538
23539 -- The state has at least one legal constituent, mark the
23540 -- start of the refinement region. The region ends when the
23541 -- body declarations end (see Analyze_Declarations).
23542
23543 Set_Has_Visible_Refinement (State_Id);
23544 end if;
23545
23546 -- Non-null constituents
23547
23548 else
23549 Non_Null_Seen := True;
23550
23551 if Null_Seen then
23552 SPARK_Msg_N
23553 ("cannot mix null and non-null constituents", Constit);
23554 end if;
23555
23556 Analyze (Constit);
23557 Resolve_State (Constit);
23558
23559 -- Ensure that the constituent denotes a valid state or a
23560 -- whole variable.
23561
23562 if Is_Entity_Name (Constit) then
23563 Constit_Id := Entity_Of (Constit);
23564
23565 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
23566 Check_Matching_Constituent (Constit_Id);
23567
23568 else
23569 SPARK_Msg_NE
23570 ("constituent & must denote a variable or state (SPARK "
23571 & "RM 7.2.2(5))", Constit, Constit_Id);
23572 end if;
23573
23574 -- The constituent is illegal
23575
23576 else
23577 SPARK_Msg_N ("malformed constituent", Constit);
23578 end if;
23579 end if;
23580 end Analyze_Constituent;
23581
23582 -----------------------------
23583 -- Check_External_Property --
23584 -----------------------------
23585
23586 procedure Check_External_Property
23587 (Prop_Nam : Name_Id;
23588 Enabled : Boolean;
23589 Constit : Entity_Id)
23590 is
23591 begin
23592 Error_Msg_Name_1 := Prop_Nam;
23593
23594 -- The property is enabled in the related Abstract_State pragma
23595 -- that defines the state (SPARK RM 7.2.8(3)).
23596
23597 if Enabled then
23598 if No (Constit) then
23599 SPARK_Msg_NE
23600 ("external state & requires at least one constituent with "
23601 & "property %", State, State_Id);
23602 end if;
23603
23604 -- The property is missing in the declaration of the state, but
23605 -- a constituent is introducing it in the state refinement
23606 -- (SPARK RM 7.2.8(3)).
23607
23608 elsif Present (Constit) then
23609 Error_Msg_Name_2 := Chars (Constit);
23610 SPARK_Msg_NE
23611 ("external state & lacks property % set by constituent %",
23612 State, State_Id);
23613 end if;
23614 end Check_External_Property;
23615
23616 --------------------------
23617 -- Check_Matching_State --
23618 --------------------------
23619
23620 procedure Check_Matching_State is
23621 State_Elmt : Elmt_Id;
23622
23623 begin
23624 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
23625
23626 if Contains (Refined_States_Seen, State_Id) then
23627 SPARK_Msg_NE
23628 ("duplicate refinement of state &", State, State_Id);
23629 return;
23630 end if;
23631
23632 -- Inspect the abstract states defined in the package declaration
23633 -- looking for a match.
23634
23635 State_Elmt := First_Elmt (Available_States);
23636 while Present (State_Elmt) loop
23637
23638 -- A valid abstract state is being refined in the body. Add
23639 -- the state to the list of processed refined states to aid
23640 -- with the detection of duplicate refinements. Remove the
23641 -- state from Available_States to signal that it has already
23642 -- been refined.
23643
23644 if Node (State_Elmt) = State_Id then
23645 Add_Item (State_Id, Refined_States_Seen);
23646 Remove_Elmt (Available_States, State_Elmt);
23647 return;
23648 end if;
23649
23650 Next_Elmt (State_Elmt);
23651 end loop;
23652
23653 -- If we get here, we are refining a state that is not defined in
23654 -- the package declaration.
23655
23656 Error_Msg_Name_1 := Chars (Spec_Id);
23657 SPARK_Msg_NE
23658 ("cannot refine state, & is not defined in package %",
23659 State, State_Id);
23660 end Check_Matching_State;
23661
23662 --------------------------------
23663 -- Report_Unused_Constituents --
23664 --------------------------------
23665
23666 procedure Report_Unused_Constituents (Constits : Elist_Id) is
23667 Constit_Elmt : Elmt_Id;
23668 Constit_Id : Entity_Id;
23669 Posted : Boolean := False;
23670
23671 begin
23672 if Present (Constits) then
23673 Constit_Elmt := First_Elmt (Constits);
23674 while Present (Constit_Elmt) loop
23675 Constit_Id := Node (Constit_Elmt);
23676
23677 -- Generate an error message of the form:
23678
23679 -- state ... has unused Part_Of constituents
23680 -- abstract state ... defined at ...
23681 -- variable ... defined at ...
23682
23683 if not Posted then
23684 Posted := True;
23685 SPARK_Msg_NE
23686 ("state & has unused Part_Of constituents",
23687 State, State_Id);
23688 end if;
23689
23690 Error_Msg_Sloc := Sloc (Constit_Id);
23691
23692 if Ekind (Constit_Id) = E_Abstract_State then
23693 SPARK_Msg_NE
23694 ("\abstract state & defined #", State, Constit_Id);
23695 else
23696 SPARK_Msg_NE
23697 ("\variable & defined #", State, Constit_Id);
23698 end if;
23699
23700 Next_Elmt (Constit_Elmt);
23701 end loop;
23702 end if;
23703 end Report_Unused_Constituents;
23704
23705 -- Local declarations
23706
23707 Body_Ref : Node_Id;
23708 Body_Ref_Elmt : Elmt_Id;
23709 Constit : Node_Id;
23710 Extra_State : Node_Id;
23711
23712 -- Start of processing for Analyze_Refinement_Clause
23713
23714 begin
23715 -- A refinement clause appears as a component association where the
23716 -- sole choice is the state and the expressions are the constituents.
23717 -- This is a syntax error, always report.
23718
23719 if Nkind (Clause) /= N_Component_Association then
23720 Error_Msg_N ("malformed state refinement clause", Clause);
23721 return;
23722 end if;
23723
23724 -- Analyze the state name of a refinement clause
23725
23726 State := First (Choices (Clause));
23727
23728 Analyze (State);
23729 Resolve_State (State);
23730
23731 -- Ensure that the state name denotes a valid abstract state that is
23732 -- defined in the spec of the related package.
23733
23734 if Is_Entity_Name (State) then
23735 State_Id := Entity_Of (State);
23736
23737 -- Catch any attempts to re-refine a state or refine a state that
23738 -- is not defined in the package declaration.
23739
23740 if Ekind (State_Id) = E_Abstract_State then
23741 Check_Matching_State;
23742 else
23743 SPARK_Msg_NE
23744 ("& must denote an abstract state", State, State_Id);
23745 return;
23746 end if;
23747
23748 -- References to a state with visible refinement are illegal.
23749 -- When nested packages are involved, detecting such references is
23750 -- tricky because pragma Refined_State is analyzed later than the
23751 -- offending pragma Depends or Global. References that occur in
23752 -- such nested context are stored in a list. Emit errors for all
23753 -- references found in Body_References (SPARK RM 6.1.4(8)).
23754
23755 if Present (Body_References (State_Id)) then
23756 Body_Ref_Elmt := First_Elmt (Body_References (State_Id));
23757 while Present (Body_Ref_Elmt) loop
23758 Body_Ref := Node (Body_Ref_Elmt);
23759
23760 SPARK_Msg_N ("reference to & not allowed", Body_Ref);
23761 Error_Msg_Sloc := Sloc (State);
23762 SPARK_Msg_N ("\refinement of & is visible#", Body_Ref);
23763
23764 Next_Elmt (Body_Ref_Elmt);
23765 end loop;
23766 end if;
23767
23768 -- The state name is illegal. This is a syntax error, always report.
23769
23770 else
23771 Error_Msg_N ("malformed state name in refinement clause", State);
23772 return;
23773 end if;
23774
23775 -- A refinement clause may only refine one state at a time
23776
23777 Extra_State := Next (State);
23778
23779 if Present (Extra_State) then
23780 SPARK_Msg_N
23781 ("refinement clause cannot cover multiple states", Extra_State);
23782 end if;
23783
23784 -- Replicate the Part_Of constituents of the refined state because
23785 -- the algorithm will consume items.
23786
23787 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
23788
23789 -- Analyze all constituents of the refinement. Multiple constituents
23790 -- appear as an aggregate.
23791
23792 Constit := Expression (Clause);
23793
23794 if Nkind (Constit) = N_Aggregate then
23795 if Present (Component_Associations (Constit)) then
23796 SPARK_Msg_N
23797 ("constituents of refinement clause must appear in "
23798 & "positional form", Constit);
23799
23800 else pragma Assert (Present (Expressions (Constit)));
23801 Constit := First (Expressions (Constit));
23802 while Present (Constit) loop
23803 Analyze_Constituent (Constit);
23804
23805 Next (Constit);
23806 end loop;
23807 end if;
23808
23809 -- Various forms of a single constituent. Note that these may include
23810 -- malformed constituents.
23811
23812 else
23813 Analyze_Constituent (Constit);
23814 end if;
23815
23816 -- A refined external state is subject to special rules with respect
23817 -- to its properties and constituents.
23818
23819 if Is_External_State (State_Id) then
23820
23821 -- The set of properties that all external constituents yield must
23822 -- match that of the refined state. There are two cases to detect:
23823 -- the refined state lacks a property or has an extra property.
23824
23825 if External_Constit_Seen then
23826 Check_External_Property
23827 (Prop_Nam => Name_Async_Readers,
23828 Enabled => Async_Readers_Enabled (State_Id),
23829 Constit => AR_Constit);
23830
23831 Check_External_Property
23832 (Prop_Nam => Name_Async_Writers,
23833 Enabled => Async_Writers_Enabled (State_Id),
23834 Constit => AW_Constit);
23835
23836 Check_External_Property
23837 (Prop_Nam => Name_Effective_Reads,
23838 Enabled => Effective_Reads_Enabled (State_Id),
23839 Constit => ER_Constit);
23840
23841 Check_External_Property
23842 (Prop_Nam => Name_Effective_Writes,
23843 Enabled => Effective_Writes_Enabled (State_Id),
23844 Constit => EW_Constit);
23845
23846 -- An external state may be refined to null (SPARK RM 7.2.8(2))
23847
23848 elsif Null_Seen then
23849 null;
23850
23851 -- The external state has constituents, but none of them are
23852 -- external (SPARK RM 7.2.8(2)).
23853
23854 else
23855 SPARK_Msg_NE
23856 ("external state & requires at least one external "
23857 & "constituent or null refinement", State, State_Id);
23858 end if;
23859
23860 -- When a refined state is not external, it should not have external
23861 -- constituents (SPARK RM 7.2.8(1)).
23862
23863 elsif External_Constit_Seen then
23864 SPARK_Msg_NE
23865 ("non-external state & cannot contain external constituents in "
23866 & "refinement", State, State_Id);
23867 end if;
23868
23869 -- Ensure that all Part_Of candidate constituents have been mentioned
23870 -- in the refinement clause.
23871
23872 Report_Unused_Constituents (Part_Of_Constits);
23873 end Analyze_Refinement_Clause;
23874
23875 -------------------------
23876 -- Collect_Body_States --
23877 -------------------------
23878
23879 function Collect_Body_States (Pack_Id : Entity_Id) return Elist_Id is
23880 Result : Elist_Id := No_Elist;
23881 -- A list containing all body states of Pack_Id
23882
23883 procedure Collect_Visible_States (Pack_Id : Entity_Id);
23884 -- Gather the entities of all abstract states and variables declared
23885 -- in the visible state space of package Pack_Id.
23886
23887 ----------------------------
23888 -- Collect_Visible_States --
23889 ----------------------------
23890
23891 procedure Collect_Visible_States (Pack_Id : Entity_Id) is
23892 Item_Id : Entity_Id;
23893
23894 begin
23895 -- Traverse the entity chain of the package and inspect all
23896 -- visible items.
23897
23898 Item_Id := First_Entity (Pack_Id);
23899 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
23900
23901 -- Do not consider internally generated items as those cannot
23902 -- be named and participate in refinement.
23903
23904 if not Comes_From_Source (Item_Id) then
23905 null;
23906
23907 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
23908 Add_Item (Item_Id, Result);
23909
23910 -- Recursively gather the visible states of a nested package
23911
23912 elsif Ekind (Item_Id) = E_Package then
23913 Collect_Visible_States (Item_Id);
23914 end if;
23915
23916 Next_Entity (Item_Id);
23917 end loop;
23918 end Collect_Visible_States;
23919
23920 -- Local variables
23921
23922 Pack_Body : constant Node_Id :=
23923 Declaration_Node (Body_Entity (Pack_Id));
23924 Decl : Node_Id;
23925 Item_Id : Entity_Id;
23926
23927 -- Start of processing for Collect_Body_States
23928
23929 begin
23930 -- Inspect the declarations of the body looking for source variables,
23931 -- packages and package instantiations.
23932
23933 Decl := First (Declarations (Pack_Body));
23934 while Present (Decl) loop
23935 if Nkind (Decl) = N_Object_Declaration then
23936 Item_Id := Defining_Entity (Decl);
23937
23938 -- Capture source variables only as internally generated
23939 -- temporaries cannot be named and participate in refinement.
23940
23941 if Ekind (Item_Id) = E_Variable
23942 and then Comes_From_Source (Item_Id)
23943 then
23944 Add_Item (Item_Id, Result);
23945 end if;
23946
23947 elsif Nkind (Decl) = N_Package_Declaration then
23948 Item_Id := Defining_Entity (Decl);
23949
23950 -- Capture the visible abstract states and variables of a
23951 -- source package [instantiation].
23952
23953 if Comes_From_Source (Item_Id) then
23954 Collect_Visible_States (Item_Id);
23955 end if;
23956 end if;
23957
23958 Next (Decl);
23959 end loop;
23960
23961 return Result;
23962 end Collect_Body_States;
23963
23964 -----------------------------
23965 -- Report_Unrefined_States --
23966 -----------------------------
23967
23968 procedure Report_Unrefined_States (States : Elist_Id) is
23969 State_Elmt : Elmt_Id;
23970
23971 begin
23972 if Present (States) then
23973 State_Elmt := First_Elmt (States);
23974 while Present (State_Elmt) loop
23975 SPARK_Msg_N
23976 ("abstract state & must be refined", Node (State_Elmt));
23977
23978 Next_Elmt (State_Elmt);
23979 end loop;
23980 end if;
23981 end Report_Unrefined_States;
23982
23983 --------------------------
23984 -- Report_Unused_States --
23985 --------------------------
23986
23987 procedure Report_Unused_States (States : Elist_Id) is
23988 Posted : Boolean := False;
23989 State_Elmt : Elmt_Id;
23990 State_Id : Entity_Id;
23991
23992 begin
23993 if Present (States) then
23994 State_Elmt := First_Elmt (States);
23995 while Present (State_Elmt) loop
23996 State_Id := Node (State_Elmt);
23997
23998 -- Generate an error message of the form:
23999
24000 -- body of package ... has unused hidden states
24001 -- abstract state ... defined at ...
24002 -- variable ... defined at ...
24003
24004 if not Posted then
24005 Posted := True;
24006 SPARK_Msg_N
24007 ("body of package & has unused hidden states", Body_Id);
24008 end if;
24009
24010 Error_Msg_Sloc := Sloc (State_Id);
24011
24012 if Ekind (State_Id) = E_Abstract_State then
24013 SPARK_Msg_NE
24014 ("\abstract state & defined #", Body_Id, State_Id);
24015 else
24016 SPARK_Msg_NE
24017 ("\variable & defined #", Body_Id, State_Id);
24018 end if;
24019
24020 Next_Elmt (State_Elmt);
24021 end loop;
24022 end if;
24023 end Report_Unused_States;
24024
24025 -- Local declarations
24026
24027 Body_Decl : constant Node_Id := Parent (N);
24028 Clauses : constant Node_Id :=
24029 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
24030 Clause : Node_Id;
24031
24032 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24033
24034 begin
24035 Set_Analyzed (N);
24036
24037 Body_Id := Defining_Entity (Body_Decl);
24038 Spec_Id := Corresponding_Spec (Body_Decl);
24039
24040 -- Replicate the abstract states declared by the package because the
24041 -- matching algorithm will consume states.
24042
24043 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
24044
24045 -- Gather all abstract states and variables declared in the visible
24046 -- state space of the package body. These items must be utilized as
24047 -- constituents in a state refinement.
24048
24049 Body_States := Collect_Body_States (Spec_Id);
24050
24051 -- Multiple non-null state refinements appear as an aggregate
24052
24053 if Nkind (Clauses) = N_Aggregate then
24054 if Present (Expressions (Clauses)) then
24055 SPARK_Msg_N
24056 ("state refinements must appear as component associations",
24057 Clauses);
24058
24059 else pragma Assert (Present (Component_Associations (Clauses)));
24060 Clause := First (Component_Associations (Clauses));
24061 while Present (Clause) loop
24062 Analyze_Refinement_Clause (Clause);
24063
24064 Next (Clause);
24065 end loop;
24066 end if;
24067
24068 -- Various forms of a single state refinement. Note that these may
24069 -- include malformed refinements.
24070
24071 else
24072 Analyze_Refinement_Clause (Clauses);
24073 end if;
24074
24075 -- List all abstract states that were left unrefined
24076
24077 Report_Unrefined_States (Available_States);
24078
24079 -- Ensure that all abstract states and variables declared in the body
24080 -- state space of the related package are utilized as constituents.
24081
24082 Report_Unused_States (Body_States);
24083 end Analyze_Refined_State_In_Decl_Part;
24084
24085 ------------------------------------
24086 -- Analyze_Test_Case_In_Decl_Part --
24087 ------------------------------------
24088
24089 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
24090 begin
24091 -- Install formals and push subprogram spec onto scope stack so that we
24092 -- can see the formals from the pragma.
24093
24094 Push_Scope (S);
24095 Install_Formals (S);
24096
24097 -- Preanalyze the boolean expressions, we treat these as spec
24098 -- expressions (i.e. similar to a default expression).
24099
24100 if Pragma_Name (N) = Name_Test_Case then
24101 Preanalyze_CTC_Args
24102 (N,
24103 Get_Requires_From_CTC_Pragma (N),
24104 Get_Ensures_From_CTC_Pragma (N));
24105 end if;
24106
24107 -- Remove the subprogram from the scope stack now that the pre-analysis
24108 -- of the expressions in the contract case or test case is done.
24109
24110 End_Scope;
24111 end Analyze_Test_Case_In_Decl_Part;
24112
24113 ----------------
24114 -- Appears_In --
24115 ----------------
24116
24117 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
24118 Elmt : Elmt_Id;
24119 Id : Entity_Id;
24120
24121 begin
24122 if Present (List) then
24123 Elmt := First_Elmt (List);
24124 while Present (Elmt) loop
24125 if Nkind (Node (Elmt)) = N_Defining_Identifier then
24126 Id := Node (Elmt);
24127 else
24128 Id := Entity_Of (Node (Elmt));
24129 end if;
24130
24131 if Id = Item_Id then
24132 return True;
24133 end if;
24134
24135 Next_Elmt (Elmt);
24136 end loop;
24137 end if;
24138
24139 return False;
24140 end Appears_In;
24141
24142 -----------------------------
24143 -- Check_Applicable_Policy --
24144 -----------------------------
24145
24146 procedure Check_Applicable_Policy (N : Node_Id) is
24147 PP : Node_Id;
24148 Policy : Name_Id;
24149
24150 Ename : constant Name_Id := Original_Aspect_Name (N);
24151
24152 begin
24153 -- No effect if not valid assertion kind name
24154
24155 if not Is_Valid_Assertion_Kind (Ename) then
24156 return;
24157 end if;
24158
24159 -- Loop through entries in check policy list
24160
24161 PP := Opt.Check_Policy_List;
24162 while Present (PP) loop
24163 declare
24164 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24165 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24166
24167 begin
24168 if Ename = Pnm
24169 or else Pnm = Name_Assertion
24170 or else (Pnm = Name_Statement_Assertions
24171 and then Nam_In (Ename, Name_Assert,
24172 Name_Assert_And_Cut,
24173 Name_Assume,
24174 Name_Loop_Invariant,
24175 Name_Loop_Variant))
24176 then
24177 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
24178
24179 case Policy is
24180 when Name_Off | Name_Ignore =>
24181 Set_Is_Ignored (N, True);
24182 Set_Is_Checked (N, False);
24183
24184 when Name_On | Name_Check =>
24185 Set_Is_Checked (N, True);
24186 Set_Is_Ignored (N, False);
24187
24188 when Name_Disable =>
24189 Set_Is_Ignored (N, True);
24190 Set_Is_Checked (N, False);
24191 Set_Is_Disabled (N, True);
24192
24193 -- That should be exhaustive, the null here is a defence
24194 -- against a malformed tree from previous errors.
24195
24196 when others =>
24197 null;
24198 end case;
24199
24200 return;
24201 end if;
24202
24203 PP := Next_Pragma (PP);
24204 end;
24205 end loop;
24206
24207 -- If there are no specific entries that matched, then we let the
24208 -- setting of assertions govern. Note that this provides the needed
24209 -- compatibility with the RM for the cases of assertion, invariant,
24210 -- precondition, predicate, and postcondition.
24211
24212 if Assertions_Enabled then
24213 Set_Is_Checked (N, True);
24214 Set_Is_Ignored (N, False);
24215 else
24216 Set_Is_Checked (N, False);
24217 Set_Is_Ignored (N, True);
24218 end if;
24219 end Check_Applicable_Policy;
24220
24221 -------------------------------
24222 -- Check_External_Properties --
24223 -------------------------------
24224
24225 procedure Check_External_Properties
24226 (Item : Node_Id;
24227 AR : Boolean;
24228 AW : Boolean;
24229 ER : Boolean;
24230 EW : Boolean)
24231 is
24232 begin
24233 -- All properties enabled
24234
24235 if AR and AW and ER and EW then
24236 null;
24237
24238 -- Async_Readers + Effective_Writes
24239 -- Async_Readers + Async_Writers + Effective_Writes
24240
24241 elsif AR and EW and not ER then
24242 null;
24243
24244 -- Async_Writers + Effective_Reads
24245 -- Async_Readers + Async_Writers + Effective_Reads
24246
24247 elsif AW and ER and not EW then
24248 null;
24249
24250 -- Async_Readers + Async_Writers
24251
24252 elsif AR and AW and not ER and not EW then
24253 null;
24254
24255 -- Async_Readers
24256
24257 elsif AR and not AW and not ER and not EW then
24258 null;
24259
24260 -- Async_Writers
24261
24262 elsif AW and not AR and not ER and not EW then
24263 null;
24264
24265 else
24266 SPARK_Msg_N
24267 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24268 Item);
24269 end if;
24270 end Check_External_Properties;
24271
24272 ----------------
24273 -- Check_Kind --
24274 ----------------
24275
24276 function Check_Kind (Nam : Name_Id) return Name_Id is
24277 PP : Node_Id;
24278
24279 begin
24280 -- Loop through entries in check policy list
24281
24282 PP := Opt.Check_Policy_List;
24283 while Present (PP) loop
24284 declare
24285 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24286 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
24287
24288 begin
24289 if Nam = Pnm
24290 or else (Pnm = Name_Assertion
24291 and then Is_Valid_Assertion_Kind (Nam))
24292 or else (Pnm = Name_Statement_Assertions
24293 and then Nam_In (Nam, Name_Assert,
24294 Name_Assert_And_Cut,
24295 Name_Assume,
24296 Name_Loop_Invariant,
24297 Name_Loop_Variant))
24298 then
24299 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
24300 when Name_On | Name_Check =>
24301 return Name_Check;
24302 when Name_Off | Name_Ignore =>
24303 return Name_Ignore;
24304 when Name_Disable =>
24305 return Name_Disable;
24306 when others =>
24307 raise Program_Error;
24308 end case;
24309
24310 else
24311 PP := Next_Pragma (PP);
24312 end if;
24313 end;
24314 end loop;
24315
24316 -- If there are no specific entries that matched, then we let the
24317 -- setting of assertions govern. Note that this provides the needed
24318 -- compatibility with the RM for the cases of assertion, invariant,
24319 -- precondition, predicate, and postcondition.
24320
24321 if Assertions_Enabled then
24322 return Name_Check;
24323 else
24324 return Name_Ignore;
24325 end if;
24326 end Check_Kind;
24327
24328 ---------------------------
24329 -- Check_Missing_Part_Of --
24330 ---------------------------
24331
24332 procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is
24333 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean;
24334 -- Determine whether a package denoted by Pack_Id declares at least one
24335 -- visible state.
24336
24337 -----------------------
24338 -- Has_Visible_State --
24339 -----------------------
24340
24341 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
24342 Item_Id : Entity_Id;
24343
24344 begin
24345 -- Traverse the entity chain of the package trying to find at least
24346 -- one visible abstract state, variable or a package [instantiation]
24347 -- that declares a visible state.
24348
24349 Item_Id := First_Entity (Pack_Id);
24350 while Present (Item_Id)
24351 and then not In_Private_Part (Item_Id)
24352 loop
24353 -- Do not consider internally generated items
24354
24355 if not Comes_From_Source (Item_Id) then
24356 null;
24357
24358 -- A visible state has been found
24359
24360 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24361 return True;
24362
24363 -- Recursively peek into nested packages and instantiations
24364
24365 elsif Ekind (Item_Id) = E_Package
24366 and then Has_Visible_State (Item_Id)
24367 then
24368 return True;
24369 end if;
24370
24371 Next_Entity (Item_Id);
24372 end loop;
24373
24374 return False;
24375 end Has_Visible_State;
24376
24377 -- Local variables
24378
24379 Pack_Id : Entity_Id;
24380 Placement : State_Space_Kind;
24381
24382 -- Start of processing for Check_Missing_Part_Of
24383
24384 begin
24385 -- Do not consider abstract states, variables or package instantiations
24386 -- coming from an instance as those always inherit the Part_Of indicator
24387 -- of the instance itself.
24388
24389 if In_Instance then
24390 return;
24391
24392 -- Do not consider internally generated entities as these can never
24393 -- have a Part_Of indicator.
24394
24395 elsif not Comes_From_Source (Item_Id) then
24396 return;
24397
24398 -- Perform these checks only when SPARK_Mode is enabled as they will
24399 -- interfere with standard Ada rules and produce false positives.
24400
24401 elsif SPARK_Mode /= On then
24402 return;
24403 end if;
24404
24405 -- Find where the abstract state, variable or package instantiation
24406 -- lives with respect to the state space.
24407
24408 Find_Placement_In_State_Space
24409 (Item_Id => Item_Id,
24410 Placement => Placement,
24411 Pack_Id => Pack_Id);
24412
24413 -- Items that appear in a non-package construct (subprogram, block, etc)
24414 -- do not require a Part_Of indicator because they can never act as a
24415 -- hidden state.
24416
24417 if Placement = Not_In_Package then
24418 null;
24419
24420 -- An item declared in the body state space of a package always act as a
24421 -- constituent and does not need explicit Part_Of indicator.
24422
24423 elsif Placement = Body_State_Space then
24424 null;
24425
24426 -- In general an item declared in the visible state space of a package
24427 -- does not require a Part_Of indicator. The only exception is when the
24428 -- related package is a private child unit in which case Part_Of must
24429 -- denote a state in the parent unit or in one of its descendants.
24430
24431 elsif Placement = Visible_State_Space then
24432 if Is_Child_Unit (Pack_Id)
24433 and then Is_Private_Descendant (Pack_Id)
24434 then
24435 -- A package instantiation does not need a Part_Of indicator when
24436 -- the related generic template has no visible state.
24437
24438 if Ekind (Item_Id) = E_Package
24439 and then Is_Generic_Instance (Item_Id)
24440 and then not Has_Visible_State (Item_Id)
24441 then
24442 null;
24443
24444 -- All other cases require Part_Of
24445
24446 else
24447 Error_Msg_N
24448 ("indicator Part_Of is required in this context "
24449 & "(SPARK RM 7.2.6(3))", Item_Id);
24450 Error_Msg_Name_1 := Chars (Pack_Id);
24451 Error_Msg_N
24452 ("\& is declared in the visible part of private child "
24453 & "unit %", Item_Id);
24454 end if;
24455 end if;
24456
24457 -- When the item appears in the private state space of a packge, it must
24458 -- be a part of some state declared by the said package.
24459
24460 else pragma Assert (Placement = Private_State_Space);
24461
24462 -- The related package does not declare a state, the item cannot act
24463 -- as a Part_Of constituent.
24464
24465 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
24466 null;
24467
24468 -- A package instantiation does not need a Part_Of indicator when the
24469 -- related generic template has no visible state.
24470
24471 elsif Ekind (Pack_Id) = E_Package
24472 and then Is_Generic_Instance (Pack_Id)
24473 and then not Has_Visible_State (Pack_Id)
24474 then
24475 null;
24476
24477 -- All other cases require Part_Of
24478
24479 else
24480 Error_Msg_N
24481 ("indicator Part_Of is required in this context "
24482 & "(SPARK RM 7.2.6(2))", Item_Id);
24483 Error_Msg_Name_1 := Chars (Pack_Id);
24484 Error_Msg_N
24485 ("\& is declared in the private part of package %", Item_Id);
24486 end if;
24487 end if;
24488 end Check_Missing_Part_Of;
24489
24490 ---------------------------------
24491 -- Check_SPARK_Aspect_For_ASIS --
24492 ---------------------------------
24493
24494 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id) is
24495 Expr : Node_Id;
24496
24497 begin
24498 if ASIS_Mode and then From_Aspect_Specification (N) then
24499 Expr := Expression (Corresponding_Aspect (N));
24500 if Nkind (Expr) /= N_Aggregate then
24501 Preanalyze_And_Resolve (Expr);
24502
24503 else
24504 declare
24505 Comps : constant List_Id := Component_Associations (Expr);
24506 Exprs : constant List_Id := Expressions (Expr);
24507 C : Node_Id;
24508 E : Node_Id;
24509
24510 begin
24511 E := First (Exprs);
24512 while Present (E) loop
24513 Analyze (E);
24514 Next (E);
24515 end loop;
24516
24517 C := First (Comps);
24518 while Present (C) loop
24519 Analyze (Expression (C));
24520 Next (C);
24521 end loop;
24522 end;
24523 end if;
24524 end if;
24525 end Check_SPARK_Aspect_For_ASIS;
24526
24527 -------------------------------------
24528 -- Check_State_And_Constituent_Use --
24529 -------------------------------------
24530
24531 procedure Check_State_And_Constituent_Use
24532 (States : Elist_Id;
24533 Constits : Elist_Id;
24534 Context : Node_Id)
24535 is
24536 function Find_Encapsulating_State
24537 (Constit_Id : Entity_Id) return Entity_Id;
24538 -- Given the entity of a constituent, try to find a corresponding
24539 -- encapsulating state that appears in the same context. The routine
24540 -- returns Empty is no such state is found.
24541
24542 ------------------------------
24543 -- Find_Encapsulating_State --
24544 ------------------------------
24545
24546 function Find_Encapsulating_State
24547 (Constit_Id : Entity_Id) return Entity_Id
24548 is
24549 State_Id : Entity_Id;
24550
24551 begin
24552 -- Since a constituent may be part of a larger constituent set, climb
24553 -- the encapsulated state chain looking for a state that appears in
24554 -- the same context.
24555
24556 State_Id := Encapsulating_State (Constit_Id);
24557 while Present (State_Id) loop
24558 if Contains (States, State_Id) then
24559 return State_Id;
24560 end if;
24561
24562 State_Id := Encapsulating_State (State_Id);
24563 end loop;
24564
24565 return Empty;
24566 end Find_Encapsulating_State;
24567
24568 -- Local variables
24569
24570 Constit_Elmt : Elmt_Id;
24571 Constit_Id : Entity_Id;
24572 State_Id : Entity_Id;
24573
24574 -- Start of processing for Check_State_And_Constituent_Use
24575
24576 begin
24577 -- Nothing to do if there are no states or constituents
24578
24579 if No (States) or else No (Constits) then
24580 return;
24581 end if;
24582
24583 -- Inspect the list of constituents and try to determine whether its
24584 -- encapsulating state is in list States.
24585
24586 Constit_Elmt := First_Elmt (Constits);
24587 while Present (Constit_Elmt) loop
24588 Constit_Id := Node (Constit_Elmt);
24589
24590 -- Determine whether the constituent is part of an encapsulating
24591 -- state that appears in the same context and if this is the case,
24592 -- emit an error (SPARK RM 7.2.6(7)).
24593
24594 State_Id := Find_Encapsulating_State (Constit_Id);
24595
24596 if Present (State_Id) then
24597 Error_Msg_Name_1 := Chars (Constit_Id);
24598 SPARK_Msg_NE
24599 ("cannot mention state & and its constituent % in the same "
24600 & "context", Context, State_Id);
24601 exit;
24602 end if;
24603
24604 Next_Elmt (Constit_Elmt);
24605 end loop;
24606 end Check_State_And_Constituent_Use;
24607
24608 --------------------------
24609 -- Collect_Global_Items --
24610 --------------------------
24611
24612 procedure Collect_Global_Items
24613 (Prag : Node_Id;
24614 In_Items : in out Elist_Id;
24615 In_Out_Items : in out Elist_Id;
24616 Out_Items : in out Elist_Id;
24617 Proof_In_Items : in out Elist_Id;
24618 Has_In_State : out Boolean;
24619 Has_In_Out_State : out Boolean;
24620 Has_Out_State : out Boolean;
24621 Has_Proof_In_State : out Boolean;
24622 Has_Null_State : out Boolean)
24623 is
24624 procedure Process_Global_List
24625 (List : Node_Id;
24626 Mode : Name_Id := Name_Input);
24627 -- Collect all items housed in a global list. Formal Mode denotes the
24628 -- current mode in effect.
24629
24630 -------------------------
24631 -- Process_Global_List --
24632 -------------------------
24633
24634 procedure Process_Global_List
24635 (List : Node_Id;
24636 Mode : Name_Id := Name_Input)
24637 is
24638 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id);
24639 -- Add a single item to the appropriate list. Formal Mode denotes the
24640 -- current mode in effect.
24641
24642 -------------------------
24643 -- Process_Global_Item --
24644 -------------------------
24645
24646 procedure Process_Global_Item (Item : Node_Id; Mode : Name_Id) is
24647 Item_Id : constant Entity_Id := Available_View (Entity_Of (Item));
24648 -- The above handles abstract views of variables and states built
24649 -- for limited with clauses.
24650
24651 begin
24652 -- Signal that the global list contains at least one abstract
24653 -- state with a visible refinement. Note that the refinement may
24654 -- be null in which case there are no constituents.
24655
24656 if Ekind (Item_Id) = E_Abstract_State then
24657 if Has_Null_Refinement (Item_Id) then
24658 Has_Null_State := True;
24659
24660 elsif Has_Non_Null_Refinement (Item_Id) then
24661 if Mode = Name_Input then
24662 Has_In_State := True;
24663 elsif Mode = Name_In_Out then
24664 Has_In_Out_State := True;
24665 elsif Mode = Name_Output then
24666 Has_Out_State := True;
24667 elsif Mode = Name_Proof_In then
24668 Has_Proof_In_State := True;
24669 end if;
24670 end if;
24671 end if;
24672
24673 -- Add the item to the proper list
24674
24675 if Mode = Name_Input then
24676 Add_Item (Item_Id, In_Items);
24677 elsif Mode = Name_In_Out then
24678 Add_Item (Item_Id, In_Out_Items);
24679 elsif Mode = Name_Output then
24680 Add_Item (Item_Id, Out_Items);
24681 elsif Mode = Name_Proof_In then
24682 Add_Item (Item_Id, Proof_In_Items);
24683 end if;
24684 end Process_Global_Item;
24685
24686 -- Local variables
24687
24688 Item : Node_Id;
24689
24690 -- Start of processing for Process_Global_List
24691
24692 begin
24693 if Nkind (List) = N_Null then
24694 null;
24695
24696 -- Single global item declaration
24697
24698 elsif Nkind_In (List, N_Expanded_Name,
24699 N_Identifier,
24700 N_Selected_Component)
24701 then
24702 Process_Global_Item (List, Mode);
24703
24704 -- Single global list or moded global list declaration
24705
24706 elsif Nkind (List) = N_Aggregate then
24707
24708 -- The declaration of a simple global list appear as a collection
24709 -- of expressions.
24710
24711 if Present (Expressions (List)) then
24712 Item := First (Expressions (List));
24713 while Present (Item) loop
24714 Process_Global_Item (Item, Mode);
24715
24716 Next (Item);
24717 end loop;
24718
24719 -- The declaration of a moded global list appears as a collection
24720 -- of component associations where individual choices denote mode.
24721
24722 elsif Present (Component_Associations (List)) then
24723 Item := First (Component_Associations (List));
24724 while Present (Item) loop
24725 Process_Global_List
24726 (List => Expression (Item),
24727 Mode => Chars (First (Choices (Item))));
24728
24729 Next (Item);
24730 end loop;
24731
24732 -- Invalid tree
24733
24734 else
24735 raise Program_Error;
24736 end if;
24737
24738 -- To accomodate partial decoration of disabled SPARK features, this
24739 -- routine may be called with illegal input. If this is the case, do
24740 -- not raise Program_Error.
24741
24742 else
24743 null;
24744 end if;
24745 end Process_Global_List;
24746
24747 -- Local variables
24748
24749 Items : constant Node_Id :=
24750 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
24751
24752 -- Start of processing for Collect_Global_Items
24753
24754 begin
24755 -- Assume that no states have been encountered
24756
24757 Has_In_State := False;
24758 Has_In_Out_State := False;
24759 Has_Out_State := False;
24760 Has_Proof_In_State := False;
24761 Has_Null_State := False;
24762
24763 Process_Global_List (Items);
24764 end Collect_Global_Items;
24765
24766 ---------------------------------------
24767 -- Collect_Subprogram_Inputs_Outputs --
24768 ---------------------------------------
24769
24770 procedure Collect_Subprogram_Inputs_Outputs
24771 (Subp_Id : Entity_Id;
24772 Subp_Inputs : in out Elist_Id;
24773 Subp_Outputs : in out Elist_Id;
24774 Global_Seen : out Boolean)
24775 is
24776 procedure Collect_Global_List
24777 (List : Node_Id;
24778 Mode : Name_Id := Name_Input);
24779 -- Collect all relevant items from a global list
24780
24781 -------------------------
24782 -- Collect_Global_List --
24783 -------------------------
24784
24785 procedure Collect_Global_List
24786 (List : Node_Id;
24787 Mode : Name_Id := Name_Input)
24788 is
24789 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
24790 -- Add an item to the proper subprogram input or output collection
24791
24792 -------------------------
24793 -- Collect_Global_Item --
24794 -------------------------
24795
24796 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
24797 begin
24798 if Nam_In (Mode, Name_In_Out, Name_Input) then
24799 Add_Item (Item, Subp_Inputs);
24800 end if;
24801
24802 if Nam_In (Mode, Name_In_Out, Name_Output) then
24803 Add_Item (Item, Subp_Outputs);
24804 end if;
24805 end Collect_Global_Item;
24806
24807 -- Local variables
24808
24809 Assoc : Node_Id;
24810 Item : Node_Id;
24811
24812 -- Start of processing for Collect_Global_List
24813
24814 begin
24815 if Nkind (List) = N_Null then
24816 null;
24817
24818 -- Single global item declaration
24819
24820 elsif Nkind_In (List, N_Expanded_Name,
24821 N_Identifier,
24822 N_Selected_Component)
24823 then
24824 Collect_Global_Item (List, Mode);
24825
24826 -- Simple global list or moded global list declaration
24827
24828 elsif Nkind (List) = N_Aggregate then
24829 if Present (Expressions (List)) then
24830 Item := First (Expressions (List));
24831 while Present (Item) loop
24832 Collect_Global_Item (Item, Mode);
24833 Next (Item);
24834 end loop;
24835
24836 else
24837 Assoc := First (Component_Associations (List));
24838 while Present (Assoc) loop
24839 Collect_Global_List
24840 (List => Expression (Assoc),
24841 Mode => Chars (First (Choices (Assoc))));
24842 Next (Assoc);
24843 end loop;
24844 end if;
24845
24846 -- To accomodate partial decoration of disabled SPARK features, this
24847 -- routine may be called with illegal input. If this is the case, do
24848 -- not raise Program_Error.
24849
24850 else
24851 null;
24852 end if;
24853 end Collect_Global_List;
24854
24855 -- Local variables
24856
24857 Subp_Decl : constant Node_Id := Parent (Parent (Subp_Id));
24858 Formal : Entity_Id;
24859 Global : Node_Id;
24860 List : Node_Id;
24861 Spec_Id : Entity_Id;
24862
24863 -- Start of processing for Collect_Subprogram_Inputs_Outputs
24864
24865 begin
24866 Global_Seen := False;
24867
24868 -- Find the entity of the corresponding spec when processing a body
24869
24870 if Nkind (Subp_Decl) = N_Subprogram_Body
24871 and then Present (Corresponding_Spec (Subp_Decl))
24872 then
24873 Spec_Id := Corresponding_Spec (Subp_Decl);
24874
24875 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
24876 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
24877 then
24878 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
24879
24880 else
24881 Spec_Id := Subp_Id;
24882 end if;
24883
24884 -- Process all formal parameters
24885
24886 Formal := First_Formal (Spec_Id);
24887 while Present (Formal) loop
24888 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
24889 Add_Item (Formal, Subp_Inputs);
24890 end if;
24891
24892 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
24893 Add_Item (Formal, Subp_Outputs);
24894
24895 -- Out parameters can act as inputs when the related type is
24896 -- tagged, unconstrained array, unconstrained record or record
24897 -- with unconstrained components.
24898
24899 if Ekind (Formal) = E_Out_Parameter
24900 and then Is_Unconstrained_Or_Tagged_Item (Formal)
24901 then
24902 Add_Item (Formal, Subp_Inputs);
24903 end if;
24904 end if;
24905
24906 Next_Formal (Formal);
24907 end loop;
24908
24909 -- When processing a subprogram body, look for pragma Refined_Global as
24910 -- it provides finer granularity of inputs and outputs.
24911
24912 if Ekind (Subp_Id) = E_Subprogram_Body then
24913 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
24914
24915 -- Subprogram declaration case, look for pragma Global
24916
24917 else
24918 Global := Get_Pragma (Spec_Id, Pragma_Global);
24919 end if;
24920
24921 if Present (Global) then
24922 Global_Seen := True;
24923 List := Expression (First (Pragma_Argument_Associations (Global)));
24924
24925 -- The pragma may not have been analyzed because of the arbitrary
24926 -- declaration order of aspects. Make sure that it is analyzed for
24927 -- the purposes of item extraction.
24928
24929 if not Analyzed (List) then
24930 if Pragma_Name (Global) = Name_Refined_Global then
24931 Analyze_Refined_Global_In_Decl_Part (Global);
24932 else
24933 Analyze_Global_In_Decl_Part (Global);
24934 end if;
24935 end if;
24936
24937 -- Nothing to be done for a null global list
24938
24939 if Nkind (List) /= N_Null then
24940 Collect_Global_List (List);
24941 end if;
24942 end if;
24943 end Collect_Subprogram_Inputs_Outputs;
24944
24945 ---------------------------------
24946 -- Delay_Config_Pragma_Analyze --
24947 ---------------------------------
24948
24949 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
24950 begin
24951 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
24952 Name_Priority_Specific_Dispatching);
24953 end Delay_Config_Pragma_Analyze;
24954
24955 -------------------------------------
24956 -- Find_Related_Subprogram_Or_Body --
24957 -------------------------------------
24958
24959 function Find_Related_Subprogram_Or_Body
24960 (Prag : Node_Id;
24961 Do_Checks : Boolean := False) return Node_Id
24962 is
24963 Context : constant Node_Id := Parent (Prag);
24964 Nam : constant Name_Id := Pragma_Name (Prag);
24965 Stmt : Node_Id;
24966
24967 Look_For_Body : constant Boolean :=
24968 Nam_In (Nam, Name_Refined_Depends,
24969 Name_Refined_Global,
24970 Name_Refined_Post);
24971 -- Refinement pragmas must be associated with a subprogram body [stub]
24972
24973 begin
24974 pragma Assert (Nkind (Prag) = N_Pragma);
24975
24976 -- If the pragma is a byproduct of aspect expansion, return the related
24977 -- context of the original aspect.
24978
24979 if Present (Corresponding_Aspect (Prag)) then
24980 return Parent (Corresponding_Aspect (Prag));
24981 end if;
24982
24983 -- Otherwise the pragma is a source construct, most likely part of a
24984 -- declarative list. Skip preceding declarations while looking for a
24985 -- proper subprogram declaration.
24986
24987 pragma Assert (Is_List_Member (Prag));
24988
24989 Stmt := Prev (Prag);
24990 while Present (Stmt) loop
24991
24992 -- Skip prior pragmas, but check for duplicates
24993
24994 if Nkind (Stmt) = N_Pragma then
24995 if Do_Checks and then Pragma_Name (Stmt) = Nam then
24996 Error_Msg_Name_1 := Nam;
24997 Error_Msg_Sloc := Sloc (Stmt);
24998 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
24999 end if;
25000
25001 -- Emit an error when a refinement pragma appears on an expression
25002 -- function without a completion.
25003
25004 elsif Do_Checks
25005 and then Look_For_Body
25006 and then Nkind (Stmt) = N_Subprogram_Declaration
25007 and then Nkind (Original_Node (Stmt)) = N_Expression_Function
25008 and then not Has_Completion (Defining_Entity (Stmt))
25009 then
25010 Error_Msg_Name_1 := Nam;
25011 Error_Msg_N
25012 ("pragma % cannot apply to a stand alone expression function",
25013 Prag);
25014
25015 return Empty;
25016
25017 -- The refinement pragma applies to a subprogram body stub
25018
25019 elsif Look_For_Body
25020 and then Nkind (Stmt) = N_Subprogram_Body_Stub
25021 then
25022 return Stmt;
25023
25024 -- Skip internally generated code
25025
25026 elsif not Comes_From_Source (Stmt) then
25027 null;
25028
25029 -- Return the current construct which is either a subprogram body,
25030 -- a subprogram declaration or is illegal.
25031
25032 else
25033 return Stmt;
25034 end if;
25035
25036 Prev (Stmt);
25037 end loop;
25038
25039 -- If we fall through, then the pragma was either the first declaration
25040 -- or it was preceded by other pragmas and no source constructs.
25041
25042 -- The pragma is associated with a library-level subprogram
25043
25044 if Nkind (Context) = N_Compilation_Unit_Aux then
25045 return Unit (Parent (Context));
25046
25047 -- The pragma appears inside the declarative part of a subprogram body
25048
25049 elsif Nkind (Context) = N_Subprogram_Body then
25050 return Context;
25051
25052 -- No candidate subprogram [body] found
25053
25054 else
25055 return Empty;
25056 end if;
25057 end Find_Related_Subprogram_Or_Body;
25058
25059 -------------------------
25060 -- Get_Base_Subprogram --
25061 -------------------------
25062
25063 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
25064 Result : Entity_Id;
25065
25066 begin
25067 -- Follow subprogram renaming chain
25068
25069 Result := Def_Id;
25070
25071 if Is_Subprogram (Result)
25072 and then
25073 Nkind (Parent (Declaration_Node (Result))) =
25074 N_Subprogram_Renaming_Declaration
25075 and then Present (Alias (Result))
25076 then
25077 Result := Alias (Result);
25078 end if;
25079
25080 return Result;
25081 end Get_Base_Subprogram;
25082
25083 -----------------------
25084 -- Get_SPARK_Mode_Type --
25085 -----------------------
25086
25087 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
25088 begin
25089 if N = Name_On then
25090 return On;
25091 elsif N = Name_Off then
25092 return Off;
25093
25094 -- Any other argument is illegal
25095
25096 else
25097 raise Program_Error;
25098 end if;
25099 end Get_SPARK_Mode_Type;
25100
25101 --------------------------------
25102 -- Get_SPARK_Mode_From_Pragma --
25103 --------------------------------
25104
25105 function Get_SPARK_Mode_From_Pragma (N : Node_Id) return SPARK_Mode_Type is
25106 Args : List_Id;
25107 Mode : Node_Id;
25108
25109 begin
25110 pragma Assert (Nkind (N) = N_Pragma);
25111 Args := Pragma_Argument_Associations (N);
25112
25113 -- Extract the mode from the argument list
25114
25115 if Present (Args) then
25116 Mode := First (Pragma_Argument_Associations (N));
25117 return Get_SPARK_Mode_Type (Chars (Get_Pragma_Arg (Mode)));
25118
25119 -- If SPARK_Mode pragma has no argument, default is ON
25120
25121 else
25122 return On;
25123 end if;
25124 end Get_SPARK_Mode_From_Pragma;
25125
25126 ---------------------------
25127 -- Has_Extra_Parentheses --
25128 ---------------------------
25129
25130 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
25131 Expr : Node_Id;
25132
25133 begin
25134 -- The aggregate should not have an expression list because a clause
25135 -- is always interpreted as a component association. The only way an
25136 -- expression list can sneak in is by adding extra parentheses around
25137 -- the individual clauses:
25138
25139 -- Depends (Output => Input) -- proper form
25140 -- Depends ((Output => Input)) -- extra parentheses
25141
25142 -- Since the extra parentheses are not allowed by the syntax of the
25143 -- pragma, flag them now to avoid emitting misleading errors down the
25144 -- line.
25145
25146 if Nkind (Clause) = N_Aggregate
25147 and then Present (Expressions (Clause))
25148 then
25149 Expr := First (Expressions (Clause));
25150 while Present (Expr) loop
25151
25152 -- A dependency clause surrounded by extra parentheses appears
25153 -- as an aggregate of component associations with an optional
25154 -- Paren_Count set.
25155
25156 if Nkind (Expr) = N_Aggregate
25157 and then Present (Component_Associations (Expr))
25158 then
25159 SPARK_Msg_N
25160 ("dependency clause contains extra parentheses", Expr);
25161
25162 -- Otherwise the expression is a malformed construct
25163
25164 else
25165 SPARK_Msg_N ("malformed dependency clause", Expr);
25166 end if;
25167
25168 Next (Expr);
25169 end loop;
25170
25171 return True;
25172 end if;
25173
25174 return False;
25175 end Has_Extra_Parentheses;
25176
25177 ----------------
25178 -- Initialize --
25179 ----------------
25180
25181 procedure Initialize is
25182 begin
25183 Externals.Init;
25184 end Initialize;
25185
25186 --------
25187 -- ip --
25188 --------
25189
25190 procedure ip is
25191 begin
25192 Dummy := Dummy + 1;
25193 end ip;
25194
25195 -----------------------------
25196 -- Is_Config_Static_String --
25197 -----------------------------
25198
25199 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
25200
25201 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
25202 -- This is an internal recursive function that is just like the outer
25203 -- function except that it adds the string to the name buffer rather
25204 -- than placing the string in the name buffer.
25205
25206 ------------------------------
25207 -- Add_Config_Static_String --
25208 ------------------------------
25209
25210 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
25211 N : Node_Id;
25212 C : Char_Code;
25213
25214 begin
25215 N := Arg;
25216
25217 if Nkind (N) = N_Op_Concat then
25218 if Add_Config_Static_String (Left_Opnd (N)) then
25219 N := Right_Opnd (N);
25220 else
25221 return False;
25222 end if;
25223 end if;
25224
25225 if Nkind (N) /= N_String_Literal then
25226 Error_Msg_N ("string literal expected for pragma argument", N);
25227 return False;
25228
25229 else
25230 for J in 1 .. String_Length (Strval (N)) loop
25231 C := Get_String_Char (Strval (N), J);
25232
25233 if not In_Character_Range (C) then
25234 Error_Msg
25235 ("string literal contains invalid wide character",
25236 Sloc (N) + 1 + Source_Ptr (J));
25237 return False;
25238 end if;
25239
25240 Add_Char_To_Name_Buffer (Get_Character (C));
25241 end loop;
25242 end if;
25243
25244 return True;
25245 end Add_Config_Static_String;
25246
25247 -- Start of processing for Is_Config_Static_String
25248
25249 begin
25250 Name_Len := 0;
25251
25252 return Add_Config_Static_String (Arg);
25253 end Is_Config_Static_String;
25254
25255 -------------------------------
25256 -- Is_Elaboration_SPARK_Mode --
25257 -------------------------------
25258
25259 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
25260 begin
25261 pragma Assert
25262 (Nkind (N) = N_Pragma
25263 and then Pragma_Name (N) = Name_SPARK_Mode
25264 and then Is_List_Member (N));
25265
25266 -- Pragma SPARK_Mode affects the elaboration of a package body when it
25267 -- appears in the statement part of the body.
25268
25269 return
25270 Present (Parent (N))
25271 and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements
25272 and then List_Containing (N) = Statements (Parent (N))
25273 and then Present (Parent (Parent (N)))
25274 and then Nkind (Parent (Parent (N))) = N_Package_Body;
25275 end Is_Elaboration_SPARK_Mode;
25276
25277 -----------------------------------------
25278 -- Is_Non_Significant_Pragma_Reference --
25279 -----------------------------------------
25280
25281 -- This function makes use of the following static table which indicates
25282 -- whether appearance of some name in a given pragma is to be considered
25283 -- as a reference for the purposes of warnings about unreferenced objects.
25284
25285 -- -1 indicates that references in any argument position are significant
25286 -- 0 indicates that appearance in any argument is not significant
25287 -- +n indicates that appearance as argument n is significant, but all
25288 -- other arguments are not significant
25289 -- 99 special processing required (e.g. for pragma Check)
25290
25291 Sig_Flags : constant array (Pragma_Id) of Int :=
25292 (Pragma_AST_Entry => -1,
25293 Pragma_Abort_Defer => -1,
25294 Pragma_Abstract_State => -1,
25295 Pragma_Ada_83 => -1,
25296 Pragma_Ada_95 => -1,
25297 Pragma_Ada_05 => -1,
25298 Pragma_Ada_2005 => -1,
25299 Pragma_Ada_12 => -1,
25300 Pragma_Ada_2012 => -1,
25301 Pragma_All_Calls_Remote => -1,
25302 Pragma_Allow_Integer_Address => 0,
25303 Pragma_Annotate => -1,
25304 Pragma_Assert => -1,
25305 Pragma_Assert_And_Cut => -1,
25306 Pragma_Assertion_Policy => 0,
25307 Pragma_Assume => -1,
25308 Pragma_Assume_No_Invalid_Values => 0,
25309 Pragma_Async_Readers => 0,
25310 Pragma_Async_Writers => 0,
25311 Pragma_Asynchronous => -1,
25312 Pragma_Atomic => 0,
25313 Pragma_Atomic_Components => 0,
25314 Pragma_Attach_Handler => -1,
25315 Pragma_Attribute_Definition => +3,
25316 Pragma_Check => 99,
25317 Pragma_Check_Float_Overflow => 0,
25318 Pragma_Check_Name => 0,
25319 Pragma_Check_Policy => 0,
25320 Pragma_CIL_Constructor => -1,
25321 Pragma_CPP_Class => 0,
25322 Pragma_CPP_Constructor => 0,
25323 Pragma_CPP_Virtual => 0,
25324 Pragma_CPP_Vtable => 0,
25325 Pragma_CPU => -1,
25326 Pragma_C_Pass_By_Copy => 0,
25327 Pragma_Comment => 0,
25328 Pragma_Common_Object => -1,
25329 Pragma_Compile_Time_Error => -1,
25330 Pragma_Compile_Time_Warning => -1,
25331 Pragma_Compiler_Unit => 0,
25332 Pragma_Compiler_Unit_Warning => 0,
25333 Pragma_Complete_Representation => 0,
25334 Pragma_Complex_Representation => 0,
25335 Pragma_Component_Alignment => -1,
25336 Pragma_Contract_Cases => -1,
25337 Pragma_Controlled => 0,
25338 Pragma_Convention => 0,
25339 Pragma_Convention_Identifier => 0,
25340 Pragma_Debug => -1,
25341 Pragma_Debug_Policy => 0,
25342 Pragma_Detect_Blocking => -1,
25343 Pragma_Default_Scalar_Storage_Order => 0,
25344 Pragma_Default_Storage_Pool => -1,
25345 Pragma_Depends => -1,
25346 Pragma_Disable_Atomic_Synchronization => -1,
25347 Pragma_Discard_Names => 0,
25348 Pragma_Dispatching_Domain => -1,
25349 Pragma_Effective_Reads => 0,
25350 Pragma_Effective_Writes => 0,
25351 Pragma_Elaborate => -1,
25352 Pragma_Elaborate_All => -1,
25353 Pragma_Elaborate_Body => -1,
25354 Pragma_Elaboration_Checks => -1,
25355 Pragma_Eliminate => -1,
25356 Pragma_Enable_Atomic_Synchronization => -1,
25357 Pragma_Export => -1,
25358 Pragma_Export_Exception => -1,
25359 Pragma_Export_Function => -1,
25360 Pragma_Export_Object => -1,
25361 Pragma_Export_Procedure => -1,
25362 Pragma_Export_Value => -1,
25363 Pragma_Export_Valued_Procedure => -1,
25364 Pragma_Extend_System => -1,
25365 Pragma_Extensions_Allowed => -1,
25366 Pragma_External => -1,
25367 Pragma_Favor_Top_Level => -1,
25368 Pragma_External_Name_Casing => -1,
25369 Pragma_Fast_Math => -1,
25370 Pragma_Finalize_Storage_Only => 0,
25371 Pragma_Float_Representation => 0,
25372 Pragma_Global => -1,
25373 Pragma_Ident => -1,
25374 Pragma_Implementation_Defined => -1,
25375 Pragma_Implemented => -1,
25376 Pragma_Implicit_Packing => 0,
25377 Pragma_Import => +2,
25378 Pragma_Import_Exception => 0,
25379 Pragma_Import_Function => 0,
25380 Pragma_Import_Object => 0,
25381 Pragma_Import_Procedure => 0,
25382 Pragma_Import_Valued_Procedure => 0,
25383 Pragma_Independent => 0,
25384 Pragma_Independent_Components => 0,
25385 Pragma_Initial_Condition => -1,
25386 Pragma_Initialize_Scalars => -1,
25387 Pragma_Initializes => -1,
25388 Pragma_Inline => 0,
25389 Pragma_Inline_Always => 0,
25390 Pragma_Inline_Generic => 0,
25391 Pragma_Inspection_Point => -1,
25392 Pragma_Interface => +2,
25393 Pragma_Interface_Name => +2,
25394 Pragma_Interrupt_Handler => -1,
25395 Pragma_Interrupt_Priority => -1,
25396 Pragma_Interrupt_State => -1,
25397 Pragma_Invariant => -1,
25398 Pragma_Java_Constructor => -1,
25399 Pragma_Java_Interface => -1,
25400 Pragma_Keep_Names => 0,
25401 Pragma_License => -1,
25402 Pragma_Link_With => -1,
25403 Pragma_Linker_Alias => -1,
25404 Pragma_Linker_Constructor => -1,
25405 Pragma_Linker_Destructor => -1,
25406 Pragma_Linker_Options => -1,
25407 Pragma_Linker_Section => -1,
25408 Pragma_List => -1,
25409 Pragma_Lock_Free => -1,
25410 Pragma_Locking_Policy => -1,
25411 Pragma_Long_Float => -1,
25412 Pragma_Loop_Invariant => -1,
25413 Pragma_Loop_Optimize => -1,
25414 Pragma_Loop_Variant => -1,
25415 Pragma_Machine_Attribute => -1,
25416 Pragma_Main => -1,
25417 Pragma_Main_Storage => -1,
25418 Pragma_Memory_Size => -1,
25419 Pragma_No_Return => 0,
25420 Pragma_No_Body => 0,
25421 Pragma_No_Inline => 0,
25422 Pragma_No_Run_Time => -1,
25423 Pragma_No_Strict_Aliasing => -1,
25424 Pragma_Normalize_Scalars => -1,
25425 Pragma_Obsolescent => 0,
25426 Pragma_Optimize => -1,
25427 Pragma_Optimize_Alignment => -1,
25428 Pragma_Overflow_Mode => 0,
25429 Pragma_Overriding_Renamings => 0,
25430 Pragma_Ordered => 0,
25431 Pragma_Pack => 0,
25432 Pragma_Page => -1,
25433 Pragma_Part_Of => -1,
25434 Pragma_Partition_Elaboration_Policy => -1,
25435 Pragma_Passive => -1,
25436 Pragma_Persistent_BSS => 0,
25437 Pragma_Polling => -1,
25438 Pragma_Post => -1,
25439 Pragma_Postcondition => -1,
25440 Pragma_Post_Class => -1,
25441 Pragma_Pre => -1,
25442 Pragma_Precondition => -1,
25443 Pragma_Predicate => -1,
25444 Pragma_Preelaborable_Initialization => -1,
25445 Pragma_Preelaborate => -1,
25446 Pragma_Pre_Class => -1,
25447 Pragma_Priority => -1,
25448 Pragma_Priority_Specific_Dispatching => -1,
25449 Pragma_Profile => 0,
25450 Pragma_Profile_Warnings => 0,
25451 Pragma_Propagate_Exceptions => -1,
25452 Pragma_Provide_Shift_Operators => -1,
25453 Pragma_Psect_Object => -1,
25454 Pragma_Pure => -1,
25455 Pragma_Pure_Function => -1,
25456 Pragma_Queuing_Policy => -1,
25457 Pragma_Rational => -1,
25458 Pragma_Ravenscar => -1,
25459 Pragma_Refined_Depends => -1,
25460 Pragma_Refined_Global => -1,
25461 Pragma_Refined_Post => -1,
25462 Pragma_Refined_State => -1,
25463 Pragma_Relative_Deadline => -1,
25464 Pragma_Remote_Access_Type => -1,
25465 Pragma_Remote_Call_Interface => -1,
25466 Pragma_Remote_Types => -1,
25467 Pragma_Restricted_Run_Time => -1,
25468 Pragma_Restriction_Warnings => -1,
25469 Pragma_Restrictions => -1,
25470 Pragma_Reviewable => -1,
25471 Pragma_Short_Circuit_And_Or => -1,
25472 Pragma_Share_Generic => -1,
25473 Pragma_Shared => -1,
25474 Pragma_Shared_Passive => -1,
25475 Pragma_Short_Descriptors => 0,
25476 Pragma_Simple_Storage_Pool_Type => 0,
25477 Pragma_Source_File_Name => -1,
25478 Pragma_Source_File_Name_Project => -1,
25479 Pragma_Source_Reference => -1,
25480 Pragma_SPARK_Mode => 0,
25481 Pragma_Storage_Size => -1,
25482 Pragma_Storage_Unit => -1,
25483 Pragma_Static_Elaboration_Desired => -1,
25484 Pragma_Stream_Convert => -1,
25485 Pragma_Style_Checks => -1,
25486 Pragma_Subtitle => -1,
25487 Pragma_Suppress => 0,
25488 Pragma_Suppress_Exception_Locations => 0,
25489 Pragma_Suppress_All => -1,
25490 Pragma_Suppress_Debug_Info => 0,
25491 Pragma_Suppress_Initialization => 0,
25492 Pragma_System_Name => -1,
25493 Pragma_Task_Dispatching_Policy => -1,
25494 Pragma_Task_Info => -1,
25495 Pragma_Task_Name => -1,
25496 Pragma_Task_Storage => 0,
25497 Pragma_Test_Case => -1,
25498 Pragma_Thread_Local_Storage => 0,
25499 Pragma_Time_Slice => -1,
25500 Pragma_Title => -1,
25501 Pragma_Type_Invariant => -1,
25502 Pragma_Type_Invariant_Class => -1,
25503 Pragma_Unchecked_Union => 0,
25504 Pragma_Unimplemented_Unit => -1,
25505 Pragma_Universal_Aliasing => -1,
25506 Pragma_Universal_Data => -1,
25507 Pragma_Unmodified => -1,
25508 Pragma_Unreferenced => -1,
25509 Pragma_Unreferenced_Objects => -1,
25510 Pragma_Unreserve_All_Interrupts => -1,
25511 Pragma_Unsuppress => 0,
25512 Pragma_Unevaluated_Use_Of_Old => 0,
25513 Pragma_Use_VADS_Size => -1,
25514 Pragma_Validity_Checks => -1,
25515 Pragma_Volatile => 0,
25516 Pragma_Volatile_Components => 0,
25517 Pragma_Warning_As_Error => -1,
25518 Pragma_Warnings => -1,
25519 Pragma_Weak_External => -1,
25520 Pragma_Wide_Character_Encoding => 0,
25521 Unknown_Pragma => 0);
25522
25523 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
25524 Id : Pragma_Id;
25525 P : Node_Id;
25526 C : Int;
25527 A : Node_Id;
25528
25529 begin
25530 P := Parent (N);
25531
25532 if Nkind (P) /= N_Pragma_Argument_Association then
25533 return False;
25534
25535 else
25536 Id := Get_Pragma_Id (Parent (P));
25537 C := Sig_Flags (Id);
25538
25539 case C is
25540 when -1 =>
25541 return False;
25542
25543 when 0 =>
25544 return True;
25545
25546 when 99 =>
25547 case Id is
25548
25549 -- For pragma Check, the first argument is not significant,
25550 -- the second and the third (if present) arguments are
25551 -- significant.
25552
25553 when Pragma_Check =>
25554 return
25555 P = First (Pragma_Argument_Associations (Parent (P)));
25556
25557 when others =>
25558 raise Program_Error;
25559 end case;
25560
25561 when others =>
25562 A := First (Pragma_Argument_Associations (Parent (P)));
25563 for J in 1 .. C - 1 loop
25564 if No (A) then
25565 return False;
25566 end if;
25567
25568 Next (A);
25569 end loop;
25570
25571 return A = P; -- is this wrong way round ???
25572 end case;
25573 end if;
25574 end Is_Non_Significant_Pragma_Reference;
25575
25576 ------------------------------
25577 -- Is_Pragma_String_Literal --
25578 ------------------------------
25579
25580 -- This function returns true if the corresponding pragma argument is a
25581 -- static string expression. These are the only cases in which string
25582 -- literals can appear as pragma arguments. We also allow a string literal
25583 -- as the first argument to pragma Assert (although it will of course
25584 -- always generate a type error).
25585
25586 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
25587 Pragn : constant Node_Id := Parent (Par);
25588 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
25589 Pname : constant Name_Id := Pragma_Name (Pragn);
25590 Argn : Natural;
25591 N : Node_Id;
25592
25593 begin
25594 Argn := 1;
25595 N := First (Assoc);
25596 loop
25597 exit when N = Par;
25598 Argn := Argn + 1;
25599 Next (N);
25600 end loop;
25601
25602 if Pname = Name_Assert then
25603 return True;
25604
25605 elsif Pname = Name_Export then
25606 return Argn > 2;
25607
25608 elsif Pname = Name_Ident then
25609 return Argn = 1;
25610
25611 elsif Pname = Name_Import then
25612 return Argn > 2;
25613
25614 elsif Pname = Name_Interface_Name then
25615 return Argn > 1;
25616
25617 elsif Pname = Name_Linker_Alias then
25618 return Argn = 2;
25619
25620 elsif Pname = Name_Linker_Section then
25621 return Argn = 2;
25622
25623 elsif Pname = Name_Machine_Attribute then
25624 return Argn = 2;
25625
25626 elsif Pname = Name_Source_File_Name then
25627 return True;
25628
25629 elsif Pname = Name_Source_Reference then
25630 return Argn = 2;
25631
25632 elsif Pname = Name_Title then
25633 return True;
25634
25635 elsif Pname = Name_Subtitle then
25636 return True;
25637
25638 else
25639 return False;
25640 end if;
25641 end Is_Pragma_String_Literal;
25642
25643 ---------------------------
25644 -- Is_Private_SPARK_Mode --
25645 ---------------------------
25646
25647 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
25648 begin
25649 pragma Assert
25650 (Nkind (N) = N_Pragma
25651 and then Pragma_Name (N) = Name_SPARK_Mode
25652 and then Is_List_Member (N));
25653
25654 -- For pragma SPARK_Mode to be private, it has to appear in the private
25655 -- declarations of a package.
25656
25657 return
25658 Present (Parent (N))
25659 and then Nkind (Parent (N)) = N_Package_Specification
25660 and then List_Containing (N) = Private_Declarations (Parent (N));
25661 end Is_Private_SPARK_Mode;
25662
25663 -------------------------------------
25664 -- Is_Unconstrained_Or_Tagged_Item --
25665 -------------------------------------
25666
25667 function Is_Unconstrained_Or_Tagged_Item
25668 (Item : Entity_Id) return Boolean
25669 is
25670 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
25671 -- Determine whether record type Typ has at least one unconstrained
25672 -- component.
25673
25674 ---------------------------------
25675 -- Has_Unconstrained_Component --
25676 ---------------------------------
25677
25678 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
25679 Comp : Entity_Id;
25680
25681 begin
25682 Comp := First_Component (Typ);
25683 while Present (Comp) loop
25684 if Is_Unconstrained_Or_Tagged_Item (Comp) then
25685 return True;
25686 end if;
25687
25688 Next_Component (Comp);
25689 end loop;
25690
25691 return False;
25692 end Has_Unconstrained_Component;
25693
25694 -- Local variables
25695
25696 Typ : constant Entity_Id := Etype (Item);
25697
25698 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
25699
25700 begin
25701 if Is_Tagged_Type (Typ) then
25702 return True;
25703
25704 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
25705 return True;
25706
25707 elsif Is_Record_Type (Typ) then
25708 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
25709 return True;
25710 else
25711 return Has_Unconstrained_Component (Typ);
25712 end if;
25713
25714 else
25715 return False;
25716 end if;
25717 end Is_Unconstrained_Or_Tagged_Item;
25718
25719 -----------------------------
25720 -- Is_Valid_Assertion_Kind --
25721 -----------------------------
25722
25723 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
25724 begin
25725 case Nam is
25726 when
25727 -- RM defined
25728
25729 Name_Assert |
25730 Name_Static_Predicate |
25731 Name_Dynamic_Predicate |
25732 Name_Pre |
25733 Name_uPre |
25734 Name_Post |
25735 Name_uPost |
25736 Name_Type_Invariant |
25737 Name_uType_Invariant |
25738
25739 -- Impl defined
25740
25741 Name_Assert_And_Cut |
25742 Name_Assume |
25743 Name_Contract_Cases |
25744 Name_Debug |
25745 Name_Initial_Condition |
25746 Name_Invariant |
25747 Name_uInvariant |
25748 Name_Loop_Invariant |
25749 Name_Loop_Variant |
25750 Name_Postcondition |
25751 Name_Precondition |
25752 Name_Predicate |
25753 Name_Refined_Post |
25754 Name_Statement_Assertions => return True;
25755
25756 when others => return False;
25757 end case;
25758 end Is_Valid_Assertion_Kind;
25759
25760 -----------------------------------------
25761 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
25762 -----------------------------------------
25763
25764 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
25765 Aspects : constant List_Id := New_List;
25766 Loc : constant Source_Ptr := Sloc (Decl);
25767 Or_Decl : constant Node_Id := Original_Node (Decl);
25768
25769 Original_Aspects : List_Id;
25770 -- To capture global references, a copy of the created aspects must be
25771 -- inserted in the original tree.
25772
25773 Prag : Node_Id;
25774 Prag_Arg_Ass : Node_Id;
25775 Prag_Id : Pragma_Id;
25776
25777 begin
25778 -- Check for any PPC pragmas that appear within Decl
25779
25780 Prag := Next (Decl);
25781 while Nkind (Prag) = N_Pragma loop
25782 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
25783
25784 case Prag_Id is
25785 when Pragma_Postcondition | Pragma_Precondition =>
25786 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
25787
25788 -- Make an aspect from any PPC pragma
25789
25790 Append_To (Aspects,
25791 Make_Aspect_Specification (Loc,
25792 Identifier =>
25793 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
25794 Expression =>
25795 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
25796
25797 -- Generate the analysis information in the pragma expression
25798 -- and then set the pragma node analyzed to avoid any further
25799 -- analysis.
25800
25801 Analyze (Expression (Prag_Arg_Ass));
25802 Set_Analyzed (Prag, True);
25803
25804 when others => null;
25805 end case;
25806
25807 Next (Prag);
25808 end loop;
25809
25810 -- Set all new aspects into the generic declaration node
25811
25812 if Is_Non_Empty_List (Aspects) then
25813
25814 -- Create the list of aspects to be inserted in the original tree
25815
25816 Original_Aspects := Copy_Separate_List (Aspects);
25817
25818 -- Check if Decl already has aspects
25819
25820 -- Attach the new lists of aspects to both the generic copy and the
25821 -- original tree.
25822
25823 if Has_Aspects (Decl) then
25824 Append_List (Aspects, Aspect_Specifications (Decl));
25825 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
25826
25827 else
25828 Set_Parent (Aspects, Decl);
25829 Set_Aspect_Specifications (Decl, Aspects);
25830 Set_Parent (Original_Aspects, Or_Decl);
25831 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
25832 end if;
25833 end if;
25834 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
25835
25836 -------------------------
25837 -- Preanalyze_CTC_Args --
25838 -------------------------
25839
25840 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
25841 begin
25842 -- Preanalyze the boolean expressions, we treat these as spec
25843 -- expressions (i.e. similar to a default expression).
25844
25845 if Present (Arg_Req) then
25846 Preanalyze_Assert_Expression
25847 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
25848
25849 -- In ASIS mode, for a pragma generated from a source aspect, also
25850 -- analyze the original aspect expression.
25851
25852 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
25853 Preanalyze_Assert_Expression
25854 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
25855 end if;
25856 end if;
25857
25858 if Present (Arg_Ens) then
25859 Preanalyze_Assert_Expression
25860 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
25861
25862 -- In ASIS mode, for a pragma generated from a source aspect, also
25863 -- analyze the original aspect expression.
25864
25865 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
25866 Preanalyze_Assert_Expression
25867 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
25868 end if;
25869 end if;
25870 end Preanalyze_CTC_Args;
25871
25872 --------------------------------------
25873 -- Process_Compilation_Unit_Pragmas --
25874 --------------------------------------
25875
25876 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
25877 begin
25878 -- A special check for pragma Suppress_All, a very strange DEC pragma,
25879 -- strange because it comes at the end of the unit. Rational has the
25880 -- same name for a pragma, but treats it as a program unit pragma, In
25881 -- GNAT we just decide to allow it anywhere at all. If it appeared then
25882 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
25883 -- node, and we insert a pragma Suppress (All_Checks) at the start of
25884 -- the context clause to ensure the correct processing.
25885
25886 if Has_Pragma_Suppress_All (N) then
25887 Prepend_To (Context_Items (N),
25888 Make_Pragma (Sloc (N),
25889 Chars => Name_Suppress,
25890 Pragma_Argument_Associations => New_List (
25891 Make_Pragma_Argument_Association (Sloc (N),
25892 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
25893 end if;
25894
25895 -- Nothing else to do at the current time
25896
25897 end Process_Compilation_Unit_Pragmas;
25898
25899 ------------------------------------
25900 -- Record_Possible_Body_Reference --
25901 ------------------------------------
25902
25903 procedure Record_Possible_Body_Reference
25904 (State_Id : Entity_Id;
25905 Ref : Node_Id)
25906 is
25907 Context : Node_Id;
25908 Spec_Id : Entity_Id;
25909
25910 begin
25911 -- Ensure that we are dealing with a reference to a state
25912
25913 pragma Assert (Ekind (State_Id) = E_Abstract_State);
25914
25915 -- Climb the tree starting from the reference looking for a package body
25916 -- whose spec declares the referenced state. This criteria automatically
25917 -- excludes references in package specs which are legal. Note that it is
25918 -- not wise to emit an error now as the package body may lack pragma
25919 -- Refined_State or the referenced state may not be mentioned in the
25920 -- refinement. This approach avoids the generation of misleading errors.
25921
25922 Context := Ref;
25923 while Present (Context) loop
25924 if Nkind (Context) = N_Package_Body then
25925 Spec_Id := Corresponding_Spec (Context);
25926
25927 if Present (Abstract_States (Spec_Id))
25928 and then Contains (Abstract_States (Spec_Id), State_Id)
25929 then
25930 if No (Body_References (State_Id)) then
25931 Set_Body_References (State_Id, New_Elmt_List);
25932 end if;
25933
25934 Append_Elmt (Ref, Body_References (State_Id));
25935 exit;
25936 end if;
25937 end if;
25938
25939 Context := Parent (Context);
25940 end loop;
25941 end Record_Possible_Body_Reference;
25942
25943 ------------------------------
25944 -- Relocate_Pragmas_To_Body --
25945 ------------------------------
25946
25947 procedure Relocate_Pragmas_To_Body
25948 (Subp_Body : Node_Id;
25949 Target_Body : Node_Id := Empty)
25950 is
25951 procedure Relocate_Pragma (Prag : Node_Id);
25952 -- Remove a single pragma from its current list and add it to the
25953 -- declarations of the proper body (either Subp_Body or Target_Body).
25954
25955 ---------------------
25956 -- Relocate_Pragma --
25957 ---------------------
25958
25959 procedure Relocate_Pragma (Prag : Node_Id) is
25960 Decls : List_Id;
25961 Target : Node_Id;
25962
25963 begin
25964 -- When subprogram stubs or expression functions are involves, the
25965 -- destination declaration list belongs to the proper body.
25966
25967 if Present (Target_Body) then
25968 Target := Target_Body;
25969 else
25970 Target := Subp_Body;
25971 end if;
25972
25973 Decls := Declarations (Target);
25974
25975 if No (Decls) then
25976 Decls := New_List;
25977 Set_Declarations (Target, Decls);
25978 end if;
25979
25980 -- Unhook the pragma from its current list
25981
25982 Remove (Prag);
25983 Prepend (Prag, Decls);
25984 end Relocate_Pragma;
25985
25986 -- Local variables
25987
25988 Body_Id : constant Entity_Id :=
25989 Defining_Unit_Name (Specification (Subp_Body));
25990 Next_Stmt : Node_Id;
25991 Stmt : Node_Id;
25992
25993 -- Start of processing for Relocate_Pragmas_To_Body
25994
25995 begin
25996 -- Do not process a body that comes from a separate unit as no construct
25997 -- can possibly follow it.
25998
25999 if not Is_List_Member (Subp_Body) then
26000 return;
26001
26002 -- Do not relocate pragmas that follow a stub if the stub does not have
26003 -- a proper body.
26004
26005 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
26006 and then No (Target_Body)
26007 then
26008 return;
26009
26010 -- Do not process internally generated routine _Postconditions
26011
26012 elsif Ekind (Body_Id) = E_Procedure
26013 and then Chars (Body_Id) = Name_uPostconditions
26014 then
26015 return;
26016 end if;
26017
26018 -- Look at what is following the body. We are interested in certain kind
26019 -- of pragmas (either from source or byproducts of expansion) that can
26020 -- apply to a body [stub].
26021
26022 Stmt := Next (Subp_Body);
26023 while Present (Stmt) loop
26024
26025 -- Preserve the following statement for iteration purposes due to a
26026 -- possible relocation of a pragma.
26027
26028 Next_Stmt := Next (Stmt);
26029
26030 -- Move a candidate pragma following the body to the declarations of
26031 -- the body.
26032
26033 if Nkind (Stmt) = N_Pragma
26034 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
26035 then
26036 Relocate_Pragma (Stmt);
26037
26038 -- Skip internally generated code
26039
26040 elsif not Comes_From_Source (Stmt) then
26041 null;
26042
26043 -- No candidate pragmas are available for relocation
26044
26045 else
26046 exit;
26047 end if;
26048
26049 Stmt := Next_Stmt;
26050 end loop;
26051 end Relocate_Pragmas_To_Body;
26052
26053 -------------------
26054 -- Resolve_State --
26055 -------------------
26056
26057 procedure Resolve_State (N : Node_Id) is
26058 Func : Entity_Id;
26059 State : Entity_Id;
26060
26061 begin
26062 if Is_Entity_Name (N) and then Present (Entity (N)) then
26063 Func := Entity (N);
26064
26065 -- Handle overloading of state names by functions. Traverse the
26066 -- homonym chain looking for an abstract state.
26067
26068 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
26069 State := Homonym (Func);
26070 while Present (State) loop
26071
26072 -- Resolve the overloading by setting the proper entity of the
26073 -- reference to that of the state.
26074
26075 if Ekind (State) = E_Abstract_State then
26076 Set_Etype (N, Standard_Void_Type);
26077 Set_Entity (N, State);
26078 Set_Associated_Node (N, State);
26079 return;
26080 end if;
26081
26082 State := Homonym (State);
26083 end loop;
26084
26085 -- A function can never act as a state. If the homonym chain does
26086 -- not contain a corresponding state, then something went wrong in
26087 -- the overloading mechanism.
26088
26089 raise Program_Error;
26090 end if;
26091 end if;
26092 end Resolve_State;
26093
26094 ----------------------------
26095 -- Rewrite_Assertion_Kind --
26096 ----------------------------
26097
26098 procedure Rewrite_Assertion_Kind (N : Node_Id) is
26099 Nam : Name_Id;
26100
26101 begin
26102 if Nkind (N) = N_Attribute_Reference
26103 and then Attribute_Name (N) = Name_Class
26104 and then Nkind (Prefix (N)) = N_Identifier
26105 then
26106 case Chars (Prefix (N)) is
26107 when Name_Pre =>
26108 Nam := Name_uPre;
26109 when Name_Post =>
26110 Nam := Name_uPost;
26111 when Name_Type_Invariant =>
26112 Nam := Name_uType_Invariant;
26113 when Name_Invariant =>
26114 Nam := Name_uInvariant;
26115 when others =>
26116 return;
26117 end case;
26118
26119 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
26120 end if;
26121 end Rewrite_Assertion_Kind;
26122
26123 --------
26124 -- rv --
26125 --------
26126
26127 procedure rv is
26128 begin
26129 Dummy := Dummy + 1;
26130 end rv;
26131
26132 --------------------------------
26133 -- Set_Encoded_Interface_Name --
26134 --------------------------------
26135
26136 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
26137 Str : constant String_Id := Strval (S);
26138 Len : constant Int := String_Length (Str);
26139 CC : Char_Code;
26140 C : Character;
26141 J : Int;
26142
26143 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
26144
26145 procedure Encode;
26146 -- Stores encoded value of character code CC. The encoding we use an
26147 -- underscore followed by four lower case hex digits.
26148
26149 ------------
26150 -- Encode --
26151 ------------
26152
26153 procedure Encode is
26154 begin
26155 Store_String_Char (Get_Char_Code ('_'));
26156 Store_String_Char
26157 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
26158 Store_String_Char
26159 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
26160 Store_String_Char
26161 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
26162 Store_String_Char
26163 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
26164 end Encode;
26165
26166 -- Start of processing for Set_Encoded_Interface_Name
26167
26168 begin
26169 -- If first character is asterisk, this is a link name, and we leave it
26170 -- completely unmodified. We also ignore null strings (the latter case
26171 -- happens only in error cases) and no encoding should occur for Java or
26172 -- AAMP interface names.
26173
26174 if Len = 0
26175 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
26176 or else VM_Target /= No_VM
26177 or else AAMP_On_Target
26178 then
26179 Set_Interface_Name (E, S);
26180
26181 else
26182 J := 1;
26183 loop
26184 CC := Get_String_Char (Str, J);
26185
26186 exit when not In_Character_Range (CC);
26187
26188 C := Get_Character (CC);
26189
26190 exit when C /= '_' and then C /= '$'
26191 and then C not in '0' .. '9'
26192 and then C not in 'a' .. 'z'
26193 and then C not in 'A' .. 'Z';
26194
26195 if J = Len then
26196 Set_Interface_Name (E, S);
26197 return;
26198
26199 else
26200 J := J + 1;
26201 end if;
26202 end loop;
26203
26204 -- Here we need to encode. The encoding we use as follows:
26205 -- three underscores + four hex digits (lower case)
26206
26207 Start_String;
26208
26209 for J in 1 .. String_Length (Str) loop
26210 CC := Get_String_Char (Str, J);
26211
26212 if not In_Character_Range (CC) then
26213 Encode;
26214 else
26215 C := Get_Character (CC);
26216
26217 if C = '_' or else C = '$'
26218 or else C in '0' .. '9'
26219 or else C in 'a' .. 'z'
26220 or else C in 'A' .. 'Z'
26221 then
26222 Store_String_Char (CC);
26223 else
26224 Encode;
26225 end if;
26226 end if;
26227 end loop;
26228
26229 Set_Interface_Name (E,
26230 Make_String_Literal (Sloc (S),
26231 Strval => End_String));
26232 end if;
26233 end Set_Encoded_Interface_Name;
26234
26235 -------------------
26236 -- Set_Unit_Name --
26237 -------------------
26238
26239 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
26240 Pref : Node_Id;
26241 Scop : Entity_Id;
26242
26243 begin
26244 if Nkind (N) = N_Identifier
26245 and then Nkind (With_Item) = N_Identifier
26246 then
26247 Set_Entity (N, Entity (With_Item));
26248
26249 elsif Nkind (N) = N_Selected_Component then
26250 Change_Selected_Component_To_Expanded_Name (N);
26251 Set_Entity (N, Entity (With_Item));
26252 Set_Entity (Selector_Name (N), Entity (N));
26253
26254 Pref := Prefix (N);
26255 Scop := Scope (Entity (N));
26256 while Nkind (Pref) = N_Selected_Component loop
26257 Change_Selected_Component_To_Expanded_Name (Pref);
26258 Set_Entity (Selector_Name (Pref), Scop);
26259 Set_Entity (Pref, Scop);
26260 Pref := Prefix (Pref);
26261 Scop := Scope (Scop);
26262 end loop;
26263
26264 Set_Entity (Pref, Scop);
26265 end if;
26266 end Set_Unit_Name;
26267
26268 end Sem_Prag;