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 Stand; use Stand;
68 with Sinfo; use Sinfo;
69 with Sinfo.CN; use Sinfo.CN;
70 with Sinput; use Sinput;
71 with Snames; use Snames;
72 with Stringt; use Stringt;
73 with Stylesw; use Stylesw;
75 with Targparm; use Targparm;
76 with Tbuild; use Tbuild;
78 with Uintp; use Uintp;
79 with Urealp; use Urealp;
80 with Validsw; use Validsw;
82 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
84 package body Sem_Prag is
86 ----------------------------------------------
87 -- Common Handling of Import-Export Pragmas --
88 ----------------------------------------------
90 -- In the following section, a number of Import_xxx and Export_xxx
91 -- pragmas are defined by GNAT. These are compatible with the DEC
92 -- pragmas of the same name, and all have the following common
93 -- form and processing:
96 -- [Internal =>] LOCAL_NAME,
97 -- [, [External =>] EXTERNAL_SYMBOL]
98 -- [, other optional parameters ]);
101 -- [Internal =>] LOCAL_NAME,
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
105 -- EXTERNAL_SYMBOL ::=
107 -- | static_string_EXPRESSION
109 -- The internal LOCAL_NAME designates the entity that is imported or
110 -- exported, and must refer to an entity in the current declarative
111 -- part (as required by the rules for LOCAL_NAME).
113 -- The external linker name is designated by the External parameter
114 -- if given, or the Internal parameter if not (if there is no External
115 -- parameter, the External parameter is a copy of the Internal name).
117 -- If the External parameter is given as a string, then this string
118 -- is treated as an external name (exactly as though it had been given
119 -- as an External_Name parameter for a normal Import pragma).
121 -- If the External parameter is given as an identifier (or there is no
122 -- External parameter, so that the Internal identifier is used), then
123 -- the external name is the characters of the identifier, translated
124 -- to all upper case letters for OpenVMS versions of GNAT, and to all
125 -- lower case letters for all other versions
127 -- Note: the external name specified or implied by any of these special
128 -- Import_xxx or Export_xxx pragmas override an external or link name
129 -- specified in a previous Import or Export pragma.
131 -- Note: these and all other DEC-compatible GNAT pragmas allow full
132 -- use of named notation, following the standard rules for subprogram
133 -- calls, i.e. parameters can be given in any order if named notation
134 -- is used, and positional and named notation can be mixed, subject to
135 -- the rule that all positional parameters must appear first.
137 -- Note: All these pragmas are implemented exactly following the DEC
138 -- design and implementation and are intended to be fully compatible
139 -- with the use of these pragmas in the DEC Ada compiler.
141 --------------------------------------------
142 -- Checking for Duplicated External Names --
143 --------------------------------------------
145 -- It is suspicious if two separate Export pragmas use the same external
146 -- name. The following table is used to diagnose this situation so that
147 -- an appropriate warning can be issued.
149 -- The Node_Id stored is for the N_String_Literal node created to
150 -- hold the value of the external name. The Sloc of this node is
151 -- used to cross-reference the location of the duplication.
153 package Externals is new Table.Table (
154 Table_Component_Type => Node_Id,
155 Table_Index_Type => Int,
156 Table_Low_Bound => 0,
157 Table_Initial => 100,
158 Table_Increment => 100,
159 Table_Name => "Name_Externals");
161 -------------------------------------
162 -- Local Subprograms and Variables --
163 -------------------------------------
165 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
166 -- This routine is used for possible casing adjustment of an explicit
167 -- external name supplied as a string literal (the node N), according
168 -- to the casing requirement of Opt.External_Name_Casing. If this is
169 -- set to As_Is, then the string literal is returned unchanged, but if
170 -- it is set to Uppercase or Lowercase, then a new string literal with
171 -- appropriate casing is constructed.
173 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
174 -- If Def_Id refers to a renamed subprogram, then the base subprogram
175 -- (the original one, following the renaming chain) is returned.
176 -- Otherwise the entity is returned unchanged. Should be in Einfo???
178 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
179 -- Place semantic information on the argument of an Elaborate or
180 -- Elaborate_All pragma. Entity name for unit and its parents is
181 -- taken from item in previous with_clause that mentions the unit.
183 -------------------------------
184 -- Adjust_External_Name_Case --
185 -------------------------------
187 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
191 -- Adjust case of literal if required
193 if Opt.External_Name_Exp_Casing = As_Is then
197 -- Copy existing string
203 for J in 1 .. String_Length (Strval (N)) loop
204 CC := Get_String_Char (Strval (N), J);
206 if Opt.External_Name_Exp_Casing = Uppercase
207 and then CC >= Get_Char_Code ('a')
208 and then CC <= Get_Char_Code ('z')
210 Store_String_Char (CC - 32);
212 elsif Opt.External_Name_Exp_Casing = Lowercase
213 and then CC >= Get_Char_Code ('A')
214 and then CC <= Get_Char_Code ('Z')
216 Store_String_Char (CC + 32);
219 Store_String_Char (CC);
224 Make_String_Literal (Sloc (N),
225 Strval => End_String);
227 end Adjust_External_Name_Case;
233 procedure Analyze_Pragma (N : Node_Id) is
234 Loc : constant Source_Ptr := Sloc (N);
237 Pragma_Exit : exception;
238 -- This exception is used to exit pragma processing completely. It
239 -- is used when an error is detected, and in other situations where
240 -- it is known that no further processing is required.
243 -- Number of pragma argument associations
249 -- First four pragma arguments (pragma argument association nodes,
250 -- or Empty if the corresponding argument does not exist).
252 type Name_List is array (Natural range <>) of Name_Id;
253 type Args_List is array (Natural range <>) of Node_Id;
254 -- Types used for arguments to Check_Arg_Order and Gather_Associations
256 procedure Check_Ada_83_Warning;
257 -- Issues a warning message for the current pragma if operating in Ada
258 -- 83 mode (used for language pragmas that are not a standard part of
259 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
262 procedure Check_Arg_Count (Required : Nat);
263 -- Check argument count for pragma is equal to given parameter.
264 -- If not, then issue an error message and raise Pragma_Exit.
266 -- Note: all routines whose name is Check_Arg_Is_xxx take an
267 -- argument Arg which can either be a pragma argument association,
268 -- in which case the check is applied to the expression of the
269 -- association or an expression directly.
271 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
272 -- Check that an argument has the right form for an EXTERNAL_NAME
273 -- parameter of an extended import/export pragma. The rule is that
274 -- the name must be an identifier or string literal (in Ada 83 mode)
275 -- or a static string expression (in Ada 95 mode).
277 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
278 -- Check the specified argument Arg to make sure that it is an
279 -- identifier. If not give error and raise Pragma_Exit.
281 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
282 -- Check the specified argument Arg to make sure that it is an
283 -- integer literal. If not give error and raise Pragma_Exit.
285 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
286 -- Check the specified argument Arg to make sure that it has the
287 -- proper syntactic form for a local name and meets the semantic
288 -- requirements for a local name. The local name is analyzed as
289 -- part of the processing for this call. In addition, the local
290 -- name is required to represent an entity at the library level.
292 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
293 -- Check the specified argument Arg to make sure that it has the
294 -- proper syntactic form for a local name and meets the semantic
295 -- requirements for a local name. The local name is analyzed as
296 -- part of the processing for this call.
298 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
299 -- Check the specified argument Arg to make sure that it is a valid
300 -- locking policy name. If not give error and raise Pragma_Exit.
302 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
303 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
304 -- Check the specified argument Arg to make sure that it is an
305 -- identifier whose name matches either N1 or N2 (or N3 if present).
306 -- If not then give error and raise Pragma_Exit.
308 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
309 -- Check the specified argument Arg to make sure that it is a valid
310 -- queuing policy name. If not give error and raise Pragma_Exit.
312 procedure Check_Arg_Is_Static_Expression
315 -- Check the specified argument Arg to make sure that it is a static
316 -- expression of the given type (i.e. it will be analyzed and resolved
317 -- using this type, which can be any valid argument to Resolve, e.g.
318 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
320 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
321 -- Check the specified argument Arg to make sure that it is a
322 -- string literal. If not give error and raise Pragma_Exit
324 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
325 -- Check the specified argument Arg to make sure that it is a valid
326 -- valid task dispatching policy name. If not give error and raise
329 procedure Check_Arg_Order (Names : Name_List);
330 -- Checks for an instance of two arguments with identifiers for the
331 -- current pragma which are not in the sequence indicated by Names,
332 -- and if so, generates a fatal message about bad order of arguments.
334 procedure Check_At_Least_N_Arguments (N : Nat);
335 -- Check there are at least N arguments present
337 procedure Check_At_Most_N_Arguments (N : Nat);
338 -- Check there are no more than N arguments present
340 procedure Check_Component (Comp : Node_Id);
341 -- Examine Unchecked_Union component for correct use of per-object
342 -- constrained subtypes.
344 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
345 -- Nam is an N_String_Literal node containing the external name set
346 -- by an Import or Export pragma (or extended Import or Export pragma).
347 -- This procedure checks for possible duplications if this is the
348 -- export case, and if found, issues an appropriate error message.
350 procedure Check_First_Subtype (Arg : Node_Id);
351 -- Checks that Arg, whose expression is an entity name referencing
352 -- a subtype, does not reference a type that is not a first subtype.
354 procedure Check_In_Main_Program;
355 -- Common checks for pragmas that appear within a main program
356 -- (Priority, Main_Storage, Time_Slice).
358 procedure Check_Interrupt_Or_Attach_Handler;
359 -- Common processing for first argument of pragma Interrupt_Handler
360 -- or pragma Attach_Handler.
362 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
363 -- Check that pragma appears in a declarative part, or in a package
364 -- specification, i.e. that it does not occur in a statement sequence
367 procedure Check_No_Identifier (Arg : Node_Id);
368 -- Checks that the given argument does not have an identifier. If
369 -- an identifier is present, then an error message is issued, and
370 -- Pragma_Exit is raised.
372 procedure Check_No_Identifiers;
373 -- Checks that none of the arguments to the pragma has an identifier.
374 -- If any argument has an identifier, then an error message is issued,
375 -- and Pragma_Exit is raised.
377 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
378 -- Checks if the given argument has an identifier, and if so, requires
379 -- it to match the given identifier name. If there is a non-matching
380 -- identifier, then an error message is given and Error_Pragmas raised.
382 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
383 -- Checks if the given argument has an identifier, and if so, requires
384 -- it to match the given identifier name. If there is a non-matching
385 -- identifier, then an error message is given and Error_Pragmas raised.
386 -- In this version of the procedure, the identifier name is given as
387 -- a string with lower case letters.
389 procedure Check_Static_Constraint (Constr : Node_Id);
390 -- Constr is a constraint from an N_Subtype_Indication node from a
391 -- component constraint in an Unchecked_Union type. This routine checks
392 -- that the constraint is static as required by the restrictions for
395 procedure Check_Valid_Configuration_Pragma;
396 -- Legality checks for placement of a configuration pragma
398 procedure Check_Valid_Library_Unit_Pragma;
399 -- Legality checks for library unit pragmas. A special case arises for
400 -- pragmas in generic instances that come from copies of the original
401 -- library unit pragmas in the generic templates. In the case of other
402 -- than library level instantiations these can appear in contexts which
403 -- would normally be invalid (they only apply to the original template
404 -- and to library level instantiations), and they are simply ignored,
405 -- which is implemented by rewriting them as null statements.
407 procedure Check_Variant (Variant : Node_Id);
408 -- Check Unchecked_Union variant for lack of nested variants and
409 -- presence of at least one component.
411 procedure Error_Pragma (Msg : String);
412 pragma No_Return (Error_Pragma);
413 -- Outputs error message for current pragma. The message contains an %
414 -- that will be replaced with the pragma name, and the flag is placed
415 -- on the pragma itself. Pragma_Exit is then raised.
417 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
418 pragma No_Return (Error_Pragma_Arg);
419 -- Outputs error message for current pragma. The message may contain
420 -- a % that will be replaced with the pragma name. The parameter Arg
421 -- may either be a pragma argument association, in which case the flag
422 -- is placed on the expression of this association, or an expression,
423 -- in which case the flag is placed directly on the expression. The
424 -- message is placed using Error_Msg_N, so the message may also contain
425 -- an & insertion character which will reference the given Arg value.
426 -- After placing the message, Pragma_Exit is raised.
428 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
429 pragma No_Return (Error_Pragma_Arg);
430 -- Similar to above form of Error_Pragma_Arg except that two messages
431 -- are provided, the second is a continuation comment starting with \.
433 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
434 pragma No_Return (Error_Pragma_Arg_Ident);
435 -- Outputs error message for current pragma. The message may contain
436 -- a % that will be replaced with the pragma name. The parameter Arg
437 -- must be a pragma argument association with a non-empty identifier
438 -- (i.e. its Chars field must be set), and the error message is placed
439 -- on the identifier. The message is placed using Error_Msg_N so
440 -- the message may also contain an & insertion character which will
441 -- reference the identifier. After placing the message, Pragma_Exit
444 function Find_Lib_Unit_Name return Entity_Id;
445 -- Used for a library unit pragma to find the entity to which the
446 -- library unit pragma applies, returns the entity found.
448 procedure Find_Program_Unit_Name (Id : Node_Id);
449 -- If the pragma is a compilation unit pragma, the id must denote the
450 -- compilation unit in the same compilation, and the pragma must appear
451 -- in the list of preceding or trailing pragmas. If it is a program
452 -- unit pragma that is not a compilation unit pragma, then the
453 -- identifier must be visible.
455 procedure Gather_Associations
457 Args : out Args_List);
458 -- This procedure is used to gather the arguments for a pragma that
459 -- permits arbitrary ordering of parameters using the normal rules
460 -- for named and positional parameters. The Names argument is a list
461 -- of Name_Id values that corresponds to the allowed pragma argument
462 -- association identifiers in order. The result returned in Args is
463 -- a list of corresponding expressions that are the pragma arguments.
464 -- Note that this is a list of expressions, not of pragma argument
465 -- associations (Gather_Associations has completely checked all the
466 -- optional identifiers when it returns). An entry in Args is Empty
467 -- on return if the corresponding argument is not present.
469 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
470 -- All the routines that check pragma arguments take either a pragma
471 -- argument association (in which case the expression of the argument
472 -- association is checked), or the expression directly. The function
473 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
474 -- Arg is a pragma argument association node, then its expression is
475 -- returned, otherwise Arg is returned unchanged.
477 procedure GNAT_Pragma;
478 -- Called for all GNAT defined pragmas to note the use of the feature,
479 -- and also check the relevant restriction (No_Implementation_Pragmas).
481 function Is_Before_First_Decl
482 (Pragma_Node : Node_Id;
483 Decls : List_Id) return Boolean;
484 -- Return True if Pragma_Node is before the first declarative item in
485 -- Decls where Decls is the list of declarative items.
487 function Is_Configuration_Pragma return Boolean;
488 -- Deterermines if the placement of the current pragma is appropriate
489 -- for a configuration pragma (precedes the current compilation unit)
491 procedure Pragma_Misplaced;
492 -- Issue fatal error message for misplaced pragma
494 procedure Process_Atomic_Shared_Volatile;
495 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
496 -- Shared is an obsolete Ada 83 pragma, treated as being identical
497 -- in effect to pragma Atomic.
499 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
500 -- Common procesing for Convention, Interface, Import and Export.
501 -- Checks first two arguments of pragma, and sets the appropriate
502 -- convention value in the specified entity or entities. On return
503 -- C is the convention, E is the referenced entity.
505 procedure Process_Extended_Import_Export_Exception_Pragma
506 (Arg_Internal : Node_Id;
507 Arg_External : Node_Id;
510 -- Common processing for the pragmas Import/Export_Exception.
511 -- The three arguments correspond to the three named parameters of
512 -- the pragma. An argument is empty if the corresponding parameter
513 -- is not present in the pragma.
515 procedure Process_Extended_Import_Export_Object_Pragma
516 (Arg_Internal : Node_Id;
517 Arg_External : Node_Id;
519 -- Common processing for the pragmass Import/Export_Object.
520 -- The three arguments correspond to the three named parameters
521 -- of the pragmas. An argument is empty if the corresponding
522 -- parameter is not present in the pragma.
524 procedure Process_Extended_Import_Export_Internal_Arg
525 (Arg_Internal : Node_Id := Empty);
526 -- Common processing for all extended Import and Export pragmas. The
527 -- argument is the pragma parameter for the Internal argument. If
528 -- Arg_Internal is empty or inappropriate, an error message is posted.
529 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
530 -- set to identify the referenced entity.
532 procedure Process_Extended_Import_Export_Subprogram_Pragma
533 (Arg_Internal : Node_Id;
534 Arg_External : Node_Id;
535 Arg_Parameter_Types : Node_Id;
536 Arg_Result_Type : Node_Id := Empty;
537 Arg_Mechanism : Node_Id;
538 Arg_Result_Mechanism : Node_Id := Empty;
539 Arg_First_Optional_Parameter : Node_Id := Empty);
540 -- Common processing for all extended Import and Export pragmas
541 -- applying to subprograms. The caller omits any arguments that do
542 -- bnot apply to the pragma in question (for example, Arg_Result_Type
543 -- can be non-Empty only in the Import_Function and Export_Function
544 -- cases). The argument names correspond to the allowed pragma
545 -- association identifiers.
547 procedure Process_Generic_List;
548 -- Common processing for Share_Generic and Inline_Generic
550 procedure Process_Import_Or_Interface;
551 -- Common processing for Import of Interface
553 procedure Process_Inline (Active : Boolean);
554 -- Common processing for Inline and Inline_Always. The parameter
555 -- indicates if the inline pragma is active, i.e. if it should
556 -- actually cause inlining to occur.
558 procedure Process_Interface_Name
559 (Subprogram_Def : Entity_Id;
562 -- Given the last two arguments of pragma Import, pragma Export, or
563 -- pragma Interface_Name, performs validity checks and sets the
564 -- Interface_Name field of the given subprogram entity to the
565 -- appropriate external or link name, depending on the arguments
566 -- given. Ext_Arg is always present, but Link_Arg may be missing.
567 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
568 -- missing, and appropriate named notation is used for Ext_Arg.
569 -- If neither Ext_Arg nor Link_Arg is present, the interface name
570 -- is set to the default from the subprogram name.
572 procedure Process_Interrupt_Or_Attach_Handler;
573 -- Common processing for Interrupt and Attach_Handler pragmas
575 procedure Process_Restrictions_Or_Restriction_Warnings;
576 -- Common processing for Restrictions and Restriction_Warnings pragmas
578 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
579 -- Common processing for Suppress and Unsuppress. The boolean parameter
580 -- Suppress_Case is True for the Suppress case, and False for the
583 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
584 -- This procedure sets the Is_Exported flag for the given entity,
585 -- checking that the entity was not previously imported. Arg is
586 -- the argument that specified the entity. A check is also made
587 -- for exporting inappropriate entities.
589 procedure Set_Extended_Import_Export_External_Name
590 (Internal_Ent : Entity_Id;
591 Arg_External : Node_Id);
592 -- Common processing for all extended import export pragmas. The first
593 -- argument, Internal_Ent, is the internal entity, which has already
594 -- been checked for validity by the caller. Arg_External is from the
595 -- Import or Export pragma, and may be null if no External parameter
596 -- was present. If Arg_External is present and is a non-null string
597 -- (a null string is treated as the default), then the Interface_Name
598 -- field of Internal_Ent is set appropriately.
600 procedure Set_Imported (E : Entity_Id);
601 -- This procedure sets the Is_Imported flag for the given entity,
602 -- checking that it is not previously exported or imported.
604 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
605 -- Mech is a parameter passing mechanism (see Import_Function syntax
606 -- for MECHANISM_NAME). This routine checks that the mechanism argument
607 -- has the right form, and if not issues an error message. If the
608 -- argument has the right form then the Mechanism field of Ent is
609 -- set appropriately.
611 procedure Set_Ravenscar_Profile (N : Node_Id);
612 -- Activate the set of configuration pragmas and restrictions that
613 -- make up the Ravenscar Profile. N is the corresponding pragma
614 -- node, which is used for error messages on any constructs
615 -- that violate the profile.
617 --------------------------
618 -- Check_Ada_83_Warning --
619 --------------------------
621 procedure Check_Ada_83_Warning is
623 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
624 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
626 end Check_Ada_83_Warning;
628 ---------------------
629 -- Check_Arg_Count --
630 ---------------------
632 procedure Check_Arg_Count (Required : Nat) is
634 if Arg_Count /= Required then
635 Error_Pragma ("wrong number of arguments for pragma%");
639 --------------------------------
640 -- Check_Arg_Is_External_Name --
641 --------------------------------
643 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
644 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
647 if Nkind (Argx) = N_Identifier then
651 Analyze_And_Resolve (Argx, Standard_String);
653 if Is_OK_Static_Expression (Argx) then
656 elsif Etype (Argx) = Any_Type then
659 -- An interesting special case, if we have a string literal and
660 -- we are in Ada 83 mode, then we allow it even though it will
661 -- not be flagged as static. This allows expected Ada 83 mode
662 -- use of external names which are string literals, even though
663 -- technically these are not static in Ada 83.
665 elsif Ada_Version = Ada_83
666 and then Nkind (Argx) = N_String_Literal
670 -- Static expression that raises Constraint_Error. This has
671 -- already been flagged, so just exit from pragma processing.
673 elsif Is_Static_Expression (Argx) then
676 -- Here we have a real error (non-static expression)
679 Error_Msg_Name_1 := Chars (N);
681 ("argument for pragma% must be a identifier or " &
682 "static string expression!", Argx);
686 end Check_Arg_Is_External_Name;
688 -----------------------------
689 -- Check_Arg_Is_Identifier --
690 -----------------------------
692 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
693 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
695 if Nkind (Argx) /= N_Identifier then
697 ("argument for pragma% must be identifier", Argx);
699 end Check_Arg_Is_Identifier;
701 ----------------------------------
702 -- Check_Arg_Is_Integer_Literal --
703 ----------------------------------
705 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
706 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
708 if Nkind (Argx) /= N_Integer_Literal then
710 ("argument for pragma% must be integer literal", Argx);
712 end Check_Arg_Is_Integer_Literal;
714 -------------------------------------------
715 -- Check_Arg_Is_Library_Level_Local_Name --
716 -------------------------------------------
720 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
721 -- | library_unit_NAME
723 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
725 Check_Arg_Is_Local_Name (Arg);
727 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
728 and then Comes_From_Source (N)
731 ("argument for pragma% must be library level entity", Arg);
733 end Check_Arg_Is_Library_Level_Local_Name;
735 -----------------------------
736 -- Check_Arg_Is_Local_Name --
737 -----------------------------
741 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
742 -- | library_unit_NAME
744 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
745 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
750 if Nkind (Argx) not in N_Direct_Name
751 and then (Nkind (Argx) /= N_Attribute_Reference
752 or else Present (Expressions (Argx))
753 or else Nkind (Prefix (Argx)) /= N_Identifier)
754 and then (not Is_Entity_Name (Argx)
755 or else not Is_Compilation_Unit (Entity (Argx)))
757 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
760 if Is_Entity_Name (Argx)
761 and then Scope (Entity (Argx)) /= Current_Scope
764 ("pragma% argument must be in same declarative part", Arg);
766 end Check_Arg_Is_Local_Name;
768 ---------------------------------
769 -- Check_Arg_Is_Locking_Policy --
770 ---------------------------------
772 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
773 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
776 Check_Arg_Is_Identifier (Argx);
778 if not Is_Locking_Policy_Name (Chars (Argx)) then
780 ("& is not a valid locking policy name", Argx);
782 end Check_Arg_Is_Locking_Policy;
784 -------------------------
785 -- Check_Arg_Is_One_Of --
786 -------------------------
788 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
789 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
792 Check_Arg_Is_Identifier (Argx);
794 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
795 Error_Msg_Name_2 := N1;
796 Error_Msg_Name_3 := N2;
797 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
799 end Check_Arg_Is_One_Of;
801 procedure Check_Arg_Is_One_Of
803 N1, N2, N3 : Name_Id)
805 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
808 Check_Arg_Is_Identifier (Argx);
810 if Chars (Argx) /= N1
811 and then Chars (Argx) /= N2
812 and then Chars (Argx) /= N3
814 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
816 end Check_Arg_Is_One_Of;
818 ---------------------------------
819 -- Check_Arg_Is_Queuing_Policy --
820 ---------------------------------
822 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
823 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
826 Check_Arg_Is_Identifier (Argx);
828 if not Is_Queuing_Policy_Name (Chars (Argx)) then
830 ("& is not a valid queuing policy name", Argx);
832 end Check_Arg_Is_Queuing_Policy;
834 ------------------------------------
835 -- Check_Arg_Is_Static_Expression --
836 ------------------------------------
838 procedure Check_Arg_Is_Static_Expression
842 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
845 Analyze_And_Resolve (Argx, Typ);
847 if Is_OK_Static_Expression (Argx) then
850 elsif Etype (Argx) = Any_Type then
853 -- An interesting special case, if we have a string literal and
854 -- we are in Ada 83 mode, then we allow it even though it will
855 -- not be flagged as static. This allows the use of Ada 95
856 -- pragmas like Import in Ada 83 mode. They will of course be
857 -- flagged with warnings as usual, but will not cause errors.
859 elsif Ada_Version = Ada_83
860 and then Nkind (Argx) = N_String_Literal
864 -- Static expression that raises Constraint_Error. This has
865 -- already been flagged, so just exit from pragma processing.
867 elsif Is_Static_Expression (Argx) then
870 -- Finally, we have a real error
873 Error_Msg_Name_1 := Chars (N);
875 ("argument for pragma% must be a static expression!", Argx);
878 end Check_Arg_Is_Static_Expression;
880 ---------------------------------
881 -- Check_Arg_Is_String_Literal --
882 ---------------------------------
884 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
885 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
887 if Nkind (Argx) /= N_String_Literal then
889 ("argument for pragma% must be string literal", Argx);
891 end Check_Arg_Is_String_Literal;
893 ------------------------------------------
894 -- Check_Arg_Is_Task_Dispatching_Policy --
895 ------------------------------------------
897 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
898 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
901 Check_Arg_Is_Identifier (Argx);
903 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
905 ("& is not a valid task dispatching policy name", Argx);
907 end Check_Arg_Is_Task_Dispatching_Policy;
909 ---------------------
910 -- Check_Arg_Order --
911 ---------------------
913 procedure Check_Arg_Order (Names : Name_List) is
916 Highest_So_Far : Natural := 0;
917 -- Highest index in Names seen do far
921 for J in 1 .. Arg_Count loop
922 if Chars (Arg) /= No_Name then
923 for K in Names'Range loop
924 if Chars (Arg) = Names (K) then
925 if K < Highest_So_Far then
926 Error_Msg_Name_1 := Chars (N);
928 ("parameters out of order for pragma%", Arg);
929 Error_Msg_Name_1 := Names (K);
930 Error_Msg_Name_2 := Names (Highest_So_Far);
931 Error_Msg_N ("\% must appear before %", Arg);
945 --------------------------------
946 -- Check_At_Least_N_Arguments --
947 --------------------------------
949 procedure Check_At_Least_N_Arguments (N : Nat) is
951 if Arg_Count < N then
952 Error_Pragma ("too few arguments for pragma%");
954 end Check_At_Least_N_Arguments;
956 -------------------------------
957 -- Check_At_Most_N_Arguments --
958 -------------------------------
960 procedure Check_At_Most_N_Arguments (N : Nat) is
963 if Arg_Count > N then
967 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
970 end Check_At_Most_N_Arguments;
972 ---------------------
973 -- Check_Component --
974 ---------------------
976 procedure Check_Component (Comp : Node_Id) is
978 if Nkind (Comp) = N_Component_Declaration then
980 Sindic : constant Node_Id :=
981 Subtype_Indication (Component_Definition (Comp));
984 if Nkind (Sindic) = N_Subtype_Indication then
986 -- Ada 2005 (AI-216): If a component subtype is subject to
987 -- a per-object constraint, then the component type shall
988 -- be an Unchecked_Union.
990 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
992 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
994 Error_Msg_N ("component subtype subject to per-object" &
995 " constraint must be an Unchecked_Union", Comp);
1000 end Check_Component;
1002 ----------------------------------
1003 -- Check_Duplicated_Export_Name --
1004 ----------------------------------
1006 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1007 String_Val : constant String_Id := Strval (Nam);
1010 -- We are only interested in the export case, and in the case of
1011 -- generics, it is the instance, not the template, that is the
1012 -- problem (the template will generate a warning in any case).
1014 if not Inside_A_Generic
1015 and then (Prag_Id = Pragma_Export
1017 Prag_Id = Pragma_Export_Procedure
1019 Prag_Id = Pragma_Export_Valued_Procedure
1021 Prag_Id = Pragma_Export_Function)
1023 for J in Externals.First .. Externals.Last loop
1024 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1025 Error_Msg_Sloc := Sloc (Externals.Table (J));
1026 Error_Msg_N ("external name duplicates name given#", Nam);
1031 Externals.Append (Nam);
1033 end Check_Duplicated_Export_Name;
1035 -------------------------
1036 -- Check_First_Subtype --
1037 -------------------------
1039 procedure Check_First_Subtype (Arg : Node_Id) is
1040 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1042 if not Is_First_Subtype (Entity (Argx)) then
1044 ("pragma% cannot apply to subtype", Argx);
1046 end Check_First_Subtype;
1048 ---------------------------
1049 -- Check_In_Main_Program --
1050 ---------------------------
1052 procedure Check_In_Main_Program is
1053 P : constant Node_Id := Parent (N);
1056 -- Must be at in subprogram body
1058 if Nkind (P) /= N_Subprogram_Body then
1059 Error_Pragma ("% pragma allowed only in subprogram");
1061 -- Otherwise warn if obviously not main program
1063 elsif Present (Parameter_Specifications (Specification (P)))
1064 or else not Is_Compilation_Unit (Defining_Entity (P))
1066 Error_Msg_Name_1 := Chars (N);
1068 ("?pragma% is only effective in main program", N);
1070 end Check_In_Main_Program;
1072 ---------------------------------------
1073 -- Check_Interrupt_Or_Attach_Handler --
1074 ---------------------------------------
1076 procedure Check_Interrupt_Or_Attach_Handler is
1077 Arg1_X : constant Node_Id := Expression (Arg1);
1082 if not Is_Entity_Name (Arg1_X) then
1084 ("argument of pragma% must be entity name", Arg1);
1086 elsif Prag_Id = Pragma_Interrupt_Handler then
1087 Check_Restriction (No_Dynamic_Attachment, N);
1091 Handler_Proc : Entity_Id := Empty;
1092 Proc_Scope : Entity_Id;
1093 Found : Boolean := False;
1096 if not Is_Overloaded (Arg1_X) then
1097 Handler_Proc := Entity (Arg1_X);
1102 Index : Interp_Index;
1105 Get_First_Interp (Arg1_X, Index, It);
1106 while Present (It.Nam) loop
1107 Handler_Proc := It.Nam;
1109 if Ekind (Handler_Proc) = E_Procedure
1110 and then No (First_Formal (Handler_Proc))
1114 Set_Entity (Arg1_X, Handler_Proc);
1115 Set_Is_Overloaded (Arg1_X, False);
1118 ("ambiguous handler name for pragma% ", Arg1);
1122 Get_Next_Interp (Index, It);
1127 ("argument of pragma% must be parameterless procedure",
1130 Handler_Proc := Entity (Arg1_X);
1135 Proc_Scope := Scope (Handler_Proc);
1137 -- On AAMP only, a pragma Interrupt_Handler is supported for
1138 -- nonprotected parameterless procedures.
1141 and then Prag_Id = Pragma_Interrupt_Handler
1143 if Ekind (Handler_Proc) /= E_Procedure then
1145 ("argument of pragma% must be a procedure", Arg1);
1148 elsif Ekind (Handler_Proc) /= E_Procedure
1149 or else Ekind (Proc_Scope) /= E_Protected_Type
1152 ("argument of pragma% must be protected procedure", Arg1);
1155 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
1156 and then Ekind (Proc_Scope) = E_Protected_Type
1159 Protected_Definition (Parent (Proc_Scope))
1161 Error_Pragma ("pragma% must be in protected definition");
1165 if not Is_Library_Level_Entity (Proc_Scope)
1166 or else (AAMP_On_Target
1167 and then not Is_Library_Level_Entity (Handler_Proc))
1170 ("pragma% requires library-level entity", Arg1);
1173 if Present (First_Formal (Handler_Proc)) then
1175 ("argument of pragma% must be parameterless procedure",
1179 end Check_Interrupt_Or_Attach_Handler;
1181 -------------------------------------------
1182 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1183 -------------------------------------------
1185 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1194 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1197 elsif Nkind (P) = N_Package_Specification then
1200 elsif Nkind (P) = N_Block_Statement then
1203 -- Note: the following tests seem a little peculiar, because
1204 -- they test for bodies, but if we were in the statement part
1205 -- of the body, we would already have hit the handled statement
1206 -- sequence, so the only way we get here is by being in the
1207 -- declarative part of the body.
1209 elsif Nkind (P) = N_Subprogram_Body
1210 or else Nkind (P) = N_Package_Body
1211 or else Nkind (P) = N_Task_Body
1212 or else Nkind (P) = N_Entry_Body
1220 Error_Pragma ("pragma% is not in declarative part or package spec");
1221 end Check_Is_In_Decl_Part_Or_Package_Spec;
1223 -------------------------
1224 -- Check_No_Identifier --
1225 -------------------------
1227 procedure Check_No_Identifier (Arg : Node_Id) is
1229 if Chars (Arg) /= No_Name then
1230 Error_Pragma_Arg_Ident
1231 ("pragma% does not permit identifier& here", Arg);
1233 end Check_No_Identifier;
1235 --------------------------
1236 -- Check_No_Identifiers --
1237 --------------------------
1239 procedure Check_No_Identifiers is
1242 if Arg_Count > 0 then
1244 while Present (Arg_Node) loop
1245 Check_No_Identifier (Arg_Node);
1249 end Check_No_Identifiers;
1251 -------------------------------
1252 -- Check_Optional_Identifier --
1253 -------------------------------
1255 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1257 if Present (Arg) and then Chars (Arg) /= No_Name then
1258 if Chars (Arg) /= Id then
1259 Error_Msg_Name_1 := Chars (N);
1260 Error_Msg_Name_2 := Id;
1261 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1265 end Check_Optional_Identifier;
1267 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1269 Name_Buffer (1 .. Id'Length) := Id;
1270 Name_Len := Id'Length;
1271 Check_Optional_Identifier (Arg, Name_Find);
1272 end Check_Optional_Identifier;
1274 -----------------------------
1275 -- Check_Static_Constraint --
1276 -----------------------------
1278 -- Note: for convenience in writing this procedure, in addition to
1279 -- the officially (i.e. by spec) allowed argument which is always
1280 -- a constraint, it also allows ranges and discriminant associations.
1281 -- Above is not clear ???
1283 procedure Check_Static_Constraint (Constr : Node_Id) is
1285 --------------------
1286 -- Require_Static --
1287 --------------------
1289 procedure Require_Static (E : Node_Id);
1290 -- Require given expression to be static expression
1292 procedure Require_Static (E : Node_Id) is
1294 if not Is_OK_Static_Expression (E) then
1295 Flag_Non_Static_Expr
1296 ("non-static constraint not allowed in Unchecked_Union!", E);
1301 -- Start of processing for Check_Static_Constraint
1304 case Nkind (Constr) is
1305 when N_Discriminant_Association =>
1306 Require_Static (Expression (Constr));
1309 Require_Static (Low_Bound (Constr));
1310 Require_Static (High_Bound (Constr));
1312 when N_Attribute_Reference =>
1313 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1314 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1316 when N_Range_Constraint =>
1317 Check_Static_Constraint (Range_Expression (Constr));
1319 when N_Index_Or_Discriminant_Constraint =>
1323 IDC := First (Constraints (Constr));
1324 while Present (IDC) loop
1325 Check_Static_Constraint (IDC);
1333 end Check_Static_Constraint;
1335 --------------------------------------
1336 -- Check_Valid_Configuration_Pragma --
1337 --------------------------------------
1339 -- A configuration pragma must appear in the context clause of
1340 -- a compilation unit, at the start of the list (i.e. only other
1341 -- pragmas may precede it).
1343 procedure Check_Valid_Configuration_Pragma is
1345 if not Is_Configuration_Pragma then
1346 Error_Pragma ("incorrect placement for configuration pragma%");
1348 end Check_Valid_Configuration_Pragma;
1350 -------------------------------------
1351 -- Check_Valid_Library_Unit_Pragma --
1352 -------------------------------------
1354 procedure Check_Valid_Library_Unit_Pragma is
1356 Parent_Node : Node_Id;
1357 Unit_Name : Entity_Id;
1358 Unit_Kind : Node_Kind;
1359 Unit_Node : Node_Id;
1360 Sindex : Source_File_Index;
1363 if not Is_List_Member (N) then
1367 Plist := List_Containing (N);
1368 Parent_Node := Parent (Plist);
1370 if Parent_Node = Empty then
1373 -- Case of pragma appearing after a compilation unit. In this
1374 -- case it must have an argument with the corresponding name
1375 -- and must be part of the following pragmas of its parent.
1377 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1378 if Plist /= Pragmas_After (Parent_Node) then
1381 elsif Arg_Count = 0 then
1383 ("argument required if outside compilation unit");
1386 Check_No_Identifiers;
1387 Check_Arg_Count (1);
1388 Unit_Node := Unit (Parent (Parent_Node));
1389 Unit_Kind := Nkind (Unit_Node);
1391 Analyze (Expression (Arg1));
1393 if Unit_Kind = N_Generic_Subprogram_Declaration
1394 or else Unit_Kind = N_Subprogram_Declaration
1396 Unit_Name := Defining_Entity (Unit_Node);
1398 elsif Unit_Kind = N_Function_Instantiation
1399 or else Unit_Kind = N_Package_Instantiation
1400 or else Unit_Kind = N_Procedure_Instantiation
1402 Unit_Name := Defining_Entity (Unit_Node);
1405 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1408 if Chars (Unit_Name) /=
1409 Chars (Entity (Expression (Arg1)))
1412 ("pragma% argument is not current unit name", Arg1);
1415 if Ekind (Unit_Name) = E_Package
1416 and then Present (Renamed_Entity (Unit_Name))
1418 Error_Pragma ("pragma% not allowed for renamed package");
1422 -- Pragma appears other than after a compilation unit
1425 -- Here we check for the generic instantiation case and also
1426 -- for the case of processing a generic formal package. We
1427 -- detect these cases by noting that the Sloc on the node
1428 -- does not belong to the current compilation unit.
1430 Sindex := Source_Index (Current_Sem_Unit);
1432 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1433 Rewrite (N, Make_Null_Statement (Loc));
1436 -- If before first declaration, the pragma applies to the
1437 -- enclosing unit, and the name if present must be this name.
1439 elsif Is_Before_First_Decl (N, Plist) then
1440 Unit_Node := Unit_Declaration_Node (Current_Scope);
1441 Unit_Kind := Nkind (Unit_Node);
1443 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1446 elsif Unit_Kind = N_Subprogram_Body
1447 and then not Acts_As_Spec (Unit_Node)
1451 elsif Nkind (Parent_Node) = N_Package_Body then
1454 elsif Nkind (Parent_Node) = N_Package_Specification
1455 and then Plist = Private_Declarations (Parent_Node)
1459 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1460 or else Nkind (Parent_Node)
1461 = N_Generic_Subprogram_Declaration)
1462 and then Plist = Generic_Formal_Declarations (Parent_Node)
1466 elsif Arg_Count > 0 then
1467 Analyze (Expression (Arg1));
1469 if Entity (Expression (Arg1)) /= Current_Scope then
1471 ("name in pragma% must be enclosing unit", Arg1);
1474 -- It is legal to have no argument in this context
1480 -- Error if not before first declaration. This is because a
1481 -- library unit pragma argument must be the name of a library
1482 -- unit (RM 10.1.5(7)), but the only names permitted in this
1483 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1484 -- generic subprogram declarations or generic instantiations.
1488 ("pragma% misplaced, must be before first declaration");
1492 end Check_Valid_Library_Unit_Pragma;
1498 procedure Check_Variant (Variant : Node_Id) is
1499 Clist : constant Node_Id := Component_List (Variant);
1503 if Present (Variant_Part (Clist)) then
1505 ("Unchecked_Union may not have nested variants",
1506 Variant_Part (Clist));
1509 if not Is_Non_Empty_List (Component_Items (Clist)) then
1511 ("Unchecked_Union may not have empty component list",
1516 Comp := First (Component_Items (Clist));
1517 while Present (Comp) loop
1518 Check_Component (Comp);
1527 procedure Error_Pragma (Msg : String) is
1529 Error_Msg_Name_1 := Chars (N);
1530 Error_Msg_N (Msg, N);
1534 ----------------------
1535 -- Error_Pragma_Arg --
1536 ----------------------
1538 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1540 Error_Msg_Name_1 := Chars (N);
1541 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1543 end Error_Pragma_Arg;
1545 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1547 Error_Msg_Name_1 := Chars (N);
1548 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1549 Error_Pragma_Arg (Msg2, Arg);
1550 end Error_Pragma_Arg;
1552 ----------------------------
1553 -- Error_Pragma_Arg_Ident --
1554 ----------------------------
1556 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1558 Error_Msg_Name_1 := Chars (N);
1559 Error_Msg_N (Msg, Arg);
1561 end Error_Pragma_Arg_Ident;
1563 ------------------------
1564 -- Find_Lib_Unit_Name --
1565 ------------------------
1567 function Find_Lib_Unit_Name return Entity_Id is
1569 -- Return inner compilation unit entity, for case of nested
1570 -- categorization pragmas. This happens in generic unit.
1572 if Nkind (Parent (N)) = N_Package_Specification
1573 and then Defining_Entity (Parent (N)) /= Current_Scope
1575 return Defining_Entity (Parent (N));
1577 return Current_Scope;
1579 end Find_Lib_Unit_Name;
1581 ----------------------------
1582 -- Find_Program_Unit_Name --
1583 ----------------------------
1585 procedure Find_Program_Unit_Name (Id : Node_Id) is
1586 Unit_Name : Entity_Id;
1587 Unit_Kind : Node_Kind;
1588 P : constant Node_Id := Parent (N);
1591 if Nkind (P) = N_Compilation_Unit then
1592 Unit_Kind := Nkind (Unit (P));
1594 if Unit_Kind = N_Subprogram_Declaration
1595 or else Unit_Kind = N_Package_Declaration
1596 or else Unit_Kind in N_Generic_Declaration
1598 Unit_Name := Defining_Entity (Unit (P));
1600 if Chars (Id) = Chars (Unit_Name) then
1601 Set_Entity (Id, Unit_Name);
1602 Set_Etype (Id, Etype (Unit_Name));
1604 Set_Etype (Id, Any_Type);
1606 ("cannot find program unit referenced by pragma%");
1610 Set_Etype (Id, Any_Type);
1611 Error_Pragma ("pragma% inapplicable to this unit");
1618 end Find_Program_Unit_Name;
1620 -------------------------
1621 -- Gather_Associations --
1622 -------------------------
1624 procedure Gather_Associations
1626 Args : out Args_List)
1631 -- Initialize all parameters to Empty
1633 for J in Args'Range loop
1637 -- That's all we have to do if there are no argument associations
1639 if No (Pragma_Argument_Associations (N)) then
1643 -- Otherwise first deal with any positional parameters present
1645 Arg := First (Pragma_Argument_Associations (N));
1646 for Index in Args'Range loop
1647 exit when No (Arg) or else Chars (Arg) /= No_Name;
1648 Args (Index) := Expression (Arg);
1652 -- Positional parameters all processed, if any left, then we
1653 -- have too many positional parameters.
1655 if Present (Arg) and then Chars (Arg) = No_Name then
1657 ("too many positional associations for pragma%", Arg);
1660 -- Process named parameters if any are present
1662 while Present (Arg) loop
1663 if Chars (Arg) = No_Name then
1665 ("positional association cannot follow named association",
1669 for Index in Names'Range loop
1670 if Names (Index) = Chars (Arg) then
1671 if Present (Args (Index)) then
1673 ("duplicate argument association for pragma%", Arg);
1675 Args (Index) := Expression (Arg);
1680 if Index = Names'Last then
1681 Error_Msg_Name_1 := Chars (N);
1682 Error_Msg_N ("pragma% does not allow & argument", Arg);
1684 -- Check for possible misspelling
1686 for Index1 in Names'Range loop
1687 if Is_Bad_Spelling_Of
1688 (Get_Name_String (Chars (Arg)),
1689 Get_Name_String (Names (Index1)))
1691 Error_Msg_Name_1 := Names (Index1);
1692 Error_Msg_N ("\possible misspelling of%", Arg);
1704 end Gather_Associations;
1706 --------------------
1707 -- Get_Pragma_Arg --
1708 --------------------
1710 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1712 if Nkind (Arg) = N_Pragma_Argument_Association then
1713 return Expression (Arg);
1723 procedure GNAT_Pragma is
1725 Check_Restriction (No_Implementation_Pragmas, N);
1728 --------------------------
1729 -- Is_Before_First_Decl --
1730 --------------------------
1732 function Is_Before_First_Decl
1733 (Pragma_Node : Node_Id;
1734 Decls : List_Id) return Boolean
1736 Item : Node_Id := First (Decls);
1739 -- Only other pragmas can come before this pragma
1742 if No (Item) or else Nkind (Item) /= N_Pragma then
1745 elsif Item = Pragma_Node then
1751 end Is_Before_First_Decl;
1753 -----------------------------
1754 -- Is_Configuration_Pragma --
1755 -----------------------------
1757 -- A configuration pragma must appear in the context clause of
1758 -- a compilation unit, at the start of the list (i.e. only other
1759 -- pragmas may precede it).
1761 function Is_Configuration_Pragma return Boolean is
1762 Lis : constant List_Id := List_Containing (N);
1763 Par : constant Node_Id := Parent (N);
1767 -- If no parent, then we are in the configuration pragma file,
1768 -- so the placement is definitely appropriate.
1773 -- Otherwise we must be in the context clause of a compilation unit
1774 -- and the only thing allowed before us in the context list is more
1775 -- configuration pragmas.
1777 elsif Nkind (Par) = N_Compilation_Unit
1778 and then Context_Items (Par) = Lis
1785 elsif Nkind (Prg) /= N_Pragma then
1795 end Is_Configuration_Pragma;
1797 ----------------------
1798 -- Pragma_Misplaced --
1799 ----------------------
1801 procedure Pragma_Misplaced is
1803 Error_Pragma ("incorrect placement of pragma%");
1804 end Pragma_Misplaced;
1806 ------------------------------------
1807 -- Process Atomic_Shared_Volatile --
1808 ------------------------------------
1810 procedure Process_Atomic_Shared_Volatile is
1817 procedure Set_Atomic (E : Entity_Id);
1818 -- Set given type as atomic, and if no explicit alignment was
1819 -- given, set alignment to unknown, since back end knows what
1820 -- the alignment requirements are for atomic arrays. Note that
1821 -- this step is necessary for derived types.
1827 procedure Set_Atomic (E : Entity_Id) is
1831 if not Has_Alignment_Clause (E) then
1832 Set_Alignment (E, Uint_0);
1836 -- Start of processing for Process_Atomic_Shared_Volatile
1839 Check_Ada_83_Warning;
1840 Check_No_Identifiers;
1841 Check_Arg_Count (1);
1842 Check_Arg_Is_Local_Name (Arg1);
1843 E_Id := Expression (Arg1);
1845 if Etype (E_Id) = Any_Type then
1850 D := Declaration_Node (E);
1854 if Rep_Item_Too_Early (E, N)
1856 Rep_Item_Too_Late (E, N)
1860 Check_First_Subtype (Arg1);
1863 if Prag_Id /= Pragma_Volatile then
1865 Set_Atomic (Underlying_Type (E));
1866 Set_Atomic (Base_Type (E));
1869 -- Attribute belongs on the base type. If the
1870 -- view of the type is currently private, it also
1871 -- belongs on the underlying type.
1873 Set_Is_Volatile (Base_Type (E));
1874 Set_Is_Volatile (Underlying_Type (E));
1876 Set_Treat_As_Volatile (E);
1877 Set_Treat_As_Volatile (Underlying_Type (E));
1879 elsif K = N_Object_Declaration
1880 or else (K = N_Component_Declaration
1881 and then Original_Record_Component (E) = E)
1883 if Rep_Item_Too_Late (E, N) then
1887 if Prag_Id /= Pragma_Volatile then
1890 -- If the object declaration has an explicit
1891 -- initialization, a temporary may have to be
1892 -- created to hold the expression, to insure
1893 -- that access to the object remain atomic.
1895 if Nkind (Parent (E)) = N_Object_Declaration
1896 and then Present (Expression (Parent (E)))
1898 Set_Has_Delayed_Freeze (E);
1901 -- An interesting improvement here. If an object of type X
1902 -- is declared atomic, and the type X is not atomic, that's
1903 -- a pity, since it may not have appropraite alignment etc.
1904 -- We can rescue this in the special case where the object
1905 -- and type are in the same unit by just setting the type
1906 -- as atomic, so that the back end will process it as atomic.
1908 Utyp := Underlying_Type (Etype (E));
1911 and then Sloc (E) > No_Location
1912 and then Sloc (Utyp) > No_Location
1914 Get_Source_File_Index (Sloc (E)) =
1915 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1917 Set_Is_Atomic (Underlying_Type (Etype (E)));
1921 Set_Is_Volatile (E);
1922 Set_Treat_As_Volatile (E);
1926 ("inappropriate entity for pragma%", Arg1);
1928 end Process_Atomic_Shared_Volatile;
1930 ------------------------
1931 -- Process_Convention --
1932 ------------------------
1934 procedure Process_Convention
1935 (C : out Convention_Id;
1941 Comp_Unit : Unit_Number_Type;
1943 procedure Set_Convention_From_Pragma (E : Entity_Id);
1944 -- Set convention in entity E, and also flag that the entity has a
1945 -- convention pragma. If entity is for a private or incomplete type,
1946 -- also set convention and flag on underlying type. This procedure
1947 -- also deals with the special case of C_Pass_By_Copy convention.
1949 --------------------------------
1950 -- Set_Convention_From_Pragma --
1951 --------------------------------
1953 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1955 Set_Convention (E, C);
1956 Set_Has_Convention_Pragma (E);
1958 if Is_Incomplete_Or_Private_Type (E) then
1959 Set_Convention (Underlying_Type (E), C);
1960 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1963 -- A class-wide type should inherit the convention of
1964 -- the specific root type (although this isn't specified
1965 -- clearly by the RM).
1967 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1968 Set_Convention (Class_Wide_Type (E), C);
1971 -- If the entity is a record type, then check for special case
1972 -- of C_Pass_By_Copy, which is treated the same as C except that
1973 -- the special record flag is set. This convention is also only
1974 -- permitted on record types (see AI95-00131).
1976 if Cname = Name_C_Pass_By_Copy then
1977 if Is_Record_Type (E) then
1978 Set_C_Pass_By_Copy (Base_Type (E));
1979 elsif Is_Incomplete_Or_Private_Type (E)
1980 and then Is_Record_Type (Underlying_Type (E))
1982 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1985 ("C_Pass_By_Copy convention allowed only for record type",
1990 -- If the entity is a derived boolean type, check for the
1991 -- special case of convention C, C++, or Fortran, where we
1992 -- consider any nonzero value to represent true.
1994 if Is_Discrete_Type (E)
1995 and then Root_Type (Etype (E)) = Standard_Boolean
2001 C = Convention_Fortran)
2003 Set_Nonzero_Is_True (Base_Type (E));
2005 end Set_Convention_From_Pragma;
2007 -- Start of processing for Process_Convention
2010 Check_At_Least_N_Arguments (2);
2011 Check_Optional_Identifier (Arg1, Name_Convention);
2012 Check_Arg_Is_Identifier (Arg1);
2013 Cname := Chars (Expression (Arg1));
2015 -- C_Pass_By_Copy is treated as a synonym for convention C
2016 -- (this is tested again below to set the critical flag)
2018 if Cname = Name_C_Pass_By_Copy then
2021 -- Otherwise we must have something in the standard convention list
2023 elsif Is_Convention_Name (Cname) then
2024 C := Get_Convention_Id (Chars (Expression (Arg1)));
2026 -- In DEC VMS, it seems that there is an undocumented feature
2027 -- that any unrecognized convention is treated as the default,
2028 -- which for us is convention C. It does not seem so terrible
2029 -- to do this unconditionally, silently in the VMS case, and
2030 -- with a warning in the non-VMS case.
2033 if Warn_On_Export_Import and not OpenVMS_On_Target then
2035 ("?unrecognized convention name, C assumed",
2042 Check_Optional_Identifier (Arg2, Name_Entity);
2043 Check_Arg_Is_Local_Name (Arg2);
2045 Id := Expression (Arg2);
2048 if not Is_Entity_Name (Id) then
2049 Error_Pragma_Arg ("entity name required", Arg2);
2054 -- Go to renamed subprogram if present, since convention applies
2055 -- to the actual renamed entity, not to the renaming entity.
2056 -- If subprogram is inherited, go to parent subprogram.
2058 if Is_Subprogram (E)
2059 and then Present (Alias (E))
2061 if Nkind (Parent (Declaration_Node (E)))
2062 = N_Subprogram_Renaming_Declaration
2066 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2067 and then Scope (E) = Scope (Alias (E))
2073 -- Check that we are not applying this to a specless body
2075 if Is_Subprogram (E)
2076 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2079 ("pragma% requires separate spec and must come before body");
2082 -- Check that we are not applying this to a named constant
2084 if Ekind (E) = E_Named_Integer
2086 Ekind (E) = E_Named_Real
2088 Error_Msg_Name_1 := Chars (N);
2090 ("cannot apply pragma% to named constant!",
2091 Get_Pragma_Arg (Arg2));
2093 ("\supply appropriate type for&!", Arg2);
2096 if Etype (E) = Any_Type
2097 or else Rep_Item_Too_Early (E, N)
2101 E := Underlying_Type (E);
2104 if Rep_Item_Too_Late (E, N) then
2108 if Has_Convention_Pragma (E) then
2110 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2112 elsif Convention (E) = Convention_Protected
2113 or else Ekind (Scope (E)) = E_Protected_Type
2116 ("a protected operation cannot be given a different convention",
2120 -- For Intrinsic, a subprogram is required
2122 if C = Convention_Intrinsic
2123 and then not Is_Subprogram (E)
2124 and then not Is_Generic_Subprogram (E)
2127 ("second argument of pragma% must be a subprogram", Arg2);
2130 -- For Stdcall, a subprogram, variable or subprogram type is required
2132 if C = Convention_Stdcall
2133 and then not Is_Subprogram (E)
2134 and then not Is_Generic_Subprogram (E)
2135 and then Ekind (E) /= E_Variable
2138 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2141 ("second argument of pragma% must be subprogram (type)",
2145 if not Is_Subprogram (E)
2146 and then not Is_Generic_Subprogram (E)
2148 Set_Convention_From_Pragma (E);
2152 Check_First_Subtype (Arg2);
2153 Set_Convention_From_Pragma (Base_Type (E));
2155 -- For subprograms, we must set the convention on the
2156 -- internally generated directly designated type as well.
2158 if Ekind (E) = E_Access_Subprogram_Type then
2159 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2163 -- For the subprogram case, set proper convention for all homonyms
2164 -- in same scope and the same declarative part, i.e. the same
2165 -- compilation unit.
2168 Comp_Unit := Get_Source_Unit (E);
2169 Set_Convention_From_Pragma (E);
2171 -- Treat a pragma Import as an implicit body, for GPS use.
2173 if Prag_Id = Pragma_Import then
2174 Generate_Reference (E, Id, 'b');
2180 exit when No (E1) or else Scope (E1) /= Current_Scope;
2182 -- Note: below we are missing a check for Rep_Item_Too_Late.
2183 -- That is deliberate, we cannot chain the rep item on more
2184 -- than one Rep_Item chain, to be fixed later ???
2186 if Comes_From_Source (E1)
2187 and then Comp_Unit = Get_Source_Unit (E1)
2188 and then Nkind (Original_Node (Parent (E1))) /=
2189 N_Full_Type_Declaration
2191 Set_Convention_From_Pragma (E1);
2193 if Prag_Id = Pragma_Import then
2194 Generate_Reference (E, Id, 'b');
2199 end Process_Convention;
2201 -----------------------------------------------------
2202 -- Process_Extended_Import_Export_Exception_Pragma --
2203 -----------------------------------------------------
2205 procedure Process_Extended_Import_Export_Exception_Pragma
2206 (Arg_Internal : Node_Id;
2207 Arg_External : Node_Id;
2217 if not OpenVMS_On_Target then
2219 ("?pragma% ignored (applies only to Open'V'M'S)");
2222 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2223 Def_Id := Entity (Arg_Internal);
2225 if Ekind (Def_Id) /= E_Exception then
2227 ("pragma% must refer to declared exception", Arg_Internal);
2230 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2232 if Present (Arg_Form) then
2233 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2236 if Present (Arg_Form)
2237 and then Chars (Arg_Form) = Name_Ada
2241 Set_Is_VMS_Exception (Def_Id);
2242 Set_Exception_Code (Def_Id, No_Uint);
2245 if Present (Arg_Code) then
2246 if not Is_VMS_Exception (Def_Id) then
2248 ("Code option for pragma% not allowed for Ada case",
2252 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2253 Code_Val := Expr_Value (Arg_Code);
2255 if not UI_Is_In_Int_Range (Code_Val) then
2257 ("Code option for pragma% must be in 32-bit range",
2261 Set_Exception_Code (Def_Id, Code_Val);
2264 end Process_Extended_Import_Export_Exception_Pragma;
2266 -------------------------------------------------
2267 -- Process_Extended_Import_Export_Internal_Arg --
2268 -------------------------------------------------
2270 procedure Process_Extended_Import_Export_Internal_Arg
2271 (Arg_Internal : Node_Id := Empty)
2276 if No (Arg_Internal) then
2277 Error_Pragma ("Internal parameter required for pragma%");
2280 if Nkind (Arg_Internal) = N_Identifier then
2283 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2284 and then (Prag_Id = Pragma_Import_Function
2286 Prag_Id = Pragma_Export_Function)
2292 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2295 Check_Arg_Is_Local_Name (Arg_Internal);
2296 end Process_Extended_Import_Export_Internal_Arg;
2298 --------------------------------------------------
2299 -- Process_Extended_Import_Export_Object_Pragma --
2300 --------------------------------------------------
2302 procedure Process_Extended_Import_Export_Object_Pragma
2303 (Arg_Internal : Node_Id;
2304 Arg_External : Node_Id;
2310 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2311 Def_Id := Entity (Arg_Internal);
2313 if Ekind (Def_Id) /= E_Constant
2314 and then Ekind (Def_Id) /= E_Variable
2317 ("pragma% must designate an object", Arg_Internal);
2320 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2322 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2325 ("previous Common/Psect_Object applies, pragma % not permitted",
2329 if Rep_Item_Too_Late (Def_Id, N) then
2333 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2335 if Present (Arg_Size) then
2336 Check_Arg_Is_External_Name (Arg_Size);
2339 -- Export_Object case
2341 if Prag_Id = Pragma_Export_Object then
2342 if not Is_Library_Level_Entity (Def_Id) then
2344 ("argument for pragma% must be library level entity",
2348 if Ekind (Current_Scope) = E_Generic_Package then
2349 Error_Pragma ("pragma& cannot appear in a generic unit");
2352 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2354 ("exported object must have compile time known size",
2358 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2360 ("?duplicate Export_Object pragma", N);
2362 Set_Exported (Def_Id, Arg_Internal);
2365 -- Import_Object case
2368 if Is_Concurrent_Type (Etype (Def_Id)) then
2370 ("cannot use pragma% for task/protected object",
2374 if Ekind (Def_Id) = E_Constant then
2376 ("cannot import a constant", Arg_Internal);
2379 if Warn_On_Export_Import
2380 and then Has_Discriminants (Etype (Def_Id))
2383 ("imported value must be initialized?", Arg_Internal);
2386 if Warn_On_Export_Import
2387 and then Is_Access_Type (Etype (Def_Id))
2390 ("cannot import object of an access type?", Arg_Internal);
2393 if Warn_On_Export_Import
2394 and then Is_Imported (Def_Id)
2397 ("?duplicate Import_Object pragma", N);
2399 -- Check for explicit initialization present. Note that an
2400 -- initialization that generated by the code generator, e.g.
2401 -- for an access type, does not count here.
2403 elsif Present (Expression (Parent (Def_Id)))
2406 (Original_Node (Expression (Parent (Def_Id))))
2408 Error_Msg_Sloc := Sloc (Def_Id);
2410 ("no initialization allowed for declaration of& #",
2411 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2414 Set_Imported (Def_Id);
2415 Note_Possible_Modification (Arg_Internal);
2418 end Process_Extended_Import_Export_Object_Pragma;
2420 ------------------------------------------------------
2421 -- Process_Extended_Import_Export_Subprogram_Pragma --
2422 ------------------------------------------------------
2424 procedure Process_Extended_Import_Export_Subprogram_Pragma
2425 (Arg_Internal : Node_Id;
2426 Arg_External : Node_Id;
2427 Arg_Parameter_Types : Node_Id;
2428 Arg_Result_Type : Node_Id := Empty;
2429 Arg_Mechanism : Node_Id;
2430 Arg_Result_Mechanism : Node_Id := Empty;
2431 Arg_First_Optional_Parameter : Node_Id := Empty)
2437 Ambiguous : Boolean;
2441 function Same_Base_Type
2443 Formal : Entity_Id) return Boolean;
2444 -- Determines if Ptype references the type of Formal. Note that
2445 -- only the base types need to match according to the spec. Ptype
2446 -- here is the argument from the pragma, which is either a type
2447 -- name, or an access attribute.
2449 --------------------
2450 -- Same_Base_Type --
2451 --------------------
2453 function Same_Base_Type
2455 Formal : Entity_Id) return Boolean
2457 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2461 -- Case where pragma argument is typ'Access
2463 if Nkind (Ptype) = N_Attribute_Reference
2464 and then Attribute_Name (Ptype) = Name_Access
2466 Pref := Prefix (Ptype);
2469 if not Is_Entity_Name (Pref)
2470 or else Entity (Pref) = Any_Type
2475 -- We have a match if the corresponding argument is of an
2476 -- anonymous access type, and its designicated type matches
2477 -- the type of the prefix of the access attribute
2479 return Ekind (Ftyp) = E_Anonymous_Access_Type
2480 and then Base_Type (Entity (Pref)) =
2481 Base_Type (Etype (Designated_Type (Ftyp)));
2483 -- Case where pragma argument is a type name
2488 if not Is_Entity_Name (Ptype)
2489 or else Entity (Ptype) = Any_Type
2494 -- We have a match if the corresponding argument is of
2495 -- the type given in the pragma (comparing base types)
2497 return Base_Type (Entity (Ptype)) = Ftyp;
2501 -- Start of processing for
2502 -- Process_Extended_Import_Export_Subprogram_Pragma
2505 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2509 -- Loop through homonyms (overloadings) of the entity
2511 Hom_Id := Entity (Arg_Internal);
2512 while Present (Hom_Id) loop
2513 Def_Id := Get_Base_Subprogram (Hom_Id);
2515 -- We need a subprogram in the current scope
2517 if not Is_Subprogram (Def_Id)
2518 or else Scope (Def_Id) /= Current_Scope
2525 -- Pragma cannot apply to subprogram body
2527 if Is_Subprogram (Def_Id)
2530 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2533 ("pragma% requires separate spec"
2534 & " and must come before body");
2537 -- Test result type if given, note that the result type
2538 -- parameter can only be present for the function cases.
2540 if Present (Arg_Result_Type)
2541 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2545 elsif Etype (Def_Id) /= Standard_Void_Type
2547 (Chars (N) = Name_Export_Procedure
2548 or else Chars (N) = Name_Import_Procedure)
2552 -- Test parameter types if given. Note that this parameter
2553 -- has not been analyzed (and must not be, since it is
2554 -- semantic nonsense), so we get it as the parser left it.
2556 elsif Present (Arg_Parameter_Types) then
2557 Check_Matching_Types : declare
2562 Formal := First_Formal (Def_Id);
2564 if Nkind (Arg_Parameter_Types) = N_Null then
2565 if Present (Formal) then
2569 -- A list of one type, e.g. (List) is parsed as
2570 -- a parenthesized expression.
2572 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2573 and then Paren_Count (Arg_Parameter_Types) = 1
2576 or else Present (Next_Formal (Formal))
2581 Same_Base_Type (Arg_Parameter_Types, Formal);
2584 -- A list of more than one type is parsed as a aggregate
2586 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2587 and then Paren_Count (Arg_Parameter_Types) = 0
2589 Ptype := First (Expressions (Arg_Parameter_Types));
2590 while Present (Ptype) or else Present (Formal) loop
2593 or else not Same_Base_Type (Ptype, Formal)
2598 Next_Formal (Formal);
2603 -- Anything else is of the wrong form
2607 ("wrong form for Parameter_Types parameter",
2608 Arg_Parameter_Types);
2610 end Check_Matching_Types;
2613 -- Match is now False if the entry we found did not match
2614 -- either a supplied Parameter_Types or Result_Types argument
2620 -- Ambiguous case, the flag Ambiguous shows if we already
2621 -- detected this and output the initial messages.
2624 if not Ambiguous then
2626 Error_Msg_Name_1 := Chars (N);
2628 ("pragma% does not uniquely identify subprogram!",
2630 Error_Msg_Sloc := Sloc (Ent);
2631 Error_Msg_N ("matching subprogram #!", N);
2635 Error_Msg_Sloc := Sloc (Def_Id);
2636 Error_Msg_N ("matching subprogram #!", N);
2641 Hom_Id := Homonym (Hom_Id);
2644 -- See if we found an entry
2647 if not Ambiguous then
2648 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2650 ("pragma% cannot be given for generic subprogram");
2654 ("pragma% does not identify local subprogram");
2661 -- Import pragmas must be be for imported entities
2663 if Prag_Id = Pragma_Import_Function
2665 Prag_Id = Pragma_Import_Procedure
2667 Prag_Id = Pragma_Import_Valued_Procedure
2669 if not Is_Imported (Ent) then
2671 ("pragma Import or Interface must precede pragma%");
2674 -- Here we have the Export case which can set the entity as exported
2676 -- But does not do so if the specified external name is null,
2677 -- since that is taken as a signal in DEC Ada 83 (with which
2678 -- we want to be compatible) to request no external name.
2680 elsif Nkind (Arg_External) = N_String_Literal
2681 and then String_Length (Strval (Arg_External)) = 0
2685 -- In all other cases, set entit as exported
2688 Set_Exported (Ent, Arg_Internal);
2691 -- Special processing for Valued_Procedure cases
2693 if Prag_Id = Pragma_Import_Valued_Procedure
2695 Prag_Id = Pragma_Export_Valued_Procedure
2697 Formal := First_Formal (Ent);
2701 ("at least one parameter required for pragma%");
2703 elsif Ekind (Formal) /= E_Out_Parameter then
2705 ("first parameter must have mode out for pragma%");
2708 Set_Is_Valued_Procedure (Ent);
2712 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2714 -- Process Result_Mechanism argument if present. We have already
2715 -- checked that this is only allowed for the function case.
2717 if Present (Arg_Result_Mechanism) then
2718 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2721 -- Process Mechanism parameter if present. Note that this parameter
2722 -- is not analyzed, and must not be analyzed since it is semantic
2723 -- nonsense, so we get it in exactly as the parser left it.
2725 if Present (Arg_Mechanism) then
2733 -- A single mechanism association without a formal parameter
2734 -- name is parsed as a parenthesized expression. All other
2735 -- cases are parsed as aggregates, so we rewrite the single
2736 -- parameter case as an aggregate for consistency.
2738 if Nkind (Arg_Mechanism) /= N_Aggregate
2739 and then Paren_Count (Arg_Mechanism) = 1
2741 Rewrite (Arg_Mechanism,
2742 Make_Aggregate (Sloc (Arg_Mechanism),
2743 Expressions => New_List (
2744 Relocate_Node (Arg_Mechanism))));
2747 -- Case of only mechanism name given, applies to all formals
2749 if Nkind (Arg_Mechanism) /= N_Aggregate then
2750 Formal := First_Formal (Ent);
2751 while Present (Formal) loop
2752 Set_Mechanism_Value (Formal, Arg_Mechanism);
2753 Next_Formal (Formal);
2756 -- Case of list of mechanism associations given
2759 if Null_Record_Present (Arg_Mechanism) then
2761 ("inappropriate form for Mechanism parameter",
2765 -- Deal with positional ones first
2767 Formal := First_Formal (Ent);
2769 if Present (Expressions (Arg_Mechanism)) then
2770 Mname := First (Expressions (Arg_Mechanism));
2772 while Present (Mname) loop
2775 ("too many mechanism associations", Mname);
2778 Set_Mechanism_Value (Formal, Mname);
2779 Next_Formal (Formal);
2784 -- Deal with named entries
2786 if Present (Component_Associations (Arg_Mechanism)) then
2787 Massoc := First (Component_Associations (Arg_Mechanism));
2789 while Present (Massoc) loop
2790 Choice := First (Choices (Massoc));
2792 if Nkind (Choice) /= N_Identifier
2793 or else Present (Next (Choice))
2796 ("incorrect form for mechanism association",
2800 Formal := First_Formal (Ent);
2804 ("parameter name & not present", Choice);
2807 if Chars (Choice) = Chars (Formal) then
2809 (Formal, Expression (Massoc));
2813 Next_Formal (Formal);
2823 -- Process First_Optional_Parameter argument if present. We have
2824 -- already checked that this is only allowed for the Import case.
2826 if Present (Arg_First_Optional_Parameter) then
2827 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2829 ("first optional parameter must be formal parameter name",
2830 Arg_First_Optional_Parameter);
2833 Formal := First_Formal (Ent);
2837 ("specified formal parameter& not found",
2838 Arg_First_Optional_Parameter);
2841 exit when Chars (Formal) =
2842 Chars (Arg_First_Optional_Parameter);
2844 Next_Formal (Formal);
2847 Set_First_Optional_Parameter (Ent, Formal);
2849 -- Check specified and all remaining formals have right form
2851 while Present (Formal) loop
2852 if Ekind (Formal) /= E_In_Parameter then
2854 ("optional formal& is not of mode in!",
2855 Arg_First_Optional_Parameter, Formal);
2858 Dval := Default_Value (Formal);
2860 if not Present (Dval) then
2862 ("optional formal& does not have default value!",
2863 Arg_First_Optional_Parameter, Formal);
2865 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2870 ("default value for optional formal& is non-static!",
2871 Arg_First_Optional_Parameter, Formal);
2875 Set_Is_Optional_Parameter (Formal);
2876 Next_Formal (Formal);
2879 end Process_Extended_Import_Export_Subprogram_Pragma;
2881 --------------------------
2882 -- Process_Generic_List --
2883 --------------------------
2885 procedure Process_Generic_List is
2891 Check_No_Identifiers;
2892 Check_At_Least_N_Arguments (1);
2895 while Present (Arg) loop
2896 Exp := Expression (Arg);
2899 if not Is_Entity_Name (Exp)
2901 (not Is_Generic_Instance (Entity (Exp))
2903 not Is_Generic_Unit (Entity (Exp)))
2906 ("pragma% argument must be name of generic unit/instance",
2912 end Process_Generic_List;
2914 ---------------------------------
2915 -- Process_Import_Or_Interface --
2916 ---------------------------------
2918 procedure Process_Import_Or_Interface is
2924 Process_Convention (C, Def_Id);
2925 Kill_Size_Check_Code (Def_Id);
2926 Note_Possible_Modification (Expression (Arg2));
2928 if Ekind (Def_Id) = E_Variable
2930 Ekind (Def_Id) = E_Constant
2932 -- User initialization is not allowed for imported object, but
2933 -- the object declaration may contain a default initialization,
2934 -- that will be discarded. Note that an explicit initialization
2935 -- only counts if it comes from source, otherwise it is simply
2936 -- the code generator making an implicit initialization explicit.
2938 if Present (Expression (Parent (Def_Id)))
2939 and then Comes_From_Source (Expression (Parent (Def_Id)))
2941 Error_Msg_Sloc := Sloc (Def_Id);
2943 ("no initialization allowed for declaration of& #",
2944 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2948 Set_Imported (Def_Id);
2949 Process_Interface_Name (Def_Id, Arg3, Arg4);
2951 -- Note that we do not set Is_Public here. That's because we
2952 -- only want to set if if there is no address clause, and we
2953 -- don't know that yet, so we delay that processing till
2956 -- pragma Import completes deferred constants
2958 if Ekind (Def_Id) = E_Constant then
2959 Set_Has_Completion (Def_Id);
2962 -- It is not possible to import a constant of an unconstrained
2963 -- array type (e.g. string) because there is no simple way to
2964 -- write a meaningful subtype for it.
2966 if Is_Array_Type (Etype (Def_Id))
2967 and then not Is_Constrained (Etype (Def_Id))
2970 ("imported constant& must have a constrained subtype",
2975 elsif Is_Subprogram (Def_Id)
2976 or else Is_Generic_Subprogram (Def_Id)
2978 -- If the name is overloaded, pragma applies to all of the
2979 -- denoted entities in the same declarative part.
2982 while Present (Hom_Id) loop
2983 Def_Id := Get_Base_Subprogram (Hom_Id);
2985 -- Ignore inherited subprograms because the pragma will
2986 -- apply to the parent operation, which is the one called.
2988 if Is_Overloadable (Def_Id)
2989 and then Present (Alias (Def_Id))
2993 -- If it is not a subprogram, it must be in an outer
2994 -- scope and pragma does not apply.
2996 elsif not Is_Subprogram (Def_Id)
2997 and then not Is_Generic_Subprogram (Def_Id)
3001 -- Verify that the homonym is in the same declarative
3002 -- part (not just the same scope).
3004 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3005 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3010 Set_Imported (Def_Id);
3012 -- Special processing for Convention_Intrinsic
3014 if C = Convention_Intrinsic then
3016 -- Link_Name argument not allowed for intrinsic
3019 and then Chars (Arg3) = Name_Link_Name
3024 if Present (Arg4) then
3026 ("Link_Name argument not allowed for " &
3031 Set_Is_Intrinsic_Subprogram (Def_Id);
3033 -- If no external name is present, then check that
3034 -- this is a valid intrinsic subprogram. If an external
3035 -- name is present, then this is handled by the back end.
3038 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3042 -- All interfaced procedures need an external symbol
3043 -- created for them since they are always referenced
3044 -- from another object file.
3046 Set_Is_Public (Def_Id);
3048 -- Verify that the subprogram does not have a completion
3049 -- through a renaming declaration. For other completions
3050 -- the pragma appears as a too late representation.
3053 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3057 and then Nkind (Decl) = N_Subprogram_Declaration
3058 and then Present (Corresponding_Body (Decl))
3061 (Unit_Declaration_Node
3062 (Corresponding_Body (Decl))) =
3063 N_Subprogram_Renaming_Declaration
3065 Error_Msg_Sloc := Sloc (Def_Id);
3066 Error_Msg_NE ("cannot import&#," &
3067 " already completed by a renaming",
3072 Set_Has_Completion (Def_Id);
3073 Process_Interface_Name (Def_Id, Arg3, Arg4);
3076 if Is_Compilation_Unit (Hom_Id) then
3078 -- Its possible homonyms are not affected by the pragma.
3079 -- Such homonyms might be present in the context of other
3080 -- units being compiled.
3085 Hom_Id := Homonym (Hom_Id);
3089 -- When the convention is Java, we also allow Import to be given
3090 -- for packages, exceptions, and record components.
3092 elsif C = Convention_Java
3094 (Ekind (Def_Id) = E_Package
3095 or else Ekind (Def_Id) = E_Exception
3096 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3098 Set_Imported (Def_Id);
3099 Set_Is_Public (Def_Id);
3100 Process_Interface_Name (Def_Id, Arg3, Arg4);
3104 ("second argument of pragma% must be object or subprogram",
3108 -- If this pragma applies to a compilation unit, then the unit,
3109 -- which is a subprogram, does not require (or allow) a body.
3110 -- We also do not need to elaborate imported procedures.
3112 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3114 Cunit : constant Node_Id := Parent (Parent (N));
3116 Set_Body_Required (Cunit, False);
3119 end Process_Import_Or_Interface;
3121 --------------------
3122 -- Process_Inline --
3123 --------------------
3125 procedure Process_Inline (Active : Boolean) is
3131 Effective : Boolean := False;
3133 procedure Make_Inline (Subp : Entity_Id);
3134 -- Subp is the defining unit name of the subprogram
3135 -- declaration. Set the flag, as well as the flag in the
3136 -- corresponding body, if there is one present.
3138 procedure Set_Inline_Flags (Subp : Entity_Id);
3139 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
3141 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3142 -- Returns True if it can be determined at this stage that inlining
3143 -- is not possible, for examle if the body is available and contains
3144 -- exception handlers, we prevent inlining, since otherwise we can
3145 -- get undefined symbols at link time. This function also emits a
3146 -- warning if front-end inlining is enabled and the pragma appears
3148 -- ??? is business with link symbols still valid, or does it relate
3149 -- to front end ZCX which is being phased out ???
3151 ---------------------------
3152 -- Inlining_Not_Possible --
3153 ---------------------------
3155 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3156 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3160 if Nkind (Decl) = N_Subprogram_Body then
3161 Stats := Handled_Statement_Sequence (Decl);
3162 return Present (Exception_Handlers (Stats))
3163 or else Present (At_End_Proc (Stats));
3165 elsif Nkind (Decl) = N_Subprogram_Declaration
3166 and then Present (Corresponding_Body (Decl))
3168 if Front_End_Inlining
3169 and then Analyzed (Corresponding_Body (Decl))
3171 Error_Msg_N ("pragma appears too late, ignored?", N);
3174 -- If the subprogram is a renaming as body, the body is
3175 -- just a call to the renamed subprogram, and inlining is
3176 -- trivially possible.
3179 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
3180 = N_Subprogram_Renaming_Declaration
3186 Handled_Statement_Sequence
3187 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3190 Present (Exception_Handlers (Stats))
3191 or else Present (At_End_Proc (Stats));
3195 -- If body is not available, assume the best, the check is
3196 -- performed again when compiling enclosing package bodies.
3200 end Inlining_Not_Possible;
3206 procedure Make_Inline (Subp : Entity_Id) is
3207 Kind : constant Entity_Kind := Ekind (Subp);
3208 Inner_Subp : Entity_Id := Subp;
3211 if Etype (Subp) = Any_Type then
3214 -- If inlining is not possible, for now do not treat as an error
3216 elsif Inlining_Not_Possible (Subp) then
3220 -- Here we have a candidate for inlining, but we must exclude
3221 -- derived operations. Otherwise we will end up trying to
3222 -- inline a phantom declaration, and the result would be to
3223 -- drag in a body which has no direct inlining associated with
3224 -- it. That would not only be inefficient but would also result
3225 -- in the backend doing cross-unit inlining in cases where it
3226 -- was definitely inappropriate to do so.
3228 -- However, a simple Comes_From_Source test is insufficient,
3229 -- since we do want to allow inlining of generic instances,
3230 -- which also do not come from source. Predefined operators do
3231 -- not come from source but are not inlineable either.
3233 elsif not Comes_From_Source (Subp)
3234 and then not Is_Generic_Instance (Subp)
3235 and then Scope (Subp) /= Standard_Standard
3240 -- The referenced entity must either be the enclosing entity,
3241 -- or an entity declared within the current open scope.
3243 elsif Present (Scope (Subp))
3244 and then Scope (Subp) /= Current_Scope
3245 and then Subp /= Current_Scope
3248 ("argument of% must be entity in current scope", Assoc);
3252 -- Processing for procedure, operator or function.
3253 -- If subprogram is aliased (as for an instance) indicate
3254 -- that the renamed entity (if declared in the same unit)
3257 if Is_Subprogram (Subp) then
3258 while Present (Alias (Inner_Subp)) loop
3259 Inner_Subp := Alias (Inner_Subp);
3262 if In_Same_Source_Unit (Subp, Inner_Subp) then
3263 Set_Inline_Flags (Inner_Subp);
3265 Decl := Parent (Parent (Inner_Subp));
3267 if Nkind (Decl) = N_Subprogram_Declaration
3268 and then Present (Corresponding_Body (Decl))
3270 Set_Inline_Flags (Corresponding_Body (Decl));
3276 -- For a generic subprogram set flag as well, for use at
3277 -- the point of instantiation, to determine whether the
3278 -- body should be generated.
3280 elsif Is_Generic_Subprogram (Subp) then
3281 Set_Inline_Flags (Subp);
3284 -- Literals are by definition inlined
3286 elsif Kind = E_Enumeration_Literal then
3289 -- Anything else is an error
3293 ("expect subprogram name for pragma%", Assoc);
3297 ----------------------
3298 -- Set_Inline_Flags --
3299 ----------------------
3301 procedure Set_Inline_Flags (Subp : Entity_Id) is
3304 Set_Is_Inlined (Subp, True);
3307 if not Has_Pragma_Inline (Subp) then
3308 Set_Has_Pragma_Inline (Subp);
3309 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
3310 Set_First_Rep_Item (Subp, N);
3313 end Set_Inline_Flags;
3315 -- Start of processing for Process_Inline
3318 Check_No_Identifiers;
3319 Check_At_Least_N_Arguments (1);
3322 Inline_Processing_Required := True;
3326 while Present (Assoc) loop
3327 Subp_Id := Expression (Assoc);
3331 if Is_Entity_Name (Subp_Id) then
3332 Subp := Entity (Subp_Id);
3334 if Subp = Any_Id then
3336 -- If previous error, avoid cascaded errors
3344 while Present (Homonym (Subp))
3345 and then Scope (Homonym (Subp)) = Current_Scope
3347 Make_Inline (Homonym (Subp));
3348 Subp := Homonym (Subp);
3355 ("inappropriate argument for pragma%", Assoc);
3358 and then Warn_On_Redundant_Constructs
3360 if Inlining_Not_Possible (Subp) then
3362 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3365 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3373 ----------------------------
3374 -- Process_Interface_Name --
3375 ----------------------------
3377 procedure Process_Interface_Name
3378 (Subprogram_Def : Entity_Id;
3384 String_Val : String_Id;
3386 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3387 -- SN is a string literal node for an interface name. This routine
3388 -- performs some minimal checks that the name is reasonable. In
3389 -- particular that no spaces or other obviously incorrect characters
3390 -- appear. This is only a warning, since any characters are allowed.
3392 ----------------------------------
3393 -- Check_Form_Of_Interface_Name --
3394 ----------------------------------
3396 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3397 S : constant String_Id := Strval (Expr_Value_S (SN));
3398 SL : constant Nat := String_Length (S);
3403 Error_Msg_N ("interface name cannot be null string", SN);
3406 for J in 1 .. SL loop
3407 C := Get_String_Char (S, J);
3409 if Warn_On_Export_Import
3410 and then (not In_Character_Range (C)
3411 or else Get_Character (C) = ' '
3412 or else Get_Character (C) = ',')
3415 ("?interface name contains illegal character", SN);
3418 end Check_Form_Of_Interface_Name;
3420 -- Start of processing for Process_Interface_Name
3423 if No (Link_Arg) then
3424 if No (Ext_Arg) then
3427 elsif Chars (Ext_Arg) = Name_Link_Name then
3429 Link_Nam := Expression (Ext_Arg);
3432 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3433 Ext_Nam := Expression (Ext_Arg);
3438 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3439 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3440 Ext_Nam := Expression (Ext_Arg);
3441 Link_Nam := Expression (Link_Arg);
3444 -- Check expressions for external name and link name are static
3446 if Present (Ext_Nam) then
3447 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3448 Check_Form_Of_Interface_Name (Ext_Nam);
3450 -- Verify that the external name is not the name of a local
3451 -- entity, which would hide the imported one and lead to
3452 -- run-time surprises. The problem can only arise for entities
3453 -- declared in a package body (otherwise the external name is
3454 -- fully qualified and won't conflict).
3462 if Prag_Id = Pragma_Import then
3463 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3465 E := Entity_Id (Get_Name_Table_Info (Nam));
3467 if Nam /= Chars (Subprogram_Def)
3468 and then Present (E)
3469 and then not Is_Overloadable (E)
3470 and then Is_Immediately_Visible (E)
3471 and then not Is_Imported (E)
3472 and then Ekind (Scope (E)) = E_Package
3476 while Present (Par) loop
3477 if Nkind (Par) = N_Package_Body then
3478 Error_Msg_Sloc := Sloc (E);
3480 ("imported entity is hidden by & declared#",
3485 Par := Parent (Par);
3492 if Present (Link_Nam) then
3493 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3494 Check_Form_Of_Interface_Name (Link_Nam);
3497 -- If there is no link name, just set the external name
3499 if No (Link_Nam) then
3500 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
3502 -- For the Link_Name case, the given literal is preceded by an
3503 -- asterisk, which indicates to GCC that the given name should
3504 -- be taken literally, and in particular that no prepending of
3505 -- underlines should occur, even in systems where this is the
3510 Store_String_Char (Get_Char_Code ('*'));
3511 String_Val := Strval (Expr_Value_S (Link_Nam));
3513 for J in 1 .. String_Length (String_Val) loop
3514 Store_String_Char (Get_String_Char (String_Val, J));
3518 Make_String_Literal (Sloc (Link_Nam), End_String);
3521 Set_Encoded_Interface_Name
3522 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3523 Check_Duplicated_Export_Name (Link_Nam);
3524 end Process_Interface_Name;
3526 -----------------------------------------
3527 -- Process_Interrupt_Or_Attach_Handler --
3528 -----------------------------------------
3530 procedure Process_Interrupt_Or_Attach_Handler is
3531 Arg1_X : constant Node_Id := Expression (Arg1);
3532 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3533 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3536 Set_Is_Interrupt_Handler (Handler_Proc);
3538 -- If the pragma is not associated with a handler procedure
3539 -- within a protected type, then it must be for a nonprotected
3540 -- procedure for the AAMP target, in which case we don't
3541 -- associate a representation item with the procedure's scope.
3543 if Ekind (Proc_Scope) = E_Protected_Type then
3544 if Prag_Id = Pragma_Interrupt_Handler
3546 Prag_Id = Pragma_Attach_Handler
3548 Record_Rep_Item (Proc_Scope, N);
3551 end Process_Interrupt_Or_Attach_Handler;
3553 --------------------------------------------------
3554 -- Process_Restrictions_Or_Restriction_Warnings --
3555 --------------------------------------------------
3557 -- Note: some of the simple identifier cases were handled in par-prag,
3558 -- but it is harmless (and more straightforward) to simply handle all
3559 -- cases here, even if it means we repeat a bit of work in some cases.
3561 procedure Process_Restrictions_Or_Restriction_Warnings is
3563 R_Id : Restriction_Id;
3568 procedure Check_Unit_Name (N : Node_Id);
3569 -- Checks unit name parameter for No_Dependence. Returns if it has
3570 -- an appropriate form, otherwise raises pragma argument error.
3572 procedure Set_Warning (R : All_Restrictions);
3573 -- If this is a Restriction_Warnings pragma, set warning flag,
3574 -- otherwise reset the flag.
3576 ---------------------
3577 -- Check_Unit_Name --
3578 ---------------------
3580 procedure Check_Unit_Name (N : Node_Id) is
3582 if Nkind (N) = N_Selected_Component then
3583 Check_Unit_Name (Prefix (N));
3584 Check_Unit_Name (Selector_Name (N));
3586 elsif Nkind (N) = N_Identifier then
3591 ("wrong form for unit name for No_Dependence", N);
3593 end Check_Unit_Name;
3599 procedure Set_Warning (R : All_Restrictions) is
3601 if Prag_Id = Pragma_Restriction_Warnings then
3602 Restriction_Warnings (R) := True;
3604 Restriction_Warnings (R) := False;
3608 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
3611 Check_Ada_83_Warning;
3612 Check_At_Least_N_Arguments (1);
3613 Check_Valid_Configuration_Pragma;
3616 while Present (Arg) loop
3618 Expr := Expression (Arg);
3620 -- Case of no restriction identifier present
3622 if Id = No_Name then
3623 if Nkind (Expr) /= N_Identifier then
3625 ("invalid form for restriction", Arg);
3630 (Process_Restriction_Synonyms (Expr));
3632 if R_Id not in All_Boolean_Restrictions then
3634 ("invalid restriction identifier", Arg);
3637 if Implementation_Restriction (R_Id) then
3639 (No_Implementation_Restrictions, Arg);
3642 Set_Restriction (R_Id, N);
3645 -- A very special case that must be processed here:
3646 -- pragma Restrictions (No_Exceptions) turns off
3647 -- all run-time checking. This is a bit dubious in
3648 -- terms of the formal language definition, but it
3649 -- is what is intended by RM H.4(12).
3651 if R_Id = No_Exceptions then
3652 Scope_Suppress := (others => True);
3655 -- Case of No_Dependence => unit-name. Note that the parser
3656 -- already made the necessary entry in the No_Dependence table.
3658 elsif Id = Name_No_Dependence then
3659 Check_Unit_Name (Expr);
3661 -- All other cases of restriction identifier present
3664 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
3665 Analyze_And_Resolve (Expr, Any_Integer);
3667 if R_Id not in All_Parameter_Restrictions then
3669 ("invalid restriction parameter identifier", Arg);
3671 elsif not Is_OK_Static_Expression (Expr) then
3672 Flag_Non_Static_Expr
3673 ("value must be static expression!", Expr);
3676 elsif not Is_Integer_Type (Etype (Expr))
3677 or else Expr_Value (Expr) < 0
3680 ("value must be non-negative integer", Arg);
3682 -- Restriction pragma is active
3685 Val := Expr_Value (Expr);
3687 if not UI_Is_In_Int_Range (Val) then
3689 ("pragma ignored, value too large?", Arg);
3691 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
3699 end Process_Restrictions_Or_Restriction_Warnings;
3701 ---------------------------------
3702 -- Process_Suppress_Unsuppress --
3703 ---------------------------------
3705 -- Note: this procedure makes entries in the check suppress data
3706 -- structures managed by Sem. See spec of package Sem for full
3707 -- details on how we handle recording of check suppression.
3709 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3714 In_Package_Spec : constant Boolean :=
3715 (Ekind (Current_Scope) = E_Package
3717 Ekind (Current_Scope) = E_Generic_Package)
3718 and then not In_Package_Body (Current_Scope);
3720 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3721 -- Used to suppress a single check on the given entity
3723 --------------------------------
3724 -- Suppress_Unsuppress_Echeck --
3725 --------------------------------
3727 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3728 ESR : constant Entity_Check_Suppress_Record :=
3731 Suppress => Suppress_Case);
3734 Set_Checks_May_Be_Suppressed (E);
3736 if In_Package_Spec then
3737 Global_Entity_Suppress.Append (ESR);
3739 Local_Entity_Suppress.Append (ESR);
3742 -- If this is a first subtype, and the base type is distinct,
3743 -- then also set the suppress flags on the base type.
3745 if Is_First_Subtype (E)
3746 and then Etype (E) /= E
3748 Suppress_Unsuppress_Echeck (Etype (E), C);
3750 end Suppress_Unsuppress_Echeck;
3752 -- Start of processing for Process_Suppress_Unsuppress
3755 -- Suppress/Unsuppress can appear as a configuration pragma,
3756 -- or in a declarative part or a package spec (RM 11.5(5))
3758 if not Is_Configuration_Pragma then
3759 Check_Is_In_Decl_Part_Or_Package_Spec;
3762 Check_At_Least_N_Arguments (1);
3763 Check_At_Most_N_Arguments (2);
3764 Check_No_Identifier (Arg1);
3765 Check_Arg_Is_Identifier (Arg1);
3767 if not Is_Check_Name (Chars (Expression (Arg1))) then
3769 ("argument of pragma% is not valid check name", Arg1);
3771 C := Get_Check_Id (Chars (Expression (Arg1)));
3774 if Arg_Count = 1 then
3776 -- Make an entry in the local scope suppress table. This is the
3777 -- table that directly shows the current value of the scope
3778 -- suppress check for any check id value.
3780 if C = All_Checks then
3781 for J in Scope_Suppress'Range loop
3782 Scope_Suppress (J) := Suppress_Case;
3785 Scope_Suppress (C) := Suppress_Case;
3788 -- Also make an entry in the Local_Entity_Suppress table. See
3789 -- extended description in the package spec of Sem for details.
3791 Local_Entity_Suppress.Append
3794 Suppress => Suppress_Case));
3796 -- Case of two arguments present, where the check is
3797 -- suppressed for a specified entity (given as the second
3798 -- argument of the pragma)
3801 Check_Optional_Identifier (Arg2, Name_On);
3802 E_Id := Expression (Arg2);
3805 if not Is_Entity_Name (E_Id) then
3807 ("second argument of pragma% must be entity name", Arg2);
3816 -- Enforce RM 11.5(7) which requires that for a pragma that
3817 -- appears within a package spec, the named entity must be
3818 -- within the package spec. We allow the package name itself
3819 -- to be mentioned since that makes sense, although it is not
3820 -- strictly allowed by 11.5(7).
3823 and then E /= Current_Scope
3824 and then Scope (E) /= Current_Scope
3827 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3831 -- Loop through homonyms. As noted below, in the case of a package
3832 -- spec, only homonyms within the package spec are considered.
3835 Suppress_Unsuppress_Echeck (E, C);
3837 if Is_Generic_Instance (E)
3838 and then Is_Subprogram (E)
3839 and then Present (Alias (E))
3841 Suppress_Unsuppress_Echeck (Alias (E), C);
3844 -- Move to next homonym
3849 -- If we are within a package specification, the
3850 -- pragma only applies to homonyms in the same scope.
3852 exit when In_Package_Spec
3853 and then Scope (E) /= Current_Scope;
3856 end Process_Suppress_Unsuppress;
3862 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3864 if Is_Imported (E) then
3866 ("cannot export entity& that was previously imported", Arg);
3868 elsif Present (Address_Clause (E)) then
3870 ("cannot export entity& that has an address clause", Arg);
3873 Set_Is_Exported (E);
3875 -- Generate a reference for entity explicitly, because the
3876 -- identifier may be overloaded and name resolution will not
3879 Generate_Reference (E, Arg);
3881 -- Deal with exporting non-library level entity
3883 if not Is_Library_Level_Entity (E) then
3885 -- Not allowed at all for subprograms
3887 if Is_Subprogram (E) then
3888 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3890 -- Otherwise set public and statically allocated
3894 Set_Is_Statically_Allocated (E);
3896 -- Warn if the corresponding W flag is set and the pragma
3897 -- comes from source. The latter may not be true e.g. on
3898 -- VMS where we expand export pragmas for exception codes
3899 -- associated with imported or exported exceptions. We do
3900 -- not want to generate a warning for something that the
3901 -- user did not write.
3903 if Warn_On_Export_Import
3904 and then Comes_From_Source (Arg)
3907 ("?& has been made static as a result of Export", Arg, E);
3909 ("\this usage is non-standard and non-portable", Arg);
3914 if Warn_On_Export_Import and then Is_Type (E) then
3916 ("exporting a type has no effect?", Arg, E);
3919 if Warn_On_Export_Import and Inside_A_Generic then
3921 ("all instances of& will have the same external name?", Arg, E);
3925 ----------------------------------------------
3926 -- Set_Extended_Import_Export_External_Name --
3927 ----------------------------------------------
3929 procedure Set_Extended_Import_Export_External_Name
3930 (Internal_Ent : Entity_Id;
3931 Arg_External : Node_Id)
3933 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3937 if No (Arg_External) then
3941 Check_Arg_Is_External_Name (Arg_External);
3943 if Nkind (Arg_External) = N_String_Literal then
3944 if String_Length (Strval (Arg_External)) = 0 then
3947 New_Name := Adjust_External_Name_Case (Arg_External);
3950 elsif Nkind (Arg_External) = N_Identifier then
3951 New_Name := Get_Default_External_Name (Arg_External);
3953 -- Check_Arg_Is_External_Name should let through only
3954 -- identifiers and string literals or static string
3955 -- expressions (which are folded to string literals).
3958 raise Program_Error;
3961 -- If we already have an external name set (by a prior normal
3962 -- Import or Export pragma), then the external names must match
3964 if Present (Interface_Name (Internal_Ent)) then
3965 Check_Matching_Internal_Names : declare
3966 S1 : constant String_Id := Strval (Old_Name);
3967 S2 : constant String_Id := Strval (New_Name);
3970 -- Called if names do not match
3976 procedure Mismatch is
3978 Error_Msg_Sloc := Sloc (Old_Name);
3980 ("external name does not match that given #",
3984 -- Start of processing for Check_Matching_Internal_Names
3987 if String_Length (S1) /= String_Length (S2) then
3991 for J in 1 .. String_Length (S1) loop
3992 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3997 end Check_Matching_Internal_Names;
3999 -- Otherwise set the given name
4002 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4003 Check_Duplicated_Export_Name (New_Name);
4005 end Set_Extended_Import_Export_External_Name;
4011 procedure Set_Imported (E : Entity_Id) is
4013 Error_Msg_Sloc := Sloc (E);
4015 if Is_Exported (E) or else Is_Imported (E) then
4016 Error_Msg_NE ("import of& declared# not allowed", N, E);
4018 if Is_Exported (E) then
4019 Error_Msg_N ("\entity was previously exported", N);
4021 Error_Msg_N ("\entity was previously imported", N);
4024 Error_Pragma ("\(pragma% applies to all previous entities)");
4027 Set_Is_Imported (E);
4029 -- If the entity is an object that is not at the library
4030 -- level, then it is statically allocated. We do not worry
4031 -- about objects with address clauses in this context since
4032 -- they are not really imported in the linker sense.
4035 and then not Is_Library_Level_Entity (E)
4036 and then No (Address_Clause (E))
4038 Set_Is_Statically_Allocated (E);
4043 -------------------------
4044 -- Set_Mechanism_Value --
4045 -------------------------
4047 -- Note: the mechanism name has not been analyzed (and cannot indeed
4048 -- be analyzed, since it is semantic nonsense), so we get it in the
4049 -- exact form created by the parser.
4051 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4055 procedure Bad_Class;
4056 -- Signal bad descriptor class name
4058 procedure Bad_Mechanism;
4059 -- Signal bad mechanism name
4065 procedure Bad_Class is
4067 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4070 -------------------------
4071 -- Bad_Mechanism_Value --
4072 -------------------------
4074 procedure Bad_Mechanism is
4076 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4079 -- Start of processing for Set_Mechanism_Value
4082 if Mechanism (Ent) /= Default_Mechanism then
4084 ("mechanism for & has already been set", Mech_Name, Ent);
4087 -- MECHANISM_NAME ::= value | reference | descriptor
4089 if Nkind (Mech_Name) = N_Identifier then
4090 if Chars (Mech_Name) = Name_Value then
4091 Set_Mechanism (Ent, By_Copy);
4094 elsif Chars (Mech_Name) = Name_Reference then
4095 Set_Mechanism (Ent, By_Reference);
4098 elsif Chars (Mech_Name) = Name_Descriptor then
4099 Check_VMS (Mech_Name);
4100 Set_Mechanism (Ent, By_Descriptor);
4103 elsif Chars (Mech_Name) = Name_Copy then
4105 ("bad mechanism name, Value assumed", Mech_Name);
4111 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
4112 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4114 -- Note: this form is parsed as an indexed component
4116 elsif Nkind (Mech_Name) = N_Indexed_Component then
4117 Class := First (Expressions (Mech_Name));
4119 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4120 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4121 or else Present (Next (Class))
4126 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4127 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4129 -- Note: this form is parsed as a function call
4131 elsif Nkind (Mech_Name) = N_Function_Call then
4133 Param := First (Parameter_Associations (Mech_Name));
4135 if Nkind (Name (Mech_Name)) /= N_Identifier
4136 or else Chars (Name (Mech_Name)) /= Name_Descriptor
4137 or else Present (Next (Param))
4138 or else No (Selector_Name (Param))
4139 or else Chars (Selector_Name (Param)) /= Name_Class
4143 Class := Explicit_Actual_Parameter (Param);
4150 -- Fall through here with Class set to descriptor class name
4152 Check_VMS (Mech_Name);
4154 if Nkind (Class) /= N_Identifier then
4157 elsif Chars (Class) = Name_UBS then
4158 Set_Mechanism (Ent, By_Descriptor_UBS);
4160 elsif Chars (Class) = Name_UBSB then
4161 Set_Mechanism (Ent, By_Descriptor_UBSB);
4163 elsif Chars (Class) = Name_UBA then
4164 Set_Mechanism (Ent, By_Descriptor_UBA);
4166 elsif Chars (Class) = Name_S then
4167 Set_Mechanism (Ent, By_Descriptor_S);
4169 elsif Chars (Class) = Name_SB then
4170 Set_Mechanism (Ent, By_Descriptor_SB);
4172 elsif Chars (Class) = Name_A then
4173 Set_Mechanism (Ent, By_Descriptor_A);
4175 elsif Chars (Class) = Name_NCA then
4176 Set_Mechanism (Ent, By_Descriptor_NCA);
4181 end Set_Mechanism_Value;
4183 ---------------------------
4184 -- Set_Ravenscar_Profile --
4185 ---------------------------
4187 -- The tasks to be done here are
4189 -- Set required policies
4191 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4192 -- pragma Locking_Policy (Ceiling_Locking)
4194 -- Set Detect_Blocking mode
4196 -- Set required restrictions (see System.Rident for detailed list)
4198 procedure Set_Ravenscar_Profile (N : Node_Id) is
4200 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4202 if Task_Dispatching_Policy /= ' '
4203 and then Task_Dispatching_Policy /= 'F'
4205 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4206 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4208 -- Set the FIFO_Within_Priorities policy, but always
4209 -- preserve System_Location since we like the error
4210 -- message with the run time name.
4213 Task_Dispatching_Policy := 'F';
4215 if Task_Dispatching_Policy_Sloc /= System_Location then
4216 Task_Dispatching_Policy_Sloc := Loc;
4220 -- pragma Locking_Policy (Ceiling_Locking)
4222 if Locking_Policy /= ' '
4223 and then Locking_Policy /= 'C'
4225 Error_Msg_Sloc := Locking_Policy_Sloc;
4226 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4228 -- Set the Ceiling_Locking policy, but always preserve
4229 -- System_Location since we like the error message with the
4233 Locking_Policy := 'C';
4235 if Locking_Policy_Sloc /= System_Location then
4236 Locking_Policy_Sloc := Loc;
4240 -- pragma Detect_Blocking
4242 Detect_Blocking := True;
4244 -- Set the corresponding restrictions
4246 Set_Profile_Restrictions (Ravenscar, N, Warn => False);
4247 end Set_Ravenscar_Profile;
4249 -- Start of processing for Analyze_Pragma
4252 if not Is_Pragma_Name (Chars (N)) then
4253 if Warn_On_Unrecognized_Pragma then
4254 Error_Pragma ("unrecognized pragma%!?");
4259 Prag_Id := Get_Pragma_Id (Chars (N));
4269 if Present (Pragma_Argument_Associations (N)) then
4270 Arg1 := First (Pragma_Argument_Associations (N));
4272 if Present (Arg1) then
4273 Arg2 := Next (Arg1);
4275 if Present (Arg2) then
4276 Arg3 := Next (Arg2);
4278 if Present (Arg3) then
4279 Arg4 := Next (Arg3);
4285 -- Count number of arguments
4292 while Present (Arg_Node) loop
4293 Arg_Count := Arg_Count + 1;
4298 -- An enumeration type defines the pragmas that are supported by the
4299 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
4300 -- into the corresponding enumeration value for the following case.
4308 -- pragma Abort_Defer;
4310 when Pragma_Abort_Defer =>
4312 Check_Arg_Count (0);
4314 -- The only required semantic processing is to check the
4315 -- placement. This pragma must appear at the start of the
4316 -- statement sequence of a handled sequence of statements.
4318 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4319 or else N /= First (Statements (Parent (N)))
4330 -- Note: this pragma also has some specific processing in Par.Prag
4331 -- because we want to set the Ada version mode during parsing.
4333 when Pragma_Ada_83 =>
4335 Ada_Version := Ada_83;
4336 Ada_Version_Explicit := Ada_Version;
4337 Check_Arg_Count (0);
4345 -- Note: this pragma also has some specific processing in Par.Prag
4346 -- because we want to set the Ada 83 version mode during parsing.
4348 when Pragma_Ada_95 =>
4350 Ada_Version := Ada_95;
4351 Ada_Version_Explicit := Ada_Version;
4352 Check_Arg_Count (0);
4359 -- pragma Ada_05 (LOCAL_NAME);
4361 -- Note: this pragma also has some specific processing in Par.Prag
4362 -- because we want to set the Ada 2005 version mode during parsing.
4364 when Pragma_Ada_05 => declare
4370 if Arg_Count = 1 then
4371 Check_Arg_Is_Local_Name (Arg1);
4372 E_Id := Expression (Arg1);
4374 if Etype (E_Id) = Any_Type then
4378 Set_Is_Ada_2005 (Entity (E_Id));
4381 Check_Arg_Count (0);
4382 Ada_Version := Ada_05;
4383 Ada_Version_Explicit := Ada_Version;
4387 ----------------------
4388 -- All_Calls_Remote --
4389 ----------------------
4391 -- pragma All_Calls_Remote [(library_package_NAME)];
4393 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
4394 Lib_Entity : Entity_Id;
4397 Check_Ada_83_Warning;
4398 Check_Valid_Library_Unit_Pragma;
4400 if Nkind (N) = N_Null_Statement then
4404 Lib_Entity := Find_Lib_Unit_Name;
4406 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
4408 if Present (Lib_Entity)
4409 and then not Debug_Flag_U
4411 if not Is_Remote_Call_Interface (Lib_Entity) then
4412 Error_Pragma ("pragma% only apply to rci unit");
4414 -- Set flag for entity of the library unit
4417 Set_Has_All_Calls_Remote (Lib_Entity);
4421 end All_Calls_Remote;
4427 -- pragma Annotate (IDENTIFIER {, ARG});
4428 -- ARG ::= NAME | EXPRESSION
4430 when Pragma_Annotate => Annotate : begin
4432 Check_At_Least_N_Arguments (1);
4433 Check_Arg_Is_Identifier (Arg1);
4436 Arg : Node_Id := Arg2;
4440 while Present (Arg) loop
4441 Exp := Expression (Arg);
4444 if Is_Entity_Name (Exp) then
4447 elsif Nkind (Exp) = N_String_Literal then
4448 Resolve (Exp, Standard_String);
4450 elsif Is_Overloaded (Exp) then
4451 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
4466 -- pragma Assert ([Check =>] Boolean_EXPRESSION
4467 -- [, [Message =>] Static_String_EXPRESSION]);
4469 when Pragma_Assert =>
4470 Check_At_Least_N_Arguments (1);
4471 Check_At_Most_N_Arguments (2);
4472 Check_Arg_Order ((Name_Check, Name_Message));
4473 Check_Optional_Identifier (Arg1, Name_Check);
4475 if Arg_Count > 1 then
4476 Check_Optional_Identifier (Arg2, Name_Message);
4477 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4480 -- If expansion is active and assertions are inactive, then
4481 -- we rewrite the Assertion as:
4483 -- if False and then condition then
4487 -- The reason we do this rewriting during semantic analysis
4488 -- rather than as part of normal expansion is that we cannot
4489 -- analyze and expand the code for the boolean expression
4490 -- directly, or it may cause insertion of actions that would
4491 -- escape the attempt to suppress the assertion code.
4493 if Expander_Active and not Assertions_Enabled then
4495 Make_If_Statement (Loc,
4498 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
4499 Right_Opnd => Get_Pragma_Arg (Arg1)),
4500 Then_Statements => New_List (
4501 Make_Null_Statement (Loc))));
4505 -- Otherwise (if assertions are enabled, or if we are not
4506 -- operating with expansion active), then we just analyze
4507 -- and resolve the expression.
4510 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
4513 ----------------------
4514 -- Assertion_Policy --
4515 ----------------------
4517 -- pragma Assertion_Policy (Check | Ignore)
4519 when Pragma_Assertion_Policy =>
4520 Check_Arg_Count (1);
4521 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
4522 Assertions_Enabled := Chars (Expression (Arg1)) = Name_Check;
4528 -- pragma AST_Entry (entry_IDENTIFIER);
4530 when Pragma_AST_Entry => AST_Entry : declare
4536 Check_Arg_Count (1);
4537 Check_No_Identifiers;
4538 Check_Arg_Is_Local_Name (Arg1);
4539 Ent := Entity (Expression (Arg1));
4541 -- Note: the implementation of the AST_Entry pragma could handle
4542 -- the entry family case fine, but for now we are consistent with
4543 -- the DEC rules, and do not allow the pragma, which of course
4544 -- has the effect of also forbidding the attribute.
4546 if Ekind (Ent) /= E_Entry then
4548 ("pragma% argument must be simple entry name", Arg1);
4550 elsif Is_AST_Entry (Ent) then
4552 ("duplicate % pragma for entry", Arg1);
4554 elsif Has_Homonym (Ent) then
4556 ("pragma% argument cannot specify overloaded entry", Arg1);
4560 FF : constant Entity_Id := First_Formal (Ent);
4563 if Present (FF) then
4564 if Present (Next_Formal (FF)) then
4566 ("entry for pragma% can have only one argument",
4569 elsif Parameter_Mode (FF) /= E_In_Parameter then
4571 ("entry parameter for pragma% must have mode IN",
4577 Set_Is_AST_Entry (Ent);
4585 -- pragma Asynchronous (LOCAL_NAME);
4587 when Pragma_Asynchronous => Asynchronous : declare
4595 procedure Process_Async_Pragma;
4596 -- Common processing for procedure and access-to-procedure case
4598 --------------------------
4599 -- Process_Async_Pragma --
4600 --------------------------
4602 procedure Process_Async_Pragma is
4604 if not Present (L) then
4605 Set_Is_Asynchronous (Nm);
4609 -- The formals should be of mode IN (RM E.4.1(6))
4612 while Present (S) loop
4613 Formal := Defining_Identifier (S);
4615 if Nkind (Formal) = N_Defining_Identifier
4616 and then Ekind (Formal) /= E_In_Parameter
4619 ("pragma% procedure can only have IN parameter",
4626 Set_Is_Asynchronous (Nm);
4627 end Process_Async_Pragma;
4629 -- Start of processing for pragma Asynchronous
4632 Check_Ada_83_Warning;
4633 Check_No_Identifiers;
4634 Check_Arg_Count (1);
4635 Check_Arg_Is_Local_Name (Arg1);
4637 if Debug_Flag_U then
4641 C_Ent := Cunit_Entity (Current_Sem_Unit);
4642 Analyze (Expression (Arg1));
4643 Nm := Entity (Expression (Arg1));
4645 if not Is_Remote_Call_Interface (C_Ent)
4646 and then not Is_Remote_Types (C_Ent)
4648 -- This pragma should only appear in an RCI or Remote Types
4649 -- unit (RM E.4.1(4))
4652 ("pragma% not in Remote_Call_Interface or " &
4653 "Remote_Types unit");
4656 if Ekind (Nm) = E_Procedure
4657 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4659 if not Is_Remote_Call_Interface (Nm) then
4661 ("pragma% cannot be applied on non-remote procedure",
4665 L := Parameter_Specifications (Parent (Nm));
4666 Process_Async_Pragma;
4669 elsif Ekind (Nm) = E_Function then
4671 ("pragma% cannot be applied to function", Arg1);
4673 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
4675 if Is_Record_Type (Nm) then
4676 -- A record type that is the Equivalent_Type for
4677 -- a remote access-to-subprogram type.
4679 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4682 -- A non-expanded RAS type (case where distribution is
4685 N := Declaration_Node (Nm);
4688 if Nkind (N) = N_Full_Type_Declaration
4689 and then Nkind (Type_Definition (N)) =
4690 N_Access_Procedure_Definition
4692 L := Parameter_Specifications (Type_Definition (N));
4693 Process_Async_Pragma;
4695 if Is_Asynchronous (Nm)
4696 and then Expander_Active
4697 and then Get_PCS_Name /= Name_No_DSA
4699 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
4704 ("pragma% cannot reference access-to-function type",
4708 -- Only other possibility is Access-to-class-wide type
4710 elsif Is_Access_Type (Nm)
4711 and then Is_Class_Wide_Type (Designated_Type (Nm))
4713 Check_First_Subtype (Arg1);
4714 Set_Is_Asynchronous (Nm);
4715 if Expander_Active then
4716 RACW_Type_Is_Asynchronous (Nm);
4720 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4728 -- pragma Atomic (LOCAL_NAME);
4730 when Pragma_Atomic =>
4731 Process_Atomic_Shared_Volatile;
4733 -----------------------
4734 -- Atomic_Components --
4735 -----------------------
4737 -- pragma Atomic_Components (array_LOCAL_NAME);
4739 -- This processing is shared by Volatile_Components
4741 when Pragma_Atomic_Components |
4742 Pragma_Volatile_Components =>
4744 Atomic_Components : declare
4751 Check_Ada_83_Warning;
4752 Check_No_Identifiers;
4753 Check_Arg_Count (1);
4754 Check_Arg_Is_Local_Name (Arg1);
4755 E_Id := Expression (Arg1);
4757 if Etype (E_Id) = Any_Type then
4763 if Rep_Item_Too_Early (E, N)
4765 Rep_Item_Too_Late (E, N)
4770 D := Declaration_Node (E);
4773 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4775 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4776 and then Nkind (D) = N_Object_Declaration
4777 and then Nkind (Object_Definition (D)) =
4778 N_Constrained_Array_Definition)
4780 -- The flag is set on the object, or on the base type
4782 if Nkind (D) /= N_Object_Declaration then
4786 Set_Has_Volatile_Components (E);
4788 if Prag_Id = Pragma_Atomic_Components then
4789 Set_Has_Atomic_Components (E);
4791 if Is_Packed (E) then
4792 Set_Is_Packed (E, False);
4795 ("?Pack canceled, cannot pack atomic components",
4801 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4803 end Atomic_Components;
4805 --------------------
4806 -- Attach_Handler --
4807 --------------------
4809 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4811 when Pragma_Attach_Handler =>
4812 Check_Ada_83_Warning;
4813 Check_No_Identifiers;
4814 Check_Arg_Count (2);
4816 if No_Run_Time_Mode then
4817 Error_Msg_CRT ("Attach_Handler pragma", N);
4819 Check_Interrupt_Or_Attach_Handler;
4821 -- The expression that designates the attribute may
4822 -- depend on a discriminant, and is therefore a per-
4823 -- object expression, to be expanded in the init proc.
4824 -- If expansion is enabled, perform semantic checks
4827 if Expander_Active then
4829 Temp : constant Node_Id :=
4830 New_Copy_Tree (Expression (Arg2));
4832 Set_Parent (Temp, N);
4833 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4837 Analyze (Expression (Arg2));
4838 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4841 Process_Interrupt_Or_Attach_Handler;
4844 --------------------
4845 -- C_Pass_By_Copy --
4846 --------------------
4848 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4850 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4856 Check_Valid_Configuration_Pragma;
4857 Check_Arg_Count (1);
4858 Check_Optional_Identifier (Arg1, "max_size");
4860 Arg := Expression (Arg1);
4861 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4863 Val := Expr_Value (Arg);
4867 ("maximum size for pragma% must be positive", Arg1);
4869 elsif UI_Is_In_Int_Range (Val) then
4870 Default_C_Record_Mechanism := UI_To_Int (Val);
4872 -- If a giant value is given, Int'Last will do well enough.
4873 -- If sometime someone complains that a record larger than
4874 -- two gigabytes is not copied, we will worry about it then!
4877 Default_C_Record_Mechanism := Mechanism_Type'Last;
4885 -- pragma Comment (static_string_EXPRESSION)
4887 -- Processing for pragma Comment shares the circuitry for
4888 -- pragma Ident. The only differences are that Ident enforces
4889 -- a limit of 31 characters on its argument, and also enforces
4890 -- limitations on placement for DEC compatibility. Pragma
4891 -- Comment shares neither of these restrictions.
4897 -- pragma Common_Object (
4898 -- [Internal =>] LOCAL_NAME,
4899 -- [, [External =>] EXTERNAL_SYMBOL]
4900 -- [, [Size =>] EXTERNAL_SYMBOL]);
4902 -- Processing for this pragma is shared with Psect_Object
4904 --------------------------
4905 -- Compile_Time_Warning --
4906 --------------------------
4908 -- pragma Compile_Time_Warning
4909 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4911 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4912 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4916 Check_Arg_Count (2);
4917 Check_No_Identifiers;
4918 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4919 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4921 if Compile_Time_Known_Value (Arg1x) then
4922 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4923 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4924 Add_Char_To_Name_Buffer ('?');
4927 Msg : String (1 .. Name_Len) :=
4928 Name_Buffer (1 .. Name_Len);
4933 -- This loop looks for multiple lines separated by
4934 -- ASCII.LF and breaks them into continuation error
4935 -- messages marked with the usual back slash.
4938 for S in 2 .. Msg'Length - 1 loop
4939 if Msg (S) = ASCII.LF then
4941 Error_Msg_N (Msg (B .. S), Arg1);
4947 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4951 end Compile_Time_Warning;
4953 ----------------------------
4954 -- Complex_Representation --
4955 ----------------------------
4957 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4959 when Pragma_Complex_Representation => Complex_Representation : declare
4966 Check_Arg_Count (1);
4967 Check_Optional_Identifier (Arg1, Name_Entity);
4968 Check_Arg_Is_Local_Name (Arg1);
4969 E_Id := Expression (Arg1);
4971 if Etype (E_Id) = Any_Type then
4977 if not Is_Record_Type (E) then
4979 ("argument for pragma% must be record type", Arg1);
4982 Ent := First_Entity (E);
4985 or else No (Next_Entity (Ent))
4986 or else Present (Next_Entity (Next_Entity (Ent)))
4987 or else not Is_Floating_Point_Type (Etype (Ent))
4988 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4991 ("record for pragma% must have two fields of same fpt type",
4995 Set_Has_Complex_Representation (Base_Type (E));
4997 end Complex_Representation;
4999 -------------------------
5000 -- Component_Alignment --
5001 -------------------------
5003 -- pragma Component_Alignment (
5004 -- [Form =>] ALIGNMENT_CHOICE
5005 -- [, [Name =>] type_LOCAL_NAME]);
5007 -- ALIGNMENT_CHOICE ::=
5009 -- | Component_Size_4
5013 when Pragma_Component_Alignment => Component_AlignmentP : declare
5014 Args : Args_List (1 .. 2);
5015 Names : constant Name_List (1 .. 2) := (
5019 Form : Node_Id renames Args (1);
5020 Name : Node_Id renames Args (2);
5022 Atype : Component_Alignment_Kind;
5027 Gather_Associations (Names, Args);
5030 Error_Pragma ("missing Form argument for pragma%");
5033 Check_Arg_Is_Identifier (Form);
5035 -- Get proper alignment, note that Default = Component_Size
5036 -- on all machines we have so far, and we want to set this
5037 -- value rather than the default value to indicate that it
5038 -- has been explicitly set (and thus will not get overridden
5039 -- by the default component alignment for the current scope)
5041 if Chars (Form) = Name_Component_Size then
5042 Atype := Calign_Component_Size;
5044 elsif Chars (Form) = Name_Component_Size_4 then
5045 Atype := Calign_Component_Size_4;
5047 elsif Chars (Form) = Name_Default then
5048 Atype := Calign_Component_Size;
5050 elsif Chars (Form) = Name_Storage_Unit then
5051 Atype := Calign_Storage_Unit;
5055 ("invalid Form parameter for pragma%", Form);
5058 -- Case with no name, supplied, affects scope table entry
5062 (Scope_Stack.Last).Component_Alignment_Default := Atype;
5064 -- Case of name supplied
5067 Check_Arg_Is_Local_Name (Name);
5069 Typ := Entity (Name);
5072 or else Rep_Item_Too_Early (Typ, N)
5076 Typ := Underlying_Type (Typ);
5079 if not Is_Record_Type (Typ)
5080 and then not Is_Array_Type (Typ)
5083 ("Name parameter of pragma% must identify record or " &
5084 "array type", Name);
5087 -- An explicit Component_Alignment pragma overrides an
5088 -- implicit pragma Pack, but not an explicit one.
5090 if not Has_Pragma_Pack (Base_Type (Typ)) then
5091 Set_Is_Packed (Base_Type (Typ), False);
5092 Set_Component_Alignment (Base_Type (Typ), Atype);
5095 end Component_AlignmentP;
5101 -- pragma Controlled (first_subtype_LOCAL_NAME);
5103 when Pragma_Controlled => Controlled : declare
5107 Check_No_Identifiers;
5108 Check_Arg_Count (1);
5109 Check_Arg_Is_Local_Name (Arg1);
5110 Arg := Expression (Arg1);
5112 if not Is_Entity_Name (Arg)
5113 or else not Is_Access_Type (Entity (Arg))
5115 Error_Pragma_Arg ("pragma% requires access type", Arg1);
5117 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5125 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
5126 -- [Entity =>] LOCAL_NAME);
5128 when Pragma_Convention => Convention : declare
5132 Check_Arg_Order ((Name_Convention, Name_Entity));
5133 Check_Ada_83_Warning;
5134 Check_Arg_Count (2);
5135 Process_Convention (C, E);
5138 ---------------------------
5139 -- Convention_Identifier --
5140 ---------------------------
5142 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
5143 -- [Convention =>] convention_IDENTIFIER);
5145 when Pragma_Convention_Identifier => Convention_Identifier : declare
5151 Check_Arg_Order ((Name_Name, Name_Convention));
5152 Check_Arg_Count (2);
5153 Check_Optional_Identifier (Arg1, Name_Name);
5154 Check_Optional_Identifier (Arg2, Name_Convention);
5155 Check_Arg_Is_Identifier (Arg1);
5156 Check_Arg_Is_Identifier (Arg1);
5157 Idnam := Chars (Expression (Arg1));
5158 Cname := Chars (Expression (Arg2));
5160 if Is_Convention_Name (Cname) then
5161 Record_Convention_Identifier
5162 (Idnam, Get_Convention_Id (Cname));
5165 ("second arg for % pragma must be convention", Arg2);
5167 end Convention_Identifier;
5173 -- pragma CPP_Class ([Entity =>] local_NAME)
5175 when Pragma_CPP_Class => CPP_Class : declare
5178 Default_DTC : Entity_Id := Empty;
5179 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5185 Check_Arg_Count (1);
5186 Check_Optional_Identifier (Arg1, Name_Entity);
5187 Check_Arg_Is_Local_Name (Arg1);
5189 Arg := Expression (Arg1);
5192 if Etype (Arg) = Any_Type then
5196 if not Is_Entity_Name (Arg)
5197 or else not Is_Type (Entity (Arg))
5199 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
5202 Typ := Entity (Arg);
5204 if not Is_Record_Type (Typ) then
5205 Error_Pragma_Arg ("pragma% applicable to a record, "
5206 & "tagged record or record extension", Arg1);
5209 Default_DTC := First_Component (Typ);
5210 while Present (Default_DTC)
5211 and then Etype (Default_DTC) /= VTP_Type
5213 Next_Component (Default_DTC);
5216 -- Case of non tagged type
5218 if not Is_Tagged_Type (Typ) then
5219 Set_Is_CPP_Class (Typ);
5221 if Present (Default_DTC) then
5223 ("only tagged records can contain vtable pointers", Arg1);
5226 -- Case of tagged type with no vtable ptr
5228 -- What is test for Typ = Root_Typ (Typ) about here ???
5230 elsif Is_Tagged_Type (Typ)
5231 and then Typ = Root_Type (Typ)
5232 and then No (Default_DTC)
5235 ("a cpp_class must contain a vtable pointer", Arg1);
5237 -- Tagged type that has a vtable ptr
5239 elsif Present (Default_DTC) then
5240 Set_Is_CPP_Class (Typ);
5241 Set_Is_Limited_Record (Typ);
5242 Set_Is_Tag (Default_DTC);
5243 Set_DT_Entry_Count (Default_DTC, No_Uint);
5245 -- Since a CPP type has no direct link to its associated tag
5246 -- most tags checks cannot be performed
5248 Set_Kill_Tag_Checks (Typ);
5249 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
5251 -- Get rid of the _tag component when there was one.
5252 -- It is only useful for regular tagged types
5254 if Expander_Active and then Typ = Root_Type (Typ) then
5256 Tag_C := First_Tag_Component (Typ);
5257 C := First_Entity (Typ);
5260 Set_First_Entity (Typ, Next_Entity (Tag_C));
5263 while Next_Entity (C) /= Tag_C loop
5267 Set_Next_Entity (C, Next_Entity (Tag_C));
5273 ---------------------
5274 -- CPP_Constructor --
5275 ---------------------
5277 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
5279 when Pragma_CPP_Constructor => CPP_Constructor : declare
5285 Check_Arg_Count (1);
5286 Check_Optional_Identifier (Arg1, Name_Entity);
5287 Check_Arg_Is_Local_Name (Arg1);
5289 Id := Expression (Arg1);
5290 Find_Program_Unit_Name (Id);
5292 -- If we did not find the name, we are done
5294 if Etype (Id) = Any_Type then
5298 Def_Id := Entity (Id);
5300 if Ekind (Def_Id) = E_Function
5301 and then Is_Class_Wide_Type (Etype (Def_Id))
5302 and then Is_CPP_Class (Etype (Etype (Def_Id)))
5304 -- What the heck is this??? this pragma allows only 1 arg
5306 if Arg_Count >= 2 then
5307 Check_At_Most_N_Arguments (3);
5308 Process_Interface_Name (Def_Id, Arg2, Arg3);
5311 if No (Parameter_Specifications (Parent (Def_Id))) then
5312 Set_Has_Completion (Def_Id);
5313 Set_Is_Constructor (Def_Id);
5316 ("non-default constructors not implemented", Arg1);
5321 ("pragma% requires function returning a 'C'P'P_Class type",
5324 end CPP_Constructor;
5330 -- pragma CPP_Virtual
5331 -- [Entity =>] LOCAL_NAME
5332 -- [ [Vtable_Ptr =>] LOCAL_NAME,
5333 -- [Position =>] static_integer_EXPRESSION]);
5335 when Pragma_CPP_Virtual => CPP_Virtual : declare
5339 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5345 Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Position));
5347 if Arg_Count = 3 then
5348 Check_Optional_Identifier (Arg2, Name_Vtable_Ptr);
5350 -- We allow Entry_Count as well as Position for the third
5351 -- parameter for back compatibility with versions of GNAT
5352 -- before version 3.12. The documentation has always said
5353 -- Position, but the code up to 3.12 said Entry_Count.
5355 if Chars (Arg3) /= Name_Entry_Count then
5356 Check_Optional_Identifier (Arg3, Name_Position);
5360 Check_Arg_Count (1);
5363 Check_Optional_Identifier (Arg1, Name_Entity);
5364 Check_Arg_Is_Local_Name (Arg1);
5366 -- First argument must be a subprogram name
5368 Arg := Expression (Arg1);
5369 Find_Program_Unit_Name (Arg);
5371 if Etype (Arg) = Any_Type then
5374 Subp := Entity (Arg);
5377 if not (Is_Subprogram (Subp)
5378 and then Is_Dispatching_Operation (Subp))
5381 ("pragma% must reference a primitive operation", Arg1);
5384 Typ := Find_Dispatching_Type (Subp);
5386 -- If only one Argument defaults are :
5387 -- . DTC_Entity is the default Vtable pointer
5388 -- . DT_Position will be set at the freezing point
5390 if Arg_Count = 1 then
5391 Set_DTC_Entity (Subp, First_Tag_Component (Typ));
5395 -- Second argument is a component name of type Vtable_Ptr
5397 Arg := Expression (Arg2);
5399 if Nkind (Arg) /= N_Identifier then
5400 Error_Msg_NE ("must be a& component name", Arg, Typ);
5404 DTC := First_Component (Typ);
5405 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5406 Next_Component (DTC);
5410 Error_Msg_NE ("must be a& component name", Arg, Typ);
5413 elsif Etype (DTC) /= VTP_Type then
5414 Wrong_Type (Arg, VTP_Type);
5418 -- Third argument is an integer (DT_Position)
5420 Arg := Expression (Arg3);
5421 Analyze_And_Resolve (Arg, Any_Integer);
5423 if not Is_Static_Expression (Arg) then
5424 Flag_Non_Static_Expr
5425 ("third argument of pragma CPP_Virtual must be static!",
5430 V := Expr_Value (Expression (Arg3));
5434 ("third argument of pragma% must be positive",
5438 Set_DTC_Entity (Subp, DTC);
5439 Set_DT_Position (Subp, V);
5448 -- pragma CPP_Vtable (
5449 -- [Entity =>] LOCAL_NAME
5450 -- [Vtable_Ptr =>] LOCAL_NAME,
5451 -- [Entry_Count =>] static_integer_EXPRESSION);
5453 when Pragma_CPP_Vtable => CPP_Vtable : declare
5456 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
5463 Check_Arg_Order ((Name_Entity, Name_Vtable_Ptr, Name_Entry_Count));
5464 Check_Arg_Count (3);
5465 Check_Optional_Identifier (Arg1, Name_Entity);
5466 Check_Optional_Identifier (Arg2, Name_Vtable_Ptr);
5467 Check_Optional_Identifier (Arg3, Name_Entry_Count);
5468 Check_Arg_Is_Local_Name (Arg1);
5470 -- First argument is a record type name
5472 Arg := Expression (Arg1);
5475 if Etype (Arg) = Any_Type then
5478 Typ := Entity (Arg);
5481 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
5482 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
5485 -- Second argument is a component name of type Vtable_Ptr
5487 Arg := Expression (Arg2);
5489 if Nkind (Arg) /= N_Identifier then
5490 Error_Msg_NE ("must be a& component name", Arg, Typ);
5494 DTC := First_Component (Typ);
5495 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
5496 Next_Component (DTC);
5500 Error_Msg_NE ("must be a& component name", Arg, Typ);
5503 elsif Etype (DTC) /= VTP_Type then
5504 Wrong_Type (DTC, VTP_Type);
5507 -- If it is the first pragma Vtable, This becomes the default tag
5509 elsif (not Is_Tag (DTC))
5510 and then DT_Entry_Count (First_Tag_Component (Typ)) = No_Uint
5512 Set_Is_Tag (First_Tag_Component (Typ), False);
5513 Set_Is_Tag (DTC, True);
5514 Set_DT_Entry_Count (DTC, No_Uint);
5517 -- Those pragmas must appear before any primitive operation
5518 -- definition (except inherited ones) otherwise the default
5521 Elmt := First_Elmt (Primitive_Operations (Typ));
5522 while Present (Elmt) loop
5523 if No (Alias (Node (Elmt))) then
5524 Error_Msg_Sloc := Sloc (Node (Elmt));
5526 ("pragma% must appear before this primitive operation");
5532 -- Third argument is an integer (DT_Entry_Count)
5534 Arg := Expression (Arg3);
5535 Analyze_And_Resolve (Arg, Any_Integer);
5537 if not Is_Static_Expression (Arg) then
5538 Flag_Non_Static_Expr
5539 ("entry count for pragma CPP_Vtable must be a static " &
5540 "expression!", Arg3);
5544 V := Expr_Value (Expression (Arg3));
5548 ("entry count for pragma% must be positive", Arg3);
5550 Set_DT_Entry_Count (DTC, V);
5559 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
5561 when Pragma_Debug => Debug : begin
5564 -- Rewrite into a conditional with a static condition
5566 Rewrite (N, Make_Implicit_If_Statement (N,
5567 Condition => New_Occurrence_Of (Boolean_Literals (
5568 Assertions_Enabled and Expander_Active), Loc),
5569 Then_Statements => New_List (
5570 Relocate_Node (Debug_Statement (N)))));
5574 ---------------------
5575 -- Detect_Blocking --
5576 ---------------------
5578 -- pragma Detect_Blocking;
5580 when Pragma_Detect_Blocking =>
5582 Check_Arg_Count (0);
5583 Check_Valid_Configuration_Pragma;
5584 Detect_Blocking := True;
5590 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
5592 when Pragma_Discard_Names => Discard_Names : declare
5597 Check_Ada_83_Warning;
5599 -- Deal with configuration pragma case
5601 if Arg_Count = 0 and then Is_Configuration_Pragma then
5602 Global_Discard_Names := True;
5605 -- Otherwise, check correct appropriate context
5608 Check_Is_In_Decl_Part_Or_Package_Spec;
5610 if Arg_Count = 0 then
5612 -- If there is no parameter, then from now on this pragma
5613 -- applies to any enumeration, exception or tagged type
5614 -- defined in the current declarative part.
5616 Set_Discard_Names (Current_Scope);
5620 Check_Arg_Count (1);
5621 Check_Optional_Identifier (Arg1, Name_On);
5622 Check_Arg_Is_Local_Name (Arg1);
5623 E_Id := Expression (Arg1);
5625 if Etype (E_Id) = Any_Type then
5631 if (Is_First_Subtype (E)
5632 and then (Is_Enumeration_Type (E)
5633 or else Is_Tagged_Type (E)))
5634 or else Ekind (E) = E_Exception
5636 Set_Discard_Names (E);
5639 ("inappropriate entity for pragma%", Arg1);
5649 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5651 when Pragma_Elaborate => Elaborate : declare
5653 Parent_Node : Node_Id;
5658 -- Pragma must be in context items list of a compilation unit
5660 if not Is_List_Member (N) then
5665 Plist := List_Containing (N);
5666 Parent_Node := Parent (Plist);
5668 if Parent_Node = Empty
5669 or else Nkind (Parent_Node) /= N_Compilation_Unit
5670 or else Context_Items (Parent_Node) /= Plist
5677 -- Must be at least one argument
5679 if Arg_Count = 0 then
5680 Error_Pragma ("pragma% requires at least one argument");
5683 -- In Ada 83 mode, there can be no items following it in the
5684 -- context list except other pragmas and implicit with clauses
5685 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5686 -- placement rule does not apply.
5688 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5691 while Present (Citem) loop
5692 if Nkind (Citem) = N_Pragma
5693 or else (Nkind (Citem) = N_With_Clause
5694 and then Implicit_With (Citem))
5699 ("(Ada 83) pragma% must be at end of context clause");
5706 -- Finally, the arguments must all be units mentioned in a with
5707 -- clause in the same context clause. Note we already checked
5708 -- (in Par.Prag) that the arguments are either identifiers or
5711 Outer : while Present (Arg) loop
5712 Citem := First (Plist);
5714 Inner : while Citem /= N loop
5715 if Nkind (Citem) = N_With_Clause
5716 and then Same_Name (Name (Citem), Expression (Arg))
5718 Set_Elaborate_Present (Citem, True);
5719 Set_Unit_Name (Expression (Arg), Name (Citem));
5721 -- With the pragma present, elaboration calls on
5722 -- subprograms from the named unit need no further
5723 -- checks, as long as the pragma appears in the current
5724 -- compilation unit. If the pragma appears in some unit
5725 -- in the context, there might still be a need for an
5726 -- Elaborate_All_Desirable from the current compilation
5727 -- to the the named unit, so we keep the check enabled.
5729 if In_Extended_Main_Source_Unit (N) then
5730 Set_Suppress_Elaboration_Warnings
5731 (Entity (Name (Citem)));
5741 ("argument of pragma% is not with'ed unit", Arg);
5747 -- Give a warning if operating in static mode with -gnatwl
5748 -- (elaboration warnings eanbled) switch set.
5750 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5752 ("?use of pragma Elaborate may not be safe", N);
5754 ("?use pragma Elaborate_All instead if possible", N);
5762 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5764 when Pragma_Elaborate_All => Elaborate_All : declare
5766 Parent_Node : Node_Id;
5771 Check_Ada_83_Warning;
5773 -- Pragma must be in context items list of a compilation unit
5775 if not Is_List_Member (N) then
5780 Plist := List_Containing (N);
5781 Parent_Node := Parent (Plist);
5783 if Parent_Node = Empty
5784 or else Nkind (Parent_Node) /= N_Compilation_Unit
5785 or else Context_Items (Parent_Node) /= Plist
5792 -- Must be at least one argument
5794 if Arg_Count = 0 then
5795 Error_Pragma ("pragma% requires at least one argument");
5798 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5799 -- have to appear at the end of the context clause, but may
5800 -- appear mixed in with other items, even in Ada 83 mode.
5802 -- Final check: the arguments must all be units mentioned in
5803 -- a with clause in the same context clause. Note that we
5804 -- already checked (in Par.Prag) that all the arguments are
5805 -- either identifiers or selected components.
5808 Outr : while Present (Arg) loop
5809 Citem := First (Plist);
5811 Innr : while Citem /= N loop
5812 if Nkind (Citem) = N_With_Clause
5813 and then Same_Name (Name (Citem), Expression (Arg))
5815 Set_Elaborate_All_Present (Citem, True);
5816 Set_Unit_Name (Expression (Arg), Name (Citem));
5818 -- Suppress warnings and elaboration checks on the named
5819 -- unit if the pragma is in the current compilation, as
5820 -- for pragma Elaborate.
5822 if In_Extended_Main_Source_Unit (N) then
5823 Set_Suppress_Elaboration_Warnings
5824 (Entity (Name (Citem)));
5833 Set_Error_Posted (N);
5835 ("argument of pragma% is not with'ed unit", Arg);
5842 --------------------
5843 -- Elaborate_Body --
5844 --------------------
5846 -- pragma Elaborate_Body [( library_unit_NAME )];
5848 when Pragma_Elaborate_Body => Elaborate_Body : declare
5849 Cunit_Node : Node_Id;
5850 Cunit_Ent : Entity_Id;
5853 Check_Ada_83_Warning;
5854 Check_Valid_Library_Unit_Pragma;
5856 if Nkind (N) = N_Null_Statement then
5860 Cunit_Node := Cunit (Current_Sem_Unit);
5861 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5863 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5865 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5867 Error_Pragma ("pragma% must refer to a spec, not a body");
5869 Set_Body_Required (Cunit_Node, True);
5870 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5872 -- If we are in dynamic elaboration mode, then we suppress
5873 -- elaboration warnings for the unit, since it is definitely
5874 -- fine NOT to do dynamic checks at the first level (and such
5875 -- checks will be suppressed because no elaboration boolean
5876 -- is created for Elaborate_Body packages).
5878 -- But in the static model of elaboration, Elaborate_Body is
5879 -- definitely NOT good enough to ensure elaboration safety on
5880 -- its own, since the body may WITH other units that are not
5881 -- safe from an elaboration point of view, so a client must
5882 -- still do an Elaborate_All on such units.
5884 -- Debug flag -gnatdD restores the old behavior of 3.13,
5885 -- where Elaborate_Body always suppressed elab warnings.
5887 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5888 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5893 ------------------------
5894 -- Elaboration_Checks --
5895 ------------------------
5897 -- pragma Elaboration_Checks (Static | Dynamic);
5899 when Pragma_Elaboration_Checks =>
5901 Check_Arg_Count (1);
5902 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5903 Dynamic_Elaboration_Checks :=
5904 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5910 -- pragma Eliminate (
5911 -- [Unit_Name =>] IDENTIFIER |
5912 -- SELECTED_COMPONENT
5913 -- [,[Entity =>] IDENTIFIER |
5914 -- SELECTED_COMPONENT |
5916 -- [,]OVERLOADING_RESOLUTION);
5918 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
5921 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
5924 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
5926 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
5927 -- Result_Type => result_SUBTYPE_NAME]
5929 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5930 -- SUBTYPE_NAME ::= STRING_LITERAL
5932 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
5933 -- SOURCE_TRACE ::= STRING_LITERAL
5935 when Pragma_Eliminate => Eliminate : declare
5936 Args : Args_List (1 .. 5);
5937 Names : constant Name_List (1 .. 5) := (
5940 Name_Parameter_Types,
5942 Name_Source_Location);
5944 Unit_Name : Node_Id renames Args (1);
5945 Entity : Node_Id renames Args (2);
5946 Parameter_Types : Node_Id renames Args (3);
5947 Result_Type : Node_Id renames Args (4);
5948 Source_Location : Node_Id renames Args (5);
5952 Check_Valid_Configuration_Pragma;
5953 Gather_Associations (Names, Args);
5955 if No (Unit_Name) then
5956 Error_Pragma ("missing Unit_Name argument for pragma%");
5960 and then (Present (Parameter_Types)
5962 Present (Result_Type)
5964 Present (Source_Location))
5966 Error_Pragma ("missing Entity argument for pragma%");
5969 if (Present (Parameter_Types)
5971 Present (Result_Type))
5973 Present (Source_Location)
5976 ("parameter profile and source location can not " &
5977 "be used together in pragma%");
5980 Process_Eliminate_Pragma
5989 -------------------------
5990 -- Explicit_Overriding --
5991 -------------------------
5993 when Pragma_Explicit_Overriding =>
5994 Check_Valid_Configuration_Pragma;
5995 Check_Arg_Count (0);
5996 Explicit_Overriding := True;
6003 -- [ Convention =>] convention_IDENTIFIER,
6004 -- [ Entity =>] local_NAME
6005 -- [, [External_Name =>] static_string_EXPRESSION ]
6006 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6008 when Pragma_Export => Export : declare
6013 Check_Ada_83_Warning;
6019 Check_At_Least_N_Arguments (2);
6020 Check_At_Most_N_Arguments (4);
6021 Process_Convention (C, Def_Id);
6023 if Ekind (Def_Id) /= E_Constant then
6024 Note_Possible_Modification (Expression (Arg2));
6027 Process_Interface_Name (Def_Id, Arg3, Arg4);
6028 Set_Exported (Def_Id, Arg2);
6031 ----------------------
6032 -- Export_Exception --
6033 ----------------------
6035 -- pragma Export_Exception (
6036 -- [Internal =>] LOCAL_NAME,
6037 -- [, [External =>] EXTERNAL_SYMBOL,]
6038 -- [, [Form =>] Ada | VMS]
6039 -- [, [Code =>] static_integer_EXPRESSION]);
6041 when Pragma_Export_Exception => Export_Exception : declare
6042 Args : Args_List (1 .. 4);
6043 Names : constant Name_List (1 .. 4) := (
6049 Internal : Node_Id renames Args (1);
6050 External : Node_Id renames Args (2);
6051 Form : Node_Id renames Args (3);
6052 Code : Node_Id renames Args (4);
6055 if Inside_A_Generic then
6056 Error_Pragma ("pragma% cannot be used for generic entities");
6059 Gather_Associations (Names, Args);
6060 Process_Extended_Import_Export_Exception_Pragma (
6061 Arg_Internal => Internal,
6062 Arg_External => External,
6066 if not Is_VMS_Exception (Entity (Internal)) then
6067 Set_Exported (Entity (Internal), Internal);
6069 end Export_Exception;
6071 ---------------------
6072 -- Export_Function --
6073 ---------------------
6075 -- pragma Export_Function (
6076 -- [Internal =>] LOCAL_NAME,
6077 -- [, [External =>] EXTERNAL_SYMBOL,]
6078 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6079 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6080 -- [, [Mechanism =>] MECHANISM]
6081 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6083 -- EXTERNAL_SYMBOL ::=
6085 -- | static_string_EXPRESSION
6087 -- PARAMETER_TYPES ::=
6089 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6091 -- TYPE_DESIGNATOR ::=
6093 -- | subtype_Name ' Access
6097 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6099 -- MECHANISM_ASSOCIATION ::=
6100 -- [formal_parameter_NAME =>] MECHANISM_NAME
6102 -- MECHANISM_NAME ::=
6105 -- | Descriptor [([Class =>] CLASS_NAME)]
6107 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6109 when Pragma_Export_Function => Export_Function : declare
6110 Args : Args_List (1 .. 6);
6111 Names : constant Name_List (1 .. 6) := (
6114 Name_Parameter_Types,
6117 Name_Result_Mechanism);
6119 Internal : Node_Id renames Args (1);
6120 External : Node_Id renames Args (2);
6121 Parameter_Types : Node_Id renames Args (3);
6122 Result_Type : Node_Id renames Args (4);
6123 Mechanism : Node_Id renames Args (5);
6124 Result_Mechanism : Node_Id renames Args (6);
6128 Gather_Associations (Names, Args);
6129 Process_Extended_Import_Export_Subprogram_Pragma (
6130 Arg_Internal => Internal,
6131 Arg_External => External,
6132 Arg_Parameter_Types => Parameter_Types,
6133 Arg_Result_Type => Result_Type,
6134 Arg_Mechanism => Mechanism,
6135 Arg_Result_Mechanism => Result_Mechanism);
6136 end Export_Function;
6142 -- pragma Export_Object (
6143 -- [Internal =>] LOCAL_NAME,
6144 -- [, [External =>] EXTERNAL_SYMBOL]
6145 -- [, [Size =>] EXTERNAL_SYMBOL]);
6147 -- EXTERNAL_SYMBOL ::=
6149 -- | static_string_EXPRESSION
6151 -- PARAMETER_TYPES ::=
6153 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6155 -- TYPE_DESIGNATOR ::=
6157 -- | subtype_Name ' Access
6161 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6163 -- MECHANISM_ASSOCIATION ::=
6164 -- [formal_parameter_NAME =>] MECHANISM_NAME
6166 -- MECHANISM_NAME ::=
6169 -- | Descriptor [([Class =>] CLASS_NAME)]
6171 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6173 when Pragma_Export_Object => Export_Object : declare
6174 Args : Args_List (1 .. 3);
6175 Names : constant Name_List (1 .. 3) := (
6180 Internal : Node_Id renames Args (1);
6181 External : Node_Id renames Args (2);
6182 Size : Node_Id renames Args (3);
6186 Gather_Associations (Names, Args);
6187 Process_Extended_Import_Export_Object_Pragma (
6188 Arg_Internal => Internal,
6189 Arg_External => External,
6193 ----------------------
6194 -- Export_Procedure --
6195 ----------------------
6197 -- pragma Export_Procedure (
6198 -- [Internal =>] LOCAL_NAME,
6199 -- [, [External =>] EXTERNAL_SYMBOL,]
6200 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6201 -- [, [Mechanism =>] MECHANISM]);
6203 -- EXTERNAL_SYMBOL ::=
6205 -- | static_string_EXPRESSION
6207 -- PARAMETER_TYPES ::=
6209 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6211 -- TYPE_DESIGNATOR ::=
6213 -- | subtype_Name ' Access
6217 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6219 -- MECHANISM_ASSOCIATION ::=
6220 -- [formal_parameter_NAME =>] MECHANISM_NAME
6222 -- MECHANISM_NAME ::=
6225 -- | Descriptor [([Class =>] CLASS_NAME)]
6227 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6229 when Pragma_Export_Procedure => Export_Procedure : declare
6230 Args : Args_List (1 .. 4);
6231 Names : constant Name_List (1 .. 4) := (
6234 Name_Parameter_Types,
6237 Internal : Node_Id renames Args (1);
6238 External : Node_Id renames Args (2);
6239 Parameter_Types : Node_Id renames Args (3);
6240 Mechanism : Node_Id renames Args (4);
6244 Gather_Associations (Names, Args);
6245 Process_Extended_Import_Export_Subprogram_Pragma (
6246 Arg_Internal => Internal,
6247 Arg_External => External,
6248 Arg_Parameter_Types => Parameter_Types,
6249 Arg_Mechanism => Mechanism);
6250 end Export_Procedure;
6256 -- pragma Export_Value (
6257 -- [Value =>] static_integer_EXPRESSION,
6258 -- [Link_Name =>] static_string_EXPRESSION);
6260 when Pragma_Export_Value =>
6262 Check_Arg_Order ((Name_Value, Name_Link_Name));
6263 Check_Arg_Count (2);
6265 Check_Optional_Identifier (Arg1, Name_Value);
6266 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6268 Check_Optional_Identifier (Arg2, Name_Link_Name);
6269 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6271 -----------------------------
6272 -- Export_Valued_Procedure --
6273 -----------------------------
6275 -- pragma Export_Valued_Procedure (
6276 -- [Internal =>] LOCAL_NAME,
6277 -- [, [External =>] EXTERNAL_SYMBOL,]
6278 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6279 -- [, [Mechanism =>] MECHANISM]);
6281 -- EXTERNAL_SYMBOL ::=
6283 -- | static_string_EXPRESSION
6285 -- PARAMETER_TYPES ::=
6287 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6289 -- TYPE_DESIGNATOR ::=
6291 -- | subtype_Name ' Access
6295 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6297 -- MECHANISM_ASSOCIATION ::=
6298 -- [formal_parameter_NAME =>] MECHANISM_NAME
6300 -- MECHANISM_NAME ::=
6303 -- | Descriptor [([Class =>] CLASS_NAME)]
6305 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6307 when Pragma_Export_Valued_Procedure =>
6308 Export_Valued_Procedure : declare
6309 Args : Args_List (1 .. 4);
6310 Names : constant Name_List (1 .. 4) := (
6313 Name_Parameter_Types,
6316 Internal : Node_Id renames Args (1);
6317 External : Node_Id renames Args (2);
6318 Parameter_Types : Node_Id renames Args (3);
6319 Mechanism : Node_Id renames Args (4);
6323 Gather_Associations (Names, Args);
6324 Process_Extended_Import_Export_Subprogram_Pragma (
6325 Arg_Internal => Internal,
6326 Arg_External => External,
6327 Arg_Parameter_Types => Parameter_Types,
6328 Arg_Mechanism => Mechanism);
6329 end Export_Valued_Procedure;
6335 -- pragma Extend_System ([Name =>] Identifier);
6337 when Pragma_Extend_System => Extend_System : declare
6340 Check_Valid_Configuration_Pragma;
6341 Check_Arg_Count (1);
6342 Check_Optional_Identifier (Arg1, Name_Name);
6343 Check_Arg_Is_Identifier (Arg1);
6345 Get_Name_String (Chars (Expression (Arg1)));
6348 and then Name_Buffer (1 .. 4) = "aux_"
6350 if Present (System_Extend_Pragma_Arg) then
6351 if Chars (Expression (Arg1)) =
6352 Chars (Expression (System_Extend_Pragma_Arg))
6356 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6357 Error_Pragma ("pragma% conflicts with that at#");
6361 System_Extend_Pragma_Arg := Arg1;
6363 if not GNAT_Mode then
6364 System_Extend_Unit := Arg1;
6368 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6372 ------------------------
6373 -- Extensions_Allowed --
6374 ------------------------
6376 -- pragma Extensions_Allowed (ON | OFF);
6378 when Pragma_Extensions_Allowed =>
6380 Check_Arg_Count (1);
6381 Check_No_Identifiers;
6382 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6384 if Chars (Expression (Arg1)) = Name_On then
6385 Extensions_Allowed := True;
6386 Ada_Version := Ada_Version_Type'Last;
6388 Extensions_Allowed := False;
6389 Ada_Version := Ada_Version_Type'Min (Ada_Version, Ada_95);
6392 Ada_Version_Explicit := Ada_Version;
6398 -- pragma External (
6399 -- [ Convention =>] convention_IDENTIFIER,
6400 -- [ Entity =>] local_NAME
6401 -- [, [External_Name =>] static_string_EXPRESSION ]
6402 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6404 when Pragma_External => External : declare
6414 Check_At_Least_N_Arguments (2);
6415 Check_At_Most_N_Arguments (4);
6416 Process_Convention (C, Def_Id);
6417 Note_Possible_Modification (Expression (Arg2));
6418 Process_Interface_Name (Def_Id, Arg3, Arg4);
6419 Set_Exported (Def_Id, Arg2);
6422 --------------------------
6423 -- External_Name_Casing --
6424 --------------------------
6426 -- pragma External_Name_Casing (
6427 -- UPPERCASE | LOWERCASE
6428 -- [, AS_IS | UPPERCASE | LOWERCASE]);
6430 when Pragma_External_Name_Casing => External_Name_Casing : declare
6433 Check_No_Identifiers;
6435 if Arg_Count = 2 then
6437 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
6439 case Chars (Get_Pragma_Arg (Arg2)) is
6441 Opt.External_Name_Exp_Casing := As_Is;
6443 when Name_Uppercase =>
6444 Opt.External_Name_Exp_Casing := Uppercase;
6446 when Name_Lowercase =>
6447 Opt.External_Name_Exp_Casing := Lowercase;
6454 Check_Arg_Count (1);
6457 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
6459 case Chars (Get_Pragma_Arg (Arg1)) is
6460 when Name_Uppercase =>
6461 Opt.External_Name_Imp_Casing := Uppercase;
6463 when Name_Lowercase =>
6464 Opt.External_Name_Imp_Casing := Lowercase;
6469 end External_Name_Casing;
6471 ---------------------------
6472 -- Finalize_Storage_Only --
6473 ---------------------------
6475 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
6477 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
6478 Assoc : constant Node_Id := Arg1;
6479 Type_Id : constant Node_Id := Expression (Assoc);
6483 Check_No_Identifiers;
6484 Check_Arg_Count (1);
6485 Check_Arg_Is_Local_Name (Arg1);
6487 Find_Type (Type_Id);
6488 Typ := Entity (Type_Id);
6491 or else Rep_Item_Too_Early (Typ, N)
6495 Typ := Underlying_Type (Typ);
6498 if not Is_Controlled (Typ) then
6499 Error_Pragma ("pragma% must specify controlled type");
6502 Check_First_Subtype (Arg1);
6504 if Finalize_Storage_Only (Typ) then
6505 Error_Pragma ("duplicate pragma%, only one allowed");
6507 elsif not Rep_Item_Too_Late (Typ, N) then
6508 Set_Finalize_Storage_Only (Base_Type (Typ), True);
6510 end Finalize_Storage;
6512 --------------------------
6513 -- Float_Representation --
6514 --------------------------
6516 -- pragma Float_Representation (VAX_Float | IEEE_Float);
6518 when Pragma_Float_Representation => Float_Representation : declare
6526 if Arg_Count = 1 then
6527 Check_Valid_Configuration_Pragma;
6529 Check_Arg_Count (2);
6530 Check_Optional_Identifier (Arg2, Name_Entity);
6531 Check_Arg_Is_Local_Name (Arg2);
6534 Check_No_Identifier (Arg1);
6535 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
6537 if not OpenVMS_On_Target then
6538 if Chars (Expression (Arg1)) = Name_VAX_Float then
6540 ("?pragma% ignored (applies only to Open'V'M'S)");
6546 -- One argument case
6548 if Arg_Count = 1 then
6550 if Chars (Expression (Arg1)) = Name_VAX_Float then
6552 if Opt.Float_Format = 'I' then
6553 Error_Pragma ("'I'E'E'E format previously specified");
6556 Opt.Float_Format := 'V';
6559 if Opt.Float_Format = 'V' then
6560 Error_Pragma ("'V'A'X format previously specified");
6563 Opt.Float_Format := 'I';
6566 Set_Standard_Fpt_Formats;
6568 -- Two argument case
6571 Argx := Get_Pragma_Arg (Arg2);
6573 if not Is_Entity_Name (Argx)
6574 or else not Is_Floating_Point_Type (Entity (Argx))
6577 ("second argument of% pragma must be floating-point type",
6581 Ent := Entity (Argx);
6582 Digs := UI_To_Int (Digits_Value (Ent));
6584 -- Two arguments, VAX_Float case
6586 if Chars (Expression (Arg1)) = Name_VAX_Float then
6589 when 6 => Set_F_Float (Ent);
6590 when 9 => Set_D_Float (Ent);
6591 when 15 => Set_G_Float (Ent);
6595 ("wrong digits value, must be 6,9 or 15", Arg2);
6598 -- Two arguments, IEEE_Float case
6602 when 6 => Set_IEEE_Short (Ent);
6603 when 15 => Set_IEEE_Long (Ent);
6607 ("wrong digits value, must be 6 or 15", Arg2);
6611 end Float_Representation;
6617 -- pragma Ident (static_string_EXPRESSION)
6619 -- Note: pragma Comment shares this processing. Pragma Comment
6620 -- is identical to Ident, except that the restriction of the
6621 -- argument to 31 characters and the placement restrictions
6622 -- are not enforced for pragma Comment.
6624 when Pragma_Ident | Pragma_Comment => Ident : declare
6629 Check_Arg_Count (1);
6630 Check_No_Identifiers;
6631 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6633 -- For pragma Ident, preserve DEC compatibility by requiring
6634 -- the pragma to appear in a declarative part or package spec.
6636 if Prag_Id = Pragma_Ident then
6637 Check_Is_In_Decl_Part_Or_Package_Spec;
6640 Str := Expr_Value_S (Expression (Arg1));
6647 GP := Parent (Parent (N));
6649 if Nkind (GP) = N_Package_Declaration
6651 Nkind (GP) = N_Generic_Package_Declaration
6656 -- If we have a compilation unit, then record the ident
6657 -- value, checking for improper duplication.
6659 if Nkind (GP) = N_Compilation_Unit then
6660 CS := Ident_String (Current_Sem_Unit);
6662 if Present (CS) then
6664 -- For Ident, we do not permit multiple instances
6666 if Prag_Id = Pragma_Ident then
6667 Error_Pragma ("duplicate% pragma not permitted");
6669 -- For Comment, we concatenate the string, unless we
6670 -- want to preserve the tree structure for ASIS.
6672 elsif not ASIS_Mode then
6673 Start_String (Strval (CS));
6674 Store_String_Char (' ');
6675 Store_String_Chars (Strval (Str));
6676 Set_Strval (CS, End_String);
6680 -- In VMS, the effect of IDENT is achieved by passing
6681 -- IDENTIFICATION=name as a --for-linker switch.
6683 if OpenVMS_On_Target then
6686 ("--for-linker=IDENTIFICATION=");
6687 String_To_Name_Buffer (Strval (Str));
6688 Store_String_Chars (Name_Buffer (1 .. Name_Len));
6690 -- Only the last processed IDENT is saved. The main
6691 -- purpose is so an IDENT associated with a main
6692 -- procedure will be used in preference to an IDENT
6693 -- associated with a with'd package.
6695 Replace_Linker_Option_String
6696 (End_String, "--for-linker=IDENTIFICATION=");
6699 Set_Ident_String (Current_Sem_Unit, Str);
6702 -- For subunits, we just ignore the Ident, since in GNAT
6703 -- these are not separate object files, and hence not
6704 -- separate units in the unit table.
6706 elsif Nkind (GP) = N_Subunit then
6709 -- Otherwise we have a misplaced pragma Ident, but we ignore
6710 -- this if we are in an instantiation, since it comes from
6711 -- a generic, and has no relevance to the instantiation.
6713 elsif Prag_Id = Pragma_Ident then
6714 if Instantiation_Location (Loc) = No_Location then
6715 Error_Pragma ("pragma% only allowed at outer level");
6726 -- [ Convention =>] convention_IDENTIFIER,
6727 -- [ Entity =>] local_NAME
6728 -- [, [External_Name =>] static_string_EXPRESSION ]
6729 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6731 when Pragma_Import =>
6732 Check_Ada_83_Warning;
6738 Check_At_Least_N_Arguments (2);
6739 Check_At_Most_N_Arguments (4);
6740 Process_Import_Or_Interface;
6742 ----------------------
6743 -- Import_Exception --
6744 ----------------------
6746 -- pragma Import_Exception (
6747 -- [Internal =>] LOCAL_NAME,
6748 -- [, [External =>] EXTERNAL_SYMBOL,]
6749 -- [, [Form =>] Ada | VMS]
6750 -- [, [Code =>] static_integer_EXPRESSION]);
6752 when Pragma_Import_Exception => Import_Exception : declare
6753 Args : Args_List (1 .. 4);
6754 Names : constant Name_List (1 .. 4) := (
6760 Internal : Node_Id renames Args (1);
6761 External : Node_Id renames Args (2);
6762 Form : Node_Id renames Args (3);
6763 Code : Node_Id renames Args (4);
6766 Gather_Associations (Names, Args);
6768 if Present (External) and then Present (Code) then
6770 ("cannot give both External and Code options for pragma%");
6773 Process_Extended_Import_Export_Exception_Pragma (
6774 Arg_Internal => Internal,
6775 Arg_External => External,
6779 if not Is_VMS_Exception (Entity (Internal)) then
6780 Set_Imported (Entity (Internal));
6782 end Import_Exception;
6784 ---------------------
6785 -- Import_Function --
6786 ---------------------
6788 -- pragma Import_Function (
6789 -- [Internal =>] LOCAL_NAME,
6790 -- [, [External =>] EXTERNAL_SYMBOL]
6791 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6792 -- [, [Result_Type =>] SUBTYPE_MARK]
6793 -- [, [Mechanism =>] MECHANISM]
6794 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6795 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6797 -- EXTERNAL_SYMBOL ::=
6799 -- | static_string_EXPRESSION
6801 -- PARAMETER_TYPES ::=
6803 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6805 -- TYPE_DESIGNATOR ::=
6807 -- | subtype_Name ' Access
6811 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6813 -- MECHANISM_ASSOCIATION ::=
6814 -- [formal_parameter_NAME =>] MECHANISM_NAME
6816 -- MECHANISM_NAME ::=
6819 -- | Descriptor [([Class =>] CLASS_NAME)]
6821 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6823 when Pragma_Import_Function => Import_Function : declare
6824 Args : Args_List (1 .. 7);
6825 Names : constant Name_List (1 .. 7) := (
6828 Name_Parameter_Types,
6831 Name_Result_Mechanism,
6832 Name_First_Optional_Parameter);
6834 Internal : Node_Id renames Args (1);
6835 External : Node_Id renames Args (2);
6836 Parameter_Types : Node_Id renames Args (3);
6837 Result_Type : Node_Id renames Args (4);
6838 Mechanism : Node_Id renames Args (5);
6839 Result_Mechanism : Node_Id renames Args (6);
6840 First_Optional_Parameter : Node_Id renames Args (7);
6844 Gather_Associations (Names, Args);
6845 Process_Extended_Import_Export_Subprogram_Pragma (
6846 Arg_Internal => Internal,
6847 Arg_External => External,
6848 Arg_Parameter_Types => Parameter_Types,
6849 Arg_Result_Type => Result_Type,
6850 Arg_Mechanism => Mechanism,
6851 Arg_Result_Mechanism => Result_Mechanism,
6852 Arg_First_Optional_Parameter => First_Optional_Parameter);
6853 end Import_Function;
6859 -- pragma Import_Object (
6860 -- [Internal =>] LOCAL_NAME,
6861 -- [, [External =>] EXTERNAL_SYMBOL]
6862 -- [, [Size =>] EXTERNAL_SYMBOL]);
6864 -- EXTERNAL_SYMBOL ::=
6866 -- | static_string_EXPRESSION
6868 when Pragma_Import_Object => Import_Object : declare
6869 Args : Args_List (1 .. 3);
6870 Names : constant Name_List (1 .. 3) := (
6875 Internal : Node_Id renames Args (1);
6876 External : Node_Id renames Args (2);
6877 Size : Node_Id renames Args (3);
6881 Gather_Associations (Names, Args);
6882 Process_Extended_Import_Export_Object_Pragma (
6883 Arg_Internal => Internal,
6884 Arg_External => External,
6888 ----------------------
6889 -- Import_Procedure --
6890 ----------------------
6892 -- pragma Import_Procedure (
6893 -- [Internal =>] LOCAL_NAME,
6894 -- [, [External =>] EXTERNAL_SYMBOL]
6895 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6896 -- [, [Mechanism =>] MECHANISM]
6897 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6899 -- EXTERNAL_SYMBOL ::=
6901 -- | static_string_EXPRESSION
6903 -- PARAMETER_TYPES ::=
6905 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6907 -- TYPE_DESIGNATOR ::=
6909 -- | subtype_Name ' Access
6913 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6915 -- MECHANISM_ASSOCIATION ::=
6916 -- [formal_parameter_NAME =>] MECHANISM_NAME
6918 -- MECHANISM_NAME ::=
6921 -- | Descriptor [([Class =>] CLASS_NAME)]
6923 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6925 when Pragma_Import_Procedure => Import_Procedure : declare
6926 Args : Args_List (1 .. 5);
6927 Names : constant Name_List (1 .. 5) := (
6930 Name_Parameter_Types,
6932 Name_First_Optional_Parameter);
6934 Internal : Node_Id renames Args (1);
6935 External : Node_Id renames Args (2);
6936 Parameter_Types : Node_Id renames Args (3);
6937 Mechanism : Node_Id renames Args (4);
6938 First_Optional_Parameter : Node_Id renames Args (5);
6942 Gather_Associations (Names, Args);
6943 Process_Extended_Import_Export_Subprogram_Pragma (
6944 Arg_Internal => Internal,
6945 Arg_External => External,
6946 Arg_Parameter_Types => Parameter_Types,
6947 Arg_Mechanism => Mechanism,
6948 Arg_First_Optional_Parameter => First_Optional_Parameter);
6949 end Import_Procedure;
6951 -----------------------------
6952 -- Import_Valued_Procedure --
6953 -----------------------------
6955 -- pragma Import_Valued_Procedure (
6956 -- [Internal =>] LOCAL_NAME,
6957 -- [, [External =>] EXTERNAL_SYMBOL]
6958 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6959 -- [, [Mechanism =>] MECHANISM]
6960 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6962 -- EXTERNAL_SYMBOL ::=
6964 -- | static_string_EXPRESSION
6966 -- PARAMETER_TYPES ::=
6968 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6970 -- TYPE_DESIGNATOR ::=
6972 -- | subtype_Name ' Access
6976 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6978 -- MECHANISM_ASSOCIATION ::=
6979 -- [formal_parameter_NAME =>] MECHANISM_NAME
6981 -- MECHANISM_NAME ::=
6984 -- | Descriptor [([Class =>] CLASS_NAME)]
6986 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6988 when Pragma_Import_Valued_Procedure =>
6989 Import_Valued_Procedure : declare
6990 Args : Args_List (1 .. 5);
6991 Names : constant Name_List (1 .. 5) := (
6994 Name_Parameter_Types,
6996 Name_First_Optional_Parameter);
6998 Internal : Node_Id renames Args (1);
6999 External : Node_Id renames Args (2);
7000 Parameter_Types : Node_Id renames Args (3);
7001 Mechanism : Node_Id renames Args (4);
7002 First_Optional_Parameter : Node_Id renames Args (5);
7006 Gather_Associations (Names, Args);
7007 Process_Extended_Import_Export_Subprogram_Pragma (
7008 Arg_Internal => Internal,
7009 Arg_External => External,
7010 Arg_Parameter_Types => Parameter_Types,
7011 Arg_Mechanism => Mechanism,
7012 Arg_First_Optional_Parameter => First_Optional_Parameter);
7013 end Import_Valued_Procedure;
7015 ------------------------
7016 -- Initialize_Scalars --
7017 ------------------------
7019 -- pragma Initialize_Scalars;
7021 when Pragma_Initialize_Scalars =>
7023 Check_Arg_Count (0);
7024 Check_Valid_Configuration_Pragma;
7025 Check_Restriction (No_Initialize_Scalars, N);
7027 if not Restriction_Active (No_Initialize_Scalars) then
7028 Init_Or_Norm_Scalars := True;
7029 Initialize_Scalars := True;
7036 -- pragma Inline ( NAME {, NAME} );
7038 when Pragma_Inline =>
7040 -- Pragma is active if inlining option is active
7042 Process_Inline (Inline_Active);
7048 -- pragma Inline_Always ( NAME {, NAME} );
7050 when Pragma_Inline_Always =>
7051 Process_Inline (True);
7053 --------------------
7054 -- Inline_Generic --
7055 --------------------
7057 -- pragma Inline_Generic (NAME {, NAME});
7059 when Pragma_Inline_Generic =>
7060 Process_Generic_List;
7062 ----------------------
7063 -- Inspection_Point --
7064 ----------------------
7066 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7068 when Pragma_Inspection_Point => Inspection_Point : declare
7073 if Arg_Count > 0 then
7076 Exp := Expression (Arg);
7079 if not Is_Entity_Name (Exp)
7080 or else not Is_Object (Entity (Exp))
7082 Error_Pragma_Arg ("object name required", Arg);
7089 end Inspection_Point;
7095 -- pragma Interface (
7096 -- convention_IDENTIFIER,
7099 when Pragma_Interface =>
7101 Check_Arg_Count (2);
7102 Check_No_Identifiers;
7103 Process_Import_Or_Interface;
7105 --------------------
7106 -- Interface_Name --
7107 --------------------
7109 -- pragma Interface_Name (
7110 -- [ Entity =>] local_NAME
7111 -- [,[External_Name =>] static_string_EXPRESSION ]
7112 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7114 when Pragma_Interface_Name => Interface_Name : declare
7123 ((Name_Entity, Name_External_Name, Name_Link_Name));
7124 Check_At_Least_N_Arguments (2);
7125 Check_At_Most_N_Arguments (3);
7126 Id := Expression (Arg1);
7129 if not Is_Entity_Name (Id) then
7131 ("first argument for pragma% must be entity name", Arg1);
7132 elsif Etype (Id) = Any_Type then
7135 Def_Id := Entity (Id);
7138 -- Special DEC-compatible processing for the object case,
7139 -- forces object to be imported.
7141 if Ekind (Def_Id) = E_Variable then
7142 Kill_Size_Check_Code (Def_Id);
7143 Note_Possible_Modification (Id);
7145 -- Initialization is not allowed for imported variable
7147 if Present (Expression (Parent (Def_Id)))
7148 and then Comes_From_Source (Expression (Parent (Def_Id)))
7150 Error_Msg_Sloc := Sloc (Def_Id);
7152 ("no initialization allowed for declaration of& #",
7156 -- For compatibility, support VADS usage of providing both
7157 -- pragmas Interface and Interface_Name to obtain the effect
7158 -- of a single Import pragma.
7160 if Is_Imported (Def_Id)
7161 and then Present (First_Rep_Item (Def_Id))
7162 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7163 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
7167 Set_Imported (Def_Id);
7170 Set_Is_Public (Def_Id);
7171 Process_Interface_Name (Def_Id, Arg2, Arg3);
7174 -- Otherwise must be subprogram
7176 elsif not Is_Subprogram (Def_Id) then
7178 ("argument of pragma% is not subprogram", Arg1);
7181 Check_At_Most_N_Arguments (3);
7185 -- Loop through homonyms
7188 Def_Id := Get_Base_Subprogram (Hom_Id);
7190 if Is_Imported (Def_Id) then
7191 Process_Interface_Name (Def_Id, Arg2, Arg3);
7195 Hom_Id := Homonym (Hom_Id);
7197 exit when No (Hom_Id)
7198 or else Scope (Hom_Id) /= Current_Scope;
7203 ("argument of pragma% is not imported subprogram",
7209 -----------------------
7210 -- Interrupt_Handler --
7211 -----------------------
7213 -- pragma Interrupt_Handler (handler_NAME);
7215 when Pragma_Interrupt_Handler =>
7216 Check_Ada_83_Warning;
7217 Check_Arg_Count (1);
7218 Check_No_Identifiers;
7220 if No_Run_Time_Mode then
7221 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7223 Check_Interrupt_Or_Attach_Handler;
7224 Process_Interrupt_Or_Attach_Handler;
7227 ------------------------
7228 -- Interrupt_Priority --
7229 ------------------------
7231 -- pragma Interrupt_Priority [(EXPRESSION)];
7233 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7234 P : constant Node_Id := Parent (N);
7238 Check_Ada_83_Warning;
7240 if Arg_Count /= 0 then
7241 Arg := Expression (Arg1);
7242 Check_Arg_Count (1);
7243 Check_No_Identifiers;
7245 -- The expression must be analyzed in the special manner
7246 -- described in "Handling of Default and Per-Object
7247 -- Expressions" in sem.ads.
7249 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
7252 if Nkind (P) /= N_Task_Definition
7253 and then Nkind (P) /= N_Protected_Definition
7258 elsif Has_Priority_Pragma (P) then
7259 Error_Pragma ("duplicate pragma% not allowed");
7262 Set_Has_Priority_Pragma (P, True);
7263 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7265 end Interrupt_Priority;
7267 ---------------------
7268 -- Interrupt_State --
7269 ---------------------
7271 -- pragma Interrupt_State (
7272 -- [Name =>] INTERRUPT_ID,
7273 -- [State =>] INTERRUPT_STATE);
7275 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7276 -- INTERRUPT_STATE => System | Runtime | User
7278 -- Note: if the interrupt id is given as an identifier, then
7279 -- it must be one of the identifiers in Ada.Interrupts.Names.
7280 -- Otherwise it is given as a static integer expression which
7281 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7283 when Pragma_Interrupt_State => Interrupt_State : declare
7285 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7286 -- This is the entity Ada.Interrupts.Interrupt_ID;
7288 State_Type : Character;
7289 -- Set to 's'/'r'/'u' for System/Runtime/User
7292 -- Index to entry in Interrupt_States table
7295 -- Value of interrupt
7297 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7298 -- The first argument to the pragma
7300 Int_Ent : Entity_Id;
7301 -- Interrupt entity in Ada.Interrupts.Names
7305 Check_Arg_Order ((Name_Name, Name_State));
7306 Check_Arg_Count (2);
7308 Check_Optional_Identifier (Arg1, Name_Name);
7309 Check_Optional_Identifier (Arg2, Name_State);
7310 Check_Arg_Is_Identifier (Arg2);
7312 -- First argument is identifier
7314 if Nkind (Arg1X) = N_Identifier then
7316 -- Search list of names in Ada.Interrupts.Names
7318 Int_Ent := First_Entity (RTE (RE_Names));
7320 if No (Int_Ent) then
7321 Error_Pragma_Arg ("invalid interrupt name", Arg1);
7323 elsif Chars (Int_Ent) = Chars (Arg1X) then
7324 Int_Val := Expr_Value (Constant_Value (Int_Ent));
7328 Next_Entity (Int_Ent);
7331 -- First argument is not an identifier, so it must be a
7332 -- static expression of type Ada.Interrupts.Interrupt_ID.
7335 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7336 Int_Val := Expr_Value (Arg1X);
7338 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
7340 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
7343 ("value not in range of type " &
7344 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
7350 case Chars (Get_Pragma_Arg (Arg2)) is
7351 when Name_Runtime => State_Type := 'r';
7352 when Name_System => State_Type := 's';
7353 when Name_User => State_Type := 'u';
7356 Error_Pragma_Arg ("invalid interrupt state", Arg2);
7359 -- Check if entry is already stored
7361 IST_Num := Interrupt_States.First;
7363 -- If entry not found, add it
7365 if IST_Num > Interrupt_States.Last then
7366 Interrupt_States.Append
7367 ((Interrupt_Number => UI_To_Int (Int_Val),
7368 Interrupt_State => State_Type,
7369 Pragma_Loc => Loc));
7372 -- Case of entry for the same entry
7374 elsif Int_Val = Interrupt_States.Table (IST_Num).
7377 -- If state matches, done, no need to make redundant entry
7380 State_Type = Interrupt_States.Table (IST_Num).
7383 -- Otherwise if state does not match, error
7386 Interrupt_States.Table (IST_Num).Pragma_Loc;
7388 ("state conflicts with that given at #", Arg2);
7392 IST_Num := IST_Num + 1;
7394 end Interrupt_State;
7396 ----------------------
7397 -- Java_Constructor --
7398 ----------------------
7400 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
7402 when Pragma_Java_Constructor => Java_Constructor : declare
7409 Check_Arg_Count (1);
7410 Check_Optional_Identifier (Arg1, Name_Entity);
7411 Check_Arg_Is_Local_Name (Arg1);
7413 Id := Expression (Arg1);
7414 Find_Program_Unit_Name (Id);
7416 -- If we did not find the name, we are done
7418 if Etype (Id) = Any_Type then
7422 Hom_Id := Entity (Id);
7424 -- Loop through homonyms
7427 Def_Id := Get_Base_Subprogram (Hom_Id);
7429 -- The constructor is required to be a function returning
7430 -- an access type whose designated type has convention Java.
7432 if Ekind (Def_Id) = E_Function
7433 and then Ekind (Etype (Def_Id)) in Access_Kind
7436 (Designated_Type (Etype (Def_Id))) = Convention_Java
7439 (Root_Type (Designated_Type (Etype (Def_Id))))
7442 Set_Is_Constructor (Def_Id);
7443 Set_Convention (Def_Id, Convention_Java);
7447 ("pragma% requires function returning a 'Java access type",
7451 Hom_Id := Homonym (Hom_Id);
7453 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
7455 end Java_Constructor;
7457 ----------------------
7458 -- Java_Interface --
7459 ----------------------
7461 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
7463 when Pragma_Java_Interface => Java_Interface : declare
7469 Check_Arg_Count (1);
7470 Check_Optional_Identifier (Arg1, Name_Entity);
7471 Check_Arg_Is_Local_Name (Arg1);
7473 Arg := Expression (Arg1);
7476 if Etype (Arg) = Any_Type then
7480 if not Is_Entity_Name (Arg)
7481 or else not Is_Type (Entity (Arg))
7483 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7486 Typ := Underlying_Type (Entity (Arg));
7488 -- For now we simply check some of the semantic constraints
7489 -- on the type. This currently leaves out some restrictions
7490 -- on interface types, namely that the parent type must be
7491 -- java.lang.Object.Typ and that all primitives of the type
7492 -- should be declared abstract. ???
7494 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
7495 Error_Pragma_Arg ("pragma% requires an abstract "
7496 & "tagged type", Arg1);
7498 elsif not Has_Discriminants (Typ)
7499 or else Ekind (Etype (First_Discriminant (Typ)))
7500 /= E_Anonymous_Access_Type
7502 not Is_Class_Wide_Type
7503 (Designated_Type (Etype (First_Discriminant (Typ))))
7506 ("type must have a class-wide access discriminant", Arg1);
7514 -- pragma Keep_Names ([On => ] local_NAME);
7516 when Pragma_Keep_Names => Keep_Names : declare
7521 Check_Arg_Count (1);
7522 Check_Optional_Identifier (Arg1, Name_On);
7523 Check_Arg_Is_Local_Name (Arg1);
7525 Arg := Expression (Arg1);
7528 if Etype (Arg) = Any_Type then
7532 if not Is_Entity_Name (Arg)
7533 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
7536 ("pragma% requires a local enumeration type", Arg1);
7539 Set_Discard_Names (Entity (Arg), False);
7546 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
7548 when Pragma_License =>
7550 Check_Arg_Count (1);
7551 Check_No_Identifiers;
7552 Check_Valid_Configuration_Pragma;
7553 Check_Arg_Is_Identifier (Arg1);
7556 Sind : constant Source_File_Index :=
7557 Source_Index (Current_Sem_Unit);
7560 case Chars (Get_Pragma_Arg (Arg1)) is
7562 Set_License (Sind, GPL);
7564 when Name_Modified_GPL =>
7565 Set_License (Sind, Modified_GPL);
7567 when Name_Restricted =>
7568 Set_License (Sind, Restricted);
7570 when Name_Unrestricted =>
7571 Set_License (Sind, Unrestricted);
7574 Error_Pragma_Arg ("invalid license name", Arg1);
7582 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
7584 when Pragma_Link_With => Link_With : declare
7590 if Operating_Mode = Generate_Code
7591 and then In_Extended_Main_Source_Unit (N)
7593 Check_At_Least_N_Arguments (1);
7594 Check_No_Identifiers;
7595 Check_Is_In_Decl_Part_Or_Package_Spec;
7596 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7600 while Present (Arg) loop
7601 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7603 -- Store argument, converting sequences of spaces
7604 -- to a single null character (this is one of the
7605 -- differences in processing between Link_With
7606 -- and Linker_Options).
7609 C : constant Char_Code := Get_Char_Code (' ');
7610 S : constant String_Id :=
7611 Strval (Expr_Value_S (Expression (Arg)));
7612 L : constant Nat := String_Length (S);
7615 procedure Skip_Spaces;
7616 -- Advance F past any spaces
7618 procedure Skip_Spaces is
7620 while F <= L and then Get_String_Char (S, F) = C loop
7626 Skip_Spaces; -- skip leading spaces
7628 -- Loop through characters, changing any embedded
7629 -- sequence of spaces to a single null character
7630 -- (this is how Link_With/Linker_Options differ)
7633 if Get_String_Char (S, F) = C then
7636 Store_String_Char (ASCII.NUL);
7639 Store_String_Char (Get_String_Char (S, F));
7647 if Present (Arg) then
7648 Store_String_Char (ASCII.NUL);
7652 Store_Linker_Option_String (End_String);
7660 -- pragma Linker_Alias (
7661 -- [Entity =>] LOCAL_NAME
7662 -- [Alias =>] static_string_EXPRESSION);
7664 when Pragma_Linker_Alias =>
7666 Check_Arg_Order ((Name_Entity, Name_Alias));
7667 Check_Arg_Count (2);
7668 Check_Optional_Identifier (Arg1, Name_Entity);
7669 Check_Optional_Identifier (Arg2, Name_Alias);
7670 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7671 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7673 -- The only processing required is to link this item on to the
7674 -- list of rep items for the given entity. This is accomplished
7675 -- by the call to Rep_Item_Too_Late (when no error is detected
7676 -- and False is returned).
7678 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7681 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7684 --------------------
7685 -- Linker_Options --
7686 --------------------
7688 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
7690 when Pragma_Linker_Options => Linker_Options : declare
7694 Check_Ada_83_Warning;
7695 Check_No_Identifiers;
7696 Check_Arg_Count (1);
7697 Check_Is_In_Decl_Part_Or_Package_Spec;
7699 if Operating_Mode = Generate_Code
7700 and then In_Extended_Main_Source_Unit (N)
7702 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7703 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7706 while Present (Arg) loop
7707 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7708 Store_String_Char (ASCII.NUL);
7710 (Strval (Expr_Value_S (Expression (Arg))));
7714 Store_Linker_Option_String (End_String);
7718 --------------------
7719 -- Linker_Section --
7720 --------------------
7722 -- pragma Linker_Section (
7723 -- [Entity =>] LOCAL_NAME
7724 -- [Section =>] static_string_EXPRESSION);
7726 when Pragma_Linker_Section =>
7728 Check_Arg_Order ((Name_Entity, Name_Section));
7729 Check_Arg_Count (2);
7730 Check_Optional_Identifier (Arg1, Name_Entity);
7731 Check_Optional_Identifier (Arg2, Name_Section);
7732 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7733 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7735 -- The only processing required is to link this item on to the
7736 -- list of rep items for the given entity. This is accomplished
7737 -- by the call to Rep_Item_Too_Late (when no error is detected
7738 -- and False is returned).
7740 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7743 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7750 -- pragma List (On | Off)
7752 -- There is nothing to do here, since we did all the processing
7753 -- for this pragma in Par.Prag (so that it works properly even in
7754 -- syntax only mode)
7759 --------------------
7760 -- Locking_Policy --
7761 --------------------
7763 -- pragma Locking_Policy (policy_IDENTIFIER);
7765 when Pragma_Locking_Policy => declare
7769 Check_Ada_83_Warning;
7770 Check_Arg_Count (1);
7771 Check_No_Identifiers;
7772 Check_Arg_Is_Locking_Policy (Arg1);
7773 Check_Valid_Configuration_Pragma;
7774 Get_Name_String (Chars (Expression (Arg1)));
7775 LP := Fold_Upper (Name_Buffer (1));
7777 if Locking_Policy /= ' '
7778 and then Locking_Policy /= LP
7780 Error_Msg_Sloc := Locking_Policy_Sloc;
7781 Error_Pragma ("locking policy incompatible with policy#");
7783 -- Set new policy, but always preserve System_Location since
7784 -- we like the error message with the run time name.
7787 Locking_Policy := LP;
7789 if Locking_Policy_Sloc /= System_Location then
7790 Locking_Policy_Sloc := Loc;
7799 -- pragma Long_Float (D_Float | G_Float);
7801 when Pragma_Long_Float =>
7803 Check_Valid_Configuration_Pragma;
7804 Check_Arg_Count (1);
7805 Check_No_Identifier (Arg1);
7806 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7808 if not OpenVMS_On_Target then
7809 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7814 if Chars (Expression (Arg1)) = Name_D_Float then
7815 if Opt.Float_Format_Long = 'G' then
7816 Error_Pragma ("G_Float previously specified");
7819 Opt.Float_Format_Long := 'D';
7821 -- G_Float case (this is the default, does not need overriding)
7824 if Opt.Float_Format_Long = 'D' then
7825 Error_Pragma ("D_Float previously specified");
7828 Opt.Float_Format_Long := 'G';
7831 Set_Standard_Fpt_Formats;
7833 -----------------------
7834 -- Machine_Attribute --
7835 -----------------------
7837 -- pragma Machine_Attribute (
7838 -- [Entity =>] LOCAL_NAME,
7839 -- [Attribute_Name =>] static_string_EXPRESSION
7840 -- [,[Info =>] static_string_EXPRESSION] );
7842 when Pragma_Machine_Attribute => Machine_Attribute : declare
7847 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
7849 if Arg_Count = 3 then
7850 Check_Optional_Identifier (Arg3, Name_Info);
7851 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7853 Check_Arg_Count (2);
7856 Check_Optional_Identifier (Arg1, Name_Entity);
7857 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
7858 Check_Arg_Is_Local_Name (Arg1);
7859 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7860 Def_Id := Entity (Expression (Arg1));
7862 if Is_Access_Type (Def_Id) then
7863 Def_Id := Designated_Type (Def_Id);
7866 if Rep_Item_Too_Early (Def_Id, N) then
7870 Def_Id := Underlying_Type (Def_Id);
7872 -- The only processing required is to link this item on to the
7873 -- list of rep items for the given entity. This is accomplished
7874 -- by the call to Rep_Item_Too_Late (when no error is detected
7875 -- and False is returned).
7877 if Rep_Item_Too_Late (Def_Id, N) then
7880 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7882 end Machine_Attribute;
7888 -- pragma Main_Storage
7889 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7891 -- MAIN_STORAGE_OPTION ::=
7892 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7893 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7895 when Pragma_Main => Main : declare
7896 Args : Args_List (1 .. 3);
7897 Names : constant Name_List (1 .. 3) := (
7899 Name_Task_Stack_Size_Default,
7900 Name_Time_Slicing_Enabled);
7906 Gather_Associations (Names, Args);
7908 for J in 1 .. 2 loop
7909 if Present (Args (J)) then
7910 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7914 if Present (Args (3)) then
7915 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7919 while Present (Nod) loop
7920 if Nkind (Nod) = N_Pragma
7921 and then Chars (Nod) = Name_Main
7923 Error_Msg_Name_1 := Chars (N);
7924 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7935 -- pragma Main_Storage
7936 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7938 -- MAIN_STORAGE_OPTION ::=
7939 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7940 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7942 when Pragma_Main_Storage => Main_Storage : declare
7943 Args : Args_List (1 .. 2);
7944 Names : constant Name_List (1 .. 2) := (
7945 Name_Working_Storage,
7952 Gather_Associations (Names, Args);
7954 for J in 1 .. 2 loop
7955 if Present (Args (J)) then
7956 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7960 Check_In_Main_Program;
7963 while Present (Nod) loop
7964 if Nkind (Nod) = N_Pragma
7965 and then Chars (Nod) = Name_Main_Storage
7967 Error_Msg_Name_1 := Chars (N);
7968 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7979 -- pragma Memory_Size (NUMERIC_LITERAL)
7981 when Pragma_Memory_Size =>
7984 -- Memory size is simply ignored
7986 Check_No_Identifiers;
7987 Check_Arg_Count (1);
7988 Check_Arg_Is_Integer_Literal (Arg1);
7994 -- pragma No_Return (procedure_LOCAL_NAME);
7996 when Pragma_No_Return => No_Return : declare
8003 Check_Arg_Count (1);
8004 Check_No_Identifiers;
8005 Check_Arg_Is_Local_Name (Arg1);
8006 Id := Expression (Arg1);
8009 if not Is_Entity_Name (Id) then
8010 Error_Pragma_Arg ("entity name required", Arg1);
8013 if Etype (Id) = Any_Type then
8021 and then Scope (E) = Current_Scope
8023 if Ekind (E) = E_Procedure
8024 or else Ekind (E) = E_Generic_Procedure
8034 Error_Pragma ("no procedures found for pragma%");
8038 ------------------------
8039 -- No_Strict_Aliasing --
8040 ------------------------
8042 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
8047 Check_At_Most_N_Arguments (1);
8049 if Arg_Count = 0 then
8050 Check_Valid_Configuration_Pragma;
8051 Opt.No_Strict_Aliasing := True;
8054 Check_Optional_Identifier (Arg2, Name_Entity);
8055 Check_Arg_Is_Local_Name (Arg1);
8056 E_Id := Entity (Expression (Arg1));
8058 if E_Id = Any_Type then
8060 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
8061 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8064 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8066 end No_Strict_Alias;
8072 -- pragma Obsolescent [(static_string_EXPRESSION [, Ada_05])];
8074 when Pragma_Obsolescent => Obsolescent : declare
8075 Subp : Node_Or_Entity_Id;
8077 Active : Boolean := True;
8081 Check_At_Most_N_Arguments (2);
8082 Check_No_Identifiers;
8084 -- Check OK placement
8086 -- First possibility is within a declarative region, where the
8087 -- pragma immediately follows a subprogram declaration.
8089 if Present (Prev (N)) then
8092 -- Second possibility, stand alone subprogram declaration with the
8093 -- pragma immediately following the declaration.
8096 and then Nkind (Parent (N)) = N_Compilation_Unit_Aux
8098 Subp := Unit (Parent (Parent (N)));
8100 -- Any other possibility is a misplacement
8106 -- Check correct placement
8108 if Nkind (Subp) /= N_Subprogram_Declaration then
8110 ("pragma% misplaced, must immediately " &
8111 "follow subprogram spec");
8114 -- If OK placement, acquire arguments
8116 Subp := Defining_Entity (Subp);
8118 if Arg_Count >= 1 then
8120 -- Deal with static string argument
8122 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8123 S := Strval (Expression (Arg1));
8125 for J in 1 .. String_Length (S) loop
8126 if not In_Character_Range (Get_String_Char (S, J)) then
8128 ("pragma% argument does not allow wide characters",
8133 Set_Obsolescent_Warning (Subp, Expression (Arg1));
8135 -- Check for Ada_05 parameter
8137 if Arg_Count /= 1 then
8138 Check_Arg_Count (2);
8141 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
8144 Check_Arg_Is_Identifier (Argx);
8146 if Chars (Argx) /= Name_Ada_05 then
8147 Error_Msg_Name_2 := Name_Ada_05;
8149 ("only allowed argument for pragma% is %", Argx);
8152 if Ada_Version_Explicit < Ada_05
8153 or else not Warn_On_Ada_2005_Compatibility
8161 -- Set flag if pragma active
8164 Set_Is_Obsolescent (Subp);
8172 -- pragma No_Run_Time
8174 -- Note: this pragma is retained for backwards compatibiltiy.
8175 -- See body of Rtsfind for full details on its handling.
8177 when Pragma_No_Run_Time =>
8179 Check_Valid_Configuration_Pragma;
8180 Check_Arg_Count (0);
8182 No_Run_Time_Mode := True;
8183 Configurable_Run_Time_Mode := True;
8186 Word32 : constant Boolean := Ttypes.System_Word_Size = 32;
8189 Duration_32_Bits_On_Target := True;
8193 Set_Restriction (No_Finalization, N);
8194 Set_Restriction (No_Exception_Handlers, N);
8195 Set_Restriction (Max_Tasks, N, 0);
8196 Set_Restriction (No_Tasking, N);
8198 -----------------------
8199 -- Normalize_Scalars --
8200 -----------------------
8202 -- pragma Normalize_Scalars;
8204 when Pragma_Normalize_Scalars =>
8205 Check_Ada_83_Warning;
8206 Check_Arg_Count (0);
8207 Check_Valid_Configuration_Pragma;
8208 Normalize_Scalars := True;
8209 Init_Or_Norm_Scalars := True;
8215 -- pragma Optimize (Time | Space);
8217 -- The actual check for optimize is done in Gigi. Note that this
8218 -- pragma does not actually change the optimization setting, it
8219 -- simply checks that it is consistent with the pragma.
8221 when Pragma_Optimize =>
8222 Check_No_Identifiers;
8223 Check_Arg_Count (1);
8224 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
8226 -------------------------
8227 -- Optional_Overriding --
8228 -------------------------
8230 -- These pragmas are treated as part of the previous subprogram
8231 -- declaration, and analyzed immediately after it (see sem_ch6,
8232 -- Check_Overriding_Operation). If the pragma has not been analyzed
8233 -- yet, it appears in the wrong place.
8235 when Pragma_Optional_Overriding =>
8236 Error_Msg_N ("pragma must appear immediately after subprogram", N);
8242 -- pragma Pack (first_subtype_LOCAL_NAME);
8244 when Pragma_Pack => Pack : declare
8245 Assoc : constant Node_Id := Arg1;
8250 Check_No_Identifiers;
8251 Check_Arg_Count (1);
8252 Check_Arg_Is_Local_Name (Arg1);
8254 Type_Id := Expression (Assoc);
8255 Find_Type (Type_Id);
8256 Typ := Entity (Type_Id);
8259 or else Rep_Item_Too_Early (Typ, N)
8263 Typ := Underlying_Type (Typ);
8266 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
8267 Error_Pragma ("pragma% must specify array or record type");
8270 Check_First_Subtype (Arg1);
8272 if Has_Pragma_Pack (Typ) then
8273 Error_Pragma ("duplicate pragma%, only one allowed");
8275 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
8276 -- but not Has_Non_Standard_Rep, because we don't actually know
8277 -- till freeze time if the array can have packed representation.
8278 -- That's because in the general case we do not know enough about
8279 -- the component type until it in turn is frozen, which certainly
8280 -- happens before the array type is frozen, but not necessarily
8281 -- till that point (i.e. right now it may be unfrozen).
8283 elsif Is_Array_Type (Typ) then
8284 if Has_Aliased_Components (Base_Type (Typ)) then
8286 ("pragma% ignored, cannot pack aliased components?");
8288 elsif Has_Atomic_Components (Typ)
8289 or else Is_Atomic (Component_Type (Typ))
8292 ("?pragma% ignored, cannot pack atomic components");
8294 elsif not Rep_Item_Too_Late (Typ, N) then
8295 Set_Is_Packed (Base_Type (Typ));
8296 Set_Has_Pragma_Pack (Base_Type (Typ));
8297 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8300 -- Record type. For record types, the pack is always effective
8302 else pragma Assert (Is_Record_Type (Typ));
8303 if not Rep_Item_Too_Late (Typ, N) then
8304 Set_Has_Pragma_Pack (Base_Type (Typ));
8305 Set_Is_Packed (Base_Type (Typ));
8306 Set_Has_Non_Standard_Rep (Base_Type (Typ));
8317 -- There is nothing to do here, since we did all the processing
8318 -- for this pragma in Par.Prag (so that it works properly even in
8319 -- syntax only mode)
8328 -- pragma Passive [(PASSIVE_FORM)];
8330 -- PASSIVE_FORM ::= Semaphore | No
8332 when Pragma_Passive =>
8335 if Nkind (Parent (N)) /= N_Task_Definition then
8336 Error_Pragma ("pragma% must be within task definition");
8339 if Arg_Count /= 0 then
8340 Check_Arg_Count (1);
8341 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
8348 -- pragma Polling (ON | OFF);
8350 when Pragma_Polling =>
8352 Check_Arg_Count (1);
8353 Check_No_Identifiers;
8354 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8355 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
8357 --------------------
8358 -- Persistent_BSS --
8359 --------------------
8361 when Pragma_Persistent_BSS => Persistent_BSS : declare
8368 Check_At_Most_N_Arguments (1);
8370 -- Case of application to specific object (one argument)
8372 if Arg_Count = 1 then
8373 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8375 if not Is_Entity_Name (Expression (Arg1))
8377 (Ekind (Entity (Expression (Arg1))) /= E_Variable
8378 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
8380 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
8383 Ent := Entity (Expression (Arg1));
8384 Decl := Parent (Ent);
8386 if Rep_Item_Too_Late (Ent, N) then
8390 if Present (Expression (Decl)) then
8392 ("object for pragma% cannot have initialization", Arg1);
8395 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
8397 ("object type for pragma% is not potentially persistent",
8402 Make_Linker_Section_Pragma
8403 (Ent, Sloc (N), ".persistent.bss");
8404 Insert_After (N, Prag);
8407 -- Case of use as configuration pragma with no arguments
8410 Check_Valid_Configuration_Pragma;
8411 Persistent_BSS_Mode := True;
8419 -- pragma Preelaborate [(library_unit_NAME)];
8421 -- Set the flag Is_Preelaborated of program unit name entity
8423 when Pragma_Preelaborate => Preelaborate : declare
8424 Pa : constant Node_Id := Parent (N);
8425 Pk : constant Node_Kind := Nkind (Pa);
8429 Check_Ada_83_Warning;
8430 Check_Valid_Library_Unit_Pragma;
8432 if Nkind (N) = N_Null_Statement then
8436 Ent := Find_Lib_Unit_Name;
8438 -- This filters out pragmas inside generic parent then
8439 -- show up inside instantiation
8442 and then not (Pk = N_Package_Specification
8443 and then Present (Generic_Parent (Pa)))
8445 if not Debug_Flag_U then
8446 Set_Is_Preelaborated (Ent);
8447 Set_Suppress_Elaboration_Warnings (Ent);
8452 ---------------------
8453 -- Preelaborate_05 --
8454 ---------------------
8456 -- pragma Preelaborate_05 [(library_unit_NAME)];
8458 -- This pragma is useable only in GNAT_Mode, where it is used like
8459 -- pragma Preelaborate but it is only effective in Ada 2005 mode
8460 -- (otherwise it is ignored). This is used to implement AI-362 which
8461 -- recategorizes some run-time packages in Ada 2005 mode.
8463 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
8468 Check_Valid_Library_Unit_Pragma;
8470 if not GNAT_Mode then
8471 Error_Pragma ("pragma% only available in GNAT mode");
8474 if Nkind (N) = N_Null_Statement then
8478 -- This is one of the few cases where we need to test the value of
8479 -- Ada_Version_Explicit rather than Ada_Version (which is always
8480 -- set to Ada_05 in a predefined unit), we need to know the
8481 -- explicit version set to know if this pragma is active.
8483 if Ada_Version_Explicit >= Ada_05 then
8484 Ent := Find_Lib_Unit_Name;
8485 Set_Is_Preelaborated (Ent);
8486 Set_Suppress_Elaboration_Warnings (Ent);
8488 end Preelaborate_05;
8494 -- pragma Priority (EXPRESSION);
8496 when Pragma_Priority => Priority : declare
8497 P : constant Node_Id := Parent (N);
8501 Check_No_Identifiers;
8502 Check_Arg_Count (1);
8506 if Nkind (P) = N_Subprogram_Body then
8507 Check_In_Main_Program;
8509 Arg := Expression (Arg1);
8510 Analyze_And_Resolve (Arg, Standard_Integer);
8514 if not Is_Static_Expression (Arg) then
8515 Flag_Non_Static_Expr
8516 ("main subprogram priority is not static!", Arg);
8519 -- If constraint error, then we already signalled an error
8521 elsif Raises_Constraint_Error (Arg) then
8524 -- Otherwise check in range
8528 Val : constant Uint := Expr_Value (Arg);
8532 or else Val > Expr_Value (Expression
8533 (Parent (RTE (RE_Max_Priority))))
8536 ("main subprogram priority is out of range", Arg1);
8542 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
8544 -- Task or Protected, must be of type Integer
8546 elsif Nkind (P) = N_Protected_Definition
8548 Nkind (P) = N_Task_Definition
8550 Arg := Expression (Arg1);
8552 -- The expression must be analyzed in the special manner
8553 -- described in "Handling of Default and Per-Object
8554 -- Expressions" in sem.ads.
8556 Analyze_Per_Use_Expression (Arg, Standard_Integer);
8558 if not Is_Static_Expression (Arg) then
8559 Check_Restriction (Static_Priorities, Arg);
8562 -- Anything else is incorrect
8568 if Has_Priority_Pragma (P) then
8569 Error_Pragma ("duplicate pragma% not allowed");
8571 Set_Has_Priority_Pragma (P, True);
8573 if Nkind (P) = N_Protected_Definition
8575 Nkind (P) = N_Task_Definition
8577 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8578 -- exp_ch9 should use this ???
8587 -- pragma Profile (profile_IDENTIFIER);
8589 -- profile_IDENTIFIER => Protected | Ravenscar
8591 when Pragma_Profile =>
8592 Check_Arg_Count (1);
8593 Check_Valid_Configuration_Pragma;
8594 Check_No_Identifiers;
8597 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8599 if Chars (Argx) = Name_Ravenscar then
8600 Set_Ravenscar_Profile (N);
8602 elsif Chars (Argx) = Name_Restricted then
8603 Set_Profile_Restrictions (Restricted, N, Warn => False);
8605 Error_Pragma_Arg ("& is not a valid profile", Argx);
8609 ----------------------
8610 -- Profile_Warnings --
8611 ----------------------
8613 -- pragma Profile_Warnings (profile_IDENTIFIER);
8615 -- profile_IDENTIFIER => Protected | Ravenscar
8617 when Pragma_Profile_Warnings =>
8619 Check_Arg_Count (1);
8620 Check_Valid_Configuration_Pragma;
8621 Check_No_Identifiers;
8624 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
8626 if Chars (Argx) = Name_Ravenscar then
8627 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
8629 elsif Chars (Argx) = Name_Restricted then
8630 Set_Profile_Restrictions (Restricted, N, Warn => True);
8632 Error_Pragma_Arg ("& is not a valid profile", Argx);
8636 --------------------------
8637 -- Propagate_Exceptions --
8638 --------------------------
8640 -- pragma Propagate_Exceptions;
8642 when Pragma_Propagate_Exceptions =>
8644 Check_Arg_Count (0);
8646 if In_Extended_Main_Source_Unit (N) then
8647 Propagate_Exceptions := True;
8654 -- pragma Psect_Object (
8655 -- [Internal =>] LOCAL_NAME,
8656 -- [, [External =>] EXTERNAL_SYMBOL]
8657 -- [, [Size =>] EXTERNAL_SYMBOL]);
8659 when Pragma_Psect_Object | Pragma_Common_Object =>
8660 Psect_Object : declare
8661 Args : Args_List (1 .. 3);
8662 Names : constant Name_List (1 .. 3) := (
8667 Internal : Node_Id renames Args (1);
8668 External : Node_Id renames Args (2);
8669 Size : Node_Id renames Args (3);
8673 procedure Check_Too_Long (Arg : Node_Id);
8674 -- Posts message if the argument is an identifier with more
8675 -- than 31 characters, or a string literal with more than
8676 -- 31 characters, and we are operating under VMS
8678 --------------------
8679 -- Check_Too_Long --
8680 --------------------
8682 procedure Check_Too_Long (Arg : Node_Id) is
8683 X : constant Node_Id := Original_Node (Arg);
8686 if Nkind (X) /= N_String_Literal
8688 Nkind (X) /= N_Identifier
8691 ("inappropriate argument for pragma %", Arg);
8694 if OpenVMS_On_Target then
8695 if (Nkind (X) = N_String_Literal
8696 and then String_Length (Strval (X)) > 31)
8698 (Nkind (X) = N_Identifier
8699 and then Length_Of_Name (Chars (X)) > 31)
8702 ("argument for pragma % is longer than 31 characters",
8708 -- Start of processing for Common_Object/Psect_Object
8712 Gather_Associations (Names, Args);
8713 Process_Extended_Import_Export_Internal_Arg (Internal);
8715 Def_Id := Entity (Internal);
8717 if Ekind (Def_Id) /= E_Constant
8718 and then Ekind (Def_Id) /= E_Variable
8721 ("pragma% must designate an object", Internal);
8724 Check_Too_Long (Internal);
8726 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
8728 ("cannot use pragma% for imported/exported object",
8732 if Is_Concurrent_Type (Etype (Internal)) then
8734 ("cannot specify pragma % for task/protected object",
8738 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
8740 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
8742 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
8745 if Ekind (Def_Id) = E_Constant then
8747 ("cannot specify pragma % for a constant", Internal);
8750 if Is_Record_Type (Etype (Internal)) then
8756 Ent := First_Entity (Etype (Internal));
8757 while Present (Ent) loop
8758 Decl := Declaration_Node (Ent);
8760 if Ekind (Ent) = E_Component
8761 and then Nkind (Decl) = N_Component_Declaration
8762 and then Present (Expression (Decl))
8763 and then Warn_On_Export_Import
8766 ("?object for pragma % has defaults", Internal);
8776 if Present (Size) then
8777 Check_Too_Long (Size);
8780 if Present (External) then
8781 Check_Arg_Is_External_Name (External);
8782 Check_Too_Long (External);
8785 -- If all error tests pass, link pragma on to the rep item chain
8787 Record_Rep_Item (Def_Id, N);
8794 -- pragma Pure [(library_unit_NAME)];
8796 when Pragma_Pure => Pure : declare
8800 Check_Ada_83_Warning;
8801 Check_Valid_Library_Unit_Pragma;
8803 if Nkind (N) = N_Null_Statement then
8807 Ent := Find_Lib_Unit_Name;
8809 Set_Suppress_Elaboration_Warnings (Ent);
8816 -- pragma Pure_05 [(library_unit_NAME)];
8818 -- This pragma is useable only in GNAT_Mode, where it is used like
8819 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
8820 -- it is ignored). It may be used after a pragma Preelaborate, in
8821 -- which case it overrides the effect of the pragma Preelaborate.
8822 -- This is used to implement AI-362 which recategorizes some run-time
8823 -- packages in Ada 2005 mode.
8825 when Pragma_Pure_05 => Pure_05 : declare
8830 Check_Valid_Library_Unit_Pragma;
8832 if not GNAT_Mode then
8833 Error_Pragma ("pragma% only available in GNAT mode");
8835 if Nkind (N) = N_Null_Statement then
8839 -- This is one of the few cases where we need to test the value of
8840 -- Ada_Version_Explicit rather than Ada_Version (which is always
8841 -- set to Ada_05 in a predefined unit), we need to know the
8842 -- explicit version set to know if this pragma is active.
8844 if Ada_Version_Explicit >= Ada_05 then
8845 Ent := Find_Lib_Unit_Name;
8846 Set_Is_Preelaborated (Ent, False);
8848 Set_Suppress_Elaboration_Warnings (Ent);
8856 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8858 when Pragma_Pure_Function => Pure_Function : declare
8862 Effective : Boolean := False;
8866 Check_Arg_Count (1);
8867 Check_Optional_Identifier (Arg1, Name_Entity);
8868 Check_Arg_Is_Local_Name (Arg1);
8869 E_Id := Expression (Arg1);
8871 if Error_Posted (E_Id) then
8875 -- Loop through homonyms (overloadings) of referenced entity
8881 Def_Id := Get_Base_Subprogram (E);
8883 if Ekind (Def_Id) /= E_Function
8884 and then Ekind (Def_Id) /= E_Generic_Function
8885 and then Ekind (Def_Id) /= E_Operator
8888 ("pragma% requires a function name", Arg1);
8891 Set_Is_Pure (Def_Id);
8893 if not Has_Pragma_Pure_Function (Def_Id) then
8894 Set_Has_Pragma_Pure_Function (Def_Id);
8899 exit when No (E) or else Scope (E) /= Current_Scope;
8903 and then Warn_On_Redundant_Constructs
8905 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
8911 --------------------
8912 -- Queuing_Policy --
8913 --------------------
8915 -- pragma Queuing_Policy (policy_IDENTIFIER);
8917 when Pragma_Queuing_Policy => declare
8921 Check_Ada_83_Warning;
8922 Check_Arg_Count (1);
8923 Check_No_Identifiers;
8924 Check_Arg_Is_Queuing_Policy (Arg1);
8925 Check_Valid_Configuration_Pragma;
8926 Get_Name_String (Chars (Expression (Arg1)));
8927 QP := Fold_Upper (Name_Buffer (1));
8929 if Queuing_Policy /= ' '
8930 and then Queuing_Policy /= QP
8932 Error_Msg_Sloc := Queuing_Policy_Sloc;
8933 Error_Pragma ("queuing policy incompatible with policy#");
8935 -- Set new policy, but always preserve System_Location since
8936 -- we like the error message with the run time name.
8939 Queuing_Policy := QP;
8941 if Queuing_Policy_Sloc /= System_Location then
8942 Queuing_Policy_Sloc := Loc;
8947 ---------------------------
8948 -- Remote_Call_Interface --
8949 ---------------------------
8951 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8953 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8954 Cunit_Node : Node_Id;
8955 Cunit_Ent : Entity_Id;
8959 Check_Ada_83_Warning;
8960 Check_Valid_Library_Unit_Pragma;
8962 if Nkind (N) = N_Null_Statement then
8966 Cunit_Node := Cunit (Current_Sem_Unit);
8967 K := Nkind (Unit (Cunit_Node));
8968 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8970 if K = N_Package_Declaration
8971 or else K = N_Generic_Package_Declaration
8972 or else K = N_Subprogram_Declaration
8973 or else K = N_Generic_Subprogram_Declaration
8974 or else (K = N_Subprogram_Body
8975 and then Acts_As_Spec (Unit (Cunit_Node)))
8980 "pragma% must apply to package or subprogram declaration");
8983 Set_Is_Remote_Call_Interface (Cunit_Ent);
8984 end Remote_Call_Interface;
8990 -- pragma Remote_Types [(library_unit_NAME)];
8992 when Pragma_Remote_Types => Remote_Types : declare
8993 Cunit_Node : Node_Id;
8994 Cunit_Ent : Entity_Id;
8997 Check_Ada_83_Warning;
8998 Check_Valid_Library_Unit_Pragma;
9000 if Nkind (N) = N_Null_Statement then
9004 Cunit_Node := Cunit (Current_Sem_Unit);
9005 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9007 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9009 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9012 "pragma% can only apply to a package declaration");
9015 Set_Is_Remote_Types (Cunit_Ent);
9022 -- pragma Ravenscar;
9024 when Pragma_Ravenscar =>
9026 Check_Arg_Count (0);
9027 Check_Valid_Configuration_Pragma;
9028 Set_Ravenscar_Profile (N);
9030 if Warn_On_Obsolescent_Feature then
9032 ("pragma Ravenscar is an obsolescent feature?", N);
9034 ("|use pragma Profile (Ravenscar) instead", N);
9037 -------------------------
9038 -- Restricted_Run_Time --
9039 -------------------------
9041 -- pragma Restricted_Run_Time;
9043 when Pragma_Restricted_Run_Time =>
9045 Check_Arg_Count (0);
9046 Check_Valid_Configuration_Pragma;
9047 Set_Profile_Restrictions (Restricted, N, Warn => False);
9049 if Warn_On_Obsolescent_Feature then
9051 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
9053 ("|use pragma Profile (Restricted) instead", N);
9060 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
9063 -- restriction_IDENTIFIER
9064 -- | restriction_parameter_IDENTIFIER => EXPRESSION
9066 when Pragma_Restrictions =>
9067 Process_Restrictions_Or_Restriction_Warnings;
9069 --------------------------
9070 -- Restriction_Warnings --
9071 --------------------------
9073 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
9076 -- restriction_IDENTIFIER
9077 -- | restriction_parameter_IDENTIFIER => EXPRESSION
9079 when Pragma_Restriction_Warnings =>
9080 Process_Restrictions_Or_Restriction_Warnings;
9086 -- pragma Reviewable;
9088 when Pragma_Reviewable =>
9089 Check_Ada_83_Warning;
9090 Check_Arg_Count (0);
9096 -- pragma Share_Generic (NAME {, NAME});
9098 when Pragma_Share_Generic =>
9100 Process_Generic_List;
9106 -- pragma Shared (LOCAL_NAME);
9108 when Pragma_Shared =>
9110 Process_Atomic_Shared_Volatile;
9112 --------------------
9113 -- Shared_Passive --
9114 --------------------
9116 -- pragma Shared_Passive [(library_unit_NAME)];
9118 -- Set the flag Is_Shared_Passive of program unit name entity
9120 when Pragma_Shared_Passive => Shared_Passive : declare
9121 Cunit_Node : Node_Id;
9122 Cunit_Ent : Entity_Id;
9125 Check_Ada_83_Warning;
9126 Check_Valid_Library_Unit_Pragma;
9128 if Nkind (N) = N_Null_Statement then
9132 Cunit_Node := Cunit (Current_Sem_Unit);
9133 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
9135 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
9137 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
9140 "pragma% can only apply to a package declaration");
9143 Set_Is_Shared_Passive (Cunit_Ent);
9146 ----------------------
9147 -- Source_File_Name --
9148 ----------------------
9150 -- There are five forms for this pragma:
9152 -- pragma Source_File_Name (
9153 -- [UNIT_NAME =>] unit_NAME,
9154 -- BODY_FILE_NAME => STRING_LITERAL
9155 -- [, [INDEX =>] INTEGER_LITERAL]);
9157 -- pragma Source_File_Name (
9158 -- [UNIT_NAME =>] unit_NAME,
9159 -- SPEC_FILE_NAME => STRING_LITERAL
9160 -- [, [INDEX =>] INTEGER_LITERAL]);
9162 -- pragma Source_File_Name (
9163 -- BODY_FILE_NAME => STRING_LITERAL
9164 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9165 -- [, CASING => CASING_SPEC]);
9167 -- pragma Source_File_Name (
9168 -- SPEC_FILE_NAME => STRING_LITERAL
9169 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9170 -- [, CASING => CASING_SPEC]);
9172 -- pragma Source_File_Name (
9173 -- SUBUNIT_FILE_NAME => STRING_LITERAL
9174 -- [, DOT_REPLACEMENT => STRING_LITERAL]
9175 -- [, CASING => CASING_SPEC]);
9177 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
9179 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
9180 -- Source_File_Name (SFN), however their usage is exclusive:
9181 -- SFN can only be used when no project file is used, while
9182 -- SFNP can only be used when a project file is used.
9184 -- No processing here. Processing was completed during parsing,
9185 -- since we need to have file names set as early as possible.
9186 -- Units are loaded well before semantic processing starts.
9188 -- The only processing we defer to this point is the check
9189 -- for correct placement.
9191 when Pragma_Source_File_Name =>
9193 Check_Valid_Configuration_Pragma;
9195 ------------------------------
9196 -- Source_File_Name_Project --
9197 ------------------------------
9199 -- See Source_File_Name for syntax
9201 -- No processing here. Processing was completed during parsing,
9202 -- since we need to have file names set as early as possible.
9203 -- Units are loaded well before semantic processing starts.
9205 -- The only processing we defer to this point is the check
9206 -- for correct placement.
9208 when Pragma_Source_File_Name_Project =>
9210 Check_Valid_Configuration_Pragma;
9212 -- Check that a pragma Source_File_Name_Project is used only
9213 -- in a configuration pragmas file.
9215 -- Pragmas Source_File_Name_Project should only be generated
9216 -- by the Project Manager in configuration pragmas files.
9218 -- This is really an ugly test. It seems to depend on some
9219 -- accidental and undocumented property. At the very least
9220 -- it needs to be documented, but it would be better to have
9221 -- a clean way of testing if we are in a configuration file???
9223 if Present (Parent (N)) then
9225 ("pragma% can only appear in a configuration pragmas file");
9228 ----------------------
9229 -- Source_Reference --
9230 ----------------------
9232 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
9234 -- Nothing to do, all processing completed in Par.Prag, since we
9235 -- need the information for possible parser messages that are output
9237 when Pragma_Source_Reference =>
9244 -- pragma Storage_Size (EXPRESSION);
9246 when Pragma_Storage_Size => Storage_Size : declare
9247 P : constant Node_Id := Parent (N);
9251 Check_No_Identifiers;
9252 Check_Arg_Count (1);
9254 -- The expression must be analyzed in the special manner
9255 -- described in "Handling of Default Expressions" in sem.ads.
9257 -- Set In_Default_Expression for per-object case ???
9259 Arg := Expression (Arg1);
9260 Analyze_Per_Use_Expression (Arg, Any_Integer);
9262 if not Is_Static_Expression (Arg) then
9263 Check_Restriction (Static_Storage_Size, Arg);
9266 if Nkind (P) /= N_Task_Definition then
9271 if Has_Storage_Size_Pragma (P) then
9272 Error_Pragma ("duplicate pragma% not allowed");
9274 Set_Has_Storage_Size_Pragma (P, True);
9277 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9278 -- ??? exp_ch9 should use this!
9286 -- pragma Storage_Unit (NUMERIC_LITERAL);
9288 -- Only permitted argument is System'Storage_Unit value
9290 when Pragma_Storage_Unit =>
9291 Check_No_Identifiers;
9292 Check_Arg_Count (1);
9293 Check_Arg_Is_Integer_Literal (Arg1);
9295 if Intval (Expression (Arg1)) /=
9296 UI_From_Int (Ttypes.System_Storage_Unit)
9298 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
9300 ("the only allowed argument for pragma% is ^", Arg1);
9303 --------------------
9304 -- Stream_Convert --
9305 --------------------
9307 -- pragma Stream_Convert (
9308 -- [Entity =>] type_LOCAL_NAME,
9309 -- [Read =>] function_NAME,
9310 -- [Write =>] function NAME);
9312 when Pragma_Stream_Convert => Stream_Convert : declare
9314 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
9315 -- Check that the given argument is the name of a local
9316 -- function of one argument that is not overloaded earlier
9317 -- in the current local scope. A check is also made that the
9318 -- argument is a function with one parameter.
9320 --------------------------------------
9321 -- Check_OK_Stream_Convert_Function --
9322 --------------------------------------
9324 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
9328 Check_Arg_Is_Local_Name (Arg);
9329 Ent := Entity (Expression (Arg));
9331 if Has_Homonym (Ent) then
9333 ("argument for pragma% may not be overloaded", Arg);
9336 if Ekind (Ent) /= E_Function
9337 or else No (First_Formal (Ent))
9338 or else Present (Next_Formal (First_Formal (Ent)))
9341 ("argument for pragma% must be" &
9342 " function of one argument", Arg);
9344 end Check_OK_Stream_Convert_Function;
9346 -- Start of procecessing for Stream_Convert
9350 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
9351 Check_Arg_Count (3);
9352 Check_Optional_Identifier (Arg1, Name_Entity);
9353 Check_Optional_Identifier (Arg2, Name_Read);
9354 Check_Optional_Identifier (Arg3, Name_Write);
9355 Check_Arg_Is_Local_Name (Arg1);
9356 Check_OK_Stream_Convert_Function (Arg2);
9357 Check_OK_Stream_Convert_Function (Arg3);
9360 Typ : constant Entity_Id :=
9361 Underlying_Type (Entity (Expression (Arg1)));
9362 Read : constant Entity_Id := Entity (Expression (Arg2));
9363 Write : constant Entity_Id := Entity (Expression (Arg3));
9366 if Etype (Typ) = Any_Type
9368 Etype (Read) = Any_Type
9370 Etype (Write) = Any_Type
9375 Check_First_Subtype (Arg1);
9377 if Rep_Item_Too_Early (Typ, N)
9379 Rep_Item_Too_Late (Typ, N)
9384 if Underlying_Type (Etype (Read)) /= Typ then
9386 ("incorrect return type for function&", Arg2);
9389 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
9391 ("incorrect parameter type for function&", Arg3);
9394 if Underlying_Type (Etype (First_Formal (Read))) /=
9395 Underlying_Type (Etype (Write))
9398 ("result type of & does not match Read parameter type",
9404 -------------------------
9405 -- Style_Checks (GNAT) --
9406 -------------------------
9408 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9410 -- This is processed by the parser since some of the style
9411 -- checks take place during source scanning and parsing. This
9412 -- means that we don't need to issue error messages here.
9414 when Pragma_Style_Checks => Style_Checks : declare
9415 A : constant Node_Id := Expression (Arg1);
9421 Check_No_Identifiers;
9423 -- Two argument form
9425 if Arg_Count = 2 then
9426 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9433 E_Id := Expression (Arg2);
9436 if not Is_Entity_Name (E_Id) then
9438 ("second argument of pragma% must be entity name",
9448 Set_Suppress_Style_Checks (E,
9449 (Chars (Expression (Arg1)) = Name_Off));
9450 exit when No (Homonym (E));
9456 -- One argument form
9459 Check_Arg_Count (1);
9461 if Nkind (A) = N_String_Literal then
9465 Slen : constant Natural := Natural (String_Length (S));
9466 Options : String (1 .. Slen);
9472 C := Get_String_Char (S, Int (J));
9473 exit when not In_Character_Range (C);
9474 Options (J) := Get_Character (C);
9477 Set_Style_Check_Options (Options);
9485 elsif Nkind (A) = N_Identifier then
9487 if Chars (A) = Name_All_Checks then
9488 Set_Default_Style_Check_Options;
9490 elsif Chars (A) = Name_On then
9491 Style_Check := True;
9493 elsif Chars (A) = Name_Off then
9494 Style_Check := False;
9505 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
9507 when Pragma_Subtitle =>
9509 Check_Arg_Count (1);
9510 Check_Optional_Identifier (Arg1, Name_Subtitle);
9511 Check_Arg_Is_String_Literal (Arg1);
9517 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
9519 when Pragma_Suppress =>
9520 Process_Suppress_Unsuppress (True);
9526 -- pragma Suppress_All;
9528 -- The only check made here is that the pragma appears in the
9529 -- proper place, i.e. following a compilation unit. If indeed
9530 -- it appears in this context, then the parser has already
9531 -- inserted an equivalent pragma Suppress (All_Checks) to get
9532 -- the required effect.
9534 when Pragma_Suppress_All =>
9536 Check_Arg_Count (0);
9538 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
9539 or else not Is_List_Member (N)
9540 or else List_Containing (N) /= Pragmas_After (Parent (N))
9543 ("misplaced pragma%, must follow compilation unit");
9546 -------------------------
9547 -- Suppress_Debug_Info --
9548 -------------------------
9550 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
9552 when Pragma_Suppress_Debug_Info =>
9554 Check_Arg_Count (1);
9555 Check_Optional_Identifier (Arg1, Name_Entity);
9556 Check_Arg_Is_Local_Name (Arg1);
9557 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
9559 ----------------------------------
9560 -- Suppress_Exception_Locations --
9561 ----------------------------------
9563 -- pragma Suppress_Exception_Locations;
9565 when Pragma_Suppress_Exception_Locations =>
9567 Check_Arg_Count (0);
9568 Check_Valid_Configuration_Pragma;
9569 Exception_Locations_Suppressed := True;
9571 -----------------------------
9572 -- Suppress_Initialization --
9573 -----------------------------
9575 -- pragma Suppress_Initialization ([Entity =>] type_Name);
9577 when Pragma_Suppress_Initialization => Suppress_Init : declare
9583 Check_Arg_Count (1);
9584 Check_Optional_Identifier (Arg1, Name_Entity);
9585 Check_Arg_Is_Local_Name (Arg1);
9587 E_Id := Expression (Arg1);
9589 if Etype (E_Id) = Any_Type then
9596 if Is_Incomplete_Or_Private_Type (E) then
9597 if No (Full_View (Base_Type (E))) then
9599 ("argument of pragma% cannot be an incomplete type",
9602 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
9605 Set_Suppress_Init_Proc (Base_Type (E));
9610 ("pragma% requires argument that is a type name", Arg1);
9618 -- pragma System_Name (DIRECT_NAME);
9620 -- Syntax check: one argument, which must be the identifier GNAT
9621 -- or the identifier GCC, no other identifiers are acceptable.
9623 when Pragma_System_Name =>
9624 Check_No_Identifiers;
9625 Check_Arg_Count (1);
9626 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
9628 -----------------------------
9629 -- Task_Dispatching_Policy --
9630 -----------------------------
9632 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
9634 when Pragma_Task_Dispatching_Policy => declare
9638 Check_Ada_83_Warning;
9639 Check_Arg_Count (1);
9640 Check_No_Identifiers;
9641 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9642 Check_Valid_Configuration_Pragma;
9643 Get_Name_String (Chars (Expression (Arg1)));
9644 DP := Fold_Upper (Name_Buffer (1));
9646 if Task_Dispatching_Policy /= ' '
9647 and then Task_Dispatching_Policy /= DP
9649 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9651 ("task dispatching policy incompatible with policy#");
9653 -- Set new policy, but always preserve System_Location since
9654 -- we like the error message with the run time name.
9657 Task_Dispatching_Policy := DP;
9659 if Task_Dispatching_Policy_Sloc /= System_Location then
9660 Task_Dispatching_Policy_Sloc := Loc;
9669 -- pragma Task_Info (EXPRESSION);
9671 when Pragma_Task_Info => Task_Info : declare
9672 P : constant Node_Id := Parent (N);
9677 if Nkind (P) /= N_Task_Definition then
9678 Error_Pragma ("pragma% must appear in task definition");
9681 Check_No_Identifiers;
9682 Check_Arg_Count (1);
9684 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
9686 if Etype (Expression (Arg1)) = Any_Type then
9690 if Has_Task_Info_Pragma (P) then
9691 Error_Pragma ("duplicate pragma% not allowed");
9693 Set_Has_Task_Info_Pragma (P, True);
9701 -- pragma Task_Name (string_EXPRESSION);
9703 when Pragma_Task_Name => Task_Name : declare
9704 -- pragma Priority (EXPRESSION);
9706 P : constant Node_Id := Parent (N);
9710 Check_No_Identifiers;
9711 Check_Arg_Count (1);
9713 Arg := Expression (Arg1);
9714 Analyze_And_Resolve (Arg, Standard_String);
9716 if Nkind (P) /= N_Task_Definition then
9720 if Has_Task_Name_Pragma (P) then
9721 Error_Pragma ("duplicate pragma% not allowed");
9723 Set_Has_Task_Name_Pragma (P, True);
9724 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9732 -- pragma Task_Storage (
9733 -- [Task_Type =>] LOCAL_NAME,
9734 -- [Top_Guard =>] static_integer_EXPRESSION);
9736 when Pragma_Task_Storage => Task_Storage : declare
9737 Args : Args_List (1 .. 2);
9738 Names : constant Name_List (1 .. 2) := (
9742 Task_Type : Node_Id renames Args (1);
9743 Top_Guard : Node_Id renames Args (2);
9749 Gather_Associations (Names, Args);
9751 if No (Task_Type) then
9753 ("missing task_type argument for pragma%");
9756 Check_Arg_Is_Local_Name (Task_Type);
9758 Ent := Entity (Task_Type);
9760 if not Is_Task_Type (Ent) then
9762 ("argument for pragma% must be task type", Task_Type);
9765 if No (Top_Guard) then
9767 ("pragma% takes two arguments", Task_Type);
9769 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9772 Check_First_Subtype (Task_Type);
9774 if Rep_Item_Too_Late (Ent, N) then
9783 -- pragma Thread_Body
9784 -- ( [Entity =>] LOCAL_NAME
9785 -- [,[Secondary_Stack_Size =>] static_integer_EXPRESSION]);
9787 when Pragma_Thread_Body => Thread_Body : declare
9794 Check_Arg_Order ((Name_Entity, Name_Secondary_Stack_Size));
9795 Check_At_Least_N_Arguments (1);
9796 Check_At_Most_N_Arguments (2);
9797 Check_Optional_Identifier (Arg1, Name_Entity);
9798 Check_Arg_Is_Local_Name (Arg1);
9800 Id := Expression (Arg1);
9802 if not Is_Entity_Name (Id)
9803 or else not Is_Subprogram (Entity (Id))
9805 Error_Pragma_Arg ("subprogram name required", Arg1);
9810 -- Go to renamed subprogram if present, since Thread_Body applies
9811 -- to the actual renamed entity, not to the renaming entity.
9813 if Present (Alias (E))
9814 and then Nkind (Parent (Declaration_Node (E))) =
9815 N_Subprogram_Renaming_Declaration
9820 -- Various error checks
9822 if Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body then
9824 ("pragma% requires separate spec and must come before body");
9826 elsif Rep_Item_Too_Early (E, N)
9828 Rep_Item_Too_Late (E, N)
9832 elsif Is_Thread_Body (E) then
9834 ("only one thread body pragma allowed", Arg1);
9836 elsif Present (Homonym (E))
9837 and then Scope (Homonym (E)) = Current_Scope
9840 ("thread body subprogram must not be overloaded", Arg1);
9843 Set_Is_Thread_Body (E);
9845 -- Deal with secondary stack argument
9847 if Arg_Count = 2 then
9848 Check_Optional_Identifier (Arg2, Name_Secondary_Stack_Size);
9849 SS := Expression (Arg2);
9850 Analyze_And_Resolve (SS, Any_Integer);
9858 -- pragma Time_Slice (static_duration_EXPRESSION);
9860 when Pragma_Time_Slice => Time_Slice : declare
9866 Check_Arg_Count (1);
9867 Check_No_Identifiers;
9868 Check_In_Main_Program;
9869 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9871 if not Error_Posted (Arg1) then
9873 while Present (Nod) loop
9874 if Nkind (Nod) = N_Pragma
9875 and then Chars (Nod) = Name_Time_Slice
9877 Error_Msg_Name_1 := Chars (N);
9878 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9885 -- Process only if in main unit
9887 if Get_Source_Unit (Loc) = Main_Unit then
9888 Opt.Time_Slice_Set := True;
9889 Val := Expr_Value_R (Expression (Arg1));
9891 if Val <= Ureal_0 then
9892 Opt.Time_Slice_Value := 0;
9894 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9895 Opt.Time_Slice_Value := 1_000_000_000;
9898 Opt.Time_Slice_Value :=
9899 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9908 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9910 -- TITLING_OPTION ::=
9911 -- [Title =>] STRING_LITERAL
9912 -- | [Subtitle =>] STRING_LITERAL
9914 when Pragma_Title => Title : declare
9915 Args : Args_List (1 .. 2);
9916 Names : constant Name_List (1 .. 2) := (
9922 Gather_Associations (Names, Args);
9924 for J in 1 .. 2 loop
9925 if Present (Args (J)) then
9926 Check_Arg_Is_String_Literal (Args (J));
9931 ---------------------
9932 -- Unchecked_Union --
9933 ---------------------
9935 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9937 when Pragma_Unchecked_Union => Unchecked_Union : declare
9938 Assoc : constant Node_Id := Arg1;
9939 Type_Id : constant Node_Id := Expression (Assoc);
9950 Check_No_Identifiers;
9951 Check_Arg_Count (1);
9952 Check_Arg_Is_Local_Name (Arg1);
9954 Find_Type (Type_Id);
9955 Typ := Entity (Type_Id);
9958 or else Rep_Item_Too_Early (Typ, N)
9962 Typ := Underlying_Type (Typ);
9965 if Rep_Item_Too_Late (Typ, N) then
9969 Check_First_Subtype (Arg1);
9971 -- Note remaining cases are references to a type in the current
9972 -- declarative part. If we find an error, we post the error on
9973 -- the relevant type declaration at an appropriate point.
9975 if not Is_Record_Type (Typ) then
9976 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9979 elsif Is_Tagged_Type (Typ) then
9980 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9983 elsif Is_Limited_Type (Typ) then
9985 ("Unchecked_Union must not be limited record type", Typ);
9986 Explain_Limited_Type (Typ, Typ);
9990 if not Has_Discriminants (Typ) then
9992 ("Unchecked_Union must have one discriminant", Typ);
9996 Discr := First_Discriminant (Typ);
9998 if Present (Next_Discriminant (Discr)) then
10000 ("Unchecked_Union must have exactly one discriminant",
10001 Next_Discriminant (Discr));
10005 if No (Discriminant_Default_Value (Discr)) then
10007 ("Unchecked_Union discriminant must have default value",
10011 Tdef := Type_Definition (Declaration_Node (Typ));
10012 Clist := Component_List (Tdef);
10014 Comp := First (Component_Items (Clist));
10015 while Present (Comp) loop
10017 Check_Component (Comp);
10022 if No (Clist) or else No (Variant_Part (Clist)) then
10024 ("Unchecked_Union must have variant part",
10029 Vpart := Variant_Part (Clist);
10031 Variant := First (Variants (Vpart));
10032 while Present (Variant) loop
10033 Check_Variant (Variant);
10038 Set_Is_Unchecked_Union (Typ, True);
10039 Set_Convention (Typ, Convention_C);
10041 Set_Has_Unchecked_Union (Base_Type (Typ), True);
10042 Set_Is_Unchecked_Union (Base_Type (Typ), True);
10043 end Unchecked_Union;
10045 ------------------------
10046 -- Unimplemented_Unit --
10047 ------------------------
10049 -- pragma Unimplemented_Unit;
10051 -- Note: this only gives an error if we are generating code,
10052 -- or if we are in a generic library unit (where the pragma
10053 -- appears in the body, not in the spec).
10055 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
10056 Cunitent : constant Entity_Id :=
10057 Cunit_Entity (Get_Source_Unit (Loc));
10058 Ent_Kind : constant Entity_Kind :=
10063 Check_Arg_Count (0);
10065 if Operating_Mode = Generate_Code
10066 or else Ent_Kind = E_Generic_Function
10067 or else Ent_Kind = E_Generic_Procedure
10068 or else Ent_Kind = E_Generic_Package
10070 Get_Name_String (Chars (Cunitent));
10071 Set_Casing (Mixed_Case);
10072 Write_Str (Name_Buffer (1 .. Name_Len));
10073 Write_Str (" is not implemented");
10075 raise Unrecoverable_Error;
10077 end Unimplemented_Unit;
10079 --------------------
10080 -- Universal_Data --
10081 --------------------
10083 -- pragma Universal_Data [(library_unit_NAME)];
10085 when Pragma_Universal_Data =>
10088 -- If this is a configuration pragma, then set the universal
10089 -- addressing option, otherwise confirm that the pragma
10090 -- satisfies the requirements of library unit pragma placement
10091 -- and leave it to the GNAAMP back end to detect the pragma
10092 -- (avoids transitive setting of the option due to withed units).
10094 if Is_Configuration_Pragma then
10095 Universal_Addressing_On_AAMP := True;
10097 Check_Valid_Library_Unit_Pragma;
10100 if not AAMP_On_Target then
10101 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
10108 -- pragma Unreferenced (local_Name {, local_Name});
10110 when Pragma_Unreferenced => Unreferenced : declare
10111 Arg_Node : Node_Id;
10112 Arg_Expr : Node_Id;
10113 Arg_Ent : Entity_Id;
10117 Check_At_Least_N_Arguments (1);
10120 while Present (Arg_Node) loop
10121 Check_No_Identifier (Arg_Node);
10123 -- Note that the analyze call done by Check_Arg_Is_Local_Name
10124 -- will in fact generate a reference, so that the entity will
10125 -- have a reference, which will inhibit any warnings about it
10126 -- not being referenced, and also properly show up in the ali
10127 -- file as a reference. But this reference is recorded before
10128 -- the Has_Pragma_Unreferenced flag is set, so that no warning
10129 -- is generated for this reference.
10131 Check_Arg_Is_Local_Name (Arg_Node);
10132 Arg_Expr := Get_Pragma_Arg (Arg_Node);
10134 if Is_Entity_Name (Arg_Expr) then
10135 Arg_Ent := Entity (Arg_Expr);
10137 -- If the entity is overloaded, the pragma applies to the
10138 -- most recent overloading, as documented. In this case,
10139 -- name resolution does not generate a reference, so it
10140 -- must be done here explicitly.
10142 if Is_Overloaded (Arg_Expr) then
10143 Generate_Reference (Arg_Ent, N);
10146 Set_Has_Pragma_Unreferenced (Arg_Ent);
10153 ------------------------------
10154 -- Unreserve_All_Interrupts --
10155 ------------------------------
10157 -- pragma Unreserve_All_Interrupts;
10159 when Pragma_Unreserve_All_Interrupts =>
10161 Check_Arg_Count (0);
10163 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
10164 Unreserve_All_Interrupts := True;
10171 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
10173 when Pragma_Unsuppress =>
10175 Process_Suppress_Unsuppress (False);
10177 -------------------
10178 -- Use_VADS_Size --
10179 -------------------
10181 -- pragma Use_VADS_Size;
10183 when Pragma_Use_VADS_Size =>
10185 Check_Arg_Count (0);
10186 Check_Valid_Configuration_Pragma;
10187 Use_VADS_Size := True;
10189 ---------------------
10190 -- Validity_Checks --
10191 ---------------------
10193 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10195 when Pragma_Validity_Checks => Validity_Checks : declare
10196 A : constant Node_Id := Expression (Arg1);
10202 Check_Arg_Count (1);
10203 Check_No_Identifiers;
10205 if Nkind (A) = N_String_Literal then
10209 Slen : constant Natural := Natural (String_Length (S));
10210 Options : String (1 .. Slen);
10216 C := Get_String_Char (S, Int (J));
10217 exit when not In_Character_Range (C);
10218 Options (J) := Get_Character (C);
10221 Set_Validity_Check_Options (Options);
10229 elsif Nkind (A) = N_Identifier then
10231 if Chars (A) = Name_All_Checks then
10232 Set_Validity_Check_Options ("a");
10234 elsif Chars (A) = Name_On then
10235 Validity_Checks_On := True;
10237 elsif Chars (A) = Name_Off then
10238 Validity_Checks_On := False;
10242 end Validity_Checks;
10248 -- pragma Volatile (LOCAL_NAME);
10250 when Pragma_Volatile =>
10251 Process_Atomic_Shared_Volatile;
10253 -------------------------
10254 -- Volatile_Components --
10255 -------------------------
10257 -- pragma Volatile_Components (array_LOCAL_NAME);
10259 -- Volatile is handled by the same circuit as Atomic_Components
10265 -- pragma Warnings (On | Off, [LOCAL_NAME])
10267 when Pragma_Warnings => Warnings : begin
10269 Check_At_Least_N_Arguments (1);
10270 Check_At_Most_N_Arguments (2);
10271 Check_No_Identifiers;
10273 -- One argument case was processed by parser in Par.Prag
10275 if Arg_Count /= 1 then
10276 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10277 Check_Arg_Count (2);
10284 E_Id := Expression (Arg2);
10287 -- In the expansion of an inlined body, a reference to
10288 -- the formal may be wrapped in a conversion if the actual
10289 -- is a conversion. Retrieve the real entity name.
10291 if (In_Instance_Body
10292 or else In_Inlined_Body)
10293 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
10295 E_Id := Expression (E_Id);
10298 if not Is_Entity_Name (E_Id) then
10300 ("second argument of pragma% must be entity name",
10304 E := Entity (E_Id);
10310 Set_Warnings_Off (E,
10311 (Chars (Expression (Arg1)) = Name_Off));
10313 if Is_Enumeration_Type (E) then
10317 Lit := First_Literal (E);
10318 while Present (Lit) loop
10319 Set_Warnings_Off (Lit);
10320 Next_Literal (Lit);
10325 exit when No (Homonym (E));
10333 -------------------
10334 -- Weak_External --
10335 -------------------
10337 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
10339 when Pragma_Weak_External => Weak_External : declare
10344 Check_Arg_Count (1);
10345 Check_Optional_Identifier (Arg1, Name_Entity);
10346 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10347 Ent := Entity (Expression (Arg1));
10349 if Rep_Item_Too_Early (Ent, N) then
10352 Ent := Underlying_Type (Ent);
10355 -- The only processing required is to link this item on to the
10356 -- list of rep items for the given entity. This is accomplished
10357 -- by the call to Rep_Item_Too_Late (when no error is detected
10358 -- and False is returned).
10360 if Rep_Item_Too_Late (Ent, N) then
10363 Set_Has_Gigi_Rep_Item (Ent);
10367 --------------------
10368 -- Unknown_Pragma --
10369 --------------------
10371 -- Should be impossible, since the case of an unknown pragma is
10372 -- separately processed before the case statement is entered.
10374 when Unknown_Pragma =>
10375 raise Program_Error;
10379 when Pragma_Exit => null;
10380 end Analyze_Pragma;
10382 ---------------------------------
10383 -- Delay_Config_Pragma_Analyze --
10384 ---------------------------------
10386 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
10388 return Chars (N) = Name_Interrupt_State;
10389 end Delay_Config_Pragma_Analyze;
10391 -------------------------
10392 -- Get_Base_Subprogram --
10393 -------------------------
10395 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
10396 Result : Entity_Id;
10399 -- Follow subprogram renaming chain
10402 while Is_Subprogram (Result)
10404 (Is_Generic_Instance (Result)
10405 or else Nkind (Parent (Declaration_Node (Result))) =
10406 N_Subprogram_Renaming_Declaration)
10407 and then Present (Alias (Result))
10409 Result := Alias (Result);
10413 end Get_Base_Subprogram;
10415 -----------------------------
10416 -- Is_Config_Static_String --
10417 -----------------------------
10419 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
10421 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
10422 -- This is an internal recursive function that is just like the
10423 -- outer function except that it adds the string to the name buffer
10424 -- rather than placing the string in the name buffer.
10426 ------------------------------
10427 -- Add_Config_Static_String --
10428 ------------------------------
10430 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
10437 if Nkind (N) = N_Op_Concat then
10438 if Add_Config_Static_String (Left_Opnd (N)) then
10439 N := Right_Opnd (N);
10445 if Nkind (N) /= N_String_Literal then
10446 Error_Msg_N ("string literal expected for pragma argument", N);
10450 for J in 1 .. String_Length (Strval (N)) loop
10451 C := Get_String_Char (Strval (N), J);
10453 if not In_Character_Range (C) then
10455 ("string literal contains invalid wide character",
10456 Sloc (N) + 1 + Source_Ptr (J));
10460 Add_Char_To_Name_Buffer (Get_Character (C));
10465 end Add_Config_Static_String;
10467 -- Start of prorcessing for Is_Config_Static_String
10472 return Add_Config_Static_String (Arg);
10473 end Is_Config_Static_String;
10475 -----------------------------------------
10476 -- Is_Non_Significant_Pragma_Reference --
10477 -----------------------------------------
10479 -- This function makes use of the following static table which indicates
10480 -- whether a given pragma is significant. A value of -1 in this table
10481 -- indicates that the reference is significant. A value of zero indicates
10482 -- than appearence as any argument is insignificant, a positive value
10483 -- indicates that appearence in that parameter position is significant.
10485 Sig_Flags : constant array (Pragma_Id) of Int :=
10487 (Pragma_AST_Entry => -1,
10488 Pragma_Abort_Defer => -1,
10489 Pragma_Ada_83 => -1,
10490 Pragma_Ada_95 => -1,
10491 Pragma_Ada_05 => -1,
10492 Pragma_All_Calls_Remote => -1,
10493 Pragma_Annotate => -1,
10494 Pragma_Assert => -1,
10495 Pragma_Assertion_Policy => 0,
10496 Pragma_Asynchronous => -1,
10497 Pragma_Atomic => 0,
10498 Pragma_Atomic_Components => 0,
10499 Pragma_Attach_Handler => -1,
10500 Pragma_CPP_Class => 0,
10501 Pragma_CPP_Constructor => 0,
10502 Pragma_CPP_Virtual => 0,
10503 Pragma_CPP_Vtable => 0,
10504 Pragma_C_Pass_By_Copy => 0,
10505 Pragma_Comment => 0,
10506 Pragma_Common_Object => -1,
10507 Pragma_Compile_Time_Warning => -1,
10508 Pragma_Complex_Representation => 0,
10509 Pragma_Component_Alignment => -1,
10510 Pragma_Controlled => 0,
10511 Pragma_Convention => 0,
10512 Pragma_Convention_Identifier => 0,
10513 Pragma_Debug => -1,
10514 Pragma_Detect_Blocking => -1,
10515 Pragma_Discard_Names => 0,
10516 Pragma_Elaborate => -1,
10517 Pragma_Elaborate_All => -1,
10518 Pragma_Elaborate_Body => -1,
10519 Pragma_Elaboration_Checks => -1,
10520 Pragma_Eliminate => -1,
10521 Pragma_Explicit_Overriding => -1,
10522 Pragma_Export => -1,
10523 Pragma_Export_Exception => -1,
10524 Pragma_Export_Function => -1,
10525 Pragma_Export_Object => -1,
10526 Pragma_Export_Procedure => -1,
10527 Pragma_Export_Value => -1,
10528 Pragma_Export_Valued_Procedure => -1,
10529 Pragma_Extend_System => -1,
10530 Pragma_Extensions_Allowed => -1,
10531 Pragma_External => -1,
10532 Pragma_External_Name_Casing => -1,
10533 Pragma_Finalize_Storage_Only => 0,
10534 Pragma_Float_Representation => 0,
10535 Pragma_Ident => -1,
10536 Pragma_Import => +2,
10537 Pragma_Import_Exception => 0,
10538 Pragma_Import_Function => 0,
10539 Pragma_Import_Object => 0,
10540 Pragma_Import_Procedure => 0,
10541 Pragma_Import_Valued_Procedure => 0,
10542 Pragma_Initialize_Scalars => -1,
10543 Pragma_Inline => 0,
10544 Pragma_Inline_Always => 0,
10545 Pragma_Inline_Generic => 0,
10546 Pragma_Inspection_Point => -1,
10547 Pragma_Interface => +2,
10548 Pragma_Interface_Name => +2,
10549 Pragma_Interrupt_Handler => -1,
10550 Pragma_Interrupt_Priority => -1,
10551 Pragma_Interrupt_State => -1,
10552 Pragma_Java_Constructor => -1,
10553 Pragma_Java_Interface => -1,
10554 Pragma_Keep_Names => 0,
10555 Pragma_License => -1,
10556 Pragma_Link_With => -1,
10557 Pragma_Linker_Alias => -1,
10558 Pragma_Linker_Options => -1,
10559 Pragma_Linker_Section => -1,
10561 Pragma_Locking_Policy => -1,
10562 Pragma_Long_Float => -1,
10563 Pragma_Machine_Attribute => -1,
10565 Pragma_Main_Storage => -1,
10566 Pragma_Memory_Size => -1,
10567 Pragma_No_Return => 0,
10568 Pragma_No_Run_Time => -1,
10569 Pragma_No_Strict_Aliasing => -1,
10570 Pragma_Normalize_Scalars => -1,
10571 Pragma_Obsolescent => 0,
10572 Pragma_Optimize => -1,
10573 Pragma_Optional_Overriding => -1,
10576 Pragma_Passive => -1,
10577 Pragma_Polling => -1,
10578 Pragma_Persistent_BSS => 0,
10579 Pragma_Preelaborate => -1,
10580 Pragma_Preelaborate_05 => -1,
10581 Pragma_Priority => -1,
10582 Pragma_Profile => 0,
10583 Pragma_Profile_Warnings => 0,
10584 Pragma_Propagate_Exceptions => -1,
10585 Pragma_Psect_Object => -1,
10587 Pragma_Pure_05 => -1,
10588 Pragma_Pure_Function => -1,
10589 Pragma_Queuing_Policy => -1,
10590 Pragma_Ravenscar => -1,
10591 Pragma_Remote_Call_Interface => -1,
10592 Pragma_Remote_Types => -1,
10593 Pragma_Restricted_Run_Time => -1,
10594 Pragma_Restriction_Warnings => -1,
10595 Pragma_Restrictions => -1,
10596 Pragma_Reviewable => -1,
10597 Pragma_Share_Generic => -1,
10598 Pragma_Shared => -1,
10599 Pragma_Shared_Passive => -1,
10600 Pragma_Source_File_Name => -1,
10601 Pragma_Source_File_Name_Project => -1,
10602 Pragma_Source_Reference => -1,
10603 Pragma_Storage_Size => -1,
10604 Pragma_Storage_Unit => -1,
10605 Pragma_Stream_Convert => -1,
10606 Pragma_Style_Checks => -1,
10607 Pragma_Subtitle => -1,
10608 Pragma_Suppress => 0,
10609 Pragma_Suppress_Exception_Locations => 0,
10610 Pragma_Suppress_All => -1,
10611 Pragma_Suppress_Debug_Info => 0,
10612 Pragma_Suppress_Initialization => 0,
10613 Pragma_System_Name => -1,
10614 Pragma_Task_Dispatching_Policy => -1,
10615 Pragma_Task_Info => -1,
10616 Pragma_Task_Name => -1,
10617 Pragma_Task_Storage => 0,
10618 Pragma_Thread_Body => +2,
10619 Pragma_Time_Slice => -1,
10620 Pragma_Title => -1,
10621 Pragma_Unchecked_Union => 0,
10622 Pragma_Unimplemented_Unit => -1,
10623 Pragma_Universal_Data => -1,
10624 Pragma_Unreferenced => -1,
10625 Pragma_Unreserve_All_Interrupts => -1,
10626 Pragma_Unsuppress => 0,
10627 Pragma_Use_VADS_Size => -1,
10628 Pragma_Validity_Checks => -1,
10629 Pragma_Volatile => 0,
10630 Pragma_Volatile_Components => 0,
10631 Pragma_Warnings => -1,
10632 Pragma_Weak_External => 0,
10633 Unknown_Pragma => 0);
10635 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
10643 if Nkind (P) /= N_Pragma_Argument_Association then
10647 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
10657 A := First (Pragma_Argument_Associations (Parent (P)));
10658 for J in 1 .. C - 1 loop
10669 end Is_Non_Significant_Pragma_Reference;
10671 ------------------------------
10672 -- Is_Pragma_String_Literal --
10673 ------------------------------
10675 -- This function returns true if the corresponding pragma argument is
10676 -- a static string expression. These are the only cases in which string
10677 -- literals can appear as pragma arguments. We also allow a string
10678 -- literal as the first argument to pragma Assert (although it will
10679 -- of course always generate a type error).
10681 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
10682 Pragn : constant Node_Id := Parent (Par);
10683 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
10684 Pname : constant Name_Id := Chars (Pragn);
10690 N := First (Assoc);
10697 if Pname = Name_Assert then
10700 elsif Pname = Name_Export then
10703 elsif Pname = Name_Ident then
10706 elsif Pname = Name_Import then
10709 elsif Pname = Name_Interface_Name then
10712 elsif Pname = Name_Linker_Alias then
10715 elsif Pname = Name_Linker_Section then
10718 elsif Pname = Name_Machine_Attribute then
10721 elsif Pname = Name_Source_File_Name then
10724 elsif Pname = Name_Source_Reference then
10727 elsif Pname = Name_Title then
10730 elsif Pname = Name_Subtitle then
10736 end Is_Pragma_String_Literal;
10738 --------------------------------------
10739 -- Process_Compilation_Unit_Pragmas --
10740 --------------------------------------
10742 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
10744 -- A special check for pragma Suppress_All. This is a strange DEC
10745 -- pragma, strange because it comes at the end of the unit. If we
10746 -- have a pragma Suppress_All in the Pragmas_After of the current
10747 -- unit, then we insert a pragma Suppress (All_Checks) at the start
10748 -- of the context clause to ensure the correct processing.
10751 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
10755 if Present (PA) then
10757 while Present (P) loop
10758 if Chars (P) = Name_Suppress_All then
10759 Prepend_To (Context_Items (N),
10760 Make_Pragma (Sloc (P),
10761 Chars => Name_Suppress,
10762 Pragma_Argument_Associations => New_List (
10763 Make_Pragma_Argument_Association (Sloc (P),
10765 Make_Identifier (Sloc (P),
10766 Chars => Name_All_Checks)))));
10774 end Process_Compilation_Unit_Pragmas;
10776 --------------------------------
10777 -- Set_Encoded_Interface_Name --
10778 --------------------------------
10780 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
10781 Str : constant String_Id := Strval (S);
10782 Len : constant Int := String_Length (Str);
10787 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
10790 -- Stores encoded value of character code CC. The encoding we
10791 -- use an underscore followed by four lower case hex digits.
10797 procedure Encode is
10799 Store_String_Char (Get_Char_Code ('_'));
10801 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
10803 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
10805 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
10807 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10810 -- Start of processing for Set_Encoded_Interface_Name
10813 -- If first character is asterisk, this is a link name, and we
10814 -- leave it completely unmodified. We also ignore null strings
10815 -- (the latter case happens only in error cases) and no encoding
10816 -- should occur for Java interface names.
10819 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10822 Set_Interface_Name (E, S);
10827 CC := Get_String_Char (Str, J);
10829 exit when not In_Character_Range (CC);
10831 C := Get_Character (CC);
10833 exit when C /= '_' and then C /= '$'
10834 and then C not in '0' .. '9'
10835 and then C not in 'a' .. 'z'
10836 and then C not in 'A' .. 'Z';
10839 Set_Interface_Name (E, S);
10847 -- Here we need to encode. The encoding we use as follows:
10848 -- three underscores + four hex digits (lower case)
10852 for J in 1 .. String_Length (Str) loop
10853 CC := Get_String_Char (Str, J);
10855 if not In_Character_Range (CC) then
10858 C := Get_Character (CC);
10860 if C = '_' or else C = '$'
10861 or else C in '0' .. '9'
10862 or else C in 'a' .. 'z'
10863 or else C in 'A' .. 'Z'
10865 Store_String_Char (CC);
10872 Set_Interface_Name (E,
10873 Make_String_Literal (Sloc (S),
10874 Strval => End_String));
10876 end Set_Encoded_Interface_Name;
10878 -------------------
10879 -- Set_Unit_Name --
10880 -------------------
10882 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10887 if Nkind (N) = N_Identifier
10888 and then Nkind (With_Item) = N_Identifier
10890 Set_Entity (N, Entity (With_Item));
10892 elsif Nkind (N) = N_Selected_Component then
10893 Change_Selected_Component_To_Expanded_Name (N);
10894 Set_Entity (N, Entity (With_Item));
10895 Set_Entity (Selector_Name (N), Entity (N));
10897 Pref := Prefix (N);
10898 Scop := Scope (Entity (N));
10899 while Nkind (Pref) = N_Selected_Component loop
10900 Change_Selected_Component_To_Expanded_Name (Pref);
10901 Set_Entity (Selector_Name (Pref), Scop);
10902 Set_Entity (Pref, Scop);
10903 Pref := Prefix (Pref);
10904 Scop := Scope (Scop);
10907 Set_Entity (Pref, Scop);