1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Dist; use Exp_Dist;
42 with Lib.Writ; use Lib.Writ;
43 with Lib.Xref; use Lib.Xref;
44 with Namet.Sp; use Namet.Sp;
45 with Nlists; use Nlists;
46 with Nmake; use Nmake;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch6; use Sem_Ch6;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch12; use Sem_Ch12;
58 with Sem_Ch13; use Sem_Ch13;
59 with Sem_Dist; use Sem_Dist;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Intr; use Sem_Intr;
63 with Sem_Mech; use Sem_Mech;
64 with Sem_Res; use Sem_Res;
65 with Sem_Type; use Sem_Type;
66 with Sem_Util; use Sem_Util;
67 with Sem_VFpt; use Sem_VFpt;
68 with Sem_Warn; use Sem_Warn;
69 with Stand; use Stand;
70 with Sinfo; use Sinfo;
71 with Sinfo.CN; use Sinfo.CN;
72 with Sinput; use Sinput;
73 with Snames; use Snames;
74 with Stringt; use Stringt;
75 with Stylesw; use Stylesw;
77 with Targparm; use Targparm;
78 with Tbuild; use Tbuild;
80 with Uintp; use Uintp;
81 with Uname; use Uname;
82 with Urealp; use Urealp;
83 with Validsw; use Validsw;
85 package body Sem_Prag is
87 ----------------------------------------------
88 -- Common Handling of Import-Export Pragmas --
89 ----------------------------------------------
91 -- In the following section, a number of Import_xxx and Export_xxx
92 -- pragmas are defined by GNAT. These are compatible with the DEC
93 -- pragmas of the same name, and all have the following common
94 -- form and processing:
97 -- [Internal =>] LOCAL_NAME
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
106 -- EXTERNAL_SYMBOL ::=
108 -- | static_string_EXPRESSION
110 -- The internal LOCAL_NAME designates the entity that is imported or
111 -- exported, and must refer to an entity in the current declarative
112 -- part (as required by the rules for LOCAL_NAME).
114 -- The external linker name is designated by the External parameter if
115 -- given, or the Internal parameter if not (if there is no External
116 -- parameter, the External parameter is a copy of the Internal name).
118 -- If the External parameter is given as a string, then this string is
119 -- treated as an external name (exactly as though it had been given as an
120 -- External_Name parameter for a normal Import pragma).
122 -- If the External parameter is given as an identifier (or there is no
123 -- External parameter, so that the Internal identifier is used), then
124 -- the external name is the characters of the identifier, translated
125 -- to all upper case letters for OpenVMS versions of GNAT, and to all
126 -- lower case letters for all other versions
128 -- Note: the external name specified or implied by any of these special
129 -- Import_xxx or Export_xxx pragmas override an external or link name
130 -- specified in a previous Import or Export pragma.
132 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
133 -- named notation, following the standard rules for subprogram calls, i.e.
134 -- parameters can be given in any order if named notation is used, and
135 -- positional and named notation can be mixed, subject to the rule that all
136 -- positional parameters must appear first.
138 -- Note: All these pragmas are implemented exactly following the DEC design
139 -- and implementation and are intended to be fully compatible with the use
140 -- of these pragmas in the DEC Ada compiler.
142 --------------------------------------------
143 -- Checking for Duplicated External Names --
144 --------------------------------------------
146 -- It is suspicious if two separate Export pragmas use the same external
147 -- name. The following table is used to diagnose this situation so that
148 -- an appropriate warning can be issued.
150 -- The Node_Id stored is for the N_String_Literal node created to hold
151 -- the value of the external name. The Sloc of this node is used to
152 -- cross-reference the location of the duplication.
154 package Externals is new Table.Table (
155 Table_Component_Type => Node_Id,
156 Table_Index_Type => Int,
157 Table_Low_Bound => 0,
158 Table_Initial => 100,
159 Table_Increment => 100,
160 Table_Name => "Name_Externals");
162 -------------------------------------
163 -- Local Subprograms and Variables --
164 -------------------------------------
166 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
167 -- This routine is used for possible casing adjustment of an explicit
168 -- external name supplied as a string literal (the node N), according to
169 -- the casing requirement of Opt.External_Name_Casing. If this is set to
170 -- As_Is, then the string literal is returned unchanged, but if it is set
171 -- to Uppercase or Lowercase, then a new string literal with appropriate
172 -- casing is constructed.
174 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
175 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
176 -- original one, following the renaming chain) is returned. Otherwise the
177 -- entity is returned unchanged. Should be in Einfo???
179 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
180 -- All the routines that check pragma arguments take either a pragma
181 -- argument association (in which case the expression of the argument
182 -- association is checked), or the expression directly. The function
183 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
184 -- is a pragma argument association node, then its expression is returned,
185 -- otherwise Arg is returned unchanged.
188 -- This is a dummy function called by the processing for pragma Reviewable.
189 -- It is there for assisting front end debugging. By placing a Reviewable
190 -- pragma in the source program, a breakpoint on rv catches this place in
191 -- the source, allowing convenient stepping to the point of interest.
193 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194 -- Place semantic information on the argument of an Elaborate/Elaborate_All
195 -- pragma. Entity name for unit and its parents is taken from item in
196 -- previous with_clause that mentions the unit.
198 -------------------------------
199 -- Adjust_External_Name_Case --
200 -------------------------------
202 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
206 -- Adjust case of literal if required
208 if Opt.External_Name_Exp_Casing = As_Is then
212 -- Copy existing string
218 for J in 1 .. String_Length (Strval (N)) loop
219 CC := Get_String_Char (Strval (N), J);
221 if Opt.External_Name_Exp_Casing = Uppercase
222 and then CC >= Get_Char_Code ('a')
223 and then CC <= Get_Char_Code ('z')
225 Store_String_Char (CC - 32);
227 elsif Opt.External_Name_Exp_Casing = Lowercase
228 and then CC >= Get_Char_Code ('A')
229 and then CC <= Get_Char_Code ('Z')
231 Store_String_Char (CC + 32);
234 Store_String_Char (CC);
239 Make_String_Literal (Sloc (N),
240 Strval => End_String);
242 end Adjust_External_Name_Case;
244 ------------------------------
245 -- Analyze_PPC_In_Decl_Part --
246 ------------------------------
248 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249 Arg1 : constant Node_Id :=
250 First (Pragma_Argument_Associations (N));
251 Arg2 : constant Node_Id := Next (Arg1);
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression
264 (Get_Pragma_Arg (Arg1), Standard_Boolean);
266 -- If there is a message argument, analyze it the same way
268 if Present (Arg2) then
269 Preanalyze_Spec_Expression
270 (Get_Pragma_Arg (Arg2), Standard_String);
273 -- Remove the subprogram from the scope stack now that the pre-analysis
274 -- of the precondition/postcondition is done.
277 end Analyze_PPC_In_Decl_Part;
283 procedure Analyze_Pragma (N : Node_Id) is
284 Loc : constant Source_Ptr := Sloc (N);
285 Pname : constant Name_Id := Pragma_Name (N);
288 Pragma_Exit : exception;
289 -- This exception is used to exit pragma processing completely. It is
290 -- used when an error is detected, and no further processing is
291 -- required. It is also used if an earlier error has left the tree in
292 -- a state where the pragma should not be processed.
295 -- Number of pragma argument associations
301 -- First four pragma arguments (pragma argument association nodes, or
302 -- Empty if the corresponding argument does not exist).
304 type Name_List is array (Natural range <>) of Name_Id;
305 type Args_List is array (Natural range <>) of Node_Id;
306 -- Types used for arguments to Check_Arg_Order and Gather_Associations
308 procedure Ada_2005_Pragma;
309 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
310 -- Ada 95 mode, these are implementation defined pragmas, so should be
311 -- caught by the No_Implementation_Pragmas restriction
313 procedure Check_Ada_83_Warning;
314 -- Issues a warning message for the current pragma if operating in Ada
315 -- 83 mode (used for language pragmas that are not a standard part of
316 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
319 procedure Check_Arg_Count (Required : Nat);
320 -- Check argument count for pragma is equal to given parameter. If not,
321 -- then issue an error message and raise Pragma_Exit.
323 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
324 -- Arg which can either be a pragma argument association, in which case
325 -- the check is applied to the expression of the association or an
326 -- expression directly.
328 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
329 -- Check that an argument has the right form for an EXTERNAL_NAME
330 -- parameter of an extended import/export pragma. The rule is that the
331 -- name must be an identifier or string literal (in Ada 83 mode) or a
332 -- static string expression (in Ada 95 mode).
334 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
335 -- Check the specified argument Arg to make sure that it is an
336 -- identifier. If not give error and raise Pragma_Exit.
338 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
339 -- Check the specified argument Arg to make sure that it is an integer
340 -- literal. If not give error and raise Pragma_Exit.
342 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
343 -- Check the specified argument Arg to make sure that it has the proper
344 -- syntactic form for a local name and meets the semantic requirements
345 -- for a local name. The local name is analyzed as part of the
346 -- processing for this call. In addition, the local name is required
347 -- to represent an entity at the library level.
349 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
350 -- Check the specified argument Arg to make sure that it has the proper
351 -- syntactic form for a local name and meets the semantic requirements
352 -- for a local name. The local name is analyzed as part of the
353 -- processing for this call.
355 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
356 -- Check the specified argument Arg to make sure that it is a valid
357 -- locking policy name. If not give error and raise Pragma_Exit.
359 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
360 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
361 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
362 -- Check the specified argument Arg to make sure that it is an
363 -- identifier whose name matches either N1 or N2 (or N3 if present).
364 -- If not then give error and raise Pragma_Exit.
366 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
367 -- Check the specified argument Arg to make sure that it is a valid
368 -- queuing policy name. If not give error and raise Pragma_Exit.
370 procedure Check_Arg_Is_Static_Expression
372 Typ : Entity_Id := Empty);
373 -- Check the specified argument Arg to make sure that it is a static
374 -- expression of the given type (i.e. it will be analyzed and resolved
375 -- using this type, which can be any valid argument to Resolve, e.g.
376 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
377 -- Typ is left Empty, then any static expression is allowed.
379 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
380 -- Check the specified argument Arg to make sure that it is a string
381 -- literal. If not give error and raise Pragma_Exit
383 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
384 -- Check the specified argument Arg to make sure that it is a valid task
385 -- dispatching policy name. If not give error and raise Pragma_Exit.
387 procedure Check_Arg_Order (Names : Name_List);
388 -- Checks for an instance of two arguments with identifiers for the
389 -- current pragma which are not in the sequence indicated by Names,
390 -- and if so, generates a fatal message about bad order of arguments.
392 procedure Check_At_Least_N_Arguments (N : Nat);
393 -- Check there are at least N arguments present
395 procedure Check_At_Most_N_Arguments (N : Nat);
396 -- Check there are no more than N arguments present
398 procedure Check_Component (Comp : Node_Id);
399 -- Examine Unchecked_Union component for correct use of per-object
400 -- constrained subtypes, and for restrictions on finalizable components.
402 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
403 -- Nam is an N_String_Literal node containing the external name set by
404 -- an Import or Export pragma (or extended Import or Export pragma).
405 -- This procedure checks for possible duplications if this is the export
406 -- case, and if found, issues an appropriate error message.
408 procedure Check_First_Subtype (Arg : Node_Id);
409 -- Checks that Arg, whose expression is an entity name referencing a
410 -- subtype, does not reference a type that is not a first subtype.
412 procedure Check_In_Main_Program;
413 -- Common checks for pragmas that appear within a main program
414 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
416 procedure Check_Interrupt_Or_Attach_Handler;
417 -- Common processing for first argument of pragma Interrupt_Handler or
418 -- pragma Attach_Handler.
420 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
421 -- Check that pragma appears in a declarative part, or in a package
422 -- specification, i.e. that it does not occur in a statement sequence
425 procedure Check_No_Identifier (Arg : Node_Id);
426 -- Checks that the given argument does not have an identifier. If
427 -- an identifier is present, then an error message is issued, and
428 -- Pragma_Exit is raised.
430 procedure Check_No_Identifiers;
431 -- Checks that none of the arguments to the pragma has an identifier.
432 -- If any argument has an identifier, then an error message is issued,
433 -- and Pragma_Exit is raised.
435 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
436 -- Checks if the given argument has an identifier, and if so, requires
437 -- it to match the given identifier name. If there is a non-matching
438 -- identifier, then an error message is given and Error_Pragmas raised.
440 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
441 -- Checks if the given argument has an identifier, and if so, requires
442 -- it to match the given identifier name. If there is a non-matching
443 -- identifier, then an error message is given and Error_Pragmas raised.
444 -- In this version of the procedure, the identifier name is given as
445 -- a string with lower case letters.
447 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
448 -- Called to process a precondition or postcondition pragma. There are
451 -- The pragma appears after a subprogram spec
453 -- If the corresponding check is not enabled, the pragma is analyzed
454 -- but otherwise ignored and control returns with In_Body set False.
456 -- If the check is enabled, then the first step is to analyze the
457 -- pragma, but this is skipped if the subprogram spec appears within
458 -- a package specification (because this is the case where we delay
459 -- analysis till the end of the spec). Then (whether or not it was
460 -- analyzed), the pragma is chained to the subprogram in question
461 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
462 -- caller with In_Body set False.
464 -- The pragma appears at the start of subprogram body declarations
466 -- In this case an immediate return to the caller is made with
467 -- In_Body set True, and the pragma is NOT analyzed.
469 -- In all other cases, an error message for bad placement is given
471 procedure Check_Static_Constraint (Constr : Node_Id);
472 -- Constr is a constraint from an N_Subtype_Indication node from a
473 -- component constraint in an Unchecked_Union type. This routine checks
474 -- that the constraint is static as required by the restrictions for
477 procedure Check_Valid_Configuration_Pragma;
478 -- Legality checks for placement of a configuration pragma
480 procedure Check_Valid_Library_Unit_Pragma;
481 -- Legality checks for library unit pragmas. A special case arises for
482 -- pragmas in generic instances that come from copies of the original
483 -- library unit pragmas in the generic templates. In the case of other
484 -- than library level instantiations these can appear in contexts which
485 -- would normally be invalid (they only apply to the original template
486 -- and to library level instantiations), and they are simply ignored,
487 -- which is implemented by rewriting them as null statements.
489 procedure Check_Variant (Variant : Node_Id);
490 -- Check Unchecked_Union variant for lack of nested variants and
491 -- presence of at least one component.
493 procedure Error_Pragma (Msg : String);
494 pragma No_Return (Error_Pragma);
495 -- Outputs error message for current pragma. The message contains a %
496 -- that will be replaced with the pragma name, and the flag is placed
497 -- on the pragma itself. Pragma_Exit is then raised.
499 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
500 pragma No_Return (Error_Pragma_Arg);
501 -- Outputs error message for current pragma. The message may contain
502 -- a % that will be replaced with the pragma name. The parameter Arg
503 -- may either be a pragma argument association, in which case the flag
504 -- is placed on the expression of this association, or an expression,
505 -- in which case the flag is placed directly on the expression. The
506 -- message is placed using Error_Msg_N, so the message may also contain
507 -- an & insertion character which will reference the given Arg value.
508 -- After placing the message, Pragma_Exit is raised.
510 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
511 pragma No_Return (Error_Pragma_Arg);
512 -- Similar to above form of Error_Pragma_Arg except that two messages
513 -- are provided, the second is a continuation comment starting with \.
515 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
516 pragma No_Return (Error_Pragma_Arg_Ident);
517 -- Outputs error message for current pragma. The message may contain
518 -- a % that will be replaced with the pragma name. The parameter Arg
519 -- must be a pragma argument association with a non-empty identifier
520 -- (i.e. its Chars field must be set), and the error message is placed
521 -- on the identifier. The message is placed using Error_Msg_N so
522 -- the message may also contain an & insertion character which will
523 -- reference the identifier. After placing the message, Pragma_Exit
526 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
527 pragma No_Return (Error_Pragma_Ref);
528 -- Outputs error message for current pragma. The message may contain
529 -- a % that will be replaced with the pragma name. The parameter Ref
530 -- must be an entity whose name can be referenced by & and sloc by #.
531 -- After placing the message, Pragma_Exit is raised.
533 function Find_Lib_Unit_Name return Entity_Id;
534 -- Used for a library unit pragma to find the entity to which the
535 -- library unit pragma applies, returns the entity found.
537 procedure Find_Program_Unit_Name (Id : Node_Id);
538 -- If the pragma is a compilation unit pragma, the id must denote the
539 -- compilation unit in the same compilation, and the pragma must appear
540 -- in the list of preceding or trailing pragmas. If it is a program
541 -- unit pragma that is not a compilation unit pragma, then the
542 -- identifier must be visible.
544 function Find_Unique_Parameterless_Procedure
546 Arg : Node_Id) return Entity_Id;
547 -- Used for a procedure pragma to find the unique parameterless
548 -- procedure identified by Name, returns it if it exists, otherwise
549 -- errors out and uses Arg as the pragma argument for the message.
551 procedure Gather_Associations
553 Args : out Args_List);
554 -- This procedure is used to gather the arguments for a pragma that
555 -- permits arbitrary ordering of parameters using the normal rules
556 -- for named and positional parameters. The Names argument is a list
557 -- of Name_Id values that corresponds to the allowed pragma argument
558 -- association identifiers in order. The result returned in Args is
559 -- a list of corresponding expressions that are the pragma arguments.
560 -- Note that this is a list of expressions, not of pragma argument
561 -- associations (Gather_Associations has completely checked all the
562 -- optional identifiers when it returns). An entry in Args is Empty
563 -- on return if the corresponding argument is not present.
565 procedure GNAT_Pragma;
566 -- Called for all GNAT defined pragmas to check the relevant restriction
567 -- (No_Implementation_Pragmas).
569 function Is_Before_First_Decl
570 (Pragma_Node : Node_Id;
571 Decls : List_Id) return Boolean;
572 -- Return True if Pragma_Node is before the first declarative item in
573 -- Decls where Decls is the list of declarative items.
575 function Is_Configuration_Pragma return Boolean;
576 -- Determines if the placement of the current pragma is appropriate
577 -- for a configuration pragma.
579 function Is_In_Context_Clause return Boolean;
580 -- Returns True if pragma appears within the context clause of a unit,
581 -- and False for any other placement (does not generate any messages).
583 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
584 -- Analyzes the argument, and determines if it is a static string
585 -- expression, returns True if so, False if non-static or not String.
587 procedure Pragma_Misplaced;
588 pragma No_Return (Pragma_Misplaced);
589 -- Issue fatal error message for misplaced pragma
591 procedure Process_Atomic_Shared_Volatile;
592 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
593 -- Shared is an obsolete Ada 83 pragma, treated as being identical
594 -- in effect to pragma Atomic.
596 procedure Process_Compile_Time_Warning_Or_Error;
597 -- Common processing for Compile_Time_Error and Compile_Time_Warning
599 procedure Process_Convention
600 (C : out Convention_Id; Ent : out Entity_Id);
601 -- Common processing for Convention, Interface, Import and Export.
602 -- Checks first two arguments of pragma, and sets the appropriate
603 -- convention value in the specified entity or entities. On return
604 -- C is the convention, Ent is the referenced entity.
606 procedure Process_Extended_Import_Export_Exception_Pragma
607 (Arg_Internal : Node_Id;
608 Arg_External : Node_Id;
611 -- Common processing for the pragmas Import/Export_Exception. The three
612 -- arguments correspond to the three named parameters of the pragma. An
613 -- argument is empty if the corresponding parameter is not present in
616 procedure Process_Extended_Import_Export_Object_Pragma
617 (Arg_Internal : Node_Id;
618 Arg_External : Node_Id;
620 -- Common processing for the pragmas Import/Export_Object. The three
621 -- arguments correspond to the three named parameters of the pragmas. An
622 -- argument is empty if the corresponding parameter is not present in
625 procedure Process_Extended_Import_Export_Internal_Arg
626 (Arg_Internal : Node_Id := Empty);
627 -- Common processing for all extended Import and Export pragmas. The
628 -- argument is the pragma parameter for the Internal argument. If
629 -- Arg_Internal is empty or inappropriate, an error message is posted.
630 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
631 -- set to identify the referenced entity.
633 procedure Process_Extended_Import_Export_Subprogram_Pragma
634 (Arg_Internal : Node_Id;
635 Arg_External : Node_Id;
636 Arg_Parameter_Types : Node_Id;
637 Arg_Result_Type : Node_Id := Empty;
638 Arg_Mechanism : Node_Id;
639 Arg_Result_Mechanism : Node_Id := Empty;
640 Arg_First_Optional_Parameter : Node_Id := Empty);
641 -- Common processing for all extended Import and Export pragmas applying
642 -- to subprograms. The caller omits any arguments that do not apply to
643 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
644 -- only in the Import_Function and Export_Function cases). The argument
645 -- names correspond to the allowed pragma association identifiers.
647 procedure Process_Generic_List;
648 -- Common processing for Share_Generic and Inline_Generic
650 procedure Process_Import_Or_Interface;
651 -- Common processing for Import of Interface
653 procedure Process_Inline (Active : Boolean);
654 -- Common processing for Inline and Inline_Always. The parameter
655 -- indicates if the inline pragma is active, i.e. if it should actually
656 -- cause inlining to occur.
658 procedure Process_Interface_Name
659 (Subprogram_Def : Entity_Id;
662 -- Given the last two arguments of pragma Import, pragma Export, or
663 -- pragma Interface_Name, performs validity checks and sets the
664 -- Interface_Name field of the given subprogram entity to the
665 -- appropriate external or link name, depending on the arguments given.
666 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
667 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
668 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
669 -- nor Link_Arg is present, the interface name is set to the default
670 -- from the subprogram name.
672 procedure Process_Interrupt_Or_Attach_Handler;
673 -- Common processing for Interrupt and Attach_Handler pragmas
675 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
676 -- Common processing for Restrictions and Restriction_Warnings pragmas.
677 -- Warn is True for Restriction_Warnings, or for Restrictions if the
678 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
679 -- is not set in the Restrictions case.
681 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
682 -- Common processing for Suppress and Unsuppress. The boolean parameter
683 -- Suppress_Case is True for the Suppress case, and False for the
686 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
687 -- This procedure sets the Is_Exported flag for the given entity,
688 -- checking that the entity was not previously imported. Arg is
689 -- the argument that specified the entity. A check is also made
690 -- for exporting inappropriate entities.
692 procedure Set_Extended_Import_Export_External_Name
693 (Internal_Ent : Entity_Id;
694 Arg_External : Node_Id);
695 -- Common processing for all extended import export pragmas. The first
696 -- argument, Internal_Ent, is the internal entity, which has already
697 -- been checked for validity by the caller. Arg_External is from the
698 -- Import or Export pragma, and may be null if no External parameter
699 -- was present. If Arg_External is present and is a non-null string
700 -- (a null string is treated as the default), then the Interface_Name
701 -- field of Internal_Ent is set appropriately.
703 procedure Set_Imported (E : Entity_Id);
704 -- This procedure sets the Is_Imported flag for the given entity,
705 -- checking that it is not previously exported or imported.
707 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
708 -- Mech is a parameter passing mechanism (see Import_Function syntax
709 -- for MECHANISM_NAME). This routine checks that the mechanism argument
710 -- has the right form, and if not issues an error message. If the
711 -- argument has the right form then the Mechanism field of Ent is
712 -- set appropriately.
714 procedure Set_Ravenscar_Profile (N : Node_Id);
715 -- Activate the set of configuration pragmas and restrictions that make
716 -- up the Ravenscar Profile. N is the corresponding pragma node, which
717 -- is used for error messages on any constructs that violate the
720 ---------------------
721 -- Ada_2005_Pragma --
722 ---------------------
724 procedure Ada_2005_Pragma is
726 if Ada_Version <= Ada_95 then
727 Check_Restriction (No_Implementation_Pragmas, N);
731 --------------------------
732 -- Check_Ada_83_Warning --
733 --------------------------
735 procedure Check_Ada_83_Warning is
737 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
738 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
740 end Check_Ada_83_Warning;
742 ---------------------
743 -- Check_Arg_Count --
744 ---------------------
746 procedure Check_Arg_Count (Required : Nat) is
748 if Arg_Count /= Required then
749 Error_Pragma ("wrong number of arguments for pragma%");
753 --------------------------------
754 -- Check_Arg_Is_External_Name --
755 --------------------------------
757 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
758 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
761 if Nkind (Argx) = N_Identifier then
765 Analyze_And_Resolve (Argx, Standard_String);
767 if Is_OK_Static_Expression (Argx) then
770 elsif Etype (Argx) = Any_Type then
773 -- An interesting special case, if we have a string literal and
774 -- we are in Ada 83 mode, then we allow it even though it will
775 -- not be flagged as static. This allows expected Ada 83 mode
776 -- use of external names which are string literals, even though
777 -- technically these are not static in Ada 83.
779 elsif Ada_Version = Ada_83
780 and then Nkind (Argx) = N_String_Literal
784 -- Static expression that raises Constraint_Error. This has
785 -- already been flagged, so just exit from pragma processing.
787 elsif Is_Static_Expression (Argx) then
790 -- Here we have a real error (non-static expression)
793 Error_Msg_Name_1 := Pname;
795 ("argument for pragma% must be a identifier or " &
796 "static string expression!", Argx);
800 end Check_Arg_Is_External_Name;
802 -----------------------------
803 -- Check_Arg_Is_Identifier --
804 -----------------------------
806 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
807 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
809 if Nkind (Argx) /= N_Identifier then
811 ("argument for pragma% must be identifier", Argx);
813 end Check_Arg_Is_Identifier;
815 ----------------------------------
816 -- Check_Arg_Is_Integer_Literal --
817 ----------------------------------
819 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
820 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
822 if Nkind (Argx) /= N_Integer_Literal then
824 ("argument for pragma% must be integer literal", Argx);
826 end Check_Arg_Is_Integer_Literal;
828 -------------------------------------------
829 -- Check_Arg_Is_Library_Level_Local_Name --
830 -------------------------------------------
834 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
835 -- | library_unit_NAME
837 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
839 Check_Arg_Is_Local_Name (Arg);
841 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
842 and then Comes_From_Source (N)
845 ("argument for pragma% must be library level entity", Arg);
847 end Check_Arg_Is_Library_Level_Local_Name;
849 -----------------------------
850 -- Check_Arg_Is_Local_Name --
851 -----------------------------
855 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
856 -- | library_unit_NAME
858 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
859 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
864 if Nkind (Argx) not in N_Direct_Name
865 and then (Nkind (Argx) /= N_Attribute_Reference
866 or else Present (Expressions (Argx))
867 or else Nkind (Prefix (Argx)) /= N_Identifier)
868 and then (not Is_Entity_Name (Argx)
869 or else not Is_Compilation_Unit (Entity (Argx)))
871 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
874 if Is_Entity_Name (Argx)
875 and then Scope (Entity (Argx)) /= Current_Scope
878 ("pragma% argument must be in same declarative part", Arg);
880 end Check_Arg_Is_Local_Name;
882 ---------------------------------
883 -- Check_Arg_Is_Locking_Policy --
884 ---------------------------------
886 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
887 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
890 Check_Arg_Is_Identifier (Argx);
892 if not Is_Locking_Policy_Name (Chars (Argx)) then
894 ("& is not a valid locking policy name", Argx);
896 end Check_Arg_Is_Locking_Policy;
898 -------------------------
899 -- Check_Arg_Is_One_Of --
900 -------------------------
902 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
903 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
906 Check_Arg_Is_Identifier (Argx);
908 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
909 Error_Msg_Name_2 := N1;
910 Error_Msg_Name_3 := N2;
911 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
913 end Check_Arg_Is_One_Of;
915 procedure Check_Arg_Is_One_Of
917 N1, N2, N3 : Name_Id)
919 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
922 Check_Arg_Is_Identifier (Argx);
924 if Chars (Argx) /= N1
925 and then Chars (Argx) /= N2
926 and then Chars (Argx) /= N3
928 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
930 end Check_Arg_Is_One_Of;
932 procedure Check_Arg_Is_One_Of
934 N1, N2, N3, N4 : Name_Id)
936 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
939 Check_Arg_Is_Identifier (Argx);
941 if Chars (Argx) /= N1
942 and then Chars (Argx) /= N2
943 and then Chars (Argx) /= N3
944 and then Chars (Argx) /= N4
946 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
948 end Check_Arg_Is_One_Of;
950 ---------------------------------
951 -- Check_Arg_Is_Queuing_Policy --
952 ---------------------------------
954 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
955 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
958 Check_Arg_Is_Identifier (Argx);
960 if not Is_Queuing_Policy_Name (Chars (Argx)) then
962 ("& is not a valid queuing policy name", Argx);
964 end Check_Arg_Is_Queuing_Policy;
966 ------------------------------------
967 -- Check_Arg_Is_Static_Expression --
968 ------------------------------------
970 procedure Check_Arg_Is_Static_Expression
972 Typ : Entity_Id := Empty)
974 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
977 if Present (Typ) then
978 Analyze_And_Resolve (Argx, Typ);
980 Analyze_And_Resolve (Argx);
983 if Is_OK_Static_Expression (Argx) then
986 elsif Etype (Argx) = Any_Type then
989 -- An interesting special case, if we have a string literal and we
990 -- are in Ada 83 mode, then we allow it even though it will not be
991 -- flagged as static. This allows the use of Ada 95 pragmas like
992 -- Import in Ada 83 mode. They will of course be flagged with
993 -- warnings as usual, but will not cause errors.
995 elsif Ada_Version = Ada_83
996 and then Nkind (Argx) = N_String_Literal
1000 -- Static expression that raises Constraint_Error. This has already
1001 -- been flagged, so just exit from pragma processing.
1003 elsif Is_Static_Expression (Argx) then
1006 -- Finally, we have a real error
1009 Error_Msg_Name_1 := Pname;
1010 Flag_Non_Static_Expr
1011 ("argument for pragma% must be a static expression!", Argx);
1014 end Check_Arg_Is_Static_Expression;
1016 ---------------------------------
1017 -- Check_Arg_Is_String_Literal --
1018 ---------------------------------
1020 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1021 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1023 if Nkind (Argx) /= N_String_Literal then
1025 ("argument for pragma% must be string literal", Argx);
1027 end Check_Arg_Is_String_Literal;
1029 ------------------------------------------
1030 -- Check_Arg_Is_Task_Dispatching_Policy --
1031 ------------------------------------------
1033 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1034 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1037 Check_Arg_Is_Identifier (Argx);
1039 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1041 ("& is not a valid task dispatching policy name", Argx);
1043 end Check_Arg_Is_Task_Dispatching_Policy;
1045 ---------------------
1046 -- Check_Arg_Order --
1047 ---------------------
1049 procedure Check_Arg_Order (Names : Name_List) is
1052 Highest_So_Far : Natural := 0;
1053 -- Highest index in Names seen do far
1057 for J in 1 .. Arg_Count loop
1058 if Chars (Arg) /= No_Name then
1059 for K in Names'Range loop
1060 if Chars (Arg) = Names (K) then
1061 if K < Highest_So_Far then
1062 Error_Msg_Name_1 := Pname;
1064 ("parameters out of order for pragma%", Arg);
1065 Error_Msg_Name_1 := Names (K);
1066 Error_Msg_Name_2 := Names (Highest_So_Far);
1067 Error_Msg_N ("\% must appear before %", Arg);
1071 Highest_So_Far := K;
1079 end Check_Arg_Order;
1081 --------------------------------
1082 -- Check_At_Least_N_Arguments --
1083 --------------------------------
1085 procedure Check_At_Least_N_Arguments (N : Nat) is
1087 if Arg_Count < N then
1088 Error_Pragma ("too few arguments for pragma%");
1090 end Check_At_Least_N_Arguments;
1092 -------------------------------
1093 -- Check_At_Most_N_Arguments --
1094 -------------------------------
1096 procedure Check_At_Most_N_Arguments (N : Nat) is
1099 if Arg_Count > N then
1101 for J in 1 .. N loop
1103 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1106 end Check_At_Most_N_Arguments;
1108 ---------------------
1109 -- Check_Component --
1110 ---------------------
1112 procedure Check_Component (Comp : Node_Id) is
1114 if Nkind (Comp) = N_Component_Declaration then
1116 Sindic : constant Node_Id :=
1117 Subtype_Indication (Component_Definition (Comp));
1118 Typ : constant Entity_Id :=
1119 Etype (Defining_Identifier (Comp));
1121 if Nkind (Sindic) = N_Subtype_Indication then
1123 -- Ada 2005 (AI-216): If a component subtype is subject to
1124 -- a per-object constraint, then the component type shall
1125 -- be an Unchecked_Union.
1127 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1129 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1131 Error_Msg_N ("component subtype subject to per-object" &
1132 " constraint must be an Unchecked_Union", Comp);
1136 if Is_Controlled (Typ) then
1138 ("component of unchecked union cannot be controlled", Comp);
1140 elsif Has_Task (Typ) then
1142 ("component of unchecked union cannot have tasks", Comp);
1146 end Check_Component;
1148 ----------------------------------
1149 -- Check_Duplicated_Export_Name --
1150 ----------------------------------
1152 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1153 String_Val : constant String_Id := Strval (Nam);
1156 -- We are only interested in the export case, and in the case of
1157 -- generics, it is the instance, not the template, that is the
1158 -- problem (the template will generate a warning in any case).
1160 if not Inside_A_Generic
1161 and then (Prag_Id = Pragma_Export
1163 Prag_Id = Pragma_Export_Procedure
1165 Prag_Id = Pragma_Export_Valued_Procedure
1167 Prag_Id = Pragma_Export_Function)
1169 for J in Externals.First .. Externals.Last loop
1170 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1171 Error_Msg_Sloc := Sloc (Externals.Table (J));
1172 Error_Msg_N ("external name duplicates name given#", Nam);
1177 Externals.Append (Nam);
1179 end Check_Duplicated_Export_Name;
1181 -------------------------
1182 -- Check_First_Subtype --
1183 -------------------------
1185 procedure Check_First_Subtype (Arg : Node_Id) is
1186 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1188 if not Is_First_Subtype (Entity (Argx)) then
1190 ("pragma% cannot apply to subtype", Argx);
1192 end Check_First_Subtype;
1194 ---------------------------
1195 -- Check_In_Main_Program --
1196 ---------------------------
1198 procedure Check_In_Main_Program is
1199 P : constant Node_Id := Parent (N);
1202 -- Must be at in subprogram body
1204 if Nkind (P) /= N_Subprogram_Body then
1205 Error_Pragma ("% pragma allowed only in subprogram");
1207 -- Otherwise warn if obviously not main program
1209 elsif Present (Parameter_Specifications (Specification (P)))
1210 or else not Is_Compilation_Unit (Defining_Entity (P))
1212 Error_Msg_Name_1 := Pname;
1214 ("?pragma% is only effective in main program", N);
1216 end Check_In_Main_Program;
1218 ---------------------------------------
1219 -- Check_Interrupt_Or_Attach_Handler --
1220 ---------------------------------------
1222 procedure Check_Interrupt_Or_Attach_Handler is
1223 Arg1_X : constant Node_Id := Expression (Arg1);
1224 Handler_Proc, Proc_Scope : Entity_Id;
1229 if Prag_Id = Pragma_Interrupt_Handler then
1230 Check_Restriction (No_Dynamic_Attachment, N);
1233 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1234 Proc_Scope := Scope (Handler_Proc);
1236 -- On AAMP only, a pragma Interrupt_Handler is supported for
1237 -- nonprotected parameterless procedures.
1239 if not AAMP_On_Target
1240 or else Prag_Id = Pragma_Attach_Handler
1242 if Ekind (Proc_Scope) /= E_Protected_Type then
1244 ("argument of pragma% must be protected procedure", Arg1);
1247 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1248 Error_Pragma ("pragma% must be in protected definition");
1252 if not Is_Library_Level_Entity (Proc_Scope)
1253 or else (AAMP_On_Target
1254 and then not Is_Library_Level_Entity (Handler_Proc))
1257 ("argument for pragma% must be library level entity", Arg1);
1259 end Check_Interrupt_Or_Attach_Handler;
1261 -------------------------------------------
1262 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1263 -------------------------------------------
1265 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1274 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1277 elsif Nkind_In (P, N_Package_Specification,
1282 -- Note: the following tests seem a little peculiar, because
1283 -- they test for bodies, but if we were in the statement part
1284 -- of the body, we would already have hit the handled statement
1285 -- sequence, so the only way we get here is by being in the
1286 -- declarative part of the body.
1288 elsif Nkind_In (P, N_Subprogram_Body,
1299 Error_Pragma ("pragma% is not in declarative part or package spec");
1300 end Check_Is_In_Decl_Part_Or_Package_Spec;
1302 -------------------------
1303 -- Check_No_Identifier --
1304 -------------------------
1306 procedure Check_No_Identifier (Arg : Node_Id) is
1308 if Chars (Arg) /= No_Name then
1309 Error_Pragma_Arg_Ident
1310 ("pragma% does not permit identifier& here", Arg);
1312 end Check_No_Identifier;
1314 --------------------------
1315 -- Check_No_Identifiers --
1316 --------------------------
1318 procedure Check_No_Identifiers is
1321 if Arg_Count > 0 then
1323 while Present (Arg_Node) loop
1324 Check_No_Identifier (Arg_Node);
1328 end Check_No_Identifiers;
1330 -------------------------------
1331 -- Check_Optional_Identifier --
1332 -------------------------------
1334 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1336 if Present (Arg) and then Chars (Arg) /= No_Name then
1337 if Chars (Arg) /= Id then
1338 Error_Msg_Name_1 := Pname;
1339 Error_Msg_Name_2 := Id;
1340 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1344 end Check_Optional_Identifier;
1346 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1348 Name_Buffer (1 .. Id'Length) := Id;
1349 Name_Len := Id'Length;
1350 Check_Optional_Identifier (Arg, Name_Find);
1351 end Check_Optional_Identifier;
1353 --------------------------------------
1354 -- Check_Precondition_Postcondition --
1355 --------------------------------------
1357 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1361 procedure Chain_PPC (PO : Node_Id);
1362 -- If PO is a subprogram declaration node (or a generic subprogram
1363 -- declaration node), then the precondition/postcondition applies
1364 -- to this subprogram and the processing for the pragma is completed.
1365 -- Otherwise the pragma is misplaced.
1371 procedure Chain_PPC (PO : Node_Id) is
1375 if not Nkind_In (PO, N_Subprogram_Declaration,
1376 N_Generic_Subprogram_Declaration)
1381 -- Here if we have subprogram or generic subprogram declaration
1383 S := Defining_Unit_Name (Specification (PO));
1385 -- Analyze the pragma unless it appears within a package spec,
1386 -- which is the case where we delay the analysis of the PPC until
1387 -- the end of the package declarations (for details, see
1388 -- Analyze_Package_Specification.Analyze_PPCs).
1390 if not Is_Package_Or_Generic_Package (Scope (S)) then
1391 Analyze_PPC_In_Decl_Part (N, S);
1394 -- Chain spec PPC pragma to list for subprogram
1396 Set_Next_Pragma (N, Spec_PPC_List (S));
1397 Set_Spec_PPC_List (S, N);
1399 -- Return indicating spec case
1405 -- Start of processing for Check_Precondition_Postcondition
1408 if not Is_List_Member (N) then
1412 -- Record whether pragma is enabled
1414 Set_PPC_Enabled (N, Check_Enabled (Pname));
1416 -- If we are within an inlined body, the legality of the pragma
1417 -- has been checked already.
1419 if In_Inlined_Body then
1424 -- Search prior declarations
1427 while Present (Prev (P)) loop
1430 -- If the previous node is a generic subprogram, do not go to to
1431 -- the original node, which is the unanalyzed tree: we need to
1432 -- attach the pre/postconditions to the analyzed version at this
1433 -- point. They get propagated to the original tree when analyzing
1434 -- the corresponding body.
1436 if Nkind (P) not in N_Generic_Declaration then
1437 PO := Original_Node (P);
1442 -- Skip past prior pragma
1444 if Nkind (PO) = N_Pragma then
1447 -- Skip stuff not coming from source
1449 elsif not Comes_From_Source (PO) then
1452 -- Only remaining possibility is subprogram declaration
1460 -- If we fall through loop, pragma is at start of list, so see if it
1461 -- is at the start of declarations of a subprogram body.
1463 if Nkind (Parent (N)) = N_Subprogram_Body
1464 and then List_Containing (N) = Declarations (Parent (N))
1466 if Operating_Mode /= Generate_Code
1467 or else Inside_A_Generic
1470 -- Analyze expression in pragma, for correctness
1471 -- and for ASIS use.
1473 Preanalyze_Spec_Expression
1474 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1480 -- See if it is in the pragmas after a library level subprogram
1482 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1483 Chain_PPC (Unit (Parent (Parent (N))));
1487 -- If we fall through, pragma was misplaced
1490 end Check_Precondition_Postcondition;
1492 -----------------------------
1493 -- Check_Static_Constraint --
1494 -----------------------------
1496 -- Note: for convenience in writing this procedure, in addition to
1497 -- the officially (i.e. by spec) allowed argument which is always a
1498 -- constraint, it also allows ranges and discriminant associations.
1499 -- Above is not clear ???
1501 procedure Check_Static_Constraint (Constr : Node_Id) is
1503 procedure Require_Static (E : Node_Id);
1504 -- Require given expression to be static expression
1506 --------------------
1507 -- Require_Static --
1508 --------------------
1510 procedure Require_Static (E : Node_Id) is
1512 if not Is_OK_Static_Expression (E) then
1513 Flag_Non_Static_Expr
1514 ("non-static constraint not allowed in Unchecked_Union!", E);
1519 -- Start of processing for Check_Static_Constraint
1522 case Nkind (Constr) is
1523 when N_Discriminant_Association =>
1524 Require_Static (Expression (Constr));
1527 Require_Static (Low_Bound (Constr));
1528 Require_Static (High_Bound (Constr));
1530 when N_Attribute_Reference =>
1531 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1532 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1534 when N_Range_Constraint =>
1535 Check_Static_Constraint (Range_Expression (Constr));
1537 when N_Index_Or_Discriminant_Constraint =>
1541 IDC := First (Constraints (Constr));
1542 while Present (IDC) loop
1543 Check_Static_Constraint (IDC);
1551 end Check_Static_Constraint;
1553 --------------------------------------
1554 -- Check_Valid_Configuration_Pragma --
1555 --------------------------------------
1557 -- A configuration pragma must appear in the context clause of a
1558 -- compilation unit, and only other pragmas may precede it. Note that
1559 -- the test also allows use in a configuration pragma file.
1561 procedure Check_Valid_Configuration_Pragma is
1563 if not Is_Configuration_Pragma then
1564 Error_Pragma ("incorrect placement for configuration pragma%");
1566 end Check_Valid_Configuration_Pragma;
1568 -------------------------------------
1569 -- Check_Valid_Library_Unit_Pragma --
1570 -------------------------------------
1572 procedure Check_Valid_Library_Unit_Pragma is
1574 Parent_Node : Node_Id;
1575 Unit_Name : Entity_Id;
1576 Unit_Kind : Node_Kind;
1577 Unit_Node : Node_Id;
1578 Sindex : Source_File_Index;
1581 if not Is_List_Member (N) then
1585 Plist := List_Containing (N);
1586 Parent_Node := Parent (Plist);
1588 if Parent_Node = Empty then
1591 -- Case of pragma appearing after a compilation unit. In this case
1592 -- it must have an argument with the corresponding name and must
1593 -- be part of the following pragmas of its parent.
1595 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1596 if Plist /= Pragmas_After (Parent_Node) then
1599 elsif Arg_Count = 0 then
1601 ("argument required if outside compilation unit");
1604 Check_No_Identifiers;
1605 Check_Arg_Count (1);
1606 Unit_Node := Unit (Parent (Parent_Node));
1607 Unit_Kind := Nkind (Unit_Node);
1609 Analyze (Expression (Arg1));
1611 if Unit_Kind = N_Generic_Subprogram_Declaration
1612 or else Unit_Kind = N_Subprogram_Declaration
1614 Unit_Name := Defining_Entity (Unit_Node);
1616 elsif Unit_Kind in N_Generic_Instantiation then
1617 Unit_Name := Defining_Entity (Unit_Node);
1620 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1623 if Chars (Unit_Name) /=
1624 Chars (Entity (Expression (Arg1)))
1627 ("pragma% argument is not current unit name", Arg1);
1630 if Ekind (Unit_Name) = E_Package
1631 and then Present (Renamed_Entity (Unit_Name))
1633 Error_Pragma ("pragma% not allowed for renamed package");
1637 -- Pragma appears other than after a compilation unit
1640 -- Here we check for the generic instantiation case and also
1641 -- for the case of processing a generic formal package. We
1642 -- detect these cases by noting that the Sloc on the node
1643 -- does not belong to the current compilation unit.
1645 Sindex := Source_Index (Current_Sem_Unit);
1647 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1648 Rewrite (N, Make_Null_Statement (Loc));
1651 -- If before first declaration, the pragma applies to the
1652 -- enclosing unit, and the name if present must be this name.
1654 elsif Is_Before_First_Decl (N, Plist) then
1655 Unit_Node := Unit_Declaration_Node (Current_Scope);
1656 Unit_Kind := Nkind (Unit_Node);
1658 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1661 elsif Unit_Kind = N_Subprogram_Body
1662 and then not Acts_As_Spec (Unit_Node)
1666 elsif Nkind (Parent_Node) = N_Package_Body then
1669 elsif Nkind (Parent_Node) = N_Package_Specification
1670 and then Plist = Private_Declarations (Parent_Node)
1674 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1675 or else Nkind (Parent_Node) =
1676 N_Generic_Subprogram_Declaration)
1677 and then Plist = Generic_Formal_Declarations (Parent_Node)
1681 elsif Arg_Count > 0 then
1682 Analyze (Expression (Arg1));
1684 if Entity (Expression (Arg1)) /= Current_Scope then
1686 ("name in pragma% must be enclosing unit", Arg1);
1689 -- It is legal to have no argument in this context
1695 -- Error if not before first declaration. This is because a
1696 -- library unit pragma argument must be the name of a library
1697 -- unit (RM 10.1.5(7)), but the only names permitted in this
1698 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1699 -- generic subprogram declarations or generic instantiations.
1703 ("pragma% misplaced, must be before first declaration");
1707 end Check_Valid_Library_Unit_Pragma;
1713 procedure Check_Variant (Variant : Node_Id) is
1714 Clist : constant Node_Id := Component_List (Variant);
1718 if not Is_Non_Empty_List (Component_Items (Clist)) then
1720 ("Unchecked_Union may not have empty component list",
1725 Comp := First (Component_Items (Clist));
1726 while Present (Comp) loop
1727 Check_Component (Comp);
1736 procedure Error_Pragma (Msg : String) is
1738 Error_Msg_Name_1 := Pname;
1739 Error_Msg_N (Msg, N);
1743 ----------------------
1744 -- Error_Pragma_Arg --
1745 ----------------------
1747 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1749 Error_Msg_Name_1 := Pname;
1750 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1752 end Error_Pragma_Arg;
1754 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1756 Error_Msg_Name_1 := Pname;
1757 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1758 Error_Pragma_Arg (Msg2, Arg);
1759 end Error_Pragma_Arg;
1761 ----------------------------
1762 -- Error_Pragma_Arg_Ident --
1763 ----------------------------
1765 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1767 Error_Msg_Name_1 := Pname;
1768 Error_Msg_N (Msg, Arg);
1770 end Error_Pragma_Arg_Ident;
1772 ----------------------
1773 -- Error_Pragma_Ref --
1774 ----------------------
1776 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1778 Error_Msg_Name_1 := Pname;
1779 Error_Msg_Sloc := Sloc (Ref);
1780 Error_Msg_NE (Msg, N, Ref);
1782 end Error_Pragma_Ref;
1784 ------------------------
1785 -- Find_Lib_Unit_Name --
1786 ------------------------
1788 function Find_Lib_Unit_Name return Entity_Id is
1790 -- Return inner compilation unit entity, for case of nested
1791 -- categorization pragmas. This happens in generic unit.
1793 if Nkind (Parent (N)) = N_Package_Specification
1794 and then Defining_Entity (Parent (N)) /= Current_Scope
1796 return Defining_Entity (Parent (N));
1798 return Current_Scope;
1800 end Find_Lib_Unit_Name;
1802 ----------------------------
1803 -- Find_Program_Unit_Name --
1804 ----------------------------
1806 procedure Find_Program_Unit_Name (Id : Node_Id) is
1807 Unit_Name : Entity_Id;
1808 Unit_Kind : Node_Kind;
1809 P : constant Node_Id := Parent (N);
1812 if Nkind (P) = N_Compilation_Unit then
1813 Unit_Kind := Nkind (Unit (P));
1815 if Unit_Kind = N_Subprogram_Declaration
1816 or else Unit_Kind = N_Package_Declaration
1817 or else Unit_Kind in N_Generic_Declaration
1819 Unit_Name := Defining_Entity (Unit (P));
1821 if Chars (Id) = Chars (Unit_Name) then
1822 Set_Entity (Id, Unit_Name);
1823 Set_Etype (Id, Etype (Unit_Name));
1825 Set_Etype (Id, Any_Type);
1827 ("cannot find program unit referenced by pragma%");
1831 Set_Etype (Id, Any_Type);
1832 Error_Pragma ("pragma% inapplicable to this unit");
1838 end Find_Program_Unit_Name;
1840 -----------------------------------------
1841 -- Find_Unique_Parameterless_Procedure --
1842 -----------------------------------------
1844 function Find_Unique_Parameterless_Procedure
1846 Arg : Node_Id) return Entity_Id
1848 Proc : Entity_Id := Empty;
1851 -- The body of this procedure needs some comments ???
1853 if not Is_Entity_Name (Name) then
1855 ("argument of pragma% must be entity name", Arg);
1857 elsif not Is_Overloaded (Name) then
1858 Proc := Entity (Name);
1860 if Ekind (Proc) /= E_Procedure
1861 or else Present (First_Formal (Proc)) then
1863 ("argument of pragma% must be parameterless procedure", Arg);
1868 Found : Boolean := False;
1870 Index : Interp_Index;
1873 Get_First_Interp (Name, Index, It);
1874 while Present (It.Nam) loop
1877 if Ekind (Proc) = E_Procedure
1878 and then No (First_Formal (Proc))
1882 Set_Entity (Name, Proc);
1883 Set_Is_Overloaded (Name, False);
1886 ("ambiguous handler name for pragma% ", Arg);
1890 Get_Next_Interp (Index, It);
1895 ("argument of pragma% must be parameterless procedure",
1898 Proc := Entity (Name);
1904 end Find_Unique_Parameterless_Procedure;
1906 -------------------------
1907 -- Gather_Associations --
1908 -------------------------
1910 procedure Gather_Associations
1912 Args : out Args_List)
1917 -- Initialize all parameters to Empty
1919 for J in Args'Range loop
1923 -- That's all we have to do if there are no argument associations
1925 if No (Pragma_Argument_Associations (N)) then
1929 -- Otherwise first deal with any positional parameters present
1931 Arg := First (Pragma_Argument_Associations (N));
1932 for Index in Args'Range loop
1933 exit when No (Arg) or else Chars (Arg) /= No_Name;
1934 Args (Index) := Expression (Arg);
1938 -- Positional parameters all processed, if any left, then we
1939 -- have too many positional parameters.
1941 if Present (Arg) and then Chars (Arg) = No_Name then
1943 ("too many positional associations for pragma%", Arg);
1946 -- Process named parameters if any are present
1948 while Present (Arg) loop
1949 if Chars (Arg) = No_Name then
1951 ("positional association cannot follow named association",
1955 for Index in Names'Range loop
1956 if Names (Index) = Chars (Arg) then
1957 if Present (Args (Index)) then
1959 ("duplicate argument association for pragma%", Arg);
1961 Args (Index) := Expression (Arg);
1966 if Index = Names'Last then
1967 Error_Msg_Name_1 := Pname;
1968 Error_Msg_N ("pragma% does not allow & argument", Arg);
1970 -- Check for possible misspelling
1972 for Index1 in Names'Range loop
1973 if Is_Bad_Spelling_Of
1974 (Chars (Arg), Names (Index1))
1976 Error_Msg_Name_1 := Names (Index1);
1977 Error_Msg_N -- CODEFIX
1978 ("\possible misspelling of%", Arg);
1990 end Gather_Associations;
1996 procedure GNAT_Pragma is
1998 Check_Restriction (No_Implementation_Pragmas, N);
2001 --------------------------
2002 -- Is_Before_First_Decl --
2003 --------------------------
2005 function Is_Before_First_Decl
2006 (Pragma_Node : Node_Id;
2007 Decls : List_Id) return Boolean
2009 Item : Node_Id := First (Decls);
2012 -- Only other pragmas can come before this pragma
2015 if No (Item) or else Nkind (Item) /= N_Pragma then
2018 elsif Item = Pragma_Node then
2024 end Is_Before_First_Decl;
2026 -----------------------------
2027 -- Is_Configuration_Pragma --
2028 -----------------------------
2030 -- A configuration pragma must appear in the context clause of a
2031 -- compilation unit, and only other pragmas may precede it. Note that
2032 -- the test below also permits use in a configuration pragma file.
2034 function Is_Configuration_Pragma return Boolean is
2035 Lis : constant List_Id := List_Containing (N);
2036 Par : constant Node_Id := Parent (N);
2040 -- If no parent, then we are in the configuration pragma file,
2041 -- so the placement is definitely appropriate.
2046 -- Otherwise we must be in the context clause of a compilation unit
2047 -- and the only thing allowed before us in the context list is more
2048 -- configuration pragmas.
2050 elsif Nkind (Par) = N_Compilation_Unit
2051 and then Context_Items (Par) = Lis
2058 elsif Nkind (Prg) /= N_Pragma then
2068 end Is_Configuration_Pragma;
2070 --------------------------
2071 -- Is_In_Context_Clause --
2072 --------------------------
2074 function Is_In_Context_Clause return Boolean is
2076 Parent_Node : Node_Id;
2079 if not Is_List_Member (N) then
2083 Plist := List_Containing (N);
2084 Parent_Node := Parent (Plist);
2086 if Parent_Node = Empty
2087 or else Nkind (Parent_Node) /= N_Compilation_Unit
2088 or else Context_Items (Parent_Node) /= Plist
2095 end Is_In_Context_Clause;
2097 ---------------------------------
2098 -- Is_Static_String_Expression --
2099 ---------------------------------
2101 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2102 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2105 Analyze_And_Resolve (Argx);
2106 return Is_OK_Static_Expression (Argx)
2107 and then Nkind (Argx) = N_String_Literal;
2108 end Is_Static_String_Expression;
2110 ----------------------
2111 -- Pragma_Misplaced --
2112 ----------------------
2114 procedure Pragma_Misplaced is
2116 Error_Pragma ("incorrect placement of pragma%");
2117 end Pragma_Misplaced;
2119 ------------------------------------
2120 -- Process Atomic_Shared_Volatile --
2121 ------------------------------------
2123 procedure Process_Atomic_Shared_Volatile is
2130 procedure Set_Atomic (E : Entity_Id);
2131 -- Set given type as atomic, and if no explicit alignment was given,
2132 -- set alignment to unknown, since back end knows what the alignment
2133 -- requirements are for atomic arrays. Note: this step is necessary
2134 -- for derived types.
2140 procedure Set_Atomic (E : Entity_Id) is
2144 if not Has_Alignment_Clause (E) then
2145 Set_Alignment (E, Uint_0);
2149 -- Start of processing for Process_Atomic_Shared_Volatile
2152 Check_Ada_83_Warning;
2153 Check_No_Identifiers;
2154 Check_Arg_Count (1);
2155 Check_Arg_Is_Local_Name (Arg1);
2156 E_Id := Expression (Arg1);
2158 if Etype (E_Id) = Any_Type then
2163 D := Declaration_Node (E);
2167 if Rep_Item_Too_Early (E, N)
2169 Rep_Item_Too_Late (E, N)
2173 Check_First_Subtype (Arg1);
2176 if Prag_Id /= Pragma_Volatile then
2178 Set_Atomic (Underlying_Type (E));
2179 Set_Atomic (Base_Type (E));
2182 -- Attribute belongs on the base type. If the view of the type is
2183 -- currently private, it also belongs on the underlying type.
2185 Set_Is_Volatile (Base_Type (E));
2186 Set_Is_Volatile (Underlying_Type (E));
2188 Set_Treat_As_Volatile (E);
2189 Set_Treat_As_Volatile (Underlying_Type (E));
2191 elsif K = N_Object_Declaration
2192 or else (K = N_Component_Declaration
2193 and then Original_Record_Component (E) = E)
2195 if Rep_Item_Too_Late (E, N) then
2199 if Prag_Id /= Pragma_Volatile then
2202 -- If the object declaration has an explicit initialization, a
2203 -- temporary may have to be created to hold the expression, to
2204 -- ensure that access to the object remain atomic.
2206 if Nkind (Parent (E)) = N_Object_Declaration
2207 and then Present (Expression (Parent (E)))
2209 Set_Has_Delayed_Freeze (E);
2212 -- An interesting improvement here. If an object of type X is
2213 -- declared atomic, and the type X is not atomic, that's a
2214 -- pity, since it may not have appropriate alignment etc. We
2215 -- can rescue this in the special case where the object and
2216 -- type are in the same unit by just setting the type as
2217 -- atomic, so that the back end will process it as atomic.
2219 Utyp := Underlying_Type (Etype (E));
2222 and then Sloc (E) > No_Location
2223 and then Sloc (Utyp) > No_Location
2225 Get_Source_File_Index (Sloc (E)) =
2226 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2228 Set_Is_Atomic (Underlying_Type (Etype (E)));
2232 Set_Is_Volatile (E);
2233 Set_Treat_As_Volatile (E);
2237 ("inappropriate entity for pragma%", Arg1);
2239 end Process_Atomic_Shared_Volatile;
2241 -------------------------------------------
2242 -- Process_Compile_Time_Warning_Or_Error --
2243 -------------------------------------------
2245 procedure Process_Compile_Time_Warning_Or_Error is
2246 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2249 Check_Arg_Count (2);
2250 Check_No_Identifiers;
2251 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2252 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2254 if Compile_Time_Known_Value (Arg1x) then
2255 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2257 Str : constant String_Id :=
2258 Strval (Get_Pragma_Arg (Arg2));
2259 Len : constant Int := String_Length (Str);
2264 Cent : constant Entity_Id :=
2265 Cunit_Entity (Current_Sem_Unit);
2267 Force : constant Boolean :=
2268 Prag_Id = Pragma_Compile_Time_Warning
2270 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2271 and then (Ekind (Cent) /= E_Package
2272 or else not In_Private_Part (Cent));
2273 -- Set True if this is the warning case, and we are in the
2274 -- visible part of a package spec, or in a subprogram spec,
2275 -- in which case we want to force the client to see the
2276 -- warning, even though it is not in the main unit.
2279 -- Loop through segments of message separated by line feeds.
2280 -- We output these segments as separate messages with
2281 -- continuation marks for all but the first.
2286 Error_Msg_Strlen := 0;
2288 -- Loop to copy characters from argument to error message
2292 exit when Ptr > Len;
2293 CC := Get_String_Char (Str, Ptr);
2296 -- Ignore wide chars ??? else store character
2298 if In_Character_Range (CC) then
2299 C := Get_Character (CC);
2300 exit when C = ASCII.LF;
2301 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2302 Error_Msg_String (Error_Msg_Strlen) := C;
2306 -- Here with one line ready to go
2308 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2310 -- If this is a warning in a spec, then we want clients
2311 -- to see the warning, so mark the message with the
2312 -- special sequence !! to force the warning. In the case
2313 -- of a package spec, we do not force this if we are in
2314 -- the private part of the spec.
2317 if Cont = False then
2318 Error_Msg_N ("<~!!", Arg1);
2321 Error_Msg_N ("\<~!!", Arg1);
2324 -- Error, rather than warning, or in a body, so we do not
2325 -- need to force visibility for client (error will be
2326 -- output in any case, and this is the situation in which
2327 -- we do not want a client to get a warning, since the
2328 -- warning is in the body or the spec private part.
2331 if Cont = False then
2332 Error_Msg_N ("<~", Arg1);
2335 Error_Msg_N ("\<~", Arg1);
2339 exit when Ptr > Len;
2344 end Process_Compile_Time_Warning_Or_Error;
2346 ------------------------
2347 -- Process_Convention --
2348 ------------------------
2350 procedure Process_Convention
2351 (C : out Convention_Id;
2352 Ent : out Entity_Id)
2358 Comp_Unit : Unit_Number_Type;
2360 procedure Set_Convention_From_Pragma (E : Entity_Id);
2361 -- Set convention in entity E, and also flag that the entity has a
2362 -- convention pragma. If entity is for a private or incomplete type,
2363 -- also set convention and flag on underlying type. This procedure
2364 -- also deals with the special case of C_Pass_By_Copy convention.
2366 --------------------------------
2367 -- Set_Convention_From_Pragma --
2368 --------------------------------
2370 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2372 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2373 -- for an overridden dispatching operation. Technically this is
2374 -- an amendment and should only be done in Ada 2005 mode. However,
2375 -- this is clearly a mistake, since the problem that is addressed
2376 -- by this AI is that there is a clear gap in the RM!
2378 if Is_Dispatching_Operation (E)
2379 and then Present (Overridden_Operation (E))
2380 and then C /= Convention (Overridden_Operation (E))
2383 ("cannot change convention for " &
2384 "overridden dispatching operation",
2388 -- Set the convention
2390 Set_Convention (E, C);
2391 Set_Has_Convention_Pragma (E);
2393 if Is_Incomplete_Or_Private_Type (E) then
2394 Set_Convention (Underlying_Type (E), C);
2395 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2398 -- A class-wide type should inherit the convention of the specific
2399 -- root type (although this isn't specified clearly by the RM).
2401 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2402 Set_Convention (Class_Wide_Type (E), C);
2405 -- If the entity is a record type, then check for special case of
2406 -- C_Pass_By_Copy, which is treated the same as C except that the
2407 -- special record flag is set. This convention is only permitted
2408 -- on record types (see AI95-00131).
2410 if Cname = Name_C_Pass_By_Copy then
2411 if Is_Record_Type (E) then
2412 Set_C_Pass_By_Copy (Base_Type (E));
2413 elsif Is_Incomplete_Or_Private_Type (E)
2414 and then Is_Record_Type (Underlying_Type (E))
2416 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2419 ("C_Pass_By_Copy convention allowed only for record type",
2424 -- If the entity is a derived boolean type, check for the special
2425 -- case of convention C, C++, or Fortran, where we consider any
2426 -- nonzero value to represent true.
2428 if Is_Discrete_Type (E)
2429 and then Root_Type (Etype (E)) = Standard_Boolean
2435 C = Convention_Fortran)
2437 Set_Nonzero_Is_True (Base_Type (E));
2439 end Set_Convention_From_Pragma;
2441 -- Start of processing for Process_Convention
2444 Check_At_Least_N_Arguments (2);
2445 Check_Optional_Identifier (Arg1, Name_Convention);
2446 Check_Arg_Is_Identifier (Arg1);
2447 Cname := Chars (Expression (Arg1));
2449 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2450 -- tested again below to set the critical flag).
2451 if Cname = Name_C_Pass_By_Copy then
2454 -- Otherwise we must have something in the standard convention list
2456 elsif Is_Convention_Name (Cname) then
2457 C := Get_Convention_Id (Chars (Expression (Arg1)));
2459 -- In DEC VMS, it seems that there is an undocumented feature that
2460 -- any unrecognized convention is treated as the default, which for
2461 -- us is convention C. It does not seem so terrible to do this
2462 -- unconditionally, silently in the VMS case, and with a warning
2463 -- in the non-VMS case.
2466 if Warn_On_Export_Import and not OpenVMS_On_Target then
2468 ("?unrecognized convention name, C assumed",
2475 Check_Optional_Identifier (Arg2, Name_Entity);
2476 Check_Arg_Is_Local_Name (Arg2);
2478 Id := Expression (Arg2);
2481 if not Is_Entity_Name (Id) then
2482 Error_Pragma_Arg ("entity name required", Arg2);
2487 -- Set entity to return
2491 -- Go to renamed subprogram if present, since convention applies to
2492 -- the actual renamed entity, not to the renaming entity. If the
2493 -- subprogram is inherited, go to parent subprogram.
2495 if Is_Subprogram (E)
2496 and then Present (Alias (E))
2498 if Nkind (Parent (Declaration_Node (E))) =
2499 N_Subprogram_Renaming_Declaration
2501 if Scope (E) /= Scope (Alias (E)) then
2503 ("cannot apply pragma% to non-local entity&#", E);
2508 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2509 N_Private_Extension_Declaration)
2510 and then Scope (E) = Scope (Alias (E))
2514 -- Return the parent subprogram the entity was inherited from
2520 -- Check that we are not applying this to a specless body
2522 if Is_Subprogram (E)
2523 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2526 ("pragma% requires separate spec and must come before body");
2529 -- Check that we are not applying this to a named constant
2531 if Ekind (E) = E_Named_Integer
2533 Ekind (E) = E_Named_Real
2535 Error_Msg_Name_1 := Pname;
2537 ("cannot apply pragma% to named constant!",
2538 Get_Pragma_Arg (Arg2));
2540 ("\supply appropriate type for&!", Arg2);
2543 if Ekind (E) = E_Enumeration_Literal then
2544 Error_Pragma ("enumeration literal not allowed for pragma%");
2547 -- Check for rep item appearing too early or too late
2549 if Etype (E) = Any_Type
2550 or else Rep_Item_Too_Early (E, N)
2554 E := Underlying_Type (E);
2557 if Rep_Item_Too_Late (E, N) then
2561 if Has_Convention_Pragma (E) then
2563 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2565 elsif Convention (E) = Convention_Protected
2566 or else Ekind (Scope (E)) = E_Protected_Type
2569 ("a protected operation cannot be given a different convention",
2573 -- For Intrinsic, a subprogram is required
2575 if C = Convention_Intrinsic
2576 and then not Is_Subprogram (E)
2577 and then not Is_Generic_Subprogram (E)
2580 ("second argument of pragma% must be a subprogram", Arg2);
2583 -- For Stdcall, a subprogram, variable or subprogram type is required
2585 if C = Convention_Stdcall
2586 and then not Is_Subprogram (E)
2587 and then not Is_Generic_Subprogram (E)
2588 and then Ekind (E) /= E_Variable
2591 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2594 ("second argument of pragma% must be subprogram (type)",
2598 if not Is_Subprogram (E)
2599 and then not Is_Generic_Subprogram (E)
2601 Set_Convention_From_Pragma (E);
2605 Check_First_Subtype (Arg2);
2606 Set_Convention_From_Pragma (Base_Type (E));
2608 -- For subprograms, we must set the convention on the
2609 -- internally generated directly designated type as well.
2611 if Ekind (E) = E_Access_Subprogram_Type then
2612 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2616 -- For the subprogram case, set proper convention for all homonyms
2617 -- in same scope and the same declarative part, i.e. the same
2618 -- compilation unit.
2621 Comp_Unit := Get_Source_Unit (E);
2622 Set_Convention_From_Pragma (E);
2624 -- Treat a pragma Import as an implicit body, for GPS use
2626 if Prag_Id = Pragma_Import then
2627 Generate_Reference (E, Id, 'b');
2630 -- Loop through the homonyms of the pragma argument's entity
2635 exit when No (E1) or else Scope (E1) /= Current_Scope;
2637 -- Do not set the pragma on inherited operations or on formal
2640 if Comes_From_Source (E1)
2641 and then Comp_Unit = Get_Source_Unit (E1)
2642 and then not Is_Formal_Subprogram (E1)
2643 and then Nkind (Original_Node (Parent (E1))) /=
2644 N_Full_Type_Declaration
2646 if Present (Alias (E1))
2647 and then Scope (E1) /= Scope (Alias (E1))
2650 ("cannot apply pragma% to non-local entity& declared#",
2654 Set_Convention_From_Pragma (E1);
2656 if Prag_Id = Pragma_Import then
2657 Generate_Reference (E1, Id, 'b');
2662 end Process_Convention;
2664 -----------------------------------------------------
2665 -- Process_Extended_Import_Export_Exception_Pragma --
2666 -----------------------------------------------------
2668 procedure Process_Extended_Import_Export_Exception_Pragma
2669 (Arg_Internal : Node_Id;
2670 Arg_External : Node_Id;
2678 if not OpenVMS_On_Target then
2680 ("?pragma% ignored (applies only to Open'V'M'S)");
2683 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2684 Def_Id := Entity (Arg_Internal);
2686 if Ekind (Def_Id) /= E_Exception then
2688 ("pragma% must refer to declared exception", Arg_Internal);
2691 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2693 if Present (Arg_Form) then
2694 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2697 if Present (Arg_Form)
2698 and then Chars (Arg_Form) = Name_Ada
2702 Set_Is_VMS_Exception (Def_Id);
2703 Set_Exception_Code (Def_Id, No_Uint);
2706 if Present (Arg_Code) then
2707 if not Is_VMS_Exception (Def_Id) then
2709 ("Code option for pragma% not allowed for Ada case",
2713 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2714 Code_Val := Expr_Value (Arg_Code);
2716 if not UI_Is_In_Int_Range (Code_Val) then
2718 ("Code option for pragma% must be in 32-bit range",
2722 Set_Exception_Code (Def_Id, Code_Val);
2725 end Process_Extended_Import_Export_Exception_Pragma;
2727 -------------------------------------------------
2728 -- Process_Extended_Import_Export_Internal_Arg --
2729 -------------------------------------------------
2731 procedure Process_Extended_Import_Export_Internal_Arg
2732 (Arg_Internal : Node_Id := Empty)
2735 if No (Arg_Internal) then
2736 Error_Pragma ("Internal parameter required for pragma%");
2739 if Nkind (Arg_Internal) = N_Identifier then
2742 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2743 and then (Prag_Id = Pragma_Import_Function
2745 Prag_Id = Pragma_Export_Function)
2751 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2754 Check_Arg_Is_Local_Name (Arg_Internal);
2755 end Process_Extended_Import_Export_Internal_Arg;
2757 --------------------------------------------------
2758 -- Process_Extended_Import_Export_Object_Pragma --
2759 --------------------------------------------------
2761 procedure Process_Extended_Import_Export_Object_Pragma
2762 (Arg_Internal : Node_Id;
2763 Arg_External : Node_Id;
2769 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2770 Def_Id := Entity (Arg_Internal);
2772 if Ekind (Def_Id) /= E_Constant
2773 and then Ekind (Def_Id) /= E_Variable
2776 ("pragma% must designate an object", Arg_Internal);
2779 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2781 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2784 ("previous Common/Psect_Object applies, pragma % not permitted",
2788 if Rep_Item_Too_Late (Def_Id, N) then
2792 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2794 if Present (Arg_Size) then
2795 Check_Arg_Is_External_Name (Arg_Size);
2798 -- Export_Object case
2800 if Prag_Id = Pragma_Export_Object then
2801 if not Is_Library_Level_Entity (Def_Id) then
2803 ("argument for pragma% must be library level entity",
2807 if Ekind (Current_Scope) = E_Generic_Package then
2808 Error_Pragma ("pragma& cannot appear in a generic unit");
2811 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2813 ("exported object must have compile time known size",
2817 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2818 Error_Msg_N ("?duplicate Export_Object pragma", N);
2820 Set_Exported (Def_Id, Arg_Internal);
2823 -- Import_Object case
2826 if Is_Concurrent_Type (Etype (Def_Id)) then
2828 ("cannot use pragma% for task/protected object",
2832 if Ekind (Def_Id) = E_Constant then
2834 ("cannot import a constant", Arg_Internal);
2837 if Warn_On_Export_Import
2838 and then Has_Discriminants (Etype (Def_Id))
2841 ("imported value must be initialized?", Arg_Internal);
2844 if Warn_On_Export_Import
2845 and then Is_Access_Type (Etype (Def_Id))
2848 ("cannot import object of an access type?", Arg_Internal);
2851 if Warn_On_Export_Import
2852 and then Is_Imported (Def_Id)
2855 ("?duplicate Import_Object pragma", N);
2857 -- Check for explicit initialization present. Note that an
2858 -- initialization generated by the code generator, e.g. for an
2859 -- access type, does not count here.
2861 elsif Present (Expression (Parent (Def_Id)))
2864 (Original_Node (Expression (Parent (Def_Id))))
2866 Error_Msg_Sloc := Sloc (Def_Id);
2868 ("imported entities cannot be initialized (RM B.1(24))",
2869 "\no initialization allowed for & declared#", Arg1);
2871 Set_Imported (Def_Id);
2872 Note_Possible_Modification (Arg_Internal, Sure => False);
2875 end Process_Extended_Import_Export_Object_Pragma;
2877 ------------------------------------------------------
2878 -- Process_Extended_Import_Export_Subprogram_Pragma --
2879 ------------------------------------------------------
2881 procedure Process_Extended_Import_Export_Subprogram_Pragma
2882 (Arg_Internal : Node_Id;
2883 Arg_External : Node_Id;
2884 Arg_Parameter_Types : Node_Id;
2885 Arg_Result_Type : Node_Id := Empty;
2886 Arg_Mechanism : Node_Id;
2887 Arg_Result_Mechanism : Node_Id := Empty;
2888 Arg_First_Optional_Parameter : Node_Id := Empty)
2894 Ambiguous : Boolean;
2898 function Same_Base_Type
2900 Formal : Entity_Id) return Boolean;
2901 -- Determines if Ptype references the type of Formal. Note that only
2902 -- the base types need to match according to the spec. Ptype here is
2903 -- the argument from the pragma, which is either a type name, or an
2904 -- access attribute.
2906 --------------------
2907 -- Same_Base_Type --
2908 --------------------
2910 function Same_Base_Type
2912 Formal : Entity_Id) return Boolean
2914 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2918 -- Case where pragma argument is typ'Access
2920 if Nkind (Ptype) = N_Attribute_Reference
2921 and then Attribute_Name (Ptype) = Name_Access
2923 Pref := Prefix (Ptype);
2926 if not Is_Entity_Name (Pref)
2927 or else Entity (Pref) = Any_Type
2932 -- We have a match if the corresponding argument is of an
2933 -- anonymous access type, and its designated type matches the
2934 -- type of the prefix of the access attribute
2936 return Ekind (Ftyp) = E_Anonymous_Access_Type
2937 and then Base_Type (Entity (Pref)) =
2938 Base_Type (Etype (Designated_Type (Ftyp)));
2940 -- Case where pragma argument is a type name
2945 if not Is_Entity_Name (Ptype)
2946 or else Entity (Ptype) = Any_Type
2951 -- We have a match if the corresponding argument is of the type
2952 -- given in the pragma (comparing base types)
2954 return Base_Type (Entity (Ptype)) = Ftyp;
2958 -- Start of processing for
2959 -- Process_Extended_Import_Export_Subprogram_Pragma
2962 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2966 -- Loop through homonyms (overloadings) of the entity
2968 Hom_Id := Entity (Arg_Internal);
2969 while Present (Hom_Id) loop
2970 Def_Id := Get_Base_Subprogram (Hom_Id);
2972 -- We need a subprogram in the current scope
2974 if not Is_Subprogram (Def_Id)
2975 or else Scope (Def_Id) /= Current_Scope
2982 -- Pragma cannot apply to subprogram body
2984 if Is_Subprogram (Def_Id)
2985 and then Nkind (Parent (Declaration_Node (Def_Id))) =
2989 ("pragma% requires separate spec"
2990 & " and must come before body");
2993 -- Test result type if given, note that the result type
2994 -- parameter can only be present for the function cases.
2996 if Present (Arg_Result_Type)
2997 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3001 elsif Etype (Def_Id) /= Standard_Void_Type
3003 (Pname = Name_Export_Procedure
3005 Pname = Name_Import_Procedure)
3009 -- Test parameter types if given. Note that this parameter
3010 -- has not been analyzed (and must not be, since it is
3011 -- semantic nonsense), so we get it as the parser left it.
3013 elsif Present (Arg_Parameter_Types) then
3014 Check_Matching_Types : declare
3019 Formal := First_Formal (Def_Id);
3021 if Nkind (Arg_Parameter_Types) = N_Null then
3022 if Present (Formal) then
3026 -- A list of one type, e.g. (List) is parsed as
3027 -- a parenthesized expression.
3029 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3030 and then Paren_Count (Arg_Parameter_Types) = 1
3033 or else Present (Next_Formal (Formal))
3038 Same_Base_Type (Arg_Parameter_Types, Formal);
3041 -- A list of more than one type is parsed as a aggregate
3043 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3044 and then Paren_Count (Arg_Parameter_Types) = 0
3046 Ptype := First (Expressions (Arg_Parameter_Types));
3047 while Present (Ptype) or else Present (Formal) loop
3050 or else not Same_Base_Type (Ptype, Formal)
3055 Next_Formal (Formal);
3060 -- Anything else is of the wrong form
3064 ("wrong form for Parameter_Types parameter",
3065 Arg_Parameter_Types);
3067 end Check_Matching_Types;
3070 -- Match is now False if the entry we found did not match
3071 -- either a supplied Parameter_Types or Result_Types argument
3077 -- Ambiguous case, the flag Ambiguous shows if we already
3078 -- detected this and output the initial messages.
3081 if not Ambiguous then
3083 Error_Msg_Name_1 := Pname;
3085 ("pragma% does not uniquely identify subprogram!",
3087 Error_Msg_Sloc := Sloc (Ent);
3088 Error_Msg_N ("matching subprogram #!", N);
3092 Error_Msg_Sloc := Sloc (Def_Id);
3093 Error_Msg_N ("matching subprogram #!", N);
3098 Hom_Id := Homonym (Hom_Id);
3101 -- See if we found an entry
3104 if not Ambiguous then
3105 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3107 ("pragma% cannot be given for generic subprogram");
3110 ("pragma% does not identify local subprogram");
3117 -- Import pragmas must be for imported entities
3119 if Prag_Id = Pragma_Import_Function
3121 Prag_Id = Pragma_Import_Procedure
3123 Prag_Id = Pragma_Import_Valued_Procedure
3125 if not Is_Imported (Ent) then
3126 Error_Pragma -- CODEFIX???
3127 ("pragma Import or Interface must precede pragma%");
3130 -- Here we have the Export case which can set the entity as exported
3132 -- But does not do so if the specified external name is null, since
3133 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3134 -- compatible) to request no external name.
3136 elsif Nkind (Arg_External) = N_String_Literal
3137 and then String_Length (Strval (Arg_External)) = 0
3141 -- In all other cases, set entity as exported
3144 Set_Exported (Ent, Arg_Internal);
3147 -- Special processing for Valued_Procedure cases
3149 if Prag_Id = Pragma_Import_Valued_Procedure
3151 Prag_Id = Pragma_Export_Valued_Procedure
3153 Formal := First_Formal (Ent);
3156 Error_Pragma ("at least one parameter required for pragma%");
3158 elsif Ekind (Formal) /= E_Out_Parameter then
3159 Error_Pragma ("first parameter must have mode out for pragma%");
3162 Set_Is_Valued_Procedure (Ent);
3166 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3168 -- Process Result_Mechanism argument if present. We have already
3169 -- checked that this is only allowed for the function case.
3171 if Present (Arg_Result_Mechanism) then
3172 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3175 -- Process Mechanism parameter if present. Note that this parameter
3176 -- is not analyzed, and must not be analyzed since it is semantic
3177 -- nonsense, so we get it in exactly as the parser left it.
3179 if Present (Arg_Mechanism) then
3187 -- A single mechanism association without a formal parameter
3188 -- name is parsed as a parenthesized expression. All other
3189 -- cases are parsed as aggregates, so we rewrite the single
3190 -- parameter case as an aggregate for consistency.
3192 if Nkind (Arg_Mechanism) /= N_Aggregate
3193 and then Paren_Count (Arg_Mechanism) = 1
3195 Rewrite (Arg_Mechanism,
3196 Make_Aggregate (Sloc (Arg_Mechanism),
3197 Expressions => New_List (
3198 Relocate_Node (Arg_Mechanism))));
3201 -- Case of only mechanism name given, applies to all formals
3203 if Nkind (Arg_Mechanism) /= N_Aggregate then
3204 Formal := First_Formal (Ent);
3205 while Present (Formal) loop
3206 Set_Mechanism_Value (Formal, Arg_Mechanism);
3207 Next_Formal (Formal);
3210 -- Case of list of mechanism associations given
3213 if Null_Record_Present (Arg_Mechanism) then
3215 ("inappropriate form for Mechanism parameter",
3219 -- Deal with positional ones first
3221 Formal := First_Formal (Ent);
3223 if Present (Expressions (Arg_Mechanism)) then
3224 Mname := First (Expressions (Arg_Mechanism));
3225 while Present (Mname) loop
3228 ("too many mechanism associations", Mname);
3231 Set_Mechanism_Value (Formal, Mname);
3232 Next_Formal (Formal);
3237 -- Deal with named entries
3239 if Present (Component_Associations (Arg_Mechanism)) then
3240 Massoc := First (Component_Associations (Arg_Mechanism));
3241 while Present (Massoc) loop
3242 Choice := First (Choices (Massoc));
3244 if Nkind (Choice) /= N_Identifier
3245 or else Present (Next (Choice))
3248 ("incorrect form for mechanism association",
3252 Formal := First_Formal (Ent);
3256 ("parameter name & not present", Choice);
3259 if Chars (Choice) = Chars (Formal) then
3261 (Formal, Expression (Massoc));
3263 -- Set entity on identifier for ASIS
3265 Set_Entity (Choice, Formal);
3270 Next_Formal (Formal);
3280 -- Process First_Optional_Parameter argument if present. We have
3281 -- already checked that this is only allowed for the Import case.
3283 if Present (Arg_First_Optional_Parameter) then
3284 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3286 ("first optional parameter must be formal parameter name",
3287 Arg_First_Optional_Parameter);
3290 Formal := First_Formal (Ent);
3294 ("specified formal parameter& not found",
3295 Arg_First_Optional_Parameter);
3298 exit when Chars (Formal) =
3299 Chars (Arg_First_Optional_Parameter);
3301 Next_Formal (Formal);
3304 Set_First_Optional_Parameter (Ent, Formal);
3306 -- Check specified and all remaining formals have right form
3308 while Present (Formal) loop
3309 if Ekind (Formal) /= E_In_Parameter then
3311 ("optional formal& is not of mode in!",
3312 Arg_First_Optional_Parameter, Formal);
3315 Dval := Default_Value (Formal);
3319 ("optional formal& does not have default value!",
3320 Arg_First_Optional_Parameter, Formal);
3322 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3327 ("default value for optional formal& is non-static!",
3328 Arg_First_Optional_Parameter, Formal);
3332 Set_Is_Optional_Parameter (Formal);
3333 Next_Formal (Formal);
3336 end Process_Extended_Import_Export_Subprogram_Pragma;
3338 --------------------------
3339 -- Process_Generic_List --
3340 --------------------------
3342 procedure Process_Generic_List is
3347 Check_No_Identifiers;
3348 Check_At_Least_N_Arguments (1);
3351 while Present (Arg) loop
3352 Exp := Expression (Arg);
3355 if not Is_Entity_Name (Exp)
3357 (not Is_Generic_Instance (Entity (Exp))
3359 not Is_Generic_Unit (Entity (Exp)))
3362 ("pragma% argument must be name of generic unit/instance",
3368 end Process_Generic_List;
3370 ---------------------------------
3371 -- Process_Import_Or_Interface --
3372 ---------------------------------
3374 procedure Process_Import_Or_Interface is
3380 Process_Convention (C, Def_Id);
3381 Kill_Size_Check_Code (Def_Id);
3382 Note_Possible_Modification (Expression (Arg2), Sure => False);
3384 if Ekind (Def_Id) = E_Variable
3386 Ekind (Def_Id) = E_Constant
3388 -- We do not permit Import to apply to a renaming declaration
3390 if Present (Renamed_Object (Def_Id)) then
3392 ("pragma% not allowed for object renaming", Arg2);
3394 -- User initialization is not allowed for imported object, but
3395 -- the object declaration may contain a default initialization,
3396 -- that will be discarded. Note that an explicit initialization
3397 -- only counts if it comes from source, otherwise it is simply
3398 -- the code generator making an implicit initialization explicit.
3400 elsif Present (Expression (Parent (Def_Id)))
3401 and then Comes_From_Source (Expression (Parent (Def_Id)))
3403 Error_Msg_Sloc := Sloc (Def_Id);
3405 ("no initialization allowed for declaration of& #",
3406 "\imported entities cannot be initialized (RM B.1(24))",
3410 Set_Imported (Def_Id);
3411 Process_Interface_Name (Def_Id, Arg3, Arg4);
3413 -- Note that we do not set Is_Public here. That's because we
3414 -- only want to set it if there is no address clause, and we
3415 -- don't know that yet, so we delay that processing till
3418 -- pragma Import completes deferred constants
3420 if Ekind (Def_Id) = E_Constant then
3421 Set_Has_Completion (Def_Id);
3424 -- It is not possible to import a constant of an unconstrained
3425 -- array type (e.g. string) because there is no simple way to
3426 -- write a meaningful subtype for it.
3428 if Is_Array_Type (Etype (Def_Id))
3429 and then not Is_Constrained (Etype (Def_Id))
3432 ("imported constant& must have a constrained subtype",
3437 elsif Is_Subprogram (Def_Id)
3438 or else Is_Generic_Subprogram (Def_Id)
3440 -- If the name is overloaded, pragma applies to all of the
3441 -- denoted entities in the same declarative part.
3444 while Present (Hom_Id) loop
3445 Def_Id := Get_Base_Subprogram (Hom_Id);
3447 -- Ignore inherited subprograms because the pragma will
3448 -- apply to the parent operation, which is the one called.
3450 if Is_Overloadable (Def_Id)
3451 and then Present (Alias (Def_Id))
3455 -- If it is not a subprogram, it must be in an outer scope and
3456 -- pragma does not apply.
3458 elsif not Is_Subprogram (Def_Id)
3459 and then not Is_Generic_Subprogram (Def_Id)
3463 -- Verify that the homonym is in the same declarative part (not
3464 -- just the same scope).
3466 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3467 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3472 Set_Imported (Def_Id);
3474 -- Reject an Import applied to an abstract subprogram
3476 if Is_Subprogram (Def_Id)
3477 and then Is_Abstract_Subprogram (Def_Id)
3479 Error_Msg_Sloc := Sloc (Def_Id);
3481 ("cannot import abstract subprogram& declared#",
3485 -- Special processing for Convention_Intrinsic
3487 if C = Convention_Intrinsic then
3489 -- Link_Name argument not allowed for intrinsic
3492 and then Chars (Arg3) = Name_Link_Name
3497 if Present (Arg4) then
3499 ("Link_Name argument not allowed for " &
3504 Set_Is_Intrinsic_Subprogram (Def_Id);
3506 -- If no external name is present, then check that this
3507 -- is a valid intrinsic subprogram. If an external name
3508 -- is present, then this is handled by the back end.
3511 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3515 -- All interfaced procedures need an external symbol created
3516 -- for them since they are always referenced from another
3519 Set_Is_Public (Def_Id);
3521 -- Verify that the subprogram does not have a completion
3522 -- through a renaming declaration. For other completions the
3523 -- pragma appears as a too late representation.
3526 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3530 and then Nkind (Decl) = N_Subprogram_Declaration
3531 and then Present (Corresponding_Body (Decl))
3532 and then Nkind (Unit_Declaration_Node
3533 (Corresponding_Body (Decl))) =
3534 N_Subprogram_Renaming_Declaration
3536 Error_Msg_Sloc := Sloc (Def_Id);
3538 ("cannot import&, renaming already provided for " &
3539 "declaration #", N, Def_Id);
3543 Set_Has_Completion (Def_Id);
3544 Process_Interface_Name (Def_Id, Arg3, Arg4);
3547 if Is_Compilation_Unit (Hom_Id) then
3549 -- Its possible homonyms are not affected by the pragma.
3550 -- Such homonyms might be present in the context of other
3551 -- units being compiled.
3556 Hom_Id := Homonym (Hom_Id);
3560 -- When the convention is Java or CIL, we also allow Import to be
3561 -- given for packages, generic packages, exceptions, record
3562 -- components, and access to subprograms.
3564 elsif (C = Convention_Java or else C = Convention_CIL)
3566 (Is_Package_Or_Generic_Package (Def_Id)
3567 or else Ekind (Def_Id) = E_Exception
3568 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3569 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3571 Set_Imported (Def_Id);
3572 Set_Is_Public (Def_Id);
3573 Process_Interface_Name (Def_Id, Arg3, Arg4);
3575 -- Import a CPP class
3577 elsif Is_Record_Type (Def_Id)
3578 and then C = Convention_CPP
3580 -- Types treated as CPP classes are treated as limited, but we
3581 -- don't require them to be declared this way. A warning is
3582 -- issued to encourage the user to declare them as limited.
3583 -- This is not an error, for compatibility reasons, because
3584 -- these types have been supported this way for some time.
3586 if not Is_Limited_Type (Def_Id) then
3588 ("imported 'C'P'P type should be " &
3589 "explicitly declared limited?",
3590 Get_Pragma_Arg (Arg2));
3592 ("\type will be considered limited",
3593 Get_Pragma_Arg (Arg2));
3596 Set_Is_CPP_Class (Def_Id);
3597 Set_Is_Limited_Record (Def_Id);
3599 -- Imported CPP types must not have discriminants (because C++
3600 -- classes do not have discriminants).
3602 if Has_Discriminants (Def_Id) then
3604 ("imported 'C'P'P type cannot have discriminants",
3605 First (Discriminant_Specifications
3606 (Declaration_Node (Def_Id))));
3609 -- Components of imported CPP types must not have default
3610 -- expressions because the constructor (if any) is on the
3614 Tdef : constant Node_Id :=
3615 Type_Definition (Declaration_Node (Def_Id));
3620 if Nkind (Tdef) = N_Record_Definition then
3621 Clist := Component_List (Tdef);
3624 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3625 Clist := Component_List (Record_Extension_Part (Tdef));
3628 if Present (Clist) then
3629 Comp := First (Component_Items (Clist));
3630 while Present (Comp) loop
3631 if Present (Expression (Comp)) then
3633 ("component of imported 'C'P'P type cannot have" &
3634 " default expression", Expression (Comp));
3644 ("second argument of pragma% must be object or subprogram",
3648 -- If this pragma applies to a compilation unit, then the unit, which
3649 -- is a subprogram, does not require (or allow) a body. We also do
3650 -- not need to elaborate imported procedures.
3652 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3654 Cunit : constant Node_Id := Parent (Parent (N));
3656 Set_Body_Required (Cunit, False);
3659 end Process_Import_Or_Interface;
3661 --------------------
3662 -- Process_Inline --
3663 --------------------
3665 procedure Process_Inline (Active : Boolean) is
3671 Effective : Boolean := False;
3673 procedure Make_Inline (Subp : Entity_Id);
3674 -- Subp is the defining unit name of the subprogram declaration. Set
3675 -- the flag, as well as the flag in the corresponding body, if there
3678 procedure Set_Inline_Flags (Subp : Entity_Id);
3679 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3680 -- Has_Pragma_Inline_Always for the Inline_Always case.
3682 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3683 -- Returns True if it can be determined at this stage that inlining
3684 -- is not possible, for example if the body is available and contains
3685 -- exception handlers, we prevent inlining, since otherwise we can
3686 -- get undefined symbols at link time. This function also emits a
3687 -- warning if front-end inlining is enabled and the pragma appears
3690 -- ??? is business with link symbols still valid, or does it relate
3691 -- to front end ZCX which is being phased out ???
3693 ---------------------------
3694 -- Inlining_Not_Possible --
3695 ---------------------------
3697 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3698 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3702 if Nkind (Decl) = N_Subprogram_Body then
3703 Stats := Handled_Statement_Sequence (Decl);
3704 return Present (Exception_Handlers (Stats))
3705 or else Present (At_End_Proc (Stats));
3707 elsif Nkind (Decl) = N_Subprogram_Declaration
3708 and then Present (Corresponding_Body (Decl))
3710 if Front_End_Inlining
3711 and then Analyzed (Corresponding_Body (Decl))
3713 Error_Msg_N ("pragma appears too late, ignored?", N);
3716 -- If the subprogram is a renaming as body, the body is just a
3717 -- call to the renamed subprogram, and inlining is trivially
3721 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3722 N_Subprogram_Renaming_Declaration
3728 Handled_Statement_Sequence
3729 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3732 Present (Exception_Handlers (Stats))
3733 or else Present (At_End_Proc (Stats));
3737 -- If body is not available, assume the best, the check is
3738 -- performed again when compiling enclosing package bodies.
3742 end Inlining_Not_Possible;
3748 procedure Make_Inline (Subp : Entity_Id) is
3749 Kind : constant Entity_Kind := Ekind (Subp);
3750 Inner_Subp : Entity_Id := Subp;
3753 -- Ignore if bad type, avoid cascaded error
3755 if Etype (Subp) = Any_Type then
3759 -- Ignore if all inlining is suppressed
3761 elsif Suppress_All_Inlining then
3765 -- If inlining is not possible, for now do not treat as an error
3767 elsif Inlining_Not_Possible (Subp) then
3771 -- Here we have a candidate for inlining, but we must exclude
3772 -- derived operations. Otherwise we would end up trying to inline
3773 -- a phantom declaration, and the result would be to drag in a
3774 -- body which has no direct inlining associated with it. That
3775 -- would not only be inefficient but would also result in the
3776 -- backend doing cross-unit inlining in cases where it was
3777 -- definitely inappropriate to do so.
3779 -- However, a simple Comes_From_Source test is insufficient, since
3780 -- we do want to allow inlining of generic instances which also do
3781 -- not come from source. We also need to recognize specs generated
3782 -- by the front-end for bodies that carry the pragma. Finally,
3783 -- predefined operators do not come from source but are not
3784 -- inlineable either.
3786 elsif Is_Generic_Instance (Subp)
3787 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3791 elsif not Comes_From_Source (Subp)
3792 and then Scope (Subp) /= Standard_Standard
3798 -- The referenced entity must either be the enclosing entity, or
3799 -- an entity declared within the current open scope.
3801 if Present (Scope (Subp))
3802 and then Scope (Subp) /= Current_Scope
3803 and then Subp /= Current_Scope
3806 ("argument of% must be entity in current scope", Assoc);
3810 -- Processing for procedure, operator or function. If subprogram
3811 -- is aliased (as for an instance) indicate that the renamed
3812 -- entity (if declared in the same unit) is inlined.
3814 if Is_Subprogram (Subp) then
3815 while Present (Alias (Inner_Subp)) loop
3816 Inner_Subp := Alias (Inner_Subp);
3819 if In_Same_Source_Unit (Subp, Inner_Subp) then
3820 Set_Inline_Flags (Inner_Subp);
3822 Decl := Parent (Parent (Inner_Subp));
3824 if Nkind (Decl) = N_Subprogram_Declaration
3825 and then Present (Corresponding_Body (Decl))
3827 Set_Inline_Flags (Corresponding_Body (Decl));
3829 elsif Is_Generic_Instance (Subp) then
3831 -- Indicate that the body needs to be created for
3832 -- inlining subsequent calls. The instantiation node
3833 -- follows the declaration of the wrapper package
3836 if Scope (Subp) /= Standard_Standard
3838 Need_Subprogram_Instance_Body
3839 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3849 -- For a generic subprogram set flag as well, for use at the point
3850 -- of instantiation, to determine whether the body should be
3853 elsif Is_Generic_Subprogram (Subp) then
3854 Set_Inline_Flags (Subp);
3857 -- Literals are by definition inlined
3859 elsif Kind = E_Enumeration_Literal then
3862 -- Anything else is an error
3866 ("expect subprogram name for pragma%", Assoc);
3870 ----------------------
3871 -- Set_Inline_Flags --
3872 ----------------------
3874 procedure Set_Inline_Flags (Subp : Entity_Id) is
3877 Set_Is_Inlined (Subp, True);
3880 if not Has_Pragma_Inline (Subp) then
3881 Set_Has_Pragma_Inline (Subp);
3885 if Prag_Id = Pragma_Inline_Always then
3886 Set_Has_Pragma_Inline_Always (Subp);
3888 end Set_Inline_Flags;
3890 -- Start of processing for Process_Inline
3893 Check_No_Identifiers;
3894 Check_At_Least_N_Arguments (1);
3897 Inline_Processing_Required := True;
3901 while Present (Assoc) loop
3902 Subp_Id := Expression (Assoc);
3906 if Is_Entity_Name (Subp_Id) then
3907 Subp := Entity (Subp_Id);
3909 if Subp = Any_Id then
3911 -- If previous error, avoid cascaded errors
3919 while Present (Homonym (Subp))
3920 and then Scope (Homonym (Subp)) = Current_Scope
3922 Make_Inline (Homonym (Subp));
3923 Subp := Homonym (Subp);
3930 ("inappropriate argument for pragma%", Assoc);
3933 and then Warn_On_Redundant_Constructs
3934 and then not Suppress_All_Inlining
3936 if Inlining_Not_Possible (Subp) then
3938 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3941 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3949 ----------------------------
3950 -- Process_Interface_Name --
3951 ----------------------------
3953 procedure Process_Interface_Name
3954 (Subprogram_Def : Entity_Id;
3960 String_Val : String_Id;
3962 procedure Check_Form_Of_Interface_Name
3964 Ext_Name_Case : Boolean);
3965 -- SN is a string literal node for an interface name. This routine
3966 -- performs some minimal checks that the name is reasonable. In
3967 -- particular that no spaces or other obviously incorrect characters
3968 -- appear. This is only a warning, since any characters are allowed.
3969 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3971 ----------------------------------
3972 -- Check_Form_Of_Interface_Name --
3973 ----------------------------------
3975 procedure Check_Form_Of_Interface_Name
3977 Ext_Name_Case : Boolean)
3979 S : constant String_Id := Strval (Expr_Value_S (SN));
3980 SL : constant Nat := String_Length (S);
3985 Error_Msg_N ("interface name cannot be null string", SN);
3988 for J in 1 .. SL loop
3989 C := Get_String_Char (S, J);
3991 -- Look for dubious character and issue unconditional warning.
3992 -- Definitely dubious if not in character range.
3994 if not In_Character_Range (C)
3996 -- For all cases except CLI target,
3997 -- commas, spaces and slashes are dubious (in CLI, we use
3998 -- commas and backslashes in external names to specify
3999 -- assembly version and public key, while slashes and spaces
4000 -- can be used in names to mark nested classes and
4003 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4004 and then (Get_Character (C) = ','
4006 Get_Character (C) = '\'))
4007 or else (VM_Target /= CLI_Target
4008 and then (Get_Character (C) = ' '
4010 Get_Character (C) = '/'))
4013 ("?interface name contains illegal character",
4014 Sloc (SN) + Source_Ptr (J));
4017 end Check_Form_Of_Interface_Name;
4019 -- Start of processing for Process_Interface_Name
4022 if No (Link_Arg) then
4023 if No (Ext_Arg) then
4024 if VM_Target = CLI_Target
4025 and then Ekind (Subprogram_Def) = E_Package
4026 and then Nkind (Parent (Subprogram_Def)) =
4027 N_Package_Specification
4028 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4033 (Generic_Parent (Parent (Subprogram_Def))));
4038 elsif Chars (Ext_Arg) = Name_Link_Name then
4040 Link_Nam := Expression (Ext_Arg);
4043 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4044 Ext_Nam := Expression (Ext_Arg);
4049 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4050 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4051 Ext_Nam := Expression (Ext_Arg);
4052 Link_Nam := Expression (Link_Arg);
4055 -- Check expressions for external name and link name are static
4057 if Present (Ext_Nam) then
4058 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4059 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4061 -- Verify that external name is not the name of a local entity,
4062 -- which would hide the imported one and could lead to run-time
4063 -- surprises. The problem can only arise for entities declared in
4064 -- a package body (otherwise the external name is fully qualified
4065 -- and will not conflict).
4073 if Prag_Id = Pragma_Import then
4074 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4076 E := Entity_Id (Get_Name_Table_Info (Nam));
4078 if Nam /= Chars (Subprogram_Def)
4079 and then Present (E)
4080 and then not Is_Overloadable (E)
4081 and then Is_Immediately_Visible (E)
4082 and then not Is_Imported (E)
4083 and then Ekind (Scope (E)) = E_Package
4086 while Present (Par) loop
4087 if Nkind (Par) = N_Package_Body then
4088 Error_Msg_Sloc := Sloc (E);
4090 ("imported entity is hidden by & declared#",
4095 Par := Parent (Par);
4102 if Present (Link_Nam) then
4103 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4104 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4107 -- If there is no link name, just set the external name
4109 if No (Link_Nam) then
4110 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4112 -- For the Link_Name case, the given literal is preceded by an
4113 -- asterisk, which indicates to GCC that the given name should be
4114 -- taken literally, and in particular that no prepending of
4115 -- underlines should occur, even in systems where this is the
4121 if VM_Target = No_VM then
4122 Store_String_Char (Get_Char_Code ('*'));
4125 String_Val := Strval (Expr_Value_S (Link_Nam));
4126 Store_String_Chars (String_Val);
4128 Make_String_Literal (Sloc (Link_Nam),
4129 Strval => End_String);
4132 Set_Encoded_Interface_Name
4133 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4134 Check_Duplicated_Export_Name (Link_Nam);
4135 end Process_Interface_Name;
4137 -----------------------------------------
4138 -- Process_Interrupt_Or_Attach_Handler --
4139 -----------------------------------------
4141 procedure Process_Interrupt_Or_Attach_Handler is
4142 Arg1_X : constant Node_Id := Expression (Arg1);
4143 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4144 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4147 Set_Is_Interrupt_Handler (Handler_Proc);
4149 -- If the pragma is not associated with a handler procedure within a
4150 -- protected type, then it must be for a nonprotected procedure for
4151 -- the AAMP target, in which case we don't associate a representation
4152 -- item with the procedure's scope.
4154 if Ekind (Proc_Scope) = E_Protected_Type then
4155 if Prag_Id = Pragma_Interrupt_Handler
4157 Prag_Id = Pragma_Attach_Handler
4159 Record_Rep_Item (Proc_Scope, N);
4162 end Process_Interrupt_Or_Attach_Handler;
4164 --------------------------------------------------
4165 -- Process_Restrictions_Or_Restriction_Warnings --
4166 --------------------------------------------------
4168 -- Note: some of the simple identifier cases were handled in par-prag,
4169 -- but it is harmless (and more straightforward) to simply handle all
4170 -- cases here, even if it means we repeat a bit of work in some cases.
4172 procedure Process_Restrictions_Or_Restriction_Warnings
4176 R_Id : Restriction_Id;
4181 procedure Check_Unit_Name (N : Node_Id);
4182 -- Checks unit name parameter for No_Dependence. Returns if it has
4183 -- an appropriate form, otherwise raises pragma argument error.
4185 ---------------------
4186 -- Check_Unit_Name --
4187 ---------------------
4189 procedure Check_Unit_Name (N : Node_Id) is
4191 if Nkind (N) = N_Selected_Component then
4192 Check_Unit_Name (Prefix (N));
4193 Check_Unit_Name (Selector_Name (N));
4195 elsif Nkind (N) = N_Identifier then
4200 ("wrong form for unit name for No_Dependence", N);
4202 end Check_Unit_Name;
4204 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4207 Check_Ada_83_Warning;
4208 Check_At_Least_N_Arguments (1);
4209 Check_Valid_Configuration_Pragma;
4212 while Present (Arg) loop
4214 Expr := Expression (Arg);
4216 -- Case of no restriction identifier present
4218 if Id = No_Name then
4219 if Nkind (Expr) /= N_Identifier then
4221 ("invalid form for restriction", Arg);
4226 (Process_Restriction_Synonyms (Expr));
4228 if R_Id not in All_Boolean_Restrictions then
4229 Error_Msg_Name_1 := Pname;
4231 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4233 -- Check for possible misspelling
4235 for J in Restriction_Id loop
4237 Rnm : constant String := Restriction_Id'Image (J);
4240 Name_Buffer (1 .. Rnm'Length) := Rnm;
4241 Name_Len := Rnm'Length;
4242 Set_Casing (All_Lower_Case);
4244 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4246 (Identifier_Casing (Current_Source_File));
4247 Error_Msg_String (1 .. Rnm'Length) :=
4248 Name_Buffer (1 .. Name_Len);
4249 Error_Msg_Strlen := Rnm'Length;
4250 Error_Msg_N -- CODEFIX
4251 ("\possible misspelling of ""~""",
4252 Get_Pragma_Arg (Arg));
4261 if Implementation_Restriction (R_Id) then
4262 Check_Restriction (No_Implementation_Restrictions, Arg);
4265 -- If this is a warning, then set the warning unless we already
4266 -- have a real restriction active (we never want a warning to
4267 -- override a real restriction).
4270 if not Restriction_Active (R_Id) then
4271 Set_Restriction (R_Id, N);
4272 Restriction_Warnings (R_Id) := True;
4275 -- If real restriction case, then set it and make sure that the
4276 -- restriction warning flag is off, since a real restriction
4277 -- always overrides a warning.
4280 Set_Restriction (R_Id, N);
4281 Restriction_Warnings (R_Id) := False;
4284 -- A very special case that must be processed here: pragma
4285 -- Restrictions (No_Exceptions) turns off all run-time
4286 -- checking. This is a bit dubious in terms of the formal
4287 -- language definition, but it is what is intended by RM
4288 -- H.4(12). Restriction_Warnings never affects generated code
4289 -- so this is done only in the real restriction case.
4291 if R_Id = No_Exceptions and then not Warn then
4292 Scope_Suppress := (others => True);
4295 -- Case of No_Dependence => unit-name. Note that the parser
4296 -- already made the necessary entry in the No_Dependence table.
4298 elsif Id = Name_No_Dependence then
4299 Check_Unit_Name (Expr);
4301 -- All other cases of restriction identifier present
4304 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4305 Analyze_And_Resolve (Expr, Any_Integer);
4307 if R_Id not in All_Parameter_Restrictions then
4309 ("invalid restriction parameter identifier", Arg);
4311 elsif not Is_OK_Static_Expression (Expr) then
4312 Flag_Non_Static_Expr
4313 ("value must be static expression!", Expr);
4316 elsif not Is_Integer_Type (Etype (Expr))
4317 or else Expr_Value (Expr) < 0
4320 ("value must be non-negative integer", Arg);
4323 -- Restriction pragma is active
4325 Val := Expr_Value (Expr);
4327 if not UI_Is_In_Int_Range (Val) then
4329 ("pragma ignored, value too large?", Arg);
4332 -- Warning case. If the real restriction is active, then we
4333 -- ignore the request, since warning never overrides a real
4334 -- restriction. Otherwise we set the proper warning. Note that
4335 -- this circuit sets the warning again if it is already set,
4336 -- which is what we want, since the constant may have changed.
4339 if not Restriction_Active (R_Id) then
4341 (R_Id, N, Integer (UI_To_Int (Val)));
4342 Restriction_Warnings (R_Id) := True;
4345 -- Real restriction case, set restriction and make sure warning
4346 -- flag is off since real restriction always overrides warning.
4349 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4350 Restriction_Warnings (R_Id) := False;
4356 end Process_Restrictions_Or_Restriction_Warnings;
4358 ---------------------------------
4359 -- Process_Suppress_Unsuppress --
4360 ---------------------------------
4362 -- Note: this procedure makes entries in the check suppress data
4363 -- structures managed by Sem. See spec of package Sem for full
4364 -- details on how we handle recording of check suppression.
4366 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4371 In_Package_Spec : constant Boolean :=
4372 Is_Package_Or_Generic_Package (Current_Scope)
4373 and then not In_Package_Body (Current_Scope);
4375 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4376 -- Used to suppress a single check on the given entity
4378 --------------------------------
4379 -- Suppress_Unsuppress_Echeck --
4380 --------------------------------
4382 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4384 Set_Checks_May_Be_Suppressed (E);
4386 if In_Package_Spec then
4387 Push_Global_Suppress_Stack_Entry
4390 Suppress => Suppress_Case);
4393 Push_Local_Suppress_Stack_Entry
4396 Suppress => Suppress_Case);
4399 -- If this is a first subtype, and the base type is distinct,
4400 -- then also set the suppress flags on the base type.
4402 if Is_First_Subtype (E)
4403 and then Etype (E) /= E
4405 Suppress_Unsuppress_Echeck (Etype (E), C);
4407 end Suppress_Unsuppress_Echeck;
4409 -- Start of processing for Process_Suppress_Unsuppress
4412 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4413 -- declarative part or a package spec (RM 11.5(5)).
4415 if not Is_Configuration_Pragma then
4416 Check_Is_In_Decl_Part_Or_Package_Spec;
4419 Check_At_Least_N_Arguments (1);
4420 Check_At_Most_N_Arguments (2);
4421 Check_No_Identifier (Arg1);
4422 Check_Arg_Is_Identifier (Arg1);
4424 C := Get_Check_Id (Chars (Expression (Arg1)));
4426 if C = No_Check_Id then
4428 ("argument of pragma% is not valid check name", Arg1);
4431 if not Suppress_Case
4432 and then (C = All_Checks or else C = Overflow_Check)
4434 Opt.Overflow_Checks_Unsuppressed := True;
4437 if Arg_Count = 1 then
4439 -- Make an entry in the local scope suppress table. This is the
4440 -- table that directly shows the current value of the scope
4441 -- suppress check for any check id value.
4443 if C = All_Checks then
4445 -- For All_Checks, we set all specific predefined checks with
4446 -- the exception of Elaboration_Check, which is handled
4447 -- specially because of not wanting All_Checks to have the
4448 -- effect of deactivating static elaboration order processing.
4450 for J in Scope_Suppress'Range loop
4451 if J /= Elaboration_Check then
4452 Scope_Suppress (J) := Suppress_Case;
4456 -- If not All_Checks, and predefined check, then set appropriate
4457 -- scope entry. Note that we will set Elaboration_Check if this
4458 -- is explicitly specified.
4460 elsif C in Predefined_Check_Id then
4461 Scope_Suppress (C) := Suppress_Case;
4464 -- Also make an entry in the Local_Entity_Suppress table
4466 Push_Local_Suppress_Stack_Entry
4469 Suppress => Suppress_Case);
4471 -- Case of two arguments present, where the check is suppressed for
4472 -- a specified entity (given as the second argument of the pragma)
4475 Check_Optional_Identifier (Arg2, Name_On);
4476 E_Id := Expression (Arg2);
4479 if not Is_Entity_Name (E_Id) then
4481 ("second argument of pragma% must be entity name", Arg2);
4490 -- Enforce RM 11.5(7) which requires that for a pragma that
4491 -- appears within a package spec, the named entity must be
4492 -- within the package spec. We allow the package name itself
4493 -- to be mentioned since that makes sense, although it is not
4494 -- strictly allowed by 11.5(7).
4497 and then E /= Current_Scope
4498 and then Scope (E) /= Current_Scope
4501 ("entity in pragma% is not in package spec (RM 11.5(7))",
4505 -- Loop through homonyms. As noted below, in the case of a package
4506 -- spec, only homonyms within the package spec are considered.
4509 Suppress_Unsuppress_Echeck (E, C);
4511 if Is_Generic_Instance (E)
4512 and then Is_Subprogram (E)
4513 and then Present (Alias (E))
4515 Suppress_Unsuppress_Echeck (Alias (E), C);
4518 -- Move to next homonym
4523 -- If we are within a package specification, the pragma only
4524 -- applies to homonyms in the same scope.
4526 exit when In_Package_Spec
4527 and then Scope (E) /= Current_Scope;
4530 end Process_Suppress_Unsuppress;
4536 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4538 if Is_Imported (E) then
4540 ("cannot export entity& that was previously imported", Arg);
4542 elsif Present (Address_Clause (E)) then
4544 ("cannot export entity& that has an address clause", Arg);
4547 Set_Is_Exported (E);
4549 -- Generate a reference for entity explicitly, because the
4550 -- identifier may be overloaded and name resolution will not
4553 Generate_Reference (E, Arg);
4555 -- Deal with exporting non-library level entity
4557 if not Is_Library_Level_Entity (E) then
4559 -- Not allowed at all for subprograms
4561 if Is_Subprogram (E) then
4562 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4564 -- Otherwise set public and statically allocated
4568 Set_Is_Statically_Allocated (E);
4570 -- Warn if the corresponding W flag is set and the pragma comes
4571 -- from source. The latter may not be true e.g. on VMS where we
4572 -- expand export pragmas for exception codes associated with
4573 -- imported or exported exceptions. We do not want to generate
4574 -- a warning for something that the user did not write.
4576 if Warn_On_Export_Import
4577 and then Comes_From_Source (Arg)
4580 ("?& has been made static as a result of Export", Arg, E);
4582 ("\this usage is non-standard and non-portable", Arg);
4587 if Warn_On_Export_Import and then Is_Type (E) then
4589 ("exporting a type has no effect?", Arg, E);
4592 if Warn_On_Export_Import and Inside_A_Generic then
4594 ("all instances of& will have the same external name?", Arg, E);
4598 ----------------------------------------------
4599 -- Set_Extended_Import_Export_External_Name --
4600 ----------------------------------------------
4602 procedure Set_Extended_Import_Export_External_Name
4603 (Internal_Ent : Entity_Id;
4604 Arg_External : Node_Id)
4606 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4610 if No (Arg_External) then
4614 Check_Arg_Is_External_Name (Arg_External);
4616 if Nkind (Arg_External) = N_String_Literal then
4617 if String_Length (Strval (Arg_External)) = 0 then
4620 New_Name := Adjust_External_Name_Case (Arg_External);
4623 elsif Nkind (Arg_External) = N_Identifier then
4624 New_Name := Get_Default_External_Name (Arg_External);
4626 -- Check_Arg_Is_External_Name should let through only identifiers and
4627 -- string literals or static string expressions (which are folded to
4628 -- string literals).
4631 raise Program_Error;
4634 -- If we already have an external name set (by a prior normal Import
4635 -- or Export pragma), then the external names must match
4637 if Present (Interface_Name (Internal_Ent)) then
4638 Check_Matching_Internal_Names : declare
4639 S1 : constant String_Id := Strval (Old_Name);
4640 S2 : constant String_Id := Strval (New_Name);
4643 -- Called if names do not match
4649 procedure Mismatch is
4651 Error_Msg_Sloc := Sloc (Old_Name);
4653 ("external name does not match that given #",
4657 -- Start of processing for Check_Matching_Internal_Names
4660 if String_Length (S1) /= String_Length (S2) then
4664 for J in 1 .. String_Length (S1) loop
4665 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4670 end Check_Matching_Internal_Names;
4672 -- Otherwise set the given name
4675 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4676 Check_Duplicated_Export_Name (New_Name);
4678 end Set_Extended_Import_Export_External_Name;
4684 procedure Set_Imported (E : Entity_Id) is
4686 -- Error message if already imported or exported
4688 if Is_Exported (E) or else Is_Imported (E) then
4689 if Is_Exported (E) then
4690 Error_Msg_NE ("entity& was previously exported", N, E);
4692 Error_Msg_NE ("entity& was previously imported", N, E);
4695 Error_Msg_Name_1 := Pname;
4697 ("\(pragma% applies to all previous entities)", N);
4699 Error_Msg_Sloc := Sloc (E);
4700 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4702 -- Here if not previously imported or exported, OK to import
4705 Set_Is_Imported (E);
4707 -- If the entity is an object that is not at the library level,
4708 -- then it is statically allocated. We do not worry about objects
4709 -- with address clauses in this context since they are not really
4710 -- imported in the linker sense.
4713 and then not Is_Library_Level_Entity (E)
4714 and then No (Address_Clause (E))
4716 Set_Is_Statically_Allocated (E);
4721 -------------------------
4722 -- Set_Mechanism_Value --
4723 -------------------------
4725 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4726 -- analyzed, since it is semantic nonsense), so we get it in the exact
4727 -- form created by the parser.
4729 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4732 Mech_Name_Id : Name_Id;
4734 procedure Bad_Class;
4735 -- Signal bad descriptor class name
4737 procedure Bad_Mechanism;
4738 -- Signal bad mechanism name
4744 procedure Bad_Class is
4746 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4749 -------------------------
4750 -- Bad_Mechanism_Value --
4751 -------------------------
4753 procedure Bad_Mechanism is
4755 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4758 -- Start of processing for Set_Mechanism_Value
4761 if Mechanism (Ent) /= Default_Mechanism then
4763 ("mechanism for & has already been set", Mech_Name, Ent);
4766 -- MECHANISM_NAME ::= value | reference | descriptor |
4769 if Nkind (Mech_Name) = N_Identifier then
4770 if Chars (Mech_Name) = Name_Value then
4771 Set_Mechanism (Ent, By_Copy);
4774 elsif Chars (Mech_Name) = Name_Reference then
4775 Set_Mechanism (Ent, By_Reference);
4778 elsif Chars (Mech_Name) = Name_Descriptor then
4779 Check_VMS (Mech_Name);
4780 Set_Mechanism (Ent, By_Descriptor);
4783 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4784 Check_VMS (Mech_Name);
4785 Set_Mechanism (Ent, By_Short_Descriptor);
4788 elsif Chars (Mech_Name) = Name_Copy then
4790 ("bad mechanism name, Value assumed", Mech_Name);
4796 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4797 -- short_descriptor (CLASS_NAME)
4798 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4800 -- Note: this form is parsed as an indexed component
4802 elsif Nkind (Mech_Name) = N_Indexed_Component then
4804 Class := First (Expressions (Mech_Name));
4806 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4807 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4808 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4809 or else Present (Next (Class))
4813 Mech_Name_Id := Chars (Prefix (Mech_Name));
4816 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4817 -- short_descriptor (Class => CLASS_NAME)
4818 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4820 -- Note: this form is parsed as a function call
4822 elsif Nkind (Mech_Name) = N_Function_Call then
4824 Param := First (Parameter_Associations (Mech_Name));
4826 if Nkind (Name (Mech_Name)) /= N_Identifier
4827 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4828 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4829 or else Present (Next (Param))
4830 or else No (Selector_Name (Param))
4831 or else Chars (Selector_Name (Param)) /= Name_Class
4835 Class := Explicit_Actual_Parameter (Param);
4836 Mech_Name_Id := Chars (Name (Mech_Name));
4843 -- Fall through here with Class set to descriptor class name
4845 Check_VMS (Mech_Name);
4847 if Nkind (Class) /= N_Identifier then
4850 elsif Mech_Name_Id = Name_Descriptor
4851 and then Chars (Class) = Name_UBS
4853 Set_Mechanism (Ent, By_Descriptor_UBS);
4855 elsif Mech_Name_Id = Name_Descriptor
4856 and then Chars (Class) = Name_UBSB
4858 Set_Mechanism (Ent, By_Descriptor_UBSB);
4860 elsif Mech_Name_Id = Name_Descriptor
4861 and then Chars (Class) = Name_UBA
4863 Set_Mechanism (Ent, By_Descriptor_UBA);
4865 elsif Mech_Name_Id = Name_Descriptor
4866 and then Chars (Class) = Name_S
4868 Set_Mechanism (Ent, By_Descriptor_S);
4870 elsif Mech_Name_Id = Name_Descriptor
4871 and then Chars (Class) = Name_SB
4873 Set_Mechanism (Ent, By_Descriptor_SB);
4875 elsif Mech_Name_Id = Name_Descriptor
4876 and then Chars (Class) = Name_A
4878 Set_Mechanism (Ent, By_Descriptor_A);
4880 elsif Mech_Name_Id = Name_Descriptor
4881 and then Chars (Class) = Name_NCA
4883 Set_Mechanism (Ent, By_Descriptor_NCA);
4885 elsif Mech_Name_Id = Name_Short_Descriptor
4886 and then Chars (Class) = Name_UBS
4888 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4890 elsif Mech_Name_Id = Name_Short_Descriptor
4891 and then Chars (Class) = Name_UBSB
4893 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4895 elsif Mech_Name_Id = Name_Short_Descriptor
4896 and then Chars (Class) = Name_UBA
4898 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4900 elsif Mech_Name_Id = Name_Short_Descriptor
4901 and then Chars (Class) = Name_S
4903 Set_Mechanism (Ent, By_Short_Descriptor_S);
4905 elsif Mech_Name_Id = Name_Short_Descriptor
4906 and then Chars (Class) = Name_SB
4908 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4910 elsif Mech_Name_Id = Name_Short_Descriptor
4911 and then Chars (Class) = Name_A
4913 Set_Mechanism (Ent, By_Short_Descriptor_A);
4915 elsif Mech_Name_Id = Name_Short_Descriptor
4916 and then Chars (Class) = Name_NCA
4918 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4923 end Set_Mechanism_Value;
4925 ---------------------------
4926 -- Set_Ravenscar_Profile --
4927 ---------------------------
4929 -- The tasks to be done here are
4931 -- Set required policies
4933 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4934 -- pragma Locking_Policy (Ceiling_Locking)
4936 -- Set Detect_Blocking mode
4938 -- Set required restrictions (see System.Rident for detailed list)
4940 procedure Set_Ravenscar_Profile (N : Node_Id) is
4942 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4944 if Task_Dispatching_Policy /= ' '
4945 and then Task_Dispatching_Policy /= 'F'
4947 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4948 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4950 -- Set the FIFO_Within_Priorities policy, but always preserve
4951 -- System_Location since we like the error message with the run time
4955 Task_Dispatching_Policy := 'F';
4957 if Task_Dispatching_Policy_Sloc /= System_Location then
4958 Task_Dispatching_Policy_Sloc := Loc;
4962 -- pragma Locking_Policy (Ceiling_Locking)
4964 if Locking_Policy /= ' '
4965 and then Locking_Policy /= 'C'
4967 Error_Msg_Sloc := Locking_Policy_Sloc;
4968 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4970 -- Set the Ceiling_Locking policy, but preserve System_Location since
4971 -- we like the error message with the run time name.
4974 Locking_Policy := 'C';
4976 if Locking_Policy_Sloc /= System_Location then
4977 Locking_Policy_Sloc := Loc;
4981 -- pragma Detect_Blocking
4983 Detect_Blocking := True;
4985 -- Set the corresponding restrictions
4987 Set_Profile_Restrictions
4988 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4989 end Set_Ravenscar_Profile;
4991 -- Start of processing for Analyze_Pragma
4994 -- Deal with unrecognized pragma
4996 if not Is_Pragma_Name (Pname) then
4997 if Warn_On_Unrecognized_Pragma then
4998 Error_Msg_Name_1 := Pname;
4999 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5001 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5002 if Is_Bad_Spelling_Of (Pname, PN) then
5003 Error_Msg_Name_1 := PN;
5004 Error_Msg_N -- CODEFIX
5005 ("\?possible misspelling of %!", Pragma_Identifier (N));
5014 -- Here to start processing for recognized pragma
5016 Prag_Id := Get_Pragma_Id (Pname);
5025 if Present (Pragma_Argument_Associations (N)) then
5026 Arg1 := First (Pragma_Argument_Associations (N));
5028 if Present (Arg1) then
5029 Arg2 := Next (Arg1);
5031 if Present (Arg2) then
5032 Arg3 := Next (Arg2);
5034 if Present (Arg3) then
5035 Arg4 := Next (Arg3);
5041 -- Count number of arguments
5048 while Present (Arg_Node) loop
5049 Arg_Count := Arg_Count + 1;
5054 -- An enumeration type defines the pragmas that are supported by the
5055 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5056 -- into the corresponding enumeration value for the following case.
5064 -- pragma Abort_Defer;
5066 when Pragma_Abort_Defer =>
5068 Check_Arg_Count (0);
5070 -- The only required semantic processing is to check the
5071 -- placement. This pragma must appear at the start of the
5072 -- statement sequence of a handled sequence of statements.
5074 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5075 or else N /= First (Statements (Parent (N)))
5086 -- Note: this pragma also has some specific processing in Par.Prag
5087 -- because we want to set the Ada version mode during parsing.
5089 when Pragma_Ada_83 =>
5091 Check_Arg_Count (0);
5093 -- We really should check unconditionally for proper configuration
5094 -- pragma placement, since we really don't want mixed Ada modes
5095 -- within a single unit, and the GNAT reference manual has always
5096 -- said this was a configuration pragma, but we did not check and
5097 -- are hesitant to add the check now.
5099 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5100 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5102 if Ada_Version >= Ada_05 then
5103 Check_Valid_Configuration_Pragma;
5106 -- Now set Ada 83 mode
5108 Ada_Version := Ada_83;
5109 Ada_Version_Explicit := Ada_Version;
5117 -- Note: this pragma also has some specific processing in Par.Prag
5118 -- because we want to set the Ada 83 version mode during parsing.
5120 when Pragma_Ada_95 =>
5122 Check_Arg_Count (0);
5124 -- We really should check unconditionally for proper configuration
5125 -- pragma placement, since we really don't want mixed Ada modes
5126 -- within a single unit, and the GNAT reference manual has always
5127 -- said this was a configuration pragma, but we did not check and
5128 -- are hesitant to add the check now.
5130 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5131 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5133 if Ada_Version >= Ada_05 then
5134 Check_Valid_Configuration_Pragma;
5137 -- Now set Ada 95 mode
5139 Ada_Version := Ada_95;
5140 Ada_Version_Explicit := Ada_Version;
5142 ---------------------
5143 -- Ada_05/Ada_2005 --
5144 ---------------------
5147 -- pragma Ada_05 (LOCAL_NAME);
5150 -- pragma Ada_2005 (LOCAL_NAME):
5152 -- Note: these pragma also have some specific processing in Par.Prag
5153 -- because we want to set the Ada 2005 version mode during parsing.
5155 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5161 if Arg_Count = 1 then
5162 Check_Arg_Is_Local_Name (Arg1);
5163 E_Id := Expression (Arg1);
5165 if Etype (E_Id) = Any_Type then
5169 Set_Is_Ada_2005_Only (Entity (E_Id));
5172 Check_Arg_Count (0);
5174 -- For Ada_2005 we unconditionally enforce the documented
5175 -- configuration pragma placement, since we do not want to
5176 -- tolerate mixed modes in a unit involving Ada 2005. That
5177 -- would cause real difficulties for those cases where there
5178 -- are incompatibilities between Ada 95 and Ada 2005.
5180 Check_Valid_Configuration_Pragma;
5182 -- Now set Ada 2005 mode
5184 Ada_Version := Ada_05;
5185 Ada_Version_Explicit := Ada_05;
5189 ----------------------
5190 -- All_Calls_Remote --
5191 ----------------------
5193 -- pragma All_Calls_Remote [(library_package_NAME)];
5195 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5196 Lib_Entity : Entity_Id;
5199 Check_Ada_83_Warning;
5200 Check_Valid_Library_Unit_Pragma;
5202 if Nkind (N) = N_Null_Statement then
5206 Lib_Entity := Find_Lib_Unit_Name;
5208 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5210 if Present (Lib_Entity)
5211 and then not Debug_Flag_U
5213 if not Is_Remote_Call_Interface (Lib_Entity) then
5214 Error_Pragma ("pragma% only apply to rci unit");
5216 -- Set flag for entity of the library unit
5219 Set_Has_All_Calls_Remote (Lib_Entity);
5223 end All_Calls_Remote;
5229 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5230 -- ARG ::= NAME | EXPRESSION
5232 -- The first two arguments are by convention intended to refer to an
5233 -- external tool and a tool-specific function. These arguments are
5236 when Pragma_Annotate => Annotate : begin
5238 Check_At_Least_N_Arguments (1);
5239 Check_Arg_Is_Identifier (Arg1);
5246 -- Second unanalyzed parameter is optional
5252 while Present (Arg) loop
5253 Exp := Expression (Arg);
5256 if Is_Entity_Name (Exp) then
5259 elsif Nkind (Exp) = N_String_Literal then
5260 Resolve (Exp, Standard_String);
5262 elsif Is_Overloaded (Exp) then
5264 ("ambiguous argument for pragma%", Exp);
5280 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5281 -- [, [Message =>] Static_String_EXPRESSION]);
5283 when Pragma_Assert => Assert : declare
5289 Check_At_Least_N_Arguments (1);
5290 Check_At_Most_N_Arguments (2);
5291 Check_Arg_Order ((Name_Check, Name_Message));
5292 Check_Optional_Identifier (Arg1, Name_Check);
5294 -- We treat pragma Assert as equivalent to:
5296 -- pragma Check (Assertion, condition [, msg]);
5298 -- So rewrite pragma in this manner, and analyze the result
5300 Expr := Get_Pragma_Arg (Arg1);
5302 Make_Pragma_Argument_Association (Loc,
5304 Make_Identifier (Loc,
5305 Chars => Name_Assertion)),
5307 Make_Pragma_Argument_Association (Sloc (Expr),
5308 Expression => Expr));
5310 if Arg_Count > 1 then
5311 Check_Optional_Identifier (Arg2, Name_Message);
5312 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5313 Append_To (Newa, Relocate_Node (Arg2));
5318 Chars => Name_Check,
5319 Pragma_Argument_Associations => Newa));
5323 ----------------------
5324 -- Assertion_Policy --
5325 ----------------------
5327 -- pragma Assertion_Policy (Check | Ignore)
5329 when Pragma_Assertion_Policy => Assertion_Policy : declare
5334 Check_Valid_Configuration_Pragma;
5335 Check_Arg_Count (1);
5336 Check_No_Identifiers;
5337 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5339 -- We treat pragma Assertion_Policy as equivalent to:
5341 -- pragma Check_Policy (Assertion, policy)
5343 -- So rewrite the pragma in that manner and link on to the chain
5344 -- of Check_Policy pragmas, marking the pragma as analyzed.
5346 Policy := Get_Pragma_Arg (Arg1);
5350 Chars => Name_Check_Policy,
5352 Pragma_Argument_Associations => New_List (
5353 Make_Pragma_Argument_Association (Loc,
5355 Make_Identifier (Loc,
5356 Chars => Name_Assertion)),
5358 Make_Pragma_Argument_Association (Loc,
5360 Make_Identifier (Sloc (Policy),
5361 Chars => Chars (Policy))))));
5364 Set_Next_Pragma (N, Opt.Check_Policy_List);
5365 Opt.Check_Policy_List := N;
5366 end Assertion_Policy;
5368 ------------------------------
5369 -- Assume_No_Invalid_Values --
5370 ------------------------------
5372 -- pragma Assume_No_Invalid_Values (On | Off);
5374 when Pragma_Assume_No_Invalid_Values =>
5376 Check_Valid_Configuration_Pragma;
5377 Check_Arg_Count (1);
5378 Check_No_Identifiers;
5379 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5381 if Chars (Expression (Arg1)) = Name_On then
5382 Assume_No_Invalid_Values := True;
5384 Assume_No_Invalid_Values := False;
5391 -- pragma AST_Entry (entry_IDENTIFIER);
5393 when Pragma_AST_Entry => AST_Entry : declare
5399 Check_Arg_Count (1);
5400 Check_No_Identifiers;
5401 Check_Arg_Is_Local_Name (Arg1);
5402 Ent := Entity (Expression (Arg1));
5404 -- Note: the implementation of the AST_Entry pragma could handle
5405 -- the entry family case fine, but for now we are consistent with
5406 -- the DEC rules, and do not allow the pragma, which of course
5407 -- has the effect of also forbidding the attribute.
5409 if Ekind (Ent) /= E_Entry then
5411 ("pragma% argument must be simple entry name", Arg1);
5413 elsif Is_AST_Entry (Ent) then
5415 ("duplicate % pragma for entry", Arg1);
5417 elsif Has_Homonym (Ent) then
5419 ("pragma% argument cannot specify overloaded entry", Arg1);
5423 FF : constant Entity_Id := First_Formal (Ent);
5426 if Present (FF) then
5427 if Present (Next_Formal (FF)) then
5429 ("entry for pragma% can have only one argument",
5432 elsif Parameter_Mode (FF) /= E_In_Parameter then
5434 ("entry parameter for pragma% must have mode IN",
5440 Set_Is_AST_Entry (Ent);
5448 -- pragma Asynchronous (LOCAL_NAME);
5450 when Pragma_Asynchronous => Asynchronous : declare
5458 procedure Process_Async_Pragma;
5459 -- Common processing for procedure and access-to-procedure case
5461 --------------------------
5462 -- Process_Async_Pragma --
5463 --------------------------
5465 procedure Process_Async_Pragma is
5468 Set_Is_Asynchronous (Nm);
5472 -- The formals should be of mode IN (RM E.4.1(6))
5475 while Present (S) loop
5476 Formal := Defining_Identifier (S);
5478 if Nkind (Formal) = N_Defining_Identifier
5479 and then Ekind (Formal) /= E_In_Parameter
5482 ("pragma% procedure can only have IN parameter",
5489 Set_Is_Asynchronous (Nm);
5490 end Process_Async_Pragma;
5492 -- Start of processing for pragma Asynchronous
5495 Check_Ada_83_Warning;
5496 Check_No_Identifiers;
5497 Check_Arg_Count (1);
5498 Check_Arg_Is_Local_Name (Arg1);
5500 if Debug_Flag_U then
5504 C_Ent := Cunit_Entity (Current_Sem_Unit);
5505 Analyze (Expression (Arg1));
5506 Nm := Entity (Expression (Arg1));
5508 if not Is_Remote_Call_Interface (C_Ent)
5509 and then not Is_Remote_Types (C_Ent)
5511 -- This pragma should only appear in an RCI or Remote Types
5512 -- unit (RM E.4.1(4)).
5515 ("pragma% not in Remote_Call_Interface or " &
5516 "Remote_Types unit");
5519 if Ekind (Nm) = E_Procedure
5520 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5522 if not Is_Remote_Call_Interface (Nm) then
5524 ("pragma% cannot be applied on non-remote procedure",
5528 L := Parameter_Specifications (Parent (Nm));
5529 Process_Async_Pragma;
5532 elsif Ekind (Nm) = E_Function then
5534 ("pragma% cannot be applied to function", Arg1);
5536 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5538 if Is_Record_Type (Nm) then
5540 -- A record type that is the Equivalent_Type for a remote
5541 -- access-to-subprogram type.
5543 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5546 -- A non-expanded RAS type (distribution is not enabled)
5548 N := Declaration_Node (Nm);
5551 if Nkind (N) = N_Full_Type_Declaration
5552 and then Nkind (Type_Definition (N)) =
5553 N_Access_Procedure_Definition
5555 L := Parameter_Specifications (Type_Definition (N));
5556 Process_Async_Pragma;
5558 if Is_Asynchronous (Nm)
5559 and then Expander_Active
5560 and then Get_PCS_Name /= Name_No_DSA
5562 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5567 ("pragma% cannot reference access-to-function type",
5571 -- Only other possibility is Access-to-class-wide type
5573 elsif Is_Access_Type (Nm)
5574 and then Is_Class_Wide_Type (Designated_Type (Nm))
5576 Check_First_Subtype (Arg1);
5577 Set_Is_Asynchronous (Nm);
5578 if Expander_Active then
5579 RACW_Type_Is_Asynchronous (Nm);
5583 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5591 -- pragma Atomic (LOCAL_NAME);
5593 when Pragma_Atomic =>
5594 Process_Atomic_Shared_Volatile;
5596 -----------------------
5597 -- Atomic_Components --
5598 -----------------------
5600 -- pragma Atomic_Components (array_LOCAL_NAME);
5602 -- This processing is shared by Volatile_Components
5604 when Pragma_Atomic_Components |
5605 Pragma_Volatile_Components =>
5607 Atomic_Components : declare
5614 Check_Ada_83_Warning;
5615 Check_No_Identifiers;
5616 Check_Arg_Count (1);
5617 Check_Arg_Is_Local_Name (Arg1);
5618 E_Id := Expression (Arg1);
5620 if Etype (E_Id) = Any_Type then
5626 if Rep_Item_Too_Early (E, N)
5628 Rep_Item_Too_Late (E, N)
5633 D := Declaration_Node (E);
5636 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5638 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5639 and then Nkind (D) = N_Object_Declaration
5640 and then Nkind (Object_Definition (D)) =
5641 N_Constrained_Array_Definition)
5643 -- The flag is set on the object, or on the base type
5645 if Nkind (D) /= N_Object_Declaration then
5649 Set_Has_Volatile_Components (E);
5651 if Prag_Id = Pragma_Atomic_Components then
5652 Set_Has_Atomic_Components (E);
5654 if Is_Packed (E) then
5655 Set_Is_Packed (E, False);
5658 ("?Pack canceled, cannot pack atomic components",
5664 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5666 end Atomic_Components;
5668 --------------------
5669 -- Attach_Handler --
5670 --------------------
5672 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5674 when Pragma_Attach_Handler =>
5675 Check_Ada_83_Warning;
5676 Check_No_Identifiers;
5677 Check_Arg_Count (2);
5679 if No_Run_Time_Mode then
5680 Error_Msg_CRT ("Attach_Handler pragma", N);
5682 Check_Interrupt_Or_Attach_Handler;
5684 -- The expression that designates the attribute may
5685 -- depend on a discriminant, and is therefore a per-
5686 -- object expression, to be expanded in the init proc.
5687 -- If expansion is enabled, perform semantic checks
5690 if Expander_Active then
5692 Temp : constant Node_Id :=
5693 New_Copy_Tree (Expression (Arg2));
5695 Set_Parent (Temp, N);
5696 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5700 Analyze (Expression (Arg2));
5701 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5704 Process_Interrupt_Or_Attach_Handler;
5707 --------------------
5708 -- C_Pass_By_Copy --
5709 --------------------
5711 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5713 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5719 Check_Valid_Configuration_Pragma;
5720 Check_Arg_Count (1);
5721 Check_Optional_Identifier (Arg1, "max_size");
5723 Arg := Expression (Arg1);
5724 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5726 Val := Expr_Value (Arg);
5730 ("maximum size for pragma% must be positive", Arg1);
5732 elsif UI_Is_In_Int_Range (Val) then
5733 Default_C_Record_Mechanism := UI_To_Int (Val);
5735 -- If a giant value is given, Int'Last will do well enough.
5736 -- If sometime someone complains that a record larger than
5737 -- two gigabytes is not copied, we will worry about it then!
5740 Default_C_Record_Mechanism := Mechanism_Type'Last;
5748 -- pragma Check ([Name =>] Identifier,
5749 -- [Check =>] Boolean_Expression
5750 -- [,[Message =>] String_Expression]);
5752 when Pragma_Check => Check : declare
5757 -- Set True if category of assertions referenced by Name enabled
5761 Check_At_Least_N_Arguments (2);
5762 Check_At_Most_N_Arguments (3);
5763 Check_Optional_Identifier (Arg1, Name_Name);
5764 Check_Optional_Identifier (Arg2, Name_Check);
5766 if Arg_Count = 3 then
5767 Check_Optional_Identifier (Arg3, Name_Message);
5768 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5771 Check_Arg_Is_Identifier (Arg1);
5772 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5774 -- If expansion is active and the check is not enabled then we
5775 -- rewrite the Check as:
5777 -- if False and then condition then
5781 -- The reason we do this rewriting during semantic analysis rather
5782 -- than as part of normal expansion is that we cannot analyze and
5783 -- expand the code for the boolean expression directly, or it may
5784 -- cause insertion of actions that would escape the attempt to
5785 -- suppress the check code.
5787 -- Note that the Sloc for the if statement corresponds to the
5788 -- argument condition, not the pragma itself. The reason for this
5789 -- is that we may generate a warning if the condition is False at
5790 -- compile time, and we do not want to delete this warning when we
5791 -- delete the if statement.
5793 Expr := Expression (Arg2);
5795 if Expander_Active and then not Check_On then
5796 Eloc := Sloc (Expr);
5799 Make_If_Statement (Eloc,
5801 Make_And_Then (Eloc,
5802 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5803 Right_Opnd => Expr),
5804 Then_Statements => New_List (
5805 Make_Null_Statement (Eloc))));
5812 Analyze_And_Resolve (Expr, Any_Boolean);
5820 -- pragma Check_Name (check_IDENTIFIER);
5822 when Pragma_Check_Name =>
5823 Check_No_Identifiers;
5825 Check_Valid_Configuration_Pragma;
5826 Check_Arg_Count (1);
5827 Check_Arg_Is_Identifier (Arg1);
5830 Nam : constant Name_Id := Chars (Expression (Arg1));
5833 for J in Check_Names.First .. Check_Names.Last loop
5834 if Check_Names.Table (J) = Nam then
5839 Check_Names.Append (Nam);
5846 -- pragma Check_Policy (
5847 -- [Name =>] IDENTIFIER,
5848 -- [Policy =>] POLICY_IDENTIFIER);
5850 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5852 -- Note: this is a configuration pragma, but it is allowed to appear
5855 when Pragma_Check_Policy =>
5857 Check_Arg_Count (2);
5858 Check_Optional_Identifier (Arg1, Name_Name);
5859 Check_Optional_Identifier (Arg2, Name_Policy);
5861 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5863 -- A Check_Policy pragma can appear either as a configuration
5864 -- pragma, or in a declarative part or a package spec (see RM
5865 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5866 -- followed for Check_Policy).
5868 if not Is_Configuration_Pragma then
5869 Check_Is_In_Decl_Part_Or_Package_Spec;
5872 Set_Next_Pragma (N, Opt.Check_Policy_List);
5873 Opt.Check_Policy_List := N;
5875 ---------------------
5876 -- CIL_Constructor --
5877 ---------------------
5879 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5881 -- Processing for this pragma is shared with Java_Constructor
5887 -- pragma Comment (static_string_EXPRESSION)
5889 -- Processing for pragma Comment shares the circuitry for pragma
5890 -- Ident. The only differences are that Ident enforces a limit of 31
5891 -- characters on its argument, and also enforces limitations on
5892 -- placement for DEC compatibility. Pragma Comment shares neither of
5893 -- these restrictions.
5899 -- pragma Common_Object (
5900 -- [Internal =>] LOCAL_NAME
5901 -- [, [External =>] EXTERNAL_SYMBOL]
5902 -- [, [Size =>] EXTERNAL_SYMBOL]);
5904 -- Processing for this pragma is shared with Psect_Object
5906 ------------------------
5907 -- Compile_Time_Error --
5908 ------------------------
5910 -- pragma Compile_Time_Error
5911 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5913 when Pragma_Compile_Time_Error =>
5915 Process_Compile_Time_Warning_Or_Error;
5917 --------------------------
5918 -- Compile_Time_Warning --
5919 --------------------------
5921 -- pragma Compile_Time_Warning
5922 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5924 when Pragma_Compile_Time_Warning =>
5926 Process_Compile_Time_Warning_Or_Error;
5932 when Pragma_Compiler_Unit =>
5934 Check_Arg_Count (0);
5935 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5937 -----------------------------
5938 -- Complete_Representation --
5939 -----------------------------
5941 -- pragma Complete_Representation;
5943 when Pragma_Complete_Representation =>
5945 Check_Arg_Count (0);
5947 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5949 ("pragma & must appear within record representation clause");
5952 ----------------------------
5953 -- Complex_Representation --
5954 ----------------------------
5956 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5958 when Pragma_Complex_Representation => Complex_Representation : declare
5965 Check_Arg_Count (1);
5966 Check_Optional_Identifier (Arg1, Name_Entity);
5967 Check_Arg_Is_Local_Name (Arg1);
5968 E_Id := Expression (Arg1);
5970 if Etype (E_Id) = Any_Type then
5976 if not Is_Record_Type (E) then
5978 ("argument for pragma% must be record type", Arg1);
5981 Ent := First_Entity (E);
5984 or else No (Next_Entity (Ent))
5985 or else Present (Next_Entity (Next_Entity (Ent)))
5986 or else not Is_Floating_Point_Type (Etype (Ent))
5987 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5990 ("record for pragma% must have two fields of the same "
5991 & "floating-point type", Arg1);
5994 Set_Has_Complex_Representation (Base_Type (E));
5996 -- We need to treat the type has having a non-standard
5997 -- representation, for back-end purposes, even though in
5998 -- general a complex will have the default representation
5999 -- of a record with two real components.
6001 Set_Has_Non_Standard_Rep (Base_Type (E));
6003 end Complex_Representation;
6005 -------------------------
6006 -- Component_Alignment --
6007 -------------------------
6009 -- pragma Component_Alignment (
6010 -- [Form =>] ALIGNMENT_CHOICE
6011 -- [, [Name =>] type_LOCAL_NAME]);
6013 -- ALIGNMENT_CHOICE ::=
6015 -- | Component_Size_4
6019 when Pragma_Component_Alignment => Component_AlignmentP : declare
6020 Args : Args_List (1 .. 2);
6021 Names : constant Name_List (1 .. 2) := (
6025 Form : Node_Id renames Args (1);
6026 Name : Node_Id renames Args (2);
6028 Atype : Component_Alignment_Kind;
6033 Gather_Associations (Names, Args);
6036 Error_Pragma ("missing Form argument for pragma%");
6039 Check_Arg_Is_Identifier (Form);
6041 -- Get proper alignment, note that Default = Component_Size on all
6042 -- machines we have so far, and we want to set this value rather
6043 -- than the default value to indicate that it has been explicitly
6044 -- set (and thus will not get overridden by the default component
6045 -- alignment for the current scope)
6047 if Chars (Form) = Name_Component_Size then
6048 Atype := Calign_Component_Size;
6050 elsif Chars (Form) = Name_Component_Size_4 then
6051 Atype := Calign_Component_Size_4;
6053 elsif Chars (Form) = Name_Default then
6054 Atype := Calign_Component_Size;
6056 elsif Chars (Form) = Name_Storage_Unit then
6057 Atype := Calign_Storage_Unit;
6061 ("invalid Form parameter for pragma%", Form);
6064 -- Case with no name, supplied, affects scope table entry
6068 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6070 -- Case of name supplied
6073 Check_Arg_Is_Local_Name (Name);
6075 Typ := Entity (Name);
6078 or else Rep_Item_Too_Early (Typ, N)
6082 Typ := Underlying_Type (Typ);
6085 if not Is_Record_Type (Typ)
6086 and then not Is_Array_Type (Typ)
6089 ("Name parameter of pragma% must identify record or " &
6090 "array type", Name);
6093 -- An explicit Component_Alignment pragma overrides an
6094 -- implicit pragma Pack, but not an explicit one.
6096 if not Has_Pragma_Pack (Base_Type (Typ)) then
6097 Set_Is_Packed (Base_Type (Typ), False);
6098 Set_Component_Alignment (Base_Type (Typ), Atype);
6101 end Component_AlignmentP;
6107 -- pragma Controlled (first_subtype_LOCAL_NAME);
6109 when Pragma_Controlled => Controlled : declare
6113 Check_No_Identifiers;
6114 Check_Arg_Count (1);
6115 Check_Arg_Is_Local_Name (Arg1);
6116 Arg := Expression (Arg1);
6118 if not Is_Entity_Name (Arg)
6119 or else not Is_Access_Type (Entity (Arg))
6121 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6123 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6131 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6132 -- [Entity =>] LOCAL_NAME);
6134 when Pragma_Convention => Convention : declare
6137 pragma Warnings (Off, C);
6138 pragma Warnings (Off, E);
6140 Check_Arg_Order ((Name_Convention, Name_Entity));
6141 Check_Ada_83_Warning;
6142 Check_Arg_Count (2);
6143 Process_Convention (C, E);
6146 ---------------------------
6147 -- Convention_Identifier --
6148 ---------------------------
6150 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6151 -- [Convention =>] convention_IDENTIFIER);
6153 when Pragma_Convention_Identifier => Convention_Identifier : declare
6159 Check_Arg_Order ((Name_Name, Name_Convention));
6160 Check_Arg_Count (2);
6161 Check_Optional_Identifier (Arg1, Name_Name);
6162 Check_Optional_Identifier (Arg2, Name_Convention);
6163 Check_Arg_Is_Identifier (Arg1);
6164 Check_Arg_Is_Identifier (Arg2);
6165 Idnam := Chars (Expression (Arg1));
6166 Cname := Chars (Expression (Arg2));
6168 if Is_Convention_Name (Cname) then
6169 Record_Convention_Identifier
6170 (Idnam, Get_Convention_Id (Cname));
6173 ("second arg for % pragma must be convention", Arg2);
6175 end Convention_Identifier;
6181 -- pragma CPP_Class ([Entity =>] local_NAME)
6183 when Pragma_CPP_Class => CPP_Class : declare
6188 if Warn_On_Obsolescent_Feature then
6190 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6191 " by pragma import?", N);
6195 Check_Arg_Count (1);
6196 Check_Optional_Identifier (Arg1, Name_Entity);
6197 Check_Arg_Is_Local_Name (Arg1);
6199 Arg := Expression (Arg1);
6202 if Etype (Arg) = Any_Type then
6206 if not Is_Entity_Name (Arg)
6207 or else not Is_Type (Entity (Arg))
6209 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6212 Typ := Entity (Arg);
6214 if not Is_Tagged_Type (Typ) then
6215 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6218 -- Types treated as CPP classes are treated as limited, but we
6219 -- don't require them to be declared this way. A warning is issued
6220 -- to encourage the user to declare them as limited. This is not
6221 -- an error, for compatibility reasons, because these types have
6222 -- been supported this way for some time.
6224 if not Is_Limited_Type (Typ) then
6226 ("imported 'C'P'P type should be " &
6227 "explicitly declared limited?",
6228 Get_Pragma_Arg (Arg1));
6230 ("\type will be considered limited",
6231 Get_Pragma_Arg (Arg1));
6234 Set_Is_CPP_Class (Typ);
6235 Set_Is_Limited_Record (Typ);
6236 Set_Convention (Typ, Convention_CPP);
6238 -- Imported CPP types must not have discriminants (because C++
6239 -- classes do not have discriminants).
6241 if Has_Discriminants (Typ) then
6243 ("imported 'C'P'P type cannot have discriminants",
6244 First (Discriminant_Specifications
6245 (Declaration_Node (Typ))));
6248 -- Components of imported CPP types must not have default
6249 -- expressions because the constructor (if any) is in the
6252 if Is_Incomplete_Or_Private_Type (Typ)
6253 and then No (Underlying_Type (Typ))
6255 -- It should be an error to apply pragma CPP to a private
6256 -- type if the underlying type is not visible (as it is
6257 -- for any representation item). For now, for backward
6258 -- compatibility we do nothing but we cannot check components
6259 -- because they are not available at this stage. All this code
6260 -- will be removed when we cleanup this obsolete GNAT pragma???
6266 Tdef : constant Node_Id :=
6267 Type_Definition (Declaration_Node (Typ));
6272 if Nkind (Tdef) = N_Record_Definition then
6273 Clist := Component_List (Tdef);
6275 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6276 Clist := Component_List (Record_Extension_Part (Tdef));
6279 if Present (Clist) then
6280 Comp := First (Component_Items (Clist));
6281 while Present (Comp) loop
6282 if Present (Expression (Comp)) then
6284 ("component of imported 'C'P'P type cannot have" &
6285 " default expression", Expression (Comp));
6295 ---------------------
6296 -- CPP_Constructor --
6297 ---------------------
6299 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6300 -- [, [External_Name =>] static_string_EXPRESSION ]
6301 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6303 when Pragma_CPP_Constructor => CPP_Constructor : declare
6307 Tag_Typ : Entity_Id;
6311 Check_At_Least_N_Arguments (1);
6312 Check_At_Most_N_Arguments (3);
6313 Check_Optional_Identifier (Arg1, Name_Entity);
6314 Check_Arg_Is_Local_Name (Arg1);
6316 Id := Expression (Arg1);
6317 Find_Program_Unit_Name (Id);
6319 -- If we did not find the name, we are done
6321 if Etype (Id) = Any_Type then
6325 Def_Id := Entity (Id);
6327 if Ekind (Def_Id) = E_Function
6328 and then (Is_CPP_Class (Etype (Def_Id))
6329 or else (Is_Class_Wide_Type (Etype (Def_Id))
6331 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6333 if Arg_Count >= 2 then
6334 Set_Imported (Def_Id);
6335 Set_Is_Public (Def_Id);
6336 Process_Interface_Name (Def_Id, Arg2, Arg3);
6339 Set_Has_Completion (Def_Id);
6340 Set_Is_Constructor (Def_Id);
6342 -- Imported C++ constructors are not dispatching primitives
6343 -- because in C++ they don't have a dispatch table slot.
6344 -- However, in Ada the constructor has the profile of a
6345 -- function that returns a tagged type and therefore it has
6346 -- been treated as a primitive operation during semantic
6347 -- analysis. We now remove it from the list of primitive
6348 -- operations of the type.
6350 if Is_Tagged_Type (Etype (Def_Id))
6351 and then not Is_Class_Wide_Type (Etype (Def_Id))
6353 pragma Assert (Is_Dispatching_Operation (Def_Id));
6354 Tag_Typ := Etype (Def_Id);
6356 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6357 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6361 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6362 Set_Is_Dispatching_Operation (Def_Id, False);
6365 -- For backward compatibility, if the constructor returns a
6366 -- class wide type, and we internally change the return type to
6367 -- the corresponding root type.
6369 if Is_Class_Wide_Type (Etype (Def_Id)) then
6370 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6374 ("pragma% requires function returning a 'C'P'P_Class type",
6377 end CPP_Constructor;
6383 when Pragma_CPP_Virtual => CPP_Virtual : declare
6387 if Warn_On_Obsolescent_Feature then
6389 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6398 when Pragma_CPP_Vtable => CPP_Vtable : declare
6402 if Warn_On_Obsolescent_Feature then
6404 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6413 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6415 when Pragma_Debug => Debug : declare
6423 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6426 if Arg_Count = 2 then
6429 Left_Opnd => Relocate_Node (Cond),
6430 Right_Opnd => Expression (Arg1));
6433 -- Rewrite into a conditional with an appropriate condition. We
6434 -- wrap the procedure call in a block so that overhead from e.g.
6435 -- use of the secondary stack does not generate execution overhead
6436 -- for suppressed conditions.
6438 Rewrite (N, Make_Implicit_If_Statement (N,
6440 Then_Statements => New_List (
6441 Make_Block_Statement (Loc,
6442 Handled_Statement_Sequence =>
6443 Make_Handled_Sequence_Of_Statements (Loc,
6444 Statements => New_List (
6445 Relocate_Node (Debug_Statement (N))))))));
6453 -- pragma Debug_Policy (Check | Ignore)
6455 when Pragma_Debug_Policy =>
6457 Check_Arg_Count (1);
6458 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6459 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6461 ---------------------
6462 -- Detect_Blocking --
6463 ---------------------
6465 -- pragma Detect_Blocking;
6467 when Pragma_Detect_Blocking =>
6469 Check_Arg_Count (0);
6470 Check_Valid_Configuration_Pragma;
6471 Detect_Blocking := True;
6477 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6479 when Pragma_Discard_Names => Discard_Names : declare
6484 Check_Ada_83_Warning;
6486 -- Deal with configuration pragma case
6488 if Arg_Count = 0 and then Is_Configuration_Pragma then
6489 Global_Discard_Names := True;
6492 -- Otherwise, check correct appropriate context
6495 Check_Is_In_Decl_Part_Or_Package_Spec;
6497 if Arg_Count = 0 then
6499 -- If there is no parameter, then from now on this pragma
6500 -- applies to any enumeration, exception or tagged type
6501 -- defined in the current declarative part, and recursively
6502 -- to any nested scope.
6504 Set_Discard_Names (Current_Scope);
6508 Check_Arg_Count (1);
6509 Check_Optional_Identifier (Arg1, Name_On);
6510 Check_Arg_Is_Local_Name (Arg1);
6512 E_Id := Expression (Arg1);
6514 if Etype (E_Id) = Any_Type then
6520 if (Is_First_Subtype (E)
6522 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6523 or else Ekind (E) = E_Exception
6525 Set_Discard_Names (E);
6528 ("inappropriate entity for pragma%", Arg1);
6539 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6541 when Pragma_Elaborate => Elaborate : declare
6546 -- Pragma must be in context items list of a compilation unit
6548 if not Is_In_Context_Clause then
6552 -- Must be at least one argument
6554 if Arg_Count = 0 then
6555 Error_Pragma ("pragma% requires at least one argument");
6558 -- In Ada 83 mode, there can be no items following it in the
6559 -- context list except other pragmas and implicit with clauses
6560 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6561 -- placement rule does not apply.
6563 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6565 while Present (Citem) loop
6566 if Nkind (Citem) = N_Pragma
6567 or else (Nkind (Citem) = N_With_Clause
6568 and then Implicit_With (Citem))
6573 ("(Ada 83) pragma% must be at end of context clause");
6580 -- Finally, the arguments must all be units mentioned in a with
6581 -- clause in the same context clause. Note we already checked (in
6582 -- Par.Prag) that the arguments are all identifiers or selected
6586 Outer : while Present (Arg) loop
6587 Citem := First (List_Containing (N));
6588 Inner : while Citem /= N loop
6589 if Nkind (Citem) = N_With_Clause
6590 and then Same_Name (Name (Citem), Expression (Arg))
6592 Set_Elaborate_Present (Citem, True);
6593 Set_Unit_Name (Expression (Arg), Name (Citem));
6595 -- With the pragma present, elaboration calls on
6596 -- subprograms from the named unit need no further
6597 -- checks, as long as the pragma appears in the current
6598 -- compilation unit. If the pragma appears in some unit
6599 -- in the context, there might still be a need for an
6600 -- Elaborate_All_Desirable from the current compilation
6601 -- to the named unit, so we keep the check enabled.
6603 if In_Extended_Main_Source_Unit (N) then
6604 Set_Suppress_Elaboration_Warnings
6605 (Entity (Name (Citem)));
6616 ("argument of pragma% is not with'ed unit", Arg);
6622 -- Give a warning if operating in static mode with -gnatwl
6623 -- (elaboration warnings enabled) switch set.
6625 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6627 ("?use of pragma Elaborate may not be safe", N);
6629 ("?use pragma Elaborate_All instead if possible", N);
6637 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6639 when Pragma_Elaborate_All => Elaborate_All : declare
6644 Check_Ada_83_Warning;
6646 -- Pragma must be in context items list of a compilation unit
6648 if not Is_In_Context_Clause then
6652 -- Must be at least one argument
6654 if Arg_Count = 0 then
6655 Error_Pragma ("pragma% requires at least one argument");
6658 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6659 -- have to appear at the end of the context clause, but may
6660 -- appear mixed in with other items, even in Ada 83 mode.
6662 -- Final check: the arguments must all be units mentioned in
6663 -- a with clause in the same context clause. Note that we
6664 -- already checked (in Par.Prag) that all the arguments are
6665 -- either identifiers or selected components.
6668 Outr : while Present (Arg) loop
6669 Citem := First (List_Containing (N));
6670 Innr : while Citem /= N loop
6671 if Nkind (Citem) = N_With_Clause
6672 and then Same_Name (Name (Citem), Expression (Arg))
6674 Set_Elaborate_All_Present (Citem, True);
6675 Set_Unit_Name (Expression (Arg), Name (Citem));
6677 -- Suppress warnings and elaboration checks on the named
6678 -- unit if the pragma is in the current compilation, as
6679 -- for pragma Elaborate.
6681 if In_Extended_Main_Source_Unit (N) then
6682 Set_Suppress_Elaboration_Warnings
6683 (Entity (Name (Citem)));
6692 Set_Error_Posted (N);
6694 ("argument of pragma% is not with'ed unit", Arg);
6701 --------------------
6702 -- Elaborate_Body --
6703 --------------------
6705 -- pragma Elaborate_Body [( library_unit_NAME )];
6707 when Pragma_Elaborate_Body => Elaborate_Body : declare
6708 Cunit_Node : Node_Id;
6709 Cunit_Ent : Entity_Id;
6712 Check_Ada_83_Warning;
6713 Check_Valid_Library_Unit_Pragma;
6715 if Nkind (N) = N_Null_Statement then
6719 Cunit_Node := Cunit (Current_Sem_Unit);
6720 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6722 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6725 Error_Pragma ("pragma% must refer to a spec, not a body");
6727 Set_Body_Required (Cunit_Node, True);
6728 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6730 -- If we are in dynamic elaboration mode, then we suppress
6731 -- elaboration warnings for the unit, since it is definitely
6732 -- fine NOT to do dynamic checks at the first level (and such
6733 -- checks will be suppressed because no elaboration boolean
6734 -- is created for Elaborate_Body packages).
6736 -- But in the static model of elaboration, Elaborate_Body is
6737 -- definitely NOT good enough to ensure elaboration safety on
6738 -- its own, since the body may WITH other units that are not
6739 -- safe from an elaboration point of view, so a client must
6740 -- still do an Elaborate_All on such units.
6742 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6743 -- Elaborate_Body always suppressed elab warnings.
6745 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6746 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6751 ------------------------
6752 -- Elaboration_Checks --
6753 ------------------------
6755 -- pragma Elaboration_Checks (Static | Dynamic);
6757 when Pragma_Elaboration_Checks =>
6759 Check_Arg_Count (1);
6760 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6761 Dynamic_Elaboration_Checks :=
6762 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6768 -- pragma Eliminate (
6769 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6770 -- [,[Entity =>] IDENTIFIER |
6771 -- SELECTED_COMPONENT |
6773 -- [, OVERLOADING_RESOLUTION]);
6775 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6778 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6781 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6783 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6784 -- Result_Type => result_SUBTYPE_NAME]
6786 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6787 -- SUBTYPE_NAME ::= STRING_LITERAL
6789 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6790 -- SOURCE_TRACE ::= STRING_LITERAL
6792 when Pragma_Eliminate => Eliminate : declare
6793 Args : Args_List (1 .. 5);
6794 Names : constant Name_List (1 .. 5) := (
6797 Name_Parameter_Types,
6799 Name_Source_Location);
6801 Unit_Name : Node_Id renames Args (1);
6802 Entity : Node_Id renames Args (2);
6803 Parameter_Types : Node_Id renames Args (3);
6804 Result_Type : Node_Id renames Args (4);
6805 Source_Location : Node_Id renames Args (5);
6809 Check_Valid_Configuration_Pragma;
6810 Gather_Associations (Names, Args);
6812 if No (Unit_Name) then
6813 Error_Pragma ("missing Unit_Name argument for pragma%");
6817 and then (Present (Parameter_Types)
6819 Present (Result_Type)
6821 Present (Source_Location))
6823 Error_Pragma ("missing Entity argument for pragma%");
6826 if (Present (Parameter_Types)
6828 Present (Result_Type))
6830 Present (Source_Location)
6833 ("parameter profile and source location cannot " &
6834 "be used together in pragma%");
6837 Process_Eliminate_Pragma
6851 -- [ Convention =>] convention_IDENTIFIER,
6852 -- [ Entity =>] local_NAME
6853 -- [, [External_Name =>] static_string_EXPRESSION ]
6854 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6856 when Pragma_Export => Export : declare
6860 pragma Warnings (Off, C);
6863 Check_Ada_83_Warning;
6869 Check_At_Least_N_Arguments (2);
6870 Check_At_Most_N_Arguments (4);
6871 Process_Convention (C, Def_Id);
6873 if Ekind (Def_Id) /= E_Constant then
6874 Note_Possible_Modification (Expression (Arg2), Sure => False);
6877 Process_Interface_Name (Def_Id, Arg3, Arg4);
6878 Set_Exported (Def_Id, Arg2);
6880 -- If the entity is a deferred constant, propagate the information
6881 -- to the full view, because gigi elaborates the full view only.
6883 if Ekind (Def_Id) = E_Constant
6884 and then Present (Full_View (Def_Id))
6887 Id2 : constant Entity_Id := Full_View (Def_Id);
6889 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6890 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6891 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6896 ----------------------
6897 -- Export_Exception --
6898 ----------------------
6900 -- pragma Export_Exception (
6901 -- [Internal =>] LOCAL_NAME
6902 -- [, [External =>] EXTERNAL_SYMBOL]
6903 -- [, [Form =>] Ada | VMS]
6904 -- [, [Code =>] static_integer_EXPRESSION]);
6906 when Pragma_Export_Exception => Export_Exception : declare
6907 Args : Args_List (1 .. 4);
6908 Names : constant Name_List (1 .. 4) := (
6914 Internal : Node_Id renames Args (1);
6915 External : Node_Id renames Args (2);
6916 Form : Node_Id renames Args (3);
6917 Code : Node_Id renames Args (4);
6922 if Inside_A_Generic then
6923 Error_Pragma ("pragma% cannot be used for generic entities");
6926 Gather_Associations (Names, Args);
6927 Process_Extended_Import_Export_Exception_Pragma (
6928 Arg_Internal => Internal,
6929 Arg_External => External,
6933 if not Is_VMS_Exception (Entity (Internal)) then
6934 Set_Exported (Entity (Internal), Internal);
6936 end Export_Exception;
6938 ---------------------
6939 -- Export_Function --
6940 ---------------------
6942 -- pragma Export_Function (
6943 -- [Internal =>] LOCAL_NAME
6944 -- [, [External =>] EXTERNAL_SYMBOL]
6945 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6946 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6947 -- [, [Mechanism =>] MECHANISM]
6948 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6950 -- EXTERNAL_SYMBOL ::=
6952 -- | static_string_EXPRESSION
6954 -- PARAMETER_TYPES ::=
6956 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6958 -- TYPE_DESIGNATOR ::=
6960 -- | subtype_Name ' Access
6964 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6966 -- MECHANISM_ASSOCIATION ::=
6967 -- [formal_parameter_NAME =>] MECHANISM_NAME
6969 -- MECHANISM_NAME ::=
6972 -- | Descriptor [([Class =>] CLASS_NAME)]
6974 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6976 when Pragma_Export_Function => Export_Function : declare
6977 Args : Args_List (1 .. 6);
6978 Names : constant Name_List (1 .. 6) := (
6981 Name_Parameter_Types,
6984 Name_Result_Mechanism);
6986 Internal : Node_Id renames Args (1);
6987 External : Node_Id renames Args (2);
6988 Parameter_Types : Node_Id renames Args (3);
6989 Result_Type : Node_Id renames Args (4);
6990 Mechanism : Node_Id renames Args (5);
6991 Result_Mechanism : Node_Id renames Args (6);
6995 Gather_Associations (Names, Args);
6996 Process_Extended_Import_Export_Subprogram_Pragma (
6997 Arg_Internal => Internal,
6998 Arg_External => External,
6999 Arg_Parameter_Types => Parameter_Types,
7000 Arg_Result_Type => Result_Type,
7001 Arg_Mechanism => Mechanism,
7002 Arg_Result_Mechanism => Result_Mechanism);
7003 end Export_Function;
7009 -- pragma Export_Object (
7010 -- [Internal =>] LOCAL_NAME
7011 -- [, [External =>] EXTERNAL_SYMBOL]
7012 -- [, [Size =>] EXTERNAL_SYMBOL]);
7014 -- EXTERNAL_SYMBOL ::=
7016 -- | static_string_EXPRESSION
7018 -- PARAMETER_TYPES ::=
7020 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7022 -- TYPE_DESIGNATOR ::=
7024 -- | subtype_Name ' Access
7028 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7030 -- MECHANISM_ASSOCIATION ::=
7031 -- [formal_parameter_NAME =>] MECHANISM_NAME
7033 -- MECHANISM_NAME ::=
7036 -- | Descriptor [([Class =>] CLASS_NAME)]
7038 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7040 when Pragma_Export_Object => Export_Object : declare
7041 Args : Args_List (1 .. 3);
7042 Names : constant Name_List (1 .. 3) := (
7047 Internal : Node_Id renames Args (1);
7048 External : Node_Id renames Args (2);
7049 Size : Node_Id renames Args (3);
7053 Gather_Associations (Names, Args);
7054 Process_Extended_Import_Export_Object_Pragma (
7055 Arg_Internal => Internal,
7056 Arg_External => External,
7060 ----------------------
7061 -- Export_Procedure --
7062 ----------------------
7064 -- pragma Export_Procedure (
7065 -- [Internal =>] LOCAL_NAME
7066 -- [, [External =>] EXTERNAL_SYMBOL]
7067 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7068 -- [, [Mechanism =>] MECHANISM]);
7070 -- EXTERNAL_SYMBOL ::=
7072 -- | static_string_EXPRESSION
7074 -- PARAMETER_TYPES ::=
7076 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7078 -- TYPE_DESIGNATOR ::=
7080 -- | subtype_Name ' Access
7084 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7086 -- MECHANISM_ASSOCIATION ::=
7087 -- [formal_parameter_NAME =>] MECHANISM_NAME
7089 -- MECHANISM_NAME ::=
7092 -- | Descriptor [([Class =>] CLASS_NAME)]
7094 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7096 when Pragma_Export_Procedure => Export_Procedure : declare
7097 Args : Args_List (1 .. 4);
7098 Names : constant Name_List (1 .. 4) := (
7101 Name_Parameter_Types,
7104 Internal : Node_Id renames Args (1);
7105 External : Node_Id renames Args (2);
7106 Parameter_Types : Node_Id renames Args (3);
7107 Mechanism : Node_Id renames Args (4);
7111 Gather_Associations (Names, Args);
7112 Process_Extended_Import_Export_Subprogram_Pragma (
7113 Arg_Internal => Internal,
7114 Arg_External => External,
7115 Arg_Parameter_Types => Parameter_Types,
7116 Arg_Mechanism => Mechanism);
7117 end Export_Procedure;
7123 -- pragma Export_Value (
7124 -- [Value =>] static_integer_EXPRESSION,
7125 -- [Link_Name =>] static_string_EXPRESSION);
7127 when Pragma_Export_Value =>
7129 Check_Arg_Order ((Name_Value, Name_Link_Name));
7130 Check_Arg_Count (2);
7132 Check_Optional_Identifier (Arg1, Name_Value);
7133 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7135 Check_Optional_Identifier (Arg2, Name_Link_Name);
7136 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7138 -----------------------------
7139 -- Export_Valued_Procedure --
7140 -----------------------------
7142 -- pragma Export_Valued_Procedure (
7143 -- [Internal =>] LOCAL_NAME
7144 -- [, [External =>] EXTERNAL_SYMBOL,]
7145 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7146 -- [, [Mechanism =>] MECHANISM]);
7148 -- EXTERNAL_SYMBOL ::=
7150 -- | static_string_EXPRESSION
7152 -- PARAMETER_TYPES ::=
7154 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7156 -- TYPE_DESIGNATOR ::=
7158 -- | subtype_Name ' Access
7162 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7164 -- MECHANISM_ASSOCIATION ::=
7165 -- [formal_parameter_NAME =>] MECHANISM_NAME
7167 -- MECHANISM_NAME ::=
7170 -- | Descriptor [([Class =>] CLASS_NAME)]
7172 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7174 when Pragma_Export_Valued_Procedure =>
7175 Export_Valued_Procedure : declare
7176 Args : Args_List (1 .. 4);
7177 Names : constant Name_List (1 .. 4) := (
7180 Name_Parameter_Types,
7183 Internal : Node_Id renames Args (1);
7184 External : Node_Id renames Args (2);
7185 Parameter_Types : Node_Id renames Args (3);
7186 Mechanism : Node_Id renames Args (4);
7190 Gather_Associations (Names, Args);
7191 Process_Extended_Import_Export_Subprogram_Pragma (
7192 Arg_Internal => Internal,
7193 Arg_External => External,
7194 Arg_Parameter_Types => Parameter_Types,
7195 Arg_Mechanism => Mechanism);
7196 end Export_Valued_Procedure;
7202 -- pragma Extend_System ([Name =>] Identifier);
7204 when Pragma_Extend_System => Extend_System : declare
7207 Check_Valid_Configuration_Pragma;
7208 Check_Arg_Count (1);
7209 Check_Optional_Identifier (Arg1, Name_Name);
7210 Check_Arg_Is_Identifier (Arg1);
7212 Get_Name_String (Chars (Expression (Arg1)));
7215 and then Name_Buffer (1 .. 4) = "aux_"
7217 if Present (System_Extend_Pragma_Arg) then
7218 if Chars (Expression (Arg1)) =
7219 Chars (Expression (System_Extend_Pragma_Arg))
7223 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7224 Error_Pragma ("pragma% conflicts with that #");
7228 System_Extend_Pragma_Arg := Arg1;
7230 if not GNAT_Mode then
7231 System_Extend_Unit := Arg1;
7235 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7239 ------------------------
7240 -- Extensions_Allowed --
7241 ------------------------
7243 -- pragma Extensions_Allowed (ON | OFF);
7245 when Pragma_Extensions_Allowed =>
7247 Check_Arg_Count (1);
7248 Check_No_Identifiers;
7249 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7251 if Chars (Expression (Arg1)) = Name_On then
7252 Extensions_Allowed := True;
7254 Extensions_Allowed := False;
7261 -- pragma External (
7262 -- [ Convention =>] convention_IDENTIFIER,
7263 -- [ Entity =>] local_NAME
7264 -- [, [External_Name =>] static_string_EXPRESSION ]
7265 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7267 when Pragma_External => External : declare
7271 pragma Warnings (Off, C);
7280 Check_At_Least_N_Arguments (2);
7281 Check_At_Most_N_Arguments (4);
7282 Process_Convention (C, Def_Id);
7283 Note_Possible_Modification (Expression (Arg2), Sure => False);
7284 Process_Interface_Name (Def_Id, Arg3, Arg4);
7285 Set_Exported (Def_Id, Arg2);
7288 --------------------------
7289 -- External_Name_Casing --
7290 --------------------------
7292 -- pragma External_Name_Casing (
7293 -- UPPERCASE | LOWERCASE
7294 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7296 when Pragma_External_Name_Casing => External_Name_Casing : declare
7299 Check_No_Identifiers;
7301 if Arg_Count = 2 then
7303 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7305 case Chars (Get_Pragma_Arg (Arg2)) is
7307 Opt.External_Name_Exp_Casing := As_Is;
7309 when Name_Uppercase =>
7310 Opt.External_Name_Exp_Casing := Uppercase;
7312 when Name_Lowercase =>
7313 Opt.External_Name_Exp_Casing := Lowercase;
7320 Check_Arg_Count (1);
7323 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7325 case Chars (Get_Pragma_Arg (Arg1)) is
7326 when Name_Uppercase =>
7327 Opt.External_Name_Imp_Casing := Uppercase;
7329 when Name_Lowercase =>
7330 Opt.External_Name_Imp_Casing := Lowercase;
7335 end External_Name_Casing;
7337 --------------------------
7338 -- Favor_Top_Level --
7339 --------------------------
7341 -- pragma Favor_Top_Level (type_NAME);
7343 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7344 Named_Entity : Entity_Id;
7348 Check_No_Identifiers;
7349 Check_Arg_Count (1);
7350 Check_Arg_Is_Local_Name (Arg1);
7351 Named_Entity := Entity (Expression (Arg1));
7353 -- If it's an access-to-subprogram type (in particular, not a
7354 -- subtype), set the flag on that type.
7356 if Is_Access_Subprogram_Type (Named_Entity) then
7357 Set_Can_Use_Internal_Rep (Named_Entity, False);
7359 -- Otherwise it's an error (name denotes the wrong sort of entity)
7363 ("access-to-subprogram type expected", Expression (Arg1));
7365 end Favor_Top_Level;
7371 -- pragma Fast_Math;
7373 when Pragma_Fast_Math =>
7375 Check_No_Identifiers;
7376 Check_Valid_Configuration_Pragma;
7379 ---------------------------
7380 -- Finalize_Storage_Only --
7381 ---------------------------
7383 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7385 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7386 Assoc : constant Node_Id := Arg1;
7387 Type_Id : constant Node_Id := Expression (Assoc);
7392 Check_No_Identifiers;
7393 Check_Arg_Count (1);
7394 Check_Arg_Is_Local_Name (Arg1);
7396 Find_Type (Type_Id);
7397 Typ := Entity (Type_Id);
7400 or else Rep_Item_Too_Early (Typ, N)
7404 Typ := Underlying_Type (Typ);
7407 if not Is_Controlled (Typ) then
7408 Error_Pragma ("pragma% must specify controlled type");
7411 Check_First_Subtype (Arg1);
7413 if Finalize_Storage_Only (Typ) then
7414 Error_Pragma ("duplicate pragma%, only one allowed");
7416 elsif not Rep_Item_Too_Late (Typ, N) then
7417 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7419 end Finalize_Storage;
7421 --------------------------
7422 -- Float_Representation --
7423 --------------------------
7425 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7427 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7429 when Pragma_Float_Representation => Float_Representation : declare
7437 if Arg_Count = 1 then
7438 Check_Valid_Configuration_Pragma;
7440 Check_Arg_Count (2);
7441 Check_Optional_Identifier (Arg2, Name_Entity);
7442 Check_Arg_Is_Local_Name (Arg2);
7445 Check_No_Identifier (Arg1);
7446 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7448 if not OpenVMS_On_Target then
7449 if Chars (Expression (Arg1)) = Name_VAX_Float then
7451 ("?pragma% ignored (applies only to Open'V'M'S)");
7457 -- One argument case
7459 if Arg_Count = 1 then
7460 if Chars (Expression (Arg1)) = Name_VAX_Float then
7461 if Opt.Float_Format = 'I' then
7462 Error_Pragma ("'I'E'E'E format previously specified");
7465 Opt.Float_Format := 'V';
7468 if Opt.Float_Format = 'V' then
7469 Error_Pragma ("'V'A'X format previously specified");
7472 Opt.Float_Format := 'I';
7475 Set_Standard_Fpt_Formats;
7477 -- Two argument case
7480 Argx := Get_Pragma_Arg (Arg2);
7482 if not Is_Entity_Name (Argx)
7483 or else not Is_Floating_Point_Type (Entity (Argx))
7486 ("second argument of% pragma must be floating-point type",
7490 Ent := Entity (Argx);
7491 Digs := UI_To_Int (Digits_Value (Ent));
7493 -- Two arguments, VAX_Float case
7495 if Chars (Expression (Arg1)) = Name_VAX_Float then
7497 when 6 => Set_F_Float (Ent);
7498 when 9 => Set_D_Float (Ent);
7499 when 15 => Set_G_Float (Ent);
7503 ("wrong digits value, must be 6,9 or 15", Arg2);
7506 -- Two arguments, IEEE_Float case
7510 when 6 => Set_IEEE_Short (Ent);
7511 when 15 => Set_IEEE_Long (Ent);
7515 ("wrong digits value, must be 6 or 15", Arg2);
7519 end Float_Representation;
7525 -- pragma Ident (static_string_EXPRESSION)
7527 -- Note: pragma Comment shares this processing. Pragma Comment is
7528 -- identical to Ident, except that the restriction of the argument to
7529 -- 31 characters and the placement restrictions are not enforced for
7532 when Pragma_Ident | Pragma_Comment => Ident : declare
7537 Check_Arg_Count (1);
7538 Check_No_Identifiers;
7539 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7541 -- For pragma Ident, preserve DEC compatibility by requiring the
7542 -- pragma to appear in a declarative part or package spec.
7544 if Prag_Id = Pragma_Ident then
7545 Check_Is_In_Decl_Part_Or_Package_Spec;
7548 Str := Expr_Value_S (Expression (Arg1));
7555 GP := Parent (Parent (N));
7557 if Nkind_In (GP, N_Package_Declaration,
7558 N_Generic_Package_Declaration)
7563 -- If we have a compilation unit, then record the ident value,
7564 -- checking for improper duplication.
7566 if Nkind (GP) = N_Compilation_Unit then
7567 CS := Ident_String (Current_Sem_Unit);
7569 if Present (CS) then
7571 -- For Ident, we do not permit multiple instances
7573 if Prag_Id = Pragma_Ident then
7574 Error_Pragma ("duplicate% pragma not permitted");
7576 -- For Comment, we concatenate the string, unless we want
7577 -- to preserve the tree structure for ASIS.
7579 elsif not ASIS_Mode then
7580 Start_String (Strval (CS));
7581 Store_String_Char (' ');
7582 Store_String_Chars (Strval (Str));
7583 Set_Strval (CS, End_String);
7587 -- In VMS, the effect of IDENT is achieved by passing
7588 -- IDENTIFICATION=name as a --for-linker switch.
7590 if OpenVMS_On_Target then
7593 ("--for-linker=IDENTIFICATION=");
7594 String_To_Name_Buffer (Strval (Str));
7595 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7597 -- Only the last processed IDENT is saved. The main
7598 -- purpose is so an IDENT associated with a main
7599 -- procedure will be used in preference to an IDENT
7600 -- associated with a with'd package.
7602 Replace_Linker_Option_String
7603 (End_String, "--for-linker=IDENTIFICATION=");
7606 Set_Ident_String (Current_Sem_Unit, Str);
7609 -- For subunits, we just ignore the Ident, since in GNAT these
7610 -- are not separate object files, and hence not separate units
7611 -- in the unit table.
7613 elsif Nkind (GP) = N_Subunit then
7616 -- Otherwise we have a misplaced pragma Ident, but we ignore
7617 -- this if we are in an instantiation, since it comes from
7618 -- a generic, and has no relevance to the instantiation.
7620 elsif Prag_Id = Pragma_Ident then
7621 if Instantiation_Location (Loc) = No_Location then
7622 Error_Pragma ("pragma% only allowed at outer level");
7628 --------------------------
7629 -- Implemented_By_Entry --
7630 --------------------------
7632 -- pragma Implemented_By_Entry (DIRECT_NAME);
7634 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7639 Check_Arg_Count (1);
7640 Check_No_Identifiers;
7641 Check_Arg_Is_Identifier (Arg1);
7642 Check_Arg_Is_Local_Name (Arg1);
7643 Ent := Entity (Expression (Arg1));
7645 -- Pragma Implemented_By_Entry must be applied only to protected
7646 -- synchronized or task interface primitives.
7648 if (Ekind (Ent) /= E_Function
7649 and then Ekind (Ent) /= E_Procedure)
7650 or else not Present (First_Formal (Ent))
7651 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7654 ("pragma % must be applied to a concurrent interface " &
7658 if Einfo.Implemented_By_Entry (Ent)
7659 and then Warn_On_Redundant_Constructs
7661 Error_Pragma ("?duplicate pragma%!");
7663 Set_Implemented_By_Entry (Ent);
7666 end Implemented_By_Entry;
7668 -----------------------
7669 -- Implicit_Packing --
7670 -----------------------
7672 -- pragma Implicit_Packing;
7674 when Pragma_Implicit_Packing =>
7676 Check_Arg_Count (0);
7677 Implicit_Packing := True;
7684 -- [Convention =>] convention_IDENTIFIER,
7685 -- [Entity =>] local_NAME
7686 -- [, [External_Name =>] static_string_EXPRESSION ]
7687 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7689 when Pragma_Import =>
7690 Check_Ada_83_Warning;
7696 Check_At_Least_N_Arguments (2);
7697 Check_At_Most_N_Arguments (4);
7698 Process_Import_Or_Interface;
7700 ----------------------
7701 -- Import_Exception --
7702 ----------------------
7704 -- pragma Import_Exception (
7705 -- [Internal =>] LOCAL_NAME
7706 -- [, [External =>] EXTERNAL_SYMBOL]
7707 -- [, [Form =>] Ada | VMS]
7708 -- [, [Code =>] static_integer_EXPRESSION]);
7710 when Pragma_Import_Exception => Import_Exception : declare
7711 Args : Args_List (1 .. 4);
7712 Names : constant Name_List (1 .. 4) := (
7718 Internal : Node_Id renames Args (1);
7719 External : Node_Id renames Args (2);
7720 Form : Node_Id renames Args (3);
7721 Code : Node_Id renames Args (4);
7725 Gather_Associations (Names, Args);
7727 if Present (External) and then Present (Code) then
7729 ("cannot give both External and Code options for pragma%");
7732 Process_Extended_Import_Export_Exception_Pragma (
7733 Arg_Internal => Internal,
7734 Arg_External => External,
7738 if not Is_VMS_Exception (Entity (Internal)) then
7739 Set_Imported (Entity (Internal));
7741 end Import_Exception;
7743 ---------------------
7744 -- Import_Function --
7745 ---------------------
7747 -- pragma Import_Function (
7748 -- [Internal =>] LOCAL_NAME,
7749 -- [, [External =>] EXTERNAL_SYMBOL]
7750 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7751 -- [, [Result_Type =>] SUBTYPE_MARK]
7752 -- [, [Mechanism =>] MECHANISM]
7753 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7754 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7756 -- EXTERNAL_SYMBOL ::=
7758 -- | static_string_EXPRESSION
7760 -- PARAMETER_TYPES ::=
7762 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7764 -- TYPE_DESIGNATOR ::=
7766 -- | subtype_Name ' Access
7770 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7772 -- MECHANISM_ASSOCIATION ::=
7773 -- [formal_parameter_NAME =>] MECHANISM_NAME
7775 -- MECHANISM_NAME ::=
7778 -- | Descriptor [([Class =>] CLASS_NAME)]
7780 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7782 when Pragma_Import_Function => Import_Function : declare
7783 Args : Args_List (1 .. 7);
7784 Names : constant Name_List (1 .. 7) := (
7787 Name_Parameter_Types,
7790 Name_Result_Mechanism,
7791 Name_First_Optional_Parameter);
7793 Internal : Node_Id renames Args (1);
7794 External : Node_Id renames Args (2);
7795 Parameter_Types : Node_Id renames Args (3);
7796 Result_Type : Node_Id renames Args (4);
7797 Mechanism : Node_Id renames Args (5);
7798 Result_Mechanism : Node_Id renames Args (6);
7799 First_Optional_Parameter : Node_Id renames Args (7);
7803 Gather_Associations (Names, Args);
7804 Process_Extended_Import_Export_Subprogram_Pragma (
7805 Arg_Internal => Internal,
7806 Arg_External => External,
7807 Arg_Parameter_Types => Parameter_Types,
7808 Arg_Result_Type => Result_Type,
7809 Arg_Mechanism => Mechanism,
7810 Arg_Result_Mechanism => Result_Mechanism,
7811 Arg_First_Optional_Parameter => First_Optional_Parameter);
7812 end Import_Function;
7818 -- pragma Import_Object (
7819 -- [Internal =>] LOCAL_NAME
7820 -- [, [External =>] EXTERNAL_SYMBOL]
7821 -- [, [Size =>] EXTERNAL_SYMBOL]);
7823 -- EXTERNAL_SYMBOL ::=
7825 -- | static_string_EXPRESSION
7827 when Pragma_Import_Object => Import_Object : declare
7828 Args : Args_List (1 .. 3);
7829 Names : constant Name_List (1 .. 3) := (
7834 Internal : Node_Id renames Args (1);
7835 External : Node_Id renames Args (2);
7836 Size : Node_Id renames Args (3);
7840 Gather_Associations (Names, Args);
7841 Process_Extended_Import_Export_Object_Pragma (
7842 Arg_Internal => Internal,
7843 Arg_External => External,
7847 ----------------------
7848 -- Import_Procedure --
7849 ----------------------
7851 -- pragma Import_Procedure (
7852 -- [Internal =>] LOCAL_NAME
7853 -- [, [External =>] EXTERNAL_SYMBOL]
7854 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7855 -- [, [Mechanism =>] MECHANISM]
7856 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7858 -- EXTERNAL_SYMBOL ::=
7860 -- | static_string_EXPRESSION
7862 -- PARAMETER_TYPES ::=
7864 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7866 -- TYPE_DESIGNATOR ::=
7868 -- | subtype_Name ' Access
7872 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7874 -- MECHANISM_ASSOCIATION ::=
7875 -- [formal_parameter_NAME =>] MECHANISM_NAME
7877 -- MECHANISM_NAME ::=
7880 -- | Descriptor [([Class =>] CLASS_NAME)]
7882 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7884 when Pragma_Import_Procedure => Import_Procedure : declare
7885 Args : Args_List (1 .. 5);
7886 Names : constant Name_List (1 .. 5) := (
7889 Name_Parameter_Types,
7891 Name_First_Optional_Parameter);
7893 Internal : Node_Id renames Args (1);
7894 External : Node_Id renames Args (2);
7895 Parameter_Types : Node_Id renames Args (3);
7896 Mechanism : Node_Id renames Args (4);
7897 First_Optional_Parameter : Node_Id renames Args (5);
7901 Gather_Associations (Names, Args);
7902 Process_Extended_Import_Export_Subprogram_Pragma (
7903 Arg_Internal => Internal,
7904 Arg_External => External,
7905 Arg_Parameter_Types => Parameter_Types,
7906 Arg_Mechanism => Mechanism,
7907 Arg_First_Optional_Parameter => First_Optional_Parameter);
7908 end Import_Procedure;
7910 -----------------------------
7911 -- Import_Valued_Procedure --
7912 -----------------------------
7914 -- pragma Import_Valued_Procedure (
7915 -- [Internal =>] LOCAL_NAME
7916 -- [, [External =>] EXTERNAL_SYMBOL]
7917 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7918 -- [, [Mechanism =>] MECHANISM]
7919 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7921 -- EXTERNAL_SYMBOL ::=
7923 -- | static_string_EXPRESSION
7925 -- PARAMETER_TYPES ::=
7927 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7929 -- TYPE_DESIGNATOR ::=
7931 -- | subtype_Name ' Access
7935 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7937 -- MECHANISM_ASSOCIATION ::=
7938 -- [formal_parameter_NAME =>] MECHANISM_NAME
7940 -- MECHANISM_NAME ::=
7943 -- | Descriptor [([Class =>] CLASS_NAME)]
7945 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7947 when Pragma_Import_Valued_Procedure =>
7948 Import_Valued_Procedure : declare
7949 Args : Args_List (1 .. 5);
7950 Names : constant Name_List (1 .. 5) := (
7953 Name_Parameter_Types,
7955 Name_First_Optional_Parameter);
7957 Internal : Node_Id renames Args (1);
7958 External : Node_Id renames Args (2);
7959 Parameter_Types : Node_Id renames Args (3);
7960 Mechanism : Node_Id renames Args (4);
7961 First_Optional_Parameter : Node_Id renames Args (5);
7965 Gather_Associations (Names, Args);
7966 Process_Extended_Import_Export_Subprogram_Pragma (
7967 Arg_Internal => Internal,
7968 Arg_External => External,
7969 Arg_Parameter_Types => Parameter_Types,
7970 Arg_Mechanism => Mechanism,
7971 Arg_First_Optional_Parameter => First_Optional_Parameter);
7972 end Import_Valued_Procedure;
7974 ------------------------
7975 -- Initialize_Scalars --
7976 ------------------------
7978 -- pragma Initialize_Scalars;
7980 when Pragma_Initialize_Scalars =>
7982 Check_Arg_Count (0);
7983 Check_Valid_Configuration_Pragma;
7984 Check_Restriction (No_Initialize_Scalars, N);
7986 -- Initialize_Scalars creates false positives in CodePeer,
7987 -- so ignore this pragma in this mode.
7989 if not Restriction_Active (No_Initialize_Scalars)
7990 and then not CodePeer_Mode
7992 Init_Or_Norm_Scalars := True;
7993 Initialize_Scalars := True;
8000 -- pragma Inline ( NAME {, NAME} );
8002 when Pragma_Inline =>
8004 -- Pragma is active if inlining option is active
8006 Process_Inline (Inline_Active);
8012 -- pragma Inline_Always ( NAME {, NAME} );
8014 when Pragma_Inline_Always =>
8016 Process_Inline (True);
8018 --------------------
8019 -- Inline_Generic --
8020 --------------------
8022 -- pragma Inline_Generic (NAME {, NAME});
8024 when Pragma_Inline_Generic =>
8026 Process_Generic_List;
8028 ----------------------
8029 -- Inspection_Point --
8030 ----------------------
8032 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8034 when Pragma_Inspection_Point => Inspection_Point : declare
8039 if Arg_Count > 0 then
8042 Exp := Expression (Arg);
8045 if not Is_Entity_Name (Exp)
8046 or else not Is_Object (Entity (Exp))
8048 Error_Pragma_Arg ("object name required", Arg);
8055 end Inspection_Point;
8061 -- pragma Interface (
8062 -- [ Convention =>] convention_IDENTIFIER,
8063 -- [ Entity =>] local_NAME
8064 -- [, [External_Name =>] static_string_EXPRESSION ]
8065 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8067 when Pragma_Interface =>
8074 Check_At_Least_N_Arguments (2);
8075 Check_At_Most_N_Arguments (4);
8076 Process_Import_Or_Interface;
8078 --------------------
8079 -- Interface_Name --
8080 --------------------
8082 -- pragma Interface_Name (
8083 -- [ Entity =>] local_NAME
8084 -- [,[External_Name =>] static_string_EXPRESSION ]
8085 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8087 when Pragma_Interface_Name => Interface_Name : declare
8096 ((Name_Entity, Name_External_Name, Name_Link_Name));
8097 Check_At_Least_N_Arguments (2);
8098 Check_At_Most_N_Arguments (3);
8099 Id := Expression (Arg1);
8102 if not Is_Entity_Name (Id) then
8104 ("first argument for pragma% must be entity name", Arg1);
8105 elsif Etype (Id) = Any_Type then
8108 Def_Id := Entity (Id);
8111 -- Special DEC-compatible processing for the object case, forces
8112 -- object to be imported.
8114 if Ekind (Def_Id) = E_Variable then
8115 Kill_Size_Check_Code (Def_Id);
8116 Note_Possible_Modification (Id, Sure => False);
8118 -- Initialization is not allowed for imported variable
8120 if Present (Expression (Parent (Def_Id)))
8121 and then Comes_From_Source (Expression (Parent (Def_Id)))
8123 Error_Msg_Sloc := Sloc (Def_Id);
8125 ("no initialization allowed for declaration of& #",
8129 -- For compatibility, support VADS usage of providing both
8130 -- pragmas Interface and Interface_Name to obtain the effect
8131 -- of a single Import pragma.
8133 if Is_Imported (Def_Id)
8134 and then Present (First_Rep_Item (Def_Id))
8135 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8137 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8141 Set_Imported (Def_Id);
8144 Set_Is_Public (Def_Id);
8145 Process_Interface_Name (Def_Id, Arg2, Arg3);
8148 -- Otherwise must be subprogram
8150 elsif not Is_Subprogram (Def_Id) then
8152 ("argument of pragma% is not subprogram", Arg1);
8155 Check_At_Most_N_Arguments (3);
8159 -- Loop through homonyms
8162 Def_Id := Get_Base_Subprogram (Hom_Id);
8164 if Is_Imported (Def_Id) then
8165 Process_Interface_Name (Def_Id, Arg2, Arg3);
8169 Hom_Id := Homonym (Hom_Id);
8171 exit when No (Hom_Id)
8172 or else Scope (Hom_Id) /= Current_Scope;
8177 ("argument of pragma% is not imported subprogram",
8183 -----------------------
8184 -- Interrupt_Handler --
8185 -----------------------
8187 -- pragma Interrupt_Handler (handler_NAME);
8189 when Pragma_Interrupt_Handler =>
8190 Check_Ada_83_Warning;
8191 Check_Arg_Count (1);
8192 Check_No_Identifiers;
8194 if No_Run_Time_Mode then
8195 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8197 Check_Interrupt_Or_Attach_Handler;
8198 Process_Interrupt_Or_Attach_Handler;
8201 ------------------------
8202 -- Interrupt_Priority --
8203 ------------------------
8205 -- pragma Interrupt_Priority [(EXPRESSION)];
8207 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8208 P : constant Node_Id := Parent (N);
8212 Check_Ada_83_Warning;
8214 if Arg_Count /= 0 then
8215 Arg := Expression (Arg1);
8216 Check_Arg_Count (1);
8217 Check_No_Identifiers;
8219 -- The expression must be analyzed in the special manner
8220 -- described in "Handling of Default and Per-Object
8221 -- Expressions" in sem.ads.
8223 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8226 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8230 elsif Has_Priority_Pragma (P) then
8231 Error_Pragma ("duplicate pragma% not allowed");
8234 Set_Has_Priority_Pragma (P, True);
8235 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8237 end Interrupt_Priority;
8239 ---------------------
8240 -- Interrupt_State --
8241 ---------------------
8243 -- pragma Interrupt_State (
8244 -- [Name =>] INTERRUPT_ID,
8245 -- [State =>] INTERRUPT_STATE);
8247 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8248 -- INTERRUPT_STATE => System | Runtime | User
8250 -- Note: if the interrupt id is given as an identifier, then it must
8251 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8252 -- given as a static integer expression which must be in the range of
8253 -- Ada.Interrupts.Interrupt_ID.
8255 when Pragma_Interrupt_State => Interrupt_State : declare
8257 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8258 -- This is the entity Ada.Interrupts.Interrupt_ID;
8260 State_Type : Character;
8261 -- Set to 's'/'r'/'u' for System/Runtime/User
8264 -- Index to entry in Interrupt_States table
8267 -- Value of interrupt
8269 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8270 -- The first argument to the pragma
8272 Int_Ent : Entity_Id;
8273 -- Interrupt entity in Ada.Interrupts.Names
8277 Check_Arg_Order ((Name_Name, Name_State));
8278 Check_Arg_Count (2);
8280 Check_Optional_Identifier (Arg1, Name_Name);
8281 Check_Optional_Identifier (Arg2, Name_State);
8282 Check_Arg_Is_Identifier (Arg2);
8284 -- First argument is identifier
8286 if Nkind (Arg1X) = N_Identifier then
8288 -- Search list of names in Ada.Interrupts.Names
8290 Int_Ent := First_Entity (RTE (RE_Names));
8292 if No (Int_Ent) then
8293 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8295 elsif Chars (Int_Ent) = Chars (Arg1X) then
8296 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8300 Next_Entity (Int_Ent);
8303 -- First argument is not an identifier, so it must be a static
8304 -- expression of type Ada.Interrupts.Interrupt_ID.
8307 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8308 Int_Val := Expr_Value (Arg1X);
8310 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8312 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8315 ("value not in range of type " &
8316 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8322 case Chars (Get_Pragma_Arg (Arg2)) is
8323 when Name_Runtime => State_Type := 'r';
8324 when Name_System => State_Type := 's';
8325 when Name_User => State_Type := 'u';
8328 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8331 -- Check if entry is already stored
8333 IST_Num := Interrupt_States.First;
8335 -- If entry not found, add it
8337 if IST_Num > Interrupt_States.Last then
8338 Interrupt_States.Append
8339 ((Interrupt_Number => UI_To_Int (Int_Val),
8340 Interrupt_State => State_Type,
8341 Pragma_Loc => Loc));
8344 -- Case of entry for the same entry
8346 elsif Int_Val = Interrupt_States.Table (IST_Num).
8349 -- If state matches, done, no need to make redundant entry
8352 State_Type = Interrupt_States.Table (IST_Num).
8355 -- Otherwise if state does not match, error
8358 Interrupt_States.Table (IST_Num).Pragma_Loc;
8360 ("state conflicts with that given #", Arg2);
8364 IST_Num := IST_Num + 1;
8366 end Interrupt_State;
8368 ----------------------
8369 -- Java_Constructor --
8370 ----------------------
8372 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8374 -- Also handles pragma CIL_Constructor
8376 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8377 Java_Constructor : declare
8381 Convention : Convention_Id;
8385 Check_Arg_Count (1);
8386 Check_Optional_Identifier (Arg1, Name_Entity);
8387 Check_Arg_Is_Local_Name (Arg1);
8389 Id := Expression (Arg1);
8390 Find_Program_Unit_Name (Id);
8392 -- If we did not find the name, we are done
8394 if Etype (Id) = Any_Type then
8399 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8400 when Pragma_Java_Constructor => Convention := Convention_Java;
8401 when others => null;
8404 Hom_Id := Entity (Id);
8406 -- Loop through homonyms
8409 Def_Id := Get_Base_Subprogram (Hom_Id);
8411 -- The constructor is required to be a function returning an
8412 -- access type whose designated type has convention Java/CIL.
8414 if Ekind (Def_Id) = E_Function
8416 (Is_Value_Type (Etype (Def_Id))
8418 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8420 Atree.Convention (Etype (Def_Id)) = Convention)
8422 (Ekind (Etype (Def_Id)) in Access_Kind
8425 (Designated_Type (Etype (Def_Id))) = Convention
8428 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8431 Set_Is_Constructor (Def_Id);
8432 Set_Convention (Def_Id, Convention);
8433 Set_Is_Imported (Def_Id);
8436 if Convention = Convention_Java then
8438 ("pragma% requires function returning a " &
8439 "'Java access type", Arg1);
8441 pragma Assert (Convention = Convention_CIL);
8443 ("pragma% requires function returning a " &
8444 "'C'I'L access type", Arg1);
8448 Hom_Id := Homonym (Hom_Id);
8450 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8452 end Java_Constructor;
8454 ----------------------
8455 -- Java_Interface --
8456 ----------------------
8458 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8460 when Pragma_Java_Interface => Java_Interface : declare
8466 Check_Arg_Count (1);
8467 Check_Optional_Identifier (Arg1, Name_Entity);
8468 Check_Arg_Is_Local_Name (Arg1);
8470 Arg := Expression (Arg1);
8473 if Etype (Arg) = Any_Type then
8477 if not Is_Entity_Name (Arg)
8478 or else not Is_Type (Entity (Arg))
8480 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8483 Typ := Underlying_Type (Entity (Arg));
8485 -- For now simply check some of the semantic constraints on the
8486 -- type. This currently leaves out some restrictions on interface
8487 -- types, namely that the parent type must be java.lang.Object.Typ
8488 -- and that all primitives of the type should be declared
8491 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8492 Error_Pragma_Arg ("pragma% requires an abstract "
8493 & "tagged type", Arg1);
8495 elsif not Has_Discriminants (Typ)
8496 or else Ekind (Etype (First_Discriminant (Typ)))
8497 /= E_Anonymous_Access_Type
8499 not Is_Class_Wide_Type
8500 (Designated_Type (Etype (First_Discriminant (Typ))))
8503 ("type must have a class-wide access discriminant", Arg1);
8511 -- pragma Keep_Names ([On => ] local_NAME);
8513 when Pragma_Keep_Names => Keep_Names : declare
8518 Check_Arg_Count (1);
8519 Check_Optional_Identifier (Arg1, Name_On);
8520 Check_Arg_Is_Local_Name (Arg1);
8522 Arg := Expression (Arg1);
8525 if Etype (Arg) = Any_Type then
8529 if not Is_Entity_Name (Arg)
8530 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8533 ("pragma% requires a local enumeration type", Arg1);
8536 Set_Discard_Names (Entity (Arg), False);
8543 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8545 when Pragma_License =>
8547 Check_Arg_Count (1);
8548 Check_No_Identifiers;
8549 Check_Valid_Configuration_Pragma;
8550 Check_Arg_Is_Identifier (Arg1);
8553 Sind : constant Source_File_Index :=
8554 Source_Index (Current_Sem_Unit);
8557 case Chars (Get_Pragma_Arg (Arg1)) is
8559 Set_License (Sind, GPL);
8561 when Name_Modified_GPL =>
8562 Set_License (Sind, Modified_GPL);
8564 when Name_Restricted =>
8565 Set_License (Sind, Restricted);
8567 when Name_Unrestricted =>
8568 Set_License (Sind, Unrestricted);
8571 Error_Pragma_Arg ("invalid license name", Arg1);
8579 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8581 when Pragma_Link_With => Link_With : declare
8587 if Operating_Mode = Generate_Code
8588 and then In_Extended_Main_Source_Unit (N)
8590 Check_At_Least_N_Arguments (1);
8591 Check_No_Identifiers;
8592 Check_Is_In_Decl_Part_Or_Package_Spec;
8593 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8597 while Present (Arg) loop
8598 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8600 -- Store argument, converting sequences of spaces to a
8601 -- single null character (this is one of the differences
8602 -- in processing between Link_With and Linker_Options).
8605 C : constant Char_Code := Get_Char_Code (' ');
8606 S : constant String_Id :=
8607 Strval (Expr_Value_S (Expression (Arg)));
8608 L : constant Nat := String_Length (S);
8611 procedure Skip_Spaces;
8612 -- Advance F past any spaces
8618 procedure Skip_Spaces is
8620 while F <= L and then Get_String_Char (S, F) = C loop
8625 -- Start of processing for Arg_Store
8628 Skip_Spaces; -- skip leading spaces
8630 -- Loop through characters, changing any embedded
8631 -- sequence of spaces to a single null character (this
8632 -- is how Link_With/Linker_Options differ)
8635 if Get_String_Char (S, F) = C then
8638 Store_String_Char (ASCII.NUL);
8641 Store_String_Char (Get_String_Char (S, F));
8649 if Present (Arg) then
8650 Store_String_Char (ASCII.NUL);
8654 Store_Linker_Option_String (End_String);
8662 -- pragma Linker_Alias (
8663 -- [Entity =>] LOCAL_NAME
8664 -- [Target =>] static_string_EXPRESSION);
8666 when Pragma_Linker_Alias =>
8668 Check_Arg_Order ((Name_Entity, Name_Target));
8669 Check_Arg_Count (2);
8670 Check_Optional_Identifier (Arg1, Name_Entity);
8671 Check_Optional_Identifier (Arg2, Name_Target);
8672 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8673 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8675 -- The only processing required is to link this item on to the
8676 -- list of rep items for the given entity. This is accomplished
8677 -- by the call to Rep_Item_Too_Late (when no error is detected
8678 -- and False is returned).
8680 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8683 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8686 ------------------------
8687 -- Linker_Constructor --
8688 ------------------------
8690 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8692 -- Code is shared with Linker_Destructor
8694 -----------------------
8695 -- Linker_Destructor --
8696 -----------------------
8698 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8700 when Pragma_Linker_Constructor |
8701 Pragma_Linker_Destructor =>
8702 Linker_Constructor : declare
8708 Check_Arg_Count (1);
8709 Check_No_Identifiers;
8710 Check_Arg_Is_Local_Name (Arg1);
8711 Arg1_X := Expression (Arg1);
8713 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8715 if not Is_Library_Level_Entity (Proc) then
8717 ("argument for pragma% must be library level entity", Arg1);
8720 -- The only processing required is to link this item on to the
8721 -- list of rep items for the given entity. This is accomplished
8722 -- by the call to Rep_Item_Too_Late (when no error is detected
8723 -- and False is returned).
8725 if Rep_Item_Too_Late (Proc, N) then
8728 Set_Has_Gigi_Rep_Item (Proc);
8730 end Linker_Constructor;
8732 --------------------
8733 -- Linker_Options --
8734 --------------------
8736 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8738 when Pragma_Linker_Options => Linker_Options : declare
8742 Check_Ada_83_Warning;
8743 Check_No_Identifiers;
8744 Check_Arg_Count (1);
8745 Check_Is_In_Decl_Part_Or_Package_Spec;
8746 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8747 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8750 while Present (Arg) loop
8751 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8752 Store_String_Char (ASCII.NUL);
8753 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8757 if Operating_Mode = Generate_Code
8758 and then In_Extended_Main_Source_Unit (N)
8760 Store_Linker_Option_String (End_String);
8764 --------------------
8765 -- Linker_Section --
8766 --------------------
8768 -- pragma Linker_Section (
8769 -- [Entity =>] LOCAL_NAME
8770 -- [Section =>] static_string_EXPRESSION);
8772 when Pragma_Linker_Section =>
8774 Check_Arg_Order ((Name_Entity, Name_Section));
8775 Check_Arg_Count (2);
8776 Check_Optional_Identifier (Arg1, Name_Entity);
8777 Check_Optional_Identifier (Arg2, Name_Section);
8778 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8779 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8781 -- This pragma applies only to objects
8783 if not Is_Object (Entity (Expression (Arg1))) then
8784 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8787 -- The only processing required is to link this item on to the
8788 -- list of rep items for the given entity. This is accomplished
8789 -- by the call to Rep_Item_Too_Late (when no error is detected
8790 -- and False is returned).
8792 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8795 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8802 -- pragma List (On | Off)
8804 -- There is nothing to do here, since we did all the processing for
8805 -- this pragma in Par.Prag (so that it works properly even in syntax
8811 --------------------
8812 -- Locking_Policy --
8813 --------------------
8815 -- pragma Locking_Policy (policy_IDENTIFIER);
8817 when Pragma_Locking_Policy => declare
8821 Check_Ada_83_Warning;
8822 Check_Arg_Count (1);
8823 Check_No_Identifiers;
8824 Check_Arg_Is_Locking_Policy (Arg1);
8825 Check_Valid_Configuration_Pragma;
8826 Get_Name_String (Chars (Expression (Arg1)));
8827 LP := Fold_Upper (Name_Buffer (1));
8829 if Locking_Policy /= ' '
8830 and then Locking_Policy /= LP
8832 Error_Msg_Sloc := Locking_Policy_Sloc;
8833 Error_Pragma ("locking policy incompatible with policy#");
8835 -- Set new policy, but always preserve System_Location since we
8836 -- like the error message with the run time name.
8839 Locking_Policy := LP;
8841 if Locking_Policy_Sloc /= System_Location then
8842 Locking_Policy_Sloc := Loc;
8851 -- pragma Long_Float (D_Float | G_Float);
8853 when Pragma_Long_Float =>
8855 Check_Valid_Configuration_Pragma;
8856 Check_Arg_Count (1);
8857 Check_No_Identifier (Arg1);
8858 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8860 if not OpenVMS_On_Target then
8861 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8866 if Chars (Expression (Arg1)) = Name_D_Float then
8867 if Opt.Float_Format_Long = 'G' then
8868 Error_Pragma ("G_Float previously specified");
8871 Opt.Float_Format_Long := 'D';
8873 -- G_Float case (this is the default, does not need overriding)
8876 if Opt.Float_Format_Long = 'D' then
8877 Error_Pragma ("D_Float previously specified");
8880 Opt.Float_Format_Long := 'G';
8883 Set_Standard_Fpt_Formats;
8885 -----------------------
8886 -- Machine_Attribute --
8887 -----------------------
8889 -- pragma Machine_Attribute (
8890 -- [Entity =>] LOCAL_NAME,
8891 -- [Attribute_Name =>] static_string_EXPRESSION
8892 -- [, [Info =>] static_EXPRESSION] );
8894 when Pragma_Machine_Attribute => Machine_Attribute : declare
8899 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8901 if Arg_Count = 3 then
8902 Check_Optional_Identifier (Arg3, Name_Info);
8903 Check_Arg_Is_Static_Expression (Arg3);
8905 Check_Arg_Count (2);
8908 Check_Optional_Identifier (Arg1, Name_Entity);
8909 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8910 Check_Arg_Is_Local_Name (Arg1);
8911 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8912 Def_Id := Entity (Expression (Arg1));
8914 if Is_Access_Type (Def_Id) then
8915 Def_Id := Designated_Type (Def_Id);
8918 if Rep_Item_Too_Early (Def_Id, N) then
8922 Def_Id := Underlying_Type (Def_Id);
8924 -- The only processing required is to link this item on to the
8925 -- list of rep items for the given entity. This is accomplished
8926 -- by the call to Rep_Item_Too_Late (when no error is detected
8927 -- and False is returned).
8929 if Rep_Item_Too_Late (Def_Id, N) then
8932 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8934 end Machine_Attribute;
8941 -- (MAIN_OPTION [, MAIN_OPTION]);
8944 -- [STACK_SIZE =>] static_integer_EXPRESSION
8945 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8946 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8948 when Pragma_Main => Main : declare
8949 Args : Args_List (1 .. 3);
8950 Names : constant Name_List (1 .. 3) := (
8952 Name_Task_Stack_Size_Default,
8953 Name_Time_Slicing_Enabled);
8959 Gather_Associations (Names, Args);
8961 for J in 1 .. 2 loop
8962 if Present (Args (J)) then
8963 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8967 if Present (Args (3)) then
8968 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8972 while Present (Nod) loop
8973 if Nkind (Nod) = N_Pragma
8974 and then Pragma_Name (Nod) = Name_Main
8976 Error_Msg_Name_1 := Pname;
8977 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8988 -- pragma Main_Storage
8989 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8991 -- MAIN_STORAGE_OPTION ::=
8992 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8993 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8995 when Pragma_Main_Storage => Main_Storage : declare
8996 Args : Args_List (1 .. 2);
8997 Names : constant Name_List (1 .. 2) := (
8998 Name_Working_Storage,
9005 Gather_Associations (Names, Args);
9007 for J in 1 .. 2 loop
9008 if Present (Args (J)) then
9009 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9013 Check_In_Main_Program;
9016 while Present (Nod) loop
9017 if Nkind (Nod) = N_Pragma
9018 and then Pragma_Name (Nod) = Name_Main_Storage
9020 Error_Msg_Name_1 := Pname;
9021 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9032 -- pragma Memory_Size (NUMERIC_LITERAL)
9034 when Pragma_Memory_Size =>
9037 -- Memory size is simply ignored
9039 Check_No_Identifiers;
9040 Check_Arg_Count (1);
9041 Check_Arg_Is_Integer_Literal (Arg1);
9049 -- The only correct use of this pragma is on its own in a file, in
9050 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9051 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9052 -- check for a file containing nothing but a No_Body pragma). If we
9053 -- attempt to process it during normal semantics processing, it means
9054 -- it was misplaced.
9056 when Pragma_No_Body =>
9064 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9066 when Pragma_No_Return => No_Return : declare
9074 Check_At_Least_N_Arguments (1);
9076 -- Loop through arguments of pragma
9079 while Present (Arg) loop
9080 Check_Arg_Is_Local_Name (Arg);
9081 Id := Expression (Arg);
9084 if not Is_Entity_Name (Id) then
9085 Error_Pragma_Arg ("entity name required", Arg);
9088 if Etype (Id) = Any_Type then
9092 -- Loop to find matching procedures
9097 and then Scope (E) = Current_Scope
9099 if Ekind (E) = E_Procedure
9100 or else Ekind (E) = E_Generic_Procedure
9104 -- Set flag on any alias as well
9106 if Is_Overloadable (E) and then Present (Alias (E)) then
9107 Set_No_Return (Alias (E));
9117 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9128 -- pragma No_Run_Time;
9130 -- Note: this pragma is retained for backwards compatibility. See
9131 -- body of Rtsfind for full details on its handling.
9133 when Pragma_No_Run_Time =>
9135 Check_Valid_Configuration_Pragma;
9136 Check_Arg_Count (0);
9138 No_Run_Time_Mode := True;
9139 Configurable_Run_Time_Mode := True;
9141 -- Set Duration to 32 bits if word size is 32
9143 if Ttypes.System_Word_Size = 32 then
9144 Duration_32_Bits_On_Target := True;
9147 -- Set appropriate restrictions
9149 Set_Restriction (No_Finalization, N);
9150 Set_Restriction (No_Exception_Handlers, N);
9151 Set_Restriction (Max_Tasks, N, 0);
9152 Set_Restriction (No_Tasking, N);
9154 ------------------------
9155 -- No_Strict_Aliasing --
9156 ------------------------
9158 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9160 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9165 Check_At_Most_N_Arguments (1);
9167 if Arg_Count = 0 then
9168 Check_Valid_Configuration_Pragma;
9169 Opt.No_Strict_Aliasing := True;
9172 Check_Optional_Identifier (Arg2, Name_Entity);
9173 Check_Arg_Is_Local_Name (Arg1);
9174 E_Id := Entity (Expression (Arg1));
9176 if E_Id = Any_Type then
9178 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9179 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9182 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9184 end No_Strict_Aliasing;
9186 -----------------------
9187 -- Normalize_Scalars --
9188 -----------------------
9190 -- pragma Normalize_Scalars;
9192 when Pragma_Normalize_Scalars =>
9193 Check_Ada_83_Warning;
9194 Check_Arg_Count (0);
9195 Check_Valid_Configuration_Pragma;
9197 -- Normalize_Scalars creates false positives in CodePeer, so
9198 -- ignore this pragma in this mode.
9200 if not CodePeer_Mode then
9201 Normalize_Scalars := True;
9202 Init_Or_Norm_Scalars := True;
9209 -- pragma Obsolescent;
9211 -- pragma Obsolescent (
9212 -- [Message =>] static_string_EXPRESSION
9213 -- [,[Version =>] Ada_05]]);
9215 -- pragma Obsolescent (
9217 -- [,[Message =>] static_string_EXPRESSION
9218 -- [,[Version =>] Ada_05]] );
9220 when Pragma_Obsolescent => Obsolescent : declare
9224 procedure Set_Obsolescent (E : Entity_Id);
9225 -- Given an entity Ent, mark it as obsolescent if appropriate
9227 ---------------------
9228 -- Set_Obsolescent --
9229 ---------------------
9231 procedure Set_Obsolescent (E : Entity_Id) is
9240 -- Entity name was given
9242 if Present (Ename) then
9244 -- If entity name matches, we are fine. Save entity in
9245 -- pragma argument, for ASIS use.
9247 if Chars (Ename) = Chars (Ent) then
9248 Set_Entity (Ename, Ent);
9249 Generate_Reference (Ent, Ename);
9251 -- If entity name does not match, only possibility is an
9252 -- enumeration literal from an enumeration type declaration.
9254 elsif Ekind (Ent) /= E_Enumeration_Type then
9256 ("pragma % entity name does not match declaration");
9259 Ent := First_Literal (E);
9263 ("pragma % entity name does not match any " &
9264 "enumeration literal");
9266 elsif Chars (Ent) = Chars (Ename) then
9267 Set_Entity (Ename, Ent);
9268 Generate_Reference (Ent, Ename);
9272 Ent := Next_Literal (Ent);
9278 -- Ent points to entity to be marked
9280 if Arg_Count >= 1 then
9282 -- Deal with static string argument
9284 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9285 S := Strval (Expression (Arg1));
9287 for J in 1 .. String_Length (S) loop
9288 if not In_Character_Range (Get_String_Char (S, J)) then
9290 ("pragma% argument does not allow wide characters",
9295 Obsolescent_Warnings.Append
9296 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9298 -- Check for Ada_05 parameter
9300 if Arg_Count /= 1 then
9301 Check_Arg_Count (2);
9304 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9307 Check_Arg_Is_Identifier (Argx);
9309 if Chars (Argx) /= Name_Ada_05 then
9310 Error_Msg_Name_2 := Name_Ada_05;
9312 ("only allowed argument for pragma% is %", Argx);
9315 if Ada_Version_Explicit < Ada_05
9316 or else not Warn_On_Ada_2005_Compatibility
9324 -- Set flag if pragma active
9327 Set_Is_Obsolescent (Ent);
9331 end Set_Obsolescent;
9333 -- Start of processing for pragma Obsolescent
9338 Check_At_Most_N_Arguments (3);
9340 -- See if first argument specifies an entity name
9344 (Chars (Arg1) = Name_Entity
9346 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9350 Ename := Get_Pragma_Arg (Arg1);
9352 -- Eliminate first argument, so we can share processing
9356 Arg_Count := Arg_Count - 1;
9358 -- No Entity name argument given
9364 if Arg_Count >= 1 then
9365 Check_Optional_Identifier (Arg1, Name_Message);
9367 if Arg_Count = 2 then
9368 Check_Optional_Identifier (Arg2, Name_Version);
9372 -- Get immediately preceding declaration
9375 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9379 -- Cases where we do not follow anything other than another pragma
9383 -- First case: library level compilation unit declaration with
9384 -- the pragma immediately following the declaration.
9386 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9388 (Defining_Entity (Unit (Parent (Parent (N)))));
9391 -- Case 2: library unit placement for package
9395 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9397 if Is_Package_Or_Generic_Package (Ent) then
9398 Set_Obsolescent (Ent);
9404 -- Cases where we must follow a declaration
9407 if Nkind (Decl) not in N_Declaration
9408 and then Nkind (Decl) not in N_Later_Decl_Item
9409 and then Nkind (Decl) not in N_Generic_Declaration
9410 and then Nkind (Decl) not in N_Renaming_Declaration
9413 ("pragma% misplaced, "
9414 & "must immediately follow a declaration");
9417 Set_Obsolescent (Defining_Entity (Decl));
9427 -- pragma Optimize (Time | Space | Off);
9429 -- The actual check for optimize is done in Gigi. Note that this
9430 -- pragma does not actually change the optimization setting, it
9431 -- simply checks that it is consistent with the pragma.
9433 when Pragma_Optimize =>
9434 Check_No_Identifiers;
9435 Check_Arg_Count (1);
9436 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9438 ------------------------
9439 -- Optimize_Alignment --
9440 ------------------------
9442 -- pragma Optimize_Alignment (Time | Space | Off);
9444 when Pragma_Optimize_Alignment =>
9446 Check_No_Identifiers;
9447 Check_Arg_Count (1);
9448 Check_Valid_Configuration_Pragma;
9451 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9455 Opt.Optimize_Alignment := 'T';
9457 Opt.Optimize_Alignment := 'S';
9459 Opt.Optimize_Alignment := 'O';
9461 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9465 -- Set indication that mode is set locally. If we are in fact in a
9466 -- configuration pragma file, this setting is harmless since the
9467 -- switch will get reset anyway at the start of each unit.
9469 Optimize_Alignment_Local := True;
9475 -- pragma Pack (first_subtype_LOCAL_NAME);
9477 when Pragma_Pack => Pack : declare
9478 Assoc : constant Node_Id := Arg1;
9483 Check_No_Identifiers;
9484 Check_Arg_Count (1);
9485 Check_Arg_Is_Local_Name (Arg1);
9487 Type_Id := Expression (Assoc);
9488 Find_Type (Type_Id);
9489 Typ := Entity (Type_Id);
9492 or else Rep_Item_Too_Early (Typ, N)
9496 Typ := Underlying_Type (Typ);
9499 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9500 Error_Pragma ("pragma% must specify array or record type");
9503 Check_First_Subtype (Arg1);
9505 if Has_Pragma_Pack (Typ) then
9506 Error_Pragma ("duplicate pragma%, only one allowed");
9510 elsif Is_Array_Type (Typ) then
9512 -- Pack not allowed for aliased or atomic components
9514 if Has_Aliased_Components (Base_Type (Typ)) then
9516 ("pragma% ignored, cannot pack aliased components?");
9518 elsif Has_Atomic_Components (Typ)
9519 or else Is_Atomic (Component_Type (Typ))
9522 ("?pragma% ignored, cannot pack atomic components");
9525 -- If we had an explicit component size given, then we do not
9526 -- let Pack override this given size. We also give a warning
9527 -- that Pack is being ignored unless we can tell for sure that
9528 -- the Pack would not have had any effect anyway.
9530 if Has_Component_Size_Clause (Typ) then
9531 if Known_Static_RM_Size (Component_Type (Typ))
9533 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9538 ("?pragma% ignored, explicit component size given");
9541 -- If no prior array component size given, Pack is effective
9544 if not Rep_Item_Too_Late (Typ, N) then
9546 -- In the context of static code analysis, we do not need
9547 -- complex front-end expansions related to pragma Pack,
9548 -- so disable handling of pragma Pack in this case.
9550 if CodePeer_Mode then
9553 -- For normal non-VM target, do the packing
9555 elsif VM_Target = No_VM then
9556 Set_Is_Packed (Base_Type (Typ));
9557 Set_Has_Pragma_Pack (Base_Type (Typ));
9558 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9560 -- If we ignore the pack, then warn about this, except
9561 -- that we suppress the warning in GNAT mode.
9563 elsif not GNAT_Mode then
9565 ("?pragma% ignored in this configuration");
9570 -- For record types, the pack is always effective
9572 else pragma Assert (Is_Record_Type (Typ));
9573 if not Rep_Item_Too_Late (Typ, N) then
9574 if VM_Target = No_VM then
9575 Set_Is_Packed (Base_Type (Typ));
9576 Set_Has_Pragma_Pack (Base_Type (Typ));
9577 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9579 elsif not GNAT_Mode then
9580 Error_Pragma ("?pragma% ignored in this configuration");
9592 -- There is nothing to do here, since we did all the processing for
9593 -- this pragma in Par.Prag (so that it works properly even in syntax
9603 -- pragma Passive [(PASSIVE_FORM)];
9605 -- PASSIVE_FORM ::= Semaphore | No
9607 when Pragma_Passive =>
9610 if Nkind (Parent (N)) /= N_Task_Definition then
9611 Error_Pragma ("pragma% must be within task definition");
9614 if Arg_Count /= 0 then
9615 Check_Arg_Count (1);
9616 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9619 ----------------------------------
9620 -- Preelaborable_Initialization --
9621 ----------------------------------
9623 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9625 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9630 Check_Arg_Count (1);
9631 Check_No_Identifiers;
9632 Check_Arg_Is_Identifier (Arg1);
9633 Check_Arg_Is_Local_Name (Arg1);
9634 Check_First_Subtype (Arg1);
9635 Ent := Entity (Expression (Arg1));
9637 if not Is_Private_Type (Ent)
9638 and then not Is_Protected_Type (Ent)
9641 ("pragma % can only be applied to private or protected type",
9645 -- Give an error if the pragma is applied to a protected type that
9646 -- does not qualify (due to having entries, or due to components
9647 -- that do not qualify).
9649 if Is_Protected_Type (Ent)
9650 and then not Has_Preelaborable_Initialization (Ent)
9653 ("protected type & does not have preelaborable " &
9654 "initialization", Ent);
9656 -- Otherwise mark the type as definitely having preelaborable
9660 Set_Known_To_Have_Preelab_Init (Ent);
9663 if Has_Pragma_Preelab_Init (Ent)
9664 and then Warn_On_Redundant_Constructs
9666 Error_Pragma ("?duplicate pragma%!");
9668 Set_Has_Pragma_Preelab_Init (Ent);
9672 --------------------
9673 -- Persistent_BSS --
9674 --------------------
9676 when Pragma_Persistent_BSS => Persistent_BSS : declare
9683 Check_At_Most_N_Arguments (1);
9685 -- Case of application to specific object (one argument)
9687 if Arg_Count = 1 then
9688 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9690 if not Is_Entity_Name (Expression (Arg1))
9692 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9693 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9695 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9698 Ent := Entity (Expression (Arg1));
9699 Decl := Parent (Ent);
9701 if Rep_Item_Too_Late (Ent, N) then
9705 if Present (Expression (Decl)) then
9707 ("object for pragma% cannot have initialization", Arg1);
9710 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9712 ("object type for pragma% is not potentially persistent",
9717 Make_Linker_Section_Pragma
9718 (Ent, Sloc (N), ".persistent.bss");
9719 Insert_After (N, Prag);
9722 -- Case of use as configuration pragma with no arguments
9725 Check_Valid_Configuration_Pragma;
9726 Persistent_BSS_Mode := True;
9734 -- pragma Polling (ON | OFF);
9736 when Pragma_Polling =>
9738 Check_Arg_Count (1);
9739 Check_No_Identifiers;
9740 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9741 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9747 -- pragma Postcondition ([Check =>] Boolean_Expression
9748 -- [,[Message =>] String_Expression]);
9750 when Pragma_Postcondition => Postcondition : declare
9752 pragma Warnings (Off, In_Body);
9756 Check_At_Least_N_Arguments (1);
9757 Check_At_Most_N_Arguments (2);
9758 Check_Optional_Identifier (Arg1, Name_Check);
9760 -- All we need to do here is call the common check procedure,
9761 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9763 Check_Precondition_Postcondition (In_Body);
9770 -- pragma Precondition ([Check =>] Boolean_Expression
9771 -- [,[Message =>] String_Expression]);
9773 when Pragma_Precondition => Precondition : declare
9778 Check_At_Least_N_Arguments (1);
9779 Check_At_Most_N_Arguments (2);
9780 Check_Optional_Identifier (Arg1, Name_Check);
9782 Check_Precondition_Postcondition (In_Body);
9784 -- If in spec, nothing more to do. If in body, then we convert the
9785 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
9786 -- this whether or not precondition checks are enabled. That works
9787 -- fine since pragma Check will do this check, and will also
9788 -- analyze the condition itself in the proper context.
9791 if Arg_Count = 2 then
9792 Check_Optional_Identifier (Arg3, Name_Message);
9793 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9798 Chars => Name_Check,
9799 Pragma_Argument_Associations => New_List (
9800 Make_Pragma_Argument_Association (Loc,
9802 Make_Identifier (Loc,
9803 Chars => Name_Precondition)),
9805 Make_Pragma_Argument_Association (Sloc (Arg1),
9806 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9808 if Arg_Count = 2 then
9809 Append_To (Pragma_Argument_Associations (N),
9810 Make_Pragma_Argument_Association (Sloc (Arg2),
9811 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9822 -- pragma Preelaborate [(library_unit_NAME)];
9824 -- Set the flag Is_Preelaborated of program unit name entity
9826 when Pragma_Preelaborate => Preelaborate : declare
9827 Pa : constant Node_Id := Parent (N);
9828 Pk : constant Node_Kind := Nkind (Pa);
9832 Check_Ada_83_Warning;
9833 Check_Valid_Library_Unit_Pragma;
9835 if Nkind (N) = N_Null_Statement then
9839 Ent := Find_Lib_Unit_Name;
9841 -- This filters out pragmas inside generic parent then
9842 -- show up inside instantiation
9845 and then not (Pk = N_Package_Specification
9846 and then Present (Generic_Parent (Pa)))
9848 if not Debug_Flag_U then
9849 Set_Is_Preelaborated (Ent);
9850 Set_Suppress_Elaboration_Warnings (Ent);
9855 ---------------------
9856 -- Preelaborate_05 --
9857 ---------------------
9859 -- pragma Preelaborate_05 [(library_unit_NAME)];
9861 -- This pragma is useable only in GNAT_Mode, where it is used like
9862 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9863 -- (otherwise it is ignored). This is used to implement AI-362 which
9864 -- recategorizes some run-time packages in Ada 2005 mode.
9866 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9871 Check_Valid_Library_Unit_Pragma;
9873 if not GNAT_Mode then
9874 Error_Pragma ("pragma% only available in GNAT mode");
9877 if Nkind (N) = N_Null_Statement then
9881 -- This is one of the few cases where we need to test the value of
9882 -- Ada_Version_Explicit rather than Ada_Version (which is always
9883 -- set to Ada_05 in a predefined unit), we need to know the
9884 -- explicit version set to know if this pragma is active.
9886 if Ada_Version_Explicit >= Ada_05 then
9887 Ent := Find_Lib_Unit_Name;
9888 Set_Is_Preelaborated (Ent);
9889 Set_Suppress_Elaboration_Warnings (Ent);
9891 end Preelaborate_05;
9897 -- pragma Priority (EXPRESSION);
9899 when Pragma_Priority => Priority : declare
9900 P : constant Node_Id := Parent (N);
9904 Check_No_Identifiers;
9905 Check_Arg_Count (1);
9909 if Nkind (P) = N_Subprogram_Body then
9910 Check_In_Main_Program;
9912 Arg := Expression (Arg1);
9913 Analyze_And_Resolve (Arg, Standard_Integer);
9917 if not Is_Static_Expression (Arg) then
9918 Flag_Non_Static_Expr
9919 ("main subprogram priority is not static!", Arg);
9922 -- If constraint error, then we already signalled an error
9924 elsif Raises_Constraint_Error (Arg) then
9927 -- Otherwise check in range
9931 Val : constant Uint := Expr_Value (Arg);
9935 or else Val > Expr_Value (Expression
9936 (Parent (RTE (RE_Max_Priority))))
9939 ("main subprogram priority is out of range", Arg1);
9945 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9947 -- Load an arbitrary entity from System.Tasking to make sure
9948 -- this package is implicitly with'ed, since we need to have
9949 -- the tasking run-time active for the pragma Priority to have
9953 Discard : Entity_Id;
9954 pragma Warnings (Off, Discard);
9956 Discard := RTE (RE_Task_List);
9959 -- Task or Protected, must be of type Integer
9961 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9962 Arg := Expression (Arg1);
9964 -- The expression must be analyzed in the special manner
9965 -- described in "Handling of Default and Per-Object
9966 -- Expressions" in sem.ads.
9968 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9970 if not Is_Static_Expression (Arg) then
9971 Check_Restriction (Static_Priorities, Arg);
9974 -- Anything else is incorrect
9980 if Has_Priority_Pragma (P) then
9981 Error_Pragma ("duplicate pragma% not allowed");
9983 Set_Has_Priority_Pragma (P, True);
9985 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9986 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9987 -- exp_ch9 should use this ???
9992 -----------------------------------
9993 -- Priority_Specific_Dispatching --
9994 -----------------------------------
9996 -- pragma Priority_Specific_Dispatching (
9997 -- policy_IDENTIFIER,
9998 -- first_priority_EXPRESSION,
9999 -- last_priority_EXPRESSION);
10001 when Pragma_Priority_Specific_Dispatching =>
10002 Priority_Specific_Dispatching : declare
10003 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10004 -- This is the entity System.Any_Priority;
10007 Lower_Bound : Node_Id;
10008 Upper_Bound : Node_Id;
10014 Check_Arg_Count (3);
10015 Check_No_Identifiers;
10016 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10017 Check_Valid_Configuration_Pragma;
10018 Get_Name_String (Chars (Expression (Arg1)));
10019 DP := Fold_Upper (Name_Buffer (1));
10021 Lower_Bound := Expression (Arg2);
10022 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10023 Lower_Val := Expr_Value (Lower_Bound);
10025 Upper_Bound := Expression (Arg3);
10026 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10027 Upper_Val := Expr_Value (Upper_Bound);
10029 -- It is not allowed to use Task_Dispatching_Policy and
10030 -- Priority_Specific_Dispatching in the same partition.
10032 if Task_Dispatching_Policy /= ' ' then
10033 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10035 ("pragma% incompatible with Task_Dispatching_Policy#");
10037 -- Check lower bound in range
10039 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10041 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10044 ("first_priority is out of range", Arg2);
10046 -- Check upper bound in range
10048 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10050 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10053 ("last_priority is out of range", Arg3);
10055 -- Check that the priority range is valid
10057 elsif Lower_Val > Upper_Val then
10059 ("last_priority_expression must be greater than" &
10060 " or equal to first_priority_expression");
10062 -- Store the new policy, but always preserve System_Location since
10063 -- we like the error message with the run-time name.
10066 -- Check overlapping in the priority ranges specified in other
10067 -- Priority_Specific_Dispatching pragmas within the same
10068 -- partition. We can only check those we know about!
10071 Specific_Dispatching.First .. Specific_Dispatching.Last
10073 if Specific_Dispatching.Table (J).First_Priority in
10074 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10075 or else Specific_Dispatching.Table (J).Last_Priority in
10076 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10079 Specific_Dispatching.Table (J).Pragma_Loc;
10081 ("priority range overlaps with "
10082 & "Priority_Specific_Dispatching#");
10086 -- The use of Priority_Specific_Dispatching is incompatible
10087 -- with Task_Dispatching_Policy.
10089 if Task_Dispatching_Policy /= ' ' then
10090 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10092 ("Priority_Specific_Dispatching incompatible "
10093 & "with Task_Dispatching_Policy#");
10096 -- The use of Priority_Specific_Dispatching forces ceiling
10099 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10100 Error_Msg_Sloc := Locking_Policy_Sloc;
10102 ("Priority_Specific_Dispatching incompatible "
10103 & "with Locking_Policy#");
10105 -- Set the Ceiling_Locking policy, but preserve System_Location
10106 -- since we like the error message with the run time name.
10109 Locking_Policy := 'C';
10111 if Locking_Policy_Sloc /= System_Location then
10112 Locking_Policy_Sloc := Loc;
10116 -- Add entry in the table
10118 Specific_Dispatching.Append
10119 ((Dispatching_Policy => DP,
10120 First_Priority => UI_To_Int (Lower_Val),
10121 Last_Priority => UI_To_Int (Upper_Val),
10122 Pragma_Loc => Loc));
10124 end Priority_Specific_Dispatching;
10130 -- pragma Profile (profile_IDENTIFIER);
10132 -- profile_IDENTIFIER => Restricted | Ravenscar
10134 when Pragma_Profile =>
10136 Check_Arg_Count (1);
10137 Check_Valid_Configuration_Pragma;
10138 Check_No_Identifiers;
10141 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10143 if Chars (Argx) = Name_Ravenscar then
10144 Set_Ravenscar_Profile (N);
10145 elsif Chars (Argx) = Name_Restricted then
10146 Set_Profile_Restrictions
10147 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10149 Error_Pragma_Arg ("& is not a valid profile", Argx);
10153 ----------------------
10154 -- Profile_Warnings --
10155 ----------------------
10157 -- pragma Profile_Warnings (profile_IDENTIFIER);
10159 -- profile_IDENTIFIER => Restricted | Ravenscar
10161 when Pragma_Profile_Warnings =>
10163 Check_Arg_Count (1);
10164 Check_Valid_Configuration_Pragma;
10165 Check_No_Identifiers;
10168 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10170 if Chars (Argx) = Name_Ravenscar then
10171 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10172 elsif Chars (Argx) = Name_Restricted then
10173 Set_Profile_Restrictions (Restricted, N, Warn => True);
10175 Error_Pragma_Arg ("& is not a valid profile", Argx);
10179 --------------------------
10180 -- Propagate_Exceptions --
10181 --------------------------
10183 -- pragma Propagate_Exceptions;
10185 -- Note: this pragma is obsolete and has no effect
10187 when Pragma_Propagate_Exceptions =>
10189 Check_Arg_Count (0);
10191 if In_Extended_Main_Source_Unit (N) then
10192 Propagate_Exceptions := True;
10199 -- pragma Psect_Object (
10200 -- [Internal =>] LOCAL_NAME,
10201 -- [, [External =>] EXTERNAL_SYMBOL]
10202 -- [, [Size =>] EXTERNAL_SYMBOL]);
10204 when Pragma_Psect_Object | Pragma_Common_Object =>
10205 Psect_Object : declare
10206 Args : Args_List (1 .. 3);
10207 Names : constant Name_List (1 .. 3) := (
10212 Internal : Node_Id renames Args (1);
10213 External : Node_Id renames Args (2);
10214 Size : Node_Id renames Args (3);
10216 Def_Id : Entity_Id;
10218 procedure Check_Too_Long (Arg : Node_Id);
10219 -- Posts message if the argument is an identifier with more
10220 -- than 31 characters, or a string literal with more than
10221 -- 31 characters, and we are operating under VMS
10223 --------------------
10224 -- Check_Too_Long --
10225 --------------------
10227 procedure Check_Too_Long (Arg : Node_Id) is
10228 X : constant Node_Id := Original_Node (Arg);
10231 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10233 ("inappropriate argument for pragma %", Arg);
10236 if OpenVMS_On_Target then
10237 if (Nkind (X) = N_String_Literal
10238 and then String_Length (Strval (X)) > 31)
10240 (Nkind (X) = N_Identifier
10241 and then Length_Of_Name (Chars (X)) > 31)
10244 ("argument for pragma % is longer than 31 characters",
10248 end Check_Too_Long;
10250 -- Start of processing for Common_Object/Psect_Object
10254 Gather_Associations (Names, Args);
10255 Process_Extended_Import_Export_Internal_Arg (Internal);
10257 Def_Id := Entity (Internal);
10259 if Ekind (Def_Id) /= E_Constant
10260 and then Ekind (Def_Id) /= E_Variable
10263 ("pragma% must designate an object", Internal);
10266 Check_Too_Long (Internal);
10268 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10270 ("cannot use pragma% for imported/exported object",
10274 if Is_Concurrent_Type (Etype (Internal)) then
10276 ("cannot specify pragma % for task/protected object",
10280 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10282 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10284 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10287 if Ekind (Def_Id) = E_Constant then
10289 ("cannot specify pragma % for a constant", Internal);
10292 if Is_Record_Type (Etype (Internal)) then
10298 Ent := First_Entity (Etype (Internal));
10299 while Present (Ent) loop
10300 Decl := Declaration_Node (Ent);
10302 if Ekind (Ent) = E_Component
10303 and then Nkind (Decl) = N_Component_Declaration
10304 and then Present (Expression (Decl))
10305 and then Warn_On_Export_Import
10308 ("?object for pragma % has defaults", Internal);
10318 if Present (Size) then
10319 Check_Too_Long (Size);
10322 if Present (External) then
10323 Check_Arg_Is_External_Name (External);
10324 Check_Too_Long (External);
10327 -- If all error tests pass, link pragma on to the rep item chain
10329 Record_Rep_Item (Def_Id, N);
10336 -- pragma Pure [(library_unit_NAME)];
10338 when Pragma_Pure => Pure : declare
10342 Check_Ada_83_Warning;
10343 Check_Valid_Library_Unit_Pragma;
10345 if Nkind (N) = N_Null_Statement then
10349 Ent := Find_Lib_Unit_Name;
10351 Set_Has_Pragma_Pure (Ent);
10352 Set_Suppress_Elaboration_Warnings (Ent);
10359 -- pragma Pure_05 [(library_unit_NAME)];
10361 -- This pragma is useable only in GNAT_Mode, where it is used like
10362 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10363 -- it is ignored). It may be used after a pragma Preelaborate, in
10364 -- which case it overrides the effect of the pragma Preelaborate.
10365 -- This is used to implement AI-362 which recategorizes some run-time
10366 -- packages in Ada 2005 mode.
10368 when Pragma_Pure_05 => Pure_05 : declare
10373 Check_Valid_Library_Unit_Pragma;
10375 if not GNAT_Mode then
10376 Error_Pragma ("pragma% only available in GNAT mode");
10379 if Nkind (N) = N_Null_Statement then
10383 -- This is one of the few cases where we need to test the value of
10384 -- Ada_Version_Explicit rather than Ada_Version (which is always
10385 -- set to Ada_05 in a predefined unit), we need to know the
10386 -- explicit version set to know if this pragma is active.
10388 if Ada_Version_Explicit >= Ada_05 then
10389 Ent := Find_Lib_Unit_Name;
10390 Set_Is_Preelaborated (Ent, False);
10392 Set_Suppress_Elaboration_Warnings (Ent);
10396 -------------------
10397 -- Pure_Function --
10398 -------------------
10400 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10402 when Pragma_Pure_Function => Pure_Function : declare
10405 Def_Id : Entity_Id;
10406 Effective : Boolean := False;
10410 Check_Arg_Count (1);
10411 Check_Optional_Identifier (Arg1, Name_Entity);
10412 Check_Arg_Is_Local_Name (Arg1);
10413 E_Id := Expression (Arg1);
10415 if Error_Posted (E_Id) then
10419 -- Loop through homonyms (overloadings) of referenced entity
10421 E := Entity (E_Id);
10423 if Present (E) then
10425 Def_Id := Get_Base_Subprogram (E);
10427 if Ekind (Def_Id) /= E_Function
10428 and then Ekind (Def_Id) /= E_Generic_Function
10429 and then Ekind (Def_Id) /= E_Operator
10432 ("pragma% requires a function name", Arg1);
10435 Set_Is_Pure (Def_Id);
10437 if not Has_Pragma_Pure_Function (Def_Id) then
10438 Set_Has_Pragma_Pure_Function (Def_Id);
10443 exit when No (E) or else Scope (E) /= Current_Scope;
10447 and then Warn_On_Redundant_Constructs
10449 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10455 --------------------
10456 -- Queuing_Policy --
10457 --------------------
10459 -- pragma Queuing_Policy (policy_IDENTIFIER);
10461 when Pragma_Queuing_Policy => declare
10465 Check_Ada_83_Warning;
10466 Check_Arg_Count (1);
10467 Check_No_Identifiers;
10468 Check_Arg_Is_Queuing_Policy (Arg1);
10469 Check_Valid_Configuration_Pragma;
10470 Get_Name_String (Chars (Expression (Arg1)));
10471 QP := Fold_Upper (Name_Buffer (1));
10473 if Queuing_Policy /= ' '
10474 and then Queuing_Policy /= QP
10476 Error_Msg_Sloc := Queuing_Policy_Sloc;
10477 Error_Pragma ("queuing policy incompatible with policy#");
10479 -- Set new policy, but always preserve System_Location since we
10480 -- like the error message with the run time name.
10483 Queuing_Policy := QP;
10485 if Queuing_Policy_Sloc /= System_Location then
10486 Queuing_Policy_Sloc := Loc;
10491 -----------------------
10492 -- Relative_Deadline --
10493 -----------------------
10495 -- pragma Relative_Deadline (time_span_EXPRESSION);
10497 when Pragma_Relative_Deadline => Relative_Deadline : declare
10498 P : constant Node_Id := Parent (N);
10503 Check_No_Identifiers;
10504 Check_Arg_Count (1);
10506 Arg := Expression (Arg1);
10508 -- The expression must be analyzed in the special manner described
10509 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10511 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10515 if Nkind (P) = N_Subprogram_Body then
10516 Check_In_Main_Program;
10520 elsif Nkind (P) = N_Task_Definition then
10523 -- Anything else is incorrect
10529 if Has_Relative_Deadline_Pragma (P) then
10530 Error_Pragma ("duplicate pragma% not allowed");
10532 Set_Has_Relative_Deadline_Pragma (P, True);
10534 if Nkind (P) = N_Task_Definition then
10535 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10538 end Relative_Deadline;
10540 ---------------------------
10541 -- Remote_Call_Interface --
10542 ---------------------------
10544 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10546 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10547 Cunit_Node : Node_Id;
10548 Cunit_Ent : Entity_Id;
10552 Check_Ada_83_Warning;
10553 Check_Valid_Library_Unit_Pragma;
10555 if Nkind (N) = N_Null_Statement then
10559 Cunit_Node := Cunit (Current_Sem_Unit);
10560 K := Nkind (Unit (Cunit_Node));
10561 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10563 if K = N_Package_Declaration
10564 or else K = N_Generic_Package_Declaration
10565 or else K = N_Subprogram_Declaration
10566 or else K = N_Generic_Subprogram_Declaration
10567 or else (K = N_Subprogram_Body
10568 and then Acts_As_Spec (Unit (Cunit_Node)))
10573 "pragma% must apply to package or subprogram declaration");
10576 Set_Is_Remote_Call_Interface (Cunit_Ent);
10577 end Remote_Call_Interface;
10583 -- pragma Remote_Types [(library_unit_NAME)];
10585 when Pragma_Remote_Types => Remote_Types : declare
10586 Cunit_Node : Node_Id;
10587 Cunit_Ent : Entity_Id;
10590 Check_Ada_83_Warning;
10591 Check_Valid_Library_Unit_Pragma;
10593 if Nkind (N) = N_Null_Statement then
10597 Cunit_Node := Cunit (Current_Sem_Unit);
10598 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10600 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10601 N_Generic_Package_Declaration)
10604 ("pragma% can only apply to a package declaration");
10607 Set_Is_Remote_Types (Cunit_Ent);
10614 -- pragma Ravenscar;
10616 when Pragma_Ravenscar =>
10618 Check_Arg_Count (0);
10619 Check_Valid_Configuration_Pragma;
10620 Set_Ravenscar_Profile (N);
10622 if Warn_On_Obsolescent_Feature then
10624 ("pragma Ravenscar is an obsolescent feature?", N);
10626 ("|use pragma Profile (Ravenscar) instead", N);
10629 -------------------------
10630 -- Restricted_Run_Time --
10631 -------------------------
10633 -- pragma Restricted_Run_Time;
10635 when Pragma_Restricted_Run_Time =>
10637 Check_Arg_Count (0);
10638 Check_Valid_Configuration_Pragma;
10639 Set_Profile_Restrictions
10640 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10642 if Warn_On_Obsolescent_Feature then
10644 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10646 ("|use pragma Profile (Restricted) instead", N);
10653 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10656 -- restriction_IDENTIFIER
10657 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10659 when Pragma_Restrictions =>
10660 Process_Restrictions_Or_Restriction_Warnings
10661 (Warn => Treat_Restrictions_As_Warnings);
10663 --------------------------
10664 -- Restriction_Warnings --
10665 --------------------------
10667 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10670 -- restriction_IDENTIFIER
10671 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10673 when Pragma_Restriction_Warnings =>
10675 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10681 -- pragma Reviewable;
10683 when Pragma_Reviewable =>
10684 Check_Ada_83_Warning;
10685 Check_Arg_Count (0);
10687 -- Call dummy debugging function rv. This is done to assist front
10688 -- end debugging. By placing a Reviewable pragma in the source
10689 -- program, a breakpoint on rv catches this place in the source,
10690 -- allowing convenient stepping to the point of interest.
10694 --------------------------
10695 -- Short_Circuit_And_Or --
10696 --------------------------
10698 when Pragma_Short_Circuit_And_Or =>
10700 Check_Arg_Count (0);
10701 Check_Valid_Configuration_Pragma;
10702 Short_Circuit_And_Or := True;
10704 -------------------
10705 -- Share_Generic --
10706 -------------------
10708 -- pragma Share_Generic (NAME {, NAME});
10710 when Pragma_Share_Generic =>
10712 Process_Generic_List;
10718 -- pragma Shared (LOCAL_NAME);
10720 when Pragma_Shared =>
10722 Process_Atomic_Shared_Volatile;
10724 --------------------
10725 -- Shared_Passive --
10726 --------------------
10728 -- pragma Shared_Passive [(library_unit_NAME)];
10730 -- Set the flag Is_Shared_Passive of program unit name entity
10732 when Pragma_Shared_Passive => Shared_Passive : declare
10733 Cunit_Node : Node_Id;
10734 Cunit_Ent : Entity_Id;
10737 Check_Ada_83_Warning;
10738 Check_Valid_Library_Unit_Pragma;
10740 if Nkind (N) = N_Null_Statement then
10744 Cunit_Node := Cunit (Current_Sem_Unit);
10745 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10747 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10748 N_Generic_Package_Declaration)
10751 ("pragma% can only apply to a package declaration");
10754 Set_Is_Shared_Passive (Cunit_Ent);
10755 end Shared_Passive;
10757 ----------------------
10758 -- Source_File_Name --
10759 ----------------------
10761 -- There are five forms for this pragma:
10763 -- pragma Source_File_Name (
10764 -- [UNIT_NAME =>] unit_NAME,
10765 -- BODY_FILE_NAME => STRING_LITERAL
10766 -- [, [INDEX =>] INTEGER_LITERAL]);
10768 -- pragma Source_File_Name (
10769 -- [UNIT_NAME =>] unit_NAME,
10770 -- SPEC_FILE_NAME => STRING_LITERAL
10771 -- [, [INDEX =>] INTEGER_LITERAL]);
10773 -- pragma Source_File_Name (
10774 -- BODY_FILE_NAME => STRING_LITERAL
10775 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10776 -- [, CASING => CASING_SPEC]);
10778 -- pragma Source_File_Name (
10779 -- SPEC_FILE_NAME => STRING_LITERAL
10780 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10781 -- [, CASING => CASING_SPEC]);
10783 -- pragma Source_File_Name (
10784 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10785 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10786 -- [, CASING => CASING_SPEC]);
10788 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10790 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10791 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
10792 -- only be used when no project file is used, while SFNP can only be
10793 -- used when a project file is used.
10795 -- No processing here. Processing was completed during parsing, since
10796 -- we need to have file names set as early as possible. Units are
10797 -- loaded well before semantic processing starts.
10799 -- The only processing we defer to this point is the check for
10800 -- correct placement.
10802 when Pragma_Source_File_Name =>
10804 Check_Valid_Configuration_Pragma;
10806 ------------------------------
10807 -- Source_File_Name_Project --
10808 ------------------------------
10810 -- See Source_File_Name for syntax
10812 -- No processing here. Processing was completed during parsing, since
10813 -- we need to have file names set as early as possible. Units are
10814 -- loaded well before semantic processing starts.
10816 -- The only processing we defer to this point is the check for
10817 -- correct placement.
10819 when Pragma_Source_File_Name_Project =>
10821 Check_Valid_Configuration_Pragma;
10823 -- Check that a pragma Source_File_Name_Project is used only in a
10824 -- configuration pragmas file.
10826 -- Pragmas Source_File_Name_Project should only be generated by
10827 -- the Project Manager in configuration pragmas files.
10829 -- This is really an ugly test. It seems to depend on some
10830 -- accidental and undocumented property. At the very least it
10831 -- needs to be documented, but it would be better to have a
10832 -- clean way of testing if we are in a configuration file???
10834 if Present (Parent (N)) then
10836 ("pragma% can only appear in a configuration pragmas file");
10839 ----------------------
10840 -- Source_Reference --
10841 ----------------------
10843 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10845 -- Nothing to do, all processing completed in Par.Prag, since we need
10846 -- the information for possible parser messages that are output.
10848 when Pragma_Source_Reference =>
10851 --------------------------------
10852 -- Static_Elaboration_Desired --
10853 --------------------------------
10855 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10857 when Pragma_Static_Elaboration_Desired =>
10859 Check_At_Most_N_Arguments (1);
10861 if Is_Compilation_Unit (Current_Scope)
10862 and then Ekind (Current_Scope) = E_Package
10864 Set_Static_Elaboration_Desired (Current_Scope, True);
10866 Error_Pragma ("pragma% must apply to a library-level package");
10873 -- pragma Storage_Size (EXPRESSION);
10875 when Pragma_Storage_Size => Storage_Size : declare
10876 P : constant Node_Id := Parent (N);
10880 Check_No_Identifiers;
10881 Check_Arg_Count (1);
10883 -- The expression must be analyzed in the special manner described
10884 -- in "Handling of Default Expressions" in sem.ads.
10886 Arg := Expression (Arg1);
10887 Preanalyze_Spec_Expression (Arg, Any_Integer);
10889 if not Is_Static_Expression (Arg) then
10890 Check_Restriction (Static_Storage_Size, Arg);
10893 if Nkind (P) /= N_Task_Definition then
10898 if Has_Storage_Size_Pragma (P) then
10899 Error_Pragma ("duplicate pragma% not allowed");
10901 Set_Has_Storage_Size_Pragma (P, True);
10904 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10905 -- ??? exp_ch9 should use this!
10913 -- pragma Storage_Unit (NUMERIC_LITERAL);
10915 -- Only permitted argument is System'Storage_Unit value
10917 when Pragma_Storage_Unit =>
10918 Check_No_Identifiers;
10919 Check_Arg_Count (1);
10920 Check_Arg_Is_Integer_Literal (Arg1);
10922 if Intval (Expression (Arg1)) /=
10923 UI_From_Int (Ttypes.System_Storage_Unit)
10925 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10927 ("the only allowed argument for pragma% is ^", Arg1);
10930 --------------------
10931 -- Stream_Convert --
10932 --------------------
10934 -- pragma Stream_Convert (
10935 -- [Entity =>] type_LOCAL_NAME,
10936 -- [Read =>] function_NAME,
10937 -- [Write =>] function NAME);
10939 when Pragma_Stream_Convert => Stream_Convert : declare
10941 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10942 -- Check that the given argument is the name of a local function
10943 -- of one argument that is not overloaded earlier in the current
10944 -- local scope. A check is also made that the argument is a
10945 -- function with one parameter.
10947 --------------------------------------
10948 -- Check_OK_Stream_Convert_Function --
10949 --------------------------------------
10951 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10955 Check_Arg_Is_Local_Name (Arg);
10956 Ent := Entity (Expression (Arg));
10958 if Has_Homonym (Ent) then
10960 ("argument for pragma% may not be overloaded", Arg);
10963 if Ekind (Ent) /= E_Function
10964 or else No (First_Formal (Ent))
10965 or else Present (Next_Formal (First_Formal (Ent)))
10968 ("argument for pragma% must be" &
10969 " function of one argument", Arg);
10971 end Check_OK_Stream_Convert_Function;
10973 -- Start of processing for Stream_Convert
10977 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10978 Check_Arg_Count (3);
10979 Check_Optional_Identifier (Arg1, Name_Entity);
10980 Check_Optional_Identifier (Arg2, Name_Read);
10981 Check_Optional_Identifier (Arg3, Name_Write);
10982 Check_Arg_Is_Local_Name (Arg1);
10983 Check_OK_Stream_Convert_Function (Arg2);
10984 Check_OK_Stream_Convert_Function (Arg3);
10987 Typ : constant Entity_Id :=
10988 Underlying_Type (Entity (Expression (Arg1)));
10989 Read : constant Entity_Id := Entity (Expression (Arg2));
10990 Write : constant Entity_Id := Entity (Expression (Arg3));
10993 Check_First_Subtype (Arg1);
10995 -- Check for too early or too late. Note that we don't enforce
10996 -- the rule about primitive operations in this case, since, as
10997 -- is the case for explicit stream attributes themselves, these
10998 -- restrictions are not appropriate. Note that the chaining of
10999 -- the pragma by Rep_Item_Too_Late is actually the critical
11000 -- processing done for this pragma.
11002 if Rep_Item_Too_Early (Typ, N)
11004 Rep_Item_Too_Late (Typ, N, FOnly => True)
11009 -- Return if previous error
11011 if Etype (Typ) = Any_Type
11013 Etype (Read) = Any_Type
11015 Etype (Write) = Any_Type
11022 if Underlying_Type (Etype (Read)) /= Typ then
11024 ("incorrect return type for function&", Arg2);
11027 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11029 ("incorrect parameter type for function&", Arg3);
11032 if Underlying_Type (Etype (First_Formal (Read))) /=
11033 Underlying_Type (Etype (Write))
11036 ("result type of & does not match Read parameter type",
11040 end Stream_Convert;
11042 -------------------------
11043 -- Style_Checks (GNAT) --
11044 -------------------------
11046 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11048 -- This is processed by the parser since some of the style checks
11049 -- take place during source scanning and parsing. This means that
11050 -- we don't need to issue error messages here.
11052 when Pragma_Style_Checks => Style_Checks : declare
11053 A : constant Node_Id := Expression (Arg1);
11059 Check_No_Identifiers;
11061 -- Two argument form
11063 if Arg_Count = 2 then
11064 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11071 E_Id := Expression (Arg2);
11074 if not Is_Entity_Name (E_Id) then
11076 ("second argument of pragma% must be entity name",
11080 E := Entity (E_Id);
11086 Set_Suppress_Style_Checks (E,
11087 (Chars (Expression (Arg1)) = Name_Off));
11088 exit when No (Homonym (E));
11094 -- One argument form
11097 Check_Arg_Count (1);
11099 if Nkind (A) = N_String_Literal then
11103 Slen : constant Natural := Natural (String_Length (S));
11104 Options : String (1 .. Slen);
11110 C := Get_String_Char (S, Int (J));
11111 exit when not In_Character_Range (C);
11112 Options (J) := Get_Character (C);
11114 -- If at end of string, set options. As per discussion
11115 -- above, no need to check for errors, since we issued
11116 -- them in the parser.
11119 Set_Style_Check_Options (Options);
11127 elsif Nkind (A) = N_Identifier then
11128 if Chars (A) = Name_All_Checks then
11129 Set_Default_Style_Check_Options;
11131 elsif Chars (A) = Name_On then
11132 Style_Check := True;
11134 elsif Chars (A) = Name_Off then
11135 Style_Check := False;
11145 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11147 when Pragma_Subtitle =>
11149 Check_Arg_Count (1);
11150 Check_Optional_Identifier (Arg1, Name_Subtitle);
11151 Check_Arg_Is_String_Literal (Arg1);
11157 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11159 when Pragma_Suppress =>
11160 Process_Suppress_Unsuppress (True);
11166 -- pragma Suppress_All;
11168 -- The only check made here is that the pragma appears in the proper
11169 -- place, i.e. following a compilation unit. If indeed it appears in
11170 -- this context, then the parser has already inserted an equivalent
11171 -- pragma Suppress (All_Checks) to get the required effect.
11173 when Pragma_Suppress_All =>
11175 Check_Arg_Count (0);
11177 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11178 or else not Is_List_Member (N)
11179 or else List_Containing (N) /= Pragmas_After (Parent (N))
11182 ("misplaced pragma%, must follow compilation unit");
11185 -------------------------
11186 -- Suppress_Debug_Info --
11187 -------------------------
11189 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11191 when Pragma_Suppress_Debug_Info =>
11193 Check_Arg_Count (1);
11194 Check_Optional_Identifier (Arg1, Name_Entity);
11195 Check_Arg_Is_Local_Name (Arg1);
11196 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11198 ----------------------------------
11199 -- Suppress_Exception_Locations --
11200 ----------------------------------
11202 -- pragma Suppress_Exception_Locations;
11204 when Pragma_Suppress_Exception_Locations =>
11206 Check_Arg_Count (0);
11207 Check_Valid_Configuration_Pragma;
11208 Exception_Locations_Suppressed := True;
11210 -----------------------------
11211 -- Suppress_Initialization --
11212 -----------------------------
11214 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11216 when Pragma_Suppress_Initialization => Suppress_Init : declare
11222 Check_Arg_Count (1);
11223 Check_Optional_Identifier (Arg1, Name_Entity);
11224 Check_Arg_Is_Local_Name (Arg1);
11226 E_Id := Expression (Arg1);
11228 if Etype (E_Id) = Any_Type then
11232 E := Entity (E_Id);
11234 if Is_Type (E) then
11235 if Is_Incomplete_Or_Private_Type (E) then
11236 if No (Full_View (Base_Type (E))) then
11238 ("argument of pragma% cannot be an incomplete type",
11241 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11244 Set_Suppress_Init_Proc (Base_Type (E));
11249 ("pragma% requires argument that is a type name", Arg1);
11257 -- pragma System_Name (DIRECT_NAME);
11259 -- Syntax check: one argument, which must be the identifier GNAT or
11260 -- the identifier GCC, no other identifiers are acceptable.
11262 when Pragma_System_Name =>
11264 Check_No_Identifiers;
11265 Check_Arg_Count (1);
11266 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11268 -----------------------------
11269 -- Task_Dispatching_Policy --
11270 -----------------------------
11272 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11274 when Pragma_Task_Dispatching_Policy => declare
11278 Check_Ada_83_Warning;
11279 Check_Arg_Count (1);
11280 Check_No_Identifiers;
11281 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11282 Check_Valid_Configuration_Pragma;
11283 Get_Name_String (Chars (Expression (Arg1)));
11284 DP := Fold_Upper (Name_Buffer (1));
11286 if Task_Dispatching_Policy /= ' '
11287 and then Task_Dispatching_Policy /= DP
11289 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11291 ("task dispatching policy incompatible with policy#");
11293 -- Set new policy, but always preserve System_Location since we
11294 -- like the error message with the run time name.
11297 Task_Dispatching_Policy := DP;
11299 if Task_Dispatching_Policy_Sloc /= System_Location then
11300 Task_Dispatching_Policy_Sloc := Loc;
11309 -- pragma Task_Info (EXPRESSION);
11311 when Pragma_Task_Info => Task_Info : declare
11312 P : constant Node_Id := Parent (N);
11317 if Nkind (P) /= N_Task_Definition then
11318 Error_Pragma ("pragma% must appear in task definition");
11321 Check_No_Identifiers;
11322 Check_Arg_Count (1);
11324 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11326 if Etype (Expression (Arg1)) = Any_Type then
11330 if Has_Task_Info_Pragma (P) then
11331 Error_Pragma ("duplicate pragma% not allowed");
11333 Set_Has_Task_Info_Pragma (P, True);
11341 -- pragma Task_Name (string_EXPRESSION);
11343 when Pragma_Task_Name => Task_Name : declare
11344 P : constant Node_Id := Parent (N);
11348 Check_No_Identifiers;
11349 Check_Arg_Count (1);
11351 Arg := Expression (Arg1);
11353 -- The expression is used in the call to Create_Task, and must be
11354 -- expanded there, not in the context of the current spec. It must
11355 -- however be analyzed to capture global references, in case it
11356 -- appears in a generic context.
11358 Preanalyze_And_Resolve (Arg, Standard_String);
11360 if Nkind (P) /= N_Task_Definition then
11364 if Has_Task_Name_Pragma (P) then
11365 Error_Pragma ("duplicate pragma% not allowed");
11367 Set_Has_Task_Name_Pragma (P, True);
11368 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11376 -- pragma Task_Storage (
11377 -- [Task_Type =>] LOCAL_NAME,
11378 -- [Top_Guard =>] static_integer_EXPRESSION);
11380 when Pragma_Task_Storage => Task_Storage : declare
11381 Args : Args_List (1 .. 2);
11382 Names : constant Name_List (1 .. 2) := (
11386 Task_Type : Node_Id renames Args (1);
11387 Top_Guard : Node_Id renames Args (2);
11393 Gather_Associations (Names, Args);
11395 if No (Task_Type) then
11397 ("missing task_type argument for pragma%");
11400 Check_Arg_Is_Local_Name (Task_Type);
11402 Ent := Entity (Task_Type);
11404 if not Is_Task_Type (Ent) then
11406 ("argument for pragma% must be task type", Task_Type);
11409 if No (Top_Guard) then
11411 ("pragma% takes two arguments", Task_Type);
11413 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11416 Check_First_Subtype (Task_Type);
11418 if Rep_Item_Too_Late (Ent, N) then
11423 --------------------------
11424 -- Thread_Local_Storage --
11425 --------------------------
11427 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11429 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11435 Check_Arg_Count (1);
11436 Check_Optional_Identifier (Arg1, Name_Entity);
11437 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11439 Id := Expression (Arg1);
11442 if not Is_Entity_Name (Id)
11443 or else Ekind (Entity (Id)) /= E_Variable
11445 Error_Pragma_Arg ("local variable name required", Arg1);
11450 if Rep_Item_Too_Early (E, N)
11451 or else Rep_Item_Too_Late (E, N)
11456 Set_Has_Pragma_Thread_Local_Storage (E);
11457 Set_Has_Gigi_Rep_Item (E);
11458 end Thread_Local_Storage;
11464 -- pragma Time_Slice (static_duration_EXPRESSION);
11466 when Pragma_Time_Slice => Time_Slice : declare
11472 Check_Arg_Count (1);
11473 Check_No_Identifiers;
11474 Check_In_Main_Program;
11475 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11477 if not Error_Posted (Arg1) then
11479 while Present (Nod) loop
11480 if Nkind (Nod) = N_Pragma
11481 and then Pragma_Name (Nod) = Name_Time_Slice
11483 Error_Msg_Name_1 := Pname;
11484 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11491 -- Process only if in main unit
11493 if Get_Source_Unit (Loc) = Main_Unit then
11494 Opt.Time_Slice_Set := True;
11495 Val := Expr_Value_R (Expression (Arg1));
11497 if Val <= Ureal_0 then
11498 Opt.Time_Slice_Value := 0;
11500 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11501 Opt.Time_Slice_Value := 1_000_000_000;
11504 Opt.Time_Slice_Value :=
11505 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11514 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11516 -- TITLING_OPTION ::=
11517 -- [Title =>] STRING_LITERAL
11518 -- | [Subtitle =>] STRING_LITERAL
11520 when Pragma_Title => Title : declare
11521 Args : Args_List (1 .. 2);
11522 Names : constant Name_List (1 .. 2) := (
11528 Gather_Associations (Names, Args);
11530 for J in 1 .. 2 loop
11531 if Present (Args (J)) then
11532 Check_Arg_Is_String_Literal (Args (J));
11537 ---------------------
11538 -- Unchecked_Union --
11539 ---------------------
11541 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11543 when Pragma_Unchecked_Union => Unchecked_Union : declare
11544 Assoc : constant Node_Id := Arg1;
11545 Type_Id : constant Node_Id := Expression (Assoc);
11556 Check_No_Identifiers;
11557 Check_Arg_Count (1);
11558 Check_Arg_Is_Local_Name (Arg1);
11560 Find_Type (Type_Id);
11561 Typ := Entity (Type_Id);
11564 or else Rep_Item_Too_Early (Typ, N)
11568 Typ := Underlying_Type (Typ);
11571 if Rep_Item_Too_Late (Typ, N) then
11575 Check_First_Subtype (Arg1);
11577 -- Note remaining cases are references to a type in the current
11578 -- declarative part. If we find an error, we post the error on
11579 -- the relevant type declaration at an appropriate point.
11581 if not Is_Record_Type (Typ) then
11582 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11585 elsif Is_Tagged_Type (Typ) then
11586 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11589 elsif Is_Limited_Type (Typ) then
11591 ("Unchecked_Union must not be limited record type", Typ);
11592 Explain_Limited_Type (Typ, Typ);
11596 if not Has_Discriminants (Typ) then
11598 ("Unchecked_Union must have one discriminant", Typ);
11602 Discr := First_Discriminant (Typ);
11603 while Present (Discr) loop
11604 if No (Discriminant_Default_Value (Discr)) then
11606 ("Unchecked_Union discriminant must have default value",
11609 Next_Discriminant (Discr);
11612 Tdef := Type_Definition (Declaration_Node (Typ));
11613 Clist := Component_List (Tdef);
11615 Comp := First (Component_Items (Clist));
11616 while Present (Comp) loop
11617 Check_Component (Comp);
11621 if No (Clist) or else No (Variant_Part (Clist)) then
11623 ("Unchecked_Union must have variant part",
11628 Vpart := Variant_Part (Clist);
11630 Variant := First (Variants (Vpart));
11631 while Present (Variant) loop
11632 Check_Variant (Variant);
11637 Set_Is_Unchecked_Union (Typ, True);
11638 Set_Convention (Typ, Convention_C);
11640 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11641 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11642 end Unchecked_Union;
11644 ------------------------
11645 -- Unimplemented_Unit --
11646 ------------------------
11648 -- pragma Unimplemented_Unit;
11650 -- Note: this only gives an error if we are generating code, or if
11651 -- we are in a generic library unit (where the pragma appears in the
11652 -- body, not in the spec).
11654 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11655 Cunitent : constant Entity_Id :=
11656 Cunit_Entity (Get_Source_Unit (Loc));
11657 Ent_Kind : constant Entity_Kind :=
11662 Check_Arg_Count (0);
11664 if Operating_Mode = Generate_Code
11665 or else Ent_Kind = E_Generic_Function
11666 or else Ent_Kind = E_Generic_Procedure
11667 or else Ent_Kind = E_Generic_Package
11669 Get_Name_String (Chars (Cunitent));
11670 Set_Casing (Mixed_Case);
11671 Write_Str (Name_Buffer (1 .. Name_Len));
11672 Write_Str (" is not supported in this configuration");
11674 raise Unrecoverable_Error;
11676 end Unimplemented_Unit;
11678 ------------------------
11679 -- Universal_Aliasing --
11680 ------------------------
11682 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11684 when Pragma_Universal_Aliasing => Universal_Alias : declare
11689 Check_Arg_Count (1);
11690 Check_Optional_Identifier (Arg2, Name_Entity);
11691 Check_Arg_Is_Local_Name (Arg1);
11692 E_Id := Entity (Expression (Arg1));
11694 if E_Id = Any_Type then
11696 elsif No (E_Id) or else not Is_Type (E_Id) then
11697 Error_Pragma_Arg ("pragma% requires type", Arg1);
11700 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11701 end Universal_Alias;
11703 --------------------
11704 -- Universal_Data --
11705 --------------------
11707 -- pragma Universal_Data [(library_unit_NAME)];
11709 when Pragma_Universal_Data =>
11712 -- If this is a configuration pragma, then set the universal
11713 -- addressing option, otherwise confirm that the pragma satisfies
11714 -- the requirements of library unit pragma placement and leave it
11715 -- to the GNAAMP back end to detect the pragma (avoids transitive
11716 -- setting of the option due to withed units).
11718 if Is_Configuration_Pragma then
11719 Universal_Addressing_On_AAMP := True;
11721 Check_Valid_Library_Unit_Pragma;
11724 if not AAMP_On_Target then
11725 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11732 -- pragma Unmodified (local_Name {, local_Name});
11734 when Pragma_Unmodified => Unmodified : declare
11735 Arg_Node : Node_Id;
11736 Arg_Expr : Node_Id;
11737 Arg_Ent : Entity_Id;
11741 Check_At_Least_N_Arguments (1);
11743 -- Loop through arguments
11746 while Present (Arg_Node) loop
11747 Check_No_Identifier (Arg_Node);
11749 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11750 -- in fact generate reference, so that the entity will have a
11751 -- reference, which will inhibit any warnings about it not
11752 -- being referenced, and also properly show up in the ali file
11753 -- as a reference. But this reference is recorded before the
11754 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11755 -- generated for this reference.
11757 Check_Arg_Is_Local_Name (Arg_Node);
11758 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11760 if Is_Entity_Name (Arg_Expr) then
11761 Arg_Ent := Entity (Arg_Expr);
11763 if not Is_Assignable (Arg_Ent) then
11765 ("pragma% can only be applied to a variable",
11768 Set_Has_Pragma_Unmodified (Arg_Ent);
11780 -- pragma Unreferenced (local_Name {, local_Name});
11782 -- or when used in a context clause:
11784 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11786 when Pragma_Unreferenced => Unreferenced : declare
11787 Arg_Node : Node_Id;
11788 Arg_Expr : Node_Id;
11789 Arg_Ent : Entity_Id;
11794 Check_At_Least_N_Arguments (1);
11796 -- Check case of appearing within context clause
11798 if Is_In_Context_Clause then
11800 -- The arguments must all be units mentioned in a with clause
11801 -- in the same context clause. Note we already checked (in
11802 -- Par.Prag) that the arguments are either identifiers or
11803 -- selected components.
11806 while Present (Arg_Node) loop
11807 Citem := First (List_Containing (N));
11808 while Citem /= N loop
11809 if Nkind (Citem) = N_With_Clause
11810 and then Same_Name (Name (Citem), Expression (Arg_Node))
11812 Set_Has_Pragma_Unreferenced
11815 (Library_Unit (Citem))));
11816 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11825 ("argument of pragma% is not with'ed unit", Arg_Node);
11831 -- Case of not in list of context items
11835 while Present (Arg_Node) loop
11836 Check_No_Identifier (Arg_Node);
11838 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11839 -- will in fact generate reference, so that the entity will
11840 -- have a reference, which will inhibit any warnings about
11841 -- it not being referenced, and also properly show up in the
11842 -- ali file as a reference. But this reference is recorded
11843 -- before the Has_Pragma_Unreferenced flag is set, so that
11844 -- no warning is generated for this reference.
11846 Check_Arg_Is_Local_Name (Arg_Node);
11847 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11849 if Is_Entity_Name (Arg_Expr) then
11850 Arg_Ent := Entity (Arg_Expr);
11852 -- If the entity is overloaded, the pragma applies to the
11853 -- most recent overloading, as documented. In this case,
11854 -- name resolution does not generate a reference, so it
11855 -- must be done here explicitly.
11857 if Is_Overloaded (Arg_Expr) then
11858 Generate_Reference (Arg_Ent, N);
11861 Set_Has_Pragma_Unreferenced (Arg_Ent);
11869 --------------------------
11870 -- Unreferenced_Objects --
11871 --------------------------
11873 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11875 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11876 Arg_Node : Node_Id;
11877 Arg_Expr : Node_Id;
11881 Check_At_Least_N_Arguments (1);
11884 while Present (Arg_Node) loop
11885 Check_No_Identifier (Arg_Node);
11886 Check_Arg_Is_Local_Name (Arg_Node);
11887 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11889 if not Is_Entity_Name (Arg_Expr)
11890 or else not Is_Type (Entity (Arg_Expr))
11893 ("argument for pragma% must be type or subtype", Arg_Node);
11896 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11899 end Unreferenced_Objects;
11901 ------------------------------
11902 -- Unreserve_All_Interrupts --
11903 ------------------------------
11905 -- pragma Unreserve_All_Interrupts;
11907 when Pragma_Unreserve_All_Interrupts =>
11909 Check_Arg_Count (0);
11911 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11912 Unreserve_All_Interrupts := True;
11919 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11921 when Pragma_Unsuppress =>
11923 Process_Suppress_Unsuppress (False);
11925 -------------------
11926 -- Use_VADS_Size --
11927 -------------------
11929 -- pragma Use_VADS_Size;
11931 when Pragma_Use_VADS_Size =>
11933 Check_Arg_Count (0);
11934 Check_Valid_Configuration_Pragma;
11935 Use_VADS_Size := True;
11937 ---------------------
11938 -- Validity_Checks --
11939 ---------------------
11941 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11943 when Pragma_Validity_Checks => Validity_Checks : declare
11944 A : constant Node_Id := Expression (Arg1);
11950 Check_Arg_Count (1);
11951 Check_No_Identifiers;
11953 if Nkind (A) = N_String_Literal then
11957 Slen : constant Natural := Natural (String_Length (S));
11958 Options : String (1 .. Slen);
11964 C := Get_String_Char (S, Int (J));
11965 exit when not In_Character_Range (C);
11966 Options (J) := Get_Character (C);
11969 Set_Validity_Check_Options (Options);
11977 elsif Nkind (A) = N_Identifier then
11979 if Chars (A) = Name_All_Checks then
11980 Set_Validity_Check_Options ("a");
11982 elsif Chars (A) = Name_On then
11983 Validity_Checks_On := True;
11985 elsif Chars (A) = Name_Off then
11986 Validity_Checks_On := False;
11990 end Validity_Checks;
11996 -- pragma Volatile (LOCAL_NAME);
11998 when Pragma_Volatile =>
11999 Process_Atomic_Shared_Volatile;
12001 -------------------------
12002 -- Volatile_Components --
12003 -------------------------
12005 -- pragma Volatile_Components (array_LOCAL_NAME);
12007 -- Volatile is handled by the same circuit as Atomic_Components
12013 -- pragma Warnings (On | Off);
12014 -- pragma Warnings (On | Off, LOCAL_NAME);
12015 -- pragma Warnings (static_string_EXPRESSION);
12016 -- pragma Warnings (On | Off, STRING_LITERAL);
12018 when Pragma_Warnings => Warnings : begin
12020 Check_At_Least_N_Arguments (1);
12021 Check_No_Identifiers;
12023 -- If debug flag -gnatd.i is set, pragma is ignored
12025 if Debug_Flag_Dot_I then
12029 -- Process various forms of the pragma
12032 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12035 -- One argument case
12037 if Arg_Count = 1 then
12039 -- On/Off one argument case was processed by parser
12041 if Nkind (Argx) = N_Identifier
12043 (Chars (Argx) = Name_On
12045 Chars (Argx) = Name_Off)
12049 -- One argument case must be ON/OFF or static string expr
12051 elsif not Is_Static_String_Expression (Arg1) then
12053 ("argument of pragma% must be On/Off or " &
12054 "static string expression", Arg2);
12056 -- One argument string expression case
12060 Lit : constant Node_Id := Expr_Value_S (Argx);
12061 Str : constant String_Id := Strval (Lit);
12062 Len : constant Nat := String_Length (Str);
12070 while J <= Len loop
12071 C := Get_String_Char (Str, J);
12072 OK := In_Character_Range (C);
12075 Chr := Get_Character (C);
12079 if J < Len and then Chr = '.' then
12081 C := Get_String_Char (Str, J);
12082 Chr := Get_Character (C);
12084 if not Set_Dot_Warning_Switch (Chr) then
12086 ("invalid warning switch character " &
12093 OK := Set_Warning_Switch (Chr);
12099 ("invalid warning switch character " & Chr,
12108 -- Two or more arguments (must be two)
12111 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12112 Check_At_Most_N_Arguments (2);
12120 E_Id := Expression (Arg2);
12123 -- In the expansion of an inlined body, a reference to
12124 -- the formal may be wrapped in a conversion if the
12125 -- actual is a conversion. Retrieve the real entity name.
12127 if (In_Instance_Body
12128 or else In_Inlined_Body)
12129 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12131 E_Id := Expression (E_Id);
12134 -- Entity name case
12136 if Is_Entity_Name (E_Id) then
12137 E := Entity (E_Id);
12144 (E, (Chars (Expression (Arg1)) = Name_Off));
12146 if Chars (Expression (Arg1)) = Name_Off
12147 and then Warn_On_Warnings_Off
12149 Warnings_Off_Pragmas.Append ((N, E));
12152 if Is_Enumeration_Type (E) then
12156 Lit := First_Literal (E);
12157 while Present (Lit) loop
12158 Set_Warnings_Off (Lit);
12159 Next_Literal (Lit);
12164 exit when No (Homonym (E));
12169 -- Error if not entity or static string literal case
12171 elsif not Is_Static_String_Expression (Arg2) then
12173 ("second argument of pragma% must be entity " &
12174 "name or static string expression", Arg2);
12176 -- String literal case
12179 String_To_Name_Buffer
12180 (Strval (Expr_Value_S (Expression (Arg2))));
12182 -- Note on configuration pragma case: If this is a
12183 -- configuration pragma, then for an OFF pragma, we
12184 -- just set Config True in the call, which is all
12185 -- that needs to be done. For the case of ON, this
12186 -- is normally an error, unless it is canceling the
12187 -- effect of a previous OFF pragma in the same file.
12188 -- In any other case, an error will be signalled (ON
12189 -- with no matching OFF).
12191 if Chars (Argx) = Name_Off then
12192 Set_Specific_Warning_Off
12193 (Loc, Name_Buffer (1 .. Name_Len),
12194 Config => Is_Configuration_Pragma);
12196 elsif Chars (Argx) = Name_On then
12197 Set_Specific_Warning_On
12198 (Loc, Name_Buffer (1 .. Name_Len), Err);
12202 ("?pragma Warnings On with no " &
12203 "matching Warnings Off",
12213 -------------------
12214 -- Weak_External --
12215 -------------------
12217 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12219 when Pragma_Weak_External => Weak_External : declare
12224 Check_Arg_Count (1);
12225 Check_Optional_Identifier (Arg1, Name_Entity);
12226 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12227 Ent := Entity (Expression (Arg1));
12229 if Rep_Item_Too_Early (Ent, N) then
12232 Ent := Underlying_Type (Ent);
12235 -- The only processing required is to link this item on to the
12236 -- list of rep items for the given entity. This is accomplished
12237 -- by the call to Rep_Item_Too_Late (when no error is detected
12238 -- and False is returned).
12240 if Rep_Item_Too_Late (Ent, N) then
12243 Set_Has_Gigi_Rep_Item (Ent);
12247 -----------------------------
12248 -- Wide_Character_Encoding --
12249 -----------------------------
12251 -- pragma Wide_Character_Encoding (IDENTIFIER);
12253 when Pragma_Wide_Character_Encoding =>
12256 -- Nothing to do, handled in parser. Note that we do not enforce
12257 -- configuration pragma placement, this pragma can appear at any
12258 -- place in the source, allowing mixed encodings within a single
12263 --------------------
12264 -- Unknown_Pragma --
12265 --------------------
12267 -- Should be impossible, since the case of an unknown pragma is
12268 -- separately processed before the case statement is entered.
12270 when Unknown_Pragma =>
12271 raise Program_Error;
12275 when Pragma_Exit => null;
12276 end Analyze_Pragma;
12278 -------------------
12279 -- Check_Enabled --
12280 -------------------
12282 function Check_Enabled (Nam : Name_Id) return Boolean is
12286 PP := Opt.Check_Policy_List;
12289 return Assertions_Enabled;
12292 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12295 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12297 when Name_On | Name_Check =>
12299 when Name_Off | Name_Ignore =>
12302 raise Program_Error;
12306 PP := Next_Pragma (PP);
12311 ---------------------------------
12312 -- Delay_Config_Pragma_Analyze --
12313 ---------------------------------
12315 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12317 return Pragma_Name (N) = Name_Interrupt_State
12319 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12320 end Delay_Config_Pragma_Analyze;
12322 -------------------------
12323 -- Get_Base_Subprogram --
12324 -------------------------
12326 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12327 Result : Entity_Id;
12330 -- Follow subprogram renaming chain
12333 while Is_Subprogram (Result)
12335 (Is_Generic_Instance (Result)
12336 or else Nkind (Parent (Declaration_Node (Result))) =
12337 N_Subprogram_Renaming_Declaration)
12338 and then Present (Alias (Result))
12340 Result := Alias (Result);
12344 end Get_Base_Subprogram;
12346 --------------------
12347 -- Get_Pragma_Arg --
12348 --------------------
12350 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12352 if Nkind (Arg) = N_Pragma_Argument_Association then
12353 return Expression (Arg);
12357 end Get_Pragma_Arg;
12363 procedure Initialize is
12368 -----------------------------
12369 -- Is_Config_Static_String --
12370 -----------------------------
12372 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12374 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12375 -- This is an internal recursive function that is just like the outer
12376 -- function except that it adds the string to the name buffer rather
12377 -- than placing the string in the name buffer.
12379 ------------------------------
12380 -- Add_Config_Static_String --
12381 ------------------------------
12383 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12390 if Nkind (N) = N_Op_Concat then
12391 if Add_Config_Static_String (Left_Opnd (N)) then
12392 N := Right_Opnd (N);
12398 if Nkind (N) /= N_String_Literal then
12399 Error_Msg_N ("string literal expected for pragma argument", N);
12403 for J in 1 .. String_Length (Strval (N)) loop
12404 C := Get_String_Char (Strval (N), J);
12406 if not In_Character_Range (C) then
12408 ("string literal contains invalid wide character",
12409 Sloc (N) + 1 + Source_Ptr (J));
12413 Add_Char_To_Name_Buffer (Get_Character (C));
12418 end Add_Config_Static_String;
12420 -- Start of processing for Is_Config_Static_String
12425 return Add_Config_Static_String (Arg);
12426 end Is_Config_Static_String;
12428 -----------------------------------------
12429 -- Is_Non_Significant_Pragma_Reference --
12430 -----------------------------------------
12432 -- This function makes use of the following static table which indicates
12433 -- whether a given pragma is significant. A value of -1 in this table
12434 -- indicates that the reference is significant. A value of zero indicates
12435 -- than appearance as any argument is insignificant, a positive value
12436 -- indicates that appearance in that parameter position is significant.
12438 -- A value of 99 flags a special case requiring a special check (this is
12439 -- used for cases not covered by this standard encoding, e.g. pragma Check
12440 -- where the first argument is not significant, but the others are).
12442 Sig_Flags : constant array (Pragma_Id) of Int :=
12443 (Pragma_AST_Entry => -1,
12444 Pragma_Abort_Defer => -1,
12445 Pragma_Ada_83 => -1,
12446 Pragma_Ada_95 => -1,
12447 Pragma_Ada_05 => -1,
12448 Pragma_Ada_2005 => -1,
12449 Pragma_All_Calls_Remote => -1,
12450 Pragma_Annotate => -1,
12451 Pragma_Assert => -1,
12452 Pragma_Assertion_Policy => 0,
12453 Pragma_Assume_No_Invalid_Values => 0,
12454 Pragma_Asynchronous => -1,
12455 Pragma_Atomic => 0,
12456 Pragma_Atomic_Components => 0,
12457 Pragma_Attach_Handler => -1,
12458 Pragma_Check => 99,
12459 Pragma_Check_Name => 0,
12460 Pragma_Check_Policy => 0,
12461 Pragma_CIL_Constructor => -1,
12462 Pragma_CPP_Class => 0,
12463 Pragma_CPP_Constructor => 0,
12464 Pragma_CPP_Virtual => 0,
12465 Pragma_CPP_Vtable => 0,
12466 Pragma_C_Pass_By_Copy => 0,
12467 Pragma_Comment => 0,
12468 Pragma_Common_Object => -1,
12469 Pragma_Compile_Time_Error => -1,
12470 Pragma_Compile_Time_Warning => -1,
12471 Pragma_Compiler_Unit => 0,
12472 Pragma_Complete_Representation => 0,
12473 Pragma_Complex_Representation => 0,
12474 Pragma_Component_Alignment => -1,
12475 Pragma_Controlled => 0,
12476 Pragma_Convention => 0,
12477 Pragma_Convention_Identifier => 0,
12478 Pragma_Debug => -1,
12479 Pragma_Debug_Policy => 0,
12480 Pragma_Detect_Blocking => -1,
12481 Pragma_Discard_Names => 0,
12482 Pragma_Elaborate => -1,
12483 Pragma_Elaborate_All => -1,
12484 Pragma_Elaborate_Body => -1,
12485 Pragma_Elaboration_Checks => -1,
12486 Pragma_Eliminate => -1,
12487 Pragma_Export => -1,
12488 Pragma_Export_Exception => -1,
12489 Pragma_Export_Function => -1,
12490 Pragma_Export_Object => -1,
12491 Pragma_Export_Procedure => -1,
12492 Pragma_Export_Value => -1,
12493 Pragma_Export_Valued_Procedure => -1,
12494 Pragma_Extend_System => -1,
12495 Pragma_Extensions_Allowed => -1,
12496 Pragma_External => -1,
12497 Pragma_Favor_Top_Level => -1,
12498 Pragma_External_Name_Casing => -1,
12499 Pragma_Fast_Math => -1,
12500 Pragma_Finalize_Storage_Only => 0,
12501 Pragma_Float_Representation => 0,
12502 Pragma_Ident => -1,
12503 Pragma_Implemented_By_Entry => -1,
12504 Pragma_Implicit_Packing => 0,
12505 Pragma_Import => +2,
12506 Pragma_Import_Exception => 0,
12507 Pragma_Import_Function => 0,
12508 Pragma_Import_Object => 0,
12509 Pragma_Import_Procedure => 0,
12510 Pragma_Import_Valued_Procedure => 0,
12511 Pragma_Initialize_Scalars => -1,
12512 Pragma_Inline => 0,
12513 Pragma_Inline_Always => 0,
12514 Pragma_Inline_Generic => 0,
12515 Pragma_Inspection_Point => -1,
12516 Pragma_Interface => +2,
12517 Pragma_Interface_Name => +2,
12518 Pragma_Interrupt_Handler => -1,
12519 Pragma_Interrupt_Priority => -1,
12520 Pragma_Interrupt_State => -1,
12521 Pragma_Java_Constructor => -1,
12522 Pragma_Java_Interface => -1,
12523 Pragma_Keep_Names => 0,
12524 Pragma_License => -1,
12525 Pragma_Link_With => -1,
12526 Pragma_Linker_Alias => -1,
12527 Pragma_Linker_Constructor => -1,
12528 Pragma_Linker_Destructor => -1,
12529 Pragma_Linker_Options => -1,
12530 Pragma_Linker_Section => -1,
12532 Pragma_Locking_Policy => -1,
12533 Pragma_Long_Float => -1,
12534 Pragma_Machine_Attribute => -1,
12536 Pragma_Main_Storage => -1,
12537 Pragma_Memory_Size => -1,
12538 Pragma_No_Return => 0,
12539 Pragma_No_Body => 0,
12540 Pragma_No_Run_Time => -1,
12541 Pragma_No_Strict_Aliasing => -1,
12542 Pragma_Normalize_Scalars => -1,
12543 Pragma_Obsolescent => 0,
12544 Pragma_Optimize => -1,
12545 Pragma_Optimize_Alignment => -1,
12548 Pragma_Passive => -1,
12549 Pragma_Preelaborable_Initialization => -1,
12550 Pragma_Polling => -1,
12551 Pragma_Persistent_BSS => 0,
12552 Pragma_Postcondition => -1,
12553 Pragma_Precondition => -1,
12554 Pragma_Preelaborate => -1,
12555 Pragma_Preelaborate_05 => -1,
12556 Pragma_Priority => -1,
12557 Pragma_Priority_Specific_Dispatching => -1,
12558 Pragma_Profile => 0,
12559 Pragma_Profile_Warnings => 0,
12560 Pragma_Propagate_Exceptions => -1,
12561 Pragma_Psect_Object => -1,
12563 Pragma_Pure_05 => -1,
12564 Pragma_Pure_Function => -1,
12565 Pragma_Queuing_Policy => -1,
12566 Pragma_Ravenscar => -1,
12567 Pragma_Relative_Deadline => -1,
12568 Pragma_Remote_Call_Interface => -1,
12569 Pragma_Remote_Types => -1,
12570 Pragma_Restricted_Run_Time => -1,
12571 Pragma_Restriction_Warnings => -1,
12572 Pragma_Restrictions => -1,
12573 Pragma_Reviewable => -1,
12574 Pragma_Short_Circuit_And_Or => -1,
12575 Pragma_Share_Generic => -1,
12576 Pragma_Shared => -1,
12577 Pragma_Shared_Passive => -1,
12578 Pragma_Source_File_Name => -1,
12579 Pragma_Source_File_Name_Project => -1,
12580 Pragma_Source_Reference => -1,
12581 Pragma_Storage_Size => -1,
12582 Pragma_Storage_Unit => -1,
12583 Pragma_Static_Elaboration_Desired => -1,
12584 Pragma_Stream_Convert => -1,
12585 Pragma_Style_Checks => -1,
12586 Pragma_Subtitle => -1,
12587 Pragma_Suppress => 0,
12588 Pragma_Suppress_Exception_Locations => 0,
12589 Pragma_Suppress_All => -1,
12590 Pragma_Suppress_Debug_Info => 0,
12591 Pragma_Suppress_Initialization => 0,
12592 Pragma_System_Name => -1,
12593 Pragma_Task_Dispatching_Policy => -1,
12594 Pragma_Task_Info => -1,
12595 Pragma_Task_Name => -1,
12596 Pragma_Task_Storage => 0,
12597 Pragma_Thread_Local_Storage => 0,
12598 Pragma_Time_Slice => -1,
12599 Pragma_Title => -1,
12600 Pragma_Unchecked_Union => 0,
12601 Pragma_Unimplemented_Unit => -1,
12602 Pragma_Universal_Aliasing => -1,
12603 Pragma_Universal_Data => -1,
12604 Pragma_Unmodified => -1,
12605 Pragma_Unreferenced => -1,
12606 Pragma_Unreferenced_Objects => -1,
12607 Pragma_Unreserve_All_Interrupts => -1,
12608 Pragma_Unsuppress => 0,
12609 Pragma_Use_VADS_Size => -1,
12610 Pragma_Validity_Checks => -1,
12611 Pragma_Volatile => 0,
12612 Pragma_Volatile_Components => 0,
12613 Pragma_Warnings => -1,
12614 Pragma_Weak_External => -1,
12615 Pragma_Wide_Character_Encoding => 0,
12616 Unknown_Pragma => 0);
12618 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12627 if Nkind (P) /= N_Pragma_Argument_Association then
12631 Id := Get_Pragma_Id (Parent (P));
12632 C := Sig_Flags (Id);
12644 -- For pragma Check, the first argument is not significant,
12645 -- the second and the third (if present) arguments are
12648 when Pragma_Check =>
12650 P = First (Pragma_Argument_Associations (Parent (P)));
12653 raise Program_Error;
12657 A := First (Pragma_Argument_Associations (Parent (P)));
12658 for J in 1 .. C - 1 loop
12666 return A = P; -- is this wrong way round ???
12669 end Is_Non_Significant_Pragma_Reference;
12671 ------------------------------
12672 -- Is_Pragma_String_Literal --
12673 ------------------------------
12675 -- This function returns true if the corresponding pragma argument is a
12676 -- static string expression. These are the only cases in which string
12677 -- literals can appear as pragma arguments. We also allow a string literal
12678 -- as the first argument to pragma Assert (although it will of course
12679 -- always generate a type error).
12681 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12682 Pragn : constant Node_Id := Parent (Par);
12683 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12684 Pname : constant Name_Id := Pragma_Name (Pragn);
12690 N := First (Assoc);
12697 if Pname = Name_Assert then
12700 elsif Pname = Name_Export then
12703 elsif Pname = Name_Ident then
12706 elsif Pname = Name_Import then
12709 elsif Pname = Name_Interface_Name then
12712 elsif Pname = Name_Linker_Alias then
12715 elsif Pname = Name_Linker_Section then
12718 elsif Pname = Name_Machine_Attribute then
12721 elsif Pname = Name_Source_File_Name then
12724 elsif Pname = Name_Source_Reference then
12727 elsif Pname = Name_Title then
12730 elsif Pname = Name_Subtitle then
12736 end Is_Pragma_String_Literal;
12738 --------------------------------------
12739 -- Process_Compilation_Unit_Pragmas --
12740 --------------------------------------
12742 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12744 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12745 -- strange because it comes at the end of the unit. If we have a pragma
12746 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12747 -- a pragma Suppress (All_Checks) at the start of the context clause to
12748 -- ensure the correct processing.
12751 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12755 if Present (PA) then
12757 while Present (P) loop
12758 if Pragma_Name (P) = Name_Suppress_All then
12759 Prepend_To (Context_Items (N),
12760 Make_Pragma (Sloc (P),
12761 Chars => Name_Suppress,
12762 Pragma_Argument_Associations => New_List (
12763 Make_Pragma_Argument_Association (Sloc (P),
12765 Make_Identifier (Sloc (P),
12766 Chars => Name_All_Checks)))));
12774 end Process_Compilation_Unit_Pragmas;
12785 --------------------------------
12786 -- Set_Encoded_Interface_Name --
12787 --------------------------------
12789 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12790 Str : constant String_Id := Strval (S);
12791 Len : constant Int := String_Length (Str);
12796 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12799 -- Stores encoded value of character code CC. The encoding we use an
12800 -- underscore followed by four lower case hex digits.
12806 procedure Encode is
12808 Store_String_Char (Get_Char_Code ('_'));
12810 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12812 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12814 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12816 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12819 -- Start of processing for Set_Encoded_Interface_Name
12822 -- If first character is asterisk, this is a link name, and we leave it
12823 -- completely unmodified. We also ignore null strings (the latter case
12824 -- happens only in error cases) and no encoding should occur for Java or
12825 -- AAMP interface names.
12828 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12829 or else VM_Target /= No_VM
12830 or else AAMP_On_Target
12832 Set_Interface_Name (E, S);
12837 CC := Get_String_Char (Str, J);
12839 exit when not In_Character_Range (CC);
12841 C := Get_Character (CC);
12843 exit when C /= '_' and then C /= '$'
12844 and then C not in '0' .. '9'
12845 and then C not in 'a' .. 'z'
12846 and then C not in 'A' .. 'Z';
12849 Set_Interface_Name (E, S);
12857 -- Here we need to encode. The encoding we use as follows:
12858 -- three underscores + four hex digits (lower case)
12862 for J in 1 .. String_Length (Str) loop
12863 CC := Get_String_Char (Str, J);
12865 if not In_Character_Range (CC) then
12868 C := Get_Character (CC);
12870 if C = '_' or else C = '$'
12871 or else C in '0' .. '9'
12872 or else C in 'a' .. 'z'
12873 or else C in 'A' .. 'Z'
12875 Store_String_Char (CC);
12882 Set_Interface_Name (E,
12883 Make_String_Literal (Sloc (S),
12884 Strval => End_String));
12886 end Set_Encoded_Interface_Name;
12888 -------------------
12889 -- Set_Unit_Name --
12890 -------------------
12892 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12897 if Nkind (N) = N_Identifier
12898 and then Nkind (With_Item) = N_Identifier
12900 Set_Entity (N, Entity (With_Item));
12902 elsif Nkind (N) = N_Selected_Component then
12903 Change_Selected_Component_To_Expanded_Name (N);
12904 Set_Entity (N, Entity (With_Item));
12905 Set_Entity (Selector_Name (N), Entity (N));
12907 Pref := Prefix (N);
12908 Scop := Scope (Entity (N));
12909 while Nkind (Pref) = N_Selected_Component loop
12910 Change_Selected_Component_To_Expanded_Name (Pref);
12911 Set_Entity (Selector_Name (Pref), Scop);
12912 Set_Entity (Pref, Scop);
12913 Pref := Prefix (Pref);
12914 Scop := Scope (Scop);
12917 Set_Entity (Pref, Scop);