1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This unit contains the semantic processing for all pragmas, both language
28 -- and implementation defined. For most pragmas, the parser only does the
29 -- most basic job of checking the syntax, so Sem_Prag also contains the code
30 -- to complete the syntax checks. Certain pragmas are handled partially or
31 -- completely by the parser (see Par.Prag for further details).
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Hostparm; use Hostparm;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet; use Namet;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Restrict; use Restrict;
51 with Rident; use Rident;
52 with Rtsfind; use Rtsfind;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch13; use Sem_Ch13;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Dist; use Sem_Dist;
59 with Sem_Elim; use Sem_Elim;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Intr; use Sem_Intr;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Res; use Sem_Res;
64 with Sem_Type; use Sem_Type;
65 with Sem_Util; use Sem_Util;
66 with Sem_VFpt; use Sem_VFpt;
67 with Sem_Warn; use Sem_Warn;
68 with Stand; use Stand;
69 with Sinfo; use Sinfo;
70 with Sinfo.CN; use Sinfo.CN;
71 with Sinput; use Sinput;
72 with Snames; use Snames;
73 with Stringt; use Stringt;
74 with Stylesw; use Stylesw;
76 with Targparm; use Targparm;
77 with Tbuild; use Tbuild;
79 with Uintp; use Uintp;
80 with Urealp; use Urealp;
81 with Validsw; use Validsw;
83 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
85 package body Sem_Prag is
87 ----------------------------------------------
88 -- Common Handling of Import-Export Pragmas --
89 ----------------------------------------------
91 -- In the following section, a number of Import_xxx and Export_xxx
92 -- pragmas are defined by GNAT. These are compatible with the DEC
93 -- pragmas of the same name, and all have the following common
94 -- form and processing:
97 -- [Internal =>] LOCAL_NAME,
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
102 -- [Internal =>] LOCAL_NAME,
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
106 -- EXTERNAL_SYMBOL ::=
108 -- | static_string_EXPRESSION
110 -- The internal LOCAL_NAME designates the entity that is imported or
111 -- exported, and must refer to an entity in the current declarative
112 -- part (as required by the rules for LOCAL_NAME).
114 -- The external linker name is designated by the External parameter
115 -- if given, or the Internal parameter if not (if there is no External
116 -- parameter, the External parameter is a copy of the Internal name).
118 -- If the External parameter is given as a string, then this string
119 -- is treated as an external name (exactly as though it had been given
120 -- as an External_Name parameter for a normal Import pragma).
122 -- If the External parameter is given as an identifier (or there is no
123 -- External parameter, so that the Internal identifier is used), then
124 -- the external name is the characters of the identifier, translated
125 -- to all upper case letters for OpenVMS versions of GNAT, and to all
126 -- lower case letters for all other versions
128 -- Note: the external name specified or implied by any of these special
129 -- Import_xxx or Export_xxx pragmas override an external or link name
130 -- specified in a previous Import or Export pragma.
132 -- Note: these and all other DEC-compatible GNAT pragmas allow full
133 -- use of named notation, following the standard rules for subprogram
134 -- calls, i.e. parameters can be given in any order if named notation
135 -- is used, and positional and named notation can be mixed, subject to
136 -- the rule that all positional parameters must appear first.
138 -- Note: All these pragmas are implemented exactly following the DEC
139 -- design and implementation and are intended to be fully compatible
140 -- with the use of these pragmas in the DEC Ada compiler.
142 --------------------------------------------
143 -- Checking for Duplicated External Names --
144 --------------------------------------------
146 -- It is suspicious if two separate Export pragmas use the same external
147 -- name. The following table is used to diagnose this situation so that
148 -- an appropriate warning can be issued.
150 -- The Node_Id stored is for the N_String_Literal node created to
151 -- hold the value of the external name. The Sloc of this node is
152 -- used to cross-reference the location of the duplication.
154 package Externals is new Table.Table (
155 Table_Component_Type => Node_Id,
156 Table_Index_Type => Int,
157 Table_Low_Bound => 0,
158 Table_Initial => 100,
159 Table_Increment => 100,
160 Table_Name => "Name_Externals");
162 -------------------------------------
163 -- Local Subprograms and Variables --
164 -------------------------------------
166 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
167 -- This routine is used for possible casing adjustment of an explicit
168 -- external name supplied as a string literal (the node N), according
169 -- to the casing requirement of Opt.External_Name_Casing. If this is
170 -- set to As_Is, then the string literal is returned unchanged, but if
171 -- it is set to Uppercase or Lowercase, then a new string literal with
172 -- appropriate casing is constructed.
174 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
175 -- If Def_Id refers to a renamed subprogram, then the base subprogram
176 -- (the original one, following the renaming chain) is returned.
177 -- Otherwise the entity is returned unchanged. Should be in Einfo???
179 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
180 -- Place semantic information on the argument of an Elaborate or
181 -- Elaborate_All pragma. Entity name for unit and its parents is
182 -- taken from item in previous with_clause that mentions the unit.
184 -------------------------------
185 -- Adjust_External_Name_Case --
186 -------------------------------
188 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
192 -- Adjust case of literal if required
194 if Opt.External_Name_Exp_Casing = As_Is then
198 -- Copy existing string
204 for J in 1 .. String_Length (Strval (N)) loop
205 CC := Get_String_Char (Strval (N), J);
207 if Opt.External_Name_Exp_Casing = Uppercase
208 and then CC >= Get_Char_Code ('a')
209 and then CC <= Get_Char_Code ('z')
211 Store_String_Char (CC - 32);
213 elsif Opt.External_Name_Exp_Casing = Lowercase
214 and then CC >= Get_Char_Code ('A')
215 and then CC <= Get_Char_Code ('Z')
217 Store_String_Char (CC + 32);
220 Store_String_Char (CC);
225 Make_String_Literal (Sloc (N),
226 Strval => End_String);
228 end Adjust_External_Name_Case;
234 procedure Analyze_Pragma (N : Node_Id) is
235 Loc : constant Source_Ptr := Sloc (N);
238 Pragma_Exit : exception;
239 -- This exception is used to exit pragma processing completely. It
240 -- is used when an error is detected, and no further processing is
241 -- required. It is also used if an earlier error has left the tree
242 -- in a state where the pragma should not be processed.
245 -- Number of pragma argument associations
251 -- First four pragma arguments (pragma argument association nodes,
252 -- or Empty if the corresponding argument does not exist).
254 type Name_List is array (Natural range <>) of Name_Id;
255 type Args_List is array (Natural range <>) of Node_Id;
256 -- Types used for arguments to Check_Arg_Order and Gather_Associations
258 procedure Check_Ada_83_Warning;
259 -- Issues a warning message for the current pragma if operating in Ada
260 -- 83 mode (used for language pragmas that are not a standard part of
261 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
264 procedure Check_Arg_Count (Required : Nat);
265 -- Check argument count for pragma is equal to given parameter.
266 -- If not, then issue an error message and raise Pragma_Exit.
268 -- Note: all routines whose name is Check_Arg_Is_xxx take an
269 -- argument Arg which can either be a pragma argument association,
270 -- in which case the check is applied to the expression of the
271 -- association or an expression directly.
273 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
274 -- Check that an argument has the right form for an EXTERNAL_NAME
275 -- parameter of an extended import/export pragma. The rule is that
276 -- the name must be an identifier or string literal (in Ada 83 mode)
277 -- or a static string expression (in Ada 95 mode).
279 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
280 -- Check the specified argument Arg to make sure that it is an
281 -- identifier. If not give error and raise Pragma_Exit.
283 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
284 -- Check the specified argument Arg to make sure that it is an
285 -- integer literal. If not give error and raise Pragma_Exit.
287 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
288 -- Check the specified argument Arg to make sure that it has the
289 -- proper syntactic form for a local name and meets the semantic
290 -- requirements for a local name. The local name is analyzed as
291 -- part of the processing for this call. In addition, the local
292 -- name is required to represent an entity at the library level.
294 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
295 -- Check the specified argument Arg to make sure that it has the
296 -- proper syntactic form for a local name and meets the semantic
297 -- requirements for a local name. The local name is analyzed as
298 -- part of the processing for this call.
300 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
301 -- Check the specified argument Arg to make sure that it is a valid
302 -- locking policy name. If not give error and raise Pragma_Exit.
304 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
305 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
306 -- Check the specified argument Arg to make sure that it is an
307 -- identifier whose name matches either N1 or N2 (or N3 if present).
308 -- If not then give error and raise Pragma_Exit.
310 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
311 -- Check the specified argument Arg to make sure that it is a valid
312 -- queuing policy name. If not give error and raise Pragma_Exit.
314 procedure Check_Arg_Is_Static_Expression
317 -- Check the specified argument Arg to make sure that it is a static
318 -- expression of the given type (i.e. it will be analyzed and resolved
319 -- using this type, which can be any valid argument to Resolve, e.g.
320 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
322 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
323 -- Check the specified argument Arg to make sure that it is a
324 -- string literal. If not give error and raise Pragma_Exit
326 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
327 -- Check the specified argument Arg to make sure that it is a valid
328 -- valid task dispatching policy name. If not give error and raise
331 procedure Check_Arg_Order (Names : Name_List);
332 -- Checks for an instance of two arguments with identifiers for the
333 -- current pragma which are not in the sequence indicated by Names,
334 -- and if so, generates a fatal message about bad order of arguments.
336 procedure Check_At_Least_N_Arguments (N : Nat);
337 -- Check there are at least N arguments present
339 procedure Check_At_Most_N_Arguments (N : Nat);
340 -- Check there are no more than N arguments present
342 procedure Check_Component (Comp : Node_Id);
343 -- Examine Unchecked_Union component for correct use of per-object
344 -- constrained subtypes.
346 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
347 -- Nam is an N_String_Literal node containing the external name set
348 -- by an Import or Export pragma (or extended Import or Export pragma).
349 -- This procedure checks for possible duplications if this is the
350 -- export case, and if found, issues an appropriate error message.
352 procedure Check_First_Subtype (Arg : Node_Id);
353 -- Checks that Arg, whose expression is an entity name referencing
354 -- a subtype, does not reference a type that is not a first subtype.
356 procedure Check_In_Main_Program;
357 -- Common checks for pragmas that appear within a main program
358 -- (Priority, Main_Storage, Time_Slice).
360 procedure Check_Interrupt_Or_Attach_Handler;
361 -- Common processing for first argument of pragma Interrupt_Handler
362 -- or pragma Attach_Handler.
364 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
365 -- Check that pragma appears in a declarative part, or in a package
366 -- specification, i.e. that it does not occur in a statement sequence
369 procedure Check_No_Identifier (Arg : Node_Id);
370 -- Checks that the given argument does not have an identifier. If
371 -- an identifier is present, then an error message is issued, and
372 -- Pragma_Exit is raised.
374 procedure Check_No_Identifiers;
375 -- Checks that none of the arguments to the pragma has an identifier.
376 -- If any argument has an identifier, then an error message is issued,
377 -- and Pragma_Exit is raised.
379 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
380 -- Checks if the given argument has an identifier, and if so, requires
381 -- it to match the given identifier name. If there is a non-matching
382 -- identifier, then an error message is given and Error_Pragmas raised.
384 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
385 -- Checks if the given argument has an identifier, and if so, requires
386 -- it to match the given identifier name. If there is a non-matching
387 -- identifier, then an error message is given and Error_Pragmas raised.
388 -- In this version of the procedure, the identifier name is given as
389 -- a string with lower case letters.
391 procedure Check_Static_Constraint (Constr : Node_Id);
392 -- Constr is a constraint from an N_Subtype_Indication node from a
393 -- component constraint in an Unchecked_Union type. This routine checks
394 -- that the constraint is static as required by the restrictions for
397 procedure Check_Valid_Configuration_Pragma;
398 -- Legality checks for placement of a configuration pragma
400 procedure Check_Valid_Library_Unit_Pragma;
401 -- Legality checks for library unit pragmas. A special case arises for
402 -- pragmas in generic instances that come from copies of the original
403 -- library unit pragmas in the generic templates. In the case of other
404 -- than library level instantiations these can appear in contexts which
405 -- would normally be invalid (they only apply to the original template
406 -- and to library level instantiations), and they are simply ignored,
407 -- which is implemented by rewriting them as null statements.
409 procedure Check_Variant (Variant : Node_Id);
410 -- Check Unchecked_Union variant for lack of nested variants and
411 -- presence of at least one component.
413 procedure Error_Pragma (Msg : String);
414 pragma No_Return (Error_Pragma);
415 -- Outputs error message for current pragma. The message contains an %
416 -- that will be replaced with the pragma name, and the flag is placed
417 -- on the pragma itself. Pragma_Exit is then raised.
419 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
420 pragma No_Return (Error_Pragma_Arg);
421 -- Outputs error message for current pragma. The message may contain
422 -- a % that will be replaced with the pragma name. The parameter Arg
423 -- may either be a pragma argument association, in which case the flag
424 -- is placed on the expression of this association, or an expression,
425 -- in which case the flag is placed directly on the expression. The
426 -- message is placed using Error_Msg_N, so the message may also contain
427 -- an & insertion character which will reference the given Arg value.
428 -- After placing the message, Pragma_Exit is raised.
430 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
431 pragma No_Return (Error_Pragma_Arg);
432 -- Similar to above form of Error_Pragma_Arg except that two messages
433 -- are provided, the second is a continuation comment starting with \.
435 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
436 pragma No_Return (Error_Pragma_Arg_Ident);
437 -- Outputs error message for current pragma. The message may contain
438 -- a % that will be replaced with the pragma name. The parameter Arg
439 -- must be a pragma argument association with a non-empty identifier
440 -- (i.e. its Chars field must be set), and the error message is placed
441 -- on the identifier. The message is placed using Error_Msg_N so
442 -- the message may also contain an & insertion character which will
443 -- reference the identifier. After placing the message, Pragma_Exit
446 function Find_Lib_Unit_Name return Entity_Id;
447 -- Used for a library unit pragma to find the entity to which the
448 -- library unit pragma applies, returns the entity found.
450 procedure Find_Program_Unit_Name (Id : Node_Id);
451 -- If the pragma is a compilation unit pragma, the id must denote the
452 -- compilation unit in the same compilation, and the pragma must appear
453 -- in the list of preceding or trailing pragmas. If it is a program
454 -- unit pragma that is not a compilation unit pragma, then the
455 -- identifier must be visible.
457 function Find_Unique_Parameterless_Procedure
459 Arg : Node_Id) return Entity_Id;
460 -- Used for a procedure pragma to find the unique parameterless
461 -- procedure identified by Name, returns it if it exists, otherwise
462 -- errors out and uses Arg as the pragma argument for the message.
464 procedure Gather_Associations
466 Args : out Args_List);
467 -- This procedure is used to gather the arguments for a pragma that
468 -- permits arbitrary ordering of parameters using the normal rules
469 -- for named and positional parameters. The Names argument is a list
470 -- of Name_Id values that corresponds to the allowed pragma argument
471 -- association identifiers in order. The result returned in Args is
472 -- a list of corresponding expressions that are the pragma arguments.
473 -- Note that this is a list of expressions, not of pragma argument
474 -- associations (Gather_Associations has completely checked all the
475 -- optional identifiers when it returns). An entry in Args is Empty
476 -- on return if the corresponding argument is not present.
478 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
479 -- All the routines that check pragma arguments take either a pragma
480 -- argument association (in which case the expression of the argument
481 -- association is checked), or the expression directly. The function
482 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
483 -- Arg is a pragma argument association node, then its expression is
484 -- returned, otherwise Arg is returned unchanged.
486 procedure GNAT_Pragma;
487 -- Called for all GNAT defined pragmas to note the use of the feature,
488 -- and also check the relevant restriction (No_Implementation_Pragmas).
490 function Is_Before_First_Decl
491 (Pragma_Node : Node_Id;
492 Decls : List_Id) return Boolean;
493 -- Return True if Pragma_Node is before the first declarative item in
494 -- Decls where Decls is the list of declarative items.
496 function Is_Configuration_Pragma return Boolean;
497 -- Deterermines if the placement of the current pragma is appropriate
498 -- for a configuration pragma (precedes the current compilation unit)
500 procedure Pragma_Misplaced;
501 -- Issue fatal error message for misplaced pragma
503 procedure Process_Atomic_Shared_Volatile;
504 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
505 -- Shared is an obsolete Ada 83 pragma, treated as being identical
506 -- in effect to pragma Atomic.
508 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
509 -- Common procesing for Convention, Interface, Import and Export.
510 -- Checks first two arguments of pragma, and sets the appropriate
511 -- convention value in the specified entity or entities. On return
512 -- C is the convention, E is the referenced entity.
514 procedure Process_Extended_Import_Export_Exception_Pragma
515 (Arg_Internal : Node_Id;
516 Arg_External : Node_Id;
519 -- Common processing for the pragmas Import/Export_Exception.
520 -- The three arguments correspond to the three named parameters of
521 -- the pragma. An argument is empty if the corresponding parameter
522 -- is not present in the pragma.
524 procedure Process_Extended_Import_Export_Object_Pragma
525 (Arg_Internal : Node_Id;
526 Arg_External : Node_Id;
528 -- Common processing for the pragmass Import/Export_Object.
529 -- The three arguments correspond to the three named parameters
530 -- of the pragmas. An argument is empty if the corresponding
531 -- parameter is not present in the pragma.
533 procedure Process_Extended_Import_Export_Internal_Arg
534 (Arg_Internal : Node_Id := Empty);
535 -- Common processing for all extended Import and Export pragmas. The
536 -- argument is the pragma parameter for the Internal argument. If
537 -- Arg_Internal is empty or inappropriate, an error message is posted.
538 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
539 -- set to identify the referenced entity.
541 procedure Process_Extended_Import_Export_Subprogram_Pragma
542 (Arg_Internal : Node_Id;
543 Arg_External : Node_Id;
544 Arg_Parameter_Types : Node_Id;
545 Arg_Result_Type : Node_Id := Empty;
546 Arg_Mechanism : Node_Id;
547 Arg_Result_Mechanism : Node_Id := Empty;
548 Arg_First_Optional_Parameter : Node_Id := Empty);
549 -- Common processing for all extended Import and Export pragmas
550 -- applying to subprograms. The caller omits any arguments that do
551 -- bnot apply to the pragma in question (for example, Arg_Result_Type
552 -- can be non-Empty only in the Import_Function and Export_Function
553 -- cases). The argument names correspond to the allowed pragma
554 -- association identifiers.
556 procedure Process_Generic_List;
557 -- Common processing for Share_Generic and Inline_Generic
559 procedure Process_Import_Or_Interface;
560 -- Common processing for Import of Interface
562 procedure Process_Inline (Active : Boolean);
563 -- Common processing for Inline and Inline_Always. The parameter
564 -- indicates if the inline pragma is active, i.e. if it should
565 -- actually cause inlining to occur.
567 procedure Process_Interface_Name
568 (Subprogram_Def : Entity_Id;
571 -- Given the last two arguments of pragma Import, pragma Export, or
572 -- pragma Interface_Name, performs validity checks and sets the
573 -- Interface_Name field of the given subprogram entity to the
574 -- appropriate external or link name, depending on the arguments
575 -- given. Ext_Arg is always present, but Link_Arg may be missing.
576 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
577 -- missing, and appropriate named notation is used for Ext_Arg.
578 -- If neither Ext_Arg nor Link_Arg is present, the interface name
579 -- is set to the default from the subprogram name.
581 procedure Process_Interrupt_Or_Attach_Handler;
582 -- Common processing for Interrupt and Attach_Handler pragmas
584 procedure Process_Restrictions_Or_Restriction_Warnings;
585 -- Common processing for Restrictions and Restriction_Warnings pragmas
587 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
588 -- Common processing for Suppress and Unsuppress. The boolean parameter
589 -- Suppress_Case is True for the Suppress case, and False for the
592 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
593 -- This procedure sets the Is_Exported flag for the given entity,
594 -- checking that the entity was not previously imported. Arg is
595 -- the argument that specified the entity. A check is also made
596 -- for exporting inappropriate entities.
598 procedure Set_Extended_Import_Export_External_Name
599 (Internal_Ent : Entity_Id;
600 Arg_External : Node_Id);
601 -- Common processing for all extended import export pragmas. The first
602 -- argument, Internal_Ent, is the internal entity, which has already
603 -- been checked for validity by the caller. Arg_External is from the
604 -- Import or Export pragma, and may be null if no External parameter
605 -- was present. If Arg_External is present and is a non-null string
606 -- (a null string is treated as the default), then the Interface_Name
607 -- field of Internal_Ent is set appropriately.
609 procedure Set_Imported (E : Entity_Id);
610 -- This procedure sets the Is_Imported flag for the given entity,
611 -- checking that it is not previously exported or imported.
613 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
614 -- Mech is a parameter passing mechanism (see Import_Function syntax
615 -- for MECHANISM_NAME). This routine checks that the mechanism argument
616 -- has the right form, and if not issues an error message. If the
617 -- argument has the right form then the Mechanism field of Ent is
618 -- set appropriately.
620 procedure Set_Ravenscar_Profile (N : Node_Id);
621 -- Activate the set of configuration pragmas and restrictions that
622 -- make up the Ravenscar Profile. N is the corresponding pragma
623 -- node, which is used for error messages on any constructs
624 -- that violate the profile.
626 --------------------------
627 -- Check_Ada_83_Warning --
628 --------------------------
630 procedure Check_Ada_83_Warning is
632 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
633 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
635 end Check_Ada_83_Warning;
637 ---------------------
638 -- Check_Arg_Count --
639 ---------------------
641 procedure Check_Arg_Count (Required : Nat) is
643 if Arg_Count /= Required then
644 Error_Pragma ("wrong number of arguments for pragma%");
648 --------------------------------
649 -- Check_Arg_Is_External_Name --
650 --------------------------------
652 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
653 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
656 if Nkind (Argx) = N_Identifier then
660 Analyze_And_Resolve (Argx, Standard_String);
662 if Is_OK_Static_Expression (Argx) then
665 elsif Etype (Argx) = Any_Type then
668 -- An interesting special case, if we have a string literal and
669 -- we are in Ada 83 mode, then we allow it even though it will
670 -- not be flagged as static. This allows expected Ada 83 mode
671 -- use of external names which are string literals, even though
672 -- technically these are not static in Ada 83.
674 elsif Ada_Version = Ada_83
675 and then Nkind (Argx) = N_String_Literal
679 -- Static expression that raises Constraint_Error. This has
680 -- already been flagged, so just exit from pragma processing.
682 elsif Is_Static_Expression (Argx) then
685 -- Here we have a real error (non-static expression)
688 Error_Msg_Name_1 := Chars (N);
690 ("argument for pragma% must be a identifier or " &
691 "static string expression!", Argx);
695 end Check_Arg_Is_External_Name;
697 -----------------------------
698 -- Check_Arg_Is_Identifier --
699 -----------------------------
701 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
702 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
704 if Nkind (Argx) /= N_Identifier then
706 ("argument for pragma% must be identifier", Argx);
708 end Check_Arg_Is_Identifier;
710 ----------------------------------
711 -- Check_Arg_Is_Integer_Literal --
712 ----------------------------------
714 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
715 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
717 if Nkind (Argx) /= N_Integer_Literal then
719 ("argument for pragma% must be integer literal", Argx);
721 end Check_Arg_Is_Integer_Literal;
723 -------------------------------------------
724 -- Check_Arg_Is_Library_Level_Local_Name --
725 -------------------------------------------
729 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
730 -- | library_unit_NAME
732 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
734 Check_Arg_Is_Local_Name (Arg);
736 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
737 and then Comes_From_Source (N)
740 ("argument for pragma% must be library level entity", Arg);
742 end Check_Arg_Is_Library_Level_Local_Name;
744 -----------------------------
745 -- Check_Arg_Is_Local_Name --
746 -----------------------------
750 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
751 -- | library_unit_NAME
753 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
754 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
759 if Nkind (Argx) not in N_Direct_Name
760 and then (Nkind (Argx) /= N_Attribute_Reference
761 or else Present (Expressions (Argx))
762 or else Nkind (Prefix (Argx)) /= N_Identifier)
763 and then (not Is_Entity_Name (Argx)
764 or else not Is_Compilation_Unit (Entity (Argx)))
766 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
769 if Is_Entity_Name (Argx)
770 and then Scope (Entity (Argx)) /= Current_Scope
773 ("pragma% argument must be in same declarative part", Arg);
775 end Check_Arg_Is_Local_Name;
777 ---------------------------------
778 -- Check_Arg_Is_Locking_Policy --
779 ---------------------------------
781 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
782 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
785 Check_Arg_Is_Identifier (Argx);
787 if not Is_Locking_Policy_Name (Chars (Argx)) then
789 ("& is not a valid locking policy name", Argx);
791 end Check_Arg_Is_Locking_Policy;
793 -------------------------
794 -- Check_Arg_Is_One_Of --
795 -------------------------
797 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
798 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
801 Check_Arg_Is_Identifier (Argx);
803 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
804 Error_Msg_Name_2 := N1;
805 Error_Msg_Name_3 := N2;
806 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
808 end Check_Arg_Is_One_Of;
810 procedure Check_Arg_Is_One_Of
812 N1, N2, N3 : Name_Id)
814 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
817 Check_Arg_Is_Identifier (Argx);
819 if Chars (Argx) /= N1
820 and then Chars (Argx) /= N2
821 and then Chars (Argx) /= N3
823 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
825 end Check_Arg_Is_One_Of;
827 ---------------------------------
828 -- Check_Arg_Is_Queuing_Policy --
829 ---------------------------------
831 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
832 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
835 Check_Arg_Is_Identifier (Argx);
837 if not Is_Queuing_Policy_Name (Chars (Argx)) then
839 ("& is not a valid queuing policy name", Argx);
841 end Check_Arg_Is_Queuing_Policy;
843 ------------------------------------
844 -- Check_Arg_Is_Static_Expression --
845 ------------------------------------
847 procedure Check_Arg_Is_Static_Expression
851 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
854 Analyze_And_Resolve (Argx, Typ);
856 if Is_OK_Static_Expression (Argx) then
859 elsif Etype (Argx) = Any_Type then
862 -- An interesting special case, if we have a string literal and
863 -- we are in Ada 83 mode, then we allow it even though it will
864 -- not be flagged as static. This allows the use of Ada 95
865 -- pragmas like Import in Ada 83 mode. They will of course be
866 -- flagged with warnings as usual, but will not cause errors.
868 elsif Ada_Version = Ada_83
869 and then Nkind (Argx) = N_String_Literal
873 -- Static expression that raises Constraint_Error. This has
874 -- already been flagged, so just exit from pragma processing.
876 elsif Is_Static_Expression (Argx) then
879 -- Finally, we have a real error
882 Error_Msg_Name_1 := Chars (N);
884 ("argument for pragma% must be a static expression!", Argx);
887 end Check_Arg_Is_Static_Expression;
889 ---------------------------------
890 -- Check_Arg_Is_String_Literal --
891 ---------------------------------
893 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
894 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
896 if Nkind (Argx) /= N_String_Literal then
898 ("argument for pragma% must be string literal", Argx);
900 end Check_Arg_Is_String_Literal;
902 ------------------------------------------
903 -- Check_Arg_Is_Task_Dispatching_Policy --
904 ------------------------------------------
906 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
907 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
910 Check_Arg_Is_Identifier (Argx);
912 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
914 ("& is not a valid task dispatching policy name", Argx);
916 end Check_Arg_Is_Task_Dispatching_Policy;
918 ---------------------
919 -- Check_Arg_Order --
920 ---------------------
922 procedure Check_Arg_Order (Names : Name_List) is
925 Highest_So_Far : Natural := 0;
926 -- Highest index in Names seen do far
930 for J in 1 .. Arg_Count loop
931 if Chars (Arg) /= No_Name then
932 for K in Names'Range loop
933 if Chars (Arg) = Names (K) then
934 if K < Highest_So_Far then
935 Error_Msg_Name_1 := Chars (N);
937 ("parameters out of order for pragma%", Arg);
938 Error_Msg_Name_1 := Names (K);
939 Error_Msg_Name_2 := Names (Highest_So_Far);
940 Error_Msg_N ("\% must appear before %", Arg);
954 --------------------------------
955 -- Check_At_Least_N_Arguments --
956 --------------------------------
958 procedure Check_At_Least_N_Arguments (N : Nat) is
960 if Arg_Count < N then
961 Error_Pragma ("too few arguments for pragma%");
963 end Check_At_Least_N_Arguments;
965 -------------------------------
966 -- Check_At_Most_N_Arguments --
967 -------------------------------
969 procedure Check_At_Most_N_Arguments (N : Nat) is
972 if Arg_Count > N then
976 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
979 end Check_At_Most_N_Arguments;
981 ---------------------
982 -- Check_Component --
983 ---------------------
985 procedure Check_Component (Comp : Node_Id) is
987 if Nkind (Comp) = N_Component_Declaration then
989 Sindic : constant Node_Id :=
990 Subtype_Indication (Component_Definition (Comp));
993 if Nkind (Sindic) = N_Subtype_Indication then
995 -- Ada 2005 (AI-216): If a component subtype is subject to
996 -- a per-object constraint, then the component type shall
997 -- be an Unchecked_Union.
999 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1001 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1003 Error_Msg_N ("component subtype subject to per-object" &
1004 " constraint must be an Unchecked_Union", Comp);
1009 end Check_Component;
1011 ----------------------------------
1012 -- Check_Duplicated_Export_Name --
1013 ----------------------------------
1015 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1016 String_Val : constant String_Id := Strval (Nam);
1019 -- We are only interested in the export case, and in the case of
1020 -- generics, it is the instance, not the template, that is the
1021 -- problem (the template will generate a warning in any case).
1023 if not Inside_A_Generic
1024 and then (Prag_Id = Pragma_Export
1026 Prag_Id = Pragma_Export_Procedure
1028 Prag_Id = Pragma_Export_Valued_Procedure
1030 Prag_Id = Pragma_Export_Function)
1032 for J in Externals.First .. Externals.Last loop
1033 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1034 Error_Msg_Sloc := Sloc (Externals.Table (J));
1035 Error_Msg_N ("external name duplicates name given#", Nam);
1040 Externals.Append (Nam);
1042 end Check_Duplicated_Export_Name;
1044 -------------------------
1045 -- Check_First_Subtype --
1046 -------------------------
1048 procedure Check_First_Subtype (Arg : Node_Id) is
1049 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1051 if not Is_First_Subtype (Entity (Argx)) then
1053 ("pragma% cannot apply to subtype", Argx);
1055 end Check_First_Subtype;
1057 ---------------------------
1058 -- Check_In_Main_Program --
1059 ---------------------------
1061 procedure Check_In_Main_Program is
1062 P : constant Node_Id := Parent (N);
1065 -- Must be at in subprogram body
1067 if Nkind (P) /= N_Subprogram_Body then
1068 Error_Pragma ("% pragma allowed only in subprogram");
1070 -- Otherwise warn if obviously not main program
1072 elsif Present (Parameter_Specifications (Specification (P)))
1073 or else not Is_Compilation_Unit (Defining_Entity (P))
1075 Error_Msg_Name_1 := Chars (N);
1077 ("?pragma% is only effective in main program", N);
1079 end Check_In_Main_Program;
1081 ---------------------------------------
1082 -- Check_Interrupt_Or_Attach_Handler --
1083 ---------------------------------------
1085 procedure Check_Interrupt_Or_Attach_Handler is
1086 Arg1_X : constant Node_Id := Expression (Arg1);
1087 Handler_Proc, Proc_Scope : Entity_Id;
1092 if Prag_Id = Pragma_Interrupt_Handler then
1093 Check_Restriction (No_Dynamic_Attachment, N);
1096 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1097 Proc_Scope := Scope (Handler_Proc);
1099 -- On AAMP only, a pragma Interrupt_Handler is supported for
1100 -- nonprotected parameterless procedures.
1102 if not AAMP_On_Target
1103 or else Prag_Id = Pragma_Attach_Handler
1105 if Ekind (Proc_Scope) /= E_Protected_Type then
1107 ("argument of pragma% must be protected procedure", Arg1);
1110 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1111 Error_Pragma ("pragma% must be in protected definition");
1115 if not Is_Library_Level_Entity (Proc_Scope)
1116 or else (AAMP_On_Target
1117 and then not Is_Library_Level_Entity (Handler_Proc))
1120 ("argument for pragma% must be library level entity", Arg1);
1122 end Check_Interrupt_Or_Attach_Handler;
1124 -------------------------------------------
1125 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1126 -------------------------------------------
1128 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1137 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1140 elsif Nkind (P) = N_Package_Specification then
1143 elsif Nkind (P) = N_Block_Statement then
1146 -- Note: the following tests seem a little peculiar, because
1147 -- they test for bodies, but if we were in the statement part
1148 -- of the body, we would already have hit the handled statement
1149 -- sequence, so the only way we get here is by being in the
1150 -- declarative part of the body.
1152 elsif Nkind (P) = N_Subprogram_Body
1153 or else Nkind (P) = N_Package_Body
1154 or else Nkind (P) = N_Task_Body
1155 or else Nkind (P) = N_Entry_Body
1163 Error_Pragma ("pragma% is not in declarative part or package spec");
1164 end Check_Is_In_Decl_Part_Or_Package_Spec;
1166 -------------------------
1167 -- Check_No_Identifier --
1168 -------------------------
1170 procedure Check_No_Identifier (Arg : Node_Id) is
1172 if Chars (Arg) /= No_Name then
1173 Error_Pragma_Arg_Ident
1174 ("pragma% does not permit identifier& here", Arg);
1176 end Check_No_Identifier;
1178 --------------------------
1179 -- Check_No_Identifiers --
1180 --------------------------
1182 procedure Check_No_Identifiers is
1185 if Arg_Count > 0 then
1187 while Present (Arg_Node) loop
1188 Check_No_Identifier (Arg_Node);
1192 end Check_No_Identifiers;
1194 -------------------------------
1195 -- Check_Optional_Identifier --
1196 -------------------------------
1198 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1200 if Present (Arg) and then Chars (Arg) /= No_Name then
1201 if Chars (Arg) /= Id then
1202 Error_Msg_Name_1 := Chars (N);
1203 Error_Msg_Name_2 := Id;
1204 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1208 end Check_Optional_Identifier;
1210 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1212 Name_Buffer (1 .. Id'Length) := Id;
1213 Name_Len := Id'Length;
1214 Check_Optional_Identifier (Arg, Name_Find);
1215 end Check_Optional_Identifier;
1217 -----------------------------
1218 -- Check_Static_Constraint --
1219 -----------------------------
1221 -- Note: for convenience in writing this procedure, in addition to
1222 -- the officially (i.e. by spec) allowed argument which is always
1223 -- a constraint, it also allows ranges and discriminant associations.
1224 -- Above is not clear ???
1226 procedure Check_Static_Constraint (Constr : Node_Id) is
1228 --------------------
1229 -- Require_Static --
1230 --------------------
1232 procedure Require_Static (E : Node_Id);
1233 -- Require given expression to be static expression
1235 procedure Require_Static (E : Node_Id) is
1237 if not Is_OK_Static_Expression (E) then
1238 Flag_Non_Static_Expr
1239 ("non-static constraint not allowed in Unchecked_Union!", E);
1244 -- Start of processing for Check_Static_Constraint
1247 case Nkind (Constr) is
1248 when N_Discriminant_Association =>
1249 Require_Static (Expression (Constr));
1252 Require_Static (Low_Bound (Constr));
1253 Require_Static (High_Bound (Constr));
1255 when N_Attribute_Reference =>
1256 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1257 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1259 when N_Range_Constraint =>
1260 Check_Static_Constraint (Range_Expression (Constr));
1262 when N_Index_Or_Discriminant_Constraint =>
1266 IDC := First (Constraints (Constr));
1267 while Present (IDC) loop
1268 Check_Static_Constraint (IDC);
1276 end Check_Static_Constraint;
1278 --------------------------------------
1279 -- Check_Valid_Configuration_Pragma --
1280 --------------------------------------
1282 -- A configuration pragma must appear in the context clause of
1283 -- a compilation unit, at the start of the list (i.e. only other
1284 -- pragmas may precede it).
1286 procedure Check_Valid_Configuration_Pragma is
1288 if not Is_Configuration_Pragma then
1289 Error_Pragma ("incorrect placement for configuration pragma%");
1291 end Check_Valid_Configuration_Pragma;
1293 -------------------------------------
1294 -- Check_Valid_Library_Unit_Pragma --
1295 -------------------------------------
1297 procedure Check_Valid_Library_Unit_Pragma is
1299 Parent_Node : Node_Id;
1300 Unit_Name : Entity_Id;
1301 Unit_Kind : Node_Kind;
1302 Unit_Node : Node_Id;
1303 Sindex : Source_File_Index;
1306 if not Is_List_Member (N) then
1310 Plist := List_Containing (N);
1311 Parent_Node := Parent (Plist);
1313 if Parent_Node = Empty then
1316 -- Case of pragma appearing after a compilation unit. In this
1317 -- case it must have an argument with the corresponding name
1318 -- and must be part of the following pragmas of its parent.
1320 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1321 if Plist /= Pragmas_After (Parent_Node) then
1324 elsif Arg_Count = 0 then
1326 ("argument required if outside compilation unit");
1329 Check_No_Identifiers;
1330 Check_Arg_Count (1);
1331 Unit_Node := Unit (Parent (Parent_Node));
1332 Unit_Kind := Nkind (Unit_Node);
1334 Analyze (Expression (Arg1));
1336 if Unit_Kind = N_Generic_Subprogram_Declaration
1337 or else Unit_Kind = N_Subprogram_Declaration
1339 Unit_Name := Defining_Entity (Unit_Node);
1341 elsif Unit_Kind in N_Generic_Instantiation then
1342 Unit_Name := Defining_Entity (Unit_Node);
1345 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1348 if Chars (Unit_Name) /=
1349 Chars (Entity (Expression (Arg1)))
1352 ("pragma% argument is not current unit name", Arg1);
1355 if Ekind (Unit_Name) = E_Package
1356 and then Present (Renamed_Entity (Unit_Name))
1358 Error_Pragma ("pragma% not allowed for renamed package");
1362 -- Pragma appears other than after a compilation unit
1365 -- Here we check for the generic instantiation case and also
1366 -- for the case of processing a generic formal package. We
1367 -- detect these cases by noting that the Sloc on the node
1368 -- does not belong to the current compilation unit.
1370 Sindex := Source_Index (Current_Sem_Unit);
1372 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1373 Rewrite (N, Make_Null_Statement (Loc));
1376 -- If before first declaration, the pragma applies to the
1377 -- enclosing unit, and the name if present must be this name.
1379 elsif Is_Before_First_Decl (N, Plist) then
1380 Unit_Node := Unit_Declaration_Node (Current_Scope);
1381 Unit_Kind := Nkind (Unit_Node);
1383 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1386 elsif Unit_Kind = N_Subprogram_Body
1387 and then not Acts_As_Spec (Unit_Node)
1391 elsif Nkind (Parent_Node) = N_Package_Body then
1394 elsif Nkind (Parent_Node) = N_Package_Specification
1395 and then Plist = Private_Declarations (Parent_Node)
1399 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1400 or else Nkind (Parent_Node)
1401 = N_Generic_Subprogram_Declaration)
1402 and then Plist = Generic_Formal_Declarations (Parent_Node)
1406 elsif Arg_Count > 0 then
1407 Analyze (Expression (Arg1));
1409 if Entity (Expression (Arg1)) /= Current_Scope then
1411 ("name in pragma% must be enclosing unit", Arg1);
1414 -- It is legal to have no argument in this context
1420 -- Error if not before first declaration. This is because a
1421 -- library unit pragma argument must be the name of a library
1422 -- unit (RM 10.1.5(7)), but the only names permitted in this
1423 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1424 -- generic subprogram declarations or generic instantiations.
1428 ("pragma% misplaced, must be before first declaration");
1432 end Check_Valid_Library_Unit_Pragma;
1438 procedure Check_Variant (Variant : Node_Id) is
1439 Clist : constant Node_Id := Component_List (Variant);
1443 if Present (Variant_Part (Clist)) then
1445 ("Unchecked_Union may not have nested variants",
1446 Variant_Part (Clist));
1449 if not Is_Non_Empty_List (Component_Items (Clist)) then
1451 ("Unchecked_Union may not have empty component list",
1456 Comp := First (Component_Items (Clist));
1457 while Present (Comp) loop
1458 Check_Component (Comp);
1467 procedure Error_Pragma (Msg : String) is
1469 Error_Msg_Name_1 := Chars (N);
1470 Error_Msg_N (Msg, N);
1474 ----------------------
1475 -- Error_Pragma_Arg --
1476 ----------------------
1478 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1480 Error_Msg_Name_1 := Chars (N);
1481 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1483 end Error_Pragma_Arg;
1485 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1487 Error_Msg_Name_1 := Chars (N);
1488 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1489 Error_Pragma_Arg (Msg2, Arg);
1490 end Error_Pragma_Arg;
1492 ----------------------------
1493 -- Error_Pragma_Arg_Ident --
1494 ----------------------------
1496 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1498 Error_Msg_Name_1 := Chars (N);
1499 Error_Msg_N (Msg, Arg);
1501 end Error_Pragma_Arg_Ident;
1503 ------------------------
1504 -- Find_Lib_Unit_Name --
1505 ------------------------
1507 function Find_Lib_Unit_Name return Entity_Id is
1509 -- Return inner compilation unit entity, for case of nested
1510 -- categorization pragmas. This happens in generic unit.
1512 if Nkind (Parent (N)) = N_Package_Specification
1513 and then Defining_Entity (Parent (N)) /= Current_Scope
1515 return Defining_Entity (Parent (N));
1517 return Current_Scope;
1519 end Find_Lib_Unit_Name;
1521 ----------------------------
1522 -- Find_Program_Unit_Name --
1523 ----------------------------
1525 procedure Find_Program_Unit_Name (Id : Node_Id) is
1526 Unit_Name : Entity_Id;
1527 Unit_Kind : Node_Kind;
1528 P : constant Node_Id := Parent (N);
1531 if Nkind (P) = N_Compilation_Unit then
1532 Unit_Kind := Nkind (Unit (P));
1534 if Unit_Kind = N_Subprogram_Declaration
1535 or else Unit_Kind = N_Package_Declaration
1536 or else Unit_Kind in N_Generic_Declaration
1538 Unit_Name := Defining_Entity (Unit (P));
1540 if Chars (Id) = Chars (Unit_Name) then
1541 Set_Entity (Id, Unit_Name);
1542 Set_Etype (Id, Etype (Unit_Name));
1544 Set_Etype (Id, Any_Type);
1546 ("cannot find program unit referenced by pragma%");
1550 Set_Etype (Id, Any_Type);
1551 Error_Pragma ("pragma% inapplicable to this unit");
1557 end Find_Program_Unit_Name;
1559 -----------------------------------------
1560 -- Find_Unique_Parameterless_Procedure --
1561 -----------------------------------------
1563 function Find_Unique_Parameterless_Procedure
1565 Arg : Node_Id) return Entity_Id
1567 Proc : Entity_Id := Empty;
1570 -- The body of this procedure needs some comments ???
1572 if not Is_Entity_Name (Name) then
1574 ("argument of pragma% must be entity name", Arg);
1576 elsif not Is_Overloaded (Name) then
1577 Proc := Entity (Name);
1579 if Ekind (Proc) /= E_Procedure
1580 or else Present (First_Formal (Proc)) then
1582 ("argument of pragma% must be parameterless procedure", Arg);
1587 Found : Boolean := False;
1589 Index : Interp_Index;
1592 Get_First_Interp (Name, Index, It);
1593 while Present (It.Nam) loop
1596 if Ekind (Proc) = E_Procedure
1597 and then No (First_Formal (Proc))
1601 Set_Entity (Name, Proc);
1602 Set_Is_Overloaded (Name, False);
1605 ("ambiguous handler name for pragma% ", Arg);
1609 Get_Next_Interp (Index, It);
1614 ("argument of pragma% must be parameterless procedure",
1617 Proc := Entity (Name);
1623 end Find_Unique_Parameterless_Procedure;
1625 -------------------------
1626 -- Gather_Associations --
1627 -------------------------
1629 procedure Gather_Associations
1631 Args : out Args_List)
1636 -- Initialize all parameters to Empty
1638 for J in Args'Range loop
1642 -- That's all we have to do if there are no argument associations
1644 if No (Pragma_Argument_Associations (N)) then
1648 -- Otherwise first deal with any positional parameters present
1650 Arg := First (Pragma_Argument_Associations (N));
1651 for Index in Args'Range loop
1652 exit when No (Arg) or else Chars (Arg) /= No_Name;
1653 Args (Index) := Expression (Arg);
1657 -- Positional parameters all processed, if any left, then we
1658 -- have too many positional parameters.
1660 if Present (Arg) and then Chars (Arg) = No_Name then
1662 ("too many positional associations for pragma%", Arg);
1665 -- Process named parameters if any are present
1667 while Present (Arg) loop
1668 if Chars (Arg) = No_Name then
1670 ("positional association cannot follow named association",
1674 for Index in Names'Range loop
1675 if Names (Index) = Chars (Arg) then
1676 if Present (Args (Index)) then
1678 ("duplicate argument association for pragma%", Arg);
1680 Args (Index) := Expression (Arg);
1685 if Index = Names'Last then
1686 Error_Msg_Name_1 := Chars (N);
1687 Error_Msg_N ("pragma% does not allow & argument", Arg);
1689 -- Check for possible misspelling
1691 for Index1 in Names'Range loop
1692 if Is_Bad_Spelling_Of
1693 (Get_Name_String (Chars (Arg)),
1694 Get_Name_String (Names (Index1)))
1696 Error_Msg_Name_1 := Names (Index1);
1697 Error_Msg_N ("\possible misspelling of%", Arg);
1709 end Gather_Associations;
1711 --------------------
1712 -- Get_Pragma_Arg --
1713 --------------------
1715 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1717 if Nkind (Arg) = N_Pragma_Argument_Association then
1718 return Expression (Arg);
1728 procedure GNAT_Pragma is
1730 Check_Restriction (No_Implementation_Pragmas, N);
1733 --------------------------
1734 -- Is_Before_First_Decl --
1735 --------------------------
1737 function Is_Before_First_Decl
1738 (Pragma_Node : Node_Id;
1739 Decls : List_Id) return Boolean
1741 Item : Node_Id := First (Decls);
1744 -- Only other pragmas can come before this pragma
1747 if No (Item) or else Nkind (Item) /= N_Pragma then
1750 elsif Item = Pragma_Node then
1756 end Is_Before_First_Decl;
1758 -----------------------------
1759 -- Is_Configuration_Pragma --
1760 -----------------------------
1762 -- A configuration pragma must appear in the context clause of
1763 -- a compilation unit, at the start of the list (i.e. only other
1764 -- pragmas may precede it).
1766 function Is_Configuration_Pragma return Boolean is
1767 Lis : constant List_Id := List_Containing (N);
1768 Par : constant Node_Id := Parent (N);
1772 -- If no parent, then we are in the configuration pragma file,
1773 -- so the placement is definitely appropriate.
1778 -- Otherwise we must be in the context clause of a compilation unit
1779 -- and the only thing allowed before us in the context list is more
1780 -- configuration pragmas.
1782 elsif Nkind (Par) = N_Compilation_Unit
1783 and then Context_Items (Par) = Lis
1790 elsif Nkind (Prg) /= N_Pragma then
1800 end Is_Configuration_Pragma;
1802 ----------------------
1803 -- Pragma_Misplaced --
1804 ----------------------
1806 procedure Pragma_Misplaced is
1808 Error_Pragma ("incorrect placement of pragma%");
1809 end Pragma_Misplaced;
1811 ------------------------------------
1812 -- Process Atomic_Shared_Volatile --
1813 ------------------------------------
1815 procedure Process_Atomic_Shared_Volatile is
1822 procedure Set_Atomic (E : Entity_Id);
1823 -- Set given type as atomic, and if no explicit alignment was
1824 -- given, set alignment to unknown, since back end knows what
1825 -- the alignment requirements are for atomic arrays. Note that
1826 -- this step is necessary for derived types.
1832 procedure Set_Atomic (E : Entity_Id) is
1836 if not Has_Alignment_Clause (E) then
1837 Set_Alignment (E, Uint_0);
1841 -- Start of processing for Process_Atomic_Shared_Volatile
1844 Check_Ada_83_Warning;
1845 Check_No_Identifiers;
1846 Check_Arg_Count (1);
1847 Check_Arg_Is_Local_Name (Arg1);
1848 E_Id := Expression (Arg1);
1850 if Etype (E_Id) = Any_Type then
1855 D := Declaration_Node (E);
1859 if Rep_Item_Too_Early (E, N)
1861 Rep_Item_Too_Late (E, N)
1865 Check_First_Subtype (Arg1);
1868 if Prag_Id /= Pragma_Volatile then
1870 Set_Atomic (Underlying_Type (E));
1871 Set_Atomic (Base_Type (E));
1874 -- Attribute belongs on the base type. If the
1875 -- view of the type is currently private, it also
1876 -- belongs on the underlying type.
1878 Set_Is_Volatile (Base_Type (E));
1879 Set_Is_Volatile (Underlying_Type (E));
1881 Set_Treat_As_Volatile (E);
1882 Set_Treat_As_Volatile (Underlying_Type (E));
1884 elsif K = N_Object_Declaration
1885 or else (K = N_Component_Declaration
1886 and then Original_Record_Component (E) = E)
1888 if Rep_Item_Too_Late (E, N) then
1892 if Prag_Id /= Pragma_Volatile then
1895 -- If the object declaration has an explicit
1896 -- initialization, a temporary may have to be
1897 -- created to hold the expression, to insure
1898 -- that access to the object remain atomic.
1900 if Nkind (Parent (E)) = N_Object_Declaration
1901 and then Present (Expression (Parent (E)))
1903 Set_Has_Delayed_Freeze (E);
1906 -- An interesting improvement here. If an object of type X
1907 -- is declared atomic, and the type X is not atomic, that's
1908 -- a pity, since it may not have appropraite alignment etc.
1909 -- We can rescue this in the special case where the object
1910 -- and type are in the same unit by just setting the type
1911 -- as atomic, so that the back end will process it as atomic.
1913 Utyp := Underlying_Type (Etype (E));
1916 and then Sloc (E) > No_Location
1917 and then Sloc (Utyp) > No_Location
1919 Get_Source_File_Index (Sloc (E)) =
1920 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1922 Set_Is_Atomic (Underlying_Type (Etype (E)));
1926 Set_Is_Volatile (E);
1927 Set_Treat_As_Volatile (E);
1931 ("inappropriate entity for pragma%", Arg1);
1933 end Process_Atomic_Shared_Volatile;
1935 ------------------------
1936 -- Process_Convention --
1937 ------------------------
1939 procedure Process_Convention
1940 (C : out Convention_Id;
1946 Comp_Unit : Unit_Number_Type;
1948 procedure Set_Convention_From_Pragma (E : Entity_Id);
1949 -- Set convention in entity E, and also flag that the entity has a
1950 -- convention pragma. If entity is for a private or incomplete type,
1951 -- also set convention and flag on underlying type. This procedure
1952 -- also deals with the special case of C_Pass_By_Copy convention.
1954 --------------------------------
1955 -- Set_Convention_From_Pragma --
1956 --------------------------------
1958 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1960 Set_Convention (E, C);
1961 Set_Has_Convention_Pragma (E);
1963 if Is_Incomplete_Or_Private_Type (E) then
1964 Set_Convention (Underlying_Type (E), C);
1965 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1968 -- A class-wide type should inherit the convention of
1969 -- the specific root type (although this isn't specified
1970 -- clearly by the RM).
1972 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1973 Set_Convention (Class_Wide_Type (E), C);
1976 -- If the entity is a record type, then check for special case
1977 -- of C_Pass_By_Copy, which is treated the same as C except that
1978 -- the special record flag is set. This convention is also only
1979 -- permitted on record types (see AI95-00131).
1981 if Cname = Name_C_Pass_By_Copy then
1982 if Is_Record_Type (E) then
1983 Set_C_Pass_By_Copy (Base_Type (E));
1984 elsif Is_Incomplete_Or_Private_Type (E)
1985 and then Is_Record_Type (Underlying_Type (E))
1987 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1990 ("C_Pass_By_Copy convention allowed only for record type",
1995 -- If the entity is a derived boolean type, check for the
1996 -- special case of convention C, C++, or Fortran, where we
1997 -- consider any nonzero value to represent true.
1999 if Is_Discrete_Type (E)
2000 and then Root_Type (Etype (E)) = Standard_Boolean
2006 C = Convention_Fortran)
2008 Set_Nonzero_Is_True (Base_Type (E));
2010 end Set_Convention_From_Pragma;
2012 -- Start of processing for Process_Convention
2015 Check_At_Least_N_Arguments (2);
2016 Check_Optional_Identifier (Arg1, Name_Convention);
2017 Check_Arg_Is_Identifier (Arg1);
2018 Cname := Chars (Expression (Arg1));
2020 -- C_Pass_By_Copy is treated as a synonym for convention C
2021 -- (this is tested again below to set the critical flag)
2023 if Cname = Name_C_Pass_By_Copy then
2026 -- Otherwise we must have something in the standard convention list
2028 elsif Is_Convention_Name (Cname) then
2029 C := Get_Convention_Id (Chars (Expression (Arg1)));
2031 -- In DEC VMS, it seems that there is an undocumented feature
2032 -- that any unrecognized convention is treated as the default,
2033 -- which for us is convention C. It does not seem so terrible
2034 -- to do this unconditionally, silently in the VMS case, and
2035 -- with a warning in the non-VMS case.
2038 if Warn_On_Export_Import and not OpenVMS_On_Target then
2040 ("?unrecognized convention name, C assumed",
2047 Check_Optional_Identifier (Arg2, Name_Entity);
2048 Check_Arg_Is_Local_Name (Arg2);
2050 Id := Expression (Arg2);
2053 if not Is_Entity_Name (Id) then
2054 Error_Pragma_Arg ("entity name required", Arg2);
2059 -- Go to renamed subprogram if present, since convention applies
2060 -- to the actual renamed entity, not to the renaming entity.
2061 -- If subprogram is inherited, go to parent subprogram.
2063 if Is_Subprogram (E)
2064 and then Present (Alias (E))
2066 if Nkind (Parent (Declaration_Node (E)))
2067 = N_Subprogram_Renaming_Declaration
2071 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2072 and then Scope (E) = Scope (Alias (E))
2078 -- Check that we are not applying this to a specless body
2080 if Is_Subprogram (E)
2081 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2084 ("pragma% requires separate spec and must come before body");
2087 -- Check that we are not applying this to a named constant
2089 if Ekind (E) = E_Named_Integer
2091 Ekind (E) = E_Named_Real
2093 Error_Msg_Name_1 := Chars (N);
2095 ("cannot apply pragma% to named constant!",
2096 Get_Pragma_Arg (Arg2));
2098 ("\supply appropriate type for&!", Arg2);
2101 if Etype (E) = Any_Type
2102 or else Rep_Item_Too_Early (E, N)
2106 E := Underlying_Type (E);
2109 if Rep_Item_Too_Late (E, N) then
2113 if Has_Convention_Pragma (E) then
2115 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2117 elsif Convention (E) = Convention_Protected
2118 or else Ekind (Scope (E)) = E_Protected_Type
2121 ("a protected operation cannot be given a different convention",
2125 -- For Intrinsic, a subprogram is required
2127 if C = Convention_Intrinsic
2128 and then not Is_Subprogram (E)
2129 and then not Is_Generic_Subprogram (E)
2132 ("second argument of pragma% must be a subprogram", Arg2);
2135 -- For Stdcall, a subprogram, variable or subprogram type is required
2137 if C = Convention_Stdcall
2138 and then not Is_Subprogram (E)
2139 and then not Is_Generic_Subprogram (E)
2140 and then Ekind (E) /= E_Variable
2143 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2146 ("second argument of pragma% must be subprogram (type)",
2150 if not Is_Subprogram (E)
2151 and then not Is_Generic_Subprogram (E)
2153 Set_Convention_From_Pragma (E);
2157 Check_First_Subtype (Arg2);
2158 Set_Convention_From_Pragma (Base_Type (E));
2160 -- For subprograms, we must set the convention on the
2161 -- internally generated directly designated type as well.
2163 if Ekind (E) = E_Access_Subprogram_Type then
2164 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2168 -- For the subprogram case, set proper convention for all homonyms
2169 -- in same scope and the same declarative part, i.e. the same
2170 -- compilation unit.
2173 Comp_Unit := Get_Source_Unit (E);
2174 Set_Convention_From_Pragma (E);
2176 -- Treat a pragma Import as an implicit body, for GPS use
2178 if Prag_Id = Pragma_Import then
2179 Generate_Reference (E, Id, 'b');
2185 exit when No (E1) or else Scope (E1) /= Current_Scope;
2187 -- Note: below we are missing a check for Rep_Item_Too_Late.
2188 -- That is deliberate, we cannot chain the rep item on more
2189 -- than one Rep_Item chain, to be fixed later ???
2191 if Comes_From_Source (E1)
2192 and then Comp_Unit = Get_Source_Unit (E1)
2193 and then Nkind (Original_Node (Parent (E1))) /=
2194 N_Full_Type_Declaration
2196 Set_Convention_From_Pragma (E1);
2198 if Prag_Id = Pragma_Import then
2199 Generate_Reference (E, Id, 'b');
2204 end Process_Convention;
2206 -----------------------------------------------------
2207 -- Process_Extended_Import_Export_Exception_Pragma --
2208 -----------------------------------------------------
2210 procedure Process_Extended_Import_Export_Exception_Pragma
2211 (Arg_Internal : Node_Id;
2212 Arg_External : Node_Id;
2222 if not OpenVMS_On_Target then
2224 ("?pragma% ignored (applies only to Open'V'M'S)");
2227 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2228 Def_Id := Entity (Arg_Internal);
2230 if Ekind (Def_Id) /= E_Exception then
2232 ("pragma% must refer to declared exception", Arg_Internal);
2235 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2237 if Present (Arg_Form) then
2238 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2241 if Present (Arg_Form)
2242 and then Chars (Arg_Form) = Name_Ada
2246 Set_Is_VMS_Exception (Def_Id);
2247 Set_Exception_Code (Def_Id, No_Uint);
2250 if Present (Arg_Code) then
2251 if not Is_VMS_Exception (Def_Id) then
2253 ("Code option for pragma% not allowed for Ada case",
2257 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2258 Code_Val := Expr_Value (Arg_Code);
2260 if not UI_Is_In_Int_Range (Code_Val) then
2262 ("Code option for pragma% must be in 32-bit range",
2266 Set_Exception_Code (Def_Id, Code_Val);
2269 end Process_Extended_Import_Export_Exception_Pragma;
2271 -------------------------------------------------
2272 -- Process_Extended_Import_Export_Internal_Arg --
2273 -------------------------------------------------
2275 procedure Process_Extended_Import_Export_Internal_Arg
2276 (Arg_Internal : Node_Id := Empty)
2281 if No (Arg_Internal) then
2282 Error_Pragma ("Internal parameter required for pragma%");
2285 if Nkind (Arg_Internal) = N_Identifier then
2288 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2289 and then (Prag_Id = Pragma_Import_Function
2291 Prag_Id = Pragma_Export_Function)
2297 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2300 Check_Arg_Is_Local_Name (Arg_Internal);
2301 end Process_Extended_Import_Export_Internal_Arg;
2303 --------------------------------------------------
2304 -- Process_Extended_Import_Export_Object_Pragma --
2305 --------------------------------------------------
2307 procedure Process_Extended_Import_Export_Object_Pragma
2308 (Arg_Internal : Node_Id;
2309 Arg_External : Node_Id;
2315 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2316 Def_Id := Entity (Arg_Internal);
2318 if Ekind (Def_Id) /= E_Constant
2319 and then Ekind (Def_Id) /= E_Variable
2322 ("pragma% must designate an object", Arg_Internal);
2325 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2327 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2330 ("previous Common/Psect_Object applies, pragma % not permitted",
2334 if Rep_Item_Too_Late (Def_Id, N) then
2338 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2340 if Present (Arg_Size) then
2341 Check_Arg_Is_External_Name (Arg_Size);
2344 -- Export_Object case
2346 if Prag_Id = Pragma_Export_Object then
2347 if not Is_Library_Level_Entity (Def_Id) then
2349 ("argument for pragma% must be library level entity",
2353 if Ekind (Current_Scope) = E_Generic_Package then
2354 Error_Pragma ("pragma& cannot appear in a generic unit");
2357 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2359 ("exported object must have compile time known size",
2363 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2365 ("?duplicate Export_Object pragma", N);
2367 Set_Exported (Def_Id, Arg_Internal);
2370 -- Import_Object case
2373 if Is_Concurrent_Type (Etype (Def_Id)) then
2375 ("cannot use pragma% for task/protected object",
2379 if Ekind (Def_Id) = E_Constant then
2381 ("cannot import a constant", Arg_Internal);
2384 if Warn_On_Export_Import
2385 and then Has_Discriminants (Etype (Def_Id))
2388 ("imported value must be initialized?", Arg_Internal);
2391 if Warn_On_Export_Import
2392 and then Is_Access_Type (Etype (Def_Id))
2395 ("cannot import object of an access type?", Arg_Internal);
2398 if Warn_On_Export_Import
2399 and then Is_Imported (Def_Id)
2402 ("?duplicate Import_Object pragma", N);
2404 -- Check for explicit initialization present. Note that an
2405 -- initialization that generated by the code generator, e.g.
2406 -- for an access type, does not count here.
2408 elsif Present (Expression (Parent (Def_Id)))
2411 (Original_Node (Expression (Parent (Def_Id))))
2413 Error_Msg_Sloc := Sloc (Def_Id);
2415 ("no initialization allowed for declaration of& #",
2416 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2419 Set_Imported (Def_Id);
2420 Note_Possible_Modification (Arg_Internal);
2423 end Process_Extended_Import_Export_Object_Pragma;
2425 ------------------------------------------------------
2426 -- Process_Extended_Import_Export_Subprogram_Pragma --
2427 ------------------------------------------------------
2429 procedure Process_Extended_Import_Export_Subprogram_Pragma
2430 (Arg_Internal : Node_Id;
2431 Arg_External : Node_Id;
2432 Arg_Parameter_Types : Node_Id;
2433 Arg_Result_Type : Node_Id := Empty;
2434 Arg_Mechanism : Node_Id;
2435 Arg_Result_Mechanism : Node_Id := Empty;
2436 Arg_First_Optional_Parameter : Node_Id := Empty)
2442 Ambiguous : Boolean;
2446 function Same_Base_Type
2448 Formal : Entity_Id) return Boolean;
2449 -- Determines if Ptype references the type of Formal. Note that
2450 -- only the base types need to match according to the spec. Ptype
2451 -- here is the argument from the pragma, which is either a type
2452 -- name, or an access attribute.
2454 --------------------
2455 -- Same_Base_Type --
2456 --------------------
2458 function Same_Base_Type
2460 Formal : Entity_Id) return Boolean
2462 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2466 -- Case where pragma argument is typ'Access
2468 if Nkind (Ptype) = N_Attribute_Reference
2469 and then Attribute_Name (Ptype) = Name_Access
2471 Pref := Prefix (Ptype);
2474 if not Is_Entity_Name (Pref)
2475 or else Entity (Pref) = Any_Type
2480 -- We have a match if the corresponding argument is of an
2481 -- anonymous access type, and its designicated type matches
2482 -- the type of the prefix of the access attribute
2484 return Ekind (Ftyp) = E_Anonymous_Access_Type
2485 and then Base_Type (Entity (Pref)) =
2486 Base_Type (Etype (Designated_Type (Ftyp)));
2488 -- Case where pragma argument is a type name
2493 if not Is_Entity_Name (Ptype)
2494 or else Entity (Ptype) = Any_Type
2499 -- We have a match if the corresponding argument is of
2500 -- the type given in the pragma (comparing base types)
2502 return Base_Type (Entity (Ptype)) = Ftyp;
2506 -- Start of processing for
2507 -- Process_Extended_Import_Export_Subprogram_Pragma
2510 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2514 -- Loop through homonyms (overloadings) of the entity
2516 Hom_Id := Entity (Arg_Internal);
2517 while Present (Hom_Id) loop
2518 Def_Id := Get_Base_Subprogram (Hom_Id);
2520 -- We need a subprogram in the current scope
2522 if not Is_Subprogram (Def_Id)
2523 or else Scope (Def_Id) /= Current_Scope
2530 -- Pragma cannot apply to subprogram body
2532 if Is_Subprogram (Def_Id)
2535 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2538 ("pragma% requires separate spec"
2539 & " and must come before body");
2542 -- Test result type if given, note that the result type
2543 -- parameter can only be present for the function cases.
2545 if Present (Arg_Result_Type)
2546 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2550 elsif Etype (Def_Id) /= Standard_Void_Type
2552 (Chars (N) = Name_Export_Procedure
2553 or else Chars (N) = Name_Import_Procedure)
2557 -- Test parameter types if given. Note that this parameter
2558 -- has not been analyzed (and must not be, since it is
2559 -- semantic nonsense), so we get it as the parser left it.
2561 elsif Present (Arg_Parameter_Types) then
2562 Check_Matching_Types : declare
2567 Formal := First_Formal (Def_Id);
2569 if Nkind (Arg_Parameter_Types) = N_Null then
2570 if Present (Formal) then
2574 -- A list of one type, e.g. (List) is parsed as
2575 -- a parenthesized expression.
2577 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2578 and then Paren_Count (Arg_Parameter_Types) = 1
2581 or else Present (Next_Formal (Formal))
2586 Same_Base_Type (Arg_Parameter_Types, Formal);
2589 -- A list of more than one type is parsed as a aggregate
2591 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2592 and then Paren_Count (Arg_Parameter_Types) = 0
2594 Ptype := First (Expressions (Arg_Parameter_Types));
2595 while Present (Ptype) or else Present (Formal) loop
2598 or else not Same_Base_Type (Ptype, Formal)
2603 Next_Formal (Formal);
2608 -- Anything else is of the wrong form
2612 ("wrong form for Parameter_Types parameter",
2613 Arg_Parameter_Types);
2615 end Check_Matching_Types;
2618 -- Match is now False if the entry we found did not match
2619 -- either a supplied Parameter_Types or Result_Types argument
2625 -- Ambiguous case, the flag Ambiguous shows if we already
2626 -- detected this and output the initial messages.
2629 if not Ambiguous then
2631 Error_Msg_Name_1 := Chars (N);
2633 ("pragma% does not uniquely identify subprogram!",
2635 Error_Msg_Sloc := Sloc (Ent);
2636 Error_Msg_N ("matching subprogram #!", N);
2640 Error_Msg_Sloc := Sloc (Def_Id);
2641 Error_Msg_N ("matching subprogram #!", N);
2646 Hom_Id := Homonym (Hom_Id);
2649 -- See if we found an entry
2652 if not Ambiguous then
2653 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2655 ("pragma% cannot be given for generic subprogram");
2659 ("pragma% does not identify local subprogram");
2666 -- Import pragmas must be be for imported entities
2668 if Prag_Id = Pragma_Import_Function
2670 Prag_Id = Pragma_Import_Procedure
2672 Prag_Id = Pragma_Import_Valued_Procedure
2674 if not Is_Imported (Ent) then
2676 ("pragma Import or Interface must precede pragma%");
2679 -- Here we have the Export case which can set the entity as exported
2681 -- But does not do so if the specified external name is null,
2682 -- since that is taken as a signal in DEC Ada 83 (with which
2683 -- we want to be compatible) to request no external name.
2685 elsif Nkind (Arg_External) = N_String_Literal
2686 and then String_Length (Strval (Arg_External)) = 0
2690 -- In all other cases, set entit as exported
2693 Set_Exported (Ent, Arg_Internal);
2696 -- Special processing for Valued_Procedure cases
2698 if Prag_Id = Pragma_Import_Valued_Procedure
2700 Prag_Id = Pragma_Export_Valued_Procedure
2702 Formal := First_Formal (Ent);
2706 ("at least one parameter required for pragma%");
2708 elsif Ekind (Formal) /= E_Out_Parameter then
2710 ("first parameter must have mode out for pragma%");
2713 Set_Is_Valued_Procedure (Ent);
2717 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2719 -- Process Result_Mechanism argument if present. We have already
2720 -- checked that this is only allowed for the function case.
2722 if Present (Arg_Result_Mechanism) then
2723 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2726 -- Process Mechanism parameter if present. Note that this parameter
2727 -- is not analyzed, and must not be analyzed since it is semantic
2728 -- nonsense, so we get it in exactly as the parser left it.
2730 if Present (Arg_Mechanism) then
2738 -- A single mechanism association without a formal parameter
2739 -- name is parsed as a parenthesized expression. All other
2740 -- cases are parsed as aggregates, so we rewrite the single
2741 -- parameter case as an aggregate for consistency.
2743 if Nkind (Arg_Mechanism) /= N_Aggregate
2744 and then Paren_Count (Arg_Mechanism) = 1
2746 Rewrite (Arg_Mechanism,
2747 Make_Aggregate (Sloc (Arg_Mechanism),
2748 Expressions => New_List (
2749 Relocate_Node (Arg_Mechanism))));
2752 -- Case of only mechanism name given, applies to all formals
2754 if Nkind (Arg_Mechanism) /= N_Aggregate then
2755 Formal := First_Formal (Ent);
2756 while Present (Formal) loop
2757 Set_Mechanism_Value (Formal, Arg_Mechanism);
2758 Next_Formal (Formal);
2761 -- Case of list of mechanism associations given
2764 if Null_Record_Present (Arg_Mechanism) then
2766 ("inappropriate form for Mechanism parameter",
2770 -- Deal with positional ones first
2772 Formal := First_Formal (Ent);
2774 if Present (Expressions (Arg_Mechanism)) then
2775 Mname := First (Expressions (Arg_Mechanism));
2777 while Present (Mname) loop
2780 ("too many mechanism associations", Mname);
2783 Set_Mechanism_Value (Formal, Mname);
2784 Next_Formal (Formal);
2789 -- Deal with named entries
2791 if Present (Component_Associations (Arg_Mechanism)) then
2792 Massoc := First (Component_Associations (Arg_Mechanism));
2794 while Present (Massoc) loop
2795 Choice := First (Choices (Massoc));
2797 if Nkind (Choice) /= N_Identifier
2798 or else Present (Next (Choice))
2801 ("incorrect form for mechanism association",
2805 Formal := First_Formal (Ent);
2809 ("parameter name & not present", Choice);
2812 if Chars (Choice) = Chars (Formal) then
2814 (Formal, Expression (Massoc));
2818 Next_Formal (Formal);
2828 -- Process First_Optional_Parameter argument if present. We have
2829 -- already checked that this is only allowed for the Import case.
2831 if Present (Arg_First_Optional_Parameter) then
2832 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2834 ("first optional parameter must be formal parameter name",
2835 Arg_First_Optional_Parameter);
2838 Formal := First_Formal (Ent);
2842 ("specified formal parameter& not found",
2843 Arg_First_Optional_Parameter);
2846 exit when Chars (Formal) =
2847 Chars (Arg_First_Optional_Parameter);
2849 Next_Formal (Formal);
2852 Set_First_Optional_Parameter (Ent, Formal);
2854 -- Check specified and all remaining formals have right form
2856 while Present (Formal) loop
2857 if Ekind (Formal) /= E_In_Parameter then
2859 ("optional formal& is not of mode in!",
2860 Arg_First_Optional_Parameter, Formal);
2863 Dval := Default_Value (Formal);
2865 if not Present (Dval) then
2867 ("optional formal& does not have default value!",
2868 Arg_First_Optional_Parameter, Formal);
2870 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2875 ("default value for optional formal& is non-static!",
2876 Arg_First_Optional_Parameter, Formal);
2880 Set_Is_Optional_Parameter (Formal);
2881 Next_Formal (Formal);
2884 end Process_Extended_Import_Export_Subprogram_Pragma;
2886 --------------------------
2887 -- Process_Generic_List --
2888 --------------------------
2890 procedure Process_Generic_List is
2896 Check_No_Identifiers;
2897 Check_At_Least_N_Arguments (1);
2900 while Present (Arg) loop
2901 Exp := Expression (Arg);
2904 if not Is_Entity_Name (Exp)
2906 (not Is_Generic_Instance (Entity (Exp))
2908 not Is_Generic_Unit (Entity (Exp)))
2911 ("pragma% argument must be name of generic unit/instance",
2917 end Process_Generic_List;
2919 ---------------------------------
2920 -- Process_Import_Or_Interface --
2921 ---------------------------------
2923 procedure Process_Import_Or_Interface is
2929 Process_Convention (C, Def_Id);
2930 Kill_Size_Check_Code (Def_Id);
2931 Note_Possible_Modification (Expression (Arg2));
2933 if Ekind (Def_Id) = E_Variable
2935 Ekind (Def_Id) = E_Constant
2937 -- User initialization is not allowed for imported object, but
2938 -- the object declaration may contain a default initialization,
2939 -- that will be discarded. Note that an explicit initialization
2940 -- only counts if it comes from source, otherwise it is simply
2941 -- the code generator making an implicit initialization explicit.
2943 if Present (Expression (Parent (Def_Id)))
2944 and then Comes_From_Source (Expression (Parent (Def_Id)))
2946 Error_Msg_Sloc := Sloc (Def_Id);
2948 ("no initialization allowed for declaration of& #",
2949 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2953 Set_Imported (Def_Id);
2954 Process_Interface_Name (Def_Id, Arg3, Arg4);
2956 -- Note that we do not set Is_Public here. That's because we
2957 -- only want to set if if there is no address clause, and we
2958 -- don't know that yet, so we delay that processing till
2961 -- pragma Import completes deferred constants
2963 if Ekind (Def_Id) = E_Constant then
2964 Set_Has_Completion (Def_Id);
2967 -- It is not possible to import a constant of an unconstrained
2968 -- array type (e.g. string) because there is no simple way to
2969 -- write a meaningful subtype for it.
2971 if Is_Array_Type (Etype (Def_Id))
2972 and then not Is_Constrained (Etype (Def_Id))
2975 ("imported constant& must have a constrained subtype",
2980 elsif Is_Subprogram (Def_Id)
2981 or else Is_Generic_Subprogram (Def_Id)
2983 -- If the name is overloaded, pragma applies to all of the
2984 -- denoted entities in the same declarative part.
2987 while Present (Hom_Id) loop
2988 Def_Id := Get_Base_Subprogram (Hom_Id);
2990 -- Ignore inherited subprograms because the pragma will
2991 -- apply to the parent operation, which is the one called.
2993 if Is_Overloadable (Def_Id)
2994 and then Present (Alias (Def_Id))
2998 -- If it is not a subprogram, it must be in an outer
2999 -- scope and pragma does not apply.
3001 elsif not Is_Subprogram (Def_Id)
3002 and then not Is_Generic_Subprogram (Def_Id)
3006 -- Verify that the homonym is in the same declarative
3007 -- part (not just the same scope).
3009 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3010 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3015 Set_Imported (Def_Id);
3017 -- Special processing for Convention_Intrinsic
3019 if C = Convention_Intrinsic then
3021 -- Link_Name argument not allowed for intrinsic
3024 and then Chars (Arg3) = Name_Link_Name
3029 if Present (Arg4) then
3031 ("Link_Name argument not allowed for " &
3036 Set_Is_Intrinsic_Subprogram (Def_Id);
3038 -- If no external name is present, then check that
3039 -- this is a valid intrinsic subprogram. If an external
3040 -- name is present, then this is handled by the back end.
3043 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3047 -- All interfaced procedures need an external symbol
3048 -- created for them since they are always referenced
3049 -- from another object file.
3051 Set_Is_Public (Def_Id);
3053 -- Verify that the subprogram does not have a completion
3054 -- through a renaming declaration. For other completions
3055 -- the pragma appears as a too late representation.
3058 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3062 and then Nkind (Decl) = N_Subprogram_Declaration
3063 and then Present (Corresponding_Body (Decl))
3066 (Unit_Declaration_Node
3067 (Corresponding_Body (Decl))) =
3068 N_Subprogram_Renaming_Declaration
3070 Error_Msg_Sloc := Sloc (Def_Id);
3071 Error_Msg_NE ("cannot import&#," &
3072 " already completed by a renaming",
3077 Set_Has_Completion (Def_Id);
3078 Process_Interface_Name (Def_Id, Arg3, Arg4);
3081 if Is_Compilation_Unit (Hom_Id) then
3083 -- Its possible homonyms are not affected by the pragma.
3084 -- Such homonyms might be present in the context of other
3085 -- units being compiled.
3090 Hom_Id := Homonym (Hom_Id);
3094 -- When the convention is Java, we also allow Import to be given
3095 -- for packages, exceptions, and record components.
3097 elsif C = Convention_Java
3099 (Ekind (Def_Id) = E_Package
3100 or else Ekind (Def_Id) = E_Exception
3101 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3103 Set_Imported (Def_Id);
3104 Set_Is_Public (Def_Id);
3105 Process_Interface_Name (Def_Id, Arg3, Arg4);
3109 ("second argument of pragma% must be object or subprogram",
3113 -- If this pragma applies to a compilation unit, then the unit,
3114 -- which is a subprogram, does not require (or allow) a body.
3115 -- We also do not need to elaborate imported procedures.
3117 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3119 Cunit : constant Node_Id := Parent (Parent (N));
3121 Set_Body_Required (Cunit, False);
3124 end Process_Import_Or_Interface;
3126 --------------------
3127 -- Process_Inline --
3128 --------------------
3130 procedure Process_Inline (Active : Boolean) is
3136 Effective : Boolean := False;
3138 procedure Make_Inline (Subp : Entity_Id);
3139 -- Subp is the defining unit name of the subprogram
3140 -- declaration. Set the flag, as well as the flag in the
3141 -- corresponding body, if there is one present.
3143 procedure Set_Inline_Flags (Subp : Entity_Id);
3144 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3146 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3147 -- Returns True if it can be determined at this stage that inlining
3148 -- is not possible, for examle if the body is available and contains
3149 -- exception handlers, we prevent inlining, since otherwise we can
3150 -- get undefined symbols at link time. This function also emits a
3151 -- warning if front-end inlining is enabled and the pragma appears
3153 -- ??? is business with link symbols still valid, or does it relate
3154 -- to front end ZCX which is being phased out ???
3156 ---------------------------
3157 -- Inlining_Not_Possible --
3158 ---------------------------
3160 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3161 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3165 if Nkind (Decl) = N_Subprogram_Body then
3166 Stats := Handled_Statement_Sequence (Decl);
3167 return Present (Exception_Handlers (Stats))
3168 or else Present (At_End_Proc (Stats));
3170 elsif Nkind (Decl) = N_Subprogram_Declaration
3171 and then Present (Corresponding_Body (Decl))
3173 if Front_End_Inlining
3174 and then Analyzed (Corresponding_Body (Decl))
3176 Error_Msg_N ("pragma appears too late, ignored?", N);
3179 -- If the subprogram is a renaming as body, the body is
3180 -- just a call to the renamed subprogram, and inlining is
3181 -- trivially possible.
3184 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3185 = N_Subprogram_Renaming_Declaration
3191 Handled_Statement_Sequence
3192 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3195 Present (Exception_Handlers (Stats))
3196 or else Present (At_End_Proc (Stats));
3200 -- If body is not available, assume the best, the check is
3201 -- performed again when compiling enclosing package bodies.
3205 end Inlining_Not_Possible;
3211 procedure Make_Inline (Subp : Entity_Id) is
3212 Kind : constant Entity_Kind := Ekind (Subp);
3213 Inner_Subp : Entity_Id := Subp;
3216 if Etype (Subp) = Any_Type then
3219 -- If inlining is not possible, for now do not treat as an error
3221 elsif Inlining_Not_Possible (Subp) then
3225 -- Here we have a candidate for inlining, but we must exclude
3226 -- derived operations. Otherwise we will end up trying to
3227 -- inline a phantom declaration, and the result would be to
3228 -- drag in a body which has no direct inlining associated with
3229 -- it. That would not only be inefficient but would also result
3230 -- in the backend doing cross-unit inlining in cases where it
3231 -- was definitely inappropriate to do so.
3233 -- However, a simple Comes_From_Source test is insufficient,
3234 -- since we do want to allow inlining of generic instances,
3235 -- which also do not come from source. Predefined operators do
3236 -- not come from source but are not inlineable either.
3238 elsif not Comes_From_Source (Subp)
3239 and then not Is_Generic_Instance (Subp)
3240 and then Scope (Subp) /= Standard_Standard
3245 -- The referenced entity must either be the enclosing entity,
3246 -- or an entity declared within the current open scope.
3248 elsif Present (Scope (Subp))
3249 and then Scope (Subp) /= Current_Scope
3250 and then Subp /= Current_Scope
3253 ("argument of% must be entity in current scope", Assoc);
3257 -- Processing for procedure, operator or function.
3258 -- If subprogram is aliased (as for an instance) indicate
3259 -- that the renamed entity (if declared in the same unit)
3262 if Is_Subprogram (Subp) then
3263 while Present (Alias (Inner_Subp)) loop
3264 Inner_Subp := Alias (Inner_Subp);
3267 if In_Same_Source_Unit (Subp, Inner_Subp) then
3268 Set_Inline_Flags (Inner_Subp);
3270 Decl := Parent (Parent (Inner_Subp));
3272 if Nkind (Decl) = N_Subprogram_Declaration
3273 and then Present (Corresponding_Body (Decl))
3275 Set_Inline_Flags (Corresponding_Body (Decl));
3281 -- For a generic subprogram set flag as well, for use at
3282 -- the point of instantiation, to determine whether the
3283 -- body should be generated.
3285 elsif Is_Generic_Subprogram (Subp) then
3286 Set_Inline_Flags (Subp);
3289 -- Literals are by definition inlined
3291 elsif Kind = E_Enumeration_Literal then
3294 -- Anything else is an error
3298 ("expect subprogram name for pragma%", Assoc);
3302 ----------------------
3303 -- Set_Inline_Flags --
3304 ----------------------
3306 procedure Set_Inline_Flags (Subp : Entity_Id) is
3309 Set_Is_Inlined (Subp, True);
3312 if not Has_Pragma_Inline (Subp) then
3313 Set_Has_Pragma_Inline (Subp);
3314 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3315 Set_First_Rep_Item (Subp, N);
3318 end Set_Inline_Flags;
3320 -- Start of processing for Process_Inline
3323 Check_No_Identifiers;
3324 Check_At_Least_N_Arguments (1);
3327 Inline_Processing_Required := True;
3331 while Present (Assoc) loop
3332 Subp_Id := Expression (Assoc);
3336 if Is_Entity_Name (Subp_Id) then
3337 Subp := Entity (Subp_Id);
3339 if Subp = Any_Id then
3341 -- If previous error, avoid cascaded errors
3349 while Present (Homonym (Subp))
3350 and then Scope (Homonym (Subp)) = Current_Scope
3352 Make_Inline (Homonym (Subp));
3353 Subp := Homonym (Subp);
3360 ("inappropriate argument for pragma%", Assoc);
3363 and then Warn_On_Redundant_Constructs
3365 if Inlining_Not_Possible (Subp) then
3367 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3370 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3378 ----------------------------
3379 -- Process_Interface_Name --
3380 ----------------------------
3382 procedure Process_Interface_Name
3383 (Subprogram_Def : Entity_Id;
3389 String_Val : String_Id;
3391 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3392 -- SN is a string literal node for an interface name. This routine
3393 -- performs some minimal checks that the name is reasonable. In
3394 -- particular that no spaces or other obviously incorrect characters
3395 -- appear. This is only a warning, since any characters are allowed.
3397 ----------------------------------
3398 -- Check_Form_Of_Interface_Name --
3399 ----------------------------------
3401 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3402 S : constant String_Id := Strval (Expr_Value_S (SN));
3403 SL : constant Nat := String_Length (S);
3408 Error_Msg_N ("interface name cannot be null string", SN);
3411 for J in 1 .. SL loop
3412 C := Get_String_Char (S, J);
3414 if Warn_On_Export_Import
3415 and then (not In_Character_Range (C)
3416 or else Get_Character (C) = ' '
3417 or else Get_Character (C) = ',')
3420 ("?interface name contains illegal character", SN);
3423 end Check_Form_Of_Interface_Name;
3425 -- Start of processing for Process_Interface_Name
3428 if No (Link_Arg) then
3429 if No (Ext_Arg) then
3432 elsif Chars (Ext_Arg) = Name_Link_Name then
3434 Link_Nam := Expression (Ext_Arg);
3437 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3438 Ext_Nam := Expression (Ext_Arg);
3443 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3444 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3445 Ext_Nam := Expression (Ext_Arg);
3446 Link_Nam := Expression (Link_Arg);
3449 -- Check expressions for external name and link name are static
3451 if Present (Ext_Nam) then
3452 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3453 Check_Form_Of_Interface_Name (Ext_Nam);
3455 -- Verify that the external name is not the name of a local
3456 -- entity, which would hide the imported one and lead to
3457 -- run-time surprises. The problem can only arise for entities
3458 -- declared in a package body (otherwise the external name is
3459 -- fully qualified and won't conflict).
3467 if Prag_Id = Pragma_Import then
3468 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3470 E := Entity_Id (Get_Name_Table_Info (Nam));
3472 if Nam /= Chars (Subprogram_Def)
3473 and then Present (E)
3474 and then not Is_Overloadable (E)
3475 and then Is_Immediately_Visible (E)
3476 and then not Is_Imported (E)
3477 and then Ekind (Scope (E)) = E_Package
3481 while Present (Par) loop
3482 if Nkind (Par) = N_Package_Body then
3483 Error_Msg_Sloc := Sloc (E);
3485 ("imported entity is hidden by & declared#",
3490 Par := Parent (Par);
3497 if Present (Link_Nam) then
3498 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3499 Check_Form_Of_Interface_Name (Link_Nam);
3502 -- If there is no link name, just set the external name
3504 if No (Link_Nam) then
3505 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3507 -- For the Link_Name case, the given literal is preceded by an
3508 -- asterisk, which indicates to GCC that the given name should
3509 -- be taken literally, and in particular that no prepending of
3510 -- underlines should occur, even in systems where this is the
3515 Store_String_Char (Get_Char_Code ('*'));
3516 String_Val := Strval (Expr_Value_S (Link_Nam));
3518 for J in 1 .. String_Length (String_Val) loop
3519 Store_String_Char (Get_String_Char (String_Val, J));
3523 Make_String_Literal (Sloc (Link_Nam), End_String);
3526 Set_Encoded_Interface_Name
3527 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3528 Check_Duplicated_Export_Name (Link_Nam);
3529 end Process_Interface_Name;
3531 -----------------------------------------
3532 -- Process_Interrupt_Or_Attach_Handler --
3533 -----------------------------------------
3535 procedure Process_Interrupt_Or_Attach_Handler is
3536 Arg1_X : constant Node_Id := Expression (Arg1);
3537 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3538 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3541 Set_Is_Interrupt_Handler (Handler_Proc);
3543 -- If the pragma is not associated with a handler procedure
3544 -- within a protected type, then it must be for a nonprotected
3545 -- procedure for the AAMP target, in which case we don't
3546 -- associate a representation item with the procedure's scope.
3548 if Ekind (Proc_Scope) = E_Protected_Type then
3549 if Prag_Id = Pragma_Interrupt_Handler
3551 Prag_Id = Pragma_Attach_Handler
3553 Record_Rep_Item (Proc_Scope, N);
3556 end Process_Interrupt_Or_Attach_Handler;
3558 --------------------------------------------------
3559 -- Process_Restrictions_Or_Restriction_Warnings --
3560 --------------------------------------------------
3562 -- Note: some of the simple identifier cases were handled in par-prag,
3563 -- but it is harmless (and more straightforward) to simply handle all
3564 -- cases here, even if it means we repeat a bit of work in some cases.
3566 procedure Process_Restrictions_Or_Restriction_Warnings is
3568 R_Id : Restriction_Id;
3573 procedure Check_Unit_Name (N : Node_Id);
3574 -- Checks unit name parameter for No_Dependence. Returns if it has
3575 -- an appropriate form, otherwise raises pragma argument error.
3577 procedure Set_Warning (R : All_Restrictions);
3578 -- If this is a Restriction_Warnings pragma, set warning flag,
3579 -- otherwise reset the flag.
3581 ---------------------
3582 -- Check_Unit_Name --
3583 ---------------------
3585 procedure Check_Unit_Name (N : Node_Id) is
3587 if Nkind (N) = N_Selected_Component then
3588 Check_Unit_Name (Prefix (N));
3589 Check_Unit_Name (Selector_Name (N));
3591 elsif Nkind (N) = N_Identifier then
3596 ("wrong form for unit name for No_Dependence", N);
3598 end Check_Unit_Name;
3604 procedure Set_Warning (R : All_Restrictions) is
3606 if Prag_Id = Pragma_Restriction_Warnings then
3607 Restriction_Warnings (R) := True;
3609 Restriction_Warnings (R) := False;
3613 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3616 Check_Ada_83_Warning;
3617 Check_At_Least_N_Arguments (1);
3618 Check_Valid_Configuration_Pragma;
3621 while Present (Arg) loop
3623 Expr := Expression (Arg);
3625 -- Case of no restriction identifier present
3627 if Id = No_Name then
3628 if Nkind (Expr) /= N_Identifier then
3630 ("invalid form for restriction", Arg);
3635 (Process_Restriction_Synonyms (Expr));
3637 if R_Id not in All_Boolean_Restrictions then
3639 ("invalid restriction identifier", Arg);
3642 if Implementation_Restriction (R_Id) then
3644 (No_Implementation_Restrictions, Arg);
3647 Set_Restriction (R_Id, N);
3650 -- A very special case that must be processed here:
3651 -- pragma Restrictions (No_Exceptions) turns off
3652 -- all run-time checking. This is a bit dubious in
3653 -- terms of the formal language definition, but it
3654 -- is what is intended by RM H.4(12).
3656 if R_Id = No_Exceptions then
3657 Scope_Suppress := (others => True);
3660 -- Case of No_Dependence => unit-name. Note that the parser
3661 -- already made the necessary entry in the No_Dependence table.
3663 elsif Id = Name_No_Dependence then
3664 Check_Unit_Name (Expr);
3666 -- All other cases of restriction identifier present
3669 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3670 Analyze_And_Resolve (Expr, Any_Integer);
3672 if R_Id not in All_Parameter_Restrictions then
3674 ("invalid restriction parameter identifier", Arg);
3676 elsif not Is_OK_Static_Expression (Expr) then
3677 Flag_Non_Static_Expr
3678 ("value must be static expression!", Expr);
3681 elsif not Is_Integer_Type (Etype (Expr))
3682 or else Expr_Value (Expr) < 0
3685 ("value must be non-negative integer", Arg);
3687 -- Restriction pragma is active
3690 Val := Expr_Value (Expr);
3692 if not UI_Is_In_Int_Range (Val) then
3694 ("pragma ignored, value too large?", Arg);
3696 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3704 end Process_Restrictions_Or_Restriction_Warnings;
3706 ---------------------------------
3707 -- Process_Suppress_Unsuppress --
3708 ---------------------------------
3710 -- Note: this procedure makes entries in the check suppress data
3711 -- structures managed by Sem. See spec of package Sem for full
3712 -- details on how we handle recording of check suppression.
3714 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3719 In_Package_Spec : constant Boolean :=
3720 (Ekind (Current_Scope) = E_Package
3722 Ekind (Current_Scope) = E_Generic_Package)
3723 and then not In_Package_Body (Current_Scope);
3725 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3726 -- Used to suppress a single check on the given entity
3728 --------------------------------
3729 -- Suppress_Unsuppress_Echeck --
3730 --------------------------------
3732 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3733 ESR : constant Entity_Check_Suppress_Record :=
3736 Suppress => Suppress_Case);
3739 Set_Checks_May_Be_Suppressed (E);
3741 if In_Package_Spec then
3742 Global_Entity_Suppress.Append (ESR);
3744 Local_Entity_Suppress.Append (ESR);
3747 -- If this is a first subtype, and the base type is distinct,
3748 -- then also set the suppress flags on the base type.
3750 if Is_First_Subtype (E)
3751 and then Etype (E) /= E
3753 Suppress_Unsuppress_Echeck (Etype (E), C);
3755 end Suppress_Unsuppress_Echeck;
3757 -- Start of processing for Process_Suppress_Unsuppress
3760 -- Suppress/Unsuppress can appear as a configuration pragma,
3761 -- or in a declarative part or a package spec (RM 11.5(5))
3763 if not Is_Configuration_Pragma then
3764 Check_Is_In_Decl_Part_Or_Package_Spec;
3767 Check_At_Least_N_Arguments (1);
3768 Check_At_Most_N_Arguments (2);
3769 Check_No_Identifier (Arg1);
3770 Check_Arg_Is_Identifier (Arg1);
3772 if not Is_Check_Name (Chars (Expression (Arg1))) then
3774 ("argument of pragma% is not valid check name", Arg1);
3776 C := Get_Check_Id (Chars (Expression (Arg1)));
3779 if Arg_Count = 1 then
3781 -- Make an entry in the local scope suppress table. This is the
3782 -- table that directly shows the current value of the scope
3783 -- suppress check for any check id value.
3785 if C = All_Checks then
3787 -- For All_Checks, we set all specific checks with the
3788 -- exception of Elaboration_Check, which is handled specially
3789 -- because of not wanting All_Checks to have the effect of
3790 -- deactivating static elaboration order processing.
3792 for J in Scope_Suppress'Range loop
3793 if J /= Elaboration_Check then
3794 Scope_Suppress (J) := Suppress_Case;
3798 -- If not All_Checks, just set appropriate entry. Note that we
3799 -- will set Elaboration_Check if this is explicitly specified.
3802 Scope_Suppress (C) := Suppress_Case;
3805 -- Also make an entry in the Local_Entity_Suppress table. See
3806 -- extended description in the package spec of Sem for details.
3808 Local_Entity_Suppress.Append
3811 Suppress => Suppress_Case));
3813 -- Case of two arguments present, where the check is
3814 -- suppressed for a specified entity (given as the second
3815 -- argument of the pragma)
3818 Check_Optional_Identifier (Arg2, Name_On);
3819 E_Id := Expression (Arg2);
3822 if not Is_Entity_Name (E_Id) then
3824 ("second argument of pragma% must be entity name", Arg2);
3833 -- Enforce RM 11.5(7) which requires that for a pragma that
3834 -- appears within a package spec, the named entity must be
3835 -- within the package spec. We allow the package name itself
3836 -- to be mentioned since that makes sense, although it is not
3837 -- strictly allowed by 11.5(7).
3840 and then E /= Current_Scope
3841 and then Scope (E) /= Current_Scope
3844 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3848 -- Loop through homonyms. As noted below, in the case of a package
3849 -- spec, only homonyms within the package spec are considered.
3852 Suppress_Unsuppress_Echeck (E, C);
3854 if Is_Generic_Instance (E)
3855 and then Is_Subprogram (E)
3856 and then Present (Alias (E))
3858 Suppress_Unsuppress_Echeck (Alias (E), C);
3861 -- Move to next homonym
3866 -- If we are within a package specification, the
3867 -- pragma only applies to homonyms in the same scope.
3869 exit when In_Package_Spec
3870 and then Scope (E) /= Current_Scope;
3873 end Process_Suppress_Unsuppress;
3879 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3881 if Is_Imported (E) then
3883 ("cannot export entity& that was previously imported", Arg);
3885 elsif Present (Address_Clause (E)) then
3887 ("cannot export entity& that has an address clause", Arg);
3890 Set_Is_Exported (E);
3892 -- Generate a reference for entity explicitly, because the
3893 -- identifier may be overloaded and name resolution will not
3896 Generate_Reference (E, Arg);
3898 -- Deal with exporting non-library level entity
3900 if not Is_Library_Level_Entity (E) then
3902 -- Not allowed at all for subprograms
3904 if Is_Subprogram (E) then
3905 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3907 -- Otherwise set public and statically allocated
3911 Set_Is_Statically_Allocated (E);
3913 -- Warn if the corresponding W flag is set and the pragma
3914 -- comes from source. The latter may not be true e.g. on
3915 -- VMS where we expand export pragmas for exception codes
3916 -- associated with imported or exported exceptions. We do
3917 -- not want to generate a warning for something that the
3918 -- user did not write.
3920 if Warn_On_Export_Import
3921 and then Comes_From_Source (Arg)
3924 ("?& has been made static as a result of Export", Arg, E);
3926 ("\this usage is non-standard and non-portable", Arg);
3931 if Warn_On_Export_Import and then Is_Type (E) then
3933 ("exporting a type has no effect?", Arg, E);
3936 if Warn_On_Export_Import and Inside_A_Generic then
3938 ("all instances of& will have the same external name?", Arg, E);
3942 ----------------------------------------------
3943 -- Set_Extended_Import_Export_External_Name --
3944 ----------------------------------------------
3946 procedure Set_Extended_Import_Export_External_Name
3947 (Internal_Ent : Entity_Id;
3948 Arg_External : Node_Id)
3950 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3954 if No (Arg_External) then
3958 Check_Arg_Is_External_Name (Arg_External);
3960 if Nkind (Arg_External) = N_String_Literal then
3961 if String_Length (Strval (Arg_External)) = 0 then
3964 New_Name := Adjust_External_Name_Case (Arg_External);
3967 elsif Nkind (Arg_External) = N_Identifier then
3968 New_Name := Get_Default_External_Name (Arg_External);
3970 -- Check_Arg_Is_External_Name should let through only
3971 -- identifiers and string literals or static string
3972 -- expressions (which are folded to string literals).
3975 raise Program_Error;
3978 -- If we already have an external name set (by a prior normal
3979 -- Import or Export pragma), then the external names must match
3981 if Present (Interface_Name (Internal_Ent)) then
3982 Check_Matching_Internal_Names : declare
3983 S1 : constant String_Id := Strval (Old_Name);
3984 S2 : constant String_Id := Strval (New_Name);
3987 -- Called if names do not match
3993 procedure Mismatch is
3995 Error_Msg_Sloc := Sloc (Old_Name);
3997 ("external name does not match that given #",
4001 -- Start of processing for Check_Matching_Internal_Names
4004 if String_Length (S1) /= String_Length (S2) then
4008 for J in 1 .. String_Length (S1) loop
4009 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4014 end Check_Matching_Internal_Names;
4016 -- Otherwise set the given name
4019 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4020 Check_Duplicated_Export_Name (New_Name);
4022 end Set_Extended_Import_Export_External_Name;
4028 procedure Set_Imported (E : Entity_Id) is
4030 Error_Msg_Sloc := Sloc (E);
4032 if Is_Exported (E) or else Is_Imported (E) then
4033 Error_Msg_NE ("import of& declared# not allowed", N, E);
4035 if Is_Exported (E) then
4036 Error_Msg_N ("\entity was previously exported", N);
4038 Error_Msg_N ("\entity was previously imported", N);
4041 Error_Pragma ("\(pragma% applies to all previous entities)");
4044 Set_Is_Imported (E);
4046 -- If the entity is an object that is not at the library
4047 -- level, then it is statically allocated. We do not worry
4048 -- about objects with address clauses in this context since
4049 -- they are not really imported in the linker sense.
4052 and then not Is_Library_Level_Entity (E)
4053 and then No (Address_Clause (E))
4055 Set_Is_Statically_Allocated (E);
4060 -------------------------
4061 -- Set_Mechanism_Value --
4062 -------------------------
4064 -- Note: the mechanism name has not been analyzed (and cannot indeed
4065 -- be analyzed, since it is semantic nonsense), so we get it in the
4066 -- exact form created by the parser.
4068 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4072 procedure Bad_Class;
4073 -- Signal bad descriptor class name
4075 procedure Bad_Mechanism;
4076 -- Signal bad mechanism name
4082 procedure Bad_Class is
4084 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4087 -------------------------
4088 -- Bad_Mechanism_Value --
4089 -------------------------
4091 procedure Bad_Mechanism is
4093 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4096 -- Start of processing for Set_Mechanism_Value
4099 if Mechanism (Ent) /= Default_Mechanism then
4101 ("mechanism for & has already been set", Mech_Name, Ent);
4104 -- MECHANISM_NAME ::= value | reference | descriptor
4106 if Nkind (Mech_Name) = N_Identifier then
4107 if Chars (Mech_Name) = Name_Value then
4108 Set_Mechanism (Ent, By_Copy);
4111 elsif Chars (Mech_Name) = Name_Reference then
4112 Set_Mechanism (Ent, By_Reference);
4115 elsif Chars (Mech_Name) = Name_Descriptor then
4116 Check_VMS (Mech_Name);
4117 Set_Mechanism (Ent, By_Descriptor);
4120 elsif Chars (Mech_Name) = Name_Copy then
4122 ("bad mechanism name, Value assumed", Mech_Name);
4128 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
4129 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4131 -- Note: this form is parsed as an indexed component
4133 elsif Nkind (Mech_Name) = N_Indexed_Component then
4134 Class := First (Expressions (Mech_Name));
4136 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4137 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4138 or else Present (Next (Class))
4143 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4144 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4146 -- Note: this form is parsed as a function call
4148 elsif Nkind (Mech_Name) = N_Function_Call then
4150 Param := First (Parameter_Associations (Mech_Name));
4152 if Nkind (Name (Mech_Name)) /= N_Identifier
4153 or else Chars (Name (Mech_Name)) /= Name_Descriptor
4154 or else Present (Next (Param))
4155 or else No (Selector_Name (Param))
4156 or else Chars (Selector_Name (Param)) /= Name_Class
4160 Class := Explicit_Actual_Parameter (Param);
4167 -- Fall through here with Class set to descriptor class name
4169 Check_VMS (Mech_Name);
4171 if Nkind (Class) /= N_Identifier then
4174 elsif Chars (Class) = Name_UBS then
4175 Set_Mechanism (Ent, By_Descriptor_UBS);
4177 elsif Chars (Class) = Name_UBSB then
4178 Set_Mechanism (Ent, By_Descriptor_UBSB);
4180 elsif Chars (Class) = Name_UBA then
4181 Set_Mechanism (Ent, By_Descriptor_UBA);
4183 elsif Chars (Class) = Name_S then
4184 Set_Mechanism (Ent, By_Descriptor_S);
4186 elsif Chars (Class) = Name_SB then
4187 Set_Mechanism (Ent, By_Descriptor_SB);
4189 elsif Chars (Class) = Name_A then
4190 Set_Mechanism (Ent, By_Descriptor_A);
4192 elsif Chars (Class) = Name_NCA then
4193 Set_Mechanism (Ent, By_Descriptor_NCA);
4198 end Set_Mechanism_Value;
4200 ---------------------------
4201 -- Set_Ravenscar_Profile --
4202 ---------------------------
4204 -- The tasks to be done here are
4206 -- Set required policies
4208 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4209 -- pragma Locking_Policy (Ceiling_Locking)
4211 -- Set Detect_Blocking mode
4213 -- Set required restrictions (see System.Rident for detailed list)
4215 procedure Set_Ravenscar_Profile (N : Node_Id) is
4217 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4219 if Task_Dispatching_Policy /= ' '
4220 and then Task_Dispatching_Policy /= 'F'
4222 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4223 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4225 -- Set the FIFO_Within_Priorities policy, but always
4226 -- preserve System_Location since we like the error
4227 -- message with the run time name.
4230 Task_Dispatching_Policy := 'F';
4232 if Task_Dispatching_Policy_Sloc /= System_Location then
4233 Task_Dispatching_Policy_Sloc := Loc;
4237 -- pragma Locking_Policy (Ceiling_Locking)
4239 if Locking_Policy /= ' '
4240 and then Locking_Policy /= 'C'
4242 Error_Msg_Sloc := Locking_Policy_Sloc;
4243 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4245 -- Set the Ceiling_Locking policy, but always preserve
4246 -- System_Location since we like the error message with the
4250 Locking_Policy := 'C';
4252 if Locking_Policy_Sloc /= System_Location then
4253 Locking_Policy_Sloc := Loc;
4257 -- pragma Detect_Blocking
4259 Detect_Blocking := True;
4261 -- Set the corresponding restrictions
4263 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4264 end Set_Ravenscar_Profile;
4266 -- Start of processing for Analyze_Pragma
4269 if not Is_Pragma_Name (Chars (N)) then
4270 if Warn_On_Unrecognized_Pragma then
4271 Error_Pragma ("unrecognized pragma%!?");
4276 Prag_Id := Get_Pragma_Id (Chars (N));
4286 if Present (Pragma_Argument_Associations (N)) then
4287 Arg1 := First (Pragma_Argument_Associations (N));
4289 if Present (Arg1) then
4290 Arg2 := Next (Arg1);
4292 if Present (Arg2) then
4293 Arg3 := Next (Arg2);
4295 if Present (Arg3) then
4296 Arg4 := Next (Arg3);
4302 -- Count number of arguments
4309 while Present (Arg_Node) loop
4310 Arg_Count := Arg_Count + 1;
4315 -- An enumeration type defines the pragmas that are supported by the
4316 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4317 -- into the corresponding enumeration value for the following case.
4325 -- pragma Abort_Defer;
4327 when Pragma_Abort_Defer =>
4329 Check_Arg_Count (0);
4331 -- The only required semantic processing is to check the
4332 -- placement. This pragma must appear at the start of the
4333 -- statement sequence of a handled sequence of statements.
4335 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4336 or else N /= First (Statements (Parent (N)))
4347 -- Note: this pragma also has some specific processing in Par.Prag
4348 -- because we want to set the Ada version mode during parsing.
4350 when Pragma_Ada_83 =>
4352 Ada_Version := Ada_83;
4353 Ada_Version_Explicit := Ada_Version;
4354 Check_Arg_Count (0);
4362 -- Note: this pragma also has some specific processing in Par.Prag
4363 -- because we want to set the Ada 83 version mode during parsing.
4365 when Pragma_Ada_95 =>
4367 Ada_Version := Ada_95;
4368 Ada_Version_Explicit := Ada_Version;
4369 Check_Arg_Count (0);
4376 -- pragma Ada_05 (LOCAL_NAME);
4378 -- Note: this pragma also has some specific processing in Par.Prag
4379 -- because we want to set the Ada 2005 version mode during parsing.
4381 when Pragma_Ada_05 => declare
4387 if Arg_Count = 1 then
4388 Check_Arg_Is_Local_Name (Arg1);
4389 E_Id := Expression (Arg1);
4391 if Etype (E_Id) = Any_Type then
4395 Set_Is_Ada_2005 (Entity (E_Id));
4398 Check_Arg_Count (0);
4399 Ada_Version := Ada_05;
4400 Ada_Version_Explicit := Ada_Version;
4404 ----------------------
4405 -- All_Calls_Remote --
4406 ----------------------
4408 -- pragma All_Calls_Remote [(library_package_NAME)];
4410 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4411 Lib_Entity : Entity_Id;
4414 Check_Ada_83_Warning;
4415 Check_Valid_Library_Unit_Pragma;
4417 if Nkind (N) = N_Null_Statement then
4421 Lib_Entity := Find_Lib_Unit_Name;
4423 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
4425 if Present (Lib_Entity)
4426 and then not Debug_Flag_U
4428 if not Is_Remote_Call_Interface (Lib_Entity) then
4429 Error_Pragma ("pragma% only apply to rci unit");
4431 -- Set flag for entity of the library unit
4434 Set_Has_All_Calls_Remote (Lib_Entity);
4438 end All_Calls_Remote;
4444 -- pragma Annotate (IDENTIFIER {, ARG});
4445 -- ARG ::= NAME | EXPRESSION
4447 when Pragma_Annotate => Annotate : begin
4449 Check_At_Least_N_Arguments (1);
4450 Check_Arg_Is_Identifier (Arg1);
4453 Arg : Node_Id := Arg2;
4457 while Present (Arg) loop
4458 Exp := Expression (Arg);
4461 if Is_Entity_Name (Exp) then
4464 elsif Nkind (Exp) = N_String_Literal then
4465 Resolve (Exp, Standard_String);
4467 elsif Is_Overloaded (Exp) then
4468 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4483 -- pragma Assert ([Check =>] Boolean_EXPRESSION
4484 -- [, [Message =>] Static_String_EXPRESSION]);
4486 when Pragma_Assert =>
4487 Check_At_Least_N_Arguments (1);
4488 Check_At_Most_N_Arguments (2);
4489 Check_Arg_Order ((Name_Check, Name_Message));
4490 Check_Optional_Identifier (Arg1, Name_Check);
4492 if Arg_Count > 1 then
4493 Check_Optional_Identifier (Arg2, Name_Message);
4494 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4497 -- If expansion is active and assertions are inactive, then
4498 -- we rewrite the Assertion as:
4500 -- if False and then condition then
4504 -- The reason we do this rewriting during semantic analysis
4505 -- rather than as part of normal expansion is that we cannot
4506 -- analyze and expand the code for the boolean expression
4507 -- directly, or it may cause insertion of actions that would
4508 -- escape the attempt to suppress the assertion code.
4510 if Expander_Active and not Assertions_Enabled then
4512 Make_If_Statement (Loc,
4515 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4516 Right_Opnd => Get_Pragma_Arg (Arg1)),
4517 Then_Statements => New_List (
4518 Make_Null_Statement (Loc))));
4522 -- Otherwise (if assertions are enabled, or if we are not
4523 -- operating with expansion active), then we just analyze
4524 -- and resolve the expression.
4527 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4530 ----------------------
4531 -- Assertion_Policy --
4532 ----------------------
4534 -- pragma Assertion_Policy (Check | Ignore)
4536 when Pragma_Assertion_Policy =>
4537 Check_Arg_Count (1);
4538 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
4539 Assertions_Enabled := Chars (Expression (Arg1)) = Name_Check;
4545 -- pragma AST_Entry (entry_IDENTIFIER);
4547 when Pragma_AST_Entry => AST_Entry : declare
4553 Check_Arg_Count (1);
4554 Check_No_Identifiers;
4555 Check_Arg_Is_Local_Name (Arg1);
4556 Ent := Entity (Expression (Arg1));
4558 -- Note: the implementation of the AST_Entry pragma could handle
4559 -- the entry family case fine, but for now we are consistent with
4560 -- the DEC rules, and do not allow the pragma, which of course
4561 -- has the effect of also forbidding the attribute.
4563 if Ekind (Ent) /= E_Entry then
4565 ("pragma% argument must be simple entry name", Arg1);
4567 elsif Is_AST_Entry (Ent) then
4569 ("duplicate % pragma for entry", Arg1);
4571 elsif Has_Homonym (Ent) then
4573 ("pragma% argument cannot specify overloaded entry", Arg1);
4577 FF : constant Entity_Id := First_Formal (Ent);
4580 if Present (FF) then
4581 if Present (Next_Formal (FF)) then
4583 ("entry for pragma% can have only one argument",
4586 elsif Parameter_Mode (FF) /= E_In_Parameter then
4588 ("entry parameter for pragma% must have mode IN",
4594 Set_Is_AST_Entry (Ent);
4602 -- pragma Asynchronous (LOCAL_NAME);
4604 when Pragma_Asynchronous => Asynchronous : declare
4612 procedure Process_Async_Pragma;
4613 -- Common processing for procedure and access-to-procedure case
4615 --------------------------
4616 -- Process_Async_Pragma --
4617 --------------------------
4619 procedure Process_Async_Pragma is
4621 if not Present (L) then
4622 Set_Is_Asynchronous (Nm);
4626 -- The formals should be of mode IN (RM E.4.1(6))
4629 while Present (S) loop
4630 Formal := Defining_Identifier (S);
4632 if Nkind (Formal) = N_Defining_Identifier
4633 and then Ekind (Formal) /= E_In_Parameter
4636 ("pragma% procedure can only have IN parameter",
4643 Set_Is_Asynchronous (Nm);
4644 end Process_Async_Pragma;
4646 -- Start of processing for pragma Asynchronous
4649 Check_Ada_83_Warning;
4650 Check_No_Identifiers;
4651 Check_Arg_Count (1);
4652 Check_Arg_Is_Local_Name (Arg1);
4654 if Debug_Flag_U then
4658 C_Ent := Cunit_Entity (Current_Sem_Unit);
4659 Analyze (Expression (Arg1));
4660 Nm := Entity (Expression (Arg1));
4662 if not Is_Remote_Call_Interface (C_Ent)
4663 and then not Is_Remote_Types (C_Ent)
4665 -- This pragma should only appear in an RCI or Remote Types
4666 -- unit (RM E.4.1(4))
4669 ("pragma% not in Remote_Call_Interface or " &
4670 "Remote_Types unit");
4673 if Ekind (Nm) = E_Procedure
4674 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4676 if not Is_Remote_Call_Interface (Nm) then
4678 ("pragma% cannot be applied on non-remote procedure",
4682 L := Parameter_Specifications (Parent (Nm));
4683 Process_Async_Pragma;
4686 elsif Ekind (Nm) = E_Function then
4688 ("pragma% cannot be applied to function", Arg1);
4690 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
4692 if Is_Record_Type (Nm) then
4693 -- A record type that is the Equivalent_Type for
4694 -- a remote access-to-subprogram type.
4696 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4699 -- A non-expanded RAS type (case where distribution is
4702 N := Declaration_Node (Nm);
4705 if Nkind (N) = N_Full_Type_Declaration
4706 and then Nkind (Type_Definition (N)) =
4707 N_Access_Procedure_Definition
4709 L := Parameter_Specifications (Type_Definition (N));
4710 Process_Async_Pragma;
4712 if Is_Asynchronous (Nm)
4713 and then Expander_Active
4714 and then Get_PCS_Name /= Name_No_DSA
4716 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
4721 ("pragma% cannot reference access-to-function type",
4725 -- Only other possibility is Access-to-class-wide type
4727 elsif Is_Access_Type (Nm)
4728 and then Is_Class_Wide_Type (Designated_Type (Nm))
4730 Check_First_Subtype (Arg1);
4731 Set_Is_Asynchronous (Nm);
4732 if Expander_Active then
4733 RACW_Type_Is_Asynchronous (Nm);
4737 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4745 -- pragma Atomic (LOCAL_NAME);
4747 when Pragma_Atomic =>
4748 Process_Atomic_Shared_Volatile;
4750 -----------------------
4751 -- Atomic_Components --
4752 -----------------------
4754 -- pragma Atomic_Components (array_LOCAL_NAME);
4756 -- This processing is shared by Volatile_Components
4758 when Pragma_Atomic_Components |
4759 Pragma_Volatile_Components =>
4761 Atomic_Components : declare
4768 Check_Ada_83_Warning;
4769 Check_No_Identifiers;
4770 Check_Arg_Count (1);
4771 Check_Arg_Is_Local_Name (Arg1);
4772 E_Id := Expression (Arg1);
4774 if Etype (E_Id) = Any_Type then
4780 if Rep_Item_Too_Early (E, N)
4782 Rep_Item_Too_Late (E, N)
4787 D := Declaration_Node (E);
4790 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4792 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4793 and then Nkind (D) = N_Object_Declaration
4794 and then Nkind (Object_Definition (D)) =
4795 N_Constrained_Array_Definition)
4797 -- The flag is set on the object, or on the base type
4799 if Nkind (D) /= N_Object_Declaration then
4803 Set_Has_Volatile_Components (E);
4805 if Prag_Id = Pragma_Atomic_Components then
4806 Set_Has_Atomic_Components (E);
4808 if Is_Packed (E) then
4809 Set_Is_Packed (E, False);
4812 ("?Pack canceled, cannot pack atomic components",
4818 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4820 end Atomic_Components;
4822 --------------------
4823 -- Attach_Handler --
4824 --------------------
4826 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4828 when Pragma_Attach_Handler =>
4829 Check_Ada_83_Warning;
4830 Check_No_Identifiers;
4831 Check_Arg_Count (2);
4833 if No_Run_Time_Mode then
4834 Error_Msg_CRT ("Attach_Handler pragma", N);
4836 Check_Interrupt_Or_Attach_Handler;
4838 -- The expression that designates the attribute may
4839 -- depend on a discriminant, and is therefore a per-
4840 -- object expression, to be expanded in the init proc.
4841 -- If expansion is enabled, perform semantic checks
4844 if Expander_Active then
4846 Temp : constant Node_Id :=
4847 New_Copy_Tree (Expression (Arg2));
4849 Set_Parent (Temp, N);
4850 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4854 Analyze (Expression (Arg2));
4855 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4858 Process_Interrupt_Or_Attach_Handler;
4861 --------------------
4862 -- C_Pass_By_Copy --
4863 --------------------
4865 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4867 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4873 Check_Valid_Configuration_Pragma;
4874 Check_Arg_Count (1);
4875 Check_Optional_Identifier (Arg1, "max_size");
4877 Arg := Expression (Arg1);
4878 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4880 Val := Expr_Value (Arg);
4884 ("maximum size for pragma% must be positive", Arg1);
4886 elsif UI_Is_In_Int_Range (Val) then
4887 Default_C_Record_Mechanism := UI_To_Int (Val);
4889 -- If a giant value is given, Int'Last will do well enough.
4890 -- If sometime someone complains that a record larger than
4891 -- two gigabytes is not copied, we will worry about it then!
4894 Default_C_Record_Mechanism := Mechanism_Type'Last;
4902 -- pragma Comment (static_string_EXPRESSION)
4904 -- Processing for pragma Comment shares the circuitry for
4905 -- pragma Ident. The only differences are that Ident enforces
4906 -- a limit of 31 characters on its argument, and also enforces
4907 -- limitations on placement for DEC compatibility. Pragma
4908 -- Comment shares neither of these restrictions.
4914 -- pragma Common_Object (
4915 -- [Internal =>] LOCAL_NAME,
4916 -- [, [External =>] EXTERNAL_SYMBOL]
4917 -- [, [Size =>] EXTERNAL_SYMBOL]);
4919 -- Processing for this pragma is shared with Psect_Object
4921 --------------------------
4922 -- Compile_Time_Warning --
4923 --------------------------
4925 -- pragma Compile_Time_Warning
4926 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4928 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4929 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4933 Check_Arg_Count (2);
4934 Check_No_Identifiers;
4935 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4936 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4938 if Compile_Time_Known_Value (Arg1x) then
4939 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4940 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4941 Add_Char_To_Name_Buffer ('?');
4944 Msg : String (1 .. Name_Len) :=
4945 Name_Buffer (1 .. Name_Len);
4950 -- This loop looks for multiple lines separated by
4951 -- ASCII.LF and breaks them into continuation error
4952 -- messages marked with the usual back slash.
4955 for S in 2 .. Msg'Length - 1 loop
4956 if Msg (S) = ASCII.LF then
4958 Error_Msg_N (Msg (B .. S), Arg1);
4964 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4968 end Compile_Time_Warning;
4970 ----------------------------
4971 -- Complex_Representation --
4972 ----------------------------
4974 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4976 when Pragma_Complex_Representation => Complex_Representation : declare
4983 Check_Arg_Count (1);
4984 Check_Optional_Identifier (Arg1, Name_Entity);
4985 Check_Arg_Is_Local_Name (Arg1);
4986 E_Id := Expression (Arg1);
4988 if Etype (E_Id) = Any_Type then
4994 if not Is_Record_Type (E) then
4996 ("argument for pragma% must be record type", Arg1);
4999 Ent := First_Entity (E);
5002 or else No (Next_Entity (Ent))
5003 or else Present (Next_Entity (Next_Entity (Ent)))
5004 or else not Is_Floating_Point_Type (Etype (Ent))
5005 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5008 ("record for pragma% must have two fields of same fpt type",
5012 Set_Has_Complex_Representation (Base_Type (E));
5014 end Complex_Representation;
5016 -------------------------
5017 -- Component_Alignment --
5018 -------------------------
5020 -- pragma Component_Alignment (
5021 -- [Form =>] ALIGNMENT_CHOICE
5022 -- [, [Name =>] type_LOCAL_NAME]);
5024 -- ALIGNMENT_CHOICE ::=
5026 -- | Component_Size_4
5030 when Pragma_Component_Alignment => Component_AlignmentP : declare
5031 Args : Args_List (1 .. 2);
5032 Names : constant Name_List (1 .. 2) := (
5036 Form : Node_Id renames Args (1);
5037 Name : Node_Id renames Args (2);
5039 Atype : Component_Alignment_Kind;
5044 Gather_Associations (Names, Args);
5047 Error_Pragma ("missing Form argument for pragma%");
5050 Check_Arg_Is_Identifier (Form);
5052 -- Get proper alignment, note that Default = Component_Size
5053 -- on all machines we have so far, and we want to set this
5054 -- value rather than the default value to indicate that it
5055 -- has been explicitly set (and thus will not get overridden
5056 -- by the default component alignment for the current scope)
5058 if Chars (Form) = Name_Component_Size then
5059 Atype := Calign_Component_Size;
5061 elsif Chars (Form) = Name_Component_Size_4 then
5062 Atype := Calign_Component_Size_4;
5064 elsif Chars (Form) = Name_Default then
5065 Atype := Calign_Component_Size;
5067 elsif Chars (Form) = Name_Storage_Unit then
5068 Atype := Calign_Storage_Unit;
5072 ("invalid Form parameter for pragma%", Form);
5075 -- Case with no name, supplied, affects scope table entry
5079 (Scope_Stack.Last).Component_Alignment_Default := Atype;
5081 -- Case of name supplied
5084 Check_Arg_Is_Local_Name (Name);
5086 Typ := Entity (Name);
5089 or else Rep_Item_Too_Early (Typ, N)
5093 Typ := Underlying_Type (Typ);
5096 if not Is_Record_Type (Typ)
5097 and then not Is_Array_Type (Typ)
5100 ("Name parameter of pragma% must identify record or " &
5101 "array type", Name);
5104 -- An explicit Component_Alignment pragma overrides an
5105 -- implicit pragma Pack, but not an explicit one.
5107 if not Has_Pragma_Pack (Base_Type (Typ)) then
5108 Set_Is_Packed (Base_Type (Typ), False);
5109 Set_Component_Alignment (Base_Type (Typ), Atype);
5112 end Component_AlignmentP;
5118 -- pragma Controlled (first_subtype_LOCAL_NAME);
5120 when Pragma_Controlled => Controlled : declare
5124 Check_No_Identifiers;
5125 Check_Arg_Count (1);
5126 Check_Arg_Is_Local_Name (Arg1);
5127 Arg := Expression (Arg1);
5129 if not Is_Entity_Name (Arg)
5130 or else not Is_Access_Type (Entity (Arg))
5132 Error_Pragma_Arg ("pragma% requires access type", Arg1);
5134 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5142 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
5143 -- [Entity =>] LOCAL_NAME);
5145 when Pragma_Convention => Convention : declare
5149 Check_Arg_Order ((Name_Convention, Name_Entity));
5150 Check_Ada_83_Warning;
5151 Check_Arg_Count (2);
5152 Process_Convention (C, E);
5155 ---------------------------
5156 -- Convention_Identifier --
5157 ---------------------------
5159 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
5160 -- [Convention =>] convention_IDENTIFIER);
5162 when Pragma_Convention_Identifier => Convention_Identifier : declare
5168 Check_Arg_Order ((Name_Name, Name_Convention));
5169 Check_Arg_Count (2);
5170 Check_Optional_Identifier (Arg1, Name_Name);
5171 Check_Optional_Identifier (Arg2, Name_Convention);
5172 Check_Arg_Is_Identifier (Arg1);
5173 Check_Arg_Is_Identifier (Arg1);
5174 Idnam := Chars (Expression (Arg1));
5175 Cname := Chars (Expression (Arg2));
5177 if Is_Convention_Name (Cname) then
5178 Record_Convention_Identifier
5179 (Idnam, Get_Convention_Id (Cname));
5182 ("second arg for % pragma must be convention", Arg2);
5184 end Convention_Identifier;
5190 -- pragma CPP_Class ([Entity =>] local_NAME)
5192 when Pragma_CPP_Class => CPP_Class : declare
5195 Default_DTC : Entity_Id := Empty;
5196 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5202 Check_Arg_Count (1);
5203 Check_Optional_Identifier (Arg1, Name_Entity);
5204 Check_Arg_Is_Local_Name (Arg1);
5206 Arg := Expression (Arg1);
5209 if Etype (Arg) = Any_Type then
5213 if not Is_Entity_Name (Arg)
5214 or else not Is_Type (Entity (Arg))
5216 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5219 Typ := Entity (Arg);
5221 if not Is_Record_Type (Typ) then
5222 Error_Pragma_Arg ("pragma% applicable to a record, "
5223 & "tagged record or record extension", Arg1);
5226 Default_DTC := First_Component (Typ);
5227 while Present (Default_DTC)
5228 and then Etype (Default_DTC) /= VTP_Type
5230 Next_Component (Default_DTC);
5233 -- Case of non tagged type
5235 if not Is_Tagged_Type (Typ) then
5236 Set_Is_CPP_Class (Typ);
5238 if Present (Default_DTC) then
5240 ("only tagged records can contain vtable pointers", Arg1);
5243 -- Case of tagged type with no vtable ptr
5245 -- What is test for Typ = Root_Typ (Typ) about here ???
5247 elsif Is_Tagged_Type (Typ)
5248 and then Typ = Root_Type (Typ)
5249 and then No (Default_DTC)
5252 ("a cpp_class must contain a vtable pointer", Arg1);
5254 -- Tagged type that has a vtable ptr
5256 elsif Present (Default_DTC) then
5257 Set_Is_CPP_Class (Typ);
5258 Set_Is_Limited_Record (Typ);
5259 Set_Is_Tag (Default_DTC);
5260 Set_DT_Entry_Count (Default_DTC, No_Uint);
5262 -- Since a CPP type has no direct link to its associated tag
5263 -- most tags checks cannot be performed
5265 Set_Kill_Tag_Checks (Typ);
5266 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5268 -- Get rid of the _tag component when there was one.
5269 -- It is only useful for regular tagged types
5271 if Expander_Active and then Typ = Root_Type (Typ) then
5273 Tag_C := First_Tag_Component (Typ);
5274 C := First_Entity (Typ);
5277 Set_First_Entity (Typ, Next_Entity (Tag_C));
5280 while Next_Entity (C) /= Tag_C loop
5284 Set_Next_Entity (C, Next_Entity (Tag_C));
5290 ---------------------
5291 -- CPP_Constructor --
5292 ---------------------
5294 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5296 when Pragma_CPP_Constructor => CPP_Constructor : declare
5302 Check_Arg_Count (1);
5303 Check_Optional_Identifier (Arg1, Name_Entity);
5304 Check_Arg_Is_Local_Name (Arg1);
5306 Id := Expression (Arg1);
5307 Find_Program_Unit_Name (Id);
5309 -- If we did not find the name, we are done
5311 if Etype (Id) = Any_Type then
5315 Def_Id := Entity (Id);
5317 if Ekind (Def_Id) = E_Function
5318 and then Is_Class_Wide_Type (Etype (Def_Id))
5319 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5321 -- What the heck is this??? this pragma allows only 1 arg
5323 if Arg_Count >= 2 then
5324 Check_At_Most_N_Arguments (3);
5325 Process_Interface_Name (Def_Id, Arg2, Arg3);
5328 if No (Parameter_Specifications (Parent (Def_Id))) then
5329 Set_Has_Completion (Def_Id);
5330 Set_Is_Constructor (Def_Id);
5333 ("non-default constructors not implemented", Arg1);
5338 ("pragma% requires function returning a 'C'P'P_Class type",
5341 end CPP_Constructor;
5347 -- pragma CPP_Virtual
5348 -- [Entity =>] LOCAL_NAME
5349 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5350 -- [Position =>] static_integer_EXPRESSION]);
5352 when Pragma_CPP_Virtual => CPP_Virtual : declare
5356 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5362 Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Position));
5364 if Arg_Count = 3 then
5365 Check_Optional_Identifier (Arg2, Name_Vtable_Ptr);
5367 -- We allow Entry_Count as well as Position for the third
5368 -- parameter for back compatibility with versions of GNAT
5369 -- before version 3.12. The documentation has always said
5370 -- Position, but the code up to 3.12 said Entry_Count.
5372 if Chars (Arg3) /= Name_Entry_Count then
5373 Check_Optional_Identifier (Arg3, Name_Position);
5377 Check_Arg_Count (1);
5380 Check_Optional_Identifier (Arg1, Name_Entity);
5381 Check_Arg_Is_Local_Name (Arg1);
5383 -- First argument must be a subprogram name
5385 Arg := Expression (Arg1);
5386 Find_Program_Unit_Name (Arg);
5388 if Etype (Arg) = Any_Type then
5391 Subp := Entity (Arg);
5394 if not (Is_Subprogram (Subp)
5395 and then Is_Dispatching_Operation (Subp))
5398 ("pragma% must reference a primitive operation", Arg1);
5401 Typ := Find_Dispatching_Type (Subp);
5403 -- If only one Argument defaults are :
5404 -- . DTC_Entity is the default Vtable pointer
5405 -- . DT_Position will be set at the freezing point
5407 if Arg_Count = 1 then
5408 Set_DTC_Entity (Subp, First_Tag_Component (Typ));
5412 -- Second argument is a component name of type Vtable_Ptr
5414 Arg := Expression (Arg2);
5416 if Nkind (Arg) /= N_Identifier then
5417 Error_Msg_NE ("must be a& component name", Arg, Typ);
5421 DTC := First_Component (Typ);
5422 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5423 Next_Component (DTC);
5427 Error_Msg_NE ("must be a& component name", Arg, Typ);
5430 elsif Etype (DTC) /= VTP_Type then
5431 Wrong_Type (Arg, VTP_Type);
5435 -- Third argument is an integer (DT_Position)
5437 Arg := Expression (Arg3);
5438 Analyze_And_Resolve (Arg, Any_Integer);
5440 if not Is_Static_Expression (Arg) then
5441 Flag_Non_Static_Expr
5442 ("third argument of pragma CPP_Virtual must be static!",
5447 V := Expr_Value (Expression (Arg3));
5451 ("third argument of pragma% must be positive",
5455 Set_DTC_Entity (Subp, DTC);
5456 Set_DT_Position (Subp, V);
5465 -- pragma CPP_Vtable (
5466 -- [Entity =>] LOCAL_NAME
5467 -- [Vtable_Ptr =>] LOCAL_NAME,
5468 -- [Entry_Count =>] static_integer_EXPRESSION);
5470 when Pragma_CPP_Vtable => CPP_Vtable : declare
5473 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5480 Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Entry_Count));
5481 Check_Arg_Count (3);
5482 Check_Optional_Identifier (Arg1, Name_Entity);
5483 Check_Optional_Identifier (Arg2, Name_Vtable_Ptr);
5484 Check_Optional_Identifier (Arg3, Name_Entry_Count);
5485 Check_Arg_Is_Local_Name (Arg1);
5487 -- First argument is a record type name
5489 Arg := Expression (Arg1);
5492 if Etype (Arg) = Any_Type then
5495 Typ := Entity (Arg);
5498 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5499 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5502 -- Second argument is a component name of type Vtable_Ptr
5504 Arg := Expression (Arg2);
5506 if Nkind (Arg) /= N_Identifier then
5507 Error_Msg_NE ("must be a& component name", Arg, Typ);
5511 DTC := First_Component (Typ);
5512 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5513 Next_Component (DTC);
5517 Error_Msg_NE ("must be a& component name", Arg, Typ);
5520 elsif Etype (DTC) /= VTP_Type then
5521 Wrong_Type (DTC, VTP_Type);
5524 -- If it is the first pragma Vtable, This becomes the default tag
5526 elsif (not Is_Tag (DTC))
5527 and then DT_Entry_Count (First_Tag_Component (Typ)) = No_Uint
5529 Set_Is_Tag (First_Tag_Component (Typ), False);
5530 Set_Is_Tag (DTC, True);
5531 Set_DT_Entry_Count (DTC, No_Uint);
5534 -- Those pragmas must appear before any primitive operation
5535 -- definition (except inherited ones) otherwise the default
5538 Elmt := First_Elmt (Primitive_Operations (Typ));
5539 while Present (Elmt) loop
5540 if No (Alias (Node (Elmt))) then
5541 Error_Msg_Sloc := Sloc (Node (Elmt));
5543 ("pragma% must appear before this primitive operation");
5549 -- Third argument is an integer (DT_Entry_Count)
5551 Arg := Expression (Arg3);
5552 Analyze_And_Resolve (Arg, Any_Integer);
5554 if not Is_Static_Expression (Arg) then
5555 Flag_Non_Static_Expr
5556 ("entry count for pragma CPP_Vtable must be a static " &
5557 "expression!", Arg3);
5561 V := Expr_Value (Expression (Arg3));
5565 ("entry count for pragma% must be positive", Arg3);
5567 Set_DT_Entry_Count (DTC, V);
5576 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5578 when Pragma_Debug => Debug : begin
5581 -- Rewrite into a conditional with a static condition
5583 Rewrite (N, Make_Implicit_If_Statement (N,
5584 Condition => New_Occurrence_Of (Boolean_Literals (
5585 Debug_Pragmas_Enabled and Expander_Active), Loc),
5586 Then_Statements => New_List (
5587 Relocate_Node (Debug_Statement (N)))));
5595 -- pragma Debug_Policy (Check | Ignore)
5597 when Pragma_Debug_Policy =>
5599 Check_Arg_Count (1);
5600 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5601 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
5603 ---------------------
5604 -- Detect_Blocking --
5605 ---------------------
5607 -- pragma Detect_Blocking;
5609 when Pragma_Detect_Blocking =>
5611 Check_Arg_Count (0);
5612 Check_Valid_Configuration_Pragma;
5613 Detect_Blocking := True;
5619 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5621 when Pragma_Discard_Names => Discard_Names : declare
5626 Check_Ada_83_Warning;
5628 -- Deal with configuration pragma case
5630 if Arg_Count = 0 and then Is_Configuration_Pragma then
5631 Global_Discard_Names := True;
5634 -- Otherwise, check correct appropriate context
5637 Check_Is_In_Decl_Part_Or_Package_Spec;
5639 if Arg_Count = 0 then
5641 -- If there is no parameter, then from now on this pragma
5642 -- applies to any enumeration, exception or tagged type
5643 -- defined in the current declarative part.
5645 Set_Discard_Names (Current_Scope);
5649 Check_Arg_Count (1);
5650 Check_Optional_Identifier (Arg1, Name_On);
5651 Check_Arg_Is_Local_Name (Arg1);
5652 E_Id := Expression (Arg1);
5654 if Etype (E_Id) = Any_Type then
5660 if (Is_First_Subtype (E)
5661 and then (Is_Enumeration_Type (E)
5662 or else Is_Tagged_Type (E)))
5663 or else Ekind (E) = E_Exception
5665 Set_Discard_Names (E);
5668 ("inappropriate entity for pragma%", Arg1);
5678 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5680 when Pragma_Elaborate => Elaborate : declare
5682 Parent_Node : Node_Id;
5687 -- Pragma must be in context items list of a compilation unit
5689 if not Is_List_Member (N) then
5694 Plist := List_Containing (N);
5695 Parent_Node := Parent (Plist);
5697 if Parent_Node = Empty
5698 or else Nkind (Parent_Node) /= N_Compilation_Unit
5699 or else Context_Items (Parent_Node) /= Plist
5706 -- Must be at least one argument
5708 if Arg_Count = 0 then
5709 Error_Pragma ("pragma% requires at least one argument");
5712 -- In Ada 83 mode, there can be no items following it in the
5713 -- context list except other pragmas and implicit with clauses
5714 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5715 -- placement rule does not apply.
5717 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5720 while Present (Citem) loop
5721 if Nkind (Citem) = N_Pragma
5722 or else (Nkind (Citem) = N_With_Clause
5723 and then Implicit_With (Citem))
5728 ("(Ada 83) pragma% must be at end of context clause");
5735 -- Finally, the arguments must all be units mentioned in a with
5736 -- clause in the same context clause. Note we already checked
5737 -- (in Par.Prag) that the arguments are either identifiers or
5740 Outer : while Present (Arg) loop
5741 Citem := First (Plist);
5743 Inner : while Citem /= N loop
5744 if Nkind (Citem) = N_With_Clause
5745 and then Same_Name (Name (Citem), Expression (Arg))
5747 Set_Elaborate_Present (Citem, True);
5748 Set_Unit_Name (Expression (Arg), Name (Citem));
5750 -- With the pragma present, elaboration calls on
5751 -- subprograms from the named unit need no further
5752 -- checks, as long as the pragma appears in the current
5753 -- compilation unit. If the pragma appears in some unit
5754 -- in the context, there might still be a need for an
5755 -- Elaborate_All_Desirable from the current compilation
5756 -- to the the named unit, so we keep the check enabled.
5758 if In_Extended_Main_Source_Unit (N) then
5759 Set_Suppress_Elaboration_Warnings
5760 (Entity (Name (Citem)));
5770 ("argument of pragma% is not with'ed unit", Arg);
5776 -- Give a warning if operating in static mode with -gnatwl
5777 -- (elaboration warnings eanbled) switch set.
5779 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5781 ("?use of pragma Elaborate may not be safe", N);
5783 ("?use pragma Elaborate_All instead if possible", N);
5791 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5793 when Pragma_Elaborate_All => Elaborate_All : declare
5795 Parent_Node : Node_Id;
5800 Check_Ada_83_Warning;
5802 -- Pragma must be in context items list of a compilation unit
5804 if not Is_List_Member (N) then
5809 Plist := List_Containing (N);
5810 Parent_Node := Parent (Plist);
5812 if Parent_Node = Empty
5813 or else Nkind (Parent_Node) /= N_Compilation_Unit
5814 or else Context_Items (Parent_Node) /= Plist
5821 -- Must be at least one argument
5823 if Arg_Count = 0 then
5824 Error_Pragma ("pragma% requires at least one argument");
5827 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5828 -- have to appear at the end of the context clause, but may
5829 -- appear mixed in with other items, even in Ada 83 mode.
5831 -- Final check: the arguments must all be units mentioned in
5832 -- a with clause in the same context clause. Note that we
5833 -- already checked (in Par.Prag) that all the arguments are
5834 -- either identifiers or selected components.
5837 Outr : while Present (Arg) loop
5838 Citem := First (Plist);
5840 Innr : while Citem /= N loop
5841 if Nkind (Citem) = N_With_Clause
5842 and then Same_Name (Name (Citem), Expression (Arg))
5844 Set_Elaborate_All_Present (Citem, True);
5845 Set_Unit_Name (Expression (Arg), Name (Citem));
5847 -- Suppress warnings and elaboration checks on the named
5848 -- unit if the pragma is in the current compilation, as
5849 -- for pragma Elaborate.
5851 if In_Extended_Main_Source_Unit (N) then
5852 Set_Suppress_Elaboration_Warnings
5853 (Entity (Name (Citem)));
5862 Set_Error_Posted (N);
5864 ("argument of pragma% is not with'ed unit", Arg);
5871 --------------------
5872 -- Elaborate_Body --
5873 --------------------
5875 -- pragma Elaborate_Body [( library_unit_NAME )];
5877 when Pragma_Elaborate_Body => Elaborate_Body : declare
5878 Cunit_Node : Node_Id;
5879 Cunit_Ent : Entity_Id;
5882 Check_Ada_83_Warning;
5883 Check_Valid_Library_Unit_Pragma;
5885 if Nkind (N) = N_Null_Statement then
5889 Cunit_Node := Cunit (Current_Sem_Unit);
5890 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5892 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5894 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5896 Error_Pragma ("pragma% must refer to a spec, not a body");
5898 Set_Body_Required (Cunit_Node, True);
5899 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5901 -- If we are in dynamic elaboration mode, then we suppress
5902 -- elaboration warnings for the unit, since it is definitely
5903 -- fine NOT to do dynamic checks at the first level (and such
5904 -- checks will be suppressed because no elaboration boolean
5905 -- is created for Elaborate_Body packages).
5907 -- But in the static model of elaboration, Elaborate_Body is
5908 -- definitely NOT good enough to ensure elaboration safety on
5909 -- its own, since the body may WITH other units that are not
5910 -- safe from an elaboration point of view, so a client must
5911 -- still do an Elaborate_All on such units.
5913 -- Debug flag -gnatdD restores the old behavior of 3.13,
5914 -- where Elaborate_Body always suppressed elab warnings.
5916 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5917 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5922 ------------------------
5923 -- Elaboration_Checks --
5924 ------------------------
5926 -- pragma Elaboration_Checks (Static | Dynamic);
5928 when Pragma_Elaboration_Checks =>
5930 Check_Arg_Count (1);
5931 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5932 Dynamic_Elaboration_Checks :=
5933 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5939 -- pragma Eliminate (
5940 -- [Unit_Name =>] IDENTIFIER |
5941 -- SELECTED_COMPONENT
5942 -- [,[Entity =>] IDENTIFIER |
5943 -- SELECTED_COMPONENT |
5945 -- [,]OVERLOADING_RESOLUTION);
5947 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5950 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5953 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5955 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5956 -- Result_Type => result_SUBTYPE_NAME]
5958 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5959 -- SUBTYPE_NAME ::= STRING_LITERAL
5961 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5962 -- SOURCE_TRACE ::= STRING_LITERAL
5964 when Pragma_Eliminate => Eliminate : declare
5965 Args : Args_List (1 .. 5);
5966 Names : constant Name_List (1 .. 5) := (
5969 Name_Parameter_Types,
5971 Name_Source_Location);
5973 Unit_Name : Node_Id renames Args (1);
5974 Entity : Node_Id renames Args (2);
5975 Parameter_Types : Node_Id renames Args (3);
5976 Result_Type : Node_Id renames Args (4);
5977 Source_Location : Node_Id renames Args (5);
5981 Check_Valid_Configuration_Pragma;
5982 Gather_Associations (Names, Args);
5984 if No (Unit_Name) then
5985 Error_Pragma ("missing Unit_Name argument for pragma%");
5989 and then (Present (Parameter_Types)
5991 Present (Result_Type)
5993 Present (Source_Location))
5995 Error_Pragma ("missing Entity argument for pragma%");
5998 if (Present (Parameter_Types)
6000 Present (Result_Type))
6002 Present (Source_Location)
6005 ("parameter profile and source location cannot " &
6006 "be used together in pragma%");
6009 Process_Eliminate_Pragma
6018 -------------------------
6019 -- Explicit_Overriding --
6020 -------------------------
6022 when Pragma_Explicit_Overriding =>
6023 Check_Valid_Configuration_Pragma;
6024 Check_Arg_Count (0);
6025 Explicit_Overriding := True;
6032 -- [ Convention =>] convention_IDENTIFIER,
6033 -- [ Entity =>] local_NAME
6034 -- [, [External_Name =>] static_string_EXPRESSION ]
6035 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6037 when Pragma_Export => Export : declare
6042 Check_Ada_83_Warning;
6048 Check_At_Least_N_Arguments (2);
6049 Check_At_Most_N_Arguments (4);
6050 Process_Convention (C, Def_Id);
6052 if Ekind (Def_Id) /= E_Constant then
6053 Note_Possible_Modification (Expression (Arg2));
6056 Process_Interface_Name (Def_Id, Arg3, Arg4);
6057 Set_Exported (Def_Id, Arg2);
6060 ----------------------
6061 -- Export_Exception --
6062 ----------------------
6064 -- pragma Export_Exception (
6065 -- [Internal =>] LOCAL_NAME,
6066 -- [, [External =>] EXTERNAL_SYMBOL,]
6067 -- [, [Form =>] Ada | VMS]
6068 -- [, [Code =>] static_integer_EXPRESSION]);
6070 when Pragma_Export_Exception => Export_Exception : declare
6071 Args : Args_List (1 .. 4);
6072 Names : constant Name_List (1 .. 4) := (
6078 Internal : Node_Id renames Args (1);
6079 External : Node_Id renames Args (2);
6080 Form : Node_Id renames Args (3);
6081 Code : Node_Id renames Args (4);
6084 if Inside_A_Generic then
6085 Error_Pragma ("pragma% cannot be used for generic entities");
6088 Gather_Associations (Names, Args);
6089 Process_Extended_Import_Export_Exception_Pragma (
6090 Arg_Internal => Internal,
6091 Arg_External => External,
6095 if not Is_VMS_Exception (Entity (Internal)) then
6096 Set_Exported (Entity (Internal), Internal);
6098 end Export_Exception;
6100 ---------------------
6101 -- Export_Function --
6102 ---------------------
6104 -- pragma Export_Function (
6105 -- [Internal =>] LOCAL_NAME,
6106 -- [, [External =>] EXTERNAL_SYMBOL,]
6107 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6108 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6109 -- [, [Mechanism =>] MECHANISM]
6110 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6112 -- EXTERNAL_SYMBOL ::=
6114 -- | static_string_EXPRESSION
6116 -- PARAMETER_TYPES ::=
6118 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6120 -- TYPE_DESIGNATOR ::=
6122 -- | subtype_Name ' Access
6126 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6128 -- MECHANISM_ASSOCIATION ::=
6129 -- [formal_parameter_NAME =>] MECHANISM_NAME
6131 -- MECHANISM_NAME ::=
6134 -- | Descriptor [([Class =>] CLASS_NAME)]
6136 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6138 when Pragma_Export_Function => Export_Function : declare
6139 Args : Args_List (1 .. 6);
6140 Names : constant Name_List (1 .. 6) := (
6143 Name_Parameter_Types,
6146 Name_Result_Mechanism);
6148 Internal : Node_Id renames Args (1);
6149 External : Node_Id renames Args (2);
6150 Parameter_Types : Node_Id renames Args (3);
6151 Result_Type : Node_Id renames Args (4);
6152 Mechanism : Node_Id renames Args (5);
6153 Result_Mechanism : Node_Id renames Args (6);
6157 Gather_Associations (Names, Args);
6158 Process_Extended_Import_Export_Subprogram_Pragma (
6159 Arg_Internal => Internal,
6160 Arg_External => External,
6161 Arg_Parameter_Types => Parameter_Types,
6162 Arg_Result_Type => Result_Type,
6163 Arg_Mechanism => Mechanism,
6164 Arg_Result_Mechanism => Result_Mechanism);
6165 end Export_Function;
6171 -- pragma Export_Object (
6172 -- [Internal =>] LOCAL_NAME,
6173 -- [, [External =>] EXTERNAL_SYMBOL]
6174 -- [, [Size =>] EXTERNAL_SYMBOL]);
6176 -- EXTERNAL_SYMBOL ::=
6178 -- | static_string_EXPRESSION
6180 -- PARAMETER_TYPES ::=
6182 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6184 -- TYPE_DESIGNATOR ::=
6186 -- | subtype_Name ' Access
6190 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6192 -- MECHANISM_ASSOCIATION ::=
6193 -- [formal_parameter_NAME =>] MECHANISM_NAME
6195 -- MECHANISM_NAME ::=
6198 -- | Descriptor [([Class =>] CLASS_NAME)]
6200 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6202 when Pragma_Export_Object => Export_Object : declare
6203 Args : Args_List (1 .. 3);
6204 Names : constant Name_List (1 .. 3) := (
6209 Internal : Node_Id renames Args (1);
6210 External : Node_Id renames Args (2);
6211 Size : Node_Id renames Args (3);
6215 Gather_Associations (Names, Args);
6216 Process_Extended_Import_Export_Object_Pragma (
6217 Arg_Internal => Internal,
6218 Arg_External => External,
6222 ----------------------
6223 -- Export_Procedure --
6224 ----------------------
6226 -- pragma Export_Procedure (
6227 -- [Internal =>] LOCAL_NAME,
6228 -- [, [External =>] EXTERNAL_SYMBOL,]
6229 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6230 -- [, [Mechanism =>] MECHANISM]);
6232 -- EXTERNAL_SYMBOL ::=
6234 -- | static_string_EXPRESSION
6236 -- PARAMETER_TYPES ::=
6238 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6240 -- TYPE_DESIGNATOR ::=
6242 -- | subtype_Name ' Access
6246 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6248 -- MECHANISM_ASSOCIATION ::=
6249 -- [formal_parameter_NAME =>] MECHANISM_NAME
6251 -- MECHANISM_NAME ::=
6254 -- | Descriptor [([Class =>] CLASS_NAME)]
6256 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6258 when Pragma_Export_Procedure => Export_Procedure : declare
6259 Args : Args_List (1 .. 4);
6260 Names : constant Name_List (1 .. 4) := (
6263 Name_Parameter_Types,
6266 Internal : Node_Id renames Args (1);
6267 External : Node_Id renames Args (2);
6268 Parameter_Types : Node_Id renames Args (3);
6269 Mechanism : Node_Id renames Args (4);
6273 Gather_Associations (Names, Args);
6274 Process_Extended_Import_Export_Subprogram_Pragma (
6275 Arg_Internal => Internal,
6276 Arg_External => External,
6277 Arg_Parameter_Types => Parameter_Types,
6278 Arg_Mechanism => Mechanism);
6279 end Export_Procedure;
6285 -- pragma Export_Value (
6286 -- [Value =>] static_integer_EXPRESSION,
6287 -- [Link_Name =>] static_string_EXPRESSION);
6289 when Pragma_Export_Value =>
6291 Check_Arg_Order ((Name_Value, Name_Link_Name));
6292 Check_Arg_Count (2);
6294 Check_Optional_Identifier (Arg1, Name_Value);
6295 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6297 Check_Optional_Identifier (Arg2, Name_Link_Name);
6298 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6300 -----------------------------
6301 -- Export_Valued_Procedure --
6302 -----------------------------
6304 -- pragma Export_Valued_Procedure (
6305 -- [Internal =>] LOCAL_NAME,
6306 -- [, [External =>] EXTERNAL_SYMBOL,]
6307 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6308 -- [, [Mechanism =>] MECHANISM]);
6310 -- EXTERNAL_SYMBOL ::=
6312 -- | static_string_EXPRESSION
6314 -- PARAMETER_TYPES ::=
6316 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6318 -- TYPE_DESIGNATOR ::=
6320 -- | subtype_Name ' Access
6324 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6326 -- MECHANISM_ASSOCIATION ::=
6327 -- [formal_parameter_NAME =>] MECHANISM_NAME
6329 -- MECHANISM_NAME ::=
6332 -- | Descriptor [([Class =>] CLASS_NAME)]
6334 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6336 when Pragma_Export_Valued_Procedure =>
6337 Export_Valued_Procedure : declare
6338 Args : Args_List (1 .. 4);
6339 Names : constant Name_List (1 .. 4) := (
6342 Name_Parameter_Types,
6345 Internal : Node_Id renames Args (1);
6346 External : Node_Id renames Args (2);
6347 Parameter_Types : Node_Id renames Args (3);
6348 Mechanism : Node_Id renames Args (4);
6352 Gather_Associations (Names, Args);
6353 Process_Extended_Import_Export_Subprogram_Pragma (
6354 Arg_Internal => Internal,
6355 Arg_External => External,
6356 Arg_Parameter_Types => Parameter_Types,
6357 Arg_Mechanism => Mechanism);
6358 end Export_Valued_Procedure;
6364 -- pragma Extend_System ([Name =>] Identifier);
6366 when Pragma_Extend_System => Extend_System : declare
6369 Check_Valid_Configuration_Pragma;
6370 Check_Arg_Count (1);
6371 Check_Optional_Identifier (Arg1, Name_Name);
6372 Check_Arg_Is_Identifier (Arg1);
6374 Get_Name_String (Chars (Expression (Arg1)));
6377 and then Name_Buffer (1 .. 4) = "aux_"
6379 if Present (System_Extend_Pragma_Arg) then
6380 if Chars (Expression (Arg1)) =
6381 Chars (Expression (System_Extend_Pragma_Arg))
6385 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6386 Error_Pragma ("pragma% conflicts with that at#");
6390 System_Extend_Pragma_Arg := Arg1;
6392 if not GNAT_Mode then
6393 System_Extend_Unit := Arg1;
6397 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6401 ------------------------
6402 -- Extensions_Allowed --
6403 ------------------------
6405 -- pragma Extensions_Allowed (ON | OFF);
6407 when Pragma_Extensions_Allowed =>
6409 Check_Arg_Count (1);
6410 Check_No_Identifiers;
6411 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6413 if Chars (Expression (Arg1)) = Name_On then
6414 Extensions_Allowed := True;
6415 Ada_Version := Ada_Version_Type'Last;
6417 Extensions_Allowed := False;
6418 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6421 Ada_Version_Explicit := Ada_Version;
6427 -- pragma External (
6428 -- [ Convention =>] convention_IDENTIFIER,
6429 -- [ Entity =>] local_NAME
6430 -- [, [External_Name =>] static_string_EXPRESSION ]
6431 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6433 when Pragma_External => External : declare
6443 Check_At_Least_N_Arguments (2);
6444 Check_At_Most_N_Arguments (4);
6445 Process_Convention (C, Def_Id);
6446 Note_Possible_Modification (Expression (Arg2));
6447 Process_Interface_Name (Def_Id, Arg3, Arg4);
6448 Set_Exported (Def_Id, Arg2);
6451 --------------------------
6452 -- External_Name_Casing --
6453 --------------------------
6455 -- pragma External_Name_Casing (
6456 -- UPPERCASE | LOWERCASE
6457 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6459 when Pragma_External_Name_Casing => External_Name_Casing : declare
6462 Check_No_Identifiers;
6464 if Arg_Count = 2 then
6466 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6468 case Chars (Get_Pragma_Arg (Arg2)) is
6470 Opt.External_Name_Exp_Casing := As_Is;
6472 when Name_Uppercase =>
6473 Opt.External_Name_Exp_Casing := Uppercase;
6475 when Name_Lowercase =>
6476 Opt.External_Name_Exp_Casing := Lowercase;
6483 Check_Arg_Count (1);
6486 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6488 case Chars (Get_Pragma_Arg (Arg1)) is
6489 when Name_Uppercase =>
6490 Opt.External_Name_Imp_Casing := Uppercase;
6492 when Name_Lowercase =>
6493 Opt.External_Name_Imp_Casing := Lowercase;
6498 end External_Name_Casing;
6500 ---------------------------
6501 -- Finalize_Storage_Only --
6502 ---------------------------
6504 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6506 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6507 Assoc : constant Node_Id := Arg1;
6508 Type_Id : constant Node_Id := Expression (Assoc);
6512 Check_No_Identifiers;
6513 Check_Arg_Count (1);
6514 Check_Arg_Is_Local_Name (Arg1);
6516 Find_Type (Type_Id);
6517 Typ := Entity (Type_Id);
6520 or else Rep_Item_Too_Early (Typ, N)
6524 Typ := Underlying_Type (Typ);
6527 if not Is_Controlled (Typ) then
6528 Error_Pragma ("pragma% must specify controlled type");
6531 Check_First_Subtype (Arg1);
6533 if Finalize_Storage_Only (Typ) then
6534 Error_Pragma ("duplicate pragma%, only one allowed");
6536 elsif not Rep_Item_Too_Late (Typ, N) then
6537 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6539 end Finalize_Storage;
6541 --------------------------
6542 -- Float_Representation --
6543 --------------------------
6545 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
6547 -- FLOAT_REP ::= VAX_Float | IEEE_Float
6549 when Pragma_Float_Representation => Float_Representation : declare
6557 if Arg_Count = 1 then
6558 Check_Valid_Configuration_Pragma;
6560 Check_Arg_Count (2);
6561 Check_Optional_Identifier (Arg2, Name_Entity);
6562 Check_Arg_Is_Local_Name (Arg2);
6565 Check_No_Identifier (Arg1);
6566 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6568 if not OpenVMS_On_Target then
6569 if Chars (Expression (Arg1)) = Name_VAX_Float then
6571 ("?pragma% ignored (applies only to Open'V'M'S)");
6577 -- One argument case
6579 if Arg_Count = 1 then
6580 if Chars (Expression (Arg1)) = Name_VAX_Float then
6581 if Opt.Float_Format = 'I' then
6582 Error_Pragma ("'I'E'E'E format previously specified");
6585 Opt.Float_Format := 'V';
6588 if Opt.Float_Format = 'V' then
6589 Error_Pragma ("'V'A'X format previously specified");
6592 Opt.Float_Format := 'I';
6595 Set_Standard_Fpt_Formats;
6597 -- Two argument case
6600 Argx := Get_Pragma_Arg (Arg2);
6602 if not Is_Entity_Name (Argx)
6603 or else not Is_Floating_Point_Type (Entity (Argx))
6606 ("second argument of% pragma must be floating-point type",
6610 Ent := Entity (Argx);
6611 Digs := UI_To_Int (Digits_Value (Ent));
6613 -- Two arguments, VAX_Float case
6615 if Chars (Expression (Arg1)) = Name_VAX_Float then
6617 when 6 => Set_F_Float (Ent);
6618 when 9 => Set_D_Float (Ent);
6619 when 15 => Set_G_Float (Ent);
6623 ("wrong digits value, must be 6,9 or 15", Arg2);
6626 -- Two arguments, IEEE_Float case
6630 when 6 => Set_IEEE_Short (Ent);
6631 when 15 => Set_IEEE_Long (Ent);
6635 ("wrong digits value, must be 6 or 15", Arg2);
6639 end Float_Representation;
6645 -- pragma Ident (static_string_EXPRESSION)
6647 -- Note: pragma Comment shares this processing. Pragma Comment
6648 -- is identical to Ident, except that the restriction of the
6649 -- argument to 31 characters and the placement restrictions
6650 -- are not enforced for pragma Comment.
6652 when Pragma_Ident | Pragma_Comment => Ident : declare
6657 Check_Arg_Count (1);
6658 Check_No_Identifiers;
6659 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6661 -- For pragma Ident, preserve DEC compatibility by requiring
6662 -- the pragma to appear in a declarative part or package spec.
6664 if Prag_Id = Pragma_Ident then
6665 Check_Is_In_Decl_Part_Or_Package_Spec;
6668 Str := Expr_Value_S (Expression (Arg1));
6675 GP := Parent (Parent (N));
6677 if Nkind (GP) = N_Package_Declaration
6679 Nkind (GP) = N_Generic_Package_Declaration
6684 -- If we have a compilation unit, then record the ident
6685 -- value, checking for improper duplication.
6687 if Nkind (GP) = N_Compilation_Unit then
6688 CS := Ident_String (Current_Sem_Unit);
6690 if Present (CS) then
6692 -- For Ident, we do not permit multiple instances
6694 if Prag_Id = Pragma_Ident then
6695 Error_Pragma ("duplicate% pragma not permitted");
6697 -- For Comment, we concatenate the string, unless we
6698 -- want to preserve the tree structure for ASIS.
6700 elsif not ASIS_Mode then
6701 Start_String (Strval (CS));
6702 Store_String_Char (' ');
6703 Store_String_Chars (Strval (Str));
6704 Set_Strval (CS, End_String);
6708 -- In VMS, the effect of IDENT is achieved by passing
6709 -- IDENTIFICATION=name as a --for-linker switch.
6711 if OpenVMS_On_Target then
6714 ("--for-linker=IDENTIFICATION=");
6715 String_To_Name_Buffer (Strval (Str));
6716 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6718 -- Only the last processed IDENT is saved. The main
6719 -- purpose is so an IDENT associated with a main
6720 -- procedure will be used in preference to an IDENT
6721 -- associated with a with'd package.
6723 Replace_Linker_Option_String
6724 (End_String, "--for-linker=IDENTIFICATION=");
6727 Set_Ident_String (Current_Sem_Unit, Str);
6730 -- For subunits, we just ignore the Ident, since in GNAT
6731 -- these are not separate object files, and hence not
6732 -- separate units in the unit table.
6734 elsif Nkind (GP) = N_Subunit then
6737 -- Otherwise we have a misplaced pragma Ident, but we ignore
6738 -- this if we are in an instantiation, since it comes from
6739 -- a generic, and has no relevance to the instantiation.
6741 elsif Prag_Id = Pragma_Ident then
6742 if Instantiation_Location (Loc) = No_Location then
6743 Error_Pragma ("pragma% only allowed at outer level");
6754 -- [ Convention =>] convention_IDENTIFIER,
6755 -- [ Entity =>] local_NAME
6756 -- [, [External_Name =>] static_string_EXPRESSION ]
6757 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6759 when Pragma_Import =>
6760 Check_Ada_83_Warning;
6766 Check_At_Least_N_Arguments (2);
6767 Check_At_Most_N_Arguments (4);
6768 Process_Import_Or_Interface;
6770 ----------------------
6771 -- Import_Exception --
6772 ----------------------
6774 -- pragma Import_Exception (
6775 -- [Internal =>] LOCAL_NAME,
6776 -- [, [External =>] EXTERNAL_SYMBOL,]
6777 -- [, [Form =>] Ada | VMS]
6778 -- [, [Code =>] static_integer_EXPRESSION]);
6780 when Pragma_Import_Exception => Import_Exception : declare
6781 Args : Args_List (1 .. 4);
6782 Names : constant Name_List (1 .. 4) := (
6788 Internal : Node_Id renames Args (1);
6789 External : Node_Id renames Args (2);
6790 Form : Node_Id renames Args (3);
6791 Code : Node_Id renames Args (4);
6794 Gather_Associations (Names, Args);
6796 if Present (External) and then Present (Code) then
6798 ("cannot give both External and Code options for pragma%");
6801 Process_Extended_Import_Export_Exception_Pragma (
6802 Arg_Internal => Internal,
6803 Arg_External => External,
6807 if not Is_VMS_Exception (Entity (Internal)) then
6808 Set_Imported (Entity (Internal));
6810 end Import_Exception;
6812 ---------------------
6813 -- Import_Function --
6814 ---------------------
6816 -- pragma Import_Function (
6817 -- [Internal =>] LOCAL_NAME,
6818 -- [, [External =>] EXTERNAL_SYMBOL]
6819 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6820 -- [, [Result_Type =>] SUBTYPE_MARK]
6821 -- [, [Mechanism =>] MECHANISM]
6822 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6823 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6825 -- EXTERNAL_SYMBOL ::=
6827 -- | static_string_EXPRESSION
6829 -- PARAMETER_TYPES ::=
6831 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6833 -- TYPE_DESIGNATOR ::=
6835 -- | subtype_Name ' Access
6839 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6841 -- MECHANISM_ASSOCIATION ::=
6842 -- [formal_parameter_NAME =>] MECHANISM_NAME
6844 -- MECHANISM_NAME ::=
6847 -- | Descriptor [([Class =>] CLASS_NAME)]
6849 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6851 when Pragma_Import_Function => Import_Function : declare
6852 Args : Args_List (1 .. 7);
6853 Names : constant Name_List (1 .. 7) := (
6856 Name_Parameter_Types,
6859 Name_Result_Mechanism,
6860 Name_First_Optional_Parameter);
6862 Internal : Node_Id renames Args (1);
6863 External : Node_Id renames Args (2);
6864 Parameter_Types : Node_Id renames Args (3);
6865 Result_Type : Node_Id renames Args (4);
6866 Mechanism : Node_Id renames Args (5);
6867 Result_Mechanism : Node_Id renames Args (6);
6868 First_Optional_Parameter : Node_Id renames Args (7);
6872 Gather_Associations (Names, Args);
6873 Process_Extended_Import_Export_Subprogram_Pragma (
6874 Arg_Internal => Internal,
6875 Arg_External => External,
6876 Arg_Parameter_Types => Parameter_Types,
6877 Arg_Result_Type => Result_Type,
6878 Arg_Mechanism => Mechanism,
6879 Arg_Result_Mechanism => Result_Mechanism,
6880 Arg_First_Optional_Parameter => First_Optional_Parameter);
6881 end Import_Function;
6887 -- pragma Import_Object (
6888 -- [Internal =>] LOCAL_NAME,
6889 -- [, [External =>] EXTERNAL_SYMBOL]
6890 -- [, [Size =>] EXTERNAL_SYMBOL]);
6892 -- EXTERNAL_SYMBOL ::=
6894 -- | static_string_EXPRESSION
6896 when Pragma_Import_Object => Import_Object : declare
6897 Args : Args_List (1 .. 3);
6898 Names : constant Name_List (1 .. 3) := (
6903 Internal : Node_Id renames Args (1);
6904 External : Node_Id renames Args (2);
6905 Size : Node_Id renames Args (3);
6909 Gather_Associations (Names, Args);
6910 Process_Extended_Import_Export_Object_Pragma (
6911 Arg_Internal => Internal,
6912 Arg_External => External,
6916 ----------------------
6917 -- Import_Procedure --
6918 ----------------------
6920 -- pragma Import_Procedure (
6921 -- [Internal =>] LOCAL_NAME,
6922 -- [, [External =>] EXTERNAL_SYMBOL]
6923 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6924 -- [, [Mechanism =>] MECHANISM]
6925 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6927 -- EXTERNAL_SYMBOL ::=
6929 -- | static_string_EXPRESSION
6931 -- PARAMETER_TYPES ::=
6933 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6935 -- TYPE_DESIGNATOR ::=
6937 -- | subtype_Name ' Access
6941 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6943 -- MECHANISM_ASSOCIATION ::=
6944 -- [formal_parameter_NAME =>] MECHANISM_NAME
6946 -- MECHANISM_NAME ::=
6949 -- | Descriptor [([Class =>] CLASS_NAME)]
6951 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6953 when Pragma_Import_Procedure => Import_Procedure : declare
6954 Args : Args_List (1 .. 5);
6955 Names : constant Name_List (1 .. 5) := (
6958 Name_Parameter_Types,
6960 Name_First_Optional_Parameter);
6962 Internal : Node_Id renames Args (1);
6963 External : Node_Id renames Args (2);
6964 Parameter_Types : Node_Id renames Args (3);
6965 Mechanism : Node_Id renames Args (4);
6966 First_Optional_Parameter : Node_Id renames Args (5);
6970 Gather_Associations (Names, Args);
6971 Process_Extended_Import_Export_Subprogram_Pragma (
6972 Arg_Internal => Internal,
6973 Arg_External => External,
6974 Arg_Parameter_Types => Parameter_Types,
6975 Arg_Mechanism => Mechanism,
6976 Arg_First_Optional_Parameter => First_Optional_Parameter);
6977 end Import_Procedure;
6979 -----------------------------
6980 -- Import_Valued_Procedure --
6981 -----------------------------
6983 -- pragma Import_Valued_Procedure (
6984 -- [Internal =>] LOCAL_NAME,
6985 -- [, [External =>] EXTERNAL_SYMBOL]
6986 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6987 -- [, [Mechanism =>] MECHANISM]
6988 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6990 -- EXTERNAL_SYMBOL ::=
6992 -- | static_string_EXPRESSION
6994 -- PARAMETER_TYPES ::=
6996 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6998 -- TYPE_DESIGNATOR ::=
7000 -- | subtype_Name ' Access
7004 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7006 -- MECHANISM_ASSOCIATION ::=
7007 -- [formal_parameter_NAME =>] MECHANISM_NAME
7009 -- MECHANISM_NAME ::=
7012 -- | Descriptor [([Class =>] CLASS_NAME)]
7014 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7016 when Pragma_Import_Valued_Procedure =>
7017 Import_Valued_Procedure : declare
7018 Args : Args_List (1 .. 5);
7019 Names : constant Name_List (1 .. 5) := (
7022 Name_Parameter_Types,
7024 Name_First_Optional_Parameter);
7026 Internal : Node_Id renames Args (1);
7027 External : Node_Id renames Args (2);
7028 Parameter_Types : Node_Id renames Args (3);
7029 Mechanism : Node_Id renames Args (4);
7030 First_Optional_Parameter : Node_Id renames Args (5);
7034 Gather_Associations (Names, Args);
7035 Process_Extended_Import_Export_Subprogram_Pragma (
7036 Arg_Internal => Internal,
7037 Arg_External => External,
7038 Arg_Parameter_Types => Parameter_Types,
7039 Arg_Mechanism => Mechanism,
7040 Arg_First_Optional_Parameter => First_Optional_Parameter);
7041 end Import_Valued_Procedure;
7043 ------------------------
7044 -- Initialize_Scalars --
7045 ------------------------
7047 -- pragma Initialize_Scalars;
7049 when Pragma_Initialize_Scalars =>
7051 Check_Arg_Count (0);
7052 Check_Valid_Configuration_Pragma;
7053 Check_Restriction (No_Initialize_Scalars, N);
7055 if not Restriction_Active (No_Initialize_Scalars) then
7056 Init_Or_Norm_Scalars := True;
7057 Initialize_Scalars := True;
7064 -- pragma Inline ( NAME {, NAME} );
7066 when Pragma_Inline =>
7068 -- Pragma is active if inlining option is active
7070 Process_Inline (Inline_Active);
7076 -- pragma Inline_Always ( NAME {, NAME} );
7078 when Pragma_Inline_Always =>
7079 Process_Inline (True);
7081 --------------------
7082 -- Inline_Generic --
7083 --------------------
7085 -- pragma Inline_Generic (NAME {, NAME});
7087 when Pragma_Inline_Generic =>
7088 Process_Generic_List;
7090 ----------------------
7091 -- Inspection_Point --
7092 ----------------------
7094 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7096 when Pragma_Inspection_Point => Inspection_Point : declare
7101 if Arg_Count > 0 then
7104 Exp := Expression (Arg);
7107 if not Is_Entity_Name (Exp)
7108 or else not Is_Object (Entity (Exp))
7110 Error_Pragma_Arg ("object name required", Arg);
7117 end Inspection_Point;
7123 -- pragma Interface (
7124 -- convention_IDENTIFIER,
7127 when Pragma_Interface =>
7129 Check_Arg_Count (2);
7130 Check_No_Identifiers;
7131 Process_Import_Or_Interface;
7133 --------------------
7134 -- Interface_Name --
7135 --------------------
7137 -- pragma Interface_Name (
7138 -- [ Entity =>] local_NAME
7139 -- [,[External_Name =>] static_string_EXPRESSION ]
7140 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7142 when Pragma_Interface_Name => Interface_Name : declare
7151 ((Name_Entity, Name_External_Name, Name_Link_Name));
7152 Check_At_Least_N_Arguments (2);
7153 Check_At_Most_N_Arguments (3);
7154 Id := Expression (Arg1);
7157 if not Is_Entity_Name (Id) then
7159 ("first argument for pragma% must be entity name", Arg1);
7160 elsif Etype (Id) = Any_Type then
7163 Def_Id := Entity (Id);
7166 -- Special DEC-compatible processing for the object case,
7167 -- forces object to be imported.
7169 if Ekind (Def_Id) = E_Variable then
7170 Kill_Size_Check_Code (Def_Id);
7171 Note_Possible_Modification (Id);
7173 -- Initialization is not allowed for imported variable
7175 if Present (Expression (Parent (Def_Id)))
7176 and then Comes_From_Source (Expression (Parent (Def_Id)))
7178 Error_Msg_Sloc := Sloc (Def_Id);
7180 ("no initialization allowed for declaration of& #",
7184 -- For compatibility, support VADS usage of providing both
7185 -- pragmas Interface and Interface_Name to obtain the effect
7186 -- of a single Import pragma.
7188 if Is_Imported (Def_Id)
7189 and then Present (First_Rep_Item (Def_Id))
7190 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7191 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
7195 Set_Imported (Def_Id);
7198 Set_Is_Public (Def_Id);
7199 Process_Interface_Name (Def_Id, Arg2, Arg3);
7202 -- Otherwise must be subprogram
7204 elsif not Is_Subprogram (Def_Id) then
7206 ("argument of pragma% is not subprogram", Arg1);
7209 Check_At_Most_N_Arguments (3);
7213 -- Loop through homonyms
7216 Def_Id := Get_Base_Subprogram (Hom_Id);
7218 if Is_Imported (Def_Id) then
7219 Process_Interface_Name (Def_Id, Arg2, Arg3);
7223 Hom_Id := Homonym (Hom_Id);
7225 exit when No (Hom_Id)
7226 or else Scope (Hom_Id) /= Current_Scope;
7231 ("argument of pragma% is not imported subprogram",
7237 -----------------------
7238 -- Interrupt_Handler --
7239 -----------------------
7241 -- pragma Interrupt_Handler (handler_NAME);
7243 when Pragma_Interrupt_Handler =>
7244 Check_Ada_83_Warning;
7245 Check_Arg_Count (1);
7246 Check_No_Identifiers;
7248 if No_Run_Time_Mode then
7249 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7251 Check_Interrupt_Or_Attach_Handler;
7252 Process_Interrupt_Or_Attach_Handler;
7255 ------------------------
7256 -- Interrupt_Priority --
7257 ------------------------
7259 -- pragma Interrupt_Priority [(EXPRESSION)];
7261 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7262 P : constant Node_Id := Parent (N);
7266 Check_Ada_83_Warning;
7268 if Arg_Count /= 0 then
7269 Arg := Expression (Arg1);
7270 Check_Arg_Count (1);
7271 Check_No_Identifiers;
7273 -- The expression must be analyzed in the special manner
7274 -- described in "Handling of Default and Per-Object
7275 -- Expressions" in sem.ads.
7277 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7280 if Nkind (P) /= N_Task_Definition
7281 and then Nkind (P) /= N_Protected_Definition
7286 elsif Has_Priority_Pragma (P) then
7287 Error_Pragma ("duplicate pragma% not allowed");
7290 Set_Has_Priority_Pragma (P, True);
7291 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7293 end Interrupt_Priority;
7295 ---------------------
7296 -- Interrupt_State --
7297 ---------------------
7299 -- pragma Interrupt_State (
7300 -- [Name =>] INTERRUPT_ID,
7301 -- [State =>] INTERRUPT_STATE);
7303 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7304 -- INTERRUPT_STATE => System | Runtime | User
7306 -- Note: if the interrupt id is given as an identifier, then
7307 -- it must be one of the identifiers in Ada.Interrupts.Names.
7308 -- Otherwise it is given as a static integer expression which
7309 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7311 when Pragma_Interrupt_State => Interrupt_State : declare
7313 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7314 -- This is the entity Ada.Interrupts.Interrupt_ID;
7316 State_Type : Character;
7317 -- Set to 's'/'r'/'u' for System/Runtime/User
7320 -- Index to entry in Interrupt_States table
7323 -- Value of interrupt
7325 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7326 -- The first argument to the pragma
7328 Int_Ent : Entity_Id;
7329 -- Interrupt entity in Ada.Interrupts.Names
7333 Check_Arg_Order ((Name_Name, Name_State));
7334 Check_Arg_Count (2);
7336 Check_Optional_Identifier (Arg1, Name_Name);
7337 Check_Optional_Identifier (Arg2, Name_State);
7338 Check_Arg_Is_Identifier (Arg2);
7340 -- First argument is identifier
7342 if Nkind (Arg1X) = N_Identifier then
7344 -- Search list of names in Ada.Interrupts.Names
7346 Int_Ent := First_Entity (RTE (RE_Names));
7348 if No (Int_Ent) then
7349 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7351 elsif Chars (Int_Ent) = Chars (Arg1X) then
7352 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7356 Next_Entity (Int_Ent);
7359 -- First argument is not an identifier, so it must be a
7360 -- static expression of type Ada.Interrupts.Interrupt_ID.
7363 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7364 Int_Val := Expr_Value (Arg1X);
7366 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7368 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7371 ("value not in range of type " &
7372 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7378 case Chars (Get_Pragma_Arg (Arg2)) is
7379 when Name_Runtime => State_Type := 'r';
7380 when Name_System => State_Type := 's';
7381 when Name_User => State_Type := 'u';
7384 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7387 -- Check if entry is already stored
7389 IST_Num := Interrupt_States.First;
7391 -- If entry not found, add it
7393 if IST_Num > Interrupt_States.Last then
7394 Interrupt_States.Append
7395 ((Interrupt_Number => UI_To_Int (Int_Val),
7396 Interrupt_State => State_Type,
7397 Pragma_Loc => Loc));
7400 -- Case of entry for the same entry
7402 elsif Int_Val = Interrupt_States.Table (IST_Num).
7405 -- If state matches, done, no need to make redundant entry
7408 State_Type = Interrupt_States.Table (IST_Num).
7411 -- Otherwise if state does not match, error
7414 Interrupt_States.Table (IST_Num).Pragma_Loc;
7416 ("state conflicts with that given at #", Arg2);
7420 IST_Num := IST_Num + 1;
7422 end Interrupt_State;
7424 ----------------------
7425 -- Java_Constructor --
7426 ----------------------
7428 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7430 when Pragma_Java_Constructor => Java_Constructor : declare
7437 Check_Arg_Count (1);
7438 Check_Optional_Identifier (Arg1, Name_Entity);
7439 Check_Arg_Is_Local_Name (Arg1);
7441 Id := Expression (Arg1);
7442 Find_Program_Unit_Name (Id);
7444 -- If we did not find the name, we are done
7446 if Etype (Id) = Any_Type then
7450 Hom_Id := Entity (Id);
7452 -- Loop through homonyms
7455 Def_Id := Get_Base_Subprogram (Hom_Id);
7457 -- The constructor is required to be a function returning
7458 -- an access type whose designated type has convention Java.
7460 if Ekind (Def_Id) = E_Function
7461 and then Ekind (Etype (Def_Id)) in Access_Kind
7464 (Designated_Type (Etype (Def_Id))) = Convention_Java
7467 (Root_Type (Designated_Type (Etype (Def_Id))))
7470 Set_Is_Constructor (Def_Id);
7471 Set_Convention (Def_Id, Convention_Java);
7475 ("pragma% requires function returning a 'Java access type",
7479 Hom_Id := Homonym (Hom_Id);
7481 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7483 end Java_Constructor;
7485 ----------------------
7486 -- Java_Interface --
7487 ----------------------
7489 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7491 when Pragma_Java_Interface => Java_Interface : declare
7497 Check_Arg_Count (1);
7498 Check_Optional_Identifier (Arg1, Name_Entity);
7499 Check_Arg_Is_Local_Name (Arg1);
7501 Arg := Expression (Arg1);
7504 if Etype (Arg) = Any_Type then
7508 if not Is_Entity_Name (Arg)
7509 or else not Is_Type (Entity (Arg))
7511 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7514 Typ := Underlying_Type (Entity (Arg));
7516 -- For now we simply check some of the semantic constraints
7517 -- on the type. This currently leaves out some restrictions
7518 -- on interface types, namely that the parent type must be
7519 -- java.lang.Object.Typ and that all primitives of the type
7520 -- should be declared abstract. ???
7522 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7523 Error_Pragma_Arg ("pragma% requires an abstract "
7524 & "tagged type", Arg1);
7526 elsif not Has_Discriminants (Typ)
7527 or else Ekind (Etype (First_Discriminant (Typ)))
7528 /= E_Anonymous_Access_Type
7530 not Is_Class_Wide_Type
7531 (Designated_Type (Etype (First_Discriminant (Typ))))
7534 ("type must have a class-wide access discriminant", Arg1);
7542 -- pragma Keep_Names ([On => ] local_NAME);
7544 when Pragma_Keep_Names => Keep_Names : declare
7549 Check_Arg_Count (1);
7550 Check_Optional_Identifier (Arg1, Name_On);
7551 Check_Arg_Is_Local_Name (Arg1);
7553 Arg := Expression (Arg1);
7556 if Etype (Arg) = Any_Type then
7560 if not Is_Entity_Name (Arg)
7561 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7564 ("pragma% requires a local enumeration type", Arg1);
7567 Set_Discard_Names (Entity (Arg), False);
7574 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
7576 when Pragma_License =>
7578 Check_Arg_Count (1);
7579 Check_No_Identifiers;
7580 Check_Valid_Configuration_Pragma;
7581 Check_Arg_Is_Identifier (Arg1);
7584 Sind : constant Source_File_Index :=
7585 Source_Index (Current_Sem_Unit);
7588 case Chars (Get_Pragma_Arg (Arg1)) is
7590 Set_License (Sind, GPL);
7592 when Name_Modified_GPL =>
7593 Set_License (Sind, Modified_GPL);
7595 when Name_Restricted =>
7596 Set_License (Sind, Restricted);
7598 when Name_Unrestricted =>
7599 Set_License (Sind, Unrestricted);
7602 Error_Pragma_Arg ("invalid license name", Arg1);
7610 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7612 when Pragma_Link_With => Link_With : declare
7618 if Operating_Mode = Generate_Code
7619 and then In_Extended_Main_Source_Unit (N)
7621 Check_At_Least_N_Arguments (1);
7622 Check_No_Identifiers;
7623 Check_Is_In_Decl_Part_Or_Package_Spec;
7624 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7628 while Present (Arg) loop
7629 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7631 -- Store argument, converting sequences of spaces
7632 -- to a single null character (this is one of the
7633 -- differences in processing between Link_With
7634 -- and Linker_Options).
7637 C : constant Char_Code := Get_Char_Code (' ');
7638 S : constant String_Id :=
7639 Strval (Expr_Value_S (Expression (Arg)));
7640 L : constant Nat := String_Length (S);
7643 procedure Skip_Spaces;
7644 -- Advance F past any spaces
7646 procedure Skip_Spaces is
7648 while F <= L and then Get_String_Char (S, F) = C loop
7654 Skip_Spaces; -- skip leading spaces
7656 -- Loop through characters, changing any embedded
7657 -- sequence of spaces to a single null character
7658 -- (this is how Link_With/Linker_Options differ)
7661 if Get_String_Char (S, F) = C then
7664 Store_String_Char (ASCII.NUL);
7667 Store_String_Char (Get_String_Char (S, F));
7675 if Present (Arg) then
7676 Store_String_Char (ASCII.NUL);
7680 Store_Linker_Option_String (End_String);
7688 -- pragma Linker_Alias (
7689 -- [Entity =>] LOCAL_NAME
7690 -- [Target =>] static_string_EXPRESSION);
7692 when Pragma_Linker_Alias =>
7694 Check_Arg_Order ((Name_Entity, Name_Target));
7695 Check_Arg_Count (2);
7696 Check_Optional_Identifier (Arg1, Name_Entity);
7697 Check_Optional_Identifier (Arg2, Name_Target);
7698 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7699 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7701 -- The only processing required is to link this item on to the
7702 -- list of rep items for the given entity. This is accomplished
7703 -- by the call to Rep_Item_Too_Late (when no error is detected
7704 -- and False is returned).
7706 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7709 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7712 ------------------------
7713 -- Linker_Constructor --
7714 ------------------------
7716 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
7718 -- Code is shared with Linker_Destructor
7720 -----------------------
7721 -- Linker_Destructor --
7722 -----------------------
7724 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
7726 when Pragma_Linker_Constructor |
7727 Pragma_Linker_Destructor =>
7728 Linker_Constructor : declare
7734 Check_Arg_Count (1);
7735 Check_No_Identifiers;
7736 Check_Arg_Is_Local_Name (Arg1);
7737 Arg1_X := Expression (Arg1);
7739 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
7741 if not Is_Library_Level_Entity (Proc) then
7743 ("argument for pragma% must be library level entity", Arg1);
7746 -- The only processing required is to link this item on to the
7747 -- list of rep items for the given entity. This is accomplished
7748 -- by the call to Rep_Item_Too_Late (when no error is detected
7749 -- and False is returned).
7751 if Rep_Item_Too_Late (Proc, N) then
7754 Set_Has_Gigi_Rep_Item (Proc);
7756 end Linker_Constructor;
7758 --------------------
7759 -- Linker_Options --
7760 --------------------
7762 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7764 when Pragma_Linker_Options => Linker_Options : declare
7768 Check_Ada_83_Warning;
7769 Check_No_Identifiers;
7770 Check_Arg_Count (1);
7771 Check_Is_In_Decl_Part_Or_Package_Spec;
7773 if Operating_Mode = Generate_Code
7774 and then In_Extended_Main_Source_Unit (N)
7776 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7777 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7780 while Present (Arg) loop
7781 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7782 Store_String_Char (ASCII.NUL);
7784 (Strval (Expr_Value_S (Expression (Arg))));
7788 Store_Linker_Option_String (End_String);
7792 --------------------
7793 -- Linker_Section --
7794 --------------------
7796 -- pragma Linker_Section (
7797 -- [Entity =>] LOCAL_NAME
7798 -- [Section =>] static_string_EXPRESSION);
7800 when Pragma_Linker_Section =>
7802 Check_Arg_Order ((Name_Entity, Name_Section));
7803 Check_Arg_Count (2);
7804 Check_Optional_Identifier (Arg1, Name_Entity);
7805 Check_Optional_Identifier (Arg2, Name_Section);
7806 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7807 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7809 -- The only processing required is to link this item on to the
7810 -- list of rep items for the given entity. This is accomplished
7811 -- by the call to Rep_Item_Too_Late (when no error is detected
7812 -- and False is returned).
7814 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7817 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7824 -- pragma List (On | Off)
7826 -- There is nothing to do here, since we did all the processing
7827 -- for this pragma in Par.Prag (so that it works properly even in
7828 -- syntax only mode)
7833 --------------------
7834 -- Locking_Policy --
7835 --------------------
7837 -- pragma Locking_Policy (policy_IDENTIFIER);
7839 when Pragma_Locking_Policy => declare
7843 Check_Ada_83_Warning;
7844 Check_Arg_Count (1);
7845 Check_No_Identifiers;
7846 Check_Arg_Is_Locking_Policy (Arg1);
7847 Check_Valid_Configuration_Pragma;
7848 Get_Name_String (Chars (Expression (Arg1)));
7849 LP := Fold_Upper (Name_Buffer (1));
7851 if Locking_Policy /= ' '
7852 and then Locking_Policy /= LP
7854 Error_Msg_Sloc := Locking_Policy_Sloc;
7855 Error_Pragma ("locking policy incompatible with policy#");
7857 -- Set new policy, but always preserve System_Location since
7858 -- we like the error message with the run time name.
7861 Locking_Policy := LP;
7863 if Locking_Policy_Sloc /= System_Location then
7864 Locking_Policy_Sloc := Loc;
7873 -- pragma Long_Float (D_Float | G_Float);
7875 when Pragma_Long_Float =>
7877 Check_Valid_Configuration_Pragma;
7878 Check_Arg_Count (1);
7879 Check_No_Identifier (Arg1);
7880 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7882 if not OpenVMS_On_Target then
7883 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7888 if Chars (Expression (Arg1)) = Name_D_Float then
7889 if Opt.Float_Format_Long = 'G' then
7890 Error_Pragma ("G_Float previously specified");
7893 Opt.Float_Format_Long := 'D';
7895 -- G_Float case (this is the default, does not need overriding)
7898 if Opt.Float_Format_Long = 'D' then
7899 Error_Pragma ("D_Float previously specified");
7902 Opt.Float_Format_Long := 'G';
7905 Set_Standard_Fpt_Formats;
7907 -----------------------
7908 -- Machine_Attribute --
7909 -----------------------
7911 -- pragma Machine_Attribute (
7912 -- [Entity =>] LOCAL_NAME,
7913 -- [Attribute_Name =>] static_string_EXPRESSION
7914 -- [,[Info =>] static_string_EXPRESSION] );
7916 when Pragma_Machine_Attribute => Machine_Attribute : declare
7921 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
7923 if Arg_Count = 3 then
7924 Check_Optional_Identifier (Arg3, Name_Info);
7925 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7927 Check_Arg_Count (2);
7930 Check_Optional_Identifier (Arg1, Name_Entity);
7931 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
7932 Check_Arg_Is_Local_Name (Arg1);
7933 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7934 Def_Id := Entity (Expression (Arg1));
7936 if Is_Access_Type (Def_Id) then
7937 Def_Id := Designated_Type (Def_Id);
7940 if Rep_Item_Too_Early (Def_Id, N) then
7944 Def_Id := Underlying_Type (Def_Id);
7946 -- The only processing required is to link this item on to the
7947 -- list of rep items for the given entity. This is accomplished
7948 -- by the call to Rep_Item_Too_Late (when no error is detected
7949 -- and False is returned).
7951 if Rep_Item_Too_Late (Def_Id, N) then
7954 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7956 end Machine_Attribute;
7962 -- pragma Main_Storage
7963 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7965 -- MAIN_STORAGE_OPTION ::=
7966 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7967 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7969 when Pragma_Main => Main : declare
7970 Args : Args_List (1 .. 3);
7971 Names : constant Name_List (1 .. 3) := (
7973 Name_Task_Stack_Size_Default,
7974 Name_Time_Slicing_Enabled);
7980 Gather_Associations (Names, Args);
7982 for J in 1 .. 2 loop
7983 if Present (Args (J)) then
7984 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7988 if Present (Args (3)) then
7989 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7993 while Present (Nod) loop
7994 if Nkind (Nod) = N_Pragma
7995 and then Chars (Nod) = Name_Main
7997 Error_Msg_Name_1 := Chars (N);
7998 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8009 -- pragma Main_Storage
8010 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8012 -- MAIN_STORAGE_OPTION ::=
8013 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8014 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8016 when Pragma_Main_Storage => Main_Storage : declare
8017 Args : Args_List (1 .. 2);
8018 Names : constant Name_List (1 .. 2) := (
8019 Name_Working_Storage,
8026 Gather_Associations (Names, Args);
8028 for J in 1 .. 2 loop
8029 if Present (Args (J)) then
8030 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8034 Check_In_Main_Program;
8037 while Present (Nod) loop
8038 if Nkind (Nod) = N_Pragma
8039 and then Chars (Nod) = Name_Main_Storage
8041 Error_Msg_Name_1 := Chars (N);
8042 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8053 -- pragma Memory_Size (NUMERIC_LITERAL)
8055 when Pragma_Memory_Size =>
8058 -- Memory size is simply ignored
8060 Check_No_Identifiers;
8061 Check_Arg_Count (1);
8062 Check_Arg_Is_Integer_Literal (Arg1);
8068 -- pragma No_Return (procedure_LOCAL_NAME);
8070 when Pragma_No_Return => No_Return : declare
8077 Check_Arg_Count (1);
8078 Check_No_Identifiers;
8079 Check_Arg_Is_Local_Name (Arg1);
8080 Id := Expression (Arg1);
8083 if not Is_Entity_Name (Id) then
8084 Error_Pragma_Arg ("entity name required", Arg1);
8087 if Etype (Id) = Any_Type then
8095 and then Scope (E) = Current_Scope
8097 if Ekind (E) = E_Procedure
8098 or else Ekind (E) = E_Generic_Procedure
8108 Error_Pragma ("no procedures found for pragma%");
8112 ------------------------
8113 -- No_Strict_Aliasing --
8114 ------------------------
8116 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
8118 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
8123 Check_At_Most_N_Arguments (1);
8125 if Arg_Count = 0 then
8126 Check_Valid_Configuration_Pragma;
8127 Opt.No_Strict_Aliasing := True;
8130 Check_Optional_Identifier (Arg2, Name_Entity);
8131 Check_Arg_Is_Local_Name (Arg1);
8132 E_Id := Entity (Expression (Arg1));
8134 if E_Id = Any_Type then
8136 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
8137 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8140 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8142 end No_Strict_Alias;
8148 -- pragma Obsolescent [(static_string_EXPRESSION [, Ada_05])];
8150 when Pragma_Obsolescent => Obsolescent : declare
8151 Subp : Node_Or_Entity_Id;
8153 Active : Boolean := True;
8155 procedure Check_Obsolete_Subprogram;
8156 -- Checks if Subp is a subprogram declaration node, and if so
8157 -- replaces Subp by the defining entity of the subprogram. If not,
8158 -- issues an error message
8160 ------------------------------
8161 -- Check_Obsolete_Subprogram--
8162 ------------------------------
8164 procedure Check_Obsolete_Subprogram is
8166 if Nkind (Subp) /= N_Subprogram_Declaration then
8168 ("pragma% misplaced, must immediately " &
8169 "follow subprogram/package declaration");
8171 Subp := Defining_Entity (Subp);
8173 end Check_Obsolete_Subprogram;
8175 -- Start of processing for pragma Obsolescent
8179 Check_At_Most_N_Arguments (2);
8180 Check_No_Identifiers;
8182 -- Check OK placement
8184 -- First possibility is within a declarative region, where the
8185 -- pragma immediately follows a subprogram declaration.
8187 if Present (Prev (N)) then
8189 Check_Obsolete_Subprogram;
8191 -- Second possibility, stand alone subprogram declaration with the
8192 -- pragma immediately following the declaration.
8195 and then Nkind (Parent (N)) = N_Compilation_Unit_Aux
8197 Subp := Unit (Parent (Parent (N)));
8198 Check_Obsolete_Subprogram;
8200 -- Only other possibility is library unit placement for package
8203 Subp := Find_Lib_Unit_Name;
8205 if Ekind (Subp) /= E_Package
8206 and then Ekind (Subp) /= E_Generic_Package
8208 Check_Obsolete_Subprogram;
8212 -- If OK placement, acquire arguments
8214 if Arg_Count >= 1 then
8216 -- Deal with static string argument
8218 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8219 S := Strval (Expression (Arg1));
8221 for J in 1 .. String_Length (S) loop
8222 if not In_Character_Range (Get_String_Char (S, J)) then
8224 ("pragma% argument does not allow wide characters",
8229 Set_Obsolescent_Warning (Subp, Expression (Arg1));
8231 -- Check for Ada_05 parameter
8233 if Arg_Count /= 1 then
8234 Check_Arg_Count (2);
8237 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
8240 Check_Arg_Is_Identifier (Argx);
8242 if Chars (Argx) /= Name_Ada_05 then
8243 Error_Msg_Name_2 := Name_Ada_05;
8245 ("only allowed argument for pragma% is %", Argx);
8248 if Ada_Version_Explicit < Ada_05
8249 or else not Warn_On_Ada_2005_Compatibility
8257 -- Set flag if pragma active
8260 Set_Is_Obsolescent (Subp);
8268 -- pragma No_Run_Time
8270 -- Note: this pragma is retained for backwards compatibiltiy.
8271 -- See body of Rtsfind for full details on its handling.
8273 when Pragma_No_Run_Time =>
8275 Check_Valid_Configuration_Pragma;
8276 Check_Arg_Count (0);
8278 No_Run_Time_Mode := True;
8279 Configurable_Run_Time_Mode := True;
8282 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
8285 Duration_32_Bits_On_Target := True;
8289 Set_Restriction (No_Finalization, N);
8290 Set_Restriction (No_Exception_Handlers, N);
8291 Set_Restriction (Max_Tasks, N, 0);
8292 Set_Restriction (No_Tasking, N);
8294 -----------------------
8295 -- Normalize_Scalars --
8296 -----------------------
8298 -- pragma Normalize_Scalars;
8300 when Pragma_Normalize_Scalars =>
8301 Check_Ada_83_Warning;
8302 Check_Arg_Count (0);
8303 Check_Valid_Configuration_Pragma;
8304 Normalize_Scalars := True;
8305 Init_Or_Norm_Scalars := True;
8311 -- pragma Optimize (Time | Space);
8313 -- The actual check for optimize is done in Gigi. Note that this
8314 -- pragma does not actually change the optimization setting, it
8315 -- simply checks that it is consistent with the pragma.
8317 when Pragma_Optimize =>
8318 Check_No_Identifiers;
8319 Check_Arg_Count (1);
8320 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
8322 -------------------------
8323 -- Optional_Overriding --
8324 -------------------------
8326 -- These pragmas are treated as part of the previous subprogram
8327 -- declaration, and analyzed immediately after it (see sem_ch6,
8328 -- Check_Overriding_Operation). If the pragma has not been analyzed
8329 -- yet, it appears in the wrong place.
8331 when Pragma_Optional_Overriding =>
8332 Error_Msg_N ("pragma must appear immediately after subprogram", N);
8338 -- pragma Pack (first_subtype_LOCAL_NAME);
8340 when Pragma_Pack => Pack : declare
8341 Assoc : constant Node_Id := Arg1;
8346 Check_No_Identifiers;
8347 Check_Arg_Count (1);
8348 Check_Arg_Is_Local_Name (Arg1);
8350 Type_Id := Expression (Assoc);
8351 Find_Type (Type_Id);
8352 Typ := Entity (Type_Id);
8355 or else Rep_Item_Too_Early (Typ, N)
8359 Typ := Underlying_Type (Typ);
8362 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
8363 Error_Pragma ("pragma% must specify array or record type");
8366 Check_First_Subtype (Arg1);
8368 if Has_Pragma_Pack (Typ) then
8369 Error_Pragma ("duplicate pragma%, only one allowed");
8373 elsif Is_Array_Type (Typ) then
8375 -- Pack not allowed for aliased or atomic components
8377 if Has_Aliased_Components (Base_Type (Typ)) then
8379 ("pragma% ignored, cannot pack aliased components?");
8381 elsif Has_Atomic_Components (Typ)
8382 or else Is_Atomic (Component_Type (Typ))
8385 ("?pragma% ignored, cannot pack atomic components");
8388 -- If we had an explicit component size given, then we do not
8389 -- let Pack override this given size. We also give a warning
8390 -- that Pack is being ignored unless we can tell for sure that
8391 -- the Pack would not have had any effect anyway.
8393 if Has_Component_Size_Clause (Typ) then
8394 if Known_Static_RM_Size (Component_Type (Typ))
8396 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
8401 ("?pragma% ignored, explicit component size given");
8404 -- If no prior array component size given, Pack is effective
8407 if not Rep_Item_Too_Late (Typ, N) then
8408 Set_Is_Packed (Base_Type (Typ));
8409 Set_Has_Pragma_Pack (Base_Type (Typ));
8410 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8414 -- For record types, the pack is always effective
8416 else pragma Assert (Is_Record_Type (Typ));
8417 if not Rep_Item_Too_Late (Typ, N) then
8418 Set_Has_Pragma_Pack (Base_Type (Typ));
8419 Set_Is_Packed (Base_Type (Typ));
8420 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8431 -- There is nothing to do here, since we did all the processing
8432 -- for this pragma in Par.Prag (so that it works properly even in
8433 -- syntax only mode)
8442 -- pragma Passive [(PASSIVE_FORM)];
8444 -- PASSIVE_FORM ::= Semaphore | No
8446 when Pragma_Passive =>
8449 if Nkind (Parent (N)) /= N_Task_Definition then
8450 Error_Pragma ("pragma% must be within task definition");
8453 if Arg_Count /= 0 then
8454 Check_Arg_Count (1);
8455 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8462 -- pragma Polling (ON | OFF);
8464 when Pragma_Polling =>
8466 Check_Arg_Count (1);
8467 Check_No_Identifiers;
8468 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8469 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8471 --------------------
8472 -- Persistent_BSS --
8473 --------------------
8475 when Pragma_Persistent_BSS => Persistent_BSS : declare
8482 Check_At_Most_N_Arguments (1);
8484 -- Case of application to specific object (one argument)
8486 if Arg_Count = 1 then
8487 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8489 if not Is_Entity_Name (Expression (Arg1))
8491 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8492 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8494 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
8497 Ent := Entity (Expression (Arg1));
8498 Decl := Parent (Ent);
8500 if Rep_Item_Too_Late (Ent, N) then
8504 if Present (Expression (Decl)) then
8506 ("object for pragma% cannot have initialization", Arg1);
8509 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
8511 ("object type for pragma% is not potentially persistent",
8516 Make_Linker_Section_Pragma
8517 (Ent, Sloc (N), ".persistent.bss");
8518 Insert_After (N, Prag);
8521 -- Case of use as configuration pragma with no arguments
8524 Check_Valid_Configuration_Pragma;
8525 Persistent_BSS_Mode := True;
8533 -- pragma Preelaborate [(library_unit_NAME)];
8535 -- Set the flag Is_Preelaborated of program unit name entity
8537 when Pragma_Preelaborate => Preelaborate : declare
8538 Pa : constant Node_Id := Parent (N);
8539 Pk : constant Node_Kind := Nkind (Pa);
8543 Check_Ada_83_Warning;
8544 Check_Valid_Library_Unit_Pragma;
8546 if Nkind (N) = N_Null_Statement then
8550 Ent := Find_Lib_Unit_Name;
8552 -- This filters out pragmas inside generic parent then
8553 -- show up inside instantiation
8556 and then not (Pk = N_Package_Specification
8557 and then Present (Generic_Parent (Pa)))
8559 if not Debug_Flag_U then
8560 Set_Is_Preelaborated (Ent);
8561 Set_Suppress_Elaboration_Warnings (Ent);
8566 ---------------------
8567 -- Preelaborate_05 --
8568 ---------------------
8570 -- pragma Preelaborate_05 [(library_unit_NAME)];
8572 -- This pragma is useable only in GNAT_Mode, where it is used like
8573 -- pragma Preelaborate but it is only effective in Ada 2005 mode
8574 -- (otherwise it is ignored). This is used to implement AI-362 which
8575 -- recategorizes some run-time packages in Ada 2005 mode.
8577 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
8582 Check_Valid_Library_Unit_Pragma;
8584 if not GNAT_Mode then
8585 Error_Pragma ("pragma% only available in GNAT mode");
8588 if Nkind (N) = N_Null_Statement then
8592 -- This is one of the few cases where we need to test the value of
8593 -- Ada_Version_Explicit rather than Ada_Version (which is always
8594 -- set to Ada_05 in a predefined unit), we need to know the
8595 -- explicit version set to know if this pragma is active.
8597 if Ada_Version_Explicit >= Ada_05 then
8598 Ent := Find_Lib_Unit_Name;
8599 Set_Is_Preelaborated (Ent);
8600 Set_Suppress_Elaboration_Warnings (Ent);
8602 end Preelaborate_05;
8608 -- pragma Priority (EXPRESSION);
8610 when Pragma_Priority => Priority : declare
8611 P : constant Node_Id := Parent (N);
8615 Check_No_Identifiers;
8616 Check_Arg_Count (1);
8620 if Nkind (P) = N_Subprogram_Body then
8621 Check_In_Main_Program;
8623 Arg := Expression (Arg1);
8624 Analyze_And_Resolve (Arg, Standard_Integer);
8628 if not Is_Static_Expression (Arg) then
8629 Flag_Non_Static_Expr
8630 ("main subprogram priority is not static!", Arg);
8633 -- If constraint error, then we already signalled an error
8635 elsif Raises_Constraint_Error (Arg) then
8638 -- Otherwise check in range
8642 Val : constant Uint := Expr_Value (Arg);
8646 or else Val > Expr_Value (Expression
8647 (Parent (RTE (RE_Max_Priority))))
8650 ("main subprogram priority is out of range", Arg1);
8656 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8658 -- Task or Protected, must be of type Integer
8660 elsif Nkind (P) = N_Protected_Definition
8662 Nkind (P) = N_Task_Definition
8664 Arg := Expression (Arg1);
8666 -- The expression must be analyzed in the special manner
8667 -- described in "Handling of Default and Per-Object
8668 -- Expressions" in sem.ads.
8670 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8672 if not Is_Static_Expression (Arg) then
8673 Check_Restriction (Static_Priorities, Arg);
8676 -- Anything else is incorrect
8682 if Has_Priority_Pragma (P) then
8683 Error_Pragma ("duplicate pragma% not allowed");
8685 Set_Has_Priority_Pragma (P, True);
8687 if Nkind (P) = N_Protected_Definition
8689 Nkind (P) = N_Task_Definition
8691 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8692 -- exp_ch9 should use this ???
8701 -- pragma Profile (profile_IDENTIFIER);
8703 -- profile_IDENTIFIER => Protected | Ravenscar
8705 when Pragma_Profile =>
8706 Check_Arg_Count (1);
8707 Check_Valid_Configuration_Pragma;
8708 Check_No_Identifiers;
8711 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8713 if Chars (Argx) = Name_Ravenscar then
8714 Set_Ravenscar_Profile (N);
8716 elsif Chars (Argx) = Name_Restricted then
8717 Set_Profile_Restrictions (Restricted, N, Warn => False);
8719 Error_Pragma_Arg ("& is not a valid profile", Argx);
8723 ----------------------
8724 -- Profile_Warnings --
8725 ----------------------
8727 -- pragma Profile_Warnings (profile_IDENTIFIER);
8729 -- profile_IDENTIFIER => Protected | Ravenscar
8731 when Pragma_Profile_Warnings =>
8733 Check_Arg_Count (1);
8734 Check_Valid_Configuration_Pragma;
8735 Check_No_Identifiers;
8738 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8740 if Chars (Argx) = Name_Ravenscar then
8741 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8743 elsif Chars (Argx) = Name_Restricted then
8744 Set_Profile_Restrictions (Restricted, N, Warn => True);
8746 Error_Pragma_Arg ("& is not a valid profile", Argx);
8750 --------------------------
8751 -- Propagate_Exceptions --
8752 --------------------------
8754 -- pragma Propagate_Exceptions;
8756 when Pragma_Propagate_Exceptions =>
8758 Check_Arg_Count (0);
8760 if In_Extended_Main_Source_Unit (N) then
8761 Propagate_Exceptions := True;
8768 -- pragma Psect_Object (
8769 -- [Internal =>] LOCAL_NAME,
8770 -- [, [External =>] EXTERNAL_SYMBOL]
8771 -- [, [Size =>] EXTERNAL_SYMBOL]);
8773 when Pragma_Psect_Object | Pragma_Common_Object =>
8774 Psect_Object : declare
8775 Args : Args_List (1 .. 3);
8776 Names : constant Name_List (1 .. 3) := (
8781 Internal : Node_Id renames Args (1);
8782 External : Node_Id renames Args (2);
8783 Size : Node_Id renames Args (3);
8787 procedure Check_Too_Long (Arg : Node_Id);
8788 -- Posts message if the argument is an identifier with more
8789 -- than 31 characters, or a string literal with more than
8790 -- 31 characters, and we are operating under VMS
8792 --------------------
8793 -- Check_Too_Long --
8794 --------------------
8796 procedure Check_Too_Long (Arg : Node_Id) is
8797 X : constant Node_Id := Original_Node (Arg);
8800 if Nkind (X) /= N_String_Literal
8802 Nkind (X) /= N_Identifier
8805 ("inappropriate argument for pragma %", Arg);
8808 if OpenVMS_On_Target then
8809 if (Nkind (X) = N_String_Literal
8810 and then String_Length (Strval (X)) > 31)
8812 (Nkind (X) = N_Identifier
8813 and then Length_Of_Name (Chars (X)) > 31)
8816 ("argument for pragma % is longer than 31 characters",
8822 -- Start of processing for Common_Object/Psect_Object
8826 Gather_Associations (Names, Args);
8827 Process_Extended_Import_Export_Internal_Arg (Internal);
8829 Def_Id := Entity (Internal);
8831 if Ekind (Def_Id) /= E_Constant
8832 and then Ekind (Def_Id) /= E_Variable
8835 ("pragma% must designate an object", Internal);
8838 Check_Too_Long (Internal);
8840 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8842 ("cannot use pragma% for imported/exported object",
8846 if Is_Concurrent_Type (Etype (Internal)) then
8848 ("cannot specify pragma % for task/protected object",
8852 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8854 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8856 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
8859 if Ekind (Def_Id) = E_Constant then
8861 ("cannot specify pragma % for a constant", Internal);
8864 if Is_Record_Type (Etype (Internal)) then
8870 Ent := First_Entity (Etype (Internal));
8871 while Present (Ent) loop
8872 Decl := Declaration_Node (Ent);
8874 if Ekind (Ent) = E_Component
8875 and then Nkind (Decl) = N_Component_Declaration
8876 and then Present (Expression (Decl))
8877 and then Warn_On_Export_Import
8880 ("?object for pragma % has defaults", Internal);
8890 if Present (Size) then
8891 Check_Too_Long (Size);
8894 if Present (External) then
8895 Check_Arg_Is_External_Name (External);
8896 Check_Too_Long (External);
8899 -- If all error tests pass, link pragma on to the rep item chain
8901 Record_Rep_Item (Def_Id, N);
8908 -- pragma Pure [(library_unit_NAME)];
8910 when Pragma_Pure => Pure : declare
8914 Check_Ada_83_Warning;
8915 Check_Valid_Library_Unit_Pragma;
8917 if Nkind (N) = N_Null_Statement then
8921 Ent := Find_Lib_Unit_Name;
8923 Set_Suppress_Elaboration_Warnings (Ent);
8930 -- pragma Pure_05 [(library_unit_NAME)];
8932 -- This pragma is useable only in GNAT_Mode, where it is used like
8933 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
8934 -- it is ignored). It may be used after a pragma Preelaborate, in
8935 -- which case it overrides the effect of the pragma Preelaborate.
8936 -- This is used to implement AI-362 which recategorizes some run-time
8937 -- packages in Ada 2005 mode.
8939 when Pragma_Pure_05 => Pure_05 : declare
8944 Check_Valid_Library_Unit_Pragma;
8946 if not GNAT_Mode then
8947 Error_Pragma ("pragma% only available in GNAT mode");
8949 if Nkind (N) = N_Null_Statement then
8953 -- This is one of the few cases where we need to test the value of
8954 -- Ada_Version_Explicit rather than Ada_Version (which is always
8955 -- set to Ada_05 in a predefined unit), we need to know the
8956 -- explicit version set to know if this pragma is active.
8958 if Ada_Version_Explicit >= Ada_05 then
8959 Ent := Find_Lib_Unit_Name;
8960 Set_Is_Preelaborated (Ent, False);
8962 Set_Suppress_Elaboration_Warnings (Ent);
8970 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8972 when Pragma_Pure_Function => Pure_Function : declare
8976 Effective : Boolean := False;
8980 Check_Arg_Count (1);
8981 Check_Optional_Identifier (Arg1, Name_Entity);
8982 Check_Arg_Is_Local_Name (Arg1);
8983 E_Id := Expression (Arg1);
8985 if Error_Posted (E_Id) then
8989 -- Loop through homonyms (overloadings) of referenced entity
8995 Def_Id := Get_Base_Subprogram (E);
8997 if Ekind (Def_Id) /= E_Function
8998 and then Ekind (Def_Id) /= E_Generic_Function
8999 and then Ekind (Def_Id) /= E_Operator
9002 ("pragma% requires a function name", Arg1);
9005 Set_Is_Pure (Def_Id);
9007 if not Has_Pragma_Pure_Function (Def_Id) then
9008 Set_Has_Pragma_Pure_Function (Def_Id);
9013 exit when No (E) or else Scope (E) /= Current_Scope;
9017 and then Warn_On_Redundant_Constructs
9019 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
9025 --------------------
9026 -- Queuing_Policy --
9027 --------------------
9029 -- pragma Queuing_Policy (policy_IDENTIFIER);
9031 when Pragma_Queuing_Policy => declare
9035 Check_Ada_83_Warning;
9036 Check_Arg_Count (1);
9037 Check_No_Identifiers;
9038 Check_Arg_Is_Queuing_Policy (Arg1);
9039 Check_Valid_Configuration_Pragma;
9040 Get_Name_String (Chars (Expression (Arg1)));
9041 QP := Fold_Upper (Name_Buffer (1));
9043 if Queuing_Policy /= ' '
9044 and then Queuing_Policy /= QP
9046 Error_Msg_Sloc := Queuing_Policy_Sloc;
9047 Error_Pragma ("queuing policy incompatible with policy#");
9049 -- Set new policy, but always preserve System_Location since
9050 -- we like the error message with the run time name.
9053 Queuing_Policy := QP;
9055 if Queuing_Policy_Sloc /= System_Location then
9056 Queuing_Policy_Sloc := Loc;
9061 ---------------------------
9062 -- Remote_Call_Interface --
9063 ---------------------------
9065 -- pragma Remote_Call_Interface [(library_unit_NAME)];
9067 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
9068 Cunit_Node : Node_Id;
9069 Cunit_Ent : Entity_Id;
9073 Check_Ada_83_Warning;
9074 Check_Valid_Library_Unit_Pragma;
9076 if Nkind (N) = N_Null_Statement then
9080 Cunit_Node := Cunit (Current_Sem_Unit);
9081 K := Nkind (Unit (Cunit_Node));
9082 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9084 if K = N_Package_Declaration
9085 or else K = N_Generic_Package_Declaration
9086 or else K = N_Subprogram_Declaration
9087 or else K = N_Generic_Subprogram_Declaration
9088 or else (K = N_Subprogram_Body
9089 and then Acts_As_Spec (Unit (Cunit_Node)))
9094 "pragma% must apply to package or subprogram declaration");
9097 Set_Is_Remote_Call_Interface (Cunit_Ent);
9098 end Remote_Call_Interface;
9104 -- pragma Remote_Types [(library_unit_NAME)];
9106 when Pragma_Remote_Types => Remote_Types : declare
9107 Cunit_Node : Node_Id;
9108 Cunit_Ent : Entity_Id;
9111 Check_Ada_83_Warning;
9112 Check_Valid_Library_Unit_Pragma;
9114 if Nkind (N) = N_Null_Statement then
9118 Cunit_Node := Cunit (Current_Sem_Unit);
9119 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9121 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9123 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9126 "pragma% can only apply to a package declaration");
9129 Set_Is_Remote_Types (Cunit_Ent);
9136 -- pragma Ravenscar;
9138 when Pragma_Ravenscar =>
9140 Check_Arg_Count (0);
9141 Check_Valid_Configuration_Pragma;
9142 Set_Ravenscar_Profile (N);
9144 if Warn_On_Obsolescent_Feature then
9146 ("pragma Ravenscar is an obsolescent feature?", N);
9148 ("|use pragma Profile (Ravenscar) instead", N);
9151 -------------------------
9152 -- Restricted_Run_Time --
9153 -------------------------
9155 -- pragma Restricted_Run_Time;
9157 when Pragma_Restricted_Run_Time =>
9159 Check_Arg_Count (0);
9160 Check_Valid_Configuration_Pragma;
9161 Set_Profile_Restrictions (Restricted, N, Warn => False);
9163 if Warn_On_Obsolescent_Feature then
9165 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
9167 ("|use pragma Profile (Restricted) instead", N);
9174 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
9177 -- restriction_IDENTIFIER
9178 -- | restriction_parameter_IDENTIFIER => EXPRESSION
9180 when Pragma_Restrictions =>
9181 Process_Restrictions_Or_Restriction_Warnings;
9183 --------------------------
9184 -- Restriction_Warnings --
9185 --------------------------
9187 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
9190 -- restriction_IDENTIFIER
9191 -- | restriction_parameter_IDENTIFIER => EXPRESSION
9193 when Pragma_Restriction_Warnings =>
9194 Process_Restrictions_Or_Restriction_Warnings;
9200 -- pragma Reviewable;
9202 when Pragma_Reviewable =>
9203 Check_Ada_83_Warning;
9204 Check_Arg_Count (0);
9210 -- pragma Share_Generic (NAME {, NAME});
9212 when Pragma_Share_Generic =>
9214 Process_Generic_List;
9220 -- pragma Shared (LOCAL_NAME);
9222 when Pragma_Shared =>
9224 Process_Atomic_Shared_Volatile;
9226 --------------------
9227 -- Shared_Passive --
9228 --------------------
9230 -- pragma Shared_Passive [(library_unit_NAME)];
9232 -- Set the flag Is_Shared_Passive of program unit name entity
9234 when Pragma_Shared_Passive => Shared_Passive : declare
9235 Cunit_Node : Node_Id;
9236 Cunit_Ent : Entity_Id;
9239 Check_Ada_83_Warning;
9240 Check_Valid_Library_Unit_Pragma;
9242 if Nkind (N) = N_Null_Statement then
9246 Cunit_Node := Cunit (Current_Sem_Unit);
9247 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9249 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9251 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9254 "pragma% can only apply to a package declaration");
9257 Set_Is_Shared_Passive (Cunit_Ent);
9260 ----------------------
9261 -- Source_File_Name --
9262 ----------------------
9264 -- There are five forms for this pragma:
9266 -- pragma Source_File_Name (
9267 -- [UNIT_NAME =>] unit_NAME,
9268 -- BODY_FILE_NAME => STRING_LITERAL
9269 -- [, [INDEX =>] INTEGER_LITERAL]);
9271 -- pragma Source_File_Name (
9272 -- [UNIT_NAME =>] unit_NAME,
9273 -- SPEC_FILE_NAME => STRING_LITERAL
9274 -- [, [INDEX =>] INTEGER_LITERAL]);
9276 -- pragma Source_File_Name (
9277 -- BODY_FILE_NAME => STRING_LITERAL
9278 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9279 -- [, CASING => CASING_SPEC]);
9281 -- pragma Source_File_Name (
9282 -- SPEC_FILE_NAME => STRING_LITERAL
9283 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9284 -- [, CASING => CASING_SPEC]);
9286 -- pragma Source_File_Name (
9287 -- SUBUNIT_FILE_NAME => STRING_LITERAL
9288 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9289 -- [, CASING => CASING_SPEC]);
9291 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
9293 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
9294 -- Source_File_Name (SFN), however their usage is exclusive:
9295 -- SFN can only be used when no project file is used, while
9296 -- SFNP can only be used when a project file is used.
9298 -- No processing here. Processing was completed during parsing,
9299 -- since we need to have file names set as early as possible.
9300 -- Units are loaded well before semantic processing starts.
9302 -- The only processing we defer to this point is the check
9303 -- for correct placement.
9305 when Pragma_Source_File_Name =>
9307 Check_Valid_Configuration_Pragma;
9309 ------------------------------
9310 -- Source_File_Name_Project --
9311 ------------------------------
9313 -- See Source_File_Name for syntax
9315 -- No processing here. Processing was completed during parsing,
9316 -- since we need to have file names set as early as possible.
9317 -- Units are loaded well before semantic processing starts.
9319 -- The only processing we defer to this point is the check
9320 -- for correct placement.
9322 when Pragma_Source_File_Name_Project =>
9324 Check_Valid_Configuration_Pragma;
9326 -- Check that a pragma Source_File_Name_Project is used only
9327 -- in a configuration pragmas file.
9329 -- Pragmas Source_File_Name_Project should only be generated
9330 -- by the Project Manager in configuration pragmas files.
9332 -- This is really an ugly test. It seems to depend on some
9333 -- accidental and undocumented property. At the very least
9334 -- it needs to be documented, but it would be better to have
9335 -- a clean way of testing if we are in a configuration file???
9337 if Present (Parent (N)) then
9339 ("pragma% can only appear in a configuration pragmas file");
9342 ----------------------
9343 -- Source_Reference --
9344 ----------------------
9346 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9348 -- Nothing to do, all processing completed in Par.Prag, since we
9349 -- need the information for possible parser messages that are output
9351 when Pragma_Source_Reference =>
9358 -- pragma Storage_Size (EXPRESSION);
9360 when Pragma_Storage_Size => Storage_Size : declare
9361 P : constant Node_Id := Parent (N);
9365 Check_No_Identifiers;
9366 Check_Arg_Count (1);
9368 -- The expression must be analyzed in the special manner
9369 -- described in "Handling of Default Expressions" in sem.ads.
9371 -- Set In_Default_Expression for per-object case ???
9373 Arg := Expression (Arg1);
9374 Analyze_Per_Use_Expression (Arg, Any_Integer);
9376 if not Is_Static_Expression (Arg) then
9377 Check_Restriction (Static_Storage_Size, Arg);
9380 if Nkind (P) /= N_Task_Definition then
9385 if Has_Storage_Size_Pragma (P) then
9386 Error_Pragma ("duplicate pragma% not allowed");
9388 Set_Has_Storage_Size_Pragma (P, True);
9391 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9392 -- ??? exp_ch9 should use this!
9400 -- pragma Storage_Unit (NUMERIC_LITERAL);
9402 -- Only permitted argument is System'Storage_Unit value
9404 when Pragma_Storage_Unit =>
9405 Check_No_Identifiers;
9406 Check_Arg_Count (1);
9407 Check_Arg_Is_Integer_Literal (Arg1);
9409 if Intval (Expression (Arg1)) /=
9410 UI_From_Int (Ttypes.System_Storage_Unit)
9412 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9414 ("the only allowed argument for pragma% is ^", Arg1);
9417 --------------------
9418 -- Stream_Convert --
9419 --------------------
9421 -- pragma Stream_Convert (
9422 -- [Entity =>] type_LOCAL_NAME,
9423 -- [Read =>] function_NAME,
9424 -- [Write =>] function NAME);
9426 when Pragma_Stream_Convert => Stream_Convert : declare
9428 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9429 -- Check that the given argument is the name of a local
9430 -- function of one argument that is not overloaded earlier
9431 -- in the current local scope. A check is also made that the
9432 -- argument is a function with one parameter.
9434 --------------------------------------
9435 -- Check_OK_Stream_Convert_Function --
9436 --------------------------------------
9438 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9442 Check_Arg_Is_Local_Name (Arg);
9443 Ent := Entity (Expression (Arg));
9445 if Has_Homonym (Ent) then
9447 ("argument for pragma% may not be overloaded", Arg);
9450 if Ekind (Ent) /= E_Function
9451 or else No (First_Formal (Ent))
9452 or else Present (Next_Formal (First_Formal (Ent)))
9455 ("argument for pragma% must be" &
9456 " function of one argument", Arg);
9458 end Check_OK_Stream_Convert_Function;
9460 -- Start of procecessing for Stream_Convert
9464 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
9465 Check_Arg_Count (3);
9466 Check_Optional_Identifier (Arg1, Name_Entity);
9467 Check_Optional_Identifier (Arg2, Name_Read);
9468 Check_Optional_Identifier (Arg3, Name_Write);
9469 Check_Arg_Is_Local_Name (Arg1);
9470 Check_OK_Stream_Convert_Function (Arg2);
9471 Check_OK_Stream_Convert_Function (Arg3);
9474 Typ : constant Entity_Id :=
9475 Underlying_Type (Entity (Expression (Arg1)));
9476 Read : constant Entity_Id := Entity (Expression (Arg2));
9477 Write : constant Entity_Id := Entity (Expression (Arg3));
9480 if Etype (Typ) = Any_Type
9482 Etype (Read) = Any_Type
9484 Etype (Write) = Any_Type
9489 Check_First_Subtype (Arg1);
9491 if Rep_Item_Too_Early (Typ, N)
9493 Rep_Item_Too_Late (Typ, N)
9498 if Underlying_Type (Etype (Read)) /= Typ then
9500 ("incorrect return type for function&", Arg2);
9503 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9505 ("incorrect parameter type for function&", Arg3);
9508 if Underlying_Type (Etype (First_Formal (Read))) /=
9509 Underlying_Type (Etype (Write))
9512 ("result type of & does not match Read parameter type",
9518 -------------------------
9519 -- Style_Checks (GNAT) --
9520 -------------------------
9522 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9524 -- This is processed by the parser since some of the style
9525 -- checks take place during source scanning and parsing. This
9526 -- means that we don't need to issue error messages here.
9528 when Pragma_Style_Checks => Style_Checks : declare
9529 A : constant Node_Id := Expression (Arg1);
9535 Check_No_Identifiers;
9537 -- Two argument form
9539 if Arg_Count = 2 then
9540 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9547 E_Id := Expression (Arg2);
9550 if not Is_Entity_Name (E_Id) then
9552 ("second argument of pragma% must be entity name",
9562 Set_Suppress_Style_Checks (E,
9563 (Chars (Expression (Arg1)) = Name_Off));
9564 exit when No (Homonym (E));
9570 -- One argument form
9573 Check_Arg_Count (1);
9575 if Nkind (A) = N_String_Literal then
9579 Slen : constant Natural := Natural (String_Length (S));
9580 Options : String (1 .. Slen);
9586 C := Get_String_Char (S, Int (J));
9587 exit when not In_Character_Range (C);
9588 Options (J) := Get_Character (C);
9591 Set_Style_Check_Options (Options);
9599 elsif Nkind (A) = N_Identifier then
9601 if Chars (A) = Name_All_Checks then
9602 Set_Default_Style_Check_Options;
9604 elsif Chars (A) = Name_On then
9605 Style_Check := True;
9607 elsif Chars (A) = Name_Off then
9608 Style_Check := False;
9619 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9621 when Pragma_Subtitle =>
9623 Check_Arg_Count (1);
9624 Check_Optional_Identifier (Arg1, Name_Subtitle);
9625 Check_Arg_Is_String_Literal (Arg1);
9631 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9633 when Pragma_Suppress =>
9634 Process_Suppress_Unsuppress (True);
9640 -- pragma Suppress_All;
9642 -- The only check made here is that the pragma appears in the
9643 -- proper place, i.e. following a compilation unit. If indeed
9644 -- it appears in this context, then the parser has already
9645 -- inserted an equivalent pragma Suppress (All_Checks) to get
9646 -- the required effect.
9648 when Pragma_Suppress_All =>
9650 Check_Arg_Count (0);
9652 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9653 or else not Is_List_Member (N)
9654 or else List_Containing (N) /= Pragmas_After (Parent (N))
9657 ("misplaced pragma%, must follow compilation unit");
9660 -------------------------
9661 -- Suppress_Debug_Info --
9662 -------------------------
9664 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9666 when Pragma_Suppress_Debug_Info =>
9668 Check_Arg_Count (1);
9669 Check_Optional_Identifier (Arg1, Name_Entity);
9670 Check_Arg_Is_Local_Name (Arg1);
9671 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9673 ----------------------------------
9674 -- Suppress_Exception_Locations --
9675 ----------------------------------
9677 -- pragma Suppress_Exception_Locations;
9679 when Pragma_Suppress_Exception_Locations =>
9681 Check_Arg_Count (0);
9682 Check_Valid_Configuration_Pragma;
9683 Exception_Locations_Suppressed := True;
9685 -----------------------------
9686 -- Suppress_Initialization --
9687 -----------------------------
9689 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9691 when Pragma_Suppress_Initialization => Suppress_Init : declare
9697 Check_Arg_Count (1);
9698 Check_Optional_Identifier (Arg1, Name_Entity);
9699 Check_Arg_Is_Local_Name (Arg1);
9701 E_Id := Expression (Arg1);
9703 if Etype (E_Id) = Any_Type then
9710 if Is_Incomplete_Or_Private_Type (E) then
9711 if No (Full_View (Base_Type (E))) then
9713 ("argument of pragma% cannot be an incomplete type",
9716 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9719 Set_Suppress_Init_Proc (Base_Type (E));
9724 ("pragma% requires argument that is a type name", Arg1);
9732 -- pragma System_Name (DIRECT_NAME);
9734 -- Syntax check: one argument, which must be the identifier GNAT
9735 -- or the identifier GCC, no other identifiers are acceptable.
9737 when Pragma_System_Name =>
9738 Check_No_Identifiers;
9739 Check_Arg_Count (1);
9740 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9742 -----------------------------
9743 -- Task_Dispatching_Policy --
9744 -----------------------------
9746 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9748 when Pragma_Task_Dispatching_Policy => declare
9752 Check_Ada_83_Warning;
9753 Check_Arg_Count (1);
9754 Check_No_Identifiers;
9755 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9756 Check_Valid_Configuration_Pragma;
9757 Get_Name_String (Chars (Expression (Arg1)));
9758 DP := Fold_Upper (Name_Buffer (1));
9760 if Task_Dispatching_Policy /= ' '
9761 and then Task_Dispatching_Policy /= DP
9763 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9765 ("task dispatching policy incompatible with policy#");
9767 -- Set new policy, but always preserve System_Location since
9768 -- we like the error message with the run time name.
9771 Task_Dispatching_Policy := DP;
9773 if Task_Dispatching_Policy_Sloc /= System_Location then
9774 Task_Dispatching_Policy_Sloc := Loc;
9783 -- pragma Task_Info (EXPRESSION);
9785 when Pragma_Task_Info => Task_Info : declare
9786 P : constant Node_Id := Parent (N);
9791 if Nkind (P) /= N_Task_Definition then
9792 Error_Pragma ("pragma% must appear in task definition");
9795 Check_No_Identifiers;
9796 Check_Arg_Count (1);
9798 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9800 if Etype (Expression (Arg1)) = Any_Type then
9804 if Has_Task_Info_Pragma (P) then
9805 Error_Pragma ("duplicate pragma% not allowed");
9807 Set_Has_Task_Info_Pragma (P, True);
9815 -- pragma Task_Name (string_EXPRESSION);
9817 when Pragma_Task_Name => Task_Name : declare
9818 -- pragma Priority (EXPRESSION);
9820 P : constant Node_Id := Parent (N);
9824 Check_No_Identifiers;
9825 Check_Arg_Count (1);
9827 Arg := Expression (Arg1);
9828 Analyze_And_Resolve (Arg, Standard_String);
9830 if Nkind (P) /= N_Task_Definition then
9834 if Has_Task_Name_Pragma (P) then
9835 Error_Pragma ("duplicate pragma% not allowed");
9837 Set_Has_Task_Name_Pragma (P, True);
9838 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9846 -- pragma Task_Storage (
9847 -- [Task_Type =>] LOCAL_NAME,
9848 -- [Top_Guard =>] static_integer_EXPRESSION);
9850 when Pragma_Task_Storage => Task_Storage : declare
9851 Args : Args_List (1 .. 2);
9852 Names : constant Name_List (1 .. 2) := (
9856 Task_Type : Node_Id renames Args (1);
9857 Top_Guard : Node_Id renames Args (2);
9863 Gather_Associations (Names, Args);
9865 if No (Task_Type) then
9867 ("missing task_type argument for pragma%");
9870 Check_Arg_Is_Local_Name (Task_Type);
9872 Ent := Entity (Task_Type);
9874 if not Is_Task_Type (Ent) then
9876 ("argument for pragma% must be task type", Task_Type);
9879 if No (Top_Guard) then
9881 ("pragma% takes two arguments", Task_Type);
9883 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9886 Check_First_Subtype (Task_Type);
9888 if Rep_Item_Too_Late (Ent, N) then
9897 -- pragma Thread_Body
9898 -- ( [Entity =>] LOCAL_NAME
9899 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9901 when Pragma_Thread_Body => Thread_Body : declare
9908 Check_Arg_Order ((Name_Entity, Name_Secondary_Stack_Size));
9909 Check_At_Least_N_Arguments (1);
9910 Check_At_Most_N_Arguments (2);
9911 Check_Optional_Identifier (Arg1, Name_Entity);
9912 Check_Arg_Is_Local_Name (Arg1);
9914 Id := Expression (Arg1);
9916 if not Is_Entity_Name (Id)
9917 or else not Is_Subprogram (Entity (Id))
9919 Error_Pragma_Arg ("subprogram name required", Arg1);
9924 -- Go to renamed subprogram if present, since Thread_Body applies
9925 -- to the actual renamed entity, not to the renaming entity.
9927 if Present (Alias (E))
9928 and then Nkind (Parent (Declaration_Node (E))) =
9929 N_Subprogram_Renaming_Declaration
9934 -- Various error checks
9936 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9938 ("pragma% requires separate spec and must come before body");
9940 elsif Rep_Item_Too_Early (E, N)
9941 or else Rep_Item_Too_Late (E, N)
9945 elsif Is_Thread_Body (E) then
9947 ("only one thread body pragma allowed", Arg1);
9949 elsif Present (Homonym (E))
9950 and then Scope (Homonym (E)) = Current_Scope
9953 ("thread body subprogram must not be overloaded", Arg1);
9956 Set_Is_Thread_Body (E);
9958 -- Deal with secondary stack argument
9960 if Arg_Count = 2 then
9961 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9962 SS := Expression (Arg2);
9963 Analyze_And_Resolve (SS, Any_Integer);
9971 -- pragma Time_Slice (static_duration_EXPRESSION);
9973 when Pragma_Time_Slice => Time_Slice : declare
9979 Check_Arg_Count (1);
9980 Check_No_Identifiers;
9981 Check_In_Main_Program;
9982 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9984 if not Error_Posted (Arg1) then
9986 while Present (Nod) loop
9987 if Nkind (Nod) = N_Pragma
9988 and then Chars (Nod) = Name_Time_Slice
9990 Error_Msg_Name_1 := Chars (N);
9991 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9998 -- Process only if in main unit
10000 if Get_Source_Unit (Loc) = Main_Unit then
10001 Opt.Time_Slice_Set := True;
10002 Val := Expr_Value_R (Expression (Arg1));
10004 if Val <= Ureal_0 then
10005 Opt.Time_Slice_Value := 0;
10007 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
10008 Opt.Time_Slice_Value := 1_000_000_000;
10011 Opt.Time_Slice_Value :=
10012 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
10021 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
10023 -- TITLING_OPTION ::=
10024 -- [Title =>] STRING_LITERAL
10025 -- | [Subtitle =>] STRING_LITERAL
10027 when Pragma_Title => Title : declare
10028 Args : Args_List (1 .. 2);
10029 Names : constant Name_List (1 .. 2) := (
10035 Gather_Associations (Names, Args);
10037 for J in 1 .. 2 loop
10038 if Present (Args (J)) then
10039 Check_Arg_Is_String_Literal (Args (J));
10044 ---------------------
10045 -- Unchecked_Union --
10046 ---------------------
10048 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
10050 when Pragma_Unchecked_Union => Unchecked_Union : declare
10051 Assoc : constant Node_Id := Arg1;
10052 Type_Id : constant Node_Id := Expression (Assoc);
10063 Check_No_Identifiers;
10064 Check_Arg_Count (1);
10065 Check_Arg_Is_Local_Name (Arg1);
10067 Find_Type (Type_Id);
10068 Typ := Entity (Type_Id);
10071 or else Rep_Item_Too_Early (Typ, N)
10075 Typ := Underlying_Type (Typ);
10078 if Rep_Item_Too_Late (Typ, N) then
10082 Check_First_Subtype (Arg1);
10084 -- Note remaining cases are references to a type in the current
10085 -- declarative part. If we find an error, we post the error on
10086 -- the relevant type declaration at an appropriate point.
10088 if not Is_Record_Type (Typ) then
10089 Error_Msg_N ("Unchecked_Union must be record type", Typ);
10092 elsif Is_Tagged_Type (Typ) then
10093 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
10096 elsif Is_Limited_Type (Typ) then
10098 ("Unchecked_Union must not be limited record type", Typ);
10099 Explain_Limited_Type (Typ, Typ);
10103 if not Has_Discriminants (Typ) then
10105 ("Unchecked_Union must have one discriminant", Typ);
10109 Discr := First_Discriminant (Typ);
10111 if Present (Next_Discriminant (Discr)) then
10113 ("Unchecked_Union must have exactly one discriminant",
10114 Next_Discriminant (Discr));
10118 if No (Discriminant_Default_Value (Discr)) then
10120 ("Unchecked_Union discriminant must have default value",
10124 Tdef := Type_Definition (Declaration_Node (Typ));
10125 Clist := Component_List (Tdef);
10127 Comp := First (Component_Items (Clist));
10128 while Present (Comp) loop
10130 Check_Component (Comp);
10135 if No (Clist) or else No (Variant_Part (Clist)) then
10137 ("Unchecked_Union must have variant part",
10142 Vpart := Variant_Part (Clist);
10144 Variant := First (Variants (Vpart));
10145 while Present (Variant) loop
10146 Check_Variant (Variant);
10151 Set_Is_Unchecked_Union (Typ, True);
10152 Set_Convention (Typ, Convention_C);
10154 Set_Has_Unchecked_Union (Base_Type (Typ), True);
10155 Set_Is_Unchecked_Union (Base_Type (Typ), True);
10156 end Unchecked_Union;
10158 ------------------------
10159 -- Unimplemented_Unit --
10160 ------------------------
10162 -- pragma Unimplemented_Unit;
10164 -- Note: this only gives an error if we are generating code,
10165 -- or if we are in a generic library unit (where the pragma
10166 -- appears in the body, not in the spec).
10168 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
10169 Cunitent : constant Entity_Id :=
10170 Cunit_Entity (Get_Source_Unit (Loc));
10171 Ent_Kind : constant Entity_Kind :=
10176 Check_Arg_Count (0);
10178 if Operating_Mode = Generate_Code
10179 or else Ent_Kind = E_Generic_Function
10180 or else Ent_Kind = E_Generic_Procedure
10181 or else Ent_Kind = E_Generic_Package
10183 Get_Name_String (Chars (Cunitent));
10184 Set_Casing (Mixed_Case);
10185 Write_Str (Name_Buffer (1 .. Name_Len));
10186 Write_Str (" is not implemented");
10188 raise Unrecoverable_Error;
10190 end Unimplemented_Unit;
10192 --------------------
10193 -- Universal_Data --
10194 --------------------
10196 -- pragma Universal_Data [(library_unit_NAME)];
10198 when Pragma_Universal_Data =>
10201 -- If this is a configuration pragma, then set the universal
10202 -- addressing option, otherwise confirm that the pragma
10203 -- satisfies the requirements of library unit pragma placement
10204 -- and leave it to the GNAAMP back end to detect the pragma
10205 -- (avoids transitive setting of the option due to withed units).
10207 if Is_Configuration_Pragma then
10208 Universal_Addressing_On_AAMP := True;
10210 Check_Valid_Library_Unit_Pragma;
10213 if not AAMP_On_Target then
10214 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
10221 -- pragma Unreferenced (local_Name {, local_Name});
10223 when Pragma_Unreferenced => Unreferenced : declare
10224 Arg_Node : Node_Id;
10225 Arg_Expr : Node_Id;
10226 Arg_Ent : Entity_Id;
10230 Check_At_Least_N_Arguments (1);
10233 while Present (Arg_Node) loop
10234 Check_No_Identifier (Arg_Node);
10236 -- Note that the analyze call done by Check_Arg_Is_Local_Name
10237 -- will in fact generate a reference, so that the entity will
10238 -- have a reference, which will inhibit any warnings about it
10239 -- not being referenced, and also properly show up in the ali
10240 -- file as a reference. But this reference is recorded before
10241 -- the Has_Pragma_Unreferenced flag is set, so that no warning
10242 -- is generated for this reference.
10244 Check_Arg_Is_Local_Name (Arg_Node);
10245 Arg_Expr := Get_Pragma_Arg (Arg_Node);
10247 if Is_Entity_Name (Arg_Expr) then
10248 Arg_Ent := Entity (Arg_Expr);
10250 -- If the entity is overloaded, the pragma applies to the
10251 -- most recent overloading, as documented. In this case,
10252 -- name resolution does not generate a reference, so it
10253 -- must be done here explicitly.
10255 if Is_Overloaded (Arg_Expr) then
10256 Generate_Reference (Arg_Ent, N);
10259 Set_Has_Pragma_Unreferenced (Arg_Ent);
10266 ------------------------------
10267 -- Unreserve_All_Interrupts --
10268 ------------------------------
10270 -- pragma Unreserve_All_Interrupts;
10272 when Pragma_Unreserve_All_Interrupts =>
10274 Check_Arg_Count (0);
10276 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
10277 Unreserve_All_Interrupts := True;
10284 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
10286 when Pragma_Unsuppress =>
10288 Process_Suppress_Unsuppress (False);
10290 -------------------
10291 -- Use_VADS_Size --
10292 -------------------
10294 -- pragma Use_VADS_Size;
10296 when Pragma_Use_VADS_Size =>
10298 Check_Arg_Count (0);
10299 Check_Valid_Configuration_Pragma;
10300 Use_VADS_Size := True;
10302 ---------------------
10303 -- Validity_Checks --
10304 ---------------------
10306 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10308 when Pragma_Validity_Checks => Validity_Checks : declare
10309 A : constant Node_Id := Expression (Arg1);
10315 Check_Arg_Count (1);
10316 Check_No_Identifiers;
10318 if Nkind (A) = N_String_Literal then
10322 Slen : constant Natural := Natural (String_Length (S));
10323 Options : String (1 .. Slen);
10329 C := Get_String_Char (S, Int (J));
10330 exit when not In_Character_Range (C);
10331 Options (J) := Get_Character (C);
10334 Set_Validity_Check_Options (Options);
10342 elsif Nkind (A) = N_Identifier then
10344 if Chars (A) = Name_All_Checks then
10345 Set_Validity_Check_Options ("a");
10347 elsif Chars (A) = Name_On then
10348 Validity_Checks_On := True;
10350 elsif Chars (A) = Name_Off then
10351 Validity_Checks_On := False;
10355 end Validity_Checks;
10361 -- pragma Volatile (LOCAL_NAME);
10363 when Pragma_Volatile =>
10364 Process_Atomic_Shared_Volatile;
10366 -------------------------
10367 -- Volatile_Components --
10368 -------------------------
10370 -- pragma Volatile_Components (array_LOCAL_NAME);
10372 -- Volatile is handled by the same circuit as Atomic_Components
10378 -- pragma Warnings (On | Off, [LOCAL_NAME])
10379 -- pragma Warnings (static_string_EXPRESSION);
10381 when Pragma_Warnings => Warnings : begin
10383 Check_At_Least_N_Arguments (1);
10384 Check_No_Identifiers;
10386 -- One argument case
10388 if Arg_Count = 1 then
10390 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10393 -- On/Off one argument case was processed by parser
10395 if Nkind (Argx) = N_Identifier
10397 (Chars (Argx) = Name_On
10399 Chars (Argx) = Name_Off)
10404 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10407 Lit : constant Node_Id := Expr_Value_S (Argx);
10408 Str : constant String_Id := Strval (Lit);
10412 for J in 1 .. String_Length (Str) loop
10413 C := Get_String_Char (Str, J);
10415 if In_Character_Range (C)
10416 and then Set_Warning_Switch (Get_Character (C))
10421 ("invalid warning switch character", Arg1);
10428 -- Two argument case
10430 elsif Arg_Count /= 1 then
10431 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10432 Check_Arg_Count (2);
10439 E_Id := Expression (Arg2);
10442 -- In the expansion of an inlined body, a reference to
10443 -- the formal may be wrapped in a conversion if the actual
10444 -- is a conversion. Retrieve the real entity name.
10446 if (In_Instance_Body
10447 or else In_Inlined_Body)
10448 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10450 E_Id := Expression (E_Id);
10453 if not Is_Entity_Name (E_Id) then
10455 ("second argument of pragma% must be entity name",
10459 E := Entity (E_Id);
10466 (E, (Chars (Expression (Arg1)) = Name_Off));
10468 if Is_Enumeration_Type (E) then
10472 Lit := First_Literal (E);
10473 while Present (Lit) loop
10474 Set_Warnings_Off (Lit);
10475 Next_Literal (Lit);
10480 exit when No (Homonym (E));
10486 -- More than two arguments
10488 Check_At_Most_N_Arguments (2);
10492 -------------------
10493 -- Weak_External --
10494 -------------------
10496 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10498 when Pragma_Weak_External => Weak_External : declare
10503 Check_Arg_Count (1);
10504 Check_Optional_Identifier (Arg1, Name_Entity);
10505 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10506 Ent := Entity (Expression (Arg1));
10508 if Rep_Item_Too_Early (Ent, N) then
10511 Ent := Underlying_Type (Ent);
10514 -- The only processing required is to link this item on to the
10515 -- list of rep items for the given entity. This is accomplished
10516 -- by the call to Rep_Item_Too_Late (when no error is detected
10517 -- and False is returned).
10519 if Rep_Item_Too_Late (Ent, N) then
10522 Set_Has_Gigi_Rep_Item (Ent);
10526 --------------------
10527 -- Unknown_Pragma --
10528 --------------------
10530 -- Should be impossible, since the case of an unknown pragma is
10531 -- separately processed before the case statement is entered.
10533 when Unknown_Pragma =>
10534 raise Program_Error;
10538 when Pragma_Exit => null;
10539 end Analyze_Pragma;
10541 ---------------------------------
10542 -- Delay_Config_Pragma_Analyze --
10543 ---------------------------------
10545 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10547 return Chars (N) = Name_Interrupt_State;
10548 end Delay_Config_Pragma_Analyze;
10550 -------------------------
10551 -- Get_Base_Subprogram --
10552 -------------------------
10554 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10555 Result : Entity_Id;
10558 -- Follow subprogram renaming chain
10561 while Is_Subprogram (Result)
10563 (Is_Generic_Instance (Result)
10564 or else Nkind (Parent (Declaration_Node (Result))) =
10565 N_Subprogram_Renaming_Declaration)
10566 and then Present (Alias (Result))
10568 Result := Alias (Result);
10572 end Get_Base_Subprogram;
10574 -----------------------------
10575 -- Is_Config_Static_String --
10576 -----------------------------
10578 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10580 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10581 -- This is an internal recursive function that is just like the
10582 -- outer function except that it adds the string to the name buffer
10583 -- rather than placing the string in the name buffer.
10585 ------------------------------
10586 -- Add_Config_Static_String --
10587 ------------------------------
10589 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10596 if Nkind (N) = N_Op_Concat then
10597 if Add_Config_Static_String (Left_Opnd (N)) then
10598 N := Right_Opnd (N);
10604 if Nkind (N) /= N_String_Literal then
10605 Error_Msg_N ("string literal expected for pragma argument", N);
10609 for J in 1 .. String_Length (Strval (N)) loop
10610 C := Get_String_Char (Strval (N), J);
10612 if not In_Character_Range (C) then
10614 ("string literal contains invalid wide character",
10615 Sloc (N) + 1 + Source_Ptr (J));
10619 Add_Char_To_Name_Buffer (Get_Character (C));
10624 end Add_Config_Static_String;
10626 -- Start of prorcessing for Is_Config_Static_String
10631 return Add_Config_Static_String (Arg);
10632 end Is_Config_Static_String;
10634 -----------------------------------------
10635 -- Is_Non_Significant_Pragma_Reference --
10636 -----------------------------------------
10638 -- This function makes use of the following static table which indicates
10639 -- whether a given pragma is significant. A value of -1 in this table
10640 -- indicates that the reference is significant. A value of zero indicates
10641 -- than appearence as any argument is insignificant, a positive value
10642 -- indicates that appearence in that parameter position is significant.
10644 Sig_Flags : constant array (Pragma_Id) of Int :=
10646 (Pragma_AST_Entry => -1,
10647 Pragma_Abort_Defer => -1,
10648 Pragma_Ada_83 => -1,
10649 Pragma_Ada_95 => -1,
10650 Pragma_Ada_05 => -1,
10651 Pragma_All_Calls_Remote => -1,
10652 Pragma_Annotate => -1,
10653 Pragma_Assert => -1,
10654 Pragma_Assertion_Policy => 0,
10655 Pragma_Asynchronous => -1,
10656 Pragma_Atomic => 0,
10657 Pragma_Atomic_Components => 0,
10658 Pragma_Attach_Handler => -1,
10659 Pragma_CPP_Class => 0,
10660 Pragma_CPP_Constructor => 0,
10661 Pragma_CPP_Virtual => 0,
10662 Pragma_CPP_Vtable => 0,
10663 Pragma_C_Pass_By_Copy => 0,
10664 Pragma_Comment => 0,
10665 Pragma_Common_Object => -1,
10666 Pragma_Compile_Time_Warning => -1,
10667 Pragma_Complex_Representation => 0,
10668 Pragma_Component_Alignment => -1,
10669 Pragma_Controlled => 0,
10670 Pragma_Convention => 0,
10671 Pragma_Convention_Identifier => 0,
10672 Pragma_Debug => -1,
10673 Pragma_Debug_Policy => 0,
10674 Pragma_Detect_Blocking => -1,
10675 Pragma_Discard_Names => 0,
10676 Pragma_Elaborate => -1,
10677 Pragma_Elaborate_All => -1,
10678 Pragma_Elaborate_Body => -1,
10679 Pragma_Elaboration_Checks => -1,
10680 Pragma_Eliminate => -1,
10681 Pragma_Explicit_Overriding => -1,
10682 Pragma_Export => -1,
10683 Pragma_Export_Exception => -1,
10684 Pragma_Export_Function => -1,
10685 Pragma_Export_Object => -1,
10686 Pragma_Export_Procedure => -1,
10687 Pragma_Export_Value => -1,
10688 Pragma_Export_Valued_Procedure => -1,
10689 Pragma_Extend_System => -1,
10690 Pragma_Extensions_Allowed => -1,
10691 Pragma_External => -1,
10692 Pragma_External_Name_Casing => -1,
10693 Pragma_Finalize_Storage_Only => 0,
10694 Pragma_Float_Representation => 0,
10695 Pragma_Ident => -1,
10696 Pragma_Import => +2,
10697 Pragma_Import_Exception => 0,
10698 Pragma_Import_Function => 0,
10699 Pragma_Import_Object => 0,
10700 Pragma_Import_Procedure => 0,
10701 Pragma_Import_Valued_Procedure => 0,
10702 Pragma_Initialize_Scalars => -1,
10703 Pragma_Inline => 0,
10704 Pragma_Inline_Always => 0,
10705 Pragma_Inline_Generic => 0,
10706 Pragma_Inspection_Point => -1,
10707 Pragma_Interface => +2,
10708 Pragma_Interface_Name => +2,
10709 Pragma_Interrupt_Handler => -1,
10710 Pragma_Interrupt_Priority => -1,
10711 Pragma_Interrupt_State => -1,
10712 Pragma_Java_Constructor => -1,
10713 Pragma_Java_Interface => -1,
10714 Pragma_Keep_Names => 0,
10715 Pragma_License => -1,
10716 Pragma_Link_With => -1,
10717 Pragma_Linker_Alias => -1,
10718 Pragma_Linker_Constructor => -1,
10719 Pragma_Linker_Destructor => -1,
10720 Pragma_Linker_Options => -1,
10721 Pragma_Linker_Section => -1,
10723 Pragma_Locking_Policy => -1,
10724 Pragma_Long_Float => -1,
10725 Pragma_Machine_Attribute => -1,
10727 Pragma_Main_Storage => -1,
10728 Pragma_Memory_Size => -1,
10729 Pragma_No_Return => 0,
10730 Pragma_No_Run_Time => -1,
10731 Pragma_No_Strict_Aliasing => -1,
10732 Pragma_Normalize_Scalars => -1,
10733 Pragma_Obsolescent => 0,
10734 Pragma_Optimize => -1,
10735 Pragma_Optional_Overriding => -1,
10738 Pragma_Passive => -1,
10739 Pragma_Polling => -1,
10740 Pragma_Persistent_BSS => 0,
10741 Pragma_Preelaborate => -1,
10742 Pragma_Preelaborate_05 => -1,
10743 Pragma_Priority => -1,
10744 Pragma_Profile => 0,
10745 Pragma_Profile_Warnings => 0,
10746 Pragma_Propagate_Exceptions => -1,
10747 Pragma_Psect_Object => -1,
10749 Pragma_Pure_05 => -1,
10750 Pragma_Pure_Function => -1,
10751 Pragma_Queuing_Policy => -1,
10752 Pragma_Ravenscar => -1,
10753 Pragma_Remote_Call_Interface => -1,
10754 Pragma_Remote_Types => -1,
10755 Pragma_Restricted_Run_Time => -1,
10756 Pragma_Restriction_Warnings => -1,
10757 Pragma_Restrictions => -1,
10758 Pragma_Reviewable => -1,
10759 Pragma_Share_Generic => -1,
10760 Pragma_Shared => -1,
10761 Pragma_Shared_Passive => -1,
10762 Pragma_Source_File_Name => -1,
10763 Pragma_Source_File_Name_Project => -1,
10764 Pragma_Source_Reference => -1,
10765 Pragma_Storage_Size => -1,
10766 Pragma_Storage_Unit => -1,
10767 Pragma_Stream_Convert => -1,
10768 Pragma_Style_Checks => -1,
10769 Pragma_Subtitle => -1,
10770 Pragma_Suppress => 0,
10771 Pragma_Suppress_Exception_Locations => 0,
10772 Pragma_Suppress_All => -1,
10773 Pragma_Suppress_Debug_Info => 0,
10774 Pragma_Suppress_Initialization => 0,
10775 Pragma_System_Name => -1,
10776 Pragma_Task_Dispatching_Policy => -1,
10777 Pragma_Task_Info => -1,
10778 Pragma_Task_Name => -1,
10779 Pragma_Task_Storage => 0,
10780 Pragma_Thread_Body => +2,
10781 Pragma_Time_Slice => -1,
10782 Pragma_Title => -1,
10783 Pragma_Unchecked_Union => 0,
10784 Pragma_Unimplemented_Unit => -1,
10785 Pragma_Universal_Data => -1,
10786 Pragma_Unreferenced => -1,
10787 Pragma_Unreserve_All_Interrupts => -1,
10788 Pragma_Unsuppress => 0,
10789 Pragma_Use_VADS_Size => -1,
10790 Pragma_Validity_Checks => -1,
10791 Pragma_Volatile => 0,
10792 Pragma_Volatile_Components => 0,
10793 Pragma_Warnings => -1,
10794 Pragma_Weak_External => 0,
10795 Unknown_Pragma => 0);
10797 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10805 if Nkind (P) /= N_Pragma_Argument_Association then
10809 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10819 A := First (Pragma_Argument_Associations (Parent (P)));
10820 for J in 1 .. C - 1 loop
10831 end Is_Non_Significant_Pragma_Reference;
10833 ------------------------------
10834 -- Is_Pragma_String_Literal --
10835 ------------------------------
10837 -- This function returns true if the corresponding pragma argument is
10838 -- a static string expression. These are the only cases in which string
10839 -- literals can appear as pragma arguments. We also allow a string
10840 -- literal as the first argument to pragma Assert (although it will
10841 -- of course always generate a type error).
10843 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10844 Pragn : constant Node_Id := Parent (Par);
10845 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10846 Pname : constant Name_Id := Chars (Pragn);
10852 N := First (Assoc);
10859 if Pname = Name_Assert then
10862 elsif Pname = Name_Export then
10865 elsif Pname = Name_Ident then
10868 elsif Pname = Name_Import then
10871 elsif Pname = Name_Interface_Name then
10874 elsif Pname = Name_Linker_Alias then
10877 elsif Pname = Name_Linker_Section then
10880 elsif Pname = Name_Machine_Attribute then
10883 elsif Pname = Name_Source_File_Name then
10886 elsif Pname = Name_Source_Reference then
10889 elsif Pname = Name_Title then
10892 elsif Pname = Name_Subtitle then
10898 end Is_Pragma_String_Literal;
10900 --------------------------------------
10901 -- Process_Compilation_Unit_Pragmas --
10902 --------------------------------------
10904 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10906 -- A special check for pragma Suppress_All. This is a strange DEC
10907 -- pragma, strange because it comes at the end of the unit. If we
10908 -- have a pragma Suppress_All in the Pragmas_After of the current
10909 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10910 -- of the context clause to ensure the correct processing.
10913 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10917 if Present (PA) then
10919 while Present (P) loop
10920 if Chars (P) = Name_Suppress_All then
10921 Prepend_To (Context_Items (N),
10922 Make_Pragma (Sloc (P),
10923 Chars => Name_Suppress,
10924 Pragma_Argument_Associations => New_List (
10925 Make_Pragma_Argument_Association (Sloc (P),
10927 Make_Identifier (Sloc (P),
10928 Chars => Name_All_Checks)))));
10936 end Process_Compilation_Unit_Pragmas;
10938 --------------------------------
10939 -- Set_Encoded_Interface_Name --
10940 --------------------------------
10942 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10943 Str : constant String_Id := Strval (S);
10944 Len : constant Int := String_Length (Str);
10949 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10952 -- Stores encoded value of character code CC. The encoding we
10953 -- use an underscore followed by four lower case hex digits.
10959 procedure Encode is
10961 Store_String_Char (Get_Char_Code ('_'));
10963 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10965 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10967 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10969 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10972 -- Start of processing for Set_Encoded_Interface_Name
10975 -- If first character is asterisk, this is a link name, and we
10976 -- leave it completely unmodified. We also ignore null strings
10977 -- (the latter case happens only in error cases) and no encoding
10978 -- should occur for Java interface names.
10981 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10984 Set_Interface_Name (E, S);
10989 CC := Get_String_Char (Str, J);
10991 exit when not In_Character_Range (CC);
10993 C := Get_Character (CC);
10995 exit when C /= '_' and then C /= '$'
10996 and then C not in '0' .. '9'
10997 and then C not in 'a' .. 'z'
10998 and then C not in 'A' .. 'Z';
11001 Set_Interface_Name (E, S);
11009 -- Here we need to encode. The encoding we use as follows:
11010 -- three underscores + four hex digits (lower case)
11014 for J in 1 .. String_Length (Str) loop
11015 CC := Get_String_Char (Str, J);
11017 if not In_Character_Range (CC) then
11020 C := Get_Character (CC);
11022 if C = '_' or else C = '$'
11023 or else C in '0' .. '9'
11024 or else C in 'a' .. 'z'
11025 or else C in 'A' .. 'Z'
11027 Store_String_Char (CC);
11034 Set_Interface_Name (E,
11035 Make_String_Literal (Sloc (S),
11036 Strval => End_String));
11038 end Set_Encoded_Interface_Name;
11040 -------------------
11041 -- Set_Unit_Name --
11042 -------------------
11044 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
11049 if Nkind (N) = N_Identifier
11050 and then Nkind (With_Item) = N_Identifier
11052 Set_Entity (N, Entity (With_Item));
11054 elsif Nkind (N) = N_Selected_Component then
11055 Change_Selected_Component_To_Expanded_Name (N);
11056 Set_Entity (N, Entity (With_Item));
11057 Set_Entity (Selector_Name (N), Entity (N));
11059 Pref := Prefix (N);
11060 Scop := Scope (Entity (N));
11061 while Nkind (Pref) = N_Selected_Component loop
11062 Change_Selected_Component_To_Expanded_Name (Pref);
11063 Set_Entity (Selector_Name (Pref), Scop);
11064 Set_Entity (Pref, Scop);
11065 Pref := Prefix (Pref);
11066 Scop := Scope (Scop);
11069 Set_Entity (Pref, Scop);