1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
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).
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;
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;
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;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
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;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
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:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
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).
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).
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).
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
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.
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.
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.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
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.
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.
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");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
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
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.
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.
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.
197 -- The value returned is one of the names Check, Ignore, Disable (On
198 -- returns Check, and Off returns Ignore).
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.
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,
212 procedure Check_State_And_Constituent_Use
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.
221 procedure Collect_Global_Items
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.
240 function Find_Related_Subprogram_Or_Body
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
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???
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
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.
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.
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).
282 procedure Record_Possible_Body_Reference
283 (State_Id : Entity_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).
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.
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.
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.
307 Dummy : Integer := 0;
308 pragma Volatile (Dummy);
309 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
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.
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.
329 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
332 To_List := New_Elmt_List;
335 Append_Elmt (Item, To_List);
338 -------------------------------
339 -- Adjust_External_Name_Case --
340 -------------------------------
342 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
346 -- Adjust case of literal if required
348 if Opt.External_Name_Exp_Casing = As_Is then
352 -- Copy existing string
358 for J in 1 .. String_Length (Strval (N)) loop
359 CC := Get_String_Char (Strval (N), J);
361 if Opt.External_Name_Exp_Casing = Uppercase
362 and then CC >= Get_Char_Code ('a')
363 and then CC <= Get_Char_Code ('z')
365 Store_String_Char (CC - 32);
367 elsif Opt.External_Name_Exp_Casing = Lowercase
368 and then CC >= Get_Char_Code ('A')
369 and then CC <= Get_Char_Code ('Z')
371 Store_String_Char (CC + 32);
374 Store_String_Char (CC);
379 Make_String_Literal (Sloc (N),
380 Strval => End_String);
382 end Adjust_External_Name_Case;
384 -----------------------------------------
385 -- Analyze_Contract_Cases_In_Decl_Part --
386 -----------------------------------------
388 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
389 Others_Seen : Boolean := False;
391 procedure Analyze_Contract_Case (CCase : Node_Id);
392 -- Verify the legality of a single contract case
394 ---------------------------
395 -- Analyze_Contract_Case --
396 ---------------------------
398 procedure Analyze_Contract_Case (CCase : Node_Id) is
399 Case_Guard : Node_Id;
401 Extra_Guard : Node_Id;
404 if Nkind (CCase) = N_Component_Association then
405 Case_Guard := First (Choices (CCase));
406 Conseq := Expression (CCase);
408 -- Each contract case must have exactly one case guard
410 Extra_Guard := Next (Case_Guard);
412 if Present (Extra_Guard) then
414 ("contract case must have exactly one case guard",
418 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
420 if Nkind (Case_Guard) = N_Others_Choice then
423 ("only one others choice allowed in contract cases",
429 elsif Others_Seen then
431 ("others must be the last choice in contract cases", N);
434 -- Preanalyze the case guard and consequence
436 if Nkind (Case_Guard) /= N_Others_Choice then
437 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
440 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
442 -- The contract case is malformed
445 Error_Msg_N ("wrong syntax in contract case", CCase);
447 end Analyze_Contract_Case;
456 Restore_Scope : Boolean := False;
457 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
459 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
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)));
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.
472 pragma Assert (Nkind (All_Cases) = N_Aggregate);
474 if No (Component_Associations (All_Cases)) then
475 Error_Msg_N ("wrong syntax for constract cases", N);
477 -- Individual contract cases appear as component associations
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.
485 if not In_Open_Scopes (Subp_Id) then
486 Restore_Scope := True;
487 Push_Scope (Subp_Id);
488 Install_Formals (Subp_Id);
491 CCase := First (Component_Associations (All_Cases));
492 while Present (CCase) loop
493 Analyze_Contract_Case (CCase);
497 if Restore_Scope then
501 end Analyze_Contract_Cases_In_Decl_Part;
503 ----------------------------------
504 -- Analyze_Depends_In_Decl_Part --
505 ----------------------------------
507 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
508 Loc : constant Source_Ptr := Sloc (N);
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.
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.
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.
525 Global_Seen : Boolean := False;
526 -- A flag set when pragma Global has been processed
528 Null_Output_Seen : Boolean := False;
529 -- A flag used to track the legality of a null output
531 Result_Seen : Boolean := False;
532 -- A flag set when Subp_Id'Result is processed
535 -- The entity of the subprogram subject to pragma [Refined_]Depends
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.
543 -- The entity of the subprogram [body or stub] subject to pragma
544 -- [Refined_]Depends.
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.
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"
560 procedure Analyze_Dependency_Clause
563 -- Verify the legality of a single dependency clause. Flag Is_Last
564 -- denotes whether Clause is the last clause in the relation.
566 procedure Check_Function_Return;
567 -- Verify that Funtion'Result appears as one of the outputs
568 -- (SPARK RM 6.1.5(10)).
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 "+".
582 procedure Check_Usage
583 (Subp_Items : Elist_Id;
584 Used_Items : Elist_Id;
586 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
587 -- error if this is not the case.
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
594 -----------------------------
595 -- Add_Item_To_Name_Buffer --
596 -----------------------------
598 procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is
600 if Ekind (Item_Id) = E_Abstract_State then
601 Add_Str_To_Name_Buffer ("state");
603 elsif Is_Formal (Item_Id) then
604 Add_Str_To_Name_Buffer ("parameter");
606 elsif Ekind (Item_Id) = E_Variable then
607 Add_Str_To_Name_Buffer ("global");
609 -- The routine should not be called with non-SPARK items
614 end Add_Item_To_Name_Buffer;
616 -------------------------------
617 -- Analyze_Dependency_Clause --
618 -------------------------------
620 procedure Analyze_Dependency_Clause
624 procedure Analyze_Input_List (Inputs : Node_Id);
625 -- Verify the legality of a single input list
627 procedure Analyze_Input_Output
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.
645 ------------------------
646 -- Analyze_Input_List --
647 ------------------------
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.
654 Non_Null_Input_Seen : Boolean := False;
655 Null_Input_Seen : Boolean := False;
656 -- Flags used to check the legality of an input list
661 -- Multiple inputs appear as an aggregate
663 if Nkind (Inputs) = N_Aggregate then
664 if Present (Component_Associations (Inputs)) then
666 ("nested dependency relations not allowed", Inputs);
668 elsif Present (Expressions (Inputs)) then
669 Input := First (Expressions (Inputs));
670 while Present (Input) loop
677 Null_Seen => Null_Input_Seen,
678 Non_Null_Seen => Non_Null_Input_Seen);
683 -- Syntax error, always report
686 Error_Msg_N ("malformed input dependency list", Inputs);
689 -- Process a solitary input
698 Null_Seen => Null_Input_Seen,
699 Non_Null_Seen => Non_Null_Input_Seen);
702 -- Detect an illegal dependency clause of the form
706 if Null_Output_Seen and then Null_Input_Seen then
708 ("null dependency clause cannot have a null input list",
711 end Analyze_Input_List;
713 --------------------------
714 -- Analyze_Input_Output --
715 --------------------------
717 procedure Analyze_Input_Output
722 Seen : in out Elist_Id;
723 Null_Seen : in out Boolean;
724 Non_Null_Seen : in out Boolean)
726 Is_Output : constant Boolean := not Is_Input;
731 -- Multiple input or output items appear as an aggregate
733 if Nkind (Item) = N_Aggregate then
734 if not Top_Level then
735 SPARK_Msg_N ("nested grouping of items not allowed", Item);
737 elsif Present (Component_Associations (Item)) then
739 ("nested dependency relations not allowed", Item);
741 -- Recursively analyze the grouped items
743 elsif Present (Expressions (Item)) then
744 Grouped := First (Expressions (Item));
745 while Present (Grouped) loop
748 Is_Input => Is_Input,
749 Self_Ref => Self_Ref,
752 Null_Seen => Null_Seen,
753 Non_Null_Seen => Non_Null_Seen);
758 -- Syntax error, always report
761 Error_Msg_N ("malformed dependency list", Item);
764 -- Process Function'Result in the context of a dependency clause
766 elsif Is_Attribute_Result (Item) then
767 Non_Null_Seen := True;
769 -- It is sufficent to analyze the prefix of 'Result in order to
770 -- establish legality of the attribute.
772 Analyze (Prefix (Item));
774 -- The prefix of 'Result must denote the function for which
775 -- pragma Depends applies (SPARK RM 6.1.5(11)).
777 if not Is_Entity_Name (Prefix (Item))
778 or else Ekind (Spec_Id) /= E_Function
779 or else Entity (Prefix (Item)) /= Spec_Id
781 Error_Msg_Name_1 := Name_Result;
783 ("prefix of attribute % must denote the enclosing "
786 -- Function'Result is allowed to appear on the output side of a
787 -- dependency clause (SPARK RM 6.1.5(6)).
790 SPARK_Msg_N ("function result cannot act as input", Item);
794 ("cannot mix null and non-null dependency items", Item);
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)).
804 elsif Nkind (Item) = N_Null then
807 ("multiple null dependency relations not allowed", Item);
809 elsif Non_Null_Seen then
811 ("cannot mix null and non-null dependency items", Item);
819 ("null output list must be the last clause in a "
820 & "dependency relation", Item);
822 -- Catch a useless dependence of the form:
827 ("useless dependence, null depends on itself", Item);
835 Non_Null_Seen := True;
838 SPARK_Msg_N ("cannot mix null and non-null items", Item);
842 Resolve_State (Item);
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).
848 Item_Id := Entity_Of (Item);
850 if Present (Item_Id) then
851 if Ekind_In (Item_Id, E_Abstract_State,
857 -- Ensure that the item fulfils its role as input and/or
858 -- output as specified by pragma Global or the enclosing
861 Check_Role (Item, Item_Id, Is_Input, Self_Ref);
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.
867 if Contains (Seen, Item_Id) then
869 ("duplicate use of item &", Item, Item_Id);
871 Add_Item (Item_Id, Seen);
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)).
879 and then Null_Output_Seen
880 and then Contains (All_Inputs_Seen, Item_Id)
883 ("input of a null output list cannot appear in "
884 & "multiple input lists", Item);
887 -- Add an input or a self-referential output to the list
888 -- of all processed inputs.
890 if Is_Input or else Self_Ref then
891 Add_Item (Item_Id, All_Inputs_Seen);
894 -- State related checks (SPARK RM 6.1.5(3))
896 if Ekind (Item_Id) = E_Abstract_State then
897 if Has_Visible_Refinement (Item_Id) then
899 ("cannot mention state & in global refinement",
902 ("\use its constituents instead", Item);
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
911 Record_Possible_Body_Reference
912 (State_Id => Item_Id,
917 -- When the item renames an entire object, replace the
918 -- item with a reference to the object.
920 if Present (Renamed_Object (Entity (Item))) then
922 New_Occurrence_Of (Item_Id, Sloc (Item)));
926 -- Add the entity of the current item to the list of
929 if Ekind (Item_Id) = E_Abstract_State then
930 Add_Item (Item_Id, States_Seen);
933 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
934 and then Present (Encapsulating_State (Item_Id))
936 Add_Item (Item_Id, Constits_Seen);
939 -- All other input/output items are illegal
940 -- (SPARK RM 6.1.5(1)).
944 ("item must denote parameter, variable, or state",
948 -- All other input/output items are illegal
949 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
953 ("item must denote parameter, variable, or state", Item);
956 end Analyze_Input_Output;
964 Non_Null_Output_Seen : Boolean := False;
965 -- Flag used to check the legality of an output list
967 -- Start of processing for Analyze_Dependency_Clause
970 Inputs := Expression (Clause);
973 -- An input list with a self-dependency appears as operator "+" where
974 -- the actuals inputs are the right operand.
976 if Nkind (Inputs) = N_Op_Plus then
977 Inputs := Right_Opnd (Inputs);
981 -- Process the output_list of a dependency_clause
983 Output := First (Choices (Clause));
984 while Present (Output) loop
988 Self_Ref => Self_Ref,
990 Seen => All_Outputs_Seen,
991 Null_Seen => Null_Output_Seen,
992 Non_Null_Seen => Non_Null_Output_Seen);
997 -- Process the input_list of a dependency_clause
999 Analyze_Input_List (Inputs);
1000 end Analyze_Dependency_Clause;
1002 ---------------------------
1003 -- Check_Function_Return --
1004 ---------------------------
1006 procedure Check_Function_Return is
1008 if Ekind (Spec_Id) = E_Function and then not Result_Seen then
1010 ("result of & must appear in exactly one output list",
1013 end Check_Function_Return;
1019 procedure Check_Role
1021 Item_Id : Entity_Id;
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.
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.
1043 (Item_Is_Input : out Boolean;
1044 Item_Is_Output : out Boolean)
1047 Item_Is_Input := False;
1048 Item_Is_Output := False;
1050 -- Abstract state cases
1052 if Ekind (Item_Id) = E_Abstract_State then
1054 -- When pragma Global is present, the mode of the state may be
1055 -- further constrained by setting a more restrictive mode.
1058 if Appears_In (Subp_Inputs, Item_Id) then
1059 Item_Is_Input := True;
1062 if Appears_In (Subp_Outputs, Item_Id) then
1063 Item_Is_Output := True;
1066 -- Otherwise the state has a default IN OUT mode
1069 Item_Is_Input := True;
1070 Item_Is_Output := True;
1075 elsif Ekind (Item_Id) = E_In_Parameter then
1076 Item_Is_Input := True;
1078 elsif Ekind (Item_Id) = E_In_Out_Parameter then
1079 Item_Is_Input := True;
1080 Item_Is_Output := True;
1082 elsif Ekind (Item_Id) = E_Out_Parameter then
1083 if Scope (Item_Id) = Spec_Id then
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.
1089 if Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1090 Item_Is_Input := True;
1093 Item_Is_Output := True;
1095 -- An OUT parameter of an enclosing subprogram behaves as a
1096 -- read-write variable in which case the mode is IN OUT.
1099 Item_Is_Input := True;
1100 Item_Is_Output := True;
1105 else pragma Assert (Ekind (Item_Id) = E_Variable);
1107 -- When pragma Global is present, the mode of the variable may
1108 -- be further constrained by setting a more restrictive mode.
1112 -- A variable has mode IN when its type is unconstrained or
1113 -- tagged because array bounds, discriminants or tags can be
1116 if Appears_In (Subp_Inputs, Item_Id)
1117 or else Is_Unconstrained_Or_Tagged_Item (Item_Id)
1119 Item_Is_Input := True;
1122 if Appears_In (Subp_Outputs, Item_Id) then
1123 Item_Is_Output := True;
1126 -- Otherwise the variable has a default IN OUT mode
1129 Item_Is_Input := True;
1130 Item_Is_Output := True;
1139 procedure Role_Error
1140 (Item_Is_Input : Boolean;
1141 Item_Is_Output : Boolean)
1143 Error_Msg : Name_Id;
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.
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");
1157 Error_Msg := Name_Find;
1158 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1160 Error_Msg_Name_1 := Chars (Subp_Id);
1162 ("\& is not part of the input or output set of subprogram %",
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)).
1170 if Item_Is_Input then
1171 Add_Str_To_Name_Buffer ("read-only");
1173 Add_Str_To_Name_Buffer ("write-only");
1176 Add_Char_To_Name_Buffer (' ');
1177 Add_Item_To_Name_Buffer (Item_Id);
1178 Add_Str_To_Name_Buffer (" & cannot appear as ");
1180 if Item_Is_Input then
1181 Add_Str_To_Name_Buffer ("output");
1183 Add_Str_To_Name_Buffer ("input");
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);
1194 Item_Is_Input : Boolean;
1195 Item_Is_Output : Boolean;
1197 -- Start of processing for Check_Role
1200 Find_Role (Item_Is_Input, Item_Is_Output);
1205 if not Item_Is_Input then
1206 Role_Error (Item_Is_Input, Item_Is_Output);
1209 -- Self-referential item
1212 if not Item_Is_Input or else not Item_Is_Output then
1213 Role_Error (Item_Is_Input, Item_Is_Output);
1218 elsif not Item_Is_Output then
1219 Role_Error (Item_Is_Input, Item_Is_Output);
1227 procedure Check_Usage
1228 (Subp_Items : Elist_Id;
1229 Used_Items : Elist_Id;
1232 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
1233 -- Emit an error concerning the illegal usage of an item
1239 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
1240 Error_Msg : Name_Id;
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)).
1252 if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then
1255 Add_Item_To_Name_Buffer (Item_Id);
1256 Add_Str_To_Name_Buffer
1257 (" & must appear in at least one input dependence list");
1259 Error_Msg := Name_Find;
1260 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1263 -- Output case (SPARK RM 6.1.5(10))
1268 Add_Item_To_Name_Buffer (Item_Id);
1269 Add_Str_To_Name_Buffer
1270 (" & must appear in exactly one output dependence list");
1272 Error_Msg := Name_Find;
1273 SPARK_Msg_NE (Get_Name_String (Error_Msg), Item, Item_Id);
1281 Item_Id : Entity_Id;
1283 -- Start of processing for Check_Usage
1286 if No (Subp_Items) then
1290 -- Each input or output of the subprogram must appear in a dependency
1293 Elmt := First_Elmt (Subp_Items);
1294 while Present (Elmt) loop
1295 Item := Node (Elmt);
1297 if Nkind (Item) = N_Defining_Identifier then
1300 Item_Id := Entity_Of (Item);
1303 -- The item does not appear in a dependency
1305 if Present (Item_Id)
1306 and then not Contains (Used_Items, Item_Id)
1308 if Is_Formal (Item_Id) then
1309 Usage_Error (Item, Item_Id);
1311 -- States and global variables are not used properly only when
1312 -- the subprogram is subject to pragma Global.
1314 elsif Global_Seen then
1315 Usage_Error (Item, Item_Id);
1323 ----------------------
1324 -- Normalize_Clause --
1325 ----------------------
1327 procedure Normalize_Clause (Clause : Node_Id) is
1328 procedure Create_Or_Modify_Clause
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
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
1349 -----------------------------
1350 -- Create_Or_Modify_Clause --
1351 -----------------------------
1353 procedure Create_Or_Modify_Clause
1361 procedure Propagate_Output
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.
1368 ----------------------
1369 -- Propagate_Output --
1370 ----------------------
1372 procedure Propagate_Output
1376 function In_Input_List
1378 Inputs : List_Id) return Boolean;
1379 -- Determine whether a particulat item appears in the input
1380 -- list of a clause.
1386 function In_Input_List
1388 Inputs : List_Id) return Boolean
1393 Elmt := First (Inputs);
1394 while Present (Elmt) loop
1395 if Entity_Of (Elmt) = Item then
1407 Output_Id : constant Entity_Id := Entity_Of (Output);
1410 -- Start of processing for Propagate_Output
1413 -- The clause is of the form:
1415 -- (Output =>+ null)
1417 -- Remove the null input and replace it with a copy of the
1420 -- (Output => Output)
1422 if Nkind (Inputs) = N_Null then
1423 Rewrite (Inputs, New_Copy_Tree (Output));
1425 -- The clause is of the form:
1427 -- (Output =>+ (Input1, ..., InputN))
1429 -- Determine whether the output is not already mentioned in the
1430 -- input list and if not, add it to the list of inputs:
1432 -- (Output => (Output, Input1, ..., InputN))
1434 elsif Nkind (Inputs) = N_Aggregate then
1435 Grouped := Expressions (Inputs);
1437 if not In_Input_List
1441 Prepend_To (Grouped, New_Copy_Tree (Output));
1444 -- The clause is of the form:
1446 -- (Output =>+ Input)
1448 -- If the input does not mention the output, group the two
1451 -- (Output => (Output, Input))
1453 elsif Entity_Of (Inputs) /= Output_Id then
1455 Make_Aggregate (Loc,
1456 Expressions => New_List (
1457 New_Copy_Tree (Output),
1458 New_Copy_Tree (Inputs))));
1460 end Propagate_Output;
1464 Loc : constant Source_Ptr := Sloc (Clause);
1465 New_Clause : Node_Id;
1467 -- Start of processing for Create_Or_Modify_Clause
1470 -- A null output depending on itself does not require any
1473 if Nkind (Output) = N_Null then
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)).
1479 elsif Is_Attribute_Result (Output) then
1480 SPARK_Msg_N ("function result cannot depend on itself", Output);
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
1491 Propagate_Output (Output, Inputs);
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.
1499 Rewrite (Outputs, Output);
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
1512 -- Generate a new clause of the form:
1513 -- (Output => Inputs)
1516 Make_Component_Association (Loc,
1517 Choices => New_List (Output),
1518 Expression => New_Copy_Tree (Inputs));
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.
1524 Set_Analyzed (New_Clause);
1527 (Output => First (Choices (New_Clause)),
1528 Inputs => Expression (New_Clause));
1530 Insert_After (After, New_Clause);
1532 end Create_Or_Modify_Clause;
1534 -----------------------
1535 -- Normalize_Outputs --
1536 -----------------------
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;
1548 -- Multiple outputs appear as an aggregate. Nothing to do when
1549 -- the clause has exactly one output.
1551 if Nkind (Outputs) = N_Aggregate then
1552 Last_Output := Last (Expressions (Outputs));
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.
1558 Output := First (Expressions (Outputs));
1559 while Present (Output) loop
1560 Next_Output := Next (Output);
1562 -- Unhook the output from the original output list as it
1563 -- will be relocated to a new clause.
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.
1571 if Output = Last_Output then
1572 Rewrite (Outputs, Output);
1575 -- Generate a clause of the form:
1576 -- (Output => Inputs)
1579 Make_Component_Association (Loc,
1580 Choices => New_List (Output),
1581 Expression => New_Copy_Tree (Inputs));
1583 -- The new clause contains replicated content that has
1584 -- already been analyzed. There is not need to reanalyze
1587 Set_Analyzed (New_Clause);
1588 Insert_After (Clause, New_Clause);
1591 Output := Next_Output;
1594 end Normalize_Outputs;
1598 Outputs : constant Node_Id := First (Choices (Clause));
1600 Last_Output : Node_Id;
1601 Next_Output : Node_Id;
1604 -- Start of processing for Normalize_Clause
1607 -- A self-dependency appears as operator "+". Remove the "+" from the
1608 -- tree by moving the real inputs to their proper place.
1610 if Nkind (Expression (Clause)) = N_Op_Plus then
1611 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1612 Inputs := Expression (Clause);
1614 -- Multiple outputs appear as an aggregate
1616 if Nkind (Outputs) = N_Aggregate then
1617 Last_Output := Last (Expressions (Outputs));
1619 Output := First (Expressions (Outputs));
1620 while Present (Output) loop
1622 -- Normalization may remove an output from its list,
1623 -- preserve the subsequent output now.
1625 Next_Output := Next (Output);
1627 Create_Or_Modify_Clause
1632 In_Place => Output = Last_Output,
1635 Output := Next_Output;
1641 Create_Or_Modify_Clause
1651 -- Split a clause with multiple outputs into multiple clauses with a
1655 end Normalize_Clause;
1659 Deps : constant Node_Id :=
1661 (First (Pragma_Argument_Associations (N)));
1664 Last_Clause : Node_Id;
1665 Subp_Decl : Node_Id;
1667 Restore_Scope : Boolean := False;
1668 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1670 -- Start of processing for Analyze_Depends_In_Decl_Part
1675 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
1676 Subp_Id := Defining_Entity (Subp_Decl);
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
1683 if Nkind (Subp_Decl) = N_Subprogram_Body
1684 and then Present (Corresponding_Spec (Subp_Decl))
1686 Spec_Id := Corresponding_Spec (Subp_Decl);
1688 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
1689 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
1691 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
1697 -- Empty dependency list
1699 if Nkind (Deps) = N_Null then
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).
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);
1711 -- Verify that every input or output of the subprogram appear in a
1714 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1715 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1716 Check_Function_Return;
1718 -- Dependency clauses appear as component associations of an aggregate
1720 elsif Nkind (Deps) = N_Aggregate then
1722 -- Do not attempt to perform analysis of a syntactically illegal
1723 -- clause as this will lead to misleading errors.
1725 if Has_Extra_Parentheses (Deps) then
1729 if Present (Component_Associations (Deps)) then
1730 Last_Clause := Last (Component_Associations (Deps));
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).
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);
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.
1747 if not In_Open_Scopes (Spec_Id) then
1748 Restore_Scope := True;
1749 Push_Scope (Spec_Id);
1750 Install_Formals (Spec_Id);
1753 Clause := First (Component_Associations (Deps));
1754 while Present (Clause) loop
1755 Errors := Serious_Errors_Detected;
1757 -- Normalization may create extra clauses that contain
1758 -- replicated input and output names. There is no need to
1761 if not Analyzed (Clause) then
1762 Set_Analyzed (Clause);
1764 Analyze_Dependency_Clause
1766 Is_Last => Clause = Last_Clause);
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.
1775 if Serious_Errors_Detected = Errors and then not ASIS_Mode then
1776 Normalize_Clause (Clause);
1782 if Restore_Scope then
1786 -- Verify that every input or output of the subprogram appear in a
1789 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1790 Check_Usage (Subp_Outputs, All_Outputs_Seen, False);
1791 Check_Function_Return;
1793 -- The dependency list is malformed. This is a syntax error, always
1797 Error_Msg_N ("malformed dependency relation", Deps);
1801 -- The top level dependency relation is malformed. This is a syntax
1802 -- error, always report.
1805 Error_Msg_N ("malformed dependency relation", Deps);
1809 -- Ensure that a state and a corresponding constituent do not appear
1810 -- together in pragma [Refined_]Depends.
1812 Check_State_And_Constituent_Use
1813 (States => States_Seen,
1814 Constits => Constits_Seen,
1816 end Analyze_Depends_In_Decl_Part;
1818 --------------------------------------------
1819 -- Analyze_External_Property_In_Decl_Part --
1820 --------------------------------------------
1822 procedure Analyze_External_Property_In_Decl_Part
1824 Expr_Val : out Boolean)
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));
1831 Error_Msg_Name_1 := Pragma_Name (N);
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:
1839 -- pragma Async_Readers (Obj);
1840 -- pragma Volatile (Obj);
1842 if not Is_SPARK_Volatile (Obj_Id) then
1844 ("external property % must apply to a volatile object", N);
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)).
1852 if Present (Expr) then
1853 Analyze_And_Resolve (Expr, Standard_Boolean);
1855 if Is_OK_Static_Expression (Expr) then
1856 Expr_Val := Is_True (Expr_Value (Expr));
1858 SPARK_Msg_N ("expression of % must be static", Expr);
1861 end Analyze_External_Property_In_Decl_Part;
1863 ---------------------------------
1864 -- Analyze_Global_In_Decl_Part --
1865 ---------------------------------
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.
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.
1877 Spec_Id : Entity_Id;
1878 -- The entity of the subprogram subject to pragma [Refined_]Global
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.
1885 Subp_Id : Entity_Id;
1886 -- The entity of the subprogram [body or stub] subject to pragma
1887 -- [Refined_]Global.
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
1895 procedure Analyze_Global_List
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.
1901 -------------------------
1902 -- Analyze_Global_List --
1903 -------------------------
1905 procedure Analyze_Global_List
1907 Global_Mode : Name_Id := Name_Input)
1909 procedure Analyze_Global_Item
1911 Global_Mode : Name_Id);
1912 -- Verify the legality of a single global item declaration.
1913 -- Global_Mode denotes the current mode in effect.
1915 procedure Check_Duplicate_Mode
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)).
1922 procedure Check_Mode_Restriction_In_Enclosing_Context
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.
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)).
1935 -------------------------
1936 -- Analyze_Global_Item --
1937 -------------------------
1939 procedure Analyze_Global_Item
1941 Global_Mode : Name_Id)
1943 Item_Id : Entity_Id;
1946 -- Detect one of the following cases
1948 -- with Global => (null, Name)
1949 -- with Global => (Name_1, null, Name_2)
1950 -- with Global => (Name, null)
1952 if Nkind (Item) = N_Null then
1953 SPARK_Msg_N ("cannot mix null and non-null global items", Item);
1958 Resolve_State (Item);
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).
1964 Item_Id := Entity_Of (Item);
1966 if Present (Item_Id) then
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.
1972 if Is_Formal (Item_Id) then
1973 if Scope (Item_Id) = Spec_Id then
1975 ("global item cannot reference parameter of subprogram",
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.
1983 elsif Ekind (Item_Id) = E_Constant then
1984 SPARK_Msg_N ("global item cannot denote a constant", Item);
1986 -- The only legal references are those to abstract states and
1987 -- variables (SPARK RM 6.1.4(4)).
1989 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1991 ("global item must denote variable or state", Item);
1995 -- State related checks
1997 if Ekind (Item_Id) = E_Abstract_State then
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)).
2003 if Has_Visible_Refinement (Item_Id) then
2005 ("cannot mention state & in global refinement",
2007 SPARK_Msg_N ("\use its constituents instead", Item);
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.
2015 Record_Possible_Body_Reference
2016 (State_Id => Item_Id,
2020 -- Variable related checks. These are only relevant when
2021 -- SPARK_Mode is on as they are not standard Ada legality
2024 elsif SPARK_Mode = On and then Is_SPARK_Volatile (Item_Id) then
2026 -- A volatile object cannot appear as a global item of a
2027 -- function (SPARK RM 7.1.3(9)).
2029 if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
2031 ("volatile object & cannot act as global item of a "
2032 & "function", Item, Item_Id);
2035 -- A volatile object with property Effective_Reads set to
2036 -- True must have mode Output or In_Out.
2038 elsif Effective_Reads_Enabled (Item_Id)
2039 and then Global_Mode = Name_Input
2042 ("volatile object & with property Effective_Reads must "
2043 & "have mode In_Out or Output (SPARK RM 7.1.3(11))",
2049 -- When the item renames an entire object, replace the item
2050 -- with a reference to the object.
2052 if Present (Renamed_Object (Entity (Item))) then
2053 Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item)));
2057 -- Some form of illegal construct masquerading as a name
2058 -- (SPARK RM 6.1.4(4)).
2061 Error_Msg_N ("global item must denote variable or state", Item);
2065 -- Verify that an output does not appear as an input in an
2066 -- enclosing subprogram.
2068 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
2069 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
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)).
2076 if Contains (Seen, Item_Id) then
2077 SPARK_Msg_N ("duplicate global item", Item);
2079 -- Add the entity of the current item to the list of processed
2083 Add_Item (Item_Id, Seen);
2085 if Ekind (Item_Id) = E_Abstract_State then
2086 Add_Item (Item_Id, States_Seen);
2089 if Ekind_In (Item_Id, E_Abstract_State, E_Variable)
2090 and then Present (Encapsulating_State (Item_Id))
2092 Add_Item (Item_Id, Constits_Seen);
2095 end Analyze_Global_Item;
2097 --------------------------
2098 -- Check_Duplicate_Mode --
2099 --------------------------
2101 procedure Check_Duplicate_Mode
2103 Status : in out Boolean)
2107 SPARK_Msg_N ("duplicate global mode", Mode);
2111 end Check_Duplicate_Mode;
2113 -------------------------------------------------
2114 -- Check_Mode_Restriction_In_Enclosing_Context --
2115 -------------------------------------------------
2117 procedure Check_Mode_Restriction_In_Enclosing_Context
2119 Item_Id : Entity_Id)
2121 Context : Entity_Id;
2123 Inputs : Elist_Id := No_Elist;
2124 Outputs : Elist_Id := No_Elist;
2127 -- Traverse the scope stack looking for enclosing subprograms
2128 -- subject to pragma [Refined_]Global.
2130 Context := Scope (Subp_Id);
2131 while Present (Context) and then Context /= Standard_Standard loop
2132 if Is_Subprogram (Context)
2134 (Present (Get_Pragma (Context, Pragma_Global))
2136 Present (Get_Pragma (Context, Pragma_Refined_Global)))
2138 Collect_Subprogram_Inputs_Outputs
2139 (Subp_Id => Context,
2140 Subp_Inputs => Inputs,
2141 Subp_Outputs => Outputs,
2142 Global_Seen => Dummy);
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)).
2147 if Appears_In (Inputs, Item_Id)
2148 and then not Appears_In (Outputs, Item_Id)
2151 ("global item & cannot have mode In_Out or Output",
2154 ("\item already appears as input of subprogram &",
2157 -- Stop the traversal once an error has been detected
2163 Context := Scope (Context);
2165 end Check_Mode_Restriction_In_Enclosing_Context;
2167 ----------------------------------------
2168 -- Check_Mode_Restriction_In_Function --
2169 ----------------------------------------
2171 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
2173 if Ekind (Spec_Id) = E_Function then
2175 ("global mode & is not applicable to functions", Mode);
2177 end Check_Mode_Restriction_In_Function;
2185 -- Start of processing for Analyze_Global_List
2188 if Nkind (List) = N_Null then
2189 Set_Analyzed (List);
2191 -- Single global item declaration
2193 elsif Nkind_In (List, N_Expanded_Name,
2195 N_Selected_Component)
2197 Analyze_Global_Item (List, Global_Mode);
2199 -- Simple global list or moded global list declaration
2201 elsif Nkind (List) = N_Aggregate then
2202 Set_Analyzed (List);
2204 -- The declaration of a simple global list appear as a collection
2207 if Present (Expressions (List)) then
2208 if Present (Component_Associations (List)) then
2210 ("cannot mix moded and non-moded global lists", List);
2213 Item := First (Expressions (List));
2214 while Present (Item) loop
2215 Analyze_Global_Item (Item, Global_Mode);
2220 -- The declaration of a moded global list appears as a collection
2221 -- of component associations where individual choices denote
2224 elsif Present (Component_Associations (List)) then
2225 if Present (Expressions (List)) then
2227 ("cannot mix moded and non-moded global lists", List);
2230 Assoc := First (Component_Associations (List));
2231 while Present (Assoc) loop
2232 Mode := First (Choices (Assoc));
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);
2239 elsif Chars (Mode) = Name_Input then
2240 Check_Duplicate_Mode (Mode, Input_Seen);
2242 elsif Chars (Mode) = Name_Output then
2243 Check_Duplicate_Mode (Mode, Output_Seen);
2244 Check_Mode_Restriction_In_Function (Mode);
2246 elsif Chars (Mode) = Name_Proof_In then
2247 Check_Duplicate_Mode (Mode, Proof_Seen);
2250 SPARK_Msg_N ("invalid mode selector", Mode);
2254 SPARK_Msg_N ("invalid mode selector", Mode);
2257 -- Items in a moded list appear as a collection of
2258 -- expressions. Reuse the existing machinery to analyze
2262 (List => Expression (Assoc),
2263 Global_Mode => Chars (Mode));
2271 raise Program_Error;
2274 -- Any other attempt to declare a global item is illegal. This is a
2275 -- syntax error, always report.
2278 Error_Msg_N ("malformed global list", List);
2280 end Analyze_Global_List;
2284 Items : constant Node_Id :=
2285 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2286 Subp_Decl : Node_Id;
2288 Restore_Scope : Boolean := False;
2289 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
2291 -- Start of processing for Analyze_Global_In_Decl_List
2295 Check_SPARK_Aspect_For_ASIS (N);
2297 Subp_Decl := Find_Related_Subprogram_Or_Body (N);
2298 Subp_Id := Defining_Entity (Subp_Decl);
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
2305 if Nkind (Subp_Decl) = N_Subprogram_Body
2306 and then Present (Corresponding_Spec (Subp_Decl))
2308 Spec_Id := Corresponding_Spec (Subp_Decl);
2310 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
2311 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
2313 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
2319 -- There is nothing to be done for a null global list
2321 if Nkind (Items) = N_Null then
2322 Set_Analyzed (Items);
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
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.
2333 if not In_Open_Scopes (Spec_Id) then
2334 Restore_Scope := True;
2335 Push_Scope (Spec_Id);
2336 Install_Formals (Spec_Id);
2339 Analyze_Global_List (Items);
2341 if Restore_Scope then
2346 -- Ensure that a state and a corresponding constituent do not appear
2347 -- together in pragma [Refined_]Global.
2349 Check_State_And_Constituent_Use
2350 (States => States_Seen,
2351 Constits => Constits_Seen,
2353 end Analyze_Global_In_Decl_Part;
2355 --------------------------------------------
2356 -- Analyze_Initial_Condition_In_Decl_Part --
2357 --------------------------------------------
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)));
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.
2370 Preanalyze_And_Resolve (Expr, Standard_Boolean);
2371 end Analyze_Initial_Condition_In_Decl_Part;
2373 --------------------------------------
2374 -- Analyze_Initializes_In_Decl_Part --
2375 --------------------------------------
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));
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.
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.
2390 Non_Null_Seen : Boolean := False;
2391 Null_Seen : Boolean := False;
2392 -- Flags used to check the legality of a null initialization list
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.
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.
2404 procedure Analyze_Initialization_Item (Item : Node_Id);
2405 -- Verify the legality of a single initialization item
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.
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.
2415 ---------------------------------
2416 -- Analyze_Initialization_Item --
2417 ---------------------------------
2419 procedure Analyze_Initialization_Item (Item : Node_Id) is
2420 Item_Id : Entity_Id;
2423 -- Null initialization list
2425 if Nkind (Item) = N_Null then
2427 SPARK_Msg_N ("multiple null initializations not allowed", Item);
2429 elsif Non_Null_Seen then
2431 ("cannot mix null and non-null initialization items", Item);
2436 -- Initialization item
2439 Non_Null_Seen := True;
2443 ("cannot mix null and non-null initialization items", Item);
2447 Resolve_State (Item);
2449 if Is_Entity_Name (Item) then
2450 Item_Id := Entity_Of (Item);
2452 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
2454 -- The state or variable must be declared in the visible
2455 -- declarations of the package (SPARK RM 7.1.5(7)).
2457 if not Contains (States_And_Vars, Item_Id) then
2458 Error_Msg_Name_1 := Chars (Pack_Id);
2460 ("initialization item & must appear in the visible "
2461 & "declarations of package %", Item, Item_Id);
2463 -- Detect a duplicate use of the same initialization item
2464 -- (SPARK RM 7.1.5(5)).
2466 elsif Contains (Items_Seen, Item_Id) then
2467 SPARK_Msg_N ("duplicate initialization item", Item);
2469 -- The item is legal, add it to the list of processed states
2473 Add_Item (Item_Id, Items_Seen);
2475 if Ekind (Item_Id) = E_Abstract_State then
2476 Add_Item (Item_Id, States_Seen);
2479 if Present (Encapsulating_State (Item_Id)) then
2480 Add_Item (Item_Id, Constits_Seen);
2484 -- The item references something that is not a state or a
2485 -- variable (SPARK RM 7.1.5(3)).
2489 ("initialization item must denote variable or state",
2493 -- Some form of illegal construct masquerading as a name
2494 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2498 ("initialization item must denote variable or state", Item);
2501 end Analyze_Initialization_Item;
2503 ---------------------------------------------
2504 -- Analyze_Initialization_Item_With_Inputs --
2505 ---------------------------------------------
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.
2512 Non_Null_Seen : Boolean := False;
2513 Null_Seen : Boolean := False;
2514 -- Flags used to check the legality of an input list
2516 procedure Analyze_Input_Item (Input : Node_Id);
2517 -- Verify the legality of a single input item
2519 ------------------------
2520 -- Analyze_Input_Item --
2521 ------------------------
2523 procedure Analyze_Input_Item (Input : Node_Id) is
2524 Input_Id : Entity_Id;
2529 if Nkind (Input) = N_Null then
2532 ("multiple null initializations not allowed", Item);
2534 elsif Non_Null_Seen then
2536 ("cannot mix null and non-null initialization item", Item);
2544 Non_Null_Seen := True;
2548 ("cannot mix null and non-null initialization item", Item);
2552 Resolve_State (Input);
2554 if Is_Entity_Name (Input) then
2555 Input_Id := Entity_Of (Input);
2557 if Ekind_In (Input_Id, E_Abstract_State,
2563 -- The input cannot denote states or variables declared
2564 -- within the related package.
2566 if Within_Scope (Input_Id, Current_Scope) then
2567 Error_Msg_Name_1 := Chars (Pack_Id);
2569 ("input item & cannot denote a visible variable or "
2570 & "state of package % (SPARK RM 7.1.5(4))",
2573 -- Detect a duplicate use of the same input item
2574 -- (SPARK RM 7.1.5(5)).
2576 elsif Contains (Inputs_Seen, Input_Id) then
2577 SPARK_Msg_N ("duplicate input item", Input);
2579 -- Input is legal, add it to the list of processed inputs
2582 Add_Item (Input_Id, Inputs_Seen);
2584 if Ekind (Input_Id) = E_Abstract_State then
2585 Add_Item (Input_Id, States_Seen);
2588 if Ekind_In (Input_Id, E_Abstract_State, E_Variable)
2589 and then Present (Encapsulating_State (Input_Id))
2591 Add_Item (Input_Id, Constits_Seen);
2595 -- The input references something that is not a state or a
2596 -- variable (SPARK RM 7.1.5(3)).
2600 ("input item must denote variable or state", Input);
2603 -- Some form of illegal construct masquerading as a name
2604 -- (SPARK RM 7.1.5(3)).
2608 ("input item must denote variable or state", Input);
2611 end Analyze_Input_Item;
2615 Inputs : constant Node_Id := Expression (Item);
2619 Name_Seen : Boolean := False;
2620 -- A flag used to detect multiple item names
2622 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2625 -- Inspect the name of an item with inputs
2627 Elmt := First (Choices (Item));
2628 while Present (Elmt) loop
2630 SPARK_Msg_N ("only one item allowed in initialization", Elmt);
2633 Analyze_Initialization_Item (Elmt);
2639 -- Multiple input items appear as an aggregate
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);
2650 if Present (Component_Associations (Inputs)) then
2652 ("inputs must appear in named association form", Inputs);
2655 -- Single input item
2658 Analyze_Input_Item (Inputs);
2660 end Analyze_Initialization_Item_With_Inputs;
2662 ----------------------------------
2663 -- Collect_States_And_Variables --
2664 ----------------------------------
2666 procedure Collect_States_And_Variables is
2670 -- Collect the abstract states defined in the package (if any)
2672 if Present (Abstract_States (Pack_Id)) then
2673 States_And_Vars := New_Copy_Elist (Abstract_States (Pack_Id));
2676 -- Collect all variables the appear in the visible declarations of
2677 -- the related package.
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)
2686 Add_Item (Defining_Entity (Decl), States_And_Vars);
2692 end Collect_States_And_Variables;
2696 Inits : constant Node_Id :=
2697 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
2700 -- Start of processing for Analyze_Initializes_In_Decl_Part
2705 Check_SPARK_Aspect_For_ASIS (N);
2707 -- Nothing to do when the initialization list is empty
2709 if Nkind (Inits) = N_Null then
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.
2717 pragma Assert (Nkind (Inits) = N_Aggregate);
2719 -- Initialize the various lists used during analysis
2721 Collect_States_And_Variables;
2723 if Present (Expressions (Inits)) then
2724 Init := First (Expressions (Inits));
2725 while Present (Init) loop
2726 Analyze_Initialization_Item (Init);
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);
2739 -- Ensure that a state and a corresponding constituent do not appear
2740 -- together in pragma Initializes.
2742 Check_State_And_Constituent_Use
2743 (States => States_Seen,
2744 Constits => Constits_Seen,
2746 end Analyze_Initializes_In_Decl_Part;
2748 --------------------
2749 -- Analyze_Pragma --
2750 --------------------
2752 procedure Analyze_Pragma (N : Node_Id) is
2753 Loc : constant Source_Ptr := Sloc (N);
2754 Prag_Id : Pragma_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.
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.
2768 -- Number of pragma argument associations
2774 -- First four pragma arguments (pragma argument association nodes, or
2775 -- Empty if the corresponding argument does not exist).
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
2781 -----------------------
2782 -- Local Subprograms --
2783 -----------------------
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.
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.
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.
2801 procedure Analyze_Part_Of
2802 (Item_Id : Entity_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.
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.
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
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.
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.
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).
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.
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.
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.
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.
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.
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.
2872 procedure Check_Arg_Is_One_Of
2875 procedure Check_Arg_Is_One_Of
2877 N1, N2, N3 : Name_Id);
2878 procedure Check_Arg_Is_One_Of
2880 N1, N2, N3, N4 : Name_Id);
2881 procedure Check_Arg_Is_One_Of
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.
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.
2892 procedure Check_Arg_Is_OK_Static_Expression
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.
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.
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.
2911 procedure Check_At_Least_N_Arguments (N : Nat);
2912 -- Check there are at least N arguments present
2914 procedure Check_At_Most_N_Arguments (N : Nat);
2915 -- Check there are no more than N arguments present
2917 procedure Check_Component
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.
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.
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.
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.
2944 procedure Check_Expr_Is_OK_Static_Expression
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.
2954 procedure Check_First_Subtype (Arg : Node_Id);
2955 -- Checks that Arg, whose expression is an entity name, references a
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.
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.
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).
2974 procedure Check_Interrupt_Or_Attach_Handler;
2975 -- Common processing for first argument of pragma Interrupt_Handler or
2976 -- pragma Attach_Handler.
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.
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
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.
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.
2998 procedure Check_No_Link_Name;
2999 -- Checks that no link name is specified
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.
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.
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.
3020 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
3021 -- Called to process a precondition or postcondition pragma. There are
3024 -- The pragma appears after a subprogram spec
3026 -- If the corresponding check is not enabled, the pragma is analyzed
3027 -- but otherwise ignored and control returns with In_Body set False.
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.
3037 -- The pragma appears at the start of subprogram body declarations
3039 -- In this case an immediate return to the caller is made with
3040 -- In_Body set True, and the pragma is NOT analyzed.
3042 -- In all other cases, an error message for bad placement is given
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
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.
3061 procedure Check_Valid_Configuration_Pragma;
3062 -- Legality checks for placement of a configuration pragma
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.
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_
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.
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).
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).
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 \.
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
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).
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.
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.
3139 function Find_Unique_Parameterless_Procedure
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.
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:
3152 -- Each substring "pragma" is replaced by "aspect"
3154 -- If "argument of" is at the start of the error message text, it is
3155 -- replaced by "entity for".
3157 -- If "argument" is at the start of the error message text, it is
3158 -- replaced by "entity".
3160 -- So for example, "argument of pragma X must be discrete type"
3161 -- returns "entity for aspect X must be a discrete type".
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.
3168 procedure Gather_Associations
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.
3182 procedure GNAT_Pragma;
3183 -- Called for all GNAT defined pragmas to check the relevant restriction
3184 -- (No_Implementation_Pragmas).
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.
3192 function Is_Configuration_Pragma return Boolean;
3193 -- Determines if the placement of the current pragma is appropriate
3194 -- for a configuration pragma.
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).
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.
3204 procedure Pragma_Misplaced;
3205 pragma No_Return (Pragma_Misplaced);
3206 -- Issue fatal error message for misplaced pragma
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.
3213 procedure Process_Compile_Time_Warning_Or_Error;
3214 -- Common processing for Compile_Time_Error and Compile_Time_Warning
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.
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.
3228 procedure Process_Extended_Import_Export_Exception_Pragma
3229 (Arg_Internal : Node_Id;
3230 Arg_External : 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
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
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.
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.
3269 procedure Process_Generic_List;
3270 -- Common processing for Share_Generic and Inline_Generic
3272 procedure Process_Import_Or_Interface;
3273 -- Common processing for Import of Interface
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.
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
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.
3290 procedure Process_Interface_Name
3291 (Subprogram_Def : Entity_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.
3304 procedure Process_Interrupt_Or_Attach_Handler;
3305 -- Common processing for Interrupt and Attach_Handler pragmas
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.
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
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.
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.
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.
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.
3346 procedure Set_Rational_Profile;
3347 -- Activate the set of configuration pragmas and permissions that make
3348 -- up the Rational profile.
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.
3355 ----------------------------------
3356 -- Acquire_Warning_Match_String --
3357 ----------------------------------
3359 procedure Acquire_Warning_Match_String (Arg : Node_Id) is
3361 String_To_Name_Buffer
3362 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
3364 -- Add asterisk at start if not already there
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;
3373 -- Add asterisk at end if not already there
3375 if Name_Buffer (Name_Len) /= '*' then
3376 Name_Len := Name_Len + 1;
3377 Name_Buffer (Name_Len) := '*';
3379 end Acquire_Warning_Match_String;
3381 ---------------------
3382 -- Ada_2005_Pragma --
3383 ---------------------
3385 procedure Ada_2005_Pragma is
3387 if Ada_Version <= Ada_95 then
3388 Check_Restriction (No_Implementation_Pragmas, N);
3390 end Ada_2005_Pragma;
3392 ---------------------
3393 -- Ada_2012_Pragma --
3394 ---------------------
3396 procedure Ada_2012_Pragma is
3398 if Ada_Version <= Ada_2005 then
3399 Check_Restriction (No_Implementation_Pragmas, N);
3401 end Ada_2012_Pragma;
3403 ---------------------
3404 -- Analyze_Part_Of --
3405 ---------------------
3407 procedure Analyze_Part_Of
3408 (Item_Id : Entity_Id;
3411 Legal : out Boolean)
3413 Pack_Id : Entity_Id;
3414 Placement : State_Space_Kind;
3415 Parent_Unit : Entity_Id;
3416 State_Id : Entity_Id;
3419 -- Assume that the pragma/option is illegal
3423 if Nkind_In (State, N_Expanded_Name,
3425 N_Selected_Component)
3428 Resolve_State (State);
3430 if Is_Entity_Name (State)
3431 and then Ekind (Entity (State)) = E_Abstract_State
3433 State_Id := Entity (State);
3437 ("indicator Part_Of must denote an abstract state", State);
3441 -- This is a syntax error, always report
3445 ("indicator Part_Of must denote an abstract state", State);
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
3454 Find_Placement_In_State_Space
3455 (Item_Id => Item_Id,
3456 Placement => Placement,
3457 Pack_Id => Pack_Id);
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
3464 if Placement = Not_In_Package then
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));
3470 ("\& is not part of the hidden state of package %",
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
3479 elsif Placement = Visible_State_Space then
3480 if Is_Child_Unit (Pack_Id)
3481 and then Is_Private_Descendant (Pack_Id)
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.
3490 -- Find nearest nearest private ancestor (which can be the
3491 -- current unit itself).
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);
3500 Parent_Unit := Scope (Parent_Unit);
3502 if not Is_Child_Or_Sibling (Pack_Id, Scope (State_Id)) then
3504 ("indicator Part_Of must denote an abstract state of& "
3505 & "or public descendant (SPARK RM 7.2.6(3))",
3506 Indic, Parent_Unit);
3508 elsif Scope (State_Id) = Parent_Unit
3509 or else (Is_Ancestor_Package (Parent_Unit, Scope (State_Id))
3511 not Is_Private_Descendant (Scope (State_Id)))
3517 ("indicator Part_Of must denote an abstract state of& "
3518 & "or public descendant (SPARK RM 7.2.6(3))",
3519 Indic, Parent_Unit);
3522 -- Indicator Part_Of is not needed when the related package is not
3523 -- a private child unit or a public descendant thereof.
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);
3531 ("\& is declared in the visible part of package %",
3535 -- When the item appears in the private state space of a package, the
3536 -- encapsulating state must be declared in the same package.
3538 elsif Placement = Private_State_Space then
3539 if Scope (State_Id) /= Pack_Id then
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);
3545 ("\& is declared in the private part of package %",
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.
3554 ("indicator Part_Of cannot appear in this context "
3555 & "(SPARK RM 7.2.6(5))", Indic);
3557 if Scope (State_Id) = Pack_Id then
3558 Error_Msg_Name_1 := Chars (Pack_Id);
3560 ("\& is declared in the body of package %", Indic, Item_Id);
3565 end Analyze_Part_Of;
3567 ----------------------------
3568 -- Analyze_Refined_Pragma --
3569 ----------------------------
3571 procedure Analyze_Refined_Pragma
3572 (Spec_Id : out Entity_Id;
3573 Body_Id : out Entity_Id;
3574 Legal : out Boolean)
3576 Body_Decl : Node_Id;
3577 Spec_Decl : Node_Id;
3580 -- Assume that the pragma is illegal
3587 Check_Arg_Count (1);
3588 Check_No_Identifiers;
3590 if Nam_In (Pname, Name_Refined_Depends,
3591 Name_Refined_Global,
3594 Ensure_Aggregate_Form (Arg1);
3597 -- Verify the placement of the pragma and check for duplicates. The
3598 -- pragma must apply to a subprogram body [stub].
3600 Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
3602 -- Extract the entities of the spec and body
3604 if Nkind (Body_Decl) = N_Subprogram_Body then
3605 Body_Id := Defining_Entity (Body_Decl);
3606 Spec_Id := Corresponding_Spec (Body_Decl);
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);
3617 -- The pragma must apply to the second declaration of a subprogram.
3618 -- In other words, the body [stub] cannot acts as a spec.
3620 if No (Spec_Id) then
3621 Error_Pragma ("pragma % cannot apply to a stand alone body");
3624 -- Catch the case where the subprogram body is a subunit and acts as
3625 -- the third declaration of the subprogram.
3627 elsif Nkind (Parent (Body_Decl)) = N_Subunit then
3628 Error_Pragma ("pragma % cannot apply to a subunit");
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.
3636 Spec_Decl := Parent (Parent (Spec_Id));
3638 if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
3640 ("pragma % must apply to the body of a subprogram declared in a "
3641 & "package specification");
3645 -- If we get here, then the pragma is legal
3648 end Analyze_Refined_Pragma;
3650 --------------------------
3651 -- Check_Ada_83_Warning --
3652 --------------------------
3654 procedure Check_Ada_83_Warning is
3656 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3657 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
3659 end Check_Ada_83_Warning;
3661 ---------------------
3662 -- Check_Arg_Count --
3663 ---------------------
3665 procedure Check_Arg_Count (Required : Nat) is
3667 if Arg_Count /= Required then
3668 Error_Pragma ("wrong number of arguments for pragma%");
3670 end Check_Arg_Count;
3672 --------------------------------
3673 -- Check_Arg_Is_External_Name --
3674 --------------------------------
3676 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
3677 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3680 if Nkind (Argx) = N_Identifier then
3684 Analyze_And_Resolve (Argx, Standard_String);
3686 if Is_OK_Static_Expression (Argx) then
3689 elsif Etype (Argx) = Any_Type then
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.
3698 elsif Ada_Version = Ada_83
3699 and then Nkind (Argx) = N_String_Literal
3703 -- Static expression that raises Constraint_Error. This has
3704 -- already been flagged, so just exit from pragma processing.
3706 elsif Is_OK_Static_Expression (Argx) then
3709 -- Here we have a real error (non-static expression)
3712 Error_Msg_Name_1 := Pname;
3715 Msg : constant String :=
3716 "argument for pragma% must be a identifier or "
3717 & "static string expression!";
3719 Flag_Non_Static_Expr (Fix_Error (Msg), Argx);
3724 end Check_Arg_Is_External_Name;
3726 -----------------------------
3727 -- Check_Arg_Is_Identifier --
3728 -----------------------------
3730 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
3731 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3733 if Nkind (Argx) /= N_Identifier then
3735 ("argument for pragma% must be identifier", Argx);
3737 end Check_Arg_Is_Identifier;
3739 ----------------------------------
3740 -- Check_Arg_Is_Integer_Literal --
3741 ----------------------------------
3743 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
3744 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3746 if Nkind (Argx) /= N_Integer_Literal then
3748 ("argument for pragma% must be integer literal", Argx);
3750 end Check_Arg_Is_Integer_Literal;
3752 -------------------------------------------
3753 -- Check_Arg_Is_Library_Level_Local_Name --
3754 -------------------------------------------
3758 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3759 -- | library_unit_NAME
3761 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
3763 Check_Arg_Is_Local_Name (Arg);
3765 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
3766 and then Comes_From_Source (N)
3769 ("argument for pragma% must be library level entity", Arg);
3771 end Check_Arg_Is_Library_Level_Local_Name;
3773 -----------------------------
3774 -- Check_Arg_Is_Local_Name --
3775 -----------------------------
3779 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3780 -- | library_unit_NAME
3782 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
3783 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
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)))
3795 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
3798 -- No further check required if not an entity name
3800 if not Is_Entity_Name (Argx) then
3806 Ent : constant Entity_Id := Entity (Argx);
3807 Scop : constant Entity_Id := Scope (Ent);
3810 -- Case of a pragma applied to a compilation unit: pragma must
3811 -- occur immediately after the program unit in the compilation.
3813 if Is_Compilation_Unit (Ent) then
3815 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
3818 -- Case of pragma placed immediately after spec
3820 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
3823 -- Case of pragma placed immediately after body
3825 elsif Nkind (Decl) = N_Subprogram_Declaration
3826 and then Present (Corresponding_Body (Decl))
3830 (Parent (Unit_Declaration_Node
3831 (Corresponding_Body (Decl))));
3833 -- All other cases are illegal
3840 -- Special restricted placement rule from 10.2.1(11.8/2)
3842 elsif Is_Generic_Formal (Ent)
3843 and then Prag_Id = Pragma_Preelaborable_Initialization
3845 OK := List_Containing (N) =
3846 Generic_Formal_Declarations
3847 (Unit_Declaration_Node (Scop));
3849 -- If this is an aspect applied to a subprogram body, the
3850 -- pragma is inserted in its declarative part.
3852 elsif From_Aspect_Specification (N)
3854 Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body
3855 and then Ent = Current_Scope
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
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)
3871 -- Default case, just check that the pragma occurs in the scope
3872 -- of the entity denoted by the name.
3875 OK := Current_Scope = Scop;
3880 ("pragma% argument must be in same declarative part", Arg);
3884 end Check_Arg_Is_Local_Name;
3886 ---------------------------------
3887 -- Check_Arg_Is_Locking_Policy --
3888 ---------------------------------
3890 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
3891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3894 Check_Arg_Is_Identifier (Argx);
3896 if not Is_Locking_Policy_Name (Chars (Argx)) then
3897 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
3899 end Check_Arg_Is_Locking_Policy;
3901 -----------------------------------------------
3902 -- Check_Arg_Is_Partition_Elaboration_Policy --
3903 -----------------------------------------------
3905 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
3906 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3909 Check_Arg_Is_Identifier (Argx);
3911 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
3913 ("& is not a valid partition elaboration policy name", Argx);
3915 end Check_Arg_Is_Partition_Elaboration_Policy;
3917 -------------------------
3918 -- Check_Arg_Is_One_Of --
3919 -------------------------
3921 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3922 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3925 Check_Arg_Is_Identifier (Argx);
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);
3932 end Check_Arg_Is_One_Of;
3934 procedure Check_Arg_Is_One_Of
3936 N1, N2, N3 : Name_Id)
3938 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3941 Check_Arg_Is_Identifier (Argx);
3943 if not Nam_In (Chars (Argx), N1, N2, N3) then
3944 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3946 end Check_Arg_Is_One_Of;
3948 procedure Check_Arg_Is_One_Of
3950 N1, N2, N3, N4 : Name_Id)
3952 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3955 Check_Arg_Is_Identifier (Argx);
3957 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
3958 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3960 end Check_Arg_Is_One_Of;
3962 procedure Check_Arg_Is_One_Of
3964 N1, N2, N3, N4, N5 : Name_Id)
3966 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3969 Check_Arg_Is_Identifier (Argx);
3971 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
3972 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
3974 end Check_Arg_Is_One_Of;
3976 ---------------------------------
3977 -- Check_Arg_Is_Queuing_Policy --
3978 ---------------------------------
3980 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
3981 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3984 Check_Arg_Is_Identifier (Argx);
3986 if not Is_Queuing_Policy_Name (Chars (Argx)) then
3987 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
3989 end Check_Arg_Is_Queuing_Policy;
3991 ---------------------------------------
3992 -- Check_Arg_Is_OK_Static_Expression --
3993 ---------------------------------------
3995 procedure Check_Arg_Is_OK_Static_Expression
3997 Typ : Entity_Id := Empty)
4000 Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ);
4001 end Check_Arg_Is_OK_Static_Expression;
4003 ------------------------------------------
4004 -- Check_Arg_Is_Task_Dispatching_Policy --
4005 ------------------------------------------
4007 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
4008 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4011 Check_Arg_Is_Identifier (Argx);
4013 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
4015 ("& is not an allowed task dispatching policy name", Argx);
4017 end Check_Arg_Is_Task_Dispatching_Policy;
4019 ---------------------
4020 -- Check_Arg_Order --
4021 ---------------------
4023 procedure Check_Arg_Order (Names : Name_List) is
4026 Highest_So_Far : Natural := 0;
4027 -- Highest index in Names seen do far
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;
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);
4045 Highest_So_Far := K;
4053 end Check_Arg_Order;
4055 --------------------------------
4056 -- Check_At_Least_N_Arguments --
4057 --------------------------------
4059 procedure Check_At_Least_N_Arguments (N : Nat) is
4061 if Arg_Count < N then
4062 Error_Pragma ("too few arguments for pragma%");
4064 end Check_At_Least_N_Arguments;
4066 -------------------------------
4067 -- Check_At_Most_N_Arguments --
4068 -------------------------------
4070 procedure Check_At_Most_N_Arguments (N : Nat) is
4073 if Arg_Count > N then
4075 for J in 1 .. N loop
4077 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
4080 end Check_At_Most_N_Arguments;
4082 ---------------------
4083 -- Check_Component --
4084 ---------------------
4086 procedure Check_Component
4089 In_Variant_Part : Boolean := False)
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);
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_
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)))
4106 ("component subtype subject to per-object constraint "
4107 & "must be an Unchecked_Union", Comp);
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.
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)
4123 ("component of unchecked union cannot be of generic type", Comp);
4125 elsif Needs_Finalization (Typ) then
4127 ("component of unchecked union cannot be controlled", Comp);
4129 elsif Has_Task (Typ) then
4131 ("component of unchecked union cannot have tasks", Comp);
4133 end Check_Component;
4135 -----------------------------
4136 -- Check_Declaration_Order --
4137 -----------------------------
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
4144 --------------------------------------
4145 -- Check_Aspect_Specification_Order --
4146 --------------------------------------
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);
4154 -- Both aspects must be part of the same aspect specification list
4157 (List_Containing (Asp_First) = List_Containing (Asp_Second));
4159 -- Try to reach Second starting from First in a left to right
4160 -- traversal of the aspect specifications.
4162 Asp := Next (Asp_First);
4163 while Present (Asp) loop
4165 -- The order is ok, First is followed by Second
4167 if Asp = Asp_Second then
4174 -- If we get here, then the aspects are out of order
4176 SPARK_Msg_N ("aspect % cannot come after aspect %", First);
4177 end Check_Aspect_Specification_Order;
4183 -- Start of processing for Check_Declaration_Order
4186 -- Cannot check the order if one of the pragmas is missing
4188 if No (First) or else No (Second) then
4192 -- Set up the error names in case the order is incorrect
4194 Error_Msg_Name_1 := Pragma_Name (First);
4195 Error_Msg_Name_2 := Pragma_Name (Second);
4197 if From_Aspect_Specification (First) then
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.
4203 if From_Aspect_Specification (Second) then
4204 Check_Aspect_Specification_Order;
4207 -- Abstract_States is a source pragma
4210 if From_Aspect_Specification (Second) then
4211 SPARK_Msg_N ("pragma % cannot come after aspect %", First);
4213 -- Both pragmas are source constructs. Try to reach First from
4214 -- Second by traversing the declarations backwards.
4217 Stmt := Prev (Second);
4218 while Present (Stmt) loop
4220 -- The order is ok, First is followed by Second
4222 if Stmt = First then
4229 -- If we get here, then the pragmas are out of order
4231 SPARK_Msg_N ("pragma % cannot come after pragma %", First);
4234 end Check_Declaration_Order;
4236 ----------------------------
4237 -- Check_Duplicate_Pragma --
4238 ----------------------------
4240 procedure Check_Duplicate_Pragma (E : Entity_Id) is
4241 Id : Entity_Id := E;
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.
4249 if From_Aspect_Specification (N) then
4253 -- Otherwise current pragma may duplicate previous pragma or a
4254 -- previously given aspect specification or attribute definition
4255 -- clause for the same pragma.
4257 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
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
4266 if Nkind (P) = N_Pragma then
4268 Args : constant List_Id :=
4269 Pragma_Argument_Associations (P);
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
4280 elsif Nkind (P) = N_Aspect_Specification
4281 and then Is_Type (Entity (P))
4282 and then Entity (P) /= E
4288 -- Here we have a definite duplicate
4290 Error_Msg_Name_1 := Pragma_Name (N);
4291 Error_Msg_Sloc := Sloc (P);
4293 -- For a single protected or a single task object, the error is
4294 -- issued on the original entity.
4296 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
4297 Id := Defining_Identifier (Original_Node (Parent (Id)));
4300 if Nkind (P) = N_Aspect_Specification
4301 or else From_Aspect_Specification (P)
4303 Error_Msg_NE ("aspect% for & previously given#", N, Id);
4305 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
4310 end Check_Duplicate_Pragma;
4312 ----------------------------------
4313 -- Check_Duplicated_Export_Name --
4314 ----------------------------------
4316 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
4317 String_Val : constant String_Id := Strval (Nam);
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).
4324 if not Inside_A_Generic
4325 and then (Prag_Id = Pragma_Export
4327 Prag_Id = Pragma_Export_Procedure
4329 Prag_Id = Pragma_Export_Valued_Procedure
4331 Prag_Id = Pragma_Export_Function)
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);
4341 Externals.Append (Nam);
4343 end Check_Duplicated_Export_Name;
4345 ----------------------------------------
4346 -- Check_Expr_Is_OK_Static_Expression --
4347 ----------------------------------------
4349 procedure Check_Expr_Is_OK_Static_Expression
4351 Typ : Entity_Id := Empty)
4354 if Present (Typ) then
4355 Analyze_And_Resolve (Expr, Typ);
4357 Analyze_And_Resolve (Expr);
4360 if Is_OK_Static_Expression (Expr) then
4363 elsif Etype (Expr) = Any_Type then
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.
4372 elsif Ada_Version = Ada_83
4373 and then Nkind (Expr) = N_String_Literal
4377 -- Static expression that raises Constraint_Error. This has already
4378 -- been flagged, so just exit from pragma processing.
4380 elsif Is_OK_Static_Expression (Expr) then
4383 -- Finally, we have a real error
4386 Error_Msg_Name_1 := Pname;
4387 Flag_Non_Static_Expr
4388 (Fix_Error ("argument for pragma% must be a static expression!"),
4392 end Check_Expr_Is_OK_Static_Expression;
4394 -------------------------
4395 -- Check_First_Subtype --
4396 -------------------------
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);
4403 if Is_First_Subtype (Ent) then
4406 elsif Is_Type (Ent) then
4408 ("pragma% cannot apply to subtype", Argx);
4410 elsif Is_Object (Ent) then
4412 ("pragma% cannot apply to object, requires a type", Argx);
4416 ("pragma% cannot apply to&, requires a type", Argx);
4418 end Check_First_Subtype;
4420 ----------------------
4421 -- Check_Identifier --
4422 ----------------------
4424 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
4427 and then Nkind (Arg) = N_Pragma_Argument_Association
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);
4436 end Check_Identifier;
4438 --------------------------------
4439 -- Check_Identifier_Is_One_Of --
4440 --------------------------------
4442 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
4445 and then Nkind (Arg) = N_Pragma_Argument_Association
4447 if Chars (Arg) = No_Name then
4448 Error_Msg_Name_1 := Pname;
4449 Error_Msg_N ("pragma% argument expects an identifier", Arg);
4452 elsif Chars (Arg) /= N1
4453 and then Chars (Arg) /= N2
4455 Error_Msg_Name_1 := Pname;
4456 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
4460 end Check_Identifier_Is_One_Of;
4462 ---------------------------
4463 -- Check_In_Main_Program --
4464 ---------------------------
4466 procedure Check_In_Main_Program is
4467 P : constant Node_Id := Parent (N);
4470 -- Must be at in subprogram body
4472 if Nkind (P) /= N_Subprogram_Body then
4473 Error_Pragma ("% pragma allowed only in subprogram");
4475 -- Otherwise warn if obviously not main program
4477 elsif Present (Parameter_Specifications (Specification (P)))
4478 or else not Is_Compilation_Unit (Defining_Entity (P))
4480 Error_Msg_Name_1 := Pname;
4482 ("??pragma% is only effective in main program", N);
4484 end Check_In_Main_Program;
4486 ---------------------------------------
4487 -- Check_Interrupt_Or_Attach_Handler --
4488 ---------------------------------------
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;
4497 if Prag_Id = Pragma_Interrupt_Handler then
4498 Check_Restriction (No_Dynamic_Attachment, N);
4501 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
4502 Proc_Scope := Scope (Handler_Proc);
4504 -- On AAMP only, a pragma Interrupt_Handler is supported for
4505 -- nonprotected parameterless procedures.
4507 if not AAMP_On_Target
4508 or else Prag_Id = Pragma_Attach_Handler
4510 if Ekind (Proc_Scope) /= E_Protected_Type then
4512 ("argument of pragma% must be protected procedure", Arg1);
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.
4519 if not From_Aspect_Specification (N)
4520 and then Parent (N) /= Protected_Definition (Parent (Proc_Scope))
4522 Error_Pragma ("pragma% must be in protected definition");
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))
4531 ("argument for pragma% must be library level entity", Arg1);
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.
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.
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
4548 Error_Pragma ("pragma% cannot be used inside a generic");
4551 end Check_Interrupt_Or_Attach_Handler;
4553 ---------------------------------
4554 -- Check_Loop_Pragma_Placement --
4555 ---------------------------------
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.
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.
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.
4573 --------------------------------
4574 -- Check_Loop_Pragma_Grouping --
4575 --------------------------------
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.
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.
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.
4593 --------------------
4594 -- Check_Grouping --
4595 --------------------
4597 procedure Check_Grouping (L : List_Id) is
4603 -- Inspect the list of declarations or statements looking for
4604 -- the first grouping of pragmas:
4607 -- pragma Loop_Invariant ...;
4608 -- pragma Loop_Variant ...;
4610 -- pragma Loop_Variant ...; -- current pragma
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
4618 while Present (Stmt) loop
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.
4625 if Nkind (Stmt) = N_Block_Statement then
4626 HSS := Handled_Statement_Sequence (Stmt);
4628 Check_Grouping (Declarations (Stmt));
4630 if Present (HSS) then
4631 Check_Grouping (Statements (HSS));
4634 -- First pragma of the first topmost grouping has been found
4636 elsif Is_Loop_Pragma (Stmt) then
4638 -- The group and the current pragma are not in the same
4639 -- declarative or statement list.
4641 if List_Containing (Stmt) /= List_Containing (N) then
4642 Grouping_Error (Stmt);
4644 -- Try to reach the current pragma from the first pragma
4645 -- of the grouping while skipping other members:
4647 -- pragma Loop_Invariant ...; -- first pragma
4648 -- pragma Loop_Variant ...; -- member
4650 -- pragma Loop_Variant ...; -- current pragma
4653 while Present (Stmt) loop
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.
4662 -- Skip group members, but keep track of the last
4663 -- pragma in the group.
4665 elsif Is_Loop_Pragma (Stmt) then
4668 -- A non-pragma is separating the group from the
4669 -- current pragma, the placement is illegal.
4672 Grouping_Error (Prag);
4678 -- If the traversal did not reach the current pragma,
4679 -- then the list must be malformed.
4681 raise Program_Error;
4689 --------------------
4690 -- Grouping_Error --
4691 --------------------
4693 procedure Grouping_Error (Prag : Node_Id) is
4695 Error_Msg_Sloc := Sloc (Prag);
4696 Error_Pragma ("pragma% must appear next to pragma#");
4699 -- Start of processing for Check_Loop_Pragma_Grouping
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.
4706 Check_Grouping (Statements (Loop_Stmt));
4709 when Stop_Search => null;
4710 end Check_Loop_Pragma_Grouping;
4712 --------------------
4713 -- Is_Loop_Pragma --
4714 --------------------
4716 function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is
4718 -- Inspect the original node as Loop_Invariant and Loop_Variant
4719 -- pragmas are rewritten to null when assertions are disabled.
4721 if Nkind (Original_Node (Stmt)) = N_Pragma then
4723 Nam_In (Pragma_Name (Original_Node (Stmt)),
4724 Name_Loop_Invariant,
4731 ---------------------
4732 -- Placement_Error --
4733 ---------------------
4735 procedure Placement_Error (Constr : Node_Id) is
4736 LA : constant String := " with Loop_Entry";
4739 if Prag_Id = Pragma_Assert then
4740 Error_Msg_String (1 .. LA'Length) := LA;
4741 Error_Msg_Strlen := LA'Length;
4743 Error_Msg_Strlen := 0;
4746 if Nkind (Constr) = N_Pragma then
4748 ("pragma %~ must appear immediately within the statements "
4752 ("block containing pragma %~ must appear immediately within "
4753 & "the statements of a loop", Constr);
4755 end Placement_Error;
4757 -- Local declarations
4762 -- Start of processing for Check_Loop_Pragma_Placement
4765 -- Check that pragma appears immediately within a loop statement,
4766 -- ignoring intervening block statements.
4770 while Present (Stmt) loop
4772 -- The pragma or previous block must appear immediately within the
4773 -- current block's declarative or statement part.
4775 if Nkind (Stmt) = N_Block_Statement then
4776 if (No (Declarations (Stmt))
4777 or else List_Containing (Prev) /= Declarations (Stmt))
4779 List_Containing (Prev) /=
4780 Statements (Handled_Statement_Sequence (Stmt))
4782 Placement_Error (Prev);
4785 -- Keep inspecting the parents because we are now within a
4786 -- chain of nested blocks.
4790 Stmt := Parent (Stmt);
4793 -- The pragma or previous block must appear immediately within the
4794 -- statements of the loop.
4796 elsif Nkind (Stmt) = N_Loop_Statement then
4797 if List_Containing (Prev) /= Statements (Stmt) then
4798 Placement_Error (Prev);
4801 -- Stop the traversal because we reached the innermost loop
4802 -- regardless of whether we encountered an error or not.
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.
4810 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
4811 Stmt := Parent (Stmt);
4813 -- Any other statement breaks the chain from the pragma to the
4817 Placement_Error (Prev);
4822 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4823 -- grouped together with other such pragmas.
4825 if Is_Loop_Pragma (N) then
4827 -- The previous check should have located the related loop
4829 pragma Assert (Nkind (Stmt) = N_Loop_Statement);
4830 Check_Loop_Pragma_Grouping (Stmt);
4832 end Check_Loop_Pragma_Placement;
4834 -------------------------------------------
4835 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4836 -------------------------------------------
4838 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
4847 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
4850 elsif Nkind_In (P, N_Package_Specification,
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.
4861 elsif Nkind_In (P, N_Subprogram_Body,
4872 Error_Pragma ("pragma% is not in declarative part or package spec");
4873 end Check_Is_In_Decl_Part_Or_Package_Spec;
4875 -------------------------
4876 -- Check_No_Identifier --
4877 -------------------------
4879 procedure Check_No_Identifier (Arg : Node_Id) is
4881 if Nkind (Arg) = N_Pragma_Argument_Association
4882 and then Chars (Arg) /= No_Name
4884 Error_Pragma_Arg_Ident
4885 ("pragma% does not permit identifier& here", Arg);
4887 end Check_No_Identifier;
4889 --------------------------
4890 -- Check_No_Identifiers --
4891 --------------------------
4893 procedure Check_No_Identifiers is
4897 for J in 1 .. Arg_Count loop
4898 Check_No_Identifier (Arg_Node);
4901 end Check_No_Identifiers;
4903 ------------------------
4904 -- Check_No_Link_Name --
4905 ------------------------
4907 procedure Check_No_Link_Name is
4909 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
4913 if Present (Arg4) then
4915 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
4917 end Check_No_Link_Name;
4919 -------------------------------
4920 -- Check_Optional_Identifier --
4921 -------------------------------
4923 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
4926 and then Nkind (Arg) = N_Pragma_Argument_Association
4927 and then Chars (Arg) /= No_Name
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);
4936 end Check_Optional_Identifier;
4938 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
4940 Name_Buffer (1 .. Id'Length) := Id;
4941 Name_Len := Id'Length;
4942 Check_Optional_Identifier (Arg, Name_Find);
4943 end Check_Optional_Identifier;
4945 --------------------
4946 -- Check_Pre_Post --
4947 --------------------
4949 procedure Check_Pre_Post is
4954 if not Is_List_Member (N) then
4958 -- If we are within an inlined body, the legality of the pragma
4959 -- has been checked already.
4961 if In_Inlined_Body then
4965 -- Search prior declarations
4968 while Present (Prev (P)) loop
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.
4977 if Nkind (P) not in N_Generic_Declaration then
4978 PO := Original_Node (P);
4983 -- Skip past prior pragma
4985 if Nkind (PO) = N_Pragma then
4988 -- Skip stuff not coming from source
4990 elsif not Comes_From_Source (PO) then
4992 -- The condition may apply to a subprogram instantiation
4994 if Nkind (PO) = N_Subprogram_Declaration
4995 and then Present (Generic_Parent (Specification (PO)))
4999 elsif Nkind (PO) = N_Subprogram_Declaration
5000 and then In_Instance
5004 -- For all other cases of non source code, do nothing
5010 -- Only remaining possibility is subprogram declaration
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.
5022 if Nkind (PO) = N_Subprogram_Body
5023 and then List_Containing (N) = Declarations (PO)
5025 -- This is only allowed if there is no separate specification
5027 if Present (Corresponding_Spec (PO)) then
5029 ("pragma% must apply to subprogram specification");
5036 --------------------------------------
5037 -- Check_Precondition_Postcondition --
5038 --------------------------------------
5040 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
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
5054 procedure Chain_PPC (PO : Node_Id) is
5058 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5059 if not From_Aspect_Specification (N) then
5061 ("pragma% cannot be applied to abstract subprogram");
5063 elsif Class_Present (N) then
5068 ("aspect % requires ''Class for abstract subprogram");
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.
5075 -- The above discrepency needs documentation. Robert is dubious
5076 -- about whether it is a good idea ???
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)
5085 ("aspect % requires ''Class for null procedure");
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).
5092 elsif Nkind (PO) = N_Subprogram_Body
5093 and then Acts_As_Spec (PO)
5097 elsif Nkind (PO) = N_Subprogram_Body_Stub then
5100 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5101 N_Expression_Function,
5102 N_Generic_Subprogram_Declaration,
5103 N_Entry_Declaration)
5108 -- Here if we have [generic] subprogram or entry declaration
5110 if Nkind (PO) = N_Entry_Declaration then
5111 S := Defining_Entity (PO);
5113 S := Defining_Unit_Name (Specification (PO));
5115 if Nkind (S) = N_Defining_Program_Unit_Name then
5116 S := Defining_Identifier (S);
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.
5126 -- Chain spec PPC pragma to list for subprogram
5128 Add_Contract_Item (N, S);
5130 -- Return indicating spec case
5136 -- Start of processing for Check_Precondition_Postcondition
5139 if not Is_List_Member (N) then
5143 -- Preanalyze message argument if present. Visibility in this
5144 -- argument is established at the point of pragma occurrence.
5146 if Arg_Count = 2 then
5147 Check_Optional_Identifier (Arg2, Name_Message);
5148 Preanalyze_Spec_Expression
5149 (Get_Pragma_Arg (Arg2), Standard_String);
5152 -- For a pragma PPC in the extended main source unit, record enabled
5155 if Is_Checked (N) and then not Split_PPC (N) then
5156 Set_SCO_Pragma_Enabled (Loc);
5159 -- If we are within an inlined body, the legality of the pragma
5160 -- has been checked already.
5162 if In_Inlined_Body then
5167 -- Search prior declarations
5170 while Present (Prev (P)) loop
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.
5179 if Nkind (P) not in N_Generic_Declaration then
5180 PO := Original_Node (P);
5185 -- Skip past prior pragma
5187 if Nkind (PO) = N_Pragma then
5190 -- Skip stuff not coming from source
5192 elsif not Comes_From_Source (PO) then
5194 -- The condition may apply to a subprogram instantiation
5196 if Nkind (PO) = N_Subprogram_Declaration
5197 and then Present (Generic_Parent (Specification (PO)))
5202 elsif Nkind (PO) = N_Subprogram_Declaration
5203 and then In_Instance
5208 -- For all other cases of non source code, do nothing
5214 -- Only remaining possibility is subprogram declaration
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.
5227 if Nkind (PO) = N_Subprogram_Body
5228 and then List_Containing (N) = Declarations (PO)
5230 if Operating_Mode /= Generate_Code or else Inside_A_Generic then
5232 -- Analyze pragma expression for correctness and for ASIS use
5234 Preanalyze_Assert_Expression
5235 (Get_Pragma_Arg (Arg1), Standard_Boolean);
5237 -- In ASIS mode, for a pragma generated from a source aspect,
5238 -- also analyze the original aspect expression.
5240 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
5241 Preanalyze_Assert_Expression
5242 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
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.
5250 if Acts_As_Spec (PO) and then GNATprove_Mode then
5252 Prag : constant Node_Id := New_Copy_Tree (N);
5255 -- Preanalyze the pragma
5257 Preanalyze_Assert_Expression
5259 (First (Pragma_Argument_Associations (Prag))),
5262 -- Preanalyze the corresponding aspect (if any)
5264 if Present (Corresponding_Aspect (Prag)) then
5265 Preanalyze_Assert_Expression
5266 (Expression (Corresponding_Aspect (Prag)),
5270 -- Chain the copy on the contract of the body
5273 (Prag, Defining_Unit_Name (Specification (PO)));
5280 -- See if it is in the pragmas after a library level subprogram
5282 elsif Nkind (PO) = N_Compilation_Unit_Aux then
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.
5288 if GNATprove_Mode or ASIS_Mode then
5289 Analyze_Pre_Post_Condition_In_Decl_Part
5290 (N, Defining_Entity (Unit (Parent (PO))));
5293 Chain_PPC (Unit (Parent (PO)));
5297 -- If we fall through, pragma was misplaced
5300 end Check_Precondition_Postcondition;
5302 -----------------------------
5303 -- Check_Static_Constraint --
5304 -----------------------------
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 ???
5311 procedure Check_Static_Constraint (Constr : Node_Id) is
5313 procedure Require_Static (E : Node_Id);
5314 -- Require given expression to be static expression
5316 --------------------
5317 -- Require_Static --
5318 --------------------
5320 procedure Require_Static (E : Node_Id) is
5322 if not Is_OK_Static_Expression (E) then
5323 Flag_Non_Static_Expr
5324 ("non-static constraint not allowed in Unchecked_Union!", E);
5329 -- Start of processing for Check_Static_Constraint
5332 case Nkind (Constr) is
5333 when N_Discriminant_Association =>
5334 Require_Static (Expression (Constr));
5337 Require_Static (Low_Bound (Constr));
5338 Require_Static (High_Bound (Constr));
5340 when N_Attribute_Reference =>
5341 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
5342 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
5344 when N_Range_Constraint =>
5345 Check_Static_Constraint (Range_Expression (Constr));
5347 when N_Index_Or_Discriminant_Constraint =>
5351 IDC := First (Constraints (Constr));
5352 while Present (IDC) loop
5353 Check_Static_Constraint (IDC);
5361 end Check_Static_Constraint;
5363 ---------------------
5364 -- Check_Test_Case --
5365 ---------------------
5367 procedure Check_Test_Case is
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.
5380 procedure Chain_CTC (PO : Node_Id) is
5384 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
5386 ("pragma% cannot be applied to abstract subprogram");
5388 elsif Nkind (PO) = N_Entry_Declaration then
5389 Error_Pragma ("pragma% cannot be applied to entry");
5391 elsif not Nkind_In (PO, N_Subprogram_Declaration,
5392 N_Generic_Subprogram_Declaration)
5397 -- Here if we have [generic] subprogram declaration
5399 S := Defining_Unit_Name (Specification (PO));
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.
5407 -- There should not be another test-case with the same name
5408 -- associated to this subprogram.
5411 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
5415 CTC := Contract_Test_Cases (Contract (S));
5416 while Present (CTC) loop
5418 -- Omit pragma Contract_Cases because it does not introduce
5419 -- a unique case name and it does not follow the syntax of
5422 if Pragma_Name (CTC) = Name_Contract_Cases then
5426 (Name, Get_Name_From_CTC_Pragma (CTC))
5428 Error_Msg_Sloc := Sloc (CTC);
5429 Error_Pragma ("name for pragma% is already used#");
5432 CTC := Next_Pragma (CTC);
5436 -- Chain spec CTC pragma to list for subprogram
5438 Add_Contract_Item (N, S);
5441 -- Start of processing for Check_Test_Case
5444 -- First check pragma arguments
5446 Check_At_Least_N_Arguments (2);
5447 Check_At_Most_N_Arguments (4);
5449 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
5451 Check_Optional_Identifier (Arg1, Name_Name);
5452 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
5454 -- In ASIS mode, for a pragma generated from a source aspect, also
5455 -- analyze the original aspect expression.
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);
5462 Check_Optional_Identifier (Arg2, Name_Mode);
5463 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
5465 if Arg_Count = 4 then
5466 Check_Identifier (Arg3, Name_Requires);
5467 Check_Identifier (Arg4, Name_Ensures);
5469 elsif Arg_Count = 3 then
5470 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
5473 -- Check pragma placement
5475 if not Is_List_Member (N) then
5479 -- Test-case should only appear in package spec unit
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)
5489 -- Search prior declarations
5492 while Present (Prev (P)) loop
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.
5501 if Nkind (P) not in N_Generic_Declaration then
5502 PO := Original_Node (P);
5507 -- Skip past prior pragma
5509 if Nkind (PO) = N_Pragma then
5512 -- Skip stuff not coming from source
5514 elsif not Comes_From_Source (PO) then
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.
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)
5536 -- If we fall through, pragma was misplaced
5539 end Check_Test_Case;
5541 --------------------------------------
5542 -- Check_Valid_Configuration_Pragma --
5543 --------------------------------------
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.
5549 procedure Check_Valid_Configuration_Pragma is
5551 if not Is_Configuration_Pragma then
5552 Error_Pragma ("incorrect placement for configuration pragma%");
5554 end Check_Valid_Configuration_Pragma;
5556 -------------------------------------
5557 -- Check_Valid_Library_Unit_Pragma --
5558 -------------------------------------
5560 procedure Check_Valid_Library_Unit_Pragma is
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;
5569 if not Is_List_Member (N) then
5573 Plist := List_Containing (N);
5574 Parent_Node := Parent (Plist);
5576 if Parent_Node = Empty then
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.
5583 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
5584 if Plist /= Pragmas_After (Parent_Node) then
5587 elsif Arg_Count = 0 then
5589 ("argument required if outside compilation unit");
5592 Check_No_Identifiers;
5593 Check_Arg_Count (1);
5594 Unit_Node := Unit (Parent (Parent_Node));
5595 Unit_Kind := Nkind (Unit_Node);
5597 Analyze (Get_Pragma_Arg (Arg1));
5599 if Unit_Kind = N_Generic_Subprogram_Declaration
5600 or else Unit_Kind = N_Subprogram_Declaration
5602 Unit_Name := Defining_Entity (Unit_Node);
5604 elsif Unit_Kind in N_Generic_Instantiation then
5605 Unit_Name := Defining_Entity (Unit_Node);
5608 Unit_Name := Cunit_Entity (Current_Sem_Unit);
5611 if Chars (Unit_Name) /=
5612 Chars (Entity (Get_Pragma_Arg (Arg1)))
5615 ("pragma% argument is not current unit name", Arg1);
5618 if Ekind (Unit_Name) = E_Package
5619 and then Present (Renamed_Entity (Unit_Name))
5621 Error_Pragma ("pragma% not allowed for renamed package");
5625 -- Pragma appears other than after a compilation unit
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.
5633 Sindex := Source_Index (Current_Sem_Unit);
5635 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
5636 Rewrite (N, Make_Null_Statement (Loc));
5639 -- If before first declaration, the pragma applies to the
5640 -- enclosing unit, and the name if present must be this name.
5642 elsif Is_Before_First_Decl (N, Plist) then
5643 Unit_Node := Unit_Declaration_Node (Current_Scope);
5644 Unit_Kind := Nkind (Unit_Node);
5646 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
5649 elsif Unit_Kind = N_Subprogram_Body
5650 and then not Acts_As_Spec (Unit_Node)
5654 elsif Nkind (Parent_Node) = N_Package_Body then
5657 elsif Nkind (Parent_Node) = N_Package_Specification
5658 and then Plist = Private_Declarations (Parent_Node)
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)
5669 elsif Arg_Count > 0 then
5670 Analyze (Get_Pragma_Arg (Arg1));
5672 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
5674 ("name in pragma% must be enclosing unit", Arg1);
5677 -- It is legal to have no argument in this context
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.
5691 ("pragma% misplaced, must be before first declaration");
5695 end Check_Valid_Library_Unit_Pragma;
5701 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
5702 Clist : constant Node_Id := Component_List (Variant);
5706 Comp := First (Component_Items (Clist));
5707 while Present (Comp) loop
5708 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
5713 ---------------------------
5714 -- Ensure_Aggregate_Form --
5715 ---------------------------
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;
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.
5729 -- pragma Global (In_Out => (A, B, C))
5733 -- pragma Global ((In_Out => (A, B, C)))
5735 -- aggregate aggregate
5737 if Nkind (Expr) = N_Aggregate then
5738 if Nam = No_Name then
5742 -- Do not transform a null argument into an aggregate as N_Null has
5743 -- special meaning in formal verification pragmas.
5745 elsif Nkind (Expr) = N_Null then
5749 -- Positional argument is transformed into an aggregate with an
5750 -- Expressions list.
5752 if Nam = No_Name then
5753 Exprs := New_List (Relocate_Node (Expr));
5755 -- An associative argument is transformed into an aggregate with
5756 -- Component_Associations.
5760 Make_Component_Association (Loc,
5761 Choices => New_List (Make_Identifier (Loc, Chars (Arg))),
5762 Expression => Relocate_Node (Expr)));
5766 -- Remove the pragma argument name as this information has been
5767 -- captured in the aggregate.
5769 Set_Chars (Arg, No_Name);
5771 Set_Expression (Arg,
5772 Make_Aggregate (Loc,
5773 Component_Associations => Comps,
5774 Expressions => Exprs));
5775 end Ensure_Aggregate_Form;
5781 procedure Error_Pragma (Msg : String) is
5783 Error_Msg_Name_1 := Pname;
5784 Error_Msg_N (Fix_Error (Msg), N);
5788 ----------------------
5789 -- Error_Pragma_Arg --
5790 ----------------------
5792 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
5794 Error_Msg_Name_1 := Pname;
5795 Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg));
5797 end Error_Pragma_Arg;
5799 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
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;
5806 ----------------------------
5807 -- Error_Pragma_Arg_Ident --
5808 ----------------------------
5810 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
5812 Error_Msg_Name_1 := Pname;
5813 Error_Msg_N (Fix_Error (Msg), Arg);
5815 end Error_Pragma_Arg_Ident;
5817 ----------------------
5818 -- Error_Pragma_Ref --
5819 ----------------------
5821 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
5823 Error_Msg_Name_1 := Pname;
5824 Error_Msg_Sloc := Sloc (Ref);
5825 Error_Msg_NE (Fix_Error (Msg), N, Ref);
5827 end Error_Pragma_Ref;
5829 ------------------------
5830 -- Find_Lib_Unit_Name --
5831 ------------------------
5833 function Find_Lib_Unit_Name return Entity_Id is
5835 -- Return inner compilation unit entity, for case of nested
5836 -- categorization pragmas. This happens in generic unit.
5838 if Nkind (Parent (N)) = N_Package_Specification
5839 and then Defining_Entity (Parent (N)) /= Current_Scope
5841 return Defining_Entity (Parent (N));
5843 return Current_Scope;
5845 end Find_Lib_Unit_Name;
5847 ----------------------------
5848 -- Find_Program_Unit_Name --
5849 ----------------------------
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);
5857 if Nkind (P) = N_Compilation_Unit then
5858 Unit_Kind := Nkind (Unit (P));
5860 if Unit_Kind = N_Subprogram_Declaration
5861 or else Unit_Kind = N_Package_Declaration
5862 or else Unit_Kind in N_Generic_Declaration
5864 Unit_Name := Defining_Entity (Unit (P));
5866 if Chars (Id) = Chars (Unit_Name) then
5867 Set_Entity (Id, Unit_Name);
5868 Set_Etype (Id, Etype (Unit_Name));
5870 Set_Etype (Id, Any_Type);
5872 ("cannot find program unit referenced by pragma%");
5876 Set_Etype (Id, Any_Type);
5877 Error_Pragma ("pragma% inapplicable to this unit");
5883 end Find_Program_Unit_Name;
5885 -----------------------------------------
5886 -- Find_Unique_Parameterless_Procedure --
5887 -----------------------------------------
5889 function Find_Unique_Parameterless_Procedure
5891 Arg : Node_Id) return Entity_Id
5893 Proc : Entity_Id := Empty;
5896 -- The body of this procedure needs some comments ???
5898 if not Is_Entity_Name (Name) then
5900 ("argument of pragma% must be entity name", Arg);
5902 elsif not Is_Overloaded (Name) then
5903 Proc := Entity (Name);
5905 if Ekind (Proc) /= E_Procedure
5906 or else Present (First_Formal (Proc))
5909 ("argument of pragma% must be parameterless procedure", Arg);
5914 Found : Boolean := False;
5916 Index : Interp_Index;
5919 Get_First_Interp (Name, Index, It);
5920 while Present (It.Nam) loop
5923 if Ekind (Proc) = E_Procedure
5924 and then No (First_Formal (Proc))
5928 Set_Entity (Name, Proc);
5929 Set_Is_Overloaded (Name, False);
5932 ("ambiguous handler name for pragma% ", Arg);
5936 Get_Next_Interp (Index, It);
5941 ("argument of pragma% must be parameterless procedure",
5944 Proc := Entity (Name);
5950 end Find_Unique_Parameterless_Procedure;
5956 function Fix_Error (Msg : String) return String is
5957 Res : String (Msg'Range) := Msg;
5958 Res_Last : Natural := Msg'Last;
5962 -- If we have a rewriting of another pragma, go to that pragma
5964 if Is_Rewrite_Substitution (N)
5965 and then Nkind (Original_Node (N)) = N_Pragma
5967 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
5970 -- Case where pragma comes from an aspect specification
5972 if From_Aspect_Specification (N) then
5974 -- Change appearence of "pragma" in message to "aspect"
5977 while J <= Res_Last - 5 loop
5978 if Res (J .. J + 5) = "pragma" then
5979 Res (J .. J + 5) := "aspect";
5987 -- Change "argument of" at start of message to "entity for"
5990 and then Res (Res'First .. Res'First + 10) = "argument of"
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;
5998 -- Change "argument" at start of message to "entity"
6001 and then Res (Res'First .. Res'First + 7) = "argument"
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;
6009 -- Get name from corresponding aspect
6011 Error_Msg_Name_1 := Original_Aspect_Name (N);
6014 -- Return possibly modified message
6016 return Res (Res'First .. Res_Last);
6019 -------------------------
6020 -- Gather_Associations --
6021 -------------------------
6023 procedure Gather_Associations
6025 Args : out Args_List)
6030 -- Initialize all parameters to Empty
6032 for J in Args'Range loop
6036 -- That's all we have to do if there are no argument associations
6038 if No (Pragma_Argument_Associations (N)) then
6042 -- Otherwise first deal with any positional parameters present
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);
6051 -- Positional parameters all processed, if any left, then we
6052 -- have too many positional parameters.
6054 if Present (Arg) and then Chars (Arg) = No_Name then
6056 ("too many positional associations for pragma%", Arg);
6059 -- Process named parameters if any are present
6061 while Present (Arg) loop
6062 if Chars (Arg) = No_Name then
6064 ("positional association cannot follow named association",
6068 for Index in Names'Range loop
6069 if Names (Index) = Chars (Arg) then
6070 if Present (Args (Index)) then
6072 ("duplicate argument association for pragma%", Arg);
6074 Args (Index) := Get_Pragma_Arg (Arg);
6079 if Index = Names'Last then
6080 Error_Msg_Name_1 := Pname;
6081 Error_Msg_N ("pragma% does not allow & argument", Arg);
6083 -- Check for possible misspelling
6085 for Index1 in Names'Range loop
6086 if Is_Bad_Spelling_Of
6087 (Chars (Arg), Names (Index1))
6089 Error_Msg_Name_1 := Names (Index1);
6090 Error_Msg_N -- CODEFIX
6091 ("\possible misspelling of%", Arg);
6103 end Gather_Associations;
6109 procedure GNAT_Pragma is
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.
6116 if Comes_From_Source (N) then
6117 Check_Restriction (No_Implementation_Pragmas, N);
6121 --------------------------
6122 -- Is_Before_First_Decl --
6123 --------------------------
6125 function Is_Before_First_Decl
6126 (Pragma_Node : Node_Id;
6127 Decls : List_Id) return Boolean
6129 Item : Node_Id := First (Decls);
6132 -- Only other pragmas can come before this pragma
6135 if No (Item) or else Nkind (Item) /= N_Pragma then
6138 elsif Item = Pragma_Node then
6144 end Is_Before_First_Decl;
6146 -----------------------------
6147 -- Is_Configuration_Pragma --
6148 -----------------------------
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.
6154 function Is_Configuration_Pragma return Boolean is
6155 Lis : constant List_Id := List_Containing (N);
6156 Par : constant Node_Id := Parent (N);
6160 -- If no parent, then we are in the configuration pragma file,
6161 -- so the placement is definitely appropriate.
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.
6170 elsif Nkind (Par) = N_Compilation_Unit
6171 and then Context_Items (Par) = Lis
6178 elsif Nkind (Prg) /= N_Pragma then
6188 end Is_Configuration_Pragma;
6190 --------------------------
6191 -- Is_In_Context_Clause --
6192 --------------------------
6194 function Is_In_Context_Clause return Boolean is
6196 Parent_Node : Node_Id;
6199 if not Is_List_Member (N) then
6203 Plist := List_Containing (N);
6204 Parent_Node := Parent (Plist);
6206 if Parent_Node = Empty
6207 or else Nkind (Parent_Node) /= N_Compilation_Unit
6208 or else Context_Items (Parent_Node) /= Plist
6215 end Is_In_Context_Clause;
6217 ---------------------------------
6218 -- Is_Static_String_Expression --
6219 ---------------------------------
6221 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
6222 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
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;
6230 ----------------------
6231 -- Pragma_Misplaced --
6232 ----------------------
6234 procedure Pragma_Misplaced is
6236 Error_Pragma ("incorrect placement of pragma%");
6237 end Pragma_Misplaced;
6239 ------------------------------------
6240 -- Process_Atomic_Shared_Volatile --
6241 ------------------------------------
6243 procedure Process_Atomic_Shared_Volatile is
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.
6260 procedure Set_Atomic (E : Entity_Id) is
6264 if not Has_Alignment_Clause (E) then
6265 Set_Alignment (E, Uint_0);
6269 -- Start of processing for Process_Atomic_Shared_Volatile
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);
6278 if Etype (E_Id) = Any_Type then
6283 D := Declaration_Node (E);
6286 -- Check duplicate before we chain ourselves
6288 Check_Duplicate_Pragma (E);
6290 -- Now check appropriateness of the entity
6293 if Rep_Item_Too_Early (E, N)
6295 Rep_Item_Too_Late (E, N)
6299 Check_First_Subtype (Arg1);
6302 if Prag_Id /= Pragma_Volatile then
6304 Set_Atomic (Underlying_Type (E));
6305 Set_Atomic (Base_Type (E));
6308 -- Attribute belongs on the base type. If the view of the type is
6309 -- currently private, it also belongs on the underlying type.
6311 Set_Is_Volatile (Base_Type (E));
6312 Set_Is_Volatile (Underlying_Type (E));
6314 Set_Treat_As_Volatile (E);
6315 Set_Treat_As_Volatile (Underlying_Type (E));
6317 elsif K = N_Object_Declaration
6318 or else (K = N_Component_Declaration
6319 and then Original_Record_Component (E) = E)
6321 if Rep_Item_Too_Late (E, N) then
6325 if Prag_Id /= Pragma_Volatile then
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.
6332 if Nkind (Parent (E)) = N_Object_Declaration
6333 and then Present (Expression (Parent (E)))
6335 Set_Has_Delayed_Freeze (E);
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.
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.
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.
6357 Utyp := Underlying_Type (Etype (E));
6360 and then Is_Composite_Type (Utyp)
6361 and then Sloc (E) > No_Location
6362 and then Sloc (Utyp) > No_Location
6364 Get_Source_File_Index (Sloc (E)) =
6365 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
6367 Set_Is_Atomic (Underlying_Type (Etype (E)));
6371 Set_Is_Volatile (E);
6372 Set_Treat_As_Volatile (E);
6375 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
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)).
6384 and then Prag_Id = Pragma_Volatile
6385 and then not Nkind_In (K, N_Full_Type_Declaration,
6386 N_Object_Declaration)
6389 ("argument of pragma % must denote a full type or object "
6390 & "declaration", Arg1);
6392 end Process_Atomic_Shared_Volatile;
6394 -------------------------------------------
6395 -- Process_Compile_Time_Warning_Or_Error --
6396 -------------------------------------------
6398 procedure Process_Compile_Time_Warning_Or_Error is
6399 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
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);
6407 if Compile_Time_Known_Value (Arg1x) then
6408 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
6410 Str : constant String_Id :=
6411 Strval (Get_Pragma_Arg (Arg2));
6412 Len : constant Int := String_Length (Str);
6417 Cent : constant Entity_Id :=
6418 Cunit_Entity (Current_Sem_Unit);
6420 Force : constant Boolean :=
6421 Prag_Id = Pragma_Compile_Time_Warning
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.
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.
6439 Error_Msg_Strlen := 0;
6441 -- Loop to copy characters from argument to error message
6445 exit when Ptr > Len;
6446 CC := Get_String_Char (Str, Ptr);
6449 -- Ignore wide chars ??? else store character
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;
6459 -- Here with one line ready to go
6461 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
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.
6470 if Cont = False then
6471 Error_Msg_N ("<<~!!", Arg1);
6474 Error_Msg_N ("\<<~!!", Arg1);
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).
6484 if Cont = False then
6485 Error_Msg_N ("<<~", Arg1);
6488 Error_Msg_N ("\<<~", Arg1);
6492 exit when Ptr > Len;
6497 end Process_Compile_Time_Warning_Or_Error;
6499 ------------------------
6500 -- Process_Convention --
6501 ------------------------
6503 procedure Process_Convention
6504 (C : out Convention_Id;
6505 Ent : out Entity_Id)
6511 Comp_Unit : Unit_Number_Type;
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.
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.
6531 -------------------------------
6532 -- Diagnose_Multiple_Pragmas --
6533 -------------------------------
6535 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
6536 Pdec : constant Node_Id := Declaration_Node (S);
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.
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.
6550 ---------------------
6551 -- Same_Convention --
6552 ---------------------
6554 function Same_Convention (Decl : Node_Id) return Boolean is
6555 Arg1 : constant Node_Id :=
6556 First (Pragma_Argument_Associations (Decl));
6559 if Present (Arg1) then
6561 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
6563 if Nkind (Arg) = N_Identifier
6564 and then Is_Convention_Name (Chars (Arg))
6565 and then Get_Convention_Id (Chars (Arg)) = C
6573 end Same_Convention;
6579 function Same_Name (Decl : Node_Id) return Boolean is
6580 Arg1 : constant Node_Id :=
6581 First (Pragma_Argument_Associations (Decl));
6589 Arg2 := Next (Arg1);
6596 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
6598 if Nkind (Arg) = N_Identifier
6599 and then Chars (Arg) = Chars (S)
6608 -- Start of processing for Diagnose_Multiple_Pragmas
6613 -- Definitely give message if we have Convention/Export here
6615 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
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.
6627 while Present (Decl) and then Decl /= Pdec loop
6629 -- Look for pragma with same name as us
6631 if Nkind (Decl) = N_Pragma
6632 and then Same_Name (Decl)
6634 -- Give error if same as our pragma or Export/Convention
6636 if Nam_In (Pragma_Name (Decl), Name_Export,
6642 -- Case of Import/Interface or the other way round
6644 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
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
6652 if Same_Convention (Decl) then
6653 Set_Import_Interface_Present (N);
6654 Set_Import_Interface_Present (Decl);
6657 -- If different conventions, special message
6660 Error_Msg_Sloc := Sloc (Decl);
6662 ("convention differs from that given#", Arg1);
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).
6678 if Err and not Relaxed_RM_Semantics then
6680 ("at most one Convention/Export/Import pragma is allowed",
6683 end Diagnose_Multiple_Pragmas;
6685 --------------------------------
6686 -- Set_Convention_From_Pragma --
6687 --------------------------------
6689 procedure Set_Convention_From_Pragma (E : Entity_Id) is
6691 -- Ghost convention is allowed only for functions
6693 if Ekind (E) /= E_Function and then C = Convention_Ghost then
6695 ("& may not have Ghost convention", E);
6697 ("\only functions are permitted to have Ghost convention",
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.
6708 if Is_Dispatching_Operation (E)
6709 and then Present (Overridden_Operation (E))
6710 and then C /= Convention (Overridden_Operation (E))
6712 -- An attempt to override a function with a ghost function
6713 -- appears as a mismatch in conventions.
6715 if C = Convention_Ghost then
6716 Error_Msg_N ("ghost function & cannot be overriding", E);
6719 ("cannot change convention for overridden dispatching "
6720 & "operation", Arg1);
6724 -- Special checks for Convention_Stdcall
6726 if C = Convention_Stdcall then
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.
6732 if Is_Dispatching_Operation (E) then
6733 Error_Msg_Sloc := Sloc (E);
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.
6741 ("dispatching subprogram# cannot use Stdcall convention!",
6744 -- Subprogram is allowed, but not a generic subprogram
6746 elsif not Is_Subprogram (E)
6747 and then not Is_Generic_Subprogram (E)
6751 and then Ekind (E) /= E_Variable
6753 -- An access to subprogram is also allowed
6757 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
6759 -- Allow internal call to set convention of subprogram type
6761 and then not (Ekind (E) = E_Subprogram_Type)
6764 ("second argument of pragma% must be subprogram (type)",
6769 -- Set the convention
6771 Set_Convention (E, C);
6772 Set_Has_Convention_Pragma (E);
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.
6778 if Is_Record_Type (E) and then Is_Base_Type (E) then
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)
6791 Set_Convention (Comp, C);
6794 Next_Component (Comp);
6799 -- Deal with incomplete/private type case, where underlying type
6800 -- is available, so set convention of that underlying type.
6802 if Is_Incomplete_Or_Private_Type (E)
6803 and then Present (Underlying_Type (E))
6805 Set_Convention (Underlying_Type (E), C);
6806 Set_Has_Convention_Pragma (Underlying_Type (E), True);
6809 -- A class-wide type should inherit the convention of the specific
6810 -- root type (although this isn't specified clearly by the RM).
6812 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
6813 Set_Convention (Class_Wide_Type (E), C);
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).
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))
6827 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
6830 ("C_Pass_By_Copy convention allowed only for record type",
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.
6839 if Is_Discrete_Type (E)
6840 and then Root_Type (Etype (E)) = Standard_Boolean
6846 C = Convention_Fortran)
6848 Set_Nonzero_Is_True (Base_Type (E));
6850 end Set_Convention_From_Pragma;
6852 -- Start of processing for Process_Convention
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));
6860 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6861 -- tested again below to set the critical flag).
6863 if Cname = Name_C_Pass_By_Copy then
6866 -- Otherwise we must have something in the standard convention list
6868 elsif Is_Convention_Name (Cname) then
6869 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
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.
6878 if Warn_On_Export_Import and not OpenVMS_On_Target then
6880 ("??unrecognized convention name, C assumed",
6881 Get_Pragma_Arg (Arg1));
6887 Check_Optional_Identifier (Arg2, Name_Entity);
6888 Check_Arg_Is_Local_Name (Arg2);
6890 Id := Get_Pragma_Arg (Arg2);
6893 if not Is_Entity_Name (Id) then
6894 Error_Pragma_Arg ("entity name required", Arg2);
6899 -- Set entity to return
6903 -- Ada_Pass_By_Copy special checking
6905 if C = Convention_Ada_Pass_By_Copy then
6906 if not Is_First_Subtype (E) then
6908 ("convention `Ada_Pass_By_Copy` only allowed for types",
6912 if Is_By_Reference_Type (E) then
6914 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6919 -- Ada_Pass_By_Reference special checking
6921 if C = Convention_Ada_Pass_By_Reference then
6922 if not Is_First_Subtype (E) then
6924 ("convention `Ada_Pass_By_Reference` only allowed for types",
6928 if Is_By_Copy_Type (E) then
6930 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6935 -- Ghost special checking
6937 if Is_Ghost_Subprogram (E)
6938 and then Present (Overridden_Operation (E))
6940 Error_Msg_N ("ghost function & cannot be overriding", E);
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.
6947 if Is_Subprogram (E)
6948 and then Present (Alias (E))
6950 if Nkind (Parent (Declaration_Node (E))) =
6951 N_Subprogram_Renaming_Declaration
6953 if Scope (E) /= Scope (Alias (E)) then
6955 ("cannot apply pragma% to non-local entity&#", E);
6960 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
6961 N_Private_Extension_Declaration)
6962 and then Scope (E) = Scope (Alias (E))
6966 -- Return the parent subprogram the entity was inherited from
6972 -- Check that we are not applying this to a specless body
6973 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
6976 if Is_Subprogram (E)
6977 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
6978 and then not Relaxed_RM_Semantics
6981 ("pragma% requires separate spec and must come before body");
6984 -- Check that we are not applying this to a named constant
6986 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
6987 Error_Msg_Name_1 := Pname;
6989 ("cannot apply pragma% to named constant!",
6990 Get_Pragma_Arg (Arg2));
6992 ("\supply appropriate type for&!", Arg2);
6995 if Ekind (E) = E_Enumeration_Literal then
6996 Error_Pragma ("enumeration literal not allowed for pragma%");
6999 -- Check for rep item appearing too early or too late
7001 if Etype (E) = Any_Type
7002 or else Rep_Item_Too_Early (E, N)
7006 elsif Present (Underlying_Type (E)) then
7007 E := Underlying_Type (E);
7010 if Rep_Item_Too_Late (E, N) then
7014 if Has_Convention_Pragma (E) then
7015 Diagnose_Multiple_Pragmas (E);
7017 elsif Convention (E) = Convention_Protected
7018 or else Ekind (Scope (E)) = E_Protected_Type
7021 ("a protected operation cannot be given a different convention",
7025 -- For Intrinsic, a subprogram is required
7027 if C = Convention_Intrinsic
7028 and then not Is_Subprogram (E)
7029 and then not Is_Generic_Subprogram (E)
7032 ("second argument of pragma% must be a subprogram", Arg2);
7035 -- Deal with non-subprogram cases
7037 if not Is_Subprogram (E)
7038 and then not Is_Generic_Subprogram (E)
7040 Set_Convention_From_Pragma (E);
7043 Check_First_Subtype (Arg2);
7044 Set_Convention_From_Pragma (Base_Type (E));
7046 -- For access subprograms, we must set the convention on the
7047 -- internally generated directly designated type as well.
7049 if Ekind (E) = E_Access_Subprogram_Type then
7050 Set_Convention_From_Pragma (Directly_Designated_Type (E));
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.
7059 Comp_Unit := Get_Source_Unit (E);
7060 Set_Convention_From_Pragma (E);
7062 -- Treat a pragma Import as an implicit body, and pragma import
7063 -- as implicit reference (for navigation in GPS).
7065 if Prag_Id = Pragma_Import then
7066 Generate_Reference (E, Id, 'b');
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.
7073 elsif Prag_Id = Pragma_Export
7074 and then Convention (E) /= Convention_Ada
7076 Generate_Reference (E, Id, 'i');
7079 -- If the pragma comes from from an aspect, it only applies to the
7080 -- given entity, not its homonyms.
7082 if From_Aspect_Specification (N) then
7086 -- Otherwise Loop through the homonyms of the pragma argument's
7087 -- entity, an apply convention to those in the current scope.
7093 exit when No (E1) or else Scope (E1) /= Current_Scope;
7095 -- Ignore entry for which convention is already set
7097 if Has_Convention_Pragma (E1) then
7101 -- Do not set the pragma on inherited operations or on formal
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
7110 if Present (Alias (E1))
7111 and then Scope (E1) /= Scope (Alias (E1))
7114 ("cannot apply pragma% to non-local entity& declared#",
7118 Set_Convention_From_Pragma (E1);
7120 if Prag_Id = Pragma_Import then
7121 Generate_Reference (E1, Id, 'b');
7129 end Process_Convention;
7131 ----------------------------------------
7132 -- Process_Disable_Enable_Atomic_Sync --
7133 ----------------------------------------
7135 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
7137 Check_No_Identifiers;
7138 Check_At_Most_N_Arguments (1);
7140 -- Modeled internally as
7141 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7145 Pragma_Identifier =>
7146 Make_Identifier (Loc, Nam),
7147 Pragma_Argument_Associations => New_List (
7148 Make_Pragma_Argument_Association (Loc,
7150 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
7152 if Present (Arg1) then
7153 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
7157 end Process_Disable_Enable_Atomic_Sync;
7159 -----------------------------------------------------
7160 -- Process_Extended_Import_Export_Exception_Pragma --
7161 -----------------------------------------------------
7163 procedure Process_Extended_Import_Export_Exception_Pragma
7164 (Arg_Internal : Node_Id;
7165 Arg_External : Node_Id;
7173 if not OpenVMS_On_Target then
7175 ("??pragma% ignored (applies only to Open'V'M'S)");
7178 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7179 Def_Id := Entity (Arg_Internal);
7181 if Ekind (Def_Id) /= E_Exception then
7183 ("pragma% must refer to declared exception", Arg_Internal);
7186 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7188 if Present (Arg_Form) then
7189 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
7192 if Present (Arg_Form)
7193 and then Chars (Arg_Form) = Name_Ada
7197 Set_Is_VMS_Exception (Def_Id);
7198 Set_Exception_Code (Def_Id, No_Uint);
7201 if Present (Arg_Code) then
7202 if not Is_VMS_Exception (Def_Id) then
7204 ("Code option for pragma% not allowed for Ada case",
7208 Check_Arg_Is_OK_Static_Expression (Arg_Code, Any_Integer);
7209 Code_Val := Expr_Value (Arg_Code);
7211 if not UI_Is_In_Int_Range (Code_Val) then
7213 ("Code option for pragma% must be in 32-bit range",
7217 Set_Exception_Code (Def_Id, Code_Val);
7220 end Process_Extended_Import_Export_Exception_Pragma;
7222 -------------------------------------------------
7223 -- Process_Extended_Import_Export_Internal_Arg --
7224 -------------------------------------------------
7226 procedure Process_Extended_Import_Export_Internal_Arg
7227 (Arg_Internal : Node_Id := Empty)
7230 if No (Arg_Internal) then
7231 Error_Pragma ("Internal parameter required for pragma%");
7234 if Nkind (Arg_Internal) = N_Identifier then
7237 elsif Nkind (Arg_Internal) = N_Operator_Symbol
7238 and then (Prag_Id = Pragma_Import_Function
7240 Prag_Id = Pragma_Export_Function)
7246 ("wrong form for Internal parameter for pragma%", Arg_Internal);
7249 Check_Arg_Is_Local_Name (Arg_Internal);
7250 end Process_Extended_Import_Export_Internal_Arg;
7252 --------------------------------------------------
7253 -- Process_Extended_Import_Export_Object_Pragma --
7254 --------------------------------------------------
7256 procedure Process_Extended_Import_Export_Object_Pragma
7257 (Arg_Internal : Node_Id;
7258 Arg_External : Node_Id;
7264 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7265 Def_Id := Entity (Arg_Internal);
7267 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
7269 ("pragma% must designate an object", Arg_Internal);
7272 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
7274 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
7277 ("previous Common/Psect_Object applies, pragma % not permitted",
7281 if Rep_Item_Too_Late (Def_Id, N) then
7285 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
7287 if Present (Arg_Size) then
7288 Check_Arg_Is_External_Name (Arg_Size);
7291 -- Export_Object case
7293 if Prag_Id = Pragma_Export_Object then
7294 if not Is_Library_Level_Entity (Def_Id) then
7296 ("argument for pragma% must be library level entity",
7300 if Ekind (Current_Scope) = E_Generic_Package then
7301 Error_Pragma ("pragma& cannot appear in a generic unit");
7304 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
7306 ("exported object must have compile time known size",
7310 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
7311 Error_Msg_N ("??duplicate Export_Object pragma", N);
7313 Set_Exported (Def_Id, Arg_Internal);
7316 -- Import_Object case
7319 if Is_Concurrent_Type (Etype (Def_Id)) then
7321 ("cannot use pragma% for task/protected object",
7325 if Ekind (Def_Id) = E_Constant then
7327 ("cannot import a constant", Arg_Internal);
7330 if Warn_On_Export_Import
7331 and then Has_Discriminants (Etype (Def_Id))
7334 ("imported value must be initialized??", Arg_Internal);
7337 if Warn_On_Export_Import
7338 and then Is_Access_Type (Etype (Def_Id))
7341 ("cannot import object of an access type??", Arg_Internal);
7344 if Warn_On_Export_Import
7345 and then Is_Imported (Def_Id)
7347 Error_Msg_N ("??duplicate Import_Object pragma", N);
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.
7353 elsif Present (Expression (Parent (Def_Id)))
7356 (Original_Node (Expression (Parent (Def_Id))))
7358 Error_Msg_Sloc := Sloc (Def_Id);
7360 ("imported entities cannot be initialized (RM B.1(24))",
7361 "\no initialization allowed for & declared#", Arg1);
7363 Set_Imported (Def_Id);
7364 Note_Possible_Modification (Arg_Internal, Sure => False);
7367 end Process_Extended_Import_Export_Object_Pragma;
7369 ------------------------------------------------------
7370 -- Process_Extended_Import_Export_Subprogram_Pragma --
7371 ------------------------------------------------------
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)
7386 Ambiguous : Boolean;
7390 function Same_Base_Type
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.
7398 --------------------
7399 -- Same_Base_Type --
7400 --------------------
7402 function Same_Base_Type
7404 Formal : Entity_Id) return Boolean
7406 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
7410 -- Case where pragma argument is typ'Access
7412 if Nkind (Ptype) = N_Attribute_Reference
7413 and then Attribute_Name (Ptype) = Name_Access
7415 Pref := Prefix (Ptype);
7418 if not Is_Entity_Name (Pref)
7419 or else Entity (Pref) = Any_Type
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
7428 return Ekind (Ftyp) = E_Anonymous_Access_Type
7429 and then Base_Type (Entity (Pref)) =
7430 Base_Type (Etype (Designated_Type (Ftyp)));
7432 -- Case where pragma argument is a type name
7437 if not Is_Entity_Name (Ptype)
7438 or else Entity (Ptype) = Any_Type
7443 -- We have a match if the corresponding argument is of the type
7444 -- given in the pragma (comparing base types)
7446 return Base_Type (Entity (Ptype)) = Ftyp;
7450 -- Start of processing for
7451 -- Process_Extended_Import_Export_Subprogram_Pragma
7454 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
7458 -- Loop through homonyms (overloadings) of the entity
7460 Hom_Id := Entity (Arg_Internal);
7461 while Present (Hom_Id) loop
7462 Def_Id := Get_Base_Subprogram (Hom_Id);
7464 -- We need a subprogram in the current scope
7466 if not Is_Subprogram (Def_Id)
7467 or else Scope (Def_Id) /= Current_Scope
7474 -- Pragma cannot apply to subprogram body
7476 if Is_Subprogram (Def_Id)
7477 and then Nkind (Parent (Declaration_Node (Def_Id))) =
7481 ("pragma% requires separate spec"
7482 & " and must come before body");
7485 -- Test result type if given, note that the result type
7486 -- parameter can only be present for the function cases.
7488 if Present (Arg_Result_Type)
7489 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
7493 elsif Etype (Def_Id) /= Standard_Void_Type
7495 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
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.
7503 elsif Present (Arg_Parameter_Types) then
7504 Check_Matching_Types : declare
7509 Formal := First_Formal (Def_Id);
7511 if Nkind (Arg_Parameter_Types) = N_Null then
7512 if Present (Formal) then
7516 -- A list of one type, e.g. (List) is parsed as
7517 -- a parenthesized expression.
7519 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
7520 and then Paren_Count (Arg_Parameter_Types) = 1
7523 or else Present (Next_Formal (Formal))
7528 Same_Base_Type (Arg_Parameter_Types, Formal);
7531 -- A list of more than one type is parsed as a aggregate
7533 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
7534 and then Paren_Count (Arg_Parameter_Types) = 0
7536 Ptype := First (Expressions (Arg_Parameter_Types));
7537 while Present (Ptype) or else Present (Formal) loop
7540 or else not Same_Base_Type (Ptype, Formal)
7545 Next_Formal (Formal);
7550 -- Anything else is of the wrong form
7554 ("wrong form for Parameter_Types parameter",
7555 Arg_Parameter_Types);
7557 end Check_Matching_Types;
7560 -- Match is now False if the entry we found did not match
7561 -- either a supplied Parameter_Types or Result_Types argument
7567 -- Ambiguous case, the flag Ambiguous shows if we already
7568 -- detected this and output the initial messages.
7571 if not Ambiguous then
7573 Error_Msg_Name_1 := Pname;
7575 ("pragma% does not uniquely identify subprogram!",
7577 Error_Msg_Sloc := Sloc (Ent);
7578 Error_Msg_N ("matching subprogram #!", N);
7582 Error_Msg_Sloc := Sloc (Def_Id);
7583 Error_Msg_N ("matching subprogram #!", N);
7588 Hom_Id := Homonym (Hom_Id);
7591 -- See if we found an entry
7594 if not Ambiguous then
7595 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
7597 ("pragma% cannot be given for generic subprogram");
7600 ("pragma% does not identify local subprogram");
7607 -- Import pragmas must be for imported entities
7609 if Prag_Id = Pragma_Import_Function
7611 Prag_Id = Pragma_Import_Procedure
7613 Prag_Id = Pragma_Import_Valued_Procedure
7615 if not Is_Imported (Ent) then
7617 ("pragma Import or Interface must precede pragma%");
7620 -- Here we have the Export case which can set the entity as exported
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.
7626 elsif Nkind (Arg_External) = N_String_Literal
7627 and then String_Length (Strval (Arg_External)) = 0
7631 -- In all other cases, set entity as exported
7634 Set_Exported (Ent, Arg_Internal);
7637 -- Special processing for Valued_Procedure cases
7639 if Prag_Id = Pragma_Import_Valued_Procedure
7641 Prag_Id = Pragma_Export_Valued_Procedure
7643 Formal := First_Formal (Ent);
7646 Error_Pragma ("at least one parameter required for pragma%");
7648 elsif Ekind (Formal) /= E_Out_Parameter then
7649 Error_Pragma ("first parameter must have mode out for pragma%");
7652 Set_Is_Valued_Procedure (Ent);
7656 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
7658 -- Process Result_Mechanism argument if present. We have already
7659 -- checked that this is only allowed for the function case.
7661 if Present (Arg_Result_Mechanism) then
7662 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
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.
7669 if Present (Arg_Mechanism) then
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.
7682 if Nkind (Arg_Mechanism) /= N_Aggregate
7683 and then Paren_Count (Arg_Mechanism) = 1
7685 Rewrite (Arg_Mechanism,
7686 Make_Aggregate (Sloc (Arg_Mechanism),
7687 Expressions => New_List (
7688 Relocate_Node (Arg_Mechanism))));
7691 -- Case of only mechanism name given, applies to all formals
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);
7700 -- Case of list of mechanism associations given
7703 if Null_Record_Present (Arg_Mechanism) then
7705 ("inappropriate form for Mechanism parameter",
7709 -- Deal with positional ones first
7711 Formal := First_Formal (Ent);
7713 if Present (Expressions (Arg_Mechanism)) then
7714 Mname := First (Expressions (Arg_Mechanism));
7715 while Present (Mname) loop
7718 ("too many mechanism associations", Mname);
7721 Set_Mechanism_Value (Formal, Mname);
7722 Next_Formal (Formal);
7727 -- Deal with named entries
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));
7734 if Nkind (Choice) /= N_Identifier
7735 or else Present (Next (Choice))
7738 ("incorrect form for mechanism association",
7742 Formal := First_Formal (Ent);
7746 ("parameter name & not present", Choice);
7749 if Chars (Choice) = Chars (Formal) then
7751 (Formal, Expression (Massoc));
7753 -- Set entity on identifier (needed by ASIS)
7755 Set_Entity (Choice, Formal);
7760 Next_Formal (Formal);
7770 -- Process First_Optional_Parameter argument if present. We have
7771 -- already checked that this is only allowed for the Import case.
7773 if Present (Arg_First_Optional_Parameter) then
7774 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
7776 ("first optional parameter must be formal parameter name",
7777 Arg_First_Optional_Parameter);
7780 Formal := First_Formal (Ent);
7784 ("specified formal parameter& not found",
7785 Arg_First_Optional_Parameter);
7788 exit when Chars (Formal) =
7789 Chars (Arg_First_Optional_Parameter);
7791 Next_Formal (Formal);
7794 Set_First_Optional_Parameter (Ent, Formal);
7796 -- Check specified and all remaining formals have right form
7798 while Present (Formal) loop
7799 if Ekind (Formal) /= E_In_Parameter then
7801 ("optional formal& is not of mode in!",
7802 Arg_First_Optional_Parameter, Formal);
7805 Dval := Default_Value (Formal);
7809 ("optional formal& does not have default value!",
7810 Arg_First_Optional_Parameter, Formal);
7812 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
7817 ("default value for optional formal& is non-static!",
7818 Arg_First_Optional_Parameter, Formal);
7822 Set_Is_Optional_Parameter (Formal);
7823 Next_Formal (Formal);
7826 end Process_Extended_Import_Export_Subprogram_Pragma;
7828 --------------------------
7829 -- Process_Generic_List --
7830 --------------------------
7832 procedure Process_Generic_List is
7837 Check_No_Identifiers;
7838 Check_At_Least_N_Arguments (1);
7840 -- Check all arguments are names of generic units or instances
7843 while Present (Arg) loop
7844 Exp := Get_Pragma_Arg (Arg);
7847 if not Is_Entity_Name (Exp)
7849 (not Is_Generic_Instance (Entity (Exp))
7851 not Is_Generic_Unit (Entity (Exp)))
7854 ("pragma% argument must be name of generic unit/instance",
7860 end Process_Generic_List;
7862 ------------------------------------
7863 -- Process_Import_Predefined_Type --
7864 ------------------------------------
7866 procedure Process_Import_Predefined_Type is
7867 Loc : constant Source_Ptr := Sloc (N);
7869 Ftyp : Node_Id := Empty;
7875 String_To_Name_Buffer (Strval (Expression (Arg3)));
7878 Elmt := First_Elmt (Predefined_Float_Types);
7879 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
7883 Ftyp := Node (Elmt);
7885 if Present (Ftyp) then
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
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)))));
7899 -- Should never have a predefined type we cannot handle
7902 raise Program_Error;
7905 -- Build and insert a Full_Type_Declaration, which will be
7906 -- analyzed as soon as this list entry has been analyzed.
7908 Decl := Make_Full_Type_Declaration (Loc,
7909 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
7910 Type_Definition => Def);
7912 Insert_After (N, Decl);
7913 Mark_Rewrite_Insertion (Decl);
7916 Error_Pragma_Arg ("no matching type found for pragma%",
7919 end Process_Import_Predefined_Type;
7921 ---------------------------------
7922 -- Process_Import_Or_Interface --
7923 ---------------------------------
7925 procedure Process_Import_Or_Interface is
7931 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7932 -- pragma Import (Entity, "external name");
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
7940 Def_Id := Get_Pragma_Arg (Arg1);
7943 if not Is_Entity_Name (Def_Id) then
7944 Error_Pragma_Arg ("entity name required", Arg1);
7947 Def_Id := Entity (Def_Id);
7948 Kill_Size_Check_Code (Def_Id);
7949 Note_Possible_Modification (Get_Pragma_Arg (Arg1), Sure => False);
7952 Process_Convention (C, Def_Id);
7953 Kill_Size_Check_Code (Def_Id);
7954 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
7957 if Ekind_In (Def_Id, E_Variable, E_Constant) then
7959 -- We do not permit Import to apply to a renaming declaration
7961 if Present (Renamed_Object (Def_Id)) then
7963 ("pragma% not allowed for object renaming", Arg2);
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.
7971 elsif Present (Expression (Parent (Def_Id)))
7972 and then Comes_From_Source (Expression (Parent (Def_Id)))
7974 Error_Msg_Sloc := Sloc (Def_Id);
7976 ("no initialization allowed for declaration of& #",
7977 "\imported entities cannot be initialized (RM B.1(24))",
7981 Set_Imported (Def_Id);
7982 Process_Interface_Name (Def_Id, Arg3, Arg4);
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
7989 -- pragma Import completes deferred constants
7991 if Ekind (Def_Id) = E_Constant then
7992 Set_Has_Completion (Def_Id);
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.
7999 if Is_Array_Type (Etype (Def_Id))
8000 and then not Is_Constrained (Etype (Def_Id))
8003 ("imported constant& must have a constrained subtype",
8008 elsif Is_Subprogram (Def_Id)
8009 or else Is_Generic_Subprogram (Def_Id)
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).
8017 while Present (Hom_Id) loop
8019 Def_Id := Get_Base_Subprogram (Hom_Id);
8021 -- Ignore inherited subprograms because the pragma will apply
8022 -- to the parent operation, which is the one called.
8024 if Is_Overloadable (Def_Id)
8025 and then Present (Alias (Def_Id))
8029 -- If it is not a subprogram, it must be in an outer scope and
8030 -- pragma does not apply.
8032 elsif not Is_Subprogram (Def_Id)
8033 and then not Is_Generic_Subprogram (Def_Id)
8037 -- The pragma does not apply to primitives of interfaces
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))
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.
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)
8056 Set_Imported (Def_Id);
8058 -- Reject an Import applied to an abstract subprogram
8060 if Is_Subprogram (Def_Id)
8061 and then Is_Abstract_Subprogram (Def_Id)
8063 Error_Msg_Sloc := Sloc (Def_Id);
8065 ("cannot import abstract subprogram& declared#",
8069 -- Special processing for Convention_Intrinsic
8071 if C = Convention_Intrinsic then
8073 -- Link_Name argument not allowed for intrinsic
8077 Set_Is_Intrinsic_Subprogram (Def_Id);
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.
8084 Check_Intrinsic_Subprogram
8085 (Def_Id, Get_Pragma_Arg (Arg2));
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.
8094 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
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
8104 Error_Msg_Sloc := Sloc (Def_Id);
8106 ("cannot import&, renaming already provided for "
8107 & "declaration #", N, Def_Id);
8111 Set_Has_Completion (Def_Id);
8112 Process_Interface_Name (Def_Id, Arg3, Arg4);
8115 if Is_Compilation_Unit (Hom_Id) then
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.
8123 elsif From_Aspect_Specification (N) then
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.
8136 elsif not Comes_From_Source (N) then
8140 Hom_Id := Homonym (Hom_Id);
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.
8148 elsif (C = Convention_Java or else C = Convention_CIL)
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)
8155 Set_Imported (Def_Id);
8156 Set_Is_Public (Def_Id);
8157 Process_Interface_Name (Def_Id, Arg3, Arg4);
8159 -- Import a CPP class
8161 elsif C = Convention_CPP
8162 and then (Is_Record_Type (Def_Id)
8163 or else Ekind (Def_Id) = E_Incomplete_Type)
8165 if Ekind (Def_Id) = E_Incomplete_Type then
8166 if Present (Full_View (Def_Id)) then
8167 Def_Id := Full_View (Def_Id);
8171 ("cannot import 'C'P'P type before full declaration seen",
8172 Get_Pragma_Arg (Arg2));
8174 -- Although we have reported the error we decorate it as
8175 -- CPP_Class to avoid reporting spurious errors
8177 Set_Is_CPP_Class (Def_Id);
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
8187 if not Is_Limited_Type (Def_Id) then
8189 ("imported 'C'P'P type must be limited",
8190 Get_Pragma_Arg (Arg2));
8193 if Etype (Def_Id) /= Def_Id
8194 and then not Is_CPP_Class (Root_Type (Def_Id))
8196 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
8199 Set_Is_CPP_Class (Def_Id);
8201 -- Imported CPP types must not have discriminants (because C++
8202 -- classes do not have discriminants).
8204 if Has_Discriminants (Def_Id) then
8206 ("imported 'C'P'P type cannot have discriminants",
8207 First (Discriminant_Specifications
8208 (Declaration_Node (Def_Id))));
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).
8215 if not Is_Private_Type (Def_Id) then
8216 Check_CPP_Type_Has_No_Defaults (Def_Id);
8219 -- Import a CPP exception
8221 elsif C = Convention_CPP
8222 and then Ekind (Def_Id) = E_Exception
8226 ("'External_'Name arguments is required for 'Cpp exception",
8229 -- As only a string is allowed, Check_Arg_Is_External_Name
8232 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8235 if Present (Arg4) then
8237 ("Link_Name argument not allowed for imported Cpp exception",
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.
8246 -- ??? Emit an error if pragma Import/Export_Exception is present
8248 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
8250 Check_Arg_Count (3);
8251 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
8253 Process_Import_Predefined_Type;
8257 ("second argument of pragma% must be object, subprogram "
8258 & "or incomplete type",
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.
8266 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
8268 Cunit : constant Node_Id := Parent (Parent (N));
8270 Set_Body_Required (Cunit, False);
8273 end Process_Import_Or_Interface;
8275 --------------------
8276 -- Process_Inline --
8277 --------------------
8279 procedure Process_Inline (Status : Inline_Status) is
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.
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
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.
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
8307 -- ??? is business with link symbols still valid, or does it relate
8308 -- to front end ZCX which is being phased out ???
8310 ---------------------------
8311 -- Inlining_Not_Possible --
8312 ---------------------------
8314 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
8315 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
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));
8324 elsif Nkind (Decl) = N_Subprogram_Declaration
8325 and then Present (Corresponding_Body (Decl))
8327 if Front_End_Inlining
8328 and then Analyzed (Corresponding_Body (Decl))
8330 Error_Msg_N ("pragma appears too late, ignored??", N);
8333 -- If the subprogram is a renaming as body, the body is just a
8334 -- call to the renamed subprogram, and inlining is trivially
8338 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
8339 N_Subprogram_Renaming_Declaration
8345 Handled_Statement_Sequence
8346 (Unit_Declaration_Node (Corresponding_Body (Decl)));
8349 Present (Exception_Handlers (Stats))
8350 or else Present (At_End_Proc (Stats));
8354 -- If body is not available, assume the best, the check is
8355 -- performed again when compiling enclosing package bodies.
8359 end Inlining_Not_Possible;
8365 procedure Make_Inline (Subp : Entity_Id) is
8366 Kind : constant Entity_Kind := Ekind (Subp);
8367 Inner_Subp : Entity_Id := Subp;
8370 -- Ignore if bad type, avoid cascaded error
8372 if Etype (Subp) = Any_Type then
8376 -- Ignore if all inlining is suppressed
8378 elsif Suppress_All_Inlining then
8382 -- If inlining is not possible, for now do not treat as an error
8384 elsif Status /= Suppressed
8385 and then Inlining_Not_Possible (Subp)
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.
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.
8405 elsif Is_Generic_Instance (Subp)
8406 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
8410 elsif not Comes_From_Source (Subp)
8411 and then Scope (Subp) /= Standard_Standard
8417 -- The referenced entity must either be the enclosing entity, or
8418 -- an entity declared within the current open scope.
8420 if Present (Scope (Subp))
8421 and then Scope (Subp) /= Current_Scope
8422 and then Subp /= Current_Scope
8425 ("argument of% must be entity in current scope", Assoc);
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.
8433 if Is_Subprogram (Subp) then
8434 Inner_Subp := Ultimate_Alias (Inner_Subp);
8436 if In_Same_Source_Unit (Subp, Inner_Subp) then
8437 Set_Inline_Flags (Inner_Subp);
8439 Decl := Parent (Parent (Inner_Subp));
8441 if Nkind (Decl) = N_Subprogram_Declaration
8442 and then Present (Corresponding_Body (Decl))
8444 Set_Inline_Flags (Corresponding_Body (Decl));
8446 elsif Is_Generic_Instance (Subp) then
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
8453 if Scope (Subp) /= Standard_Standard
8455 Need_Subprogram_Instance_Body
8456 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
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.
8467 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
8468 and then List_Containing (Decl) = List_Containing (N)
8469 and then not In_Instance
8472 ("Inline cannot apply to a formal subprogram", N);
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.
8480 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
8481 Set_Inline_Flags (Subp);
8487 -- For a generic subprogram set flag as well, for use at the point
8488 -- of instantiation, to determine whether the body should be
8491 elsif Is_Generic_Subprogram (Subp) then
8492 Set_Inline_Flags (Subp);
8495 -- Literals are by definition inlined
8497 elsif Kind = E_Enumeration_Literal then
8500 -- Anything else is an error
8504 ("expect subprogram name for pragma%", Assoc);
8508 ----------------------
8509 -- Set_Inline_Flags --
8510 ----------------------
8512 procedure Set_Inline_Flags (Subp : Entity_Id) is
8514 -- First set the Has_Pragma_XXX flags and issue the appropriate
8515 -- errors and warnings for suspicious combinations.
8517 if Prag_Id = Pragma_No_Inline then
8518 if Has_Pragma_Inline_Always (Subp) then
8520 ("Inline_Always and No_Inline are mutually exclusive", N);
8521 elsif Has_Pragma_Inline (Subp) then
8523 ("Inline and No_Inline both specified for& ??",
8524 N, Entity (Subp_Id));
8527 Set_Has_Pragma_No_Inline (Subp);
8529 if Prag_Id = Pragma_Inline_Always then
8530 if Has_Pragma_No_Inline (Subp) then
8532 ("Inline_Always and No_Inline are mutually exclusive",
8536 Set_Has_Pragma_Inline_Always (Subp);
8538 if Has_Pragma_No_Inline (Subp) then
8540 ("Inline and No_Inline both specified for& ??",
8541 N, Entity (Subp_Id));
8545 if not Has_Pragma_Inline (Subp) then
8546 Set_Has_Pragma_Inline (Subp);
8551 -- Then adjust the Is_Inlined flag. It can never be set if the
8552 -- subprogram is subject to pragma No_Inline.
8556 Set_Is_Inlined (Subp, False);
8560 if not Has_Pragma_No_Inline (Subp) then
8561 Set_Is_Inlined (Subp, True);
8564 end Set_Inline_Flags;
8566 -- Start of processing for Process_Inline
8569 Check_No_Identifiers;
8570 Check_At_Least_N_Arguments (1);
8572 if Status = Enabled then
8573 Inline_Processing_Required := True;
8577 while Present (Assoc) loop
8578 Subp_Id := Get_Pragma_Arg (Assoc);
8582 if Is_Entity_Name (Subp_Id) then
8583 Subp := Entity (Subp_Id);
8585 if Subp = Any_Id then
8587 -- If previous error, avoid cascaded errors
8589 Check_Error_Detected;
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.
8601 if not From_Aspect_Specification (N) then
8602 while Present (Homonym (Subp))
8603 and then Scope (Homonym (Subp)) = Current_Scope
8605 Make_Inline (Homonym (Subp));
8606 Subp := Homonym (Subp);
8614 ("inappropriate argument for pragma%", Assoc);
8617 and then Warn_On_Redundant_Constructs
8618 and then not (Status = Suppressed or else Suppress_All_Inlining)
8620 if Inlining_Not_Possible (Subp) then
8622 ("pragma Inline for& is ignored?r?",
8623 N, Entity (Subp_Id));
8626 ("pragma Inline for& is redundant?r?",
8627 N, Entity (Subp_Id));
8635 ----------------------------
8636 -- Process_Interface_Name --
8637 ----------------------------
8639 procedure Process_Interface_Name
8640 (Subprogram_Def : Entity_Id;
8646 String_Val : String_Id;
8648 procedure Check_Form_Of_Interface_Name
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.
8657 ----------------------------------
8658 -- Check_Form_Of_Interface_Name --
8659 ----------------------------------
8661 procedure Check_Form_Of_Interface_Name
8663 Ext_Name_Case : Boolean)
8665 S : constant String_Id := Strval (Expr_Value_S (SN));
8666 SL : constant Nat := String_Length (S);
8671 Error_Msg_N ("interface name cannot be null string", SN);
8674 for J in 1 .. SL loop
8675 C := Get_String_Char (S, J);
8677 -- Look for dubious character and issue unconditional warning.
8678 -- Definitely dubious if not in character range.
8680 if not In_Character_Range (C)
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
8689 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
8690 and then (Get_Character (C) = ','
8692 Get_Character (C) = '\'))
8693 or else (VM_Target /= CLI_Target
8694 and then (Get_Character (C) = ' '
8696 Get_Character (C) = '/'))
8699 ("??interface name contains illegal character",
8700 Sloc (SN) + Source_Ptr (J));
8703 end Check_Form_Of_Interface_Name;
8705 -- Start of processing for Process_Interface_Name
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)))
8719 (Generic_Parent (Parent (Subprogram_Def))));
8724 elsif Chars (Ext_Arg) = Name_Link_Name then
8726 Link_Nam := Expression (Ext_Arg);
8729 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
8730 Ext_Nam := Expression (Ext_Arg);
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);
8741 -- Check expressions for external name and link name are static
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);
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).
8759 if Prag_Id = Pragma_Import then
8760 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
8762 E := Entity_Id (Get_Name_Table_Info (Nam));
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
8772 while Present (Par) loop
8773 if Nkind (Par) = N_Package_Body then
8774 Error_Msg_Sloc := Sloc (E);
8776 ("imported entity is hidden by & declared#",
8781 Par := Parent (Par);
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);
8793 -- If there is no link name, just set the external name
8795 if No (Link_Nam) then
8796 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
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
8807 if VM_Target = No_VM then
8808 Store_String_Char (Get_Char_Code ('*'));
8811 String_Val := Strval (Expr_Value_S (Link_Nam));
8812 Store_String_Chars (String_Val);
8814 Make_String_Literal (Sloc (Link_Nam),
8815 Strval => End_String);
8818 -- Set the interface name. If the entity is a generic instance, use
8819 -- its alias, which is the callable entity.
8821 if Is_Generic_Instance (Subprogram_Def) then
8822 Set_Encoded_Interface_Name
8823 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
8825 Set_Encoded_Interface_Name
8826 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
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.
8833 if Convention (Subprogram_Def) /= Convention_CIL
8835 Convention (Subprogram_Def) /= Convention_Java
8837 Check_Duplicated_Export_Name (Link_Nam);
8839 end Process_Interface_Name;
8841 -----------------------------------------
8842 -- Process_Interrupt_Or_Attach_Handler --
8843 -----------------------------------------
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);
8851 Set_Is_Interrupt_Handler (Handler_Proc);
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.
8858 if Ekind (Proc_Scope) = E_Protected_Type then
8859 if Prag_Id = Pragma_Interrupt_Handler
8861 Prag_Id = Pragma_Attach_Handler
8863 Record_Rep_Item (Proc_Scope, N);
8866 end Process_Interrupt_Or_Attach_Handler;
8868 --------------------------------------------------
8869 -- Process_Restrictions_Or_Restriction_Warnings --
8870 --------------------------------------------------
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.
8876 procedure Process_Restrictions_Or_Restriction_Warnings
8880 R_Id : Restriction_Id;
8886 -- Ignore all Restrictions pragmas in CodePeer mode
8888 if CodePeer_Mode then
8892 Check_Ada_83_Warning;
8893 Check_At_Least_N_Arguments (1);
8894 Check_Valid_Configuration_Pragma;
8897 while Present (Arg) loop
8899 Expr := Get_Pragma_Arg (Arg);
8901 -- Case of no restriction identifier present
8903 if Id = No_Name then
8904 if Nkind (Expr) /= N_Identifier then
8906 ("invalid form for restriction", Arg);
8911 (Process_Restriction_Synonyms (Expr));
8913 if R_Id not in All_Boolean_Restrictions then
8914 Error_Msg_Name_1 := Pname;
8916 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
8918 -- Check for possible misspelling
8920 for J in Restriction_Id loop
8922 Rnm : constant String := Restriction_Id'Image (J);
8925 Name_Buffer (1 .. Rnm'Length) := Rnm;
8926 Name_Len := Rnm'Length;
8927 Set_Casing (All_Lower_Case);
8929 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
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));
8946 if Implementation_Restriction (R_Id) then
8947 Check_Restriction (No_Implementation_Restrictions, Arg);
8950 -- Special processing for No_Elaboration_Code restriction
8952 if R_Id = No_Elaboration_Code then
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.
8959 if not (Current_Sem_Unit = Main_Unit
8960 or else In_Extended_Main_Source_Unit (N))
8964 -- Don't allow in a subunit unless already specified in
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)
8972 ("invalid specification of ""No_Elaboration_Code""",
8975 ("\restriction cannot be specified in a subunit", N);
8977 ("\unless also specified in body or spec", N);
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.
8986 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
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).
8995 if not Restriction_Active (R_Id) then
8996 Set_Restriction (R_Id, N);
8997 Restriction_Warnings (R_Id) := True;
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.
9005 Set_Restriction (R_Id, N);
9006 Restriction_Warnings (R_Id) := False;
9009 -- Check for obsolescent restrictions in Ada 2005 mode
9012 and then Ada_Version >= Ada_2005
9013 and then (R_Id = No_Asynchronous_Control
9015 R_Id = No_Unchecked_Deallocation
9017 R_Id = No_Unchecked_Conversion)
9019 Check_Restriction (No_Obsolescent_Features, N);
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.
9029 -- Atomic_Synchronization is not a real check, so it is not
9030 -- affected by this processing).
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;
9040 -- Case of No_Dependence => unit-name. Note that the parser
9041 -- already made the necessary entry in the No_Dependence table.
9043 elsif Id = Name_No_Dependence then
9044 if not OK_No_Dependence_Unit_Name (Expr) then
9048 -- Case of No_Specification_Of_Aspect => Identifier.
9050 elsif Id = Name_No_Specification_Of_Aspect then
9055 if Nkind (Expr) /= N_Identifier then
9058 A_Id := Get_Aspect_Id (Chars (Expr));
9061 if A_Id = No_Aspect then
9062 Error_Pragma_Arg ("invalid restriction name", Arg);
9064 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
9068 elsif Id = Name_No_Use_Of_Attribute then
9069 if Nkind (Expr) /= N_Identifier
9070 or else not Is_Attribute_Name (Chars (Expr))
9072 Error_Msg_N ("unknown attribute name??", Expr);
9075 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
9078 elsif Id = Name_No_Use_Of_Pragma then
9079 if Nkind (Expr) /= N_Identifier
9080 or else not Is_Pragma_Name (Chars (Expr))
9082 Error_Msg_N ("unknown pragma name??", Expr);
9085 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
9088 -- All other cases of restriction identifier present
9091 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
9092 Analyze_And_Resolve (Expr, Any_Integer);
9094 if R_Id not in All_Parameter_Restrictions then
9096 ("invalid restriction parameter identifier", Arg);
9098 elsif not Is_OK_Static_Expression (Expr) then
9099 Flag_Non_Static_Expr
9100 ("value must be static expression!", Expr);
9103 elsif not Is_Integer_Type (Etype (Expr))
9104 or else Expr_Value (Expr) < 0
9107 ("value must be non-negative integer", Arg);
9110 -- Restriction pragma is active
9112 Val := Expr_Value (Expr);
9114 if not UI_Is_In_Int_Range (Val) then
9116 ("pragma ignored, value too large??", Arg);
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.
9126 if not Restriction_Active (R_Id) then
9128 (R_Id, N, Integer (UI_To_Int (Val)));
9129 Restriction_Warnings (R_Id) := True;
9132 -- Real restriction case, set restriction and make sure warning
9133 -- flag is off since real restriction always overrides warning.
9136 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
9137 Restriction_Warnings (R_Id) := False;
9143 end Process_Restrictions_Or_Restriction_Warnings;
9145 ---------------------------------
9146 -- Process_Suppress_Unsuppress --
9147 ---------------------------------
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.
9153 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
9158 In_Package_Spec : constant Boolean :=
9159 Is_Package_Or_Generic_Package (Current_Scope)
9160 and then not In_Package_Body (Current_Scope);
9162 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
9163 -- Used to suppress a single check on the given entity
9165 --------------------------------
9166 -- Suppress_Unsuppress_Echeck --
9167 --------------------------------
9169 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
9171 -- Check for error of trying to set atomic synchronization for
9172 -- a non-atomic variable.
9174 if C = Atomic_Synchronization
9175 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
9178 ("pragma & requires atomic type or variable",
9179 Pragma_Identifier (Original_Node (N)));
9182 Set_Checks_May_Be_Suppressed (E);
9184 if In_Package_Spec then
9185 Push_Global_Suppress_Stack_Entry
9188 Suppress => Suppress_Case);
9190 Push_Local_Suppress_Stack_Entry
9193 Suppress => Suppress_Case);
9196 -- If this is a first subtype, and the base type is distinct,
9197 -- then also set the suppress flags on the base type.
9199 if Is_First_Subtype (E) and then Etype (E) /= E then
9200 Suppress_Unsuppress_Echeck (Etype (E), C);
9202 end Suppress_Unsuppress_Echeck;
9204 -- Start of processing for Process_Suppress_Unsuppress
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
9211 if (CodePeer_Mode or GNATprove_Mode)
9212 and then Comes_From_Source (N)
9217 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9218 -- declarative part or a package spec (RM 11.5(5)).
9220 if not Is_Configuration_Pragma then
9221 Check_Is_In_Decl_Part_Or_Package_Spec;
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);
9229 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
9231 if C = No_Check_Id then
9233 ("argument of pragma% is not valid check name", Arg1);
9236 if Arg_Count = 1 then
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.
9242 if C = All_Checks then
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.
9251 for J in Scope_Suppress.Suppress'Range loop
9252 if J /= Elaboration_Check
9254 J /= Atomic_Synchronization
9256 Scope_Suppress.Suppress (J) := Suppress_Case;
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.
9265 elsif C in Predefined_Check_Id
9266 and then (not Comes_From_Source (N)
9267 or else C /= Atomic_Synchronization)
9269 Scope_Suppress.Suppress (C) := Suppress_Case;
9272 -- Also make an entry in the Local_Entity_Suppress table
9274 Push_Local_Suppress_Stack_Entry
9277 Suppress => Suppress_Case);
9279 -- Case of two arguments present, where the check is suppressed for
9280 -- a specified entity (given as the second argument of the pragma)
9283 -- This is obsolescent in Ada 2005 mode
9285 if Ada_Version >= Ada_2005 then
9286 Check_Restriction (No_Obsolescent_Features, Arg2);
9289 Check_Optional_Identifier (Arg2, Name_On);
9290 E_Id := Get_Pragma_Arg (Arg2);
9293 if not Is_Entity_Name (E_Id) then
9295 ("second argument of pragma% must be entity name", Arg2);
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).
9311 and then E /= Current_Scope
9312 and then Scope (E) /= Current_Scope
9315 ("entity in pragma% is not in package spec (RM 11.5(7))",
9319 -- Loop through homonyms. As noted below, in the case of a package
9320 -- spec, only homonyms within the package spec are considered.
9323 Suppress_Unsuppress_Echeck (E, C);
9325 if Is_Generic_Instance (E)
9326 and then Is_Subprogram (E)
9327 and then Present (Alias (E))
9329 Suppress_Unsuppress_Echeck (Alias (E), C);
9332 -- Move to next homonym if not aspect spec case
9334 exit when From_Aspect_Specification (N);
9338 -- If we are within a package specification, the pragma only
9339 -- applies to homonyms in the same scope.
9341 exit when In_Package_Spec
9342 and then Scope (E) /= Current_Scope;
9345 end Process_Suppress_Unsuppress;
9351 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
9353 if Is_Imported (E) then
9355 ("cannot export entity& that was previously imported", Arg);
9357 elsif Present (Address_Clause (E))
9358 and then not Relaxed_RM_Semantics
9361 ("cannot export entity& that has an address clause", Arg);
9364 Set_Is_Exported (E);
9366 -- Generate a reference for entity explicitly, because the
9367 -- identifier may be overloaded and name resolution will not
9370 Generate_Reference (E, Arg);
9372 -- Deal with exporting non-library level entity
9374 if not Is_Library_Level_Entity (E) then
9376 -- Not allowed at all for subprograms
9378 if Is_Subprogram (E) then
9379 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
9381 -- Otherwise set public and statically allocated
9385 Set_Is_Statically_Allocated (E);
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.
9393 if Warn_On_Export_Import
9394 and then Comes_From_Source (Arg)
9397 ("?x?& has been made static as a result of Export",
9400 ("\?x?this usage is non-standard and non-portable",
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);
9410 if Warn_On_Export_Import and Inside_A_Generic then
9412 ("all instances of& will have the same external name?x?",
9417 ----------------------------------------------
9418 -- Set_Extended_Import_Export_External_Name --
9419 ----------------------------------------------
9421 procedure Set_Extended_Import_Export_External_Name
9422 (Internal_Ent : Entity_Id;
9423 Arg_External : Node_Id)
9425 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
9429 if No (Arg_External) then
9433 Check_Arg_Is_External_Name (Arg_External);
9435 if Nkind (Arg_External) = N_String_Literal then
9436 if String_Length (Strval (Arg_External)) = 0 then
9439 New_Name := Adjust_External_Name_Case (Arg_External);
9442 elsif Nkind (Arg_External) = N_Identifier then
9443 New_Name := Get_Default_External_Name (Arg_External);
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).
9450 raise Program_Error;
9453 -- If we already have an external name set (by a prior normal Import
9454 -- or Export pragma), then the external names must match
9456 if Present (Interface_Name (Internal_Ent)) then
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:
9462 -- pragma Export_Procedure (P, "a");
9463 -- pragma Export_Procedure (P, "b");
9465 if CodePeer_Mode then
9469 Check_Matching_Internal_Names : declare
9470 S1 : constant String_Id := Strval (Old_Name);
9471 S2 : constant String_Id := Strval (New_Name);
9474 pragma No_Return (Mismatch);
9475 -- Called if names do not match
9481 procedure Mismatch is
9483 Error_Msg_Sloc := Sloc (Old_Name);
9485 ("external name does not match that given #",
9489 -- Start of processing for Check_Matching_Internal_Names
9492 if String_Length (S1) /= String_Length (S2) then
9496 for J in 1 .. String_Length (S1) loop
9497 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
9502 end Check_Matching_Internal_Names;
9504 -- Otherwise set the given name
9507 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
9508 Check_Duplicated_Export_Name (New_Name);
9510 end Set_Extended_Import_Export_External_Name;
9516 procedure Set_Imported (E : Entity_Id) is
9518 -- Error message if already imported or exported
9520 if Is_Exported (E) or else Is_Imported (E) then
9522 -- Error if being set Exported twice
9524 if Is_Exported (E) then
9525 Error_Msg_NE ("entity& was previously exported", N, E);
9527 -- Ignore error in CodePeer mode where we treat all imported
9528 -- subprograms as unknown.
9530 elsif CodePeer_Mode then
9533 -- OK if Import/Interface case
9535 elsif Import_Interface_Present (N) then
9538 -- Error if being set Imported twice
9541 Error_Msg_NE ("entity& was previously imported", N, E);
9544 Error_Msg_Name_1 := Pname;
9546 ("\(pragma% applies to all previous entities)", N);
9548 Error_Msg_Sloc := Sloc (E);
9549 Error_Msg_NE ("\import not allowed for& declared#", N, E);
9551 -- Here if not previously imported or exported, OK to import
9554 Set_Is_Imported (E);
9556 -- For subprogram, set Import_Pragma field
9558 if Is_Subprogram (E) then
9559 Set_Import_Pragma (E, N);
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.
9568 and then not Is_Library_Level_Entity (E)
9569 and then No (Address_Clause (E))
9571 Set_Is_Statically_Allocated (E);
9578 -------------------------
9579 -- Set_Mechanism_Value --
9580 -------------------------
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.
9586 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
9589 Mech_Name_Id : Name_Id;
9591 procedure Bad_Class;
9592 pragma No_Return (Bad_Class);
9593 -- Signal bad descriptor class name
9595 procedure Bad_Mechanism;
9596 pragma No_Return (Bad_Mechanism);
9597 -- Signal bad mechanism name
9603 procedure Bad_Class is
9605 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
9608 -------------------------
9609 -- Bad_Mechanism_Value --
9610 -------------------------
9612 procedure Bad_Mechanism is
9614 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
9617 -- Start of processing for Set_Mechanism_Value
9620 if Mechanism (Ent) /= Default_Mechanism then
9622 ("mechanism for & has already been set", Mech_Name, Ent);
9625 -- MECHANISM_NAME ::= value | reference | descriptor |
9628 if Nkind (Mech_Name) = N_Identifier then
9629 if Chars (Mech_Name) = Name_Value then
9630 Set_Mechanism (Ent, By_Copy);
9633 elsif Chars (Mech_Name) = Name_Reference then
9634 Set_Mechanism (Ent, By_Reference);
9637 elsif Chars (Mech_Name) = Name_Descriptor then
9638 Check_VMS (Mech_Name);
9640 -- Descriptor => Short_Descriptor if pragma was given
9642 if Short_Descriptors then
9643 Set_Mechanism (Ent, By_Short_Descriptor);
9645 Set_Mechanism (Ent, By_Descriptor);
9650 elsif Chars (Mech_Name) = Name_Short_Descriptor then
9651 Check_VMS (Mech_Name);
9652 Set_Mechanism (Ent, By_Short_Descriptor);
9655 elsif Chars (Mech_Name) = Name_Copy then
9657 ("bad mechanism name, Value assumed", Mech_Name);
9663 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
9664 -- short_descriptor (CLASS_NAME)
9665 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9667 -- Note: this form is parsed as an indexed component
9669 elsif Nkind (Mech_Name) = N_Indexed_Component then
9670 Class := First (Expressions (Mech_Name));
9672 if Nkind (Prefix (Mech_Name)) /= N_Identifier
9674 not Nam_In (Chars (Prefix (Mech_Name)), Name_Descriptor,
9675 Name_Short_Descriptor)
9676 or else Present (Next (Class))
9680 Mech_Name_Id := Chars (Prefix (Mech_Name));
9682 -- Change Descriptor => Short_Descriptor if pragma was given
9684 if Mech_Name_Id = Name_Descriptor
9685 and then Short_Descriptors
9687 Mech_Name_Id := Name_Short_Descriptor;
9691 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
9692 -- short_descriptor (Class => CLASS_NAME)
9693 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9695 -- Note: this form is parsed as a function call
9697 elsif Nkind (Mech_Name) = N_Function_Call then
9698 Param := First (Parameter_Associations (Mech_Name));
9700 if Nkind (Name (Mech_Name)) /= N_Identifier
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
9710 Class := Explicit_Actual_Parameter (Param);
9711 Mech_Name_Id := Chars (Name (Mech_Name));
9718 -- Fall through here with Class set to descriptor class name
9720 Check_VMS (Mech_Name);
9722 if Nkind (Class) /= N_Identifier then
9725 elsif Mech_Name_Id = Name_Descriptor
9726 and then Chars (Class) = Name_UBS
9728 Set_Mechanism (Ent, By_Descriptor_UBS);
9730 elsif Mech_Name_Id = Name_Descriptor
9731 and then Chars (Class) = Name_UBSB
9733 Set_Mechanism (Ent, By_Descriptor_UBSB);
9735 elsif Mech_Name_Id = Name_Descriptor
9736 and then Chars (Class) = Name_UBA
9738 Set_Mechanism (Ent, By_Descriptor_UBA);
9740 elsif Mech_Name_Id = Name_Descriptor
9741 and then Chars (Class) = Name_S
9743 Set_Mechanism (Ent, By_Descriptor_S);
9745 elsif Mech_Name_Id = Name_Descriptor
9746 and then Chars (Class) = Name_SB
9748 Set_Mechanism (Ent, By_Descriptor_SB);
9750 elsif Mech_Name_Id = Name_Descriptor
9751 and then Chars (Class) = Name_A
9753 Set_Mechanism (Ent, By_Descriptor_A);
9755 elsif Mech_Name_Id = Name_Descriptor
9756 and then Chars (Class) = Name_NCA
9758 Set_Mechanism (Ent, By_Descriptor_NCA);
9760 elsif Mech_Name_Id = Name_Short_Descriptor
9761 and then Chars (Class) = Name_UBS
9763 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
9765 elsif Mech_Name_Id = Name_Short_Descriptor
9766 and then Chars (Class) = Name_UBSB
9768 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
9770 elsif Mech_Name_Id = Name_Short_Descriptor
9771 and then Chars (Class) = Name_UBA
9773 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
9775 elsif Mech_Name_Id = Name_Short_Descriptor
9776 and then Chars (Class) = Name_S
9778 Set_Mechanism (Ent, By_Short_Descriptor_S);
9780 elsif Mech_Name_Id = Name_Short_Descriptor
9781 and then Chars (Class) = Name_SB
9783 Set_Mechanism (Ent, By_Short_Descriptor_SB);
9785 elsif Mech_Name_Id = Name_Short_Descriptor
9786 and then Chars (Class) = Name_A
9788 Set_Mechanism (Ent, By_Short_Descriptor_A);
9790 elsif Mech_Name_Id = Name_Short_Descriptor
9791 and then Chars (Class) = Name_NCA
9793 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
9798 end Set_Mechanism_Value;
9800 --------------------------
9801 -- Set_Rational_Profile --
9802 --------------------------
9804 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9805 -- and extension to the semantics of renaming declarations.
9807 procedure Set_Rational_Profile is
9809 Implicit_Packing := True;
9810 Overriding_Renamings := True;
9811 Use_VADS_Size := True;
9812 end Set_Rational_Profile;
9814 ---------------------------
9815 -- Set_Ravenscar_Profile --
9816 ---------------------------
9818 -- The tasks to be done here are
9820 -- Set required policies
9822 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9823 -- pragma Locking_Policy (Ceiling_Locking)
9825 -- Set Detect_Blocking mode
9827 -- Set required restrictions (see System.Rident for detailed list)
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
9837 procedure Set_Ravenscar_Profile (N : Node_Id) is
9838 Prefix_Entity : Entity_Id;
9839 Selector_Entity : Entity_Id;
9840 Prefix_Node : Node_Id;
9844 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9846 if Task_Dispatching_Policy /= ' '
9847 and then Task_Dispatching_Policy /= 'F'
9849 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9850 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9852 -- Set the FIFO_Within_Priorities policy, but always preserve
9853 -- System_Location since we like the error message with the run time
9857 Task_Dispatching_Policy := 'F';
9859 if Task_Dispatching_Policy_Sloc /= System_Location then
9860 Task_Dispatching_Policy_Sloc := Loc;
9864 -- pragma Locking_Policy (Ceiling_Locking)
9866 if Locking_Policy /= ' '
9867 and then Locking_Policy /= 'C'
9869 Error_Msg_Sloc := Locking_Policy_Sloc;
9870 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
9872 -- Set the Ceiling_Locking policy, but preserve System_Location since
9873 -- we like the error message with the run time name.
9876 Locking_Policy := 'C';
9878 if Locking_Policy_Sloc /= System_Location then
9879 Locking_Policy_Sloc := Loc;
9883 -- pragma Detect_Blocking
9885 Detect_Blocking := True;
9887 -- Set the corresponding restrictions
9889 Set_Profile_Restrictions
9890 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
9892 -- Set the No_Dependence restrictions
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.
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
9904 if Ada_Version >= Ada_2005 then
9905 Name_Buffer (1 .. 3) := "ada";
9908 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9910 Name_Buffer (1 .. 14) := "execution_time";
9913 Selector_Entity := Make_Identifier (Loc, Name_Find);
9916 Make_Selected_Component
9918 Prefix => Prefix_Entity,
9919 Selector_Name => Selector_Entity);
9921 Name_Buffer (1 .. 13) := "group_budgets";
9924 Selector_Entity := Make_Identifier (Loc, Name_Find);
9927 Make_Selected_Component
9929 Prefix => Prefix_Node,
9930 Selector_Name => Selector_Entity);
9932 Set_Restriction_No_Dependence
9934 Warn => Treat_Restrictions_As_Warnings,
9935 Profile => Ravenscar);
9937 Name_Buffer (1 .. 6) := "timers";
9940 Selector_Entity := Make_Identifier (Loc, Name_Find);
9943 Make_Selected_Component
9945 Prefix => Prefix_Node,
9946 Selector_Name => Selector_Entity);
9948 Set_Restriction_No_Dependence
9950 Warn => Treat_Restrictions_As_Warnings,
9951 Profile => Ravenscar);
9954 -- Set the following restrictions which was added to Ada 2012 (see
9956 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9958 if Ada_Version >= Ada_2012 then
9959 Name_Buffer (1 .. 6) := "system";
9962 Prefix_Entity := Make_Identifier (Loc, Name_Find);
9964 Name_Buffer (1 .. 15) := "multiprocessors";
9967 Selector_Entity := Make_Identifier (Loc, Name_Find);
9970 Make_Selected_Component
9972 Prefix => Prefix_Entity,
9973 Selector_Name => Selector_Entity);
9975 Name_Buffer (1 .. 19) := "dispatching_domains";
9978 Selector_Entity := Make_Identifier (Loc, Name_Find);
9981 Make_Selected_Component
9983 Prefix => Prefix_Node,
9984 Selector_Name => Selector_Entity);
9986 Set_Restriction_No_Dependence
9988 Warn => Treat_Restrictions_As_Warnings,
9989 Profile => Ravenscar);
9991 end Set_Ravenscar_Profile;
9993 -- Start of processing for Analyze_Pragma
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.
10000 if Analyzed (N) then
10003 Set_Analyzed (N, True);
10006 -- Deal with unrecognized pragma
10008 Pname := Pragma_Name (N);
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));
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));
10028 -- Here to start processing for recognized pragma
10030 Prag_Id := Get_Pragma_Id (Pname);
10031 Pname := Original_Aspect_Name (N);
10033 -- Capture setting of Opt.Uneval_Old
10035 case Opt.Uneval_Old is
10037 Set_Uneval_Old_Accept (N);
10041 Set_Uneval_Old_Warn (N);
10043 raise Program_Error;
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.
10051 if Is_Ignored (N) or else Is_Checked (N) then
10054 -- For a pragma that is a rewriting of another pragma, copy the
10055 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10057 elsif Is_Rewrite_Substitution (N)
10058 and then Nkind (Original_Node (N)) = N_Pragma
10059 and then Original_Node (N) /= N
10061 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
10062 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
10064 -- Otherwise query the applicable policy at this point
10067 Check_Applicable_Policy (N);
10069 -- If pragma is disabled, rewrite as NULL and skip analysis
10071 if Is_Disabled (N) then
10072 Rewrite (N, Make_Null_Statement (Loc));
10078 -- Preset arguments
10086 if Present (Pragma_Argument_Associations (N)) then
10087 Arg_Count := List_Length (Pragma_Argument_Associations (N));
10088 Arg1 := First (Pragma_Argument_Associations (N));
10090 if Present (Arg1) then
10091 Arg2 := Next (Arg1);
10093 if Present (Arg2) then
10094 Arg3 := Next (Arg2);
10096 if Present (Arg3) then
10097 Arg4 := Next (Arg3);
10103 Check_Restriction_No_Use_Of_Pragma (N);
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.
10115 -- pragma Abort_Defer;
10117 when Pragma_Abort_Defer =>
10119 Check_Arg_Count (0);
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.
10125 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
10126 or else N /= First (Statements (Parent (N)))
10131 --------------------
10132 -- Abstract_State --
10133 --------------------
10135 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10137 -- ABSTRACT_STATE_LIST ::=
10139 -- | STATE_NAME_WITH_OPTIONS
10140 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
10142 -- STATE_NAME_WITH_OPTIONS ::=
10144 -- | (STATE_NAME with OPTION_LIST)
10146 -- OPTION_LIST ::= OPTION {, OPTION}
10150 -- | NAME_VALUE_OPTION
10152 -- SIMPLE_OPTION ::= identifier
10154 -- NAME_VALUE_OPTION ::=
10155 -- Part_Of => ABSTRACT_STATE
10156 -- | External [=> EXTERNAL_PROPERTY_LIST]
10158 -- EXTERNAL_PROPERTY_LIST ::=
10159 -- EXTERNAL_PROPERTY
10160 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
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
10169 -- STATE_NAME ::= defining_identifier
10171 -- ABSTRACT_STATE ::= name
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
10178 -- Flags used to verify the consistency of states
10180 Non_Null_Seen : Boolean := False;
10181 Null_Seen : Boolean := False;
10183 Pack_Id : Entity_Id;
10184 -- Entity of related package when pragma Abstract_State appears
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.
10191 ----------------------------
10192 -- Analyze_Abstract_State --
10193 ----------------------------
10195 procedure Analyze_Abstract_State (State : Node_Id) is
10197 -- Flags used to verify the consistency of options
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;
10207 -- Flags used to store the static value of all external states'
10210 AR_Val : Boolean := False;
10211 AW_Val : Boolean := False;
10212 ER_Val : Boolean := False;
10213 EW_Val : Boolean := False;
10215 State_Id : Entity_Id := Empty;
10216 -- The entity to be generated for the current state declaration
10218 procedure Analyze_External_Option (Opt : Node_Id);
10219 -- Verify the legality of option External
10221 procedure Analyze_External_Property
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.
10228 procedure Analyze_Part_Of_Option (Opt : Node_Id);
10229 -- Verify the legality of option Part_Of
10231 procedure Check_Duplicate_Option
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)).
10239 procedure Check_Duplicate_Property
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))
10248 procedure Create_Abstract_State
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
10260 -----------------------------
10261 -- Analyze_External_Option --
10262 -----------------------------
10264 procedure Analyze_External_Option (Opt : Node_Id) is
10265 Errors : constant Nat := Serious_Errors_Detected;
10267 Props : Node_Id := Empty;
10270 Check_Duplicate_Option (Opt, External_Seen);
10272 if Nkind (Opt) = N_Component_Association then
10273 Props := Expression (Opt);
10276 -- External state with properties
10278 if Present (Props) then
10280 -- Multiple properties appear as an aggregate
10282 if Nkind (Props) = N_Aggregate then
10284 -- Simple property form
10286 Prop := First (Expressions (Props));
10287 while Present (Prop) loop
10288 Analyze_External_Property (Prop);
10292 -- Property with expression form
10294 Prop := First (Component_Associations (Props));
10295 while Present (Prop) loop
10296 Analyze_External_Property
10297 (Prop => First (Choices (Prop)),
10298 Expr => Expression (Prop));
10306 Analyze_External_Property (Props);
10309 -- An external state defined without any properties defaults
10310 -- all properties to True.
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.
10324 if Errors = Serious_Errors_Detected then
10325 Check_External_Properties
10326 (State, AR_Val, AW_Val, ER_Val, EW_Val);
10328 end Analyze_External_Option;
10330 -------------------------------
10331 -- Analyze_External_Property --
10332 -------------------------------
10334 procedure Analyze_External_Property
10336 Expr : Node_Id := Empty)
10338 Expr_Val : Boolean;
10341 -- Check the placement of "others" (if available)
10343 if Nkind (Prop) = N_Others_Choice then
10344 if Others_Seen then
10346 ("only one others choice allowed in option External",
10349 Others_Seen := True;
10352 elsif Others_Seen then
10354 ("others must be the last property in option External",
10357 -- The only remaining legal options are the four predefined
10358 -- external properties.
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)
10368 -- Otherwise the construct is not a valid property
10371 SPARK_Msg_N ("invalid external state property", Prop);
10375 -- Ensure that the expression of the external state property
10376 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10378 if Present (Expr) then
10379 Analyze_And_Resolve (Expr, Standard_Boolean);
10381 if Is_OK_Static_Expression (Expr) then
10382 Expr_Val := Is_True (Expr_Value (Expr));
10385 ("expression of external state property must be "
10389 -- The lack of expression defaults the property to True
10395 -- Named properties
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;
10402 elsif Chars (Prop) = Name_Async_Writers then
10403 Check_Duplicate_Property (Prop, AW_Seen);
10404 AW_Val := Expr_Val;
10406 elsif Chars (Prop) = Name_Effective_Reads then
10407 Check_Duplicate_Property (Prop, ER_Seen);
10408 ER_Val := Expr_Val;
10411 Check_Duplicate_Property (Prop, EW_Seen);
10412 EW_Val := Expr_Val;
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
10421 if not AR_Seen then
10422 AR_Val := Expr_Val;
10425 if not AW_Seen then
10426 AW_Val := Expr_Val;
10429 if not ER_Seen then
10430 ER_Val := Expr_Val;
10433 if not EW_Seen then
10434 EW_Val := Expr_Val;
10437 end Analyze_External_Property;
10439 ----------------------------
10440 -- Analyze_Part_Of_Option --
10441 ----------------------------
10443 procedure Analyze_Part_Of_Option (Opt : Node_Id) is
10444 Encaps : constant Node_Id := Expression (Opt);
10445 Encaps_Id : Entity_Id;
10449 Check_Duplicate_Option (Opt, Part_Of_Seen);
10452 (Item_Id => State_Id,
10454 Indic => First (Choices (Opt)),
10457 -- The Part_Of indicator turns an abstract state into a
10458 -- constituent of the encapsulating state.
10461 Encaps_Id := Entity (Encaps);
10463 Append_Elmt (State_Id, Part_Of_Constituents (Encaps_Id));
10464 Set_Encapsulating_State (State_Id, Encaps_Id);
10466 end Analyze_Part_Of_Option;
10468 ----------------------------
10469 -- Check_Duplicate_Option --
10470 ----------------------------
10472 procedure Check_Duplicate_Option
10474 Status : in out Boolean)
10478 SPARK_Msg_N ("duplicate state option", Opt);
10482 end Check_Duplicate_Option;
10484 ------------------------------
10485 -- Check_Duplicate_Property --
10486 ------------------------------
10488 procedure Check_Duplicate_Property
10490 Status : in out Boolean)
10494 SPARK_Msg_N ("duplicate external property", Prop);
10498 end Check_Duplicate_Property;
10500 ---------------------------
10501 -- Create_Abstract_State --
10502 ---------------------------
10504 procedure Create_Abstract_State
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.
10515 if Present (Decl) and then Present (Entity (Decl)) then
10516 State_Id := Entity (Decl);
10518 -- Otherwise the elaboration of pragma Abstract_State
10519 -- declares the state.
10522 State_Id := Make_Defining_Identifier (Loc, Nam);
10524 if Present (Decl) then
10525 Set_Entity (Decl, State_Id);
10529 -- Null states never come from source
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);
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.
10543 if not Is_Null then
10544 if Present (Decl) then
10545 Set_Entity (Decl, State_Id);
10546 Set_Etype (Decl, Standard_Void_Type);
10549 -- Every non-null state must be defined, nameable and
10552 Push_Scope (Pack_Id);
10553 Generate_Definition (State_Id);
10554 Enter_Name (State_Id);
10557 end Create_Abstract_State;
10564 -- Start of processing for Analyze_Abstract_State
10567 -- A package with a null abstract state is not allowed to
10568 -- declare additional states.
10572 ("package & has null abstract state", State, Pack_Id);
10574 -- Null states appear as internally generated entities
10576 elsif Nkind (State) = N_Null then
10577 Create_Abstract_State
10578 (Nam => New_Internal_Name ('S'),
10580 Loc => Sloc (State),
10584 -- Catch a case where a null state appears in a list of
10585 -- non-null states.
10587 if Non_Null_Seen then
10589 ("package & has non-null abstract state",
10593 -- Simple state declaration
10595 elsif Nkind (State) = N_Identifier then
10596 Create_Abstract_State
10597 (Nam => Chars (State),
10599 Loc => Sloc (State),
10601 Non_Null_Seen := True;
10603 -- State declaration with various options. This construct
10604 -- appears as an extension aggregate in the tree.
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)),
10613 Non_Null_Seen := True;
10616 ("state name must be an identifier",
10617 Ancestor_Part (State));
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.
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);
10630 -- Option Part_Of without an encapsulating state is
10631 -- illegal. (SPARK RM 7.1.4(9)).
10633 elsif Chars (Opt) = Name_Part_Of then
10635 ("indicator Part_Of must denote an abstract "
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.
10642 -- with Abstract_State
10643 -- (State_1 with ..., -- missing parentheses
10644 -- (State_2 with ...),
10645 -- State_3) -- ok state declaration
10647 elsif Missing_Parentheses then
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.
10655 -- with Abstract_State
10656 -- (State_1 with ..., -- missing parentheses
10657 -- State_2); -- could be an option
10661 ("simple option not allowed in state declaration",
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.
10669 -- with Abstract_State
10670 -- (State_1 with ..., -- missing parentheses
10671 -- (State_2 with ...))
10673 elsif Nkind (Opt) = N_Extension_Aggregate then
10674 Missing_Parentheses := True;
10676 ("state declaration must be parenthesized",
10677 Ancestor_Part (State));
10679 -- Otherwise the option is malformed
10682 SPARK_Msg_N ("malformed option", Opt);
10688 -- Options External and Part_Of appear as component
10691 Opt := First (Component_Associations (State));
10692 while Present (Opt) loop
10693 Opt_Nam := First (Choices (Opt));
10695 if Nkind (Opt_Nam) = N_Identifier then
10696 if Chars (Opt_Nam) = Name_External then
10697 Analyze_External_Option (Opt);
10699 elsif Chars (Opt_Nam) = Name_Part_Of then
10700 Analyze_Part_Of_Option (Opt);
10703 SPARK_Msg_N ("invalid state option", Opt);
10706 SPARK_Msg_N ("invalid state option", Opt);
10712 -- Any other attempt to declare a state is illegal. This is a
10713 -- syntax error, always report.
10716 Error_Msg_N ("malformed abstract state declaration", State);
10720 -- Guard against a junk state. In such cases no entity is
10721 -- generated and the subsequent checks cannot be applied.
10723 if Present (State_Id) then
10725 -- Verify whether the state does not introduce an illegal
10726 -- hidden state within a package subject to a null abstract
10729 Check_No_Hidden_State (State_Id);
10731 -- Check whether the lack of option Part_Of agrees with the
10732 -- placement of the abstract state with respect to the state
10735 if not Part_Of_Seen then
10736 Check_Missing_Part_Of (State_Id);
10739 -- Associate the state with its related package
10741 if No (Abstract_States (Pack_Id)) then
10742 Set_Abstract_States (Pack_Id, New_Elmt_List);
10745 Append_Elmt (State_Id, Abstract_States (Pack_Id));
10747 end Analyze_Abstract_State;
10751 Context : constant Node_Id := Parent (Parent (N));
10754 -- Start of processing for Abstract_State
10758 Check_Arg_Count (1);
10759 Ensure_Aggregate_Form (Arg1);
10761 -- Ensure the proper placement of the pragma. Abstract states must
10762 -- be associated with a package declaration.
10764 if not Nkind_In (Context, N_Generic_Package_Declaration,
10765 N_Package_Declaration)
10771 State := Expression (Arg1);
10772 Pack_Id := Defining_Entity (Context);
10774 -- Multiple non-null abstract states appear as an aggregate
10776 if Nkind (State) = N_Aggregate then
10777 State := First (Expressions (State));
10778 while Present (State) loop
10779 Analyze_Abstract_State (State);
10783 -- Various forms of a single abstract state. Note that these may
10784 -- include malformed state declarations.
10787 Analyze_Abstract_State (State);
10790 -- Save the pragma for retrieval by other tools
10792 Add_Contract_Item (N, Pack_Id);
10794 -- Verify the declaration order of pragmas Abstract_State and
10797 Check_Declaration_Order
10799 Second => Get_Pragma (Pack_Id, Pragma_Initializes));
10800 end Abstract_State;
10808 -- Note: this pragma also has some specific processing in Par.Prag
10809 -- because we want to set the Ada version mode during parsing.
10811 when Pragma_Ada_83 =>
10813 Check_Arg_Count (0);
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.
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.
10825 if Ada_Version >= Ada_2005 then
10826 Check_Valid_Configuration_Pragma;
10829 -- Now set Ada 83 mode
10831 Ada_Version := Ada_83;
10832 Ada_Version_Explicit := Ada_83;
10833 Ada_Version_Pragma := N;
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.
10844 when Pragma_Ada_95 =>
10846 Check_Arg_Count (0);
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.
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.
10857 if Ada_Version >= Ada_2005 then
10858 Check_Valid_Configuration_Pragma;
10861 -- Now set Ada 95 mode
10863 Ada_Version := Ada_95;
10864 Ada_Version_Explicit := Ada_95;
10865 Ada_Version_Pragma := N;
10867 ---------------------
10868 -- Ada_05/Ada_2005 --
10869 ---------------------
10872 -- pragma Ada_05 (LOCAL_NAME);
10874 -- pragma Ada_2005;
10875 -- pragma Ada_2005 (LOCAL_NAME):
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.
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.
10890 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
10896 if Arg_Count = 1 then
10897 Check_Arg_Is_Local_Name (Arg1);
10898 E_Id := Get_Pragma_Arg (Arg1);
10900 if Etype (E_Id) = Any_Type then
10904 Set_Is_Ada_2005_Only (Entity (E_Id));
10905 Record_Rep_Item (Entity (E_Id), N);
10908 Check_Arg_Count (0);
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.
10916 Check_Valid_Configuration_Pragma;
10918 -- Now set appropriate Ada mode
10920 Ada_Version := Ada_2005;
10921 Ada_Version_Explicit := Ada_2005;
10922 Ada_Version_Pragma := N;
10926 ---------------------
10927 -- Ada_12/Ada_2012 --
10928 ---------------------
10931 -- pragma Ada_12 (LOCAL_NAME);
10933 -- pragma Ada_2012;
10934 -- pragma Ada_2012 (LOCAL_NAME):
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.
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.
10949 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
10955 if Arg_Count = 1 then
10956 Check_Arg_Is_Local_Name (Arg1);
10957 E_Id := Get_Pragma_Arg (Arg1);
10959 if Etype (E_Id) = Any_Type then
10963 Set_Is_Ada_2012_Only (Entity (E_Id));
10964 Record_Rep_Item (Entity (E_Id), N);
10967 Check_Arg_Count (0);
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.
10976 Check_Valid_Configuration_Pragma;
10978 -- Now set appropriate Ada mode
10980 Ada_Version := Ada_2012;
10981 Ada_Version_Explicit := Ada_2012;
10982 Ada_Version_Pragma := N;
10986 ----------------------
10987 -- All_Calls_Remote --
10988 ----------------------
10990 -- pragma All_Calls_Remote [(library_package_NAME)];
10992 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
10993 Lib_Entity : Entity_Id;
10996 Check_Ada_83_Warning;
10997 Check_Valid_Library_Unit_Pragma;
10999 if Nkind (N) = N_Null_Statement then
11003 Lib_Entity := Find_Lib_Unit_Name;
11005 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11007 if Present (Lib_Entity)
11008 and then not Debug_Flag_U
11010 if not Is_Remote_Call_Interface (Lib_Entity) then
11011 Error_Pragma ("pragma% only apply to rci unit");
11013 -- Set flag for entity of the library unit
11016 Set_Has_All_Calls_Remote (Lib_Entity);
11020 end All_Calls_Remote;
11022 ---------------------------
11023 -- Allow_Integer_Address --
11024 ---------------------------
11026 -- pragma Allow_Integer_Address;
11028 when Pragma_Allow_Integer_Address =>
11030 Check_Valid_Configuration_Pragma;
11031 Check_Arg_Count (0);
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.
11038 if Opt.Address_Is_Private then
11039 Opt.Allow_Integer_Address := True;
11047 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11048 -- ARG ::= NAME | EXPRESSION
11050 -- The first two arguments are by convention intended to refer to an
11051 -- external tool and a tool-specific function. These arguments are
11054 when Pragma_Annotate => Annotate : declare
11060 Check_At_Least_N_Arguments (1);
11062 -- See if last argument is Entity => local_Name, and if so process
11063 -- and then remove it for remaining processing.
11066 Last_Arg : constant Node_Id :=
11067 Last (Pragma_Argument_Associations (N));
11070 if Nkind (Last_Arg) = N_Pragma_Argument_Association
11071 and then Chars (Last_Arg) = Name_Entity
11073 Check_Arg_Is_Local_Name (Last_Arg);
11074 Arg_Count := Arg_Count - 1;
11076 -- Not allowed in compiler units (bootstrap issues)
11078 Check_Compiler_Unit ("Entity for pragma Annotate", N);
11082 -- Continue processing with last argument removed for now
11084 Check_Arg_Is_Identifier (Arg1);
11085 Check_No_Identifiers;
11088 -- Second parameter is optional, it is never analyzed
11093 -- Here if we have a second parameter
11096 -- Second parameter must be identifier
11098 Check_Arg_Is_Identifier (Arg2);
11100 -- Process remaining parameters if any
11102 Arg := Next (Arg2);
11103 while Present (Arg) loop
11104 Exp := Get_Pragma_Arg (Arg);
11107 if Is_Entity_Name (Exp) then
11110 -- For string literals, we assume Standard_String as the
11111 -- type, unless the string contains wide or wide_wide
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);
11120 Resolve (Exp, Standard_String);
11123 elsif Is_Overloaded (Exp) then
11125 ("ambiguous argument for pragma%", Exp);
11136 -------------------------------------------------
11137 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11138 -------------------------------------------------
11141 -- ( [Check => ] Boolean_EXPRESSION
11142 -- [, [Message =>] Static_String_EXPRESSION]);
11144 -- pragma Assert_And_Cut
11145 -- ( [Check => ] Boolean_EXPRESSION
11146 -- [, [Message =>] Static_String_EXPRESSION]);
11149 -- ( [Check => ] Boolean_EXPRESSION
11150 -- [, [Message =>] Static_String_EXPRESSION]);
11152 -- pragma Loop_Invariant
11153 -- ( [Check => ] Boolean_EXPRESSION
11154 -- [, [Message =>] Static_String_EXPRESSION]);
11156 when Pragma_Assert |
11157 Pragma_Assert_And_Cut |
11159 Pragma_Loop_Invariant =>
11164 Has_Loop_Entry : Boolean;
11167 function Contains_Loop_Entry return Boolean;
11168 -- Tests if Expr contains a Loop_Entry attribute reference
11170 -------------------------
11171 -- Contains_Loop_Entry --
11172 -------------------------
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
11182 function Process (N : Node_Id) return Traverse_Result is
11184 if Nkind (N) = N_Attribute_Reference
11185 and then Attribute_Name (N) = Name_Loop_Entry
11187 Has_Loop_Entry := True;
11194 procedure Traverse is new Traverse_Proc (Process);
11196 -- Start of processing for Contains_Loop_Entry
11199 Has_Loop_Entry := False;
11201 return Has_Loop_Entry;
11202 end Contains_Loop_Entry;
11204 -- Start of processing for Assert
11207 -- Assert is an Ada 2005 RM-defined pragma
11209 if Prag_Id = Pragma_Assert then
11212 -- The remaining ones are GNAT pragmas
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);
11224 -- Special processing for Loop_Invariant or for other cases if
11225 -- a Loop_Entry attribute is present.
11227 if Prag_Id = Pragma_Loop_Invariant
11228 or else Contains_Loop_Entry
11230 -- Check restricted placement, must be within a loop
11232 Check_Loop_Pragma_Placement;
11234 -- Do preanalyze to deal with embedded Loop_Entry attribute
11236 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
11239 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11240 -- a corresponding Check pragma:
11242 -- pragma Check (name, condition [, msg]);
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
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).
11254 Make_Pragma_Argument_Association (Loc,
11255 Expression => Make_Identifier (Loc, Pname)),
11256 Make_Pragma_Argument_Association (Sloc (Expr),
11257 Expression => Expr));
11259 if Arg_Count > 1 then
11260 Check_Optional_Identifier (Arg2, Name_Message);
11261 Append_To (Newa, New_Copy_Tree (Arg2));
11264 -- Rewrite as Check pragma
11268 Chars => Name_Check,
11269 Pragma_Argument_Associations => Newa));
11273 ----------------------
11274 -- Assertion_Policy --
11275 ----------------------
11277 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11279 -- The following form is Ada 2012 only, but we allow it in all modes
11281 -- Pragma Assertion_Policy (
11282 -- ASSERTION_KIND => POLICY_IDENTIFIER
11283 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11285 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11287 -- RM_ASSERTION_KIND ::= Assert |
11288 -- Static_Predicate |
11289 -- Dynamic_Predicate |
11294 -- Type_Invariant |
11295 -- Type_Invariant'Class
11297 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11299 -- Contract_Cases |
11301 -- Initial_Condition |
11302 -- Loop_Invariant |
11308 -- Statement_Assertions
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:
11316 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
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.
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.
11331 when Pragma_Assertion_Policy => Assertion_Policy : declare
11340 -- This can always appear as a configuration pragma
11342 if Is_Configuration_Pragma then
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.
11350 Check_Is_In_Decl_Part_Or_Package_Spec;
11354 -- One argument case with no identifier (first form above)
11357 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
11358 or else Chars (Arg1) = No_Name)
11360 Check_Arg_Is_One_Of
11361 (Arg1, Name_Check, Name_Disable, Name_Ignore);
11363 -- Treat one argument Assertion_Policy as equivalent to:
11365 -- pragma Check_Policy (Assertion, policy)
11367 -- So rewrite pragma in that manner and link on to the chain
11368 -- of Check_Policy pragmas, marking the pragma as analyzed.
11370 Policy := Get_Pragma_Arg (Arg1);
11374 Chars => Name_Check_Policy,
11375 Pragma_Argument_Associations => New_List (
11376 Make_Pragma_Argument_Association (Loc,
11377 Expression => Make_Identifier (Loc, Name_Assertion)),
11379 Make_Pragma_Argument_Association (Loc,
11381 Make_Identifier (Sloc (Policy), Chars (Policy))))));
11384 -- Here if we have two or more arguments
11387 Check_At_Least_N_Arguments (1);
11390 -- Loop through arguments
11393 while Present (Arg) loop
11394 LocP := Sloc (Arg);
11396 -- Kind must be specified
11398 if Nkind (Arg) /= N_Pragma_Argument_Association
11399 or else Chars (Arg) = No_Name
11402 ("missing assertion kind for pragma%", Arg);
11405 -- Check Kind and Policy have allowed forms
11407 Kind := Chars (Arg);
11409 if not Is_Valid_Assertion_Kind (Kind) then
11411 ("invalid assertion kind for pragma%", Arg);
11414 Check_Arg_Is_One_Of
11415 (Arg, Name_Check, Name_Disable, Name_Ignore);
11417 -- We rewrite the Assertion_Policy pragma as a series of
11418 -- Check_Policy pragmas:
11420 -- Check_Policy (Kind, Policy);
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)))));
11434 -- Rewrite the Assertion_Policy pragma as null since we have
11435 -- now inserted all the equivalent Check pragmas.
11437 Rewrite (N, Make_Null_Statement (Loc));
11440 end Assertion_Policy;
11442 ------------------------------
11443 -- Assume_No_Invalid_Values --
11444 ------------------------------
11446 -- pragma Assume_No_Invalid_Values (On | Off);
11448 when Pragma_Assume_No_Invalid_Values =>
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);
11455 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11456 Assume_No_Invalid_Values := True;
11458 Assume_No_Invalid_Values := False;
11461 --------------------------
11462 -- Attribute_Definition --
11463 --------------------------
11465 -- pragma Attribute_Definition
11466 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11467 -- [Entity =>] LOCAL_NAME,
11468 -- [Expression =>] EXPRESSION | NAME);
11470 when Pragma_Attribute_Definition => Attribute_Definition : declare
11471 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
11476 Check_Arg_Count (3);
11477 Check_Optional_Identifier (Arg1, "attribute");
11478 Check_Optional_Identifier (Arg2, "entity");
11479 Check_Optional_Identifier (Arg3, "expression");
11481 if Nkind (Attribute_Designator) /= N_Identifier then
11482 Error_Msg_N ("attribute name expected", Attribute_Designator);
11486 Check_Arg_Is_Local_Name (Arg2);
11488 -- If the attribute is not recognized, then issue a warning (not
11489 -- an error), and ignore the pragma.
11491 Aname := Chars (Attribute_Designator);
11493 if not Is_Attribute_Name (Aname) then
11494 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
11498 -- Otherwise, rewrite the pragma as an attribute definition clause
11501 Make_Attribute_Definition_Clause (Loc,
11502 Name => Get_Pragma_Arg (Arg2),
11504 Expression => Get_Pragma_Arg (Arg3)));
11506 end Attribute_Definition;
11512 -- pragma AST_Entry (entry_IDENTIFIER);
11514 when Pragma_AST_Entry => AST_Entry : declare
11520 Check_Arg_Count (1);
11521 Check_No_Identifiers;
11522 Check_Arg_Is_Local_Name (Arg1);
11523 Ent := Entity (Get_Pragma_Arg (Arg1));
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.
11530 if Ekind (Ent) /= E_Entry then
11532 ("pragma% argument must be simple entry name", Arg1);
11534 elsif Is_AST_Entry (Ent) then
11536 ("duplicate % pragma for entry", Arg1);
11538 elsif Has_Homonym (Ent) then
11540 ("pragma% argument cannot specify overloaded entry", Arg1);
11544 FF : constant Entity_Id := First_Formal (Ent);
11547 if Present (FF) then
11548 if Present (Next_Formal (FF)) then
11550 ("entry for pragma% can have only one argument",
11553 elsif Parameter_Mode (FF) /= E_In_Parameter then
11555 ("entry parameter for pragma% must have mode IN",
11561 Set_Is_AST_Entry (Ent);
11565 ------------------------------------------------------------------
11566 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11567 ------------------------------------------------------------------
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] );
11574 -- FLAG ::= boolean_EXPRESSION
11576 when Pragma_Async_Readers |
11577 Pragma_Async_Writers |
11578 Pragma_Effective_Reads |
11579 Pragma_Effective_Writes =>
11580 Async_Effective : declare
11584 Obj_Id : Entity_Id;
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;
11594 Obj := Get_Pragma_Arg (Arg1);
11595 Expr := Get_Pragma_Arg (Arg2);
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.
11601 if Is_Entity_Name (Obj)
11602 and then Present (Entity (Obj))
11603 and then Ekind (Entity (Obj)) = E_Variable
11605 Obj_Id := Entity (Obj);
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.
11613 Duplic := Get_Pragma (Obj_Id, Prag_Id);
11615 if Present (Duplic) then
11616 Error_Msg_Sloc := Sloc (Duplic);
11617 Error_Msg_N ("pragma % duplicates pragma declared #", N);
11619 -- No duplicate detected
11622 if Present (Expr) then
11623 Preanalyze_And_Resolve (Expr, Standard_Boolean);
11626 -- Chain the pragma on the contract for further processing
11628 Add_Contract_Item (N, Obj_Id);
11631 Error_Pragma ("pragma % must apply to a volatile object");
11633 end Async_Effective;
11639 -- pragma Asynchronous (LOCAL_NAME);
11641 when Pragma_Asynchronous => Asynchronous : declare
11647 Formal : Entity_Id;
11649 procedure Process_Async_Pragma;
11650 -- Common processing for procedure and access-to-procedure case
11652 --------------------------
11653 -- Process_Async_Pragma --
11654 --------------------------
11656 procedure Process_Async_Pragma is
11659 Set_Is_Asynchronous (Nm);
11663 -- The formals should be of mode IN (RM E.4.1(6))
11666 while Present (S) loop
11667 Formal := Defining_Identifier (S);
11669 if Nkind (Formal) = N_Defining_Identifier
11670 and then Ekind (Formal) /= E_In_Parameter
11673 ("pragma% procedure can only have IN parameter",
11680 Set_Is_Asynchronous (Nm);
11681 end Process_Async_Pragma;
11683 -- Start of processing for pragma Asynchronous
11686 Check_Ada_83_Warning;
11687 Check_No_Identifiers;
11688 Check_Arg_Count (1);
11689 Check_Arg_Is_Local_Name (Arg1);
11691 if Debug_Flag_U then
11695 C_Ent := Cunit_Entity (Current_Sem_Unit);
11696 Analyze (Get_Pragma_Arg (Arg1));
11697 Nm := Entity (Get_Pragma_Arg (Arg1));
11699 if not Is_Remote_Call_Interface (C_Ent)
11700 and then not Is_Remote_Types (C_Ent)
11702 -- This pragma should only appear in an RCI or Remote Types
11703 -- unit (RM E.4.1(4)).
11706 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11709 if Ekind (Nm) = E_Procedure
11710 and then Nkind (Parent (Nm)) = N_Procedure_Specification
11712 if not Is_Remote_Call_Interface (Nm) then
11714 ("pragma% cannot be applied on non-remote procedure",
11718 L := Parameter_Specifications (Parent (Nm));
11719 Process_Async_Pragma;
11722 elsif Ekind (Nm) = E_Function then
11724 ("pragma% cannot be applied to function", Arg1);
11726 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
11727 if Is_Record_Type (Nm) then
11729 -- A record type that is the Equivalent_Type for a remote
11730 -- access-to-subprogram type.
11732 N := Declaration_Node (Corresponding_Remote_Type (Nm));
11735 -- A non-expanded RAS type (distribution is not enabled)
11737 N := Declaration_Node (Nm);
11740 if Nkind (N) = N_Full_Type_Declaration
11741 and then Nkind (Type_Definition (N)) =
11742 N_Access_Procedure_Definition
11744 L := Parameter_Specifications (Type_Definition (N));
11745 Process_Async_Pragma;
11747 if Is_Asynchronous (Nm)
11748 and then Expander_Active
11749 and then Get_PCS_Name /= Name_No_DSA
11751 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
11756 ("pragma% cannot reference access-to-function type",
11760 -- Only other possibility is Access-to-class-wide type
11762 elsif Is_Access_Type (Nm)
11763 and then Is_Class_Wide_Type (Designated_Type (Nm))
11765 Check_First_Subtype (Arg1);
11766 Set_Is_Asynchronous (Nm);
11767 if Expander_Active then
11768 RACW_Type_Is_Asynchronous (Nm);
11772 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
11780 -- pragma Atomic (LOCAL_NAME);
11782 when Pragma_Atomic =>
11783 Process_Atomic_Shared_Volatile;
11785 -----------------------
11786 -- Atomic_Components --
11787 -----------------------
11789 -- pragma Atomic_Components (array_LOCAL_NAME);
11791 -- This processing is shared by Volatile_Components
11793 when Pragma_Atomic_Components |
11794 Pragma_Volatile_Components =>
11796 Atomic_Components : declare
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);
11809 if Etype (E_Id) = Any_Type then
11813 E := Entity (E_Id);
11815 Check_Duplicate_Pragma (E);
11817 if Rep_Item_Too_Early (E, N)
11819 Rep_Item_Too_Late (E, N)
11824 D := Declaration_Node (E);
11827 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
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)
11834 -- The flag is set on the object, or on the base type
11836 if Nkind (D) /= N_Object_Declaration then
11837 E := Base_Type (E);
11840 Set_Has_Volatile_Components (E);
11842 if Prag_Id = Pragma_Atomic_Components then
11843 Set_Has_Atomic_Components (E);
11847 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
11849 end Atomic_Components;
11851 --------------------
11852 -- Attach_Handler --
11853 --------------------
11855 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11857 when Pragma_Attach_Handler =>
11858 Check_Ada_83_Warning;
11859 Check_No_Identifiers;
11860 Check_Arg_Count (2);
11862 if No_Run_Time_Mode then
11863 Error_Msg_CRT ("Attach_Handler pragma", N);
11865 Check_Interrupt_Or_Attach_Handler;
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.
11875 Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2);
11878 -- In Relaxed_RM_Semantics mode, we allow any static
11879 -- integer value, for compatibility with other compilers.
11881 if Relaxed_RM_Semantics
11882 and then Nkind (Parg2) = N_Integer_Literal
11884 Typ := Standard_Integer;
11886 Typ := RTE (RE_Interrupt_ID);
11889 if Expander_Active then
11890 Temp := New_Copy_Tree (Parg2);
11891 Set_Parent (Temp, N);
11892 Preanalyze_And_Resolve (Temp, Typ);
11895 Resolve (Parg2, Typ);
11899 Process_Interrupt_Or_Attach_Handler;
11902 --------------------
11903 -- C_Pass_By_Copy --
11904 --------------------
11906 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11908 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
11914 Check_Valid_Configuration_Pragma;
11915 Check_Arg_Count (1);
11916 Check_Optional_Identifier (Arg1, "max_size");
11918 Arg := Get_Pragma_Arg (Arg1);
11919 Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer);
11921 Val := Expr_Value (Arg);
11925 ("maximum size for pragma% must be positive", Arg1);
11927 elsif UI_Is_In_Int_Range (Val) then
11928 Default_C_Record_Mechanism := UI_To_Int (Val);
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.
11935 Default_C_Record_Mechanism := Mechanism_Type'Last;
11937 end C_Pass_By_Copy;
11943 -- pragma Check ([Name =>] CHECK_KIND,
11944 -- [Check =>] Boolean_EXPRESSION
11945 -- [,[Message =>] String_EXPRESSION]);
11947 -- CHECK_KIND ::= IDENTIFIER |
11950 -- Invariant'Class |
11951 -- Type_Invariant'Class
11953 -- The identifiers Assertions and Statement_Assertions are not
11954 -- allowed, since they have special meaning for Check_Policy.
11956 when Pragma_Check => Check : declare
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);
11969 if Arg_Count = 3 then
11970 Check_Optional_Identifier (Arg3, Name_Message);
11971 Str := Get_Pragma_Arg (Arg3);
11974 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
11975 Check_Arg_Is_Identifier (Arg1);
11976 Cname := Chars (Get_Pragma_Arg (Arg1));
11978 -- Check forbidden name Assertions or Statement_Assertions
11981 when Name_Assertions =>
11983 ("""Assertions"" is not allowed as a check kind "
11984 & "for pragma%", Arg1);
11986 when Name_Statement_Assertions =>
11988 ("""Statement_Assertions"" is not allowed as a check kind "
11989 & "for pragma%", Arg1);
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).
11998 if Is_Checked (N) or else Is_Ignored (N) then
12001 -- For a non-source pragma that is a rewriting of another pragma,
12002 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12004 elsif Is_Rewrite_Substitution (N)
12005 and then Nkind (Original_Node (N)) = N_Pragma
12006 and then Original_Node (N) /= N
12008 Set_Is_Ignored (N, Is_Ignored (Original_Node (N)));
12009 Set_Is_Checked (N, Is_Checked (Original_Node (N)));
12011 -- Otherwise query the applicable policy at this point
12014 case Check_Kind (Cname) is
12015 when Name_Ignore =>
12016 Set_Is_Ignored (N, True);
12017 Set_Is_Checked (N, False);
12020 Set_Is_Ignored (N, False);
12021 Set_Is_Checked (N, True);
12023 -- For disable, rewrite pragma as null statement and skip
12024 -- rest of the analysis of the pragma.
12026 when Name_Disable =>
12027 Rewrite (N, Make_Null_Statement (Loc));
12031 -- No other possibilities
12034 raise Program_Error;
12038 -- If check kind was not Disable, then continue pragma analysis
12040 Expr := Get_Pragma_Arg (Arg2);
12042 -- Deal with SCO generation
12045 when Name_Predicate |
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.
12056 if Is_Checked (N) and then not Split_PPC (N) then
12058 -- Mark aspect/pragma SCO as enabled
12060 Set_SCO_Pragma_Enabled (Loc);
12064 -- Deal with analyzing the string argument.
12066 if Arg_Count = 3 then
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
12073 if Is_Ignored (N) then
12074 Preanalyze_And_Resolve (Str, Standard_String);
12076 -- Otherwise we need a proper analysis and expansion
12079 Analyze_And_Resolve (Str, Standard_String);
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.
12089 -- So instead we wrap the boolean expression in an if statement
12090 -- that looks like:
12092 -- if False and then condition then
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.
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.
12108 if Expander_Active and Is_Ignored (N) then
12109 Eloc := Sloc (Expr);
12112 Make_If_Statement (Eloc,
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))));
12120 In_Assertion_Expr := In_Assertion_Expr + 1;
12122 In_Assertion_Expr := In_Assertion_Expr - 1;
12124 -- Check is active or expansion not active. In these cases we can
12125 -- just go ahead and analyze the boolean with no worries.
12128 In_Assertion_Expr := In_Assertion_Expr + 1;
12129 Analyze_And_Resolve (Expr, Any_Boolean);
12130 In_Assertion_Expr := In_Assertion_Expr - 1;
12134 --------------------------
12135 -- Check_Float_Overflow --
12136 --------------------------
12138 -- pragma Check_Float_Overflow;
12140 when Pragma_Check_Float_Overflow =>
12142 Check_Valid_Configuration_Pragma;
12143 Check_Arg_Count (0);
12144 Check_Float_Overflow := True;
12150 -- pragma Check_Name (check_IDENTIFIER);
12152 when Pragma_Check_Name =>
12154 Check_No_Identifiers;
12155 Check_Valid_Configuration_Pragma;
12156 Check_Arg_Count (1);
12157 Check_Arg_Is_Identifier (Arg1);
12160 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
12163 for J in Check_Names.First .. Check_Names.Last loop
12164 if Check_Names.Table (J) = Nam then
12169 Check_Names.Append (Nam);
12176 -- This is the old style syntax, which is still allowed in all modes:
12178 -- pragma Check_Policy ([Name =>] CHECK_KIND
12179 -- [Policy =>] POLICY_IDENTIFIER);
12181 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12183 -- CHECK_KIND ::= IDENTIFIER |
12186 -- Type_Invariant'Class |
12189 -- This is the new style syntax, compatible with Assertion_Policy
12190 -- and also allowed in all modes.
12192 -- Pragma Check_Policy (
12193 -- CHECK_KIND => POLICY_IDENTIFIER
12194 -- {, CHECK_KIND => POLICY_IDENTIFIER});
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.
12200 when Pragma_Check_Policy => Check_Policy : declare
12205 Check_At_Least_N_Arguments (1);
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).
12212 if not Is_Configuration_Pragma then
12213 Check_Is_In_Decl_Part_Or_Package_Spec;
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.
12220 if Nkind (Arg1) /= N_Pragma_Argument_Association
12221 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
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);
12231 -- Check forbidden check kind
12233 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
12234 Error_Msg_Name_2 := Chars (Kind);
12236 ("pragma% does not allow% as check name", Arg1);
12241 Check_Optional_Identifier (Arg2, Name_Policy);
12242 Check_Arg_Is_One_Of
12244 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
12246 -- And chain pragma on the Check_Policy_List for search
12248 Set_Next_Pragma (N, Opt.Check_Policy_List);
12249 Opt.Check_Policy_List := N;
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).
12264 while Present (Arg) loop
12265 LocP := Sloc (Arg);
12266 Argx := Get_Pragma_Arg (Arg);
12268 -- Kind must be specified
12270 if Nkind (Arg) /= N_Pragma_Argument_Association
12271 or else Chars (Arg) = No_Name
12274 ("missing assertion kind for pragma%", Arg);
12277 -- Construct equivalent old form syntax Check_Policy
12278 -- pragma and insert it to get remaining checks.
12282 Chars => Name_Check_Policy,
12283 Pragma_Argument_Associations => New_List (
12284 Make_Pragma_Argument_Association (LocP,
12286 Make_Identifier (LocP, Chars (Arg))),
12287 Make_Pragma_Argument_Association (Sloc (Argx),
12288 Expression => Argx))));
12293 -- Rewrite original Check_Policy pragma to null, since we
12294 -- have converted it into a series of old syntax pragmas.
12296 Rewrite (N, Make_Null_Statement (Loc));
12302 ---------------------
12303 -- CIL_Constructor --
12304 ---------------------
12306 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
12308 -- Processing for this pragma is shared with Java_Constructor
12314 -- pragma Comment (static_string_EXPRESSION)
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.
12322 -------------------
12323 -- Common_Object --
12324 -------------------
12326 -- pragma Common_Object (
12327 -- [Internal =>] LOCAL_NAME
12328 -- [, [External =>] EXTERNAL_SYMBOL]
12329 -- [, [Size =>] EXTERNAL_SYMBOL]);
12331 -- Processing for this pragma is shared with Psect_Object
12333 ------------------------
12334 -- Compile_Time_Error --
12335 ------------------------
12337 -- pragma Compile_Time_Error
12338 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12340 when Pragma_Compile_Time_Error =>
12342 Process_Compile_Time_Warning_Or_Error;
12344 --------------------------
12345 -- Compile_Time_Warning --
12346 --------------------------
12348 -- pragma Compile_Time_Warning
12349 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12351 when Pragma_Compile_Time_Warning =>
12353 Process_Compile_Time_Warning_Or_Error;
12355 ---------------------------
12356 -- Compiler_Unit_Warning --
12357 ---------------------------
12359 -- pragma Compiler_Unit_Warning;
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.
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
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.
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?
12387 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning =>
12389 Check_Arg_Count (0);
12391 -- Only recognized in main unit
12393 if Current_Sem_Unit = Main_Unit then
12394 Compiler_Unit := True;
12397 -----------------------------
12398 -- Complete_Representation --
12399 -----------------------------
12401 -- pragma Complete_Representation;
12403 when Pragma_Complete_Representation =>
12405 Check_Arg_Count (0);
12407 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
12409 ("pragma & must appear within record representation clause");
12412 ----------------------------
12413 -- Complex_Representation --
12414 ----------------------------
12416 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12418 when Pragma_Complex_Representation => Complex_Representation : declare
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);
12430 if Etype (E_Id) = Any_Type then
12434 E := Entity (E_Id);
12436 if not Is_Record_Type (E) then
12438 ("argument for pragma% must be record type", Arg1);
12441 Ent := First_Entity (E);
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))
12450 ("record for pragma% must have two fields of the same "
12451 & "floating-point type", Arg1);
12454 Set_Has_Complex_Representation (Base_Type (E));
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.
12461 Set_Has_Non_Standard_Rep (Base_Type (E));
12463 end Complex_Representation;
12465 -------------------------
12466 -- Component_Alignment --
12467 -------------------------
12469 -- pragma Component_Alignment (
12470 -- [Form =>] ALIGNMENT_CHOICE
12471 -- [, [Name =>] type_LOCAL_NAME]);
12473 -- ALIGNMENT_CHOICE ::=
12475 -- | Component_Size_4
12479 when Pragma_Component_Alignment => Component_AlignmentP : declare
12480 Args : Args_List (1 .. 2);
12481 Names : constant Name_List (1 .. 2) := (
12485 Form : Node_Id renames Args (1);
12486 Name : Node_Id renames Args (2);
12488 Atype : Component_Alignment_Kind;
12493 Gather_Associations (Names, Args);
12496 Error_Pragma ("missing Form argument for pragma%");
12499 Check_Arg_Is_Identifier (Form);
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)
12507 if Chars (Form) = Name_Component_Size then
12508 Atype := Calign_Component_Size;
12510 elsif Chars (Form) = Name_Component_Size_4 then
12511 Atype := Calign_Component_Size_4;
12513 elsif Chars (Form) = Name_Default then
12514 Atype := Calign_Component_Size;
12516 elsif Chars (Form) = Name_Storage_Unit then
12517 Atype := Calign_Storage_Unit;
12521 ("invalid Form parameter for pragma%", Form);
12524 -- Case with no name, supplied, affects scope table entry
12528 (Scope_Stack.Last).Component_Alignment_Default := Atype;
12530 -- Case of name supplied
12533 Check_Arg_Is_Local_Name (Name);
12535 Typ := Entity (Name);
12538 or else Rep_Item_Too_Early (Typ, N)
12542 Typ := Underlying_Type (Typ);
12545 if not Is_Record_Type (Typ)
12546 and then not Is_Array_Type (Typ)
12549 ("Name parameter of pragma% must identify record or "
12550 & "array type", Name);
12553 -- An explicit Component_Alignment pragma overrides an
12554 -- implicit pragma Pack, but not an explicit one.
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);
12561 end Component_AlignmentP;
12563 --------------------
12564 -- Contract_Cases --
12565 --------------------
12567 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12569 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12571 -- CASE_GUARD ::= boolean_EXPRESSION | others
12573 -- CONSEQUENCE ::= boolean_EXPRESSION
12575 when Pragma_Contract_Cases => Contract_Cases : declare
12576 Subp_Decl : Node_Id;
12580 Check_Arg_Count (1);
12581 Ensure_Aggregate_Form (Arg1);
12583 -- The pragma is analyzed at the end of the declarative part which
12584 -- contains the related subprogram. Reset the analyzed flag.
12586 Set_Analyzed (N, False);
12588 -- Ensure the proper placement of the pragma. Contract_Cases must
12589 -- be associated with a subprogram declaration or a body that acts
12593 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
12595 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
12598 -- Body acts as spec
12600 elsif Nkind (Subp_Decl) = N_Subprogram_Body
12601 and then No (Corresponding_Spec (Subp_Decl))
12605 -- Body stub acts as spec
12607 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
12608 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
12617 -- When the pragma appears on a subprogram body, perform the full
12620 if Nkind (Subp_Decl) = N_Subprogram_Body then
12621 Analyze_Contract_Cases_In_Decl_Part (N);
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.
12627 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
12628 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
12630 Analyze_Contract_Cases_In_Decl_Part (N);
12633 -- Chain the pragma on the contract for further processing
12635 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
12636 end Contract_Cases;
12642 -- pragma Controlled (first_subtype_LOCAL_NAME);
12644 when Pragma_Controlled => Controlled : declare
12648 Check_No_Identifiers;
12649 Check_Arg_Count (1);
12650 Check_Arg_Is_Local_Name (Arg1);
12651 Arg := Get_Pragma_Arg (Arg1);
12653 if not Is_Entity_Name (Arg)
12654 or else not Is_Access_Type (Entity (Arg))
12656 Error_Pragma_Arg ("pragma% requires access type", Arg1);
12658 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
12666 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12667 -- [Entity =>] LOCAL_NAME);
12669 when Pragma_Convention => Convention : declare
12672 pragma Warnings (Off, C);
12673 pragma Warnings (Off, E);
12675 Check_Arg_Order ((Name_Convention, Name_Entity));
12676 Check_Ada_83_Warning;
12677 Check_Arg_Count (2);
12678 Process_Convention (C, E);
12681 ---------------------------
12682 -- Convention_Identifier --
12683 ---------------------------
12685 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12686 -- [Convention =>] convention_IDENTIFIER);
12688 when Pragma_Convention_Identifier => Convention_Identifier : declare
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));
12703 if Is_Convention_Name (Cname) then
12704 Record_Convention_Identifier
12705 (Idnam, Get_Convention_Id (Cname));
12708 ("second arg for % pragma must be convention", Arg2);
12710 end Convention_Identifier;
12716 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12718 when Pragma_CPP_Class => CPP_Class : declare
12722 if Warn_On_Obsolescent_Feature then
12724 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12725 & "effect; replace it by pragma import?j?", N);
12728 Check_Arg_Count (1);
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))))));
12740 ---------------------
12741 -- CPP_Constructor --
12742 ---------------------
12744 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12745 -- [, [External_Name =>] static_string_EXPRESSION ]
12746 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12748 when Pragma_CPP_Constructor => CPP_Constructor : declare
12751 Def_Id : Entity_Id;
12752 Tag_Typ : Entity_Id;
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);
12761 Id := Get_Pragma_Arg (Arg1);
12762 Find_Program_Unit_Name (Id);
12764 -- If we did not find the name, we are done
12766 if Etype (Id) = Any_Type then
12770 Def_Id := Entity (Id);
12772 -- Check if already defined as constructor
12774 if Is_Constructor (Def_Id) then
12776 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
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))
12784 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
12786 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
12788 ("'C'P'P constructor must be defined in the scope of "
12789 & "its returned type", Arg1);
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);
12798 Set_Has_Completion (Def_Id);
12799 Set_Is_Constructor (Def_Id);
12800 Set_Convention (Def_Id, Convention_CPP);
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.
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)
12814 Tag_Typ := Etype (Def_Id);
12816 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
12817 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
12821 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
12822 Set_Is_Dispatching_Operation (Def_Id, False);
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.
12829 if Is_Class_Wide_Type (Etype (Def_Id)) then
12830 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
12834 ("pragma% requires function returning a 'C'P'P_Class type",
12837 end CPP_Constructor;
12843 when Pragma_CPP_Virtual => CPP_Virtual : declare
12847 if Warn_On_Obsolescent_Feature then
12849 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12858 when Pragma_CPP_Vtable => CPP_Vtable : declare
12862 if Warn_On_Obsolescent_Feature then
12864 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12873 -- pragma CPU (EXPRESSION);
12875 when Pragma_CPU => CPU : declare
12876 P : constant Node_Id := Parent (N);
12882 Check_No_Identifiers;
12883 Check_Arg_Count (1);
12887 if Nkind (P) = N_Subprogram_Body then
12888 Check_In_Main_Program;
12890 Arg := Get_Pragma_Arg (Arg1);
12891 Analyze_And_Resolve (Arg, Any_Integer);
12893 Ent := Defining_Unit_Name (Specification (P));
12895 if Nkind (Ent) = N_Defining_Program_Unit_Name then
12896 Ent := Defining_Identifier (Ent);
12901 if not Is_OK_Static_Expression (Arg) then
12902 Flag_Non_Static_Expr
12903 ("main subprogram affinity is not static!", Arg);
12906 -- If constraint error, then we already signalled an error
12908 elsif Raises_Constraint_Error (Arg) then
12911 -- Otherwise check in range
12915 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
12916 -- This is the entity System.Multiprocessors.CPU_Range;
12918 Val : constant Uint := Expr_Value (Arg);
12921 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
12923 Val > Expr_Value (Type_High_Bound (CPU_Id))
12926 ("main subprogram CPU is out of range", Arg1);
12932 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12936 elsif Nkind (P) = N_Task_Definition then
12937 Arg := Get_Pragma_Arg (Arg1);
12938 Ent := Defining_Identifier (Parent (P));
12940 -- The expression must be analyzed in the special manner
12941 -- described in "Handling of Default and Per-Object
12942 -- Expressions" in sem.ads.
12944 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
12946 -- Anything else is incorrect
12952 -- Check duplicate pragma before we chain the pragma in the Rep
12953 -- Item chain of Ent.
12955 Check_Duplicate_Pragma (Ent);
12956 Record_Rep_Item (Ent, N);
12963 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12965 when Pragma_Debug => Debug : declare
12972 -- The condition for executing the call is that the expander
12973 -- is active and that we are not ignoring this debug pragma.
12978 (Expander_Active and then not Is_Ignored (N)),
12981 if not Is_Ignored (N) then
12982 Set_SCO_Pragma_Enabled (Loc);
12985 if Arg_Count = 2 then
12987 Make_And_Then (Loc,
12988 Left_Opnd => Relocate_Node (Cond),
12989 Right_Opnd => Get_Pragma_Arg (Arg1));
12990 Call := Get_Pragma_Arg (Arg2);
12992 Call := Get_Pragma_Arg (Arg1);
12996 N_Indexed_Component,
13000 N_Selected_Component)
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.
13008 Change_Name_To_Procedure_Call_Statement (Call);
13010 elsif Nkind (Call) = N_Procedure_Call_Statement then
13012 -- Already in the form of a procedure call statement: nothing
13013 -- to do (could happen in case of an internally generated
13019 -- All other cases: diagnose error
13022 ("argument of pragma ""Debug"" is not procedure call",
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.
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
13039 if Nkind (Call) = N_Procedure_Call_Statement
13040 and then Is_Entity_Name (Name (Call))
13042 Analyze (Name (Call));
13043 Freeze_Before (N, Entity (Name (Call)));
13047 Make_Implicit_If_Statement (N,
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)))))));
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.
13061 if GNATprove_Mode then
13062 Rewrite (N, Make_Null_Statement (Loc));
13070 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13072 when Pragma_Debug_Policy =>
13074 Check_Arg_Count (1);
13075 Check_No_Identifiers;
13076 Check_Arg_Is_Identifier (Arg1);
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.
13084 Chars => Name_Check_Policy,
13085 Pragma_Argument_Associations => New_List (
13086 Make_Pragma_Argument_Association (Loc,
13087 Expression => Make_Identifier (Loc, Name_Debug)),
13089 Make_Pragma_Argument_Association (Loc,
13090 Expression => Get_Pragma_Arg (Arg1)))));
13097 -- pragma Depends (DEPENDENCY_RELATION);
13099 -- DEPENDENCY_RELATION ::=
13101 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
13103 -- DEPENDENCY_CLAUSE ::=
13104 -- OUTPUT_LIST =>[+] INPUT_LIST
13105 -- | NULL_DEPENDENCY_CLAUSE
13107 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13109 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13111 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13113 -- OUTPUT ::= NAME | FUNCTION_RESULT
13116 -- where FUNCTION_RESULT is a function Result attribute_reference
13118 when Pragma_Depends => Depends : declare
13119 Subp_Decl : Node_Id;
13123 Check_Arg_Count (1);
13124 Ensure_Aggregate_Form (Arg1);
13126 -- Ensure the proper placement of the pragma. Depends must be
13127 -- associated with a subprogram declaration or a body that acts
13131 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
13133 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
13136 -- Body acts as spec
13138 elsif Nkind (Subp_Decl) = N_Subprogram_Body
13139 and then No (Corresponding_Spec (Subp_Decl))
13143 -- Body stub acts as spec
13145 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
13146 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
13155 -- When the pragma appears on a subprogram body, perform the full
13158 if Nkind (Subp_Decl) = N_Subprogram_Body then
13159 Analyze_Depends_In_Decl_Part (N);
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.
13165 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
13166 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
13168 Analyze_Depends_In_Decl_Part (N);
13171 -- Chain the pragma on the contract for further processing
13173 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
13176 ---------------------
13177 -- Detect_Blocking --
13178 ---------------------
13180 -- pragma Detect_Blocking;
13182 when Pragma_Detect_Blocking =>
13184 Check_Arg_Count (0);
13185 Check_Valid_Configuration_Pragma;
13186 Detect_Blocking := True;
13188 ----------------------------------
13189 -- Default_Scalar_Storage_Order --
13190 ----------------------------------
13192 -- pragma Default_Scalar_Storage_Order
13193 -- (High_Order_First | Low_Order_First);
13195 when Pragma_Default_Scalar_Storage_Order => DSSO : declare
13196 Default : Character;
13200 Check_Arg_Count (1);
13202 -- Default_Scalar_Storage_Order can appear as a configuration
13203 -- pragma, or in a declarative part of a package spec.
13205 if not Is_Configuration_Pragma then
13206 Check_Is_In_Decl_Part_Or_Package_Spec;
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));
13215 if not Support_Nondefault_SSO_On_Target
13216 and then (Ttypes.Bytes_Big_Endian /= (Default = 'H'))
13218 if Warn_On_Unrecognized_Pragma then
13220 ("non-default Scalar_Storage_Order not supported "
13221 & "on target?g?", N);
13223 ("\pragma Default_Scalar_Storage_Order ignored?g?", N);
13226 -- Here set the specified default
13229 Opt.Default_SSO := Default;
13233 --------------------------
13234 -- Default_Storage_Pool --
13235 --------------------------
13237 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13239 when Pragma_Default_Storage_Pool =>
13241 Check_Arg_Count (1);
13243 -- Default_Storage_Pool can appear as a configuration pragma, or
13244 -- in a declarative part of a package spec.
13246 if not Is_Configuration_Pragma then
13247 Check_Is_In_Decl_Part_Or_Package_Spec;
13250 -- Case of Default_Storage_Pool (null);
13252 if Nkind (Expression (Arg1)) = N_Null then
13253 Analyze (Expression (Arg1));
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.
13258 Set_Etype (Expression (Arg1), Empty);
13260 -- Case of Default_Storage_Pool (storage_pool_NAME);
13263 -- If it's a configuration pragma, then the only allowed
13264 -- argument is "null".
13266 if Is_Configuration_Pragma then
13267 Error_Pragma_Arg ("NULL expected", Arg1);
13270 -- The expected type for a non-"null" argument is
13271 -- Root_Storage_Pool'Class.
13273 Analyze_And_Resolve
13274 (Get_Pragma_Arg (Arg1),
13275 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
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.
13282 Default_Pool := Expression (Arg1);
13284 ------------------------------------
13285 -- Disable_Atomic_Synchronization --
13286 ------------------------------------
13288 -- pragma Disable_Atomic_Synchronization [(Entity)];
13290 when Pragma_Disable_Atomic_Synchronization =>
13292 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
13294 -------------------
13295 -- Discard_Names --
13296 -------------------
13298 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13300 when Pragma_Discard_Names => Discard_Names : declare
13305 Check_Ada_83_Warning;
13307 -- Deal with configuration pragma case
13309 if Arg_Count = 0 and then Is_Configuration_Pragma then
13310 Global_Discard_Names := True;
13313 -- Otherwise, check correct appropriate context
13316 Check_Is_In_Decl_Part_Or_Package_Spec;
13318 if Arg_Count = 0 then
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.
13325 Set_Discard_Names (Current_Scope);
13329 Check_Arg_Count (1);
13330 Check_Optional_Identifier (Arg1, Name_On);
13331 Check_Arg_Is_Local_Name (Arg1);
13333 E_Id := Get_Pragma_Arg (Arg1);
13335 if Etype (E_Id) = Any_Type then
13338 E := Entity (E_Id);
13341 if (Is_First_Subtype (E)
13343 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
13344 or else Ekind (E) = E_Exception
13346 Set_Discard_Names (E);
13347 Record_Rep_Item (E, N);
13351 ("inappropriate entity for pragma%", Arg1);
13358 ------------------------
13359 -- Dispatching_Domain --
13360 ------------------------
13362 -- pragma Dispatching_Domain (EXPRESSION);
13364 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
13365 P : constant Node_Id := Parent (N);
13371 Check_No_Identifiers;
13372 Check_Arg_Count (1);
13374 -- This pragma is born obsolete, but not the aspect
13376 if not From_Aspect_Specification (N) then
13378 (No_Obsolescent_Features, Pragma_Identifier (N));
13381 if Nkind (P) = N_Task_Definition then
13382 Arg := Get_Pragma_Arg (Arg1);
13383 Ent := Defining_Identifier (Parent (P));
13385 -- The expression must be analyzed in the special manner
13386 -- described in "Handling of Default and Per-Object
13387 -- Expressions" in sem.ads.
13389 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
13391 -- Check duplicate pragma before we chain the pragma in the Rep
13392 -- Item chain of Ent.
13394 Check_Duplicate_Pragma (Ent);
13395 Record_Rep_Item (Ent, N);
13397 -- Anything else is incorrect
13402 end Dispatching_Domain;
13408 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13410 when Pragma_Elaborate => Elaborate : declare
13415 -- Pragma must be in context items list of a compilation unit
13417 if not Is_In_Context_Clause then
13421 -- Must be at least one argument
13423 if Arg_Count = 0 then
13424 Error_Pragma ("pragma% requires at least one argument");
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.
13432 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
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))
13442 ("(Ada 83) pragma% must be at end of context clause");
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
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))
13461 Set_Elaborate_Present (Citem, True);
13462 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13463 Generate_Reference (Entity (Name (Citem)), Citem);
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.
13473 if In_Extended_Main_Source_Unit (N) then
13474 Set_Suppress_Elaboration_Warnings
13475 (Entity (Name (Citem)));
13486 ("argument of pragma% is not withed unit", Arg);
13492 -- Give a warning if operating in static mode with one of the
13493 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
13495 if Elab_Warnings and not Dynamic_Elaboration_Checks then
13497 ("?l?use of pragma Elaborate may not be safe", N);
13499 ("?l?use pragma Elaborate_All instead if possible", N);
13503 -------------------
13504 -- Elaborate_All --
13505 -------------------
13507 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
13509 when Pragma_Elaborate_All => Elaborate_All : declare
13514 Check_Ada_83_Warning;
13516 -- Pragma must be in context items list of a compilation unit
13518 if not Is_In_Context_Clause then
13522 -- Must be at least one argument
13524 if Arg_Count = 0 then
13525 Error_Pragma ("pragma% requires at least one argument");
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.
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.
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))
13544 Set_Elaborate_All_Present (Citem, True);
13545 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
13547 -- Suppress warnings and elaboration checks on the named
13548 -- unit if the pragma is in the current compilation, as
13549 -- for pragma Elaborate.
13551 if In_Extended_Main_Source_Unit (N) then
13552 Set_Suppress_Elaboration_Warnings
13553 (Entity (Name (Citem)));
13562 Set_Error_Posted (N);
13564 ("argument of pragma% is not withed unit", Arg);
13571 --------------------
13572 -- Elaborate_Body --
13573 --------------------
13575 -- pragma Elaborate_Body [( library_unit_NAME )];
13577 when Pragma_Elaborate_Body => Elaborate_Body : declare
13578 Cunit_Node : Node_Id;
13579 Cunit_Ent : Entity_Id;
13582 Check_Ada_83_Warning;
13583 Check_Valid_Library_Unit_Pragma;
13585 if Nkind (N) = N_Null_Statement then
13589 Cunit_Node := Cunit (Current_Sem_Unit);
13590 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
13592 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
13595 Error_Pragma ("pragma% must refer to a spec, not a body");
13597 Set_Body_Required (Cunit_Node, True);
13598 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
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).
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.
13612 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13613 -- Elaborate_Body always suppressed elab warnings.
13615 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
13616 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
13619 end Elaborate_Body;
13621 ------------------------
13622 -- Elaboration_Checks --
13623 ------------------------
13625 -- pragma Elaboration_Checks (Static | Dynamic);
13627 when Pragma_Elaboration_Checks =>
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);
13638 -- pragma Eliminate (
13639 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13640 -- [,[Entity =>] IDENTIFIER |
13641 -- SELECTED_COMPONENT |
13643 -- [, OVERLOADING_RESOLUTION]);
13645 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13648 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13649 -- FUNCTION_PROFILE
13651 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13653 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13654 -- Result_Type => result_SUBTYPE_NAME]
13656 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13657 -- SUBTYPE_NAME ::= STRING_LITERAL
13659 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13660 -- SOURCE_TRACE ::= STRING_LITERAL
13662 when Pragma_Eliminate => Eliminate : declare
13663 Args : Args_List (1 .. 5);
13664 Names : constant Name_List (1 .. 5) := (
13667 Name_Parameter_Types,
13669 Name_Source_Location);
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);
13679 Check_Valid_Configuration_Pragma;
13680 Gather_Associations (Names, Args);
13682 if No (Unit_Name) then
13683 Error_Pragma ("missing Unit_Name argument for pragma%");
13687 and then (Present (Parameter_Types)
13689 Present (Result_Type)
13691 Present (Source_Location))
13693 Error_Pragma ("missing Entity argument for pragma%");
13696 if (Present (Parameter_Types)
13698 Present (Result_Type))
13700 Present (Source_Location)
13703 ("parameter profile and source location cannot be used "
13704 & "together in pragma%");
13707 Process_Eliminate_Pragma
13716 -----------------------------------
13717 -- Enable_Atomic_Synchronization --
13718 -----------------------------------
13720 -- pragma Enable_Atomic_Synchronization [(Entity)];
13722 when Pragma_Enable_Atomic_Synchronization =>
13724 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
13731 -- [ Convention =>] convention_IDENTIFIER,
13732 -- [ Entity =>] LOCAL_NAME
13733 -- [, [External_Name =>] static_string_EXPRESSION ]
13734 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13736 when Pragma_Export => Export : declare
13738 Def_Id : Entity_Id;
13740 pragma Warnings (Off, C);
13743 Check_Ada_83_Warning;
13747 Name_External_Name,
13750 Check_At_Least_N_Arguments (2);
13751 Check_At_Most_N_Arguments (4);
13753 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13754 -- pragma Export (Entity, "external name");
13756 if Relaxed_RM_Semantics
13757 and then Arg_Count = 2
13758 and then Nkind (Expression (Arg2)) = N_String_Literal
13761 Def_Id := Get_Pragma_Arg (Arg1);
13764 if not Is_Entity_Name (Def_Id) then
13765 Error_Pragma_Arg ("entity name required", Arg1);
13768 Def_Id := Entity (Def_Id);
13769 Set_Exported (Def_Id, Arg1);
13772 Process_Convention (C, Def_Id);
13774 if Ekind (Def_Id) /= E_Constant then
13775 Note_Possible_Modification
13776 (Get_Pragma_Arg (Arg2), Sure => False);
13779 Process_Interface_Name (Def_Id, Arg3, Arg4);
13780 Set_Exported (Def_Id, Arg2);
13783 -- If the entity is a deferred constant, propagate the information
13784 -- to the full view, because gigi elaborates the full view only.
13786 if Ekind (Def_Id) = E_Constant
13787 and then Present (Full_View (Def_Id))
13790 Id2 : constant Entity_Id := Full_View (Def_Id);
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));
13799 ----------------------
13800 -- Export_Exception --
13801 ----------------------
13803 -- pragma Export_Exception (
13804 -- [Internal =>] LOCAL_NAME
13805 -- [, [External =>] EXTERNAL_SYMBOL]
13806 -- [, [Form =>] Ada | VMS]
13807 -- [, [Code =>] static_integer_EXPRESSION]);
13809 when Pragma_Export_Exception => Export_Exception : declare
13810 Args : Args_List (1 .. 4);
13811 Names : constant Name_List (1 .. 4) := (
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);
13825 if Inside_A_Generic then
13826 Error_Pragma ("pragma% cannot be used for generic entities");
13829 Gather_Associations (Names, Args);
13830 Process_Extended_Import_Export_Exception_Pragma (
13831 Arg_Internal => Internal,
13832 Arg_External => External,
13836 if not Is_VMS_Exception (Entity (Internal)) then
13837 Set_Exported (Entity (Internal), Internal);
13839 end Export_Exception;
13841 ---------------------
13842 -- Export_Function --
13843 ---------------------
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]);
13853 -- EXTERNAL_SYMBOL ::=
13855 -- | static_string_EXPRESSION
13857 -- PARAMETER_TYPES ::=
13859 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13861 -- TYPE_DESIGNATOR ::=
13863 -- | subtype_Name ' Access
13867 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13869 -- MECHANISM_ASSOCIATION ::=
13870 -- [formal_parameter_NAME =>] MECHANISM_NAME
13872 -- MECHANISM_NAME ::=
13875 -- | Descriptor [([Class =>] CLASS_NAME)]
13877 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13879 when Pragma_Export_Function => Export_Function : declare
13880 Args : Args_List (1 .. 6);
13881 Names : constant Name_List (1 .. 6) := (
13884 Name_Parameter_Types,
13887 Name_Result_Mechanism);
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);
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;
13908 -------------------
13909 -- Export_Object --
13910 -------------------
13912 -- pragma Export_Object (
13913 -- [Internal =>] LOCAL_NAME
13914 -- [, [External =>] EXTERNAL_SYMBOL]
13915 -- [, [Size =>] EXTERNAL_SYMBOL]);
13917 -- EXTERNAL_SYMBOL ::=
13919 -- | static_string_EXPRESSION
13921 -- PARAMETER_TYPES ::=
13923 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13925 -- TYPE_DESIGNATOR ::=
13927 -- | subtype_Name ' Access
13931 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13933 -- MECHANISM_ASSOCIATION ::=
13934 -- [formal_parameter_NAME =>] MECHANISM_NAME
13936 -- MECHANISM_NAME ::=
13939 -- | Descriptor [([Class =>] CLASS_NAME)]
13941 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13943 when Pragma_Export_Object => Export_Object : declare
13944 Args : Args_List (1 .. 3);
13945 Names : constant Name_List (1 .. 3) := (
13950 Internal : Node_Id renames Args (1);
13951 External : Node_Id renames Args (2);
13952 Size : Node_Id renames Args (3);
13956 Gather_Associations (Names, Args);
13957 Process_Extended_Import_Export_Object_Pragma (
13958 Arg_Internal => Internal,
13959 Arg_External => External,
13963 ----------------------
13964 -- Export_Procedure --
13965 ----------------------
13967 -- pragma Export_Procedure (
13968 -- [Internal =>] LOCAL_NAME
13969 -- [, [External =>] EXTERNAL_SYMBOL]
13970 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13971 -- [, [Mechanism =>] MECHANISM]);
13973 -- EXTERNAL_SYMBOL ::=
13975 -- | static_string_EXPRESSION
13977 -- PARAMETER_TYPES ::=
13979 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13981 -- TYPE_DESIGNATOR ::=
13983 -- | subtype_Name ' Access
13987 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13989 -- MECHANISM_ASSOCIATION ::=
13990 -- [formal_parameter_NAME =>] MECHANISM_NAME
13992 -- MECHANISM_NAME ::=
13995 -- | Descriptor [([Class =>] CLASS_NAME)]
13997 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
13999 when Pragma_Export_Procedure => Export_Procedure : declare
14000 Args : Args_List (1 .. 4);
14001 Names : constant Name_List (1 .. 4) := (
14004 Name_Parameter_Types,
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);
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;
14026 -- pragma Export_Value (
14027 -- [Value =>] static_integer_EXPRESSION,
14028 -- [Link_Name =>] static_string_EXPRESSION);
14030 when Pragma_Export_Value =>
14032 Check_Arg_Order ((Name_Value, Name_Link_Name));
14033 Check_Arg_Count (2);
14035 Check_Optional_Identifier (Arg1, Name_Value);
14036 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
14038 Check_Optional_Identifier (Arg2, Name_Link_Name);
14039 Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String);
14041 -----------------------------
14042 -- Export_Valued_Procedure --
14043 -----------------------------
14045 -- pragma Export_Valued_Procedure (
14046 -- [Internal =>] LOCAL_NAME
14047 -- [, [External =>] EXTERNAL_SYMBOL,]
14048 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14049 -- [, [Mechanism =>] MECHANISM]);
14051 -- EXTERNAL_SYMBOL ::=
14053 -- | static_string_EXPRESSION
14055 -- PARAMETER_TYPES ::=
14057 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14059 -- TYPE_DESIGNATOR ::=
14061 -- | subtype_Name ' Access
14065 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14067 -- MECHANISM_ASSOCIATION ::=
14068 -- [formal_parameter_NAME =>] MECHANISM_NAME
14070 -- MECHANISM_NAME ::=
14073 -- | Descriptor [([Class =>] CLASS_NAME)]
14075 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
14077 when Pragma_Export_Valued_Procedure =>
14078 Export_Valued_Procedure : declare
14079 Args : Args_List (1 .. 4);
14080 Names : constant Name_List (1 .. 4) := (
14083 Name_Parameter_Types,
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);
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;
14101 -------------------
14102 -- Extend_System --
14103 -------------------
14105 -- pragma Extend_System ([Name =>] Identifier);
14107 when Pragma_Extend_System => Extend_System : declare
14110 Check_Valid_Configuration_Pragma;
14111 Check_Arg_Count (1);
14112 Check_Optional_Identifier (Arg1, Name_Name);
14113 Check_Arg_Is_Identifier (Arg1);
14115 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
14118 and then Name_Buffer (1 .. 4) = "aux_"
14120 if Present (System_Extend_Pragma_Arg) then
14121 if Chars (Get_Pragma_Arg (Arg1)) =
14122 Chars (Expression (System_Extend_Pragma_Arg))
14126 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
14127 Error_Pragma ("pragma% conflicts with that #");
14131 System_Extend_Pragma_Arg := Arg1;
14133 if not GNAT_Mode then
14134 System_Extend_Unit := Arg1;
14138 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
14142 ------------------------
14143 -- Extensions_Allowed --
14144 ------------------------
14146 -- pragma Extensions_Allowed (ON | OFF);
14148 when Pragma_Extensions_Allowed =>
14150 Check_Arg_Count (1);
14151 Check_No_Identifiers;
14152 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14154 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
14155 Extensions_Allowed := True;
14156 Ada_Version := Ada_Version_Type'Last;
14159 Extensions_Allowed := False;
14160 Ada_Version := Ada_Version_Explicit;
14161 Ada_Version_Pragma := Empty;
14168 -- pragma External (
14169 -- [ Convention =>] convention_IDENTIFIER,
14170 -- [ Entity =>] LOCAL_NAME
14171 -- [, [External_Name =>] static_string_EXPRESSION ]
14172 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14174 when Pragma_External => External : declare
14175 Def_Id : Entity_Id;
14178 pragma Warnings (Off, C);
14185 Name_External_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);
14196 --------------------------
14197 -- External_Name_Casing --
14198 --------------------------
14200 -- pragma External_Name_Casing (
14201 -- UPPERCASE | LOWERCASE
14202 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14204 when Pragma_External_Name_Casing => External_Name_Casing : declare
14207 Check_No_Identifiers;
14209 if Arg_Count = 2 then
14210 Check_Arg_Is_One_Of
14211 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
14213 case Chars (Get_Pragma_Arg (Arg2)) is
14215 Opt.External_Name_Exp_Casing := As_Is;
14217 when Name_Uppercase =>
14218 Opt.External_Name_Exp_Casing := Uppercase;
14220 when Name_Lowercase =>
14221 Opt.External_Name_Exp_Casing := Lowercase;
14228 Check_Arg_Count (1);
14231 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
14233 case Chars (Get_Pragma_Arg (Arg1)) is
14234 when Name_Uppercase =>
14235 Opt.External_Name_Imp_Casing := Uppercase;
14237 when Name_Lowercase =>
14238 Opt.External_Name_Imp_Casing := Lowercase;
14243 end External_Name_Casing;
14249 -- pragma Fast_Math;
14251 when Pragma_Fast_Math =>
14253 Check_No_Identifiers;
14254 Check_Valid_Configuration_Pragma;
14257 --------------------------
14258 -- Favor_Top_Level --
14259 --------------------------
14261 -- pragma Favor_Top_Level (type_NAME);
14263 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
14264 Named_Entity : Entity_Id;
14268 Check_No_Identifiers;
14269 Check_Arg_Count (1);
14270 Check_Arg_Is_Local_Name (Arg1);
14271 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
14273 -- If it's an access-to-subprogram type (in particular, not a
14274 -- subtype), set the flag on that type.
14276 if Is_Access_Subprogram_Type (Named_Entity) then
14277 Set_Can_Use_Internal_Rep (Named_Entity, False);
14279 -- Otherwise it's an error (name denotes the wrong sort of entity)
14283 ("access-to-subprogram type expected",
14284 Get_Pragma_Arg (Arg1));
14286 end Favor_Top_Level;
14288 ---------------------------
14289 -- Finalize_Storage_Only --
14290 ---------------------------
14292 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
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);
14301 Check_No_Identifiers;
14302 Check_Arg_Count (1);
14303 Check_Arg_Is_Local_Name (Arg1);
14305 Find_Type (Type_Id);
14306 Typ := Entity (Type_Id);
14309 or else Rep_Item_Too_Early (Typ, N)
14313 Typ := Underlying_Type (Typ);
14316 if not Is_Controlled (Typ) then
14317 Error_Pragma ("pragma% must specify controlled type");
14320 Check_First_Subtype (Arg1);
14322 if Finalize_Storage_Only (Typ) then
14323 Error_Pragma ("duplicate pragma%, only one allowed");
14325 elsif not Rep_Item_Too_Late (Typ, N) then
14326 Set_Finalize_Storage_Only (Base_Type (Typ), True);
14328 end Finalize_Storage;
14330 --------------------------
14331 -- Float_Representation --
14332 --------------------------
14334 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
14336 -- FLOAT_REP ::= VAX_Float | IEEE_Float
14338 when Pragma_Float_Representation => Float_Representation : declare
14346 if Arg_Count = 1 then
14347 Check_Valid_Configuration_Pragma;
14349 Check_Arg_Count (2);
14350 Check_Optional_Identifier (Arg2, Name_Entity);
14351 Check_Arg_Is_Local_Name (Arg2);
14354 Check_No_Identifier (Arg1);
14355 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
14357 if not OpenVMS_On_Target then
14358 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
14360 ("??pragma% ignored (applies only to Open'V'M'S)");
14366 -- One argument case
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");
14374 Opt.Float_Format := 'V';
14377 if Opt.Float_Format = 'V' then
14378 Error_Pragma ("'V'A'X format previously specified");
14381 Opt.Float_Format := 'I';
14384 Set_Standard_Fpt_Formats;
14386 -- Two argument case
14389 Argx := Get_Pragma_Arg (Arg2);
14391 if not Is_Entity_Name (Argx)
14392 or else not Is_Floating_Point_Type (Entity (Argx))
14395 ("second argument of% pragma must be floating-point type",
14399 Ent := Entity (Argx);
14400 Digs := UI_To_Int (Digits_Value (Ent));
14402 -- Two arguments, VAX_Float case
14404 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
14406 when 6 => Set_F_Float (Ent);
14407 when 9 => Set_D_Float (Ent);
14408 when 15 => Set_G_Float (Ent);
14412 ("wrong digits value, must be 6,9 or 15", Arg2);
14415 -- Two arguments, IEEE_Float case
14419 when 6 => Set_IEEE_Short (Ent);
14420 when 15 => Set_IEEE_Long (Ent);
14424 ("wrong digits value, must be 6 or 15", Arg2);
14428 end Float_Representation;
14434 -- pragma Global (GLOBAL_SPECIFICATION);
14436 -- GLOBAL_SPECIFICATION ::=
14439 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14441 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14443 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14444 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14445 -- GLOBAL_ITEM ::= NAME
14447 when Pragma_Global => Global : declare
14448 Subp_Decl : Node_Id;
14452 Check_Arg_Count (1);
14453 Ensure_Aggregate_Form (Arg1);
14455 -- Ensure the proper placement of the pragma. Global must be
14456 -- associated with a subprogram declaration or a body that acts
14460 Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
14462 if Nkind (Subp_Decl) = N_Subprogram_Declaration then
14465 -- Body acts as spec
14467 elsif Nkind (Subp_Decl) = N_Subprogram_Body
14468 and then No (Corresponding_Spec (Subp_Decl))
14472 -- Body stub acts as spec
14474 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
14475 and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
14484 -- When the pragma appears on a subprogram body, perform the full
14487 if Nkind (Subp_Decl) = N_Subprogram_Body then
14488 Analyze_Global_In_Decl_Part (N);
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.
14494 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
14495 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
14497 Analyze_Global_In_Decl_Part (N);
14500 -- Chain the pragma on the contract for further processing
14502 Add_Contract_Item (N, Defining_Entity (Subp_Decl));
14509 -- pragma Ident (static_string_EXPRESSION)
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
14516 when Pragma_Ident | Pragma_Comment => Ident : declare
14521 Check_Arg_Count (1);
14522 Check_No_Identifiers;
14523 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
14526 -- For pragma Ident, preserve DEC compatibility by requiring the
14527 -- pragma to appear in a declarative part or package spec.
14529 if Prag_Id = Pragma_Ident then
14530 Check_Is_In_Decl_Part_Or_Package_Spec;
14533 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
14540 GP := Parent (Parent (N));
14542 if Nkind_In (GP, N_Package_Declaration,
14543 N_Generic_Package_Declaration)
14548 -- If we have a compilation unit, then record the ident value,
14549 -- checking for improper duplication.
14551 if Nkind (GP) = N_Compilation_Unit then
14552 CS := Ident_String (Current_Sem_Unit);
14554 if Present (CS) then
14556 -- For Ident, we do not permit multiple instances
14558 if Prag_Id = Pragma_Ident then
14559 Error_Pragma ("duplicate% pragma not permitted");
14561 -- For Comment, we concatenate the string, unless we want
14562 -- to preserve the tree structure for ASIS.
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);
14572 -- In VMS, the effect of IDENT is achieved by passing
14573 -- --identification=name as a --for-linker switch.
14575 if OpenVMS_On_Target then
14578 ("--for-linker=--identification=");
14579 String_To_Name_Buffer (Strval (Str));
14580 Store_String_Chars (Name_Buffer (1 .. Name_Len));
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.
14587 Replace_Linker_Option_String
14588 (End_String, "--for-linker=--identification=");
14591 Set_Ident_String (Current_Sem_Unit, Str);
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.
14598 elsif Nkind (GP) = N_Subunit then
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.
14605 elsif Prag_Id = Pragma_Ident then
14606 if Instantiation_Location (Loc) = No_Location then
14607 Error_Pragma ("pragma% only allowed at outer level");
14613 ----------------------------
14614 -- Implementation_Defined --
14615 ----------------------------
14617 -- pragma Implementation_Defined (LOCAL_NAME);
14619 -- Marks previously declared entity as implementation defined. For
14620 -- an overloaded entity, applies to the most recent homonym.
14622 -- pragma Implementation_Defined;
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.
14628 when Pragma_Implementation_Defined => Implementation_Defined : declare
14633 Check_No_Identifiers;
14635 -- Form with no arguments
14637 if Arg_Count = 0 then
14638 Set_Is_Implementation_Defined (Current_Scope);
14640 -- Form with one argument
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);
14648 end Implementation_Defined;
14654 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14656 -- IMPLEMENTATION_KIND ::=
14657 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14659 -- "By_Any" and "Optional" are treated as synonyms in order to
14660 -- support Ada 2012 aspect Synchronization.
14662 when Pragma_Implemented => Implemented : declare
14663 Proc_Id : Entity_Id;
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,
14675 Name_By_Protected_Procedure,
14678 -- Extract the name of the local procedure
14680 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
14682 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14683 -- primitive procedure of a synchronized tagged type.
14685 if Ekind (Proc_Id) = E_Procedure
14686 and then Is_Primitive (Proc_Id)
14687 and then Present (First_Formal (Proc_Id))
14689 Typ := Etype (First_Formal (Proc_Id));
14691 if Is_Tagged_Type (Typ)
14694 -- Check for a protected, a synchronized or a task interface
14696 ((Is_Interface (Typ)
14697 and then Is_Synchronized_Interface (Typ))
14699 -- Check for a protected type or a task type that implements
14703 (Is_Concurrent_Record_Type (Typ)
14704 and then Present (Interfaces (Typ)))
14706 -- Check for a private record extension with keyword
14710 (Ekind_In (Typ, E_Record_Type_With_Private,
14711 E_Record_Subtype_With_Private)
14712 and then Synchronized_Present (Parent (Typ))))
14717 ("controlling formal must be of synchronized tagged type",
14722 -- Procedures declared inside a protected type must be accepted
14724 elsif Ekind (Proc_Id) = E_Procedure
14725 and then Is_Protected_Type (Scope (Proc_Id))
14729 -- The first argument is not a primitive procedure
14733 ("pragma % must be applied to a primitive procedure", Arg1);
14737 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
14738 -- By_Protected_Procedure to the primitive procedure of a task
14741 if Chars (Arg2) = Name_By_Protected_Procedure
14742 and then Is_Interface (Typ)
14743 and then Is_Task_Interface (Typ)
14746 ("implementation kind By_Protected_Procedure cannot be "
14747 & "applied to a task interface primitive", Arg2);
14751 Record_Rep_Item (Proc_Id, N);
14754 ----------------------
14755 -- Implicit_Packing --
14756 ----------------------
14758 -- pragma Implicit_Packing;
14760 when Pragma_Implicit_Packing =>
14762 Check_Arg_Count (0);
14763 Implicit_Packing := True;
14770 -- [Convention =>] convention_IDENTIFIER,
14771 -- [Entity =>] LOCAL_NAME
14772 -- [, [External_Name =>] static_string_EXPRESSION ]
14773 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14775 when Pragma_Import =>
14776 Check_Ada_83_Warning;
14780 Name_External_Name,
14783 Check_At_Least_N_Arguments (2);
14784 Check_At_Most_N_Arguments (4);
14785 Process_Import_Or_Interface;
14787 ----------------------
14788 -- Import_Exception --
14789 ----------------------
14791 -- pragma Import_Exception (
14792 -- [Internal =>] LOCAL_NAME
14793 -- [, [External =>] EXTERNAL_SYMBOL]
14794 -- [, [Form =>] Ada | VMS]
14795 -- [, [Code =>] static_integer_EXPRESSION]);
14797 when Pragma_Import_Exception => Import_Exception : declare
14798 Args : Args_List (1 .. 4);
14799 Names : constant Name_List (1 .. 4) := (
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);
14812 Gather_Associations (Names, Args);
14814 if Present (External) and then Present (Code) then
14816 ("cannot give both External and Code options for pragma%");
14819 Process_Extended_Import_Export_Exception_Pragma (
14820 Arg_Internal => Internal,
14821 Arg_External => External,
14825 if not Is_VMS_Exception (Entity (Internal)) then
14826 Set_Imported (Entity (Internal));
14828 end Import_Exception;
14830 ---------------------
14831 -- Import_Function --
14832 ---------------------
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]);
14843 -- EXTERNAL_SYMBOL ::=
14845 -- | static_string_EXPRESSION
14847 -- PARAMETER_TYPES ::=
14849 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14851 -- TYPE_DESIGNATOR ::=
14853 -- | subtype_Name ' Access
14857 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14859 -- MECHANISM_ASSOCIATION ::=
14860 -- [formal_parameter_NAME =>] MECHANISM_NAME
14862 -- MECHANISM_NAME ::=
14865 -- | Descriptor [([Class =>] CLASS_NAME)]
14867 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
14869 when Pragma_Import_Function => Import_Function : declare
14870 Args : Args_List (1 .. 7);
14871 Names : constant Name_List (1 .. 7) := (
14874 Name_Parameter_Types,
14877 Name_Result_Mechanism,
14878 Name_First_Optional_Parameter);
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);
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;
14901 -------------------
14902 -- Import_Object --
14903 -------------------
14905 -- pragma Import_Object (
14906 -- [Internal =>] LOCAL_NAME
14907 -- [, [External =>] EXTERNAL_SYMBOL]
14908 -- [, [Size =>] EXTERNAL_SYMBOL]);
14910 -- EXTERNAL_SYMBOL ::=
14912 -- | static_string_EXPRESSION
14914 when Pragma_Import_Object => Import_Object : declare
14915 Args : Args_List (1 .. 3);
14916 Names : constant Name_List (1 .. 3) := (
14921 Internal : Node_Id renames Args (1);
14922 External : Node_Id renames Args (2);
14923 Size : Node_Id renames Args (3);
14927 Gather_Associations (Names, Args);
14928 Process_Extended_Import_Export_Object_Pragma (
14929 Arg_Internal => Internal,
14930 Arg_External => External,
14934 ----------------------
14935 -- Import_Procedure --
14936 ----------------------
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]);
14945 -- EXTERNAL_SYMBOL ::=
14947 -- | static_string_EXPRESSION
14949 -- PARAMETER_TYPES ::=
14951 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14953 -- TYPE_DESIGNATOR ::=
14955 -- | subtype_Name ' Access
14959 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14961 -- MECHANISM_ASSOCIATION ::=
14962 -- [formal_parameter_NAME =>] MECHANISM_NAME
14964 -- MECHANISM_NAME ::=
14967 -- | Descriptor [([Class =>] CLASS_NAME)]
14969 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
14971 when Pragma_Import_Procedure => Import_Procedure : declare
14972 Args : Args_List (1 .. 5);
14973 Names : constant Name_List (1 .. 5) := (
14976 Name_Parameter_Types,
14978 Name_First_Optional_Parameter);
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);
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;
14997 -----------------------------
14998 -- Import_Valued_Procedure --
14999 -----------------------------
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]);
15008 -- EXTERNAL_SYMBOL ::=
15010 -- | static_string_EXPRESSION
15012 -- PARAMETER_TYPES ::=
15014 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15016 -- TYPE_DESIGNATOR ::=
15018 -- | subtype_Name ' Access
15022 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15024 -- MECHANISM_ASSOCIATION ::=
15025 -- [formal_parameter_NAME =>] MECHANISM_NAME
15027 -- MECHANISM_NAME ::=
15030 -- | Descriptor [([Class =>] CLASS_NAME)]
15032 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
15034 when Pragma_Import_Valued_Procedure =>
15035 Import_Valued_Procedure : declare
15036 Args : Args_List (1 .. 5);
15037 Names : constant Name_List (1 .. 5) := (
15040 Name_Parameter_Types,
15042 Name_First_Optional_Parameter);
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);
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;
15065 -- pragma Independent (record_component_LOCAL_NAME);
15067 when Pragma_Independent => Independent : declare
15072 Check_Ada_83_Warning;
15074 Check_No_Identifiers;
15075 Check_Arg_Count (1);
15076 Check_Arg_Is_Local_Name (Arg1);
15077 E_Id := Get_Pragma_Arg (Arg1);
15079 if Etype (E_Id) = Any_Type then
15083 E := Entity (E_Id);
15085 -- Check we have a record component. We have not yet setup
15086 -- components fully, so identify by syntactic structure.
15088 if Nkind (Declaration_Node (E)) /= N_Component_Declaration then
15090 ("argument for pragma% must be record component", Arg1);
15093 -- Check duplicate before we chain ourselves
15095 Check_Duplicate_Pragma (E);
15099 if Rep_Item_Too_Early (E, N)
15101 Rep_Item_Too_Late (E, N)
15106 -- Set flag in component
15108 Set_Is_Independent (E);
15110 Independence_Checks.Append ((N, E));
15113 ----------------------------
15114 -- Independent_Components --
15115 ----------------------------
15117 -- pragma Atomic_Components (array_LOCAL_NAME);
15119 -- This processing is shared by Volatile_Components
15121 when Pragma_Independent_Components => Independent_Components : declare
15129 Check_Ada_83_Warning;
15131 Check_No_Identifiers;
15132 Check_Arg_Count (1);
15133 Check_Arg_Is_Local_Name (Arg1);
15134 E_Id := Get_Pragma_Arg (Arg1);
15136 if Etype (E_Id) = Any_Type then
15140 E := Entity (E_Id);
15142 -- Check duplicate before we chain ourselves
15144 Check_Duplicate_Pragma (E);
15146 -- Check appropriate entity
15148 if Rep_Item_Too_Early (E, N)
15150 Rep_Item_Too_Late (E, N)
15155 D := Declaration_Node (E);
15158 if K = N_Full_Type_Declaration
15159 and then (Is_Array_Type (E) or else Is_Record_Type (E))
15161 Independence_Checks.Append ((N, Base_Type (E)));
15162 Set_Has_Independent_Components (Base_Type (E));
15164 -- For record type, set all components independent
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);
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
15179 Independence_Checks.Append ((N, Base_Type (Etype (E))));
15180 Set_Has_Independent_Components (Base_Type (Etype (E)));
15183 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
15185 end Independent_Components;
15187 -----------------------
15188 -- Initial_Condition --
15189 -----------------------
15191 -- pragma Initial_Condition (boolean_EXPRESSION);
15193 when Pragma_Initial_Condition => Initial_Condition : declare
15194 Context : constant Node_Id := Parent (Parent (N));
15195 Pack_Id : Entity_Id;
15200 Check_Arg_Count (1);
15202 -- Ensure the proper placement of the pragma. Initial_Condition
15203 -- must be associated with a package declaration.
15205 if not Nkind_In (Context, N_Generic_Package_Declaration,
15206 N_Package_Declaration)
15213 while Present (Stmt) loop
15215 -- Skip prior pragmas, but check for duplicates
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);
15224 -- Skip internally generated code
15226 elsif not Comes_From_Source (Stmt) then
15229 -- The pragma does not apply to a legal construct, issue an
15230 -- error and stop the analysis.
15237 Stmt := Prev (Stmt);
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.
15245 Pack_Id := Defining_Entity (Context);
15246 Add_Contract_Item (N, Pack_Id);
15248 -- Verify the declaration order of pragma Initial_Condition with
15249 -- respect to pragmas Abstract_State and Initializes when SPARK
15250 -- checks are enabled.
15252 if SPARK_Mode /= Off then
15253 Check_Declaration_Order
15254 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15257 Check_Declaration_Order
15258 (First => Get_Pragma (Pack_Id, Pragma_Initializes),
15261 end Initial_Condition;
15263 ------------------------
15264 -- Initialize_Scalars --
15265 ------------------------
15267 -- pragma Initialize_Scalars;
15269 when Pragma_Initialize_Scalars =>
15271 Check_Arg_Count (0);
15272 Check_Valid_Configuration_Pragma;
15273 Check_Restriction (No_Initialize_Scalars, N);
15275 -- Initialize_Scalars creates false positives in CodePeer, and
15276 -- incorrect negative results in GNATprove mode, so ignore this
15277 -- pragma in these modes.
15279 if not Restriction_Active (No_Initialize_Scalars)
15280 and then not (CodePeer_Mode or GNATprove_Mode)
15282 Init_Or_Norm_Scalars := True;
15283 Initialize_Scalars := True;
15290 -- pragma Initializes (INITIALIZATION_SPEC);
15292 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
15294 -- INITIALIZATION_LIST ::=
15295 -- INITIALIZATION_ITEM
15296 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15298 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15303 -- | (INPUT {, INPUT})
15307 when Pragma_Initializes => Initializes : declare
15308 Context : constant Node_Id := Parent (Parent (N));
15309 Pack_Id : Entity_Id;
15314 Check_Arg_Count (1);
15315 Ensure_Aggregate_Form (Arg1);
15317 -- Ensure the proper placement of the pragma. Initializes must be
15318 -- associated with a package declaration.
15320 if not Nkind_In (Context, N_Generic_Package_Declaration,
15321 N_Package_Declaration)
15328 while Present (Stmt) loop
15330 -- Skip prior pragmas, but check for duplicates
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);
15339 -- Skip internally generated code
15341 elsif not Comes_From_Source (Stmt) then
15344 -- The pragma does not apply to a legal construct, issue an
15345 -- error and stop the analysis.
15352 Stmt := Prev (Stmt);
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.
15360 Pack_Id := Defining_Entity (Context);
15361 Add_Contract_Item (N, Pack_Id);
15363 -- Verify the declaration order of pragmas Abstract_State and
15364 -- Initializes when SPARK checks are enabled.
15366 if SPARK_Mode /= Off then
15367 Check_Declaration_Order
15368 (First => Get_Pragma (Pack_Id, Pragma_Abstract_State),
15377 -- pragma Inline ( NAME {, NAME} );
15379 when Pragma_Inline =>
15381 -- Inline status is Enabled if inlining option is active
15383 if Inline_Active then
15384 Process_Inline (Enabled);
15386 Process_Inline (Disabled);
15389 -------------------
15390 -- Inline_Always --
15391 -------------------
15393 -- pragma Inline_Always ( NAME {, NAME} );
15395 when Pragma_Inline_Always =>
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.
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.
15406 if not CodePeer_Mode then
15407 Process_Inline (Enabled);
15410 --------------------
15411 -- Inline_Generic --
15412 --------------------
15414 -- pragma Inline_Generic (NAME {, NAME});
15416 when Pragma_Inline_Generic =>
15418 Process_Generic_List;
15420 ----------------------
15421 -- Inspection_Point --
15422 ----------------------
15424 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
15426 when Pragma_Inspection_Point => Inspection_Point : declare
15433 if Arg_Count > 0 then
15436 Exp := Get_Pragma_Arg (Arg);
15439 if not Is_Entity_Name (Exp)
15440 or else not Is_Object (Entity (Exp))
15442 Error_Pragma_Arg ("object name required", Arg);
15446 exit when No (Arg);
15449 end Inspection_Point;
15455 -- pragma Interface (
15456 -- [ Convention =>] convention_IDENTIFIER,
15457 -- [ Entity =>] LOCAL_NAME
15458 -- [, [External_Name =>] static_string_EXPRESSION ]
15459 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15461 when Pragma_Interface =>
15466 Name_External_Name,
15468 Check_At_Least_N_Arguments (2);
15469 Check_At_Most_N_Arguments (4);
15470 Process_Import_Or_Interface;
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.
15476 if Ada_Version >= Ada_95 then
15478 (No_Obsolescent_Features, Pragma_Identifier (N));
15480 if Warn_On_Obsolescent_Feature then
15482 ("pragma Interface is an obsolescent feature?j?", N);
15484 ("|use pragma Import instead?j?", N);
15488 --------------------
15489 -- Interface_Name --
15490 --------------------
15492 -- pragma Interface_Name (
15493 -- [ Entity =>] LOCAL_NAME
15494 -- [,[External_Name =>] static_string_EXPRESSION ]
15495 -- [,[Link_Name =>] static_string_EXPRESSION ]);
15497 when Pragma_Interface_Name => Interface_Name : declare
15499 Def_Id : Entity_Id;
15500 Hom_Id : Entity_Id;
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);
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).
15516 if Ada_Version >= Ada_95 then
15517 if Warn_On_Obsolescent_Feature then
15519 ("pragma Interface_Name is an obsolescent feature?j?", N);
15521 ("|use pragma Import instead?j?", N);
15525 if not Is_Entity_Name (Id) then
15527 ("first argument for pragma% must be entity name", Arg1);
15528 elsif Etype (Id) = Any_Type then
15531 Def_Id := Entity (Id);
15534 -- Special DEC-compatible processing for the object case, forces
15535 -- object to be imported.
15537 if Ekind (Def_Id) = E_Variable then
15538 Kill_Size_Check_Code (Def_Id);
15539 Note_Possible_Modification (Id, Sure => False);
15541 -- Initialization is not allowed for imported variable
15543 if Present (Expression (Parent (Def_Id)))
15544 and then Comes_From_Source (Expression (Parent (Def_Id)))
15546 Error_Msg_Sloc := Sloc (Def_Id);
15548 ("no initialization allowed for declaration of& #",
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.
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
15560 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
15564 Set_Imported (Def_Id);
15567 Set_Is_Public (Def_Id);
15568 Process_Interface_Name (Def_Id, Arg2, Arg3);
15571 -- Otherwise must be subprogram
15573 elsif not Is_Subprogram (Def_Id) then
15575 ("argument of pragma% is not subprogram", Arg1);
15578 Check_At_Most_N_Arguments (3);
15582 -- Loop through homonyms
15585 Def_Id := Get_Base_Subprogram (Hom_Id);
15587 if Is_Imported (Def_Id) then
15588 Process_Interface_Name (Def_Id, Arg2, Arg3);
15592 exit when From_Aspect_Specification (N);
15593 Hom_Id := Homonym (Hom_Id);
15595 exit when No (Hom_Id)
15596 or else Scope (Hom_Id) /= Current_Scope;
15601 ("argument of pragma% is not imported subprogram",
15605 end Interface_Name;
15607 -----------------------
15608 -- Interrupt_Handler --
15609 -----------------------
15611 -- pragma Interrupt_Handler (handler_NAME);
15613 when Pragma_Interrupt_Handler =>
15614 Check_Ada_83_Warning;
15615 Check_Arg_Count (1);
15616 Check_No_Identifiers;
15618 if No_Run_Time_Mode then
15619 Error_Msg_CRT ("Interrupt_Handler pragma", N);
15621 Check_Interrupt_Or_Attach_Handler;
15622 Process_Interrupt_Or_Attach_Handler;
15625 ------------------------
15626 -- Interrupt_Priority --
15627 ------------------------
15629 -- pragma Interrupt_Priority [(EXPRESSION)];
15631 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
15632 P : constant Node_Id := Parent (N);
15637 Check_Ada_83_Warning;
15639 if Arg_Count /= 0 then
15640 Arg := Get_Pragma_Arg (Arg1);
15641 Check_Arg_Count (1);
15642 Check_No_Identifiers;
15644 -- The expression must be analyzed in the special manner
15645 -- described in "Handling of Default and Per-Object
15646 -- Expressions" in sem.ads.
15648 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
15651 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
15656 Ent := Defining_Identifier (Parent (P));
15658 -- Check duplicate pragma before we chain the pragma in the Rep
15659 -- Item chain of Ent.
15661 Check_Duplicate_Pragma (Ent);
15662 Record_Rep_Item (Ent, N);
15664 end Interrupt_Priority;
15666 ---------------------
15667 -- Interrupt_State --
15668 ---------------------
15670 -- pragma Interrupt_State (
15671 -- [Name =>] INTERRUPT_ID,
15672 -- [State =>] INTERRUPT_STATE);
15674 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15675 -- INTERRUPT_STATE => System | Runtime | User
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.
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;
15686 State_Type : Character;
15687 -- Set to 's'/'r'/'u' for System/Runtime/User
15690 -- Index to entry in Interrupt_States table
15693 -- Value of interrupt
15695 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
15696 -- The first argument to the pragma
15698 Int_Ent : Entity_Id;
15699 -- Interrupt entity in Ada.Interrupts.Names
15703 Check_Arg_Order ((Name_Name, Name_State));
15704 Check_Arg_Count (2);
15706 Check_Optional_Identifier (Arg1, Name_Name);
15707 Check_Optional_Identifier (Arg2, Name_State);
15708 Check_Arg_Is_Identifier (Arg2);
15710 -- First argument is identifier
15712 if Nkind (Arg1X) = N_Identifier then
15714 -- Search list of names in Ada.Interrupts.Names
15716 Int_Ent := First_Entity (RTE (RE_Names));
15718 if No (Int_Ent) then
15719 Error_Pragma_Arg ("invalid interrupt name", Arg1);
15721 elsif Chars (Int_Ent) = Chars (Arg1X) then
15722 Int_Val := Expr_Value (Constant_Value (Int_Ent));
15726 Next_Entity (Int_Ent);
15729 -- First argument is not an identifier, so it must be a static
15730 -- expression of type Ada.Interrupts.Interrupt_ID.
15733 Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer);
15734 Int_Val := Expr_Value (Arg1X);
15736 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
15738 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
15741 ("value not in range of type "
15742 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
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';
15754 Error_Pragma_Arg ("invalid interrupt state", Arg2);
15757 -- Check if entry is already stored
15759 IST_Num := Interrupt_States.First;
15761 -- If entry not found, add it
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));
15770 -- Case of entry for the same entry
15772 elsif Int_Val = Interrupt_States.Table (IST_Num).
15775 -- If state matches, done, no need to make redundant entry
15778 State_Type = Interrupt_States.Table (IST_Num).
15781 -- Otherwise if state does not match, error
15784 Interrupt_States.Table (IST_Num).Pragma_Loc;
15786 ("state conflicts with that given #", Arg2);
15790 IST_Num := IST_Num + 1;
15792 end Interrupt_State;
15798 -- pragma Invariant
15799 -- ([Entity =>] type_LOCAL_NAME,
15800 -- [Check =>] EXPRESSION
15801 -- [,[Message =>] String_Expression]);
15803 when Pragma_Invariant => Invariant : declare
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);
15816 if Arg_Count = 3 then
15817 Check_Optional_Identifier (Arg3, Name_Message);
15818 Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String);
15821 Check_Arg_Is_Local_Name (Arg1);
15823 Type_Id := Get_Pragma_Arg (Arg1);
15824 Find_Type (Type_Id);
15825 Typ := Entity (Type_Id);
15827 if Typ = Any_Type then
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.
15835 elsif Ekind_In (Typ, E_Private_Type,
15836 E_Record_Type_With_Private,
15837 E_Limited_Private_Type)
15841 elsif In_Private_Part (Current_Scope)
15842 and then Has_Private_Declaration (Typ)
15843 and then not Class_Present (N)
15847 elsif In_Private_Part (Current_Scope) then
15849 ("pragma% only allowed for private type declared in "
15850 & "visible part", Arg1);
15854 ("pragma% only allowed for private type", Arg1);
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).
15863 PDecl := Build_Invariant_Procedure_Declaration (Typ);
15865 Insert_After (N, PDecl);
15868 if Class_Present (N) then
15869 Set_Has_Inheritable_Invariants (Typ);
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.
15876 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15879 ----------------------
15880 -- Java_Constructor --
15881 ----------------------
15883 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15885 -- Also handles pragma CIL_Constructor
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;
15893 This_Formal : Entity_Id;
15897 Check_Arg_Count (1);
15898 Check_Optional_Identifier (Arg1, Name_Entity);
15899 Check_Arg_Is_Local_Name (Arg1);
15901 Id := Get_Pragma_Arg (Arg1);
15902 Find_Program_Unit_Name (Id);
15904 -- If we did not find the name, we are done
15906 if Etype (Id) = Any_Type then
15910 -- Check wrong use of pragma in wrong VM target
15912 if VM_Target = No_VM then
15915 elsif VM_Target = CLI_Target
15916 and then Prag_Id = Pragma_Java_Constructor
15918 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
15920 elsif VM_Target = JVM_Target
15921 and then Prag_Id = Pragma_CIL_Constructor
15923 Error_Pragma ("must use pragma 'Java_'Constructor");
15927 when Pragma_CIL_Constructor => Convention := Convention_CIL;
15928 when Pragma_Java_Constructor => Convention := Convention_Java;
15929 when others => null;
15932 Hom_Id := Entity (Id);
15934 -- Loop through homonyms
15937 Def_Id := Get_Base_Subprogram (Hom_Id);
15939 -- The constructor is required to be a function
15941 if Ekind (Def_Id) /= E_Function then
15942 if VM_Target = JVM_Target then
15944 ("pragma% requires function returning a 'Java access "
15948 ("pragma% requires function returning a 'C'I'L access "
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:
15959 -- type Typ is tagged ...
15960 -- type Ref is access all Typ;
15961 -- pragma Convention (CIL, Typ);
15963 -- function New_Typ (This : Ref) return Ref;
15964 -- function New_Typ (This : Ref; I : Integer) return Ref;
15965 -- pragma Cil_Constructor (New_Typ);
15967 -- Reason: The first formal must NOT be a primitive of the
15970 -- This rule also applies to constructors of delegates used
15971 -- to interface with standard target libraries. For example:
15973 -- type Delegate is access procedure ...
15974 -- pragma Import (CIL, Delegate, ...);
15976 -- function new_Delegate
15977 -- (This : Delegate := null; ... ) return Delegate;
15979 -- For value-types this rule does not apply.
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);
15988 -- In the JRE library we have several occurrences in which
15989 -- the "this" parameter is not the first formal.
15991 This_Formal := First_Formal (Def_Id);
15993 -- In the JRE library we have several occurrences in which
15994 -- the "this" parameter is not the first formal. Search for
15997 if VM_Target = JVM_Target then
15998 while Present (This_Formal)
15999 and then Get_Name_String (Chars (This_Formal)) /= "this"
16001 Next_Formal (This_Formal);
16004 if No (This_Formal) then
16005 This_Formal := First_Formal (Def_Id);
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) ???
16013 -- function new_Thread
16014 -- (Self_Id : System.Address) return Thread_Id;
16015 -- pragma Java_Constructor (new_Thread);
16017 if VM_Target = JVM_Target
16018 and then Get_Name_String (Chars (First_Formal (Def_Id)))
16020 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
16024 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
16025 Error_Msg_Name_1 := Pname;
16027 ("first formal of % function must be named `this`",
16028 Parent (This_Formal));
16030 elsif not Is_Access_Type (Etype (This_Formal)) then
16031 Error_Msg_Name_1 := Pname;
16033 ("first formal of % function must be an access type",
16034 Parameter_Type (Parent (This_Formal)));
16036 -- For delegates the type of the first formal must be a
16037 -- named access-to-subprogram type (see previous example)
16039 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
16040 and then Ekind (Etype (This_Formal))
16041 /= E_Access_Subprogram_Type
16043 Error_Msg_Name_1 := Pname;
16045 ("first formal of % function must be a named access "
16046 & "to subprogram type",
16047 Parameter_Type (Parent (This_Formal)));
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???
16054 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
16055 and then not Ekind_In (Etype (This_Formal),
16057 E_General_Access_Type,
16058 E_Anonymous_Access_Type)
16060 Error_Msg_Name_1 := Pname;
16062 ("first formal of % function must be a named access "
16063 & "type", Parameter_Type (Parent (This_Formal)));
16065 elsif Atree.Convention
16066 (Designated_Type (Etype (This_Formal))) /= Convention
16068 Error_Msg_Name_1 := Pname;
16070 if Convention = Convention_Java then
16072 ("pragma% requires convention 'Cil in designated "
16073 & "type", Parameter_Type (Parent (This_Formal)));
16076 ("pragma% requires convention 'Java in designated "
16077 & "type", Parameter_Type (Parent (This_Formal)));
16080 elsif No (Expression (Parent (This_Formal)))
16081 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
16083 Error_Msg_Name_1 := Pname;
16085 ("pragma% requires first formal with default `null`",
16086 Parameter_Type (Parent (This_Formal)));
16090 -- Check result type: the constructor must be a function
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
16097 if Is_Value_Type (Etype (Def_Id)) then
16100 -- Access-to-subprogram type with convention Java/CIL
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
16106 ("pragma% requires function returning a 'Java "
16107 & "access type", Arg1);
16109 pragma Assert (Convention = Convention_CIL);
16111 ("pragma% requires function returning a 'C'I'L "
16112 & "access type", Arg1);
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)
16121 (Designated_Type (Etype (Def_Id))) /= Convention
16123 Error_Msg_Name_1 := Pname;
16125 if Convention = Convention_Java then
16127 ("pragma% requires function returning a named "
16128 & "'Java access type", Arg1);
16131 ("pragma% requires function returning a named "
16132 & "'C'I'L access type", Arg1);
16137 Set_Is_Constructor (Def_Id);
16138 Set_Convention (Def_Id, Convention);
16139 Set_Is_Imported (Def_Id);
16141 exit when From_Aspect_Specification (N);
16142 Hom_Id := Homonym (Hom_Id);
16144 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
16146 end Java_Constructor;
16148 ----------------------
16149 -- Java_Interface --
16150 ----------------------
16152 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
16154 when Pragma_Java_Interface => Java_Interface : declare
16160 Check_Arg_Count (1);
16161 Check_Optional_Identifier (Arg1, Name_Entity);
16162 Check_Arg_Is_Local_Name (Arg1);
16164 Arg := Get_Pragma_Arg (Arg1);
16167 if Etype (Arg) = Any_Type then
16171 if not Is_Entity_Name (Arg)
16172 or else not Is_Type (Entity (Arg))
16174 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
16177 Typ := Underlying_Type (Entity (Arg));
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
16185 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
16187 ("pragma% requires an abstract tagged type", Arg1);
16189 elsif not Has_Discriminants (Typ)
16190 or else Ekind (Etype (First_Discriminant (Typ)))
16191 /= E_Anonymous_Access_Type
16193 not Is_Class_Wide_Type
16194 (Designated_Type (Etype (First_Discriminant (Typ))))
16197 ("type must have a class-wide access discriminant", Arg1);
16199 end Java_Interface;
16205 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16207 when Pragma_Keep_Names => Keep_Names : declare
16212 Check_Arg_Count (1);
16213 Check_Optional_Identifier (Arg1, Name_On);
16214 Check_Arg_Is_Local_Name (Arg1);
16216 Arg := Get_Pragma_Arg (Arg1);
16219 if Etype (Arg) = Any_Type then
16223 if not Is_Entity_Name (Arg)
16224 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
16227 ("pragma% requires a local enumeration type", Arg1);
16230 Set_Discard_Names (Entity (Arg), False);
16237 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16239 when Pragma_License =>
16241 Check_Arg_Count (1);
16242 Check_No_Identifiers;
16243 Check_Valid_Configuration_Pragma;
16244 Check_Arg_Is_Identifier (Arg1);
16247 Sind : constant Source_File_Index :=
16248 Source_Index (Current_Sem_Unit);
16251 case Chars (Get_Pragma_Arg (Arg1)) is
16253 Set_License (Sind, GPL);
16255 when Name_Modified_GPL =>
16256 Set_License (Sind, Modified_GPL);
16258 when Name_Restricted =>
16259 Set_License (Sind, Restricted);
16261 when Name_Unrestricted =>
16262 Set_License (Sind, Unrestricted);
16265 Error_Pragma_Arg ("invalid license name", Arg1);
16273 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16275 when Pragma_Link_With => Link_With : declare
16281 if Operating_Mode = Generate_Code
16282 and then In_Extended_Main_Source_Unit (N)
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);
16291 while Present (Arg) loop
16292 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
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).
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);
16305 procedure Skip_Spaces;
16306 -- Advance F past any spaces
16312 procedure Skip_Spaces is
16314 while F <= L and then Get_String_Char (S, F) = C loop
16319 -- Start of processing for Arg_Store
16322 Skip_Spaces; -- skip leading spaces
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)
16329 if Get_String_Char (S, F) = C then
16332 Store_String_Char (ASCII.NUL);
16335 Store_String_Char (Get_String_Char (S, F));
16343 if Present (Arg) then
16344 Store_String_Char (ASCII.NUL);
16348 Store_Linker_Option_String (End_String);
16356 -- pragma Linker_Alias (
16357 -- [Entity =>] LOCAL_NAME
16358 -- [Target =>] static_string_EXPRESSION);
16360 when Pragma_Linker_Alias =>
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);
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).
16374 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
16377 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16380 ------------------------
16381 -- Linker_Constructor --
16382 ------------------------
16384 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16386 -- Code is shared with Linker_Destructor
16388 -----------------------
16389 -- Linker_Destructor --
16390 -----------------------
16392 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16394 when Pragma_Linker_Constructor |
16395 Pragma_Linker_Destructor =>
16396 Linker_Constructor : declare
16402 Check_Arg_Count (1);
16403 Check_No_Identifiers;
16404 Check_Arg_Is_Local_Name (Arg1);
16405 Arg1_X := Get_Pragma_Arg (Arg1);
16407 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
16409 if not Is_Library_Level_Entity (Proc) then
16411 ("argument for pragma% must be library level entity", Arg1);
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).
16419 if Rep_Item_Too_Late (Proc, N) then
16422 Set_Has_Gigi_Rep_Item (Proc);
16424 end Linker_Constructor;
16426 --------------------
16427 -- Linker_Options --
16428 --------------------
16430 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16432 when Pragma_Linker_Options => Linker_Options : declare
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))));
16444 while Present (Arg) loop
16445 Check_Arg_Is_OK_Static_Expression (Arg, Standard_String);
16446 Store_String_Char (ASCII.NUL);
16448 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
16452 if Operating_Mode = Generate_Code
16453 and then In_Extended_Main_Source_Unit (N)
16455 Store_Linker_Option_String (End_String);
16457 end Linker_Options;
16459 --------------------
16460 -- Linker_Section --
16461 --------------------
16463 -- pragma Linker_Section (
16464 -- [Entity =>] LOCAL_NAME
16465 -- [Section =>] static_string_EXPRESSION);
16467 when Pragma_Linker_Section => Linker_Section : declare
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);
16480 -- Check kind of entity
16482 Arg := Get_Pragma_Arg (Arg1);
16483 Ent := Entity (Arg);
16485 case Ekind (Ent) is
16487 -- Objects (constants and variables) and types. For these cases
16488 -- all we need to do is to set the Linker_Section_pragma field.
16490 when E_Constant | E_Variable | Type_Kind =>
16491 Set_Linker_Section_Pragma (Ent, N);
16495 when Subprogram_Kind =>
16497 -- Aspect case, entity already set
16499 if From_Aspect_Specification (N) then
16500 Set_Linker_Section_Pragma
16501 (Entity (Corresponding_Aspect (N)), N);
16503 -- Pragma case, we must climb the homonym chain, but skip
16504 -- any for which the linker section is already set.
16508 if No (Linker_Section_Pragma (Ent)) then
16509 Set_Linker_Section_Pragma (Ent, N);
16512 Ent := Homonym (Ent);
16514 or else Scope (Ent) /= Current_Scope;
16518 -- All other cases are illegal
16522 ("pragma% applies only to objects, subprograms, and types",
16525 end Linker_Section;
16531 -- pragma List (On | Off)
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
16537 when Pragma_List =>
16544 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16546 when Pragma_Lock_Free => Lock_Free : declare
16547 P : constant Node_Id := Parent (N);
16553 Check_No_Identifiers;
16554 Check_At_Most_N_Arguments (1);
16556 -- Protected definition case
16558 if Nkind (P) = N_Protected_Definition then
16559 Ent := Defining_Identifier (Parent (P));
16563 if Arg_Count = 1 then
16564 Arg := Get_Pragma_Arg (Arg1);
16565 Val := Is_True (Static_Boolean (Arg));
16567 -- No arguments (expression is considered to be True)
16573 -- Check duplicate pragma before we chain the pragma in the Rep
16574 -- Item chain of Ent.
16576 Check_Duplicate_Pragma (Ent);
16577 Record_Rep_Item (Ent, N);
16578 Set_Uses_Lock_Free (Ent, Val);
16580 -- Anything else is incorrect placement
16587 --------------------
16588 -- Locking_Policy --
16589 --------------------
16591 -- pragma Locking_Policy (policy_IDENTIFIER);
16593 when Pragma_Locking_Policy => declare
16594 subtype LP_Range is Name_Id
16595 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
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));
16608 when Name_Ceiling_Locking =>
16610 when Name_Inheritance_Locking =>
16612 when Name_Concurrent_Readers_Locking =>
16616 if Locking_Policy /= ' '
16617 and then Locking_Policy /= LP
16619 Error_Msg_Sloc := Locking_Policy_Sloc;
16620 Error_Pragma ("locking policy incompatible with policy#");
16622 -- Set new policy, but always preserve System_Location since we
16623 -- like the error message with the run time name.
16626 Locking_Policy := LP;
16628 if Locking_Policy_Sloc /= System_Location then
16629 Locking_Policy_Sloc := Loc;
16638 -- pragma Long_Float (D_Float | G_Float);
16640 when Pragma_Long_Float => Long_Float : declare
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);
16648 if not OpenVMS_On_Target then
16649 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
16654 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
16655 if Opt.Float_Format_Long = 'G' then
16657 ("G_Float previously specified", Arg1);
16659 elsif Current_Sem_Unit /= Main_Unit
16660 and then Opt.Float_Format_Long /= 'D'
16663 ("main unit not compiled with pragma Long_Float (D_Float)",
16664 "\pragma% must be used consistently for whole partition",
16668 Opt.Float_Format_Long := 'D';
16671 -- G_Float case (this is the default, does not need overriding)
16674 if Opt.Float_Format_Long = 'D' then
16675 Error_Pragma ("D_Float previously specified");
16677 elsif Current_Sem_Unit /= Main_Unit
16678 and then Opt.Float_Format_Long /= 'G'
16681 ("main unit not compiled with pragma Long_Float (G_Float)",
16682 "\pragma% must be used consistently for whole partition",
16686 Opt.Float_Format_Long := 'G';
16690 Set_Standard_Fpt_Formats;
16693 -------------------
16694 -- Loop_Optimize --
16695 -------------------
16697 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16699 -- OPTIMIZATION_HINT ::=
16700 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16702 when Pragma_Loop_Optimize => Loop_Optimize : declare
16707 Check_At_Least_N_Arguments (1);
16708 Check_No_Identifiers;
16710 Hint := First (Pragma_Argument_Associations (N));
16711 while Present (Hint) loop
16712 Check_Arg_Is_One_Of (Hint, Name_Ivdep,
16720 Check_Loop_Pragma_Placement;
16727 -- pragma Loop_Variant
16728 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16730 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16732 -- CHANGE_DIRECTION ::= Increases | Decreases
16734 when Pragma_Loop_Variant => Loop_Variant : declare
16739 Check_At_Least_N_Arguments (1);
16740 Check_Loop_Pragma_Placement;
16742 -- Process all increasing / decreasing expressions
16744 Variant := First (Pragma_Argument_Associations (N));
16745 while Present (Variant) loop
16746 if not Nam_In (Chars (Variant), Name_Decreases,
16749 Error_Pragma_Arg ("wrong change modifier", Variant);
16752 Preanalyze_Assert_Expression
16753 (Expression (Variant), Any_Discrete);
16759 -----------------------
16760 -- Machine_Attribute --
16761 -----------------------
16763 -- pragma Machine_Attribute (
16764 -- [Entity =>] LOCAL_NAME,
16765 -- [Attribute_Name =>] static_string_EXPRESSION
16766 -- [, [Info =>] static_EXPRESSION] );
16768 when Pragma_Machine_Attribute => Machine_Attribute : declare
16769 Def_Id : Entity_Id;
16773 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
16775 if Arg_Count = 3 then
16776 Check_Optional_Identifier (Arg3, Name_Info);
16777 Check_Arg_Is_OK_Static_Expression (Arg3);
16779 Check_Arg_Count (2);
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));
16788 if Is_Access_Type (Def_Id) then
16789 Def_Id := Designated_Type (Def_Id);
16792 if Rep_Item_Too_Early (Def_Id, N) then
16796 Def_Id := Underlying_Type (Def_Id);
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).
16803 if Rep_Item_Too_Late (Def_Id, N) then
16806 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
16808 end Machine_Attribute;
16815 -- (MAIN_OPTION [, MAIN_OPTION]);
16818 -- [STACK_SIZE =>] static_integer_EXPRESSION
16819 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16820 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16822 when Pragma_Main => Main : declare
16823 Args : Args_List (1 .. 3);
16824 Names : constant Name_List (1 .. 3) := (
16826 Name_Task_Stack_Size_Default,
16827 Name_Time_Slicing_Enabled);
16833 Gather_Associations (Names, Args);
16835 for J in 1 .. 2 loop
16836 if Present (Args (J)) then
16837 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16841 if Present (Args (3)) then
16842 Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean);
16846 while Present (Nod) loop
16847 if Nkind (Nod) = N_Pragma
16848 and then Pragma_Name (Nod) = Name_Main
16850 Error_Msg_Name_1 := Pname;
16851 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16862 -- pragma Main_Storage
16863 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16865 -- MAIN_STORAGE_OPTION ::=
16866 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16867 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
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,
16879 Gather_Associations (Names, Args);
16881 for J in 1 .. 2 loop
16882 if Present (Args (J)) then
16883 Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer);
16887 Check_In_Main_Program;
16890 while Present (Nod) loop
16891 if Nkind (Nod) = N_Pragma
16892 and then Pragma_Name (Nod) = Name_Main_Storage
16894 Error_Msg_Name_1 := Pname;
16895 Error_Msg_N ("duplicate pragma% not permitted", Nod);
16906 -- pragma Memory_Size (NUMERIC_LITERAL)
16908 when Pragma_Memory_Size =>
16911 -- Memory size is simply ignored
16913 Check_No_Identifiers;
16914 Check_Arg_Count (1);
16915 Check_Arg_Is_Integer_Literal (Arg1);
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.
16930 when Pragma_No_Body =>
16938 -- pragma No_Inline ( NAME {, NAME} );
16940 when Pragma_No_Inline =>
16942 Process_Inline (Suppressed);
16948 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16950 when Pragma_No_Return => No_Return : declare
16958 Check_At_Least_N_Arguments (1);
16960 -- Loop through arguments of pragma
16963 while Present (Arg) loop
16964 Check_Arg_Is_Local_Name (Arg);
16965 Id := Get_Pragma_Arg (Arg);
16968 if not Is_Entity_Name (Id) then
16969 Error_Pragma_Arg ("entity name required", Arg);
16972 if Etype (Id) = Any_Type then
16976 -- Loop to find matching procedures
16981 and then Scope (E) = Current_Scope
16983 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
16986 -- Set flag on any alias as well
16988 if Is_Overloadable (E) and then Present (Alias (E)) then
16989 Set_No_Return (Alias (E));
16995 exit when From_Aspect_Specification (N);
16999 -- If entity in not in current scope it may be the enclosing
17000 -- suprogram body to which the aspect applies.
17003 if Entity (Id) = Current_Scope
17004 and then From_Aspect_Specification (N)
17006 Set_No_Return (Entity (Id));
17008 Error_Pragma_Arg ("no procedure& found for pragma%", Arg);
17020 -- pragma No_Run_Time;
17022 -- Note: this pragma is retained for backwards compatibility. See
17023 -- body of Rtsfind for full details on its handling.
17025 when Pragma_No_Run_Time =>
17027 Check_Valid_Configuration_Pragma;
17028 Check_Arg_Count (0);
17030 No_Run_Time_Mode := True;
17031 Configurable_Run_Time_Mode := True;
17033 -- Set Duration to 32 bits if word size is 32
17035 if Ttypes.System_Word_Size = 32 then
17036 Duration_32_Bits_On_Target := True;
17039 -- Set appropriate restrictions
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);
17046 ------------------------
17047 -- No_Strict_Aliasing --
17048 ------------------------
17050 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17052 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
17057 Check_At_Most_N_Arguments (1);
17059 if Arg_Count = 0 then
17060 Check_Valid_Configuration_Pragma;
17061 Opt.No_Strict_Aliasing := True;
17064 Check_Optional_Identifier (Arg2, Name_Entity);
17065 Check_Arg_Is_Local_Name (Arg1);
17066 E_Id := Entity (Get_Pragma_Arg (Arg1));
17068 if E_Id = Any_Type then
17070 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
17071 Error_Pragma_Arg ("pragma% requires access type", Arg1);
17074 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
17076 end No_Strict_Aliasing;
17078 -----------------------
17079 -- Normalize_Scalars --
17080 -----------------------
17082 -- pragma Normalize_Scalars;
17084 when Pragma_Normalize_Scalars =>
17085 Check_Ada_83_Warning;
17086 Check_Arg_Count (0);
17087 Check_Valid_Configuration_Pragma;
17089 -- Normalize_Scalars creates false positives in CodePeer, and
17090 -- incorrect negative results in GNATprove mode, so ignore this
17091 -- pragma in these modes.
17093 if not (CodePeer_Mode or GNATprove_Mode) then
17094 Normalize_Scalars := True;
17095 Init_Or_Norm_Scalars := True;
17102 -- pragma Obsolescent;
17104 -- pragma Obsolescent (
17105 -- [Message =>] static_string_EXPRESSION
17106 -- [,[Version =>] Ada_05]]);
17108 -- pragma Obsolescent (
17109 -- [Entity =>] NAME
17110 -- [,[Message =>] static_string_EXPRESSION
17111 -- [,[Version =>] Ada_05]] );
17113 when Pragma_Obsolescent => Obsolescent : declare
17117 procedure Set_Obsolescent (E : Entity_Id);
17118 -- Given an entity Ent, mark it as obsolescent if appropriate
17120 ---------------------
17121 -- Set_Obsolescent --
17122 ---------------------
17124 procedure Set_Obsolescent (E : Entity_Id) is
17133 -- Entity name was given
17135 if Present (Ename) then
17137 -- If entity name matches, we are fine. Save entity in
17138 -- pragma argument, for ASIS use.
17140 if Chars (Ename) = Chars (Ent) then
17141 Set_Entity (Ename, Ent);
17142 Generate_Reference (Ent, Ename);
17144 -- If entity name does not match, only possibility is an
17145 -- enumeration literal from an enumeration type declaration.
17147 elsif Ekind (Ent) /= E_Enumeration_Type then
17149 ("pragma % entity name does not match declaration");
17152 Ent := First_Literal (E);
17156 ("pragma % entity name does not match any "
17157 & "enumeration literal");
17159 elsif Chars (Ent) = Chars (Ename) then
17160 Set_Entity (Ename, Ent);
17161 Generate_Reference (Ent, Ename);
17165 Ent := Next_Literal (Ent);
17171 -- Ent points to entity to be marked
17173 if Arg_Count >= 1 then
17175 -- Deal with static string argument
17177 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
17178 S := Strval (Get_Pragma_Arg (Arg1));
17180 for J in 1 .. String_Length (S) loop
17181 if not In_Character_Range (Get_String_Char (S, J)) then
17183 ("pragma% argument does not allow wide characters",
17188 Obsolescent_Warnings.Append
17189 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
17191 -- Check for Ada_05 parameter
17193 if Arg_Count /= 1 then
17194 Check_Arg_Count (2);
17197 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
17200 Check_Arg_Is_Identifier (Argx);
17202 if Chars (Argx) /= Name_Ada_05 then
17203 Error_Msg_Name_2 := Name_Ada_05;
17205 ("only allowed argument for pragma% is %", Argx);
17208 if Ada_Version_Explicit < Ada_2005
17209 or else not Warn_On_Ada_2005_Compatibility
17217 -- Set flag if pragma active
17220 Set_Is_Obsolescent (Ent);
17224 end Set_Obsolescent;
17226 -- Start of processing for pragma Obsolescent
17231 Check_At_Most_N_Arguments (3);
17233 -- See if first argument specifies an entity name
17237 (Chars (Arg1) = Name_Entity
17239 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
17241 N_Operator_Symbol))
17243 Ename := Get_Pragma_Arg (Arg1);
17245 -- Eliminate first argument, so we can share processing
17249 Arg_Count := Arg_Count - 1;
17251 -- No Entity name argument given
17257 if Arg_Count >= 1 then
17258 Check_Optional_Identifier (Arg1, Name_Message);
17260 if Arg_Count = 2 then
17261 Check_Optional_Identifier (Arg2, Name_Version);
17265 -- Get immediately preceding declaration
17268 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
17272 -- Cases where we do not follow anything other than another pragma
17276 -- First case: library level compilation unit declaration with
17277 -- the pragma immediately following the declaration.
17279 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
17281 (Defining_Entity (Unit (Parent (Parent (N)))));
17284 -- Case 2: library unit placement for package
17288 Ent : constant Entity_Id := Find_Lib_Unit_Name;
17290 if Is_Package_Or_Generic_Package (Ent) then
17291 Set_Obsolescent (Ent);
17297 -- Cases where we must follow a declaration
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
17306 ("pragma% misplaced, "
17307 & "must immediately follow a declaration");
17310 Set_Obsolescent (Defining_Entity (Decl));
17320 -- pragma Optimize (Time | Space | Off);
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.
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);
17331 ------------------------
17332 -- Optimize_Alignment --
17333 ------------------------
17335 -- pragma Optimize_Alignment (Time | Space | Off);
17337 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
17339 Check_No_Identifiers;
17340 Check_Arg_Count (1);
17341 Check_Valid_Configuration_Pragma;
17344 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
17348 Opt.Optimize_Alignment := 'T';
17350 Opt.Optimize_Alignment := 'S';
17352 Opt.Optimize_Alignment := 'O';
17354 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
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.
17362 Optimize_Alignment_Local := True;
17363 end Optimize_Alignment;
17369 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17371 when Pragma_Ordered => Ordered : declare
17372 Assoc : constant Node_Id := Arg1;
17378 Check_No_Identifiers;
17379 Check_Arg_Count (1);
17380 Check_Arg_Is_Local_Name (Arg1);
17382 Type_Id := Get_Pragma_Arg (Assoc);
17383 Find_Type (Type_Id);
17384 Typ := Entity (Type_Id);
17386 if Typ = Any_Type then
17389 Typ := Underlying_Type (Typ);
17392 if not Is_Enumeration_Type (Typ) then
17393 Error_Pragma ("pragma% must specify enumeration type");
17396 Check_First_Subtype (Arg1);
17397 Set_Has_Pragma_Ordered (Base_Type (Typ));
17400 -------------------
17401 -- Overflow_Mode --
17402 -------------------
17404 -- pragma Overflow_Mode
17405 -- ([General => ] MODE [, [Assertions => ] MODE]);
17407 -- MODE := STRICT | MINIMIZED | ELIMINATED
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.
17413 when Pragma_Overflow_Mode => Overflow_Mode : declare
17414 function Get_Overflow_Mode
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.
17421 -----------------------
17422 -- Get_Overflow_Mode --
17423 -----------------------
17425 function Get_Overflow_Mode
17427 Arg : Node_Id) return Overflow_Mode_Type
17429 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
17432 Check_Optional_Identifier (Arg, Name);
17433 Check_Arg_Is_Identifier (Argx);
17435 if Chars (Argx) = Name_Strict then
17438 elsif Chars (Argx) = Name_Minimized then
17441 elsif Chars (Argx) = Name_Eliminated then
17442 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
17444 ("Eliminated not implemented on this target", Argx);
17450 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
17452 end Get_Overflow_Mode;
17454 -- Start of processing for Overflow_Mode
17458 Check_At_Least_N_Arguments (1);
17459 Check_At_Most_N_Arguments (2);
17461 -- Process first argument
17463 Scope_Suppress.Overflow_Mode_General :=
17464 Get_Overflow_Mode (Name_General, Arg1);
17466 -- Case of only one argument
17468 if Arg_Count = 1 then
17469 Scope_Suppress.Overflow_Mode_Assertions :=
17470 Scope_Suppress.Overflow_Mode_General;
17472 -- Case of two arguments present
17475 Scope_Suppress.Overflow_Mode_Assertions :=
17476 Get_Overflow_Mode (Name_Assertions, Arg2);
17480 --------------------------
17481 -- Overriding Renamings --
17482 --------------------------
17484 -- pragma Overriding_Renamings;
17486 when Pragma_Overriding_Renamings =>
17488 Check_Arg_Count (0);
17489 Check_Valid_Configuration_Pragma;
17490 Overriding_Renamings := True;
17496 -- pragma Pack (first_subtype_LOCAL_NAME);
17498 when Pragma_Pack => Pack : declare
17499 Assoc : constant Node_Id := Arg1;
17503 Ignore : Boolean := False;
17506 Check_No_Identifiers;
17507 Check_Arg_Count (1);
17508 Check_Arg_Is_Local_Name (Arg1);
17509 Type_Id := Get_Pragma_Arg (Assoc);
17511 if not Is_Entity_Name (Type_Id)
17512 or else not Is_Type (Entity (Type_Id))
17515 ("argument for pragma% must be type or subtype", Arg1);
17518 Find_Type (Type_Id);
17519 Typ := Entity (Type_Id);
17522 or else Rep_Item_Too_Early (Typ, N)
17526 Typ := Underlying_Type (Typ);
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");
17533 Check_First_Subtype (Arg1);
17534 Check_Duplicate_Pragma (Typ);
17538 if Is_Array_Type (Typ) then
17539 Ctyp := Component_Type (Typ);
17541 -- Ignore pack that does nothing
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))
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.
17555 if not Rep_Item_Too_Late (Typ, N) then
17557 -- In CodePeer mode, we do not need complex front-end
17558 -- expansions related to pragma Pack, so disable handling
17561 if CodePeer_Mode then
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).
17570 elsif VM_Target /= No_VM then
17571 if not GNAT_Mode then
17573 ("??pragma% ignored in this configuration");
17576 -- Normal case where we do the pack action
17580 Set_Is_Packed (Base_Type (Typ));
17581 Set_Has_Non_Standard_Rep (Base_Type (Typ));
17584 Set_Has_Pragma_Pack (Base_Type (Typ));
17588 -- For record types, the pack is always effective
17590 else pragma Assert (Is_Record_Type (Typ));
17591 if not Rep_Item_Too_Late (Typ, N) then
17593 -- Ignore pack request with warning in VM mode (skip warning
17594 -- if we are compiling GNAT run time library).
17596 if VM_Target /= No_VM then
17597 if not GNAT_Mode then
17599 ("??pragma% ignored in this configuration");
17602 -- Normal case of pack request active
17605 Set_Is_Packed (Base_Type (Typ));
17606 Set_Has_Pragma_Pack (Base_Type (Typ));
17607 Set_Has_Non_Standard_Rep (Base_Type (Typ));
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
17623 when Pragma_Page =>
17630 -- pragma Part_Of (ABSTRACT_STATE);
17632 -- ABSTRACT_STATE ::= NAME
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.
17644 -----------------------
17645 -- Propagate_Part_Of --
17646 -----------------------
17648 procedure Propagate_Part_Of
17649 (Pack_Id : Entity_Id;
17650 State_Id : Entity_Id;
17651 Instance : Node_Id)
17653 Has_Item : Boolean := False;
17654 -- Flag set when the visible state space contains at least one
17655 -- abstract state or variable.
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.
17662 -----------------------
17663 -- Propagate_Part_Of --
17664 -----------------------
17666 procedure Propagate_Part_Of (Pack_Id : Entity_Id) is
17667 Item_Id : Entity_Id;
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.
17674 Item_Id := First_Entity (Pack_Id);
17675 while Present (Item_Id)
17676 and then not In_Private_Part (Item_Id)
17678 -- Do not consider internally generated items
17680 if not Comes_From_Source (Item_Id) then
17683 -- The Part_Of indicator turns an abstract state or
17684 -- variable into a constituent of the encapsulating
17687 elsif Ekind_In (Item_Id, E_Abstract_State,
17692 Append_Elmt (Item_Id, Part_Of_Constituents (State_Id));
17693 Set_Encapsulating_State (Item_Id, State_Id);
17695 -- Recursively handle nested packages and instantiations
17697 elsif Ekind (Item_Id) = E_Package then
17698 Propagate_Part_Of (Item_Id);
17701 Next_Entity (Item_Id);
17703 end Propagate_Part_Of;
17705 -- Start of processing for Propagate_Part_Of
17708 Propagate_Part_Of (Pack_Id);
17710 -- Detect a package instantiation that is subject to a Part_Of
17711 -- indicator, but has no visible state.
17713 if not Has_Item then
17715 ("package instantiation & has Part_Of indicator but "
17716 & "lacks visible state", Instance, Pack_Id);
17718 end Propagate_Part_Of;
17722 Item_Id : Entity_Id;
17725 State_Id : Entity_Id;
17728 -- Start of processing for Part_Of
17732 Check_Arg_Count (1);
17734 -- Ensure the proper placement of the pragma. Part_Of must appear
17735 -- on a variable declaration or a package instantiation.
17738 while Present (Stmt) loop
17740 -- Skip prior pragmas, but check for duplicates
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);
17749 -- Skip internally generated code
17751 elsif not Comes_From_Source (Stmt) then
17754 -- The pragma applies to an object declaration (possibly a
17755 -- variable) or a package instantiation. Stop the traversal
17756 -- and continue the analysis.
17758 elsif Nkind_In (Stmt, N_Object_Declaration,
17759 N_Package_Instantiation)
17763 -- The pragma does not apply to a legal construct, issue an
17764 -- error and stop the analysis.
17771 Stmt := Prev (Stmt);
17774 -- When the context is an object declaration, ensure that we are
17775 -- dealing with a variable.
17777 if Nkind (Stmt) = N_Object_Declaration
17778 and then Ekind (Defining_Entity (Stmt)) /= E_Variable
17780 SPARK_Msg_N ("indicator Part_Of must apply to a variable", N);
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.
17788 if Nkind (Stmt) = N_Package_Instantiation then
17789 Stmt := Instance_Spec (Stmt);
17792 Item_Id := Defining_Entity (Stmt);
17793 State := Get_Pragma_Arg (Arg1);
17795 -- Detect any discrepancies between the placement of the object
17796 -- or package instantiation with respect to state space and the
17797 -- encapsulating state.
17800 (Item_Id => Item_Id,
17806 State_Id := Entity (State);
17808 -- Add the pragma to the contract of the item. This aids with
17809 -- the detection of a missing but required Part_Of indicator.
17811 Add_Contract_Item (N, Item_Id);
17813 -- The Part_Of indicator turns a variable into a constituent
17814 -- of the encapsulating state.
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);
17820 -- Propagate the Part_Of indicator to the visible state space
17821 -- of the package instantiation.
17825 (Pack_Id => Item_Id,
17826 State_Id => State_Id,
17832 ----------------------------------
17833 -- Partition_Elaboration_Policy --
17834 ----------------------------------
17836 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
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;
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));
17854 when Name_Concurrent =>
17856 when Name_Sequential =>
17860 if Partition_Elaboration_Policy /= ' '
17861 and then Partition_Elaboration_Policy /= PEP
17863 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
17865 ("partition elaboration policy incompatible with policy#");
17867 -- Set new policy, but always preserve System_Location since we
17868 -- like the error message with the run time name.
17871 Partition_Elaboration_Policy := PEP;
17873 if Partition_Elaboration_Policy_Sloc /= System_Location then
17874 Partition_Elaboration_Policy_Sloc := Loc;
17883 -- pragma Passive [(PASSIVE_FORM)];
17885 -- PASSIVE_FORM ::= Semaphore | No
17887 when Pragma_Passive =>
17890 if Nkind (Parent (N)) /= N_Task_Definition then
17891 Error_Pragma ("pragma% must be within task definition");
17894 if Arg_Count /= 0 then
17895 Check_Arg_Count (1);
17896 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
17899 ----------------------------------
17900 -- Preelaborable_Initialization --
17901 ----------------------------------
17903 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17905 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
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));
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.
17921 if Has_Private_Declaration (Ent)
17922 and then From_Aspect_Specification (N)
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))
17934 ("pragma % can only be applied to private, formal derived or "
17935 & "protected type",
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).
17943 if Is_Protected_Type (Ent)
17944 and then not Has_Preelaborable_Initialization (Ent)
17947 ("protected type & does not have preelaborable "
17948 & "initialization", Ent);
17950 -- Otherwise mark the type as definitely having preelaborable
17954 Set_Known_To_Have_Preelab_Init (Ent);
17957 if Has_Pragma_Preelab_Init (Ent)
17958 and then Warn_On_Redundant_Constructs
17960 Error_Pragma ("?r?duplicate pragma%!");
17962 Set_Has_Pragma_Preelab_Init (Ent);
17966 --------------------
17967 -- Persistent_BSS --
17968 --------------------
17970 -- pragma Persistent_BSS [(object_NAME)];
17972 when Pragma_Persistent_BSS => Persistent_BSS : declare
17979 Check_At_Most_N_Arguments (1);
17981 -- Case of application to specific object (one argument)
17983 if Arg_Count = 1 then
17984 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17986 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
17988 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
17991 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
17994 Ent := Entity (Get_Pragma_Arg (Arg1));
17995 Decl := Parent (Ent);
17997 -- Check for duplication before inserting in list of
17998 -- representation items.
18000 Check_Duplicate_Pragma (Ent);
18002 if Rep_Item_Too_Late (Ent, N) then
18006 if Present (Expression (Decl)) then
18008 ("object for pragma% cannot have initialization", Arg1);
18011 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
18013 ("object type for pragma% is not potentially persistent",
18018 Make_Linker_Section_Pragma
18019 (Ent, Sloc (N), ".persistent.bss");
18020 Insert_After (N, Prag);
18023 -- Case of use as configuration pragma with no arguments
18026 Check_Valid_Configuration_Pragma;
18027 Persistent_BSS_Mode := True;
18029 end Persistent_BSS;
18035 -- pragma Polling (ON | OFF);
18037 when Pragma_Polling =>
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);
18048 -- pragma Post (Boolean_EXPRESSION);
18049 -- pragma Post_Class (Boolean_EXPRESSION);
18051 when Pragma_Post | Pragma_Post_Class => Post : declare
18052 PC_Pragma : Node_Id;
18056 Check_Arg_Count (1);
18057 Check_No_Identifiers;
18060 -- Rewrite Post[_Class] pragma as Postcondition pragma setting the
18061 -- flag Class_Present to True for the Post_Class case.
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);
18072 -------------------
18073 -- Postcondition --
18074 -------------------
18076 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18077 -- [,[Message =>] String_EXPRESSION]);
18079 when Pragma_Postcondition => Postcondition : declare
18084 Check_At_Least_N_Arguments (1);
18085 Check_At_Most_N_Arguments (2);
18086 Check_Optional_Identifier (Arg1, Name_Check);
18088 -- Verify the proper placement of the pragma. The remainder of the
18089 -- processing is found in Sem_Ch6/Sem_Ch7.
18091 Check_Precondition_Postcondition (In_Body);
18093 -- When the pragma is a source construct appearing inside a body,
18094 -- preanalyze the boolean_expression to detect illegal forward
18098 -- pragma Postcondition (X'Old ...);
18101 if Comes_From_Source (N) and then In_Body then
18102 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
18110 -- pragma Pre (Boolean_EXPRESSION);
18111 -- pragma Pre_Class (Boolean_EXPRESSION);
18113 when Pragma_Pre | Pragma_Pre_Class => Pre : declare
18114 PC_Pragma : Node_Id;
18118 Check_Arg_Count (1);
18119 Check_No_Identifiers;
18122 -- Rewrite Pre[_Class] pragma as Precondition pragma setting the
18123 -- flag Class_Present to True for the Pre_Class case.
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);
18138 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18139 -- [,[Message =>] String_EXPRESSION]);
18141 when Pragma_Precondition => Precondition : declare
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);
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.
18155 -- The form of the pragma Check is either:
18157 -- pragma Check (Precondition, cond [, msg])
18159 -- pragma Check (Pre, cond [, msg])
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.
18167 -- Rewrite as Check pragma
18171 Chars => Name_Check,
18172 Pragma_Argument_Associations => New_List (
18173 Make_Pragma_Argument_Association (Loc,
18174 Expression => Make_Identifier (Loc, Pname)),
18176 Make_Pragma_Argument_Association (Sloc (Arg1),
18178 Relocate_Node (Get_Pragma_Arg (Arg1))))));
18180 if Arg_Count = 2 then
18181 Append_To (Pragma_Argument_Associations (N),
18182 Make_Pragma_Argument_Association (Sloc (Arg2),
18184 Relocate_Node (Get_Pragma_Arg (Arg2))));
18195 -- pragma Predicate
18196 -- ([Entity =>] type_LOCAL_NAME,
18197 -- [Check =>] boolean_EXPRESSION);
18199 when Pragma_Predicate => Predicate : declare
18206 Check_Arg_Count (2);
18207 Check_Optional_Identifier (Arg1, Name_Entity);
18208 Check_Optional_Identifier (Arg2, Name_Check);
18210 Check_Arg_Is_Local_Name (Arg1);
18212 Type_Id := Get_Pragma_Arg (Arg1);
18213 Find_Type (Type_Id);
18214 Typ := Entity (Type_Id);
18216 if Typ = Any_Type then
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.
18225 Set_Has_Predicates (Typ);
18226 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
18233 -- pragma Preelaborate [(library_unit_NAME)];
18235 -- Set the flag Is_Preelaborated of program unit name entity
18237 when Pragma_Preelaborate => Preelaborate : declare
18238 Pa : constant Node_Id := Parent (N);
18239 Pk : constant Node_Kind := Nkind (Pa);
18243 Check_Ada_83_Warning;
18244 Check_Valid_Library_Unit_Pragma;
18246 if Nkind (N) = N_Null_Statement then
18250 Ent := Find_Lib_Unit_Name;
18251 Check_Duplicate_Pragma (Ent);
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.
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)
18265 if not Debug_Flag_U then
18266 Set_Is_Preelaborated (Ent);
18267 Set_Suppress_Elaboration_Warnings (Ent);
18277 -- pragma Priority (EXPRESSION);
18279 when Pragma_Priority => Priority : declare
18280 P : constant Node_Id := Parent (N);
18285 Check_No_Identifiers;
18286 Check_Arg_Count (1);
18290 if Nkind (P) = N_Subprogram_Body then
18291 Check_In_Main_Program;
18293 Ent := Defining_Unit_Name (Specification (P));
18295 if Nkind (Ent) = N_Defining_Program_Unit_Name then
18296 Ent := Defining_Identifier (Ent);
18299 Arg := Get_Pragma_Arg (Arg1);
18300 Analyze_And_Resolve (Arg, Standard_Integer);
18304 if not Is_OK_Static_Expression (Arg) then
18305 Flag_Non_Static_Expr
18306 ("main subprogram priority is not static!", Arg);
18309 -- If constraint error, then we already signalled an error
18311 elsif Raises_Constraint_Error (Arg) then
18314 -- Otherwise check in range except if Relaxed_RM_Semantics
18315 -- where we ignore the value if out of range.
18319 Val : constant Uint := Expr_Value (Arg);
18321 if not Relaxed_RM_Semantics
18324 or else Val > Expr_Value (Expression
18325 (Parent (RTE (RE_Max_Priority)))))
18328 ("main subprogram priority is out of range", Arg1);
18331 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
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.
18346 Discard : Entity_Id;
18347 pragma Warnings (Off, Discard);
18349 if Restricted_Profile then
18350 Discard := RTE (RE_Activate_Restricted_Tasks);
18352 Discard := RTE (RE_Activate_Tasks);
18356 -- Task or Protected, must be of type Integer
18358 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
18359 Arg := Get_Pragma_Arg (Arg1);
18360 Ent := Defining_Identifier (Parent (P));
18362 -- The expression must be analyzed in the special manner
18363 -- described in "Handling of Default and Per-Object
18364 -- Expressions" in sem.ads.
18366 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
18368 if not Is_Static_Expression (Arg) then
18369 Check_Restriction (Static_Priorities, Arg);
18372 -- Anything else is incorrect
18378 -- Check duplicate pragma before we chain the pragma in the Rep
18379 -- Item chain of Ent.
18381 Check_Duplicate_Pragma (Ent);
18382 Record_Rep_Item (Ent, N);
18385 -----------------------------------
18386 -- Priority_Specific_Dispatching --
18387 -----------------------------------
18389 -- pragma Priority_Specific_Dispatching (
18390 -- policy_IDENTIFIER,
18391 -- first_priority_EXPRESSION,
18392 -- last_priority_EXPRESSION);
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;
18400 Lower_Bound : Node_Id;
18401 Upper_Bound : Node_Id;
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));
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);
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);
18422 -- It is not allowed to use Task_Dispatching_Policy and
18423 -- Priority_Specific_Dispatching in the same partition.
18425 if Task_Dispatching_Policy /= ' ' then
18426 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18428 ("pragma% incompatible with Task_Dispatching_Policy#");
18430 -- Check lower bound in range
18432 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18434 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
18437 ("first_priority is out of range", Arg2);
18439 -- Check upper bound in range
18441 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
18443 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
18446 ("last_priority is out of range", Arg3);
18448 -- Check that the priority range is valid
18450 elsif Lower_Val > Upper_Val then
18452 ("last_priority_expression must be greater than or equal to "
18453 & "first_priority_expression");
18455 -- Store the new policy, but always preserve System_Location since
18456 -- we like the error message with the run-time name.
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.
18464 Specific_Dispatching.First .. Specific_Dispatching.Last
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)
18472 Specific_Dispatching.Table (J).Pragma_Loc;
18474 ("priority range overlaps with "
18475 & "Priority_Specific_Dispatching#");
18479 -- The use of Priority_Specific_Dispatching is incompatible
18480 -- with Task_Dispatching_Policy.
18482 if Task_Dispatching_Policy /= ' ' then
18483 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
18485 ("Priority_Specific_Dispatching incompatible "
18486 & "with Task_Dispatching_Policy#");
18489 -- The use of Priority_Specific_Dispatching forces ceiling
18492 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
18493 Error_Msg_Sloc := Locking_Policy_Sloc;
18495 ("Priority_Specific_Dispatching incompatible "
18496 & "with Locking_Policy#");
18498 -- Set the Ceiling_Locking policy, but preserve System_Location
18499 -- since we like the error message with the run time name.
18502 Locking_Policy := 'C';
18504 if Locking_Policy_Sloc /= System_Location then
18505 Locking_Policy_Sloc := Loc;
18509 -- Add entry in the table
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));
18517 end Priority_Specific_Dispatching;
18523 -- pragma Profile (profile_IDENTIFIER);
18525 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18527 when Pragma_Profile =>
18529 Check_Arg_Count (1);
18530 Check_Valid_Configuration_Pragma;
18531 Check_No_Identifiers;
18534 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18537 if Chars (Argx) = Name_Ravenscar then
18538 Set_Ravenscar_Profile (N);
18540 elsif Chars (Argx) = Name_Restricted then
18541 Set_Profile_Restrictions
18543 N, Warn => Treat_Restrictions_As_Warnings);
18545 elsif Chars (Argx) = Name_Rational then
18546 Set_Rational_Profile;
18548 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18549 Set_Profile_Restrictions
18550 (No_Implementation_Extensions,
18551 N, Warn => Treat_Restrictions_As_Warnings);
18554 Error_Pragma_Arg ("& is not a valid profile", Argx);
18558 ----------------------
18559 -- Profile_Warnings --
18560 ----------------------
18562 -- pragma Profile_Warnings (profile_IDENTIFIER);
18564 -- profile_IDENTIFIER => Restricted | Ravenscar
18566 when Pragma_Profile_Warnings =>
18568 Check_Arg_Count (1);
18569 Check_Valid_Configuration_Pragma;
18570 Check_No_Identifiers;
18573 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
18576 if Chars (Argx) = Name_Ravenscar then
18577 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
18579 elsif Chars (Argx) = Name_Restricted then
18580 Set_Profile_Restrictions (Restricted, N, Warn => True);
18582 elsif Chars (Argx) = Name_No_Implementation_Extensions then
18583 Set_Profile_Restrictions
18584 (No_Implementation_Extensions, N, Warn => True);
18587 Error_Pragma_Arg ("& is not a valid profile", Argx);
18591 --------------------------
18592 -- Propagate_Exceptions --
18593 --------------------------
18595 -- pragma Propagate_Exceptions;
18597 -- Note: this pragma is obsolete and has no effect
18599 when Pragma_Propagate_Exceptions =>
18601 Check_Arg_Count (0);
18603 if Warn_On_Obsolescent_Feature then
18605 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18606 "and has no effect?j?", N);
18609 -----------------------------
18610 -- Provide_Shift_Operators --
18611 -----------------------------
18613 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18615 when Pragma_Provide_Shift_Operators =>
18616 Provide_Shift_Operators : declare
18619 procedure Declare_Shift_Operator (Nam : Name_Id);
18620 -- Insert declaration and pragma Instrinsic for named shift op
18622 ----------------------------
18623 -- Declare_Shift_Operator --
18624 ----------------------------
18626 procedure Declare_Shift_Operator (Nam : Name_Id) is
18632 Make_Subprogram_Declaration (Loc,
18633 Make_Function_Specification (Loc,
18634 Defining_Unit_Name =>
18635 Make_Defining_Identifier (Loc, Chars => Nam),
18637 Result_Definition =>
18638 Make_Identifier (Loc, Chars => Chars (Ent)),
18640 Parameter_Specifications => New_List (
18641 Make_Parameter_Specification (Loc,
18642 Defining_Identifier =>
18643 Make_Defining_Identifier (Loc, Name_Value),
18645 Make_Identifier (Loc, Chars => Chars (Ent))),
18647 Make_Parameter_Specification (Loc,
18648 Defining_Identifier =>
18649 Make_Defining_Identifier (Loc, Name_Amount),
18651 New_Occurrence_Of (Standard_Natural, 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))));
18662 Insert_After (N, Import);
18663 Insert_After (N, Func);
18664 end Declare_Shift_Operator;
18666 -- Start of processing for Provide_Shift_Operators
18670 Check_Arg_Count (1);
18671 Check_Arg_Is_Local_Name (Arg1);
18673 Arg1 := Get_Pragma_Arg (Arg1);
18675 -- We must have an entity name
18677 if not Is_Entity_Name (Arg1) then
18679 ("pragma % must apply to integer first subtype", Arg1);
18682 -- If no Entity, means there was a prior error so ignore
18684 if Present (Entity (Arg1)) then
18685 Ent := Entity (Arg1);
18687 -- Apply error checks
18689 if not Is_First_Subtype (Ent) then
18691 ("cannot apply pragma %",
18692 "\& is not a first subtype",
18695 elsif not Is_Integer_Type (Ent) then
18697 ("cannot apply pragma %",
18698 "\& is not an integer type",
18701 elsif Has_Shift_Operator (Ent) then
18703 ("cannot apply pragma %",
18704 "\& already has declared shift operators",
18707 elsif Is_Frozen (Ent) then
18709 ("pragma % appears too late",
18710 "\& is already frozen",
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.
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);
18724 end Provide_Shift_Operators;
18730 -- pragma Psect_Object (
18731 -- [Internal =>] LOCAL_NAME,
18732 -- [, [External =>] EXTERNAL_SYMBOL]
18733 -- [, [Size =>] EXTERNAL_SYMBOL]);
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) := (
18743 Internal : Node_Id renames Args (1);
18744 External : Node_Id renames Args (2);
18745 Size : Node_Id renames Args (3);
18747 Def_Id : Entity_Id;
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
18754 --------------------
18755 -- Check_Too_Long --
18756 --------------------
18758 procedure Check_Too_Long (Arg : Node_Id) is
18759 X : constant Node_Id := Original_Node (Arg);
18762 if not Nkind_In (X, N_String_Literal, N_Identifier) then
18764 ("inappropriate argument for pragma %", Arg);
18767 if OpenVMS_On_Target then
18768 if (Nkind (X) = N_String_Literal
18769 and then String_Length (Strval (X)) > 31)
18771 (Nkind (X) = N_Identifier
18772 and then Length_Of_Name (Chars (X)) > 31)
18775 ("argument for pragma % is longer than 31 characters",
18779 end Check_Too_Long;
18781 -- Start of processing for Common_Object/Psect_Object
18785 Gather_Associations (Names, Args);
18786 Process_Extended_Import_Export_Internal_Arg (Internal);
18788 Def_Id := Entity (Internal);
18790 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
18792 ("pragma% must designate an object", Internal);
18795 Check_Too_Long (Internal);
18797 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
18799 ("cannot use pragma% for imported/exported object",
18803 if Is_Concurrent_Type (Etype (Internal)) then
18805 ("cannot specify pragma % for task/protected object",
18809 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
18811 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
18813 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
18816 if Ekind (Def_Id) = E_Constant then
18818 ("cannot specify pragma % for a constant", Internal);
18821 if Is_Record_Type (Etype (Internal)) then
18827 Ent := First_Entity (Etype (Internal));
18828 while Present (Ent) loop
18829 Decl := Declaration_Node (Ent);
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
18837 ("?x?object for pragma % has defaults", Internal);
18847 if Present (Size) then
18848 Check_Too_Long (Size);
18851 if Present (External) then
18852 Check_Arg_Is_External_Name (External);
18853 Check_Too_Long (External);
18856 -- If all error tests pass, link pragma on to the rep item chain
18858 Record_Rep_Item (Def_Id, N);
18865 -- pragma Pure [(library_unit_NAME)];
18867 when Pragma_Pure => Pure : declare
18871 Check_Ada_83_Warning;
18872 Check_Valid_Library_Unit_Pragma;
18874 if Nkind (N) = N_Null_Statement then
18878 Ent := Find_Lib_Unit_Name;
18880 Set_Has_Pragma_Pure (Ent);
18881 Set_Suppress_Elaboration_Warnings (Ent);
18884 -------------------
18885 -- Pure_Function --
18886 -------------------
18888 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18890 when Pragma_Pure_Function => Pure_Function : declare
18893 Def_Id : Entity_Id;
18894 Effective : Boolean := False;
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);
18903 if Error_Posted (E_Id) then
18907 -- Loop through homonyms (overloadings) of referenced entity
18909 E := Entity (E_Id);
18911 if Present (E) then
18913 Def_Id := Get_Base_Subprogram (E);
18915 if not Ekind_In (Def_Id, E_Function,
18916 E_Generic_Function,
18920 ("pragma% requires a function name", Arg1);
18923 Set_Is_Pure (Def_Id);
18925 if not Has_Pragma_Pure_Function (Def_Id) then
18926 Set_Has_Pragma_Pure_Function (Def_Id);
18930 exit when From_Aspect_Specification (N);
18932 exit when No (E) or else Scope (E) /= Current_Scope;
18936 and then Warn_On_Redundant_Constructs
18939 ("pragma Pure_Function on& is redundant?r?",
18945 --------------------
18946 -- Queuing_Policy --
18947 --------------------
18949 -- pragma Queuing_Policy (policy_IDENTIFIER);
18951 when Pragma_Queuing_Policy => declare
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));
18963 if Queuing_Policy /= ' '
18964 and then Queuing_Policy /= QP
18966 Error_Msg_Sloc := Queuing_Policy_Sloc;
18967 Error_Pragma ("queuing policy incompatible with policy#");
18969 -- Set new policy, but always preserve System_Location since we
18970 -- like the error message with the run time name.
18973 Queuing_Policy := QP;
18975 if Queuing_Policy_Sloc /= System_Location then
18976 Queuing_Policy_Sloc := Loc;
18985 -- pragma Rational, for compatibility with foreign compiler
18987 when Pragma_Rational =>
18988 Set_Rational_Profile;
18990 ------------------------------------
18991 -- Refined_Depends/Refined_Global --
18992 ------------------------------------
18994 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18996 -- DEPENDENCY_RELATION ::=
18998 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
19000 -- DEPENDENCY_CLAUSE ::=
19001 -- OUTPUT_LIST =>[+] INPUT_LIST
19002 -- | NULL_DEPENDENCY_CLAUSE
19004 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19006 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19008 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19010 -- OUTPUT ::= NAME | FUNCTION_RESULT
19013 -- where FUNCTION_RESULT is a function Result attribute_reference
19015 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19017 -- GLOBAL_SPECIFICATION ::=
19020 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
19022 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19024 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19025 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19026 -- GLOBAL_ITEM ::= NAME
19028 when Pragma_Refined_Depends |
19029 Pragma_Refined_Global => Refined_Depends_Global :
19031 Body_Id : Entity_Id;
19033 Spec_Id : Entity_Id;
19036 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
19038 -- Save the pragma in the contract of the subprogram body. The
19039 -- remaining analysis is performed at the end of the enclosing
19043 Add_Contract_Item (N, Body_Id);
19045 end Refined_Depends_Global;
19051 -- pragma Refined_Post (boolean_EXPRESSION);
19053 when Pragma_Refined_Post => Refined_Post : declare
19054 Body_Id : Entity_Id;
19056 Result_Seen : Boolean := False;
19057 Spec_Id : Entity_Id;
19060 Analyze_Refined_Pragma (Spec_Id, Body_Id, Legal);
19062 -- Analyze the boolean expression as a "spec expression"
19065 Analyze_Pre_Post_Condition_In_Decl_Part (N, Spec_Id);
19067 -- Verify that the refined postcondition mentions attribute
19068 -- 'Result and its expression introduces a post-state.
19070 if Warn_On_Suspicious_Contract
19071 and then Ekind_In (Spec_Id, E_Function, E_Generic_Function)
19073 Check_Result_And_Post_State (N, Result_Seen);
19075 if not Result_Seen then
19077 ("pragma % does not mention function result?T?");
19081 -- Chain the pragma on the contract for easy retrieval
19083 Add_Contract_Item (N, Body_Id);
19087 -------------------
19088 -- Refined_State --
19089 -------------------
19091 -- pragma Refined_State (REFINEMENT_LIST);
19093 -- REFINEMENT_LIST ::=
19094 -- REFINEMENT_CLAUSE
19095 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19097 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19099 -- CONSTITUENT_LIST ::=
19102 -- | (CONSTITUENT {, CONSTITUENT})
19104 -- CONSTITUENT ::= object_NAME | state_NAME
19106 when Pragma_Refined_State => Refined_State : declare
19107 Context : constant Node_Id := Parent (N);
19108 Spec_Id : Entity_Id;
19113 Check_Arg_Count (1);
19115 -- Ensure the proper placement of the pragma. Refined states must
19116 -- be associated with a package body.
19118 if Nkind (Context) /= N_Package_Body then
19124 while Present (Stmt) loop
19126 -- Skip prior pragmas, but check for duplicates
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);
19135 -- Skip internally generated code
19137 elsif not Comes_From_Source (Stmt) then
19140 -- The pragma does not apply to a legal construct, issue an
19141 -- error and stop the analysis.
19148 Stmt := Prev (Stmt);
19151 Spec_Id := Corresponding_Spec (Context);
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)).
19157 if SPARK_Mode /= Off
19159 (No (Abstract_States (Spec_Id))
19160 or else Has_Null_Abstract_State (Spec_Id))
19163 ("useless refinement, package & does not define abstract "
19164 & "states", N, Spec_Id);
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.
19173 Add_Contract_Item (N, Defining_Entity (Context));
19176 -----------------------
19177 -- Relative_Deadline --
19178 -----------------------
19180 -- pragma Relative_Deadline (time_span_EXPRESSION);
19182 when Pragma_Relative_Deadline => Relative_Deadline : declare
19183 P : constant Node_Id := Parent (N);
19188 Check_No_Identifiers;
19189 Check_Arg_Count (1);
19191 Arg := Get_Pragma_Arg (Arg1);
19193 -- The expression must be analyzed in the special manner described
19194 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19196 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
19200 if Nkind (P) = N_Subprogram_Body then
19201 Check_In_Main_Program;
19203 -- Only Task and subprogram cases allowed
19205 elsif Nkind (P) /= N_Task_Definition then
19209 -- Check duplicate pragma before we set the corresponding flag
19211 if Has_Relative_Deadline_Pragma (P) then
19212 Error_Pragma ("duplicate pragma% not allowed");
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.
19220 Set_Has_Relative_Deadline_Pragma (P, True);
19221 end Relative_Deadline;
19223 ------------------------
19224 -- Remote_Access_Type --
19225 ------------------------
19227 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19229 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
19234 Check_Arg_Count (1);
19235 Check_Optional_Identifier (Arg1, Name_Entity);
19236 Check_Arg_Is_Local_Name (Arg1);
19238 E := Entity (Get_Pragma_Arg (Arg1));
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)))
19245 and then Is_Valid_Remote_Object_Type
19246 (Root_Type (Directly_Designated_Type (E)))
19248 Set_Is_Remote_Types (E);
19252 ("pragma% applies only to formal access to classwide types",
19255 end Remote_Access_Type;
19257 ---------------------------
19258 -- Remote_Call_Interface --
19259 ---------------------------
19261 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19263 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
19264 Cunit_Node : Node_Id;
19265 Cunit_Ent : Entity_Id;
19269 Check_Ada_83_Warning;
19270 Check_Valid_Library_Unit_Pragma;
19272 if Nkind (N) = N_Null_Statement then
19276 Cunit_Node := Cunit (Current_Sem_Unit);
19277 K := Nkind (Unit (Cunit_Node));
19278 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
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)))
19290 "pragma% must apply to package or subprogram declaration");
19293 Set_Is_Remote_Call_Interface (Cunit_Ent);
19294 end Remote_Call_Interface;
19300 -- pragma Remote_Types [(library_unit_NAME)];
19302 when Pragma_Remote_Types => Remote_Types : declare
19303 Cunit_Node : Node_Id;
19304 Cunit_Ent : Entity_Id;
19307 Check_Ada_83_Warning;
19308 Check_Valid_Library_Unit_Pragma;
19310 if Nkind (N) = N_Null_Statement then
19314 Cunit_Node := Cunit (Current_Sem_Unit);
19315 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19317 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19318 N_Generic_Package_Declaration)
19321 ("pragma% can only apply to a package declaration");
19324 Set_Is_Remote_Types (Cunit_Ent);
19331 -- pragma Ravenscar;
19333 when Pragma_Ravenscar =>
19335 Check_Arg_Count (0);
19336 Check_Valid_Configuration_Pragma;
19337 Set_Ravenscar_Profile (N);
19339 if Warn_On_Obsolescent_Feature then
19341 ("pragma Ravenscar is an obsolescent feature?j?", N);
19343 ("|use pragma Profile (Ravenscar) instead?j?", N);
19346 -------------------------
19347 -- Restricted_Run_Time --
19348 -------------------------
19350 -- pragma Restricted_Run_Time;
19352 when Pragma_Restricted_Run_Time =>
19354 Check_Arg_Count (0);
19355 Check_Valid_Configuration_Pragma;
19356 Set_Profile_Restrictions
19357 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
19359 if Warn_On_Obsolescent_Feature then
19361 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
19364 ("|use pragma Profile (Restricted) instead?j?", N);
19371 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
19374 -- restriction_IDENTIFIER
19375 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19377 when Pragma_Restrictions =>
19378 Process_Restrictions_Or_Restriction_Warnings
19379 (Warn => Treat_Restrictions_As_Warnings);
19381 --------------------------
19382 -- Restriction_Warnings --
19383 --------------------------
19385 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
19388 -- restriction_IDENTIFIER
19389 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19391 when Pragma_Restriction_Warnings =>
19393 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
19399 -- pragma Reviewable;
19401 when Pragma_Reviewable =>
19402 Check_Ada_83_Warning;
19403 Check_Arg_Count (0);
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.
19412 --------------------------
19413 -- Short_Circuit_And_Or --
19414 --------------------------
19416 -- pragma Short_Circuit_And_Or;
19418 when Pragma_Short_Circuit_And_Or =>
19420 Check_Arg_Count (0);
19421 Check_Valid_Configuration_Pragma;
19422 Short_Circuit_And_Or := True;
19424 -------------------
19425 -- Share_Generic --
19426 -------------------
19428 -- pragma Share_Generic (GNAME {, GNAME});
19430 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
19432 when Pragma_Share_Generic =>
19434 Process_Generic_List;
19440 -- pragma Shared (LOCAL_NAME);
19442 when Pragma_Shared =>
19444 Process_Atomic_Shared_Volatile;
19446 --------------------
19447 -- Shared_Passive --
19448 --------------------
19450 -- pragma Shared_Passive [(library_unit_NAME)];
19452 -- Set the flag Is_Shared_Passive of program unit name entity
19454 when Pragma_Shared_Passive => Shared_Passive : declare
19455 Cunit_Node : Node_Id;
19456 Cunit_Ent : Entity_Id;
19459 Check_Ada_83_Warning;
19460 Check_Valid_Library_Unit_Pragma;
19462 if Nkind (N) = N_Null_Statement then
19466 Cunit_Node := Cunit (Current_Sem_Unit);
19467 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
19469 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
19470 N_Generic_Package_Declaration)
19473 ("pragma% can only apply to a package declaration");
19476 Set_Is_Shared_Passive (Cunit_Ent);
19477 end Shared_Passive;
19479 -----------------------
19480 -- Short_Descriptors --
19481 -----------------------
19483 -- pragma Short_Descriptors;
19485 when Pragma_Short_Descriptors =>
19487 Check_Arg_Count (0);
19488 Check_Valid_Configuration_Pragma;
19489 Short_Descriptors := True;
19491 ------------------------------
19492 -- Simple_Storage_Pool_Type --
19493 ------------------------------
19495 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
19497 when Pragma_Simple_Storage_Pool_Type =>
19498 Simple_Storage_Pool_Type : declare
19504 Check_Arg_Count (1);
19505 Check_Arg_Is_Library_Level_Local_Name (Arg1);
19507 Type_Id := Get_Pragma_Arg (Arg1);
19508 Find_Type (Type_Id);
19509 Typ := Entity (Type_Id);
19511 if Typ = Any_Type then
19515 -- We require the pragma to apply to a type declared in a package
19516 -- declaration, but not (immediately) within a package body.
19518 if Ekind (Current_Scope) /= E_Package
19519 or else In_Package_Body (Current_Scope)
19522 ("pragma% can only apply to type declared immediately "
19523 & "within a package declaration");
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).
19531 if Is_Record_Type (Typ)
19532 and then not Is_Limited_View (Typ)
19535 ("pragma% can only apply to explicitly limited record type");
19537 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
19539 ("pragma% can only apply to a private type that is limited");
19541 elsif not Is_Record_Type (Typ)
19542 and then not Is_Private_Type (Typ)
19545 ("pragma% can only apply to limited record or private type");
19548 Record_Rep_Item (Typ, N);
19549 end Simple_Storage_Pool_Type;
19551 ----------------------
19552 -- Source_File_Name --
19553 ----------------------
19555 -- There are five forms for this pragma:
19557 -- pragma Source_File_Name (
19558 -- [UNIT_NAME =>] unit_NAME,
19559 -- BODY_FILE_NAME => STRING_LITERAL
19560 -- [, [INDEX =>] INTEGER_LITERAL]);
19562 -- pragma Source_File_Name (
19563 -- [UNIT_NAME =>] unit_NAME,
19564 -- SPEC_FILE_NAME => STRING_LITERAL
19565 -- [, [INDEX =>] INTEGER_LITERAL]);
19567 -- pragma Source_File_Name (
19568 -- BODY_FILE_NAME => STRING_LITERAL
19569 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19570 -- [, CASING => CASING_SPEC]);
19572 -- pragma Source_File_Name (
19573 -- SPEC_FILE_NAME => STRING_LITERAL
19574 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19575 -- [, CASING => CASING_SPEC]);
19577 -- pragma Source_File_Name (
19578 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19579 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19580 -- [, CASING => CASING_SPEC]);
19582 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
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.
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.
19593 -- The only processing we defer to this point is the check for
19594 -- correct placement.
19596 when Pragma_Source_File_Name =>
19598 Check_Valid_Configuration_Pragma;
19600 ------------------------------
19601 -- Source_File_Name_Project --
19602 ------------------------------
19604 -- See Source_File_Name for syntax
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.
19610 -- The only processing we defer to this point is the check for
19611 -- correct placement.
19613 when Pragma_Source_File_Name_Project =>
19615 Check_Valid_Configuration_Pragma;
19617 -- Check that a pragma Source_File_Name_Project is used only in a
19618 -- configuration pragmas file.
19620 -- Pragmas Source_File_Name_Project should only be generated by
19621 -- the Project Manager in configuration pragmas files.
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???
19628 if Present (Parent (N)) then
19630 ("pragma% can only appear in a configuration pragmas file");
19633 ----------------------
19634 -- Source_Reference --
19635 ----------------------
19637 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19639 -- Nothing to do, all processing completed in Par.Prag, since we need
19640 -- the information for possible parser messages that are output.
19642 when Pragma_Source_Reference =>
19649 -- pragma SPARK_Mode [(On | Off)];
19651 when Pragma_SPARK_Mode => Do_SPARK_Mode : declare
19652 Body_Id : Entity_Id;
19655 Mode_Id : SPARK_Mode_Type;
19656 Spec_Id : Entity_Id;
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
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
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.
19680 procedure Check_Library_Level_Entity (E : Entity_Id);
19681 -- Verify that pragma is applied to library-level entity E
19683 ------------------------------
19684 -- Check_Pragma_Conformance --
19685 ------------------------------
19687 procedure Check_Pragma_Conformance
19688 (Context_Pragma : Node_Id;
19689 Entity_Pragma : Node_Id;
19690 Entity : Entity_Id)
19693 if Present (Context_Pragma) then
19694 pragma Assert (Nkind (Context_Pragma) = N_Pragma);
19696 -- New mode less restrictive than the established mode
19698 if Get_SPARK_Mode_From_Pragma (Context_Pragma) = Off
19699 and then Mode_Id = On
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);
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
19714 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19715 Error_Msg_Sloc := Sloc (Entity_Pragma);
19717 ("\value Off was set for SPARK_Mode on&#",
19723 Error_Msg_N ("incorrect use of SPARK_Mode", Arg1);
19724 Error_Msg_Sloc := Sloc (Entity);
19726 ("\no value was set for SPARK_Mode on&#",
19731 end Check_Pragma_Conformance;
19733 --------------------------------
19734 -- Check_Library_Level_Entity --
19735 --------------------------------
19737 procedure Check_Library_Level_Entity (E : Entity_Id) is
19738 MsgF : constant String := "incorrect placement of pragma%";
19741 if not Is_Library_Level_Entity (E) then
19742 Error_Msg_Name_1 := Pname;
19743 Error_Msg_N (Fix_Error (MsgF), N);
19745 if Ekind_In (E, E_Generic_Package,
19750 ("\& is not a library-level package", N, E);
19753 ("\& is not a library-level subprogram", N, E);
19758 end Check_Library_Level_Entity;
19760 -- Start of processing for Do_SPARK_Mode
19764 Check_No_Identifiers;
19765 Check_At_Most_N_Arguments (1);
19767 -- Check the legality of the mode (no argument = ON)
19769 if Arg_Count = 1 then
19770 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
19771 Mode := Chars (Get_Pragma_Arg (Arg1));
19776 Mode_Id := Get_SPARK_Mode_Type (Mode);
19777 Context := Parent (N);
19779 -- Packages and subprograms declared in a generic unit cannot be
19780 -- subject to the pragma.
19782 if Inside_A_Generic then
19783 Error_Pragma ("incorrect placement of pragma% in a generic");
19785 -- The pragma appears in a configuration pragmas file
19787 elsif No (Context) then
19788 Check_Valid_Configuration_Pragma;
19790 if Present (SPARK_Mode_Pragma) then
19791 Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma);
19792 Error_Msg_N ("pragma% duplicates pragma declared#", N);
19796 SPARK_Mode_Pragma := N;
19797 SPARK_Mode := Mode_Id;
19799 -- When the pragma is placed before the declaration of a unit, it
19800 -- configures the whole unit.
19802 elsif Nkind (Context) = N_Compilation_Unit then
19803 Check_Valid_Configuration_Pragma;
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)
19810 Error_Pragma ("incorrect placement of pragma% in a generic");
19813 SPARK_Mode_Pragma := N;
19814 SPARK_Mode := Mode_Id;
19816 -- The pragma applies to a [library unit] subprogram or package
19819 -- Verify the placement of the pragma with respect to package
19820 -- or subprogram declarations and detect duplicates.
19823 while Present (Stmt) loop
19825 -- Skip prior pragmas, but check for duplicates
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);
19835 elsif Nkind (Stmt) in N_Generic_Declaration then
19837 ("incorrect placement of pragma% on a generic");
19839 -- The pragma applies to a package declaration
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,
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);
19855 -- The pragma applies to a subprogram declaration
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,
19865 Set_SPARK_Pragma (Spec_Id, N);
19866 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19869 -- Skip internally generated code
19871 elsif not Comes_From_Source (Stmt) then
19874 -- The pragma does not apply to a legal construct, issue an
19875 -- error and stop the analysis.
19882 Stmt := Prev (Stmt);
19885 -- Handle all cases where the pragma is actually an aspect and
19886 -- applies to a library-level package spec, body or subprogram.
19888 -- function F ... with SPARK_Mode => ...;
19889 -- package P with SPARK_Mode => ...;
19890 -- package body P with SPARK_Mode => ... is
19892 -- The following circuitry simply prepares the proper context
19893 -- for the general pragma processing mechanism below.
19895 if Nkind (Context) = N_Compilation_Unit_Aux then
19896 Context := Unit (Parent (Context));
19898 if Nkind_In (Context, N_Package_Declaration,
19899 N_Subprogram_Declaration)
19901 Context := Specification (Context);
19905 -- The pragma is at the top level of a package spec
19908 -- pragma SPARK_Mode;
19915 -- pragma SPARK_Mode;
19917 if Nkind (Context) = N_Package_Specification then
19918 Spec_Id := Defining_Entity (Context);
19920 -- Pragma applies to private part
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;
19931 Set_SPARK_Aux_Pragma (Spec_Id, N);
19932 Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False);
19934 -- Pragma applies to public part
19937 Check_Library_Level_Entity (Spec_Id);
19938 Check_Pragma_Conformance
19939 (Context_Pragma => SPARK_Pragma (Spec_Id),
19940 Entity_Pragma => Empty,
19942 SPARK_Mode_Pragma := N;
19943 SPARK_Mode := Mode_Id;
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);
19951 -- The pragma appears as an aspect on a subprogram.
19953 -- function F ... with SPARK_Mode => ...;
19955 elsif Nkind_In (Context, N_Function_Specification,
19956 N_Procedure_Specification)
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,
19964 Set_SPARK_Pragma (Spec_Id, N);
19965 Set_SPARK_Pragma_Inherited (Spec_Id, False);
19967 -- Pragma is immediately within a package body
19969 -- package body P is
19970 -- pragma SPARK_Mode;
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;
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);
19988 -- Pragma is immediately within a subprogram body
19990 -- function F ... is
19991 -- pragma SPARK_Mode;
19993 elsif Nkind (Context) = N_Subprogram_Body then
19994 Spec_Id := Corresponding_Spec (Context);
19995 Context := Specification (Context);
19996 Body_Id := Defining_Entity (Context);
19998 -- Ignore pragma when applied to the special body created
19999 -- for inlining, recognized by its internal name _Parent.
20001 if Chars (Body_Id) = Name_uParent then
20005 Check_Library_Level_Entity (Body_Id);
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);
20013 Check_Pragma_Conformance
20014 (Context_Pragma => SPARK_Pragma (Body_Id),
20015 Entity_Pragma => Empty,
20019 SPARK_Mode_Pragma := N;
20020 SPARK_Mode := Mode_Id;
20022 Set_SPARK_Pragma (Body_Id, N);
20023 Set_SPARK_Pragma_Inherited (Body_Id, False);
20025 -- The pragma applies to the statements of a package body
20027 -- package body P is
20029 -- pragma SPARK_Mode;
20031 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements
20032 and then Nkind (Parent (Context)) = N_Package_Body
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;
20045 Set_SPARK_Aux_Pragma (Body_Id, N);
20046 Set_SPARK_Aux_Pragma_Inherited (Body_Id, False);
20048 -- The pragma does not apply to a legal construct, issue error
20056 --------------------------------
20057 -- Static_Elaboration_Desired --
20058 --------------------------------
20060 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
20062 when Pragma_Static_Elaboration_Desired =>
20064 Check_At_Most_N_Arguments (1);
20066 if Is_Compilation_Unit (Current_Scope)
20067 and then Ekind (Current_Scope) = E_Package
20069 Set_Static_Elaboration_Desired (Current_Scope, True);
20071 Error_Pragma ("pragma% must apply to a library-level package");
20078 -- pragma Storage_Size (EXPRESSION);
20080 when Pragma_Storage_Size => Storage_Size : declare
20081 P : constant Node_Id := Parent (N);
20085 Check_No_Identifiers;
20086 Check_Arg_Count (1);
20088 -- The expression must be analyzed in the special manner described
20089 -- in "Handling of Default Expressions" in sem.ads.
20091 Arg := Get_Pragma_Arg (Arg1);
20092 Preanalyze_Spec_Expression (Arg, Any_Integer);
20094 if not Is_OK_Static_Expression (Arg) then
20095 Check_Restriction (Static_Storage_Size, Arg);
20098 if Nkind (P) /= N_Task_Definition then
20103 if Has_Storage_Size_Pragma (P) then
20104 Error_Pragma ("duplicate pragma% not allowed");
20106 Set_Has_Storage_Size_Pragma (P, True);
20109 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
20117 -- pragma Storage_Unit (NUMERIC_LITERAL);
20119 -- Only permitted argument is System'Storage_Unit value
20121 when Pragma_Storage_Unit =>
20122 Check_No_Identifiers;
20123 Check_Arg_Count (1);
20124 Check_Arg_Is_Integer_Literal (Arg1);
20126 if Intval (Get_Pragma_Arg (Arg1)) /=
20127 UI_From_Int (Ttypes.System_Storage_Unit)
20129 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
20131 ("the only allowed argument for pragma% is ^", Arg1);
20134 --------------------
20135 -- Stream_Convert --
20136 --------------------
20138 -- pragma Stream_Convert (
20139 -- [Entity =>] type_LOCAL_NAME,
20140 -- [Read =>] function_NAME,
20141 -- [Write =>] function NAME);
20143 when Pragma_Stream_Convert => Stream_Convert : declare
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.
20151 --------------------------------------
20152 -- Check_OK_Stream_Convert_Function --
20153 --------------------------------------
20155 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
20159 Check_Arg_Is_Local_Name (Arg);
20160 Ent := Entity (Get_Pragma_Arg (Arg));
20162 if Has_Homonym (Ent) then
20164 ("argument for pragma% may not be overloaded", Arg);
20167 if Ekind (Ent) /= E_Function
20168 or else No (First_Formal (Ent))
20169 or else Present (Next_Formal (First_Formal (Ent)))
20172 ("argument for pragma% must be function of one argument",
20175 end Check_OK_Stream_Convert_Function;
20177 -- Start of processing for Stream_Convert
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);
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));
20197 Check_First_Subtype (Arg1);
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.
20206 if Rep_Item_Too_Early (Typ, N)
20208 Rep_Item_Too_Late (Typ, N, FOnly => True)
20213 -- Return if previous error
20215 if Etype (Typ) = Any_Type
20217 Etype (Read) = Any_Type
20219 Etype (Write) = Any_Type
20226 if Underlying_Type (Etype (Read)) /= Typ then
20228 ("incorrect return type for function&", Arg2);
20231 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
20233 ("incorrect parameter type for function&", Arg3);
20236 if Underlying_Type (Etype (First_Formal (Read))) /=
20237 Underlying_Type (Etype (Write))
20240 ("result type of & does not match Read parameter type",
20244 end Stream_Convert;
20250 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
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.
20256 when Pragma_Style_Checks => Style_Checks : declare
20257 A : constant Node_Id := Get_Pragma_Arg (Arg1);
20263 Check_No_Identifiers;
20265 -- Two argument form
20267 if Arg_Count = 2 then
20268 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
20275 E_Id := Get_Pragma_Arg (Arg2);
20278 if not Is_Entity_Name (E_Id) then
20280 ("second argument of pragma% must be entity name",
20284 E := Entity (E_Id);
20286 if not Ignore_Style_Checks_Pragmas then
20291 Set_Suppress_Style_Checks
20292 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
20293 exit when No (Homonym (E));
20300 -- One argument form
20303 Check_Arg_Count (1);
20305 if Nkind (A) = N_String_Literal then
20309 Slen : constant Natural := Natural (String_Length (S));
20310 Options : String (1 .. Slen);
20316 C := Get_String_Char (S, Int (J));
20317 exit when not In_Character_Range (C);
20318 Options (J) := Get_Character (C);
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.
20325 if not Ignore_Style_Checks_Pragmas then
20326 Set_Style_Check_Options (Options);
20336 elsif Nkind (A) = N_Identifier then
20337 if Chars (A) = Name_All_Checks then
20338 if not Ignore_Style_Checks_Pragmas then
20340 Set_GNAT_Style_Check_Options;
20342 Set_Default_Style_Check_Options;
20346 elsif Chars (A) = Name_On then
20347 if not Ignore_Style_Checks_Pragmas then
20348 Style_Check := True;
20351 elsif Chars (A) = Name_Off then
20352 if not Ignore_Style_Checks_Pragmas then
20353 Style_Check := False;
20364 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
20366 when Pragma_Subtitle =>
20368 Check_Arg_Count (1);
20369 Check_Optional_Identifier (Arg1, Name_Subtitle);
20370 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String);
20377 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
20379 when Pragma_Suppress =>
20380 Process_Suppress_Unsuppress (True);
20386 -- pragma Suppress_All;
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).
20394 when Pragma_Suppress_All =>
20396 Check_Arg_Count (0);
20398 -------------------------
20399 -- Suppress_Debug_Info --
20400 -------------------------
20402 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
20404 when Pragma_Suppress_Debug_Info =>
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)));
20411 ----------------------------------
20412 -- Suppress_Exception_Locations --
20413 ----------------------------------
20415 -- pragma Suppress_Exception_Locations;
20417 when Pragma_Suppress_Exception_Locations =>
20419 Check_Arg_Count (0);
20420 Check_Valid_Configuration_Pragma;
20421 Exception_Locations_Suppressed := True;
20423 -----------------------------
20424 -- Suppress_Initialization --
20425 -----------------------------
20427 -- pragma Suppress_Initialization ([Entity =>] type_Name);
20429 when Pragma_Suppress_Initialization => Suppress_Init : declare
20435 Check_Arg_Count (1);
20436 Check_Optional_Identifier (Arg1, Name_Entity);
20437 Check_Arg_Is_Local_Name (Arg1);
20439 E_Id := Get_Pragma_Arg (Arg1);
20441 if Etype (E_Id) = Any_Type then
20445 E := Entity (E_Id);
20447 if not Is_Type (E) then
20448 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
20451 if Rep_Item_Too_Early (E, N)
20453 Rep_Item_Too_Late (E, N, FOnly => True)
20458 -- For incomplete/private type, set flag on full view
20460 if Is_Incomplete_Or_Private_Type (E) then
20461 if No (Full_View (Base_Type (E))) then
20463 ("argument of pragma% cannot be an incomplete type", Arg1);
20465 Set_Suppress_Initialization (Full_View (Base_Type (E)));
20468 -- For first subtype, set flag on base type
20470 elsif Is_First_Subtype (E) then
20471 Set_Suppress_Initialization (Base_Type (E));
20473 -- For other than first subtype, set flag on subtype itself
20476 Set_Suppress_Initialization (E);
20484 -- pragma System_Name (DIRECT_NAME);
20486 -- Syntax check: one argument, which must be the identifier GNAT or
20487 -- the identifier GCC, no other identifiers are acceptable.
20489 when Pragma_System_Name =>
20491 Check_No_Identifiers;
20492 Check_Arg_Count (1);
20493 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
20495 -----------------------------
20496 -- Task_Dispatching_Policy --
20497 -----------------------------
20499 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
20501 when Pragma_Task_Dispatching_Policy => declare
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));
20513 if Task_Dispatching_Policy /= ' '
20514 and then Task_Dispatching_Policy /= DP
20516 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
20518 ("task dispatching policy incompatible with policy#");
20520 -- Set new policy, but always preserve System_Location since we
20521 -- like the error message with the run time name.
20524 Task_Dispatching_Policy := DP;
20526 if Task_Dispatching_Policy_Sloc /= System_Location then
20527 Task_Dispatching_Policy_Sloc := Loc;
20536 -- pragma Task_Info (EXPRESSION);
20538 when Pragma_Task_Info => Task_Info : declare
20539 P : constant Node_Id := Parent (N);
20545 if Warn_On_Obsolescent_Feature then
20547 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20548 & "instead?j?", N);
20551 if Nkind (P) /= N_Task_Definition then
20552 Error_Pragma ("pragma% must appear in task definition");
20555 Check_No_Identifiers;
20556 Check_Arg_Count (1);
20558 Analyze_And_Resolve
20559 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
20561 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
20565 Ent := Defining_Identifier (Parent (P));
20567 -- Check duplicate pragma before we chain the pragma in the Rep
20568 -- Item chain of Ent.
20571 (Ent, Name_Task_Info, Check_Parents => False)
20573 Error_Pragma ("duplicate pragma% not allowed");
20576 Record_Rep_Item (Ent, N);
20583 -- pragma Task_Name (string_EXPRESSION);
20585 when Pragma_Task_Name => Task_Name : declare
20586 P : constant Node_Id := Parent (N);
20591 Check_No_Identifiers;
20592 Check_Arg_Count (1);
20594 Arg := Get_Pragma_Arg (Arg1);
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.
20601 Preanalyze_And_Resolve (Arg, Standard_String);
20603 if Nkind (P) /= N_Task_Definition then
20607 Ent := Defining_Identifier (Parent (P));
20609 -- Check duplicate pragma before we chain the pragma in the Rep
20610 -- Item chain of Ent.
20613 (Ent, Name_Task_Name, Check_Parents => False)
20615 Error_Pragma ("duplicate pragma% not allowed");
20618 Record_Rep_Item (Ent, N);
20625 -- pragma Task_Storage (
20626 -- [Task_Type =>] LOCAL_NAME,
20627 -- [Top_Guard =>] static_integer_EXPRESSION);
20629 when Pragma_Task_Storage => Task_Storage : declare
20630 Args : Args_List (1 .. 2);
20631 Names : constant Name_List (1 .. 2) := (
20635 Task_Type : Node_Id renames Args (1);
20636 Top_Guard : Node_Id renames Args (2);
20642 Gather_Associations (Names, Args);
20644 if No (Task_Type) then
20646 ("missing task_type argument for pragma%");
20649 Check_Arg_Is_Local_Name (Task_Type);
20651 Ent := Entity (Task_Type);
20653 if not Is_Task_Type (Ent) then
20655 ("argument for pragma% must be task type", Task_Type);
20658 if No (Top_Guard) then
20660 ("pragma% takes two arguments", Task_Type);
20662 Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer);
20665 Check_First_Subtype (Task_Type);
20667 if Rep_Item_Too_Late (Ent, N) then
20676 -- pragma Test_Case
20677 -- ([Name =>] Static_String_EXPRESSION
20678 -- ,[Mode =>] MODE_TYPE
20679 -- [, Requires => Boolean_EXPRESSION]
20680 -- [, Ensures => Boolean_EXPRESSION]);
20682 -- MODE_TYPE ::= Nominal | Robustness
20684 when Pragma_Test_Case =>
20688 --------------------------
20689 -- Thread_Local_Storage --
20690 --------------------------
20692 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20694 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
20700 Check_Arg_Count (1);
20701 Check_Optional_Identifier (Arg1, Name_Entity);
20702 Check_Arg_Is_Library_Level_Local_Name (Arg1);
20704 Id := Get_Pragma_Arg (Arg1);
20707 if not Is_Entity_Name (Id)
20708 or else Ekind (Entity (Id)) /= E_Variable
20710 Error_Pragma_Arg ("local variable name required", Arg1);
20715 if Rep_Item_Too_Early (E, N)
20716 or else Rep_Item_Too_Late (E, N)
20721 Set_Has_Pragma_Thread_Local_Storage (E);
20722 Set_Has_Gigi_Rep_Item (E);
20723 end Thread_Local_Storage;
20729 -- pragma Time_Slice (static_duration_EXPRESSION);
20731 when Pragma_Time_Slice => Time_Slice : declare
20737 Check_Arg_Count (1);
20738 Check_No_Identifiers;
20739 Check_In_Main_Program;
20740 Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration);
20742 if not Error_Posted (Arg1) then
20744 while Present (Nod) loop
20745 if Nkind (Nod) = N_Pragma
20746 and then Pragma_Name (Nod) = Name_Time_Slice
20748 Error_Msg_Name_1 := Pname;
20749 Error_Msg_N ("duplicate pragma% not permitted", Nod);
20756 -- Process only if in main unit
20758 if Get_Source_Unit (Loc) = Main_Unit then
20759 Opt.Time_Slice_Set := True;
20760 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
20762 if Val <= Ureal_0 then
20763 Opt.Time_Slice_Value := 0;
20765 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
20766 Opt.Time_Slice_Value := 1_000_000_000;
20769 Opt.Time_Slice_Value :=
20770 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
20779 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20781 -- TITLING_OPTION ::=
20782 -- [Title =>] STRING_LITERAL
20783 -- | [Subtitle =>] STRING_LITERAL
20785 when Pragma_Title => Title : declare
20786 Args : Args_List (1 .. 2);
20787 Names : constant Name_List (1 .. 2) := (
20793 Gather_Associations (Names, Args);
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);
20804 ----------------------------
20805 -- Type_Invariant[_Class] --
20806 ----------------------------
20808 -- pragma Type_Invariant[_Class]
20809 -- ([Entity =>] type_LOCAL_NAME,
20810 -- [Check =>] EXPRESSION);
20812 when Pragma_Type_Invariant |
20813 Pragma_Type_Invariant_Class =>
20814 Type_Invariant : declare
20815 I_Pragma : Node_Id;
20818 Check_Arg_Count (2);
20820 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20821 -- setting Class_Present for the Type_Invariant_Class case.
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);
20830 end Type_Invariant;
20832 ---------------------
20833 -- Unchecked_Union --
20834 ---------------------
20836 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20838 when Pragma_Unchecked_Union => Unchecked_Union : declare
20839 Assoc : constant Node_Id := Arg1;
20840 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
20850 Check_No_Identifiers;
20851 Check_Arg_Count (1);
20852 Check_Arg_Is_Local_Name (Arg1);
20854 Find_Type (Type_Id);
20856 Typ := Entity (Type_Id);
20859 or else Rep_Item_Too_Early (Typ, N)
20863 Typ := Underlying_Type (Typ);
20866 if Rep_Item_Too_Late (Typ, N) then
20870 Check_First_Subtype (Arg1);
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.
20876 if not Is_Record_Type (Typ) then
20877 Error_Msg_N ("unchecked union must be record type", Typ);
20880 elsif Is_Tagged_Type (Typ) then
20881 Error_Msg_N ("unchecked union must not be tagged", Typ);
20884 elsif not Has_Discriminants (Typ) then
20886 ("unchecked union must have one discriminant", Typ);
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.
20893 -- Similarly, GNAT used to require that all discriminants have
20894 -- default values, but this is not mandated by the RM.
20896 -- Proceed with basic error checks completed
20899 Tdef := Type_Definition (Declaration_Node (Typ));
20900 Clist := Component_List (Tdef);
20902 -- Check presence of component list and variant part
20904 if No (Clist) or else No (Variant_Part (Clist)) then
20906 ("unchecked union must have variant part", Tdef);
20910 -- Check components
20912 Comp := First (Component_Items (Clist));
20913 while Present (Comp) loop
20914 Check_Component (Comp, Typ);
20918 -- Check variant part
20920 Vpart := Variant_Part (Clist);
20922 Variant := First (Variants (Vpart));
20923 while Present (Variant) loop
20924 Check_Variant (Variant, Typ);
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;
20935 ------------------------
20936 -- Unimplemented_Unit --
20937 ------------------------
20939 -- pragma Unimplemented_Unit;
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).
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 :=
20953 Check_Arg_Count (0);
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
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");
20965 raise Unrecoverable_Error;
20967 end Unimplemented_Unit;
20969 ------------------------
20970 -- Universal_Aliasing --
20971 ------------------------
20973 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20975 when Pragma_Universal_Aliasing => Universal_Alias : declare
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));
20985 if E_Id = Any_Type then
20987 elsif No (E_Id) or else not Is_Type (E_Id) then
20988 Error_Pragma_Arg ("pragma% requires type", Arg1);
20991 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
20992 Record_Rep_Item (E_Id, N);
20993 end Universal_Alias;
20995 --------------------
20996 -- Universal_Data --
20997 --------------------
20999 -- pragma Universal_Data [(library_unit_NAME)];
21001 when Pragma_Universal_Data =>
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).
21010 if Is_Configuration_Pragma then
21011 Universal_Addressing_On_AAMP := True;
21013 Check_Valid_Library_Unit_Pragma;
21016 if not AAMP_On_Target then
21017 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
21024 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
21026 when Pragma_Unmodified => Unmodified : declare
21027 Arg_Node : Node_Id;
21028 Arg_Expr : Node_Id;
21029 Arg_Ent : Entity_Id;
21033 Check_At_Least_N_Arguments (1);
21035 -- Loop through arguments
21038 while Present (Arg_Node) loop
21039 Check_No_Identifier (Arg_Node);
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.
21049 Check_Arg_Is_Local_Name (Arg_Node);
21050 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21052 if Is_Entity_Name (Arg_Expr) then
21053 Arg_Ent := Entity (Arg_Expr);
21055 if not Is_Assignable (Arg_Ent) then
21057 ("pragma% can only be applied to a variable",
21060 Set_Has_Pragma_Unmodified (Arg_Ent);
21072 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
21074 -- or when used in a context clause:
21076 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
21078 when Pragma_Unreferenced => Unreferenced : declare
21079 Arg_Node : Node_Id;
21080 Arg_Expr : Node_Id;
21081 Arg_Ent : Entity_Id;
21086 Check_At_Least_N_Arguments (1);
21088 -- Check case of appearing within context clause
21090 if Is_In_Context_Clause then
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.
21098 while Present (Arg_Node) loop
21099 Citem := First (List_Containing (N));
21100 while Citem /= N loop
21101 if Nkind (Citem) = N_With_Clause
21103 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
21105 Set_Has_Pragma_Unreferenced
21108 (Library_Unit (Citem))));
21110 (Get_Pragma_Arg (Arg_Node), Name (Citem));
21119 ("argument of pragma% is not withed unit", Arg_Node);
21125 -- Case of not in list of context items
21129 while Present (Arg_Node) loop
21130 Check_No_Identifier (Arg_Node);
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.
21140 Check_Arg_Is_Local_Name (Arg_Node);
21141 Arg_Expr := Get_Pragma_Arg (Arg_Node);
21143 if Is_Entity_Name (Arg_Expr) then
21144 Arg_Ent := Entity (Arg_Expr);
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.
21151 if Is_Overloaded (Arg_Expr) then
21152 Generate_Reference (Arg_Ent, N);
21155 Set_Has_Pragma_Unreferenced (Arg_Ent);
21163 --------------------------
21164 -- Unreferenced_Objects --
21165 --------------------------
21167 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
21169 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
21170 Arg_Node : Node_Id;
21171 Arg_Expr : Node_Id;
21175 Check_At_Least_N_Arguments (1);
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);
21183 if not Is_Entity_Name (Arg_Expr)
21184 or else not Is_Type (Entity (Arg_Expr))
21187 ("argument for pragma% must be type or subtype", Arg_Node);
21190 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
21193 end Unreferenced_Objects;
21195 ------------------------------
21196 -- Unreserve_All_Interrupts --
21197 ------------------------------
21199 -- pragma Unreserve_All_Interrupts;
21201 when Pragma_Unreserve_All_Interrupts =>
21203 Check_Arg_Count (0);
21205 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
21206 Unreserve_All_Interrupts := True;
21213 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
21215 when Pragma_Unsuppress =>
21217 Process_Suppress_Unsuppress (False);
21219 ----------------------------
21220 -- Unevaluated_Use_Of_Old --
21221 ----------------------------
21223 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
21225 when Pragma_Unevaluated_Use_Of_Old =>
21227 Check_Arg_Count (1);
21228 Check_No_Identifiers;
21229 Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow);
21231 -- Suppress/Unsuppress can appear as a configuration pragma, or in
21232 -- a declarative part or a package spec.
21234 if not Is_Configuration_Pragma then
21235 Check_Is_In_Decl_Part_Or_Package_Spec;
21238 -- Store proper setting of Uneval_Old
21240 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
21241 Uneval_Old := Fold_Upper (Name_Buffer (1));
21243 -------------------
21244 -- Use_VADS_Size --
21245 -------------------
21247 -- pragma Use_VADS_Size;
21249 when Pragma_Use_VADS_Size =>
21251 Check_Arg_Count (0);
21252 Check_Valid_Configuration_Pragma;
21253 Use_VADS_Size := True;
21255 ---------------------
21256 -- Validity_Checks --
21257 ---------------------
21259 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21261 when Pragma_Validity_Checks => Validity_Checks : declare
21262 A : constant Node_Id := Get_Pragma_Arg (Arg1);
21268 Check_Arg_Count (1);
21269 Check_No_Identifiers;
21271 -- Pragma always active unless in CodePeer or GNATprove modes,
21272 -- which use a fixed configuration of validity checks.
21274 if not (CodePeer_Mode or GNATprove_Mode) then
21275 if Nkind (A) = N_String_Literal then
21279 Slen : constant Natural := Natural (String_Length (S));
21280 Options : String (1 .. Slen);
21284 -- Couldn't we use a for loop here over Options'Range???
21288 C := Get_String_Char (S, Int (J));
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 ???
21294 exit when not In_Character_Range (C);
21295 Options (J) := Get_Character (C);
21298 Set_Validity_Check_Options (Options);
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;
21316 end Validity_Checks;
21322 -- pragma Volatile (LOCAL_NAME);
21324 when Pragma_Volatile =>
21325 Process_Atomic_Shared_Volatile;
21327 -------------------------
21328 -- Volatile_Components --
21329 -------------------------
21331 -- pragma Volatile_Components (array_LOCAL_NAME);
21333 -- Volatile is handled by the same circuit as Atomic_Components
21335 ----------------------
21336 -- Warning_As_Error --
21337 ----------------------
21339 when Pragma_Warning_As_Error =>
21341 Check_Arg_Count (1);
21342 Check_No_Identifiers;
21343 Check_Valid_Configuration_Pragma;
21345 if not Is_Static_String_Expression (Arg1) then
21347 ("argument of pragma% must be static string expression",
21350 -- OK static string expression
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));
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]);
21368 -- REASON ::= Reason => Static_String_Expression
21370 when Pragma_Warnings => Warnings : declare
21371 Reason : String_Id;
21375 Check_At_Least_N_Arguments (1);
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).
21383 Last_Arg : constant Node_Id :=
21384 Last (Pragma_Argument_Associations (N));
21387 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21388 and then Chars (Last_Arg) = Name_Reason
21391 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21392 Reason := End_String;
21393 Arg_Count := Arg_Count - 1;
21395 -- Not allowed in compiler units (bootstrap issues)
21397 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21399 -- No REASON string, set null string as reason
21402 Reason := Null_String_Id;
21406 -- Now proceed with REASON taken care of and eliminated
21408 Check_No_Identifiers;
21410 -- If debug flag -gnatd.i is set, pragma is ignored
21412 if Debug_Flag_Dot_I then
21416 -- Process various forms of the pragma
21419 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21422 -- One argument case
21424 if Arg_Count = 1 then
21426 -- On/Off one argument case was processed by parser
21428 if Nkind (Argx) = N_Identifier
21429 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21433 -- One argument case must be ON/OFF or static string expr
21435 elsif not Is_Static_String_Expression (Arg1) then
21437 ("argument of pragma% must be On/Off or static string "
21438 & "expression", Arg1);
21440 -- One argument string expression case
21444 Lit : constant Node_Id := Expr_Value_S (Argx);
21445 Str : constant String_Id := Strval (Lit);
21446 Len : constant Nat := String_Length (Str);
21454 while J <= Len loop
21455 C := Get_String_Char (Str, J);
21456 OK := In_Character_Range (C);
21459 Chr := Get_Character (C);
21461 -- Dash case: only -Wxxx is accepted
21468 C := Get_String_Char (Str, J);
21469 Chr := Get_Character (C);
21470 exit when Chr = 'W';
21475 elsif J < Len and then Chr = '.' then
21477 C := Get_String_Char (Str, J);
21478 Chr := Get_Character (C);
21480 if not Set_Dot_Warning_Switch (Chr) then
21482 ("invalid warning switch character "
21483 & '.' & Chr, Arg1);
21489 OK := Set_Warning_Switch (Chr);
21495 ("invalid warning switch character " & Chr,
21504 -- Two or more arguments (must be two)
21507 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21508 Check_Arg_Count (2);
21516 E_Id := Get_Pragma_Arg (Arg2);
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.
21523 if (In_Instance_Body or In_Inlined_Body)
21524 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21526 E_Id := Expression (E_Id);
21529 -- Entity name case
21531 if Is_Entity_Name (E_Id) then
21532 E := Entity (E_Id);
21539 (E, (Chars (Get_Pragma_Arg (Arg1)) =
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.
21548 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21549 and then Warn_On_Warnings_Off
21550 and then not In_Instance
21552 Warnings_Off_Pragmas.Append ((N, E, Reason));
21555 if Is_Enumeration_Type (E) then
21559 Lit := First_Literal (E);
21560 while Present (Lit) loop
21561 Set_Warnings_Off (Lit);
21562 Next_Literal (Lit);
21567 exit when No (Homonym (E));
21572 -- Error if not entity or static string expression case
21574 elsif not Is_Static_String_Expression (Arg2) then
21576 ("second argument of pragma% must be entity name "
21577 & "or static string expression", Arg2);
21579 -- Static string expression case
21582 Acquire_Warning_Match_String (Arg2);
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).
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.
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.
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);
21609 elsif Chars (Argx) = Name_On then
21610 Set_Specific_Warning_On
21611 (Loc, Name_Buffer (1 .. Name_Len), Err);
21615 ("??pragma Warnings On with no matching "
21616 & "Warnings Off", Loc);
21625 -------------------
21626 -- Weak_External --
21627 -------------------
21629 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21631 when Pragma_Weak_External => Weak_External : declare
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));
21641 if Rep_Item_Too_Early (Ent, N) then
21644 Ent := Underlying_Type (Ent);
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).
21652 if Rep_Item_Too_Late (Ent, N) then
21655 Set_Has_Gigi_Rep_Item (Ent);
21659 -----------------------------
21660 -- Wide_Character_Encoding --
21661 -----------------------------
21663 -- pragma Wide_Character_Encoding (IDENTIFIER);
21665 when Pragma_Wide_Character_Encoding =>
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
21675 --------------------
21676 -- Unknown_Pragma --
21677 --------------------
21679 -- Should be impossible, since the case of an unknown pragma is
21680 -- separately processed before the case statement is entered.
21682 when Unknown_Pragma =>
21683 raise Program_Error;
21686 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21687 -- until AI is formally approved.
21689 -- Check_Order_Dependence;
21692 when Pragma_Exit => null;
21693 end Analyze_Pragma;
21695 ---------------------------------------------
21696 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21697 ---------------------------------------------
21699 procedure Analyze_Pre_Post_Condition_In_Decl_Part
21701 Subp_Id : Entity_Id)
21703 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (Prag));
21704 Nam : constant Name_Id := Original_Aspect_Name (Prag);
21707 Restore_Scope : Boolean := False;
21708 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
21711 -- Ensure that the subprogram and its formals are visible when analyzing
21712 -- the expression of the pragma.
21714 if not In_Open_Scopes (Subp_Id) then
21715 Restore_Scope := True;
21716 Push_Scope (Subp_Id);
21717 Install_Formals (Subp_Id);
21720 -- Preanalyze the boolean expression, we treat this as a spec expression
21721 -- (i.e. similar to a default expression).
21723 Expr := Get_Pragma_Arg (Arg1);
21725 -- In ASIS mode, for a pragma generated from a source aspect, analyze
21726 -- the original aspect expression, which is shared with the generated
21729 if ASIS_Mode and then Present (Corresponding_Aspect (Prag)) then
21730 Expr := Expression (Corresponding_Aspect (Prag));
21733 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
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)).
21740 if Class_Present (Prag) then
21741 Class_Wide_Condition : declare
21742 T : constant Entity_Id := Find_Dispatching_Type (Subp_Id);
21744 ACW : Entity_Id := Empty;
21745 -- Access to T'class, created if there is a controlling formal
21746 -- that is an access parameter.
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.
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.
21769 function Get_ACW return Entity_Id is
21770 Loc : constant Source_Ptr := Sloc (Prag);
21776 Make_Full_Type_Declaration (Loc,
21777 Defining_Identifier => Make_Temporary (Loc, 'T'),
21779 Make_Access_To_Object_Definition (Loc,
21780 Subtype_Indication =>
21781 New_Occurrence_Of (Class_Wide_Type (T), Loc),
21782 All_Present => True));
21784 Insert_Before (Unit_Declaration_Node (Subp_Id), Decl);
21786 ACW := Defining_Identifier (Decl);
21787 Freeze_Before (Unit_Declaration_Node (Subp_Id), ACW);
21797 function Process (N : Node_Id) return Traverse_Result is
21798 Loc : constant Source_Ptr := Sloc (N);
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
21807 (Nkind (Parent (N)) /= N_Parameter_Association
21808 or else N /= Selector_Name (Parent (N)))
21810 if Etype (Entity (N)) = T then
21811 Typ := Class_Wide_Type (T);
21813 elsif Is_Access_Type (Etype (Entity (N)))
21814 and then Designated_Type (Etype (Entity (N))) = T
21821 if Present (Typ) then
21823 Make_Type_Conversion (Loc,
21825 New_Occurrence_Of (Typ, Loc),
21826 Expression => New_Occurrence_Of (Entity (N), Loc)));
21827 Set_Etype (N, Typ);
21834 procedure Replace_Type is new Traverse_Proc (Process);
21836 -- Start of processing for Class_Wide_Condition
21839 if not Present (T) then
21841 -- Pre'Class/Post'Class aspect cases
21843 if From_Aspect_Specification (Prag) then
21844 if Nam = Name_uPre then
21845 Error_Msg_Name_1 := Name_Pre;
21847 Error_Msg_Name_1 := Name_Post;
21850 Error_Msg_Name_2 := Name_Class;
21853 ("aspect `%''%` can only be specified for a primitive "
21854 & "operation of a tagged type",
21855 Corresponding_Aspect (Prag));
21857 -- Pre_Class, Post_Class pragma cases
21860 if Nam = Name_uPre then
21861 Error_Msg_Name_1 := Name_Pre_Class;
21863 Error_Msg_Name_1 := Name_Post_Class;
21867 ("pragma% can only be specified for a primitive "
21868 & "operation of a tagged type",
21869 Corresponding_Aspect (Prag));
21873 Replace_Type (Get_Pragma_Arg (Arg1));
21874 end Class_Wide_Condition;
21877 -- Remove the subprogram from the scope stack now that the pre-analysis
21878 -- of the precondition/postcondition is done.
21880 if Restore_Scope then
21883 end Analyze_Pre_Post_Condition_In_Decl_Part;
21885 ------------------------------------------
21886 -- Analyze_Refined_Depends_In_Decl_Part --
21887 ------------------------------------------
21889 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21890 Dependencies : List_Id := No_List;
21892 -- The corresponding Depends pragma along with its clauses
21894 Matched_Items : Elist_Id := No_Elist;
21895 -- A list containing the entities of all successfully matched items
21896 -- found in pragma Depends.
21898 Refinements : List_Id := No_List;
21899 -- The clauses of pragma Refined_Depends
21901 Spec_Id : Entity_Id;
21902 -- The entity of the subprogram subject to pragma Refined_Depends
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.
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
21914 procedure Report_Extra_Clauses;
21915 -- Emit an error for each extra clause found in list Refinements
21917 -----------------------------
21918 -- Check_Dependency_Clause --
21919 -----------------------------
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));
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).
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.
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.
21957 procedure Record_Item (Item_Id : Entity_Id);
21958 -- Store the entity of an item denoted by Item_Id in Matched_Items
21960 ----------------------------
21961 -- Is_In_Out_State_Clause --
21962 ----------------------------
21964 function Is_In_Out_State_Clause return Boolean is
21965 Dep_Input_Id : Entity_Id;
21966 Dep_Output_Id : Entity_Id;
21969 -- Detect the following clause:
21972 if Is_Entity_Name (Dep_Input)
21973 and then Is_Entity_Name (Dep_Output)
21975 -- Handle abstract views generated for limited with clauses
21977 Dep_Input_Id := Available_View (Entity_Of (Dep_Input));
21978 Dep_Output_Id := Available_View (Entity_Of (Dep_Output));
21981 Ekind (Dep_Input_Id) = E_Abstract_State
21982 and then Dep_Input_Id = Dep_Output_Id;
21986 end Is_In_Out_State_Clause;
21988 ---------------------------
21989 -- Is_Null_Refined_State --
21990 ---------------------------
21992 function Is_Null_Refined_State (Item : Node_Id) return Boolean is
21993 Item_Id : Entity_Id;
21996 if Is_Entity_Name (Item) then
21998 -- Handle abstract views generated for limited with clauses
22000 Item_Id := Available_View (Entity_Of (Item));
22002 return Ekind (Item_Id) = E_Abstract_State
22003 and then Has_Null_Refinement (Item_Id);
22008 end Is_Null_Refined_State;
22014 procedure Match_Items
22015 (Dep_Item : Node_Id;
22016 Ref_Item : Node_Id;
22017 Matched : out Boolean)
22019 Dep_Item_Id : Entity_Id;
22020 Ref_Item_Id : Entity_Id;
22023 -- Assume that the two items do not match
22027 -- A null matches null or Empty (special case)
22029 if Nkind (Dep_Item) = N_Null
22030 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
22034 -- Attribute 'Result matches attribute 'Result
22036 elsif Is_Attribute_Result (Dep_Item)
22037 and then Is_Attribute_Result (Dep_Item)
22041 -- Abstract states, formal parameters and variables
22043 elsif Is_Entity_Name (Dep_Item) then
22045 -- Handle abstract views generated for limited with clauses
22047 Dep_Item_Id := Available_View (Entity_Of (Dep_Item));
22049 if Ekind (Dep_Item_Id) = E_Abstract_State then
22051 -- An abstract state with visible null refinement matches
22052 -- null or Empty (special case).
22054 if Has_Null_Refinement (Dep_Item_Id)
22055 and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null)
22057 Record_Item (Dep_Item_Id);
22060 -- An abstract state with visible non-null refinement
22061 -- matches one of its constituents.
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);
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) =
22072 Record_Item (Dep_Item_Id);
22077 -- An abstract state without a visible refinement matches
22080 elsif Is_Entity_Name (Ref_Item)
22081 and then Entity_Of (Ref_Item) = Dep_Item_Id
22083 Record_Item (Dep_Item_Id);
22087 -- A formal parameter or a variable matches itself
22089 elsif Is_Entity_Name (Ref_Item)
22090 and then Entity_Of (Ref_Item) = Dep_Item_Id
22092 Record_Item (Dep_Item_Id);
22102 procedure Record_Item (Item_Id : Entity_Id) is
22104 if not Contains (Matched_Items, Item_Id) then
22105 Add_Item (Item_Id, Matched_Items);
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;
22120 -- Start of processing for Check_Dependency_Clause
22123 -- Examine all refinement clauses and compare them against the
22124 -- dependence clause.
22126 Ref_Clause := First (Refinements);
22127 while Present (Ref_Clause) loop
22128 Next_Ref_Clause := Next (Ref_Clause);
22130 -- Obtain the attributes of the current refinement clause
22132 Ref_Input := Expression (Ref_Clause);
22133 Ref_Output := First (Choices (Ref_Clause));
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.
22139 -- Depends Dep_Output => Dep_Input
22143 -- Refined_Depends Ref_Output => Ref_Input
22146 (Dep_Item => Dep_Input,
22147 Ref_Item => Ref_Input,
22148 Matched => Inputs_Match);
22151 (Dep_Item => Dep_Output,
22152 Ref_Item => Ref_Output,
22153 Matched => Outputs_Match);
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.
22159 if Is_In_Out_State_Clause then
22161 -- Depends => (State => State)
22162 -- Refined_Depends => (null => Constit) -- OK
22165 and then not Outputs_Match
22166 and then Nkind (Ref_Output) = N_Null
22168 Outputs_Match := True;
22171 -- Depends => (State => State)
22172 -- Refined_Depends => (Constit => null) -- OK
22174 if not Inputs_Match
22175 and then Outputs_Match
22176 and then Nkind (Ref_Input) = N_Null
22178 Inputs_Match := True;
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.
22187 if Inputs_Match and then Outputs_Match then
22188 Clause_Matched := True;
22189 Remove (Ref_Clause);
22192 Ref_Clause := Next_Ref_Clause;
22195 -- Depending on the order or composition of refinement clauses, an
22196 -- In_Out state clause may not be directly refinable.
22198 -- Depends => ((Output, State) => (Input, State))
22199 -- Refined_State => (State => (Constit_1, Constit_2))
22200 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
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.
22209 if not Clause_Matched
22210 and then Is_In_Out_State_Clause
22212 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22214 Clause_Matched := True;
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.
22221 -- Depends => (Output => State) -- implicitly OK
22222 -- Refined_State => (State => null)
22223 -- Refined_Depends => (Output => ...)
22225 if not Clause_Matched
22226 and then Is_Null_Refined_State (Dep_Input)
22227 and then Is_Entity_Name (Dep_Output)
22229 Contains (Matched_Items, Available_View (Entity_Of (Dep_Output)))
22231 Clause_Matched := True;
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.
22238 -- Depends => (State => Input) -- implicitly OK
22239 -- Refined_State => (State => null)
22240 -- Refined_Depends => (... => Input)
22242 if not Clause_Matched
22243 and then Is_Null_Refined_State (Dep_Output)
22244 and then Is_Entity_Name (Dep_Input)
22246 Contains (Matched_Items, Available_View (Entity_Of (Dep_Input)))
22248 Clause_Matched := True;
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.
22255 -- Depends => (State => null)
22256 -- Refined_State => (State => null)
22257 -- Refined_Depends => null -- OK
22259 if not Clause_Matched then
22261 (Dep_Item => Dep_Input,
22263 Matched => Inputs_Match);
22266 (Dep_Item => Dep_Output,
22268 Matched => Outputs_Match);
22270 Clause_Matched := Inputs_Match and Outputs_Match;
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.
22277 if not Clause_Matched then
22279 ("dependence clause of subprogram & has no matching refinement "
22280 & "in body", Dep_Clause, Spec_Id);
22282 end Check_Dependency_Clause;
22284 -----------------------
22285 -- Normalize_Clauses --
22286 -----------------------
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:
22294 -- Output => (Input_1, Input_2) -- original
22296 -- Output => Input_1 -- normalizations
22297 -- Output => Input_2
22299 ----------------------
22300 -- Normalize_Inputs --
22301 ----------------------
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;
22309 New_Clause : Node_Id;
22310 Next_Input : Node_Id;
22313 -- Normalization is performed only when the original clause has
22314 -- more than one input. Multiple inputs appear as an aggregate.
22316 if Nkind (Inputs) = N_Aggregate then
22317 Last_Input := Last (Expressions (Inputs));
22319 -- Create a new clause for each input
22321 Input := First (Expressions (Inputs));
22322 while Present (Input) loop
22323 Next_Input := Next (Input);
22325 -- Unhook the current input from the original input list
22326 -- because it will be relocated to a new clause.
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.
22334 if Input = Last_Input then
22335 Rewrite (Inputs, Input);
22337 -- Generate a clause of the form:
22342 Make_Component_Association (Loc,
22343 Choices => New_Copy_List_Tree (Output),
22344 Expression => Input);
22346 -- The new clause contains replicated content that has
22347 -- already been analyzed, mark the clause as analyzed.
22349 Set_Analyzed (New_Clause);
22350 Insert_After (Clause, New_Clause);
22353 Input := Next_Input;
22356 end Normalize_Inputs;
22362 -- Start of processing for Normalize_Clauses
22365 Clause := First (Clauses);
22366 while Present (Clause) loop
22367 Normalize_Inputs (Clause);
22370 end Normalize_Clauses;
22372 --------------------------
22373 -- Report_Extra_Clauses --
22374 --------------------------
22376 procedure Report_Extra_Clauses is
22380 if Present (Refinements) then
22381 Clause := First (Refinements);
22382 while Present (Clause) loop
22384 -- Do not complain about a null input refinement, since a null
22385 -- input legitimately matches anything.
22387 if Nkind (Clause) /= N_Component_Association
22388 or else Nkind (Expression (Clause)) /= N_Null
22391 ("unmatched or extra clause in dependence refinement",
22398 end Report_Extra_Clauses;
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)));
22409 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22412 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
22413 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
22415 Spec_Id := Corresponding_Spec (Body_Decl);
22418 Depends := Get_Pragma (Spec_Id, Pragma_Depends);
22420 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22421 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22423 if No (Depends) then
22425 ("useless refinement, declaration of subprogram & lacks aspect or "
22426 & "pragma Depends", N, Spec_Id);
22430 Deps := Get_Pragma_Arg (First (Pragma_Argument_Associations (Depends)));
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)).
22437 if Nkind (Deps) = N_Null then
22439 ("useless refinement, subprogram & does not depend on abstract "
22440 & "state with visible refinement", N, Spec_Id);
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.
22448 Analyze_Depends_In_Decl_Part (N);
22450 -- Do not match dependencies against refinements if Refined_Depends is
22451 -- illegal to avoid emitting misleading error.
22453 if Serious_Errors_Detected = Errors then
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.
22459 pragma Assert (Nkind (Deps) = N_Aggregate);
22460 Dependencies := New_Copy_List_Tree (Component_Associations (Deps));
22461 Normalize_Clauses (Dependencies);
22463 if Nkind (Refs) = N_Null then
22464 Refinements := No_List;
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.
22470 else pragma Assert (Nkind (Refs) = N_Aggregate);
22471 Refinements := New_Copy_List_Tree (Component_Associations (Refs));
22472 Normalize_Clauses (Refinements);
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.
22480 Clause := First (Dependencies);
22481 while Present (Clause) loop
22482 Check_Dependency_Clause (Clause);
22486 if Serious_Errors_Detected = Errors then
22487 Report_Extra_Clauses;
22490 end Analyze_Refined_Depends_In_Decl_Part;
22492 -----------------------------------------
22493 -- Analyze_Refined_Global_In_Decl_Part --
22494 -----------------------------------------
22496 procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is
22498 -- The corresponding Global pragma
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
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.
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.
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.
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
22535 -- This routine may remove elements from In_Constits, In_Out_Constits,
22536 -- Out_Constits and Proof_In_Constits.
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.
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.
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.
22559 procedure Check_Refined_Global_List
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.
22565 function Present_Then_Remove
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.
22572 procedure Report_Extra_Constituents;
22573 -- Emit an error for each constituent found in lists In_Constits,
22574 -- In_Out_Constits and Out_Constits.
22576 -------------------------
22577 -- Check_In_Out_States --
22578 -------------------------
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
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
22588 -- If this is not the case, emit an error.
22590 -----------------------------
22591 -- Check_Constituent_Usage --
22592 -----------------------------
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;
22603 -- Process all the constituents of the state and note their modes
22604 -- within the global refinement.
22606 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22607 while Present (Constit_Elmt) loop
22608 Constit_Id := Node (Constit_Elmt);
22610 if Present_Then_Remove (In_Constits, Constit_Id) then
22613 elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then
22614 In_Out_Seen := True;
22616 elsif Present_Then_Remove (Out_Constits, Constit_Id) then
22619 -- A Proof_In constituent cannot participate in the completion
22620 -- of an Output state (SPARK RM 7.2.4(5)).
22622 elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22623 Error_Msg_Name_1 := Chars (State_Id);
22625 ("constituent & of state % must have mode Input, In_Out "
22626 & "or Output in global refinement",
22630 Has_Missing := True;
22633 Next_Elmt (Constit_Elmt);
22636 -- A single In_Out constituent is a valid completion
22638 if In_Out_Seen then
22641 -- A pair of one Input and one Output constituent is a valid
22644 elsif In_Seen and then Out_Seen then
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)).
22650 elsif Has_Missing and then Out_Seen then
22655 ("global refinement of state & redefines the mode of its "
22656 & "constituents", N, State_Id);
22658 end Check_Constituent_Usage;
22662 Item_Elmt : Elmt_Id;
22663 Item_Id : Entity_Id;
22665 -- Start of processing for Check_In_Out_States
22668 -- Inspect the In_Out items of the corresponding Global pragma
22669 -- looking for a state with a visible refinement.
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);
22676 -- Ensure that one of the three coverage variants is satisfied
22678 if Ekind (Item_Id) = E_Abstract_State
22679 and then Has_Non_Null_Refinement (Item_Id)
22681 Check_Constituent_Usage (Item_Id);
22684 Next_Elmt (Item_Elmt);
22687 end Check_In_Out_States;
22689 ------------------------
22690 -- Check_Input_States --
22691 ------------------------
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
22700 -----------------------------
22701 -- Check_Constituent_Usage --
22702 -----------------------------
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;
22710 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22711 while Present (Constit_Elmt) loop
22712 Constit_Id := Node (Constit_Elmt);
22714 -- At least one of the constituents appears as an Input
22716 if Present_Then_Remove (In_Constits, Constit_Id) then
22719 -- The constituent appears in the global refinement, but has
22720 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
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)
22726 Error_Msg_Name_1 := Chars (State_Id);
22728 ("constituent & of state % must have mode Input in global "
22729 & "refinement", N, Constit_Id);
22732 Next_Elmt (Constit_Elmt);
22735 -- Not one of the constituents appeared as Input
22737 if not In_Seen then
22739 ("global refinement of state & must include at least one "
22740 & "constituent of mode Input", N, State_Id);
22742 end Check_Constituent_Usage;
22746 Item_Elmt : Elmt_Id;
22747 Item_Id : Entity_Id;
22749 -- Start of processing for Check_Input_States
22752 -- Inspect the Input items of the corresponding Global pragma
22753 -- looking for a state with a visible refinement.
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);
22760 -- Ensure that at least one of the constituents is utilized and
22761 -- is of mode Input.
22763 if Ekind (Item_Id) = E_Abstract_State
22764 and then Has_Non_Null_Refinement (Item_Id)
22766 Check_Constituent_Usage (Item_Id);
22769 Next_Elmt (Item_Elmt);
22772 end Check_Input_States;
22774 -------------------------
22775 -- Check_Output_States --
22776 -------------------------
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
22784 -----------------------------
22785 -- Check_Constituent_Usage --
22786 -----------------------------
22788 procedure Check_Constituent_Usage (State_Id : Entity_Id) is
22789 Constit_Elmt : Elmt_Id;
22790 Constit_Id : Entity_Id;
22791 Posted : Boolean := False;
22794 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22795 while Present (Constit_Elmt) loop
22796 Constit_Id := Node (Constit_Elmt);
22798 if Present_Then_Remove (Out_Constits, Constit_Id) then
22801 -- The constituent appears in the global refinement, but has
22802 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
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)
22808 Error_Msg_Name_1 := Chars (State_Id);
22810 ("constituent & of state % must have mode Output in "
22811 & "global refinement", N, Constit_Id);
22813 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22819 ("output state & must be replaced by all its "
22820 & "constituents in global refinement", N, State_Id);
22824 ("\constituent & is missing in output list",
22828 Next_Elmt (Constit_Elmt);
22830 end Check_Constituent_Usage;
22834 Item_Elmt : Elmt_Id;
22835 Item_Id : Entity_Id;
22837 -- Start of processing for Check_Output_States
22840 -- Inspect the Output items of the corresponding Global pragma
22841 -- looking for a state with a visible refinement.
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);
22848 -- Ensure that all of the constituents are utilized and they
22849 -- have mode Output.
22851 if Ekind (Item_Id) = E_Abstract_State
22852 and then Has_Non_Null_Refinement (Item_Id)
22854 Check_Constituent_Usage (Item_Id);
22857 Next_Elmt (Item_Elmt);
22860 end Check_Output_States;
22862 ---------------------------
22863 -- Check_Proof_In_States --
22864 ---------------------------
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.
22872 -----------------------------
22873 -- Check_Constituent_Usage --
22874 -----------------------------
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;
22882 Constit_Elmt := First_Elmt (Refinement_Constituents (State_Id));
22883 while Present (Constit_Elmt) loop
22884 Constit_Id := Node (Constit_Elmt);
22886 -- At least one of the constituents appears as Proof_In
22888 if Present_Then_Remove (Proof_In_Constits, Constit_Id) then
22889 Proof_In_Seen := True;
22891 -- The constituent appears in the global refinement, but has
22892 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
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)
22898 Error_Msg_Name_1 := Chars (State_Id);
22900 ("constituent & of state % must have mode Proof_In in "
22901 & "global refinement", N, Constit_Id);
22904 Next_Elmt (Constit_Elmt);
22907 -- Not one of the constituents appeared as Proof_In
22909 if not Proof_In_Seen then
22911 ("global refinement of state & must include at least one "
22912 & "constituent of mode Proof_In", N, State_Id);
22914 end Check_Constituent_Usage;
22918 Item_Elmt : Elmt_Id;
22919 Item_Id : Entity_Id;
22921 -- Start of processing for Check_Proof_In_States
22924 -- Inspect the Proof_In items of the corresponding Global pragma
22925 -- looking for a state with a visible refinement.
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);
22932 -- Ensure that at least one of the constituents is utilized and
22933 -- is of mode Proof_In
22935 if Ekind (Item_Id) = E_Abstract_State
22936 and then Has_Non_Null_Refinement (Item_Id)
22938 Check_Constituent_Usage (Item_Id);
22941 Next_Elmt (Item_Elmt);
22944 end Check_Proof_In_States;
22946 -------------------------------
22947 -- Check_Refined_Global_List --
22948 -------------------------------
22950 procedure Check_Refined_Global_List
22952 Global_Mode : Name_Id := Name_Input)
22954 procedure Check_Refined_Global_Item
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.
22960 -------------------------------
22961 -- Check_Refined_Global_Item --
22962 -------------------------------
22964 procedure Check_Refined_Global_Item
22966 Global_Mode : Name_Id)
22968 Item_Id : constant Entity_Id := Entity_Of (Item);
22970 procedure Inconsistent_Mode_Error (Expect : Name_Id);
22971 -- Issue a common error message for all mode mismatches. Expect
22972 -- denotes the expected mode.
22974 -----------------------------
22975 -- Inconsistent_Mode_Error --
22976 -----------------------------
22978 procedure Inconsistent_Mode_Error (Expect : Name_Id) is
22981 ("global item & has inconsistent modes", Item, Item_Id);
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;
22988 -- Start of processing for Check_Refined_Global_Item
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.
22995 if Present (Encapsulating_State (Item_Id))
22996 and then Has_Visible_Refinement (Encapsulating_State (Item_Id))
22998 if Global_Mode = Name_Input then
22999 Add_Item (Item_Id, In_Constits);
23001 elsif Global_Mode = Name_In_Out then
23002 Add_Item (Item_Id, In_Out_Constits);
23004 elsif Global_Mode = Name_Output then
23005 Add_Item (Item_Id, Out_Constits);
23007 elsif Global_Mode = Name_Proof_In then
23008 Add_Item (Item_Id, Proof_In_Constits);
23011 -- When not a constituent, ensure that both occurrences of the
23012 -- item in pragmas Global and Refined_Global match.
23014 elsif Contains (In_Items, Item_Id) then
23015 if Global_Mode /= Name_Input then
23016 Inconsistent_Mode_Error (Name_Input);
23019 elsif Contains (In_Out_Items, Item_Id) then
23020 if Global_Mode /= Name_In_Out then
23021 Inconsistent_Mode_Error (Name_In_Out);
23024 elsif Contains (Out_Items, Item_Id) then
23025 if Global_Mode /= Name_Output then
23026 Inconsistent_Mode_Error (Name_Output);
23029 elsif Contains (Proof_In_Items, Item_Id) then
23032 -- The item does not appear in the corresponding Global pragma,
23033 -- it must be an extra (SPARK RM 7.2.4(3)).
23036 SPARK_Msg_NE ("extra global item &", Item, Item_Id);
23038 end Check_Refined_Global_Item;
23044 -- Start of processing for Check_Refined_Global_List
23047 if Nkind (List) = N_Null then
23050 -- Single global item declaration
23052 elsif Nkind_In (List, N_Expanded_Name,
23054 N_Selected_Component)
23056 Check_Refined_Global_Item (List, Global_Mode);
23058 -- Simple global list or moded global list declaration
23060 elsif Nkind (List) = N_Aggregate then
23062 -- The declaration of a simple global list appear as a collection
23065 if Present (Expressions (List)) then
23066 Item := First (Expressions (List));
23067 while Present (Item) loop
23068 Check_Refined_Global_Item (Item, Global_Mode);
23073 -- The declaration of a moded global list appears as a collection
23074 -- of component associations where individual choices denote
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))));
23090 raise Program_Error;
23096 raise Program_Error;
23098 end Check_Refined_Global_List;
23100 -------------------------
23101 -- Present_Then_Remove --
23102 -------------------------
23104 function Present_Then_Remove
23106 Item : Entity_Id) return Boolean
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);
23124 end Present_Then_Remove;
23126 -------------------------------
23127 -- Report_Extra_Constituents --
23128 -------------------------------
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
23134 ---------------------------------------
23135 -- Report_Extra_Constituents_In_List --
23136 ---------------------------------------
23138 procedure Report_Extra_Constituents_In_List (List : Elist_Id) is
23139 Constit_Elmt : Elmt_Id;
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);
23149 end Report_Extra_Constituents_In_List;
23151 -- Start of processing for Report_Extra_Constituents
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;
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;
23168 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23171 if Nkind (Body_Decl) = N_Subprogram_Body_Stub then
23172 Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
23174 Spec_Id := Corresponding_Spec (Body_Decl);
23177 Global := Get_Pragma (Spec_Id, Pragma_Global);
23179 -- The subprogram declaration lacks pragma Global. This renders
23180 -- Refined_Global useless as there is nothing to refine.
23182 if No (Global) then
23184 ("useless refinement, declaration of subprogram & lacks aspect or "
23185 & "pragma Global", N, Spec_Id);
23189 -- Extract all relevant items from the corresponding Global pragma
23191 Collect_Global_Items
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);
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)).
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
23214 ("useless refinement, subprogram & does not depend on abstract "
23215 & "state with visible refinement", N, Spec_Id);
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.
23223 if Nkind (Items) = N_Null
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
23232 ("refinement cannot be null, subprogram & has global items",
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.
23241 Analyze_Global_In_Decl_Part (N);
23243 -- Perform all refinement checks with respect to completeness and mode
23246 if Serious_Errors_Detected = Errors then
23247 Check_Refined_Global_List (Items);
23250 -- For Input states with visible refinement, at least one constituent
23251 -- must be used as an Input in the global refinement.
23253 if Serious_Errors_Detected = Errors then
23254 Check_Input_States;
23257 -- Verify all possible completion variants for In_Out states with
23258 -- visible refinement.
23260 if Serious_Errors_Detected = Errors then
23261 Check_In_Out_States;
23264 -- For Output states with visible refinement, all constituents must be
23265 -- used as Outputs in the global refinement.
23267 if Serious_Errors_Detected = Errors then
23268 Check_Output_States;
23271 -- For Proof_In states with visible refinement, at least one constituent
23272 -- must be used as Proof_In in the global refinement.
23274 if Serious_Errors_Detected = Errors then
23275 Check_Proof_In_States;
23278 -- Emit errors for all constituents that belong to other states with
23279 -- visible refinement that do not appear in Global.
23281 if Serious_Errors_Detected = Errors then
23282 Report_Extra_Constituents;
23284 end Analyze_Refined_Global_In_Decl_Part;
23286 ----------------------------------------
23287 -- Analyze_Refined_State_In_Decl_Part --
23288 ----------------------------------------
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
23296 Body_Id : Entity_Id;
23297 -- The body entity of the package subject to pragma Refined_State
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.
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.
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.
23311 Spec_Id : Entity_Id;
23312 -- The spec entity of the package subject to pragma Refined_State
23314 procedure Analyze_Refinement_Clause (Clause : Node_Id);
23315 -- Perform full analysis of a single refinement clause
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.
23321 procedure Report_Unrefined_States (States : Elist_Id);
23322 -- Emit errors for all unrefined abstract states found in list States
23324 procedure Report_Unused_States (States : Elist_Id);
23325 -- Emit errors for all unused states found in list States
23327 -------------------------------
23328 -- Analyze_Refinement_Clause --
23329 -------------------------------
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.
23340 External_Constit_Seen : Boolean := False;
23341 -- Flag used to mark when at least one external constituent is part
23342 -- of the state refinement.
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.
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.
23354 State_Id : Entity_Id;
23355 -- The current state being refined
23357 procedure Analyze_Constituent (Constit : Node_Id);
23358 -- Perform full analysis of a single constituent
23360 procedure Check_External_Property
23361 (Prop_Nam : Name_Id;
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.
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.
23375 procedure Report_Unused_Constituents (Constits : Elist_Id);
23376 -- Emit errors for all unused Part_Of constituents in list Constits
23378 -------------------------
23379 -- Analyze_Constituent --
23380 -------------------------
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.
23390 --------------------------------
23391 -- Check_Matching_Constituent --
23392 --------------------------------
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
23398 -------------------------
23399 -- Collect_Constituent --
23400 -------------------------
23402 procedure Collect_Constituent is
23404 -- Add the constituent to the list of processed items to aid
23405 -- with the detection of duplicates.
23407 Add_Item (Constit_Id, Constituents_Seen);
23409 -- Collect the constituent in the list of refinement items
23410 -- and establish a relation between the refined state and
23413 Append_Elmt (Constit_Id, Refinement_Constituents (State_Id));
23414 Set_Encapsulating_State (Constit_Id, State_Id);
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).
23420 Set_Has_Visible_Refinement (State_Id);
23422 -- When the constituent is external, save its relevant
23423 -- property for further checks.
23425 if Async_Readers_Enabled (Constit_Id) then
23426 AR_Constit := Constit_Id;
23427 External_Constit_Seen := True;
23430 if Async_Writers_Enabled (Constit_Id) then
23431 AW_Constit := Constit_Id;
23432 External_Constit_Seen := True;
23435 if Effective_Reads_Enabled (Constit_Id) then
23436 ER_Constit := Constit_Id;
23437 External_Constit_Seen := True;
23440 if Effective_Writes_Enabled (Constit_Id) then
23441 EW_Constit := Constit_Id;
23442 External_Constit_Seen := True;
23444 end Collect_Constituent;
23448 State_Elmt : Elmt_Id;
23450 -- Start of processing for Check_Matching_Constituent
23453 -- Detect a duplicate use of a constituent
23455 if Contains (Constituents_Seen, Constit_Id) then
23457 ("duplicate use of constituent &", Constit, Constit_Id);
23461 -- The constituent is subject to a Part_Of indicator
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;
23468 -- The constituent is part of another state and is used
23469 -- incorrectly in the refinement of the current state.
23472 Error_Msg_Name_1 := Chars (State_Id);
23474 ("& cannot act as constituent of state %",
23475 Constit, Constit_Id);
23477 ("\Part_Of indicator specifies & as encapsulating "
23478 & "state", Constit, Encapsulating_State (Constit_Id));
23481 -- The only other source of legal constituents is the body
23482 -- state space of the related package.
23485 if Present (Body_States) then
23486 State_Elmt := First_Elmt (Body_States);
23487 while Present (State_Elmt) loop
23489 -- Consume a valid constituent to signal that it has
23490 -- been encountered.
23492 if Node (State_Elmt) = Constit_Id then
23493 Remove_Elmt (Body_States, State_Elmt);
23494 Collect_Constituent;
23498 Next_Elmt (State_Elmt);
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)).
23506 Error_Msg_Name_1 := Chars (Spec_Id);
23508 ("cannot use & in refinement, constituent is not a hidden "
23509 & "state of package %", Constit, Constit_Id);
23511 end Check_Matching_Constituent;
23515 Constit_Id : Entity_Id;
23517 -- Start of processing for Analyze_Constituent
23520 -- Detect multiple uses of null in a single refinement clause or a
23521 -- mixture of null and non-null constituents.
23523 if Nkind (Constit) = N_Null then
23526 ("multiple null constituents not allowed", Constit);
23528 elsif Non_Null_Seen then
23530 ("cannot mix null and non-null constituents", Constit);
23535 -- Collect the constituent in the list of refinement items
23537 Append_Elmt (Constit, Refinement_Constituents (State_Id));
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).
23543 Set_Has_Visible_Refinement (State_Id);
23546 -- Non-null constituents
23549 Non_Null_Seen := True;
23553 ("cannot mix null and non-null constituents", Constit);
23557 Resolve_State (Constit);
23559 -- Ensure that the constituent denotes a valid state or a
23562 if Is_Entity_Name (Constit) then
23563 Constit_Id := Entity_Of (Constit);
23565 if Ekind_In (Constit_Id, E_Abstract_State, E_Variable) then
23566 Check_Matching_Constituent (Constit_Id);
23570 ("constituent & must denote a variable or state (SPARK "
23571 & "RM 7.2.2(5))", Constit, Constit_Id);
23574 -- The constituent is illegal
23577 SPARK_Msg_N ("malformed constituent", Constit);
23580 end Analyze_Constituent;
23582 -----------------------------
23583 -- Check_External_Property --
23584 -----------------------------
23586 procedure Check_External_Property
23587 (Prop_Nam : Name_Id;
23589 Constit : Entity_Id)
23592 Error_Msg_Name_1 := Prop_Nam;
23594 -- The property is enabled in the related Abstract_State pragma
23595 -- that defines the state (SPARK RM 7.2.8(3)).
23598 if No (Constit) then
23600 ("external state & requires at least one constituent with "
23601 & "property %", State, State_Id);
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)).
23608 elsif Present (Constit) then
23609 Error_Msg_Name_2 := Chars (Constit);
23611 ("external state & lacks property % set by constituent %",
23614 end Check_External_Property;
23616 --------------------------
23617 -- Check_Matching_State --
23618 --------------------------
23620 procedure Check_Matching_State is
23621 State_Elmt : Elmt_Id;
23624 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
23626 if Contains (Refined_States_Seen, State_Id) then
23628 ("duplicate refinement of state &", State, State_Id);
23632 -- Inspect the abstract states defined in the package declaration
23633 -- looking for a match.
23635 State_Elmt := First_Elmt (Available_States);
23636 while Present (State_Elmt) loop
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
23644 if Node (State_Elmt) = State_Id then
23645 Add_Item (State_Id, Refined_States_Seen);
23646 Remove_Elmt (Available_States, State_Elmt);
23650 Next_Elmt (State_Elmt);
23653 -- If we get here, we are refining a state that is not defined in
23654 -- the package declaration.
23656 Error_Msg_Name_1 := Chars (Spec_Id);
23658 ("cannot refine state, & is not defined in package %",
23660 end Check_Matching_State;
23662 --------------------------------
23663 -- Report_Unused_Constituents --
23664 --------------------------------
23666 procedure Report_Unused_Constituents (Constits : Elist_Id) is
23667 Constit_Elmt : Elmt_Id;
23668 Constit_Id : Entity_Id;
23669 Posted : Boolean := False;
23672 if Present (Constits) then
23673 Constit_Elmt := First_Elmt (Constits);
23674 while Present (Constit_Elmt) loop
23675 Constit_Id := Node (Constit_Elmt);
23677 -- Generate an error message of the form:
23679 -- state ... has unused Part_Of constituents
23680 -- abstract state ... defined at ...
23681 -- variable ... defined at ...
23686 ("state & has unused Part_Of constituents",
23690 Error_Msg_Sloc := Sloc (Constit_Id);
23692 if Ekind (Constit_Id) = E_Abstract_State then
23694 ("\abstract state & defined #", State, Constit_Id);
23697 ("\variable & defined #", State, Constit_Id);
23700 Next_Elmt (Constit_Elmt);
23703 end Report_Unused_Constituents;
23705 -- Local declarations
23707 Body_Ref : Node_Id;
23708 Body_Ref_Elmt : Elmt_Id;
23710 Extra_State : Node_Id;
23712 -- Start of processing for Analyze_Refinement_Clause
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.
23719 if Nkind (Clause) /= N_Component_Association then
23720 Error_Msg_N ("malformed state refinement clause", Clause);
23724 -- Analyze the state name of a refinement clause
23726 State := First (Choices (Clause));
23729 Resolve_State (State);
23731 -- Ensure that the state name denotes a valid abstract state that is
23732 -- defined in the spec of the related package.
23734 if Is_Entity_Name (State) then
23735 State_Id := Entity_Of (State);
23737 -- Catch any attempts to re-refine a state or refine a state that
23738 -- is not defined in the package declaration.
23740 if Ekind (State_Id) = E_Abstract_State then
23741 Check_Matching_State;
23744 ("& must denote an abstract state", State, State_Id);
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)).
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);
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);
23764 Next_Elmt (Body_Ref_Elmt);
23768 -- The state name is illegal. This is a syntax error, always report.
23771 Error_Msg_N ("malformed state name in refinement clause", State);
23775 -- A refinement clause may only refine one state at a time
23777 Extra_State := Next (State);
23779 if Present (Extra_State) then
23781 ("refinement clause cannot cover multiple states", Extra_State);
23784 -- Replicate the Part_Of constituents of the refined state because
23785 -- the algorithm will consume items.
23787 Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id));
23789 -- Analyze all constituents of the refinement. Multiple constituents
23790 -- appear as an aggregate.
23792 Constit := Expression (Clause);
23794 if Nkind (Constit) = N_Aggregate then
23795 if Present (Component_Associations (Constit)) then
23797 ("constituents of refinement clause must appear in "
23798 & "positional form", Constit);
23800 else pragma Assert (Present (Expressions (Constit)));
23801 Constit := First (Expressions (Constit));
23802 while Present (Constit) loop
23803 Analyze_Constituent (Constit);
23809 -- Various forms of a single constituent. Note that these may include
23810 -- malformed constituents.
23813 Analyze_Constituent (Constit);
23816 -- A refined external state is subject to special rules with respect
23817 -- to its properties and constituents.
23819 if Is_External_State (State_Id) then
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.
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);
23831 Check_External_Property
23832 (Prop_Nam => Name_Async_Writers,
23833 Enabled => Async_Writers_Enabled (State_Id),
23834 Constit => AW_Constit);
23836 Check_External_Property
23837 (Prop_Nam => Name_Effective_Reads,
23838 Enabled => Effective_Reads_Enabled (State_Id),
23839 Constit => ER_Constit);
23841 Check_External_Property
23842 (Prop_Nam => Name_Effective_Writes,
23843 Enabled => Effective_Writes_Enabled (State_Id),
23844 Constit => EW_Constit);
23846 -- An external state may be refined to null (SPARK RM 7.2.8(2))
23848 elsif Null_Seen then
23851 -- The external state has constituents, but none of them are
23852 -- external (SPARK RM 7.2.8(2)).
23856 ("external state & requires at least one external "
23857 & "constituent or null refinement", State, State_Id);
23860 -- When a refined state is not external, it should not have external
23861 -- constituents (SPARK RM 7.2.8(1)).
23863 elsif External_Constit_Seen then
23865 ("non-external state & cannot contain external constituents in "
23866 & "refinement", State, State_Id);
23869 -- Ensure that all Part_Of candidate constituents have been mentioned
23870 -- in the refinement clause.
23872 Report_Unused_Constituents (Part_Of_Constits);
23873 end Analyze_Refinement_Clause;
23875 -------------------------
23876 -- Collect_Body_States --
23877 -------------------------
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
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.
23887 ----------------------------
23888 -- Collect_Visible_States --
23889 ----------------------------
23891 procedure Collect_Visible_States (Pack_Id : Entity_Id) is
23892 Item_Id : Entity_Id;
23895 -- Traverse the entity chain of the package and inspect all
23898 Item_Id := First_Entity (Pack_Id);
23899 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
23901 -- Do not consider internally generated items as those cannot
23902 -- be named and participate in refinement.
23904 if not Comes_From_Source (Item_Id) then
23907 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
23908 Add_Item (Item_Id, Result);
23910 -- Recursively gather the visible states of a nested package
23912 elsif Ekind (Item_Id) = E_Package then
23913 Collect_Visible_States (Item_Id);
23916 Next_Entity (Item_Id);
23918 end Collect_Visible_States;
23922 Pack_Body : constant Node_Id :=
23923 Declaration_Node (Body_Entity (Pack_Id));
23925 Item_Id : Entity_Id;
23927 -- Start of processing for Collect_Body_States
23930 -- Inspect the declarations of the body looking for source variables,
23931 -- packages and package instantiations.
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);
23938 -- Capture source variables only as internally generated
23939 -- temporaries cannot be named and participate in refinement.
23941 if Ekind (Item_Id) = E_Variable
23942 and then Comes_From_Source (Item_Id)
23944 Add_Item (Item_Id, Result);
23947 elsif Nkind (Decl) = N_Package_Declaration then
23948 Item_Id := Defining_Entity (Decl);
23950 -- Capture the visible abstract states and variables of a
23951 -- source package [instantiation].
23953 if Comes_From_Source (Item_Id) then
23954 Collect_Visible_States (Item_Id);
23962 end Collect_Body_States;
23964 -----------------------------
23965 -- Report_Unrefined_States --
23966 -----------------------------
23968 procedure Report_Unrefined_States (States : Elist_Id) is
23969 State_Elmt : Elmt_Id;
23972 if Present (States) then
23973 State_Elmt := First_Elmt (States);
23974 while Present (State_Elmt) loop
23976 ("abstract state & must be refined", Node (State_Elmt));
23978 Next_Elmt (State_Elmt);
23981 end Report_Unrefined_States;
23983 --------------------------
23984 -- Report_Unused_States --
23985 --------------------------
23987 procedure Report_Unused_States (States : Elist_Id) is
23988 Posted : Boolean := False;
23989 State_Elmt : Elmt_Id;
23990 State_Id : Entity_Id;
23993 if Present (States) then
23994 State_Elmt := First_Elmt (States);
23995 while Present (State_Elmt) loop
23996 State_Id := Node (State_Elmt);
23998 -- Generate an error message of the form:
24000 -- body of package ... has unused hidden states
24001 -- abstract state ... defined at ...
24002 -- variable ... defined at ...
24007 ("body of package & has unused hidden states", Body_Id);
24010 Error_Msg_Sloc := Sloc (State_Id);
24012 if Ekind (State_Id) = E_Abstract_State then
24014 ("\abstract state & defined #", Body_Id, State_Id);
24017 ("\variable & defined #", Body_Id, State_Id);
24020 Next_Elmt (State_Elmt);
24023 end Report_Unused_States;
24025 -- Local declarations
24027 Body_Decl : constant Node_Id := Parent (N);
24028 Clauses : constant Node_Id :=
24029 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
24032 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24037 Body_Id := Defining_Entity (Body_Decl);
24038 Spec_Id := Corresponding_Spec (Body_Decl);
24040 -- Replicate the abstract states declared by the package because the
24041 -- matching algorithm will consume states.
24043 Available_States := New_Copy_Elist (Abstract_States (Spec_Id));
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.
24049 Body_States := Collect_Body_States (Spec_Id);
24051 -- Multiple non-null state refinements appear as an aggregate
24053 if Nkind (Clauses) = N_Aggregate then
24054 if Present (Expressions (Clauses)) then
24056 ("state refinements must appear as component associations",
24059 else pragma Assert (Present (Component_Associations (Clauses)));
24060 Clause := First (Component_Associations (Clauses));
24061 while Present (Clause) loop
24062 Analyze_Refinement_Clause (Clause);
24068 -- Various forms of a single state refinement. Note that these may
24069 -- include malformed refinements.
24072 Analyze_Refinement_Clause (Clauses);
24075 -- List all abstract states that were left unrefined
24077 Report_Unrefined_States (Available_States);
24079 -- Ensure that all abstract states and variables declared in the body
24080 -- state space of the related package are utilized as constituents.
24082 Report_Unused_States (Body_States);
24083 end Analyze_Refined_State_In_Decl_Part;
24085 ------------------------------------
24086 -- Analyze_Test_Case_In_Decl_Part --
24087 ------------------------------------
24089 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
24091 -- Install formals and push subprogram spec onto scope stack so that we
24092 -- can see the formals from the pragma.
24095 Install_Formals (S);
24097 -- Preanalyze the boolean expressions, we treat these as spec
24098 -- expressions (i.e. similar to a default expression).
24100 if Pragma_Name (N) = Name_Test_Case then
24101 Preanalyze_CTC_Args
24103 Get_Requires_From_CTC_Pragma (N),
24104 Get_Ensures_From_CTC_Pragma (N));
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.
24111 end Analyze_Test_Case_In_Decl_Part;
24117 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
24122 if Present (List) then
24123 Elmt := First_Elmt (List);
24124 while Present (Elmt) loop
24125 if Nkind (Node (Elmt)) = N_Defining_Identifier then
24128 Id := Entity_Of (Node (Elmt));
24131 if Id = Item_Id then
24142 -----------------------------
24143 -- Check_Applicable_Policy --
24144 -----------------------------
24146 procedure Check_Applicable_Policy (N : Node_Id) is
24150 Ename : constant Name_Id := Original_Aspect_Name (N);
24153 -- No effect if not valid assertion kind name
24155 if not Is_Valid_Assertion_Kind (Ename) then
24159 -- Loop through entries in check policy list
24161 PP := Opt.Check_Policy_List;
24162 while Present (PP) loop
24164 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24165 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
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,
24174 Name_Loop_Invariant,
24175 Name_Loop_Variant))
24177 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
24180 when Name_Off | Name_Ignore =>
24181 Set_Is_Ignored (N, True);
24182 Set_Is_Checked (N, False);
24184 when Name_On | Name_Check =>
24185 Set_Is_Checked (N, True);
24186 Set_Is_Ignored (N, False);
24188 when Name_Disable =>
24189 Set_Is_Ignored (N, True);
24190 Set_Is_Checked (N, False);
24191 Set_Is_Disabled (N, True);
24193 -- That should be exhaustive, the null here is a defence
24194 -- against a malformed tree from previous errors.
24203 PP := Next_Pragma (PP);
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.
24212 if Assertions_Enabled then
24213 Set_Is_Checked (N, True);
24214 Set_Is_Ignored (N, False);
24216 Set_Is_Checked (N, False);
24217 Set_Is_Ignored (N, True);
24219 end Check_Applicable_Policy;
24221 -------------------------------
24222 -- Check_External_Properties --
24223 -------------------------------
24225 procedure Check_External_Properties
24233 -- All properties enabled
24235 if AR and AW and ER and EW then
24238 -- Async_Readers + Effective_Writes
24239 -- Async_Readers + Async_Writers + Effective_Writes
24241 elsif AR and EW and not ER then
24244 -- Async_Writers + Effective_Reads
24245 -- Async_Readers + Async_Writers + Effective_Reads
24247 elsif AW and ER and not EW then
24250 -- Async_Readers + Async_Writers
24252 elsif AR and AW and not ER and not EW then
24257 elsif AR and not AW and not ER and not EW then
24262 elsif AW and not AR and not ER and not EW then
24267 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24270 end Check_External_Properties;
24276 function Check_Kind (Nam : Name_Id) return Name_Id is
24280 -- Loop through entries in check policy list
24282 PP := Opt.Check_Policy_List;
24283 while Present (PP) loop
24285 PPA : constant List_Id := Pragma_Argument_Associations (PP);
24286 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
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,
24296 Name_Loop_Invariant,
24297 Name_Loop_Variant))
24299 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
24300 when Name_On | Name_Check =>
24302 when Name_Off | Name_Ignore =>
24303 return Name_Ignore;
24304 when Name_Disable =>
24305 return Name_Disable;
24307 raise Program_Error;
24311 PP := Next_Pragma (PP);
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.
24321 if Assertions_Enabled then
24324 return Name_Ignore;
24328 ---------------------------
24329 -- Check_Missing_Part_Of --
24330 ---------------------------
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
24337 -----------------------
24338 -- Has_Visible_State --
24339 -----------------------
24341 function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is
24342 Item_Id : Entity_Id;
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.
24349 Item_Id := First_Entity (Pack_Id);
24350 while Present (Item_Id)
24351 and then not In_Private_Part (Item_Id)
24353 -- Do not consider internally generated items
24355 if not Comes_From_Source (Item_Id) then
24358 -- A visible state has been found
24360 elsif Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
24363 -- Recursively peek into nested packages and instantiations
24365 elsif Ekind (Item_Id) = E_Package
24366 and then Has_Visible_State (Item_Id)
24371 Next_Entity (Item_Id);
24375 end Has_Visible_State;
24379 Pack_Id : Entity_Id;
24380 Placement : State_Space_Kind;
24382 -- Start of processing for Check_Missing_Part_Of
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.
24389 if In_Instance then
24392 -- Do not consider internally generated entities as these can never
24393 -- have a Part_Of indicator.
24395 elsif not Comes_From_Source (Item_Id) then
24398 -- Perform these checks only when SPARK_Mode is enabled as they will
24399 -- interfere with standard Ada rules and produce false positives.
24401 elsif SPARK_Mode /= On then
24405 -- Find where the abstract state, variable or package instantiation
24406 -- lives with respect to the state space.
24408 Find_Placement_In_State_Space
24409 (Item_Id => Item_Id,
24410 Placement => Placement,
24411 Pack_Id => Pack_Id);
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
24417 if Placement = Not_In_Package then
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.
24423 elsif Placement = Body_State_Space then
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.
24431 elsif Placement = Visible_State_Space then
24432 if Is_Child_Unit (Pack_Id)
24433 and then Is_Private_Descendant (Pack_Id)
24435 -- A package instantiation does not need a Part_Of indicator when
24436 -- the related generic template has no visible state.
24438 if Ekind (Item_Id) = E_Package
24439 and then Is_Generic_Instance (Item_Id)
24440 and then not Has_Visible_State (Item_Id)
24444 -- All other cases require Part_Of
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);
24452 ("\& is declared in the visible part of private child "
24453 & "unit %", Item_Id);
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.
24460 else pragma Assert (Placement = Private_State_Space);
24462 -- The related package does not declare a state, the item cannot act
24463 -- as a Part_Of constituent.
24465 if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then
24468 -- A package instantiation does not need a Part_Of indicator when the
24469 -- related generic template has no visible state.
24471 elsif Ekind (Pack_Id) = E_Package
24472 and then Is_Generic_Instance (Pack_Id)
24473 and then not Has_Visible_State (Pack_Id)
24477 -- All other cases require Part_Of
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);
24485 ("\& is declared in the private part of package %", Item_Id);
24488 end Check_Missing_Part_Of;
24490 ---------------------------------
24491 -- Check_SPARK_Aspect_For_ASIS --
24492 ---------------------------------
24494 procedure Check_SPARK_Aspect_For_ASIS (N : Node_Id) is
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);
24505 Comps : constant List_Id := Component_Associations (Expr);
24506 Exprs : constant List_Id := Expressions (Expr);
24511 E := First (Exprs);
24512 while Present (E) loop
24517 C := First (Comps);
24518 while Present (C) loop
24519 Analyze (Expression (C));
24525 end Check_SPARK_Aspect_For_ASIS;
24527 -------------------------------------
24528 -- Check_State_And_Constituent_Use --
24529 -------------------------------------
24531 procedure Check_State_And_Constituent_Use
24532 (States : Elist_Id;
24533 Constits : Elist_Id;
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.
24542 ------------------------------
24543 -- Find_Encapsulating_State --
24544 ------------------------------
24546 function Find_Encapsulating_State
24547 (Constit_Id : Entity_Id) return Entity_Id
24549 State_Id : Entity_Id;
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.
24556 State_Id := Encapsulating_State (Constit_Id);
24557 while Present (State_Id) loop
24558 if Contains (States, State_Id) then
24562 State_Id := Encapsulating_State (State_Id);
24566 end Find_Encapsulating_State;
24570 Constit_Elmt : Elmt_Id;
24571 Constit_Id : Entity_Id;
24572 State_Id : Entity_Id;
24574 -- Start of processing for Check_State_And_Constituent_Use
24577 -- Nothing to do if there are no states or constituents
24579 if No (States) or else No (Constits) then
24583 -- Inspect the list of constituents and try to determine whether its
24584 -- encapsulating state is in list States.
24586 Constit_Elmt := First_Elmt (Constits);
24587 while Present (Constit_Elmt) loop
24588 Constit_Id := Node (Constit_Elmt);
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)).
24594 State_Id := Find_Encapsulating_State (Constit_Id);
24596 if Present (State_Id) then
24597 Error_Msg_Name_1 := Chars (Constit_Id);
24599 ("cannot mention state & and its constituent % in the same "
24600 & "context", Context, State_Id);
24604 Next_Elmt (Constit_Elmt);
24606 end Check_State_And_Constituent_Use;
24608 --------------------------
24609 -- Collect_Global_Items --
24610 --------------------------
24612 procedure Collect_Global_Items
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)
24624 procedure Process_Global_List
24626 Mode : Name_Id := Name_Input);
24627 -- Collect all items housed in a global list. Formal Mode denotes the
24628 -- current mode in effect.
24630 -------------------------
24631 -- Process_Global_List --
24632 -------------------------
24634 procedure Process_Global_List
24636 Mode : Name_Id := Name_Input)
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.
24642 -------------------------
24643 -- Process_Global_Item --
24644 -------------------------
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.
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.
24656 if Ekind (Item_Id) = E_Abstract_State then
24657 if Has_Null_Refinement (Item_Id) then
24658 Has_Null_State := True;
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;
24673 -- Add the item to the proper list
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);
24684 end Process_Global_Item;
24690 -- Start of processing for Process_Global_List
24693 if Nkind (List) = N_Null then
24696 -- Single global item declaration
24698 elsif Nkind_In (List, N_Expanded_Name,
24700 N_Selected_Component)
24702 Process_Global_Item (List, Mode);
24704 -- Single global list or moded global list declaration
24706 elsif Nkind (List) = N_Aggregate then
24708 -- The declaration of a simple global list appear as a collection
24711 if Present (Expressions (List)) then
24712 Item := First (Expressions (List));
24713 while Present (Item) loop
24714 Process_Global_Item (Item, Mode);
24719 -- The declaration of a moded global list appears as a collection
24720 -- of component associations where individual choices denote mode.
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))));
24735 raise Program_Error;
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.
24745 end Process_Global_List;
24749 Items : constant Node_Id :=
24750 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
24752 -- Start of processing for Collect_Global_Items
24755 -- Assume that no states have been encountered
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;
24763 Process_Global_List (Items);
24764 end Collect_Global_Items;
24766 ---------------------------------------
24767 -- Collect_Subprogram_Inputs_Outputs --
24768 ---------------------------------------
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)
24776 procedure Collect_Global_List
24778 Mode : Name_Id := Name_Input);
24779 -- Collect all relevant items from a global list
24781 -------------------------
24782 -- Collect_Global_List --
24783 -------------------------
24785 procedure Collect_Global_List
24787 Mode : Name_Id := Name_Input)
24789 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
24790 -- Add an item to the proper subprogram input or output collection
24792 -------------------------
24793 -- Collect_Global_Item --
24794 -------------------------
24796 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
24798 if Nam_In (Mode, Name_In_Out, Name_Input) then
24799 Add_Item (Item, Subp_Inputs);
24802 if Nam_In (Mode, Name_In_Out, Name_Output) then
24803 Add_Item (Item, Subp_Outputs);
24805 end Collect_Global_Item;
24812 -- Start of processing for Collect_Global_List
24815 if Nkind (List) = N_Null then
24818 -- Single global item declaration
24820 elsif Nkind_In (List, N_Expanded_Name,
24822 N_Selected_Component)
24824 Collect_Global_Item (List, Mode);
24826 -- Simple global list or moded global list declaration
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);
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))));
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.
24853 end Collect_Global_List;
24857 Subp_Decl : constant Node_Id := Parent (Parent (Subp_Id));
24858 Formal : Entity_Id;
24861 Spec_Id : Entity_Id;
24863 -- Start of processing for Collect_Subprogram_Inputs_Outputs
24866 Global_Seen := False;
24868 -- Find the entity of the corresponding spec when processing a body
24870 if Nkind (Subp_Decl) = N_Subprogram_Body
24871 and then Present (Corresponding_Spec (Subp_Decl))
24873 Spec_Id := Corresponding_Spec (Subp_Decl);
24875 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
24876 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
24878 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
24881 Spec_Id := Subp_Id;
24884 -- Process all formal parameters
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);
24892 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
24893 Add_Item (Formal, Subp_Outputs);
24895 -- Out parameters can act as inputs when the related type is
24896 -- tagged, unconstrained array, unconstrained record or record
24897 -- with unconstrained components.
24899 if Ekind (Formal) = E_Out_Parameter
24900 and then Is_Unconstrained_Or_Tagged_Item (Formal)
24902 Add_Item (Formal, Subp_Inputs);
24906 Next_Formal (Formal);
24909 -- When processing a subprogram body, look for pragma Refined_Global as
24910 -- it provides finer granularity of inputs and outputs.
24912 if Ekind (Subp_Id) = E_Subprogram_Body then
24913 Global := Get_Pragma (Subp_Id, Pragma_Refined_Global);
24915 -- Subprogram declaration case, look for pragma Global
24918 Global := Get_Pragma (Spec_Id, Pragma_Global);
24921 if Present (Global) then
24922 Global_Seen := True;
24923 List := Expression (First (Pragma_Argument_Associations (Global)));
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.
24929 if not Analyzed (List) then
24930 if Pragma_Name (Global) = Name_Refined_Global then
24931 Analyze_Refined_Global_In_Decl_Part (Global);
24933 Analyze_Global_In_Decl_Part (Global);
24937 -- Nothing to be done for a null global list
24939 if Nkind (List) /= N_Null then
24940 Collect_Global_List (List);
24943 end Collect_Subprogram_Inputs_Outputs;
24945 ---------------------------------
24946 -- Delay_Config_Pragma_Analyze --
24947 ---------------------------------
24949 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
24951 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
24952 Name_Priority_Specific_Dispatching);
24953 end Delay_Config_Pragma_Analyze;
24955 -------------------------------------
24956 -- Find_Related_Subprogram_Or_Body --
24957 -------------------------------------
24959 function Find_Related_Subprogram_Or_Body
24961 Do_Checks : Boolean := False) return Node_Id
24963 Context : constant Node_Id := Parent (Prag);
24964 Nam : constant Name_Id := Pragma_Name (Prag);
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]
24974 pragma Assert (Nkind (Prag) = N_Pragma);
24976 -- If the pragma is a byproduct of aspect expansion, return the related
24977 -- context of the original aspect.
24979 if Present (Corresponding_Aspect (Prag)) then
24980 return Parent (Corresponding_Aspect (Prag));
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.
24987 pragma Assert (Is_List_Member (Prag));
24989 Stmt := Prev (Prag);
24990 while Present (Stmt) loop
24992 -- Skip prior pragmas, but check for duplicates
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);
25001 -- Emit an error when a refinement pragma appears on an expression
25002 -- function without a completion.
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))
25010 Error_Msg_Name_1 := Nam;
25012 ("pragma % cannot apply to a stand alone expression function",
25017 -- The refinement pragma applies to a subprogram body stub
25019 elsif Look_For_Body
25020 and then Nkind (Stmt) = N_Subprogram_Body_Stub
25024 -- Skip internally generated code
25026 elsif not Comes_From_Source (Stmt) then
25029 -- Return the current construct which is either a subprogram body,
25030 -- a subprogram declaration or is illegal.
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.
25042 -- The pragma is associated with a library-level subprogram
25044 if Nkind (Context) = N_Compilation_Unit_Aux then
25045 return Unit (Parent (Context));
25047 -- The pragma appears inside the declarative part of a subprogram body
25049 elsif Nkind (Context) = N_Subprogram_Body then
25052 -- No candidate subprogram [body] found
25057 end Find_Related_Subprogram_Or_Body;
25059 -------------------------
25060 -- Get_Base_Subprogram --
25061 -------------------------
25063 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
25064 Result : Entity_Id;
25067 -- Follow subprogram renaming chain
25071 if Is_Subprogram (Result)
25073 Nkind (Parent (Declaration_Node (Result))) =
25074 N_Subprogram_Renaming_Declaration
25075 and then Present (Alias (Result))
25077 Result := Alias (Result);
25081 end Get_Base_Subprogram;
25083 -----------------------
25084 -- Get_SPARK_Mode_Type --
25085 -----------------------
25087 function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is
25089 if N = Name_On then
25091 elsif N = Name_Off then
25094 -- Any other argument is illegal
25097 raise Program_Error;
25099 end Get_SPARK_Mode_Type;
25101 --------------------------------
25102 -- Get_SPARK_Mode_From_Pragma --
25103 --------------------------------
25105 function Get_SPARK_Mode_From_Pragma (N : Node_Id) return SPARK_Mode_Type is
25110 pragma Assert (Nkind (N) = N_Pragma);
25111 Args := Pragma_Argument_Associations (N);
25113 -- Extract the mode from the argument list
25115 if Present (Args) then
25116 Mode := First (Pragma_Argument_Associations (N));
25117 return Get_SPARK_Mode_Type (Chars (Get_Pragma_Arg (Mode)));
25119 -- If SPARK_Mode pragma has no argument, default is ON
25124 end Get_SPARK_Mode_From_Pragma;
25126 ---------------------------
25127 -- Has_Extra_Parentheses --
25128 ---------------------------
25130 function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is
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:
25139 -- Depends (Output => Input) -- proper form
25140 -- Depends ((Output => Input)) -- extra parentheses
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
25146 if Nkind (Clause) = N_Aggregate
25147 and then Present (Expressions (Clause))
25149 Expr := First (Expressions (Clause));
25150 while Present (Expr) loop
25152 -- A dependency clause surrounded by extra parentheses appears
25153 -- as an aggregate of component associations with an optional
25154 -- Paren_Count set.
25156 if Nkind (Expr) = N_Aggregate
25157 and then Present (Component_Associations (Expr))
25160 ("dependency clause contains extra parentheses", Expr);
25162 -- Otherwise the expression is a malformed construct
25165 SPARK_Msg_N ("malformed dependency clause", Expr);
25175 end Has_Extra_Parentheses;
25181 procedure Initialize is
25192 Dummy := Dummy + 1;
25195 -----------------------------
25196 -- Is_Config_Static_String --
25197 -----------------------------
25199 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
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.
25206 ------------------------------
25207 -- Add_Config_Static_String --
25208 ------------------------------
25210 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
25217 if Nkind (N) = N_Op_Concat then
25218 if Add_Config_Static_String (Left_Opnd (N)) then
25219 N := Right_Opnd (N);
25225 if Nkind (N) /= N_String_Literal then
25226 Error_Msg_N ("string literal expected for pragma argument", N);
25230 for J in 1 .. String_Length (Strval (N)) loop
25231 C := Get_String_Char (Strval (N), J);
25233 if not In_Character_Range (C) then
25235 ("string literal contains invalid wide character",
25236 Sloc (N) + 1 + Source_Ptr (J));
25240 Add_Char_To_Name_Buffer (Get_Character (C));
25245 end Add_Config_Static_String;
25247 -- Start of processing for Is_Config_Static_String
25252 return Add_Config_Static_String (Arg);
25253 end Is_Config_Static_String;
25255 -------------------------------
25256 -- Is_Elaboration_SPARK_Mode --
25257 -------------------------------
25259 function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is
25262 (Nkind (N) = N_Pragma
25263 and then Pragma_Name (N) = Name_SPARK_Mode
25264 and then Is_List_Member (N));
25266 -- Pragma SPARK_Mode affects the elaboration of a package body when it
25267 -- appears in the statement part of the body.
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;
25277 -----------------------------------------
25278 -- Is_Non_Significant_Pragma_Reference --
25279 -----------------------------------------
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.
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)
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,
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,
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,
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,
25433 Pragma_Part_Of => -1,
25434 Pragma_Partition_Elaboration_Policy => -1,
25435 Pragma_Passive => -1,
25436 Pragma_Persistent_BSS => 0,
25437 Pragma_Polling => -1,
25439 Pragma_Postcondition => -1,
25440 Pragma_Post_Class => -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,
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);
25523 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
25532 if Nkind (P) /= N_Pragma_Argument_Association then
25536 Id := Get_Pragma_Id (Parent (P));
25537 C := Sig_Flags (Id);
25549 -- For pragma Check, the first argument is not significant,
25550 -- the second and the third (if present) arguments are
25553 when Pragma_Check =>
25555 P = First (Pragma_Argument_Associations (Parent (P)));
25558 raise Program_Error;
25562 A := First (Pragma_Argument_Associations (Parent (P)));
25563 for J in 1 .. C - 1 loop
25571 return A = P; -- is this wrong way round ???
25574 end Is_Non_Significant_Pragma_Reference;
25576 ------------------------------
25577 -- Is_Pragma_String_Literal --
25578 ------------------------------
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).
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);
25595 N := First (Assoc);
25602 if Pname = Name_Assert then
25605 elsif Pname = Name_Export then
25608 elsif Pname = Name_Ident then
25611 elsif Pname = Name_Import then
25614 elsif Pname = Name_Interface_Name then
25617 elsif Pname = Name_Linker_Alias then
25620 elsif Pname = Name_Linker_Section then
25623 elsif Pname = Name_Machine_Attribute then
25626 elsif Pname = Name_Source_File_Name then
25629 elsif Pname = Name_Source_Reference then
25632 elsif Pname = Name_Title then
25635 elsif Pname = Name_Subtitle then
25641 end Is_Pragma_String_Literal;
25643 ---------------------------
25644 -- Is_Private_SPARK_Mode --
25645 ---------------------------
25647 function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is
25650 (Nkind (N) = N_Pragma
25651 and then Pragma_Name (N) = Name_SPARK_Mode
25652 and then Is_List_Member (N));
25654 -- For pragma SPARK_Mode to be private, it has to appear in the private
25655 -- declarations of a package.
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;
25663 -------------------------------------
25664 -- Is_Unconstrained_Or_Tagged_Item --
25665 -------------------------------------
25667 function Is_Unconstrained_Or_Tagged_Item
25668 (Item : Entity_Id) return Boolean
25670 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
25671 -- Determine whether record type Typ has at least one unconstrained
25674 ---------------------------------
25675 -- Has_Unconstrained_Component --
25676 ---------------------------------
25678 function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
25682 Comp := First_Component (Typ);
25683 while Present (Comp) loop
25684 if Is_Unconstrained_Or_Tagged_Item (Comp) then
25688 Next_Component (Comp);
25692 end Has_Unconstrained_Component;
25696 Typ : constant Entity_Id := Etype (Item);
25698 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
25701 if Is_Tagged_Type (Typ) then
25704 elsif Is_Array_Type (Typ) and then not Is_Constrained (Typ) then
25707 elsif Is_Record_Type (Typ) then
25708 if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
25711 return Has_Unconstrained_Component (Typ);
25717 end Is_Unconstrained_Or_Tagged_Item;
25719 -----------------------------
25720 -- Is_Valid_Assertion_Kind --
25721 -----------------------------
25723 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
25730 Name_Static_Predicate |
25731 Name_Dynamic_Predicate |
25736 Name_Type_Invariant |
25737 Name_uType_Invariant |
25741 Name_Assert_And_Cut |
25743 Name_Contract_Cases |
25745 Name_Initial_Condition |
25748 Name_Loop_Invariant |
25749 Name_Loop_Variant |
25750 Name_Postcondition |
25751 Name_Precondition |
25753 Name_Refined_Post |
25754 Name_Statement_Assertions => return True;
25756 when others => return False;
25758 end Is_Valid_Assertion_Kind;
25760 -----------------------------------------
25761 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
25762 -----------------------------------------
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);
25769 Original_Aspects : List_Id;
25770 -- To capture global references, a copy of the created aspects must be
25771 -- inserted in the original tree.
25774 Prag_Arg_Ass : Node_Id;
25775 Prag_Id : Pragma_Id;
25778 -- Check for any PPC pragmas that appear within Decl
25780 Prag := Next (Decl);
25781 while Nkind (Prag) = N_Pragma loop
25782 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
25785 when Pragma_Postcondition | Pragma_Precondition =>
25786 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
25788 -- Make an aspect from any PPC pragma
25790 Append_To (Aspects,
25791 Make_Aspect_Specification (Loc,
25793 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
25795 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
25797 -- Generate the analysis information in the pragma expression
25798 -- and then set the pragma node analyzed to avoid any further
25801 Analyze (Expression (Prag_Arg_Ass));
25802 Set_Analyzed (Prag, True);
25804 when others => null;
25810 -- Set all new aspects into the generic declaration node
25812 if Is_Non_Empty_List (Aspects) then
25814 -- Create the list of aspects to be inserted in the original tree
25816 Original_Aspects := Copy_Separate_List (Aspects);
25818 -- Check if Decl already has aspects
25820 -- Attach the new lists of aspects to both the generic copy and the
25823 if Has_Aspects (Decl) then
25824 Append_List (Aspects, Aspect_Specifications (Decl));
25825 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
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);
25834 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
25836 -------------------------
25837 -- Preanalyze_CTC_Args --
25838 -------------------------
25840 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
25842 -- Preanalyze the boolean expressions, we treat these as spec
25843 -- expressions (i.e. similar to a default expression).
25845 if Present (Arg_Req) then
25846 Preanalyze_Assert_Expression
25847 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
25849 -- In ASIS mode, for a pragma generated from a source aspect, also
25850 -- analyze the original aspect expression.
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);
25858 if Present (Arg_Ens) then
25859 Preanalyze_Assert_Expression
25860 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
25862 -- In ASIS mode, for a pragma generated from a source aspect, also
25863 -- analyze the original aspect expression.
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);
25870 end Preanalyze_CTC_Args;
25872 --------------------------------------
25873 -- Process_Compilation_Unit_Pragmas --
25874 --------------------------------------
25876 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
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.
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)))));
25895 -- Nothing else to do at the current time
25897 end Process_Compilation_Unit_Pragmas;
25899 ------------------------------------
25900 -- Record_Possible_Body_Reference --
25901 ------------------------------------
25903 procedure Record_Possible_Body_Reference
25904 (State_Id : Entity_Id;
25908 Spec_Id : Entity_Id;
25911 -- Ensure that we are dealing with a reference to a state
25913 pragma Assert (Ekind (State_Id) = E_Abstract_State);
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.
25923 while Present (Context) loop
25924 if Nkind (Context) = N_Package_Body then
25925 Spec_Id := Corresponding_Spec (Context);
25927 if Present (Abstract_States (Spec_Id))
25928 and then Contains (Abstract_States (Spec_Id), State_Id)
25930 if No (Body_References (State_Id)) then
25931 Set_Body_References (State_Id, New_Elmt_List);
25934 Append_Elmt (Ref, Body_References (State_Id));
25939 Context := Parent (Context);
25941 end Record_Possible_Body_Reference;
25943 ------------------------------
25944 -- Relocate_Pragmas_To_Body --
25945 ------------------------------
25947 procedure Relocate_Pragmas_To_Body
25948 (Subp_Body : Node_Id;
25949 Target_Body : Node_Id := Empty)
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).
25955 ---------------------
25956 -- Relocate_Pragma --
25957 ---------------------
25959 procedure Relocate_Pragma (Prag : Node_Id) is
25964 -- When subprogram stubs or expression functions are involves, the
25965 -- destination declaration list belongs to the proper body.
25967 if Present (Target_Body) then
25968 Target := Target_Body;
25970 Target := Subp_Body;
25973 Decls := Declarations (Target);
25977 Set_Declarations (Target, Decls);
25980 -- Unhook the pragma from its current list
25983 Prepend (Prag, Decls);
25984 end Relocate_Pragma;
25988 Body_Id : constant Entity_Id :=
25989 Defining_Unit_Name (Specification (Subp_Body));
25990 Next_Stmt : Node_Id;
25993 -- Start of processing for Relocate_Pragmas_To_Body
25996 -- Do not process a body that comes from a separate unit as no construct
25997 -- can possibly follow it.
25999 if not Is_List_Member (Subp_Body) then
26002 -- Do not relocate pragmas that follow a stub if the stub does not have
26005 elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub
26006 and then No (Target_Body)
26010 -- Do not process internally generated routine _Postconditions
26012 elsif Ekind (Body_Id) = E_Procedure
26013 and then Chars (Body_Id) = Name_uPostconditions
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].
26022 Stmt := Next (Subp_Body);
26023 while Present (Stmt) loop
26025 -- Preserve the following statement for iteration purposes due to a
26026 -- possible relocation of a pragma.
26028 Next_Stmt := Next (Stmt);
26030 -- Move a candidate pragma following the body to the declarations of
26033 if Nkind (Stmt) = N_Pragma
26034 and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt))
26036 Relocate_Pragma (Stmt);
26038 -- Skip internally generated code
26040 elsif not Comes_From_Source (Stmt) then
26043 -- No candidate pragmas are available for relocation
26051 end Relocate_Pragmas_To_Body;
26053 -------------------
26054 -- Resolve_State --
26055 -------------------
26057 procedure Resolve_State (N : Node_Id) is
26062 if Is_Entity_Name (N) and then Present (Entity (N)) then
26063 Func := Entity (N);
26065 -- Handle overloading of state names by functions. Traverse the
26066 -- homonym chain looking for an abstract state.
26068 if Ekind (Func) = E_Function and then Has_Homonym (Func) then
26069 State := Homonym (Func);
26070 while Present (State) loop
26072 -- Resolve the overloading by setting the proper entity of the
26073 -- reference to that of the state.
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);
26082 State := Homonym (State);
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.
26089 raise Program_Error;
26094 ----------------------------
26095 -- Rewrite_Assertion_Kind --
26096 ----------------------------
26098 procedure Rewrite_Assertion_Kind (N : Node_Id) is
26102 if Nkind (N) = N_Attribute_Reference
26103 and then Attribute_Name (N) = Name_Class
26104 and then Nkind (Prefix (N)) = N_Identifier
26106 case Chars (Prefix (N)) is
26111 when Name_Type_Invariant =>
26112 Nam := Name_uType_Invariant;
26113 when Name_Invariant =>
26114 Nam := Name_uInvariant;
26119 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
26121 end Rewrite_Assertion_Kind;
26129 Dummy := Dummy + 1;
26132 --------------------------------
26133 -- Set_Encoded_Interface_Name --
26134 --------------------------------
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);
26143 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
26146 -- Stores encoded value of character code CC. The encoding we use an
26147 -- underscore followed by four lower case hex digits.
26153 procedure Encode is
26155 Store_String_Char (Get_Char_Code ('_'));
26157 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
26159 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
26161 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
26163 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
26166 -- Start of processing for Set_Encoded_Interface_Name
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.
26175 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
26176 or else VM_Target /= No_VM
26177 or else AAMP_On_Target
26179 Set_Interface_Name (E, S);
26184 CC := Get_String_Char (Str, J);
26186 exit when not In_Character_Range (CC);
26188 C := Get_Character (CC);
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';
26196 Set_Interface_Name (E, S);
26204 -- Here we need to encode. The encoding we use as follows:
26205 -- three underscores + four hex digits (lower case)
26209 for J in 1 .. String_Length (Str) loop
26210 CC := Get_String_Char (Str, J);
26212 if not In_Character_Range (CC) then
26215 C := Get_Character (CC);
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'
26222 Store_String_Char (CC);
26229 Set_Interface_Name (E,
26230 Make_String_Literal (Sloc (S),
26231 Strval => End_String));
26233 end Set_Encoded_Interface_Name;
26235 -------------------
26236 -- Set_Unit_Name --
26237 -------------------
26239 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
26244 if Nkind (N) = N_Identifier
26245 and then Nkind (With_Item) = N_Identifier
26247 Set_Entity (N, Entity (With_Item));
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));
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);
26264 Set_Entity (Pref, Scop);