1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This unit contains the semantic processing for all pragmas, both language
30 -- and implementation defined. For most pragmas, the parser only does the
31 -- most basic job of checking the syntax, so Sem_Prag also contains the code
32 -- to complete the syntax checks. Certain pragmas are handled partially or
33 -- completely by the parser (see Par.Prag for further details).
35 with Atree; use Atree;
36 with Casing; use Casing;
37 with Csets; use Csets;
38 with Debug; use Debug;
39 with Einfo; use Einfo;
40 with Elists; use Elists;
41 with Errout; use Errout;
42 with Expander; use Expander;
43 with Exp_Dist; use Exp_Dist;
44 with Fname; use Fname;
45 with Hostparm; use Hostparm;
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 Rtsfind; use Rtsfind;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch13; use Sem_Ch13;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Elim; use Sem_Elim;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Mech; use Sem_Mech;
62 with Sem_Res; use Sem_Res;
63 with Sem_Type; use Sem_Type;
64 with Sem_Util; use Sem_Util;
65 with Sem_VFpt; use Sem_VFpt;
66 with Stand; use Stand;
67 with Sinfo; use Sinfo;
68 with Sinfo.CN; use Sinfo.CN;
69 with Sinput; use Sinput;
70 with Snames; use Snames;
71 with Stringt; use Stringt;
72 with Stylesw; use Stylesw;
73 with Targparm; use Targparm;
74 with Tbuild; use Tbuild;
76 with Uintp; use Uintp;
77 with Urealp; use Urealp;
78 with Validsw; use Validsw;
80 package body Sem_Prag is
82 ----------------------------------------------
83 -- Common Handling of Import-Export Pragmas --
84 ----------------------------------------------
86 -- In the following section, a number of Import_xxx and Export_xxx
87 -- pragmas are defined by GNAT. These are compatible with the DEC
88 -- pragmas of the same name, and all have the following common
89 -- form and processing:
92 -- [Internal =>] LOCAL_NAME,
93 -- [, [External =>] EXTERNAL_SYMBOL]
94 -- [, other optional parameters ]);
97 -- [Internal =>] LOCAL_NAME,
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
101 -- EXTERNAL_SYMBOL ::=
103 -- | static_string_EXPRESSION
105 -- The internal LOCAL_NAME designates the entity that is imported or
106 -- exported, and must refer to an entity in the current declarative
107 -- part (as required by the rules for LOCAL_NAME).
109 -- The external linker name is designated by the External parameter
110 -- if given, or the Internal parameter if not (if there is no External
111 -- parameter, the External parameter is a copy of the Internal name).
113 -- If the External parameter is given as a string, then this string
114 -- is treated as an external name (exactly as though it had been given
115 -- as an External_Name parameter for a normal Import pragma).
117 -- If the External parameter is given as an identifier (or there is no
118 -- External parameter, so that the Internal identifier is used), then
119 -- the external name is the characters of the identifier, translated
120 -- to all upper case letters for OpenVMS versions of GNAT, and to all
121 -- lower case letters for all other versions
123 -- Note: the external name specified or implied by any of these special
124 -- Import_xxx or Export_xxx pragmas override an external or link name
125 -- specified in a previous Import or Export pragma.
127 -- Note: these and all other DEC-compatible GNAT pragmas allow full
128 -- use of named notation, following the standard rules for subprogram
129 -- calls, i.e. parameters can be given in any order if named notation
130 -- is used, and positional and named notation can be mixed, subject to
131 -- the rule that all positional parameters must appear first.
133 -- Note: All these pragmas are implemented exactly following the DEC
134 -- design and implementation and are intended to be fully compatible
135 -- with the use of these pragmas in the DEC Ada compiler.
137 -------------------------------------
138 -- Local Subprograms and Variables --
139 -------------------------------------
141 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
142 -- This routine is used for possible casing adjustment of an explicit
143 -- external name supplied as a string literal (the node N), according
144 -- to the casing requirement of Opt.External_Name_Casing. If this is
145 -- set to As_Is, then the string literal is returned unchanged, but if
146 -- it is set to Uppercase or Lowercase, then a new string literal with
147 -- appropriate casing is constructed.
149 function Is_Generic_Subprogram (Id : Entity_Id) return Boolean;
150 -- Return True if Id is a generic procedure or a function
152 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
153 -- If Def_Id refers to a renamed subprogram, then the base subprogram
154 -- (the original one, following the renaming chain) is returned.
155 -- Otherwise the entity is returned unchanged. Should be in Einfo???
157 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
158 -- Place semantic information on the argument of an Elaborate or
159 -- Elaborate_All pragma. Entity name for unit and its parents is
160 -- taken from item in previous with_clause that mentions the unit.
162 Locking_Policy_Sloc : Source_Ptr := No_Location;
163 Queuing_Policy_Sloc : Source_Ptr := No_Location;
164 Task_Dispatching_Policy_Sloc : Source_Ptr := No_Location;
165 -- These global variables remember the location of a previous locking,
166 -- queuing or task dispatching policy pragma, so that appropriate error
167 -- messages can be generated for inconsistent pragmas. Note that it is
168 -- fine that these are global locations, because the check for consistency
169 -- is over the entire program.
171 -------------------------------
172 -- Adjust_External_Name_Case --
173 -------------------------------
175 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
179 -- Adjust case of literal if required
181 if Opt.External_Name_Exp_Casing = As_Is then
185 -- Copy existing string
191 for J in 1 .. String_Length (Strval (N)) loop
192 CC := Get_String_Char (Strval (N), J);
194 if Opt.External_Name_Exp_Casing = Uppercase
195 and then CC >= Get_Char_Code ('a')
196 and then CC <= Get_Char_Code ('z')
198 Store_String_Char (CC - 32);
200 elsif Opt.External_Name_Exp_Casing = Lowercase
201 and then CC >= Get_Char_Code ('A')
202 and then CC <= Get_Char_Code ('Z')
204 Store_String_Char (CC + 32);
207 Store_String_Char (CC);
212 Make_String_Literal (Sloc (N),
213 Strval => End_String);
215 end Adjust_External_Name_Case;
221 procedure Analyze_Pragma (N : Node_Id) is
222 Loc : constant Source_Ptr := Sloc (N);
225 Pragma_Exit : exception;
226 -- This exception is used to exit pragma processing completely. It
227 -- is used when an error is detected, and in other situations where
228 -- it is known that no further processing is required.
231 -- Number of pragma argument associations
237 -- First four pragma arguments (pragma argument association nodes,
238 -- or Empty if the corresponding argument does not exist).
240 procedure Check_Ada_83_Warning;
241 -- Issues a warning message for the current pragma if operating in Ada
242 -- 83 mode (used for language pragmas that are not a standard part of
243 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
246 procedure Check_Arg_Count (Required : Nat);
247 -- Check argument count for pragma is equal to given parameter.
248 -- If not, then issue an error message and raise Pragma_Exit.
250 -- Note: all routines whose name is Check_Arg_Is_xxx take an
251 -- argument Arg which can either be a pragma argument association,
252 -- in which case the check is applied to the expression of the
253 -- association or an expression directly.
255 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
256 -- Check the specified argument Arg to make sure that it is an
257 -- identifier. If not give error and raise Pragma_Exit.
259 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
260 -- Check the specified argument Arg to make sure that it is an
261 -- integer literal. If not give error and raise Pragma_Exit.
263 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
264 -- Check the specified argument Arg to make sure that it has the
265 -- proper syntactic form for a local name and meets the semantic
266 -- requirements for a local name. The local name is analyzed as
267 -- part of the processing for this call. In addition, the local
268 -- name is required to represent an entity at the library level.
270 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
271 -- Check the specified argument Arg to make sure that it has the
272 -- proper syntactic form for a local name and meets the semantic
273 -- requirements for a local name. The local name is analyzed as
274 -- part of the processing for this call.
276 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
277 -- Check the specified argument Arg to make sure that it is a valid
278 -- locking policy name. If not give error and raise Pragma_Exit.
280 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
281 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
282 -- Check the specified argument Arg to make sure that it is an
283 -- identifier whose name matches either N1 or N2 (or N3 if present).
284 -- If not then give error and raise Pragma_Exit.
286 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
287 -- Check the specified argument Arg to make sure that it is a valid
288 -- queuing policy name. If not give error and raise Pragma_Exit.
290 procedure Check_Arg_Is_Static_Expression
293 -- Check the specified argument Arg to make sure that it is a static
294 -- expression of the given type (i.e. it will be analyzed and resolved
295 -- using this type, which can be any valid argument to Resolve, e.g.
296 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
298 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
299 -- Check the specified argument Arg to make sure that it is a
300 -- string literal. If not give error and raise Pragma_Exit
302 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
303 -- Check the specified argument Arg to make sure that it is a valid
304 -- valid task dispatching policy name. If not give error and raise
307 procedure Check_At_Least_N_Arguments (N : Nat);
308 -- Check there are at least N arguments present
310 procedure Check_At_Most_N_Arguments (N : Nat);
311 -- Check there are no more than N arguments present
313 procedure Check_First_Subtype (Arg : Node_Id);
314 -- Checks that Arg, whose expression is an entity name referencing
315 -- a subtype, does not reference a type that is not a first subtype.
317 procedure Check_In_Main_Program;
318 -- Common checks for pragmas that appear within a main program
319 -- (Priority, Main_Storage, Time_Slice).
321 procedure Check_Interrupt_Or_Attach_Handler;
322 -- Common processing for first argument of pragma Interrupt_Handler
323 -- or pragma Attach_Handler.
325 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
326 -- Check that pragma appears in a declarative part, or in a package
327 -- specification, i.e. that it does not occur in a statement sequence
330 procedure Check_No_Identifier (Arg : Node_Id);
331 -- Checks that the given argument does not have an identifier. If
332 -- an identifier is present, then an error message is issued, and
333 -- Pragma_Exit is raised.
335 procedure Check_No_Identifiers;
336 -- Checks that none of the arguments to the pragma has an identifier.
337 -- If any argument has an identifier, then an error message is issued,
338 -- and Pragma_Exit is raised.
340 procedure Check_Non_Overloaded_Function (Arg : Node_Id);
341 -- Check that the given argument is the name of a local function of
342 -- one argument that is not overloaded in the current local scope.
344 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
345 -- Checks if the given argument has an identifier, and if so, requires
346 -- it to match the given identifier name. If there is a non-matching
347 -- identifier, then an error message is given and Error_Pragmas raised.
349 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
350 -- Checks if the given argument has an identifier, and if so, requires
351 -- it to match the given identifier name. If there is a non-matching
352 -- identifier, then an error message is given and Error_Pragmas raised.
353 -- In this version of the procedure, the identifier name is given as
354 -- a string with lower case letters.
356 procedure Check_Static_Constraint (Constr : Node_Id);
357 -- Constr is a constraint from an N_Subtype_Indication node from a
358 -- component constraint in an Unchecked_Union type. This routine checks
359 -- that the constraint is static as required by the restrictions for
362 procedure Check_Valid_Configuration_Pragma;
363 -- Legality checks for placement of a configuration pragma
365 procedure Check_Valid_Library_Unit_Pragma;
366 -- Legality checks for library unit pragmas. A special case arises for
367 -- pragmas in generic instances that come from copies of the original
368 -- library unit pragmas in the generic templates. In the case of other
369 -- than library level instantiations these can appear in contexts which
370 -- would normally be invalid (they only apply to the original template
371 -- and to library level instantiations), and they are simply ignored,
372 -- which is implemented by rewriting them as null statements.
374 procedure Error_Pragma (Msg : String);
375 pragma No_Return (Error_Pragma);
376 -- Outputs error message for current pragma. The message contains an %
377 -- that will be replaced with the pragma name, and the flag is placed
378 -- on the pragma itself. Pragma_Exit is then raised.
380 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
381 pragma No_Return (Error_Pragma_Arg);
382 -- Outputs error message for current pragma. The message may contain
383 -- a % that will be replaced with the pragma name. The parameter Arg
384 -- may either be a pragma argument association, in which case the flag
385 -- is placed on the expression of this association, or an expression,
386 -- in which case the flag is placed directly on the expression. The
387 -- message is placed using Error_Msg_N, so the message may also contain
388 -- an & insertion character which will reference the given Arg value.
389 -- After placing the message, Pragma_Exit is raised.
391 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
392 pragma No_Return (Error_Pragma_Arg);
393 -- Similar to above form of Error_Pragma_Arg except that two messages
394 -- are provided, the second is a continuation comment starting with \.
396 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
397 pragma No_Return (Error_Pragma_Arg_Ident);
398 -- Outputs error message for current pragma. The message may contain
399 -- a % that will be replaced with the pragma name. The parameter Arg
400 -- must be a pragma argument association with a non-empty identifier
401 -- (i.e. its Chars field must be set), and the error message is placed
402 -- on the identifier. The message is placed using Error_Msg_N so
403 -- the message may also contain an & insertion character which will
404 -- reference the identifier. After placing the message, Pragma_Exit
407 function Find_Lib_Unit_Name return Entity_Id;
408 -- Used for a library unit pragma to find the entity to which the
409 -- library unit pragma applies, returns the entity found.
411 procedure Find_Program_Unit_Name (Id : Node_Id);
412 -- If the pragma is a compilation unit pragma, the id must denote the
413 -- compilation unit in the same compilation, and the pragma must appear
414 -- in the list of preceding or trailing pragmas. If it is a program
415 -- unit pragma that is not a compilation unit pragma, then the
416 -- identifier must be visible.
418 type Name_List is array (Natural range <>) of Name_Id;
419 type Args_List is array (Natural range <>) of Node_Id;
420 procedure Gather_Associations
422 Args : out Args_List);
423 -- This procedure is used to gather the arguments for a pragma that
424 -- permits arbitrary ordering of parameters using the normal rules
425 -- for named and positional parameters. The Names argument is a list
426 -- of Name_Id values that corresponds to the allowed pragma argument
427 -- association identifiers in order. The result returned in Args is
428 -- a list of corresponding expressions that are the pragma arguments.
429 -- Note that this is a list of expressions, not of pragma argument
430 -- associations (Gather_Associations has completely checked all the
431 -- optional identifiers when it returns). An entry in Args is Empty
432 -- on return if the corresponding argument is not present.
434 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
435 -- All the routines that check pragma arguments take either a pragma
436 -- argument association (in which case the expression of the argument
437 -- association is checked), or the expression directly. The function
438 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
439 -- Arg is a pragma argument association node, then its expression is
440 -- returned, otherwise Arg is returned unchanged.
442 procedure GNAT_Pragma;
443 -- Called for all GNAT defined pragmas to note the use of the feature,
444 -- and also check the relevant restriction (No_Implementation_Pragmas).
446 function Is_Before_First_Decl
447 (Pragma_Node : Node_Id;
450 -- Return True if Pragma_Node is before the first declarative item in
451 -- Decls where Decls is the list of declarative items.
453 function Is_Configuration_Pragma return Boolean;
454 -- Deterermines if the placement of the current pragma is appropriate
455 -- for a configuration pragma (precedes the current compilation unit)
457 procedure Pragma_Misplaced;
458 -- Issue fatal error message for misplaced pragma
460 procedure Process_Atomic_Shared_Volatile;
461 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
462 -- Shared is an obsolete Ada 83 pragma, treated as being identical
463 -- in effect to pragma Atomic.
465 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
466 -- Common procesing for Convention, Interface, Import and Export.
467 -- Checks first two arguments of pragma, and sets the appropriate
468 -- convention value in the specified entity or entities. On return
469 -- C is the convention, E is the referenced entity.
471 procedure Process_Extended_Import_Export_Exception_Pragma
472 (Arg_Internal : Node_Id;
473 Arg_External : Node_Id;
476 -- Common processing for the pragmas Import/Export_Exception.
477 -- The three arguments correspond to the three named parameters of
478 -- the pragma. An argument is empty if the corresponding parameter
479 -- is not present in the pragma.
481 procedure Process_Extended_Import_Export_Object_Pragma
482 (Arg_Internal : Node_Id;
483 Arg_External : Node_Id;
485 -- Common processing for the pragmass Import/Export_Object.
486 -- The three arguments correspond to the three named parameters
487 -- of the pragmas. An argument is empty if the corresponding
488 -- parameter is not present in the pragma.
490 procedure Process_Extended_Import_Export_Internal_Arg
491 (Arg_Internal : Node_Id := Empty);
492 -- Common processing for all extended Import and Export pragmas. The
493 -- argument is the pragma parameter for the Internal argument. If
494 -- Arg_Internal is empty or inappropriate, an error message is posted.
495 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
496 -- set to identify the referenced entity.
498 procedure Process_Extended_Import_Export_Subprogram_Pragma
499 (Arg_Internal : Node_Id;
500 Arg_External : Node_Id;
501 Arg_Parameter_Types : Node_Id;
502 Arg_Result_Type : Node_Id := Empty;
503 Arg_Mechanism : Node_Id;
504 Arg_Result_Mechanism : Node_Id := Empty;
505 Arg_First_Optional_Parameter : Node_Id := Empty);
506 -- Common processing for all extended Import and Export pragmas
507 -- applying to subprograms. The caller omits any arguments that do
508 -- bnot apply to the pragma in question (for example, Arg_Result_Type
509 -- can be non-Empty only in the Import_Function and Export_Function
510 -- cases). The argument names correspond to the allowed pragma
511 -- association identifiers.
513 procedure Process_Generic_List;
514 -- Common processing for Share_Generic and Inline_Generic
516 procedure Process_Import_Or_Interface;
517 -- Common processing for Import of Interface
519 procedure Process_Inline (Active : Boolean);
520 -- Common processing for Inline and Inline_Always. The parameter
521 -- indicates if the inline pragma is active, i.e. if it should
522 -- actually cause inlining to occur.
524 procedure Process_Interface_Name
525 (Subprogram_Def : Entity_Id;
528 -- Given the last two arguments of pragma Import, pragma Export, or
529 -- pragma Interface_Name, performs validity checks and sets the
530 -- Interface_Name field of the given subprogram entity to the
531 -- appropriate external or link name, depending on the arguments
532 -- given. Ext_Arg is always present, but Link_Arg may be missing.
533 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
534 -- missing, and appropriate named notation is used for Ext_Arg.
535 -- If neither Ext_Arg nor Link_Arg is present, the interface name
536 -- is set to the default from the subprogram name.
538 procedure Process_Interrupt_Or_Attach_Handler;
539 -- Attach the pragmas to the rep item chain.
541 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
542 -- Common processing for Suppress and Unsuppress. The boolean parameter
543 -- Suppress_Case is True for the Suppress case, and False for the
546 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
547 -- This procedure sets the Is_Exported flag for the given entity,
548 -- checking that the entity was not previously imported. Arg is
549 -- the argument that specified the entity.
551 procedure Set_Extended_Import_Export_External_Name
552 (Internal_Ent : Entity_Id;
553 Arg_External : Node_Id);
554 -- Common processing for all extended import export pragmas. The first
555 -- argument, Internal_Ent, is the internal entity, which has already
556 -- been checked for validity by the caller. Arg_External is from the
557 -- Import or Export pragma, and may be null if no External parameter
558 -- was present. If Arg_External is present and is a non-null string
559 -- (a null string is treated as the default), then the Interface_Name
560 -- field of Internal_Ent is set appropriately.
562 procedure Set_Imported (E : Entity_Id);
563 -- This procedure sets the Is_Imported flag for the given entity,
564 -- checking that it is not previously exported or imported.
566 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
567 -- Mech is a parameter passing mechanism (see Import_Function syntax
568 -- for MECHANISM_NAME). This routine checks that the mechanism argument
569 -- has the right form, and if not issues an error message. If the
570 -- argument has the right form then the Mechanism field of Ent is
571 -- set appropriately.
573 --------------------------
574 -- Check_Ada_83_Warning --
575 --------------------------
577 procedure Check_Ada_83_Warning is
581 if Ada_83 and then Comes_From_Source (N) then
582 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
584 end Check_Ada_83_Warning;
586 ---------------------
587 -- Check_Arg_Count --
588 ---------------------
590 procedure Check_Arg_Count (Required : Nat) is
592 if Arg_Count /= Required then
593 Error_Pragma ("wrong number of arguments for pragma%");
597 -----------------------------
598 -- Check_Arg_Is_Identifier --
599 -----------------------------
601 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
602 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
605 if Nkind (Argx) /= N_Identifier then
607 ("argument for pragma% must be identifier", Argx);
609 end Check_Arg_Is_Identifier;
611 ----------------------------------
612 -- Check_Arg_Is_Integer_Literal --
613 ----------------------------------
615 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
616 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
619 if Nkind (Argx) /= N_Integer_Literal then
621 ("argument for pragma% must be integer literal", Argx);
623 end Check_Arg_Is_Integer_Literal;
625 -------------------------------------------
626 -- Check_Arg_Is_Library_Level_Local_Name --
627 -------------------------------------------
631 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
632 -- | library_unit_NAME
634 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
636 Check_Arg_Is_Local_Name (Arg);
638 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
639 and then Comes_From_Source (N)
642 ("argument for pragma% must be library level entity", Arg);
644 end Check_Arg_Is_Library_Level_Local_Name;
646 -----------------------------
647 -- Check_Arg_Is_Local_Name --
648 -----------------------------
652 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
653 -- | library_unit_NAME
655 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
656 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
661 if Nkind (Argx) not in N_Direct_Name
662 and then (Nkind (Argx) /= N_Attribute_Reference
663 or else Present (Expressions (Argx))
664 or else Nkind (Prefix (Argx)) /= N_Identifier)
665 and then (not Is_Entity_Name (Argx)
666 or else not Is_Compilation_Unit (Entity (Argx)))
668 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
671 if Is_Entity_Name (Argx)
672 and then Scope (Entity (Argx)) /= Current_Scope
675 ("pragma% argument must be in same declarative part", Arg);
677 end Check_Arg_Is_Local_Name;
679 ---------------------------------
680 -- Check_Arg_Is_Locking_Policy --
681 ---------------------------------
683 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
684 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
687 Check_Arg_Is_Identifier (Argx);
689 if not Is_Locking_Policy_Name (Chars (Argx)) then
691 ("& is not a valid locking policy name", Argx);
693 end Check_Arg_Is_Locking_Policy;
695 -------------------------
696 -- Check_Arg_Is_One_Of --
697 -------------------------
699 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
700 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
703 Check_Arg_Is_Identifier (Argx);
705 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
706 Error_Msg_Name_2 := N1;
707 Error_Msg_Name_3 := N2;
708 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
710 end Check_Arg_Is_One_Of;
712 procedure Check_Arg_Is_One_Of
714 N1, N2, N3 : Name_Id)
716 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
719 Check_Arg_Is_Identifier (Argx);
721 if Chars (Argx) /= N1
722 and then Chars (Argx) /= N2
723 and then Chars (Argx) /= N3
725 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
727 end Check_Arg_Is_One_Of;
729 ---------------------------------
730 -- Check_Arg_Is_Queuing_Policy --
731 ---------------------------------
733 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
734 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
737 Check_Arg_Is_Identifier (Argx);
739 if not Is_Queuing_Policy_Name (Chars (Argx)) then
741 ("& is not a valid queuing policy name", Argx);
743 end Check_Arg_Is_Queuing_Policy;
745 ------------------------------------
746 -- Check_Arg_Is_Static_Expression --
747 ------------------------------------
749 procedure Check_Arg_Is_Static_Expression
753 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
756 Analyze_And_Resolve (Argx, Typ);
758 if Is_OK_Static_Expression (Argx) then
761 elsif Etype (Argx) = Any_Type then
764 -- An interesting special case, if we have a string literal and
765 -- we are in Ada 83 mode, then we allow it even though it will
766 -- not be flagged as static. This allows the use of Ada 95
767 -- pragmas like Import in Ada 83 mode. They will of course be
768 -- flagged with warnings as usual, but will not cause errors.
770 elsif Ada_83 and then Nkind (Argx) = N_String_Literal then
773 -- Static expression that raises Constraint_Error. This has
774 -- already been flagged, so just exit from pragma processing.
776 elsif Is_Static_Expression (Argx) then
779 -- Finally, we have a real error
783 ("argument for pragma% must be a static expression", Argx);
786 end Check_Arg_Is_Static_Expression;
788 ---------------------------------
789 -- Check_Arg_Is_String_Literal --
790 ---------------------------------
792 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
793 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
796 if Nkind (Argx) /= N_String_Literal then
798 ("argument for pragma% must be string literal", Argx);
801 end Check_Arg_Is_String_Literal;
803 ------------------------------------------
804 -- Check_Arg_Is_Task_Dispatching_Policy --
805 ------------------------------------------
807 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
808 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
811 Check_Arg_Is_Identifier (Argx);
813 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
815 ("& is not a valid task dispatching policy name", Argx);
817 end Check_Arg_Is_Task_Dispatching_Policy;
819 --------------------------------
820 -- Check_At_Least_N_Arguments --
821 --------------------------------
823 procedure Check_At_Least_N_Arguments (N : Nat) is
825 if Arg_Count < N then
826 Error_Pragma ("too few arguments for pragma%");
828 end Check_At_Least_N_Arguments;
830 -------------------------------
831 -- Check_At_Most_N_Arguments --
832 -------------------------------
834 procedure Check_At_Most_N_Arguments (N : Nat) is
838 if Arg_Count > N then
843 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
846 end Check_At_Most_N_Arguments;
848 -------------------------
849 -- Check_First_Subtype --
850 -------------------------
852 procedure Check_First_Subtype (Arg : Node_Id) is
853 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
856 if not Is_First_Subtype (Entity (Argx)) then
858 ("pragma% cannot apply to subtype", Argx);
860 end Check_First_Subtype;
862 ---------------------------
863 -- Check_In_Main_Program --
864 ---------------------------
866 procedure Check_In_Main_Program is
867 P : constant Node_Id := Parent (N);
870 -- Must be at in subprogram body
872 if Nkind (P) /= N_Subprogram_Body then
873 Error_Pragma ("% pragma allowed only in subprogram");
875 -- Otherwise warn if obviously not main program
877 elsif Present (Parameter_Specifications (Specification (P)))
878 or else not Is_Library_Level_Entity (Defining_Entity (P))
880 Error_Msg_Name_1 := Chars (N);
882 ("?pragma% is only effective in main program", N);
884 end Check_In_Main_Program;
886 ---------------------------------------
887 -- Check_Interrupt_Or_Attach_Handler --
888 ---------------------------------------
890 procedure Check_Interrupt_Or_Attach_Handler is
891 Arg1_X : constant Node_Id := Expression (Arg1);
896 if not Is_Entity_Name (Arg1_X) then
898 ("argument of pragma% must be entity name", Arg1);
900 elsif Prag_Id = Pragma_Interrupt_Handler then
901 Check_Restriction (No_Dynamic_Interrupts, N);
905 Prot_Proc : Entity_Id := Empty;
906 Prot_Type : Entity_Id;
907 Found : Boolean := False;
910 if not Is_Overloaded (Arg1_X) then
911 Prot_Proc := Entity (Arg1_X);
916 Index : Interp_Index;
919 Get_First_Interp (Arg1_X, Index, It);
920 while Present (It.Nam) loop
923 if Ekind (Prot_Proc) = E_Procedure
924 and then No (First_Formal (Prot_Proc))
928 Set_Entity (Arg1_X, Prot_Proc);
929 Set_Is_Overloaded (Arg1_X, False);
932 ("ambiguous handler name for pragma% ", Arg1);
936 Get_Next_Interp (Index, It);
941 ("argument of pragma% must be parameterless procedure",
944 Prot_Proc := Entity (Arg1_X);
949 Prot_Type := Scope (Prot_Proc);
951 if Ekind (Prot_Proc) /= E_Procedure
952 or else Ekind (Prot_Type) /= E_Protected_Type
955 ("argument of pragma% must be protected procedure",
959 if not Is_Library_Level_Entity (Prot_Type) then
961 ("pragma% requires library level entity", Arg1);
964 if Present (First_Formal (Prot_Proc)) then
966 ("argument of pragma% must be parameterless procedure",
971 Protected_Definition (Parent (Prot_Type))
973 Error_Pragma ("pragma% must be in protected definition");
977 end Check_Interrupt_Or_Attach_Handler;
979 -------------------------------------------
980 -- Check_Is_In_Decl_Part_Or_Package_Spec --
981 -------------------------------------------
983 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
992 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
995 elsif Nkind (P) = N_Package_Specification then
998 elsif Nkind (P) = N_Block_Statement then
1001 -- Note: the following tests seem a little peculiar, because
1002 -- they test for bodies, but if we were in the statement part
1003 -- of the body, we would already have hit the handled statement
1004 -- sequence, so the only way we get here is by being in the
1005 -- declarative part of the body.
1007 elsif Nkind (P) = N_Subprogram_Body
1008 or else Nkind (P) = N_Package_Body
1009 or else Nkind (P) = N_Task_Body
1010 or else Nkind (P) = N_Entry_Body
1018 Error_Pragma ("pragma% is not in declarative part or package spec");
1020 end Check_Is_In_Decl_Part_Or_Package_Spec;
1022 -------------------------
1023 -- Check_No_Identifier --
1024 -------------------------
1026 procedure Check_No_Identifier (Arg : Node_Id) is
1028 if Chars (Arg) /= No_Name then
1029 Error_Pragma_Arg_Ident
1030 ("pragma% does not permit identifier& here", Arg);
1032 end Check_No_Identifier;
1034 --------------------------
1035 -- Check_No_Identifiers --
1036 --------------------------
1038 procedure Check_No_Identifiers is
1042 if Arg_Count > 0 then
1045 while Present (Arg_Node) loop
1046 Check_No_Identifier (Arg_Node);
1050 end Check_No_Identifiers;
1052 -----------------------------------
1053 -- Check_Non_Overloaded_Function --
1054 -----------------------------------
1056 procedure Check_Non_Overloaded_Function (Arg : Node_Id) is
1060 Check_Arg_Is_Local_Name (Arg);
1061 Ent := Entity (Expression (Arg));
1063 if Present (Homonym (Ent))
1064 and then Scope (Homonym (Ent)) = Current_Scope
1067 ("argument for pragma% may not be overloaded", Arg);
1070 if Ekind (Ent) /= E_Function
1071 or else No (First_Formal (Ent))
1072 or else Present (Next_Formal (First_Formal (Ent)))
1075 ("argument for pragma% must be function of one argument", Arg);
1077 end Check_Non_Overloaded_Function;
1079 -------------------------------
1080 -- Check_Optional_Identifier --
1081 -------------------------------
1083 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1085 if Present (Arg) and then Chars (Arg) /= No_Name then
1086 if Chars (Arg) /= Id then
1087 Error_Msg_Name_1 := Chars (N);
1088 Error_Msg_Name_2 := Id;
1089 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1093 end Check_Optional_Identifier;
1095 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1097 Name_Buffer (1 .. Id'Length) := Id;
1098 Name_Len := Id'Length;
1099 Check_Optional_Identifier (Arg, Name_Find);
1100 end Check_Optional_Identifier;
1102 -----------------------------
1103 -- Check_Static_Constraint --
1104 -----------------------------
1106 -- Note: for convenience in writing this procedure, in addition to
1107 -- the officially (i.e. by spec) allowed argument which is always
1108 -- a constraint, it also allows ranges and discriminant associations.
1110 procedure Check_Static_Constraint (Constr : Node_Id) is
1112 --------------------
1113 -- Require_Static --
1114 --------------------
1116 procedure Require_Static (E : Node_Id);
1117 -- Require given expression to be static expression
1119 procedure Require_Static (E : Node_Id) is
1121 if not Is_OK_Static_Expression (E) then
1123 ("non-static constraint not allowed in Unchecked_Union", E);
1128 -- Start of processing for Check_Static_Constraint
1131 case Nkind (Constr) is
1132 when N_Discriminant_Association =>
1133 Require_Static (Expression (Constr));
1136 Require_Static (Low_Bound (Constr));
1137 Require_Static (High_Bound (Constr));
1139 when N_Attribute_Reference =>
1140 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1141 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1143 when N_Range_Constraint =>
1144 Check_Static_Constraint (Range_Expression (Constr));
1146 when N_Index_Or_Discriminant_Constraint =>
1148 IDC : Entity_Id := First (Constraints (Constr));
1151 while Present (IDC) loop
1152 Check_Static_Constraint (IDC);
1160 end Check_Static_Constraint;
1162 --------------------------------------
1163 -- Check_Valid_Configuration_Pragma --
1164 --------------------------------------
1166 -- A configuration pragma must appear in the context clause of
1167 -- a compilation unit, at the start of the list (i.e. only other
1168 -- pragmas may precede it).
1170 procedure Check_Valid_Configuration_Pragma is
1172 if not Is_Configuration_Pragma then
1173 Error_Pragma ("incorrect placement for configuration pragma%");
1175 end Check_Valid_Configuration_Pragma;
1177 -------------------------------------
1178 -- Check_Valid_Library_Unit_Pragma --
1179 -------------------------------------
1181 procedure Check_Valid_Library_Unit_Pragma is
1183 Parent_Node : Node_Id;
1184 Unit_Name : Entity_Id;
1185 Valid : Boolean := True;
1186 Unit_Kind : Node_Kind;
1187 Unit_Node : Node_Id;
1188 Sindex : Source_File_Index;
1191 if not Is_List_Member (N) then
1196 Plist := List_Containing (N);
1197 Parent_Node := Parent (Plist);
1199 if Parent_Node = Empty then
1202 -- Case of pragma appearing after a compilation unit. In this
1203 -- case it must have an argument with the corresponding name
1204 -- and must be part of the following pragmas of its parent.
1206 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1207 if Plist /= Pragmas_After (Parent_Node) then
1210 elsif Arg_Count = 0 then
1212 ("argument required if outside compilation unit");
1215 Check_No_Identifiers;
1216 Check_Arg_Count (1);
1217 Unit_Node := Unit (Parent (Parent_Node));
1218 Unit_Kind := Nkind (Unit_Node);
1220 Analyze (Expression (Arg1));
1222 if Unit_Kind = N_Generic_Subprogram_Declaration
1223 or else Unit_Kind = N_Subprogram_Declaration
1225 Unit_Name := Defining_Entity (Unit_Node);
1227 elsif Unit_Kind = N_Function_Instantiation
1228 or else Unit_Kind = N_Package_Instantiation
1229 or else Unit_Kind = N_Procedure_Instantiation
1231 Unit_Name := Defining_Entity (Unit_Node);
1234 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1237 if Chars (Unit_Name) /=
1238 Chars (Entity (Expression (Arg1)))
1241 ("pragma% argument is not current unit name", Arg1);
1244 if Ekind (Unit_Name) = E_Package
1245 and then Present (Renamed_Entity (Unit_Name))
1247 Error_Pragma ("pragma% not allowed for renamed package");
1251 -- Pragma appears other than after a compilation unit
1254 -- Here we check for the generic instantiation case and also
1255 -- for the case of processing a generic formal package. We
1256 -- detect these cases by noting that the Sloc on the node
1257 -- does not belong to the current compilation unit.
1259 Sindex := Source_Index (Current_Sem_Unit);
1261 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1262 Rewrite (N, Make_Null_Statement (Loc));
1265 -- If before first declaration, the pragma applies to the
1266 -- enclosing unit, and the name if present must be this name.
1268 elsif Is_Before_First_Decl (N, Plist) then
1269 Unit_Node := Unit_Declaration_Node (Current_Scope);
1270 Unit_Kind := Nkind (Unit_Node);
1272 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1275 elsif Unit_Kind = N_Subprogram_Body
1276 and then not Acts_As_Spec (Unit_Node)
1280 elsif Nkind (Parent_Node) = N_Package_Body then
1283 elsif Nkind (Parent_Node) = N_Package_Specification
1284 and then Plist = Private_Declarations (Parent_Node)
1288 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1289 or else Nkind (Parent_Node)
1290 = N_Generic_Subprogram_Declaration)
1291 and then Plist = Generic_Formal_Declarations (Parent_Node)
1295 elsif Arg_Count > 0 then
1296 Analyze (Expression (Arg1));
1298 if Entity (Expression (Arg1)) /= Current_Scope then
1300 ("name in pragma% must be enclosing unit", Arg1);
1303 -- It is legal to have no argument in this context
1309 -- Error if not before first declaration. This is because a
1310 -- library unit pragma argument must be the name of a library
1311 -- unit (RM 10.1.5(7)), but the only names permitted in this
1312 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1313 -- generic subprogram declarations or generic instantiations.
1317 ("pragma% misplaced, must be before first declaration");
1322 end Check_Valid_Library_Unit_Pragma;
1328 procedure Error_Pragma (Msg : String) is
1330 Error_Msg_Name_1 := Chars (N);
1331 Error_Msg_N (Msg, N);
1335 ----------------------
1336 -- Error_Pragma_Arg --
1337 ----------------------
1339 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1341 Error_Msg_Name_1 := Chars (N);
1342 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1344 end Error_Pragma_Arg;
1346 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1348 Error_Msg_Name_1 := Chars (N);
1349 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1350 Error_Pragma_Arg (Msg2, Arg);
1351 end Error_Pragma_Arg;
1353 ----------------------------
1354 -- Error_Pragma_Arg_Ident --
1355 ----------------------------
1357 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1359 Error_Msg_Name_1 := Chars (N);
1360 Error_Msg_N (Msg, Arg);
1362 end Error_Pragma_Arg_Ident;
1364 ------------------------
1365 -- Find_Lib_Unit_Name --
1366 ------------------------
1368 function Find_Lib_Unit_Name return Entity_Id is
1370 -- Return inner compilation unit entity, for case of nested
1371 -- categorization pragmas. This happens in generic unit.
1373 if Nkind (Parent (N)) = N_Package_Specification
1374 and then Defining_Entity (Parent (N)) /= Current_Scope
1376 return Defining_Entity (Parent (N));
1379 return Current_Scope;
1381 end Find_Lib_Unit_Name;
1383 ----------------------------
1384 -- Find_Program_Unit_Name --
1385 ----------------------------
1387 procedure Find_Program_Unit_Name (Id : Node_Id) is
1388 Unit_Name : Entity_Id;
1389 Unit_Kind : Node_Kind;
1390 P : constant Node_Id := Parent (N);
1393 if Nkind (P) = N_Compilation_Unit then
1394 Unit_Kind := Nkind (Unit (P));
1396 if Unit_Kind = N_Subprogram_Declaration
1397 or else Unit_Kind = N_Package_Declaration
1398 or else Unit_Kind in N_Generic_Declaration
1400 Unit_Name := Defining_Entity (Unit (P));
1402 if Chars (Id) = Chars (Unit_Name) then
1403 Set_Entity (Id, Unit_Name);
1404 Set_Etype (Id, Etype (Unit_Name));
1406 Set_Etype (Id, Any_Type);
1408 ("cannot find program unit referenced by pragma%");
1412 Set_Etype (Id, Any_Type);
1413 Error_Pragma ("pragma% inapplicable to this unit");
1420 end Find_Program_Unit_Name;
1422 -------------------------
1423 -- Gather_Associations --
1424 -------------------------
1426 procedure Gather_Associations
1428 Args : out Args_List)
1433 -- Initialize all parameters to Empty
1435 for J in Args'Range loop
1439 -- That's all we have to do if there are no argument associations
1441 if No (Pragma_Argument_Associations (N)) then
1445 -- Otherwise first deal with any positional parameters present
1447 Arg := First (Pragma_Argument_Associations (N));
1449 for Index in Args'Range loop
1450 exit when No (Arg) or else Chars (Arg) /= No_Name;
1451 Args (Index) := Expression (Arg);
1455 -- Positional parameters all processed, if any left, then we
1456 -- have too many positional parameters.
1458 if Present (Arg) and then Chars (Arg) = No_Name then
1460 ("too many positional associations for pragma%", Arg);
1463 -- Process named parameters if any are present
1465 while Present (Arg) loop
1466 if Chars (Arg) = No_Name then
1468 ("positional association cannot follow named association",
1472 for Index in Names'Range loop
1473 if Names (Index) = Chars (Arg) then
1474 if Present (Args (Index)) then
1476 ("duplicate argument association for pragma%", Arg);
1478 Args (Index) := Expression (Arg);
1483 if Index = Names'Last then
1484 Error_Pragma_Arg_Ident
1485 ("pragma% does not allow & argument", Arg);
1492 end Gather_Associations;
1494 --------------------
1495 -- Get_Pragma_Arg --
1496 --------------------
1498 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1500 if Nkind (Arg) = N_Pragma_Argument_Association then
1501 return Expression (Arg);
1511 procedure GNAT_Pragma is
1513 Check_Restriction (No_Implementation_Pragmas, N);
1516 --------------------------
1517 -- Is_Before_First_Decl --
1518 --------------------------
1520 function Is_Before_First_Decl
1521 (Pragma_Node : Node_Id;
1525 Item : Node_Id := First (Decls);
1528 -- Only other pragmas can come before this pragma
1531 if No (Item) or else Nkind (Item) /= N_Pragma then
1534 elsif Item = Pragma_Node then
1541 end Is_Before_First_Decl;
1543 -----------------------------
1544 -- Is_Configuration_Pragma --
1545 -----------------------------
1547 -- A configuration pragma must appear in the context clause of
1548 -- a compilation unit, at the start of the list (i.e. only other
1549 -- pragmas may precede it).
1551 function Is_Configuration_Pragma return Boolean is
1552 Lis : constant List_Id := List_Containing (N);
1553 Par : constant Node_Id := Parent (N);
1557 -- If no parent, then we are in the configuration pragma file,
1558 -- so the placement is definitely appropriate.
1563 -- Otherwise we must be in the context clause of a compilation unit
1564 -- and the only thing allowed before us in the context list is more
1565 -- configuration pragmas.
1567 elsif Nkind (Par) = N_Compilation_Unit
1568 and then Context_Items (Par) = Lis
1575 elsif Nkind (Prg) /= N_Pragma then
1586 end Is_Configuration_Pragma;
1588 ----------------------
1589 -- Pragma_Misplaced --
1590 ----------------------
1592 procedure Pragma_Misplaced is
1594 Error_Pragma ("incorrect placement of pragma%");
1595 end Pragma_Misplaced;
1597 ------------------------------------
1598 -- Process Atomic_Shared_Volatile --
1599 ------------------------------------
1601 procedure Process_Atomic_Shared_Volatile is
1609 Check_Ada_83_Warning;
1610 Check_No_Identifiers;
1611 Check_Arg_Count (1);
1612 Check_Arg_Is_Local_Name (Arg1);
1613 E_Id := Expression (Arg1);
1615 if Etype (E_Id) = Any_Type then
1620 D := Declaration_Node (E);
1624 if Rep_Item_Too_Early (E, N)
1626 Rep_Item_Too_Late (E, N)
1630 Check_First_Subtype (Arg1);
1633 if Prag_Id /= Pragma_Volatile then
1635 Set_Is_Atomic (Underlying_Type (E));
1638 Set_Is_Volatile (E);
1639 Set_Is_Volatile (Underlying_Type (E));
1641 elsif K = N_Object_Declaration
1642 or else (K = N_Component_Declaration
1643 and then Original_Record_Component (E) = E)
1645 if Rep_Item_Too_Late (E, N) then
1649 if Prag_Id /= Pragma_Volatile then
1653 Set_Is_Volatile (E);
1657 ("inappropriate entity for pragma%", Arg1);
1659 end Process_Atomic_Shared_Volatile;
1661 ------------------------
1662 -- Process_Convention --
1663 ------------------------
1665 procedure Process_Convention
1666 (C : out Convention_Id;
1671 Comp_Unit : Unit_Number_Type;
1674 procedure Set_Convention_From_Pragma (E : Entity_Id);
1675 -- Set convention in entity E, and also flag that the entity has a
1676 -- convention pragma. If entity is for a private or incomplete type,
1677 -- also set convention and flag on underlying type. This procedure
1678 -- also deals with the special case of C_Pass_By_Copy convention.
1680 --------------------------------
1681 -- Set_Convention_From_Pragma --
1682 --------------------------------
1684 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1686 Set_Convention (E, C);
1687 Set_Has_Convention_Pragma (E);
1689 if Is_Incomplete_Or_Private_Type (E) then
1690 Set_Convention (Underlying_Type (E), C);
1691 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1694 -- A class-wide type should inherit the convention of
1695 -- the specific root type (although this isn't specified
1696 -- clearly by the RM).
1698 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1699 Set_Convention (Class_Wide_Type (E), C);
1702 -- If the entity is a record type, then check for special case
1703 -- of C_Pass_By_Copy, which is treated the same as C except that
1704 -- the special record flag is set. This convention is also only
1705 -- permitted on record types (see AI95-00131).
1707 if Cname = Name_C_Pass_By_Copy then
1708 if Is_Record_Type (E) then
1709 Set_C_Pass_By_Copy (Base_Type (E));
1710 elsif Is_Incomplete_Or_Private_Type (E)
1711 and then Is_Record_Type (Underlying_Type (E))
1713 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1716 ("C_Pass_By_Copy convention allowed only for record type",
1721 -- If the entity is a derived boolean type, check for the
1722 -- special case of convention C, C++, or Fortran, where we
1723 -- consider any nonzero value to represent true.
1725 if Is_Discrete_Type (E)
1726 and then Root_Type (Etype (E)) = Standard_Boolean
1732 C = Convention_Fortran)
1734 Set_Nonzero_Is_True (Base_Type (E));
1736 end Set_Convention_From_Pragma;
1738 -- Start of processing for Process_Convention
1741 Check_At_Least_N_Arguments (2);
1742 Check_Arg_Is_Identifier (Arg1);
1743 Check_Optional_Identifier (Arg1, Name_Convention);
1744 Cname := Chars (Expression (Arg1));
1746 -- C_Pass_By_Copy is treated as a synonym for convention C
1747 -- (this is tested again below to set the critical flag)
1749 if Cname = Name_C_Pass_By_Copy then
1752 -- Otherwise we must have something in the standard convention list
1754 elsif Is_Convention_Name (Cname) then
1755 C := Get_Convention_Id (Chars (Expression (Arg1)));
1757 -- In DEC VMS, it seems that there is an undocumented feature
1758 -- that any unrecognized convention is treated as the default,
1759 -- which for us is convention C. It does not seem so terrible
1760 -- to do this unconditionally, silently in the VMS case, and
1761 -- with a warning in the non-VMS case.
1764 if not OpenVMS_On_Target then
1766 ("?unrecognized convention name, C assumed",
1773 Check_Arg_Is_Local_Name (Arg2);
1774 Check_Optional_Identifier (Arg2, Name_Entity);
1776 Id := Expression (Arg2);
1779 if not Is_Entity_Name (Id) then
1780 Error_Pragma_Arg ("entity name required", Arg2);
1785 -- Go to renamed subprogram if present, since convention applies
1786 -- to the actual renamed entity, not to the renaming entity.
1788 if Is_Subprogram (E)
1789 and then Present (Alias (E))
1790 and then Nkind (Parent (Declaration_Node (E))) =
1791 N_Subprogram_Renaming_Declaration
1796 -- Check that we not applying this to a specless body
1798 if Is_Subprogram (E)
1799 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
1802 ("pragma% requires separate spec and must come before body");
1805 -- Check that we are not applying this to a named constant
1807 if Ekind (E) = E_Named_Integer
1809 Ekind (E) = E_Named_Real
1811 Error_Msg_Name_1 := Chars (N);
1813 ("cannot apply pragma% to named constant!",
1814 Get_Pragma_Arg (Arg2));
1816 ("\supply appropriate type for&!", Arg2);
1819 if Etype (E) = Any_Type
1820 or else Rep_Item_Too_Early (E, N)
1824 E := Underlying_Type (E);
1827 if Rep_Item_Too_Late (E, N) then
1831 if Has_Convention_Pragma (E) then
1833 ("at most one Convention/Export/Import pragma is allowed", Arg2);
1835 elsif Convention (E) = Convention_Protected
1836 or else Ekind (Scope (E)) = E_Protected_Type
1839 ("a protected operation cannot be given a different convention",
1843 -- For Intrinsic, a subprogram is required
1845 if C = Convention_Intrinsic
1846 and then not Is_Subprogram (E)
1847 and then not Is_Generic_Subprogram (E)
1850 ("second argument of pragma% must be a subprogram", Arg2);
1853 -- For Stdcall, a subprogram, variable or subprogram type is required
1855 if C = Convention_Stdcall
1856 and then not Is_Subprogram (E)
1857 and then not Is_Generic_Subprogram (E)
1858 and then Ekind (E) /= E_Variable
1861 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
1864 ("second argument of pragma% must be subprogram (type)",
1868 if not Is_Subprogram (E)
1869 and then not Is_Generic_Subprogram (E)
1871 Set_Convention_From_Pragma (E);
1875 Check_First_Subtype (Arg2);
1876 Set_Convention_From_Pragma (Base_Type (E));
1878 -- For subprograms, we must set the convention on the
1879 -- internally generated directly designated type as well.
1881 if Ekind (E) = E_Access_Subprogram_Type then
1882 Set_Convention_From_Pragma (Directly_Designated_Type (E));
1886 -- For the subprogram case, set proper convention for all homonyms
1887 -- in same compilation unit.
1888 -- Is the test of compilation unit really necessary ???
1889 -- What about subprogram renamings here???
1892 Comp_Unit := Get_Source_Unit (E);
1893 Set_Convention_From_Pragma (E);
1898 exit when No (E1) or else Scope (E1) /= Current_Scope;
1900 -- Note: below we are missing a check for Rep_Item_Too_Late.
1901 -- That is deliberate, we cannot chain the rep item on more
1902 -- than one Rep_Item chain, to be fixed later ???
1904 if Comp_Unit = Get_Source_Unit (E1) then
1905 Set_Convention_From_Pragma (E1);
1910 end Process_Convention;
1912 -----------------------------------------------------
1913 -- Process_Extended_Import_Export_Exception_Pragma --
1914 -----------------------------------------------------
1916 procedure Process_Extended_Import_Export_Exception_Pragma
1917 (Arg_Internal : Node_Id;
1918 Arg_External : Node_Id;
1926 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
1927 Def_Id := Entity (Arg_Internal);
1929 if Ekind (Def_Id) /= E_Exception then
1931 ("pragma% must refer to declared exception", Arg_Internal);
1934 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
1936 if Present (Arg_Form) then
1937 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
1940 if Present (Arg_Form)
1941 and then Chars (Arg_Form) = Name_Ada
1945 Set_Is_VMS_Exception (Def_Id);
1946 Set_Exception_Code (Def_Id, No_Uint);
1949 if Present (Arg_Code) then
1950 if not Is_VMS_Exception (Def_Id) then
1952 ("Code option for pragma% not allowed for Ada case",
1956 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
1957 Code_Val := Expr_Value (Arg_Code);
1959 if not UI_Is_In_Int_Range (Code_Val) then
1961 ("Code option for pragma% must be in 32-bit range",
1965 Set_Exception_Code (Def_Id, Code_Val);
1969 end Process_Extended_Import_Export_Exception_Pragma;
1971 -------------------------------------------------
1972 -- Process_Extended_Import_Export_Internal_Arg --
1973 -------------------------------------------------
1975 procedure Process_Extended_Import_Export_Internal_Arg
1976 (Arg_Internal : Node_Id := Empty)
1981 if No (Arg_Internal) then
1982 Error_Pragma ("Internal parameter required for pragma%");
1985 if Nkind (Arg_Internal) = N_Identifier then
1988 elsif Nkind (Arg_Internal) = N_Operator_Symbol
1989 and then (Prag_Id = Pragma_Import_Function
1991 Prag_Id = Pragma_Export_Function)
1997 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2000 Check_Arg_Is_Local_Name (Arg_Internal);
2002 end Process_Extended_Import_Export_Internal_Arg;
2004 --------------------------------------------------
2005 -- Process_Extended_Import_Export_Object_Pragma --
2006 --------------------------------------------------
2008 procedure Process_Extended_Import_Export_Object_Pragma
2009 (Arg_Internal : Node_Id;
2010 Arg_External : Node_Id;
2016 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2017 Def_Id := Entity (Arg_Internal);
2019 if Ekind (Def_Id) /= E_Constant
2020 and then Ekind (Def_Id) /= E_Variable
2023 ("pragma% must designate an object", Arg_Internal);
2026 if Is_Psected (Def_Id) then
2028 ("previous Psect_Object applies, pragma % not permitted",
2032 if Rep_Item_Too_Late (Def_Id, N) then
2036 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2038 if Present (Arg_Size)
2039 and then Nkind (Arg_Size) /= N_Identifier
2040 and then Nkind (Arg_Size) /= N_String_Literal
2043 ("pragma% Size argument must be identifier or string literal",
2047 -- Export_Object case
2049 if Prag_Id = Pragma_Export_Object then
2051 if not Is_Library_Level_Entity (Def_Id) then
2053 ("argument for pragma% must be library level entity",
2057 if Ekind (Current_Scope) = E_Generic_Package then
2058 Error_Pragma ("pragma& cannot appear in a generic unit");
2061 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2063 ("exported object must have compile time known size",
2067 if Is_Exported (Def_Id) then
2069 ("?duplicate Export_Object pragma", N);
2071 Set_Exported (Def_Id, Arg_Internal);
2074 -- Import_Object case
2077 if Is_Concurrent_Type (Etype (Def_Id)) then
2079 ("cannot use pragma% for task/protected object",
2083 if Ekind (Def_Id) = E_Constant then
2085 ("cannot import a constant", Arg_Internal);
2088 if Has_Discriminants (Etype (Def_Id)) then
2090 ("imported value must be initialized?", Arg_Internal);
2093 if Is_Access_Type (Etype (Def_Id)) then
2095 ("cannot import object of an access type?", Arg_Internal);
2098 if Is_Imported (Def_Id) then
2100 ("?duplicate Import_Object pragma", N);
2102 Set_Imported (Def_Id);
2106 end Process_Extended_Import_Export_Object_Pragma;
2108 ------------------------------------------------------
2109 -- Process_Extended_Import_Export_Subprogram_Pragma --
2110 ------------------------------------------------------
2112 procedure Process_Extended_Import_Export_Subprogram_Pragma
2113 (Arg_Internal : Node_Id;
2114 Arg_External : Node_Id;
2115 Arg_Parameter_Types : Node_Id;
2116 Arg_Result_Type : Node_Id := Empty;
2117 Arg_Mechanism : Node_Id;
2118 Arg_Result_Mechanism : Node_Id := Empty;
2119 Arg_First_Optional_Parameter : Node_Id := Empty)
2125 Ambiguous : Boolean;
2129 function Same_Base_Type (Ptype, Formal : Entity_Id) return Boolean;
2130 -- Determines if Ptype references the type of Formal. Note that
2131 -- only the base types need to match according to the spec.
2133 function Same_Base_Type (Ptype, Formal : Entity_Id) return Boolean is
2137 if not Is_Entity_Name (Ptype)
2138 or else Entity (Ptype) = Any_Type
2143 return Base_Type (Entity (Ptype)) = Base_Type (Etype (Formal));
2146 -- Start of processing for
2147 -- Process_Extended_Import_Export_Subprogram_Pragma
2150 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2151 Hom_Id := Entity (Arg_Internal);
2155 -- Loop through homonyms (overloadings) of Hom_Id
2157 while Present (Hom_Id) loop
2158 Def_Id := Get_Base_Subprogram (Hom_Id);
2160 -- We need a subprogram in the current scope
2162 if not Is_Subprogram (Def_Id)
2163 or else Scope (Def_Id) /= Current_Scope
2170 -- Pragma cannot apply to subprogram body
2172 if Is_Subprogram (Def_Id)
2175 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2178 ("pragma% requires separate spec"
2179 & " and must come before body");
2182 -- Test result type if given, note that the result type
2183 -- parameter can only be present for the function cases.
2185 if Present (Arg_Result_Type)
2186 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2190 -- Test parameter types if given. Note that this parameter
2191 -- has not been analyzed (and must not be, since it is
2192 -- semantic nonsense), so we get it as the parser left it.
2194 elsif Present (Arg_Parameter_Types) then
2195 Check_Matching_Types : declare
2200 Formal := First_Formal (Def_Id);
2202 if Nkind (Arg_Parameter_Types) = N_Null then
2203 if Present (Formal) then
2207 -- A list of one type, e.g. (List) is parsed as
2208 -- a parenthesized expression.
2210 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2211 and then Paren_Count (Arg_Parameter_Types) = 1
2214 or else Present (Next_Formal (Formal))
2219 Same_Base_Type (Arg_Parameter_Types, Formal);
2222 -- A list of more than one type is parsed as a aggregate
2224 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2225 and then Paren_Count (Arg_Parameter_Types) = 0
2227 Ptype := First (Expressions (Arg_Parameter_Types));
2229 while Present (Ptype) or else Present (Formal) loop
2232 or else not Same_Base_Type (Ptype, Formal)
2237 Next_Formal (Formal);
2242 -- Anything else is of the wrong form
2246 ("wrong form for Parameter_Types parameter",
2247 Arg_Parameter_Types);
2249 end Check_Matching_Types;
2252 -- Match is now False if the entry we found did not match
2253 -- either a supplied Parameter_Types or Result_Types argument
2259 -- Ambiguous case, the flag Ambiguous shows if we already
2260 -- detected this and output the initial messages.
2263 if not Ambiguous then
2265 Error_Msg_Name_1 := Chars (N);
2267 ("pragma% does not uniquely identify subprogram!",
2269 Error_Msg_Sloc := Sloc (Ent);
2270 Error_Msg_N ("matching subprogram #!", N);
2274 Error_Msg_Sloc := Sloc (Def_Id);
2275 Error_Msg_N ("matching subprogram #!", N);
2280 Hom_Id := Homonym (Hom_Id);
2283 -- See if we found an entry
2286 if not Ambiguous then
2287 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2289 ("pragma% cannot be given for generic subprogram");
2293 ("pragma% does not identify local subprogram");
2300 -- Import pragmas must be be for imported entities
2302 if (Prag_Id = Pragma_Import_Function
2304 Prag_Id = Pragma_Import_Procedure
2306 Prag_Id = Pragma_Import_Valued_Procedure)
2308 if not Is_Imported (Ent) then
2310 ("pragma Import or Interface must precede pragma%");
2313 -- For the Export cases, the pragma Export is sufficient to set
2314 -- the entity as exported, if it is not exported already. We
2315 -- leave the default Ada convention in this case.
2318 Set_Exported (Ent, Arg_Internal);
2321 -- Special processing for Valued_Procedure cases
2323 if Prag_Id = Pragma_Import_Valued_Procedure
2325 Prag_Id = Pragma_Export_Valued_Procedure
2327 Formal := First_Formal (Ent);
2331 ("at least one parameter required for pragma%");
2333 elsif Ekind (Formal) /= E_Out_Parameter then
2335 ("first parameter must have mode out for pragma%");
2338 Set_Is_Valued_Procedure (Ent);
2342 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2344 -- Process Result_Mechanism argument if present. We have already
2345 -- checked that this is only allowed for the function case.
2347 if Present (Arg_Result_Mechanism) then
2348 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2351 -- Process Mechanism parameter if present. Note that this parameter
2352 -- is not analyzed, and must not be analyzed since it is semantic
2353 -- nonsense, so we get it in exactly as the parser left it.
2355 if Present (Arg_Mechanism) then
2364 -- A single mechanism association without a formal parameter
2365 -- name is parsed as a parenthesized expression. All other
2366 -- cases are parsed as aggregates, so we rewrite the single
2367 -- parameter case as an aggregate for consistency.
2369 if Nkind (Arg_Mechanism) /= N_Aggregate
2370 and then Paren_Count (Arg_Mechanism) = 1
2372 Rewrite (Arg_Mechanism,
2373 Make_Aggregate (Sloc (Arg_Mechanism),
2374 Expressions => New_List (
2375 Relocate_Node (Arg_Mechanism))));
2378 -- Case of only mechanism name given, applies to all formals
2380 if Nkind (Arg_Mechanism) /= N_Aggregate then
2381 Formal := First_Formal (Ent);
2382 while Present (Formal) loop
2383 Set_Mechanism_Value (Formal, Arg_Mechanism);
2384 Next_Formal (Formal);
2387 -- Case of list of mechanism associations given
2390 if Null_Record_Present (Arg_Mechanism) then
2392 ("inappropriate form for Mechanism parameter",
2396 -- Deal with positional ones first
2398 Formal := First_Formal (Ent);
2399 if Present (Expressions (Arg_Mechanism)) then
2400 Mname := First (Expressions (Arg_Mechanism));
2402 while Present (Mname) loop
2405 ("too many mechanism associations", Mname);
2408 Set_Mechanism_Value (Formal, Mname);
2409 Next_Formal (Formal);
2414 -- Deal with named entries
2416 if Present (Component_Associations (Arg_Mechanism)) then
2417 Massoc := First (Component_Associations (Arg_Mechanism));
2419 while Present (Massoc) loop
2420 Choice := First (Choices (Massoc));
2422 if Nkind (Choice) /= N_Identifier
2423 or else Present (Next (Choice))
2426 ("incorrect form for mechanism association",
2430 Formal := First_Formal (Ent);
2434 ("parameter name & not present", Choice);
2437 if Chars (Choice) = Chars (Formal) then
2439 (Formal, Expression (Massoc));
2443 Next_Formal (Formal);
2453 -- Process First_Optional_Parameter argument if present. We have
2454 -- already checked that this is only allowed for the Import case.
2456 if Present (Arg_First_Optional_Parameter) then
2457 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2459 ("first optional parameter must be formal parameter name",
2460 Arg_First_Optional_Parameter);
2463 Formal := First_Formal (Ent);
2467 ("specified formal parameter& not found",
2468 Arg_First_Optional_Parameter);
2471 exit when Chars (Formal) =
2472 Chars (Arg_First_Optional_Parameter);
2474 Next_Formal (Formal);
2477 Set_First_Optional_Parameter (Ent, Formal);
2479 -- Check specified and all remaining formals have right form
2481 while Present (Formal) loop
2482 if Ekind (Formal) /= E_In_Parameter then
2484 ("optional formal& is not of mode in!",
2485 Arg_First_Optional_Parameter, Formal);
2488 Dval := Default_Value (Formal);
2490 if not Present (Dval) then
2492 ("optional formal& does not have default value!",
2493 Arg_First_Optional_Parameter, Formal);
2495 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2500 ("default value for optional formal& is non-static!",
2501 Arg_First_Optional_Parameter, Formal);
2505 Set_Is_Optional_Parameter (Formal);
2506 Next_Formal (Formal);
2510 end Process_Extended_Import_Export_Subprogram_Pragma;
2512 --------------------------
2513 -- Process_Generic_List --
2514 --------------------------
2516 procedure Process_Generic_List is
2522 Check_No_Identifiers;
2523 Check_At_Least_N_Arguments (1);
2526 while Present (Arg) loop
2527 Exp := Expression (Arg);
2530 if not Is_Entity_Name (Exp)
2532 (not Is_Generic_Instance (Entity (Exp))
2534 not Is_Generic_Unit (Entity (Exp)))
2537 ("pragma% argument must be name of generic unit/instance",
2543 end Process_Generic_List;
2545 ---------------------------------
2546 -- Process_Import_Or_Interface --
2547 ---------------------------------
2549 procedure Process_Import_Or_Interface is
2555 Process_Convention (C, Def_Id);
2556 Kill_Size_Check_Code (Def_Id);
2557 Note_Possible_Modification (Expression (Arg2));
2559 if Ekind (Def_Id) = E_Variable
2561 Ekind (Def_Id) = E_Constant
2563 -- User initialization is not allowed for imported object, but
2564 -- the object declaration may contain a default initialization,
2565 -- that will be discarded.
2567 if Present (Expression (Parent (Def_Id)))
2568 and then Comes_From_Source (Expression (Parent (Def_Id)))
2570 Error_Msg_Sloc := Sloc (Def_Id);
2572 ("no initialization allowed for declaration of& #",
2573 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2577 Set_Imported (Def_Id);
2578 Set_Is_Public (Def_Id);
2579 Process_Interface_Name (Def_Id, Arg3, Arg4);
2582 elsif Is_Subprogram (Def_Id)
2583 or else Is_Generic_Subprogram (Def_Id)
2585 -- If the name is overloaded, pragma applies to all of the
2586 -- denoted entities in the same declarative part.
2590 while Present (Hom_Id) loop
2591 Def_Id := Get_Base_Subprogram (Hom_Id);
2593 -- Ignore inherited subprograms because the pragma will
2594 -- apply to the parent operation, which is the one called.
2596 if Is_Overloadable (Def_Id)
2597 and then Present (Alias (Def_Id))
2601 -- Verify that the homonym is in the same declarative
2602 -- part (not just the same scope).
2604 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2605 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2610 Set_Imported (Def_Id);
2612 -- If Import intrinsic, set intrinsic flag
2613 -- and verify that it is known as such.
2615 if C = Convention_Intrinsic then
2616 Set_Is_Intrinsic_Subprogram (Def_Id);
2617 Check_Intrinsic_Subprogram
2618 (Def_Id, Expression (Arg2));
2621 -- All interfaced procedures need an external
2622 -- symbol created for them since they are
2623 -- always referenced from another object file.
2625 Set_Is_Public (Def_Id);
2626 Set_Has_Completion (Def_Id);
2627 Process_Interface_Name (Def_Id, Arg3, Arg4);
2630 if Is_Compilation_Unit (Hom_Id) then
2632 -- Its possible homonyms are not affected by the pragma.
2633 -- Such homonyms might be present in the context of other
2634 -- units being compiled.
2639 Hom_Id := Homonym (Hom_Id);
2643 -- When the convention is Java, we also allow Import to be given
2644 -- for packages, exceptions, and record components.
2646 elsif C = Convention_Java
2647 and then (Ekind (Def_Id) = E_Package
2648 or else Ekind (Def_Id) = E_Exception
2649 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
2651 Set_Imported (Def_Id);
2652 Set_Is_Public (Def_Id);
2653 Process_Interface_Name (Def_Id, Arg3, Arg4);
2657 ("second argument of pragma% must be object or subprogram",
2661 -- If this pragma applies to a compilation unit, then the unit,
2662 -- which is a subprogram, does not require (or allow) a body.
2663 -- We also do not need to elaborate imported procedures.
2665 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2667 Cunit : constant Node_Id := Parent (Parent (N));
2670 Set_Body_Required (Cunit, False);
2674 end Process_Import_Or_Interface;
2676 --------------------
2677 -- Process_Inline --
2678 --------------------
2680 procedure Process_Inline (Active : Boolean) is
2687 procedure Make_Inline (Subp : Entity_Id);
2688 -- Subp is the defining unit name of the subprogram
2689 -- declaration. Set the flag, as well as the flag in the
2690 -- corresponding body, if there is one present.
2692 procedure Set_Inline_Flags (Subp : Entity_Id);
2693 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
2699 procedure Make_Inline (Subp : Entity_Id) is
2700 Kind : Entity_Kind := Ekind (Subp);
2701 Inner_Subp : Entity_Id := Subp;
2704 if Etype (Subp) = Any_Type then
2707 -- Here we have a candidate for inlining, but we must exclude
2708 -- derived operations. Otherwise we will end up trying to
2709 -- inline a phantom declaration, and the result would be to
2710 -- drag in a body which has no direct inlining associated with
2711 -- it. That would not only be inefficient but would also result
2712 -- in the backend doing cross-unit inlining in cases where it
2713 -- was definitely inappropriate to do so.
2715 -- However, a simple Comes_From_Source test is insufficient,
2716 -- since we do want to allow inlining of generic instances,
2717 -- which also do not come from source. Predefined operators do
2718 -- not come from source but are not inlineable either.
2720 elsif not Comes_From_Source (Subp)
2721 and then not Is_Generic_Instance (Subp)
2722 and then Scope (Subp) /= Standard_Standard
2727 -- The referenced entity must either be the enclosing entity,
2728 -- or an entity declared within the current open scope.
2730 elsif Present (Scope (Subp))
2731 and then Scope (Subp) /= Current_Scope
2732 and then Subp /= Current_Scope
2735 ("argument of% must be entity in current scope", Assoc);
2739 -- Processing for procedure, operator or function.
2740 -- If subprogram is aliased (as for an instance) indicate
2741 -- that the renamed entity is inlined.
2743 if Kind = E_Procedure
2744 or else Kind = E_Function
2745 or else Kind = E_Operator
2747 while Present (Alias (Inner_Subp)) loop
2748 Inner_Subp := Alias (Inner_Subp);
2751 Set_Inline_Flags (Inner_Subp);
2753 Decl := Parent (Parent (Inner_Subp));
2755 if Nkind (Decl) = N_Subprogram_Declaration
2756 and then Present (Corresponding_Body (Decl))
2758 Set_Inline_Flags (Corresponding_Body (Decl));
2763 -- For a generic subprogram set flag as well, for use at
2764 -- the point of instantiation, to determine whether the
2765 -- body should be generated.
2767 elsif Kind = E_Generic_Procedure
2768 or else Kind = E_Generic_Function
2770 Set_Inline_Flags (Subp);
2773 -- Literals are by definition inlined.
2775 elsif Kind = E_Enumeration_Literal then
2778 -- Anything else is an error
2782 ("expect subprogram name for pragma%", Assoc);
2786 ----------------------
2787 -- Set_Inline_Flags --
2788 ----------------------
2790 procedure Set_Inline_Flags (Subp : Entity_Id) is
2793 Set_Is_Inlined (Subp, True);
2796 if not Has_Pragma_Inline (Subp) then
2797 Set_Has_Pragma_Inline (Subp);
2798 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
2799 Set_First_Rep_Item (Subp, N);
2801 end Set_Inline_Flags;
2803 -- Start of processing for Process_Inline
2806 Check_No_Identifiers;
2807 Check_At_Least_N_Arguments (1);
2810 Inline_Processing_Required := True;
2814 while Present (Assoc) loop
2815 Subp_Id := Expression (Assoc);
2819 if Is_Entity_Name (Subp_Id) then
2820 Subp := Entity (Subp_Id);
2822 if Subp = Any_Id then
2828 while Present (Homonym (Subp))
2829 and then Scope (Homonym (Subp)) = Current_Scope
2831 Make_Inline (Homonym (Subp));
2832 Subp := Homonym (Subp);
2839 ("inappropriate argument for pragma%", Assoc);
2847 ----------------------------
2848 -- Process_Interface_Name --
2849 ----------------------------
2851 procedure Process_Interface_Name
2852 (Subprogram_Def : Entity_Id;
2858 String_Val : String_Id;
2860 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
2861 -- SN is a string literal node for an interface name. This routine
2862 -- performs some minimal checks that the name is reasonable. In
2863 -- particular that no spaces or other obviously incorrect characters
2864 -- appear. This is only a warning, since any characters are allowed.
2866 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
2867 S : constant String_Id := Strval (Expr_Value_S (SN));
2868 SL : constant Nat := String_Length (S);
2873 Error_Msg_N ("interface name cannot be null string", SN);
2876 for J in 1 .. SL loop
2877 C := Get_String_Char (S, J);
2879 if not In_Character_Range (C)
2880 or else Get_Character (C) = ' '
2881 or else Get_Character (C) = ','
2884 ("?interface name contains illegal character", SN);
2887 end Check_Form_Of_Interface_Name;
2889 -- Start of processing for Process_Interface_Name
2892 if No (Link_Arg) then
2893 if No (Ext_Arg) then
2896 elsif Chars (Ext_Arg) = Name_Link_Name then
2898 Link_Nam := Expression (Ext_Arg);
2901 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
2902 Ext_Nam := Expression (Ext_Arg);
2907 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
2908 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
2909 Ext_Nam := Expression (Ext_Arg);
2910 Link_Nam := Expression (Link_Arg);
2913 -- Check expressions for external name and link name are static
2915 if Present (Ext_Nam) then
2916 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
2917 Check_Form_Of_Interface_Name (Ext_Nam);
2919 -- Verify that the external name is not the name of a local
2920 -- entity, which would hide the imported one and lead to
2921 -- run-time surprises. The problem can only arise for entities
2922 -- declared in a package body (otherwise the external name is
2923 -- fully qualified and won't conflict).
2931 if Prag_Id = Pragma_Import then
2932 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
2934 E := Entity_Id (Get_Name_Table_Info (Nam));
2936 if Nam /= Chars (Subprogram_Def)
2937 and then Present (E)
2938 and then not Is_Overloadable (E)
2939 and then Is_Immediately_Visible (E)
2940 and then not Is_Imported (E)
2941 and then Ekind (Scope (E)) = E_Package
2945 while Present (Par) loop
2946 if Nkind (Par) = N_Package_Body then
2947 Error_Msg_Sloc := Sloc (E);
2949 ("imported entity is hidden by & declared#",
2954 Par := Parent (Par);
2961 if Present (Link_Nam) then
2962 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
2963 Check_Form_Of_Interface_Name (Link_Nam);
2966 -- If there is no link name, just set the external name
2968 if No (Link_Nam) then
2969 Set_Encoded_Interface_Name
2970 (Get_Base_Subprogram (Subprogram_Def),
2971 Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)));
2973 -- For the Link_Name case, the given literal is preceded by an
2974 -- asterisk, which indicates to GCC that the given name should
2975 -- be taken literally, and in particular that no prepending of
2976 -- underlines should occur, even in systems where this is the
2981 Store_String_Char (Get_Char_Code ('*'));
2982 String_Val := Strval (Expr_Value_S (Link_Nam));
2984 for J in 1 .. String_Length (String_Val) loop
2985 Store_String_Char (Get_String_Char (String_Val, J));
2989 Make_String_Literal (Sloc (Link_Nam), End_String);
2991 Set_Encoded_Interface_Name
2992 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
2994 end Process_Interface_Name;
2996 -----------------------------------------
2997 -- Process_Interrupt_Or_Attach_Handler --
2998 -----------------------------------------
3000 procedure Process_Interrupt_Or_Attach_Handler is
3001 Arg1_X : constant Node_Id := Expression (Arg1);
3002 Prot_Proc : constant Entity_Id := Entity (Arg1_X);
3003 Prot_Type : constant Entity_Id := Scope (Prot_Proc);
3006 Set_Is_Interrupt_Handler (Prot_Proc);
3008 if Prag_Id = Pragma_Interrupt_Handler
3009 or Prag_Id = Pragma_Attach_Handler
3011 Record_Rep_Item (Prot_Type, N);
3014 end Process_Interrupt_Or_Attach_Handler;
3016 ---------------------------------
3017 -- Process_Suppress_Unsuppress --
3018 ---------------------------------
3020 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3024 Effective : Boolean;
3026 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3027 -- Used to suppress a single check on the given entity
3029 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3031 -- First set appropriate suppress flags in the entity
3034 when Access_Check =>
3035 Effective := Suppress_Access_Checks (E);
3036 Set_Suppress_Access_Checks (E, Suppress_Case);
3038 when Accessibility_Check =>
3039 Effective := Suppress_Accessibility_Checks (E);
3040 Set_Suppress_Accessibility_Checks (E, Suppress_Case);
3042 when Discriminant_Check =>
3043 Effective := Suppress_Discriminant_Checks (E);
3044 Set_Suppress_Discriminant_Checks (E, Suppress_Case);
3046 when Division_Check =>
3047 Effective := Suppress_Division_Checks (E);
3048 Set_Suppress_Division_Checks (E, Suppress_Case);
3050 when Elaboration_Check =>
3051 Effective := Suppress_Elaboration_Checks (E);
3052 Set_Suppress_Elaboration_Checks (E, Suppress_Case);
3055 Effective := Suppress_Index_Checks (E);
3056 Set_Suppress_Index_Checks (E, Suppress_Case);
3058 when Length_Check =>
3059 Effective := Suppress_Length_Checks (E);
3060 Set_Suppress_Length_Checks (E, Suppress_Case);
3062 when Overflow_Check =>
3063 Effective := Suppress_Overflow_Checks (E);
3064 Set_Suppress_Overflow_Checks (E, Suppress_Case);
3067 Effective := Suppress_Range_Checks (E);
3068 Set_Suppress_Range_Checks (E, Suppress_Case);
3070 when Storage_Check =>
3071 Effective := Suppress_Storage_Checks (E);
3072 Set_Suppress_Storage_Checks (E, Suppress_Case);
3075 Effective := Suppress_Tag_Checks (E);
3076 Set_Suppress_Tag_Checks (E, Suppress_Case);
3079 Suppress_Unsuppress_Echeck (E, Access_Check);
3080 Suppress_Unsuppress_Echeck (E, Accessibility_Check);
3081 Suppress_Unsuppress_Echeck (E, Discriminant_Check);
3082 Suppress_Unsuppress_Echeck (E, Division_Check);
3083 Suppress_Unsuppress_Echeck (E, Elaboration_Check);
3084 Suppress_Unsuppress_Echeck (E, Index_Check);
3085 Suppress_Unsuppress_Echeck (E, Length_Check);
3086 Suppress_Unsuppress_Echeck (E, Overflow_Check);
3087 Suppress_Unsuppress_Echeck (E, Range_Check);
3088 Suppress_Unsuppress_Echeck (E, Storage_Check);
3089 Suppress_Unsuppress_Echeck (E, Tag_Check);
3092 -- If the entity is not declared in the current scope, then we
3093 -- make an entry in the Entity_Suppress table so that the flag
3094 -- will be removed on exit. This entry is only made if the
3095 -- suppress did something (i.e. the flag was not already set).
3097 if Effective and then Scope (E) /= Current_Scope then
3098 Entity_Suppress.Increment_Last;
3099 Entity_Suppress.Table
3100 (Entity_Suppress.Last).Entity := E;
3101 Entity_Suppress.Table
3102 (Entity_Suppress.Last).Check := C;
3105 -- If this is a first subtype, and the base type is distinct,
3106 -- then also set the suppress flags on the base type.
3108 if Is_First_Subtype (E)
3109 and then Etype (E) /= E
3111 Suppress_Unsuppress_Echeck (Etype (E), C);
3113 end Suppress_Unsuppress_Echeck;
3115 -- Start of processing for Process_Suppress_Unsuppress
3118 -- Suppress/Unsuppress can appear as a configuration pragma,
3119 -- or in a declarative part or a package spec (RM 11.5(5))
3121 if not Is_Configuration_Pragma then
3122 Check_Is_In_Decl_Part_Or_Package_Spec;
3125 Check_At_Least_N_Arguments (1);
3126 Check_At_Most_N_Arguments (2);
3127 Check_No_Identifier (Arg1);
3128 Check_Arg_Is_Identifier (Arg1);
3130 if not Is_Check_Name (Chars (Expression (Arg1))) then
3132 ("argument of pragma% is not valid check name", Arg1);
3135 C := Get_Check_Id (Chars (Expression (Arg1)));
3138 if Arg_Count = 1 then
3140 when Access_Check =>
3141 Scope_Suppress.Access_Checks := Suppress_Case;
3143 when Accessibility_Check =>
3144 Scope_Suppress.Accessibility_Checks := Suppress_Case;
3146 when Discriminant_Check =>
3147 Scope_Suppress.Discriminant_Checks := Suppress_Case;
3149 when Division_Check =>
3150 Scope_Suppress.Division_Checks := Suppress_Case;
3152 when Elaboration_Check =>
3153 Scope_Suppress.Elaboration_Checks := Suppress_Case;
3156 Scope_Suppress.Index_Checks := Suppress_Case;
3158 when Length_Check =>
3159 Scope_Suppress.Length_Checks := Suppress_Case;
3161 when Overflow_Check =>
3162 Scope_Suppress.Overflow_Checks := Suppress_Case;
3165 Scope_Suppress.Range_Checks := Suppress_Case;
3167 when Storage_Check =>
3168 Scope_Suppress.Storage_Checks := Suppress_Case;
3171 Scope_Suppress.Tag_Checks := Suppress_Case;
3174 Scope_Suppress := (others => Suppress_Case);
3178 -- Case of two arguments present, where the check is
3179 -- suppressed for a specified entity (given as the second
3180 -- argument of the pragma)
3183 Check_Optional_Identifier (Arg2, Name_On);
3184 E_Id := Expression (Arg2);
3187 if not Is_Entity_Name (E_Id) then
3189 ("second argument of pragma% must be entity name", Arg2);
3198 Suppress_Unsuppress_Echeck (E, C);
3200 if Is_Generic_Instance (E)
3201 and then Is_Subprogram (E)
3202 and then Present (Alias (E))
3204 Suppress_Unsuppress_Echeck (Alias (E), C);
3207 if C = Elaboration_Check and then Suppress_Case then
3208 Set_Suppress_Elaboration_Warnings (E);
3211 -- If we are within a package specification, the
3212 -- pragma only applies to homonyms in the same scope.
3214 exit when No (Homonym (E))
3215 or else (Scope (Homonym (E)) /= Current_Scope
3216 and then Ekind (Current_Scope) = E_Package
3217 and then not In_Package_Body (Current_Scope));
3224 end Process_Suppress_Unsuppress;
3230 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3232 if Is_Imported (E) then
3234 ("cannot export entity& that was previously imported", Arg);
3236 elsif Present (Address_Clause (E)) then
3238 ("cannot export entity& that has an address clause", Arg);
3241 Set_Is_Exported (E);
3243 -- Deal with exporting non-library level entity
3245 if not Is_Library_Level_Entity (E) then
3247 -- Not allowed at all for subprograms
3249 if Is_Subprogram (E) then
3250 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3252 -- Otherwise set public and statically allocated
3256 Set_Is_Statically_Allocated (E);
3260 if Inside_A_Generic then
3262 ("all instances of& will have the same external name?", Arg, E);
3267 ----------------------------------------------
3268 -- Set_Extended_Import_Export_External_Name --
3269 ----------------------------------------------
3271 procedure Set_Extended_Import_Export_External_Name
3272 (Internal_Ent : Entity_Id;
3273 Arg_External : Node_Id)
3275 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3279 if No (Arg_External) then
3282 elsif Nkind (Arg_External) = N_String_Literal then
3283 if String_Length (Strval (Arg_External)) = 0 then
3286 New_Name := Adjust_External_Name_Case (Arg_External);
3289 elsif Nkind (Arg_External) = N_Identifier then
3290 New_Name := Get_Default_External_Name (Arg_External);
3294 ("incorrect form for External parameter for pragma%",
3298 -- If we already have an external name set (by a prior normal
3299 -- Import or Export pragma), then the external names must match
3301 if Present (Interface_Name (Internal_Ent)) then
3303 S1 : constant String_Id := Strval (Old_Name);
3304 S2 : constant String_Id := Strval (New_Name);
3307 -- Called if names do not match
3309 procedure Mismatch is
3311 Error_Msg_Sloc := Sloc (Old_Name);
3313 ("external name does not match that given #",
3318 if String_Length (S1) /= String_Length (S2) then
3322 for J in 1 .. String_Length (S1) loop
3323 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3330 -- Otherwise set the given name
3333 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3336 end Set_Extended_Import_Export_External_Name;
3342 procedure Set_Imported (E : Entity_Id) is
3344 Error_Msg_Sloc := Sloc (E);
3346 if Is_Exported (E) or else Is_Imported (E) then
3347 Error_Msg_NE ("import of& declared# not allowed", N, E);
3349 if Is_Exported (E) then
3350 Error_Msg_N ("\entity was previously exported", N);
3352 Error_Msg_N ("\entity was previously imported", N);
3355 Error_Pragma ("\(pragma% applies to all previous entities)");
3358 Set_Is_Imported (E);
3360 -- If the entity is an object that is not at the library
3361 -- level, then it is statically allocated. We do not worry
3362 -- about objects with address clauses in this context since
3363 -- they are not really imported in the linker sense.
3366 and then not Is_Library_Level_Entity (E)
3367 and then No (Address_Clause (E))
3369 Set_Is_Statically_Allocated (E);
3374 -------------------------
3375 -- Set_Mechanism_Value --
3376 -------------------------
3378 -- Note: the mechanism name has not been analyzed (and cannot indeed
3379 -- be analyzed, since it is semantic nonsense), so we get it in the
3380 -- exact form created by the parser.
3382 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3386 procedure Bad_Class;
3387 -- Signal bad descriptor class name
3389 procedure Bad_Mechanism;
3390 -- Signal bad mechanism name
3392 procedure Bad_Class is
3394 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3397 procedure Bad_Mechanism is
3399 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3402 -- Start of processing for Set_Mechanism_Value
3405 if Mechanism (Ent) /= Default_Mechanism then
3407 ("mechanism for & has already been set", Mech_Name, Ent);
3410 -- MECHANISM_NAME ::= value | reference | descriptor
3412 if Nkind (Mech_Name) = N_Identifier then
3413 if Chars (Mech_Name) = Name_Value then
3414 Set_Mechanism (Ent, By_Copy);
3417 elsif Chars (Mech_Name) = Name_Reference then
3418 Set_Mechanism (Ent, By_Reference);
3421 elsif Chars (Mech_Name) = Name_Descriptor then
3422 Check_VMS (Mech_Name);
3423 Set_Mechanism (Ent, By_Descriptor);
3426 elsif Chars (Mech_Name) = Name_Copy then
3428 ("bad mechanism name, Value assumed", Mech_Name);
3434 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3435 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3437 -- Note: this form is parsed as an indexed component
3439 elsif Nkind (Mech_Name) = N_Indexed_Component then
3440 Class := First (Expressions (Mech_Name));
3442 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3443 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3444 or else Present (Next (Class))
3449 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3450 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3452 -- Note: this form is parsed as a function call
3454 elsif Nkind (Mech_Name) = N_Function_Call then
3456 Param := First (Parameter_Associations (Mech_Name));
3458 if Nkind (Name (Mech_Name)) /= N_Identifier
3459 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3460 or else Present (Next (Param))
3461 or else No (Selector_Name (Param))
3462 or else Chars (Selector_Name (Param)) /= Name_Class
3466 Class := Explicit_Actual_Parameter (Param);
3473 -- Fall through here with Class set to descriptor class name
3475 Check_VMS (Mech_Name);
3477 if Nkind (Class) /= N_Identifier then
3480 elsif Chars (Class) = Name_UBS then
3481 Set_Mechanism (Ent, By_Descriptor_UBS);
3483 elsif Chars (Class) = Name_UBSB then
3484 Set_Mechanism (Ent, By_Descriptor_UBSB);
3486 elsif Chars (Class) = Name_UBA then
3487 Set_Mechanism (Ent, By_Descriptor_UBA);
3489 elsif Chars (Class) = Name_S then
3490 Set_Mechanism (Ent, By_Descriptor_S);
3492 elsif Chars (Class) = Name_SB then
3493 Set_Mechanism (Ent, By_Descriptor_SB);
3495 elsif Chars (Class) = Name_A then
3496 Set_Mechanism (Ent, By_Descriptor_A);
3498 elsif Chars (Class) = Name_NCA then
3499 Set_Mechanism (Ent, By_Descriptor_NCA);
3505 end Set_Mechanism_Value;
3507 -- Start of processing for Analyze_Pragma
3510 if not Is_Pragma_Name (Chars (N)) then
3511 Error_Pragma ("unrecognized pragma%!?");
3513 Prag_Id := Get_Pragma_Id (Chars (N));
3523 if Present (Pragma_Argument_Associations (N)) then
3524 Arg1 := First (Pragma_Argument_Associations (N));
3526 if Present (Arg1) then
3527 Arg2 := Next (Arg1);
3529 if Present (Arg2) then
3530 Arg3 := Next (Arg2);
3532 if Present (Arg3) then
3533 Arg4 := Next (Arg3);
3539 -- Count number of arguments
3548 while Present (Arg_Node) loop
3549 Arg_Count := Arg_Count + 1;
3554 -- An enumeration type defines the pragmas that are supported by the
3555 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
3556 -- into the corresponding enumeration value for the following case.
3564 -- pragma Abort_Defer;
3566 when Pragma_Abort_Defer =>
3568 Check_Arg_Count (0);
3570 -- The only required semantic processing is to check the
3571 -- placement. This pragma must appear at the start of the
3572 -- statement sequence of a handled sequence of statements.
3574 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
3575 or else N /= First (Statements (Parent (N)))
3586 -- Note: this pragma also has some specific processing in Par.Prag
3587 -- because we want to set the Ada 83 mode switch during parsing.
3589 when Pragma_Ada_83 =>
3593 Check_Arg_Count (0);
3601 -- Note: this pragma also has some specific processing in Par.Prag
3602 -- because we want to set the Ada 83 mode switch during parsing.
3604 when Pragma_Ada_95 =>
3608 Check_Arg_Count (0);
3610 ----------------------
3611 -- All_Calls_Remote --
3612 ----------------------
3614 -- pragma All_Calls_Remote [(library_package_NAME)];
3616 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
3617 Lib_Entity : Entity_Id;
3620 Check_Ada_83_Warning;
3621 Check_Valid_Library_Unit_Pragma;
3623 if Nkind (N) = N_Null_Statement then
3627 Lib_Entity := Find_Lib_Unit_Name;
3629 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
3631 if Present (Lib_Entity)
3632 and then not Debug_Flag_U
3634 if not Is_Remote_Call_Interface (Lib_Entity) then
3635 Error_Pragma ("pragma% only apply to rci unit");
3637 -- Set flag for entity of the library unit
3640 Set_Has_All_Calls_Remote (Lib_Entity);
3644 end All_Calls_Remote;
3650 -- pragma Annotate (IDENTIFIER {, ARG});
3651 -- ARG ::= NAME | EXPRESSION
3653 when Pragma_Annotate => Annotate : begin
3655 Check_At_Least_N_Arguments (1);
3656 Check_Arg_Is_Identifier (Arg1);
3659 Arg : Node_Id := Arg2;
3663 while Present (Arg) loop
3664 Exp := Expression (Arg);
3667 if Is_Entity_Name (Exp) then
3670 elsif Nkind (Exp) = N_String_Literal then
3671 Resolve (Exp, Standard_String);
3673 elsif Is_Overloaded (Exp) then
3674 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
3677 Resolve (Exp, Etype (Exp));
3689 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
3691 when Pragma_Assert =>
3693 Check_No_Identifiers;
3695 if Arg_Count > 1 then
3696 Check_Arg_Count (2);
3697 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3700 -- If expansion is active and assertions are inactive, then
3701 -- we rewrite the Assertion as:
3703 -- if False and then condition then
3707 -- The reason we do this rewriting during semantic analysis
3708 -- rather than as part of normal expansion is that we cannot
3709 -- analyze and expand the code for the boolean expression
3710 -- directly, or it may cause insertion of actions that would
3711 -- escape the attempt to suppress the assertion code.
3713 if Expander_Active and not Assertions_Enabled then
3715 Make_If_Statement (Loc,
3718 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
3719 Right_Opnd => Get_Pragma_Arg (Arg1)),
3720 Then_Statements => New_List (
3721 Make_Null_Statement (Loc))));
3725 -- Otherwise (if assertions are enabled, or if we are not
3726 -- operating with expansion active), then we just analyze
3727 -- and resolve the expression.
3730 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
3737 -- pragma AST_Entry (entry_IDENTIFIER);
3739 when Pragma_AST_Entry => AST_Entry : declare
3745 Check_Arg_Count (1);
3746 Check_No_Identifiers;
3747 Check_Arg_Is_Local_Name (Arg1);
3748 Ent := Entity (Expression (Arg1));
3750 -- Note: the implementation of the AST_Entry pragma could handle
3751 -- the entry family case fine, but for now we are consistent with
3752 -- the DEC rules, and do not allow the pragma, which of course
3753 -- has the effect of also forbidding the attribute.
3755 if Ekind (Ent) /= E_Entry then
3757 ("pragma% argument must be simple entry name", Arg1);
3759 elsif Is_AST_Entry (Ent) then
3761 ("duplicate % pragma for entry", Arg1);
3763 elsif Has_Homonym (Ent) then
3765 ("pragma% argument cannot specify overloaded entry", Arg1);
3769 FF : constant Entity_Id := First_Formal (Ent);
3772 if Present (FF) then
3773 if Present (Next_Formal (FF)) then
3775 ("entry for pragma% can have only one argument",
3778 elsif Parameter_Mode (FF) /= E_In_Parameter then
3780 ("entry parameter for pragma% must have mode IN",
3786 Set_Is_AST_Entry (Ent);
3794 -- pragma Asynchronous (LOCAL_NAME);
3796 when Pragma_Asynchronous => Asynchronous : declare
3804 procedure Process_Async_Pragma;
3805 -- Common processing for procedure and access-to-procedure case
3807 --------------------------
3808 -- Process_Async_Pragma --
3809 --------------------------
3811 procedure Process_Async_Pragma is
3813 if not Present (L) then
3814 Set_Is_Asynchronous (Nm);
3818 -- The formals should be of mode IN (RM E.4.1(6))
3821 while Present (S) loop
3822 Formal := Defining_Identifier (S);
3824 if Nkind (Formal) = N_Defining_Identifier
3825 and then Ekind (Formal) /= E_In_Parameter
3828 ("pragma% procedure can only have IN parameter",
3835 Set_Is_Asynchronous (Nm);
3836 end Process_Async_Pragma;
3838 -- Start of processing for pragma Asynchronous
3841 Check_Ada_83_Warning;
3842 Check_No_Identifiers;
3843 Check_Arg_Count (1);
3844 Check_Arg_Is_Local_Name (Arg1);
3846 if Debug_Flag_U then
3850 C_Ent := Cunit_Entity (Current_Sem_Unit);
3851 Analyze (Expression (Arg1));
3852 Nm := Entity (Expression (Arg1));
3854 if not Is_Remote_Call_Interface (C_Ent)
3855 and then not Is_Remote_Types (C_Ent)
3857 -- This pragma should only appear in an RCI or Remote Types
3858 -- unit (RM E.4.1(4))
3861 ("pragma% not in Remote_Call_Interface or " &
3862 "Remote_Types unit");
3865 if Ekind (Nm) = E_Procedure
3866 and then Nkind (Parent (Nm)) = N_Procedure_Specification
3868 if not Is_Remote_Call_Interface (Nm) then
3870 ("pragma% cannot be applied on non-remote procedure",
3874 L := Parameter_Specifications (Parent (Nm));
3875 Process_Async_Pragma;
3878 elsif Ekind (Nm) = E_Function then
3880 ("pragma% cannot be applied to function", Arg1);
3882 elsif Ekind (Nm) = E_Record_Type
3883 and then Present (Corresponding_Remote_Type (Nm))
3885 N := Declaration_Node (Corresponding_Remote_Type (Nm));
3887 if Nkind (N) = N_Full_Type_Declaration
3888 and then Nkind (Type_Definition (N)) =
3889 N_Access_Procedure_Definition
3891 L := Parameter_Specifications (Type_Definition (N));
3892 Process_Async_Pragma;
3896 ("pragma% cannot reference access-to-function type",
3900 -- Only other possibility is Access-to-class-wide type
3902 elsif Is_Access_Type (Nm)
3903 and then Is_Class_Wide_Type (Designated_Type (Nm))
3905 Check_First_Subtype (Arg1);
3906 Set_Is_Asynchronous (Nm);
3907 if Expander_Active then
3908 RACW_Type_Is_Asynchronous (Nm);
3912 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
3921 -- pragma Atomic (LOCAL_NAME);
3923 when Pragma_Atomic =>
3924 Process_Atomic_Shared_Volatile;
3926 -----------------------
3927 -- Atomic_Components --
3928 -----------------------
3930 -- pragma Atomic_Components (array_LOCAL_NAME);
3932 -- This processing is shared by Volatile_Components
3934 when Pragma_Atomic_Components |
3935 Pragma_Volatile_Components =>
3937 Atomic_Components : declare
3945 Check_Ada_83_Warning;
3946 Check_No_Identifiers;
3947 Check_Arg_Count (1);
3948 Check_Arg_Is_Local_Name (Arg1);
3949 E_Id := Expression (Arg1);
3951 if Etype (E_Id) = Any_Type then
3957 if Rep_Item_Too_Early (E, N)
3959 Rep_Item_Too_Late (E, N)
3964 D := Declaration_Node (E);
3967 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
3969 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
3970 and then Nkind (D) = N_Object_Declaration
3971 and then Nkind (Object_Definition (D)) =
3972 N_Constrained_Array_Definition)
3974 -- The flag is set on the object, or on the base type
3976 if Nkind (D) /= N_Object_Declaration then
3980 Set_Has_Volatile_Components (E);
3982 if Prag_Id = Pragma_Atomic_Components then
3983 Set_Has_Atomic_Components (E);
3985 if Is_Packed (E) then
3986 Set_Is_Packed (E, False);
3989 ("?Pack canceled, cannot pack atomic components",
3995 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
3997 end Atomic_Components;
3999 --------------------
4000 -- Attach_Handler --
4001 --------------------
4003 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4005 when Pragma_Attach_Handler =>
4006 Check_Ada_83_Warning;
4007 Check_No_Identifiers;
4008 Check_Arg_Count (2);
4009 Check_Interrupt_Or_Attach_Handler;
4010 Analyze_And_Resolve (Expression (Arg2), RTE (RE_Interrupt_Id));
4011 Process_Interrupt_Or_Attach_Handler;
4013 --------------------
4014 -- C_Pass_By_Copy --
4015 --------------------
4017 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4019 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4025 Check_Valid_Configuration_Pragma;
4026 Check_Arg_Count (1);
4027 Check_Optional_Identifier (Arg1, "max_size");
4029 Arg := Expression (Arg1);
4030 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4032 Val := Expr_Value (Arg);
4036 ("maximum size for pragma% must be positive", Arg1);
4038 elsif UI_Is_In_Int_Range (Val) then
4039 Default_C_Record_Mechanism := UI_To_Int (Val);
4041 -- If a giant value is given, Int'Last will do well enough.
4042 -- If sometime someone complains that a record larger than
4043 -- two gigabytes is not copied, we will worry about it then!
4046 Default_C_Record_Mechanism := Mechanism_Type'Last;
4054 -- pragma Comment (static_string_EXPRESSION)
4056 -- Processing for pragma Comment shares the circuitry for
4057 -- pragma Ident. The only differences are that Ident enforces
4058 -- a limit of 31 characters on its argument, and also enforces
4059 -- limitations on placement for DEC compatibility. Pragma
4060 -- Comment shares neither of these restrictions.
4066 -- pragma Common_Object (
4067 -- [Internal =>] LOCAL_NAME,
4068 -- [, [External =>] EXTERNAL_SYMBOL]
4069 -- [, [Size =>] EXTERNAL_SYMBOL]);
4071 -- Processing for this pragma is shared with Psect_Object
4073 ----------------------------
4074 -- Complex_Representation --
4075 ----------------------------
4077 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4079 when Pragma_Complex_Representation => Complex_Representation : declare
4086 Check_Arg_Count (1);
4087 Check_Optional_Identifier (Arg1, Name_Entity);
4088 Check_Arg_Is_Local_Name (Arg1);
4089 E_Id := Expression (Arg1);
4091 if Etype (E_Id) = Any_Type then
4097 if not Is_Record_Type (E) then
4099 ("argument for pragma% must be record type", Arg1);
4102 Ent := First_Entity (E);
4105 or else No (Next_Entity (Ent))
4106 or else Present (Next_Entity (Next_Entity (Ent)))
4107 or else not Is_Floating_Point_Type (Etype (Ent))
4108 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4111 ("record for pragma% must have two fields of same fpt type",
4115 Set_Has_Complex_Representation (Base_Type (E));
4117 end Complex_Representation;
4119 -------------------------
4120 -- Component_Alignment --
4121 -------------------------
4123 -- pragma Component_Alignment (
4124 -- [Form =>] ALIGNMENT_CHOICE
4125 -- [, [Name =>] type_LOCAL_NAME]);
4127 -- ALIGNMENT_CHOICE ::=
4129 -- | Component_Size_4
4133 when Pragma_Component_Alignment => Component_AlignmentP : declare
4134 Args : Args_List (1 .. 2);
4135 Names : Name_List (1 .. 2) := (
4139 Form : Node_Id renames Args (1);
4140 Name : Node_Id renames Args (2);
4142 Atype : Component_Alignment_Kind;
4147 Gather_Associations (Names, Args);
4150 Error_Pragma ("missing Form argument for pragma%");
4153 Check_Arg_Is_Identifier (Form);
4155 -- Get proper alignment, note that Default = Component_Size
4156 -- on all machines we have so far, and we want to set this
4157 -- value rather than the default value to indicate that it
4158 -- has been explicitly set (and thus will not get overridden
4159 -- by the default component alignment for the current scope)
4161 if Chars (Form) = Name_Component_Size then
4162 Atype := Calign_Component_Size;
4164 elsif Chars (Form) = Name_Component_Size_4 then
4165 Atype := Calign_Component_Size_4;
4167 elsif Chars (Form) = Name_Default then
4168 Atype := Calign_Component_Size;
4170 elsif Chars (Form) = Name_Storage_Unit then
4171 Atype := Calign_Storage_Unit;
4175 ("invalid Form parameter for pragma%", Form);
4178 -- Case with no name, supplied, affects scope table entry
4182 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4184 -- Case of name supplied
4187 Check_Arg_Is_Local_Name (Name);
4189 Typ := Entity (Name);
4192 or else Rep_Item_Too_Early (Typ, N)
4196 Typ := Underlying_Type (Typ);
4199 if not Is_Record_Type (Typ)
4200 and then not Is_Array_Type (Typ)
4203 ("Name parameter of pragma% must identify record or " &
4204 "array type", Name);
4207 -- An explicit Component_Alignment pragma overrides an
4208 -- implicit pragma Pack, but not an explicit one.
4210 if not Has_Pragma_Pack (Base_Type (Typ)) then
4211 Set_Is_Packed (Base_Type (Typ), False);
4212 Set_Component_Alignment (Base_Type (Typ), Atype);
4216 end Component_AlignmentP;
4222 -- pragma Controlled (first_subtype_LOCAL_NAME);
4224 when Pragma_Controlled => Controlled : declare
4228 Check_No_Identifiers;
4229 Check_Arg_Count (1);
4230 Check_Arg_Is_Local_Name (Arg1);
4231 Arg := Expression (Arg1);
4233 if not Is_Entity_Name (Arg)
4234 or else not Is_Access_Type (Entity (Arg))
4236 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4238 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4246 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4247 -- [Entity =>] LOCAL_NAME);
4249 when Pragma_Convention => Convention : declare
4254 Check_Ada_83_Warning;
4255 Check_Arg_Count (2);
4256 Process_Convention (C, E);
4263 -- pragma CPP_Class ([Entity =>] local_NAME)
4265 when Pragma_CPP_Class => CPP_Class : declare
4268 Default_DTC : Entity_Id := Empty;
4269 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4275 Check_Arg_Count (1);
4276 Check_Optional_Identifier (Arg1, Name_Entity);
4277 Check_Arg_Is_Local_Name (Arg1);
4279 Arg := Expression (Arg1);
4282 if Etype (Arg) = Any_Type then
4286 if not Is_Entity_Name (Arg)
4287 or else not Is_Type (Entity (Arg))
4289 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
4292 Typ := Entity (Arg);
4294 if not Is_Record_Type (Typ) then
4295 Error_Pragma_Arg ("pragma% applicable to a record, "
4296 & "tagged record or record extension", Arg1);
4299 Default_DTC := First_Component (Typ);
4300 while Present (Default_DTC)
4301 and then Etype (Default_DTC) /= VTP_Type
4303 Next_Component (Default_DTC);
4306 -- Case of non tagged type
4308 if not Is_Tagged_Type (Typ) then
4309 Set_Is_CPP_Class (Typ);
4311 if Present (Default_DTC) then
4313 ("only tagged records can contain vtable pointers", Arg1);
4316 -- Case of tagged type with no vtable ptr
4318 -- What is test for Typ = Root_Typ (Typ) about here ???
4320 elsif Is_Tagged_Type (Typ)
4321 and then Typ = Root_Type (Typ)
4322 and then No (Default_DTC)
4325 ("a cpp_class must contain a vtable pointer", Arg1);
4327 -- Tagged type that has a vtable ptr
4329 elsif Present (Default_DTC) then
4330 Set_Is_CPP_Class (Typ);
4331 Set_Is_Limited_Record (Typ);
4332 Set_Is_Tag (Default_DTC);
4333 Set_DT_Entry_Count (Default_DTC, No_Uint);
4335 -- Since a CPP type has no direct link to its associated tag
4336 -- most tags checks cannot be performed
4338 Set_Suppress_Tag_Checks (Typ);
4339 Set_Suppress_Tag_Checks (Class_Wide_Type (Typ));
4341 -- Get rid of the _tag component when there was one.
4342 -- It is only useful for regular tagged types
4344 if Expander_Active and then Typ = Root_Type (Typ) then
4346 Tag_C := Tag_Component (Typ);
4347 C := First_Entity (Typ);
4350 Set_First_Entity (Typ, Next_Entity (Tag_C));
4353 while Next_Entity (C) /= Tag_C loop
4357 Set_Next_Entity (C, Next_Entity (Tag_C));
4363 ---------------------
4364 -- CPP_Constructor --
4365 ---------------------
4367 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
4369 when Pragma_CPP_Constructor => CPP_Constructor : declare
4375 Check_Arg_Count (1);
4376 Check_Optional_Identifier (Arg1, Name_Entity);
4377 Check_Arg_Is_Local_Name (Arg1);
4379 Id := Expression (Arg1);
4380 Find_Program_Unit_Name (Id);
4382 -- If we did not find the name, we are done
4384 if Etype (Id) = Any_Type then
4388 Def_Id := Entity (Id);
4390 if Ekind (Def_Id) = E_Function
4391 and then Is_Class_Wide_Type (Etype (Def_Id))
4392 and then Is_CPP_Class (Etype (Etype (Def_Id)))
4394 -- What the heck is this??? this pragma allows only 1 arg
4396 if Arg_Count >= 2 then
4397 Check_At_Most_N_Arguments (3);
4398 Process_Interface_Name (Def_Id, Arg2, Arg3);
4401 if No (Parameter_Specifications (Parent (Def_Id))) then
4402 Set_Has_Completion (Def_Id);
4403 Set_Is_Constructor (Def_Id);
4406 ("non-default constructors not implemented", Arg1);
4411 ("pragma% requires function returning a 'C'P'P_Class type",
4414 end CPP_Constructor;
4420 -- pragma CPP_Virtual
4421 -- [Entity =>] LOCAL_NAME
4422 -- [ [Vtable_Ptr =>] LOCAL_NAME,
4423 -- [Position =>] static_integer_EXPRESSION]);
4425 when Pragma_CPP_Virtual => CPP_Virtual : declare
4429 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4436 if Arg_Count = 3 then
4437 Check_Optional_Identifier (Arg2, "vtable_ptr");
4439 -- We allow Entry_Count as well as Position for the third
4440 -- parameter for back compatibility with versions of GNAT
4441 -- before version 3.12. The documentation has always said
4442 -- Position, but the code up to 3.12 said Entry_Count.
4444 if Chars (Arg3) /= Name_Position then
4445 Check_Optional_Identifier (Arg3, "entry_count");
4449 Check_Arg_Count (1);
4452 Check_Optional_Identifier (Arg1, Name_Entity);
4453 Check_Arg_Is_Local_Name (Arg1);
4455 -- First argument must be a subprogram name
4457 Arg := Expression (Arg1);
4458 Find_Program_Unit_Name (Arg);
4460 if Etype (Arg) = Any_Type then
4463 Subp := Entity (Arg);
4466 if not (Is_Subprogram (Subp)
4467 and then Is_Dispatching_Operation (Subp))
4470 ("pragma% must reference a primitive operation", Arg1);
4473 Typ := Find_Dispatching_Type (Subp);
4475 -- If only one Argument defaults are :
4476 -- . DTC_Entity is the default Vtable pointer
4477 -- . DT_Position will be set at the freezing point
4479 if Arg_Count = 1 then
4480 Set_DTC_Entity (Subp, Tag_Component (Typ));
4484 -- Second argument is a component name of type Vtable_Ptr
4486 Arg := Expression (Arg2);
4488 if Nkind (Arg) /= N_Identifier then
4489 Error_Msg_NE ("must be a& component name", Arg, Typ);
4493 DTC := First_Component (Typ);
4494 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4495 Next_Component (DTC);
4499 Error_Msg_NE ("must be a& component name", Arg, Typ);
4502 elsif Etype (DTC) /= VTP_Type then
4503 Wrong_Type (Arg, VTP_Type);
4507 -- Third argument is an integer (DT_Position)
4509 Arg := Expression (Arg3);
4510 Analyze_And_Resolve (Arg, Any_Integer);
4512 if not Is_Static_Expression (Arg) then
4514 ("third argument of pragma% must be a static expression",
4518 V := Expr_Value (Expression (Arg3));
4522 ("third argument of pragma% must be positive",
4526 Set_DTC_Entity (Subp, DTC);
4527 Set_DT_Position (Subp, V);
4536 -- pragma CPP_Vtable (
4537 -- [Entity =>] LOCAL_NAME
4538 -- [Vtable_Ptr =>] LOCAL_NAME,
4539 -- [Entry_Count =>] static_integer_EXPRESSION);
4541 when Pragma_CPP_Vtable => CPP_Vtable : declare
4544 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4551 Check_Arg_Count (3);
4552 Check_Optional_Identifier (Arg1, Name_Entity);
4553 Check_Optional_Identifier (Arg2, "vtable_ptr");
4554 Check_Optional_Identifier (Arg3, "entry_count");
4555 Check_Arg_Is_Local_Name (Arg1);
4557 -- First argument is a record type name
4559 Arg := Expression (Arg1);
4562 if Etype (Arg) = Any_Type then
4565 Typ := Entity (Arg);
4568 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
4569 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
4572 -- Second argument is a component name of type Vtable_Ptr
4574 Arg := Expression (Arg2);
4576 if Nkind (Arg) /= N_Identifier then
4577 Error_Msg_NE ("must be a& component name", Arg, Typ);
4581 DTC := First_Component (Typ);
4582 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4583 Next_Component (DTC);
4587 Error_Msg_NE ("must be a& component name", Arg, Typ);
4590 elsif Etype (DTC) /= VTP_Type then
4591 Wrong_Type (DTC, VTP_Type);
4594 -- If it is the first pragma Vtable, This becomes the default tag
4596 elsif (not Is_Tag (DTC))
4597 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
4599 Set_Is_Tag (Tag_Component (Typ), False);
4600 Set_Is_Tag (DTC, True);
4601 Set_DT_Entry_Count (DTC, No_Uint);
4604 -- Those pragmas must appear before any primitive operation
4605 -- definition (except inherited ones) otherwise the default
4608 Elmt := First_Elmt (Primitive_Operations (Typ));
4609 while Present (Elmt) loop
4610 if No (Alias (Node (Elmt))) then
4611 Error_Msg_Sloc := Sloc (Node (Elmt));
4613 ("pragma% must appear before this primitive operation");
4619 -- Third argument is an integer (DT_Entry_Count)
4621 Arg := Expression (Arg3);
4622 Analyze_And_Resolve (Arg, Any_Integer);
4624 if not Is_Static_Expression (Arg) then
4626 ("entry count for pragma% must be a static expression", Arg3);
4629 V := Expr_Value (Expression (Arg3));
4633 ("entry count for pragma% must be positive", Arg3);
4635 Set_DT_Entry_Count (DTC, V);
4645 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
4647 when Pragma_Debug => Debug : begin
4650 -- If assertions are enabled, and we are expanding code, then
4651 -- we rewrite the pragma with its corresponding procedure call
4652 -- and then analyze the call.
4654 if Assertions_Enabled and Expander_Active then
4655 Rewrite (N, Relocate_Node (Debug_Statement (N)));
4658 -- Otherwise we work a bit to get a tree that makes sense
4659 -- for ASIS purposes, namely a pragma with an analyzed
4660 -- argument that looks like a procedure call.
4663 Expander_Mode_Save_And_Set (False);
4664 Rewrite (N, Relocate_Node (Debug_Statement (N)));
4668 Chars => Name_Debug,
4669 Pragma_Argument_Associations =>
4670 New_List (Relocate_Node (N))));
4671 Expander_Mode_Restore;
4679 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
4681 when Pragma_Discard_Names => Discard_Names : declare
4687 Check_Ada_83_Warning;
4689 -- Deal with configuration pragma case
4691 if Arg_Count = 0 and then Is_Configuration_Pragma then
4692 Global_Discard_Names := True;
4695 -- Otherwise, check correct appropriate context
4698 Check_Is_In_Decl_Part_Or_Package_Spec;
4700 if Arg_Count = 0 then
4702 -- If there is no parameter, then from now on this pragma
4703 -- applies to any enumeration, exception or tagged type
4704 -- defined in the current declarative part.
4706 Set_Discard_Names (Current_Scope);
4710 Check_Arg_Count (1);
4711 Check_Optional_Identifier (Arg1, Name_On);
4712 Check_Arg_Is_Local_Name (Arg1);
4713 E_Id := Expression (Arg1);
4715 if Etype (E_Id) = Any_Type then
4721 if (Is_First_Subtype (E)
4722 and then (Is_Enumeration_Type (E)
4723 or else Is_Tagged_Type (E)))
4724 or else Ekind (E) = E_Exception
4726 Set_Discard_Names (E);
4729 ("inappropriate entity for pragma%", Arg1);
4739 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
4741 when Pragma_Elaborate => Elaborate : declare
4743 Parent_Node : Node_Id;
4748 -- Pragma must be in context items list of a compilation unit
4750 if not Is_List_Member (N) then
4755 Plist := List_Containing (N);
4756 Parent_Node := Parent (Plist);
4758 if Parent_Node = Empty
4759 or else Nkind (Parent_Node) /= N_Compilation_Unit
4760 or else Context_Items (Parent_Node) /= Plist
4767 -- Must be at least one argument
4769 if Arg_Count = 0 then
4770 Error_Pragma ("pragma% requires at least one argument");
4773 -- In Ada 83 mode, there can be no items following it in the
4774 -- context list except other pragmas and implicit with clauses
4775 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
4776 -- placement rule does not apply.
4778 if Ada_83 and then Comes_From_Source (N) then
4781 while Present (Citem) loop
4782 if Nkind (Citem) = N_Pragma
4783 or else (Nkind (Citem) = N_With_Clause
4784 and then Implicit_With (Citem))
4789 ("(Ada 83) pragma% must be at end of context clause");
4796 -- Finally, the arguments must all be units mentioned in a with
4797 -- clause in the same context clause. Note we already checked
4798 -- (in Par.Prag) that the arguments are either identifiers or
4801 Outer : while Present (Arg) loop
4802 Citem := First (Plist);
4804 Inner : while Citem /= N loop
4805 if Nkind (Citem) = N_With_Clause
4806 and then Same_Name (Name (Citem), Expression (Arg))
4808 Set_Elaborate_Present (Citem, True);
4809 Set_Unit_Name (Expression (Arg), Name (Citem));
4810 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
4819 ("argument of pragma% is not with'ed unit", Arg);
4830 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
4832 when Pragma_Elaborate_All => Elaborate_All : declare
4834 Parent_Node : Node_Id;
4839 Check_Ada_83_Warning;
4841 -- Pragma must be in context items list of a compilation unit
4843 if not Is_List_Member (N) then
4848 Plist := List_Containing (N);
4849 Parent_Node := Parent (Plist);
4851 if Parent_Node = Empty
4852 or else Nkind (Parent_Node) /= N_Compilation_Unit
4853 or else Context_Items (Parent_Node) /= Plist
4860 -- Must be at least one argument
4862 if Arg_Count = 0 then
4863 Error_Pragma ("pragma% requires at least one argument");
4866 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
4867 -- have to appear at the end of the context clause, but may
4868 -- appear mixed in with other items, even in Ada 83 mode.
4870 -- Final check: the arguments must all be units mentioned in
4871 -- a with clause in the same context clause. Note that we
4872 -- already checked (in Par.Prag) that all the arguments are
4873 -- either identifiers or selected components.
4876 Outr : while Present (Arg) loop
4877 Citem := First (Plist);
4879 Innr : while Citem /= N loop
4880 if Nkind (Citem) = N_With_Clause
4881 and then Same_Name (Name (Citem), Expression (Arg))
4883 Set_Elaborate_All_Present (Citem, True);
4884 Set_Unit_Name (Expression (Arg), Name (Citem));
4885 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
4894 ("argument of pragma% is not with'ed unit", Arg);
4901 --------------------
4902 -- Elaborate_Body --
4903 --------------------
4905 -- pragma Elaborate_Body [( library_unit_NAME )];
4907 when Pragma_Elaborate_Body => Elaborate_Body : declare
4908 Cunit_Node : Node_Id;
4909 Cunit_Ent : Entity_Id;
4912 Check_Ada_83_Warning;
4913 Check_Valid_Library_Unit_Pragma;
4915 if Nkind (N) = N_Null_Statement then
4919 Cunit_Node := Cunit (Current_Sem_Unit);
4920 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
4922 if Nkind (Unit (Cunit_Node)) = N_Package_Body
4924 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
4926 Error_Pragma ("pragma% must refer to a spec, not a body");
4928 Set_Body_Required (Cunit_Node, True);
4929 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
4931 -- If we are in dynamic elaboration mode, then we suppress
4932 -- elaboration warnings for the unit, since it is definitely
4933 -- fine NOT to do dynamic checks at the first level (and such
4934 -- checks will be suppressed because no elaboration boolean
4935 -- is created for Elaborate_Body packages).
4937 -- But in the static model of elaboration, Elaborate_Body is
4938 -- definitely NOT good enough to ensure elaboration safety on
4939 -- its own, since the body may WITH other units that are not
4940 -- safe from an elaboration point of view, so a client must
4941 -- still do an Elaborate_All on such units.
4943 -- Debug flag -gnatdD restores the old behavior of 3.13,
4944 -- where Elaborate_Body always suppressed elab warnings.
4946 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
4947 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
4952 ------------------------
4953 -- Elaboration_Checks --
4954 ------------------------
4956 -- pragma Elaboration_Checks (Static | Dynamic);
4958 when Pragma_Elaboration_Checks =>
4960 Check_Arg_Count (1);
4961 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
4962 Dynamic_Elaboration_Checks :=
4963 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
4969 -- pragma Eliminate (
4970 -- [Unit_Name =>] IDENTIFIER |
4971 -- SELECTED_COMPONENT
4972 -- [,[Entity =>] IDENTIFIER |
4973 -- SELECTED_COMPONENT |
4975 -- [,[Parameter_Types =>] PARAMETER_TYPES]
4976 -- [,[Result_Type =>] result_SUBTYPE_MARK]);
4978 -- PARAMETER_TYPES ::=
4980 -- (SUBTYPE_MARK, SUBTYPE_MARK, ...)
4982 when Pragma_Eliminate => Eliminate : begin
4984 Check_Ada_83_Warning;
4985 Check_Valid_Configuration_Pragma;
4986 Check_At_Least_N_Arguments (1);
4987 Check_At_Most_N_Arguments (4);
4990 and then Chars (Arg3) = Name_Result_Type
4996 Check_Optional_Identifier (Arg1, "unit_name");
4997 Check_Optional_Identifier (Arg2, Name_Entity);
4998 Check_Optional_Identifier (Arg3, Name_Parameter_Types);
4999 Check_Optional_Identifier (Arg4, Name_Result_Type);
5002 Process_Eliminate_Pragma (Arg1, Arg2, Arg3, Arg4);
5010 -- [ Convention =>] convention_IDENTIFIER,
5011 -- [ Entity =>] local_NAME
5012 -- [, [External_Name =>] static_string_EXPRESSION ]
5013 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5015 when Pragma_Export => Export : declare
5020 Check_Ada_83_Warning;
5021 Check_At_Least_N_Arguments (2);
5022 Check_At_Most_N_Arguments (4);
5023 Process_Convention (C, Def_Id);
5024 Note_Possible_Modification (Expression (Arg2));
5025 Process_Interface_Name (Def_Id, Arg3, Arg4);
5026 Set_Exported (Def_Id, Arg2);
5029 ----------------------
5030 -- Export_Exception --
5031 ----------------------
5033 -- pragma Export_Exception (
5034 -- [Internal =>] LOCAL_NAME,
5035 -- [, [External =>] EXTERNAL_SYMBOL,]
5036 -- [, [Form =>] Ada | VMS]
5037 -- [, [Code =>] static_integer_EXPRESSION]);
5039 when Pragma_Export_Exception => Export_Exception : declare
5040 Args : Args_List (1 .. 4);
5041 Names : Name_List (1 .. 4) := (
5047 Internal : Node_Id renames Args (1);
5048 External : Node_Id renames Args (2);
5049 Form : Node_Id renames Args (3);
5050 Code : Node_Id renames Args (4);
5055 if Inside_A_Generic then
5056 Error_Pragma ("pragma% cannot be used for generic entities");
5059 Gather_Associations (Names, Args);
5060 Process_Extended_Import_Export_Exception_Pragma (
5061 Arg_Internal => Internal,
5062 Arg_External => External,
5066 if not Is_VMS_Exception (Entity (Internal)) then
5067 Set_Exported (Entity (Internal), Internal);
5070 end Export_Exception;
5072 ---------------------
5073 -- Export_Function --
5074 ---------------------
5076 -- pragma Export_Function (
5077 -- [Internal =>] LOCAL_NAME,
5078 -- [, [External =>] EXTERNAL_SYMBOL,]
5079 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5080 -- [, [Result_Type =>] SUBTYPE_MARK]
5081 -- [, [Mechanism =>] MECHANISM]
5082 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5084 when Pragma_Export_Function => Export_Function : declare
5085 Args : Args_List (1 .. 6);
5086 Names : Name_List (1 .. 6) := (
5089 Name_Parameter_Types,
5092 Name_Result_Mechanism);
5094 Internal : Node_Id renames Args (1);
5095 External : Node_Id renames Args (2);
5096 Parameter_Types : Node_Id renames Args (3);
5097 Result_Type : Node_Id renames Args (4);
5098 Mechanism : Node_Id renames Args (5);
5099 Result_Mechanism : Node_Id renames Args (6);
5103 Gather_Associations (Names, Args);
5104 Process_Extended_Import_Export_Subprogram_Pragma (
5105 Arg_Internal => Internal,
5106 Arg_External => External,
5107 Arg_Parameter_Types => Parameter_Types,
5108 Arg_Result_Type => Result_Type,
5109 Arg_Mechanism => Mechanism,
5110 Arg_Result_Mechanism => Result_Mechanism);
5111 end Export_Function;
5117 -- pragma Export_Object (
5118 -- [Internal =>] LOCAL_NAME,
5119 -- [, [External =>] EXTERNAL_SYMBOL]
5120 -- [, [Size =>] EXTERNAL_SYMBOL]);
5122 when Pragma_Export_Object => Export_Object : declare
5123 Args : Args_List (1 .. 3);
5124 Names : Name_List (1 .. 3) := (
5129 Internal : Node_Id renames Args (1);
5130 External : Node_Id renames Args (2);
5131 Size : Node_Id renames Args (3);
5135 Gather_Associations (Names, Args);
5136 Process_Extended_Import_Export_Object_Pragma (
5137 Arg_Internal => Internal,
5138 Arg_External => External,
5142 ----------------------
5143 -- Export_Procedure --
5144 ----------------------
5146 -- pragma Export_Procedure (
5147 -- [Internal =>] LOCAL_NAME,
5148 -- [, [External =>] EXTERNAL_SYMBOL,]
5149 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5150 -- [, [Mechanism =>] MECHANISM]);
5152 when Pragma_Export_Procedure => Export_Procedure : declare
5153 Args : Args_List (1 .. 4);
5154 Names : Name_List (1 .. 4) := (
5157 Name_Parameter_Types,
5160 Internal : Node_Id renames Args (1);
5161 External : Node_Id renames Args (2);
5162 Parameter_Types : Node_Id renames Args (3);
5163 Mechanism : Node_Id renames Args (4);
5167 Gather_Associations (Names, Args);
5168 Process_Extended_Import_Export_Subprogram_Pragma (
5169 Arg_Internal => Internal,
5170 Arg_External => External,
5171 Arg_Parameter_Types => Parameter_Types,
5172 Arg_Mechanism => Mechanism);
5173 end Export_Procedure;
5175 -----------------------------
5176 -- Export_Valued_Procedure --
5177 -----------------------------
5179 -- pragma Export_Valued_Procedure (
5180 -- [Internal =>] LOCAL_NAME,
5181 -- [, [External =>] EXTERNAL_SYMBOL,]
5182 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5183 -- [, [Mechanism =>] MECHANISM]);
5185 when Pragma_Export_Valued_Procedure =>
5186 Export_Valued_Procedure : declare
5187 Args : Args_List (1 .. 4);
5188 Names : Name_List (1 .. 4) := (
5191 Name_Parameter_Types,
5194 Internal : Node_Id renames Args (1);
5195 External : Node_Id renames Args (2);
5196 Parameter_Types : Node_Id renames Args (3);
5197 Mechanism : Node_Id renames Args (4);
5201 Gather_Associations (Names, Args);
5202 Process_Extended_Import_Export_Subprogram_Pragma (
5203 Arg_Internal => Internal,
5204 Arg_External => External,
5205 Arg_Parameter_Types => Parameter_Types,
5206 Arg_Mechanism => Mechanism);
5207 end Export_Valued_Procedure;
5213 -- pragma Extend_System ([Name =>] Identifier);
5215 when Pragma_Extend_System => Extend_System : declare
5218 Check_Valid_Configuration_Pragma;
5219 Check_Arg_Count (1);
5220 Check_Optional_Identifier (Arg1, Name_Name);
5221 Check_Arg_Is_Identifier (Arg1);
5223 Get_Name_String (Chars (Expression (Arg1)));
5226 and then Name_Buffer (1 .. 4) = "aux_"
5228 if Present (System_Extend_Pragma_Arg) then
5229 if Chars (Expression (Arg1)) =
5230 Chars (Expression (System_Extend_Pragma_Arg))
5234 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
5235 Error_Pragma ("pragma% conflicts with that at#");
5239 System_Extend_Pragma_Arg := Arg1;
5242 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
5246 ------------------------
5247 -- Extensions_Allowed --
5248 ------------------------
5250 -- pragma Extensions_Allowed (ON | OFF);
5252 when Pragma_Extensions_Allowed =>
5254 Check_Arg_Count (1);
5255 Check_No_Identifiers;
5256 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5257 Extensions_Allowed := (Chars (Expression (Arg1)) = Name_On);
5259 --------------------------
5260 -- External_Name_Casing --
5261 --------------------------
5263 -- pragma External_Name_Casing (
5264 -- UPPERCASE | LOWERCASE
5265 -- [, AS_IS | UPPERCASE | LOWERCASE]);
5267 when Pragma_External_Name_Casing =>
5269 External_Name_Casing : declare
5272 Check_No_Identifiers;
5274 if Arg_Count = 2 then
5276 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
5278 case Chars (Get_Pragma_Arg (Arg2)) is
5280 Opt.External_Name_Exp_Casing := As_Is;
5282 when Name_Uppercase =>
5283 Opt.External_Name_Exp_Casing := Uppercase;
5285 when Name_Lowercase =>
5286 Opt.External_Name_Exp_Casing := Lowercase;
5293 Check_Arg_Count (1);
5296 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
5298 case Chars (Get_Pragma_Arg (Arg1)) is
5299 when Name_Uppercase =>
5300 Opt.External_Name_Imp_Casing := Uppercase;
5302 when Name_Lowercase =>
5303 Opt.External_Name_Imp_Casing := Lowercase;
5309 end External_Name_Casing;
5311 ---------------------------
5312 -- Finalize_Storage_Only --
5313 ---------------------------
5315 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
5317 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
5318 Assoc : Node_Id := Arg1;
5319 Type_Id : Node_Id := Expression (Assoc);
5323 Check_No_Identifiers;
5324 Check_Arg_Count (1);
5325 Check_Arg_Is_Local_Name (Arg1);
5327 Find_Type (Type_Id);
5328 Typ := Entity (Type_Id);
5331 or else Rep_Item_Too_Early (Typ, N)
5335 Typ := Underlying_Type (Typ);
5338 if not Is_Controlled (Typ) then
5339 Error_Pragma ("pragma% must specify controlled type");
5342 Check_First_Subtype (Arg1);
5344 if Finalize_Storage_Only (Typ) then
5345 Error_Pragma ("duplicate pragma%, only one allowed");
5347 elsif not Rep_Item_Too_Late (Typ, N) then
5348 Set_Finalize_Storage_Only (Typ, True);
5350 end Finalize_Storage;
5352 --------------------------
5353 -- Float_Representation --
5354 --------------------------
5356 -- pragma Float_Representation (VAX_Float | IEEE_Float);
5358 when Pragma_Float_Representation => Float_Representation : declare
5366 if Arg_Count = 1 then
5367 Check_Valid_Configuration_Pragma;
5369 Check_Arg_Count (2);
5370 Check_Optional_Identifier (Arg2, Name_Entity);
5371 Check_Arg_Is_Local_Name (Arg2);
5374 Check_No_Identifier (Arg1);
5375 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
5377 if not OpenVMS_On_Target then
5378 if Chars (Expression (Arg1)) = Name_VAX_Float then
5380 ("?pragma% ignored (applies only to Open'V'M'S)");
5386 -- One argument case
5388 if Arg_Count = 1 then
5390 if Chars (Expression (Arg1)) = Name_VAX_Float then
5392 if Opt.Float_Format = 'I' then
5393 Error_Pragma ("'I'E'E'E format previously specified");
5396 Opt.Float_Format := 'V';
5399 if Opt.Float_Format = 'V' then
5400 Error_Pragma ("'V'A'X format previously specified");
5403 Opt.Float_Format := 'I';
5406 Set_Standard_Fpt_Formats;
5408 -- Two argument case
5411 Argx := Get_Pragma_Arg (Arg2);
5413 if not Is_Entity_Name (Argx)
5414 or else not Is_Floating_Point_Type (Entity (Argx))
5417 ("second argument of% pragma must be floating-point type",
5421 Ent := Entity (Argx);
5422 Digs := UI_To_Int (Digits_Value (Ent));
5424 -- Two arguments, VAX_Float case
5426 if Chars (Expression (Arg1)) = Name_VAX_Float then
5429 when 6 => Set_F_Float (Ent);
5430 when 9 => Set_D_Float (Ent);
5431 when 15 => Set_G_Float (Ent);
5435 ("wrong digits value, must be 6,9 or 15", Arg2);
5438 -- Two arguments, IEEE_Float case
5442 when 6 => Set_IEEE_Short (Ent);
5443 when 15 => Set_IEEE_Long (Ent);
5447 ("wrong digits value, must be 6 or 15", Arg2);
5452 end Float_Representation;
5458 -- pragma Ident (static_string_EXPRESSION)
5460 -- Note: pragma Comment shares this processing. Pragma Comment
5461 -- is identical to Ident, except that the restriction of the
5462 -- argument to 31 characters and the placement restrictions
5463 -- are not enforced for pragma Comment.
5465 when Pragma_Ident | Pragma_Comment => Ident : declare
5470 Check_Arg_Count (1);
5471 Check_No_Identifiers;
5472 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
5474 -- For pragma Ident, preserve DEC compatibility by requiring
5475 -- the pragma to appear in a declarative part or package spec.
5477 if Prag_Id = Pragma_Ident then
5478 Check_Is_In_Decl_Part_Or_Package_Spec;
5481 Str := Expr_Value_S (Expression (Arg1));
5483 -- For pragma Ident, preserve DEC compatibility by limiting
5484 -- the length to 31 characters.
5486 if Prag_Id = Pragma_Ident
5487 and then String_Length (Strval (Str)) > 31
5490 ("argument for pragma% is too long, maximum is 31", Arg1);
5498 GP := Parent (Parent (N));
5500 if Nkind (GP) = N_Package_Declaration
5502 Nkind (GP) = N_Generic_Package_Declaration
5507 -- If we have a compilation unit, then record the ident
5508 -- value, checking for improper duplication.
5510 if Nkind (GP) = N_Compilation_Unit then
5511 CS := Ident_String (Current_Sem_Unit);
5513 if Present (CS) then
5515 -- For Ident, we do not permit multiple instances
5517 if Prag_Id = Pragma_Ident then
5518 Error_Pragma ("duplicate% pragma not permitted");
5520 -- For Comment, we concatenate the string, unless we
5521 -- want to preserve the tree structure for ASIS.
5523 elsif not Tree_Output then
5524 Start_String (Strval (CS));
5525 Store_String_Char (' ');
5526 Store_String_Chars (Strval (Str));
5527 Set_Strval (CS, End_String);
5531 -- In VMS, the effect of IDENT is achieved by passing
5532 -- IDENTIFICATION=name as a --for-linker switch.
5534 if OpenVMS_On_Target then
5537 ("--for-linker=IDENTIFICATION=");
5538 String_To_Name_Buffer (Strval (Str));
5539 Store_String_Chars (Name_Buffer (1 .. Name_Len));
5541 -- Only the last processed IDENT is saved. The main
5542 -- purpose is so an IDENT associated with a main
5543 -- procedure will be used in preference to an IDENT
5544 -- associated with a with'd package.
5546 Replace_Linker_Option_String
5547 (End_String, "--for-linker=IDENTIFICATION=");
5550 Set_Ident_String (Current_Sem_Unit, Str);
5553 -- For subunits, we just ignore the Ident, since in GNAT
5554 -- these are not separate object files, and hence not
5555 -- separate units in the unit table.
5557 elsif Nkind (GP) = N_Subunit then
5560 -- Otherwise we have a misplaced pragma Ident, but we ignore
5561 -- this if we are in an instantiation, since it comes from
5562 -- a generic, and has no relevance to the instantiation.
5564 elsif Prag_Id = Pragma_Ident then
5565 if Instantiation_Location (Loc) = No_Location then
5566 Error_Pragma ("pragma% only allowed at outer level");
5577 -- [ Convention =>] convention_IDENTIFIER,
5578 -- [ Entity =>] local_NAME
5579 -- [, [External_Name =>] static_string_EXPRESSION ]
5580 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5582 when Pragma_Import =>
5583 Check_Ada_83_Warning;
5584 Check_At_Least_N_Arguments (2);
5585 Check_At_Most_N_Arguments (4);
5586 Process_Import_Or_Interface;
5588 ----------------------
5589 -- Import_Exception --
5590 ----------------------
5592 -- pragma Import_Exception (
5593 -- [Internal =>] LOCAL_NAME,
5594 -- [, [External =>] EXTERNAL_SYMBOL,]
5595 -- [, [Form =>] Ada | VMS]
5596 -- [, [Code =>] static_integer_EXPRESSION]);
5598 when Pragma_Import_Exception => Import_Exception : declare
5599 Args : Args_List (1 .. 4);
5600 Names : Name_List (1 .. 4) := (
5606 Internal : Node_Id renames Args (1);
5607 External : Node_Id renames Args (2);
5608 Form : Node_Id renames Args (3);
5609 Code : Node_Id renames Args (4);
5613 Gather_Associations (Names, Args);
5615 if Present (External) and then Present (Code) then
5617 ("cannot give both External and Code options for pragma%");
5620 Process_Extended_Import_Export_Exception_Pragma (
5621 Arg_Internal => Internal,
5622 Arg_External => External,
5626 if not Is_VMS_Exception (Entity (Internal)) then
5627 Set_Imported (Entity (Internal));
5630 end Import_Exception;
5632 ---------------------
5633 -- Import_Function --
5634 ---------------------
5636 -- pragma Import_Function (
5637 -- [Internal =>] LOCAL_NAME,
5638 -- [, [External =>] EXTERNAL_SYMBOL]
5639 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5640 -- [, [Result_Type =>] SUBTYPE_MARK]
5641 -- [, [Mechanism =>] MECHANISM]
5642 -- [, [Result_Mechanism =>] MECHANISM_NAME]
5643 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
5645 when Pragma_Import_Function => Import_Function : declare
5646 Args : Args_List (1 .. 7);
5647 Names : Name_List (1 .. 7) := (
5650 Name_Parameter_Types,
5653 Name_Result_Mechanism,
5654 Name_First_Optional_Parameter);
5656 Internal : Node_Id renames Args (1);
5657 External : Node_Id renames Args (2);
5658 Parameter_Types : Node_Id renames Args (3);
5659 Result_Type : Node_Id renames Args (4);
5660 Mechanism : Node_Id renames Args (5);
5661 Result_Mechanism : Node_Id renames Args (6);
5662 First_Optional_Parameter : Node_Id renames Args (7);
5666 Gather_Associations (Names, Args);
5667 Process_Extended_Import_Export_Subprogram_Pragma (
5668 Arg_Internal => Internal,
5669 Arg_External => External,
5670 Arg_Parameter_Types => Parameter_Types,
5671 Arg_Result_Type => Result_Type,
5672 Arg_Mechanism => Mechanism,
5673 Arg_Result_Mechanism => Result_Mechanism,
5674 Arg_First_Optional_Parameter => First_Optional_Parameter);
5675 end Import_Function;
5681 -- pragma Import_Object (
5682 -- [Internal =>] LOCAL_NAME,
5683 -- [, [External =>] EXTERNAL_SYMBOL]
5684 -- [, [Size =>] EXTERNAL_SYMBOL]);
5686 when Pragma_Import_Object => Import_Object : declare
5687 Args : Args_List (1 .. 3);
5688 Names : Name_List (1 .. 3) := (
5693 Internal : Node_Id renames Args (1);
5694 External : Node_Id renames Args (2);
5695 Size : Node_Id renames Args (3);
5699 Gather_Associations (Names, Args);
5700 Process_Extended_Import_Export_Object_Pragma (
5701 Arg_Internal => Internal,
5702 Arg_External => External,
5706 ----------------------
5707 -- Import_Procedure --
5708 ----------------------
5710 -- pragma Import_Procedure (
5711 -- [Internal =>] LOCAL_NAME,
5712 -- [, [External =>] EXTERNAL_SYMBOL]
5713 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5714 -- [, [Mechanism =>] MECHANISM]
5715 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
5717 when Pragma_Import_Procedure => Import_Procedure : declare
5718 Args : Args_List (1 .. 5);
5719 Names : Name_List (1 .. 5) := (
5722 Name_Parameter_Types,
5724 Name_First_Optional_Parameter);
5726 Internal : Node_Id renames Args (1);
5727 External : Node_Id renames Args (2);
5728 Parameter_Types : Node_Id renames Args (3);
5729 Mechanism : Node_Id renames Args (4);
5730 First_Optional_Parameter : Node_Id renames Args (5);
5734 Gather_Associations (Names, Args);
5735 Process_Extended_Import_Export_Subprogram_Pragma (
5736 Arg_Internal => Internal,
5737 Arg_External => External,
5738 Arg_Parameter_Types => Parameter_Types,
5739 Arg_Mechanism => Mechanism,
5740 Arg_First_Optional_Parameter => First_Optional_Parameter);
5741 end Import_Procedure;
5743 -----------------------------
5744 -- Import_Valued_Procedure --
5745 -----------------------------
5747 -- pragma Import_Valued_Procedure (
5748 -- [Internal =>] LOCAL_NAME,
5749 -- [, [External =>] EXTERNAL_SYMBOL]
5750 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5751 -- [, [Mechanism =>] MECHANISM]
5752 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
5754 when Pragma_Import_Valued_Procedure =>
5755 Import_Valued_Procedure : declare
5756 Args : Args_List (1 .. 5);
5757 Names : Name_List (1 .. 5) := (
5760 Name_Parameter_Types,
5762 Name_First_Optional_Parameter);
5764 Internal : Node_Id renames Args (1);
5765 External : Node_Id renames Args (2);
5766 Parameter_Types : Node_Id renames Args (3);
5767 Mechanism : Node_Id renames Args (4);
5768 First_Optional_Parameter : Node_Id renames Args (5);
5772 Gather_Associations (Names, Args);
5773 Process_Extended_Import_Export_Subprogram_Pragma (
5774 Arg_Internal => Internal,
5775 Arg_External => External,
5776 Arg_Parameter_Types => Parameter_Types,
5777 Arg_Mechanism => Mechanism,
5778 Arg_First_Optional_Parameter => First_Optional_Parameter);
5779 end Import_Valued_Procedure;
5781 ------------------------
5782 -- Initialize_Scalars --
5783 ------------------------
5785 -- pragma Initialize_Scalars;
5787 when Pragma_Initialize_Scalars =>
5789 Check_Arg_Count (0);
5790 Check_Valid_Configuration_Pragma;
5791 Init_Or_Norm_Scalars := True;
5792 Initialize_Scalars := True;
5798 -- pragma Inline ( NAME {, NAME} );
5800 when Pragma_Inline =>
5802 -- Pragma is active if inlining option is active
5804 if Inline_Active then
5805 Process_Inline (True);
5807 -- Pragma is active in a predefined file in no run time mode
5811 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
5813 Process_Inline (True);
5816 Process_Inline (False);
5823 -- pragma Inline_Always ( NAME {, NAME} );
5825 when Pragma_Inline_Always =>
5826 Process_Inline (True);
5828 --------------------
5829 -- Inline_Generic --
5830 --------------------
5832 -- pragma Inline_Generic (NAME {, NAME});
5834 when Pragma_Inline_Generic =>
5835 Process_Generic_List;
5837 ----------------------
5838 -- Inspection_Point --
5839 ----------------------
5841 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
5843 when Pragma_Inspection_Point => Inspection_Point : declare
5848 if Arg_Count > 0 then
5851 Exp := Expression (Arg);
5854 if not Is_Entity_Name (Exp)
5855 or else not Is_Object (Entity (Exp))
5857 Error_Pragma_Arg ("object name required", Arg);
5864 end Inspection_Point;
5870 -- pragma Interface (
5871 -- convention_IDENTIFIER,
5874 when Pragma_Interface =>
5876 Check_Arg_Count (2);
5877 Check_No_Identifiers;
5878 Process_Import_Or_Interface;
5880 --------------------
5881 -- Interface_Name --
5882 --------------------
5884 -- pragma Interface_Name (
5885 -- [ Entity =>] local_NAME
5886 -- [,[External_Name =>] static_string_EXPRESSION ]
5887 -- [,[Link_Name =>] static_string_EXPRESSION ]);
5889 when Pragma_Interface_Name => Interface_Name : declare
5897 Check_At_Least_N_Arguments (2);
5898 Check_At_Most_N_Arguments (3);
5899 Id := Expression (Arg1);
5902 if not Is_Entity_Name (Id) then
5904 ("first argument for pragma% must be entity name", Arg1);
5905 elsif Etype (Id) = Any_Type then
5908 Def_Id := Entity (Id);
5911 -- Special DEC-compatible processing for the object case,
5912 -- forces object to be imported.
5914 if Ekind (Def_Id) = E_Variable then
5915 Kill_Size_Check_Code (Def_Id);
5916 Note_Possible_Modification (Id);
5918 -- Initialization is not allowed for imported variable
5920 if Present (Expression (Parent (Def_Id)))
5921 and then Comes_From_Source (Expression (Parent (Def_Id)))
5923 Error_Msg_Sloc := Sloc (Def_Id);
5925 ("no initialization allowed for declaration of& #",
5929 -- For compatibility, support VADS usage of providing both
5930 -- pragmas Interface and Interface_Name to obtain the effect
5931 -- of a single Import pragma.
5933 if Is_Imported (Def_Id)
5934 and then Present (First_Rep_Item (Def_Id))
5935 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
5936 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
5940 Set_Imported (Def_Id);
5943 Set_Is_Public (Def_Id);
5944 Process_Interface_Name (Def_Id, Arg2, Arg3);
5947 -- Otherwise must be subprogram
5949 elsif not Is_Subprogram (Def_Id) then
5951 ("argument of pragma% is not subprogram", Arg1);
5954 Check_At_Most_N_Arguments (3);
5958 -- Loop through homonyms
5961 Def_Id := Get_Base_Subprogram (Hom_Id);
5963 if Is_Imported (Def_Id) then
5964 Process_Interface_Name (Def_Id, Arg2, Arg3);
5968 Hom_Id := Homonym (Hom_Id);
5970 exit when No (Hom_Id)
5971 or else Scope (Hom_Id) /= Current_Scope;
5976 ("argument of pragma% is not imported subprogram",
5982 -----------------------
5983 -- Interrupt_Handler --
5984 -----------------------
5986 -- pragma Interrupt_Handler (handler_NAME);
5988 when Pragma_Interrupt_Handler =>
5989 Check_Ada_83_Warning;
5990 Check_Arg_Count (1);
5991 Check_No_Identifiers;
5992 Check_Interrupt_Or_Attach_Handler;
5993 Process_Interrupt_Or_Attach_Handler;
5995 ------------------------
5996 -- Interrupt_Priority --
5997 ------------------------
5999 -- pragma Interrupt_Priority [(EXPRESSION)];
6001 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
6002 P : constant Node_Id := Parent (N);
6006 Check_Ada_83_Warning;
6008 if Arg_Count /= 0 then
6009 Arg := Expression (Arg1);
6010 Check_Arg_Count (1);
6011 Check_No_Identifiers;
6013 -- Set In_Default_Expression for per-object case???
6015 Analyze_And_Resolve (Arg, Standard_Integer);
6016 if Expander_Active then
6018 Convert_To (RTE (RE_Interrupt_Priority), Arg));
6022 if Nkind (P) /= N_Task_Definition
6023 and then Nkind (P) /= N_Protected_Definition
6028 elsif Has_Priority_Pragma (P) then
6029 Error_Pragma ("duplicate pragma% not allowed");
6032 Set_Has_Priority_Pragma (P, True);
6033 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6035 end Interrupt_Priority;
6037 ----------------------
6038 -- Java_Constructor --
6039 ----------------------
6041 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
6043 when Pragma_Java_Constructor => Java_Constructor : declare
6050 Check_Arg_Count (1);
6051 Check_Optional_Identifier (Arg1, Name_Entity);
6052 Check_Arg_Is_Local_Name (Arg1);
6054 Id := Expression (Arg1);
6055 Find_Program_Unit_Name (Id);
6057 -- If we did not find the name, we are done
6059 if Etype (Id) = Any_Type then
6063 Hom_Id := Entity (Id);
6065 -- Loop through homonyms
6068 Def_Id := Get_Base_Subprogram (Hom_Id);
6070 -- The constructor is required to be a function returning
6071 -- an access type whose designated type has convention Java.
6073 if Ekind (Def_Id) = E_Function
6074 and then Ekind (Etype (Def_Id)) in Access_Kind
6077 (Designated_Type (Etype (Def_Id))) = Convention_Java
6080 (Root_Type (Designated_Type (Etype (Def_Id))))
6083 Set_Is_Constructor (Def_Id);
6084 Set_Convention (Def_Id, Convention_Java);
6088 ("pragma% requires function returning a 'Java access type",
6092 Hom_Id := Homonym (Hom_Id);
6094 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
6096 end Java_Constructor;
6098 ----------------------
6099 -- Java_Interface --
6100 ----------------------
6102 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
6104 when Pragma_Java_Interface => Java_Interface : declare
6110 Check_Arg_Count (1);
6111 Check_Optional_Identifier (Arg1, Name_Entity);
6112 Check_Arg_Is_Local_Name (Arg1);
6114 Arg := Expression (Arg1);
6117 if Etype (Arg) = Any_Type then
6121 if not Is_Entity_Name (Arg)
6122 or else not Is_Type (Entity (Arg))
6124 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6127 Typ := Underlying_Type (Entity (Arg));
6129 -- For now we simply check some of the semantic constraints
6130 -- on the type. This currently leaves out some restrictions
6131 -- on interface types, namely that the parent type must be
6132 -- java.lang.Object.Typ and that all primitives of the type
6133 -- should be declared abstract. ???
6135 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
6136 Error_Pragma_Arg ("pragma% requires an abstract "
6137 & "tagged type", Arg1);
6139 elsif not Has_Discriminants (Typ)
6140 or else Ekind (Etype (First_Discriminant (Typ)))
6141 /= E_Anonymous_Access_Type
6143 not Is_Class_Wide_Type
6144 (Designated_Type (Etype (First_Discriminant (Typ))))
6147 ("type must have a class-wide access discriminant", Arg1);
6155 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
6157 when Pragma_License =>
6159 Check_Arg_Count (1);
6160 Check_No_Identifiers;
6161 Check_Valid_Configuration_Pragma;
6162 Check_Arg_Is_Identifier (Arg1);
6165 Sind : constant Source_File_Index :=
6166 Source_Index (Current_Sem_Unit);
6169 case Chars (Get_Pragma_Arg (Arg1)) is
6171 Set_License (Sind, GPL);
6173 when Name_Modified_GPL =>
6174 Set_License (Sind, Modified_GPL);
6176 when Name_Restricted =>
6177 Set_License (Sind, Restricted);
6179 when Name_Unrestricted =>
6180 Set_License (Sind, Unrestricted);
6183 Error_Pragma_Arg ("invalid license name", Arg1);
6191 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
6193 when Pragma_Link_With => Link_With : declare
6199 if Operating_Mode = Generate_Code
6200 and then In_Extended_Main_Source_Unit (N)
6202 Check_At_Least_N_Arguments (1);
6203 Check_No_Identifiers;
6204 Check_Is_In_Decl_Part_Or_Package_Spec;
6205 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6209 while Present (Arg) loop
6210 Check_Arg_Is_Static_Expression (Arg, Standard_String);
6212 -- Store argument, converting sequences of spaces to
6213 -- a single null character (this is the difference in
6214 -- processing between Link_With, and Linker_Options).
6217 C : constant Char_Code := Get_Char_Code (' ');
6218 S : constant String_Id :=
6219 Strval (Expr_Value_S (Expression (Arg)));
6222 L : Nat := String_Length (S);
6224 procedure Skip_Spaces;
6225 -- Advance F past any spaces
6227 procedure Skip_Spaces is
6229 while F <= L and then Get_String_Char (S, F) = C loop
6235 Skip_Spaces; -- skip leading spaces
6237 -- Loop through characters, changing any embedded
6238 -- sequence of spaces to a single null character
6239 -- (this is how Link_With/Linker_Options differ)
6242 if Get_String_Char (S, F) = C then
6245 Store_String_Char (ASCII.NUL);
6248 Store_String_Char (Get_String_Char (S, F));
6256 if Present (Arg) then
6257 Store_String_Char (ASCII.NUL);
6261 Store_Linker_Option_String (End_String);
6269 -- pragma Linker_Alias (
6270 -- [Entity =>] LOCAL_NAME
6271 -- [Alias =>] static_string_EXPRESSION);
6273 when Pragma_Linker_Alias =>
6275 Check_Arg_Count (2);
6276 Check_Optional_Identifier (Arg1, Name_Entity);
6277 Check_Optional_Identifier (Arg2, "alias");
6278 Check_Arg_Is_Library_Level_Local_Name (Arg1);
6279 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6281 -- The only processing required is to link this item on to the
6282 -- list of rep items for the given entity. This is accomplished
6283 -- by the call to Rep_Item_Too_Late (when no error is detected
6284 -- and False is returned).
6286 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
6289 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6292 --------------------
6293 -- Linker_Options --
6294 --------------------
6296 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
6298 -- Note: the use of multiple arguments is a GNAT extension
6300 when Pragma_Linker_Options => Linker_Options : declare
6304 if Operating_Mode = Generate_Code
6305 and then In_Extended_Main_Source_Unit (N)
6307 Check_Ada_83_Warning;
6308 Check_At_Least_N_Arguments (1);
6309 Check_No_Identifiers;
6310 Check_Is_In_Decl_Part_Or_Package_Spec;
6311 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6312 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
6315 while Present (Arg) loop
6316 Check_Arg_Is_Static_Expression (Arg, Standard_String);
6317 Store_String_Char (ASCII.NUL);
6319 (Strval (Expr_Value_S (Expression (Arg))));
6323 Store_Linker_Option_String (End_String);
6327 --------------------
6328 -- Linker_Section --
6329 --------------------
6331 -- pragma Linker_Section (
6332 -- [Entity =>] LOCAL_NAME
6333 -- [Section =>] static_string_EXPRESSION);
6335 when Pragma_Linker_Section =>
6337 Check_Arg_Count (2);
6338 Check_Optional_Identifier (Arg1, Name_Entity);
6339 Check_Optional_Identifier (Arg2, Name_Section);
6340 Check_Arg_Is_Library_Level_Local_Name (Arg1);
6341 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6343 -- The only processing required is to link this item on to the
6344 -- list of rep items for the given entity. This is accomplished
6345 -- by the call to Rep_Item_Too_Late (when no error is detected
6346 -- and False is returned).
6348 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
6351 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6358 -- pragma List (On | Off)
6360 -- There is nothing to do here, since we did all the processing
6361 -- for this pragma in Par.Prag (so that it works properly even in
6362 -- syntax only mode)
6367 --------------------
6368 -- Locking_Policy --
6369 --------------------
6371 -- pragma Locking_Policy (policy_IDENTIFIER);
6373 when Pragma_Locking_Policy => declare
6377 Check_Ada_83_Warning;
6378 Check_Arg_Count (1);
6379 Check_No_Identifiers;
6380 Check_Arg_Is_Locking_Policy (Arg1);
6381 Check_Valid_Configuration_Pragma;
6382 Get_Name_String (Chars (Expression (Arg1)));
6383 LP := Fold_Upper (Name_Buffer (1));
6385 if Locking_Policy /= ' '
6386 and then Locking_Policy /= LP
6388 Error_Msg_Sloc := Locking_Policy_Sloc;
6389 Error_Pragma ("locking policy incompatible with policy#");
6391 Locking_Policy := LP;
6392 Locking_Policy_Sloc := Loc;
6400 -- pragma Long_Float (D_Float | G_Float);
6402 when Pragma_Long_Float =>
6404 Check_Valid_Configuration_Pragma;
6405 Check_Arg_Count (1);
6406 Check_No_Identifier (Arg1);
6407 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
6409 if not OpenVMS_On_Target then
6410 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
6415 if Chars (Expression (Arg1)) = Name_D_Float then
6416 if Opt.Float_Format_Long = 'G' then
6417 Error_Pragma ("G_Float previously specified");
6420 Opt.Float_Format_Long := 'D';
6422 -- G_Float case (this is the default, does not need overriding)
6425 if Opt.Float_Format_Long = 'D' then
6426 Error_Pragma ("D_Float previously specified");
6429 Opt.Float_Format_Long := 'G';
6432 Set_Standard_Fpt_Formats;
6434 -----------------------
6435 -- Machine_Attribute --
6436 -----------------------
6438 -- pragma Machine_Attribute (
6439 -- [Entity =>] LOCAL_NAME,
6440 -- [Attribute_Name =>] static_string_EXPRESSION
6441 -- [,[Info =>] static_string_EXPRESSION] );
6443 when Pragma_Machine_Attribute => Machine_Attribute : declare
6449 if Arg_Count = 3 then
6450 Check_Optional_Identifier (Arg3, "info");
6451 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
6453 Check_Arg_Count (2);
6456 Check_Arg_Is_Local_Name (Arg1);
6457 Check_Optional_Identifier (Arg2, "attribute_name");
6458 Check_Optional_Identifier (Arg1, Name_Entity);
6459 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6460 Def_Id := Entity (Expression (Arg1));
6462 if Is_Access_Type (Def_Id) then
6463 Def_Id := Designated_Type (Def_Id);
6466 if Rep_Item_Too_Early (Def_Id, N) then
6470 Def_Id := Underlying_Type (Def_Id);
6472 -- The only processing required is to link this item on to the
6473 -- list of rep items for the given entity. This is accomplished
6474 -- by the call to Rep_Item_Too_Late (when no error is detected
6475 -- and False is returned).
6477 if Rep_Item_Too_Late (Def_Id, N) then
6480 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6482 end Machine_Attribute;
6488 -- pragma Main_Storage
6489 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
6491 -- MAIN_STORAGE_OPTION ::=
6492 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
6493 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
6495 when Pragma_Main => Main : declare
6496 Args : Args_List (1 .. 3);
6497 Names : Name_List (1 .. 3) := (
6499 Name_Task_Stack_Size_Default,
6500 Name_Time_Slicing_Enabled);
6506 Gather_Associations (Names, Args);
6508 for J in 1 .. 2 loop
6509 if Present (Args (J)) then
6510 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
6514 if Present (Args (3)) then
6515 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
6519 while Present (Nod) loop
6520 if Nkind (Nod) = N_Pragma
6521 and then Chars (Nod) = Name_Main
6523 Error_Msg_Name_1 := Chars (N);
6524 Error_Msg_N ("duplicate pragma% not permitted", Nod);
6535 -- pragma Main_Storage
6536 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
6538 -- MAIN_STORAGE_OPTION ::=
6539 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
6540 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
6542 when Pragma_Main_Storage => Main_Storage : declare
6543 Args : Args_List (1 .. 2);
6544 Names : Name_List (1 .. 2) := (
6545 Name_Working_Storage,
6552 Gather_Associations (Names, Args);
6554 for J in 1 .. 2 loop
6555 if Present (Args (J)) then
6556 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
6560 Check_In_Main_Program;
6563 while Present (Nod) loop
6564 if Nkind (Nod) = N_Pragma
6565 and then Chars (Nod) = Name_Main_Storage
6567 Error_Msg_Name_1 := Chars (N);
6568 Error_Msg_N ("duplicate pragma% not permitted", Nod);
6580 -- pragma Memory_Size (NUMERIC_LITERAL)
6582 when Pragma_Memory_Size =>
6585 -- Memory size is simply ignored
6587 Check_No_Identifiers;
6588 Check_Arg_Count (1);
6589 Check_Arg_Is_Integer_Literal (Arg1);
6595 -- pragma No_Return (procedure_LOCAL_NAME);
6597 when Pragma_No_Return => declare
6604 Check_Arg_Count (1);
6605 Check_No_Identifiers;
6606 Check_Arg_Is_Local_Name (Arg1);
6607 Id := Expression (Arg1);
6610 if not Is_Entity_Name (Id) then
6611 Error_Pragma_Arg ("entity name required", Arg1);
6614 if Etype (Id) = Any_Type then
6622 and then Scope (E) = Current_Scope
6624 if Ekind (E) = E_Procedure
6625 or else Ekind (E) = E_Generic_Procedure
6635 Error_Pragma ("no procedures found for pragma%");
6643 -- pragma No_Run_Time
6645 when Pragma_No_Run_Time =>
6647 Check_Valid_Configuration_Pragma;
6648 Check_Arg_Count (0);
6649 Set_No_Run_Time_Mode;
6651 -----------------------
6652 -- Normalize_Scalars --
6653 -----------------------
6655 -- pragma Normalize_Scalars;
6657 when Pragma_Normalize_Scalars =>
6658 Check_Ada_83_Warning;
6659 Check_Arg_Count (0);
6660 Check_Valid_Configuration_Pragma;
6661 Normalize_Scalars := True;
6662 Init_Or_Norm_Scalars := True;
6668 -- pragma Optimize (Time | Space);
6670 -- The actual check for optimize is done in Gigi. Note that this
6671 -- pragma does not actually change the optimization setting, it
6672 -- simply checks that it is consistent with the pragma.
6674 when Pragma_Optimize =>
6675 Check_No_Identifiers;
6676 Check_Arg_Count (1);
6677 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
6683 -- pragma Pack (first_subtype_LOCAL_NAME);
6685 when Pragma_Pack => Pack : declare
6686 Assoc : Node_Id := Arg1;
6691 Check_No_Identifiers;
6692 Check_Arg_Count (1);
6693 Check_Arg_Is_Local_Name (Arg1);
6695 Type_Id := Expression (Assoc);
6696 Find_Type (Type_Id);
6697 Typ := Entity (Type_Id);
6700 or else Rep_Item_Too_Early (Typ, N)
6704 Typ := Underlying_Type (Typ);
6707 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
6708 Error_Pragma ("pragma% must specify array or record type");
6711 Check_First_Subtype (Arg1);
6713 if Has_Pragma_Pack (Typ) then
6714 Error_Pragma ("duplicate pragma%, only one allowed");
6716 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
6717 -- but not Has_Non_Standard_Rep, because we don't actually know
6718 -- till freeze time if the array can have packed representation.
6719 -- That's because in the general case we do not know enough about
6720 -- the component type until it in turn is frozen, which certainly
6721 -- happens before the array type is frozen, but not necessarily
6722 -- till that point (i.e. right now it may be unfrozen).
6724 elsif Is_Array_Type (Typ) then
6726 if Has_Aliased_Components (Base_Type (Typ)) then
6728 ("pragma% ignored, cannot pack aliased components?");
6730 elsif Has_Atomic_Components (Typ) then
6732 ("?pragma% ignored, cannot pack atomic components");
6734 elsif not Rep_Item_Too_Late (Typ, N) then
6735 Set_Is_Packed (Base_Type (Typ));
6736 Set_Has_Pragma_Pack (Base_Type (Typ));
6737 Set_Has_Non_Standard_Rep (Base_Type (Typ));
6740 -- Record type. For record types, the pack is always effective
6742 else -- Is_Record_Type (Typ)
6743 if not Rep_Item_Too_Late (Typ, N) then
6744 Set_Has_Pragma_Pack (Base_Type (Typ));
6745 Set_Is_Packed (Base_Type (Typ));
6746 Set_Has_Non_Standard_Rep (Base_Type (Typ));
6757 -- There is nothing to do here, since we did all the processing
6758 -- for this pragma in Par.Prag (so that it works properly even in
6759 -- syntax only mode)
6768 -- pragma Passive [(PASSIVE_FORM)];
6770 -- PASSIVE_FORM ::= Semaphore | No
6772 when Pragma_Passive =>
6775 if Nkind (Parent (N)) /= N_Task_Definition then
6776 Error_Pragma ("pragma% must be within task definition");
6779 if Arg_Count /= 0 then
6780 Check_Arg_Count (1);
6781 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
6788 -- pragma Polling (ON | OFF);
6790 when Pragma_Polling =>
6792 Check_Arg_Count (1);
6793 Check_No_Identifiers;
6794 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6795 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
6801 -- pragma Preelaborate [(library_unit_NAME)];
6803 -- Set the flag Is_Preelaborated of program unit name entity
6805 when Pragma_Preelaborate => Preelaborate : declare
6807 Pa : Node_Id := Parent (N);
6808 Pk : Node_Kind := Nkind (Pa);
6811 Check_Ada_83_Warning;
6812 Check_Valid_Library_Unit_Pragma;
6814 if Nkind (N) = N_Null_Statement then
6818 Ent := Find_Lib_Unit_Name;
6820 -- This filters out pragmas inside generic parent then
6821 -- show up inside instantiation
6824 and then not (Pk = N_Package_Specification
6825 and then Present (Generic_Parent (Pa)))
6827 if not Debug_Flag_U then
6828 Set_Is_Preelaborated (Ent);
6829 Set_Suppress_Elaboration_Warnings (Ent);
6838 -- pragma Priority (EXPRESSION);
6840 when Pragma_Priority => Priority : declare
6841 P : constant Node_Id := Parent (N);
6845 Check_No_Identifiers;
6846 Check_Arg_Count (1);
6848 Arg := Expression (Arg1);
6849 Analyze_And_Resolve (Arg, Standard_Integer);
6851 if not Is_Static_Expression (Arg) then
6852 Check_Restriction (Static_Priorities, Arg);
6857 if Nkind (P) = N_Subprogram_Body then
6858 Check_In_Main_Program;
6862 if not Is_Static_Expression (Arg) then
6864 ("main subprogram priority is not static", Arg1);
6866 -- If constraint error, then we already signalled an error
6868 elsif Raises_Constraint_Error (Arg) then
6871 -- Otherwise check in range
6875 Val : constant Uint := Expr_Value (Arg);
6879 or else Val > Expr_Value (Expression
6880 (Parent (RTE (RE_Max_Priority))))
6883 ("main subprogram priority is out of range", Arg1);
6889 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
6891 -- Task or Protected, must be of type Integer
6893 elsif Nkind (P) = N_Protected_Definition
6895 Nkind (P) = N_Task_Definition
6897 if Expander_Active then
6899 Convert_To (RTE (RE_Any_Priority), Arg));
6902 -- Anything else is incorrect
6908 if Has_Priority_Pragma (P) then
6909 Error_Pragma ("duplicate pragma% not allowed");
6911 Set_Has_Priority_Pragma (P, True);
6913 if Nkind (P) = N_Protected_Definition
6915 Nkind (P) = N_Task_Definition
6917 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6918 -- exp_ch9 should use this ???
6924 --------------------------
6925 -- Propagate_Exceptions --
6926 --------------------------
6928 -- pragma Propagate_Exceptions;
6930 when Pragma_Propagate_Exceptions =>
6932 Check_Arg_Count (0);
6934 if In_Extended_Main_Source_Unit (N) then
6935 Propagate_Exceptions := True;
6942 -- pragma Psect_Object (
6943 -- [Internal =>] LOCAL_NAME,
6944 -- [, [External =>] EXTERNAL_SYMBOL]
6945 -- [, [Size =>] EXTERNAL_SYMBOL]);
6947 when Pragma_Psect_Object | Pragma_Common_Object =>
6948 Psect_Object : declare
6949 Args : Args_List (1 .. 3);
6950 Names : Name_List (1 .. 3) := (
6955 Internal : Node_Id renames Args (1);
6956 External : Node_Id renames Args (2);
6957 Size : Node_Id renames Args (3);
6959 R_Internal : Node_Id;
6960 R_External : Node_Id;
6967 procedure Check_Too_Long (Arg : Node_Id);
6968 -- Posts message if the argument is an identifier with more
6969 -- than 31 characters, or a string literal with more than
6970 -- 31 characters, and we are operating under VMS
6972 procedure Check_Too_Long (Arg : Node_Id) is
6973 X : Node_Id := Original_Node (Arg);
6976 if Nkind (X) /= N_String_Literal
6978 Nkind (X) /= N_Identifier
6981 ("inappropriate argument for pragma %", Arg);
6984 if OpenVMS_On_Target then
6985 if (Nkind (X) = N_String_Literal
6986 and then String_Length (Strval (X)) > 31)
6988 (Nkind (X) = N_Identifier
6989 and then Length_Of_Name (Chars (X)) > 31)
6992 ("argument for pragma % is longer than 31 characters",
6998 -- Start of processing for Common_Object/Psect_Object
7002 Gather_Associations (Names, Args);
7003 Process_Extended_Import_Export_Internal_Arg (Internal);
7005 R_Internal := Relocate_Node (Internal);
7007 Def_Id := Entity (R_Internal);
7009 if Ekind (Def_Id) /= E_Constant
7010 and then Ekind (Def_Id) /= E_Variable
7013 ("pragma% must designate an object", Internal);
7016 Check_Too_Long (R_Internal);
7018 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
7020 ("cannot use pragma% for imported/exported object",
7024 if Is_Concurrent_Type (Etype (R_Internal)) then
7026 ("cannot specify pragma % for task/protected object",
7030 if Is_Psected (Def_Id) then
7031 Error_Msg_N ("?duplicate Psect_Object pragma", N);
7033 Set_Is_Psected (Def_Id);
7036 if Ekind (Def_Id) = E_Constant then
7038 ("cannot specify pragma % for a constant", R_Internal);
7041 if Is_Record_Type (Etype (R_Internal)) then
7047 Ent := First_Entity (Etype (R_Internal));
7048 while Present (Ent) loop
7049 Decl := Declaration_Node (Ent);
7051 if Ekind (Ent) = E_Component
7052 and then Nkind (Decl) = N_Component_Declaration
7053 and then Present (Expression (Decl))
7056 ("?object for pragma % has defaults", R_Internal);
7066 if Present (Size) then
7067 Check_Too_Long (Size);
7070 -- Make Psect case-insensitive.
7072 if Present (External) then
7073 Check_Too_Long (External);
7075 if Nkind (External) = N_String_Literal then
7076 String_To_Name_Buffer (Strval (External));
7078 Get_Name_String (Chars (External));
7083 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7085 R_External := Make_String_Literal
7086 (Sloc => Sloc (External), Strval => Str);
7088 Get_Name_String (Chars (Internal));
7091 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7093 R_External := Make_String_Literal
7094 (Sloc => Sloc (Internal), Strval => Str);
7097 -- Transform into pragma Linker_Section, add attributes to
7098 -- match what DEC Ada does. Ignore size for now?
7103 Name_Linker_Section,
7105 (Make_Pragma_Argument_Association
7106 (Sloc => Sloc (R_Internal),
7107 Expression => R_Internal),
7108 Make_Pragma_Argument_Association
7109 (Sloc => Sloc (R_External),
7110 Expression => R_External))));
7114 -- Add Machine_Attribute of "overlaid", so the section overlays
7115 -- other sections of the same name.
7118 Store_String_Chars ("overlaid");
7124 Name_Machine_Attribute,
7126 (Make_Pragma_Argument_Association
7127 (Sloc => Sloc (R_Internal),
7128 Expression => R_Internal),
7129 Make_Pragma_Argument_Association
7130 (Sloc => Sloc (R_External),
7133 (Sloc => Sloc (R_External),
7137 -- Add Machine_Attribute of "global", so the section is visible
7141 Store_String_Chars ("global");
7147 Name_Machine_Attribute,
7149 (Make_Pragma_Argument_Association
7150 (Sloc => Sloc (R_Internal),
7151 Expression => R_Internal),
7152 Make_Pragma_Argument_Association
7153 (Sloc => Sloc (R_External),
7156 (Sloc => Sloc (R_External),
7160 -- Add Machine_Attribute of "initialize", so the section is
7164 Store_String_Chars ("initialize");
7170 Name_Machine_Attribute,
7172 (Make_Pragma_Argument_Association
7173 (Sloc => Sloc (R_Internal),
7174 Expression => R_Internal),
7175 Make_Pragma_Argument_Association
7176 (Sloc => Sloc (R_External),
7179 (Sloc => Sloc (R_External),
7189 -- pragma Pure [(library_unit_NAME)];
7191 when Pragma_Pure => Pure : declare
7194 Check_Ada_83_Warning;
7195 Check_Valid_Library_Unit_Pragma;
7197 if Nkind (N) = N_Null_Statement then
7201 Ent := Find_Lib_Unit_Name;
7203 Set_Suppress_Elaboration_Warnings (Ent);
7210 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
7212 when Pragma_Pure_Function => Pure_Function : declare
7219 Check_Arg_Count (1);
7220 Check_Optional_Identifier (Arg1, Name_Entity);
7221 Check_Arg_Is_Local_Name (Arg1);
7222 E_Id := Expression (Arg1);
7224 if Error_Posted (E_Id) then
7228 -- Loop through homonyms (overloadings) of referenced entity
7231 while Present (E) loop
7232 Def_Id := Get_Base_Subprogram (E);
7234 if Ekind (Def_Id) /= E_Function
7235 and then Ekind (Def_Id) /= E_Generic_Function
7236 and then Ekind (Def_Id) /= E_Operator
7238 Error_Pragma_Arg ("pragma% requires a function name", Arg1);
7241 Set_Is_Pure (Def_Id);
7246 --------------------
7247 -- Queuing_Policy --
7248 --------------------
7250 -- pragma Queuing_Policy (policy_IDENTIFIER);
7252 when Pragma_Queuing_Policy => declare
7256 Check_Ada_83_Warning;
7257 Check_Arg_Count (1);
7258 Check_No_Identifiers;
7259 Check_Arg_Is_Queuing_Policy (Arg1);
7260 Check_Valid_Configuration_Pragma;
7261 Get_Name_String (Chars (Expression (Arg1)));
7262 QP := Fold_Upper (Name_Buffer (1));
7264 if Queuing_Policy /= ' '
7265 and then Queuing_Policy /= QP
7267 Error_Msg_Sloc := Queuing_Policy_Sloc;
7268 Error_Pragma ("queuing policy incompatible with policy#");
7270 Queuing_Policy := QP;
7271 Queuing_Policy_Sloc := Loc;
7275 ---------------------------
7276 -- Remote_Call_Interface --
7277 ---------------------------
7279 -- pragma Remote_Call_Interface [(library_unit_NAME)];
7281 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
7282 Cunit_Node : Node_Id;
7283 Cunit_Ent : Entity_Id;
7287 Check_Ada_83_Warning;
7288 Check_Valid_Library_Unit_Pragma;
7290 if Nkind (N) = N_Null_Statement then
7294 Cunit_Node := Cunit (Current_Sem_Unit);
7295 K := Nkind (Unit (Cunit_Node));
7296 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7298 if K = N_Package_Declaration
7299 or else K = N_Generic_Package_Declaration
7300 or else K = N_Subprogram_Declaration
7301 or else K = N_Generic_Subprogram_Declaration
7302 or else (K = N_Subprogram_Body
7303 and then Acts_As_Spec (Unit (Cunit_Node)))
7308 "pragma% must apply to package or subprogram declaration");
7311 Set_Is_Remote_Call_Interface (Cunit_Ent);
7312 end Remote_Call_Interface;
7318 -- pragma Remote_Types [(library_unit_NAME)];
7320 when Pragma_Remote_Types => Remote_Types : declare
7321 Cunit_Node : Node_Id;
7322 Cunit_Ent : Entity_Id;
7325 Check_Ada_83_Warning;
7326 Check_Valid_Library_Unit_Pragma;
7328 if Nkind (N) = N_Null_Statement then
7332 Cunit_Node := Cunit (Current_Sem_Unit);
7333 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7335 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
7337 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
7340 "pragma% can only apply to a package declaration");
7343 Set_Is_Remote_Types (Cunit_Ent);
7350 when Pragma_Ravenscar =>
7352 Check_Arg_Count (0);
7353 Check_Valid_Configuration_Pragma;
7356 -------------------------
7357 -- Restricted_Run_Time --
7358 -------------------------
7360 when Pragma_Restricted_Run_Time =>
7362 Check_Arg_Count (0);
7363 Check_Valid_Configuration_Pragma;
7364 Set_Restricted_Profile;
7370 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
7373 -- restriction_IDENTIFIER
7374 -- | restriction_parameter_IDENTIFIER => EXPRESSION
7376 when Pragma_Restrictions => Restrictions_Pragma : declare
7378 R_Id : Restriction_Id;
7379 RP_Id : Restriction_Parameter_Id;
7385 Check_Ada_83_Warning;
7386 Check_At_Least_N_Arguments (1);
7387 Check_Valid_Configuration_Pragma;
7391 while Present (Arg) loop
7393 Expr := Expression (Arg);
7395 -- Case of no restriction identifier
7397 if Id = No_Name then
7398 if Nkind (Expr) /= N_Identifier then
7400 ("invalid form for restriction", Arg);
7403 R_Id := Get_Restriction_Id (Chars (Expr));
7405 if R_Id = Not_A_Restriction_Id then
7407 ("invalid restriction identifier", Arg);
7409 -- Restriction is active
7412 Restrictions (R_Id) := True;
7413 Restrictions_Loc (R_Id) := Sloc (N);
7415 -- Record the restriction if we are in the main unit,
7416 -- or in the extended main unit. The reason that we
7417 -- test separately for Main_Unit is that gnat.adc is
7418 -- processed with Current_Sem_Unit = Main_Unit, but
7419 -- nodes in gnat.adc do not appear to be the extended
7420 -- main source unit (they probably should do ???)
7422 if Current_Sem_Unit = Main_Unit
7423 or else In_Extended_Main_Source_Unit (N)
7425 Main_Restrictions (R_Id) := True;
7428 -- A very special case that must be processed here:
7429 -- pragma Restrictions (No_Exceptions) turns off all
7430 -- run-time checking. This is a bit dubious in terms
7431 -- of the formal language definition, but it is what
7432 -- is intended by the wording of RM H.4(12).
7434 if R_Id = No_Exceptions then
7435 Scope_Suppress := (others => True);
7440 -- Case of restriction identifier present
7443 RP_Id := Get_Restriction_Parameter_Id (Id);
7444 Analyze_And_Resolve (Expr, Any_Integer);
7446 if RP_Id = Not_A_Restriction_Parameter_Id then
7448 ("invalid restriction parameter identifier", Arg);
7450 elsif not Is_OK_Static_Expression (Expr)
7451 or else not Is_Integer_Type (Etype (Expr))
7452 or else Expr_Value (Expr) < 0
7455 ("value must be non-negative static integer", Arg);
7457 -- Restriction pragma is active
7460 Val := Expr_Value (Expr);
7462 -- Record pragma if most restrictive so far
7464 if Restriction_Parameters (RP_Id) = No_Uint
7465 or else Val < Restriction_Parameters (RP_Id)
7467 Restriction_Parameters (RP_Id) := Expr_Value (Expr);
7468 Restriction_Parameters_Loc (RP_Id) := Sloc (N);
7475 end Restrictions_Pragma;
7481 -- pragma Reviewable;
7483 when Pragma_Reviewable =>
7484 Check_Ada_83_Warning;
7485 Check_Arg_Count (0);
7491 -- pragma Share_Generic (NAME {, NAME});
7493 when Pragma_Share_Generic =>
7495 Process_Generic_List;
7501 -- pragma Shared (LOCAL_NAME);
7503 when Pragma_Shared =>
7504 Process_Atomic_Shared_Volatile;
7506 --------------------
7507 -- Shared_Passive --
7508 --------------------
7510 -- pragma Shared_Passive [(library_unit_NAME)];
7512 -- Set the flag Is_Shared_Passive of program unit name entity
7514 when Pragma_Shared_Passive => Shared_Passive : declare
7515 Cunit_Node : Node_Id;
7516 Cunit_Ent : Entity_Id;
7519 Check_Ada_83_Warning;
7520 Check_Valid_Library_Unit_Pragma;
7522 if Nkind (N) = N_Null_Statement then
7526 Cunit_Node := Cunit (Current_Sem_Unit);
7527 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7529 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
7531 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
7534 "pragma% can only apply to a package declaration");
7537 Set_Is_Shared_Passive (Cunit_Ent);
7540 ----------------------
7541 -- Source_File_Name --
7542 ----------------------
7544 -- pragma Source_File_Name (
7545 -- [UNIT_NAME =>] unit_NAME,
7546 -- [BODY_FILE_NAME | SPEC_FILE_NAME] => STRING_LITERAL);
7548 -- No processing here. Processing was completed during parsing,
7549 -- since we need to have file names set as early as possible.
7550 -- Units are loaded well before semantic processing starts.
7552 -- The only processing we defer to this point is the check
7553 -- for correct placement.
7555 when Pragma_Source_File_Name =>
7557 Check_Valid_Configuration_Pragma;
7559 ----------------------
7560 -- Source_Reference --
7561 ----------------------
7563 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
7565 -- Nothing to do, all processing completed in Par.Prag, since we
7566 -- need the information for possible parser messages that are output
7568 when Pragma_Source_Reference =>
7575 -- pragma Storage_Size (EXPRESSION);
7577 when Pragma_Storage_Size => Storage_Size : declare
7578 P : constant Node_Id := Parent (N);
7582 Check_No_Identifiers;
7583 Check_Arg_Count (1);
7585 -- Set In_Default_Expression for per-object case???
7587 X := Expression (Arg1);
7588 Analyze_And_Resolve (X, Any_Integer);
7590 if not Is_Static_Expression (X) then
7591 Check_Restriction (Static_Storage_Size, X);
7594 if Nkind (P) /= N_Task_Definition then
7599 if Has_Storage_Size_Pragma (P) then
7600 Error_Pragma ("duplicate pragma% not allowed");
7602 Set_Has_Storage_Size_Pragma (P, True);
7605 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7606 -- ??? exp_ch9 should use this!
7614 -- pragma Storage_Unit (NUMERIC_LITERAL);
7616 -- Only permitted argument is System'Storage_Unit value
7618 when Pragma_Storage_Unit =>
7619 Check_No_Identifiers;
7620 Check_Arg_Count (1);
7621 Check_Arg_Is_Integer_Literal (Arg1);
7623 if Intval (Expression (Arg1)) /=
7624 UI_From_Int (Ttypes.System_Storage_Unit)
7626 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
7628 ("the only allowed argument for pragma% is ^", Arg1);
7631 --------------------
7632 -- Stream_Convert --
7633 --------------------
7635 -- pragma Stream_Convert (
7636 -- [Entity =>] type_LOCAL_NAME,
7637 -- [Read =>] function_NAME,
7638 -- [Write =>] function NAME);
7640 when Pragma_Stream_Convert => Stream_Convert : begin
7642 Check_Arg_Count (3);
7643 Check_Optional_Identifier (Arg1, Name_Entity);
7644 Check_Optional_Identifier (Arg2, Name_Read);
7645 Check_Optional_Identifier (Arg3, Name_Write);
7646 Check_Arg_Is_Local_Name (Arg1);
7647 Check_Non_Overloaded_Function (Arg2);
7648 Check_Non_Overloaded_Function (Arg3);
7651 Typ : constant Entity_Id :=
7652 Underlying_Type (Entity (Expression (Arg1)));
7653 Read : constant Entity_Id := Entity (Expression (Arg2));
7654 Write : constant Entity_Id := Entity (Expression (Arg3));
7657 if Etype (Typ) = Any_Type
7659 Etype (Read) = Any_Type
7661 Etype (Write) = Any_Type
7666 Check_First_Subtype (Arg1);
7668 if Rep_Item_Too_Early (Typ, N)
7670 Rep_Item_Too_Late (Typ, N)
7675 if Underlying_Type (Etype (Read)) /= Typ then
7677 ("incorrect return type for function&", Arg2);
7680 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
7682 ("incorrect parameter type for function&", Arg3);
7685 if Underlying_Type (Etype (First_Formal (Read))) /=
7686 Underlying_Type (Etype (Write))
7689 ("result type of & does not match Read parameter type",
7695 -------------------------
7696 -- Style_Checks (GNAT) --
7697 -------------------------
7699 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
7701 -- This is processed by the parser since some of the style
7702 -- checks take place during source scanning and parsing. This
7703 -- means that we don't need to issue error messages here.
7705 when Pragma_Style_Checks => Style_Checks : declare
7706 A : constant Node_Id := Expression (Arg1);
7712 Check_No_Identifiers;
7714 -- Two argument form
7716 if Arg_Count = 2 then
7717 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7724 E_Id := Expression (Arg2);
7727 if not Is_Entity_Name (E_Id) then
7729 ("second argument of pragma% must be entity name",
7739 Set_Suppress_Style_Checks (E,
7740 (Chars (Expression (Arg1)) = Name_Off));
7741 exit when No (Homonym (E));
7747 -- One argument form
7750 Check_Arg_Count (1);
7752 if Nkind (A) = N_String_Literal then
7756 Slen : Natural := Natural (String_Length (S));
7757 Options : String (1 .. Slen);
7763 C := Get_String_Char (S, Int (J));
7764 exit when not In_Character_Range (C);
7765 Options (J) := Get_Character (C);
7768 Set_Style_Check_Options (Options);
7776 elsif Nkind (A) = N_Identifier then
7778 if Chars (A) = Name_All_Checks then
7779 Set_Default_Style_Check_Options;
7781 elsif Chars (A) = Name_On then
7782 Style_Check := True;
7784 elsif Chars (A) = Name_Off then
7785 Style_Check := False;
7796 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
7798 when Pragma_Subtitle =>
7800 Check_Arg_Count (1);
7801 Check_Optional_Identifier (Arg1, Name_Subtitle);
7802 Check_Arg_Is_String_Literal (Arg1);
7808 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
7810 when Pragma_Suppress =>
7811 Process_Suppress_Unsuppress (True);
7817 -- pragma Suppress_All;
7819 -- The only check made here is that the pragma appears in the
7820 -- proper place, i.e. following a compilation unit. If indeed
7821 -- it appears in this context, then the parser has already
7822 -- inserted an equivalent pragma Suppress (All_Checks) to get
7823 -- the required effect.
7825 when Pragma_Suppress_All =>
7827 Check_Arg_Count (0);
7829 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7830 or else not Is_List_Member (N)
7831 or else List_Containing (N) /= Pragmas_After (Parent (N))
7834 ("misplaced pragma%, must follow compilation unit");
7837 -------------------------
7838 -- Suppress_Debug_Info --
7839 -------------------------
7841 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
7843 when Pragma_Suppress_Debug_Info =>
7845 Check_Arg_Count (1);
7846 Check_Arg_Is_Local_Name (Arg1);
7847 Check_Optional_Identifier (Arg1, Name_Entity);
7848 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
7850 -----------------------------
7851 -- Suppress_Initialization --
7852 -----------------------------
7854 -- pragma Suppress_Initialization ([Entity =>] type_Name);
7856 when Pragma_Suppress_Initialization => Suppress_Init : declare
7862 Check_Arg_Count (1);
7863 Check_Optional_Identifier (Arg1, Name_Entity);
7864 Check_Arg_Is_Local_Name (Arg1);
7866 E_Id := Expression (Arg1);
7868 if Etype (E_Id) = Any_Type then
7875 if Is_Incomplete_Or_Private_Type (E) then
7876 if No (Full_View (Base_Type (E))) then
7878 ("argument of pragma% cannot be an incomplete type",
7881 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
7884 Set_Suppress_Init_Proc (Base_Type (E));
7889 ("pragma% requires argument that is a type name", Arg1);
7897 -- pragma System_Name (DIRECT_NAME);
7899 -- Syntax check: one argument, which must be the identifier GNAT
7900 -- or the identifier GCC, no other identifiers are acceptable.
7902 when Pragma_System_Name =>
7903 Check_No_Identifiers;
7904 Check_Arg_Count (1);
7905 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
7907 -----------------------------
7908 -- Task_Dispatching_Policy --
7909 -----------------------------
7911 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
7913 when Pragma_Task_Dispatching_Policy => declare
7917 Check_Ada_83_Warning;
7918 Check_Arg_Count (1);
7919 Check_No_Identifiers;
7920 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
7921 Check_Valid_Configuration_Pragma;
7922 Get_Name_String (Chars (Expression (Arg1)));
7923 DP := Fold_Upper (Name_Buffer (1));
7925 if Task_Dispatching_Policy /= ' '
7926 and then Task_Dispatching_Policy /= DP
7928 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
7930 ("task dispatching policy incompatible with policy#");
7932 Task_Dispatching_Policy := DP;
7933 Task_Dispatching_Policy_Sloc := Loc;
7941 -- pragma Task_Info (EXPRESSION);
7943 when Pragma_Task_Info => Task_Info : declare
7944 P : constant Node_Id := Parent (N);
7949 if Nkind (P) /= N_Task_Definition then
7950 Error_Pragma ("pragma% must appear in task definition");
7953 Check_No_Identifiers;
7954 Check_Arg_Count (1);
7956 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
7958 if Etype (Expression (Arg1)) = Any_Type then
7962 if Has_Task_Info_Pragma (P) then
7963 Error_Pragma ("duplicate pragma% not allowed");
7965 Set_Has_Task_Info_Pragma (P, True);
7974 -- pragma Task_Name (string_EXPRESSION);
7976 when Pragma_Task_Name => Task_Name : declare
7977 -- pragma Priority (EXPRESSION);
7979 P : constant Node_Id := Parent (N);
7983 Check_No_Identifiers;
7984 Check_Arg_Count (1);
7986 Arg := Expression (Arg1);
7987 Analyze_And_Resolve (Arg, Standard_String);
7989 if Nkind (P) /= N_Task_Definition then
7993 if Has_Task_Name_Pragma (P) then
7994 Error_Pragma ("duplicate pragma% not allowed");
7996 Set_Has_Task_Name_Pragma (P, True);
7997 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8006 -- pragma Task_Storage (
8007 -- [Task_Type =>] LOCAL_NAME,
8008 -- [Top_Guard =>] static_integer_EXPRESSION);
8010 when Pragma_Task_Storage => Task_Storage : declare
8011 Args : Args_List (1 .. 2);
8012 Names : Name_List (1 .. 2) := (
8016 Task_Type : Node_Id renames Args (1);
8017 Top_Guard : Node_Id renames Args (2);
8023 Gather_Associations (Names, Args);
8024 Check_Arg_Is_Local_Name (Task_Type);
8026 Ent := Entity (Task_Type);
8028 if not Is_Task_Type (Ent) then
8030 ("argument for pragma% must be task type", Task_Type);
8033 if No (Top_Guard) then
8035 ("pragma% takes two arguments", Task_Type);
8037 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
8040 Check_First_Subtype (Task_Type);
8042 if Rep_Item_Too_Late (Ent, N) then
8052 -- pragma Time_Slice (static_duration_EXPRESSION);
8054 when Pragma_Time_Slice => Time_Slice : declare
8060 Check_Arg_Count (1);
8061 Check_No_Identifiers;
8062 Check_In_Main_Program;
8063 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
8065 if not Error_Posted (Arg1) then
8067 while Present (Nod) loop
8068 if Nkind (Nod) = N_Pragma
8069 and then Chars (Nod) = Name_Time_Slice
8071 Error_Msg_Name_1 := Chars (N);
8072 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8079 -- Process only if in main unit
8081 if Get_Source_Unit (Loc) = Main_Unit then
8082 Opt.Time_Slice_Set := True;
8083 Val := Expr_Value_R (Expression (Arg1));
8085 if Val <= Ureal_0 then
8086 Opt.Time_Slice_Value := 0;
8088 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
8089 Opt.Time_Slice_Value := 1_000_000_000;
8092 Opt.Time_Slice_Value :=
8093 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
8102 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
8104 -- TITLING_OPTION ::=
8105 -- [Title =>] STRING_LITERAL
8106 -- | [Subtitle =>] STRING_LITERAL
8108 when Pragma_Title => Title : declare
8109 Args : Args_List (1 .. 2);
8110 Names : Name_List (1 .. 2) := (
8116 Gather_Associations (Names, Args);
8118 for J in 1 .. 2 loop
8119 if Present (Args (J)) then
8120 Check_Arg_Is_String_Literal (Args (J));
8125 ---------------------
8126 -- Unchecked_Union --
8127 ---------------------
8129 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
8131 when Pragma_Unchecked_Union => Unchecked_Union : declare
8132 Assoc : Node_Id := Arg1;
8133 Type_Id : Node_Id := Expression (Assoc);
8144 Check_No_Identifiers;
8145 Check_Arg_Count (1);
8146 Check_Arg_Is_Local_Name (Arg1);
8148 Find_Type (Type_Id);
8149 Typ := Entity (Type_Id);
8152 or else Rep_Item_Too_Early (Typ, N)
8156 Typ := Underlying_Type (Typ);
8159 if Rep_Item_Too_Late (Typ, N) then
8163 Check_First_Subtype (Arg1);
8165 -- Note remaining cases are references to a type in the current
8166 -- declarative part. If we find an error, we post the error on
8167 -- the relevant type declaration at an appropriate point.
8169 if not Is_Record_Type (Typ) then
8170 Error_Msg_N ("Unchecked_Union must be record type", Typ);
8173 elsif Is_Tagged_Type (Typ) then
8174 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
8177 elsif Is_Limited_Type (Typ) then
8179 ("Unchecked_Union must not be limited record type", Typ);
8183 if not Has_Discriminants (Typ) then
8185 ("Unchecked_Union must have one discriminant", Typ);
8189 Discr := First_Discriminant (Typ);
8191 if Present (Next_Discriminant (Discr)) then
8193 ("Unchecked_Union must have exactly one discriminant",
8194 Next_Discriminant (Discr));
8198 if No (Discriminant_Default_Value (Discr)) then
8200 ("Unchecked_Union discriminant must have default value",
8204 Tdef := Type_Definition (Declaration_Node (Typ));
8205 Clist := Component_List (Tdef);
8207 if No (Clist) or else No (Variant_Part (Clist)) then
8209 ("Unchecked_Union must have variant part",
8214 Vpart := Variant_Part (Clist);
8216 if Is_Non_Empty_List (Component_Items (Clist)) then
8218 ("components before variant not allowed " &
8219 "in Unchecked_Union",
8220 First (Component_Items (Clist)));
8223 Variant := First (Variants (Vpart));
8224 while Present (Variant) loop
8225 Clist := Component_List (Variant);
8227 if Present (Variant_Part (Clist)) then
8229 ("Unchecked_Union may not have nested variants",
8230 Variant_Part (Clist));
8233 if not Is_Non_Empty_List (Component_Items (Clist)) then
8235 ("Unchecked_Union may not have empty component list",
8240 Comp := First (Component_Items (Clist));
8242 if Nkind (Comp) = N_Component_Declaration then
8244 if Present (Expression (Comp)) then
8246 ("default initialization not allowed " &
8247 "in Unchecked_Union",
8252 Sindic : constant Node_Id :=
8253 Subtype_Indication (Comp);
8256 if Nkind (Sindic) = N_Subtype_Indication then
8257 Check_Static_Constraint (Constraint (Sindic));
8262 if Present (Next (Comp)) then
8264 ("Unchecked_Union variant can have only one component",
8272 Set_Is_Unchecked_Union (Typ, True);
8273 Set_Suppress_Discriminant_Checks (Typ, True);
8274 Set_Convention (Typ, Convention_C);
8276 Set_Has_Unchecked_Union (Base_Type (Typ), True);
8277 Set_Is_Unchecked_Union (Base_Type (Typ), True);
8279 end Unchecked_Union;
8281 ------------------------
8282 -- Unimplemented_Unit --
8283 ------------------------
8285 -- pragma Unimplemented_Unit;
8287 -- Note: this only gives an error if we are generating code,
8288 -- or if we are in a generic library unit (where the pragma
8289 -- appears in the body, not in the spec).
8291 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
8292 Cunitent : Entity_Id := Cunit_Entity (Get_Source_Unit (Loc));
8293 Ent_Kind : Entity_Kind := Ekind (Cunitent);
8297 Check_Arg_Count (0);
8299 if Operating_Mode = Generate_Code
8300 or else Ent_Kind = E_Generic_Function
8301 or else Ent_Kind = E_Generic_Procedure
8302 or else Ent_Kind = E_Generic_Package
8304 Get_Name_String (Chars (Cunitent));
8305 Set_Casing (Mixed_Case);
8306 Write_Str (Name_Buffer (1 .. Name_Len));
8307 Write_Str (" is not implemented");
8309 raise Unrecoverable_Error;
8311 end Unimplemented_Unit;
8313 ------------------------------
8314 -- Unreserve_All_Interrupts --
8315 ------------------------------
8317 -- pragma Unreserve_All_Interrupts;
8319 when Pragma_Unreserve_All_Interrupts =>
8321 Check_Arg_Count (0);
8323 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
8324 Unreserve_All_Interrupts := True;
8331 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
8333 when Pragma_Unsuppress =>
8335 Process_Suppress_Unsuppress (False);
8341 -- pragma Use_VADS_Size;
8343 when Pragma_Use_VADS_Size =>
8345 Check_Arg_Count (0);
8346 Check_Valid_Configuration_Pragma;
8347 Use_VADS_Size := True;
8349 ---------------------
8350 -- Validity_Checks --
8351 ---------------------
8353 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
8355 when Pragma_Validity_Checks => Validity_Checks : declare
8356 A : constant Node_Id := Expression (Arg1);
8362 Check_Arg_Count (1);
8363 Check_Valid_Configuration_Pragma;
8364 Check_No_Identifiers;
8366 if Nkind (A) = N_String_Literal then
8370 Slen : Natural := Natural (String_Length (S));
8371 Options : String (1 .. Slen);
8377 C := Get_String_Char (S, Int (J));
8378 exit when not In_Character_Range (C);
8379 Options (J) := Get_Character (C);
8382 Set_Validity_Check_Options (Options);
8390 elsif Nkind (A) = N_Identifier then
8392 if Chars (A) = Name_All_Checks then
8393 Set_Validity_Check_Options ("a");
8395 elsif Chars (A) = Name_On then
8396 Validity_Checks_On := True;
8398 elsif Chars (A) = Name_Off then
8399 Validity_Checks_On := False;
8403 end Validity_Checks;
8409 -- pragma Volatile (LOCAL_NAME);
8411 when Pragma_Volatile =>
8412 Process_Atomic_Shared_Volatile;
8414 -------------------------
8415 -- Volatile_Components --
8416 -------------------------
8418 -- pragma Volatile_Components (array_LOCAL_NAME);
8420 -- Volatile is handled by the same circuit as Atomic_Components
8426 -- pragma Warnings (On | Off, [LOCAL_NAME])
8428 when Pragma_Warnings =>
8430 Check_At_Least_N_Arguments (1);
8431 Check_At_Most_N_Arguments (2);
8432 Check_No_Identifiers;
8434 -- One argument case was processed by parser in Par.Prag
8436 if Arg_Count /= 1 then
8437 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8438 Check_Arg_Count (2);
8445 E_Id := Expression (Arg2);
8448 if not Is_Entity_Name (E_Id) then
8450 ("second argument of pragma% must be entity name",
8460 Set_Warnings_Off (E,
8461 (Chars (Expression (Arg1)) = Name_Off));
8463 if Is_Enumeration_Type (E) then
8465 Lit : Entity_Id := First_Literal (E);
8468 while Present (Lit) loop
8469 Set_Warnings_Off (Lit);
8475 exit when No (Homonym (E));
8486 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
8488 when Pragma_Weak_External => Weak_External : declare
8493 Check_Arg_Count (1);
8494 Check_Optional_Identifier (Arg1, Name_Entity);
8495 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8496 Ent := Entity (Expression (Arg1));
8498 if Rep_Item_Too_Early (Ent, N) then
8501 Ent := Underlying_Type (Ent);
8504 -- The only processing required is to link this item on to the
8505 -- list of rep items for the given entity. This is accomplished
8506 -- by the call to Rep_Item_Too_Late (when no error is detected
8507 -- and False is returned).
8509 if Rep_Item_Too_Late (Ent, N) then
8512 Set_Has_Gigi_Rep_Item (Ent);
8519 when Pragma_Exit => null;
8523 -------------------------
8524 -- Get_Base_Subprogram --
8525 -------------------------
8527 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
8533 -- Follow subprogram renaming chain
8535 while Is_Subprogram (Result)
8537 (Is_Generic_Instance (Result)
8538 or else Nkind (Parent (Declaration_Node (Result))) =
8539 N_Subprogram_Renaming_Declaration)
8540 and then Present (Alias (Result))
8542 Result := Alias (Result);
8546 end Get_Base_Subprogram;
8548 ---------------------------
8549 -- Is_Generic_Subprogram --
8550 ---------------------------
8552 function Is_Generic_Subprogram (Id : Entity_Id) return Boolean is
8554 return Ekind (Id) = E_Generic_Procedure
8555 or else Ekind (Id) = E_Generic_Function;
8556 end Is_Generic_Subprogram;
8558 ------------------------------
8559 -- Is_Pragma_String_Literal --
8560 ------------------------------
8562 -- This function returns true if the corresponding pragma argument is
8563 -- a static string expression. These are the only cases in which string
8564 -- literals can appear as pragma arguments. We also allow a string
8565 -- literal as the first argument to pragma Assert (although it will
8566 -- of course always generate a type error).
8568 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
8569 Pragn : constant Node_Id := Parent (Par);
8570 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
8571 Pname : constant Name_Id := Chars (Pragn);
8584 if Pname = Name_Assert then
8587 elsif Pname = Name_Export then
8590 elsif Pname = Name_Ident then
8593 elsif Pname = Name_Import then
8596 elsif Pname = Name_Interface_Name then
8599 elsif Pname = Name_Linker_Alias then
8602 elsif Pname = Name_Linker_Section then
8605 elsif Pname = Name_Machine_Attribute then
8608 elsif Pname = Name_Source_File_Name then
8611 elsif Pname = Name_Source_Reference then
8614 elsif Pname = Name_Title then
8617 elsif Pname = Name_Subtitle then
8624 end Is_Pragma_String_Literal;
8626 --------------------------------------
8627 -- Process_Compilation_Unit_Pragmas --
8628 --------------------------------------
8630 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
8632 -- A special check for pragma Suppress_All. This is a strange DEC
8633 -- pragma, strange because it comes at the end of the unit. If we
8634 -- have a pragma Suppress_All in the Pragmas_After of the current
8635 -- unit, then we insert a pragma Suppress (All_Checks) at the start
8636 -- of the context clause to ensure the correct processing.
8639 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
8643 if Present (PA) then
8645 while Present (P) loop
8646 if Chars (P) = Name_Suppress_All then
8647 Prepend_To (Context_Items (N),
8648 Make_Pragma (Sloc (P),
8649 Chars => Name_Suppress,
8650 Pragma_Argument_Associations => New_List (
8651 Make_Pragma_Argument_Association (Sloc (P),
8653 Make_Identifier (Sloc (P),
8654 Chars => Name_All_Checks)))));
8662 end Process_Compilation_Unit_Pragmas;
8664 --------------------------------
8665 -- Set_Encoded_Interface_Name --
8666 --------------------------------
8668 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
8669 Str : constant String_Id := Strval (S);
8670 Len : constant Int := String_Length (Str);
8675 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
8678 -- Stores encoded value of character code CC. The encoding we
8679 -- use an underscore followed by four lower case hex digits.
8683 Store_String_Char (Get_Char_Code ('_'));
8685 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
8687 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
8689 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
8691 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
8694 -- Start of processing for Set_Encoded_Interface_Name
8697 -- If first character is asterisk, this is a link name, and we
8698 -- leave it completely unmodified. We also ignore null strings
8699 -- (the latter case happens only in error cases) and no encoding
8700 -- should occur for Java interface names.
8703 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
8706 Set_Interface_Name (E, S);
8711 CC := Get_String_Char (Str, J);
8713 exit when not In_Character_Range (CC);
8715 C := Get_Character (CC);
8717 exit when C /= '_' and then C /= '$'
8718 and then C not in '0' .. '9'
8719 and then C not in 'a' .. 'z'
8720 and then C not in 'A' .. 'Z';
8723 Set_Interface_Name (E, S);
8731 -- Here we need to encode. The encoding we use as follows:
8732 -- three underscores + four hex digits (lower case)
8736 for J in 1 .. String_Length (Str) loop
8737 CC := Get_String_Char (Str, J);
8739 if not In_Character_Range (CC) then
8742 C := Get_Character (CC);
8744 if C = '_' or else C = '$'
8745 or else C in '0' .. '9'
8746 or else C in 'a' .. 'z'
8747 or else C in 'A' .. 'Z'
8749 Store_String_Char (CC);
8756 Set_Interface_Name (E,
8757 Make_String_Literal (Sloc (S),
8758 Strval => End_String));
8760 end Set_Encoded_Interface_Name;
8766 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
8771 if Nkind (N) = N_Identifier
8772 and then Nkind (With_Item) = N_Identifier
8774 Set_Entity (N, Entity (With_Item));
8776 elsif Nkind (N) = N_Selected_Component then
8777 Change_Selected_Component_To_Expanded_Name (N);
8778 Set_Entity (N, Entity (With_Item));
8779 Set_Entity (Selector_Name (N), Entity (N));
8782 Scop := Scope (Entity (N));
8784 while Nkind (Pref) = N_Selected_Component loop
8785 Change_Selected_Component_To_Expanded_Name (Pref);
8786 Set_Entity (Selector_Name (Pref), Scop);
8787 Set_Entity (Pref, Scop);
8788 Pref := Prefix (Pref);
8789 Scop := Scope (Scop);
8792 Set_Entity (Pref, Scop);