1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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;
51 with Output; use Output;
52 with Par_SCO; use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident; use Rident;
55 with Rtsfind; use Rtsfind;
57 with Sem_Aux; use Sem_Aux;
58 with Sem_Ch3; use Sem_Ch3;
59 with Sem_Ch6; use Sem_Ch6;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res; use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand; use Stand;
75 with Sinfo; use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput; use Sinput;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
80 with Stylesw; use Stylesw;
82 with Targparm; use Targparm;
83 with Tbuild; use Tbuild;
85 with Uintp; use Uintp;
86 with Uname; use Uname;
87 with Urealp; use Urealp;
88 with Validsw; use Validsw;
89 with Warnsw; use Warnsw;
91 package body Sem_Prag is
93 ----------------------------------------------
94 -- Common Handling of Import-Export Pragmas --
95 ----------------------------------------------
97 -- In the following section, a number of Import_xxx and Export_xxx pragmas
98 -- are defined by GNAT. These are compatible with the DEC pragmas of the
99 -- same name, and all have the following common form and processing:
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
107 -- [Internal =>] LOCAL_NAME
108 -- [, [External =>] EXTERNAL_SYMBOL]
109 -- [, other optional parameters ]);
111 -- EXTERNAL_SYMBOL ::=
113 -- | static_string_EXPRESSION
115 -- The internal LOCAL_NAME designates the entity that is imported or
116 -- exported, and must refer to an entity in the current declarative
117 -- part (as required by the rules for LOCAL_NAME).
119 -- The external linker name is designated by the External parameter if
120 -- given, or the Internal parameter if not (if there is no External
121 -- parameter, the External parameter is a copy of the Internal name).
123 -- If the External parameter is given as a string, then this string is
124 -- treated as an external name (exactly as though it had been given as an
125 -- External_Name parameter for a normal Import pragma).
127 -- If the External parameter is given as an identifier (or there is no
128 -- External parameter, so that the Internal identifier is used), then
129 -- the external name is the characters of the identifier, translated
130 -- to all upper case letters for OpenVMS versions of GNAT, and to all
131 -- lower case letters for all other versions
133 -- Note: the external name specified or implied by any of these special
134 -- Import_xxx or Export_xxx pragmas override an external or link name
135 -- specified in a previous Import or Export pragma.
137 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
138 -- named notation, following the standard rules for subprogram calls, i.e.
139 -- parameters can be given in any order if named notation is used, and
140 -- positional and named notation can be mixed, subject to the rule that all
141 -- positional parameters must appear first.
143 -- Note: All these pragmas are implemented exactly following the DEC design
144 -- and implementation and are intended to be fully compatible with the use
145 -- of these pragmas in the DEC Ada compiler.
147 --------------------------------------------
148 -- Checking for Duplicated External Names --
149 --------------------------------------------
151 -- It is suspicious if two separate Export pragmas use the same external
152 -- name. The following table is used to diagnose this situation so that
153 -- an appropriate warning can be issued.
155 -- The Node_Id stored is for the N_String_Literal node created to hold
156 -- the value of the external name. The Sloc of this node is used to
157 -- cross-reference the location of the duplication.
159 package Externals is new Table.Table (
160 Table_Component_Type => Node_Id,
161 Table_Index_Type => Int,
162 Table_Low_Bound => 0,
163 Table_Initial => 100,
164 Table_Increment => 100,
165 Table_Name => "Name_Externals");
167 -------------------------------------
168 -- Local Subprograms and Variables --
169 -------------------------------------
171 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
172 -- Subsidiary routine to the analysis of pragmas Depends and Global. Append
173 -- an input or output item to a list. If the list is empty, a new one is
176 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
177 -- This routine is used for possible casing adjustment of an explicit
178 -- external name supplied as a string literal (the node N), according to
179 -- the casing requirement of Opt.External_Name_Casing. If this is set to
180 -- As_Is, then the string literal is returned unchanged, but if it is set
181 -- to Uppercase or Lowercase, then a new string literal with appropriate
182 -- casing is constructed.
184 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
185 -- Subsidiary to the analysis of pragma Global and pragma Depends. Query
186 -- whether a particular item appears in a mixed list of nodes and entities.
187 -- It is assumed that all nodes in the list have entities.
189 procedure Collect_Subprogram_Inputs_Outputs
190 (Subp_Id : Entity_Id;
191 Subp_Inputs : in out Elist_Id;
192 Subp_Outputs : in out Elist_Id;
193 Global_Seen : out Boolean);
194 -- Subsidiary to the analysis of pragma Global and pragma Depends. Gather
195 -- all inputs and outputs of subprogram Subp_Id in lists Subp_Inputs and
196 -- Subp_Outputs. If the case where the subprogram has no inputs and/or
197 -- outputs, the corresponding returned list is No_Elist. Flag Global_Seen
198 -- is set when the related subprogram has aspect/pragma Global.
200 function Find_Related_Subprogram
202 Check_Duplicates : Boolean := False) return Node_Id;
203 -- Find the declaration of the related subprogram subject to pragma Prag.
204 -- If flag Check_Duplicates is set, the routine emits errors concerning
205 -- duplicate pragmas. If a related subprogram is found, then either the
206 -- corresponding N_Subprogram_Declaration node is returned, or, if the
207 -- pragma applies to a subprogram body, then the N_Subprogram_Body node
208 -- is returned. Note that in the latter case, no check is made to ensure
209 -- that there is no separate declaration of the subprogram.
211 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
212 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
213 -- original one, following the renaming chain) is returned. Otherwise the
214 -- entity is returned unchanged. Should be in Einfo???
216 function Original_Name (N : Node_Id) return Name_Id;
217 -- N is a pragma node or aspect specification node. This function returns
218 -- the name of the pragma or aspect in original source form, taking into
219 -- account possible rewrites, and also cases where a pragma comes from an
220 -- aspect (in such cases, the name can be different from the pragma name,
221 -- e.g. a Pre aspect generates a Precondition pragma). This also deals with
222 -- the presence of 'Class, which results in one of the special names
223 -- Name_uPre, Name_uPost, Name_uInvariant, or Name_uType_Invariant being
224 -- returned to represent the corresponding aspects with x'Class names.
226 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
227 -- Preanalyze the boolean expressions in the Requires and Ensures arguments
228 -- of a Test_Case pragma if present (possibly Empty). We treat these as
229 -- spec expressions (i.e. similar to a default expression).
231 procedure Rewrite_Assertion_Kind (N : Node_Id);
232 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
233 -- then it is rewritten as an identifier with the corresponding special
234 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
235 -- Check, Check_Policy.
238 -- This is a dummy function called by the processing for pragma Reviewable.
239 -- It is there for assisting front end debugging. By placing a Reviewable
240 -- pragma in the source program, a breakpoint on rv catches this place in
241 -- the source, allowing convenient stepping to the point of interest.
243 function Requires_Profile_Installation
245 Subp : Node_Id) return Boolean;
246 -- Subsidiary routine to the analysis of pragma Depends and pragma Global.
247 -- Determine whether the profile of subprogram Subp must be installed into
248 -- visibility to access its formals from pragma Prag.
250 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
251 -- Place semantic information on the argument of an Elaborate/Elaborate_All
252 -- pragma. Entity name for unit and its parents is taken from item in
253 -- previous with_clause that mentions the unit.
259 procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
262 To_List := New_Elmt_List;
265 Append_Unique_Elmt (Item, To_List);
268 -------------------------------
269 -- Adjust_External_Name_Case --
270 -------------------------------
272 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
276 -- Adjust case of literal if required
278 if Opt.External_Name_Exp_Casing = As_Is then
282 -- Copy existing string
288 for J in 1 .. String_Length (Strval (N)) loop
289 CC := Get_String_Char (Strval (N), J);
291 if Opt.External_Name_Exp_Casing = Uppercase
292 and then CC >= Get_Char_Code ('a')
293 and then CC <= Get_Char_Code ('z')
295 Store_String_Char (CC - 32);
297 elsif Opt.External_Name_Exp_Casing = Lowercase
298 and then CC >= Get_Char_Code ('A')
299 and then CC <= Get_Char_Code ('Z')
301 Store_String_Char (CC + 32);
304 Store_String_Char (CC);
309 Make_String_Literal (Sloc (N),
310 Strval => End_String);
312 end Adjust_External_Name_Case;
314 -----------------------------------------
315 -- Analyze_Contract_Cases_In_Decl_Part --
316 -----------------------------------------
318 procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
319 Others_Seen : Boolean := False;
321 procedure Analyze_Contract_Case (CCase : Node_Id);
322 -- Verify the legality of a single contract case
324 ---------------------------
325 -- Analyze_Contract_Case --
326 ---------------------------
328 procedure Analyze_Contract_Case (CCase : Node_Id) is
329 Case_Guard : Node_Id;
331 Extra_Guard : Node_Id;
334 if Nkind (CCase) = N_Component_Association then
335 Case_Guard := First (Choices (CCase));
336 Conseq := Expression (CCase);
338 -- Each contract case must have exactly one case guard
340 Extra_Guard := Next (Case_Guard);
342 if Present (Extra_Guard) then
344 ("contract case may have only one case guard", Extra_Guard);
347 -- Check the placement of "others" (if available)
349 if Nkind (Case_Guard) = N_Others_Choice then
352 ("only one others choice allowed in aspect Contract_Cases",
358 elsif Others_Seen then
360 ("others must be the last choice in aspect Contract_Cases",
364 -- Preanalyze the case guard and consequence
366 if Nkind (Case_Guard) /= N_Others_Choice then
367 Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
370 Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
372 -- The contract case is malformed
375 Error_Msg_N ("wrong syntax in contract case", CCase);
377 end Analyze_Contract_Case;
381 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
387 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
392 Subp_Decl := Find_Related_Subprogram (N);
393 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
394 All_Cases := Expression (Arg1);
396 -- Multiple contract cases appear in aggregate form
398 if Nkind (All_Cases) = N_Aggregate then
399 if No (Component_Associations (All_Cases)) then
400 Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
402 -- Individual contract cases appear as component associations
405 -- Ensure that the formal parameters are visible when analyzing
406 -- all clauses. This falls out of the general rule of aspects
407 -- pertaining to subprogram declarations. Skip the installation
408 -- for subprogram bodies because the formals are already visible.
410 if Requires_Profile_Installation (N, Subp_Decl) then
411 Push_Scope (Subp_Id);
412 Install_Formals (Subp_Id);
415 CCase := First (Component_Associations (All_Cases));
416 while Present (CCase) loop
417 Analyze_Contract_Case (CCase);
421 if Requires_Profile_Installation (N, Subp_Decl) then
427 Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
429 end Analyze_Contract_Cases_In_Decl_Part;
431 ----------------------------------
432 -- Analyze_Depends_In_Decl_Part --
433 ----------------------------------
435 procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
436 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
437 Loc : constant Source_Ptr := Sloc (N);
439 All_Inputs_Seen : Elist_Id := No_Elist;
440 -- A list containing the entities of all the inputs processed so far.
441 -- This Elist is populated with unique entities because the same input
442 -- may appear in multiple input lists.
444 Global_Seen : Boolean := False;
445 -- A flag set when pragma Global has been processed
447 Outputs_Seen : Elist_Id := No_Elist;
448 -- A list containing the entities of all the outputs processed so far.
449 -- The elements of this list may come from different output lists.
451 Null_Output_Seen : Boolean := False;
452 -- A flag used to track the legality of a null output
454 Result_Seen : Boolean := False;
455 -- A flag set when Subp_Id'Result is processed
458 -- The entity of the subprogram subject to pragma Depends
460 Subp_Inputs : Elist_Id := No_Elist;
461 Subp_Outputs : Elist_Id := No_Elist;
462 -- Two lists containing the full set of inputs and output of the related
463 -- subprograms. Note that these lists contain both nodes and entities.
465 procedure Analyze_Dependency_Clause
468 -- Verify the legality of a single dependency clause. Flag Is_Last
469 -- denotes whether Clause is the last clause in the relation.
471 procedure Check_Function_Return;
472 -- Verify that Funtion'Result appears as one of the outputs
479 -- Ensure that an item has a proper "in", "in out" or "out" mode
480 -- depending on its function. If this is not the case, emit an error.
481 -- Item and Item_Id denote the attributes of an item. Flag Is_Input
482 -- should be set when item comes from an input list. Flag Self_Ref
483 -- should be set when the item is an output and the dependency clause
486 procedure Check_Usage
487 (Subp_Items : Elist_Id;
488 Used_Items : Elist_Id;
490 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
491 -- error if this is not the case.
493 procedure Normalize_Clause (Clause : Node_Id);
494 -- Remove a self-dependency "+" from the input list of a clause.
495 -- Depending on the contents of the relation, either split the the
496 -- clause into multiple smaller clauses or perform the normalization in
499 -------------------------------
500 -- Analyze_Dependency_Clause --
501 -------------------------------
503 procedure Analyze_Dependency_Clause
507 procedure Analyze_Input_List (Inputs : Node_Id);
508 -- Verify the legality of a single input list
510 procedure Analyze_Input_Output
515 Seen : in out Elist_Id;
516 Null_Seen : in out Boolean);
517 -- Verify the legality of a single input or output item. Flag
518 -- Is_Input should be set whenever Item is an input, False when it
519 -- denotes an output. Flag Self_Ref should be set when the item is an
520 -- output and the dependency clause has a "+". Flag Top_Level should
521 -- be set whenever Item appears immediately within an input or output
522 -- list. Seen is a collection of all abstract states, variables and
523 -- formals processed so far. Flag Null_Seen denotes whether a null
524 -- input or output has been encountered.
526 ------------------------
527 -- Analyze_Input_List --
528 ------------------------
530 procedure Analyze_Input_List (Inputs : Node_Id) is
531 Inputs_Seen : Elist_Id := No_Elist;
532 -- A list containing the entities of all inputs that appear in the
533 -- current input list.
535 Null_Input_Seen : Boolean := False;
536 -- A flag used to track the legality of a null input
541 -- Multiple inputs appear as an aggregate
543 if Nkind (Inputs) = N_Aggregate then
544 if Present (Component_Associations (Inputs)) then
546 ("nested dependency relations not allowed", Inputs);
548 elsif Present (Expressions (Inputs)) then
549 Input := First (Expressions (Inputs));
550 while Present (Input) loop
557 Null_Seen => Null_Input_Seen);
563 Error_Msg_N ("malformed input dependency list", Inputs);
566 -- Process a solitary input
575 Null_Seen => Null_Input_Seen);
578 -- Detect an illegal dependency clause of the form
582 if Null_Output_Seen and then Null_Input_Seen then
584 ("null dependency clause cannot have a null input list",
587 end Analyze_Input_List;
589 --------------------------
590 -- Analyze_Input_Output --
591 --------------------------
593 procedure Analyze_Input_Output
598 Seen : in out Elist_Id;
599 Null_Seen : in out Boolean)
601 Is_Output : constant Boolean := not Is_Input;
606 -- Multiple input or output items appear as an aggregate
608 if Nkind (Item) = N_Aggregate then
609 if not Top_Level then
610 Error_Msg_N ("nested grouping of items not allowed", Item);
612 elsif Present (Component_Associations (Item)) then
614 ("nested dependency relations not allowed", Item);
616 -- Recursively analyze the grouped items
618 elsif Present (Expressions (Item)) then
619 Grouped := First (Expressions (Item));
620 while Present (Grouped) loop
623 Is_Input => Is_Input,
624 Self_Ref => Self_Ref,
627 Null_Seen => Null_Seen);
633 Error_Msg_N ("malformed dependency list", Item);
636 -- Process Function'Result in the context of a dependency clause
638 elsif Nkind (Item) = N_Attribute_Reference
639 and then Attribute_Name (Item) = Name_Result
641 -- It is sufficent to analyze the prefix of 'Result in order to
642 -- establish legality of the attribute.
644 Analyze (Prefix (Item));
646 -- The prefix of 'Result must denote the function for which
647 -- aspect/pragma Depends applies.
649 if not Is_Entity_Name (Prefix (Item))
650 or else Ekind (Subp_Id) /= E_Function
651 or else Entity (Prefix (Item)) /= Subp_Id
653 Error_Msg_Name_1 := Name_Result;
655 ("prefix of attribute % must denote the enclosing "
658 -- Function'Result is allowed to appear on the output side of a
659 -- dependency clause.
662 Error_Msg_N ("function result cannot act as input", Item);
668 -- Detect multiple uses of null in a single dependency list or
669 -- throughout the whole relation. Verify the placement of a null
670 -- output list relative to the other clauses.
672 elsif Nkind (Item) = N_Null then
675 ("multiple null dependency relations not allowed", Item);
679 if Is_Output and then not Is_Last then
681 ("null output list must be the last clause in a "
682 & "dependency relation", Item);
691 -- Find the entity of the item. If this is a renaming, climb
692 -- the renaming chain to reach the root object. Renamings of
693 -- non-entire objects do not yield an entity (Empty).
695 Item_Id := Entity_Of (Item);
697 if Present (Item_Id) then
698 if Ekind_In (Item_Id, E_Abstract_State,
704 -- Ensure that the item is of the correct mode depending
707 Check_Mode (Item, Item_Id, Is_Input, Self_Ref);
709 -- Detect multiple uses of the same state, variable or
710 -- formal parameter. If this is not the case, add the
711 -- item to the list of processed relations.
713 if Contains (Seen, Item_Id) then
714 Error_Msg_N ("duplicate use of item", Item);
716 Add_Item (Item_Id, Seen);
719 -- Detect an illegal use of an input related to a null
720 -- output. Such input items cannot appear in other input
724 and then Contains (All_Inputs_Seen, Item_Id)
727 ("input of a null output list appears in multiple "
728 & "input lists", Item);
730 Add_Item (Item_Id, All_Inputs_Seen);
733 -- When the item renames an entire object, replace the
734 -- item with a reference to the object.
736 if Present (Renamed_Object (Entity (Item))) then
738 New_Reference_To (Item_Id, Sloc (Item)));
742 -- All other input/output items are illegal
746 ("item must denote variable, state or formal "
747 & "parameter", Item);
750 -- All other input/output items are illegal
754 ("item must denote variable, state or formal parameter",
758 end Analyze_Input_Output;
766 -- Start of processing for Analyze_Dependency_Clause
769 Inputs := Expression (Clause);
772 -- An input list with a self-dependency appears as operator "+" where
773 -- the actuals inputs are the right operand.
775 if Nkind (Inputs) = N_Op_Plus then
776 Inputs := Right_Opnd (Inputs);
780 -- Process the output_list of a dependency_clause
782 Output := First (Choices (Clause));
783 while Present (Output) loop
787 Self_Ref => Self_Ref,
789 Seen => Outputs_Seen,
790 Null_Seen => Null_Output_Seen);
795 -- Process the input_list of a dependency_clause
797 Analyze_Input_List (Inputs);
798 end Analyze_Dependency_Clause;
800 ----------------------------
801 -- Check_Function_Return --
802 ----------------------------
804 procedure Check_Function_Return is
806 if Ekind (Subp_Id) = E_Function and then not Result_Seen then
808 ("result of & must appear in exactly one output list",
811 end Check_Function_Return;
827 if Ekind (Item_Id) = E_Out_Parameter
829 and then not Appears_In (Subp_Inputs, Item_Id))
832 ("item & must have mode in or in out", Item, Item_Id);
835 -- Self-referential output
839 -- A self-referential state or variable must appear in both input
840 -- and output lists of a subprogram.
842 if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
845 (Appears_In (Subp_Inputs, Item_Id)
847 Appears_In (Subp_Outputs, Item_Id))
849 Error_Msg_NE ("item & must have mode in out", Item, Item_Id);
852 -- Self-referential parameter
854 elsif Ekind (Item_Id) /= E_In_Out_Parameter then
855 Error_Msg_NE ("item & must have mode in out", Item, Item_Id);
860 elsif Ekind (Item_Id) = E_In_Parameter
862 (Global_Seen and then not Appears_In (Subp_Outputs, Item_Id))
865 ("item & must have mode out or in out", Item, Item_Id);
873 procedure Check_Usage
874 (Subp_Items : Elist_Id;
875 Used_Items : Elist_Id;
878 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
879 -- Emit an error concerning the erroneous usage of an item
885 procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
889 ("item & must appear in at least one input list of aspect "
890 & "Depends", Item, Item_Id);
893 ("item & must appear in exactly one output list of aspect "
894 & "Depends", Item, Item_Id);
904 -- Start of processing for Check_Usage
907 if No (Subp_Items) then
911 -- Each input or output of the subprogram must appear in a dependency
914 Elmt := First_Elmt (Subp_Items);
915 while Present (Elmt) loop
918 if Nkind (Item) = N_Defining_Identifier then
921 Item_Id := Entity (Item);
924 -- The item does not appear in a dependency
926 if not Contains (Used_Items, Item_Id) then
927 if Is_Formal (Item_Id) then
928 Usage_Error (Item, Item_Id);
930 -- States and global variables are not used properly only when
931 -- the subprogram is subject to pragma Global.
933 elsif Global_Seen then
934 Usage_Error (Item, Item_Id);
942 ----------------------
943 -- Normalize_Clause --
944 ----------------------
946 procedure Normalize_Clause (Clause : Node_Id) is
947 procedure Create_Or_Modify_Clause
954 -- Create a brand new clause to represent the self-reference or
955 -- modify the input and/or output lists of an existing clause. Output
956 -- denotes a self-referencial output. Outputs is the output list of a
957 -- clause. Inputs is the input list of a clause. After denotes the
958 -- clause after which the new clause is to be inserted. Flag In_Place
959 -- should be set when normalizing the last output of an output list.
960 -- Flag Multiple should be set when Output comes from a list with
963 -----------------------------
964 -- Create_Or_Modify_Clause --
965 -----------------------------
967 procedure Create_Or_Modify_Clause
975 procedure Propagate_Output
978 -- Handle the various cases of output propagation to the input
979 -- list. Output denotes a self-referencial output item. Inputs is
980 -- the input list of a clause.
982 ----------------------
983 -- Propagate_Output --
984 ----------------------
986 procedure Propagate_Output
990 function In_Input_List
992 Inputs : List_Id) return Boolean;
993 -- Determine whether a particulat item appears in the input
1000 function In_Input_List
1002 Inputs : List_Id) return Boolean
1007 Elmt := First (Inputs);
1008 while Present (Elmt) loop
1009 if Entity_Of (Elmt) = Item then
1021 Output_Id : constant Entity_Id := Entity_Of (Output);
1024 -- Start of processing for Propagate_Output
1027 -- The clause is of the form:
1029 -- (Output =>+ null)
1031 -- Remove the null input and replace it with a copy of the
1034 -- (Output => Output)
1036 if Nkind (Inputs) = N_Null then
1037 Rewrite (Inputs, New_Copy_Tree (Output));
1039 -- The clause is of the form:
1041 -- (Output =>+ (Input1, ..., InputN))
1043 -- Determine whether the output is not already mentioned in the
1044 -- input list and if not, add it to the list of inputs:
1046 -- (Output => (Output, Input1, ..., InputN))
1048 elsif Nkind (Inputs) = N_Aggregate then
1049 Grouped := Expressions (Inputs);
1051 if not In_Input_List
1055 Prepend_To (Grouped, New_Copy_Tree (Output));
1058 -- The clause is of the form:
1060 -- (Output =>+ Input)
1062 -- If the input does not mention the output, group the two
1065 -- (Output => (Output, Input))
1067 elsif Entity_Of (Inputs) /= Output_Id then
1069 Make_Aggregate (Loc,
1070 Expressions => New_List (
1071 New_Copy_Tree (Output),
1072 New_Copy_Tree (Inputs))));
1074 end Propagate_Output;
1078 Loc : constant Source_Ptr := Sloc (Output);
1081 -- Start of processing for Create_Or_Modify_Clause
1084 -- A function result cannot depend on itself because it cannot
1085 -- appear in the input list of a relation.
1087 if Nkind (Output) = N_Attribute_Reference
1088 and then Attribute_Name (Output) = Name_Result
1090 Error_Msg_N ("function result cannot depend on itself", Output);
1093 -- A null output depending on itself does not require any
1096 elsif Nkind (Output) = N_Null then
1100 -- When performing the transformation in place, simply add the
1101 -- output to the list of inputs (if not already there). This case
1102 -- arises when dealing with the last output of an output list -
1103 -- we perform the normalization in place to avoid generating a
1107 Propagate_Output (Output, Inputs);
1109 -- A list with multiple outputs is slowly trimmed until only
1110 -- one element remains. When this happens, replace the
1111 -- aggregate with the element itself.
1115 Rewrite (Outputs, Output);
1121 -- Unchain the output from its output list as it will appear in
1122 -- a new clause. Note that we cannot simply rewrite the output
1123 -- as null because this will violate the semantics of aspect or
1128 -- Create a new clause of the form:
1130 -- (Output => Inputs)
1133 Make_Component_Association (Loc,
1134 Choices => New_List (Output),
1135 Expression => New_Copy_Tree (Inputs));
1137 -- The new clause contains replicated content that has already
1138 -- been analyzed. There is not need to reanalyze it or
1139 -- renormalize it again.
1141 Set_Analyzed (Clause);
1144 (Output => First (Choices (Clause)),
1145 Inputs => Expression (Clause));
1147 Insert_After (After, Clause);
1149 end Create_Or_Modify_Clause;
1153 Outputs : constant Node_Id := First (Choices (Clause));
1155 Last_Output : Node_Id;
1156 Next_Output : Node_Id;
1159 -- Start of processing for Normalize_Clause
1162 -- A self-dependency appears as operator "+". Remove the "+" from the
1163 -- tree by moving the real inputs to their proper place.
1165 if Nkind (Expression (Clause)) = N_Op_Plus then
1166 Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1167 Inputs := Expression (Clause);
1169 -- Multiple outputs appear as an aggregate
1171 if Nkind (Outputs) = N_Aggregate then
1172 Last_Output := Last (Expressions (Outputs));
1174 Output := First (Expressions (Outputs));
1175 while Present (Output) loop
1177 -- Normalization may remove an output from its list,
1178 -- preserve the subsequent output now.
1180 Next_Output := Next (Output);
1182 Create_Or_Modify_Clause
1187 In_Place => Output = Last_Output,
1190 Output := Next_Output;
1196 Create_Or_Modify_Clause
1205 end Normalize_Clause;
1211 Last_Clause : Node_Id;
1212 Subp_Decl : Node_Id;
1214 -- Start of processing for Analyze_Depends_In_Decl_Part
1219 Subp_Decl := Find_Related_Subprogram (N);
1220 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
1221 Clause := Expression (Arg1);
1223 -- Empty dependency list
1225 if Nkind (Clause) = N_Null then
1227 -- Gather all states, variables and formal parameters that the
1228 -- subprogram may depend on. These items are obtained from the
1229 -- parameter profile or pragma Global (if available).
1231 Collect_Subprogram_Inputs_Outputs
1232 (Subp_Id => Subp_Id,
1233 Subp_Inputs => Subp_Inputs,
1234 Subp_Outputs => Subp_Outputs,
1235 Global_Seen => Global_Seen);
1237 -- Verify that every input or output of the subprogram appear in a
1240 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1241 Check_Usage (Subp_Outputs, Outputs_Seen, False);
1242 Check_Function_Return;
1244 -- Dependency clauses appear as component associations of an aggregate
1246 elsif Nkind (Clause) = N_Aggregate
1247 and then Present (Component_Associations (Clause))
1249 Last_Clause := Last (Component_Associations (Clause));
1251 -- Gather all states, variables and formal parameters that the
1252 -- subprogram may depend on. These items are obtained from the
1253 -- parameter profile or pragma Global (if available).
1255 Collect_Subprogram_Inputs_Outputs
1256 (Subp_Id => Subp_Id,
1257 Subp_Inputs => Subp_Inputs,
1258 Subp_Outputs => Subp_Outputs,
1259 Global_Seen => Global_Seen);
1261 -- Ensure that the formal parameters are visible when analyzing all
1262 -- clauses. This falls out of the general rule of aspects pertaining
1263 -- to subprogram declarations. Skip the installation for subprogram
1264 -- bodies because the formals are already visible.
1266 if Requires_Profile_Installation (N, Subp_Decl) then
1267 Push_Scope (Subp_Id);
1268 Install_Formals (Subp_Id);
1271 Clause := First (Component_Associations (Clause));
1272 while Present (Clause) loop
1273 Errors := Serious_Errors_Detected;
1275 -- Normalization may create extra clauses that contain replicated
1276 -- input and output names. There is no need to reanalyze or
1277 -- renormalize these extra clauses.
1279 if not Analyzed (Clause) then
1280 Set_Analyzed (Clause);
1282 Analyze_Dependency_Clause
1284 Is_Last => Clause = Last_Clause);
1286 -- Do not normalize an erroneous clause because the inputs or
1287 -- outputs may denote illegal items.
1289 if Errors = Serious_Errors_Detected then
1290 Normalize_Clause (Clause);
1297 if Requires_Profile_Installation (N, Subp_Decl) then
1301 -- Verify that every input or output of the subprogram appear in a
1304 Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1305 Check_Usage (Subp_Outputs, Outputs_Seen, False);
1306 Check_Function_Return;
1308 -- The top level dependency relation is malformed
1311 Error_Msg_N ("malformed dependency relation", Clause);
1313 end Analyze_Depends_In_Decl_Part;
1315 ---------------------------------
1316 -- Analyze_Global_In_Decl_Part --
1317 ---------------------------------
1319 procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1320 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1322 Seen : Elist_Id := No_Elist;
1323 -- A list containing the entities of all the items processed so far. It
1324 -- plays a role in detecting distinct entities.
1326 Subp_Id : Entity_Id;
1327 -- The entity of the subprogram subject to pragma Global
1329 Contract_Seen : Boolean := False;
1330 In_Out_Seen : Boolean := False;
1331 Input_Seen : Boolean := False;
1332 Output_Seen : Boolean := False;
1333 -- Flags used to verify the consistency of modes
1335 procedure Analyze_Global_List
1337 Global_Mode : Name_Id := Name_Input);
1338 -- Verify the legality of a single global list declaration. Global_Mode
1339 -- denotes the current mode in effect.
1341 -------------------------
1342 -- Analyze_Global_List --
1343 -------------------------
1345 procedure Analyze_Global_List
1347 Global_Mode : Name_Id := Name_Input)
1349 procedure Analyze_Global_Item
1351 Global_Mode : Name_Id);
1352 -- Verify the legality of a single global item declaration.
1353 -- Global_Mode denotes the current mode in effect.
1355 procedure Check_Duplicate_Mode
1357 Status : in out Boolean);
1358 -- Flag Status denotes whether a particular mode has been seen while
1359 -- processing a global list. This routine verifies that Mode is not a
1360 -- duplicate mode and sets the flag Status.
1362 procedure Check_Mode_Restriction_In_Enclosing_Context
1364 Item_Id : Entity_Id);
1365 -- Verify that an item of mode In_Out or Output does not appear as an
1366 -- input in the Global aspect of an enclosing subprogram. If this is
1367 -- the case, emit an error. Item and Item_Id are respectively the
1368 -- item and its entity.
1370 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1371 -- Mode denotes either In_Out or Output. Depending on the kind of the
1372 -- related subprogram, emit an error if those two modes apply to a
1375 -------------------------
1376 -- Analyze_Global_Item --
1377 -------------------------
1379 procedure Analyze_Global_Item
1381 Global_Mode : Name_Id)
1383 Item_Id : Entity_Id;
1386 -- Detect one of the following cases
1388 -- with Global => (null, Name)
1389 -- with Global => (Name_1, null, Name_2)
1390 -- with Global => (Name, null)
1392 if Nkind (Item) = N_Null then
1393 Error_Msg_N ("cannot mix null and non-null global items", Item);
1399 -- Find the entity of the item. If this is a renaming, climb the
1400 -- renaming chain to reach the root object. Renamings of non-
1401 -- entire objects do not yield an entity (Empty).
1403 Item_Id := Entity_Of (Item);
1405 if Present (Item_Id) then
1407 -- A global item cannot reference a formal parameter. Do this
1408 -- check first to provide a better error diagnostic.
1410 if Is_Formal (Item_Id) then
1412 ("global item cannot reference formal parameter", Item);
1415 -- The only legal references are those to abstract states and
1418 elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1420 ("global item must denote variable or state", Item);
1424 -- When the item renames an entire object, replace the item
1425 -- with a reference to the object.
1427 if Present (Renamed_Object (Entity (Item))) then
1428 Rewrite (Item, New_Reference_To (Item_Id, Sloc (Item)));
1432 -- Some form of illegal construct masquerading as a name
1435 Error_Msg_N ("global item must denote variable or state", Item);
1439 -- At this point we know that the global item is one of the two
1440 -- valid choices. Perform mode- and usage-specific checks.
1442 if Ekind (Item_Id) = E_Abstract_State
1443 and then Is_Volatile_State (Item_Id)
1445 -- A global item of mode In_Out or Output cannot denote a
1446 -- volatile Input state.
1448 if Is_Input_State (Item_Id)
1449 and then Nam_In (Global_Mode, Name_In_Out, Name_Output)
1452 ("global item of mode In_Out or Output cannot reference "
1453 & "Volatile Input state", Item);
1455 -- A global item of mode In_Out or Input cannot reference a
1456 -- volatile Output state.
1458 elsif Is_Output_State (Item_Id)
1459 and then Nam_In (Global_Mode, Name_In_Out, Name_Input)
1462 ("global item of mode In_Out or Input cannot reference "
1463 & "Volatile Output state", Item);
1467 -- Verify that an output does not appear as an input in an
1468 -- enclosing subprogram.
1470 if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1471 Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1474 -- The same entity might be referenced through various way. Check
1475 -- the entity of the item rather than the item itself.
1477 if Contains (Seen, Item_Id) then
1478 Error_Msg_N ("duplicate global item", Item);
1480 -- Add the entity of the current item to the list of processed
1484 Add_Item (Item_Id, Seen);
1486 end Analyze_Global_Item;
1488 --------------------------
1489 -- Check_Duplicate_Mode --
1490 --------------------------
1492 procedure Check_Duplicate_Mode
1494 Status : in out Boolean)
1498 Error_Msg_N ("duplicate global mode", Mode);
1502 end Check_Duplicate_Mode;
1504 -------------------------------------------------
1505 -- Check_Mode_Restriction_In_Enclosing_Context --
1506 -------------------------------------------------
1508 procedure Check_Mode_Restriction_In_Enclosing_Context
1510 Item_Id : Entity_Id)
1513 Inputs : Elist_Id := No_Elist;
1514 Outputs : Elist_Id := No_Elist;
1515 Subp_Id : Entity_Id;
1518 -- Traverse the scope stack looking for enclosing subprograms
1519 -- subject to aspect/pragma Global.
1521 Subp_Id := Scope (Current_Scope);
1522 while Present (Subp_Id) and then Subp_Id /= Standard_Standard loop
1523 if Is_Subprogram (Subp_Id)
1524 and then Has_Aspect (Subp_Id, Aspect_Global)
1526 Collect_Subprogram_Inputs_Outputs
1527 (Subp_Id => Subp_Id,
1528 Subp_Inputs => Inputs,
1529 Subp_Outputs => Outputs,
1530 Global_Seen => Dummy);
1532 -- The item is classified as In_Out or Output but appears as
1533 -- an Input in an enclosing subprogram.
1535 if Appears_In (Inputs, Item_Id)
1536 and then not Appears_In (Outputs, Item_Id)
1539 ("global item & cannot have mode In_Out or Output",
1542 ("\item already appears as input of subprogram &",
1547 Subp_Id := Scope (Subp_Id);
1549 end Check_Mode_Restriction_In_Enclosing_Context;
1551 ----------------------------------------
1552 -- Check_Mode_Restriction_In_Function --
1553 ----------------------------------------
1555 procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
1557 if Ekind (Subp_Id) = E_Function then
1559 ("global mode & not applicable to functions", Mode);
1561 end Check_Mode_Restriction_In_Function;
1569 -- Start of processing for Analyze_Global_List
1572 -- Single global item declaration
1574 if Nkind_In (List, N_Identifier, N_Selected_Component) then
1575 Analyze_Global_Item (List, Global_Mode);
1577 -- Simple global list or moded global list declaration
1579 elsif Nkind (List) = N_Aggregate then
1581 -- The declaration of a simple global list appear as a collection
1584 if Present (Expressions (List)) then
1585 if Present (Component_Associations (List)) then
1587 ("cannot mix moded and non-moded global lists", List);
1590 Item := First (Expressions (List));
1591 while Present (Item) loop
1592 Analyze_Global_Item (Item, Global_Mode);
1597 -- The declaration of a moded global list appears as a collection
1598 -- of component associations where individual choices denote
1601 elsif Present (Component_Associations (List)) then
1602 if Present (Expressions (List)) then
1604 ("cannot mix moded and non-moded global lists", List);
1607 Assoc := First (Component_Associations (List));
1608 while Present (Assoc) loop
1609 Mode := First (Choices (Assoc));
1611 if Nkind (Mode) = N_Identifier then
1612 if Chars (Mode) = Name_Contract_In then
1613 Check_Duplicate_Mode (Mode, Contract_Seen);
1615 elsif Chars (Mode) = Name_In_Out then
1616 Check_Duplicate_Mode (Mode, In_Out_Seen);
1617 Check_Mode_Restriction_In_Function (Mode);
1619 elsif Chars (Mode) = Name_Input then
1620 Check_Duplicate_Mode (Mode, Input_Seen);
1622 elsif Chars (Mode) = Name_Output then
1623 Check_Duplicate_Mode (Mode, Output_Seen);
1624 Check_Mode_Restriction_In_Function (Mode);
1627 Error_Msg_N ("invalid mode selector", Mode);
1631 Error_Msg_N ("invalid mode selector", Mode);
1634 -- Items in a moded list appear as a collection of
1635 -- expressions. Reuse the existing machinery to analyze
1639 (List => Expression (Assoc),
1640 Global_Mode => Chars (Mode));
1645 -- Something went horribly wrong, we have a malformed tree
1648 raise Program_Error;
1651 -- Any other attempt to declare a global item is erroneous
1654 Error_Msg_N ("malformed global list declaration", List);
1656 end Analyze_Global_List;
1661 Subp_Decl : Node_Id;
1663 -- Start of processing for Analyze_Global_In_Decl_List
1668 Subp_Decl := Find_Related_Subprogram (N);
1669 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
1670 List := Expression (Arg1);
1672 -- There is nothing to be done for a null global list
1674 if Nkind (List) = N_Null then
1677 -- Analyze the various forms of global lists and items. Note that some
1678 -- of these may be malformed in which case the analysis emits error
1682 -- Ensure that the formal parameters are visible when processing an
1683 -- item. This falls out of the general rule of aspects pertaining to
1684 -- subprogram declarations.
1686 if Requires_Profile_Installation (N, Subp_Decl) then
1687 Push_Scope (Subp_Id);
1688 Install_Formals (Subp_Id);
1691 Analyze_Global_List (List);
1693 if Requires_Profile_Installation (N, Subp_Decl) then
1697 end Analyze_Global_In_Decl_Part;
1699 ------------------------------
1700 -- Analyze_PPC_In_Decl_Part --
1701 ------------------------------
1703 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
1704 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1707 -- Install formals and push subprogram spec onto scope stack so that we
1708 -- can see the formals from the pragma.
1710 Install_Formals (S);
1713 -- Preanalyze the boolean expression, we treat this as a spec expression
1714 -- (i.e. similar to a default expression).
1716 Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
1718 -- In ASIS mode, for a pragma generated from a source aspect, also
1719 -- analyze the original aspect expression.
1721 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
1722 Preanalyze_Assert_Expression
1723 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
1726 -- For a class-wide condition, a reference to a controlling formal must
1727 -- be interpreted as having the class-wide type (or an access to such)
1728 -- so that the inherited condition can be properly applied to any
1729 -- overriding operation (see ARM12 6.6.1 (7)).
1731 if Class_Present (N) then
1732 Class_Wide_Condition : declare
1733 T : constant Entity_Id := Find_Dispatching_Type (S);
1735 ACW : Entity_Id := Empty;
1736 -- Access to T'class, created if there is a controlling formal
1737 -- that is an access parameter.
1739 function Get_ACW return Entity_Id;
1740 -- If the expression has a reference to an controlling access
1741 -- parameter, create an access to T'class for the necessary
1742 -- conversions if one does not exist.
1744 function Process (N : Node_Id) return Traverse_Result;
1745 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
1746 -- aspect for a primitive subprogram of a tagged type T, a name
1747 -- that denotes a formal parameter of type T is interpreted as
1748 -- having type T'Class. Similarly, a name that denotes a formal
1749 -- accessparameter of type access-to-T is interpreted as having
1750 -- type access-to-T'Class. This ensures the expression is well-
1751 -- defined for a primitive subprogram of a type descended from T.
1752 -- Note that this replacement is not done for selector names in
1753 -- parameter associations. These carry an entity for reference
1754 -- purposes, but semantically they are just identifiers.
1760 function Get_ACW return Entity_Id is
1761 Loc : constant Source_Ptr := Sloc (N);
1766 Decl := Make_Full_Type_Declaration (Loc,
1767 Defining_Identifier => Make_Temporary (Loc, 'T'),
1769 Make_Access_To_Object_Definition (Loc,
1770 Subtype_Indication =>
1771 New_Occurrence_Of (Class_Wide_Type (T), Loc),
1772 All_Present => True));
1774 Insert_Before (Unit_Declaration_Node (S), Decl);
1776 ACW := Defining_Identifier (Decl);
1777 Freeze_Before (Unit_Declaration_Node (S), ACW);
1787 function Process (N : Node_Id) return Traverse_Result is
1788 Loc : constant Source_Ptr := Sloc (N);
1792 if Is_Entity_Name (N)
1793 and then Present (Entity (N))
1794 and then Is_Formal (Entity (N))
1795 and then Nkind (Parent (N)) /= N_Type_Conversion
1797 (Nkind (Parent (N)) /= N_Parameter_Association
1798 or else N /= Selector_Name (Parent (N)))
1800 if Etype (Entity (N)) = T then
1801 Typ := Class_Wide_Type (T);
1803 elsif Is_Access_Type (Etype (Entity (N)))
1804 and then Designated_Type (Etype (Entity (N))) = T
1811 if Present (Typ) then
1813 Make_Type_Conversion (Loc,
1815 New_Occurrence_Of (Typ, Loc),
1816 Expression => New_Occurrence_Of (Entity (N), Loc)));
1824 procedure Replace_Type is new Traverse_Proc (Process);
1826 -- Start of processing for Class_Wide_Condition
1829 if not Present (T) then
1831 Chars (Identifier (Corresponding_Aspect (N)));
1833 Error_Msg_Name_2 := Name_Class;
1836 ("aspect `%''%` can only be specified for a primitive "
1837 & "operation of a tagged type", Corresponding_Aspect (N));
1840 Replace_Type (Get_Pragma_Arg (Arg1));
1841 end Class_Wide_Condition;
1844 -- Remove the subprogram from the scope stack now that the pre-analysis
1845 -- of the precondition/postcondition is done.
1848 end Analyze_PPC_In_Decl_Part;
1850 --------------------
1851 -- Analyze_Pragma --
1852 --------------------
1854 procedure Analyze_Pragma (N : Node_Id) is
1855 Loc : constant Source_Ptr := Sloc (N);
1856 Prag_Id : Pragma_Id;
1859 -- Name of the source pragma, or name of the corresponding aspect for
1860 -- pragmas which originate in a source aspect. In the latter case, the
1861 -- name may be different from the pragma name.
1863 Pragma_Exit : exception;
1864 -- This exception is used to exit pragma processing completely. It is
1865 -- used when an error is detected, and no further processing is
1866 -- required. It is also used if an earlier error has left the tree in
1867 -- a state where the pragma should not be processed.
1870 -- Number of pragma argument associations
1876 -- First four pragma arguments (pragma argument association nodes, or
1877 -- Empty if the corresponding argument does not exist).
1879 type Name_List is array (Natural range <>) of Name_Id;
1880 type Args_List is array (Natural range <>) of Node_Id;
1881 -- Types used for arguments to Check_Arg_Order and Gather_Associations
1883 procedure Ada_2005_Pragma;
1884 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
1885 -- Ada 95 mode, these are implementation defined pragmas, so should be
1886 -- caught by the No_Implementation_Pragmas restriction.
1888 procedure Ada_2012_Pragma;
1889 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
1890 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
1891 -- should be caught by the No_Implementation_Pragmas restriction.
1893 procedure Check_Ada_83_Warning;
1894 -- Issues a warning message for the current pragma if operating in Ada
1895 -- 83 mode (used for language pragmas that are not a standard part of
1896 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
1899 procedure Check_Arg_Count (Required : Nat);
1900 -- Check argument count for pragma is equal to given parameter. If not,
1901 -- then issue an error message and raise Pragma_Exit.
1903 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
1904 -- Arg which can either be a pragma argument association, in which case
1905 -- the check is applied to the expression of the association or an
1906 -- expression directly.
1908 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
1909 -- Check that an argument has the right form for an EXTERNAL_NAME
1910 -- parameter of an extended import/export pragma. The rule is that the
1911 -- name must be an identifier or string literal (in Ada 83 mode) or a
1912 -- static string expression (in Ada 95 mode).
1914 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
1915 -- Check the specified argument Arg to make sure that it is an
1916 -- identifier. If not give error and raise Pragma_Exit.
1918 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
1919 -- Check the specified argument Arg to make sure that it is an integer
1920 -- literal. If not give error and raise Pragma_Exit.
1922 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
1923 -- Check the specified argument Arg to make sure that it has the proper
1924 -- syntactic form for a local name and meets the semantic requirements
1925 -- for a local name. The local name is analyzed as part of the
1926 -- processing for this call. In addition, the local name is required
1927 -- to represent an entity at the library level.
1929 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
1930 -- Check the specified argument Arg to make sure that it has the proper
1931 -- syntactic form for a local name and meets the semantic requirements
1932 -- for a local name. The local name is analyzed as part of the
1933 -- processing for this call.
1935 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
1936 -- Check the specified argument Arg to make sure that it is a valid
1937 -- locking policy name. If not give error and raise Pragma_Exit.
1939 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
1940 -- Check the specified argument Arg to make sure that it is a valid
1941 -- elaboration policy name. If not give error and raise Pragma_Exit.
1943 procedure Check_Arg_Is_One_Of
1946 procedure Check_Arg_Is_One_Of
1948 N1, N2, N3 : Name_Id);
1949 procedure Check_Arg_Is_One_Of
1951 N1, N2, N3, N4 : Name_Id);
1952 procedure Check_Arg_Is_One_Of
1954 N1, N2, N3, N4, N5 : Name_Id);
1955 -- Check the specified argument Arg to make sure that it is an
1956 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
1957 -- present). If not then give error and raise Pragma_Exit.
1959 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
1960 -- Check the specified argument Arg to make sure that it is a valid
1961 -- queuing policy name. If not give error and raise Pragma_Exit.
1963 procedure Check_Arg_Is_Static_Expression
1965 Typ : Entity_Id := Empty);
1966 -- Check the specified argument Arg to make sure that it is a static
1967 -- expression of the given type (i.e. it will be analyzed and resolved
1968 -- using this type, which can be any valid argument to Resolve, e.g.
1969 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
1970 -- Typ is left Empty, then any static expression is allowed.
1972 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
1973 -- Check the specified argument Arg to make sure that it is a valid task
1974 -- dispatching policy name. If not give error and raise Pragma_Exit.
1976 procedure Check_Arg_Order (Names : Name_List);
1977 -- Checks for an instance of two arguments with identifiers for the
1978 -- current pragma which are not in the sequence indicated by Names,
1979 -- and if so, generates a fatal message about bad order of arguments.
1981 procedure Check_At_Least_N_Arguments (N : Nat);
1982 -- Check there are at least N arguments present
1984 procedure Check_At_Most_N_Arguments (N : Nat);
1985 -- Check there are no more than N arguments present
1987 procedure Check_Component
1990 In_Variant_Part : Boolean := False);
1991 -- Examine an Unchecked_Union component for correct use of per-object
1992 -- constrained subtypes, and for restrictions on finalizable components.
1993 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
1994 -- should be set when Comp comes from a record variant.
1996 procedure Check_Test_Case;
1997 -- Called to process a test-case pragma. It starts with checking pragma
1998 -- arguments, and the rest of the treatment is similar to the one for
1999 -- pre- and postcondition in Check_Precondition_Postcondition, except
2000 -- the placement rules for the test-case pragma are stricter. These
2001 -- pragmas may only occur after a subprogram spec declared directly
2002 -- in a package spec unit. In this case, the pragma is chained to the
2003 -- subprogram in question (using Contract_Test_Cases and Next_Pragma)
2004 -- and analysis of the pragma is delayed till the end of the spec. In
2005 -- all other cases, an error message for bad placement is given.
2007 procedure Check_Duplicate_Pragma (E : Entity_Id);
2008 -- Check if a rep item of the same name as the current pragma is already
2009 -- chained as a rep pragma to the given entity. If so give a message
2010 -- about the duplicate, and then raise Pragma_Exit so does not return.
2012 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2013 -- Nam is an N_String_Literal node containing the external name set by
2014 -- an Import or Export pragma (or extended Import or Export pragma).
2015 -- This procedure checks for possible duplications if this is the export
2016 -- case, and if found, issues an appropriate error message.
2018 procedure Check_Expr_Is_Static_Expression
2020 Typ : Entity_Id := Empty);
2021 -- Check the specified expression Expr to make sure that it is a static
2022 -- expression of the given type (i.e. it will be analyzed and resolved
2023 -- using this type, which can be any valid argument to Resolve, e.g.
2024 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2025 -- Typ is left Empty, then any static expression is allowed.
2027 procedure Check_First_Subtype (Arg : Node_Id);
2028 -- Checks that Arg, whose expression is an entity name, references a
2031 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2032 -- Checks that the given argument has an identifier, and if so, requires
2033 -- it to match the given identifier name. If there is no identifier, or
2034 -- a non-matching identifier, then an error message is given and
2035 -- Pragma_Exit is raised.
2037 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2038 -- Checks that the given argument has an identifier, and if so, requires
2039 -- it to match one of the given identifier names. If there is no
2040 -- identifier, or a non-matching identifier, then an error message is
2041 -- given and Pragma_Exit is raised.
2043 procedure Check_In_Main_Program;
2044 -- Common checks for pragmas that appear within a main program
2045 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2047 procedure Check_Interrupt_Or_Attach_Handler;
2048 -- Common processing for first argument of pragma Interrupt_Handler or
2049 -- pragma Attach_Handler.
2051 procedure Check_Loop_Pragma_Placement;
2052 -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
2053 -- appear immediately within a construct restricted to loops.
2055 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2056 -- Check that pragma appears in a declarative part, or in a package
2057 -- specification, i.e. that it does not occur in a statement sequence
2060 procedure Check_No_Identifier (Arg : Node_Id);
2061 -- Checks that the given argument does not have an identifier. If
2062 -- an identifier is present, then an error message is issued, and
2063 -- Pragma_Exit is raised.
2065 procedure Check_No_Identifiers;
2066 -- Checks that none of the arguments to the pragma has an identifier.
2067 -- If any argument has an identifier, then an error message is issued,
2068 -- and Pragma_Exit is raised.
2070 procedure Check_No_Link_Name;
2071 -- Checks that no link name is specified
2073 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
2074 -- Checks if the given argument has an identifier, and if so, requires
2075 -- it to match the given identifier name. If there is a non-matching
2076 -- identifier, then an error message is given and Pragma_Exit is raised.
2078 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
2079 -- Checks if the given argument has an identifier, and if so, requires
2080 -- it to match the given identifier name. If there is a non-matching
2081 -- identifier, then an error message is given and Pragma_Exit is raised.
2082 -- In this version of the procedure, the identifier name is given as
2083 -- a string with lower case letters.
2085 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
2086 -- Called to process a precondition or postcondition pragma. There are
2089 -- The pragma appears after a subprogram spec
2091 -- If the corresponding check is not enabled, the pragma is analyzed
2092 -- but otherwise ignored and control returns with In_Body set False.
2094 -- If the check is enabled, then the first step is to analyze the
2095 -- pragma, but this is skipped if the subprogram spec appears within
2096 -- a package specification (because this is the case where we delay
2097 -- analysis till the end of the spec). Then (whether or not it was
2098 -- analyzed), the pragma is chained to the subprogram in question
2099 -- (using Pre_Post_Conditions and Next_Pragma) and control returns
2100 -- to the caller with In_Body set False.
2102 -- The pragma appears at the start of subprogram body declarations
2104 -- In this case an immediate return to the caller is made with
2105 -- In_Body set True, and the pragma is NOT analyzed.
2107 -- In all other cases, an error message for bad placement is given
2109 procedure Check_Static_Constraint (Constr : Node_Id);
2110 -- Constr is a constraint from an N_Subtype_Indication node from a
2111 -- component constraint in an Unchecked_Union type. This routine checks
2112 -- that the constraint is static as required by the restrictions for
2115 procedure Check_Valid_Configuration_Pragma;
2116 -- Legality checks for placement of a configuration pragma
2118 procedure Check_Valid_Library_Unit_Pragma;
2119 -- Legality checks for library unit pragmas. A special case arises for
2120 -- pragmas in generic instances that come from copies of the original
2121 -- library unit pragmas in the generic templates. In the case of other
2122 -- than library level instantiations these can appear in contexts which
2123 -- would normally be invalid (they only apply to the original template
2124 -- and to library level instantiations), and they are simply ignored,
2125 -- which is implemented by rewriting them as null statements.
2127 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
2128 -- Check an Unchecked_Union variant for lack of nested variants and
2129 -- presence of at least one component. UU_Typ is the related Unchecked_
2132 procedure Error_Pragma (Msg : String);
2133 pragma No_Return (Error_Pragma);
2134 -- Outputs error message for current pragma. The message contains a %
2135 -- that will be replaced with the pragma name, and the flag is placed
2136 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2137 -- calls Fix_Error (see spec of that procedure for details).
2139 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
2140 pragma No_Return (Error_Pragma_Arg);
2141 -- Outputs error message for current pragma. The message may contain
2142 -- a % that will be replaced with the pragma name. The parameter Arg
2143 -- may either be a pragma argument association, in which case the flag
2144 -- is placed on the expression of this association, or an expression,
2145 -- in which case the flag is placed directly on the expression. The
2146 -- message is placed using Error_Msg_N, so the message may also contain
2147 -- an & insertion character which will reference the given Arg value.
2148 -- After placing the message, Pragma_Exit is raised. Note: this routine
2149 -- calls Fix_Error (see spec of that procedure for details).
2151 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
2152 pragma No_Return (Error_Pragma_Arg);
2153 -- Similar to above form of Error_Pragma_Arg except that two messages
2154 -- are provided, the second is a continuation comment starting with \.
2156 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
2157 pragma No_Return (Error_Pragma_Arg_Ident);
2158 -- Outputs error message for current pragma. The message may contain
2159 -- a % that will be replaced with the pragma name. The parameter Arg
2160 -- must be a pragma argument association with a non-empty identifier
2161 -- (i.e. its Chars field must be set), and the error message is placed
2162 -- on the identifier. The message is placed using Error_Msg_N so
2163 -- the message may also contain an & insertion character which will
2164 -- reference the identifier. After placing the message, Pragma_Exit
2165 -- is raised. Note: this routine calls Fix_Error (see spec of that
2166 -- procedure for details).
2168 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
2169 pragma No_Return (Error_Pragma_Ref);
2170 -- Outputs error message for current pragma. The message may contain
2171 -- a % that will be replaced with the pragma name. The parameter Ref
2172 -- must be an entity whose name can be referenced by & and sloc by #.
2173 -- After placing the message, Pragma_Exit is raised. Note: this routine
2174 -- calls Fix_Error (see spec of that procedure for details).
2176 function Find_Lib_Unit_Name return Entity_Id;
2177 -- Used for a library unit pragma to find the entity to which the
2178 -- library unit pragma applies, returns the entity found.
2180 procedure Find_Program_Unit_Name (Id : Node_Id);
2181 -- If the pragma is a compilation unit pragma, the id must denote the
2182 -- compilation unit in the same compilation, and the pragma must appear
2183 -- in the list of preceding or trailing pragmas. If it is a program
2184 -- unit pragma that is not a compilation unit pragma, then the
2185 -- identifier must be visible.
2187 function Find_Unique_Parameterless_Procedure
2189 Arg : Node_Id) return Entity_Id;
2190 -- Used for a procedure pragma to find the unique parameterless
2191 -- procedure identified by Name, returns it if it exists, otherwise
2192 -- errors out and uses Arg as the pragma argument for the message.
2194 procedure Fix_Error (Msg : in out String);
2195 -- This is called prior to issuing an error message. Msg is a string
2196 -- that typically contains the substring "pragma". If the pragma comes
2197 -- from an aspect, each such "pragma" substring is replaced with the
2198 -- characters "aspect", and Error_Msg_Name_1 is set to the name of the
2199 -- aspect (which may be different from the pragma name). If the current
2200 -- pragma results from rewriting another pragma, then Error_Msg_Name_1
2201 -- is set to the original pragma name.
2203 procedure Gather_Associations
2205 Args : out Args_List);
2206 -- This procedure is used to gather the arguments for a pragma that
2207 -- permits arbitrary ordering of parameters using the normal rules
2208 -- for named and positional parameters. The Names argument is a list
2209 -- of Name_Id values that corresponds to the allowed pragma argument
2210 -- association identifiers in order. The result returned in Args is
2211 -- a list of corresponding expressions that are the pragma arguments.
2212 -- Note that this is a list of expressions, not of pragma argument
2213 -- associations (Gather_Associations has completely checked all the
2214 -- optional identifiers when it returns). An entry in Args is Empty
2215 -- on return if the corresponding argument is not present.
2217 procedure GNAT_Pragma;
2218 -- Called for all GNAT defined pragmas to check the relevant restriction
2219 -- (No_Implementation_Pragmas).
2221 procedure S14_Pragma;
2222 -- Called for all pragmas defined for formal verification to check that
2223 -- the S14_Extensions flag is set.
2224 -- This name needs fixing ??? There is no such thing as an
2225 -- "S14_Extensions" flag ???
2227 function Is_Before_First_Decl
2228 (Pragma_Node : Node_Id;
2229 Decls : List_Id) return Boolean;
2230 -- Return True if Pragma_Node is before the first declarative item in
2231 -- Decls where Decls is the list of declarative items.
2233 function Is_Configuration_Pragma return Boolean;
2234 -- Determines if the placement of the current pragma is appropriate
2235 -- for a configuration pragma.
2237 function Is_In_Context_Clause return Boolean;
2238 -- Returns True if pragma appears within the context clause of a unit,
2239 -- and False for any other placement (does not generate any messages).
2241 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
2242 -- Analyzes the argument, and determines if it is a static string
2243 -- expression, returns True if so, False if non-static or not String.
2245 procedure Pragma_Misplaced;
2246 pragma No_Return (Pragma_Misplaced);
2247 -- Issue fatal error message for misplaced pragma
2249 procedure Process_Atomic_Shared_Volatile;
2250 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
2251 -- Shared is an obsolete Ada 83 pragma, treated as being identical
2252 -- in effect to pragma Atomic.
2254 procedure Process_Compile_Time_Warning_Or_Error;
2255 -- Common processing for Compile_Time_Error and Compile_Time_Warning
2257 procedure Process_Convention
2258 (C : out Convention_Id;
2259 Ent : out Entity_Id);
2260 -- Common processing for Convention, Interface, Import and Export.
2261 -- Checks first two arguments of pragma, and sets the appropriate
2262 -- convention value in the specified entity or entities. On return
2263 -- C is the convention, Ent is the referenced entity.
2265 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
2266 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
2267 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
2269 procedure Process_Extended_Import_Export_Exception_Pragma
2270 (Arg_Internal : Node_Id;
2271 Arg_External : Node_Id;
2273 Arg_Code : Node_Id);
2274 -- Common processing for the pragmas Import/Export_Exception. The three
2275 -- arguments correspond to the three named parameters of the pragma. An
2276 -- argument is empty if the corresponding parameter is not present in
2279 procedure Process_Extended_Import_Export_Object_Pragma
2280 (Arg_Internal : Node_Id;
2281 Arg_External : Node_Id;
2282 Arg_Size : Node_Id);
2283 -- Common processing for the pragmas Import/Export_Object. The three
2284 -- arguments correspond to the three named parameters of the pragmas. An
2285 -- argument is empty if the corresponding parameter is not present in
2288 procedure Process_Extended_Import_Export_Internal_Arg
2289 (Arg_Internal : Node_Id := Empty);
2290 -- Common processing for all extended Import and Export pragmas. The
2291 -- argument is the pragma parameter for the Internal argument. If
2292 -- Arg_Internal is empty or inappropriate, an error message is posted.
2293 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
2294 -- set to identify the referenced entity.
2296 procedure Process_Extended_Import_Export_Subprogram_Pragma
2297 (Arg_Internal : Node_Id;
2298 Arg_External : Node_Id;
2299 Arg_Parameter_Types : Node_Id;
2300 Arg_Result_Type : Node_Id := Empty;
2301 Arg_Mechanism : Node_Id;
2302 Arg_Result_Mechanism : Node_Id := Empty;
2303 Arg_First_Optional_Parameter : Node_Id := Empty);
2304 -- Common processing for all extended Import and Export pragmas applying
2305 -- to subprograms. The caller omits any arguments that do not apply to
2306 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
2307 -- only in the Import_Function and Export_Function cases). The argument
2308 -- names correspond to the allowed pragma association identifiers.
2310 procedure Process_Generic_List;
2311 -- Common processing for Share_Generic and Inline_Generic
2313 procedure Process_Import_Or_Interface;
2314 -- Common processing for Import of Interface
2316 procedure Process_Import_Predefined_Type;
2317 -- Processing for completing a type with pragma Import. This is used
2318 -- to declare types that match predefined C types, especially for cases
2319 -- without corresponding Ada predefined type.
2321 type Inline_Status is (Suppressed, Disabled, Enabled);
2322 -- Inline status of a subprogram, indicated as follows:
2323 -- Suppressed: inlining is suppressed for the subprogram
2324 -- Disabled: no inlining is requested for the subprogram
2325 -- Enabled: inlining is requested/required for the subprogram
2327 procedure Process_Inline (Status : Inline_Status);
2328 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
2329 -- indicates the inline status specified by the pragma.
2331 procedure Process_Interface_Name
2332 (Subprogram_Def : Entity_Id;
2334 Link_Arg : Node_Id);
2335 -- Given the last two arguments of pragma Import, pragma Export, or
2336 -- pragma Interface_Name, performs validity checks and sets the
2337 -- Interface_Name field of the given subprogram entity to the
2338 -- appropriate external or link name, depending on the arguments given.
2339 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
2340 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
2341 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
2342 -- nor Link_Arg is present, the interface name is set to the default
2343 -- from the subprogram name.
2345 procedure Process_Interrupt_Or_Attach_Handler;
2346 -- Common processing for Interrupt and Attach_Handler pragmas
2348 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
2349 -- Common processing for Restrictions and Restriction_Warnings pragmas.
2350 -- Warn is True for Restriction_Warnings, or for Restrictions if the
2351 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
2352 -- is not set in the Restrictions case.
2354 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
2355 -- Common processing for Suppress and Unsuppress. The boolean parameter
2356 -- Suppress_Case is True for the Suppress case, and False for the
2359 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
2360 -- This procedure sets the Is_Exported flag for the given entity,
2361 -- checking that the entity was not previously imported. Arg is
2362 -- the argument that specified the entity. A check is also made
2363 -- for exporting inappropriate entities.
2365 procedure Set_Extended_Import_Export_External_Name
2366 (Internal_Ent : Entity_Id;
2367 Arg_External : Node_Id);
2368 -- Common processing for all extended import export pragmas. The first
2369 -- argument, Internal_Ent, is the internal entity, which has already
2370 -- been checked for validity by the caller. Arg_External is from the
2371 -- Import or Export pragma, and may be null if no External parameter
2372 -- was present. If Arg_External is present and is a non-null string
2373 -- (a null string is treated as the default), then the Interface_Name
2374 -- field of Internal_Ent is set appropriately.
2376 procedure Set_Imported (E : Entity_Id);
2377 -- This procedure sets the Is_Imported flag for the given entity,
2378 -- checking that it is not previously exported or imported.
2380 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
2381 -- Mech is a parameter passing mechanism (see Import_Function syntax
2382 -- for MECHANISM_NAME). This routine checks that the mechanism argument
2383 -- has the right form, and if not issues an error message. If the
2384 -- argument has the right form then the Mechanism field of Ent is
2385 -- set appropriately.
2387 procedure Set_Rational_Profile;
2388 -- Activate the set of configuration pragmas and permissions that make
2389 -- up the Rational profile.
2391 procedure Set_Ravenscar_Profile (N : Node_Id);
2392 -- Activate the set of configuration pragmas and restrictions that make
2393 -- up the Ravenscar Profile. N is the corresponding pragma node, which
2394 -- is used for error messages on any constructs that violate the
2397 ---------------------
2398 -- Ada_2005_Pragma --
2399 ---------------------
2401 procedure Ada_2005_Pragma is
2403 if Ada_Version <= Ada_95 then
2404 Check_Restriction (No_Implementation_Pragmas, N);
2406 end Ada_2005_Pragma;
2408 ---------------------
2409 -- Ada_2012_Pragma --
2410 ---------------------
2412 procedure Ada_2012_Pragma is
2414 if Ada_Version <= Ada_2005 then
2415 Check_Restriction (No_Implementation_Pragmas, N);
2417 end Ada_2012_Pragma;
2419 --------------------------
2420 -- Check_Ada_83_Warning --
2421 --------------------------
2423 procedure Check_Ada_83_Warning is
2425 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2426 Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
2428 end Check_Ada_83_Warning;
2430 ---------------------
2431 -- Check_Arg_Count --
2432 ---------------------
2434 procedure Check_Arg_Count (Required : Nat) is
2436 if Arg_Count /= Required then
2437 Error_Pragma ("wrong number of arguments for pragma%");
2439 end Check_Arg_Count;
2441 --------------------------------
2442 -- Check_Arg_Is_External_Name --
2443 --------------------------------
2445 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
2446 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2449 if Nkind (Argx) = N_Identifier then
2453 Analyze_And_Resolve (Argx, Standard_String);
2455 if Is_OK_Static_Expression (Argx) then
2458 elsif Etype (Argx) = Any_Type then
2461 -- An interesting special case, if we have a string literal and
2462 -- we are in Ada 83 mode, then we allow it even though it will
2463 -- not be flagged as static. This allows expected Ada 83 mode
2464 -- use of external names which are string literals, even though
2465 -- technically these are not static in Ada 83.
2467 elsif Ada_Version = Ada_83
2468 and then Nkind (Argx) = N_String_Literal
2472 -- Static expression that raises Constraint_Error. This has
2473 -- already been flagged, so just exit from pragma processing.
2475 elsif Is_Static_Expression (Argx) then
2478 -- Here we have a real error (non-static expression)
2481 Error_Msg_Name_1 := Pname;
2485 "argument for pragma% must be a identifier or "
2486 & "static string expression!";
2489 Flag_Non_Static_Expr (Msg, Argx);
2494 end Check_Arg_Is_External_Name;
2496 -----------------------------
2497 -- Check_Arg_Is_Identifier --
2498 -----------------------------
2500 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
2501 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2503 if Nkind (Argx) /= N_Identifier then
2505 ("argument for pragma% must be identifier", Argx);
2507 end Check_Arg_Is_Identifier;
2509 ----------------------------------
2510 -- Check_Arg_Is_Integer_Literal --
2511 ----------------------------------
2513 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
2514 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2516 if Nkind (Argx) /= N_Integer_Literal then
2518 ("argument for pragma% must be integer literal", Argx);
2520 end Check_Arg_Is_Integer_Literal;
2522 -------------------------------------------
2523 -- Check_Arg_Is_Library_Level_Local_Name --
2524 -------------------------------------------
2528 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
2529 -- | library_unit_NAME
2531 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
2533 Check_Arg_Is_Local_Name (Arg);
2535 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
2536 and then Comes_From_Source (N)
2539 ("argument for pragma% must be library level entity", Arg);
2541 end Check_Arg_Is_Library_Level_Local_Name;
2543 -----------------------------
2544 -- Check_Arg_Is_Local_Name --
2545 -----------------------------
2549 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
2550 -- | library_unit_NAME
2552 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
2553 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2558 if Nkind (Argx) not in N_Direct_Name
2559 and then (Nkind (Argx) /= N_Attribute_Reference
2560 or else Present (Expressions (Argx))
2561 or else Nkind (Prefix (Argx)) /= N_Identifier)
2562 and then (not Is_Entity_Name (Argx)
2563 or else not Is_Compilation_Unit (Entity (Argx)))
2565 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
2568 -- No further check required if not an entity name
2570 if not Is_Entity_Name (Argx) then
2576 Ent : constant Entity_Id := Entity (Argx);
2577 Scop : constant Entity_Id := Scope (Ent);
2580 -- Case of a pragma applied to a compilation unit: pragma must
2581 -- occur immediately after the program unit in the compilation.
2583 if Is_Compilation_Unit (Ent) then
2585 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
2588 -- Case of pragma placed immediately after spec
2590 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
2593 -- Case of pragma placed immediately after body
2595 elsif Nkind (Decl) = N_Subprogram_Declaration
2596 and then Present (Corresponding_Body (Decl))
2600 (Parent (Unit_Declaration_Node
2601 (Corresponding_Body (Decl))));
2603 -- All other cases are illegal
2610 -- Special restricted placement rule from 10.2.1(11.8/2)
2612 elsif Is_Generic_Formal (Ent)
2613 and then Prag_Id = Pragma_Preelaborable_Initialization
2615 OK := List_Containing (N) =
2616 Generic_Formal_Declarations
2617 (Unit_Declaration_Node (Scop));
2619 -- Default case, just check that the pragma occurs in the scope
2620 -- of the entity denoted by the name.
2623 OK := Current_Scope = Scop;
2628 ("pragma% argument must be in same declarative part", Arg);
2632 end Check_Arg_Is_Local_Name;
2634 ---------------------------------
2635 -- Check_Arg_Is_Locking_Policy --
2636 ---------------------------------
2638 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
2639 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2642 Check_Arg_Is_Identifier (Argx);
2644 if not Is_Locking_Policy_Name (Chars (Argx)) then
2645 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
2647 end Check_Arg_Is_Locking_Policy;
2649 -----------------------------------------------
2650 -- Check_Arg_Is_Partition_Elaboration_Policy --
2651 -----------------------------------------------
2653 procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
2654 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2657 Check_Arg_Is_Identifier (Argx);
2659 if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
2661 ("& is not a valid partition elaboration policy name", Argx);
2663 end Check_Arg_Is_Partition_Elaboration_Policy;
2665 -------------------------
2666 -- Check_Arg_Is_One_Of --
2667 -------------------------
2669 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
2670 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2673 Check_Arg_Is_Identifier (Argx);
2675 if not Nam_In (Chars (Argx), N1, N2) then
2676 Error_Msg_Name_2 := N1;
2677 Error_Msg_Name_3 := N2;
2678 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
2680 end Check_Arg_Is_One_Of;
2682 procedure Check_Arg_Is_One_Of
2684 N1, N2, N3 : Name_Id)
2686 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2689 Check_Arg_Is_Identifier (Argx);
2691 if not Nam_In (Chars (Argx), N1, N2, N3) then
2692 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
2694 end Check_Arg_Is_One_Of;
2696 procedure Check_Arg_Is_One_Of
2698 N1, N2, N3, N4 : Name_Id)
2700 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2703 Check_Arg_Is_Identifier (Argx);
2705 if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
2706 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
2708 end Check_Arg_Is_One_Of;
2710 procedure Check_Arg_Is_One_Of
2712 N1, N2, N3, N4, N5 : Name_Id)
2714 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2717 Check_Arg_Is_Identifier (Argx);
2719 if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
2720 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
2722 end Check_Arg_Is_One_Of;
2724 ---------------------------------
2725 -- Check_Arg_Is_Queuing_Policy --
2726 ---------------------------------
2728 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
2729 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2732 Check_Arg_Is_Identifier (Argx);
2734 if not Is_Queuing_Policy_Name (Chars (Argx)) then
2735 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
2737 end Check_Arg_Is_Queuing_Policy;
2739 ------------------------------------
2740 -- Check_Arg_Is_Static_Expression --
2741 ------------------------------------
2743 procedure Check_Arg_Is_Static_Expression
2745 Typ : Entity_Id := Empty)
2748 Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
2749 end Check_Arg_Is_Static_Expression;
2751 ------------------------------------------
2752 -- Check_Arg_Is_Task_Dispatching_Policy --
2753 ------------------------------------------
2755 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
2756 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2759 Check_Arg_Is_Identifier (Argx);
2761 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
2763 ("& is not a valid task dispatching policy name", Argx);
2765 end Check_Arg_Is_Task_Dispatching_Policy;
2767 ---------------------
2768 -- Check_Arg_Order --
2769 ---------------------
2771 procedure Check_Arg_Order (Names : Name_List) is
2774 Highest_So_Far : Natural := 0;
2775 -- Highest index in Names seen do far
2779 for J in 1 .. Arg_Count loop
2780 if Chars (Arg) /= No_Name then
2781 for K in Names'Range loop
2782 if Chars (Arg) = Names (K) then
2783 if K < Highest_So_Far then
2784 Error_Msg_Name_1 := Pname;
2786 ("parameters out of order for pragma%", Arg);
2787 Error_Msg_Name_1 := Names (K);
2788 Error_Msg_Name_2 := Names (Highest_So_Far);
2789 Error_Msg_N ("\% must appear before %", Arg);
2793 Highest_So_Far := K;
2801 end Check_Arg_Order;
2803 --------------------------------
2804 -- Check_At_Least_N_Arguments --
2805 --------------------------------
2807 procedure Check_At_Least_N_Arguments (N : Nat) is
2809 if Arg_Count < N then
2810 Error_Pragma ("too few arguments for pragma%");
2812 end Check_At_Least_N_Arguments;
2814 -------------------------------
2815 -- Check_At_Most_N_Arguments --
2816 -------------------------------
2818 procedure Check_At_Most_N_Arguments (N : Nat) is
2821 if Arg_Count > N then
2823 for J in 1 .. N loop
2825 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
2828 end Check_At_Most_N_Arguments;
2830 ---------------------
2831 -- Check_Component --
2832 ---------------------
2834 procedure Check_Component
2837 In_Variant_Part : Boolean := False)
2839 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
2840 Sindic : constant Node_Id :=
2841 Subtype_Indication (Component_Definition (Comp));
2842 Typ : constant Entity_Id := Etype (Comp_Id);
2845 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
2846 -- object constraint, then the component type shall be an Unchecked_
2849 if Nkind (Sindic) = N_Subtype_Indication
2850 and then Has_Per_Object_Constraint (Comp_Id)
2851 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
2854 ("component subtype subject to per-object constraint "
2855 & "must be an Unchecked_Union", Comp);
2857 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
2858 -- the body of a generic unit, or within the body of any of its
2859 -- descendant library units, no part of the type of a component
2860 -- declared in a variant_part of the unchecked union type shall be of
2861 -- a formal private type or formal private extension declared within
2862 -- the formal part of the generic unit.
2864 elsif Ada_Version >= Ada_2012
2865 and then In_Generic_Body (UU_Typ)
2866 and then In_Variant_Part
2867 and then Is_Private_Type (Typ)
2868 and then Is_Generic_Type (Typ)
2871 ("component of unchecked union cannot be of generic type", Comp);
2873 elsif Needs_Finalization (Typ) then
2875 ("component of unchecked union cannot be controlled", Comp);
2877 elsif Has_Task (Typ) then
2879 ("component of unchecked union cannot have tasks", Comp);
2881 end Check_Component;
2883 ----------------------------
2884 -- Check_Duplicate_Pragma --
2885 ----------------------------
2887 procedure Check_Duplicate_Pragma (E : Entity_Id) is
2888 Id : Entity_Id := E;
2892 -- Nothing to do if this pragma comes from an aspect specification,
2893 -- since we could not be duplicating a pragma, and we dealt with the
2894 -- case of duplicated aspects in Analyze_Aspect_Specifications.
2896 if From_Aspect_Specification (N) then
2900 -- Otherwise current pragma may duplicate previous pragma or a
2901 -- previously given aspect specification or attribute definition
2902 -- clause for the same pragma.
2904 P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
2907 Error_Msg_Name_1 := Pragma_Name (N);
2908 Error_Msg_Sloc := Sloc (P);
2910 -- For a single protected or a single task object, the error is
2911 -- issued on the original entity.
2913 if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
2914 Id := Defining_Identifier (Original_Node (Parent (Id)));
2917 if Nkind (P) = N_Aspect_Specification
2918 or else From_Aspect_Specification (P)
2920 Error_Msg_NE ("aspect% for & previously given#", N, Id);
2922 Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
2927 end Check_Duplicate_Pragma;
2929 ----------------------------------
2930 -- Check_Duplicated_Export_Name --
2931 ----------------------------------
2933 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
2934 String_Val : constant String_Id := Strval (Nam);
2937 -- We are only interested in the export case, and in the case of
2938 -- generics, it is the instance, not the template, that is the
2939 -- problem (the template will generate a warning in any case).
2941 if not Inside_A_Generic
2942 and then (Prag_Id = Pragma_Export
2944 Prag_Id = Pragma_Export_Procedure
2946 Prag_Id = Pragma_Export_Valued_Procedure
2948 Prag_Id = Pragma_Export_Function)
2950 for J in Externals.First .. Externals.Last loop
2951 if String_Equal (String_Val, Strval (Externals.Table (J))) then
2952 Error_Msg_Sloc := Sloc (Externals.Table (J));
2953 Error_Msg_N ("external name duplicates name given#", Nam);
2958 Externals.Append (Nam);
2960 end Check_Duplicated_Export_Name;
2962 -------------------------------------
2963 -- Check_Expr_Is_Static_Expression --
2964 -------------------------------------
2966 procedure Check_Expr_Is_Static_Expression
2968 Typ : Entity_Id := Empty)
2971 if Present (Typ) then
2972 Analyze_And_Resolve (Expr, Typ);
2974 Analyze_And_Resolve (Expr);
2977 if Is_OK_Static_Expression (Expr) then
2980 elsif Etype (Expr) = Any_Type then
2983 -- An interesting special case, if we have a string literal and we
2984 -- are in Ada 83 mode, then we allow it even though it will not be
2985 -- flagged as static. This allows the use of Ada 95 pragmas like
2986 -- Import in Ada 83 mode. They will of course be flagged with
2987 -- warnings as usual, but will not cause errors.
2989 elsif Ada_Version = Ada_83
2990 and then Nkind (Expr) = N_String_Literal
2994 -- Static expression that raises Constraint_Error. This has already
2995 -- been flagged, so just exit from pragma processing.
2997 elsif Is_Static_Expression (Expr) then
3000 -- Finally, we have a real error
3003 Error_Msg_Name_1 := Pname;
3007 "argument for pragma% must be a static expression!";
3010 Flag_Non_Static_Expr (Msg, Expr);
3015 end Check_Expr_Is_Static_Expression;
3017 -------------------------
3018 -- Check_First_Subtype --
3019 -------------------------
3021 procedure Check_First_Subtype (Arg : Node_Id) is
3022 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3023 Ent : constant Entity_Id := Entity (Argx);
3026 if Is_First_Subtype (Ent) then
3029 elsif Is_Type (Ent) then
3031 ("pragma% cannot apply to subtype", Argx);
3033 elsif Is_Object (Ent) then
3035 ("pragma% cannot apply to object, requires a type", Argx);
3039 ("pragma% cannot apply to&, requires a type", Argx);
3041 end Check_First_Subtype;
3043 ----------------------
3044 -- Check_Identifier --
3045 ----------------------
3047 procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
3050 and then Nkind (Arg) = N_Pragma_Argument_Association
3052 if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
3053 Error_Msg_Name_1 := Pname;
3054 Error_Msg_Name_2 := Id;
3055 Error_Msg_N ("pragma% argument expects identifier%", Arg);
3059 end Check_Identifier;
3061 --------------------------------
3062 -- Check_Identifier_Is_One_Of --
3063 --------------------------------
3065 procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3068 and then Nkind (Arg) = N_Pragma_Argument_Association
3070 if Chars (Arg) = No_Name then
3071 Error_Msg_Name_1 := Pname;
3072 Error_Msg_N ("pragma% argument expects an identifier", Arg);
3075 elsif Chars (Arg) /= N1
3076 and then Chars (Arg) /= N2
3078 Error_Msg_Name_1 := Pname;
3079 Error_Msg_N ("invalid identifier for pragma% argument", Arg);
3083 end Check_Identifier_Is_One_Of;
3085 ---------------------------
3086 -- Check_In_Main_Program --
3087 ---------------------------
3089 procedure Check_In_Main_Program is
3090 P : constant Node_Id := Parent (N);
3093 -- Must be at in subprogram body
3095 if Nkind (P) /= N_Subprogram_Body then
3096 Error_Pragma ("% pragma allowed only in subprogram");
3098 -- Otherwise warn if obviously not main program
3100 elsif Present (Parameter_Specifications (Specification (P)))
3101 or else not Is_Compilation_Unit (Defining_Entity (P))
3103 Error_Msg_Name_1 := Pname;
3105 ("??pragma% is only effective in main program", N);
3107 end Check_In_Main_Program;
3109 ---------------------------------------
3110 -- Check_Interrupt_Or_Attach_Handler --
3111 ---------------------------------------
3113 procedure Check_Interrupt_Or_Attach_Handler is
3114 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
3115 Handler_Proc, Proc_Scope : Entity_Id;
3120 if Prag_Id = Pragma_Interrupt_Handler then
3121 Check_Restriction (No_Dynamic_Attachment, N);
3124 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
3125 Proc_Scope := Scope (Handler_Proc);
3127 -- On AAMP only, a pragma Interrupt_Handler is supported for
3128 -- nonprotected parameterless procedures.
3130 if not AAMP_On_Target
3131 or else Prag_Id = Pragma_Attach_Handler
3133 if Ekind (Proc_Scope) /= E_Protected_Type then
3135 ("argument of pragma% must be protected procedure", Arg1);
3138 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
3139 Error_Pragma ("pragma% must be in protected definition");
3143 if not Is_Library_Level_Entity (Proc_Scope)
3144 or else (AAMP_On_Target
3145 and then not Is_Library_Level_Entity (Handler_Proc))
3148 ("argument for pragma% must be library level entity", Arg1);
3151 -- AI05-0033: A pragma cannot appear within a generic body, because
3152 -- instance can be in a nested scope. The check that protected type
3153 -- is itself a library-level declaration is done elsewhere.
3155 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
3156 -- handle code prior to AI-0033. Analysis tools typically are not
3157 -- interested in this pragma in any case, so no need to worry too
3158 -- much about its placement.
3160 if Inside_A_Generic then
3161 if Ekind (Scope (Current_Scope)) = E_Generic_Package
3162 and then In_Package_Body (Scope (Current_Scope))
3163 and then not Relaxed_RM_Semantics
3165 Error_Pragma ("pragma% cannot be used inside a generic");
3168 end Check_Interrupt_Or_Attach_Handler;
3170 ---------------------------------
3171 -- Check_Loop_Pragma_Placement --
3172 ---------------------------------
3174 procedure Check_Loop_Pragma_Placement is
3175 procedure Placement_Error (Constr : Node_Id);
3176 pragma No_Return (Placement_Error);
3177 -- Node Constr denotes the last loop restricted construct before we
3178 -- encountered an illegal relation between enclosing constructs. Emit
3179 -- an error depending on what Constr was.
3181 ---------------------
3182 -- Placement_Error --
3183 ---------------------
3185 procedure Placement_Error (Constr : Node_Id) is
3187 if Nkind (Constr) = N_Pragma then
3189 ("pragma % must appear immediately within the statements "
3193 ("block containing pragma % must appear immediately within "
3194 & "the statements of a loop", Constr);
3196 end Placement_Error;
3198 -- Local declarations
3203 -- Start of processing for Check_Loop_Pragma_Placement
3208 while Present (Stmt) loop
3210 -- The pragma or previous block must appear immediately within the
3211 -- current block's declarative or statement part.
3213 if Nkind (Stmt) = N_Block_Statement then
3214 if (No (Declarations (Stmt))
3215 or else List_Containing (Prev) /= Declarations (Stmt))
3217 List_Containing (Prev) /=
3218 Statements (Handled_Statement_Sequence (Stmt))
3220 Placement_Error (Prev);
3223 -- Keep inspecting the parents because we are now within a
3224 -- chain of nested blocks.
3228 Stmt := Parent (Stmt);
3231 -- The pragma or previous block must appear immediately within the
3232 -- statements of the loop.
3234 elsif Nkind (Stmt) = N_Loop_Statement then
3235 if List_Containing (Prev) /= Statements (Stmt) then
3236 Placement_Error (Prev);
3239 -- Stop the traversal because we reached the innermost loop
3240 -- regardless of whether we encountered an error or not.
3244 -- Ignore a handled statement sequence. Note that this node may
3245 -- be related to a subprogram body in which case we will emit an
3246 -- error on the next iteration of the search.
3248 elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
3249 Stmt := Parent (Stmt);
3251 -- Any other statement breaks the chain from the pragma to the
3255 Placement_Error (Prev);
3259 end Check_Loop_Pragma_Placement;
3261 -------------------------------------------
3262 -- Check_Is_In_Decl_Part_Or_Package_Spec --
3263 -------------------------------------------
3265 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
3274 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
3277 elsif Nkind_In (P, N_Package_Specification,
3282 -- Note: the following tests seem a little peculiar, because
3283 -- they test for bodies, but if we were in the statement part
3284 -- of the body, we would already have hit the handled statement
3285 -- sequence, so the only way we get here is by being in the
3286 -- declarative part of the body.
3288 elsif Nkind_In (P, N_Subprogram_Body,
3299 Error_Pragma ("pragma% is not in declarative part or package spec");
3300 end Check_Is_In_Decl_Part_Or_Package_Spec;
3302 -------------------------
3303 -- Check_No_Identifier --
3304 -------------------------
3306 procedure Check_No_Identifier (Arg : Node_Id) is
3308 if Nkind (Arg) = N_Pragma_Argument_Association
3309 and then Chars (Arg) /= No_Name
3311 Error_Pragma_Arg_Ident
3312 ("pragma% does not permit identifier& here", Arg);
3314 end Check_No_Identifier;
3316 --------------------------
3317 -- Check_No_Identifiers --
3318 --------------------------
3320 procedure Check_No_Identifiers is
3324 for J in 1 .. Arg_Count loop
3325 Check_No_Identifier (Arg_Node);
3328 end Check_No_Identifiers;
3330 ------------------------
3331 -- Check_No_Link_Name --
3332 ------------------------
3334 procedure Check_No_Link_Name is
3336 if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
3340 if Present (Arg4) then
3342 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
3344 end Check_No_Link_Name;
3346 -------------------------------
3347 -- Check_Optional_Identifier --
3348 -------------------------------
3350 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
3353 and then Nkind (Arg) = N_Pragma_Argument_Association
3354 and then Chars (Arg) /= No_Name
3356 if Chars (Arg) /= Id then
3357 Error_Msg_Name_1 := Pname;
3358 Error_Msg_Name_2 := Id;
3359 Error_Msg_N ("pragma% argument expects identifier%", Arg);
3363 end Check_Optional_Identifier;
3365 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
3367 Name_Buffer (1 .. Id'Length) := Id;
3368 Name_Len := Id'Length;
3369 Check_Optional_Identifier (Arg, Name_Find);
3370 end Check_Optional_Identifier;
3372 --------------------------------------
3373 -- Check_Precondition_Postcondition --
3374 --------------------------------------
3376 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
3380 procedure Chain_PPC (PO : Node_Id);
3381 -- If PO is an entry or a [generic] subprogram declaration node, then
3382 -- the precondition/postcondition applies to this subprogram and the
3383 -- processing for the pragma is completed. Otherwise the pragma is
3390 procedure Chain_PPC (PO : Node_Id) is
3394 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
3395 if not From_Aspect_Specification (N) then
3397 ("pragma% cannot be applied to abstract subprogram");
3399 elsif Class_Present (N) then
3404 ("aspect % requires ''Class for abstract subprogram");
3407 -- AI05-0230: The same restriction applies to null procedures. For
3408 -- compatibility with earlier uses of the Ada pragma, apply this
3409 -- rule only to aspect specifications.
3411 -- The above discrpency needs documentation. Robert is dubious
3412 -- about whether it is a good idea ???
3414 elsif Nkind (PO) = N_Subprogram_Declaration
3415 and then Nkind (Specification (PO)) = N_Procedure_Specification
3416 and then Null_Present (Specification (PO))
3417 and then From_Aspect_Specification (N)
3418 and then not Class_Present (N)
3421 ("aspect % requires ''Class for null procedure");
3423 -- Pre/postconditions are legal on a subprogram body if it is not
3424 -- a completion of a declaration. They are also legal on a stub
3425 -- with no previous declarations (this is checked when processing
3426 -- the corresponding aspects).
3428 elsif Nkind (PO) = N_Subprogram_Body
3429 and then Acts_As_Spec (PO)
3433 elsif Nkind (PO) = N_Subprogram_Body_Stub then
3436 elsif not Nkind_In (PO, N_Subprogram_Declaration,
3437 N_Expression_Function,
3438 N_Generic_Subprogram_Declaration,
3439 N_Entry_Declaration)
3444 -- Here if we have [generic] subprogram or entry declaration
3446 if Nkind (PO) = N_Entry_Declaration then
3447 S := Defining_Entity (PO);
3449 S := Defining_Unit_Name (Specification (PO));
3451 if Nkind (S) = N_Defining_Program_Unit_Name then
3452 S := Defining_Identifier (S);
3456 -- Note: we do not analyze the pragma at this point. Instead we
3457 -- delay this analysis until the end of the declarative part in
3458 -- which the pragma appears. This implements the required delay
3459 -- in this analysis, allowing forward references. The analysis
3460 -- happens at the end of Analyze_Declarations.
3462 -- Chain spec PPC pragma to list for subprogram
3464 Add_Contract_Item (N, S);
3466 -- Return indicating spec case
3472 -- Start of processing for Check_Precondition_Postcondition
3475 if not Is_List_Member (N) then
3479 -- Preanalyze message argument if present. Visibility in this
3480 -- argument is established at the point of pragma occurrence.
3482 if Arg_Count = 2 then
3483 Check_Optional_Identifier (Arg2, Name_Message);
3484 Preanalyze_Spec_Expression
3485 (Get_Pragma_Arg (Arg2), Standard_String);
3488 -- For a pragma PPC in the extended main source unit, record enabled
3491 if not Is_Ignored (N) and then not Split_PPC (N) then
3492 Set_SCO_Pragma_Enabled (Loc);
3495 -- If we are within an inlined body, the legality of the pragma
3496 -- has been checked already.
3498 if In_Inlined_Body then
3503 -- Search prior declarations
3506 while Present (Prev (P)) loop
3509 -- If the previous node is a generic subprogram, do not go to to
3510 -- the original node, which is the unanalyzed tree: we need to
3511 -- attach the pre/postconditions to the analyzed version at this
3512 -- point. They get propagated to the original tree when analyzing
3513 -- the corresponding body.
3515 if Nkind (P) not in N_Generic_Declaration then
3516 PO := Original_Node (P);
3521 -- Skip past prior pragma
3523 if Nkind (PO) = N_Pragma then
3526 -- Skip stuff not coming from source
3528 elsif not Comes_From_Source (PO) then
3530 -- The condition may apply to a subprogram instantiation
3532 if Nkind (PO) = N_Subprogram_Declaration
3533 and then Present (Generic_Parent (Specification (PO)))
3538 elsif Nkind (PO) = N_Subprogram_Declaration
3539 and then In_Instance
3544 -- For all other cases of non source code, do nothing
3550 -- Only remaining possibility is subprogram declaration
3558 -- If we fall through loop, pragma is at start of list, so see if it
3559 -- is at the start of declarations of a subprogram body.
3561 if Nkind (Parent (N)) = N_Subprogram_Body
3562 and then List_Containing (N) = Declarations (Parent (N))
3564 if Operating_Mode /= Generate_Code
3565 or else Inside_A_Generic
3567 -- Analyze pragma expression for correctness and for ASIS use
3569 Preanalyze_Assert_Expression
3570 (Get_Pragma_Arg (Arg1), Standard_Boolean);
3572 -- In ASIS mode, for a pragma generated from a source aspect,
3573 -- also analyze the original aspect expression.
3575 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
3576 Preanalyze_Assert_Expression
3577 (Expression (Corresponding_Aspect (N)), Standard_Boolean);
3584 -- See if it is in the pragmas after a library level subprogram
3586 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3588 -- In formal verification mode, analyze pragma expression for
3589 -- correctness, as it is not expanded later.
3592 Analyze_PPC_In_Decl_Part
3593 (N, Defining_Entity (Unit (Parent (Parent (N)))));
3596 Chain_PPC (Unit (Parent (Parent (N))));
3600 -- If we fall through, pragma was misplaced
3603 end Check_Precondition_Postcondition;
3605 -----------------------------
3606 -- Check_Static_Constraint --
3607 -----------------------------
3609 -- Note: for convenience in writing this procedure, in addition to
3610 -- the officially (i.e. by spec) allowed argument which is always a
3611 -- constraint, it also allows ranges and discriminant associations.
3612 -- Above is not clear ???
3614 procedure Check_Static_Constraint (Constr : Node_Id) is
3616 procedure Require_Static (E : Node_Id);
3617 -- Require given expression to be static expression
3619 --------------------
3620 -- Require_Static --
3621 --------------------
3623 procedure Require_Static (E : Node_Id) is
3625 if not Is_OK_Static_Expression (E) then
3626 Flag_Non_Static_Expr
3627 ("non-static constraint not allowed in Unchecked_Union!", E);
3632 -- Start of processing for Check_Static_Constraint
3635 case Nkind (Constr) is
3636 when N_Discriminant_Association =>
3637 Require_Static (Expression (Constr));
3640 Require_Static (Low_Bound (Constr));
3641 Require_Static (High_Bound (Constr));
3643 when N_Attribute_Reference =>
3644 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
3645 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
3647 when N_Range_Constraint =>
3648 Check_Static_Constraint (Range_Expression (Constr));
3650 when N_Index_Or_Discriminant_Constraint =>
3654 IDC := First (Constraints (Constr));
3655 while Present (IDC) loop
3656 Check_Static_Constraint (IDC);
3664 end Check_Static_Constraint;
3666 ---------------------
3667 -- Check_Test_Case --
3668 ---------------------
3670 procedure Check_Test_Case is
3674 procedure Chain_CTC (PO : Node_Id);
3675 -- If PO is a [generic] subprogram declaration node, then the
3676 -- test-case applies to this subprogram and the processing for
3677 -- the pragma is completed. Otherwise the pragma is misplaced.
3683 procedure Chain_CTC (PO : Node_Id) is
3687 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
3689 ("pragma% cannot be applied to abstract subprogram");
3691 elsif Nkind (PO) = N_Entry_Declaration then
3692 Error_Pragma ("pragma% cannot be applied to entry");
3694 elsif not Nkind_In (PO, N_Subprogram_Declaration,
3695 N_Generic_Subprogram_Declaration)
3700 -- Here if we have [generic] subprogram declaration
3702 S := Defining_Unit_Name (Specification (PO));
3704 -- Note: we do not analyze the pragma at this point. Instead we
3705 -- delay this analysis until the end of the declarative part in
3706 -- which the pragma appears. This implements the required delay
3707 -- in this analysis, allowing forward references. The analysis
3708 -- happens at the end of Analyze_Declarations.
3710 -- There should not be another test-case with the same name
3711 -- associated to this subprogram.
3714 Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
3718 CTC := Contract_Test_Cases (Contract (S));
3719 while Present (CTC) loop
3721 -- Omit pragma Contract_Cases because it does not introduce
3722 -- a unique case name and it does not follow the syntax of
3725 if Pragma_Name (CTC) = Name_Contract_Cases then
3729 (Name, Get_Name_From_CTC_Pragma (CTC))
3731 Error_Msg_Sloc := Sloc (CTC);
3732 Error_Pragma ("name for pragma% is already used#");
3735 CTC := Next_Pragma (CTC);
3739 -- Chain spec CTC pragma to list for subprogram
3741 Add_Contract_Item (N, S);
3744 -- Start of processing for Check_Test_Case
3747 -- First check pragma arguments
3749 Check_At_Least_N_Arguments (2);
3750 Check_At_Most_N_Arguments (4);
3752 ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
3754 Check_Optional_Identifier (Arg1, Name_Name);
3755 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
3757 -- In ASIS mode, for a pragma generated from a source aspect, also
3758 -- analyze the original aspect expression.
3760 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
3761 Check_Expr_Is_Static_Expression
3762 (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
3765 Check_Optional_Identifier (Arg2, Name_Mode);
3766 Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
3768 if Arg_Count = 4 then
3769 Check_Identifier (Arg3, Name_Requires);
3770 Check_Identifier (Arg4, Name_Ensures);
3772 elsif Arg_Count = 3 then
3773 Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
3776 -- Check pragma placement
3778 if not Is_List_Member (N) then
3782 -- Test-case should only appear in package spec unit
3784 if Get_Source_Unit (N) = No_Unit
3785 or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
3786 N_Package_Declaration,
3787 N_Generic_Package_Declaration)
3792 -- Search prior declarations
3795 while Present (Prev (P)) loop
3798 -- If the previous node is a generic subprogram, do not go to to
3799 -- the original node, which is the unanalyzed tree: we need to
3800 -- attach the test-case to the analyzed version at this point.
3801 -- They get propagated to the original tree when analyzing the
3802 -- corresponding body.
3804 if Nkind (P) not in N_Generic_Declaration then
3805 PO := Original_Node (P);
3810 -- Skip past prior pragma
3812 if Nkind (PO) = N_Pragma then
3815 -- Skip stuff not coming from source
3817 elsif not Comes_From_Source (PO) then
3820 -- Only remaining possibility is subprogram declaration. First
3821 -- check that it is declared directly in a package declaration.
3822 -- This may be either the package declaration for the current unit
3823 -- being defined or a local package declaration.
3825 elsif not Present (Parent (Parent (PO)))
3826 or else not Present (Parent (Parent (Parent (PO))))
3827 or else not Nkind_In (Parent (Parent (PO)),
3828 N_Package_Declaration,
3829 N_Generic_Package_Declaration)
3839 -- If we fall through, pragma was misplaced
3842 end Check_Test_Case;
3844 --------------------------------------
3845 -- Check_Valid_Configuration_Pragma --
3846 --------------------------------------
3848 -- A configuration pragma must appear in the context clause of a
3849 -- compilation unit, and only other pragmas may precede it. Note that
3850 -- the test also allows use in a configuration pragma file.
3852 procedure Check_Valid_Configuration_Pragma is
3854 if not Is_Configuration_Pragma then
3855 Error_Pragma ("incorrect placement for configuration pragma%");
3857 end Check_Valid_Configuration_Pragma;
3859 -------------------------------------
3860 -- Check_Valid_Library_Unit_Pragma --
3861 -------------------------------------
3863 procedure Check_Valid_Library_Unit_Pragma is
3865 Parent_Node : Node_Id;
3866 Unit_Name : Entity_Id;
3867 Unit_Kind : Node_Kind;
3868 Unit_Node : Node_Id;
3869 Sindex : Source_File_Index;
3872 if not Is_List_Member (N) then
3876 Plist := List_Containing (N);
3877 Parent_Node := Parent (Plist);
3879 if Parent_Node = Empty then
3882 -- Case of pragma appearing after a compilation unit. In this case
3883 -- it must have an argument with the corresponding name and must
3884 -- be part of the following pragmas of its parent.
3886 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
3887 if Plist /= Pragmas_After (Parent_Node) then
3890 elsif Arg_Count = 0 then
3892 ("argument required if outside compilation unit");
3895 Check_No_Identifiers;
3896 Check_Arg_Count (1);
3897 Unit_Node := Unit (Parent (Parent_Node));
3898 Unit_Kind := Nkind (Unit_Node);
3900 Analyze (Get_Pragma_Arg (Arg1));
3902 if Unit_Kind = N_Generic_Subprogram_Declaration
3903 or else Unit_Kind = N_Subprogram_Declaration
3905 Unit_Name := Defining_Entity (Unit_Node);
3907 elsif Unit_Kind in N_Generic_Instantiation then
3908 Unit_Name := Defining_Entity (Unit_Node);
3911 Unit_Name := Cunit_Entity (Current_Sem_Unit);
3914 if Chars (Unit_Name) /=
3915 Chars (Entity (Get_Pragma_Arg (Arg1)))
3918 ("pragma% argument is not current unit name", Arg1);
3921 if Ekind (Unit_Name) = E_Package
3922 and then Present (Renamed_Entity (Unit_Name))
3924 Error_Pragma ("pragma% not allowed for renamed package");
3928 -- Pragma appears other than after a compilation unit
3931 -- Here we check for the generic instantiation case and also
3932 -- for the case of processing a generic formal package. We
3933 -- detect these cases by noting that the Sloc on the node
3934 -- does not belong to the current compilation unit.
3936 Sindex := Source_Index (Current_Sem_Unit);
3938 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
3939 Rewrite (N, Make_Null_Statement (Loc));
3942 -- If before first declaration, the pragma applies to the
3943 -- enclosing unit, and the name if present must be this name.
3945 elsif Is_Before_First_Decl (N, Plist) then
3946 Unit_Node := Unit_Declaration_Node (Current_Scope);
3947 Unit_Kind := Nkind (Unit_Node);
3949 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
3952 elsif Unit_Kind = N_Subprogram_Body
3953 and then not Acts_As_Spec (Unit_Node)
3957 elsif Nkind (Parent_Node) = N_Package_Body then
3960 elsif Nkind (Parent_Node) = N_Package_Specification
3961 and then Plist = Private_Declarations (Parent_Node)
3965 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
3966 or else Nkind (Parent_Node) =
3967 N_Generic_Subprogram_Declaration)
3968 and then Plist = Generic_Formal_Declarations (Parent_Node)
3972 elsif Arg_Count > 0 then
3973 Analyze (Get_Pragma_Arg (Arg1));
3975 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
3977 ("name in pragma% must be enclosing unit", Arg1);
3980 -- It is legal to have no argument in this context
3986 -- Error if not before first declaration. This is because a
3987 -- library unit pragma argument must be the name of a library
3988 -- unit (RM 10.1.5(7)), but the only names permitted in this
3989 -- context are (RM 10.1.5(6)) names of subprogram declarations,
3990 -- generic subprogram declarations or generic instantiations.
3994 ("pragma% misplaced, must be before first declaration");
3998 end Check_Valid_Library_Unit_Pragma;
4004 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
4005 Clist : constant Node_Id := Component_List (Variant);
4009 Comp := First (Component_Items (Clist));
4010 while Present (Comp) loop
4011 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
4020 procedure Error_Pragma (Msg : String) is
4021 MsgF : String := Msg;
4023 Error_Msg_Name_1 := Pname;
4025 Error_Msg_N (MsgF, N);
4029 ----------------------
4030 -- Error_Pragma_Arg --
4031 ----------------------
4033 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
4034 MsgF : String := Msg;
4036 Error_Msg_Name_1 := Pname;
4038 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
4040 end Error_Pragma_Arg;
4042 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
4043 MsgF : String := Msg1;
4045 Error_Msg_Name_1 := Pname;
4047 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
4048 Error_Pragma_Arg (Msg2, Arg);
4049 end Error_Pragma_Arg;
4051 ----------------------------
4052 -- Error_Pragma_Arg_Ident --
4053 ----------------------------
4055 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
4056 MsgF : String := Msg;
4058 Error_Msg_Name_1 := Pname;
4060 Error_Msg_N (MsgF, Arg);
4062 end Error_Pragma_Arg_Ident;
4064 ----------------------
4065 -- Error_Pragma_Ref --
4066 ----------------------
4068 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
4069 MsgF : String := Msg;
4071 Error_Msg_Name_1 := Pname;
4073 Error_Msg_Sloc := Sloc (Ref);
4074 Error_Msg_NE (MsgF, N, Ref);
4076 end Error_Pragma_Ref;
4078 ------------------------
4079 -- Find_Lib_Unit_Name --
4080 ------------------------
4082 function Find_Lib_Unit_Name return Entity_Id is
4084 -- Return inner compilation unit entity, for case of nested
4085 -- categorization pragmas. This happens in generic unit.
4087 if Nkind (Parent (N)) = N_Package_Specification
4088 and then Defining_Entity (Parent (N)) /= Current_Scope
4090 return Defining_Entity (Parent (N));
4092 return Current_Scope;
4094 end Find_Lib_Unit_Name;
4096 ----------------------------
4097 -- Find_Program_Unit_Name --
4098 ----------------------------
4100 procedure Find_Program_Unit_Name (Id : Node_Id) is
4101 Unit_Name : Entity_Id;
4102 Unit_Kind : Node_Kind;
4103 P : constant Node_Id := Parent (N);
4106 if Nkind (P) = N_Compilation_Unit then
4107 Unit_Kind := Nkind (Unit (P));
4109 if Unit_Kind = N_Subprogram_Declaration
4110 or else Unit_Kind = N_Package_Declaration
4111 or else Unit_Kind in N_Generic_Declaration
4113 Unit_Name := Defining_Entity (Unit (P));
4115 if Chars (Id) = Chars (Unit_Name) then
4116 Set_Entity (Id, Unit_Name);
4117 Set_Etype (Id, Etype (Unit_Name));
4119 Set_Etype (Id, Any_Type);
4121 ("cannot find program unit referenced by pragma%");
4125 Set_Etype (Id, Any_Type);
4126 Error_Pragma ("pragma% inapplicable to this unit");
4132 end Find_Program_Unit_Name;
4134 -----------------------------------------
4135 -- Find_Unique_Parameterless_Procedure --
4136 -----------------------------------------
4138 function Find_Unique_Parameterless_Procedure
4140 Arg : Node_Id) return Entity_Id
4142 Proc : Entity_Id := Empty;
4145 -- The body of this procedure needs some comments ???
4147 if not Is_Entity_Name (Name) then
4149 ("argument of pragma% must be entity name", Arg);
4151 elsif not Is_Overloaded (Name) then
4152 Proc := Entity (Name);
4154 if Ekind (Proc) /= E_Procedure
4155 or else Present (First_Formal (Proc))
4158 ("argument of pragma% must be parameterless procedure", Arg);
4163 Found : Boolean := False;
4165 Index : Interp_Index;
4168 Get_First_Interp (Name, Index, It);
4169 while Present (It.Nam) loop
4172 if Ekind (Proc) = E_Procedure
4173 and then No (First_Formal (Proc))
4177 Set_Entity (Name, Proc);
4178 Set_Is_Overloaded (Name, False);
4181 ("ambiguous handler name for pragma% ", Arg);
4185 Get_Next_Interp (Index, It);
4190 ("argument of pragma% must be parameterless procedure",
4193 Proc := Entity (Name);
4199 end Find_Unique_Parameterless_Procedure;
4205 procedure Fix_Error (Msg : in out String) is
4207 -- If we have a rewriting of another pragma, go to that pragma
4209 if Is_Rewrite_Substitution (N)
4210 and then Nkind (Original_Node (N)) = N_Pragma
4212 Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
4215 -- Case where pragma comes from an aspect specification
4217 if From_Aspect_Specification (N) then
4219 -- Change appearence of "pragma" in message to "aspect"
4221 for J in Msg'First .. Msg'Last - 5 loop
4222 if Msg (J .. J + 5) = "pragma" then
4223 Msg (J .. J + 5) := "aspect";
4227 -- Get name from corresponding aspect
4229 Error_Msg_Name_1 := Original_Name (N);
4233 -------------------------
4234 -- Gather_Associations --
4235 -------------------------
4237 procedure Gather_Associations
4239 Args : out Args_List)
4244 -- Initialize all parameters to Empty
4246 for J in Args'Range loop
4250 -- That's all we have to do if there are no argument associations
4252 if No (Pragma_Argument_Associations (N)) then
4256 -- Otherwise first deal with any positional parameters present
4258 Arg := First (Pragma_Argument_Associations (N));
4259 for Index in Args'Range loop
4260 exit when No (Arg) or else Chars (Arg) /= No_Name;
4261 Args (Index) := Get_Pragma_Arg (Arg);
4265 -- Positional parameters all processed, if any left, then we
4266 -- have too many positional parameters.
4268 if Present (Arg) and then Chars (Arg) = No_Name then
4270 ("too many positional associations for pragma%", Arg);
4273 -- Process named parameters if any are present
4275 while Present (Arg) loop
4276 if Chars (Arg) = No_Name then
4278 ("positional association cannot follow named association",
4282 for Index in Names'Range loop
4283 if Names (Index) = Chars (Arg) then
4284 if Present (Args (Index)) then
4286 ("duplicate argument association for pragma%", Arg);
4288 Args (Index) := Get_Pragma_Arg (Arg);
4293 if Index = Names'Last then
4294 Error_Msg_Name_1 := Pname;
4295 Error_Msg_N ("pragma% does not allow & argument", Arg);
4297 -- Check for possible misspelling
4299 for Index1 in Names'Range loop
4300 if Is_Bad_Spelling_Of
4301 (Chars (Arg), Names (Index1))
4303 Error_Msg_Name_1 := Names (Index1);
4304 Error_Msg_N -- CODEFIX
4305 ("\possible misspelling of%", Arg);
4317 end Gather_Associations;
4323 procedure GNAT_Pragma is
4325 -- We need to check the No_Implementation_Pragmas restriction for
4326 -- the case of a pragma from source. Note that the case of aspects
4327 -- generating corresponding pragmas marks these pragmas as not being
4328 -- from source, so this test also catches that case.
4330 if Comes_From_Source (N) then
4331 Check_Restriction (No_Implementation_Pragmas, N);
4335 --------------------------
4336 -- Is_Before_First_Decl --
4337 --------------------------
4339 function Is_Before_First_Decl
4340 (Pragma_Node : Node_Id;
4341 Decls : List_Id) return Boolean
4343 Item : Node_Id := First (Decls);
4346 -- Only other pragmas can come before this pragma
4349 if No (Item) or else Nkind (Item) /= N_Pragma then
4352 elsif Item = Pragma_Node then
4358 end Is_Before_First_Decl;
4360 -----------------------------
4361 -- Is_Configuration_Pragma --
4362 -----------------------------
4364 -- A configuration pragma must appear in the context clause of a
4365 -- compilation unit, and only other pragmas may precede it. Note that
4366 -- the test below also permits use in a configuration pragma file.
4368 function Is_Configuration_Pragma return Boolean is
4369 Lis : constant List_Id := List_Containing (N);
4370 Par : constant Node_Id := Parent (N);
4374 -- If no parent, then we are in the configuration pragma file,
4375 -- so the placement is definitely appropriate.
4380 -- Otherwise we must be in the context clause of a compilation unit
4381 -- and the only thing allowed before us in the context list is more
4382 -- configuration pragmas.
4384 elsif Nkind (Par) = N_Compilation_Unit
4385 and then Context_Items (Par) = Lis
4392 elsif Nkind (Prg) /= N_Pragma then
4402 end Is_Configuration_Pragma;
4404 --------------------------
4405 -- Is_In_Context_Clause --
4406 --------------------------
4408 function Is_In_Context_Clause return Boolean is
4410 Parent_Node : Node_Id;
4413 if not Is_List_Member (N) then
4417 Plist := List_Containing (N);
4418 Parent_Node := Parent (Plist);
4420 if Parent_Node = Empty
4421 or else Nkind (Parent_Node) /= N_Compilation_Unit
4422 or else Context_Items (Parent_Node) /= Plist
4429 end Is_In_Context_Clause;
4431 ---------------------------------
4432 -- Is_Static_String_Expression --
4433 ---------------------------------
4435 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
4436 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4439 Analyze_And_Resolve (Argx);
4440 return Is_OK_Static_Expression (Argx)
4441 and then Nkind (Argx) = N_String_Literal;
4442 end Is_Static_String_Expression;
4444 ----------------------
4445 -- Pragma_Misplaced --
4446 ----------------------
4448 procedure Pragma_Misplaced is
4450 Error_Pragma ("incorrect placement of pragma%");
4451 end Pragma_Misplaced;
4453 ------------------------------------
4454 -- Process_Atomic_Shared_Volatile --
4455 ------------------------------------
4457 procedure Process_Atomic_Shared_Volatile is
4464 procedure Set_Atomic (E : Entity_Id);
4465 -- Set given type as atomic, and if no explicit alignment was given,
4466 -- set alignment to unknown, since back end knows what the alignment
4467 -- requirements are for atomic arrays. Note: this step is necessary
4468 -- for derived types.
4474 procedure Set_Atomic (E : Entity_Id) is
4478 if not Has_Alignment_Clause (E) then
4479 Set_Alignment (E, Uint_0);
4483 -- Start of processing for Process_Atomic_Shared_Volatile
4486 Check_Ada_83_Warning;
4487 Check_No_Identifiers;
4488 Check_Arg_Count (1);
4489 Check_Arg_Is_Local_Name (Arg1);
4490 E_Id := Get_Pragma_Arg (Arg1);
4492 if Etype (E_Id) = Any_Type then
4497 D := Declaration_Node (E);
4500 -- Check duplicate before we chain ourselves!
4502 Check_Duplicate_Pragma (E);
4504 -- Now check appropriateness of the entity
4507 if Rep_Item_Too_Early (E, N)
4509 Rep_Item_Too_Late (E, N)
4513 Check_First_Subtype (Arg1);
4516 if Prag_Id /= Pragma_Volatile then
4518 Set_Atomic (Underlying_Type (E));
4519 Set_Atomic (Base_Type (E));
4522 -- Attribute belongs on the base type. If the view of the type is
4523 -- currently private, it also belongs on the underlying type.
4525 Set_Is_Volatile (Base_Type (E));
4526 Set_Is_Volatile (Underlying_Type (E));
4528 Set_Treat_As_Volatile (E);
4529 Set_Treat_As_Volatile (Underlying_Type (E));
4531 elsif K = N_Object_Declaration
4532 or else (K = N_Component_Declaration
4533 and then Original_Record_Component (E) = E)
4535 if Rep_Item_Too_Late (E, N) then
4539 if Prag_Id /= Pragma_Volatile then
4542 -- If the object declaration has an explicit initialization, a
4543 -- temporary may have to be created to hold the expression, to
4544 -- ensure that access to the object remain atomic.
4546 if Nkind (Parent (E)) = N_Object_Declaration
4547 and then Present (Expression (Parent (E)))
4549 Set_Has_Delayed_Freeze (E);
4552 -- An interesting improvement here. If an object of composite
4553 -- type X is declared atomic, and the type X isn't, that's a
4554 -- pity, since it may not have appropriate alignment etc. We
4555 -- can rescue this in the special case where the object and
4556 -- type are in the same unit by just setting the type as
4557 -- atomic, so that the back end will process it as atomic.
4559 -- Note: we used to do this for elementary types as well,
4560 -- but that turns out to be a bad idea and can have unwanted
4561 -- effects, most notably if the type is elementary, the object
4562 -- a simple component within a record, and both are in a spec:
4563 -- every object of this type in the entire program will be
4564 -- treated as atomic, thus incurring a potentially costly
4565 -- synchronization operation for every access.
4567 -- Of course it would be best if the back end could just adjust
4568 -- the alignment etc for the specific object, but that's not
4569 -- something we are capable of doing at this point.
4571 Utyp := Underlying_Type (Etype (E));
4574 and then Is_Composite_Type (Utyp)
4575 and then Sloc (E) > No_Location
4576 and then Sloc (Utyp) > No_Location
4578 Get_Source_File_Index (Sloc (E)) =
4579 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
4581 Set_Is_Atomic (Underlying_Type (Etype (E)));
4585 Set_Is_Volatile (E);
4586 Set_Treat_As_Volatile (E);
4590 ("inappropriate entity for pragma%", Arg1);
4592 end Process_Atomic_Shared_Volatile;
4594 -------------------------------------------
4595 -- Process_Compile_Time_Warning_Or_Error --
4596 -------------------------------------------
4598 procedure Process_Compile_Time_Warning_Or_Error is
4599 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4602 Check_Arg_Count (2);
4603 Check_No_Identifiers;
4604 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4605 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4607 if Compile_Time_Known_Value (Arg1x) then
4608 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4610 Str : constant String_Id :=
4611 Strval (Get_Pragma_Arg (Arg2));
4612 Len : constant Int := String_Length (Str);
4617 Cent : constant Entity_Id :=
4618 Cunit_Entity (Current_Sem_Unit);
4620 Force : constant Boolean :=
4621 Prag_Id = Pragma_Compile_Time_Warning
4623 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
4624 and then (Ekind (Cent) /= E_Package
4625 or else not In_Private_Part (Cent));
4626 -- Set True if this is the warning case, and we are in the
4627 -- visible part of a package spec, or in a subprogram spec,
4628 -- in which case we want to force the client to see the
4629 -- warning, even though it is not in the main unit.
4632 -- Loop through segments of message separated by line feeds.
4633 -- We output these segments as separate messages with
4634 -- continuation marks for all but the first.
4639 Error_Msg_Strlen := 0;
4641 -- Loop to copy characters from argument to error message
4645 exit when Ptr > Len;
4646 CC := Get_String_Char (Str, Ptr);
4649 -- Ignore wide chars ??? else store character
4651 if In_Character_Range (CC) then
4652 C := Get_Character (CC);
4653 exit when C = ASCII.LF;
4654 Error_Msg_Strlen := Error_Msg_Strlen + 1;
4655 Error_Msg_String (Error_Msg_Strlen) := C;
4659 -- Here with one line ready to go
4661 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
4663 -- If this is a warning in a spec, then we want clients
4664 -- to see the warning, so mark the message with the
4665 -- special sequence !! to force the warning. In the case
4666 -- of a package spec, we do not force this if we are in
4667 -- the private part of the spec.
4670 if Cont = False then
4671 Error_Msg_N ("<~!!", Arg1);
4674 Error_Msg_N ("\<~!!", Arg1);
4677 -- Error, rather than warning, or in a body, so we do not
4678 -- need to force visibility for client (error will be
4679 -- output in any case, and this is the situation in which
4680 -- we do not want a client to get a warning, since the
4681 -- warning is in the body or the spec private part).
4684 if Cont = False then
4685 Error_Msg_N ("<~", Arg1);
4688 Error_Msg_N ("\<~", Arg1);
4692 exit when Ptr > Len;
4697 end Process_Compile_Time_Warning_Or_Error;
4699 ------------------------
4700 -- Process_Convention --
4701 ------------------------
4703 procedure Process_Convention
4704 (C : out Convention_Id;
4705 Ent : out Entity_Id)
4711 Comp_Unit : Unit_Number_Type;
4713 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
4714 -- Called if we have more than one Export/Import/Convention pragma.
4715 -- This is generally illegal, but we have a special case of allowing
4716 -- Import and Interface to coexist if they specify the convention in
4717 -- a consistent manner. We are allowed to do this, since Interface is
4718 -- an implementation defined pragma, and we choose to do it since we
4719 -- know Rational allows this combination. S is the entity id of the
4720 -- subprogram in question. This procedure also sets the special flag
4721 -- Import_Interface_Present in both pragmas in the case where we do
4722 -- have matching Import and Interface pragmas.
4724 procedure Set_Convention_From_Pragma (E : Entity_Id);
4725 -- Set convention in entity E, and also flag that the entity has a
4726 -- convention pragma. If entity is for a private or incomplete type,
4727 -- also set convention and flag on underlying type. This procedure
4728 -- also deals with the special case of C_Pass_By_Copy convention.
4730 -------------------------------
4731 -- Diagnose_Multiple_Pragmas --
4732 -------------------------------
4734 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
4735 Pdec : constant Node_Id := Declaration_Node (S);
4739 function Same_Convention (Decl : Node_Id) return Boolean;
4740 -- Decl is a pragma node. This function returns True if this
4741 -- pragma has a first argument that is an identifier with a
4742 -- Chars field corresponding to the Convention_Id C.
4744 function Same_Name (Decl : Node_Id) return Boolean;
4745 -- Decl is a pragma node. This function returns True if this
4746 -- pragma has a second argument that is an identifier with a
4747 -- Chars field that matches the Chars of the current subprogram.
4749 ---------------------
4750 -- Same_Convention --
4751 ---------------------
4753 function Same_Convention (Decl : Node_Id) return Boolean is
4754 Arg1 : constant Node_Id :=
4755 First (Pragma_Argument_Associations (Decl));
4758 if Present (Arg1) then
4760 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
4762 if Nkind (Arg) = N_Identifier
4763 and then Is_Convention_Name (Chars (Arg))
4764 and then Get_Convention_Id (Chars (Arg)) = C
4772 end Same_Convention;
4778 function Same_Name (Decl : Node_Id) return Boolean is
4779 Arg1 : constant Node_Id :=
4780 First (Pragma_Argument_Associations (Decl));
4788 Arg2 := Next (Arg1);
4795 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
4797 if Nkind (Arg) = N_Identifier
4798 and then Chars (Arg) = Chars (S)
4807 -- Start of processing for Diagnose_Multiple_Pragmas
4812 -- Definitely give message if we have Convention/Export here
4814 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
4817 -- If we have an Import or Export, scan back from pragma to
4818 -- find any previous pragma applying to the same procedure.
4819 -- The scan will be terminated by the start of the list, or
4820 -- hitting the subprogram declaration. This won't allow one
4821 -- pragma to appear in the public part and one in the private
4822 -- part, but that seems very unlikely in practice.
4826 while Present (Decl) and then Decl /= Pdec loop
4828 -- Look for pragma with same name as us
4830 if Nkind (Decl) = N_Pragma
4831 and then Same_Name (Decl)
4833 -- Give error if same as our pragma or Export/Convention
4835 if Nam_In (Pragma_Name (Decl), Name_Export,
4841 -- Case of Import/Interface or the other way round
4843 elsif Nam_In (Pragma_Name (Decl), Name_Interface,
4846 -- Here we know that we have Import and Interface. It
4847 -- doesn't matter which way round they are. See if
4848 -- they specify the same convention. If so, all OK,
4849 -- and set special flags to stop other messages
4851 if Same_Convention (Decl) then
4852 Set_Import_Interface_Present (N);
4853 Set_Import_Interface_Present (Decl);
4856 -- If different conventions, special message
4859 Error_Msg_Sloc := Sloc (Decl);
4861 ("convention differs from that given#", Arg1);
4871 -- Give message if needed if we fall through those tests
4872 -- except on Relaxed_RM_Semantics where we let go: either this
4873 -- is a case accepted/ignored by other Ada compilers (e.g.
4874 -- a mix of Convention and Import), or another error will be
4875 -- generated later (e.g. using both Import and Export).
4877 if Err and not Relaxed_RM_Semantics then
4879 ("at most one Convention/Export/Import pragma is allowed",
4882 end Diagnose_Multiple_Pragmas;
4884 --------------------------------
4885 -- Set_Convention_From_Pragma --
4886 --------------------------------
4888 procedure Set_Convention_From_Pragma (E : Entity_Id) is
4890 -- Ada 2005 (AI-430): Check invalid attempt to change convention
4891 -- for an overridden dispatching operation. Technically this is
4892 -- an amendment and should only be done in Ada 2005 mode. However,
4893 -- this is clearly a mistake, since the problem that is addressed
4894 -- by this AI is that there is a clear gap in the RM!
4896 if Is_Dispatching_Operation (E)
4897 and then Present (Overridden_Operation (E))
4898 and then C /= Convention (Overridden_Operation (E))
4900 -- An attempt to override a subprogram with a ghost subprogram
4901 -- appears as a mismatch in conventions.
4903 if C = Convention_Ghost then
4904 Error_Msg_N ("ghost subprogram & cannot be overriding", E);
4907 ("cannot change convention for overridden dispatching "
4908 & "operation", Arg1);
4912 -- Special checks for Convention_Stdcall
4914 if C = Convention_Stdcall then
4916 -- A dispatching call is not allowed. A dispatching subprogram
4917 -- cannot be used to interface to the Win32 API, so in fact
4918 -- this check does not impose any effective restriction.
4920 if Is_Dispatching_Operation (E) then
4921 Error_Msg_Sloc := Sloc (E);
4923 -- Note: make this unconditional so that if there is more
4924 -- than one call to which the pragma applies, we get a
4925 -- message for each call. Also don't use Error_Pragma,
4926 -- so that we get multiple messages!
4929 ("dispatching subprogram# cannot use Stdcall convention!",
4932 -- Subprogram is allowed, but not a generic subprogram
4934 elsif not Is_Subprogram (E)
4935 and then not Is_Generic_Subprogram (E)
4939 and then Ekind (E) /= E_Variable
4941 -- An access to subprogram is also allowed
4945 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
4947 -- Allow internal call to set convention of subprogram type
4949 and then not (Ekind (E) = E_Subprogram_Type)
4952 ("second argument of pragma% must be subprogram (type)",
4957 -- Set the convention
4959 Set_Convention (E, C);
4960 Set_Has_Convention_Pragma (E);
4962 if Is_Incomplete_Or_Private_Type (E)
4963 and then Present (Underlying_Type (E))
4965 Set_Convention (Underlying_Type (E), C);
4966 Set_Has_Convention_Pragma (Underlying_Type (E), True);
4969 -- A class-wide type should inherit the convention of the specific
4970 -- root type (although this isn't specified clearly by the RM).
4972 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
4973 Set_Convention (Class_Wide_Type (E), C);
4976 -- If the entity is a record type, then check for special case of
4977 -- C_Pass_By_Copy, which is treated the same as C except that the
4978 -- special record flag is set. This convention is only permitted
4979 -- on record types (see AI95-00131).
4981 if Cname = Name_C_Pass_By_Copy then
4982 if Is_Record_Type (E) then
4983 Set_C_Pass_By_Copy (Base_Type (E));
4984 elsif Is_Incomplete_Or_Private_Type (E)
4985 and then Is_Record_Type (Underlying_Type (E))
4987 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
4990 ("C_Pass_By_Copy convention allowed only for record type",
4995 -- If the entity is a derived boolean type, check for the special
4996 -- case of convention C, C++, or Fortran, where we consider any
4997 -- nonzero value to represent true.
4999 if Is_Discrete_Type (E)
5000 and then Root_Type (Etype (E)) = Standard_Boolean
5006 C = Convention_Fortran)
5008 Set_Nonzero_Is_True (Base_Type (E));
5010 end Set_Convention_From_Pragma;
5012 -- Start of processing for Process_Convention
5015 Check_At_Least_N_Arguments (2);
5016 Check_Optional_Identifier (Arg1, Name_Convention);
5017 Check_Arg_Is_Identifier (Arg1);
5018 Cname := Chars (Get_Pragma_Arg (Arg1));
5020 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
5021 -- tested again below to set the critical flag).
5023 if Cname = Name_C_Pass_By_Copy then
5026 -- Otherwise we must have something in the standard convention list
5028 elsif Is_Convention_Name (Cname) then
5029 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
5031 -- In DEC VMS, it seems that there is an undocumented feature that
5032 -- any unrecognized convention is treated as the default, which for
5033 -- us is convention C. It does not seem so terrible to do this
5034 -- unconditionally, silently in the VMS case, and with a warning
5035 -- in the non-VMS case.
5038 if Warn_On_Export_Import and not OpenVMS_On_Target then
5040 ("??unrecognized convention name, C assumed",
5041 Get_Pragma_Arg (Arg1));
5047 Check_Optional_Identifier (Arg2, Name_Entity);
5048 Check_Arg_Is_Local_Name (Arg2);
5050 Id := Get_Pragma_Arg (Arg2);
5053 if not Is_Entity_Name (Id) then
5054 Error_Pragma_Arg ("entity name required", Arg2);
5059 -- Set entity to return
5063 -- Ada_Pass_By_Copy special checking
5065 if C = Convention_Ada_Pass_By_Copy then
5066 if not Is_First_Subtype (E) then
5068 ("convention `Ada_Pass_By_Copy` only allowed for types",
5072 if Is_By_Reference_Type (E) then
5074 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
5079 -- Ada_Pass_By_Reference special checking
5081 if C = Convention_Ada_Pass_By_Reference then
5082 if not Is_First_Subtype (E) then
5084 ("convention `Ada_Pass_By_Reference` only allowed for types",
5088 if Is_By_Copy_Type (E) then
5090 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
5095 -- Ghost special checking
5097 if Is_Ghost_Subprogram (E)
5098 and then Present (Overridden_Operation (E))
5100 Error_Msg_N ("ghost subprogram & cannot be overriding", E);
5103 -- Go to renamed subprogram if present, since convention applies to
5104 -- the actual renamed entity, not to the renaming entity. If the
5105 -- subprogram is inherited, go to parent subprogram.
5107 if Is_Subprogram (E)
5108 and then Present (Alias (E))
5110 if Nkind (Parent (Declaration_Node (E))) =
5111 N_Subprogram_Renaming_Declaration
5113 if Scope (E) /= Scope (Alias (E)) then
5115 ("cannot apply pragma% to non-local entity&#", E);
5120 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
5121 N_Private_Extension_Declaration)
5122 and then Scope (E) = Scope (Alias (E))
5126 -- Return the parent subprogram the entity was inherited from
5132 -- Check that we are not applying this to a specless body
5133 -- Relax this check if Relaxed_RM_Semantics to accomodate other Ada
5136 if Is_Subprogram (E)
5137 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
5138 and then not Relaxed_RM_Semantics
5141 ("pragma% requires separate spec and must come before body");
5144 -- Check that we are not applying this to a named constant
5146 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
5147 Error_Msg_Name_1 := Pname;
5149 ("cannot apply pragma% to named constant!",
5150 Get_Pragma_Arg (Arg2));
5152 ("\supply appropriate type for&!", Arg2);
5155 if Ekind (E) = E_Enumeration_Literal then
5156 Error_Pragma ("enumeration literal not allowed for pragma%");
5159 -- Check for rep item appearing too early or too late
5161 if Etype (E) = Any_Type
5162 or else Rep_Item_Too_Early (E, N)
5166 elsif Present (Underlying_Type (E)) then
5167 E := Underlying_Type (E);
5170 if Rep_Item_Too_Late (E, N) then
5174 if Has_Convention_Pragma (E) then
5175 Diagnose_Multiple_Pragmas (E);
5177 elsif Convention (E) = Convention_Protected
5178 or else Ekind (Scope (E)) = E_Protected_Type
5181 ("a protected operation cannot be given a different convention",
5185 -- For Intrinsic, a subprogram is required
5187 if C = Convention_Intrinsic
5188 and then not Is_Subprogram (E)
5189 and then not Is_Generic_Subprogram (E)
5192 ("second argument of pragma% must be a subprogram", Arg2);
5195 -- Deal with non-subprogram cases
5197 if not Is_Subprogram (E)
5198 and then not Is_Generic_Subprogram (E)
5200 Set_Convention_From_Pragma (E);
5203 Check_First_Subtype (Arg2);
5204 Set_Convention_From_Pragma (Base_Type (E));
5206 -- For access subprograms, we must set the convention on the
5207 -- internally generated directly designated type as well.
5209 if Ekind (E) = E_Access_Subprogram_Type then
5210 Set_Convention_From_Pragma (Directly_Designated_Type (E));
5214 -- For the subprogram case, set proper convention for all homonyms
5215 -- in same scope and the same declarative part, i.e. the same
5216 -- compilation unit.
5219 Comp_Unit := Get_Source_Unit (E);
5220 Set_Convention_From_Pragma (E);
5222 -- Treat a pragma Import as an implicit body, and pragma import
5223 -- as implicit reference (for navigation in GPS).
5225 if Prag_Id = Pragma_Import then
5226 Generate_Reference (E, Id, 'b');
5228 -- For exported entities we restrict the generation of references
5229 -- to entities exported to foreign languages since entities
5230 -- exported to Ada do not provide further information to GPS and
5231 -- add undesired references to the output of the gnatxref tool.
5233 elsif Prag_Id = Pragma_Export
5234 and then Convention (E) /= Convention_Ada
5236 Generate_Reference (E, Id, 'i');
5239 -- If the pragma comes from from an aspect, it only applies to the
5240 -- given entity, not its homonyms.
5242 if From_Aspect_Specification (N) then
5246 -- Otherwise Loop through the homonyms of the pragma argument's
5247 -- entity, an apply convention to those in the current scope.
5253 exit when No (E1) or else Scope (E1) /= Current_Scope;
5255 -- Ignore entry for which convention is already set
5257 if Has_Convention_Pragma (E1) then
5261 -- Do not set the pragma on inherited operations or on formal
5264 if Comes_From_Source (E1)
5265 and then Comp_Unit = Get_Source_Unit (E1)
5266 and then not Is_Formal_Subprogram (E1)
5267 and then Nkind (Original_Node (Parent (E1))) /=
5268 N_Full_Type_Declaration
5270 if Present (Alias (E1))
5271 and then Scope (E1) /= Scope (Alias (E1))
5274 ("cannot apply pragma% to non-local entity& declared#",
5278 Set_Convention_From_Pragma (E1);
5280 if Prag_Id = Pragma_Import then
5281 Generate_Reference (E1, Id, 'b');
5289 end Process_Convention;
5291 ----------------------------------------
5292 -- Process_Disable_Enable_Atomic_Sync --
5293 ----------------------------------------
5295 procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
5297 Check_No_Identifiers;
5298 Check_At_Most_N_Arguments (1);
5300 -- Modeled internally as
5301 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
5305 Pragma_Identifier =>
5306 Make_Identifier (Loc, Nam),
5307 Pragma_Argument_Associations => New_List (
5308 Make_Pragma_Argument_Association (Loc,
5310 Make_Identifier (Loc, Name_Atomic_Synchronization)))));
5312 if Present (Arg1) then
5313 Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
5317 end Process_Disable_Enable_Atomic_Sync;
5319 -----------------------------------------------------
5320 -- Process_Extended_Import_Export_Exception_Pragma --
5321 -----------------------------------------------------
5323 procedure Process_Extended_Import_Export_Exception_Pragma
5324 (Arg_Internal : Node_Id;
5325 Arg_External : Node_Id;
5333 if not OpenVMS_On_Target then
5335 ("??pragma% ignored (applies only to Open'V'M'S)");
5338 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
5339 Def_Id := Entity (Arg_Internal);
5341 if Ekind (Def_Id) /= E_Exception then
5343 ("pragma% must refer to declared exception", Arg_Internal);
5346 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
5348 if Present (Arg_Form) then
5349 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
5352 if Present (Arg_Form)
5353 and then Chars (Arg_Form) = Name_Ada
5357 Set_Is_VMS_Exception (Def_Id);
5358 Set_Exception_Code (Def_Id, No_Uint);
5361 if Present (Arg_Code) then
5362 if not Is_VMS_Exception (Def_Id) then
5364 ("Code option for pragma% not allowed for Ada case",
5368 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
5369 Code_Val := Expr_Value (Arg_Code);
5371 if not UI_Is_In_Int_Range (Code_Val) then
5373 ("Code option for pragma% must be in 32-bit range",
5377 Set_Exception_Code (Def_Id, Code_Val);
5380 end Process_Extended_Import_Export_Exception_Pragma;
5382 -------------------------------------------------
5383 -- Process_Extended_Import_Export_Internal_Arg --
5384 -------------------------------------------------
5386 procedure Process_Extended_Import_Export_Internal_Arg
5387 (Arg_Internal : Node_Id := Empty)
5390 if No (Arg_Internal) then
5391 Error_Pragma ("Internal parameter required for pragma%");
5394 if Nkind (Arg_Internal) = N_Identifier then
5397 elsif Nkind (Arg_Internal) = N_Operator_Symbol
5398 and then (Prag_Id = Pragma_Import_Function
5400 Prag_Id = Pragma_Export_Function)
5406 ("wrong form for Internal parameter for pragma%", Arg_Internal);
5409 Check_Arg_Is_Local_Name (Arg_Internal);
5410 end Process_Extended_Import_Export_Internal_Arg;
5412 --------------------------------------------------
5413 -- Process_Extended_Import_Export_Object_Pragma --
5414 --------------------------------------------------
5416 procedure Process_Extended_Import_Export_Object_Pragma
5417 (Arg_Internal : Node_Id;
5418 Arg_External : Node_Id;
5424 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
5425 Def_Id := Entity (Arg_Internal);
5427 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
5429 ("pragma% must designate an object", Arg_Internal);
5432 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
5434 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
5437 ("previous Common/Psect_Object applies, pragma % not permitted",
5441 if Rep_Item_Too_Late (Def_Id, N) then
5445 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
5447 if Present (Arg_Size) then
5448 Check_Arg_Is_External_Name (Arg_Size);
5451 -- Export_Object case
5453 if Prag_Id = Pragma_Export_Object then
5454 if not Is_Library_Level_Entity (Def_Id) then
5456 ("argument for pragma% must be library level entity",
5460 if Ekind (Current_Scope) = E_Generic_Package then
5461 Error_Pragma ("pragma& cannot appear in a generic unit");
5464 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
5466 ("exported object must have compile time known size",
5470 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
5471 Error_Msg_N ("??duplicate Export_Object pragma", N);
5473 Set_Exported (Def_Id, Arg_Internal);
5476 -- Import_Object case
5479 if Is_Concurrent_Type (Etype (Def_Id)) then
5481 ("cannot use pragma% for task/protected object",
5485 if Ekind (Def_Id) = E_Constant then
5487 ("cannot import a constant", Arg_Internal);
5490 if Warn_On_Export_Import
5491 and then Has_Discriminants (Etype (Def_Id))
5494 ("imported value must be initialized??", Arg_Internal);
5497 if Warn_On_Export_Import
5498 and then Is_Access_Type (Etype (Def_Id))
5501 ("cannot import object of an access type??", Arg_Internal);
5504 if Warn_On_Export_Import
5505 and then Is_Imported (Def_Id)
5507 Error_Msg_N ("??duplicate Import_Object pragma", N);
5509 -- Check for explicit initialization present. Note that an
5510 -- initialization generated by the code generator, e.g. for an
5511 -- access type, does not count here.
5513 elsif Present (Expression (Parent (Def_Id)))
5516 (Original_Node (Expression (Parent (Def_Id))))
5518 Error_Msg_Sloc := Sloc (Def_Id);
5520 ("imported entities cannot be initialized (RM B.1(24))",
5521 "\no initialization allowed for & declared#", Arg1);
5523 Set_Imported (Def_Id);
5524 Note_Possible_Modification (Arg_Internal, Sure => False);
5527 end Process_Extended_Import_Export_Object_Pragma;
5529 ------------------------------------------------------
5530 -- Process_Extended_Import_Export_Subprogram_Pragma --
5531 ------------------------------------------------------
5533 procedure Process_Extended_Import_Export_Subprogram_Pragma
5534 (Arg_Internal : Node_Id;
5535 Arg_External : Node_Id;
5536 Arg_Parameter_Types : Node_Id;
5537 Arg_Result_Type : Node_Id := Empty;
5538 Arg_Mechanism : Node_Id;
5539 Arg_Result_Mechanism : Node_Id := Empty;
5540 Arg_First_Optional_Parameter : Node_Id := Empty)
5546 Ambiguous : Boolean;
5550 function Same_Base_Type
5552 Formal : Entity_Id) return Boolean;
5553 -- Determines if Ptype references the type of Formal. Note that only
5554 -- the base types need to match according to the spec. Ptype here is
5555 -- the argument from the pragma, which is either a type name, or an
5556 -- access attribute.
5558 --------------------
5559 -- Same_Base_Type --
5560 --------------------
5562 function Same_Base_Type
5564 Formal : Entity_Id) return Boolean
5566 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
5570 -- Case where pragma argument is typ'Access
5572 if Nkind (Ptype) = N_Attribute_Reference
5573 and then Attribute_Name (Ptype) = Name_Access
5575 Pref := Prefix (Ptype);
5578 if not Is_Entity_Name (Pref)
5579 or else Entity (Pref) = Any_Type
5584 -- We have a match if the corresponding argument is of an
5585 -- anonymous access type, and its designated type matches the
5586 -- type of the prefix of the access attribute
5588 return Ekind (Ftyp) = E_Anonymous_Access_Type
5589 and then Base_Type (Entity (Pref)) =
5590 Base_Type (Etype (Designated_Type (Ftyp)));
5592 -- Case where pragma argument is a type name
5597 if not Is_Entity_Name (Ptype)
5598 or else Entity (Ptype) = Any_Type
5603 -- We have a match if the corresponding argument is of the type
5604 -- given in the pragma (comparing base types)
5606 return Base_Type (Entity (Ptype)) = Ftyp;
5610 -- Start of processing for
5611 -- Process_Extended_Import_Export_Subprogram_Pragma
5614 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
5618 -- Loop through homonyms (overloadings) of the entity
5620 Hom_Id := Entity (Arg_Internal);
5621 while Present (Hom_Id) loop
5622 Def_Id := Get_Base_Subprogram (Hom_Id);
5624 -- We need a subprogram in the current scope
5626 if not Is_Subprogram (Def_Id)
5627 or else Scope (Def_Id) /= Current_Scope
5634 -- Pragma cannot apply to subprogram body
5636 if Is_Subprogram (Def_Id)
5637 and then Nkind (Parent (Declaration_Node (Def_Id))) =
5641 ("pragma% requires separate spec"
5642 & " and must come before body");
5645 -- Test result type if given, note that the result type
5646 -- parameter can only be present for the function cases.
5648 if Present (Arg_Result_Type)
5649 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
5653 elsif Etype (Def_Id) /= Standard_Void_Type
5655 Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
5659 -- Test parameter types if given. Note that this parameter
5660 -- has not been analyzed (and must not be, since it is
5661 -- semantic nonsense), so we get it as the parser left it.
5663 elsif Present (Arg_Parameter_Types) then
5664 Check_Matching_Types : declare
5669 Formal := First_Formal (Def_Id);
5671 if Nkind (Arg_Parameter_Types) = N_Null then
5672 if Present (Formal) then
5676 -- A list of one type, e.g. (List) is parsed as
5677 -- a parenthesized expression.
5679 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
5680 and then Paren_Count (Arg_Parameter_Types) = 1
5683 or else Present (Next_Formal (Formal))
5688 Same_Base_Type (Arg_Parameter_Types, Formal);
5691 -- A list of more than one type is parsed as a aggregate
5693 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
5694 and then Paren_Count (Arg_Parameter_Types) = 0
5696 Ptype := First (Expressions (Arg_Parameter_Types));
5697 while Present (Ptype) or else Present (Formal) loop
5700 or else not Same_Base_Type (Ptype, Formal)
5705 Next_Formal (Formal);
5710 -- Anything else is of the wrong form
5714 ("wrong form for Parameter_Types parameter",
5715 Arg_Parameter_Types);
5717 end Check_Matching_Types;
5720 -- Match is now False if the entry we found did not match
5721 -- either a supplied Parameter_Types or Result_Types argument
5727 -- Ambiguous case, the flag Ambiguous shows if we already
5728 -- detected this and output the initial messages.
5731 if not Ambiguous then
5733 Error_Msg_Name_1 := Pname;
5735 ("pragma% does not uniquely identify subprogram!",
5737 Error_Msg_Sloc := Sloc (Ent);
5738 Error_Msg_N ("matching subprogram #!", N);
5742 Error_Msg_Sloc := Sloc (Def_Id);
5743 Error_Msg_N ("matching subprogram #!", N);
5748 Hom_Id := Homonym (Hom_Id);
5751 -- See if we found an entry
5754 if not Ambiguous then
5755 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
5757 ("pragma% cannot be given for generic subprogram");
5760 ("pragma% does not identify local subprogram");
5767 -- Import pragmas must be for imported entities
5769 if Prag_Id = Pragma_Import_Function
5771 Prag_Id = Pragma_Import_Procedure
5773 Prag_Id = Pragma_Import_Valued_Procedure
5775 if not Is_Imported (Ent) then
5777 ("pragma Import or Interface must precede pragma%");
5780 -- Here we have the Export case which can set the entity as exported
5782 -- But does not do so if the specified external name is null, since
5783 -- that is taken as a signal in DEC Ada 83 (with which we want to be
5784 -- compatible) to request no external name.
5786 elsif Nkind (Arg_External) = N_String_Literal
5787 and then String_Length (Strval (Arg_External)) = 0
5791 -- In all other cases, set entity as exported
5794 Set_Exported (Ent, Arg_Internal);
5797 -- Special processing for Valued_Procedure cases
5799 if Prag_Id = Pragma_Import_Valued_Procedure
5801 Prag_Id = Pragma_Export_Valued_Procedure
5803 Formal := First_Formal (Ent);
5806 Error_Pragma ("at least one parameter required for pragma%");
5808 elsif Ekind (Formal) /= E_Out_Parameter then
5809 Error_Pragma ("first parameter must have mode out for pragma%");
5812 Set_Is_Valued_Procedure (Ent);
5816 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
5818 -- Process Result_Mechanism argument if present. We have already
5819 -- checked that this is only allowed for the function case.
5821 if Present (Arg_Result_Mechanism) then
5822 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
5825 -- Process Mechanism parameter if present. Note that this parameter
5826 -- is not analyzed, and must not be analyzed since it is semantic
5827 -- nonsense, so we get it in exactly as the parser left it.
5829 if Present (Arg_Mechanism) then
5837 -- A single mechanism association without a formal parameter
5838 -- name is parsed as a parenthesized expression. All other
5839 -- cases are parsed as aggregates, so we rewrite the single
5840 -- parameter case as an aggregate for consistency.
5842 if Nkind (Arg_Mechanism) /= N_Aggregate
5843 and then Paren_Count (Arg_Mechanism) = 1
5845 Rewrite (Arg_Mechanism,
5846 Make_Aggregate (Sloc (Arg_Mechanism),
5847 Expressions => New_List (
5848 Relocate_Node (Arg_Mechanism))));
5851 -- Case of only mechanism name given, applies to all formals
5853 if Nkind (Arg_Mechanism) /= N_Aggregate then
5854 Formal := First_Formal (Ent);
5855 while Present (Formal) loop
5856 Set_Mechanism_Value (Formal, Arg_Mechanism);
5857 Next_Formal (Formal);
5860 -- Case of list of mechanism associations given
5863 if Null_Record_Present (Arg_Mechanism) then
5865 ("inappropriate form for Mechanism parameter",
5869 -- Deal with positional ones first
5871 Formal := First_Formal (Ent);
5873 if Present (Expressions (Arg_Mechanism)) then
5874 Mname := First (Expressions (Arg_Mechanism));
5875 while Present (Mname) loop
5878 ("too many mechanism associations", Mname);
5881 Set_Mechanism_Value (Formal, Mname);
5882 Next_Formal (Formal);
5887 -- Deal with named entries
5889 if Present (Component_Associations (Arg_Mechanism)) then
5890 Massoc := First (Component_Associations (Arg_Mechanism));
5891 while Present (Massoc) loop
5892 Choice := First (Choices (Massoc));
5894 if Nkind (Choice) /= N_Identifier
5895 or else Present (Next (Choice))
5898 ("incorrect form for mechanism association",
5902 Formal := First_Formal (Ent);
5906 ("parameter name & not present", Choice);
5909 if Chars (Choice) = Chars (Formal) then
5911 (Formal, Expression (Massoc));
5913 -- Set entity on identifier (needed by ASIS)
5915 Set_Entity (Choice, Formal);
5920 Next_Formal (Formal);
5930 -- Process First_Optional_Parameter argument if present. We have
5931 -- already checked that this is only allowed for the Import case.
5933 if Present (Arg_First_Optional_Parameter) then
5934 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
5936 ("first optional parameter must be formal parameter name",
5937 Arg_First_Optional_Parameter);
5940 Formal := First_Formal (Ent);
5944 ("specified formal parameter& not found",
5945 Arg_First_Optional_Parameter);
5948 exit when Chars (Formal) =
5949 Chars (Arg_First_Optional_Parameter);
5951 Next_Formal (Formal);
5954 Set_First_Optional_Parameter (Ent, Formal);
5956 -- Check specified and all remaining formals have right form
5958 while Present (Formal) loop
5959 if Ekind (Formal) /= E_In_Parameter then
5961 ("optional formal& is not of mode in!",
5962 Arg_First_Optional_Parameter, Formal);
5965 Dval := Default_Value (Formal);
5969 ("optional formal& does not have default value!",
5970 Arg_First_Optional_Parameter, Formal);
5972 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
5977 ("default value for optional formal& is non-static!",
5978 Arg_First_Optional_Parameter, Formal);
5982 Set_Is_Optional_Parameter (Formal);
5983 Next_Formal (Formal);
5986 end Process_Extended_Import_Export_Subprogram_Pragma;
5988 --------------------------
5989 -- Process_Generic_List --
5990 --------------------------
5992 procedure Process_Generic_List is
5997 Check_No_Identifiers;
5998 Check_At_Least_N_Arguments (1);
6000 -- Check all arguments are names of generic units or instances
6003 while Present (Arg) loop
6004 Exp := Get_Pragma_Arg (Arg);
6007 if not Is_Entity_Name (Exp)
6009 (not Is_Generic_Instance (Entity (Exp))
6011 not Is_Generic_Unit (Entity (Exp)))
6014 ("pragma% argument must be name of generic unit/instance",
6020 end Process_Generic_List;
6022 ------------------------------------
6023 -- Process_Import_Predefined_Type --
6024 ------------------------------------
6026 procedure Process_Import_Predefined_Type is
6027 Loc : constant Source_Ptr := Sloc (N);
6029 Ftyp : Node_Id := Empty;
6035 String_To_Name_Buffer (Strval (Expression (Arg3)));
6038 Elmt := First_Elmt (Predefined_Float_Types);
6039 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
6043 Ftyp := Node (Elmt);
6045 if Present (Ftyp) then
6047 -- Don't build a derived type declaration, because predefined C
6048 -- types have no declaration anywhere, so cannot really be named.
6049 -- Instead build a full type declaration, starting with an
6050 -- appropriate type definition is built
6052 if Is_Floating_Point_Type (Ftyp) then
6053 Def := Make_Floating_Point_Definition (Loc,
6054 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
6055 Make_Real_Range_Specification (Loc,
6056 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
6057 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
6059 -- Should never have a predefined type we cannot handle
6062 raise Program_Error;
6065 -- Build and insert a Full_Type_Declaration, which will be
6066 -- analyzed as soon as this list entry has been analyzed.
6068 Decl := Make_Full_Type_Declaration (Loc,
6069 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
6070 Type_Definition => Def);
6072 Insert_After (N, Decl);
6073 Mark_Rewrite_Insertion (Decl);
6076 Error_Pragma_Arg ("no matching type found for pragma%",
6079 end Process_Import_Predefined_Type;
6081 ---------------------------------
6082 -- Process_Import_Or_Interface --
6083 ---------------------------------
6085 procedure Process_Import_Or_Interface is
6091 Process_Convention (C, Def_Id);
6092 Kill_Size_Check_Code (Def_Id);
6093 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
6095 if Ekind_In (Def_Id, E_Variable, E_Constant) then
6097 -- We do not permit Import to apply to a renaming declaration
6099 if Present (Renamed_Object (Def_Id)) then
6101 ("pragma% not allowed for object renaming", Arg2);
6103 -- User initialization is not allowed for imported object, but
6104 -- the object declaration may contain a default initialization,
6105 -- that will be discarded. Note that an explicit initialization
6106 -- only counts if it comes from source, otherwise it is simply
6107 -- the code generator making an implicit initialization explicit.
6109 elsif Present (Expression (Parent (Def_Id)))
6110 and then Comes_From_Source (Expression (Parent (Def_Id)))
6112 Error_Msg_Sloc := Sloc (Def_Id);
6114 ("no initialization allowed for declaration of& #",
6115 "\imported entities cannot be initialized (RM B.1(24))",
6119 Set_Imported (Def_Id);
6120 Process_Interface_Name (Def_Id, Arg3, Arg4);
6122 -- Note that we do not set Is_Public here. That's because we
6123 -- only want to set it if there is no address clause, and we
6124 -- don't know that yet, so we delay that processing till
6127 -- pragma Import completes deferred constants
6129 if Ekind (Def_Id) = E_Constant then
6130 Set_Has_Completion (Def_Id);
6133 -- It is not possible to import a constant of an unconstrained
6134 -- array type (e.g. string) because there is no simple way to
6135 -- write a meaningful subtype for it.
6137 if Is_Array_Type (Etype (Def_Id))
6138 and then not Is_Constrained (Etype (Def_Id))
6141 ("imported constant& must have a constrained subtype",
6146 elsif Is_Subprogram (Def_Id)
6147 or else Is_Generic_Subprogram (Def_Id)
6149 -- If the name is overloaded, pragma applies to all of the denoted
6150 -- entities in the same declarative part, unless the pragma comes
6151 -- from an aspect specification.
6154 while Present (Hom_Id) loop
6156 Def_Id := Get_Base_Subprogram (Hom_Id);
6158 -- Ignore inherited subprograms because the pragma will apply
6159 -- to the parent operation, which is the one called.
6161 if Is_Overloadable (Def_Id)
6162 and then Present (Alias (Def_Id))
6166 -- If it is not a subprogram, it must be in an outer scope and
6167 -- pragma does not apply.
6169 elsif not Is_Subprogram (Def_Id)
6170 and then not Is_Generic_Subprogram (Def_Id)
6174 -- The pragma does not apply to primitives of interfaces
6176 elsif Is_Dispatching_Operation (Def_Id)
6177 and then Present (Find_Dispatching_Type (Def_Id))
6178 and then Is_Interface (Find_Dispatching_Type (Def_Id))
6182 -- Verify that the homonym is in the same declarative part (not
6183 -- just the same scope). If the pragma comes from an aspect
6184 -- specification we know that it is part of the declaration.
6186 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
6187 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
6188 and then not From_Aspect_Specification (N)
6193 Set_Imported (Def_Id);
6195 -- Reject an Import applied to an abstract subprogram
6197 if Is_Subprogram (Def_Id)
6198 and then Is_Abstract_Subprogram (Def_Id)
6200 Error_Msg_Sloc := Sloc (Def_Id);
6202 ("cannot import abstract subprogram& declared#",
6206 -- Special processing for Convention_Intrinsic
6208 if C = Convention_Intrinsic then
6210 -- Link_Name argument not allowed for intrinsic
6214 Set_Is_Intrinsic_Subprogram (Def_Id);
6216 -- If no external name is present, then check that this
6217 -- is a valid intrinsic subprogram. If an external name
6218 -- is present, then this is handled by the back end.
6221 Check_Intrinsic_Subprogram
6222 (Def_Id, Get_Pragma_Arg (Arg2));
6226 -- All interfaced procedures need an external symbol created
6227 -- for them since they are always referenced from another
6230 Set_Is_Public (Def_Id);
6232 -- Verify that the subprogram does not have a completion
6233 -- through a renaming declaration. For other completions the
6234 -- pragma appears as a too late representation.
6237 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
6241 and then Nkind (Decl) = N_Subprogram_Declaration
6242 and then Present (Corresponding_Body (Decl))
6243 and then Nkind (Unit_Declaration_Node
6244 (Corresponding_Body (Decl))) =
6245 N_Subprogram_Renaming_Declaration
6247 Error_Msg_Sloc := Sloc (Def_Id);
6249 ("cannot import&, renaming already provided for "
6250 & "declaration #", N, Def_Id);
6254 Set_Has_Completion (Def_Id);
6255 Process_Interface_Name (Def_Id, Arg3, Arg4);
6258 if Is_Compilation_Unit (Hom_Id) then
6260 -- Its possible homonyms are not affected by the pragma.
6261 -- Such homonyms might be present in the context of other
6262 -- units being compiled.
6266 elsif From_Aspect_Specification (N) then
6270 Hom_Id := Homonym (Hom_Id);
6274 -- When the convention is Java or CIL, we also allow Import to
6275 -- be given for packages, generic packages, exceptions, record
6276 -- components, and access to subprograms.
6278 elsif (C = Convention_Java or else C = Convention_CIL)
6280 (Is_Package_Or_Generic_Package (Def_Id)
6281 or else Ekind (Def_Id) = E_Exception
6282 or else Ekind (Def_Id) = E_Access_Subprogram_Type
6283 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
6285 Set_Imported (Def_Id);
6286 Set_Is_Public (Def_Id);
6287 Process_Interface_Name (Def_Id, Arg3, Arg4);
6289 -- Import a CPP class
6291 elsif C = Convention_CPP
6292 and then (Is_Record_Type (Def_Id)
6293 or else Ekind (Def_Id) = E_Incomplete_Type)
6295 if Ekind (Def_Id) = E_Incomplete_Type then
6296 if Present (Full_View (Def_Id)) then
6297 Def_Id := Full_View (Def_Id);
6301 ("cannot import 'C'P'P type before full declaration seen",
6302 Get_Pragma_Arg (Arg2));
6304 -- Although we have reported the error we decorate it as
6305 -- CPP_Class to avoid reporting spurious errors
6307 Set_Is_CPP_Class (Def_Id);
6312 -- Types treated as CPP classes must be declared limited (note:
6313 -- this used to be a warning but there is no real benefit to it
6314 -- since we did effectively intend to treat the type as limited
6317 if not Is_Limited_Type (Def_Id) then
6319 ("imported 'C'P'P type must be limited",
6320 Get_Pragma_Arg (Arg2));
6323 if Etype (Def_Id) /= Def_Id
6324 and then not Is_CPP_Class (Root_Type (Def_Id))
6326 Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
6329 Set_Is_CPP_Class (Def_Id);
6331 -- Imported CPP types must not have discriminants (because C++
6332 -- classes do not have discriminants).
6334 if Has_Discriminants (Def_Id) then
6336 ("imported 'C'P'P type cannot have discriminants",
6337 First (Discriminant_Specifications
6338 (Declaration_Node (Def_Id))));
6341 -- Check that components of imported CPP types do not have default
6342 -- expressions. For private types this check is performed when the
6343 -- full view is analyzed (see Process_Full_View).
6345 if not Is_Private_Type (Def_Id) then
6346 Check_CPP_Type_Has_No_Defaults (Def_Id);
6349 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
6351 Check_Arg_Count (3);
6352 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
6354 Process_Import_Predefined_Type;
6358 ("second argument of pragma% must be object, subprogram "
6359 & "or incomplete type",
6363 -- If this pragma applies to a compilation unit, then the unit, which
6364 -- is a subprogram, does not require (or allow) a body. We also do
6365 -- not need to elaborate imported procedures.
6367 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
6369 Cunit : constant Node_Id := Parent (Parent (N));
6371 Set_Body_Required (Cunit, False);
6374 end Process_Import_Or_Interface;
6376 --------------------
6377 -- Process_Inline --
6378 --------------------
6380 procedure Process_Inline (Status : Inline_Status) is
6387 Effective : Boolean := False;
6388 -- Set True if inline has some effect, i.e. if there is at least one
6389 -- subprogram set as inlined as a result of the use of the pragma.
6391 procedure Make_Inline (Subp : Entity_Id);
6392 -- Subp is the defining unit name of the subprogram declaration. Set
6393 -- the flag, as well as the flag in the corresponding body, if there
6396 procedure Set_Inline_Flags (Subp : Entity_Id);
6397 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
6398 -- Has_Pragma_Inline_Always for the Inline_Always case.
6400 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
6401 -- Returns True if it can be determined at this stage that inlining
6402 -- is not possible, for example if the body is available and contains
6403 -- exception handlers, we prevent inlining, since otherwise we can
6404 -- get undefined symbols at link time. This function also emits a
6405 -- warning if front-end inlining is enabled and the pragma appears
6408 -- ??? is business with link symbols still valid, or does it relate
6409 -- to front end ZCX which is being phased out ???
6411 ---------------------------
6412 -- Inlining_Not_Possible --
6413 ---------------------------
6415 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
6416 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
6420 if Nkind (Decl) = N_Subprogram_Body then
6421 Stats := Handled_Statement_Sequence (Decl);
6422 return Present (Exception_Handlers (Stats))
6423 or else Present (At_End_Proc (Stats));
6425 elsif Nkind (Decl) = N_Subprogram_Declaration
6426 and then Present (Corresponding_Body (Decl))
6428 if Front_End_Inlining
6429 and then Analyzed (Corresponding_Body (Decl))
6431 Error_Msg_N ("pragma appears too late, ignored??", N);
6434 -- If the subprogram is a renaming as body, the body is just a
6435 -- call to the renamed subprogram, and inlining is trivially
6439 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
6440 N_Subprogram_Renaming_Declaration
6446 Handled_Statement_Sequence
6447 (Unit_Declaration_Node (Corresponding_Body (Decl)));
6450 Present (Exception_Handlers (Stats))
6451 or else Present (At_End_Proc (Stats));
6455 -- If body is not available, assume the best, the check is
6456 -- performed again when compiling enclosing package bodies.
6460 end Inlining_Not_Possible;
6466 procedure Make_Inline (Subp : Entity_Id) is
6467 Kind : constant Entity_Kind := Ekind (Subp);
6468 Inner_Subp : Entity_Id := Subp;
6471 -- Ignore if bad type, avoid cascaded error
6473 if Etype (Subp) = Any_Type then
6477 -- Ignore if all inlining is suppressed
6479 elsif Suppress_All_Inlining then
6483 -- If inlining is not possible, for now do not treat as an error
6485 elsif Status /= Suppressed
6486 and then Inlining_Not_Possible (Subp)
6491 -- Here we have a candidate for inlining, but we must exclude
6492 -- derived operations. Otherwise we would end up trying to inline
6493 -- a phantom declaration, and the result would be to drag in a
6494 -- body which has no direct inlining associated with it. That
6495 -- would not only be inefficient but would also result in the
6496 -- backend doing cross-unit inlining in cases where it was
6497 -- definitely inappropriate to do so.
6499 -- However, a simple Comes_From_Source test is insufficient, since
6500 -- we do want to allow inlining of generic instances which also do
6501 -- not come from source. We also need to recognize specs generated
6502 -- by the front-end for bodies that carry the pragma. Finally,
6503 -- predefined operators do not come from source but are not
6504 -- inlineable either.
6506 elsif Is_Generic_Instance (Subp)
6507 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
6511 elsif not Comes_From_Source (Subp)
6512 and then Scope (Subp) /= Standard_Standard
6518 -- The referenced entity must either be the enclosing entity, or
6519 -- an entity declared within the current open scope.
6521 if Present (Scope (Subp))
6522 and then Scope (Subp) /= Current_Scope
6523 and then Subp /= Current_Scope
6526 ("argument of% must be entity in current scope", Assoc);
6530 -- Processing for procedure, operator or function. If subprogram
6531 -- is aliased (as for an instance) indicate that the renamed
6532 -- entity (if declared in the same unit) is inlined.
6534 if Is_Subprogram (Subp) then
6535 Inner_Subp := Ultimate_Alias (Inner_Subp);
6537 if In_Same_Source_Unit (Subp, Inner_Subp) then
6538 Set_Inline_Flags (Inner_Subp);
6540 Decl := Parent (Parent (Inner_Subp));
6542 if Nkind (Decl) = N_Subprogram_Declaration
6543 and then Present (Corresponding_Body (Decl))
6545 Set_Inline_Flags (Corresponding_Body (Decl));
6547 elsif Is_Generic_Instance (Subp) then
6549 -- Indicate that the body needs to be created for
6550 -- inlining subsequent calls. The instantiation node
6551 -- follows the declaration of the wrapper package
6554 if Scope (Subp) /= Standard_Standard
6556 Need_Subprogram_Instance_Body
6557 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
6563 -- Inline is a program unit pragma (RM 10.1.5) and cannot
6564 -- appear in a formal part to apply to a formal subprogram.
6565 -- Do not apply check within an instance or a formal package
6566 -- the test will have been applied to the original generic.
6568 elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
6569 and then List_Containing (Decl) = List_Containing (N)
6570 and then not In_Instance
6573 ("Inline cannot apply to a formal subprogram", N);
6575 -- If Subp is a renaming, it is the renamed entity that
6576 -- will appear in any call, and be inlined. However, for
6577 -- ASIS uses it is convenient to indicate that the renaming
6578 -- itself is an inlined subprogram, so that some gnatcheck
6579 -- rules can be applied in the absence of expansion.
6581 elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
6582 Set_Inline_Flags (Subp);
6588 -- For a generic subprogram set flag as well, for use at the point
6589 -- of instantiation, to determine whether the body should be
6592 elsif Is_Generic_Subprogram (Subp) then
6593 Set_Inline_Flags (Subp);
6596 -- Literals are by definition inlined
6598 elsif Kind = E_Enumeration_Literal then
6601 -- Anything else is an error
6605 ("expect subprogram name for pragma%", Assoc);
6609 ----------------------
6610 -- Set_Inline_Flags --
6611 ----------------------
6613 procedure Set_Inline_Flags (Subp : Entity_Id) is
6615 -- First set the Has_Pragma_XXX flags and issue the appropriate
6616 -- errors and warnings for suspicious combinations.
6618 if Prag_Id = Pragma_No_Inline then
6619 if Has_Pragma_Inline_Always (Subp) then
6621 ("Inline_Always and No_Inline are mutually exclusive", N);
6622 elsif Has_Pragma_Inline (Subp) then
6624 ("Inline and No_Inline both specified for& ??",
6625 N, Entity (Subp_Id));
6628 Set_Has_Pragma_No_Inline (Subp);
6630 if Prag_Id = Pragma_Inline_Always then
6631 if Has_Pragma_No_Inline (Subp) then
6633 ("Inline_Always and No_Inline are mutually exclusive",
6637 Set_Has_Pragma_Inline_Always (Subp);
6639 if Has_Pragma_No_Inline (Subp) then
6641 ("Inline and No_Inline both specified for& ??",
6642 N, Entity (Subp_Id));
6646 if not Has_Pragma_Inline (Subp) then
6647 Set_Has_Pragma_Inline (Subp);
6652 -- Then adjust the Is_Inlined flag. It can never be set if the
6653 -- subprogram is subject to pragma No_Inline.
6657 Set_Is_Inlined (Subp, False);
6661 if not Has_Pragma_No_Inline (Subp) then
6662 Set_Is_Inlined (Subp, True);
6665 end Set_Inline_Flags;
6667 -- Start of processing for Process_Inline
6670 Check_No_Identifiers;
6671 Check_At_Least_N_Arguments (1);
6673 if Status = Enabled then
6674 Inline_Processing_Required := True;
6678 while Present (Assoc) loop
6679 Subp_Id := Get_Pragma_Arg (Assoc);
6683 if Is_Entity_Name (Subp_Id) then
6684 Subp := Entity (Subp_Id);
6686 if Subp = Any_Id then
6688 -- If previous error, avoid cascaded errors
6690 Check_Error_Detected;
6697 -- For the pragma case, climb homonym chain. This is
6698 -- what implements allowing the pragma in the renaming
6699 -- case, with the result applying to the ancestors, and
6700 -- also allows Inline to apply to all previous homonyms.
6702 if not From_Aspect_Specification (N) then
6703 while Present (Homonym (Subp))
6704 and then Scope (Homonym (Subp)) = Current_Scope
6706 Make_Inline (Homonym (Subp));
6707 Subp := Homonym (Subp);
6715 ("inappropriate argument for pragma%", Assoc);
6718 and then Warn_On_Redundant_Constructs
6719 and then not (Status = Suppressed or else Suppress_All_Inlining)
6721 if Inlining_Not_Possible (Subp) then
6723 ("pragma Inline for& is ignored?r?",
6724 N, Entity (Subp_Id));
6727 ("pragma Inline for& is redundant?r?",
6728 N, Entity (Subp_Id));
6736 ----------------------------
6737 -- Process_Interface_Name --
6738 ----------------------------
6740 procedure Process_Interface_Name
6741 (Subprogram_Def : Entity_Id;
6747 String_Val : String_Id;
6749 procedure Check_Form_Of_Interface_Name
6751 Ext_Name_Case : Boolean);
6752 -- SN is a string literal node for an interface name. This routine
6753 -- performs some minimal checks that the name is reasonable. In
6754 -- particular that no spaces or other obviously incorrect characters
6755 -- appear. This is only a warning, since any characters are allowed.
6756 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
6758 ----------------------------------
6759 -- Check_Form_Of_Interface_Name --
6760 ----------------------------------
6762 procedure Check_Form_Of_Interface_Name
6764 Ext_Name_Case : Boolean)
6766 S : constant String_Id := Strval (Expr_Value_S (SN));
6767 SL : constant Nat := String_Length (S);
6772 Error_Msg_N ("interface name cannot be null string", SN);
6775 for J in 1 .. SL loop
6776 C := Get_String_Char (S, J);
6778 -- Look for dubious character and issue unconditional warning.
6779 -- Definitely dubious if not in character range.
6781 if not In_Character_Range (C)
6783 -- For all cases except CLI target,
6784 -- commas, spaces and slashes are dubious (in CLI, we use
6785 -- commas and backslashes in external names to specify
6786 -- assembly version and public key, while slashes and spaces
6787 -- can be used in names to mark nested classes and
6790 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
6791 and then (Get_Character (C) = ','
6793 Get_Character (C) = '\'))
6794 or else (VM_Target /= CLI_Target
6795 and then (Get_Character (C) = ' '
6797 Get_Character (C) = '/'))
6800 ("??interface name contains illegal character",
6801 Sloc (SN) + Source_Ptr (J));
6804 end Check_Form_Of_Interface_Name;
6806 -- Start of processing for Process_Interface_Name
6809 if No (Link_Arg) then
6810 if No (Ext_Arg) then
6811 if VM_Target = CLI_Target
6812 and then Ekind (Subprogram_Def) = E_Package
6813 and then Nkind (Parent (Subprogram_Def)) =
6814 N_Package_Specification
6815 and then Present (Generic_Parent (Parent (Subprogram_Def)))
6820 (Generic_Parent (Parent (Subprogram_Def))));
6825 elsif Chars (Ext_Arg) = Name_Link_Name then
6827 Link_Nam := Expression (Ext_Arg);
6830 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
6831 Ext_Nam := Expression (Ext_Arg);
6836 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
6837 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
6838 Ext_Nam := Expression (Ext_Arg);
6839 Link_Nam := Expression (Link_Arg);
6842 -- Check expressions for external name and link name are static
6844 if Present (Ext_Nam) then
6845 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
6846 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
6848 -- Verify that external name is not the name of a local entity,
6849 -- which would hide the imported one and could lead to run-time
6850 -- surprises. The problem can only arise for entities declared in
6851 -- a package body (otherwise the external name is fully qualified
6852 -- and will not conflict).
6860 if Prag_Id = Pragma_Import then
6861 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
6863 E := Entity_Id (Get_Name_Table_Info (Nam));
6865 if Nam /= Chars (Subprogram_Def)
6866 and then Present (E)
6867 and then not Is_Overloadable (E)
6868 and then Is_Immediately_Visible (E)
6869 and then not Is_Imported (E)
6870 and then Ekind (Scope (E)) = E_Package
6873 while Present (Par) loop
6874 if Nkind (Par) = N_Package_Body then
6875 Error_Msg_Sloc := Sloc (E);
6877 ("imported entity is hidden by & declared#",
6882 Par := Parent (Par);
6889 if Present (Link_Nam) then
6890 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
6891 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
6894 -- If there is no link name, just set the external name
6896 if No (Link_Nam) then
6897 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
6899 -- For the Link_Name case, the given literal is preceded by an
6900 -- asterisk, which indicates to GCC that the given name should be
6901 -- taken literally, and in particular that no prepending of
6902 -- underlines should occur, even in systems where this is the
6908 if VM_Target = No_VM then
6909 Store_String_Char (Get_Char_Code ('*'));
6912 String_Val := Strval (Expr_Value_S (Link_Nam));
6913 Store_String_Chars (String_Val);
6915 Make_String_Literal (Sloc (Link_Nam),
6916 Strval => End_String);
6919 -- Set the interface name. If the entity is a generic instance, use
6920 -- its alias, which is the callable entity.
6922 if Is_Generic_Instance (Subprogram_Def) then
6923 Set_Encoded_Interface_Name
6924 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
6926 Set_Encoded_Interface_Name
6927 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
6930 -- We allow duplicated export names in CIL/Java, as they are always
6931 -- enclosed in a namespace that differentiates them, and overloaded
6932 -- entities are supported by the VM.
6934 if Convention (Subprogram_Def) /= Convention_CIL
6936 Convention (Subprogram_Def) /= Convention_Java
6938 Check_Duplicated_Export_Name (Link_Nam);
6940 end Process_Interface_Name;
6942 -----------------------------------------
6943 -- Process_Interrupt_Or_Attach_Handler --
6944 -----------------------------------------
6946 procedure Process_Interrupt_Or_Attach_Handler is
6947 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
6948 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
6949 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
6952 Set_Is_Interrupt_Handler (Handler_Proc);
6954 -- If the pragma is not associated with a handler procedure within a
6955 -- protected type, then it must be for a nonprotected procedure for
6956 -- the AAMP target, in which case we don't associate a representation
6957 -- item with the procedure's scope.
6959 if Ekind (Proc_Scope) = E_Protected_Type then
6960 if Prag_Id = Pragma_Interrupt_Handler
6962 Prag_Id = Pragma_Attach_Handler
6964 Record_Rep_Item (Proc_Scope, N);
6967 end Process_Interrupt_Or_Attach_Handler;
6969 --------------------------------------------------
6970 -- Process_Restrictions_Or_Restriction_Warnings --
6971 --------------------------------------------------
6973 -- Note: some of the simple identifier cases were handled in par-prag,
6974 -- but it is harmless (and more straightforward) to simply handle all
6975 -- cases here, even if it means we repeat a bit of work in some cases.
6977 procedure Process_Restrictions_Or_Restriction_Warnings
6981 R_Id : Restriction_Id;
6986 procedure Check_Unit_Name (N : Node_Id);
6987 -- Checks unit name parameter for No_Dependence. Returns if it has
6988 -- an appropriate form, otherwise raises pragma argument error.
6990 ---------------------
6991 -- Check_Unit_Name --
6992 ---------------------
6994 procedure Check_Unit_Name (N : Node_Id) is
6996 if Nkind (N) = N_Selected_Component then
6997 Check_Unit_Name (Prefix (N));
6998 Check_Unit_Name (Selector_Name (N));
7000 elsif Nkind (N) = N_Identifier then
7005 ("wrong form for unit name for No_Dependence", N);
7007 end Check_Unit_Name;
7009 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
7012 -- Ignore all Restrictions pragma in CodePeer mode
7014 if CodePeer_Mode then
7018 Check_Ada_83_Warning;
7019 Check_At_Least_N_Arguments (1);
7020 Check_Valid_Configuration_Pragma;
7023 while Present (Arg) loop
7025 Expr := Get_Pragma_Arg (Arg);
7027 -- Case of no restriction identifier present
7029 if Id = No_Name then
7030 if Nkind (Expr) /= N_Identifier then
7032 ("invalid form for restriction", Arg);
7037 (Process_Restriction_Synonyms (Expr));
7039 if R_Id not in All_Boolean_Restrictions then
7040 Error_Msg_Name_1 := Pname;
7042 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
7044 -- Check for possible misspelling
7046 for J in Restriction_Id loop
7048 Rnm : constant String := Restriction_Id'Image (J);
7051 Name_Buffer (1 .. Rnm'Length) := Rnm;
7052 Name_Len := Rnm'Length;
7053 Set_Casing (All_Lower_Case);
7055 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
7057 (Identifier_Casing (Current_Source_File));
7058 Error_Msg_String (1 .. Rnm'Length) :=
7059 Name_Buffer (1 .. Name_Len);
7060 Error_Msg_Strlen := Rnm'Length;
7061 Error_Msg_N -- CODEFIX
7062 ("\possible misspelling of ""~""",
7063 Get_Pragma_Arg (Arg));
7072 if Implementation_Restriction (R_Id) then
7073 Check_Restriction (No_Implementation_Restrictions, Arg);
7076 -- Special processing for No_Elaboration_Code restriction
7078 if R_Id = No_Elaboration_Code then
7080 -- Restriction is only recognized within a configuration
7081 -- pragma file, or within a unit of the main extended
7082 -- program. Note: the test for Main_Unit is needed to
7083 -- properly include the case of configuration pragma files.
7085 if not (Current_Sem_Unit = Main_Unit
7086 or else In_Extended_Main_Source_Unit (N))
7090 -- Don't allow in a subunit unless already specified in
7093 elsif Nkind (Parent (N)) = N_Compilation_Unit
7094 and then Nkind (Unit (Parent (N))) = N_Subunit
7095 and then not Restriction_Active (No_Elaboration_Code)
7098 ("invalid specification of ""No_Elaboration_Code""",
7101 ("\restriction cannot be specified in a subunit", N);
7103 ("\unless also specified in body or spec", N);
7106 -- If we have a No_Elaboration_Code pragma that we
7107 -- accept, then it needs to be added to the configuration
7108 -- restrcition set so that we get proper application to
7109 -- other units in the main extended source as required.
7112 Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
7116 -- If this is a warning, then set the warning unless we already
7117 -- have a real restriction active (we never want a warning to
7118 -- override a real restriction).
7121 if not Restriction_Active (R_Id) then
7122 Set_Restriction (R_Id, N);
7123 Restriction_Warnings (R_Id) := True;
7126 -- If real restriction case, then set it and make sure that the
7127 -- restriction warning flag is off, since a real restriction
7128 -- always overrides a warning.
7131 Set_Restriction (R_Id, N);
7132 Restriction_Warnings (R_Id) := False;
7135 -- Check for obsolescent restrictions in Ada 2005 mode
7138 and then Ada_Version >= Ada_2005
7139 and then (R_Id = No_Asynchronous_Control
7141 R_Id = No_Unchecked_Deallocation
7143 R_Id = No_Unchecked_Conversion)
7145 Check_Restriction (No_Obsolescent_Features, N);
7148 -- A very special case that must be processed here: pragma
7149 -- Restrictions (No_Exceptions) turns off all run-time
7150 -- checking. This is a bit dubious in terms of the formal
7151 -- language definition, but it is what is intended by RM
7152 -- H.4(12). Restriction_Warnings never affects generated code
7153 -- so this is done only in the real restriction case.
7155 -- Atomic_Synchronization is not a real check, so it is not
7156 -- affected by this processing).
7158 if R_Id = No_Exceptions and then not Warn then
7159 for J in Scope_Suppress.Suppress'Range loop
7160 if J /= Atomic_Synchronization then
7161 Scope_Suppress.Suppress (J) := True;
7166 -- Case of No_Dependence => unit-name. Note that the parser
7167 -- already made the necessary entry in the No_Dependence table.
7169 elsif Id = Name_No_Dependence then
7170 Check_Unit_Name (Expr);
7172 -- Case of No_Specification_Of_Aspect => Identifier.
7174 elsif Id = Name_No_Specification_Of_Aspect then
7179 if Nkind (Expr) /= N_Identifier then
7182 A_Id := Get_Aspect_Id (Chars (Expr));
7185 if A_Id = No_Aspect then
7186 Error_Pragma_Arg ("invalid restriction name", Arg);
7188 Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
7192 elsif Id = Name_No_Use_Of_Attribute then
7193 if Nkind (Expr) /= N_Identifier
7194 or else not Is_Attribute_Name (Chars (Expr))
7196 Error_Msg_N ("unknown attribute name?", Expr);
7199 Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
7202 elsif Id = Name_No_Use_Of_Pragma then
7203 if Nkind (Expr) /= N_Identifier
7204 or else not Is_Pragma_Name (Chars (Expr))
7206 Error_Msg_N ("unknown pragma name?", Expr);
7209 Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
7212 -- All other cases of restriction identifier present
7215 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
7216 Analyze_And_Resolve (Expr, Any_Integer);
7218 if R_Id not in All_Parameter_Restrictions then
7220 ("invalid restriction parameter identifier", Arg);
7222 elsif not Is_OK_Static_Expression (Expr) then
7223 Flag_Non_Static_Expr
7224 ("value must be static expression!", Expr);
7227 elsif not Is_Integer_Type (Etype (Expr))
7228 or else Expr_Value (Expr) < 0
7231 ("value must be non-negative integer", Arg);
7234 -- Restriction pragma is active
7236 Val := Expr_Value (Expr);
7238 if not UI_Is_In_Int_Range (Val) then
7240 ("pragma ignored, value too large??", Arg);
7243 -- Warning case. If the real restriction is active, then we
7244 -- ignore the request, since warning never overrides a real
7245 -- restriction. Otherwise we set the proper warning. Note that
7246 -- this circuit sets the warning again if it is already set,
7247 -- which is what we want, since the constant may have changed.
7250 if not Restriction_Active (R_Id) then
7252 (R_Id, N, Integer (UI_To_Int (Val)));
7253 Restriction_Warnings (R_Id) := True;
7256 -- Real restriction case, set restriction and make sure warning
7257 -- flag is off since real restriction always overrides warning.
7260 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
7261 Restriction_Warnings (R_Id) := False;
7267 end Process_Restrictions_Or_Restriction_Warnings;
7269 ---------------------------------
7270 -- Process_Suppress_Unsuppress --
7271 ---------------------------------
7273 -- Note: this procedure makes entries in the check suppress data
7274 -- structures managed by Sem. See spec of package Sem for full
7275 -- details on how we handle recording of check suppression.
7277 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
7282 In_Package_Spec : constant Boolean :=
7283 Is_Package_Or_Generic_Package (Current_Scope)
7284 and then not In_Package_Body (Current_Scope);
7286 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
7287 -- Used to suppress a single check on the given entity
7289 --------------------------------
7290 -- Suppress_Unsuppress_Echeck --
7291 --------------------------------
7293 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
7295 -- Check for error of trying to set atomic synchronization for
7296 -- a non-atomic variable.
7298 if C = Atomic_Synchronization
7299 and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
7302 ("pragma & requires atomic type or variable",
7303 Pragma_Identifier (Original_Node (N)));
7306 Set_Checks_May_Be_Suppressed (E);
7308 if In_Package_Spec then
7309 Push_Global_Suppress_Stack_Entry
7312 Suppress => Suppress_Case);
7314 Push_Local_Suppress_Stack_Entry
7317 Suppress => Suppress_Case);
7320 -- If this is a first subtype, and the base type is distinct,
7321 -- then also set the suppress flags on the base type.
7323 if Is_First_Subtype (E) and then Etype (E) /= E then
7324 Suppress_Unsuppress_Echeck (Etype (E), C);
7326 end Suppress_Unsuppress_Echeck;
7328 -- Start of processing for Process_Suppress_Unsuppress
7331 -- Ignore pragma Suppress/Unsuppress in CodePeer and SPARK modes on
7332 -- user code: we want to generate checks for analysis purposes, as
7333 -- set respectively by -gnatC and -gnatd.F
7335 if (CodePeer_Mode or SPARK_Mode) and then Comes_From_Source (N) then
7339 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
7340 -- declarative part or a package spec (RM 11.5(5)).
7342 if not Is_Configuration_Pragma then
7343 Check_Is_In_Decl_Part_Or_Package_Spec;
7346 Check_At_Least_N_Arguments (1);
7347 Check_At_Most_N_Arguments (2);
7348 Check_No_Identifier (Arg1);
7349 Check_Arg_Is_Identifier (Arg1);
7351 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
7353 if C = No_Check_Id then
7355 ("argument of pragma% is not valid check name", Arg1);
7358 if Arg_Count = 1 then
7360 -- Make an entry in the local scope suppress table. This is the
7361 -- table that directly shows the current value of the scope
7362 -- suppress check for any check id value.
7364 if C = All_Checks then
7366 -- For All_Checks, we set all specific predefined checks with
7367 -- the exception of Elaboration_Check, which is handled
7368 -- specially because of not wanting All_Checks to have the
7369 -- effect of deactivating static elaboration order processing.
7370 -- Atomic_Synchronization is also not affected, since this is
7371 -- not a real check.
7373 for J in Scope_Suppress.Suppress'Range loop
7374 if J /= Elaboration_Check
7376 J /= Atomic_Synchronization
7378 Scope_Suppress.Suppress (J) := Suppress_Case;
7382 -- If not All_Checks, and predefined check, then set appropriate
7383 -- scope entry. Note that we will set Elaboration_Check if this
7384 -- is explicitly specified. Atomic_Synchronization is allowed
7385 -- only if internally generated and entity is atomic.
7387 elsif C in Predefined_Check_Id
7388 and then (not Comes_From_Source (N)
7389 or else C /= Atomic_Synchronization)
7391 Scope_Suppress.Suppress (C) := Suppress_Case;
7394 -- Also make an entry in the Local_Entity_Suppress table
7396 Push_Local_Suppress_Stack_Entry
7399 Suppress => Suppress_Case);
7401 -- Case of two arguments present, where the check is suppressed for
7402 -- a specified entity (given as the second argument of the pragma)
7405 -- This is obsolescent in Ada 2005 mode
7407 if Ada_Version >= Ada_2005 then
7408 Check_Restriction (No_Obsolescent_Features, Arg2);
7411 Check_Optional_Identifier (Arg2, Name_On);
7412 E_Id := Get_Pragma_Arg (Arg2);
7415 if not Is_Entity_Name (E_Id) then
7417 ("second argument of pragma% must be entity name", Arg2);
7426 -- Enforce RM 11.5(7) which requires that for a pragma that
7427 -- appears within a package spec, the named entity must be
7428 -- within the package spec. We allow the package name itself
7429 -- to be mentioned since that makes sense, although it is not
7430 -- strictly allowed by 11.5(7).
7433 and then E /= Current_Scope
7434 and then Scope (E) /= Current_Scope
7437 ("entity in pragma% is not in package spec (RM 11.5(7))",
7441 -- Loop through homonyms. As noted below, in the case of a package
7442 -- spec, only homonyms within the package spec are considered.
7445 Suppress_Unsuppress_Echeck (E, C);
7447 if Is_Generic_Instance (E)
7448 and then Is_Subprogram (E)
7449 and then Present (Alias (E))
7451 Suppress_Unsuppress_Echeck (Alias (E), C);
7454 -- Move to next homonym if not aspect spec case
7456 exit when From_Aspect_Specification (N);
7460 -- If we are within a package specification, the pragma only
7461 -- applies to homonyms in the same scope.
7463 exit when In_Package_Spec
7464 and then Scope (E) /= Current_Scope;
7467 end Process_Suppress_Unsuppress;
7473 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
7475 if Is_Imported (E) then
7477 ("cannot export entity& that was previously imported", Arg);
7479 elsif Present (Address_Clause (E))
7480 and then not Relaxed_RM_Semantics
7483 ("cannot export entity& that has an address clause", Arg);
7486 Set_Is_Exported (E);
7488 -- Generate a reference for entity explicitly, because the
7489 -- identifier may be overloaded and name resolution will not
7492 Generate_Reference (E, Arg);
7494 -- Deal with exporting non-library level entity
7496 if not Is_Library_Level_Entity (E) then
7498 -- Not allowed at all for subprograms
7500 if Is_Subprogram (E) then
7501 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
7503 -- Otherwise set public and statically allocated
7507 Set_Is_Statically_Allocated (E);
7509 -- Warn if the corresponding W flag is set and the pragma comes
7510 -- from source. The latter may not be true e.g. on VMS where we
7511 -- expand export pragmas for exception codes associated with
7512 -- imported or exported exceptions. We do not want to generate
7513 -- a warning for something that the user did not write.
7515 if Warn_On_Export_Import
7516 and then Comes_From_Source (Arg)
7519 ("?x?& has been made static as a result of Export",
7522 ("\?x?this usage is non-standard and non-portable",
7528 if Warn_On_Export_Import and then Is_Type (E) then
7529 Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
7532 if Warn_On_Export_Import and Inside_A_Generic then
7534 ("all instances of& will have the same external name?x?",
7539 ----------------------------------------------
7540 -- Set_Extended_Import_Export_External_Name --
7541 ----------------------------------------------
7543 procedure Set_Extended_Import_Export_External_Name
7544 (Internal_Ent : Entity_Id;
7545 Arg_External : Node_Id)
7547 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
7551 if No (Arg_External) then
7555 Check_Arg_Is_External_Name (Arg_External);
7557 if Nkind (Arg_External) = N_String_Literal then
7558 if String_Length (Strval (Arg_External)) = 0 then
7561 New_Name := Adjust_External_Name_Case (Arg_External);
7564 elsif Nkind (Arg_External) = N_Identifier then
7565 New_Name := Get_Default_External_Name (Arg_External);
7567 -- Check_Arg_Is_External_Name should let through only identifiers and
7568 -- string literals or static string expressions (which are folded to
7569 -- string literals).
7572 raise Program_Error;
7575 -- If we already have an external name set (by a prior normal Import
7576 -- or Export pragma), then the external names must match
7578 if Present (Interface_Name (Internal_Ent)) then
7579 Check_Matching_Internal_Names : declare
7580 S1 : constant String_Id := Strval (Old_Name);
7581 S2 : constant String_Id := Strval (New_Name);
7584 pragma No_Return (Mismatch);
7585 -- Called if names do not match
7591 procedure Mismatch is
7593 Error_Msg_Sloc := Sloc (Old_Name);
7595 ("external name does not match that given #",
7599 -- Start of processing for Check_Matching_Internal_Names
7602 if String_Length (S1) /= String_Length (S2) then
7606 for J in 1 .. String_Length (S1) loop
7607 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
7612 end Check_Matching_Internal_Names;
7614 -- Otherwise set the given name
7617 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
7618 Check_Duplicated_Export_Name (New_Name);
7620 end Set_Extended_Import_Export_External_Name;
7626 procedure Set_Imported (E : Entity_Id) is
7628 -- Error message if already imported or exported
7630 if Is_Exported (E) or else Is_Imported (E) then
7632 -- Error if being set Exported twice
7634 if Is_Exported (E) then
7635 Error_Msg_NE ("entity& was previously exported", N, E);
7637 -- Ignore error in CodePeer mode where we treat all imported
7638 -- subprograms as unknown.
7640 elsif CodePeer_Mode then
7643 -- OK if Import/Interface case
7645 elsif Import_Interface_Present (N) then
7648 -- Error if being set Imported twice
7651 Error_Msg_NE ("entity& was previously imported", N, E);
7654 Error_Msg_Name_1 := Pname;
7656 ("\(pragma% applies to all previous entities)", N);
7658 Error_Msg_Sloc := Sloc (E);
7659 Error_Msg_NE ("\import not allowed for& declared#", N, E);
7661 -- Here if not previously imported or exported, OK to import
7664 Set_Is_Imported (E);
7666 -- If the entity is an object that is not at the library level,
7667 -- then it is statically allocated. We do not worry about objects
7668 -- with address clauses in this context since they are not really
7669 -- imported in the linker sense.
7672 and then not Is_Library_Level_Entity (E)
7673 and then No (Address_Clause (E))
7675 Set_Is_Statically_Allocated (E);
7682 -------------------------
7683 -- Set_Mechanism_Value --
7684 -------------------------
7686 -- Note: the mechanism name has not been analyzed (and cannot indeed be
7687 -- analyzed, since it is semantic nonsense), so we get it in the exact
7688 -- form created by the parser.
7690 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
7693 Mech_Name_Id : Name_Id;
7695 procedure Bad_Class;
7696 pragma No_Return (Bad_Class);
7697 -- Signal bad descriptor class name
7699 procedure Bad_Mechanism;
7700 pragma No_Return (Bad_Mechanism);
7701 -- Signal bad mechanism name
7707 procedure Bad_Class is
7709 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
7712 -------------------------
7713 -- Bad_Mechanism_Value --
7714 -------------------------
7716 procedure Bad_Mechanism is
7718 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
7721 -- Start of processing for Set_Mechanism_Value
7724 if Mechanism (Ent) /= Default_Mechanism then
7726 ("mechanism for & has already been set", Mech_Name, Ent);
7729 -- MECHANISM_NAME ::= value | reference | descriptor |
7732 if Nkind (Mech_Name) = N_Identifier then
7733 if Chars (Mech_Name) = Name_Value then
7734 Set_Mechanism (Ent, By_Copy);
7737 elsif Chars (Mech_Name) = Name_Reference then
7738 Set_Mechanism (Ent, By_Reference);
7741 elsif Chars (Mech_Name) = Name_Descriptor then
7742 Check_VMS (Mech_Name);
7744 -- Descriptor => Short_Descriptor if pragma was given
7746 if Short_Descriptors then
7747 Set_Mechanism (Ent, By_Short_Descriptor);
7749 Set_Mechanism (Ent, By_Descriptor);
7754 elsif Chars (Mech_Name) = Name_Short_Descriptor then
7755 Check_VMS (Mech_Name);
7756 Set_Mechanism (Ent, By_Short_Descriptor);
7759 elsif Chars (Mech_Name) = Name_Copy then
7761 ("bad mechanism name, Value assumed", Mech_Name);
7767 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
7768 -- short_descriptor (CLASS_NAME)
7769 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7771 -- Note: this form is parsed as an indexed component
7773 elsif Nkind (Mech_Name) = N_Indexed_Component then
7774 Class := First (Expressions (Mech_Name));
7776 if Nkind (Prefix (Mech_Name)) /= N_Identifier
7778 not Nam_In (Chars (Prefix (Mech_Name)), Name_Descriptor,
7779 Name_Short_Descriptor)
7780 or else Present (Next (Class))
7784 Mech_Name_Id := Chars (Prefix (Mech_Name));
7786 -- Change Descriptor => Short_Descriptor if pragma was given
7788 if Mech_Name_Id = Name_Descriptor
7789 and then Short_Descriptors
7791 Mech_Name_Id := Name_Short_Descriptor;
7795 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
7796 -- short_descriptor (Class => CLASS_NAME)
7797 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7799 -- Note: this form is parsed as a function call
7801 elsif Nkind (Mech_Name) = N_Function_Call then
7802 Param := First (Parameter_Associations (Mech_Name));
7804 if Nkind (Name (Mech_Name)) /= N_Identifier
7806 not Nam_In (Chars (Name (Mech_Name)), Name_Descriptor,
7807 Name_Short_Descriptor)
7808 or else Present (Next (Param))
7809 or else No (Selector_Name (Param))
7810 or else Chars (Selector_Name (Param)) /= Name_Class
7814 Class := Explicit_Actual_Parameter (Param);
7815 Mech_Name_Id := Chars (Name (Mech_Name));
7822 -- Fall through here with Class set to descriptor class name
7824 Check_VMS (Mech_Name);
7826 if Nkind (Class) /= N_Identifier then
7829 elsif Mech_Name_Id = Name_Descriptor
7830 and then Chars (Class) = Name_UBS
7832 Set_Mechanism (Ent, By_Descriptor_UBS);
7834 elsif Mech_Name_Id = Name_Descriptor
7835 and then Chars (Class) = Name_UBSB
7837 Set_Mechanism (Ent, By_Descriptor_UBSB);
7839 elsif Mech_Name_Id = Name_Descriptor
7840 and then Chars (Class) = Name_UBA
7842 Set_Mechanism (Ent, By_Descriptor_UBA);
7844 elsif Mech_Name_Id = Name_Descriptor
7845 and then Chars (Class) = Name_S
7847 Set_Mechanism (Ent, By_Descriptor_S);
7849 elsif Mech_Name_Id = Name_Descriptor
7850 and then Chars (Class) = Name_SB
7852 Set_Mechanism (Ent, By_Descriptor_SB);
7854 elsif Mech_Name_Id = Name_Descriptor
7855 and then Chars (Class) = Name_A
7857 Set_Mechanism (Ent, By_Descriptor_A);
7859 elsif Mech_Name_Id = Name_Descriptor
7860 and then Chars (Class) = Name_NCA
7862 Set_Mechanism (Ent, By_Descriptor_NCA);
7864 elsif Mech_Name_Id = Name_Short_Descriptor
7865 and then Chars (Class) = Name_UBS
7867 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
7869 elsif Mech_Name_Id = Name_Short_Descriptor
7870 and then Chars (Class) = Name_UBSB
7872 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
7874 elsif Mech_Name_Id = Name_Short_Descriptor
7875 and then Chars (Class) = Name_UBA
7877 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
7879 elsif Mech_Name_Id = Name_Short_Descriptor
7880 and then Chars (Class) = Name_S
7882 Set_Mechanism (Ent, By_Short_Descriptor_S);
7884 elsif Mech_Name_Id = Name_Short_Descriptor
7885 and then Chars (Class) = Name_SB
7887 Set_Mechanism (Ent, By_Short_Descriptor_SB);
7889 elsif Mech_Name_Id = Name_Short_Descriptor
7890 and then Chars (Class) = Name_A
7892 Set_Mechanism (Ent, By_Short_Descriptor_A);
7894 elsif Mech_Name_Id = Name_Short_Descriptor
7895 and then Chars (Class) = Name_NCA
7897 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
7902 end Set_Mechanism_Value;
7904 --------------------------
7905 -- Set_Rational_Profile --
7906 --------------------------
7908 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
7909 -- and extension to the semantics of renaming declarations.
7911 procedure Set_Rational_Profile is
7913 Implicit_Packing := True;
7914 Overriding_Renamings := True;
7915 Use_VADS_Size := True;
7916 end Set_Rational_Profile;
7918 ---------------------------
7919 -- Set_Ravenscar_Profile --
7920 ---------------------------
7922 -- The tasks to be done here are
7924 -- Set required policies
7926 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
7927 -- pragma Locking_Policy (Ceiling_Locking)
7929 -- Set Detect_Blocking mode
7931 -- Set required restrictions (see System.Rident for detailed list)
7933 -- Set the No_Dependence rules
7934 -- No_Dependence => Ada.Asynchronous_Task_Control
7935 -- No_Dependence => Ada.Calendar
7936 -- No_Dependence => Ada.Execution_Time.Group_Budget
7937 -- No_Dependence => Ada.Execution_Time.Timers
7938 -- No_Dependence => Ada.Task_Attributes
7939 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
7941 procedure Set_Ravenscar_Profile (N : Node_Id) is
7942 Prefix_Entity : Entity_Id;
7943 Selector_Entity : Entity_Id;
7944 Prefix_Node : Node_Id;
7948 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
7950 if Task_Dispatching_Policy /= ' '
7951 and then Task_Dispatching_Policy /= 'F'
7953 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
7954 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
7956 -- Set the FIFO_Within_Priorities policy, but always preserve
7957 -- System_Location since we like the error message with the run time
7961 Task_Dispatching_Policy := 'F';
7963 if Task_Dispatching_Policy_Sloc /= System_Location then
7964 Task_Dispatching_Policy_Sloc := Loc;
7968 -- pragma Locking_Policy (Ceiling_Locking)
7970 if Locking_Policy /= ' '
7971 and then Locking_Policy /= 'C'
7973 Error_Msg_Sloc := Locking_Policy_Sloc;
7974 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
7976 -- Set the Ceiling_Locking policy, but preserve System_Location since
7977 -- we like the error message with the run time name.
7980 Locking_Policy := 'C';
7982 if Locking_Policy_Sloc /= System_Location then
7983 Locking_Policy_Sloc := Loc;
7987 -- pragma Detect_Blocking
7989 Detect_Blocking := True;
7991 -- Set the corresponding restrictions
7993 Set_Profile_Restrictions
7994 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
7996 -- Set the No_Dependence restrictions
7998 -- The following No_Dependence restrictions:
7999 -- No_Dependence => Ada.Asynchronous_Task_Control
8000 -- No_Dependence => Ada.Calendar
8001 -- No_Dependence => Ada.Task_Attributes
8002 -- are already set by previous call to Set_Profile_Restrictions.
8004 -- Set the following restrictions which were added to Ada 2005:
8005 -- No_Dependence => Ada.Execution_Time.Group_Budget
8006 -- No_Dependence => Ada.Execution_Time.Timers
8008 if Ada_Version >= Ada_2005 then
8009 Name_Buffer (1 .. 3) := "ada";
8012 Prefix_Entity := Make_Identifier (Loc, Name_Find);
8014 Name_Buffer (1 .. 14) := "execution_time";
8017 Selector_Entity := Make_Identifier (Loc, Name_Find);
8020 Make_Selected_Component
8022 Prefix => Prefix_Entity,
8023 Selector_Name => Selector_Entity);
8025 Name_Buffer (1 .. 13) := "group_budgets";
8028 Selector_Entity := Make_Identifier (Loc, Name_Find);
8031 Make_Selected_Component
8033 Prefix => Prefix_Node,
8034 Selector_Name => Selector_Entity);
8036 Set_Restriction_No_Dependence
8038 Warn => Treat_Restrictions_As_Warnings,
8039 Profile => Ravenscar);
8041 Name_Buffer (1 .. 6) := "timers";
8044 Selector_Entity := Make_Identifier (Loc, Name_Find);
8047 Make_Selected_Component
8049 Prefix => Prefix_Node,
8050 Selector_Name => Selector_Entity);
8052 Set_Restriction_No_Dependence
8054 Warn => Treat_Restrictions_As_Warnings,
8055 Profile => Ravenscar);
8058 -- Set the following restrictions which was added to Ada 2012 (see
8060 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
8062 if Ada_Version >= Ada_2012 then
8063 Name_Buffer (1 .. 6) := "system";
8066 Prefix_Entity := Make_Identifier (Loc, Name_Find);
8068 Name_Buffer (1 .. 15) := "multiprocessors";
8071 Selector_Entity := Make_Identifier (Loc, Name_Find);
8074 Make_Selected_Component
8076 Prefix => Prefix_Entity,
8077 Selector_Name => Selector_Entity);
8079 Name_Buffer (1 .. 19) := "dispatching_domains";
8082 Selector_Entity := Make_Identifier (Loc, Name_Find);
8085 Make_Selected_Component
8087 Prefix => Prefix_Node,
8088 Selector_Name => Selector_Entity);
8090 Set_Restriction_No_Dependence
8092 Warn => Treat_Restrictions_As_Warnings,
8093 Profile => Ravenscar);
8095 end Set_Ravenscar_Profile;
8101 procedure S14_Pragma is
8103 if not Formal_Extensions then
8104 Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
8108 -- Start of processing for Analyze_Pragma
8111 -- The following code is a defense against recursion. Not clear that
8112 -- this can happen legitimately, but perhaps some error situations
8113 -- can cause it, and we did see this recursion during testing.
8115 if Analyzed (N) then
8118 Set_Analyzed (N, True);
8121 -- Deal with unrecognized pragma
8123 Pname := Pragma_Name (N);
8125 if not Is_Pragma_Name (Pname) then
8126 if Warn_On_Unrecognized_Pragma then
8127 Error_Msg_Name_1 := Pname;
8128 Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
8130 for PN in First_Pragma_Name .. Last_Pragma_Name loop
8131 if Is_Bad_Spelling_Of (Pname, PN) then
8132 Error_Msg_Name_1 := PN;
8133 Error_Msg_N -- CODEFIX
8134 ("\?g?possible misspelling of %!", Pragma_Identifier (N));
8143 -- Here to start processing for recognized pragma
8145 Prag_Id := Get_Pragma_Id (Pname);
8146 Pname := Original_Name (N);
8148 -- Check applicable policy. We skip this for a pragma that came from
8149 -- an aspect, since we already dealt with the Disable case, and we set
8150 -- the Is_Ignored flag at the time the aspect was analyzed.
8152 if not From_Aspect_Specification (N) then
8153 Check_Applicable_Policy (N);
8155 -- If pragma is disabled, rewrite as NULL and skip analysis
8157 if Is_Disabled (N) then
8158 Rewrite (N, Make_Null_Statement (Loc));
8172 if Present (Pragma_Argument_Associations (N)) then
8173 Arg_Count := List_Length (Pragma_Argument_Associations (N));
8174 Arg1 := First (Pragma_Argument_Associations (N));
8176 if Present (Arg1) then
8177 Arg2 := Next (Arg1);
8179 if Present (Arg2) then
8180 Arg3 := Next (Arg2);
8182 if Present (Arg3) then
8183 Arg4 := Next (Arg3);
8189 Check_Restriction_No_Use_Of_Pragma (N);
8191 -- An enumeration type defines the pragmas that are supported by the
8192 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
8193 -- into the corresponding enumeration value for the following case.
8201 -- pragma Abort_Defer;
8203 when Pragma_Abort_Defer =>
8205 Check_Arg_Count (0);
8207 -- The only required semantic processing is to check the
8208 -- placement. This pragma must appear at the start of the
8209 -- statement sequence of a handled sequence of statements.
8211 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
8212 or else N /= First (Statements (Parent (N)))
8217 --------------------
8218 -- Abstract_State --
8219 --------------------
8221 -- pragma Abstract_State (ABSTRACT_STATE_LIST)
8223 -- ABSTRACT_STATE_LIST ::=
8225 -- | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
8227 -- STATE_NAME_WITH_PROPERTIES ::=
8229 -- | (STATE_NAME with PROPERTY_LIST)
8231 -- PROPERTY_LIST ::= PROPERTY {, PROPERTY}
8232 -- PROPERTY ::= SIMPLE_PROPERTY | NAME_VALUE_PROPERTY
8234 -- SIMPLE_PROPERTY ::= IDENTIFIER
8235 -- NAME_VALUE_PROPERTY ::= IDENTIFIER => EXPRESSION
8237 -- STATE_NAME ::= DEFINING_IDENTIFIER
8239 when Pragma_Abstract_State => Abstract_State : declare
8240 Pack_Id : Entity_Id;
8242 -- Flags used to verify the consistency of states
8244 Non_Null_Seen : Boolean := False;
8245 Null_Seen : Boolean := False;
8247 procedure Analyze_Abstract_State (State : Node_Id);
8248 -- Verify the legality of a single state declaration. Create and
8249 -- decorate a state abstraction entity and introduce it into the
8250 -- visibility chain.
8252 ----------------------------
8253 -- Analyze_Abstract_State --
8254 ----------------------------
8256 procedure Analyze_Abstract_State (State : Node_Id) is
8257 procedure Check_Duplicate_Property
8259 Status : in out Boolean);
8260 -- Flag Status denotes whether a particular property has been
8261 -- seen while processing a state. This routine verifies that
8262 -- Prop is not a duplicate property and sets the flag Status.
8264 ------------------------------
8265 -- Check_Duplicate_Property --
8266 ------------------------------
8268 procedure Check_Duplicate_Property
8270 Status : in out Boolean)
8274 Error_Msg_N ("duplicate state property", Prop);
8278 end Check_Duplicate_Property;
8282 Errors : constant Nat := Serious_Errors_Detected;
8283 Loc : constant Source_Ptr := Sloc (State);
8286 Is_Null : Boolean := False;
8287 Level : Uint := Uint_0;
8291 -- Flags used to verify the consistency of properties
8293 Input_Seen : Boolean := False;
8294 Integrity_Seen : Boolean := False;
8295 Output_Seen : Boolean := False;
8296 Volatile_Seen : Boolean := False;
8298 -- Start of processing for Analyze_Abstract_State
8301 -- A package with a null abstract state is not allowed to
8302 -- declare additional states.
8306 ("package & has null abstract state", State, Pack_Id);
8308 -- Null states appear as internally generated entities
8310 elsif Nkind (State) = N_Null then
8311 Name := New_Internal_Name ('S');
8315 -- Catch a case where a null state appears in a list of
8318 if Non_Null_Seen then
8320 ("package & has non-null abstract state",
8324 -- Simple state declaration
8326 elsif Nkind (State) = N_Identifier then
8327 Name := Chars (State);
8328 Non_Null_Seen := True;
8330 -- State declaration with various properties. This construct
8331 -- appears as an extension aggregate in the tree.
8333 elsif Nkind (State) = N_Extension_Aggregate then
8334 if Nkind (Ancestor_Part (State)) = N_Identifier then
8335 Name := Chars (Ancestor_Part (State));
8336 Non_Null_Seen := True;
8339 ("state name must be an identifier",
8340 Ancestor_Part (State));
8343 -- Process properties Input, Output and Volatile. Ensure
8344 -- that none of them appear more than once.
8346 Prop := First (Expressions (State));
8347 while Present (Prop) loop
8348 if Nkind (Prop) = N_Identifier then
8349 if Chars (Prop) = Name_Input then
8350 Check_Duplicate_Property (Prop, Input_Seen);
8351 elsif Chars (Prop) = Name_Output then
8352 Check_Duplicate_Property (Prop, Output_Seen);
8353 elsif Chars (Prop) = Name_Volatile then
8354 Check_Duplicate_Property (Prop, Volatile_Seen);
8356 Error_Msg_N ("invalid state property", Prop);
8359 Error_Msg_N ("invalid state property", Prop);
8365 -- Volatile requires exactly one Input or Output
8367 if Volatile_Seen and then Input_Seen = Output_Seen then
8369 ("property Volatile requires exactly one Input or "
8373 -- Either Input or Output require Volatile
8375 if (Input_Seen or Output_Seen)
8376 and then not Volatile_Seen
8379 ("properties Input and Output require Volatile", State);
8382 -- State property Integrity appears as a component
8385 Assoc := First (Component_Associations (State));
8386 while Present (Assoc) loop
8387 Prop := First (Choices (Assoc));
8388 while Present (Prop) loop
8389 if Nkind (Prop) = N_Identifier
8390 and then Chars (Prop) = Name_Integrity
8392 Check_Duplicate_Property (Prop, Integrity_Seen);
8394 Error_Msg_N ("invalid state property", Prop);
8400 if Nkind (Expression (Assoc)) = N_Integer_Literal then
8401 Level := Intval (Expression (Assoc));
8404 ("integrity level must be an integer literal",
8405 Expression (Assoc));
8411 -- Any other attempt to declare a state is erroneous
8414 Error_Msg_N ("malformed abstract state declaration", State);
8417 -- Do not generate a state abstraction entity if it was not
8418 -- properly declared.
8420 if Serious_Errors_Detected > Errors then
8424 -- The generated state abstraction reuses the same characters
8425 -- from the original state declaration. Decorate the entity.
8427 Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
8428 Set_Comes_From_Source (Id, not Is_Null);
8429 Set_Parent (Id, State);
8430 Set_Ekind (Id, E_Abstract_State);
8431 Set_Etype (Id, Standard_Void_Type);
8432 Set_Integrity_Level (Id, Level);
8433 Set_Refined_State (Id, Empty);
8435 -- Every non-null state must be nameable and resolvable the
8436 -- same way a constant is.
8439 Push_Scope (Pack_Id);
8444 -- Verify whether the state introduces an illegal hidden state
8445 -- within a package subject to a null abstract state.
8447 if Formal_Extensions then
8448 Check_No_Hidden_State (Id);
8451 -- Associate the state with its related package
8453 if No (Abstract_States (Pack_Id)) then
8454 Set_Abstract_States (Pack_Id, New_Elmt_List);
8457 Append_Elmt (Id, Abstract_States (Pack_Id));
8458 end Analyze_Abstract_State;
8465 -- Start of processing for Abstract_State
8470 Check_Arg_Count (1);
8472 -- Ensure the proper placement of the pragma. Abstract states must
8473 -- be associated with a package declaration.
8475 if From_Aspect_Specification (N) then
8476 Par := Parent (Corresponding_Aspect (N));
8478 Par := Parent (Parent (N));
8481 if Nkind (Par) = N_Compilation_Unit then
8485 if not Nkind_In (Par, N_Generic_Package_Declaration,
8486 N_Package_Declaration)
8492 Pack_Id := Defining_Entity (Par);
8493 State := Expression (Arg1);
8495 -- Multiple abstract states appear as an aggregate
8497 if Nkind (State) = N_Aggregate then
8498 State := First (Expressions (State));
8499 while Present (State) loop
8500 Analyze_Abstract_State (State);
8505 -- Various forms of a single abstract state. Note that these may
8506 -- include malformed state declarations.
8509 Analyze_Abstract_State (State);
8519 -- Note: this pragma also has some specific processing in Par.Prag
8520 -- because we want to set the Ada version mode during parsing.
8522 when Pragma_Ada_83 =>
8524 Check_Arg_Count (0);
8526 -- We really should check unconditionally for proper configuration
8527 -- pragma placement, since we really don't want mixed Ada modes
8528 -- within a single unit, and the GNAT reference manual has always
8529 -- said this was a configuration pragma, but we did not check and
8530 -- are hesitant to add the check now.
8532 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
8533 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
8534 -- or Ada 2012 mode.
8536 if Ada_Version >= Ada_2005 then
8537 Check_Valid_Configuration_Pragma;
8540 -- Now set Ada 83 mode
8542 Ada_Version := Ada_83;
8543 Ada_Version_Explicit := Ada_Version;
8551 -- Note: this pragma also has some specific processing in Par.Prag
8552 -- because we want to set the Ada 83 version mode during parsing.
8554 when Pragma_Ada_95 =>
8556 Check_Arg_Count (0);
8558 -- We really should check unconditionally for proper configuration
8559 -- pragma placement, since we really don't want mixed Ada modes
8560 -- within a single unit, and the GNAT reference manual has always
8561 -- said this was a configuration pragma, but we did not check and
8562 -- are hesitant to add the check now.
8564 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
8565 -- or Ada 95, so we must check if we are in Ada 2005 mode.
8567 if Ada_Version >= Ada_2005 then
8568 Check_Valid_Configuration_Pragma;
8571 -- Now set Ada 95 mode
8573 Ada_Version := Ada_95;
8574 Ada_Version_Explicit := Ada_Version;
8576 ---------------------
8577 -- Ada_05/Ada_2005 --
8578 ---------------------
8581 -- pragma Ada_05 (LOCAL_NAME);
8584 -- pragma Ada_2005 (LOCAL_NAME):
8586 -- Note: these pragmas also have some specific processing in Par.Prag
8587 -- because we want to set the Ada 2005 version mode during parsing.
8589 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
8595 if Arg_Count = 1 then
8596 Check_Arg_Is_Local_Name (Arg1);
8597 E_Id := Get_Pragma_Arg (Arg1);
8599 if Etype (E_Id) = Any_Type then
8603 Set_Is_Ada_2005_Only (Entity (E_Id));
8604 Record_Rep_Item (Entity (E_Id), N);
8607 Check_Arg_Count (0);
8609 -- For Ada_2005 we unconditionally enforce the documented
8610 -- configuration pragma placement, since we do not want to
8611 -- tolerate mixed modes in a unit involving Ada 2005. That
8612 -- would cause real difficulties for those cases where there
8613 -- are incompatibilities between Ada 95 and Ada 2005.
8615 Check_Valid_Configuration_Pragma;
8617 -- Now set appropriate Ada mode
8619 Ada_Version := Ada_2005;
8620 Ada_Version_Explicit := Ada_2005;
8624 ---------------------
8625 -- Ada_12/Ada_2012 --
8626 ---------------------
8629 -- pragma Ada_12 (LOCAL_NAME);
8632 -- pragma Ada_2012 (LOCAL_NAME):
8634 -- Note: these pragmas also have some specific processing in Par.Prag
8635 -- because we want to set the Ada 2012 version mode during parsing.
8637 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
8643 if Arg_Count = 1 then
8644 Check_Arg_Is_Local_Name (Arg1);
8645 E_Id := Get_Pragma_Arg (Arg1);
8647 if Etype (E_Id) = Any_Type then
8651 Set_Is_Ada_2012_Only (Entity (E_Id));
8652 Record_Rep_Item (Entity (E_Id), N);
8655 Check_Arg_Count (0);
8657 -- For Ada_2012 we unconditionally enforce the documented
8658 -- configuration pragma placement, since we do not want to
8659 -- tolerate mixed modes in a unit involving Ada 2012. That
8660 -- would cause real difficulties for those cases where there
8661 -- are incompatibilities between Ada 95 and Ada 2012. We could
8662 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
8664 Check_Valid_Configuration_Pragma;
8666 -- Now set appropriate Ada mode
8668 Ada_Version := Ada_2012;
8669 Ada_Version_Explicit := Ada_2012;
8673 ----------------------
8674 -- All_Calls_Remote --
8675 ----------------------
8677 -- pragma All_Calls_Remote [(library_package_NAME)];
8679 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
8680 Lib_Entity : Entity_Id;
8683 Check_Ada_83_Warning;
8684 Check_Valid_Library_Unit_Pragma;
8686 if Nkind (N) = N_Null_Statement then
8690 Lib_Entity := Find_Lib_Unit_Name;
8692 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
8694 if Present (Lib_Entity)
8695 and then not Debug_Flag_U
8697 if not Is_Remote_Call_Interface (Lib_Entity) then
8698 Error_Pragma ("pragma% only apply to rci unit");
8700 -- Set flag for entity of the library unit
8703 Set_Has_All_Calls_Remote (Lib_Entity);
8707 end All_Calls_Remote;
8713 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
8714 -- ARG ::= NAME | EXPRESSION
8716 -- The first two arguments are by convention intended to refer to an
8717 -- external tool and a tool-specific function. These arguments are
8720 when Pragma_Annotate => Annotate : declare
8726 Check_At_Least_N_Arguments (1);
8727 Check_Arg_Is_Identifier (Arg1);
8728 Check_No_Identifiers;
8731 -- Second parameter is optional, it is never analyzed
8736 -- Here if we have a second parameter
8739 -- Second parameter must be identifier
8741 Check_Arg_Is_Identifier (Arg2);
8743 -- Process remaining parameters if any
8746 while Present (Arg) loop
8747 Exp := Get_Pragma_Arg (Arg);
8750 if Is_Entity_Name (Exp) then
8753 -- For string literals, we assume Standard_String as the
8754 -- type, unless the string contains wide or wide_wide
8757 elsif Nkind (Exp) = N_String_Literal then
8758 if Has_Wide_Wide_Character (Exp) then
8759 Resolve (Exp, Standard_Wide_Wide_String);
8760 elsif Has_Wide_Character (Exp) then
8761 Resolve (Exp, Standard_Wide_String);
8763 Resolve (Exp, Standard_String);
8766 elsif Is_Overloaded (Exp) then
8768 ("ambiguous argument for pragma%", Exp);
8779 -------------------------------------------------
8780 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
8781 -------------------------------------------------
8784 -- ( [Check => ] Boolean_EXPRESSION
8785 -- [, [Message =>] Static_String_EXPRESSION]);
8787 -- pragma Assert_And_Cut
8788 -- ( [Check => ] Boolean_EXPRESSION
8789 -- [, [Message =>] Static_String_EXPRESSION]);
8792 -- ( [Check => ] Boolean_EXPRESSION
8793 -- [, [Message =>] Static_String_EXPRESSION]);
8795 -- pragma Loop_Invariant
8796 -- ( [Check => ] Boolean_EXPRESSION
8797 -- [, [Message =>] Static_String_EXPRESSION]);
8799 when Pragma_Assert |
8800 Pragma_Assert_And_Cut |
8802 Pragma_Loop_Invariant =>
8808 -- Assert is an Ada 2005 RM-defined pragma
8810 if Prag_Id = Pragma_Assert then
8813 -- The remaining ones are GNAT pragmas
8819 Check_At_Least_N_Arguments (1);
8820 Check_At_Most_N_Arguments (2);
8821 Check_Arg_Order ((Name_Check, Name_Message));
8822 Check_Optional_Identifier (Arg1, Name_Check);
8824 -- Special processing for Loop_Invariant
8826 if Prag_Id = Pragma_Loop_Invariant then
8828 -- Check restricted placement, must be within a loop
8830 Check_Loop_Pragma_Placement;
8832 -- Do preanalyze to deal with embedded Loop_Entry attribute
8834 Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
8837 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
8838 -- a corresponding Check pragma:
8840 -- pragma Check (name, condition [, msg]);
8842 -- Where name is the identifier matching the pragma name. So
8843 -- rewrite pragma in this manner, transfer the message argument
8844 -- if present, and analyze the result
8846 -- Note: When dealing with a semantically analyzed tree, the
8847 -- information that a Check node N corresponds to a source Assert,
8848 -- Assume, or Assert_And_Cut pragma can be retrieved from the
8849 -- pragma kind of Original_Node(N).
8851 Expr := Get_Pragma_Arg (Arg1);
8853 Make_Pragma_Argument_Association (Loc,
8854 Expression => Make_Identifier (Loc, Pname)),
8855 Make_Pragma_Argument_Association (Sloc (Expr),
8856 Expression => Expr));
8858 if Arg_Count > 1 then
8859 Check_Optional_Identifier (Arg2, Name_Message);
8860 Append_To (Newa, New_Copy_Tree (Arg2));
8865 Chars => Name_Check,
8866 Pragma_Argument_Associations => Newa));
8870 ----------------------
8871 -- Assertion_Policy --
8872 ----------------------
8874 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
8876 -- The following form is Ada 2012 only, but we allow it in all modes
8878 -- Pragma Assertion_Policy (
8879 -- ASSERTION_KIND => POLICY_IDENTIFIER
8880 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
8882 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
8884 -- RM_ASSERTION_KIND ::= Assert |
8885 -- Static_Predicate |
8886 -- Dynamic_Predicate |
8892 -- Type_Invariant'Class
8894 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
8903 -- Statement_Assertions
8905 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
8906 -- ID_ASSERTION_KIND list contains implementation-defined additions
8907 -- recognized by GNAT. The effect is to control the behavior of
8908 -- identically named aspects and pragmas, depending on the specified
8909 -- policy identifier:
8911 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
8913 -- Note: Check and Ignore are language-defined. Disable is a GNAT
8914 -- implementation defined addition that results in totally ignoring
8915 -- the corresponding assertion. If Disable is specified, then the
8916 -- argument of the assertion is not even analyzed. This is useful
8917 -- when the aspect/pragma argument references entities in a with'ed
8918 -- package that is replaced by a dummy package in the final build.
8920 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
8921 -- and Type_Invariant'Class were recognized by the parser and
8922 -- transformed into references to the special internal identifiers
8923 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
8924 -- processing is required here.
8926 when Pragma_Assertion_Policy => Assertion_Policy : declare
8935 -- This can always appear as a configuration pragma
8937 if Is_Configuration_Pragma then
8940 -- It can also appear in a declarative part or package spec in Ada
8941 -- 2012 mode. We allow this in other modes, but in that case we
8942 -- consider that we have an Ada 2012 pragma on our hands.
8945 Check_Is_In_Decl_Part_Or_Package_Spec;
8949 -- One argument case with no identifier (first form above)
8952 and then (Nkind (Arg1) /= N_Pragma_Argument_Association
8953 or else Chars (Arg1) = No_Name)
8956 (Arg1, Name_Check, Name_Disable, Name_Ignore);
8958 -- Treat one argument Assertion_Policy as equivalent to:
8960 -- pragma Check_Policy (Assertion, policy)
8962 -- So rewrite pragma in that manner and link on to the chain
8963 -- of Check_Policy pragmas, marking the pragma as analyzed.
8965 Policy := Get_Pragma_Arg (Arg1);
8969 Chars => Name_Check_Policy,
8970 Pragma_Argument_Associations => New_List (
8971 Make_Pragma_Argument_Association (Loc,
8972 Expression => Make_Identifier (Loc, Name_Assertion)),
8974 Make_Pragma_Argument_Association (Loc,
8976 Make_Identifier (Sloc (Policy), Chars (Policy))))));
8979 -- Here if we have two or more arguments
8982 Check_At_Least_N_Arguments (1);
8985 -- Loop through arguments
8988 while Present (Arg) loop
8991 -- Kind must be specified
8993 if Nkind (Arg) /= N_Pragma_Argument_Association
8994 or else Chars (Arg) = No_Name
8997 ("missing assertion kind for pragma%", Arg);
9000 -- Check Kind and Policy have allowed forms
9002 Kind := Chars (Arg);
9004 if not Is_Valid_Assertion_Kind (Kind) then
9006 ("invalid assertion kind for pragma%", Arg);
9010 (Arg, Name_Check, Name_Disable, Name_Ignore);
9012 -- We rewrite the Assertion_Policy pragma as a series of
9013 -- Check_Policy pragmas:
9015 -- Check_Policy (Kind, Policy);
9019 Chars => Name_Check_Policy,
9020 Pragma_Argument_Associations => New_List (
9021 Make_Pragma_Argument_Association (LocP,
9022 Expression => Make_Identifier (LocP, Kind)),
9023 Make_Pragma_Argument_Association (LocP,
9024 Expression => Get_Pragma_Arg (Arg)))));
9029 -- Rewrite the Assertion_Policy pragma as null since we have
9030 -- now inserted all the equivalent Check pragmas.
9032 Rewrite (N, Make_Null_Statement (Loc));
9035 end Assertion_Policy;
9037 ------------------------------
9038 -- Assume_No_Invalid_Values --
9039 ------------------------------
9041 -- pragma Assume_No_Invalid_Values (On | Off);
9043 when Pragma_Assume_No_Invalid_Values =>
9045 Check_Valid_Configuration_Pragma;
9046 Check_Arg_Count (1);
9047 Check_No_Identifiers;
9048 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9050 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9051 Assume_No_Invalid_Values := True;
9053 Assume_No_Invalid_Values := False;
9056 --------------------------
9057 -- Attribute_Definition --
9058 --------------------------
9060 -- pragma Attribute_Definition
9061 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
9062 -- [Entity =>] LOCAL_NAME,
9063 -- [Expression =>] EXPRESSION | NAME);
9065 when Pragma_Attribute_Definition => Attribute_Definition : declare
9066 Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
9071 Check_Arg_Count (3);
9072 Check_Optional_Identifier (Arg1, "attribute");
9073 Check_Optional_Identifier (Arg2, "entity");
9074 Check_Optional_Identifier (Arg3, "expression");
9076 if Nkind (Attribute_Designator) /= N_Identifier then
9077 Error_Msg_N ("attribute name expected", Attribute_Designator);
9081 Check_Arg_Is_Local_Name (Arg2);
9083 -- If the attribute is not recognized, then issue a warning (not
9084 -- an error), and ignore the pragma.
9086 Aname := Chars (Attribute_Designator);
9088 if not Is_Attribute_Name (Aname) then
9089 Bad_Attribute (Attribute_Designator, Aname, Warn => True);
9093 -- Otherwise, rewrite the pragma as an attribute definition clause
9096 Make_Attribute_Definition_Clause (Loc,
9097 Name => Get_Pragma_Arg (Arg2),
9099 Expression => Get_Pragma_Arg (Arg3)));
9101 end Attribute_Definition;
9107 -- pragma AST_Entry (entry_IDENTIFIER);
9109 when Pragma_AST_Entry => AST_Entry : declare
9115 Check_Arg_Count (1);
9116 Check_No_Identifiers;
9117 Check_Arg_Is_Local_Name (Arg1);
9118 Ent := Entity (Get_Pragma_Arg (Arg1));
9120 -- Note: the implementation of the AST_Entry pragma could handle
9121 -- the entry family case fine, but for now we are consistent with
9122 -- the DEC rules, and do not allow the pragma, which of course
9123 -- has the effect of also forbidding the attribute.
9125 if Ekind (Ent) /= E_Entry then
9127 ("pragma% argument must be simple entry name", Arg1);
9129 elsif Is_AST_Entry (Ent) then
9131 ("duplicate % pragma for entry", Arg1);
9133 elsif Has_Homonym (Ent) then
9135 ("pragma% argument cannot specify overloaded entry", Arg1);
9139 FF : constant Entity_Id := First_Formal (Ent);
9142 if Present (FF) then
9143 if Present (Next_Formal (FF)) then
9145 ("entry for pragma% can have only one argument",
9148 elsif Parameter_Mode (FF) /= E_In_Parameter then
9150 ("entry parameter for pragma% must have mode IN",
9156 Set_Is_AST_Entry (Ent);
9164 -- pragma Asynchronous (LOCAL_NAME);
9166 when Pragma_Asynchronous => Asynchronous : declare
9174 procedure Process_Async_Pragma;
9175 -- Common processing for procedure and access-to-procedure case
9177 --------------------------
9178 -- Process_Async_Pragma --
9179 --------------------------
9181 procedure Process_Async_Pragma is
9184 Set_Is_Asynchronous (Nm);
9188 -- The formals should be of mode IN (RM E.4.1(6))
9191 while Present (S) loop
9192 Formal := Defining_Identifier (S);
9194 if Nkind (Formal) = N_Defining_Identifier
9195 and then Ekind (Formal) /= E_In_Parameter
9198 ("pragma% procedure can only have IN parameter",
9205 Set_Is_Asynchronous (Nm);
9206 end Process_Async_Pragma;
9208 -- Start of processing for pragma Asynchronous
9211 Check_Ada_83_Warning;
9212 Check_No_Identifiers;
9213 Check_Arg_Count (1);
9214 Check_Arg_Is_Local_Name (Arg1);
9216 if Debug_Flag_U then
9220 C_Ent := Cunit_Entity (Current_Sem_Unit);
9221 Analyze (Get_Pragma_Arg (Arg1));
9222 Nm := Entity (Get_Pragma_Arg (Arg1));
9224 if not Is_Remote_Call_Interface (C_Ent)
9225 and then not Is_Remote_Types (C_Ent)
9227 -- This pragma should only appear in an RCI or Remote Types
9228 -- unit (RM E.4.1(4)).
9231 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
9234 if Ekind (Nm) = E_Procedure
9235 and then Nkind (Parent (Nm)) = N_Procedure_Specification
9237 if not Is_Remote_Call_Interface (Nm) then
9239 ("pragma% cannot be applied on non-remote procedure",
9243 L := Parameter_Specifications (Parent (Nm));
9244 Process_Async_Pragma;
9247 elsif Ekind (Nm) = E_Function then
9249 ("pragma% cannot be applied to function", Arg1);
9251 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
9252 if Is_Record_Type (Nm) then
9254 -- A record type that is the Equivalent_Type for a remote
9255 -- access-to-subprogram type.
9257 N := Declaration_Node (Corresponding_Remote_Type (Nm));
9260 -- A non-expanded RAS type (distribution is not enabled)
9262 N := Declaration_Node (Nm);
9265 if Nkind (N) = N_Full_Type_Declaration
9266 and then Nkind (Type_Definition (N)) =
9267 N_Access_Procedure_Definition
9269 L := Parameter_Specifications (Type_Definition (N));
9270 Process_Async_Pragma;
9272 if Is_Asynchronous (Nm)
9273 and then Expander_Active
9274 and then Get_PCS_Name /= Name_No_DSA
9276 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
9281 ("pragma% cannot reference access-to-function type",
9285 -- Only other possibility is Access-to-class-wide type
9287 elsif Is_Access_Type (Nm)
9288 and then Is_Class_Wide_Type (Designated_Type (Nm))
9290 Check_First_Subtype (Arg1);
9291 Set_Is_Asynchronous (Nm);
9292 if Expander_Active then
9293 RACW_Type_Is_Asynchronous (Nm);
9297 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
9305 -- pragma Atomic (LOCAL_NAME);
9307 when Pragma_Atomic =>
9308 Process_Atomic_Shared_Volatile;
9310 -----------------------
9311 -- Atomic_Components --
9312 -----------------------
9314 -- pragma Atomic_Components (array_LOCAL_NAME);
9316 -- This processing is shared by Volatile_Components
9318 when Pragma_Atomic_Components |
9319 Pragma_Volatile_Components =>
9321 Atomic_Components : declare
9328 Check_Ada_83_Warning;
9329 Check_No_Identifiers;
9330 Check_Arg_Count (1);
9331 Check_Arg_Is_Local_Name (Arg1);
9332 E_Id := Get_Pragma_Arg (Arg1);
9334 if Etype (E_Id) = Any_Type then
9340 Check_Duplicate_Pragma (E);
9342 if Rep_Item_Too_Early (E, N)
9344 Rep_Item_Too_Late (E, N)
9349 D := Declaration_Node (E);
9352 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
9354 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9355 and then Nkind (D) = N_Object_Declaration
9356 and then Nkind (Object_Definition (D)) =
9357 N_Constrained_Array_Definition)
9359 -- The flag is set on the object, or on the base type
9361 if Nkind (D) /= N_Object_Declaration then
9365 Set_Has_Volatile_Components (E);
9367 if Prag_Id = Pragma_Atomic_Components then
9368 Set_Has_Atomic_Components (E);
9372 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9374 end Atomic_Components;
9376 --------------------
9377 -- Attach_Handler --
9378 --------------------
9380 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
9382 when Pragma_Attach_Handler =>
9383 Check_Ada_83_Warning;
9384 Check_No_Identifiers;
9385 Check_Arg_Count (2);
9387 if No_Run_Time_Mode then
9388 Error_Msg_CRT ("Attach_Handler pragma", N);
9390 Check_Interrupt_Or_Attach_Handler;
9392 -- The expression that designates the attribute may depend on a
9393 -- discriminant, and is therefore a per-object expression, to
9394 -- be expanded in the init proc. If expansion is enabled, then
9395 -- perform semantic checks on a copy only.
9397 if Expander_Active then
9399 Temp : constant Node_Id :=
9400 New_Copy_Tree (Get_Pragma_Arg (Arg2));
9402 Set_Parent (Temp, N);
9403 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
9407 Analyze (Get_Pragma_Arg (Arg2));
9408 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
9411 Process_Interrupt_Or_Attach_Handler;
9414 --------------------
9415 -- C_Pass_By_Copy --
9416 --------------------
9418 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
9420 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
9426 Check_Valid_Configuration_Pragma;
9427 Check_Arg_Count (1);
9428 Check_Optional_Identifier (Arg1, "max_size");
9430 Arg := Get_Pragma_Arg (Arg1);
9431 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
9433 Val := Expr_Value (Arg);
9437 ("maximum size for pragma% must be positive", Arg1);
9439 elsif UI_Is_In_Int_Range (Val) then
9440 Default_C_Record_Mechanism := UI_To_Int (Val);
9442 -- If a giant value is given, Int'Last will do well enough.
9443 -- If sometime someone complains that a record larger than
9444 -- two gigabytes is not copied, we will worry about it then!
9447 Default_C_Record_Mechanism := Mechanism_Type'Last;
9455 -- pragma Check ([Name =>] CHECK_KIND,
9456 -- [Check =>] Boolean_EXPRESSION
9457 -- [,[Message =>] String_EXPRESSION]);
9459 -- CHECK_KIND ::= IDENTIFIER |
9462 -- Invariant'Class |
9463 -- Type_Invariant'Class
9465 -- The identifiers Assertions and Statement_Assertions are not
9466 -- allowed, since they have special meaning for Check_Policy.
9468 when Pragma_Check => Check : declare
9475 -- Set True if category of assertions referenced by Name enabled
9479 Check_At_Least_N_Arguments (2);
9480 Check_At_Most_N_Arguments (3);
9481 Check_Optional_Identifier (Arg1, Name_Name);
9482 Check_Optional_Identifier (Arg2, Name_Check);
9484 if Arg_Count = 3 then
9485 Check_Optional_Identifier (Arg3, Name_Message);
9486 Str := Get_Pragma_Arg (Arg3);
9489 Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
9490 Check_Arg_Is_Identifier (Arg1);
9491 Cname := Chars (Get_Pragma_Arg (Arg1));
9493 -- Check forbidden name Assertions or Statement_Assertions
9496 when Name_Assertions =>
9498 ("""Assertions"" is not allowed as a check kind "
9499 & "for pragma%", Arg1);
9501 when Name_Statement_Assertions =>
9503 ("""Statement_Assertions"" is not allowed as a check kind "
9504 & "for pragma%", Arg1);
9510 -- Set Check_On to indicate check status
9512 -- If this comes from an aspect, we have already taken care of
9513 -- the policy active when the aspect was analyzed, and Is_Ignored
9514 -- is set appropriately already.
9516 if From_Aspect_Specification (N) then
9517 Check_On := not Is_Ignored (N);
9519 -- Otherwise check the status right now
9522 case Check_Kind (Cname) is
9529 -- For disable, rewrite pragma as null statement and skip
9530 -- rest of the analysis of the pragma.
9532 when Name_Disable =>
9533 Rewrite (N, Make_Null_Statement (Loc));
9537 -- No other possibilities
9540 raise Program_Error;
9544 -- If check kind was not Disable, then continue pragma analysis
9546 Expr := Get_Pragma_Arg (Arg2);
9548 -- Deal with SCO generation
9551 when Name_Predicate |
9554 -- Nothing to do: since checks occur in client units,
9555 -- the SCO for the aspect in the declaration unit is
9556 -- conservatively always enabled.
9562 if Check_On and then not Split_PPC (N) then
9564 -- Mark pragma/aspect SCO as enabled
9566 Set_SCO_Pragma_Enabled (Loc);
9570 -- Deal with analyzing the string argument.
9572 if Arg_Count = 3 then
9574 -- If checks are not on we don't want any expansion (since
9575 -- such expansion would not get properly deleted) but
9576 -- we do want to analyze (to get proper references).
9577 -- The Preanalyze_And_Resolve routine does just what we want
9579 if not Check_On then
9580 Preanalyze_And_Resolve (Str, Standard_String);
9582 -- Otherwise we need a proper analysis and expansion
9585 Analyze_And_Resolve (Str, Standard_String);
9589 -- Now you might think we could just do the same with the Boolean
9590 -- expression if checks are off (and expansion is on) and then
9591 -- rewrite the check as a null statement. This would work but we
9592 -- would lose the useful warnings about an assertion being bound
9593 -- to fail even if assertions are turned off.
9595 -- So instead we wrap the boolean expression in an if statement
9598 -- if False and then condition then
9602 -- The reason we do this rewriting during semantic analysis
9603 -- rather than as part of normal expansion is that we cannot
9604 -- analyze and expand the code for the boolean expression
9605 -- directly, or it may cause insertion of actions that would
9606 -- escape the attempt to suppress the check code.
9608 -- Note that the Sloc for the if statement corresponds to the
9609 -- argument condition, not the pragma itself. The reason for
9610 -- this is that we may generate a warning if the condition is
9611 -- False at compile time, and we do not want to delete this
9612 -- warning when we delete the if statement.
9614 if Expander_Active and not Check_On then
9615 Eloc := Sloc (Expr);
9618 Make_If_Statement (Eloc,
9620 Make_And_Then (Eloc,
9621 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
9622 Right_Opnd => Expr),
9623 Then_Statements => New_List (
9624 Make_Null_Statement (Eloc))));
9626 In_Assertion_Expr := In_Assertion_Expr + 1;
9628 In_Assertion_Expr := In_Assertion_Expr - 1;
9630 -- Check is active or expansion not active. In these cases we can
9631 -- just go ahead and analyze the boolean with no worries.
9634 In_Assertion_Expr := In_Assertion_Expr + 1;
9635 Analyze_And_Resolve (Expr, Any_Boolean);
9636 In_Assertion_Expr := In_Assertion_Expr - 1;
9640 --------------------------
9641 -- Check_Float_Overflow --
9642 --------------------------
9644 -- pragma Check_Float_Overflow;
9646 when Pragma_Check_Float_Overflow =>
9648 Check_Valid_Configuration_Pragma;
9649 Check_Arg_Count (0);
9650 Check_Float_Overflow := True;
9656 -- pragma Check_Name (check_IDENTIFIER);
9658 when Pragma_Check_Name =>
9660 Check_No_Identifiers;
9661 Check_Valid_Configuration_Pragma;
9662 Check_Arg_Count (1);
9663 Check_Arg_Is_Identifier (Arg1);
9666 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9669 for J in Check_Names.First .. Check_Names.Last loop
9670 if Check_Names.Table (J) = Nam then
9675 Check_Names.Append (Nam);
9682 -- This is the old style syntax, which is still allowed in all modes:
9684 -- pragma Check_Policy ([Name =>] CHECK_KIND
9685 -- [Policy =>] POLICY_IDENTIFIER);
9687 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
9689 -- CHECK_KIND ::= IDENTIFIER |
9692 -- Type_Invariant'Class |
9695 -- This is the new style syntax, compatible with Assertion_Policy
9696 -- and also allowed in all modes.
9698 -- Pragma Check_Policy (
9699 -- CHECK_KIND => POLICY_IDENTIFIER
9700 -- {, CHECK_KIND => POLICY_IDENTIFIER});
9702 -- Note: the identifiers Name and Policy are not allowed as
9703 -- Check_Kind values. This avoids ambiguities between the old and
9706 when Pragma_Check_Policy => Check_Policy : declare
9711 Check_At_Least_N_Arguments (1);
9713 -- A Check_Policy pragma can appear either as a configuration
9714 -- pragma, or in a declarative part or a package spec (see RM
9715 -- 11.5(5) for rules for Suppress/Unsuppress which are also
9716 -- followed for Check_Policy).
9718 if not Is_Configuration_Pragma then
9719 Check_Is_In_Decl_Part_Or_Package_Spec;
9722 -- Figure out if we have the old or new syntax. We have the
9723 -- old syntax if the first argument has no identifier, or the
9724 -- identifier is Name.
9726 if Nkind (Arg1) /= N_Pragma_Argument_Association
9727 or else Nam_In (Chars (Arg1), No_Name, Name_Name)
9731 Check_Arg_Count (2);
9732 Check_Optional_Identifier (Arg1, Name_Name);
9733 Kind := Get_Pragma_Arg (Arg1);
9734 Rewrite_Assertion_Kind (Kind);
9735 Check_Arg_Is_Identifier (Arg1);
9737 -- Check forbidden check kind
9739 if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
9740 Error_Msg_Name_2 := Chars (Kind);
9742 ("pragma% does not allow% as check name", Arg1);
9747 Check_Optional_Identifier (Arg2, Name_Policy);
9750 Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
9752 -- And chain pragma on the Check_Policy_List for search
9754 Set_Next_Pragma (N, Opt.Check_Policy_List);
9755 Opt.Check_Policy_List := N;
9757 -- For the new syntax, what we do is to convert each argument to
9758 -- an old syntax equivalent. We do that because we want to chain
9759 -- old style Check_Policy pragmas for the search (we don't want
9760 -- to have to deal with multiple arguments in the search).
9770 while Present (Arg) loop
9772 Argx := Get_Pragma_Arg (Arg);
9774 -- Kind must be specified
9776 if Nkind (Arg) /= N_Pragma_Argument_Association
9777 or else Chars (Arg) = No_Name
9780 ("missing assertion kind for pragma%", Arg);
9783 -- Construct equivalent old form syntax Check_Policy
9784 -- pragma and insert it to get remaining checks.
9788 Chars => Name_Check_Policy,
9789 Pragma_Argument_Associations => New_List (
9790 Make_Pragma_Argument_Association (LocP,
9792 Make_Identifier (LocP, Chars (Arg))),
9793 Make_Pragma_Argument_Association (Sloc (Argx),
9794 Expression => Argx))));
9799 -- Rewrite original Check_Policy pragma to null, since we
9800 -- have converted it into a series of old syntax pragmas.
9802 Rewrite (N, Make_Null_Statement (Loc));
9808 ---------------------
9809 -- CIL_Constructor --
9810 ---------------------
9812 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
9814 -- Processing for this pragma is shared with Java_Constructor
9820 -- pragma Comment (static_string_EXPRESSION)
9822 -- Processing for pragma Comment shares the circuitry for pragma
9823 -- Ident. The only differences are that Ident enforces a limit of 31
9824 -- characters on its argument, and also enforces limitations on
9825 -- placement for DEC compatibility. Pragma Comment shares neither of
9826 -- these restrictions.
9832 -- pragma Common_Object (
9833 -- [Internal =>] LOCAL_NAME
9834 -- [, [External =>] EXTERNAL_SYMBOL]
9835 -- [, [Size =>] EXTERNAL_SYMBOL]);
9837 -- Processing for this pragma is shared with Psect_Object
9839 ------------------------
9840 -- Compile_Time_Error --
9841 ------------------------
9843 -- pragma Compile_Time_Error
9844 -- (boolean_EXPRESSION, static_string_EXPRESSION);
9846 when Pragma_Compile_Time_Error =>
9848 Process_Compile_Time_Warning_Or_Error;
9850 --------------------------
9851 -- Compile_Time_Warning --
9852 --------------------------
9854 -- pragma Compile_Time_Warning
9855 -- (boolean_EXPRESSION, static_string_EXPRESSION);
9857 when Pragma_Compile_Time_Warning =>
9859 Process_Compile_Time_Warning_Or_Error;
9865 when Pragma_Compiler_Unit =>
9867 Check_Arg_Count (0);
9868 Set_Is_Compiler_Unit (Get_Source_Unit (N));
9870 -----------------------------
9871 -- Complete_Representation --
9872 -----------------------------
9874 -- pragma Complete_Representation;
9876 when Pragma_Complete_Representation =>
9878 Check_Arg_Count (0);
9880 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
9882 ("pragma & must appear within record representation clause");
9885 ----------------------------
9886 -- Complex_Representation --
9887 ----------------------------
9889 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
9891 when Pragma_Complex_Representation => Complex_Representation : declare
9898 Check_Arg_Count (1);
9899 Check_Optional_Identifier (Arg1, Name_Entity);
9900 Check_Arg_Is_Local_Name (Arg1);
9901 E_Id := Get_Pragma_Arg (Arg1);
9903 if Etype (E_Id) = Any_Type then
9909 if not Is_Record_Type (E) then
9911 ("argument for pragma% must be record type", Arg1);
9914 Ent := First_Entity (E);
9917 or else No (Next_Entity (Ent))
9918 or else Present (Next_Entity (Next_Entity (Ent)))
9919 or else not Is_Floating_Point_Type (Etype (Ent))
9920 or else Etype (Ent) /= Etype (Next_Entity (Ent))
9923 ("record for pragma% must have two fields of the same "
9924 & "floating-point type", Arg1);
9927 Set_Has_Complex_Representation (Base_Type (E));
9929 -- We need to treat the type has having a non-standard
9930 -- representation, for back-end purposes, even though in
9931 -- general a complex will have the default representation
9932 -- of a record with two real components.
9934 Set_Has_Non_Standard_Rep (Base_Type (E));
9936 end Complex_Representation;
9938 -------------------------
9939 -- Component_Alignment --
9940 -------------------------
9942 -- pragma Component_Alignment (
9943 -- [Form =>] ALIGNMENT_CHOICE
9944 -- [, [Name =>] type_LOCAL_NAME]);
9946 -- ALIGNMENT_CHOICE ::=
9948 -- | Component_Size_4
9952 when Pragma_Component_Alignment => Component_AlignmentP : declare
9953 Args : Args_List (1 .. 2);
9954 Names : constant Name_List (1 .. 2) := (
9958 Form : Node_Id renames Args (1);
9959 Name : Node_Id renames Args (2);
9961 Atype : Component_Alignment_Kind;
9966 Gather_Associations (Names, Args);
9969 Error_Pragma ("missing Form argument for pragma%");
9972 Check_Arg_Is_Identifier (Form);
9974 -- Get proper alignment, note that Default = Component_Size on all
9975 -- machines we have so far, and we want to set this value rather
9976 -- than the default value to indicate that it has been explicitly
9977 -- set (and thus will not get overridden by the default component
9978 -- alignment for the current scope)
9980 if Chars (Form) = Name_Component_Size then
9981 Atype := Calign_Component_Size;
9983 elsif Chars (Form) = Name_Component_Size_4 then
9984 Atype := Calign_Component_Size_4;
9986 elsif Chars (Form) = Name_Default then
9987 Atype := Calign_Component_Size;
9989 elsif Chars (Form) = Name_Storage_Unit then
9990 Atype := Calign_Storage_Unit;
9994 ("invalid Form parameter for pragma%", Form);
9997 -- Case with no name, supplied, affects scope table entry
10001 (Scope_Stack.Last).Component_Alignment_Default := Atype;
10003 -- Case of name supplied
10006 Check_Arg_Is_Local_Name (Name);
10008 Typ := Entity (Name);
10011 or else Rep_Item_Too_Early (Typ, N)
10015 Typ := Underlying_Type (Typ);
10018 if not Is_Record_Type (Typ)
10019 and then not Is_Array_Type (Typ)
10022 ("Name parameter of pragma% must identify record or "
10023 & "array type", Name);
10026 -- An explicit Component_Alignment pragma overrides an
10027 -- implicit pragma Pack, but not an explicit one.
10029 if not Has_Pragma_Pack (Base_Type (Typ)) then
10030 Set_Is_Packed (Base_Type (Typ), False);
10031 Set_Component_Alignment (Base_Type (Typ), Atype);
10034 end Component_AlignmentP;
10036 --------------------
10037 -- Contract_Cases --
10038 --------------------
10040 -- pragma Contract_Cases (CONTRACT_CASE_LIST);
10042 -- CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
10044 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
10046 -- CASE_GUARD ::= boolean_EXPRESSION | others
10048 -- CONSEQUENCE ::= boolean_EXPRESSION
10050 when Pragma_Contract_Cases => Contract_Cases : declare
10051 Subp_Decl : Node_Id;
10052 Subp_Id : Entity_Id;
10056 Check_Arg_Count (1);
10058 -- Ensure the proper placement of the pragma. Contract_Cases must
10059 -- be associated with a subprogram declaration or a body that acts
10062 Subp_Decl := Find_Related_Subprogram (N, Check_Duplicates => True);
10064 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
10065 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
10066 or else not Acts_As_Spec (Subp_Decl))
10072 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
10074 -- The pragma is analyzed at the end of the declarative part which
10075 -- contains the related subprogram. Reset the analyzed flag.
10077 Set_Analyzed (N, False);
10079 -- When the aspect/pragma appears on a subprogram body, perform
10080 -- the full analysis now.
10082 if Nkind (Subp_Decl) = N_Subprogram_Body then
10083 Analyze_Contract_Cases_In_Decl_Part (N);
10085 -- When Contract_Cases applies to a subprogram compilation unit,
10086 -- the corresponding pragma is placed after the unit's declaration
10087 -- node and needs to be analyzed immediately.
10089 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
10090 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
10092 Analyze_Contract_Cases_In_Decl_Part (N);
10095 -- Chain the pragma on the contract for further processing
10097 Add_Contract_Item (N, Subp_Id);
10098 end Contract_Cases;
10104 -- pragma Controlled (first_subtype_LOCAL_NAME);
10106 when Pragma_Controlled => Controlled : declare
10110 Check_No_Identifiers;
10111 Check_Arg_Count (1);
10112 Check_Arg_Is_Local_Name (Arg1);
10113 Arg := Get_Pragma_Arg (Arg1);
10115 if not Is_Entity_Name (Arg)
10116 or else not Is_Access_Type (Entity (Arg))
10118 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10120 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
10128 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
10129 -- [Entity =>] LOCAL_NAME);
10131 when Pragma_Convention => Convention : declare
10134 pragma Warnings (Off, C);
10135 pragma Warnings (Off, E);
10137 Check_Arg_Order ((Name_Convention, Name_Entity));
10138 Check_Ada_83_Warning;
10139 Check_Arg_Count (2);
10140 Process_Convention (C, E);
10143 ---------------------------
10144 -- Convention_Identifier --
10145 ---------------------------
10147 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
10148 -- [Convention =>] convention_IDENTIFIER);
10150 when Pragma_Convention_Identifier => Convention_Identifier : declare
10156 Check_Arg_Order ((Name_Name, Name_Convention));
10157 Check_Arg_Count (2);
10158 Check_Optional_Identifier (Arg1, Name_Name);
10159 Check_Optional_Identifier (Arg2, Name_Convention);
10160 Check_Arg_Is_Identifier (Arg1);
10161 Check_Arg_Is_Identifier (Arg2);
10162 Idnam := Chars (Get_Pragma_Arg (Arg1));
10163 Cname := Chars (Get_Pragma_Arg (Arg2));
10165 if Is_Convention_Name (Cname) then
10166 Record_Convention_Identifier
10167 (Idnam, Get_Convention_Id (Cname));
10170 ("second arg for % pragma must be convention", Arg2);
10172 end Convention_Identifier;
10178 -- pragma CPP_Class ([Entity =>] local_NAME)
10180 when Pragma_CPP_Class => CPP_Class : declare
10184 if Warn_On_Obsolescent_Feature then
10186 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
10187 & "effect; replace it by pragma import?j?", N);
10190 Check_Arg_Count (1);
10194 Chars => Name_Import,
10195 Pragma_Argument_Associations => New_List (
10196 Make_Pragma_Argument_Association (Loc,
10197 Expression => Make_Identifier (Loc, Name_CPP)),
10198 New_Copy (First (Pragma_Argument_Associations (N))))));
10202 ---------------------
10203 -- CPP_Constructor --
10204 ---------------------
10206 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
10207 -- [, [External_Name =>] static_string_EXPRESSION ]
10208 -- [, [Link_Name =>] static_string_EXPRESSION ]);
10210 when Pragma_CPP_Constructor => CPP_Constructor : declare
10213 Def_Id : Entity_Id;
10214 Tag_Typ : Entity_Id;
10218 Check_At_Least_N_Arguments (1);
10219 Check_At_Most_N_Arguments (3);
10220 Check_Optional_Identifier (Arg1, Name_Entity);
10221 Check_Arg_Is_Local_Name (Arg1);
10223 Id := Get_Pragma_Arg (Arg1);
10224 Find_Program_Unit_Name (Id);
10226 -- If we did not find the name, we are done
10228 if Etype (Id) = Any_Type then
10232 Def_Id := Entity (Id);
10234 -- Check if already defined as constructor
10236 if Is_Constructor (Def_Id) then
10238 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
10242 if Ekind (Def_Id) = E_Function
10243 and then (Is_CPP_Class (Etype (Def_Id))
10244 or else (Is_Class_Wide_Type (Etype (Def_Id))
10246 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
10248 if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
10250 ("'C'P'P constructor must be defined in the scope of "
10251 & "its returned type", Arg1);
10254 if Arg_Count >= 2 then
10255 Set_Imported (Def_Id);
10256 Set_Is_Public (Def_Id);
10257 Process_Interface_Name (Def_Id, Arg2, Arg3);
10260 Set_Has_Completion (Def_Id);
10261 Set_Is_Constructor (Def_Id);
10262 Set_Convention (Def_Id, Convention_CPP);
10264 -- Imported C++ constructors are not dispatching primitives
10265 -- because in C++ they don't have a dispatch table slot.
10266 -- However, in Ada the constructor has the profile of a
10267 -- function that returns a tagged type and therefore it has
10268 -- been treated as a primitive operation during semantic
10269 -- analysis. We now remove it from the list of primitive
10270 -- operations of the type.
10272 if Is_Tagged_Type (Etype (Def_Id))
10273 and then not Is_Class_Wide_Type (Etype (Def_Id))
10274 and then Is_Dispatching_Operation (Def_Id)
10276 Tag_Typ := Etype (Def_Id);
10278 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
10279 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
10283 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
10284 Set_Is_Dispatching_Operation (Def_Id, False);
10287 -- For backward compatibility, if the constructor returns a
10288 -- class wide type, and we internally change the return type to
10289 -- the corresponding root type.
10291 if Is_Class_Wide_Type (Etype (Def_Id)) then
10292 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
10296 ("pragma% requires function returning a 'C'P'P_Class type",
10299 end CPP_Constructor;
10305 when Pragma_CPP_Virtual => CPP_Virtual : declare
10309 if Warn_On_Obsolescent_Feature then
10311 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
10320 when Pragma_CPP_Vtable => CPP_Vtable : declare
10324 if Warn_On_Obsolescent_Feature then
10326 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
10335 -- pragma CPU (EXPRESSION);
10337 when Pragma_CPU => CPU : declare
10338 P : constant Node_Id := Parent (N);
10344 Check_No_Identifiers;
10345 Check_Arg_Count (1);
10349 if Nkind (P) = N_Subprogram_Body then
10350 Check_In_Main_Program;
10352 Arg := Get_Pragma_Arg (Arg1);
10353 Analyze_And_Resolve (Arg, Any_Integer);
10355 Ent := Defining_Unit_Name (Specification (P));
10357 if Nkind (Ent) = N_Defining_Program_Unit_Name then
10358 Ent := Defining_Identifier (Ent);
10363 if not Is_Static_Expression (Arg) then
10364 Flag_Non_Static_Expr
10365 ("main subprogram affinity is not static!", Arg);
10368 -- If constraint error, then we already signalled an error
10370 elsif Raises_Constraint_Error (Arg) then
10373 -- Otherwise check in range
10377 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
10378 -- This is the entity System.Multiprocessors.CPU_Range;
10380 Val : constant Uint := Expr_Value (Arg);
10383 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
10385 Val > Expr_Value (Type_High_Bound (CPU_Id))
10388 ("main subprogram CPU is out of range", Arg1);
10394 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10398 elsif Nkind (P) = N_Task_Definition then
10399 Arg := Get_Pragma_Arg (Arg1);
10400 Ent := Defining_Identifier (Parent (P));
10402 -- The expression must be analyzed in the special manner
10403 -- described in "Handling of Default and Per-Object
10404 -- Expressions" in sem.ads.
10406 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
10408 -- Anything else is incorrect
10414 -- Check duplicate pragma before we chain the pragma in the Rep
10415 -- Item chain of Ent.
10417 Check_Duplicate_Pragma (Ent);
10418 Record_Rep_Item (Ent, N);
10425 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
10427 when Pragma_Debug => Debug : declare
10434 -- The condition for executing the call is that the expander
10435 -- is active and that we are not ignoring this debug pragma.
10440 (Expander_Active and then not Is_Ignored (N)),
10443 if not Is_Ignored (N) then
10444 Set_SCO_Pragma_Enabled (Loc);
10447 if Arg_Count = 2 then
10449 Make_And_Then (Loc,
10450 Left_Opnd => Relocate_Node (Cond),
10451 Right_Opnd => Get_Pragma_Arg (Arg1));
10452 Call := Get_Pragma_Arg (Arg2);
10454 Call := Get_Pragma_Arg (Arg1);
10458 N_Indexed_Component,
10462 N_Selected_Component)
10464 -- If this pragma Debug comes from source, its argument was
10465 -- parsed as a name form (which is syntactically identical).
10466 -- In a generic context a parameterless call will be left as
10467 -- an expanded name (if global) or selected_component if local.
10468 -- Change it to a procedure call statement now.
10470 Change_Name_To_Procedure_Call_Statement (Call);
10472 elsif Nkind (Call) = N_Procedure_Call_Statement then
10474 -- Already in the form of a procedure call statement: nothing
10475 -- to do (could happen in case of an internally generated
10481 -- All other cases: diagnose error
10484 ("argument of pragma ""Debug"" is not procedure call",
10489 -- Rewrite into a conditional with an appropriate condition. We
10490 -- wrap the procedure call in a block so that overhead from e.g.
10491 -- use of the secondary stack does not generate execution overhead
10492 -- for suppressed conditions.
10494 -- Normally the analysis that follows will freeze the subprogram
10495 -- being called. However, if the call is to a null procedure,
10496 -- we want to freeze it before creating the block, because the
10497 -- analysis that follows may be done with expansion disabled, in
10498 -- which case the body will not be generated, leading to spurious
10501 if Nkind (Call) = N_Procedure_Call_Statement
10502 and then Is_Entity_Name (Name (Call))
10504 Analyze (Name (Call));
10505 Freeze_Before (N, Entity (Name (Call)));
10508 Rewrite (N, Make_Implicit_If_Statement (N,
10510 Then_Statements => New_List (
10511 Make_Block_Statement (Loc,
10512 Handled_Statement_Sequence =>
10513 Make_Handled_Sequence_Of_Statements (Loc,
10514 Statements => New_List (Relocate_Node (Call)))))));
10522 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
10524 when Pragma_Debug_Policy =>
10526 Check_Arg_Count (1);
10527 Check_No_Identifiers;
10528 Check_Arg_Is_Identifier (Arg1);
10530 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
10531 -- rewrite it that way, and let the rest of the checking come
10532 -- from analyzing the rewritten pragma.
10536 Chars => Name_Check_Policy,
10537 Pragma_Argument_Associations => New_List (
10538 Make_Pragma_Argument_Association (Loc,
10539 Expression => Make_Identifier (Loc, Name_Debug)),
10541 Make_Pragma_Argument_Association (Loc,
10542 Expression => Get_Pragma_Arg (Arg1)))));
10549 -- pragma Depends (DEPENDENCY_RELATION);
10551 -- DEPENDENCY_RELATION ::=
10553 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
10555 -- DEPENDENCY_CLAUSE ::=
10556 -- OUTPUT_LIST =>[+] INPUT_LIST
10557 -- | NULL_DEPENDENCY_CLAUSE
10559 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
10561 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
10563 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
10565 -- OUTPUT ::= NAME | FUNCTION_RESULT
10568 -- where FUNCTION_RESULT is a function Result attribute_reference
10570 when Pragma_Depends => Depends : declare
10571 Subp_Decl : Node_Id;
10572 Subp_Id : Entity_Id;
10577 Check_Arg_Count (1);
10579 -- Ensure the proper placement of the pragma. Depends must be
10580 -- associated with a subprogram declaration or a body that acts
10583 Subp_Decl := Find_Related_Subprogram (N, Check_Duplicates => True);
10585 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
10586 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
10587 or else not Acts_As_Spec (Subp_Decl))
10593 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
10595 -- When the aspect/pragma appears on a subprogram body, perform
10596 -- the full analysis now.
10598 if Nkind (Subp_Decl) = N_Subprogram_Body then
10599 Analyze_Depends_In_Decl_Part (N);
10601 -- When Depends applies to a subprogram compilation unit, the
10602 -- corresponding pragma is placed after the unit's declaration
10603 -- node and needs to be analyzed immediately.
10605 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
10606 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
10608 Analyze_Depends_In_Decl_Part (N);
10611 -- Chain the pragma on the contract for further processing
10613 Add_Contract_Item (N, Subp_Id);
10616 ---------------------
10617 -- Detect_Blocking --
10618 ---------------------
10620 -- pragma Detect_Blocking;
10622 when Pragma_Detect_Blocking =>
10624 Check_Arg_Count (0);
10625 Check_Valid_Configuration_Pragma;
10626 Detect_Blocking := True;
10628 --------------------------
10629 -- Default_Storage_Pool --
10630 --------------------------
10632 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
10634 when Pragma_Default_Storage_Pool =>
10636 Check_Arg_Count (1);
10638 -- Default_Storage_Pool can appear as a configuration pragma, or
10639 -- in a declarative part or a package spec.
10641 if not Is_Configuration_Pragma then
10642 Check_Is_In_Decl_Part_Or_Package_Spec;
10645 -- Case of Default_Storage_Pool (null);
10647 if Nkind (Expression (Arg1)) = N_Null then
10648 Analyze (Expression (Arg1));
10650 -- This is an odd case, this is not really an expression, so
10651 -- we don't have a type for it. So just set the type to Empty.
10653 Set_Etype (Expression (Arg1), Empty);
10655 -- Case of Default_Storage_Pool (storage_pool_NAME);
10658 -- If it's a configuration pragma, then the only allowed
10659 -- argument is "null".
10661 if Is_Configuration_Pragma then
10662 Error_Pragma_Arg ("NULL expected", Arg1);
10665 -- The expected type for a non-"null" argument is
10666 -- Root_Storage_Pool'Class.
10668 Analyze_And_Resolve
10669 (Get_Pragma_Arg (Arg1),
10670 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
10673 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
10674 -- for an access type will use this information to set the
10675 -- appropriate attributes of the access type.
10677 Default_Pool := Expression (Arg1);
10679 ------------------------------------
10680 -- Disable_Atomic_Synchronization --
10681 ------------------------------------
10683 -- pragma Disable_Atomic_Synchronization [(Entity)];
10685 when Pragma_Disable_Atomic_Synchronization =>
10687 Process_Disable_Enable_Atomic_Sync (Name_Suppress);
10689 -------------------
10690 -- Discard_Names --
10691 -------------------
10693 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
10695 when Pragma_Discard_Names => Discard_Names : declare
10700 Check_Ada_83_Warning;
10702 -- Deal with configuration pragma case
10704 if Arg_Count = 0 and then Is_Configuration_Pragma then
10705 Global_Discard_Names := True;
10708 -- Otherwise, check correct appropriate context
10711 Check_Is_In_Decl_Part_Or_Package_Spec;
10713 if Arg_Count = 0 then
10715 -- If there is no parameter, then from now on this pragma
10716 -- applies to any enumeration, exception or tagged type
10717 -- defined in the current declarative part, and recursively
10718 -- to any nested scope.
10720 Set_Discard_Names (Current_Scope);
10724 Check_Arg_Count (1);
10725 Check_Optional_Identifier (Arg1, Name_On);
10726 Check_Arg_Is_Local_Name (Arg1);
10728 E_Id := Get_Pragma_Arg (Arg1);
10730 if Etype (E_Id) = Any_Type then
10733 E := Entity (E_Id);
10736 if (Is_First_Subtype (E)
10738 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
10739 or else Ekind (E) = E_Exception
10741 Set_Discard_Names (E);
10742 Record_Rep_Item (E, N);
10746 ("inappropriate entity for pragma%", Arg1);
10753 ------------------------
10754 -- Dispatching_Domain --
10755 ------------------------
10757 -- pragma Dispatching_Domain (EXPRESSION);
10759 when Pragma_Dispatching_Domain => Dispatching_Domain : declare
10760 P : constant Node_Id := Parent (N);
10766 Check_No_Identifiers;
10767 Check_Arg_Count (1);
10769 -- This pragma is born obsolete, but not the aspect
10771 if not From_Aspect_Specification (N) then
10773 (No_Obsolescent_Features, Pragma_Identifier (N));
10776 if Nkind (P) = N_Task_Definition then
10777 Arg := Get_Pragma_Arg (Arg1);
10778 Ent := Defining_Identifier (Parent (P));
10780 -- The expression must be analyzed in the special manner
10781 -- described in "Handling of Default and Per-Object
10782 -- Expressions" in sem.ads.
10784 Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
10786 -- Check duplicate pragma before we chain the pragma in the Rep
10787 -- Item chain of Ent.
10789 Check_Duplicate_Pragma (Ent);
10790 Record_Rep_Item (Ent, N);
10792 -- Anything else is incorrect
10797 end Dispatching_Domain;
10803 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
10805 when Pragma_Elaborate => Elaborate : declare
10810 -- Pragma must be in context items list of a compilation unit
10812 if not Is_In_Context_Clause then
10816 -- Must be at least one argument
10818 if Arg_Count = 0 then
10819 Error_Pragma ("pragma% requires at least one argument");
10822 -- In Ada 83 mode, there can be no items following it in the
10823 -- context list except other pragmas and implicit with clauses
10824 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
10825 -- placement rule does not apply.
10827 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
10829 while Present (Citem) loop
10830 if Nkind (Citem) = N_Pragma
10831 or else (Nkind (Citem) = N_With_Clause
10832 and then Implicit_With (Citem))
10837 ("(Ada 83) pragma% must be at end of context clause");
10844 -- Finally, the arguments must all be units mentioned in a with
10845 -- clause in the same context clause. Note we already checked (in
10846 -- Par.Prag) that the arguments are all identifiers or selected
10850 Outer : while Present (Arg) loop
10851 Citem := First (List_Containing (N));
10852 Inner : while Citem /= N loop
10853 if Nkind (Citem) = N_With_Clause
10854 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10856 Set_Elaborate_Present (Citem, True);
10857 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10858 Generate_Reference (Entity (Name (Citem)), Citem);
10860 -- With the pragma present, elaboration calls on
10861 -- subprograms from the named unit need no further
10862 -- checks, as long as the pragma appears in the current
10863 -- compilation unit. If the pragma appears in some unit
10864 -- in the context, there might still be a need for an
10865 -- Elaborate_All_Desirable from the current compilation
10866 -- to the named unit, so we keep the check enabled.
10868 if In_Extended_Main_Source_Unit (N) then
10869 Set_Suppress_Elaboration_Warnings
10870 (Entity (Name (Citem)));
10881 ("argument of pragma% is not withed unit", Arg);
10887 -- Give a warning if operating in static mode with -gnatwl
10888 -- (elaboration warnings enabled) switch set.
10890 if Elab_Warnings and not Dynamic_Elaboration_Checks then
10892 ("?l?use of pragma Elaborate may not be safe", N);
10894 ("?l?use pragma Elaborate_All instead if possible", N);
10898 -------------------
10899 -- Elaborate_All --
10900 -------------------
10902 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
10904 when Pragma_Elaborate_All => Elaborate_All : declare
10909 Check_Ada_83_Warning;
10911 -- Pragma must be in context items list of a compilation unit
10913 if not Is_In_Context_Clause then
10917 -- Must be at least one argument
10919 if Arg_Count = 0 then
10920 Error_Pragma ("pragma% requires at least one argument");
10923 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
10924 -- have to appear at the end of the context clause, but may
10925 -- appear mixed in with other items, even in Ada 83 mode.
10927 -- Final check: the arguments must all be units mentioned in
10928 -- a with clause in the same context clause. Note that we
10929 -- already checked (in Par.Prag) that all the arguments are
10930 -- either identifiers or selected components.
10933 Outr : while Present (Arg) loop
10934 Citem := First (List_Containing (N));
10935 Innr : while Citem /= N loop
10936 if Nkind (Citem) = N_With_Clause
10937 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10939 Set_Elaborate_All_Present (Citem, True);
10940 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10942 -- Suppress warnings and elaboration checks on the named
10943 -- unit if the pragma is in the current compilation, as
10944 -- for pragma Elaborate.
10946 if In_Extended_Main_Source_Unit (N) then
10947 Set_Suppress_Elaboration_Warnings
10948 (Entity (Name (Citem)));
10957 Set_Error_Posted (N);
10959 ("argument of pragma% is not withed unit", Arg);
10966 --------------------
10967 -- Elaborate_Body --
10968 --------------------
10970 -- pragma Elaborate_Body [( library_unit_NAME )];
10972 when Pragma_Elaborate_Body => Elaborate_Body : declare
10973 Cunit_Node : Node_Id;
10974 Cunit_Ent : Entity_Id;
10977 Check_Ada_83_Warning;
10978 Check_Valid_Library_Unit_Pragma;
10980 if Nkind (N) = N_Null_Statement then
10984 Cunit_Node := Cunit (Current_Sem_Unit);
10985 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10987 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
10990 Error_Pragma ("pragma% must refer to a spec, not a body");
10992 Set_Body_Required (Cunit_Node, True);
10993 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
10995 -- If we are in dynamic elaboration mode, then we suppress
10996 -- elaboration warnings for the unit, since it is definitely
10997 -- fine NOT to do dynamic checks at the first level (and such
10998 -- checks will be suppressed because no elaboration boolean
10999 -- is created for Elaborate_Body packages).
11001 -- But in the static model of elaboration, Elaborate_Body is
11002 -- definitely NOT good enough to ensure elaboration safety on
11003 -- its own, since the body may WITH other units that are not
11004 -- safe from an elaboration point of view, so a client must
11005 -- still do an Elaborate_All on such units.
11007 -- Debug flag -gnatdD restores the old behavior of 3.13, where
11008 -- Elaborate_Body always suppressed elab warnings.
11010 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
11011 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
11014 end Elaborate_Body;
11016 ------------------------
11017 -- Elaboration_Checks --
11018 ------------------------
11020 -- pragma Elaboration_Checks (Static | Dynamic);
11022 when Pragma_Elaboration_Checks =>
11024 Check_Arg_Count (1);
11025 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
11026 Dynamic_Elaboration_Checks :=
11027 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
11033 -- pragma Eliminate (
11034 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
11035 -- [,[Entity =>] IDENTIFIER |
11036 -- SELECTED_COMPONENT |
11038 -- [, OVERLOADING_RESOLUTION]);
11040 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
11043 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
11044 -- FUNCTION_PROFILE
11046 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
11048 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
11049 -- Result_Type => result_SUBTYPE_NAME]
11051 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
11052 -- SUBTYPE_NAME ::= STRING_LITERAL
11054 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
11055 -- SOURCE_TRACE ::= STRING_LITERAL
11057 when Pragma_Eliminate => Eliminate : declare
11058 Args : Args_List (1 .. 5);
11059 Names : constant Name_List (1 .. 5) := (
11062 Name_Parameter_Types,
11064 Name_Source_Location);
11066 Unit_Name : Node_Id renames Args (1);
11067 Entity : Node_Id renames Args (2);
11068 Parameter_Types : Node_Id renames Args (3);
11069 Result_Type : Node_Id renames Args (4);
11070 Source_Location : Node_Id renames Args (5);
11074 Check_Valid_Configuration_Pragma;
11075 Gather_Associations (Names, Args);
11077 if No (Unit_Name) then
11078 Error_Pragma ("missing Unit_Name argument for pragma%");
11082 and then (Present (Parameter_Types)
11084 Present (Result_Type)
11086 Present (Source_Location))
11088 Error_Pragma ("missing Entity argument for pragma%");
11091 if (Present (Parameter_Types)
11093 Present (Result_Type))
11095 Present (Source_Location)
11098 ("parameter profile and source location cannot be used "
11099 & "together in pragma%");
11102 Process_Eliminate_Pragma
11111 -----------------------------------
11112 -- Enable_Atomic_Synchronization --
11113 -----------------------------------
11115 -- pragma Enable_Atomic_Synchronization [(Entity)];
11117 when Pragma_Enable_Atomic_Synchronization =>
11119 Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
11126 -- [ Convention =>] convention_IDENTIFIER,
11127 -- [ Entity =>] local_NAME
11128 -- [, [External_Name =>] static_string_EXPRESSION ]
11129 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11131 when Pragma_Export => Export : declare
11133 Def_Id : Entity_Id;
11135 pragma Warnings (Off, C);
11138 Check_Ada_83_Warning;
11142 Name_External_Name,
11145 Check_At_Least_N_Arguments (2);
11147 Check_At_Most_N_Arguments (4);
11148 Process_Convention (C, Def_Id);
11150 if Ekind (Def_Id) /= E_Constant then
11151 Note_Possible_Modification
11152 (Get_Pragma_Arg (Arg2), Sure => False);
11155 Process_Interface_Name (Def_Id, Arg3, Arg4);
11156 Set_Exported (Def_Id, Arg2);
11158 -- If the entity is a deferred constant, propagate the information
11159 -- to the full view, because gigi elaborates the full view only.
11161 if Ekind (Def_Id) = E_Constant
11162 and then Present (Full_View (Def_Id))
11165 Id2 : constant Entity_Id := Full_View (Def_Id);
11167 Set_Is_Exported (Id2, Is_Exported (Def_Id));
11168 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
11169 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
11174 ----------------------
11175 -- Export_Exception --
11176 ----------------------
11178 -- pragma Export_Exception (
11179 -- [Internal =>] LOCAL_NAME
11180 -- [, [External =>] EXTERNAL_SYMBOL]
11181 -- [, [Form =>] Ada | VMS]
11182 -- [, [Code =>] static_integer_EXPRESSION]);
11184 when Pragma_Export_Exception => Export_Exception : declare
11185 Args : Args_List (1 .. 4);
11186 Names : constant Name_List (1 .. 4) := (
11192 Internal : Node_Id renames Args (1);
11193 External : Node_Id renames Args (2);
11194 Form : Node_Id renames Args (3);
11195 Code : Node_Id renames Args (4);
11200 if Inside_A_Generic then
11201 Error_Pragma ("pragma% cannot be used for generic entities");
11204 Gather_Associations (Names, Args);
11205 Process_Extended_Import_Export_Exception_Pragma (
11206 Arg_Internal => Internal,
11207 Arg_External => External,
11211 if not Is_VMS_Exception (Entity (Internal)) then
11212 Set_Exported (Entity (Internal), Internal);
11214 end Export_Exception;
11216 ---------------------
11217 -- Export_Function --
11218 ---------------------
11220 -- pragma Export_Function (
11221 -- [Internal =>] LOCAL_NAME
11222 -- [, [External =>] EXTERNAL_SYMBOL]
11223 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11224 -- [, [Result_Type =>] TYPE_DESIGNATOR]
11225 -- [, [Mechanism =>] MECHANISM]
11226 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
11228 -- EXTERNAL_SYMBOL ::=
11230 -- | static_string_EXPRESSION
11232 -- PARAMETER_TYPES ::=
11234 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11236 -- TYPE_DESIGNATOR ::=
11238 -- | subtype_Name ' Access
11242 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11244 -- MECHANISM_ASSOCIATION ::=
11245 -- [formal_parameter_NAME =>] MECHANISM_NAME
11247 -- MECHANISM_NAME ::=
11250 -- | Descriptor [([Class =>] CLASS_NAME)]
11252 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11254 when Pragma_Export_Function => Export_Function : declare
11255 Args : Args_List (1 .. 6);
11256 Names : constant Name_List (1 .. 6) := (
11259 Name_Parameter_Types,
11262 Name_Result_Mechanism);
11264 Internal : Node_Id renames Args (1);
11265 External : Node_Id renames Args (2);
11266 Parameter_Types : Node_Id renames Args (3);
11267 Result_Type : Node_Id renames Args (4);
11268 Mechanism : Node_Id renames Args (5);
11269 Result_Mechanism : Node_Id renames Args (6);
11273 Gather_Associations (Names, Args);
11274 Process_Extended_Import_Export_Subprogram_Pragma (
11275 Arg_Internal => Internal,
11276 Arg_External => External,
11277 Arg_Parameter_Types => Parameter_Types,
11278 Arg_Result_Type => Result_Type,
11279 Arg_Mechanism => Mechanism,
11280 Arg_Result_Mechanism => Result_Mechanism);
11281 end Export_Function;
11283 -------------------
11284 -- Export_Object --
11285 -------------------
11287 -- pragma Export_Object (
11288 -- [Internal =>] LOCAL_NAME
11289 -- [, [External =>] EXTERNAL_SYMBOL]
11290 -- [, [Size =>] EXTERNAL_SYMBOL]);
11292 -- EXTERNAL_SYMBOL ::=
11294 -- | static_string_EXPRESSION
11296 -- PARAMETER_TYPES ::=
11298 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11300 -- TYPE_DESIGNATOR ::=
11302 -- | subtype_Name ' Access
11306 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11308 -- MECHANISM_ASSOCIATION ::=
11309 -- [formal_parameter_NAME =>] MECHANISM_NAME
11311 -- MECHANISM_NAME ::=
11314 -- | Descriptor [([Class =>] CLASS_NAME)]
11316 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11318 when Pragma_Export_Object => Export_Object : declare
11319 Args : Args_List (1 .. 3);
11320 Names : constant Name_List (1 .. 3) := (
11325 Internal : Node_Id renames Args (1);
11326 External : Node_Id renames Args (2);
11327 Size : Node_Id renames Args (3);
11331 Gather_Associations (Names, Args);
11332 Process_Extended_Import_Export_Object_Pragma (
11333 Arg_Internal => Internal,
11334 Arg_External => External,
11338 ----------------------
11339 -- Export_Procedure --
11340 ----------------------
11342 -- pragma Export_Procedure (
11343 -- [Internal =>] LOCAL_NAME
11344 -- [, [External =>] EXTERNAL_SYMBOL]
11345 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11346 -- [, [Mechanism =>] MECHANISM]);
11348 -- EXTERNAL_SYMBOL ::=
11350 -- | static_string_EXPRESSION
11352 -- PARAMETER_TYPES ::=
11354 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11356 -- TYPE_DESIGNATOR ::=
11358 -- | subtype_Name ' Access
11362 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11364 -- MECHANISM_ASSOCIATION ::=
11365 -- [formal_parameter_NAME =>] MECHANISM_NAME
11367 -- MECHANISM_NAME ::=
11370 -- | Descriptor [([Class =>] CLASS_NAME)]
11372 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11374 when Pragma_Export_Procedure => Export_Procedure : declare
11375 Args : Args_List (1 .. 4);
11376 Names : constant Name_List (1 .. 4) := (
11379 Name_Parameter_Types,
11382 Internal : Node_Id renames Args (1);
11383 External : Node_Id renames Args (2);
11384 Parameter_Types : Node_Id renames Args (3);
11385 Mechanism : Node_Id renames Args (4);
11389 Gather_Associations (Names, Args);
11390 Process_Extended_Import_Export_Subprogram_Pragma (
11391 Arg_Internal => Internal,
11392 Arg_External => External,
11393 Arg_Parameter_Types => Parameter_Types,
11394 Arg_Mechanism => Mechanism);
11395 end Export_Procedure;
11401 -- pragma Export_Value (
11402 -- [Value =>] static_integer_EXPRESSION,
11403 -- [Link_Name =>] static_string_EXPRESSION);
11405 when Pragma_Export_Value =>
11407 Check_Arg_Order ((Name_Value, Name_Link_Name));
11408 Check_Arg_Count (2);
11410 Check_Optional_Identifier (Arg1, Name_Value);
11411 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
11413 Check_Optional_Identifier (Arg2, Name_Link_Name);
11414 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11416 -----------------------------
11417 -- Export_Valued_Procedure --
11418 -----------------------------
11420 -- pragma Export_Valued_Procedure (
11421 -- [Internal =>] LOCAL_NAME
11422 -- [, [External =>] EXTERNAL_SYMBOL,]
11423 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
11424 -- [, [Mechanism =>] MECHANISM]);
11426 -- EXTERNAL_SYMBOL ::=
11428 -- | static_string_EXPRESSION
11430 -- PARAMETER_TYPES ::=
11432 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11434 -- TYPE_DESIGNATOR ::=
11436 -- | subtype_Name ' Access
11440 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11442 -- MECHANISM_ASSOCIATION ::=
11443 -- [formal_parameter_NAME =>] MECHANISM_NAME
11445 -- MECHANISM_NAME ::=
11448 -- | Descriptor [([Class =>] CLASS_NAME)]
11450 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11452 when Pragma_Export_Valued_Procedure =>
11453 Export_Valued_Procedure : declare
11454 Args : Args_List (1 .. 4);
11455 Names : constant Name_List (1 .. 4) := (
11458 Name_Parameter_Types,
11461 Internal : Node_Id renames Args (1);
11462 External : Node_Id renames Args (2);
11463 Parameter_Types : Node_Id renames Args (3);
11464 Mechanism : Node_Id renames Args (4);
11468 Gather_Associations (Names, Args);
11469 Process_Extended_Import_Export_Subprogram_Pragma (
11470 Arg_Internal => Internal,
11471 Arg_External => External,
11472 Arg_Parameter_Types => Parameter_Types,
11473 Arg_Mechanism => Mechanism);
11474 end Export_Valued_Procedure;
11476 -------------------
11477 -- Extend_System --
11478 -------------------
11480 -- pragma Extend_System ([Name =>] Identifier);
11482 when Pragma_Extend_System => Extend_System : declare
11485 Check_Valid_Configuration_Pragma;
11486 Check_Arg_Count (1);
11487 Check_Optional_Identifier (Arg1, Name_Name);
11488 Check_Arg_Is_Identifier (Arg1);
11490 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11493 and then Name_Buffer (1 .. 4) = "aux_"
11495 if Present (System_Extend_Pragma_Arg) then
11496 if Chars (Get_Pragma_Arg (Arg1)) =
11497 Chars (Expression (System_Extend_Pragma_Arg))
11501 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
11502 Error_Pragma ("pragma% conflicts with that #");
11506 System_Extend_Pragma_Arg := Arg1;
11508 if not GNAT_Mode then
11509 System_Extend_Unit := Arg1;
11513 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
11517 ------------------------
11518 -- Extensions_Allowed --
11519 ------------------------
11521 -- pragma Extensions_Allowed (ON | OFF);
11523 when Pragma_Extensions_Allowed =>
11525 Check_Arg_Count (1);
11526 Check_No_Identifiers;
11527 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11529 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11530 Extensions_Allowed := True;
11531 Ada_Version := Ada_Version_Type'Last;
11534 Extensions_Allowed := False;
11535 Ada_Version := Ada_Version_Explicit;
11542 -- pragma External (
11543 -- [ Convention =>] convention_IDENTIFIER,
11544 -- [ Entity =>] local_NAME
11545 -- [, [External_Name =>] static_string_EXPRESSION ]
11546 -- [, [Link_Name =>] static_string_EXPRESSION ]);
11548 when Pragma_External => External : declare
11549 Def_Id : Entity_Id;
11552 pragma Warnings (Off, C);
11559 Name_External_Name,
11561 Check_At_Least_N_Arguments (2);
11562 Check_At_Most_N_Arguments (4);
11563 Process_Convention (C, Def_Id);
11564 Note_Possible_Modification
11565 (Get_Pragma_Arg (Arg2), Sure => False);
11566 Process_Interface_Name (Def_Id, Arg3, Arg4);
11567 Set_Exported (Def_Id, Arg2);
11570 --------------------------
11571 -- External_Name_Casing --
11572 --------------------------
11574 -- pragma External_Name_Casing (
11575 -- UPPERCASE | LOWERCASE
11576 -- [, AS_IS | UPPERCASE | LOWERCASE]);
11578 when Pragma_External_Name_Casing => External_Name_Casing : declare
11581 Check_No_Identifiers;
11583 if Arg_Count = 2 then
11584 Check_Arg_Is_One_Of
11585 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
11587 case Chars (Get_Pragma_Arg (Arg2)) is
11589 Opt.External_Name_Exp_Casing := As_Is;
11591 when Name_Uppercase =>
11592 Opt.External_Name_Exp_Casing := Uppercase;
11594 when Name_Lowercase =>
11595 Opt.External_Name_Exp_Casing := Lowercase;
11602 Check_Arg_Count (1);
11605 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
11607 case Chars (Get_Pragma_Arg (Arg1)) is
11608 when Name_Uppercase =>
11609 Opt.External_Name_Imp_Casing := Uppercase;
11611 when Name_Lowercase =>
11612 Opt.External_Name_Imp_Casing := Lowercase;
11617 end External_Name_Casing;
11623 -- pragma Fast_Math;
11625 when Pragma_Fast_Math =>
11627 Check_No_Identifiers;
11628 Check_Valid_Configuration_Pragma;
11631 --------------------------
11632 -- Favor_Top_Level --
11633 --------------------------
11635 -- pragma Favor_Top_Level (type_NAME);
11637 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
11638 Named_Entity : Entity_Id;
11642 Check_No_Identifiers;
11643 Check_Arg_Count (1);
11644 Check_Arg_Is_Local_Name (Arg1);
11645 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
11647 -- If it's an access-to-subprogram type (in particular, not a
11648 -- subtype), set the flag on that type.
11650 if Is_Access_Subprogram_Type (Named_Entity) then
11651 Set_Can_Use_Internal_Rep (Named_Entity, False);
11653 -- Otherwise it's an error (name denotes the wrong sort of entity)
11657 ("access-to-subprogram type expected",
11658 Get_Pragma_Arg (Arg1));
11660 end Favor_Top_Level;
11662 ---------------------------
11663 -- Finalize_Storage_Only --
11664 ---------------------------
11666 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
11668 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
11669 Assoc : constant Node_Id := Arg1;
11670 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
11675 Check_No_Identifiers;
11676 Check_Arg_Count (1);
11677 Check_Arg_Is_Local_Name (Arg1);
11679 Find_Type (Type_Id);
11680 Typ := Entity (Type_Id);
11683 or else Rep_Item_Too_Early (Typ, N)
11687 Typ := Underlying_Type (Typ);
11690 if not Is_Controlled (Typ) then
11691 Error_Pragma ("pragma% must specify controlled type");
11694 Check_First_Subtype (Arg1);
11696 if Finalize_Storage_Only (Typ) then
11697 Error_Pragma ("duplicate pragma%, only one allowed");
11699 elsif not Rep_Item_Too_Late (Typ, N) then
11700 Set_Finalize_Storage_Only (Base_Type (Typ), True);
11702 end Finalize_Storage;
11704 --------------------------
11705 -- Float_Representation --
11706 --------------------------
11708 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
11710 -- FLOAT_REP ::= VAX_Float | IEEE_Float
11712 when Pragma_Float_Representation => Float_Representation : declare
11720 if Arg_Count = 1 then
11721 Check_Valid_Configuration_Pragma;
11723 Check_Arg_Count (2);
11724 Check_Optional_Identifier (Arg2, Name_Entity);
11725 Check_Arg_Is_Local_Name (Arg2);
11728 Check_No_Identifier (Arg1);
11729 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
11731 if not OpenVMS_On_Target then
11732 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11734 ("??pragma% ignored (applies only to Open'V'M'S)");
11740 -- One argument case
11742 if Arg_Count = 1 then
11743 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11744 if Opt.Float_Format = 'I' then
11745 Error_Pragma ("'I'E'E'E format previously specified");
11748 Opt.Float_Format := 'V';
11751 if Opt.Float_Format = 'V' then
11752 Error_Pragma ("'V'A'X format previously specified");
11755 Opt.Float_Format := 'I';
11758 Set_Standard_Fpt_Formats;
11760 -- Two argument case
11763 Argx := Get_Pragma_Arg (Arg2);
11765 if not Is_Entity_Name (Argx)
11766 or else not Is_Floating_Point_Type (Entity (Argx))
11769 ("second argument of% pragma must be floating-point type",
11773 Ent := Entity (Argx);
11774 Digs := UI_To_Int (Digits_Value (Ent));
11776 -- Two arguments, VAX_Float case
11778 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11780 when 6 => Set_F_Float (Ent);
11781 when 9 => Set_D_Float (Ent);
11782 when 15 => Set_G_Float (Ent);
11786 ("wrong digits value, must be 6,9 or 15", Arg2);
11789 -- Two arguments, IEEE_Float case
11793 when 6 => Set_IEEE_Short (Ent);
11794 when 15 => Set_IEEE_Long (Ent);
11798 ("wrong digits value, must be 6 or 15", Arg2);
11802 end Float_Representation;
11808 -- pragma Global (GLOBAL_SPECIFICATION)
11810 -- GLOBAL_SPECIFICATION ::=
11813 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
11815 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
11817 -- MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
11818 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
11819 -- GLOBAL_ITEM ::= NAME
11821 when Pragma_Global => Global : declare
11822 Subp_Decl : Node_Id;
11823 Subp_Id : Entity_Id;
11828 Check_Arg_Count (1);
11830 -- Ensure the proper placement of the pragma. Global must be
11831 -- associated with a subprogram declaration or a body that acts
11834 Subp_Decl := Find_Related_Subprogram (N, Check_Duplicates => True);
11836 if Nkind (Subp_Decl) /= N_Subprogram_Declaration
11837 and then (Nkind (Subp_Decl) /= N_Subprogram_Body
11838 or else not Acts_As_Spec (Subp_Decl))
11844 Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
11846 -- When the aspect/pragma appears on a subprogram body, perform
11847 -- the full analysis now.
11849 if Nkind (Subp_Decl) = N_Subprogram_Body then
11850 Analyze_Global_In_Decl_Part (N);
11852 -- When Global applies to a subprogram compilation unit, the
11853 -- corresponding pragma is placed after the unit's declaration
11854 -- node and needs to be analyzed immediately.
11856 elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
11857 and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
11859 Analyze_Global_In_Decl_Part (N);
11862 -- Chain the pragma on the contract for further processing
11864 Add_Contract_Item (N, Subp_Id);
11871 -- pragma Ident (static_string_EXPRESSION)
11873 -- Note: pragma Comment shares this processing. Pragma Comment is
11874 -- identical to Ident, except that the restriction of the argument to
11875 -- 31 characters and the placement restrictions are not enforced for
11878 when Pragma_Ident | Pragma_Comment => Ident : declare
11883 Check_Arg_Count (1);
11884 Check_No_Identifiers;
11885 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11888 -- For pragma Ident, preserve DEC compatibility by requiring the
11889 -- pragma to appear in a declarative part or package spec.
11891 if Prag_Id = Pragma_Ident then
11892 Check_Is_In_Decl_Part_Or_Package_Spec;
11895 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
11902 GP := Parent (Parent (N));
11904 if Nkind_In (GP, N_Package_Declaration,
11905 N_Generic_Package_Declaration)
11910 -- If we have a compilation unit, then record the ident value,
11911 -- checking for improper duplication.
11913 if Nkind (GP) = N_Compilation_Unit then
11914 CS := Ident_String (Current_Sem_Unit);
11916 if Present (CS) then
11918 -- For Ident, we do not permit multiple instances
11920 if Prag_Id = Pragma_Ident then
11921 Error_Pragma ("duplicate% pragma not permitted");
11923 -- For Comment, we concatenate the string, unless we want
11924 -- to preserve the tree structure for ASIS.
11926 elsif not ASIS_Mode then
11927 Start_String (Strval (CS));
11928 Store_String_Char (' ');
11929 Store_String_Chars (Strval (Str));
11930 Set_Strval (CS, End_String);
11934 -- In VMS, the effect of IDENT is achieved by passing
11935 -- --identification=name as a --for-linker switch.
11937 if OpenVMS_On_Target then
11940 ("--for-linker=--identification=");
11941 String_To_Name_Buffer (Strval (Str));
11942 Store_String_Chars (Name_Buffer (1 .. Name_Len));
11944 -- Only the last processed IDENT is saved. The main
11945 -- purpose is so an IDENT associated with a main
11946 -- procedure will be used in preference to an IDENT
11947 -- associated with a with'd package.
11949 Replace_Linker_Option_String
11950 (End_String, "--for-linker=--identification=");
11953 Set_Ident_String (Current_Sem_Unit, Str);
11956 -- For subunits, we just ignore the Ident, since in GNAT these
11957 -- are not separate object files, and hence not separate units
11958 -- in the unit table.
11960 elsif Nkind (GP) = N_Subunit then
11963 -- Otherwise we have a misplaced pragma Ident, but we ignore
11964 -- this if we are in an instantiation, since it comes from
11965 -- a generic, and has no relevance to the instantiation.
11967 elsif Prag_Id = Pragma_Ident then
11968 if Instantiation_Location (Loc) = No_Location then
11969 Error_Pragma ("pragma% only allowed at outer level");
11975 ----------------------------
11976 -- Implementation_Defined --
11977 ----------------------------
11979 -- pragma Implementation_Defined (local_NAME);
11981 -- Marks previously declared entity as implementation defined. For
11982 -- an overloaded entity, applies to the most recent homonym.
11984 -- pragma Implementation_Defined;
11986 -- The form with no arguments appears anywhere within a scope, most
11987 -- typically a package spec, and indicates that all entities that are
11988 -- defined within the package spec are Implementation_Defined.
11990 when Pragma_Implementation_Defined => Implementation_Defined : declare
11995 Check_No_Identifiers;
11997 -- Form with no arguments
11999 if Arg_Count = 0 then
12000 Set_Is_Implementation_Defined (Current_Scope);
12002 -- Form with one argument
12005 Check_Arg_Count (1);
12006 Check_Arg_Is_Local_Name (Arg1);
12007 Ent := Entity (Get_Pragma_Arg (Arg1));
12008 Set_Is_Implementation_Defined (Ent);
12010 end Implementation_Defined;
12016 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
12018 -- IMPLEMENTATION_KIND ::=
12019 -- By_Entry | By_Protected_Procedure | By_Any | Optional
12021 -- "By_Any" and "Optional" are treated as synonyms in order to
12022 -- support Ada 2012 aspect Synchronization.
12024 when Pragma_Implemented => Implemented : declare
12025 Proc_Id : Entity_Id;
12030 Check_Arg_Count (2);
12031 Check_No_Identifiers;
12032 Check_Arg_Is_Identifier (Arg1);
12033 Check_Arg_Is_Local_Name (Arg1);
12034 Check_Arg_Is_One_Of (Arg2,
12037 Name_By_Protected_Procedure,
12040 -- Extract the name of the local procedure
12042 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
12044 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
12045 -- primitive procedure of a synchronized tagged type.
12047 if Ekind (Proc_Id) = E_Procedure
12048 and then Is_Primitive (Proc_Id)
12049 and then Present (First_Formal (Proc_Id))
12051 Typ := Etype (First_Formal (Proc_Id));
12053 if Is_Tagged_Type (Typ)
12056 -- Check for a protected, a synchronized or a task interface
12058 ((Is_Interface (Typ)
12059 and then Is_Synchronized_Interface (Typ))
12061 -- Check for a protected type or a task type that implements
12065 (Is_Concurrent_Record_Type (Typ)
12066 and then Present (Interfaces (Typ)))
12068 -- Check for a private record extension with keyword
12072 (Ekind_In (Typ, E_Record_Type_With_Private,
12073 E_Record_Subtype_With_Private)
12074 and then Synchronized_Present (Parent (Typ))))
12079 ("controlling formal must be of synchronized tagged type",
12084 -- Procedures declared inside a protected type must be accepted
12086 elsif Ekind (Proc_Id) = E_Procedure
12087 and then Is_Protected_Type (Scope (Proc_Id))
12091 -- The first argument is not a primitive procedure
12095 ("pragma % must be applied to a primitive procedure", Arg1);
12099 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
12100 -- By_Protected_Procedure to the primitive procedure of a task
12103 if Chars (Arg2) = Name_By_Protected_Procedure
12104 and then Is_Interface (Typ)
12105 and then Is_Task_Interface (Typ)
12108 ("implementation kind By_Protected_Procedure cannot be "
12109 & "applied to a task interface primitive", Arg2);
12113 Record_Rep_Item (Proc_Id, N);
12116 ----------------------
12117 -- Implicit_Packing --
12118 ----------------------
12120 -- pragma Implicit_Packing;
12122 when Pragma_Implicit_Packing =>
12124 Check_Arg_Count (0);
12125 Implicit_Packing := True;
12132 -- [Convention =>] convention_IDENTIFIER,
12133 -- [Entity =>] local_NAME
12134 -- [, [External_Name =>] static_string_EXPRESSION ]
12135 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12137 when Pragma_Import =>
12138 Check_Ada_83_Warning;
12142 Name_External_Name,
12145 Check_At_Least_N_Arguments (2);
12146 Check_At_Most_N_Arguments (4);
12147 Process_Import_Or_Interface;
12149 ----------------------
12150 -- Import_Exception --
12151 ----------------------
12153 -- pragma Import_Exception (
12154 -- [Internal =>] LOCAL_NAME
12155 -- [, [External =>] EXTERNAL_SYMBOL]
12156 -- [, [Form =>] Ada | VMS]
12157 -- [, [Code =>] static_integer_EXPRESSION]);
12159 when Pragma_Import_Exception => Import_Exception : declare
12160 Args : Args_List (1 .. 4);
12161 Names : constant Name_List (1 .. 4) := (
12167 Internal : Node_Id renames Args (1);
12168 External : Node_Id renames Args (2);
12169 Form : Node_Id renames Args (3);
12170 Code : Node_Id renames Args (4);
12174 Gather_Associations (Names, Args);
12176 if Present (External) and then Present (Code) then
12178 ("cannot give both External and Code options for pragma%");
12181 Process_Extended_Import_Export_Exception_Pragma (
12182 Arg_Internal => Internal,
12183 Arg_External => External,
12187 if not Is_VMS_Exception (Entity (Internal)) then
12188 Set_Imported (Entity (Internal));
12190 end Import_Exception;
12192 ---------------------
12193 -- Import_Function --
12194 ---------------------
12196 -- pragma Import_Function (
12197 -- [Internal =>] LOCAL_NAME,
12198 -- [, [External =>] EXTERNAL_SYMBOL]
12199 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12200 -- [, [Result_Type =>] SUBTYPE_MARK]
12201 -- [, [Mechanism =>] MECHANISM]
12202 -- [, [Result_Mechanism =>] MECHANISM_NAME]
12203 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
12205 -- EXTERNAL_SYMBOL ::=
12207 -- | static_string_EXPRESSION
12209 -- PARAMETER_TYPES ::=
12211 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12213 -- TYPE_DESIGNATOR ::=
12215 -- | subtype_Name ' Access
12219 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12221 -- MECHANISM_ASSOCIATION ::=
12222 -- [formal_parameter_NAME =>] MECHANISM_NAME
12224 -- MECHANISM_NAME ::=
12227 -- | Descriptor [([Class =>] CLASS_NAME)]
12229 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12231 when Pragma_Import_Function => Import_Function : declare
12232 Args : Args_List (1 .. 7);
12233 Names : constant Name_List (1 .. 7) := (
12236 Name_Parameter_Types,
12239 Name_Result_Mechanism,
12240 Name_First_Optional_Parameter);
12242 Internal : Node_Id renames Args (1);
12243 External : Node_Id renames Args (2);
12244 Parameter_Types : Node_Id renames Args (3);
12245 Result_Type : Node_Id renames Args (4);
12246 Mechanism : Node_Id renames Args (5);
12247 Result_Mechanism : Node_Id renames Args (6);
12248 First_Optional_Parameter : Node_Id renames Args (7);
12252 Gather_Associations (Names, Args);
12253 Process_Extended_Import_Export_Subprogram_Pragma (
12254 Arg_Internal => Internal,
12255 Arg_External => External,
12256 Arg_Parameter_Types => Parameter_Types,
12257 Arg_Result_Type => Result_Type,
12258 Arg_Mechanism => Mechanism,
12259 Arg_Result_Mechanism => Result_Mechanism,
12260 Arg_First_Optional_Parameter => First_Optional_Parameter);
12261 end Import_Function;
12263 -------------------
12264 -- Import_Object --
12265 -------------------
12267 -- pragma Import_Object (
12268 -- [Internal =>] LOCAL_NAME
12269 -- [, [External =>] EXTERNAL_SYMBOL]
12270 -- [, [Size =>] EXTERNAL_SYMBOL]);
12272 -- EXTERNAL_SYMBOL ::=
12274 -- | static_string_EXPRESSION
12276 when Pragma_Import_Object => Import_Object : declare
12277 Args : Args_List (1 .. 3);
12278 Names : constant Name_List (1 .. 3) := (
12283 Internal : Node_Id renames Args (1);
12284 External : Node_Id renames Args (2);
12285 Size : Node_Id renames Args (3);
12289 Gather_Associations (Names, Args);
12290 Process_Extended_Import_Export_Object_Pragma (
12291 Arg_Internal => Internal,
12292 Arg_External => External,
12296 ----------------------
12297 -- Import_Procedure --
12298 ----------------------
12300 -- pragma Import_Procedure (
12301 -- [Internal =>] LOCAL_NAME
12302 -- [, [External =>] EXTERNAL_SYMBOL]
12303 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12304 -- [, [Mechanism =>] MECHANISM]
12305 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
12307 -- EXTERNAL_SYMBOL ::=
12309 -- | static_string_EXPRESSION
12311 -- PARAMETER_TYPES ::=
12313 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12315 -- TYPE_DESIGNATOR ::=
12317 -- | subtype_Name ' Access
12321 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12323 -- MECHANISM_ASSOCIATION ::=
12324 -- [formal_parameter_NAME =>] MECHANISM_NAME
12326 -- MECHANISM_NAME ::=
12329 -- | Descriptor [([Class =>] CLASS_NAME)]
12331 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12333 when Pragma_Import_Procedure => Import_Procedure : declare
12334 Args : Args_List (1 .. 5);
12335 Names : constant Name_List (1 .. 5) := (
12338 Name_Parameter_Types,
12340 Name_First_Optional_Parameter);
12342 Internal : Node_Id renames Args (1);
12343 External : Node_Id renames Args (2);
12344 Parameter_Types : Node_Id renames Args (3);
12345 Mechanism : Node_Id renames Args (4);
12346 First_Optional_Parameter : Node_Id renames Args (5);
12350 Gather_Associations (Names, Args);
12351 Process_Extended_Import_Export_Subprogram_Pragma (
12352 Arg_Internal => Internal,
12353 Arg_External => External,
12354 Arg_Parameter_Types => Parameter_Types,
12355 Arg_Mechanism => Mechanism,
12356 Arg_First_Optional_Parameter => First_Optional_Parameter);
12357 end Import_Procedure;
12359 -----------------------------
12360 -- Import_Valued_Procedure --
12361 -----------------------------
12363 -- pragma Import_Valued_Procedure (
12364 -- [Internal =>] LOCAL_NAME
12365 -- [, [External =>] EXTERNAL_SYMBOL]
12366 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
12367 -- [, [Mechanism =>] MECHANISM]
12368 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
12370 -- EXTERNAL_SYMBOL ::=
12372 -- | static_string_EXPRESSION
12374 -- PARAMETER_TYPES ::=
12376 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12378 -- TYPE_DESIGNATOR ::=
12380 -- | subtype_Name ' Access
12384 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12386 -- MECHANISM_ASSOCIATION ::=
12387 -- [formal_parameter_NAME =>] MECHANISM_NAME
12389 -- MECHANISM_NAME ::=
12392 -- | Descriptor [([Class =>] CLASS_NAME)]
12394 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12396 when Pragma_Import_Valued_Procedure =>
12397 Import_Valued_Procedure : declare
12398 Args : Args_List (1 .. 5);
12399 Names : constant Name_List (1 .. 5) := (
12402 Name_Parameter_Types,
12404 Name_First_Optional_Parameter);
12406 Internal : Node_Id renames Args (1);
12407 External : Node_Id renames Args (2);
12408 Parameter_Types : Node_Id renames Args (3);
12409 Mechanism : Node_Id renames Args (4);
12410 First_Optional_Parameter : Node_Id renames Args (5);
12414 Gather_Associations (Names, Args);
12415 Process_Extended_Import_Export_Subprogram_Pragma (
12416 Arg_Internal => Internal,
12417 Arg_External => External,
12418 Arg_Parameter_Types => Parameter_Types,
12419 Arg_Mechanism => Mechanism,
12420 Arg_First_Optional_Parameter => First_Optional_Parameter);
12421 end Import_Valued_Procedure;
12427 -- pragma Independent (LOCAL_NAME);
12429 when Pragma_Independent => Independent : declare
12436 Check_Ada_83_Warning;
12438 Check_No_Identifiers;
12439 Check_Arg_Count (1);
12440 Check_Arg_Is_Local_Name (Arg1);
12441 E_Id := Get_Pragma_Arg (Arg1);
12443 if Etype (E_Id) = Any_Type then
12447 E := Entity (E_Id);
12448 D := Declaration_Node (E);
12451 -- Check duplicate before we chain ourselves!
12453 Check_Duplicate_Pragma (E);
12455 -- Check appropriate entity
12457 if Is_Type (E) then
12458 if Rep_Item_Too_Early (E, N)
12460 Rep_Item_Too_Late (E, N)
12464 Check_First_Subtype (Arg1);
12467 elsif K = N_Object_Declaration
12468 or else (K = N_Component_Declaration
12469 and then Original_Record_Component (E) = E)
12471 if Rep_Item_Too_Late (E, N) then
12477 ("inappropriate entity for pragma%", Arg1);
12480 Independence_Checks.Append ((N, E));
12483 ----------------------------
12484 -- Independent_Components --
12485 ----------------------------
12487 -- pragma Atomic_Components (array_LOCAL_NAME);
12489 -- This processing is shared by Volatile_Components
12491 when Pragma_Independent_Components => Independent_Components : declare
12498 Check_Ada_83_Warning;
12500 Check_No_Identifiers;
12501 Check_Arg_Count (1);
12502 Check_Arg_Is_Local_Name (Arg1);
12503 E_Id := Get_Pragma_Arg (Arg1);
12505 if Etype (E_Id) = Any_Type then
12509 E := Entity (E_Id);
12511 -- Check duplicate before we chain ourselves!
12513 Check_Duplicate_Pragma (E);
12515 -- Check appropriate entity
12517 if Rep_Item_Too_Early (E, N)
12519 Rep_Item_Too_Late (E, N)
12524 D := Declaration_Node (E);
12527 if K = N_Full_Type_Declaration
12528 and then (Is_Array_Type (E) or else Is_Record_Type (E))
12530 Independence_Checks.Append ((N, E));
12531 Set_Has_Independent_Components (Base_Type (E));
12533 elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12534 and then Nkind (D) = N_Object_Declaration
12535 and then Nkind (Object_Definition (D)) =
12536 N_Constrained_Array_Definition
12538 Independence_Checks.Append ((N, E));
12539 Set_Has_Independent_Components (E);
12542 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12544 end Independent_Components;
12546 ------------------------
12547 -- Initialize_Scalars --
12548 ------------------------
12550 -- pragma Initialize_Scalars;
12552 when Pragma_Initialize_Scalars =>
12554 Check_Arg_Count (0);
12555 Check_Valid_Configuration_Pragma;
12556 Check_Restriction (No_Initialize_Scalars, N);
12558 -- Initialize_Scalars creates false positives in CodePeer, and
12559 -- incorrect negative results in SPARK mode, so ignore this pragma
12562 if not Restriction_Active (No_Initialize_Scalars)
12563 and then not (CodePeer_Mode or SPARK_Mode)
12565 Init_Or_Norm_Scalars := True;
12566 Initialize_Scalars := True;
12573 -- pragma Inline ( NAME {, NAME} );
12575 when Pragma_Inline =>
12577 -- Inline status is Enabled if inlining option is active
12579 if Inline_Active then
12580 Process_Inline (Enabled);
12582 Process_Inline (Disabled);
12585 -------------------
12586 -- Inline_Always --
12587 -------------------
12589 -- pragma Inline_Always ( NAME {, NAME} );
12591 when Pragma_Inline_Always =>
12594 -- Pragma always active unless in CodePeer or SPARK mode, since
12595 -- this causes walk order issues.
12597 if not (CodePeer_Mode or SPARK_Mode) then
12598 Process_Inline (Enabled);
12601 --------------------
12602 -- Inline_Generic --
12603 --------------------
12605 -- pragma Inline_Generic (NAME {, NAME});
12607 when Pragma_Inline_Generic =>
12609 Process_Generic_List;
12611 ----------------------
12612 -- Inspection_Point --
12613 ----------------------
12615 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
12617 when Pragma_Inspection_Point => Inspection_Point : declare
12622 if Arg_Count > 0 then
12625 Exp := Get_Pragma_Arg (Arg);
12628 if not Is_Entity_Name (Exp)
12629 or else not Is_Object (Entity (Exp))
12631 Error_Pragma_Arg ("object name required", Arg);
12635 exit when No (Arg);
12638 end Inspection_Point;
12644 -- pragma Interface (
12645 -- [ Convention =>] convention_IDENTIFIER,
12646 -- [ Entity =>] local_NAME
12647 -- [, [External_Name =>] static_string_EXPRESSION ]
12648 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12650 when Pragma_Interface =>
12655 Name_External_Name,
12657 Check_At_Least_N_Arguments (2);
12658 Check_At_Most_N_Arguments (4);
12659 Process_Import_Or_Interface;
12661 -- In Ada 2005, the permission to use Interface (a reserved word)
12662 -- as a pragma name is considered an obsolescent feature, and this
12663 -- pragma was already obsolescent in Ada 95.
12665 if Ada_Version >= Ada_95 then
12667 (No_Obsolescent_Features, Pragma_Identifier (N));
12669 if Warn_On_Obsolescent_Feature then
12671 ("pragma Interface is an obsolescent feature?j?", N);
12673 ("|use pragma Import instead?j?", N);
12677 --------------------
12678 -- Interface_Name --
12679 --------------------
12681 -- pragma Interface_Name (
12682 -- [ Entity =>] local_NAME
12683 -- [,[External_Name =>] static_string_EXPRESSION ]
12684 -- [,[Link_Name =>] static_string_EXPRESSION ]);
12686 when Pragma_Interface_Name => Interface_Name : declare
12688 Def_Id : Entity_Id;
12689 Hom_Id : Entity_Id;
12695 ((Name_Entity, Name_External_Name, Name_Link_Name));
12696 Check_At_Least_N_Arguments (2);
12697 Check_At_Most_N_Arguments (3);
12698 Id := Get_Pragma_Arg (Arg1);
12701 -- This is obsolete from Ada 95 on, but it is an implementation
12702 -- defined pragma, so we do not consider that it violates the
12703 -- restriction (No_Obsolescent_Features).
12705 if Ada_Version >= Ada_95 then
12706 if Warn_On_Obsolescent_Feature then
12708 ("pragma Interface_Name is an obsolescent feature?j?", N);
12710 ("|use pragma Import instead?j?", N);
12714 if not Is_Entity_Name (Id) then
12716 ("first argument for pragma% must be entity name", Arg1);
12717 elsif Etype (Id) = Any_Type then
12720 Def_Id := Entity (Id);
12723 -- Special DEC-compatible processing for the object case, forces
12724 -- object to be imported.
12726 if Ekind (Def_Id) = E_Variable then
12727 Kill_Size_Check_Code (Def_Id);
12728 Note_Possible_Modification (Id, Sure => False);
12730 -- Initialization is not allowed for imported variable
12732 if Present (Expression (Parent (Def_Id)))
12733 and then Comes_From_Source (Expression (Parent (Def_Id)))
12735 Error_Msg_Sloc := Sloc (Def_Id);
12737 ("no initialization allowed for declaration of& #",
12741 -- For compatibility, support VADS usage of providing both
12742 -- pragmas Interface and Interface_Name to obtain the effect
12743 -- of a single Import pragma.
12745 if Is_Imported (Def_Id)
12746 and then Present (First_Rep_Item (Def_Id))
12747 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
12749 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
12753 Set_Imported (Def_Id);
12756 Set_Is_Public (Def_Id);
12757 Process_Interface_Name (Def_Id, Arg2, Arg3);
12760 -- Otherwise must be subprogram
12762 elsif not Is_Subprogram (Def_Id) then
12764 ("argument of pragma% is not subprogram", Arg1);
12767 Check_At_Most_N_Arguments (3);
12771 -- Loop through homonyms
12774 Def_Id := Get_Base_Subprogram (Hom_Id);
12776 if Is_Imported (Def_Id) then
12777 Process_Interface_Name (Def_Id, Arg2, Arg3);
12781 exit when From_Aspect_Specification (N);
12782 Hom_Id := Homonym (Hom_Id);
12784 exit when No (Hom_Id)
12785 or else Scope (Hom_Id) /= Current_Scope;
12790 ("argument of pragma% is not imported subprogram",
12794 end Interface_Name;
12796 -----------------------
12797 -- Interrupt_Handler --
12798 -----------------------
12800 -- pragma Interrupt_Handler (handler_NAME);
12802 when Pragma_Interrupt_Handler =>
12803 Check_Ada_83_Warning;
12804 Check_Arg_Count (1);
12805 Check_No_Identifiers;
12807 if No_Run_Time_Mode then
12808 Error_Msg_CRT ("Interrupt_Handler pragma", N);
12810 Check_Interrupt_Or_Attach_Handler;
12811 Process_Interrupt_Or_Attach_Handler;
12814 ------------------------
12815 -- Interrupt_Priority --
12816 ------------------------
12818 -- pragma Interrupt_Priority [(EXPRESSION)];
12820 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
12821 P : constant Node_Id := Parent (N);
12826 Check_Ada_83_Warning;
12828 if Arg_Count /= 0 then
12829 Arg := Get_Pragma_Arg (Arg1);
12830 Check_Arg_Count (1);
12831 Check_No_Identifiers;
12833 -- The expression must be analyzed in the special manner
12834 -- described in "Handling of Default and Per-Object
12835 -- Expressions" in sem.ads.
12837 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
12840 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
12845 Ent := Defining_Identifier (Parent (P));
12847 -- Check duplicate pragma before we chain the pragma in the Rep
12848 -- Item chain of Ent.
12850 Check_Duplicate_Pragma (Ent);
12851 Record_Rep_Item (Ent, N);
12853 end Interrupt_Priority;
12855 ---------------------
12856 -- Interrupt_State --
12857 ---------------------
12859 -- pragma Interrupt_State (
12860 -- [Name =>] INTERRUPT_ID,
12861 -- [State =>] INTERRUPT_STATE);
12863 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
12864 -- INTERRUPT_STATE => System | Runtime | User
12866 -- Note: if the interrupt id is given as an identifier, then it must
12867 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
12868 -- given as a static integer expression which must be in the range of
12869 -- Ada.Interrupts.Interrupt_ID.
12871 when Pragma_Interrupt_State => Interrupt_State : declare
12873 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
12874 -- This is the entity Ada.Interrupts.Interrupt_ID;
12876 State_Type : Character;
12877 -- Set to 's'/'r'/'u' for System/Runtime/User
12880 -- Index to entry in Interrupt_States table
12883 -- Value of interrupt
12885 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
12886 -- The first argument to the pragma
12888 Int_Ent : Entity_Id;
12889 -- Interrupt entity in Ada.Interrupts.Names
12893 Check_Arg_Order ((Name_Name, Name_State));
12894 Check_Arg_Count (2);
12896 Check_Optional_Identifier (Arg1, Name_Name);
12897 Check_Optional_Identifier (Arg2, Name_State);
12898 Check_Arg_Is_Identifier (Arg2);
12900 -- First argument is identifier
12902 if Nkind (Arg1X) = N_Identifier then
12904 -- Search list of names in Ada.Interrupts.Names
12906 Int_Ent := First_Entity (RTE (RE_Names));
12908 if No (Int_Ent) then
12909 Error_Pragma_Arg ("invalid interrupt name", Arg1);
12911 elsif Chars (Int_Ent) = Chars (Arg1X) then
12912 Int_Val := Expr_Value (Constant_Value (Int_Ent));
12916 Next_Entity (Int_Ent);
12919 -- First argument is not an identifier, so it must be a static
12920 -- expression of type Ada.Interrupts.Interrupt_ID.
12923 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12924 Int_Val := Expr_Value (Arg1X);
12926 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
12928 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
12931 ("value not in range of type "
12932 & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
12938 case Chars (Get_Pragma_Arg (Arg2)) is
12939 when Name_Runtime => State_Type := 'r';
12940 when Name_System => State_Type := 's';
12941 when Name_User => State_Type := 'u';
12944 Error_Pragma_Arg ("invalid interrupt state", Arg2);
12947 -- Check if entry is already stored
12949 IST_Num := Interrupt_States.First;
12951 -- If entry not found, add it
12953 if IST_Num > Interrupt_States.Last then
12954 Interrupt_States.Append
12955 ((Interrupt_Number => UI_To_Int (Int_Val),
12956 Interrupt_State => State_Type,
12957 Pragma_Loc => Loc));
12960 -- Case of entry for the same entry
12962 elsif Int_Val = Interrupt_States.Table (IST_Num).
12965 -- If state matches, done, no need to make redundant entry
12968 State_Type = Interrupt_States.Table (IST_Num).
12971 -- Otherwise if state does not match, error
12974 Interrupt_States.Table (IST_Num).Pragma_Loc;
12976 ("state conflicts with that given #", Arg2);
12980 IST_Num := IST_Num + 1;
12982 end Interrupt_State;
12988 -- pragma Invariant
12989 -- ([Entity =>] type_LOCAL_NAME,
12990 -- [Check =>] EXPRESSION
12991 -- [,[Message =>] String_Expression]);
12993 when Pragma_Invariant => Invariant : declare
12999 pragma Unreferenced (Discard);
13003 Check_At_Least_N_Arguments (2);
13004 Check_At_Most_N_Arguments (3);
13005 Check_Optional_Identifier (Arg1, Name_Entity);
13006 Check_Optional_Identifier (Arg2, Name_Check);
13008 if Arg_Count = 3 then
13009 Check_Optional_Identifier (Arg3, Name_Message);
13010 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
13013 Check_Arg_Is_Local_Name (Arg1);
13015 Type_Id := Get_Pragma_Arg (Arg1);
13016 Find_Type (Type_Id);
13017 Typ := Entity (Type_Id);
13019 if Typ = Any_Type then
13022 -- An invariant must apply to a private type, or appear in the
13023 -- private part of a package spec and apply to a completion.
13025 elsif Ekind_In (Typ, E_Private_Type,
13026 E_Record_Type_With_Private,
13027 E_Limited_Private_Type)
13031 elsif In_Private_Part (Current_Scope)
13032 and then Has_Private_Declaration (Typ)
13036 elsif In_Private_Part (Current_Scope) then
13038 ("pragma% only allowed for private type declared in "
13039 & "visible part", Arg1);
13043 ("pragma% only allowed for private type", Arg1);
13046 -- Note that the type has at least one invariant, and also that
13047 -- it has inheritable invariants if we have Invariant'Class
13048 -- or Type_Invariant'Class. Build the corresponding invariant
13049 -- procedure declaration, so that calls to it can be generated
13050 -- before the body is built (e.g. within an expression function).
13052 PDecl := Build_Invariant_Procedure_Declaration (Typ);
13054 Insert_After (N, PDecl);
13057 if Class_Present (N) then
13058 Set_Has_Inheritable_Invariants (Typ);
13061 -- The remaining processing is simply to link the pragma on to
13062 -- the rep item chain, for processing when the type is frozen.
13063 -- This is accomplished by a call to Rep_Item_Too_Late.
13065 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13068 ----------------------
13069 -- Java_Constructor --
13070 ----------------------
13072 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
13074 -- Also handles pragma CIL_Constructor
13076 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
13077 Java_Constructor : declare
13078 Convention : Convention_Id;
13079 Def_Id : Entity_Id;
13080 Hom_Id : Entity_Id;
13082 This_Formal : Entity_Id;
13086 Check_Arg_Count (1);
13087 Check_Optional_Identifier (Arg1, Name_Entity);
13088 Check_Arg_Is_Local_Name (Arg1);
13090 Id := Get_Pragma_Arg (Arg1);
13091 Find_Program_Unit_Name (Id);
13093 -- If we did not find the name, we are done
13095 if Etype (Id) = Any_Type then
13099 -- Check wrong use of pragma in wrong VM target
13101 if VM_Target = No_VM then
13104 elsif VM_Target = CLI_Target
13105 and then Prag_Id = Pragma_Java_Constructor
13107 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
13109 elsif VM_Target = JVM_Target
13110 and then Prag_Id = Pragma_CIL_Constructor
13112 Error_Pragma ("must use pragma 'Java_'Constructor");
13116 when Pragma_CIL_Constructor => Convention := Convention_CIL;
13117 when Pragma_Java_Constructor => Convention := Convention_Java;
13118 when others => null;
13121 Hom_Id := Entity (Id);
13123 -- Loop through homonyms
13126 Def_Id := Get_Base_Subprogram (Hom_Id);
13128 -- The constructor is required to be a function
13130 if Ekind (Def_Id) /= E_Function then
13131 if VM_Target = JVM_Target then
13133 ("pragma% requires function returning a 'Java access "
13137 ("pragma% requires function returning a 'C'I'L access "
13142 -- Check arguments: For tagged type the first formal must be
13143 -- named "this" and its type must be a named access type
13144 -- designating a class-wide tagged type that has convention
13145 -- CIL/Java. The first formal must also have a null default
13146 -- value. For example:
13148 -- type Typ is tagged ...
13149 -- type Ref is access all Typ;
13150 -- pragma Convention (CIL, Typ);
13152 -- function New_Typ (This : Ref) return Ref;
13153 -- function New_Typ (This : Ref; I : Integer) return Ref;
13154 -- pragma Cil_Constructor (New_Typ);
13156 -- Reason: The first formal must NOT be a primitive of the
13159 -- This rule also applies to constructors of delegates used
13160 -- to interface with standard target libraries. For example:
13162 -- type Delegate is access procedure ...
13163 -- pragma Import (CIL, Delegate, ...);
13165 -- function new_Delegate
13166 -- (This : Delegate := null; ... ) return Delegate;
13168 -- For value-types this rule does not apply.
13170 if not Is_Value_Type (Etype (Def_Id)) then
13171 if No (First_Formal (Def_Id)) then
13172 Error_Msg_Name_1 := Pname;
13173 Error_Msg_N ("% function must have parameters", Def_Id);
13177 -- In the JRE library we have several occurrences in which
13178 -- the "this" parameter is not the first formal.
13180 This_Formal := First_Formal (Def_Id);
13182 -- In the JRE library we have several occurrences in which
13183 -- the "this" parameter is not the first formal. Search for
13186 if VM_Target = JVM_Target then
13187 while Present (This_Formal)
13188 and then Get_Name_String (Chars (This_Formal)) /= "this"
13190 Next_Formal (This_Formal);
13193 if No (This_Formal) then
13194 This_Formal := First_Formal (Def_Id);
13198 -- Warning: The first parameter should be named "this".
13199 -- We temporarily allow it because we have the following
13200 -- case in the Java runtime (file s-osinte.ads) ???
13202 -- function new_Thread
13203 -- (Self_Id : System.Address) return Thread_Id;
13204 -- pragma Java_Constructor (new_Thread);
13206 if VM_Target = JVM_Target
13207 and then Get_Name_String (Chars (First_Formal (Def_Id)))
13209 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
13213 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
13214 Error_Msg_Name_1 := Pname;
13216 ("first formal of % function must be named `this`",
13217 Parent (This_Formal));
13219 elsif not Is_Access_Type (Etype (This_Formal)) then
13220 Error_Msg_Name_1 := Pname;
13222 ("first formal of % function must be an access type",
13223 Parameter_Type (Parent (This_Formal)));
13225 -- For delegates the type of the first formal must be a
13226 -- named access-to-subprogram type (see previous example)
13228 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
13229 and then Ekind (Etype (This_Formal))
13230 /= E_Access_Subprogram_Type
13232 Error_Msg_Name_1 := Pname;
13234 ("first formal of % function must be a named access "
13235 & "to subprogram type",
13236 Parameter_Type (Parent (This_Formal)));
13238 -- Warning: We should reject anonymous access types because
13239 -- the constructor must not be handled as a primitive of the
13240 -- tagged type. We temporarily allow it because this profile
13241 -- is currently generated by cil2ada???
13243 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
13244 and then not Ekind_In (Etype (This_Formal),
13246 E_General_Access_Type,
13247 E_Anonymous_Access_Type)
13249 Error_Msg_Name_1 := Pname;
13251 ("first formal of % function must be a named access "
13252 & "type", Parameter_Type (Parent (This_Formal)));
13254 elsif Atree.Convention
13255 (Designated_Type (Etype (This_Formal))) /= Convention
13257 Error_Msg_Name_1 := Pname;
13259 if Convention = Convention_Java then
13261 ("pragma% requires convention 'Cil in designated "
13262 & "type", Parameter_Type (Parent (This_Formal)));
13265 ("pragma% requires convention 'Java in designated "
13266 & "type", Parameter_Type (Parent (This_Formal)));
13269 elsif No (Expression (Parent (This_Formal)))
13270 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
13272 Error_Msg_Name_1 := Pname;
13274 ("pragma% requires first formal with default `null`",
13275 Parameter_Type (Parent (This_Formal)));
13279 -- Check result type: the constructor must be a function
13281 -- * a value type (only allowed in the CIL compiler)
13282 -- * an access-to-subprogram type with convention Java/CIL
13283 -- * an access-type designating a type that has convention
13286 if Is_Value_Type (Etype (Def_Id)) then
13289 -- Access-to-subprogram type with convention Java/CIL
13291 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
13292 if Atree.Convention (Etype (Def_Id)) /= Convention then
13293 if Convention = Convention_Java then
13295 ("pragma% requires function returning a 'Java "
13296 & "access type", Arg1);
13298 pragma Assert (Convention = Convention_CIL);
13300 ("pragma% requires function returning a 'C'I'L "
13301 & "access type", Arg1);
13305 elsif Ekind (Etype (Def_Id)) in Access_Kind then
13306 if not Ekind_In (Etype (Def_Id), E_Access_Type,
13307 E_General_Access_Type)
13310 (Designated_Type (Etype (Def_Id))) /= Convention
13312 Error_Msg_Name_1 := Pname;
13314 if Convention = Convention_Java then
13316 ("pragma% requires function returning a named "
13317 & "'Java access type", Arg1);
13320 ("pragma% requires function returning a named "
13321 & "'C'I'L access type", Arg1);
13326 Set_Is_Constructor (Def_Id);
13327 Set_Convention (Def_Id, Convention);
13328 Set_Is_Imported (Def_Id);
13330 exit when From_Aspect_Specification (N);
13331 Hom_Id := Homonym (Hom_Id);
13333 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
13335 end Java_Constructor;
13337 ----------------------
13338 -- Java_Interface --
13339 ----------------------
13341 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
13343 when Pragma_Java_Interface => Java_Interface : declare
13349 Check_Arg_Count (1);
13350 Check_Optional_Identifier (Arg1, Name_Entity);
13351 Check_Arg_Is_Local_Name (Arg1);
13353 Arg := Get_Pragma_Arg (Arg1);
13356 if Etype (Arg) = Any_Type then
13360 if not Is_Entity_Name (Arg)
13361 or else not Is_Type (Entity (Arg))
13363 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
13366 Typ := Underlying_Type (Entity (Arg));
13368 -- For now simply check some of the semantic constraints on the
13369 -- type. This currently leaves out some restrictions on interface
13370 -- types, namely that the parent type must be java.lang.Object.Typ
13371 -- and that all primitives of the type should be declared
13374 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
13376 ("pragma% requires an abstract tagged type", Arg1);
13378 elsif not Has_Discriminants (Typ)
13379 or else Ekind (Etype (First_Discriminant (Typ)))
13380 /= E_Anonymous_Access_Type
13382 not Is_Class_Wide_Type
13383 (Designated_Type (Etype (First_Discriminant (Typ))))
13386 ("type must have a class-wide access discriminant", Arg1);
13388 end Java_Interface;
13394 -- pragma Keep_Names ([On => ] local_NAME);
13396 when Pragma_Keep_Names => Keep_Names : declare
13401 Check_Arg_Count (1);
13402 Check_Optional_Identifier (Arg1, Name_On);
13403 Check_Arg_Is_Local_Name (Arg1);
13405 Arg := Get_Pragma_Arg (Arg1);
13408 if Etype (Arg) = Any_Type then
13412 if not Is_Entity_Name (Arg)
13413 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
13416 ("pragma% requires a local enumeration type", Arg1);
13419 Set_Discard_Names (Entity (Arg), False);
13426 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
13428 when Pragma_License =>
13430 Check_Arg_Count (1);
13431 Check_No_Identifiers;
13432 Check_Valid_Configuration_Pragma;
13433 Check_Arg_Is_Identifier (Arg1);
13436 Sind : constant Source_File_Index :=
13437 Source_Index (Current_Sem_Unit);
13440 case Chars (Get_Pragma_Arg (Arg1)) is
13442 Set_License (Sind, GPL);
13444 when Name_Modified_GPL =>
13445 Set_License (Sind, Modified_GPL);
13447 when Name_Restricted =>
13448 Set_License (Sind, Restricted);
13450 when Name_Unrestricted =>
13451 Set_License (Sind, Unrestricted);
13454 Error_Pragma_Arg ("invalid license name", Arg1);
13462 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
13464 when Pragma_Link_With => Link_With : declare
13470 if Operating_Mode = Generate_Code
13471 and then In_Extended_Main_Source_Unit (N)
13473 Check_At_Least_N_Arguments (1);
13474 Check_No_Identifiers;
13475 Check_Is_In_Decl_Part_Or_Package_Spec;
13476 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13480 while Present (Arg) loop
13481 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13483 -- Store argument, converting sequences of spaces to a
13484 -- single null character (this is one of the differences
13485 -- in processing between Link_With and Linker_Options).
13487 Arg_Store : declare
13488 C : constant Char_Code := Get_Char_Code (' ');
13489 S : constant String_Id :=
13490 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
13491 L : constant Nat := String_Length (S);
13494 procedure Skip_Spaces;
13495 -- Advance F past any spaces
13501 procedure Skip_Spaces is
13503 while F <= L and then Get_String_Char (S, F) = C loop
13508 -- Start of processing for Arg_Store
13511 Skip_Spaces; -- skip leading spaces
13513 -- Loop through characters, changing any embedded
13514 -- sequence of spaces to a single null character (this
13515 -- is how Link_With/Linker_Options differ)
13518 if Get_String_Char (S, F) = C then
13521 Store_String_Char (ASCII.NUL);
13524 Store_String_Char (Get_String_Char (S, F));
13532 if Present (Arg) then
13533 Store_String_Char (ASCII.NUL);
13537 Store_Linker_Option_String (End_String);
13545 -- pragma Linker_Alias (
13546 -- [Entity =>] LOCAL_NAME
13547 -- [Target =>] static_string_EXPRESSION);
13549 when Pragma_Linker_Alias =>
13551 Check_Arg_Order ((Name_Entity, Name_Target));
13552 Check_Arg_Count (2);
13553 Check_Optional_Identifier (Arg1, Name_Entity);
13554 Check_Optional_Identifier (Arg2, Name_Target);
13555 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13556 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13558 -- The only processing required is to link this item on to the
13559 -- list of rep items for the given entity. This is accomplished
13560 -- by the call to Rep_Item_Too_Late (when no error is detected
13561 -- and False is returned).
13563 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13566 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13569 ------------------------
13570 -- Linker_Constructor --
13571 ------------------------
13573 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
13575 -- Code is shared with Linker_Destructor
13577 -----------------------
13578 -- Linker_Destructor --
13579 -----------------------
13581 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
13583 when Pragma_Linker_Constructor |
13584 Pragma_Linker_Destructor =>
13585 Linker_Constructor : declare
13591 Check_Arg_Count (1);
13592 Check_No_Identifiers;
13593 Check_Arg_Is_Local_Name (Arg1);
13594 Arg1_X := Get_Pragma_Arg (Arg1);
13596 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
13598 if not Is_Library_Level_Entity (Proc) then
13600 ("argument for pragma% must be library level entity", Arg1);
13603 -- The only processing required is to link this item on to the
13604 -- list of rep items for the given entity. This is accomplished
13605 -- by the call to Rep_Item_Too_Late (when no error is detected
13606 -- and False is returned).
13608 if Rep_Item_Too_Late (Proc, N) then
13611 Set_Has_Gigi_Rep_Item (Proc);
13613 end Linker_Constructor;
13615 --------------------
13616 -- Linker_Options --
13617 --------------------
13619 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
13621 when Pragma_Linker_Options => Linker_Options : declare
13625 Check_Ada_83_Warning;
13626 Check_No_Identifiers;
13627 Check_Arg_Count (1);
13628 Check_Is_In_Decl_Part_Or_Package_Spec;
13629 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13630 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
13633 while Present (Arg) loop
13634 Check_Arg_Is_Static_Expression (Arg, Standard_String);
13635 Store_String_Char (ASCII.NUL);
13637 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
13641 if Operating_Mode = Generate_Code
13642 and then In_Extended_Main_Source_Unit (N)
13644 Store_Linker_Option_String (End_String);
13646 end Linker_Options;
13648 --------------------
13649 -- Linker_Section --
13650 --------------------
13652 -- pragma Linker_Section (
13653 -- [Entity =>] LOCAL_NAME
13654 -- [Section =>] static_string_EXPRESSION);
13656 when Pragma_Linker_Section =>
13658 Check_Arg_Order ((Name_Entity, Name_Section));
13659 Check_Arg_Count (2);
13660 Check_Optional_Identifier (Arg1, Name_Entity);
13661 Check_Optional_Identifier (Arg2, Name_Section);
13662 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13663 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13665 -- This pragma applies only to objects
13667 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
13668 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
13671 -- The only processing required is to link this item on to the
13672 -- list of rep items for the given entity. This is accomplished
13673 -- by the call to Rep_Item_Too_Late (when no error is detected
13674 -- and False is returned).
13676 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13679 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13686 -- pragma List (On | Off)
13688 -- There is nothing to do here, since we did all the processing for
13689 -- this pragma in Par.Prag (so that it works properly even in syntax
13692 when Pragma_List =>
13699 -- pragma Lock_Free [(Boolean_EXPRESSION)];
13701 when Pragma_Lock_Free => Lock_Free : declare
13702 P : constant Node_Id := Parent (N);
13708 Check_No_Identifiers;
13709 Check_At_Most_N_Arguments (1);
13711 -- Protected definition case
13713 if Nkind (P) = N_Protected_Definition then
13714 Ent := Defining_Identifier (Parent (P));
13718 if Arg_Count = 1 then
13719 Arg := Get_Pragma_Arg (Arg1);
13720 Val := Is_True (Static_Boolean (Arg));
13722 -- No arguments (expression is considered to be True)
13728 -- Check duplicate pragma before we chain the pragma in the Rep
13729 -- Item chain of Ent.
13731 Check_Duplicate_Pragma (Ent);
13732 Record_Rep_Item (Ent, N);
13733 Set_Uses_Lock_Free (Ent, Val);
13735 -- Anything else is incorrect placement
13742 --------------------
13743 -- Locking_Policy --
13744 --------------------
13746 -- pragma Locking_Policy (policy_IDENTIFIER);
13748 when Pragma_Locking_Policy => declare
13749 subtype LP_Range is Name_Id
13750 range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
13755 Check_Ada_83_Warning;
13756 Check_Arg_Count (1);
13757 Check_No_Identifiers;
13758 Check_Arg_Is_Locking_Policy (Arg1);
13759 Check_Valid_Configuration_Pragma;
13760 LP_Val := Chars (Get_Pragma_Arg (Arg1));
13763 when Name_Ceiling_Locking =>
13765 when Name_Inheritance_Locking =>
13767 when Name_Concurrent_Readers_Locking =>
13771 if Locking_Policy /= ' '
13772 and then Locking_Policy /= LP
13774 Error_Msg_Sloc := Locking_Policy_Sloc;
13775 Error_Pragma ("locking policy incompatible with policy#");
13777 -- Set new policy, but always preserve System_Location since we
13778 -- like the error message with the run time name.
13781 Locking_Policy := LP;
13783 if Locking_Policy_Sloc /= System_Location then
13784 Locking_Policy_Sloc := Loc;
13793 -- pragma Long_Float (D_Float | G_Float);
13795 when Pragma_Long_Float => Long_Float : declare
13798 Check_Valid_Configuration_Pragma;
13799 Check_Arg_Count (1);
13800 Check_No_Identifier (Arg1);
13801 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
13803 if not OpenVMS_On_Target then
13804 Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
13809 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
13810 if Opt.Float_Format_Long = 'G' then
13812 ("G_Float previously specified", Arg1);
13814 elsif Current_Sem_Unit /= Main_Unit
13815 and then Opt.Float_Format_Long /= 'D'
13818 ("main unit not compiled with pragma Long_Float (D_Float)",
13819 "\pragma% must be used consistently for whole partition",
13823 Opt.Float_Format_Long := 'D';
13826 -- G_Float case (this is the default, does not need overriding)
13829 if Opt.Float_Format_Long = 'D' then
13830 Error_Pragma ("D_Float previously specified");
13832 elsif Current_Sem_Unit /= Main_Unit
13833 and then Opt.Float_Format_Long /= 'G'
13836 ("main unit not compiled with pragma Long_Float (G_Float)",
13837 "\pragma% must be used consistently for whole partition",
13841 Opt.Float_Format_Long := 'G';
13845 Set_Standard_Fpt_Formats;
13848 -------------------
13849 -- Loop_Optimize --
13850 -------------------
13852 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
13854 -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
13856 when Pragma_Loop_Optimize => Loop_Optimize : declare
13861 Check_At_Least_N_Arguments (1);
13862 Check_No_Identifiers;
13864 Hint := First (Pragma_Argument_Associations (N));
13865 while Present (Hint) loop
13866 Check_Arg_Is_One_Of (Hint,
13867 Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
13871 Check_Loop_Pragma_Placement;
13878 -- pragma Loop_Variant
13879 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
13881 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
13883 -- CHANGE_DIRECTION ::= Increases | Decreases
13885 when Pragma_Loop_Variant => Loop_Variant : declare
13890 Check_At_Least_N_Arguments (1);
13891 Check_Loop_Pragma_Placement;
13893 -- Process all increasing / decreasing expressions
13895 Variant := First (Pragma_Argument_Associations (N));
13896 while Present (Variant) loop
13897 if not Nam_In (Chars (Variant), Name_Decreases,
13900 Error_Pragma_Arg ("wrong change modifier", Variant);
13903 Preanalyze_Assert_Expression
13904 (Expression (Variant), Any_Discrete);
13910 -----------------------
13911 -- Machine_Attribute --
13912 -----------------------
13914 -- pragma Machine_Attribute (
13915 -- [Entity =>] LOCAL_NAME,
13916 -- [Attribute_Name =>] static_string_EXPRESSION
13917 -- [, [Info =>] static_EXPRESSION] );
13919 when Pragma_Machine_Attribute => Machine_Attribute : declare
13920 Def_Id : Entity_Id;
13924 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
13926 if Arg_Count = 3 then
13927 Check_Optional_Identifier (Arg3, Name_Info);
13928 Check_Arg_Is_Static_Expression (Arg3);
13930 Check_Arg_Count (2);
13933 Check_Optional_Identifier (Arg1, Name_Entity);
13934 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
13935 Check_Arg_Is_Local_Name (Arg1);
13936 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13937 Def_Id := Entity (Get_Pragma_Arg (Arg1));
13939 if Is_Access_Type (Def_Id) then
13940 Def_Id := Designated_Type (Def_Id);
13943 if Rep_Item_Too_Early (Def_Id, N) then
13947 Def_Id := Underlying_Type (Def_Id);
13949 -- The only processing required is to link this item on to the
13950 -- list of rep items for the given entity. This is accomplished
13951 -- by the call to Rep_Item_Too_Late (when no error is detected
13952 -- and False is returned).
13954 if Rep_Item_Too_Late (Def_Id, N) then
13957 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13959 end Machine_Attribute;
13966 -- (MAIN_OPTION [, MAIN_OPTION]);
13969 -- [STACK_SIZE =>] static_integer_EXPRESSION
13970 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
13971 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
13973 when Pragma_Main => Main : declare
13974 Args : Args_List (1 .. 3);
13975 Names : constant Name_List (1 .. 3) := (
13977 Name_Task_Stack_Size_Default,
13978 Name_Time_Slicing_Enabled);
13984 Gather_Associations (Names, Args);
13986 for J in 1 .. 2 loop
13987 if Present (Args (J)) then
13988 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13992 if Present (Args (3)) then
13993 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
13997 while Present (Nod) loop
13998 if Nkind (Nod) = N_Pragma
13999 and then Pragma_Name (Nod) = Name_Main
14001 Error_Msg_Name_1 := Pname;
14002 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14013 -- pragma Main_Storage
14014 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
14016 -- MAIN_STORAGE_OPTION ::=
14017 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
14018 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
14020 when Pragma_Main_Storage => Main_Storage : declare
14021 Args : Args_List (1 .. 2);
14022 Names : constant Name_List (1 .. 2) := (
14023 Name_Working_Storage,
14030 Gather_Associations (Names, Args);
14032 for J in 1 .. 2 loop
14033 if Present (Args (J)) then
14034 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
14038 Check_In_Main_Program;
14041 while Present (Nod) loop
14042 if Nkind (Nod) = N_Pragma
14043 and then Pragma_Name (Nod) = Name_Main_Storage
14045 Error_Msg_Name_1 := Pname;
14046 Error_Msg_N ("duplicate pragma% not permitted", Nod);
14057 -- pragma Memory_Size (NUMERIC_LITERAL)
14059 when Pragma_Memory_Size =>
14062 -- Memory size is simply ignored
14064 Check_No_Identifiers;
14065 Check_Arg_Count (1);
14066 Check_Arg_Is_Integer_Literal (Arg1);
14074 -- The only correct use of this pragma is on its own in a file, in
14075 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
14076 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
14077 -- check for a file containing nothing but a No_Body pragma). If we
14078 -- attempt to process it during normal semantics processing, it means
14079 -- it was misplaced.
14081 when Pragma_No_Body =>
14089 -- pragma No_Inline ( NAME {, NAME} );
14091 when Pragma_No_Inline =>
14093 Process_Inline (Suppressed);
14099 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
14101 when Pragma_No_Return => No_Return : declare
14109 Check_At_Least_N_Arguments (1);
14111 -- Loop through arguments of pragma
14114 while Present (Arg) loop
14115 Check_Arg_Is_Local_Name (Arg);
14116 Id := Get_Pragma_Arg (Arg);
14119 if not Is_Entity_Name (Id) then
14120 Error_Pragma_Arg ("entity name required", Arg);
14123 if Etype (Id) = Any_Type then
14127 -- Loop to find matching procedures
14132 and then Scope (E) = Current_Scope
14134 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
14137 -- Set flag on any alias as well
14139 if Is_Overloadable (E) and then Present (Alias (E)) then
14140 Set_No_Return (Alias (E));
14146 exit when From_Aspect_Specification (N);
14151 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
14162 -- pragma No_Run_Time;
14164 -- Note: this pragma is retained for backwards compatibility. See
14165 -- body of Rtsfind for full details on its handling.
14167 when Pragma_No_Run_Time =>
14169 Check_Valid_Configuration_Pragma;
14170 Check_Arg_Count (0);
14172 No_Run_Time_Mode := True;
14173 Configurable_Run_Time_Mode := True;
14175 -- Set Duration to 32 bits if word size is 32
14177 if Ttypes.System_Word_Size = 32 then
14178 Duration_32_Bits_On_Target := True;
14181 -- Set appropriate restrictions
14183 Set_Restriction (No_Finalization, N);
14184 Set_Restriction (No_Exception_Handlers, N);
14185 Set_Restriction (Max_Tasks, N, 0);
14186 Set_Restriction (No_Tasking, N);
14188 ------------------------
14189 -- No_Strict_Aliasing --
14190 ------------------------
14192 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
14194 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
14199 Check_At_Most_N_Arguments (1);
14201 if Arg_Count = 0 then
14202 Check_Valid_Configuration_Pragma;
14203 Opt.No_Strict_Aliasing := True;
14206 Check_Optional_Identifier (Arg2, Name_Entity);
14207 Check_Arg_Is_Local_Name (Arg1);
14208 E_Id := Entity (Get_Pragma_Arg (Arg1));
14210 if E_Id = Any_Type then
14212 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
14213 Error_Pragma_Arg ("pragma% requires access type", Arg1);
14216 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
14218 end No_Strict_Aliasing;
14220 -----------------------
14221 -- Normalize_Scalars --
14222 -----------------------
14224 -- pragma Normalize_Scalars;
14226 when Pragma_Normalize_Scalars =>
14227 Check_Ada_83_Warning;
14228 Check_Arg_Count (0);
14229 Check_Valid_Configuration_Pragma;
14231 -- Normalize_Scalars creates false positives in CodePeer, and
14232 -- incorrect negative results in SPARK mode, so ignore this pragma
14235 if not (CodePeer_Mode or SPARK_Mode) then
14236 Normalize_Scalars := True;
14237 Init_Or_Norm_Scalars := True;
14244 -- pragma Obsolescent;
14246 -- pragma Obsolescent (
14247 -- [Message =>] static_string_EXPRESSION
14248 -- [,[Version =>] Ada_05]]);
14250 -- pragma Obsolescent (
14251 -- [Entity =>] NAME
14252 -- [,[Message =>] static_string_EXPRESSION
14253 -- [,[Version =>] Ada_05]] );
14255 when Pragma_Obsolescent => Obsolescent : declare
14259 procedure Set_Obsolescent (E : Entity_Id);
14260 -- Given an entity Ent, mark it as obsolescent if appropriate
14262 ---------------------
14263 -- Set_Obsolescent --
14264 ---------------------
14266 procedure Set_Obsolescent (E : Entity_Id) is
14275 -- Entity name was given
14277 if Present (Ename) then
14279 -- If entity name matches, we are fine. Save entity in
14280 -- pragma argument, for ASIS use.
14282 if Chars (Ename) = Chars (Ent) then
14283 Set_Entity (Ename, Ent);
14284 Generate_Reference (Ent, Ename);
14286 -- If entity name does not match, only possibility is an
14287 -- enumeration literal from an enumeration type declaration.
14289 elsif Ekind (Ent) /= E_Enumeration_Type then
14291 ("pragma % entity name does not match declaration");
14294 Ent := First_Literal (E);
14298 ("pragma % entity name does not match any "
14299 & "enumeration literal");
14301 elsif Chars (Ent) = Chars (Ename) then
14302 Set_Entity (Ename, Ent);
14303 Generate_Reference (Ent, Ename);
14307 Ent := Next_Literal (Ent);
14313 -- Ent points to entity to be marked
14315 if Arg_Count >= 1 then
14317 -- Deal with static string argument
14319 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14320 S := Strval (Get_Pragma_Arg (Arg1));
14322 for J in 1 .. String_Length (S) loop
14323 if not In_Character_Range (Get_String_Char (S, J)) then
14325 ("pragma% argument does not allow wide characters",
14330 Obsolescent_Warnings.Append
14331 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
14333 -- Check for Ada_05 parameter
14335 if Arg_Count /= 1 then
14336 Check_Arg_Count (2);
14339 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
14342 Check_Arg_Is_Identifier (Argx);
14344 if Chars (Argx) /= Name_Ada_05 then
14345 Error_Msg_Name_2 := Name_Ada_05;
14347 ("only allowed argument for pragma% is %", Argx);
14350 if Ada_Version_Explicit < Ada_2005
14351 or else not Warn_On_Ada_2005_Compatibility
14359 -- Set flag if pragma active
14362 Set_Is_Obsolescent (Ent);
14366 end Set_Obsolescent;
14368 -- Start of processing for pragma Obsolescent
14373 Check_At_Most_N_Arguments (3);
14375 -- See if first argument specifies an entity name
14379 (Chars (Arg1) = Name_Entity
14381 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
14383 N_Operator_Symbol))
14385 Ename := Get_Pragma_Arg (Arg1);
14387 -- Eliminate first argument, so we can share processing
14391 Arg_Count := Arg_Count - 1;
14393 -- No Entity name argument given
14399 if Arg_Count >= 1 then
14400 Check_Optional_Identifier (Arg1, Name_Message);
14402 if Arg_Count = 2 then
14403 Check_Optional_Identifier (Arg2, Name_Version);
14407 -- Get immediately preceding declaration
14410 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
14414 -- Cases where we do not follow anything other than another pragma
14418 -- First case: library level compilation unit declaration with
14419 -- the pragma immediately following the declaration.
14421 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
14423 (Defining_Entity (Unit (Parent (Parent (N)))));
14426 -- Case 2: library unit placement for package
14430 Ent : constant Entity_Id := Find_Lib_Unit_Name;
14432 if Is_Package_Or_Generic_Package (Ent) then
14433 Set_Obsolescent (Ent);
14439 -- Cases where we must follow a declaration
14442 if Nkind (Decl) not in N_Declaration
14443 and then Nkind (Decl) not in N_Later_Decl_Item
14444 and then Nkind (Decl) not in N_Generic_Declaration
14445 and then Nkind (Decl) not in N_Renaming_Declaration
14448 ("pragma% misplaced, "
14449 & "must immediately follow a declaration");
14452 Set_Obsolescent (Defining_Entity (Decl));
14462 -- pragma Optimize (Time | Space | Off);
14464 -- The actual check for optimize is done in Gigi. Note that this
14465 -- pragma does not actually change the optimization setting, it
14466 -- simply checks that it is consistent with the pragma.
14468 when Pragma_Optimize =>
14469 Check_No_Identifiers;
14470 Check_Arg_Count (1);
14471 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
14473 ------------------------
14474 -- Optimize_Alignment --
14475 ------------------------
14477 -- pragma Optimize_Alignment (Time | Space | Off);
14479 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
14481 Check_No_Identifiers;
14482 Check_Arg_Count (1);
14483 Check_Valid_Configuration_Pragma;
14486 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14490 Opt.Optimize_Alignment := 'T';
14492 Opt.Optimize_Alignment := 'S';
14494 Opt.Optimize_Alignment := 'O';
14496 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
14500 -- Set indication that mode is set locally. If we are in fact in a
14501 -- configuration pragma file, this setting is harmless since the
14502 -- switch will get reset anyway at the start of each unit.
14504 Optimize_Alignment_Local := True;
14505 end Optimize_Alignment;
14511 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
14513 when Pragma_Ordered => Ordered : declare
14514 Assoc : constant Node_Id := Arg1;
14520 Check_No_Identifiers;
14521 Check_Arg_Count (1);
14522 Check_Arg_Is_Local_Name (Arg1);
14524 Type_Id := Get_Pragma_Arg (Assoc);
14525 Find_Type (Type_Id);
14526 Typ := Entity (Type_Id);
14528 if Typ = Any_Type then
14531 Typ := Underlying_Type (Typ);
14534 if not Is_Enumeration_Type (Typ) then
14535 Error_Pragma ("pragma% must specify enumeration type");
14538 Check_First_Subtype (Arg1);
14539 Set_Has_Pragma_Ordered (Base_Type (Typ));
14542 -------------------
14543 -- Overflow_Mode --
14544 -------------------
14546 -- pragma Overflow_Mode
14547 -- ([General => ] MODE [, [Assertions => ] MODE]);
14549 -- MODE := STRICT | MINIMIZED | ELIMINATED
14551 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
14552 -- since System.Bignums makes this assumption. This is true of nearly
14553 -- all (all?) targets.
14555 when Pragma_Overflow_Mode => Overflow_Mode : declare
14556 function Get_Overflow_Mode
14558 Arg : Node_Id) return Overflow_Mode_Type;
14559 -- Function to process one pragma argument, Arg. If an identifier
14560 -- is present, it must be Name. Mode type is returned if a valid
14561 -- argument exists, otherwise an error is signalled.
14563 -----------------------
14564 -- Get_Overflow_Mode --
14565 -----------------------
14567 function Get_Overflow_Mode
14569 Arg : Node_Id) return Overflow_Mode_Type
14571 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
14574 Check_Optional_Identifier (Arg, Name);
14575 Check_Arg_Is_Identifier (Argx);
14577 if Chars (Argx) = Name_Strict then
14580 elsif Chars (Argx) = Name_Minimized then
14583 elsif Chars (Argx) = Name_Eliminated then
14584 if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
14586 ("Eliminated not implemented on this target", Argx);
14592 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
14594 end Get_Overflow_Mode;
14596 -- Start of processing for Overflow_Mode
14600 Check_At_Least_N_Arguments (1);
14601 Check_At_Most_N_Arguments (2);
14603 -- Process first argument
14605 Scope_Suppress.Overflow_Mode_General :=
14606 Get_Overflow_Mode (Name_General, Arg1);
14608 -- Case of only one argument
14610 if Arg_Count = 1 then
14611 Scope_Suppress.Overflow_Mode_Assertions :=
14612 Scope_Suppress.Overflow_Mode_General;
14614 -- Case of two arguments present
14617 Scope_Suppress.Overflow_Mode_Assertions :=
14618 Get_Overflow_Mode (Name_Assertions, Arg2);
14622 --------------------------
14623 -- Overriding Renamings --
14624 --------------------------
14626 -- pragma Overriding_Renamings;
14628 when Pragma_Overriding_Renamings =>
14630 Check_Arg_Count (0);
14631 Check_Valid_Configuration_Pragma;
14632 Overriding_Renamings := True;
14638 -- pragma Pack (first_subtype_LOCAL_NAME);
14640 when Pragma_Pack => Pack : declare
14641 Assoc : constant Node_Id := Arg1;
14645 Ignore : Boolean := False;
14648 Check_No_Identifiers;
14649 Check_Arg_Count (1);
14650 Check_Arg_Is_Local_Name (Arg1);
14652 Type_Id := Get_Pragma_Arg (Assoc);
14653 Find_Type (Type_Id);
14654 Typ := Entity (Type_Id);
14657 or else Rep_Item_Too_Early (Typ, N)
14661 Typ := Underlying_Type (Typ);
14664 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
14665 Error_Pragma ("pragma% must specify array or record type");
14668 Check_First_Subtype (Arg1);
14669 Check_Duplicate_Pragma (Typ);
14673 if Is_Array_Type (Typ) then
14674 Ctyp := Component_Type (Typ);
14676 -- Ignore pack that does nothing
14678 if Known_Static_Esize (Ctyp)
14679 and then Known_Static_RM_Size (Ctyp)
14680 and then Esize (Ctyp) = RM_Size (Ctyp)
14681 and then Addressable (Esize (Ctyp))
14686 -- Process OK pragma Pack. Note that if there is a separate
14687 -- component clause present, the Pack will be cancelled. This
14688 -- processing is in Freeze.
14690 if not Rep_Item_Too_Late (Typ, N) then
14692 -- In the context of static code analysis, we do not need
14693 -- complex front-end expansions related to pragma Pack,
14694 -- so disable handling of pragma Pack in these cases.
14696 if CodePeer_Mode or SPARK_Mode then
14699 -- Don't attempt any packing for VM targets. We possibly
14700 -- could deal with some cases of array bit-packing, but we
14701 -- don't bother, since this is not a typical kind of
14702 -- representation in the VM context anyway (and would not
14703 -- for example work nicely with the debugger).
14705 elsif VM_Target /= No_VM then
14706 if not GNAT_Mode then
14708 ("??pragma% ignored in this configuration");
14711 -- Normal case where we do the pack action
14715 Set_Is_Packed (Base_Type (Typ));
14716 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14719 Set_Has_Pragma_Pack (Base_Type (Typ));
14723 -- For record types, the pack is always effective
14725 else pragma Assert (Is_Record_Type (Typ));
14726 if not Rep_Item_Too_Late (Typ, N) then
14728 -- Ignore pack request with warning in VM mode (skip warning
14729 -- if we are compiling GNAT run time library).
14731 if VM_Target /= No_VM then
14732 if not GNAT_Mode then
14734 ("??pragma% ignored in this configuration");
14737 -- Normal case of pack request active
14740 Set_Is_Packed (Base_Type (Typ));
14741 Set_Has_Pragma_Pack (Base_Type (Typ));
14742 Set_Has_Non_Standard_Rep (Base_Type (Typ));
14754 -- There is nothing to do here, since we did all the processing for
14755 -- this pragma in Par.Prag (so that it works properly even in syntax
14758 when Pragma_Page =>
14761 ----------------------------------
14762 -- Partition_Elaboration_Policy --
14763 ----------------------------------
14765 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
14767 when Pragma_Partition_Elaboration_Policy => declare
14768 subtype PEP_Range is Name_Id
14769 range First_Partition_Elaboration_Policy_Name
14770 .. Last_Partition_Elaboration_Policy_Name;
14771 PEP_Val : PEP_Range;
14776 Check_Arg_Count (1);
14777 Check_No_Identifiers;
14778 Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
14779 Check_Valid_Configuration_Pragma;
14780 PEP_Val := Chars (Get_Pragma_Arg (Arg1));
14783 when Name_Concurrent =>
14785 when Name_Sequential =>
14789 if Partition_Elaboration_Policy /= ' '
14790 and then Partition_Elaboration_Policy /= PEP
14792 Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
14794 ("partition elaboration policy incompatible with policy#");
14796 -- Set new policy, but always preserve System_Location since we
14797 -- like the error message with the run time name.
14800 Partition_Elaboration_Policy := PEP;
14802 if Partition_Elaboration_Policy_Sloc /= System_Location then
14803 Partition_Elaboration_Policy_Sloc := Loc;
14812 -- pragma Passive [(PASSIVE_FORM)];
14814 -- PASSIVE_FORM ::= Semaphore | No
14816 when Pragma_Passive =>
14819 if Nkind (Parent (N)) /= N_Task_Definition then
14820 Error_Pragma ("pragma% must be within task definition");
14823 if Arg_Count /= 0 then
14824 Check_Arg_Count (1);
14825 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
14828 ----------------------------------
14829 -- Preelaborable_Initialization --
14830 ----------------------------------
14832 -- pragma Preelaborable_Initialization (DIRECT_NAME);
14834 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
14839 Check_Arg_Count (1);
14840 Check_No_Identifiers;
14841 Check_Arg_Is_Identifier (Arg1);
14842 Check_Arg_Is_Local_Name (Arg1);
14843 Check_First_Subtype (Arg1);
14844 Ent := Entity (Get_Pragma_Arg (Arg1));
14846 -- The pragma may come from an aspect on a private declaration,
14847 -- even if the freeze point at which this is analyzed in the
14848 -- private part after the full view.
14850 if Has_Private_Declaration (Ent)
14851 and then From_Aspect_Specification (N)
14855 elsif Is_Private_Type (Ent)
14856 or else Is_Protected_Type (Ent)
14857 or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
14863 ("pragma % can only be applied to private, formal derived or "
14864 & "protected type",
14868 -- Give an error if the pragma is applied to a protected type that
14869 -- does not qualify (due to having entries, or due to components
14870 -- that do not qualify).
14872 if Is_Protected_Type (Ent)
14873 and then not Has_Preelaborable_Initialization (Ent)
14876 ("protected type & does not have preelaborable "
14877 & "initialization", Ent);
14879 -- Otherwise mark the type as definitely having preelaborable
14883 Set_Known_To_Have_Preelab_Init (Ent);
14886 if Has_Pragma_Preelab_Init (Ent)
14887 and then Warn_On_Redundant_Constructs
14889 Error_Pragma ("?r?duplicate pragma%!");
14891 Set_Has_Pragma_Preelab_Init (Ent);
14895 --------------------
14896 -- Persistent_BSS --
14897 --------------------
14899 -- pragma Persistent_BSS [(object_NAME)];
14901 when Pragma_Persistent_BSS => Persistent_BSS : declare
14908 Check_At_Most_N_Arguments (1);
14910 -- Case of application to specific object (one argument)
14912 if Arg_Count = 1 then
14913 Check_Arg_Is_Library_Level_Local_Name (Arg1);
14915 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
14917 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
14920 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
14923 Ent := Entity (Get_Pragma_Arg (Arg1));
14924 Decl := Parent (Ent);
14926 -- Check for duplication before inserting in list of
14927 -- representation items.
14929 Check_Duplicate_Pragma (Ent);
14931 if Rep_Item_Too_Late (Ent, N) then
14935 if Present (Expression (Decl)) then
14937 ("object for pragma% cannot have initialization", Arg1);
14940 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
14942 ("object type for pragma% is not potentially persistent",
14947 Make_Linker_Section_Pragma
14948 (Ent, Sloc (N), ".persistent.bss");
14949 Insert_After (N, Prag);
14952 -- Case of use as configuration pragma with no arguments
14955 Check_Valid_Configuration_Pragma;
14956 Persistent_BSS_Mode := True;
14958 end Persistent_BSS;
14964 -- pragma Polling (ON | OFF);
14966 when Pragma_Polling =>
14968 Check_Arg_Count (1);
14969 Check_No_Identifiers;
14970 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14971 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
14973 -------------------
14974 -- Postcondition --
14975 -------------------
14977 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
14978 -- [,[Message =>] String_EXPRESSION]);
14980 when Pragma_Postcondition => Postcondition : declare
14985 Check_At_Least_N_Arguments (1);
14986 Check_At_Most_N_Arguments (2);
14987 Check_Optional_Identifier (Arg1, Name_Check);
14989 -- Verify the proper placement of the pragma. The remainder of the
14990 -- processing is found in Sem_Ch6/Sem_Ch7.
14992 Check_Precondition_Postcondition (In_Body);
14994 -- When the pragma is a source construct appearing inside a body,
14995 -- preanalyze the boolean_expression to detect illegal forward
14999 -- pragma Postcondition (X'Old ...);
15002 if Comes_From_Source (N) and then In_Body then
15003 Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
15011 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
15012 -- [,[Message =>] String_EXPRESSION]);
15014 when Pragma_Precondition => Precondition : declare
15019 Check_At_Least_N_Arguments (1);
15020 Check_At_Most_N_Arguments (2);
15021 Check_Optional_Identifier (Arg1, Name_Check);
15022 Check_Precondition_Postcondition (In_Body);
15024 -- If in spec, nothing more to do. If in body, then we convert the
15025 -- pragma to an equivalent pragam Check. Note we do this whether
15026 -- or not precondition checks are enabled. That works fine since
15027 -- pragma Check will do this check, and will also analyze the
15028 -- condition itself in the proper context.
15030 -- The form of the pragma Check is either:
15032 -- pragma Check (Precondition, cond [, msg])
15034 -- pragma Check (Pre, cond [, msg])
15036 -- We use the Pre form if this pragma derived from a Pre aspect.
15037 -- This is needed to make sure that the right set of Policy
15038 -- pragmas are checked.
15043 Chars => Name_Check,
15044 Pragma_Argument_Associations => New_List (
15045 Make_Pragma_Argument_Association (Loc,
15046 Expression => Make_Identifier (Loc, Pname)),
15048 Make_Pragma_Argument_Association (Sloc (Arg1),
15049 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
15051 if Arg_Count = 2 then
15052 Append_To (Pragma_Argument_Associations (N),
15053 Make_Pragma_Argument_Association (Sloc (Arg2),
15054 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
15065 -- pragma Predicate
15066 -- ([Entity =>] type_LOCAL_NAME,
15067 -- [Check =>] boolean_EXPRESSION);
15069 when Pragma_Predicate => Predicate : declare
15074 pragma Unreferenced (Discard);
15078 Check_Arg_Count (2);
15079 Check_Optional_Identifier (Arg1, Name_Entity);
15080 Check_Optional_Identifier (Arg2, Name_Check);
15082 Check_Arg_Is_Local_Name (Arg1);
15084 Type_Id := Get_Pragma_Arg (Arg1);
15085 Find_Type (Type_Id);
15086 Typ := Entity (Type_Id);
15088 if Typ = Any_Type then
15092 -- The remaining processing is simply to link the pragma on to
15093 -- the rep item chain, for processing when the type is frozen.
15094 -- This is accomplished by a call to Rep_Item_Too_Late. We also
15095 -- mark the type as having predicates.
15097 Set_Has_Predicates (Typ);
15098 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15105 -- pragma Preelaborate [(library_unit_NAME)];
15107 -- Set the flag Is_Preelaborated of program unit name entity
15109 when Pragma_Preelaborate => Preelaborate : declare
15110 Pa : constant Node_Id := Parent (N);
15111 Pk : constant Node_Kind := Nkind (Pa);
15115 Check_Ada_83_Warning;
15116 Check_Valid_Library_Unit_Pragma;
15118 if Nkind (N) = N_Null_Statement then
15122 Ent := Find_Lib_Unit_Name;
15123 Check_Duplicate_Pragma (Ent);
15125 -- This filters out pragmas inside generic parent then
15126 -- show up inside instantiation
15129 and then not (Pk = N_Package_Specification
15130 and then Present (Generic_Parent (Pa)))
15132 if not Debug_Flag_U then
15133 Set_Is_Preelaborated (Ent);
15134 Set_Suppress_Elaboration_Warnings (Ent);
15139 ---------------------
15140 -- Preelaborate_05 --
15141 ---------------------
15143 -- pragma Preelaborate_05 [(library_unit_NAME)];
15145 -- This pragma is useable only in GNAT_Mode, where it is used like
15146 -- pragma Preelaborate but it is only effective in Ada 2005 mode
15147 -- (otherwise it is ignored). This is used to implement AI-362 which
15148 -- recategorizes some run-time packages in Ada 2005 mode.
15150 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
15155 Check_Valid_Library_Unit_Pragma;
15157 if not GNAT_Mode then
15158 Error_Pragma ("pragma% only available in GNAT mode");
15161 if Nkind (N) = N_Null_Statement then
15165 -- This is one of the few cases where we need to test the value of
15166 -- Ada_Version_Explicit rather than Ada_Version (which is always
15167 -- set to Ada_2012 in a predefined unit), we need to know the
15168 -- explicit version set to know if this pragma is active.
15170 if Ada_Version_Explicit >= Ada_2005 then
15171 Ent := Find_Lib_Unit_Name;
15172 Set_Is_Preelaborated (Ent);
15173 Set_Suppress_Elaboration_Warnings (Ent);
15175 end Preelaborate_05;
15181 -- pragma Priority (EXPRESSION);
15183 when Pragma_Priority => Priority : declare
15184 P : constant Node_Id := Parent (N);
15189 Check_No_Identifiers;
15190 Check_Arg_Count (1);
15194 if Nkind (P) = N_Subprogram_Body then
15195 Check_In_Main_Program;
15197 Ent := Defining_Unit_Name (Specification (P));
15199 if Nkind (Ent) = N_Defining_Program_Unit_Name then
15200 Ent := Defining_Identifier (Ent);
15203 Arg := Get_Pragma_Arg (Arg1);
15204 Analyze_And_Resolve (Arg, Standard_Integer);
15208 if not Is_Static_Expression (Arg) then
15209 Flag_Non_Static_Expr
15210 ("main subprogram priority is not static!", Arg);
15213 -- If constraint error, then we already signalled an error
15215 elsif Raises_Constraint_Error (Arg) then
15218 -- Otherwise check in range
15222 Val : constant Uint := Expr_Value (Arg);
15226 or else Val > Expr_Value (Expression
15227 (Parent (RTE (RE_Max_Priority))))
15230 ("main subprogram priority is out of range", Arg1);
15236 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
15238 -- Load an arbitrary entity from System.Tasking to make sure
15239 -- this package is implicitly with'ed, since we need to have
15240 -- the tasking run-time active for the pragma Priority to have
15244 Discard : Entity_Id;
15245 pragma Warnings (Off, Discard);
15247 Discard := RTE (RE_Task_List);
15250 -- Task or Protected, must be of type Integer
15252 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
15253 Arg := Get_Pragma_Arg (Arg1);
15254 Ent := Defining_Identifier (Parent (P));
15256 -- The expression must be analyzed in the special manner
15257 -- described in "Handling of Default and Per-Object
15258 -- Expressions" in sem.ads.
15260 Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
15262 if not Is_Static_Expression (Arg) then
15263 Check_Restriction (Static_Priorities, Arg);
15266 -- Anything else is incorrect
15272 -- Check duplicate pragma before we chain the pragma in the Rep
15273 -- Item chain of Ent.
15275 Check_Duplicate_Pragma (Ent);
15276 Record_Rep_Item (Ent, N);
15279 -----------------------------------
15280 -- Priority_Specific_Dispatching --
15281 -----------------------------------
15283 -- pragma Priority_Specific_Dispatching (
15284 -- policy_IDENTIFIER,
15285 -- first_priority_EXPRESSION,
15286 -- last_priority_EXPRESSION);
15288 when Pragma_Priority_Specific_Dispatching =>
15289 Priority_Specific_Dispatching : declare
15290 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
15291 -- This is the entity System.Any_Priority;
15294 Lower_Bound : Node_Id;
15295 Upper_Bound : Node_Id;
15301 Check_Arg_Count (3);
15302 Check_No_Identifiers;
15303 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15304 Check_Valid_Configuration_Pragma;
15305 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15306 DP := Fold_Upper (Name_Buffer (1));
15308 Lower_Bound := Get_Pragma_Arg (Arg2);
15309 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
15310 Lower_Val := Expr_Value (Lower_Bound);
15312 Upper_Bound := Get_Pragma_Arg (Arg3);
15313 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
15314 Upper_Val := Expr_Value (Upper_Bound);
15316 -- It is not allowed to use Task_Dispatching_Policy and
15317 -- Priority_Specific_Dispatching in the same partition.
15319 if Task_Dispatching_Policy /= ' ' then
15320 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15322 ("pragma% incompatible with Task_Dispatching_Policy#");
15324 -- Check lower bound in range
15326 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
15328 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
15331 ("first_priority is out of range", Arg2);
15333 -- Check upper bound in range
15335 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
15337 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
15340 ("last_priority is out of range", Arg3);
15342 -- Check that the priority range is valid
15344 elsif Lower_Val > Upper_Val then
15346 ("last_priority_expression must be greater than or equal to "
15347 & "first_priority_expression");
15349 -- Store the new policy, but always preserve System_Location since
15350 -- we like the error message with the run-time name.
15353 -- Check overlapping in the priority ranges specified in other
15354 -- Priority_Specific_Dispatching pragmas within the same
15355 -- partition. We can only check those we know about!
15358 Specific_Dispatching.First .. Specific_Dispatching.Last
15360 if Specific_Dispatching.Table (J).First_Priority in
15361 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15362 or else Specific_Dispatching.Table (J).Last_Priority in
15363 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15366 Specific_Dispatching.Table (J).Pragma_Loc;
15368 ("priority range overlaps with "
15369 & "Priority_Specific_Dispatching#");
15373 -- The use of Priority_Specific_Dispatching is incompatible
15374 -- with Task_Dispatching_Policy.
15376 if Task_Dispatching_Policy /= ' ' then
15377 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15379 ("Priority_Specific_Dispatching incompatible "
15380 & "with Task_Dispatching_Policy#");
15383 -- The use of Priority_Specific_Dispatching forces ceiling
15386 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
15387 Error_Msg_Sloc := Locking_Policy_Sloc;
15389 ("Priority_Specific_Dispatching incompatible "
15390 & "with Locking_Policy#");
15392 -- Set the Ceiling_Locking policy, but preserve System_Location
15393 -- since we like the error message with the run time name.
15396 Locking_Policy := 'C';
15398 if Locking_Policy_Sloc /= System_Location then
15399 Locking_Policy_Sloc := Loc;
15403 -- Add entry in the table
15405 Specific_Dispatching.Append
15406 ((Dispatching_Policy => DP,
15407 First_Priority => UI_To_Int (Lower_Val),
15408 Last_Priority => UI_To_Int (Upper_Val),
15409 Pragma_Loc => Loc));
15411 end Priority_Specific_Dispatching;
15417 -- pragma Profile (profile_IDENTIFIER);
15419 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
15421 when Pragma_Profile =>
15423 Check_Arg_Count (1);
15424 Check_Valid_Configuration_Pragma;
15425 Check_No_Identifiers;
15428 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15431 if Chars (Argx) = Name_Ravenscar then
15432 Set_Ravenscar_Profile (N);
15434 elsif Chars (Argx) = Name_Restricted then
15435 Set_Profile_Restrictions
15437 N, Warn => Treat_Restrictions_As_Warnings);
15439 elsif Chars (Argx) = Name_Rational then
15440 Set_Rational_Profile;
15442 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15443 Set_Profile_Restrictions
15444 (No_Implementation_Extensions,
15445 N, Warn => Treat_Restrictions_As_Warnings);
15448 Error_Pragma_Arg ("& is not a valid profile", Argx);
15452 ----------------------
15453 -- Profile_Warnings --
15454 ----------------------
15456 -- pragma Profile_Warnings (profile_IDENTIFIER);
15458 -- profile_IDENTIFIER => Restricted | Ravenscar
15460 when Pragma_Profile_Warnings =>
15462 Check_Arg_Count (1);
15463 Check_Valid_Configuration_Pragma;
15464 Check_No_Identifiers;
15467 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15470 if Chars (Argx) = Name_Ravenscar then
15471 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
15473 elsif Chars (Argx) = Name_Restricted then
15474 Set_Profile_Restrictions (Restricted, N, Warn => True);
15476 elsif Chars (Argx) = Name_No_Implementation_Extensions then
15477 Set_Profile_Restrictions
15478 (No_Implementation_Extensions, N, Warn => True);
15481 Error_Pragma_Arg ("& is not a valid profile", Argx);
15485 --------------------------
15486 -- Propagate_Exceptions --
15487 --------------------------
15489 -- pragma Propagate_Exceptions;
15491 -- Note: this pragma is obsolete and has no effect
15493 when Pragma_Propagate_Exceptions =>
15495 Check_Arg_Count (0);
15497 if Warn_On_Obsolescent_Feature then
15499 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
15500 "and has no effect?j?", N);
15507 -- pragma Psect_Object (
15508 -- [Internal =>] LOCAL_NAME,
15509 -- [, [External =>] EXTERNAL_SYMBOL]
15510 -- [, [Size =>] EXTERNAL_SYMBOL]);
15512 when Pragma_Psect_Object | Pragma_Common_Object =>
15513 Psect_Object : declare
15514 Args : Args_List (1 .. 3);
15515 Names : constant Name_List (1 .. 3) := (
15520 Internal : Node_Id renames Args (1);
15521 External : Node_Id renames Args (2);
15522 Size : Node_Id renames Args (3);
15524 Def_Id : Entity_Id;
15526 procedure Check_Too_Long (Arg : Node_Id);
15527 -- Posts message if the argument is an identifier with more
15528 -- than 31 characters, or a string literal with more than
15529 -- 31 characters, and we are operating under VMS
15531 --------------------
15532 -- Check_Too_Long --
15533 --------------------
15535 procedure Check_Too_Long (Arg : Node_Id) is
15536 X : constant Node_Id := Original_Node (Arg);
15539 if not Nkind_In (X, N_String_Literal, N_Identifier) then
15541 ("inappropriate argument for pragma %", Arg);
15544 if OpenVMS_On_Target then
15545 if (Nkind (X) = N_String_Literal
15546 and then String_Length (Strval (X)) > 31)
15548 (Nkind (X) = N_Identifier
15549 and then Length_Of_Name (Chars (X)) > 31)
15552 ("argument for pragma % is longer than 31 characters",
15556 end Check_Too_Long;
15558 -- Start of processing for Common_Object/Psect_Object
15562 Gather_Associations (Names, Args);
15563 Process_Extended_Import_Export_Internal_Arg (Internal);
15565 Def_Id := Entity (Internal);
15567 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
15569 ("pragma% must designate an object", Internal);
15572 Check_Too_Long (Internal);
15574 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
15576 ("cannot use pragma% for imported/exported object",
15580 if Is_Concurrent_Type (Etype (Internal)) then
15582 ("cannot specify pragma % for task/protected object",
15586 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
15588 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
15590 Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
15593 if Ekind (Def_Id) = E_Constant then
15595 ("cannot specify pragma % for a constant", Internal);
15598 if Is_Record_Type (Etype (Internal)) then
15604 Ent := First_Entity (Etype (Internal));
15605 while Present (Ent) loop
15606 Decl := Declaration_Node (Ent);
15608 if Ekind (Ent) = E_Component
15609 and then Nkind (Decl) = N_Component_Declaration
15610 and then Present (Expression (Decl))
15611 and then Warn_On_Export_Import
15614 ("?x?object for pragma % has defaults", Internal);
15624 if Present (Size) then
15625 Check_Too_Long (Size);
15628 if Present (External) then
15629 Check_Arg_Is_External_Name (External);
15630 Check_Too_Long (External);
15633 -- If all error tests pass, link pragma on to the rep item chain
15635 Record_Rep_Item (Def_Id, N);
15642 -- pragma Pure [(library_unit_NAME)];
15644 when Pragma_Pure => Pure : declare
15648 Check_Ada_83_Warning;
15649 Check_Valid_Library_Unit_Pragma;
15651 if Nkind (N) = N_Null_Statement then
15655 Ent := Find_Lib_Unit_Name;
15657 Set_Has_Pragma_Pure (Ent);
15658 Set_Suppress_Elaboration_Warnings (Ent);
15665 -- pragma Pure_05 [(library_unit_NAME)];
15667 -- This pragma is useable only in GNAT_Mode, where it is used like
15668 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
15669 -- it is ignored). It may be used after a pragma Preelaborate, in
15670 -- which case it overrides the effect of the pragma Preelaborate.
15671 -- This is used to implement AI-362 which recategorizes some run-time
15672 -- packages in Ada 2005 mode.
15674 when Pragma_Pure_05 => Pure_05 : declare
15679 Check_Valid_Library_Unit_Pragma;
15681 if not GNAT_Mode then
15682 Error_Pragma ("pragma% only available in GNAT mode");
15685 if Nkind (N) = N_Null_Statement then
15689 -- This is one of the few cases where we need to test the value of
15690 -- Ada_Version_Explicit rather than Ada_Version (which is always
15691 -- set to Ada_2012 in a predefined unit), we need to know the
15692 -- explicit version set to know if this pragma is active.
15694 if Ada_Version_Explicit >= Ada_2005 then
15695 Ent := Find_Lib_Unit_Name;
15696 Set_Is_Preelaborated (Ent, False);
15698 Set_Suppress_Elaboration_Warnings (Ent);
15706 -- pragma Pure_12 [(library_unit_NAME)];
15708 -- This pragma is useable only in GNAT_Mode, where it is used like
15709 -- pragma Pure but it is only effective in Ada 2012 mode (otherwise
15710 -- it is ignored). It may be used after a pragma Preelaborate, in
15711 -- which case it overrides the effect of the pragma Preelaborate.
15712 -- This is used to implement AI05-0212 which recategorizes some
15713 -- run-time packages in Ada 2012 mode.
15715 when Pragma_Pure_12 => Pure_12 : declare
15720 Check_Valid_Library_Unit_Pragma;
15722 if not GNAT_Mode then
15723 Error_Pragma ("pragma% only available in GNAT mode");
15726 if Nkind (N) = N_Null_Statement then
15730 -- This is one of the few cases where we need to test the value of
15731 -- Ada_Version_Explicit rather than Ada_Version (which is always
15732 -- set to Ada_2012 in a predefined unit), we need to know the
15733 -- explicit version set to know if this pragma is active.
15735 if Ada_Version_Explicit >= Ada_2012 then
15736 Ent := Find_Lib_Unit_Name;
15737 Set_Is_Preelaborated (Ent, False);
15739 Set_Suppress_Elaboration_Warnings (Ent);
15743 -------------------
15744 -- Pure_Function --
15745 -------------------
15747 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
15749 when Pragma_Pure_Function => Pure_Function : declare
15752 Def_Id : Entity_Id;
15753 Effective : Boolean := False;
15757 Check_Arg_Count (1);
15758 Check_Optional_Identifier (Arg1, Name_Entity);
15759 Check_Arg_Is_Local_Name (Arg1);
15760 E_Id := Get_Pragma_Arg (Arg1);
15762 if Error_Posted (E_Id) then
15766 -- Loop through homonyms (overloadings) of referenced entity
15768 E := Entity (E_Id);
15770 if Present (E) then
15772 Def_Id := Get_Base_Subprogram (E);
15774 if not Ekind_In (Def_Id, E_Function,
15775 E_Generic_Function,
15779 ("pragma% requires a function name", Arg1);
15782 Set_Is_Pure (Def_Id);
15784 if not Has_Pragma_Pure_Function (Def_Id) then
15785 Set_Has_Pragma_Pure_Function (Def_Id);
15789 exit when From_Aspect_Specification (N);
15791 exit when No (E) or else Scope (E) /= Current_Scope;
15795 and then Warn_On_Redundant_Constructs
15798 ("pragma Pure_Function on& is redundant?r?",
15804 --------------------
15805 -- Queuing_Policy --
15806 --------------------
15808 -- pragma Queuing_Policy (policy_IDENTIFIER);
15810 when Pragma_Queuing_Policy => declare
15814 Check_Ada_83_Warning;
15815 Check_Arg_Count (1);
15816 Check_No_Identifiers;
15817 Check_Arg_Is_Queuing_Policy (Arg1);
15818 Check_Valid_Configuration_Pragma;
15819 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15820 QP := Fold_Upper (Name_Buffer (1));
15822 if Queuing_Policy /= ' '
15823 and then Queuing_Policy /= QP
15825 Error_Msg_Sloc := Queuing_Policy_Sloc;
15826 Error_Pragma ("queuing policy incompatible with policy#");
15828 -- Set new policy, but always preserve System_Location since we
15829 -- like the error message with the run time name.
15832 Queuing_Policy := QP;
15834 if Queuing_Policy_Sloc /= System_Location then
15835 Queuing_Policy_Sloc := Loc;
15844 -- pragma Rational, for compatibility with foreign compiler
15846 when Pragma_Rational =>
15847 Set_Rational_Profile;
15849 -----------------------
15850 -- Relative_Deadline --
15851 -----------------------
15853 -- pragma Relative_Deadline (time_span_EXPRESSION);
15855 when Pragma_Relative_Deadline => Relative_Deadline : declare
15856 P : constant Node_Id := Parent (N);
15861 Check_No_Identifiers;
15862 Check_Arg_Count (1);
15864 Arg := Get_Pragma_Arg (Arg1);
15866 -- The expression must be analyzed in the special manner described
15867 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
15869 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15873 if Nkind (P) = N_Subprogram_Body then
15874 Check_In_Main_Program;
15876 -- Only Task and subprogram cases allowed
15878 elsif Nkind (P) /= N_Task_Definition then
15882 -- Check duplicate pragma before we set the corresponding flag
15884 if Has_Relative_Deadline_Pragma (P) then
15885 Error_Pragma ("duplicate pragma% not allowed");
15888 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
15889 -- Relative_Deadline pragma node cannot be inserted in the Rep
15890 -- Item chain of Ent since it is rewritten by the expander as a
15891 -- procedure call statement that will break the chain.
15893 Set_Has_Relative_Deadline_Pragma (P, True);
15894 end Relative_Deadline;
15896 ------------------------
15897 -- Remote_Access_Type --
15898 ------------------------
15900 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
15902 when Pragma_Remote_Access_Type => Remote_Access_Type : declare
15907 Check_Arg_Count (1);
15908 Check_Optional_Identifier (Arg1, Name_Entity);
15909 Check_Arg_Is_Local_Name (Arg1);
15911 E := Entity (Get_Pragma_Arg (Arg1));
15913 if Nkind (Parent (E)) = N_Formal_Type_Declaration
15914 and then Ekind (E) = E_General_Access_Type
15915 and then Is_Class_Wide_Type (Directly_Designated_Type (E))
15916 and then Scope (Root_Type (Directly_Designated_Type (E)))
15918 and then Is_Valid_Remote_Object_Type
15919 (Root_Type (Directly_Designated_Type (E)))
15921 Set_Is_Remote_Types (E);
15925 ("pragma% applies only to formal access to classwide types",
15928 end Remote_Access_Type;
15930 ---------------------------
15931 -- Remote_Call_Interface --
15932 ---------------------------
15934 -- pragma Remote_Call_Interface [(library_unit_NAME)];
15936 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
15937 Cunit_Node : Node_Id;
15938 Cunit_Ent : Entity_Id;
15942 Check_Ada_83_Warning;
15943 Check_Valid_Library_Unit_Pragma;
15945 if Nkind (N) = N_Null_Statement then
15949 Cunit_Node := Cunit (Current_Sem_Unit);
15950 K := Nkind (Unit (Cunit_Node));
15951 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15953 if K = N_Package_Declaration
15954 or else K = N_Generic_Package_Declaration
15955 or else K = N_Subprogram_Declaration
15956 or else K = N_Generic_Subprogram_Declaration
15957 or else (K = N_Subprogram_Body
15958 and then Acts_As_Spec (Unit (Cunit_Node)))
15963 "pragma% must apply to package or subprogram declaration");
15966 Set_Is_Remote_Call_Interface (Cunit_Ent);
15967 end Remote_Call_Interface;
15973 -- pragma Remote_Types [(library_unit_NAME)];
15975 when Pragma_Remote_Types => Remote_Types : declare
15976 Cunit_Node : Node_Id;
15977 Cunit_Ent : Entity_Id;
15980 Check_Ada_83_Warning;
15981 Check_Valid_Library_Unit_Pragma;
15983 if Nkind (N) = N_Null_Statement then
15987 Cunit_Node := Cunit (Current_Sem_Unit);
15988 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
15990 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15991 N_Generic_Package_Declaration)
15994 ("pragma% can only apply to a package declaration");
15997 Set_Is_Remote_Types (Cunit_Ent);
16004 -- pragma Ravenscar;
16006 when Pragma_Ravenscar =>
16008 Check_Arg_Count (0);
16009 Check_Valid_Configuration_Pragma;
16010 Set_Ravenscar_Profile (N);
16012 if Warn_On_Obsolescent_Feature then
16014 ("pragma Ravenscar is an obsolescent feature?j?", N);
16016 ("|use pragma Profile (Ravenscar) instead?j?", N);
16019 -------------------------
16020 -- Restricted_Run_Time --
16021 -------------------------
16023 -- pragma Restricted_Run_Time;
16025 when Pragma_Restricted_Run_Time =>
16027 Check_Arg_Count (0);
16028 Check_Valid_Configuration_Pragma;
16029 Set_Profile_Restrictions
16030 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
16032 if Warn_On_Obsolescent_Feature then
16034 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
16037 ("|use pragma Profile (Restricted) instead?j?", N);
16044 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
16047 -- restriction_IDENTIFIER
16048 -- | restriction_parameter_IDENTIFIER => EXPRESSION
16050 when Pragma_Restrictions =>
16051 Process_Restrictions_Or_Restriction_Warnings
16052 (Warn => Treat_Restrictions_As_Warnings);
16054 --------------------------
16055 -- Restriction_Warnings --
16056 --------------------------
16058 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
16061 -- restriction_IDENTIFIER
16062 -- | restriction_parameter_IDENTIFIER => EXPRESSION
16064 when Pragma_Restriction_Warnings =>
16066 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
16072 -- pragma Reviewable;
16074 when Pragma_Reviewable =>
16075 Check_Ada_83_Warning;
16076 Check_Arg_Count (0);
16078 -- Call dummy debugging function rv. This is done to assist front
16079 -- end debugging. By placing a Reviewable pragma in the source
16080 -- program, a breakpoint on rv catches this place in the source,
16081 -- allowing convenient stepping to the point of interest.
16085 --------------------------
16086 -- Short_Circuit_And_Or --
16087 --------------------------
16089 -- pragma Short_Circuit_And_Or;
16091 when Pragma_Short_Circuit_And_Or =>
16093 Check_Arg_Count (0);
16094 Check_Valid_Configuration_Pragma;
16095 Short_Circuit_And_Or := True;
16097 -------------------
16098 -- Share_Generic --
16099 -------------------
16101 -- pragma Share_Generic (GNAME {, GNAME});
16103 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
16105 when Pragma_Share_Generic =>
16107 Process_Generic_List;
16113 -- pragma Shared (LOCAL_NAME);
16115 when Pragma_Shared =>
16117 Process_Atomic_Shared_Volatile;
16119 --------------------
16120 -- Shared_Passive --
16121 --------------------
16123 -- pragma Shared_Passive [(library_unit_NAME)];
16125 -- Set the flag Is_Shared_Passive of program unit name entity
16127 when Pragma_Shared_Passive => Shared_Passive : declare
16128 Cunit_Node : Node_Id;
16129 Cunit_Ent : Entity_Id;
16132 Check_Ada_83_Warning;
16133 Check_Valid_Library_Unit_Pragma;
16135 if Nkind (N) = N_Null_Statement then
16139 Cunit_Node := Cunit (Current_Sem_Unit);
16140 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
16142 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
16143 N_Generic_Package_Declaration)
16146 ("pragma% can only apply to a package declaration");
16149 Set_Is_Shared_Passive (Cunit_Ent);
16150 end Shared_Passive;
16152 -----------------------
16153 -- Short_Descriptors --
16154 -----------------------
16156 -- pragma Short_Descriptors;
16158 when Pragma_Short_Descriptors =>
16160 Check_Arg_Count (0);
16161 Check_Valid_Configuration_Pragma;
16162 Short_Descriptors := True;
16164 ------------------------------
16165 -- Simple_Storage_Pool_Type --
16166 ------------------------------
16168 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
16170 when Pragma_Simple_Storage_Pool_Type =>
16171 Simple_Storage_Pool_Type : declare
16177 Check_Arg_Count (1);
16178 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16180 Type_Id := Get_Pragma_Arg (Arg1);
16181 Find_Type (Type_Id);
16182 Typ := Entity (Type_Id);
16184 if Typ = Any_Type then
16188 -- We require the pragma to apply to a type declared in a package
16189 -- declaration, but not (immediately) within a package body.
16191 if Ekind (Current_Scope) /= E_Package
16192 or else In_Package_Body (Current_Scope)
16195 ("pragma% can only apply to type declared immediately "
16196 & "within a package declaration");
16199 -- A simple storage pool type must be an immutably limited record
16200 -- or private type. If the pragma is given for a private type,
16201 -- the full type is similarly restricted (which is checked later
16202 -- in Freeze_Entity).
16204 if Is_Record_Type (Typ)
16205 and then not Is_Immutably_Limited_Type (Typ)
16208 ("pragma% can only apply to explicitly limited record type");
16210 elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
16212 ("pragma% can only apply to a private type that is limited");
16214 elsif not Is_Record_Type (Typ)
16215 and then not Is_Private_Type (Typ)
16218 ("pragma% can only apply to limited record or private type");
16221 Record_Rep_Item (Typ, N);
16222 end Simple_Storage_Pool_Type;
16224 ----------------------
16225 -- Source_File_Name --
16226 ----------------------
16228 -- There are five forms for this pragma:
16230 -- pragma Source_File_Name (
16231 -- [UNIT_NAME =>] unit_NAME,
16232 -- BODY_FILE_NAME => STRING_LITERAL
16233 -- [, [INDEX =>] INTEGER_LITERAL]);
16235 -- pragma Source_File_Name (
16236 -- [UNIT_NAME =>] unit_NAME,
16237 -- SPEC_FILE_NAME => STRING_LITERAL
16238 -- [, [INDEX =>] INTEGER_LITERAL]);
16240 -- pragma Source_File_Name (
16241 -- BODY_FILE_NAME => STRING_LITERAL
16242 -- [, DOT_REPLACEMENT => STRING_LITERAL]
16243 -- [, CASING => CASING_SPEC]);
16245 -- pragma Source_File_Name (
16246 -- SPEC_FILE_NAME => STRING_LITERAL
16247 -- [, DOT_REPLACEMENT => STRING_LITERAL]
16248 -- [, CASING => CASING_SPEC]);
16250 -- pragma Source_File_Name (
16251 -- SUBUNIT_FILE_NAME => STRING_LITERAL
16252 -- [, DOT_REPLACEMENT => STRING_LITERAL]
16253 -- [, CASING => CASING_SPEC]);
16255 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
16257 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
16258 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
16259 -- only be used when no project file is used, while SFNP can only be
16260 -- used when a project file is used.
16262 -- No processing here. Processing was completed during parsing, since
16263 -- we need to have file names set as early as possible. Units are
16264 -- loaded well before semantic processing starts.
16266 -- The only processing we defer to this point is the check for
16267 -- correct placement.
16269 when Pragma_Source_File_Name =>
16271 Check_Valid_Configuration_Pragma;
16273 ------------------------------
16274 -- Source_File_Name_Project --
16275 ------------------------------
16277 -- See Source_File_Name for syntax
16279 -- No processing here. Processing was completed during parsing, since
16280 -- we need to have file names set as early as possible. Units are
16281 -- loaded well before semantic processing starts.
16283 -- The only processing we defer to this point is the check for
16284 -- correct placement.
16286 when Pragma_Source_File_Name_Project =>
16288 Check_Valid_Configuration_Pragma;
16290 -- Check that a pragma Source_File_Name_Project is used only in a
16291 -- configuration pragmas file.
16293 -- Pragmas Source_File_Name_Project should only be generated by
16294 -- the Project Manager in configuration pragmas files.
16296 -- This is really an ugly test. It seems to depend on some
16297 -- accidental and undocumented property. At the very least it
16298 -- needs to be documented, but it would be better to have a
16299 -- clean way of testing if we are in a configuration file???
16301 if Present (Parent (N)) then
16303 ("pragma% can only appear in a configuration pragmas file");
16306 ----------------------
16307 -- Source_Reference --
16308 ----------------------
16310 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
16312 -- Nothing to do, all processing completed in Par.Prag, since we need
16313 -- the information for possible parser messages that are output.
16315 when Pragma_Source_Reference =>
16318 --------------------------------
16319 -- Static_Elaboration_Desired --
16320 --------------------------------
16322 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
16324 when Pragma_Static_Elaboration_Desired =>
16326 Check_At_Most_N_Arguments (1);
16328 if Is_Compilation_Unit (Current_Scope)
16329 and then Ekind (Current_Scope) = E_Package
16331 Set_Static_Elaboration_Desired (Current_Scope, True);
16333 Error_Pragma ("pragma% must apply to a library-level package");
16340 -- pragma Storage_Size (EXPRESSION);
16342 when Pragma_Storage_Size => Storage_Size : declare
16343 P : constant Node_Id := Parent (N);
16347 Check_No_Identifiers;
16348 Check_Arg_Count (1);
16350 -- The expression must be analyzed in the special manner described
16351 -- in "Handling of Default Expressions" in sem.ads.
16353 Arg := Get_Pragma_Arg (Arg1);
16354 Preanalyze_Spec_Expression (Arg, Any_Integer);
16356 if not Is_Static_Expression (Arg) then
16357 Check_Restriction (Static_Storage_Size, Arg);
16360 if Nkind (P) /= N_Task_Definition then
16365 if Has_Storage_Size_Pragma (P) then
16366 Error_Pragma ("duplicate pragma% not allowed");
16368 Set_Has_Storage_Size_Pragma (P, True);
16371 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
16379 -- pragma Storage_Unit (NUMERIC_LITERAL);
16381 -- Only permitted argument is System'Storage_Unit value
16383 when Pragma_Storage_Unit =>
16384 Check_No_Identifiers;
16385 Check_Arg_Count (1);
16386 Check_Arg_Is_Integer_Literal (Arg1);
16388 if Intval (Get_Pragma_Arg (Arg1)) /=
16389 UI_From_Int (Ttypes.System_Storage_Unit)
16391 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
16393 ("the only allowed argument for pragma% is ^", Arg1);
16396 --------------------
16397 -- Stream_Convert --
16398 --------------------
16400 -- pragma Stream_Convert (
16401 -- [Entity =>] type_LOCAL_NAME,
16402 -- [Read =>] function_NAME,
16403 -- [Write =>] function NAME);
16405 when Pragma_Stream_Convert => Stream_Convert : declare
16407 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
16408 -- Check that the given argument is the name of a local function
16409 -- of one argument that is not overloaded earlier in the current
16410 -- local scope. A check is also made that the argument is a
16411 -- function with one parameter.
16413 --------------------------------------
16414 -- Check_OK_Stream_Convert_Function --
16415 --------------------------------------
16417 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
16421 Check_Arg_Is_Local_Name (Arg);
16422 Ent := Entity (Get_Pragma_Arg (Arg));
16424 if Has_Homonym (Ent) then
16426 ("argument for pragma% may not be overloaded", Arg);
16429 if Ekind (Ent) /= E_Function
16430 or else No (First_Formal (Ent))
16431 or else Present (Next_Formal (First_Formal (Ent)))
16434 ("argument for pragma% must be function of one argument",
16437 end Check_OK_Stream_Convert_Function;
16439 -- Start of processing for Stream_Convert
16443 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
16444 Check_Arg_Count (3);
16445 Check_Optional_Identifier (Arg1, Name_Entity);
16446 Check_Optional_Identifier (Arg2, Name_Read);
16447 Check_Optional_Identifier (Arg3, Name_Write);
16448 Check_Arg_Is_Local_Name (Arg1);
16449 Check_OK_Stream_Convert_Function (Arg2);
16450 Check_OK_Stream_Convert_Function (Arg3);
16453 Typ : constant Entity_Id :=
16454 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
16455 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
16456 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
16459 Check_First_Subtype (Arg1);
16461 -- Check for too early or too late. Note that we don't enforce
16462 -- the rule about primitive operations in this case, since, as
16463 -- is the case for explicit stream attributes themselves, these
16464 -- restrictions are not appropriate. Note that the chaining of
16465 -- the pragma by Rep_Item_Too_Late is actually the critical
16466 -- processing done for this pragma.
16468 if Rep_Item_Too_Early (Typ, N)
16470 Rep_Item_Too_Late (Typ, N, FOnly => True)
16475 -- Return if previous error
16477 if Etype (Typ) = Any_Type
16479 Etype (Read) = Any_Type
16481 Etype (Write) = Any_Type
16488 if Underlying_Type (Etype (Read)) /= Typ then
16490 ("incorrect return type for function&", Arg2);
16493 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
16495 ("incorrect parameter type for function&", Arg3);
16498 if Underlying_Type (Etype (First_Formal (Read))) /=
16499 Underlying_Type (Etype (Write))
16502 ("result type of & does not match Read parameter type",
16506 end Stream_Convert;
16512 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16514 -- This is processed by the parser since some of the style checks
16515 -- take place during source scanning and parsing. This means that
16516 -- we don't need to issue error messages here.
16518 when Pragma_Style_Checks => Style_Checks : declare
16519 A : constant Node_Id := Get_Pragma_Arg (Arg1);
16525 Check_No_Identifiers;
16527 -- Two argument form
16529 if Arg_Count = 2 then
16530 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16537 E_Id := Get_Pragma_Arg (Arg2);
16540 if not Is_Entity_Name (E_Id) then
16542 ("second argument of pragma% must be entity name",
16546 E := Entity (E_Id);
16548 if not Ignore_Style_Checks_Pragmas then
16553 Set_Suppress_Style_Checks
16554 (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
16555 exit when No (Homonym (E));
16562 -- One argument form
16565 Check_Arg_Count (1);
16567 if Nkind (A) = N_String_Literal then
16571 Slen : constant Natural := Natural (String_Length (S));
16572 Options : String (1 .. Slen);
16578 C := Get_String_Char (S, Int (J));
16579 exit when not In_Character_Range (C);
16580 Options (J) := Get_Character (C);
16582 -- If at end of string, set options. As per discussion
16583 -- above, no need to check for errors, since we issued
16584 -- them in the parser.
16587 if not Ignore_Style_Checks_Pragmas then
16588 Set_Style_Check_Options (Options);
16598 elsif Nkind (A) = N_Identifier then
16599 if Chars (A) = Name_All_Checks then
16600 if not Ignore_Style_Checks_Pragmas then
16602 Set_GNAT_Style_Check_Options;
16604 Set_Default_Style_Check_Options;
16608 elsif Chars (A) = Name_On then
16609 if not Ignore_Style_Checks_Pragmas then
16610 Style_Check := True;
16613 elsif Chars (A) = Name_Off then
16614 if not Ignore_Style_Checks_Pragmas then
16615 Style_Check := False;
16626 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
16628 when Pragma_Subtitle =>
16630 Check_Arg_Count (1);
16631 Check_Optional_Identifier (Arg1, Name_Subtitle);
16632 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
16639 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
16641 when Pragma_Suppress =>
16642 Process_Suppress_Unsuppress (True);
16648 -- pragma Suppress_All;
16650 -- The only check made here is that the pragma has no arguments.
16651 -- There are no placement rules, and the processing required (setting
16652 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
16653 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
16654 -- then creates and inserts a pragma Suppress (All_Checks).
16656 when Pragma_Suppress_All =>
16658 Check_Arg_Count (0);
16660 -------------------------
16661 -- Suppress_Debug_Info --
16662 -------------------------
16664 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
16666 when Pragma_Suppress_Debug_Info =>
16668 Check_Arg_Count (1);
16669 Check_Optional_Identifier (Arg1, Name_Entity);
16670 Check_Arg_Is_Local_Name (Arg1);
16671 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
16673 ----------------------------------
16674 -- Suppress_Exception_Locations --
16675 ----------------------------------
16677 -- pragma Suppress_Exception_Locations;
16679 when Pragma_Suppress_Exception_Locations =>
16681 Check_Arg_Count (0);
16682 Check_Valid_Configuration_Pragma;
16683 Exception_Locations_Suppressed := True;
16685 -----------------------------
16686 -- Suppress_Initialization --
16687 -----------------------------
16689 -- pragma Suppress_Initialization ([Entity =>] type_Name);
16691 when Pragma_Suppress_Initialization => Suppress_Init : declare
16697 Check_Arg_Count (1);
16698 Check_Optional_Identifier (Arg1, Name_Entity);
16699 Check_Arg_Is_Local_Name (Arg1);
16701 E_Id := Get_Pragma_Arg (Arg1);
16703 if Etype (E_Id) = Any_Type then
16707 E := Entity (E_Id);
16709 if not Is_Type (E) then
16710 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
16713 if Rep_Item_Too_Early (E, N)
16715 Rep_Item_Too_Late (E, N, FOnly => True)
16720 -- For incomplete/private type, set flag on full view
16722 if Is_Incomplete_Or_Private_Type (E) then
16723 if No (Full_View (Base_Type (E))) then
16725 ("argument of pragma% cannot be an incomplete type", Arg1);
16727 Set_Suppress_Initialization (Full_View (Base_Type (E)));
16730 -- For first subtype, set flag on base type
16732 elsif Is_First_Subtype (E) then
16733 Set_Suppress_Initialization (Base_Type (E));
16735 -- For other than first subtype, set flag on subtype itself
16738 Set_Suppress_Initialization (E);
16746 -- pragma System_Name (DIRECT_NAME);
16748 -- Syntax check: one argument, which must be the identifier GNAT or
16749 -- the identifier GCC, no other identifiers are acceptable.
16751 when Pragma_System_Name =>
16753 Check_No_Identifiers;
16754 Check_Arg_Count (1);
16755 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
16757 -----------------------------
16758 -- Task_Dispatching_Policy --
16759 -----------------------------
16761 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
16763 when Pragma_Task_Dispatching_Policy => declare
16767 Check_Ada_83_Warning;
16768 Check_Arg_Count (1);
16769 Check_No_Identifiers;
16770 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16771 Check_Valid_Configuration_Pragma;
16772 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16773 DP := Fold_Upper (Name_Buffer (1));
16775 if Task_Dispatching_Policy /= ' '
16776 and then Task_Dispatching_Policy /= DP
16778 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16780 ("task dispatching policy incompatible with policy#");
16782 -- Set new policy, but always preserve System_Location since we
16783 -- like the error message with the run time name.
16786 Task_Dispatching_Policy := DP;
16788 if Task_Dispatching_Policy_Sloc /= System_Location then
16789 Task_Dispatching_Policy_Sloc := Loc;
16798 -- pragma Task_Info (EXPRESSION);
16800 when Pragma_Task_Info => Task_Info : declare
16801 P : constant Node_Id := Parent (N);
16807 if Nkind (P) /= N_Task_Definition then
16808 Error_Pragma ("pragma% must appear in task definition");
16811 Check_No_Identifiers;
16812 Check_Arg_Count (1);
16814 Analyze_And_Resolve
16815 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
16817 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
16821 Ent := Defining_Identifier (Parent (P));
16823 -- Check duplicate pragma before we chain the pragma in the Rep
16824 -- Item chain of Ent.
16827 (Ent, Name_Task_Info, Check_Parents => False)
16829 Error_Pragma ("duplicate pragma% not allowed");
16832 Record_Rep_Item (Ent, N);
16839 -- pragma Task_Name (string_EXPRESSION);
16841 when Pragma_Task_Name => Task_Name : declare
16842 P : constant Node_Id := Parent (N);
16847 Check_No_Identifiers;
16848 Check_Arg_Count (1);
16850 Arg := Get_Pragma_Arg (Arg1);
16852 -- The expression is used in the call to Create_Task, and must be
16853 -- expanded there, not in the context of the current spec. It must
16854 -- however be analyzed to capture global references, in case it
16855 -- appears in a generic context.
16857 Preanalyze_And_Resolve (Arg, Standard_String);
16859 if Nkind (P) /= N_Task_Definition then
16863 Ent := Defining_Identifier (Parent (P));
16865 -- Check duplicate pragma before we chain the pragma in the Rep
16866 -- Item chain of Ent.
16869 (Ent, Name_Task_Name, Check_Parents => False)
16871 Error_Pragma ("duplicate pragma% not allowed");
16874 Record_Rep_Item (Ent, N);
16881 -- pragma Task_Storage (
16882 -- [Task_Type =>] LOCAL_NAME,
16883 -- [Top_Guard =>] static_integer_EXPRESSION);
16885 when Pragma_Task_Storage => Task_Storage : declare
16886 Args : Args_List (1 .. 2);
16887 Names : constant Name_List (1 .. 2) := (
16891 Task_Type : Node_Id renames Args (1);
16892 Top_Guard : Node_Id renames Args (2);
16898 Gather_Associations (Names, Args);
16900 if No (Task_Type) then
16902 ("missing task_type argument for pragma%");
16905 Check_Arg_Is_Local_Name (Task_Type);
16907 Ent := Entity (Task_Type);
16909 if not Is_Task_Type (Ent) then
16911 ("argument for pragma% must be task type", Task_Type);
16914 if No (Top_Guard) then
16916 ("pragma% takes two arguments", Task_Type);
16918 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
16921 Check_First_Subtype (Task_Type);
16923 if Rep_Item_Too_Late (Ent, N) then
16932 -- pragma Test_Case
16933 -- ([Name =>] Static_String_EXPRESSION
16934 -- ,[Mode =>] MODE_TYPE
16935 -- [, Requires => Boolean_EXPRESSION]
16936 -- [, Ensures => Boolean_EXPRESSION]);
16938 -- MODE_TYPE ::= Nominal | Robustness
16940 when Pragma_Test_Case =>
16944 --------------------------
16945 -- Thread_Local_Storage --
16946 --------------------------
16948 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
16950 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
16956 Check_Arg_Count (1);
16957 Check_Optional_Identifier (Arg1, Name_Entity);
16958 Check_Arg_Is_Library_Level_Local_Name (Arg1);
16960 Id := Get_Pragma_Arg (Arg1);
16963 if not Is_Entity_Name (Id)
16964 or else Ekind (Entity (Id)) /= E_Variable
16966 Error_Pragma_Arg ("local variable name required", Arg1);
16971 if Rep_Item_Too_Early (E, N)
16972 or else Rep_Item_Too_Late (E, N)
16977 Set_Has_Pragma_Thread_Local_Storage (E);
16978 Set_Has_Gigi_Rep_Item (E);
16979 end Thread_Local_Storage;
16985 -- pragma Time_Slice (static_duration_EXPRESSION);
16987 when Pragma_Time_Slice => Time_Slice : declare
16993 Check_Arg_Count (1);
16994 Check_No_Identifiers;
16995 Check_In_Main_Program;
16996 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
16998 if not Error_Posted (Arg1) then
17000 while Present (Nod) loop
17001 if Nkind (Nod) = N_Pragma
17002 and then Pragma_Name (Nod) = Name_Time_Slice
17004 Error_Msg_Name_1 := Pname;
17005 Error_Msg_N ("duplicate pragma% not permitted", Nod);
17012 -- Process only if in main unit
17014 if Get_Source_Unit (Loc) = Main_Unit then
17015 Opt.Time_Slice_Set := True;
17016 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
17018 if Val <= Ureal_0 then
17019 Opt.Time_Slice_Value := 0;
17021 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
17022 Opt.Time_Slice_Value := 1_000_000_000;
17025 Opt.Time_Slice_Value :=
17026 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
17035 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
17037 -- TITLING_OPTION ::=
17038 -- [Title =>] STRING_LITERAL
17039 -- | [Subtitle =>] STRING_LITERAL
17041 when Pragma_Title => Title : declare
17042 Args : Args_List (1 .. 2);
17043 Names : constant Name_List (1 .. 2) := (
17049 Gather_Associations (Names, Args);
17052 for J in 1 .. 2 loop
17053 if Present (Args (J)) then
17054 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
17059 ---------------------
17060 -- Unchecked_Union --
17061 ---------------------
17063 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
17065 when Pragma_Unchecked_Union => Unchecked_Union : declare
17066 Assoc : constant Node_Id := Arg1;
17067 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
17077 Check_No_Identifiers;
17078 Check_Arg_Count (1);
17079 Check_Arg_Is_Local_Name (Arg1);
17081 Find_Type (Type_Id);
17083 Typ := Entity (Type_Id);
17086 or else Rep_Item_Too_Early (Typ, N)
17090 Typ := Underlying_Type (Typ);
17093 if Rep_Item_Too_Late (Typ, N) then
17097 Check_First_Subtype (Arg1);
17099 -- Note remaining cases are references to a type in the current
17100 -- declarative part. If we find an error, we post the error on
17101 -- the relevant type declaration at an appropriate point.
17103 if not Is_Record_Type (Typ) then
17104 Error_Msg_N ("unchecked union must be record type", Typ);
17107 elsif Is_Tagged_Type (Typ) then
17108 Error_Msg_N ("unchecked union must not be tagged", Typ);
17111 elsif not Has_Discriminants (Typ) then
17113 ("unchecked union must have one discriminant", Typ);
17116 -- Note: in previous versions of GNAT we used to check for limited
17117 -- types and give an error, but in fact the standard does allow
17118 -- Unchecked_Union on limited types, so this check was removed.
17120 -- Similarly, GNAT used to require that all discriminants have
17121 -- default values, but this is not mandated by the RM.
17123 -- Proceed with basic error checks completed
17126 Tdef := Type_Definition (Declaration_Node (Typ));
17127 Clist := Component_List (Tdef);
17129 -- Check presence of component list and variant part
17131 if No (Clist) or else No (Variant_Part (Clist)) then
17133 ("unchecked union must have variant part", Tdef);
17137 -- Check components
17139 Comp := First (Component_Items (Clist));
17140 while Present (Comp) loop
17141 Check_Component (Comp, Typ);
17145 -- Check variant part
17147 Vpart := Variant_Part (Clist);
17149 Variant := First (Variants (Vpart));
17150 while Present (Variant) loop
17151 Check_Variant (Variant, Typ);
17156 Set_Is_Unchecked_Union (Typ);
17157 Set_Convention (Typ, Convention_C);
17158 Set_Has_Unchecked_Union (Base_Type (Typ));
17159 Set_Is_Unchecked_Union (Base_Type (Typ));
17160 end Unchecked_Union;
17162 ------------------------
17163 -- Unimplemented_Unit --
17164 ------------------------
17166 -- pragma Unimplemented_Unit;
17168 -- Note: this only gives an error if we are generating code, or if
17169 -- we are in a generic library unit (where the pragma appears in the
17170 -- body, not in the spec).
17172 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
17173 Cunitent : constant Entity_Id :=
17174 Cunit_Entity (Get_Source_Unit (Loc));
17175 Ent_Kind : constant Entity_Kind :=
17180 Check_Arg_Count (0);
17182 if Operating_Mode = Generate_Code
17183 or else Ent_Kind = E_Generic_Function
17184 or else Ent_Kind = E_Generic_Procedure
17185 or else Ent_Kind = E_Generic_Package
17187 Get_Name_String (Chars (Cunitent));
17188 Set_Casing (Mixed_Case);
17189 Write_Str (Name_Buffer (1 .. Name_Len));
17190 Write_Str (" is not supported in this configuration");
17192 raise Unrecoverable_Error;
17194 end Unimplemented_Unit;
17196 ------------------------
17197 -- Universal_Aliasing --
17198 ------------------------
17200 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
17202 when Pragma_Universal_Aliasing => Universal_Alias : declare
17207 Check_Arg_Count (1);
17208 Check_Optional_Identifier (Arg2, Name_Entity);
17209 Check_Arg_Is_Local_Name (Arg1);
17210 E_Id := Entity (Get_Pragma_Arg (Arg1));
17212 if E_Id = Any_Type then
17214 elsif No (E_Id) or else not Is_Type (E_Id) then
17215 Error_Pragma_Arg ("pragma% requires type", Arg1);
17218 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
17219 Record_Rep_Item (E_Id, N);
17220 end Universal_Alias;
17222 --------------------
17223 -- Universal_Data --
17224 --------------------
17226 -- pragma Universal_Data [(library_unit_NAME)];
17228 when Pragma_Universal_Data =>
17231 -- If this is a configuration pragma, then set the universal
17232 -- addressing option, otherwise confirm that the pragma satisfies
17233 -- the requirements of library unit pragma placement and leave it
17234 -- to the GNAAMP back end to detect the pragma (avoids transitive
17235 -- setting of the option due to withed units).
17237 if Is_Configuration_Pragma then
17238 Universal_Addressing_On_AAMP := True;
17240 Check_Valid_Library_Unit_Pragma;
17243 if not AAMP_On_Target then
17244 Error_Pragma ("??pragma% ignored (applies only to AAMP)");
17251 -- pragma Unmodified (local_Name {, local_Name});
17253 when Pragma_Unmodified => Unmodified : declare
17254 Arg_Node : Node_Id;
17255 Arg_Expr : Node_Id;
17256 Arg_Ent : Entity_Id;
17260 Check_At_Least_N_Arguments (1);
17262 -- Loop through arguments
17265 while Present (Arg_Node) loop
17266 Check_No_Identifier (Arg_Node);
17268 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
17269 -- in fact generate reference, so that the entity will have a
17270 -- reference, which will inhibit any warnings about it not
17271 -- being referenced, and also properly show up in the ali file
17272 -- as a reference. But this reference is recorded before the
17273 -- Has_Pragma_Unreferenced flag is set, so that no warning is
17274 -- generated for this reference.
17276 Check_Arg_Is_Local_Name (Arg_Node);
17277 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17279 if Is_Entity_Name (Arg_Expr) then
17280 Arg_Ent := Entity (Arg_Expr);
17282 if not Is_Assignable (Arg_Ent) then
17284 ("pragma% can only be applied to a variable",
17287 Set_Has_Pragma_Unmodified (Arg_Ent);
17299 -- pragma Unreferenced (local_Name {, local_Name});
17301 -- or when used in a context clause:
17303 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
17305 when Pragma_Unreferenced => Unreferenced : declare
17306 Arg_Node : Node_Id;
17307 Arg_Expr : Node_Id;
17308 Arg_Ent : Entity_Id;
17313 Check_At_Least_N_Arguments (1);
17315 -- Check case of appearing within context clause
17317 if Is_In_Context_Clause then
17319 -- The arguments must all be units mentioned in a with clause
17320 -- in the same context clause. Note we already checked (in
17321 -- Par.Prag) that the arguments are either identifiers or
17322 -- selected components.
17325 while Present (Arg_Node) loop
17326 Citem := First (List_Containing (N));
17327 while Citem /= N loop
17328 if Nkind (Citem) = N_With_Clause
17330 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
17332 Set_Has_Pragma_Unreferenced
17335 (Library_Unit (Citem))));
17337 (Get_Pragma_Arg (Arg_Node), Name (Citem));
17346 ("argument of pragma% is not withed unit", Arg_Node);
17352 -- Case of not in list of context items
17356 while Present (Arg_Node) loop
17357 Check_No_Identifier (Arg_Node);
17359 -- Note: the analyze call done by Check_Arg_Is_Local_Name
17360 -- will in fact generate reference, so that the entity will
17361 -- have a reference, which will inhibit any warnings about
17362 -- it not being referenced, and also properly show up in the
17363 -- ali file as a reference. But this reference is recorded
17364 -- before the Has_Pragma_Unreferenced flag is set, so that
17365 -- no warning is generated for this reference.
17367 Check_Arg_Is_Local_Name (Arg_Node);
17368 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17370 if Is_Entity_Name (Arg_Expr) then
17371 Arg_Ent := Entity (Arg_Expr);
17373 -- If the entity is overloaded, the pragma applies to the
17374 -- most recent overloading, as documented. In this case,
17375 -- name resolution does not generate a reference, so it
17376 -- must be done here explicitly.
17378 if Is_Overloaded (Arg_Expr) then
17379 Generate_Reference (Arg_Ent, N);
17382 Set_Has_Pragma_Unreferenced (Arg_Ent);
17390 --------------------------
17391 -- Unreferenced_Objects --
17392 --------------------------
17394 -- pragma Unreferenced_Objects (local_Name {, local_Name});
17396 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
17397 Arg_Node : Node_Id;
17398 Arg_Expr : Node_Id;
17402 Check_At_Least_N_Arguments (1);
17405 while Present (Arg_Node) loop
17406 Check_No_Identifier (Arg_Node);
17407 Check_Arg_Is_Local_Name (Arg_Node);
17408 Arg_Expr := Get_Pragma_Arg (Arg_Node);
17410 if not Is_Entity_Name (Arg_Expr)
17411 or else not Is_Type (Entity (Arg_Expr))
17414 ("argument for pragma% must be type or subtype", Arg_Node);
17417 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
17420 end Unreferenced_Objects;
17422 ------------------------------
17423 -- Unreserve_All_Interrupts --
17424 ------------------------------
17426 -- pragma Unreserve_All_Interrupts;
17428 when Pragma_Unreserve_All_Interrupts =>
17430 Check_Arg_Count (0);
17432 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
17433 Unreserve_All_Interrupts := True;
17440 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
17442 when Pragma_Unsuppress =>
17444 Process_Suppress_Unsuppress (False);
17446 -------------------
17447 -- Use_VADS_Size --
17448 -------------------
17450 -- pragma Use_VADS_Size;
17452 when Pragma_Use_VADS_Size =>
17454 Check_Arg_Count (0);
17455 Check_Valid_Configuration_Pragma;
17456 Use_VADS_Size := True;
17458 ---------------------
17459 -- Validity_Checks --
17460 ---------------------
17462 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
17464 when Pragma_Validity_Checks => Validity_Checks : declare
17465 A : constant Node_Id := Get_Pragma_Arg (Arg1);
17471 Check_Arg_Count (1);
17472 Check_No_Identifiers;
17474 if Nkind (A) = N_String_Literal then
17478 Slen : constant Natural := Natural (String_Length (S));
17479 Options : String (1 .. Slen);
17485 C := Get_String_Char (S, Int (J));
17486 exit when not In_Character_Range (C);
17487 Options (J) := Get_Character (C);
17490 Set_Validity_Check_Options (Options);
17498 elsif Nkind (A) = N_Identifier then
17499 if Chars (A) = Name_All_Checks then
17500 Set_Validity_Check_Options ("a");
17501 elsif Chars (A) = Name_On then
17502 Validity_Checks_On := True;
17503 elsif Chars (A) = Name_Off then
17504 Validity_Checks_On := False;
17507 end Validity_Checks;
17513 -- pragma Volatile (LOCAL_NAME);
17515 when Pragma_Volatile =>
17516 Process_Atomic_Shared_Volatile;
17518 -------------------------
17519 -- Volatile_Components --
17520 -------------------------
17522 -- pragma Volatile_Components (array_LOCAL_NAME);
17524 -- Volatile is handled by the same circuit as Atomic_Components
17530 -- pragma Warnings (On | Off [,REASON]);
17531 -- pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
17532 -- pragma Warnings (static_string_EXPRESSION [,REASON]);
17533 -- pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
17535 -- REASON ::= Reason => Static_String_Expression
17537 when Pragma_Warnings => Warnings : begin
17539 Check_At_Least_N_Arguments (1);
17541 -- See if last argument is labeled Reason. If so, make sure we
17542 -- have a static string expression, but otherwise just ignore
17543 -- the REASON argument by decreasing Num_Args by 1 (all the
17544 -- remaining tests look only at the first Num_Args arguments).
17547 Last_Arg : constant Node_Id :=
17548 Last (Pragma_Argument_Associations (N));
17550 if Nkind (Last_Arg) = N_Pragma_Argument_Association
17551 and then Chars (Last_Arg) = Name_Reason
17553 Check_Arg_Is_Static_Expression (Last_Arg, Standard_String);
17554 Arg_Count := Arg_Count - 1;
17558 -- Now proceed with REASON taken care of and eliminated
17560 Check_No_Identifiers;
17562 -- If debug flag -gnatd.i is set, pragma is ignored
17564 if Debug_Flag_Dot_I then
17568 -- Process various forms of the pragma
17571 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
17574 -- One argument case
17576 if Arg_Count = 1 then
17578 -- On/Off one argument case was processed by parser
17580 if Nkind (Argx) = N_Identifier
17581 and then Nam_In (Chars (Argx), Name_On, Name_Off)
17585 -- One argument case must be ON/OFF or static string expr
17587 elsif not Is_Static_String_Expression (Arg1) then
17589 ("argument of pragma% must be On/Off or static string "
17590 & "expression", Arg1);
17592 -- One argument string expression case
17596 Lit : constant Node_Id := Expr_Value_S (Argx);
17597 Str : constant String_Id := Strval (Lit);
17598 Len : constant Nat := String_Length (Str);
17606 while J <= Len loop
17607 C := Get_String_Char (Str, J);
17608 OK := In_Character_Range (C);
17611 Chr := Get_Character (C);
17613 -- Dash case: only -Wxxx is accepted
17620 C := Get_String_Char (Str, J);
17621 Chr := Get_Character (C);
17622 exit when Chr = 'W';
17627 elsif J < Len and then Chr = '.' then
17629 C := Get_String_Char (Str, J);
17630 Chr := Get_Character (C);
17632 if not Set_Dot_Warning_Switch (Chr) then
17634 ("invalid warning switch character "
17635 & '.' & Chr, Arg1);
17641 OK := Set_Warning_Switch (Chr);
17647 ("invalid warning switch character " & Chr,
17656 -- Two or more arguments (must be two)
17659 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17660 Check_At_Most_N_Arguments (2);
17668 E_Id := Get_Pragma_Arg (Arg2);
17671 -- In the expansion of an inlined body, a reference to
17672 -- the formal may be wrapped in a conversion if the
17673 -- actual is a conversion. Retrieve the real entity name.
17675 if (In_Instance_Body or In_Inlined_Body)
17676 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
17678 E_Id := Expression (E_Id);
17681 -- Entity name case
17683 if Is_Entity_Name (E_Id) then
17684 E := Entity (E_Id);
17691 (E, (Chars (Get_Pragma_Arg (Arg1)) =
17694 -- For OFF case, make entry in warnings off
17695 -- pragma table for later processing. But we do
17696 -- not do that within an instance, since these
17697 -- warnings are about what is needed in the
17698 -- template, not an instance of it.
17700 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
17701 and then Warn_On_Warnings_Off
17702 and then not In_Instance
17704 Warnings_Off_Pragmas.Append ((N, E));
17707 if Is_Enumeration_Type (E) then
17711 Lit := First_Literal (E);
17712 while Present (Lit) loop
17713 Set_Warnings_Off (Lit);
17714 Next_Literal (Lit);
17719 exit when No (Homonym (E));
17724 -- Error if not entity or static string literal case
17726 elsif not Is_Static_String_Expression (Arg2) then
17728 ("second argument of pragma% must be entity name "
17729 & "or static string expression", Arg2);
17731 -- String literal case
17734 String_To_Name_Buffer
17735 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
17737 -- Note on configuration pragma case: If this is a
17738 -- configuration pragma, then for an OFF pragma, we
17739 -- just set Config True in the call, which is all
17740 -- that needs to be done. For the case of ON, this
17741 -- is normally an error, unless it is canceling the
17742 -- effect of a previous OFF pragma in the same file.
17743 -- In any other case, an error will be signalled (ON
17744 -- with no matching OFF).
17746 -- Note: We set Used if we are inside a generic to
17747 -- disable the test that the non-config case actually
17748 -- cancels a warning. That's because we can't be sure
17749 -- there isn't an instantiation in some other unit
17750 -- where a warning is suppressed.
17752 -- We could do a little better here by checking if the
17753 -- generic unit we are inside is public, but for now
17754 -- we don't bother with that refinement.
17756 if Chars (Argx) = Name_Off then
17757 Set_Specific_Warning_Off
17758 (Loc, Name_Buffer (1 .. Name_Len),
17759 Config => Is_Configuration_Pragma,
17760 Used => Inside_A_Generic or else In_Instance);
17762 elsif Chars (Argx) = Name_On then
17763 Set_Specific_Warning_On
17764 (Loc, Name_Buffer (1 .. Name_Len), Err);
17768 ("??pragma Warnings On with no matching "
17769 & "Warnings Off", Loc);
17778 -------------------
17779 -- Weak_External --
17780 -------------------
17782 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
17784 when Pragma_Weak_External => Weak_External : declare
17789 Check_Arg_Count (1);
17790 Check_Optional_Identifier (Arg1, Name_Entity);
17791 Check_Arg_Is_Library_Level_Local_Name (Arg1);
17792 Ent := Entity (Get_Pragma_Arg (Arg1));
17794 if Rep_Item_Too_Early (Ent, N) then
17797 Ent := Underlying_Type (Ent);
17800 -- The only processing required is to link this item on to the
17801 -- list of rep items for the given entity. This is accomplished
17802 -- by the call to Rep_Item_Too_Late (when no error is detected
17803 -- and False is returned).
17805 if Rep_Item_Too_Late (Ent, N) then
17808 Set_Has_Gigi_Rep_Item (Ent);
17812 -----------------------------
17813 -- Wide_Character_Encoding --
17814 -----------------------------
17816 -- pragma Wide_Character_Encoding (IDENTIFIER);
17818 when Pragma_Wide_Character_Encoding =>
17821 -- Nothing to do, handled in parser. Note that we do not enforce
17822 -- configuration pragma placement, this pragma can appear at any
17823 -- place in the source, allowing mixed encodings within a single
17828 --------------------
17829 -- Unknown_Pragma --
17830 --------------------
17832 -- Should be impossible, since the case of an unknown pragma is
17833 -- separately processed before the case statement is entered.
17835 when Unknown_Pragma =>
17836 raise Program_Error;
17839 -- AI05-0144: detect dangerous order dependence. Disabled for now,
17840 -- until AI is formally approved.
17842 -- Check_Order_Dependence;
17845 when Pragma_Exit => null;
17846 end Analyze_Pragma;
17848 ------------------------------------
17849 -- Analyze_Test_Case_In_Decl_Part --
17850 ------------------------------------
17852 procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
17854 -- Install formals and push subprogram spec onto scope stack so that we
17855 -- can see the formals from the pragma.
17858 Install_Formals (S);
17860 -- Preanalyze the boolean expressions, we treat these as spec
17861 -- expressions (i.e. similar to a default expression).
17863 if Pragma_Name (N) = Name_Test_Case then
17864 Preanalyze_CTC_Args
17866 Get_Requires_From_CTC_Pragma (N),
17867 Get_Ensures_From_CTC_Pragma (N));
17870 -- Remove the subprogram from the scope stack now that the pre-analysis
17871 -- of the expressions in the contract case or test case is done.
17874 end Analyze_Test_Case_In_Decl_Part;
17880 function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
17885 if Present (List) then
17886 Elmt := First_Elmt (List);
17887 while Present (Elmt) loop
17888 if Nkind (Node (Elmt)) = N_Defining_Identifier then
17891 Id := Entity (Node (Elmt));
17894 if Id = Item_Id then
17909 function Check_Kind (Nam : Name_Id) return Name_Id is
17913 -- Loop through entries in check policy list
17915 PP := Opt.Check_Policy_List;
17916 while Present (PP) loop
17918 PPA : constant List_Id := Pragma_Argument_Associations (PP);
17919 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
17923 or else (Pnm = Name_Assertion
17924 and then Is_Valid_Assertion_Kind (Nam))
17925 or else (Pnm = Name_Statement_Assertions
17926 and then Nam_In (Nam, Name_Assert,
17927 Name_Assert_And_Cut,
17929 Name_Loop_Invariant))
17931 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
17932 when Name_On | Name_Check =>
17934 when Name_Off | Name_Ignore =>
17935 return Name_Ignore;
17936 when Name_Disable =>
17937 return Name_Disable;
17939 raise Program_Error;
17943 PP := Next_Pragma (PP);
17948 -- If there are no specific entries that matched, then we let the
17949 -- setting of assertions govern. Note that this provides the needed
17950 -- compatibility with the RM for the cases of assertion, invariant,
17951 -- precondition, predicate, and postcondition.
17953 if Assertions_Enabled then
17956 return Name_Ignore;
17960 -----------------------------
17961 -- Check_Applicable_Policy --
17962 -----------------------------
17964 procedure Check_Applicable_Policy (N : Node_Id) is
17968 Ename : constant Name_Id := Original_Name (N);
17971 -- No effect if not valid assertion kind name
17973 if not Is_Valid_Assertion_Kind (Ename) then
17977 -- Loop through entries in check policy list
17979 PP := Opt.Check_Policy_List;
17980 while Present (PP) loop
17982 PPA : constant List_Id := Pragma_Argument_Associations (PP);
17983 Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
17986 if Ename = Pnm or else Pnm = Name_Assertion then
17987 Policy := Chars (Get_Pragma_Arg (Last (PPA)));
17990 when Name_Off | Name_Ignore =>
17991 Set_Is_Ignored (N, True);
17993 when Name_Disable =>
17994 Set_Is_Ignored (N, True);
17995 Set_Is_Disabled (N, True);
18004 PP := Next_Pragma (PP);
18008 -- If there are no specific entries that matched, then we let the
18009 -- setting of assertions govern. Note that this provides the needed
18010 -- compatibility with the RM for the cases of assertion, invariant,
18011 -- precondition, predicate, and postcondition.
18013 if not Assertions_Enabled then
18014 Set_Is_Ignored (N);
18016 end Check_Applicable_Policy;
18018 ---------------------------------------
18019 -- Collect_Subprogram_Inputs_Outputs --
18020 ---------------------------------------
18022 procedure Collect_Subprogram_Inputs_Outputs
18023 (Subp_Id : Entity_Id;
18024 Subp_Inputs : in out Elist_Id;
18025 Subp_Outputs : in out Elist_Id;
18026 Global_Seen : out Boolean)
18028 procedure Collect_Global_List
18030 Mode : Name_Id := Name_Input);
18031 -- Collect all relevant items from a global list
18033 -------------------------
18034 -- Collect_Global_List --
18035 -------------------------
18037 procedure Collect_Global_List
18039 Mode : Name_Id := Name_Input)
18041 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
18042 -- Add an item to the proper subprogram input or output collection
18044 -------------------------
18045 -- Collect_Global_Item --
18046 -------------------------
18048 procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
18050 if Nam_In (Mode, Name_In_Out, Name_Input) then
18051 Add_Item (Item, Subp_Inputs);
18054 if Nam_In (Mode, Name_In_Out, Name_Output) then
18055 Add_Item (Item, Subp_Outputs);
18057 end Collect_Global_Item;
18064 -- Start of processing for Collect_Global_List
18067 -- Single global item declaration
18069 if Nkind_In (List, N_Identifier, N_Selected_Component) then
18070 Collect_Global_Item (List, Mode);
18072 -- Simple global list or moded global list declaration
18075 if Present (Expressions (List)) then
18076 Item := First (Expressions (List));
18077 while Present (Item) loop
18078 Collect_Global_Item (Item, Mode);
18083 Assoc := First (Component_Associations (List));
18084 while Present (Assoc) loop
18085 Collect_Global_List
18086 (List => Expression (Assoc),
18087 Mode => Chars (First (Choices (Assoc))));
18092 end Collect_Global_List;
18096 Formal : Entity_Id;
18100 -- Start of processing for Collect_Subprogram_Inputs_Outputs
18103 Global_Seen := False;
18105 -- Process all formal parameters
18107 Formal := First_Formal (Subp_Id);
18108 while Present (Formal) loop
18109 if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
18110 Add_Item (Formal, Subp_Inputs);
18113 if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
18114 Add_Item (Formal, Subp_Outputs);
18117 Next_Formal (Formal);
18120 -- If the subprogram is subject to pragma Global, traverse all global
18121 -- lists and gather the relevant items.
18123 Global := Find_Aspect (Subp_Id, Aspect_Global);
18124 if Present (Global) then
18125 Global_Seen := True;
18127 -- Retrieve the pragma as it contains the analyzed lists
18129 Global := Aspect_Rep_Item (Global);
18130 List := Expression (First (Pragma_Argument_Associations (Global)));
18132 -- The pragma may not have been analyzed because of the arbitrary
18133 -- declaration order of aspects. Make sure that it is analyzed for
18134 -- the purposes of item extraction.
18136 if not Analyzed (List) then
18137 Analyze_Global_In_Decl_Part (Global);
18140 -- Nothing to be done for a null global list
18142 if Nkind (List) /= N_Null then
18143 Collect_Global_List (List);
18146 end Collect_Subprogram_Inputs_Outputs;
18148 ---------------------------------
18149 -- Delay_Config_Pragma_Analyze --
18150 ---------------------------------
18152 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
18154 return Nam_In (Pragma_Name (N), Name_Interrupt_State,
18155 Name_Priority_Specific_Dispatching);
18156 end Delay_Config_Pragma_Analyze;
18158 -----------------------------
18159 -- Find_Related_Subprogram --
18160 -----------------------------
18162 function Find_Related_Subprogram
18164 Check_Duplicates : Boolean := False) return Node_Id
18166 Context : constant Node_Id := Parent (Prag);
18167 Nam : constant Name_Id := Pragma_Name (Prag);
18169 Subp_Decl : Node_Id;
18172 pragma Assert (Nkind (Prag) = N_Pragma);
18174 -- If the pragma comes from an aspect, then what we want is the
18175 -- declaration to which the aspect is attached, i.e. its parent.
18177 if Present (Corresponding_Aspect (Prag)) then
18178 return Parent (Corresponding_Aspect (Prag));
18181 -- Otherwise the pragma must be a list element, and the first thing to
18182 -- do is to position past any previous pragmas or generated code. What
18183 -- we are doing here is looking for the preceding declaration. This is
18184 -- also where we will check for a duplicate pragma.
18186 pragma Assert (Is_List_Member (Prag));
18190 Elmt := Prev (Elmt);
18191 exit when No (Elmt);
18193 -- Typically want we will want is the declaration original node. But
18194 -- for the generic subprogram case, don't go to to the original node,
18195 -- which is the unanalyzed tree: we need to attach the pre- and post-
18196 -- conditions to the analyzed version at this point. They propagate
18197 -- to the original tree when analyzing the corresponding body.
18199 if Nkind (Elmt) not in N_Generic_Declaration then
18200 Subp_Decl := Original_Node (Elmt);
18205 -- Skip prior pragmas
18207 if Nkind (Subp_Decl) = N_Pragma then
18208 if Check_Duplicates and then Pragma_Name (Subp_Decl) = Nam then
18209 Error_Msg_Name_1 := Nam;
18210 Error_Msg_Sloc := Sloc (Subp_Decl);
18211 Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
18214 -- Skip internally generated code
18216 elsif not Comes_From_Source (Subp_Decl) then
18219 -- Otherwise we have a declaration to return
18226 -- We fell through, which means there was no declaration preceding the
18227 -- pragma (either it was the first element of the list, or we only had
18228 -- other pragmas and generated code before it).
18230 -- The pragma is associated with a library-level subprogram
18232 if Nkind (Context) = N_Compilation_Unit_Aux then
18233 return Unit (Parent (Context));
18235 -- The pragma appears inside the declarative part of a subprogram body
18237 elsif Nkind (Context) = N_Subprogram_Body then
18240 -- Otherwise no subprogram found, return original pragma
18245 end Find_Related_Subprogram;
18247 -------------------------
18248 -- Get_Base_Subprogram --
18249 -------------------------
18251 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
18252 Result : Entity_Id;
18255 -- Follow subprogram renaming chain
18259 if Is_Subprogram (Result)
18261 Nkind (Parent (Declaration_Node (Result))) =
18262 N_Subprogram_Renaming_Declaration
18263 and then Present (Alias (Result))
18265 Result := Alias (Result);
18269 end Get_Base_Subprogram;
18275 procedure Initialize is
18280 -----------------------------
18281 -- Is_Config_Static_String --
18282 -----------------------------
18284 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
18286 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
18287 -- This is an internal recursive function that is just like the outer
18288 -- function except that it adds the string to the name buffer rather
18289 -- than placing the string in the name buffer.
18291 ------------------------------
18292 -- Add_Config_Static_String --
18293 ------------------------------
18295 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
18302 if Nkind (N) = N_Op_Concat then
18303 if Add_Config_Static_String (Left_Opnd (N)) then
18304 N := Right_Opnd (N);
18310 if Nkind (N) /= N_String_Literal then
18311 Error_Msg_N ("string literal expected for pragma argument", N);
18315 for J in 1 .. String_Length (Strval (N)) loop
18316 C := Get_String_Char (Strval (N), J);
18318 if not In_Character_Range (C) then
18320 ("string literal contains invalid wide character",
18321 Sloc (N) + 1 + Source_Ptr (J));
18325 Add_Char_To_Name_Buffer (Get_Character (C));
18330 end Add_Config_Static_String;
18332 -- Start of processing for Is_Config_Static_String
18337 return Add_Config_Static_String (Arg);
18338 end Is_Config_Static_String;
18340 -----------------------------------------
18341 -- Is_Non_Significant_Pragma_Reference --
18342 -----------------------------------------
18344 -- This function makes use of the following static table which indicates
18345 -- whether appearance of some name in a given pragma is to be considered
18346 -- as a reference for the purposes of warnings about unreferenced objects.
18348 -- -1 indicates that references in any argument position are significant
18349 -- 0 indicates that appearance in any argument is not significant
18350 -- +n indicates that appearance as argument n is significant, but all
18351 -- other arguments are not significant
18352 -- 99 special processing required (e.g. for pragma Check)
18354 Sig_Flags : constant array (Pragma_Id) of Int :=
18355 (Pragma_AST_Entry => -1,
18356 Pragma_Abort_Defer => -1,
18357 Pragma_Abstract_State => -1,
18358 Pragma_Ada_83 => -1,
18359 Pragma_Ada_95 => -1,
18360 Pragma_Ada_05 => -1,
18361 Pragma_Ada_2005 => -1,
18362 Pragma_Ada_12 => -1,
18363 Pragma_Ada_2012 => -1,
18364 Pragma_All_Calls_Remote => -1,
18365 Pragma_Annotate => -1,
18366 Pragma_Assert => -1,
18367 Pragma_Assert_And_Cut => -1,
18368 Pragma_Assertion_Policy => 0,
18369 Pragma_Assume => -1,
18370 Pragma_Assume_No_Invalid_Values => 0,
18371 Pragma_Attribute_Definition => +3,
18372 Pragma_Asynchronous => -1,
18373 Pragma_Atomic => 0,
18374 Pragma_Atomic_Components => 0,
18375 Pragma_Attach_Handler => -1,
18376 Pragma_Check => 99,
18377 Pragma_Check_Float_Overflow => 0,
18378 Pragma_Check_Name => 0,
18379 Pragma_Check_Policy => 0,
18380 Pragma_CIL_Constructor => -1,
18381 Pragma_CPP_Class => 0,
18382 Pragma_CPP_Constructor => 0,
18383 Pragma_CPP_Virtual => 0,
18384 Pragma_CPP_Vtable => 0,
18386 Pragma_C_Pass_By_Copy => 0,
18387 Pragma_Comment => 0,
18388 Pragma_Common_Object => -1,
18389 Pragma_Compile_Time_Error => -1,
18390 Pragma_Compile_Time_Warning => -1,
18391 Pragma_Compiler_Unit => 0,
18392 Pragma_Complete_Representation => 0,
18393 Pragma_Complex_Representation => 0,
18394 Pragma_Component_Alignment => -1,
18395 Pragma_Contract_Cases => -1,
18396 Pragma_Controlled => 0,
18397 Pragma_Convention => 0,
18398 Pragma_Convention_Identifier => 0,
18399 Pragma_Debug => -1,
18400 Pragma_Debug_Policy => 0,
18401 Pragma_Detect_Blocking => -1,
18402 Pragma_Default_Storage_Pool => -1,
18403 Pragma_Depends => -1,
18404 Pragma_Disable_Atomic_Synchronization => -1,
18405 Pragma_Discard_Names => 0,
18406 Pragma_Dispatching_Domain => -1,
18407 Pragma_Elaborate => -1,
18408 Pragma_Elaborate_All => -1,
18409 Pragma_Elaborate_Body => -1,
18410 Pragma_Elaboration_Checks => -1,
18411 Pragma_Eliminate => -1,
18412 Pragma_Enable_Atomic_Synchronization => -1,
18413 Pragma_Export => -1,
18414 Pragma_Export_Exception => -1,
18415 Pragma_Export_Function => -1,
18416 Pragma_Export_Object => -1,
18417 Pragma_Export_Procedure => -1,
18418 Pragma_Export_Value => -1,
18419 Pragma_Export_Valued_Procedure => -1,
18420 Pragma_Extend_System => -1,
18421 Pragma_Extensions_Allowed => -1,
18422 Pragma_External => -1,
18423 Pragma_Favor_Top_Level => -1,
18424 Pragma_External_Name_Casing => -1,
18425 Pragma_Fast_Math => -1,
18426 Pragma_Finalize_Storage_Only => 0,
18427 Pragma_Float_Representation => 0,
18428 Pragma_Global => -1,
18429 Pragma_Ident => -1,
18430 Pragma_Implementation_Defined => -1,
18431 Pragma_Implemented => -1,
18432 Pragma_Implicit_Packing => 0,
18433 Pragma_Import => +2,
18434 Pragma_Import_Exception => 0,
18435 Pragma_Import_Function => 0,
18436 Pragma_Import_Object => 0,
18437 Pragma_Import_Procedure => 0,
18438 Pragma_Import_Valued_Procedure => 0,
18439 Pragma_Independent => 0,
18440 Pragma_Independent_Components => 0,
18441 Pragma_Initialize_Scalars => -1,
18442 Pragma_Inline => 0,
18443 Pragma_Inline_Always => 0,
18444 Pragma_Inline_Generic => 0,
18445 Pragma_Inspection_Point => -1,
18446 Pragma_Interface => +2,
18447 Pragma_Interface_Name => +2,
18448 Pragma_Interrupt_Handler => -1,
18449 Pragma_Interrupt_Priority => -1,
18450 Pragma_Interrupt_State => -1,
18451 Pragma_Invariant => -1,
18452 Pragma_Java_Constructor => -1,
18453 Pragma_Java_Interface => -1,
18454 Pragma_Keep_Names => 0,
18455 Pragma_License => -1,
18456 Pragma_Link_With => -1,
18457 Pragma_Linker_Alias => -1,
18458 Pragma_Linker_Constructor => -1,
18459 Pragma_Linker_Destructor => -1,
18460 Pragma_Linker_Options => -1,
18461 Pragma_Linker_Section => -1,
18463 Pragma_Lock_Free => -1,
18464 Pragma_Locking_Policy => -1,
18465 Pragma_Long_Float => -1,
18466 Pragma_Loop_Invariant => -1,
18467 Pragma_Loop_Optimize => -1,
18468 Pragma_Loop_Variant => -1,
18469 Pragma_Machine_Attribute => -1,
18471 Pragma_Main_Storage => -1,
18472 Pragma_Memory_Size => -1,
18473 Pragma_No_Return => 0,
18474 Pragma_No_Body => 0,
18475 Pragma_No_Inline => 0,
18476 Pragma_No_Run_Time => -1,
18477 Pragma_No_Strict_Aliasing => -1,
18478 Pragma_Normalize_Scalars => -1,
18479 Pragma_Obsolescent => 0,
18480 Pragma_Optimize => -1,
18481 Pragma_Optimize_Alignment => -1,
18482 Pragma_Overflow_Mode => 0,
18483 Pragma_Overriding_Renamings => 0,
18484 Pragma_Ordered => 0,
18487 Pragma_Partition_Elaboration_Policy => -1,
18488 Pragma_Passive => -1,
18489 Pragma_Preelaborable_Initialization => -1,
18490 Pragma_Polling => -1,
18491 Pragma_Persistent_BSS => 0,
18492 Pragma_Postcondition => -1,
18493 Pragma_Precondition => -1,
18494 Pragma_Predicate => -1,
18495 Pragma_Preelaborate => -1,
18496 Pragma_Preelaborate_05 => -1,
18497 Pragma_Priority => -1,
18498 Pragma_Priority_Specific_Dispatching => -1,
18499 Pragma_Profile => 0,
18500 Pragma_Profile_Warnings => 0,
18501 Pragma_Propagate_Exceptions => -1,
18502 Pragma_Psect_Object => -1,
18504 Pragma_Pure_05 => -1,
18505 Pragma_Pure_12 => -1,
18506 Pragma_Pure_Function => -1,
18507 Pragma_Queuing_Policy => -1,
18508 Pragma_Rational => -1,
18509 Pragma_Ravenscar => -1,
18510 Pragma_Relative_Deadline => -1,
18511 Pragma_Remote_Access_Type => -1,
18512 Pragma_Remote_Call_Interface => -1,
18513 Pragma_Remote_Types => -1,
18514 Pragma_Restricted_Run_Time => -1,
18515 Pragma_Restriction_Warnings => -1,
18516 Pragma_Restrictions => -1,
18517 Pragma_Reviewable => -1,
18518 Pragma_Short_Circuit_And_Or => -1,
18519 Pragma_Share_Generic => -1,
18520 Pragma_Shared => -1,
18521 Pragma_Shared_Passive => -1,
18522 Pragma_Short_Descriptors => 0,
18523 Pragma_Simple_Storage_Pool_Type => 0,
18524 Pragma_Source_File_Name => -1,
18525 Pragma_Source_File_Name_Project => -1,
18526 Pragma_Source_Reference => -1,
18527 Pragma_Storage_Size => -1,
18528 Pragma_Storage_Unit => -1,
18529 Pragma_Static_Elaboration_Desired => -1,
18530 Pragma_Stream_Convert => -1,
18531 Pragma_Style_Checks => -1,
18532 Pragma_Subtitle => -1,
18533 Pragma_Suppress => 0,
18534 Pragma_Suppress_Exception_Locations => 0,
18535 Pragma_Suppress_All => -1,
18536 Pragma_Suppress_Debug_Info => 0,
18537 Pragma_Suppress_Initialization => 0,
18538 Pragma_System_Name => -1,
18539 Pragma_Task_Dispatching_Policy => -1,
18540 Pragma_Task_Info => -1,
18541 Pragma_Task_Name => -1,
18542 Pragma_Task_Storage => 0,
18543 Pragma_Test_Case => -1,
18544 Pragma_Thread_Local_Storage => 0,
18545 Pragma_Time_Slice => -1,
18546 Pragma_Title => -1,
18547 Pragma_Unchecked_Union => 0,
18548 Pragma_Unimplemented_Unit => -1,
18549 Pragma_Universal_Aliasing => -1,
18550 Pragma_Universal_Data => -1,
18551 Pragma_Unmodified => -1,
18552 Pragma_Unreferenced => -1,
18553 Pragma_Unreferenced_Objects => -1,
18554 Pragma_Unreserve_All_Interrupts => -1,
18555 Pragma_Unsuppress => 0,
18556 Pragma_Use_VADS_Size => -1,
18557 Pragma_Validity_Checks => -1,
18558 Pragma_Volatile => 0,
18559 Pragma_Volatile_Components => 0,
18560 Pragma_Warnings => -1,
18561 Pragma_Weak_External => -1,
18562 Pragma_Wide_Character_Encoding => 0,
18563 Unknown_Pragma => 0);
18565 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
18574 if Nkind (P) /= N_Pragma_Argument_Association then
18578 Id := Get_Pragma_Id (Parent (P));
18579 C := Sig_Flags (Id);
18591 -- For pragma Check, the first argument is not significant,
18592 -- the second and the third (if present) arguments are
18595 when Pragma_Check =>
18597 P = First (Pragma_Argument_Associations (Parent (P)));
18600 raise Program_Error;
18604 A := First (Pragma_Argument_Associations (Parent (P)));
18605 for J in 1 .. C - 1 loop
18613 return A = P; -- is this wrong way round ???
18616 end Is_Non_Significant_Pragma_Reference;
18618 ------------------------------
18619 -- Is_Pragma_String_Literal --
18620 ------------------------------
18622 -- This function returns true if the corresponding pragma argument is a
18623 -- static string expression. These are the only cases in which string
18624 -- literals can appear as pragma arguments. We also allow a string literal
18625 -- as the first argument to pragma Assert (although it will of course
18626 -- always generate a type error).
18628 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
18629 Pragn : constant Node_Id := Parent (Par);
18630 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
18631 Pname : constant Name_Id := Pragma_Name (Pragn);
18637 N := First (Assoc);
18644 if Pname = Name_Assert then
18647 elsif Pname = Name_Export then
18650 elsif Pname = Name_Ident then
18653 elsif Pname = Name_Import then
18656 elsif Pname = Name_Interface_Name then
18659 elsif Pname = Name_Linker_Alias then
18662 elsif Pname = Name_Linker_Section then
18665 elsif Pname = Name_Machine_Attribute then
18668 elsif Pname = Name_Source_File_Name then
18671 elsif Pname = Name_Source_Reference then
18674 elsif Pname = Name_Title then
18677 elsif Pname = Name_Subtitle then
18683 end Is_Pragma_String_Literal;
18685 -----------------------------
18686 -- Is_Valid_Assertion_Kind --
18687 -----------------------------
18689 function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
18696 Name_Static_Predicate |
18697 Name_Dynamic_Predicate |
18702 Name_Type_Invariant |
18703 Name_uType_Invariant |
18707 Name_Assert_And_Cut |
18709 Name_Contract_Cases |
18713 Name_Loop_Invariant |
18714 Name_Loop_Variant |
18715 Name_Postcondition |
18716 Name_Precondition |
18718 Name_Statement_Assertions => return True;
18720 when others => return False;
18722 end Is_Valid_Assertion_Kind;
18724 -----------------------------------------
18725 -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
18726 -----------------------------------------
18728 procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
18729 Aspects : constant List_Id := New_List;
18730 Loc : constant Source_Ptr := Sloc (Decl);
18731 Or_Decl : constant Node_Id := Original_Node (Decl);
18733 Original_Aspects : List_Id;
18734 -- To capture global references, a copy of the created aspects must be
18735 -- inserted in the original tree.
18738 Prag_Arg_Ass : Node_Id;
18739 Prag_Id : Pragma_Id;
18742 -- Check for any PPC pragmas that appear within Decl
18744 Prag := Next (Decl);
18745 while Nkind (Prag) = N_Pragma loop
18746 Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
18749 when Pragma_Postcondition | Pragma_Precondition =>
18750 Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
18752 -- Make an aspect from any PPC pragma
18754 Append_To (Aspects,
18755 Make_Aspect_Specification (Loc,
18757 Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
18759 Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
18761 -- Generate the analysis information in the pragma expression
18762 -- and then set the pragma node analyzed to avoid any further
18765 Analyze (Expression (Prag_Arg_Ass));
18766 Set_Analyzed (Prag, True);
18768 when others => null;
18774 -- Set all new aspects into the generic declaration node
18776 if Is_Non_Empty_List (Aspects) then
18778 -- Create the list of aspects to be inserted in the original tree
18780 Original_Aspects := Copy_Separate_List (Aspects);
18782 -- Check if Decl already has aspects
18784 -- Attach the new lists of aspects to both the generic copy and the
18787 if Has_Aspects (Decl) then
18788 Append_List (Aspects, Aspect_Specifications (Decl));
18789 Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
18792 Set_Parent (Aspects, Decl);
18793 Set_Aspect_Specifications (Decl, Aspects);
18794 Set_Parent (Original_Aspects, Or_Decl);
18795 Set_Aspect_Specifications (Or_Decl, Original_Aspects);
18798 end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
18800 -------------------
18801 -- Original_Name --
18802 -------------------
18804 function Original_Name (N : Node_Id) return Name_Id is
18809 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
18812 if Is_Rewrite_Substitution (Pras)
18813 and then Nkind (Original_Node (Pras)) = N_Pragma
18815 Pras := Original_Node (Pras);
18818 -- Case where we came from aspect specication
18820 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
18821 Pras := Corresponding_Aspect (Pras);
18824 -- Get name from aspect or pragma
18826 if Nkind (Pras) = N_Pragma then
18827 Name := Pragma_Name (Pras);
18829 Name := Chars (Identifier (Pras));
18832 -- Deal with 'Class
18834 if Class_Present (Pras) then
18837 -- Names that need converting to special _xxx form
18839 when Name_Pre => Name := Name_uPre;
18840 when Name_Post => Name := Name_uPost;
18841 when Name_Invariant => Name := Name_uInvariant;
18842 when Name_Type_Invariant => Name := Name_uType_Invariant;
18844 -- Names already in special _xxx form (leave them alone)
18846 when Name_uPre => null;
18847 when Name_uPost => null;
18848 when Name_uInvariant => null;
18849 when Name_uType_Invariant => null;
18851 -- Anything else is impossible with Class_Present set True
18853 when others => raise Program_Error;
18860 -------------------------
18861 -- Preanalyze_CTC_Args --
18862 -------------------------
18864 procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
18866 -- Preanalyze the boolean expressions, we treat these as spec
18867 -- expressions (i.e. similar to a default expression).
18869 if Present (Arg_Req) then
18870 Preanalyze_Assert_Expression
18871 (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
18873 -- In ASIS mode, for a pragma generated from a source aspect, also
18874 -- analyze the original aspect expression.
18876 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18877 Preanalyze_Assert_Expression
18878 (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
18882 if Present (Arg_Ens) then
18883 Preanalyze_Assert_Expression
18884 (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
18886 -- In ASIS mode, for a pragma generated from a source aspect, also
18887 -- analyze the original aspect expression.
18889 if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18890 Preanalyze_Assert_Expression
18891 (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
18894 end Preanalyze_CTC_Args;
18896 --------------------------------------
18897 -- Process_Compilation_Unit_Pragmas --
18898 --------------------------------------
18900 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
18902 -- A special check for pragma Suppress_All, a very strange DEC pragma,
18903 -- strange because it comes at the end of the unit. Rational has the
18904 -- same name for a pragma, but treats it as a program unit pragma, In
18905 -- GNAT we just decide to allow it anywhere at all. If it appeared then
18906 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
18907 -- node, and we insert a pragma Suppress (All_Checks) at the start of
18908 -- the context clause to ensure the correct processing.
18910 if Has_Pragma_Suppress_All (N) then
18911 Prepend_To (Context_Items (N),
18912 Make_Pragma (Sloc (N),
18913 Chars => Name_Suppress,
18914 Pragma_Argument_Associations => New_List (
18915 Make_Pragma_Argument_Association (Sloc (N),
18916 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
18919 -- Nothing else to do at the current time!
18921 end Process_Compilation_Unit_Pragmas;
18923 ----------------------------
18924 -- Rewrite_Assertion_Kind --
18925 ----------------------------
18927 procedure Rewrite_Assertion_Kind (N : Node_Id) is
18931 if Nkind (N) = N_Attribute_Reference
18932 and then Attribute_Name (N) = Name_Class
18933 and then Nkind (Prefix (N)) = N_Identifier
18935 case Chars (Prefix (N)) is
18940 when Name_Type_Invariant =>
18941 Nam := Name_uType_Invariant;
18942 when Name_Invariant =>
18943 Nam := Name_uInvariant;
18948 Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
18950 end Rewrite_Assertion_Kind;
18961 -----------------------------------
18962 -- Requires_Profile_Installation --
18963 -----------------------------------
18965 function Requires_Profile_Installation
18967 Subp : Node_Id) return Boolean
18970 -- When aspects Depends and Global are associated with a subprogram
18971 -- declaration, their corresponding pragmas are analyzed at the end of
18972 -- the declarative part. This is done out of context, therefore the
18973 -- formals must be installed in visibility.
18975 if Nkind (Subp) = N_Subprogram_Declaration then
18978 -- When aspects Depends and Global are associated with a subprogram body
18979 -- which is also a compilation unit, their corresponding pragmas appear
18980 -- in the Pragmas_After list. The Pragmas_After collection is analyzed
18981 -- out of context and the formals must be installed in visibility. This
18982 -- does not apply when the pragma is a source construct.
18984 elsif Nkind (Subp) = N_Subprogram_Body then
18985 if Nkind (Parent (Subp)) = N_Compilation_Unit then
18986 return Present (Corresponding_Aspect (Prag));
18991 -- In all other cases the two corresponding pragmas are analyzed in
18992 -- context and the formals are already visibile.
18997 end Requires_Profile_Installation;
18999 --------------------------------
19000 -- Set_Encoded_Interface_Name --
19001 --------------------------------
19003 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
19004 Str : constant String_Id := Strval (S);
19005 Len : constant Int := String_Length (Str);
19010 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
19013 -- Stores encoded value of character code CC. The encoding we use an
19014 -- underscore followed by four lower case hex digits.
19020 procedure Encode is
19022 Store_String_Char (Get_Char_Code ('_'));
19024 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
19026 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
19028 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
19030 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
19033 -- Start of processing for Set_Encoded_Interface_Name
19036 -- If first character is asterisk, this is a link name, and we leave it
19037 -- completely unmodified. We also ignore null strings (the latter case
19038 -- happens only in error cases) and no encoding should occur for Java or
19039 -- AAMP interface names.
19042 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
19043 or else VM_Target /= No_VM
19044 or else AAMP_On_Target
19046 Set_Interface_Name (E, S);
19051 CC := Get_String_Char (Str, J);
19053 exit when not In_Character_Range (CC);
19055 C := Get_Character (CC);
19057 exit when C /= '_' and then C /= '$'
19058 and then C not in '0' .. '9'
19059 and then C not in 'a' .. 'z'
19060 and then C not in 'A' .. 'Z';
19063 Set_Interface_Name (E, S);
19071 -- Here we need to encode. The encoding we use as follows:
19072 -- three underscores + four hex digits (lower case)
19076 for J in 1 .. String_Length (Str) loop
19077 CC := Get_String_Char (Str, J);
19079 if not In_Character_Range (CC) then
19082 C := Get_Character (CC);
19084 if C = '_' or else C = '$'
19085 or else C in '0' .. '9'
19086 or else C in 'a' .. 'z'
19087 or else C in 'A' .. 'Z'
19089 Store_String_Char (CC);
19096 Set_Interface_Name (E,
19097 Make_String_Literal (Sloc (S),
19098 Strval => End_String));
19100 end Set_Encoded_Interface_Name;
19102 -------------------
19103 -- Set_Unit_Name --
19104 -------------------
19106 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
19111 if Nkind (N) = N_Identifier
19112 and then Nkind (With_Item) = N_Identifier
19114 Set_Entity (N, Entity (With_Item));
19116 elsif Nkind (N) = N_Selected_Component then
19117 Change_Selected_Component_To_Expanded_Name (N);
19118 Set_Entity (N, Entity (With_Item));
19119 Set_Entity (Selector_Name (N), Entity (N));
19121 Pref := Prefix (N);
19122 Scop := Scope (Entity (N));
19123 while Nkind (Pref) = N_Selected_Component loop
19124 Change_Selected_Component_To_Expanded_Name (Pref);
19125 Set_Entity (Selector_Name (Pref), Scop);
19126 Set_Entity (Pref, Scop);
19127 Pref := Prefix (Pref);
19128 Scop := Scope (Scop);
19131 Set_Entity (Pref, Scop);