1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Errout; use Errout;
39 with Exp_Dist; use Exp_Dist;
41 with Lib.Writ; use Lib.Writ;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Output; use Output;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Ch3; use Sem_Ch3;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch13; use Sem_Ch13;
57 with Sem_Dist; use Sem_Dist;
58 with Sem_Elim; use Sem_Elim;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Mech; use Sem_Mech;
62 with Sem_Res; use Sem_Res;
63 with Sem_Type; use Sem_Type;
64 with Sem_Util; use Sem_Util;
65 with Sem_VFpt; use Sem_VFpt;
66 with Sem_Warn; use Sem_Warn;
67 with Stand; use Stand;
68 with Sinfo; use Sinfo;
69 with Sinfo.CN; use Sinfo.CN;
70 with Sinput; use Sinput;
71 with Snames; use Snames;
72 with Stringt; use Stringt;
73 with Stylesw; use Stylesw;
75 with Targparm; use Targparm;
76 with Tbuild; use Tbuild;
78 with Uintp; use Uintp;
79 with Uname; use Uname;
80 with Urealp; use Urealp;
81 with Validsw; use Validsw;
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 -- Checking for Duplicated External Names --
142 --------------------------------------------
144 -- It is suspicious if two separate Export pragmas use the same external
145 -- name. The following table is used to diagnose this situation so that
146 -- an appropriate warning can be issued.
148 -- The Node_Id stored is for the N_String_Literal node created to
149 -- hold the value of the external name. The Sloc of this node is
150 -- used to cross-reference the location of the duplication.
152 package Externals is new Table.Table (
153 Table_Component_Type => Node_Id,
154 Table_Index_Type => Int,
155 Table_Low_Bound => 0,
156 Table_Initial => 100,
157 Table_Increment => 100,
158 Table_Name => "Name_Externals");
160 -------------------------------------
161 -- Local Subprograms and Variables --
162 -------------------------------------
164 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
165 -- This routine is used for possible casing adjustment of an explicit
166 -- external name supplied as a string literal (the node N), according
167 -- to the casing requirement of Opt.External_Name_Casing. If this is
168 -- set to As_Is, then the string literal is returned unchanged, but if
169 -- it is set to Uppercase or Lowercase, then a new string literal with
170 -- appropriate casing is constructed.
172 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
173 -- If Def_Id refers to a renamed subprogram, then the base subprogram
174 -- (the original one, following the renaming chain) is returned.
175 -- Otherwise the entity is returned unchanged. Should be in Einfo???
177 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
178 -- All the routines that check pragma arguments take either a pragma
179 -- argument association (in which case the expression of the argument
180 -- association is checked), or the expression directly. The function
181 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
182 -- is a pragma argument association node, then its expression is returned,
183 -- otherwise Arg is returned unchanged.
186 -- This is a dummy function called by the processing for pragma Reviewable.
187 -- It is there for assisting front end debugging. By placing a Reviewable
188 -- pragma in the source program, a breakpoint on rv catches this place in
189 -- the source, allowing convenient stepping to the point of interest.
191 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
192 -- Place semantic information on the argument of an Elaborate or
193 -- Elaborate_All pragma. Entity name for unit and its parents is
194 -- taken from item in previous with_clause that mentions the unit.
196 -------------------------------
197 -- Adjust_External_Name_Case --
198 -------------------------------
200 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
204 -- Adjust case of literal if required
206 if Opt.External_Name_Exp_Casing = As_Is then
210 -- Copy existing string
216 for J in 1 .. String_Length (Strval (N)) loop
217 CC := Get_String_Char (Strval (N), J);
219 if Opt.External_Name_Exp_Casing = Uppercase
220 and then CC >= Get_Char_Code ('a')
221 and then CC <= Get_Char_Code ('z')
223 Store_String_Char (CC - 32);
225 elsif Opt.External_Name_Exp_Casing = Lowercase
226 and then CC >= Get_Char_Code ('A')
227 and then CC <= Get_Char_Code ('Z')
229 Store_String_Char (CC + 32);
232 Store_String_Char (CC);
237 Make_String_Literal (Sloc (N),
238 Strval => End_String);
240 end Adjust_External_Name_Case;
242 ------------------------------
243 -- Analyze_PPC_In_Decl_Part --
244 ------------------------------
246 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
247 Arg1 : constant Node_Id :=
248 First (Pragma_Argument_Associations (N));
249 Arg2 : constant Node_Id := Next (Arg1);
252 -- Install formals and push subprogram spec onto scope stack
253 -- so that we can see the formals from the pragma.
258 -- Preanalyze the boolean expression, we treat this as a
259 -- spec expression (i.e. similar to a default expression).
261 Preanalyze_Spec_Expression
262 (Get_Pragma_Arg (Arg1), Standard_Boolean);
264 -- If there is a message argument, analyze it the same way
266 if Present (Arg2) then
267 Preanalyze_Spec_Expression
268 (Get_Pragma_Arg (Arg2), Standard_String);
271 -- Remove the subprogram from the scope stack now that the
272 -- pre-analysis of the precondition/postcondition is done.
275 end Analyze_PPC_In_Decl_Part;
281 procedure Analyze_Pragma (N : Node_Id) is
282 Loc : constant Source_Ptr := Sloc (N);
283 Pname : constant Name_Id := Pragma_Name (N);
286 Pragma_Exit : exception;
287 -- This exception is used to exit pragma processing completely. It
288 -- is used when an error is detected, and no further processing is
289 -- required. It is also used if an earlier error has left the tree
290 -- in a state where the pragma should not be processed.
293 -- Number of pragma argument associations
299 -- First four pragma arguments (pragma argument association nodes,
300 -- or Empty if the corresponding argument does not exist).
302 type Name_List is array (Natural range <>) of Name_Id;
303 type Args_List is array (Natural range <>) of Node_Id;
304 -- Types used for arguments to Check_Arg_Order and Gather_Associations
306 procedure Ada_2005_Pragma;
307 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
308 -- Ada 95 mode, these are implementation defined pragmas, so should be
309 -- caught by the No_Implementation_Pragmas restriction
311 procedure Check_Ada_83_Warning;
312 -- Issues a warning message for the current pragma if operating in Ada
313 -- 83 mode (used for language pragmas that are not a standard part of
314 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
317 procedure Check_Arg_Count (Required : Nat);
318 -- Check argument count for pragma is equal to given parameter.
319 -- If not, then issue an error message and raise Pragma_Exit.
321 -- Note: all routines whose name is Check_Arg_Is_xxx take an
322 -- argument Arg which can either be a pragma argument association,
323 -- in which case the check is applied to the expression of the
324 -- association or an expression directly.
326 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
327 -- Check that an argument has the right form for an EXTERNAL_NAME
328 -- parameter of an extended import/export pragma. The rule is that
329 -- the name must be an identifier or string literal (in Ada 83 mode)
330 -- or a static string expression (in Ada 95 mode).
332 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
333 -- Check the specified argument Arg to make sure that it is an
334 -- identifier. If not give error and raise Pragma_Exit.
336 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
337 -- Check the specified argument Arg to make sure that it is an
338 -- integer literal. If not give error and raise Pragma_Exit.
340 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
341 -- Check the specified argument Arg to make sure that it has the
342 -- proper syntactic form for a local name and meets the semantic
343 -- requirements for a local name. The local name is analyzed as
344 -- part of the processing for this call. In addition, the local
345 -- name is required to represent an entity at the library level.
347 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
348 -- Check the specified argument Arg to make sure that it has the
349 -- proper syntactic form for a local name and meets the semantic
350 -- requirements for a local name. The local name is analyzed as
351 -- part of the processing for this call.
353 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
354 -- Check the specified argument Arg to make sure that it is a valid
355 -- locking policy name. If not give error and raise Pragma_Exit.
357 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
358 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
359 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
360 -- Check the specified argument Arg to make sure that it is an
361 -- identifier whose name matches either N1 or N2 (or N3 if present).
362 -- If not then give error and raise Pragma_Exit.
364 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
365 -- Check the specified argument Arg to make sure that it is a valid
366 -- queuing policy name. If not give error and raise Pragma_Exit.
368 procedure Check_Arg_Is_Static_Expression
371 -- Check the specified argument Arg to make sure that it is a static
372 -- expression of the given type (i.e. it will be analyzed and resolved
373 -- using this type, which can be any valid argument to Resolve, e.g.
374 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
376 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
377 -- Check the specified argument Arg to make sure that it is a
378 -- string literal. If not give error and raise Pragma_Exit
380 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
381 -- Check the specified argument Arg to make sure that it is a valid
382 -- valid task dispatching policy name. If not give error and raise
385 procedure Check_Arg_Order (Names : Name_List);
386 -- Checks for an instance of two arguments with identifiers for the
387 -- current pragma which are not in the sequence indicated by Names,
388 -- and if so, generates a fatal message about bad order of arguments.
390 procedure Check_At_Least_N_Arguments (N : Nat);
391 -- Check there are at least N arguments present
393 procedure Check_At_Most_N_Arguments (N : Nat);
394 -- Check there are no more than N arguments present
396 procedure Check_Component (Comp : Node_Id);
397 -- Examine Unchecked_Union component for correct use of per-object
398 -- constrained subtypes, and for restrictions on finalizable components.
400 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
401 -- Nam is an N_String_Literal node containing the external name set
402 -- by an Import or Export pragma (or extended Import or Export pragma).
403 -- This procedure checks for possible duplications if this is the
404 -- export case, and if found, issues an appropriate error message.
406 procedure Check_First_Subtype (Arg : Node_Id);
407 -- Checks that Arg, whose expression is an entity name referencing
408 -- a subtype, does not reference a type that is not a first subtype.
410 procedure Check_In_Main_Program;
411 -- Common checks for pragmas that appear within a main program
412 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
414 procedure Check_Interrupt_Or_Attach_Handler;
415 -- Common processing for first argument of pragma Interrupt_Handler
416 -- or pragma Attach_Handler.
418 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
419 -- Check that pragma appears in a declarative part, or in a package
420 -- specification, i.e. that it does not occur in a statement sequence
423 procedure Check_No_Identifier (Arg : Node_Id);
424 -- Checks that the given argument does not have an identifier. If
425 -- an identifier is present, then an error message is issued, and
426 -- Pragma_Exit is raised.
428 procedure Check_No_Identifiers;
429 -- Checks that none of the arguments to the pragma has an identifier.
430 -- If any argument has an identifier, then an error message is issued,
431 -- and Pragma_Exit is raised.
433 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
434 -- Checks if the given argument has an identifier, and if so, requires
435 -- it to match the given identifier name. If there is a non-matching
436 -- identifier, then an error message is given and Error_Pragmas raised.
438 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
439 -- Checks if the given argument has an identifier, and if so, requires
440 -- it to match the given identifier name. If there is a non-matching
441 -- identifier, then an error message is given and Error_Pragmas raised.
442 -- In this version of the procedure, the identifier name is given as
443 -- a string with lower case letters.
445 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
446 -- Called to process a precondition or postcondition pragma. There are
449 -- The pragma appears after a subprogram spec
451 -- If the corresponding check is not enabled, the pragma is analyzed
452 -- but otherwise ignored and control returns with In_Body set False.
454 -- If the check is enabled, then the first step is to analyze the
455 -- pragma, but this is skipped if the subprogram spec appears within
456 -- a package specification (because this is the case where we delay
457 -- analysis till the end of the spec). Then (whether or not it was
458 -- analyzed), the pragma is chained to the subprogram in question
459 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
460 -- caller with In_Body set False.
462 -- The pragma appears at the start of subprogram body declarations
464 -- In this case an immediate return to the caller is made with
465 -- In_Body set True, and the pragma is NOT analyzed.
467 -- In all other cases, an error message for bad placement is given
469 procedure Check_Static_Constraint (Constr : Node_Id);
470 -- Constr is a constraint from an N_Subtype_Indication node from a
471 -- component constraint in an Unchecked_Union type. This routine checks
472 -- that the constraint is static as required by the restrictions for
475 procedure Check_Valid_Configuration_Pragma;
476 -- Legality checks for placement of a configuration pragma
478 procedure Check_Valid_Library_Unit_Pragma;
479 -- Legality checks for library unit pragmas. A special case arises for
480 -- pragmas in generic instances that come from copies of the original
481 -- library unit pragmas in the generic templates. In the case of other
482 -- than library level instantiations these can appear in contexts which
483 -- would normally be invalid (they only apply to the original template
484 -- and to library level instantiations), and they are simply ignored,
485 -- which is implemented by rewriting them as null statements.
487 procedure Check_Variant (Variant : Node_Id);
488 -- Check Unchecked_Union variant for lack of nested variants and
489 -- presence of at least one component.
491 procedure Error_Pragma (Msg : String);
492 pragma No_Return (Error_Pragma);
493 -- Outputs error message for current pragma. The message contains a %
494 -- that will be replaced with the pragma name, and the flag is placed
495 -- on the pragma itself. Pragma_Exit is then raised.
497 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
498 pragma No_Return (Error_Pragma_Arg);
499 -- Outputs error message for current pragma. The message may contain
500 -- a % that will be replaced with the pragma name. The parameter Arg
501 -- may either be a pragma argument association, in which case the flag
502 -- is placed on the expression of this association, or an expression,
503 -- in which case the flag is placed directly on the expression. The
504 -- message is placed using Error_Msg_N, so the message may also contain
505 -- an & insertion character which will reference the given Arg value.
506 -- After placing the message, Pragma_Exit is raised.
508 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
509 pragma No_Return (Error_Pragma_Arg);
510 -- Similar to above form of Error_Pragma_Arg except that two messages
511 -- are provided, the second is a continuation comment starting with \.
513 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
514 pragma No_Return (Error_Pragma_Arg_Ident);
515 -- Outputs error message for current pragma. The message may contain
516 -- a % that will be replaced with the pragma name. The parameter Arg
517 -- must be a pragma argument association with a non-empty identifier
518 -- (i.e. its Chars field must be set), and the error message is placed
519 -- on the identifier. The message is placed using Error_Msg_N so
520 -- the message may also contain an & insertion character which will
521 -- reference the identifier. After placing the message, Pragma_Exit
524 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
525 pragma No_Return (Error_Pragma_Ref);
526 -- Outputs error message for current pragma. The message may contain
527 -- a % that will be replaced with the pragma name. The parameter Ref
528 -- must be an entity whose name can be referenced by & and sloc by #.
529 -- After placing the message, Pragma_Exit is raised.
531 function Find_Lib_Unit_Name return Entity_Id;
532 -- Used for a library unit pragma to find the entity to which the
533 -- library unit pragma applies, returns the entity found.
535 procedure Find_Program_Unit_Name (Id : Node_Id);
536 -- If the pragma is a compilation unit pragma, the id must denote the
537 -- compilation unit in the same compilation, and the pragma must appear
538 -- in the list of preceding or trailing pragmas. If it is a program
539 -- unit pragma that is not a compilation unit pragma, then the
540 -- identifier must be visible.
542 function Find_Unique_Parameterless_Procedure
544 Arg : Node_Id) return Entity_Id;
545 -- Used for a procedure pragma to find the unique parameterless
546 -- procedure identified by Name, returns it if it exists, otherwise
547 -- errors out and uses Arg as the pragma argument for the message.
549 procedure Gather_Associations
551 Args : out Args_List);
552 -- This procedure is used to gather the arguments for a pragma that
553 -- permits arbitrary ordering of parameters using the normal rules
554 -- for named and positional parameters. The Names argument is a list
555 -- of Name_Id values that corresponds to the allowed pragma argument
556 -- association identifiers in order. The result returned in Args is
557 -- a list of corresponding expressions that are the pragma arguments.
558 -- Note that this is a list of expressions, not of pragma argument
559 -- associations (Gather_Associations has completely checked all the
560 -- optional identifiers when it returns). An entry in Args is Empty
561 -- on return if the corresponding argument is not present.
563 procedure GNAT_Pragma;
564 -- Called for all GNAT defined pragmas to check the relevant restriction
565 -- (No_Implementation_Pragmas).
567 function Is_Before_First_Decl
568 (Pragma_Node : Node_Id;
569 Decls : List_Id) return Boolean;
570 -- Return True if Pragma_Node is before the first declarative item in
571 -- Decls where Decls is the list of declarative items.
573 function Is_Configuration_Pragma return Boolean;
574 -- Determines if the placement of the current pragma is appropriate
575 -- for a configuration pragma.
577 function Is_In_Context_Clause return Boolean;
578 -- Returns True if pragma appears within the context clause of a unit,
579 -- and False for any other placement (does not generate any messages).
581 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
582 -- Analyzes the argument, and determines if it is a static string
583 -- expression, returns True if so, False if non-static or not String.
585 procedure Pragma_Misplaced;
586 pragma No_Return (Pragma_Misplaced);
587 -- Issue fatal error message for misplaced pragma
589 procedure Process_Atomic_Shared_Volatile;
590 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
591 -- Shared is an obsolete Ada 83 pragma, treated as being identical
592 -- in effect to pragma Atomic.
594 procedure Process_Compile_Time_Warning_Or_Error;
595 -- Common processing for Compile_Time_Error and Compile_Time_Warning
597 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
598 -- Common processing for Convention, Interface, Import and Export.
599 -- Checks first two arguments of pragma, and sets the appropriate
600 -- convention value in the specified entity or entities. On return
601 -- C is the convention, E is the referenced entity.
603 procedure Process_Extended_Import_Export_Exception_Pragma
604 (Arg_Internal : Node_Id;
605 Arg_External : Node_Id;
608 -- Common processing for the pragmas Import/Export_Exception.
609 -- The three arguments correspond to the three named parameters of
610 -- the pragma. An argument is empty if the corresponding parameter
611 -- is not present in the pragma.
613 procedure Process_Extended_Import_Export_Object_Pragma
614 (Arg_Internal : Node_Id;
615 Arg_External : Node_Id;
617 -- Common processing for the pragmas Import/Export_Object.
618 -- The three arguments correspond to the three named parameters
619 -- of the pragmas. An argument is empty if the corresponding
620 -- parameter is not present in the pragma.
622 procedure Process_Extended_Import_Export_Internal_Arg
623 (Arg_Internal : Node_Id := Empty);
624 -- Common processing for all extended Import and Export pragmas. The
625 -- argument is the pragma parameter for the Internal argument. If
626 -- Arg_Internal is empty or inappropriate, an error message is posted.
627 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
628 -- set to identify the referenced entity.
630 procedure Process_Extended_Import_Export_Subprogram_Pragma
631 (Arg_Internal : Node_Id;
632 Arg_External : Node_Id;
633 Arg_Parameter_Types : Node_Id;
634 Arg_Result_Type : Node_Id := Empty;
635 Arg_Mechanism : Node_Id;
636 Arg_Result_Mechanism : Node_Id := Empty;
637 Arg_First_Optional_Parameter : Node_Id := Empty);
638 -- Common processing for all extended Import and Export pragmas
639 -- applying to subprograms. The caller omits any arguments that do
640 -- not apply to the pragma in question (for example, Arg_Result_Type
641 -- can be non-Empty only in the Import_Function and Export_Function
642 -- cases). The argument names correspond to the allowed pragma
643 -- association identifiers.
645 procedure Process_Generic_List;
646 -- Common processing for Share_Generic and Inline_Generic
648 procedure Process_Import_Or_Interface;
649 -- Common processing for Import of Interface
651 procedure Process_Inline (Active : Boolean);
652 -- Common processing for Inline and Inline_Always. The parameter
653 -- indicates if the inline pragma is active, i.e. if it should
654 -- actually cause inlining to occur.
656 procedure Process_Interface_Name
657 (Subprogram_Def : Entity_Id;
660 -- Given the last two arguments of pragma Import, pragma Export, or
661 -- pragma Interface_Name, performs validity checks and sets the
662 -- Interface_Name field of the given subprogram entity to the
663 -- appropriate external or link name, depending on the arguments
664 -- given. Ext_Arg is always present, but Link_Arg may be missing.
665 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
666 -- missing, and appropriate named notation is used for Ext_Arg.
667 -- If neither Ext_Arg nor Link_Arg is present, the interface name
668 -- is set to the default from the subprogram name.
670 procedure Process_Interrupt_Or_Attach_Handler;
671 -- Common processing for Interrupt and Attach_Handler pragmas
673 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
674 -- Common processing for Restrictions and Restriction_Warnings pragmas.
675 -- Warn is True for Restriction_Warnings, or for Restrictions if the
676 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
677 -- is not set in the Restrictions case.
679 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
680 -- Common processing for Suppress and Unsuppress. The boolean parameter
681 -- Suppress_Case is True for the Suppress case, and False for the
684 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
685 -- This procedure sets the Is_Exported flag for the given entity,
686 -- checking that the entity was not previously imported. Arg is
687 -- the argument that specified the entity. A check is also made
688 -- for exporting inappropriate entities.
690 procedure Set_Extended_Import_Export_External_Name
691 (Internal_Ent : Entity_Id;
692 Arg_External : Node_Id);
693 -- Common processing for all extended import export pragmas. The first
694 -- argument, Internal_Ent, is the internal entity, which has already
695 -- been checked for validity by the caller. Arg_External is from the
696 -- Import or Export pragma, and may be null if no External parameter
697 -- was present. If Arg_External is present and is a non-null string
698 -- (a null string is treated as the default), then the Interface_Name
699 -- field of Internal_Ent is set appropriately.
701 procedure Set_Imported (E : Entity_Id);
702 -- This procedure sets the Is_Imported flag for the given entity,
703 -- checking that it is not previously exported or imported.
705 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
706 -- Mech is a parameter passing mechanism (see Import_Function syntax
707 -- for MECHANISM_NAME). This routine checks that the mechanism argument
708 -- has the right form, and if not issues an error message. If the
709 -- argument has the right form then the Mechanism field of Ent is
710 -- set appropriately.
712 procedure Set_Ravenscar_Profile (N : Node_Id);
713 -- Activate the set of configuration pragmas and restrictions that
714 -- make up the Ravenscar Profile. N is the corresponding pragma
715 -- node, which is used for error messages on any constructs
716 -- that violate the profile.
718 ---------------------
719 -- Ada_2005_Pragma --
720 ---------------------
722 procedure Ada_2005_Pragma is
724 if Ada_Version <= Ada_95 then
725 Check_Restriction (No_Implementation_Pragmas, N);
729 --------------------------
730 -- Check_Ada_83_Warning --
731 --------------------------
733 procedure Check_Ada_83_Warning is
735 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
736 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
738 end Check_Ada_83_Warning;
740 ---------------------
741 -- Check_Arg_Count --
742 ---------------------
744 procedure Check_Arg_Count (Required : Nat) is
746 if Arg_Count /= Required then
747 Error_Pragma ("wrong number of arguments for pragma%");
751 --------------------------------
752 -- Check_Arg_Is_External_Name --
753 --------------------------------
755 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
756 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
759 if Nkind (Argx) = N_Identifier then
763 Analyze_And_Resolve (Argx, Standard_String);
765 if Is_OK_Static_Expression (Argx) then
768 elsif Etype (Argx) = Any_Type then
771 -- An interesting special case, if we have a string literal and
772 -- we are in Ada 83 mode, then we allow it even though it will
773 -- not be flagged as static. This allows expected Ada 83 mode
774 -- use of external names which are string literals, even though
775 -- technically these are not static in Ada 83.
777 elsif Ada_Version = Ada_83
778 and then Nkind (Argx) = N_String_Literal
782 -- Static expression that raises Constraint_Error. This has
783 -- already been flagged, so just exit from pragma processing.
785 elsif Is_Static_Expression (Argx) then
788 -- Here we have a real error (non-static expression)
791 Error_Msg_Name_1 := Pname;
793 ("argument for pragma% must be a identifier or " &
794 "static string expression!", Argx);
798 end Check_Arg_Is_External_Name;
800 -----------------------------
801 -- Check_Arg_Is_Identifier --
802 -----------------------------
804 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
805 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
807 if Nkind (Argx) /= N_Identifier then
809 ("argument for pragma% must be identifier", Argx);
811 end Check_Arg_Is_Identifier;
813 ----------------------------------
814 -- Check_Arg_Is_Integer_Literal --
815 ----------------------------------
817 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
818 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
820 if Nkind (Argx) /= N_Integer_Literal then
822 ("argument for pragma% must be integer literal", Argx);
824 end Check_Arg_Is_Integer_Literal;
826 -------------------------------------------
827 -- Check_Arg_Is_Library_Level_Local_Name --
828 -------------------------------------------
832 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
833 -- | library_unit_NAME
835 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
837 Check_Arg_Is_Local_Name (Arg);
839 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
840 and then Comes_From_Source (N)
843 ("argument for pragma% must be library level entity", Arg);
845 end Check_Arg_Is_Library_Level_Local_Name;
847 -----------------------------
848 -- Check_Arg_Is_Local_Name --
849 -----------------------------
853 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
854 -- | library_unit_NAME
856 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
857 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
862 if Nkind (Argx) not in N_Direct_Name
863 and then (Nkind (Argx) /= N_Attribute_Reference
864 or else Present (Expressions (Argx))
865 or else Nkind (Prefix (Argx)) /= N_Identifier)
866 and then (not Is_Entity_Name (Argx)
867 or else not Is_Compilation_Unit (Entity (Argx)))
869 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
872 if Is_Entity_Name (Argx)
873 and then Scope (Entity (Argx)) /= Current_Scope
876 ("pragma% argument must be in same declarative part", Arg);
878 end Check_Arg_Is_Local_Name;
880 ---------------------------------
881 -- Check_Arg_Is_Locking_Policy --
882 ---------------------------------
884 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
885 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
888 Check_Arg_Is_Identifier (Argx);
890 if not Is_Locking_Policy_Name (Chars (Argx)) then
892 ("& is not a valid locking policy name", Argx);
894 end Check_Arg_Is_Locking_Policy;
896 -------------------------
897 -- Check_Arg_Is_One_Of --
898 -------------------------
900 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
901 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
904 Check_Arg_Is_Identifier (Argx);
906 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
907 Error_Msg_Name_2 := N1;
908 Error_Msg_Name_3 := N2;
909 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
911 end Check_Arg_Is_One_Of;
913 procedure Check_Arg_Is_One_Of
915 N1, N2, N3 : Name_Id)
917 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
920 Check_Arg_Is_Identifier (Argx);
922 if Chars (Argx) /= N1
923 and then Chars (Argx) /= N2
924 and then Chars (Argx) /= N3
926 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
928 end Check_Arg_Is_One_Of;
930 procedure Check_Arg_Is_One_Of
932 N1, N2, N3, N4 : Name_Id)
934 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
937 Check_Arg_Is_Identifier (Argx);
939 if Chars (Argx) /= N1
940 and then Chars (Argx) /= N2
941 and then Chars (Argx) /= N3
942 and then Chars (Argx) /= N4
944 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
946 end Check_Arg_Is_One_Of;
948 ---------------------------------
949 -- Check_Arg_Is_Queuing_Policy --
950 ---------------------------------
952 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
953 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
956 Check_Arg_Is_Identifier (Argx);
958 if not Is_Queuing_Policy_Name (Chars (Argx)) then
960 ("& is not a valid queuing policy name", Argx);
962 end Check_Arg_Is_Queuing_Policy;
964 ------------------------------------
965 -- Check_Arg_Is_Static_Expression --
966 ------------------------------------
968 procedure Check_Arg_Is_Static_Expression
972 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
975 Analyze_And_Resolve (Argx, Typ);
977 if Is_OK_Static_Expression (Argx) then
980 elsif Etype (Argx) = Any_Type then
983 -- An interesting special case, if we have a string literal and
984 -- we are in Ada 83 mode, then we allow it even though it will
985 -- not be flagged as static. This allows the use of Ada 95
986 -- pragmas like Import in Ada 83 mode. They will of course be
987 -- flagged with warnings as usual, but will not cause errors.
989 elsif Ada_Version = Ada_83
990 and then Nkind (Argx) = N_String_Literal
994 -- Static expression that raises Constraint_Error. This has
995 -- already been flagged, so just exit from pragma processing.
997 elsif Is_Static_Expression (Argx) then
1000 -- Finally, we have a real error
1003 Error_Msg_Name_1 := Pname;
1004 Flag_Non_Static_Expr
1005 ("argument for pragma% must be a static expression!", Argx);
1008 end Check_Arg_Is_Static_Expression;
1010 ---------------------------------
1011 -- Check_Arg_Is_String_Literal --
1012 ---------------------------------
1014 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1015 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1017 if Nkind (Argx) /= N_String_Literal then
1019 ("argument for pragma% must be string literal", Argx);
1021 end Check_Arg_Is_String_Literal;
1023 ------------------------------------------
1024 -- Check_Arg_Is_Task_Dispatching_Policy --
1025 ------------------------------------------
1027 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1028 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1031 Check_Arg_Is_Identifier (Argx);
1033 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1035 ("& is not a valid task dispatching policy name", Argx);
1037 end Check_Arg_Is_Task_Dispatching_Policy;
1039 ---------------------
1040 -- Check_Arg_Order --
1041 ---------------------
1043 procedure Check_Arg_Order (Names : Name_List) is
1046 Highest_So_Far : Natural := 0;
1047 -- Highest index in Names seen do far
1051 for J in 1 .. Arg_Count loop
1052 if Chars (Arg) /= No_Name then
1053 for K in Names'Range loop
1054 if Chars (Arg) = Names (K) then
1055 if K < Highest_So_Far then
1056 Error_Msg_Name_1 := Pname;
1058 ("parameters out of order for pragma%", Arg);
1059 Error_Msg_Name_1 := Names (K);
1060 Error_Msg_Name_2 := Names (Highest_So_Far);
1061 Error_Msg_N ("\% must appear before %", Arg);
1065 Highest_So_Far := K;
1073 end Check_Arg_Order;
1075 --------------------------------
1076 -- Check_At_Least_N_Arguments --
1077 --------------------------------
1079 procedure Check_At_Least_N_Arguments (N : Nat) is
1081 if Arg_Count < N then
1082 Error_Pragma ("too few arguments for pragma%");
1084 end Check_At_Least_N_Arguments;
1086 -------------------------------
1087 -- Check_At_Most_N_Arguments --
1088 -------------------------------
1090 procedure Check_At_Most_N_Arguments (N : Nat) is
1093 if Arg_Count > N then
1095 for J in 1 .. N loop
1097 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1100 end Check_At_Most_N_Arguments;
1102 ---------------------
1103 -- Check_Component --
1104 ---------------------
1106 procedure Check_Component (Comp : Node_Id) is
1108 if Nkind (Comp) = N_Component_Declaration then
1110 Sindic : constant Node_Id :=
1111 Subtype_Indication (Component_Definition (Comp));
1112 Typ : constant Entity_Id :=
1113 Etype (Defining_Identifier (Comp));
1115 if Nkind (Sindic) = N_Subtype_Indication then
1117 -- Ada 2005 (AI-216): If a component subtype is subject to
1118 -- a per-object constraint, then the component type shall
1119 -- be an Unchecked_Union.
1121 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1123 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1125 Error_Msg_N ("component subtype subject to per-object" &
1126 " constraint must be an Unchecked_Union", Comp);
1130 if Is_Controlled (Typ) then
1132 ("component of unchecked union cannot be controlled", Comp);
1134 elsif Has_Task (Typ) then
1136 ("component of unchecked union cannot have tasks", Comp);
1140 end Check_Component;
1142 ----------------------------------
1143 -- Check_Duplicated_Export_Name --
1144 ----------------------------------
1146 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1147 String_Val : constant String_Id := Strval (Nam);
1150 -- We are only interested in the export case, and in the case of
1151 -- generics, it is the instance, not the template, that is the
1152 -- problem (the template will generate a warning in any case).
1154 if not Inside_A_Generic
1155 and then (Prag_Id = Pragma_Export
1157 Prag_Id = Pragma_Export_Procedure
1159 Prag_Id = Pragma_Export_Valued_Procedure
1161 Prag_Id = Pragma_Export_Function)
1163 for J in Externals.First .. Externals.Last loop
1164 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1165 Error_Msg_Sloc := Sloc (Externals.Table (J));
1166 Error_Msg_N ("external name duplicates name given#", Nam);
1171 Externals.Append (Nam);
1173 end Check_Duplicated_Export_Name;
1175 -------------------------
1176 -- Check_First_Subtype --
1177 -------------------------
1179 procedure Check_First_Subtype (Arg : Node_Id) is
1180 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1182 if not Is_First_Subtype (Entity (Argx)) then
1184 ("pragma% cannot apply to subtype", Argx);
1186 end Check_First_Subtype;
1188 ---------------------------
1189 -- Check_In_Main_Program --
1190 ---------------------------
1192 procedure Check_In_Main_Program is
1193 P : constant Node_Id := Parent (N);
1196 -- Must be at in subprogram body
1198 if Nkind (P) /= N_Subprogram_Body then
1199 Error_Pragma ("% pragma allowed only in subprogram");
1201 -- Otherwise warn if obviously not main program
1203 elsif Present (Parameter_Specifications (Specification (P)))
1204 or else not Is_Compilation_Unit (Defining_Entity (P))
1206 Error_Msg_Name_1 := Pname;
1208 ("?pragma% is only effective in main program", N);
1210 end Check_In_Main_Program;
1212 ---------------------------------------
1213 -- Check_Interrupt_Or_Attach_Handler --
1214 ---------------------------------------
1216 procedure Check_Interrupt_Or_Attach_Handler is
1217 Arg1_X : constant Node_Id := Expression (Arg1);
1218 Handler_Proc, Proc_Scope : Entity_Id;
1223 if Prag_Id = Pragma_Interrupt_Handler then
1224 Check_Restriction (No_Dynamic_Attachment, N);
1227 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1228 Proc_Scope := Scope (Handler_Proc);
1230 -- On AAMP only, a pragma Interrupt_Handler is supported for
1231 -- nonprotected parameterless procedures.
1233 if not AAMP_On_Target
1234 or else Prag_Id = Pragma_Attach_Handler
1236 if Ekind (Proc_Scope) /= E_Protected_Type then
1238 ("argument of pragma% must be protected procedure", Arg1);
1241 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1242 Error_Pragma ("pragma% must be in protected definition");
1246 if not Is_Library_Level_Entity (Proc_Scope)
1247 or else (AAMP_On_Target
1248 and then not Is_Library_Level_Entity (Handler_Proc))
1251 ("argument for pragma% must be library level entity", Arg1);
1253 end Check_Interrupt_Or_Attach_Handler;
1255 -------------------------------------------
1256 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1257 -------------------------------------------
1259 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1268 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1271 elsif Nkind (P) = N_Package_Specification then
1274 elsif Nkind (P) = N_Block_Statement then
1277 -- Note: the following tests seem a little peculiar, because
1278 -- they test for bodies, but if we were in the statement part
1279 -- of the body, we would already have hit the handled statement
1280 -- sequence, so the only way we get here is by being in the
1281 -- declarative part of the body.
1283 elsif Nkind (P) = N_Subprogram_Body
1284 or else Nkind (P) = N_Package_Body
1285 or else Nkind (P) = N_Task_Body
1286 or else Nkind (P) = N_Entry_Body
1294 Error_Pragma ("pragma% is not in declarative part or package spec");
1295 end Check_Is_In_Decl_Part_Or_Package_Spec;
1297 -------------------------
1298 -- Check_No_Identifier --
1299 -------------------------
1301 procedure Check_No_Identifier (Arg : Node_Id) is
1303 if Chars (Arg) /= No_Name then
1304 Error_Pragma_Arg_Ident
1305 ("pragma% does not permit identifier& here", Arg);
1307 end Check_No_Identifier;
1309 --------------------------
1310 -- Check_No_Identifiers --
1311 --------------------------
1313 procedure Check_No_Identifiers is
1316 if Arg_Count > 0 then
1318 while Present (Arg_Node) loop
1319 Check_No_Identifier (Arg_Node);
1323 end Check_No_Identifiers;
1325 -------------------------------
1326 -- Check_Optional_Identifier --
1327 -------------------------------
1329 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1331 if Present (Arg) and then Chars (Arg) /= No_Name then
1332 if Chars (Arg) /= Id then
1333 Error_Msg_Name_1 := Pname;
1334 Error_Msg_Name_2 := Id;
1335 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1339 end Check_Optional_Identifier;
1341 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1343 Name_Buffer (1 .. Id'Length) := Id;
1344 Name_Len := Id'Length;
1345 Check_Optional_Identifier (Arg, Name_Find);
1346 end Check_Optional_Identifier;
1348 --------------------------------------
1349 -- Check_Precondition_Postcondition --
1350 --------------------------------------
1352 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1356 procedure Chain_PPC (PO : Node_Id);
1357 -- PO is the N_Subprogram_Declaration node for the subprogram to
1358 -- which the precondition/postcondition applies. This procedure
1359 -- completes the processing for the pragma.
1365 procedure Chain_PPC (PO : Node_Id) is
1369 S := Defining_Unit_Name (Specification (PO));
1371 -- Analyze the pragma unless it appears within a package spec,
1372 -- which is the case where we delay the analysis of the PPC until
1373 -- the end of the package declarations (for details, see
1374 -- Analyze_Package_Specification.Analyze_PPCs).
1376 if Ekind (Scope (S)) /= E_Package
1378 Ekind (Scope (S)) /= E_Generic_Package
1380 Analyze_PPC_In_Decl_Part (N, S);
1383 -- Chain spec PPC pragma to list for subprogram
1385 Set_Next_Pragma (N, Spec_PPC_List (S));
1386 Set_Spec_PPC_List (S, N);
1388 -- Return indicating spec case
1394 -- Start of processing for Check_Precondition_Postcondition
1397 if not Is_List_Member (N) then
1401 -- Record whether pragma is enabled
1403 Set_PPC_Enabled (N, Check_Enabled (Pname));
1405 -- If we are within an inlined body, the legality of the pragma
1406 -- has been checked already.
1408 if In_Inlined_Body then
1413 -- Search prior declarations
1416 while Present (Prev (P)) loop
1418 PO := Original_Node (P);
1420 -- Skip past prior pragma
1422 if Nkind (PO) = N_Pragma then
1425 -- Skip stuff not coming from source
1427 elsif not Comes_From_Source (PO) then
1430 -- Here if we hit a subprogram declaration
1432 elsif Nkind (PO) = N_Subprogram_Declaration then
1436 -- If we encounter any other declaration moving back, misplaced
1443 -- If we fall through loop, pragma is at start of list, so see if
1444 -- it is at the start of declarations of a subprogram body.
1446 if Nkind (Parent (N)) = N_Subprogram_Body
1447 and then List_Containing (N) = Declarations (Parent (N))
1452 -- See if it is in the pragmas after a library level subprogram
1454 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1456 Decl : constant Node_Id := Unit (Parent (Parent (N)));
1458 if Nkind (Decl) = N_Subprogram_Declaration then
1465 -- If we fall through, pragma was misplaced
1468 end Check_Precondition_Postcondition;
1470 -----------------------------
1471 -- Check_Static_Constraint --
1472 -----------------------------
1474 -- Note: for convenience in writing this procedure, in addition to
1475 -- the officially (i.e. by spec) allowed argument which is always
1476 -- a constraint, it also allows ranges and discriminant associations.
1477 -- Above is not clear ???
1479 procedure Check_Static_Constraint (Constr : Node_Id) is
1481 procedure Require_Static (E : Node_Id);
1482 -- Require given expression to be static expression
1484 --------------------
1485 -- Require_Static --
1486 --------------------
1488 procedure Require_Static (E : Node_Id) is
1490 if not Is_OK_Static_Expression (E) then
1491 Flag_Non_Static_Expr
1492 ("non-static constraint not allowed in Unchecked_Union!", E);
1497 -- Start of processing for Check_Static_Constraint
1500 case Nkind (Constr) is
1501 when N_Discriminant_Association =>
1502 Require_Static (Expression (Constr));
1505 Require_Static (Low_Bound (Constr));
1506 Require_Static (High_Bound (Constr));
1508 when N_Attribute_Reference =>
1509 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1510 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1512 when N_Range_Constraint =>
1513 Check_Static_Constraint (Range_Expression (Constr));
1515 when N_Index_Or_Discriminant_Constraint =>
1519 IDC := First (Constraints (Constr));
1520 while Present (IDC) loop
1521 Check_Static_Constraint (IDC);
1529 end Check_Static_Constraint;
1531 --------------------------------------
1532 -- Check_Valid_Configuration_Pragma --
1533 --------------------------------------
1535 -- A configuration pragma must appear in the context clause of a
1536 -- compilation unit, and only other pragmas may precede it. Note that
1537 -- the test also allows use in a configuration pragma file.
1539 procedure Check_Valid_Configuration_Pragma is
1541 if not Is_Configuration_Pragma then
1542 Error_Pragma ("incorrect placement for configuration pragma%");
1544 end Check_Valid_Configuration_Pragma;
1546 -------------------------------------
1547 -- Check_Valid_Library_Unit_Pragma --
1548 -------------------------------------
1550 procedure Check_Valid_Library_Unit_Pragma is
1552 Parent_Node : Node_Id;
1553 Unit_Name : Entity_Id;
1554 Unit_Kind : Node_Kind;
1555 Unit_Node : Node_Id;
1556 Sindex : Source_File_Index;
1559 if not Is_List_Member (N) then
1563 Plist := List_Containing (N);
1564 Parent_Node := Parent (Plist);
1566 if Parent_Node = Empty then
1569 -- Case of pragma appearing after a compilation unit. In this
1570 -- case it must have an argument with the corresponding name
1571 -- and must be part of the following pragmas of its parent.
1573 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1574 if Plist /= Pragmas_After (Parent_Node) then
1577 elsif Arg_Count = 0 then
1579 ("argument required if outside compilation unit");
1582 Check_No_Identifiers;
1583 Check_Arg_Count (1);
1584 Unit_Node := Unit (Parent (Parent_Node));
1585 Unit_Kind := Nkind (Unit_Node);
1587 Analyze (Expression (Arg1));
1589 if Unit_Kind = N_Generic_Subprogram_Declaration
1590 or else Unit_Kind = N_Subprogram_Declaration
1592 Unit_Name := Defining_Entity (Unit_Node);
1594 elsif Unit_Kind in N_Generic_Instantiation then
1595 Unit_Name := Defining_Entity (Unit_Node);
1598 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1601 if Chars (Unit_Name) /=
1602 Chars (Entity (Expression (Arg1)))
1605 ("pragma% argument is not current unit name", Arg1);
1608 if Ekind (Unit_Name) = E_Package
1609 and then Present (Renamed_Entity (Unit_Name))
1611 Error_Pragma ("pragma% not allowed for renamed package");
1615 -- Pragma appears other than after a compilation unit
1618 -- Here we check for the generic instantiation case and also
1619 -- for the case of processing a generic formal package. We
1620 -- detect these cases by noting that the Sloc on the node
1621 -- does not belong to the current compilation unit.
1623 Sindex := Source_Index (Current_Sem_Unit);
1625 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1626 Rewrite (N, Make_Null_Statement (Loc));
1629 -- If before first declaration, the pragma applies to the
1630 -- enclosing unit, and the name if present must be this name.
1632 elsif Is_Before_First_Decl (N, Plist) then
1633 Unit_Node := Unit_Declaration_Node (Current_Scope);
1634 Unit_Kind := Nkind (Unit_Node);
1636 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1639 elsif Unit_Kind = N_Subprogram_Body
1640 and then not Acts_As_Spec (Unit_Node)
1644 elsif Nkind (Parent_Node) = N_Package_Body then
1647 elsif Nkind (Parent_Node) = N_Package_Specification
1648 and then Plist = Private_Declarations (Parent_Node)
1652 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1653 or else Nkind (Parent_Node) =
1654 N_Generic_Subprogram_Declaration)
1655 and then Plist = Generic_Formal_Declarations (Parent_Node)
1659 elsif Arg_Count > 0 then
1660 Analyze (Expression (Arg1));
1662 if Entity (Expression (Arg1)) /= Current_Scope then
1664 ("name in pragma% must be enclosing unit", Arg1);
1667 -- It is legal to have no argument in this context
1673 -- Error if not before first declaration. This is because a
1674 -- library unit pragma argument must be the name of a library
1675 -- unit (RM 10.1.5(7)), but the only names permitted in this
1676 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1677 -- generic subprogram declarations or generic instantiations.
1681 ("pragma% misplaced, must be before first declaration");
1685 end Check_Valid_Library_Unit_Pragma;
1691 procedure Check_Variant (Variant : Node_Id) is
1692 Clist : constant Node_Id := Component_List (Variant);
1696 if not Is_Non_Empty_List (Component_Items (Clist)) then
1698 ("Unchecked_Union may not have empty component list",
1703 Comp := First (Component_Items (Clist));
1704 while Present (Comp) loop
1705 Check_Component (Comp);
1714 procedure Error_Pragma (Msg : String) is
1716 Error_Msg_Name_1 := Pname;
1717 Error_Msg_N (Msg, N);
1721 ----------------------
1722 -- Error_Pragma_Arg --
1723 ----------------------
1725 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1727 Error_Msg_Name_1 := Pname;
1728 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1730 end Error_Pragma_Arg;
1732 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1734 Error_Msg_Name_1 := Pname;
1735 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1736 Error_Pragma_Arg (Msg2, Arg);
1737 end Error_Pragma_Arg;
1739 ----------------------------
1740 -- Error_Pragma_Arg_Ident --
1741 ----------------------------
1743 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1745 Error_Msg_Name_1 := Pname;
1746 Error_Msg_N (Msg, Arg);
1748 end Error_Pragma_Arg_Ident;
1750 ----------------------
1751 -- Error_Pragma_Ref --
1752 ----------------------
1754 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1756 Error_Msg_Name_1 := Pname;
1757 Error_Msg_Sloc := Sloc (Ref);
1758 Error_Msg_NE (Msg, N, Ref);
1760 end Error_Pragma_Ref;
1762 ------------------------
1763 -- Find_Lib_Unit_Name --
1764 ------------------------
1766 function Find_Lib_Unit_Name return Entity_Id is
1768 -- Return inner compilation unit entity, for case of nested
1769 -- categorization pragmas. This happens in generic unit.
1771 if Nkind (Parent (N)) = N_Package_Specification
1772 and then Defining_Entity (Parent (N)) /= Current_Scope
1774 return Defining_Entity (Parent (N));
1776 return Current_Scope;
1778 end Find_Lib_Unit_Name;
1780 ----------------------------
1781 -- Find_Program_Unit_Name --
1782 ----------------------------
1784 procedure Find_Program_Unit_Name (Id : Node_Id) is
1785 Unit_Name : Entity_Id;
1786 Unit_Kind : Node_Kind;
1787 P : constant Node_Id := Parent (N);
1790 if Nkind (P) = N_Compilation_Unit then
1791 Unit_Kind := Nkind (Unit (P));
1793 if Unit_Kind = N_Subprogram_Declaration
1794 or else Unit_Kind = N_Package_Declaration
1795 or else Unit_Kind in N_Generic_Declaration
1797 Unit_Name := Defining_Entity (Unit (P));
1799 if Chars (Id) = Chars (Unit_Name) then
1800 Set_Entity (Id, Unit_Name);
1801 Set_Etype (Id, Etype (Unit_Name));
1803 Set_Etype (Id, Any_Type);
1805 ("cannot find program unit referenced by pragma%");
1809 Set_Etype (Id, Any_Type);
1810 Error_Pragma ("pragma% inapplicable to this unit");
1816 end Find_Program_Unit_Name;
1818 -----------------------------------------
1819 -- Find_Unique_Parameterless_Procedure --
1820 -----------------------------------------
1822 function Find_Unique_Parameterless_Procedure
1824 Arg : Node_Id) return Entity_Id
1826 Proc : Entity_Id := Empty;
1829 -- The body of this procedure needs some comments ???
1831 if not Is_Entity_Name (Name) then
1833 ("argument of pragma% must be entity name", Arg);
1835 elsif not Is_Overloaded (Name) then
1836 Proc := Entity (Name);
1838 if Ekind (Proc) /= E_Procedure
1839 or else Present (First_Formal (Proc)) then
1841 ("argument of pragma% must be parameterless procedure", Arg);
1846 Found : Boolean := False;
1848 Index : Interp_Index;
1851 Get_First_Interp (Name, Index, It);
1852 while Present (It.Nam) loop
1855 if Ekind (Proc) = E_Procedure
1856 and then No (First_Formal (Proc))
1860 Set_Entity (Name, Proc);
1861 Set_Is_Overloaded (Name, False);
1864 ("ambiguous handler name for pragma% ", Arg);
1868 Get_Next_Interp (Index, It);
1873 ("argument of pragma% must be parameterless procedure",
1876 Proc := Entity (Name);
1882 end Find_Unique_Parameterless_Procedure;
1884 -------------------------
1885 -- Gather_Associations --
1886 -------------------------
1888 procedure Gather_Associations
1890 Args : out Args_List)
1895 -- Initialize all parameters to Empty
1897 for J in Args'Range loop
1901 -- That's all we have to do if there are no argument associations
1903 if No (Pragma_Argument_Associations (N)) then
1907 -- Otherwise first deal with any positional parameters present
1909 Arg := First (Pragma_Argument_Associations (N));
1910 for Index in Args'Range loop
1911 exit when No (Arg) or else Chars (Arg) /= No_Name;
1912 Args (Index) := Expression (Arg);
1916 -- Positional parameters all processed, if any left, then we
1917 -- have too many positional parameters.
1919 if Present (Arg) and then Chars (Arg) = No_Name then
1921 ("too many positional associations for pragma%", Arg);
1924 -- Process named parameters if any are present
1926 while Present (Arg) loop
1927 if Chars (Arg) = No_Name then
1929 ("positional association cannot follow named association",
1933 for Index in Names'Range loop
1934 if Names (Index) = Chars (Arg) then
1935 if Present (Args (Index)) then
1937 ("duplicate argument association for pragma%", Arg);
1939 Args (Index) := Expression (Arg);
1944 if Index = Names'Last then
1945 Error_Msg_Name_1 := Pname;
1946 Error_Msg_N ("pragma% does not allow & argument", Arg);
1948 -- Check for possible misspelling
1950 for Index1 in Names'Range loop
1951 if Is_Bad_Spelling_Of
1952 (Chars (Arg), Names (Index1))
1954 Error_Msg_Name_1 := Names (Index1);
1955 Error_Msg_N ("\possible misspelling of%", Arg);
1967 end Gather_Associations;
1973 procedure GNAT_Pragma is
1975 Check_Restriction (No_Implementation_Pragmas, N);
1978 --------------------------
1979 -- Is_Before_First_Decl --
1980 --------------------------
1982 function Is_Before_First_Decl
1983 (Pragma_Node : Node_Id;
1984 Decls : List_Id) return Boolean
1986 Item : Node_Id := First (Decls);
1989 -- Only other pragmas can come before this pragma
1992 if No (Item) or else Nkind (Item) /= N_Pragma then
1995 elsif Item = Pragma_Node then
2001 end Is_Before_First_Decl;
2003 -----------------------------
2004 -- Is_Configuration_Pragma --
2005 -----------------------------
2007 -- A configuration pragma must appear in the context clause of a
2008 -- compilation unit, and only other pragmas may precede it. Note that
2009 -- the test below also permits use in a configuration pragma file.
2011 function Is_Configuration_Pragma return Boolean is
2012 Lis : constant List_Id := List_Containing (N);
2013 Par : constant Node_Id := Parent (N);
2017 -- If no parent, then we are in the configuration pragma file,
2018 -- so the placement is definitely appropriate.
2023 -- Otherwise we must be in the context clause of a compilation unit
2024 -- and the only thing allowed before us in the context list is more
2025 -- configuration pragmas.
2027 elsif Nkind (Par) = N_Compilation_Unit
2028 and then Context_Items (Par) = Lis
2035 elsif Nkind (Prg) /= N_Pragma then
2045 end Is_Configuration_Pragma;
2047 --------------------------
2048 -- Is_In_Context_Clause --
2049 --------------------------
2051 function Is_In_Context_Clause return Boolean is
2053 Parent_Node : Node_Id;
2056 if not Is_List_Member (N) then
2060 Plist := List_Containing (N);
2061 Parent_Node := Parent (Plist);
2063 if Parent_Node = Empty
2064 or else Nkind (Parent_Node) /= N_Compilation_Unit
2065 or else Context_Items (Parent_Node) /= Plist
2072 end Is_In_Context_Clause;
2074 ---------------------------------
2075 -- Is_Static_String_Expression --
2076 ---------------------------------
2078 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2079 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2082 Analyze_And_Resolve (Argx);
2083 return Is_OK_Static_Expression (Argx)
2084 and then Nkind (Argx) = N_String_Literal;
2085 end Is_Static_String_Expression;
2087 ----------------------
2088 -- Pragma_Misplaced --
2089 ----------------------
2091 procedure Pragma_Misplaced is
2093 Error_Pragma ("incorrect placement of pragma%");
2094 end Pragma_Misplaced;
2096 ------------------------------------
2097 -- Process Atomic_Shared_Volatile --
2098 ------------------------------------
2100 procedure Process_Atomic_Shared_Volatile is
2107 procedure Set_Atomic (E : Entity_Id);
2108 -- Set given type as atomic, and if no explicit alignment was given,
2109 -- set alignment to unknown, since back end knows what the alignment
2110 -- requirements are for atomic arrays. Note: this step is necessary
2111 -- for derived types.
2117 procedure Set_Atomic (E : Entity_Id) is
2121 if not Has_Alignment_Clause (E) then
2122 Set_Alignment (E, Uint_0);
2126 -- Start of processing for Process_Atomic_Shared_Volatile
2129 Check_Ada_83_Warning;
2130 Check_No_Identifiers;
2131 Check_Arg_Count (1);
2132 Check_Arg_Is_Local_Name (Arg1);
2133 E_Id := Expression (Arg1);
2135 if Etype (E_Id) = Any_Type then
2140 D := Declaration_Node (E);
2144 if Rep_Item_Too_Early (E, N)
2146 Rep_Item_Too_Late (E, N)
2150 Check_First_Subtype (Arg1);
2153 if Prag_Id /= Pragma_Volatile then
2155 Set_Atomic (Underlying_Type (E));
2156 Set_Atomic (Base_Type (E));
2159 -- Attribute belongs on the base type. If the view of the type is
2160 -- currently private, it also belongs on the underlying type.
2162 Set_Is_Volatile (Base_Type (E));
2163 Set_Is_Volatile (Underlying_Type (E));
2165 Set_Treat_As_Volatile (E);
2166 Set_Treat_As_Volatile (Underlying_Type (E));
2168 elsif K = N_Object_Declaration
2169 or else (K = N_Component_Declaration
2170 and then Original_Record_Component (E) = E)
2172 if Rep_Item_Too_Late (E, N) then
2176 if Prag_Id /= Pragma_Volatile then
2179 -- If the object declaration has an explicit initialization, a
2180 -- temporary may have to be created to hold the expression, to
2181 -- ensure that access to the object remain atomic.
2183 if Nkind (Parent (E)) = N_Object_Declaration
2184 and then Present (Expression (Parent (E)))
2186 Set_Has_Delayed_Freeze (E);
2189 -- An interesting improvement here. If an object of type X
2190 -- is declared atomic, and the type X is not atomic, that's
2191 -- a pity, since it may not have appropriate alignment etc.
2192 -- We can rescue this in the special case where the object
2193 -- and type are in the same unit by just setting the type
2194 -- as atomic, so that the back end will process it as atomic.
2196 Utyp := Underlying_Type (Etype (E));
2199 and then Sloc (E) > No_Location
2200 and then Sloc (Utyp) > No_Location
2202 Get_Source_File_Index (Sloc (E)) =
2203 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2205 Set_Is_Atomic (Underlying_Type (Etype (E)));
2209 Set_Is_Volatile (E);
2210 Set_Treat_As_Volatile (E);
2214 ("inappropriate entity for pragma%", Arg1);
2216 end Process_Atomic_Shared_Volatile;
2218 -------------------------------------------
2219 -- Process_Compile_Time_Warning_Or_Error --
2220 -------------------------------------------
2222 procedure Process_Compile_Time_Warning_Or_Error is
2223 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2227 Check_Arg_Count (2);
2228 Check_No_Identifiers;
2229 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2230 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2232 if Compile_Time_Known_Value (Arg1x) then
2233 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2235 Str : constant String_Id :=
2236 Strval (Get_Pragma_Arg (Arg2));
2237 Len : constant Int := String_Length (Str);
2242 Cent : constant Entity_Id :=
2243 Cunit_Entity (Current_Sem_Unit);
2245 Force : constant Boolean :=
2246 Prag_Id = Pragma_Compile_Time_Warning
2248 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2249 and then (Ekind (Cent) /= E_Package
2250 or else not In_Private_Part (Cent));
2251 -- Set True if this is the warning case, and we are in the
2252 -- visible part of a package spec, or in a subprogram spec,
2253 -- in which case we want to force the client to see the
2254 -- warning, even though it is not in the main unit.
2257 -- Loop through segments of message separated by line
2258 -- feeds. We output these segments as separate messages
2259 -- with continuation marks for all but the first.
2264 Error_Msg_Strlen := 0;
2266 -- Loop to copy characters from argument to error
2267 -- message string buffer.
2270 exit when Ptr > Len;
2271 CC := Get_String_Char (Str, Ptr);
2274 -- Ignore wide chars ??? else store character
2276 if In_Character_Range (CC) then
2277 C := Get_Character (CC);
2278 exit when C = ASCII.LF;
2279 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2280 Error_Msg_String (Error_Msg_Strlen) := C;
2284 -- Here with one line ready to go
2286 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2288 -- If this is a warning in a spec, then we want clients
2289 -- to see the warning, so mark the message with the
2290 -- special sequence !! to force the warning. In the case
2291 -- of a package spec, we do not force this if we are in
2292 -- the private part of the spec.
2295 if Cont = False then
2296 Error_Msg_N ("<~!!", Arg1);
2299 Error_Msg_N ("\<~!!", Arg1);
2302 -- Error, rather than warning, or in a body, so we do not
2303 -- need to force visibility for client (error will be
2304 -- output in any case, and this is the situation in which
2305 -- we do not want a client to get a warning, since the
2306 -- warning is in the body or the spec private part.
2309 if Cont = False then
2310 Error_Msg_N ("<~", Arg1);
2313 Error_Msg_N ("\<~", Arg1);
2317 exit when Ptr > Len;
2322 end Process_Compile_Time_Warning_Or_Error;
2324 ------------------------
2325 -- Process_Convention --
2326 ------------------------
2328 procedure Process_Convention
2329 (C : out Convention_Id;
2335 Comp_Unit : Unit_Number_Type;
2337 procedure Set_Convention_From_Pragma (E : Entity_Id);
2338 -- Set convention in entity E, and also flag that the entity has a
2339 -- convention pragma. If entity is for a private or incomplete type,
2340 -- also set convention and flag on underlying type. This procedure
2341 -- also deals with the special case of C_Pass_By_Copy convention.
2343 --------------------------------
2344 -- Set_Convention_From_Pragma --
2345 --------------------------------
2347 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2349 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2350 -- for an overridden dispatching operation. Technically this is
2351 -- an amendment and should only be done in Ada 2005 mode. However,
2352 -- this is clearly a mistake, since the problem that is addressed
2353 -- by this AI is that there is a clear gap in the RM!
2355 if Is_Dispatching_Operation (E)
2356 and then Present (Overridden_Operation (E))
2357 and then C /= Convention (Overridden_Operation (E))
2360 ("cannot change convention for " &
2361 "overridden dispatching operation",
2365 -- Set the convention
2367 Set_Convention (E, C);
2368 Set_Has_Convention_Pragma (E);
2370 if Is_Incomplete_Or_Private_Type (E) then
2371 Set_Convention (Underlying_Type (E), C);
2372 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2375 -- A class-wide type should inherit the convention of
2376 -- the specific root type (although this isn't specified
2377 -- clearly by the RM).
2379 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2380 Set_Convention (Class_Wide_Type (E), C);
2383 -- If the entity is a record type, then check for special case of
2384 -- C_Pass_By_Copy, which is treated the same as C except that the
2385 -- special record flag is set. This convention is only permitted
2386 -- on record types (see AI95-00131).
2388 if Cname = Name_C_Pass_By_Copy then
2389 if Is_Record_Type (E) then
2390 Set_C_Pass_By_Copy (Base_Type (E));
2391 elsif Is_Incomplete_Or_Private_Type (E)
2392 and then Is_Record_Type (Underlying_Type (E))
2394 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2397 ("C_Pass_By_Copy convention allowed only for record type",
2402 -- If the entity is a derived boolean type, check for the
2403 -- special case of convention C, C++, or Fortran, where we
2404 -- consider any nonzero value to represent true.
2406 if Is_Discrete_Type (E)
2407 and then Root_Type (Etype (E)) = Standard_Boolean
2413 C = Convention_Fortran)
2415 Set_Nonzero_Is_True (Base_Type (E));
2417 end Set_Convention_From_Pragma;
2419 -- Start of processing for Process_Convention
2422 Check_At_Least_N_Arguments (2);
2423 Check_Optional_Identifier (Arg1, Name_Convention);
2424 Check_Arg_Is_Identifier (Arg1);
2425 Cname := Chars (Expression (Arg1));
2427 -- C_Pass_By_Copy is treated as a synonym for convention C
2428 -- (this is tested again below to set the critical flag)
2430 if Cname = Name_C_Pass_By_Copy then
2433 -- Otherwise we must have something in the standard convention list
2435 elsif Is_Convention_Name (Cname) then
2436 C := Get_Convention_Id (Chars (Expression (Arg1)));
2438 -- In DEC VMS, it seems that there is an undocumented feature that
2439 -- any unrecognized convention is treated as the default, which for
2440 -- us is convention C. It does not seem so terrible to do this
2441 -- unconditionally, silently in the VMS case, and with a warning
2442 -- in the non-VMS case.
2445 if Warn_On_Export_Import and not OpenVMS_On_Target then
2447 ("?unrecognized convention name, C assumed",
2454 Check_Optional_Identifier (Arg2, Name_Entity);
2455 Check_Arg_Is_Local_Name (Arg2);
2457 Id := Expression (Arg2);
2460 if not Is_Entity_Name (Id) then
2461 Error_Pragma_Arg ("entity name required", Arg2);
2466 -- Go to renamed subprogram if present, since convention applies to
2467 -- the actual renamed entity, not to the renaming entity. If the
2468 -- subprogram is inherited, go to parent subprogram.
2470 if Is_Subprogram (E)
2471 and then Present (Alias (E))
2473 if Nkind (Parent (Declaration_Node (E))) =
2474 N_Subprogram_Renaming_Declaration
2476 if Scope (E) /= Scope (Alias (E)) then
2478 ("cannot apply pragma% to non-local renaming&#", E);
2482 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2483 and then Scope (E) = Scope (Alias (E))
2489 -- Check that we are not applying this to a specless body
2491 if Is_Subprogram (E)
2492 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2495 ("pragma% requires separate spec and must come before body");
2498 -- Check that we are not applying this to a named constant
2500 if Ekind (E) = E_Named_Integer
2502 Ekind (E) = E_Named_Real
2504 Error_Msg_Name_1 := Pname;
2506 ("cannot apply pragma% to named constant!",
2507 Get_Pragma_Arg (Arg2));
2509 ("\supply appropriate type for&!", Arg2);
2512 if Ekind (E) = E_Enumeration_Literal then
2513 Error_Pragma ("enumeration literal not allowed for pragma%");
2516 -- Check for rep item appearing too early or too late
2518 if Etype (E) = Any_Type
2519 or else Rep_Item_Too_Early (E, N)
2523 E := Underlying_Type (E);
2526 if Rep_Item_Too_Late (E, N) then
2530 if Has_Convention_Pragma (E) then
2532 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2534 elsif Convention (E) = Convention_Protected
2535 or else Ekind (Scope (E)) = E_Protected_Type
2538 ("a protected operation cannot be given a different convention",
2542 -- For Intrinsic, a subprogram is required
2544 if C = Convention_Intrinsic
2545 and then not Is_Subprogram (E)
2546 and then not Is_Generic_Subprogram (E)
2549 ("second argument of pragma% must be a subprogram", Arg2);
2552 -- For Stdcall, a subprogram, variable or subprogram type is required
2554 if C = Convention_Stdcall
2555 and then not Is_Subprogram (E)
2556 and then not Is_Generic_Subprogram (E)
2557 and then Ekind (E) /= E_Variable
2560 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2563 ("second argument of pragma% must be subprogram (type)",
2567 if not Is_Subprogram (E)
2568 and then not Is_Generic_Subprogram (E)
2570 Set_Convention_From_Pragma (E);
2574 Check_First_Subtype (Arg2);
2575 Set_Convention_From_Pragma (Base_Type (E));
2577 -- For subprograms, we must set the convention on the
2578 -- internally generated directly designated type as well.
2580 if Ekind (E) = E_Access_Subprogram_Type then
2581 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2585 -- For the subprogram case, set proper convention for all homonyms
2586 -- in same scope and the same declarative part, i.e. the same
2587 -- compilation unit.
2590 Comp_Unit := Get_Source_Unit (E);
2591 Set_Convention_From_Pragma (E);
2593 -- Treat a pragma Import as an implicit body, for GPS use
2595 if Prag_Id = Pragma_Import then
2596 Generate_Reference (E, Id, 'b');
2602 exit when No (E1) or else Scope (E1) /= Current_Scope;
2604 -- Do not set the pragma on inherited operations or on
2605 -- formal subprograms.
2607 if Comes_From_Source (E1)
2608 and then Comp_Unit = Get_Source_Unit (E1)
2609 and then not Is_Formal_Subprogram (E1)
2610 and then Nkind (Original_Node (Parent (E1))) /=
2611 N_Full_Type_Declaration
2613 if Present (Alias (E1))
2614 and then Scope (E1) /= Scope (Alias (E1))
2617 ("cannot apply pragma% to non-local renaming&#", E1);
2619 Set_Convention_From_Pragma (E1);
2621 if Prag_Id = Pragma_Import then
2622 Generate_Reference (E, Id, 'b');
2627 end Process_Convention;
2629 -----------------------------------------------------
2630 -- Process_Extended_Import_Export_Exception_Pragma --
2631 -----------------------------------------------------
2633 procedure Process_Extended_Import_Export_Exception_Pragma
2634 (Arg_Internal : Node_Id;
2635 Arg_External : Node_Id;
2645 if not OpenVMS_On_Target then
2647 ("?pragma% ignored (applies only to Open'V'M'S)");
2650 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2651 Def_Id := Entity (Arg_Internal);
2653 if Ekind (Def_Id) /= E_Exception then
2655 ("pragma% must refer to declared exception", Arg_Internal);
2658 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2660 if Present (Arg_Form) then
2661 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2664 if Present (Arg_Form)
2665 and then Chars (Arg_Form) = Name_Ada
2669 Set_Is_VMS_Exception (Def_Id);
2670 Set_Exception_Code (Def_Id, No_Uint);
2673 if Present (Arg_Code) then
2674 if not Is_VMS_Exception (Def_Id) then
2676 ("Code option for pragma% not allowed for Ada case",
2680 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2681 Code_Val := Expr_Value (Arg_Code);
2683 if not UI_Is_In_Int_Range (Code_Val) then
2685 ("Code option for pragma% must be in 32-bit range",
2689 Set_Exception_Code (Def_Id, Code_Val);
2692 end Process_Extended_Import_Export_Exception_Pragma;
2694 -------------------------------------------------
2695 -- Process_Extended_Import_Export_Internal_Arg --
2696 -------------------------------------------------
2698 procedure Process_Extended_Import_Export_Internal_Arg
2699 (Arg_Internal : Node_Id := Empty)
2704 if No (Arg_Internal) then
2705 Error_Pragma ("Internal parameter required for pragma%");
2708 if Nkind (Arg_Internal) = N_Identifier then
2711 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2712 and then (Prag_Id = Pragma_Import_Function
2714 Prag_Id = Pragma_Export_Function)
2720 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2723 Check_Arg_Is_Local_Name (Arg_Internal);
2724 end Process_Extended_Import_Export_Internal_Arg;
2726 --------------------------------------------------
2727 -- Process_Extended_Import_Export_Object_Pragma --
2728 --------------------------------------------------
2730 procedure Process_Extended_Import_Export_Object_Pragma
2731 (Arg_Internal : Node_Id;
2732 Arg_External : Node_Id;
2738 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2739 Def_Id := Entity (Arg_Internal);
2741 if Ekind (Def_Id) /= E_Constant
2742 and then Ekind (Def_Id) /= E_Variable
2745 ("pragma% must designate an object", Arg_Internal);
2748 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2750 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2753 ("previous Common/Psect_Object applies, pragma % not permitted",
2757 if Rep_Item_Too_Late (Def_Id, N) then
2761 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2763 if Present (Arg_Size) then
2764 Check_Arg_Is_External_Name (Arg_Size);
2767 -- Export_Object case
2769 if Prag_Id = Pragma_Export_Object then
2770 if not Is_Library_Level_Entity (Def_Id) then
2772 ("argument for pragma% must be library level entity",
2776 if Ekind (Current_Scope) = E_Generic_Package then
2777 Error_Pragma ("pragma& cannot appear in a generic unit");
2780 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2782 ("exported object must have compile time known size",
2786 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2788 ("?duplicate Export_Object pragma", N);
2790 Set_Exported (Def_Id, Arg_Internal);
2793 -- Import_Object case
2796 if Is_Concurrent_Type (Etype (Def_Id)) then
2798 ("cannot use pragma% for task/protected object",
2802 if Ekind (Def_Id) = E_Constant then
2804 ("cannot import a constant", Arg_Internal);
2807 if Warn_On_Export_Import
2808 and then Has_Discriminants (Etype (Def_Id))
2811 ("imported value must be initialized?", Arg_Internal);
2814 if Warn_On_Export_Import
2815 and then Is_Access_Type (Etype (Def_Id))
2818 ("cannot import object of an access type?", Arg_Internal);
2821 if Warn_On_Export_Import
2822 and then Is_Imported (Def_Id)
2825 ("?duplicate Import_Object pragma", N);
2827 -- Check for explicit initialization present. Note that an
2828 -- initialization that generated by the code generator, e.g.
2829 -- for an access type, does not count here.
2831 elsif Present (Expression (Parent (Def_Id)))
2834 (Original_Node (Expression (Parent (Def_Id))))
2836 Error_Msg_Sloc := Sloc (Def_Id);
2838 ("imported entities cannot be initialized (RM B.1(24))",
2839 "\no initialization allowed for & declared#", Arg1);
2841 Set_Imported (Def_Id);
2842 Note_Possible_Modification (Arg_Internal, Sure => False);
2845 end Process_Extended_Import_Export_Object_Pragma;
2847 ------------------------------------------------------
2848 -- Process_Extended_Import_Export_Subprogram_Pragma --
2849 ------------------------------------------------------
2851 procedure Process_Extended_Import_Export_Subprogram_Pragma
2852 (Arg_Internal : Node_Id;
2853 Arg_External : Node_Id;
2854 Arg_Parameter_Types : Node_Id;
2855 Arg_Result_Type : Node_Id := Empty;
2856 Arg_Mechanism : Node_Id;
2857 Arg_Result_Mechanism : Node_Id := Empty;
2858 Arg_First_Optional_Parameter : Node_Id := Empty)
2864 Ambiguous : Boolean;
2868 function Same_Base_Type
2870 Formal : Entity_Id) return Boolean;
2871 -- Determines if Ptype references the type of Formal. Note that
2872 -- only the base types need to match according to the spec. Ptype
2873 -- here is the argument from the pragma, which is either a type
2874 -- name, or an access attribute.
2876 --------------------
2877 -- Same_Base_Type --
2878 --------------------
2880 function Same_Base_Type
2882 Formal : Entity_Id) return Boolean
2884 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2888 -- Case where pragma argument is typ'Access
2890 if Nkind (Ptype) = N_Attribute_Reference
2891 and then Attribute_Name (Ptype) = Name_Access
2893 Pref := Prefix (Ptype);
2896 if not Is_Entity_Name (Pref)
2897 or else Entity (Pref) = Any_Type
2902 -- We have a match if the corresponding argument is of an
2903 -- anonymous access type, and its designated type matches
2904 -- the type of the prefix of the access attribute
2906 return Ekind (Ftyp) = E_Anonymous_Access_Type
2907 and then Base_Type (Entity (Pref)) =
2908 Base_Type (Etype (Designated_Type (Ftyp)));
2910 -- Case where pragma argument is a type name
2915 if not Is_Entity_Name (Ptype)
2916 or else Entity (Ptype) = Any_Type
2921 -- We have a match if the corresponding argument is of
2922 -- the type given in the pragma (comparing base types)
2924 return Base_Type (Entity (Ptype)) = Ftyp;
2928 -- Start of processing for
2929 -- Process_Extended_Import_Export_Subprogram_Pragma
2932 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2936 -- Loop through homonyms (overloadings) of the entity
2938 Hom_Id := Entity (Arg_Internal);
2939 while Present (Hom_Id) loop
2940 Def_Id := Get_Base_Subprogram (Hom_Id);
2942 -- We need a subprogram in the current scope
2944 if not Is_Subprogram (Def_Id)
2945 or else Scope (Def_Id) /= Current_Scope
2952 -- Pragma cannot apply to subprogram body
2954 if Is_Subprogram (Def_Id)
2957 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2960 ("pragma% requires separate spec"
2961 & " and must come before body");
2964 -- Test result type if given, note that the result type
2965 -- parameter can only be present for the function cases.
2967 if Present (Arg_Result_Type)
2968 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2972 elsif Etype (Def_Id) /= Standard_Void_Type
2974 (Pname = Name_Export_Procedure
2976 Pname = Name_Import_Procedure)
2980 -- Test parameter types if given. Note that this parameter
2981 -- has not been analyzed (and must not be, since it is
2982 -- semantic nonsense), so we get it as the parser left it.
2984 elsif Present (Arg_Parameter_Types) then
2985 Check_Matching_Types : declare
2990 Formal := First_Formal (Def_Id);
2992 if Nkind (Arg_Parameter_Types) = N_Null then
2993 if Present (Formal) then
2997 -- A list of one type, e.g. (List) is parsed as
2998 -- a parenthesized expression.
3000 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3001 and then Paren_Count (Arg_Parameter_Types) = 1
3004 or else Present (Next_Formal (Formal))
3009 Same_Base_Type (Arg_Parameter_Types, Formal);
3012 -- A list of more than one type is parsed as a aggregate
3014 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3015 and then Paren_Count (Arg_Parameter_Types) = 0
3017 Ptype := First (Expressions (Arg_Parameter_Types));
3018 while Present (Ptype) or else Present (Formal) loop
3021 or else not Same_Base_Type (Ptype, Formal)
3026 Next_Formal (Formal);
3031 -- Anything else is of the wrong form
3035 ("wrong form for Parameter_Types parameter",
3036 Arg_Parameter_Types);
3038 end Check_Matching_Types;
3041 -- Match is now False if the entry we found did not match
3042 -- either a supplied Parameter_Types or Result_Types argument
3048 -- Ambiguous case, the flag Ambiguous shows if we already
3049 -- detected this and output the initial messages.
3052 if not Ambiguous then
3054 Error_Msg_Name_1 := Pname;
3056 ("pragma% does not uniquely identify subprogram!",
3058 Error_Msg_Sloc := Sloc (Ent);
3059 Error_Msg_N ("matching subprogram #!", N);
3063 Error_Msg_Sloc := Sloc (Def_Id);
3064 Error_Msg_N ("matching subprogram #!", N);
3069 Hom_Id := Homonym (Hom_Id);
3072 -- See if we found an entry
3075 if not Ambiguous then
3076 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3078 ("pragma% cannot be given for generic subprogram");
3081 ("pragma% does not identify local subprogram");
3088 -- Import pragmas must be be for imported entities
3090 if Prag_Id = Pragma_Import_Function
3092 Prag_Id = Pragma_Import_Procedure
3094 Prag_Id = Pragma_Import_Valued_Procedure
3096 if not Is_Imported (Ent) then
3098 ("pragma Import or Interface must precede pragma%");
3101 -- Here we have the Export case which can set the entity as exported
3103 -- But does not do so if the specified external name is null, since
3104 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3105 -- compatible) to request no external name.
3107 elsif Nkind (Arg_External) = N_String_Literal
3108 and then String_Length (Strval (Arg_External)) = 0
3112 -- In all other cases, set entity as exported
3115 Set_Exported (Ent, Arg_Internal);
3118 -- Special processing for Valued_Procedure cases
3120 if Prag_Id = Pragma_Import_Valued_Procedure
3122 Prag_Id = Pragma_Export_Valued_Procedure
3124 Formal := First_Formal (Ent);
3128 ("at least one parameter required for pragma%");
3130 elsif Ekind (Formal) /= E_Out_Parameter then
3132 ("first parameter must have mode out for pragma%");
3135 Set_Is_Valued_Procedure (Ent);
3139 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3141 -- Process Result_Mechanism argument if present. We have already
3142 -- checked that this is only allowed for the function case.
3144 if Present (Arg_Result_Mechanism) then
3145 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3148 -- Process Mechanism parameter if present. Note that this parameter
3149 -- is not analyzed, and must not be analyzed since it is semantic
3150 -- nonsense, so we get it in exactly as the parser left it.
3152 if Present (Arg_Mechanism) then
3160 -- A single mechanism association without a formal parameter
3161 -- name is parsed as a parenthesized expression. All other
3162 -- cases are parsed as aggregates, so we rewrite the single
3163 -- parameter case as an aggregate for consistency.
3165 if Nkind (Arg_Mechanism) /= N_Aggregate
3166 and then Paren_Count (Arg_Mechanism) = 1
3168 Rewrite (Arg_Mechanism,
3169 Make_Aggregate (Sloc (Arg_Mechanism),
3170 Expressions => New_List (
3171 Relocate_Node (Arg_Mechanism))));
3174 -- Case of only mechanism name given, applies to all formals
3176 if Nkind (Arg_Mechanism) /= N_Aggregate then
3177 Formal := First_Formal (Ent);
3178 while Present (Formal) loop
3179 Set_Mechanism_Value (Formal, Arg_Mechanism);
3180 Next_Formal (Formal);
3183 -- Case of list of mechanism associations given
3186 if Null_Record_Present (Arg_Mechanism) then
3188 ("inappropriate form for Mechanism parameter",
3192 -- Deal with positional ones first
3194 Formal := First_Formal (Ent);
3196 if Present (Expressions (Arg_Mechanism)) then
3197 Mname := First (Expressions (Arg_Mechanism));
3198 while Present (Mname) loop
3201 ("too many mechanism associations", Mname);
3204 Set_Mechanism_Value (Formal, Mname);
3205 Next_Formal (Formal);
3210 -- Deal with named entries
3212 if Present (Component_Associations (Arg_Mechanism)) then
3213 Massoc := First (Component_Associations (Arg_Mechanism));
3214 while Present (Massoc) loop
3215 Choice := First (Choices (Massoc));
3217 if Nkind (Choice) /= N_Identifier
3218 or else Present (Next (Choice))
3221 ("incorrect form for mechanism association",
3225 Formal := First_Formal (Ent);
3229 ("parameter name & not present", Choice);
3232 if Chars (Choice) = Chars (Formal) then
3234 (Formal, Expression (Massoc));
3236 -- Set entity on identifier for ASIS
3238 Set_Entity (Choice, Formal);
3243 Next_Formal (Formal);
3253 -- Process First_Optional_Parameter argument if present. We have
3254 -- already checked that this is only allowed for the Import case.
3256 if Present (Arg_First_Optional_Parameter) then
3257 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3259 ("first optional parameter must be formal parameter name",
3260 Arg_First_Optional_Parameter);
3263 Formal := First_Formal (Ent);
3267 ("specified formal parameter& not found",
3268 Arg_First_Optional_Parameter);
3271 exit when Chars (Formal) =
3272 Chars (Arg_First_Optional_Parameter);
3274 Next_Formal (Formal);
3277 Set_First_Optional_Parameter (Ent, Formal);
3279 -- Check specified and all remaining formals have right form
3281 while Present (Formal) loop
3282 if Ekind (Formal) /= E_In_Parameter then
3284 ("optional formal& is not of mode in!",
3285 Arg_First_Optional_Parameter, Formal);
3288 Dval := Default_Value (Formal);
3292 ("optional formal& does not have default value!",
3293 Arg_First_Optional_Parameter, Formal);
3295 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3300 ("default value for optional formal& is non-static!",
3301 Arg_First_Optional_Parameter, Formal);
3305 Set_Is_Optional_Parameter (Formal);
3306 Next_Formal (Formal);
3309 end Process_Extended_Import_Export_Subprogram_Pragma;
3311 --------------------------
3312 -- Process_Generic_List --
3313 --------------------------
3315 procedure Process_Generic_List is
3321 Check_No_Identifiers;
3322 Check_At_Least_N_Arguments (1);
3325 while Present (Arg) loop
3326 Exp := Expression (Arg);
3329 if not Is_Entity_Name (Exp)
3331 (not Is_Generic_Instance (Entity (Exp))
3333 not Is_Generic_Unit (Entity (Exp)))
3336 ("pragma% argument must be name of generic unit/instance",
3342 end Process_Generic_List;
3344 ---------------------------------
3345 -- Process_Import_Or_Interface --
3346 ---------------------------------
3348 procedure Process_Import_Or_Interface is
3354 Process_Convention (C, Def_Id);
3355 Kill_Size_Check_Code (Def_Id);
3356 Note_Possible_Modification (Expression (Arg2), Sure => False);
3358 if Ekind (Def_Id) = E_Variable
3360 Ekind (Def_Id) = E_Constant
3362 -- We do not permit Import to apply to a renaming declaration
3364 if Present (Renamed_Object (Def_Id)) then
3366 ("pragma% not allowed for object renaming", Arg2);
3368 -- User initialization is not allowed for imported object, but
3369 -- the object declaration may contain a default initialization,
3370 -- that will be discarded. Note that an explicit initialization
3371 -- only counts if it comes from source, otherwise it is simply
3372 -- the code generator making an implicit initialization explicit.
3374 elsif Present (Expression (Parent (Def_Id)))
3375 and then Comes_From_Source (Expression (Parent (Def_Id)))
3377 Error_Msg_Sloc := Sloc (Def_Id);
3379 ("no initialization allowed for declaration of& #",
3380 "\imported entities cannot be initialized (RM B.1(24))",
3384 Set_Imported (Def_Id);
3385 Process_Interface_Name (Def_Id, Arg3, Arg4);
3387 -- Note that we do not set Is_Public here. That's because we
3388 -- only want to set if if there is no address clause, and we
3389 -- don't know that yet, so we delay that processing till
3392 -- pragma Import completes deferred constants
3394 if Ekind (Def_Id) = E_Constant then
3395 Set_Has_Completion (Def_Id);
3398 -- It is not possible to import a constant of an unconstrained
3399 -- array type (e.g. string) because there is no simple way to
3400 -- write a meaningful subtype for it.
3402 if Is_Array_Type (Etype (Def_Id))
3403 and then not Is_Constrained (Etype (Def_Id))
3406 ("imported constant& must have a constrained subtype",
3411 elsif Is_Subprogram (Def_Id)
3412 or else Is_Generic_Subprogram (Def_Id)
3414 -- If the name is overloaded, pragma applies to all of the
3415 -- denoted entities in the same declarative part.
3418 while Present (Hom_Id) loop
3419 Def_Id := Get_Base_Subprogram (Hom_Id);
3421 -- Ignore inherited subprograms because the pragma will
3422 -- apply to the parent operation, which is the one called.
3424 if Is_Overloadable (Def_Id)
3425 and then Present (Alias (Def_Id))
3429 -- If it is not a subprogram, it must be in an outer
3430 -- scope and pragma does not apply.
3432 elsif not Is_Subprogram (Def_Id)
3433 and then not Is_Generic_Subprogram (Def_Id)
3437 -- Verify that the homonym is in the same declarative
3438 -- part (not just the same scope).
3440 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3441 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3446 Set_Imported (Def_Id);
3448 -- Special processing for Convention_Intrinsic
3450 if C = Convention_Intrinsic then
3452 -- Link_Name argument not allowed for intrinsic
3455 and then Chars (Arg3) = Name_Link_Name
3460 if Present (Arg4) then
3462 ("Link_Name argument not allowed for " &
3467 Set_Is_Intrinsic_Subprogram (Def_Id);
3469 -- If no external name is present, then check that
3470 -- this is a valid intrinsic subprogram. If an external
3471 -- name is present, then this is handled by the back end.
3474 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3478 -- All interfaced procedures need an external symbol
3479 -- created for them since they are always referenced
3480 -- from another object file.
3482 Set_Is_Public (Def_Id);
3484 -- Verify that the subprogram does not have a completion
3485 -- through a renaming declaration. For other completions
3486 -- the pragma appears as a too late representation.
3489 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3493 and then Nkind (Decl) = N_Subprogram_Declaration
3494 and then Present (Corresponding_Body (Decl))
3497 (Unit_Declaration_Node
3498 (Corresponding_Body (Decl))) =
3499 N_Subprogram_Renaming_Declaration
3501 Error_Msg_Sloc := Sloc (Def_Id);
3503 ("cannot import&, renaming already provided for " &
3504 "declaration #", N, Def_Id);
3508 Set_Has_Completion (Def_Id);
3509 Process_Interface_Name (Def_Id, Arg3, Arg4);
3512 if Is_Compilation_Unit (Hom_Id) then
3514 -- Its possible homonyms are not affected by the pragma.
3515 -- Such homonyms might be present in the context of other
3516 -- units being compiled.
3521 Hom_Id := Homonym (Hom_Id);
3525 -- When the convention is Java or CIL, we also allow Import to be
3526 -- given for packages, generic packages, exceptions, and record
3529 elsif (C = Convention_Java or else C = Convention_CIL)
3531 (Ekind (Def_Id) = E_Package
3532 or else Ekind (Def_Id) = E_Generic_Package
3533 or else Ekind (Def_Id) = E_Exception
3534 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3536 Set_Imported (Def_Id);
3537 Set_Is_Public (Def_Id);
3538 Process_Interface_Name (Def_Id, Arg3, Arg4);
3540 -- Import a CPP class
3542 elsif Is_Record_Type (Def_Id)
3543 and then C = Convention_CPP
3545 if not Is_Tagged_Type (Def_Id) then
3546 Error_Msg_Sloc := Sloc (Def_Id);
3547 Error_Pragma_Arg ("imported 'C'P'P type must be tagged", Arg2);
3550 -- Types treated as CPP classes are treated as limited, but we
3551 -- don't require them to be declared this way. A warning is
3552 -- issued to encourage the user to declare them as limited.
3553 -- This is not an error, for compatibility reasons, because
3554 -- these types have been supported this way for some time.
3556 if not Is_Limited_Type (Def_Id) then
3558 ("imported 'C'P'P type should be " &
3559 "explicitly declared limited?",
3560 Get_Pragma_Arg (Arg2));
3562 ("\type will be considered limited",
3563 Get_Pragma_Arg (Arg2));
3566 Set_Is_CPP_Class (Def_Id);
3567 Set_Is_Limited_Record (Def_Id);
3572 ("second argument of pragma% must be object or subprogram",
3576 -- If this pragma applies to a compilation unit, then the unit,
3577 -- which is a subprogram, does not require (or allow) a body.
3578 -- We also do not need to elaborate imported procedures.
3580 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3582 Cunit : constant Node_Id := Parent (Parent (N));
3584 Set_Body_Required (Cunit, False);
3587 end Process_Import_Or_Interface;
3589 --------------------
3590 -- Process_Inline --
3591 --------------------
3593 procedure Process_Inline (Active : Boolean) is
3599 Effective : Boolean := False;
3601 procedure Make_Inline (Subp : Entity_Id);
3602 -- Subp is the defining unit name of the subprogram
3603 -- declaration. Set the flag, as well as the flag in the
3604 -- corresponding body, if there is one present.
3606 procedure Set_Inline_Flags (Subp : Entity_Id);
3607 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3608 -- Has_Pragma_Inline_Always for the Inline_Always case.
3610 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3611 -- Returns True if it can be determined at this stage that inlining
3612 -- is not possible, for example if the body is available and contains
3613 -- exception handlers, we prevent inlining, since otherwise we can
3614 -- get undefined symbols at link time. This function also emits a
3615 -- warning if front-end inlining is enabled and the pragma appears
3618 -- ??? is business with link symbols still valid, or does it relate
3619 -- to front end ZCX which is being phased out ???
3621 ---------------------------
3622 -- Inlining_Not_Possible --
3623 ---------------------------
3625 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3626 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3630 if Nkind (Decl) = N_Subprogram_Body then
3631 Stats := Handled_Statement_Sequence (Decl);
3632 return Present (Exception_Handlers (Stats))
3633 or else Present (At_End_Proc (Stats));
3635 elsif Nkind (Decl) = N_Subprogram_Declaration
3636 and then Present (Corresponding_Body (Decl))
3638 if Front_End_Inlining
3639 and then Analyzed (Corresponding_Body (Decl))
3641 Error_Msg_N ("pragma appears too late, ignored?", N);
3644 -- If the subprogram is a renaming as body, the body is
3645 -- just a call to the renamed subprogram, and inlining is
3646 -- trivially possible.
3649 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3650 N_Subprogram_Renaming_Declaration
3656 Handled_Statement_Sequence
3657 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3660 Present (Exception_Handlers (Stats))
3661 or else Present (At_End_Proc (Stats));
3665 -- If body is not available, assume the best, the check is
3666 -- performed again when compiling enclosing package bodies.
3670 end Inlining_Not_Possible;
3676 procedure Make_Inline (Subp : Entity_Id) is
3677 Kind : constant Entity_Kind := Ekind (Subp);
3678 Inner_Subp : Entity_Id := Subp;
3681 -- Ignore if bad type, avoid cascaded error
3683 if Etype (Subp) = Any_Type then
3687 -- Ignore if all inlining is suppressed
3689 elsif Suppress_All_Inlining then
3693 -- If inlining is not possible, for now do not treat as an error
3695 elsif Inlining_Not_Possible (Subp) then
3699 -- Here we have a candidate for inlining, but we must exclude
3700 -- derived operations. Otherwise we would end up trying to inline
3701 -- a phantom declaration, and the result would be to drag in a
3702 -- body which has no direct inlining associated with it. That
3703 -- would not only be inefficient but would also result in the
3704 -- backend doing cross-unit inlining in cases where it was
3705 -- definitely inappropriate to do so.
3707 -- However, a simple Comes_From_Source test is insufficient, since
3708 -- we do want to allow inlining of generic instances which also do
3709 -- not come from source. We also need to recognize specs
3710 -- generated by the front-end for bodies that carry the pragma.
3711 -- Finally, predefined operators do not come from source but are
3712 -- not inlineable either.
3714 elsif Is_Generic_Instance (Subp)
3715 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3719 elsif not Comes_From_Source (Subp)
3720 and then Scope (Subp) /= Standard_Standard
3726 -- The referenced entity must either be the enclosing entity,
3727 -- or an entity declared within the current open scope.
3729 if Present (Scope (Subp))
3730 and then Scope (Subp) /= Current_Scope
3731 and then Subp /= Current_Scope
3734 ("argument of% must be entity in current scope", Assoc);
3738 -- Processing for procedure, operator or function.
3739 -- If subprogram is aliased (as for an instance) indicate
3740 -- that the renamed entity (if declared in the same unit)
3743 if Is_Subprogram (Subp) then
3744 while Present (Alias (Inner_Subp)) loop
3745 Inner_Subp := Alias (Inner_Subp);
3748 if In_Same_Source_Unit (Subp, Inner_Subp) then
3749 Set_Inline_Flags (Inner_Subp);
3751 Decl := Parent (Parent (Inner_Subp));
3753 if Nkind (Decl) = N_Subprogram_Declaration
3754 and then Present (Corresponding_Body (Decl))
3756 Set_Inline_Flags (Corresponding_Body (Decl));
3762 -- For a generic subprogram set flag as well, for use at
3763 -- the point of instantiation, to determine whether the
3764 -- body should be generated.
3766 elsif Is_Generic_Subprogram (Subp) then
3767 Set_Inline_Flags (Subp);
3770 -- Literals are by definition inlined
3772 elsif Kind = E_Enumeration_Literal then
3775 -- Anything else is an error
3779 ("expect subprogram name for pragma%", Assoc);
3783 ----------------------
3784 -- Set_Inline_Flags --
3785 ----------------------
3787 procedure Set_Inline_Flags (Subp : Entity_Id) is
3790 Set_Is_Inlined (Subp, True);
3793 if not Has_Pragma_Inline (Subp) then
3794 Set_Has_Pragma_Inline (Subp);
3798 if Prag_Id = Pragma_Inline_Always then
3799 Set_Has_Pragma_Inline_Always (Subp);
3801 end Set_Inline_Flags;
3803 -- Start of processing for Process_Inline
3806 Check_No_Identifiers;
3807 Check_At_Least_N_Arguments (1);
3810 Inline_Processing_Required := True;
3814 while Present (Assoc) loop
3815 Subp_Id := Expression (Assoc);
3819 if Is_Entity_Name (Subp_Id) then
3820 Subp := Entity (Subp_Id);
3822 if Subp = Any_Id then
3824 -- If previous error, avoid cascaded errors
3832 while Present (Homonym (Subp))
3833 and then Scope (Homonym (Subp)) = Current_Scope
3835 Make_Inline (Homonym (Subp));
3836 Subp := Homonym (Subp);
3843 ("inappropriate argument for pragma%", Assoc);
3846 and then Warn_On_Redundant_Constructs
3847 and then not Suppress_All_Inlining
3849 if Inlining_Not_Possible (Subp) then
3851 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3854 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3862 ----------------------------
3863 -- Process_Interface_Name --
3864 ----------------------------
3866 procedure Process_Interface_Name
3867 (Subprogram_Def : Entity_Id;
3873 String_Val : String_Id;
3875 procedure Check_Form_Of_Interface_Name (SN : Node_Id);
3876 -- SN is a string literal node for an interface name. This routine
3877 -- performs some minimal checks that the name is reasonable. In
3878 -- particular that no spaces or other obviously incorrect characters
3879 -- appear. This is only a warning, since any characters are allowed.
3881 ----------------------------------
3882 -- Check_Form_Of_Interface_Name --
3883 ----------------------------------
3885 procedure Check_Form_Of_Interface_Name (SN : Node_Id) is
3886 S : constant String_Id := Strval (Expr_Value_S (SN));
3887 SL : constant Nat := String_Length (S);
3892 Error_Msg_N ("interface name cannot be null string", SN);
3895 for J in 1 .. SL loop
3896 C := Get_String_Char (S, J);
3898 if Warn_On_Export_Import
3900 (not In_Character_Range (C)
3901 or else (Get_Character (C) = ' '
3902 and then VM_Target /= CLI_Target)
3903 or else Get_Character (C) = ',')
3906 ("?interface name contains illegal character", SN);
3909 end Check_Form_Of_Interface_Name;
3911 -- Start of processing for Process_Interface_Name
3914 if No (Link_Arg) then
3915 if No (Ext_Arg) then
3916 if VM_Target = CLI_Target
3917 and then Ekind (Subprogram_Def) = E_Package
3918 and then Nkind (Parent (Subprogram_Def)) =
3919 N_Package_Specification
3920 and then Present (Generic_Parent (Parent (Subprogram_Def)))
3925 (Generic_Parent (Parent (Subprogram_Def))));
3930 elsif Chars (Ext_Arg) = Name_Link_Name then
3932 Link_Nam := Expression (Ext_Arg);
3935 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3936 Ext_Nam := Expression (Ext_Arg);
3941 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3942 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3943 Ext_Nam := Expression (Ext_Arg);
3944 Link_Nam := Expression (Link_Arg);
3947 -- Check expressions for external name and link name are static
3949 if Present (Ext_Nam) then
3950 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3951 Check_Form_Of_Interface_Name (Ext_Nam);
3953 -- Verify that the external name is not the name of a local
3954 -- entity, which would hide the imported one and lead to
3955 -- run-time surprises. The problem can only arise for entities
3956 -- declared in a package body (otherwise the external name is
3957 -- fully qualified and won't conflict).
3965 if Prag_Id = Pragma_Import then
3966 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
3968 E := Entity_Id (Get_Name_Table_Info (Nam));
3970 if Nam /= Chars (Subprogram_Def)
3971 and then Present (E)
3972 and then not Is_Overloadable (E)
3973 and then Is_Immediately_Visible (E)
3974 and then not Is_Imported (E)
3975 and then Ekind (Scope (E)) = E_Package
3978 while Present (Par) loop
3979 if Nkind (Par) = N_Package_Body then
3980 Error_Msg_Sloc := Sloc (E);
3982 ("imported entity is hidden by & declared#",
3987 Par := Parent (Par);
3994 if Present (Link_Nam) then
3995 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
3996 Check_Form_Of_Interface_Name (Link_Nam);
3999 -- If there is no link name, just set the external name
4001 if No (Link_Nam) then
4002 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4004 -- For the Link_Name case, the given literal is preceded by an
4005 -- asterisk, which indicates to GCC that the given name should
4006 -- be taken literally, and in particular that no prepending of
4007 -- underlines should occur, even in systems where this is the
4013 if VM_Target = No_VM then
4014 Store_String_Char (Get_Char_Code ('*'));
4017 String_Val := Strval (Expr_Value_S (Link_Nam));
4018 Store_String_Chars (String_Val);
4020 Make_String_Literal (Sloc (Link_Nam),
4021 Strval => End_String);
4024 Set_Encoded_Interface_Name
4025 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4026 Check_Duplicated_Export_Name (Link_Nam);
4027 end Process_Interface_Name;
4029 -----------------------------------------
4030 -- Process_Interrupt_Or_Attach_Handler --
4031 -----------------------------------------
4033 procedure Process_Interrupt_Or_Attach_Handler is
4034 Arg1_X : constant Node_Id := Expression (Arg1);
4035 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4036 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4039 Set_Is_Interrupt_Handler (Handler_Proc);
4041 -- If the pragma is not associated with a handler procedure
4042 -- within a protected type, then it must be for a nonprotected
4043 -- procedure for the AAMP target, in which case we don't
4044 -- associate a representation item with the procedure's scope.
4046 if Ekind (Proc_Scope) = E_Protected_Type then
4047 if Prag_Id = Pragma_Interrupt_Handler
4049 Prag_Id = Pragma_Attach_Handler
4051 Record_Rep_Item (Proc_Scope, N);
4054 end Process_Interrupt_Or_Attach_Handler;
4056 --------------------------------------------------
4057 -- Process_Restrictions_Or_Restriction_Warnings --
4058 --------------------------------------------------
4060 -- Note: some of the simple identifier cases were handled in par-prag,
4061 -- but it is harmless (and more straightforward) to simply handle all
4062 -- cases here, even if it means we repeat a bit of work in some cases.
4064 procedure Process_Restrictions_Or_Restriction_Warnings
4068 R_Id : Restriction_Id;
4073 procedure Check_Unit_Name (N : Node_Id);
4074 -- Checks unit name parameter for No_Dependence. Returns if it has
4075 -- an appropriate form, otherwise raises pragma argument error.
4077 ---------------------
4078 -- Check_Unit_Name --
4079 ---------------------
4081 procedure Check_Unit_Name (N : Node_Id) is
4083 if Nkind (N) = N_Selected_Component then
4084 Check_Unit_Name (Prefix (N));
4085 Check_Unit_Name (Selector_Name (N));
4087 elsif Nkind (N) = N_Identifier then
4092 ("wrong form for unit name for No_Dependence", N);
4094 end Check_Unit_Name;
4096 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4099 Check_Ada_83_Warning;
4100 Check_At_Least_N_Arguments (1);
4101 Check_Valid_Configuration_Pragma;
4104 while Present (Arg) loop
4106 Expr := Expression (Arg);
4108 -- Case of no restriction identifier present
4110 if Id = No_Name then
4111 if Nkind (Expr) /= N_Identifier then
4113 ("invalid form for restriction", Arg);
4118 (Process_Restriction_Synonyms (Expr));
4120 if R_Id not in All_Boolean_Restrictions then
4121 Error_Msg_Name_1 := Pname;
4123 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4125 -- Check for possible misspelling
4127 for J in Restriction_Id loop
4129 Rnm : constant String := Restriction_Id'Image (J);
4132 Name_Buffer (1 .. Rnm'Length) := Rnm;
4133 Name_Len := Rnm'Length;
4134 Set_Casing (All_Lower_Case);
4136 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4138 (Identifier_Casing (Current_Source_File));
4139 Error_Msg_String (1 .. Rnm'Length) :=
4140 Name_Buffer (1 .. Name_Len);
4141 Error_Msg_Strlen := Rnm'Length;
4143 ("\possible misspelling of ""~""",
4144 Get_Pragma_Arg (Arg));
4153 if Implementation_Restriction (R_Id) then
4154 Check_Restriction (No_Implementation_Restrictions, Arg);
4157 -- If this is a warning, then set the warning unless we already
4158 -- have a real restriction active (we never want a warning to
4159 -- override a real restriction).
4162 if not Restriction_Active (R_Id) then
4163 Set_Restriction (R_Id, N);
4164 Restriction_Warnings (R_Id) := True;
4167 -- If real restriction case, then set it and make sure that the
4168 -- restriction warning flag is off, since a real restriction
4169 -- always overrides a warning.
4172 Set_Restriction (R_Id, N);
4173 Restriction_Warnings (R_Id) := False;
4176 -- A very special case that must be processed here: pragma
4177 -- Restrictions (No_Exceptions) turns off all run-time
4178 -- checking. This is a bit dubious in terms of the formal
4179 -- language definition, but it is what is intended by RM
4180 -- H.4(12). Restriction_Warnings never affects generated code
4181 -- so this is done only in the real restriction case.
4183 if R_Id = No_Exceptions and then not Warn then
4184 Scope_Suppress := (others => True);
4187 -- Case of No_Dependence => unit-name. Note that the parser
4188 -- already made the necessary entry in the No_Dependence table.
4190 elsif Id = Name_No_Dependence then
4191 Check_Unit_Name (Expr);
4193 -- All other cases of restriction identifier present
4196 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4197 Analyze_And_Resolve (Expr, Any_Integer);
4199 if R_Id not in All_Parameter_Restrictions then
4201 ("invalid restriction parameter identifier", Arg);
4203 elsif not Is_OK_Static_Expression (Expr) then
4204 Flag_Non_Static_Expr
4205 ("value must be static expression!", Expr);
4208 elsif not Is_Integer_Type (Etype (Expr))
4209 or else Expr_Value (Expr) < 0
4212 ("value must be non-negative integer", Arg);
4215 -- Restriction pragma is active
4217 Val := Expr_Value (Expr);
4219 if not UI_Is_In_Int_Range (Val) then
4221 ("pragma ignored, value too large?", Arg);
4224 -- Warning case. If the real restriction is active, then we
4225 -- ignore the request, since warning never overrides a real
4226 -- restriction. Otherwise we set the proper warning. Note that
4227 -- this circuit sets the warning again if it is already set,
4228 -- which is what we want, since the constant may have changed.
4231 if not Restriction_Active (R_Id) then
4233 (R_Id, N, Integer (UI_To_Int (Val)));
4234 Restriction_Warnings (R_Id) := True;
4237 -- Real restriction case, set restriction and make sure warning
4238 -- flag is off since real restriction always overrides warning.
4241 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4242 Restriction_Warnings (R_Id) := False;
4248 end Process_Restrictions_Or_Restriction_Warnings;
4250 ---------------------------------
4251 -- Process_Suppress_Unsuppress --
4252 ---------------------------------
4254 -- Note: this procedure makes entries in the check suppress data
4255 -- structures managed by Sem. See spec of package Sem for full
4256 -- details on how we handle recording of check suppression.
4258 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4263 In_Package_Spec : constant Boolean :=
4264 (Ekind (Current_Scope) = E_Package
4266 Ekind (Current_Scope) = E_Generic_Package)
4267 and then not In_Package_Body (Current_Scope);
4269 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4270 -- Used to suppress a single check on the given entity
4272 --------------------------------
4273 -- Suppress_Unsuppress_Echeck --
4274 --------------------------------
4276 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4278 Set_Checks_May_Be_Suppressed (E);
4280 if In_Package_Spec then
4281 Push_Global_Suppress_Stack_Entry
4284 Suppress => Suppress_Case);
4287 Push_Local_Suppress_Stack_Entry
4290 Suppress => Suppress_Case);
4293 -- If this is a first subtype, and the base type is distinct,
4294 -- then also set the suppress flags on the base type.
4296 if Is_First_Subtype (E)
4297 and then Etype (E) /= E
4299 Suppress_Unsuppress_Echeck (Etype (E), C);
4301 end Suppress_Unsuppress_Echeck;
4303 -- Start of processing for Process_Suppress_Unsuppress
4306 -- Suppress/Unsuppress can appear as a configuration pragma,
4307 -- or in a declarative part or a package spec (RM 11.5(5))
4309 if not Is_Configuration_Pragma then
4310 Check_Is_In_Decl_Part_Or_Package_Spec;
4313 Check_At_Least_N_Arguments (1);
4314 Check_At_Most_N_Arguments (2);
4315 Check_No_Identifier (Arg1);
4316 Check_Arg_Is_Identifier (Arg1);
4318 C := Get_Check_Id (Chars (Expression (Arg1)));
4320 if C = No_Check_Id then
4322 ("argument of pragma% is not valid check name", Arg1);
4325 if not Suppress_Case
4326 and then (C = All_Checks or else C = Overflow_Check)
4328 Opt.Overflow_Checks_Unsuppressed := True;
4331 if Arg_Count = 1 then
4333 -- Make an entry in the local scope suppress table. This is the
4334 -- table that directly shows the current value of the scope
4335 -- suppress check for any check id value.
4337 if C = All_Checks then
4339 -- For All_Checks, we set all specific predefined checks with
4340 -- the exception of Elaboration_Check, which is handled
4341 -- specially because of not wanting All_Checks to have the
4342 -- effect of deactivating static elaboration order processing.
4344 for J in Scope_Suppress'Range loop
4345 if J /= Elaboration_Check then
4346 Scope_Suppress (J) := Suppress_Case;
4350 -- If not All_Checks, and predefined check, then set appropriate
4351 -- scope entry. Note that we will set Elaboration_Check if this
4352 -- is explicitly specified.
4354 elsif C in Predefined_Check_Id then
4355 Scope_Suppress (C) := Suppress_Case;
4358 -- Also make an entry in the Local_Entity_Suppress table
4360 Push_Local_Suppress_Stack_Entry
4363 Suppress => Suppress_Case);
4365 -- Case of two arguments present, where the check is suppressed for
4366 -- a specified entity (given as the second argument of the pragma)
4369 Check_Optional_Identifier (Arg2, Name_On);
4370 E_Id := Expression (Arg2);
4373 if not Is_Entity_Name (E_Id) then
4375 ("second argument of pragma% must be entity name", Arg2);
4384 -- Enforce RM 11.5(7) which requires that for a pragma that
4385 -- appears within a package spec, the named entity must be
4386 -- within the package spec. We allow the package name itself
4387 -- to be mentioned since that makes sense, although it is not
4388 -- strictly allowed by 11.5(7).
4391 and then E /= Current_Scope
4392 and then Scope (E) /= Current_Scope
4395 ("entity in pragma% is not in package spec (RM 11.5(7))",
4399 -- Loop through homonyms. As noted below, in the case of a package
4400 -- spec, only homonyms within the package spec are considered.
4403 Suppress_Unsuppress_Echeck (E, C);
4405 if Is_Generic_Instance (E)
4406 and then Is_Subprogram (E)
4407 and then Present (Alias (E))
4409 Suppress_Unsuppress_Echeck (Alias (E), C);
4412 -- Move to next homonym
4417 -- If we are within a package specification, the
4418 -- pragma only applies to homonyms in the same scope.
4420 exit when In_Package_Spec
4421 and then Scope (E) /= Current_Scope;
4424 end Process_Suppress_Unsuppress;
4430 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4432 if Is_Imported (E) then
4434 ("cannot export entity& that was previously imported", Arg);
4436 elsif Present (Address_Clause (E)) then
4438 ("cannot export entity& that has an address clause", Arg);
4441 Set_Is_Exported (E);
4443 -- Generate a reference for entity explicitly, because the
4444 -- identifier may be overloaded and name resolution will not
4447 Generate_Reference (E, Arg);
4449 -- Deal with exporting non-library level entity
4451 if not Is_Library_Level_Entity (E) then
4453 -- Not allowed at all for subprograms
4455 if Is_Subprogram (E) then
4456 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4458 -- Otherwise set public and statically allocated
4462 Set_Is_Statically_Allocated (E);
4464 -- Warn if the corresponding W flag is set and the pragma
4465 -- comes from source. The latter may not be true e.g. on
4466 -- VMS where we expand export pragmas for exception codes
4467 -- associated with imported or exported exceptions. We do
4468 -- not want to generate a warning for something that the
4469 -- user did not write.
4471 if Warn_On_Export_Import
4472 and then Comes_From_Source (Arg)
4475 ("?& has been made static as a result of Export", Arg, E);
4477 ("\this usage is non-standard and non-portable", Arg);
4482 if Warn_On_Export_Import and then Is_Type (E) then
4484 ("exporting a type has no effect?", Arg, E);
4487 if Warn_On_Export_Import and Inside_A_Generic then
4489 ("all instances of& will have the same external name?", Arg, E);
4493 ----------------------------------------------
4494 -- Set_Extended_Import_Export_External_Name --
4495 ----------------------------------------------
4497 procedure Set_Extended_Import_Export_External_Name
4498 (Internal_Ent : Entity_Id;
4499 Arg_External : Node_Id)
4501 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4505 if No (Arg_External) then
4509 Check_Arg_Is_External_Name (Arg_External);
4511 if Nkind (Arg_External) = N_String_Literal then
4512 if String_Length (Strval (Arg_External)) = 0 then
4515 New_Name := Adjust_External_Name_Case (Arg_External);
4518 elsif Nkind (Arg_External) = N_Identifier then
4519 New_Name := Get_Default_External_Name (Arg_External);
4521 -- Check_Arg_Is_External_Name should let through only
4522 -- identifiers and string literals or static string
4523 -- expressions (which are folded to string literals).
4526 raise Program_Error;
4529 -- If we already have an external name set (by a prior normal
4530 -- Import or Export pragma), then the external names must match
4532 if Present (Interface_Name (Internal_Ent)) then
4533 Check_Matching_Internal_Names : declare
4534 S1 : constant String_Id := Strval (Old_Name);
4535 S2 : constant String_Id := Strval (New_Name);
4538 -- Called if names do not match
4544 procedure Mismatch is
4546 Error_Msg_Sloc := Sloc (Old_Name);
4548 ("external name does not match that given #",
4552 -- Start of processing for Check_Matching_Internal_Names
4555 if String_Length (S1) /= String_Length (S2) then
4559 for J in 1 .. String_Length (S1) loop
4560 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4565 end Check_Matching_Internal_Names;
4567 -- Otherwise set the given name
4570 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4571 Check_Duplicated_Export_Name (New_Name);
4573 end Set_Extended_Import_Export_External_Name;
4579 procedure Set_Imported (E : Entity_Id) is
4581 -- Error message if already imported or exported
4583 if Is_Exported (E) or else Is_Imported (E) then
4584 if Is_Exported (E) then
4585 Error_Msg_NE ("entity& was previously exported", N, E);
4587 Error_Msg_NE ("entity& was previously imported", N, E);
4590 Error_Msg_Name_1 := Pname;
4592 ("\(pragma% applies to all previous entities)", N);
4594 Error_Msg_Sloc := Sloc (E);
4595 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4597 -- Here if not previously imported or exported, OK to import
4600 Set_Is_Imported (E);
4602 -- If the entity is an object that is not at the library
4603 -- level, then it is statically allocated. We do not worry
4604 -- about objects with address clauses in this context since
4605 -- they are not really imported in the linker sense.
4608 and then not Is_Library_Level_Entity (E)
4609 and then No (Address_Clause (E))
4611 Set_Is_Statically_Allocated (E);
4616 -------------------------
4617 -- Set_Mechanism_Value --
4618 -------------------------
4620 -- Note: the mechanism name has not been analyzed (and cannot indeed
4621 -- be analyzed, since it is semantic nonsense), so we get it in the
4622 -- exact form created by the parser.
4624 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4628 procedure Bad_Class;
4629 -- Signal bad descriptor class name
4631 procedure Bad_Mechanism;
4632 -- Signal bad mechanism name
4638 procedure Bad_Class is
4640 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4643 -------------------------
4644 -- Bad_Mechanism_Value --
4645 -------------------------
4647 procedure Bad_Mechanism is
4649 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4652 -- Start of processing for Set_Mechanism_Value
4655 if Mechanism (Ent) /= Default_Mechanism then
4657 ("mechanism for & has already been set", Mech_Name, Ent);
4660 -- MECHANISM_NAME ::= value | reference | descriptor
4662 if Nkind (Mech_Name) = N_Identifier then
4663 if Chars (Mech_Name) = Name_Value then
4664 Set_Mechanism (Ent, By_Copy);
4667 elsif Chars (Mech_Name) = Name_Reference then
4668 Set_Mechanism (Ent, By_Reference);
4671 elsif Chars (Mech_Name) = Name_Descriptor then
4672 Check_VMS (Mech_Name);
4673 Set_Mechanism (Ent, By_Descriptor);
4676 elsif Chars (Mech_Name) = Name_Copy then
4678 ("bad mechanism name, Value assumed", Mech_Name);
4684 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
4685 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4687 -- Note: this form is parsed as an indexed component
4689 elsif Nkind (Mech_Name) = N_Indexed_Component then
4690 Class := First (Expressions (Mech_Name));
4692 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4693 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
4694 or else Present (Next (Class))
4699 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
4700 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4702 -- Note: this form is parsed as a function call
4704 elsif Nkind (Mech_Name) = N_Function_Call then
4706 Param := First (Parameter_Associations (Mech_Name));
4708 if Nkind (Name (Mech_Name)) /= N_Identifier
4709 or else Chars (Name (Mech_Name)) /= Name_Descriptor
4710 or else Present (Next (Param))
4711 or else No (Selector_Name (Param))
4712 or else Chars (Selector_Name (Param)) /= Name_Class
4716 Class := Explicit_Actual_Parameter (Param);
4723 -- Fall through here with Class set to descriptor class name
4725 Check_VMS (Mech_Name);
4727 if Nkind (Class) /= N_Identifier then
4730 elsif Chars (Class) = Name_UBS then
4731 Set_Mechanism (Ent, By_Descriptor_UBS);
4733 elsif Chars (Class) = Name_UBSB then
4734 Set_Mechanism (Ent, By_Descriptor_UBSB);
4736 elsif Chars (Class) = Name_UBA then
4737 Set_Mechanism (Ent, By_Descriptor_UBA);
4739 elsif Chars (Class) = Name_S then
4740 Set_Mechanism (Ent, By_Descriptor_S);
4742 elsif Chars (Class) = Name_SB then
4743 Set_Mechanism (Ent, By_Descriptor_SB);
4745 elsif Chars (Class) = Name_A then
4746 Set_Mechanism (Ent, By_Descriptor_A);
4748 elsif Chars (Class) = Name_NCA then
4749 Set_Mechanism (Ent, By_Descriptor_NCA);
4754 end Set_Mechanism_Value;
4756 ---------------------------
4757 -- Set_Ravenscar_Profile --
4758 ---------------------------
4760 -- The tasks to be done here are
4762 -- Set required policies
4764 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4765 -- pragma Locking_Policy (Ceiling_Locking)
4767 -- Set Detect_Blocking mode
4769 -- Set required restrictions (see System.Rident for detailed list)
4771 procedure Set_Ravenscar_Profile (N : Node_Id) is
4773 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4775 if Task_Dispatching_Policy /= ' '
4776 and then Task_Dispatching_Policy /= 'F'
4778 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4779 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4781 -- Set the FIFO_Within_Priorities policy, but always preserve
4782 -- System_Location since we like the error message with the run time
4786 Task_Dispatching_Policy := 'F';
4788 if Task_Dispatching_Policy_Sloc /= System_Location then
4789 Task_Dispatching_Policy_Sloc := Loc;
4793 -- pragma Locking_Policy (Ceiling_Locking)
4795 if Locking_Policy /= ' '
4796 and then Locking_Policy /= 'C'
4798 Error_Msg_Sloc := Locking_Policy_Sloc;
4799 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4801 -- Set the Ceiling_Locking policy, but preserve System_Location since
4802 -- we like the error message with the run time name.
4805 Locking_Policy := 'C';
4807 if Locking_Policy_Sloc /= System_Location then
4808 Locking_Policy_Sloc := Loc;
4812 -- pragma Detect_Blocking
4814 Detect_Blocking := True;
4816 -- Set the corresponding restrictions
4818 Set_Profile_Restrictions
4819 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4820 end Set_Ravenscar_Profile;
4822 -- Start of processing for Analyze_Pragma
4825 -- Deal with unrecognized pragma
4827 if not Is_Pragma_Name (Pname) then
4828 if Warn_On_Unrecognized_Pragma then
4829 Error_Msg_Name_1 := Pname;
4830 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
4832 for PN in First_Pragma_Name .. Last_Pragma_Name loop
4833 if Is_Bad_Spelling_Of (Pname, PN) then
4834 Error_Msg_Name_1 := PN;
4836 ("\?possible misspelling of %!", Pragma_Identifier (N));
4845 -- Here to start processing for recognized pragma
4847 Prag_Id := Get_Pragma_Id (Pname);
4856 if Present (Pragma_Argument_Associations (N)) then
4857 Arg1 := First (Pragma_Argument_Associations (N));
4859 if Present (Arg1) then
4860 Arg2 := Next (Arg1);
4862 if Present (Arg2) then
4863 Arg3 := Next (Arg2);
4865 if Present (Arg3) then
4866 Arg4 := Next (Arg3);
4872 -- Count number of arguments
4879 while Present (Arg_Node) loop
4880 Arg_Count := Arg_Count + 1;
4885 -- An enumeration type defines the pragmas that are supported by the
4886 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
4887 -- into the corresponding enumeration value for the following case.
4895 -- pragma Abort_Defer;
4897 when Pragma_Abort_Defer =>
4899 Check_Arg_Count (0);
4901 -- The only required semantic processing is to check the
4902 -- placement. This pragma must appear at the start of the
4903 -- statement sequence of a handled sequence of statements.
4905 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
4906 or else N /= First (Statements (Parent (N)))
4917 -- Note: this pragma also has some specific processing in Par.Prag
4918 -- because we want to set the Ada version mode during parsing.
4920 when Pragma_Ada_83 =>
4922 Check_Arg_Count (0);
4924 -- We really should check unconditionally for proper configuration
4925 -- pragma placement, since we really don't want mixed Ada modes
4926 -- within a single unit, and the GNAT reference manual has always
4927 -- said this was a configuration pragma, but we did not check and
4928 -- are hesitant to add the check now.
4930 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
4931 -- or Ada 95, so we must check if we are in Ada 2005 mode.
4933 if Ada_Version >= Ada_05 then
4934 Check_Valid_Configuration_Pragma;
4937 -- Now set Ada 83 mode
4939 Ada_Version := Ada_83;
4940 Ada_Version_Explicit := Ada_Version;
4948 -- Note: this pragma also has some specific processing in Par.Prag
4949 -- because we want to set the Ada 83 version mode during parsing.
4951 when Pragma_Ada_95 =>
4953 Check_Arg_Count (0);
4955 -- We really should check unconditionally for proper configuration
4956 -- pragma placement, since we really don't want mixed Ada modes
4957 -- within a single unit, and the GNAT reference manual has always
4958 -- said this was a configuration pragma, but we did not check and
4959 -- are hesitant to add the check now.
4961 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
4962 -- or Ada 95, so we must check if we are in Ada 2005 mode.
4964 if Ada_Version >= Ada_05 then
4965 Check_Valid_Configuration_Pragma;
4968 -- Now set Ada 95 mode
4970 Ada_Version := Ada_95;
4971 Ada_Version_Explicit := Ada_Version;
4973 ---------------------
4974 -- Ada_05/Ada_2005 --
4975 ---------------------
4978 -- pragma Ada_05 (LOCAL_NAME);
4981 -- pragma Ada_2005 (LOCAL_NAME):
4983 -- Note: these pragma also have some specific processing in Par.Prag
4984 -- because we want to set the Ada 2005 version mode during parsing.
4986 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
4992 if Arg_Count = 1 then
4993 Check_Arg_Is_Local_Name (Arg1);
4994 E_Id := Expression (Arg1);
4996 if Etype (E_Id) = Any_Type then
5000 Set_Is_Ada_2005_Only (Entity (E_Id));
5003 Check_Arg_Count (0);
5005 -- For Ada_2005 we unconditionally enforce the documented
5006 -- configuration pragma placement, since we do not want to
5007 -- tolerate mixed modes in a unit involving Ada 2005. That
5008 -- would cause real difficulties for those cases where there
5009 -- are incompatibilities between Ada 95 and Ada 2005.
5011 Check_Valid_Configuration_Pragma;
5013 -- Now set Ada 2005 mode
5015 Ada_Version := Ada_05;
5016 Ada_Version_Explicit := Ada_05;
5020 ----------------------
5021 -- All_Calls_Remote --
5022 ----------------------
5024 -- pragma All_Calls_Remote [(library_package_NAME)];
5026 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5027 Lib_Entity : Entity_Id;
5030 Check_Ada_83_Warning;
5031 Check_Valid_Library_Unit_Pragma;
5033 if Nkind (N) = N_Null_Statement then
5037 Lib_Entity := Find_Lib_Unit_Name;
5039 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5041 if Present (Lib_Entity)
5042 and then not Debug_Flag_U
5044 if not Is_Remote_Call_Interface (Lib_Entity) then
5045 Error_Pragma ("pragma% only apply to rci unit");
5047 -- Set flag for entity of the library unit
5050 Set_Has_All_Calls_Remote (Lib_Entity);
5054 end All_Calls_Remote;
5060 -- pragma Annotate (IDENTIFIER {, ARG});
5061 -- ARG ::= NAME | EXPRESSION
5063 when Pragma_Annotate => Annotate : begin
5065 Check_At_Least_N_Arguments (1);
5066 Check_Arg_Is_Identifier (Arg1);
5074 while Present (Arg) loop
5075 Exp := Expression (Arg);
5078 if Is_Entity_Name (Exp) then
5081 elsif Nkind (Exp) = N_String_Literal then
5082 Resolve (Exp, Standard_String);
5084 elsif Is_Overloaded (Exp) then
5085 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
5100 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5101 -- [, [Message =>] Static_String_EXPRESSION]);
5103 when Pragma_Assert => Assert : declare
5109 Check_At_Least_N_Arguments (1);
5110 Check_At_Most_N_Arguments (2);
5111 Check_Arg_Order ((Name_Check, Name_Message));
5112 Check_Optional_Identifier (Arg1, Name_Check);
5114 -- We treat pragma Assert as equivalent to:
5116 -- pragma Check (Assertion, condition [, msg]);
5118 -- So rewrite pragma in this manner, and analyze the result
5120 Expr := Get_Pragma_Arg (Arg1);
5122 Make_Pragma_Argument_Association (Loc,
5124 Make_Identifier (Loc,
5125 Chars => Name_Assertion)),
5127 Make_Pragma_Argument_Association (Sloc (Expr),
5128 Expression => Expr));
5130 if Arg_Count > 1 then
5131 Check_Optional_Identifier (Arg2, Name_Message);
5132 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5133 Append_To (Newa, Relocate_Node (Arg2));
5138 Chars => Name_Check,
5139 Pragma_Argument_Associations => Newa));
5143 ----------------------
5144 -- Assertion_Policy --
5145 ----------------------
5147 -- pragma Assertion_Policy (Check | Ignore)
5149 when Pragma_Assertion_Policy => Assertion_Policy : declare
5154 Check_Valid_Configuration_Pragma;
5155 Check_Arg_Count (1);
5156 Check_No_Identifiers;
5157 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5159 -- We treat pragma Assertion_Policy as equivalent to:
5161 -- pragma Check_Policy (Assertion, policy)
5163 -- So rewrite the pragma in that manner and link on to the chain
5164 -- of Check_Policy pragmas, marking the pragma as analyzed.
5166 Policy := Get_Pragma_Arg (Arg1);
5170 Chars => Name_Check_Policy,
5172 Pragma_Argument_Associations => New_List (
5173 Make_Pragma_Argument_Association (Loc,
5175 Make_Identifier (Loc,
5176 Chars => Name_Assertion)),
5178 Make_Pragma_Argument_Association (Loc,
5180 Make_Identifier (Sloc (Policy),
5181 Chars => Chars (Policy))))));
5184 Set_Next_Pragma (N, Opt.Check_Policy_List);
5185 Opt.Check_Policy_List := N;
5186 end Assertion_Policy;
5192 -- pragma AST_Entry (entry_IDENTIFIER);
5194 when Pragma_AST_Entry => AST_Entry : declare
5200 Check_Arg_Count (1);
5201 Check_No_Identifiers;
5202 Check_Arg_Is_Local_Name (Arg1);
5203 Ent := Entity (Expression (Arg1));
5205 -- Note: the implementation of the AST_Entry pragma could handle
5206 -- the entry family case fine, but for now we are consistent with
5207 -- the DEC rules, and do not allow the pragma, which of course
5208 -- has the effect of also forbidding the attribute.
5210 if Ekind (Ent) /= E_Entry then
5212 ("pragma% argument must be simple entry name", Arg1);
5214 elsif Is_AST_Entry (Ent) then
5216 ("duplicate % pragma for entry", Arg1);
5218 elsif Has_Homonym (Ent) then
5220 ("pragma% argument cannot specify overloaded entry", Arg1);
5224 FF : constant Entity_Id := First_Formal (Ent);
5227 if Present (FF) then
5228 if Present (Next_Formal (FF)) then
5230 ("entry for pragma% can have only one argument",
5233 elsif Parameter_Mode (FF) /= E_In_Parameter then
5235 ("entry parameter for pragma% must have mode IN",
5241 Set_Is_AST_Entry (Ent);
5249 -- pragma Asynchronous (LOCAL_NAME);
5251 when Pragma_Asynchronous => Asynchronous : declare
5259 procedure Process_Async_Pragma;
5260 -- Common processing for procedure and access-to-procedure case
5262 --------------------------
5263 -- Process_Async_Pragma --
5264 --------------------------
5266 procedure Process_Async_Pragma is
5269 Set_Is_Asynchronous (Nm);
5273 -- The formals should be of mode IN (RM E.4.1(6))
5276 while Present (S) loop
5277 Formal := Defining_Identifier (S);
5279 if Nkind (Formal) = N_Defining_Identifier
5280 and then Ekind (Formal) /= E_In_Parameter
5283 ("pragma% procedure can only have IN parameter",
5290 Set_Is_Asynchronous (Nm);
5291 end Process_Async_Pragma;
5293 -- Start of processing for pragma Asynchronous
5296 Check_Ada_83_Warning;
5297 Check_No_Identifiers;
5298 Check_Arg_Count (1);
5299 Check_Arg_Is_Local_Name (Arg1);
5301 if Debug_Flag_U then
5305 C_Ent := Cunit_Entity (Current_Sem_Unit);
5306 Analyze (Expression (Arg1));
5307 Nm := Entity (Expression (Arg1));
5309 if not Is_Remote_Call_Interface (C_Ent)
5310 and then not Is_Remote_Types (C_Ent)
5312 -- This pragma should only appear in an RCI or Remote Types
5313 -- unit (RM E.4.1(4))
5316 ("pragma% not in Remote_Call_Interface or " &
5317 "Remote_Types unit");
5320 if Ekind (Nm) = E_Procedure
5321 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5323 if not Is_Remote_Call_Interface (Nm) then
5325 ("pragma% cannot be applied on non-remote procedure",
5329 L := Parameter_Specifications (Parent (Nm));
5330 Process_Async_Pragma;
5333 elsif Ekind (Nm) = E_Function then
5335 ("pragma% cannot be applied to function", Arg1);
5337 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5339 if Is_Record_Type (Nm) then
5340 -- A record type that is the Equivalent_Type for
5341 -- a remote access-to-subprogram type.
5343 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5346 -- A non-expanded RAS type (case where distribution is
5349 N := Declaration_Node (Nm);
5352 if Nkind (N) = N_Full_Type_Declaration
5353 and then Nkind (Type_Definition (N)) =
5354 N_Access_Procedure_Definition
5356 L := Parameter_Specifications (Type_Definition (N));
5357 Process_Async_Pragma;
5359 if Is_Asynchronous (Nm)
5360 and then Expander_Active
5361 and then Get_PCS_Name /= Name_No_DSA
5363 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5368 ("pragma% cannot reference access-to-function type",
5372 -- Only other possibility is Access-to-class-wide type
5374 elsif Is_Access_Type (Nm)
5375 and then Is_Class_Wide_Type (Designated_Type (Nm))
5377 Check_First_Subtype (Arg1);
5378 Set_Is_Asynchronous (Nm);
5379 if Expander_Active then
5380 RACW_Type_Is_Asynchronous (Nm);
5384 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5392 -- pragma Atomic (LOCAL_NAME);
5394 when Pragma_Atomic =>
5395 Process_Atomic_Shared_Volatile;
5397 -----------------------
5398 -- Atomic_Components --
5399 -----------------------
5401 -- pragma Atomic_Components (array_LOCAL_NAME);
5403 -- This processing is shared by Volatile_Components
5405 when Pragma_Atomic_Components |
5406 Pragma_Volatile_Components =>
5408 Atomic_Components : declare
5415 Check_Ada_83_Warning;
5416 Check_No_Identifiers;
5417 Check_Arg_Count (1);
5418 Check_Arg_Is_Local_Name (Arg1);
5419 E_Id := Expression (Arg1);
5421 if Etype (E_Id) = Any_Type then
5427 if Rep_Item_Too_Early (E, N)
5429 Rep_Item_Too_Late (E, N)
5434 D := Declaration_Node (E);
5437 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5439 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5440 and then Nkind (D) = N_Object_Declaration
5441 and then Nkind (Object_Definition (D)) =
5442 N_Constrained_Array_Definition)
5444 -- The flag is set on the object, or on the base type
5446 if Nkind (D) /= N_Object_Declaration then
5450 Set_Has_Volatile_Components (E);
5452 if Prag_Id = Pragma_Atomic_Components then
5453 Set_Has_Atomic_Components (E);
5455 if Is_Packed (E) then
5456 Set_Is_Packed (E, False);
5459 ("?Pack canceled, cannot pack atomic components",
5465 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5467 end Atomic_Components;
5469 --------------------
5470 -- Attach_Handler --
5471 --------------------
5473 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5475 when Pragma_Attach_Handler =>
5476 Check_Ada_83_Warning;
5477 Check_No_Identifiers;
5478 Check_Arg_Count (2);
5480 if No_Run_Time_Mode then
5481 Error_Msg_CRT ("Attach_Handler pragma", N);
5483 Check_Interrupt_Or_Attach_Handler;
5485 -- The expression that designates the attribute may
5486 -- depend on a discriminant, and is therefore a per-
5487 -- object expression, to be expanded in the init proc.
5488 -- If expansion is enabled, perform semantic checks
5491 if Expander_Active then
5493 Temp : constant Node_Id :=
5494 New_Copy_Tree (Expression (Arg2));
5496 Set_Parent (Temp, N);
5497 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5501 Analyze (Expression (Arg2));
5502 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5505 Process_Interrupt_Or_Attach_Handler;
5508 --------------------
5509 -- C_Pass_By_Copy --
5510 --------------------
5512 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5514 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5520 Check_Valid_Configuration_Pragma;
5521 Check_Arg_Count (1);
5522 Check_Optional_Identifier (Arg1, "max_size");
5524 Arg := Expression (Arg1);
5525 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5527 Val := Expr_Value (Arg);
5531 ("maximum size for pragma% must be positive", Arg1);
5533 elsif UI_Is_In_Int_Range (Val) then
5534 Default_C_Record_Mechanism := UI_To_Int (Val);
5536 -- If a giant value is given, Int'Last will do well enough.
5537 -- If sometime someone complains that a record larger than
5538 -- two gigabytes is not copied, we will worry about it then!
5541 Default_C_Record_Mechanism := Mechanism_Type'Last;
5549 -- pragma Check ([Name =>] Identifier,
5550 -- [Check =>] Boolean_Expression
5551 -- [,[Message =>] String_Expression]);
5553 when Pragma_Check => Check : declare
5558 -- Set True if category of assertions referenced by Name enabled
5562 Check_At_Least_N_Arguments (2);
5563 Check_At_Most_N_Arguments (3);
5564 Check_Optional_Identifier (Arg1, Name_Name);
5565 Check_Optional_Identifier (Arg2, Name_Check);
5567 if Arg_Count = 3 then
5568 Check_Optional_Identifier (Arg3, Name_Message);
5569 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5572 Check_Arg_Is_Identifier (Arg1);
5573 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5575 -- If expansion is active and the check is not enabled then we
5576 -- rewrite the Check as:
5578 -- if False and then condition then
5582 -- The reason we do this rewriting during semantic analysis rather
5583 -- than as part of normal expansion is that we cannot analyze and
5584 -- expand the code for the boolean expression directly, or it may
5585 -- cause insertion of actions that would escape the attempt to
5586 -- suppress the check code.
5588 -- Note that the Sloc for the if statement corresponds to the
5589 -- argument condition, not the pragma itself. The reason for this
5590 -- is that we may generate a warning if the condition is False at
5591 -- compile time, and we do not want to delete this warning when we
5592 -- delete the if statement.
5594 Expr := Expression (Arg2);
5596 if Expander_Active and then not Check_On then
5597 Eloc := Sloc (Expr);
5600 Make_If_Statement (Eloc,
5602 Make_And_Then (Eloc,
5603 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5604 Right_Opnd => Expr),
5605 Then_Statements => New_List (
5606 Make_Null_Statement (Eloc))));
5613 Analyze_And_Resolve (Expr, Any_Boolean);
5616 -- If assertion is of the form (X'First = literal), where X is
5617 -- a formal, then set Low_Bound_Known flag on this formal.
5619 if Nkind (Expr) = N_Op_Eq then
5621 Right : constant Node_Id := Right_Opnd (Expr);
5622 Left : constant Node_Id := Left_Opnd (Expr);
5624 if Nkind (Left) = N_Attribute_Reference
5625 and then Attribute_Name (Left) = Name_First
5626 and then Is_Entity_Name (Prefix (Left))
5627 and then Is_Formal (Entity (Prefix (Left)))
5628 and then Nkind (Right) = N_Integer_Literal
5630 Set_Low_Bound_Known (Entity (Prefix (Left)));
5640 -- pragma Check_Name (check_IDENTIFIER);
5642 when Pragma_Check_Name =>
5643 Check_No_Identifiers;
5645 Check_Valid_Configuration_Pragma;
5646 Check_Arg_Count (1);
5647 Check_Arg_Is_Identifier (Arg1);
5650 Nam : constant Name_Id := Chars (Expression (Arg1));
5653 for J in Check_Names.First .. Check_Names.Last loop
5654 if Check_Names.Table (J) = Nam then
5659 Check_Names.Append (Nam);
5666 -- pragma Check_Policy ([Name =>] IDENTIFIER,
5667 -- POLICY_IDENTIFIER;
5669 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5671 -- Note: this is a configuration pragma, but it is allowed to
5672 -- appear anywhere else.
5674 when Pragma_Check_Policy =>
5676 Check_Arg_Count (2);
5677 Check_No_Identifier (Arg2);
5678 Check_Optional_Identifier (Arg1, Name_Name);
5680 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5682 -- A Check_Policy pragma can appear either as a configuration
5683 -- pragma, or in a declarative part or a package spec (see RM
5684 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5685 -- followed for Check_Policy).
5687 if not Is_Configuration_Pragma then
5688 Check_Is_In_Decl_Part_Or_Package_Spec;
5691 Set_Next_Pragma (N, Opt.Check_Policy_List);
5692 Opt.Check_Policy_List := N;
5694 ---------------------
5695 -- CIL_Constructor --
5696 ---------------------
5698 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5700 -- Processing for this pragma is shared with Java_Constructor
5706 -- pragma Comment (static_string_EXPRESSION)
5708 -- Processing for pragma Comment shares the circuitry for
5709 -- pragma Ident. The only differences are that Ident enforces
5710 -- a limit of 31 characters on its argument, and also enforces
5711 -- limitations on placement for DEC compatibility. Pragma
5712 -- Comment shares neither of these restrictions.
5718 -- pragma Common_Object (
5719 -- [Internal =>] LOCAL_NAME
5720 -- [, [External =>] EXTERNAL_SYMBOL]
5721 -- [, [Size =>] EXTERNAL_SYMBOL]);
5723 -- Processing for this pragma is shared with Psect_Object
5725 ------------------------
5726 -- Compile_Time_Error --
5727 ------------------------
5729 -- pragma Compile_Time_Error
5730 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5732 when Pragma_Compile_Time_Error =>
5733 Process_Compile_Time_Warning_Or_Error;
5735 --------------------------
5736 -- Compile_Time_Warning --
5737 --------------------------
5739 -- pragma Compile_Time_Warning
5740 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5742 when Pragma_Compile_Time_Warning =>
5743 Process_Compile_Time_Warning_Or_Error;
5749 when Pragma_Compiler_Unit =>
5751 Check_Arg_Count (0);
5752 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5754 -----------------------------
5755 -- Complete_Representation --
5756 -----------------------------
5758 -- pragma Complete_Representation;
5760 when Pragma_Complete_Representation =>
5762 Check_Arg_Count (0);
5764 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5766 ("pragma & must appear within record representation clause");
5769 ----------------------------
5770 -- Complex_Representation --
5771 ----------------------------
5773 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5775 when Pragma_Complex_Representation => Complex_Representation : declare
5782 Check_Arg_Count (1);
5783 Check_Optional_Identifier (Arg1, Name_Entity);
5784 Check_Arg_Is_Local_Name (Arg1);
5785 E_Id := Expression (Arg1);
5787 if Etype (E_Id) = Any_Type then
5793 if not Is_Record_Type (E) then
5795 ("argument for pragma% must be record type", Arg1);
5798 Ent := First_Entity (E);
5801 or else No (Next_Entity (Ent))
5802 or else Present (Next_Entity (Next_Entity (Ent)))
5803 or else not Is_Floating_Point_Type (Etype (Ent))
5804 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5807 ("record for pragma% must have two fields of the same "
5808 & "floating-point type", Arg1);
5811 Set_Has_Complex_Representation (Base_Type (E));
5813 -- We need to treat the type has having a non-standard
5814 -- representation, for back-end purposes, even though in
5815 -- general a complex will have the default representation
5816 -- of a record with two real components.
5818 Set_Has_Non_Standard_Rep (Base_Type (E));
5820 end Complex_Representation;
5822 -------------------------
5823 -- Component_Alignment --
5824 -------------------------
5826 -- pragma Component_Alignment (
5827 -- [Form =>] ALIGNMENT_CHOICE
5828 -- [, [Name =>] type_LOCAL_NAME]);
5830 -- ALIGNMENT_CHOICE ::=
5832 -- | Component_Size_4
5836 when Pragma_Component_Alignment => Component_AlignmentP : declare
5837 Args : Args_List (1 .. 2);
5838 Names : constant Name_List (1 .. 2) := (
5842 Form : Node_Id renames Args (1);
5843 Name : Node_Id renames Args (2);
5845 Atype : Component_Alignment_Kind;
5850 Gather_Associations (Names, Args);
5853 Error_Pragma ("missing Form argument for pragma%");
5856 Check_Arg_Is_Identifier (Form);
5858 -- Get proper alignment, note that Default = Component_Size
5859 -- on all machines we have so far, and we want to set this
5860 -- value rather than the default value to indicate that it
5861 -- has been explicitly set (and thus will not get overridden
5862 -- by the default component alignment for the current scope)
5864 if Chars (Form) = Name_Component_Size then
5865 Atype := Calign_Component_Size;
5867 elsif Chars (Form) = Name_Component_Size_4 then
5868 Atype := Calign_Component_Size_4;
5870 elsif Chars (Form) = Name_Default then
5871 Atype := Calign_Component_Size;
5873 elsif Chars (Form) = Name_Storage_Unit then
5874 Atype := Calign_Storage_Unit;
5878 ("invalid Form parameter for pragma%", Form);
5881 -- Case with no name, supplied, affects scope table entry
5885 (Scope_Stack.Last).Component_Alignment_Default := Atype;
5887 -- Case of name supplied
5890 Check_Arg_Is_Local_Name (Name);
5892 Typ := Entity (Name);
5895 or else Rep_Item_Too_Early (Typ, N)
5899 Typ := Underlying_Type (Typ);
5902 if not Is_Record_Type (Typ)
5903 and then not Is_Array_Type (Typ)
5906 ("Name parameter of pragma% must identify record or " &
5907 "array type", Name);
5910 -- An explicit Component_Alignment pragma overrides an
5911 -- implicit pragma Pack, but not an explicit one.
5913 if not Has_Pragma_Pack (Base_Type (Typ)) then
5914 Set_Is_Packed (Base_Type (Typ), False);
5915 Set_Component_Alignment (Base_Type (Typ), Atype);
5918 end Component_AlignmentP;
5924 -- pragma Controlled (first_subtype_LOCAL_NAME);
5926 when Pragma_Controlled => Controlled : declare
5930 Check_No_Identifiers;
5931 Check_Arg_Count (1);
5932 Check_Arg_Is_Local_Name (Arg1);
5933 Arg := Expression (Arg1);
5935 if not Is_Entity_Name (Arg)
5936 or else not Is_Access_Type (Entity (Arg))
5938 Error_Pragma_Arg ("pragma% requires access type", Arg1);
5940 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
5948 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
5949 -- [Entity =>] LOCAL_NAME);
5951 when Pragma_Convention => Convention : declare
5954 pragma Warnings (Off, C);
5955 pragma Warnings (Off, E);
5957 Check_Arg_Order ((Name_Convention, Name_Entity));
5958 Check_Ada_83_Warning;
5959 Check_Arg_Count (2);
5960 Process_Convention (C, E);
5963 ---------------------------
5964 -- Convention_Identifier --
5965 ---------------------------
5967 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
5968 -- [Convention =>] convention_IDENTIFIER);
5970 when Pragma_Convention_Identifier => Convention_Identifier : declare
5976 Check_Arg_Order ((Name_Name, Name_Convention));
5977 Check_Arg_Count (2);
5978 Check_Optional_Identifier (Arg1, Name_Name);
5979 Check_Optional_Identifier (Arg2, Name_Convention);
5980 Check_Arg_Is_Identifier (Arg1);
5981 Check_Arg_Is_Identifier (Arg2);
5982 Idnam := Chars (Expression (Arg1));
5983 Cname := Chars (Expression (Arg2));
5985 if Is_Convention_Name (Cname) then
5986 Record_Convention_Identifier
5987 (Idnam, Get_Convention_Id (Cname));
5990 ("second arg for % pragma must be convention", Arg2);
5992 end Convention_Identifier;
5998 -- pragma CPP_Class ([Entity =>] local_NAME)
6000 when Pragma_CPP_Class => CPP_Class : declare
6005 if Warn_On_Obsolescent_Feature then
6007 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6008 " by pragma import?", N);
6012 Check_Arg_Count (1);
6013 Check_Optional_Identifier (Arg1, Name_Entity);
6014 Check_Arg_Is_Local_Name (Arg1);
6016 Arg := Expression (Arg1);
6019 if Etype (Arg) = Any_Type then
6023 if not Is_Entity_Name (Arg)
6024 or else not Is_Type (Entity (Arg))
6026 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6029 Typ := Entity (Arg);
6031 if not Is_Tagged_Type (Typ) then
6032 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6035 -- Types treated as CPP classes are treated as limited, but we
6036 -- don't require them to be declared this way. A warning is issued
6037 -- to encourage the user to declare them as limited. This is not
6038 -- an error, for compatibility reasons, because these types have
6039 -- been supported this way for some time.
6041 if not Is_Limited_Type (Typ) then
6043 ("imported 'C'P'P type should be " &
6044 "explicitly declared limited?",
6045 Get_Pragma_Arg (Arg1));
6047 ("\type will be considered limited",
6048 Get_Pragma_Arg (Arg1));
6051 Set_Is_CPP_Class (Typ);
6052 Set_Is_Limited_Record (Typ);
6053 Set_Convention (Typ, Convention_CPP);
6056 ---------------------
6057 -- CPP_Constructor --
6058 ---------------------
6060 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6061 -- [, [External_Name =>] static_string_EXPRESSION ]
6062 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6064 when Pragma_CPP_Constructor => CPP_Constructor : declare
6070 Check_At_Least_N_Arguments (1);
6071 Check_At_Most_N_Arguments (3);
6072 Check_Optional_Identifier (Arg1, Name_Entity);
6073 Check_Arg_Is_Local_Name (Arg1);
6075 Id := Expression (Arg1);
6076 Find_Program_Unit_Name (Id);
6078 -- If we did not find the name, we are done
6080 if Etype (Id) = Any_Type then
6084 Def_Id := Entity (Id);
6086 if Ekind (Def_Id) = E_Function
6087 and then Is_Class_Wide_Type (Etype (Def_Id))
6088 and then Is_CPP_Class (Etype (Etype (Def_Id)))
6090 if Arg_Count >= 2 then
6091 Set_Imported (Def_Id);
6092 Set_Is_Public (Def_Id);
6093 Process_Interface_Name (Def_Id, Arg2, Arg3);
6096 if No (Parameter_Specifications (Parent (Def_Id))) then
6097 Set_Has_Completion (Def_Id);
6098 Set_Is_Constructor (Def_Id);
6101 ("non-default constructors not implemented", Arg1);
6106 ("pragma% requires function returning a 'C'P'P_Class type",
6109 end CPP_Constructor;
6115 when Pragma_CPP_Virtual => CPP_Virtual : declare
6117 if Warn_On_Obsolescent_Feature then
6119 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6128 when Pragma_CPP_Vtable => CPP_Vtable : declare
6130 if Warn_On_Obsolescent_Feature then
6132 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6141 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6143 when Pragma_Debug => Debug : declare
6151 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6154 if Arg_Count = 2 then
6157 Left_Opnd => Relocate_Node (Cond),
6158 Right_Opnd => Expression (Arg1));
6161 -- Rewrite into a conditional with an appropriate condition. We
6162 -- wrap the procedure call in a block so that overhead from e.g.
6163 -- use of the secondary stack does not generate execution overhead
6164 -- for suppressed conditions.
6166 Rewrite (N, Make_Implicit_If_Statement (N,
6168 Then_Statements => New_List (
6169 Make_Block_Statement (Loc,
6170 Handled_Statement_Sequence =>
6171 Make_Handled_Sequence_Of_Statements (Loc,
6172 Statements => New_List (
6173 Relocate_Node (Debug_Statement (N))))))));
6181 -- pragma Debug_Policy (Check | Ignore)
6183 when Pragma_Debug_Policy =>
6185 Check_Arg_Count (1);
6186 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6187 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6189 ---------------------
6190 -- Detect_Blocking --
6191 ---------------------
6193 -- pragma Detect_Blocking;
6195 when Pragma_Detect_Blocking =>
6197 Check_Arg_Count (0);
6198 Check_Valid_Configuration_Pragma;
6199 Detect_Blocking := True;
6205 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6207 when Pragma_Discard_Names => Discard_Names : declare
6212 Check_Ada_83_Warning;
6214 -- Deal with configuration pragma case
6216 if Arg_Count = 0 and then Is_Configuration_Pragma then
6217 Global_Discard_Names := True;
6220 -- Otherwise, check correct appropriate context
6223 Check_Is_In_Decl_Part_Or_Package_Spec;
6225 if Arg_Count = 0 then
6227 -- If there is no parameter, then from now on this pragma
6228 -- applies to any enumeration, exception or tagged type
6229 -- defined in the current declarative part, and recursively
6230 -- to any nested scope.
6232 Set_Discard_Names (Current_Scope);
6236 Check_Arg_Count (1);
6237 Check_Optional_Identifier (Arg1, Name_On);
6238 Check_Arg_Is_Local_Name (Arg1);
6239 E_Id := Expression (Arg1);
6241 if Etype (E_Id) = Any_Type then
6247 if (Is_First_Subtype (E)
6248 and then (Is_Enumeration_Type (E)
6249 or else Is_Tagged_Type (E)))
6250 or else Ekind (E) = E_Exception
6252 Set_Discard_Names (E);
6255 ("inappropriate entity for pragma%", Arg1);
6265 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6267 when Pragma_Elaborate => Elaborate : declare
6272 -- Pragma must be in context items list of a compilation unit
6274 if not Is_In_Context_Clause then
6278 -- Must be at least one argument
6280 if Arg_Count = 0 then
6281 Error_Pragma ("pragma% requires at least one argument");
6284 -- In Ada 83 mode, there can be no items following it in the
6285 -- context list except other pragmas and implicit with clauses
6286 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6287 -- placement rule does not apply.
6289 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6291 while Present (Citem) loop
6292 if Nkind (Citem) = N_Pragma
6293 or else (Nkind (Citem) = N_With_Clause
6294 and then Implicit_With (Citem))
6299 ("(Ada 83) pragma% must be at end of context clause");
6306 -- Finally, the arguments must all be units mentioned in a with
6307 -- clause in the same context clause. Note we already checked (in
6308 -- Par.Prag) that the arguments are all identifiers or selected
6312 Outer : while Present (Arg) loop
6313 Citem := First (List_Containing (N));
6314 Inner : while Citem /= N loop
6315 if Nkind (Citem) = N_With_Clause
6316 and then Same_Name (Name (Citem), Expression (Arg))
6318 Set_Elaborate_Present (Citem, True);
6319 Set_Unit_Name (Expression (Arg), Name (Citem));
6321 -- With the pragma present, elaboration calls on
6322 -- subprograms from the named unit need no further
6323 -- checks, as long as the pragma appears in the current
6324 -- compilation unit. If the pragma appears in some unit
6325 -- in the context, there might still be a need for an
6326 -- Elaborate_All_Desirable from the current compilation
6327 -- to the named unit, so we keep the check enabled.
6329 if In_Extended_Main_Source_Unit (N) then
6330 Set_Suppress_Elaboration_Warnings
6331 (Entity (Name (Citem)));
6342 ("argument of pragma% is not with'ed unit", Arg);
6348 -- Give a warning if operating in static mode with -gnatwl
6349 -- (elaboration warnings enabled) switch set.
6351 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6353 ("?use of pragma Elaborate may not be safe", N);
6355 ("?use pragma Elaborate_All instead if possible", N);
6363 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6365 when Pragma_Elaborate_All => Elaborate_All : declare
6370 Check_Ada_83_Warning;
6372 -- Pragma must be in context items list of a compilation unit
6374 if not Is_In_Context_Clause then
6378 -- Must be at least one argument
6380 if Arg_Count = 0 then
6381 Error_Pragma ("pragma% requires at least one argument");
6384 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6385 -- have to appear at the end of the context clause, but may
6386 -- appear mixed in with other items, even in Ada 83 mode.
6388 -- Final check: the arguments must all be units mentioned in
6389 -- a with clause in the same context clause. Note that we
6390 -- already checked (in Par.Prag) that all the arguments are
6391 -- either identifiers or selected components.
6394 Outr : while Present (Arg) loop
6395 Citem := First (List_Containing (N));
6396 Innr : while Citem /= N loop
6397 if Nkind (Citem) = N_With_Clause
6398 and then Same_Name (Name (Citem), Expression (Arg))
6400 Set_Elaborate_All_Present (Citem, True);
6401 Set_Unit_Name (Expression (Arg), Name (Citem));
6403 -- Suppress warnings and elaboration checks on the named
6404 -- unit if the pragma is in the current compilation, as
6405 -- for pragma Elaborate.
6407 if In_Extended_Main_Source_Unit (N) then
6408 Set_Suppress_Elaboration_Warnings
6409 (Entity (Name (Citem)));
6418 Set_Error_Posted (N);
6420 ("argument of pragma% is not with'ed unit", Arg);
6427 --------------------
6428 -- Elaborate_Body --
6429 --------------------
6431 -- pragma Elaborate_Body [( library_unit_NAME )];
6433 when Pragma_Elaborate_Body => Elaborate_Body : declare
6434 Cunit_Node : Node_Id;
6435 Cunit_Ent : Entity_Id;
6438 Check_Ada_83_Warning;
6439 Check_Valid_Library_Unit_Pragma;
6441 if Nkind (N) = N_Null_Statement then
6445 Cunit_Node := Cunit (Current_Sem_Unit);
6446 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6448 if Nkind (Unit (Cunit_Node)) = N_Package_Body
6450 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
6452 Error_Pragma ("pragma% must refer to a spec, not a body");
6454 Set_Body_Required (Cunit_Node, True);
6455 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6457 -- If we are in dynamic elaboration mode, then we suppress
6458 -- elaboration warnings for the unit, since it is definitely
6459 -- fine NOT to do dynamic checks at the first level (and such
6460 -- checks will be suppressed because no elaboration boolean
6461 -- is created for Elaborate_Body packages).
6463 -- But in the static model of elaboration, Elaborate_Body is
6464 -- definitely NOT good enough to ensure elaboration safety on
6465 -- its own, since the body may WITH other units that are not
6466 -- safe from an elaboration point of view, so a client must
6467 -- still do an Elaborate_All on such units.
6469 -- Debug flag -gnatdD restores the old behavior of 3.13,
6470 -- where Elaborate_Body always suppressed elab warnings.
6472 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6473 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6478 ------------------------
6479 -- Elaboration_Checks --
6480 ------------------------
6482 -- pragma Elaboration_Checks (Static | Dynamic);
6484 when Pragma_Elaboration_Checks =>
6486 Check_Arg_Count (1);
6487 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6488 Dynamic_Elaboration_Checks :=
6489 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6495 -- pragma Eliminate (
6496 -- [Unit_Name =>] IDENTIFIER |
6497 -- SELECTED_COMPONENT
6498 -- [,[Entity =>] IDENTIFIER |
6499 -- SELECTED_COMPONENT |
6501 -- [,]OVERLOADING_RESOLUTION);
6503 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6506 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6509 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6511 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6512 -- Result_Type => result_SUBTYPE_NAME]
6514 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6515 -- SUBTYPE_NAME ::= STRING_LITERAL
6517 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6518 -- SOURCE_TRACE ::= STRING_LITERAL
6520 when Pragma_Eliminate => Eliminate : declare
6521 Args : Args_List (1 .. 5);
6522 Names : constant Name_List (1 .. 5) := (
6525 Name_Parameter_Types,
6527 Name_Source_Location);
6529 Unit_Name : Node_Id renames Args (1);
6530 Entity : Node_Id renames Args (2);
6531 Parameter_Types : Node_Id renames Args (3);
6532 Result_Type : Node_Id renames Args (4);
6533 Source_Location : Node_Id renames Args (5);
6537 Check_Valid_Configuration_Pragma;
6538 Gather_Associations (Names, Args);
6540 if No (Unit_Name) then
6541 Error_Pragma ("missing Unit_Name argument for pragma%");
6545 and then (Present (Parameter_Types)
6547 Present (Result_Type)
6549 Present (Source_Location))
6551 Error_Pragma ("missing Entity argument for pragma%");
6554 if (Present (Parameter_Types)
6556 Present (Result_Type))
6558 Present (Source_Location)
6561 ("parameter profile and source location cannot " &
6562 "be used together in pragma%");
6565 Process_Eliminate_Pragma
6579 -- [ Convention =>] convention_IDENTIFIER,
6580 -- [ Entity =>] local_NAME
6581 -- [, [External_Name =>] static_string_EXPRESSION ]
6582 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6584 when Pragma_Export => Export : declare
6588 pragma Warnings (Off, C);
6591 Check_Ada_83_Warning;
6597 Check_At_Least_N_Arguments (2);
6598 Check_At_Most_N_Arguments (4);
6599 Process_Convention (C, Def_Id);
6601 if Ekind (Def_Id) /= E_Constant then
6602 Note_Possible_Modification (Expression (Arg2), Sure => False);
6605 Process_Interface_Name (Def_Id, Arg3, Arg4);
6606 Set_Exported (Def_Id, Arg2);
6608 -- If the entity is a deferred constant, propagate the
6609 -- information to the full view, because gigi elaborates
6610 -- the full view only.
6612 if Ekind (Def_Id) = E_Constant
6613 and then Present (Full_View (Def_Id))
6616 Id2 : constant Entity_Id := Full_View (Def_Id);
6618 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6619 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6620 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6625 ----------------------
6626 -- Export_Exception --
6627 ----------------------
6629 -- pragma Export_Exception (
6630 -- [Internal =>] LOCAL_NAME
6631 -- [, [External =>] EXTERNAL_SYMBOL]
6632 -- [, [Form =>] Ada | VMS]
6633 -- [, [Code =>] static_integer_EXPRESSION]);
6635 when Pragma_Export_Exception => Export_Exception : declare
6636 Args : Args_List (1 .. 4);
6637 Names : constant Name_List (1 .. 4) := (
6643 Internal : Node_Id renames Args (1);
6644 External : Node_Id renames Args (2);
6645 Form : Node_Id renames Args (3);
6646 Code : Node_Id renames Args (4);
6649 if Inside_A_Generic then
6650 Error_Pragma ("pragma% cannot be used for generic entities");
6653 Gather_Associations (Names, Args);
6654 Process_Extended_Import_Export_Exception_Pragma (
6655 Arg_Internal => Internal,
6656 Arg_External => External,
6660 if not Is_VMS_Exception (Entity (Internal)) then
6661 Set_Exported (Entity (Internal), Internal);
6663 end Export_Exception;
6665 ---------------------
6666 -- Export_Function --
6667 ---------------------
6669 -- pragma Export_Function (
6670 -- [Internal =>] LOCAL_NAME
6671 -- [, [External =>] EXTERNAL_SYMBOL]
6672 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6673 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6674 -- [, [Mechanism =>] MECHANISM]
6675 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6677 -- EXTERNAL_SYMBOL ::=
6679 -- | static_string_EXPRESSION
6681 -- PARAMETER_TYPES ::=
6683 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6685 -- TYPE_DESIGNATOR ::=
6687 -- | subtype_Name ' Access
6691 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6693 -- MECHANISM_ASSOCIATION ::=
6694 -- [formal_parameter_NAME =>] MECHANISM_NAME
6696 -- MECHANISM_NAME ::=
6699 -- | Descriptor [([Class =>] CLASS_NAME)]
6701 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6703 when Pragma_Export_Function => Export_Function : declare
6704 Args : Args_List (1 .. 6);
6705 Names : constant Name_List (1 .. 6) := (
6708 Name_Parameter_Types,
6711 Name_Result_Mechanism);
6713 Internal : Node_Id renames Args (1);
6714 External : Node_Id renames Args (2);
6715 Parameter_Types : Node_Id renames Args (3);
6716 Result_Type : Node_Id renames Args (4);
6717 Mechanism : Node_Id renames Args (5);
6718 Result_Mechanism : Node_Id renames Args (6);
6722 Gather_Associations (Names, Args);
6723 Process_Extended_Import_Export_Subprogram_Pragma (
6724 Arg_Internal => Internal,
6725 Arg_External => External,
6726 Arg_Parameter_Types => Parameter_Types,
6727 Arg_Result_Type => Result_Type,
6728 Arg_Mechanism => Mechanism,
6729 Arg_Result_Mechanism => Result_Mechanism);
6730 end Export_Function;
6736 -- pragma Export_Object (
6737 -- [Internal =>] LOCAL_NAME
6738 -- [, [External =>] EXTERNAL_SYMBOL]
6739 -- [, [Size =>] EXTERNAL_SYMBOL]);
6741 -- EXTERNAL_SYMBOL ::=
6743 -- | static_string_EXPRESSION
6745 -- PARAMETER_TYPES ::=
6747 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6749 -- TYPE_DESIGNATOR ::=
6751 -- | subtype_Name ' Access
6755 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6757 -- MECHANISM_ASSOCIATION ::=
6758 -- [formal_parameter_NAME =>] MECHANISM_NAME
6760 -- MECHANISM_NAME ::=
6763 -- | Descriptor [([Class =>] CLASS_NAME)]
6765 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6767 when Pragma_Export_Object => Export_Object : declare
6768 Args : Args_List (1 .. 3);
6769 Names : constant Name_List (1 .. 3) := (
6774 Internal : Node_Id renames Args (1);
6775 External : Node_Id renames Args (2);
6776 Size : Node_Id renames Args (3);
6780 Gather_Associations (Names, Args);
6781 Process_Extended_Import_Export_Object_Pragma (
6782 Arg_Internal => Internal,
6783 Arg_External => External,
6787 ----------------------
6788 -- Export_Procedure --
6789 ----------------------
6791 -- pragma Export_Procedure (
6792 -- [Internal =>] LOCAL_NAME
6793 -- [, [External =>] EXTERNAL_SYMBOL]
6794 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6795 -- [, [Mechanism =>] MECHANISM]);
6797 -- EXTERNAL_SYMBOL ::=
6799 -- | static_string_EXPRESSION
6801 -- PARAMETER_TYPES ::=
6803 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6805 -- TYPE_DESIGNATOR ::=
6807 -- | subtype_Name ' Access
6811 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6813 -- MECHANISM_ASSOCIATION ::=
6814 -- [formal_parameter_NAME =>] MECHANISM_NAME
6816 -- MECHANISM_NAME ::=
6819 -- | Descriptor [([Class =>] CLASS_NAME)]
6821 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6823 when Pragma_Export_Procedure => Export_Procedure : declare
6824 Args : Args_List (1 .. 4);
6825 Names : constant Name_List (1 .. 4) := (
6828 Name_Parameter_Types,
6831 Internal : Node_Id renames Args (1);
6832 External : Node_Id renames Args (2);
6833 Parameter_Types : Node_Id renames Args (3);
6834 Mechanism : Node_Id renames Args (4);
6838 Gather_Associations (Names, Args);
6839 Process_Extended_Import_Export_Subprogram_Pragma (
6840 Arg_Internal => Internal,
6841 Arg_External => External,
6842 Arg_Parameter_Types => Parameter_Types,
6843 Arg_Mechanism => Mechanism);
6844 end Export_Procedure;
6850 -- pragma Export_Value (
6851 -- [Value =>] static_integer_EXPRESSION,
6852 -- [Link_Name =>] static_string_EXPRESSION);
6854 when Pragma_Export_Value =>
6856 Check_Arg_Order ((Name_Value, Name_Link_Name));
6857 Check_Arg_Count (2);
6859 Check_Optional_Identifier (Arg1, Name_Value);
6860 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6862 Check_Optional_Identifier (Arg2, Name_Link_Name);
6863 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6865 -----------------------------
6866 -- Export_Valued_Procedure --
6867 -----------------------------
6869 -- pragma Export_Valued_Procedure (
6870 -- [Internal =>] LOCAL_NAME
6871 -- [, [External =>] EXTERNAL_SYMBOL,]
6872 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6873 -- [, [Mechanism =>] MECHANISM]);
6875 -- EXTERNAL_SYMBOL ::=
6877 -- | static_string_EXPRESSION
6879 -- PARAMETER_TYPES ::=
6881 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6883 -- TYPE_DESIGNATOR ::=
6885 -- | subtype_Name ' Access
6889 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6891 -- MECHANISM_ASSOCIATION ::=
6892 -- [formal_parameter_NAME =>] MECHANISM_NAME
6894 -- MECHANISM_NAME ::=
6897 -- | Descriptor [([Class =>] CLASS_NAME)]
6899 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6901 when Pragma_Export_Valued_Procedure =>
6902 Export_Valued_Procedure : declare
6903 Args : Args_List (1 .. 4);
6904 Names : constant Name_List (1 .. 4) := (
6907 Name_Parameter_Types,
6910 Internal : Node_Id renames Args (1);
6911 External : Node_Id renames Args (2);
6912 Parameter_Types : Node_Id renames Args (3);
6913 Mechanism : Node_Id renames Args (4);
6917 Gather_Associations (Names, Args);
6918 Process_Extended_Import_Export_Subprogram_Pragma (
6919 Arg_Internal => Internal,
6920 Arg_External => External,
6921 Arg_Parameter_Types => Parameter_Types,
6922 Arg_Mechanism => Mechanism);
6923 end Export_Valued_Procedure;
6929 -- pragma Extend_System ([Name =>] Identifier);
6931 when Pragma_Extend_System => Extend_System : declare
6934 Check_Valid_Configuration_Pragma;
6935 Check_Arg_Count (1);
6936 Check_Optional_Identifier (Arg1, Name_Name);
6937 Check_Arg_Is_Identifier (Arg1);
6939 Get_Name_String (Chars (Expression (Arg1)));
6942 and then Name_Buffer (1 .. 4) = "aux_"
6944 if Present (System_Extend_Pragma_Arg) then
6945 if Chars (Expression (Arg1)) =
6946 Chars (Expression (System_Extend_Pragma_Arg))
6950 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
6951 Error_Pragma ("pragma% conflicts with that #");
6955 System_Extend_Pragma_Arg := Arg1;
6957 if not GNAT_Mode then
6958 System_Extend_Unit := Arg1;
6962 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
6966 ------------------------
6967 -- Extensions_Allowed --
6968 ------------------------
6970 -- pragma Extensions_Allowed (ON | OFF);
6972 when Pragma_Extensions_Allowed =>
6974 Check_Arg_Count (1);
6975 Check_No_Identifiers;
6976 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6978 if Chars (Expression (Arg1)) = Name_On then
6979 Extensions_Allowed := True;
6981 Extensions_Allowed := False;
6988 -- pragma External (
6989 -- [ Convention =>] convention_IDENTIFIER,
6990 -- [ Entity =>] local_NAME
6991 -- [, [External_Name =>] static_string_EXPRESSION ]
6992 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6994 when Pragma_External => External : declare
6998 pragma Warnings (Off, C);
7007 Check_At_Least_N_Arguments (2);
7008 Check_At_Most_N_Arguments (4);
7009 Process_Convention (C, Def_Id);
7010 Note_Possible_Modification (Expression (Arg2), Sure => False);
7011 Process_Interface_Name (Def_Id, Arg3, Arg4);
7012 Set_Exported (Def_Id, Arg2);
7015 --------------------------
7016 -- External_Name_Casing --
7017 --------------------------
7019 -- pragma External_Name_Casing (
7020 -- UPPERCASE | LOWERCASE
7021 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7023 when Pragma_External_Name_Casing => External_Name_Casing : declare
7026 Check_No_Identifiers;
7028 if Arg_Count = 2 then
7030 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7032 case Chars (Get_Pragma_Arg (Arg2)) is
7034 Opt.External_Name_Exp_Casing := As_Is;
7036 when Name_Uppercase =>
7037 Opt.External_Name_Exp_Casing := Uppercase;
7039 when Name_Lowercase =>
7040 Opt.External_Name_Exp_Casing := Lowercase;
7047 Check_Arg_Count (1);
7050 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7052 case Chars (Get_Pragma_Arg (Arg1)) is
7053 when Name_Uppercase =>
7054 Opt.External_Name_Imp_Casing := Uppercase;
7056 when Name_Lowercase =>
7057 Opt.External_Name_Imp_Casing := Lowercase;
7062 end External_Name_Casing;
7064 --------------------------
7065 -- Favor_Top_Level --
7066 --------------------------
7068 -- pragma Favor_Top_Level (type_NAME);
7070 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7071 Named_Entity : Entity_Id;
7075 Check_No_Identifiers;
7076 Check_Arg_Count (1);
7077 Check_Arg_Is_Local_Name (Arg1);
7078 Named_Entity := Entity (Expression (Arg1));
7080 -- If it's an access-to-subprogram type (in particular, not a
7081 -- subtype), set the flag on that type.
7083 if Is_Access_Subprogram_Type (Named_Entity) then
7084 Set_Can_Use_Internal_Rep (Named_Entity, False);
7086 -- Otherwise it's an error (name denotes the wrong sort of entity)
7090 ("access-to-subprogram type expected", Expression (Arg1));
7092 end Favor_Top_Level;
7098 -- pragma Fast_Math;
7100 when Pragma_Fast_Math =>
7102 Check_No_Identifiers;
7103 Check_Valid_Configuration_Pragma;
7106 ---------------------------
7107 -- Finalize_Storage_Only --
7108 ---------------------------
7110 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7112 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7113 Assoc : constant Node_Id := Arg1;
7114 Type_Id : constant Node_Id := Expression (Assoc);
7118 Check_No_Identifiers;
7119 Check_Arg_Count (1);
7120 Check_Arg_Is_Local_Name (Arg1);
7122 Find_Type (Type_Id);
7123 Typ := Entity (Type_Id);
7126 or else Rep_Item_Too_Early (Typ, N)
7130 Typ := Underlying_Type (Typ);
7133 if not Is_Controlled (Typ) then
7134 Error_Pragma ("pragma% must specify controlled type");
7137 Check_First_Subtype (Arg1);
7139 if Finalize_Storage_Only (Typ) then
7140 Error_Pragma ("duplicate pragma%, only one allowed");
7142 elsif not Rep_Item_Too_Late (Typ, N) then
7143 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7145 end Finalize_Storage;
7147 --------------------------
7148 -- Float_Representation --
7149 --------------------------
7151 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7153 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7155 when Pragma_Float_Representation => Float_Representation : declare
7163 if Arg_Count = 1 then
7164 Check_Valid_Configuration_Pragma;
7166 Check_Arg_Count (2);
7167 Check_Optional_Identifier (Arg2, Name_Entity);
7168 Check_Arg_Is_Local_Name (Arg2);
7171 Check_No_Identifier (Arg1);
7172 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7174 if not OpenVMS_On_Target then
7175 if Chars (Expression (Arg1)) = Name_VAX_Float then
7177 ("?pragma% ignored (applies only to Open'V'M'S)");
7183 -- One argument case
7185 if Arg_Count = 1 then
7186 if Chars (Expression (Arg1)) = Name_VAX_Float then
7187 if Opt.Float_Format = 'I' then
7188 Error_Pragma ("'I'E'E'E format previously specified");
7191 Opt.Float_Format := 'V';
7194 if Opt.Float_Format = 'V' then
7195 Error_Pragma ("'V'A'X format previously specified");
7198 Opt.Float_Format := 'I';
7201 Set_Standard_Fpt_Formats;
7203 -- Two argument case
7206 Argx := Get_Pragma_Arg (Arg2);
7208 if not Is_Entity_Name (Argx)
7209 or else not Is_Floating_Point_Type (Entity (Argx))
7212 ("second argument of% pragma must be floating-point type",
7216 Ent := Entity (Argx);
7217 Digs := UI_To_Int (Digits_Value (Ent));
7219 -- Two arguments, VAX_Float case
7221 if Chars (Expression (Arg1)) = Name_VAX_Float then
7223 when 6 => Set_F_Float (Ent);
7224 when 9 => Set_D_Float (Ent);
7225 when 15 => Set_G_Float (Ent);
7229 ("wrong digits value, must be 6,9 or 15", Arg2);
7232 -- Two arguments, IEEE_Float case
7236 when 6 => Set_IEEE_Short (Ent);
7237 when 15 => Set_IEEE_Long (Ent);
7241 ("wrong digits value, must be 6 or 15", Arg2);
7245 end Float_Representation;
7251 -- pragma Ident (static_string_EXPRESSION)
7253 -- Note: pragma Comment shares this processing. Pragma Comment
7254 -- is identical to Ident, except that the restriction of the
7255 -- argument to 31 characters and the placement restrictions
7256 -- are not enforced for pragma Comment.
7258 when Pragma_Ident | Pragma_Comment => Ident : declare
7263 Check_Arg_Count (1);
7264 Check_No_Identifiers;
7265 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7267 -- For pragma Ident, preserve DEC compatibility by requiring
7268 -- the pragma to appear in a declarative part or package spec.
7270 if Prag_Id = Pragma_Ident then
7271 Check_Is_In_Decl_Part_Or_Package_Spec;
7274 Str := Expr_Value_S (Expression (Arg1));
7281 GP := Parent (Parent (N));
7283 if Nkind (GP) = N_Package_Declaration
7285 Nkind (GP) = N_Generic_Package_Declaration
7290 -- If we have a compilation unit, then record the ident
7291 -- value, checking for improper duplication.
7293 if Nkind (GP) = N_Compilation_Unit then
7294 CS := Ident_String (Current_Sem_Unit);
7296 if Present (CS) then
7298 -- For Ident, we do not permit multiple instances
7300 if Prag_Id = Pragma_Ident then
7301 Error_Pragma ("duplicate% pragma not permitted");
7303 -- For Comment, we concatenate the string, unless we
7304 -- want to preserve the tree structure for ASIS.
7306 elsif not ASIS_Mode then
7307 Start_String (Strval (CS));
7308 Store_String_Char (' ');
7309 Store_String_Chars (Strval (Str));
7310 Set_Strval (CS, End_String);
7314 -- In VMS, the effect of IDENT is achieved by passing
7315 -- IDENTIFICATION=name as a --for-linker switch.
7317 if OpenVMS_On_Target then
7320 ("--for-linker=IDENTIFICATION=");
7321 String_To_Name_Buffer (Strval (Str));
7322 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7324 -- Only the last processed IDENT is saved. The main
7325 -- purpose is so an IDENT associated with a main
7326 -- procedure will be used in preference to an IDENT
7327 -- associated with a with'd package.
7329 Replace_Linker_Option_String
7330 (End_String, "--for-linker=IDENTIFICATION=");
7333 Set_Ident_String (Current_Sem_Unit, Str);
7336 -- For subunits, we just ignore the Ident, since in GNAT
7337 -- these are not separate object files, and hence not
7338 -- separate units in the unit table.
7340 elsif Nkind (GP) = N_Subunit then
7343 -- Otherwise we have a misplaced pragma Ident, but we ignore
7344 -- this if we are in an instantiation, since it comes from
7345 -- a generic, and has no relevance to the instantiation.
7347 elsif Prag_Id = Pragma_Ident then
7348 if Instantiation_Location (Loc) = No_Location then
7349 Error_Pragma ("pragma% only allowed at outer level");
7355 --------------------------
7356 -- Implemented_By_Entry --
7357 --------------------------
7359 -- pragma Implemented_By_Entry (DIRECT_NAME);
7361 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7366 Check_Arg_Count (1);
7367 Check_No_Identifiers;
7368 Check_Arg_Is_Identifier (Arg1);
7369 Check_Arg_Is_Local_Name (Arg1);
7370 Ent := Entity (Expression (Arg1));
7372 -- Pragma Implemented_By_Entry must be applied only to protected
7373 -- synchronized or task interface primitives.
7375 if (Ekind (Ent) /= E_Function
7376 and then Ekind (Ent) /= E_Procedure)
7377 or else not Present (First_Formal (Ent))
7378 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7381 ("pragma % must be applied to a concurrent interface " &
7385 if Einfo.Implemented_By_Entry (Ent)
7386 and then Warn_On_Redundant_Constructs
7388 Error_Pragma ("?duplicate pragma%!");
7390 Set_Implemented_By_Entry (Ent);
7393 end Implemented_By_Entry;
7395 -----------------------
7396 -- Implicit_Packing --
7397 -----------------------
7399 -- pragma Implicit_Packing;
7401 when Pragma_Implicit_Packing =>
7403 Check_Arg_Count (0);
7404 Implicit_Packing := True;
7411 -- [Convention =>] convention_IDENTIFIER,
7412 -- [Entity =>] local_NAME
7413 -- [, [External_Name =>] static_string_EXPRESSION ]
7414 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7416 when Pragma_Import =>
7417 Check_Ada_83_Warning;
7423 Check_At_Least_N_Arguments (2);
7424 Check_At_Most_N_Arguments (4);
7425 Process_Import_Or_Interface;
7427 ----------------------
7428 -- Import_Exception --
7429 ----------------------
7431 -- pragma Import_Exception (
7432 -- [Internal =>] LOCAL_NAME
7433 -- [, [External =>] EXTERNAL_SYMBOL]
7434 -- [, [Form =>] Ada | VMS]
7435 -- [, [Code =>] static_integer_EXPRESSION]);
7437 when Pragma_Import_Exception => Import_Exception : declare
7438 Args : Args_List (1 .. 4);
7439 Names : constant Name_List (1 .. 4) := (
7445 Internal : Node_Id renames Args (1);
7446 External : Node_Id renames Args (2);
7447 Form : Node_Id renames Args (3);
7448 Code : Node_Id renames Args (4);
7451 Gather_Associations (Names, Args);
7453 if Present (External) and then Present (Code) then
7455 ("cannot give both External and Code options for pragma%");
7458 Process_Extended_Import_Export_Exception_Pragma (
7459 Arg_Internal => Internal,
7460 Arg_External => External,
7464 if not Is_VMS_Exception (Entity (Internal)) then
7465 Set_Imported (Entity (Internal));
7467 end Import_Exception;
7469 ---------------------
7470 -- Import_Function --
7471 ---------------------
7473 -- pragma Import_Function (
7474 -- [Internal =>] LOCAL_NAME,
7475 -- [, [External =>] EXTERNAL_SYMBOL]
7476 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7477 -- [, [Result_Type =>] SUBTYPE_MARK]
7478 -- [, [Mechanism =>] MECHANISM]
7479 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7480 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7482 -- EXTERNAL_SYMBOL ::=
7484 -- | static_string_EXPRESSION
7486 -- PARAMETER_TYPES ::=
7488 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7490 -- TYPE_DESIGNATOR ::=
7492 -- | subtype_Name ' Access
7496 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7498 -- MECHANISM_ASSOCIATION ::=
7499 -- [formal_parameter_NAME =>] MECHANISM_NAME
7501 -- MECHANISM_NAME ::=
7504 -- | Descriptor [([Class =>] CLASS_NAME)]
7506 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7508 when Pragma_Import_Function => Import_Function : declare
7509 Args : Args_List (1 .. 7);
7510 Names : constant Name_List (1 .. 7) := (
7513 Name_Parameter_Types,
7516 Name_Result_Mechanism,
7517 Name_First_Optional_Parameter);
7519 Internal : Node_Id renames Args (1);
7520 External : Node_Id renames Args (2);
7521 Parameter_Types : Node_Id renames Args (3);
7522 Result_Type : Node_Id renames Args (4);
7523 Mechanism : Node_Id renames Args (5);
7524 Result_Mechanism : Node_Id renames Args (6);
7525 First_Optional_Parameter : Node_Id renames Args (7);
7529 Gather_Associations (Names, Args);
7530 Process_Extended_Import_Export_Subprogram_Pragma (
7531 Arg_Internal => Internal,
7532 Arg_External => External,
7533 Arg_Parameter_Types => Parameter_Types,
7534 Arg_Result_Type => Result_Type,
7535 Arg_Mechanism => Mechanism,
7536 Arg_Result_Mechanism => Result_Mechanism,
7537 Arg_First_Optional_Parameter => First_Optional_Parameter);
7538 end Import_Function;
7544 -- pragma Import_Object (
7545 -- [Internal =>] LOCAL_NAME
7546 -- [, [External =>] EXTERNAL_SYMBOL]
7547 -- [, [Size =>] EXTERNAL_SYMBOL]);
7549 -- EXTERNAL_SYMBOL ::=
7551 -- | static_string_EXPRESSION
7553 when Pragma_Import_Object => Import_Object : declare
7554 Args : Args_List (1 .. 3);
7555 Names : constant Name_List (1 .. 3) := (
7560 Internal : Node_Id renames Args (1);
7561 External : Node_Id renames Args (2);
7562 Size : Node_Id renames Args (3);
7566 Gather_Associations (Names, Args);
7567 Process_Extended_Import_Export_Object_Pragma (
7568 Arg_Internal => Internal,
7569 Arg_External => External,
7573 ----------------------
7574 -- Import_Procedure --
7575 ----------------------
7577 -- pragma Import_Procedure (
7578 -- [Internal =>] LOCAL_NAME
7579 -- [, [External =>] EXTERNAL_SYMBOL]
7580 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7581 -- [, [Mechanism =>] MECHANISM]
7582 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7584 -- EXTERNAL_SYMBOL ::=
7586 -- | static_string_EXPRESSION
7588 -- PARAMETER_TYPES ::=
7590 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7592 -- TYPE_DESIGNATOR ::=
7594 -- | subtype_Name ' Access
7598 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7600 -- MECHANISM_ASSOCIATION ::=
7601 -- [formal_parameter_NAME =>] MECHANISM_NAME
7603 -- MECHANISM_NAME ::=
7606 -- | Descriptor [([Class =>] CLASS_NAME)]
7608 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7610 when Pragma_Import_Procedure => Import_Procedure : declare
7611 Args : Args_List (1 .. 5);
7612 Names : constant Name_List (1 .. 5) := (
7615 Name_Parameter_Types,
7617 Name_First_Optional_Parameter);
7619 Internal : Node_Id renames Args (1);
7620 External : Node_Id renames Args (2);
7621 Parameter_Types : Node_Id renames Args (3);
7622 Mechanism : Node_Id renames Args (4);
7623 First_Optional_Parameter : Node_Id renames Args (5);
7627 Gather_Associations (Names, Args);
7628 Process_Extended_Import_Export_Subprogram_Pragma (
7629 Arg_Internal => Internal,
7630 Arg_External => External,
7631 Arg_Parameter_Types => Parameter_Types,
7632 Arg_Mechanism => Mechanism,
7633 Arg_First_Optional_Parameter => First_Optional_Parameter);
7634 end Import_Procedure;
7636 -----------------------------
7637 -- Import_Valued_Procedure --
7638 -----------------------------
7640 -- pragma Import_Valued_Procedure (
7641 -- [Internal =>] LOCAL_NAME
7642 -- [, [External =>] EXTERNAL_SYMBOL]
7643 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7644 -- [, [Mechanism =>] MECHANISM]
7645 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7647 -- EXTERNAL_SYMBOL ::=
7649 -- | static_string_EXPRESSION
7651 -- PARAMETER_TYPES ::=
7653 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7655 -- TYPE_DESIGNATOR ::=
7657 -- | subtype_Name ' Access
7661 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7663 -- MECHANISM_ASSOCIATION ::=
7664 -- [formal_parameter_NAME =>] MECHANISM_NAME
7666 -- MECHANISM_NAME ::=
7669 -- | Descriptor [([Class =>] CLASS_NAME)]
7671 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7673 when Pragma_Import_Valued_Procedure =>
7674 Import_Valued_Procedure : declare
7675 Args : Args_List (1 .. 5);
7676 Names : constant Name_List (1 .. 5) := (
7679 Name_Parameter_Types,
7681 Name_First_Optional_Parameter);
7683 Internal : Node_Id renames Args (1);
7684 External : Node_Id renames Args (2);
7685 Parameter_Types : Node_Id renames Args (3);
7686 Mechanism : Node_Id renames Args (4);
7687 First_Optional_Parameter : Node_Id renames Args (5);
7691 Gather_Associations (Names, Args);
7692 Process_Extended_Import_Export_Subprogram_Pragma (
7693 Arg_Internal => Internal,
7694 Arg_External => External,
7695 Arg_Parameter_Types => Parameter_Types,
7696 Arg_Mechanism => Mechanism,
7697 Arg_First_Optional_Parameter => First_Optional_Parameter);
7698 end Import_Valued_Procedure;
7700 ------------------------
7701 -- Initialize_Scalars --
7702 ------------------------
7704 -- pragma Initialize_Scalars;
7706 when Pragma_Initialize_Scalars =>
7708 Check_Arg_Count (0);
7709 Check_Valid_Configuration_Pragma;
7710 Check_Restriction (No_Initialize_Scalars, N);
7712 if not Restriction_Active (No_Initialize_Scalars) then
7713 Init_Or_Norm_Scalars := True;
7714 Initialize_Scalars := True;
7721 -- pragma Inline ( NAME {, NAME} );
7723 when Pragma_Inline =>
7725 -- Pragma is active if inlining option is active
7727 Process_Inline (Inline_Active);
7733 -- pragma Inline_Always ( NAME {, NAME} );
7735 when Pragma_Inline_Always =>
7736 Process_Inline (True);
7738 --------------------
7739 -- Inline_Generic --
7740 --------------------
7742 -- pragma Inline_Generic (NAME {, NAME});
7744 when Pragma_Inline_Generic =>
7745 Process_Generic_List;
7747 ----------------------
7748 -- Inspection_Point --
7749 ----------------------
7751 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7753 when Pragma_Inspection_Point => Inspection_Point : declare
7758 if Arg_Count > 0 then
7761 Exp := Expression (Arg);
7764 if not Is_Entity_Name (Exp)
7765 or else not Is_Object (Entity (Exp))
7767 Error_Pragma_Arg ("object name required", Arg);
7774 end Inspection_Point;
7780 -- pragma Interface (
7781 -- [ Convention =>] convention_IDENTIFIER,
7782 -- [ Entity =>] local_NAME
7783 -- [, [External_Name =>] static_string_EXPRESSION ]
7784 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7786 when Pragma_Interface =>
7793 Check_At_Least_N_Arguments (2);
7794 Check_At_Most_N_Arguments (4);
7795 Process_Import_Or_Interface;
7797 --------------------
7798 -- Interface_Name --
7799 --------------------
7801 -- pragma Interface_Name (
7802 -- [ Entity =>] local_NAME
7803 -- [,[External_Name =>] static_string_EXPRESSION ]
7804 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7806 when Pragma_Interface_Name => Interface_Name : declare
7815 ((Name_Entity, Name_External_Name, Name_Link_Name));
7816 Check_At_Least_N_Arguments (2);
7817 Check_At_Most_N_Arguments (3);
7818 Id := Expression (Arg1);
7821 if not Is_Entity_Name (Id) then
7823 ("first argument for pragma% must be entity name", Arg1);
7824 elsif Etype (Id) = Any_Type then
7827 Def_Id := Entity (Id);
7830 -- Special DEC-compatible processing for the object case, forces
7831 -- object to be imported.
7833 if Ekind (Def_Id) = E_Variable then
7834 Kill_Size_Check_Code (Def_Id);
7835 Note_Possible_Modification (Id, Sure => False);
7837 -- Initialization is not allowed for imported variable
7839 if Present (Expression (Parent (Def_Id)))
7840 and then Comes_From_Source (Expression (Parent (Def_Id)))
7842 Error_Msg_Sloc := Sloc (Def_Id);
7844 ("no initialization allowed for declaration of& #",
7848 -- For compatibility, support VADS usage of providing both
7849 -- pragmas Interface and Interface_Name to obtain the effect
7850 -- of a single Import pragma.
7852 if Is_Imported (Def_Id)
7853 and then Present (First_Rep_Item (Def_Id))
7854 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7856 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
7860 Set_Imported (Def_Id);
7863 Set_Is_Public (Def_Id);
7864 Process_Interface_Name (Def_Id, Arg2, Arg3);
7867 -- Otherwise must be subprogram
7869 elsif not Is_Subprogram (Def_Id) then
7871 ("argument of pragma% is not subprogram", Arg1);
7874 Check_At_Most_N_Arguments (3);
7878 -- Loop through homonyms
7881 Def_Id := Get_Base_Subprogram (Hom_Id);
7883 if Is_Imported (Def_Id) then
7884 Process_Interface_Name (Def_Id, Arg2, Arg3);
7888 Hom_Id := Homonym (Hom_Id);
7890 exit when No (Hom_Id)
7891 or else Scope (Hom_Id) /= Current_Scope;
7896 ("argument of pragma% is not imported subprogram",
7902 -----------------------
7903 -- Interrupt_Handler --
7904 -----------------------
7906 -- pragma Interrupt_Handler (handler_NAME);
7908 when Pragma_Interrupt_Handler =>
7909 Check_Ada_83_Warning;
7910 Check_Arg_Count (1);
7911 Check_No_Identifiers;
7913 if No_Run_Time_Mode then
7914 Error_Msg_CRT ("Interrupt_Handler pragma", N);
7916 Check_Interrupt_Or_Attach_Handler;
7917 Process_Interrupt_Or_Attach_Handler;
7920 ------------------------
7921 -- Interrupt_Priority --
7922 ------------------------
7924 -- pragma Interrupt_Priority [(EXPRESSION)];
7926 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
7927 P : constant Node_Id := Parent (N);
7931 Check_Ada_83_Warning;
7933 if Arg_Count /= 0 then
7934 Arg := Expression (Arg1);
7935 Check_Arg_Count (1);
7936 Check_No_Identifiers;
7938 -- The expression must be analyzed in the special manner
7939 -- described in "Handling of Default and Per-Object
7940 -- Expressions" in sem.ads.
7942 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
7945 if Nkind (P) /= N_Task_Definition
7946 and then Nkind (P) /= N_Protected_Definition
7951 elsif Has_Priority_Pragma (P) then
7952 Error_Pragma ("duplicate pragma% not allowed");
7955 Set_Has_Priority_Pragma (P, True);
7956 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7958 end Interrupt_Priority;
7960 ---------------------
7961 -- Interrupt_State --
7962 ---------------------
7964 -- pragma Interrupt_State (
7965 -- [Name =>] INTERRUPT_ID,
7966 -- [State =>] INTERRUPT_STATE);
7968 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
7969 -- INTERRUPT_STATE => System | Runtime | User
7971 -- Note: if the interrupt id is given as an identifier, then
7972 -- it must be one of the identifiers in Ada.Interrupts.Names.
7973 -- Otherwise it is given as a static integer expression which
7974 -- must be in the range of Ada.Interrupts.Interrupt_ID.
7976 when Pragma_Interrupt_State => Interrupt_State : declare
7978 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
7979 -- This is the entity Ada.Interrupts.Interrupt_ID;
7981 State_Type : Character;
7982 -- Set to 's'/'r'/'u' for System/Runtime/User
7985 -- Index to entry in Interrupt_States table
7988 -- Value of interrupt
7990 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
7991 -- The first argument to the pragma
7993 Int_Ent : Entity_Id;
7994 -- Interrupt entity in Ada.Interrupts.Names
7998 Check_Arg_Order ((Name_Name, Name_State));
7999 Check_Arg_Count (2);
8001 Check_Optional_Identifier (Arg1, Name_Name);
8002 Check_Optional_Identifier (Arg2, Name_State);
8003 Check_Arg_Is_Identifier (Arg2);
8005 -- First argument is identifier
8007 if Nkind (Arg1X) = N_Identifier then
8009 -- Search list of names in Ada.Interrupts.Names
8011 Int_Ent := First_Entity (RTE (RE_Names));
8013 if No (Int_Ent) then
8014 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8016 elsif Chars (Int_Ent) = Chars (Arg1X) then
8017 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8021 Next_Entity (Int_Ent);
8024 -- First argument is not an identifier, so it must be a
8025 -- static expression of type Ada.Interrupts.Interrupt_ID.
8028 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8029 Int_Val := Expr_Value (Arg1X);
8031 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8033 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8036 ("value not in range of type " &
8037 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8043 case Chars (Get_Pragma_Arg (Arg2)) is
8044 when Name_Runtime => State_Type := 'r';
8045 when Name_System => State_Type := 's';
8046 when Name_User => State_Type := 'u';
8049 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8052 -- Check if entry is already stored
8054 IST_Num := Interrupt_States.First;
8056 -- If entry not found, add it
8058 if IST_Num > Interrupt_States.Last then
8059 Interrupt_States.Append
8060 ((Interrupt_Number => UI_To_Int (Int_Val),
8061 Interrupt_State => State_Type,
8062 Pragma_Loc => Loc));
8065 -- Case of entry for the same entry
8067 elsif Int_Val = Interrupt_States.Table (IST_Num).
8070 -- If state matches, done, no need to make redundant entry
8073 State_Type = Interrupt_States.Table (IST_Num).
8076 -- Otherwise if state does not match, error
8079 Interrupt_States.Table (IST_Num).Pragma_Loc;
8081 ("state conflicts with that given #", Arg2);
8085 IST_Num := IST_Num + 1;
8087 end Interrupt_State;
8089 ----------------------
8090 -- Java_Constructor --
8091 ----------------------
8093 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8095 -- Also handles pragma CIL_Constructor
8097 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8098 Java_Constructor : declare
8102 Convention : Convention_Id;
8106 Check_Arg_Count (1);
8107 Check_Optional_Identifier (Arg1, Name_Entity);
8108 Check_Arg_Is_Local_Name (Arg1);
8110 Id := Expression (Arg1);
8111 Find_Program_Unit_Name (Id);
8113 -- If we did not find the name, we are done
8115 if Etype (Id) = Any_Type then
8120 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8121 when Pragma_Java_Constructor => Convention := Convention_Java;
8122 when others => null;
8125 Hom_Id := Entity (Id);
8127 -- Loop through homonyms
8130 Def_Id := Get_Base_Subprogram (Hom_Id);
8132 -- The constructor is required to be a function returning an
8133 -- access type whose designated type has convention Java/CIL.
8135 if Ekind (Def_Id) = E_Function
8137 (Is_Value_Type (Etype (Def_Id))
8139 (Ekind (Etype (Def_Id)) in Access_Kind
8142 (Designated_Type (Etype (Def_Id))) = Convention
8145 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8148 Set_Is_Constructor (Def_Id);
8149 Set_Convention (Def_Id, Convention);
8150 Set_Is_Imported (Def_Id);
8153 if Convention = Convention_Java then
8155 ("pragma% requires function returning a " &
8156 "'Java access type", Arg1);
8158 pragma Assert (Convention = Convention_CIL);
8160 ("pragma% requires function returning a " &
8161 "'CIL access type", Arg1);
8165 Hom_Id := Homonym (Hom_Id);
8167 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8169 end Java_Constructor;
8171 ----------------------
8172 -- Java_Interface --
8173 ----------------------
8175 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8177 when Pragma_Java_Interface => Java_Interface : declare
8183 Check_Arg_Count (1);
8184 Check_Optional_Identifier (Arg1, Name_Entity);
8185 Check_Arg_Is_Local_Name (Arg1);
8187 Arg := Expression (Arg1);
8190 if Etype (Arg) = Any_Type then
8194 if not Is_Entity_Name (Arg)
8195 or else not Is_Type (Entity (Arg))
8197 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8200 Typ := Underlying_Type (Entity (Arg));
8202 -- For now we simply check some of the semantic constraints
8203 -- on the type. This currently leaves out some restrictions
8204 -- on interface types, namely that the parent type must be
8205 -- java.lang.Object.Typ and that all primitives of the type
8206 -- should be declared abstract. ???
8208 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8209 Error_Pragma_Arg ("pragma% requires an abstract "
8210 & "tagged type", Arg1);
8212 elsif not Has_Discriminants (Typ)
8213 or else Ekind (Etype (First_Discriminant (Typ)))
8214 /= E_Anonymous_Access_Type
8216 not Is_Class_Wide_Type
8217 (Designated_Type (Etype (First_Discriminant (Typ))))
8220 ("type must have a class-wide access discriminant", Arg1);
8228 -- pragma Keep_Names ([On => ] local_NAME);
8230 when Pragma_Keep_Names => Keep_Names : declare
8235 Check_Arg_Count (1);
8236 Check_Optional_Identifier (Arg1, Name_On);
8237 Check_Arg_Is_Local_Name (Arg1);
8239 Arg := Expression (Arg1);
8242 if Etype (Arg) = Any_Type then
8246 if not Is_Entity_Name (Arg)
8247 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8250 ("pragma% requires a local enumeration type", Arg1);
8253 Set_Discard_Names (Entity (Arg), False);
8260 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8262 when Pragma_License =>
8264 Check_Arg_Count (1);
8265 Check_No_Identifiers;
8266 Check_Valid_Configuration_Pragma;
8267 Check_Arg_Is_Identifier (Arg1);
8270 Sind : constant Source_File_Index :=
8271 Source_Index (Current_Sem_Unit);
8274 case Chars (Get_Pragma_Arg (Arg1)) is
8276 Set_License (Sind, GPL);
8278 when Name_Modified_GPL =>
8279 Set_License (Sind, Modified_GPL);
8281 when Name_Restricted =>
8282 Set_License (Sind, Restricted);
8284 when Name_Unrestricted =>
8285 Set_License (Sind, Unrestricted);
8288 Error_Pragma_Arg ("invalid license name", Arg1);
8296 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8298 when Pragma_Link_With => Link_With : declare
8304 if Operating_Mode = Generate_Code
8305 and then In_Extended_Main_Source_Unit (N)
8307 Check_At_Least_N_Arguments (1);
8308 Check_No_Identifiers;
8309 Check_Is_In_Decl_Part_Or_Package_Spec;
8310 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8314 while Present (Arg) loop
8315 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8317 -- Store argument, converting sequences of spaces
8318 -- to a single null character (this is one of the
8319 -- differences in processing between Link_With
8320 -- and Linker_Options).
8323 C : constant Char_Code := Get_Char_Code (' ');
8324 S : constant String_Id :=
8325 Strval (Expr_Value_S (Expression (Arg)));
8326 L : constant Nat := String_Length (S);
8329 procedure Skip_Spaces;
8330 -- Advance F past any spaces
8336 procedure Skip_Spaces is
8338 while F <= L and then Get_String_Char (S, F) = C loop
8343 -- Start of processing for Arg_Store
8346 Skip_Spaces; -- skip leading spaces
8348 -- Loop through characters, changing any embedded
8349 -- sequence of spaces to a single null character
8350 -- (this is how Link_With/Linker_Options differ)
8353 if Get_String_Char (S, F) = C then
8356 Store_String_Char (ASCII.NUL);
8359 Store_String_Char (Get_String_Char (S, F));
8367 if Present (Arg) then
8368 Store_String_Char (ASCII.NUL);
8372 Store_Linker_Option_String (End_String);
8380 -- pragma Linker_Alias (
8381 -- [Entity =>] LOCAL_NAME
8382 -- [Target =>] static_string_EXPRESSION);
8384 when Pragma_Linker_Alias =>
8386 Check_Arg_Order ((Name_Entity, Name_Target));
8387 Check_Arg_Count (2);
8388 Check_Optional_Identifier (Arg1, Name_Entity);
8389 Check_Optional_Identifier (Arg2, Name_Target);
8390 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8391 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8393 -- The only processing required is to link this item on to the
8394 -- list of rep items for the given entity. This is accomplished
8395 -- by the call to Rep_Item_Too_Late (when no error is detected
8396 -- and False is returned).
8398 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8401 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8404 ------------------------
8405 -- Linker_Constructor --
8406 ------------------------
8408 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8410 -- Code is shared with Linker_Destructor
8412 -----------------------
8413 -- Linker_Destructor --
8414 -----------------------
8416 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8418 when Pragma_Linker_Constructor |
8419 Pragma_Linker_Destructor =>
8420 Linker_Constructor : declare
8426 Check_Arg_Count (1);
8427 Check_No_Identifiers;
8428 Check_Arg_Is_Local_Name (Arg1);
8429 Arg1_X := Expression (Arg1);
8431 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8433 if not Is_Library_Level_Entity (Proc) then
8435 ("argument for pragma% must be library level entity", Arg1);
8438 -- The only processing required is to link this item on to the
8439 -- list of rep items for the given entity. This is accomplished
8440 -- by the call to Rep_Item_Too_Late (when no error is detected
8441 -- and False is returned).
8443 if Rep_Item_Too_Late (Proc, N) then
8446 Set_Has_Gigi_Rep_Item (Proc);
8448 end Linker_Constructor;
8450 --------------------
8451 -- Linker_Options --
8452 --------------------
8454 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8456 when Pragma_Linker_Options => Linker_Options : declare
8460 Check_Ada_83_Warning;
8461 Check_No_Identifiers;
8462 Check_Arg_Count (1);
8463 Check_Is_In_Decl_Part_Or_Package_Spec;
8464 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8465 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8468 while Present (Arg) loop
8469 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8470 Store_String_Char (ASCII.NUL);
8471 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8475 if Operating_Mode = Generate_Code
8476 and then In_Extended_Main_Source_Unit (N)
8478 Store_Linker_Option_String (End_String);
8482 --------------------
8483 -- Linker_Section --
8484 --------------------
8486 -- pragma Linker_Section (
8487 -- [Entity =>] LOCAL_NAME
8488 -- [Section =>] static_string_EXPRESSION);
8490 when Pragma_Linker_Section =>
8492 Check_Arg_Order ((Name_Entity, Name_Section));
8493 Check_Arg_Count (2);
8494 Check_Optional_Identifier (Arg1, Name_Entity);
8495 Check_Optional_Identifier (Arg2, Name_Section);
8496 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8497 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8499 -- This pragma applies only to objects
8501 if not Is_Object (Entity (Expression (Arg1))) then
8502 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8505 -- The only processing required is to link this item on to the
8506 -- list of rep items for the given entity. This is accomplished
8507 -- by the call to Rep_Item_Too_Late (when no error is detected
8508 -- and False is returned).
8510 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8513 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8520 -- pragma List (On | Off)
8522 -- There is nothing to do here, since we did all the processing
8523 -- for this pragma in Par.Prag (so that it works properly even in
8524 -- syntax only mode)
8529 --------------------
8530 -- Locking_Policy --
8531 --------------------
8533 -- pragma Locking_Policy (policy_IDENTIFIER);
8535 when Pragma_Locking_Policy => declare
8539 Check_Ada_83_Warning;
8540 Check_Arg_Count (1);
8541 Check_No_Identifiers;
8542 Check_Arg_Is_Locking_Policy (Arg1);
8543 Check_Valid_Configuration_Pragma;
8544 Get_Name_String (Chars (Expression (Arg1)));
8545 LP := Fold_Upper (Name_Buffer (1));
8547 if Locking_Policy /= ' '
8548 and then Locking_Policy /= LP
8550 Error_Msg_Sloc := Locking_Policy_Sloc;
8551 Error_Pragma ("locking policy incompatible with policy#");
8553 -- Set new policy, but always preserve System_Location since
8554 -- we like the error message with the run time name.
8557 Locking_Policy := LP;
8559 if Locking_Policy_Sloc /= System_Location then
8560 Locking_Policy_Sloc := Loc;
8569 -- pragma Long_Float (D_Float | G_Float);
8571 when Pragma_Long_Float =>
8573 Check_Valid_Configuration_Pragma;
8574 Check_Arg_Count (1);
8575 Check_No_Identifier (Arg1);
8576 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8578 if not OpenVMS_On_Target then
8579 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8584 if Chars (Expression (Arg1)) = Name_D_Float then
8585 if Opt.Float_Format_Long = 'G' then
8586 Error_Pragma ("G_Float previously specified");
8589 Opt.Float_Format_Long := 'D';
8591 -- G_Float case (this is the default, does not need overriding)
8594 if Opt.Float_Format_Long = 'D' then
8595 Error_Pragma ("D_Float previously specified");
8598 Opt.Float_Format_Long := 'G';
8601 Set_Standard_Fpt_Formats;
8603 -----------------------
8604 -- Machine_Attribute --
8605 -----------------------
8607 -- pragma Machine_Attribute (
8608 -- [Entity =>] LOCAL_NAME,
8609 -- [Attribute_Name =>] static_string_EXPRESSION
8610 -- [, [Info =>] static_string_EXPRESSION] );
8612 when Pragma_Machine_Attribute => Machine_Attribute : declare
8617 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8619 if Arg_Count = 3 then
8620 Check_Optional_Identifier (Arg3, Name_Info);
8621 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
8623 Check_Arg_Count (2);
8626 Check_Optional_Identifier (Arg1, Name_Entity);
8627 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8628 Check_Arg_Is_Local_Name (Arg1);
8629 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8630 Def_Id := Entity (Expression (Arg1));
8632 if Is_Access_Type (Def_Id) then
8633 Def_Id := Designated_Type (Def_Id);
8636 if Rep_Item_Too_Early (Def_Id, N) then
8640 Def_Id := Underlying_Type (Def_Id);
8642 -- The only processing required is to link this item on to the
8643 -- list of rep items for the given entity. This is accomplished
8644 -- by the call to Rep_Item_Too_Late (when no error is detected
8645 -- and False is returned).
8647 if Rep_Item_Too_Late (Def_Id, N) then
8650 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8652 end Machine_Attribute;
8659 -- (MAIN_OPTION [, MAIN_OPTION]);
8662 -- [STACK_SIZE =>] static_integer_EXPRESSION
8663 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8664 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8666 when Pragma_Main => Main : declare
8667 Args : Args_List (1 .. 3);
8668 Names : constant Name_List (1 .. 3) := (
8670 Name_Task_Stack_Size_Default,
8671 Name_Time_Slicing_Enabled);
8677 Gather_Associations (Names, Args);
8679 for J in 1 .. 2 loop
8680 if Present (Args (J)) then
8681 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8685 if Present (Args (3)) then
8686 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8690 while Present (Nod) loop
8691 if Nkind (Nod) = N_Pragma
8692 and then Pragma_Name (Nod) = Name_Main
8694 Error_Msg_Name_1 := Pname;
8695 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8706 -- pragma Main_Storage
8707 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8709 -- MAIN_STORAGE_OPTION ::=
8710 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8711 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8713 when Pragma_Main_Storage => Main_Storage : declare
8714 Args : Args_List (1 .. 2);
8715 Names : constant Name_List (1 .. 2) := (
8716 Name_Working_Storage,
8723 Gather_Associations (Names, Args);
8725 for J in 1 .. 2 loop
8726 if Present (Args (J)) then
8727 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8731 Check_In_Main_Program;
8734 while Present (Nod) loop
8735 if Nkind (Nod) = N_Pragma
8736 and then Pragma_Name (Nod) = Name_Main_Storage
8738 Error_Msg_Name_1 := Pname;
8739 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8750 -- pragma Memory_Size (NUMERIC_LITERAL)
8752 when Pragma_Memory_Size =>
8755 -- Memory size is simply ignored
8757 Check_No_Identifiers;
8758 Check_Arg_Count (1);
8759 Check_Arg_Is_Integer_Literal (Arg1);
8767 -- The only correct use of this pragma is on its own in a file, in
8768 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
8769 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
8770 -- check for a file containing nothing but a No_Body pragma). If we
8771 -- attempt to process it during normal semantics processing, it means
8772 -- it was misplaced.
8774 when Pragma_No_Body =>
8781 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8783 when Pragma_No_Return => No_Return : declare
8791 Check_At_Least_N_Arguments (1);
8793 -- Loop through arguments of pragma
8796 while Present (Arg) loop
8797 Check_Arg_Is_Local_Name (Arg);
8798 Id := Expression (Arg);
8801 if not Is_Entity_Name (Id) then
8802 Error_Pragma_Arg ("entity name required", Arg);
8805 if Etype (Id) = Any_Type then
8809 -- Loop to find matching procedures
8814 and then Scope (E) = Current_Scope
8816 if Ekind (E) = E_Procedure
8817 or else Ekind (E) = E_Generic_Procedure
8821 -- Set flag on any alias as well
8823 if Is_Overloadable (E) and then Present (Alias (E)) then
8824 Set_No_Return (Alias (E));
8834 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
8841 ------------------------
8842 -- No_Strict_Aliasing --
8843 ------------------------
8845 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
8847 when Pragma_No_Strict_Aliasing => No_Strict_Alias : declare
8852 Check_At_Most_N_Arguments (1);
8854 if Arg_Count = 0 then
8855 Check_Valid_Configuration_Pragma;
8856 Opt.No_Strict_Aliasing := True;
8859 Check_Optional_Identifier (Arg2, Name_Entity);
8860 Check_Arg_Is_Local_Name (Arg1);
8861 E_Id := Entity (Expression (Arg1));
8863 if E_Id = Any_Type then
8865 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
8866 Error_Pragma_Arg ("pragma% requires access type", Arg1);
8869 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
8871 end No_Strict_Alias;
8877 -- pragma Obsolescent [(
8878 -- [Entity => NAME,]
8879 -- [(static_string_EXPRESSION [, Ada_05])];
8881 when Pragma_Obsolescent => Obsolescent : declare
8885 procedure Set_Obsolescent (E : Entity_Id);
8886 -- Given an entity Ent, mark it as obsolescent if appropriate
8888 ---------------------
8889 -- Set_Obsolescent --
8890 ---------------------
8892 procedure Set_Obsolescent (E : Entity_Id) is
8901 -- Entity name was given
8903 if Present (Ename) then
8905 -- If entity name matches, we are fine
8907 if Chars (Ename) = Chars (Ent) then
8910 -- If entity name does not match, only possibility is an
8911 -- enumeration literal from an enumeration type declaration.
8913 elsif Ekind (Ent) /= E_Enumeration_Type then
8915 ("pragma % entity name does not match declaration");
8918 Ent := First_Literal (E);
8922 ("pragma % entity name does not match any " &
8923 "enumeration literal");
8925 elsif Chars (Ent) = Chars (Ename) then
8929 Ent := Next_Literal (Ent);
8935 -- Ent points to entity to be marked
8937 if Arg_Count >= 1 then
8939 -- Deal with static string argument
8941 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8942 S := Strval (Expression (Arg1));
8944 for J in 1 .. String_Length (S) loop
8945 if not In_Character_Range (Get_String_Char (S, J)) then
8947 ("pragma% argument does not allow wide characters",
8952 Obsolescent_Warnings.Append
8953 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
8955 -- Check for Ada_05 parameter
8957 if Arg_Count /= 1 then
8958 Check_Arg_Count (2);
8961 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
8964 Check_Arg_Is_Identifier (Argx);
8966 if Chars (Argx) /= Name_Ada_05 then
8967 Error_Msg_Name_2 := Name_Ada_05;
8969 ("only allowed argument for pragma% is %", Argx);
8972 if Ada_Version_Explicit < Ada_05
8973 or else not Warn_On_Ada_2005_Compatibility
8981 -- Set flag if pragma active
8984 Set_Is_Obsolescent (Ent);
8988 end Set_Obsolescent;
8990 -- Start of processing for pragma Obsolescent
8995 Check_At_Most_N_Arguments (3);
8997 -- See if first argument specifies an entity name
9000 and then Chars (Arg1) = Name_Entity
9002 Ename := Get_Pragma_Arg (Arg1);
9004 if Nkind (Ename) /= N_Character_Literal
9006 Nkind (Ename) /= N_Identifier
9008 Nkind (Ename) /= N_Operator_Symbol
9010 Error_Pragma_Arg ("entity name expected for pragma%", Arg1);
9013 -- Eliminate first argument, so we can share processing
9017 Arg_Count := Arg_Count - 1;
9019 -- No Entity name argument given
9025 Check_No_Identifiers;
9027 -- Get immediately preceding declaration
9030 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9034 -- Cases where we do not follow anything other than another pragma
9038 -- First case: library level compilation unit declaration with
9039 -- the pragma immediately following the declaration.
9041 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9043 (Defining_Entity (Unit (Parent (Parent (N)))));
9046 -- Case 2: library unit placement for package
9050 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9052 if Ekind (Ent) = E_Package
9053 or else Ekind (Ent) = E_Generic_Package
9055 Set_Obsolescent (Ent);
9061 -- Cases where we must follow a declaration
9064 if Nkind (Decl) not in N_Declaration
9065 and then Nkind (Decl) not in N_Later_Decl_Item
9066 and then Nkind (Decl) not in N_Generic_Declaration
9069 ("pragma% misplaced, " &
9070 "must immediately follow a declaration");
9073 Set_Obsolescent (Defining_Entity (Decl));
9083 -- pragma No_Run_Time
9085 -- Note: this pragma is retained for backwards compatibility.
9086 -- See body of Rtsfind for full details on its handling.
9088 when Pragma_No_Run_Time =>
9090 Check_Valid_Configuration_Pragma;
9091 Check_Arg_Count (0);
9093 No_Run_Time_Mode := True;
9094 Configurable_Run_Time_Mode := True;
9096 -- Set Duration to 32 bits if word size is 32
9098 if Ttypes.System_Word_Size = 32 then
9099 Duration_32_Bits_On_Target := True;
9102 -- Set appropriate restrictions
9104 Set_Restriction (No_Finalization, N);
9105 Set_Restriction (No_Exception_Handlers, N);
9106 Set_Restriction (Max_Tasks, N, 0);
9107 Set_Restriction (No_Tasking, N);
9109 -----------------------
9110 -- Normalize_Scalars --
9111 -----------------------
9113 -- pragma Normalize_Scalars;
9115 when Pragma_Normalize_Scalars =>
9116 Check_Ada_83_Warning;
9117 Check_Arg_Count (0);
9118 Check_Valid_Configuration_Pragma;
9119 Normalize_Scalars := True;
9120 Init_Or_Norm_Scalars := True;
9126 -- pragma Optimize (Time | Space | Off);
9128 -- The actual check for optimize is done in Gigi. Note that this
9129 -- pragma does not actually change the optimization setting, it
9130 -- simply checks that it is consistent with the pragma.
9132 when Pragma_Optimize =>
9133 Check_No_Identifiers;
9134 Check_Arg_Count (1);
9135 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9137 ------------------------
9138 -- Optimize_Alignment --
9139 ------------------------
9141 -- pragma Optimize_Alignment (Time | Space | Off);
9143 when Pragma_Optimize_Alignment =>
9145 Check_No_Identifiers;
9146 Check_Arg_Count (1);
9147 Check_Valid_Configuration_Pragma;
9150 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9154 Opt.Optimize_Alignment := 'T';
9156 Opt.Optimize_Alignment := 'S';
9158 Opt.Optimize_Alignment := 'O';
9160 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9164 -- Set indication that mode is set locally. If we are in fact in a
9165 -- configuration pragma file, this setting is harmless since the
9166 -- switch will get reset anyway at the start of each unit.
9168 Optimize_Alignment_Local := True;
9174 -- pragma Pack (first_subtype_LOCAL_NAME);
9176 when Pragma_Pack => Pack : declare
9177 Assoc : constant Node_Id := Arg1;
9182 Check_No_Identifiers;
9183 Check_Arg_Count (1);
9184 Check_Arg_Is_Local_Name (Arg1);
9186 Type_Id := Expression (Assoc);
9187 Find_Type (Type_Id);
9188 Typ := Entity (Type_Id);
9191 or else Rep_Item_Too_Early (Typ, N)
9195 Typ := Underlying_Type (Typ);
9198 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9199 Error_Pragma ("pragma% must specify array or record type");
9202 Check_First_Subtype (Arg1);
9204 if Has_Pragma_Pack (Typ) then
9205 Error_Pragma ("duplicate pragma%, only one allowed");
9209 elsif Is_Array_Type (Typ) then
9211 -- Pack not allowed for aliased or atomic components
9213 if Has_Aliased_Components (Base_Type (Typ)) then
9215 ("pragma% ignored, cannot pack aliased components?");
9217 elsif Has_Atomic_Components (Typ)
9218 or else Is_Atomic (Component_Type (Typ))
9221 ("?pragma% ignored, cannot pack atomic components");
9224 -- If we had an explicit component size given, then we do not
9225 -- let Pack override this given size. We also give a warning
9226 -- that Pack is being ignored unless we can tell for sure that
9227 -- the Pack would not have had any effect anyway.
9229 if Has_Component_Size_Clause (Typ) then
9230 if Known_Static_RM_Size (Component_Type (Typ))
9232 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9237 ("?pragma% ignored, explicit component size given");
9240 -- If no prior array component size given, Pack is effective
9243 if not Rep_Item_Too_Late (Typ, N) then
9244 if VM_Target = No_VM then
9245 Set_Is_Packed (Base_Type (Typ));
9246 elsif not GNAT_Mode then
9248 ("?pragma% ignored in this configuration");
9251 Set_Has_Pragma_Pack (Base_Type (Typ));
9252 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9256 -- For record types, the pack is always effective
9258 else pragma Assert (Is_Record_Type (Typ));
9259 if not Rep_Item_Too_Late (Typ, N) then
9260 if VM_Target = No_VM then
9261 Set_Is_Packed (Base_Type (Typ));
9262 elsif not GNAT_Mode then
9263 Error_Pragma ("?pragma% ignored in this configuration");
9266 Set_Has_Pragma_Pack (Base_Type (Typ));
9267 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9278 -- There is nothing to do here, since we did all the processing
9279 -- for this pragma in Par.Prag (so that it works properly even in
9280 -- syntax only mode)
9289 -- pragma Passive [(PASSIVE_FORM)];
9291 -- PASSIVE_FORM ::= Semaphore | No
9293 when Pragma_Passive =>
9296 if Nkind (Parent (N)) /= N_Task_Definition then
9297 Error_Pragma ("pragma% must be within task definition");
9300 if Arg_Count /= 0 then
9301 Check_Arg_Count (1);
9302 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9305 ----------------------------------
9306 -- Preelaborable_Initialization --
9307 ----------------------------------
9309 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9311 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9316 Check_Arg_Count (1);
9317 Check_No_Identifiers;
9318 Check_Arg_Is_Identifier (Arg1);
9319 Check_Arg_Is_Local_Name (Arg1);
9320 Check_First_Subtype (Arg1);
9321 Ent := Entity (Expression (Arg1));
9323 if not Is_Private_Type (Ent)
9324 and then not Is_Protected_Type (Ent)
9327 ("pragma % can only be applied to private or protected type",
9331 -- Give an error if the pragma is applied to a protected type that
9332 -- does not qualify (due to having entries, or due to components
9333 -- that do not qualify).
9335 if Is_Protected_Type (Ent)
9336 and then not Has_Preelaborable_Initialization (Ent)
9339 ("protected type & does not have preelaborable " &
9340 "initialization", Ent);
9342 -- Otherwise mark the type as definitely having preelaborable
9346 Set_Known_To_Have_Preelab_Init (Ent);
9349 if Has_Pragma_Preelab_Init (Ent)
9350 and then Warn_On_Redundant_Constructs
9352 Error_Pragma ("?duplicate pragma%!");
9354 Set_Has_Pragma_Preelab_Init (Ent);
9362 -- pragma Polling (ON | OFF);
9364 when Pragma_Polling =>
9366 Check_Arg_Count (1);
9367 Check_No_Identifiers;
9368 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9369 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9371 --------------------
9372 -- Persistent_BSS --
9373 --------------------
9375 when Pragma_Persistent_BSS => Persistent_BSS : declare
9382 Check_At_Most_N_Arguments (1);
9384 -- Case of application to specific object (one argument)
9386 if Arg_Count = 1 then
9387 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9389 if not Is_Entity_Name (Expression (Arg1))
9391 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9392 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9394 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9397 Ent := Entity (Expression (Arg1));
9398 Decl := Parent (Ent);
9400 if Rep_Item_Too_Late (Ent, N) then
9404 if Present (Expression (Decl)) then
9406 ("object for pragma% cannot have initialization", Arg1);
9409 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9411 ("object type for pragma% is not potentially persistent",
9416 Make_Linker_Section_Pragma
9417 (Ent, Sloc (N), ".persistent.bss");
9418 Insert_After (N, Prag);
9421 -- Case of use as configuration pragma with no arguments
9424 Check_Valid_Configuration_Pragma;
9425 Persistent_BSS_Mode := True;
9433 -- pragma Postcondition ([Check =>] Boolean_Expression
9434 -- [,[Message =>] String_Expression]);
9436 when Pragma_Postcondition => Postcondition : declare
9438 pragma Warnings (Off, In_Body);
9442 Check_At_Least_N_Arguments (1);
9443 Check_At_Most_N_Arguments (2);
9444 Check_Optional_Identifier (Arg1, Name_Check);
9446 -- All we need to do here is call the common check procedure,
9447 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9449 Check_Precondition_Postcondition (In_Body);
9456 -- pragma Precondition ([Check =>] Boolean_Expression
9457 -- [,[Message =>] String_Expression]);
9459 when Pragma_Precondition => Precondition : declare
9464 Check_At_Least_N_Arguments (1);
9465 Check_At_Most_N_Arguments (2);
9466 Check_Optional_Identifier (Arg1, Name_Check);
9468 Check_Precondition_Postcondition (In_Body);
9470 -- If in spec, nothing to do. If in body, then we convert the
9471 -- pragma to pragma Check (Precondition, cond [, msg]). Note we
9472 -- do this whether or not precondition checks are enabled. That
9473 -- works fine since pragma Check will do this check.
9476 if Arg_Count = 2 then
9477 Check_Optional_Identifier (Arg3, Name_Message);
9478 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9481 Analyze_And_Resolve (Get_Pragma_Arg (Arg1), Standard_Boolean);
9485 Chars => Name_Check,
9486 Pragma_Argument_Associations => New_List (
9487 Make_Pragma_Argument_Association (Loc,
9489 Make_Identifier (Loc,
9490 Chars => Name_Precondition)),
9492 Make_Pragma_Argument_Association (Sloc (Arg1),
9493 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9495 if Arg_Count = 2 then
9496 Append_To (Pragma_Argument_Associations (N),
9497 Make_Pragma_Argument_Association (Sloc (Arg2),
9498 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9509 -- pragma Preelaborate [(library_unit_NAME)];
9511 -- Set the flag Is_Preelaborated of program unit name entity
9513 when Pragma_Preelaborate => Preelaborate : declare
9514 Pa : constant Node_Id := Parent (N);
9515 Pk : constant Node_Kind := Nkind (Pa);
9519 Check_Ada_83_Warning;
9520 Check_Valid_Library_Unit_Pragma;
9522 if Nkind (N) = N_Null_Statement then
9526 Ent := Find_Lib_Unit_Name;
9528 -- This filters out pragmas inside generic parent then
9529 -- show up inside instantiation
9532 and then not (Pk = N_Package_Specification
9533 and then Present (Generic_Parent (Pa)))
9535 if not Debug_Flag_U then
9536 Set_Is_Preelaborated (Ent);
9537 Set_Suppress_Elaboration_Warnings (Ent);
9542 ---------------------
9543 -- Preelaborate_05 --
9544 ---------------------
9546 -- pragma Preelaborate_05 [(library_unit_NAME)];
9548 -- This pragma is useable only in GNAT_Mode, where it is used like
9549 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9550 -- (otherwise it is ignored). This is used to implement AI-362 which
9551 -- recategorizes some run-time packages in Ada 2005 mode.
9553 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9558 Check_Valid_Library_Unit_Pragma;
9560 if not GNAT_Mode then
9561 Error_Pragma ("pragma% only available in GNAT mode");
9564 if Nkind (N) = N_Null_Statement then
9568 -- This is one of the few cases where we need to test the value of
9569 -- Ada_Version_Explicit rather than Ada_Version (which is always
9570 -- set to Ada_05 in a predefined unit), we need to know the
9571 -- explicit version set to know if this pragma is active.
9573 if Ada_Version_Explicit >= Ada_05 then
9574 Ent := Find_Lib_Unit_Name;
9575 Set_Is_Preelaborated (Ent);
9576 Set_Suppress_Elaboration_Warnings (Ent);
9578 end Preelaborate_05;
9584 -- pragma Priority (EXPRESSION);
9586 when Pragma_Priority => Priority : declare
9587 P : constant Node_Id := Parent (N);
9591 Check_No_Identifiers;
9592 Check_Arg_Count (1);
9596 if Nkind (P) = N_Subprogram_Body then
9597 Check_In_Main_Program;
9599 Arg := Expression (Arg1);
9600 Analyze_And_Resolve (Arg, Standard_Integer);
9604 if not Is_Static_Expression (Arg) then
9605 Flag_Non_Static_Expr
9606 ("main subprogram priority is not static!", Arg);
9609 -- If constraint error, then we already signalled an error
9611 elsif Raises_Constraint_Error (Arg) then
9614 -- Otherwise check in range
9618 Val : constant Uint := Expr_Value (Arg);
9622 or else Val > Expr_Value (Expression
9623 (Parent (RTE (RE_Max_Priority))))
9626 ("main subprogram priority is out of range", Arg1);
9632 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9634 -- Load an arbitrary entity from System.Tasking to make sure
9635 -- this package is implicitly with'ed, since we need to have
9636 -- the tasking run-time active for the pragma Priority to have
9640 Discard : Entity_Id;
9641 pragma Warnings (Off, Discard);
9643 Discard := RTE (RE_Task_List);
9646 -- Task or Protected, must be of type Integer
9648 elsif Nkind (P) = N_Protected_Definition
9650 Nkind (P) = N_Task_Definition
9652 Arg := Expression (Arg1);
9654 -- The expression must be analyzed in the special manner
9655 -- described in "Handling of Default and Per-Object
9656 -- Expressions" in sem.ads.
9658 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9660 if not Is_Static_Expression (Arg) then
9661 Check_Restriction (Static_Priorities, Arg);
9664 -- Anything else is incorrect
9670 if Has_Priority_Pragma (P) then
9671 Error_Pragma ("duplicate pragma% not allowed");
9673 Set_Has_Priority_Pragma (P, True);
9675 if Nkind (P) = N_Protected_Definition
9677 Nkind (P) = N_Task_Definition
9679 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9680 -- exp_ch9 should use this ???
9685 -----------------------------------
9686 -- Priority_Specific_Dispatching --
9687 -----------------------------------
9689 -- pragma Priority_Specific_Dispatching (
9690 -- policy_IDENTIFIER,
9691 -- first_priority_EXPRESSION,
9692 -- last_priority_EXPRESSION);
9694 when Pragma_Priority_Specific_Dispatching =>
9695 Priority_Specific_Dispatching : declare
9696 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9697 -- This is the entity System.Any_Priority;
9700 Lower_Bound : Node_Id;
9701 Upper_Bound : Node_Id;
9707 Check_Arg_Count (3);
9708 Check_No_Identifiers;
9709 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9710 Check_Valid_Configuration_Pragma;
9711 Get_Name_String (Chars (Expression (Arg1)));
9712 DP := Fold_Upper (Name_Buffer (1));
9714 Lower_Bound := Expression (Arg2);
9715 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9716 Lower_Val := Expr_Value (Lower_Bound);
9718 Upper_Bound := Expression (Arg3);
9719 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
9720 Upper_Val := Expr_Value (Upper_Bound);
9722 -- It is not allowed to use Task_Dispatching_Policy and
9723 -- Priority_Specific_Dispatching in the same partition.
9725 if Task_Dispatching_Policy /= ' ' then
9726 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9728 ("pragma% incompatible with Task_Dispatching_Policy#");
9730 -- Check lower bound in range
9732 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9734 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
9737 ("first_priority is out of range", Arg2);
9739 -- Check upper bound in range
9741 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9743 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
9746 ("last_priority is out of range", Arg3);
9748 -- Check that the priority range is valid
9750 elsif Lower_Val > Upper_Val then
9752 ("last_priority_expression must be greater than" &
9753 " or equal to first_priority_expression");
9755 -- Store the new policy, but always preserve System_Location since
9756 -- we like the error message with the run-time name.
9759 -- Check overlapping in the priority ranges specified in other
9760 -- Priority_Specific_Dispatching pragmas within the same
9761 -- partition. We can only check those we know about!
9764 Specific_Dispatching.First .. Specific_Dispatching.Last
9766 if Specific_Dispatching.Table (J).First_Priority in
9767 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9768 or else Specific_Dispatching.Table (J).Last_Priority in
9769 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9772 Specific_Dispatching.Table (J).Pragma_Loc;
9774 ("priority range overlaps with "
9775 & "Priority_Specific_Dispatching#");
9779 -- The use of Priority_Specific_Dispatching is incompatible
9780 -- with Task_Dispatching_Policy.
9782 if Task_Dispatching_Policy /= ' ' then
9783 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9785 ("Priority_Specific_Dispatching incompatible "
9786 & "with Task_Dispatching_Policy#");
9789 -- The use of Priority_Specific_Dispatching forces ceiling
9792 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
9793 Error_Msg_Sloc := Locking_Policy_Sloc;
9795 ("Priority_Specific_Dispatching incompatible "
9796 & "with Locking_Policy#");
9798 -- Set the Ceiling_Locking policy, but preserve System_Location
9799 -- since we like the error message with the run time name.
9802 Locking_Policy := 'C';
9804 if Locking_Policy_Sloc /= System_Location then
9805 Locking_Policy_Sloc := Loc;
9809 -- Add entry in the table
9811 Specific_Dispatching.Append
9812 ((Dispatching_Policy => DP,
9813 First_Priority => UI_To_Int (Lower_Val),
9814 Last_Priority => UI_To_Int (Upper_Val),
9815 Pragma_Loc => Loc));
9817 end Priority_Specific_Dispatching;
9823 -- pragma Profile (profile_IDENTIFIER);
9825 -- profile_IDENTIFIER => Restricted | Ravenscar
9827 when Pragma_Profile =>
9829 Check_Arg_Count (1);
9830 Check_Valid_Configuration_Pragma;
9831 Check_No_Identifiers;
9834 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9836 if Chars (Argx) = Name_Ravenscar then
9837 Set_Ravenscar_Profile (N);
9838 elsif Chars (Argx) = Name_Restricted then
9839 Set_Profile_Restrictions
9840 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
9842 Error_Pragma_Arg ("& is not a valid profile", Argx);
9846 ----------------------
9847 -- Profile_Warnings --
9848 ----------------------
9850 -- pragma Profile_Warnings (profile_IDENTIFIER);
9852 -- profile_IDENTIFIER => Restricted | Ravenscar
9854 when Pragma_Profile_Warnings =>
9856 Check_Arg_Count (1);
9857 Check_Valid_Configuration_Pragma;
9858 Check_No_Identifiers;
9861 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9863 if Chars (Argx) = Name_Ravenscar then
9864 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
9865 elsif Chars (Argx) = Name_Restricted then
9866 Set_Profile_Restrictions (Restricted, N, Warn => True);
9868 Error_Pragma_Arg ("& is not a valid profile", Argx);
9872 --------------------------
9873 -- Propagate_Exceptions --
9874 --------------------------
9876 -- pragma Propagate_Exceptions;
9878 -- Note: this pragma is obsolete and has no effect
9880 when Pragma_Propagate_Exceptions =>
9882 Check_Arg_Count (0);
9884 if In_Extended_Main_Source_Unit (N) then
9885 Propagate_Exceptions := True;
9892 -- pragma Psect_Object (
9893 -- [Internal =>] LOCAL_NAME,
9894 -- [, [External =>] EXTERNAL_SYMBOL]
9895 -- [, [Size =>] EXTERNAL_SYMBOL]);
9897 when Pragma_Psect_Object | Pragma_Common_Object =>
9898 Psect_Object : declare
9899 Args : Args_List (1 .. 3);
9900 Names : constant Name_List (1 .. 3) := (
9905 Internal : Node_Id renames Args (1);
9906 External : Node_Id renames Args (2);
9907 Size : Node_Id renames Args (3);
9911 procedure Check_Too_Long (Arg : Node_Id);
9912 -- Posts message if the argument is an identifier with more
9913 -- than 31 characters, or a string literal with more than
9914 -- 31 characters, and we are operating under VMS
9916 --------------------
9917 -- Check_Too_Long --
9918 --------------------
9920 procedure Check_Too_Long (Arg : Node_Id) is
9921 X : constant Node_Id := Original_Node (Arg);
9924 if Nkind (X) /= N_String_Literal
9926 Nkind (X) /= N_Identifier
9929 ("inappropriate argument for pragma %", Arg);
9932 if OpenVMS_On_Target then
9933 if (Nkind (X) = N_String_Literal
9934 and then String_Length (Strval (X)) > 31)
9936 (Nkind (X) = N_Identifier
9937 and then Length_Of_Name (Chars (X)) > 31)
9940 ("argument for pragma % is longer than 31 characters",
9946 -- Start of processing for Common_Object/Psect_Object
9950 Gather_Associations (Names, Args);
9951 Process_Extended_Import_Export_Internal_Arg (Internal);
9953 Def_Id := Entity (Internal);
9955 if Ekind (Def_Id) /= E_Constant
9956 and then Ekind (Def_Id) /= E_Variable
9959 ("pragma% must designate an object", Internal);
9962 Check_Too_Long (Internal);
9964 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
9966 ("cannot use pragma% for imported/exported object",
9970 if Is_Concurrent_Type (Etype (Internal)) then
9972 ("cannot specify pragma % for task/protected object",
9976 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
9978 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
9980 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
9983 if Ekind (Def_Id) = E_Constant then
9985 ("cannot specify pragma % for a constant", Internal);
9988 if Is_Record_Type (Etype (Internal)) then
9994 Ent := First_Entity (Etype (Internal));
9995 while Present (Ent) loop
9996 Decl := Declaration_Node (Ent);
9998 if Ekind (Ent) = E_Component
9999 and then Nkind (Decl) = N_Component_Declaration
10000 and then Present (Expression (Decl))
10001 and then Warn_On_Export_Import
10004 ("?object for pragma % has defaults", Internal);
10014 if Present (Size) then
10015 Check_Too_Long (Size);
10018 if Present (External) then
10019 Check_Arg_Is_External_Name (External);
10020 Check_Too_Long (External);
10023 -- If all error tests pass, link pragma on to the rep item chain
10025 Record_Rep_Item (Def_Id, N);
10032 -- pragma Pure [(library_unit_NAME)];
10034 when Pragma_Pure => Pure : declare
10038 Check_Ada_83_Warning;
10039 Check_Valid_Library_Unit_Pragma;
10041 if Nkind (N) = N_Null_Statement then
10045 Ent := Find_Lib_Unit_Name;
10047 Set_Has_Pragma_Pure (Ent);
10048 Set_Suppress_Elaboration_Warnings (Ent);
10055 -- pragma Pure_05 [(library_unit_NAME)];
10057 -- This pragma is useable only in GNAT_Mode, where it is used like
10058 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10059 -- it is ignored). It may be used after a pragma Preelaborate, in
10060 -- which case it overrides the effect of the pragma Preelaborate.
10061 -- This is used to implement AI-362 which recategorizes some run-time
10062 -- packages in Ada 2005 mode.
10064 when Pragma_Pure_05 => Pure_05 : declare
10069 Check_Valid_Library_Unit_Pragma;
10071 if not GNAT_Mode then
10072 Error_Pragma ("pragma% only available in GNAT mode");
10074 if Nkind (N) = N_Null_Statement then
10078 -- This is one of the few cases where we need to test the value of
10079 -- Ada_Version_Explicit rather than Ada_Version (which is always
10080 -- set to Ada_05 in a predefined unit), we need to know the
10081 -- explicit version set to know if this pragma is active.
10083 if Ada_Version_Explicit >= Ada_05 then
10084 Ent := Find_Lib_Unit_Name;
10085 Set_Is_Preelaborated (Ent, False);
10087 Set_Suppress_Elaboration_Warnings (Ent);
10091 -------------------
10092 -- Pure_Function --
10093 -------------------
10095 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10097 when Pragma_Pure_Function => Pure_Function : declare
10100 Def_Id : Entity_Id;
10101 Effective : Boolean := False;
10105 Check_Arg_Count (1);
10106 Check_Optional_Identifier (Arg1, Name_Entity);
10107 Check_Arg_Is_Local_Name (Arg1);
10108 E_Id := Expression (Arg1);
10110 if Error_Posted (E_Id) then
10114 -- Loop through homonyms (overloadings) of referenced entity
10116 E := Entity (E_Id);
10118 if Present (E) then
10120 Def_Id := Get_Base_Subprogram (E);
10122 if Ekind (Def_Id) /= E_Function
10123 and then Ekind (Def_Id) /= E_Generic_Function
10124 and then Ekind (Def_Id) /= E_Operator
10127 ("pragma% requires a function name", Arg1);
10130 Set_Is_Pure (Def_Id);
10132 if not Has_Pragma_Pure_Function (Def_Id) then
10133 Set_Has_Pragma_Pure_Function (Def_Id);
10138 exit when No (E) or else Scope (E) /= Current_Scope;
10142 and then Warn_On_Redundant_Constructs
10144 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10150 --------------------
10151 -- Queuing_Policy --
10152 --------------------
10154 -- pragma Queuing_Policy (policy_IDENTIFIER);
10156 when Pragma_Queuing_Policy => declare
10160 Check_Ada_83_Warning;
10161 Check_Arg_Count (1);
10162 Check_No_Identifiers;
10163 Check_Arg_Is_Queuing_Policy (Arg1);
10164 Check_Valid_Configuration_Pragma;
10165 Get_Name_String (Chars (Expression (Arg1)));
10166 QP := Fold_Upper (Name_Buffer (1));
10168 if Queuing_Policy /= ' '
10169 and then Queuing_Policy /= QP
10171 Error_Msg_Sloc := Queuing_Policy_Sloc;
10172 Error_Pragma ("queuing policy incompatible with policy#");
10174 -- Set new policy, but always preserve System_Location since
10175 -- we like the error message with the run time name.
10178 Queuing_Policy := QP;
10180 if Queuing_Policy_Sloc /= System_Location then
10181 Queuing_Policy_Sloc := Loc;
10186 -----------------------
10187 -- Relative_Deadline --
10188 -----------------------
10190 -- pragma Relative_Deadline (time_span_EXPRESSION);
10192 when Pragma_Relative_Deadline => Relative_Deadline : declare
10193 P : constant Node_Id := Parent (N);
10198 Check_No_Identifiers;
10199 Check_Arg_Count (1);
10201 Arg := Expression (Arg1);
10203 -- The expression must be analyzed in the special manner described
10204 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10206 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10210 if Nkind (P) = N_Subprogram_Body then
10211 Check_In_Main_Program;
10215 elsif Nkind (P) = N_Task_Definition then
10218 -- Anything else is incorrect
10224 if Has_Relative_Deadline_Pragma (P) then
10225 Error_Pragma ("duplicate pragma% not allowed");
10227 Set_Has_Relative_Deadline_Pragma (P, True);
10229 if Nkind (P) = N_Task_Definition then
10230 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10233 end Relative_Deadline;
10235 ---------------------------
10236 -- Remote_Call_Interface --
10237 ---------------------------
10239 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10241 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10242 Cunit_Node : Node_Id;
10243 Cunit_Ent : Entity_Id;
10247 Check_Ada_83_Warning;
10248 Check_Valid_Library_Unit_Pragma;
10250 if Nkind (N) = N_Null_Statement then
10254 Cunit_Node := Cunit (Current_Sem_Unit);
10255 K := Nkind (Unit (Cunit_Node));
10256 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10258 if K = N_Package_Declaration
10259 or else K = N_Generic_Package_Declaration
10260 or else K = N_Subprogram_Declaration
10261 or else K = N_Generic_Subprogram_Declaration
10262 or else (K = N_Subprogram_Body
10263 and then Acts_As_Spec (Unit (Cunit_Node)))
10268 "pragma% must apply to package or subprogram declaration");
10271 Set_Is_Remote_Call_Interface (Cunit_Ent);
10272 end Remote_Call_Interface;
10278 -- pragma Remote_Types [(library_unit_NAME)];
10280 when Pragma_Remote_Types => Remote_Types : declare
10281 Cunit_Node : Node_Id;
10282 Cunit_Ent : Entity_Id;
10285 Check_Ada_83_Warning;
10286 Check_Valid_Library_Unit_Pragma;
10288 if Nkind (N) = N_Null_Statement then
10292 Cunit_Node := Cunit (Current_Sem_Unit);
10293 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10295 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
10297 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
10300 "pragma% can only apply to a package declaration");
10303 Set_Is_Remote_Types (Cunit_Ent);
10310 -- pragma Ravenscar;
10312 when Pragma_Ravenscar =>
10314 Check_Arg_Count (0);
10315 Check_Valid_Configuration_Pragma;
10316 Set_Ravenscar_Profile (N);
10318 if Warn_On_Obsolescent_Feature then
10320 ("pragma Ravenscar is an obsolescent feature?", N);
10322 ("|use pragma Profile (Ravenscar) instead", N);
10325 -------------------------
10326 -- Restricted_Run_Time --
10327 -------------------------
10329 -- pragma Restricted_Run_Time;
10331 when Pragma_Restricted_Run_Time =>
10333 Check_Arg_Count (0);
10334 Check_Valid_Configuration_Pragma;
10335 Set_Profile_Restrictions
10336 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10338 if Warn_On_Obsolescent_Feature then
10340 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10342 ("|use pragma Profile (Restricted) instead", N);
10349 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10352 -- restriction_IDENTIFIER
10353 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10355 when Pragma_Restrictions =>
10356 Process_Restrictions_Or_Restriction_Warnings
10357 (Warn => Treat_Restrictions_As_Warnings);
10359 --------------------------
10360 -- Restriction_Warnings --
10361 --------------------------
10363 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10366 -- restriction_IDENTIFIER
10367 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10369 when Pragma_Restriction_Warnings =>
10371 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10377 -- pragma Reviewable;
10379 when Pragma_Reviewable =>
10380 Check_Ada_83_Warning;
10381 Check_Arg_Count (0);
10384 -------------------
10385 -- Share_Generic --
10386 -------------------
10388 -- pragma Share_Generic (NAME {, NAME});
10390 when Pragma_Share_Generic =>
10392 Process_Generic_List;
10398 -- pragma Shared (LOCAL_NAME);
10400 when Pragma_Shared =>
10402 Process_Atomic_Shared_Volatile;
10404 --------------------
10405 -- Shared_Passive --
10406 --------------------
10408 -- pragma Shared_Passive [(library_unit_NAME)];
10410 -- Set the flag Is_Shared_Passive of program unit name entity
10412 when Pragma_Shared_Passive => Shared_Passive : declare
10413 Cunit_Node : Node_Id;
10414 Cunit_Ent : Entity_Id;
10417 Check_Ada_83_Warning;
10418 Check_Valid_Library_Unit_Pragma;
10420 if Nkind (N) = N_Null_Statement then
10424 Cunit_Node := Cunit (Current_Sem_Unit);
10425 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10427 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
10429 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
10432 "pragma% can only apply to a package declaration");
10435 Set_Is_Shared_Passive (Cunit_Ent);
10436 end Shared_Passive;
10438 ----------------------
10439 -- Source_File_Name --
10440 ----------------------
10442 -- There are five forms for this pragma:
10444 -- pragma Source_File_Name (
10445 -- [UNIT_NAME =>] unit_NAME,
10446 -- BODY_FILE_NAME => STRING_LITERAL
10447 -- [, [INDEX =>] INTEGER_LITERAL]);
10449 -- pragma Source_File_Name (
10450 -- [UNIT_NAME =>] unit_NAME,
10451 -- SPEC_FILE_NAME => STRING_LITERAL
10452 -- [, [INDEX =>] INTEGER_LITERAL]);
10454 -- pragma Source_File_Name (
10455 -- BODY_FILE_NAME => STRING_LITERAL
10456 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10457 -- [, CASING => CASING_SPEC]);
10459 -- pragma Source_File_Name (
10460 -- SPEC_FILE_NAME => STRING_LITERAL
10461 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10462 -- [, CASING => CASING_SPEC]);
10464 -- pragma Source_File_Name (
10465 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10466 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10467 -- [, CASING => CASING_SPEC]);
10469 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10471 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10472 -- Source_File_Name (SFN), however their usage is exclusive:
10473 -- SFN can only be used when no project file is used, while
10474 -- SFNP can only be used when a project file is used.
10476 -- No processing here. Processing was completed during parsing,
10477 -- since we need to have file names set as early as possible.
10478 -- Units are loaded well before semantic processing starts.
10480 -- The only processing we defer to this point is the check
10481 -- for correct placement.
10483 when Pragma_Source_File_Name =>
10485 Check_Valid_Configuration_Pragma;
10487 ------------------------------
10488 -- Source_File_Name_Project --
10489 ------------------------------
10491 -- See Source_File_Name for syntax
10493 -- No processing here. Processing was completed during parsing,
10494 -- since we need to have file names set as early as possible.
10495 -- Units are loaded well before semantic processing starts.
10497 -- The only processing we defer to this point is the check
10498 -- for correct placement.
10500 when Pragma_Source_File_Name_Project =>
10502 Check_Valid_Configuration_Pragma;
10504 -- Check that a pragma Source_File_Name_Project is used only
10505 -- in a configuration pragmas file.
10507 -- Pragmas Source_File_Name_Project should only be generated
10508 -- by the Project Manager in configuration pragmas files.
10510 -- This is really an ugly test. It seems to depend on some
10511 -- accidental and undocumented property. At the very least
10512 -- it needs to be documented, but it would be better to have
10513 -- a clean way of testing if we are in a configuration file???
10515 if Present (Parent (N)) then
10517 ("pragma% can only appear in a configuration pragmas file");
10520 ----------------------
10521 -- Source_Reference --
10522 ----------------------
10524 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10526 -- Nothing to do, all processing completed in Par.Prag, since we
10527 -- need the information for possible parser messages that are output
10529 when Pragma_Source_Reference =>
10532 --------------------------------
10533 -- Static_Elaboration_Desired --
10534 --------------------------------
10536 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10538 when Pragma_Static_Elaboration_Desired =>
10540 Check_At_Most_N_Arguments (1);
10542 if Is_Compilation_Unit (Current_Scope)
10543 and then Ekind (Current_Scope) = E_Package
10545 Set_Static_Elaboration_Desired (Current_Scope, True);
10547 Error_Pragma ("pragma% must apply to a library-level package");
10554 -- pragma Storage_Size (EXPRESSION);
10556 when Pragma_Storage_Size => Storage_Size : declare
10557 P : constant Node_Id := Parent (N);
10561 Check_No_Identifiers;
10562 Check_Arg_Count (1);
10564 -- The expression must be analyzed in the special manner described
10565 -- in "Handling of Default Expressions" in sem.ads.
10567 Arg := Expression (Arg1);
10568 Preanalyze_Spec_Expression (Arg, Any_Integer);
10570 if not Is_Static_Expression (Arg) then
10571 Check_Restriction (Static_Storage_Size, Arg);
10574 if Nkind (P) /= N_Task_Definition then
10579 if Has_Storage_Size_Pragma (P) then
10580 Error_Pragma ("duplicate pragma% not allowed");
10582 Set_Has_Storage_Size_Pragma (P, True);
10585 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10586 -- ??? exp_ch9 should use this!
10594 -- pragma Storage_Unit (NUMERIC_LITERAL);
10596 -- Only permitted argument is System'Storage_Unit value
10598 when Pragma_Storage_Unit =>
10599 Check_No_Identifiers;
10600 Check_Arg_Count (1);
10601 Check_Arg_Is_Integer_Literal (Arg1);
10603 if Intval (Expression (Arg1)) /=
10604 UI_From_Int (Ttypes.System_Storage_Unit)
10606 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10608 ("the only allowed argument for pragma% is ^", Arg1);
10611 --------------------
10612 -- Stream_Convert --
10613 --------------------
10615 -- pragma Stream_Convert (
10616 -- [Entity =>] type_LOCAL_NAME,
10617 -- [Read =>] function_NAME,
10618 -- [Write =>] function NAME);
10620 when Pragma_Stream_Convert => Stream_Convert : declare
10622 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10623 -- Check that the given argument is the name of a local
10624 -- function of one argument that is not overloaded earlier
10625 -- in the current local scope. A check is also made that the
10626 -- argument is a function with one parameter.
10628 --------------------------------------
10629 -- Check_OK_Stream_Convert_Function --
10630 --------------------------------------
10632 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10636 Check_Arg_Is_Local_Name (Arg);
10637 Ent := Entity (Expression (Arg));
10639 if Has_Homonym (Ent) then
10641 ("argument for pragma% may not be overloaded", Arg);
10644 if Ekind (Ent) /= E_Function
10645 or else No (First_Formal (Ent))
10646 or else Present (Next_Formal (First_Formal (Ent)))
10649 ("argument for pragma% must be" &
10650 " function of one argument", Arg);
10652 end Check_OK_Stream_Convert_Function;
10654 -- Start of processing for Stream_Convert
10658 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10659 Check_Arg_Count (3);
10660 Check_Optional_Identifier (Arg1, Name_Entity);
10661 Check_Optional_Identifier (Arg2, Name_Read);
10662 Check_Optional_Identifier (Arg3, Name_Write);
10663 Check_Arg_Is_Local_Name (Arg1);
10664 Check_OK_Stream_Convert_Function (Arg2);
10665 Check_OK_Stream_Convert_Function (Arg3);
10668 Typ : constant Entity_Id :=
10669 Underlying_Type (Entity (Expression (Arg1)));
10670 Read : constant Entity_Id := Entity (Expression (Arg2));
10671 Write : constant Entity_Id := Entity (Expression (Arg3));
10674 Check_First_Subtype (Arg1);
10676 -- Check for too early or too late. Note that we don't enforce
10677 -- the rule about primitive operations in this case, since, as
10678 -- is the case for explicit stream attributes themselves, these
10679 -- restrictions are not appropriate. Note that the chaining of
10680 -- the pragma by Rep_Item_Too_Late is actually the critical
10681 -- processing done for this pragma.
10683 if Rep_Item_Too_Early (Typ, N)
10685 Rep_Item_Too_Late (Typ, N, FOnly => True)
10690 -- Return if previous error
10692 if Etype (Typ) = Any_Type
10694 Etype (Read) = Any_Type
10696 Etype (Write) = Any_Type
10703 if Underlying_Type (Etype (Read)) /= Typ then
10705 ("incorrect return type for function&", Arg2);
10708 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
10710 ("incorrect parameter type for function&", Arg3);
10713 if Underlying_Type (Etype (First_Formal (Read))) /=
10714 Underlying_Type (Etype (Write))
10717 ("result type of & does not match Read parameter type",
10721 end Stream_Convert;
10723 -------------------------
10724 -- Style_Checks (GNAT) --
10725 -------------------------
10727 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10729 -- This is processed by the parser since some of the style
10730 -- checks take place during source scanning and parsing. This
10731 -- means that we don't need to issue error messages here.
10733 when Pragma_Style_Checks => Style_Checks : declare
10734 A : constant Node_Id := Expression (Arg1);
10740 Check_No_Identifiers;
10742 -- Two argument form
10744 if Arg_Count = 2 then
10745 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10752 E_Id := Expression (Arg2);
10755 if not Is_Entity_Name (E_Id) then
10757 ("second argument of pragma% must be entity name",
10761 E := Entity (E_Id);
10767 Set_Suppress_Style_Checks (E,
10768 (Chars (Expression (Arg1)) = Name_Off));
10769 exit when No (Homonym (E));
10775 -- One argument form
10778 Check_Arg_Count (1);
10780 if Nkind (A) = N_String_Literal then
10784 Slen : constant Natural := Natural (String_Length (S));
10785 Options : String (1 .. Slen);
10791 C := Get_String_Char (S, Int (J));
10792 exit when not In_Character_Range (C);
10793 Options (J) := Get_Character (C);
10795 -- If at end of string, set options. As per discussion
10796 -- above, no need to check for errors, since we issued
10797 -- them in the parser.
10800 Set_Style_Check_Options (Options);
10808 elsif Nkind (A) = N_Identifier then
10809 if Chars (A) = Name_All_Checks then
10810 Set_Default_Style_Check_Options;
10812 elsif Chars (A) = Name_On then
10813 Style_Check := True;
10815 elsif Chars (A) = Name_Off then
10816 Style_Check := False;
10826 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
10828 when Pragma_Subtitle =>
10830 Check_Arg_Count (1);
10831 Check_Optional_Identifier (Arg1, Name_Subtitle);
10832 Check_Arg_Is_String_Literal (Arg1);
10838 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
10840 when Pragma_Suppress =>
10841 Process_Suppress_Unsuppress (True);
10847 -- pragma Suppress_All;
10849 -- The only check made here is that the pragma appears in the
10850 -- proper place, i.e. following a compilation unit. If indeed
10851 -- it appears in this context, then the parser has already
10852 -- inserted an equivalent pragma Suppress (All_Checks) to get
10853 -- the required effect.
10855 when Pragma_Suppress_All =>
10857 Check_Arg_Count (0);
10859 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
10860 or else not Is_List_Member (N)
10861 or else List_Containing (N) /= Pragmas_After (Parent (N))
10864 ("misplaced pragma%, must follow compilation unit");
10867 -------------------------
10868 -- Suppress_Debug_Info --
10869 -------------------------
10871 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
10873 when Pragma_Suppress_Debug_Info =>
10875 Check_Arg_Count (1);
10876 Check_Optional_Identifier (Arg1, Name_Entity);
10877 Check_Arg_Is_Local_Name (Arg1);
10878 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
10880 ----------------------------------
10881 -- Suppress_Exception_Locations --
10882 ----------------------------------
10884 -- pragma Suppress_Exception_Locations;
10886 when Pragma_Suppress_Exception_Locations =>
10888 Check_Arg_Count (0);
10889 Check_Valid_Configuration_Pragma;
10890 Exception_Locations_Suppressed := True;
10892 -----------------------------
10893 -- Suppress_Initialization --
10894 -----------------------------
10896 -- pragma Suppress_Initialization ([Entity =>] type_Name);
10898 when Pragma_Suppress_Initialization => Suppress_Init : declare
10904 Check_Arg_Count (1);
10905 Check_Optional_Identifier (Arg1, Name_Entity);
10906 Check_Arg_Is_Local_Name (Arg1);
10908 E_Id := Expression (Arg1);
10910 if Etype (E_Id) = Any_Type then
10914 E := Entity (E_Id);
10916 if Is_Type (E) then
10917 if Is_Incomplete_Or_Private_Type (E) then
10918 if No (Full_View (Base_Type (E))) then
10920 ("argument of pragma% cannot be an incomplete type",
10923 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
10926 Set_Suppress_Init_Proc (Base_Type (E));
10931 ("pragma% requires argument that is a type name", Arg1);
10939 -- pragma System_Name (DIRECT_NAME);
10941 -- Syntax check: one argument, which must be the identifier GNAT
10942 -- or the identifier GCC, no other identifiers are acceptable.
10944 when Pragma_System_Name =>
10945 Check_No_Identifiers;
10946 Check_Arg_Count (1);
10947 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
10949 -----------------------------
10950 -- Task_Dispatching_Policy --
10951 -----------------------------
10953 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
10955 when Pragma_Task_Dispatching_Policy => declare
10959 Check_Ada_83_Warning;
10960 Check_Arg_Count (1);
10961 Check_No_Identifiers;
10962 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10963 Check_Valid_Configuration_Pragma;
10964 Get_Name_String (Chars (Expression (Arg1)));
10965 DP := Fold_Upper (Name_Buffer (1));
10967 if Task_Dispatching_Policy /= ' '
10968 and then Task_Dispatching_Policy /= DP
10970 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10972 ("task dispatching policy incompatible with policy#");
10974 -- Set new policy, but always preserve System_Location since
10975 -- we like the error message with the run time name.
10978 Task_Dispatching_Policy := DP;
10980 if Task_Dispatching_Policy_Sloc /= System_Location then
10981 Task_Dispatching_Policy_Sloc := Loc;
10990 -- pragma Task_Info (EXPRESSION);
10992 when Pragma_Task_Info => Task_Info : declare
10993 P : constant Node_Id := Parent (N);
10998 if Nkind (P) /= N_Task_Definition then
10999 Error_Pragma ("pragma% must appear in task definition");
11002 Check_No_Identifiers;
11003 Check_Arg_Count (1);
11005 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11007 if Etype (Expression (Arg1)) = Any_Type then
11011 if Has_Task_Info_Pragma (P) then
11012 Error_Pragma ("duplicate pragma% not allowed");
11014 Set_Has_Task_Info_Pragma (P, True);
11022 -- pragma Task_Name (string_EXPRESSION);
11024 when Pragma_Task_Name => Task_Name : declare
11025 P : constant Node_Id := Parent (N);
11029 Check_No_Identifiers;
11030 Check_Arg_Count (1);
11032 Arg := Expression (Arg1);
11033 Analyze_And_Resolve (Arg, Standard_String);
11035 if Nkind (P) /= N_Task_Definition then
11039 if Has_Task_Name_Pragma (P) then
11040 Error_Pragma ("duplicate pragma% not allowed");
11042 Set_Has_Task_Name_Pragma (P, True);
11043 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11051 -- pragma Task_Storage (
11052 -- [Task_Type =>] LOCAL_NAME,
11053 -- [Top_Guard =>] static_integer_EXPRESSION);
11055 when Pragma_Task_Storage => Task_Storage : declare
11056 Args : Args_List (1 .. 2);
11057 Names : constant Name_List (1 .. 2) := (
11061 Task_Type : Node_Id renames Args (1);
11062 Top_Guard : Node_Id renames Args (2);
11068 Gather_Associations (Names, Args);
11070 if No (Task_Type) then
11072 ("missing task_type argument for pragma%");
11075 Check_Arg_Is_Local_Name (Task_Type);
11077 Ent := Entity (Task_Type);
11079 if not Is_Task_Type (Ent) then
11081 ("argument for pragma% must be task type", Task_Type);
11084 if No (Top_Guard) then
11086 ("pragma% takes two arguments", Task_Type);
11088 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11091 Check_First_Subtype (Task_Type);
11093 if Rep_Item_Too_Late (Ent, N) then
11102 -- pragma Time_Slice (static_duration_EXPRESSION);
11104 when Pragma_Time_Slice => Time_Slice : declare
11110 Check_Arg_Count (1);
11111 Check_No_Identifiers;
11112 Check_In_Main_Program;
11113 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11115 if not Error_Posted (Arg1) then
11117 while Present (Nod) loop
11118 if Nkind (Nod) = N_Pragma
11119 and then Pragma_Name (Nod) = Name_Time_Slice
11121 Error_Msg_Name_1 := Pname;
11122 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11129 -- Process only if in main unit
11131 if Get_Source_Unit (Loc) = Main_Unit then
11132 Opt.Time_Slice_Set := True;
11133 Val := Expr_Value_R (Expression (Arg1));
11135 if Val <= Ureal_0 then
11136 Opt.Time_Slice_Value := 0;
11138 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11139 Opt.Time_Slice_Value := 1_000_000_000;
11142 Opt.Time_Slice_Value :=
11143 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11152 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11154 -- TITLING_OPTION ::=
11155 -- [Title =>] STRING_LITERAL
11156 -- | [Subtitle =>] STRING_LITERAL
11158 when Pragma_Title => Title : declare
11159 Args : Args_List (1 .. 2);
11160 Names : constant Name_List (1 .. 2) := (
11166 Gather_Associations (Names, Args);
11168 for J in 1 .. 2 loop
11169 if Present (Args (J)) then
11170 Check_Arg_Is_String_Literal (Args (J));
11175 ---------------------
11176 -- Unchecked_Union --
11177 ---------------------
11179 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11181 when Pragma_Unchecked_Union => Unchecked_Union : declare
11182 Assoc : constant Node_Id := Arg1;
11183 Type_Id : constant Node_Id := Expression (Assoc);
11194 Check_No_Identifiers;
11195 Check_Arg_Count (1);
11196 Check_Arg_Is_Local_Name (Arg1);
11198 Find_Type (Type_Id);
11199 Typ := Entity (Type_Id);
11202 or else Rep_Item_Too_Early (Typ, N)
11206 Typ := Underlying_Type (Typ);
11209 if Rep_Item_Too_Late (Typ, N) then
11213 Check_First_Subtype (Arg1);
11215 -- Note remaining cases are references to a type in the current
11216 -- declarative part. If we find an error, we post the error on
11217 -- the relevant type declaration at an appropriate point.
11219 if not Is_Record_Type (Typ) then
11220 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11223 elsif Is_Tagged_Type (Typ) then
11224 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11227 elsif Is_Limited_Type (Typ) then
11229 ("Unchecked_Union must not be limited record type", Typ);
11230 Explain_Limited_Type (Typ, Typ);
11234 if not Has_Discriminants (Typ) then
11236 ("Unchecked_Union must have one discriminant", Typ);
11240 Discr := First_Discriminant (Typ);
11241 while Present (Discr) loop
11242 if No (Discriminant_Default_Value (Discr)) then
11244 ("Unchecked_Union discriminant must have default value",
11247 Next_Discriminant (Discr);
11250 Tdef := Type_Definition (Declaration_Node (Typ));
11251 Clist := Component_List (Tdef);
11253 Comp := First (Component_Items (Clist));
11254 while Present (Comp) loop
11255 Check_Component (Comp);
11259 if No (Clist) or else No (Variant_Part (Clist)) then
11261 ("Unchecked_Union must have variant part",
11266 Vpart := Variant_Part (Clist);
11268 Variant := First (Variants (Vpart));
11269 while Present (Variant) loop
11270 Check_Variant (Variant);
11275 Set_Is_Unchecked_Union (Typ, True);
11276 Set_Convention (Typ, Convention_C);
11278 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11279 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11280 end Unchecked_Union;
11282 ------------------------
11283 -- Unimplemented_Unit --
11284 ------------------------
11286 -- pragma Unimplemented_Unit;
11288 -- Note: this only gives an error if we are generating code,
11289 -- or if we are in a generic library unit (where the pragma
11290 -- appears in the body, not in the spec).
11292 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11293 Cunitent : constant Entity_Id :=
11294 Cunit_Entity (Get_Source_Unit (Loc));
11295 Ent_Kind : constant Entity_Kind :=
11300 Check_Arg_Count (0);
11302 if Operating_Mode = Generate_Code
11303 or else Ent_Kind = E_Generic_Function
11304 or else Ent_Kind = E_Generic_Procedure
11305 or else Ent_Kind = E_Generic_Package
11307 Get_Name_String (Chars (Cunitent));
11308 Set_Casing (Mixed_Case);
11309 Write_Str (Name_Buffer (1 .. Name_Len));
11310 Write_Str (" is not supported in this configuration");
11312 raise Unrecoverable_Error;
11314 end Unimplemented_Unit;
11316 ------------------------
11317 -- Universal_Aliasing --
11318 ------------------------
11320 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11322 when Pragma_Universal_Aliasing => Universal_Alias : declare
11327 Check_Arg_Count (1);
11328 Check_Optional_Identifier (Arg2, Name_Entity);
11329 Check_Arg_Is_Local_Name (Arg1);
11330 E_Id := Entity (Expression (Arg1));
11332 if E_Id = Any_Type then
11334 elsif No (E_Id) or else not Is_Type (E_Id) then
11335 Error_Pragma_Arg ("pragma% requires type", Arg1);
11338 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11339 end Universal_Alias;
11341 --------------------
11342 -- Universal_Data --
11343 --------------------
11345 -- pragma Universal_Data [(library_unit_NAME)];
11347 when Pragma_Universal_Data =>
11350 -- If this is a configuration pragma, then set the universal
11351 -- addressing option, otherwise confirm that the pragma
11352 -- satisfies the requirements of library unit pragma placement
11353 -- and leave it to the GNAAMP back end to detect the pragma
11354 -- (avoids transitive setting of the option due to withed units).
11356 if Is_Configuration_Pragma then
11357 Universal_Addressing_On_AAMP := True;
11359 Check_Valid_Library_Unit_Pragma;
11362 if not AAMP_On_Target then
11363 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11370 -- pragma Unmodified (local_Name {, local_Name});
11372 when Pragma_Unmodified => Unmodified : declare
11373 Arg_Node : Node_Id;
11374 Arg_Expr : Node_Id;
11375 Arg_Ent : Entity_Id;
11379 Check_At_Least_N_Arguments (1);
11381 -- Loop through arguments
11384 while Present (Arg_Node) loop
11385 Check_No_Identifier (Arg_Node);
11387 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11388 -- will in fact generate reference, so that the entity will
11389 -- have a reference, which will inhibit any warnings about
11390 -- it not being referenced, and also properly show up in the
11391 -- ali file as a reference. But this reference is recorded
11392 -- before the Has_Pragma_Unreferenced flag is set, so that
11393 -- no warning is generated for this reference.
11395 Check_Arg_Is_Local_Name (Arg_Node);
11396 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11398 if Is_Entity_Name (Arg_Expr) then
11399 Arg_Ent := Entity (Arg_Expr);
11401 if not Is_Assignable (Arg_Ent) then
11403 ("pragma% can only be applied to a variable",
11406 Set_Has_Pragma_Unmodified (Arg_Ent);
11418 -- pragma Unreferenced (local_Name {, local_Name});
11420 -- or when used in a context clause:
11422 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11424 when Pragma_Unreferenced => Unreferenced : declare
11425 Arg_Node : Node_Id;
11426 Arg_Expr : Node_Id;
11427 Arg_Ent : Entity_Id;
11432 Check_At_Least_N_Arguments (1);
11434 -- Check case of appearing within context clause
11436 if Is_In_Context_Clause then
11438 -- The arguments must all be units mentioned in a with clause
11439 -- in the same context clause. Note we already checked (in
11440 -- Par.Prag) that the arguments are either identifiers or
11441 -- selected components.
11444 while Present (Arg_Node) loop
11445 Citem := First (List_Containing (N));
11446 while Citem /= N loop
11447 if Nkind (Citem) = N_With_Clause
11448 and then Same_Name (Name (Citem), Expression (Arg_Node))
11450 Set_Has_Pragma_Unreferenced
11453 (Library_Unit (Citem))));
11454 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11463 ("argument of pragma% is not with'ed unit", Arg_Node);
11469 -- Case of not in list of context items
11473 while Present (Arg_Node) loop
11474 Check_No_Identifier (Arg_Node);
11476 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11477 -- will in fact generate reference, so that the entity will
11478 -- have a reference, which will inhibit any warnings about
11479 -- it not being referenced, and also properly show up in the
11480 -- ali file as a reference. But this reference is recorded
11481 -- before the Has_Pragma_Unreferenced flag is set, so that
11482 -- no warning is generated for this reference.
11484 Check_Arg_Is_Local_Name (Arg_Node);
11485 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11487 if Is_Entity_Name (Arg_Expr) then
11488 Arg_Ent := Entity (Arg_Expr);
11490 -- If the entity is overloaded, the pragma applies to the
11491 -- most recent overloading, as documented. In this case,
11492 -- name resolution does not generate a reference, so it
11493 -- must be done here explicitly.
11495 if Is_Overloaded (Arg_Expr) then
11496 Generate_Reference (Arg_Ent, N);
11499 Set_Has_Pragma_Unreferenced (Arg_Ent);
11507 --------------------------
11508 -- Unreferenced_Objects --
11509 --------------------------
11511 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11513 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11514 Arg_Node : Node_Id;
11515 Arg_Expr : Node_Id;
11519 Check_At_Least_N_Arguments (1);
11522 while Present (Arg_Node) loop
11523 Check_No_Identifier (Arg_Node);
11524 Check_Arg_Is_Local_Name (Arg_Node);
11525 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11527 if not Is_Entity_Name (Arg_Expr)
11528 or else not Is_Type (Entity (Arg_Expr))
11531 ("argument for pragma% must be type or subtype", Arg_Node);
11534 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11537 end Unreferenced_Objects;
11539 ------------------------------
11540 -- Unreserve_All_Interrupts --
11541 ------------------------------
11543 -- pragma Unreserve_All_Interrupts;
11545 when Pragma_Unreserve_All_Interrupts =>
11547 Check_Arg_Count (0);
11549 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11550 Unreserve_All_Interrupts := True;
11557 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11559 when Pragma_Unsuppress =>
11561 Process_Suppress_Unsuppress (False);
11563 -------------------
11564 -- Use_VADS_Size --
11565 -------------------
11567 -- pragma Use_VADS_Size;
11569 when Pragma_Use_VADS_Size =>
11571 Check_Arg_Count (0);
11572 Check_Valid_Configuration_Pragma;
11573 Use_VADS_Size := True;
11575 ---------------------
11576 -- Validity_Checks --
11577 ---------------------
11579 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11581 when Pragma_Validity_Checks => Validity_Checks : declare
11582 A : constant Node_Id := Expression (Arg1);
11588 Check_Arg_Count (1);
11589 Check_No_Identifiers;
11591 if Nkind (A) = N_String_Literal then
11595 Slen : constant Natural := Natural (String_Length (S));
11596 Options : String (1 .. Slen);
11602 C := Get_String_Char (S, Int (J));
11603 exit when not In_Character_Range (C);
11604 Options (J) := Get_Character (C);
11607 Set_Validity_Check_Options (Options);
11615 elsif Nkind (A) = N_Identifier then
11617 if Chars (A) = Name_All_Checks then
11618 Set_Validity_Check_Options ("a");
11620 elsif Chars (A) = Name_On then
11621 Validity_Checks_On := True;
11623 elsif Chars (A) = Name_Off then
11624 Validity_Checks_On := False;
11628 end Validity_Checks;
11634 -- pragma Volatile (LOCAL_NAME);
11636 when Pragma_Volatile =>
11637 Process_Atomic_Shared_Volatile;
11639 -------------------------
11640 -- Volatile_Components --
11641 -------------------------
11643 -- pragma Volatile_Components (array_LOCAL_NAME);
11645 -- Volatile is handled by the same circuit as Atomic_Components
11651 -- pragma Warnings (On | Off);
11652 -- pragma Warnings (On | Off, LOCAL_NAME);
11653 -- pragma Warnings (static_string_EXPRESSION);
11654 -- pragma Warnings (On | Off, STRING_LITERAL);
11656 when Pragma_Warnings => Warnings : begin
11658 Check_At_Least_N_Arguments (1);
11659 Check_No_Identifiers;
11662 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11665 -- One argument case
11667 if Arg_Count = 1 then
11669 -- On/Off one argument case was processed by parser
11671 if Nkind (Argx) = N_Identifier
11673 (Chars (Argx) = Name_On
11675 Chars (Argx) = Name_Off)
11679 -- One argument case must be ON/OFF or static string expr
11681 elsif not Is_Static_String_Expression (Arg1) then
11683 ("argument of pragma% must be On/Off or " &
11684 "static string expression", Arg2);
11686 -- One argument string expression case
11690 Lit : constant Node_Id := Expr_Value_S (Argx);
11691 Str : constant String_Id := Strval (Lit);
11692 Len : constant Nat := String_Length (Str);
11700 while J <= Len loop
11701 C := Get_String_Char (Str, J);
11702 OK := In_Character_Range (C);
11705 Chr := Get_Character (C);
11709 if J < Len and then Chr = '.' then
11711 C := Get_String_Char (Str, J);
11712 Chr := Get_Character (C);
11714 if not Set_Dot_Warning_Switch (Chr) then
11716 ("invalid warning switch character " &
11723 OK := Set_Warning_Switch (Chr);
11729 ("invalid warning switch character " & Chr,
11738 -- Two or more arguments (must be two)
11741 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11742 Check_At_Most_N_Arguments (2);
11750 E_Id := Expression (Arg2);
11753 -- In the expansion of an inlined body, a reference to
11754 -- the formal may be wrapped in a conversion if the
11755 -- actual is a conversion. Retrieve the real entity name.
11757 if (In_Instance_Body
11758 or else In_Inlined_Body)
11759 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
11761 E_Id := Expression (E_Id);
11764 -- Entity name case
11766 if Is_Entity_Name (E_Id) then
11767 E := Entity (E_Id);
11774 (E, (Chars (Expression (Arg1)) = Name_Off));
11776 if Chars (Expression (Arg1)) = Name_Off
11777 and then Warn_On_Warnings_Off
11779 Warnings_Off_Pragmas.Append ((N, E));
11782 if Is_Enumeration_Type (E) then
11786 Lit := First_Literal (E);
11787 while Present (Lit) loop
11788 Set_Warnings_Off (Lit);
11789 Next_Literal (Lit);
11794 exit when No (Homonym (E));
11799 -- Error if not entity or static string literal case
11801 elsif not Is_Static_String_Expression (Arg2) then
11803 ("second argument of pragma% must be entity " &
11804 "name or static string expression", Arg2);
11806 -- String literal case
11809 String_To_Name_Buffer
11810 (Strval (Expr_Value_S (Expression (Arg2))));
11812 -- Note on configuration pragma case: If this is a
11813 -- configuration pragma, then for an OFF pragma, we
11814 -- just set Config True in the call, which is all
11815 -- that needs to be done. For the case of ON, this
11816 -- is normally an error, unless it is canceling the
11817 -- effect of a previous OFF pragma in the same file.
11818 -- In any other case, an error will be signalled (ON
11819 -- with no matching OFF).
11821 if Chars (Argx) = Name_Off then
11822 Set_Specific_Warning_Off
11823 (Loc, Name_Buffer (1 .. Name_Len),
11824 Config => Is_Configuration_Pragma);
11826 elsif Chars (Argx) = Name_On then
11827 Set_Specific_Warning_On
11828 (Loc, Name_Buffer (1 .. Name_Len), Err);
11832 ("?pragma Warnings On with no " &
11833 "matching Warnings Off",
11843 -------------------
11844 -- Weak_External --
11845 -------------------
11847 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
11849 when Pragma_Weak_External => Weak_External : declare
11854 Check_Arg_Count (1);
11855 Check_Optional_Identifier (Arg1, Name_Entity);
11856 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11857 Ent := Entity (Expression (Arg1));
11859 if Rep_Item_Too_Early (Ent, N) then
11862 Ent := Underlying_Type (Ent);
11865 -- The only processing required is to link this item on to the
11866 -- list of rep items for the given entity. This is accomplished
11867 -- by the call to Rep_Item_Too_Late (when no error is detected
11868 -- and False is returned).
11870 if Rep_Item_Too_Late (Ent, N) then
11873 Set_Has_Gigi_Rep_Item (Ent);
11877 -----------------------------
11878 -- Wide_Character_Encoding --
11879 -----------------------------
11881 -- pragma Wide_Character_Encoding (IDENTIFIER);
11883 when Pragma_Wide_Character_Encoding =>
11885 -- Nothing to do, handled in parser. Note that we do not enforce
11886 -- configuration pragma placement, this pragma can appear at any
11887 -- place in the source, allowing mixed encodings within a single
11892 --------------------
11893 -- Unknown_Pragma --
11894 --------------------
11896 -- Should be impossible, since the case of an unknown pragma is
11897 -- separately processed before the case statement is entered.
11899 when Unknown_Pragma =>
11900 raise Program_Error;
11904 when Pragma_Exit => null;
11905 end Analyze_Pragma;
11907 -------------------
11908 -- Check_Enabled --
11909 -------------------
11911 function Check_Enabled (Nam : Name_Id) return Boolean is
11915 PP := Opt.Check_Policy_List;
11918 return Assertions_Enabled;
11921 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
11924 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
11926 when Name_On | Name_Check =>
11928 when Name_Off | Name_Ignore =>
11931 raise Program_Error;
11935 PP := Next_Pragma (PP);
11940 ---------------------------------
11941 -- Delay_Config_Pragma_Analyze --
11942 ---------------------------------
11944 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
11946 return Pragma_Name (N) = Name_Interrupt_State
11948 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
11949 end Delay_Config_Pragma_Analyze;
11951 -------------------------
11952 -- Get_Base_Subprogram --
11953 -------------------------
11955 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
11956 Result : Entity_Id;
11959 -- Follow subprogram renaming chain
11962 while Is_Subprogram (Result)
11964 (Is_Generic_Instance (Result)
11965 or else Nkind (Parent (Declaration_Node (Result))) =
11966 N_Subprogram_Renaming_Declaration)
11967 and then Present (Alias (Result))
11969 Result := Alias (Result);
11973 end Get_Base_Subprogram;
11975 --------------------
11976 -- Get_Pragma_Arg --
11977 --------------------
11979 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
11981 if Nkind (Arg) = N_Pragma_Argument_Association then
11982 return Expression (Arg);
11986 end Get_Pragma_Arg;
11992 procedure Initialize is
11997 -----------------------------
11998 -- Is_Config_Static_String --
11999 -----------------------------
12001 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12003 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12004 -- This is an internal recursive function that is just like the
12005 -- outer function except that it adds the string to the name buffer
12006 -- rather than placing the string in the name buffer.
12008 ------------------------------
12009 -- Add_Config_Static_String --
12010 ------------------------------
12012 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12019 if Nkind (N) = N_Op_Concat then
12020 if Add_Config_Static_String (Left_Opnd (N)) then
12021 N := Right_Opnd (N);
12027 if Nkind (N) /= N_String_Literal then
12028 Error_Msg_N ("string literal expected for pragma argument", N);
12032 for J in 1 .. String_Length (Strval (N)) loop
12033 C := Get_String_Char (Strval (N), J);
12035 if not In_Character_Range (C) then
12037 ("string literal contains invalid wide character",
12038 Sloc (N) + 1 + Source_Ptr (J));
12042 Add_Char_To_Name_Buffer (Get_Character (C));
12047 end Add_Config_Static_String;
12049 -- Start of processing for Is_Config_Static_String
12054 return Add_Config_Static_String (Arg);
12055 end Is_Config_Static_String;
12057 -----------------------------------------
12058 -- Is_Non_Significant_Pragma_Reference --
12059 -----------------------------------------
12061 -- This function makes use of the following static table which indicates
12062 -- whether a given pragma is significant. A value of -1 in this table
12063 -- indicates that the reference is significant. A value of zero indicates
12064 -- than appearance as any argument is insignificant, a positive value
12065 -- indicates that appearance in that parameter position is significant.
12067 -- A value of 99 flags a special case requiring a special check (this is
12068 -- used for cases not covered by this standard encoding, e.g. pragma Check
12069 -- where the first argument is not significant, but the others are).
12071 Sig_Flags : constant array (Pragma_Id) of Int :=
12072 (Pragma_AST_Entry => -1,
12073 Pragma_Abort_Defer => -1,
12074 Pragma_Ada_83 => -1,
12075 Pragma_Ada_95 => -1,
12076 Pragma_Ada_05 => -1,
12077 Pragma_Ada_2005 => -1,
12078 Pragma_All_Calls_Remote => -1,
12079 Pragma_Annotate => -1,
12080 Pragma_Assert => -1,
12081 Pragma_Assertion_Policy => 0,
12082 Pragma_Asynchronous => -1,
12083 Pragma_Atomic => 0,
12084 Pragma_Atomic_Components => 0,
12085 Pragma_Attach_Handler => -1,
12086 Pragma_Check => 99,
12087 Pragma_Check_Name => 0,
12088 Pragma_Check_Policy => 0,
12089 Pragma_CIL_Constructor => -1,
12090 Pragma_CPP_Class => 0,
12091 Pragma_CPP_Constructor => 0,
12092 Pragma_CPP_Virtual => 0,
12093 Pragma_CPP_Vtable => 0,
12094 Pragma_C_Pass_By_Copy => 0,
12095 Pragma_Comment => 0,
12096 Pragma_Common_Object => -1,
12097 Pragma_Compile_Time_Error => -1,
12098 Pragma_Compile_Time_Warning => -1,
12099 Pragma_Compiler_Unit => 0,
12100 Pragma_Complete_Representation => 0,
12101 Pragma_Complex_Representation => 0,
12102 Pragma_Component_Alignment => -1,
12103 Pragma_Controlled => 0,
12104 Pragma_Convention => 0,
12105 Pragma_Convention_Identifier => 0,
12106 Pragma_Debug => -1,
12107 Pragma_Debug_Policy => 0,
12108 Pragma_Detect_Blocking => -1,
12109 Pragma_Discard_Names => 0,
12110 Pragma_Elaborate => -1,
12111 Pragma_Elaborate_All => -1,
12112 Pragma_Elaborate_Body => -1,
12113 Pragma_Elaboration_Checks => -1,
12114 Pragma_Eliminate => -1,
12115 Pragma_Export => -1,
12116 Pragma_Export_Exception => -1,
12117 Pragma_Export_Function => -1,
12118 Pragma_Export_Object => -1,
12119 Pragma_Export_Procedure => -1,
12120 Pragma_Export_Value => -1,
12121 Pragma_Export_Valued_Procedure => -1,
12122 Pragma_Extend_System => -1,
12123 Pragma_Extensions_Allowed => -1,
12124 Pragma_External => -1,
12125 Pragma_Favor_Top_Level => -1,
12126 Pragma_External_Name_Casing => -1,
12127 Pragma_Fast_Math => -1,
12128 Pragma_Finalize_Storage_Only => 0,
12129 Pragma_Float_Representation => 0,
12130 Pragma_Ident => -1,
12131 Pragma_Implemented_By_Entry => -1,
12132 Pragma_Implicit_Packing => 0,
12133 Pragma_Import => +2,
12134 Pragma_Import_Exception => 0,
12135 Pragma_Import_Function => 0,
12136 Pragma_Import_Object => 0,
12137 Pragma_Import_Procedure => 0,
12138 Pragma_Import_Valued_Procedure => 0,
12139 Pragma_Initialize_Scalars => -1,
12140 Pragma_Inline => 0,
12141 Pragma_Inline_Always => 0,
12142 Pragma_Inline_Generic => 0,
12143 Pragma_Inspection_Point => -1,
12144 Pragma_Interface => +2,
12145 Pragma_Interface_Name => +2,
12146 Pragma_Interrupt_Handler => -1,
12147 Pragma_Interrupt_Priority => -1,
12148 Pragma_Interrupt_State => -1,
12149 Pragma_Java_Constructor => -1,
12150 Pragma_Java_Interface => -1,
12151 Pragma_Keep_Names => 0,
12152 Pragma_License => -1,
12153 Pragma_Link_With => -1,
12154 Pragma_Linker_Alias => -1,
12155 Pragma_Linker_Constructor => -1,
12156 Pragma_Linker_Destructor => -1,
12157 Pragma_Linker_Options => -1,
12158 Pragma_Linker_Section => -1,
12160 Pragma_Locking_Policy => -1,
12161 Pragma_Long_Float => -1,
12162 Pragma_Machine_Attribute => -1,
12164 Pragma_Main_Storage => -1,
12165 Pragma_Memory_Size => -1,
12166 Pragma_No_Return => 0,
12167 Pragma_No_Body => 0,
12168 Pragma_No_Run_Time => -1,
12169 Pragma_No_Strict_Aliasing => -1,
12170 Pragma_Normalize_Scalars => -1,
12171 Pragma_Obsolescent => 0,
12172 Pragma_Optimize => -1,
12173 Pragma_Optimize_Alignment => -1,
12176 Pragma_Passive => -1,
12177 Pragma_Preelaborable_Initialization => -1,
12178 Pragma_Polling => -1,
12179 Pragma_Persistent_BSS => 0,
12180 Pragma_Postcondition => -1,
12181 Pragma_Precondition => -1,
12182 Pragma_Preelaborate => -1,
12183 Pragma_Preelaborate_05 => -1,
12184 Pragma_Priority => -1,
12185 Pragma_Priority_Specific_Dispatching => -1,
12186 Pragma_Profile => 0,
12187 Pragma_Profile_Warnings => 0,
12188 Pragma_Propagate_Exceptions => -1,
12189 Pragma_Psect_Object => -1,
12191 Pragma_Pure_05 => -1,
12192 Pragma_Pure_Function => -1,
12193 Pragma_Queuing_Policy => -1,
12194 Pragma_Ravenscar => -1,
12195 Pragma_Relative_Deadline => -1,
12196 Pragma_Remote_Call_Interface => -1,
12197 Pragma_Remote_Types => -1,
12198 Pragma_Restricted_Run_Time => -1,
12199 Pragma_Restriction_Warnings => -1,
12200 Pragma_Restrictions => -1,
12201 Pragma_Reviewable => -1,
12202 Pragma_Share_Generic => -1,
12203 Pragma_Shared => -1,
12204 Pragma_Shared_Passive => -1,
12205 Pragma_Source_File_Name => -1,
12206 Pragma_Source_File_Name_Project => -1,
12207 Pragma_Source_Reference => -1,
12208 Pragma_Storage_Size => -1,
12209 Pragma_Storage_Unit => -1,
12210 Pragma_Static_Elaboration_Desired => -1,
12211 Pragma_Stream_Convert => -1,
12212 Pragma_Style_Checks => -1,
12213 Pragma_Subtitle => -1,
12214 Pragma_Suppress => 0,
12215 Pragma_Suppress_Exception_Locations => 0,
12216 Pragma_Suppress_All => -1,
12217 Pragma_Suppress_Debug_Info => 0,
12218 Pragma_Suppress_Initialization => 0,
12219 Pragma_System_Name => -1,
12220 Pragma_Task_Dispatching_Policy => -1,
12221 Pragma_Task_Info => -1,
12222 Pragma_Task_Name => -1,
12223 Pragma_Task_Storage => 0,
12224 Pragma_Time_Slice => -1,
12225 Pragma_Title => -1,
12226 Pragma_Unchecked_Union => 0,
12227 Pragma_Unimplemented_Unit => -1,
12228 Pragma_Universal_Aliasing => -1,
12229 Pragma_Universal_Data => -1,
12230 Pragma_Unmodified => -1,
12231 Pragma_Unreferenced => -1,
12232 Pragma_Unreferenced_Objects => -1,
12233 Pragma_Unreserve_All_Interrupts => -1,
12234 Pragma_Unsuppress => 0,
12235 Pragma_Use_VADS_Size => -1,
12236 Pragma_Validity_Checks => -1,
12237 Pragma_Volatile => 0,
12238 Pragma_Volatile_Components => 0,
12239 Pragma_Warnings => -1,
12240 Pragma_Weak_External => -1,
12241 Pragma_Wide_Character_Encoding => 0,
12242 Unknown_Pragma => 0);
12244 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12253 if Nkind (P) /= N_Pragma_Argument_Association then
12257 Id := Get_Pragma_Id (Parent (P));
12258 C := Sig_Flags (Id);
12270 -- For pragma Check, the first argument is not significant,
12271 -- the second and the third (if present) arguments are
12274 when Pragma_Check =>
12276 P = First (Pragma_Argument_Associations (Parent (P)));
12279 raise Program_Error;
12283 A := First (Pragma_Argument_Associations (Parent (P)));
12284 for J in 1 .. C - 1 loop
12292 return A = P; -- is this wrong way round ???
12295 end Is_Non_Significant_Pragma_Reference;
12297 ------------------------------
12298 -- Is_Pragma_String_Literal --
12299 ------------------------------
12301 -- This function returns true if the corresponding pragma argument is
12302 -- a static string expression. These are the only cases in which string
12303 -- literals can appear as pragma arguments. We also allow a string
12304 -- literal as the first argument to pragma Assert (although it will
12305 -- of course always generate a type error).
12307 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12308 Pragn : constant Node_Id := Parent (Par);
12309 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12310 Pname : constant Name_Id := Pragma_Name (Pragn);
12316 N := First (Assoc);
12323 if Pname = Name_Assert then
12326 elsif Pname = Name_Export then
12329 elsif Pname = Name_Ident then
12332 elsif Pname = Name_Import then
12335 elsif Pname = Name_Interface_Name then
12338 elsif Pname = Name_Linker_Alias then
12341 elsif Pname = Name_Linker_Section then
12344 elsif Pname = Name_Machine_Attribute then
12347 elsif Pname = Name_Source_File_Name then
12350 elsif Pname = Name_Source_Reference then
12353 elsif Pname = Name_Title then
12356 elsif Pname = Name_Subtitle then
12362 end Is_Pragma_String_Literal;
12364 --------------------------------------
12365 -- Process_Compilation_Unit_Pragmas --
12366 --------------------------------------
12368 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12370 -- A special check for pragma Suppress_All. This is a strange DEC
12371 -- pragma, strange because it comes at the end of the unit. If we
12372 -- have a pragma Suppress_All in the Pragmas_After of the current
12373 -- unit, then we insert a pragma Suppress (All_Checks) at the start
12374 -- of the context clause to ensure the correct processing.
12377 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12381 if Present (PA) then
12383 while Present (P) loop
12384 if Pragma_Name (P) = Name_Suppress_All then
12385 Prepend_To (Context_Items (N),
12386 Make_Pragma (Sloc (P),
12387 Chars => Name_Suppress,
12388 Pragma_Argument_Associations => New_List (
12389 Make_Pragma_Argument_Association (Sloc (P),
12391 Make_Identifier (Sloc (P),
12392 Chars => Name_All_Checks)))));
12400 end Process_Compilation_Unit_Pragmas;
12411 --------------------------------
12412 -- Set_Encoded_Interface_Name --
12413 --------------------------------
12415 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12416 Str : constant String_Id := Strval (S);
12417 Len : constant Int := String_Length (Str);
12422 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12425 -- Stores encoded value of character code CC. The encoding we
12426 -- use an underscore followed by four lower case hex digits.
12432 procedure Encode is
12434 Store_String_Char (Get_Char_Code ('_'));
12436 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12438 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12440 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12442 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12445 -- Start of processing for Set_Encoded_Interface_Name
12448 -- If first character is asterisk, this is a link name, and we
12449 -- leave it completely unmodified. We also ignore null strings
12450 -- (the latter case happens only in error cases) and no encoding
12451 -- should occur for Java or AAMP interface names.
12454 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12455 or else VM_Target /= No_VM
12456 or else AAMP_On_Target
12458 Set_Interface_Name (E, S);
12463 CC := Get_String_Char (Str, J);
12465 exit when not In_Character_Range (CC);
12467 C := Get_Character (CC);
12469 exit when C /= '_' and then C /= '$'
12470 and then C not in '0' .. '9'
12471 and then C not in 'a' .. 'z'
12472 and then C not in 'A' .. 'Z';
12475 Set_Interface_Name (E, S);
12483 -- Here we need to encode. The encoding we use as follows:
12484 -- three underscores + four hex digits (lower case)
12488 for J in 1 .. String_Length (Str) loop
12489 CC := Get_String_Char (Str, J);
12491 if not In_Character_Range (CC) then
12494 C := Get_Character (CC);
12496 if C = '_' or else C = '$'
12497 or else C in '0' .. '9'
12498 or else C in 'a' .. 'z'
12499 or else C in 'A' .. 'Z'
12501 Store_String_Char (CC);
12508 Set_Interface_Name (E,
12509 Make_String_Literal (Sloc (S),
12510 Strval => End_String));
12512 end Set_Encoded_Interface_Name;
12514 -------------------
12515 -- Set_Unit_Name --
12516 -------------------
12518 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12523 if Nkind (N) = N_Identifier
12524 and then Nkind (With_Item) = N_Identifier
12526 Set_Entity (N, Entity (With_Item));
12528 elsif Nkind (N) = N_Selected_Component then
12529 Change_Selected_Component_To_Expanded_Name (N);
12530 Set_Entity (N, Entity (With_Item));
12531 Set_Entity (Selector_Name (N), Entity (N));
12533 Pref := Prefix (N);
12534 Scop := Scope (Entity (N));
12535 while Nkind (Pref) = N_Selected_Component loop
12536 Change_Selected_Component_To_Expanded_Name (Pref);
12537 Set_Entity (Selector_Name (Pref), Scop);
12538 Set_Entity (Pref, Scop);
12539 Pref := Prefix (Pref);
12540 Scop := Scope (Scop);
12543 Set_Entity (Pref, Scop);