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 --------------------------
565 -- Check_Ada_83_Warning --
566 --------------------------
568 procedure Check_Ada_83_Warning is
570 if Ada_83 and then Comes_From_Source (N) then
571 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
573 end Check_Ada_83_Warning;
575 ---------------------
576 -- Check_Arg_Count --
577 ---------------------
579 procedure Check_Arg_Count (Required : Nat) is
581 if Arg_Count /= Required then
582 Error_Pragma ("wrong number of arguments for pragma%");
586 -----------------------------
587 -- Check_Arg_Is_Identifier --
588 -----------------------------
590 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
591 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
594 if Nkind (Argx) /= N_Identifier then
596 ("argument for pragma% must be identifier", Argx);
598 end Check_Arg_Is_Identifier;
600 ----------------------------------
601 -- Check_Arg_Is_Integer_Literal --
602 ----------------------------------
604 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
605 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
608 if Nkind (Argx) /= N_Integer_Literal then
610 ("argument for pragma% must be integer literal", Argx);
612 end Check_Arg_Is_Integer_Literal;
614 -------------------------------------------
615 -- Check_Arg_Is_Library_Level_Local_Name --
616 -------------------------------------------
620 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
621 -- | library_unit_NAME
623 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
625 Check_Arg_Is_Local_Name (Arg);
627 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
628 and then Comes_From_Source (N)
631 ("argument for pragma% must be library level entity", Arg);
633 end Check_Arg_Is_Library_Level_Local_Name;
635 -----------------------------
636 -- Check_Arg_Is_Local_Name --
637 -----------------------------
641 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
642 -- | library_unit_NAME
644 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
645 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
650 if Nkind (Argx) not in N_Direct_Name
651 and then (Nkind (Argx) /= N_Attribute_Reference
652 or else Present (Expressions (Argx))
653 or else Nkind (Prefix (Argx)) /= N_Identifier)
654 and then (not Is_Entity_Name (Argx)
655 or else not Is_Compilation_Unit (Entity (Argx)))
657 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
660 if Is_Entity_Name (Argx)
661 and then Scope (Entity (Argx)) /= Current_Scope
664 ("pragma% argument must be in same declarative part", Arg);
666 end Check_Arg_Is_Local_Name;
668 ---------------------------------
669 -- Check_Arg_Is_Locking_Policy --
670 ---------------------------------
672 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
673 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
676 Check_Arg_Is_Identifier (Argx);
678 if not Is_Locking_Policy_Name (Chars (Argx)) then
680 ("& is not a valid locking policy name", Argx);
682 end Check_Arg_Is_Locking_Policy;
684 -------------------------
685 -- Check_Arg_Is_One_Of --
686 -------------------------
688 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
689 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
692 Check_Arg_Is_Identifier (Argx);
694 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
695 Error_Msg_Name_2 := N1;
696 Error_Msg_Name_3 := N2;
697 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
699 end Check_Arg_Is_One_Of;
701 procedure Check_Arg_Is_One_Of
703 N1, N2, N3 : Name_Id)
705 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
708 Check_Arg_Is_Identifier (Argx);
710 if Chars (Argx) /= N1
711 and then Chars (Argx) /= N2
712 and then Chars (Argx) /= N3
714 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
716 end Check_Arg_Is_One_Of;
718 ---------------------------------
719 -- Check_Arg_Is_Queuing_Policy --
720 ---------------------------------
722 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
723 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
726 Check_Arg_Is_Identifier (Argx);
728 if not Is_Queuing_Policy_Name (Chars (Argx)) then
730 ("& is not a valid queuing policy name", Argx);
732 end Check_Arg_Is_Queuing_Policy;
734 ------------------------------------
735 -- Check_Arg_Is_Static_Expression --
736 ------------------------------------
738 procedure Check_Arg_Is_Static_Expression
742 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
745 Analyze_And_Resolve (Argx, Typ);
747 if Is_OK_Static_Expression (Argx) then
750 elsif Etype (Argx) = Any_Type then
753 -- An interesting special case, if we have a string literal and
754 -- we are in Ada 83 mode, then we allow it even though it will
755 -- not be flagged as static. This allows the use of Ada 95
756 -- pragmas like Import in Ada 83 mode. They will of course be
757 -- flagged with warnings as usual, but will not cause errors.
759 elsif Ada_83 and then Nkind (Argx) = N_String_Literal then
762 -- Static expression that raises Constraint_Error. This has
763 -- already been flagged, so just exit from pragma processing.
765 elsif Is_Static_Expression (Argx) then
768 -- Finally, we have a real error
771 Error_Msg_Name_1 := Chars (N);
773 ("argument for pragma% must be a static expression!", Argx);
776 end Check_Arg_Is_Static_Expression;
778 ---------------------------------
779 -- Check_Arg_Is_String_Literal --
780 ---------------------------------
782 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
783 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
786 if Nkind (Argx) /= N_String_Literal then
788 ("argument for pragma% must be string literal", Argx);
791 end Check_Arg_Is_String_Literal;
793 ------------------------------------------
794 -- Check_Arg_Is_Task_Dispatching_Policy --
795 ------------------------------------------
797 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
798 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
801 Check_Arg_Is_Identifier (Argx);
803 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
805 ("& is not a valid task dispatching policy name", Argx);
807 end Check_Arg_Is_Task_Dispatching_Policy;
809 --------------------------------
810 -- Check_At_Least_N_Arguments --
811 --------------------------------
813 procedure Check_At_Least_N_Arguments (N : Nat) is
815 if Arg_Count < N then
816 Error_Pragma ("too few arguments for pragma%");
818 end Check_At_Least_N_Arguments;
820 -------------------------------
821 -- Check_At_Most_N_Arguments --
822 -------------------------------
824 procedure Check_At_Most_N_Arguments (N : Nat) is
828 if Arg_Count > N then
833 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
836 end Check_At_Most_N_Arguments;
838 -------------------------
839 -- Check_First_Subtype --
840 -------------------------
842 procedure Check_First_Subtype (Arg : Node_Id) is
843 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
846 if not Is_First_Subtype (Entity (Argx)) then
848 ("pragma% cannot apply to subtype", Argx);
850 end Check_First_Subtype;
852 ---------------------------
853 -- Check_In_Main_Program --
854 ---------------------------
856 procedure Check_In_Main_Program is
857 P : constant Node_Id := Parent (N);
860 -- Must be at in subprogram body
862 if Nkind (P) /= N_Subprogram_Body then
863 Error_Pragma ("% pragma allowed only in subprogram");
865 -- Otherwise warn if obviously not main program
867 elsif Present (Parameter_Specifications (Specification (P)))
868 or else not Is_Compilation_Unit (Defining_Entity (P))
870 Error_Msg_Name_1 := Chars (N);
872 ("?pragma% is only effective in main program", N);
874 end Check_In_Main_Program;
876 ---------------------------------------
877 -- Check_Interrupt_Or_Attach_Handler --
878 ---------------------------------------
880 procedure Check_Interrupt_Or_Attach_Handler is
881 Arg1_X : constant Node_Id := Expression (Arg1);
886 if not Is_Entity_Name (Arg1_X) then
888 ("argument of pragma% must be entity name", Arg1);
890 elsif Prag_Id = Pragma_Interrupt_Handler then
891 Check_Restriction (No_Dynamic_Attachment, N);
895 Handler_Proc : Entity_Id := Empty;
896 Proc_Scope : Entity_Id;
897 Found : Boolean := False;
900 if not Is_Overloaded (Arg1_X) then
901 Handler_Proc := Entity (Arg1_X);
906 Index : Interp_Index;
909 Get_First_Interp (Arg1_X, Index, It);
910 while Present (It.Nam) loop
911 Handler_Proc := It.Nam;
913 if Ekind (Handler_Proc) = E_Procedure
914 and then No (First_Formal (Handler_Proc))
918 Set_Entity (Arg1_X, Handler_Proc);
919 Set_Is_Overloaded (Arg1_X, False);
922 ("ambiguous handler name for pragma% ", Arg1);
926 Get_Next_Interp (Index, It);
931 ("argument of pragma% must be parameterless procedure",
934 Handler_Proc := Entity (Arg1_X);
939 Proc_Scope := Scope (Handler_Proc);
941 -- On AAMP only, a pragma Interrupt_Handler is supported for
942 -- nonprotected parameterless procedures.
945 and then Prag_Id = Pragma_Interrupt_Handler
947 if Ekind (Handler_Proc) /= E_Procedure then
949 ("argument of pragma% must be a procedure", Arg1);
952 elsif Ekind (Handler_Proc) /= E_Procedure
953 or else Ekind (Proc_Scope) /= E_Protected_Type
956 ("argument of pragma% must be protected procedure", Arg1);
959 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
960 and then Ekind (Proc_Scope) = E_Protected_Type
963 Protected_Definition (Parent (Proc_Scope))
965 Error_Pragma ("pragma% must be in protected definition");
969 if not Is_Library_Level_Entity (Proc_Scope)
970 or else (AAMP_On_Target
971 and then not Is_Library_Level_Entity (Handler_Proc))
974 ("pragma% requires library-level entity", Arg1);
977 if Present (First_Formal (Handler_Proc)) then
979 ("argument of pragma% must be parameterless procedure",
983 end Check_Interrupt_Or_Attach_Handler;
985 -------------------------------------------
986 -- Check_Is_In_Decl_Part_Or_Package_Spec --
987 -------------------------------------------
989 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
998 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1001 elsif Nkind (P) = N_Package_Specification then
1004 elsif Nkind (P) = N_Block_Statement then
1007 -- Note: the following tests seem a little peculiar, because
1008 -- they test for bodies, but if we were in the statement part
1009 -- of the body, we would already have hit the handled statement
1010 -- sequence, so the only way we get here is by being in the
1011 -- declarative part of the body.
1013 elsif Nkind (P) = N_Subprogram_Body
1014 or else Nkind (P) = N_Package_Body
1015 or else Nkind (P) = N_Task_Body
1016 or else Nkind (P) = N_Entry_Body
1024 Error_Pragma ("pragma% is not in declarative part or package spec");
1025 end Check_Is_In_Decl_Part_Or_Package_Spec;
1027 -------------------------
1028 -- Check_No_Identifier --
1029 -------------------------
1031 procedure Check_No_Identifier (Arg : Node_Id) is
1033 if Chars (Arg) /= No_Name then
1034 Error_Pragma_Arg_Ident
1035 ("pragma% does not permit identifier& here", Arg);
1037 end Check_No_Identifier;
1039 --------------------------
1040 -- Check_No_Identifiers --
1041 --------------------------
1043 procedure Check_No_Identifiers is
1047 if Arg_Count > 0 then
1050 while Present (Arg_Node) loop
1051 Check_No_Identifier (Arg_Node);
1055 end Check_No_Identifiers;
1057 -------------------------------
1058 -- Check_Optional_Identifier --
1059 -------------------------------
1061 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1063 if Present (Arg) and then Chars (Arg) /= No_Name then
1064 if Chars (Arg) /= Id then
1065 Error_Msg_Name_1 := Chars (N);
1066 Error_Msg_Name_2 := Id;
1067 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1071 end Check_Optional_Identifier;
1073 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1075 Name_Buffer (1 .. Id'Length) := Id;
1076 Name_Len := Id'Length;
1077 Check_Optional_Identifier (Arg, Name_Find);
1078 end Check_Optional_Identifier;
1080 -----------------------------
1081 -- Check_Static_Constraint --
1082 -----------------------------
1084 -- Note: for convenience in writing this procedure, in addition to
1085 -- the officially (i.e. by spec) allowed argument which is always
1086 -- a constraint, it also allows ranges and discriminant associations.
1087 -- Above is not clear ???
1089 procedure Check_Static_Constraint (Constr : Node_Id) is
1091 --------------------
1092 -- Require_Static --
1093 --------------------
1095 procedure Require_Static (E : Node_Id);
1096 -- Require given expression to be static expression
1098 procedure Require_Static (E : Node_Id) is
1100 if not Is_OK_Static_Expression (E) then
1101 Flag_Non_Static_Expr
1102 ("non-static constraint not allowed in Unchecked_Union!", E);
1107 -- Start of processing for Check_Static_Constraint
1110 case Nkind (Constr) is
1111 when N_Discriminant_Association =>
1112 Require_Static (Expression (Constr));
1115 Require_Static (Low_Bound (Constr));
1116 Require_Static (High_Bound (Constr));
1118 when N_Attribute_Reference =>
1119 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1120 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1122 when N_Range_Constraint =>
1123 Check_Static_Constraint (Range_Expression (Constr));
1125 when N_Index_Or_Discriminant_Constraint =>
1127 IDC : Entity_Id := First (Constraints (Constr));
1129 while Present (IDC) loop
1130 Check_Static_Constraint (IDC);
1138 end Check_Static_Constraint;
1140 --------------------------------------
1141 -- Check_Valid_Configuration_Pragma --
1142 --------------------------------------
1144 -- A configuration pragma must appear in the context clause of
1145 -- a compilation unit, at the start of the list (i.e. only other
1146 -- pragmas may precede it).
1148 procedure Check_Valid_Configuration_Pragma is
1150 if not Is_Configuration_Pragma then
1151 Error_Pragma ("incorrect placement for configuration pragma%");
1153 end Check_Valid_Configuration_Pragma;
1155 -------------------------------------
1156 -- Check_Valid_Library_Unit_Pragma --
1157 -------------------------------------
1159 procedure Check_Valid_Library_Unit_Pragma is
1161 Parent_Node : Node_Id;
1162 Unit_Name : Entity_Id;
1163 Unit_Kind : Node_Kind;
1164 Unit_Node : Node_Id;
1165 Sindex : Source_File_Index;
1168 if not Is_List_Member (N) then
1172 Plist := List_Containing (N);
1173 Parent_Node := Parent (Plist);
1175 if Parent_Node = Empty then
1178 -- Case of pragma appearing after a compilation unit. In this
1179 -- case it must have an argument with the corresponding name
1180 -- and must be part of the following pragmas of its parent.
1182 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1183 if Plist /= Pragmas_After (Parent_Node) then
1186 elsif Arg_Count = 0 then
1188 ("argument required if outside compilation unit");
1191 Check_No_Identifiers;
1192 Check_Arg_Count (1);
1193 Unit_Node := Unit (Parent (Parent_Node));
1194 Unit_Kind := Nkind (Unit_Node);
1196 Analyze (Expression (Arg1));
1198 if Unit_Kind = N_Generic_Subprogram_Declaration
1199 or else Unit_Kind = N_Subprogram_Declaration
1201 Unit_Name := Defining_Entity (Unit_Node);
1203 elsif Unit_Kind = N_Function_Instantiation
1204 or else Unit_Kind = N_Package_Instantiation
1205 or else Unit_Kind = N_Procedure_Instantiation
1207 Unit_Name := Defining_Entity (Unit_Node);
1210 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1213 if Chars (Unit_Name) /=
1214 Chars (Entity (Expression (Arg1)))
1217 ("pragma% argument is not current unit name", Arg1);
1220 if Ekind (Unit_Name) = E_Package
1221 and then Present (Renamed_Entity (Unit_Name))
1223 Error_Pragma ("pragma% not allowed for renamed package");
1227 -- Pragma appears other than after a compilation unit
1230 -- Here we check for the generic instantiation case and also
1231 -- for the case of processing a generic formal package. We
1232 -- detect these cases by noting that the Sloc on the node
1233 -- does not belong to the current compilation unit.
1235 Sindex := Source_Index (Current_Sem_Unit);
1237 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1238 Rewrite (N, Make_Null_Statement (Loc));
1241 -- If before first declaration, the pragma applies to the
1242 -- enclosing unit, and the name if present must be this name.
1244 elsif Is_Before_First_Decl (N, Plist) then
1245 Unit_Node := Unit_Declaration_Node (Current_Scope);
1246 Unit_Kind := Nkind (Unit_Node);
1248 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1251 elsif Unit_Kind = N_Subprogram_Body
1252 and then not Acts_As_Spec (Unit_Node)
1256 elsif Nkind (Parent_Node) = N_Package_Body then
1259 elsif Nkind (Parent_Node) = N_Package_Specification
1260 and then Plist = Private_Declarations (Parent_Node)
1264 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1265 or else Nkind (Parent_Node)
1266 = N_Generic_Subprogram_Declaration)
1267 and then Plist = Generic_Formal_Declarations (Parent_Node)
1271 elsif Arg_Count > 0 then
1272 Analyze (Expression (Arg1));
1274 if Entity (Expression (Arg1)) /= Current_Scope then
1276 ("name in pragma% must be enclosing unit", Arg1);
1279 -- It is legal to have no argument in this context
1285 -- Error if not before first declaration. This is because a
1286 -- library unit pragma argument must be the name of a library
1287 -- unit (RM 10.1.5(7)), but the only names permitted in this
1288 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1289 -- generic subprogram declarations or generic instantiations.
1293 ("pragma% misplaced, must be before first declaration");
1297 end Check_Valid_Library_Unit_Pragma;
1303 procedure Error_Pragma (Msg : String) is
1305 Error_Msg_Name_1 := Chars (N);
1306 Error_Msg_N (Msg, N);
1310 ----------------------
1311 -- Error_Pragma_Arg --
1312 ----------------------
1314 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1316 Error_Msg_Name_1 := Chars (N);
1317 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1319 end Error_Pragma_Arg;
1321 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1323 Error_Msg_Name_1 := Chars (N);
1324 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1325 Error_Pragma_Arg (Msg2, Arg);
1326 end Error_Pragma_Arg;
1328 ----------------------------
1329 -- Error_Pragma_Arg_Ident --
1330 ----------------------------
1332 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1334 Error_Msg_Name_1 := Chars (N);
1335 Error_Msg_N (Msg, Arg);
1337 end Error_Pragma_Arg_Ident;
1339 ------------------------
1340 -- Find_Lib_Unit_Name --
1341 ------------------------
1343 function Find_Lib_Unit_Name return Entity_Id is
1345 -- Return inner compilation unit entity, for case of nested
1346 -- categorization pragmas. This happens in generic unit.
1348 if Nkind (Parent (N)) = N_Package_Specification
1349 and then Defining_Entity (Parent (N)) /= Current_Scope
1351 return Defining_Entity (Parent (N));
1353 return Current_Scope;
1355 end Find_Lib_Unit_Name;
1357 ----------------------------
1358 -- Find_Program_Unit_Name --
1359 ----------------------------
1361 procedure Find_Program_Unit_Name (Id : Node_Id) is
1362 Unit_Name : Entity_Id;
1363 Unit_Kind : Node_Kind;
1364 P : constant Node_Id := Parent (N);
1367 if Nkind (P) = N_Compilation_Unit then
1368 Unit_Kind := Nkind (Unit (P));
1370 if Unit_Kind = N_Subprogram_Declaration
1371 or else Unit_Kind = N_Package_Declaration
1372 or else Unit_Kind in N_Generic_Declaration
1374 Unit_Name := Defining_Entity (Unit (P));
1376 if Chars (Id) = Chars (Unit_Name) then
1377 Set_Entity (Id, Unit_Name);
1378 Set_Etype (Id, Etype (Unit_Name));
1380 Set_Etype (Id, Any_Type);
1382 ("cannot find program unit referenced by pragma%");
1386 Set_Etype (Id, Any_Type);
1387 Error_Pragma ("pragma% inapplicable to this unit");
1394 end Find_Program_Unit_Name;
1396 -------------------------
1397 -- Gather_Associations --
1398 -------------------------
1400 procedure Gather_Associations
1402 Args : out Args_List)
1407 -- Initialize all parameters to Empty
1409 for J in Args'Range loop
1413 -- That's all we have to do if there are no argument associations
1415 if No (Pragma_Argument_Associations (N)) then
1419 -- Otherwise first deal with any positional parameters present
1421 Arg := First (Pragma_Argument_Associations (N));
1423 for Index in Args'Range loop
1424 exit when No (Arg) or else Chars (Arg) /= No_Name;
1425 Args (Index) := Expression (Arg);
1429 -- Positional parameters all processed, if any left, then we
1430 -- have too many positional parameters.
1432 if Present (Arg) and then Chars (Arg) = No_Name then
1434 ("too many positional associations for pragma%", Arg);
1437 -- Process named parameters if any are present
1439 while Present (Arg) loop
1440 if Chars (Arg) = No_Name then
1442 ("positional association cannot follow named association",
1446 for Index in Names'Range loop
1447 if Names (Index) = Chars (Arg) then
1448 if Present (Args (Index)) then
1450 ("duplicate argument association for pragma%", Arg);
1452 Args (Index) := Expression (Arg);
1457 if Index = Names'Last then
1458 Error_Msg_Name_1 := Chars (N);
1459 Error_Msg_N ("pragma% does not allow & argument", Arg);
1461 -- Check for possible misspelling
1463 for Index1 in Names'Range loop
1464 if Is_Bad_Spelling_Of
1465 (Get_Name_String (Chars (Arg)),
1466 Get_Name_String (Names (Index1)))
1468 Error_Msg_Name_1 := Names (Index1);
1469 Error_Msg_N ("\possible misspelling of%", Arg);
1481 end Gather_Associations;
1483 --------------------
1484 -- Get_Pragma_Arg --
1485 --------------------
1487 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1489 if Nkind (Arg) = N_Pragma_Argument_Association then
1490 return Expression (Arg);
1500 procedure GNAT_Pragma is
1502 Check_Restriction (No_Implementation_Pragmas, N);
1505 --------------------------
1506 -- Is_Before_First_Decl --
1507 --------------------------
1509 function Is_Before_First_Decl
1510 (Pragma_Node : Node_Id;
1511 Decls : List_Id) return Boolean
1513 Item : Node_Id := First (Decls);
1516 -- Only other pragmas can come before this pragma
1519 if No (Item) or else Nkind (Item) /= N_Pragma then
1522 elsif Item = Pragma_Node then
1528 end Is_Before_First_Decl;
1530 -----------------------------
1531 -- Is_Configuration_Pragma --
1532 -----------------------------
1534 -- A configuration pragma must appear in the context clause of
1535 -- a compilation unit, at the start of the list (i.e. only other
1536 -- pragmas may precede it).
1538 function Is_Configuration_Pragma return Boolean is
1539 Lis : constant List_Id := List_Containing (N);
1540 Par : constant Node_Id := Parent (N);
1544 -- If no parent, then we are in the configuration pragma file,
1545 -- so the placement is definitely appropriate.
1550 -- Otherwise we must be in the context clause of a compilation unit
1551 -- and the only thing allowed before us in the context list is more
1552 -- configuration pragmas.
1554 elsif Nkind (Par) = N_Compilation_Unit
1555 and then Context_Items (Par) = Lis
1562 elsif Nkind (Prg) /= N_Pragma then
1572 end Is_Configuration_Pragma;
1574 ----------------------
1575 -- Pragma_Misplaced --
1576 ----------------------
1578 procedure Pragma_Misplaced is
1580 Error_Pragma ("incorrect placement of pragma%");
1581 end Pragma_Misplaced;
1583 ------------------------------------
1584 -- Process Atomic_Shared_Volatile --
1585 ------------------------------------
1587 procedure Process_Atomic_Shared_Volatile is
1595 Check_Ada_83_Warning;
1596 Check_No_Identifiers;
1597 Check_Arg_Count (1);
1598 Check_Arg_Is_Local_Name (Arg1);
1599 E_Id := Expression (Arg1);
1601 if Etype (E_Id) = Any_Type then
1606 D := Declaration_Node (E);
1610 if Rep_Item_Too_Early (E, N)
1612 Rep_Item_Too_Late (E, N)
1616 Check_First_Subtype (Arg1);
1619 if Prag_Id /= Pragma_Volatile then
1621 Set_Is_Atomic (Underlying_Type (E));
1624 -- Attribute belongs on the base type. If the
1625 -- view of the type is currently private, it also
1626 -- belongs on the underlying type.
1628 Set_Is_Volatile (Base_Type (E));
1629 Set_Is_Volatile (Underlying_Type (E));
1631 Set_Treat_As_Volatile (E);
1632 Set_Treat_As_Volatile (Underlying_Type (E));
1634 elsif K = N_Object_Declaration
1635 or else (K = N_Component_Declaration
1636 and then Original_Record_Component (E) = E)
1638 if Rep_Item_Too_Late (E, N) then
1642 if Prag_Id /= Pragma_Volatile then
1645 -- If the object declaration has an explicit
1646 -- initialization, a temporary may have to be
1647 -- created to hold the expression, to insure
1648 -- that access to the object remain atomic.
1650 if Nkind (Parent (E)) = N_Object_Declaration
1651 and then Present (Expression (Parent (E)))
1653 Set_Has_Delayed_Freeze (E);
1656 -- An interesting improvement here. If an object of type X
1657 -- is declared atomic, and the type X is not atomic, that's
1658 -- a pity, since it may not have appropraite alignment etc.
1659 -- We can rescue this in the special case where the object
1660 -- and type are in the same unit by just setting the type
1661 -- as atomic, so that the back end will process it as atomic.
1663 Utyp := Underlying_Type (Etype (E));
1666 and then Sloc (E) > No_Location
1667 and then Sloc (Utyp) > No_Location
1669 Get_Source_File_Index (Sloc (E)) =
1670 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1672 Set_Is_Atomic (Underlying_Type (Etype (E)));
1676 Set_Is_Volatile (E);
1677 Set_Treat_As_Volatile (E);
1681 ("inappropriate entity for pragma%", Arg1);
1683 end Process_Atomic_Shared_Volatile;
1685 ------------------------
1686 -- Process_Convention --
1687 ------------------------
1689 procedure Process_Convention
1690 (C : out Convention_Id;
1696 Comp_Unit : Unit_Number_Type;
1698 procedure Set_Convention_From_Pragma (E : Entity_Id);
1699 -- Set convention in entity E, and also flag that the entity has a
1700 -- convention pragma. If entity is for a private or incomplete type,
1701 -- also set convention and flag on underlying type. This procedure
1702 -- also deals with the special case of C_Pass_By_Copy convention.
1704 --------------------------------
1705 -- Set_Convention_From_Pragma --
1706 --------------------------------
1708 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1710 Set_Convention (E, C);
1711 Set_Has_Convention_Pragma (E);
1713 if Is_Incomplete_Or_Private_Type (E) then
1714 Set_Convention (Underlying_Type (E), C);
1715 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1718 -- A class-wide type should inherit the convention of
1719 -- the specific root type (although this isn't specified
1720 -- clearly by the RM).
1722 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1723 Set_Convention (Class_Wide_Type (E), C);
1726 -- If the entity is a record type, then check for special case
1727 -- of C_Pass_By_Copy, which is treated the same as C except that
1728 -- the special record flag is set. This convention is also only
1729 -- permitted on record types (see AI95-00131).
1731 if Cname = Name_C_Pass_By_Copy then
1732 if Is_Record_Type (E) then
1733 Set_C_Pass_By_Copy (Base_Type (E));
1734 elsif Is_Incomplete_Or_Private_Type (E)
1735 and then Is_Record_Type (Underlying_Type (E))
1737 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1740 ("C_Pass_By_Copy convention allowed only for record type",
1745 -- If the entity is a derived boolean type, check for the
1746 -- special case of convention C, C++, or Fortran, where we
1747 -- consider any nonzero value to represent true.
1749 if Is_Discrete_Type (E)
1750 and then Root_Type (Etype (E)) = Standard_Boolean
1756 C = Convention_Fortran)
1758 Set_Nonzero_Is_True (Base_Type (E));
1760 end Set_Convention_From_Pragma;
1762 -- Start of processing for Process_Convention
1765 Check_At_Least_N_Arguments (2);
1766 Check_Arg_Is_Identifier (Arg1);
1767 Check_Optional_Identifier (Arg1, Name_Convention);
1768 Cname := Chars (Expression (Arg1));
1770 -- C_Pass_By_Copy is treated as a synonym for convention C
1771 -- (this is tested again below to set the critical flag)
1773 if Cname = Name_C_Pass_By_Copy then
1776 -- Otherwise we must have something in the standard convention list
1778 elsif Is_Convention_Name (Cname) then
1779 C := Get_Convention_Id (Chars (Expression (Arg1)));
1781 -- In DEC VMS, it seems that there is an undocumented feature
1782 -- that any unrecognized convention is treated as the default,
1783 -- which for us is convention C. It does not seem so terrible
1784 -- to do this unconditionally, silently in the VMS case, and
1785 -- with a warning in the non-VMS case.
1788 if Warn_On_Export_Import and not OpenVMS_On_Target then
1790 ("?unrecognized convention name, C assumed",
1797 Check_Arg_Is_Local_Name (Arg2);
1798 Check_Optional_Identifier (Arg2, Name_Entity);
1800 Id := Expression (Arg2);
1803 if not Is_Entity_Name (Id) then
1804 Error_Pragma_Arg ("entity name required", Arg2);
1809 -- Go to renamed subprogram if present, since convention applies
1810 -- to the actual renamed entity, not to the renaming entity.
1812 if Is_Subprogram (E)
1813 and then Present (Alias (E))
1814 and then Nkind (Parent (Declaration_Node (E))) =
1815 N_Subprogram_Renaming_Declaration
1820 -- Check that we not applying this to a specless body
1822 if Is_Subprogram (E)
1823 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
1826 ("pragma% requires separate spec and must come before body");
1829 -- Check that we are not applying this to a named constant
1831 if Ekind (E) = E_Named_Integer
1833 Ekind (E) = E_Named_Real
1835 Error_Msg_Name_1 := Chars (N);
1837 ("cannot apply pragma% to named constant!",
1838 Get_Pragma_Arg (Arg2));
1840 ("\supply appropriate type for&!", Arg2);
1843 if Etype (E) = Any_Type
1844 or else Rep_Item_Too_Early (E, N)
1848 E := Underlying_Type (E);
1851 if Rep_Item_Too_Late (E, N) then
1855 if Has_Convention_Pragma (E) then
1857 ("at most one Convention/Export/Import pragma is allowed", Arg2);
1859 elsif Convention (E) = Convention_Protected
1860 or else Ekind (Scope (E)) = E_Protected_Type
1863 ("a protected operation cannot be given a different convention",
1867 -- For Intrinsic, a subprogram is required
1869 if C = Convention_Intrinsic
1870 and then not Is_Subprogram (E)
1871 and then not Is_Generic_Subprogram (E)
1874 ("second argument of pragma% must be a subprogram", Arg2);
1877 -- For Stdcall, a subprogram, variable or subprogram type is required
1879 if C = Convention_Stdcall
1880 and then not Is_Subprogram (E)
1881 and then not Is_Generic_Subprogram (E)
1882 and then Ekind (E) /= E_Variable
1885 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
1888 ("second argument of pragma% must be subprogram (type)",
1892 if not Is_Subprogram (E)
1893 and then not Is_Generic_Subprogram (E)
1895 Set_Convention_From_Pragma (E);
1899 Check_First_Subtype (Arg2);
1900 Set_Convention_From_Pragma (Base_Type (E));
1902 -- For subprograms, we must set the convention on the
1903 -- internally generated directly designated type as well.
1905 if Ekind (E) = E_Access_Subprogram_Type then
1906 Set_Convention_From_Pragma (Directly_Designated_Type (E));
1910 -- For the subprogram case, set proper convention for all homonyms
1911 -- in same scope and the same declarative part, i.e. the same
1912 -- compilation unit.
1915 Comp_Unit := Get_Source_Unit (E);
1916 Set_Convention_From_Pragma (E);
1918 -- Treat a pragma Import as an implicit body, for GPS use.
1920 if Prag_Id = Pragma_Import then
1921 Generate_Reference (E, Id, 'b');
1927 exit when No (E1) or else Scope (E1) /= Current_Scope;
1929 -- Note: below we are missing a check for Rep_Item_Too_Late.
1930 -- That is deliberate, we cannot chain the rep item on more
1931 -- than one Rep_Item chain, to be fixed later ???
1933 if Comes_From_Source (E1)
1934 and then Comp_Unit = Get_Source_Unit (E1)
1935 and then Nkind (Original_Node (Parent (E1))) /=
1936 N_Full_Type_Declaration
1938 Set_Convention_From_Pragma (E1);
1940 if Prag_Id = Pragma_Import then
1941 Generate_Reference (E, Id, 'b');
1946 end Process_Convention;
1948 -----------------------------------------------------
1949 -- Process_Extended_Import_Export_Exception_Pragma --
1950 -----------------------------------------------------
1952 procedure Process_Extended_Import_Export_Exception_Pragma
1953 (Arg_Internal : Node_Id;
1954 Arg_External : Node_Id;
1964 if not OpenVMS_On_Target then
1966 ("?pragma% ignored (applies only to Open'V'M'S)");
1969 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
1970 Def_Id := Entity (Arg_Internal);
1972 if Ekind (Def_Id) /= E_Exception then
1974 ("pragma% must refer to declared exception", Arg_Internal);
1977 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
1979 if Present (Arg_Form) then
1980 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
1983 if Present (Arg_Form)
1984 and then Chars (Arg_Form) = Name_Ada
1988 Set_Is_VMS_Exception (Def_Id);
1989 Set_Exception_Code (Def_Id, No_Uint);
1992 if Present (Arg_Code) then
1993 if not Is_VMS_Exception (Def_Id) then
1995 ("Code option for pragma% not allowed for Ada case",
1999 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2000 Code_Val := Expr_Value (Arg_Code);
2002 if not UI_Is_In_Int_Range (Code_Val) then
2004 ("Code option for pragma% must be in 32-bit range",
2008 Set_Exception_Code (Def_Id, Code_Val);
2011 end Process_Extended_Import_Export_Exception_Pragma;
2013 -------------------------------------------------
2014 -- Process_Extended_Import_Export_Internal_Arg --
2015 -------------------------------------------------
2017 procedure Process_Extended_Import_Export_Internal_Arg
2018 (Arg_Internal : Node_Id := Empty)
2023 if No (Arg_Internal) then
2024 Error_Pragma ("Internal parameter required for pragma%");
2027 if Nkind (Arg_Internal) = N_Identifier then
2030 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2031 and then (Prag_Id = Pragma_Import_Function
2033 Prag_Id = Pragma_Export_Function)
2039 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2042 Check_Arg_Is_Local_Name (Arg_Internal);
2043 end Process_Extended_Import_Export_Internal_Arg;
2045 --------------------------------------------------
2046 -- Process_Extended_Import_Export_Object_Pragma --
2047 --------------------------------------------------
2049 procedure Process_Extended_Import_Export_Object_Pragma
2050 (Arg_Internal : Node_Id;
2051 Arg_External : Node_Id;
2057 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2058 Def_Id := Entity (Arg_Internal);
2060 if Ekind (Def_Id) /= E_Constant
2061 and then Ekind (Def_Id) /= E_Variable
2064 ("pragma% must designate an object", Arg_Internal);
2067 if Is_Psected (Def_Id) then
2069 ("previous Psect_Object applies, pragma % not permitted",
2073 if Rep_Item_Too_Late (Def_Id, N) then
2077 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2079 if Present (Arg_Size)
2080 and then Nkind (Arg_Size) /= N_Identifier
2081 and then Nkind (Arg_Size) /= N_String_Literal
2084 ("pragma% Size argument must be identifier or string literal",
2088 -- Export_Object case
2090 if Prag_Id = Pragma_Export_Object then
2091 if not Is_Library_Level_Entity (Def_Id) then
2093 ("argument for pragma% must be library level entity",
2097 if Ekind (Current_Scope) = E_Generic_Package then
2098 Error_Pragma ("pragma& cannot appear in a generic unit");
2101 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2103 ("exported object must have compile time known size",
2107 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2109 ("?duplicate Export_Object pragma", N);
2111 Set_Exported (Def_Id, Arg_Internal);
2114 -- Import_Object case
2117 if Is_Concurrent_Type (Etype (Def_Id)) then
2119 ("cannot use pragma% for task/protected object",
2123 if Ekind (Def_Id) = E_Constant then
2125 ("cannot import a constant", Arg_Internal);
2128 if Warn_On_Export_Import
2129 and then Has_Discriminants (Etype (Def_Id))
2132 ("imported value must be initialized?", Arg_Internal);
2135 if Warn_On_Export_Import
2136 and then Is_Access_Type (Etype (Def_Id))
2139 ("cannot import object of an access type?", Arg_Internal);
2142 if Warn_On_Export_Import
2143 and then Is_Imported (Def_Id)
2146 ("?duplicate Import_Object pragma", N);
2148 -- Check for explicit initialization present. Note that an
2149 -- initialization that generated by the code generator, e.g.
2150 -- for an access type, does not count here.
2152 elsif Present (Expression (Parent (Def_Id)))
2155 (Original_Node (Expression (Parent (Def_Id))))
2157 Error_Msg_Sloc := Sloc (Def_Id);
2159 ("no initialization allowed for declaration of& #",
2160 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2163 Set_Imported (Def_Id);
2164 Note_Possible_Modification (Arg_Internal);
2167 end Process_Extended_Import_Export_Object_Pragma;
2169 ------------------------------------------------------
2170 -- Process_Extended_Import_Export_Subprogram_Pragma --
2171 ------------------------------------------------------
2173 procedure Process_Extended_Import_Export_Subprogram_Pragma
2174 (Arg_Internal : Node_Id;
2175 Arg_External : Node_Id;
2176 Arg_Parameter_Types : Node_Id;
2177 Arg_Result_Type : Node_Id := Empty;
2178 Arg_Mechanism : Node_Id;
2179 Arg_Result_Mechanism : Node_Id := Empty;
2180 Arg_First_Optional_Parameter : Node_Id := Empty)
2186 Ambiguous : Boolean;
2190 function Same_Base_Type
2192 Formal : Entity_Id) return Boolean;
2193 -- Determines if Ptype references the type of Formal. Note that
2194 -- only the base types need to match according to the spec. Ptype
2195 -- here is the argument from the pragma, which is either a type
2196 -- name, or an access attribute.
2198 --------------------
2199 -- Same_Base_Type --
2200 --------------------
2202 function Same_Base_Type
2204 Formal : Entity_Id) return Boolean
2206 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2210 -- Case where pragma argument is typ'Access
2212 if Nkind (Ptype) = N_Attribute_Reference
2213 and then Attribute_Name (Ptype) = Name_Access
2215 Pref := Prefix (Ptype);
2218 if not Is_Entity_Name (Pref)
2219 or else Entity (Pref) = Any_Type
2224 -- We have a match if the corresponding argument is of an
2225 -- anonymous access type, and its designicated type matches
2226 -- the type of the prefix of the access attribute
2228 return Ekind (Ftyp) = E_Anonymous_Access_Type
2229 and then Base_Type (Entity (Pref)) =
2230 Base_Type (Etype (Designated_Type (Ftyp)));
2232 -- Case where pragma argument is a type name
2237 if not Is_Entity_Name (Ptype)
2238 or else Entity (Ptype) = Any_Type
2243 -- We have a match if the corresponding argument is of
2244 -- the type given in the pragma (comparing base types)
2246 return Base_Type (Entity (Ptype)) = Ftyp;
2250 -- Start of processing for
2251 -- Process_Extended_Import_Export_Subprogram_Pragma
2254 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2255 Hom_Id := Entity (Arg_Internal);
2259 -- Loop through homonyms (overloadings) of Hom_Id
2261 while Present (Hom_Id) loop
2262 Def_Id := Get_Base_Subprogram (Hom_Id);
2264 -- We need a subprogram in the current scope
2266 if not Is_Subprogram (Def_Id)
2267 or else Scope (Def_Id) /= Current_Scope
2274 -- Pragma cannot apply to subprogram body
2276 if Is_Subprogram (Def_Id)
2279 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2282 ("pragma% requires separate spec"
2283 & " and must come before body");
2286 -- Test result type if given, note that the result type
2287 -- parameter can only be present for the function cases.
2289 if Present (Arg_Result_Type)
2290 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2294 elsif Etype (Def_Id) /= Standard_Void_Type
2296 (Chars (N) = Name_Export_Procedure
2297 or else Chars (N) = Name_Import_Procedure)
2301 -- Test parameter types if given. Note that this parameter
2302 -- has not been analyzed (and must not be, since it is
2303 -- semantic nonsense), so we get it as the parser left it.
2305 elsif Present (Arg_Parameter_Types) then
2306 Check_Matching_Types : declare
2311 Formal := First_Formal (Def_Id);
2313 if Nkind (Arg_Parameter_Types) = N_Null then
2314 if Present (Formal) then
2318 -- A list of one type, e.g. (List) is parsed as
2319 -- a parenthesized expression.
2321 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2322 and then Paren_Count (Arg_Parameter_Types) = 1
2325 or else Present (Next_Formal (Formal))
2330 Same_Base_Type (Arg_Parameter_Types, Formal);
2333 -- A list of more than one type is parsed as a aggregate
2335 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2336 and then Paren_Count (Arg_Parameter_Types) = 0
2338 Ptype := First (Expressions (Arg_Parameter_Types));
2339 while Present (Ptype) or else Present (Formal) loop
2342 or else not Same_Base_Type (Ptype, Formal)
2347 Next_Formal (Formal);
2352 -- Anything else is of the wrong form
2356 ("wrong form for Parameter_Types parameter",
2357 Arg_Parameter_Types);
2359 end Check_Matching_Types;
2362 -- Match is now False if the entry we found did not match
2363 -- either a supplied Parameter_Types or Result_Types argument
2369 -- Ambiguous case, the flag Ambiguous shows if we already
2370 -- detected this and output the initial messages.
2373 if not Ambiguous then
2375 Error_Msg_Name_1 := Chars (N);
2377 ("pragma% does not uniquely identify subprogram!",
2379 Error_Msg_Sloc := Sloc (Ent);
2380 Error_Msg_N ("matching subprogram #!", N);
2384 Error_Msg_Sloc := Sloc (Def_Id);
2385 Error_Msg_N ("matching subprogram #!", N);
2390 Hom_Id := Homonym (Hom_Id);
2393 -- See if we found an entry
2396 if not Ambiguous then
2397 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2399 ("pragma% cannot be given for generic subprogram");
2403 ("pragma% does not identify local subprogram");
2410 -- Import pragmas must be be for imported entities
2412 if Prag_Id = Pragma_Import_Function
2414 Prag_Id = Pragma_Import_Procedure
2416 Prag_Id = Pragma_Import_Valued_Procedure
2418 if not Is_Imported (Ent) then
2420 ("pragma Import or Interface must precede pragma%");
2423 -- Here we have the Export case which can set the entity as exported
2425 -- But does not do so if the specified external name is null,
2426 -- since that is taken as a signal in DEC Ada 83 (with which
2427 -- we want to be compatible) to request no external name.
2429 elsif Nkind (Arg_External) = N_String_Literal
2430 and then String_Length (Strval (Arg_External)) = 0
2434 -- In all other cases, set entit as exported
2437 Set_Exported (Ent, Arg_Internal);
2440 -- Special processing for Valued_Procedure cases
2442 if Prag_Id = Pragma_Import_Valued_Procedure
2444 Prag_Id = Pragma_Export_Valued_Procedure
2446 Formal := First_Formal (Ent);
2450 ("at least one parameter required for pragma%");
2452 elsif Ekind (Formal) /= E_Out_Parameter then
2454 ("first parameter must have mode out for pragma%");
2457 Set_Is_Valued_Procedure (Ent);
2461 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2463 -- Process Result_Mechanism argument if present. We have already
2464 -- checked that this is only allowed for the function case.
2466 if Present (Arg_Result_Mechanism) then
2467 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2470 -- Process Mechanism parameter if present. Note that this parameter
2471 -- is not analyzed, and must not be analyzed since it is semantic
2472 -- nonsense, so we get it in exactly as the parser left it.
2474 if Present (Arg_Mechanism) then
2482 -- A single mechanism association without a formal parameter
2483 -- name is parsed as a parenthesized expression. All other
2484 -- cases are parsed as aggregates, so we rewrite the single
2485 -- parameter case as an aggregate for consistency.
2487 if Nkind (Arg_Mechanism) /= N_Aggregate
2488 and then Paren_Count (Arg_Mechanism) = 1
2490 Rewrite (Arg_Mechanism,
2491 Make_Aggregate (Sloc (Arg_Mechanism),
2492 Expressions => New_List (
2493 Relocate_Node (Arg_Mechanism))));
2496 -- Case of only mechanism name given, applies to all formals
2498 if Nkind (Arg_Mechanism) /= N_Aggregate then
2499 Formal := First_Formal (Ent);
2500 while Present (Formal) loop
2501 Set_Mechanism_Value (Formal, Arg_Mechanism);
2502 Next_Formal (Formal);
2505 -- Case of list of mechanism associations given
2508 if Null_Record_Present (Arg_Mechanism) then
2510 ("inappropriate form for Mechanism parameter",
2514 -- Deal with positional ones first
2516 Formal := First_Formal (Ent);
2517 if Present (Expressions (Arg_Mechanism)) then
2518 Mname := First (Expressions (Arg_Mechanism));
2520 while Present (Mname) loop
2523 ("too many mechanism associations", Mname);
2526 Set_Mechanism_Value (Formal, Mname);
2527 Next_Formal (Formal);
2532 -- Deal with named entries
2534 if Present (Component_Associations (Arg_Mechanism)) then
2535 Massoc := First (Component_Associations (Arg_Mechanism));
2537 while Present (Massoc) loop
2538 Choice := First (Choices (Massoc));
2540 if Nkind (Choice) /= N_Identifier
2541 or else Present (Next (Choice))
2544 ("incorrect form for mechanism association",
2548 Formal := First_Formal (Ent);
2552 ("parameter name & not present", Choice);
2555 if Chars (Choice) = Chars (Formal) then
2557 (Formal, Expression (Massoc));
2561 Next_Formal (Formal);
2571 -- Process First_Optional_Parameter argument if present. We have
2572 -- already checked that this is only allowed for the Import case.
2574 if Present (Arg_First_Optional_Parameter) then
2575 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2577 ("first optional parameter must be formal parameter name",
2578 Arg_First_Optional_Parameter);
2581 Formal := First_Formal (Ent);
2585 ("specified formal parameter& not found",
2586 Arg_First_Optional_Parameter);
2589 exit when Chars (Formal) =
2590 Chars (Arg_First_Optional_Parameter);
2592 Next_Formal (Formal);
2595 Set_First_Optional_Parameter (Ent, Formal);
2597 -- Check specified and all remaining formals have right form
2599 while Present (Formal) loop
2600 if Ekind (Formal) /= E_In_Parameter then
2602 ("optional formal& is not of mode in!",
2603 Arg_First_Optional_Parameter, Formal);
2606 Dval := Default_Value (Formal);
2608 if not Present (Dval) then
2610 ("optional formal& does not have default value!",
2611 Arg_First_Optional_Parameter, Formal);
2613 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2618 ("default value for optional formal& is non-static!",
2619 Arg_First_Optional_Parameter, Formal);
2623 Set_Is_Optional_Parameter (Formal);
2624 Next_Formal (Formal);
2627 end Process_Extended_Import_Export_Subprogram_Pragma;
2629 --------------------------
2630 -- Process_Generic_List --
2631 --------------------------
2633 procedure Process_Generic_List is
2639 Check_No_Identifiers;
2640 Check_At_Least_N_Arguments (1);
2643 while Present (Arg) loop
2644 Exp := Expression (Arg);
2647 if not Is_Entity_Name (Exp)
2649 (not Is_Generic_Instance (Entity (Exp))
2651 not Is_Generic_Unit (Entity (Exp)))
2654 ("pragma% argument must be name of generic unit/instance",
2660 end Process_Generic_List;
2662 ---------------------------------
2663 -- Process_Import_Or_Interface --
2664 ---------------------------------
2666 procedure Process_Import_Or_Interface is
2672 Process_Convention (C, Def_Id);
2673 Kill_Size_Check_Code (Def_Id);
2674 Note_Possible_Modification (Expression (Arg2));
2676 if Ekind (Def_Id) = E_Variable
2678 Ekind (Def_Id) = E_Constant
2680 -- User initialization is not allowed for imported object, but
2681 -- the object declaration may contain a default initialization,
2682 -- that will be discarded. Note that an explicit initialization
2683 -- only counts if it comes from source, otherwise it is simply
2684 -- the code generator making an implicit initialization explicit.
2686 if Present (Expression (Parent (Def_Id)))
2687 and then Comes_From_Source (Expression (Parent (Def_Id)))
2689 Error_Msg_Sloc := Sloc (Def_Id);
2691 ("no initialization allowed for declaration of& #",
2692 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2696 Set_Imported (Def_Id);
2697 Set_Is_Public (Def_Id);
2698 Process_Interface_Name (Def_Id, Arg3, Arg4);
2700 -- It is not possible to import a constant of an unconstrained
2701 -- array type (e.g. string) because there is no simple way to
2702 -- write a meaningful subtype for it.
2704 if Is_Array_Type (Etype (Def_Id))
2705 and then not Is_Constrained (Etype (Def_Id))
2708 ("imported constant& must have a constrained subtype",
2713 elsif Is_Subprogram (Def_Id)
2714 or else Is_Generic_Subprogram (Def_Id)
2716 -- If the name is overloaded, pragma applies to all of the
2717 -- denoted entities in the same declarative part.
2721 while Present (Hom_Id) loop
2722 Def_Id := Get_Base_Subprogram (Hom_Id);
2724 -- Ignore inherited subprograms because the pragma will
2725 -- apply to the parent operation, which is the one called.
2727 if Is_Overloadable (Def_Id)
2728 and then Present (Alias (Def_Id))
2732 -- If it is not a subprogram, it must be in an outer
2733 -- scope and pragma does not apply.
2735 elsif not Is_Subprogram (Def_Id)
2736 and then not Is_Generic_Subprogram (Def_Id)
2740 -- Verify that the homonym is in the same declarative
2741 -- part (not just the same scope).
2743 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2744 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2749 Set_Imported (Def_Id);
2751 -- If Import intrinsic, set intrinsic flag
2752 -- and verify that it is known as such.
2754 if C = Convention_Intrinsic then
2755 Set_Is_Intrinsic_Subprogram (Def_Id);
2756 Check_Intrinsic_Subprogram
2757 (Def_Id, Expression (Arg2));
2760 -- All interfaced procedures need an external
2761 -- symbol created for them since they are
2762 -- always referenced from another object file.
2764 Set_Is_Public (Def_Id);
2766 -- Verify that the subprogram does not have a completion
2767 -- through a renaming declaration. For other completions
2768 -- the pragma appears as a too late representation.
2771 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
2775 and then Nkind (Decl) = N_Subprogram_Declaration
2776 and then Present (Corresponding_Body (Decl))
2779 (Unit_Declaration_Node
2780 (Corresponding_Body (Decl))) =
2781 N_Subprogram_Renaming_Declaration
2783 Error_Msg_Sloc := Sloc (Def_Id);
2784 Error_Msg_NE ("cannot import&#," &
2785 " already completed by a renaming",
2790 Set_Has_Completion (Def_Id);
2791 Process_Interface_Name (Def_Id, Arg3, Arg4);
2794 if Is_Compilation_Unit (Hom_Id) then
2796 -- Its possible homonyms are not affected by the pragma.
2797 -- Such homonyms might be present in the context of other
2798 -- units being compiled.
2803 Hom_Id := Homonym (Hom_Id);
2807 -- When the convention is Java, we also allow Import to be given
2808 -- for packages, exceptions, and record components.
2810 elsif C = Convention_Java
2812 (Ekind (Def_Id) = E_Package
2813 or else Ekind (Def_Id) = E_Exception
2814 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
2816 Set_Imported (Def_Id);
2817 Set_Is_Public (Def_Id);
2818 Process_Interface_Name (Def_Id, Arg3, Arg4);
2822 ("second argument of pragma% must be object or subprogram",
2826 -- If this pragma applies to a compilation unit, then the unit,
2827 -- which is a subprogram, does not require (or allow) a body.
2828 -- We also do not need to elaborate imported procedures.
2830 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2832 Cunit : constant Node_Id := Parent (Parent (N));
2834 Set_Body_Required (Cunit, False);
2837 end Process_Import_Or_Interface;
2839 --------------------
2840 -- Process_Inline --
2841 --------------------
2843 procedure Process_Inline (Active : Boolean) is
2849 Effective : Boolean := False;
2851 procedure Make_Inline (Subp : Entity_Id);
2852 -- Subp is the defining unit name of the subprogram
2853 -- declaration. Set the flag, as well as the flag in the
2854 -- corresponding body, if there is one present.
2856 procedure Set_Inline_Flags (Subp : Entity_Id);
2857 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
2859 function Back_End_Cannot_Inline (Subp : Entity_Id) return Boolean;
2860 -- Do not set the inline flag if body is available and contains
2861 -- exception handlers, to prevent undefined symbols at link time.
2863 ----------------------------
2864 -- Back_End_Cannot_Inline --
2865 ----------------------------
2867 function Back_End_Cannot_Inline (Subp : Entity_Id) return Boolean is
2868 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
2871 if Nkind (Decl) = N_Subprogram_Body then
2874 (Exception_Handlers (Handled_Statement_Sequence (Decl)));
2876 elsif Nkind (Decl) = N_Subprogram_Declaration
2877 and then Present (Corresponding_Body (Decl))
2879 -- If the subprogram is a renaming as body, the body is
2880 -- just a call to the renamed subprogram, and inlining is
2881 -- trivially possible.
2883 if Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
2884 N_Subprogram_Renaming_Declaration
2890 Present (Exception_Handlers
2891 (Handled_Statement_Sequence
2892 (Unit_Declaration_Node (Corresponding_Body (Decl)))));
2895 -- If body is not available, assume the best, the check is
2896 -- performed again when compiling enclosing package bodies.
2900 end Back_End_Cannot_Inline;
2906 procedure Make_Inline (Subp : Entity_Id) is
2907 Kind : constant Entity_Kind := Ekind (Subp);
2908 Inner_Subp : Entity_Id := Subp;
2911 if Etype (Subp) = Any_Type then
2914 elsif Back_End_Cannot_Inline (Subp) then
2915 Applies := True; -- Do not treat as an error.
2918 -- Here we have a candidate for inlining, but we must exclude
2919 -- derived operations. Otherwise we will end up trying to
2920 -- inline a phantom declaration, and the result would be to
2921 -- drag in a body which has no direct inlining associated with
2922 -- it. That would not only be inefficient but would also result
2923 -- in the backend doing cross-unit inlining in cases where it
2924 -- was definitely inappropriate to do so.
2926 -- However, a simple Comes_From_Source test is insufficient,
2927 -- since we do want to allow inlining of generic instances,
2928 -- which also do not come from source. Predefined operators do
2929 -- not come from source but are not inlineable either.
2931 elsif not Comes_From_Source (Subp)
2932 and then not Is_Generic_Instance (Subp)
2933 and then Scope (Subp) /= Standard_Standard
2938 -- The referenced entity must either be the enclosing entity,
2939 -- or an entity declared within the current open scope.
2941 elsif Present (Scope (Subp))
2942 and then Scope (Subp) /= Current_Scope
2943 and then Subp /= Current_Scope
2946 ("argument of% must be entity in current scope", Assoc);
2950 -- Processing for procedure, operator or function.
2951 -- If subprogram is aliased (as for an instance) indicate
2952 -- that the renamed entity (if declared in the same unit)
2955 if Is_Subprogram (Subp) then
2956 while Present (Alias (Inner_Subp)) loop
2957 Inner_Subp := Alias (Inner_Subp);
2960 if In_Same_Source_Unit (Subp, Inner_Subp) then
2961 Set_Inline_Flags (Inner_Subp);
2963 Decl := Parent (Parent (Inner_Subp));
2965 if Nkind (Decl) = N_Subprogram_Declaration
2966 and then Present (Corresponding_Body (Decl))
2968 Set_Inline_Flags (Corresponding_Body (Decl));
2974 -- For a generic subprogram set flag as well, for use at
2975 -- the point of instantiation, to determine whether the
2976 -- body should be generated.
2978 elsif Is_Generic_Subprogram (Subp) then
2979 Set_Inline_Flags (Subp);
2982 -- Literals are by definition inlined
2984 elsif Kind = E_Enumeration_Literal then
2987 -- Anything else is an error
2991 ("expect subprogram name for pragma%", Assoc);
2995 ----------------------
2996 -- Set_Inline_Flags --
2997 ----------------------
2999 procedure Set_Inline_Flags (Subp : Entity_Id) is
3002 Set_Is_Inlined (Subp, True);
3005 if not Has_Pragma_Inline (Subp) then
3006 Set_Has_Pragma_Inline (Subp);
3007 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3008 Set_First_Rep_Item (Subp, N);
3011 end Set_Inline_Flags;
3013 -- Start of processing for Process_Inline
3016 Check_No_Identifiers;
3017 Check_At_Least_N_Arguments (1);
3020 Inline_Processing_Required := True;
3024 while Present (Assoc) loop
3025 Subp_Id := Expression (Assoc);
3029 if Is_Entity_Name (Subp_Id) then
3030 Subp := Entity (Subp_Id);
3032 if Subp = Any_Id then
3038 while Present (Homonym (Subp))
3039 and then Scope (Homonym (Subp)) = Current_Scope
3041 Make_Inline (Homonym (Subp));
3042 Subp := Homonym (Subp);
3049 ("inappropriate argument for pragma%", Assoc);
3052 and then Warn_On_Redundant_Constructs
3054 Error_Msg_NE ("pragma inline on& is redundant?",
3055 N, Entity (Subp_Id));
3062 ----------------------------
3063 -- Process_Interface_Name --
3064 ----------------------------
3066 procedure Process_Interface_Name
3067 (Subprogram_Def : Entity_Id;
3073 String_Val : String_Id;
3075 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3076 -- SN is a string literal node for an interface name. This routine
3077 -- performs some minimal checks that the name is reasonable. In
3078 -- particular that no spaces or other obviously incorrect characters
3079 -- appear. This is only a warning, since any characters are allowed.
3081 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3082 S : constant String_Id := Strval (Expr_Value_S (SN));
3083 SL : constant Nat := String_Length (S);
3088 Error_Msg_N ("interface name cannot be null string", SN);
3091 for J in 1 .. SL loop
3092 C := Get_String_Char (S, J);
3094 if Warn_On_Export_Import
3095 and then (not In_Character_Range (C)
3096 or else Get_Character (C) = ' '
3097 or else Get_Character (C) = ',')
3100 ("?interface name contains illegal character", SN);
3103 end Check_Form_Of_Interface_Name;
3105 -- Start of processing for Process_Interface_Name
3108 if No (Link_Arg) then
3109 if No (Ext_Arg) then
3112 elsif Chars (Ext_Arg) = Name_Link_Name then
3114 Link_Nam := Expression (Ext_Arg);
3117 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3118 Ext_Nam := Expression (Ext_Arg);
3123 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3124 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3125 Ext_Nam := Expression (Ext_Arg);
3126 Link_Nam := Expression (Link_Arg);
3129 -- Check expressions for external name and link name are static
3131 if Present (Ext_Nam) then
3132 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3133 Check_Form_Of_Interface_Name (Ext_Nam);
3135 -- Verify that the external name is not the name of a local
3136 -- entity, which would hide the imported one and lead to
3137 -- run-time surprises. The problem can only arise for entities
3138 -- declared in a package body (otherwise the external name is
3139 -- fully qualified and won't conflict).
3147 if Prag_Id = Pragma_Import then
3148 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3150 E := Entity_Id (Get_Name_Table_Info (Nam));
3152 if Nam /= Chars (Subprogram_Def)
3153 and then Present (E)
3154 and then not Is_Overloadable (E)
3155 and then Is_Immediately_Visible (E)
3156 and then not Is_Imported (E)
3157 and then Ekind (Scope (E)) = E_Package
3161 while Present (Par) loop
3162 if Nkind (Par) = N_Package_Body then
3163 Error_Msg_Sloc := Sloc (E);
3165 ("imported entity is hidden by & declared#",
3170 Par := Parent (Par);
3177 if Present (Link_Nam) then
3178 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3179 Check_Form_Of_Interface_Name (Link_Nam);
3182 -- If there is no link name, just set the external name
3184 if No (Link_Nam) then
3185 Set_Encoded_Interface_Name
3186 (Get_Base_Subprogram (Subprogram_Def),
3187 Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)));
3189 -- For the Link_Name case, the given literal is preceded by an
3190 -- asterisk, which indicates to GCC that the given name should
3191 -- be taken literally, and in particular that no prepending of
3192 -- underlines should occur, even in systems where this is the
3197 Store_String_Char (Get_Char_Code ('*'));
3198 String_Val := Strval (Expr_Value_S (Link_Nam));
3200 for J in 1 .. String_Length (String_Val) loop
3201 Store_String_Char (Get_String_Char (String_Val, J));
3205 Make_String_Literal (Sloc (Link_Nam), End_String);
3207 Set_Encoded_Interface_Name
3208 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3210 end Process_Interface_Name;
3212 -----------------------------------------
3213 -- Process_Interrupt_Or_Attach_Handler --
3214 -----------------------------------------
3216 procedure Process_Interrupt_Or_Attach_Handler is
3217 Arg1_X : constant Node_Id := Expression (Arg1);
3218 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3219 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3222 Set_Is_Interrupt_Handler (Handler_Proc);
3224 -- If the pragma is not associated with a handler procedure
3225 -- within a protected type, then it must be for a nonprotected
3226 -- procedure for the AAMP target, in which case we don't
3227 -- associate a representation item with the procedure's scope.
3229 if Ekind (Proc_Scope) = E_Protected_Type then
3230 if Prag_Id = Pragma_Interrupt_Handler
3232 Prag_Id = Pragma_Attach_Handler
3234 Record_Rep_Item (Proc_Scope, N);
3237 end Process_Interrupt_Or_Attach_Handler;
3239 --------------------------------------------------
3240 -- Process_Restrictions_Or_Restriction_Warnings --
3241 --------------------------------------------------
3243 procedure Process_Restrictions_Or_Restriction_Warnings is
3245 R_Id : Restriction_Id;
3250 procedure Set_Warning (R : All_Restrictions);
3251 -- If this is a Restriction_Warnings pragma, set warning flag
3253 procedure Set_Warning (R : All_Restrictions) is
3255 if Prag_Id = Pragma_Restriction_Warnings then
3256 Restriction_Warnings (R) := True;
3260 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3263 Check_Ada_83_Warning;
3264 Check_At_Least_N_Arguments (1);
3265 Check_Valid_Configuration_Pragma;
3268 while Present (Arg) loop
3270 Expr := Expression (Arg);
3272 -- Case of no restriction identifier
3274 if Id = No_Name then
3275 if Nkind (Expr) /= N_Identifier then
3277 ("invalid form for restriction", Arg);
3279 -- Deal with synonyms. This should be done more cleanly ???
3282 -- Boolean_Entry_Barriers is a synonym of Simple_Barriers
3284 if Chars (Expr) = Name_Boolean_Entry_Barriers then
3286 (No_Implementation_Restrictions, Arg);
3287 Set_Restriction (Simple_Barriers, N);
3288 Set_Warning (Simple_Barriers);
3290 -- Max_Entry_Queue_Depth is a synonym of
3291 -- Max_Entry_Queue_Length
3293 elsif Chars (Expr) = Name_Max_Entry_Queue_Depth then
3294 Analyze_And_Resolve (Expr, Any_Integer);
3296 if not Is_OK_Static_Expression (Expr) then
3297 Flag_Non_Static_Expr
3298 ("value must be static expression!", Expr);
3301 elsif not Is_Integer_Type (Etype (Expr))
3302 or else Expr_Value (Expr) < 0
3305 ("value must be non-negative integer", Arg);
3307 -- Restriction pragma is active
3310 Val := Expr_Value (Expr);
3312 if not UI_Is_In_Int_Range (Val) then
3314 ("pragma ignored, value too large?", Arg);
3316 Set_Restriction (Max_Entry_Queue_Length, N,
3317 Integer (UI_To_Int (Val)));
3318 Set_Warning (Max_Entry_Queue_Length);
3322 -- No_Dynamic_Interrupts is a synonym for
3323 -- No_Dynamic_Attachment
3325 elsif Chars (Expr) = Name_No_Dynamic_Interrupts then
3327 (No_Implementation_Restrictions, Arg);
3328 Set_Restriction (No_Dynamic_Attachment, N);
3329 Set_Warning (No_Dynamic_Attachment);
3331 -- No_Requeue is a synonym for No_Requeue_Statements
3333 elsif Chars (Expr) = Name_No_Requeue then
3335 (No_Implementation_Restrictions, Arg);
3336 Set_Restriction (No_Requeue_Statements, N);
3337 Set_Warning (No_Requeue_Statements);
3339 -- No_Task_Attributes is a synonym for
3340 -- No_Task_Attributes_Package
3342 elsif Chars (Expr) = Name_No_Task_Attributes then
3344 (No_Implementation_Restrictions, Arg);
3345 Set_Restriction (No_Task_Attributes_Package, N);
3346 Set_Warning (No_Task_Attributes_Package);
3348 -- Normal processing for all other cases
3351 R_Id := Get_Restriction_Id (Chars (Expr));
3353 if R_Id not in All_Boolean_Restrictions then
3355 ("invalid restriction identifier", Arg);
3357 -- Restriction is active
3360 if Implementation_Restriction (R_Id) then
3362 (No_Implementation_Restrictions, Arg);
3365 Set_Restriction (R_Id, N);
3368 -- A very special case that must be processed here:
3369 -- pragma Restrictions (No_Exceptions) turns off
3370 -- all run-time checking. This is a bit dubious in
3371 -- terms of the formal language definition, but it
3372 -- is what is intended by RM H.4(12).
3374 if R_Id = No_Exceptions then
3375 Scope_Suppress := (others => True);
3381 -- Case of restriction identifier present
3384 R_Id := Get_Restriction_Id (Id);
3385 Analyze_And_Resolve (Expr, Any_Integer);
3387 if R_Id not in All_Parameter_Restrictions then
3389 ("invalid restriction parameter identifier", Arg);
3391 elsif not Is_OK_Static_Expression (Expr) then
3392 Flag_Non_Static_Expr
3393 ("value must be static expression!", Expr);
3396 elsif not Is_Integer_Type (Etype (Expr))
3397 or else Expr_Value (Expr) < 0
3400 ("value must be non-negative integer", Arg);
3402 -- Restriction pragma is active
3405 Val := Expr_Value (Expr);
3407 if not UI_Is_In_Int_Range (Val) then
3409 ("pragma ignored, value too large?", Arg);
3411 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3419 end Process_Restrictions_Or_Restriction_Warnings;
3421 ---------------------------------
3422 -- Process_Suppress_Unsuppress --
3423 ---------------------------------
3425 -- Note: this procedure makes entries in the check suppress data
3426 -- structures managed by Sem. See spec of package Sem for full
3427 -- details on how we handle recording of check suppression.
3429 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3434 In_Package_Spec : constant Boolean :=
3435 (Ekind (Current_Scope) = E_Package
3437 Ekind (Current_Scope) = E_Generic_Package)
3438 and then not In_Package_Body (Current_Scope);
3440 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3441 -- Used to suppress a single check on the given entity
3443 --------------------------------
3444 -- Suppress_Unsuppress_Echeck --
3445 --------------------------------
3447 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3448 ESR : constant Entity_Check_Suppress_Record :=
3451 Suppress => Suppress_Case);
3454 Set_Checks_May_Be_Suppressed (E);
3456 if In_Package_Spec then
3457 Global_Entity_Suppress.Append (ESR);
3459 Local_Entity_Suppress.Append (ESR);
3462 -- If this is a first subtype, and the base type is distinct,
3463 -- then also set the suppress flags on the base type.
3465 if Is_First_Subtype (E)
3466 and then Etype (E) /= E
3468 Suppress_Unsuppress_Echeck (Etype (E), C);
3470 end Suppress_Unsuppress_Echeck;
3472 -- Start of processing for Process_Suppress_Unsuppress
3475 -- Suppress/Unsuppress can appear as a configuration pragma,
3476 -- or in a declarative part or a package spec (RM 11.5(5))
3478 if not Is_Configuration_Pragma then
3479 Check_Is_In_Decl_Part_Or_Package_Spec;
3482 Check_At_Least_N_Arguments (1);
3483 Check_At_Most_N_Arguments (2);
3484 Check_No_Identifier (Arg1);
3485 Check_Arg_Is_Identifier (Arg1);
3487 if not Is_Check_Name (Chars (Expression (Arg1))) then
3489 ("argument of pragma% is not valid check name", Arg1);
3491 C := Get_Check_Id (Chars (Expression (Arg1)));
3494 if Arg_Count = 1 then
3496 -- Make an entry in the local scope suppress table. This is the
3497 -- table that directly shows the current value of the scope
3498 -- suppress check for any check id value.
3500 if C = All_Checks then
3501 for J in Scope_Suppress'Range loop
3502 Scope_Suppress (J) := Suppress_Case;
3505 Scope_Suppress (C) := Suppress_Case;
3508 -- Also make an entry in the Local_Entity_Suppress table. See
3509 -- extended description in the package spec of Sem for details.
3511 Local_Entity_Suppress.Append
3514 Suppress => Suppress_Case));
3516 -- Case of two arguments present, where the check is
3517 -- suppressed for a specified entity (given as the second
3518 -- argument of the pragma)
3521 Check_Optional_Identifier (Arg2, Name_On);
3522 E_Id := Expression (Arg2);
3525 if not Is_Entity_Name (E_Id) then
3527 ("second argument of pragma% must be entity name", Arg2);
3536 -- Enforce RM 11.5(7) which requires that for a pragma that
3537 -- appears within a package spec, the named entity must be
3538 -- within the package spec. We allow the package name itself
3539 -- to be mentioned since that makes sense, although it is not
3540 -- strictly allowed by 11.5(7).
3543 and then E /= Current_Scope
3544 and then Scope (E) /= Current_Scope
3547 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3551 -- Loop through homonyms. As noted below, in the case of a package
3552 -- spec, only homonyms within the package spec are considered.
3555 Suppress_Unsuppress_Echeck (E, C);
3557 if Is_Generic_Instance (E)
3558 and then Is_Subprogram (E)
3559 and then Present (Alias (E))
3561 Suppress_Unsuppress_Echeck (Alias (E), C);
3564 -- Move to next homonym
3569 -- If we are within a package specification, the
3570 -- pragma only applies to homonyms in the same scope.
3572 exit when In_Package_Spec
3573 and then Scope (E) /= Current_Scope;
3576 end Process_Suppress_Unsuppress;
3582 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3584 if Is_Imported (E) then
3586 ("cannot export entity& that was previously imported", Arg);
3588 elsif Present (Address_Clause (E)) then
3590 ("cannot export entity& that has an address clause", Arg);
3593 Set_Is_Exported (E);
3595 -- Generate a reference for entity explicitly, because the
3596 -- identifier may be overloaded and name resolution will not
3599 Generate_Reference (E, Arg);
3601 -- Deal with exporting non-library level entity
3603 if not Is_Library_Level_Entity (E) then
3605 -- Not allowed at all for subprograms
3607 if Is_Subprogram (E) then
3608 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3610 -- Otherwise set public and statically allocated
3614 Set_Is_Statically_Allocated (E);
3616 -- Warn if the corresponding W flag is set and the pragma
3617 -- comes from source. The latter may not be true e.g. on
3618 -- VMS where we expand export pragmas for exception codes
3619 -- associated with imported or exported exceptions. We do
3620 -- not want to generate a warning for something that the
3621 -- user did not write.
3623 if Warn_On_Export_Import
3624 and then Comes_From_Source (Arg)
3627 ("?& has been made static as a result of Export", Arg, E);
3629 ("\this usage is non-standard and non-portable", Arg);
3634 if Warn_On_Export_Import and then Is_Type (E) then
3636 ("exporting a type has no effect?", Arg, E);
3639 if Warn_On_Export_Import and Inside_A_Generic then
3641 ("all instances of& will have the same external name?", Arg, E);
3645 ----------------------------------------------
3646 -- Set_Extended_Import_Export_External_Name --
3647 ----------------------------------------------
3649 procedure Set_Extended_Import_Export_External_Name
3650 (Internal_Ent : Entity_Id;
3651 Arg_External : Node_Id)
3653 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3657 if No (Arg_External) then
3660 elsif Nkind (Arg_External) = N_String_Literal then
3661 if String_Length (Strval (Arg_External)) = 0 then
3664 New_Name := Adjust_External_Name_Case (Arg_External);
3667 elsif Nkind (Arg_External) = N_Identifier then
3668 New_Name := Get_Default_External_Name (Arg_External);
3672 ("incorrect form for External parameter for pragma%",
3676 -- If we already have an external name set (by a prior normal
3677 -- Import or Export pragma), then the external names must match
3679 if Present (Interface_Name (Internal_Ent)) then
3681 S1 : constant String_Id := Strval (Old_Name);
3682 S2 : constant String_Id := Strval (New_Name);
3685 -- Called if names do not match
3687 procedure Mismatch is
3689 Error_Msg_Sloc := Sloc (Old_Name);
3691 ("external name does not match that given #",
3696 if String_Length (S1) /= String_Length (S2) then
3700 for J in 1 .. String_Length (S1) loop
3701 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3708 -- Otherwise set the given name
3711 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3714 end Set_Extended_Import_Export_External_Name;
3720 procedure Set_Imported (E : Entity_Id) is
3722 Error_Msg_Sloc := Sloc (E);
3724 if Is_Exported (E) or else Is_Imported (E) then
3725 Error_Msg_NE ("import of& declared# not allowed", N, E);
3727 if Is_Exported (E) then
3728 Error_Msg_N ("\entity was previously exported", N);
3730 Error_Msg_N ("\entity was previously imported", N);
3733 Error_Pragma ("\(pragma% applies to all previous entities)");
3736 Set_Is_Imported (E);
3738 -- If the entity is an object that is not at the library
3739 -- level, then it is statically allocated. We do not worry
3740 -- about objects with address clauses in this context since
3741 -- they are not really imported in the linker sense.
3744 and then not Is_Library_Level_Entity (E)
3745 and then No (Address_Clause (E))
3747 Set_Is_Statically_Allocated (E);
3752 -------------------------
3753 -- Set_Mechanism_Value --
3754 -------------------------
3756 -- Note: the mechanism name has not been analyzed (and cannot indeed
3757 -- be analyzed, since it is semantic nonsense), so we get it in the
3758 -- exact form created by the parser.
3760 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3764 procedure Bad_Class;
3765 -- Signal bad descriptor class name
3767 procedure Bad_Mechanism;
3768 -- Signal bad mechanism name
3770 procedure Bad_Class is
3772 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3775 procedure Bad_Mechanism is
3777 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3780 -- Start of processing for Set_Mechanism_Value
3783 if Mechanism (Ent) /= Default_Mechanism then
3785 ("mechanism for & has already been set", Mech_Name, Ent);
3788 -- MECHANISM_NAME ::= value | reference | descriptor
3790 if Nkind (Mech_Name) = N_Identifier then
3791 if Chars (Mech_Name) = Name_Value then
3792 Set_Mechanism (Ent, By_Copy);
3795 elsif Chars (Mech_Name) = Name_Reference then
3796 Set_Mechanism (Ent, By_Reference);
3799 elsif Chars (Mech_Name) = Name_Descriptor then
3800 Check_VMS (Mech_Name);
3801 Set_Mechanism (Ent, By_Descriptor);
3804 elsif Chars (Mech_Name) = Name_Copy then
3806 ("bad mechanism name, Value assumed", Mech_Name);
3812 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3813 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3815 -- Note: this form is parsed as an indexed component
3817 elsif Nkind (Mech_Name) = N_Indexed_Component then
3818 Class := First (Expressions (Mech_Name));
3820 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3821 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3822 or else Present (Next (Class))
3827 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3828 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3830 -- Note: this form is parsed as a function call
3832 elsif Nkind (Mech_Name) = N_Function_Call then
3834 Param := First (Parameter_Associations (Mech_Name));
3836 if Nkind (Name (Mech_Name)) /= N_Identifier
3837 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3838 or else Present (Next (Param))
3839 or else No (Selector_Name (Param))
3840 or else Chars (Selector_Name (Param)) /= Name_Class
3844 Class := Explicit_Actual_Parameter (Param);
3851 -- Fall through here with Class set to descriptor class name
3853 Check_VMS (Mech_Name);
3855 if Nkind (Class) /= N_Identifier then
3858 elsif Chars (Class) = Name_UBS then
3859 Set_Mechanism (Ent, By_Descriptor_UBS);
3861 elsif Chars (Class) = Name_UBSB then
3862 Set_Mechanism (Ent, By_Descriptor_UBSB);
3864 elsif Chars (Class) = Name_UBA then
3865 Set_Mechanism (Ent, By_Descriptor_UBA);
3867 elsif Chars (Class) = Name_S then
3868 Set_Mechanism (Ent, By_Descriptor_S);
3870 elsif Chars (Class) = Name_SB then
3871 Set_Mechanism (Ent, By_Descriptor_SB);
3873 elsif Chars (Class) = Name_A then
3874 Set_Mechanism (Ent, By_Descriptor_A);
3876 elsif Chars (Class) = Name_NCA then
3877 Set_Mechanism (Ent, By_Descriptor_NCA);
3883 end Set_Mechanism_Value;
3885 -- Start of processing for Analyze_Pragma
3888 if not Is_Pragma_Name (Chars (N)) then
3889 if Warn_On_Unrecognized_Pragma then
3890 Error_Pragma ("unrecognized pragma%!?");
3895 Prag_Id := Get_Pragma_Id (Chars (N));
3905 if Present (Pragma_Argument_Associations (N)) then
3906 Arg1 := First (Pragma_Argument_Associations (N));
3908 if Present (Arg1) then
3909 Arg2 := Next (Arg1);
3911 if Present (Arg2) then
3912 Arg3 := Next (Arg2);
3914 if Present (Arg3) then
3915 Arg4 := Next (Arg3);
3921 -- Count number of arguments
3928 while Present (Arg_Node) loop
3929 Arg_Count := Arg_Count + 1;
3934 -- An enumeration type defines the pragmas that are supported by the
3935 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
3936 -- into the corresponding enumeration value for the following case.
3944 -- pragma Abort_Defer;
3946 when Pragma_Abort_Defer =>
3948 Check_Arg_Count (0);
3950 -- The only required semantic processing is to check the
3951 -- placement. This pragma must appear at the start of the
3952 -- statement sequence of a handled sequence of statements.
3954 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
3955 or else N /= First (Statements (Parent (N)))
3966 -- Note: this pragma also has some specific processing in Par.Prag
3967 -- because we want to set the Ada 83 mode switch during parsing.
3969 when Pragma_Ada_83 =>
3973 Check_Arg_Count (0);
3981 -- Note: this pragma also has some specific processing in Par.Prag
3982 -- because we want to set the Ada 83 mode switch during parsing.
3984 when Pragma_Ada_95 =>
3988 Check_Arg_Count (0);
3990 ----------------------
3991 -- All_Calls_Remote --
3992 ----------------------
3994 -- pragma All_Calls_Remote [(library_package_NAME)];
3996 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
3997 Lib_Entity : Entity_Id;
4000 Check_Ada_83_Warning;
4001 Check_Valid_Library_Unit_Pragma;
4003 if Nkind (N) = N_Null_Statement then
4007 Lib_Entity := Find_Lib_Unit_Name;
4009 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4011 if Present (Lib_Entity)
4012 and then not Debug_Flag_U
4014 if not Is_Remote_Call_Interface (Lib_Entity) then
4015 Error_Pragma ("pragma% only apply to rci unit");
4017 -- Set flag for entity of the library unit
4020 Set_Has_All_Calls_Remote (Lib_Entity);
4024 end All_Calls_Remote;
4030 -- pragma Annotate (IDENTIFIER {, ARG});
4031 -- ARG ::= NAME | EXPRESSION
4033 when Pragma_Annotate => Annotate : begin
4035 Check_At_Least_N_Arguments (1);
4036 Check_Arg_Is_Identifier (Arg1);
4039 Arg : Node_Id := Arg2;
4043 while Present (Arg) loop
4044 Exp := Expression (Arg);
4047 if Is_Entity_Name (Exp) then
4050 elsif Nkind (Exp) = N_String_Literal then
4051 Resolve (Exp, Standard_String);
4053 elsif Is_Overloaded (Exp) then
4054 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4069 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
4071 when Pragma_Assert =>
4073 Check_No_Identifiers;
4075 if Arg_Count > 1 then
4076 Check_Arg_Count (2);
4077 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4080 -- If expansion is active and assertions are inactive, then
4081 -- we rewrite the Assertion as:
4083 -- if False and then condition then
4087 -- The reason we do this rewriting during semantic analysis
4088 -- rather than as part of normal expansion is that we cannot
4089 -- analyze and expand the code for the boolean expression
4090 -- directly, or it may cause insertion of actions that would
4091 -- escape the attempt to suppress the assertion code.
4093 if Expander_Active and not Assertions_Enabled then
4095 Make_If_Statement (Loc,
4098 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4099 Right_Opnd => Get_Pragma_Arg (Arg1)),
4100 Then_Statements => New_List (
4101 Make_Null_Statement (Loc))));
4105 -- Otherwise (if assertions are enabled, or if we are not
4106 -- operating with expansion active), then we just analyze
4107 -- and resolve the expression.
4110 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4117 -- pragma AST_Entry (entry_IDENTIFIER);
4119 when Pragma_AST_Entry => AST_Entry : declare
4125 Check_Arg_Count (1);
4126 Check_No_Identifiers;
4127 Check_Arg_Is_Local_Name (Arg1);
4128 Ent := Entity (Expression (Arg1));
4130 -- Note: the implementation of the AST_Entry pragma could handle
4131 -- the entry family case fine, but for now we are consistent with
4132 -- the DEC rules, and do not allow the pragma, which of course
4133 -- has the effect of also forbidding the attribute.
4135 if Ekind (Ent) /= E_Entry then
4137 ("pragma% argument must be simple entry name", Arg1);
4139 elsif Is_AST_Entry (Ent) then
4141 ("duplicate % pragma for entry", Arg1);
4143 elsif Has_Homonym (Ent) then
4145 ("pragma% argument cannot specify overloaded entry", Arg1);
4149 FF : constant Entity_Id := First_Formal (Ent);
4152 if Present (FF) then
4153 if Present (Next_Formal (FF)) then
4155 ("entry for pragma% can have only one argument",
4158 elsif Parameter_Mode (FF) /= E_In_Parameter then
4160 ("entry parameter for pragma% must have mode IN",
4166 Set_Is_AST_Entry (Ent);
4174 -- pragma Asynchronous (LOCAL_NAME);
4176 when Pragma_Asynchronous => Asynchronous : declare
4184 procedure Process_Async_Pragma;
4185 -- Common processing for procedure and access-to-procedure case
4187 --------------------------
4188 -- Process_Async_Pragma --
4189 --------------------------
4191 procedure Process_Async_Pragma is
4193 if not Present (L) then
4194 Set_Is_Asynchronous (Nm);
4198 -- The formals should be of mode IN (RM E.4.1(6))
4201 while Present (S) loop
4202 Formal := Defining_Identifier (S);
4204 if Nkind (Formal) = N_Defining_Identifier
4205 and then Ekind (Formal) /= E_In_Parameter
4208 ("pragma% procedure can only have IN parameter",
4215 Set_Is_Asynchronous (Nm);
4216 end Process_Async_Pragma;
4218 -- Start of processing for pragma Asynchronous
4221 Check_Ada_83_Warning;
4222 Check_No_Identifiers;
4223 Check_Arg_Count (1);
4224 Check_Arg_Is_Local_Name (Arg1);
4226 if Debug_Flag_U then
4230 C_Ent := Cunit_Entity (Current_Sem_Unit);
4231 Analyze (Expression (Arg1));
4232 Nm := Entity (Expression (Arg1));
4234 if not Is_Remote_Call_Interface (C_Ent)
4235 and then not Is_Remote_Types (C_Ent)
4237 -- This pragma should only appear in an RCI or Remote Types
4238 -- unit (RM E.4.1(4))
4241 ("pragma% not in Remote_Call_Interface or " &
4242 "Remote_Types unit");
4245 if Ekind (Nm) = E_Procedure
4246 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4248 if not Is_Remote_Call_Interface (Nm) then
4250 ("pragma% cannot be applied on non-remote procedure",
4254 L := Parameter_Specifications (Parent (Nm));
4255 Process_Async_Pragma;
4258 elsif Ekind (Nm) = E_Function then
4260 ("pragma% cannot be applied to function", Arg1);
4262 elsif Ekind (Nm) = E_Record_Type
4263 and then Present (Corresponding_Remote_Type (Nm))
4265 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4267 if Nkind (N) = N_Full_Type_Declaration
4268 and then Nkind (Type_Definition (N)) =
4269 N_Access_Procedure_Definition
4271 L := Parameter_Specifications (Type_Definition (N));
4272 Process_Async_Pragma;
4276 ("pragma% cannot reference access-to-function type",
4280 -- Only other possibility is Access-to-class-wide type
4282 elsif Is_Access_Type (Nm)
4283 and then Is_Class_Wide_Type (Designated_Type (Nm))
4285 Check_First_Subtype (Arg1);
4286 Set_Is_Asynchronous (Nm);
4287 if Expander_Active then
4288 RACW_Type_Is_Asynchronous (Nm);
4292 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4300 -- pragma Atomic (LOCAL_NAME);
4302 when Pragma_Atomic =>
4303 Process_Atomic_Shared_Volatile;
4305 -----------------------
4306 -- Atomic_Components --
4307 -----------------------
4309 -- pragma Atomic_Components (array_LOCAL_NAME);
4311 -- This processing is shared by Volatile_Components
4313 when Pragma_Atomic_Components |
4314 Pragma_Volatile_Components =>
4316 Atomic_Components : declare
4323 Check_Ada_83_Warning;
4324 Check_No_Identifiers;
4325 Check_Arg_Count (1);
4326 Check_Arg_Is_Local_Name (Arg1);
4327 E_Id := Expression (Arg1);
4329 if Etype (E_Id) = Any_Type then
4335 if Rep_Item_Too_Early (E, N)
4337 Rep_Item_Too_Late (E, N)
4342 D := Declaration_Node (E);
4345 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4347 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4348 and then Nkind (D) = N_Object_Declaration
4349 and then Nkind (Object_Definition (D)) =
4350 N_Constrained_Array_Definition)
4352 -- The flag is set on the object, or on the base type
4354 if Nkind (D) /= N_Object_Declaration then
4358 Set_Has_Volatile_Components (E);
4360 if Prag_Id = Pragma_Atomic_Components then
4361 Set_Has_Atomic_Components (E);
4363 if Is_Packed (E) then
4364 Set_Is_Packed (E, False);
4367 ("?Pack canceled, cannot pack atomic components",
4373 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4375 end Atomic_Components;
4377 --------------------
4378 -- Attach_Handler --
4379 --------------------
4381 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4383 when Pragma_Attach_Handler =>
4384 Check_Ada_83_Warning;
4385 Check_No_Identifiers;
4386 Check_Arg_Count (2);
4388 if No_Run_Time_Mode then
4389 Error_Msg_CRT ("Attach_Handler pragma", N);
4391 Check_Interrupt_Or_Attach_Handler;
4393 -- The expression that designates the attribute may
4394 -- depend on a discriminant, and is therefore a per-
4395 -- object expression, to be expanded in the init proc.
4396 -- If expansion is enabled, perform semantic checks
4399 if Expander_Active then
4401 Temp : constant Node_Id :=
4402 New_Copy_Tree (Expression (Arg2));
4404 Set_Parent (Temp, N);
4405 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4409 Analyze (Expression (Arg2));
4410 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4413 Process_Interrupt_Or_Attach_Handler;
4416 --------------------
4417 -- C_Pass_By_Copy --
4418 --------------------
4420 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4422 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4428 Check_Valid_Configuration_Pragma;
4429 Check_Arg_Count (1);
4430 Check_Optional_Identifier (Arg1, "max_size");
4432 Arg := Expression (Arg1);
4433 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4435 Val := Expr_Value (Arg);
4439 ("maximum size for pragma% must be positive", Arg1);
4441 elsif UI_Is_In_Int_Range (Val) then
4442 Default_C_Record_Mechanism := UI_To_Int (Val);
4444 -- If a giant value is given, Int'Last will do well enough.
4445 -- If sometime someone complains that a record larger than
4446 -- two gigabytes is not copied, we will worry about it then!
4449 Default_C_Record_Mechanism := Mechanism_Type'Last;
4457 -- pragma Comment (static_string_EXPRESSION)
4459 -- Processing for pragma Comment shares the circuitry for
4460 -- pragma Ident. The only differences are that Ident enforces
4461 -- a limit of 31 characters on its argument, and also enforces
4462 -- limitations on placement for DEC compatibility. Pragma
4463 -- Comment shares neither of these restrictions.
4469 -- pragma Common_Object (
4470 -- [Internal =>] LOCAL_NAME,
4471 -- [, [External =>] EXTERNAL_SYMBOL]
4472 -- [, [Size =>] EXTERNAL_SYMBOL]);
4474 -- Processing for this pragma is shared with Psect_Object
4476 --------------------------
4477 -- Compile_Time_Warning --
4478 --------------------------
4480 -- pragma Compile_Time_Warning
4481 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4483 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4484 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4488 Check_Arg_Count (2);
4489 Check_No_Identifiers;
4490 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4491 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4493 if Compile_Time_Known_Value (Arg1x) then
4494 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4495 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4496 Add_Char_To_Name_Buffer ('?');
4499 Msg : String (1 .. Name_Len) :=
4500 Name_Buffer (1 .. Name_Len);
4505 -- This loop looks for multiple lines separated by
4506 -- ASCII.LF and breaks them into continuation error
4507 -- messages marked with the usual back slash.
4510 for S in 2 .. Msg'Length - 1 loop
4511 if Msg (S) = ASCII.LF then
4513 Error_Msg_N (Msg (B .. S), Arg1);
4519 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4523 end Compile_Time_Warning;
4525 ----------------------------
4526 -- Complex_Representation --
4527 ----------------------------
4529 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4531 when Pragma_Complex_Representation => Complex_Representation : declare
4538 Check_Arg_Count (1);
4539 Check_Optional_Identifier (Arg1, Name_Entity);
4540 Check_Arg_Is_Local_Name (Arg1);
4541 E_Id := Expression (Arg1);
4543 if Etype (E_Id) = Any_Type then
4549 if not Is_Record_Type (E) then
4551 ("argument for pragma% must be record type", Arg1);
4554 Ent := First_Entity (E);
4557 or else No (Next_Entity (Ent))
4558 or else Present (Next_Entity (Next_Entity (Ent)))
4559 or else not Is_Floating_Point_Type (Etype (Ent))
4560 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4563 ("record for pragma% must have two fields of same fpt type",
4567 Set_Has_Complex_Representation (Base_Type (E));
4569 end Complex_Representation;
4571 -------------------------
4572 -- Component_Alignment --
4573 -------------------------
4575 -- pragma Component_Alignment (
4576 -- [Form =>] ALIGNMENT_CHOICE
4577 -- [, [Name =>] type_LOCAL_NAME]);
4579 -- ALIGNMENT_CHOICE ::=
4581 -- | Component_Size_4
4585 when Pragma_Component_Alignment => Component_AlignmentP : declare
4586 Args : Args_List (1 .. 2);
4587 Names : constant Name_List (1 .. 2) := (
4591 Form : Node_Id renames Args (1);
4592 Name : Node_Id renames Args (2);
4594 Atype : Component_Alignment_Kind;
4599 Gather_Associations (Names, Args);
4602 Error_Pragma ("missing Form argument for pragma%");
4605 Check_Arg_Is_Identifier (Form);
4607 -- Get proper alignment, note that Default = Component_Size
4608 -- on all machines we have so far, and we want to set this
4609 -- value rather than the default value to indicate that it
4610 -- has been explicitly set (and thus will not get overridden
4611 -- by the default component alignment for the current scope)
4613 if Chars (Form) = Name_Component_Size then
4614 Atype := Calign_Component_Size;
4616 elsif Chars (Form) = Name_Component_Size_4 then
4617 Atype := Calign_Component_Size_4;
4619 elsif Chars (Form) = Name_Default then
4620 Atype := Calign_Component_Size;
4622 elsif Chars (Form) = Name_Storage_Unit then
4623 Atype := Calign_Storage_Unit;
4627 ("invalid Form parameter for pragma%", Form);
4630 -- Case with no name, supplied, affects scope table entry
4634 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4636 -- Case of name supplied
4639 Check_Arg_Is_Local_Name (Name);
4641 Typ := Entity (Name);
4644 or else Rep_Item_Too_Early (Typ, N)
4648 Typ := Underlying_Type (Typ);
4651 if not Is_Record_Type (Typ)
4652 and then not Is_Array_Type (Typ)
4655 ("Name parameter of pragma% must identify record or " &
4656 "array type", Name);
4659 -- An explicit Component_Alignment pragma overrides an
4660 -- implicit pragma Pack, but not an explicit one.
4662 if not Has_Pragma_Pack (Base_Type (Typ)) then
4663 Set_Is_Packed (Base_Type (Typ), False);
4664 Set_Component_Alignment (Base_Type (Typ), Atype);
4667 end Component_AlignmentP;
4673 -- pragma Controlled (first_subtype_LOCAL_NAME);
4675 when Pragma_Controlled => Controlled : declare
4679 Check_No_Identifiers;
4680 Check_Arg_Count (1);
4681 Check_Arg_Is_Local_Name (Arg1);
4682 Arg := Expression (Arg1);
4684 if not Is_Entity_Name (Arg)
4685 or else not Is_Access_Type (Entity (Arg))
4687 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4689 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4697 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4698 -- [Entity =>] LOCAL_NAME);
4700 when Pragma_Convention => Convention : declare
4704 Check_Ada_83_Warning;
4705 Check_Arg_Count (2);
4706 Process_Convention (C, E);
4709 ---------------------------
4710 -- Convention_Identifier --
4711 ---------------------------
4713 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
4714 -- [Convention =>] convention_IDENTIFIER);
4716 when Pragma_Convention_Identifier => Convention_Identifier : declare
4722 Check_Arg_Count (2);
4723 Check_Optional_Identifier (Arg1, Name_Name);
4724 Check_Optional_Identifier (Arg2, Name_Convention);
4725 Check_Arg_Is_Identifier (Arg1);
4726 Check_Arg_Is_Identifier (Arg1);
4727 Idnam := Chars (Expression (Arg1));
4728 Cname := Chars (Expression (Arg2));
4730 if Is_Convention_Name (Cname) then
4731 Record_Convention_Identifier
4732 (Idnam, Get_Convention_Id (Cname));
4735 ("second arg for % pragma must be convention", Arg2);
4737 end Convention_Identifier;
4743 -- pragma CPP_Class ([Entity =>] local_NAME)
4745 when Pragma_CPP_Class => CPP_Class : declare
4748 Default_DTC : Entity_Id := Empty;
4749 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4755 Check_Arg_Count (1);
4756 Check_Optional_Identifier (Arg1, Name_Entity);
4757 Check_Arg_Is_Local_Name (Arg1);
4759 Arg := Expression (Arg1);
4762 if Etype (Arg) = Any_Type then
4766 if not Is_Entity_Name (Arg)
4767 or else not Is_Type (Entity (Arg))
4769 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
4772 Typ := Entity (Arg);
4774 if not Is_Record_Type (Typ) then
4775 Error_Pragma_Arg ("pragma% applicable to a record, "
4776 & "tagged record or record extension", Arg1);
4779 Default_DTC := First_Component (Typ);
4780 while Present (Default_DTC)
4781 and then Etype (Default_DTC) /= VTP_Type
4783 Next_Component (Default_DTC);
4786 -- Case of non tagged type
4788 if not Is_Tagged_Type (Typ) then
4789 Set_Is_CPP_Class (Typ);
4791 if Present (Default_DTC) then
4793 ("only tagged records can contain vtable pointers", Arg1);
4796 -- Case of tagged type with no vtable ptr
4798 -- What is test for Typ = Root_Typ (Typ) about here ???
4800 elsif Is_Tagged_Type (Typ)
4801 and then Typ = Root_Type (Typ)
4802 and then No (Default_DTC)
4805 ("a cpp_class must contain a vtable pointer", Arg1);
4807 -- Tagged type that has a vtable ptr
4809 elsif Present (Default_DTC) then
4810 Set_Is_CPP_Class (Typ);
4811 Set_Is_Limited_Record (Typ);
4812 Set_Is_Tag (Default_DTC);
4813 Set_DT_Entry_Count (Default_DTC, No_Uint);
4815 -- Since a CPP type has no direct link to its associated tag
4816 -- most tags checks cannot be performed
4818 Set_Kill_Tag_Checks (Typ);
4819 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
4821 -- Get rid of the _tag component when there was one.
4822 -- It is only useful for regular tagged types
4824 if Expander_Active and then Typ = Root_Type (Typ) then
4826 Tag_C := Tag_Component (Typ);
4827 C := First_Entity (Typ);
4830 Set_First_Entity (Typ, Next_Entity (Tag_C));
4833 while Next_Entity (C) /= Tag_C loop
4837 Set_Next_Entity (C, Next_Entity (Tag_C));
4843 ---------------------
4844 -- CPP_Constructor --
4845 ---------------------
4847 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
4849 when Pragma_CPP_Constructor => CPP_Constructor : declare
4855 Check_Arg_Count (1);
4856 Check_Optional_Identifier (Arg1, Name_Entity);
4857 Check_Arg_Is_Local_Name (Arg1);
4859 Id := Expression (Arg1);
4860 Find_Program_Unit_Name (Id);
4862 -- If we did not find the name, we are done
4864 if Etype (Id) = Any_Type then
4868 Def_Id := Entity (Id);
4870 if Ekind (Def_Id) = E_Function
4871 and then Is_Class_Wide_Type (Etype (Def_Id))
4872 and then Is_CPP_Class (Etype (Etype (Def_Id)))
4874 -- What the heck is this??? this pragma allows only 1 arg
4876 if Arg_Count >= 2 then
4877 Check_At_Most_N_Arguments (3);
4878 Process_Interface_Name (Def_Id, Arg2, Arg3);
4881 if No (Parameter_Specifications (Parent (Def_Id))) then
4882 Set_Has_Completion (Def_Id);
4883 Set_Is_Constructor (Def_Id);
4886 ("non-default constructors not implemented", Arg1);
4891 ("pragma% requires function returning a 'C'P'P_Class type",
4894 end CPP_Constructor;
4900 -- pragma CPP_Virtual
4901 -- [Entity =>] LOCAL_NAME
4902 -- [ [Vtable_Ptr =>] LOCAL_NAME,
4903 -- [Position =>] static_integer_EXPRESSION]);
4905 when Pragma_CPP_Virtual => CPP_Virtual : declare
4909 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4916 if Arg_Count = 3 then
4917 Check_Optional_Identifier (Arg2, "vtable_ptr");
4919 -- We allow Entry_Count as well as Position for the third
4920 -- parameter for back compatibility with versions of GNAT
4921 -- before version 3.12. The documentation has always said
4922 -- Position, but the code up to 3.12 said Entry_Count.
4924 if Chars (Arg3) /= Name_Position then
4925 Check_Optional_Identifier (Arg3, "entry_count");
4929 Check_Arg_Count (1);
4932 Check_Optional_Identifier (Arg1, Name_Entity);
4933 Check_Arg_Is_Local_Name (Arg1);
4935 -- First argument must be a subprogram name
4937 Arg := Expression (Arg1);
4938 Find_Program_Unit_Name (Arg);
4940 if Etype (Arg) = Any_Type then
4943 Subp := Entity (Arg);
4946 if not (Is_Subprogram (Subp)
4947 and then Is_Dispatching_Operation (Subp))
4950 ("pragma% must reference a primitive operation", Arg1);
4953 Typ := Find_Dispatching_Type (Subp);
4955 -- If only one Argument defaults are :
4956 -- . DTC_Entity is the default Vtable pointer
4957 -- . DT_Position will be set at the freezing point
4959 if Arg_Count = 1 then
4960 Set_DTC_Entity (Subp, Tag_Component (Typ));
4964 -- Second argument is a component name of type Vtable_Ptr
4966 Arg := Expression (Arg2);
4968 if Nkind (Arg) /= N_Identifier then
4969 Error_Msg_NE ("must be a& component name", Arg, Typ);
4973 DTC := First_Component (Typ);
4974 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4975 Next_Component (DTC);
4979 Error_Msg_NE ("must be a& component name", Arg, Typ);
4982 elsif Etype (DTC) /= VTP_Type then
4983 Wrong_Type (Arg, VTP_Type);
4987 -- Third argument is an integer (DT_Position)
4989 Arg := Expression (Arg3);
4990 Analyze_And_Resolve (Arg, Any_Integer);
4992 if not Is_Static_Expression (Arg) then
4993 Flag_Non_Static_Expr
4994 ("third argument of pragma CPP_Virtual must be static!",
4999 V := Expr_Value (Expression (Arg3));
5003 ("third argument of pragma% must be positive",
5007 Set_DTC_Entity (Subp, DTC);
5008 Set_DT_Position (Subp, V);
5017 -- pragma CPP_Vtable (
5018 -- [Entity =>] LOCAL_NAME
5019 -- [Vtable_Ptr =>] LOCAL_NAME,
5020 -- [Entry_Count =>] static_integer_EXPRESSION);
5022 when Pragma_CPP_Vtable => CPP_Vtable : declare
5025 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5032 Check_Arg_Count (3);
5033 Check_Optional_Identifier (Arg1, Name_Entity);
5034 Check_Optional_Identifier (Arg2, "vtable_ptr");
5035 Check_Optional_Identifier (Arg3, "entry_count");
5036 Check_Arg_Is_Local_Name (Arg1);
5038 -- First argument is a record type name
5040 Arg := Expression (Arg1);
5043 if Etype (Arg) = Any_Type then
5046 Typ := Entity (Arg);
5049 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5050 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5053 -- Second argument is a component name of type Vtable_Ptr
5055 Arg := Expression (Arg2);
5057 if Nkind (Arg) /= N_Identifier then
5058 Error_Msg_NE ("must be a& component name", Arg, Typ);
5062 DTC := First_Component (Typ);
5063 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5064 Next_Component (DTC);
5068 Error_Msg_NE ("must be a& component name", Arg, Typ);
5071 elsif Etype (DTC) /= VTP_Type then
5072 Wrong_Type (DTC, VTP_Type);
5075 -- If it is the first pragma Vtable, This becomes the default tag
5077 elsif (not Is_Tag (DTC))
5078 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
5080 Set_Is_Tag (Tag_Component (Typ), False);
5081 Set_Is_Tag (DTC, True);
5082 Set_DT_Entry_Count (DTC, No_Uint);
5085 -- Those pragmas must appear before any primitive operation
5086 -- definition (except inherited ones) otherwise the default
5089 Elmt := First_Elmt (Primitive_Operations (Typ));
5090 while Present (Elmt) loop
5091 if No (Alias (Node (Elmt))) then
5092 Error_Msg_Sloc := Sloc (Node (Elmt));
5094 ("pragma% must appear before this primitive operation");
5100 -- Third argument is an integer (DT_Entry_Count)
5102 Arg := Expression (Arg3);
5103 Analyze_And_Resolve (Arg, Any_Integer);
5105 if not Is_Static_Expression (Arg) then
5106 Flag_Non_Static_Expr
5107 ("entry count for pragma CPP_Vtable must be a static " &
5108 "expression!", Arg3);
5112 V := Expr_Value (Expression (Arg3));
5116 ("entry count for pragma% must be positive", Arg3);
5118 Set_DT_Entry_Count (DTC, V);
5127 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5129 when Pragma_Debug => Debug : begin
5132 -- If assertions are enabled, and we are expanding code, then
5133 -- we rewrite the pragma with its corresponding procedure call
5134 -- and then analyze the call.
5136 if Assertions_Enabled and Expander_Active then
5137 Rewrite (N, Relocate_Node (Debug_Statement (N)));
5140 -- Otherwise we work a bit to get a tree that makes sense
5141 -- for ASIS purposes, namely a pragma with an analyzed
5142 -- argument that looks like a procedure call.
5145 Expander_Mode_Save_And_Set (False);
5146 Rewrite (N, Relocate_Node (Debug_Statement (N)));
5150 Chars => Name_Debug,
5151 Pragma_Argument_Associations =>
5152 New_List (Relocate_Node (N))));
5153 Expander_Mode_Restore;
5161 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5163 when Pragma_Discard_Names => Discard_Names : declare
5168 Check_Ada_83_Warning;
5170 -- Deal with configuration pragma case
5172 if Arg_Count = 0 and then Is_Configuration_Pragma then
5173 Global_Discard_Names := True;
5176 -- Otherwise, check correct appropriate context
5179 Check_Is_In_Decl_Part_Or_Package_Spec;
5181 if Arg_Count = 0 then
5183 -- If there is no parameter, then from now on this pragma
5184 -- applies to any enumeration, exception or tagged type
5185 -- defined in the current declarative part.
5187 Set_Discard_Names (Current_Scope);
5191 Check_Arg_Count (1);
5192 Check_Optional_Identifier (Arg1, Name_On);
5193 Check_Arg_Is_Local_Name (Arg1);
5194 E_Id := Expression (Arg1);
5196 if Etype (E_Id) = Any_Type then
5202 if (Is_First_Subtype (E)
5203 and then (Is_Enumeration_Type (E)
5204 or else Is_Tagged_Type (E)))
5205 or else Ekind (E) = E_Exception
5207 Set_Discard_Names (E);
5210 ("inappropriate entity for pragma%", Arg1);
5220 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5222 when Pragma_Elaborate => Elaborate : declare
5224 Parent_Node : Node_Id;
5229 -- Pragma must be in context items list of a compilation unit
5231 if not Is_List_Member (N) then
5236 Plist := List_Containing (N);
5237 Parent_Node := Parent (Plist);
5239 if Parent_Node = Empty
5240 or else Nkind (Parent_Node) /= N_Compilation_Unit
5241 or else Context_Items (Parent_Node) /= Plist
5248 -- Must be at least one argument
5250 if Arg_Count = 0 then
5251 Error_Pragma ("pragma% requires at least one argument");
5254 -- In Ada 83 mode, there can be no items following it in the
5255 -- context list except other pragmas and implicit with clauses
5256 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5257 -- placement rule does not apply.
5259 if Ada_83 and then Comes_From_Source (N) then
5262 while Present (Citem) loop
5263 if Nkind (Citem) = N_Pragma
5264 or else (Nkind (Citem) = N_With_Clause
5265 and then Implicit_With (Citem))
5270 ("(Ada 83) pragma% must be at end of context clause");
5277 -- Finally, the arguments must all be units mentioned in a with
5278 -- clause in the same context clause. Note we already checked
5279 -- (in Par.Prag) that the arguments are either identifiers or
5282 Outer : while Present (Arg) loop
5283 Citem := First (Plist);
5285 Inner : while Citem /= N loop
5286 if Nkind (Citem) = N_With_Clause
5287 and then Same_Name (Name (Citem), Expression (Arg))
5289 Set_Elaborate_Present (Citem, True);
5290 Set_Unit_Name (Expression (Arg), Name (Citem));
5291 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5300 ("argument of pragma% is not with'ed unit", Arg);
5306 -- Give a warning if operating in static mode with -gnatwl
5307 -- (elaboration warnings eanbled) switch set.
5309 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5311 ("?use of pragma Elaborate may not be safe", N);
5313 ("?use pragma Elaborate_All instead if possible", N);
5321 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5323 when Pragma_Elaborate_All => Elaborate_All : declare
5325 Parent_Node : Node_Id;
5330 Check_Ada_83_Warning;
5332 -- Pragma must be in context items list of a compilation unit
5334 if not Is_List_Member (N) then
5339 Plist := List_Containing (N);
5340 Parent_Node := Parent (Plist);
5342 if Parent_Node = Empty
5343 or else Nkind (Parent_Node) /= N_Compilation_Unit
5344 or else Context_Items (Parent_Node) /= Plist
5351 -- Must be at least one argument
5353 if Arg_Count = 0 then
5354 Error_Pragma ("pragma% requires at least one argument");
5357 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5358 -- have to appear at the end of the context clause, but may
5359 -- appear mixed in with other items, even in Ada 83 mode.
5361 -- Final check: the arguments must all be units mentioned in
5362 -- a with clause in the same context clause. Note that we
5363 -- already checked (in Par.Prag) that all the arguments are
5364 -- either identifiers or selected components.
5367 Outr : while Present (Arg) loop
5368 Citem := First (Plist);
5370 Innr : while Citem /= N loop
5371 if Nkind (Citem) = N_With_Clause
5372 and then Same_Name (Name (Citem), Expression (Arg))
5374 Set_Elaborate_All_Present (Citem, True);
5375 Set_Unit_Name (Expression (Arg), Name (Citem));
5376 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5384 Set_Error_Posted (N);
5386 ("argument of pragma% is not with'ed unit", Arg);
5393 --------------------
5394 -- Elaborate_Body --
5395 --------------------
5397 -- pragma Elaborate_Body [( library_unit_NAME )];
5399 when Pragma_Elaborate_Body => Elaborate_Body : declare
5400 Cunit_Node : Node_Id;
5401 Cunit_Ent : Entity_Id;
5404 Check_Ada_83_Warning;
5405 Check_Valid_Library_Unit_Pragma;
5407 if Nkind (N) = N_Null_Statement then
5411 Cunit_Node := Cunit (Current_Sem_Unit);
5412 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5414 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5416 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5418 Error_Pragma ("pragma% must refer to a spec, not a body");
5420 Set_Body_Required (Cunit_Node, True);
5421 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5423 -- If we are in dynamic elaboration mode, then we suppress
5424 -- elaboration warnings for the unit, since it is definitely
5425 -- fine NOT to do dynamic checks at the first level (and such
5426 -- checks will be suppressed because no elaboration boolean
5427 -- is created for Elaborate_Body packages).
5429 -- But in the static model of elaboration, Elaborate_Body is
5430 -- definitely NOT good enough to ensure elaboration safety on
5431 -- its own, since the body may WITH other units that are not
5432 -- safe from an elaboration point of view, so a client must
5433 -- still do an Elaborate_All on such units.
5435 -- Debug flag -gnatdD restores the old behavior of 3.13,
5436 -- where Elaborate_Body always suppressed elab warnings.
5438 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5439 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5444 ------------------------
5445 -- Elaboration_Checks --
5446 ------------------------
5448 -- pragma Elaboration_Checks (Static | Dynamic);
5450 when Pragma_Elaboration_Checks =>
5452 Check_Arg_Count (1);
5453 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5454 Dynamic_Elaboration_Checks :=
5455 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5461 -- pragma Eliminate (
5462 -- [Unit_Name =>] IDENTIFIER |
5463 -- SELECTED_COMPONENT
5464 -- [,[Entity =>] IDENTIFIER |
5465 -- SELECTED_COMPONENT |
5467 -- [,]OVERLOADING_RESOLUTION);
5469 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5472 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5475 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5477 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5478 -- Result_Type => result_SUBTYPE_NAME]
5480 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5481 -- SUBTYPE_NAME ::= STRING_LITERAL
5483 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5484 -- SOURCE_TRACE ::= STRING_LITERAL
5486 when Pragma_Eliminate => Eliminate : declare
5487 Args : Args_List (1 .. 5);
5488 Names : constant Name_List (1 .. 5) := (
5491 Name_Parameter_Types,
5493 Name_Source_Location);
5495 Unit_Name : Node_Id renames Args (1);
5496 Entity : Node_Id renames Args (2);
5497 Parameter_Types : Node_Id renames Args (3);
5498 Result_Type : Node_Id renames Args (4);
5499 Source_Location : Node_Id renames Args (5);
5503 Check_Valid_Configuration_Pragma;
5504 Gather_Associations (Names, Args);
5506 if No (Unit_Name) then
5507 Error_Pragma ("missing Unit_Name argument for pragma%");
5511 and then (Present (Parameter_Types)
5513 Present (Result_Type)
5515 Present (Source_Location))
5517 Error_Pragma ("missing Entity argument for pragma%");
5520 if (Present (Parameter_Types)
5522 Present (Result_Type))
5524 Present (Source_Location)
5527 ("parameter profile and source location can not " &
5528 "be used together in pragma%");
5531 Process_Eliminate_Pragma
5540 --------------------------
5541 -- Explicit_Overriding --
5542 --------------------------
5544 when Pragma_Explicit_Overriding =>
5545 Check_Valid_Configuration_Pragma;
5546 Check_Arg_Count (0);
5547 Explicit_Overriding := True;
5554 -- [ Convention =>] convention_IDENTIFIER,
5555 -- [ Entity =>] local_NAME
5556 -- [, [External_Name =>] static_string_EXPRESSION ]
5557 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5559 when Pragma_Export => Export : declare
5564 Check_Ada_83_Warning;
5565 Check_At_Least_N_Arguments (2);
5566 Check_At_Most_N_Arguments (4);
5567 Process_Convention (C, Def_Id);
5569 if Ekind (Def_Id) /= E_Constant then
5570 Note_Possible_Modification (Expression (Arg2));
5573 Process_Interface_Name (Def_Id, Arg3, Arg4);
5574 Set_Exported (Def_Id, Arg2);
5577 ----------------------
5578 -- Export_Exception --
5579 ----------------------
5581 -- pragma Export_Exception (
5582 -- [Internal =>] LOCAL_NAME,
5583 -- [, [External =>] EXTERNAL_SYMBOL,]
5584 -- [, [Form =>] Ada | VMS]
5585 -- [, [Code =>] static_integer_EXPRESSION]);
5587 when Pragma_Export_Exception => Export_Exception : declare
5588 Args : Args_List (1 .. 4);
5589 Names : constant Name_List (1 .. 4) := (
5595 Internal : Node_Id renames Args (1);
5596 External : Node_Id renames Args (2);
5597 Form : Node_Id renames Args (3);
5598 Code : Node_Id renames Args (4);
5601 if Inside_A_Generic then
5602 Error_Pragma ("pragma% cannot be used for generic entities");
5605 Gather_Associations (Names, Args);
5606 Process_Extended_Import_Export_Exception_Pragma (
5607 Arg_Internal => Internal,
5608 Arg_External => External,
5612 if not Is_VMS_Exception (Entity (Internal)) then
5613 Set_Exported (Entity (Internal), Internal);
5615 end Export_Exception;
5617 ---------------------
5618 -- Export_Function --
5619 ---------------------
5621 -- pragma Export_Function (
5622 -- [Internal =>] LOCAL_NAME,
5623 -- [, [External =>] EXTERNAL_SYMBOL,]
5624 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5625 -- [, [Result_Type =>] TYPE_DESIGNATOR]
5626 -- [, [Mechanism =>] MECHANISM]
5627 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5629 -- EXTERNAL_SYMBOL ::=
5631 -- | static_string_EXPRESSION
5633 -- PARAMETER_TYPES ::=
5635 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5637 -- TYPE_DESIGNATOR ::=
5639 -- | subtype_Name ' Access
5643 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5645 -- MECHANISM_ASSOCIATION ::=
5646 -- [formal_parameter_NAME =>] MECHANISM_NAME
5648 -- MECHANISM_NAME ::=
5651 -- | Descriptor [([Class =>] CLASS_NAME)]
5653 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5655 when Pragma_Export_Function => Export_Function : declare
5656 Args : Args_List (1 .. 6);
5657 Names : constant Name_List (1 .. 6) := (
5660 Name_Parameter_Types,
5663 Name_Result_Mechanism);
5665 Internal : Node_Id renames Args (1);
5666 External : Node_Id renames Args (2);
5667 Parameter_Types : Node_Id renames Args (3);
5668 Result_Type : Node_Id renames Args (4);
5669 Mechanism : Node_Id renames Args (5);
5670 Result_Mechanism : Node_Id renames Args (6);
5674 Gather_Associations (Names, Args);
5675 Process_Extended_Import_Export_Subprogram_Pragma (
5676 Arg_Internal => Internal,
5677 Arg_External => External,
5678 Arg_Parameter_Types => Parameter_Types,
5679 Arg_Result_Type => Result_Type,
5680 Arg_Mechanism => Mechanism,
5681 Arg_Result_Mechanism => Result_Mechanism);
5682 end Export_Function;
5688 -- pragma Export_Object (
5689 -- [Internal =>] LOCAL_NAME,
5690 -- [, [External =>] EXTERNAL_SYMBOL]
5691 -- [, [Size =>] EXTERNAL_SYMBOL]);
5693 -- EXTERNAL_SYMBOL ::=
5695 -- | static_string_EXPRESSION
5697 -- PARAMETER_TYPES ::=
5699 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5701 -- TYPE_DESIGNATOR ::=
5703 -- | subtype_Name ' Access
5707 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5709 -- MECHANISM_ASSOCIATION ::=
5710 -- [formal_parameter_NAME =>] MECHANISM_NAME
5712 -- MECHANISM_NAME ::=
5715 -- | Descriptor [([Class =>] CLASS_NAME)]
5717 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5719 when Pragma_Export_Object => Export_Object : declare
5720 Args : Args_List (1 .. 3);
5721 Names : constant Name_List (1 .. 3) := (
5726 Internal : Node_Id renames Args (1);
5727 External : Node_Id renames Args (2);
5728 Size : Node_Id renames Args (3);
5732 Gather_Associations (Names, Args);
5733 Process_Extended_Import_Export_Object_Pragma (
5734 Arg_Internal => Internal,
5735 Arg_External => External,
5739 ----------------------
5740 -- Export_Procedure --
5741 ----------------------
5743 -- pragma Export_Procedure (
5744 -- [Internal =>] LOCAL_NAME,
5745 -- [, [External =>] EXTERNAL_SYMBOL,]
5746 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5747 -- [, [Mechanism =>] MECHANISM]);
5749 -- EXTERNAL_SYMBOL ::=
5751 -- | static_string_EXPRESSION
5753 -- PARAMETER_TYPES ::=
5755 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5757 -- TYPE_DESIGNATOR ::=
5759 -- | subtype_Name ' Access
5763 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5765 -- MECHANISM_ASSOCIATION ::=
5766 -- [formal_parameter_NAME =>] MECHANISM_NAME
5768 -- MECHANISM_NAME ::=
5771 -- | Descriptor [([Class =>] CLASS_NAME)]
5773 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5775 when Pragma_Export_Procedure => Export_Procedure : declare
5776 Args : Args_List (1 .. 4);
5777 Names : constant Name_List (1 .. 4) := (
5780 Name_Parameter_Types,
5783 Internal : Node_Id renames Args (1);
5784 External : Node_Id renames Args (2);
5785 Parameter_Types : Node_Id renames Args (3);
5786 Mechanism : Node_Id renames Args (4);
5790 Gather_Associations (Names, Args);
5791 Process_Extended_Import_Export_Subprogram_Pragma (
5792 Arg_Internal => Internal,
5793 Arg_External => External,
5794 Arg_Parameter_Types => Parameter_Types,
5795 Arg_Mechanism => Mechanism);
5796 end Export_Procedure;
5802 -- pragma Export_Value (
5803 -- [Value =>] static_integer_EXPRESSION,
5804 -- [Link_Name =>] static_string_EXPRESSION);
5806 when Pragma_Export_Value =>
5808 Check_Arg_Count (2);
5810 Check_Optional_Identifier (Arg1, Name_Value);
5811 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
5813 Check_Optional_Identifier (Arg2, Name_Link_Name);
5814 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
5816 -----------------------------
5817 -- Export_Valued_Procedure --
5818 -----------------------------
5820 -- pragma Export_Valued_Procedure (
5821 -- [Internal =>] LOCAL_NAME,
5822 -- [, [External =>] EXTERNAL_SYMBOL,]
5823 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5824 -- [, [Mechanism =>] MECHANISM]);
5826 -- EXTERNAL_SYMBOL ::=
5828 -- | static_string_EXPRESSION
5830 -- PARAMETER_TYPES ::=
5832 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5834 -- TYPE_DESIGNATOR ::=
5836 -- | subtype_Name ' Access
5840 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5842 -- MECHANISM_ASSOCIATION ::=
5843 -- [formal_parameter_NAME =>] MECHANISM_NAME
5845 -- MECHANISM_NAME ::=
5848 -- | Descriptor [([Class =>] CLASS_NAME)]
5850 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5852 when Pragma_Export_Valued_Procedure =>
5853 Export_Valued_Procedure : declare
5854 Args : Args_List (1 .. 4);
5855 Names : constant Name_List (1 .. 4) := (
5858 Name_Parameter_Types,
5861 Internal : Node_Id renames Args (1);
5862 External : Node_Id renames Args (2);
5863 Parameter_Types : Node_Id renames Args (3);
5864 Mechanism : Node_Id renames Args (4);
5868 Gather_Associations (Names, Args);
5869 Process_Extended_Import_Export_Subprogram_Pragma (
5870 Arg_Internal => Internal,
5871 Arg_External => External,
5872 Arg_Parameter_Types => Parameter_Types,
5873 Arg_Mechanism => Mechanism);
5874 end Export_Valued_Procedure;
5880 -- pragma Extend_System ([Name =>] Identifier);
5882 when Pragma_Extend_System => Extend_System : declare
5885 Check_Valid_Configuration_Pragma;
5886 Check_Arg_Count (1);
5887 Check_Optional_Identifier (Arg1, Name_Name);
5888 Check_Arg_Is_Identifier (Arg1);
5890 Get_Name_String (Chars (Expression (Arg1)));
5893 and then Name_Buffer (1 .. 4) = "aux_"
5895 if Present (System_Extend_Pragma_Arg) then
5896 if Chars (Expression (Arg1)) =
5897 Chars (Expression (System_Extend_Pragma_Arg))
5901 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
5902 Error_Pragma ("pragma% conflicts with that at#");
5906 System_Extend_Pragma_Arg := Arg1;
5908 if not GNAT_Mode then
5909 System_Extend_Unit := Arg1;
5913 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
5917 ------------------------
5918 -- Extensions_Allowed --
5919 ------------------------
5921 -- pragma Extensions_Allowed (ON | OFF);
5923 when Pragma_Extensions_Allowed =>
5925 Check_Arg_Count (1);
5926 Check_No_Identifiers;
5927 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5928 Extensions_Allowed := (Chars (Expression (Arg1)) = Name_On);
5934 -- pragma External (
5935 -- [ Convention =>] convention_IDENTIFIER,
5936 -- [ Entity =>] local_NAME
5937 -- [, [External_Name =>] static_string_EXPRESSION ]
5938 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5940 when Pragma_External => External : declare
5946 Check_At_Least_N_Arguments (2);
5947 Check_At_Most_N_Arguments (4);
5948 Process_Convention (C, Def_Id);
5949 Note_Possible_Modification (Expression (Arg2));
5950 Process_Interface_Name (Def_Id, Arg3, Arg4);
5951 Set_Exported (Def_Id, Arg2);
5954 --------------------------
5955 -- External_Name_Casing --
5956 --------------------------
5958 -- pragma External_Name_Casing (
5959 -- UPPERCASE | LOWERCASE
5960 -- [, AS_IS | UPPERCASE | LOWERCASE]);
5962 when Pragma_External_Name_Casing =>
5964 External_Name_Casing : declare
5967 Check_No_Identifiers;
5969 if Arg_Count = 2 then
5971 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
5973 case Chars (Get_Pragma_Arg (Arg2)) is
5975 Opt.External_Name_Exp_Casing := As_Is;
5977 when Name_Uppercase =>
5978 Opt.External_Name_Exp_Casing := Uppercase;
5980 when Name_Lowercase =>
5981 Opt.External_Name_Exp_Casing := Lowercase;
5988 Check_Arg_Count (1);
5991 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
5993 case Chars (Get_Pragma_Arg (Arg1)) is
5994 when Name_Uppercase =>
5995 Opt.External_Name_Imp_Casing := Uppercase;
5997 when Name_Lowercase =>
5998 Opt.External_Name_Imp_Casing := Lowercase;
6003 end External_Name_Casing;
6005 ---------------------------
6006 -- Finalize_Storage_Only --
6007 ---------------------------
6009 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6011 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6012 Assoc : constant Node_Id := Arg1;
6013 Type_Id : constant Node_Id := Expression (Assoc);
6017 Check_No_Identifiers;
6018 Check_Arg_Count (1);
6019 Check_Arg_Is_Local_Name (Arg1);
6021 Find_Type (Type_Id);
6022 Typ := Entity (Type_Id);
6025 or else Rep_Item_Too_Early (Typ, N)
6029 Typ := Underlying_Type (Typ);
6032 if not Is_Controlled (Typ) then
6033 Error_Pragma ("pragma% must specify controlled type");
6036 Check_First_Subtype (Arg1);
6038 if Finalize_Storage_Only (Typ) then
6039 Error_Pragma ("duplicate pragma%, only one allowed");
6041 elsif not Rep_Item_Too_Late (Typ, N) then
6042 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6044 end Finalize_Storage;
6046 --------------------------
6047 -- Float_Representation --
6048 --------------------------
6050 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6052 when Pragma_Float_Representation => Float_Representation : declare
6060 if Arg_Count = 1 then
6061 Check_Valid_Configuration_Pragma;
6063 Check_Arg_Count (2);
6064 Check_Optional_Identifier (Arg2, Name_Entity);
6065 Check_Arg_Is_Local_Name (Arg2);
6068 Check_No_Identifier (Arg1);
6069 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6071 if not OpenVMS_On_Target then
6072 if Chars (Expression (Arg1)) = Name_VAX_Float then
6074 ("?pragma% ignored (applies only to Open'V'M'S)");
6080 -- One argument case
6082 if Arg_Count = 1 then
6084 if Chars (Expression (Arg1)) = Name_VAX_Float then
6086 if Opt.Float_Format = 'I' then
6087 Error_Pragma ("'I'E'E'E format previously specified");
6090 Opt.Float_Format := 'V';
6093 if Opt.Float_Format = 'V' then
6094 Error_Pragma ("'V'A'X format previously specified");
6097 Opt.Float_Format := 'I';
6100 Set_Standard_Fpt_Formats;
6102 -- Two argument case
6105 Argx := Get_Pragma_Arg (Arg2);
6107 if not Is_Entity_Name (Argx)
6108 or else not Is_Floating_Point_Type (Entity (Argx))
6111 ("second argument of% pragma must be floating-point type",
6115 Ent := Entity (Argx);
6116 Digs := UI_To_Int (Digits_Value (Ent));
6118 -- Two arguments, VAX_Float case
6120 if Chars (Expression (Arg1)) = Name_VAX_Float then
6123 when 6 => Set_F_Float (Ent);
6124 when 9 => Set_D_Float (Ent);
6125 when 15 => Set_G_Float (Ent);
6129 ("wrong digits value, must be 6,9 or 15", Arg2);
6132 -- Two arguments, IEEE_Float case
6136 when 6 => Set_IEEE_Short (Ent);
6137 when 15 => Set_IEEE_Long (Ent);
6141 ("wrong digits value, must be 6 or 15", Arg2);
6145 end Float_Representation;
6151 -- pragma Ident (static_string_EXPRESSION)
6153 -- Note: pragma Comment shares this processing. Pragma Comment
6154 -- is identical to Ident, except that the restriction of the
6155 -- argument to 31 characters and the placement restrictions
6156 -- are not enforced for pragma Comment.
6158 when Pragma_Ident | Pragma_Comment => Ident : declare
6163 Check_Arg_Count (1);
6164 Check_No_Identifiers;
6165 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6167 -- For pragma Ident, preserve DEC compatibility by requiring
6168 -- the pragma to appear in a declarative part or package spec.
6170 if Prag_Id = Pragma_Ident then
6171 Check_Is_In_Decl_Part_Or_Package_Spec;
6174 Str := Expr_Value_S (Expression (Arg1));
6181 GP := Parent (Parent (N));
6183 if Nkind (GP) = N_Package_Declaration
6185 Nkind (GP) = N_Generic_Package_Declaration
6190 -- If we have a compilation unit, then record the ident
6191 -- value, checking for improper duplication.
6193 if Nkind (GP) = N_Compilation_Unit then
6194 CS := Ident_String (Current_Sem_Unit);
6196 if Present (CS) then
6198 -- For Ident, we do not permit multiple instances
6200 if Prag_Id = Pragma_Ident then
6201 Error_Pragma ("duplicate% pragma not permitted");
6203 -- For Comment, we concatenate the string, unless we
6204 -- want to preserve the tree structure for ASIS.
6206 elsif not ASIS_Mode then
6207 Start_String (Strval (CS));
6208 Store_String_Char (' ');
6209 Store_String_Chars (Strval (Str));
6210 Set_Strval (CS, End_String);
6214 -- In VMS, the effect of IDENT is achieved by passing
6215 -- IDENTIFICATION=name as a --for-linker switch.
6217 if OpenVMS_On_Target then
6220 ("--for-linker=IDENTIFICATION=");
6221 String_To_Name_Buffer (Strval (Str));
6222 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6224 -- Only the last processed IDENT is saved. The main
6225 -- purpose is so an IDENT associated with a main
6226 -- procedure will be used in preference to an IDENT
6227 -- associated with a with'd package.
6229 Replace_Linker_Option_String
6230 (End_String, "--for-linker=IDENTIFICATION=");
6233 Set_Ident_String (Current_Sem_Unit, Str);
6236 -- For subunits, we just ignore the Ident, since in GNAT
6237 -- these are not separate object files, and hence not
6238 -- separate units in the unit table.
6240 elsif Nkind (GP) = N_Subunit then
6243 -- Otherwise we have a misplaced pragma Ident, but we ignore
6244 -- this if we are in an instantiation, since it comes from
6245 -- a generic, and has no relevance to the instantiation.
6247 elsif Prag_Id = Pragma_Ident then
6248 if Instantiation_Location (Loc) = No_Location then
6249 Error_Pragma ("pragma% only allowed at outer level");
6260 -- [ Convention =>] convention_IDENTIFIER,
6261 -- [ Entity =>] local_NAME
6262 -- [, [External_Name =>] static_string_EXPRESSION ]
6263 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6265 when Pragma_Import =>
6266 Check_Ada_83_Warning;
6267 Check_At_Least_N_Arguments (2);
6268 Check_At_Most_N_Arguments (4);
6269 Process_Import_Or_Interface;
6271 ----------------------
6272 -- Import_Exception --
6273 ----------------------
6275 -- pragma Import_Exception (
6276 -- [Internal =>] LOCAL_NAME,
6277 -- [, [External =>] EXTERNAL_SYMBOL,]
6278 -- [, [Form =>] Ada | VMS]
6279 -- [, [Code =>] static_integer_EXPRESSION]);
6281 when Pragma_Import_Exception => Import_Exception : declare
6282 Args : Args_List (1 .. 4);
6283 Names : constant Name_List (1 .. 4) := (
6289 Internal : Node_Id renames Args (1);
6290 External : Node_Id renames Args (2);
6291 Form : Node_Id renames Args (3);
6292 Code : Node_Id renames Args (4);
6295 Gather_Associations (Names, Args);
6297 if Present (External) and then Present (Code) then
6299 ("cannot give both External and Code options for pragma%");
6302 Process_Extended_Import_Export_Exception_Pragma (
6303 Arg_Internal => Internal,
6304 Arg_External => External,
6308 if not Is_VMS_Exception (Entity (Internal)) then
6309 Set_Imported (Entity (Internal));
6311 end Import_Exception;
6313 ---------------------
6314 -- Import_Function --
6315 ---------------------
6317 -- pragma Import_Function (
6318 -- [Internal =>] LOCAL_NAME,
6319 -- [, [External =>] EXTERNAL_SYMBOL]
6320 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6321 -- [, [Result_Type =>] SUBTYPE_MARK]
6322 -- [, [Mechanism =>] MECHANISM]
6323 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6324 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6326 -- EXTERNAL_SYMBOL ::=
6328 -- | static_string_EXPRESSION
6330 -- PARAMETER_TYPES ::=
6332 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6334 -- TYPE_DESIGNATOR ::=
6336 -- | subtype_Name ' Access
6340 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6342 -- MECHANISM_ASSOCIATION ::=
6343 -- [formal_parameter_NAME =>] MECHANISM_NAME
6345 -- MECHANISM_NAME ::=
6348 -- | Descriptor [([Class =>] CLASS_NAME)]
6350 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6352 when Pragma_Import_Function => Import_Function : declare
6353 Args : Args_List (1 .. 7);
6354 Names : constant Name_List (1 .. 7) := (
6357 Name_Parameter_Types,
6360 Name_Result_Mechanism,
6361 Name_First_Optional_Parameter);
6363 Internal : Node_Id renames Args (1);
6364 External : Node_Id renames Args (2);
6365 Parameter_Types : Node_Id renames Args (3);
6366 Result_Type : Node_Id renames Args (4);
6367 Mechanism : Node_Id renames Args (5);
6368 Result_Mechanism : Node_Id renames Args (6);
6369 First_Optional_Parameter : Node_Id renames Args (7);
6373 Gather_Associations (Names, Args);
6374 Process_Extended_Import_Export_Subprogram_Pragma (
6375 Arg_Internal => Internal,
6376 Arg_External => External,
6377 Arg_Parameter_Types => Parameter_Types,
6378 Arg_Result_Type => Result_Type,
6379 Arg_Mechanism => Mechanism,
6380 Arg_Result_Mechanism => Result_Mechanism,
6381 Arg_First_Optional_Parameter => First_Optional_Parameter);
6382 end Import_Function;
6388 -- pragma Import_Object (
6389 -- [Internal =>] LOCAL_NAME,
6390 -- [, [External =>] EXTERNAL_SYMBOL]
6391 -- [, [Size =>] EXTERNAL_SYMBOL]);
6393 -- EXTERNAL_SYMBOL ::=
6395 -- | static_string_EXPRESSION
6397 when Pragma_Import_Object => Import_Object : declare
6398 Args : Args_List (1 .. 3);
6399 Names : constant Name_List (1 .. 3) := (
6404 Internal : Node_Id renames Args (1);
6405 External : Node_Id renames Args (2);
6406 Size : Node_Id renames Args (3);
6410 Gather_Associations (Names, Args);
6411 Process_Extended_Import_Export_Object_Pragma (
6412 Arg_Internal => Internal,
6413 Arg_External => External,
6417 ----------------------
6418 -- Import_Procedure --
6419 ----------------------
6421 -- pragma Import_Procedure (
6422 -- [Internal =>] LOCAL_NAME,
6423 -- [, [External =>] EXTERNAL_SYMBOL]
6424 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6425 -- [, [Mechanism =>] MECHANISM]
6426 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6428 -- EXTERNAL_SYMBOL ::=
6430 -- | static_string_EXPRESSION
6432 -- PARAMETER_TYPES ::=
6434 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6436 -- TYPE_DESIGNATOR ::=
6438 -- | subtype_Name ' Access
6442 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6444 -- MECHANISM_ASSOCIATION ::=
6445 -- [formal_parameter_NAME =>] MECHANISM_NAME
6447 -- MECHANISM_NAME ::=
6450 -- | Descriptor [([Class =>] CLASS_NAME)]
6452 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6454 when Pragma_Import_Procedure => Import_Procedure : declare
6455 Args : Args_List (1 .. 5);
6456 Names : constant Name_List (1 .. 5) := (
6459 Name_Parameter_Types,
6461 Name_First_Optional_Parameter);
6463 Internal : Node_Id renames Args (1);
6464 External : Node_Id renames Args (2);
6465 Parameter_Types : Node_Id renames Args (3);
6466 Mechanism : Node_Id renames Args (4);
6467 First_Optional_Parameter : Node_Id renames Args (5);
6471 Gather_Associations (Names, Args);
6472 Process_Extended_Import_Export_Subprogram_Pragma (
6473 Arg_Internal => Internal,
6474 Arg_External => External,
6475 Arg_Parameter_Types => Parameter_Types,
6476 Arg_Mechanism => Mechanism,
6477 Arg_First_Optional_Parameter => First_Optional_Parameter);
6478 end Import_Procedure;
6480 -----------------------------
6481 -- Import_Valued_Procedure --
6482 -----------------------------
6484 -- pragma Import_Valued_Procedure (
6485 -- [Internal =>] LOCAL_NAME,
6486 -- [, [External =>] EXTERNAL_SYMBOL]
6487 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6488 -- [, [Mechanism =>] MECHANISM]
6489 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6491 -- EXTERNAL_SYMBOL ::=
6493 -- | static_string_EXPRESSION
6495 -- PARAMETER_TYPES ::=
6497 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6499 -- TYPE_DESIGNATOR ::=
6501 -- | subtype_Name ' Access
6505 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6507 -- MECHANISM_ASSOCIATION ::=
6508 -- [formal_parameter_NAME =>] MECHANISM_NAME
6510 -- MECHANISM_NAME ::=
6513 -- | Descriptor [([Class =>] CLASS_NAME)]
6515 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6517 when Pragma_Import_Valued_Procedure =>
6518 Import_Valued_Procedure : declare
6519 Args : Args_List (1 .. 5);
6520 Names : constant Name_List (1 .. 5) := (
6523 Name_Parameter_Types,
6525 Name_First_Optional_Parameter);
6527 Internal : Node_Id renames Args (1);
6528 External : Node_Id renames Args (2);
6529 Parameter_Types : Node_Id renames Args (3);
6530 Mechanism : Node_Id renames Args (4);
6531 First_Optional_Parameter : Node_Id renames Args (5);
6535 Gather_Associations (Names, Args);
6536 Process_Extended_Import_Export_Subprogram_Pragma (
6537 Arg_Internal => Internal,
6538 Arg_External => External,
6539 Arg_Parameter_Types => Parameter_Types,
6540 Arg_Mechanism => Mechanism,
6541 Arg_First_Optional_Parameter => First_Optional_Parameter);
6542 end Import_Valued_Procedure;
6544 ------------------------
6545 -- Initialize_Scalars --
6546 ------------------------
6548 -- pragma Initialize_Scalars;
6550 when Pragma_Initialize_Scalars =>
6552 Check_Arg_Count (0);
6553 Check_Valid_Configuration_Pragma;
6554 Check_Restriction (No_Initialize_Scalars, N);
6556 if not Restriction_Active (No_Initialize_Scalars) then
6557 Init_Or_Norm_Scalars := True;
6558 Initialize_Scalars := True;
6565 -- pragma Inline ( NAME {, NAME} );
6567 when Pragma_Inline =>
6569 -- Pragma is active if inlining option is active
6571 if Inline_Active then
6572 Process_Inline (True);
6574 -- Pragma is active in a predefined file in config run time mode
6576 elsif Configurable_Run_Time_Mode
6578 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
6580 Process_Inline (True);
6582 -- Otherwise inlining is not active
6585 Process_Inline (False);
6592 -- pragma Inline_Always ( NAME {, NAME} );
6594 when Pragma_Inline_Always =>
6595 Process_Inline (True);
6597 --------------------
6598 -- Inline_Generic --
6599 --------------------
6601 -- pragma Inline_Generic (NAME {, NAME});
6603 when Pragma_Inline_Generic =>
6604 Process_Generic_List;
6606 ----------------------
6607 -- Inspection_Point --
6608 ----------------------
6610 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6612 when Pragma_Inspection_Point => Inspection_Point : declare
6617 if Arg_Count > 0 then
6620 Exp := Expression (Arg);
6623 if not Is_Entity_Name (Exp)
6624 or else not Is_Object (Entity (Exp))
6626 Error_Pragma_Arg ("object name required", Arg);
6633 end Inspection_Point;
6639 -- pragma Interface (
6640 -- convention_IDENTIFIER,
6643 when Pragma_Interface =>
6645 Check_Arg_Count (2);
6646 Check_No_Identifiers;
6647 Process_Import_Or_Interface;
6649 --------------------
6650 -- Interface_Name --
6651 --------------------
6653 -- pragma Interface_Name (
6654 -- [ Entity =>] local_NAME
6655 -- [,[External_Name =>] static_string_EXPRESSION ]
6656 -- [,[Link_Name =>] static_string_EXPRESSION ]);
6658 when Pragma_Interface_Name => Interface_Name : declare
6666 Check_At_Least_N_Arguments (2);
6667 Check_At_Most_N_Arguments (3);
6668 Id := Expression (Arg1);
6671 if not Is_Entity_Name (Id) then
6673 ("first argument for pragma% must be entity name", Arg1);
6674 elsif Etype (Id) = Any_Type then
6677 Def_Id := Entity (Id);
6680 -- Special DEC-compatible processing for the object case,
6681 -- forces object to be imported.
6683 if Ekind (Def_Id) = E_Variable then
6684 Kill_Size_Check_Code (Def_Id);
6685 Note_Possible_Modification (Id);
6687 -- Initialization is not allowed for imported variable
6689 if Present (Expression (Parent (Def_Id)))
6690 and then Comes_From_Source (Expression (Parent (Def_Id)))
6692 Error_Msg_Sloc := Sloc (Def_Id);
6694 ("no initialization allowed for declaration of& #",
6698 -- For compatibility, support VADS usage of providing both
6699 -- pragmas Interface and Interface_Name to obtain the effect
6700 -- of a single Import pragma.
6702 if Is_Imported (Def_Id)
6703 and then Present (First_Rep_Item (Def_Id))
6704 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6705 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6709 Set_Imported (Def_Id);
6712 Set_Is_Public (Def_Id);
6713 Process_Interface_Name (Def_Id, Arg2, Arg3);
6716 -- Otherwise must be subprogram
6718 elsif not Is_Subprogram (Def_Id) then
6720 ("argument of pragma% is not subprogram", Arg1);
6723 Check_At_Most_N_Arguments (3);
6727 -- Loop through homonyms
6730 Def_Id := Get_Base_Subprogram (Hom_Id);
6732 if Is_Imported (Def_Id) then
6733 Process_Interface_Name (Def_Id, Arg2, Arg3);
6737 Hom_Id := Homonym (Hom_Id);
6739 exit when No (Hom_Id)
6740 or else Scope (Hom_Id) /= Current_Scope;
6745 ("argument of pragma% is not imported subprogram",
6751 -----------------------
6752 -- Interrupt_Handler --
6753 -----------------------
6755 -- pragma Interrupt_Handler (handler_NAME);
6757 when Pragma_Interrupt_Handler =>
6758 Check_Ada_83_Warning;
6759 Check_Arg_Count (1);
6760 Check_No_Identifiers;
6762 if No_Run_Time_Mode then
6763 Error_Msg_CRT ("Interrupt_Handler pragma", N);
6765 Check_Interrupt_Or_Attach_Handler;
6766 Process_Interrupt_Or_Attach_Handler;
6769 ------------------------
6770 -- Interrupt_Priority --
6771 ------------------------
6773 -- pragma Interrupt_Priority [(EXPRESSION)];
6775 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
6776 P : constant Node_Id := Parent (N);
6780 Check_Ada_83_Warning;
6782 if Arg_Count /= 0 then
6783 Arg := Expression (Arg1);
6784 Check_Arg_Count (1);
6785 Check_No_Identifiers;
6787 -- The expression must be analyzed in the special manner
6788 -- described in "Handling of Default and Per-Object
6789 -- Expressions" in sem.ads.
6791 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
6794 if Nkind (P) /= N_Task_Definition
6795 and then Nkind (P) /= N_Protected_Definition
6800 elsif Has_Priority_Pragma (P) then
6801 Error_Pragma ("duplicate pragma% not allowed");
6804 Set_Has_Priority_Pragma (P, True);
6805 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6807 end Interrupt_Priority;
6809 ---------------------
6810 -- Interrupt_State --
6811 ---------------------
6813 -- pragma Interrupt_State (
6814 -- [Name =>] INTERRUPT_ID,
6815 -- [State =>] INTERRUPT_STATE);
6817 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
6818 -- INTERRUPT_STATE => System | Runtime | User
6820 -- Note: if the interrupt id is given as an identifier, then
6821 -- it must be one of the identifiers in Ada.Interrupts.Names.
6822 -- Otherwise it is given as a static integer expression which
6823 -- must be in the range of Ada.Interrupts.Interrupt_ID.
6825 when Pragma_Interrupt_State => Interrupt_State : declare
6827 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
6828 -- This is the entity Ada.Interrupts.Interrupt_ID;
6830 State_Type : Character;
6831 -- Set to 's'/'r'/'u' for System/Runtime/User
6834 -- Index to entry in Interrupt_States table
6837 -- Value of interrupt
6839 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
6840 -- The first argument to the pragma
6842 Int_Ent : Entity_Id;
6843 -- Interrupt entity in Ada.Interrupts.Names
6847 Check_Arg_Count (2);
6849 Check_Optional_Identifier (Arg1, Name_Name);
6850 Check_Optional_Identifier (Arg2, "state");
6851 Check_Arg_Is_Identifier (Arg2);
6853 -- First argument is identifier
6855 if Nkind (Arg1X) = N_Identifier then
6857 -- Search list of names in Ada.Interrupts.Names
6859 Int_Ent := First_Entity (RTE (RE_Names));
6861 if No (Int_Ent) then
6862 Error_Pragma_Arg ("invalid interrupt name", Arg1);
6864 elsif Chars (Int_Ent) = Chars (Arg1X) then
6865 Int_Val := Expr_Value (Constant_Value (Int_Ent));
6869 Next_Entity (Int_Ent);
6872 -- First argument is not an identifier, so it must be a
6873 -- static expression of type Ada.Interrupts.Interrupt_ID.
6876 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6877 Int_Val := Expr_Value (Arg1X);
6879 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
6881 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
6884 ("value not in range of type " &
6885 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
6891 case Chars (Get_Pragma_Arg (Arg2)) is
6892 when Name_Runtime => State_Type := 'r';
6893 when Name_System => State_Type := 's';
6894 when Name_User => State_Type := 'u';
6897 Error_Pragma_Arg ("invalid interrupt state", Arg2);
6900 -- Check if entry is already stored
6902 IST_Num := Interrupt_States.First;
6904 -- If entry not found, add it
6906 if IST_Num > Interrupt_States.Last then
6907 Interrupt_States.Append
6908 ((Interrupt_Number => UI_To_Int (Int_Val),
6909 Interrupt_State => State_Type,
6910 Pragma_Loc => Loc));
6913 -- Case of entry for the same entry
6915 elsif Int_Val = Interrupt_States.Table (IST_Num).
6918 -- If state matches, done, no need to make redundant entry
6921 State_Type = Interrupt_States.Table (IST_Num).
6924 -- Otherwise if state does not match, error
6927 Interrupt_States.Table (IST_Num).Pragma_Loc;
6929 ("state conflicts with that given at #", Arg2);
6933 IST_Num := IST_Num + 1;
6935 end Interrupt_State;
6937 ----------------------
6938 -- Java_Constructor --
6939 ----------------------
6941 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
6943 when Pragma_Java_Constructor => Java_Constructor : declare
6950 Check_Arg_Count (1);
6951 Check_Optional_Identifier (Arg1, Name_Entity);
6952 Check_Arg_Is_Local_Name (Arg1);
6954 Id := Expression (Arg1);
6955 Find_Program_Unit_Name (Id);
6957 -- If we did not find the name, we are done
6959 if Etype (Id) = Any_Type then
6963 Hom_Id := Entity (Id);
6965 -- Loop through homonyms
6968 Def_Id := Get_Base_Subprogram (Hom_Id);
6970 -- The constructor is required to be a function returning
6971 -- an access type whose designated type has convention Java.
6973 if Ekind (Def_Id) = E_Function
6974 and then Ekind (Etype (Def_Id)) in Access_Kind
6977 (Designated_Type (Etype (Def_Id))) = Convention_Java
6980 (Root_Type (Designated_Type (Etype (Def_Id))))
6983 Set_Is_Constructor (Def_Id);
6984 Set_Convention (Def_Id, Convention_Java);
6988 ("pragma% requires function returning a 'Java access type",
6992 Hom_Id := Homonym (Hom_Id);
6994 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
6996 end Java_Constructor;
6998 ----------------------
6999 -- Java_Interface --
7000 ----------------------
7002 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7004 when Pragma_Java_Interface => Java_Interface : declare
7010 Check_Arg_Count (1);
7011 Check_Optional_Identifier (Arg1, Name_Entity);
7012 Check_Arg_Is_Local_Name (Arg1);
7014 Arg := Expression (Arg1);
7017 if Etype (Arg) = Any_Type then
7021 if not Is_Entity_Name (Arg)
7022 or else not Is_Type (Entity (Arg))
7024 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7027 Typ := Underlying_Type (Entity (Arg));
7029 -- For now we simply check some of the semantic constraints
7030 -- on the type. This currently leaves out some restrictions
7031 -- on interface types, namely that the parent type must be
7032 -- java.lang.Object.Typ and that all primitives of the type
7033 -- should be declared abstract. ???
7035 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7036 Error_Pragma_Arg ("pragma% requires an abstract "
7037 & "tagged type", Arg1);
7039 elsif not Has_Discriminants (Typ)
7040 or else Ekind (Etype (First_Discriminant (Typ)))
7041 /= E_Anonymous_Access_Type
7043 not Is_Class_Wide_Type
7044 (Designated_Type (Etype (First_Discriminant (Typ))))
7047 ("type must have a class-wide access discriminant", Arg1);
7055 -- pragma Keep_Names ([On => ] local_NAME);
7057 when Pragma_Keep_Names => Keep_Names : declare
7062 Check_Arg_Count (1);
7063 Check_Optional_Identifier (Arg1, Name_On);
7064 Check_Arg_Is_Local_Name (Arg1);
7066 Arg := Expression (Arg1);
7069 if Etype (Arg) = Any_Type then
7073 if not Is_Entity_Name (Arg)
7074 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7077 ("pragma% requires a local enumeration type", Arg1);
7080 Set_Discard_Names (Entity (Arg), False);
7087 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
7089 when Pragma_License =>
7091 Check_Arg_Count (1);
7092 Check_No_Identifiers;
7093 Check_Valid_Configuration_Pragma;
7094 Check_Arg_Is_Identifier (Arg1);
7097 Sind : constant Source_File_Index :=
7098 Source_Index (Current_Sem_Unit);
7101 case Chars (Get_Pragma_Arg (Arg1)) is
7103 Set_License (Sind, GPL);
7105 when Name_Modified_GPL =>
7106 Set_License (Sind, Modified_GPL);
7108 when Name_Restricted =>
7109 Set_License (Sind, Restricted);
7111 when Name_Unrestricted =>
7112 Set_License (Sind, Unrestricted);
7115 Error_Pragma_Arg ("invalid license name", Arg1);
7123 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7125 when Pragma_Link_With => Link_With : declare
7131 if Operating_Mode = Generate_Code
7132 and then In_Extended_Main_Source_Unit (N)
7134 Check_At_Least_N_Arguments (1);
7135 Check_No_Identifiers;
7136 Check_Is_In_Decl_Part_Or_Package_Spec;
7137 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7141 while Present (Arg) loop
7142 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7144 -- Store argument, converting sequences of spaces
7145 -- to a single null character (this is one of the
7146 -- differences in processing between Link_With
7147 -- and Linker_Options).
7150 C : constant Char_Code := Get_Char_Code (' ');
7151 S : constant String_Id :=
7152 Strval (Expr_Value_S (Expression (Arg)));
7153 L : constant Nat := String_Length (S);
7156 procedure Skip_Spaces;
7157 -- Advance F past any spaces
7159 procedure Skip_Spaces is
7161 while F <= L and then Get_String_Char (S, F) = C loop
7167 Skip_Spaces; -- skip leading spaces
7169 -- Loop through characters, changing any embedded
7170 -- sequence of spaces to a single null character
7171 -- (this is how Link_With/Linker_Options differ)
7174 if Get_String_Char (S, F) = C then
7177 Store_String_Char (ASCII.NUL);
7180 Store_String_Char (Get_String_Char (S, F));
7188 if Present (Arg) then
7189 Store_String_Char (ASCII.NUL);
7193 Store_Linker_Option_String (End_String);
7201 -- pragma Linker_Alias (
7202 -- [Entity =>] LOCAL_NAME
7203 -- [Alias =>] static_string_EXPRESSION);
7205 when Pragma_Linker_Alias =>
7207 Check_Arg_Count (2);
7208 Check_Optional_Identifier (Arg1, Name_Entity);
7209 Check_Optional_Identifier (Arg2, "alias");
7210 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7211 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7213 -- The only processing required is to link this item on to the
7214 -- list of rep items for the given entity. This is accomplished
7215 -- by the call to Rep_Item_Too_Late (when no error is detected
7216 -- and False is returned).
7218 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7221 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7224 --------------------
7225 -- Linker_Options --
7226 --------------------
7228 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7230 when Pragma_Linker_Options => Linker_Options : declare
7234 Check_Ada_83_Warning;
7235 Check_No_Identifiers;
7236 Check_Arg_Count (1);
7237 Check_Is_In_Decl_Part_Or_Package_Spec;
7239 if Operating_Mode = Generate_Code
7240 and then In_Extended_Main_Source_Unit (N)
7242 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7243 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7246 while Present (Arg) loop
7247 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7248 Store_String_Char (ASCII.NUL);
7250 (Strval (Expr_Value_S (Expression (Arg))));
7254 Store_Linker_Option_String (End_String);
7258 --------------------
7259 -- Linker_Section --
7260 --------------------
7262 -- pragma Linker_Section (
7263 -- [Entity =>] LOCAL_NAME
7264 -- [Section =>] static_string_EXPRESSION);
7266 when Pragma_Linker_Section =>
7268 Check_Arg_Count (2);
7269 Check_Optional_Identifier (Arg1, Name_Entity);
7270 Check_Optional_Identifier (Arg2, Name_Section);
7271 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7272 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7274 -- The only processing required is to link this item on to the
7275 -- list of rep items for the given entity. This is accomplished
7276 -- by the call to Rep_Item_Too_Late (when no error is detected
7277 -- and False is returned).
7279 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7282 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7289 -- pragma List (On | Off)
7291 -- There is nothing to do here, since we did all the processing
7292 -- for this pragma in Par.Prag (so that it works properly even in
7293 -- syntax only mode)
7298 --------------------
7299 -- Locking_Policy --
7300 --------------------
7302 -- pragma Locking_Policy (policy_IDENTIFIER);
7304 when Pragma_Locking_Policy => declare
7308 Check_Ada_83_Warning;
7309 Check_Arg_Count (1);
7310 Check_No_Identifiers;
7311 Check_Arg_Is_Locking_Policy (Arg1);
7312 Check_Valid_Configuration_Pragma;
7313 Get_Name_String (Chars (Expression (Arg1)));
7314 LP := Fold_Upper (Name_Buffer (1));
7316 if Locking_Policy /= ' '
7317 and then Locking_Policy /= LP
7319 Error_Msg_Sloc := Locking_Policy_Sloc;
7320 Error_Pragma ("locking policy incompatible with policy#");
7322 -- Set new policy, but always preserve System_Location since
7323 -- we like the error message with the run time name.
7326 Locking_Policy := LP;
7328 if Locking_Policy_Sloc /= System_Location then
7329 Locking_Policy_Sloc := Loc;
7338 -- pragma Long_Float (D_Float | G_Float);
7340 when Pragma_Long_Float =>
7342 Check_Valid_Configuration_Pragma;
7343 Check_Arg_Count (1);
7344 Check_No_Identifier (Arg1);
7345 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7347 if not OpenVMS_On_Target then
7348 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7353 if Chars (Expression (Arg1)) = Name_D_Float then
7354 if Opt.Float_Format_Long = 'G' then
7355 Error_Pragma ("G_Float previously specified");
7358 Opt.Float_Format_Long := 'D';
7360 -- G_Float case (this is the default, does not need overriding)
7363 if Opt.Float_Format_Long = 'D' then
7364 Error_Pragma ("D_Float previously specified");
7367 Opt.Float_Format_Long := 'G';
7370 Set_Standard_Fpt_Formats;
7372 -----------------------
7373 -- Machine_Attribute --
7374 -----------------------
7376 -- pragma Machine_Attribute (
7377 -- [Entity =>] LOCAL_NAME,
7378 -- [Attribute_Name =>] static_string_EXPRESSION
7379 -- [,[Info =>] static_string_EXPRESSION] );
7381 when Pragma_Machine_Attribute => Machine_Attribute : declare
7387 if Arg_Count = 3 then
7388 Check_Optional_Identifier (Arg3, "info");
7389 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7391 Check_Arg_Count (2);
7394 Check_Arg_Is_Local_Name (Arg1);
7395 Check_Optional_Identifier (Arg2, "attribute_name");
7396 Check_Optional_Identifier (Arg1, Name_Entity);
7397 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7398 Def_Id := Entity (Expression (Arg1));
7400 if Is_Access_Type (Def_Id) then
7401 Def_Id := Designated_Type (Def_Id);
7404 if Rep_Item_Too_Early (Def_Id, N) then
7408 Def_Id := Underlying_Type (Def_Id);
7410 -- The only processing required is to link this item on to the
7411 -- list of rep items for the given entity. This is accomplished
7412 -- by the call to Rep_Item_Too_Late (when no error is detected
7413 -- and False is returned).
7415 if Rep_Item_Too_Late (Def_Id, N) then
7418 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7420 end Machine_Attribute;
7426 -- pragma Main_Storage
7427 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7429 -- MAIN_STORAGE_OPTION ::=
7430 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7431 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7433 when Pragma_Main => Main : declare
7434 Args : Args_List (1 .. 3);
7435 Names : constant Name_List (1 .. 3) := (
7437 Name_Task_Stack_Size_Default,
7438 Name_Time_Slicing_Enabled);
7444 Gather_Associations (Names, Args);
7446 for J in 1 .. 2 loop
7447 if Present (Args (J)) then
7448 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7452 if Present (Args (3)) then
7453 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7457 while Present (Nod) loop
7458 if Nkind (Nod) = N_Pragma
7459 and then Chars (Nod) = Name_Main
7461 Error_Msg_Name_1 := Chars (N);
7462 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7473 -- pragma Main_Storage
7474 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7476 -- MAIN_STORAGE_OPTION ::=
7477 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7478 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7480 when Pragma_Main_Storage => Main_Storage : declare
7481 Args : Args_List (1 .. 2);
7482 Names : constant Name_List (1 .. 2) := (
7483 Name_Working_Storage,
7490 Gather_Associations (Names, Args);
7492 for J in 1 .. 2 loop
7493 if Present (Args (J)) then
7494 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7498 Check_In_Main_Program;
7501 while Present (Nod) loop
7502 if Nkind (Nod) = N_Pragma
7503 and then Chars (Nod) = Name_Main_Storage
7505 Error_Msg_Name_1 := Chars (N);
7506 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7517 -- pragma Memory_Size (NUMERIC_LITERAL)
7519 when Pragma_Memory_Size =>
7522 -- Memory size is simply ignored
7524 Check_No_Identifiers;
7525 Check_Arg_Count (1);
7526 Check_Arg_Is_Integer_Literal (Arg1);
7532 -- pragma No_Return (procedure_LOCAL_NAME);
7534 when Pragma_No_Return => No_Return : declare
7541 Check_Arg_Count (1);
7542 Check_No_Identifiers;
7543 Check_Arg_Is_Local_Name (Arg1);
7544 Id := Expression (Arg1);
7547 if not Is_Entity_Name (Id) then
7548 Error_Pragma_Arg ("entity name required", Arg1);
7551 if Etype (Id) = Any_Type then
7559 and then Scope (E) = Current_Scope
7561 if Ekind (E) = E_Procedure
7562 or else Ekind (E) = E_Generic_Procedure
7572 Error_Pragma ("no procedures found for pragma%");
7576 ------------------------
7577 -- No_Strict_Aliasing --
7578 ------------------------
7580 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
7585 Check_At_Most_N_Arguments (1);
7587 if Arg_Count = 0 then
7588 Check_Valid_Configuration_Pragma;
7589 Opt.No_Strict_Aliasing := True;
7592 Check_Optional_Identifier (Arg2, Name_Entity);
7593 Check_Arg_Is_Local_Name (Arg1);
7594 E_Id := Entity (Expression (Arg1));
7596 if E_Id = Any_Type then
7598 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
7599 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7602 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
7604 end No_Strict_Alias;
7610 -- pragma Obsolescent [(static_string_EXPRESSION)];
7612 when Pragma_Obsolescent => Obsolescent : declare
7615 Check_At_Most_N_Arguments (1);
7616 Check_No_Identifiers;
7618 if Arg_Count = 1 then
7619 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7623 or else (Nkind (Prev (N))) /= N_Subprogram_Declaration
7626 ("pragma% misplaced, must immediately " &
7627 "follow subprogram spec");
7635 -- pragma No_Run_Time
7637 -- Note: this pragma is retained for backwards compatibiltiy.
7638 -- See body of Rtsfind for full details on its handling.
7640 when Pragma_No_Run_Time =>
7642 Check_Valid_Configuration_Pragma;
7643 Check_Arg_Count (0);
7645 No_Run_Time_Mode := True;
7646 Configurable_Run_Time_Mode := True;
7649 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
7652 Duration_32_Bits_On_Target := True;
7656 Set_Restriction (No_Finalization, N);
7657 Set_Restriction (No_Exception_Handlers, N);
7658 Set_Restriction (Max_Tasks, N, 0);
7659 Set_Restriction (No_Tasking, N);
7661 -----------------------
7662 -- Normalize_Scalars --
7663 -----------------------
7665 -- pragma Normalize_Scalars;
7667 when Pragma_Normalize_Scalars =>
7668 Check_Ada_83_Warning;
7669 Check_Arg_Count (0);
7670 Check_Valid_Configuration_Pragma;
7671 Normalize_Scalars := True;
7672 Init_Or_Norm_Scalars := True;
7678 -- pragma Optimize (Time | Space);
7680 -- The actual check for optimize is done in Gigi. Note that this
7681 -- pragma does not actually change the optimization setting, it
7682 -- simply checks that it is consistent with the pragma.
7684 when Pragma_Optimize =>
7685 Check_No_Identifiers;
7686 Check_Arg_Count (1);
7687 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
7689 -------------------------
7690 -- Optional_Overriding --
7691 -------------------------
7693 -- These pragmas are treated as part of the previous subprogram
7694 -- declaration, and analyzed immediately after it (see sem_ch6,
7695 -- Check_Overriding_Operation). If the pragma has not been analyzed
7696 -- yet, it appears in the wrong place.
7698 when Pragma_Optional_Overriding =>
7699 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7705 when Pragma_Overriding =>
7706 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7712 -- pragma Pack (first_subtype_LOCAL_NAME);
7714 when Pragma_Pack => Pack : declare
7715 Assoc : constant Node_Id := Arg1;
7720 Check_No_Identifiers;
7721 Check_Arg_Count (1);
7722 Check_Arg_Is_Local_Name (Arg1);
7724 Type_Id := Expression (Assoc);
7725 Find_Type (Type_Id);
7726 Typ := Entity (Type_Id);
7729 or else Rep_Item_Too_Early (Typ, N)
7733 Typ := Underlying_Type (Typ);
7736 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
7737 Error_Pragma ("pragma% must specify array or record type");
7740 Check_First_Subtype (Arg1);
7742 if Has_Pragma_Pack (Typ) then
7743 Error_Pragma ("duplicate pragma%, only one allowed");
7745 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
7746 -- but not Has_Non_Standard_Rep, because we don't actually know
7747 -- till freeze time if the array can have packed representation.
7748 -- That's because in the general case we do not know enough about
7749 -- the component type until it in turn is frozen, which certainly
7750 -- happens before the array type is frozen, but not necessarily
7751 -- till that point (i.e. right now it may be unfrozen).
7753 elsif Is_Array_Type (Typ) then
7754 if Has_Aliased_Components (Base_Type (Typ)) then
7756 ("pragma% ignored, cannot pack aliased components?");
7758 elsif Has_Atomic_Components (Typ)
7759 or else Is_Atomic (Component_Type (Typ))
7762 ("?pragma% ignored, cannot pack atomic components");
7764 elsif not Rep_Item_Too_Late (Typ, N) then
7765 Set_Is_Packed (Base_Type (Typ));
7766 Set_Has_Pragma_Pack (Base_Type (Typ));
7767 Set_Has_Non_Standard_Rep (Base_Type (Typ));
7770 -- Record type. For record types, the pack is always effective
7772 else pragma Assert (Is_Record_Type (Typ));
7773 if not Rep_Item_Too_Late (Typ, N) then
7774 Set_Has_Pragma_Pack (Base_Type (Typ));
7775 Set_Is_Packed (Base_Type (Typ));
7776 Set_Has_Non_Standard_Rep (Base_Type (Typ));
7787 -- There is nothing to do here, since we did all the processing
7788 -- for this pragma in Par.Prag (so that it works properly even in
7789 -- syntax only mode)
7798 -- pragma Passive [(PASSIVE_FORM)];
7800 -- PASSIVE_FORM ::= Semaphore | No
7802 when Pragma_Passive =>
7805 if Nkind (Parent (N)) /= N_Task_Definition then
7806 Error_Pragma ("pragma% must be within task definition");
7809 if Arg_Count /= 0 then
7810 Check_Arg_Count (1);
7811 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
7818 -- pragma Polling (ON | OFF);
7820 when Pragma_Polling =>
7822 Check_Arg_Count (1);
7823 Check_No_Identifiers;
7824 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7825 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
7827 ---------------------
7828 -- Persistent_Data --
7829 ---------------------
7831 when Pragma_Persistent_Data => declare
7835 -- Register the pragma as applying to the compilation unit.
7836 -- Individual Persistent_Object pragmas for relevant objects
7837 -- are generated the end of the compilation.
7840 Check_Valid_Configuration_Pragma;
7841 Check_Arg_Count (0);
7842 Ent := Find_Lib_Unit_Name;
7843 Set_Is_Preelaborated (Ent);
7846 -----------------------
7847 -- Persistent_Object --
7848 -----------------------
7850 when Pragma_Persistent_Object => declare
7858 Check_Arg_Count (1);
7859 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7861 if not Is_Entity_Name (Expression (Arg1))
7863 (Ekind (Entity (Expression (Arg1))) /= E_Variable
7864 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
7866 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
7869 Ent := Entity (Expression (Arg1));
7870 Decl := Parent (Ent);
7872 if Nkind (Decl) /= N_Object_Declaration then
7876 -- Placement of the object depends on whether there is
7877 -- an initial value or none. If the No_Initialization flag
7878 -- is set, the initialization has been transformed into
7879 -- assignments, which is disallowed elaboration code.
7881 if No_Initialization (Decl) then
7883 ("initialization for persistent object"
7884 & "must be static expression", Decl);
7888 if No (Expression (Decl)) then
7890 Store_String_Chars ("section ("".persistent.bss"")");
7894 if not Is_OK_Static_Expression (Expression (Decl)) then
7895 Flag_Non_Static_Expr
7896 ("initialization for persistent object"
7897 & "must be static expression!", Expression (Decl));
7902 Store_String_Chars ("section ("".persistent.data"")");
7909 Name_Machine_Attribute,
7911 (Make_Pragma_Argument_Association
7912 (Sloc => Sloc (Arg1),
7913 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
7914 Make_Pragma_Argument_Association
7915 (Sloc => Sloc (Arg1),
7918 (Sloc => Sloc (Arg1),
7921 Insert_After (N, MA);
7923 Set_Has_Gigi_Rep_Item (Ent);
7930 -- pragma Preelaborate [(library_unit_NAME)];
7932 -- Set the flag Is_Preelaborated of program unit name entity
7934 when Pragma_Preelaborate => Preelaborate : declare
7935 Pa : constant Node_Id := Parent (N);
7936 Pk : constant Node_Kind := Nkind (Pa);
7940 Check_Ada_83_Warning;
7941 Check_Valid_Library_Unit_Pragma;
7943 if Nkind (N) = N_Null_Statement then
7947 Ent := Find_Lib_Unit_Name;
7949 -- This filters out pragmas inside generic parent then
7950 -- show up inside instantiation
7953 and then not (Pk = N_Package_Specification
7954 and then Present (Generic_Parent (Pa)))
7956 if not Debug_Flag_U then
7957 Set_Is_Preelaborated (Ent);
7958 Set_Suppress_Elaboration_Warnings (Ent);
7967 -- pragma Priority (EXPRESSION);
7969 when Pragma_Priority => Priority : declare
7970 P : constant Node_Id := Parent (N);
7974 Check_No_Identifiers;
7975 Check_Arg_Count (1);
7979 if Nkind (P) = N_Subprogram_Body then
7980 Check_In_Main_Program;
7982 Arg := Expression (Arg1);
7983 Analyze_And_Resolve (Arg, Standard_Integer);
7987 if not Is_Static_Expression (Arg) then
7988 Flag_Non_Static_Expr
7989 ("main subprogram priority is not static!", Arg);
7992 -- If constraint error, then we already signalled an error
7994 elsif Raises_Constraint_Error (Arg) then
7997 -- Otherwise check in range
8001 Val : constant Uint := Expr_Value (Arg);
8005 or else Val > Expr_Value (Expression
8006 (Parent (RTE (RE_Max_Priority))))
8009 ("main subprogram priority is out of range", Arg1);
8015 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8017 -- Task or Protected, must be of type Integer
8019 elsif Nkind (P) = N_Protected_Definition
8021 Nkind (P) = N_Task_Definition
8023 Arg := Expression (Arg1);
8025 -- The expression must be analyzed in the special manner
8026 -- described in "Handling of Default and Per-Object
8027 -- Expressions" in sem.ads.
8029 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8031 if not Is_Static_Expression (Arg) then
8032 Check_Restriction (Static_Priorities, Arg);
8035 -- Anything else is incorrect
8041 if Has_Priority_Pragma (P) then
8042 Error_Pragma ("duplicate pragma% not allowed");
8044 Set_Has_Priority_Pragma (P, True);
8046 if Nkind (P) = N_Protected_Definition
8048 Nkind (P) = N_Task_Definition
8050 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8051 -- exp_ch9 should use this ???
8060 -- pragma Profile (profile_IDENTIFIER);
8062 -- profile_IDENTIFIER => Ravenscar
8064 when Pragma_Profile =>
8066 Check_Arg_Count (1);
8067 Check_Valid_Configuration_Pragma;
8068 Check_No_Identifiers;
8072 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8074 if Chars (Argx) = Name_Ravenscar then
8077 Error_Pragma_Arg ("& is not a valid profile", Argx);
8081 --------------------------
8082 -- Propagate_Exceptions --
8083 --------------------------
8085 -- pragma Propagate_Exceptions;
8087 when Pragma_Propagate_Exceptions =>
8089 Check_Arg_Count (0);
8091 if In_Extended_Main_Source_Unit (N) then
8092 Propagate_Exceptions := True;
8099 -- pragma Psect_Object (
8100 -- [Internal =>] LOCAL_NAME,
8101 -- [, [External =>] EXTERNAL_SYMBOL]
8102 -- [, [Size =>] EXTERNAL_SYMBOL]);
8104 when Pragma_Psect_Object | Pragma_Common_Object =>
8105 Psect_Object : declare
8106 Args : Args_List (1 .. 3);
8107 Names : constant Name_List (1 .. 3) := (
8112 Internal : Node_Id renames Args (1);
8113 External : Node_Id renames Args (2);
8114 Size : Node_Id renames Args (3);
8116 R_Internal : Node_Id;
8117 R_External : Node_Id;
8124 procedure Check_Too_Long (Arg : Node_Id);
8125 -- Posts message if the argument is an identifier with more
8126 -- than 31 characters, or a string literal with more than
8127 -- 31 characters, and we are operating under VMS
8129 --------------------
8130 -- Check_Too_Long --
8131 --------------------
8133 procedure Check_Too_Long (Arg : Node_Id) is
8134 X : constant Node_Id := Original_Node (Arg);
8137 if Nkind (X) /= N_String_Literal
8139 Nkind (X) /= N_Identifier
8142 ("inappropriate argument for pragma %", Arg);
8145 if OpenVMS_On_Target then
8146 if (Nkind (X) = N_String_Literal
8147 and then String_Length (Strval (X)) > 31)
8149 (Nkind (X) = N_Identifier
8150 and then Length_Of_Name (Chars (X)) > 31)
8153 ("argument for pragma % is longer than 31 characters",
8159 -- Start of processing for Common_Object/Psect_Object
8163 Gather_Associations (Names, Args);
8164 Process_Extended_Import_Export_Internal_Arg (Internal);
8166 R_Internal := Relocate_Node (Internal);
8168 Def_Id := Entity (R_Internal);
8170 if Ekind (Def_Id) /= E_Constant
8171 and then Ekind (Def_Id) /= E_Variable
8174 ("pragma% must designate an object", Internal);
8177 Check_Too_Long (R_Internal);
8179 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8181 ("cannot use pragma% for imported/exported object",
8185 if Is_Concurrent_Type (Etype (R_Internal)) then
8187 ("cannot specify pragma % for task/protected object",
8191 if Is_Psected (Def_Id) then
8192 Error_Msg_N ("?duplicate Psect_Object pragma", N);
8194 Set_Is_Psected (Def_Id);
8197 if Ekind (Def_Id) = E_Constant then
8199 ("cannot specify pragma % for a constant", R_Internal);
8202 if Is_Record_Type (Etype (R_Internal)) then
8208 Ent := First_Entity (Etype (R_Internal));
8209 while Present (Ent) loop
8210 Decl := Declaration_Node (Ent);
8212 if Ekind (Ent) = E_Component
8213 and then Nkind (Decl) = N_Component_Declaration
8214 and then Present (Expression (Decl))
8215 and then Warn_On_Export_Import
8218 ("?object for pragma % has defaults", R_Internal);
8228 if Present (Size) then
8229 Check_Too_Long (Size);
8232 -- Make Psect case-insensitive.
8234 if Present (External) then
8235 Check_Too_Long (External);
8237 if Nkind (External) = N_String_Literal then
8238 String_To_Name_Buffer (Strval (External));
8240 Get_Name_String (Chars (External));
8245 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8247 R_External := Make_String_Literal
8248 (Sloc => Sloc (External), Strval => Str);
8250 Get_Name_String (Chars (Internal));
8253 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8255 R_External := Make_String_Literal
8256 (Sloc => Sloc (Internal), Strval => Str);
8259 -- Transform into pragma Linker_Section, add attributes to
8260 -- match what DEC Ada does. Ignore size for now?
8265 Name_Linker_Section,
8267 (Make_Pragma_Argument_Association
8268 (Sloc => Sloc (R_Internal),
8269 Expression => R_Internal),
8270 Make_Pragma_Argument_Association
8271 (Sloc => Sloc (R_External),
8272 Expression => R_External))));
8276 -- Add Machine_Attribute of "overlaid", so the section overlays
8277 -- other sections of the same name.
8280 Store_String_Chars ("overlaid");
8286 Name_Machine_Attribute,
8288 (Make_Pragma_Argument_Association
8289 (Sloc => Sloc (R_Internal),
8290 Expression => R_Internal),
8291 Make_Pragma_Argument_Association
8292 (Sloc => Sloc (R_External),
8295 (Sloc => Sloc (R_External),
8299 -- Add Machine_Attribute of "global", so the section is visible
8303 Store_String_Chars ("global");
8309 Name_Machine_Attribute,
8311 (Make_Pragma_Argument_Association
8312 (Sloc => Sloc (R_Internal),
8313 Expression => R_Internal),
8315 Make_Pragma_Argument_Association
8316 (Sloc => Sloc (R_External),
8319 (Sloc => Sloc (R_External),
8323 -- Add Machine_Attribute of "initialize", so the section is
8327 Store_String_Chars ("initialize");
8333 Name_Machine_Attribute,
8335 (Make_Pragma_Argument_Association
8336 (Sloc => Sloc (R_Internal),
8337 Expression => R_Internal),
8339 Make_Pragma_Argument_Association
8340 (Sloc => Sloc (R_External),
8343 (Sloc => Sloc (R_External),
8352 -- pragma Pure [(library_unit_NAME)];
8354 when Pragma_Pure => Pure : declare
8357 Check_Ada_83_Warning;
8358 Check_Valid_Library_Unit_Pragma;
8360 if Nkind (N) = N_Null_Statement then
8364 Ent := Find_Lib_Unit_Name;
8366 Set_Suppress_Elaboration_Warnings (Ent);
8373 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8375 when Pragma_Pure_Function => Pure_Function : declare
8379 Effective : Boolean := False;
8383 Check_Arg_Count (1);
8384 Check_Optional_Identifier (Arg1, Name_Entity);
8385 Check_Arg_Is_Local_Name (Arg1);
8386 E_Id := Expression (Arg1);
8388 if Error_Posted (E_Id) then
8392 -- Loop through homonyms (overloadings) of referenced entity
8398 Def_Id := Get_Base_Subprogram (E);
8400 if Ekind (Def_Id) /= E_Function
8401 and then Ekind (Def_Id) /= E_Generic_Function
8402 and then Ekind (Def_Id) /= E_Operator
8405 ("pragma% requires a function name", Arg1);
8408 Set_Is_Pure (Def_Id);
8410 if not Has_Pragma_Pure_Function (Def_Id) then
8411 Set_Has_Pragma_Pure_Function (Def_Id);
8416 exit when No (E) or else Scope (E) /= Current_Scope;
8420 and then Warn_On_Redundant_Constructs
8422 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8428 --------------------
8429 -- Queuing_Policy --
8430 --------------------
8432 -- pragma Queuing_Policy (policy_IDENTIFIER);
8434 when Pragma_Queuing_Policy => declare
8438 Check_Ada_83_Warning;
8439 Check_Arg_Count (1);
8440 Check_No_Identifiers;
8441 Check_Arg_Is_Queuing_Policy (Arg1);
8442 Check_Valid_Configuration_Pragma;
8443 Get_Name_String (Chars (Expression (Arg1)));
8444 QP := Fold_Upper (Name_Buffer (1));
8446 if Queuing_Policy /= ' '
8447 and then Queuing_Policy /= QP
8449 Error_Msg_Sloc := Queuing_Policy_Sloc;
8450 Error_Pragma ("queuing policy incompatible with policy#");
8452 -- Set new policy, but always preserve System_Location since
8453 -- we like the error message with the run time name.
8456 Queuing_Policy := QP;
8458 if Queuing_Policy_Sloc /= System_Location then
8459 Queuing_Policy_Sloc := Loc;
8464 ---------------------------
8465 -- Remote_Call_Interface --
8466 ---------------------------
8468 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8470 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8471 Cunit_Node : Node_Id;
8472 Cunit_Ent : Entity_Id;
8476 Check_Ada_83_Warning;
8477 Check_Valid_Library_Unit_Pragma;
8479 if Nkind (N) = N_Null_Statement then
8483 Cunit_Node := Cunit (Current_Sem_Unit);
8484 K := Nkind (Unit (Cunit_Node));
8485 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8487 if K = N_Package_Declaration
8488 or else K = N_Generic_Package_Declaration
8489 or else K = N_Subprogram_Declaration
8490 or else K = N_Generic_Subprogram_Declaration
8491 or else (K = N_Subprogram_Body
8492 and then Acts_As_Spec (Unit (Cunit_Node)))
8497 "pragma% must apply to package or subprogram declaration");
8500 Set_Is_Remote_Call_Interface (Cunit_Ent);
8501 end Remote_Call_Interface;
8507 -- pragma Remote_Types [(library_unit_NAME)];
8509 when Pragma_Remote_Types => Remote_Types : declare
8510 Cunit_Node : Node_Id;
8511 Cunit_Ent : Entity_Id;
8514 Check_Ada_83_Warning;
8515 Check_Valid_Library_Unit_Pragma;
8517 if Nkind (N) = N_Null_Statement then
8521 Cunit_Node := Cunit (Current_Sem_Unit);
8522 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8524 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8526 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8529 "pragma% can only apply to a package declaration");
8532 Set_Is_Remote_Types (Cunit_Ent);
8539 -- pragma Ravenscar;
8541 when Pragma_Ravenscar =>
8543 Check_Arg_Count (0);
8544 Check_Valid_Configuration_Pragma;
8547 -------------------------
8548 -- Restricted_Run_Time --
8549 -------------------------
8551 -- pragma Restricted_Run_Time;
8553 when Pragma_Restricted_Run_Time =>
8555 Check_Arg_Count (0);
8556 Check_Valid_Configuration_Pragma;
8557 Set_Restricted_Profile (N);
8563 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8566 -- restriction_IDENTIFIER
8567 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8569 when Pragma_Restrictions =>
8570 Process_Restrictions_Or_Restriction_Warnings;
8572 --------------------------
8573 -- Restriction_Warnings --
8574 --------------------------
8576 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8579 -- restriction_IDENTIFIER
8580 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8582 when Pragma_Restriction_Warnings =>
8583 Process_Restrictions_Or_Restriction_Warnings;
8589 -- pragma Reviewable;
8591 when Pragma_Reviewable =>
8592 Check_Ada_83_Warning;
8593 Check_Arg_Count (0);
8599 -- pragma Share_Generic (NAME {, NAME});
8601 when Pragma_Share_Generic =>
8603 Process_Generic_List;
8609 -- pragma Shared (LOCAL_NAME);
8611 when Pragma_Shared =>
8613 Process_Atomic_Shared_Volatile;
8615 --------------------
8616 -- Shared_Passive --
8617 --------------------
8619 -- pragma Shared_Passive [(library_unit_NAME)];
8621 -- Set the flag Is_Shared_Passive of program unit name entity
8623 when Pragma_Shared_Passive => Shared_Passive : declare
8624 Cunit_Node : Node_Id;
8625 Cunit_Ent : Entity_Id;
8628 Check_Ada_83_Warning;
8629 Check_Valid_Library_Unit_Pragma;
8631 if Nkind (N) = N_Null_Statement then
8635 Cunit_Node := Cunit (Current_Sem_Unit);
8636 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8638 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8640 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8643 "pragma% can only apply to a package declaration");
8646 Set_Is_Shared_Passive (Cunit_Ent);
8649 ----------------------
8650 -- Source_File_Name --
8651 ----------------------
8653 -- There are five forms for this pragma:
8655 -- pragma Source_File_Name (
8656 -- [UNIT_NAME =>] unit_NAME,
8657 -- BODY_FILE_NAME => STRING_LITERAL
8658 -- [, [INDEX =>] INTEGER_LITERAL]);
8660 -- pragma Source_File_Name (
8661 -- [UNIT_NAME =>] unit_NAME,
8662 -- SPEC_FILE_NAME => STRING_LITERAL
8663 -- [, [INDEX =>] INTEGER_LITERAL]);
8665 -- pragma Source_File_Name (
8666 -- BODY_FILE_NAME => STRING_LITERAL
8667 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8668 -- [, CASING => CASING_SPEC]);
8670 -- pragma Source_File_Name (
8671 -- SPEC_FILE_NAME => STRING_LITERAL
8672 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8673 -- [, CASING => CASING_SPEC]);
8675 -- pragma Source_File_Name (
8676 -- SUBUNIT_FILE_NAME => STRING_LITERAL
8677 -- [, DOT_REPLACEMENT => STRING_LITERAL]
8678 -- [, CASING => CASING_SPEC]);
8680 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
8682 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
8683 -- Source_File_Name (SFN), however their usage is exclusive:
8684 -- SFN can only be used when no project file is used, while
8685 -- SFNP can only be used when a project file is used.
8687 -- No processing here. Processing was completed during parsing,
8688 -- since we need to have file names set as early as possible.
8689 -- Units are loaded well before semantic processing starts.
8691 -- The only processing we defer to this point is the check
8692 -- for correct placement.
8694 when Pragma_Source_File_Name =>
8696 Check_Valid_Configuration_Pragma;
8698 ------------------------------
8699 -- Source_File_Name_Project --
8700 ------------------------------
8702 -- See Source_File_Name for syntax
8704 -- No processing here. Processing was completed during parsing,
8705 -- since we need to have file names set as early as possible.
8706 -- Units are loaded well before semantic processing starts.
8708 -- The only processing we defer to this point is the check
8709 -- for correct placement.
8711 when Pragma_Source_File_Name_Project =>
8713 Check_Valid_Configuration_Pragma;
8715 -- Check that a pragma Source_File_Name_Project is used only
8716 -- in a configuration pragmas file.
8718 -- Pragmas Source_File_Name_Project should only be generated
8719 -- by the Project Manager in configuration pragmas files.
8721 -- This is really an ugly test. It seems to depend on some
8722 -- accidental and undocumented property. At the very least
8723 -- it needs to be documented, but it would be better to have
8724 -- a clean way of testing if we are in a configuration file???
8726 if Present (Parent (N)) then
8728 ("pragma% can only appear in a configuration pragmas file");
8731 ----------------------
8732 -- Source_Reference --
8733 ----------------------
8735 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
8737 -- Nothing to do, all processing completed in Par.Prag, since we
8738 -- need the information for possible parser messages that are output
8740 when Pragma_Source_Reference =>
8747 -- pragma Storage_Size (EXPRESSION);
8749 when Pragma_Storage_Size => Storage_Size : declare
8750 P : constant Node_Id := Parent (N);
8754 Check_No_Identifiers;
8755 Check_Arg_Count (1);
8757 -- The expression must be analyzed in the special manner
8758 -- described in "Handling of Default Expressions" in sem.ads.
8760 -- Set In_Default_Expression for per-object case ???
8762 Arg := Expression (Arg1);
8763 Analyze_Per_Use_Expression (Arg, Any_Integer);
8765 if not Is_Static_Expression (Arg) then
8766 Check_Restriction (Static_Storage_Size, Arg);
8769 if Nkind (P) /= N_Task_Definition then
8774 if Has_Storage_Size_Pragma (P) then
8775 Error_Pragma ("duplicate pragma% not allowed");
8777 Set_Has_Storage_Size_Pragma (P, True);
8780 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8781 -- ??? exp_ch9 should use this!
8789 -- pragma Storage_Unit (NUMERIC_LITERAL);
8791 -- Only permitted argument is System'Storage_Unit value
8793 when Pragma_Storage_Unit =>
8794 Check_No_Identifiers;
8795 Check_Arg_Count (1);
8796 Check_Arg_Is_Integer_Literal (Arg1);
8798 if Intval (Expression (Arg1)) /=
8799 UI_From_Int (Ttypes.System_Storage_Unit)
8801 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
8803 ("the only allowed argument for pragma% is ^", Arg1);
8806 --------------------
8807 -- Stream_Convert --
8808 --------------------
8810 -- pragma Stream_Convert (
8811 -- [Entity =>] type_LOCAL_NAME,
8812 -- [Read =>] function_NAME,
8813 -- [Write =>] function NAME);
8815 when Pragma_Stream_Convert => Stream_Convert : declare
8817 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
8818 -- Check that the given argument is the name of a local
8819 -- function of one argument that is not overloaded earlier
8820 -- in the current local scope. A check is also made that the
8821 -- argument is a function with one parameter.
8823 --------------------------------------
8824 -- Check_OK_Stream_Convert_Function --
8825 --------------------------------------
8827 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
8831 Check_Arg_Is_Local_Name (Arg);
8832 Ent := Entity (Expression (Arg));
8834 if Has_Homonym (Ent) then
8836 ("argument for pragma% may not be overloaded", Arg);
8839 if Ekind (Ent) /= E_Function
8840 or else No (First_Formal (Ent))
8841 or else Present (Next_Formal (First_Formal (Ent)))
8844 ("argument for pragma% must be" &
8845 " function of one argument", Arg);
8847 end Check_OK_Stream_Convert_Function;
8849 -- Start of procecessing for Stream_Convert
8853 Check_Arg_Count (3);
8854 Check_Optional_Identifier (Arg1, Name_Entity);
8855 Check_Optional_Identifier (Arg2, Name_Read);
8856 Check_Optional_Identifier (Arg3, Name_Write);
8857 Check_Arg_Is_Local_Name (Arg1);
8858 Check_OK_Stream_Convert_Function (Arg2);
8859 Check_OK_Stream_Convert_Function (Arg3);
8862 Typ : constant Entity_Id :=
8863 Underlying_Type (Entity (Expression (Arg1)));
8864 Read : constant Entity_Id := Entity (Expression (Arg2));
8865 Write : constant Entity_Id := Entity (Expression (Arg3));
8868 if Etype (Typ) = Any_Type
8870 Etype (Read) = Any_Type
8872 Etype (Write) = Any_Type
8877 Check_First_Subtype (Arg1);
8879 if Rep_Item_Too_Early (Typ, N)
8881 Rep_Item_Too_Late (Typ, N)
8886 if Underlying_Type (Etype (Read)) /= Typ then
8888 ("incorrect return type for function&", Arg2);
8891 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
8893 ("incorrect parameter type for function&", Arg3);
8896 if Underlying_Type (Etype (First_Formal (Read))) /=
8897 Underlying_Type (Etype (Write))
8900 ("result type of & does not match Read parameter type",
8906 -------------------------
8907 -- Style_Checks (GNAT) --
8908 -------------------------
8910 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
8912 -- This is processed by the parser since some of the style
8913 -- checks take place during source scanning and parsing. This
8914 -- means that we don't need to issue error messages here.
8916 when Pragma_Style_Checks => Style_Checks : declare
8917 A : constant Node_Id := Expression (Arg1);
8923 Check_No_Identifiers;
8925 -- Two argument form
8927 if Arg_Count = 2 then
8928 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8935 E_Id := Expression (Arg2);
8938 if not Is_Entity_Name (E_Id) then
8940 ("second argument of pragma% must be entity name",
8950 Set_Suppress_Style_Checks (E,
8951 (Chars (Expression (Arg1)) = Name_Off));
8952 exit when No (Homonym (E));
8958 -- One argument form
8961 Check_Arg_Count (1);
8963 if Nkind (A) = N_String_Literal then
8967 Slen : constant Natural := Natural (String_Length (S));
8968 Options : String (1 .. Slen);
8974 C := Get_String_Char (S, Int (J));
8975 exit when not In_Character_Range (C);
8976 Options (J) := Get_Character (C);
8979 Set_Style_Check_Options (Options);
8987 elsif Nkind (A) = N_Identifier then
8989 if Chars (A) = Name_All_Checks then
8990 Set_Default_Style_Check_Options;
8992 elsif Chars (A) = Name_On then
8993 Style_Check := True;
8995 elsif Chars (A) = Name_Off then
8996 Style_Check := False;
9007 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9009 when Pragma_Subtitle =>
9011 Check_Arg_Count (1);
9012 Check_Optional_Identifier (Arg1, Name_Subtitle);
9013 Check_Arg_Is_String_Literal (Arg1);
9019 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9021 when Pragma_Suppress =>
9022 Process_Suppress_Unsuppress (True);
9028 -- pragma Suppress_All;
9030 -- The only check made here is that the pragma appears in the
9031 -- proper place, i.e. following a compilation unit. If indeed
9032 -- it appears in this context, then the parser has already
9033 -- inserted an equivalent pragma Suppress (All_Checks) to get
9034 -- the required effect.
9036 when Pragma_Suppress_All =>
9038 Check_Arg_Count (0);
9040 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9041 or else not Is_List_Member (N)
9042 or else List_Containing (N) /= Pragmas_After (Parent (N))
9045 ("misplaced pragma%, must follow compilation unit");
9048 -------------------------
9049 -- Suppress_Debug_Info --
9050 -------------------------
9052 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9054 when Pragma_Suppress_Debug_Info =>
9056 Check_Arg_Count (1);
9057 Check_Arg_Is_Local_Name (Arg1);
9058 Check_Optional_Identifier (Arg1, Name_Entity);
9059 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9061 ----------------------------------
9062 -- Suppress_Exception_Locations --
9063 ----------------------------------
9065 -- pragma Suppress_Exception_Locations;
9067 when Pragma_Suppress_Exception_Locations =>
9069 Check_Arg_Count (0);
9070 Check_Valid_Configuration_Pragma;
9071 Exception_Locations_Suppressed := True;
9073 -----------------------------
9074 -- Suppress_Initialization --
9075 -----------------------------
9077 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9079 when Pragma_Suppress_Initialization => Suppress_Init : declare
9085 Check_Arg_Count (1);
9086 Check_Optional_Identifier (Arg1, Name_Entity);
9087 Check_Arg_Is_Local_Name (Arg1);
9089 E_Id := Expression (Arg1);
9091 if Etype (E_Id) = Any_Type then
9098 if Is_Incomplete_Or_Private_Type (E) then
9099 if No (Full_View (Base_Type (E))) then
9101 ("argument of pragma% cannot be an incomplete type",
9104 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9107 Set_Suppress_Init_Proc (Base_Type (E));
9112 ("pragma% requires argument that is a type name", Arg1);
9120 -- pragma System_Name (DIRECT_NAME);
9122 -- Syntax check: one argument, which must be the identifier GNAT
9123 -- or the identifier GCC, no other identifiers are acceptable.
9125 when Pragma_System_Name =>
9126 Check_No_Identifiers;
9127 Check_Arg_Count (1);
9128 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9130 -----------------------------
9131 -- Task_Dispatching_Policy --
9132 -----------------------------
9134 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9136 when Pragma_Task_Dispatching_Policy => declare
9140 Check_Ada_83_Warning;
9141 Check_Arg_Count (1);
9142 Check_No_Identifiers;
9143 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9144 Check_Valid_Configuration_Pragma;
9145 Get_Name_String (Chars (Expression (Arg1)));
9146 DP := Fold_Upper (Name_Buffer (1));
9148 if Task_Dispatching_Policy /= ' '
9149 and then Task_Dispatching_Policy /= DP
9151 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9153 ("task dispatching policy incompatible with policy#");
9155 -- Set new policy, but always preserve System_Location since
9156 -- we like the error message with the run time name.
9159 Task_Dispatching_Policy := DP;
9161 if Task_Dispatching_Policy_Sloc /= System_Location then
9162 Task_Dispatching_Policy_Sloc := Loc;
9171 -- pragma Task_Info (EXPRESSION);
9173 when Pragma_Task_Info => Task_Info : declare
9174 P : constant Node_Id := Parent (N);
9179 if Nkind (P) /= N_Task_Definition then
9180 Error_Pragma ("pragma% must appear in task definition");
9183 Check_No_Identifiers;
9184 Check_Arg_Count (1);
9186 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9188 if Etype (Expression (Arg1)) = Any_Type then
9192 if Has_Task_Info_Pragma (P) then
9193 Error_Pragma ("duplicate pragma% not allowed");
9195 Set_Has_Task_Info_Pragma (P, True);
9203 -- pragma Task_Name (string_EXPRESSION);
9205 when Pragma_Task_Name => Task_Name : declare
9206 -- pragma Priority (EXPRESSION);
9208 P : constant Node_Id := Parent (N);
9212 Check_No_Identifiers;
9213 Check_Arg_Count (1);
9215 Arg := Expression (Arg1);
9216 Analyze_And_Resolve (Arg, Standard_String);
9218 if Nkind (P) /= N_Task_Definition then
9222 if Has_Task_Name_Pragma (P) then
9223 Error_Pragma ("duplicate pragma% not allowed");
9225 Set_Has_Task_Name_Pragma (P, True);
9226 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9234 -- pragma Task_Storage (
9235 -- [Task_Type =>] LOCAL_NAME,
9236 -- [Top_Guard =>] static_integer_EXPRESSION);
9238 when Pragma_Task_Storage => Task_Storage : declare
9239 Args : Args_List (1 .. 2);
9240 Names : constant Name_List (1 .. 2) := (
9244 Task_Type : Node_Id renames Args (1);
9245 Top_Guard : Node_Id renames Args (2);
9251 Gather_Associations (Names, Args);
9253 if No (Task_Type) then
9255 ("missing task_type argument for pragma%");
9258 Check_Arg_Is_Local_Name (Task_Type);
9260 Ent := Entity (Task_Type);
9262 if not Is_Task_Type (Ent) then
9264 ("argument for pragma% must be task type", Task_Type);
9267 if No (Top_Guard) then
9269 ("pragma% takes two arguments", Task_Type);
9271 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9274 Check_First_Subtype (Task_Type);
9276 if Rep_Item_Too_Late (Ent, N) then
9285 -- pragma Thread_Body
9286 -- ( [Entity =>] LOCAL_NAME
9287 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9289 when Pragma_Thread_Body => Thread_Body : declare
9296 Check_At_Least_N_Arguments (1);
9297 Check_At_Most_N_Arguments (2);
9298 Check_Optional_Identifier (Arg1, Name_Entity);
9299 Check_Arg_Is_Local_Name (Arg1);
9301 Id := Expression (Arg1);
9303 if not Is_Entity_Name (Id)
9304 or else not Is_Subprogram (Entity (Id))
9306 Error_Pragma_Arg ("subprogram name required", Arg1);
9311 -- Go to renamed subprogram if present, since Thread_Body applies
9312 -- to the actual renamed entity, not to the renaming entity.
9314 if Present (Alias (E))
9315 and then Nkind (Parent (Declaration_Node (E))) =
9316 N_Subprogram_Renaming_Declaration
9321 -- Various error checks
9323 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9325 ("pragma% requires separate spec and must come before body");
9327 elsif Rep_Item_Too_Early (E, N)
9329 Rep_Item_Too_Late (E, N)
9333 elsif Is_Thread_Body (E) then
9335 ("only one thread body pragma allowed", Arg1);
9337 elsif Present (Homonym (E))
9338 and then Scope (Homonym (E)) = Current_Scope
9341 ("thread body subprogram must not be overloaded", Arg1);
9344 Set_Is_Thread_Body (E);
9346 -- Deal with secondary stack argument
9348 if Arg_Count = 2 then
9349 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9350 SS := Expression (Arg2);
9351 Analyze_And_Resolve (SS, Any_Integer);
9359 -- pragma Time_Slice (static_duration_EXPRESSION);
9361 when Pragma_Time_Slice => Time_Slice : declare
9367 Check_Arg_Count (1);
9368 Check_No_Identifiers;
9369 Check_In_Main_Program;
9370 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9372 if not Error_Posted (Arg1) then
9374 while Present (Nod) loop
9375 if Nkind (Nod) = N_Pragma
9376 and then Chars (Nod) = Name_Time_Slice
9378 Error_Msg_Name_1 := Chars (N);
9379 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9386 -- Process only if in main unit
9388 if Get_Source_Unit (Loc) = Main_Unit then
9389 Opt.Time_Slice_Set := True;
9390 Val := Expr_Value_R (Expression (Arg1));
9392 if Val <= Ureal_0 then
9393 Opt.Time_Slice_Value := 0;
9395 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9396 Opt.Time_Slice_Value := 1_000_000_000;
9399 Opt.Time_Slice_Value :=
9400 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9409 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9411 -- TITLING_OPTION ::=
9412 -- [Title =>] STRING_LITERAL
9413 -- | [Subtitle =>] STRING_LITERAL
9415 when Pragma_Title => Title : declare
9416 Args : Args_List (1 .. 2);
9417 Names : constant Name_List (1 .. 2) := (
9423 Gather_Associations (Names, Args);
9425 for J in 1 .. 2 loop
9426 if Present (Args (J)) then
9427 Check_Arg_Is_String_Literal (Args (J));
9432 ---------------------
9433 -- Unchecked_Union --
9434 ---------------------
9436 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9438 when Pragma_Unchecked_Union => Unchecked_Union : declare
9439 Assoc : constant Node_Id := Arg1;
9440 Type_Id : constant Node_Id := Expression (Assoc);
9451 Check_No_Identifiers;
9452 Check_Arg_Count (1);
9453 Check_Arg_Is_Local_Name (Arg1);
9455 Find_Type (Type_Id);
9456 Typ := Entity (Type_Id);
9459 or else Rep_Item_Too_Early (Typ, N)
9463 Typ := Underlying_Type (Typ);
9466 if Rep_Item_Too_Late (Typ, N) then
9470 Check_First_Subtype (Arg1);
9472 -- Note remaining cases are references to a type in the current
9473 -- declarative part. If we find an error, we post the error on
9474 -- the relevant type declaration at an appropriate point.
9476 if not Is_Record_Type (Typ) then
9477 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9480 elsif Is_Tagged_Type (Typ) then
9481 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9484 elsif Is_Limited_Type (Typ) then
9486 ("Unchecked_Union must not be limited record type", Typ);
9487 Explain_Limited_Type (Typ, Typ);
9491 if not Has_Discriminants (Typ) then
9493 ("Unchecked_Union must have one discriminant", Typ);
9497 Discr := First_Discriminant (Typ);
9499 if Present (Next_Discriminant (Discr)) then
9501 ("Unchecked_Union must have exactly one discriminant",
9502 Next_Discriminant (Discr));
9506 if No (Discriminant_Default_Value (Discr)) then
9508 ("Unchecked_Union discriminant must have default value",
9512 Tdef := Type_Definition (Declaration_Node (Typ));
9513 Clist := Component_List (Tdef);
9515 if No (Clist) or else No (Variant_Part (Clist)) then
9517 ("Unchecked_Union must have variant part",
9522 Vpart := Variant_Part (Clist);
9524 if Is_Non_Empty_List (Component_Items (Clist)) then
9526 ("components before variant not allowed " &
9527 "in Unchecked_Union",
9528 First (Component_Items (Clist)));
9531 Variant := First (Variants (Vpart));
9532 while Present (Variant) loop
9533 Clist := Component_List (Variant);
9535 if Present (Variant_Part (Clist)) then
9537 ("Unchecked_Union may not have nested variants",
9538 Variant_Part (Clist));
9541 if not Is_Non_Empty_List (Component_Items (Clist)) then
9543 ("Unchecked_Union may not have empty component list",
9548 Comp := First (Component_Items (Clist));
9550 if Nkind (Comp) = N_Component_Declaration then
9552 if Present (Expression (Comp)) then
9554 ("default initialization not allowed " &
9555 "in Unchecked_Union",
9560 Sindic : constant Node_Id :=
9561 Subtype_Indication (Component_Definition (Comp));
9564 if Nkind (Sindic) = N_Subtype_Indication then
9565 Check_Static_Constraint (Constraint (Sindic));
9570 if Present (Next (Comp)) then
9572 ("Unchecked_Union variant can have only one component",
9580 Set_Is_Unchecked_Union (Typ, True);
9581 Set_Convention (Typ, Convention_C);
9583 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9584 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9585 end Unchecked_Union;
9587 ------------------------
9588 -- Unimplemented_Unit --
9589 ------------------------
9591 -- pragma Unimplemented_Unit;
9593 -- Note: this only gives an error if we are generating code,
9594 -- or if we are in a generic library unit (where the pragma
9595 -- appears in the body, not in the spec).
9597 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9598 Cunitent : constant Entity_Id :=
9599 Cunit_Entity (Get_Source_Unit (Loc));
9600 Ent_Kind : constant Entity_Kind :=
9605 Check_Arg_Count (0);
9607 if Operating_Mode = Generate_Code
9608 or else Ent_Kind = E_Generic_Function
9609 or else Ent_Kind = E_Generic_Procedure
9610 or else Ent_Kind = E_Generic_Package
9612 Get_Name_String (Chars (Cunitent));
9613 Set_Casing (Mixed_Case);
9614 Write_Str (Name_Buffer (1 .. Name_Len));
9615 Write_Str (" is not implemented");
9617 raise Unrecoverable_Error;
9619 end Unimplemented_Unit;
9621 --------------------
9622 -- Universal_Data --
9623 --------------------
9625 -- pragma Universal_Data [(library_unit_NAME)];
9627 when Pragma_Universal_Data =>
9630 -- If this is a configuration pragma, then set the universal
9631 -- addressing option, otherwise confirm that the pragma
9632 -- satisfies the requirements of library unit pragma placement
9633 -- and leave it to the GNAAMP back end to detect the pragma
9634 -- (avoids transitive setting of the option due to withed units).
9636 if Is_Configuration_Pragma then
9637 Universal_Addressing_On_AAMP := True;
9639 Check_Valid_Library_Unit_Pragma;
9642 if not AAMP_On_Target then
9643 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9650 -- pragma Unreferenced (local_Name {, local_Name});
9652 when Pragma_Unreferenced => Unreferenced : declare
9655 Arg_Ent : Entity_Id;
9659 Check_At_Least_N_Arguments (1);
9663 while Present (Arg_Node) loop
9664 Check_No_Identifier (Arg_Node);
9666 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9667 -- will in fact generate a reference, so that the entity will
9668 -- have a reference, which will inhibit any warnings about it
9669 -- not being referenced, and also properly show up in the ali
9670 -- file as a reference. But this reference is recorded before
9671 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9672 -- is generated for this reference.
9674 Check_Arg_Is_Local_Name (Arg_Node);
9675 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9677 if Is_Entity_Name (Arg_Expr) then
9678 Arg_Ent := Entity (Arg_Expr);
9680 -- If the entity is overloaded, the pragma applies to the
9681 -- most recent overloading, as documented. In this case,
9682 -- name resolution does not generate a reference, so it
9683 -- must be done here explicitly.
9685 if Is_Overloaded (Arg_Expr) then
9686 Generate_Reference (Arg_Ent, N);
9689 Set_Has_Pragma_Unreferenced (Arg_Ent);
9696 ------------------------------
9697 -- Unreserve_All_Interrupts --
9698 ------------------------------
9700 -- pragma Unreserve_All_Interrupts;
9702 when Pragma_Unreserve_All_Interrupts =>
9704 Check_Arg_Count (0);
9706 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9707 Unreserve_All_Interrupts := True;
9714 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
9716 when Pragma_Unsuppress =>
9718 Process_Suppress_Unsuppress (False);
9724 -- pragma Use_VADS_Size;
9726 when Pragma_Use_VADS_Size =>
9728 Check_Arg_Count (0);
9729 Check_Valid_Configuration_Pragma;
9730 Use_VADS_Size := True;
9732 ---------------------
9733 -- Validity_Checks --
9734 ---------------------
9736 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9738 when Pragma_Validity_Checks => Validity_Checks : declare
9739 A : constant Node_Id := Expression (Arg1);
9745 Check_Arg_Count (1);
9746 Check_No_Identifiers;
9748 if Nkind (A) = N_String_Literal then
9752 Slen : constant Natural := Natural (String_Length (S));
9753 Options : String (1 .. Slen);
9759 C := Get_String_Char (S, Int (J));
9760 exit when not In_Character_Range (C);
9761 Options (J) := Get_Character (C);
9764 Set_Validity_Check_Options (Options);
9772 elsif Nkind (A) = N_Identifier then
9774 if Chars (A) = Name_All_Checks then
9775 Set_Validity_Check_Options ("a");
9777 elsif Chars (A) = Name_On then
9778 Validity_Checks_On := True;
9780 elsif Chars (A) = Name_Off then
9781 Validity_Checks_On := False;
9785 end Validity_Checks;
9791 -- pragma Volatile (LOCAL_NAME);
9793 when Pragma_Volatile =>
9794 Process_Atomic_Shared_Volatile;
9796 -------------------------
9797 -- Volatile_Components --
9798 -------------------------
9800 -- pragma Volatile_Components (array_LOCAL_NAME);
9802 -- Volatile is handled by the same circuit as Atomic_Components
9808 -- pragma Warnings (On | Off, [LOCAL_NAME])
9810 when Pragma_Warnings => Warnings : begin
9812 Check_At_Least_N_Arguments (1);
9813 Check_At_Most_N_Arguments (2);
9814 Check_No_Identifiers;
9816 -- One argument case was processed by parser in Par.Prag
9818 if Arg_Count /= 1 then
9819 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9820 Check_Arg_Count (2);
9827 E_Id := Expression (Arg2);
9830 -- In the expansion of an inlined body, a reference to
9831 -- the formal may be wrapped in a conversion if the actual
9832 -- is a conversion. Retrieve the real entity name.
9834 if (In_Instance_Body
9835 or else In_Inlined_Body)
9836 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
9838 E_Id := Expression (E_Id);
9841 if not Is_Entity_Name (E_Id) then
9843 ("second argument of pragma% must be entity name",
9853 Set_Warnings_Off (E,
9854 (Chars (Expression (Arg1)) = Name_Off));
9856 if Is_Enumeration_Type (E) then
9858 Lit : Entity_Id := First_Literal (E);
9861 while Present (Lit) loop
9862 Set_Warnings_Off (Lit);
9868 exit when No (Homonym (E));
9880 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
9882 when Pragma_Weak_External => Weak_External : declare
9887 Check_Arg_Count (1);
9888 Check_Optional_Identifier (Arg1, Name_Entity);
9889 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9890 Ent := Entity (Expression (Arg1));
9892 if Rep_Item_Too_Early (Ent, N) then
9895 Ent := Underlying_Type (Ent);
9898 -- The only processing required is to link this item on to the
9899 -- list of rep items for the given entity. This is accomplished
9900 -- by the call to Rep_Item_Too_Late (when no error is detected
9901 -- and False is returned).
9903 if Rep_Item_Too_Late (Ent, N) then
9906 Set_Has_Gigi_Rep_Item (Ent);
9910 --------------------
9911 -- Unknown_Pragma --
9912 --------------------
9914 -- Should be impossible, since the case of an unknown pragma is
9915 -- separately processed before the case statement is entered.
9917 when Unknown_Pragma =>
9918 raise Program_Error;
9922 when Pragma_Exit => null;
9925 ---------------------------------
9926 -- Delay_Config_Pragma_Analyze --
9927 ---------------------------------
9929 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
9931 return Chars (N) = Name_Interrupt_State;
9932 end Delay_Config_Pragma_Analyze;
9934 -------------------------
9935 -- Get_Base_Subprogram --
9936 -------------------------
9938 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
9944 -- Follow subprogram renaming chain
9946 while Is_Subprogram (Result)
9948 (Is_Generic_Instance (Result)
9949 or else Nkind (Parent (Declaration_Node (Result))) =
9950 N_Subprogram_Renaming_Declaration)
9951 and then Present (Alias (Result))
9953 Result := Alias (Result);
9957 end Get_Base_Subprogram;
9959 -----------------------------
9960 -- Is_Config_Static_String --
9961 -----------------------------
9963 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
9965 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
9966 -- This is an internal recursive function that is just like the
9967 -- outer function except that it adds the string to the name buffer
9968 -- rather than placing the string in the name buffer.
9970 ------------------------------
9971 -- Add_Config_Static_String --
9972 ------------------------------
9974 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
9981 if Nkind (N) = N_Op_Concat then
9982 if Add_Config_Static_String (Left_Opnd (N)) then
9983 N := Right_Opnd (N);
9989 if Nkind (N) /= N_String_Literal then
9990 Error_Msg_N ("string literal expected for pragma argument", N);
9994 for J in 1 .. String_Length (Strval (N)) loop
9995 C := Get_String_Char (Strval (N), J);
9997 if not In_Character_Range (C) then
9999 ("string literal contains invalid wide character",
10000 Sloc (N) + 1 + Source_Ptr (J));
10004 Add_Char_To_Name_Buffer (Get_Character (C));
10009 end Add_Config_Static_String;
10011 -- Start of prorcessing for Is_Config_Static_String
10015 return Add_Config_Static_String (Arg);
10016 end Is_Config_Static_String;
10018 -----------------------------------------
10019 -- Is_Non_Significant_Pragma_Reference --
10020 -----------------------------------------
10022 -- This function makes use of the following static table which indicates
10023 -- whether a given pragma is significant. A value of -1 in this table
10024 -- indicates that the reference is significant. A value of zero indicates
10025 -- than appearence as any argument is insignificant, a positive value
10026 -- indicates that appearence in that parameter position is significant.
10028 Sig_Flags : constant array (Pragma_Id) of Int :=
10029 (Pragma_AST_Entry => -1,
10030 Pragma_Abort_Defer => -1,
10031 Pragma_Ada_83 => -1,
10032 Pragma_Ada_95 => -1,
10033 Pragma_All_Calls_Remote => -1,
10034 Pragma_Annotate => -1,
10035 Pragma_Assert => -1,
10036 Pragma_Asynchronous => -1,
10037 Pragma_Atomic => 0,
10038 Pragma_Atomic_Components => 0,
10039 Pragma_Attach_Handler => -1,
10040 Pragma_CPP_Class => 0,
10041 Pragma_CPP_Constructor => 0,
10042 Pragma_CPP_Virtual => 0,
10043 Pragma_CPP_Vtable => 0,
10044 Pragma_C_Pass_By_Copy => 0,
10045 Pragma_Comment => 0,
10046 Pragma_Common_Object => -1,
10047 Pragma_Compile_Time_Warning => -1,
10048 Pragma_Complex_Representation => 0,
10049 Pragma_Component_Alignment => -1,
10050 Pragma_Controlled => 0,
10051 Pragma_Convention => 0,
10052 Pragma_Convention_Identifier => 0,
10053 Pragma_Debug => -1,
10054 Pragma_Discard_Names => 0,
10055 Pragma_Elaborate => -1,
10056 Pragma_Elaborate_All => -1,
10057 Pragma_Elaborate_Body => -1,
10058 Pragma_Elaboration_Checks => -1,
10059 Pragma_Eliminate => -1,
10060 Pragma_Explicit_Overriding => -1,
10061 Pragma_Export => -1,
10062 Pragma_Export_Exception => -1,
10063 Pragma_Export_Function => -1,
10064 Pragma_Export_Object => -1,
10065 Pragma_Export_Procedure => -1,
10066 Pragma_Export_Value => -1,
10067 Pragma_Export_Valued_Procedure => -1,
10068 Pragma_Extend_System => -1,
10069 Pragma_Extensions_Allowed => -1,
10070 Pragma_External => -1,
10071 Pragma_External_Name_Casing => -1,
10072 Pragma_Finalize_Storage_Only => 0,
10073 Pragma_Float_Representation => 0,
10074 Pragma_Ident => -1,
10075 Pragma_Import => +2,
10076 Pragma_Import_Exception => 0,
10077 Pragma_Import_Function => 0,
10078 Pragma_Import_Object => 0,
10079 Pragma_Import_Procedure => 0,
10080 Pragma_Import_Valued_Procedure => 0,
10081 Pragma_Initialize_Scalars => -1,
10082 Pragma_Inline => 0,
10083 Pragma_Inline_Always => 0,
10084 Pragma_Inline_Generic => 0,
10085 Pragma_Inspection_Point => -1,
10086 Pragma_Interface => +2,
10087 Pragma_Interface_Name => +2,
10088 Pragma_Interrupt_Handler => -1,
10089 Pragma_Interrupt_Priority => -1,
10090 Pragma_Interrupt_State => -1,
10091 Pragma_Java_Constructor => -1,
10092 Pragma_Java_Interface => -1,
10093 Pragma_Keep_Names => 0,
10094 Pragma_License => -1,
10095 Pragma_Link_With => -1,
10096 Pragma_Linker_Alias => -1,
10097 Pragma_Linker_Options => -1,
10098 Pragma_Linker_Section => -1,
10100 Pragma_Locking_Policy => -1,
10101 Pragma_Long_Float => -1,
10102 Pragma_Machine_Attribute => -1,
10104 Pragma_Main_Storage => -1,
10105 Pragma_Memory_Size => -1,
10106 Pragma_No_Return => 0,
10107 Pragma_No_Run_Time => -1,
10108 Pragma_No_Strict_Aliasing => -1,
10109 Pragma_Normalize_Scalars => -1,
10110 Pragma_Obsolescent => 0,
10111 Pragma_Optimize => -1,
10112 Pragma_Optional_Overriding => -1,
10113 Pragma_Overriding => -1,
10116 Pragma_Passive => -1,
10117 Pragma_Polling => -1,
10118 Pragma_Persistent_Data => -1,
10119 Pragma_Persistent_Object => -1,
10120 Pragma_Preelaborate => -1,
10121 Pragma_Priority => -1,
10122 Pragma_Profile => 0,
10123 Pragma_Propagate_Exceptions => -1,
10124 Pragma_Psect_Object => -1,
10126 Pragma_Pure_Function => 0,
10127 Pragma_Queuing_Policy => -1,
10128 Pragma_Ravenscar => -1,
10129 Pragma_Remote_Call_Interface => -1,
10130 Pragma_Remote_Types => -1,
10131 Pragma_Restricted_Run_Time => -1,
10132 Pragma_Restriction_Warnings => -1,
10133 Pragma_Restrictions => -1,
10134 Pragma_Reviewable => -1,
10135 Pragma_Share_Generic => -1,
10136 Pragma_Shared => -1,
10137 Pragma_Shared_Passive => -1,
10138 Pragma_Source_File_Name => -1,
10139 Pragma_Source_File_Name_Project => -1,
10140 Pragma_Source_Reference => -1,
10141 Pragma_Storage_Size => -1,
10142 Pragma_Storage_Unit => -1,
10143 Pragma_Stream_Convert => -1,
10144 Pragma_Style_Checks => -1,
10145 Pragma_Subtitle => -1,
10146 Pragma_Suppress => 0,
10147 Pragma_Suppress_Exception_Locations => 0,
10148 Pragma_Suppress_All => -1,
10149 Pragma_Suppress_Debug_Info => 0,
10150 Pragma_Suppress_Initialization => 0,
10151 Pragma_System_Name => -1,
10152 Pragma_Task_Dispatching_Policy => -1,
10153 Pragma_Task_Info => -1,
10154 Pragma_Task_Name => -1,
10155 Pragma_Task_Storage => 0,
10156 Pragma_Thread_Body => +2,
10157 Pragma_Time_Slice => -1,
10158 Pragma_Title => -1,
10159 Pragma_Unchecked_Union => -1,
10160 Pragma_Unimplemented_Unit => -1,
10161 Pragma_Universal_Data => -1,
10162 Pragma_Unreferenced => -1,
10163 Pragma_Unreserve_All_Interrupts => -1,
10164 Pragma_Unsuppress => 0,
10165 Pragma_Use_VADS_Size => -1,
10166 Pragma_Validity_Checks => -1,
10167 Pragma_Volatile => 0,
10168 Pragma_Volatile_Components => 0,
10169 Pragma_Warnings => -1,
10170 Pragma_Weak_External => 0,
10171 Unknown_Pragma => 0);
10173 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10181 if Nkind (P) /= N_Pragma_Argument_Association then
10185 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10195 A := First (Pragma_Argument_Associations (Parent (P)));
10196 for J in 1 .. C - 1 loop
10207 end Is_Non_Significant_Pragma_Reference;
10209 ------------------------------
10210 -- Is_Pragma_String_Literal --
10211 ------------------------------
10213 -- This function returns true if the corresponding pragma argument is
10214 -- a static string expression. These are the only cases in which string
10215 -- literals can appear as pragma arguments. We also allow a string
10216 -- literal as the first argument to pragma Assert (although it will
10217 -- of course always generate a type error).
10219 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10220 Pragn : constant Node_Id := Parent (Par);
10221 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10222 Pname : constant Name_Id := Chars (Pragn);
10228 N := First (Assoc);
10235 if Pname = Name_Assert then
10238 elsif Pname = Name_Export then
10241 elsif Pname = Name_Ident then
10244 elsif Pname = Name_Import then
10247 elsif Pname = Name_Interface_Name then
10250 elsif Pname = Name_Linker_Alias then
10253 elsif Pname = Name_Linker_Section then
10256 elsif Pname = Name_Machine_Attribute then
10259 elsif Pname = Name_Source_File_Name then
10262 elsif Pname = Name_Source_Reference then
10265 elsif Pname = Name_Title then
10268 elsif Pname = Name_Subtitle then
10274 end Is_Pragma_String_Literal;
10276 --------------------------------------
10277 -- Process_Compilation_Unit_Pragmas --
10278 --------------------------------------
10280 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10282 -- A special check for pragma Suppress_All. This is a strange DEC
10283 -- pragma, strange because it comes at the end of the unit. If we
10284 -- have a pragma Suppress_All in the Pragmas_After of the current
10285 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10286 -- of the context clause to ensure the correct processing.
10289 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10293 if Present (PA) then
10295 while Present (P) loop
10296 if Chars (P) = Name_Suppress_All then
10297 Prepend_To (Context_Items (N),
10298 Make_Pragma (Sloc (P),
10299 Chars => Name_Suppress,
10300 Pragma_Argument_Associations => New_List (
10301 Make_Pragma_Argument_Association (Sloc (P),
10303 Make_Identifier (Sloc (P),
10304 Chars => Name_All_Checks)))));
10312 end Process_Compilation_Unit_Pragmas;
10314 --------------------------------
10315 -- Set_Encoded_Interface_Name --
10316 --------------------------------
10318 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10319 Str : constant String_Id := Strval (S);
10320 Len : constant Int := String_Length (Str);
10325 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10328 -- Stores encoded value of character code CC. The encoding we
10329 -- use an underscore followed by four lower case hex digits.
10331 procedure Encode is
10333 Store_String_Char (Get_Char_Code ('_'));
10335 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10337 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10339 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10341 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10344 -- Start of processing for Set_Encoded_Interface_Name
10347 -- If first character is asterisk, this is a link name, and we
10348 -- leave it completely unmodified. We also ignore null strings
10349 -- (the latter case happens only in error cases) and no encoding
10350 -- should occur for Java interface names.
10353 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10356 Set_Interface_Name (E, S);
10361 CC := Get_String_Char (Str, J);
10363 exit when not In_Character_Range (CC);
10365 C := Get_Character (CC);
10367 exit when C /= '_' and then C /= '$'
10368 and then C not in '0' .. '9'
10369 and then C not in 'a' .. 'z'
10370 and then C not in 'A' .. 'Z';
10373 Set_Interface_Name (E, S);
10381 -- Here we need to encode. The encoding we use as follows:
10382 -- three underscores + four hex digits (lower case)
10386 for J in 1 .. String_Length (Str) loop
10387 CC := Get_String_Char (Str, J);
10389 if not In_Character_Range (CC) then
10392 C := Get_Character (CC);
10394 if C = '_' or else C = '$'
10395 or else C in '0' .. '9'
10396 or else C in 'a' .. 'z'
10397 or else C in 'A' .. 'Z'
10399 Store_String_Char (CC);
10406 Set_Interface_Name (E,
10407 Make_String_Literal (Sloc (S),
10408 Strval => End_String));
10410 end Set_Encoded_Interface_Name;
10412 -------------------
10413 -- Set_Unit_Name --
10414 -------------------
10416 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10421 if Nkind (N) = N_Identifier
10422 and then Nkind (With_Item) = N_Identifier
10424 Set_Entity (N, Entity (With_Item));
10426 elsif Nkind (N) = N_Selected_Component then
10427 Change_Selected_Component_To_Expanded_Name (N);
10428 Set_Entity (N, Entity (With_Item));
10429 Set_Entity (Selector_Name (N), Entity (N));
10431 Pref := Prefix (N);
10432 Scop := Scope (Entity (N));
10434 while Nkind (Pref) = N_Selected_Component loop
10435 Change_Selected_Component_To_Expanded_Name (Pref);
10436 Set_Entity (Selector_Name (Pref), Scop);
10437 Set_Entity (Pref, Scop);
10438 Pref := Prefix (Pref);
10439 Scop := Scope (Scop);
10442 Set_Entity (Pref, Scop);