1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This unit contains the semantic processing for all pragmas, both language
28 -- and implementation defined. For most pragmas, the parser only does the
29 -- most basic job of checking the syntax, so Sem_Prag also contains the code
30 -- to complete the syntax checks. Certain pragmas are handled partially or
31 -- completely by the parser (see Par.Prag for further details).
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Expander; use Expander;
41 with Exp_Dist; use Exp_Dist;
42 with Fname; use Fname;
43 with Hostparm; use Hostparm;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet; use Namet;
48 with Nlists; use Nlists;
49 with Nmake; use Nmake;
51 with Output; use Output;
52 with Restrict; use Restrict;
53 with Rtsfind; use Rtsfind;
55 with Sem_Ch3; use Sem_Ch3;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch13; use Sem_Ch13;
58 with Sem_Disp; use Sem_Disp;
59 with Sem_Elim; use Sem_Elim;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Intr; use Sem_Intr;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Res; use Sem_Res;
64 with Sem_Type; use Sem_Type;
65 with Sem_Util; use Sem_Util;
66 with Sem_VFpt; use Sem_VFpt;
67 with Stand; use Stand;
68 with Sinfo; use Sinfo;
69 with Sinfo.CN; use Sinfo.CN;
70 with Sinput; use Sinput;
71 with Snames; use Snames;
72 with Stringt; use Stringt;
73 with Stylesw; use Stylesw;
74 with Targparm; use Targparm;
75 with Tbuild; use Tbuild;
77 with Uintp; use Uintp;
78 with Urealp; use Urealp;
79 with Validsw; use Validsw;
81 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
83 package body Sem_Prag is
85 ----------------------------------------------
86 -- Common Handling of Import-Export Pragmas --
87 ----------------------------------------------
89 -- In the following section, a number of Import_xxx and Export_xxx
90 -- pragmas are defined by GNAT. These are compatible with the DEC
91 -- pragmas of the same name, and all have the following common
92 -- form and processing:
95 -- [Internal =>] LOCAL_NAME,
96 -- [, [External =>] EXTERNAL_SYMBOL]
97 -- [, other optional parameters ]);
100 -- [Internal =>] LOCAL_NAME,
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
104 -- EXTERNAL_SYMBOL ::=
106 -- | static_string_EXPRESSION
108 -- The internal LOCAL_NAME designates the entity that is imported or
109 -- exported, and must refer to an entity in the current declarative
110 -- part (as required by the rules for LOCAL_NAME).
112 -- The external linker name is designated by the External parameter
113 -- if given, or the Internal parameter if not (if there is no External
114 -- parameter, the External parameter is a copy of the Internal name).
116 -- If the External parameter is given as a string, then this string
117 -- is treated as an external name (exactly as though it had been given
118 -- as an External_Name parameter for a normal Import pragma).
120 -- If the External parameter is given as an identifier (or there is no
121 -- External parameter, so that the Internal identifier is used), then
122 -- the external name is the characters of the identifier, translated
123 -- to all upper case letters for OpenVMS versions of GNAT, and to all
124 -- lower case letters for all other versions
126 -- Note: the external name specified or implied by any of these special
127 -- Import_xxx or Export_xxx pragmas override an external or link name
128 -- specified in a previous Import or Export pragma.
130 -- Note: these and all other DEC-compatible GNAT pragmas allow full
131 -- use of named notation, following the standard rules for subprogram
132 -- calls, i.e. parameters can be given in any order if named notation
133 -- is used, and positional and named notation can be mixed, subject to
134 -- the rule that all positional parameters must appear first.
136 -- Note: All these pragmas are implemented exactly following the DEC
137 -- design and implementation and are intended to be fully compatible
138 -- with the use of these pragmas in the DEC Ada compiler.
140 -------------------------------------
141 -- Local Subprograms and Variables --
142 -------------------------------------
144 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
145 -- This routine is used for possible casing adjustment of an explicit
146 -- external name supplied as a string literal (the node N), according
147 -- to the casing requirement of Opt.External_Name_Casing. If this is
148 -- set to As_Is, then the string literal is returned unchanged, but if
149 -- it is set to Uppercase or Lowercase, then a new string literal with
150 -- appropriate casing is constructed.
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 -------------------------------
163 -- Adjust_External_Name_Case --
164 -------------------------------
166 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
170 -- Adjust case of literal if required
172 if Opt.External_Name_Exp_Casing = As_Is then
176 -- Copy existing string
182 for J in 1 .. String_Length (Strval (N)) loop
183 CC := Get_String_Char (Strval (N), J);
185 if Opt.External_Name_Exp_Casing = Uppercase
186 and then CC >= Get_Char_Code ('a')
187 and then CC <= Get_Char_Code ('z')
189 Store_String_Char (CC - 32);
191 elsif Opt.External_Name_Exp_Casing = Lowercase
192 and then CC >= Get_Char_Code ('A')
193 and then CC <= Get_Char_Code ('Z')
195 Store_String_Char (CC + 32);
198 Store_String_Char (CC);
203 Make_String_Literal (Sloc (N),
204 Strval => End_String);
206 end Adjust_External_Name_Case;
212 procedure Analyze_Pragma (N : Node_Id) is
213 Loc : constant Source_Ptr := Sloc (N);
216 Pragma_Exit : exception;
217 -- This exception is used to exit pragma processing completely. It
218 -- is used when an error is detected, and in other situations where
219 -- it is known that no further processing is required.
222 -- Number of pragma argument associations
228 -- First four pragma arguments (pragma argument association nodes,
229 -- or Empty if the corresponding argument does not exist).
231 procedure Check_Ada_83_Warning;
232 -- Issues a warning message for the current pragma if operating in Ada
233 -- 83 mode (used for language pragmas that are not a standard part of
234 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
237 procedure Check_Arg_Count (Required : Nat);
238 -- Check argument count for pragma is equal to given parameter.
239 -- If not, then issue an error message and raise Pragma_Exit.
241 -- Note: all routines whose name is Check_Arg_Is_xxx take an
242 -- argument Arg which can either be a pragma argument association,
243 -- in which case the check is applied to the expression of the
244 -- association or an expression directly.
246 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
247 -- Check the specified argument Arg to make sure that it is an
248 -- identifier. If not give error and raise Pragma_Exit.
250 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
251 -- Check the specified argument Arg to make sure that it is an
252 -- integer literal. If not give error and raise Pragma_Exit.
254 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
255 -- Check the specified argument Arg to make sure that it has the
256 -- proper syntactic form for a local name and meets the semantic
257 -- requirements for a local name. The local name is analyzed as
258 -- part of the processing for this call. In addition, the local
259 -- name is required to represent an entity at the library level.
261 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
262 -- Check the specified argument Arg to make sure that it has the
263 -- proper syntactic form for a local name and meets the semantic
264 -- requirements for a local name. The local name is analyzed as
265 -- part of the processing for this call.
267 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
268 -- Check the specified argument Arg to make sure that it is a valid
269 -- locking policy name. If not give error and raise Pragma_Exit.
271 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
272 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
273 -- Check the specified argument Arg to make sure that it is an
274 -- identifier whose name matches either N1 or N2 (or N3 if present).
275 -- If not then give error and raise Pragma_Exit.
277 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
278 -- Check the specified argument Arg to make sure that it is a valid
279 -- queuing policy name. If not give error and raise Pragma_Exit.
281 procedure Check_Arg_Is_Static_Expression
284 -- Check the specified argument Arg to make sure that it is a static
285 -- expression of the given type (i.e. it will be analyzed and resolved
286 -- using this type, which can be any valid argument to Resolve, e.g.
287 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
289 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
290 -- Check the specified argument Arg to make sure that it is a
291 -- string literal. If not give error and raise Pragma_Exit
293 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
294 -- Check the specified argument Arg to make sure that it is a valid
295 -- valid task dispatching policy name. If not give error and raise
298 procedure Check_At_Least_N_Arguments (N : Nat);
299 -- Check there are at least N arguments present
301 procedure Check_At_Most_N_Arguments (N : Nat);
302 -- Check there are no more than N arguments present
304 procedure Check_First_Subtype (Arg : Node_Id);
305 -- Checks that Arg, whose expression is an entity name referencing
306 -- a subtype, does not reference a type that is not a first subtype.
308 procedure Check_In_Main_Program;
309 -- Common checks for pragmas that appear within a main program
310 -- (Priority, Main_Storage, Time_Slice).
312 procedure Check_Interrupt_Or_Attach_Handler;
313 -- Common processing for first argument of pragma Interrupt_Handler
314 -- or pragma Attach_Handler.
316 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
317 -- Check that pragma appears in a declarative part, or in a package
318 -- specification, i.e. that it does not occur in a statement sequence
321 procedure Check_No_Identifier (Arg : Node_Id);
322 -- Checks that the given argument does not have an identifier. If
323 -- an identifier is present, then an error message is issued, and
324 -- Pragma_Exit is raised.
326 procedure Check_No_Identifiers;
327 -- Checks that none of the arguments to the pragma has an identifier.
328 -- If any argument has an identifier, then an error message is issued,
329 -- and Pragma_Exit is raised.
331 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
332 -- Checks if the given argument has an identifier, and if so, requires
333 -- it to match the given identifier name. If there is a non-matching
334 -- identifier, then an error message is given and Error_Pragmas raised.
336 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
337 -- Checks if the given argument has an identifier, and if so, requires
338 -- it to match the given identifier name. If there is a non-matching
339 -- identifier, then an error message is given and Error_Pragmas raised.
340 -- In this version of the procedure, the identifier name is given as
341 -- a string with lower case letters.
343 procedure Check_Static_Constraint (Constr : Node_Id);
344 -- Constr is a constraint from an N_Subtype_Indication node from a
345 -- component constraint in an Unchecked_Union type. This routine checks
346 -- that the constraint is static as required by the restrictions for
349 procedure Check_Valid_Configuration_Pragma;
350 -- Legality checks for placement of a configuration pragma
352 procedure Check_Valid_Library_Unit_Pragma;
353 -- Legality checks for library unit pragmas. A special case arises for
354 -- pragmas in generic instances that come from copies of the original
355 -- library unit pragmas in the generic templates. In the case of other
356 -- than library level instantiations these can appear in contexts which
357 -- would normally be invalid (they only apply to the original template
358 -- and to library level instantiations), and they are simply ignored,
359 -- which is implemented by rewriting them as null statements.
361 procedure Error_Pragma (Msg : String);
362 pragma No_Return (Error_Pragma);
363 -- Outputs error message for current pragma. The message contains an %
364 -- that will be replaced with the pragma name, and the flag is placed
365 -- on the pragma itself. Pragma_Exit is then raised.
367 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
368 pragma No_Return (Error_Pragma_Arg);
369 -- Outputs error message for current pragma. The message may contain
370 -- a % that will be replaced with the pragma name. The parameter Arg
371 -- may either be a pragma argument association, in which case the flag
372 -- is placed on the expression of this association, or an expression,
373 -- in which case the flag is placed directly on the expression. The
374 -- message is placed using Error_Msg_N, so the message may also contain
375 -- an & insertion character which will reference the given Arg value.
376 -- After placing the message, Pragma_Exit is raised.
378 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
379 pragma No_Return (Error_Pragma_Arg);
380 -- Similar to above form of Error_Pragma_Arg except that two messages
381 -- are provided, the second is a continuation comment starting with \.
383 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
384 pragma No_Return (Error_Pragma_Arg_Ident);
385 -- Outputs error message for current pragma. The message may contain
386 -- a % that will be replaced with the pragma name. The parameter Arg
387 -- must be a pragma argument association with a non-empty identifier
388 -- (i.e. its Chars field must be set), and the error message is placed
389 -- on the identifier. The message is placed using Error_Msg_N so
390 -- the message may also contain an & insertion character which will
391 -- reference the identifier. After placing the message, Pragma_Exit
394 function Find_Lib_Unit_Name return Entity_Id;
395 -- Used for a library unit pragma to find the entity to which the
396 -- library unit pragma applies, returns the entity found.
398 procedure Find_Program_Unit_Name (Id : Node_Id);
399 -- If the pragma is a compilation unit pragma, the id must denote the
400 -- compilation unit in the same compilation, and the pragma must appear
401 -- in the list of preceding or trailing pragmas. If it is a program
402 -- unit pragma that is not a compilation unit pragma, then the
403 -- identifier must be visible.
405 type Name_List is array (Natural range <>) of Name_Id;
406 type Args_List is array (Natural range <>) of Node_Id;
407 procedure Gather_Associations
409 Args : out Args_List);
410 -- This procedure is used to gather the arguments for a pragma that
411 -- permits arbitrary ordering of parameters using the normal rules
412 -- for named and positional parameters. The Names argument is a list
413 -- of Name_Id values that corresponds to the allowed pragma argument
414 -- association identifiers in order. The result returned in Args is
415 -- a list of corresponding expressions that are the pragma arguments.
416 -- Note that this is a list of expressions, not of pragma argument
417 -- associations (Gather_Associations has completely checked all the
418 -- optional identifiers when it returns). An entry in Args is Empty
419 -- on return if the corresponding argument is not present.
421 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
422 -- All the routines that check pragma arguments take either a pragma
423 -- argument association (in which case the expression of the argument
424 -- association is checked), or the expression directly. The function
425 -- Get_Pragma_Arg is a utility used to deal with these two cases. If
426 -- Arg is a pragma argument association node, then its expression is
427 -- returned, otherwise Arg is returned unchanged.
429 procedure GNAT_Pragma;
430 -- Called for all GNAT defined pragmas to note the use of the feature,
431 -- and also check the relevant restriction (No_Implementation_Pragmas).
433 function Is_Before_First_Decl
434 (Pragma_Node : Node_Id;
437 -- Return True if Pragma_Node is before the first declarative item in
438 -- Decls where Decls is the list of declarative items.
440 function Is_Configuration_Pragma return Boolean;
441 -- Deterermines if the placement of the current pragma is appropriate
442 -- for a configuration pragma (precedes the current compilation unit)
444 procedure Pragma_Misplaced;
445 -- Issue fatal error message for misplaced pragma
447 procedure Process_Atomic_Shared_Volatile;
448 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
449 -- Shared is an obsolete Ada 83 pragma, treated as being identical
450 -- in effect to pragma Atomic.
452 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
453 -- Common procesing for Convention, Interface, Import and Export.
454 -- Checks first two arguments of pragma, and sets the appropriate
455 -- convention value in the specified entity or entities. On return
456 -- C is the convention, E is the referenced entity.
458 procedure Process_Extended_Import_Export_Exception_Pragma
459 (Arg_Internal : Node_Id;
460 Arg_External : Node_Id;
463 -- Common processing for the pragmas Import/Export_Exception.
464 -- The three arguments correspond to the three named parameters of
465 -- the pragma. An argument is empty if the corresponding parameter
466 -- is not present in the pragma.
468 procedure Process_Extended_Import_Export_Object_Pragma
469 (Arg_Internal : Node_Id;
470 Arg_External : Node_Id;
472 -- Common processing for the pragmass Import/Export_Object.
473 -- The three arguments correspond to the three named parameters
474 -- of the pragmas. An argument is empty if the corresponding
475 -- parameter is not present in the pragma.
477 procedure Process_Extended_Import_Export_Internal_Arg
478 (Arg_Internal : Node_Id := Empty);
479 -- Common processing for all extended Import and Export pragmas. The
480 -- argument is the pragma parameter for the Internal argument. If
481 -- Arg_Internal is empty or inappropriate, an error message is posted.
482 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
483 -- set to identify the referenced entity.
485 procedure Process_Extended_Import_Export_Subprogram_Pragma
486 (Arg_Internal : Node_Id;
487 Arg_External : Node_Id;
488 Arg_Parameter_Types : Node_Id;
489 Arg_Result_Type : Node_Id := Empty;
490 Arg_Mechanism : Node_Id;
491 Arg_Result_Mechanism : Node_Id := Empty;
492 Arg_First_Optional_Parameter : Node_Id := Empty);
493 -- Common processing for all extended Import and Export pragmas
494 -- applying to subprograms. The caller omits any arguments that do
495 -- bnot apply to the pragma in question (for example, Arg_Result_Type
496 -- can be non-Empty only in the Import_Function and Export_Function
497 -- cases). The argument names correspond to the allowed pragma
498 -- association identifiers.
500 procedure Process_Generic_List;
501 -- Common processing for Share_Generic and Inline_Generic
503 procedure Process_Import_Or_Interface;
504 -- Common processing for Import of Interface
506 procedure Process_Inline (Active : Boolean);
507 -- Common processing for Inline and Inline_Always. The parameter
508 -- indicates if the inline pragma is active, i.e. if it should
509 -- actually cause inlining to occur.
511 procedure Process_Interface_Name
512 (Subprogram_Def : Entity_Id;
515 -- Given the last two arguments of pragma Import, pragma Export, or
516 -- pragma Interface_Name, performs validity checks and sets the
517 -- Interface_Name field of the given subprogram entity to the
518 -- appropriate external or link name, depending on the arguments
519 -- given. Ext_Arg is always present, but Link_Arg may be missing.
520 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
521 -- missing, and appropriate named notation is used for Ext_Arg.
522 -- If neither Ext_Arg nor Link_Arg is present, the interface name
523 -- is set to the default from the subprogram name.
525 procedure Process_Interrupt_Or_Attach_Handler;
526 -- Attach the pragmas to the rep item chain.
528 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
529 -- Common processing for Suppress and Unsuppress. The boolean parameter
530 -- Suppress_Case is True for the Suppress case, and False for the
533 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
534 -- This procedure sets the Is_Exported flag for the given entity,
535 -- checking that the entity was not previously imported. Arg is
536 -- the argument that specified the entity. A check is also made
537 -- for exporting inappropriate entities.
539 procedure Set_Extended_Import_Export_External_Name
540 (Internal_Ent : Entity_Id;
541 Arg_External : Node_Id);
542 -- Common processing for all extended import export pragmas. The first
543 -- argument, Internal_Ent, is the internal entity, which has already
544 -- been checked for validity by the caller. Arg_External is from the
545 -- Import or Export pragma, and may be null if no External parameter
546 -- was present. If Arg_External is present and is a non-null string
547 -- (a null string is treated as the default), then the Interface_Name
548 -- field of Internal_Ent is set appropriately.
550 procedure Set_Imported (E : Entity_Id);
551 -- This procedure sets the Is_Imported flag for the given entity,
552 -- checking that it is not previously exported or imported.
554 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
555 -- Mech is a parameter passing mechanism (see Import_Function syntax
556 -- for MECHANISM_NAME). This routine checks that the mechanism argument
557 -- has the right form, and if not issues an error message. If the
558 -- argument has the right form then the Mechanism field of Ent is
559 -- set appropriately.
561 --------------------------
562 -- Check_Ada_83_Warning --
563 --------------------------
565 procedure Check_Ada_83_Warning is
567 if Ada_83 and then Comes_From_Source (N) then
568 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
570 end Check_Ada_83_Warning;
572 ---------------------
573 -- Check_Arg_Count --
574 ---------------------
576 procedure Check_Arg_Count (Required : Nat) is
578 if Arg_Count /= Required then
579 Error_Pragma ("wrong number of arguments for pragma%");
583 -----------------------------
584 -- Check_Arg_Is_Identifier --
585 -----------------------------
587 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
588 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
591 if Nkind (Argx) /= N_Identifier then
593 ("argument for pragma% must be identifier", Argx);
595 end Check_Arg_Is_Identifier;
597 ----------------------------------
598 -- Check_Arg_Is_Integer_Literal --
599 ----------------------------------
601 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
602 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
605 if Nkind (Argx) /= N_Integer_Literal then
607 ("argument for pragma% must be integer literal", Argx);
609 end Check_Arg_Is_Integer_Literal;
611 -------------------------------------------
612 -- Check_Arg_Is_Library_Level_Local_Name --
613 -------------------------------------------
617 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
618 -- | library_unit_NAME
620 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
622 Check_Arg_Is_Local_Name (Arg);
624 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
625 and then Comes_From_Source (N)
628 ("argument for pragma% must be library level entity", Arg);
630 end Check_Arg_Is_Library_Level_Local_Name;
632 -----------------------------
633 -- Check_Arg_Is_Local_Name --
634 -----------------------------
638 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
639 -- | library_unit_NAME
641 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
642 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
647 if Nkind (Argx) not in N_Direct_Name
648 and then (Nkind (Argx) /= N_Attribute_Reference
649 or else Present (Expressions (Argx))
650 or else Nkind (Prefix (Argx)) /= N_Identifier)
651 and then (not Is_Entity_Name (Argx)
652 or else not Is_Compilation_Unit (Entity (Argx)))
654 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
657 if Is_Entity_Name (Argx)
658 and then Scope (Entity (Argx)) /= Current_Scope
661 ("pragma% argument must be in same declarative part", Arg);
663 end Check_Arg_Is_Local_Name;
665 ---------------------------------
666 -- Check_Arg_Is_Locking_Policy --
667 ---------------------------------
669 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
670 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
673 Check_Arg_Is_Identifier (Argx);
675 if not Is_Locking_Policy_Name (Chars (Argx)) then
677 ("& is not a valid locking policy name", Argx);
679 end Check_Arg_Is_Locking_Policy;
681 -------------------------
682 -- Check_Arg_Is_One_Of --
683 -------------------------
685 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
686 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
689 Check_Arg_Is_Identifier (Argx);
691 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
692 Error_Msg_Name_2 := N1;
693 Error_Msg_Name_3 := N2;
694 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
696 end Check_Arg_Is_One_Of;
698 procedure Check_Arg_Is_One_Of
700 N1, N2, N3 : Name_Id)
702 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
705 Check_Arg_Is_Identifier (Argx);
707 if Chars (Argx) /= N1
708 and then Chars (Argx) /= N2
709 and then Chars (Argx) /= N3
711 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
713 end Check_Arg_Is_One_Of;
715 ---------------------------------
716 -- Check_Arg_Is_Queuing_Policy --
717 ---------------------------------
719 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
720 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
723 Check_Arg_Is_Identifier (Argx);
725 if not Is_Queuing_Policy_Name (Chars (Argx)) then
727 ("& is not a valid queuing policy name", Argx);
729 end Check_Arg_Is_Queuing_Policy;
731 ------------------------------------
732 -- Check_Arg_Is_Static_Expression --
733 ------------------------------------
735 procedure Check_Arg_Is_Static_Expression
739 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
742 Analyze_And_Resolve (Argx, Typ);
744 if Is_OK_Static_Expression (Argx) then
747 elsif Etype (Argx) = Any_Type then
750 -- An interesting special case, if we have a string literal and
751 -- we are in Ada 83 mode, then we allow it even though it will
752 -- not be flagged as static. This allows the use of Ada 95
753 -- pragmas like Import in Ada 83 mode. They will of course be
754 -- flagged with warnings as usual, but will not cause errors.
756 elsif Ada_83 and then Nkind (Argx) = N_String_Literal then
759 -- Static expression that raises Constraint_Error. This has
760 -- already been flagged, so just exit from pragma processing.
762 elsif Is_Static_Expression (Argx) then
765 -- Finally, we have a real error
768 Error_Msg_Name_1 := Chars (N);
770 ("argument for pragma% must be a static expression!", Argx);
773 end Check_Arg_Is_Static_Expression;
775 ---------------------------------
776 -- Check_Arg_Is_String_Literal --
777 ---------------------------------
779 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
780 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
783 if Nkind (Argx) /= N_String_Literal then
785 ("argument for pragma% must be string literal", Argx);
788 end Check_Arg_Is_String_Literal;
790 ------------------------------------------
791 -- Check_Arg_Is_Task_Dispatching_Policy --
792 ------------------------------------------
794 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
795 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
798 Check_Arg_Is_Identifier (Argx);
800 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
802 ("& is not a valid task dispatching policy name", Argx);
804 end Check_Arg_Is_Task_Dispatching_Policy;
806 --------------------------------
807 -- Check_At_Least_N_Arguments --
808 --------------------------------
810 procedure Check_At_Least_N_Arguments (N : Nat) is
812 if Arg_Count < N then
813 Error_Pragma ("too few arguments for pragma%");
815 end Check_At_Least_N_Arguments;
817 -------------------------------
818 -- Check_At_Most_N_Arguments --
819 -------------------------------
821 procedure Check_At_Most_N_Arguments (N : Nat) is
825 if Arg_Count > N then
830 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
833 end Check_At_Most_N_Arguments;
835 -------------------------
836 -- Check_First_Subtype --
837 -------------------------
839 procedure Check_First_Subtype (Arg : Node_Id) is
840 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
843 if not Is_First_Subtype (Entity (Argx)) then
845 ("pragma% cannot apply to subtype", Argx);
847 end Check_First_Subtype;
849 ---------------------------
850 -- Check_In_Main_Program --
851 ---------------------------
853 procedure Check_In_Main_Program is
854 P : constant Node_Id := Parent (N);
857 -- Must be at in subprogram body
859 if Nkind (P) /= N_Subprogram_Body then
860 Error_Pragma ("% pragma allowed only in subprogram");
862 -- Otherwise warn if obviously not main program
864 elsif Present (Parameter_Specifications (Specification (P)))
865 or else not Is_Compilation_Unit (Defining_Entity (P))
867 Error_Msg_Name_1 := Chars (N);
869 ("?pragma% is only effective in main program", N);
871 end Check_In_Main_Program;
873 ---------------------------------------
874 -- Check_Interrupt_Or_Attach_Handler --
875 ---------------------------------------
877 procedure Check_Interrupt_Or_Attach_Handler is
878 Arg1_X : constant Node_Id := Expression (Arg1);
883 if not Is_Entity_Name (Arg1_X) then
885 ("argument of pragma% must be entity name", Arg1);
887 elsif Prag_Id = Pragma_Interrupt_Handler then
888 Check_Restriction (No_Dynamic_Interrupts, N);
892 Handler_Proc : Entity_Id := Empty;
893 Proc_Scope : Entity_Id;
894 Found : Boolean := False;
897 if not Is_Overloaded (Arg1_X) then
898 Handler_Proc := Entity (Arg1_X);
903 Index : Interp_Index;
906 Get_First_Interp (Arg1_X, Index, It);
907 while Present (It.Nam) loop
908 Handler_Proc := It.Nam;
910 if Ekind (Handler_Proc) = E_Procedure
911 and then No (First_Formal (Handler_Proc))
915 Set_Entity (Arg1_X, Handler_Proc);
916 Set_Is_Overloaded (Arg1_X, False);
919 ("ambiguous handler name for pragma% ", Arg1);
923 Get_Next_Interp (Index, It);
928 ("argument of pragma% must be parameterless procedure",
931 Handler_Proc := Entity (Arg1_X);
936 Proc_Scope := Scope (Handler_Proc);
938 -- On AAMP only, a pragma Interrupt_Handler is supported for
939 -- nonprotected parameterless procedures.
942 and then Prag_Id = Pragma_Interrupt_Handler
944 if Ekind (Handler_Proc) /= E_Procedure then
946 ("argument of pragma% must be a procedure", Arg1);
949 elsif Ekind (Handler_Proc) /= E_Procedure
950 or else Ekind (Proc_Scope) /= E_Protected_Type
953 ("argument of pragma% must be protected procedure", Arg1);
956 if (not AAMP_On_Target or else Prag_Id = Pragma_Attach_Handler)
957 and then Ekind (Proc_Scope) = E_Protected_Type
960 Protected_Definition (Parent (Proc_Scope))
962 Error_Pragma ("pragma% must be in protected definition");
966 if not Is_Library_Level_Entity (Proc_Scope)
967 or else (AAMP_On_Target
968 and then not Is_Library_Level_Entity (Handler_Proc))
971 ("pragma% requires library-level entity", Arg1);
974 if Present (First_Formal (Handler_Proc)) then
976 ("argument of pragma% must be parameterless procedure",
980 end Check_Interrupt_Or_Attach_Handler;
982 -------------------------------------------
983 -- Check_Is_In_Decl_Part_Or_Package_Spec --
984 -------------------------------------------
986 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
995 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
998 elsif Nkind (P) = N_Package_Specification then
1001 elsif Nkind (P) = N_Block_Statement then
1004 -- Note: the following tests seem a little peculiar, because
1005 -- they test for bodies, but if we were in the statement part
1006 -- of the body, we would already have hit the handled statement
1007 -- sequence, so the only way we get here is by being in the
1008 -- declarative part of the body.
1010 elsif Nkind (P) = N_Subprogram_Body
1011 or else Nkind (P) = N_Package_Body
1012 or else Nkind (P) = N_Task_Body
1013 or else Nkind (P) = N_Entry_Body
1021 Error_Pragma ("pragma% is not in declarative part or package spec");
1022 end Check_Is_In_Decl_Part_Or_Package_Spec;
1024 -------------------------
1025 -- Check_No_Identifier --
1026 -------------------------
1028 procedure Check_No_Identifier (Arg : Node_Id) is
1030 if Chars (Arg) /= No_Name then
1031 Error_Pragma_Arg_Ident
1032 ("pragma% does not permit identifier& here", Arg);
1034 end Check_No_Identifier;
1036 --------------------------
1037 -- Check_No_Identifiers --
1038 --------------------------
1040 procedure Check_No_Identifiers is
1044 if Arg_Count > 0 then
1047 while Present (Arg_Node) loop
1048 Check_No_Identifier (Arg_Node);
1052 end Check_No_Identifiers;
1054 -------------------------------
1055 -- Check_Optional_Identifier --
1056 -------------------------------
1058 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1060 if Present (Arg) and then Chars (Arg) /= No_Name then
1061 if Chars (Arg) /= Id then
1062 Error_Msg_Name_1 := Chars (N);
1063 Error_Msg_Name_2 := Id;
1064 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1068 end Check_Optional_Identifier;
1070 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1072 Name_Buffer (1 .. Id'Length) := Id;
1073 Name_Len := Id'Length;
1074 Check_Optional_Identifier (Arg, Name_Find);
1075 end Check_Optional_Identifier;
1077 -----------------------------
1078 -- Check_Static_Constraint --
1079 -----------------------------
1081 -- Note: for convenience in writing this procedure, in addition to
1082 -- the officially (i.e. by spec) allowed argument which is always
1083 -- a constraint, it also allows ranges and discriminant associations.
1084 -- Above is not clear ???
1086 procedure Check_Static_Constraint (Constr : Node_Id) is
1088 --------------------
1089 -- Require_Static --
1090 --------------------
1092 procedure Require_Static (E : Node_Id);
1093 -- Require given expression to be static expression
1095 procedure Require_Static (E : Node_Id) is
1097 if not Is_OK_Static_Expression (E) then
1098 Flag_Non_Static_Expr
1099 ("non-static constraint not allowed in Unchecked_Union!", E);
1104 -- Start of processing for Check_Static_Constraint
1107 case Nkind (Constr) is
1108 when N_Discriminant_Association =>
1109 Require_Static (Expression (Constr));
1112 Require_Static (Low_Bound (Constr));
1113 Require_Static (High_Bound (Constr));
1115 when N_Attribute_Reference =>
1116 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1117 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1119 when N_Range_Constraint =>
1120 Check_Static_Constraint (Range_Expression (Constr));
1122 when N_Index_Or_Discriminant_Constraint =>
1124 IDC : Entity_Id := First (Constraints (Constr));
1127 while Present (IDC) loop
1128 Check_Static_Constraint (IDC);
1136 end Check_Static_Constraint;
1138 --------------------------------------
1139 -- Check_Valid_Configuration_Pragma --
1140 --------------------------------------
1142 -- A configuration pragma must appear in the context clause of
1143 -- a compilation unit, at the start of the list (i.e. only other
1144 -- pragmas may precede it).
1146 procedure Check_Valid_Configuration_Pragma is
1148 if not Is_Configuration_Pragma then
1149 Error_Pragma ("incorrect placement for configuration pragma%");
1151 end Check_Valid_Configuration_Pragma;
1153 -------------------------------------
1154 -- Check_Valid_Library_Unit_Pragma --
1155 -------------------------------------
1157 procedure Check_Valid_Library_Unit_Pragma is
1159 Parent_Node : Node_Id;
1160 Unit_Name : Entity_Id;
1161 Unit_Kind : Node_Kind;
1162 Unit_Node : Node_Id;
1163 Sindex : Source_File_Index;
1166 if not Is_List_Member (N) then
1170 Plist := List_Containing (N);
1171 Parent_Node := Parent (Plist);
1173 if Parent_Node = Empty then
1176 -- Case of pragma appearing after a compilation unit. In this
1177 -- case it must have an argument with the corresponding name
1178 -- and must be part of the following pragmas of its parent.
1180 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1181 if Plist /= Pragmas_After (Parent_Node) then
1184 elsif Arg_Count = 0 then
1186 ("argument required if outside compilation unit");
1189 Check_No_Identifiers;
1190 Check_Arg_Count (1);
1191 Unit_Node := Unit (Parent (Parent_Node));
1192 Unit_Kind := Nkind (Unit_Node);
1194 Analyze (Expression (Arg1));
1196 if Unit_Kind = N_Generic_Subprogram_Declaration
1197 or else Unit_Kind = N_Subprogram_Declaration
1199 Unit_Name := Defining_Entity (Unit_Node);
1201 elsif Unit_Kind = N_Function_Instantiation
1202 or else Unit_Kind = N_Package_Instantiation
1203 or else Unit_Kind = N_Procedure_Instantiation
1205 Unit_Name := Defining_Entity (Unit_Node);
1208 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1211 if Chars (Unit_Name) /=
1212 Chars (Entity (Expression (Arg1)))
1215 ("pragma% argument is not current unit name", Arg1);
1218 if Ekind (Unit_Name) = E_Package
1219 and then Present (Renamed_Entity (Unit_Name))
1221 Error_Pragma ("pragma% not allowed for renamed package");
1225 -- Pragma appears other than after a compilation unit
1228 -- Here we check for the generic instantiation case and also
1229 -- for the case of processing a generic formal package. We
1230 -- detect these cases by noting that the Sloc on the node
1231 -- does not belong to the current compilation unit.
1233 Sindex := Source_Index (Current_Sem_Unit);
1235 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1236 Rewrite (N, Make_Null_Statement (Loc));
1239 -- If before first declaration, the pragma applies to the
1240 -- enclosing unit, and the name if present must be this name.
1242 elsif Is_Before_First_Decl (N, Plist) then
1243 Unit_Node := Unit_Declaration_Node (Current_Scope);
1244 Unit_Kind := Nkind (Unit_Node);
1246 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1249 elsif Unit_Kind = N_Subprogram_Body
1250 and then not Acts_As_Spec (Unit_Node)
1254 elsif Nkind (Parent_Node) = N_Package_Body then
1257 elsif Nkind (Parent_Node) = N_Package_Specification
1258 and then Plist = Private_Declarations (Parent_Node)
1262 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1263 or else Nkind (Parent_Node)
1264 = N_Generic_Subprogram_Declaration)
1265 and then Plist = Generic_Formal_Declarations (Parent_Node)
1269 elsif Arg_Count > 0 then
1270 Analyze (Expression (Arg1));
1272 if Entity (Expression (Arg1)) /= Current_Scope then
1274 ("name in pragma% must be enclosing unit", Arg1);
1277 -- It is legal to have no argument in this context
1283 -- Error if not before first declaration. This is because a
1284 -- library unit pragma argument must be the name of a library
1285 -- unit (RM 10.1.5(7)), but the only names permitted in this
1286 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1287 -- generic subprogram declarations or generic instantiations.
1291 ("pragma% misplaced, must be before first declaration");
1295 end Check_Valid_Library_Unit_Pragma;
1301 procedure Error_Pragma (Msg : String) is
1303 Error_Msg_Name_1 := Chars (N);
1304 Error_Msg_N (Msg, N);
1308 ----------------------
1309 -- Error_Pragma_Arg --
1310 ----------------------
1312 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1314 Error_Msg_Name_1 := Chars (N);
1315 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1317 end Error_Pragma_Arg;
1319 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1321 Error_Msg_Name_1 := Chars (N);
1322 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1323 Error_Pragma_Arg (Msg2, Arg);
1324 end Error_Pragma_Arg;
1326 ----------------------------
1327 -- Error_Pragma_Arg_Ident --
1328 ----------------------------
1330 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1332 Error_Msg_Name_1 := Chars (N);
1333 Error_Msg_N (Msg, Arg);
1335 end Error_Pragma_Arg_Ident;
1337 ------------------------
1338 -- Find_Lib_Unit_Name --
1339 ------------------------
1341 function Find_Lib_Unit_Name return Entity_Id is
1343 -- Return inner compilation unit entity, for case of nested
1344 -- categorization pragmas. This happens in generic unit.
1346 if Nkind (Parent (N)) = N_Package_Specification
1347 and then Defining_Entity (Parent (N)) /= Current_Scope
1349 return Defining_Entity (Parent (N));
1351 return Current_Scope;
1353 end Find_Lib_Unit_Name;
1355 ----------------------------
1356 -- Find_Program_Unit_Name --
1357 ----------------------------
1359 procedure Find_Program_Unit_Name (Id : Node_Id) is
1360 Unit_Name : Entity_Id;
1361 Unit_Kind : Node_Kind;
1362 P : constant Node_Id := Parent (N);
1365 if Nkind (P) = N_Compilation_Unit then
1366 Unit_Kind := Nkind (Unit (P));
1368 if Unit_Kind = N_Subprogram_Declaration
1369 or else Unit_Kind = N_Package_Declaration
1370 or else Unit_Kind in N_Generic_Declaration
1372 Unit_Name := Defining_Entity (Unit (P));
1374 if Chars (Id) = Chars (Unit_Name) then
1375 Set_Entity (Id, Unit_Name);
1376 Set_Etype (Id, Etype (Unit_Name));
1378 Set_Etype (Id, Any_Type);
1380 ("cannot find program unit referenced by pragma%");
1384 Set_Etype (Id, Any_Type);
1385 Error_Pragma ("pragma% inapplicable to this unit");
1392 end Find_Program_Unit_Name;
1394 -------------------------
1395 -- Gather_Associations --
1396 -------------------------
1398 procedure Gather_Associations
1400 Args : out Args_List)
1405 -- Initialize all parameters to Empty
1407 for J in Args'Range loop
1411 -- That's all we have to do if there are no argument associations
1413 if No (Pragma_Argument_Associations (N)) then
1417 -- Otherwise first deal with any positional parameters present
1419 Arg := First (Pragma_Argument_Associations (N));
1421 for Index in Args'Range loop
1422 exit when No (Arg) or else Chars (Arg) /= No_Name;
1423 Args (Index) := Expression (Arg);
1427 -- Positional parameters all processed, if any left, then we
1428 -- have too many positional parameters.
1430 if Present (Arg) and then Chars (Arg) = No_Name then
1432 ("too many positional associations for pragma%", Arg);
1435 -- Process named parameters if any are present
1437 while Present (Arg) loop
1438 if Chars (Arg) = No_Name then
1440 ("positional association cannot follow named association",
1444 for Index in Names'Range loop
1445 if Names (Index) = Chars (Arg) then
1446 if Present (Args (Index)) then
1448 ("duplicate argument association for pragma%", Arg);
1450 Args (Index) := Expression (Arg);
1455 if Index = Names'Last then
1456 Error_Msg_Name_1 := Chars (N);
1457 Error_Msg_N ("pragma% does not allow & argument", Arg);
1459 -- Check for possible misspelling
1461 for Index1 in Names'Range loop
1462 if Is_Bad_Spelling_Of
1463 (Get_Name_String (Chars (Arg)),
1464 Get_Name_String (Names (Index1)))
1466 Error_Msg_Name_1 := Names (Index1);
1467 Error_Msg_N ("\possible misspelling of%", Arg);
1479 end Gather_Associations;
1481 --------------------
1482 -- Get_Pragma_Arg --
1483 --------------------
1485 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
1487 if Nkind (Arg) = N_Pragma_Argument_Association then
1488 return Expression (Arg);
1498 procedure GNAT_Pragma is
1500 Check_Restriction (No_Implementation_Pragmas, N);
1503 --------------------------
1504 -- Is_Before_First_Decl --
1505 --------------------------
1507 function Is_Before_First_Decl
1508 (Pragma_Node : Node_Id;
1512 Item : Node_Id := First (Decls);
1515 -- Only other pragmas can come before this pragma
1518 if No (Item) or else Nkind (Item) /= N_Pragma then
1521 elsif Item = Pragma_Node then
1527 end Is_Before_First_Decl;
1529 -----------------------------
1530 -- Is_Configuration_Pragma --
1531 -----------------------------
1533 -- A configuration pragma must appear in the context clause of
1534 -- a compilation unit, at the start of the list (i.e. only other
1535 -- pragmas may precede it).
1537 function Is_Configuration_Pragma return Boolean is
1538 Lis : constant List_Id := List_Containing (N);
1539 Par : constant Node_Id := Parent (N);
1543 -- If no parent, then we are in the configuration pragma file,
1544 -- so the placement is definitely appropriate.
1549 -- Otherwise we must be in the context clause of a compilation unit
1550 -- and the only thing allowed before us in the context list is more
1551 -- configuration pragmas.
1553 elsif Nkind (Par) = N_Compilation_Unit
1554 and then Context_Items (Par) = Lis
1561 elsif Nkind (Prg) /= N_Pragma then
1571 end Is_Configuration_Pragma;
1573 ----------------------
1574 -- Pragma_Misplaced --
1575 ----------------------
1577 procedure Pragma_Misplaced is
1579 Error_Pragma ("incorrect placement of pragma%");
1580 end Pragma_Misplaced;
1582 ------------------------------------
1583 -- Process Atomic_Shared_Volatile --
1584 ------------------------------------
1586 procedure Process_Atomic_Shared_Volatile is
1594 Check_Ada_83_Warning;
1595 Check_No_Identifiers;
1596 Check_Arg_Count (1);
1597 Check_Arg_Is_Local_Name (Arg1);
1598 E_Id := Expression (Arg1);
1600 if Etype (E_Id) = Any_Type then
1605 D := Declaration_Node (E);
1609 if Rep_Item_Too_Early (E, N)
1611 Rep_Item_Too_Late (E, N)
1615 Check_First_Subtype (Arg1);
1618 if Prag_Id /= Pragma_Volatile then
1620 Set_Is_Atomic (Underlying_Type (E));
1623 -- Attribute belongs on the base type. If the
1624 -- view of the type is currently private, it also
1625 -- belongs on the underlying type.
1627 Set_Is_Volatile (Base_Type (E));
1628 Set_Is_Volatile (Underlying_Type (E));
1630 Set_Treat_As_Volatile (E);
1631 Set_Treat_As_Volatile (Underlying_Type (E));
1633 elsif K = N_Object_Declaration
1634 or else (K = N_Component_Declaration
1635 and then Original_Record_Component (E) = E)
1637 if Rep_Item_Too_Late (E, N) then
1641 if Prag_Id /= Pragma_Volatile then
1644 -- If the object declaration has an explicit
1645 -- initialization, a temporary may have to be
1646 -- created to hold the expression, to insure
1647 -- that access to the object remain atomic.
1649 if Nkind (Parent (E)) = N_Object_Declaration
1650 and then Present (Expression (Parent (E)))
1652 Set_Has_Delayed_Freeze (E);
1655 -- An interesting improvement here. If an object of type X
1656 -- is declared atomic, and the type X is not atomic, that's
1657 -- a pity, since it may not have appropraite alignment etc.
1658 -- We can rescue this in the special case where the object
1659 -- and type are in the same unit by just setting the type
1660 -- as atomic, so that the back end will process it as atomic.
1662 Utyp := Underlying_Type (Etype (E));
1665 and then Sloc (E) > No_Location
1666 and then Sloc (Utyp) > No_Location
1668 Get_Source_File_Index (Sloc (E)) =
1669 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
1671 Set_Is_Atomic (Underlying_Type (Etype (E)));
1675 Set_Is_Volatile (E);
1676 Set_Treat_As_Volatile (E);
1680 ("inappropriate entity for pragma%", Arg1);
1682 end Process_Atomic_Shared_Volatile;
1684 ------------------------
1685 -- Process_Convention --
1686 ------------------------
1688 procedure Process_Convention
1689 (C : out Convention_Id;
1694 Comp_Unit : Unit_Number_Type;
1697 procedure Set_Convention_From_Pragma (E : Entity_Id);
1698 -- Set convention in entity E, and also flag that the entity has a
1699 -- convention pragma. If entity is for a private or incomplete type,
1700 -- also set convention and flag on underlying type. This procedure
1701 -- also deals with the special case of C_Pass_By_Copy convention.
1703 --------------------------------
1704 -- Set_Convention_From_Pragma --
1705 --------------------------------
1707 procedure Set_Convention_From_Pragma (E : Entity_Id) is
1709 Set_Convention (E, C);
1710 Set_Has_Convention_Pragma (E);
1712 if Is_Incomplete_Or_Private_Type (E) then
1713 Set_Convention (Underlying_Type (E), C);
1714 Set_Has_Convention_Pragma (Underlying_Type (E), True);
1717 -- A class-wide type should inherit the convention of
1718 -- the specific root type (although this isn't specified
1719 -- clearly by the RM).
1721 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
1722 Set_Convention (Class_Wide_Type (E), C);
1725 -- If the entity is a record type, then check for special case
1726 -- of C_Pass_By_Copy, which is treated the same as C except that
1727 -- the special record flag is set. This convention is also only
1728 -- permitted on record types (see AI95-00131).
1730 if Cname = Name_C_Pass_By_Copy then
1731 if Is_Record_Type (E) then
1732 Set_C_Pass_By_Copy (Base_Type (E));
1733 elsif Is_Incomplete_Or_Private_Type (E)
1734 and then Is_Record_Type (Underlying_Type (E))
1736 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
1739 ("C_Pass_By_Copy convention allowed only for record type",
1744 -- If the entity is a derived boolean type, check for the
1745 -- special case of convention C, C++, or Fortran, where we
1746 -- consider any nonzero value to represent true.
1748 if Is_Discrete_Type (E)
1749 and then Root_Type (Etype (E)) = Standard_Boolean
1755 C = Convention_Fortran)
1757 Set_Nonzero_Is_True (Base_Type (E));
1759 end Set_Convention_From_Pragma;
1761 -- Start of processing for Process_Convention
1764 Check_At_Least_N_Arguments (2);
1765 Check_Arg_Is_Identifier (Arg1);
1766 Check_Optional_Identifier (Arg1, Name_Convention);
1767 Cname := Chars (Expression (Arg1));
1769 -- C_Pass_By_Copy is treated as a synonym for convention C
1770 -- (this is tested again below to set the critical flag)
1772 if Cname = Name_C_Pass_By_Copy then
1775 -- Otherwise we must have something in the standard convention list
1777 elsif Is_Convention_Name (Cname) then
1778 C := Get_Convention_Id (Chars (Expression (Arg1)));
1780 -- In DEC VMS, it seems that there is an undocumented feature
1781 -- that any unrecognized convention is treated as the default,
1782 -- which for us is convention C. It does not seem so terrible
1783 -- to do this unconditionally, silently in the VMS case, and
1784 -- with a warning in the non-VMS case.
1787 if Warn_On_Export_Import and not OpenVMS_On_Target then
1789 ("?unrecognized convention name, C assumed",
1796 Check_Arg_Is_Local_Name (Arg2);
1797 Check_Optional_Identifier (Arg2, Name_Entity);
1799 Id := Expression (Arg2);
1802 if not Is_Entity_Name (Id) then
1803 Error_Pragma_Arg ("entity name required", Arg2);
1808 -- Go to renamed subprogram if present, since convention applies
1809 -- to the actual renamed entity, not to the renaming entity.
1811 if Is_Subprogram (E)
1812 and then Present (Alias (E))
1813 and then Nkind (Parent (Declaration_Node (E))) =
1814 N_Subprogram_Renaming_Declaration
1819 -- Check that we not applying this to a specless body
1821 if Is_Subprogram (E)
1822 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
1825 ("pragma% requires separate spec and must come before body");
1828 -- Check that we are not applying this to a named constant
1830 if Ekind (E) = E_Named_Integer
1832 Ekind (E) = E_Named_Real
1834 Error_Msg_Name_1 := Chars (N);
1836 ("cannot apply pragma% to named constant!",
1837 Get_Pragma_Arg (Arg2));
1839 ("\supply appropriate type for&!", Arg2);
1842 if Etype (E) = Any_Type
1843 or else Rep_Item_Too_Early (E, N)
1847 E := Underlying_Type (E);
1850 if Rep_Item_Too_Late (E, N) then
1854 if Has_Convention_Pragma (E) then
1856 ("at most one Convention/Export/Import pragma is allowed", Arg2);
1858 elsif Convention (E) = Convention_Protected
1859 or else Ekind (Scope (E)) = E_Protected_Type
1862 ("a protected operation cannot be given a different convention",
1866 -- For Intrinsic, a subprogram is required
1868 if C = Convention_Intrinsic
1869 and then not Is_Subprogram (E)
1870 and then not Is_Generic_Subprogram (E)
1873 ("second argument of pragma% must be a subprogram", Arg2);
1876 -- For Stdcall, a subprogram, variable or subprogram type is required
1878 if C = Convention_Stdcall
1879 and then not Is_Subprogram (E)
1880 and then not Is_Generic_Subprogram (E)
1881 and then Ekind (E) /= E_Variable
1884 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
1887 ("second argument of pragma% must be subprogram (type)",
1891 if not Is_Subprogram (E)
1892 and then not Is_Generic_Subprogram (E)
1894 Set_Convention_From_Pragma (E);
1898 Check_First_Subtype (Arg2);
1899 Set_Convention_From_Pragma (Base_Type (E));
1901 -- For subprograms, we must set the convention on the
1902 -- internally generated directly designated type as well.
1904 if Ekind (E) = E_Access_Subprogram_Type then
1905 Set_Convention_From_Pragma (Directly_Designated_Type (E));
1909 -- For the subprogram case, set proper convention for all homonyms
1910 -- in same compilation unit.
1911 -- Is the test of compilation unit really necessary ???
1912 -- What about subprogram renamings here???
1915 Comp_Unit := Get_Source_Unit (E);
1916 Set_Convention_From_Pragma (E);
1918 -- Treat a pragma Import as an implicit body, for GPS use.
1920 if Prag_Id = Pragma_Import then
1921 Generate_Reference (E, Id, 'b');
1927 exit when No (E1) or else Scope (E1) /= Current_Scope;
1929 -- Note: below we are missing a check for Rep_Item_Too_Late.
1930 -- That is deliberate, we cannot chain the rep item on more
1931 -- than one Rep_Item chain, to be fixed later ???
1933 if Comp_Unit = Get_Source_Unit (E1) then
1934 Set_Convention_From_Pragma (E1);
1936 if Prag_Id = Pragma_Import then
1937 Generate_Reference (E, Id, 'b');
1942 end Process_Convention;
1944 -----------------------------------------------------
1945 -- Process_Extended_Import_Export_Exception_Pragma --
1946 -----------------------------------------------------
1948 procedure Process_Extended_Import_Export_Exception_Pragma
1949 (Arg_Internal : Node_Id;
1950 Arg_External : Node_Id;
1960 if not OpenVMS_On_Target then
1962 ("?pragma% ignored (applies only to Open'V'M'S)");
1965 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
1966 Def_Id := Entity (Arg_Internal);
1968 if Ekind (Def_Id) /= E_Exception then
1970 ("pragma% must refer to declared exception", Arg_Internal);
1973 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
1975 if Present (Arg_Form) then
1976 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
1979 if Present (Arg_Form)
1980 and then Chars (Arg_Form) = Name_Ada
1984 Set_Is_VMS_Exception (Def_Id);
1985 Set_Exception_Code (Def_Id, No_Uint);
1988 if Present (Arg_Code) then
1989 if not Is_VMS_Exception (Def_Id) then
1991 ("Code option for pragma% not allowed for Ada case",
1995 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
1996 Code_Val := Expr_Value (Arg_Code);
1998 if not UI_Is_In_Int_Range (Code_Val) then
2000 ("Code option for pragma% must be in 32-bit range",
2004 Set_Exception_Code (Def_Id, Code_Val);
2007 end Process_Extended_Import_Export_Exception_Pragma;
2009 -------------------------------------------------
2010 -- Process_Extended_Import_Export_Internal_Arg --
2011 -------------------------------------------------
2013 procedure Process_Extended_Import_Export_Internal_Arg
2014 (Arg_Internal : Node_Id := Empty)
2019 if No (Arg_Internal) then
2020 Error_Pragma ("Internal parameter required for pragma%");
2023 if Nkind (Arg_Internal) = N_Identifier then
2026 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2027 and then (Prag_Id = Pragma_Import_Function
2029 Prag_Id = Pragma_Export_Function)
2035 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2038 Check_Arg_Is_Local_Name (Arg_Internal);
2039 end Process_Extended_Import_Export_Internal_Arg;
2041 --------------------------------------------------
2042 -- Process_Extended_Import_Export_Object_Pragma --
2043 --------------------------------------------------
2045 procedure Process_Extended_Import_Export_Object_Pragma
2046 (Arg_Internal : Node_Id;
2047 Arg_External : Node_Id;
2053 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2054 Def_Id := Entity (Arg_Internal);
2056 if Ekind (Def_Id) /= E_Constant
2057 and then Ekind (Def_Id) /= E_Variable
2060 ("pragma% must designate an object", Arg_Internal);
2063 if Is_Psected (Def_Id) then
2065 ("previous Psect_Object applies, pragma % not permitted",
2069 if Rep_Item_Too_Late (Def_Id, N) then
2073 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2075 if Present (Arg_Size)
2076 and then Nkind (Arg_Size) /= N_Identifier
2077 and then Nkind (Arg_Size) /= N_String_Literal
2080 ("pragma% Size argument must be identifier or string literal",
2084 -- Export_Object case
2086 if Prag_Id = Pragma_Export_Object then
2087 if not Is_Library_Level_Entity (Def_Id) then
2089 ("argument for pragma% must be library level entity",
2093 if Ekind (Current_Scope) = E_Generic_Package then
2094 Error_Pragma ("pragma& cannot appear in a generic unit");
2097 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2099 ("exported object must have compile time known size",
2103 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2105 ("?duplicate Export_Object pragma", N);
2107 Set_Exported (Def_Id, Arg_Internal);
2110 -- Import_Object case
2113 if Is_Concurrent_Type (Etype (Def_Id)) then
2115 ("cannot use pragma% for task/protected object",
2119 if Ekind (Def_Id) = E_Constant then
2121 ("cannot import a constant", Arg_Internal);
2124 if Warn_On_Export_Import
2125 and then Has_Discriminants (Etype (Def_Id))
2128 ("imported value must be initialized?", Arg_Internal);
2131 if Warn_On_Export_Import
2132 and then Is_Access_Type (Etype (Def_Id))
2135 ("cannot import object of an access type?", Arg_Internal);
2138 if Warn_On_Export_Import
2139 and then Is_Imported (Def_Id)
2142 ("?duplicate Import_Object pragma", N);
2144 -- Check for explicit initialization present. Note that an
2145 -- initialization that generated by the code generator, e.g.
2146 -- for an access type, does not count here.
2148 elsif Present (Expression (Parent (Def_Id)))
2151 (Original_Node (Expression (Parent (Def_Id))))
2153 Error_Msg_Sloc := Sloc (Def_Id);
2155 ("no initialization allowed for declaration of& #",
2156 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2159 Set_Imported (Def_Id);
2160 Note_Possible_Modification (Arg_Internal);
2163 end Process_Extended_Import_Export_Object_Pragma;
2165 ------------------------------------------------------
2166 -- Process_Extended_Import_Export_Subprogram_Pragma --
2167 ------------------------------------------------------
2169 procedure Process_Extended_Import_Export_Subprogram_Pragma
2170 (Arg_Internal : Node_Id;
2171 Arg_External : Node_Id;
2172 Arg_Parameter_Types : Node_Id;
2173 Arg_Result_Type : Node_Id := Empty;
2174 Arg_Mechanism : Node_Id;
2175 Arg_Result_Mechanism : Node_Id := Empty;
2176 Arg_First_Optional_Parameter : Node_Id := Empty)
2182 Ambiguous : Boolean;
2186 function Same_Base_Type
2190 -- Determines if Ptype references the type of Formal. Note that
2191 -- only the base types need to match according to the spec. Ptype
2192 -- here is the argument from the pragma, which is either a type
2193 -- name, or an access attribute.
2195 --------------------
2196 -- Same_Base_Type --
2197 --------------------
2199 function Same_Base_Type (Ptype, Formal : Entity_Id) return Boolean is
2200 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2204 -- Case where pragma argument is typ'Access
2206 if Nkind (Ptype) = N_Attribute_Reference
2207 and then Attribute_Name (Ptype) = Name_Access
2209 Pref := Prefix (Ptype);
2212 if not Is_Entity_Name (Pref)
2213 or else Entity (Pref) = Any_Type
2218 -- We have a match if the corresponding argument is of an
2219 -- anonymous access type, and its designicated type matches
2220 -- the type of the prefix of the access attribute
2222 return Ekind (Ftyp) = E_Anonymous_Access_Type
2223 and then Base_Type (Entity (Pref)) =
2224 Base_Type (Etype (Designated_Type (Ftyp)));
2226 -- Case where pragma argument is a type name
2231 if not Is_Entity_Name (Ptype)
2232 or else Entity (Ptype) = Any_Type
2237 -- We have a match if the corresponding argument is of
2238 -- the type given in the pragma (comparing base types)
2240 return Base_Type (Entity (Ptype)) = Ftyp;
2244 -- Start of processing for
2245 -- Process_Extended_Import_Export_Subprogram_Pragma
2248 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2249 Hom_Id := Entity (Arg_Internal);
2253 -- Loop through homonyms (overloadings) of Hom_Id
2255 while Present (Hom_Id) loop
2256 Def_Id := Get_Base_Subprogram (Hom_Id);
2258 -- We need a subprogram in the current scope
2260 if not Is_Subprogram (Def_Id)
2261 or else Scope (Def_Id) /= Current_Scope
2268 -- Pragma cannot apply to subprogram body
2270 if Is_Subprogram (Def_Id)
2273 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2276 ("pragma% requires separate spec"
2277 & " and must come before body");
2280 -- Test result type if given, note that the result type
2281 -- parameter can only be present for the function cases.
2283 if Present (Arg_Result_Type)
2284 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2288 elsif Etype (Def_Id) /= Standard_Void_Type
2290 (Chars (N) = Name_Export_Procedure
2291 or else Chars (N) = Name_Import_Procedure)
2295 -- Test parameter types if given. Note that this parameter
2296 -- has not been analyzed (and must not be, since it is
2297 -- semantic nonsense), so we get it as the parser left it.
2299 elsif Present (Arg_Parameter_Types) then
2300 Check_Matching_Types : declare
2305 Formal := First_Formal (Def_Id);
2307 if Nkind (Arg_Parameter_Types) = N_Null then
2308 if Present (Formal) then
2312 -- A list of one type, e.g. (List) is parsed as
2313 -- a parenthesized expression.
2315 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
2316 and then Paren_Count (Arg_Parameter_Types) = 1
2319 or else Present (Next_Formal (Formal))
2324 Same_Base_Type (Arg_Parameter_Types, Formal);
2327 -- A list of more than one type is parsed as a aggregate
2329 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
2330 and then Paren_Count (Arg_Parameter_Types) = 0
2332 Ptype := First (Expressions (Arg_Parameter_Types));
2334 while Present (Ptype) or else Present (Formal) loop
2337 or else not Same_Base_Type (Ptype, Formal)
2342 Next_Formal (Formal);
2347 -- Anything else is of the wrong form
2351 ("wrong form for Parameter_Types parameter",
2352 Arg_Parameter_Types);
2354 end Check_Matching_Types;
2357 -- Match is now False if the entry we found did not match
2358 -- either a supplied Parameter_Types or Result_Types argument
2364 -- Ambiguous case, the flag Ambiguous shows if we already
2365 -- detected this and output the initial messages.
2368 if not Ambiguous then
2370 Error_Msg_Name_1 := Chars (N);
2372 ("pragma% does not uniquely identify subprogram!",
2374 Error_Msg_Sloc := Sloc (Ent);
2375 Error_Msg_N ("matching subprogram #!", N);
2379 Error_Msg_Sloc := Sloc (Def_Id);
2380 Error_Msg_N ("matching subprogram #!", N);
2385 Hom_Id := Homonym (Hom_Id);
2388 -- See if we found an entry
2391 if not Ambiguous then
2392 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
2394 ("pragma% cannot be given for generic subprogram");
2398 ("pragma% does not identify local subprogram");
2405 -- Import pragmas must be be for imported entities
2407 if Prag_Id = Pragma_Import_Function
2409 Prag_Id = Pragma_Import_Procedure
2411 Prag_Id = Pragma_Import_Valued_Procedure
2413 if not Is_Imported (Ent) then
2415 ("pragma Import or Interface must precede pragma%");
2418 -- Here we have the Export case which can set the entity as exported
2420 -- But does not do so if the specified external name is null,
2421 -- since that is taken as a signal in DEC Ada 83 (with which
2422 -- we want to be compatible) to request no external name.
2424 elsif Nkind (Arg_External) = N_String_Literal
2425 and then String_Length (Strval (Arg_External)) = 0
2429 -- In all other cases, set entit as exported
2432 Set_Exported (Ent, Arg_Internal);
2435 -- Special processing for Valued_Procedure cases
2437 if Prag_Id = Pragma_Import_Valued_Procedure
2439 Prag_Id = Pragma_Export_Valued_Procedure
2441 Formal := First_Formal (Ent);
2445 ("at least one parameter required for pragma%");
2447 elsif Ekind (Formal) /= E_Out_Parameter then
2449 ("first parameter must have mode out for pragma%");
2452 Set_Is_Valued_Procedure (Ent);
2456 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
2458 -- Process Result_Mechanism argument if present. We have already
2459 -- checked that this is only allowed for the function case.
2461 if Present (Arg_Result_Mechanism) then
2462 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
2465 -- Process Mechanism parameter if present. Note that this parameter
2466 -- is not analyzed, and must not be analyzed since it is semantic
2467 -- nonsense, so we get it in exactly as the parser left it.
2469 if Present (Arg_Mechanism) then
2477 -- A single mechanism association without a formal parameter
2478 -- name is parsed as a parenthesized expression. All other
2479 -- cases are parsed as aggregates, so we rewrite the single
2480 -- parameter case as an aggregate for consistency.
2482 if Nkind (Arg_Mechanism) /= N_Aggregate
2483 and then Paren_Count (Arg_Mechanism) = 1
2485 Rewrite (Arg_Mechanism,
2486 Make_Aggregate (Sloc (Arg_Mechanism),
2487 Expressions => New_List (
2488 Relocate_Node (Arg_Mechanism))));
2491 -- Case of only mechanism name given, applies to all formals
2493 if Nkind (Arg_Mechanism) /= N_Aggregate then
2494 Formal := First_Formal (Ent);
2495 while Present (Formal) loop
2496 Set_Mechanism_Value (Formal, Arg_Mechanism);
2497 Next_Formal (Formal);
2500 -- Case of list of mechanism associations given
2503 if Null_Record_Present (Arg_Mechanism) then
2505 ("inappropriate form for Mechanism parameter",
2509 -- Deal with positional ones first
2511 Formal := First_Formal (Ent);
2512 if Present (Expressions (Arg_Mechanism)) then
2513 Mname := First (Expressions (Arg_Mechanism));
2515 while Present (Mname) loop
2518 ("too many mechanism associations", Mname);
2521 Set_Mechanism_Value (Formal, Mname);
2522 Next_Formal (Formal);
2527 -- Deal with named entries
2529 if Present (Component_Associations (Arg_Mechanism)) then
2530 Massoc := First (Component_Associations (Arg_Mechanism));
2532 while Present (Massoc) loop
2533 Choice := First (Choices (Massoc));
2535 if Nkind (Choice) /= N_Identifier
2536 or else Present (Next (Choice))
2539 ("incorrect form for mechanism association",
2543 Formal := First_Formal (Ent);
2547 ("parameter name & not present", Choice);
2550 if Chars (Choice) = Chars (Formal) then
2552 (Formal, Expression (Massoc));
2556 Next_Formal (Formal);
2566 -- Process First_Optional_Parameter argument if present. We have
2567 -- already checked that this is only allowed for the Import case.
2569 if Present (Arg_First_Optional_Parameter) then
2570 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
2572 ("first optional parameter must be formal parameter name",
2573 Arg_First_Optional_Parameter);
2576 Formal := First_Formal (Ent);
2580 ("specified formal parameter& not found",
2581 Arg_First_Optional_Parameter);
2584 exit when Chars (Formal) =
2585 Chars (Arg_First_Optional_Parameter);
2587 Next_Formal (Formal);
2590 Set_First_Optional_Parameter (Ent, Formal);
2592 -- Check specified and all remaining formals have right form
2594 while Present (Formal) loop
2595 if Ekind (Formal) /= E_In_Parameter then
2597 ("optional formal& is not of mode in!",
2598 Arg_First_Optional_Parameter, Formal);
2601 Dval := Default_Value (Formal);
2603 if not Present (Dval) then
2605 ("optional formal& does not have default value!",
2606 Arg_First_Optional_Parameter, Formal);
2608 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
2613 ("default value for optional formal& is non-static!",
2614 Arg_First_Optional_Parameter, Formal);
2618 Set_Is_Optional_Parameter (Formal);
2619 Next_Formal (Formal);
2622 end Process_Extended_Import_Export_Subprogram_Pragma;
2624 --------------------------
2625 -- Process_Generic_List --
2626 --------------------------
2628 procedure Process_Generic_List is
2634 Check_No_Identifiers;
2635 Check_At_Least_N_Arguments (1);
2638 while Present (Arg) loop
2639 Exp := Expression (Arg);
2642 if not Is_Entity_Name (Exp)
2644 (not Is_Generic_Instance (Entity (Exp))
2646 not Is_Generic_Unit (Entity (Exp)))
2649 ("pragma% argument must be name of generic unit/instance",
2655 end Process_Generic_List;
2657 ---------------------------------
2658 -- Process_Import_Or_Interface --
2659 ---------------------------------
2661 procedure Process_Import_Or_Interface is
2667 Process_Convention (C, Def_Id);
2668 Kill_Size_Check_Code (Def_Id);
2669 Note_Possible_Modification (Expression (Arg2));
2671 if Ekind (Def_Id) = E_Variable
2673 Ekind (Def_Id) = E_Constant
2675 -- User initialization is not allowed for imported object, but
2676 -- the object declaration may contain a default initialization,
2677 -- that will be discarded. Note that an explicit initialization
2678 -- only counts if it comes from source, otherwise it is simply
2679 -- the code generator making an implicit initialization explicit.
2681 if Present (Expression (Parent (Def_Id)))
2682 and then Comes_From_Source (Expression (Parent (Def_Id)))
2684 Error_Msg_Sloc := Sloc (Def_Id);
2686 ("no initialization allowed for declaration of& #",
2687 "\imported entities cannot be initialized ('R'M' 'B.1(24))",
2691 Set_Imported (Def_Id);
2692 Set_Is_Public (Def_Id);
2693 Process_Interface_Name (Def_Id, Arg3, Arg4);
2695 -- It is not possible to import a constant of an unconstrained
2696 -- array type (e.g. string) because there is no simple way to
2697 -- write a meaningful subtype for it.
2699 if Is_Array_Type (Etype (Def_Id))
2700 and then not Is_Constrained (Etype (Def_Id))
2703 ("imported constant& must have a constrained subtype",
2708 elsif Is_Subprogram (Def_Id)
2709 or else Is_Generic_Subprogram (Def_Id)
2711 -- If the name is overloaded, pragma applies to all of the
2712 -- denoted entities in the same declarative part.
2716 while Present (Hom_Id) loop
2717 Def_Id := Get_Base_Subprogram (Hom_Id);
2719 -- Ignore inherited subprograms because the pragma will
2720 -- apply to the parent operation, which is the one called.
2722 if Is_Overloadable (Def_Id)
2723 and then Present (Alias (Def_Id))
2727 -- If it is not a subprogram, it must be in an outer
2728 -- scope and pragma does not apply.
2730 elsif not Is_Subprogram (Def_Id)
2731 and then not Is_Generic_Subprogram (Def_Id)
2735 -- Verify that the homonym is in the same declarative
2736 -- part (not just the same scope).
2738 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
2739 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
2744 Set_Imported (Def_Id);
2746 -- If Import intrinsic, set intrinsic flag
2747 -- and verify that it is known as such.
2749 if C = Convention_Intrinsic then
2750 Set_Is_Intrinsic_Subprogram (Def_Id);
2751 Check_Intrinsic_Subprogram
2752 (Def_Id, Expression (Arg2));
2755 -- All interfaced procedures need an external
2756 -- symbol created for them since they are
2757 -- always referenced from another object file.
2759 Set_Is_Public (Def_Id);
2761 -- Verify that the subprogram does not have a completion
2762 -- through a renaming declaration. For other completions
2763 -- the pragma appears as a too late representation.
2766 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
2769 and then Nkind (Decl) = N_Subprogram_Declaration
2770 and then Present (Corresponding_Body (Decl))
2773 (Unit_Declaration_Node
2774 (Corresponding_Body (Decl))) =
2775 N_Subprogram_Renaming_Declaration
2777 Error_Msg_Sloc := Sloc (Def_Id);
2778 Error_Msg_NE ("cannot import&#," &
2779 " already completed by a renaming",
2784 Set_Has_Completion (Def_Id);
2785 Process_Interface_Name (Def_Id, Arg3, Arg4);
2788 if Is_Compilation_Unit (Hom_Id) then
2790 -- Its possible homonyms are not affected by the pragma.
2791 -- Such homonyms might be present in the context of other
2792 -- units being compiled.
2797 Hom_Id := Homonym (Hom_Id);
2801 -- When the convention is Java, we also allow Import to be given
2802 -- for packages, exceptions, and record components.
2804 elsif C = Convention_Java
2805 and then (Ekind (Def_Id) = E_Package
2806 or else Ekind (Def_Id) = E_Exception
2807 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
2809 Set_Imported (Def_Id);
2810 Set_Is_Public (Def_Id);
2811 Process_Interface_Name (Def_Id, Arg3, Arg4);
2815 ("second argument of pragma% must be object or subprogram",
2819 -- If this pragma applies to a compilation unit, then the unit,
2820 -- which is a subprogram, does not require (or allow) a body.
2821 -- We also do not need to elaborate imported procedures.
2823 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2825 Cunit : constant Node_Id := Parent (Parent (N));
2828 Set_Body_Required (Cunit, False);
2831 end Process_Import_Or_Interface;
2833 --------------------
2834 -- Process_Inline --
2835 --------------------
2837 procedure Process_Inline (Active : Boolean) is
2844 procedure Make_Inline (Subp : Entity_Id);
2845 -- Subp is the defining unit name of the subprogram
2846 -- declaration. Set the flag, as well as the flag in the
2847 -- corresponding body, if there is one present.
2849 procedure Set_Inline_Flags (Subp : Entity_Id);
2850 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp
2852 function Back_End_Cannot_Inline (Subp : Entity_Id) return Boolean;
2853 -- Do not set the inline flag if body is available and contains
2854 -- exception handlers, to prevent undefined symbols at link time.
2856 ----------------------------
2857 -- Back_End_Cannot_Inline --
2858 ----------------------------
2860 function Back_End_Cannot_Inline (Subp : Entity_Id) return Boolean is
2861 Decl : Node_Id := Unit_Declaration_Node (Subp);
2864 if Nkind (Decl) = N_Subprogram_Body then
2867 (Exception_Handlers (Handled_Statement_Sequence (Decl)));
2869 elsif Nkind (Decl) = N_Subprogram_Declaration
2870 and then Present (Corresponding_Body (Decl))
2873 Present (Exception_Handlers
2874 (Handled_Statement_Sequence
2875 (Unit_Declaration_Node (Corresponding_Body (Decl)))));
2877 -- If body is not available, assume the best, the check is
2878 -- performed again when compiling enclosing package bodies.
2882 end Back_End_Cannot_Inline;
2888 procedure Make_Inline (Subp : Entity_Id) is
2889 Kind : constant Entity_Kind := Ekind (Subp);
2890 Inner_Subp : Entity_Id := Subp;
2893 if Etype (Subp) = Any_Type then
2896 elsif Back_End_Cannot_Inline (Subp) then
2897 Applies := True; -- Do not treat as an error.
2900 -- Here we have a candidate for inlining, but we must exclude
2901 -- derived operations. Otherwise we will end up trying to
2902 -- inline a phantom declaration, and the result would be to
2903 -- drag in a body which has no direct inlining associated with
2904 -- it. That would not only be inefficient but would also result
2905 -- in the backend doing cross-unit inlining in cases where it
2906 -- was definitely inappropriate to do so.
2908 -- However, a simple Comes_From_Source test is insufficient,
2909 -- since we do want to allow inlining of generic instances,
2910 -- which also do not come from source. Predefined operators do
2911 -- not come from source but are not inlineable either.
2913 elsif not Comes_From_Source (Subp)
2914 and then not Is_Generic_Instance (Subp)
2915 and then Scope (Subp) /= Standard_Standard
2920 -- The referenced entity must either be the enclosing entity,
2921 -- or an entity declared within the current open scope.
2923 elsif Present (Scope (Subp))
2924 and then Scope (Subp) /= Current_Scope
2925 and then Subp /= Current_Scope
2928 ("argument of% must be entity in current scope", Assoc);
2932 -- Processing for procedure, operator or function.
2933 -- If subprogram is aliased (as for an instance) indicate
2934 -- that the renamed entity is inlined.
2936 if Is_Subprogram (Subp) then
2937 while Present (Alias (Inner_Subp)) loop
2938 Inner_Subp := Alias (Inner_Subp);
2941 Set_Inline_Flags (Inner_Subp);
2943 Decl := Parent (Parent (Inner_Subp));
2945 if Nkind (Decl) = N_Subprogram_Declaration
2946 and then Present (Corresponding_Body (Decl))
2948 Set_Inline_Flags (Corresponding_Body (Decl));
2953 -- For a generic subprogram set flag as well, for use at
2954 -- the point of instantiation, to determine whether the
2955 -- body should be generated.
2957 elsif Is_Generic_Subprogram (Subp) then
2958 Set_Inline_Flags (Subp);
2961 -- Literals are by definition inlined
2963 elsif Kind = E_Enumeration_Literal then
2966 -- Anything else is an error
2970 ("expect subprogram name for pragma%", Assoc);
2974 ----------------------
2975 -- Set_Inline_Flags --
2976 ----------------------
2978 procedure Set_Inline_Flags (Subp : Entity_Id) is
2981 Set_Is_Inlined (Subp, True);
2984 if not Has_Pragma_Inline (Subp) then
2985 Set_Has_Pragma_Inline (Subp);
2986 Set_Next_Rep_Item (N, First_Rep_Item (Subp));
2987 Set_First_Rep_Item (Subp, N);
2989 end Set_Inline_Flags;
2991 -- Start of processing for Process_Inline
2994 Check_No_Identifiers;
2995 Check_At_Least_N_Arguments (1);
2998 Inline_Processing_Required := True;
3002 while Present (Assoc) loop
3003 Subp_Id := Expression (Assoc);
3007 if Is_Entity_Name (Subp_Id) then
3008 Subp := Entity (Subp_Id);
3010 if Subp = Any_Id then
3016 while Present (Homonym (Subp))
3017 and then Scope (Homonym (Subp)) = Current_Scope
3019 Make_Inline (Homonym (Subp));
3020 Subp := Homonym (Subp);
3027 ("inappropriate argument for pragma%", Assoc);
3034 ----------------------------
3035 -- Process_Interface_Name --
3036 ----------------------------
3038 procedure Process_Interface_Name
3039 (Subprogram_Def : Entity_Id;
3045 String_Val : String_Id;
3047 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3048 -- SN is a string literal node for an interface name. This routine
3049 -- performs some minimal checks that the name is reasonable. In
3050 -- particular that no spaces or other obviously incorrect characters
3051 -- appear. This is only a warning, since any characters are allowed.
3053 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3054 S : constant String_Id := Strval (Expr_Value_S (SN));
3055 SL : constant Nat := String_Length (S);
3060 Error_Msg_N ("interface name cannot be null string", SN);
3063 for J in 1 .. SL loop
3064 C := Get_String_Char (S, J);
3066 if Warn_On_Export_Import
3067 and then (not In_Character_Range (C)
3068 or else Get_Character (C) = ' '
3069 or else Get_Character (C) = ',')
3072 ("?interface name contains illegal character", SN);
3075 end Check_Form_Of_Interface_Name;
3077 -- Start of processing for Process_Interface_Name
3080 if No (Link_Arg) then
3081 if No (Ext_Arg) then
3084 elsif Chars (Ext_Arg) = Name_Link_Name then
3086 Link_Nam := Expression (Ext_Arg);
3089 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3090 Ext_Nam := Expression (Ext_Arg);
3095 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3096 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3097 Ext_Nam := Expression (Ext_Arg);
3098 Link_Nam := Expression (Link_Arg);
3101 -- Check expressions for external name and link name are static
3103 if Present (Ext_Nam) then
3104 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3105 Check_Form_Of_Interface_Name (Ext_Nam);
3107 -- Verify that the external name is not the name of a local
3108 -- entity, which would hide the imported one and lead to
3109 -- run-time surprises. The problem can only arise for entities
3110 -- declared in a package body (otherwise the external name is
3111 -- fully qualified and won't conflict).
3119 if Prag_Id = Pragma_Import then
3120 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3122 E := Entity_Id (Get_Name_Table_Info (Nam));
3124 if Nam /= Chars (Subprogram_Def)
3125 and then Present (E)
3126 and then not Is_Overloadable (E)
3127 and then Is_Immediately_Visible (E)
3128 and then not Is_Imported (E)
3129 and then Ekind (Scope (E)) = E_Package
3133 while Present (Par) loop
3134 if Nkind (Par) = N_Package_Body then
3135 Error_Msg_Sloc := Sloc (E);
3137 ("imported entity is hidden by & declared#",
3142 Par := Parent (Par);
3149 if Present (Link_Nam) then
3150 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3151 Check_Form_Of_Interface_Name (Link_Nam);
3154 -- If there is no link name, just set the external name
3156 if No (Link_Nam) then
3157 Set_Encoded_Interface_Name
3158 (Get_Base_Subprogram (Subprogram_Def),
3159 Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)));
3161 -- For the Link_Name case, the given literal is preceded by an
3162 -- asterisk, which indicates to GCC that the given name should
3163 -- be taken literally, and in particular that no prepending of
3164 -- underlines should occur, even in systems where this is the
3169 Store_String_Char (Get_Char_Code ('*'));
3170 String_Val := Strval (Expr_Value_S (Link_Nam));
3172 for J in 1 .. String_Length (String_Val) loop
3173 Store_String_Char (Get_String_Char (String_Val, J));
3177 Make_String_Literal (Sloc (Link_Nam), End_String);
3179 Set_Encoded_Interface_Name
3180 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
3182 end Process_Interface_Name;
3184 -----------------------------------------
3185 -- Process_Interrupt_Or_Attach_Handler --
3186 -----------------------------------------
3188 procedure Process_Interrupt_Or_Attach_Handler is
3189 Arg1_X : constant Node_Id := Expression (Arg1);
3190 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
3191 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
3194 Set_Is_Interrupt_Handler (Handler_Proc);
3196 -- If the pragma is not associated with a handler procedure
3197 -- within a protected type, then it must be for a nonprotected
3198 -- procedure for the AAMP target, in which case we don't
3199 -- associate a representation item with the procedure's scope.
3201 if Ekind (Proc_Scope) = E_Protected_Type then
3202 if Prag_Id = Pragma_Interrupt_Handler
3203 or Prag_Id = Pragma_Attach_Handler
3205 Record_Rep_Item (Proc_Scope, N);
3208 end Process_Interrupt_Or_Attach_Handler;
3210 ---------------------------------
3211 -- Process_Suppress_Unsuppress --
3212 ---------------------------------
3214 -- Note: this procedure makes entries in the check suppress data
3215 -- structures managed by Sem. See spec of package Sem for full
3216 -- details on how we handle recording of check suppression.
3218 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
3223 In_Package_Spec : constant Boolean :=
3224 (Ekind (Current_Scope) = E_Package
3226 Ekind (Current_Scope) = E_Generic_Package)
3227 and then not In_Package_Body (Current_Scope);
3229 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
3230 -- Used to suppress a single check on the given entity
3232 --------------------------------
3233 -- Suppress_Unsuppress_Echeck --
3234 --------------------------------
3236 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
3237 ESR : constant Entity_Check_Suppress_Record :=
3240 Suppress => Suppress_Case);
3243 Set_Checks_May_Be_Suppressed (E);
3245 if In_Package_Spec then
3246 Global_Entity_Suppress.Append (ESR);
3248 Local_Entity_Suppress.Append (ESR);
3251 -- If this is a first subtype, and the base type is distinct,
3252 -- then also set the suppress flags on the base type.
3254 if Is_First_Subtype (E)
3255 and then Etype (E) /= E
3257 Suppress_Unsuppress_Echeck (Etype (E), C);
3259 end Suppress_Unsuppress_Echeck;
3261 -- Start of processing for Process_Suppress_Unsuppress
3264 -- Suppress/Unsuppress can appear as a configuration pragma,
3265 -- or in a declarative part or a package spec (RM 11.5(5))
3267 if not Is_Configuration_Pragma then
3268 Check_Is_In_Decl_Part_Or_Package_Spec;
3271 Check_At_Least_N_Arguments (1);
3272 Check_At_Most_N_Arguments (2);
3273 Check_No_Identifier (Arg1);
3274 Check_Arg_Is_Identifier (Arg1);
3276 if not Is_Check_Name (Chars (Expression (Arg1))) then
3278 ("argument of pragma% is not valid check name", Arg1);
3281 C := Get_Check_Id (Chars (Expression (Arg1)));
3284 if Arg_Count = 1 then
3286 -- Make an entry in the local scope suppress table. This is the
3287 -- table that directly shows the current value of the scope
3288 -- suppress check for any check id value.
3290 if C = All_Checks then
3291 Scope_Suppress := (others => Suppress_Case);
3293 Scope_Suppress (C) := Suppress_Case;
3296 -- Also make an entry in the Local_Entity_Suppress table. See
3297 -- extended description in the package spec of Sem for details.
3299 Local_Entity_Suppress.Append
3302 Suppress => Suppress_Case));
3304 -- Case of two arguments present, where the check is
3305 -- suppressed for a specified entity (given as the second
3306 -- argument of the pragma)
3309 Check_Optional_Identifier (Arg2, Name_On);
3310 E_Id := Expression (Arg2);
3313 if not Is_Entity_Name (E_Id) then
3315 ("second argument of pragma% must be entity name", Arg2);
3324 -- Enforce RM 11.5(7) which requires that for a pragma that
3325 -- appears within a package spec, the named entity must be
3326 -- within the package spec. We allow the package name itself
3327 -- to be mentioned since that makes sense, although it is not
3328 -- strictly allowed by 11.5(7).
3331 and then E /= Current_Scope
3332 and then Scope (E) /= Current_Scope
3335 ("entity in pragma% is not in package spec ('R'M 11.5(7))",
3339 -- Loop through homonyms. As noted below, in the case of a package
3340 -- spec, only homonyms within the package spec are considered.
3343 Suppress_Unsuppress_Echeck (E, C);
3345 if Is_Generic_Instance (E)
3346 and then Is_Subprogram (E)
3347 and then Present (Alias (E))
3349 Suppress_Unsuppress_Echeck (Alias (E), C);
3352 -- Move to next homonym
3357 -- If we are within a package specification, the
3358 -- pragma only applies to homonyms in the same scope.
3360 exit when In_Package_Spec
3361 and then Scope (E) /= Current_Scope;
3364 end Process_Suppress_Unsuppress;
3370 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
3372 if Is_Imported (E) then
3374 ("cannot export entity& that was previously imported", Arg);
3376 elsif Present (Address_Clause (E)) then
3378 ("cannot export entity& that has an address clause", Arg);
3381 Set_Is_Exported (E);
3383 -- Generate a reference for entity explicitly, because the
3384 -- identifier may be overloaded and name resolution will not
3387 Generate_Reference (E, Arg);
3389 -- Deal with exporting non-library level entity
3391 if not Is_Library_Level_Entity (E) then
3393 -- Not allowed at all for subprograms
3395 if Is_Subprogram (E) then
3396 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
3398 -- Otherwise set public and statically allocated
3402 Set_Is_Statically_Allocated (E);
3404 if Warn_On_Export_Import then
3406 ("?& has been made static as a result of Export", Arg, E);
3408 ("\this usage is non-standard and non-portable", Arg);
3413 if Warn_On_Export_Import and then Is_Type (E) then
3415 ("exporting a type has no effect?", Arg, E);
3418 if Warn_On_Export_Import and Inside_A_Generic then
3420 ("all instances of& will have the same external name?", Arg, E);
3424 ----------------------------------------------
3425 -- Set_Extended_Import_Export_External_Name --
3426 ----------------------------------------------
3428 procedure Set_Extended_Import_Export_External_Name
3429 (Internal_Ent : Entity_Id;
3430 Arg_External : Node_Id)
3432 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
3436 if No (Arg_External) then
3439 elsif Nkind (Arg_External) = N_String_Literal then
3440 if String_Length (Strval (Arg_External)) = 0 then
3443 New_Name := Adjust_External_Name_Case (Arg_External);
3446 elsif Nkind (Arg_External) = N_Identifier then
3447 New_Name := Get_Default_External_Name (Arg_External);
3451 ("incorrect form for External parameter for pragma%",
3455 -- If we already have an external name set (by a prior normal
3456 -- Import or Export pragma), then the external names must match
3458 if Present (Interface_Name (Internal_Ent)) then
3460 S1 : constant String_Id := Strval (Old_Name);
3461 S2 : constant String_Id := Strval (New_Name);
3464 -- Called if names do not match
3466 procedure Mismatch is
3468 Error_Msg_Sloc := Sloc (Old_Name);
3470 ("external name does not match that given #",
3475 if String_Length (S1) /= String_Length (S2) then
3479 for J in 1 .. String_Length (S1) loop
3480 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
3487 -- Otherwise set the given name
3490 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
3493 end Set_Extended_Import_Export_External_Name;
3499 procedure Set_Imported (E : Entity_Id) is
3501 Error_Msg_Sloc := Sloc (E);
3503 if Is_Exported (E) or else Is_Imported (E) then
3504 Error_Msg_NE ("import of& declared# not allowed", N, E);
3506 if Is_Exported (E) then
3507 Error_Msg_N ("\entity was previously exported", N);
3509 Error_Msg_N ("\entity was previously imported", N);
3512 Error_Pragma ("\(pragma% applies to all previous entities)");
3515 Set_Is_Imported (E);
3517 -- If the entity is an object that is not at the library
3518 -- level, then it is statically allocated. We do not worry
3519 -- about objects with address clauses in this context since
3520 -- they are not really imported in the linker sense.
3523 and then not Is_Library_Level_Entity (E)
3524 and then No (Address_Clause (E))
3526 Set_Is_Statically_Allocated (E);
3531 -------------------------
3532 -- Set_Mechanism_Value --
3533 -------------------------
3535 -- Note: the mechanism name has not been analyzed (and cannot indeed
3536 -- be analyzed, since it is semantic nonsense), so we get it in the
3537 -- exact form created by the parser.
3539 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
3543 procedure Bad_Class;
3544 -- Signal bad descriptor class name
3546 procedure Bad_Mechanism;
3547 -- Signal bad mechanism name
3549 procedure Bad_Class is
3551 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
3554 procedure Bad_Mechanism is
3556 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
3559 -- Start of processing for Set_Mechanism_Value
3562 if Mechanism (Ent) /= Default_Mechanism then
3564 ("mechanism for & has already been set", Mech_Name, Ent);
3567 -- MECHANISM_NAME ::= value | reference | descriptor
3569 if Nkind (Mech_Name) = N_Identifier then
3570 if Chars (Mech_Name) = Name_Value then
3571 Set_Mechanism (Ent, By_Copy);
3574 elsif Chars (Mech_Name) = Name_Reference then
3575 Set_Mechanism (Ent, By_Reference);
3578 elsif Chars (Mech_Name) = Name_Descriptor then
3579 Check_VMS (Mech_Name);
3580 Set_Mechanism (Ent, By_Descriptor);
3583 elsif Chars (Mech_Name) = Name_Copy then
3585 ("bad mechanism name, Value assumed", Mech_Name);
3591 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
3592 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3594 -- Note: this form is parsed as an indexed component
3596 elsif Nkind (Mech_Name) = N_Indexed_Component then
3597 Class := First (Expressions (Mech_Name));
3599 if Nkind (Prefix (Mech_Name)) /= N_Identifier
3600 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
3601 or else Present (Next (Class))
3606 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
3607 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
3609 -- Note: this form is parsed as a function call
3611 elsif Nkind (Mech_Name) = N_Function_Call then
3613 Param := First (Parameter_Associations (Mech_Name));
3615 if Nkind (Name (Mech_Name)) /= N_Identifier
3616 or else Chars (Name (Mech_Name)) /= Name_Descriptor
3617 or else Present (Next (Param))
3618 or else No (Selector_Name (Param))
3619 or else Chars (Selector_Name (Param)) /= Name_Class
3623 Class := Explicit_Actual_Parameter (Param);
3630 -- Fall through here with Class set to descriptor class name
3632 Check_VMS (Mech_Name);
3634 if Nkind (Class) /= N_Identifier then
3637 elsif Chars (Class) = Name_UBS then
3638 Set_Mechanism (Ent, By_Descriptor_UBS);
3640 elsif Chars (Class) = Name_UBSB then
3641 Set_Mechanism (Ent, By_Descriptor_UBSB);
3643 elsif Chars (Class) = Name_UBA then
3644 Set_Mechanism (Ent, By_Descriptor_UBA);
3646 elsif Chars (Class) = Name_S then
3647 Set_Mechanism (Ent, By_Descriptor_S);
3649 elsif Chars (Class) = Name_SB then
3650 Set_Mechanism (Ent, By_Descriptor_SB);
3652 elsif Chars (Class) = Name_A then
3653 Set_Mechanism (Ent, By_Descriptor_A);
3655 elsif Chars (Class) = Name_NCA then
3656 Set_Mechanism (Ent, By_Descriptor_NCA);
3662 end Set_Mechanism_Value;
3664 -- Start of processing for Analyze_Pragma
3667 if not Is_Pragma_Name (Chars (N)) then
3668 if Warn_On_Unrecognized_Pragma then
3669 Error_Pragma ("unrecognized pragma%!?");
3674 Prag_Id := Get_Pragma_Id (Chars (N));
3684 if Present (Pragma_Argument_Associations (N)) then
3685 Arg1 := First (Pragma_Argument_Associations (N));
3687 if Present (Arg1) then
3688 Arg2 := Next (Arg1);
3690 if Present (Arg2) then
3691 Arg3 := Next (Arg2);
3693 if Present (Arg3) then
3694 Arg4 := Next (Arg3);
3700 -- Count number of arguments
3709 while Present (Arg_Node) loop
3710 Arg_Count := Arg_Count + 1;
3715 -- An enumeration type defines the pragmas that are supported by the
3716 -- implementation. Get_Pragma_Id (in package Prag) transorms a name
3717 -- into the corresponding enumeration value for the following case.
3725 -- pragma Abort_Defer;
3727 when Pragma_Abort_Defer =>
3729 Check_Arg_Count (0);
3731 -- The only required semantic processing is to check the
3732 -- placement. This pragma must appear at the start of the
3733 -- statement sequence of a handled sequence of statements.
3735 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
3736 or else N /= First (Statements (Parent (N)))
3747 -- Note: this pragma also has some specific processing in Par.Prag
3748 -- because we want to set the Ada 83 mode switch during parsing.
3750 when Pragma_Ada_83 =>
3754 Check_Arg_Count (0);
3762 -- Note: this pragma also has some specific processing in Par.Prag
3763 -- because we want to set the Ada 83 mode switch during parsing.
3765 when Pragma_Ada_95 =>
3769 Check_Arg_Count (0);
3771 ----------------------
3772 -- All_Calls_Remote --
3773 ----------------------
3775 -- pragma All_Calls_Remote [(library_package_NAME)];
3777 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
3778 Lib_Entity : Entity_Id;
3781 Check_Ada_83_Warning;
3782 Check_Valid_Library_Unit_Pragma;
3784 if Nkind (N) = N_Null_Statement then
3788 Lib_Entity := Find_Lib_Unit_Name;
3790 -- This pragma should only apply to a RCI unit (RM E.2.3(23)).
3792 if Present (Lib_Entity)
3793 and then not Debug_Flag_U
3795 if not Is_Remote_Call_Interface (Lib_Entity) then
3796 Error_Pragma ("pragma% only apply to rci unit");
3798 -- Set flag for entity of the library unit
3801 Set_Has_All_Calls_Remote (Lib_Entity);
3805 end All_Calls_Remote;
3811 -- pragma Annotate (IDENTIFIER {, ARG});
3812 -- ARG ::= NAME | EXPRESSION
3814 when Pragma_Annotate => Annotate : begin
3816 Check_At_Least_N_Arguments (1);
3817 Check_Arg_Is_Identifier (Arg1);
3820 Arg : Node_Id := Arg2;
3824 while Present (Arg) loop
3825 Exp := Expression (Arg);
3828 if Is_Entity_Name (Exp) then
3831 elsif Nkind (Exp) = N_String_Literal then
3832 Resolve (Exp, Standard_String);
3834 elsif Is_Overloaded (Exp) then
3835 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
3850 -- pragma Assert (Boolean_EXPRESSION [, static_string_EXPRESSION]);
3852 when Pragma_Assert =>
3854 Check_No_Identifiers;
3856 if Arg_Count > 1 then
3857 Check_Arg_Count (2);
3858 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3861 -- If expansion is active and assertions are inactive, then
3862 -- we rewrite the Assertion as:
3864 -- if False and then condition then
3868 -- The reason we do this rewriting during semantic analysis
3869 -- rather than as part of normal expansion is that we cannot
3870 -- analyze and expand the code for the boolean expression
3871 -- directly, or it may cause insertion of actions that would
3872 -- escape the attempt to suppress the assertion code.
3874 if Expander_Active and not Assertions_Enabled then
3876 Make_If_Statement (Loc,
3879 Left_Opnd => New_Occurrence_Of (Standard_False, Loc),
3880 Right_Opnd => Get_Pragma_Arg (Arg1)),
3881 Then_Statements => New_List (
3882 Make_Null_Statement (Loc))));
3886 -- Otherwise (if assertions are enabled, or if we are not
3887 -- operating with expansion active), then we just analyze
3888 -- and resolve the expression.
3891 Analyze_And_Resolve (Expression (Arg1), Any_Boolean);
3898 -- pragma AST_Entry (entry_IDENTIFIER);
3900 when Pragma_AST_Entry => AST_Entry : declare
3906 Check_Arg_Count (1);
3907 Check_No_Identifiers;
3908 Check_Arg_Is_Local_Name (Arg1);
3909 Ent := Entity (Expression (Arg1));
3911 -- Note: the implementation of the AST_Entry pragma could handle
3912 -- the entry family case fine, but for now we are consistent with
3913 -- the DEC rules, and do not allow the pragma, which of course
3914 -- has the effect of also forbidding the attribute.
3916 if Ekind (Ent) /= E_Entry then
3918 ("pragma% argument must be simple entry name", Arg1);
3920 elsif Is_AST_Entry (Ent) then
3922 ("duplicate % pragma for entry", Arg1);
3924 elsif Has_Homonym (Ent) then
3926 ("pragma% argument cannot specify overloaded entry", Arg1);
3930 FF : constant Entity_Id := First_Formal (Ent);
3933 if Present (FF) then
3934 if Present (Next_Formal (FF)) then
3936 ("entry for pragma% can have only one argument",
3939 elsif Parameter_Mode (FF) /= E_In_Parameter then
3941 ("entry parameter for pragma% must have mode IN",
3947 Set_Is_AST_Entry (Ent);
3955 -- pragma Asynchronous (LOCAL_NAME);
3957 when Pragma_Asynchronous => Asynchronous : declare
3965 procedure Process_Async_Pragma;
3966 -- Common processing for procedure and access-to-procedure case
3968 --------------------------
3969 -- Process_Async_Pragma --
3970 --------------------------
3972 procedure Process_Async_Pragma is
3974 if not Present (L) then
3975 Set_Is_Asynchronous (Nm);
3979 -- The formals should be of mode IN (RM E.4.1(6))
3982 while Present (S) loop
3983 Formal := Defining_Identifier (S);
3985 if Nkind (Formal) = N_Defining_Identifier
3986 and then Ekind (Formal) /= E_In_Parameter
3989 ("pragma% procedure can only have IN parameter",
3996 Set_Is_Asynchronous (Nm);
3997 end Process_Async_Pragma;
3999 -- Start of processing for pragma Asynchronous
4002 Check_Ada_83_Warning;
4003 Check_No_Identifiers;
4004 Check_Arg_Count (1);
4005 Check_Arg_Is_Local_Name (Arg1);
4007 if Debug_Flag_U then
4011 C_Ent := Cunit_Entity (Current_Sem_Unit);
4012 Analyze (Expression (Arg1));
4013 Nm := Entity (Expression (Arg1));
4015 if not Is_Remote_Call_Interface (C_Ent)
4016 and then not Is_Remote_Types (C_Ent)
4018 -- This pragma should only appear in an RCI or Remote Types
4019 -- unit (RM E.4.1(4))
4022 ("pragma% not in Remote_Call_Interface or " &
4023 "Remote_Types unit");
4026 if Ekind (Nm) = E_Procedure
4027 and then Nkind (Parent (Nm)) = N_Procedure_Specification
4029 if not Is_Remote_Call_Interface (Nm) then
4031 ("pragma% cannot be applied on non-remote procedure",
4035 L := Parameter_Specifications (Parent (Nm));
4036 Process_Async_Pragma;
4039 elsif Ekind (Nm) = E_Function then
4041 ("pragma% cannot be applied to function", Arg1);
4043 elsif Ekind (Nm) = E_Record_Type
4044 and then Present (Corresponding_Remote_Type (Nm))
4046 N := Declaration_Node (Corresponding_Remote_Type (Nm));
4048 if Nkind (N) = N_Full_Type_Declaration
4049 and then Nkind (Type_Definition (N)) =
4050 N_Access_Procedure_Definition
4052 L := Parameter_Specifications (Type_Definition (N));
4053 Process_Async_Pragma;
4057 ("pragma% cannot reference access-to-function type",
4061 -- Only other possibility is Access-to-class-wide type
4063 elsif Is_Access_Type (Nm)
4064 and then Is_Class_Wide_Type (Designated_Type (Nm))
4066 Check_First_Subtype (Arg1);
4067 Set_Is_Asynchronous (Nm);
4068 if Expander_Active then
4069 RACW_Type_Is_Asynchronous (Nm);
4073 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
4081 -- pragma Atomic (LOCAL_NAME);
4083 when Pragma_Atomic =>
4084 Process_Atomic_Shared_Volatile;
4086 -----------------------
4087 -- Atomic_Components --
4088 -----------------------
4090 -- pragma Atomic_Components (array_LOCAL_NAME);
4092 -- This processing is shared by Volatile_Components
4094 when Pragma_Atomic_Components |
4095 Pragma_Volatile_Components =>
4097 Atomic_Components : declare
4104 Check_Ada_83_Warning;
4105 Check_No_Identifiers;
4106 Check_Arg_Count (1);
4107 Check_Arg_Is_Local_Name (Arg1);
4108 E_Id := Expression (Arg1);
4110 if Etype (E_Id) = Any_Type then
4116 if Rep_Item_Too_Early (E, N)
4118 Rep_Item_Too_Late (E, N)
4123 D := Declaration_Node (E);
4126 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
4128 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
4129 and then Nkind (D) = N_Object_Declaration
4130 and then Nkind (Object_Definition (D)) =
4131 N_Constrained_Array_Definition)
4133 -- The flag is set on the object, or on the base type
4135 if Nkind (D) /= N_Object_Declaration then
4139 Set_Has_Volatile_Components (E);
4141 if Prag_Id = Pragma_Atomic_Components then
4142 Set_Has_Atomic_Components (E);
4144 if Is_Packed (E) then
4145 Set_Is_Packed (E, False);
4148 ("?Pack canceled, cannot pack atomic components",
4154 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
4156 end Atomic_Components;
4158 --------------------
4159 -- Attach_Handler --
4160 --------------------
4162 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
4164 when Pragma_Attach_Handler =>
4165 Check_Ada_83_Warning;
4166 Check_No_Identifiers;
4167 Check_Arg_Count (2);
4169 if No_Run_Time_Mode then
4170 Error_Msg_CRT ("Attach_Handler pragma", N);
4172 Check_Interrupt_Or_Attach_Handler;
4174 -- The expression that designates the attribute may
4175 -- depend on a discriminant, and is therefore a per-
4176 -- object expression, to be expanded in the init proc.
4177 -- If expansion is enabled, perform semantic checks
4180 if Expander_Active then
4182 Temp : Node_Id := New_Copy_Tree (Expression (Arg2));
4184 Set_Parent (Temp, N);
4185 Pre_Analyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
4189 Analyze (Expression (Arg2));
4190 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
4193 Process_Interrupt_Or_Attach_Handler;
4196 --------------------
4197 -- C_Pass_By_Copy --
4198 --------------------
4200 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
4202 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
4208 Check_Valid_Configuration_Pragma;
4209 Check_Arg_Count (1);
4210 Check_Optional_Identifier (Arg1, "max_size");
4212 Arg := Expression (Arg1);
4213 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
4215 Val := Expr_Value (Arg);
4219 ("maximum size for pragma% must be positive", Arg1);
4221 elsif UI_Is_In_Int_Range (Val) then
4222 Default_C_Record_Mechanism := UI_To_Int (Val);
4224 -- If a giant value is given, Int'Last will do well enough.
4225 -- If sometime someone complains that a record larger than
4226 -- two gigabytes is not copied, we will worry about it then!
4229 Default_C_Record_Mechanism := Mechanism_Type'Last;
4237 -- pragma Comment (static_string_EXPRESSION)
4239 -- Processing for pragma Comment shares the circuitry for
4240 -- pragma Ident. The only differences are that Ident enforces
4241 -- a limit of 31 characters on its argument, and also enforces
4242 -- limitations on placement for DEC compatibility. Pragma
4243 -- Comment shares neither of these restrictions.
4249 -- pragma Common_Object (
4250 -- [Internal =>] LOCAL_NAME,
4251 -- [, [External =>] EXTERNAL_SYMBOL]
4252 -- [, [Size =>] EXTERNAL_SYMBOL]);
4254 -- Processing for this pragma is shared with Psect_Object
4256 --------------------------
4257 -- Compile_Time_Warning --
4258 --------------------------
4260 -- pragma Compile_Time_Warning
4261 -- (boolean_EXPRESSION, static_string_EXPRESSION);
4263 when Pragma_Compile_Time_Warning => Compile_Time_Warning : declare
4264 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4268 Check_Arg_Count (2);
4269 Check_No_Identifiers;
4270 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4271 Analyze_And_Resolve (Arg1x, Standard_Boolean);
4273 if Compile_Time_Known_Value (Arg1x) then
4274 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4275 String_To_Name_Buffer (Strval (Get_Pragma_Arg (Arg2)));
4276 Add_Char_To_Name_Buffer ('?');
4279 Msg : String (1 .. Name_Len) :=
4280 Name_Buffer (1 .. Name_Len);
4285 -- This loop looks for multiple lines separated by
4286 -- ASCII.LF and breaks them into continuation error
4287 -- messages marked with the usual back slash.
4290 for S in 2 .. Msg'Length - 1 loop
4291 if Msg (S) = ASCII.LF then
4293 Error_Msg_N (Msg (B .. S), Arg1);
4299 Error_Msg_N (Msg (B .. Msg'Length), Arg1);
4303 end Compile_Time_Warning;
4305 ----------------------------
4306 -- Complex_Representation --
4307 ----------------------------
4309 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
4311 when Pragma_Complex_Representation => Complex_Representation : declare
4318 Check_Arg_Count (1);
4319 Check_Optional_Identifier (Arg1, Name_Entity);
4320 Check_Arg_Is_Local_Name (Arg1);
4321 E_Id := Expression (Arg1);
4323 if Etype (E_Id) = Any_Type then
4329 if not Is_Record_Type (E) then
4331 ("argument for pragma% must be record type", Arg1);
4334 Ent := First_Entity (E);
4337 or else No (Next_Entity (Ent))
4338 or else Present (Next_Entity (Next_Entity (Ent)))
4339 or else not Is_Floating_Point_Type (Etype (Ent))
4340 or else Etype (Ent) /= Etype (Next_Entity (Ent))
4343 ("record for pragma% must have two fields of same fpt type",
4347 Set_Has_Complex_Representation (Base_Type (E));
4349 end Complex_Representation;
4351 -------------------------
4352 -- Component_Alignment --
4353 -------------------------
4355 -- pragma Component_Alignment (
4356 -- [Form =>] ALIGNMENT_CHOICE
4357 -- [, [Name =>] type_LOCAL_NAME]);
4359 -- ALIGNMENT_CHOICE ::=
4361 -- | Component_Size_4
4365 when Pragma_Component_Alignment => Component_AlignmentP : declare
4366 Args : Args_List (1 .. 2);
4367 Names : constant Name_List (1 .. 2) := (
4371 Form : Node_Id renames Args (1);
4372 Name : Node_Id renames Args (2);
4374 Atype : Component_Alignment_Kind;
4379 Gather_Associations (Names, Args);
4382 Error_Pragma ("missing Form argument for pragma%");
4385 Check_Arg_Is_Identifier (Form);
4387 -- Get proper alignment, note that Default = Component_Size
4388 -- on all machines we have so far, and we want to set this
4389 -- value rather than the default value to indicate that it
4390 -- has been explicitly set (and thus will not get overridden
4391 -- by the default component alignment for the current scope)
4393 if Chars (Form) = Name_Component_Size then
4394 Atype := Calign_Component_Size;
4396 elsif Chars (Form) = Name_Component_Size_4 then
4397 Atype := Calign_Component_Size_4;
4399 elsif Chars (Form) = Name_Default then
4400 Atype := Calign_Component_Size;
4402 elsif Chars (Form) = Name_Storage_Unit then
4403 Atype := Calign_Storage_Unit;
4407 ("invalid Form parameter for pragma%", Form);
4410 -- Case with no name, supplied, affects scope table entry
4414 (Scope_Stack.Last).Component_Alignment_Default := Atype;
4416 -- Case of name supplied
4419 Check_Arg_Is_Local_Name (Name);
4421 Typ := Entity (Name);
4424 or else Rep_Item_Too_Early (Typ, N)
4428 Typ := Underlying_Type (Typ);
4431 if not Is_Record_Type (Typ)
4432 and then not Is_Array_Type (Typ)
4435 ("Name parameter of pragma% must identify record or " &
4436 "array type", Name);
4439 -- An explicit Component_Alignment pragma overrides an
4440 -- implicit pragma Pack, but not an explicit one.
4442 if not Has_Pragma_Pack (Base_Type (Typ)) then
4443 Set_Is_Packed (Base_Type (Typ), False);
4444 Set_Component_Alignment (Base_Type (Typ), Atype);
4447 end Component_AlignmentP;
4453 -- pragma Controlled (first_subtype_LOCAL_NAME);
4455 when Pragma_Controlled => Controlled : declare
4459 Check_No_Identifiers;
4460 Check_Arg_Count (1);
4461 Check_Arg_Is_Local_Name (Arg1);
4462 Arg := Expression (Arg1);
4464 if not Is_Entity_Name (Arg)
4465 or else not Is_Access_Type (Entity (Arg))
4467 Error_Pragma_Arg ("pragma% requires access type", Arg1);
4469 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
4477 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
4478 -- [Entity =>] LOCAL_NAME);
4480 when Pragma_Convention => Convention : declare
4485 Check_Ada_83_Warning;
4486 Check_Arg_Count (2);
4487 Process_Convention (C, E);
4490 ---------------------------
4491 -- Convention_Identifier --
4492 ---------------------------
4494 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
4495 -- [Convention =>] convention_IDENTIFIER);
4497 when Pragma_Convention_Identifier => Convention_Identifier : declare
4503 Check_Arg_Count (2);
4504 Check_Optional_Identifier (Arg1, Name_Name);
4505 Check_Optional_Identifier (Arg2, Name_Convention);
4506 Check_Arg_Is_Identifier (Arg1);
4507 Check_Arg_Is_Identifier (Arg1);
4508 Idnam := Chars (Expression (Arg1));
4509 Cname := Chars (Expression (Arg2));
4511 if Is_Convention_Name (Cname) then
4512 Record_Convention_Identifier
4513 (Idnam, Get_Convention_Id (Cname));
4516 ("second arg for % pragma must be convention", Arg2);
4518 end Convention_Identifier;
4524 -- pragma CPP_Class ([Entity =>] local_NAME)
4526 when Pragma_CPP_Class => CPP_Class : declare
4529 Default_DTC : Entity_Id := Empty;
4530 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4536 Check_Arg_Count (1);
4537 Check_Optional_Identifier (Arg1, Name_Entity);
4538 Check_Arg_Is_Local_Name (Arg1);
4540 Arg := Expression (Arg1);
4543 if Etype (Arg) = Any_Type then
4547 if not Is_Entity_Name (Arg)
4548 or else not Is_Type (Entity (Arg))
4550 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
4553 Typ := Entity (Arg);
4555 if not Is_Record_Type (Typ) then
4556 Error_Pragma_Arg ("pragma% applicable to a record, "
4557 & "tagged record or record extension", Arg1);
4560 Default_DTC := First_Component (Typ);
4561 while Present (Default_DTC)
4562 and then Etype (Default_DTC) /= VTP_Type
4564 Next_Component (Default_DTC);
4567 -- Case of non tagged type
4569 if not Is_Tagged_Type (Typ) then
4570 Set_Is_CPP_Class (Typ);
4572 if Present (Default_DTC) then
4574 ("only tagged records can contain vtable pointers", Arg1);
4577 -- Case of tagged type with no vtable ptr
4579 -- What is test for Typ = Root_Typ (Typ) about here ???
4581 elsif Is_Tagged_Type (Typ)
4582 and then Typ = Root_Type (Typ)
4583 and then No (Default_DTC)
4586 ("a cpp_class must contain a vtable pointer", Arg1);
4588 -- Tagged type that has a vtable ptr
4590 elsif Present (Default_DTC) then
4591 Set_Is_CPP_Class (Typ);
4592 Set_Is_Limited_Record (Typ);
4593 Set_Is_Tag (Default_DTC);
4594 Set_DT_Entry_Count (Default_DTC, No_Uint);
4596 -- Since a CPP type has no direct link to its associated tag
4597 -- most tags checks cannot be performed
4599 Set_Kill_Tag_Checks (Typ);
4600 Set_Kill_Tag_Checks (Class_Wide_Type (Typ));
4602 -- Get rid of the _tag component when there was one.
4603 -- It is only useful for regular tagged types
4605 if Expander_Active and then Typ = Root_Type (Typ) then
4607 Tag_C := Tag_Component (Typ);
4608 C := First_Entity (Typ);
4611 Set_First_Entity (Typ, Next_Entity (Tag_C));
4614 while Next_Entity (C) /= Tag_C loop
4618 Set_Next_Entity (C, Next_Entity (Tag_C));
4624 ---------------------
4625 -- CPP_Constructor --
4626 ---------------------
4628 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME);
4630 when Pragma_CPP_Constructor => CPP_Constructor : declare
4636 Check_Arg_Count (1);
4637 Check_Optional_Identifier (Arg1, Name_Entity);
4638 Check_Arg_Is_Local_Name (Arg1);
4640 Id := Expression (Arg1);
4641 Find_Program_Unit_Name (Id);
4643 -- If we did not find the name, we are done
4645 if Etype (Id) = Any_Type then
4649 Def_Id := Entity (Id);
4651 if Ekind (Def_Id) = E_Function
4652 and then Is_Class_Wide_Type (Etype (Def_Id))
4653 and then Is_CPP_Class (Etype (Etype (Def_Id)))
4655 -- What the heck is this??? this pragma allows only 1 arg
4657 if Arg_Count >= 2 then
4658 Check_At_Most_N_Arguments (3);
4659 Process_Interface_Name (Def_Id, Arg2, Arg3);
4662 if No (Parameter_Specifications (Parent (Def_Id))) then
4663 Set_Has_Completion (Def_Id);
4664 Set_Is_Constructor (Def_Id);
4667 ("non-default constructors not implemented", Arg1);
4672 ("pragma% requires function returning a 'C'P'P_Class type",
4675 end CPP_Constructor;
4681 -- pragma CPP_Virtual
4682 -- [Entity =>] LOCAL_NAME
4683 -- [ [Vtable_Ptr =>] LOCAL_NAME,
4684 -- [Position =>] static_integer_EXPRESSION]);
4686 when Pragma_CPP_Virtual => CPP_Virtual : declare
4690 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4697 if Arg_Count = 3 then
4698 Check_Optional_Identifier (Arg2, "vtable_ptr");
4700 -- We allow Entry_Count as well as Position for the third
4701 -- parameter for back compatibility with versions of GNAT
4702 -- before version 3.12. The documentation has always said
4703 -- Position, but the code up to 3.12 said Entry_Count.
4705 if Chars (Arg3) /= Name_Position then
4706 Check_Optional_Identifier (Arg3, "entry_count");
4710 Check_Arg_Count (1);
4713 Check_Optional_Identifier (Arg1, Name_Entity);
4714 Check_Arg_Is_Local_Name (Arg1);
4716 -- First argument must be a subprogram name
4718 Arg := Expression (Arg1);
4719 Find_Program_Unit_Name (Arg);
4721 if Etype (Arg) = Any_Type then
4724 Subp := Entity (Arg);
4727 if not (Is_Subprogram (Subp)
4728 and then Is_Dispatching_Operation (Subp))
4731 ("pragma% must reference a primitive operation", Arg1);
4734 Typ := Find_Dispatching_Type (Subp);
4736 -- If only one Argument defaults are :
4737 -- . DTC_Entity is the default Vtable pointer
4738 -- . DT_Position will be set at the freezing point
4740 if Arg_Count = 1 then
4741 Set_DTC_Entity (Subp, Tag_Component (Typ));
4745 -- Second argument is a component name of type Vtable_Ptr
4747 Arg := Expression (Arg2);
4749 if Nkind (Arg) /= N_Identifier then
4750 Error_Msg_NE ("must be a& component name", Arg, Typ);
4754 DTC := First_Component (Typ);
4755 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4756 Next_Component (DTC);
4760 Error_Msg_NE ("must be a& component name", Arg, Typ);
4763 elsif Etype (DTC) /= VTP_Type then
4764 Wrong_Type (Arg, VTP_Type);
4768 -- Third argument is an integer (DT_Position)
4770 Arg := Expression (Arg3);
4771 Analyze_And_Resolve (Arg, Any_Integer);
4773 if not Is_Static_Expression (Arg) then
4774 Flag_Non_Static_Expr
4775 ("third argument of pragma CPP_Virtual must be static!",
4780 V := Expr_Value (Expression (Arg3));
4784 ("third argument of pragma% must be positive",
4788 Set_DTC_Entity (Subp, DTC);
4789 Set_DT_Position (Subp, V);
4798 -- pragma CPP_Vtable (
4799 -- [Entity =>] LOCAL_NAME
4800 -- [Vtable_Ptr =>] LOCAL_NAME,
4801 -- [Entry_Count =>] static_integer_EXPRESSION);
4803 when Pragma_CPP_Vtable => CPP_Vtable : declare
4806 VTP_Type : constant Entity_Id := RTE (RE_Vtable_Ptr);
4813 Check_Arg_Count (3);
4814 Check_Optional_Identifier (Arg1, Name_Entity);
4815 Check_Optional_Identifier (Arg2, "vtable_ptr");
4816 Check_Optional_Identifier (Arg3, "entry_count");
4817 Check_Arg_Is_Local_Name (Arg1);
4819 -- First argument is a record type name
4821 Arg := Expression (Arg1);
4824 if Etype (Arg) = Any_Type then
4827 Typ := Entity (Arg);
4830 if not (Is_Tagged_Type (Typ) and then Is_CPP_Class (Typ)) then
4831 Error_Pragma_Arg ("'C'P'P_Class tagged type expected", Arg1);
4834 -- Second argument is a component name of type Vtable_Ptr
4836 Arg := Expression (Arg2);
4838 if Nkind (Arg) /= N_Identifier then
4839 Error_Msg_NE ("must be a& component name", Arg, Typ);
4843 DTC := First_Component (Typ);
4844 while Present (DTC) and then Chars (DTC) /= Chars (Arg) loop
4845 Next_Component (DTC);
4849 Error_Msg_NE ("must be a& component name", Arg, Typ);
4852 elsif Etype (DTC) /= VTP_Type then
4853 Wrong_Type (DTC, VTP_Type);
4856 -- If it is the first pragma Vtable, This becomes the default tag
4858 elsif (not Is_Tag (DTC))
4859 and then DT_Entry_Count (Tag_Component (Typ)) = No_Uint
4861 Set_Is_Tag (Tag_Component (Typ), False);
4862 Set_Is_Tag (DTC, True);
4863 Set_DT_Entry_Count (DTC, No_Uint);
4866 -- Those pragmas must appear before any primitive operation
4867 -- definition (except inherited ones) otherwise the default
4870 Elmt := First_Elmt (Primitive_Operations (Typ));
4871 while Present (Elmt) loop
4872 if No (Alias (Node (Elmt))) then
4873 Error_Msg_Sloc := Sloc (Node (Elmt));
4875 ("pragma% must appear before this primitive operation");
4881 -- Third argument is an integer (DT_Entry_Count)
4883 Arg := Expression (Arg3);
4884 Analyze_And_Resolve (Arg, Any_Integer);
4886 if not Is_Static_Expression (Arg) then
4887 Flag_Non_Static_Expr
4888 ("entry count for pragma CPP_Vtable must be a static " &
4889 "expression!", Arg3);
4893 V := Expr_Value (Expression (Arg3));
4897 ("entry count for pragma% must be positive", Arg3);
4899 Set_DT_Entry_Count (DTC, V);
4908 -- pragma Debug (PROCEDURE_CALL_STATEMENT);
4910 when Pragma_Debug => Debug : begin
4913 -- If assertions are enabled, and we are expanding code, then
4914 -- we rewrite the pragma with its corresponding procedure call
4915 -- and then analyze the call.
4917 if Assertions_Enabled and Expander_Active then
4918 Rewrite (N, Relocate_Node (Debug_Statement (N)));
4921 -- Otherwise we work a bit to get a tree that makes sense
4922 -- for ASIS purposes, namely a pragma with an analyzed
4923 -- argument that looks like a procedure call.
4926 Expander_Mode_Save_And_Set (False);
4927 Rewrite (N, Relocate_Node (Debug_Statement (N)));
4931 Chars => Name_Debug,
4932 Pragma_Argument_Associations =>
4933 New_List (Relocate_Node (N))));
4934 Expander_Mode_Restore;
4942 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
4944 when Pragma_Discard_Names => Discard_Names : declare
4949 Check_Ada_83_Warning;
4951 -- Deal with configuration pragma case
4953 if Arg_Count = 0 and then Is_Configuration_Pragma then
4954 Global_Discard_Names := True;
4957 -- Otherwise, check correct appropriate context
4960 Check_Is_In_Decl_Part_Or_Package_Spec;
4962 if Arg_Count = 0 then
4964 -- If there is no parameter, then from now on this pragma
4965 -- applies to any enumeration, exception or tagged type
4966 -- defined in the current declarative part.
4968 Set_Discard_Names (Current_Scope);
4972 Check_Arg_Count (1);
4973 Check_Optional_Identifier (Arg1, Name_On);
4974 Check_Arg_Is_Local_Name (Arg1);
4975 E_Id := Expression (Arg1);
4977 if Etype (E_Id) = Any_Type then
4983 if (Is_First_Subtype (E)
4984 and then (Is_Enumeration_Type (E)
4985 or else Is_Tagged_Type (E)))
4986 or else Ekind (E) = E_Exception
4988 Set_Discard_Names (E);
4991 ("inappropriate entity for pragma%", Arg1);
5001 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
5003 when Pragma_Elaborate => Elaborate : declare
5005 Parent_Node : Node_Id;
5010 -- Pragma must be in context items list of a compilation unit
5012 if not Is_List_Member (N) then
5017 Plist := List_Containing (N);
5018 Parent_Node := Parent (Plist);
5020 if Parent_Node = Empty
5021 or else Nkind (Parent_Node) /= N_Compilation_Unit
5022 or else Context_Items (Parent_Node) /= Plist
5029 -- Must be at least one argument
5031 if Arg_Count = 0 then
5032 Error_Pragma ("pragma% requires at least one argument");
5035 -- In Ada 83 mode, there can be no items following it in the
5036 -- context list except other pragmas and implicit with clauses
5037 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
5038 -- placement rule does not apply.
5040 if Ada_83 and then Comes_From_Source (N) then
5043 while Present (Citem) loop
5044 if Nkind (Citem) = N_Pragma
5045 or else (Nkind (Citem) = N_With_Clause
5046 and then Implicit_With (Citem))
5051 ("(Ada 83) pragma% must be at end of context clause");
5058 -- Finally, the arguments must all be units mentioned in a with
5059 -- clause in the same context clause. Note we already checked
5060 -- (in Par.Prag) that the arguments are either identifiers or
5063 Outer : while Present (Arg) loop
5064 Citem := First (Plist);
5066 Inner : while Citem /= N loop
5067 if Nkind (Citem) = N_With_Clause
5068 and then Same_Name (Name (Citem), Expression (Arg))
5070 Set_Elaborate_Present (Citem, True);
5071 Set_Unit_Name (Expression (Arg), Name (Citem));
5072 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5081 ("argument of pragma% is not with'ed unit", Arg);
5087 -- Give a warning if operating in static mode with -gnatwl
5088 -- (elaboration warnings eanbled) switch set.
5090 if Elab_Warnings and not Dynamic_Elaboration_Checks then
5092 ("?use of pragma Elaborate may not be safe", N);
5094 ("?use pragma Elaborate_All instead if possible", N);
5102 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
5104 when Pragma_Elaborate_All => Elaborate_All : declare
5106 Parent_Node : Node_Id;
5111 Check_Ada_83_Warning;
5113 -- Pragma must be in context items list of a compilation unit
5115 if not Is_List_Member (N) then
5120 Plist := List_Containing (N);
5121 Parent_Node := Parent (Plist);
5123 if Parent_Node = Empty
5124 or else Nkind (Parent_Node) /= N_Compilation_Unit
5125 or else Context_Items (Parent_Node) /= Plist
5132 -- Must be at least one argument
5134 if Arg_Count = 0 then
5135 Error_Pragma ("pragma% requires at least one argument");
5138 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
5139 -- have to appear at the end of the context clause, but may
5140 -- appear mixed in with other items, even in Ada 83 mode.
5142 -- Final check: the arguments must all be units mentioned in
5143 -- a with clause in the same context clause. Note that we
5144 -- already checked (in Par.Prag) that all the arguments are
5145 -- either identifiers or selected components.
5148 Outr : while Present (Arg) loop
5149 Citem := First (Plist);
5151 Innr : while Citem /= N loop
5152 if Nkind (Citem) = N_With_Clause
5153 and then Same_Name (Name (Citem), Expression (Arg))
5155 Set_Elaborate_All_Present (Citem, True);
5156 Set_Unit_Name (Expression (Arg), Name (Citem));
5157 Set_Suppress_Elaboration_Warnings (Entity (Name (Citem)));
5165 Set_Error_Posted (N);
5167 ("argument of pragma% is not with'ed unit", Arg);
5174 --------------------
5175 -- Elaborate_Body --
5176 --------------------
5178 -- pragma Elaborate_Body [( library_unit_NAME )];
5180 when Pragma_Elaborate_Body => Elaborate_Body : declare
5181 Cunit_Node : Node_Id;
5182 Cunit_Ent : Entity_Id;
5185 Check_Ada_83_Warning;
5186 Check_Valid_Library_Unit_Pragma;
5188 if Nkind (N) = N_Null_Statement then
5192 Cunit_Node := Cunit (Current_Sem_Unit);
5193 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
5195 if Nkind (Unit (Cunit_Node)) = N_Package_Body
5197 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
5199 Error_Pragma ("pragma% must refer to a spec, not a body");
5201 Set_Body_Required (Cunit_Node, True);
5202 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
5204 -- If we are in dynamic elaboration mode, then we suppress
5205 -- elaboration warnings for the unit, since it is definitely
5206 -- fine NOT to do dynamic checks at the first level (and such
5207 -- checks will be suppressed because no elaboration boolean
5208 -- is created for Elaborate_Body packages).
5210 -- But in the static model of elaboration, Elaborate_Body is
5211 -- definitely NOT good enough to ensure elaboration safety on
5212 -- its own, since the body may WITH other units that are not
5213 -- safe from an elaboration point of view, so a client must
5214 -- still do an Elaborate_All on such units.
5216 -- Debug flag -gnatdD restores the old behavior of 3.13,
5217 -- where Elaborate_Body always suppressed elab warnings.
5219 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
5220 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
5225 ------------------------
5226 -- Elaboration_Checks --
5227 ------------------------
5229 -- pragma Elaboration_Checks (Static | Dynamic);
5231 when Pragma_Elaboration_Checks =>
5233 Check_Arg_Count (1);
5234 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
5235 Dynamic_Elaboration_Checks :=
5236 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
5242 -- pragma Eliminate (
5243 -- [Unit_Name =>] IDENTIFIER |
5244 -- SELECTED_COMPONENT
5245 -- [,[Entity =>] IDENTIFIER |
5246 -- SELECTED_COMPONENT |
5248 -- [,[Parameter_Types =>] PARAMETER_TYPES]
5249 -- [,[Result_Type =>] result_SUBTYPE_NAME]
5250 -- [,[Homonym_Number =>] INTEGER_LITERAL]);
5252 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
5253 -- SUBTYPE_NAME ::= STRING_LITERAL
5255 when Pragma_Eliminate => Eliminate : declare
5256 Args : Args_List (1 .. 5);
5257 Names : constant Name_List (1 .. 5) := (
5260 Name_Parameter_Types,
5262 Name_Homonym_Number);
5264 Unit_Name : Node_Id renames Args (1);
5265 Entity : Node_Id renames Args (2);
5266 Parameter_Types : Node_Id renames Args (3);
5267 Result_Type : Node_Id renames Args (4);
5268 Homonym_Number : Node_Id renames Args (5);
5272 Check_Valid_Configuration_Pragma;
5273 Gather_Associations (Names, Args);
5275 if No (Unit_Name) then
5276 Error_Pragma ("missing Unit_Name argument for pragma%");
5280 and then (Present (Parameter_Types)
5282 Present (Result_Type)
5284 Present (Homonym_Number))
5286 Error_Pragma ("missing Entity argument for pragma%");
5289 Process_Eliminate_Pragma
5297 --------------------------
5298 -- Explicit_Overriding --
5299 --------------------------
5301 when Pragma_Explicit_Overriding =>
5302 Check_Valid_Configuration_Pragma;
5303 Check_Arg_Count (0);
5304 Explicit_Overriding := True;
5311 -- [ Convention =>] convention_IDENTIFIER,
5312 -- [ Entity =>] local_NAME
5313 -- [, [External_Name =>] static_string_EXPRESSION ]
5314 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5316 when Pragma_Export => Export : declare
5321 Check_Ada_83_Warning;
5322 Check_At_Least_N_Arguments (2);
5323 Check_At_Most_N_Arguments (4);
5324 Process_Convention (C, Def_Id);
5326 if Ekind (Def_Id) /= E_Constant then
5327 Note_Possible_Modification (Expression (Arg2));
5330 Process_Interface_Name (Def_Id, Arg3, Arg4);
5331 Set_Exported (Def_Id, Arg2);
5334 ----------------------
5335 -- Export_Exception --
5336 ----------------------
5338 -- pragma Export_Exception (
5339 -- [Internal =>] LOCAL_NAME,
5340 -- [, [External =>] EXTERNAL_SYMBOL,]
5341 -- [, [Form =>] Ada | VMS]
5342 -- [, [Code =>] static_integer_EXPRESSION]);
5344 when Pragma_Export_Exception => Export_Exception : declare
5345 Args : Args_List (1 .. 4);
5346 Names : constant Name_List (1 .. 4) := (
5352 Internal : Node_Id renames Args (1);
5353 External : Node_Id renames Args (2);
5354 Form : Node_Id renames Args (3);
5355 Code : Node_Id renames Args (4);
5358 if Inside_A_Generic then
5359 Error_Pragma ("pragma% cannot be used for generic entities");
5362 Gather_Associations (Names, Args);
5363 Process_Extended_Import_Export_Exception_Pragma (
5364 Arg_Internal => Internal,
5365 Arg_External => External,
5369 if not Is_VMS_Exception (Entity (Internal)) then
5370 Set_Exported (Entity (Internal), Internal);
5372 end Export_Exception;
5374 ---------------------
5375 -- Export_Function --
5376 ---------------------
5378 -- pragma Export_Function (
5379 -- [Internal =>] LOCAL_NAME,
5380 -- [, [External =>] EXTERNAL_SYMBOL,]
5381 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5382 -- [, [Result_Type =>] TYPE_DESIGNATOR]
5383 -- [, [Mechanism =>] MECHANISM]
5384 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
5386 -- EXTERNAL_SYMBOL ::=
5388 -- | static_string_EXPRESSION
5390 -- PARAMETER_TYPES ::=
5392 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5394 -- TYPE_DESIGNATOR ::=
5396 -- | subtype_Name ' Access
5400 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5402 -- MECHANISM_ASSOCIATION ::=
5403 -- [formal_parameter_NAME =>] MECHANISM_NAME
5405 -- MECHANISM_NAME ::=
5408 -- | Descriptor [([Class =>] CLASS_NAME)]
5410 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5412 when Pragma_Export_Function => Export_Function : declare
5413 Args : Args_List (1 .. 6);
5414 Names : constant Name_List (1 .. 6) := (
5417 Name_Parameter_Types,
5420 Name_Result_Mechanism);
5422 Internal : Node_Id renames Args (1);
5423 External : Node_Id renames Args (2);
5424 Parameter_Types : Node_Id renames Args (3);
5425 Result_Type : Node_Id renames Args (4);
5426 Mechanism : Node_Id renames Args (5);
5427 Result_Mechanism : Node_Id renames Args (6);
5431 Gather_Associations (Names, Args);
5432 Process_Extended_Import_Export_Subprogram_Pragma (
5433 Arg_Internal => Internal,
5434 Arg_External => External,
5435 Arg_Parameter_Types => Parameter_Types,
5436 Arg_Result_Type => Result_Type,
5437 Arg_Mechanism => Mechanism,
5438 Arg_Result_Mechanism => Result_Mechanism);
5439 end Export_Function;
5445 -- pragma Export_Object (
5446 -- [Internal =>] LOCAL_NAME,
5447 -- [, [External =>] EXTERNAL_SYMBOL]
5448 -- [, [Size =>] EXTERNAL_SYMBOL]);
5450 -- EXTERNAL_SYMBOL ::=
5452 -- | static_string_EXPRESSION
5454 -- PARAMETER_TYPES ::=
5456 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5458 -- TYPE_DESIGNATOR ::=
5460 -- | subtype_Name ' Access
5464 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5466 -- MECHANISM_ASSOCIATION ::=
5467 -- [formal_parameter_NAME =>] MECHANISM_NAME
5469 -- MECHANISM_NAME ::=
5472 -- | Descriptor [([Class =>] CLASS_NAME)]
5474 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5476 when Pragma_Export_Object => Export_Object : declare
5477 Args : Args_List (1 .. 3);
5478 Names : constant Name_List (1 .. 3) := (
5483 Internal : Node_Id renames Args (1);
5484 External : Node_Id renames Args (2);
5485 Size : Node_Id renames Args (3);
5489 Gather_Associations (Names, Args);
5490 Process_Extended_Import_Export_Object_Pragma (
5491 Arg_Internal => Internal,
5492 Arg_External => External,
5496 ----------------------
5497 -- Export_Procedure --
5498 ----------------------
5500 -- pragma Export_Procedure (
5501 -- [Internal =>] LOCAL_NAME,
5502 -- [, [External =>] EXTERNAL_SYMBOL,]
5503 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5504 -- [, [Mechanism =>] MECHANISM]);
5506 -- EXTERNAL_SYMBOL ::=
5508 -- | static_string_EXPRESSION
5510 -- PARAMETER_TYPES ::=
5512 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5514 -- TYPE_DESIGNATOR ::=
5516 -- | subtype_Name ' Access
5520 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5522 -- MECHANISM_ASSOCIATION ::=
5523 -- [formal_parameter_NAME =>] MECHANISM_NAME
5525 -- MECHANISM_NAME ::=
5528 -- | Descriptor [([Class =>] CLASS_NAME)]
5530 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5532 when Pragma_Export_Procedure => Export_Procedure : declare
5533 Args : Args_List (1 .. 4);
5534 Names : constant Name_List (1 .. 4) := (
5537 Name_Parameter_Types,
5540 Internal : Node_Id renames Args (1);
5541 External : Node_Id renames Args (2);
5542 Parameter_Types : Node_Id renames Args (3);
5543 Mechanism : Node_Id renames Args (4);
5547 Gather_Associations (Names, Args);
5548 Process_Extended_Import_Export_Subprogram_Pragma (
5549 Arg_Internal => Internal,
5550 Arg_External => External,
5551 Arg_Parameter_Types => Parameter_Types,
5552 Arg_Mechanism => Mechanism);
5553 end Export_Procedure;
5559 -- pragma Export_Value (
5560 -- [Value =>] static_integer_EXPRESSION,
5561 -- [Link_Name =>] static_string_EXPRESSION);
5563 when Pragma_Export_Value =>
5565 Check_Arg_Count (2);
5567 Check_Optional_Identifier (Arg1, Name_Value);
5568 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
5570 Check_Optional_Identifier (Arg2, Name_Link_Name);
5571 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
5573 -----------------------------
5574 -- Export_Valued_Procedure --
5575 -----------------------------
5577 -- pragma Export_Valued_Procedure (
5578 -- [Internal =>] LOCAL_NAME,
5579 -- [, [External =>] EXTERNAL_SYMBOL,]
5580 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
5581 -- [, [Mechanism =>] MECHANISM]);
5583 -- EXTERNAL_SYMBOL ::=
5585 -- | static_string_EXPRESSION
5587 -- PARAMETER_TYPES ::=
5589 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
5591 -- TYPE_DESIGNATOR ::=
5593 -- | subtype_Name ' Access
5597 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
5599 -- MECHANISM_ASSOCIATION ::=
5600 -- [formal_parameter_NAME =>] MECHANISM_NAME
5602 -- MECHANISM_NAME ::=
5605 -- | Descriptor [([Class =>] CLASS_NAME)]
5607 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5609 when Pragma_Export_Valued_Procedure =>
5610 Export_Valued_Procedure : declare
5611 Args : Args_List (1 .. 4);
5612 Names : constant Name_List (1 .. 4) := (
5615 Name_Parameter_Types,
5618 Internal : Node_Id renames Args (1);
5619 External : Node_Id renames Args (2);
5620 Parameter_Types : Node_Id renames Args (3);
5621 Mechanism : Node_Id renames Args (4);
5625 Gather_Associations (Names, Args);
5626 Process_Extended_Import_Export_Subprogram_Pragma (
5627 Arg_Internal => Internal,
5628 Arg_External => External,
5629 Arg_Parameter_Types => Parameter_Types,
5630 Arg_Mechanism => Mechanism);
5631 end Export_Valued_Procedure;
5637 -- pragma Extend_System ([Name =>] Identifier);
5639 when Pragma_Extend_System => Extend_System : declare
5642 Check_Valid_Configuration_Pragma;
5643 Check_Arg_Count (1);
5644 Check_Optional_Identifier (Arg1, Name_Name);
5645 Check_Arg_Is_Identifier (Arg1);
5647 Get_Name_String (Chars (Expression (Arg1)));
5650 and then Name_Buffer (1 .. 4) = "aux_"
5652 if Present (System_Extend_Pragma_Arg) then
5653 if Chars (Expression (Arg1)) =
5654 Chars (Expression (System_Extend_Pragma_Arg))
5658 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
5659 Error_Pragma ("pragma% conflicts with that at#");
5663 System_Extend_Pragma_Arg := Arg1;
5665 if not GNAT_Mode then
5666 System_Extend_Unit := Arg1;
5670 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
5674 ------------------------
5675 -- Extensions_Allowed --
5676 ------------------------
5678 -- pragma Extensions_Allowed (ON | OFF);
5680 when Pragma_Extensions_Allowed =>
5682 Check_Arg_Count (1);
5683 Check_No_Identifiers;
5684 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5685 Extensions_Allowed := (Chars (Expression (Arg1)) = Name_On);
5691 -- pragma External (
5692 -- [ Convention =>] convention_IDENTIFIER,
5693 -- [ Entity =>] local_NAME
5694 -- [, [External_Name =>] static_string_EXPRESSION ]
5695 -- [, [Link_Name =>] static_string_EXPRESSION ]);
5697 when Pragma_External => External : declare
5703 Check_At_Least_N_Arguments (2);
5704 Check_At_Most_N_Arguments (4);
5705 Process_Convention (C, Def_Id);
5706 Note_Possible_Modification (Expression (Arg2));
5707 Process_Interface_Name (Def_Id, Arg3, Arg4);
5708 Set_Exported (Def_Id, Arg2);
5711 --------------------------
5712 -- External_Name_Casing --
5713 --------------------------
5715 -- pragma External_Name_Casing (
5716 -- UPPERCASE | LOWERCASE
5717 -- [, AS_IS | UPPERCASE | LOWERCASE]);
5719 when Pragma_External_Name_Casing =>
5721 External_Name_Casing : declare
5724 Check_No_Identifiers;
5726 if Arg_Count = 2 then
5728 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
5730 case Chars (Get_Pragma_Arg (Arg2)) is
5732 Opt.External_Name_Exp_Casing := As_Is;
5734 when Name_Uppercase =>
5735 Opt.External_Name_Exp_Casing := Uppercase;
5737 when Name_Lowercase =>
5738 Opt.External_Name_Exp_Casing := Lowercase;
5745 Check_Arg_Count (1);
5748 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
5750 case Chars (Get_Pragma_Arg (Arg1)) is
5751 when Name_Uppercase =>
5752 Opt.External_Name_Imp_Casing := Uppercase;
5754 when Name_Lowercase =>
5755 Opt.External_Name_Imp_Casing := Lowercase;
5760 end External_Name_Casing;
5762 ---------------------------
5763 -- Finalize_Storage_Only --
5764 ---------------------------
5766 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
5768 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
5769 Assoc : constant Node_Id := Arg1;
5770 Type_Id : constant Node_Id := Expression (Assoc);
5774 Check_No_Identifiers;
5775 Check_Arg_Count (1);
5776 Check_Arg_Is_Local_Name (Arg1);
5778 Find_Type (Type_Id);
5779 Typ := Entity (Type_Id);
5782 or else Rep_Item_Too_Early (Typ, N)
5786 Typ := Underlying_Type (Typ);
5789 if not Is_Controlled (Typ) then
5790 Error_Pragma ("pragma% must specify controlled type");
5793 Check_First_Subtype (Arg1);
5795 if Finalize_Storage_Only (Typ) then
5796 Error_Pragma ("duplicate pragma%, only one allowed");
5798 elsif not Rep_Item_Too_Late (Typ, N) then
5799 Set_Finalize_Storage_Only (Base_Type (Typ), True);
5801 end Finalize_Storage;
5803 --------------------------
5804 -- Float_Representation --
5805 --------------------------
5807 -- pragma Float_Representation (VAX_Float | IEEE_Float);
5809 when Pragma_Float_Representation => Float_Representation : declare
5817 if Arg_Count = 1 then
5818 Check_Valid_Configuration_Pragma;
5820 Check_Arg_Count (2);
5821 Check_Optional_Identifier (Arg2, Name_Entity);
5822 Check_Arg_Is_Local_Name (Arg2);
5825 Check_No_Identifier (Arg1);
5826 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
5828 if not OpenVMS_On_Target then
5829 if Chars (Expression (Arg1)) = Name_VAX_Float then
5831 ("?pragma% ignored (applies only to Open'V'M'S)");
5837 -- One argument case
5839 if Arg_Count = 1 then
5841 if Chars (Expression (Arg1)) = Name_VAX_Float then
5843 if Opt.Float_Format = 'I' then
5844 Error_Pragma ("'I'E'E'E format previously specified");
5847 Opt.Float_Format := 'V';
5850 if Opt.Float_Format = 'V' then
5851 Error_Pragma ("'V'A'X format previously specified");
5854 Opt.Float_Format := 'I';
5857 Set_Standard_Fpt_Formats;
5859 -- Two argument case
5862 Argx := Get_Pragma_Arg (Arg2);
5864 if not Is_Entity_Name (Argx)
5865 or else not Is_Floating_Point_Type (Entity (Argx))
5868 ("second argument of% pragma must be floating-point type",
5872 Ent := Entity (Argx);
5873 Digs := UI_To_Int (Digits_Value (Ent));
5875 -- Two arguments, VAX_Float case
5877 if Chars (Expression (Arg1)) = Name_VAX_Float then
5880 when 6 => Set_F_Float (Ent);
5881 when 9 => Set_D_Float (Ent);
5882 when 15 => Set_G_Float (Ent);
5886 ("wrong digits value, must be 6,9 or 15", Arg2);
5889 -- Two arguments, IEEE_Float case
5893 when 6 => Set_IEEE_Short (Ent);
5894 when 15 => Set_IEEE_Long (Ent);
5898 ("wrong digits value, must be 6 or 15", Arg2);
5902 end Float_Representation;
5908 -- pragma Ident (static_string_EXPRESSION)
5910 -- Note: pragma Comment shares this processing. Pragma Comment
5911 -- is identical to Ident, except that the restriction of the
5912 -- argument to 31 characters and the placement restrictions
5913 -- are not enforced for pragma Comment.
5915 when Pragma_Ident | Pragma_Comment => Ident : declare
5920 Check_Arg_Count (1);
5921 Check_No_Identifiers;
5922 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
5924 -- For pragma Ident, preserve DEC compatibility by requiring
5925 -- the pragma to appear in a declarative part or package spec.
5927 if Prag_Id = Pragma_Ident then
5928 Check_Is_In_Decl_Part_Or_Package_Spec;
5931 Str := Expr_Value_S (Expression (Arg1));
5938 GP := Parent (Parent (N));
5940 if Nkind (GP) = N_Package_Declaration
5942 Nkind (GP) = N_Generic_Package_Declaration
5947 -- If we have a compilation unit, then record the ident
5948 -- value, checking for improper duplication.
5950 if Nkind (GP) = N_Compilation_Unit then
5951 CS := Ident_String (Current_Sem_Unit);
5953 if Present (CS) then
5955 -- For Ident, we do not permit multiple instances
5957 if Prag_Id = Pragma_Ident then
5958 Error_Pragma ("duplicate% pragma not permitted");
5960 -- For Comment, we concatenate the string, unless we
5961 -- want to preserve the tree structure for ASIS.
5963 elsif not ASIS_Mode then
5964 Start_String (Strval (CS));
5965 Store_String_Char (' ');
5966 Store_String_Chars (Strval (Str));
5967 Set_Strval (CS, End_String);
5971 -- In VMS, the effect of IDENT is achieved by passing
5972 -- IDENTIFICATION=name as a --for-linker switch.
5974 if OpenVMS_On_Target then
5977 ("--for-linker=IDENTIFICATION=");
5978 String_To_Name_Buffer (Strval (Str));
5979 Store_String_Chars (Name_Buffer (1 .. Name_Len));
5981 -- Only the last processed IDENT is saved. The main
5982 -- purpose is so an IDENT associated with a main
5983 -- procedure will be used in preference to an IDENT
5984 -- associated with a with'd package.
5986 Replace_Linker_Option_String
5987 (End_String, "--for-linker=IDENTIFICATION=");
5990 Set_Ident_String (Current_Sem_Unit, Str);
5993 -- For subunits, we just ignore the Ident, since in GNAT
5994 -- these are not separate object files, and hence not
5995 -- separate units in the unit table.
5997 elsif Nkind (GP) = N_Subunit then
6000 -- Otherwise we have a misplaced pragma Ident, but we ignore
6001 -- this if we are in an instantiation, since it comes from
6002 -- a generic, and has no relevance to the instantiation.
6004 elsif Prag_Id = Pragma_Ident then
6005 if Instantiation_Location (Loc) = No_Location then
6006 Error_Pragma ("pragma% only allowed at outer level");
6017 -- [ Convention =>] convention_IDENTIFIER,
6018 -- [ Entity =>] local_NAME
6019 -- [, [External_Name =>] static_string_EXPRESSION ]
6020 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6022 when Pragma_Import =>
6023 Check_Ada_83_Warning;
6024 Check_At_Least_N_Arguments (2);
6025 Check_At_Most_N_Arguments (4);
6026 Process_Import_Or_Interface;
6028 ----------------------
6029 -- Import_Exception --
6030 ----------------------
6032 -- pragma Import_Exception (
6033 -- [Internal =>] LOCAL_NAME,
6034 -- [, [External =>] EXTERNAL_SYMBOL,]
6035 -- [, [Form =>] Ada | VMS]
6036 -- [, [Code =>] static_integer_EXPRESSION]);
6038 when Pragma_Import_Exception => Import_Exception : declare
6039 Args : Args_List (1 .. 4);
6040 Names : constant Name_List (1 .. 4) := (
6046 Internal : Node_Id renames Args (1);
6047 External : Node_Id renames Args (2);
6048 Form : Node_Id renames Args (3);
6049 Code : Node_Id renames Args (4);
6052 Gather_Associations (Names, Args);
6054 if Present (External) and then Present (Code) then
6056 ("cannot give both External and Code options for pragma%");
6059 Process_Extended_Import_Export_Exception_Pragma (
6060 Arg_Internal => Internal,
6061 Arg_External => External,
6065 if not Is_VMS_Exception (Entity (Internal)) then
6066 Set_Imported (Entity (Internal));
6068 end Import_Exception;
6070 ---------------------
6071 -- Import_Function --
6072 ---------------------
6074 -- pragma Import_Function (
6075 -- [Internal =>] LOCAL_NAME,
6076 -- [, [External =>] EXTERNAL_SYMBOL]
6077 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6078 -- [, [Result_Type =>] SUBTYPE_MARK]
6079 -- [, [Mechanism =>] MECHANISM]
6080 -- [, [Result_Mechanism =>] MECHANISM_NAME]
6081 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6083 -- EXTERNAL_SYMBOL ::=
6085 -- | static_string_EXPRESSION
6087 -- PARAMETER_TYPES ::=
6089 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6091 -- TYPE_DESIGNATOR ::=
6093 -- | subtype_Name ' Access
6097 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6099 -- MECHANISM_ASSOCIATION ::=
6100 -- [formal_parameter_NAME =>] MECHANISM_NAME
6102 -- MECHANISM_NAME ::=
6105 -- | Descriptor [([Class =>] CLASS_NAME)]
6107 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6109 when Pragma_Import_Function => Import_Function : declare
6110 Args : Args_List (1 .. 7);
6111 Names : constant Name_List (1 .. 7) := (
6114 Name_Parameter_Types,
6117 Name_Result_Mechanism,
6118 Name_First_Optional_Parameter);
6120 Internal : Node_Id renames Args (1);
6121 External : Node_Id renames Args (2);
6122 Parameter_Types : Node_Id renames Args (3);
6123 Result_Type : Node_Id renames Args (4);
6124 Mechanism : Node_Id renames Args (5);
6125 Result_Mechanism : Node_Id renames Args (6);
6126 First_Optional_Parameter : Node_Id renames Args (7);
6130 Gather_Associations (Names, Args);
6131 Process_Extended_Import_Export_Subprogram_Pragma (
6132 Arg_Internal => Internal,
6133 Arg_External => External,
6134 Arg_Parameter_Types => Parameter_Types,
6135 Arg_Result_Type => Result_Type,
6136 Arg_Mechanism => Mechanism,
6137 Arg_Result_Mechanism => Result_Mechanism,
6138 Arg_First_Optional_Parameter => First_Optional_Parameter);
6139 end Import_Function;
6145 -- pragma Import_Object (
6146 -- [Internal =>] LOCAL_NAME,
6147 -- [, [External =>] EXTERNAL_SYMBOL]
6148 -- [, [Size =>] EXTERNAL_SYMBOL]);
6150 -- EXTERNAL_SYMBOL ::=
6152 -- | static_string_EXPRESSION
6154 when Pragma_Import_Object => Import_Object : declare
6155 Args : Args_List (1 .. 3);
6156 Names : constant Name_List (1 .. 3) := (
6161 Internal : Node_Id renames Args (1);
6162 External : Node_Id renames Args (2);
6163 Size : Node_Id renames Args (3);
6167 Gather_Associations (Names, Args);
6168 Process_Extended_Import_Export_Object_Pragma (
6169 Arg_Internal => Internal,
6170 Arg_External => External,
6174 ----------------------
6175 -- Import_Procedure --
6176 ----------------------
6178 -- pragma Import_Procedure (
6179 -- [Internal =>] LOCAL_NAME,
6180 -- [, [External =>] EXTERNAL_SYMBOL]
6181 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6182 -- [, [Mechanism =>] MECHANISM]
6183 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6185 -- EXTERNAL_SYMBOL ::=
6187 -- | static_string_EXPRESSION
6189 -- PARAMETER_TYPES ::=
6191 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6193 -- TYPE_DESIGNATOR ::=
6195 -- | subtype_Name ' Access
6199 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6201 -- MECHANISM_ASSOCIATION ::=
6202 -- [formal_parameter_NAME =>] MECHANISM_NAME
6204 -- MECHANISM_NAME ::=
6207 -- | Descriptor [([Class =>] CLASS_NAME)]
6209 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6211 when Pragma_Import_Procedure => Import_Procedure : declare
6212 Args : Args_List (1 .. 5);
6213 Names : constant Name_List (1 .. 5) := (
6216 Name_Parameter_Types,
6218 Name_First_Optional_Parameter);
6220 Internal : Node_Id renames Args (1);
6221 External : Node_Id renames Args (2);
6222 Parameter_Types : Node_Id renames Args (3);
6223 Mechanism : Node_Id renames Args (4);
6224 First_Optional_Parameter : Node_Id renames Args (5);
6228 Gather_Associations (Names, Args);
6229 Process_Extended_Import_Export_Subprogram_Pragma (
6230 Arg_Internal => Internal,
6231 Arg_External => External,
6232 Arg_Parameter_Types => Parameter_Types,
6233 Arg_Mechanism => Mechanism,
6234 Arg_First_Optional_Parameter => First_Optional_Parameter);
6235 end Import_Procedure;
6237 -----------------------------
6238 -- Import_Valued_Procedure --
6239 -----------------------------
6241 -- pragma Import_Valued_Procedure (
6242 -- [Internal =>] LOCAL_NAME,
6243 -- [, [External =>] EXTERNAL_SYMBOL]
6244 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6245 -- [, [Mechanism =>] MECHANISM]
6246 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
6248 -- EXTERNAL_SYMBOL ::=
6250 -- | static_string_EXPRESSION
6252 -- PARAMETER_TYPES ::=
6254 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6256 -- TYPE_DESIGNATOR ::=
6258 -- | subtype_Name ' Access
6262 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6264 -- MECHANISM_ASSOCIATION ::=
6265 -- [formal_parameter_NAME =>] MECHANISM_NAME
6267 -- MECHANISM_NAME ::=
6270 -- | Descriptor [([Class =>] CLASS_NAME)]
6272 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6274 when Pragma_Import_Valued_Procedure =>
6275 Import_Valued_Procedure : declare
6276 Args : Args_List (1 .. 5);
6277 Names : constant Name_List (1 .. 5) := (
6280 Name_Parameter_Types,
6282 Name_First_Optional_Parameter);
6284 Internal : Node_Id renames Args (1);
6285 External : Node_Id renames Args (2);
6286 Parameter_Types : Node_Id renames Args (3);
6287 Mechanism : Node_Id renames Args (4);
6288 First_Optional_Parameter : Node_Id renames Args (5);
6292 Gather_Associations (Names, Args);
6293 Process_Extended_Import_Export_Subprogram_Pragma (
6294 Arg_Internal => Internal,
6295 Arg_External => External,
6296 Arg_Parameter_Types => Parameter_Types,
6297 Arg_Mechanism => Mechanism,
6298 Arg_First_Optional_Parameter => First_Optional_Parameter);
6299 end Import_Valued_Procedure;
6301 ------------------------
6302 -- Initialize_Scalars --
6303 ------------------------
6305 -- pragma Initialize_Scalars;
6307 when Pragma_Initialize_Scalars =>
6309 Check_Arg_Count (0);
6310 Check_Valid_Configuration_Pragma;
6311 Check_Restriction (No_Initialize_Scalars, N);
6313 if not Restrictions (No_Initialize_Scalars) then
6314 Init_Or_Norm_Scalars := True;
6315 Initialize_Scalars := True;
6322 -- pragma Inline ( NAME {, NAME} );
6324 when Pragma_Inline =>
6326 -- Pragma is active if inlining option is active
6328 if Inline_Active then
6329 Process_Inline (True);
6331 -- Pragma is active in a predefined file in config run time mode
6333 elsif Configurable_Run_Time_Mode
6335 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
6337 Process_Inline (True);
6339 -- Otherwise inlining is not active
6342 Process_Inline (False);
6349 -- pragma Inline_Always ( NAME {, NAME} );
6351 when Pragma_Inline_Always =>
6352 Process_Inline (True);
6354 --------------------
6355 -- Inline_Generic --
6356 --------------------
6358 -- pragma Inline_Generic (NAME {, NAME});
6360 when Pragma_Inline_Generic =>
6361 Process_Generic_List;
6363 ----------------------
6364 -- Inspection_Point --
6365 ----------------------
6367 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
6369 when Pragma_Inspection_Point => Inspection_Point : declare
6374 if Arg_Count > 0 then
6377 Exp := Expression (Arg);
6380 if not Is_Entity_Name (Exp)
6381 or else not Is_Object (Entity (Exp))
6383 Error_Pragma_Arg ("object name required", Arg);
6390 end Inspection_Point;
6396 -- pragma Interface (
6397 -- convention_IDENTIFIER,
6400 when Pragma_Interface =>
6402 Check_Arg_Count (2);
6403 Check_No_Identifiers;
6404 Process_Import_Or_Interface;
6406 --------------------
6407 -- Interface_Name --
6408 --------------------
6410 -- pragma Interface_Name (
6411 -- [ Entity =>] local_NAME
6412 -- [,[External_Name =>] static_string_EXPRESSION ]
6413 -- [,[Link_Name =>] static_string_EXPRESSION ]);
6415 when Pragma_Interface_Name => Interface_Name : declare
6423 Check_At_Least_N_Arguments (2);
6424 Check_At_Most_N_Arguments (3);
6425 Id := Expression (Arg1);
6428 if not Is_Entity_Name (Id) then
6430 ("first argument for pragma% must be entity name", Arg1);
6431 elsif Etype (Id) = Any_Type then
6434 Def_Id := Entity (Id);
6437 -- Special DEC-compatible processing for the object case,
6438 -- forces object to be imported.
6440 if Ekind (Def_Id) = E_Variable then
6441 Kill_Size_Check_Code (Def_Id);
6442 Note_Possible_Modification (Id);
6444 -- Initialization is not allowed for imported variable
6446 if Present (Expression (Parent (Def_Id)))
6447 and then Comes_From_Source (Expression (Parent (Def_Id)))
6449 Error_Msg_Sloc := Sloc (Def_Id);
6451 ("no initialization allowed for declaration of& #",
6455 -- For compatibility, support VADS usage of providing both
6456 -- pragmas Interface and Interface_Name to obtain the effect
6457 -- of a single Import pragma.
6459 if Is_Imported (Def_Id)
6460 and then Present (First_Rep_Item (Def_Id))
6461 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
6462 and then Chars (First_Rep_Item (Def_Id)) = Name_Interface
6466 Set_Imported (Def_Id);
6469 Set_Is_Public (Def_Id);
6470 Process_Interface_Name (Def_Id, Arg2, Arg3);
6473 -- Otherwise must be subprogram
6475 elsif not Is_Subprogram (Def_Id) then
6477 ("argument of pragma% is not subprogram", Arg1);
6480 Check_At_Most_N_Arguments (3);
6484 -- Loop through homonyms
6487 Def_Id := Get_Base_Subprogram (Hom_Id);
6489 if Is_Imported (Def_Id) then
6490 Process_Interface_Name (Def_Id, Arg2, Arg3);
6494 Hom_Id := Homonym (Hom_Id);
6496 exit when No (Hom_Id)
6497 or else Scope (Hom_Id) /= Current_Scope;
6502 ("argument of pragma% is not imported subprogram",
6508 -----------------------
6509 -- Interrupt_Handler --
6510 -----------------------
6512 -- pragma Interrupt_Handler (handler_NAME);
6514 when Pragma_Interrupt_Handler =>
6515 Check_Ada_83_Warning;
6516 Check_Arg_Count (1);
6517 Check_No_Identifiers;
6519 if No_Run_Time_Mode then
6520 Error_Msg_CRT ("Interrupt_Handler pragma", N);
6522 Check_Interrupt_Or_Attach_Handler;
6523 Process_Interrupt_Or_Attach_Handler;
6526 ------------------------
6527 -- Interrupt_Priority --
6528 ------------------------
6530 -- pragma Interrupt_Priority [(EXPRESSION)];
6532 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
6533 P : constant Node_Id := Parent (N);
6537 Check_Ada_83_Warning;
6539 if Arg_Count /= 0 then
6540 Arg := Expression (Arg1);
6541 Check_Arg_Count (1);
6542 Check_No_Identifiers;
6544 -- The expression must be analyzed in the special manner
6545 -- described in "Handling of Default and Per-Object
6546 -- Expressions" in sem.ads.
6548 Analyze_Per_Use_Expression (Arg, RTE (RE_Interrupt_Priority));
6551 if Nkind (P) /= N_Task_Definition
6552 and then Nkind (P) /= N_Protected_Definition
6557 elsif Has_Priority_Pragma (P) then
6558 Error_Pragma ("duplicate pragma% not allowed");
6561 Set_Has_Priority_Pragma (P, True);
6562 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
6564 end Interrupt_Priority;
6566 ---------------------
6567 -- Interrupt_State --
6568 ---------------------
6570 -- pragma Interrupt_State (
6571 -- [Name =>] INTERRUPT_ID,
6572 -- [State =>] INTERRUPT_STATE);
6574 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
6575 -- INTERRUPT_STATE => System | Runtime | User
6577 -- Note: if the interrupt id is given as an identifier, then
6578 -- it must be one of the identifiers in Ada.Interrupts.Names.
6579 -- Otherwise it is given as a static integer expression which
6580 -- must be in the range of Ada.Interrupts.Interrupt_ID.
6582 when Pragma_Interrupt_State => Interrupt_State : declare
6584 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
6585 -- This is the entity Ada.Interrupts.Interrupt_ID;
6587 State_Type : Character;
6588 -- Set to 's'/'r'/'u' for System/Runtime/User
6591 -- Index to entry in Interrupt_States table
6594 -- Value of interrupt
6596 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
6597 -- The first argument to the pragma
6599 Int_Ent : Entity_Id;
6600 -- Interrupt entity in Ada.Interrupts.Names
6604 Check_Arg_Count (2);
6606 Check_Optional_Identifier (Arg1, Name_Name);
6607 Check_Optional_Identifier (Arg2, "state");
6608 Check_Arg_Is_Identifier (Arg2);
6610 -- First argument is identifier
6612 if Nkind (Arg1X) = N_Identifier then
6614 -- Search list of names in Ada.Interrupts.Names
6616 Int_Ent := First_Entity (RTE (RE_Names));
6618 if No (Int_Ent) then
6619 Error_Pragma_Arg ("invalid interrupt name", Arg1);
6621 elsif Chars (Int_Ent) = Chars (Arg1X) then
6622 Int_Val := Expr_Value (Constant_Value (Int_Ent));
6626 Next_Entity (Int_Ent);
6629 -- First argument is not an identifier, so it must be a
6630 -- static expression of type Ada.Interrupts.Interrupt_ID.
6633 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6634 Int_Val := Expr_Value (Arg1X);
6636 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
6638 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
6641 ("value not in range of type " &
6642 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
6648 case Chars (Get_Pragma_Arg (Arg2)) is
6649 when Name_Runtime => State_Type := 'r';
6650 when Name_System => State_Type := 's';
6651 when Name_User => State_Type := 'u';
6654 Error_Pragma_Arg ("invalid interrupt state", Arg2);
6657 -- Check if entry is already stored
6659 IST_Num := Interrupt_States.First;
6661 -- If entry not found, add it
6663 if IST_Num > Interrupt_States.Last then
6664 Interrupt_States.Append
6665 ((Interrupt_Number => UI_To_Int (Int_Val),
6666 Interrupt_State => State_Type,
6667 Pragma_Loc => Loc));
6670 -- Case of entry for the same entry
6672 elsif Int_Val = Interrupt_States.Table (IST_Num).
6675 -- If state matches, done, no need to make redundant entry
6678 State_Type = Interrupt_States.Table (IST_Num).
6681 -- Otherwise if state does not match, error
6684 Interrupt_States.Table (IST_Num).Pragma_Loc;
6686 ("state conflicts with that given at #", Arg2);
6690 IST_Num := IST_Num + 1;
6692 end Interrupt_State;
6694 ----------------------
6695 -- Java_Constructor --
6696 ----------------------
6698 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
6700 when Pragma_Java_Constructor => Java_Constructor : declare
6707 Check_Arg_Count (1);
6708 Check_Optional_Identifier (Arg1, Name_Entity);
6709 Check_Arg_Is_Local_Name (Arg1);
6711 Id := Expression (Arg1);
6712 Find_Program_Unit_Name (Id);
6714 -- If we did not find the name, we are done
6716 if Etype (Id) = Any_Type then
6720 Hom_Id := Entity (Id);
6722 -- Loop through homonyms
6725 Def_Id := Get_Base_Subprogram (Hom_Id);
6727 -- The constructor is required to be a function returning
6728 -- an access type whose designated type has convention Java.
6730 if Ekind (Def_Id) = E_Function
6731 and then Ekind (Etype (Def_Id)) in Access_Kind
6734 (Designated_Type (Etype (Def_Id))) = Convention_Java
6737 (Root_Type (Designated_Type (Etype (Def_Id))))
6740 Set_Is_Constructor (Def_Id);
6741 Set_Convention (Def_Id, Convention_Java);
6745 ("pragma% requires function returning a 'Java access type",
6749 Hom_Id := Homonym (Hom_Id);
6751 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
6753 end Java_Constructor;
6755 ----------------------
6756 -- Java_Interface --
6757 ----------------------
6759 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
6761 when Pragma_Java_Interface => Java_Interface : declare
6767 Check_Arg_Count (1);
6768 Check_Optional_Identifier (Arg1, Name_Entity);
6769 Check_Arg_Is_Local_Name (Arg1);
6771 Arg := Expression (Arg1);
6774 if Etype (Arg) = Any_Type then
6778 if not Is_Entity_Name (Arg)
6779 or else not Is_Type (Entity (Arg))
6781 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6784 Typ := Underlying_Type (Entity (Arg));
6786 -- For now we simply check some of the semantic constraints
6787 -- on the type. This currently leaves out some restrictions
6788 -- on interface types, namely that the parent type must be
6789 -- java.lang.Object.Typ and that all primitives of the type
6790 -- should be declared abstract. ???
6792 if not Is_Tagged_Type (Typ) or else not Is_Abstract (Typ) then
6793 Error_Pragma_Arg ("pragma% requires an abstract "
6794 & "tagged type", Arg1);
6796 elsif not Has_Discriminants (Typ)
6797 or else Ekind (Etype (First_Discriminant (Typ)))
6798 /= E_Anonymous_Access_Type
6800 not Is_Class_Wide_Type
6801 (Designated_Type (Etype (First_Discriminant (Typ))))
6804 ("type must have a class-wide access discriminant", Arg1);
6812 -- pragma Keep_Names ([On => ] local_NAME);
6814 when Pragma_Keep_Names => Keep_Names : declare
6819 Check_Arg_Count (1);
6820 Check_Optional_Identifier (Arg1, Name_On);
6821 Check_Arg_Is_Local_Name (Arg1);
6823 Arg := Expression (Arg1);
6826 if Etype (Arg) = Any_Type then
6830 if not Is_Entity_Name (Arg)
6831 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
6834 ("pragma% requires a local enumeration type", Arg1);
6837 Set_Discard_Names (Entity (Arg), False);
6844 -- pragma License (RESTRICTED | UNRESRICTED | GPL | MODIFIED_GPL);
6846 when Pragma_License =>
6848 Check_Arg_Count (1);
6849 Check_No_Identifiers;
6850 Check_Valid_Configuration_Pragma;
6851 Check_Arg_Is_Identifier (Arg1);
6854 Sind : constant Source_File_Index :=
6855 Source_Index (Current_Sem_Unit);
6858 case Chars (Get_Pragma_Arg (Arg1)) is
6860 Set_License (Sind, GPL);
6862 when Name_Modified_GPL =>
6863 Set_License (Sind, Modified_GPL);
6865 when Name_Restricted =>
6866 Set_License (Sind, Restricted);
6868 when Name_Unrestricted =>
6869 Set_License (Sind, Unrestricted);
6872 Error_Pragma_Arg ("invalid license name", Arg1);
6880 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
6882 when Pragma_Link_With => Link_With : declare
6888 if Operating_Mode = Generate_Code
6889 and then In_Extended_Main_Source_Unit (N)
6891 Check_At_Least_N_Arguments (1);
6892 Check_No_Identifiers;
6893 Check_Is_In_Decl_Part_Or_Package_Spec;
6894 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
6898 while Present (Arg) loop
6899 Check_Arg_Is_Static_Expression (Arg, Standard_String);
6901 -- Store argument, converting sequences of spaces
6902 -- to a single null character (this is one of the
6903 -- differences in processing between Link_With
6904 -- and Linker_Options).
6907 C : constant Char_Code := Get_Char_Code (' ');
6908 S : constant String_Id :=
6909 Strval (Expr_Value_S (Expression (Arg)));
6910 L : constant Nat := String_Length (S);
6913 procedure Skip_Spaces;
6914 -- Advance F past any spaces
6916 procedure Skip_Spaces is
6918 while F <= L and then Get_String_Char (S, F) = C loop
6924 Skip_Spaces; -- skip leading spaces
6926 -- Loop through characters, changing any embedded
6927 -- sequence of spaces to a single null character
6928 -- (this is how Link_With/Linker_Options differ)
6931 if Get_String_Char (S, F) = C then
6934 Store_String_Char (ASCII.NUL);
6937 Store_String_Char (Get_String_Char (S, F));
6945 if Present (Arg) then
6946 Store_String_Char (ASCII.NUL);
6950 Store_Linker_Option_String (End_String);
6958 -- pragma Linker_Alias (
6959 -- [Entity =>] LOCAL_NAME
6960 -- [Alias =>] static_string_EXPRESSION);
6962 when Pragma_Linker_Alias =>
6964 Check_Arg_Count (2);
6965 Check_Optional_Identifier (Arg1, Name_Entity);
6966 Check_Optional_Identifier (Arg2, "alias");
6967 Check_Arg_Is_Library_Level_Local_Name (Arg1);
6968 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6970 -- The only processing required is to link this item on to the
6971 -- list of rep items for the given entity. This is accomplished
6972 -- by the call to Rep_Item_Too_Late (when no error is detected
6973 -- and False is returned).
6975 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
6978 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
6981 --------------------
6982 -- Linker_Options --
6983 --------------------
6985 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
6987 when Pragma_Linker_Options => Linker_Options : declare
6991 Check_Ada_83_Warning;
6992 Check_No_Identifiers;
6993 Check_Arg_Count (1);
6994 Check_Is_In_Decl_Part_Or_Package_Spec;
6996 if Operating_Mode = Generate_Code
6997 and then In_Extended_Main_Source_Unit (N)
6999 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7000 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
7003 while Present (Arg) loop
7004 Check_Arg_Is_Static_Expression (Arg, Standard_String);
7005 Store_String_Char (ASCII.NUL);
7007 (Strval (Expr_Value_S (Expression (Arg))));
7011 Store_Linker_Option_String (End_String);
7015 --------------------
7016 -- Linker_Section --
7017 --------------------
7019 -- pragma Linker_Section (
7020 -- [Entity =>] LOCAL_NAME
7021 -- [Section =>] static_string_EXPRESSION);
7023 when Pragma_Linker_Section =>
7025 Check_Arg_Count (2);
7026 Check_Optional_Identifier (Arg1, Name_Entity);
7027 Check_Optional_Identifier (Arg2, Name_Section);
7028 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7029 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7031 -- The only processing required is to link this item on to the
7032 -- list of rep items for the given entity. This is accomplished
7033 -- by the call to Rep_Item_Too_Late (when no error is detected
7034 -- and False is returned).
7036 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
7039 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7046 -- pragma List (On | Off)
7048 -- There is nothing to do here, since we did all the processing
7049 -- for this pragma in Par.Prag (so that it works properly even in
7050 -- syntax only mode)
7055 --------------------
7056 -- Locking_Policy --
7057 --------------------
7059 -- pragma Locking_Policy (policy_IDENTIFIER);
7061 when Pragma_Locking_Policy => declare
7065 Check_Ada_83_Warning;
7066 Check_Arg_Count (1);
7067 Check_No_Identifiers;
7068 Check_Arg_Is_Locking_Policy (Arg1);
7069 Check_Valid_Configuration_Pragma;
7070 Get_Name_String (Chars (Expression (Arg1)));
7071 LP := Fold_Upper (Name_Buffer (1));
7073 if Locking_Policy /= ' '
7074 and then Locking_Policy /= LP
7076 Error_Msg_Sloc := Locking_Policy_Sloc;
7077 Error_Pragma ("locking policy incompatible with policy#");
7079 -- Set new policy, but always preserve System_Location since
7080 -- we like the error message with the run time name.
7083 Locking_Policy := LP;
7085 if Locking_Policy_Sloc /= System_Location then
7086 Locking_Policy_Sloc := Loc;
7095 -- pragma Long_Float (D_Float | G_Float);
7097 when Pragma_Long_Float =>
7099 Check_Valid_Configuration_Pragma;
7100 Check_Arg_Count (1);
7101 Check_No_Identifier (Arg1);
7102 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
7104 if not OpenVMS_On_Target then
7105 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
7110 if Chars (Expression (Arg1)) = Name_D_Float then
7111 if Opt.Float_Format_Long = 'G' then
7112 Error_Pragma ("G_Float previously specified");
7115 Opt.Float_Format_Long := 'D';
7117 -- G_Float case (this is the default, does not need overriding)
7120 if Opt.Float_Format_Long = 'D' then
7121 Error_Pragma ("D_Float previously specified");
7124 Opt.Float_Format_Long := 'G';
7127 Set_Standard_Fpt_Formats;
7129 -----------------------
7130 -- Machine_Attribute --
7131 -----------------------
7133 -- pragma Machine_Attribute (
7134 -- [Entity =>] LOCAL_NAME,
7135 -- [Attribute_Name =>] static_string_EXPRESSION
7136 -- [,[Info =>] static_string_EXPRESSION] );
7138 when Pragma_Machine_Attribute => Machine_Attribute : declare
7144 if Arg_Count = 3 then
7145 Check_Optional_Identifier (Arg3, "info");
7146 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
7148 Check_Arg_Count (2);
7151 Check_Arg_Is_Local_Name (Arg1);
7152 Check_Optional_Identifier (Arg2, "attribute_name");
7153 Check_Optional_Identifier (Arg1, Name_Entity);
7154 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7155 Def_Id := Entity (Expression (Arg1));
7157 if Is_Access_Type (Def_Id) then
7158 Def_Id := Designated_Type (Def_Id);
7161 if Rep_Item_Too_Early (Def_Id, N) then
7165 Def_Id := Underlying_Type (Def_Id);
7167 -- The only processing required is to link this item on to the
7168 -- list of rep items for the given entity. This is accomplished
7169 -- by the call to Rep_Item_Too_Late (when no error is detected
7170 -- and False is returned).
7172 if Rep_Item_Too_Late (Def_Id, N) then
7175 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
7177 end Machine_Attribute;
7183 -- pragma Main_Storage
7184 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7186 -- MAIN_STORAGE_OPTION ::=
7187 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7188 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7190 when Pragma_Main => Main : declare
7191 Args : Args_List (1 .. 3);
7192 Names : constant Name_List (1 .. 3) := (
7194 Name_Task_Stack_Size_Default,
7195 Name_Time_Slicing_Enabled);
7201 Gather_Associations (Names, Args);
7203 for J in 1 .. 2 loop
7204 if Present (Args (J)) then
7205 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7209 if Present (Args (3)) then
7210 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
7214 while Present (Nod) loop
7215 if Nkind (Nod) = N_Pragma
7216 and then Chars (Nod) = Name_Main
7218 Error_Msg_Name_1 := Chars (N);
7219 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7230 -- pragma Main_Storage
7231 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
7233 -- MAIN_STORAGE_OPTION ::=
7234 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
7235 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
7237 when Pragma_Main_Storage => Main_Storage : declare
7238 Args : Args_List (1 .. 2);
7239 Names : constant Name_List (1 .. 2) := (
7240 Name_Working_Storage,
7247 Gather_Associations (Names, Args);
7249 for J in 1 .. 2 loop
7250 if Present (Args (J)) then
7251 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
7255 Check_In_Main_Program;
7258 while Present (Nod) loop
7259 if Nkind (Nod) = N_Pragma
7260 and then Chars (Nod) = Name_Main_Storage
7262 Error_Msg_Name_1 := Chars (N);
7263 Error_Msg_N ("duplicate pragma% not permitted", Nod);
7274 -- pragma Memory_Size (NUMERIC_LITERAL)
7276 when Pragma_Memory_Size =>
7279 -- Memory size is simply ignored
7281 Check_No_Identifiers;
7282 Check_Arg_Count (1);
7283 Check_Arg_Is_Integer_Literal (Arg1);
7289 -- pragma No_Return (procedure_LOCAL_NAME);
7291 when Pragma_No_Return => No_Return : declare
7298 Check_Arg_Count (1);
7299 Check_No_Identifiers;
7300 Check_Arg_Is_Local_Name (Arg1);
7301 Id := Expression (Arg1);
7304 if not Is_Entity_Name (Id) then
7305 Error_Pragma_Arg ("entity name required", Arg1);
7308 if Etype (Id) = Any_Type then
7316 and then Scope (E) = Current_Scope
7318 if Ekind (E) = E_Procedure
7319 or else Ekind (E) = E_Generic_Procedure
7329 Error_Pragma ("no procedures found for pragma%");
7337 -- pragma Obsolescent [(static_string_EXPRESSION)];
7339 when Pragma_Obsolescent => Obsolescent : declare
7342 Check_At_Most_N_Arguments (1);
7343 Check_No_Identifiers;
7345 if Arg_Count = 1 then
7346 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7350 or else (Nkind (Prev (N))) /= N_Subprogram_Declaration
7353 ("pragma% misplaced, must immediately " &
7354 "follow subprogram spec");
7362 -- pragma No_Run_Time
7364 -- Note: this pragma is retained for backwards compatibiltiy.
7365 -- See body of Rtsfind for full details on its handling.
7367 when Pragma_No_Run_Time =>
7369 Check_Valid_Configuration_Pragma;
7370 Check_Arg_Count (0);
7372 No_Run_Time_Mode := True;
7373 Configurable_Run_Time_Mode := True;
7375 if Ttypes.System_Word_Size = 32 then
7376 Duration_32_Bits_On_Target := True;
7379 Restrictions (No_Finalization) := True;
7380 Restrictions (No_Exception_Handlers) := True;
7381 Restriction_Parameters (Max_Tasks) := Uint_0;
7383 -----------------------
7384 -- Normalize_Scalars --
7385 -----------------------
7387 -- pragma Normalize_Scalars;
7389 when Pragma_Normalize_Scalars =>
7390 Check_Ada_83_Warning;
7391 Check_Arg_Count (0);
7392 Check_Valid_Configuration_Pragma;
7393 Normalize_Scalars := True;
7394 Init_Or_Norm_Scalars := True;
7400 -- pragma Optimize (Time | Space);
7402 -- The actual check for optimize is done in Gigi. Note that this
7403 -- pragma does not actually change the optimization setting, it
7404 -- simply checks that it is consistent with the pragma.
7406 when Pragma_Optimize =>
7407 Check_No_Identifiers;
7408 Check_Arg_Count (1);
7409 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
7411 -------------------------
7412 -- Optional_Overriding --
7413 -------------------------
7415 -- These pragmas are treated as part of the previous subprogram
7416 -- declaration, and analyzed immediately after it (see sem_ch6,
7417 -- Check_Overriding_Operation). If the pragma has not been analyzed
7418 -- yet, it appears in the wrong place.
7420 when Pragma_Optional_Overriding =>
7421 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7427 when Pragma_Overriding =>
7428 Error_Msg_N ("pragma must appear immediately after subprogram", N);
7434 -- pragma Pack (first_subtype_LOCAL_NAME);
7436 when Pragma_Pack => Pack : declare
7437 Assoc : constant Node_Id := Arg1;
7442 Check_No_Identifiers;
7443 Check_Arg_Count (1);
7444 Check_Arg_Is_Local_Name (Arg1);
7446 Type_Id := Expression (Assoc);
7447 Find_Type (Type_Id);
7448 Typ := Entity (Type_Id);
7451 or else Rep_Item_Too_Early (Typ, N)
7455 Typ := Underlying_Type (Typ);
7458 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
7459 Error_Pragma ("pragma% must specify array or record type");
7462 Check_First_Subtype (Arg1);
7464 if Has_Pragma_Pack (Typ) then
7465 Error_Pragma ("duplicate pragma%, only one allowed");
7467 -- Array type. We set the Has_Pragma_Pack flag, and Is_Packed,
7468 -- but not Has_Non_Standard_Rep, because we don't actually know
7469 -- till freeze time if the array can have packed representation.
7470 -- That's because in the general case we do not know enough about
7471 -- the component type until it in turn is frozen, which certainly
7472 -- happens before the array type is frozen, but not necessarily
7473 -- till that point (i.e. right now it may be unfrozen).
7475 elsif Is_Array_Type (Typ) then
7476 if Has_Aliased_Components (Base_Type (Typ)) then
7478 ("pragma% ignored, cannot pack aliased components?");
7480 elsif Has_Atomic_Components (Typ) then
7482 ("?pragma% ignored, cannot pack atomic components");
7484 elsif not Rep_Item_Too_Late (Typ, N) then
7485 Set_Is_Packed (Base_Type (Typ));
7486 Set_Has_Pragma_Pack (Base_Type (Typ));
7487 Set_Has_Non_Standard_Rep (Base_Type (Typ));
7490 -- Record type. For record types, the pack is always effective
7492 else pragma Assert (Is_Record_Type (Typ));
7493 if not Rep_Item_Too_Late (Typ, N) then
7494 Set_Has_Pragma_Pack (Base_Type (Typ));
7495 Set_Is_Packed (Base_Type (Typ));
7496 Set_Has_Non_Standard_Rep (Base_Type (Typ));
7507 -- There is nothing to do here, since we did all the processing
7508 -- for this pragma in Par.Prag (so that it works properly even in
7509 -- syntax only mode)
7518 -- pragma Passive [(PASSIVE_FORM)];
7520 -- PASSIVE_FORM ::= Semaphore | No
7522 when Pragma_Passive =>
7525 if Nkind (Parent (N)) /= N_Task_Definition then
7526 Error_Pragma ("pragma% must be within task definition");
7529 if Arg_Count /= 0 then
7530 Check_Arg_Count (1);
7531 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
7538 -- pragma Polling (ON | OFF);
7540 when Pragma_Polling =>
7542 Check_Arg_Count (1);
7543 Check_No_Identifiers;
7544 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7545 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
7547 ---------------------
7548 -- Persistent_Data --
7549 ---------------------
7551 when Pragma_Persistent_Data => declare
7555 -- Register the pragma as applying to the compilation unit.
7556 -- Individual Persistent_Object pragmas for relevant objects
7557 -- are generated the end of the compilation.
7560 Check_Valid_Configuration_Pragma;
7561 Check_Arg_Count (0);
7562 Ent := Find_Lib_Unit_Name;
7563 Set_Is_Preelaborated (Ent);
7566 ------------------------
7567 -- Persistent_Object --
7568 ------------------------
7570 when Pragma_Persistent_Object => declare
7578 Check_Arg_Count (1);
7579 Check_Arg_Is_Library_Level_Local_Name (Arg1);
7580 if not Is_Entity_Name (Expression (Arg1))
7582 (Ekind (Entity (Expression (Arg1))) /= E_Variable
7583 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
7585 Error_Pragma_Arg ("pragma only applies to objects", Arg1);
7588 Ent := Entity (Expression (Arg1));
7589 Decl := Parent (Ent);
7591 if Nkind (Decl) /= N_Object_Declaration then
7595 -- Placement of the object depends on whether there is
7596 -- an initial value or none. If the No_Initialization flag
7597 -- is set, the initialization has been transformed into
7598 -- assignments, which is disallowed elaboration code.
7600 if No_Initialization (Decl) then
7602 ("initialization for persistent object"
7603 & "must be static expression", Decl);
7607 if No (Expression (Decl)) then
7609 Store_String_Chars ("section ("".persistent.bss"")");
7613 if not Is_OK_Static_Expression (Expression (Decl)) then
7614 Flag_Non_Static_Expr
7615 ("initialization for persistent object"
7616 & "must be static expression!", Expression (Decl));
7621 Store_String_Chars ("section ("".persistent.data"")");
7628 Name_Machine_Attribute,
7630 (Make_Pragma_Argument_Association
7631 (Sloc => Sloc (Arg1),
7632 Expression => New_Occurrence_Of (Ent, Sloc (Ent))),
7633 Make_Pragma_Argument_Association
7634 (Sloc => Sloc (Arg1),
7637 (Sloc => Sloc (Arg1),
7640 Insert_After (N, MA);
7642 Set_Has_Gigi_Rep_Item (Ent);
7649 -- pragma Preelaborate [(library_unit_NAME)];
7651 -- Set the flag Is_Preelaborated of program unit name entity
7653 when Pragma_Preelaborate => Preelaborate : declare
7654 Pa : constant Node_Id := Parent (N);
7655 Pk : constant Node_Kind := Nkind (Pa);
7659 Check_Ada_83_Warning;
7660 Check_Valid_Library_Unit_Pragma;
7662 if Nkind (N) = N_Null_Statement then
7666 Ent := Find_Lib_Unit_Name;
7668 -- This filters out pragmas inside generic parent then
7669 -- show up inside instantiation
7672 and then not (Pk = N_Package_Specification
7673 and then Present (Generic_Parent (Pa)))
7675 if not Debug_Flag_U then
7676 Set_Is_Preelaborated (Ent);
7677 Set_Suppress_Elaboration_Warnings (Ent);
7686 -- pragma Priority (EXPRESSION);
7688 when Pragma_Priority => Priority : declare
7689 P : constant Node_Id := Parent (N);
7693 Check_No_Identifiers;
7694 Check_Arg_Count (1);
7698 if Nkind (P) = N_Subprogram_Body then
7699 Check_In_Main_Program;
7701 Arg := Expression (Arg1);
7702 Analyze_And_Resolve (Arg, Standard_Integer);
7706 if not Is_Static_Expression (Arg) then
7707 Flag_Non_Static_Expr
7708 ("main subprogram priority is not static!", Arg);
7711 -- If constraint error, then we already signalled an error
7713 elsif Raises_Constraint_Error (Arg) then
7716 -- Otherwise check in range
7720 Val : constant Uint := Expr_Value (Arg);
7724 or else Val > Expr_Value (Expression
7725 (Parent (RTE (RE_Max_Priority))))
7728 ("main subprogram priority is out of range", Arg1);
7734 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7736 -- Task or Protected, must be of type Integer
7738 elsif Nkind (P) = N_Protected_Definition
7740 Nkind (P) = N_Task_Definition
7742 Arg := Expression (Arg1);
7744 -- The expression must be analyzed in the special manner
7745 -- described in "Handling of Default and Per-Object
7746 -- Expressions" in sem.ads.
7748 Analyze_Per_Use_Expression (Arg, Standard_Integer);
7750 if not Is_Static_Expression (Arg) then
7751 Check_Restriction (Static_Priorities, Arg);
7754 -- Anything else is incorrect
7760 if Has_Priority_Pragma (P) then
7761 Error_Pragma ("duplicate pragma% not allowed");
7763 Set_Has_Priority_Pragma (P, True);
7765 if Nkind (P) = N_Protected_Definition
7767 Nkind (P) = N_Task_Definition
7769 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7770 -- exp_ch9 should use this ???
7775 --------------------------
7776 -- Propagate_Exceptions --
7777 --------------------------
7779 -- pragma Propagate_Exceptions;
7781 when Pragma_Propagate_Exceptions =>
7783 Check_Arg_Count (0);
7785 if In_Extended_Main_Source_Unit (N) then
7786 Propagate_Exceptions := True;
7793 -- pragma Psect_Object (
7794 -- [Internal =>] LOCAL_NAME,
7795 -- [, [External =>] EXTERNAL_SYMBOL]
7796 -- [, [Size =>] EXTERNAL_SYMBOL]);
7798 when Pragma_Psect_Object | Pragma_Common_Object =>
7799 Psect_Object : declare
7800 Args : Args_List (1 .. 3);
7801 Names : constant Name_List (1 .. 3) := (
7806 Internal : Node_Id renames Args (1);
7807 External : Node_Id renames Args (2);
7808 Size : Node_Id renames Args (3);
7810 R_Internal : Node_Id;
7811 R_External : Node_Id;
7818 procedure Check_Too_Long (Arg : Node_Id);
7819 -- Posts message if the argument is an identifier with more
7820 -- than 31 characters, or a string literal with more than
7821 -- 31 characters, and we are operating under VMS
7823 --------------------
7824 -- Check_Too_Long --
7825 --------------------
7827 procedure Check_Too_Long (Arg : Node_Id) is
7828 X : constant Node_Id := Original_Node (Arg);
7831 if Nkind (X) /= N_String_Literal
7833 Nkind (X) /= N_Identifier
7836 ("inappropriate argument for pragma %", Arg);
7839 if OpenVMS_On_Target then
7840 if (Nkind (X) = N_String_Literal
7841 and then String_Length (Strval (X)) > 31)
7843 (Nkind (X) = N_Identifier
7844 and then Length_Of_Name (Chars (X)) > 31)
7847 ("argument for pragma % is longer than 31 characters",
7853 -- Start of processing for Common_Object/Psect_Object
7857 Gather_Associations (Names, Args);
7858 Process_Extended_Import_Export_Internal_Arg (Internal);
7860 R_Internal := Relocate_Node (Internal);
7862 Def_Id := Entity (R_Internal);
7864 if Ekind (Def_Id) /= E_Constant
7865 and then Ekind (Def_Id) /= E_Variable
7868 ("pragma% must designate an object", Internal);
7871 Check_Too_Long (R_Internal);
7873 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
7875 ("cannot use pragma% for imported/exported object",
7879 if Is_Concurrent_Type (Etype (R_Internal)) then
7881 ("cannot specify pragma % for task/protected object",
7885 if Is_Psected (Def_Id) then
7886 Error_Msg_N ("?duplicate Psect_Object pragma", N);
7888 Set_Is_Psected (Def_Id);
7891 if Ekind (Def_Id) = E_Constant then
7893 ("cannot specify pragma % for a constant", R_Internal);
7896 if Is_Record_Type (Etype (R_Internal)) then
7902 Ent := First_Entity (Etype (R_Internal));
7903 while Present (Ent) loop
7904 Decl := Declaration_Node (Ent);
7906 if Ekind (Ent) = E_Component
7907 and then Nkind (Decl) = N_Component_Declaration
7908 and then Present (Expression (Decl))
7909 and then Warn_On_Export_Import
7912 ("?object for pragma % has defaults", R_Internal);
7922 if Present (Size) then
7923 Check_Too_Long (Size);
7926 -- Make Psect case-insensitive.
7928 if Present (External) then
7929 Check_Too_Long (External);
7931 if Nkind (External) = N_String_Literal then
7932 String_To_Name_Buffer (Strval (External));
7934 Get_Name_String (Chars (External));
7939 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7941 R_External := Make_String_Literal
7942 (Sloc => Sloc (External), Strval => Str);
7944 Get_Name_String (Chars (Internal));
7947 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7949 R_External := Make_String_Literal
7950 (Sloc => Sloc (Internal), Strval => Str);
7953 -- Transform into pragma Linker_Section, add attributes to
7954 -- match what DEC Ada does. Ignore size for now?
7959 Name_Linker_Section,
7961 (Make_Pragma_Argument_Association
7962 (Sloc => Sloc (R_Internal),
7963 Expression => R_Internal),
7964 Make_Pragma_Argument_Association
7965 (Sloc => Sloc (R_External),
7966 Expression => R_External))));
7970 -- Add Machine_Attribute of "overlaid", so the section overlays
7971 -- other sections of the same name.
7974 Store_String_Chars ("overlaid");
7980 Name_Machine_Attribute,
7982 (Make_Pragma_Argument_Association
7983 (Sloc => Sloc (R_Internal),
7984 Expression => R_Internal),
7985 Make_Pragma_Argument_Association
7986 (Sloc => Sloc (R_External),
7989 (Sloc => Sloc (R_External),
7993 -- Add Machine_Attribute of "global", so the section is visible
7997 Store_String_Chars ("global");
8003 Name_Machine_Attribute,
8005 (Make_Pragma_Argument_Association
8006 (Sloc => Sloc (R_Internal),
8007 Expression => R_Internal),
8009 Make_Pragma_Argument_Association
8010 (Sloc => Sloc (R_External),
8013 (Sloc => Sloc (R_External),
8017 -- Add Machine_Attribute of "initialize", so the section is
8021 Store_String_Chars ("initialize");
8027 Name_Machine_Attribute,
8029 (Make_Pragma_Argument_Association
8030 (Sloc => Sloc (R_Internal),
8031 Expression => R_Internal),
8033 Make_Pragma_Argument_Association
8034 (Sloc => Sloc (R_External),
8037 (Sloc => Sloc (R_External),
8046 -- pragma Pure [(library_unit_NAME)];
8048 when Pragma_Pure => Pure : declare
8051 Check_Ada_83_Warning;
8052 Check_Valid_Library_Unit_Pragma;
8054 if Nkind (N) = N_Null_Statement then
8058 Ent := Find_Lib_Unit_Name;
8060 Set_Suppress_Elaboration_Warnings (Ent);
8067 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
8069 when Pragma_Pure_Function => Pure_Function : declare
8076 Check_Arg_Count (1);
8077 Check_Optional_Identifier (Arg1, Name_Entity);
8078 Check_Arg_Is_Local_Name (Arg1);
8079 E_Id := Expression (Arg1);
8081 if Error_Posted (E_Id) then
8085 -- Loop through homonyms (overloadings) of referenced entity
8091 Def_Id := Get_Base_Subprogram (E);
8093 if Ekind (Def_Id) /= E_Function
8094 and then Ekind (Def_Id) /= E_Generic_Function
8095 and then Ekind (Def_Id) /= E_Operator
8098 ("pragma% requires a function name", Arg1);
8101 Set_Is_Pure (Def_Id);
8102 Set_Has_Pragma_Pure_Function (Def_Id);
8105 exit when No (E) or else Scope (E) /= Current_Scope;
8110 --------------------
8111 -- Queuing_Policy --
8112 --------------------
8114 -- pragma Queuing_Policy (policy_IDENTIFIER);
8116 when Pragma_Queuing_Policy => declare
8120 Check_Ada_83_Warning;
8121 Check_Arg_Count (1);
8122 Check_No_Identifiers;
8123 Check_Arg_Is_Queuing_Policy (Arg1);
8124 Check_Valid_Configuration_Pragma;
8125 Get_Name_String (Chars (Expression (Arg1)));
8126 QP := Fold_Upper (Name_Buffer (1));
8128 if Queuing_Policy /= ' '
8129 and then Queuing_Policy /= QP
8131 Error_Msg_Sloc := Queuing_Policy_Sloc;
8132 Error_Pragma ("queuing policy incompatible with policy#");
8134 -- Set new policy, but always preserve System_Location since
8135 -- we like the error message with the run time name.
8138 Queuing_Policy := QP;
8140 if Queuing_Policy_Sloc /= System_Location then
8141 Queuing_Policy_Sloc := Loc;
8146 ---------------------------
8147 -- Remote_Call_Interface --
8148 ---------------------------
8150 -- pragma Remote_Call_Interface [(library_unit_NAME)];
8152 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
8153 Cunit_Node : Node_Id;
8154 Cunit_Ent : Entity_Id;
8158 Check_Ada_83_Warning;
8159 Check_Valid_Library_Unit_Pragma;
8161 if Nkind (N) = N_Null_Statement then
8165 Cunit_Node := Cunit (Current_Sem_Unit);
8166 K := Nkind (Unit (Cunit_Node));
8167 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8169 if K = N_Package_Declaration
8170 or else K = N_Generic_Package_Declaration
8171 or else K = N_Subprogram_Declaration
8172 or else K = N_Generic_Subprogram_Declaration
8173 or else (K = N_Subprogram_Body
8174 and then Acts_As_Spec (Unit (Cunit_Node)))
8179 "pragma% must apply to package or subprogram declaration");
8182 Set_Is_Remote_Call_Interface (Cunit_Ent);
8183 end Remote_Call_Interface;
8189 -- pragma Remote_Types [(library_unit_NAME)];
8191 when Pragma_Remote_Types => Remote_Types : declare
8192 Cunit_Node : Node_Id;
8193 Cunit_Ent : Entity_Id;
8196 Check_Ada_83_Warning;
8197 Check_Valid_Library_Unit_Pragma;
8199 if Nkind (N) = N_Null_Statement then
8203 Cunit_Node := Cunit (Current_Sem_Unit);
8204 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8206 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8208 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8211 "pragma% can only apply to a package declaration");
8214 Set_Is_Remote_Types (Cunit_Ent);
8221 -- pragma Ravenscar;
8223 when Pragma_Ravenscar =>
8225 Check_Arg_Count (0);
8226 Check_Valid_Configuration_Pragma;
8229 -------------------------
8230 -- Restricted_Run_Time --
8231 -------------------------
8233 -- pragma Restricted_Run_Time;
8235 when Pragma_Restricted_Run_Time =>
8237 Check_Arg_Count (0);
8238 Check_Valid_Configuration_Pragma;
8239 Set_Restricted_Profile (N);
8245 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
8248 -- restriction_IDENTIFIER
8249 -- | restriction_parameter_IDENTIFIER => EXPRESSION
8251 when Pragma_Restrictions => Restrictions_Pragma : declare
8253 R_Id : Restriction_Id;
8254 RP_Id : Restriction_Parameter_Id;
8260 Check_Ada_83_Warning;
8261 Check_At_Least_N_Arguments (1);
8262 Check_Valid_Configuration_Pragma;
8265 while Present (Arg) loop
8267 Expr := Expression (Arg);
8269 -- Case of no restriction identifier
8271 if Id = No_Name then
8272 if Nkind (Expr) /= N_Identifier then
8274 ("invalid form for restriction", Arg);
8277 R_Id := Get_Restriction_Id (Chars (Expr));
8279 if R_Id = Not_A_Restriction_Id then
8281 ("invalid restriction identifier", Arg);
8283 -- Restriction is active
8286 if Implementation_Restriction (R_Id) then
8288 (No_Implementation_Restrictions, Arg);
8291 Restrictions (R_Id) := True;
8293 -- Set location, but preserve location of system
8294 -- restriction for nice error msg with run time name
8296 if Restrictions_Loc (R_Id) /= System_Location then
8297 Restrictions_Loc (R_Id) := Sloc (N);
8300 -- Record the restriction if we are in the main unit,
8301 -- or in the extended main unit. The reason that we
8302 -- test separately for Main_Unit is that gnat.adc is
8303 -- processed with Current_Sem_Unit = Main_Unit, but
8304 -- nodes in gnat.adc do not appear to be the extended
8305 -- main source unit (they probably should do ???)
8307 if Current_Sem_Unit = Main_Unit
8308 or else In_Extended_Main_Source_Unit (N)
8310 Main_Restrictions (R_Id) := True;
8313 -- A very special case that must be processed here:
8314 -- pragma Restrictions (No_Exceptions) turns off all
8315 -- run-time checking. This is a bit dubious in terms
8316 -- of the formal language definition, but it is what
8317 -- is intended by the wording of RM H.4(12).
8319 if R_Id = No_Exceptions then
8320 Scope_Suppress := (others => True);
8325 -- Case of restriction identifier present
8328 RP_Id := Get_Restriction_Parameter_Id (Id);
8329 Analyze_And_Resolve (Expr, Any_Integer);
8331 if RP_Id = Not_A_Restriction_Parameter_Id then
8333 ("invalid restriction parameter identifier", Arg);
8335 elsif not Is_OK_Static_Expression (Expr) then
8336 Flag_Non_Static_Expr
8337 ("value must be static expression!", Expr);
8340 elsif not Is_Integer_Type (Etype (Expr))
8341 or else Expr_Value (Expr) < 0
8344 ("value must be non-negative integer", Arg);
8346 -- Restriction pragma is active
8349 Val := Expr_Value (Expr);
8351 -- Record pragma if most restrictive so far
8353 if Restriction_Parameters (RP_Id) = No_Uint
8354 or else Val < Restriction_Parameters (RP_Id)
8356 Restriction_Parameters (RP_Id) := Val;
8357 Restriction_Parameters_Loc (RP_Id) := Sloc (N);
8364 end Restrictions_Pragma;
8366 --------------------------
8367 -- Restriction_Warnings --
8368 --------------------------
8370 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
8372 -- RESTRICTION ::= restriction_IDENTIFIER
8374 when Pragma_Restriction_Warnings => Restriction_Warn : declare
8376 R_Id : Restriction_Id;
8381 Check_At_Least_N_Arguments (1);
8382 Check_Valid_Configuration_Pragma;
8383 Check_No_Identifiers;
8386 while Present (Arg) loop
8387 Expr := Expression (Arg);
8389 if Nkind (Expr) /= N_Identifier then
8391 ("invalid form for restriction", Arg);
8394 R_Id := Get_Restriction_Id (Chars (Expr));
8396 if R_Id = Not_A_Restriction_Id then
8398 ("invalid restriction identifier", Arg);
8400 -- Restriction is active
8403 if Implementation_Restriction (R_Id) then
8405 (No_Implementation_Restrictions, Arg);
8408 Restriction_Warnings (R_Id) := True;
8414 end Restriction_Warn;
8420 -- pragma Reviewable;
8422 when Pragma_Reviewable =>
8423 Check_Ada_83_Warning;
8424 Check_Arg_Count (0);
8430 -- pragma Share_Generic (NAME {, NAME});
8432 when Pragma_Share_Generic =>
8434 Process_Generic_List;
8440 -- pragma Shared (LOCAL_NAME);
8442 when Pragma_Shared =>
8444 Process_Atomic_Shared_Volatile;
8446 --------------------
8447 -- Shared_Passive --
8448 --------------------
8450 -- pragma Shared_Passive [(library_unit_NAME)];
8452 -- Set the flag Is_Shared_Passive of program unit name entity
8454 when Pragma_Shared_Passive => Shared_Passive : declare
8455 Cunit_Node : Node_Id;
8456 Cunit_Ent : Entity_Id;
8459 Check_Ada_83_Warning;
8460 Check_Valid_Library_Unit_Pragma;
8462 if Nkind (N) = N_Null_Statement then
8466 Cunit_Node := Cunit (Current_Sem_Unit);
8467 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
8469 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
8471 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
8474 "pragma% can only apply to a package declaration");
8477 Set_Is_Shared_Passive (Cunit_Ent);
8480 ----------------------
8481 -- Source_File_Name --
8482 ----------------------
8484 -- pragma Source_File_Name (
8485 -- [UNIT_NAME =>] unit_NAME,
8486 -- [BODY_FILE_NAME | SPEC_FILE_NAME] => STRING_LITERAL);
8488 -- No processing here. Processing was completed during parsing,
8489 -- since we need to have file names set as early as possible.
8490 -- Units are loaded well before semantic processing starts.
8492 -- The only processing we defer to this point is the check
8493 -- for correct placement.
8495 when Pragma_Source_File_Name =>
8497 Check_Valid_Configuration_Pragma;
8499 ------------------------------
8500 -- Source_File_Name_Project --
8501 ------------------------------
8503 -- pragma Source_File_Name_Project (
8504 -- [UNIT_NAME =>] unit_NAME,
8505 -- [BODY_FILE_NAME | SPEC_FILE_NAME] => STRING_LITERAL);
8507 -- No processing here. Processing was completed during parsing,
8508 -- since we need to have file names set as early as possible.
8509 -- Units are loaded well before semantic processing starts.
8511 -- The only processing we defer to this point is the check
8512 -- for correct placement.
8514 when Pragma_Source_File_Name_Project =>
8516 Check_Valid_Configuration_Pragma;
8518 -- Check that a pragma Source_File_Name_Project is used only
8519 -- in a configuration pragmas file.
8520 -- Pragmas Source_File_Name_Project should only be generated
8521 -- by the Project Manager in configuration pragmas files.
8523 -- This is really an ugly test. It seems to depend on some
8524 -- accidental and undocumented property. At the very least
8525 -- it needs to be documented, but it would be better to have
8526 -- a clean way of testing if we are in a configuration file???
8528 if Present (Parent (N)) then
8530 ("pragma% can only appear in a configuration pragmas file");
8533 ----------------------
8534 -- Source_Reference --
8535 ----------------------
8537 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
8539 -- Nothing to do, all processing completed in Par.Prag, since we
8540 -- need the information for possible parser messages that are output
8542 when Pragma_Source_Reference =>
8549 -- pragma Storage_Size (EXPRESSION);
8551 when Pragma_Storage_Size => Storage_Size : declare
8552 P : constant Node_Id := Parent (N);
8556 Check_No_Identifiers;
8557 Check_Arg_Count (1);
8559 -- The expression must be analyzed in the special manner
8560 -- described in "Handling of Default Expressions" in sem.ads.
8562 -- Set In_Default_Expression for per-object case ???
8564 Arg := Expression (Arg1);
8565 Analyze_Per_Use_Expression (Arg, Any_Integer);
8567 if not Is_Static_Expression (Arg) then
8568 Check_Restriction (Static_Storage_Size, Arg);
8571 if Nkind (P) /= N_Task_Definition then
8576 if Has_Storage_Size_Pragma (P) then
8577 Error_Pragma ("duplicate pragma% not allowed");
8579 Set_Has_Storage_Size_Pragma (P, True);
8582 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8583 -- ??? exp_ch9 should use this!
8591 -- pragma Storage_Unit (NUMERIC_LITERAL);
8593 -- Only permitted argument is System'Storage_Unit value
8595 when Pragma_Storage_Unit =>
8596 Check_No_Identifiers;
8597 Check_Arg_Count (1);
8598 Check_Arg_Is_Integer_Literal (Arg1);
8600 if Intval (Expression (Arg1)) /=
8601 UI_From_Int (Ttypes.System_Storage_Unit)
8603 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
8605 ("the only allowed argument for pragma% is ^", Arg1);
8608 --------------------
8609 -- Stream_Convert --
8610 --------------------
8612 -- pragma Stream_Convert (
8613 -- [Entity =>] type_LOCAL_NAME,
8614 -- [Read =>] function_NAME,
8615 -- [Write =>] function NAME);
8617 when Pragma_Stream_Convert => Stream_Convert : declare
8619 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
8620 -- Check that the given argument is the name of a local
8621 -- function of one argument that is not overloaded earlier
8622 -- in the current local scope. A check is also made that the
8623 -- argument is a function with one parameter.
8625 --------------------------------------
8626 -- Check_OK_Stream_Convert_Function --
8627 --------------------------------------
8629 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
8633 Check_Arg_Is_Local_Name (Arg);
8634 Ent := Entity (Expression (Arg));
8636 if Has_Homonym (Ent) then
8638 ("argument for pragma% may not be overloaded", Arg);
8641 if Ekind (Ent) /= E_Function
8642 or else No (First_Formal (Ent))
8643 or else Present (Next_Formal (First_Formal (Ent)))
8646 ("argument for pragma% must be" &
8647 " function of one argument", Arg);
8649 end Check_OK_Stream_Convert_Function;
8651 -- Start of procecessing for Stream_Convert
8655 Check_Arg_Count (3);
8656 Check_Optional_Identifier (Arg1, Name_Entity);
8657 Check_Optional_Identifier (Arg2, Name_Read);
8658 Check_Optional_Identifier (Arg3, Name_Write);
8659 Check_Arg_Is_Local_Name (Arg1);
8660 Check_OK_Stream_Convert_Function (Arg2);
8661 Check_OK_Stream_Convert_Function (Arg3);
8664 Typ : constant Entity_Id :=
8665 Underlying_Type (Entity (Expression (Arg1)));
8666 Read : constant Entity_Id := Entity (Expression (Arg2));
8667 Write : constant Entity_Id := Entity (Expression (Arg3));
8670 if Etype (Typ) = Any_Type
8672 Etype (Read) = Any_Type
8674 Etype (Write) = Any_Type
8679 Check_First_Subtype (Arg1);
8681 if Rep_Item_Too_Early (Typ, N)
8683 Rep_Item_Too_Late (Typ, N)
8688 if Underlying_Type (Etype (Read)) /= Typ then
8690 ("incorrect return type for function&", Arg2);
8693 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
8695 ("incorrect parameter type for function&", Arg3);
8698 if Underlying_Type (Etype (First_Formal (Read))) /=
8699 Underlying_Type (Etype (Write))
8702 ("result type of & does not match Read parameter type",
8708 -------------------------
8709 -- Style_Checks (GNAT) --
8710 -------------------------
8712 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
8714 -- This is processed by the parser since some of the style
8715 -- checks take place during source scanning and parsing. This
8716 -- means that we don't need to issue error messages here.
8718 when Pragma_Style_Checks => Style_Checks : declare
8719 A : constant Node_Id := Expression (Arg1);
8725 Check_No_Identifiers;
8727 -- Two argument form
8729 if Arg_Count = 2 then
8730 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8737 E_Id := Expression (Arg2);
8740 if not Is_Entity_Name (E_Id) then
8742 ("second argument of pragma% must be entity name",
8752 Set_Suppress_Style_Checks (E,
8753 (Chars (Expression (Arg1)) = Name_Off));
8754 exit when No (Homonym (E));
8760 -- One argument form
8763 Check_Arg_Count (1);
8765 if Nkind (A) = N_String_Literal then
8769 Slen : constant Natural := Natural (String_Length (S));
8770 Options : String (1 .. Slen);
8776 C := Get_String_Char (S, Int (J));
8777 exit when not In_Character_Range (C);
8778 Options (J) := Get_Character (C);
8781 Set_Style_Check_Options (Options);
8789 elsif Nkind (A) = N_Identifier then
8791 if Chars (A) = Name_All_Checks then
8792 Set_Default_Style_Check_Options;
8794 elsif Chars (A) = Name_On then
8795 Style_Check := True;
8797 elsif Chars (A) = Name_Off then
8798 Style_Check := False;
8809 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
8811 when Pragma_Subtitle =>
8813 Check_Arg_Count (1);
8814 Check_Optional_Identifier (Arg1, Name_Subtitle);
8815 Check_Arg_Is_String_Literal (Arg1);
8821 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
8823 when Pragma_Suppress =>
8824 Process_Suppress_Unsuppress (True);
8830 -- pragma Suppress_All;
8832 -- The only check made here is that the pragma appears in the
8833 -- proper place, i.e. following a compilation unit. If indeed
8834 -- it appears in this context, then the parser has already
8835 -- inserted an equivalent pragma Suppress (All_Checks) to get
8836 -- the required effect.
8838 when Pragma_Suppress_All =>
8840 Check_Arg_Count (0);
8842 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
8843 or else not Is_List_Member (N)
8844 or else List_Containing (N) /= Pragmas_After (Parent (N))
8847 ("misplaced pragma%, must follow compilation unit");
8850 -------------------------
8851 -- Suppress_Debug_Info --
8852 -------------------------
8854 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
8856 when Pragma_Suppress_Debug_Info =>
8858 Check_Arg_Count (1);
8859 Check_Arg_Is_Local_Name (Arg1);
8860 Check_Optional_Identifier (Arg1, Name_Entity);
8861 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
8863 ----------------------------------
8864 -- Suppress_Exception_Locations --
8865 ----------------------------------
8867 -- pragma Suppress_Exception_Locations;
8869 when Pragma_Suppress_Exception_Locations =>
8871 Check_Arg_Count (0);
8872 Check_Valid_Configuration_Pragma;
8873 Exception_Locations_Suppressed := True;
8875 -----------------------------
8876 -- Suppress_Initialization --
8877 -----------------------------
8879 -- pragma Suppress_Initialization ([Entity =>] type_Name);
8881 when Pragma_Suppress_Initialization => Suppress_Init : declare
8887 Check_Arg_Count (1);
8888 Check_Optional_Identifier (Arg1, Name_Entity);
8889 Check_Arg_Is_Local_Name (Arg1);
8891 E_Id := Expression (Arg1);
8893 if Etype (E_Id) = Any_Type then
8900 if Is_Incomplete_Or_Private_Type (E) then
8901 if No (Full_View (Base_Type (E))) then
8903 ("argument of pragma% cannot be an incomplete type",
8906 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
8909 Set_Suppress_Init_Proc (Base_Type (E));
8914 ("pragma% requires argument that is a type name", Arg1);
8922 -- pragma System_Name (DIRECT_NAME);
8924 -- Syntax check: one argument, which must be the identifier GNAT
8925 -- or the identifier GCC, no other identifiers are acceptable.
8927 when Pragma_System_Name =>
8928 Check_No_Identifiers;
8929 Check_Arg_Count (1);
8930 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
8932 -----------------------------
8933 -- Task_Dispatching_Policy --
8934 -----------------------------
8936 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
8938 when Pragma_Task_Dispatching_Policy => declare
8942 Check_Ada_83_Warning;
8943 Check_Arg_Count (1);
8944 Check_No_Identifiers;
8945 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
8946 Check_Valid_Configuration_Pragma;
8947 Get_Name_String (Chars (Expression (Arg1)));
8948 DP := Fold_Upper (Name_Buffer (1));
8950 if Task_Dispatching_Policy /= ' '
8951 and then Task_Dispatching_Policy /= DP
8953 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
8955 ("task dispatching policy incompatible with policy#");
8957 -- Set new policy, but always preserve System_Location since
8958 -- we like the error message with the run time name.
8961 Task_Dispatching_Policy := DP;
8963 if Task_Dispatching_Policy_Sloc /= System_Location then
8964 Task_Dispatching_Policy_Sloc := Loc;
8973 -- pragma Task_Info (EXPRESSION);
8975 when Pragma_Task_Info => Task_Info : declare
8976 P : constant Node_Id := Parent (N);
8981 if Nkind (P) /= N_Task_Definition then
8982 Error_Pragma ("pragma% must appear in task definition");
8985 Check_No_Identifiers;
8986 Check_Arg_Count (1);
8988 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
8990 if Etype (Expression (Arg1)) = Any_Type then
8994 if Has_Task_Info_Pragma (P) then
8995 Error_Pragma ("duplicate pragma% not allowed");
8997 Set_Has_Task_Info_Pragma (P, True);
9005 -- pragma Task_Name (string_EXPRESSION);
9007 when Pragma_Task_Name => Task_Name : declare
9008 -- pragma Priority (EXPRESSION);
9010 P : constant Node_Id := Parent (N);
9014 Check_No_Identifiers;
9015 Check_Arg_Count (1);
9017 Arg := Expression (Arg1);
9018 Analyze_And_Resolve (Arg, Standard_String);
9020 if Nkind (P) /= N_Task_Definition then
9024 if Has_Task_Name_Pragma (P) then
9025 Error_Pragma ("duplicate pragma% not allowed");
9027 Set_Has_Task_Name_Pragma (P, True);
9028 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9036 -- pragma Task_Storage (
9037 -- [Task_Type =>] LOCAL_NAME,
9038 -- [Top_Guard =>] static_integer_EXPRESSION);
9040 when Pragma_Task_Storage => Task_Storage : declare
9041 Args : Args_List (1 .. 2);
9042 Names : constant Name_List (1 .. 2) := (
9046 Task_Type : Node_Id renames Args (1);
9047 Top_Guard : Node_Id renames Args (2);
9053 Gather_Associations (Names, Args);
9055 if No (Task_Type) then
9057 ("missing task_type argument for pragma%");
9060 Check_Arg_Is_Local_Name (Task_Type);
9062 Ent := Entity (Task_Type);
9064 if not Is_Task_Type (Ent) then
9066 ("argument for pragma% must be task type", Task_Type);
9069 if No (Top_Guard) then
9071 ("pragma% takes two arguments", Task_Type);
9073 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
9076 Check_First_Subtype (Task_Type);
9078 if Rep_Item_Too_Late (Ent, N) then
9087 -- pragma Time_Slice (static_duration_EXPRESSION);
9089 when Pragma_Time_Slice => Time_Slice : declare
9095 Check_Arg_Count (1);
9096 Check_No_Identifiers;
9097 Check_In_Main_Program;
9098 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
9100 if not Error_Posted (Arg1) then
9102 while Present (Nod) loop
9103 if Nkind (Nod) = N_Pragma
9104 and then Chars (Nod) = Name_Time_Slice
9106 Error_Msg_Name_1 := Chars (N);
9107 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9114 -- Process only if in main unit
9116 if Get_Source_Unit (Loc) = Main_Unit then
9117 Opt.Time_Slice_Set := True;
9118 Val := Expr_Value_R (Expression (Arg1));
9120 if Val <= Ureal_0 then
9121 Opt.Time_Slice_Value := 0;
9123 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
9124 Opt.Time_Slice_Value := 1_000_000_000;
9127 Opt.Time_Slice_Value :=
9128 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
9137 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
9139 -- TITLING_OPTION ::=
9140 -- [Title =>] STRING_LITERAL
9141 -- | [Subtitle =>] STRING_LITERAL
9143 when Pragma_Title => Title : declare
9144 Args : Args_List (1 .. 2);
9145 Names : constant Name_List (1 .. 2) := (
9151 Gather_Associations (Names, Args);
9153 for J in 1 .. 2 loop
9154 if Present (Args (J)) then
9155 Check_Arg_Is_String_Literal (Args (J));
9160 ---------------------
9161 -- Unchecked_Union --
9162 ---------------------
9164 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
9166 when Pragma_Unchecked_Union => Unchecked_Union : declare
9167 Assoc : constant Node_Id := Arg1;
9168 Type_Id : constant Node_Id := Expression (Assoc);
9179 Check_No_Identifiers;
9180 Check_Arg_Count (1);
9181 Check_Arg_Is_Local_Name (Arg1);
9183 Find_Type (Type_Id);
9184 Typ := Entity (Type_Id);
9187 or else Rep_Item_Too_Early (Typ, N)
9191 Typ := Underlying_Type (Typ);
9194 if Rep_Item_Too_Late (Typ, N) then
9198 Check_First_Subtype (Arg1);
9200 -- Note remaining cases are references to a type in the current
9201 -- declarative part. If we find an error, we post the error on
9202 -- the relevant type declaration at an appropriate point.
9204 if not Is_Record_Type (Typ) then
9205 Error_Msg_N ("Unchecked_Union must be record type", Typ);
9208 elsif Is_Tagged_Type (Typ) then
9209 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
9212 elsif Is_Limited_Type (Typ) then
9214 ("Unchecked_Union must not be limited record type", Typ);
9215 Explain_Limited_Type (Typ, Typ);
9219 if not Has_Discriminants (Typ) then
9221 ("Unchecked_Union must have one discriminant", Typ);
9225 Discr := First_Discriminant (Typ);
9227 if Present (Next_Discriminant (Discr)) then
9229 ("Unchecked_Union must have exactly one discriminant",
9230 Next_Discriminant (Discr));
9234 if No (Discriminant_Default_Value (Discr)) then
9236 ("Unchecked_Union discriminant must have default value",
9240 Tdef := Type_Definition (Declaration_Node (Typ));
9241 Clist := Component_List (Tdef);
9243 if No (Clist) or else No (Variant_Part (Clist)) then
9245 ("Unchecked_Union must have variant part",
9250 Vpart := Variant_Part (Clist);
9252 if Is_Non_Empty_List (Component_Items (Clist)) then
9254 ("components before variant not allowed " &
9255 "in Unchecked_Union",
9256 First (Component_Items (Clist)));
9259 Variant := First (Variants (Vpart));
9260 while Present (Variant) loop
9261 Clist := Component_List (Variant);
9263 if Present (Variant_Part (Clist)) then
9265 ("Unchecked_Union may not have nested variants",
9266 Variant_Part (Clist));
9269 if not Is_Non_Empty_List (Component_Items (Clist)) then
9271 ("Unchecked_Union may not have empty component list",
9276 Comp := First (Component_Items (Clist));
9278 if Nkind (Comp) = N_Component_Declaration then
9280 if Present (Expression (Comp)) then
9282 ("default initialization not allowed " &
9283 "in Unchecked_Union",
9288 Sindic : constant Node_Id :=
9289 Subtype_Indication (Comp);
9292 if Nkind (Sindic) = N_Subtype_Indication then
9293 Check_Static_Constraint (Constraint (Sindic));
9298 if Present (Next (Comp)) then
9300 ("Unchecked_Union variant can have only one component",
9308 Set_Is_Unchecked_Union (Typ, True);
9309 Set_Convention (Typ, Convention_C);
9311 Set_Has_Unchecked_Union (Base_Type (Typ), True);
9312 Set_Is_Unchecked_Union (Base_Type (Typ), True);
9313 end Unchecked_Union;
9315 ------------------------
9316 -- Unimplemented_Unit --
9317 ------------------------
9319 -- pragma Unimplemented_Unit;
9321 -- Note: this only gives an error if we are generating code,
9322 -- or if we are in a generic library unit (where the pragma
9323 -- appears in the body, not in the spec).
9325 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
9326 Cunitent : constant Entity_Id :=
9327 Cunit_Entity (Get_Source_Unit (Loc));
9328 Ent_Kind : constant Entity_Kind :=
9333 Check_Arg_Count (0);
9335 if Operating_Mode = Generate_Code
9336 or else Ent_Kind = E_Generic_Function
9337 or else Ent_Kind = E_Generic_Procedure
9338 or else Ent_Kind = E_Generic_Package
9340 Get_Name_String (Chars (Cunitent));
9341 Set_Casing (Mixed_Case);
9342 Write_Str (Name_Buffer (1 .. Name_Len));
9343 Write_Str (" is not implemented");
9345 raise Unrecoverable_Error;
9347 end Unimplemented_Unit;
9349 --------------------
9350 -- Universal_Data --
9351 --------------------
9353 -- pragma Universal_Data [(library_unit_NAME)];
9355 when Pragma_Universal_Data =>
9358 -- If this is a configuration pragma, then set the universal
9359 -- addressing option, otherwise confirm that the pragma
9360 -- satisfies the requirements of library unit pragma placement
9361 -- and leave it to the GNAAMP back end to detect the pragma
9362 -- (avoids transitive setting of the option due to withed units).
9364 if Is_Configuration_Pragma then
9365 Universal_Addressing_On_AAMP := True;
9367 Check_Valid_Library_Unit_Pragma;
9370 if not AAMP_On_Target then
9371 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
9378 -- pragma Unreferenced (local_Name {, local_Name});
9380 when Pragma_Unreferenced => Unreferenced : declare
9383 Arg_Ent : Entity_Id;
9387 Check_At_Least_N_Arguments (1);
9391 while Present (Arg_Node) loop
9392 Check_No_Identifier (Arg_Node);
9394 -- Note that the analyze call done by Check_Arg_Is_Local_Name
9395 -- will in fact generate a reference, so that the entity will
9396 -- have a reference, which will inhibit any warnings about it
9397 -- not being referenced, and also properly show up in the ali
9398 -- file as a reference. But this reference is recorded before
9399 -- the Has_Pragma_Unreferenced flag is set, so that no warning
9400 -- is generated for this reference.
9402 Check_Arg_Is_Local_Name (Arg_Node);
9403 Arg_Expr := Get_Pragma_Arg (Arg_Node);
9405 if Is_Entity_Name (Arg_Expr) then
9406 Arg_Ent := Entity (Arg_Expr);
9408 -- If the entity is overloaded, the pragma applies to the
9409 -- most recent overloading, as documented. In this case,
9410 -- name resolution does not generate a reference, so it
9411 -- must be done here explicitly.
9413 if Is_Overloaded (Arg_Expr) then
9414 Generate_Reference (Arg_Ent, N);
9417 Set_Has_Pragma_Unreferenced (Arg_Ent);
9424 ------------------------------
9425 -- Unreserve_All_Interrupts --
9426 ------------------------------
9428 -- pragma Unreserve_All_Interrupts;
9430 when Pragma_Unreserve_All_Interrupts =>
9432 Check_Arg_Count (0);
9434 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
9435 Unreserve_All_Interrupts := True;
9442 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
9444 when Pragma_Unsuppress =>
9446 Process_Suppress_Unsuppress (False);
9452 -- pragma Use_VADS_Size;
9454 when Pragma_Use_VADS_Size =>
9456 Check_Arg_Count (0);
9457 Check_Valid_Configuration_Pragma;
9458 Use_VADS_Size := True;
9460 ---------------------
9461 -- Validity_Checks --
9462 ---------------------
9464 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
9466 when Pragma_Validity_Checks => Validity_Checks : declare
9467 A : constant Node_Id := Expression (Arg1);
9473 Check_Arg_Count (1);
9474 Check_No_Identifiers;
9476 if Nkind (A) = N_String_Literal then
9480 Slen : constant Natural := Natural (String_Length (S));
9481 Options : String (1 .. Slen);
9487 C := Get_String_Char (S, Int (J));
9488 exit when not In_Character_Range (C);
9489 Options (J) := Get_Character (C);
9492 Set_Validity_Check_Options (Options);
9500 elsif Nkind (A) = N_Identifier then
9502 if Chars (A) = Name_All_Checks then
9503 Set_Validity_Check_Options ("a");
9505 elsif Chars (A) = Name_On then
9506 Validity_Checks_On := True;
9508 elsif Chars (A) = Name_Off then
9509 Validity_Checks_On := False;
9513 end Validity_Checks;
9519 -- pragma Volatile (LOCAL_NAME);
9521 when Pragma_Volatile =>
9522 Process_Atomic_Shared_Volatile;
9524 -------------------------
9525 -- Volatile_Components --
9526 -------------------------
9528 -- pragma Volatile_Components (array_LOCAL_NAME);
9530 -- Volatile is handled by the same circuit as Atomic_Components
9536 -- pragma Warnings (On | Off, [LOCAL_NAME])
9538 when Pragma_Warnings => Warnings : begin
9540 Check_At_Least_N_Arguments (1);
9541 Check_At_Most_N_Arguments (2);
9542 Check_No_Identifiers;
9544 -- One argument case was processed by parser in Par.Prag
9546 if Arg_Count /= 1 then
9547 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9548 Check_Arg_Count (2);
9555 E_Id := Expression (Arg2);
9558 if not Is_Entity_Name (E_Id) then
9560 ("second argument of pragma% must be entity name",
9570 Set_Warnings_Off (E,
9571 (Chars (Expression (Arg1)) = Name_Off));
9573 if Is_Enumeration_Type (E) then
9575 Lit : Entity_Id := First_Literal (E);
9578 while Present (Lit) loop
9579 Set_Warnings_Off (Lit);
9585 exit when No (Homonym (E));
9597 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
9599 when Pragma_Weak_External => Weak_External : declare
9604 Check_Arg_Count (1);
9605 Check_Optional_Identifier (Arg1, Name_Entity);
9606 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9607 Ent := Entity (Expression (Arg1));
9609 if Rep_Item_Too_Early (Ent, N) then
9612 Ent := Underlying_Type (Ent);
9615 -- The only processing required is to link this item on to the
9616 -- list of rep items for the given entity. This is accomplished
9617 -- by the call to Rep_Item_Too_Late (when no error is detected
9618 -- and False is returned).
9620 if Rep_Item_Too_Late (Ent, N) then
9623 Set_Has_Gigi_Rep_Item (Ent);
9627 --------------------
9628 -- Unknown_Pragma --
9629 --------------------
9631 -- Should be impossible, since the case of an unknown pragma is
9632 -- separately processed before the case statement is entered.
9634 when Unknown_Pragma =>
9635 raise Program_Error;
9640 when Pragma_Exit => null;
9643 ---------------------------------
9644 -- Delay_Config_Pragma_Analyze --
9645 ---------------------------------
9647 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
9649 return Chars (N) = Name_Interrupt_State;
9650 end Delay_Config_Pragma_Analyze;
9652 -------------------------
9653 -- Get_Base_Subprogram --
9654 -------------------------
9656 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
9662 -- Follow subprogram renaming chain
9664 while Is_Subprogram (Result)
9666 (Is_Generic_Instance (Result)
9667 or else Nkind (Parent (Declaration_Node (Result))) =
9668 N_Subprogram_Renaming_Declaration)
9669 and then Present (Alias (Result))
9671 Result := Alias (Result);
9675 end Get_Base_Subprogram;
9677 -----------------------------------------
9678 -- Is_Non_Significant_Pragma_Reference --
9679 -----------------------------------------
9681 -- This function makes use of the following static table which indicates
9682 -- whether a given pragma is significant. A value of -1 in this table
9683 -- indicates that the reference is significant. A value of zero indicates
9684 -- than appearence as any argument is insignificant, a positive value
9685 -- indicates that appearence in that parameter position is significant.
9687 Sig_Flags : array (Pragma_Id) of Int :=
9688 (Pragma_AST_Entry => -1,
9689 Pragma_Abort_Defer => -1,
9690 Pragma_Ada_83 => -1,
9691 Pragma_Ada_95 => -1,
9692 Pragma_All_Calls_Remote => -1,
9693 Pragma_Annotate => -1,
9694 Pragma_Assert => -1,
9695 Pragma_Asynchronous => -1,
9697 Pragma_Atomic_Components => 0,
9698 Pragma_Attach_Handler => -1,
9699 Pragma_CPP_Class => 0,
9700 Pragma_CPP_Constructor => 0,
9701 Pragma_CPP_Virtual => 0,
9702 Pragma_CPP_Vtable => 0,
9703 Pragma_C_Pass_By_Copy => 0,
9704 Pragma_Comment => 0,
9705 Pragma_Common_Object => -1,
9706 Pragma_Compile_Time_Warning => -1,
9707 Pragma_Complex_Representation => 0,
9708 Pragma_Component_Alignment => -1,
9709 Pragma_Controlled => 0,
9710 Pragma_Convention => 0,
9711 Pragma_Convention_Identifier => 0,
9713 Pragma_Discard_Names => 0,
9714 Pragma_Elaborate => -1,
9715 Pragma_Elaborate_All => -1,
9716 Pragma_Elaborate_Body => -1,
9717 Pragma_Elaboration_Checks => -1,
9718 Pragma_Eliminate => -1,
9719 Pragma_Explicit_Overriding => -1,
9720 Pragma_Export => -1,
9721 Pragma_Export_Exception => -1,
9722 Pragma_Export_Function => -1,
9723 Pragma_Export_Object => -1,
9724 Pragma_Export_Procedure => -1,
9725 Pragma_Export_Value => -1,
9726 Pragma_Export_Valued_Procedure => -1,
9727 Pragma_Extend_System => -1,
9728 Pragma_Extensions_Allowed => -1,
9729 Pragma_External => -1,
9730 Pragma_External_Name_Casing => -1,
9731 Pragma_Finalize_Storage_Only => 0,
9732 Pragma_Float_Representation => 0,
9734 Pragma_Import => +2,
9735 Pragma_Import_Exception => 0,
9736 Pragma_Import_Function => 0,
9737 Pragma_Import_Object => 0,
9738 Pragma_Import_Procedure => 0,
9739 Pragma_Import_Valued_Procedure => 0,
9740 Pragma_Initialize_Scalars => -1,
9742 Pragma_Inline_Always => 0,
9743 Pragma_Inline_Generic => 0,
9744 Pragma_Inspection_Point => -1,
9745 Pragma_Interface => +2,
9746 Pragma_Interface_Name => +2,
9747 Pragma_Interrupt_Handler => -1,
9748 Pragma_Interrupt_Priority => -1,
9749 Pragma_Interrupt_State => -1,
9750 Pragma_Java_Constructor => -1,
9751 Pragma_Java_Interface => -1,
9752 Pragma_Keep_Names => 0,
9753 Pragma_License => -1,
9754 Pragma_Link_With => -1,
9755 Pragma_Linker_Alias => -1,
9756 Pragma_Linker_Options => -1,
9757 Pragma_Linker_Section => -1,
9759 Pragma_Locking_Policy => -1,
9760 Pragma_Long_Float => -1,
9761 Pragma_Machine_Attribute => -1,
9763 Pragma_Main_Storage => -1,
9764 Pragma_Memory_Size => -1,
9765 Pragma_No_Return => 0,
9766 Pragma_No_Run_Time => -1,
9767 Pragma_Normalize_Scalars => -1,
9768 Pragma_Obsolescent => 0,
9769 Pragma_Optimize => -1,
9770 Pragma_Optional_Overriding => -1,
9771 Pragma_Overriding => -1,
9774 Pragma_Passive => -1,
9775 Pragma_Polling => -1,
9776 Pragma_Persistent_Data => -1,
9777 Pragma_Persistent_Object => -1,
9778 Pragma_Preelaborate => -1,
9779 Pragma_Priority => -1,
9780 Pragma_Propagate_Exceptions => -1,
9781 Pragma_Psect_Object => -1,
9783 Pragma_Pure_Function => 0,
9784 Pragma_Queuing_Policy => -1,
9785 Pragma_Ravenscar => -1,
9786 Pragma_Remote_Call_Interface => -1,
9787 Pragma_Remote_Types => -1,
9788 Pragma_Restricted_Run_Time => -1,
9789 Pragma_Restriction_Warnings => -1,
9790 Pragma_Restrictions => -1,
9791 Pragma_Reviewable => -1,
9792 Pragma_Share_Generic => -1,
9793 Pragma_Shared => -1,
9794 Pragma_Shared_Passive => -1,
9795 Pragma_Source_File_Name => -1,
9796 Pragma_Source_File_Name_Project => -1,
9797 Pragma_Source_Reference => -1,
9798 Pragma_Storage_Size => -1,
9799 Pragma_Storage_Unit => -1,
9800 Pragma_Stream_Convert => -1,
9801 Pragma_Style_Checks => -1,
9802 Pragma_Subtitle => -1,
9803 Pragma_Suppress => 0,
9804 Pragma_Suppress_Exception_Locations => 0,
9805 Pragma_Suppress_All => -1,
9806 Pragma_Suppress_Debug_Info => 0,
9807 Pragma_Suppress_Initialization => 0,
9808 Pragma_System_Name => -1,
9809 Pragma_Task_Dispatching_Policy => -1,
9810 Pragma_Task_Info => -1,
9811 Pragma_Task_Name => -1,
9812 Pragma_Task_Storage => 0,
9813 Pragma_Time_Slice => -1,
9815 Pragma_Unchecked_Union => -1,
9816 Pragma_Unimplemented_Unit => -1,
9817 Pragma_Universal_Data => -1,
9818 Pragma_Unreferenced => -1,
9819 Pragma_Unreserve_All_Interrupts => -1,
9820 Pragma_Unsuppress => 0,
9821 Pragma_Use_VADS_Size => -1,
9822 Pragma_Validity_Checks => -1,
9823 Pragma_Volatile => 0,
9824 Pragma_Volatile_Components => 0,
9825 Pragma_Warnings => -1,
9826 Pragma_Weak_External => 0,
9827 Unknown_Pragma => 0);
9829 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
9837 if Nkind (P) /= N_Pragma_Argument_Association then
9841 C := Sig_Flags (Get_Pragma_Id (Chars (Parent (P))));
9851 A := First (Pragma_Argument_Associations (Parent (P)));
9852 for J in 1 .. C - 1 loop
9863 end Is_Non_Significant_Pragma_Reference;
9865 ------------------------------
9866 -- Is_Pragma_String_Literal --
9867 ------------------------------
9869 -- This function returns true if the corresponding pragma argument is
9870 -- a static string expression. These are the only cases in which string
9871 -- literals can appear as pragma arguments. We also allow a string
9872 -- literal as the first argument to pragma Assert (although it will
9873 -- of course always generate a type error).
9875 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
9876 Pragn : constant Node_Id := Parent (Par);
9877 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
9878 Pname : constant Name_Id := Chars (Pragn);
9891 if Pname = Name_Assert then
9894 elsif Pname = Name_Export then
9897 elsif Pname = Name_Ident then
9900 elsif Pname = Name_Import then
9903 elsif Pname = Name_Interface_Name then
9906 elsif Pname = Name_Linker_Alias then
9909 elsif Pname = Name_Linker_Section then
9912 elsif Pname = Name_Machine_Attribute then
9915 elsif Pname = Name_Source_File_Name then
9918 elsif Pname = Name_Source_Reference then
9921 elsif Pname = Name_Title then
9924 elsif Pname = Name_Subtitle then
9930 end Is_Pragma_String_Literal;
9932 --------------------------------------
9933 -- Process_Compilation_Unit_Pragmas --
9934 --------------------------------------
9936 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
9938 -- A special check for pragma Suppress_All. This is a strange DEC
9939 -- pragma, strange because it comes at the end of the unit. If we
9940 -- have a pragma Suppress_All in the Pragmas_After of the current
9941 -- unit, then we insert a pragma Suppress (All_Checks) at the start
9942 -- of the context clause to ensure the correct processing.
9945 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
9949 if Present (PA) then
9951 while Present (P) loop
9952 if Chars (P) = Name_Suppress_All then
9953 Prepend_To (Context_Items (N),
9954 Make_Pragma (Sloc (P),
9955 Chars => Name_Suppress,
9956 Pragma_Argument_Associations => New_List (
9957 Make_Pragma_Argument_Association (Sloc (P),
9959 Make_Identifier (Sloc (P),
9960 Chars => Name_All_Checks)))));
9968 end Process_Compilation_Unit_Pragmas;
9970 --------------------------------
9971 -- Set_Encoded_Interface_Name --
9972 --------------------------------
9974 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
9975 Str : constant String_Id := Strval (S);
9976 Len : constant Int := String_Length (Str);
9981 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
9984 -- Stores encoded value of character code CC. The encoding we
9985 -- use an underscore followed by four lower case hex digits.
9989 Store_String_Char (Get_Char_Code ('_'));
9991 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
9993 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
9995 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
9997 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
10000 -- Start of processing for Set_Encoded_Interface_Name
10003 -- If first character is asterisk, this is a link name, and we
10004 -- leave it completely unmodified. We also ignore null strings
10005 -- (the latter case happens only in error cases) and no encoding
10006 -- should occur for Java interface names.
10009 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
10012 Set_Interface_Name (E, S);
10017 CC := Get_String_Char (Str, J);
10019 exit when not In_Character_Range (CC);
10021 C := Get_Character (CC);
10023 exit when C /= '_' and then C /= '$'
10024 and then C not in '0' .. '9'
10025 and then C not in 'a' .. 'z'
10026 and then C not in 'A' .. 'Z';
10029 Set_Interface_Name (E, S);
10037 -- Here we need to encode. The encoding we use as follows:
10038 -- three underscores + four hex digits (lower case)
10042 for J in 1 .. String_Length (Str) loop
10043 CC := Get_String_Char (Str, J);
10045 if not In_Character_Range (CC) then
10048 C := Get_Character (CC);
10050 if C = '_' or else C = '$'
10051 or else C in '0' .. '9'
10052 or else C in 'a' .. 'z'
10053 or else C in 'A' .. 'Z'
10055 Store_String_Char (CC);
10062 Set_Interface_Name (E,
10063 Make_String_Literal (Sloc (S),
10064 Strval => End_String));
10066 end Set_Encoded_Interface_Name;
10068 -------------------
10069 -- Set_Unit_Name --
10070 -------------------
10072 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
10077 if Nkind (N) = N_Identifier
10078 and then Nkind (With_Item) = N_Identifier
10080 Set_Entity (N, Entity (With_Item));
10082 elsif Nkind (N) = N_Selected_Component then
10083 Change_Selected_Component_To_Expanded_Name (N);
10084 Set_Entity (N, Entity (With_Item));
10085 Set_Entity (Selector_Name (N), Entity (N));
10087 Pref := Prefix (N);
10088 Scop := Scope (Entity (N));
10090 while Nkind (Pref) = N_Selected_Component loop
10091 Change_Selected_Component_To_Expanded_Name (Pref);
10092 Set_Entity (Selector_Name (Pref), Scop);
10093 Set_Entity (Pref, Scop);
10094 Pref := Prefix (Pref);
10095 Scop := Scope (Scop);
10098 Set_Entity (Pref, Scop);