1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This unit contains the semantic processing for all pragmas, both language
28 -- and implementation defined. For most pragmas, the parser only does the
29 -- most basic job of checking the syntax, so Sem_Prag also contains the code
30 -- to complete the syntax checks. Certain pragmas are handled partially or
31 -- completely by the parser (see Par.Prag for further details).
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Expander; use Expander;
41 with Exp_Dist; use Exp_Dist;
42 with Fname; use Fname;
43 with Hostparm; use Hostparm;
45 with 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 Rtsfind; use Rtsfind;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Ch13; use Sem_Ch13;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Elim; use Sem_Elim;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Intr; use Sem_Intr;
59 with Sem_Mech; use Sem_Mech;
60 with Sem_Res; use Sem_Res;
61 with Sem_Type; use Sem_Type;
62 with Sem_Util; use Sem_Util;
63 with Sem_VFpt; use Sem_VFpt;
64 with Stand; use Stand;
65 with Sinfo; use Sinfo;
66 with Sinfo.CN; use Sinfo.CN;
67 with Sinput; use Sinput;
68 with Snames; use Snames;
69 with Stringt; use Stringt;
70 with Stylesw; use Stylesw;
71 with Targparm; use Targparm;
72 with Tbuild; use Tbuild;
74 with Uintp; use Uintp;
75 with Urealp; use Urealp;
76 with Validsw; use Validsw;
78 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
80 package body Sem_Prag is
82 ----------------------------------------------
83 -- Common Handling of Import-Export Pragmas --
84 ----------------------------------------------
86 -- In the following section, a number of Import_xxx and Export_xxx
87 -- pragmas are defined by GNAT. These are compatible with the DEC
88 -- pragmas of the same name, and all have the following common
89 -- form and processing:
92 -- [Internal =>] LOCAL_NAME,
93 -- [, [External =>] EXTERNAL_SYMBOL]
94 -- [, other optional parameters ]);
97 -- [Internal =>] LOCAL_NAME,
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
101 -- EXTERNAL_SYMBOL ::=
103 -- | static_string_EXPRESSION
105 -- The internal LOCAL_NAME designates the entity that is imported or
106 -- exported, and must refer to an entity in the current declarative
107 -- part (as required by the rules for LOCAL_NAME).
109 -- The external linker name is designated by the External parameter
110 -- if given, or the Internal parameter if not (if there is no External
111 -- parameter, the External parameter is a copy of the Internal name).
113 -- If the External parameter is given as a string, then this string
114 -- is treated as an external name (exactly as though it had been given
115 -- as an External_Name parameter for a normal Import pragma).
117 -- If the External parameter is given as an identifier (or there is no
118 -- External parameter, so that the Internal identifier is used), then
119 -- the external name is the characters of the identifier, translated
120 -- to all upper case letters for OpenVMS versions of GNAT, and to all
121 -- lower case letters for all other versions
123 -- Note: the external name specified or implied by any of these special
124 -- Import_xxx or Export_xxx pragmas override an external or link name
125 -- specified in a previous Import or Export pragma.
127 -- Note: these and all other DEC-compatible GNAT pragmas allow full
128 -- use of named notation, following the standard rules for subprogram
129 -- calls, i.e. parameters can be given in any order if named notation
130 -- is used, and positional and named notation can be mixed, subject to
131 -- the rule that all positional parameters must appear first.
133 -- Note: All these pragmas are implemented exactly following the DEC
134 -- design and implementation and are intended to be fully compatible
135 -- with the use of these pragmas in the DEC Ada compiler.
137 -------------------------------------
138 -- Local Subprograms and Variables --
139 -------------------------------------
141 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
142 -- This routine is used for possible casing adjustment of an explicit
143 -- external name supplied as a string literal (the node N), according
144 -- to the casing requirement of Opt.External_Name_Casing. If this is
145 -- set to As_Is, then the string literal is returned unchanged, but if
146 -- it is set to Uppercase or Lowercase, then a new string literal with
147 -- appropriate casing is constructed.
149 function Is_Generic_Subprogram (Id : Entity_Id) return Boolean;
150 -- Return True if Id is a generic procedure or a function
152 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
153 -- If Def_Id refers to a renamed subprogram, then the base subprogram
154 -- (the original one, following the renaming chain) is returned.
155 -- Otherwise the entity is returned unchanged. Should be in Einfo???
157 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
158 -- Place semantic information on the argument of an Elaborate or
159 -- Elaborate_All pragma. Entity name for unit and its parents is
160 -- taken from item in previous with_clause that mentions the unit.
162 Locking_Policy_Sloc : Source_Ptr := No_Location;
163 Queuing_Policy_Sloc : Source_Ptr := No_Location;
164 Task_Dispatching_Policy_Sloc : Source_Ptr := No_Location;
165 -- These global variables remember the location of a previous locking,
166 -- queuing or task dispatching policy pragma, so that appropriate error
167 -- messages can be generated for inconsistent pragmas. Note that it is
168 -- fine that these are global locations, because the check for consistency
169 -- is over the entire program.
171 -------------------------------
172 -- Adjust_External_Name_Case --
173 -------------------------------
175 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
179 -- Adjust case of literal if required
181 if Opt.External_Name_Exp_Casing = As_Is then
185 -- Copy existing string
191 for J in 1 .. String_Length (Strval (N)) loop
192 CC := Get_String_Char (Strval (N), J);
194 if Opt.External_Name_Exp_Casing = Uppercase
195 and then CC >= Get_Char_Code ('a')
196 and then CC <= Get_Char_Code ('z')
198 Store_String_Char (CC - 32);
200 elsif Opt.External_Name_Exp_Casing = Lowercase
201 and then CC >= Get_Char_Code ('A')
202 and then CC <= Get_Char_Code ('Z')
204 Store_String_Char (CC + 32);
207 Store_String_Char (CC);
212 Make_String_Literal (Sloc (N),
213 Strval => End_String);
215 end Adjust_External_Name_Case;
221 procedure Analyze_Pragma (N : Node_Id) is
222 Loc : constant Source_Ptr := Sloc (N);
225 Pragma_Exit : exception;
226 -- This exception is used to exit pragma processing completely. It
227 -- is used when an error is detected, and in other situations where
228 -- it is known that no further processing is required.
231 -- Number of pragma argument associations
237 -- First four pragma arguments (pragma argument association nodes,
238 -- or Empty if the corresponding argument does not exist).
240 procedure Check_Ada_83_Warning;
241 -- Issues a warning message for the current pragma if operating in Ada
242 -- 83 mode (used for language pragmas that are not a standard part of
243 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
246 procedure Check_Arg_Count (Required : Nat);
247 -- Check argument count for pragma is equal to given parameter.
248 -- If not, then issue an error message and raise Pragma_Exit.
250 -- Note: all routines whose name is Check_Arg_Is_xxx take an
251 -- argument Arg which can either be a pragma argument association,
252 -- in which case the check is applied to the expression of the
253 -- association or an expression directly.
255 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
256 -- Check the specified argument Arg to make sure that it is an
257 -- identifier. If not give error and raise Pragma_Exit.
259 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
260 -- Check the specified argument Arg to make sure that it is an
261 -- integer literal. If not give error and raise Pragma_Exit.
263 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
264 -- Check the specified argument Arg to make sure that it has the
265 -- proper syntactic form for a local name and meets the semantic
266 -- requirements for a local name. The local name is analyzed as
267 -- part of the processing for this call. In addition, the local
268 -- name is required to represent an entity at the library level.
270 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
271 -- Check the specified argument Arg to make sure that it has the
272 -- proper syntactic form for a local name and meets the semantic
273 -- requirements for a local name. The local name is analyzed as
274 -- part of the processing for this call.
276 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
277 -- Check the specified argument Arg to make sure that it is a valid
278 -- locking policy name. If not give error and raise Pragma_Exit.
280 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
281 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
282 -- Check the specified argument Arg to make sure that it is an
283 -- identifier whose name matches either N1 or N2 (or N3 if present).
284 -- If not then give error and raise Pragma_Exit.
286 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
287 -- Check the specified argument Arg to make sure that it is a valid
288 -- queuing policy name. If not give error and raise Pragma_Exit.
290 procedure Check_Arg_Is_Static_Expression
293 -- Check the specified argument Arg to make sure that it is a static
294 -- expression of the given type (i.e. it will be analyzed and resolved
295 -- using this type, which can be any valid argument to Resolve, e.g.
296 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
298 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
299 -- Check the specified argument Arg to make sure that it is a
300 -- string literal. If not give error and raise Pragma_Exit
302 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
303 -- Check the specified argument Arg to make sure that it is a valid
304 -- valid task dispatching policy name. If not give error and raise
307 procedure Check_At_Least_N_Arguments (N : Nat);
308 -- Check there are at least N arguments present
310 procedure Check_At_Most_N_Arguments (N : Nat);
311 -- Check there are no more than N arguments present
313 procedure Check_First_Subtype (Arg : Node_Id);
314 -- Checks that Arg, whose expression is an entity name referencing
315 -- a subtype, does not reference a type that is not a first subtype.
317 procedure Check_In_Main_Program;
318 -- Common checks for pragmas that appear within a main program
319 -- (Priority, Main_Storage, Time_Slice).
321 procedure Check_Interrupt_Or_Attach_Handler;
322 -- Common processing for first argument of pragma Interrupt_Handler
323 -- or pragma Attach_Handler.
325 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
326 -- Check that pragma appears in a declarative part, or in a package
327 -- specification, i.e. that it does not occur in a statement sequence
330 procedure Check_No_Identifier (Arg : Node_Id);
331 -- Checks that the given argument does not have an identifier. If
332 -- an identifier is present, then an error message is issued, and
333 -- Pragma_Exit is raised.
335 procedure Check_No_Identifiers;
336 -- Checks that none of the arguments to the pragma has an identifier.
337 -- If any argument has an identifier, then an error message is issued,
338 -- and Pragma_Exit is raised.
340 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
341 -- Checks if the given argument has an identifier, and if so, requires
342 -- it to match the given identifier name. If there is a non-matching
343 -- identifier, then an error message is given and Error_Pragmas raised.
345 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
346 -- Checks if the given argument has an identifier, and if so, requires
347 -- it to match the given identifier name. If there is a non-matching
348 -- identifier, then an error message is given and Error_Pragmas raised.
349 -- In this version of the procedure, the identifier name is given as
350 -- a string with lower case letters.
352 procedure Check_Static_Constraint (Constr : Node_Id);
353 -- Constr is a constraint from an N_Subtype_Indication node from a
354 -- component constraint in an Unchecked_Union type. This routine checks
355 -- that the constraint is static as required by the restrictions for
358 procedure Check_Valid_Configuration_Pragma;
359 -- Legality checks for placement of a configuration pragma
361 procedure Check_Valid_Library_Unit_Pragma;
362 -- Legality checks for library unit pragmas. A special case arises for
363 -- pragmas in generic instances that come from copies of the original
364 -- library unit pragmas in the generic templates. In the case of other
365 -- than library level instantiations these can appear in contexts which
366 -- would normally be invalid (they only apply to the original template
367 -- and to library level instantiations), and they are simply ignored,
368 -- which is implemented by rewriting them as null statements.
370 procedure Error_Pragma (Msg : String);
371 pragma No_Return (Error_Pragma);
372 -- Outputs error message for current pragma. The message contains an %
373 -- that will be replaced with the pragma name, and the flag is placed
374 -- on the pragma itself. Pragma_Exit is then raised.
376 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
377 pragma No_Return (Error_Pragma_Arg);
378 -- Outputs error message for current pragma. The message may contain
379 -- a % that will be replaced with the pragma name. The parameter Arg
380 -- may either be a pragma argument association, in which case the flag
381 -- is placed on the expression of this association, or an expression,
382 -- in which case the flag is placed directly on the expression. The
383 -- message is placed using Error_Msg_N, so the message may also contain
384 -- an & insertion character which will reference the given Arg value.
385 -- After placing the message, Pragma_Exit is raised.
387 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
388 pragma No_Return (Error_Pragma_Arg);
389 -- Similar to above form of Error_Pragma_Arg except that two messages
390 -- are provided, the second is a continuation comment starting with \.
392 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
393 pragma No_Return (Error_Pragma_Arg_Ident);
394 -- Outputs error message for current pragma. The message may contain
395 -- a % that will be replaced with the pragma name. The parameter Arg
396 -- must be a pragma argument association with a non-empty identifier
397 -- (i.e. its Chars field must be set), and the error message is placed
398 -- on the identifier. The message is placed using Error_Msg_N so
399 -- the message may also contain an & insertion character which will
400 -- reference the identifier. After placing the message, Pragma_Exit
403 function Find_Lib_Unit_Name return Entity_Id;
404 -- Used for a library unit pragma to find the entity to which the
405 -- library unit pragma applies, returns the entity found.
407 procedure Find_Program_Unit_Name (Id : Node_Id);
408 -- If the pragma is a compilation unit pragma, the id must denote the
409 -- compilation unit in the same compilation, and the pragma must appear
410 -- in the list of preceding or trailing pragmas. If it is a program
411 -- unit pragma that is not a compilation unit pragma, then the
412 -- identifier must be visible.
414 type Name_List is array (Natural range <>) of Name_Id;
415 type Args_List is array (Natural range <>) of Node_Id;
416 procedure Gather_Associations
418 Args : out Args_List);
419 -- This procedure is used to gather the arguments for a pragma that
420 -- permits arbitrary ordering of parameters using the normal rules
421 -- for named and positional parameters. The Names argument is a list
422 -- of Name_Id values that corresponds to the allowed pragma argument
423 -- association identifiers in order. The result returned in Args is
424 -- a list of corresponding expressions that are the pragma arguments.
425 -- Note that this is a list of expressions, not of pragma argument
426 -- associations (Gather_Associations has completely checked all the
427 -- optional identifiers when it returns). An entry in Args is Empty
428 -- on return if the corresponding argument is not present.
430 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
431 -- All the routines that check pragma arguments take either a pragma
432 -- argument association (in which case the expression of the argument
433 -- association is checked), or the expression directly. The function
434 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
435 -- Arg is a pragma argument association node, then its expression is
436 -- returned, otherwise Arg is returned unchanged.
438 procedure GNAT_Pragma;
439 -- Called for all GNAT defined pragmas to note the use of the feature,
440 -- and also check the relevant restriction (No_Implementation_Pragmas).
442 function Is_Before_First_Decl
443 (Pragma_Node : Node_Id;
446 -- Return True if Pragma_Node is before the first declarative item in
447 -- Decls where Decls is the list of declarative items.
449 function Is_Configuration_Pragma return Boolean;
450 -- Deterermines if the placement of the current pragma is appropriate
451 -- for a configuration pragma (precedes the current compilation unit)
453 procedure Pragma_Misplaced;
454 -- Issue fatal error message for misplaced pragma
456 procedure Process_Atomic_Shared_Volatile;
457 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
458 -- Shared is an obsolete Ada 83 pragma, treated as being identical
459 -- in effect to pragma Atomic.
461 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
462 -- Common procesing for Convention, Interface, Import and Export.
463 -- Checks first two arguments of pragma, and sets the appropriate
464 -- convention value in the specified entity or entities. On return
465 -- C is the convention, E is the referenced entity.
467 procedure Process_Extended_Import_Export_Exception_Pragma
468 (Arg_Internal : Node_Id;
469 Arg_External : Node_Id;
472 -- Common processing for the pragmas Import/Export_Exception.
473 -- The three arguments correspond to the three named parameters of
474 -- the pragma. An argument is empty if the corresponding parameter
475 -- is not present in the pragma.
477 procedure Process_Extended_Import_Export_Object_Pragma
478 (Arg_Internal : Node_Id;
479 Arg_External : Node_Id;
481 -- Common processing for the pragmass Import/Export_Object.
482 -- The three arguments correspond to the three named parameters
483 -- of the pragmas. An argument is empty if the corresponding
484 -- parameter is not present in the pragma.
486 procedure Process_Extended_Import_Export_Internal_Arg
487 (Arg_Internal : Node_Id := Empty);
488 -- Common processing for all extended Import and Export pragmas. The
489 -- argument is the pragma parameter for the Internal argument. If
490 -- Arg_Internal is empty or inappropriate, an error message is posted.
491 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
492 -- set to identify the referenced entity.
494 procedure Process_Extended_Import_Export_Subprogram_Pragma
495 (Arg_Internal : Node_Id;
496 Arg_External : Node_Id;
497 Arg_Parameter_Types : Node_Id;
498 Arg_Result_Type : Node_Id := Empty;
499 Arg_Mechanism : Node_Id;
500 Arg_Result_Mechanism : Node_Id := Empty;
501 Arg_First_Optional_Parameter : Node_Id := Empty);
502 -- Common processing for all extended Import and Export pragmas
503 -- applying to subprograms. The caller omits any arguments that do
504 -- bnot apply to the pragma in question (for example, Arg_Result_Type
505 -- can be non-Empty only in the Import_Function and Export_Function
506 -- cases). The argument names correspond to the allowed pragma
507 -- association identifiers.
509 procedure Process_Generic_List;
510 -- Common processing for Share_Generic and Inline_Generic
512 procedure Process_Import_Or_Interface;
513 -- Common processing for Import of Interface
515 procedure Process_Inline (Active : Boolean);
516 -- Common processing for Inline and Inline_Always. The parameter
517 -- indicates if the inline pragma is active, i.e. if it should
518 -- actually cause inlining to occur.
520 procedure Process_Interface_Name
521 (Subprogram_Def : Entity_Id;
524 -- Given the last two arguments of pragma Import, pragma Export, or
525 -- pragma Interface_Name, performs validity checks and sets the
526 -- Interface_Name field of the given subprogram entity to the
527 -- appropriate external or link name, depending on the arguments
528 -- given. Ext_Arg is always present, but Link_Arg may be missing.
529 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
530 -- missing, and appropriate named notation is used for Ext_Arg.
531 -- If neither Ext_Arg nor Link_Arg is present, the interface name
532 -- is set to the default from the subprogram name.
534 procedure Process_Interrupt_Or_Attach_Handler;
535 -- Attach the pragmas to the rep item chain.
537 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
538 -- Common processing for Suppress and Unsuppress. The boolean parameter
539 -- Suppress_Case is True for the Suppress case, and False for the
542 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
543 -- This procedure sets the Is_Exported flag for the given entity,
544 -- checking that the entity was not previously imported. Arg is
545 -- the argument that specified the entity.
547 procedure Set_Extended_Import_Export_External_Name
548 (Internal_Ent : Entity_Id;
549 Arg_External : Node_Id);
550 -- Common processing for all extended import export pragmas. The first
551 -- argument, Internal_Ent, is the internal entity, which has already
552 -- been checked for validity by the caller. Arg_External is from the
553 -- Import or Export pragma, and may be null if no External parameter
554 -- was present. If Arg_External is present and is a non-null string
555 -- (a null string is treated as the default), then the Interface_Name
556 -- field of Internal_Ent is set appropriately.
558 procedure Set_Imported (E : Entity_Id);
559 -- This procedure sets the Is_Imported flag for the given entity,
560 -- checking that it is not previously exported or imported.
562 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
563 -- Mech is a parameter passing mechanism (see Import_Function syntax
564 -- for MECHANISM_NAME). This routine checks that the mechanism argument
565 -- has the right form, and if not issues an error message. If the
566 -- argument has the right form then the Mechanism field of Ent is
567 -- set appropriately.
569 --------------------------
570 -- Check_Ada_83_Warning --
571 --------------------------
573 procedure Check_Ada_83_Warning is
575 if Ada_83 and then Comes_From_Source (N) then
576 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
578 end Check_Ada_83_Warning;
580 ---------------------
581 -- Check_Arg_Count --
582 ---------------------
584 procedure Check_Arg_Count (Required : Nat) is
586 if Arg_Count /= Required then
587 Error_Pragma ("wrong number of arguments for pragma%");
591 -----------------------------
592 -- Check_Arg_Is_Identifier --
593 -----------------------------
595 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
596 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
599 if Nkind (Argx) /= N_Identifier then
601 ("argument for pragma% must be identifier", Argx);
603 end Check_Arg_Is_Identifier;
605 ----------------------------------
606 -- Check_Arg_Is_Integer_Literal --
607 ----------------------------------
609 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
610 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
613 if Nkind (Argx) /= N_Integer_Literal then
615 ("argument for pragma% must be integer literal", Argx);
617 end Check_Arg_Is_Integer_Literal;
619 -------------------------------------------
620 -- Check_Arg_Is_Library_Level_Local_Name --
621 -------------------------------------------
625 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
626 -- | library_unit_NAME
628 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
630 Check_Arg_Is_Local_Name (Arg);
632 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
633 and then Comes_From_Source (N)
636 ("argument for pragma% must be library level entity", Arg);
638 end Check_Arg_Is_Library_Level_Local_Name;
640 -----------------------------
641 -- Check_Arg_Is_Local_Name --
642 -----------------------------
646 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
647 -- | library_unit_NAME
649 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
650 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
655 if Nkind (Argx) not in N_Direct_Name
656 and then (Nkind (Argx) /= N_Attribute_Reference
657 or else Present (Expressions (Argx))
658 or else Nkind (Prefix (Argx)) /= N_Identifier)
659 and then (not Is_Entity_Name (Argx)
660 or else not Is_Compilation_Unit (Entity (Argx)))
662 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
665 if Is_Entity_Name (Argx)
666 and then Scope (Entity (Argx)) /= Current_Scope
669 ("pragma% argument must be in same declarative part", Arg);
671 end Check_Arg_Is_Local_Name;
673 ---------------------------------
674 -- Check_Arg_Is_Locking_Policy --
675 ---------------------------------
677 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
678 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
681 Check_Arg_Is_Identifier (Argx);
683 if not Is_Locking_Policy_Name (Chars (Argx)) then
685 ("& is not a valid locking policy name", Argx);
687 end Check_Arg_Is_Locking_Policy;
689 -------------------------
690 -- Check_Arg_Is_One_Of --
691 -------------------------
693 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
694 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
697 Check_Arg_Is_Identifier (Argx);
699 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
700 Error_Msg_Name_2 := N1;
701 Error_Msg_Name_3 := N2;
702 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
704 end Check_Arg_Is_One_Of;
706 procedure Check_Arg_Is_One_Of
708 N1, N2, N3 : Name_Id)
710 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
713 Check_Arg_Is_Identifier (Argx);
715 if Chars (Argx) /= N1
716 and then Chars (Argx) /= N2
717 and then Chars (Argx) /= N3
719 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
721 end Check_Arg_Is_One_Of;
723 ---------------------------------
724 -- Check_Arg_Is_Queuing_Policy --
725 ---------------------------------
727 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
728 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
731 Check_Arg_Is_Identifier (Argx);
733 if not Is_Queuing_Policy_Name (Chars (Argx)) then
735 ("& is not a valid queuing policy name", Argx);
737 end Check_Arg_Is_Queuing_Policy;
739 ------------------------------------
740 -- Check_Arg_Is_Static_Expression --
741 ------------------------------------
743 procedure Check_Arg_Is_Static_Expression
747 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
750 Analyze_And_Resolve (Argx, Typ);
752 if Is_OK_Static_Expression (Argx) then
755 elsif Etype (Argx) = Any_Type then
758 -- An interesting special case, if we have a string literal and
759 -- we are in Ada 83 mode, then we allow it even though it will
760 -- not be flagged as static. This allows the use of Ada 95
761 -- pragmas like Import in Ada 83 mode. They will of course be
762 -- flagged with warnings as usual, but will not cause errors.
764 elsif Ada_83 and then Nkind (Argx) = N_String_Literal then
767 -- Static expression that raises Constraint_Error. This has
768 -- already been flagged, so just exit from pragma processing.
770 elsif Is_Static_Expression (Argx) then
773 -- Finally, we have a real error
777 ("argument for pragma% must be a static expression", Argx);
780 end Check_Arg_Is_Static_Expression;
782 ---------------------------------
783 -- Check_Arg_Is_String_Literal --
784 ---------------------------------
786 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
787 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
790 if Nkind (Argx) /= N_String_Literal then
792 ("argument for pragma% must be string literal", Argx);
795 end Check_Arg_Is_String_Literal;
797 ------------------------------------------
798 -- Check_Arg_Is_Task_Dispatching_Policy --
799 ------------------------------------------
801 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
802 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
805 Check_Arg_Is_Identifier (Argx);
807 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
809 ("& is not a valid task dispatching policy name", Argx);
811 end Check_Arg_Is_Task_Dispatching_Policy;
813 --------------------------------
814 -- Check_At_Least_N_Arguments --
815 --------------------------------
817 procedure Check_At_Least_N_Arguments (N : Nat) is
819 if Arg_Count < N then
820 Error_Pragma ("too few arguments for pragma%");
822 end Check_At_Least_N_Arguments;
824 -------------------------------
825 -- Check_At_Most_N_Arguments --
826 -------------------------------
828 procedure Check_At_Most_N_Arguments (N : Nat) is
832 if Arg_Count > N then
837 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
840 end Check_At_Most_N_Arguments;
842 -------------------------
843 -- Check_First_Subtype --
844 -------------------------
846 procedure Check_First_Subtype (Arg : Node_Id) is
847 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
850 if not Is_First_Subtype (Entity (Argx)) then
852 ("pragma% cannot apply to subtype", Argx);
854 end Check_First_Subtype;
856 ---------------------------
857 -- Check_In_Main_Program --
858 ---------------------------
860 procedure Check_In_Main_Program is
861 P : constant Node_Id := Parent (N);
864 -- Must be at in subprogram body
866 if Nkind (P) /= N_Subprogram_Body then
867 Error_Pragma ("% pragma allowed only in subprogram");
869 -- Otherwise warn if obviously not main program
871 elsif Present (Parameter_Specifications (Specification (P)))
872 or else not Is_Library_Level_Entity (Defining_Entity (P))
874 Error_Msg_Name_1 := Chars (N);
876 ("?pragma% is only effective in main program", N);
878 end Check_In_Main_Program;
880 ---------------------------------------
881 -- Check_Interrupt_Or_Attach_Handler --
882 ---------------------------------------
884 procedure Check_Interrupt_Or_Attach_Handler is
885 Arg1_X : constant Node_Id := Expression (Arg1);
890 if not Is_Entity_Name (Arg1_X) then
892 ("argument of pragma% must be entity name", Arg1);
894 elsif Prag_Id = Pragma_Interrupt_Handler then
895 Check_Restriction (No_Dynamic_Interrupts, N);
899 Prot_Proc : Entity_Id := Empty;
900 Prot_Type : Entity_Id;
901 Found : Boolean := False;
904 if not Is_Overloaded (Arg1_X) then
905 Prot_Proc := Entity (Arg1_X);
910 Index : Interp_Index;
913 Get_First_Interp (Arg1_X, Index, It);
914 while Present (It.Nam) loop
917 if Ekind (Prot_Proc) = E_Procedure
918 and then No (First_Formal (Prot_Proc))
922 Set_Entity (Arg1_X, Prot_Proc);
923 Set_Is_Overloaded (Arg1_X, False);
926 ("ambiguous handler name for pragma% ", Arg1);
930 Get_Next_Interp (Index, It);
935 ("argument of pragma% must be parameterless procedure",
938 Prot_Proc := Entity (Arg1_X);
943 Prot_Type := Scope (Prot_Proc);
945 if Ekind (Prot_Proc) /= E_Procedure
946 or else Ekind (Prot_Type) /= E_Protected_Type
949 ("argument of pragma% must be protected procedure",
953 if not Is_Library_Level_Entity (Prot_Type) then
955 ("pragma% requires library level entity", Arg1);
958 if Present (First_Formal (Prot_Proc)) then
960 ("argument of pragma% must be parameterless procedure",
965 Protected_Definition (Parent (Prot_Type))
967 Error_Pragma ("pragma% must be in protected definition");
971 end Check_Interrupt_Or_Attach_Handler;
973 -------------------------------------------
974 -- Check_Is_In_Decl_Part_Or_Package_Spec --
975 -------------------------------------------
977 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
986 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
989 elsif Nkind (P) = N_Package_Specification then
992 elsif Nkind (P) = N_Block_Statement then
995 -- Note: the following tests seem a little peculiar, because
996 -- they test for bodies, but if we were in the statement part
997 -- of the body, we would already have hit the handled statement
998 -- sequence, so the only way we get here is by being in the
999 -- declarative part of the body.
1001 elsif Nkind (P) = N_Subprogram_Body
1002 or else Nkind (P) = N_Package_Body
1003 or else Nkind (P) = N_Task_Body
1004 or else Nkind (P) = N_Entry_Body
1012 Error_Pragma ("pragma% is not in declarative part or package spec");
1014 end Check_Is_In_Decl_Part_Or_Package_Spec;
1016 -------------------------
1017 -- Check_No_Identifier --
1018 -------------------------
1020 procedure Check_No_Identifier (Arg : Node_Id) is
1022 if Chars (Arg) /= No_Name then
1023 Error_Pragma_Arg_Ident
1024 ("pragma% does not permit identifier& here", Arg);
1026 end Check_No_Identifier;
1028 --------------------------
1029 -- Check_No_Identifiers --
1030 --------------------------
1032 procedure Check_No_Identifiers is
1036 if Arg_Count > 0 then
1039 while Present (Arg_Node) loop
1040 Check_No_Identifier (Arg_Node);
1044 end Check_No_Identifiers;
1046 -------------------------------
1047 -- Check_Optional_Identifier --
1048 -------------------------------
1050 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1052 if Present (Arg) and then Chars (Arg) /= No_Name then
1053 if Chars (Arg) /= Id then
1054 Error_Msg_Name_1 := Chars (N);
1055 Error_Msg_Name_2 := Id;
1056 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1060 end Check_Optional_Identifier;
1062 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1064 Name_Buffer (1 .. Id'Length) := Id;
1065 Name_Len := Id'Length;
1066 Check_Optional_Identifier (Arg, Name_Find);
1067 end Check_Optional_Identifier;
1069 -----------------------------
1070 -- Check_Static_Constraint --
1071 -----------------------------
1073 -- Note: for convenience in writing this procedure, in addition to
1074 -- the officially (i.e. by spec) allowed argument which is always
1075 -- a constraint, it also allows ranges and discriminant associations.
1077 procedure Check_Static_Constraint (Constr : Node_Id) is
1079 --------------------
1080 -- Require_Static --
1081 --------------------
1083 procedure Require_Static (E : Node_Id);
1084 -- Require given expression to be static expression
1086 procedure Require_Static (E : Node_Id) is
1088 if not Is_OK_Static_Expression (E) then
1090 ("non-static constraint not allowed in Unchecked_Union", E);
1095 -- Start of processing for Check_Static_Constraint
1098 case Nkind (Constr) is
1099 when N_Discriminant_Association =>
1100 Require_Static (Expression (Constr));
1103 Require_Static (Low_Bound (Constr));
1104 Require_Static (High_Bound (Constr));
1106 when N_Attribute_Reference =>
1107 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1108 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1110 when N_Range_Constraint =>
1111 Check_Static_Constraint (Range_Expression (Constr));
1113 when N_Index_Or_Discriminant_Constraint =>
1115 IDC : Entity_Id := First (Constraints (Constr));
1118 while Present (IDC) loop
1119 Check_Static_Constraint (IDC);
1127 end Check_Static_Constraint;
1129 --------------------------------------
1130 -- Check_Valid_Configuration_Pragma --
1131 --------------------------------------
1133 -- A configuration pragma must appear in the context clause of
1134 -- a compilation unit, at the start of the list (i.e. only other
1135 -- pragmas may precede it).
1137 procedure Check_Valid_Configuration_Pragma is
1139 if not Is_Configuration_Pragma then
1140 Error_Pragma ("incorrect placement for configuration pragma%");
1142 end Check_Valid_Configuration_Pragma;
1144 -------------------------------------
1145 -- Check_Valid_Library_Unit_Pragma --
1146 -------------------------------------
1148 procedure Check_Valid_Library_Unit_Pragma is
1150 Parent_Node : Node_Id;
1151 Unit_Name : Entity_Id;
1152 Valid : Boolean := True;
1153 Unit_Kind : Node_Kind;
1154 Unit_Node : Node_Id;
1155 Sindex : Source_File_Index;
1158 if not Is_List_Member (N) then
1163 Plist := List_Containing (N);
1164 Parent_Node := Parent (Plist);
1166 if Parent_Node = Empty then
1169 -- Case of pragma appearing after a compilation unit. In this
1170 -- case it must have an argument with the corresponding name
1171 -- and must be part of the following pragmas of its parent.
1173 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1174 if Plist /= Pragmas_After (Parent_Node) then
1177 elsif Arg_Count = 0 then
1179 ("argument required if outside compilation unit");
1182 Check_No_Identifiers;
1183 Check_Arg_Count (1);
1184 Unit_Node := Unit (Parent (Parent_Node));
1185 Unit_Kind := Nkind (Unit_Node);
1187 Analyze (Expression (Arg1));
1189 if Unit_Kind = N_Generic_Subprogram_Declaration
1190 or else Unit_Kind = N_Subprogram_Declaration
1192 Unit_Name := Defining_Entity (Unit_Node);
1194 elsif Unit_Kind = N_Function_Instantiation
1195 or else Unit_Kind = N_Package_Instantiation
1196 or else Unit_Kind = N_Procedure_Instantiation
1198 Unit_Name := Defining_Entity (Unit_Node);
1201 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1204 if Chars (Unit_Name) /=
1205 Chars (Entity (Expression (Arg1)))
1208 ("pragma% argument is not current unit name", Arg1);
1211 if Ekind (Unit_Name) = E_Package
1212 and then Present (Renamed_Entity (Unit_Name))
1214 Error_Pragma ("pragma% not allowed for renamed package");
1218 -- Pragma appears other than after a compilation unit
1221 -- Here we check for the generic instantiation case and also
1222 -- for the case of processing a generic formal package. We
1223 -- detect these cases by noting that the Sloc on the node
1224 -- does not belong to the current compilation unit.
1226 Sindex := Source_Index (Current_Sem_Unit);
1228 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1229 Rewrite (N, Make_Null_Statement (Loc));
1232 -- If before first declaration, the pragma applies to the
1233 -- enclosing unit, and the name if present must be this name.
1235 elsif Is_Before_First_Decl (N, Plist) then
1236 Unit_Node := Unit_Declaration_Node (Current_Scope);
1237 Unit_Kind := Nkind (Unit_Node);
1239 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1242 elsif Unit_Kind = N_Subprogram_Body
1243 and then not Acts_As_Spec (Unit_Node)
1247 elsif Nkind (Parent_Node) = N_Package_Body then
1250 elsif Nkind (Parent_Node) = N_Package_Specification
1251 and then Plist = Private_Declarations (Parent_Node)
1255 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1256 or else Nkind (Parent_Node)
1257 = N_Generic_Subprogram_Declaration)
1258 and then Plist = Generic_Formal_Declarations (Parent_Node)
1262 elsif Arg_Count > 0 then
1263 Analyze (Expression (Arg1));
1265 if Entity (Expression (Arg1)) /= Current_Scope then
1267 ("name in pragma% must be enclosing unit", Arg1);
1270 -- It is legal to have no argument in this context
1276 -- Error if not before first declaration. This is because a
1277 -- library unit pragma argument must be the name of a library
1278 -- unit (RM 10.1.5(7)), but the only names permitted in this
1279 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1280 -- generic subprogram declarations or generic instantiations.
1284 ("pragma% misplaced, must be before first declaration");
1289 end Check_Valid_Library_Unit_Pragma;
1295 procedure Error_Pragma (Msg : String) is
1297 Error_Msg_Name_1 := Chars (N);
1298 Error_Msg_N (Msg, N);
1302 ----------------------
1303 -- Error_Pragma_Arg --
1304 ----------------------
1306 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1308 Error_Msg_Name_1 := Chars (N);
1309 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1311 end Error_Pragma_Arg;
1313 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1315 Error_Msg_Name_1 := Chars (N);
1316 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1317 Error_Pragma_Arg (Msg2, Arg);
1318 end Error_Pragma_Arg;
1320 ----------------------------
1321 -- Error_Pragma_Arg_Ident --
1322 ----------------------------
1324 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1326 Error_Msg_Name_1 := Chars (N);
1327 Error_Msg_N (Msg, Arg);
1329 end Error_Pragma_Arg_Ident;
1331 ------------------------
1332 -- Find_Lib_Unit_Name --
1333 ------------------------
1335 function Find_Lib_Unit_Name return Entity_Id is
1337 -- Return inner compilation unit entity, for case of nested
1338 -- categorization pragmas. This happens in generic unit.
1340 if Nkind (Parent (N)) = N_Package_Specification
1341 and then Defining_Entity (Parent (N)) /= Current_Scope
1343 return Defining_Entity (Parent (N));
1346 return Current_Scope;
1348 end Find_Lib_Unit_Name;
1350 ----------------------------
1351 -- Find_Program_Unit_Name --
1352 ----------------------------
1354 procedure Find_Program_Unit_Name (Id : Node_Id) is
1355 Unit_Name : Entity_Id;
1356 Unit_Kind : Node_Kind;
1357 P : constant Node_Id := Parent (N);
1360 if Nkind (P) = N_Compilation_Unit then
1361 Unit_Kind := Nkind (Unit (P));
1363 if Unit_Kind = N_Subprogram_Declaration
1364 or else Unit_Kind = N_Package_Declaration
1365 or else Unit_Kind in N_Generic_Declaration
1367 Unit_Name := Defining_Entity (Unit (P));
1369 if Chars (Id) = Chars (Unit_Name) then
1370 Set_Entity (Id, Unit_Name);
1371 Set_Etype (Id, Etype (Unit_Name));
1373 Set_Etype (Id, Any_Type);
1375 ("cannot find program unit referenced by pragma%");
1379 Set_Etype (Id, Any_Type);
1380 Error_Pragma ("pragma% inapplicable to this unit");
1387 end Find_Program_Unit_Name;
1389 -------------------------
1390 -- Gather_Associations --
1391 -------------------------
1393 procedure Gather_Associations
1395 Args : out Args_List)
1400 -- Initialize all parameters to Empty
1402 for J in Args'Range loop
1406 -- That's all we have to do if there are no argument associations
1408 if No (Pragma_Argument_Associations (N)) then
1412 -- Otherwise first deal with any positional parameters present
1414 Arg := First (Pragma_Argument_Associations (N));
1416 for Index in Args'Range loop
1417 exit when No (Arg) or else Chars (Arg) /= No_Name;
1418 Args (Index) := Expression (Arg);
1422 -- Positional parameters all processed, if any left, then we
1423 -- have too many positional parameters.
1425 if Present (Arg) and then Chars (Arg) = No_Name then
1427 ("too many positional associations for pragma%", Arg);
1430 -- Process named parameters if any are present
1432 while Present (Arg) loop
1433 if Chars (Arg) = No_Name then
1435 ("positional association cannot follow named association",
1439 for Index in Names'Range loop
1440 if Names (Index) = Chars (Arg) then
1441 if Present (Args (Index)) then
1443 ("duplicate argument association for pragma%", Arg);
1445 Args (Index) := Expression (Arg);
1450 if Index = Names'Last then
1451 Error_Msg_Name_1 := Chars (N);
1452 Error_Msg_N ("pragma% does not allow & argument", Arg);
1454 -- Check for possible misspelling
1456 for Index1 in Names'Range loop
1457 if Is_Bad_Spelling_Of
1458 (Get_Name_String (Chars (Arg)),
1459 Get_Name_String (Names (Index1)))
1461 Error_Msg_Name_1 := Names (Index1);
1462 Error_Msg_N ("\possible misspelling of%", Arg);
1474 end Gather_Associations;
1476 --------------------
1477 -- Get_Pragma_Arg --
1478 --------------------
1480 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1482 if Nkind (Arg) = N_Pragma_Argument_Association then
1483 return Expression (Arg);
1493 procedure GNAT_Pragma is
1495 Check_Restriction (No_Implementation_Pragmas, N);
1498 --------------------------
1499 -- Is_Before_First_Decl --
1500 --------------------------
1502 function Is_Before_First_Decl
1503 (Pragma_Node : Node_Id;
1507 Item : Node_Id := First (Decls);
1510 -- Only other pragmas can come before this pragma
1513 if No (Item) or else Nkind (Item) /= N_Pragma then
1516 elsif Item = Pragma_Node then
1523 end Is_Before_First_Decl;
1525 -----------------------------
1526 -- Is_Configuration_Pragma --
1527 -----------------------------
1529 -- A configuration pragma must appear in the context clause of
1530 -- a compilation unit, at the start of the list (i.e. only other
1531 -- pragmas may precede it).
1533 function Is_Configuration_Pragma return Boolean is
1534 Lis : constant List_Id := List_Containing (N);
1535 Par : constant Node_Id := Parent (N);
1539 -- If no parent, then we are in the configuration pragma file,
1540 -- so the placement is definitely appropriate.
1545 -- Otherwise we must be in the context clause of a compilation unit
1546 -- and the only thing allowed before us in the context list is more
1547 -- configuration pragmas.
1549 elsif Nkind (Par) = N_Compilation_Unit
1550 and then Context_Items (Par) = Lis
1557 elsif Nkind (Prg) /= N_Pragma then
1568 end Is_Configuration_Pragma;
1570 ----------------------
1571 -- Pragma_Misplaced --
1572 ----------------------
1574 procedure Pragma_Misplaced is
1576 Error_Pragma ("incorrect placement of pragma%");
1577 end Pragma_Misplaced;
1579 ------------------------------------
1580 -- Process Atomic_Shared_Volatile --
1581 ------------------------------------
1583 procedure Process_Atomic_Shared_Volatile is
1591 Check_Ada_83_Warning;
1592 Check_No_Identifiers;
1593 Check_Arg_Count (1);
1594 Check_Arg_Is_Local_Name (Arg1);
1595 E_Id := Expression (Arg1);
1597 if Etype (E_Id) = Any_Type then
1602 D := Declaration_Node (E);
1606 if Rep_Item_Too_Early (E, N)
1608 Rep_Item_Too_Late (E, N)
1612 Check_First_Subtype (Arg1);
1615 if Prag_Id /= Pragma_Volatile then
1617 Set_Is_Atomic (Underlying_Type (E));
1620 Set_Is_Volatile (E);
1621 Set_Is_Volatile (Underlying_Type (E));
1623 elsif K = N_Object_Declaration
1624 or else (K = N_Component_Declaration
1625 and then Original_Record_Component (E) = E)
1627 if Rep_Item_Too_Late (E, N) then
1631 if Prag_Id /= Pragma_Volatile then
1634 -- An interesting improvement here. If an object of type X
1635 -- is declared atomic, and the type X is not atomic, that's
1636 -- a pity, since it may not have appropraite alignment etc.
1637 -- We can rescue this in the special case where the object
1638 -- and type are in the same unit by just setting the type
1639 -- as atomic, so that the back end will process it as atomic.
1641 Utyp := Underlying_Type (Etype (E));
1644 and then Sloc (E) > No_Location
1645 and then Sloc (Utyp) > No_Location
1647 Get_Source_File_Index (Sloc (E)) =
1648 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1650 Set_Is_Atomic (Underlying_Type (Etype (E)));
1654 Set_Is_Volatile (E);
1658 ("inappropriate entity for pragma%", Arg1);
1660 end Process_Atomic_Shared_Volatile;
1662 ------------------------
1663 -- Process_Convention --
1664 ------------------------
1666 procedure Process_Convention
1667 (C : out Convention_Id;
1672 Comp_Unit : Unit_Number_Type;
1675 procedure Set_Convention_From_Pragma (E : Entity_Id);
1676 -- Set convention in entity E, and also flag that the entity has a
1677 -- convention pragma. If entity is for a private or incomplete type,
1678 -- also set convention and flag on underlying type. This procedure
1679 -- also deals with the special case of C_Pass_By_Copy convention.
1681 --------------------------------
1682 -- Set_Convention_From_Pragma --
1683 --------------------------------
1685 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1687 Set_Convention (E, C);
1688 Set_Has_Convention_Pragma (E);
1690 if Is_Incomplete_Or_Private_Type (E) then
1691 Set_Convention (Underlying_Type (E), C);
1692 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1695 -- A class-wide type should inherit the convention of
1696 -- the specific root type (although this isn't specified
1697 -- clearly by the RM).
1699 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1700 Set_Convention (Class_Wide_Type (E), C);
1703 -- If the entity is a record type, then check for special case
1704 -- of C_Pass_By_Copy, which is treated the same as C except that
1705 -- the special record flag is set. This convention is also only
1706 -- permitted on record types (see AI95-00131).
1708 if Cname = Name_C_Pass_By_Copy then
1709 if Is_Record_Type (E) then
1710 Set_C_Pass_By_Copy (Base_Type (E));
1711 elsif Is_Incomplete_Or_Private_Type (E)
1712 and then Is_Record_Type (Underlying_Type (E))
1714 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1717 ("C_Pass_By_Copy convention allowed only for record type",
1722 -- If the entity is a derived boolean type, check for the
1723 -- special case of convention C, C++, or Fortran, where we
1724 -- consider any nonzero value to represent true.
1726 if Is_Discrete_Type (E)
1727 and then Root_Type (Etype (E)) = Standard_Boolean
1733 C = Convention_Fortran)
1735 Set_Nonzero_Is_True (Base_Type (E));
1737 end Set_Convention_From_Pragma;
1739 -- Start of processing for Process_Convention
1742 Check_At_Least_N_Arguments (2);
1743 Check_Arg_Is_Identifier (Arg1);
1744 Check_Optional_Identifier (Arg1, Name_Convention);
1745 Cname := Chars (Expression (Arg1));
1747 -- C_Pass_By_Copy is treated as a synonym for convention C
1748 -- (this is tested again below to set the critical flag)
1750 if Cname = Name_C_Pass_By_Copy then
1753 -- Otherwise we must have something in the standard convention list
1755 elsif Is_Convention_Name (Cname) then
1756 C := Get_Convention_Id (Chars (Expression (Arg1)));
1758 -- In DEC VMS, it seems that there is an undocumented feature
1759 -- that any unrecognized convention is treated as the default,
1760 -- which for us is convention C. It does not seem so terrible
1761 -- to do this unconditionally, silently in the VMS case, and
1762 -- with a warning in the non-VMS case.
1765 if not OpenVMS_On_Target then
1767 ("?unrecognized convention name, C assumed",
1774 Check_Arg_Is_Local_Name (Arg2);
1775 Check_Optional_Identifier (Arg2, Name_Entity);
1777 Id := Expression (Arg2);
1780 if not Is_Entity_Name (Id) then
1781 Error_Pragma_Arg ("entity name required", Arg2);
1786 -- Go to renamed subprogram if present, since convention applies
1787 -- to the actual renamed entity, not to the renaming entity.
1789 if Is_Subprogram (E)
1790 and then Present (Alias (E))
1791 and then Nkind (Parent (Declaration_Node (E))) =
1792 N_Subprogram_Renaming_Declaration
1797 -- Check that we not applying this to a specless body
1799 if Is_Subprogram (E)
1800 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
1803 ("pragma% requires separate spec and must come before body");
1806 -- Check that we are not applying this to a named constant
1808 if Ekind (E) = E_Named_Integer
1810 Ekind (E) = E_Named_Real
1812 Error_Msg_Name_1 := Chars (N);
1814 ("cannot apply pragma% to named constant!",
1815 Get_Pragma_Arg (Arg2));
1817 ("\supply appropriate type for&!", Arg2);
1820 if Etype (E) = Any_Type
1821 or else Rep_Item_Too_Early (E, N)
1825 E := Underlying_Type (E);
1828 if Rep_Item_Too_Late (E, N) then
1832 if Has_Convention_Pragma (E) then
1834 ("at most one Convention/Export/Import pragma is allowed", Arg2);
1836 elsif Convention (E) = Convention_Protected
1837 or else Ekind (Scope (E)) = E_Protected_Type
1840 ("a protected operation cannot be given a different convention",
1844 -- For Intrinsic, a subprogram is required
1846 if C = Convention_Intrinsic
1847 and then not Is_Subprogram (E)
1848 and then not Is_Generic_Subprogram (E)
1851 ("second argument of pragma% must be a subprogram", Arg2);
1854 -- For Stdcall, a subprogram, variable or subprogram type is required
1856 if C = Convention_Stdcall
1857 and then not Is_Subprogram (E)
1858 and then not Is_Generic_Subprogram (E)
1859 and then Ekind (E) /= E_Variable
1862 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
1865 ("second argument of pragma% must be subprogram (type)",
1869 if not Is_Subprogram (E)
1870 and then not Is_Generic_Subprogram (E)
1872 Set_Convention_From_Pragma (E);
1876 Check_First_Subtype (Arg2);
1877 Set_Convention_From_Pragma (Base_Type (E));
1879 -- For subprograms, we must set the convention on the
1880 -- internally generated directly designated type as well.
1882 if Ekind (E) = E_Access_Subprogram_Type then
1883 Set_Convention_From_Pragma (Directly_Designated_Type (E));
1887 -- For the subprogram case, set proper convention for all homonyms
1888 -- in same compilation unit.
1889 -- Is the test of compilation unit really necessary ???
1890 -- What about subprogram renamings here???
1893 Comp_Unit := Get_Source_Unit (E);
1894 Set_Convention_From_Pragma (E);
1899 exit when No (E1) or else Scope (E1) /= Current_Scope;
1901 -- Note: below we are missing a check for Rep_Item_Too_Late.
1902 -- That is deliberate, we cannot chain the rep item on more
1903 -- than one Rep_Item chain, to be fixed later ???
1905 if Comp_Unit = Get_Source_Unit (E1) then
1906 Set_Convention_From_Pragma (E1);
1911 end Process_Convention;
1913 -----------------------------------------------------
1914 -- Process_Extended_Import_Export_Exception_Pragma --
1915 -----------------------------------------------------
1917 procedure Process_Extended_Import_Export_Exception_Pragma
1918 (Arg_Internal : Node_Id;
1919 Arg_External : Node_Id;
1928 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
1929 Def_Id := Entity (Arg_Internal);
1931 if Ekind (Def_Id) /= E_Exception then
1933 ("pragma% must refer to declared exception", Arg_Internal);
1936 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
1938 if Present (Arg_Form) then
1939 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
1942 if Present (Arg_Form)
1943 and then Chars (Arg_Form) = Name_Ada
1947 Set_Is_VMS_Exception (Def_Id);
1948 Set_Exception_Code (Def_Id, No_Uint);
1951 if Present (Arg_Code) then
1952 if not Is_VMS_Exception (Def_Id) then
1954 ("Code option for pragma% not allowed for Ada case",
1958 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
1959 Code_Val := Expr_Value (Arg_Code);
1961 if not UI_Is_In_Int_Range (Code_Val) then
1963 ("Code option for pragma% must be in 32-bit range",
1967 Set_Exception_Code (Def_Id, Code_Val);
1971 end Process_Extended_Import_Export_Exception_Pragma;
1973 -------------------------------------------------
1974 -- Process_Extended_Import_Export_Internal_Arg --
1975 -------------------------------------------------
1977 procedure Process_Extended_Import_Export_Internal_Arg
1978 (Arg_Internal : Node_Id := Empty)
1983 if No (Arg_Internal) then
1984 Error_Pragma ("Internal parameter required for pragma%");
1987 if Nkind (Arg_Internal) = N_Identifier then
1990 elsif Nkind (Arg_Internal) = N_Operator_Symbol
1991 and then (Prag_Id = Pragma_Import_Function
1993 Prag_Id = Pragma_Export_Function)
1999 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2002 Check_Arg_Is_Local_Name (Arg_Internal);
2004 end Process_Extended_Import_Export_Internal_Arg;
2006 --------------------------------------------------
2007 -- Process_Extended_Import_Export_Object_Pragma --
2008 --------------------------------------------------
2010 procedure Process_Extended_Import_Export_Object_Pragma
2011 (Arg_Internal : Node_Id;
2012 Arg_External : Node_Id;
2018 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2019 Def_Id := Entity (Arg_Internal);
2021 if Ekind (Def_Id) /= E_Constant
2022 and then Ekind (Def_Id) /= E_Variable
2025 ("pragma% must designate an object", Arg_Internal);
2028 if Is_Psected (Def_Id) then
2030 ("previous Psect_Object applies, pragma % not permitted",
2034 if Rep_Item_Too_Late (Def_Id, N) then
2038 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2040 if Present (Arg_Size)
2041 and then Nkind (Arg_Size) /= N_Identifier
2042 and then Nkind (Arg_Size) /= N_String_Literal
2045 ("pragma% Size argument must be identifier or string literal",
2049 -- Export_Object case
2051 if Prag_Id = Pragma_Export_Object then
2053 if not Is_Library_Level_Entity (Def_Id) then
2055 ("argument for pragma% must be library level entity",
2059 if Ekind (Current_Scope) = E_Generic_Package then
2060 Error_Pragma ("pragma& cannot appear in a generic unit");
2063 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2065 ("exported object must have compile time known size",
2069 if Is_Exported (Def_Id) then
2071 ("?duplicate Export_Object pragma", N);
2073 Set_Exported (Def_Id, Arg_Internal);
2076 -- Import_Object case
2079 if Is_Concurrent_Type (Etype (Def_Id)) then
2081 ("cannot use pragma% for task/protected object",
2085 if Ekind (Def_Id) = E_Constant then
2087 ("cannot import a constant", Arg_Internal);
2090 if Has_Discriminants (Etype (Def_Id)) then
2092 ("imported value must be initialized?", Arg_Internal);
2095 if Is_Access_Type (Etype (Def_Id)) then
2097 ("cannot import object of an access type?", Arg_Internal);
2100 if Is_Imported (Def_Id) then
2102 ("?duplicate Import_Object pragma", N);
2104 Set_Imported (Def_Id);
2108 end Process_Extended_Import_Export_Object_Pragma;
2110 ------------------------------------------------------
2111 -- Process_Extended_Import_Export_Subprogram_Pragma --
2112 ------------------------------------------------------
2114 procedure Process_Extended_Import_Export_Subprogram_Pragma
2115 (Arg_Internal : Node_Id;
2116 Arg_External : Node_Id;
2117 Arg_Parameter_Types : Node_Id;
2118 Arg_Result_Type : Node_Id := Empty;
2119 Arg_Mechanism : Node_Id;
2120 Arg_Result_Mechanism : Node_Id := Empty;
2121 Arg_First_Optional_Parameter : Node_Id := Empty)
2127 Ambiguous : Boolean;
2131 function Same_Base_Type (Ptype, Formal : Entity_Id) return Boolean;
2132 -- Determines if Ptype references the type of Formal. Note that
2133 -- only the base types need to match according to the spec.
2135 function Same_Base_Type (Ptype, Formal : Entity_Id) return Boolean is
2139 if not Is_Entity_Name (Ptype)
2140 or else Entity (Ptype) = Any_Type
2145 return Base_Type (Entity (Ptype)) = Base_Type (Etype (Formal));
2148 -- Start of processing for
2149 -- Process_Extended_Import_Export_Subprogram_Pragma
2152 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2153 Hom_Id := Entity (Arg_Internal);
2157 -- Loop through homonyms (overloadings) of Hom_Id
2159 while Present (Hom_Id) loop
2160 Def_Id := Get_Base_Subprogram (Hom_Id);
2162 -- We need a subprogram in the current scope
2164 if not Is_Subprogram (Def_Id)
2165 or else Scope (Def_Id) /= Current_Scope
2172 -- Pragma cannot apply to subprogram body
2174 if Is_Subprogram (Def_Id)
2177 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2180 ("pragma% requires separate spec"
2181 & " and must come before body");
2184 -- Test result type if given, note that the result type
2185 -- parameter can only be present for the function cases.
2187 if Present (Arg_Result_Type)
2188 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2192 -- Test parameter types if given. Note that this parameter
2193 -- has not been analyzed (and must not be, since it is
2194 -- semantic nonsense), so we get it as the parser left it.
2196 elsif Present (Arg_Parameter_Types) then
2197 Check_Matching_Types : declare
2202 Formal := First_Formal (Def_Id);
2204 if Nkind (Arg_Parameter_Types) = N_Null then
2205 if Present (Formal) then
2209 -- A list of one type, e.g. (List) is parsed as
2210 -- a parenthesized expression.
2212 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2213 and then Paren_Count (Arg_Parameter_Types) = 1
2216 or else Present (Next_Formal (Formal))
2221 Same_Base_Type (Arg_Parameter_Types, Formal);
2224 -- A list of more than one type is parsed as a aggregate
2226 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2227 and then Paren_Count (Arg_Parameter_Types) = 0
2229 Ptype := First (Expressions (Arg_Parameter_Types));
2231 while Present (Ptype) or else Present (Formal) loop
2234 or else not Same_Base_Type (Ptype, Formal)
2239 Next_Formal (Formal);
2244 -- Anything else is of the wrong form
2248 ("wrong form for Parameter_Types parameter",
2249 Arg_Parameter_Types);
2251 end Check_Matching_Types;
2254 -- Match is now False if the entry we found did not match
2255 -- either a supplied Parameter_Types or Result_Types argument
2261 -- Ambiguous case, the flag Ambiguous shows if we already
2262 -- detected this and output the initial messages.
2265 if not Ambiguous then
2267 Error_Msg_Name_1 := Chars (N);
2269 ("pragma% does not uniquely identify subprogram!",
2271 Error_Msg_Sloc := Sloc (Ent);
2272 Error_Msg_N ("matching subprogram #!", N);
2276 Error_Msg_Sloc := Sloc (Def_Id);
2277 Error_Msg_N ("matching subprogram #!", N);
2282 Hom_Id := Homonym (Hom_Id);
2285 -- See if we found an entry
2288 if not Ambiguous then
2289 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2291 ("pragma% cannot be given for generic subprogram");
2295 ("pragma% does not identify local subprogram");
2302 -- Import pragmas must be be for imported entities
2304 if (Prag_Id = Pragma_Import_Function
2306 Prag_Id = Pragma_Import_Procedure
2308 Prag_Id = Pragma_Import_Valued_Procedure)
2310 if not Is_Imported (Ent) then
2312 ("pragma Import or Interface must precede pragma%");
2315 -- For the Export cases, the pragma Export is sufficient to set
2316 -- the entity as exported, if it is not exported already. We
2317 -- leave the default Ada convention in this case.
2320 Set_Exported (Ent, Arg_Internal);
2323 -- Special processing for Valued_Procedure cases
2325 if Prag_Id = Pragma_Import_Valued_Procedure
2327 Prag_Id = Pragma_Export_Valued_Procedure
2329 Formal := First_Formal (Ent);
2333 ("at least one parameter required for pragma%");
2335 elsif Ekind (Formal) /= E_Out_Parameter then
2337 ("first parameter must have mode out for pragma%");
2340 Set_Is_Valued_Procedure (Ent);
2344 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2346 -- Process Result_Mechanism argument if present. We have already
2347 -- checked that this is only allowed for the function case.
2349 if Present (Arg_Result_Mechanism) then
2350 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2353 -- Process Mechanism parameter if present. Note that this parameter
2354 -- is not analyzed, and must not be analyzed since it is semantic
2355 -- nonsense, so we get it in exactly as the parser left it.
2357 if Present (Arg_Mechanism) then
2366 -- A single mechanism association without a formal parameter
2367 -- name is parsed as a parenthesized expression. All other
2368 -- cases are parsed as aggregates, so we rewrite the single
2369 -- parameter case as an aggregate for consistency.
2371 if Nkind (Arg_Mechanism) /= N_Aggregate
2372 and then Paren_Count (Arg_Mechanism) = 1
2374 Rewrite (Arg_Mechanism,
2375 Make_Aggregate (Sloc (Arg_Mechanism),
2376 Expressions => New_List (
2377 Relocate_Node (Arg_Mechanism))));
2380 -- Case of only mechanism name given, applies to all formals
2382 if Nkind (Arg_Mechanism) /= N_Aggregate then
2383 Formal := First_Formal (Ent);
2384 while Present (Formal) loop
2385 Set_Mechanism_Value (Formal, Arg_Mechanism);
2386 Next_Formal (Formal);
2389 -- Case of list of mechanism associations given
2392 if Null_Record_Present (Arg_Mechanism) then
2394 ("inappropriate form for Mechanism parameter",
2398 -- Deal with positional ones first
2400 Formal := First_Formal (Ent);
2401 if Present (Expressions (Arg_Mechanism)) then
2402 Mname := First (Expressions (Arg_Mechanism));
2404 while Present (Mname) loop
2407 ("too many mechanism associations", Mname);
2410 Set_Mechanism_Value (Formal, Mname);
2411 Next_Formal (Formal);
2416 -- Deal with named entries
2418 if Present (Component_Associations (Arg_Mechanism)) then
2419 Massoc := First (Component_Associations (Arg_Mechanism));
2421 while Present (Massoc) loop
2422 Choice := First (Choices (Massoc));
2424 if Nkind (Choice) /= N_Identifier
2425 or else Present (Next (Choice))
2428 ("incorrect form for mechanism association",
2432 Formal := First_Formal (Ent);
2436 ("parameter name & not present", Choice);
2439 if Chars (Choice) = Chars (Formal) then
2441 (Formal, Expression (Massoc));
2445 Next_Formal (Formal);
2455 -- Process First_Optional_Parameter argument if present. We have
2456 -- already checked that this is only allowed for the Import case.
2458 if Present (Arg_First_Optional_Parameter) then
2459 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2461 ("first optional parameter must be formal parameter name",
2462 Arg_First_Optional_Parameter);
2465 Formal := First_Formal (Ent);
2469 ("specified formal parameter& not found",
2470 Arg_First_Optional_Parameter);
2473 exit when Chars (Formal) =
2474 Chars (Arg_First_Optional_Parameter);
2476 Next_Formal (Formal);
2479 Set_First_Optional_Parameter (Ent, Formal);
2481 -- Check specified and all remaining formals have right form
2483 while Present (Formal) loop
2484 if Ekind (Formal) /= E_In_Parameter then
2486 ("optional formal& is not of mode in!",
2487 Arg_First_Optional_Parameter, Formal);
2490 Dval := Default_Value (Formal);
2492 if not Present (Dval) then
2494 ("optional formal& does not have default value!",
2495 Arg_First_Optional_Parameter, Formal);
2497 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2502 ("default value for optional formal& is non-static!",
2503 Arg_First_Optional_Parameter, Formal);
2507 Set_Is_Optional_Parameter (Formal);
2508 Next_Formal (Formal);
2511 end Process_Extended_Import_Export_Subprogram_Pragma;
2513 --------------------------
2514 -- Process_Generic_List --
2515 --------------------------
2517 procedure Process_Generic_List is
2523 Check_No_Identifiers;
2524 Check_At_Least_N_Arguments (1);
2527 while Present (Arg) loop
2528 Exp := Expression (Arg);
2531 if not Is_Entity_Name (Exp)
2533 (not Is_Generic_Instance (Entity (Exp))
2535 not Is_Generic_Unit (Entity (Exp)))
2538 ("pragma% argument must be name of generic unit/instance",
2544 end Process_Generic_List;
2546 ---------------------------------
2547 -- Process_Import_Or_Interface --
2548 ---------------------------------
2550 procedure Process_Import_Or_Interface is
2556 Process_Convention (C, Def_Id);
2557 Kill_Size_Check_Code (Def_Id);
2558 Note_Possible_Modification (Expression (Arg2));
2560 if Ekind (Def_Id) = E_Variable
2562 Ekind (Def_Id) = E_Constant
2564 -- User initialization is not allowed for imported object, but
2565 -- the object declaration may contain a default initialization,
2566 -- that will be discarded.
2568 if Present (Expression (Parent (Def_Id)))
2569 and then Comes_From_Source (Expression (Parent (Def_Id)))
2571 Error_Msg_Sloc := Sloc (Def_Id);
2573 ("no initialization allowed for declaration of& #",
2574 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2578 Set_Imported (Def_Id);
2579 Set_Is_Public (Def_Id);
2580 Process_Interface_Name (Def_Id, Arg3, Arg4);
2583 elsif Is_Subprogram (Def_Id)
2584 or else Is_Generic_Subprogram (Def_Id)
2586 -- If the name is overloaded, pragma applies to all of the
2587 -- denoted entities in the same declarative part.
2591 while Present (Hom_Id) loop
2592 Def_Id := Get_Base_Subprogram (Hom_Id);
2594 -- Ignore inherited subprograms because the pragma will
2595 -- apply to the parent operation, which is the one called.
2597 if Is_Overloadable (Def_Id)
2598 and then Present (Alias (Def_Id))
2602 -- Verify that the homonym is in the same declarative
2603 -- part (not just the same scope).
2605 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2606 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2611 Set_Imported (Def_Id);
2613 -- If Import intrinsic, set intrinsic flag
2614 -- and verify that it is known as such.
2616 if C = Convention_Intrinsic then
2617 Set_Is_Intrinsic_Subprogram (Def_Id);
2618 Check_Intrinsic_Subprogram
2619 (Def_Id, Expression (Arg2));
2622 -- All interfaced procedures need an external
2623 -- symbol created for them since they are
2624 -- always referenced from another object file.
2626 Set_Is_Public (Def_Id);
2627 Set_Has_Completion (Def_Id);
2628 Process_Interface_Name (Def_Id, Arg3, Arg4);
2631 if Is_Compilation_Unit (Hom_Id) then
2633 -- Its possible homonyms are not affected by the pragma.
2634 -- Such homonyms might be present in the context of other
2635 -- units being compiled.
2640 Hom_Id := Homonym (Hom_Id);
2644 -- When the convention is Java, we also allow Import to be given
2645 -- for packages, exceptions, and record components.
2647 elsif C = Convention_Java
2648 and then (Ekind (Def_Id) = E_Package
2649 or else Ekind (Def_Id) = E_Exception
2650 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
2652 Set_Imported (Def_Id);
2653 Set_Is_Public (Def_Id);
2654 Process_Interface_Name (Def_Id, Arg3, Arg4);
2658 ("second argument of pragma% must be object or subprogram",
2662 -- If this pragma applies to a compilation unit, then the unit,
2663 -- which is a subprogram, does not require (or allow) a body.
2664 -- We also do not need to elaborate imported procedures.
2666 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2668 Cunit : constant Node_Id := Parent (Parent (N));
2671 Set_Body_Required (Cunit, False);
2675 end Process_Import_Or_Interface;
2677 --------------------
2678 -- Process_Inline --
2679 --------------------
2681 procedure Process_Inline (Active : Boolean) is
2688 procedure Make_Inline (Subp : Entity_Id);
2689 -- Subp is the defining unit name of the subprogram
2690 -- declaration. Set the flag, as well as the flag in the
2691 -- corresponding body, if there is one present.
2693 procedure Set_Inline_Flags (Subp : Entity_Id);
2694 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
2700 procedure Make_Inline (Subp : Entity_Id) is
2701 Kind : Entity_Kind := Ekind (Subp);
2702 Inner_Subp : Entity_Id := Subp;
2705 if Etype (Subp) = Any_Type then
2708 -- Here we have a candidate for inlining, but we must exclude
2709 -- derived operations. Otherwise we will end up trying to
2710 -- inline a phantom declaration, and the result would be to
2711 -- drag in a body which has no direct inlining associated with
2712 -- it. That would not only be inefficient but would also result
2713 -- in the backend doing cross-unit inlining in cases where it
2714 -- was definitely inappropriate to do so.
2716 -- However, a simple Comes_From_Source test is insufficient,
2717 -- since we do want to allow inlining of generic instances,
2718 -- which also do not come from source. Predefined operators do
2719 -- not come from source but are not inlineable either.
2721 elsif not Comes_From_Source (Subp)
2722 and then not Is_Generic_Instance (Subp)
2723 and then Scope (Subp) /= Standard_Standard
2728 -- The referenced entity must either be the enclosing entity,
2729 -- or an entity declared within the current open scope.
2731 elsif Present (Scope (Subp))
2732 and then Scope (Subp) /= Current_Scope
2733 and then Subp /= Current_Scope
2736 ("argument of% must be entity in current scope", Assoc);
2740 -- Processing for procedure, operator or function.
2741 -- If subprogram is aliased (as for an instance) indicate
2742 -- that the renamed entity is inlined.
2744 if Kind = E_Procedure
2745 or else Kind = E_Function
2746 or else Kind = E_Operator
2748 while Present (Alias (Inner_Subp)) loop
2749 Inner_Subp := Alias (Inner_Subp);
2752 Set_Inline_Flags (Inner_Subp);
2754 Decl := Parent (Parent (Inner_Subp));
2756 if Nkind (Decl) = N_Subprogram_Declaration
2757 and then Present (Corresponding_Body (Decl))
2759 Set_Inline_Flags (Corresponding_Body (Decl));
2764 -- For a generic subprogram set flag as well, for use at
2765 -- the point of instantiation, to determine whether the
2766 -- body should be generated.
2768 elsif Kind = E_Generic_Procedure
2769 or else Kind = E_Generic_Function
2771 Set_Inline_Flags (Subp);
2774 -- Literals are by definition inlined.
2776 elsif Kind = E_Enumeration_Literal then
2779 -- Anything else is an error
2783 ("expect subprogram name for pragma%", Assoc);
2787 ----------------------
2788 -- Set_Inline_Flags --
2789 ----------------------
2791 procedure Set_Inline_Flags (Subp : Entity_Id) is
2794 Set_Is_Inlined (Subp, True);
2797 if not Has_Pragma_Inline (Subp) then
2798 Set_Has_Pragma_Inline (Subp);
2799 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
2800 Set_First_Rep_Item (Subp, N);
2802 end Set_Inline_Flags;
2804 -- Start of processing for Process_Inline
2807 Check_No_Identifiers;
2808 Check_At_Least_N_Arguments (1);
2811 Inline_Processing_Required := True;
2815 while Present (Assoc) loop
2816 Subp_Id := Expression (Assoc);
2820 if Is_Entity_Name (Subp_Id) then
2821 Subp := Entity (Subp_Id);
2823 if Subp = Any_Id then
2829 while Present (Homonym (Subp))
2830 and then Scope (Homonym (Subp)) = Current_Scope
2832 Make_Inline (Homonym (Subp));
2833 Subp := Homonym (Subp);
2840 ("inappropriate argument for pragma%", Assoc);
2848 ----------------------------
2849 -- Process_Interface_Name --
2850 ----------------------------
2852 procedure Process_Interface_Name
2853 (Subprogram_Def : Entity_Id;
2859 String_Val : String_Id;
2861 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
2862 -- SN is a string literal node for an interface name. This routine
2863 -- performs some minimal checks that the name is reasonable. In
2864 -- particular that no spaces or other obviously incorrect characters
2865 -- appear. This is only a warning, since any characters are allowed.
2867 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
2868 S : constant String_Id := Strval (Expr_Value_S (SN));
2869 SL : constant Nat := String_Length (S);
2874 Error_Msg_N ("interface name cannot be null string", SN);
2877 for J in 1 .. SL loop
2878 C := Get_String_Char (S, J);
2880 if not In_Character_Range (C)
2881 or else Get_Character (C) = ' '
2882 or else Get_Character (C) = ','
2885 ("?interface name contains illegal character", SN);
2888 end Check_Form_Of_Interface_Name;
2890 -- Start of processing for Process_Interface_Name
2893 if No (Link_Arg) then
2894 if No (Ext_Arg) then
2897 elsif Chars (Ext_Arg) = Name_Link_Name then
2899 Link_Nam := Expression (Ext_Arg);
2902 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
2903 Ext_Nam := Expression (Ext_Arg);
2908 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
2909 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
2910 Ext_Nam := Expression (Ext_Arg);
2911 Link_Nam := Expression (Link_Arg);
2914 -- Check expressions for external name and link name are static
2916 if Present (Ext_Nam) then
2917 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
2918 Check_Form_Of_Interface_Name (Ext_Nam);
2920 -- Verify that the external name is not the name of a local
2921 -- entity, which would hide the imported one and lead to
2922 -- run-time surprises. The problem can only arise for entities
2923 -- declared in a package body (otherwise the external name is
2924 -- fully qualified and won't conflict).
2932 if Prag_Id = Pragma_Import then
2933 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
2935 E := Entity_Id (Get_Name_Table_Info (Nam));
2937 if Nam /= Chars (Subprogram_Def)
2938 and then Present (E)
2939 and then not Is_Overloadable (E)
2940 and then Is_Immediately_Visible (E)
2941 and then not Is_Imported (E)
2942 and then Ekind (Scope (E)) = E_Package
2946 while Present (Par) loop
2947 if Nkind (Par) = N_Package_Body then
2948 Error_Msg_Sloc := Sloc (E);
2950 ("imported entity is hidden by & declared#",
2955 Par := Parent (Par);
2962 if Present (Link_Nam) then
2963 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
2964 Check_Form_Of_Interface_Name (Link_Nam);
2967 -- If there is no link name, just set the external name
2969 if No (Link_Nam) then
2970 Set_Encoded_Interface_Name
2971 (Get_Base_Subprogram (Subprogram_Def),
2972 Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)));
2974 -- For the Link_Name case, the given literal is preceded by an
2975 -- asterisk, which indicates to GCC that the given name should
2976 -- be taken literally, and in particular that no prepending of
2977 -- underlines should occur, even in systems where this is the
2982 Store_String_Char (Get_Char_Code ('*'));
2983 String_Val := Strval (Expr_Value_S (Link_Nam));
2985 for J in 1 .. String_Length (String_Val) loop
2986 Store_String_Char (Get_String_Char (String_Val, J));
2990 Make_String_Literal (Sloc (Link_Nam), End_String);
2992 Set_Encoded_Interface_Name
2993 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
2995 end Process_Interface_Name;
2997 -----------------------------------------
2998 -- Process_Interrupt_Or_Attach_Handler --
2999 -----------------------------------------
3001 procedure Process_Interrupt_Or_Attach_Handler is
3002 Arg1_X : constant Node_Id := Expression (Arg1);
3003 Prot_Proc : constant Entity_Id := Entity (Arg1_X);
3004 Prot_Type : constant Entity_Id := Scope (Prot_Proc);
3007 Set_Is_Interrupt_Handler (Prot_Proc);
3009 if Prag_Id = Pragma_Interrupt_Handler
3010 or Prag_Id = Pragma_Attach_Handler
3012 Record_Rep_Item (Prot_Type, N);
3015 end Process_Interrupt_Or_Attach_Handler;
3017 ---------------------------------
3018 -- Process_Suppress_Unsuppress --
3019 ---------------------------------
3021 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3025 Effective : Boolean;
3027 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3028 -- Used to suppress a single check on the given entity
3030 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3032 -- First set appropriate suppress flags in the entity
3035 when Access_Check =>
3036 Effective := Suppress_Access_Checks (E);
3037 Set_Suppress_Access_Checks (E, Suppress_Case);
3039 when Accessibility_Check =>
3040 Effective := Suppress_Accessibility_Checks (E);
3041 Set_Suppress_Accessibility_Checks (E, Suppress_Case);
3043 when Discriminant_Check =>
3044 Effective := Suppress_Discriminant_Checks (E);
3045 Set_Suppress_Discriminant_Checks (E, Suppress_Case);
3047 when Division_Check =>
3048 Effective := Suppress_Division_Checks (E);
3049 Set_Suppress_Division_Checks (E, Suppress_Case);
3051 when Elaboration_Check =>
3052 Effective := Suppress_Elaboration_Checks (E);
3053 Set_Suppress_Elaboration_Checks (E, Suppress_Case);
3056 Effective := Suppress_Index_Checks (E);
3057 Set_Suppress_Index_Checks (E, Suppress_Case);
3059 when Length_Check =>
3060 Effective := Suppress_Length_Checks (E);
3061 Set_Suppress_Length_Checks (E, Suppress_Case);
3063 when Overflow_Check =>
3064 Effective := Suppress_Overflow_Checks (E);
3065 Set_Suppress_Overflow_Checks (E, Suppress_Case);
3068 Effective := Suppress_Range_Checks (E);
3069 Set_Suppress_Range_Checks (E, Suppress_Case);
3071 when Storage_Check =>
3072 Effective := Suppress_Storage_Checks (E);
3073 Set_Suppress_Storage_Checks (E, Suppress_Case);
3076 Effective := Suppress_Tag_Checks (E);
3077 Set_Suppress_Tag_Checks (E, Suppress_Case);
3080 Suppress_Unsuppress_Echeck (E, Access_Check);
3081 Suppress_Unsuppress_Echeck (E, Accessibility_Check);
3082 Suppress_Unsuppress_Echeck (E, Discriminant_Check);
3083 Suppress_Unsuppress_Echeck (E, Division_Check);
3084 Suppress_Unsuppress_Echeck (E, Elaboration_Check);
3085 Suppress_Unsuppress_Echeck (E, Index_Check);
3086 Suppress_Unsuppress_Echeck (E, Length_Check);
3087 Suppress_Unsuppress_Echeck (E, Overflow_Check);
3088 Suppress_Unsuppress_Echeck (E, Range_Check);
3089 Suppress_Unsuppress_Echeck (E, Storage_Check);
3090 Suppress_Unsuppress_Echeck (E, Tag_Check);
3093 -- If the entity is not declared in the current scope, then we
3094 -- make an entry in the Entity_Suppress table so that the flag
3095 -- will be removed on exit. This entry is only made if the
3096 -- suppress did something (i.e. the flag was not already set).
3098 if Effective and then Scope (E) /= Current_Scope then
3099 Entity_Suppress.Increment_Last;
3100 Entity_Suppress.Table
3101 (Entity_Suppress.Last).Entity := E;
3102 Entity_Suppress.Table
3103 (Entity_Suppress.Last).Check := C;
3106 -- If this is a first subtype, and the base type is distinct,
3107 -- then also set the suppress flags on the base type.
3109 if Is_First_Subtype (E)
3110 and then Etype (E) /= E
3112 Suppress_Unsuppress_Echeck (Etype (E), C);
3114 end Suppress_Unsuppress_Echeck;
3116 -- Start of processing for Process_Suppress_Unsuppress
3119 -- Suppress/Unsuppress can appear as a configuration pragma,
3120 -- or in a declarative part or a package spec (RM 11.5(5))
3122 if not Is_Configuration_Pragma then
3123 Check_Is_In_Decl_Part_Or_Package_Spec;
3126 Check_At_Least_N_Arguments (1);
3127 Check_At_Most_N_Arguments (2);
3128 Check_No_Identifier (Arg1);
3129 Check_Arg_Is_Identifier (Arg1);
3131 if not Is_Check_Name (Chars (Expression (Arg1))) then
3133 ("argument of pragma% is not valid check name", Arg1);
3136 C := Get_Check_Id (Chars (Expression (Arg1)));
3139 if Arg_Count = 1 then
3141 when Access_Check =>
3142 Scope_Suppress.Access_Checks := Suppress_Case;
3144 when Accessibility_Check =>
3145 Scope_Suppress.Accessibility_Checks := Suppress_Case;
3147 when Discriminant_Check =>
3148 Scope_Suppress.Discriminant_Checks := Suppress_Case;
3150 when Division_Check =>
3151 Scope_Suppress.Division_Checks := Suppress_Case;
3153 when Elaboration_Check =>
3154 Scope_Suppress.Elaboration_Checks := Suppress_Case;
3157 Scope_Suppress.Index_Checks := Suppress_Case;
3159 when Length_Check =>
3160 Scope_Suppress.Length_Checks := Suppress_Case;
3162 when Overflow_Check =>
3163 Scope_Suppress.Overflow_Checks := Suppress_Case;
3166 Scope_Suppress.Range_Checks := Suppress_Case;
3168 when Storage_Check =>
3169 Scope_Suppress.Storage_Checks := Suppress_Case;
3172 Scope_Suppress.Tag_Checks := Suppress_Case;
3175 Scope_Suppress := (others => Suppress_Case);
3179 -- Case of two arguments present, where the check is
3180 -- suppressed for a specified entity (given as the second
3181 -- argument of the pragma)
3184 Check_Optional_Identifier (Arg2, Name_On);
3185 E_Id := Expression (Arg2);
3188 if not Is_Entity_Name (E_Id) then
3190 ("second argument of pragma% must be entity name", Arg2);
3199 Suppress_Unsuppress_Echeck (E, C);
3201 if Is_Generic_Instance (E)
3202 and then Is_Subprogram (E)
3203 and then Present (Alias (E))
3205 Suppress_Unsuppress_Echeck (Alias (E), C);
3208 if C = Elaboration_Check and then Suppress_Case then
3209 Set_Suppress_Elaboration_Warnings (E);
3212 -- If we are within a package specification, the
3213 -- pragma only applies to homonyms in the same scope.
3215 exit when No (Homonym (E))
3216 or else (Scope (Homonym (E)) /= Current_Scope
3217 and then Ekind (Current_Scope) = E_Package
3218 and then not In_Package_Body (Current_Scope));
3225 end Process_Suppress_Unsuppress;
3231 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3233 if Is_Imported (E) then
3235 ("cannot export entity& that was previously imported", Arg);
3237 elsif Present (Address_Clause (E)) then
3239 ("cannot export entity& that has an address clause", Arg);
3242 Set_Is_Exported (E);
3244 -- Deal with exporting non-library level entity
3246 if not Is_Library_Level_Entity (E) then
3248 -- Not allowed at all for subprograms
3250 if Is_Subprogram (E) then
3251 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3253 -- Otherwise set public and statically allocated
3257 Set_Is_Statically_Allocated (E);
3261 if Inside_A_Generic then
3263 ("all instances of& will have the same external name?", Arg, E);
3268 ----------------------------------------------
3269 -- Set_Extended_Import_Export_External_Name --
3270 ----------------------------------------------
3272 procedure Set_Extended_Import_Export_External_Name
3273 (Internal_Ent : Entity_Id;
3274 Arg_External : Node_Id)
3276 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3280 if No (Arg_External) then
3283 elsif Nkind (Arg_External) = N_String_Literal then
3284 if String_Length (Strval (Arg_External)) = 0 then
3287 New_Name := Adjust_External_Name_Case (Arg_External);
3290 elsif Nkind (Arg_External) = N_Identifier then
3291 New_Name := Get_Default_External_Name (Arg_External);
3295 ("incorrect form for External parameter for pragma%",
3299 -- If we already have an external name set (by a prior normal
3300 -- Import or Export pragma), then the external names must match
3302 if Present (Interface_Name (Internal_Ent)) then
3304 S1 : constant String_Id := Strval (Old_Name);
3305 S2 : constant String_Id := Strval (New_Name);
3308 -- Called if names do not match
3310 procedure Mismatch is
3312 Error_Msg_Sloc := Sloc (Old_Name);
3314 ("external name does not match that given #",
3319 if String_Length (S1) /= String_Length (S2) then
3323 for J in 1 .. String_Length (S1) loop
3324 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3331 -- Otherwise set the given name
3334 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3337 end Set_Extended_Import_Export_External_Name;
3343 procedure Set_Imported (E : Entity_Id) is
3345 Error_Msg_Sloc := Sloc (E);
3347 if Is_Exported (E) or else Is_Imported (E) then
3348 Error_Msg_NE ("import of& declared# not allowed", N, E);
3350 if Is_Exported (E) then
3351 Error_Msg_N ("\entity was previously exported", N);
3353 Error_Msg_N ("\entity was previously imported", N);
3356 Error_Pragma ("\(pragma% applies to all previous entities)");
3359 Set_Is_Imported (E);
3361 -- If the entity is an object that is not at the library
3362 -- level, then it is statically allocated. We do not worry
3363 -- about objects with address clauses in this context since
3364 -- they are not really imported in the linker sense.
3367 and then not Is_Library_Level_Entity (E)
3368 and then No (Address_Clause (E))
3370 Set_Is_Statically_Allocated (E);
3375 -------------------------
3376 -- Set_Mechanism_Value --
3377 -------------------------
3379 -- Note: the mechanism name has not been analyzed (and cannot indeed
3380 -- be analyzed, since it is semantic nonsense), so we get it in the
3381 -- exact form created by the parser.
3383 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3387 procedure Bad_Class;
3388 -- Signal bad descriptor class name
3390 procedure Bad_Mechanism;
3391 -- Signal bad mechanism name
3393 procedure Bad_Class is
3395 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3398 procedure Bad_Mechanism is
3400 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3403 -- Start of processing for Set_Mechanism_Value
3406 if Mechanism (Ent) /= Default_Mechanism then
3408 ("mechanism for & has already been set", Mech_Name, Ent);
3411 -- MECHANISM_NAME ::= value | reference | descriptor
3413 if Nkind (Mech_Name) = N_Identifier then
3414 if Chars (Mech_Name) = Name_Value then
3415 Set_Mechanism (Ent, By_Copy);
3418 elsif Chars (Mech_Name) = Name_Reference then
3419 Set_Mechanism (Ent, By_Reference);
3422 elsif Chars (Mech_Name) = Name_Descriptor then
3423 Check_VMS (Mech_Name);
3424 Set_Mechanism (Ent, By_Descriptor);
3427 elsif Chars (Mech_Name) = Name_Copy then
3429 ("bad mechanism name, Value assumed", Mech_Name);
3435 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3436 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3438 -- Note: this form is parsed as an indexed component
3440 elsif Nkind (Mech_Name) = N_Indexed_Component then
3441 Class := First (Expressions (Mech_Name));
3443 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3444 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3445 or else Present (Next (Class))
3450 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3451 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3453 -- Note: this form is parsed as a function call
3455 elsif Nkind (Mech_Name) = N_Function_Call then
3457 Param := First (Parameter_Associations (Mech_Name));
3459 if Nkind (Name (Mech_Name)) /= N_Identifier
3460 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3461 or else Present (Next (Param))
3462 or else No (Selector_Name (Param))
3463 or else Chars (Selector_Name (Param)) /= Name_Class
3467 Class := Explicit_Actual_Parameter (Param);
3474 -- Fall through here with Class set to descriptor class name
3476 Check_VMS (Mech_Name);
3478 if Nkind (Class) /= N_Identifier then
3481 elsif Chars (Class) = Name_UBS then
3482 Set_Mechanism (Ent, By_Descriptor_UBS);
3484 elsif Chars (Class) = Name_UBSB then
3485 Set_Mechanism (Ent, By_Descriptor_UBSB);
3487 elsif Chars (Class) = Name_UBA then
3488 Set_Mechanism (Ent, By_Descriptor_UBA);
3490 elsif Chars (Class) = Name_S then
3491 Set_Mechanism (Ent, By_Descriptor_S);
3493 elsif Chars (Class) = Name_SB then
3494 Set_Mechanism (Ent, By_Descriptor_SB);
3496 elsif Chars (Class) = Name_A then
3497 Set_Mechanism (Ent, By_Descriptor_A);
3499 elsif Chars (Class) = Name_NCA then
3500 Set_Mechanism (Ent, By_Descriptor_NCA);
3506 end Set_Mechanism_Value;
3508 -- Start of processing for Analyze_Pragma
3511 if not Is_Pragma_Name (Chars (N)) then
3512 Error_Pragma ("unrecognized pragma%!?");
3514 Prag_Id := Get_Pragma_Id (Chars (N));
3524 if Present (Pragma_Argument_Associations (N)) then
3525 Arg1 := First (Pragma_Argument_Associations (N));
3527 if Present (Arg1) then
3528 Arg2 := Next (Arg1);
3530 if Present (Arg2) then
3531 Arg3 := Next (Arg2);
3533 if Present (Arg3) then
3534 Arg4 := Next (Arg3);
3540 -- Count number of arguments
3549 while Present (Arg_Node) loop
3550 Arg_Count := Arg_Count + 1;
3555 -- An enumeration type defines the pragmas that are supported by the
3556 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
3557 -- into the corresponding enumeration value for the following case.
3565 -- pragma Abort_Defer;
3567 when Pragma_Abort_Defer =>
3569 Check_Arg_Count (0);
3571 -- The only required semantic processing is to check the
3572 -- placement. This pragma must appear at the start of the
3573 -- statement sequence of a handled sequence of statements.
3575 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
3576 or else N /= First (Statements (Parent (N)))
3587 -- Note: this pragma also has some specific processing in Par.Prag
3588 -- because we want to set the Ada 83 mode switch during parsing.
3590 when Pragma_Ada_83 =>
3594 Check_Arg_Count (0);
3602 -- Note: this pragma also has some specific processing in Par.Prag
3603 -- because we want to set the Ada 83 mode switch during parsing.
3605 when Pragma_Ada_95 =>
3609 Check_Arg_Count (0);
3611 ----------------------
3612 -- All_Calls_Remote --
3613 ----------------------
3615 -- pragma All_Calls_Remote [(library_package_NAME)];
3617 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
3618 Lib_Entity : Entity_Id;
3621 Check_Ada_83_Warning;
3622 Check_Valid_Library_Unit_Pragma;
3624 if Nkind (N) = N_Null_Statement then
3628 Lib_Entity := Find_Lib_Unit_Name;
3630 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
3632 if Present (Lib_Entity)
3633 and then not Debug_Flag_U
3635 if not Is_Remote_Call_Interface (Lib_Entity) then
3636 Error_Pragma ("pragma% only apply to rci unit");
3638 -- Set flag for entity of the library unit
3641 Set_Has_All_Calls_Remote (Lib_Entity);
3645 end All_Calls_Remote;
3651 -- pragma Annotate (IDENTIFIER {, ARG});
3652 -- ARG ::= NAME | EXPRESSION
3654 when Pragma_Annotate => Annotate : begin
3656 Check_At_Least_N_Arguments (1);
3657 Check_Arg_Is_Identifier (Arg1);
3660 Arg : Node_Id := Arg2;
3664 while Present (Arg) loop
3665 Exp := Expression (Arg);
3668 if Is_Entity_Name (Exp) then
3671 elsif Nkind (Exp) = N_String_Literal then
3672 Resolve (Exp, Standard_String);
3674 elsif Is_Overloaded (Exp) then
3675 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
3678 Resolve (Exp, Etype (Exp));
3690 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
3692 when Pragma_Assert =>
3694 Check_No_Identifiers;
3696 if Arg_Count > 1 then
3697 Check_Arg_Count (2);
3698 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3701 -- If expansion is active and assertions are inactive, then
3702 -- we rewrite the Assertion as:
3704 -- if False and then condition then
3708 -- The reason we do this rewriting during semantic analysis
3709 -- rather than as part of normal expansion is that we cannot
3710 -- analyze and expand the code for the boolean expression
3711 -- directly, or it may cause insertion of actions that would
3712 -- escape the attempt to suppress the assertion code.
3714 if Expander_Active and not Assertions_Enabled then
3716 Make_If_Statement (Loc,
3719 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
3720 Right_Opnd => Get_Pragma_Arg (Arg1)),
3721 Then_Statements => New_List (
3722 Make_Null_Statement (Loc))));
3726 -- Otherwise (if assertions are enabled, or if we are not
3727 -- operating with expansion active), then we just analyze
3728 -- and resolve the expression.
3731 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
3738 -- pragma AST_Entry (entry_IDENTIFIER);
3740 when Pragma_AST_Entry => AST_Entry : declare
3746 Check_Arg_Count (1);
3747 Check_No_Identifiers;
3748 Check_Arg_Is_Local_Name (Arg1);
3749 Ent := Entity (Expression (Arg1));
3751 -- Note: the implementation of the AST_Entry pragma could handle
3752 -- the entry family case fine, but for now we are consistent with
3753 -- the DEC rules, and do not allow the pragma, which of course
3754 -- has the effect of also forbidding the attribute.
3756 if Ekind (Ent) /= E_Entry then
3758 ("pragma% argument must be simple entry name", Arg1);
3760 elsif Is_AST_Entry (Ent) then
3762 ("duplicate % pragma for entry", Arg1);
3764 elsif Has_Homonym (Ent) then
3766 ("pragma% argument cannot specify overloaded entry", Arg1);
3770 FF : constant Entity_Id := First_Formal (Ent);
3773 if Present (FF) then
3774 if Present (Next_Formal (FF)) then
3776 ("entry for pragma% can have only one argument",
3779 elsif Parameter_Mode (FF) /= E_In_Parameter then
3781 ("entry parameter for pragma% must have mode IN",
3787 Set_Is_AST_Entry (Ent);
3795 -- pragma Asynchronous (LOCAL_NAME);
3797 when Pragma_Asynchronous => Asynchronous : declare
3805 procedure Process_Async_Pragma;
3806 -- Common processing for procedure and access-to-procedure case
3808 --------------------------
3809 -- Process_Async_Pragma --
3810 --------------------------
3812 procedure Process_Async_Pragma is
3814 if not Present (L) then
3815 Set_Is_Asynchronous (Nm);
3819 -- The formals should be of mode IN (RM E.4.1(6))
3822 while Present (S) loop
3823 Formal := Defining_Identifier (S);
3825 if Nkind (Formal) = N_Defining_Identifier
3826 and then Ekind (Formal) /= E_In_Parameter
3829 ("pragma% procedure can only have IN parameter",
3836 Set_Is_Asynchronous (Nm);
3837 end Process_Async_Pragma;
3839 -- Start of processing for pragma Asynchronous
3842 Check_Ada_83_Warning;
3843 Check_No_Identifiers;
3844 Check_Arg_Count (1);
3845 Check_Arg_Is_Local_Name (Arg1);
3847 if Debug_Flag_U then
3851 C_Ent := Cunit_Entity (Current_Sem_Unit);
3852 Analyze (Expression (Arg1));
3853 Nm := Entity (Expression (Arg1));
3855 if not Is_Remote_Call_Interface (C_Ent)
3856 and then not Is_Remote_Types (C_Ent)
3858 -- This pragma should only appear in an RCI or Remote Types
3859 -- unit (RM E.4.1(4))
3862 ("pragma% not in Remote_Call_Interface or " &
3863 "Remote_Types unit");
3866 if Ekind (Nm) = E_Procedure
3867 and then Nkind (Parent (Nm)) = N_Procedure_Specification
3869 if not Is_Remote_Call_Interface (Nm) then
3871 ("pragma% cannot be applied on non-remote procedure",
3875 L := Parameter_Specifications (Parent (Nm));
3876 Process_Async_Pragma;
3879 elsif Ekind (Nm) = E_Function then
3881 ("pragma% cannot be applied to function", Arg1);
3883 elsif Ekind (Nm) = E_Record_Type
3884 and then Present (Corresponding_Remote_Type (Nm))
3886 N := Declaration_Node (Corresponding_Remote_Type (Nm));
3888 if Nkind (N) = N_Full_Type_Declaration
3889 and then Nkind (Type_Definition (N)) =
3890 N_Access_Procedure_Definition
3892 L := Parameter_Specifications (Type_Definition (N));
3893 Process_Async_Pragma;
3897 ("pragma% cannot reference access-to-function type",
3901 -- Only other possibility is Access-to-class-wide type
3903 elsif Is_Access_Type (Nm)
3904 and then Is_Class_Wide_Type (Designated_Type (Nm))
3906 Check_First_Subtype (Arg1);
3907 Set_Is_Asynchronous (Nm);
3908 if Expander_Active then
3909 RACW_Type_Is_Asynchronous (Nm);
3913 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
3922 -- pragma Atomic (LOCAL_NAME);
3924 when Pragma_Atomic =>
3925 Process_Atomic_Shared_Volatile;
3927 -----------------------
3928 -- Atomic_Components --
3929 -----------------------
3931 -- pragma Atomic_Components (array_LOCAL_NAME);
3933 -- This processing is shared by Volatile_Components
3935 when Pragma_Atomic_Components |
3936 Pragma_Volatile_Components =>
3938 Atomic_Components : declare
3945 Check_Ada_83_Warning;
3946 Check_No_Identifiers;
3947 Check_Arg_Count (1);
3948 Check_Arg_Is_Local_Name (Arg1);
3949 E_Id := Expression (Arg1);
3951 if Etype (E_Id) = Any_Type then
3957 if Rep_Item_Too_Early (E, N)
3959 Rep_Item_Too_Late (E, N)
3964 D := Declaration_Node (E);
3967 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
3969 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
3970 and then Nkind (D) = N_Object_Declaration
3971 and then Nkind (Object_Definition (D)) =
3972 N_Constrained_Array_Definition)
3974 -- The flag is set on the object, or on the base type
3976 if Nkind (D) /= N_Object_Declaration then
3980 Set_Has_Volatile_Components (E);
3982 if Prag_Id = Pragma_Atomic_Components then
3983 Set_Has_Atomic_Components (E);
3985 if Is_Packed (E) then
3986 Set_Is_Packed (E, False);
3989 ("?Pack canceled, cannot pack atomic components",
3995 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
3997 end Atomic_Components;
3999 --------------------
4000 -- Attach_Handler --
4001 --------------------
4003 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4005 when Pragma_Attach_Handler =>
4006 Check_Ada_83_Warning;
4007 Check_No_Identifiers;
4008 Check_Arg_Count (2);
4009 Check_Interrupt_Or_Attach_Handler;
4010 Analyze_And_Resolve (Expression (Arg2), RTE (RE_Interrupt_Id));
4011 Process_Interrupt_Or_Attach_Handler;
4013 --------------------
4014 -- C_Pass_By_Copy --
4015 --------------------
4017 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4019 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4025 Check_Valid_Configuration_Pragma;
4026 Check_Arg_Count (1);
4027 Check_Optional_Identifier (Arg1, "max_size");
4029 Arg := Expression (Arg1);
4030 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4032 Val := Expr_Value (Arg);
4036 ("maximum size for pragma% must be positive", Arg1);
4038 elsif UI_Is_In_Int_Range (Val) then
4039 Default_C_Record_Mechanism := UI_To_Int (Val);
4041 -- If a giant value is given, Int'Last will do well enough.
4042 -- If sometime someone complains that a record larger than
4043 -- two gigabytes is not copied, we will worry about it then!
4046 Default_C_Record_Mechanism := Mechanism_Type'Last;
4054 -- pragma Comment (static_string_EXPRESSION)
4056 -- Processing for pragma Comment shares the circuitry for
4057 -- pragma Ident. The only differences are that Ident enforces
4058 -- a limit of 31 characters on its argument, and also enforces
4059 -- limitations on placement for DEC compatibility. Pragma
4060 -- Comment shares neither of these restrictions.
4066 -- pragma Common_Object (
4067 -- [Internal =>] LOCAL_NAME,
4068 -- [, [External =>] EXTERNAL_SYMBOL]
4069 -- [, [Size =>] EXTERNAL_SYMBOL]);
4071 -- Processing for this pragma is shared with Psect_Object
4073 ----------------------------
4074 -- Complex_Representation --
4075 ----------------------------
4077 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4079 when Pragma_Complex_Representation => Complex_Representation : declare
4086 Check_Arg_Count (1);
4087 Check_Optional_Identifier (Arg1, Name_Entity);
4088 Check_Arg_Is_Local_Name (Arg1);
4089 E_Id := Expression (Arg1);
4091 if Etype (E_Id) = Any_Type then
4097 if not Is_Record_Type (E) then
4099 ("argument for pragma% must be record type", Arg1);
4102 Ent := First_Entity (E);
4105 or else No (Next_Entity (Ent))
4106 or else Present (Next_Entity (Next_Entity (Ent)))
4107 or else not Is_Floating_Point_Type (Etype (Ent))
4108 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4111 ("record for pragma% must have two fields of same fpt type",
4115 Set_Has_Complex_Representation (Base_Type (E));
4117 end Complex_Representation;
4119 -------------------------
4120 -- Component_Alignment --
4121 -------------------------
4123 -- pragma Component_Alignment (
4124 -- [Form =>] ALIGNMENT_CHOICE
4125 -- [, [Name =>] type_LOCAL_NAME]);
4127 -- ALIGNMENT_CHOICE ::=
4129 -- | Component_Size_4
4133 when Pragma_Component_Alignment => Component_AlignmentP : declare
4134 Args : Args_List (1 .. 2);
4135 Names : Name_List (1 .. 2) := (
4139 Form : Node_Id renames Args (1);
4140 Name : Node_Id renames Args (2);
4142 Atype : Component_Alignment_Kind;
4147 Gather_Associations (Names, Args);
4150 Error_Pragma ("missing Form argument for pragma%");
4153 Check_Arg_Is_Identifier (Form);
4155 -- Get proper alignment, note that Default = Component_Size
4156 -- on all machines we have so far, and we want to set this
4157 -- value rather than the default value to indicate that it
4158 -- has been explicitly set (and thus will not get overridden
4159 -- by the default component alignment for the current scope)
4161 if Chars (Form) = Name_Component_Size then
4162 Atype := Calign_Component_Size;
4164 elsif Chars (Form) = Name_Component_Size_4 then
4165 Atype := Calign_Component_Size_4;
4167 elsif Chars (Form) = Name_Default then
4168 Atype := Calign_Component_Size;
4170 elsif Chars (Form) = Name_Storage_Unit then
4171 Atype := Calign_Storage_Unit;
4175 ("invalid Form parameter for pragma%", Form);
4178 -- Case with no name, supplied, affects scope table entry
4182 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4184 -- Case of name supplied
4187 Check_Arg_Is_Local_Name (Name);
4189 Typ := Entity (Name);
4192 or else Rep_Item_Too_Early (Typ, N)
4196 Typ := Underlying_Type (Typ);
4199 if not Is_Record_Type (Typ)
4200 and then not Is_Array_Type (Typ)
4203 ("Name parameter of pragma% must identify record or " &
4204 "array type", Name);
4207 -- An explicit Component_Alignment pragma overrides an
4208 -- implicit pragma Pack, but not an explicit one.
4210 if not Has_Pragma_Pack (Base_Type (Typ)) then
4211 Set_Is_Packed (Base_Type (Typ), False);
4212 Set_Component_Alignment (Base_Type (Typ), Atype);
4215 end Component_AlignmentP;
4221 -- pragma Controlled (first_subtype_LOCAL_NAME);
4223 when Pragma_Controlled => Controlled : declare
4227 Check_No_Identifiers;
4228 Check_Arg_Count (1);
4229 Check_Arg_Is_Local_Name (Arg1);
4230 Arg := Expression (Arg1);
4232 if not Is_Entity_Name (Arg)
4233 or else not Is_Access_Type (Entity (Arg))
4235 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4237 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4245 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4246 -- [Entity =>] LOCAL_NAME);
4248 when Pragma_Convention => Convention : declare
4253 Check_Ada_83_Warning;
4254 Check_Arg_Count (2);
4255 Process_Convention (C, E);
4258 ---------------------------
4259 -- Convention_Identifier --
4260 ---------------------------
4262 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
4263 -- [Convention =>] convention_IDENTIFIER);
4265 when Pragma_Convention_Identifier => Convention_Identifier : declare
4271 Check_Arg_Count (2);
4272 Check_Optional_Identifier (Arg1, Name_Name);
4273 Check_Optional_Identifier (Arg2, Name_Convention);
4274 Check_Arg_Is_Identifier (Arg1);
4275 Check_Arg_Is_Identifier (Arg1);
4276 Idnam := Chars (Expression (Arg1));
4277 Cname := Chars (Expression (Arg2));
4279 if Is_Convention_Name (Cname) then
4280 Record_Convention_Identifier
4281 (Idnam, Get_Convention_Id (Cname));
4284 ("second arg for % pragma must be convention", Arg2);
4286 end Convention_Identifier;
4292 -- pragma CPP_Class ([Entity =>] local_NAME)
4294 when Pragma_CPP_Class => CPP_Class : declare
4297 Default_DTC : Entity_Id := Empty;
4298 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4304 Check_Arg_Count (1);
4305 Check_Optional_Identifier (Arg1, Name_Entity);
4306 Check_Arg_Is_Local_Name (Arg1);
4308 Arg := Expression (Arg1);
4311 if Etype (Arg) = Any_Type then
4315 if not Is_Entity_Name (Arg)
4316 or else not Is_Type (Entity (Arg))
4318 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
4321 Typ := Entity (Arg);
4323 if not Is_Record_Type (Typ) then
4324 Error_Pragma_Arg ("pragma% applicable to a record, "
4325 & "tagged record or record extension", Arg1);
4328 Default_DTC := First_Component (Typ);
4329 while Present (Default_DTC)
4330 and then Etype (Default_DTC) /= VTP_Type
4332 Next_Component (Default_DTC);
4335 -- Case of non tagged type
4337 if not Is_Tagged_Type (Typ) then
4338 Set_Is_CPP_Class (Typ);
4340 if Present (Default_DTC) then
4342 ("only tagged records can contain vtable pointers", Arg1);
4345 -- Case of tagged type with no vtable ptr
4347 -- What is test for Typ = Root_Typ (Typ) about here ???
4349 elsif Is_Tagged_Type (Typ)
4350 and then Typ = Root_Type (Typ)
4351 and then No (Default_DTC)
4354 ("a cpp_class must contain a vtable pointer", Arg1);
4356 -- Tagged type that has a vtable ptr
4358 elsif Present (Default_DTC) then
4359 Set_Is_CPP_Class (Typ);
4360 Set_Is_Limited_Record (Typ);
4361 Set_Is_Tag (Default_DTC);
4362 Set_DT_Entry_Count (Default_DTC, No_Uint);
4364 -- Since a CPP type has no direct link to its associated tag
4365 -- most tags checks cannot be performed
4367 Set_Suppress_Tag_Checks (Typ);
4368 Set_Suppress_Tag_Checks (Class_Wide_Type (Typ));
4370 -- Get rid of the _tag component when there was one.
4371 -- It is only useful for regular tagged types
4373 if Expander_Active and then Typ = Root_Type (Typ) then
4375 Tag_C := Tag_Component (Typ);
4376 C := First_Entity (Typ);
4379 Set_First_Entity (Typ, Next_Entity (Tag_C));
4382 while Next_Entity (C) /= Tag_C loop
4386 Set_Next_Entity (C, Next_Entity (Tag_C));
4392 ---------------------
4393 -- CPP_Constructor --
4394 ---------------------
4396 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
4398 when Pragma_CPP_Constructor => CPP_Constructor : declare
4404 Check_Arg_Count (1);
4405 Check_Optional_Identifier (Arg1, Name_Entity);
4406 Check_Arg_Is_Local_Name (Arg1);
4408 Id := Expression (Arg1);
4409 Find_Program_Unit_Name (Id);
4411 -- If we did not find the name, we are done
4413 if Etype (Id) = Any_Type then
4417 Def_Id := Entity (Id);
4419 if Ekind (Def_Id) = E_Function
4420 and then Is_Class_Wide_Type (Etype (Def_Id))
4421 and then Is_CPP_Class (Etype (Etype (Def_Id)))
4423 -- What the heck is this??? this pragma allows only 1 arg
4425 if Arg_Count >= 2 then
4426 Check_At_Most_N_Arguments (3);
4427 Process_Interface_Name (Def_Id, Arg2, Arg3);
4430 if No (Parameter_Specifications (Parent (Def_Id))) then
4431 Set_Has_Completion (Def_Id);
4432 Set_Is_Constructor (Def_Id);
4435 ("non-default constructors not implemented", Arg1);
4440 ("pragma% requires function returning a 'C'P'P_Class type",
4443 end CPP_Constructor;
4449 -- pragma CPP_Virtual
4450 -- [Entity =>] LOCAL_NAME
4451 -- [ [Vtable_Ptr =>] LOCAL_NAME,
4452 -- [Position =>] static_integer_EXPRESSION]);
4454 when Pragma_CPP_Virtual => CPP_Virtual : declare
4458 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4465 if Arg_Count = 3 then
4466 Check_Optional_Identifier (Arg2, "vtable_ptr");
4468 -- We allow Entry_Count as well as Position for the third
4469 -- parameter for back compatibility with versions of GNAT
4470 -- before version 3.12. The documentation has always said
4471 -- Position, but the code up to 3.12 said Entry_Count.
4473 if Chars (Arg3) /= Name_Position then
4474 Check_Optional_Identifier (Arg3, "entry_count");
4478 Check_Arg_Count (1);
4481 Check_Optional_Identifier (Arg1, Name_Entity);
4482 Check_Arg_Is_Local_Name (Arg1);
4484 -- First argument must be a subprogram name
4486 Arg := Expression (Arg1);
4487 Find_Program_Unit_Name (Arg);
4489 if Etype (Arg) = Any_Type then
4492 Subp := Entity (Arg);
4495 if not (Is_Subprogram (Subp)
4496 and then Is_Dispatching_Operation (Subp))
4499 ("pragma% must reference a primitive operation", Arg1);
4502 Typ := Find_Dispatching_Type (Subp);
4504 -- If only one Argument defaults are :
4505 -- . DTC_Entity is the default Vtable pointer
4506 -- . DT_Position will be set at the freezing point
4508 if Arg_Count = 1 then
4509 Set_DTC_Entity (Subp, Tag_Component (Typ));
4513 -- Second argument is a component name of type Vtable_Ptr
4515 Arg := Expression (Arg2);
4517 if Nkind (Arg) /= N_Identifier then
4518 Error_Msg_NE ("must be a& component name", Arg, Typ);
4522 DTC := First_Component (Typ);
4523 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4524 Next_Component (DTC);
4528 Error_Msg_NE ("must be a& component name", Arg, Typ);
4531 elsif Etype (DTC) /= VTP_Type then
4532 Wrong_Type (Arg, VTP_Type);
4536 -- Third argument is an integer (DT_Position)
4538 Arg := Expression (Arg3);
4539 Analyze_And_Resolve (Arg, Any_Integer);
4541 if not Is_Static_Expression (Arg) then
4543 ("third argument of pragma% must be a static expression",
4547 V := Expr_Value (Expression (Arg3));
4551 ("third argument of pragma% must be positive",
4555 Set_DTC_Entity (Subp, DTC);
4556 Set_DT_Position (Subp, V);
4565 -- pragma CPP_Vtable (
4566 -- [Entity =>] LOCAL_NAME
4567 -- [Vtable_Ptr =>] LOCAL_NAME,
4568 -- [Entry_Count =>] static_integer_EXPRESSION);
4570 when Pragma_CPP_Vtable => CPP_Vtable : declare
4573 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4580 Check_Arg_Count (3);
4581 Check_Optional_Identifier (Arg1, Name_Entity);
4582 Check_Optional_Identifier (Arg2, "vtable_ptr");
4583 Check_Optional_Identifier (Arg3, "entry_count");
4584 Check_Arg_Is_Local_Name (Arg1);
4586 -- First argument is a record type name
4588 Arg := Expression (Arg1);
4591 if Etype (Arg) = Any_Type then
4594 Typ := Entity (Arg);
4597 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
4598 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
4601 -- Second argument is a component name of type Vtable_Ptr
4603 Arg := Expression (Arg2);
4605 if Nkind (Arg) /= N_Identifier then
4606 Error_Msg_NE ("must be a& component name", Arg, Typ);
4610 DTC := First_Component (Typ);
4611 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4612 Next_Component (DTC);
4616 Error_Msg_NE ("must be a& component name", Arg, Typ);
4619 elsif Etype (DTC) /= VTP_Type then
4620 Wrong_Type (DTC, VTP_Type);
4623 -- If it is the first pragma Vtable, This becomes the default tag
4625 elsif (not Is_Tag (DTC))
4626 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
4628 Set_Is_Tag (Tag_Component (Typ), False);
4629 Set_Is_Tag (DTC, True);
4630 Set_DT_Entry_Count (DTC, No_Uint);
4633 -- Those pragmas must appear before any primitive operation
4634 -- definition (except inherited ones) otherwise the default
4637 Elmt := First_Elmt (Primitive_Operations (Typ));
4638 while Present (Elmt) loop
4639 if No (Alias (Node (Elmt))) then
4640 Error_Msg_Sloc := Sloc (Node (Elmt));
4642 ("pragma% must appear before this primitive operation");
4648 -- Third argument is an integer (DT_Entry_Count)
4650 Arg := Expression (Arg3);
4651 Analyze_And_Resolve (Arg, Any_Integer);
4653 if not Is_Static_Expression (Arg) then
4655 ("entry count for pragma% must be a static expression", Arg3);
4658 V := Expr_Value (Expression (Arg3));
4662 ("entry count for pragma% must be positive", Arg3);
4664 Set_DT_Entry_Count (DTC, V);
4674 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
4676 when Pragma_Debug => Debug : begin
4679 -- If assertions are enabled, and we are expanding code, then
4680 -- we rewrite the pragma with its corresponding procedure call
4681 -- and then analyze the call.
4683 if Assertions_Enabled and Expander_Active then
4684 Rewrite (N, Relocate_Node (Debug_Statement (N)));
4687 -- Otherwise we work a bit to get a tree that makes sense
4688 -- for ASIS purposes, namely a pragma with an analyzed
4689 -- argument that looks like a procedure call.
4692 Expander_Mode_Save_And_Set (False);
4693 Rewrite (N, Relocate_Node (Debug_Statement (N)));
4697 Chars => Name_Debug,
4698 Pragma_Argument_Associations =>
4699 New_List (Relocate_Node (N))));
4700 Expander_Mode_Restore;
4708 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
4710 when Pragma_Discard_Names => Discard_Names : declare
4715 Check_Ada_83_Warning;
4717 -- Deal with configuration pragma case
4719 if Arg_Count = 0 and then Is_Configuration_Pragma then
4720 Global_Discard_Names := True;
4723 -- Otherwise, check correct appropriate context
4726 Check_Is_In_Decl_Part_Or_Package_Spec;
4728 if Arg_Count = 0 then
4730 -- If there is no parameter, then from now on this pragma
4731 -- applies to any enumeration, exception or tagged type
4732 -- defined in the current declarative part.
4734 Set_Discard_Names (Current_Scope);
4738 Check_Arg_Count (1);
4739 Check_Optional_Identifier (Arg1, Name_On);
4740 Check_Arg_Is_Local_Name (Arg1);
4741 E_Id := Expression (Arg1);
4743 if Etype (E_Id) = Any_Type then
4749 if (Is_First_Subtype (E)
4750 and then (Is_Enumeration_Type (E)
4751 or else Is_Tagged_Type (E)))
4752 or else Ekind (E) = E_Exception
4754 Set_Discard_Names (E);
4757 ("inappropriate entity for pragma%", Arg1);
4767 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
4769 when Pragma_Elaborate => Elaborate : declare
4771 Parent_Node : Node_Id;
4776 -- Pragma must be in context items list of a compilation unit
4778 if not Is_List_Member (N) then
4783 Plist := List_Containing (N);
4784 Parent_Node := Parent (Plist);
4786 if Parent_Node = Empty
4787 or else Nkind (Parent_Node) /= N_Compilation_Unit
4788 or else Context_Items (Parent_Node) /= Plist
4795 -- Must be at least one argument
4797 if Arg_Count = 0 then
4798 Error_Pragma ("pragma% requires at least one argument");
4801 -- In Ada 83 mode, there can be no items following it in the
4802 -- context list except other pragmas and implicit with clauses
4803 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
4804 -- placement rule does not apply.
4806 if Ada_83 and then Comes_From_Source (N) then
4809 while Present (Citem) loop
4810 if Nkind (Citem) = N_Pragma
4811 or else (Nkind (Citem) = N_With_Clause
4812 and then Implicit_With (Citem))
4817 ("(Ada 83) pragma% must be at end of context clause");
4824 -- Finally, the arguments must all be units mentioned in a with
4825 -- clause in the same context clause. Note we already checked
4826 -- (in Par.Prag) that the arguments are either identifiers or
4829 Outer : while Present (Arg) loop
4830 Citem := First (Plist);
4832 Inner : while Citem /= N loop
4833 if Nkind (Citem) = N_With_Clause
4834 and then Same_Name (Name (Citem), Expression (Arg))
4836 Set_Elaborate_Present (Citem, True);
4837 Set_Unit_Name (Expression (Arg), Name (Citem));
4838 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
4847 ("argument of pragma% is not with'ed unit", Arg);
4858 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
4860 when Pragma_Elaborate_All => Elaborate_All : declare
4862 Parent_Node : Node_Id;
4867 Check_Ada_83_Warning;
4869 -- Pragma must be in context items list of a compilation unit
4871 if not Is_List_Member (N) then
4876 Plist := List_Containing (N);
4877 Parent_Node := Parent (Plist);
4879 if Parent_Node = Empty
4880 or else Nkind (Parent_Node) /= N_Compilation_Unit
4881 or else Context_Items (Parent_Node) /= Plist
4888 -- Must be at least one argument
4890 if Arg_Count = 0 then
4891 Error_Pragma ("pragma% requires at least one argument");
4894 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
4895 -- have to appear at the end of the context clause, but may
4896 -- appear mixed in with other items, even in Ada 83 mode.
4898 -- Final check: the arguments must all be units mentioned in
4899 -- a with clause in the same context clause. Note that we
4900 -- already checked (in Par.Prag) that all the arguments are
4901 -- either identifiers or selected components.
4904 Outr : while Present (Arg) loop
4905 Citem := First (Plist);
4907 Innr : while Citem /= N loop
4908 if Nkind (Citem) = N_With_Clause
4909 and then Same_Name (Name (Citem), Expression (Arg))
4911 Set_Elaborate_All_Present (Citem, True);
4912 Set_Unit_Name (Expression (Arg), Name (Citem));
4913 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
4922 ("argument of pragma% is not with'ed unit", Arg);
4929 --------------------
4930 -- Elaborate_Body --
4931 --------------------
4933 -- pragma Elaborate_Body [( library_unit_NAME )];
4935 when Pragma_Elaborate_Body => Elaborate_Body : declare
4936 Cunit_Node : Node_Id;
4937 Cunit_Ent : Entity_Id;
4940 Check_Ada_83_Warning;
4941 Check_Valid_Library_Unit_Pragma;
4943 if Nkind (N) = N_Null_Statement then
4947 Cunit_Node := Cunit (Current_Sem_Unit);
4948 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
4950 if Nkind (Unit (Cunit_Node)) = N_Package_Body
4952 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
4954 Error_Pragma ("pragma% must refer to a spec, not a body");
4956 Set_Body_Required (Cunit_Node, True);
4957 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
4959 -- If we are in dynamic elaboration mode, then we suppress
4960 -- elaboration warnings for the unit, since it is definitely
4961 -- fine NOT to do dynamic checks at the first level (and such
4962 -- checks will be suppressed because no elaboration boolean
4963 -- is created for Elaborate_Body packages).
4965 -- But in the static model of elaboration, Elaborate_Body is
4966 -- definitely NOT good enough to ensure elaboration safety on
4967 -- its own, since the body may WITH other units that are not
4968 -- safe from an elaboration point of view, so a client must
4969 -- still do an Elaborate_All on such units.
4971 -- Debug flag -gnatdD restores the old behavior of 3.13,
4972 -- where Elaborate_Body always suppressed elab warnings.
4974 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
4975 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
4980 ------------------------
4981 -- Elaboration_Checks --
4982 ------------------------
4984 -- pragma Elaboration_Checks (Static | Dynamic);
4986 when Pragma_Elaboration_Checks =>
4988 Check_Arg_Count (1);
4989 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
4990 Dynamic_Elaboration_Checks :=
4991 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
4997 -- pragma Eliminate (
4998 -- [Unit_Name =>] IDENTIFIER |
4999 -- SELECTED_COMPONENT
5000 -- [,[Entity =>] IDENTIFIER |
5001 -- SELECTED_COMPONENT |
5003 -- [,[Parameter_Types =>] PARAMETER_TYPES]
5004 -- [,[Result_Type =>] result_SUBTYPE_NAME]
5005 -- [,[Homonym_Number =>] INTEGER_LITERAL]);
5007 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5008 -- SUBTYPE_NAME ::= STRING_LITERAL
5010 when Pragma_Eliminate => Eliminate : declare
5011 Args : Args_List (1 .. 5);
5012 Names : Name_List (1 .. 5) := (
5015 Name_Parameter_Types,
5017 Name_Homonym_Number);
5019 Unit_Name : Node_Id renames Args (1);
5020 Entity : Node_Id renames Args (2);
5021 Parameter_Types : Node_Id renames Args (3);
5022 Result_Type : Node_Id renames Args (4);
5023 Homonym_Number : Node_Id renames Args (5);
5027 Check_Valid_Configuration_Pragma;
5028 Gather_Associations (Names, Args);
5030 if No (Unit_Name) then
5031 Error_Pragma ("missing Unit_Name argument for pragma%");
5035 and then (Present (Parameter_Types)
5037 Present (Result_Type)
5039 Present (Homonym_Number))
5041 Error_Pragma ("missing Entity argument for pragma%");
5044 Process_Eliminate_Pragma
5057 -- [ Convention =>] convention_IDENTIFIER,
5058 -- [ Entity =>] local_NAME
5059 -- [, [External_Name =>] static_string_EXPRESSION ]
5060 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5062 when Pragma_Export => Export : declare
5067 Check_Ada_83_Warning;
5068 Check_At_Least_N_Arguments (2);
5069 Check_At_Most_N_Arguments (4);
5070 Process_Convention (C, Def_Id);
5072 if Ekind (Def_Id) /= E_Constant then
5073 Note_Possible_Modification (Expression (Arg2));
5076 Process_Interface_Name (Def_Id, Arg3, Arg4);
5077 Set_Exported (Def_Id, Arg2);
5080 ----------------------
5081 -- Export_Exception --
5082 ----------------------
5084 -- pragma Export_Exception (
5085 -- [Internal =>] LOCAL_NAME,
5086 -- [, [External =>] EXTERNAL_SYMBOL,]
5087 -- [, [Form =>] Ada | VMS]
5088 -- [, [Code =>] static_integer_EXPRESSION]);
5090 when Pragma_Export_Exception => Export_Exception : declare
5091 Args : Args_List (1 .. 4);
5092 Names : Name_List (1 .. 4) := (
5098 Internal : Node_Id renames Args (1);
5099 External : Node_Id renames Args (2);
5100 Form : Node_Id renames Args (3);
5101 Code : Node_Id renames Args (4);
5104 if Inside_A_Generic then
5105 Error_Pragma ("pragma% cannot be used for generic entities");
5108 Gather_Associations (Names, Args);
5109 Process_Extended_Import_Export_Exception_Pragma (
5110 Arg_Internal => Internal,
5111 Arg_External => External,
5115 if not Is_VMS_Exception (Entity (Internal)) then
5116 Set_Exported (Entity (Internal), Internal);
5119 end Export_Exception;
5121 ---------------------
5122 -- Export_Function --
5123 ---------------------
5125 -- pragma Export_Function (
5126 -- [Internal =>] LOCAL_NAME,
5127 -- [, [External =>] EXTERNAL_SYMBOL,]
5128 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5129 -- [, [Result_Type =>] SUBTYPE_MARK]
5130 -- [, [Mechanism =>] MECHANISM]
5131 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5133 when Pragma_Export_Function => Export_Function : declare
5134 Args : Args_List (1 .. 6);
5135 Names : Name_List (1 .. 6) := (
5138 Name_Parameter_Types,
5141 Name_Result_Mechanism);
5143 Internal : Node_Id renames Args (1);
5144 External : Node_Id renames Args (2);
5145 Parameter_Types : Node_Id renames Args (3);
5146 Result_Type : Node_Id renames Args (4);
5147 Mechanism : Node_Id renames Args (5);
5148 Result_Mechanism : Node_Id renames Args (6);
5152 Gather_Associations (Names, Args);
5153 Process_Extended_Import_Export_Subprogram_Pragma (
5154 Arg_Internal => Internal,
5155 Arg_External => External,
5156 Arg_Parameter_Types => Parameter_Types,
5157 Arg_Result_Type => Result_Type,
5158 Arg_Mechanism => Mechanism,
5159 Arg_Result_Mechanism => Result_Mechanism);
5160 end Export_Function;
5166 -- pragma Export_Object (
5167 -- [Internal =>] LOCAL_NAME,
5168 -- [, [External =>] EXTERNAL_SYMBOL]
5169 -- [, [Size =>] EXTERNAL_SYMBOL]);
5171 when Pragma_Export_Object => Export_Object : declare
5172 Args : Args_List (1 .. 3);
5173 Names : Name_List (1 .. 3) := (
5178 Internal : Node_Id renames Args (1);
5179 External : Node_Id renames Args (2);
5180 Size : Node_Id renames Args (3);
5184 Gather_Associations (Names, Args);
5185 Process_Extended_Import_Export_Object_Pragma (
5186 Arg_Internal => Internal,
5187 Arg_External => External,
5191 ----------------------
5192 -- Export_Procedure --
5193 ----------------------
5195 -- pragma Export_Procedure (
5196 -- [Internal =>] LOCAL_NAME,
5197 -- [, [External =>] EXTERNAL_SYMBOL,]
5198 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5199 -- [, [Mechanism =>] MECHANISM]);
5201 when Pragma_Export_Procedure => Export_Procedure : declare
5202 Args : Args_List (1 .. 4);
5203 Names : Name_List (1 .. 4) := (
5206 Name_Parameter_Types,
5209 Internal : Node_Id renames Args (1);
5210 External : Node_Id renames Args (2);
5211 Parameter_Types : Node_Id renames Args (3);
5212 Mechanism : Node_Id renames Args (4);
5216 Gather_Associations (Names, Args);
5217 Process_Extended_Import_Export_Subprogram_Pragma (
5218 Arg_Internal => Internal,
5219 Arg_External => External,
5220 Arg_Parameter_Types => Parameter_Types,
5221 Arg_Mechanism => Mechanism);
5222 end Export_Procedure;
5224 -----------------------------
5225 -- Export_Valued_Procedure --
5226 -----------------------------
5228 -- pragma Export_Valued_Procedure (
5229 -- [Internal =>] LOCAL_NAME,
5230 -- [, [External =>] EXTERNAL_SYMBOL,]
5231 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5232 -- [, [Mechanism =>] MECHANISM]);
5234 when Pragma_Export_Valued_Procedure =>
5235 Export_Valued_Procedure : declare
5236 Args : Args_List (1 .. 4);
5237 Names : Name_List (1 .. 4) := (
5240 Name_Parameter_Types,
5243 Internal : Node_Id renames Args (1);
5244 External : Node_Id renames Args (2);
5245 Parameter_Types : Node_Id renames Args (3);
5246 Mechanism : Node_Id renames Args (4);
5250 Gather_Associations (Names, Args);
5251 Process_Extended_Import_Export_Subprogram_Pragma (
5252 Arg_Internal => Internal,
5253 Arg_External => External,
5254 Arg_Parameter_Types => Parameter_Types,
5255 Arg_Mechanism => Mechanism);
5256 end Export_Valued_Procedure;
5262 -- pragma Extend_System ([Name =>] Identifier);
5264 when Pragma_Extend_System => Extend_System : declare
5267 Check_Valid_Configuration_Pragma;
5268 Check_Arg_Count (1);
5269 Check_Optional_Identifier (Arg1, Name_Name);
5270 Check_Arg_Is_Identifier (Arg1);
5272 Get_Name_String (Chars (Expression (Arg1)));
5275 and then Name_Buffer (1 .. 4) = "aux_"
5277 if Present (System_Extend_Pragma_Arg) then
5278 if Chars (Expression (Arg1)) =
5279 Chars (Expression (System_Extend_Pragma_Arg))
5283 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
5284 Error_Pragma ("pragma% conflicts with that at#");
5288 System_Extend_Pragma_Arg := Arg1;
5291 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
5295 ------------------------
5296 -- Extensions_Allowed --
5297 ------------------------
5299 -- pragma Extensions_Allowed (ON | OFF);
5301 when Pragma_Extensions_Allowed =>
5303 Check_Arg_Count (1);
5304 Check_No_Identifiers;
5305 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5306 Extensions_Allowed := (Chars (Expression (Arg1)) = Name_On);
5312 -- pragma External (
5313 -- [ Convention =>] convention_IDENTIFIER,
5314 -- [ Entity =>] local_NAME
5315 -- [, [External_Name =>] static_string_EXPRESSION ]
5316 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5318 when Pragma_External => External : declare
5324 Check_At_Least_N_Arguments (2);
5325 Check_At_Most_N_Arguments (4);
5326 Process_Convention (C, Def_Id);
5327 Note_Possible_Modification (Expression (Arg2));
5328 Process_Interface_Name (Def_Id, Arg3, Arg4);
5329 Set_Exported (Def_Id, Arg2);
5332 --------------------------
5333 -- External_Name_Casing --
5334 --------------------------
5336 -- pragma External_Name_Casing (
5337 -- UPPERCASE | LOWERCASE
5338 -- [, AS_IS | UPPERCASE | LOWERCASE]);
5340 when Pragma_External_Name_Casing =>
5342 External_Name_Casing : declare
5345 Check_No_Identifiers;
5347 if Arg_Count = 2 then
5349 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
5351 case Chars (Get_Pragma_Arg (Arg2)) is
5353 Opt.External_Name_Exp_Casing := As_Is;
5355 when Name_Uppercase =>
5356 Opt.External_Name_Exp_Casing := Uppercase;
5358 when Name_Lowercase =>
5359 Opt.External_Name_Exp_Casing := Lowercase;
5366 Check_Arg_Count (1);
5369 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
5371 case Chars (Get_Pragma_Arg (Arg1)) is
5372 when Name_Uppercase =>
5373 Opt.External_Name_Imp_Casing := Uppercase;
5375 when Name_Lowercase =>
5376 Opt.External_Name_Imp_Casing := Lowercase;
5381 end External_Name_Casing;
5383 ---------------------------
5384 -- Finalize_Storage_Only --
5385 ---------------------------
5387 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
5389 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
5390 Assoc : Node_Id := Arg1;
5391 Type_Id : Node_Id := Expression (Assoc);
5395 Check_No_Identifiers;
5396 Check_Arg_Count (1);
5397 Check_Arg_Is_Local_Name (Arg1);
5399 Find_Type (Type_Id);
5400 Typ := Entity (Type_Id);
5403 or else Rep_Item_Too_Early (Typ, N)
5407 Typ := Underlying_Type (Typ);
5410 if not Is_Controlled (Typ) then
5411 Error_Pragma ("pragma% must specify controlled type");
5414 Check_First_Subtype (Arg1);
5416 if Finalize_Storage_Only (Typ) then
5417 Error_Pragma ("duplicate pragma%, only one allowed");
5419 elsif not Rep_Item_Too_Late (Typ, N) then
5420 Set_Finalize_Storage_Only (Base_Type (Typ), True);
5422 end Finalize_Storage;
5424 --------------------------
5425 -- Float_Representation --
5426 --------------------------
5428 -- pragma Float_Representation (VAX_Float | IEEE_Float);
5430 when Pragma_Float_Representation => Float_Representation : declare
5438 if Arg_Count = 1 then
5439 Check_Valid_Configuration_Pragma;
5441 Check_Arg_Count (2);
5442 Check_Optional_Identifier (Arg2, Name_Entity);
5443 Check_Arg_Is_Local_Name (Arg2);
5446 Check_No_Identifier (Arg1);
5447 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
5449 if not OpenVMS_On_Target then
5450 if Chars (Expression (Arg1)) = Name_VAX_Float then
5452 ("?pragma% ignored (applies only to Open'V'M'S)");
5458 -- One argument case
5460 if Arg_Count = 1 then
5462 if Chars (Expression (Arg1)) = Name_VAX_Float then
5464 if Opt.Float_Format = 'I' then
5465 Error_Pragma ("'I'E'E'E format previously specified");
5468 Opt.Float_Format := 'V';
5471 if Opt.Float_Format = 'V' then
5472 Error_Pragma ("'V'A'X format previously specified");
5475 Opt.Float_Format := 'I';
5478 Set_Standard_Fpt_Formats;
5480 -- Two argument case
5483 Argx := Get_Pragma_Arg (Arg2);
5485 if not Is_Entity_Name (Argx)
5486 or else not Is_Floating_Point_Type (Entity (Argx))
5489 ("second argument of% pragma must be floating-point type",
5493 Ent := Entity (Argx);
5494 Digs := UI_To_Int (Digits_Value (Ent));
5496 -- Two arguments, VAX_Float case
5498 if Chars (Expression (Arg1)) = Name_VAX_Float then
5501 when 6 => Set_F_Float (Ent);
5502 when 9 => Set_D_Float (Ent);
5503 when 15 => Set_G_Float (Ent);
5507 ("wrong digits value, must be 6,9 or 15", Arg2);
5510 -- Two arguments, IEEE_Float case
5514 when 6 => Set_IEEE_Short (Ent);
5515 when 15 => Set_IEEE_Long (Ent);
5519 ("wrong digits value, must be 6 or 15", Arg2);
5523 end Float_Representation;
5529 -- pragma Ident (static_string_EXPRESSION)
5531 -- Note: pragma Comment shares this processing. Pragma Comment
5532 -- is identical to Ident, except that the restriction of the
5533 -- argument to 31 characters and the placement restrictions
5534 -- are not enforced for pragma Comment.
5536 when Pragma_Ident | Pragma_Comment => Ident : declare
5541 Check_Arg_Count (1);
5542 Check_No_Identifiers;
5543 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
5545 -- For pragma Ident, preserve DEC compatibility by requiring
5546 -- the pragma to appear in a declarative part or package spec.
5548 if Prag_Id = Pragma_Ident then
5549 Check_Is_In_Decl_Part_Or_Package_Spec;
5552 Str := Expr_Value_S (Expression (Arg1));
5554 -- For pragma Ident, preserve DEC compatibility by limiting
5555 -- the length to 31 characters.
5557 if Prag_Id = Pragma_Ident
5558 and then String_Length (Strval (Str)) > 31
5561 ("argument for pragma% is too long, maximum is 31", Arg1);
5569 GP := Parent (Parent (N));
5571 if Nkind (GP) = N_Package_Declaration
5573 Nkind (GP) = N_Generic_Package_Declaration
5578 -- If we have a compilation unit, then record the ident
5579 -- value, checking for improper duplication.
5581 if Nkind (GP) = N_Compilation_Unit then
5582 CS := Ident_String (Current_Sem_Unit);
5584 if Present (CS) then
5586 -- For Ident, we do not permit multiple instances
5588 if Prag_Id = Pragma_Ident then
5589 Error_Pragma ("duplicate% pragma not permitted");
5591 -- For Comment, we concatenate the string, unless we
5592 -- want to preserve the tree structure for ASIS.
5594 elsif not Tree_Output then
5595 Start_String (Strval (CS));
5596 Store_String_Char (' ');
5597 Store_String_Chars (Strval (Str));
5598 Set_Strval (CS, End_String);
5602 -- In VMS, the effect of IDENT is achieved by passing
5603 -- IDENTIFICATION=name as a --for-linker switch.
5605 if OpenVMS_On_Target then
5608 ("--for-linker=IDENTIFICATION=");
5609 String_To_Name_Buffer (Strval (Str));
5610 Store_String_Chars (Name_Buffer (1 .. Name_Len));
5612 -- Only the last processed IDENT is saved. The main
5613 -- purpose is so an IDENT associated with a main
5614 -- procedure will be used in preference to an IDENT
5615 -- associated with a with'd package.
5617 Replace_Linker_Option_String
5618 (End_String, "--for-linker=IDENTIFICATION=");
5621 Set_Ident_String (Current_Sem_Unit, Str);
5624 -- For subunits, we just ignore the Ident, since in GNAT
5625 -- these are not separate object files, and hence not
5626 -- separate units in the unit table.
5628 elsif Nkind (GP) = N_Subunit then
5631 -- Otherwise we have a misplaced pragma Ident, but we ignore
5632 -- this if we are in an instantiation, since it comes from
5633 -- a generic, and has no relevance to the instantiation.
5635 elsif Prag_Id = Pragma_Ident then
5636 if Instantiation_Location (Loc) = No_Location then
5637 Error_Pragma ("pragma% only allowed at outer level");
5648 -- [ Convention =>] convention_IDENTIFIER,
5649 -- [ Entity =>] local_NAME
5650 -- [, [External_Name =>] static_string_EXPRESSION ]
5651 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5653 when Pragma_Import =>
5654 Check_Ada_83_Warning;
5655 Check_At_Least_N_Arguments (2);
5656 Check_At_Most_N_Arguments (4);
5657 Process_Import_Or_Interface;
5659 ----------------------
5660 -- Import_Exception --
5661 ----------------------
5663 -- pragma Import_Exception (
5664 -- [Internal =>] LOCAL_NAME,
5665 -- [, [External =>] EXTERNAL_SYMBOL,]
5666 -- [, [Form =>] Ada | VMS]
5667 -- [, [Code =>] static_integer_EXPRESSION]);
5669 when Pragma_Import_Exception => Import_Exception : declare
5670 Args : Args_List (1 .. 4);
5671 Names : Name_List (1 .. 4) := (
5677 Internal : Node_Id renames Args (1);
5678 External : Node_Id renames Args (2);
5679 Form : Node_Id renames Args (3);
5680 Code : Node_Id renames Args (4);
5683 Gather_Associations (Names, Args);
5685 if Present (External) and then Present (Code) then
5687 ("cannot give both External and Code options for pragma%");
5690 Process_Extended_Import_Export_Exception_Pragma (
5691 Arg_Internal => Internal,
5692 Arg_External => External,
5696 if not Is_VMS_Exception (Entity (Internal)) then
5697 Set_Imported (Entity (Internal));
5699 end Import_Exception;
5701 ---------------------
5702 -- Import_Function --
5703 ---------------------
5705 -- pragma Import_Function (
5706 -- [Internal =>] LOCAL_NAME,
5707 -- [, [External =>] EXTERNAL_SYMBOL]
5708 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5709 -- [, [Result_Type =>] SUBTYPE_MARK]
5710 -- [, [Mechanism =>] MECHANISM]
5711 -- [, [Result_Mechanism =>] MECHANISM_NAME]
5712 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
5714 when Pragma_Import_Function => Import_Function : declare
5715 Args : Args_List (1 .. 7);
5716 Names : Name_List (1 .. 7) := (
5719 Name_Parameter_Types,
5722 Name_Result_Mechanism,
5723 Name_First_Optional_Parameter);
5725 Internal : Node_Id renames Args (1);
5726 External : Node_Id renames Args (2);
5727 Parameter_Types : Node_Id renames Args (3);
5728 Result_Type : Node_Id renames Args (4);
5729 Mechanism : Node_Id renames Args (5);
5730 Result_Mechanism : Node_Id renames Args (6);
5731 First_Optional_Parameter : Node_Id renames Args (7);
5735 Gather_Associations (Names, Args);
5736 Process_Extended_Import_Export_Subprogram_Pragma (
5737 Arg_Internal => Internal,
5738 Arg_External => External,
5739 Arg_Parameter_Types => Parameter_Types,
5740 Arg_Result_Type => Result_Type,
5741 Arg_Mechanism => Mechanism,
5742 Arg_Result_Mechanism => Result_Mechanism,
5743 Arg_First_Optional_Parameter => First_Optional_Parameter);
5744 end Import_Function;
5750 -- pragma Import_Object (
5751 -- [Internal =>] LOCAL_NAME,
5752 -- [, [External =>] EXTERNAL_SYMBOL]
5753 -- [, [Size =>] EXTERNAL_SYMBOL]);
5755 when Pragma_Import_Object => Import_Object : declare
5756 Args : Args_List (1 .. 3);
5757 Names : Name_List (1 .. 3) := (
5762 Internal : Node_Id renames Args (1);
5763 External : Node_Id renames Args (2);
5764 Size : Node_Id renames Args (3);
5768 Gather_Associations (Names, Args);
5769 Process_Extended_Import_Export_Object_Pragma (
5770 Arg_Internal => Internal,
5771 Arg_External => External,
5775 ----------------------
5776 -- Import_Procedure --
5777 ----------------------
5779 -- pragma Import_Procedure (
5780 -- [Internal =>] LOCAL_NAME,
5781 -- [, [External =>] EXTERNAL_SYMBOL]
5782 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5783 -- [, [Mechanism =>] MECHANISM]
5784 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
5786 when Pragma_Import_Procedure => Import_Procedure : declare
5787 Args : Args_List (1 .. 5);
5788 Names : Name_List (1 .. 5) := (
5791 Name_Parameter_Types,
5793 Name_First_Optional_Parameter);
5795 Internal : Node_Id renames Args (1);
5796 External : Node_Id renames Args (2);
5797 Parameter_Types : Node_Id renames Args (3);
5798 Mechanism : Node_Id renames Args (4);
5799 First_Optional_Parameter : Node_Id renames Args (5);
5803 Gather_Associations (Names, Args);
5804 Process_Extended_Import_Export_Subprogram_Pragma (
5805 Arg_Internal => Internal,
5806 Arg_External => External,
5807 Arg_Parameter_Types => Parameter_Types,
5808 Arg_Mechanism => Mechanism,
5809 Arg_First_Optional_Parameter => First_Optional_Parameter);
5810 end Import_Procedure;
5812 -----------------------------
5813 -- Import_Valued_Procedure --
5814 -----------------------------
5816 -- pragma Import_Valued_Procedure (
5817 -- [Internal =>] LOCAL_NAME,
5818 -- [, [External =>] EXTERNAL_SYMBOL]
5819 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5820 -- [, [Mechanism =>] MECHANISM]
5821 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
5823 when Pragma_Import_Valued_Procedure =>
5824 Import_Valued_Procedure : declare
5825 Args : Args_List (1 .. 5);
5826 Names : Name_List (1 .. 5) := (
5829 Name_Parameter_Types,
5831 Name_First_Optional_Parameter);
5833 Internal : Node_Id renames Args (1);
5834 External : Node_Id renames Args (2);
5835 Parameter_Types : Node_Id renames Args (3);
5836 Mechanism : Node_Id renames Args (4);
5837 First_Optional_Parameter : Node_Id renames Args (5);
5841 Gather_Associations (Names, Args);
5842 Process_Extended_Import_Export_Subprogram_Pragma (
5843 Arg_Internal => Internal,
5844 Arg_External => External,
5845 Arg_Parameter_Types => Parameter_Types,
5846 Arg_Mechanism => Mechanism,
5847 Arg_First_Optional_Parameter => First_Optional_Parameter);
5848 end Import_Valued_Procedure;
5850 ------------------------
5851 -- Initialize_Scalars --
5852 ------------------------
5854 -- pragma Initialize_Scalars;
5856 when Pragma_Initialize_Scalars =>
5858 Check_Arg_Count (0);
5859 Check_Valid_Configuration_Pragma;
5860 Init_Or_Norm_Scalars := True;
5861 Initialize_Scalars := True;
5867 -- pragma Inline ( NAME {, NAME} );
5869 when Pragma_Inline =>
5871 -- Pragma is active if inlining option is active
5873 if Inline_Active then
5874 Process_Inline (True);
5876 -- Pragma is active in a predefined file in no run time mode
5880 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
5882 Process_Inline (True);
5885 Process_Inline (False);
5892 -- pragma Inline_Always ( NAME {, NAME} );
5894 when Pragma_Inline_Always =>
5895 Process_Inline (True);
5897 --------------------
5898 -- Inline_Generic --
5899 --------------------
5901 -- pragma Inline_Generic (NAME {, NAME});
5903 when Pragma_Inline_Generic =>
5904 Process_Generic_List;
5906 ----------------------
5907 -- Inspection_Point --
5908 ----------------------
5910 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
5912 when Pragma_Inspection_Point => Inspection_Point : declare
5917 if Arg_Count > 0 then
5920 Exp := Expression (Arg);
5923 if not Is_Entity_Name (Exp)
5924 or else not Is_Object (Entity (Exp))
5926 Error_Pragma_Arg ("object name required", Arg);
5933 end Inspection_Point;
5939 -- pragma Interface (
5940 -- convention_IDENTIFIER,
5943 when Pragma_Interface =>
5945 Check_Arg_Count (2);
5946 Check_No_Identifiers;
5947 Process_Import_Or_Interface;
5949 --------------------
5950 -- Interface_Name --
5951 --------------------
5953 -- pragma Interface_Name (
5954 -- [ Entity =>] local_NAME
5955 -- [,[External_Name =>] static_string_EXPRESSION ]
5956 -- [,[Link_Name =>] static_string_EXPRESSION ]);
5958 when Pragma_Interface_Name => Interface_Name : declare
5966 Check_At_Least_N_Arguments (2);
5967 Check_At_Most_N_Arguments (3);
5968 Id := Expression (Arg1);
5971 if not Is_Entity_Name (Id) then
5973 ("first argument for pragma% must be entity name", Arg1);
5974 elsif Etype (Id) = Any_Type then
5977 Def_Id := Entity (Id);
5980 -- Special DEC-compatible processing for the object case,
5981 -- forces object to be imported.
5983 if Ekind (Def_Id) = E_Variable then
5984 Kill_Size_Check_Code (Def_Id);
5985 Note_Possible_Modification (Id);
5987 -- Initialization is not allowed for imported variable
5989 if Present (Expression (Parent (Def_Id)))
5990 and then Comes_From_Source (Expression (Parent (Def_Id)))
5992 Error_Msg_Sloc := Sloc (Def_Id);
5994 ("no initialization allowed for declaration of& #",
5998 -- For compatibility, support VADS usage of providing both
5999 -- pragmas Interface and Interface_Name to obtain the effect
6000 -- of a single Import pragma.
6002 if Is_Imported (Def_Id)
6003 and then Present (First_Rep_Item (Def_Id))
6004 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6005 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6009 Set_Imported (Def_Id);
6012 Set_Is_Public (Def_Id);
6013 Process_Interface_Name (Def_Id, Arg2, Arg3);
6016 -- Otherwise must be subprogram
6018 elsif not Is_Subprogram (Def_Id) then
6020 ("argument of pragma% is not subprogram", Arg1);
6023 Check_At_Most_N_Arguments (3);
6027 -- Loop through homonyms
6030 Def_Id := Get_Base_Subprogram (Hom_Id);
6032 if Is_Imported (Def_Id) then
6033 Process_Interface_Name (Def_Id, Arg2, Arg3);
6037 Hom_Id := Homonym (Hom_Id);
6039 exit when No (Hom_Id)
6040 or else Scope (Hom_Id) /= Current_Scope;
6045 ("argument of pragma% is not imported subprogram",
6051 -----------------------
6052 -- Interrupt_Handler --
6053 -----------------------
6055 -- pragma Interrupt_Handler (handler_NAME);
6057 when Pragma_Interrupt_Handler =>
6058 Check_Ada_83_Warning;
6059 Check_Arg_Count (1);
6060 Check_No_Identifiers;
6061 Check_Interrupt_Or_Attach_Handler;
6062 Process_Interrupt_Or_Attach_Handler;
6064 ------------------------
6065 -- Interrupt_Priority --
6066 ------------------------
6068 -- pragma Interrupt_Priority [(EXPRESSION)];
6070 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
6071 P : constant Node_Id := Parent (N);
6075 Check_Ada_83_Warning;
6077 if Arg_Count /= 0 then
6078 Arg := Expression (Arg1);
6079 Check_Arg_Count (1);
6080 Check_No_Identifiers;
6082 -- Set In_Default_Expression for per-object case???
6084 Analyze_And_Resolve (Arg, Standard_Integer);
6085 if Expander_Active then
6087 Convert_To (RTE (RE_Interrupt_Priority), Arg));
6091 if Nkind (P) /= N_Task_Definition
6092 and then Nkind (P) /= N_Protected_Definition
6097 elsif Has_Priority_Pragma (P) then
6098 Error_Pragma ("duplicate pragma% not allowed");
6101 Set_Has_Priority_Pragma (P, True);
6102 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6104 end Interrupt_Priority;
6106 ----------------------
6107 -- Java_Constructor --
6108 ----------------------
6110 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
6112 when Pragma_Java_Constructor => Java_Constructor : declare
6119 Check_Arg_Count (1);
6120 Check_Optional_Identifier (Arg1, Name_Entity);
6121 Check_Arg_Is_Local_Name (Arg1);
6123 Id := Expression (Arg1);
6124 Find_Program_Unit_Name (Id);
6126 -- If we did not find the name, we are done
6128 if Etype (Id) = Any_Type then
6132 Hom_Id := Entity (Id);
6134 -- Loop through homonyms
6137 Def_Id := Get_Base_Subprogram (Hom_Id);
6139 -- The constructor is required to be a function returning
6140 -- an access type whose designated type has convention Java.
6142 if Ekind (Def_Id) = E_Function
6143 and then Ekind (Etype (Def_Id)) in Access_Kind
6146 (Designated_Type (Etype (Def_Id))) = Convention_Java
6149 (Root_Type (Designated_Type (Etype (Def_Id))))
6152 Set_Is_Constructor (Def_Id);
6153 Set_Convention (Def_Id, Convention_Java);
6157 ("pragma% requires function returning a 'Java access type",
6161 Hom_Id := Homonym (Hom_Id);
6163 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
6165 end Java_Constructor;
6167 ----------------------
6168 -- Java_Interface --
6169 ----------------------
6171 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
6173 when Pragma_Java_Interface => Java_Interface : declare
6179 Check_Arg_Count (1);
6180 Check_Optional_Identifier (Arg1, Name_Entity);
6181 Check_Arg_Is_Local_Name (Arg1);
6183 Arg := Expression (Arg1);
6186 if Etype (Arg) = Any_Type then
6190 if not Is_Entity_Name (Arg)
6191 or else not Is_Type (Entity (Arg))
6193 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6196 Typ := Underlying_Type (Entity (Arg));
6198 -- For now we simply check some of the semantic constraints
6199 -- on the type. This currently leaves out some restrictions
6200 -- on interface types, namely that the parent type must be
6201 -- java.lang.Object.Typ and that all primitives of the type
6202 -- should be declared abstract. ???
6204 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
6205 Error_Pragma_Arg ("pragma% requires an abstract "
6206 & "tagged type", Arg1);
6208 elsif not Has_Discriminants (Typ)
6209 or else Ekind (Etype (First_Discriminant (Typ)))
6210 /= E_Anonymous_Access_Type
6212 not Is_Class_Wide_Type
6213 (Designated_Type (Etype (First_Discriminant (Typ))))
6216 ("type must have a class-wide access discriminant", Arg1);
6224 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
6226 when Pragma_License =>
6228 Check_Arg_Count (1);
6229 Check_No_Identifiers;
6230 Check_Valid_Configuration_Pragma;
6231 Check_Arg_Is_Identifier (Arg1);
6234 Sind : constant Source_File_Index :=
6235 Source_Index (Current_Sem_Unit);
6238 case Chars (Get_Pragma_Arg (Arg1)) is
6240 Set_License (Sind, GPL);
6242 when Name_Modified_GPL =>
6243 Set_License (Sind, Modified_GPL);
6245 when Name_Restricted =>
6246 Set_License (Sind, Restricted);
6248 when Name_Unrestricted =>
6249 Set_License (Sind, Unrestricted);
6252 Error_Pragma_Arg ("invalid license name", Arg1);
6260 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
6262 when Pragma_Link_With => Link_With : declare
6268 if Operating_Mode = Generate_Code
6269 and then In_Extended_Main_Source_Unit (N)
6271 Check_At_Least_N_Arguments (1);
6272 Check_No_Identifiers;
6273 Check_Is_In_Decl_Part_Or_Package_Spec;
6274 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6278 while Present (Arg) loop
6279 Check_Arg_Is_Static_Expression (Arg, Standard_String);
6281 -- Store argument, converting sequences of spaces
6282 -- to a single null character (this is one of the
6283 -- differences in processing between Link_With
6284 -- and Linker_Options).
6287 C : constant Char_Code := Get_Char_Code (' ');
6288 S : constant String_Id :=
6289 Strval (Expr_Value_S (Expression (Arg)));
6292 L : Nat := String_Length (S);
6294 procedure Skip_Spaces;
6295 -- Advance F past any spaces
6297 procedure Skip_Spaces is
6299 while F <= L and then Get_String_Char (S, F) = C loop
6305 Skip_Spaces; -- skip leading spaces
6307 -- Loop through characters, changing any embedded
6308 -- sequence of spaces to a single null character
6309 -- (this is how Link_With/Linker_Options differ)
6312 if Get_String_Char (S, F) = C then
6315 Store_String_Char (ASCII.NUL);
6318 Store_String_Char (Get_String_Char (S, F));
6326 if Present (Arg) then
6327 Store_String_Char (ASCII.NUL);
6331 Store_Linker_Option_String (End_String);
6339 -- pragma Linker_Alias (
6340 -- [Entity =>] LOCAL_NAME
6341 -- [Alias =>] static_string_EXPRESSION);
6343 when Pragma_Linker_Alias =>
6345 Check_Arg_Count (2);
6346 Check_Optional_Identifier (Arg1, Name_Entity);
6347 Check_Optional_Identifier (Arg2, "alias");
6348 Check_Arg_Is_Library_Level_Local_Name (Arg1);
6349 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6351 -- The only processing required is to link this item on to the
6352 -- list of rep items for the given entity. This is accomplished
6353 -- by the call to Rep_Item_Too_Late (when no error is detected
6354 -- and False is returned).
6356 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
6359 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6362 --------------------
6363 -- Linker_Options --
6364 --------------------
6366 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
6368 when Pragma_Linker_Options => Linker_Options : declare
6372 Check_Ada_83_Warning;
6373 Check_No_Identifiers;
6374 Check_Arg_Count (1);
6375 Check_Is_In_Decl_Part_Or_Package_Spec;
6377 if Operating_Mode = Generate_Code
6378 and then In_Extended_Main_Source_Unit (N)
6380 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6381 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
6384 while Present (Arg) loop
6385 Check_Arg_Is_Static_Expression (Arg, Standard_String);
6386 Store_String_Char (ASCII.NUL);
6388 (Strval (Expr_Value_S (Expression (Arg))));
6392 Store_Linker_Option_String (End_String);
6396 --------------------
6397 -- Linker_Section --
6398 --------------------
6400 -- pragma Linker_Section (
6401 -- [Entity =>] LOCAL_NAME
6402 -- [Section =>] static_string_EXPRESSION);
6404 when Pragma_Linker_Section =>
6406 Check_Arg_Count (2);
6407 Check_Optional_Identifier (Arg1, Name_Entity);
6408 Check_Optional_Identifier (Arg2, Name_Section);
6409 Check_Arg_Is_Library_Level_Local_Name (Arg1);
6410 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6412 -- The only processing required is to link this item on to the
6413 -- list of rep items for the given entity. This is accomplished
6414 -- by the call to Rep_Item_Too_Late (when no error is detected
6415 -- and False is returned).
6417 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
6420 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6427 -- pragma List (On | Off)
6429 -- There is nothing to do here, since we did all the processing
6430 -- for this pragma in Par.Prag (so that it works properly even in
6431 -- syntax only mode)
6436 --------------------
6437 -- Locking_Policy --
6438 --------------------
6440 -- pragma Locking_Policy (policy_IDENTIFIER);
6442 when Pragma_Locking_Policy => declare
6446 Check_Ada_83_Warning;
6447 Check_Arg_Count (1);
6448 Check_No_Identifiers;
6449 Check_Arg_Is_Locking_Policy (Arg1);
6450 Check_Valid_Configuration_Pragma;
6451 Get_Name_String (Chars (Expression (Arg1)));
6452 LP := Fold_Upper (Name_Buffer (1));
6454 if Locking_Policy /= ' '
6455 and then Locking_Policy /= LP
6457 Error_Msg_Sloc := Locking_Policy_Sloc;
6458 Error_Pragma ("locking policy incompatible with policy#");
6460 Locking_Policy := LP;
6461 Locking_Policy_Sloc := Loc;
6469 -- pragma Long_Float (D_Float | G_Float);
6471 when Pragma_Long_Float =>
6473 Check_Valid_Configuration_Pragma;
6474 Check_Arg_Count (1);
6475 Check_No_Identifier (Arg1);
6476 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
6478 if not OpenVMS_On_Target then
6479 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
6484 if Chars (Expression (Arg1)) = Name_D_Float then
6485 if Opt.Float_Format_Long = 'G' then
6486 Error_Pragma ("G_Float previously specified");
6489 Opt.Float_Format_Long := 'D';
6491 -- G_Float case (this is the default, does not need overriding)
6494 if Opt.Float_Format_Long = 'D' then
6495 Error_Pragma ("D_Float previously specified");
6498 Opt.Float_Format_Long := 'G';
6501 Set_Standard_Fpt_Formats;
6503 -----------------------
6504 -- Machine_Attribute --
6505 -----------------------
6507 -- pragma Machine_Attribute (
6508 -- [Entity =>] LOCAL_NAME,
6509 -- [Attribute_Name =>] static_string_EXPRESSION
6510 -- [,[Info =>] static_string_EXPRESSION] );
6512 when Pragma_Machine_Attribute => Machine_Attribute : declare
6518 if Arg_Count = 3 then
6519 Check_Optional_Identifier (Arg3, "info");
6520 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
6522 Check_Arg_Count (2);
6525 Check_Arg_Is_Local_Name (Arg1);
6526 Check_Optional_Identifier (Arg2, "attribute_name");
6527 Check_Optional_Identifier (Arg1, Name_Entity);
6528 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6529 Def_Id := Entity (Expression (Arg1));
6531 if Is_Access_Type (Def_Id) then
6532 Def_Id := Designated_Type (Def_Id);
6535 if Rep_Item_Too_Early (Def_Id, N) then
6539 Def_Id := Underlying_Type (Def_Id);
6541 -- The only processing required is to link this item on to the
6542 -- list of rep items for the given entity. This is accomplished
6543 -- by the call to Rep_Item_Too_Late (when no error is detected
6544 -- and False is returned).
6546 if Rep_Item_Too_Late (Def_Id, N) then
6549 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6551 end Machine_Attribute;
6557 -- pragma Main_Storage
6558 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
6560 -- MAIN_STORAGE_OPTION ::=
6561 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
6562 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
6564 when Pragma_Main => Main : declare
6565 Args : Args_List (1 .. 3);
6566 Names : Name_List (1 .. 3) := (
6568 Name_Task_Stack_Size_Default,
6569 Name_Time_Slicing_Enabled);
6575 Gather_Associations (Names, Args);
6577 for J in 1 .. 2 loop
6578 if Present (Args (J)) then
6579 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
6583 if Present (Args (3)) then
6584 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
6588 while Present (Nod) loop
6589 if Nkind (Nod) = N_Pragma
6590 and then Chars (Nod) = Name_Main
6592 Error_Msg_Name_1 := Chars (N);
6593 Error_Msg_N ("duplicate pragma% not permitted", Nod);
6604 -- pragma Main_Storage
6605 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
6607 -- MAIN_STORAGE_OPTION ::=
6608 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
6609 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
6611 when Pragma_Main_Storage => Main_Storage : declare
6612 Args : Args_List (1 .. 2);
6613 Names : Name_List (1 .. 2) := (
6614 Name_Working_Storage,
6621 Gather_Associations (Names, Args);
6623 for J in 1 .. 2 loop
6624 if Present (Args (J)) then
6625 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
6629 Check_In_Main_Program;
6632 while Present (Nod) loop
6633 if Nkind (Nod) = N_Pragma
6634 and then Chars (Nod) = Name_Main_Storage
6636 Error_Msg_Name_1 := Chars (N);
6637 Error_Msg_N ("duplicate pragma% not permitted", Nod);
6648 -- pragma Memory_Size (NUMERIC_LITERAL)
6650 when Pragma_Memory_Size =>
6653 -- Memory size is simply ignored
6655 Check_No_Identifiers;
6656 Check_Arg_Count (1);
6657 Check_Arg_Is_Integer_Literal (Arg1);
6663 -- pragma No_Return (procedure_LOCAL_NAME);
6665 when Pragma_No_Return => declare
6672 Check_Arg_Count (1);
6673 Check_No_Identifiers;
6674 Check_Arg_Is_Local_Name (Arg1);
6675 Id := Expression (Arg1);
6678 if not Is_Entity_Name (Id) then
6679 Error_Pragma_Arg ("entity name required", Arg1);
6682 if Etype (Id) = Any_Type then
6690 and then Scope (E) = Current_Scope
6692 if Ekind (E) = E_Procedure
6693 or else Ekind (E) = E_Generic_Procedure
6703 Error_Pragma ("no procedures found for pragma%");
6711 -- pragma No_Run_Time
6713 when Pragma_No_Run_Time =>
6715 Check_Valid_Configuration_Pragma;
6716 Check_Arg_Count (0);
6717 Set_No_Run_Time_Mode;
6719 -----------------------
6720 -- Normalize_Scalars --
6721 -----------------------
6723 -- pragma Normalize_Scalars;
6725 when Pragma_Normalize_Scalars =>
6726 Check_Ada_83_Warning;
6727 Check_Arg_Count (0);
6728 Check_Valid_Configuration_Pragma;
6729 Normalize_Scalars := True;
6730 Init_Or_Norm_Scalars := True;
6736 -- pragma Optimize (Time | Space);
6738 -- The actual check for optimize is done in Gigi. Note that this
6739 -- pragma does not actually change the optimization setting, it
6740 -- simply checks that it is consistent with the pragma.
6742 when Pragma_Optimize =>
6743 Check_No_Identifiers;
6744 Check_Arg_Count (1);
6745 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
6751 -- pragma Pack (first_subtype_LOCAL_NAME);
6753 when Pragma_Pack => Pack : declare
6754 Assoc : Node_Id := Arg1;
6759 Check_No_Identifiers;
6760 Check_Arg_Count (1);
6761 Check_Arg_Is_Local_Name (Arg1);
6763 Type_Id := Expression (Assoc);
6764 Find_Type (Type_Id);
6765 Typ := Entity (Type_Id);
6768 or else Rep_Item_Too_Early (Typ, N)
6772 Typ := Underlying_Type (Typ);
6775 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
6776 Error_Pragma ("pragma% must specify array or record type");
6779 Check_First_Subtype (Arg1);
6781 if Has_Pragma_Pack (Typ) then
6782 Error_Pragma ("duplicate pragma%, only one allowed");
6784 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
6785 -- but not Has_Non_Standard_Rep, because we don't actually know
6786 -- till freeze time if the array can have packed representation.
6787 -- That's because in the general case we do not know enough about
6788 -- the component type until it in turn is frozen, which certainly
6789 -- happens before the array type is frozen, but not necessarily
6790 -- till that point (i.e. right now it may be unfrozen).
6792 elsif Is_Array_Type (Typ) then
6794 if Has_Aliased_Components (Base_Type (Typ)) then
6796 ("pragma% ignored, cannot pack aliased components?");
6798 elsif Has_Atomic_Components (Typ) then
6800 ("?pragma% ignored, cannot pack atomic components");
6802 elsif not Rep_Item_Too_Late (Typ, N) then
6803 Set_Is_Packed (Base_Type (Typ));
6804 Set_Has_Pragma_Pack (Base_Type (Typ));
6805 Set_Has_Non_Standard_Rep (Base_Type (Typ));
6808 -- Record type. For record types, the pack is always effective
6810 else -- Is_Record_Type (Typ)
6811 if not Rep_Item_Too_Late (Typ, N) then
6812 Set_Has_Pragma_Pack (Base_Type (Typ));
6813 Set_Is_Packed (Base_Type (Typ));
6814 Set_Has_Non_Standard_Rep (Base_Type (Typ));
6825 -- There is nothing to do here, since we did all the processing
6826 -- for this pragma in Par.Prag (so that it works properly even in
6827 -- syntax only mode)
6836 -- pragma Passive [(PASSIVE_FORM)];
6838 -- PASSIVE_FORM ::= Semaphore | No
6840 when Pragma_Passive =>
6843 if Nkind (Parent (N)) /= N_Task_Definition then
6844 Error_Pragma ("pragma% must be within task definition");
6847 if Arg_Count /= 0 then
6848 Check_Arg_Count (1);
6849 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
6856 -- pragma Polling (ON | OFF);
6858 when Pragma_Polling =>
6860 Check_Arg_Count (1);
6861 Check_No_Identifiers;
6862 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6863 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
6869 -- pragma Preelaborate [(library_unit_NAME)];
6871 -- Set the flag Is_Preelaborated of program unit name entity
6873 when Pragma_Preelaborate => Preelaborate : declare
6875 Pa : Node_Id := Parent (N);
6876 Pk : Node_Kind := Nkind (Pa);
6879 Check_Ada_83_Warning;
6880 Check_Valid_Library_Unit_Pragma;
6882 if Nkind (N) = N_Null_Statement then
6886 Ent := Find_Lib_Unit_Name;
6888 -- This filters out pragmas inside generic parent then
6889 -- show up inside instantiation
6892 and then not (Pk = N_Package_Specification
6893 and then Present (Generic_Parent (Pa)))
6895 if not Debug_Flag_U then
6896 Set_Is_Preelaborated (Ent);
6897 Set_Suppress_Elaboration_Warnings (Ent);
6906 -- pragma Priority (EXPRESSION);
6908 when Pragma_Priority => Priority : declare
6909 P : constant Node_Id := Parent (N);
6913 Check_No_Identifiers;
6914 Check_Arg_Count (1);
6916 Arg := Expression (Arg1);
6917 Analyze_And_Resolve (Arg, Standard_Integer);
6919 if not Is_Static_Expression (Arg) then
6920 Check_Restriction (Static_Priorities, Arg);
6925 if Nkind (P) = N_Subprogram_Body then
6926 Check_In_Main_Program;
6930 if not Is_Static_Expression (Arg) then
6932 ("main subprogram priority is not static", Arg1);
6934 -- If constraint error, then we already signalled an error
6936 elsif Raises_Constraint_Error (Arg) then
6939 -- Otherwise check in range
6943 Val : constant Uint := Expr_Value (Arg);
6947 or else Val > Expr_Value (Expression
6948 (Parent (RTE (RE_Max_Priority))))
6951 ("main subprogram priority is out of range", Arg1);
6957 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
6959 -- Task or Protected, must be of type Integer
6961 elsif Nkind (P) = N_Protected_Definition
6963 Nkind (P) = N_Task_Definition
6965 if Expander_Active then
6967 Convert_To (RTE (RE_Any_Priority), Arg));
6970 -- Anything else is incorrect
6976 if Has_Priority_Pragma (P) then
6977 Error_Pragma ("duplicate pragma% not allowed");
6979 Set_Has_Priority_Pragma (P, True);
6981 if Nkind (P) = N_Protected_Definition
6983 Nkind (P) = N_Task_Definition
6985 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6986 -- exp_ch9 should use this ???
6991 --------------------------
6992 -- Propagate_Exceptions --
6993 --------------------------
6995 -- pragma Propagate_Exceptions;
6997 when Pragma_Propagate_Exceptions =>
6999 Check_Arg_Count (0);
7001 if In_Extended_Main_Source_Unit (N) then
7002 Propagate_Exceptions := True;
7009 -- pragma Psect_Object (
7010 -- [Internal =>] LOCAL_NAME,
7011 -- [, [External =>] EXTERNAL_SYMBOL]
7012 -- [, [Size =>] EXTERNAL_SYMBOL]);
7014 when Pragma_Psect_Object | Pragma_Common_Object =>
7015 Psect_Object : declare
7016 Args : Args_List (1 .. 3);
7017 Names : Name_List (1 .. 3) := (
7022 Internal : Node_Id renames Args (1);
7023 External : Node_Id renames Args (2);
7024 Size : Node_Id renames Args (3);
7026 R_Internal : Node_Id;
7027 R_External : Node_Id;
7034 procedure Check_Too_Long (Arg : Node_Id);
7035 -- Posts message if the argument is an identifier with more
7036 -- than 31 characters, or a string literal with more than
7037 -- 31 characters, and we are operating under VMS
7039 --------------------
7040 -- Check_Too_Long --
7041 --------------------
7043 procedure Check_Too_Long (Arg : Node_Id) is
7044 X : Node_Id := Original_Node (Arg);
7047 if Nkind (X) /= N_String_Literal
7049 Nkind (X) /= N_Identifier
7052 ("inappropriate argument for pragma %", Arg);
7055 if OpenVMS_On_Target then
7056 if (Nkind (X) = N_String_Literal
7057 and then String_Length (Strval (X)) > 31)
7059 (Nkind (X) = N_Identifier
7060 and then Length_Of_Name (Chars (X)) > 31)
7063 ("argument for pragma % is longer than 31 characters",
7069 -- Start of processing for Common_Object/Psect_Object
7073 Gather_Associations (Names, Args);
7074 Process_Extended_Import_Export_Internal_Arg (Internal);
7076 R_Internal := Relocate_Node (Internal);
7078 Def_Id := Entity (R_Internal);
7080 if Ekind (Def_Id) /= E_Constant
7081 and then Ekind (Def_Id) /= E_Variable
7084 ("pragma% must designate an object", Internal);
7087 Check_Too_Long (R_Internal);
7089 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
7091 ("cannot use pragma% for imported/exported object",
7095 if Is_Concurrent_Type (Etype (R_Internal)) then
7097 ("cannot specify pragma % for task/protected object",
7101 if Is_Psected (Def_Id) then
7102 Error_Msg_N ("?duplicate Psect_Object pragma", N);
7104 Set_Is_Psected (Def_Id);
7107 if Ekind (Def_Id) = E_Constant then
7109 ("cannot specify pragma % for a constant", R_Internal);
7112 if Is_Record_Type (Etype (R_Internal)) then
7118 Ent := First_Entity (Etype (R_Internal));
7119 while Present (Ent) loop
7120 Decl := Declaration_Node (Ent);
7122 if Ekind (Ent) = E_Component
7123 and then Nkind (Decl) = N_Component_Declaration
7124 and then Present (Expression (Decl))
7127 ("?object for pragma % has defaults", R_Internal);
7137 if Present (Size) then
7138 Check_Too_Long (Size);
7141 -- Make Psect case-insensitive.
7143 if Present (External) then
7144 Check_Too_Long (External);
7146 if Nkind (External) = N_String_Literal then
7147 String_To_Name_Buffer (Strval (External));
7149 Get_Name_String (Chars (External));
7154 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7156 R_External := Make_String_Literal
7157 (Sloc => Sloc (External), Strval => Str);
7159 Get_Name_String (Chars (Internal));
7162 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7164 R_External := Make_String_Literal
7165 (Sloc => Sloc (Internal), Strval => Str);
7168 -- Transform into pragma Linker_Section, add attributes to
7169 -- match what DEC Ada does. Ignore size for now?
7174 Name_Linker_Section,
7176 (Make_Pragma_Argument_Association
7177 (Sloc => Sloc (R_Internal),
7178 Expression => R_Internal),
7179 Make_Pragma_Argument_Association
7180 (Sloc => Sloc (R_External),
7181 Expression => R_External))));
7185 -- Add Machine_Attribute of "overlaid", so the section overlays
7186 -- other sections of the same name.
7189 Store_String_Chars ("overlaid");
7195 Name_Machine_Attribute,
7197 (Make_Pragma_Argument_Association
7198 (Sloc => Sloc (R_Internal),
7199 Expression => R_Internal),
7200 Make_Pragma_Argument_Association
7201 (Sloc => Sloc (R_External),
7204 (Sloc => Sloc (R_External),
7208 -- Add Machine_Attribute of "global", so the section is visible
7212 Store_String_Chars ("global");
7218 Name_Machine_Attribute,
7220 (Make_Pragma_Argument_Association
7221 (Sloc => Sloc (R_Internal),
7222 Expression => R_Internal),
7223 Make_Pragma_Argument_Association
7224 (Sloc => Sloc (R_External),
7227 (Sloc => Sloc (R_External),
7231 -- Add Machine_Attribute of "initialize", so the section is
7235 Store_String_Chars ("initialize");
7241 Name_Machine_Attribute,
7243 (Make_Pragma_Argument_Association
7244 (Sloc => Sloc (R_Internal),
7245 Expression => R_Internal),
7246 Make_Pragma_Argument_Association
7247 (Sloc => Sloc (R_External),
7250 (Sloc => Sloc (R_External),
7259 -- pragma Pure [(library_unit_NAME)];
7261 when Pragma_Pure => Pure : declare
7264 Check_Ada_83_Warning;
7265 Check_Valid_Library_Unit_Pragma;
7267 if Nkind (N) = N_Null_Statement then
7271 Ent := Find_Lib_Unit_Name;
7273 Set_Suppress_Elaboration_Warnings (Ent);
7280 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
7282 when Pragma_Pure_Function => Pure_Function : declare
7289 Check_Arg_Count (1);
7290 Check_Optional_Identifier (Arg1, Name_Entity);
7291 Check_Arg_Is_Local_Name (Arg1);
7292 E_Id := Expression (Arg1);
7294 if Error_Posted (E_Id) then
7298 -- Loop through homonyms (overloadings) of referenced entity
7301 while Present (E) loop
7302 Def_Id := Get_Base_Subprogram (E);
7304 if Ekind (Def_Id) /= E_Function
7305 and then Ekind (Def_Id) /= E_Generic_Function
7306 and then Ekind (Def_Id) /= E_Operator
7308 Error_Pragma_Arg ("pragma% requires a function name", Arg1);
7311 Set_Is_Pure (Def_Id);
7312 Set_Has_Pragma_Pure_Function (Def_Id);
7317 --------------------
7318 -- Queuing_Policy --
7319 --------------------
7321 -- pragma Queuing_Policy (policy_IDENTIFIER);
7323 when Pragma_Queuing_Policy => declare
7327 Check_Ada_83_Warning;
7328 Check_Arg_Count (1);
7329 Check_No_Identifiers;
7330 Check_Arg_Is_Queuing_Policy (Arg1);
7331 Check_Valid_Configuration_Pragma;
7332 Get_Name_String (Chars (Expression (Arg1)));
7333 QP := Fold_Upper (Name_Buffer (1));
7335 if Queuing_Policy /= ' '
7336 and then Queuing_Policy /= QP
7338 Error_Msg_Sloc := Queuing_Policy_Sloc;
7339 Error_Pragma ("queuing policy incompatible with policy#");
7341 Queuing_Policy := QP;
7342 Queuing_Policy_Sloc := Loc;
7346 ---------------------------
7347 -- Remote_Call_Interface --
7348 ---------------------------
7350 -- pragma Remote_Call_Interface [(library_unit_NAME)];
7352 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
7353 Cunit_Node : Node_Id;
7354 Cunit_Ent : Entity_Id;
7358 Check_Ada_83_Warning;
7359 Check_Valid_Library_Unit_Pragma;
7361 if Nkind (N) = N_Null_Statement then
7365 Cunit_Node := Cunit (Current_Sem_Unit);
7366 K := Nkind (Unit (Cunit_Node));
7367 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7369 if K = N_Package_Declaration
7370 or else K = N_Generic_Package_Declaration
7371 or else K = N_Subprogram_Declaration
7372 or else K = N_Generic_Subprogram_Declaration
7373 or else (K = N_Subprogram_Body
7374 and then Acts_As_Spec (Unit (Cunit_Node)))
7379 "pragma% must apply to package or subprogram declaration");
7382 Set_Is_Remote_Call_Interface (Cunit_Ent);
7383 end Remote_Call_Interface;
7389 -- pragma Remote_Types [(library_unit_NAME)];
7391 when Pragma_Remote_Types => Remote_Types : declare
7392 Cunit_Node : Node_Id;
7393 Cunit_Ent : Entity_Id;
7396 Check_Ada_83_Warning;
7397 Check_Valid_Library_Unit_Pragma;
7399 if Nkind (N) = N_Null_Statement then
7403 Cunit_Node := Cunit (Current_Sem_Unit);
7404 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7406 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
7408 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
7411 "pragma% can only apply to a package declaration");
7414 Set_Is_Remote_Types (Cunit_Ent);
7421 when Pragma_Ravenscar =>
7423 Check_Arg_Count (0);
7424 Check_Valid_Configuration_Pragma;
7427 -------------------------
7428 -- Restricted_Run_Time --
7429 -------------------------
7431 when Pragma_Restricted_Run_Time =>
7433 Check_Arg_Count (0);
7434 Check_Valid_Configuration_Pragma;
7435 Set_Restricted_Profile;
7441 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
7444 -- restriction_IDENTIFIER
7445 -- | restriction_parameter_IDENTIFIER => EXPRESSION
7447 when Pragma_Restrictions => Restrictions_Pragma : declare
7449 R_Id : Restriction_Id;
7450 RP_Id : Restriction_Parameter_Id;
7456 Check_Ada_83_Warning;
7457 Check_At_Least_N_Arguments (1);
7458 Check_Valid_Configuration_Pragma;
7462 while Present (Arg) loop
7464 Expr := Expression (Arg);
7466 -- Case of no restriction identifier
7468 if Id = No_Name then
7469 if Nkind (Expr) /= N_Identifier then
7471 ("invalid form for restriction", Arg);
7474 R_Id := Get_Restriction_Id (Chars (Expr));
7476 if R_Id = Not_A_Restriction_Id then
7478 ("invalid restriction identifier", Arg);
7480 -- Restriction is active
7483 if Implementation_Restriction (R_Id) then
7485 (No_Implementation_Restrictions, Arg);
7488 Restrictions (R_Id) := True;
7489 Restrictions_Loc (R_Id) := Sloc (N);
7491 -- Record the restriction if we are in the main unit,
7492 -- or in the extended main unit. The reason that we
7493 -- test separately for Main_Unit is that gnat.adc is
7494 -- processed with Current_Sem_Unit = Main_Unit, but
7495 -- nodes in gnat.adc do not appear to be the extended
7496 -- main source unit (they probably should do ???)
7498 if Current_Sem_Unit = Main_Unit
7499 or else In_Extended_Main_Source_Unit (N)
7501 Main_Restrictions (R_Id) := True;
7504 -- A very special case that must be processed here:
7505 -- pragma Restrictions (No_Exceptions) turns off all
7506 -- run-time checking. This is a bit dubious in terms
7507 -- of the formal language definition, but it is what
7508 -- is intended by the wording of RM H.4(12).
7510 if R_Id = No_Exceptions then
7511 Scope_Suppress := (others => True);
7516 -- Case of restriction identifier present
7519 RP_Id := Get_Restriction_Parameter_Id (Id);
7520 Analyze_And_Resolve (Expr, Any_Integer);
7522 if RP_Id = Not_A_Restriction_Parameter_Id then
7524 ("invalid restriction parameter identifier", Arg);
7526 elsif not Is_OK_Static_Expression (Expr)
7527 or else not Is_Integer_Type (Etype (Expr))
7528 or else Expr_Value (Expr) < 0
7531 ("value must be non-negative static integer", Arg);
7533 -- Restriction pragma is active
7536 Val := Expr_Value (Expr);
7538 -- Record pragma if most restrictive so far
7540 if Restriction_Parameters (RP_Id) = No_Uint
7541 or else Val < Restriction_Parameters (RP_Id)
7543 Restriction_Parameters (RP_Id) := Expr_Value (Expr);
7544 Restriction_Parameters_Loc (RP_Id) := Sloc (N);
7551 end Restrictions_Pragma;
7557 -- pragma Reviewable;
7559 when Pragma_Reviewable =>
7560 Check_Ada_83_Warning;
7561 Check_Arg_Count (0);
7567 -- pragma Share_Generic (NAME {, NAME});
7569 when Pragma_Share_Generic =>
7571 Process_Generic_List;
7577 -- pragma Shared (LOCAL_NAME);
7579 when Pragma_Shared =>
7581 Process_Atomic_Shared_Volatile;
7583 --------------------
7584 -- Shared_Passive --
7585 --------------------
7587 -- pragma Shared_Passive [(library_unit_NAME)];
7589 -- Set the flag Is_Shared_Passive of program unit name entity
7591 when Pragma_Shared_Passive => Shared_Passive : declare
7592 Cunit_Node : Node_Id;
7593 Cunit_Ent : Entity_Id;
7596 Check_Ada_83_Warning;
7597 Check_Valid_Library_Unit_Pragma;
7599 if Nkind (N) = N_Null_Statement then
7603 Cunit_Node := Cunit (Current_Sem_Unit);
7604 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7606 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
7608 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
7611 "pragma% can only apply to a package declaration");
7614 Set_Is_Shared_Passive (Cunit_Ent);
7617 ----------------------
7618 -- Source_File_Name --
7619 ----------------------
7621 -- pragma Source_File_Name (
7622 -- [UNIT_NAME =>] unit_NAME,
7623 -- [BODY_FILE_NAME | SPEC_FILE_NAME] => STRING_LITERAL);
7625 -- No processing here. Processing was completed during parsing,
7626 -- since we need to have file names set as early as possible.
7627 -- Units are loaded well before semantic processing starts.
7629 -- The only processing we defer to this point is the check
7630 -- for correct placement.
7632 when Pragma_Source_File_Name =>
7634 Check_Valid_Configuration_Pragma;
7636 ----------------------
7637 -- Source_Reference --
7638 ----------------------
7640 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
7642 -- Nothing to do, all processing completed in Par.Prag, since we
7643 -- need the information for possible parser messages that are output
7645 when Pragma_Source_Reference =>
7652 -- pragma Storage_Size (EXPRESSION);
7654 when Pragma_Storage_Size => Storage_Size : declare
7655 P : constant Node_Id := Parent (N);
7659 Check_No_Identifiers;
7660 Check_Arg_Count (1);
7662 -- Set In_Default_Expression for per-object case???
7664 X := Expression (Arg1);
7665 Analyze_And_Resolve (X, Any_Integer);
7667 if not Is_Static_Expression (X) then
7668 Check_Restriction (Static_Storage_Size, X);
7671 if Nkind (P) /= N_Task_Definition then
7676 if Has_Storage_Size_Pragma (P) then
7677 Error_Pragma ("duplicate pragma% not allowed");
7679 Set_Has_Storage_Size_Pragma (P, True);
7682 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7683 -- ??? exp_ch9 should use this!
7691 -- pragma Storage_Unit (NUMERIC_LITERAL);
7693 -- Only permitted argument is System'Storage_Unit value
7695 when Pragma_Storage_Unit =>
7696 Check_No_Identifiers;
7697 Check_Arg_Count (1);
7698 Check_Arg_Is_Integer_Literal (Arg1);
7700 if Intval (Expression (Arg1)) /=
7701 UI_From_Int (Ttypes.System_Storage_Unit)
7703 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
7705 ("the only allowed argument for pragma% is ^", Arg1);
7708 --------------------
7709 -- Stream_Convert --
7710 --------------------
7712 -- pragma Stream_Convert (
7713 -- [Entity =>] type_LOCAL_NAME,
7714 -- [Read =>] function_NAME,
7715 -- [Write =>] function NAME);
7717 when Pragma_Stream_Convert => Stream_Convert : declare
7719 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
7720 -- Check that the given argument is the name of a local
7721 -- function of one argument that is not overloaded earlier
7722 -- in the current local scope. A check is also made that the
7723 -- argument is a function with one parameter.
7725 --------------------------------------
7726 -- Check_OK_Stream_Convert_Function --
7727 --------------------------------------
7729 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
7733 Check_Arg_Is_Local_Name (Arg);
7734 Ent := Entity (Expression (Arg));
7736 if Has_Homonym (Ent) then
7738 ("argument for pragma% may not be overloaded", Arg);
7741 if Ekind (Ent) /= E_Function
7742 or else No (First_Formal (Ent))
7743 or else Present (Next_Formal (First_Formal (Ent)))
7746 ("argument for pragma% must be" &
7747 " function of one argument", Arg);
7749 end Check_OK_Stream_Convert_Function;
7751 -- Start of procecessing for Stream_Convert
7755 Check_Arg_Count (3);
7756 Check_Optional_Identifier (Arg1, Name_Entity);
7757 Check_Optional_Identifier (Arg2, Name_Read);
7758 Check_Optional_Identifier (Arg3, Name_Write);
7759 Check_Arg_Is_Local_Name (Arg1);
7760 Check_OK_Stream_Convert_Function (Arg2);
7761 Check_OK_Stream_Convert_Function (Arg3);
7764 Typ : constant Entity_Id :=
7765 Underlying_Type (Entity (Expression (Arg1)));
7766 Read : constant Entity_Id := Entity (Expression (Arg2));
7767 Write : constant Entity_Id := Entity (Expression (Arg3));
7770 if Etype (Typ) = Any_Type
7772 Etype (Read) = Any_Type
7774 Etype (Write) = Any_Type
7779 Check_First_Subtype (Arg1);
7781 if Rep_Item_Too_Early (Typ, N)
7783 Rep_Item_Too_Late (Typ, N)
7788 if Underlying_Type (Etype (Read)) /= Typ then
7790 ("incorrect return type for function&", Arg2);
7793 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
7795 ("incorrect parameter type for function&", Arg3);
7798 if Underlying_Type (Etype (First_Formal (Read))) /=
7799 Underlying_Type (Etype (Write))
7802 ("result type of & does not match Read parameter type",
7808 -------------------------
7809 -- Style_Checks (GNAT) --
7810 -------------------------
7812 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
7814 -- This is processed by the parser since some of the style
7815 -- checks take place during source scanning and parsing. This
7816 -- means that we don't need to issue error messages here.
7818 when Pragma_Style_Checks => Style_Checks : declare
7819 A : constant Node_Id := Expression (Arg1);
7825 Check_No_Identifiers;
7827 -- Two argument form
7829 if Arg_Count = 2 then
7830 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7837 E_Id := Expression (Arg2);
7840 if not Is_Entity_Name (E_Id) then
7842 ("second argument of pragma% must be entity name",
7852 Set_Suppress_Style_Checks (E,
7853 (Chars (Expression (Arg1)) = Name_Off));
7854 exit when No (Homonym (E));
7860 -- One argument form
7863 Check_Arg_Count (1);
7865 if Nkind (A) = N_String_Literal then
7869 Slen : Natural := Natural (String_Length (S));
7870 Options : String (1 .. Slen);
7876 C := Get_String_Char (S, Int (J));
7877 exit when not In_Character_Range (C);
7878 Options (J) := Get_Character (C);
7881 Set_Style_Check_Options (Options);
7889 elsif Nkind (A) = N_Identifier then
7891 if Chars (A) = Name_All_Checks then
7892 Set_Default_Style_Check_Options;
7894 elsif Chars (A) = Name_On then
7895 Style_Check := True;
7897 elsif Chars (A) = Name_Off then
7898 Style_Check := False;
7909 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
7911 when Pragma_Subtitle =>
7913 Check_Arg_Count (1);
7914 Check_Optional_Identifier (Arg1, Name_Subtitle);
7915 Check_Arg_Is_String_Literal (Arg1);
7921 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
7923 when Pragma_Suppress =>
7924 Process_Suppress_Unsuppress (True);
7930 -- pragma Suppress_All;
7932 -- The only check made here is that the pragma appears in the
7933 -- proper place, i.e. following a compilation unit. If indeed
7934 -- it appears in this context, then the parser has already
7935 -- inserted an equivalent pragma Suppress (All_Checks) to get
7936 -- the required effect.
7938 when Pragma_Suppress_All =>
7940 Check_Arg_Count (0);
7942 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
7943 or else not Is_List_Member (N)
7944 or else List_Containing (N) /= Pragmas_After (Parent (N))
7947 ("misplaced pragma%, must follow compilation unit");
7950 -------------------------
7951 -- Suppress_Debug_Info --
7952 -------------------------
7954 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
7956 when Pragma_Suppress_Debug_Info =>
7958 Check_Arg_Count (1);
7959 Check_Arg_Is_Local_Name (Arg1);
7960 Check_Optional_Identifier (Arg1, Name_Entity);
7961 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
7963 -----------------------------
7964 -- Suppress_Initialization --
7965 -----------------------------
7967 -- pragma Suppress_Initialization ([Entity =>] type_Name);
7969 when Pragma_Suppress_Initialization => Suppress_Init : declare
7975 Check_Arg_Count (1);
7976 Check_Optional_Identifier (Arg1, Name_Entity);
7977 Check_Arg_Is_Local_Name (Arg1);
7979 E_Id := Expression (Arg1);
7981 if Etype (E_Id) = Any_Type then
7988 if Is_Incomplete_Or_Private_Type (E) then
7989 if No (Full_View (Base_Type (E))) then
7991 ("argument of pragma% cannot be an incomplete type",
7994 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
7997 Set_Suppress_Init_Proc (Base_Type (E));
8002 ("pragma% requires argument that is a type name", Arg1);
8010 -- pragma System_Name (DIRECT_NAME);
8012 -- Syntax check: one argument, which must be the identifier GNAT
8013 -- or the identifier GCC, no other identifiers are acceptable.
8015 when Pragma_System_Name =>
8016 Check_No_Identifiers;
8017 Check_Arg_Count (1);
8018 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
8020 -----------------------------
8021 -- Task_Dispatching_Policy --
8022 -----------------------------
8024 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
8026 when Pragma_Task_Dispatching_Policy => declare
8030 Check_Ada_83_Warning;
8031 Check_Arg_Count (1);
8032 Check_No_Identifiers;
8033 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
8034 Check_Valid_Configuration_Pragma;
8035 Get_Name_String (Chars (Expression (Arg1)));
8036 DP := Fold_Upper (Name_Buffer (1));
8038 if Task_Dispatching_Policy /= ' '
8039 and then Task_Dispatching_Policy /= DP
8041 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
8043 ("task dispatching policy incompatible with policy#");
8045 Task_Dispatching_Policy := DP;
8046 Task_Dispatching_Policy_Sloc := Loc;
8054 -- pragma Task_Info (EXPRESSION);
8056 when Pragma_Task_Info => Task_Info : declare
8057 P : constant Node_Id := Parent (N);
8062 if Nkind (P) /= N_Task_Definition then
8063 Error_Pragma ("pragma% must appear in task definition");
8066 Check_No_Identifiers;
8067 Check_Arg_Count (1);
8069 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
8071 if Etype (Expression (Arg1)) = Any_Type then
8075 if Has_Task_Info_Pragma (P) then
8076 Error_Pragma ("duplicate pragma% not allowed");
8078 Set_Has_Task_Info_Pragma (P, True);
8086 -- pragma Task_Name (string_EXPRESSION);
8088 when Pragma_Task_Name => Task_Name : declare
8089 -- pragma Priority (EXPRESSION);
8091 P : constant Node_Id := Parent (N);
8095 Check_No_Identifiers;
8096 Check_Arg_Count (1);
8098 Arg := Expression (Arg1);
8099 Analyze_And_Resolve (Arg, Standard_String);
8101 if Nkind (P) /= N_Task_Definition then
8105 if Has_Task_Name_Pragma (P) then
8106 Error_Pragma ("duplicate pragma% not allowed");
8108 Set_Has_Task_Name_Pragma (P, True);
8109 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8117 -- pragma Task_Storage (
8118 -- [Task_Type =>] LOCAL_NAME,
8119 -- [Top_Guard =>] static_integer_EXPRESSION);
8121 when Pragma_Task_Storage => Task_Storage : declare
8122 Args : Args_List (1 .. 2);
8123 Names : Name_List (1 .. 2) := (
8127 Task_Type : Node_Id renames Args (1);
8128 Top_Guard : Node_Id renames Args (2);
8134 Gather_Associations (Names, Args);
8135 Check_Arg_Is_Local_Name (Task_Type);
8137 Ent := Entity (Task_Type);
8139 if not Is_Task_Type (Ent) then
8141 ("argument for pragma% must be task type", Task_Type);
8144 if No (Top_Guard) then
8146 ("pragma% takes two arguments", Task_Type);
8148 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
8151 Check_First_Subtype (Task_Type);
8153 if Rep_Item_Too_Late (Ent, N) then
8162 -- pragma Time_Slice (static_duration_EXPRESSION);
8164 when Pragma_Time_Slice => Time_Slice : declare
8170 Check_Arg_Count (1);
8171 Check_No_Identifiers;
8172 Check_In_Main_Program;
8173 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
8175 if not Error_Posted (Arg1) then
8177 while Present (Nod) loop
8178 if Nkind (Nod) = N_Pragma
8179 and then Chars (Nod) = Name_Time_Slice
8181 Error_Msg_Name_1 := Chars (N);
8182 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8189 -- Process only if in main unit
8191 if Get_Source_Unit (Loc) = Main_Unit then
8192 Opt.Time_Slice_Set := True;
8193 Val := Expr_Value_R (Expression (Arg1));
8195 if Val <= Ureal_0 then
8196 Opt.Time_Slice_Value := 0;
8198 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
8199 Opt.Time_Slice_Value := 1_000_000_000;
8202 Opt.Time_Slice_Value :=
8203 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
8212 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
8214 -- TITLING_OPTION ::=
8215 -- [Title =>] STRING_LITERAL
8216 -- | [Subtitle =>] STRING_LITERAL
8218 when Pragma_Title => Title : declare
8219 Args : Args_List (1 .. 2);
8220 Names : Name_List (1 .. 2) := (
8226 Gather_Associations (Names, Args);
8228 for J in 1 .. 2 loop
8229 if Present (Args (J)) then
8230 Check_Arg_Is_String_Literal (Args (J));
8235 ---------------------
8236 -- Unchecked_Union --
8237 ---------------------
8239 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
8241 when Pragma_Unchecked_Union => Unchecked_Union : declare
8242 Assoc : Node_Id := Arg1;
8243 Type_Id : Node_Id := Expression (Assoc);
8254 Check_No_Identifiers;
8255 Check_Arg_Count (1);
8256 Check_Arg_Is_Local_Name (Arg1);
8258 Find_Type (Type_Id);
8259 Typ := Entity (Type_Id);
8262 or else Rep_Item_Too_Early (Typ, N)
8266 Typ := Underlying_Type (Typ);
8269 if Rep_Item_Too_Late (Typ, N) then
8273 Check_First_Subtype (Arg1);
8275 -- Note remaining cases are references to a type in the current
8276 -- declarative part. If we find an error, we post the error on
8277 -- the relevant type declaration at an appropriate point.
8279 if not Is_Record_Type (Typ) then
8280 Error_Msg_N ("Unchecked_Union must be record type", Typ);
8283 elsif Is_Tagged_Type (Typ) then
8284 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
8287 elsif Is_Limited_Type (Typ) then
8289 ("Unchecked_Union must not be limited record type", Typ);
8293 if not Has_Discriminants (Typ) then
8295 ("Unchecked_Union must have one discriminant", Typ);
8299 Discr := First_Discriminant (Typ);
8301 if Present (Next_Discriminant (Discr)) then
8303 ("Unchecked_Union must have exactly one discriminant",
8304 Next_Discriminant (Discr));
8308 if No (Discriminant_Default_Value (Discr)) then
8310 ("Unchecked_Union discriminant must have default value",
8314 Tdef := Type_Definition (Declaration_Node (Typ));
8315 Clist := Component_List (Tdef);
8317 if No (Clist) or else No (Variant_Part (Clist)) then
8319 ("Unchecked_Union must have variant part",
8324 Vpart := Variant_Part (Clist);
8326 if Is_Non_Empty_List (Component_Items (Clist)) then
8328 ("components before variant not allowed " &
8329 "in Unchecked_Union",
8330 First (Component_Items (Clist)));
8333 Variant := First (Variants (Vpart));
8334 while Present (Variant) loop
8335 Clist := Component_List (Variant);
8337 if Present (Variant_Part (Clist)) then
8339 ("Unchecked_Union may not have nested variants",
8340 Variant_Part (Clist));
8343 if not Is_Non_Empty_List (Component_Items (Clist)) then
8345 ("Unchecked_Union may not have empty component list",
8350 Comp := First (Component_Items (Clist));
8352 if Nkind (Comp) = N_Component_Declaration then
8354 if Present (Expression (Comp)) then
8356 ("default initialization not allowed " &
8357 "in Unchecked_Union",
8362 Sindic : constant Node_Id :=
8363 Subtype_Indication (Comp);
8366 if Nkind (Sindic) = N_Subtype_Indication then
8367 Check_Static_Constraint (Constraint (Sindic));
8372 if Present (Next (Comp)) then
8374 ("Unchecked_Union variant can have only one component",
8382 Set_Is_Unchecked_Union (Typ, True);
8383 Set_Suppress_Discriminant_Checks (Typ, True);
8384 Set_Convention (Typ, Convention_C);
8386 Set_Has_Unchecked_Union (Base_Type (Typ), True);
8387 Set_Is_Unchecked_Union (Base_Type (Typ), True);
8389 end Unchecked_Union;
8391 ------------------------
8392 -- Unimplemented_Unit --
8393 ------------------------
8395 -- pragma Unimplemented_Unit;
8397 -- Note: this only gives an error if we are generating code,
8398 -- or if we are in a generic library unit (where the pragma
8399 -- appears in the body, not in the spec).
8401 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
8402 Cunitent : Entity_Id := Cunit_Entity (Get_Source_Unit (Loc));
8403 Ent_Kind : Entity_Kind := Ekind (Cunitent);
8407 Check_Arg_Count (0);
8409 if Operating_Mode = Generate_Code
8410 or else Ent_Kind = E_Generic_Function
8411 or else Ent_Kind = E_Generic_Procedure
8412 or else Ent_Kind = E_Generic_Package
8414 Get_Name_String (Chars (Cunitent));
8415 Set_Casing (Mixed_Case);
8416 Write_Str (Name_Buffer (1 .. Name_Len));
8417 Write_Str (" is not implemented");
8419 raise Unrecoverable_Error;
8421 end Unimplemented_Unit;
8423 --------------------
8424 -- Universal_Data --
8425 --------------------
8427 -- pragma Universal_Data;
8429 when Pragma_Universal_Data =>
8431 Check_Arg_Count (0);
8432 Check_Valid_Library_Unit_Pragma;
8434 if not AAMP_On_Target then
8435 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
8442 -- pragma Unreferenced (local_Name {, local_Name});
8444 when Pragma_Unreferenced => Unreferenced : declare
8450 Check_At_Least_N_Arguments (1);
8454 while Present (Arg_Node) loop
8455 Check_No_Identifier (Arg_Node);
8457 -- Note that the analyze call done by Check_Arg_Is_Local_Name
8458 -- will in fact generate a reference, so that the entity will
8459 -- have a reference, which will inhibit any warnings about it
8460 -- not being referenced, and also properly show up in the ali
8461 -- file as a reference. But this reference is recorded before
8462 -- the Has_Pragma_Unreferenced flag is set, so that no warning
8463 -- is generated for this reference.
8465 Check_Arg_Is_Local_Name (Arg_Node);
8466 Arg_Expr := Get_Pragma_Arg (Arg_Node);
8468 if Is_Entity_Name (Arg_Expr) then
8469 Set_Has_Pragma_Unreferenced (Entity (Arg_Expr));
8476 ------------------------------
8477 -- Unreserve_All_Interrupts --
8478 ------------------------------
8480 -- pragma Unreserve_All_Interrupts;
8482 when Pragma_Unreserve_All_Interrupts =>
8484 Check_Arg_Count (0);
8486 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
8487 Unreserve_All_Interrupts := True;
8494 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
8496 when Pragma_Unsuppress =>
8498 Process_Suppress_Unsuppress (False);
8504 -- pragma Use_VADS_Size;
8506 when Pragma_Use_VADS_Size =>
8508 Check_Arg_Count (0);
8509 Check_Valid_Configuration_Pragma;
8510 Use_VADS_Size := True;
8512 ---------------------
8513 -- Validity_Checks --
8514 ---------------------
8516 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
8518 when Pragma_Validity_Checks => Validity_Checks : declare
8519 A : constant Node_Id := Expression (Arg1);
8525 Check_Arg_Count (1);
8526 Check_No_Identifiers;
8528 if Nkind (A) = N_String_Literal then
8532 Slen : Natural := Natural (String_Length (S));
8533 Options : String (1 .. Slen);
8539 C := Get_String_Char (S, Int (J));
8540 exit when not In_Character_Range (C);
8541 Options (J) := Get_Character (C);
8544 Set_Validity_Check_Options (Options);
8552 elsif Nkind (A) = N_Identifier then
8554 if Chars (A) = Name_All_Checks then
8555 Set_Validity_Check_Options ("a");
8557 elsif Chars (A) = Name_On then
8558 Validity_Checks_On := True;
8560 elsif Chars (A) = Name_Off then
8561 Validity_Checks_On := False;
8565 end Validity_Checks;
8571 -- pragma Volatile (LOCAL_NAME);
8573 when Pragma_Volatile =>
8574 Process_Atomic_Shared_Volatile;
8576 -------------------------
8577 -- Volatile_Components --
8578 -------------------------
8580 -- pragma Volatile_Components (array_LOCAL_NAME);
8582 -- Volatile is handled by the same circuit as Atomic_Components
8588 -- pragma Warnings (On | Off, [LOCAL_NAME])
8590 when Pragma_Warnings =>
8592 Check_At_Least_N_Arguments (1);
8593 Check_At_Most_N_Arguments (2);
8594 Check_No_Identifiers;
8596 -- One argument case was processed by parser in Par.Prag
8598 if Arg_Count /= 1 then
8599 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8600 Check_Arg_Count (2);
8607 E_Id := Expression (Arg2);
8610 if not Is_Entity_Name (E_Id) then
8612 ("second argument of pragma% must be entity name",
8622 Set_Warnings_Off (E,
8623 (Chars (Expression (Arg1)) = Name_Off));
8625 if Is_Enumeration_Type (E) then
8627 Lit : Entity_Id := First_Literal (E);
8630 while Present (Lit) loop
8631 Set_Warnings_Off (Lit);
8637 exit when No (Homonym (E));
8648 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
8650 when Pragma_Weak_External => Weak_External : declare
8655 Check_Arg_Count (1);
8656 Check_Optional_Identifier (Arg1, Name_Entity);
8657 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8658 Ent := Entity (Expression (Arg1));
8660 if Rep_Item_Too_Early (Ent, N) then
8663 Ent := Underlying_Type (Ent);
8666 -- The only processing required is to link this item on to the
8667 -- list of rep items for the given entity. This is accomplished
8668 -- by the call to Rep_Item_Too_Late (when no error is detected
8669 -- and False is returned).
8671 if Rep_Item_Too_Late (Ent, N) then
8674 Set_Has_Gigi_Rep_Item (Ent);
8681 when Pragma_Exit => null;
8685 -------------------------
8686 -- Get_Base_Subprogram --
8687 -------------------------
8689 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
8695 -- Follow subprogram renaming chain
8697 while Is_Subprogram (Result)
8699 (Is_Generic_Instance (Result)
8700 or else Nkind (Parent (Declaration_Node (Result))) =
8701 N_Subprogram_Renaming_Declaration)
8702 and then Present (Alias (Result))
8704 Result := Alias (Result);
8708 end Get_Base_Subprogram;
8710 ---------------------------
8711 -- Is_Generic_Subprogram --
8712 ---------------------------
8714 function Is_Generic_Subprogram (Id : Entity_Id) return Boolean is
8716 return Ekind (Id) = E_Generic_Procedure
8717 or else Ekind (Id) = E_Generic_Function;
8718 end Is_Generic_Subprogram;
8720 ------------------------------
8721 -- Is_Pragma_String_Literal --
8722 ------------------------------
8724 -- This function returns true if the corresponding pragma argument is
8725 -- a static string expression. These are the only cases in which string
8726 -- literals can appear as pragma arguments. We also allow a string
8727 -- literal as the first argument to pragma Assert (although it will
8728 -- of course always generate a type error).
8730 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
8731 Pragn : constant Node_Id := Parent (Par);
8732 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
8733 Pname : constant Name_Id := Chars (Pragn);
8746 if Pname = Name_Assert then
8749 elsif Pname = Name_Export then
8752 elsif Pname = Name_Ident then
8755 elsif Pname = Name_Import then
8758 elsif Pname = Name_Interface_Name then
8761 elsif Pname = Name_Linker_Alias then
8764 elsif Pname = Name_Linker_Section then
8767 elsif Pname = Name_Machine_Attribute then
8770 elsif Pname = Name_Source_File_Name then
8773 elsif Pname = Name_Source_Reference then
8776 elsif Pname = Name_Title then
8779 elsif Pname = Name_Subtitle then
8785 end Is_Pragma_String_Literal;
8787 --------------------------------------
8788 -- Process_Compilation_Unit_Pragmas --
8789 --------------------------------------
8791 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
8793 -- A special check for pragma Suppress_All. This is a strange DEC
8794 -- pragma, strange because it comes at the end of the unit. If we
8795 -- have a pragma Suppress_All in the Pragmas_After of the current
8796 -- unit, then we insert a pragma Suppress (All_Checks) at the start
8797 -- of the context clause to ensure the correct processing.
8800 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
8804 if Present (PA) then
8806 while Present (P) loop
8807 if Chars (P) = Name_Suppress_All then
8808 Prepend_To (Context_Items (N),
8809 Make_Pragma (Sloc (P),
8810 Chars => Name_Suppress,
8811 Pragma_Argument_Associations => New_List (
8812 Make_Pragma_Argument_Association (Sloc (P),
8814 Make_Identifier (Sloc (P),
8815 Chars => Name_All_Checks)))));
8823 end Process_Compilation_Unit_Pragmas;
8825 --------------------------------
8826 -- Set_Encoded_Interface_Name --
8827 --------------------------------
8829 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
8830 Str : constant String_Id := Strval (S);
8831 Len : constant Int := String_Length (Str);
8836 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
8839 -- Stores encoded value of character code CC. The encoding we
8840 -- use an underscore followed by four lower case hex digits.
8844 Store_String_Char (Get_Char_Code ('_'));
8846 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
8848 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
8850 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
8852 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
8855 -- Start of processing for Set_Encoded_Interface_Name
8858 -- If first character is asterisk, this is a link name, and we
8859 -- leave it completely unmodified. We also ignore null strings
8860 -- (the latter case happens only in error cases) and no encoding
8861 -- should occur for Java interface names.
8864 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
8867 Set_Interface_Name (E, S);
8872 CC := Get_String_Char (Str, J);
8874 exit when not In_Character_Range (CC);
8876 C := Get_Character (CC);
8878 exit when C /= '_' and then C /= '$'
8879 and then C not in '0' .. '9'
8880 and then C not in 'a' .. 'z'
8881 and then C not in 'A' .. 'Z';
8884 Set_Interface_Name (E, S);
8892 -- Here we need to encode. The encoding we use as follows:
8893 -- three underscores + four hex digits (lower case)
8897 for J in 1 .. String_Length (Str) loop
8898 CC := Get_String_Char (Str, J);
8900 if not In_Character_Range (CC) then
8903 C := Get_Character (CC);
8905 if C = '_' or else C = '$'
8906 or else C in '0' .. '9'
8907 or else C in 'a' .. 'z'
8908 or else C in 'A' .. 'Z'
8910 Store_String_Char (CC);
8917 Set_Interface_Name (E,
8918 Make_String_Literal (Sloc (S),
8919 Strval => End_String));
8921 end Set_Encoded_Interface_Name;
8927 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
8932 if Nkind (N) = N_Identifier
8933 and then Nkind (With_Item) = N_Identifier
8935 Set_Entity (N, Entity (With_Item));
8937 elsif Nkind (N) = N_Selected_Component then
8938 Change_Selected_Component_To_Expanded_Name (N);
8939 Set_Entity (N, Entity (With_Item));
8940 Set_Entity (Selector_Name (N), Entity (N));
8943 Scop := Scope (Entity (N));
8945 while Nkind (Pref) = N_Selected_Component loop
8946 Change_Selected_Component_To_Expanded_Name (Pref);
8947 Set_Entity (Selector_Name (Pref), Scop);
8948 Set_Entity (Pref, Scop);
8949 Pref := Prefix (Pref);
8950 Scop := Scope (Scop);
8953 Set_Entity (Pref, Scop);