1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This unit contains the semantic processing for all pragmas, both language
28 -- and implementation defined. For most pragmas, the parser only does the
29 -- most basic job of checking the syntax, so Sem_Prag also contains the code
30 -- to complete the syntax checks. Certain pragmas are handled partially or
31 -- completely by the parser (see Par.Prag for further details).
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Expander; use Expander;
41 with Exp_Dist; use Exp_Dist;
42 with Fname; use Fname;
43 with Hostparm; use Hostparm;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet; use Namet;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Restrict; use Restrict;
53 with Rident; use Rident;
54 with Rtsfind; use Rtsfind;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch8; use Sem_Ch8;
58 with Sem_Ch13; use Sem_Ch13;
59 with Sem_Disp; use Sem_Disp;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Intr; use Sem_Intr;
63 with Sem_Mech; use Sem_Mech;
64 with Sem_Res; use Sem_Res;
65 with Sem_Type; use Sem_Type;
66 with Sem_Util; use Sem_Util;
67 with Sem_VFpt; use Sem_VFpt;
68 with Stand; use Stand;
69 with Sinfo; use Sinfo;
70 with Sinfo.CN; use Sinfo.CN;
71 with Sinput; use Sinput;
72 with Snames; use Snames;
73 with Stringt; use Stringt;
74 with Stylesw; use Stylesw;
75 with Targparm; use Targparm;
76 with Tbuild; use Tbuild;
78 with Uintp; use Uintp;
79 with Urealp; use Urealp;
80 with Validsw; use Validsw;
82 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
84 package body Sem_Prag is
86 ----------------------------------------------
87 -- Common Handling of Import-Export Pragmas --
88 ----------------------------------------------
90 -- In the following section, a number of Import_xxx and Export_xxx
91 -- pragmas are defined by GNAT. These are compatible with the DEC
92 -- pragmas of the same name, and all have the following common
93 -- form and processing:
96 -- [Internal =>] LOCAL_NAME,
97 -- [, [External =>] EXTERNAL_SYMBOL]
98 -- [, other optional parameters ]);
101 -- [Internal =>] LOCAL_NAME,
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
105 -- EXTERNAL_SYMBOL ::=
107 -- | static_string_EXPRESSION
109 -- The internal LOCAL_NAME designates the entity that is imported or
110 -- exported, and must refer to an entity in the current declarative
111 -- part (as required by the rules for LOCAL_NAME).
113 -- The external linker name is designated by the External parameter
114 -- if given, or the Internal parameter if not (if there is no External
115 -- parameter, the External parameter is a copy of the Internal name).
117 -- If the External parameter is given as a string, then this string
118 -- is treated as an external name (exactly as though it had been given
119 -- as an External_Name parameter for a normal Import pragma).
121 -- If the External parameter is given as an identifier (or there is no
122 -- External parameter, so that the Internal identifier is used), then
123 -- the external name is the characters of the identifier, translated
124 -- to all upper case letters for OpenVMS versions of GNAT, and to all
125 -- lower case letters for all other versions
127 -- Note: the external name specified or implied by any of these special
128 -- Import_xxx or Export_xxx pragmas override an external or link name
129 -- specified in a previous Import or Export pragma.
131 -- Note: these and all other DEC-compatible GNAT pragmas allow full
132 -- use of named notation, following the standard rules for subprogram
133 -- calls, i.e. parameters can be given in any order if named notation
134 -- is used, and positional and named notation can be mixed, subject to
135 -- the rule that all positional parameters must appear first.
137 -- Note: All these pragmas are implemented exactly following the DEC
138 -- design and implementation and are intended to be fully compatible
139 -- with the use of these pragmas in the DEC Ada compiler.
141 -------------------------------------
142 -- Local Subprograms and Variables --
143 -------------------------------------
145 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
146 -- This routine is used for possible casing adjustment of an explicit
147 -- external name supplied as a string literal (the node N), according
148 -- to the casing requirement of Opt.External_Name_Casing. If this is
149 -- set to As_Is, then the string literal is returned unchanged, but if
150 -- it is set to Uppercase or Lowercase, then a new string literal with
151 -- appropriate casing is constructed.
153 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
154 -- If Def_Id refers to a renamed subprogram, then the base subprogram
155 -- (the original one, following the renaming chain) is returned.
156 -- Otherwise the entity is returned unchanged. Should be in Einfo???
158 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
159 -- Place semantic information on the argument of an Elaborate or
160 -- Elaborate_All pragma. Entity name for unit and its parents is
161 -- taken from item in previous with_clause that mentions the unit.
163 -------------------------------
164 -- Adjust_External_Name_Case --
165 -------------------------------
167 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
171 -- Adjust case of literal if required
173 if Opt.External_Name_Exp_Casing = As_Is then
177 -- Copy existing string
183 for J in 1 .. String_Length (Strval (N)) loop
184 CC := Get_String_Char (Strval (N), J);
186 if Opt.External_Name_Exp_Casing = Uppercase
187 and then CC >= Get_Char_Code ('a')
188 and then CC <= Get_Char_Code ('z')
190 Store_String_Char (CC - 32);
192 elsif Opt.External_Name_Exp_Casing = Lowercase
193 and then CC >= Get_Char_Code ('A')
194 and then CC <= Get_Char_Code ('Z')
196 Store_String_Char (CC + 32);
199 Store_String_Char (CC);
204 Make_String_Literal (Sloc (N),
205 Strval => End_String);
207 end Adjust_External_Name_Case;
213 procedure Analyze_Pragma (N : Node_Id) is
214 Loc : constant Source_Ptr := Sloc (N);
217 Pragma_Exit : exception;
218 -- This exception is used to exit pragma processing completely. It
219 -- is used when an error is detected, and in other situations where
220 -- it is known that no further processing is required.
223 -- Number of pragma argument associations
229 -- First four pragma arguments (pragma argument association nodes,
230 -- or Empty if the corresponding argument does not exist).
232 procedure Check_Ada_83_Warning;
233 -- Issues a warning message for the current pragma if operating in Ada
234 -- 83 mode (used for language pragmas that are not a standard part of
235 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
238 procedure Check_Arg_Count (Required : Nat);
239 -- Check argument count for pragma is equal to given parameter.
240 -- If not, then issue an error message and raise Pragma_Exit.
242 -- Note: all routines whose name is Check_Arg_Is_xxx take an
243 -- argument Arg which can either be a pragma argument association,
244 -- in which case the check is applied to the expression of the
245 -- association or an expression directly.
247 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
248 -- Check the specified argument Arg to make sure that it is an
249 -- identifier. If not give error and raise Pragma_Exit.
251 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
252 -- Check the specified argument Arg to make sure that it is an
253 -- integer literal. If not give error and raise Pragma_Exit.
255 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
256 -- Check the specified argument Arg to make sure that it has the
257 -- proper syntactic form for a local name and meets the semantic
258 -- requirements for a local name. The local name is analyzed as
259 -- part of the processing for this call. In addition, the local
260 -- name is required to represent an entity at the library level.
262 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
263 -- Check the specified argument Arg to make sure that it has the
264 -- proper syntactic form for a local name and meets the semantic
265 -- requirements for a local name. The local name is analyzed as
266 -- part of the processing for this call.
268 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
269 -- Check the specified argument Arg to make sure that it is a valid
270 -- locking policy name. If not give error and raise Pragma_Exit.
272 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
273 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
274 -- Check the specified argument Arg to make sure that it is an
275 -- identifier whose name matches either N1 or N2 (or N3 if present).
276 -- If not then give error and raise Pragma_Exit.
278 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
279 -- Check the specified argument Arg to make sure that it is a valid
280 -- queuing policy name. If not give error and raise Pragma_Exit.
282 procedure Check_Arg_Is_Static_Expression
285 -- Check the specified argument Arg to make sure that it is a static
286 -- expression of the given type (i.e. it will be analyzed and resolved
287 -- using this type, which can be any valid argument to Resolve, e.g.
288 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
290 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
291 -- Check the specified argument Arg to make sure that it is a
292 -- string literal. If not give error and raise Pragma_Exit
294 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
295 -- Check the specified argument Arg to make sure that it is a valid
296 -- valid task dispatching policy name. If not give error and raise
299 procedure Check_At_Least_N_Arguments (N : Nat);
300 -- Check there are at least N arguments present
302 procedure Check_At_Most_N_Arguments (N : Nat);
303 -- Check there are no more than N arguments present
305 procedure Check_First_Subtype (Arg : Node_Id);
306 -- Checks that Arg, whose expression is an entity name referencing
307 -- a subtype, does not reference a type that is not a first subtype.
309 procedure Check_In_Main_Program;
310 -- Common checks for pragmas that appear within a main program
311 -- (Priority, Main_Storage, Time_Slice).
313 procedure Check_Interrupt_Or_Attach_Handler;
314 -- Common processing for first argument of pragma Interrupt_Handler
315 -- or pragma Attach_Handler.
317 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
318 -- Check that pragma appears in a declarative part, or in a package
319 -- specification, i.e. that it does not occur in a statement sequence
322 procedure Check_No_Identifier (Arg : Node_Id);
323 -- Checks that the given argument does not have an identifier. If
324 -- an identifier is present, then an error message is issued, and
325 -- Pragma_Exit is raised.
327 procedure Check_No_Identifiers;
328 -- Checks that none of the arguments to the pragma has an identifier.
329 -- If any argument has an identifier, then an error message is issued,
330 -- and Pragma_Exit is raised.
332 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
333 -- Checks if the given argument has an identifier, and if so, requires
334 -- it to match the given identifier name. If there is a non-matching
335 -- identifier, then an error message is given and Error_Pragmas raised.
337 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
338 -- Checks if the given argument has an identifier, and if so, requires
339 -- it to match the given identifier name. If there is a non-matching
340 -- identifier, then an error message is given and Error_Pragmas raised.
341 -- In this version of the procedure, the identifier name is given as
342 -- a string with lower case letters.
344 procedure Check_Static_Constraint (Constr : Node_Id);
345 -- Constr is a constraint from an N_Subtype_Indication node from a
346 -- component constraint in an Unchecked_Union type. This routine checks
347 -- that the constraint is static as required by the restrictions for
350 procedure Check_Valid_Configuration_Pragma;
351 -- Legality checks for placement of a configuration pragma
353 procedure Check_Valid_Library_Unit_Pragma;
354 -- Legality checks for library unit pragmas. A special case arises for
355 -- pragmas in generic instances that come from copies of the original
356 -- library unit pragmas in the generic templates. In the case of other
357 -- than library level instantiations these can appear in contexts which
358 -- would normally be invalid (they only apply to the original template
359 -- and to library level instantiations), and they are simply ignored,
360 -- which is implemented by rewriting them as null statements.
362 procedure Error_Pragma (Msg : String);
363 pragma No_Return (Error_Pragma);
364 -- Outputs error message for current pragma. The message contains an %
365 -- that will be replaced with the pragma name, and the flag is placed
366 -- on the pragma itself. Pragma_Exit is then raised.
368 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
369 pragma No_Return (Error_Pragma_Arg);
370 -- Outputs error message for current pragma. The message may contain
371 -- a % that will be replaced with the pragma name. The parameter Arg
372 -- may either be a pragma argument association, in which case the flag
373 -- is placed on the expression of this association, or an expression,
374 -- in which case the flag is placed directly on the expression. The
375 -- message is placed using Error_Msg_N, so the message may also contain
376 -- an & insertion character which will reference the given Arg value.
377 -- After placing the message, Pragma_Exit is raised.
379 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
380 pragma No_Return (Error_Pragma_Arg);
381 -- Similar to above form of Error_Pragma_Arg except that two messages
382 -- are provided, the second is a continuation comment starting with \.
384 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
385 pragma No_Return (Error_Pragma_Arg_Ident);
386 -- Outputs error message for current pragma. The message may contain
387 -- a % that will be replaced with the pragma name. The parameter Arg
388 -- must be a pragma argument association with a non-empty identifier
389 -- (i.e. its Chars field must be set), and the error message is placed
390 -- on the identifier. The message is placed using Error_Msg_N so
391 -- the message may also contain an & insertion character which will
392 -- reference the identifier. After placing the message, Pragma_Exit
395 function Find_Lib_Unit_Name return Entity_Id;
396 -- Used for a library unit pragma to find the entity to which the
397 -- library unit pragma applies, returns the entity found.
399 procedure Find_Program_Unit_Name (Id : Node_Id);
400 -- If the pragma is a compilation unit pragma, the id must denote the
401 -- compilation unit in the same compilation, and the pragma must appear
402 -- in the list of preceding or trailing pragmas. If it is a program
403 -- unit pragma that is not a compilation unit pragma, then the
404 -- identifier must be visible.
406 type Name_List is array (Natural range <>) of Name_Id;
407 type Args_List is array (Natural range <>) of Node_Id;
408 procedure Gather_Associations
410 Args : out Args_List);
411 -- This procedure is used to gather the arguments for a pragma that
412 -- permits arbitrary ordering of parameters using the normal rules
413 -- for named and positional parameters. The Names argument is a list
414 -- of Name_Id values that corresponds to the allowed pragma argument
415 -- association identifiers in order. The result returned in Args is
416 -- a list of corresponding expressions that are the pragma arguments.
417 -- Note that this is a list of expressions, not of pragma argument
418 -- associations (Gather_Associations has completely checked all the
419 -- optional identifiers when it returns). An entry in Args is Empty
420 -- on return if the corresponding argument is not present.
422 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
423 -- All the routines that check pragma arguments take either a pragma
424 -- argument association (in which case the expression of the argument
425 -- association is checked), or the expression directly. The function
426 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
427 -- Arg is a pragma argument association node, then its expression is
428 -- returned, otherwise Arg is returned unchanged.
430 procedure GNAT_Pragma;
431 -- Called for all GNAT defined pragmas to note the use of the feature,
432 -- and also check the relevant restriction (No_Implementation_Pragmas).
434 function Is_Before_First_Decl
435 (Pragma_Node : Node_Id;
436 Decls : List_Id) return Boolean;
437 -- Return True if Pragma_Node is before the first declarative item in
438 -- Decls where Decls is the list of declarative items.
440 function Is_Configuration_Pragma return Boolean;
441 -- Deterermines if the placement of the current pragma is appropriate
442 -- for a configuration pragma (precedes the current compilation unit)
444 procedure Pragma_Misplaced;
445 -- Issue fatal error message for misplaced pragma
447 procedure Process_Atomic_Shared_Volatile;
448 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
449 -- Shared is an obsolete Ada 83 pragma, treated as being identical
450 -- in effect to pragma Atomic.
452 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
453 -- Common procesing for Convention, Interface, Import and Export.
454 -- Checks first two arguments of pragma, and sets the appropriate
455 -- convention value in the specified entity or entities. On return
456 -- C is the convention, E is the referenced entity.
458 procedure Process_Extended_Import_Export_Exception_Pragma
459 (Arg_Internal : Node_Id;
460 Arg_External : Node_Id;
463 -- Common processing for the pragmas Import/Export_Exception.
464 -- The three arguments correspond to the three named parameters of
465 -- the pragma. An argument is empty if the corresponding parameter
466 -- is not present in the pragma.
468 procedure Process_Extended_Import_Export_Object_Pragma
469 (Arg_Internal : Node_Id;
470 Arg_External : Node_Id;
472 -- Common processing for the pragmass Import/Export_Object.
473 -- The three arguments correspond to the three named parameters
474 -- of the pragmas. An argument is empty if the corresponding
475 -- parameter is not present in the pragma.
477 procedure Process_Extended_Import_Export_Internal_Arg
478 (Arg_Internal : Node_Id := Empty);
479 -- Common processing for all extended Import and Export pragmas. The
480 -- argument is the pragma parameter for the Internal argument. If
481 -- Arg_Internal is empty or inappropriate, an error message is posted.
482 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
483 -- set to identify the referenced entity.
485 procedure Process_Extended_Import_Export_Subprogram_Pragma
486 (Arg_Internal : Node_Id;
487 Arg_External : Node_Id;
488 Arg_Parameter_Types : Node_Id;
489 Arg_Result_Type : Node_Id := Empty;
490 Arg_Mechanism : Node_Id;
491 Arg_Result_Mechanism : Node_Id := Empty;
492 Arg_First_Optional_Parameter : Node_Id := Empty);
493 -- Common processing for all extended Import and Export pragmas
494 -- applying to subprograms. The caller omits any arguments that do
495 -- bnot apply to the pragma in question (for example, Arg_Result_Type
496 -- can be non-Empty only in the Import_Function and Export_Function
497 -- cases). The argument names correspond to the allowed pragma
498 -- association identifiers.
500 procedure Process_Generic_List;
501 -- Common processing for Share_Generic and Inline_Generic
503 procedure Process_Import_Or_Interface;
504 -- Common processing for Import of Interface
506 procedure Process_Inline (Active : Boolean);
507 -- Common processing for Inline and Inline_Always. The parameter
508 -- indicates if the inline pragma is active, i.e. if it should
509 -- actually cause inlining to occur.
511 procedure Process_Interface_Name
512 (Subprogram_Def : Entity_Id;
515 -- Given the last two arguments of pragma Import, pragma Export, or
516 -- pragma Interface_Name, performs validity checks and sets the
517 -- Interface_Name field of the given subprogram entity to the
518 -- appropriate external or link name, depending on the arguments
519 -- given. Ext_Arg is always present, but Link_Arg may be missing.
520 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
521 -- missing, and appropriate named notation is used for Ext_Arg.
522 -- If neither Ext_Arg nor Link_Arg is present, the interface name
523 -- is set to the default from the subprogram name.
525 procedure Process_Interrupt_Or_Attach_Handler;
526 -- Common processing for Interrupt and Attach_Handler pragmas
528 procedure Process_Restrictions_Or_Restriction_Warnings;
529 -- Common processing for Restrictions and Restriction_Warnings pragmas
531 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
532 -- Common processing for Suppress and Unsuppress. The boolean parameter
533 -- Suppress_Case is True for the Suppress case, and False for the
536 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
537 -- This procedure sets the Is_Exported flag for the given entity,
538 -- checking that the entity was not previously imported. Arg is
539 -- the argument that specified the entity. A check is also made
540 -- for exporting inappropriate entities.
542 procedure Set_Extended_Import_Export_External_Name
543 (Internal_Ent : Entity_Id;
544 Arg_External : Node_Id);
545 -- Common processing for all extended import export pragmas. The first
546 -- argument, Internal_Ent, is the internal entity, which has already
547 -- been checked for validity by the caller. Arg_External is from the
548 -- Import or Export pragma, and may be null if no External parameter
549 -- was present. If Arg_External is present and is a non-null string
550 -- (a null string is treated as the default), then the Interface_Name
551 -- field of Internal_Ent is set appropriately.
553 procedure Set_Imported (E : Entity_Id);
554 -- This procedure sets the Is_Imported flag for the given entity,
555 -- checking that it is not previously exported or imported.
557 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
558 -- Mech is a parameter passing mechanism (see Import_Function syntax
559 -- for MECHANISM_NAME). This routine checks that the mechanism argument
560 -- has the right form, and if not issues an error message. If the
561 -- argument has the right form then the Mechanism field of Ent is
562 -- set appropriately.
564 procedure Set_Ravenscar_Profile (N : Node_Id);
565 -- Activate the set of configuration pragmas and restrictions that
566 -- make up the Ravenscar Profile. N is the corresponding pragma
567 -- node, which is used for error messages on any constructs
568 -- that violate the profile.
570 --------------------------
571 -- Check_Ada_83_Warning --
572 --------------------------
574 procedure Check_Ada_83_Warning is
576 if Ada_83 and then Comes_From_Source (N) then
577 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
579 end Check_Ada_83_Warning;
581 ---------------------
582 -- Check_Arg_Count --
583 ---------------------
585 procedure Check_Arg_Count (Required : Nat) is
587 if Arg_Count /= Required then
588 Error_Pragma ("wrong number of arguments for pragma%");
592 -----------------------------
593 -- Check_Arg_Is_Identifier --
594 -----------------------------
596 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
597 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
600 if Nkind (Argx) /= N_Identifier then
602 ("argument for pragma% must be identifier", Argx);
604 end Check_Arg_Is_Identifier;
606 ----------------------------------
607 -- Check_Arg_Is_Integer_Literal --
608 ----------------------------------
610 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
611 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
614 if Nkind (Argx) /= N_Integer_Literal then
616 ("argument for pragma% must be integer literal", Argx);
618 end Check_Arg_Is_Integer_Literal;
620 -------------------------------------------
621 -- Check_Arg_Is_Library_Level_Local_Name --
622 -------------------------------------------
626 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
627 -- | library_unit_NAME
629 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
631 Check_Arg_Is_Local_Name (Arg);
633 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
634 and then Comes_From_Source (N)
637 ("argument for pragma% must be library level entity", Arg);
639 end Check_Arg_Is_Library_Level_Local_Name;
641 -----------------------------
642 -- Check_Arg_Is_Local_Name --
643 -----------------------------
647 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
648 -- | library_unit_NAME
650 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
651 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
656 if Nkind (Argx) not in N_Direct_Name
657 and then (Nkind (Argx) /= N_Attribute_Reference
658 or else Present (Expressions (Argx))
659 or else Nkind (Prefix (Argx)) /= N_Identifier)
660 and then (not Is_Entity_Name (Argx)
661 or else not Is_Compilation_Unit (Entity (Argx)))
663 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
666 if Is_Entity_Name (Argx)
667 and then Scope (Entity (Argx)) /= Current_Scope
670 ("pragma% argument must be in same declarative part", Arg);
672 end Check_Arg_Is_Local_Name;
674 ---------------------------------
675 -- Check_Arg_Is_Locking_Policy --
676 ---------------------------------
678 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
679 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
682 Check_Arg_Is_Identifier (Argx);
684 if not Is_Locking_Policy_Name (Chars (Argx)) then
686 ("& is not a valid locking policy name", Argx);
688 end Check_Arg_Is_Locking_Policy;
690 -------------------------
691 -- Check_Arg_Is_One_Of --
692 -------------------------
694 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
695 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
698 Check_Arg_Is_Identifier (Argx);
700 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
701 Error_Msg_Name_2 := N1;
702 Error_Msg_Name_3 := N2;
703 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
705 end Check_Arg_Is_One_Of;
707 procedure Check_Arg_Is_One_Of
709 N1, N2, N3 : Name_Id)
711 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
714 Check_Arg_Is_Identifier (Argx);
716 if Chars (Argx) /= N1
717 and then Chars (Argx) /= N2
718 and then Chars (Argx) /= N3
720 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
722 end Check_Arg_Is_One_Of;
724 ---------------------------------
725 -- Check_Arg_Is_Queuing_Policy --
726 ---------------------------------
728 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
729 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
732 Check_Arg_Is_Identifier (Argx);
734 if not Is_Queuing_Policy_Name (Chars (Argx)) then
736 ("& is not a valid queuing policy name", Argx);
738 end Check_Arg_Is_Queuing_Policy;
740 ------------------------------------
741 -- Check_Arg_Is_Static_Expression --
742 ------------------------------------
744 procedure Check_Arg_Is_Static_Expression
748 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
751 Analyze_And_Resolve (Argx, Typ);
753 if Is_OK_Static_Expression (Argx) then
756 elsif Etype (Argx) = Any_Type then
759 -- An interesting special case, if we have a string literal and
760 -- we are in Ada 83 mode, then we allow it even though it will
761 -- not be flagged as static. This allows the use of Ada 95
762 -- pragmas like Import in Ada 83 mode. They will of course be
763 -- flagged with warnings as usual, but will not cause errors.
765 elsif Ada_83 and then Nkind (Argx) = N_String_Literal then
768 -- Static expression that raises Constraint_Error. This has
769 -- already been flagged, so just exit from pragma processing.
771 elsif Is_Static_Expression (Argx) then
774 -- Finally, we have a real error
777 Error_Msg_Name_1 := Chars (N);
779 ("argument for pragma% must be a static expression!", Argx);
782 end Check_Arg_Is_Static_Expression;
784 ---------------------------------
785 -- Check_Arg_Is_String_Literal --
786 ---------------------------------
788 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
789 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
792 if Nkind (Argx) /= N_String_Literal then
794 ("argument for pragma% must be string literal", Argx);
797 end Check_Arg_Is_String_Literal;
799 ------------------------------------------
800 -- Check_Arg_Is_Task_Dispatching_Policy --
801 ------------------------------------------
803 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
804 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
807 Check_Arg_Is_Identifier (Argx);
809 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
811 ("& is not a valid task dispatching policy name", Argx);
813 end Check_Arg_Is_Task_Dispatching_Policy;
815 --------------------------------
816 -- Check_At_Least_N_Arguments --
817 --------------------------------
819 procedure Check_At_Least_N_Arguments (N : Nat) is
821 if Arg_Count < N then
822 Error_Pragma ("too few arguments for pragma%");
824 end Check_At_Least_N_Arguments;
826 -------------------------------
827 -- Check_At_Most_N_Arguments --
828 -------------------------------
830 procedure Check_At_Most_N_Arguments (N : Nat) is
834 if Arg_Count > N then
839 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
842 end Check_At_Most_N_Arguments;
844 -------------------------
845 -- Check_First_Subtype --
846 -------------------------
848 procedure Check_First_Subtype (Arg : Node_Id) is
849 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
852 if not Is_First_Subtype (Entity (Argx)) then
854 ("pragma% cannot apply to subtype", Argx);
856 end Check_First_Subtype;
858 ---------------------------
859 -- Check_In_Main_Program --
860 ---------------------------
862 procedure Check_In_Main_Program is
863 P : constant Node_Id := Parent (N);
866 -- Must be at in subprogram body
868 if Nkind (P) /= N_Subprogram_Body then
869 Error_Pragma ("% pragma allowed only in subprogram");
871 -- Otherwise warn if obviously not main program
873 elsif Present (Parameter_Specifications (Specification (P)))
874 or else not Is_Compilation_Unit (Defining_Entity (P))
876 Error_Msg_Name_1 := Chars (N);
878 ("?pragma% is only effective in main program", N);
880 end Check_In_Main_Program;
882 ---------------------------------------
883 -- Check_Interrupt_Or_Attach_Handler --
884 ---------------------------------------
886 procedure Check_Interrupt_Or_Attach_Handler is
887 Arg1_X : constant Node_Id := Expression (Arg1);
892 if not Is_Entity_Name (Arg1_X) then
894 ("argument of pragma% must be entity name", Arg1);
896 elsif Prag_Id = Pragma_Interrupt_Handler then
897 Check_Restriction (No_Dynamic_Attachment, N);
901 Handler_Proc : Entity_Id := Empty;
902 Proc_Scope : Entity_Id;
903 Found : Boolean := False;
906 if not Is_Overloaded (Arg1_X) then
907 Handler_Proc := Entity (Arg1_X);
912 Index : Interp_Index;
915 Get_First_Interp (Arg1_X, Index, It);
916 while Present (It.Nam) loop
917 Handler_Proc := It.Nam;
919 if Ekind (Handler_Proc) = E_Procedure
920 and then No (First_Formal (Handler_Proc))
924 Set_Entity (Arg1_X, Handler_Proc);
925 Set_Is_Overloaded (Arg1_X, False);
928 ("ambiguous handler name for pragma% ", Arg1);
932 Get_Next_Interp (Index, It);
937 ("argument of pragma% must be parameterless procedure",
940 Handler_Proc := Entity (Arg1_X);
945 Proc_Scope := Scope (Handler_Proc);
947 -- On AAMP only, a pragma Interrupt_Handler is supported for
948 -- nonprotected parameterless procedures.
951 and then Prag_Id = Pragma_Interrupt_Handler
953 if Ekind (Handler_Proc) /= E_Procedure then
955 ("argument of pragma% must be a procedure", Arg1);
958 elsif Ekind (Handler_Proc) /= E_Procedure
959 or else Ekind (Proc_Scope) /= E_Protected_Type
962 ("argument of pragma% must be protected procedure", Arg1);
965 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
966 and then Ekind (Proc_Scope) = E_Protected_Type
969 Protected_Definition (Parent (Proc_Scope))
971 Error_Pragma ("pragma% must be in protected definition");
975 if not Is_Library_Level_Entity (Proc_Scope)
976 or else (AAMP_On_Target
977 and then not Is_Library_Level_Entity (Handler_Proc))
980 ("pragma% requires library-level entity", Arg1);
983 if Present (First_Formal (Handler_Proc)) then
985 ("argument of pragma% must be parameterless procedure",
989 end Check_Interrupt_Or_Attach_Handler;
991 -------------------------------------------
992 -- Check_Is_In_Decl_Part_Or_Package_Spec --
993 -------------------------------------------
995 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1004 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1007 elsif Nkind (P) = N_Package_Specification then
1010 elsif Nkind (P) = N_Block_Statement then
1013 -- Note: the following tests seem a little peculiar, because
1014 -- they test for bodies, but if we were in the statement part
1015 -- of the body, we would already have hit the handled statement
1016 -- sequence, so the only way we get here is by being in the
1017 -- declarative part of the body.
1019 elsif Nkind (P) = N_Subprogram_Body
1020 or else Nkind (P) = N_Package_Body
1021 or else Nkind (P) = N_Task_Body
1022 or else Nkind (P) = N_Entry_Body
1030 Error_Pragma ("pragma% is not in declarative part or package spec");
1031 end Check_Is_In_Decl_Part_Or_Package_Spec;
1033 -------------------------
1034 -- Check_No_Identifier --
1035 -------------------------
1037 procedure Check_No_Identifier (Arg : Node_Id) is
1039 if Chars (Arg) /= No_Name then
1040 Error_Pragma_Arg_Ident
1041 ("pragma% does not permit identifier& here", Arg);
1043 end Check_No_Identifier;
1045 --------------------------
1046 -- Check_No_Identifiers --
1047 --------------------------
1049 procedure Check_No_Identifiers is
1053 if Arg_Count > 0 then
1056 while Present (Arg_Node) loop
1057 Check_No_Identifier (Arg_Node);
1061 end Check_No_Identifiers;
1063 -------------------------------
1064 -- Check_Optional_Identifier --
1065 -------------------------------
1067 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1069 if Present (Arg) and then Chars (Arg) /= No_Name then
1070 if Chars (Arg) /= Id then
1071 Error_Msg_Name_1 := Chars (N);
1072 Error_Msg_Name_2 := Id;
1073 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1077 end Check_Optional_Identifier;
1079 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1081 Name_Buffer (1 .. Id'Length) := Id;
1082 Name_Len := Id'Length;
1083 Check_Optional_Identifier (Arg, Name_Find);
1084 end Check_Optional_Identifier;
1086 -----------------------------
1087 -- Check_Static_Constraint --
1088 -----------------------------
1090 -- Note: for convenience in writing this procedure, in addition to
1091 -- the officially (i.e. by spec) allowed argument which is always
1092 -- a constraint, it also allows ranges and discriminant associations.
1093 -- Above is not clear ???
1095 procedure Check_Static_Constraint (Constr : Node_Id) is
1097 --------------------
1098 -- Require_Static --
1099 --------------------
1101 procedure Require_Static (E : Node_Id);
1102 -- Require given expression to be static expression
1104 procedure Require_Static (E : Node_Id) is
1106 if not Is_OK_Static_Expression (E) then
1107 Flag_Non_Static_Expr
1108 ("non-static constraint not allowed in Unchecked_Union!", E);
1113 -- Start of processing for Check_Static_Constraint
1116 case Nkind (Constr) is
1117 when N_Discriminant_Association =>
1118 Require_Static (Expression (Constr));
1121 Require_Static (Low_Bound (Constr));
1122 Require_Static (High_Bound (Constr));
1124 when N_Attribute_Reference =>
1125 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1126 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1128 when N_Range_Constraint =>
1129 Check_Static_Constraint (Range_Expression (Constr));
1131 when N_Index_Or_Discriminant_Constraint =>
1133 IDC : Entity_Id := First (Constraints (Constr));
1135 while Present (IDC) loop
1136 Check_Static_Constraint (IDC);
1144 end Check_Static_Constraint;
1146 --------------------------------------
1147 -- Check_Valid_Configuration_Pragma --
1148 --------------------------------------
1150 -- A configuration pragma must appear in the context clause of
1151 -- a compilation unit, at the start of the list (i.e. only other
1152 -- pragmas may precede it).
1154 procedure Check_Valid_Configuration_Pragma is
1156 if not Is_Configuration_Pragma then
1157 Error_Pragma ("incorrect placement for configuration pragma%");
1159 end Check_Valid_Configuration_Pragma;
1161 -------------------------------------
1162 -- Check_Valid_Library_Unit_Pragma --
1163 -------------------------------------
1165 procedure Check_Valid_Library_Unit_Pragma is
1167 Parent_Node : Node_Id;
1168 Unit_Name : Entity_Id;
1169 Unit_Kind : Node_Kind;
1170 Unit_Node : Node_Id;
1171 Sindex : Source_File_Index;
1174 if not Is_List_Member (N) then
1178 Plist := List_Containing (N);
1179 Parent_Node := Parent (Plist);
1181 if Parent_Node = Empty then
1184 -- Case of pragma appearing after a compilation unit. In this
1185 -- case it must have an argument with the corresponding name
1186 -- and must be part of the following pragmas of its parent.
1188 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1189 if Plist /= Pragmas_After (Parent_Node) then
1192 elsif Arg_Count = 0 then
1194 ("argument required if outside compilation unit");
1197 Check_No_Identifiers;
1198 Check_Arg_Count (1);
1199 Unit_Node := Unit (Parent (Parent_Node));
1200 Unit_Kind := Nkind (Unit_Node);
1202 Analyze (Expression (Arg1));
1204 if Unit_Kind = N_Generic_Subprogram_Declaration
1205 or else Unit_Kind = N_Subprogram_Declaration
1207 Unit_Name := Defining_Entity (Unit_Node);
1209 elsif Unit_Kind = N_Function_Instantiation
1210 or else Unit_Kind = N_Package_Instantiation
1211 or else Unit_Kind = N_Procedure_Instantiation
1213 Unit_Name := Defining_Entity (Unit_Node);
1216 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1219 if Chars (Unit_Name) /=
1220 Chars (Entity (Expression (Arg1)))
1223 ("pragma% argument is not current unit name", Arg1);
1226 if Ekind (Unit_Name) = E_Package
1227 and then Present (Renamed_Entity (Unit_Name))
1229 Error_Pragma ("pragma% not allowed for renamed package");
1233 -- Pragma appears other than after a compilation unit
1236 -- Here we check for the generic instantiation case and also
1237 -- for the case of processing a generic formal package. We
1238 -- detect these cases by noting that the Sloc on the node
1239 -- does not belong to the current compilation unit.
1241 Sindex := Source_Index (Current_Sem_Unit);
1243 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1244 Rewrite (N, Make_Null_Statement (Loc));
1247 -- If before first declaration, the pragma applies to the
1248 -- enclosing unit, and the name if present must be this name.
1250 elsif Is_Before_First_Decl (N, Plist) then
1251 Unit_Node := Unit_Declaration_Node (Current_Scope);
1252 Unit_Kind := Nkind (Unit_Node);
1254 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1257 elsif Unit_Kind = N_Subprogram_Body
1258 and then not Acts_As_Spec (Unit_Node)
1262 elsif Nkind (Parent_Node) = N_Package_Body then
1265 elsif Nkind (Parent_Node) = N_Package_Specification
1266 and then Plist = Private_Declarations (Parent_Node)
1270 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1271 or else Nkind (Parent_Node)
1272 = N_Generic_Subprogram_Declaration)
1273 and then Plist = Generic_Formal_Declarations (Parent_Node)
1277 elsif Arg_Count > 0 then
1278 Analyze (Expression (Arg1));
1280 if Entity (Expression (Arg1)) /= Current_Scope then
1282 ("name in pragma% must be enclosing unit", Arg1);
1285 -- It is legal to have no argument in this context
1291 -- Error if not before first declaration. This is because a
1292 -- library unit pragma argument must be the name of a library
1293 -- unit (RM 10.1.5(7)), but the only names permitted in this
1294 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1295 -- generic subprogram declarations or generic instantiations.
1299 ("pragma% misplaced, must be before first declaration");
1303 end Check_Valid_Library_Unit_Pragma;
1309 procedure Error_Pragma (Msg : String) is
1311 Error_Msg_Name_1 := Chars (N);
1312 Error_Msg_N (Msg, N);
1316 ----------------------
1317 -- Error_Pragma_Arg --
1318 ----------------------
1320 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1322 Error_Msg_Name_1 := Chars (N);
1323 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1325 end Error_Pragma_Arg;
1327 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1329 Error_Msg_Name_1 := Chars (N);
1330 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1331 Error_Pragma_Arg (Msg2, Arg);
1332 end Error_Pragma_Arg;
1334 ----------------------------
1335 -- Error_Pragma_Arg_Ident --
1336 ----------------------------
1338 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1340 Error_Msg_Name_1 := Chars (N);
1341 Error_Msg_N (Msg, Arg);
1343 end Error_Pragma_Arg_Ident;
1345 ------------------------
1346 -- Find_Lib_Unit_Name --
1347 ------------------------
1349 function Find_Lib_Unit_Name return Entity_Id is
1351 -- Return inner compilation unit entity, for case of nested
1352 -- categorization pragmas. This happens in generic unit.
1354 if Nkind (Parent (N)) = N_Package_Specification
1355 and then Defining_Entity (Parent (N)) /= Current_Scope
1357 return Defining_Entity (Parent (N));
1359 return Current_Scope;
1361 end Find_Lib_Unit_Name;
1363 ----------------------------
1364 -- Find_Program_Unit_Name --
1365 ----------------------------
1367 procedure Find_Program_Unit_Name (Id : Node_Id) is
1368 Unit_Name : Entity_Id;
1369 Unit_Kind : Node_Kind;
1370 P : constant Node_Id := Parent (N);
1373 if Nkind (P) = N_Compilation_Unit then
1374 Unit_Kind := Nkind (Unit (P));
1376 if Unit_Kind = N_Subprogram_Declaration
1377 or else Unit_Kind = N_Package_Declaration
1378 or else Unit_Kind in N_Generic_Declaration
1380 Unit_Name := Defining_Entity (Unit (P));
1382 if Chars (Id) = Chars (Unit_Name) then
1383 Set_Entity (Id, Unit_Name);
1384 Set_Etype (Id, Etype (Unit_Name));
1386 Set_Etype (Id, Any_Type);
1388 ("cannot find program unit referenced by pragma%");
1392 Set_Etype (Id, Any_Type);
1393 Error_Pragma ("pragma% inapplicable to this unit");
1400 end Find_Program_Unit_Name;
1402 -------------------------
1403 -- Gather_Associations --
1404 -------------------------
1406 procedure Gather_Associations
1408 Args : out Args_List)
1413 -- Initialize all parameters to Empty
1415 for J in Args'Range loop
1419 -- That's all we have to do if there are no argument associations
1421 if No (Pragma_Argument_Associations (N)) then
1425 -- Otherwise first deal with any positional parameters present
1427 Arg := First (Pragma_Argument_Associations (N));
1429 for Index in Args'Range loop
1430 exit when No (Arg) or else Chars (Arg) /= No_Name;
1431 Args (Index) := Expression (Arg);
1435 -- Positional parameters all processed, if any left, then we
1436 -- have too many positional parameters.
1438 if Present (Arg) and then Chars (Arg) = No_Name then
1440 ("too many positional associations for pragma%", Arg);
1443 -- Process named parameters if any are present
1445 while Present (Arg) loop
1446 if Chars (Arg) = No_Name then
1448 ("positional association cannot follow named association",
1452 for Index in Names'Range loop
1453 if Names (Index) = Chars (Arg) then
1454 if Present (Args (Index)) then
1456 ("duplicate argument association for pragma%", Arg);
1458 Args (Index) := Expression (Arg);
1463 if Index = Names'Last then
1464 Error_Msg_Name_1 := Chars (N);
1465 Error_Msg_N ("pragma% does not allow & argument", Arg);
1467 -- Check for possible misspelling
1469 for Index1 in Names'Range loop
1470 if Is_Bad_Spelling_Of
1471 (Get_Name_String (Chars (Arg)),
1472 Get_Name_String (Names (Index1)))
1474 Error_Msg_Name_1 := Names (Index1);
1475 Error_Msg_N ("\possible misspelling of%", Arg);
1487 end Gather_Associations;
1489 --------------------
1490 -- Get_Pragma_Arg --
1491 --------------------
1493 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1495 if Nkind (Arg) = N_Pragma_Argument_Association then
1496 return Expression (Arg);
1506 procedure GNAT_Pragma is
1508 Check_Restriction (No_Implementation_Pragmas, N);
1511 --------------------------
1512 -- Is_Before_First_Decl --
1513 --------------------------
1515 function Is_Before_First_Decl
1516 (Pragma_Node : Node_Id;
1517 Decls : List_Id) return Boolean
1519 Item : Node_Id := First (Decls);
1522 -- Only other pragmas can come before this pragma
1525 if No (Item) or else Nkind (Item) /= N_Pragma then
1528 elsif Item = Pragma_Node then
1534 end Is_Before_First_Decl;
1536 -----------------------------
1537 -- Is_Configuration_Pragma --
1538 -----------------------------
1540 -- A configuration pragma must appear in the context clause of
1541 -- a compilation unit, at the start of the list (i.e. only other
1542 -- pragmas may precede it).
1544 function Is_Configuration_Pragma return Boolean is
1545 Lis : constant List_Id := List_Containing (N);
1546 Par : constant Node_Id := Parent (N);
1550 -- If no parent, then we are in the configuration pragma file,
1551 -- so the placement is definitely appropriate.
1556 -- Otherwise we must be in the context clause of a compilation unit
1557 -- and the only thing allowed before us in the context list is more
1558 -- configuration pragmas.
1560 elsif Nkind (Par) = N_Compilation_Unit
1561 and then Context_Items (Par) = Lis
1568 elsif Nkind (Prg) /= N_Pragma then
1578 end Is_Configuration_Pragma;
1580 ----------------------
1581 -- Pragma_Misplaced --
1582 ----------------------
1584 procedure Pragma_Misplaced is
1586 Error_Pragma ("incorrect placement of pragma%");
1587 end Pragma_Misplaced;
1589 ------------------------------------
1590 -- Process Atomic_Shared_Volatile --
1591 ------------------------------------
1593 procedure Process_Atomic_Shared_Volatile is
1601 Check_Ada_83_Warning;
1602 Check_No_Identifiers;
1603 Check_Arg_Count (1);
1604 Check_Arg_Is_Local_Name (Arg1);
1605 E_Id := Expression (Arg1);
1607 if Etype (E_Id) = Any_Type then
1612 D := Declaration_Node (E);
1616 if Rep_Item_Too_Early (E, N)
1618 Rep_Item_Too_Late (E, N)
1622 Check_First_Subtype (Arg1);
1625 if Prag_Id /= Pragma_Volatile then
1627 Set_Is_Atomic (Underlying_Type (E));
1630 -- Attribute belongs on the base type. If the
1631 -- view of the type is currently private, it also
1632 -- belongs on the underlying type.
1634 Set_Is_Volatile (Base_Type (E));
1635 Set_Is_Volatile (Underlying_Type (E));
1637 Set_Treat_As_Volatile (E);
1638 Set_Treat_As_Volatile (Underlying_Type (E));
1640 elsif K = N_Object_Declaration
1641 or else (K = N_Component_Declaration
1642 and then Original_Record_Component (E) = E)
1644 if Rep_Item_Too_Late (E, N) then
1648 if Prag_Id /= Pragma_Volatile then
1651 -- If the object declaration has an explicit
1652 -- initialization, a temporary may have to be
1653 -- created to hold the expression, to insure
1654 -- that access to the object remain atomic.
1656 if Nkind (Parent (E)) = N_Object_Declaration
1657 and then Present (Expression (Parent (E)))
1659 Set_Has_Delayed_Freeze (E);
1662 -- An interesting improvement here. If an object of type X
1663 -- is declared atomic, and the type X is not atomic, that's
1664 -- a pity, since it may not have appropraite alignment etc.
1665 -- We can rescue this in the special case where the object
1666 -- and type are in the same unit by just setting the type
1667 -- as atomic, so that the back end will process it as atomic.
1669 Utyp := Underlying_Type (Etype (E));
1672 and then Sloc (E) > No_Location
1673 and then Sloc (Utyp) > No_Location
1675 Get_Source_File_Index (Sloc (E)) =
1676 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1678 Set_Is_Atomic (Underlying_Type (Etype (E)));
1682 Set_Is_Volatile (E);
1683 Set_Treat_As_Volatile (E);
1687 ("inappropriate entity for pragma%", Arg1);
1689 end Process_Atomic_Shared_Volatile;
1691 ------------------------
1692 -- Process_Convention --
1693 ------------------------
1695 procedure Process_Convention
1696 (C : out Convention_Id;
1702 Comp_Unit : Unit_Number_Type;
1704 procedure Set_Convention_From_Pragma (E : Entity_Id);
1705 -- Set convention in entity E, and also flag that the entity has a
1706 -- convention pragma. If entity is for a private or incomplete type,
1707 -- also set convention and flag on underlying type. This procedure
1708 -- also deals with the special case of C_Pass_By_Copy convention.
1710 --------------------------------
1711 -- Set_Convention_From_Pragma --
1712 --------------------------------
1714 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1716 Set_Convention (E, C);
1717 Set_Has_Convention_Pragma (E);
1719 if Is_Incomplete_Or_Private_Type (E) then
1720 Set_Convention (Underlying_Type (E), C);
1721 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1724 -- A class-wide type should inherit the convention of
1725 -- the specific root type (although this isn't specified
1726 -- clearly by the RM).
1728 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1729 Set_Convention (Class_Wide_Type (E), C);
1732 -- If the entity is a record type, then check for special case
1733 -- of C_Pass_By_Copy, which is treated the same as C except that
1734 -- the special record flag is set. This convention is also only
1735 -- permitted on record types (see AI95-00131).
1737 if Cname = Name_C_Pass_By_Copy then
1738 if Is_Record_Type (E) then
1739 Set_C_Pass_By_Copy (Base_Type (E));
1740 elsif Is_Incomplete_Or_Private_Type (E)
1741 and then Is_Record_Type (Underlying_Type (E))
1743 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1746 ("C_Pass_By_Copy convention allowed only for record type",
1751 -- If the entity is a derived boolean type, check for the
1752 -- special case of convention C, C++, or Fortran, where we
1753 -- consider any nonzero value to represent true.
1755 if Is_Discrete_Type (E)
1756 and then Root_Type (Etype (E)) = Standard_Boolean
1762 C = Convention_Fortran)
1764 Set_Nonzero_Is_True (Base_Type (E));
1766 end Set_Convention_From_Pragma;
1768 -- Start of processing for Process_Convention
1771 Check_At_Least_N_Arguments (2);
1772 Check_Arg_Is_Identifier (Arg1);
1773 Check_Optional_Identifier (Arg1, Name_Convention);
1774 Cname := Chars (Expression (Arg1));
1776 -- C_Pass_By_Copy is treated as a synonym for convention C
1777 -- (this is tested again below to set the critical flag)
1779 if Cname = Name_C_Pass_By_Copy then
1782 -- Otherwise we must have something in the standard convention list
1784 elsif Is_Convention_Name (Cname) then
1785 C := Get_Convention_Id (Chars (Expression (Arg1)));
1787 -- In DEC VMS, it seems that there is an undocumented feature
1788 -- that any unrecognized convention is treated as the default,
1789 -- which for us is convention C. It does not seem so terrible
1790 -- to do this unconditionally, silently in the VMS case, and
1791 -- with a warning in the non-VMS case.
1794 if Warn_On_Export_Import and not OpenVMS_On_Target then
1796 ("?unrecognized convention name, C assumed",
1803 Check_Arg_Is_Local_Name (Arg2);
1804 Check_Optional_Identifier (Arg2, Name_Entity);
1806 Id := Expression (Arg2);
1809 if not Is_Entity_Name (Id) then
1810 Error_Pragma_Arg ("entity name required", Arg2);
1815 -- Go to renamed subprogram if present, since convention applies
1816 -- to the actual renamed entity, not to the renaming entity.
1818 if Is_Subprogram (E)
1819 and then Present (Alias (E))
1820 and then Nkind (Parent (Declaration_Node (E))) =
1821 N_Subprogram_Renaming_Declaration
1826 -- Check that we not applying this to a specless body
1828 if Is_Subprogram (E)
1829 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
1832 ("pragma% requires separate spec and must come before body");
1835 -- Check that we are not applying this to a named constant
1837 if Ekind (E) = E_Named_Integer
1839 Ekind (E) = E_Named_Real
1841 Error_Msg_Name_1 := Chars (N);
1843 ("cannot apply pragma% to named constant!",
1844 Get_Pragma_Arg (Arg2));
1846 ("\supply appropriate type for&!", Arg2);
1849 if Etype (E) = Any_Type
1850 or else Rep_Item_Too_Early (E, N)
1854 E := Underlying_Type (E);
1857 if Rep_Item_Too_Late (E, N) then
1861 if Has_Convention_Pragma (E) then
1863 ("at most one Convention/Export/Import pragma is allowed", Arg2);
1865 elsif Convention (E) = Convention_Protected
1866 or else Ekind (Scope (E)) = E_Protected_Type
1869 ("a protected operation cannot be given a different convention",
1873 -- For Intrinsic, a subprogram is required
1875 if C = Convention_Intrinsic
1876 and then not Is_Subprogram (E)
1877 and then not Is_Generic_Subprogram (E)
1880 ("second argument of pragma% must be a subprogram", Arg2);
1883 -- For Stdcall, a subprogram, variable or subprogram type is required
1885 if C = Convention_Stdcall
1886 and then not Is_Subprogram (E)
1887 and then not Is_Generic_Subprogram (E)
1888 and then Ekind (E) /= E_Variable
1891 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
1894 ("second argument of pragma% must be subprogram (type)",
1898 if not Is_Subprogram (E)
1899 and then not Is_Generic_Subprogram (E)
1901 Set_Convention_From_Pragma (E);
1905 Check_First_Subtype (Arg2);
1906 Set_Convention_From_Pragma (Base_Type (E));
1908 -- For subprograms, we must set the convention on the
1909 -- internally generated directly designated type as well.
1911 if Ekind (E) = E_Access_Subprogram_Type then
1912 Set_Convention_From_Pragma (Directly_Designated_Type (E));
1916 -- For the subprogram case, set proper convention for all homonyms
1917 -- in same scope and the same declarative part, i.e. the same
1918 -- compilation unit.
1921 Comp_Unit := Get_Source_Unit (E);
1922 Set_Convention_From_Pragma (E);
1924 -- Treat a pragma Import as an implicit body, for GPS use.
1926 if Prag_Id = Pragma_Import then
1927 Generate_Reference (E, Id, 'b');
1933 exit when No (E1) or else Scope (E1) /= Current_Scope;
1935 -- Note: below we are missing a check for Rep_Item_Too_Late.
1936 -- That is deliberate, we cannot chain the rep item on more
1937 -- than one Rep_Item chain, to be fixed later ???
1939 if Comes_From_Source (E1)
1940 and then Comp_Unit = Get_Source_Unit (E1)
1941 and then Nkind (Original_Node (Parent (E1))) /=
1942 N_Full_Type_Declaration
1944 Set_Convention_From_Pragma (E1);
1946 if Prag_Id = Pragma_Import then
1947 Generate_Reference (E, Id, 'b');
1952 end Process_Convention;
1954 -----------------------------------------------------
1955 -- Process_Extended_Import_Export_Exception_Pragma --
1956 -----------------------------------------------------
1958 procedure Process_Extended_Import_Export_Exception_Pragma
1959 (Arg_Internal : Node_Id;
1960 Arg_External : Node_Id;
1970 if not OpenVMS_On_Target then
1972 ("?pragma% ignored (applies only to Open'V'M'S)");
1975 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
1976 Def_Id := Entity (Arg_Internal);
1978 if Ekind (Def_Id) /= E_Exception then
1980 ("pragma% must refer to declared exception", Arg_Internal);
1983 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
1985 if Present (Arg_Form) then
1986 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
1989 if Present (Arg_Form)
1990 and then Chars (Arg_Form) = Name_Ada
1994 Set_Is_VMS_Exception (Def_Id);
1995 Set_Exception_Code (Def_Id, No_Uint);
1998 if Present (Arg_Code) then
1999 if not Is_VMS_Exception (Def_Id) then
2001 ("Code option for pragma% not allowed for Ada case",
2005 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2006 Code_Val := Expr_Value (Arg_Code);
2008 if not UI_Is_In_Int_Range (Code_Val) then
2010 ("Code option for pragma% must be in 32-bit range",
2014 Set_Exception_Code (Def_Id, Code_Val);
2017 end Process_Extended_Import_Export_Exception_Pragma;
2019 -------------------------------------------------
2020 -- Process_Extended_Import_Export_Internal_Arg --
2021 -------------------------------------------------
2023 procedure Process_Extended_Import_Export_Internal_Arg
2024 (Arg_Internal : Node_Id := Empty)
2029 if No (Arg_Internal) then
2030 Error_Pragma ("Internal parameter required for pragma%");
2033 if Nkind (Arg_Internal) = N_Identifier then
2036 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2037 and then (Prag_Id = Pragma_Import_Function
2039 Prag_Id = Pragma_Export_Function)
2045 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2048 Check_Arg_Is_Local_Name (Arg_Internal);
2049 end Process_Extended_Import_Export_Internal_Arg;
2051 --------------------------------------------------
2052 -- Process_Extended_Import_Export_Object_Pragma --
2053 --------------------------------------------------
2055 procedure Process_Extended_Import_Export_Object_Pragma
2056 (Arg_Internal : Node_Id;
2057 Arg_External : Node_Id;
2063 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2064 Def_Id := Entity (Arg_Internal);
2066 if Ekind (Def_Id) /= E_Constant
2067 and then Ekind (Def_Id) /= E_Variable
2070 ("pragma% must designate an object", Arg_Internal);
2073 if Is_Psected (Def_Id) then
2075 ("previous Psect_Object applies, pragma % not permitted",
2079 if Rep_Item_Too_Late (Def_Id, N) then
2083 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2085 if Present (Arg_Size)
2086 and then Nkind (Arg_Size) /= N_Identifier
2087 and then Nkind (Arg_Size) /= N_String_Literal
2090 ("pragma% Size argument must be identifier or string literal",
2094 -- Export_Object case
2096 if Prag_Id = Pragma_Export_Object then
2097 if not Is_Library_Level_Entity (Def_Id) then
2099 ("argument for pragma% must be library level entity",
2103 if Ekind (Current_Scope) = E_Generic_Package then
2104 Error_Pragma ("pragma& cannot appear in a generic unit");
2107 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2109 ("exported object must have compile time known size",
2113 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2115 ("?duplicate Export_Object pragma", N);
2117 Set_Exported (Def_Id, Arg_Internal);
2120 -- Import_Object case
2123 if Is_Concurrent_Type (Etype (Def_Id)) then
2125 ("cannot use pragma% for task/protected object",
2129 if Ekind (Def_Id) = E_Constant then
2131 ("cannot import a constant", Arg_Internal);
2134 if Warn_On_Export_Import
2135 and then Has_Discriminants (Etype (Def_Id))
2138 ("imported value must be initialized?", Arg_Internal);
2141 if Warn_On_Export_Import
2142 and then Is_Access_Type (Etype (Def_Id))
2145 ("cannot import object of an access type?", Arg_Internal);
2148 if Warn_On_Export_Import
2149 and then Is_Imported (Def_Id)
2152 ("?duplicate Import_Object pragma", N);
2154 -- Check for explicit initialization present. Note that an
2155 -- initialization that generated by the code generator, e.g.
2156 -- for an access type, does not count here.
2158 elsif Present (Expression (Parent (Def_Id)))
2161 (Original_Node (Expression (Parent (Def_Id))))
2163 Error_Msg_Sloc := Sloc (Def_Id);
2165 ("no initialization allowed for declaration of& #",
2166 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2169 Set_Imported (Def_Id);
2170 Note_Possible_Modification (Arg_Internal);
2173 end Process_Extended_Import_Export_Object_Pragma;
2175 ------------------------------------------------------
2176 -- Process_Extended_Import_Export_Subprogram_Pragma --
2177 ------------------------------------------------------
2179 procedure Process_Extended_Import_Export_Subprogram_Pragma
2180 (Arg_Internal : Node_Id;
2181 Arg_External : Node_Id;
2182 Arg_Parameter_Types : Node_Id;
2183 Arg_Result_Type : Node_Id := Empty;
2184 Arg_Mechanism : Node_Id;
2185 Arg_Result_Mechanism : Node_Id := Empty;
2186 Arg_First_Optional_Parameter : Node_Id := Empty)
2192 Ambiguous : Boolean;
2196 function Same_Base_Type
2198 Formal : Entity_Id) return Boolean;
2199 -- Determines if Ptype references the type of Formal. Note that
2200 -- only the base types need to match according to the spec. Ptype
2201 -- here is the argument from the pragma, which is either a type
2202 -- name, or an access attribute.
2204 --------------------
2205 -- Same_Base_Type --
2206 --------------------
2208 function Same_Base_Type
2210 Formal : Entity_Id) return Boolean
2212 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2216 -- Case where pragma argument is typ'Access
2218 if Nkind (Ptype) = N_Attribute_Reference
2219 and then Attribute_Name (Ptype) = Name_Access
2221 Pref := Prefix (Ptype);
2224 if not Is_Entity_Name (Pref)
2225 or else Entity (Pref) = Any_Type
2230 -- We have a match if the corresponding argument is of an
2231 -- anonymous access type, and its designicated type matches
2232 -- the type of the prefix of the access attribute
2234 return Ekind (Ftyp) = E_Anonymous_Access_Type
2235 and then Base_Type (Entity (Pref)) =
2236 Base_Type (Etype (Designated_Type (Ftyp)));
2238 -- Case where pragma argument is a type name
2243 if not Is_Entity_Name (Ptype)
2244 or else Entity (Ptype) = Any_Type
2249 -- We have a match if the corresponding argument is of
2250 -- the type given in the pragma (comparing base types)
2252 return Base_Type (Entity (Ptype)) = Ftyp;
2256 -- Start of processing for
2257 -- Process_Extended_Import_Export_Subprogram_Pragma
2260 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2261 Hom_Id := Entity (Arg_Internal);
2265 -- Loop through homonyms (overloadings) of Hom_Id
2267 while Present (Hom_Id) loop
2268 Def_Id := Get_Base_Subprogram (Hom_Id);
2270 -- We need a subprogram in the current scope
2272 if not Is_Subprogram (Def_Id)
2273 or else Scope (Def_Id) /= Current_Scope
2280 -- Pragma cannot apply to subprogram body
2282 if Is_Subprogram (Def_Id)
2285 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2288 ("pragma% requires separate spec"
2289 & " and must come before body");
2292 -- Test result type if given, note that the result type
2293 -- parameter can only be present for the function cases.
2295 if Present (Arg_Result_Type)
2296 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2300 elsif Etype (Def_Id) /= Standard_Void_Type
2302 (Chars (N) = Name_Export_Procedure
2303 or else Chars (N) = Name_Import_Procedure)
2307 -- Test parameter types if given. Note that this parameter
2308 -- has not been analyzed (and must not be, since it is
2309 -- semantic nonsense), so we get it as the parser left it.
2311 elsif Present (Arg_Parameter_Types) then
2312 Check_Matching_Types : declare
2317 Formal := First_Formal (Def_Id);
2319 if Nkind (Arg_Parameter_Types) = N_Null then
2320 if Present (Formal) then
2324 -- A list of one type, e.g. (List) is parsed as
2325 -- a parenthesized expression.
2327 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2328 and then Paren_Count (Arg_Parameter_Types) = 1
2331 or else Present (Next_Formal (Formal))
2336 Same_Base_Type (Arg_Parameter_Types, Formal);
2339 -- A list of more than one type is parsed as a aggregate
2341 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2342 and then Paren_Count (Arg_Parameter_Types) = 0
2344 Ptype := First (Expressions (Arg_Parameter_Types));
2345 while Present (Ptype) or else Present (Formal) loop
2348 or else not Same_Base_Type (Ptype, Formal)
2353 Next_Formal (Formal);
2358 -- Anything else is of the wrong form
2362 ("wrong form for Parameter_Types parameter",
2363 Arg_Parameter_Types);
2365 end Check_Matching_Types;
2368 -- Match is now False if the entry we found did not match
2369 -- either a supplied Parameter_Types or Result_Types argument
2375 -- Ambiguous case, the flag Ambiguous shows if we already
2376 -- detected this and output the initial messages.
2379 if not Ambiguous then
2381 Error_Msg_Name_1 := Chars (N);
2383 ("pragma% does not uniquely identify subprogram!",
2385 Error_Msg_Sloc := Sloc (Ent);
2386 Error_Msg_N ("matching subprogram #!", N);
2390 Error_Msg_Sloc := Sloc (Def_Id);
2391 Error_Msg_N ("matching subprogram #!", N);
2396 Hom_Id := Homonym (Hom_Id);
2399 -- See if we found an entry
2402 if not Ambiguous then
2403 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2405 ("pragma% cannot be given for generic subprogram");
2409 ("pragma% does not identify local subprogram");
2416 -- Import pragmas must be be for imported entities
2418 if Prag_Id = Pragma_Import_Function
2420 Prag_Id = Pragma_Import_Procedure
2422 Prag_Id = Pragma_Import_Valued_Procedure
2424 if not Is_Imported (Ent) then
2426 ("pragma Import or Interface must precede pragma%");
2429 -- Here we have the Export case which can set the entity as exported
2431 -- But does not do so if the specified external name is null,
2432 -- since that is taken as a signal in DEC Ada 83 (with which
2433 -- we want to be compatible) to request no external name.
2435 elsif Nkind (Arg_External) = N_String_Literal
2436 and then String_Length (Strval (Arg_External)) = 0
2440 -- In all other cases, set entit as exported
2443 Set_Exported (Ent, Arg_Internal);
2446 -- Special processing for Valued_Procedure cases
2448 if Prag_Id = Pragma_Import_Valued_Procedure
2450 Prag_Id = Pragma_Export_Valued_Procedure
2452 Formal := First_Formal (Ent);
2456 ("at least one parameter required for pragma%");
2458 elsif Ekind (Formal) /= E_Out_Parameter then
2460 ("first parameter must have mode out for pragma%");
2463 Set_Is_Valued_Procedure (Ent);
2467 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2469 -- Process Result_Mechanism argument if present. We have already
2470 -- checked that this is only allowed for the function case.
2472 if Present (Arg_Result_Mechanism) then
2473 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2476 -- Process Mechanism parameter if present. Note that this parameter
2477 -- is not analyzed, and must not be analyzed since it is semantic
2478 -- nonsense, so we get it in exactly as the parser left it.
2480 if Present (Arg_Mechanism) then
2488 -- A single mechanism association without a formal parameter
2489 -- name is parsed as a parenthesized expression. All other
2490 -- cases are parsed as aggregates, so we rewrite the single
2491 -- parameter case as an aggregate for consistency.
2493 if Nkind (Arg_Mechanism) /= N_Aggregate
2494 and then Paren_Count (Arg_Mechanism) = 1
2496 Rewrite (Arg_Mechanism,
2497 Make_Aggregate (Sloc (Arg_Mechanism),
2498 Expressions => New_List (
2499 Relocate_Node (Arg_Mechanism))));
2502 -- Case of only mechanism name given, applies to all formals
2504 if Nkind (Arg_Mechanism) /= N_Aggregate then
2505 Formal := First_Formal (Ent);
2506 while Present (Formal) loop
2507 Set_Mechanism_Value (Formal, Arg_Mechanism);
2508 Next_Formal (Formal);
2511 -- Case of list of mechanism associations given
2514 if Null_Record_Present (Arg_Mechanism) then
2516 ("inappropriate form for Mechanism parameter",
2520 -- Deal with positional ones first
2522 Formal := First_Formal (Ent);
2523 if Present (Expressions (Arg_Mechanism)) then
2524 Mname := First (Expressions (Arg_Mechanism));
2526 while Present (Mname) loop
2529 ("too many mechanism associations", Mname);
2532 Set_Mechanism_Value (Formal, Mname);
2533 Next_Formal (Formal);
2538 -- Deal with named entries
2540 if Present (Component_Associations (Arg_Mechanism)) then
2541 Massoc := First (Component_Associations (Arg_Mechanism));
2543 while Present (Massoc) loop
2544 Choice := First (Choices (Massoc));
2546 if Nkind (Choice) /= N_Identifier
2547 or else Present (Next (Choice))
2550 ("incorrect form for mechanism association",
2554 Formal := First_Formal (Ent);
2558 ("parameter name & not present", Choice);
2561 if Chars (Choice) = Chars (Formal) then
2563 (Formal, Expression (Massoc));
2567 Next_Formal (Formal);
2577 -- Process First_Optional_Parameter argument if present. We have
2578 -- already checked that this is only allowed for the Import case.
2580 if Present (Arg_First_Optional_Parameter) then
2581 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2583 ("first optional parameter must be formal parameter name",
2584 Arg_First_Optional_Parameter);
2587 Formal := First_Formal (Ent);
2591 ("specified formal parameter& not found",
2592 Arg_First_Optional_Parameter);
2595 exit when Chars (Formal) =
2596 Chars (Arg_First_Optional_Parameter);
2598 Next_Formal (Formal);
2601 Set_First_Optional_Parameter (Ent, Formal);
2603 -- Check specified and all remaining formals have right form
2605 while Present (Formal) loop
2606 if Ekind (Formal) /= E_In_Parameter then
2608 ("optional formal& is not of mode in!",
2609 Arg_First_Optional_Parameter, Formal);
2612 Dval := Default_Value (Formal);
2614 if not Present (Dval) then
2616 ("optional formal& does not have default value!",
2617 Arg_First_Optional_Parameter, Formal);
2619 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2624 ("default value for optional formal& is non-static!",
2625 Arg_First_Optional_Parameter, Formal);
2629 Set_Is_Optional_Parameter (Formal);
2630 Next_Formal (Formal);
2633 end Process_Extended_Import_Export_Subprogram_Pragma;
2635 --------------------------
2636 -- Process_Generic_List --
2637 --------------------------
2639 procedure Process_Generic_List is
2645 Check_No_Identifiers;
2646 Check_At_Least_N_Arguments (1);
2649 while Present (Arg) loop
2650 Exp := Expression (Arg);
2653 if not Is_Entity_Name (Exp)
2655 (not Is_Generic_Instance (Entity (Exp))
2657 not Is_Generic_Unit (Entity (Exp)))
2660 ("pragma% argument must be name of generic unit/instance",
2666 end Process_Generic_List;
2668 ---------------------------------
2669 -- Process_Import_Or_Interface --
2670 ---------------------------------
2672 procedure Process_Import_Or_Interface is
2678 Process_Convention (C, Def_Id);
2679 Kill_Size_Check_Code (Def_Id);
2680 Note_Possible_Modification (Expression (Arg2));
2682 if Ekind (Def_Id) = E_Variable
2684 Ekind (Def_Id) = E_Constant
2686 -- User initialization is not allowed for imported object, but
2687 -- the object declaration may contain a default initialization,
2688 -- that will be discarded. Note that an explicit initialization
2689 -- only counts if it comes from source, otherwise it is simply
2690 -- the code generator making an implicit initialization explicit.
2692 if Present (Expression (Parent (Def_Id)))
2693 and then Comes_From_Source (Expression (Parent (Def_Id)))
2695 Error_Msg_Sloc := Sloc (Def_Id);
2697 ("no initialization allowed for declaration of& #",
2698 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2702 Set_Imported (Def_Id);
2703 Set_Is_Public (Def_Id);
2704 Process_Interface_Name (Def_Id, Arg3, Arg4);
2706 -- It is not possible to import a constant of an unconstrained
2707 -- array type (e.g. string) because there is no simple way to
2708 -- write a meaningful subtype for it.
2710 if Is_Array_Type (Etype (Def_Id))
2711 and then not Is_Constrained (Etype (Def_Id))
2714 ("imported constant& must have a constrained subtype",
2719 elsif Is_Subprogram (Def_Id)
2720 or else Is_Generic_Subprogram (Def_Id)
2722 -- If the name is overloaded, pragma applies to all of the
2723 -- denoted entities in the same declarative part.
2727 while Present (Hom_Id) loop
2728 Def_Id := Get_Base_Subprogram (Hom_Id);
2730 -- Ignore inherited subprograms because the pragma will
2731 -- apply to the parent operation, which is the one called.
2733 if Is_Overloadable (Def_Id)
2734 and then Present (Alias (Def_Id))
2738 -- If it is not a subprogram, it must be in an outer
2739 -- scope and pragma does not apply.
2741 elsif not Is_Subprogram (Def_Id)
2742 and then not Is_Generic_Subprogram (Def_Id)
2746 -- Verify that the homonym is in the same declarative
2747 -- part (not just the same scope).
2749 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2750 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2755 Set_Imported (Def_Id);
2757 -- If Import intrinsic, set intrinsic flag
2758 -- and verify that it is known as such.
2760 if C = Convention_Intrinsic then
2761 Set_Is_Intrinsic_Subprogram (Def_Id);
2762 Check_Intrinsic_Subprogram
2763 (Def_Id, Expression (Arg2));
2766 -- All interfaced procedures need an external
2767 -- symbol created for them since they are
2768 -- always referenced from another object file.
2770 Set_Is_Public (Def_Id);
2772 -- Verify that the subprogram does not have a completion
2773 -- through a renaming declaration. For other completions
2774 -- the pragma appears as a too late representation.
2777 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
2781 and then Nkind (Decl) = N_Subprogram_Declaration
2782 and then Present (Corresponding_Body (Decl))
2785 (Unit_Declaration_Node
2786 (Corresponding_Body (Decl))) =
2787 N_Subprogram_Renaming_Declaration
2789 Error_Msg_Sloc := Sloc (Def_Id);
2790 Error_Msg_NE ("cannot import&#," &
2791 " already completed by a renaming",
2796 Set_Has_Completion (Def_Id);
2797 Process_Interface_Name (Def_Id, Arg3, Arg4);
2800 if Is_Compilation_Unit (Hom_Id) then
2802 -- Its possible homonyms are not affected by the pragma.
2803 -- Such homonyms might be present in the context of other
2804 -- units being compiled.
2809 Hom_Id := Homonym (Hom_Id);
2813 -- When the convention is Java, we also allow Import to be given
2814 -- for packages, exceptions, and record components.
2816 elsif C = Convention_Java
2818 (Ekind (Def_Id) = E_Package
2819 or else Ekind (Def_Id) = E_Exception
2820 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
2822 Set_Imported (Def_Id);
2823 Set_Is_Public (Def_Id);
2824 Process_Interface_Name (Def_Id, Arg3, Arg4);
2828 ("second argument of pragma% must be object or subprogram",
2832 -- If this pragma applies to a compilation unit, then the unit,
2833 -- which is a subprogram, does not require (or allow) a body.
2834 -- We also do not need to elaborate imported procedures.
2836 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2838 Cunit : constant Node_Id := Parent (Parent (N));
2840 Set_Body_Required (Cunit, False);
2843 end Process_Import_Or_Interface;
2845 --------------------
2846 -- Process_Inline --
2847 --------------------
2849 procedure Process_Inline (Active : Boolean) is
2855 Effective : Boolean := False;
2857 procedure Make_Inline (Subp : Entity_Id);
2858 -- Subp is the defining unit name of the subprogram
2859 -- declaration. Set the flag, as well as the flag in the
2860 -- corresponding body, if there is one present.
2862 procedure Set_Inline_Flags (Subp : Entity_Id);
2863 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
2865 function Cannot_Inline (Subp : Entity_Id) return Boolean;
2866 -- Do not set the inline flag if body is available and contains
2867 -- exception handlers, to prevent undefined symbols at link time.
2868 -- Emit warning if front-end inlining is enabled and the pragma
2869 -- appears too late.
2875 function Cannot_Inline (Subp : Entity_Id) return Boolean is
2876 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
2879 if Nkind (Decl) = N_Subprogram_Body then
2882 (Exception_Handlers (Handled_Statement_Sequence (Decl)));
2884 elsif Nkind (Decl) = N_Subprogram_Declaration
2885 and then Present (Corresponding_Body (Decl))
2887 if Front_End_Inlining
2888 and then Analyzed (Corresponding_Body (Decl))
2890 Error_Msg_N ("pragma appears too late, ignored?", N);
2893 -- If the subprogram is a renaming as body, the body is
2894 -- just a call to the renamed subprogram, and inlining is
2895 -- trivially possible.
2898 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
2899 = N_Subprogram_Renaming_Declaration
2905 Present (Exception_Handlers
2906 (Handled_Statement_Sequence
2907 (Unit_Declaration_Node (Corresponding_Body (Decl)))));
2910 -- If body is not available, assume the best, the check is
2911 -- performed again when compiling enclosing package bodies.
2921 procedure Make_Inline (Subp : Entity_Id) is
2922 Kind : constant Entity_Kind := Ekind (Subp);
2923 Inner_Subp : Entity_Id := Subp;
2926 if Etype (Subp) = Any_Type then
2929 elsif Cannot_Inline (Subp) then
2930 Applies := True; -- Do not treat as an error.
2933 -- Here we have a candidate for inlining, but we must exclude
2934 -- derived operations. Otherwise we will end up trying to
2935 -- inline a phantom declaration, and the result would be to
2936 -- drag in a body which has no direct inlining associated with
2937 -- it. That would not only be inefficient but would also result
2938 -- in the backend doing cross-unit inlining in cases where it
2939 -- was definitely inappropriate to do so.
2941 -- However, a simple Comes_From_Source test is insufficient,
2942 -- since we do want to allow inlining of generic instances,
2943 -- which also do not come from source. Predefined operators do
2944 -- not come from source but are not inlineable either.
2946 elsif not Comes_From_Source (Subp)
2947 and then not Is_Generic_Instance (Subp)
2948 and then Scope (Subp) /= Standard_Standard
2953 -- The referenced entity must either be the enclosing entity,
2954 -- or an entity declared within the current open scope.
2956 elsif Present (Scope (Subp))
2957 and then Scope (Subp) /= Current_Scope
2958 and then Subp /= Current_Scope
2961 ("argument of% must be entity in current scope", Assoc);
2965 -- Processing for procedure, operator or function.
2966 -- If subprogram is aliased (as for an instance) indicate
2967 -- that the renamed entity (if declared in the same unit)
2970 if Is_Subprogram (Subp) then
2971 while Present (Alias (Inner_Subp)) loop
2972 Inner_Subp := Alias (Inner_Subp);
2975 if In_Same_Source_Unit (Subp, Inner_Subp) then
2976 Set_Inline_Flags (Inner_Subp);
2978 Decl := Parent (Parent (Inner_Subp));
2980 if Nkind (Decl) = N_Subprogram_Declaration
2981 and then Present (Corresponding_Body (Decl))
2983 Set_Inline_Flags (Corresponding_Body (Decl));
2989 -- For a generic subprogram set flag as well, for use at
2990 -- the point of instantiation, to determine whether the
2991 -- body should be generated.
2993 elsif Is_Generic_Subprogram (Subp) then
2994 Set_Inline_Flags (Subp);
2997 -- Literals are by definition inlined
2999 elsif Kind = E_Enumeration_Literal then
3002 -- Anything else is an error
3006 ("expect subprogram name for pragma%", Assoc);
3010 ----------------------
3011 -- Set_Inline_Flags --
3012 ----------------------
3014 procedure Set_Inline_Flags (Subp : Entity_Id) is
3017 Set_Is_Inlined (Subp, True);
3020 if not Has_Pragma_Inline (Subp) then
3021 Set_Has_Pragma_Inline (Subp);
3022 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3023 Set_First_Rep_Item (Subp, N);
3026 end Set_Inline_Flags;
3028 -- Start of processing for Process_Inline
3031 Check_No_Identifiers;
3032 Check_At_Least_N_Arguments (1);
3035 Inline_Processing_Required := True;
3039 while Present (Assoc) loop
3040 Subp_Id := Expression (Assoc);
3044 if Is_Entity_Name (Subp_Id) then
3045 Subp := Entity (Subp_Id);
3047 if Subp = Any_Id then
3053 while Present (Homonym (Subp))
3054 and then Scope (Homonym (Subp)) = Current_Scope
3056 Make_Inline (Homonym (Subp));
3057 Subp := Homonym (Subp);
3064 ("inappropriate argument for pragma%", Assoc);
3067 and then Warn_On_Redundant_Constructs
3069 Error_Msg_NE ("pragma inline on& is redundant?",
3070 N, Entity (Subp_Id));
3077 ----------------------------
3078 -- Process_Interface_Name --
3079 ----------------------------
3081 procedure Process_Interface_Name
3082 (Subprogram_Def : Entity_Id;
3088 String_Val : String_Id;
3090 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3091 -- SN is a string literal node for an interface name. This routine
3092 -- performs some minimal checks that the name is reasonable. In
3093 -- particular that no spaces or other obviously incorrect characters
3094 -- appear. This is only a warning, since any characters are allowed.
3096 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3097 S : constant String_Id := Strval (Expr_Value_S (SN));
3098 SL : constant Nat := String_Length (S);
3103 Error_Msg_N ("interface name cannot be null string", SN);
3106 for J in 1 .. SL loop
3107 C := Get_String_Char (S, J);
3109 if Warn_On_Export_Import
3110 and then (not In_Character_Range (C)
3111 or else Get_Character (C) = ' '
3112 or else Get_Character (C) = ',')
3115 ("?interface name contains illegal character", SN);
3118 end Check_Form_Of_Interface_Name;
3120 -- Start of processing for Process_Interface_Name
3123 if No (Link_Arg) then
3124 if No (Ext_Arg) then
3127 elsif Chars (Ext_Arg) = Name_Link_Name then
3129 Link_Nam := Expression (Ext_Arg);
3132 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3133 Ext_Nam := Expression (Ext_Arg);
3138 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3139 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3140 Ext_Nam := Expression (Ext_Arg);
3141 Link_Nam := Expression (Link_Arg);
3144 -- Check expressions for external name and link name are static
3146 if Present (Ext_Nam) then
3147 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3148 Check_Form_Of_Interface_Name (Ext_Nam);
3150 -- Verify that the external name is not the name of a local
3151 -- entity, which would hide the imported one and lead to
3152 -- run-time surprises. The problem can only arise for entities
3153 -- declared in a package body (otherwise the external name is
3154 -- fully qualified and won't conflict).
3162 if Prag_Id = Pragma_Import then
3163 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3165 E := Entity_Id (Get_Name_Table_Info (Nam));
3167 if Nam /= Chars (Subprogram_Def)
3168 and then Present (E)
3169 and then not Is_Overloadable (E)
3170 and then Is_Immediately_Visible (E)
3171 and then not Is_Imported (E)
3172 and then Ekind (Scope (E)) = E_Package
3176 while Present (Par) loop
3177 if Nkind (Par) = N_Package_Body then
3178 Error_Msg_Sloc := Sloc (E);
3180 ("imported entity is hidden by & declared#",
3185 Par := Parent (Par);
3192 if Present (Link_Nam) then
3193 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3194 Check_Form_Of_Interface_Name (Link_Nam);
3197 -- If there is no link name, just set the external name
3199 if No (Link_Nam) then
3200 Set_Encoded_Interface_Name
3201 (Get_Base_Subprogram (Subprogram_Def),
3202 Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)));
3204 -- For the Link_Name case, the given literal is preceded by an
3205 -- asterisk, which indicates to GCC that the given name should
3206 -- be taken literally, and in particular that no prepending of
3207 -- underlines should occur, even in systems where this is the
3212 Store_String_Char (Get_Char_Code ('*'));
3213 String_Val := Strval (Expr_Value_S (Link_Nam));
3215 for J in 1 .. String_Length (String_Val) loop
3216 Store_String_Char (Get_String_Char (String_Val, J));
3220 Make_String_Literal (Sloc (Link_Nam), End_String);
3222 Set_Encoded_Interface_Name
3223 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3225 end Process_Interface_Name;
3227 -----------------------------------------
3228 -- Process_Interrupt_Or_Attach_Handler --
3229 -----------------------------------------
3231 procedure Process_Interrupt_Or_Attach_Handler is
3232 Arg1_X : constant Node_Id := Expression (Arg1);
3233 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3234 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3237 Set_Is_Interrupt_Handler (Handler_Proc);
3239 -- If the pragma is not associated with a handler procedure
3240 -- within a protected type, then it must be for a nonprotected
3241 -- procedure for the AAMP target, in which case we don't
3242 -- associate a representation item with the procedure's scope.
3244 if Ekind (Proc_Scope) = E_Protected_Type then
3245 if Prag_Id = Pragma_Interrupt_Handler
3247 Prag_Id = Pragma_Attach_Handler
3249 Record_Rep_Item (Proc_Scope, N);
3252 end Process_Interrupt_Or_Attach_Handler;
3254 --------------------------------------------------
3255 -- Process_Restrictions_Or_Restriction_Warnings --
3256 --------------------------------------------------
3258 procedure Process_Restrictions_Or_Restriction_Warnings is
3260 R_Id : Restriction_Id;
3265 procedure Set_Warning (R : All_Restrictions);
3266 -- If this is a Restriction_Warnings pragma, set warning flag
3272 procedure Set_Warning (R : All_Restrictions) is
3274 if Prag_Id = Pragma_Restriction_Warnings then
3275 Restriction_Warnings (R) := True;
3279 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3282 Check_Ada_83_Warning;
3283 Check_At_Least_N_Arguments (1);
3284 Check_Valid_Configuration_Pragma;
3287 while Present (Arg) loop
3289 Expr := Expression (Arg);
3291 -- Case of no restriction identifier present
3293 if Id = No_Name then
3294 if Nkind (Expr) /= N_Identifier then
3296 ("invalid form for restriction", Arg);
3301 (Process_Restriction_Synonyms (Chars (Expr)));
3303 if R_Id not in All_Boolean_Restrictions then
3305 ("invalid restriction identifier", Arg);
3308 if Implementation_Restriction (R_Id) then
3310 (No_Implementation_Restrictions, Arg);
3313 Set_Restriction (R_Id, N);
3316 -- A very special case that must be processed here:
3317 -- pragma Restrictions (No_Exceptions) turns off
3318 -- all run-time checking. This is a bit dubious in
3319 -- terms of the formal language definition, but it
3320 -- is what is intended by RM H.4(12).
3322 if R_Id = No_Exceptions then
3323 Scope_Suppress := (others => True);
3326 -- Case of restriction identifier present
3329 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Id));
3330 Analyze_And_Resolve (Expr, Any_Integer);
3332 if R_Id not in All_Parameter_Restrictions then
3334 ("invalid restriction parameter identifier", Arg);
3336 elsif not Is_OK_Static_Expression (Expr) then
3337 Flag_Non_Static_Expr
3338 ("value must be static expression!", Expr);
3341 elsif not Is_Integer_Type (Etype (Expr))
3342 or else Expr_Value (Expr) < 0
3345 ("value must be non-negative integer", Arg);
3347 -- Restriction pragma is active
3350 Val := Expr_Value (Expr);
3352 if not UI_Is_In_Int_Range (Val) then
3354 ("pragma ignored, value too large?", Arg);
3356 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3364 end Process_Restrictions_Or_Restriction_Warnings;
3366 ---------------------------------
3367 -- Process_Suppress_Unsuppress --
3368 ---------------------------------
3370 -- Note: this procedure makes entries in the check suppress data
3371 -- structures managed by Sem. See spec of package Sem for full
3372 -- details on how we handle recording of check suppression.
3374 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3379 In_Package_Spec : constant Boolean :=
3380 (Ekind (Current_Scope) = E_Package
3382 Ekind (Current_Scope) = E_Generic_Package)
3383 and then not In_Package_Body (Current_Scope);
3385 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3386 -- Used to suppress a single check on the given entity
3388 --------------------------------
3389 -- Suppress_Unsuppress_Echeck --
3390 --------------------------------
3392 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3393 ESR : constant Entity_Check_Suppress_Record :=
3396 Suppress => Suppress_Case);
3399 Set_Checks_May_Be_Suppressed (E);
3401 if In_Package_Spec then
3402 Global_Entity_Suppress.Append (ESR);
3404 Local_Entity_Suppress.Append (ESR);
3407 -- If this is a first subtype, and the base type is distinct,
3408 -- then also set the suppress flags on the base type.
3410 if Is_First_Subtype (E)
3411 and then Etype (E) /= E
3413 Suppress_Unsuppress_Echeck (Etype (E), C);
3415 end Suppress_Unsuppress_Echeck;
3417 -- Start of processing for Process_Suppress_Unsuppress
3420 -- Suppress/Unsuppress can appear as a configuration pragma,
3421 -- or in a declarative part or a package spec (RM 11.5(5))
3423 if not Is_Configuration_Pragma then
3424 Check_Is_In_Decl_Part_Or_Package_Spec;
3427 Check_At_Least_N_Arguments (1);
3428 Check_At_Most_N_Arguments (2);
3429 Check_No_Identifier (Arg1);
3430 Check_Arg_Is_Identifier (Arg1);
3432 if not Is_Check_Name (Chars (Expression (Arg1))) then
3434 ("argument of pragma% is not valid check name", Arg1);
3436 C := Get_Check_Id (Chars (Expression (Arg1)));
3439 if Arg_Count = 1 then
3441 -- Make an entry in the local scope suppress table. This is the
3442 -- table that directly shows the current value of the scope
3443 -- suppress check for any check id value.
3445 if C = All_Checks then
3446 for J in Scope_Suppress'Range loop
3447 Scope_Suppress (J) := Suppress_Case;
3450 Scope_Suppress (C) := Suppress_Case;
3453 -- Also make an entry in the Local_Entity_Suppress table. See
3454 -- extended description in the package spec of Sem for details.
3456 Local_Entity_Suppress.Append
3459 Suppress => Suppress_Case));
3461 -- Case of two arguments present, where the check is
3462 -- suppressed for a specified entity (given as the second
3463 -- argument of the pragma)
3466 Check_Optional_Identifier (Arg2, Name_On);
3467 E_Id := Expression (Arg2);
3470 if not Is_Entity_Name (E_Id) then
3472 ("second argument of pragma% must be entity name", Arg2);
3481 -- Enforce RM 11.5(7) which requires that for a pragma that
3482 -- appears within a package spec, the named entity must be
3483 -- within the package spec. We allow the package name itself
3484 -- to be mentioned since that makes sense, although it is not
3485 -- strictly allowed by 11.5(7).
3488 and then E /= Current_Scope
3489 and then Scope (E) /= Current_Scope
3492 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3496 -- Loop through homonyms. As noted below, in the case of a package
3497 -- spec, only homonyms within the package spec are considered.
3500 Suppress_Unsuppress_Echeck (E, C);
3502 if Is_Generic_Instance (E)
3503 and then Is_Subprogram (E)
3504 and then Present (Alias (E))
3506 Suppress_Unsuppress_Echeck (Alias (E), C);
3509 -- Move to next homonym
3514 -- If we are within a package specification, the
3515 -- pragma only applies to homonyms in the same scope.
3517 exit when In_Package_Spec
3518 and then Scope (E) /= Current_Scope;
3521 end Process_Suppress_Unsuppress;
3527 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3529 if Is_Imported (E) then
3531 ("cannot export entity& that was previously imported", Arg);
3533 elsif Present (Address_Clause (E)) then
3535 ("cannot export entity& that has an address clause", Arg);
3538 Set_Is_Exported (E);
3540 -- Generate a reference for entity explicitly, because the
3541 -- identifier may be overloaded and name resolution will not
3544 Generate_Reference (E, Arg);
3546 -- Deal with exporting non-library level entity
3548 if not Is_Library_Level_Entity (E) then
3550 -- Not allowed at all for subprograms
3552 if Is_Subprogram (E) then
3553 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3555 -- Otherwise set public and statically allocated
3559 Set_Is_Statically_Allocated (E);
3561 -- Warn if the corresponding W flag is set and the pragma
3562 -- comes from source. The latter may not be true e.g. on
3563 -- VMS where we expand export pragmas for exception codes
3564 -- associated with imported or exported exceptions. We do
3565 -- not want to generate a warning for something that the
3566 -- user did not write.
3568 if Warn_On_Export_Import
3569 and then Comes_From_Source (Arg)
3572 ("?& has been made static as a result of Export", Arg, E);
3574 ("\this usage is non-standard and non-portable", Arg);
3579 if Warn_On_Export_Import and then Is_Type (E) then
3581 ("exporting a type has no effect?", Arg, E);
3584 if Warn_On_Export_Import and Inside_A_Generic then
3586 ("all instances of& will have the same external name?", Arg, E);
3590 ----------------------------------------------
3591 -- Set_Extended_Import_Export_External_Name --
3592 ----------------------------------------------
3594 procedure Set_Extended_Import_Export_External_Name
3595 (Internal_Ent : Entity_Id;
3596 Arg_External : Node_Id)
3598 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3602 if No (Arg_External) then
3605 elsif Nkind (Arg_External) = N_String_Literal then
3606 if String_Length (Strval (Arg_External)) = 0 then
3609 New_Name := Adjust_External_Name_Case (Arg_External);
3612 elsif Nkind (Arg_External) = N_Identifier then
3613 New_Name := Get_Default_External_Name (Arg_External);
3617 ("incorrect form for External parameter for pragma%",
3621 -- If we already have an external name set (by a prior normal
3622 -- Import or Export pragma), then the external names must match
3624 if Present (Interface_Name (Internal_Ent)) then
3626 S1 : constant String_Id := Strval (Old_Name);
3627 S2 : constant String_Id := Strval (New_Name);
3630 -- Called if names do not match
3632 procedure Mismatch is
3634 Error_Msg_Sloc := Sloc (Old_Name);
3636 ("external name does not match that given #",
3641 if String_Length (S1) /= String_Length (S2) then
3645 for J in 1 .. String_Length (S1) loop
3646 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3653 -- Otherwise set the given name
3656 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3659 end Set_Extended_Import_Export_External_Name;
3665 procedure Set_Imported (E : Entity_Id) is
3667 Error_Msg_Sloc := Sloc (E);
3669 if Is_Exported (E) or else Is_Imported (E) then
3670 Error_Msg_NE ("import of& declared# not allowed", N, E);
3672 if Is_Exported (E) then
3673 Error_Msg_N ("\entity was previously exported", N);
3675 Error_Msg_N ("\entity was previously imported", N);
3678 Error_Pragma ("\(pragma% applies to all previous entities)");
3681 Set_Is_Imported (E);
3683 -- If the entity is an object that is not at the library
3684 -- level, then it is statically allocated. We do not worry
3685 -- about objects with address clauses in this context since
3686 -- they are not really imported in the linker sense.
3689 and then not Is_Library_Level_Entity (E)
3690 and then No (Address_Clause (E))
3692 Set_Is_Statically_Allocated (E);
3697 -------------------------
3698 -- Set_Mechanism_Value --
3699 -------------------------
3701 -- Note: the mechanism name has not been analyzed (and cannot indeed
3702 -- be analyzed, since it is semantic nonsense), so we get it in the
3703 -- exact form created by the parser.
3705 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3709 procedure Bad_Class;
3710 -- Signal bad descriptor class name
3712 procedure Bad_Mechanism;
3713 -- Signal bad mechanism name
3715 procedure Bad_Class is
3717 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3720 procedure Bad_Mechanism is
3722 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3725 -- Start of processing for Set_Mechanism_Value
3728 if Mechanism (Ent) /= Default_Mechanism then
3730 ("mechanism for & has already been set", Mech_Name, Ent);
3733 -- MECHANISM_NAME ::= value | reference | descriptor
3735 if Nkind (Mech_Name) = N_Identifier then
3736 if Chars (Mech_Name) = Name_Value then
3737 Set_Mechanism (Ent, By_Copy);
3740 elsif Chars (Mech_Name) = Name_Reference then
3741 Set_Mechanism (Ent, By_Reference);
3744 elsif Chars (Mech_Name) = Name_Descriptor then
3745 Check_VMS (Mech_Name);
3746 Set_Mechanism (Ent, By_Descriptor);
3749 elsif Chars (Mech_Name) = Name_Copy then
3751 ("bad mechanism name, Value assumed", Mech_Name);
3757 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3758 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3760 -- Note: this form is parsed as an indexed component
3762 elsif Nkind (Mech_Name) = N_Indexed_Component then
3763 Class := First (Expressions (Mech_Name));
3765 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3766 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3767 or else Present (Next (Class))
3772 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3773 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3775 -- Note: this form is parsed as a function call
3777 elsif Nkind (Mech_Name) = N_Function_Call then
3779 Param := First (Parameter_Associations (Mech_Name));
3781 if Nkind (Name (Mech_Name)) /= N_Identifier
3782 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3783 or else Present (Next (Param))
3784 or else No (Selector_Name (Param))
3785 or else Chars (Selector_Name (Param)) /= Name_Class
3789 Class := Explicit_Actual_Parameter (Param);
3796 -- Fall through here with Class set to descriptor class name
3798 Check_VMS (Mech_Name);
3800 if Nkind (Class) /= N_Identifier then
3803 elsif Chars (Class) = Name_UBS then
3804 Set_Mechanism (Ent, By_Descriptor_UBS);
3806 elsif Chars (Class) = Name_UBSB then
3807 Set_Mechanism (Ent, By_Descriptor_UBSB);
3809 elsif Chars (Class) = Name_UBA then
3810 Set_Mechanism (Ent, By_Descriptor_UBA);
3812 elsif Chars (Class) = Name_S then
3813 Set_Mechanism (Ent, By_Descriptor_S);
3815 elsif Chars (Class) = Name_SB then
3816 Set_Mechanism (Ent, By_Descriptor_SB);
3818 elsif Chars (Class) = Name_A then
3819 Set_Mechanism (Ent, By_Descriptor_A);
3821 elsif Chars (Class) = Name_NCA then
3822 Set_Mechanism (Ent, By_Descriptor_NCA);
3828 end Set_Mechanism_Value;
3830 ---------------------------
3831 -- Set_Ravenscar_Profile --
3832 ---------------------------
3834 -- The tasks to be done here are
3836 -- Set required policies
3838 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
3839 -- pragma Locking_Policy (Ceiling_Locking)
3841 -- Set Detect_Blocking mode ???
3843 -- Set required restrictions (see Restrict.Set_Ravenscar for details)
3845 procedure Set_Ravenscar_Profile (N : Node_Id) is
3847 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
3849 if Task_Dispatching_Policy /= ' '
3850 and then Task_Dispatching_Policy /= 'F'
3852 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
3853 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
3855 -- Set the FIFO_Within_Priorities policy, but always
3856 -- preserve System_Location since we like the error
3857 -- message with the run time name.
3860 Task_Dispatching_Policy := 'F';
3862 if Task_Dispatching_Policy_Sloc /= System_Location then
3863 Task_Dispatching_Policy_Sloc := Loc;
3867 -- pragma Locking_Policy (Ceiling_Locking)
3869 if Locking_Policy /= ' '
3870 and then Locking_Policy /= 'C'
3872 Error_Msg_Sloc := Locking_Policy_Sloc;
3873 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
3875 -- Set the Ceiling_Locking policy, but always preserve
3876 -- System_Location since we like the error message with the
3880 Locking_Policy := 'C';
3882 if Locking_Policy_Sloc /= System_Location then
3883 Locking_Policy_Sloc := Loc;
3887 -- ??? Detect_Blocking
3889 -- Set the corresponding restrictions
3892 end Set_Ravenscar_Profile;
3894 -- Start of processing for Analyze_Pragma
3897 if not Is_Pragma_Name (Chars (N)) then
3898 if Warn_On_Unrecognized_Pragma then
3899 Error_Pragma ("unrecognized pragma%!?");
3904 Prag_Id := Get_Pragma_Id (Chars (N));
3914 if Present (Pragma_Argument_Associations (N)) then
3915 Arg1 := First (Pragma_Argument_Associations (N));
3917 if Present (Arg1) then
3918 Arg2 := Next (Arg1);
3920 if Present (Arg2) then
3921 Arg3 := Next (Arg2);
3923 if Present (Arg3) then
3924 Arg4 := Next (Arg3);
3930 -- Count number of arguments
3937 while Present (Arg_Node) loop
3938 Arg_Count := Arg_Count + 1;
3943 -- An enumeration type defines the pragmas that are supported by the
3944 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
3945 -- into the corresponding enumeration value for the following case.
3953 -- pragma Abort_Defer;
3955 when Pragma_Abort_Defer =>
3957 Check_Arg_Count (0);
3959 -- The only required semantic processing is to check the
3960 -- placement. This pragma must appear at the start of the
3961 -- statement sequence of a handled sequence of statements.
3963 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
3964 or else N /= First (Statements (Parent (N)))
3975 -- Note: this pragma also has some specific processing in Par.Prag
3976 -- because we want to set the Ada 83 mode switch during parsing.
3978 when Pragma_Ada_83 =>
3982 Check_Arg_Count (0);
3990 -- Note: this pragma also has some specific processing in Par.Prag
3991 -- because we want to set the Ada 83 mode switch during parsing.
3993 when Pragma_Ada_95 =>
3997 Check_Arg_Count (0);
3999 ----------------------
4000 -- All_Calls_Remote --
4001 ----------------------
4003 -- pragma All_Calls_Remote [(library_package_NAME)];
4005 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4006 Lib_Entity : Entity_Id;
4009 Check_Ada_83_Warning;
4010 Check_Valid_Library_Unit_Pragma;
4012 if Nkind (N) = N_Null_Statement then
4016 Lib_Entity := Find_Lib_Unit_Name;
4018 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4020 if Present (Lib_Entity)
4021 and then not Debug_Flag_U
4023 if not Is_Remote_Call_Interface (Lib_Entity) then
4024 Error_Pragma ("pragma% only apply to rci unit");
4026 -- Set flag for entity of the library unit
4029 Set_Has_All_Calls_Remote (Lib_Entity);
4033 end All_Calls_Remote;
4039 -- pragma Annotate (IDENTIFIER {, ARG});
4040 -- ARG ::= NAME | EXPRESSION
4042 when Pragma_Annotate => Annotate : begin
4044 Check_At_Least_N_Arguments (1);
4045 Check_Arg_Is_Identifier (Arg1);
4048 Arg : Node_Id := Arg2;
4052 while Present (Arg) loop
4053 Exp := Expression (Arg);
4056 if Is_Entity_Name (Exp) then
4059 elsif Nkind (Exp) = N_String_Literal then
4060 Resolve (Exp, Standard_String);
4062 elsif Is_Overloaded (Exp) then
4063 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4078 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4080 when Pragma_Assert =>
4082 Check_No_Identifiers;
4084 if Arg_Count > 1 then
4085 Check_Arg_Count (2);
4086 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4089 -- If expansion is active and assertions are inactive, then
4090 -- we rewrite the Assertion as:
4092 -- if False and then condition then
4096 -- The reason we do this rewriting during semantic analysis
4097 -- rather than as part of normal expansion is that we cannot
4098 -- analyze and expand the code for the boolean expression
4099 -- directly, or it may cause insertion of actions that would
4100 -- escape the attempt to suppress the assertion code.
4102 if Expander_Active and not Assertions_Enabled then
4104 Make_If_Statement (Loc,
4107 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4108 Right_Opnd => Get_Pragma_Arg (Arg1)),
4109 Then_Statements => New_List (
4110 Make_Null_Statement (Loc))));
4114 -- Otherwise (if assertions are enabled, or if we are not
4115 -- operating with expansion active), then we just analyze
4116 -- and resolve the expression.
4119 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4126 -- pragma AST_Entry (entry_IDENTIFIER);
4128 when Pragma_AST_Entry => AST_Entry : declare
4134 Check_Arg_Count (1);
4135 Check_No_Identifiers;
4136 Check_Arg_Is_Local_Name (Arg1);
4137 Ent := Entity (Expression (Arg1));
4139 -- Note: the implementation of the AST_Entry pragma could handle
4140 -- the entry family case fine, but for now we are consistent with
4141 -- the DEC rules, and do not allow the pragma, which of course
4142 -- has the effect of also forbidding the attribute.
4144 if Ekind (Ent) /= E_Entry then
4146 ("pragma% argument must be simple entry name", Arg1);
4148 elsif Is_AST_Entry (Ent) then
4150 ("duplicate % pragma for entry", Arg1);
4152 elsif Has_Homonym (Ent) then
4154 ("pragma% argument cannot specify overloaded entry", Arg1);
4158 FF : constant Entity_Id := First_Formal (Ent);
4161 if Present (FF) then
4162 if Present (Next_Formal (FF)) then
4164 ("entry for pragma% can have only one argument",
4167 elsif Parameter_Mode (FF) /= E_In_Parameter then
4169 ("entry parameter for pragma% must have mode IN",
4175 Set_Is_AST_Entry (Ent);
4183 -- pragma Asynchronous (LOCAL_NAME);
4185 when Pragma_Asynchronous => Asynchronous : declare
4193 procedure Process_Async_Pragma;
4194 -- Common processing for procedure and access-to-procedure case
4196 --------------------------
4197 -- Process_Async_Pragma --
4198 --------------------------
4200 procedure Process_Async_Pragma is
4202 if not Present (L) then
4203 Set_Is_Asynchronous (Nm);
4207 -- The formals should be of mode IN (RM E.4.1(6))
4210 while Present (S) loop
4211 Formal := Defining_Identifier (S);
4213 if Nkind (Formal) = N_Defining_Identifier
4214 and then Ekind (Formal) /= E_In_Parameter
4217 ("pragma% procedure can only have IN parameter",
4224 Set_Is_Asynchronous (Nm);
4225 end Process_Async_Pragma;
4227 -- Start of processing for pragma Asynchronous
4230 Check_Ada_83_Warning;
4231 Check_No_Identifiers;
4232 Check_Arg_Count (1);
4233 Check_Arg_Is_Local_Name (Arg1);
4235 if Debug_Flag_U then
4239 C_Ent := Cunit_Entity (Current_Sem_Unit);
4240 Analyze (Expression (Arg1));
4241 Nm := Entity (Expression (Arg1));
4243 if not Is_Remote_Call_Interface (C_Ent)
4244 and then not Is_Remote_Types (C_Ent)
4246 -- This pragma should only appear in an RCI or Remote Types
4247 -- unit (RM E.4.1(4))
4250 ("pragma% not in Remote_Call_Interface or " &
4251 "Remote_Types unit");
4254 if Ekind (Nm) = E_Procedure
4255 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4257 if not Is_Remote_Call_Interface (Nm) then
4259 ("pragma% cannot be applied on non-remote procedure",
4263 L := Parameter_Specifications (Parent (Nm));
4264 Process_Async_Pragma;
4267 elsif Ekind (Nm) = E_Function then
4269 ("pragma% cannot be applied to function", Arg1);
4271 elsif Ekind (Nm) = E_Record_Type
4272 and then Present (Corresponding_Remote_Type (Nm))
4274 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4276 if Nkind (N) = N_Full_Type_Declaration
4277 and then Nkind (Type_Definition (N)) =
4278 N_Access_Procedure_Definition
4280 L := Parameter_Specifications (Type_Definition (N));
4281 Process_Async_Pragma;
4285 ("pragma% cannot reference access-to-function type",
4289 -- Only other possibility is Access-to-class-wide type
4291 elsif Is_Access_Type (Nm)
4292 and then Is_Class_Wide_Type (Designated_Type (Nm))
4294 Check_First_Subtype (Arg1);
4295 Set_Is_Asynchronous (Nm);
4296 if Expander_Active then
4297 RACW_Type_Is_Asynchronous (Nm);
4301 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4309 -- pragma Atomic (LOCAL_NAME);
4311 when Pragma_Atomic =>
4312 Process_Atomic_Shared_Volatile;
4314 -----------------------
4315 -- Atomic_Components --
4316 -----------------------
4318 -- pragma Atomic_Components (array_LOCAL_NAME);
4320 -- This processing is shared by Volatile_Components
4322 when Pragma_Atomic_Components |
4323 Pragma_Volatile_Components =>
4325 Atomic_Components : declare
4332 Check_Ada_83_Warning;
4333 Check_No_Identifiers;
4334 Check_Arg_Count (1);
4335 Check_Arg_Is_Local_Name (Arg1);
4336 E_Id := Expression (Arg1);
4338 if Etype (E_Id) = Any_Type then
4344 if Rep_Item_Too_Early (E, N)
4346 Rep_Item_Too_Late (E, N)
4351 D := Declaration_Node (E);
4354 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4356 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4357 and then Nkind (D) = N_Object_Declaration
4358 and then Nkind (Object_Definition (D)) =
4359 N_Constrained_Array_Definition)
4361 -- The flag is set on the object, or on the base type
4363 if Nkind (D) /= N_Object_Declaration then
4367 Set_Has_Volatile_Components (E);
4369 if Prag_Id = Pragma_Atomic_Components then
4370 Set_Has_Atomic_Components (E);
4372 if Is_Packed (E) then
4373 Set_Is_Packed (E, False);
4376 ("?Pack canceled, cannot pack atomic components",
4382 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4384 end Atomic_Components;
4386 --------------------
4387 -- Attach_Handler --
4388 --------------------
4390 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4392 when Pragma_Attach_Handler =>
4393 Check_Ada_83_Warning;
4394 Check_No_Identifiers;
4395 Check_Arg_Count (2);
4397 if No_Run_Time_Mode then
4398 Error_Msg_CRT ("Attach_Handler pragma", N);
4400 Check_Interrupt_Or_Attach_Handler;
4402 -- The expression that designates the attribute may
4403 -- depend on a discriminant, and is therefore a per-
4404 -- object expression, to be expanded in the init proc.
4405 -- If expansion is enabled, perform semantic checks
4408 if Expander_Active then
4410 Temp : constant Node_Id :=
4411 New_Copy_Tree (Expression (Arg2));
4413 Set_Parent (Temp, N);
4414 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4418 Analyze (Expression (Arg2));
4419 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4422 Process_Interrupt_Or_Attach_Handler;
4425 --------------------
4426 -- C_Pass_By_Copy --
4427 --------------------
4429 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4431 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4437 Check_Valid_Configuration_Pragma;
4438 Check_Arg_Count (1);
4439 Check_Optional_Identifier (Arg1, "max_size");
4441 Arg := Expression (Arg1);
4442 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4444 Val := Expr_Value (Arg);
4448 ("maximum size for pragma% must be positive", Arg1);
4450 elsif UI_Is_In_Int_Range (Val) then
4451 Default_C_Record_Mechanism := UI_To_Int (Val);
4453 -- If a giant value is given, Int'Last will do well enough.
4454 -- If sometime someone complains that a record larger than
4455 -- two gigabytes is not copied, we will worry about it then!
4458 Default_C_Record_Mechanism := Mechanism_Type'Last;
4466 -- pragma Comment (static_string_EXPRESSION)
4468 -- Processing for pragma Comment shares the circuitry for
4469 -- pragma Ident. The only differences are that Ident enforces
4470 -- a limit of 31 characters on its argument, and also enforces
4471 -- limitations on placement for DEC compatibility. Pragma
4472 -- Comment shares neither of these restrictions.
4478 -- pragma Common_Object (
4479 -- [Internal =>] LOCAL_NAME,
4480 -- [, [External =>] EXTERNAL_SYMBOL]
4481 -- [, [Size =>] EXTERNAL_SYMBOL]);
4483 -- Processing for this pragma is shared with Psect_Object
4485 --------------------------
4486 -- Compile_Time_Warning --
4487 --------------------------
4489 -- pragma Compile_Time_Warning
4490 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4492 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4493 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4497 Check_Arg_Count (2);
4498 Check_No_Identifiers;
4499 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4500 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4502 if Compile_Time_Known_Value (Arg1x) then
4503 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4504 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4505 Add_Char_To_Name_Buffer ('?');
4508 Msg : String (1 .. Name_Len) :=
4509 Name_Buffer (1 .. Name_Len);
4514 -- This loop looks for multiple lines separated by
4515 -- ASCII.LF and breaks them into continuation error
4516 -- messages marked with the usual back slash.
4519 for S in 2 .. Msg'Length - 1 loop
4520 if Msg (S) = ASCII.LF then
4522 Error_Msg_N (Msg (B .. S), Arg1);
4528 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4532 end Compile_Time_Warning;
4534 ----------------------------
4535 -- Complex_Representation --
4536 ----------------------------
4538 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4540 when Pragma_Complex_Representation => Complex_Representation : declare
4547 Check_Arg_Count (1);
4548 Check_Optional_Identifier (Arg1, Name_Entity);
4549 Check_Arg_Is_Local_Name (Arg1);
4550 E_Id := Expression (Arg1);
4552 if Etype (E_Id) = Any_Type then
4558 if not Is_Record_Type (E) then
4560 ("argument for pragma% must be record type", Arg1);
4563 Ent := First_Entity (E);
4566 or else No (Next_Entity (Ent))
4567 or else Present (Next_Entity (Next_Entity (Ent)))
4568 or else not Is_Floating_Point_Type (Etype (Ent))
4569 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4572 ("record for pragma% must have two fields of same fpt type",
4576 Set_Has_Complex_Representation (Base_Type (E));
4578 end Complex_Representation;
4580 -------------------------
4581 -- Component_Alignment --
4582 -------------------------
4584 -- pragma Component_Alignment (
4585 -- [Form =>] ALIGNMENT_CHOICE
4586 -- [, [Name =>] type_LOCAL_NAME]);
4588 -- ALIGNMENT_CHOICE ::=
4590 -- | Component_Size_4
4594 when Pragma_Component_Alignment => Component_AlignmentP : declare
4595 Args : Args_List (1 .. 2);
4596 Names : constant Name_List (1 .. 2) := (
4600 Form : Node_Id renames Args (1);
4601 Name : Node_Id renames Args (2);
4603 Atype : Component_Alignment_Kind;
4608 Gather_Associations (Names, Args);
4611 Error_Pragma ("missing Form argument for pragma%");
4614 Check_Arg_Is_Identifier (Form);
4616 -- Get proper alignment, note that Default = Component_Size
4617 -- on all machines we have so far, and we want to set this
4618 -- value rather than the default value to indicate that it
4619 -- has been explicitly set (and thus will not get overridden
4620 -- by the default component alignment for the current scope)
4622 if Chars (Form) = Name_Component_Size then
4623 Atype := Calign_Component_Size;
4625 elsif Chars (Form) = Name_Component_Size_4 then
4626 Atype := Calign_Component_Size_4;
4628 elsif Chars (Form) = Name_Default then
4629 Atype := Calign_Component_Size;
4631 elsif Chars (Form) = Name_Storage_Unit then
4632 Atype := Calign_Storage_Unit;
4636 ("invalid Form parameter for pragma%", Form);
4639 -- Case with no name, supplied, affects scope table entry
4643 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4645 -- Case of name supplied
4648 Check_Arg_Is_Local_Name (Name);
4650 Typ := Entity (Name);
4653 or else Rep_Item_Too_Early (Typ, N)
4657 Typ := Underlying_Type (Typ);
4660 if not Is_Record_Type (Typ)
4661 and then not Is_Array_Type (Typ)
4664 ("Name parameter of pragma% must identify record or " &
4665 "array type", Name);
4668 -- An explicit Component_Alignment pragma overrides an
4669 -- implicit pragma Pack, but not an explicit one.
4671 if not Has_Pragma_Pack (Base_Type (Typ)) then
4672 Set_Is_Packed (Base_Type (Typ), False);
4673 Set_Component_Alignment (Base_Type (Typ), Atype);
4676 end Component_AlignmentP;
4682 -- pragma Controlled (first_subtype_LOCAL_NAME);
4684 when Pragma_Controlled => Controlled : declare
4688 Check_No_Identifiers;
4689 Check_Arg_Count (1);
4690 Check_Arg_Is_Local_Name (Arg1);
4691 Arg := Expression (Arg1);
4693 if not Is_Entity_Name (Arg)
4694 or else not Is_Access_Type (Entity (Arg))
4696 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4698 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4706 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4707 -- [Entity =>] LOCAL_NAME);
4709 when Pragma_Convention => Convention : declare
4713 Check_Ada_83_Warning;
4714 Check_Arg_Count (2);
4715 Process_Convention (C, E);
4718 ---------------------------
4719 -- Convention_Identifier --
4720 ---------------------------
4722 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
4723 -- [Convention =>] convention_IDENTIFIER);
4725 when Pragma_Convention_Identifier => Convention_Identifier : declare
4731 Check_Arg_Count (2);
4732 Check_Optional_Identifier (Arg1, Name_Name);
4733 Check_Optional_Identifier (Arg2, Name_Convention);
4734 Check_Arg_Is_Identifier (Arg1);
4735 Check_Arg_Is_Identifier (Arg1);
4736 Idnam := Chars (Expression (Arg1));
4737 Cname := Chars (Expression (Arg2));
4739 if Is_Convention_Name (Cname) then
4740 Record_Convention_Identifier
4741 (Idnam, Get_Convention_Id (Cname));
4744 ("second arg for % pragma must be convention", Arg2);
4746 end Convention_Identifier;
4752 -- pragma CPP_Class ([Entity =>] local_NAME)
4754 when Pragma_CPP_Class => CPP_Class : declare
4757 Default_DTC : Entity_Id := Empty;
4758 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4764 Check_Arg_Count (1);
4765 Check_Optional_Identifier (Arg1, Name_Entity);
4766 Check_Arg_Is_Local_Name (Arg1);
4768 Arg := Expression (Arg1);
4771 if Etype (Arg) = Any_Type then
4775 if not Is_Entity_Name (Arg)
4776 or else not Is_Type (Entity (Arg))
4778 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
4781 Typ := Entity (Arg);
4783 if not Is_Record_Type (Typ) then
4784 Error_Pragma_Arg ("pragma% applicable to a record, "
4785 & "tagged record or record extension", Arg1);
4788 Default_DTC := First_Component (Typ);
4789 while Present (Default_DTC)
4790 and then Etype (Default_DTC) /= VTP_Type
4792 Next_Component (Default_DTC);
4795 -- Case of non tagged type
4797 if not Is_Tagged_Type (Typ) then
4798 Set_Is_CPP_Class (Typ);
4800 if Present (Default_DTC) then
4802 ("only tagged records can contain vtable pointers", Arg1);
4805 -- Case of tagged type with no vtable ptr
4807 -- What is test for Typ = Root_Typ (Typ) about here ???
4809 elsif Is_Tagged_Type (Typ)
4810 and then Typ = Root_Type (Typ)
4811 and then No (Default_DTC)
4814 ("a cpp_class must contain a vtable pointer", Arg1);
4816 -- Tagged type that has a vtable ptr
4818 elsif Present (Default_DTC) then
4819 Set_Is_CPP_Class (Typ);
4820 Set_Is_Limited_Record (Typ);
4821 Set_Is_Tag (Default_DTC);
4822 Set_DT_Entry_Count (Default_DTC, No_Uint);
4824 -- Since a CPP type has no direct link to its associated tag
4825 -- most tags checks cannot be performed
4827 Set_Kill_Tag_Checks (Typ);
4828 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
4830 -- Get rid of the _tag component when there was one.
4831 -- It is only useful for regular tagged types
4833 if Expander_Active and then Typ = Root_Type (Typ) then
4835 Tag_C := Tag_Component (Typ);
4836 C := First_Entity (Typ);
4839 Set_First_Entity (Typ, Next_Entity (Tag_C));
4842 while Next_Entity (C) /= Tag_C loop
4846 Set_Next_Entity (C, Next_Entity (Tag_C));
4852 ---------------------
4853 -- CPP_Constructor --
4854 ---------------------
4856 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
4858 when Pragma_CPP_Constructor => CPP_Constructor : declare
4864 Check_Arg_Count (1);
4865 Check_Optional_Identifier (Arg1, Name_Entity);
4866 Check_Arg_Is_Local_Name (Arg1);
4868 Id := Expression (Arg1);
4869 Find_Program_Unit_Name (Id);
4871 -- If we did not find the name, we are done
4873 if Etype (Id) = Any_Type then
4877 Def_Id := Entity (Id);
4879 if Ekind (Def_Id) = E_Function
4880 and then Is_Class_Wide_Type (Etype (Def_Id))
4881 and then Is_CPP_Class (Etype (Etype (Def_Id)))
4883 -- What the heck is this??? this pragma allows only 1 arg
4885 if Arg_Count >= 2 then
4886 Check_At_Most_N_Arguments (3);
4887 Process_Interface_Name (Def_Id, Arg2, Arg3);
4890 if No (Parameter_Specifications (Parent (Def_Id))) then
4891 Set_Has_Completion (Def_Id);
4892 Set_Is_Constructor (Def_Id);
4895 ("non-default constructors not implemented", Arg1);
4900 ("pragma% requires function returning a 'C'P'P_Class type",
4903 end CPP_Constructor;
4909 -- pragma CPP_Virtual
4910 -- [Entity =>] LOCAL_NAME
4911 -- [ [Vtable_Ptr =>] LOCAL_NAME,
4912 -- [Position =>] static_integer_EXPRESSION]);
4914 when Pragma_CPP_Virtual => CPP_Virtual : declare
4918 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4925 if Arg_Count = 3 then
4926 Check_Optional_Identifier (Arg2, "vtable_ptr");
4928 -- We allow Entry_Count as well as Position for the third
4929 -- parameter for back compatibility with versions of GNAT
4930 -- before version 3.12. The documentation has always said
4931 -- Position, but the code up to 3.12 said Entry_Count.
4933 if Chars (Arg3) /= Name_Position then
4934 Check_Optional_Identifier (Arg3, "entry_count");
4938 Check_Arg_Count (1);
4941 Check_Optional_Identifier (Arg1, Name_Entity);
4942 Check_Arg_Is_Local_Name (Arg1);
4944 -- First argument must be a subprogram name
4946 Arg := Expression (Arg1);
4947 Find_Program_Unit_Name (Arg);
4949 if Etype (Arg) = Any_Type then
4952 Subp := Entity (Arg);
4955 if not (Is_Subprogram (Subp)
4956 and then Is_Dispatching_Operation (Subp))
4959 ("pragma% must reference a primitive operation", Arg1);
4962 Typ := Find_Dispatching_Type (Subp);
4964 -- If only one Argument defaults are :
4965 -- . DTC_Entity is the default Vtable pointer
4966 -- . DT_Position will be set at the freezing point
4968 if Arg_Count = 1 then
4969 Set_DTC_Entity (Subp, Tag_Component (Typ));
4973 -- Second argument is a component name of type Vtable_Ptr
4975 Arg := Expression (Arg2);
4977 if Nkind (Arg) /= N_Identifier then
4978 Error_Msg_NE ("must be a& component name", Arg, Typ);
4982 DTC := First_Component (Typ);
4983 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4984 Next_Component (DTC);
4988 Error_Msg_NE ("must be a& component name", Arg, Typ);
4991 elsif Etype (DTC) /= VTP_Type then
4992 Wrong_Type (Arg, VTP_Type);
4996 -- Third argument is an integer (DT_Position)
4998 Arg := Expression (Arg3);
4999 Analyze_And_Resolve (Arg, Any_Integer);
5001 if not Is_Static_Expression (Arg) then
5002 Flag_Non_Static_Expr
5003 ("third argument of pragma CPP_Virtual must be static!",
5008 V := Expr_Value (Expression (Arg3));
5012 ("third argument of pragma% must be positive",
5016 Set_DTC_Entity (Subp, DTC);
5017 Set_DT_Position (Subp, V);
5026 -- pragma CPP_Vtable (
5027 -- [Entity =>] LOCAL_NAME
5028 -- [Vtable_Ptr =>] LOCAL_NAME,
5029 -- [Entry_Count =>] static_integer_EXPRESSION);
5031 when Pragma_CPP_Vtable => CPP_Vtable : declare
5034 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5041 Check_Arg_Count (3);
5042 Check_Optional_Identifier (Arg1, Name_Entity);
5043 Check_Optional_Identifier (Arg2, "vtable_ptr");
5044 Check_Optional_Identifier (Arg3, "entry_count");
5045 Check_Arg_Is_Local_Name (Arg1);
5047 -- First argument is a record type name
5049 Arg := Expression (Arg1);
5052 if Etype (Arg) = Any_Type then
5055 Typ := Entity (Arg);
5058 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5059 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5062 -- Second argument is a component name of type Vtable_Ptr
5064 Arg := Expression (Arg2);
5066 if Nkind (Arg) /= N_Identifier then
5067 Error_Msg_NE ("must be a& component name", Arg, Typ);
5071 DTC := First_Component (Typ);
5072 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5073 Next_Component (DTC);
5077 Error_Msg_NE ("must be a& component name", Arg, Typ);
5080 elsif Etype (DTC) /= VTP_Type then
5081 Wrong_Type (DTC, VTP_Type);
5084 -- If it is the first pragma Vtable, This becomes the default tag
5086 elsif (not Is_Tag (DTC))
5087 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
5089 Set_Is_Tag (Tag_Component (Typ), False);
5090 Set_Is_Tag (DTC, True);
5091 Set_DT_Entry_Count (DTC, No_Uint);
5094 -- Those pragmas must appear before any primitive operation
5095 -- definition (except inherited ones) otherwise the default
5098 Elmt := First_Elmt (Primitive_Operations (Typ));
5099 while Present (Elmt) loop
5100 if No (Alias (Node (Elmt))) then
5101 Error_Msg_Sloc := Sloc (Node (Elmt));
5103 ("pragma% must appear before this primitive operation");
5109 -- Third argument is an integer (DT_Entry_Count)
5111 Arg := Expression (Arg3);
5112 Analyze_And_Resolve (Arg, Any_Integer);
5114 if not Is_Static_Expression (Arg) then
5115 Flag_Non_Static_Expr
5116 ("entry count for pragma CPP_Vtable must be a static " &
5117 "expression!", Arg3);
5121 V := Expr_Value (Expression (Arg3));
5125 ("entry count for pragma% must be positive", Arg3);
5127 Set_DT_Entry_Count (DTC, V);
5136 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5138 when Pragma_Debug => Debug : begin
5141 -- If assertions are enabled, and we are expanding code, then
5142 -- we rewrite the pragma with its corresponding procedure call
5143 -- and then analyze the call.
5145 if Assertions_Enabled and Expander_Active then
5146 Rewrite (N, Relocate_Node (Debug_Statement (N)));
5149 -- Otherwise we work a bit to get a tree that makes sense
5150 -- for ASIS purposes, namely a pragma with an analyzed
5151 -- argument that looks like a procedure call.
5154 Expander_Mode_Save_And_Set (False);
5155 Rewrite (N, Relocate_Node (Debug_Statement (N)));
5159 Chars => Name_Debug,
5160 Pragma_Argument_Associations =>
5161 New_List (Relocate_Node (N))));
5162 Expander_Mode_Restore;
5170 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5172 when Pragma_Discard_Names => Discard_Names : declare
5177 Check_Ada_83_Warning;
5179 -- Deal with configuration pragma case
5181 if Arg_Count = 0 and then Is_Configuration_Pragma then
5182 Global_Discard_Names := True;
5185 -- Otherwise, check correct appropriate context
5188 Check_Is_In_Decl_Part_Or_Package_Spec;
5190 if Arg_Count = 0 then
5192 -- If there is no parameter, then from now on this pragma
5193 -- applies to any enumeration, exception or tagged type
5194 -- defined in the current declarative part.
5196 Set_Discard_Names (Current_Scope);
5200 Check_Arg_Count (1);
5201 Check_Optional_Identifier (Arg1, Name_On);
5202 Check_Arg_Is_Local_Name (Arg1);
5203 E_Id := Expression (Arg1);
5205 if Etype (E_Id) = Any_Type then
5211 if (Is_First_Subtype (E)
5212 and then (Is_Enumeration_Type (E)
5213 or else Is_Tagged_Type (E)))
5214 or else Ekind (E) = E_Exception
5216 Set_Discard_Names (E);
5219 ("inappropriate entity for pragma%", Arg1);
5229 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5231 when Pragma_Elaborate => Elaborate : declare
5233 Parent_Node : Node_Id;
5238 -- Pragma must be in context items list of a compilation unit
5240 if not Is_List_Member (N) then
5245 Plist := List_Containing (N);
5246 Parent_Node := Parent (Plist);
5248 if Parent_Node = Empty
5249 or else Nkind (Parent_Node) /= N_Compilation_Unit
5250 or else Context_Items (Parent_Node) /= Plist
5257 -- Must be at least one argument
5259 if Arg_Count = 0 then
5260 Error_Pragma ("pragma% requires at least one argument");
5263 -- In Ada 83 mode, there can be no items following it in the
5264 -- context list except other pragmas and implicit with clauses
5265 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5266 -- placement rule does not apply.
5268 if Ada_83 and then Comes_From_Source (N) then
5271 while Present (Citem) loop
5272 if Nkind (Citem) = N_Pragma
5273 or else (Nkind (Citem) = N_With_Clause
5274 and then Implicit_With (Citem))
5279 ("(Ada 83) pragma% must be at end of context clause");
5286 -- Finally, the arguments must all be units mentioned in a with
5287 -- clause in the same context clause. Note we already checked
5288 -- (in Par.Prag) that the arguments are either identifiers or
5291 Outer : while Present (Arg) loop
5292 Citem := First (Plist);
5294 Inner : while Citem /= N loop
5295 if Nkind (Citem) = N_With_Clause
5296 and then Same_Name (Name (Citem), Expression (Arg))
5298 Set_Elaborate_Present (Citem, True);
5299 Set_Unit_Name (Expression (Arg), Name (Citem));
5300 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5309 ("argument of pragma% is not with'ed unit", Arg);
5315 -- Give a warning if operating in static mode with -gnatwl
5316 -- (elaboration warnings eanbled) switch set.
5318 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5320 ("?use of pragma Elaborate may not be safe", N);
5322 ("?use pragma Elaborate_All instead if possible", N);
5330 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5332 when Pragma_Elaborate_All => Elaborate_All : declare
5334 Parent_Node : Node_Id;
5339 Check_Ada_83_Warning;
5341 -- Pragma must be in context items list of a compilation unit
5343 if not Is_List_Member (N) then
5348 Plist := List_Containing (N);
5349 Parent_Node := Parent (Plist);
5351 if Parent_Node = Empty
5352 or else Nkind (Parent_Node) /= N_Compilation_Unit
5353 or else Context_Items (Parent_Node) /= Plist
5360 -- Must be at least one argument
5362 if Arg_Count = 0 then
5363 Error_Pragma ("pragma% requires at least one argument");
5366 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5367 -- have to appear at the end of the context clause, but may
5368 -- appear mixed in with other items, even in Ada 83 mode.
5370 -- Final check: the arguments must all be units mentioned in
5371 -- a with clause in the same context clause. Note that we
5372 -- already checked (in Par.Prag) that all the arguments are
5373 -- either identifiers or selected components.
5376 Outr : while Present (Arg) loop
5377 Citem := First (Plist);
5379 Innr : while Citem /= N loop
5380 if Nkind (Citem) = N_With_Clause
5381 and then Same_Name (Name (Citem), Expression (Arg))
5383 Set_Elaborate_All_Present (Citem, True);
5384 Set_Unit_Name (Expression (Arg), Name (Citem));
5385 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5393 Set_Error_Posted (N);
5395 ("argument of pragma% is not with'ed unit", Arg);
5402 --------------------
5403 -- Elaborate_Body --
5404 --------------------
5406 -- pragma Elaborate_Body [( library_unit_NAME )];
5408 when Pragma_Elaborate_Body => Elaborate_Body : declare
5409 Cunit_Node : Node_Id;
5410 Cunit_Ent : Entity_Id;
5413 Check_Ada_83_Warning;
5414 Check_Valid_Library_Unit_Pragma;
5416 if Nkind (N) = N_Null_Statement then
5420 Cunit_Node := Cunit (Current_Sem_Unit);
5421 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5423 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5425 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5427 Error_Pragma ("pragma% must refer to a spec, not a body");
5429 Set_Body_Required (Cunit_Node, True);
5430 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5432 -- If we are in dynamic elaboration mode, then we suppress
5433 -- elaboration warnings for the unit, since it is definitely
5434 -- fine NOT to do dynamic checks at the first level (and such
5435 -- checks will be suppressed because no elaboration boolean
5436 -- is created for Elaborate_Body packages).
5438 -- But in the static model of elaboration, Elaborate_Body is
5439 -- definitely NOT good enough to ensure elaboration safety on
5440 -- its own, since the body may WITH other units that are not
5441 -- safe from an elaboration point of view, so a client must
5442 -- still do an Elaborate_All on such units.
5444 -- Debug flag -gnatdD restores the old behavior of 3.13,
5445 -- where Elaborate_Body always suppressed elab warnings.
5447 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5448 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5453 ------------------------
5454 -- Elaboration_Checks --
5455 ------------------------
5457 -- pragma Elaboration_Checks (Static | Dynamic);
5459 when Pragma_Elaboration_Checks =>
5461 Check_Arg_Count (1);
5462 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5463 Dynamic_Elaboration_Checks :=
5464 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5470 -- pragma Eliminate (
5471 -- [Unit_Name =>] IDENTIFIER |
5472 -- SELECTED_COMPONENT
5473 -- [,[Entity =>] IDENTIFIER |
5474 -- SELECTED_COMPONENT |
5476 -- [,]OVERLOADING_RESOLUTION);
5478 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5481 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5484 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5486 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5487 -- Result_Type => result_SUBTYPE_NAME]
5489 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5490 -- SUBTYPE_NAME ::= STRING_LITERAL
5492 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5493 -- SOURCE_TRACE ::= STRING_LITERAL
5495 when Pragma_Eliminate => Eliminate : declare
5496 Args : Args_List (1 .. 5);
5497 Names : constant Name_List (1 .. 5) := (
5500 Name_Parameter_Types,
5502 Name_Source_Location);
5504 Unit_Name : Node_Id renames Args (1);
5505 Entity : Node_Id renames Args (2);
5506 Parameter_Types : Node_Id renames Args (3);
5507 Result_Type : Node_Id renames Args (4);
5508 Source_Location : Node_Id renames Args (5);
5512 Check_Valid_Configuration_Pragma;
5513 Gather_Associations (Names, Args);
5515 if No (Unit_Name) then
5516 Error_Pragma ("missing Unit_Name argument for pragma%");
5520 and then (Present (Parameter_Types)
5522 Present (Result_Type)
5524 Present (Source_Location))
5526 Error_Pragma ("missing Entity argument for pragma%");
5529 if (Present (Parameter_Types)
5531 Present (Result_Type))
5533 Present (Source_Location)
5536 ("parameter profile and source location can not " &
5537 "be used together in pragma%");
5540 Process_Eliminate_Pragma
5549 --------------------------
5550 -- Explicit_Overriding --
5551 --------------------------
5553 when Pragma_Explicit_Overriding =>
5554 Check_Valid_Configuration_Pragma;
5555 Check_Arg_Count (0);
5556 Explicit_Overriding := True;
5563 -- [ Convention =>] convention_IDENTIFIER,
5564 -- [ Entity =>] local_NAME
5565 -- [, [External_Name =>] static_string_EXPRESSION ]
5566 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5568 when Pragma_Export => Export : declare
5573 Check_Ada_83_Warning;
5574 Check_At_Least_N_Arguments (2);
5575 Check_At_Most_N_Arguments (4);
5576 Process_Convention (C, Def_Id);
5578 if Ekind (Def_Id) /= E_Constant then
5579 Note_Possible_Modification (Expression (Arg2));
5582 Process_Interface_Name (Def_Id, Arg3, Arg4);
5583 Set_Exported (Def_Id, Arg2);
5586 ----------------------
5587 -- Export_Exception --
5588 ----------------------
5590 -- pragma Export_Exception (
5591 -- [Internal =>] LOCAL_NAME,
5592 -- [, [External =>] EXTERNAL_SYMBOL,]
5593 -- [, [Form =>] Ada | VMS]
5594 -- [, [Code =>] static_integer_EXPRESSION]);
5596 when Pragma_Export_Exception => Export_Exception : declare
5597 Args : Args_List (1 .. 4);
5598 Names : constant Name_List (1 .. 4) := (
5604 Internal : Node_Id renames Args (1);
5605 External : Node_Id renames Args (2);
5606 Form : Node_Id renames Args (3);
5607 Code : Node_Id renames Args (4);
5610 if Inside_A_Generic then
5611 Error_Pragma ("pragma% cannot be used for generic entities");
5614 Gather_Associations (Names, Args);
5615 Process_Extended_Import_Export_Exception_Pragma (
5616 Arg_Internal => Internal,
5617 Arg_External => External,
5621 if not Is_VMS_Exception (Entity (Internal)) then
5622 Set_Exported (Entity (Internal), Internal);
5624 end Export_Exception;
5626 ---------------------
5627 -- Export_Function --
5628 ---------------------
5630 -- pragma Export_Function (
5631 -- [Internal =>] LOCAL_NAME,
5632 -- [, [External =>] EXTERNAL_SYMBOL,]
5633 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5634 -- [, [Result_Type =>] TYPE_DESIGNATOR]
5635 -- [, [Mechanism =>] MECHANISM]
5636 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5638 -- EXTERNAL_SYMBOL ::=
5640 -- | static_string_EXPRESSION
5642 -- PARAMETER_TYPES ::=
5644 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5646 -- TYPE_DESIGNATOR ::=
5648 -- | subtype_Name ' Access
5652 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5654 -- MECHANISM_ASSOCIATION ::=
5655 -- [formal_parameter_NAME =>] MECHANISM_NAME
5657 -- MECHANISM_NAME ::=
5660 -- | Descriptor [([Class =>] CLASS_NAME)]
5662 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5664 when Pragma_Export_Function => Export_Function : declare
5665 Args : Args_List (1 .. 6);
5666 Names : constant Name_List (1 .. 6) := (
5669 Name_Parameter_Types,
5672 Name_Result_Mechanism);
5674 Internal : Node_Id renames Args (1);
5675 External : Node_Id renames Args (2);
5676 Parameter_Types : Node_Id renames Args (3);
5677 Result_Type : Node_Id renames Args (4);
5678 Mechanism : Node_Id renames Args (5);
5679 Result_Mechanism : Node_Id renames Args (6);
5683 Gather_Associations (Names, Args);
5684 Process_Extended_Import_Export_Subprogram_Pragma (
5685 Arg_Internal => Internal,
5686 Arg_External => External,
5687 Arg_Parameter_Types => Parameter_Types,
5688 Arg_Result_Type => Result_Type,
5689 Arg_Mechanism => Mechanism,
5690 Arg_Result_Mechanism => Result_Mechanism);
5691 end Export_Function;
5697 -- pragma Export_Object (
5698 -- [Internal =>] LOCAL_NAME,
5699 -- [, [External =>] EXTERNAL_SYMBOL]
5700 -- [, [Size =>] EXTERNAL_SYMBOL]);
5702 -- EXTERNAL_SYMBOL ::=
5704 -- | static_string_EXPRESSION
5706 -- PARAMETER_TYPES ::=
5708 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5710 -- TYPE_DESIGNATOR ::=
5712 -- | subtype_Name ' Access
5716 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5718 -- MECHANISM_ASSOCIATION ::=
5719 -- [formal_parameter_NAME =>] MECHANISM_NAME
5721 -- MECHANISM_NAME ::=
5724 -- | Descriptor [([Class =>] CLASS_NAME)]
5726 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5728 when Pragma_Export_Object => Export_Object : declare
5729 Args : Args_List (1 .. 3);
5730 Names : constant Name_List (1 .. 3) := (
5735 Internal : Node_Id renames Args (1);
5736 External : Node_Id renames Args (2);
5737 Size : Node_Id renames Args (3);
5741 Gather_Associations (Names, Args);
5742 Process_Extended_Import_Export_Object_Pragma (
5743 Arg_Internal => Internal,
5744 Arg_External => External,
5748 ----------------------
5749 -- Export_Procedure --
5750 ----------------------
5752 -- pragma Export_Procedure (
5753 -- [Internal =>] LOCAL_NAME,
5754 -- [, [External =>] EXTERNAL_SYMBOL,]
5755 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5756 -- [, [Mechanism =>] MECHANISM]);
5758 -- EXTERNAL_SYMBOL ::=
5760 -- | static_string_EXPRESSION
5762 -- PARAMETER_TYPES ::=
5764 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5766 -- TYPE_DESIGNATOR ::=
5768 -- | subtype_Name ' Access
5772 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5774 -- MECHANISM_ASSOCIATION ::=
5775 -- [formal_parameter_NAME =>] MECHANISM_NAME
5777 -- MECHANISM_NAME ::=
5780 -- | Descriptor [([Class =>] CLASS_NAME)]
5782 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5784 when Pragma_Export_Procedure => Export_Procedure : declare
5785 Args : Args_List (1 .. 4);
5786 Names : constant Name_List (1 .. 4) := (
5789 Name_Parameter_Types,
5792 Internal : Node_Id renames Args (1);
5793 External : Node_Id renames Args (2);
5794 Parameter_Types : Node_Id renames Args (3);
5795 Mechanism : Node_Id renames Args (4);
5799 Gather_Associations (Names, Args);
5800 Process_Extended_Import_Export_Subprogram_Pragma (
5801 Arg_Internal => Internal,
5802 Arg_External => External,
5803 Arg_Parameter_Types => Parameter_Types,
5804 Arg_Mechanism => Mechanism);
5805 end Export_Procedure;
5811 -- pragma Export_Value (
5812 -- [Value =>] static_integer_EXPRESSION,
5813 -- [Link_Name =>] static_string_EXPRESSION);
5815 when Pragma_Export_Value =>
5817 Check_Arg_Count (2);
5819 Check_Optional_Identifier (Arg1, Name_Value);
5820 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
5822 Check_Optional_Identifier (Arg2, Name_Link_Name);
5823 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
5825 -----------------------------
5826 -- Export_Valued_Procedure --
5827 -----------------------------
5829 -- pragma Export_Valued_Procedure (
5830 -- [Internal =>] LOCAL_NAME,
5831 -- [, [External =>] EXTERNAL_SYMBOL,]
5832 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5833 -- [, [Mechanism =>] MECHANISM]);
5835 -- EXTERNAL_SYMBOL ::=
5837 -- | static_string_EXPRESSION
5839 -- PARAMETER_TYPES ::=
5841 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5843 -- TYPE_DESIGNATOR ::=
5845 -- | subtype_Name ' Access
5849 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5851 -- MECHANISM_ASSOCIATION ::=
5852 -- [formal_parameter_NAME =>] MECHANISM_NAME
5854 -- MECHANISM_NAME ::=
5857 -- | Descriptor [([Class =>] CLASS_NAME)]
5859 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5861 when Pragma_Export_Valued_Procedure =>
5862 Export_Valued_Procedure : declare
5863 Args : Args_List (1 .. 4);
5864 Names : constant Name_List (1 .. 4) := (
5867 Name_Parameter_Types,
5870 Internal : Node_Id renames Args (1);
5871 External : Node_Id renames Args (2);
5872 Parameter_Types : Node_Id renames Args (3);
5873 Mechanism : Node_Id renames Args (4);
5877 Gather_Associations (Names, Args);
5878 Process_Extended_Import_Export_Subprogram_Pragma (
5879 Arg_Internal => Internal,
5880 Arg_External => External,
5881 Arg_Parameter_Types => Parameter_Types,
5882 Arg_Mechanism => Mechanism);
5883 end Export_Valued_Procedure;
5889 -- pragma Extend_System ([Name =>] Identifier);
5891 when Pragma_Extend_System => Extend_System : declare
5894 Check_Valid_Configuration_Pragma;
5895 Check_Arg_Count (1);
5896 Check_Optional_Identifier (Arg1, Name_Name);
5897 Check_Arg_Is_Identifier (Arg1);
5899 Get_Name_String (Chars (Expression (Arg1)));
5902 and then Name_Buffer (1 .. 4) = "aux_"
5904 if Present (System_Extend_Pragma_Arg) then
5905 if Chars (Expression (Arg1)) =
5906 Chars (Expression (System_Extend_Pragma_Arg))
5910 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
5911 Error_Pragma ("pragma% conflicts with that at#");
5915 System_Extend_Pragma_Arg := Arg1;
5917 if not GNAT_Mode then
5918 System_Extend_Unit := Arg1;
5922 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
5926 ------------------------
5927 -- Extensions_Allowed --
5928 ------------------------
5930 -- pragma Extensions_Allowed (ON | OFF);
5932 when Pragma_Extensions_Allowed =>
5934 Check_Arg_Count (1);
5935 Check_No_Identifiers;
5936 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5937 Extensions_Allowed := (Chars (Expression (Arg1)) = Name_On);
5943 -- pragma External (
5944 -- [ Convention =>] convention_IDENTIFIER,
5945 -- [ Entity =>] local_NAME
5946 -- [, [External_Name =>] static_string_EXPRESSION ]
5947 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5949 when Pragma_External => External : declare
5955 Check_At_Least_N_Arguments (2);
5956 Check_At_Most_N_Arguments (4);
5957 Process_Convention (C, Def_Id);
5958 Note_Possible_Modification (Expression (Arg2));
5959 Process_Interface_Name (Def_Id, Arg3, Arg4);
5960 Set_Exported (Def_Id, Arg2);
5963 --------------------------
5964 -- External_Name_Casing --
5965 --------------------------
5967 -- pragma External_Name_Casing (
5968 -- UPPERCASE | LOWERCASE
5969 -- [, AS_IS | UPPERCASE | LOWERCASE]);
5971 when Pragma_External_Name_Casing =>
5973 External_Name_Casing : declare
5976 Check_No_Identifiers;
5978 if Arg_Count = 2 then
5980 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
5982 case Chars (Get_Pragma_Arg (Arg2)) is
5984 Opt.External_Name_Exp_Casing := As_Is;
5986 when Name_Uppercase =>
5987 Opt.External_Name_Exp_Casing := Uppercase;
5989 when Name_Lowercase =>
5990 Opt.External_Name_Exp_Casing := Lowercase;
5997 Check_Arg_Count (1);
6000 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6002 case Chars (Get_Pragma_Arg (Arg1)) is
6003 when Name_Uppercase =>
6004 Opt.External_Name_Imp_Casing := Uppercase;
6006 when Name_Lowercase =>
6007 Opt.External_Name_Imp_Casing := Lowercase;
6012 end External_Name_Casing;
6014 ---------------------------
6015 -- Finalize_Storage_Only --
6016 ---------------------------
6018 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6020 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6021 Assoc : constant Node_Id := Arg1;
6022 Type_Id : constant Node_Id := Expression (Assoc);
6026 Check_No_Identifiers;
6027 Check_Arg_Count (1);
6028 Check_Arg_Is_Local_Name (Arg1);
6030 Find_Type (Type_Id);
6031 Typ := Entity (Type_Id);
6034 or else Rep_Item_Too_Early (Typ, N)
6038 Typ := Underlying_Type (Typ);
6041 if not Is_Controlled (Typ) then
6042 Error_Pragma ("pragma% must specify controlled type");
6045 Check_First_Subtype (Arg1);
6047 if Finalize_Storage_Only (Typ) then
6048 Error_Pragma ("duplicate pragma%, only one allowed");
6050 elsif not Rep_Item_Too_Late (Typ, N) then
6051 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6053 end Finalize_Storage;
6055 --------------------------
6056 -- Float_Representation --
6057 --------------------------
6059 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6061 when Pragma_Float_Representation => Float_Representation : declare
6069 if Arg_Count = 1 then
6070 Check_Valid_Configuration_Pragma;
6072 Check_Arg_Count (2);
6073 Check_Optional_Identifier (Arg2, Name_Entity);
6074 Check_Arg_Is_Local_Name (Arg2);
6077 Check_No_Identifier (Arg1);
6078 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6080 if not OpenVMS_On_Target then
6081 if Chars (Expression (Arg1)) = Name_VAX_Float then
6083 ("?pragma% ignored (applies only to Open'V'M'S)");
6089 -- One argument case
6091 if Arg_Count = 1 then
6093 if Chars (Expression (Arg1)) = Name_VAX_Float then
6095 if Opt.Float_Format = 'I' then
6096 Error_Pragma ("'I'E'E'E format previously specified");
6099 Opt.Float_Format := 'V';
6102 if Opt.Float_Format = 'V' then
6103 Error_Pragma ("'V'A'X format previously specified");
6106 Opt.Float_Format := 'I';
6109 Set_Standard_Fpt_Formats;
6111 -- Two argument case
6114 Argx := Get_Pragma_Arg (Arg2);
6116 if not Is_Entity_Name (Argx)
6117 or else not Is_Floating_Point_Type (Entity (Argx))
6120 ("second argument of% pragma must be floating-point type",
6124 Ent := Entity (Argx);
6125 Digs := UI_To_Int (Digits_Value (Ent));
6127 -- Two arguments, VAX_Float case
6129 if Chars (Expression (Arg1)) = Name_VAX_Float then
6132 when 6 => Set_F_Float (Ent);
6133 when 9 => Set_D_Float (Ent);
6134 when 15 => Set_G_Float (Ent);
6138 ("wrong digits value, must be 6,9 or 15", Arg2);
6141 -- Two arguments, IEEE_Float case
6145 when 6 => Set_IEEE_Short (Ent);
6146 when 15 => Set_IEEE_Long (Ent);
6150 ("wrong digits value, must be 6 or 15", Arg2);
6154 end Float_Representation;
6160 -- pragma Ident (static_string_EXPRESSION)
6162 -- Note: pragma Comment shares this processing. Pragma Comment
6163 -- is identical to Ident, except that the restriction of the
6164 -- argument to 31 characters and the placement restrictions
6165 -- are not enforced for pragma Comment.
6167 when Pragma_Ident | Pragma_Comment => Ident : declare
6172 Check_Arg_Count (1);
6173 Check_No_Identifiers;
6174 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6176 -- For pragma Ident, preserve DEC compatibility by requiring
6177 -- the pragma to appear in a declarative part or package spec.
6179 if Prag_Id = Pragma_Ident then
6180 Check_Is_In_Decl_Part_Or_Package_Spec;
6183 Str := Expr_Value_S (Expression (Arg1));
6190 GP := Parent (Parent (N));
6192 if Nkind (GP) = N_Package_Declaration
6194 Nkind (GP) = N_Generic_Package_Declaration
6199 -- If we have a compilation unit, then record the ident
6200 -- value, checking for improper duplication.
6202 if Nkind (GP) = N_Compilation_Unit then
6203 CS := Ident_String (Current_Sem_Unit);
6205 if Present (CS) then
6207 -- For Ident, we do not permit multiple instances
6209 if Prag_Id = Pragma_Ident then
6210 Error_Pragma ("duplicate% pragma not permitted");
6212 -- For Comment, we concatenate the string, unless we
6213 -- want to preserve the tree structure for ASIS.
6215 elsif not ASIS_Mode then
6216 Start_String (Strval (CS));
6217 Store_String_Char (' ');
6218 Store_String_Chars (Strval (Str));
6219 Set_Strval (CS, End_String);
6223 -- In VMS, the effect of IDENT is achieved by passing
6224 -- IDENTIFICATION=name as a --for-linker switch.
6226 if OpenVMS_On_Target then
6229 ("--for-linker=IDENTIFICATION=");
6230 String_To_Name_Buffer (Strval (Str));
6231 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6233 -- Only the last processed IDENT is saved. The main
6234 -- purpose is so an IDENT associated with a main
6235 -- procedure will be used in preference to an IDENT
6236 -- associated with a with'd package.
6238 Replace_Linker_Option_String
6239 (End_String, "--for-linker=IDENTIFICATION=");
6242 Set_Ident_String (Current_Sem_Unit, Str);
6245 -- For subunits, we just ignore the Ident, since in GNAT
6246 -- these are not separate object files, and hence not
6247 -- separate units in the unit table.
6249 elsif Nkind (GP) = N_Subunit then
6252 -- Otherwise we have a misplaced pragma Ident, but we ignore
6253 -- this if we are in an instantiation, since it comes from
6254 -- a generic, and has no relevance to the instantiation.
6256 elsif Prag_Id = Pragma_Ident then
6257 if Instantiation_Location (Loc) = No_Location then
6258 Error_Pragma ("pragma% only allowed at outer level");
6269 -- [ Convention =>] convention_IDENTIFIER,
6270 -- [ Entity =>] local_NAME
6271 -- [, [External_Name =>] static_string_EXPRESSION ]
6272 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6274 when Pragma_Import =>
6275 Check_Ada_83_Warning;
6276 Check_At_Least_N_Arguments (2);
6277 Check_At_Most_N_Arguments (4);
6278 Process_Import_Or_Interface;
6280 ----------------------
6281 -- Import_Exception --
6282 ----------------------
6284 -- pragma Import_Exception (
6285 -- [Internal =>] LOCAL_NAME,
6286 -- [, [External =>] EXTERNAL_SYMBOL,]
6287 -- [, [Form =>] Ada | VMS]
6288 -- [, [Code =>] static_integer_EXPRESSION]);
6290 when Pragma_Import_Exception => Import_Exception : declare
6291 Args : Args_List (1 .. 4);
6292 Names : constant Name_List (1 .. 4) := (
6298 Internal : Node_Id renames Args (1);
6299 External : Node_Id renames Args (2);
6300 Form : Node_Id renames Args (3);
6301 Code : Node_Id renames Args (4);
6304 Gather_Associations (Names, Args);
6306 if Present (External) and then Present (Code) then
6308 ("cannot give both External and Code options for pragma%");
6311 Process_Extended_Import_Export_Exception_Pragma (
6312 Arg_Internal => Internal,
6313 Arg_External => External,
6317 if not Is_VMS_Exception (Entity (Internal)) then
6318 Set_Imported (Entity (Internal));
6320 end Import_Exception;
6322 ---------------------
6323 -- Import_Function --
6324 ---------------------
6326 -- pragma Import_Function (
6327 -- [Internal =>] LOCAL_NAME,
6328 -- [, [External =>] EXTERNAL_SYMBOL]
6329 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6330 -- [, [Result_Type =>] SUBTYPE_MARK]
6331 -- [, [Mechanism =>] MECHANISM]
6332 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6333 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6335 -- EXTERNAL_SYMBOL ::=
6337 -- | static_string_EXPRESSION
6339 -- PARAMETER_TYPES ::=
6341 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6343 -- TYPE_DESIGNATOR ::=
6345 -- | subtype_Name ' Access
6349 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6351 -- MECHANISM_ASSOCIATION ::=
6352 -- [formal_parameter_NAME =>] MECHANISM_NAME
6354 -- MECHANISM_NAME ::=
6357 -- | Descriptor [([Class =>] CLASS_NAME)]
6359 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6361 when Pragma_Import_Function => Import_Function : declare
6362 Args : Args_List (1 .. 7);
6363 Names : constant Name_List (1 .. 7) := (
6366 Name_Parameter_Types,
6369 Name_Result_Mechanism,
6370 Name_First_Optional_Parameter);
6372 Internal : Node_Id renames Args (1);
6373 External : Node_Id renames Args (2);
6374 Parameter_Types : Node_Id renames Args (3);
6375 Result_Type : Node_Id renames Args (4);
6376 Mechanism : Node_Id renames Args (5);
6377 Result_Mechanism : Node_Id renames Args (6);
6378 First_Optional_Parameter : Node_Id renames Args (7);
6382 Gather_Associations (Names, Args);
6383 Process_Extended_Import_Export_Subprogram_Pragma (
6384 Arg_Internal => Internal,
6385 Arg_External => External,
6386 Arg_Parameter_Types => Parameter_Types,
6387 Arg_Result_Type => Result_Type,
6388 Arg_Mechanism => Mechanism,
6389 Arg_Result_Mechanism => Result_Mechanism,
6390 Arg_First_Optional_Parameter => First_Optional_Parameter);
6391 end Import_Function;
6397 -- pragma Import_Object (
6398 -- [Internal =>] LOCAL_NAME,
6399 -- [, [External =>] EXTERNAL_SYMBOL]
6400 -- [, [Size =>] EXTERNAL_SYMBOL]);
6402 -- EXTERNAL_SYMBOL ::=
6404 -- | static_string_EXPRESSION
6406 when Pragma_Import_Object => Import_Object : declare
6407 Args : Args_List (1 .. 3);
6408 Names : constant Name_List (1 .. 3) := (
6413 Internal : Node_Id renames Args (1);
6414 External : Node_Id renames Args (2);
6415 Size : Node_Id renames Args (3);
6419 Gather_Associations (Names, Args);
6420 Process_Extended_Import_Export_Object_Pragma (
6421 Arg_Internal => Internal,
6422 Arg_External => External,
6426 ----------------------
6427 -- Import_Procedure --
6428 ----------------------
6430 -- pragma Import_Procedure (
6431 -- [Internal =>] LOCAL_NAME,
6432 -- [, [External =>] EXTERNAL_SYMBOL]
6433 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6434 -- [, [Mechanism =>] MECHANISM]
6435 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6437 -- EXTERNAL_SYMBOL ::=
6439 -- | static_string_EXPRESSION
6441 -- PARAMETER_TYPES ::=
6443 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6445 -- TYPE_DESIGNATOR ::=
6447 -- | subtype_Name ' Access
6451 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6453 -- MECHANISM_ASSOCIATION ::=
6454 -- [formal_parameter_NAME =>] MECHANISM_NAME
6456 -- MECHANISM_NAME ::=
6459 -- | Descriptor [([Class =>] CLASS_NAME)]
6461 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6463 when Pragma_Import_Procedure => Import_Procedure : declare
6464 Args : Args_List (1 .. 5);
6465 Names : constant Name_List (1 .. 5) := (
6468 Name_Parameter_Types,
6470 Name_First_Optional_Parameter);
6472 Internal : Node_Id renames Args (1);
6473 External : Node_Id renames Args (2);
6474 Parameter_Types : Node_Id renames Args (3);
6475 Mechanism : Node_Id renames Args (4);
6476 First_Optional_Parameter : Node_Id renames Args (5);
6480 Gather_Associations (Names, Args);
6481 Process_Extended_Import_Export_Subprogram_Pragma (
6482 Arg_Internal => Internal,
6483 Arg_External => External,
6484 Arg_Parameter_Types => Parameter_Types,
6485 Arg_Mechanism => Mechanism,
6486 Arg_First_Optional_Parameter => First_Optional_Parameter);
6487 end Import_Procedure;
6489 -----------------------------
6490 -- Import_Valued_Procedure --
6491 -----------------------------
6493 -- pragma Import_Valued_Procedure (
6494 -- [Internal =>] LOCAL_NAME,
6495 -- [, [External =>] EXTERNAL_SYMBOL]
6496 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6497 -- [, [Mechanism =>] MECHANISM]
6498 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6500 -- EXTERNAL_SYMBOL ::=
6502 -- | static_string_EXPRESSION
6504 -- PARAMETER_TYPES ::=
6506 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6508 -- TYPE_DESIGNATOR ::=
6510 -- | subtype_Name ' Access
6514 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6516 -- MECHANISM_ASSOCIATION ::=
6517 -- [formal_parameter_NAME =>] MECHANISM_NAME
6519 -- MECHANISM_NAME ::=
6522 -- | Descriptor [([Class =>] CLASS_NAME)]
6524 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6526 when Pragma_Import_Valued_Procedure =>
6527 Import_Valued_Procedure : declare
6528 Args : Args_List (1 .. 5);
6529 Names : constant Name_List (1 .. 5) := (
6532 Name_Parameter_Types,
6534 Name_First_Optional_Parameter);
6536 Internal : Node_Id renames Args (1);
6537 External : Node_Id renames Args (2);
6538 Parameter_Types : Node_Id renames Args (3);
6539 Mechanism : Node_Id renames Args (4);
6540 First_Optional_Parameter : Node_Id renames Args (5);
6544 Gather_Associations (Names, Args);
6545 Process_Extended_Import_Export_Subprogram_Pragma (
6546 Arg_Internal => Internal,
6547 Arg_External => External,
6548 Arg_Parameter_Types => Parameter_Types,
6549 Arg_Mechanism => Mechanism,
6550 Arg_First_Optional_Parameter => First_Optional_Parameter);
6551 end Import_Valued_Procedure;
6553 ------------------------
6554 -- Initialize_Scalars --
6555 ------------------------
6557 -- pragma Initialize_Scalars;
6559 when Pragma_Initialize_Scalars =>
6561 Check_Arg_Count (0);
6562 Check_Valid_Configuration_Pragma;
6563 Check_Restriction (No_Initialize_Scalars, N);
6565 if not Restriction_Active (No_Initialize_Scalars) then
6566 Init_Or_Norm_Scalars := True;
6567 Initialize_Scalars := True;
6574 -- pragma Inline ( NAME {, NAME} );
6576 when Pragma_Inline =>
6578 -- Pragma is active if inlining option is active
6580 if Inline_Active then
6581 Process_Inline (True);
6583 -- Pragma is active in a predefined file in config run time mode
6585 elsif Configurable_Run_Time_Mode
6587 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
6589 Process_Inline (True);
6591 -- Otherwise inlining is not active
6594 Process_Inline (False);
6601 -- pragma Inline_Always ( NAME {, NAME} );
6603 when Pragma_Inline_Always =>
6604 Process_Inline (True);
6606 --------------------
6607 -- Inline_Generic --
6608 --------------------
6610 -- pragma Inline_Generic (NAME {, NAME});
6612 when Pragma_Inline_Generic =>
6613 Process_Generic_List;
6615 ----------------------
6616 -- Inspection_Point --
6617 ----------------------
6619 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6621 when Pragma_Inspection_Point => Inspection_Point : declare
6626 if Arg_Count > 0 then
6629 Exp := Expression (Arg);
6632 if not Is_Entity_Name (Exp)
6633 or else not Is_Object (Entity (Exp))
6635 Error_Pragma_Arg ("object name required", Arg);
6642 end Inspection_Point;
6648 -- pragma Interface (
6649 -- convention_IDENTIFIER,
6652 when Pragma_Interface =>
6654 Check_Arg_Count (2);
6655 Check_No_Identifiers;
6656 Process_Import_Or_Interface;
6658 --------------------
6659 -- Interface_Name --
6660 --------------------
6662 -- pragma Interface_Name (
6663 -- [ Entity =>] local_NAME
6664 -- [,[External_Name =>] static_string_EXPRESSION ]
6665 -- [,[Link_Name =>] static_string_EXPRESSION ]);
6667 when Pragma_Interface_Name => Interface_Name : declare
6675 Check_At_Least_N_Arguments (2);
6676 Check_At_Most_N_Arguments (3);
6677 Id := Expression (Arg1);
6680 if not Is_Entity_Name (Id) then
6682 ("first argument for pragma% must be entity name", Arg1);
6683 elsif Etype (Id) = Any_Type then
6686 Def_Id := Entity (Id);
6689 -- Special DEC-compatible processing for the object case,
6690 -- forces object to be imported.
6692 if Ekind (Def_Id) = E_Variable then
6693 Kill_Size_Check_Code (Def_Id);
6694 Note_Possible_Modification (Id);
6696 -- Initialization is not allowed for imported variable
6698 if Present (Expression (Parent (Def_Id)))
6699 and then Comes_From_Source (Expression (Parent (Def_Id)))
6701 Error_Msg_Sloc := Sloc (Def_Id);
6703 ("no initialization allowed for declaration of& #",
6707 -- For compatibility, support VADS usage of providing both
6708 -- pragmas Interface and Interface_Name to obtain the effect
6709 -- of a single Import pragma.
6711 if Is_Imported (Def_Id)
6712 and then Present (First_Rep_Item (Def_Id))
6713 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6714 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6718 Set_Imported (Def_Id);
6721 Set_Is_Public (Def_Id);
6722 Process_Interface_Name (Def_Id, Arg2, Arg3);
6725 -- Otherwise must be subprogram
6727 elsif not Is_Subprogram (Def_Id) then
6729 ("argument of pragma% is not subprogram", Arg1);
6732 Check_At_Most_N_Arguments (3);
6736 -- Loop through homonyms
6739 Def_Id := Get_Base_Subprogram (Hom_Id);
6741 if Is_Imported (Def_Id) then
6742 Process_Interface_Name (Def_Id, Arg2, Arg3);
6746 Hom_Id := Homonym (Hom_Id);
6748 exit when No (Hom_Id)
6749 or else Scope (Hom_Id) /= Current_Scope;
6754 ("argument of pragma% is not imported subprogram",
6760 -----------------------
6761 -- Interrupt_Handler --
6762 -----------------------
6764 -- pragma Interrupt_Handler (handler_NAME);
6766 when Pragma_Interrupt_Handler =>
6767 Check_Ada_83_Warning;
6768 Check_Arg_Count (1);
6769 Check_No_Identifiers;
6771 if No_Run_Time_Mode then
6772 Error_Msg_CRT ("Interrupt_Handler pragma", N);
6774 Check_Interrupt_Or_Attach_Handler;
6775 Process_Interrupt_Or_Attach_Handler;
6778 ------------------------
6779 -- Interrupt_Priority --
6780 ------------------------
6782 -- pragma Interrupt_Priority [(EXPRESSION)];
6784 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
6785 P : constant Node_Id := Parent (N);
6789 Check_Ada_83_Warning;
6791 if Arg_Count /= 0 then
6792 Arg := Expression (Arg1);
6793 Check_Arg_Count (1);
6794 Check_No_Identifiers;
6796 -- The expression must be analyzed in the special manner
6797 -- described in "Handling of Default and Per-Object
6798 -- Expressions" in sem.ads.
6800 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
6803 if Nkind (P) /= N_Task_Definition
6804 and then Nkind (P) /= N_Protected_Definition
6809 elsif Has_Priority_Pragma (P) then
6810 Error_Pragma ("duplicate pragma% not allowed");
6813 Set_Has_Priority_Pragma (P, True);
6814 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6816 end Interrupt_Priority;
6818 ---------------------
6819 -- Interrupt_State --
6820 ---------------------
6822 -- pragma Interrupt_State (
6823 -- [Name =>] INTERRUPT_ID,
6824 -- [State =>] INTERRUPT_STATE);
6826 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
6827 -- INTERRUPT_STATE => System | Runtime | User
6829 -- Note: if the interrupt id is given as an identifier, then
6830 -- it must be one of the identifiers in Ada.Interrupts.Names.
6831 -- Otherwise it is given as a static integer expression which
6832 -- must be in the range of Ada.Interrupts.Interrupt_ID.
6834 when Pragma_Interrupt_State => Interrupt_State : declare
6836 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
6837 -- This is the entity Ada.Interrupts.Interrupt_ID;
6839 State_Type : Character;
6840 -- Set to 's'/'r'/'u' for System/Runtime/User
6843 -- Index to entry in Interrupt_States table
6846 -- Value of interrupt
6848 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
6849 -- The first argument to the pragma
6851 Int_Ent : Entity_Id;
6852 -- Interrupt entity in Ada.Interrupts.Names
6856 Check_Arg_Count (2);
6858 Check_Optional_Identifier (Arg1, Name_Name);
6859 Check_Optional_Identifier (Arg2, "state");
6860 Check_Arg_Is_Identifier (Arg2);
6862 -- First argument is identifier
6864 if Nkind (Arg1X) = N_Identifier then
6866 -- Search list of names in Ada.Interrupts.Names
6868 Int_Ent := First_Entity (RTE (RE_Names));
6870 if No (Int_Ent) then
6871 Error_Pragma_Arg ("invalid interrupt name", Arg1);
6873 elsif Chars (Int_Ent) = Chars (Arg1X) then
6874 Int_Val := Expr_Value (Constant_Value (Int_Ent));
6878 Next_Entity (Int_Ent);
6881 -- First argument is not an identifier, so it must be a
6882 -- static expression of type Ada.Interrupts.Interrupt_ID.
6885 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6886 Int_Val := Expr_Value (Arg1X);
6888 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
6890 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
6893 ("value not in range of type " &
6894 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
6900 case Chars (Get_Pragma_Arg (Arg2)) is
6901 when Name_Runtime => State_Type := 'r';
6902 when Name_System => State_Type := 's';
6903 when Name_User => State_Type := 'u';
6906 Error_Pragma_Arg ("invalid interrupt state", Arg2);
6909 -- Check if entry is already stored
6911 IST_Num := Interrupt_States.First;
6913 -- If entry not found, add it
6915 if IST_Num > Interrupt_States.Last then
6916 Interrupt_States.Append
6917 ((Interrupt_Number => UI_To_Int (Int_Val),
6918 Interrupt_State => State_Type,
6919 Pragma_Loc => Loc));
6922 -- Case of entry for the same entry
6924 elsif Int_Val = Interrupt_States.Table (IST_Num).
6927 -- If state matches, done, no need to make redundant entry
6930 State_Type = Interrupt_States.Table (IST_Num).
6933 -- Otherwise if state does not match, error
6936 Interrupt_States.Table (IST_Num).Pragma_Loc;
6938 ("state conflicts with that given at #", Arg2);
6942 IST_Num := IST_Num + 1;
6944 end Interrupt_State;
6946 ----------------------
6947 -- Java_Constructor --
6948 ----------------------
6950 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
6952 when Pragma_Java_Constructor => Java_Constructor : declare
6959 Check_Arg_Count (1);
6960 Check_Optional_Identifier (Arg1, Name_Entity);
6961 Check_Arg_Is_Local_Name (Arg1);
6963 Id := Expression (Arg1);
6964 Find_Program_Unit_Name (Id);
6966 -- If we did not find the name, we are done
6968 if Etype (Id) = Any_Type then
6972 Hom_Id := Entity (Id);
6974 -- Loop through homonyms
6977 Def_Id := Get_Base_Subprogram (Hom_Id);
6979 -- The constructor is required to be a function returning
6980 -- an access type whose designated type has convention Java.
6982 if Ekind (Def_Id) = E_Function
6983 and then Ekind (Etype (Def_Id)) in Access_Kind
6986 (Designated_Type (Etype (Def_Id))) = Convention_Java
6989 (Root_Type (Designated_Type (Etype (Def_Id))))
6992 Set_Is_Constructor (Def_Id);
6993 Set_Convention (Def_Id, Convention_Java);
6997 ("pragma% requires function returning a 'Java access type",
7001 Hom_Id := Homonym (Hom_Id);
7003 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7005 end Java_Constructor;
7007 ----------------------
7008 -- Java_Interface --
7009 ----------------------
7011 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7013 when Pragma_Java_Interface => Java_Interface : declare
7019 Check_Arg_Count (1);
7020 Check_Optional_Identifier (Arg1, Name_Entity);
7021 Check_Arg_Is_Local_Name (Arg1);
7023 Arg := Expression (Arg1);
7026 if Etype (Arg) = Any_Type then
7030 if not Is_Entity_Name (Arg)
7031 or else not Is_Type (Entity (Arg))
7033 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7036 Typ := Underlying_Type (Entity (Arg));
7038 -- For now we simply check some of the semantic constraints
7039 -- on the type. This currently leaves out some restrictions
7040 -- on interface types, namely that the parent type must be
7041 -- java.lang.Object.Typ and that all primitives of the type
7042 -- should be declared abstract. ???
7044 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7045 Error_Pragma_Arg ("pragma% requires an abstract "
7046 & "tagged type", Arg1);
7048 elsif not Has_Discriminants (Typ)
7049 or else Ekind (Etype (First_Discriminant (Typ)))
7050 /= E_Anonymous_Access_Type
7052 not Is_Class_Wide_Type
7053 (Designated_Type (Etype (First_Discriminant (Typ))))
7056 ("type must have a class-wide access discriminant", Arg1);
7064 -- pragma Keep_Names ([On => ] local_NAME);
7066 when Pragma_Keep_Names => Keep_Names : declare
7071 Check_Arg_Count (1);
7072 Check_Optional_Identifier (Arg1, Name_On);
7073 Check_Arg_Is_Local_Name (Arg1);
7075 Arg := Expression (Arg1);
7078 if Etype (Arg) = Any_Type then
7082 if not Is_Entity_Name (Arg)
7083 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7086 ("pragma% requires a local enumeration type", Arg1);
7089 Set_Discard_Names (Entity (Arg), False);
7096 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7098 when Pragma_License =>
7100 Check_Arg_Count (1);
7101 Check_No_Identifiers;
7102 Check_Valid_Configuration_Pragma;
7103 Check_Arg_Is_Identifier (Arg1);
7106 Sind : constant Source_File_Index :=
7107 Source_Index (Current_Sem_Unit);
7110 case Chars (Get_Pragma_Arg (Arg1)) is
7112 Set_License (Sind, GPL);
7114 when Name_Modified_GPL =>
7115 Set_License (Sind, Modified_GPL);
7117 when Name_Restricted =>
7118 Set_License (Sind, Restricted);
7120 when Name_Unrestricted =>
7121 Set_License (Sind, Unrestricted);
7124 Error_Pragma_Arg ("invalid license name", Arg1);
7132 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7134 when Pragma_Link_With => Link_With : declare
7140 if Operating_Mode = Generate_Code
7141 and then In_Extended_Main_Source_Unit (N)
7143 Check_At_Least_N_Arguments (1);
7144 Check_No_Identifiers;
7145 Check_Is_In_Decl_Part_Or_Package_Spec;
7146 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7150 while Present (Arg) loop
7151 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7153 -- Store argument, converting sequences of spaces
7154 -- to a single null character (this is one of the
7155 -- differences in processing between Link_With
7156 -- and Linker_Options).
7159 C : constant Char_Code := Get_Char_Code (' ');
7160 S : constant String_Id :=
7161 Strval (Expr_Value_S (Expression (Arg)));
7162 L : constant Nat := String_Length (S);
7165 procedure Skip_Spaces;
7166 -- Advance F past any spaces
7168 procedure Skip_Spaces is
7170 while F <= L and then Get_String_Char (S, F) = C loop
7176 Skip_Spaces; -- skip leading spaces
7178 -- Loop through characters, changing any embedded
7179 -- sequence of spaces to a single null character
7180 -- (this is how Link_With/Linker_Options differ)
7183 if Get_String_Char (S, F) = C then
7186 Store_String_Char (ASCII.NUL);
7189 Store_String_Char (Get_String_Char (S, F));
7197 if Present (Arg) then
7198 Store_String_Char (ASCII.NUL);
7202 Store_Linker_Option_String (End_String);
7210 -- pragma Linker_Alias (
7211 -- [Entity =>] LOCAL_NAME
7212 -- [Alias =>] static_string_EXPRESSION);
7214 when Pragma_Linker_Alias =>
7216 Check_Arg_Count (2);
7217 Check_Optional_Identifier (Arg1, Name_Entity);
7218 Check_Optional_Identifier (Arg2, "alias");
7219 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7220 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7222 -- The only processing required is to link this item on to the
7223 -- list of rep items for the given entity. This is accomplished
7224 -- by the call to Rep_Item_Too_Late (when no error is detected
7225 -- and False is returned).
7227 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7230 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7233 --------------------
7234 -- Linker_Options --
7235 --------------------
7237 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7239 when Pragma_Linker_Options => Linker_Options : declare
7243 Check_Ada_83_Warning;
7244 Check_No_Identifiers;
7245 Check_Arg_Count (1);
7246 Check_Is_In_Decl_Part_Or_Package_Spec;
7248 if Operating_Mode = Generate_Code
7249 and then In_Extended_Main_Source_Unit (N)
7251 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7252 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7255 while Present (Arg) loop
7256 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7257 Store_String_Char (ASCII.NUL);
7259 (Strval (Expr_Value_S (Expression (Arg))));
7263 Store_Linker_Option_String (End_String);
7267 --------------------
7268 -- Linker_Section --
7269 --------------------
7271 -- pragma Linker_Section (
7272 -- [Entity =>] LOCAL_NAME
7273 -- [Section =>] static_string_EXPRESSION);
7275 when Pragma_Linker_Section =>
7277 Check_Arg_Count (2);
7278 Check_Optional_Identifier (Arg1, Name_Entity);
7279 Check_Optional_Identifier (Arg2, Name_Section);
7280 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7281 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7283 -- The only processing required is to link this item on to the
7284 -- list of rep items for the given entity. This is accomplished
7285 -- by the call to Rep_Item_Too_Late (when no error is detected
7286 -- and False is returned).
7288 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7291 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7298 -- pragma List (On | Off)
7300 -- There is nothing to do here, since we did all the processing
7301 -- for this pragma in Par.Prag (so that it works properly even in
7302 -- syntax only mode)
7307 --------------------
7308 -- Locking_Policy --
7309 --------------------
7311 -- pragma Locking_Policy (policy_IDENTIFIER);
7313 when Pragma_Locking_Policy => declare
7317 Check_Ada_83_Warning;
7318 Check_Arg_Count (1);
7319 Check_No_Identifiers;
7320 Check_Arg_Is_Locking_Policy (Arg1);
7321 Check_Valid_Configuration_Pragma;
7322 Get_Name_String (Chars (Expression (Arg1)));
7323 LP := Fold_Upper (Name_Buffer (1));
7325 if Locking_Policy /= ' '
7326 and then Locking_Policy /= LP
7328 Error_Msg_Sloc := Locking_Policy_Sloc;
7329 Error_Pragma ("locking policy incompatible with policy#");
7331 -- Set new policy, but always preserve System_Location since
7332 -- we like the error message with the run time name.
7335 Locking_Policy := LP;
7337 if Locking_Policy_Sloc /= System_Location then
7338 Locking_Policy_Sloc := Loc;
7347 -- pragma Long_Float (D_Float | G_Float);
7349 when Pragma_Long_Float =>
7351 Check_Valid_Configuration_Pragma;
7352 Check_Arg_Count (1);
7353 Check_No_Identifier (Arg1);
7354 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7356 if not OpenVMS_On_Target then
7357 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7362 if Chars (Expression (Arg1)) = Name_D_Float then
7363 if Opt.Float_Format_Long = 'G' then
7364 Error_Pragma ("G_Float previously specified");
7367 Opt.Float_Format_Long := 'D';
7369 -- G_Float case (this is the default, does not need overriding)
7372 if Opt.Float_Format_Long = 'D' then
7373 Error_Pragma ("D_Float previously specified");
7376 Opt.Float_Format_Long := 'G';
7379 Set_Standard_Fpt_Formats;
7381 -----------------------
7382 -- Machine_Attribute --
7383 -----------------------
7385 -- pragma Machine_Attribute (
7386 -- [Entity =>] LOCAL_NAME,
7387 -- [Attribute_Name =>] static_string_EXPRESSION
7388 -- [,[Info =>] static_string_EXPRESSION] );
7390 when Pragma_Machine_Attribute => Machine_Attribute : declare
7396 if Arg_Count = 3 then
7397 Check_Optional_Identifier (Arg3, "info");
7398 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7400 Check_Arg_Count (2);
7403 Check_Arg_Is_Local_Name (Arg1);
7404 Check_Optional_Identifier (Arg2, "attribute_name");
7405 Check_Optional_Identifier (Arg1, Name_Entity);
7406 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7407 Def_Id := Entity (Expression (Arg1));
7409 if Is_Access_Type (Def_Id) then
7410 Def_Id := Designated_Type (Def_Id);
7413 if Rep_Item_Too_Early (Def_Id, N) then
7417 Def_Id := Underlying_Type (Def_Id);
7419 -- The only processing required is to link this item on to the
7420 -- list of rep items for the given entity. This is accomplished
7421 -- by the call to Rep_Item_Too_Late (when no error is detected
7422 -- and False is returned).
7424 if Rep_Item_Too_Late (Def_Id, N) then
7427 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7429 end Machine_Attribute;
7435 -- pragma Main_Storage
7436 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7438 -- MAIN_STORAGE_OPTION ::=
7439 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7440 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7442 when Pragma_Main => Main : declare
7443 Args : Args_List (1 .. 3);
7444 Names : constant Name_List (1 .. 3) := (
7446 Name_Task_Stack_Size_Default,
7447 Name_Time_Slicing_Enabled);
7453 Gather_Associations (Names, Args);
7455 for J in 1 .. 2 loop
7456 if Present (Args (J)) then
7457 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7461 if Present (Args (3)) then
7462 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7466 while Present (Nod) loop
7467 if Nkind (Nod) = N_Pragma
7468 and then Chars (Nod) = Name_Main
7470 Error_Msg_Name_1 := Chars (N);
7471 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7482 -- pragma Main_Storage
7483 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7485 -- MAIN_STORAGE_OPTION ::=
7486 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7487 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7489 when Pragma_Main_Storage => Main_Storage : declare
7490 Args : Args_List (1 .. 2);
7491 Names : constant Name_List (1 .. 2) := (
7492 Name_Working_Storage,
7499 Gather_Associations (Names, Args);
7501 for J in 1 .. 2 loop
7502 if Present (Args (J)) then
7503 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7507 Check_In_Main_Program;
7510 while Present (Nod) loop
7511 if Nkind (Nod) = N_Pragma
7512 and then Chars (Nod) = Name_Main_Storage
7514 Error_Msg_Name_1 := Chars (N);
7515 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7526 -- pragma Memory_Size (NUMERIC_LITERAL)
7528 when Pragma_Memory_Size =>
7531 -- Memory size is simply ignored
7533 Check_No_Identifiers;
7534 Check_Arg_Count (1);
7535 Check_Arg_Is_Integer_Literal (Arg1);
7541 -- pragma No_Return (procedure_LOCAL_NAME);
7543 when Pragma_No_Return => No_Return : declare
7550 Check_Arg_Count (1);
7551 Check_No_Identifiers;
7552 Check_Arg_Is_Local_Name (Arg1);
7553 Id := Expression (Arg1);
7556 if not Is_Entity_Name (Id) then
7557 Error_Pragma_Arg ("entity name required", Arg1);
7560 if Etype (Id) = Any_Type then
7568 and then Scope (E) = Current_Scope
7570 if Ekind (E) = E_Procedure
7571 or else Ekind (E) = E_Generic_Procedure
7581 Error_Pragma ("no procedures found for pragma%");
7585 ------------------------
7586 -- No_Strict_Aliasing --
7587 ------------------------
7589 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7594 Check_At_Most_N_Arguments (1);
7596 if Arg_Count = 0 then
7597 Check_Valid_Configuration_Pragma;
7598 Opt.No_Strict_Aliasing := True;
7601 Check_Optional_Identifier (Arg2, Name_Entity);
7602 Check_Arg_Is_Local_Name (Arg1);
7603 E_Id := Entity (Expression (Arg1));
7605 if E_Id = Any_Type then
7607 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7608 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7611 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7613 end No_Strict_Alias;
7619 -- pragma Obsolescent [(static_string_EXPRESSION)];
7621 when Pragma_Obsolescent => Obsolescent : declare
7624 Check_At_Most_N_Arguments (1);
7625 Check_No_Identifiers;
7627 if Arg_Count = 1 then
7628 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7632 or else (Nkind (Prev (N))) /= N_Subprogram_Declaration
7635 ("pragma% misplaced, must immediately " &
7636 "follow subprogram spec");
7644 -- pragma No_Run_Time
7646 -- Note: this pragma is retained for backwards compatibiltiy.
7647 -- See body of Rtsfind for full details on its handling.
7649 when Pragma_No_Run_Time =>
7651 Check_Valid_Configuration_Pragma;
7652 Check_Arg_Count (0);
7654 No_Run_Time_Mode := True;
7655 Configurable_Run_Time_Mode := True;
7658 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
7661 Duration_32_Bits_On_Target := True;
7665 Set_Restriction (No_Finalization, N);
7666 Set_Restriction (No_Exception_Handlers, N);
7667 Set_Restriction (Max_Tasks, N, 0);
7668 Set_Restriction (No_Tasking, N);
7670 -----------------------
7671 -- Normalize_Scalars --
7672 -----------------------
7674 -- pragma Normalize_Scalars;
7676 when Pragma_Normalize_Scalars =>
7677 Check_Ada_83_Warning;
7678 Check_Arg_Count (0);
7679 Check_Valid_Configuration_Pragma;
7680 Normalize_Scalars := True;
7681 Init_Or_Norm_Scalars := True;
7687 -- pragma Optimize (Time | Space);
7689 -- The actual check for optimize is done in Gigi. Note that this
7690 -- pragma does not actually change the optimization setting, it
7691 -- simply checks that it is consistent with the pragma.
7693 when Pragma_Optimize =>
7694 Check_No_Identifiers;
7695 Check_Arg_Count (1);
7696 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
7698 -------------------------
7699 -- Optional_Overriding --
7700 -------------------------
7702 -- These pragmas are treated as part of the previous subprogram
7703 -- declaration, and analyzed immediately after it (see sem_ch6,
7704 -- Check_Overriding_Operation). If the pragma has not been analyzed
7705 -- yet, it appears in the wrong place.
7707 when Pragma_Optional_Overriding =>
7708 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7714 when Pragma_Overriding =>
7715 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7721 -- pragma Pack (first_subtype_LOCAL_NAME);
7723 when Pragma_Pack => Pack : declare
7724 Assoc : constant Node_Id := Arg1;
7729 Check_No_Identifiers;
7730 Check_Arg_Count (1);
7731 Check_Arg_Is_Local_Name (Arg1);
7733 Type_Id := Expression (Assoc);
7734 Find_Type (Type_Id);
7735 Typ := Entity (Type_Id);
7738 or else Rep_Item_Too_Early (Typ, N)
7742 Typ := Underlying_Type (Typ);
7745 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
7746 Error_Pragma ("pragma% must specify array or record type");
7749 Check_First_Subtype (Arg1);
7751 if Has_Pragma_Pack (Typ) then
7752 Error_Pragma ("duplicate pragma%, only one allowed");
7754 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
7755 -- but not Has_Non_Standard_Rep, because we don't actually know
7756 -- till freeze time if the array can have packed representation.
7757 -- That's because in the general case we do not know enough about
7758 -- the component type until it in turn is frozen, which certainly
7759 -- happens before the array type is frozen, but not necessarily
7760 -- till that point (i.e. right now it may be unfrozen).
7762 elsif Is_Array_Type (Typ) then
7763 if Has_Aliased_Components (Base_Type (Typ)) then
7765 ("pragma% ignored, cannot pack aliased components?");
7767 elsif Has_Atomic_Components (Typ)
7768 or else Is_Atomic (Component_Type (Typ))
7771 ("?pragma% ignored, cannot pack atomic components");
7773 elsif not Rep_Item_Too_Late (Typ, N) then
7774 Set_Is_Packed (Base_Type (Typ));
7775 Set_Has_Pragma_Pack (Base_Type (Typ));
7776 Set_Has_Non_Standard_Rep (Base_Type (Typ));
7779 -- Record type. For record types, the pack is always effective
7781 else pragma Assert (Is_Record_Type (Typ));
7782 if not Rep_Item_Too_Late (Typ, N) then
7783 Set_Has_Pragma_Pack (Base_Type (Typ));
7784 Set_Is_Packed (Base_Type (Typ));
7785 Set_Has_Non_Standard_Rep (Base_Type (Typ));
7796 -- There is nothing to do here, since we did all the processing
7797 -- for this pragma in Par.Prag (so that it works properly even in
7798 -- syntax only mode)
7807 -- pragma Passive [(PASSIVE_FORM)];
7809 -- PASSIVE_FORM ::= Semaphore | No
7811 when Pragma_Passive =>
7814 if Nkind (Parent (N)) /= N_Task_Definition then
7815 Error_Pragma ("pragma% must be within task definition");
7818 if Arg_Count /= 0 then
7819 Check_Arg_Count (1);
7820 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
7827 -- pragma Polling (ON | OFF);
7829 when Pragma_Polling =>
7831 Check_Arg_Count (1);
7832 Check_No_Identifiers;
7833 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7834 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
7836 ---------------------
7837 -- Persistent_Data --
7838 ---------------------
7840 when Pragma_Persistent_Data => declare
7844 -- Register the pragma as applying to the compilation unit.
7845 -- Individual Persistent_Object pragmas for relevant objects
7846 -- are generated the end of the compilation.
7849 Check_Valid_Configuration_Pragma;
7850 Check_Arg_Count (0);
7851 Ent := Find_Lib_Unit_Name;
7852 Set_Is_Preelaborated (Ent);
7855 -----------------------
7856 -- Persistent_Object --
7857 -----------------------
7859 when Pragma_Persistent_Object => declare
7867 Check_Arg_Count (1);
7868 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7870 if not Is_Entity_Name (Expression (Arg1))
7872 (Ekind (Entity (Expression (Arg1))) /= E_Variable
7873 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
7875 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
7878 Ent := Entity (Expression (Arg1));
7879 Decl := Parent (Ent);
7881 if Nkind (Decl) /= N_Object_Declaration then
7885 -- Placement of the object depends on whether there is
7886 -- an initial value or none. If the No_Initialization flag
7887 -- is set, the initialization has been transformed into
7888 -- assignments, which is disallowed elaboration code.
7890 if No_Initialization (Decl) then
7892 ("initialization for persistent object"
7893 & "must be static expression", Decl);
7897 if No (Expression (Decl)) then
7899 Store_String_Chars ("section ("".persistent.bss"")");
7903 if not Is_OK_Static_Expression (Expression (Decl)) then
7904 Flag_Non_Static_Expr
7905 ("initialization for persistent object"
7906 & "must be static expression!", Expression (Decl));
7911 Store_String_Chars ("section ("".persistent.data"")");
7918 Name_Machine_Attribute,
7920 (Make_Pragma_Argument_Association
7921 (Sloc => Sloc (Arg1),
7922 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
7923 Make_Pragma_Argument_Association
7924 (Sloc => Sloc (Arg1),
7927 (Sloc => Sloc (Arg1),
7930 Insert_After (N, MA);
7932 Set_Has_Gigi_Rep_Item (Ent);
7939 -- pragma Preelaborate [(library_unit_NAME)];
7941 -- Set the flag Is_Preelaborated of program unit name entity
7943 when Pragma_Preelaborate => Preelaborate : declare
7944 Pa : constant Node_Id := Parent (N);
7945 Pk : constant Node_Kind := Nkind (Pa);
7949 Check_Ada_83_Warning;
7950 Check_Valid_Library_Unit_Pragma;
7952 if Nkind (N) = N_Null_Statement then
7956 Ent := Find_Lib_Unit_Name;
7958 -- This filters out pragmas inside generic parent then
7959 -- show up inside instantiation
7962 and then not (Pk = N_Package_Specification
7963 and then Present (Generic_Parent (Pa)))
7965 if not Debug_Flag_U then
7966 Set_Is_Preelaborated (Ent);
7967 Set_Suppress_Elaboration_Warnings (Ent);
7976 -- pragma Priority (EXPRESSION);
7978 when Pragma_Priority => Priority : declare
7979 P : constant Node_Id := Parent (N);
7983 Check_No_Identifiers;
7984 Check_Arg_Count (1);
7988 if Nkind (P) = N_Subprogram_Body then
7989 Check_In_Main_Program;
7991 Arg := Expression (Arg1);
7992 Analyze_And_Resolve (Arg, Standard_Integer);
7996 if not Is_Static_Expression (Arg) then
7997 Flag_Non_Static_Expr
7998 ("main subprogram priority is not static!", Arg);
8001 -- If constraint error, then we already signalled an error
8003 elsif Raises_Constraint_Error (Arg) then
8006 -- Otherwise check in range
8010 Val : constant Uint := Expr_Value (Arg);
8014 or else Val > Expr_Value (Expression
8015 (Parent (RTE (RE_Max_Priority))))
8018 ("main subprogram priority is out of range", Arg1);
8024 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8026 -- Task or Protected, must be of type Integer
8028 elsif Nkind (P) = N_Protected_Definition
8030 Nkind (P) = N_Task_Definition
8032 Arg := Expression (Arg1);
8034 -- The expression must be analyzed in the special manner
8035 -- described in "Handling of Default and Per-Object
8036 -- Expressions" in sem.ads.
8038 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8040 if not Is_Static_Expression (Arg) then
8041 Check_Restriction (Static_Priorities, Arg);
8044 -- Anything else is incorrect
8050 if Has_Priority_Pragma (P) then
8051 Error_Pragma ("duplicate pragma% not allowed");
8053 Set_Has_Priority_Pragma (P, True);
8055 if Nkind (P) = N_Protected_Definition
8057 Nkind (P) = N_Task_Definition
8059 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8060 -- exp_ch9 should use this ???
8069 -- pragma Profile (profile_IDENTIFIER);
8071 -- profile_IDENTIFIER => Ravenscar
8073 when Pragma_Profile =>
8075 Check_Arg_Count (1);
8076 Check_Valid_Configuration_Pragma;
8077 Check_No_Identifiers;
8080 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8082 if Chars (Argx) = Name_Ravenscar then
8083 Set_Ravenscar_Profile (N);
8085 Error_Pragma_Arg ("& is not a valid profile", Argx);
8089 --------------------------
8090 -- Propagate_Exceptions --
8091 --------------------------
8093 -- pragma Propagate_Exceptions;
8095 when Pragma_Propagate_Exceptions =>
8097 Check_Arg_Count (0);
8099 if In_Extended_Main_Source_Unit (N) then
8100 Propagate_Exceptions := True;
8107 -- pragma Psect_Object (
8108 -- [Internal =>] LOCAL_NAME,
8109 -- [, [External =>] EXTERNAL_SYMBOL]
8110 -- [, [Size =>] EXTERNAL_SYMBOL]);
8112 when Pragma_Psect_Object | Pragma_Common_Object =>
8113 Psect_Object : declare
8114 Args : Args_List (1 .. 3);
8115 Names : constant Name_List (1 .. 3) := (
8120 Internal : Node_Id renames Args (1);
8121 External : Node_Id renames Args (2);
8122 Size : Node_Id renames Args (3);
8124 R_Internal : Node_Id;
8125 R_External : Node_Id;
8132 procedure Check_Too_Long (Arg : Node_Id);
8133 -- Posts message if the argument is an identifier with more
8134 -- than 31 characters, or a string literal with more than
8135 -- 31 characters, and we are operating under VMS
8137 --------------------
8138 -- Check_Too_Long --
8139 --------------------
8141 procedure Check_Too_Long (Arg : Node_Id) is
8142 X : constant Node_Id := Original_Node (Arg);
8145 if Nkind (X) /= N_String_Literal
8147 Nkind (X) /= N_Identifier
8150 ("inappropriate argument for pragma %", Arg);
8153 if OpenVMS_On_Target then
8154 if (Nkind (X) = N_String_Literal
8155 and then String_Length (Strval (X)) > 31)
8157 (Nkind (X) = N_Identifier
8158 and then Length_Of_Name (Chars (X)) > 31)
8161 ("argument for pragma % is longer than 31 characters",
8167 -- Start of processing for Common_Object/Psect_Object
8171 Gather_Associations (Names, Args);
8172 Process_Extended_Import_Export_Internal_Arg (Internal);
8174 R_Internal := Relocate_Node (Internal);
8176 Def_Id := Entity (R_Internal);
8178 if Ekind (Def_Id) /= E_Constant
8179 and then Ekind (Def_Id) /= E_Variable
8182 ("pragma% must designate an object", Internal);
8185 Check_Too_Long (R_Internal);
8187 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8189 ("cannot use pragma% for imported/exported object",
8193 if Is_Concurrent_Type (Etype (R_Internal)) then
8195 ("cannot specify pragma % for task/protected object",
8199 if Is_Psected (Def_Id) then
8200 Error_Msg_N ("?duplicate Psect_Object pragma", N);
8202 Set_Is_Psected (Def_Id);
8205 if Ekind (Def_Id) = E_Constant then
8207 ("cannot specify pragma % for a constant", R_Internal);
8210 if Is_Record_Type (Etype (R_Internal)) then
8216 Ent := First_Entity (Etype (R_Internal));
8217 while Present (Ent) loop
8218 Decl := Declaration_Node (Ent);
8220 if Ekind (Ent) = E_Component
8221 and then Nkind (Decl) = N_Component_Declaration
8222 and then Present (Expression (Decl))
8223 and then Warn_On_Export_Import
8226 ("?object for pragma % has defaults", R_Internal);
8236 if Present (Size) then
8237 Check_Too_Long (Size);
8240 -- Make Psect case-insensitive.
8242 if Present (External) then
8243 Check_Too_Long (External);
8245 if Nkind (External) = N_String_Literal then
8246 String_To_Name_Buffer (Strval (External));
8248 Get_Name_String (Chars (External));
8253 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8255 R_External := Make_String_Literal
8256 (Sloc => Sloc (External), Strval => Str);
8258 Get_Name_String (Chars (Internal));
8261 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8263 R_External := Make_String_Literal
8264 (Sloc => Sloc (Internal), Strval => Str);
8267 -- Transform into pragma Linker_Section, add attributes to
8268 -- match what DEC Ada does. Ignore size for now?
8273 Name_Linker_Section,
8275 (Make_Pragma_Argument_Association
8276 (Sloc => Sloc (R_Internal),
8277 Expression => R_Internal),
8278 Make_Pragma_Argument_Association
8279 (Sloc => Sloc (R_External),
8280 Expression => R_External))));
8284 -- Add Machine_Attribute of "overlaid", so the section overlays
8285 -- other sections of the same name.
8288 Store_String_Chars ("overlaid");
8294 Name_Machine_Attribute,
8296 (Make_Pragma_Argument_Association
8297 (Sloc => Sloc (R_Internal),
8298 Expression => R_Internal),
8299 Make_Pragma_Argument_Association
8300 (Sloc => Sloc (R_External),
8303 (Sloc => Sloc (R_External),
8307 -- Add Machine_Attribute of "global", so the section is visible
8311 Store_String_Chars ("global");
8317 Name_Machine_Attribute,
8319 (Make_Pragma_Argument_Association
8320 (Sloc => Sloc (R_Internal),
8321 Expression => R_Internal),
8323 Make_Pragma_Argument_Association
8324 (Sloc => Sloc (R_External),
8327 (Sloc => Sloc (R_External),
8331 -- Add Machine_Attribute of "initialize", so the section is
8335 Store_String_Chars ("initialize");
8341 Name_Machine_Attribute,
8343 (Make_Pragma_Argument_Association
8344 (Sloc => Sloc (R_Internal),
8345 Expression => R_Internal),
8347 Make_Pragma_Argument_Association
8348 (Sloc => Sloc (R_External),
8351 (Sloc => Sloc (R_External),
8360 -- pragma Pure [(library_unit_NAME)];
8362 when Pragma_Pure => Pure : declare
8365 Check_Ada_83_Warning;
8366 Check_Valid_Library_Unit_Pragma;
8368 if Nkind (N) = N_Null_Statement then
8372 Ent := Find_Lib_Unit_Name;
8374 Set_Suppress_Elaboration_Warnings (Ent);
8381 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8383 when Pragma_Pure_Function => Pure_Function : declare
8387 Effective : Boolean := False;
8391 Check_Arg_Count (1);
8392 Check_Optional_Identifier (Arg1, Name_Entity);
8393 Check_Arg_Is_Local_Name (Arg1);
8394 E_Id := Expression (Arg1);
8396 if Error_Posted (E_Id) then
8400 -- Loop through homonyms (overloadings) of referenced entity
8406 Def_Id := Get_Base_Subprogram (E);
8408 if Ekind (Def_Id) /= E_Function
8409 and then Ekind (Def_Id) /= E_Generic_Function
8410 and then Ekind (Def_Id) /= E_Operator
8413 ("pragma% requires a function name", Arg1);
8416 Set_Is_Pure (Def_Id);
8418 if not Has_Pragma_Pure_Function (Def_Id) then
8419 Set_Has_Pragma_Pure_Function (Def_Id);
8424 exit when No (E) or else Scope (E) /= Current_Scope;
8428 and then Warn_On_Redundant_Constructs
8430 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8436 --------------------
8437 -- Queuing_Policy --
8438 --------------------
8440 -- pragma Queuing_Policy (policy_IDENTIFIER);
8442 when Pragma_Queuing_Policy => declare
8446 Check_Ada_83_Warning;
8447 Check_Arg_Count (1);
8448 Check_No_Identifiers;
8449 Check_Arg_Is_Queuing_Policy (Arg1);
8450 Check_Valid_Configuration_Pragma;
8451 Get_Name_String (Chars (Expression (Arg1)));
8452 QP := Fold_Upper (Name_Buffer (1));
8454 if Queuing_Policy /= ' '
8455 and then Queuing_Policy /= QP
8457 Error_Msg_Sloc := Queuing_Policy_Sloc;
8458 Error_Pragma ("queuing policy incompatible with policy#");
8460 -- Set new policy, but always preserve System_Location since
8461 -- we like the error message with the run time name.
8464 Queuing_Policy := QP;
8466 if Queuing_Policy_Sloc /= System_Location then
8467 Queuing_Policy_Sloc := Loc;
8472 ---------------------------
8473 -- Remote_Call_Interface --
8474 ---------------------------
8476 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8478 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8479 Cunit_Node : Node_Id;
8480 Cunit_Ent : Entity_Id;
8484 Check_Ada_83_Warning;
8485 Check_Valid_Library_Unit_Pragma;
8487 if Nkind (N) = N_Null_Statement then
8491 Cunit_Node := Cunit (Current_Sem_Unit);
8492 K := Nkind (Unit (Cunit_Node));
8493 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8495 if K = N_Package_Declaration
8496 or else K = N_Generic_Package_Declaration
8497 or else K = N_Subprogram_Declaration
8498 or else K = N_Generic_Subprogram_Declaration
8499 or else (K = N_Subprogram_Body
8500 and then Acts_As_Spec (Unit (Cunit_Node)))
8505 "pragma% must apply to package or subprogram declaration");
8508 Set_Is_Remote_Call_Interface (Cunit_Ent);
8509 end Remote_Call_Interface;
8515 -- pragma Remote_Types [(library_unit_NAME)];
8517 when Pragma_Remote_Types => Remote_Types : declare
8518 Cunit_Node : Node_Id;
8519 Cunit_Ent : Entity_Id;
8522 Check_Ada_83_Warning;
8523 Check_Valid_Library_Unit_Pragma;
8525 if Nkind (N) = N_Null_Statement then
8529 Cunit_Node := Cunit (Current_Sem_Unit);
8530 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8532 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8534 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8537 "pragma% can only apply to a package declaration");
8540 Set_Is_Remote_Types (Cunit_Ent);
8547 -- pragma Ravenscar;
8549 when Pragma_Ravenscar =>
8551 Check_Arg_Count (0);
8552 Check_Valid_Configuration_Pragma;
8553 Set_Ravenscar_Profile (N);
8555 -------------------------
8556 -- Restricted_Run_Time --
8557 -------------------------
8559 -- pragma Restricted_Run_Time;
8561 when Pragma_Restricted_Run_Time =>
8563 Check_Arg_Count (0);
8564 Check_Valid_Configuration_Pragma;
8565 Set_Restricted_Profile (N);
8571 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8574 -- restriction_IDENTIFIER
8575 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8577 when Pragma_Restrictions =>
8578 Process_Restrictions_Or_Restriction_Warnings;
8580 --------------------------
8581 -- Restriction_Warnings --
8582 --------------------------
8584 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8587 -- restriction_IDENTIFIER
8588 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8590 when Pragma_Restriction_Warnings =>
8591 Process_Restrictions_Or_Restriction_Warnings;
8597 -- pragma Reviewable;
8599 when Pragma_Reviewable =>
8600 Check_Ada_83_Warning;
8601 Check_Arg_Count (0);
8607 -- pragma Share_Generic (NAME {, NAME});
8609 when Pragma_Share_Generic =>
8611 Process_Generic_List;
8617 -- pragma Shared (LOCAL_NAME);
8619 when Pragma_Shared =>
8621 Process_Atomic_Shared_Volatile;
8623 --------------------
8624 -- Shared_Passive --
8625 --------------------
8627 -- pragma Shared_Passive [(library_unit_NAME)];
8629 -- Set the flag Is_Shared_Passive of program unit name entity
8631 when Pragma_Shared_Passive => Shared_Passive : declare
8632 Cunit_Node : Node_Id;
8633 Cunit_Ent : Entity_Id;
8636 Check_Ada_83_Warning;
8637 Check_Valid_Library_Unit_Pragma;
8639 if Nkind (N) = N_Null_Statement then
8643 Cunit_Node := Cunit (Current_Sem_Unit);
8644 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8646 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8648 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8651 "pragma% can only apply to a package declaration");
8654 Set_Is_Shared_Passive (Cunit_Ent);
8657 ----------------------
8658 -- Source_File_Name --
8659 ----------------------
8661 -- There are five forms for this pragma:
8663 -- pragma Source_File_Name (
8664 -- [UNIT_NAME =>] unit_NAME,
8665 -- BODY_FILE_NAME => STRING_LITERAL
8666 -- [, [INDEX =>] INTEGER_LITERAL]);
8668 -- pragma Source_File_Name (
8669 -- [UNIT_NAME =>] unit_NAME,
8670 -- SPEC_FILE_NAME => STRING_LITERAL
8671 -- [, [INDEX =>] INTEGER_LITERAL]);
8673 -- pragma Source_File_Name (
8674 -- BODY_FILE_NAME => STRING_LITERAL
8675 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8676 -- [, CASING => CASING_SPEC]);
8678 -- pragma Source_File_Name (
8679 -- SPEC_FILE_NAME => STRING_LITERAL
8680 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8681 -- [, CASING => CASING_SPEC]);
8683 -- pragma Source_File_Name (
8684 -- SUBUNIT_FILE_NAME => STRING_LITERAL
8685 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8686 -- [, CASING => CASING_SPEC]);
8688 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
8690 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
8691 -- Source_File_Name (SFN), however their usage is exclusive:
8692 -- SFN can only be used when no project file is used, while
8693 -- SFNP can only be used when a project file is used.
8695 -- No processing here. Processing was completed during parsing,
8696 -- since we need to have file names set as early as possible.
8697 -- Units are loaded well before semantic processing starts.
8699 -- The only processing we defer to this point is the check
8700 -- for correct placement.
8702 when Pragma_Source_File_Name =>
8704 Check_Valid_Configuration_Pragma;
8706 ------------------------------
8707 -- Source_File_Name_Project --
8708 ------------------------------
8710 -- See Source_File_Name for syntax
8712 -- No processing here. Processing was completed during parsing,
8713 -- since we need to have file names set as early as possible.
8714 -- Units are loaded well before semantic processing starts.
8716 -- The only processing we defer to this point is the check
8717 -- for correct placement.
8719 when Pragma_Source_File_Name_Project =>
8721 Check_Valid_Configuration_Pragma;
8723 -- Check that a pragma Source_File_Name_Project is used only
8724 -- in a configuration pragmas file.
8726 -- Pragmas Source_File_Name_Project should only be generated
8727 -- by the Project Manager in configuration pragmas files.
8729 -- This is really an ugly test. It seems to depend on some
8730 -- accidental and undocumented property. At the very least
8731 -- it needs to be documented, but it would be better to have
8732 -- a clean way of testing if we are in a configuration file???
8734 if Present (Parent (N)) then
8736 ("pragma% can only appear in a configuration pragmas file");
8739 ----------------------
8740 -- Source_Reference --
8741 ----------------------
8743 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
8745 -- Nothing to do, all processing completed in Par.Prag, since we
8746 -- need the information for possible parser messages that are output
8748 when Pragma_Source_Reference =>
8755 -- pragma Storage_Size (EXPRESSION);
8757 when Pragma_Storage_Size => Storage_Size : declare
8758 P : constant Node_Id := Parent (N);
8762 Check_No_Identifiers;
8763 Check_Arg_Count (1);
8765 -- The expression must be analyzed in the special manner
8766 -- described in "Handling of Default Expressions" in sem.ads.
8768 -- Set In_Default_Expression for per-object case ???
8770 Arg := Expression (Arg1);
8771 Analyze_Per_Use_Expression (Arg, Any_Integer);
8773 if not Is_Static_Expression (Arg) then
8774 Check_Restriction (Static_Storage_Size, Arg);
8777 if Nkind (P) /= N_Task_Definition then
8782 if Has_Storage_Size_Pragma (P) then
8783 Error_Pragma ("duplicate pragma% not allowed");
8785 Set_Has_Storage_Size_Pragma (P, True);
8788 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8789 -- ??? exp_ch9 should use this!
8797 -- pragma Storage_Unit (NUMERIC_LITERAL);
8799 -- Only permitted argument is System'Storage_Unit value
8801 when Pragma_Storage_Unit =>
8802 Check_No_Identifiers;
8803 Check_Arg_Count (1);
8804 Check_Arg_Is_Integer_Literal (Arg1);
8806 if Intval (Expression (Arg1)) /=
8807 UI_From_Int (Ttypes.System_Storage_Unit)
8809 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
8811 ("the only allowed argument for pragma% is ^", Arg1);
8814 --------------------
8815 -- Stream_Convert --
8816 --------------------
8818 -- pragma Stream_Convert (
8819 -- [Entity =>] type_LOCAL_NAME,
8820 -- [Read =>] function_NAME,
8821 -- [Write =>] function NAME);
8823 when Pragma_Stream_Convert => Stream_Convert : declare
8825 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
8826 -- Check that the given argument is the name of a local
8827 -- function of one argument that is not overloaded earlier
8828 -- in the current local scope. A check is also made that the
8829 -- argument is a function with one parameter.
8831 --------------------------------------
8832 -- Check_OK_Stream_Convert_Function --
8833 --------------------------------------
8835 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
8839 Check_Arg_Is_Local_Name (Arg);
8840 Ent := Entity (Expression (Arg));
8842 if Has_Homonym (Ent) then
8844 ("argument for pragma% may not be overloaded", Arg);
8847 if Ekind (Ent) /= E_Function
8848 or else No (First_Formal (Ent))
8849 or else Present (Next_Formal (First_Formal (Ent)))
8852 ("argument for pragma% must be" &
8853 " function of one argument", Arg);
8855 end Check_OK_Stream_Convert_Function;
8857 -- Start of procecessing for Stream_Convert
8861 Check_Arg_Count (3);
8862 Check_Optional_Identifier (Arg1, Name_Entity);
8863 Check_Optional_Identifier (Arg2, Name_Read);
8864 Check_Optional_Identifier (Arg3, Name_Write);
8865 Check_Arg_Is_Local_Name (Arg1);
8866 Check_OK_Stream_Convert_Function (Arg2);
8867 Check_OK_Stream_Convert_Function (Arg3);
8870 Typ : constant Entity_Id :=
8871 Underlying_Type (Entity (Expression (Arg1)));
8872 Read : constant Entity_Id := Entity (Expression (Arg2));
8873 Write : constant Entity_Id := Entity (Expression (Arg3));
8876 if Etype (Typ) = Any_Type
8878 Etype (Read) = Any_Type
8880 Etype (Write) = Any_Type
8885 Check_First_Subtype (Arg1);
8887 if Rep_Item_Too_Early (Typ, N)
8889 Rep_Item_Too_Late (Typ, N)
8894 if Underlying_Type (Etype (Read)) /= Typ then
8896 ("incorrect return type for function&", Arg2);
8899 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
8901 ("incorrect parameter type for function&", Arg3);
8904 if Underlying_Type (Etype (First_Formal (Read))) /=
8905 Underlying_Type (Etype (Write))
8908 ("result type of & does not match Read parameter type",
8914 -------------------------
8915 -- Style_Checks (GNAT) --
8916 -------------------------
8918 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
8920 -- This is processed by the parser since some of the style
8921 -- checks take place during source scanning and parsing. This
8922 -- means that we don't need to issue error messages here.
8924 when Pragma_Style_Checks => Style_Checks : declare
8925 A : constant Node_Id := Expression (Arg1);
8931 Check_No_Identifiers;
8933 -- Two argument form
8935 if Arg_Count = 2 then
8936 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8943 E_Id := Expression (Arg2);
8946 if not Is_Entity_Name (E_Id) then
8948 ("second argument of pragma% must be entity name",
8958 Set_Suppress_Style_Checks (E,
8959 (Chars (Expression (Arg1)) = Name_Off));
8960 exit when No (Homonym (E));
8966 -- One argument form
8969 Check_Arg_Count (1);
8971 if Nkind (A) = N_String_Literal then
8975 Slen : constant Natural := Natural (String_Length (S));
8976 Options : String (1 .. Slen);
8982 C := Get_String_Char (S, Int (J));
8983 exit when not In_Character_Range (C);
8984 Options (J) := Get_Character (C);
8987 Set_Style_Check_Options (Options);
8995 elsif Nkind (A) = N_Identifier then
8997 if Chars (A) = Name_All_Checks then
8998 Set_Default_Style_Check_Options;
9000 elsif Chars (A) = Name_On then
9001 Style_Check := True;
9003 elsif Chars (A) = Name_Off then
9004 Style_Check := False;
9015 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9017 when Pragma_Subtitle =>
9019 Check_Arg_Count (1);
9020 Check_Optional_Identifier (Arg1, Name_Subtitle);
9021 Check_Arg_Is_String_Literal (Arg1);
9027 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9029 when Pragma_Suppress =>
9030 Process_Suppress_Unsuppress (True);
9036 -- pragma Suppress_All;
9038 -- The only check made here is that the pragma appears in the
9039 -- proper place, i.e. following a compilation unit. If indeed
9040 -- it appears in this context, then the parser has already
9041 -- inserted an equivalent pragma Suppress (All_Checks) to get
9042 -- the required effect.
9044 when Pragma_Suppress_All =>
9046 Check_Arg_Count (0);
9048 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9049 or else not Is_List_Member (N)
9050 or else List_Containing (N) /= Pragmas_After (Parent (N))
9053 ("misplaced pragma%, must follow compilation unit");
9056 -------------------------
9057 -- Suppress_Debug_Info --
9058 -------------------------
9060 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9062 when Pragma_Suppress_Debug_Info =>
9064 Check_Arg_Count (1);
9065 Check_Arg_Is_Local_Name (Arg1);
9066 Check_Optional_Identifier (Arg1, Name_Entity);
9067 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9069 ----------------------------------
9070 -- Suppress_Exception_Locations --
9071 ----------------------------------
9073 -- pragma Suppress_Exception_Locations;
9075 when Pragma_Suppress_Exception_Locations =>
9077 Check_Arg_Count (0);
9078 Check_Valid_Configuration_Pragma;
9079 Exception_Locations_Suppressed := True;
9081 -----------------------------
9082 -- Suppress_Initialization --
9083 -----------------------------
9085 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9087 when Pragma_Suppress_Initialization => Suppress_Init : declare
9093 Check_Arg_Count (1);
9094 Check_Optional_Identifier (Arg1, Name_Entity);
9095 Check_Arg_Is_Local_Name (Arg1);
9097 E_Id := Expression (Arg1);
9099 if Etype (E_Id) = Any_Type then
9106 if Is_Incomplete_Or_Private_Type (E) then
9107 if No (Full_View (Base_Type (E))) then
9109 ("argument of pragma% cannot be an incomplete type",
9112 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9115 Set_Suppress_Init_Proc (Base_Type (E));
9120 ("pragma% requires argument that is a type name", Arg1);
9128 -- pragma System_Name (DIRECT_NAME);
9130 -- Syntax check: one argument, which must be the identifier GNAT
9131 -- or the identifier GCC, no other identifiers are acceptable.
9133 when Pragma_System_Name =>
9134 Check_No_Identifiers;
9135 Check_Arg_Count (1);
9136 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9138 -----------------------------
9139 -- Task_Dispatching_Policy --
9140 -----------------------------
9142 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9144 when Pragma_Task_Dispatching_Policy => declare
9148 Check_Ada_83_Warning;
9149 Check_Arg_Count (1);
9150 Check_No_Identifiers;
9151 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9152 Check_Valid_Configuration_Pragma;
9153 Get_Name_String (Chars (Expression (Arg1)));
9154 DP := Fold_Upper (Name_Buffer (1));
9156 if Task_Dispatching_Policy /= ' '
9157 and then Task_Dispatching_Policy /= DP
9159 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9161 ("task dispatching policy incompatible with policy#");
9163 -- Set new policy, but always preserve System_Location since
9164 -- we like the error message with the run time name.
9167 Task_Dispatching_Policy := DP;
9169 if Task_Dispatching_Policy_Sloc /= System_Location then
9170 Task_Dispatching_Policy_Sloc := Loc;
9179 -- pragma Task_Info (EXPRESSION);
9181 when Pragma_Task_Info => Task_Info : declare
9182 P : constant Node_Id := Parent (N);
9187 if Nkind (P) /= N_Task_Definition then
9188 Error_Pragma ("pragma% must appear in task definition");
9191 Check_No_Identifiers;
9192 Check_Arg_Count (1);
9194 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9196 if Etype (Expression (Arg1)) = Any_Type then
9200 if Has_Task_Info_Pragma (P) then
9201 Error_Pragma ("duplicate pragma% not allowed");
9203 Set_Has_Task_Info_Pragma (P, True);
9211 -- pragma Task_Name (string_EXPRESSION);
9213 when Pragma_Task_Name => Task_Name : declare
9214 -- pragma Priority (EXPRESSION);
9216 P : constant Node_Id := Parent (N);
9220 Check_No_Identifiers;
9221 Check_Arg_Count (1);
9223 Arg := Expression (Arg1);
9224 Analyze_And_Resolve (Arg, Standard_String);
9226 if Nkind (P) /= N_Task_Definition then
9230 if Has_Task_Name_Pragma (P) then
9231 Error_Pragma ("duplicate pragma% not allowed");
9233 Set_Has_Task_Name_Pragma (P, True);
9234 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9242 -- pragma Task_Storage (
9243 -- [Task_Type =>] LOCAL_NAME,
9244 -- [Top_Guard =>] static_integer_EXPRESSION);
9246 when Pragma_Task_Storage => Task_Storage : declare
9247 Args : Args_List (1 .. 2);
9248 Names : constant Name_List (1 .. 2) := (
9252 Task_Type : Node_Id renames Args (1);
9253 Top_Guard : Node_Id renames Args (2);
9259 Gather_Associations (Names, Args);
9261 if No (Task_Type) then
9263 ("missing task_type argument for pragma%");
9266 Check_Arg_Is_Local_Name (Task_Type);
9268 Ent := Entity (Task_Type);
9270 if not Is_Task_Type (Ent) then
9272 ("argument for pragma% must be task type", Task_Type);
9275 if No (Top_Guard) then
9277 ("pragma% takes two arguments", Task_Type);
9279 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9282 Check_First_Subtype (Task_Type);
9284 if Rep_Item_Too_Late (Ent, N) then
9293 -- pragma Thread_Body
9294 -- ( [Entity =>] LOCAL_NAME
9295 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9297 when Pragma_Thread_Body => Thread_Body : declare
9304 Check_At_Least_N_Arguments (1);
9305 Check_At_Most_N_Arguments (2);
9306 Check_Optional_Identifier (Arg1, Name_Entity);
9307 Check_Arg_Is_Local_Name (Arg1);
9309 Id := Expression (Arg1);
9311 if not Is_Entity_Name (Id)
9312 or else not Is_Subprogram (Entity (Id))
9314 Error_Pragma_Arg ("subprogram name required", Arg1);
9319 -- Go to renamed subprogram if present, since Thread_Body applies
9320 -- to the actual renamed entity, not to the renaming entity.
9322 if Present (Alias (E))
9323 and then Nkind (Parent (Declaration_Node (E))) =
9324 N_Subprogram_Renaming_Declaration
9329 -- Various error checks
9331 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9333 ("pragma% requires separate spec and must come before body");
9335 elsif Rep_Item_Too_Early (E, N)
9337 Rep_Item_Too_Late (E, N)
9341 elsif Is_Thread_Body (E) then
9343 ("only one thread body pragma allowed", Arg1);
9345 elsif Present (Homonym (E))
9346 and then Scope (Homonym (E)) = Current_Scope
9349 ("thread body subprogram must not be overloaded", Arg1);
9352 Set_Is_Thread_Body (E);
9354 -- Deal with secondary stack argument
9356 if Arg_Count = 2 then
9357 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9358 SS := Expression (Arg2);
9359 Analyze_And_Resolve (SS, Any_Integer);
9367 -- pragma Time_Slice (static_duration_EXPRESSION);
9369 when Pragma_Time_Slice => Time_Slice : declare
9375 Check_Arg_Count (1);
9376 Check_No_Identifiers;
9377 Check_In_Main_Program;
9378 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9380 if not Error_Posted (Arg1) then
9382 while Present (Nod) loop
9383 if Nkind (Nod) = N_Pragma
9384 and then Chars (Nod) = Name_Time_Slice
9386 Error_Msg_Name_1 := Chars (N);
9387 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9394 -- Process only if in main unit
9396 if Get_Source_Unit (Loc) = Main_Unit then
9397 Opt.Time_Slice_Set := True;
9398 Val := Expr_Value_R (Expression (Arg1));
9400 if Val <= Ureal_0 then
9401 Opt.Time_Slice_Value := 0;
9403 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9404 Opt.Time_Slice_Value := 1_000_000_000;
9407 Opt.Time_Slice_Value :=
9408 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9417 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9419 -- TITLING_OPTION ::=
9420 -- [Title =>] STRING_LITERAL
9421 -- | [Subtitle =>] STRING_LITERAL
9423 when Pragma_Title => Title : declare
9424 Args : Args_List (1 .. 2);
9425 Names : constant Name_List (1 .. 2) := (
9431 Gather_Associations (Names, Args);
9433 for J in 1 .. 2 loop
9434 if Present (Args (J)) then
9435 Check_Arg_Is_String_Literal (Args (J));
9440 ---------------------
9441 -- Unchecked_Union --
9442 ---------------------
9444 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9446 when Pragma_Unchecked_Union => Unchecked_Union : declare
9447 Assoc : constant Node_Id := Arg1;
9448 Type_Id : constant Node_Id := Expression (Assoc);
9459 Check_No_Identifiers;
9460 Check_Arg_Count (1);
9461 Check_Arg_Is_Local_Name (Arg1);
9463 Find_Type (Type_Id);
9464 Typ := Entity (Type_Id);
9467 or else Rep_Item_Too_Early (Typ, N)
9471 Typ := Underlying_Type (Typ);
9474 if Rep_Item_Too_Late (Typ, N) then
9478 Check_First_Subtype (Arg1);
9480 -- Note remaining cases are references to a type in the current
9481 -- declarative part. If we find an error, we post the error on
9482 -- the relevant type declaration at an appropriate point.
9484 if not Is_Record_Type (Typ) then
9485 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9488 elsif Is_Tagged_Type (Typ) then
9489 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9492 elsif Is_Limited_Type (Typ) then
9494 ("Unchecked_Union must not be limited record type", Typ);
9495 Explain_Limited_Type (Typ, Typ);
9499 if not Has_Discriminants (Typ) then
9501 ("Unchecked_Union must have one discriminant", Typ);
9505 Discr := First_Discriminant (Typ);
9507 if Present (Next_Discriminant (Discr)) then
9509 ("Unchecked_Union must have exactly one discriminant",
9510 Next_Discriminant (Discr));
9514 if No (Discriminant_Default_Value (Discr)) then
9516 ("Unchecked_Union discriminant must have default value",
9520 Tdef := Type_Definition (Declaration_Node (Typ));
9521 Clist := Component_List (Tdef);
9523 if No (Clist) or else No (Variant_Part (Clist)) then
9525 ("Unchecked_Union must have variant part",
9530 Vpart := Variant_Part (Clist);
9532 if Is_Non_Empty_List (Component_Items (Clist)) then
9534 ("components before variant not allowed " &
9535 "in Unchecked_Union",
9536 First (Component_Items (Clist)));
9539 Variant := First (Variants (Vpart));
9540 while Present (Variant) loop
9541 Clist := Component_List (Variant);
9543 if Present (Variant_Part (Clist)) then
9545 ("Unchecked_Union may not have nested variants",
9546 Variant_Part (Clist));
9549 if not Is_Non_Empty_List (Component_Items (Clist)) then
9551 ("Unchecked_Union may not have empty component list",
9556 Comp := First (Component_Items (Clist));
9558 if Nkind (Comp) = N_Component_Declaration then
9560 if Present (Expression (Comp)) then
9562 ("default initialization not allowed " &
9563 "in Unchecked_Union",
9568 Sindic : constant Node_Id :=
9569 Subtype_Indication (Component_Definition (Comp));
9572 if Nkind (Sindic) = N_Subtype_Indication then
9573 Check_Static_Constraint (Constraint (Sindic));
9578 if Present (Next (Comp)) then
9580 ("Unchecked_Union variant can have only one component",
9588 Set_Is_Unchecked_Union (Typ, True);
9589 Set_Convention (Typ, Convention_C);
9591 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9592 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9593 end Unchecked_Union;
9595 ------------------------
9596 -- Unimplemented_Unit --
9597 ------------------------
9599 -- pragma Unimplemented_Unit;
9601 -- Note: this only gives an error if we are generating code,
9602 -- or if we are in a generic library unit (where the pragma
9603 -- appears in the body, not in the spec).
9605 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9606 Cunitent : constant Entity_Id :=
9607 Cunit_Entity (Get_Source_Unit (Loc));
9608 Ent_Kind : constant Entity_Kind :=
9613 Check_Arg_Count (0);
9615 if Operating_Mode = Generate_Code
9616 or else Ent_Kind = E_Generic_Function
9617 or else Ent_Kind = E_Generic_Procedure
9618 or else Ent_Kind = E_Generic_Package
9620 Get_Name_String (Chars (Cunitent));
9621 Set_Casing (Mixed_Case);
9622 Write_Str (Name_Buffer (1 .. Name_Len));
9623 Write_Str (" is not implemented");
9625 raise Unrecoverable_Error;
9627 end Unimplemented_Unit;
9629 --------------------
9630 -- Universal_Data --
9631 --------------------
9633 -- pragma Universal_Data [(library_unit_NAME)];
9635 when Pragma_Universal_Data =>
9638 -- If this is a configuration pragma, then set the universal
9639 -- addressing option, otherwise confirm that the pragma
9640 -- satisfies the requirements of library unit pragma placement
9641 -- and leave it to the GNAAMP back end to detect the pragma
9642 -- (avoids transitive setting of the option due to withed units).
9644 if Is_Configuration_Pragma then
9645 Universal_Addressing_On_AAMP := True;
9647 Check_Valid_Library_Unit_Pragma;
9650 if not AAMP_On_Target then
9651 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9658 -- pragma Unreferenced (local_Name {, local_Name});
9660 when Pragma_Unreferenced => Unreferenced : declare
9663 Arg_Ent : Entity_Id;
9667 Check_At_Least_N_Arguments (1);
9671 while Present (Arg_Node) loop
9672 Check_No_Identifier (Arg_Node);
9674 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9675 -- will in fact generate a reference, so that the entity will
9676 -- have a reference, which will inhibit any warnings about it
9677 -- not being referenced, and also properly show up in the ali
9678 -- file as a reference. But this reference is recorded before
9679 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9680 -- is generated for this reference.
9682 Check_Arg_Is_Local_Name (Arg_Node);
9683 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9685 if Is_Entity_Name (Arg_Expr) then
9686 Arg_Ent := Entity (Arg_Expr);
9688 -- If the entity is overloaded, the pragma applies to the
9689 -- most recent overloading, as documented. In this case,
9690 -- name resolution does not generate a reference, so it
9691 -- must be done here explicitly.
9693 if Is_Overloaded (Arg_Expr) then
9694 Generate_Reference (Arg_Ent, N);
9697 Set_Has_Pragma_Unreferenced (Arg_Ent);
9704 ------------------------------
9705 -- Unreserve_All_Interrupts --
9706 ------------------------------
9708 -- pragma Unreserve_All_Interrupts;
9710 when Pragma_Unreserve_All_Interrupts =>
9712 Check_Arg_Count (0);
9714 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9715 Unreserve_All_Interrupts := True;
9722 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
9724 when Pragma_Unsuppress =>
9726 Process_Suppress_Unsuppress (False);
9732 -- pragma Use_VADS_Size;
9734 when Pragma_Use_VADS_Size =>
9736 Check_Arg_Count (0);
9737 Check_Valid_Configuration_Pragma;
9738 Use_VADS_Size := True;
9740 ---------------------
9741 -- Validity_Checks --
9742 ---------------------
9744 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9746 when Pragma_Validity_Checks => Validity_Checks : declare
9747 A : constant Node_Id := Expression (Arg1);
9753 Check_Arg_Count (1);
9754 Check_No_Identifiers;
9756 if Nkind (A) = N_String_Literal then
9760 Slen : constant Natural := Natural (String_Length (S));
9761 Options : String (1 .. Slen);
9767 C := Get_String_Char (S, Int (J));
9768 exit when not In_Character_Range (C);
9769 Options (J) := Get_Character (C);
9772 Set_Validity_Check_Options (Options);
9780 elsif Nkind (A) = N_Identifier then
9782 if Chars (A) = Name_All_Checks then
9783 Set_Validity_Check_Options ("a");
9785 elsif Chars (A) = Name_On then
9786 Validity_Checks_On := True;
9788 elsif Chars (A) = Name_Off then
9789 Validity_Checks_On := False;
9793 end Validity_Checks;
9799 -- pragma Volatile (LOCAL_NAME);
9801 when Pragma_Volatile =>
9802 Process_Atomic_Shared_Volatile;
9804 -------------------------
9805 -- Volatile_Components --
9806 -------------------------
9808 -- pragma Volatile_Components (array_LOCAL_NAME);
9810 -- Volatile is handled by the same circuit as Atomic_Components
9816 -- pragma Warnings (On | Off, [LOCAL_NAME])
9818 when Pragma_Warnings => Warnings : begin
9820 Check_At_Least_N_Arguments (1);
9821 Check_At_Most_N_Arguments (2);
9822 Check_No_Identifiers;
9824 -- One argument case was processed by parser in Par.Prag
9826 if Arg_Count /= 1 then
9827 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9828 Check_Arg_Count (2);
9835 E_Id := Expression (Arg2);
9838 -- In the expansion of an inlined body, a reference to
9839 -- the formal may be wrapped in a conversion if the actual
9840 -- is a conversion. Retrieve the real entity name.
9842 if (In_Instance_Body
9843 or else In_Inlined_Body)
9844 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
9846 E_Id := Expression (E_Id);
9849 if not Is_Entity_Name (E_Id) then
9851 ("second argument of pragma% must be entity name",
9861 Set_Warnings_Off (E,
9862 (Chars (Expression (Arg1)) = Name_Off));
9864 if Is_Enumeration_Type (E) then
9866 Lit : Entity_Id := First_Literal (E);
9869 while Present (Lit) loop
9870 Set_Warnings_Off (Lit);
9876 exit when No (Homonym (E));
9888 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
9890 when Pragma_Weak_External => Weak_External : declare
9895 Check_Arg_Count (1);
9896 Check_Optional_Identifier (Arg1, Name_Entity);
9897 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9898 Ent := Entity (Expression (Arg1));
9900 if Rep_Item_Too_Early (Ent, N) then
9903 Ent := Underlying_Type (Ent);
9906 -- The only processing required is to link this item on to the
9907 -- list of rep items for the given entity. This is accomplished
9908 -- by the call to Rep_Item_Too_Late (when no error is detected
9909 -- and False is returned).
9911 if Rep_Item_Too_Late (Ent, N) then
9914 Set_Has_Gigi_Rep_Item (Ent);
9918 --------------------
9919 -- Unknown_Pragma --
9920 --------------------
9922 -- Should be impossible, since the case of an unknown pragma is
9923 -- separately processed before the case statement is entered.
9925 when Unknown_Pragma =>
9926 raise Program_Error;
9930 when Pragma_Exit => null;
9933 ---------------------------------
9934 -- Delay_Config_Pragma_Analyze --
9935 ---------------------------------
9937 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
9939 return Chars (N) = Name_Interrupt_State;
9940 end Delay_Config_Pragma_Analyze;
9942 -------------------------
9943 -- Get_Base_Subprogram --
9944 -------------------------
9946 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
9952 -- Follow subprogram renaming chain
9954 while Is_Subprogram (Result)
9956 (Is_Generic_Instance (Result)
9957 or else Nkind (Parent (Declaration_Node (Result))) =
9958 N_Subprogram_Renaming_Declaration)
9959 and then Present (Alias (Result))
9961 Result := Alias (Result);
9965 end Get_Base_Subprogram;
9967 -----------------------------
9968 -- Is_Config_Static_String --
9969 -----------------------------
9971 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
9973 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
9974 -- This is an internal recursive function that is just like the
9975 -- outer function except that it adds the string to the name buffer
9976 -- rather than placing the string in the name buffer.
9978 ------------------------------
9979 -- Add_Config_Static_String --
9980 ------------------------------
9982 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
9989 if Nkind (N) = N_Op_Concat then
9990 if Add_Config_Static_String (Left_Opnd (N)) then
9991 N := Right_Opnd (N);
9997 if Nkind (N) /= N_String_Literal then
9998 Error_Msg_N ("string literal expected for pragma argument", N);
10002 for J in 1 .. String_Length (Strval (N)) loop
10003 C := Get_String_Char (Strval (N), J);
10005 if not In_Character_Range (C) then
10007 ("string literal contains invalid wide character",
10008 Sloc (N) + 1 + Source_Ptr (J));
10012 Add_Char_To_Name_Buffer (Get_Character (C));
10017 end Add_Config_Static_String;
10019 -- Start of prorcessing for Is_Config_Static_String
10024 return Add_Config_Static_String (Arg);
10025 end Is_Config_Static_String;
10027 -----------------------------------------
10028 -- Is_Non_Significant_Pragma_Reference --
10029 -----------------------------------------
10031 -- This function makes use of the following static table which indicates
10032 -- whether a given pragma is significant. A value of -1 in this table
10033 -- indicates that the reference is significant. A value of zero indicates
10034 -- than appearence as any argument is insignificant, a positive value
10035 -- indicates that appearence in that parameter position is significant.
10037 Sig_Flags : constant array (Pragma_Id) of Int :=
10039 (Pragma_AST_Entry => -1,
10040 Pragma_Abort_Defer => -1,
10041 Pragma_Ada_83 => -1,
10042 Pragma_Ada_95 => -1,
10043 Pragma_All_Calls_Remote => -1,
10044 Pragma_Annotate => -1,
10045 Pragma_Assert => -1,
10046 Pragma_Asynchronous => -1,
10047 Pragma_Atomic => 0,
10048 Pragma_Atomic_Components => 0,
10049 Pragma_Attach_Handler => -1,
10050 Pragma_CPP_Class => 0,
10051 Pragma_CPP_Constructor => 0,
10052 Pragma_CPP_Virtual => 0,
10053 Pragma_CPP_Vtable => 0,
10054 Pragma_C_Pass_By_Copy => 0,
10055 Pragma_Comment => 0,
10056 Pragma_Common_Object => -1,
10057 Pragma_Compile_Time_Warning => -1,
10058 Pragma_Complex_Representation => 0,
10059 Pragma_Component_Alignment => -1,
10060 Pragma_Controlled => 0,
10061 Pragma_Convention => 0,
10062 Pragma_Convention_Identifier => 0,
10063 Pragma_Debug => -1,
10064 Pragma_Discard_Names => 0,
10065 Pragma_Elaborate => -1,
10066 Pragma_Elaborate_All => -1,
10067 Pragma_Elaborate_Body => -1,
10068 Pragma_Elaboration_Checks => -1,
10069 Pragma_Eliminate => -1,
10070 Pragma_Explicit_Overriding => -1,
10071 Pragma_Export => -1,
10072 Pragma_Export_Exception => -1,
10073 Pragma_Export_Function => -1,
10074 Pragma_Export_Object => -1,
10075 Pragma_Export_Procedure => -1,
10076 Pragma_Export_Value => -1,
10077 Pragma_Export_Valued_Procedure => -1,
10078 Pragma_Extend_System => -1,
10079 Pragma_Extensions_Allowed => -1,
10080 Pragma_External => -1,
10081 Pragma_External_Name_Casing => -1,
10082 Pragma_Finalize_Storage_Only => 0,
10083 Pragma_Float_Representation => 0,
10084 Pragma_Ident => -1,
10085 Pragma_Import => +2,
10086 Pragma_Import_Exception => 0,
10087 Pragma_Import_Function => 0,
10088 Pragma_Import_Object => 0,
10089 Pragma_Import_Procedure => 0,
10090 Pragma_Import_Valued_Procedure => 0,
10091 Pragma_Initialize_Scalars => -1,
10092 Pragma_Inline => 0,
10093 Pragma_Inline_Always => 0,
10094 Pragma_Inline_Generic => 0,
10095 Pragma_Inspection_Point => -1,
10096 Pragma_Interface => +2,
10097 Pragma_Interface_Name => +2,
10098 Pragma_Interrupt_Handler => -1,
10099 Pragma_Interrupt_Priority => -1,
10100 Pragma_Interrupt_State => -1,
10101 Pragma_Java_Constructor => -1,
10102 Pragma_Java_Interface => -1,
10103 Pragma_Keep_Names => 0,
10104 Pragma_License => -1,
10105 Pragma_Link_With => -1,
10106 Pragma_Linker_Alias => -1,
10107 Pragma_Linker_Options => -1,
10108 Pragma_Linker_Section => -1,
10110 Pragma_Locking_Policy => -1,
10111 Pragma_Long_Float => -1,
10112 Pragma_Machine_Attribute => -1,
10114 Pragma_Main_Storage => -1,
10115 Pragma_Memory_Size => -1,
10116 Pragma_No_Return => 0,
10117 Pragma_No_Run_Time => -1,
10118 Pragma_No_Strict_Aliasing => -1,
10119 Pragma_Normalize_Scalars => -1,
10120 Pragma_Obsolescent => 0,
10121 Pragma_Optimize => -1,
10122 Pragma_Optional_Overriding => -1,
10123 Pragma_Overriding => -1,
10126 Pragma_Passive => -1,
10127 Pragma_Polling => -1,
10128 Pragma_Persistent_Data => -1,
10129 Pragma_Persistent_Object => -1,
10130 Pragma_Preelaborate => -1,
10131 Pragma_Priority => -1,
10132 Pragma_Profile => 0,
10133 Pragma_Propagate_Exceptions => -1,
10134 Pragma_Psect_Object => -1,
10136 Pragma_Pure_Function => 0,
10137 Pragma_Queuing_Policy => -1,
10138 Pragma_Ravenscar => -1,
10139 Pragma_Remote_Call_Interface => -1,
10140 Pragma_Remote_Types => -1,
10141 Pragma_Restricted_Run_Time => -1,
10142 Pragma_Restriction_Warnings => -1,
10143 Pragma_Restrictions => -1,
10144 Pragma_Reviewable => -1,
10145 Pragma_Share_Generic => -1,
10146 Pragma_Shared => -1,
10147 Pragma_Shared_Passive => -1,
10148 Pragma_Source_File_Name => -1,
10149 Pragma_Source_File_Name_Project => -1,
10150 Pragma_Source_Reference => -1,
10151 Pragma_Storage_Size => -1,
10152 Pragma_Storage_Unit => -1,
10153 Pragma_Stream_Convert => -1,
10154 Pragma_Style_Checks => -1,
10155 Pragma_Subtitle => -1,
10156 Pragma_Suppress => 0,
10157 Pragma_Suppress_Exception_Locations => 0,
10158 Pragma_Suppress_All => -1,
10159 Pragma_Suppress_Debug_Info => 0,
10160 Pragma_Suppress_Initialization => 0,
10161 Pragma_System_Name => -1,
10162 Pragma_Task_Dispatching_Policy => -1,
10163 Pragma_Task_Info => -1,
10164 Pragma_Task_Name => -1,
10165 Pragma_Task_Storage => 0,
10166 Pragma_Thread_Body => +2,
10167 Pragma_Time_Slice => -1,
10168 Pragma_Title => -1,
10169 Pragma_Unchecked_Union => 0,
10170 Pragma_Unimplemented_Unit => -1,
10171 Pragma_Universal_Data => -1,
10172 Pragma_Unreferenced => -1,
10173 Pragma_Unreserve_All_Interrupts => -1,
10174 Pragma_Unsuppress => 0,
10175 Pragma_Use_VADS_Size => -1,
10176 Pragma_Validity_Checks => -1,
10177 Pragma_Volatile => 0,
10178 Pragma_Volatile_Components => 0,
10179 Pragma_Warnings => -1,
10180 Pragma_Weak_External => 0,
10181 Unknown_Pragma => 0);
10183 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10191 if Nkind (P) /= N_Pragma_Argument_Association then
10195 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10205 A := First (Pragma_Argument_Associations (Parent (P)));
10206 for J in 1 .. C - 1 loop
10217 end Is_Non_Significant_Pragma_Reference;
10219 ------------------------------
10220 -- Is_Pragma_String_Literal --
10221 ------------------------------
10223 -- This function returns true if the corresponding pragma argument is
10224 -- a static string expression. These are the only cases in which string
10225 -- literals can appear as pragma arguments. We also allow a string
10226 -- literal as the first argument to pragma Assert (although it will
10227 -- of course always generate a type error).
10229 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10230 Pragn : constant Node_Id := Parent (Par);
10231 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10232 Pname : constant Name_Id := Chars (Pragn);
10238 N := First (Assoc);
10245 if Pname = Name_Assert then
10248 elsif Pname = Name_Export then
10251 elsif Pname = Name_Ident then
10254 elsif Pname = Name_Import then
10257 elsif Pname = Name_Interface_Name then
10260 elsif Pname = Name_Linker_Alias then
10263 elsif Pname = Name_Linker_Section then
10266 elsif Pname = Name_Machine_Attribute then
10269 elsif Pname = Name_Source_File_Name then
10272 elsif Pname = Name_Source_Reference then
10275 elsif Pname = Name_Title then
10278 elsif Pname = Name_Subtitle then
10284 end Is_Pragma_String_Literal;
10286 --------------------------------------
10287 -- Process_Compilation_Unit_Pragmas --
10288 --------------------------------------
10290 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10292 -- A special check for pragma Suppress_All. This is a strange DEC
10293 -- pragma, strange because it comes at the end of the unit. If we
10294 -- have a pragma Suppress_All in the Pragmas_After of the current
10295 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10296 -- of the context clause to ensure the correct processing.
10299 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10303 if Present (PA) then
10305 while Present (P) loop
10306 if Chars (P) = Name_Suppress_All then
10307 Prepend_To (Context_Items (N),
10308 Make_Pragma (Sloc (P),
10309 Chars => Name_Suppress,
10310 Pragma_Argument_Associations => New_List (
10311 Make_Pragma_Argument_Association (Sloc (P),
10313 Make_Identifier (Sloc (P),
10314 Chars => Name_All_Checks)))));
10322 end Process_Compilation_Unit_Pragmas;
10324 --------------------------------
10325 -- Set_Encoded_Interface_Name --
10326 --------------------------------
10328 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10329 Str : constant String_Id := Strval (S);
10330 Len : constant Int := String_Length (Str);
10335 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10338 -- Stores encoded value of character code CC. The encoding we
10339 -- use an underscore followed by four lower case hex digits.
10341 procedure Encode is
10343 Store_String_Char (Get_Char_Code ('_'));
10345 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10347 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10349 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10351 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10354 -- Start of processing for Set_Encoded_Interface_Name
10357 -- If first character is asterisk, this is a link name, and we
10358 -- leave it completely unmodified. We also ignore null strings
10359 -- (the latter case happens only in error cases) and no encoding
10360 -- should occur for Java interface names.
10363 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10366 Set_Interface_Name (E, S);
10371 CC := Get_String_Char (Str, J);
10373 exit when not In_Character_Range (CC);
10375 C := Get_Character (CC);
10377 exit when C /= '_' and then C /= '$'
10378 and then C not in '0' .. '9'
10379 and then C not in 'a' .. 'z'
10380 and then C not in 'A' .. 'Z';
10383 Set_Interface_Name (E, S);
10391 -- Here we need to encode. The encoding we use as follows:
10392 -- three underscores + four hex digits (lower case)
10396 for J in 1 .. String_Length (Str) loop
10397 CC := Get_String_Char (Str, J);
10399 if not In_Character_Range (CC) then
10402 C := Get_Character (CC);
10404 if C = '_' or else C = '$'
10405 or else C in '0' .. '9'
10406 or else C in 'a' .. 'z'
10407 or else C in 'A' .. 'Z'
10409 Store_String_Char (CC);
10416 Set_Interface_Name (E,
10417 Make_String_Literal (Sloc (S),
10418 Strval => End_String));
10420 end Set_Encoded_Interface_Name;
10422 -------------------
10423 -- Set_Unit_Name --
10424 -------------------
10426 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10431 if Nkind (N) = N_Identifier
10432 and then Nkind (With_Item) = N_Identifier
10434 Set_Entity (N, Entity (With_Item));
10436 elsif Nkind (N) = N_Selected_Component then
10437 Change_Selected_Component_To_Expanded_Name (N);
10438 Set_Entity (N, Entity (With_Item));
10439 Set_Entity (Selector_Name (N), Entity (N));
10441 Pref := Prefix (N);
10442 Scop := Scope (Entity (N));
10444 while Nkind (Pref) = N_Selected_Component loop
10445 Change_Selected_Component_To_Expanded_Name (Pref);
10446 Set_Entity (Selector_Name (Pref), Scop);
10447 Set_Entity (Pref, Scop);
10448 Pref := Prefix (Pref);
10449 Scop := Scope (Scop);
10452 Set_Entity (Pref, Scop);