1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elim; use Sem_Elim;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Intr; use Sem_Intr;
65 with Sem_Mech; use Sem_Mech;
66 with Sem_Res; use Sem_Res;
67 with Sem_Type; use Sem_Type;
68 with Sem_Util; use Sem_Util;
69 with Sem_VFpt; use Sem_VFpt;
70 with Sem_Warn; use Sem_Warn;
71 with Stand; use Stand;
72 with Sinfo; use Sinfo;
73 with Sinfo.CN; use Sinfo.CN;
74 with Sinput; use Sinput;
75 with Snames; use Snames;
76 with Stringt; use Stringt;
77 with Stylesw; use Stylesw;
79 with Targparm; use Targparm;
80 with Tbuild; use Tbuild;
82 with Uintp; use Uintp;
83 with Uname; use Uname;
84 with Urealp; use Urealp;
85 with Validsw; use Validsw;
87 package body Sem_Prag is
89 ----------------------------------------------
90 -- Common Handling of Import-Export Pragmas --
91 ----------------------------------------------
93 -- In the following section, a number of Import_xxx and Export_xxx
94 -- pragmas are defined by GNAT. These are compatible with the DEC
95 -- pragmas of the same name, and all have the following common
96 -- form and processing:
99 -- [Internal =>] LOCAL_NAME
100 -- [, [External =>] EXTERNAL_SYMBOL]
101 -- [, other optional parameters ]);
104 -- [Internal =>] LOCAL_NAME
105 -- [, [External =>] EXTERNAL_SYMBOL]
106 -- [, other optional parameters ]);
108 -- EXTERNAL_SYMBOL ::=
110 -- | static_string_EXPRESSION
112 -- The internal LOCAL_NAME designates the entity that is imported or
113 -- exported, and must refer to an entity in the current declarative
114 -- part (as required by the rules for LOCAL_NAME).
116 -- The external linker name is designated by the External parameter if
117 -- given, or the Internal parameter if not (if there is no External
118 -- parameter, the External parameter is a copy of the Internal name).
120 -- If the External parameter is given as a string, then this string is
121 -- treated as an external name (exactly as though it had been given as an
122 -- External_Name parameter for a normal Import pragma).
124 -- If the External parameter is given as an identifier (or there is no
125 -- External parameter, so that the Internal identifier is used), then
126 -- the external name is the characters of the identifier, translated
127 -- to all upper case letters for OpenVMS versions of GNAT, and to all
128 -- lower case letters for all other versions
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
169 -- This routine is used for possible casing adjustment of an explicit
170 -- external name supplied as a string literal (the node N), according to
171 -- the casing requirement of Opt.External_Name_Casing. If this is set to
172 -- As_Is, then the string literal is returned unchanged, but if it is set
173 -- to Uppercase or Lowercase, then a new string literal with appropriate
174 -- casing is constructed.
176 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
177 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
178 -- original one, following the renaming chain) is returned. Otherwise the
179 -- entity is returned unchanged. Should be in Einfo???
181 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
182 -- All the routines that check pragma arguments take either a pragma
183 -- argument association (in which case the expression of the argument
184 -- association is checked), or the expression directly. The function
185 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
186 -- is a pragma argument association node, then its expression is returned,
187 -- otherwise Arg is returned unchanged.
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id :=
252 First (Pragma_Argument_Associations (N));
253 Arg2 : constant Node_Id := Next (Arg1);
256 -- Install formals and push subprogram spec onto scope stack so that we
257 -- can see the formals from the pragma.
262 -- Preanalyze the boolean expression, we treat this as a spec expression
263 -- (i.e. similar to a default expression).
265 Preanalyze_Spec_Expression
266 (Get_Pragma_Arg (Arg1), Standard_Boolean);
268 -- If there is a message argument, analyze it the same way
270 if Present (Arg2) then
271 Preanalyze_Spec_Expression
272 (Get_Pragma_Arg (Arg2), Standard_String);
275 -- Remove the subprogram from the scope stack now that the pre-analysis
276 -- of the precondition/postcondition is done.
279 end Analyze_PPC_In_Decl_Part;
285 procedure Analyze_Pragma (N : Node_Id) is
286 Loc : constant Source_Ptr := Sloc (N);
287 Pname : constant Name_Id := Pragma_Name (N);
290 Pragma_Exit : exception;
291 -- This exception is used to exit pragma processing completely. It is
292 -- used when an error is detected, and no further processing is
293 -- required. It is also used if an earlier error has left the tree in
294 -- a state where the pragma should not be processed.
297 -- Number of pragma argument associations
303 -- First four pragma arguments (pragma argument association nodes, or
304 -- Empty if the corresponding argument does not exist).
306 type Name_List is array (Natural range <>) of Name_Id;
307 type Args_List is array (Natural range <>) of Node_Id;
308 -- Types used for arguments to Check_Arg_Order and Gather_Associations
310 procedure Ada_2005_Pragma;
311 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
312 -- Ada 95 mode, these are implementation defined pragmas, so should be
313 -- caught by the No_Implementation_Pragmas restriction.
315 procedure Ada_2012_Pragma;
316 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
317 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
318 -- should be caught by the No_Implementation_Pragmas restriction.
320 procedure Check_Ada_83_Warning;
321 -- Issues a warning message for the current pragma if operating in Ada
322 -- 83 mode (used for language pragmas that are not a standard part of
323 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
326 procedure Check_Arg_Count (Required : Nat);
327 -- Check argument count for pragma is equal to given parameter. If not,
328 -- then issue an error message and raise Pragma_Exit.
330 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
331 -- Arg which can either be a pragma argument association, in which case
332 -- the check is applied to the expression of the association or an
333 -- expression directly.
335 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
336 -- Check that an argument has the right form for an EXTERNAL_NAME
337 -- parameter of an extended import/export pragma. The rule is that the
338 -- name must be an identifier or string literal (in Ada 83 mode) or a
339 -- static string expression (in Ada 95 mode).
341 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
342 -- Check the specified argument Arg to make sure that it is an
343 -- identifier. If not give error and raise Pragma_Exit.
345 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
346 -- Check the specified argument Arg to make sure that it is an integer
347 -- literal. If not give error and raise Pragma_Exit.
349 procedure Check_Arg_Is_Library_Level_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. In addition, the local name is required
354 -- to represent an entity at the library level.
356 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
357 -- Check the specified argument Arg to make sure that it has the proper
358 -- syntactic form for a local name and meets the semantic requirements
359 -- for a local name. The local name is analyzed as part of the
360 -- processing for this call.
362 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
363 -- Check the specified argument Arg to make sure that it is a valid
364 -- locking policy name. If not give error and raise Pragma_Exit.
366 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
367 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
368 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
369 -- Check the specified argument Arg to make sure that it is an
370 -- identifier whose name matches either N1 or N2 (or N3 if present).
371 -- If not then give error and raise Pragma_Exit.
373 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
374 -- Check the specified argument Arg to make sure that it is a valid
375 -- queuing policy name. If not give error and raise Pragma_Exit.
377 procedure Check_Arg_Is_Static_Expression
379 Typ : Entity_Id := Empty);
380 -- Check the specified argument Arg to make sure that it is a static
381 -- expression of the given type (i.e. it will be analyzed and resolved
382 -- using this type, which can be any valid argument to Resolve, e.g.
383 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
384 -- Typ is left Empty, then any static expression is allowed.
386 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
387 -- Check the specified argument Arg to make sure that it is a valid task
388 -- dispatching policy name. If not give error and raise Pragma_Exit.
390 procedure Check_Arg_Order (Names : Name_List);
391 -- Checks for an instance of two arguments with identifiers for the
392 -- current pragma which are not in the sequence indicated by Names,
393 -- and if so, generates a fatal message about bad order of arguments.
395 procedure Check_At_Least_N_Arguments (N : Nat);
396 -- Check there are at least N arguments present
398 procedure Check_At_Most_N_Arguments (N : Nat);
399 -- Check there are no more than N arguments present
401 procedure Check_Component
404 In_Variant_Part : Boolean := False);
405 -- Examine an Unchecked_Union component for correct use of per-object
406 -- constrained subtypes, and for restrictions on finalizable components.
407 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
408 -- should be set when Comp comes from a record variant.
410 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
411 -- Nam is an N_String_Literal node containing the external name set by
412 -- an Import or Export pragma (or extended Import or Export pragma).
413 -- This procedure checks for possible duplications if this is the export
414 -- case, and if found, issues an appropriate error message.
416 procedure Check_First_Subtype (Arg : Node_Id);
417 -- Checks that Arg, whose expression is an entity name referencing a
418 -- subtype, does not reference a type that is not a first subtype.
420 procedure Check_In_Main_Program;
421 -- Common checks for pragmas that appear within a main program
422 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
424 procedure Check_Interrupt_Or_Attach_Handler;
425 -- Common processing for first argument of pragma Interrupt_Handler or
426 -- pragma Attach_Handler.
428 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
429 -- Check that pragma appears in a declarative part, or in a package
430 -- specification, i.e. that it does not occur in a statement sequence
433 procedure Check_No_Identifier (Arg : Node_Id);
434 -- Checks that the given argument does not have an identifier. If
435 -- an identifier is present, then an error message is issued, and
436 -- Pragma_Exit is raised.
438 procedure Check_No_Identifiers;
439 -- Checks that none of the arguments to the pragma has an identifier.
440 -- If any argument has an identifier, then an error message is issued,
441 -- and Pragma_Exit is raised.
443 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
444 -- Checks if the given argument has an identifier, and if so, requires
445 -- it to match the given identifier name. If there is a non-matching
446 -- identifier, then an error message is given and Error_Pragmas raised.
448 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
449 -- Checks if the given argument has an identifier, and if so, requires
450 -- it to match the given identifier name. If there is a non-matching
451 -- identifier, then an error message is given and Error_Pragmas raised.
452 -- In this version of the procedure, the identifier name is given as
453 -- a string with lower case letters.
455 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
456 -- Called to process a precondition or postcondition pragma. There are
459 -- The pragma appears after a subprogram spec
461 -- If the corresponding check is not enabled, the pragma is analyzed
462 -- but otherwise ignored and control returns with In_Body set False.
464 -- If the check is enabled, then the first step is to analyze the
465 -- pragma, but this is skipped if the subprogram spec appears within
466 -- a package specification (because this is the case where we delay
467 -- analysis till the end of the spec). Then (whether or not it was
468 -- analyzed), the pragma is chained to the subprogram in question
469 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
470 -- caller with In_Body set False.
472 -- The pragma appears at the start of subprogram body declarations
474 -- In this case an immediate return to the caller is made with
475 -- In_Body set True, and the pragma is NOT analyzed.
477 -- In all other cases, an error message for bad placement is given
479 procedure Check_Static_Constraint (Constr : Node_Id);
480 -- Constr is a constraint from an N_Subtype_Indication node from a
481 -- component constraint in an Unchecked_Union type. This routine checks
482 -- that the constraint is static as required by the restrictions for
485 procedure Check_Valid_Configuration_Pragma;
486 -- Legality checks for placement of a configuration pragma
488 procedure Check_Valid_Library_Unit_Pragma;
489 -- Legality checks for library unit pragmas. A special case arises for
490 -- pragmas in generic instances that come from copies of the original
491 -- library unit pragmas in the generic templates. In the case of other
492 -- than library level instantiations these can appear in contexts which
493 -- would normally be invalid (they only apply to the original template
494 -- and to library level instantiations), and they are simply ignored,
495 -- which is implemented by rewriting them as null statements.
497 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
498 -- Check an Unchecked_Union variant for lack of nested variants and
499 -- presence of at least one component. UU_Typ is the related Unchecked_
502 procedure Error_Pragma (Msg : String);
503 pragma No_Return (Error_Pragma);
504 -- Outputs error message for current pragma. The message contains a %
505 -- that will be replaced with the pragma name, and the flag is placed
506 -- on the pragma itself. Pragma_Exit is then raised.
508 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
509 pragma No_Return (Error_Pragma_Arg);
510 -- Outputs error message for current pragma. The message may contain
511 -- a % that will be replaced with the pragma name. The parameter Arg
512 -- may either be a pragma argument association, in which case the flag
513 -- is placed on the expression of this association, or an expression,
514 -- in which case the flag is placed directly on the expression. The
515 -- message is placed using Error_Msg_N, so the message may also contain
516 -- an & insertion character which will reference the given Arg value.
517 -- After placing the message, Pragma_Exit is raised.
519 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
520 pragma No_Return (Error_Pragma_Arg);
521 -- Similar to above form of Error_Pragma_Arg except that two messages
522 -- are provided, the second is a continuation comment starting with \.
524 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
525 pragma No_Return (Error_Pragma_Arg_Ident);
526 -- Outputs error message for current pragma. The message may contain
527 -- a % that will be replaced with the pragma name. The parameter Arg
528 -- must be a pragma argument association with a non-empty identifier
529 -- (i.e. its Chars field must be set), and the error message is placed
530 -- on the identifier. The message is placed using Error_Msg_N so
531 -- the message may also contain an & insertion character which will
532 -- reference the identifier. After placing the message, Pragma_Exit
535 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
536 pragma No_Return (Error_Pragma_Ref);
537 -- Outputs error message for current pragma. The message may contain
538 -- a % that will be replaced with the pragma name. The parameter Ref
539 -- must be an entity whose name can be referenced by & and sloc by #.
540 -- After placing the message, Pragma_Exit is raised.
542 function Find_Lib_Unit_Name return Entity_Id;
543 -- Used for a library unit pragma to find the entity to which the
544 -- library unit pragma applies, returns the entity found.
546 procedure Find_Program_Unit_Name (Id : Node_Id);
547 -- If the pragma is a compilation unit pragma, the id must denote the
548 -- compilation unit in the same compilation, and the pragma must appear
549 -- in the list of preceding or trailing pragmas. If it is a program
550 -- unit pragma that is not a compilation unit pragma, then the
551 -- identifier must be visible.
553 function Find_Unique_Parameterless_Procedure
555 Arg : Node_Id) return Entity_Id;
556 -- Used for a procedure pragma to find the unique parameterless
557 -- procedure identified by Name, returns it if it exists, otherwise
558 -- errors out and uses Arg as the pragma argument for the message.
560 procedure Gather_Associations
562 Args : out Args_List);
563 -- This procedure is used to gather the arguments for a pragma that
564 -- permits arbitrary ordering of parameters using the normal rules
565 -- for named and positional parameters. The Names argument is a list
566 -- of Name_Id values that corresponds to the allowed pragma argument
567 -- association identifiers in order. The result returned in Args is
568 -- a list of corresponding expressions that are the pragma arguments.
569 -- Note that this is a list of expressions, not of pragma argument
570 -- associations (Gather_Associations has completely checked all the
571 -- optional identifiers when it returns). An entry in Args is Empty
572 -- on return if the corresponding argument is not present.
574 procedure GNAT_Pragma;
575 -- Called for all GNAT defined pragmas to check the relevant restriction
576 -- (No_Implementation_Pragmas).
578 function Is_Before_First_Decl
579 (Pragma_Node : Node_Id;
580 Decls : List_Id) return Boolean;
581 -- Return True if Pragma_Node is before the first declarative item in
582 -- Decls where Decls is the list of declarative items.
584 function Is_Configuration_Pragma return Boolean;
585 -- Determines if the placement of the current pragma is appropriate
586 -- for a configuration pragma.
588 function Is_In_Context_Clause return Boolean;
589 -- Returns True if pragma appears within the context clause of a unit,
590 -- and False for any other placement (does not generate any messages).
592 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
593 -- Analyzes the argument, and determines if it is a static string
594 -- expression, returns True if so, False if non-static or not String.
596 procedure Pragma_Misplaced;
597 pragma No_Return (Pragma_Misplaced);
598 -- Issue fatal error message for misplaced pragma
600 procedure Process_Atomic_Shared_Volatile;
601 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
602 -- Shared is an obsolete Ada 83 pragma, treated as being identical
603 -- in effect to pragma Atomic.
605 procedure Process_Compile_Time_Warning_Or_Error;
606 -- Common processing for Compile_Time_Error and Compile_Time_Warning
608 procedure Process_Convention
609 (C : out Convention_Id;
610 Ent : out Entity_Id);
611 -- Common processing for Convention, Interface, Import and Export.
612 -- Checks first two arguments of pragma, and sets the appropriate
613 -- convention value in the specified entity or entities. On return
614 -- C is the convention, Ent is the referenced entity.
616 procedure Process_Extended_Import_Export_Exception_Pragma
617 (Arg_Internal : Node_Id;
618 Arg_External : Node_Id;
621 -- Common processing for the pragmas Import/Export_Exception. The three
622 -- arguments correspond to the three named parameters of the pragma. An
623 -- argument is empty if the corresponding parameter is not present in
626 procedure Process_Extended_Import_Export_Object_Pragma
627 (Arg_Internal : Node_Id;
628 Arg_External : Node_Id;
630 -- Common processing for the pragmas Import/Export_Object. The three
631 -- arguments correspond to the three named parameters of the pragmas. An
632 -- argument is empty if the corresponding parameter is not present in
635 procedure Process_Extended_Import_Export_Internal_Arg
636 (Arg_Internal : Node_Id := Empty);
637 -- Common processing for all extended Import and Export pragmas. The
638 -- argument is the pragma parameter for the Internal argument. If
639 -- Arg_Internal is empty or inappropriate, an error message is posted.
640 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
641 -- set to identify the referenced entity.
643 procedure Process_Extended_Import_Export_Subprogram_Pragma
644 (Arg_Internal : Node_Id;
645 Arg_External : Node_Id;
646 Arg_Parameter_Types : Node_Id;
647 Arg_Result_Type : Node_Id := Empty;
648 Arg_Mechanism : Node_Id;
649 Arg_Result_Mechanism : Node_Id := Empty;
650 Arg_First_Optional_Parameter : Node_Id := Empty);
651 -- Common processing for all extended Import and Export pragmas applying
652 -- to subprograms. The caller omits any arguments that do not apply to
653 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
654 -- only in the Import_Function and Export_Function cases). The argument
655 -- names correspond to the allowed pragma association identifiers.
657 procedure Process_Generic_List;
658 -- Common processing for Share_Generic and Inline_Generic
660 procedure Process_Import_Or_Interface;
661 -- Common processing for Import of Interface
663 procedure Process_Inline (Active : Boolean);
664 -- Common processing for Inline and Inline_Always. The parameter
665 -- indicates if the inline pragma is active, i.e. if it should actually
666 -- cause inlining to occur.
668 procedure Process_Interface_Name
669 (Subprogram_Def : Entity_Id;
672 -- Given the last two arguments of pragma Import, pragma Export, or
673 -- pragma Interface_Name, performs validity checks and sets the
674 -- Interface_Name field of the given subprogram entity to the
675 -- appropriate external or link name, depending on the arguments given.
676 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
677 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
678 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
679 -- nor Link_Arg is present, the interface name is set to the default
680 -- from the subprogram name.
682 procedure Process_Interrupt_Or_Attach_Handler;
683 -- Common processing for Interrupt and Attach_Handler pragmas
685 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
686 -- Common processing for Restrictions and Restriction_Warnings pragmas.
687 -- Warn is True for Restriction_Warnings, or for Restrictions if the
688 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
689 -- is not set in the Restrictions case.
691 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
692 -- Common processing for Suppress and Unsuppress. The boolean parameter
693 -- Suppress_Case is True for the Suppress case, and False for the
696 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
697 -- This procedure sets the Is_Exported flag for the given entity,
698 -- checking that the entity was not previously imported. Arg is
699 -- the argument that specified the entity. A check is also made
700 -- for exporting inappropriate entities.
702 procedure Set_Extended_Import_Export_External_Name
703 (Internal_Ent : Entity_Id;
704 Arg_External : Node_Id);
705 -- Common processing for all extended import export pragmas. The first
706 -- argument, Internal_Ent, is the internal entity, which has already
707 -- been checked for validity by the caller. Arg_External is from the
708 -- Import or Export pragma, and may be null if no External parameter
709 -- was present. If Arg_External is present and is a non-null string
710 -- (a null string is treated as the default), then the Interface_Name
711 -- field of Internal_Ent is set appropriately.
713 procedure Set_Imported (E : Entity_Id);
714 -- This procedure sets the Is_Imported flag for the given entity,
715 -- checking that it is not previously exported or imported.
717 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
718 -- Mech is a parameter passing mechanism (see Import_Function syntax
719 -- for MECHANISM_NAME). This routine checks that the mechanism argument
720 -- has the right form, and if not issues an error message. If the
721 -- argument has the right form then the Mechanism field of Ent is
722 -- set appropriately.
724 procedure Set_Ravenscar_Profile (N : Node_Id);
725 -- Activate the set of configuration pragmas and restrictions that make
726 -- up the Ravenscar Profile. N is the corresponding pragma node, which
727 -- is used for error messages on any constructs that violate the
730 ---------------------
731 -- Ada_2005_Pragma --
732 ---------------------
734 procedure Ada_2005_Pragma is
736 if Ada_Version <= Ada_95 then
737 Check_Restriction (No_Implementation_Pragmas, N);
741 ---------------------
742 -- Ada_2012_Pragma --
743 ---------------------
745 procedure Ada_2012_Pragma is
747 if Ada_Version <= Ada_05 then
748 Check_Restriction (No_Implementation_Pragmas, N);
752 --------------------------
753 -- Check_Ada_83_Warning --
754 --------------------------
756 procedure Check_Ada_83_Warning is
758 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
759 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
761 end Check_Ada_83_Warning;
763 ---------------------
764 -- Check_Arg_Count --
765 ---------------------
767 procedure Check_Arg_Count (Required : Nat) is
769 if Arg_Count /= Required then
770 Error_Pragma ("wrong number of arguments for pragma%");
774 --------------------------------
775 -- Check_Arg_Is_External_Name --
776 --------------------------------
778 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
779 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
782 if Nkind (Argx) = N_Identifier then
786 Analyze_And_Resolve (Argx, Standard_String);
788 if Is_OK_Static_Expression (Argx) then
791 elsif Etype (Argx) = Any_Type then
794 -- An interesting special case, if we have a string literal and
795 -- we are in Ada 83 mode, then we allow it even though it will
796 -- not be flagged as static. This allows expected Ada 83 mode
797 -- use of external names which are string literals, even though
798 -- technically these are not static in Ada 83.
800 elsif Ada_Version = Ada_83
801 and then Nkind (Argx) = N_String_Literal
805 -- Static expression that raises Constraint_Error. This has
806 -- already been flagged, so just exit from pragma processing.
808 elsif Is_Static_Expression (Argx) then
811 -- Here we have a real error (non-static expression)
814 Error_Msg_Name_1 := Pname;
816 ("argument for pragma% must be a identifier or " &
817 "static string expression!", Argx);
821 end Check_Arg_Is_External_Name;
823 -----------------------------
824 -- Check_Arg_Is_Identifier --
825 -----------------------------
827 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
828 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
830 if Nkind (Argx) /= N_Identifier then
832 ("argument for pragma% must be identifier", Argx);
834 end Check_Arg_Is_Identifier;
836 ----------------------------------
837 -- Check_Arg_Is_Integer_Literal --
838 ----------------------------------
840 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
841 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
843 if Nkind (Argx) /= N_Integer_Literal then
845 ("argument for pragma% must be integer literal", Argx);
847 end Check_Arg_Is_Integer_Literal;
849 -------------------------------------------
850 -- Check_Arg_Is_Library_Level_Local_Name --
851 -------------------------------------------
855 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
856 -- | library_unit_NAME
858 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
860 Check_Arg_Is_Local_Name (Arg);
862 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
863 and then Comes_From_Source (N)
866 ("argument for pragma% must be library level entity", Arg);
868 end Check_Arg_Is_Library_Level_Local_Name;
870 -----------------------------
871 -- Check_Arg_Is_Local_Name --
872 -----------------------------
876 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
877 -- | library_unit_NAME
879 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
880 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
885 if Nkind (Argx) not in N_Direct_Name
886 and then (Nkind (Argx) /= N_Attribute_Reference
887 or else Present (Expressions (Argx))
888 or else Nkind (Prefix (Argx)) /= N_Identifier)
889 and then (not Is_Entity_Name (Argx)
890 or else not Is_Compilation_Unit (Entity (Argx)))
892 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
895 if Is_Entity_Name (Argx)
896 and then Scope (Entity (Argx)) /= Current_Scope
899 ("pragma% argument must be in same declarative part", Arg);
901 end Check_Arg_Is_Local_Name;
903 ---------------------------------
904 -- Check_Arg_Is_Locking_Policy --
905 ---------------------------------
907 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
908 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
911 Check_Arg_Is_Identifier (Argx);
913 if not Is_Locking_Policy_Name (Chars (Argx)) then
915 ("& is not a valid locking policy name", Argx);
917 end Check_Arg_Is_Locking_Policy;
919 -------------------------
920 -- Check_Arg_Is_One_Of --
921 -------------------------
923 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
924 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
927 Check_Arg_Is_Identifier (Argx);
929 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
930 Error_Msg_Name_2 := N1;
931 Error_Msg_Name_3 := N2;
932 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
934 end Check_Arg_Is_One_Of;
936 procedure Check_Arg_Is_One_Of
938 N1, N2, N3 : Name_Id)
940 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
943 Check_Arg_Is_Identifier (Argx);
945 if Chars (Argx) /= N1
946 and then Chars (Argx) /= N2
947 and then Chars (Argx) /= N3
949 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
951 end Check_Arg_Is_One_Of;
953 procedure Check_Arg_Is_One_Of
955 N1, N2, N3, N4 : Name_Id)
957 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
960 Check_Arg_Is_Identifier (Argx);
962 if Chars (Argx) /= N1
963 and then Chars (Argx) /= N2
964 and then Chars (Argx) /= N3
965 and then Chars (Argx) /= N4
967 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
969 end Check_Arg_Is_One_Of;
971 ---------------------------------
972 -- Check_Arg_Is_Queuing_Policy --
973 ---------------------------------
975 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
976 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
979 Check_Arg_Is_Identifier (Argx);
981 if not Is_Queuing_Policy_Name (Chars (Argx)) then
983 ("& is not a valid queuing policy name", Argx);
985 end Check_Arg_Is_Queuing_Policy;
987 ------------------------------------
988 -- Check_Arg_Is_Static_Expression --
989 ------------------------------------
991 procedure Check_Arg_Is_Static_Expression
993 Typ : Entity_Id := Empty)
995 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
998 if Present (Typ) then
999 Analyze_And_Resolve (Argx, Typ);
1001 Analyze_And_Resolve (Argx);
1004 if Is_OK_Static_Expression (Argx) then
1007 elsif Etype (Argx) = Any_Type then
1010 -- An interesting special case, if we have a string literal and we
1011 -- are in Ada 83 mode, then we allow it even though it will not be
1012 -- flagged as static. This allows the use of Ada 95 pragmas like
1013 -- Import in Ada 83 mode. They will of course be flagged with
1014 -- warnings as usual, but will not cause errors.
1016 elsif Ada_Version = Ada_83
1017 and then Nkind (Argx) = N_String_Literal
1021 -- Static expression that raises Constraint_Error. This has already
1022 -- been flagged, so just exit from pragma processing.
1024 elsif Is_Static_Expression (Argx) then
1027 -- Finally, we have a real error
1030 Error_Msg_Name_1 := Pname;
1031 Flag_Non_Static_Expr
1032 ("argument for pragma% must be a static expression!", Argx);
1035 end Check_Arg_Is_Static_Expression;
1037 ------------------------------------------
1038 -- Check_Arg_Is_Task_Dispatching_Policy --
1039 ------------------------------------------
1041 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1042 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1045 Check_Arg_Is_Identifier (Argx);
1047 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1049 ("& is not a valid task dispatching policy name", Argx);
1051 end Check_Arg_Is_Task_Dispatching_Policy;
1053 ---------------------
1054 -- Check_Arg_Order --
1055 ---------------------
1057 procedure Check_Arg_Order (Names : Name_List) is
1060 Highest_So_Far : Natural := 0;
1061 -- Highest index in Names seen do far
1065 for J in 1 .. Arg_Count loop
1066 if Chars (Arg) /= No_Name then
1067 for K in Names'Range loop
1068 if Chars (Arg) = Names (K) then
1069 if K < Highest_So_Far then
1070 Error_Msg_Name_1 := Pname;
1072 ("parameters out of order for pragma%", Arg);
1073 Error_Msg_Name_1 := Names (K);
1074 Error_Msg_Name_2 := Names (Highest_So_Far);
1075 Error_Msg_N ("\% must appear before %", Arg);
1079 Highest_So_Far := K;
1087 end Check_Arg_Order;
1089 --------------------------------
1090 -- Check_At_Least_N_Arguments --
1091 --------------------------------
1093 procedure Check_At_Least_N_Arguments (N : Nat) is
1095 if Arg_Count < N then
1096 Error_Pragma ("too few arguments for pragma%");
1098 end Check_At_Least_N_Arguments;
1100 -------------------------------
1101 -- Check_At_Most_N_Arguments --
1102 -------------------------------
1104 procedure Check_At_Most_N_Arguments (N : Nat) is
1107 if Arg_Count > N then
1109 for J in 1 .. N loop
1111 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1114 end Check_At_Most_N_Arguments;
1116 ---------------------
1117 -- Check_Component --
1118 ---------------------
1120 procedure Check_Component
1123 In_Variant_Part : Boolean := False)
1125 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1126 Sindic : constant Node_Id :=
1127 Subtype_Indication (Component_Definition (Comp));
1128 Typ : constant Entity_Id := Etype (Comp_Id);
1130 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1131 -- Determine whether entity Id appears inside a generic body
1133 -------------------------
1134 -- Inside_Generic_Body --
1135 -------------------------
1137 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1138 S : Entity_Id := Id;
1142 and then S /= Standard_Standard
1144 if Ekind (S) = E_Generic_Package
1145 and then In_Package_Body (S)
1154 end Inside_Generic_Body;
1156 -- Start of processing for Check_Component
1159 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1160 -- object constraint, then the component type shall be an Unchecked_
1163 if Nkind (Sindic) = N_Subtype_Indication
1164 and then Has_Per_Object_Constraint (Comp_Id)
1165 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1168 ("component subtype subject to per-object constraint " &
1169 "must be an Unchecked_Union", Comp);
1171 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1172 -- the body of a generic unit, or within the body of any of its
1173 -- descendant library units, no part of the type of a component
1174 -- declared in a variant_part of the unchecked union type shall be of
1175 -- a formal private type or formal private extension declared within
1176 -- the formal part of the generic unit.
1178 elsif Ada_Version >= Ada_2012
1179 and then Inside_Generic_Body (UU_Typ)
1180 and then In_Variant_Part
1181 and then Is_Private_Type (Typ)
1182 and then Is_Generic_Type (Typ)
1185 ("component of Unchecked_Union cannot be of generic type", Comp);
1187 elsif Needs_Finalization (Typ) then
1189 ("component of Unchecked_Union cannot be controlled", Comp);
1191 elsif Has_Task (Typ) then
1193 ("component of Unchecked_Union cannot have tasks", Comp);
1195 end Check_Component;
1197 ----------------------------------
1198 -- Check_Duplicated_Export_Name --
1199 ----------------------------------
1201 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1202 String_Val : constant String_Id := Strval (Nam);
1205 -- We are only interested in the export case, and in the case of
1206 -- generics, it is the instance, not the template, that is the
1207 -- problem (the template will generate a warning in any case).
1209 if not Inside_A_Generic
1210 and then (Prag_Id = Pragma_Export
1212 Prag_Id = Pragma_Export_Procedure
1214 Prag_Id = Pragma_Export_Valued_Procedure
1216 Prag_Id = Pragma_Export_Function)
1218 for J in Externals.First .. Externals.Last loop
1219 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1220 Error_Msg_Sloc := Sloc (Externals.Table (J));
1221 Error_Msg_N ("external name duplicates name given#", Nam);
1226 Externals.Append (Nam);
1228 end Check_Duplicated_Export_Name;
1230 -------------------------
1231 -- Check_First_Subtype --
1232 -------------------------
1234 procedure Check_First_Subtype (Arg : Node_Id) is
1235 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1237 if not Is_First_Subtype (Entity (Argx)) then
1239 ("pragma% cannot apply to subtype", Argx);
1241 end Check_First_Subtype;
1243 ---------------------------
1244 -- Check_In_Main_Program --
1245 ---------------------------
1247 procedure Check_In_Main_Program is
1248 P : constant Node_Id := Parent (N);
1251 -- Must be at in subprogram body
1253 if Nkind (P) /= N_Subprogram_Body then
1254 Error_Pragma ("% pragma allowed only in subprogram");
1256 -- Otherwise warn if obviously not main program
1258 elsif Present (Parameter_Specifications (Specification (P)))
1259 or else not Is_Compilation_Unit (Defining_Entity (P))
1261 Error_Msg_Name_1 := Pname;
1263 ("?pragma% is only effective in main program", N);
1265 end Check_In_Main_Program;
1267 ---------------------------------------
1268 -- Check_Interrupt_Or_Attach_Handler --
1269 ---------------------------------------
1271 procedure Check_Interrupt_Or_Attach_Handler is
1272 Arg1_X : constant Node_Id := Expression (Arg1);
1273 Handler_Proc, Proc_Scope : Entity_Id;
1278 if Prag_Id = Pragma_Interrupt_Handler then
1279 Check_Restriction (No_Dynamic_Attachment, N);
1282 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1283 Proc_Scope := Scope (Handler_Proc);
1285 -- On AAMP only, a pragma Interrupt_Handler is supported for
1286 -- nonprotected parameterless procedures.
1288 if not AAMP_On_Target
1289 or else Prag_Id = Pragma_Attach_Handler
1291 if Ekind (Proc_Scope) /= E_Protected_Type then
1293 ("argument of pragma% must be protected procedure", Arg1);
1296 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1297 Error_Pragma ("pragma% must be in protected definition");
1301 if not Is_Library_Level_Entity (Proc_Scope)
1302 or else (AAMP_On_Target
1303 and then not Is_Library_Level_Entity (Handler_Proc))
1306 ("argument for pragma% must be library level entity", Arg1);
1308 end Check_Interrupt_Or_Attach_Handler;
1310 -------------------------------------------
1311 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1312 -------------------------------------------
1314 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1323 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1326 elsif Nkind_In (P, N_Package_Specification,
1331 -- Note: the following tests seem a little peculiar, because
1332 -- they test for bodies, but if we were in the statement part
1333 -- of the body, we would already have hit the handled statement
1334 -- sequence, so the only way we get here is by being in the
1335 -- declarative part of the body.
1337 elsif Nkind_In (P, N_Subprogram_Body,
1348 Error_Pragma ("pragma% is not in declarative part or package spec");
1349 end Check_Is_In_Decl_Part_Or_Package_Spec;
1351 -------------------------
1352 -- Check_No_Identifier --
1353 -------------------------
1355 procedure Check_No_Identifier (Arg : Node_Id) is
1357 if Chars (Arg) /= No_Name then
1358 Error_Pragma_Arg_Ident
1359 ("pragma% does not permit identifier& here", Arg);
1361 end Check_No_Identifier;
1363 --------------------------
1364 -- Check_No_Identifiers --
1365 --------------------------
1367 procedure Check_No_Identifiers is
1370 if Arg_Count > 0 then
1372 while Present (Arg_Node) loop
1373 Check_No_Identifier (Arg_Node);
1377 end Check_No_Identifiers;
1379 -------------------------------
1380 -- Check_Optional_Identifier --
1381 -------------------------------
1383 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1385 if Present (Arg) and then Chars (Arg) /= No_Name then
1386 if Chars (Arg) /= Id then
1387 Error_Msg_Name_1 := Pname;
1388 Error_Msg_Name_2 := Id;
1389 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1393 end Check_Optional_Identifier;
1395 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1397 Name_Buffer (1 .. Id'Length) := Id;
1398 Name_Len := Id'Length;
1399 Check_Optional_Identifier (Arg, Name_Find);
1400 end Check_Optional_Identifier;
1402 --------------------------------------
1403 -- Check_Precondition_Postcondition --
1404 --------------------------------------
1406 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1410 procedure Chain_PPC (PO : Node_Id);
1411 -- If PO is a subprogram declaration node (or a generic subprogram
1412 -- declaration node), then the precondition/postcondition applies
1413 -- to this subprogram and the processing for the pragma is completed.
1414 -- Otherwise the pragma is misplaced.
1420 procedure Chain_PPC (PO : Node_Id) is
1424 if not Nkind_In (PO, N_Subprogram_Declaration,
1425 N_Generic_Subprogram_Declaration)
1430 -- Here if we have subprogram or generic subprogram declaration
1432 S := Defining_Unit_Name (Specification (PO));
1434 -- Analyze the pragma unless it appears within a package spec,
1435 -- which is the case where we delay the analysis of the PPC until
1436 -- the end of the package declarations (for details, see
1437 -- Analyze_Package_Specification.Analyze_PPCs).
1439 if not Is_Package_Or_Generic_Package (Scope (S)) then
1440 Analyze_PPC_In_Decl_Part (N, S);
1443 -- Chain spec PPC pragma to list for subprogram
1445 Set_Next_Pragma (N, Spec_PPC_List (S));
1446 Set_Spec_PPC_List (S, N);
1448 -- Return indicating spec case
1454 -- Start of processing for Check_Precondition_Postcondition
1457 if not Is_List_Member (N) then
1461 -- Record if pragma is enabled
1463 if Check_Enabled (Pname) then
1464 Set_Pragma_Enabled (N);
1465 Set_SCO_Pragma_Enabled (Loc);
1468 -- If we are within an inlined body, the legality of the pragma
1469 -- has been checked already.
1471 if In_Inlined_Body then
1476 -- Search prior declarations
1479 while Present (Prev (P)) loop
1482 -- If the previous node is a generic subprogram, do not go to to
1483 -- the original node, which is the unanalyzed tree: we need to
1484 -- attach the pre/postconditions to the analyzed version at this
1485 -- point. They get propagated to the original tree when analyzing
1486 -- the corresponding body.
1488 if Nkind (P) not in N_Generic_Declaration then
1489 PO := Original_Node (P);
1494 -- Skip past prior pragma
1496 if Nkind (PO) = N_Pragma then
1499 -- Skip stuff not coming from source
1501 elsif not Comes_From_Source (PO) then
1504 -- Only remaining possibility is subprogram declaration
1512 -- If we fall through loop, pragma is at start of list, so see if it
1513 -- is at the start of declarations of a subprogram body.
1515 if Nkind (Parent (N)) = N_Subprogram_Body
1516 and then List_Containing (N) = Declarations (Parent (N))
1518 if Operating_Mode /= Generate_Code
1519 or else Inside_A_Generic
1522 -- Analyze expression in pragma, for correctness
1523 -- and for ASIS use.
1525 Preanalyze_Spec_Expression
1526 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1532 -- See if it is in the pragmas after a library level subprogram
1534 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1535 Chain_PPC (Unit (Parent (Parent (N))));
1539 -- If we fall through, pragma was misplaced
1542 end Check_Precondition_Postcondition;
1544 -----------------------------
1545 -- Check_Static_Constraint --
1546 -----------------------------
1548 -- Note: for convenience in writing this procedure, in addition to
1549 -- the officially (i.e. by spec) allowed argument which is always a
1550 -- constraint, it also allows ranges and discriminant associations.
1551 -- Above is not clear ???
1553 procedure Check_Static_Constraint (Constr : Node_Id) is
1555 procedure Require_Static (E : Node_Id);
1556 -- Require given expression to be static expression
1558 --------------------
1559 -- Require_Static --
1560 --------------------
1562 procedure Require_Static (E : Node_Id) is
1564 if not Is_OK_Static_Expression (E) then
1565 Flag_Non_Static_Expr
1566 ("non-static constraint not allowed in Unchecked_Union!", E);
1571 -- Start of processing for Check_Static_Constraint
1574 case Nkind (Constr) is
1575 when N_Discriminant_Association =>
1576 Require_Static (Expression (Constr));
1579 Require_Static (Low_Bound (Constr));
1580 Require_Static (High_Bound (Constr));
1582 when N_Attribute_Reference =>
1583 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1584 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1586 when N_Range_Constraint =>
1587 Check_Static_Constraint (Range_Expression (Constr));
1589 when N_Index_Or_Discriminant_Constraint =>
1593 IDC := First (Constraints (Constr));
1594 while Present (IDC) loop
1595 Check_Static_Constraint (IDC);
1603 end Check_Static_Constraint;
1605 --------------------------------------
1606 -- Check_Valid_Configuration_Pragma --
1607 --------------------------------------
1609 -- A configuration pragma must appear in the context clause of a
1610 -- compilation unit, and only other pragmas may precede it. Note that
1611 -- the test also allows use in a configuration pragma file.
1613 procedure Check_Valid_Configuration_Pragma is
1615 if not Is_Configuration_Pragma then
1616 Error_Pragma ("incorrect placement for configuration pragma%");
1618 end Check_Valid_Configuration_Pragma;
1620 -------------------------------------
1621 -- Check_Valid_Library_Unit_Pragma --
1622 -------------------------------------
1624 procedure Check_Valid_Library_Unit_Pragma is
1626 Parent_Node : Node_Id;
1627 Unit_Name : Entity_Id;
1628 Unit_Kind : Node_Kind;
1629 Unit_Node : Node_Id;
1630 Sindex : Source_File_Index;
1633 if not Is_List_Member (N) then
1637 Plist := List_Containing (N);
1638 Parent_Node := Parent (Plist);
1640 if Parent_Node = Empty then
1643 -- Case of pragma appearing after a compilation unit. In this case
1644 -- it must have an argument with the corresponding name and must
1645 -- be part of the following pragmas of its parent.
1647 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1648 if Plist /= Pragmas_After (Parent_Node) then
1651 elsif Arg_Count = 0 then
1653 ("argument required if outside compilation unit");
1656 Check_No_Identifiers;
1657 Check_Arg_Count (1);
1658 Unit_Node := Unit (Parent (Parent_Node));
1659 Unit_Kind := Nkind (Unit_Node);
1661 Analyze (Expression (Arg1));
1663 if Unit_Kind = N_Generic_Subprogram_Declaration
1664 or else Unit_Kind = N_Subprogram_Declaration
1666 Unit_Name := Defining_Entity (Unit_Node);
1668 elsif Unit_Kind in N_Generic_Instantiation then
1669 Unit_Name := Defining_Entity (Unit_Node);
1672 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1675 if Chars (Unit_Name) /=
1676 Chars (Entity (Expression (Arg1)))
1679 ("pragma% argument is not current unit name", Arg1);
1682 if Ekind (Unit_Name) = E_Package
1683 and then Present (Renamed_Entity (Unit_Name))
1685 Error_Pragma ("pragma% not allowed for renamed package");
1689 -- Pragma appears other than after a compilation unit
1692 -- Here we check for the generic instantiation case and also
1693 -- for the case of processing a generic formal package. We
1694 -- detect these cases by noting that the Sloc on the node
1695 -- does not belong to the current compilation unit.
1697 Sindex := Source_Index (Current_Sem_Unit);
1699 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1700 Rewrite (N, Make_Null_Statement (Loc));
1703 -- If before first declaration, the pragma applies to the
1704 -- enclosing unit, and the name if present must be this name.
1706 elsif Is_Before_First_Decl (N, Plist) then
1707 Unit_Node := Unit_Declaration_Node (Current_Scope);
1708 Unit_Kind := Nkind (Unit_Node);
1710 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1713 elsif Unit_Kind = N_Subprogram_Body
1714 and then not Acts_As_Spec (Unit_Node)
1718 elsif Nkind (Parent_Node) = N_Package_Body then
1721 elsif Nkind (Parent_Node) = N_Package_Specification
1722 and then Plist = Private_Declarations (Parent_Node)
1726 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1727 or else Nkind (Parent_Node) =
1728 N_Generic_Subprogram_Declaration)
1729 and then Plist = Generic_Formal_Declarations (Parent_Node)
1733 elsif Arg_Count > 0 then
1734 Analyze (Expression (Arg1));
1736 if Entity (Expression (Arg1)) /= Current_Scope then
1738 ("name in pragma% must be enclosing unit", Arg1);
1741 -- It is legal to have no argument in this context
1747 -- Error if not before first declaration. This is because a
1748 -- library unit pragma argument must be the name of a library
1749 -- unit (RM 10.1.5(7)), but the only names permitted in this
1750 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1751 -- generic subprogram declarations or generic instantiations.
1755 ("pragma% misplaced, must be before first declaration");
1759 end Check_Valid_Library_Unit_Pragma;
1765 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1766 Clist : constant Node_Id := Component_List (Variant);
1770 if not Is_Non_Empty_List (Component_Items (Clist)) then
1772 ("Unchecked_Union may not have empty component list",
1777 Comp := First (Component_Items (Clist));
1778 while Present (Comp) loop
1779 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
1788 procedure Error_Pragma (Msg : String) is
1790 Error_Msg_Name_1 := Pname;
1791 Error_Msg_N (Msg, N);
1795 ----------------------
1796 -- Error_Pragma_Arg --
1797 ----------------------
1799 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1801 Error_Msg_Name_1 := Pname;
1802 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1804 end Error_Pragma_Arg;
1806 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1808 Error_Msg_Name_1 := Pname;
1809 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1810 Error_Pragma_Arg (Msg2, Arg);
1811 end Error_Pragma_Arg;
1813 ----------------------------
1814 -- Error_Pragma_Arg_Ident --
1815 ----------------------------
1817 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1819 Error_Msg_Name_1 := Pname;
1820 Error_Msg_N (Msg, Arg);
1822 end Error_Pragma_Arg_Ident;
1824 ----------------------
1825 -- Error_Pragma_Ref --
1826 ----------------------
1828 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1830 Error_Msg_Name_1 := Pname;
1831 Error_Msg_Sloc := Sloc (Ref);
1832 Error_Msg_NE (Msg, N, Ref);
1834 end Error_Pragma_Ref;
1836 ------------------------
1837 -- Find_Lib_Unit_Name --
1838 ------------------------
1840 function Find_Lib_Unit_Name return Entity_Id is
1842 -- Return inner compilation unit entity, for case of nested
1843 -- categorization pragmas. This happens in generic unit.
1845 if Nkind (Parent (N)) = N_Package_Specification
1846 and then Defining_Entity (Parent (N)) /= Current_Scope
1848 return Defining_Entity (Parent (N));
1850 return Current_Scope;
1852 end Find_Lib_Unit_Name;
1854 ----------------------------
1855 -- Find_Program_Unit_Name --
1856 ----------------------------
1858 procedure Find_Program_Unit_Name (Id : Node_Id) is
1859 Unit_Name : Entity_Id;
1860 Unit_Kind : Node_Kind;
1861 P : constant Node_Id := Parent (N);
1864 if Nkind (P) = N_Compilation_Unit then
1865 Unit_Kind := Nkind (Unit (P));
1867 if Unit_Kind = N_Subprogram_Declaration
1868 or else Unit_Kind = N_Package_Declaration
1869 or else Unit_Kind in N_Generic_Declaration
1871 Unit_Name := Defining_Entity (Unit (P));
1873 if Chars (Id) = Chars (Unit_Name) then
1874 Set_Entity (Id, Unit_Name);
1875 Set_Etype (Id, Etype (Unit_Name));
1877 Set_Etype (Id, Any_Type);
1879 ("cannot find program unit referenced by pragma%");
1883 Set_Etype (Id, Any_Type);
1884 Error_Pragma ("pragma% inapplicable to this unit");
1890 end Find_Program_Unit_Name;
1892 -----------------------------------------
1893 -- Find_Unique_Parameterless_Procedure --
1894 -----------------------------------------
1896 function Find_Unique_Parameterless_Procedure
1898 Arg : Node_Id) return Entity_Id
1900 Proc : Entity_Id := Empty;
1903 -- The body of this procedure needs some comments ???
1905 if not Is_Entity_Name (Name) then
1907 ("argument of pragma% must be entity name", Arg);
1909 elsif not Is_Overloaded (Name) then
1910 Proc := Entity (Name);
1912 if Ekind (Proc) /= E_Procedure
1913 or else Present (First_Formal (Proc))
1916 ("argument of pragma% must be parameterless procedure", Arg);
1921 Found : Boolean := False;
1923 Index : Interp_Index;
1926 Get_First_Interp (Name, Index, It);
1927 while Present (It.Nam) loop
1930 if Ekind (Proc) = E_Procedure
1931 and then No (First_Formal (Proc))
1935 Set_Entity (Name, Proc);
1936 Set_Is_Overloaded (Name, False);
1939 ("ambiguous handler name for pragma% ", Arg);
1943 Get_Next_Interp (Index, It);
1948 ("argument of pragma% must be parameterless procedure",
1951 Proc := Entity (Name);
1957 end Find_Unique_Parameterless_Procedure;
1959 -------------------------
1960 -- Gather_Associations --
1961 -------------------------
1963 procedure Gather_Associations
1965 Args : out Args_List)
1970 -- Initialize all parameters to Empty
1972 for J in Args'Range loop
1976 -- That's all we have to do if there are no argument associations
1978 if No (Pragma_Argument_Associations (N)) then
1982 -- Otherwise first deal with any positional parameters present
1984 Arg := First (Pragma_Argument_Associations (N));
1985 for Index in Args'Range loop
1986 exit when No (Arg) or else Chars (Arg) /= No_Name;
1987 Args (Index) := Expression (Arg);
1991 -- Positional parameters all processed, if any left, then we
1992 -- have too many positional parameters.
1994 if Present (Arg) and then Chars (Arg) = No_Name then
1996 ("too many positional associations for pragma%", Arg);
1999 -- Process named parameters if any are present
2001 while Present (Arg) loop
2002 if Chars (Arg) = No_Name then
2004 ("positional association cannot follow named association",
2008 for Index in Names'Range loop
2009 if Names (Index) = Chars (Arg) then
2010 if Present (Args (Index)) then
2012 ("duplicate argument association for pragma%", Arg);
2014 Args (Index) := Expression (Arg);
2019 if Index = Names'Last then
2020 Error_Msg_Name_1 := Pname;
2021 Error_Msg_N ("pragma% does not allow & argument", Arg);
2023 -- Check for possible misspelling
2025 for Index1 in Names'Range loop
2026 if Is_Bad_Spelling_Of
2027 (Chars (Arg), Names (Index1))
2029 Error_Msg_Name_1 := Names (Index1);
2030 Error_Msg_N -- CODEFIX
2031 ("\possible misspelling of%", Arg);
2043 end Gather_Associations;
2049 procedure GNAT_Pragma is
2051 Check_Restriction (No_Implementation_Pragmas, N);
2054 --------------------------
2055 -- Is_Before_First_Decl --
2056 --------------------------
2058 function Is_Before_First_Decl
2059 (Pragma_Node : Node_Id;
2060 Decls : List_Id) return Boolean
2062 Item : Node_Id := First (Decls);
2065 -- Only other pragmas can come before this pragma
2068 if No (Item) or else Nkind (Item) /= N_Pragma then
2071 elsif Item = Pragma_Node then
2077 end Is_Before_First_Decl;
2079 -----------------------------
2080 -- Is_Configuration_Pragma --
2081 -----------------------------
2083 -- A configuration pragma must appear in the context clause of a
2084 -- compilation unit, and only other pragmas may precede it. Note that
2085 -- the test below also permits use in a configuration pragma file.
2087 function Is_Configuration_Pragma return Boolean is
2088 Lis : constant List_Id := List_Containing (N);
2089 Par : constant Node_Id := Parent (N);
2093 -- If no parent, then we are in the configuration pragma file,
2094 -- so the placement is definitely appropriate.
2099 -- Otherwise we must be in the context clause of a compilation unit
2100 -- and the only thing allowed before us in the context list is more
2101 -- configuration pragmas.
2103 elsif Nkind (Par) = N_Compilation_Unit
2104 and then Context_Items (Par) = Lis
2111 elsif Nkind (Prg) /= N_Pragma then
2121 end Is_Configuration_Pragma;
2123 --------------------------
2124 -- Is_In_Context_Clause --
2125 --------------------------
2127 function Is_In_Context_Clause return Boolean is
2129 Parent_Node : Node_Id;
2132 if not Is_List_Member (N) then
2136 Plist := List_Containing (N);
2137 Parent_Node := Parent (Plist);
2139 if Parent_Node = Empty
2140 or else Nkind (Parent_Node) /= N_Compilation_Unit
2141 or else Context_Items (Parent_Node) /= Plist
2148 end Is_In_Context_Clause;
2150 ---------------------------------
2151 -- Is_Static_String_Expression --
2152 ---------------------------------
2154 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2155 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2158 Analyze_And_Resolve (Argx);
2159 return Is_OK_Static_Expression (Argx)
2160 and then Nkind (Argx) = N_String_Literal;
2161 end Is_Static_String_Expression;
2163 ----------------------
2164 -- Pragma_Misplaced --
2165 ----------------------
2167 procedure Pragma_Misplaced is
2169 Error_Pragma ("incorrect placement of pragma%");
2170 end Pragma_Misplaced;
2172 ------------------------------------
2173 -- Process Atomic_Shared_Volatile --
2174 ------------------------------------
2176 procedure Process_Atomic_Shared_Volatile is
2183 procedure Set_Atomic (E : Entity_Id);
2184 -- Set given type as atomic, and if no explicit alignment was given,
2185 -- set alignment to unknown, since back end knows what the alignment
2186 -- requirements are for atomic arrays. Note: this step is necessary
2187 -- for derived types.
2193 procedure Set_Atomic (E : Entity_Id) is
2197 if not Has_Alignment_Clause (E) then
2198 Set_Alignment (E, Uint_0);
2202 -- Start of processing for Process_Atomic_Shared_Volatile
2205 Check_Ada_83_Warning;
2206 Check_No_Identifiers;
2207 Check_Arg_Count (1);
2208 Check_Arg_Is_Local_Name (Arg1);
2209 E_Id := Expression (Arg1);
2211 if Etype (E_Id) = Any_Type then
2216 D := Declaration_Node (E);
2220 if Rep_Item_Too_Early (E, N)
2222 Rep_Item_Too_Late (E, N)
2226 Check_First_Subtype (Arg1);
2229 if Prag_Id /= Pragma_Volatile then
2231 Set_Atomic (Underlying_Type (E));
2232 Set_Atomic (Base_Type (E));
2235 -- Attribute belongs on the base type. If the view of the type is
2236 -- currently private, it also belongs on the underlying type.
2238 Set_Is_Volatile (Base_Type (E));
2239 Set_Is_Volatile (Underlying_Type (E));
2241 Set_Treat_As_Volatile (E);
2242 Set_Treat_As_Volatile (Underlying_Type (E));
2244 elsif K = N_Object_Declaration
2245 or else (K = N_Component_Declaration
2246 and then Original_Record_Component (E) = E)
2248 if Rep_Item_Too_Late (E, N) then
2252 if Prag_Id /= Pragma_Volatile then
2255 -- If the object declaration has an explicit initialization, a
2256 -- temporary may have to be created to hold the expression, to
2257 -- ensure that access to the object remain atomic.
2259 if Nkind (Parent (E)) = N_Object_Declaration
2260 and then Present (Expression (Parent (E)))
2262 Set_Has_Delayed_Freeze (E);
2265 -- An interesting improvement here. If an object of type X is
2266 -- declared atomic, and the type X is not atomic, that's a
2267 -- pity, since it may not have appropriate alignment etc. We
2268 -- can rescue this in the special case where the object and
2269 -- type are in the same unit by just setting the type as
2270 -- atomic, so that the back end will process it as atomic.
2272 Utyp := Underlying_Type (Etype (E));
2275 and then Sloc (E) > No_Location
2276 and then Sloc (Utyp) > No_Location
2278 Get_Source_File_Index (Sloc (E)) =
2279 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2281 Set_Is_Atomic (Underlying_Type (Etype (E)));
2285 Set_Is_Volatile (E);
2286 Set_Treat_As_Volatile (E);
2290 ("inappropriate entity for pragma%", Arg1);
2292 end Process_Atomic_Shared_Volatile;
2294 -------------------------------------------
2295 -- Process_Compile_Time_Warning_Or_Error --
2296 -------------------------------------------
2298 procedure Process_Compile_Time_Warning_Or_Error is
2299 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2302 Check_Arg_Count (2);
2303 Check_No_Identifiers;
2304 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2305 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2307 if Compile_Time_Known_Value (Arg1x) then
2308 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2310 Str : constant String_Id :=
2311 Strval (Get_Pragma_Arg (Arg2));
2312 Len : constant Int := String_Length (Str);
2317 Cent : constant Entity_Id :=
2318 Cunit_Entity (Current_Sem_Unit);
2320 Force : constant Boolean :=
2321 Prag_Id = Pragma_Compile_Time_Warning
2323 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2324 and then (Ekind (Cent) /= E_Package
2325 or else not In_Private_Part (Cent));
2326 -- Set True if this is the warning case, and we are in the
2327 -- visible part of a package spec, or in a subprogram spec,
2328 -- in which case we want to force the client to see the
2329 -- warning, even though it is not in the main unit.
2332 -- Loop through segments of message separated by line feeds.
2333 -- We output these segments as separate messages with
2334 -- continuation marks for all but the first.
2339 Error_Msg_Strlen := 0;
2341 -- Loop to copy characters from argument to error message
2345 exit when Ptr > Len;
2346 CC := Get_String_Char (Str, Ptr);
2349 -- Ignore wide chars ??? else store character
2351 if In_Character_Range (CC) then
2352 C := Get_Character (CC);
2353 exit when C = ASCII.LF;
2354 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2355 Error_Msg_String (Error_Msg_Strlen) := C;
2359 -- Here with one line ready to go
2361 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2363 -- If this is a warning in a spec, then we want clients
2364 -- to see the warning, so mark the message with the
2365 -- special sequence !! to force the warning. In the case
2366 -- of a package spec, we do not force this if we are in
2367 -- the private part of the spec.
2370 if Cont = False then
2371 Error_Msg_N ("<~!!", Arg1);
2374 Error_Msg_N ("\<~!!", Arg1);
2377 -- Error, rather than warning, or in a body, so we do not
2378 -- need to force visibility for client (error will be
2379 -- output in any case, and this is the situation in which
2380 -- we do not want a client to get a warning, since the
2381 -- warning is in the body or the spec private part.
2384 if Cont = False then
2385 Error_Msg_N ("<~", Arg1);
2388 Error_Msg_N ("\<~", Arg1);
2392 exit when Ptr > Len;
2397 end Process_Compile_Time_Warning_Or_Error;
2399 ------------------------
2400 -- Process_Convention --
2401 ------------------------
2403 procedure Process_Convention
2404 (C : out Convention_Id;
2405 Ent : out Entity_Id)
2411 Comp_Unit : Unit_Number_Type;
2413 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2414 -- Called if we have more than one Export/Import/Convention pragma.
2415 -- This is generally illegal, but we have a special case of allowing
2416 -- Import and Interface to coexist if they specify the convention in
2417 -- a consistent manner. We are allowed to do this, since Interface is
2418 -- an implementation defined pragma, and we choose to do it since we
2419 -- know Rational allows this combination. S is the entity id of the
2420 -- subprogram in question. This procedure also sets the special flag
2421 -- Import_Interface_Present in both pragmas in the case where we do
2422 -- have matching Import and Interface pragmas.
2424 procedure Set_Convention_From_Pragma (E : Entity_Id);
2425 -- Set convention in entity E, and also flag that the entity has a
2426 -- convention pragma. If entity is for a private or incomplete type,
2427 -- also set convention and flag on underlying type. This procedure
2428 -- also deals with the special case of C_Pass_By_Copy convention.
2430 -------------------------------
2431 -- Diagnose_Multiple_Pragmas --
2432 -------------------------------
2434 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2435 Pdec : constant Node_Id := Declaration_Node (S);
2439 function Same_Convention (Decl : Node_Id) return Boolean;
2440 -- Decl is a pragma node. This function returns True if this
2441 -- pragma has a first argument that is an identifier with a
2442 -- Chars field corresponding to the Convention_Id C.
2444 function Same_Name (Decl : Node_Id) return Boolean;
2445 -- Decl is a pragma node. This function returns True if this
2446 -- pragma has a second argument that is an identifier with a
2447 -- Chars field that matches the Chars of the current subprogram.
2449 ---------------------
2450 -- Same_Convention --
2451 ---------------------
2453 function Same_Convention (Decl : Node_Id) return Boolean is
2454 Arg1 : constant Node_Id :=
2455 First (Pragma_Argument_Associations (Decl));
2458 if Present (Arg1) then
2460 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2462 if Nkind (Arg) = N_Identifier
2463 and then Is_Convention_Name (Chars (Arg))
2464 and then Get_Convention_Id (Chars (Arg)) = C
2472 end Same_Convention;
2478 function Same_Name (Decl : Node_Id) return Boolean is
2479 Arg1 : constant Node_Id :=
2480 First (Pragma_Argument_Associations (Decl));
2488 Arg2 := Next (Arg1);
2495 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2497 if Nkind (Arg) = N_Identifier
2498 and then Chars (Arg) = Chars (S)
2507 -- Start of processing for Diagnose_Multiple_Pragmas
2512 -- Definitely give message if we have Convention/Export here
2514 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2517 -- If we have an Import or Export, scan back from pragma to
2518 -- find any previous pragma applying to the same procedure.
2519 -- The scan will be terminated by the start of the list, or
2520 -- hitting the subprogram declaration. This won't allow one
2521 -- pragma to appear in the public part and one in the private
2522 -- part, but that seems very unlikely in practice.
2526 while Present (Decl) and then Decl /= Pdec loop
2528 -- Look for pragma with same name as us
2530 if Nkind (Decl) = N_Pragma
2531 and then Same_Name (Decl)
2533 -- Give error if same as our pragma or Export/Convention
2535 if Pragma_Name (Decl) = Name_Export
2537 Pragma_Name (Decl) = Name_Convention
2539 Pragma_Name (Decl) = Pragma_Name (N)
2543 -- Case of Import/Interface or the other way round
2545 elsif Pragma_Name (Decl) = Name_Interface
2547 Pragma_Name (Decl) = Name_Import
2549 -- Here we know that we have Import and Interface. It
2550 -- doesn't matter which way round they are. See if
2551 -- they specify the same convention. If so, all OK,
2552 -- and set special flags to stop other messages
2554 if Same_Convention (Decl) then
2555 Set_Import_Interface_Present (N);
2556 Set_Import_Interface_Present (Decl);
2559 -- If different conventions, special message
2562 Error_Msg_Sloc := Sloc (Decl);
2564 ("convention differs from that given#", Arg1);
2574 -- Give message if needed if we fall through those tests
2578 ("at most one Convention/Export/Import pragma is allowed",
2581 end Diagnose_Multiple_Pragmas;
2583 --------------------------------
2584 -- Set_Convention_From_Pragma --
2585 --------------------------------
2587 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2589 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2590 -- for an overridden dispatching operation. Technically this is
2591 -- an amendment and should only be done in Ada 2005 mode. However,
2592 -- this is clearly a mistake, since the problem that is addressed
2593 -- by this AI is that there is a clear gap in the RM!
2595 if Is_Dispatching_Operation (E)
2596 and then Present (Overridden_Operation (E))
2597 and then C /= Convention (Overridden_Operation (E))
2600 ("cannot change convention for " &
2601 "overridden dispatching operation",
2605 -- Set the convention
2607 Set_Convention (E, C);
2608 Set_Has_Convention_Pragma (E);
2610 if Is_Incomplete_Or_Private_Type (E) then
2611 Set_Convention (Underlying_Type (E), C);
2612 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2615 -- A class-wide type should inherit the convention of the specific
2616 -- root type (although this isn't specified clearly by the RM).
2618 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2619 Set_Convention (Class_Wide_Type (E), C);
2622 -- If the entity is a record type, then check for special case of
2623 -- C_Pass_By_Copy, which is treated the same as C except that the
2624 -- special record flag is set. This convention is only permitted
2625 -- on record types (see AI95-00131).
2627 if Cname = Name_C_Pass_By_Copy then
2628 if Is_Record_Type (E) then
2629 Set_C_Pass_By_Copy (Base_Type (E));
2630 elsif Is_Incomplete_Or_Private_Type (E)
2631 and then Is_Record_Type (Underlying_Type (E))
2633 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2636 ("C_Pass_By_Copy convention allowed only for record type",
2641 -- If the entity is a derived boolean type, check for the special
2642 -- case of convention C, C++, or Fortran, where we consider any
2643 -- nonzero value to represent true.
2645 if Is_Discrete_Type (E)
2646 and then Root_Type (Etype (E)) = Standard_Boolean
2652 C = Convention_Fortran)
2654 Set_Nonzero_Is_True (Base_Type (E));
2656 end Set_Convention_From_Pragma;
2658 -- Start of processing for Process_Convention
2661 Check_At_Least_N_Arguments (2);
2662 Check_Optional_Identifier (Arg1, Name_Convention);
2663 Check_Arg_Is_Identifier (Arg1);
2664 Cname := Chars (Expression (Arg1));
2666 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2667 -- tested again below to set the critical flag).
2668 if Cname = Name_C_Pass_By_Copy then
2671 -- Otherwise we must have something in the standard convention list
2673 elsif Is_Convention_Name (Cname) then
2674 C := Get_Convention_Id (Chars (Expression (Arg1)));
2676 -- In DEC VMS, it seems that there is an undocumented feature that
2677 -- any unrecognized convention is treated as the default, which for
2678 -- us is convention C. It does not seem so terrible to do this
2679 -- unconditionally, silently in the VMS case, and with a warning
2680 -- in the non-VMS case.
2683 if Warn_On_Export_Import and not OpenVMS_On_Target then
2685 ("?unrecognized convention name, C assumed",
2692 Check_Optional_Identifier (Arg2, Name_Entity);
2693 Check_Arg_Is_Local_Name (Arg2);
2695 Id := Expression (Arg2);
2698 if not Is_Entity_Name (Id) then
2699 Error_Pragma_Arg ("entity name required", Arg2);
2704 -- Set entity to return
2708 -- Go to renamed subprogram if present, since convention applies to
2709 -- the actual renamed entity, not to the renaming entity. If the
2710 -- subprogram is inherited, go to parent subprogram.
2712 if Is_Subprogram (E)
2713 and then Present (Alias (E))
2715 if Nkind (Parent (Declaration_Node (E))) =
2716 N_Subprogram_Renaming_Declaration
2718 if Scope (E) /= Scope (Alias (E)) then
2720 ("cannot apply pragma% to non-local entity&#", E);
2725 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2726 N_Private_Extension_Declaration)
2727 and then Scope (E) = Scope (Alias (E))
2731 -- Return the parent subprogram the entity was inherited from
2737 -- Check that we are not applying this to a specless body
2739 if Is_Subprogram (E)
2740 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2743 ("pragma% requires separate spec and must come before body");
2746 -- Check that we are not applying this to a named constant
2748 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2749 Error_Msg_Name_1 := Pname;
2751 ("cannot apply pragma% to named constant!",
2752 Get_Pragma_Arg (Arg2));
2754 ("\supply appropriate type for&!", Arg2);
2757 if Ekind (E) = E_Enumeration_Literal then
2758 Error_Pragma ("enumeration literal not allowed for pragma%");
2761 -- Check for rep item appearing too early or too late
2763 if Etype (E) = Any_Type
2764 or else Rep_Item_Too_Early (E, N)
2768 E := Underlying_Type (E);
2771 if Rep_Item_Too_Late (E, N) then
2775 if Has_Convention_Pragma (E) then
2776 Diagnose_Multiple_Pragmas (E);
2778 elsif Convention (E) = Convention_Protected
2779 or else Ekind (Scope (E)) = E_Protected_Type
2782 ("a protected operation cannot be given a different convention",
2786 -- For Intrinsic, a subprogram is required
2788 if C = Convention_Intrinsic
2789 and then not Is_Subprogram (E)
2790 and then not Is_Generic_Subprogram (E)
2793 ("second argument of pragma% must be a subprogram", Arg2);
2796 -- For Stdcall, a subprogram, variable or subprogram type is required
2798 if C = Convention_Stdcall
2799 and then not Is_Subprogram (E)
2800 and then not Is_Generic_Subprogram (E)
2801 and then Ekind (E) /= E_Variable
2804 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2807 ("second argument of pragma% must be subprogram (type)",
2811 if not Is_Subprogram (E)
2812 and then not Is_Generic_Subprogram (E)
2814 Set_Convention_From_Pragma (E);
2817 Check_First_Subtype (Arg2);
2818 Set_Convention_From_Pragma (Base_Type (E));
2820 -- For subprograms, we must set the convention on the
2821 -- internally generated directly designated type as well.
2823 if Ekind (E) = E_Access_Subprogram_Type then
2824 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2828 -- For the subprogram case, set proper convention for all homonyms
2829 -- in same scope and the same declarative part, i.e. the same
2830 -- compilation unit.
2833 Comp_Unit := Get_Source_Unit (E);
2834 Set_Convention_From_Pragma (E);
2836 -- Treat a pragma Import as an implicit body, for GPS use
2838 if Prag_Id = Pragma_Import then
2839 Generate_Reference (E, Id, 'b');
2842 -- Loop through the homonyms of the pragma argument's entity
2847 exit when No (E1) or else Scope (E1) /= Current_Scope;
2849 -- Do not set the pragma on inherited operations or on formal
2852 if Comes_From_Source (E1)
2853 and then Comp_Unit = Get_Source_Unit (E1)
2854 and then not Is_Formal_Subprogram (E1)
2855 and then Nkind (Original_Node (Parent (E1))) /=
2856 N_Full_Type_Declaration
2858 if Present (Alias (E1))
2859 and then Scope (E1) /= Scope (Alias (E1))
2862 ("cannot apply pragma% to non-local entity& declared#",
2866 Set_Convention_From_Pragma (E1);
2868 if Prag_Id = Pragma_Import then
2869 Generate_Reference (E1, Id, 'b');
2874 end Process_Convention;
2876 -----------------------------------------------------
2877 -- Process_Extended_Import_Export_Exception_Pragma --
2878 -----------------------------------------------------
2880 procedure Process_Extended_Import_Export_Exception_Pragma
2881 (Arg_Internal : Node_Id;
2882 Arg_External : Node_Id;
2890 if not OpenVMS_On_Target then
2892 ("?pragma% ignored (applies only to Open'V'M'S)");
2895 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2896 Def_Id := Entity (Arg_Internal);
2898 if Ekind (Def_Id) /= E_Exception then
2900 ("pragma% must refer to declared exception", Arg_Internal);
2903 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2905 if Present (Arg_Form) then
2906 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2909 if Present (Arg_Form)
2910 and then Chars (Arg_Form) = Name_Ada
2914 Set_Is_VMS_Exception (Def_Id);
2915 Set_Exception_Code (Def_Id, No_Uint);
2918 if Present (Arg_Code) then
2919 if not Is_VMS_Exception (Def_Id) then
2921 ("Code option for pragma% not allowed for Ada case",
2925 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2926 Code_Val := Expr_Value (Arg_Code);
2928 if not UI_Is_In_Int_Range (Code_Val) then
2930 ("Code option for pragma% must be in 32-bit range",
2934 Set_Exception_Code (Def_Id, Code_Val);
2937 end Process_Extended_Import_Export_Exception_Pragma;
2939 -------------------------------------------------
2940 -- Process_Extended_Import_Export_Internal_Arg --
2941 -------------------------------------------------
2943 procedure Process_Extended_Import_Export_Internal_Arg
2944 (Arg_Internal : Node_Id := Empty)
2947 if No (Arg_Internal) then
2948 Error_Pragma ("Internal parameter required for pragma%");
2951 if Nkind (Arg_Internal) = N_Identifier then
2954 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2955 and then (Prag_Id = Pragma_Import_Function
2957 Prag_Id = Pragma_Export_Function)
2963 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2966 Check_Arg_Is_Local_Name (Arg_Internal);
2967 end Process_Extended_Import_Export_Internal_Arg;
2969 --------------------------------------------------
2970 -- Process_Extended_Import_Export_Object_Pragma --
2971 --------------------------------------------------
2973 procedure Process_Extended_Import_Export_Object_Pragma
2974 (Arg_Internal : Node_Id;
2975 Arg_External : Node_Id;
2981 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2982 Def_Id := Entity (Arg_Internal);
2984 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
2986 ("pragma% must designate an object", Arg_Internal);
2989 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2991 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2994 ("previous Common/Psect_Object applies, pragma % not permitted",
2998 if Rep_Item_Too_Late (Def_Id, N) then
3002 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3004 if Present (Arg_Size) then
3005 Check_Arg_Is_External_Name (Arg_Size);
3008 -- Export_Object case
3010 if Prag_Id = Pragma_Export_Object then
3011 if not Is_Library_Level_Entity (Def_Id) then
3013 ("argument for pragma% must be library level entity",
3017 if Ekind (Current_Scope) = E_Generic_Package then
3018 Error_Pragma ("pragma& cannot appear in a generic unit");
3021 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3023 ("exported object must have compile time known size",
3027 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3028 Error_Msg_N ("?duplicate Export_Object pragma", N);
3030 Set_Exported (Def_Id, Arg_Internal);
3033 -- Import_Object case
3036 if Is_Concurrent_Type (Etype (Def_Id)) then
3038 ("cannot use pragma% for task/protected object",
3042 if Ekind (Def_Id) = E_Constant then
3044 ("cannot import a constant", Arg_Internal);
3047 if Warn_On_Export_Import
3048 and then Has_Discriminants (Etype (Def_Id))
3051 ("imported value must be initialized?", Arg_Internal);
3054 if Warn_On_Export_Import
3055 and then Is_Access_Type (Etype (Def_Id))
3058 ("cannot import object of an access type?", Arg_Internal);
3061 if Warn_On_Export_Import
3062 and then Is_Imported (Def_Id)
3065 ("?duplicate Import_Object pragma", N);
3067 -- Check for explicit initialization present. Note that an
3068 -- initialization generated by the code generator, e.g. for an
3069 -- access type, does not count here.
3071 elsif Present (Expression (Parent (Def_Id)))
3074 (Original_Node (Expression (Parent (Def_Id))))
3076 Error_Msg_Sloc := Sloc (Def_Id);
3078 ("imported entities cannot be initialized (RM B.1(24))",
3079 "\no initialization allowed for & declared#", Arg1);
3081 Set_Imported (Def_Id);
3082 Note_Possible_Modification (Arg_Internal, Sure => False);
3085 end Process_Extended_Import_Export_Object_Pragma;
3087 ------------------------------------------------------
3088 -- Process_Extended_Import_Export_Subprogram_Pragma --
3089 ------------------------------------------------------
3091 procedure Process_Extended_Import_Export_Subprogram_Pragma
3092 (Arg_Internal : Node_Id;
3093 Arg_External : Node_Id;
3094 Arg_Parameter_Types : Node_Id;
3095 Arg_Result_Type : Node_Id := Empty;
3096 Arg_Mechanism : Node_Id;
3097 Arg_Result_Mechanism : Node_Id := Empty;
3098 Arg_First_Optional_Parameter : Node_Id := Empty)
3104 Ambiguous : Boolean;
3108 function Same_Base_Type
3110 Formal : Entity_Id) return Boolean;
3111 -- Determines if Ptype references the type of Formal. Note that only
3112 -- the base types need to match according to the spec. Ptype here is
3113 -- the argument from the pragma, which is either a type name, or an
3114 -- access attribute.
3116 --------------------
3117 -- Same_Base_Type --
3118 --------------------
3120 function Same_Base_Type
3122 Formal : Entity_Id) return Boolean
3124 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3128 -- Case where pragma argument is typ'Access
3130 if Nkind (Ptype) = N_Attribute_Reference
3131 and then Attribute_Name (Ptype) = Name_Access
3133 Pref := Prefix (Ptype);
3136 if not Is_Entity_Name (Pref)
3137 or else Entity (Pref) = Any_Type
3142 -- We have a match if the corresponding argument is of an
3143 -- anonymous access type, and its designated type matches the
3144 -- type of the prefix of the access attribute
3146 return Ekind (Ftyp) = E_Anonymous_Access_Type
3147 and then Base_Type (Entity (Pref)) =
3148 Base_Type (Etype (Designated_Type (Ftyp)));
3150 -- Case where pragma argument is a type name
3155 if not Is_Entity_Name (Ptype)
3156 or else Entity (Ptype) = Any_Type
3161 -- We have a match if the corresponding argument is of the type
3162 -- given in the pragma (comparing base types)
3164 return Base_Type (Entity (Ptype)) = Ftyp;
3168 -- Start of processing for
3169 -- Process_Extended_Import_Export_Subprogram_Pragma
3172 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3176 -- Loop through homonyms (overloadings) of the entity
3178 Hom_Id := Entity (Arg_Internal);
3179 while Present (Hom_Id) loop
3180 Def_Id := Get_Base_Subprogram (Hom_Id);
3182 -- We need a subprogram in the current scope
3184 if not Is_Subprogram (Def_Id)
3185 or else Scope (Def_Id) /= Current_Scope
3192 -- Pragma cannot apply to subprogram body
3194 if Is_Subprogram (Def_Id)
3195 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3199 ("pragma% requires separate spec"
3200 & " and must come before body");
3203 -- Test result type if given, note that the result type
3204 -- parameter can only be present for the function cases.
3206 if Present (Arg_Result_Type)
3207 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3211 elsif Etype (Def_Id) /= Standard_Void_Type
3213 (Pname = Name_Export_Procedure
3215 Pname = Name_Import_Procedure)
3219 -- Test parameter types if given. Note that this parameter
3220 -- has not been analyzed (and must not be, since it is
3221 -- semantic nonsense), so we get it as the parser left it.
3223 elsif Present (Arg_Parameter_Types) then
3224 Check_Matching_Types : declare
3229 Formal := First_Formal (Def_Id);
3231 if Nkind (Arg_Parameter_Types) = N_Null then
3232 if Present (Formal) then
3236 -- A list of one type, e.g. (List) is parsed as
3237 -- a parenthesized expression.
3239 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3240 and then Paren_Count (Arg_Parameter_Types) = 1
3243 or else Present (Next_Formal (Formal))
3248 Same_Base_Type (Arg_Parameter_Types, Formal);
3251 -- A list of more than one type is parsed as a aggregate
3253 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3254 and then Paren_Count (Arg_Parameter_Types) = 0
3256 Ptype := First (Expressions (Arg_Parameter_Types));
3257 while Present (Ptype) or else Present (Formal) loop
3260 or else not Same_Base_Type (Ptype, Formal)
3265 Next_Formal (Formal);
3270 -- Anything else is of the wrong form
3274 ("wrong form for Parameter_Types parameter",
3275 Arg_Parameter_Types);
3277 end Check_Matching_Types;
3280 -- Match is now False if the entry we found did not match
3281 -- either a supplied Parameter_Types or Result_Types argument
3287 -- Ambiguous case, the flag Ambiguous shows if we already
3288 -- detected this and output the initial messages.
3291 if not Ambiguous then
3293 Error_Msg_Name_1 := Pname;
3295 ("pragma% does not uniquely identify subprogram!",
3297 Error_Msg_Sloc := Sloc (Ent);
3298 Error_Msg_N ("matching subprogram #!", N);
3302 Error_Msg_Sloc := Sloc (Def_Id);
3303 Error_Msg_N ("matching subprogram #!", N);
3308 Hom_Id := Homonym (Hom_Id);
3311 -- See if we found an entry
3314 if not Ambiguous then
3315 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3317 ("pragma% cannot be given for generic subprogram");
3320 ("pragma% does not identify local subprogram");
3327 -- Import pragmas must be for imported entities
3329 if Prag_Id = Pragma_Import_Function
3331 Prag_Id = Pragma_Import_Procedure
3333 Prag_Id = Pragma_Import_Valued_Procedure
3335 if not Is_Imported (Ent) then
3337 ("pragma Import or Interface must precede pragma%");
3340 -- Here we have the Export case which can set the entity as exported
3342 -- But does not do so if the specified external name is null, since
3343 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3344 -- compatible) to request no external name.
3346 elsif Nkind (Arg_External) = N_String_Literal
3347 and then String_Length (Strval (Arg_External)) = 0
3351 -- In all other cases, set entity as exported
3354 Set_Exported (Ent, Arg_Internal);
3357 -- Special processing for Valued_Procedure cases
3359 if Prag_Id = Pragma_Import_Valued_Procedure
3361 Prag_Id = Pragma_Export_Valued_Procedure
3363 Formal := First_Formal (Ent);
3366 Error_Pragma ("at least one parameter required for pragma%");
3368 elsif Ekind (Formal) /= E_Out_Parameter then
3369 Error_Pragma ("first parameter must have mode out for pragma%");
3372 Set_Is_Valued_Procedure (Ent);
3376 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3378 -- Process Result_Mechanism argument if present. We have already
3379 -- checked that this is only allowed for the function case.
3381 if Present (Arg_Result_Mechanism) then
3382 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3385 -- Process Mechanism parameter if present. Note that this parameter
3386 -- is not analyzed, and must not be analyzed since it is semantic
3387 -- nonsense, so we get it in exactly as the parser left it.
3389 if Present (Arg_Mechanism) then
3397 -- A single mechanism association without a formal parameter
3398 -- name is parsed as a parenthesized expression. All other
3399 -- cases are parsed as aggregates, so we rewrite the single
3400 -- parameter case as an aggregate for consistency.
3402 if Nkind (Arg_Mechanism) /= N_Aggregate
3403 and then Paren_Count (Arg_Mechanism) = 1
3405 Rewrite (Arg_Mechanism,
3406 Make_Aggregate (Sloc (Arg_Mechanism),
3407 Expressions => New_List (
3408 Relocate_Node (Arg_Mechanism))));
3411 -- Case of only mechanism name given, applies to all formals
3413 if Nkind (Arg_Mechanism) /= N_Aggregate then
3414 Formal := First_Formal (Ent);
3415 while Present (Formal) loop
3416 Set_Mechanism_Value (Formal, Arg_Mechanism);
3417 Next_Formal (Formal);
3420 -- Case of list of mechanism associations given
3423 if Null_Record_Present (Arg_Mechanism) then
3425 ("inappropriate form for Mechanism parameter",
3429 -- Deal with positional ones first
3431 Formal := First_Formal (Ent);
3433 if Present (Expressions (Arg_Mechanism)) then
3434 Mname := First (Expressions (Arg_Mechanism));
3435 while Present (Mname) loop
3438 ("too many mechanism associations", Mname);
3441 Set_Mechanism_Value (Formal, Mname);
3442 Next_Formal (Formal);
3447 -- Deal with named entries
3449 if Present (Component_Associations (Arg_Mechanism)) then
3450 Massoc := First (Component_Associations (Arg_Mechanism));
3451 while Present (Massoc) loop
3452 Choice := First (Choices (Massoc));
3454 if Nkind (Choice) /= N_Identifier
3455 or else Present (Next (Choice))
3458 ("incorrect form for mechanism association",
3462 Formal := First_Formal (Ent);
3466 ("parameter name & not present", Choice);
3469 if Chars (Choice) = Chars (Formal) then
3471 (Formal, Expression (Massoc));
3473 -- Set entity on identifier for ASIS
3475 Set_Entity (Choice, Formal);
3480 Next_Formal (Formal);
3490 -- Process First_Optional_Parameter argument if present. We have
3491 -- already checked that this is only allowed for the Import case.
3493 if Present (Arg_First_Optional_Parameter) then
3494 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3496 ("first optional parameter must be formal parameter name",
3497 Arg_First_Optional_Parameter);
3500 Formal := First_Formal (Ent);
3504 ("specified formal parameter& not found",
3505 Arg_First_Optional_Parameter);
3508 exit when Chars (Formal) =
3509 Chars (Arg_First_Optional_Parameter);
3511 Next_Formal (Formal);
3514 Set_First_Optional_Parameter (Ent, Formal);
3516 -- Check specified and all remaining formals have right form
3518 while Present (Formal) loop
3519 if Ekind (Formal) /= E_In_Parameter then
3521 ("optional formal& is not of mode in!",
3522 Arg_First_Optional_Parameter, Formal);
3525 Dval := Default_Value (Formal);
3529 ("optional formal& does not have default value!",
3530 Arg_First_Optional_Parameter, Formal);
3532 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3537 ("default value for optional formal& is non-static!",
3538 Arg_First_Optional_Parameter, Formal);
3542 Set_Is_Optional_Parameter (Formal);
3543 Next_Formal (Formal);
3546 end Process_Extended_Import_Export_Subprogram_Pragma;
3548 --------------------------
3549 -- Process_Generic_List --
3550 --------------------------
3552 procedure Process_Generic_List is
3557 Check_No_Identifiers;
3558 Check_At_Least_N_Arguments (1);
3561 while Present (Arg) loop
3562 Exp := Expression (Arg);
3565 if not Is_Entity_Name (Exp)
3567 (not Is_Generic_Instance (Entity (Exp))
3569 not Is_Generic_Unit (Entity (Exp)))
3572 ("pragma% argument must be name of generic unit/instance",
3578 end Process_Generic_List;
3580 ---------------------------------
3581 -- Process_Import_Or_Interface --
3582 ---------------------------------
3584 procedure Process_Import_Or_Interface is
3590 Process_Convention (C, Def_Id);
3591 Kill_Size_Check_Code (Def_Id);
3592 Note_Possible_Modification (Expression (Arg2), Sure => False);
3594 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3596 -- We do not permit Import to apply to a renaming declaration
3598 if Present (Renamed_Object (Def_Id)) then
3600 ("pragma% not allowed for object renaming", Arg2);
3602 -- User initialization is not allowed for imported object, but
3603 -- the object declaration may contain a default initialization,
3604 -- that will be discarded. Note that an explicit initialization
3605 -- only counts if it comes from source, otherwise it is simply
3606 -- the code generator making an implicit initialization explicit.
3608 elsif Present (Expression (Parent (Def_Id)))
3609 and then Comes_From_Source (Expression (Parent (Def_Id)))
3611 Error_Msg_Sloc := Sloc (Def_Id);
3613 ("no initialization allowed for declaration of& #",
3614 "\imported entities cannot be initialized (RM B.1(24))",
3618 Set_Imported (Def_Id);
3619 Process_Interface_Name (Def_Id, Arg3, Arg4);
3621 -- Note that we do not set Is_Public here. That's because we
3622 -- only want to set it if there is no address clause, and we
3623 -- don't know that yet, so we delay that processing till
3626 -- pragma Import completes deferred constants
3628 if Ekind (Def_Id) = E_Constant then
3629 Set_Has_Completion (Def_Id);
3632 -- It is not possible to import a constant of an unconstrained
3633 -- array type (e.g. string) because there is no simple way to
3634 -- write a meaningful subtype for it.
3636 if Is_Array_Type (Etype (Def_Id))
3637 and then not Is_Constrained (Etype (Def_Id))
3640 ("imported constant& must have a constrained subtype",
3645 elsif Is_Subprogram (Def_Id)
3646 or else Is_Generic_Subprogram (Def_Id)
3648 -- If the name is overloaded, pragma applies to all of the
3649 -- denoted entities in the same declarative part.
3652 while Present (Hom_Id) loop
3653 Def_Id := Get_Base_Subprogram (Hom_Id);
3655 -- Ignore inherited subprograms because the pragma will
3656 -- apply to the parent operation, which is the one called.
3658 if Is_Overloadable (Def_Id)
3659 and then Present (Alias (Def_Id))
3663 -- If it is not a subprogram, it must be in an outer scope and
3664 -- pragma does not apply.
3666 elsif not Is_Subprogram (Def_Id)
3667 and then not Is_Generic_Subprogram (Def_Id)
3671 -- Verify that the homonym is in the same declarative part (not
3672 -- just the same scope).
3674 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3675 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3680 Set_Imported (Def_Id);
3682 -- Reject an Import applied to an abstract subprogram
3684 if Is_Subprogram (Def_Id)
3685 and then Is_Abstract_Subprogram (Def_Id)
3687 Error_Msg_Sloc := Sloc (Def_Id);
3689 ("cannot import abstract subprogram& declared#",
3693 -- Special processing for Convention_Intrinsic
3695 if C = Convention_Intrinsic then
3697 -- Link_Name argument not allowed for intrinsic
3700 and then Chars (Arg3) = Name_Link_Name
3705 if Present (Arg4) then
3707 ("Link_Name argument not allowed for " &
3712 Set_Is_Intrinsic_Subprogram (Def_Id);
3714 -- If no external name is present, then check that this
3715 -- is a valid intrinsic subprogram. If an external name
3716 -- is present, then this is handled by the back end.
3719 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3723 -- All interfaced procedures need an external symbol created
3724 -- for them since they are always referenced from another
3727 Set_Is_Public (Def_Id);
3729 -- Verify that the subprogram does not have a completion
3730 -- through a renaming declaration. For other completions the
3731 -- pragma appears as a too late representation.
3734 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3738 and then Nkind (Decl) = N_Subprogram_Declaration
3739 and then Present (Corresponding_Body (Decl))
3740 and then Nkind (Unit_Declaration_Node
3741 (Corresponding_Body (Decl))) =
3742 N_Subprogram_Renaming_Declaration
3744 Error_Msg_Sloc := Sloc (Def_Id);
3746 ("cannot import&, renaming already provided for " &
3747 "declaration #", N, Def_Id);
3751 Set_Has_Completion (Def_Id);
3752 Process_Interface_Name (Def_Id, Arg3, Arg4);
3755 if Is_Compilation_Unit (Hom_Id) then
3757 -- Its possible homonyms are not affected by the pragma.
3758 -- Such homonyms might be present in the context of other
3759 -- units being compiled.
3764 Hom_Id := Homonym (Hom_Id);
3768 -- When the convention is Java or CIL, we also allow Import to be
3769 -- given for packages, generic packages, exceptions, record
3770 -- components, and access to subprograms.
3772 elsif (C = Convention_Java or else C = Convention_CIL)
3774 (Is_Package_Or_Generic_Package (Def_Id)
3775 or else Ekind (Def_Id) = E_Exception
3776 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3777 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3779 Set_Imported (Def_Id);
3780 Set_Is_Public (Def_Id);
3781 Process_Interface_Name (Def_Id, Arg3, Arg4);
3783 -- Import a CPP class
3785 elsif Is_Record_Type (Def_Id)
3786 and then C = Convention_CPP
3788 -- Types treated as CPP classes are treated as limited, but we
3789 -- don't require them to be declared this way. A warning is
3790 -- issued to encourage the user to declare them as limited.
3791 -- This is not an error, for compatibility reasons, because
3792 -- these types have been supported this way for some time.
3794 if not Is_Limited_Type (Def_Id) then
3796 ("imported 'C'P'P type should be " &
3797 "explicitly declared limited?",
3798 Get_Pragma_Arg (Arg2));
3800 ("\type will be considered limited",
3801 Get_Pragma_Arg (Arg2));
3804 Set_Is_CPP_Class (Def_Id);
3805 Set_Is_Limited_Record (Def_Id);
3807 -- Imported CPP types must not have discriminants (because C++
3808 -- classes do not have discriminants).
3810 if Has_Discriminants (Def_Id) then
3812 ("imported 'C'P'P type cannot have discriminants",
3813 First (Discriminant_Specifications
3814 (Declaration_Node (Def_Id))));
3817 -- Components of imported CPP types must not have default
3818 -- expressions because the constructor (if any) is on the
3822 Tdef : constant Node_Id :=
3823 Type_Definition (Declaration_Node (Def_Id));
3828 if Nkind (Tdef) = N_Record_Definition then
3829 Clist := Component_List (Tdef);
3832 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3833 Clist := Component_List (Record_Extension_Part (Tdef));
3836 if Present (Clist) then
3837 Comp := First (Component_Items (Clist));
3838 while Present (Comp) loop
3839 if Present (Expression (Comp)) then
3841 ("component of imported 'C'P'P type cannot have" &
3842 " default expression", Expression (Comp));
3852 ("second argument of pragma% must be object or subprogram",
3856 -- If this pragma applies to a compilation unit, then the unit, which
3857 -- is a subprogram, does not require (or allow) a body. We also do
3858 -- not need to elaborate imported procedures.
3860 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3862 Cunit : constant Node_Id := Parent (Parent (N));
3864 Set_Body_Required (Cunit, False);
3867 end Process_Import_Or_Interface;
3869 --------------------
3870 -- Process_Inline --
3871 --------------------
3873 procedure Process_Inline (Active : Boolean) is
3879 Effective : Boolean := False;
3881 procedure Make_Inline (Subp : Entity_Id);
3882 -- Subp is the defining unit name of the subprogram declaration. Set
3883 -- the flag, as well as the flag in the corresponding body, if there
3886 procedure Set_Inline_Flags (Subp : Entity_Id);
3887 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3888 -- Has_Pragma_Inline_Always for the Inline_Always case.
3890 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3891 -- Returns True if it can be determined at this stage that inlining
3892 -- is not possible, for example if the body is available and contains
3893 -- exception handlers, we prevent inlining, since otherwise we can
3894 -- get undefined symbols at link time. This function also emits a
3895 -- warning if front-end inlining is enabled and the pragma appears
3898 -- ??? is business with link symbols still valid, or does it relate
3899 -- to front end ZCX which is being phased out ???
3901 ---------------------------
3902 -- Inlining_Not_Possible --
3903 ---------------------------
3905 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3906 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3910 if Nkind (Decl) = N_Subprogram_Body then
3911 Stats := Handled_Statement_Sequence (Decl);
3912 return Present (Exception_Handlers (Stats))
3913 or else Present (At_End_Proc (Stats));
3915 elsif Nkind (Decl) = N_Subprogram_Declaration
3916 and then Present (Corresponding_Body (Decl))
3918 if Front_End_Inlining
3919 and then Analyzed (Corresponding_Body (Decl))
3921 Error_Msg_N ("pragma appears too late, ignored?", N);
3924 -- If the subprogram is a renaming as body, the body is just a
3925 -- call to the renamed subprogram, and inlining is trivially
3929 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3930 N_Subprogram_Renaming_Declaration
3936 Handled_Statement_Sequence
3937 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3940 Present (Exception_Handlers (Stats))
3941 or else Present (At_End_Proc (Stats));
3945 -- If body is not available, assume the best, the check is
3946 -- performed again when compiling enclosing package bodies.
3950 end Inlining_Not_Possible;
3956 procedure Make_Inline (Subp : Entity_Id) is
3957 Kind : constant Entity_Kind := Ekind (Subp);
3958 Inner_Subp : Entity_Id := Subp;
3961 -- Ignore if bad type, avoid cascaded error
3963 if Etype (Subp) = Any_Type then
3967 -- Ignore if all inlining is suppressed
3969 elsif Suppress_All_Inlining then
3973 -- If inlining is not possible, for now do not treat as an error
3975 elsif Inlining_Not_Possible (Subp) then
3979 -- Here we have a candidate for inlining, but we must exclude
3980 -- derived operations. Otherwise we would end up trying to inline
3981 -- a phantom declaration, and the result would be to drag in a
3982 -- body which has no direct inlining associated with it. That
3983 -- would not only be inefficient but would also result in the
3984 -- backend doing cross-unit inlining in cases where it was
3985 -- definitely inappropriate to do so.
3987 -- However, a simple Comes_From_Source test is insufficient, since
3988 -- we do want to allow inlining of generic instances which also do
3989 -- not come from source. We also need to recognize specs generated
3990 -- by the front-end for bodies that carry the pragma. Finally,
3991 -- predefined operators do not come from source but are not
3992 -- inlineable either.
3994 elsif Is_Generic_Instance (Subp)
3995 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3999 elsif not Comes_From_Source (Subp)
4000 and then Scope (Subp) /= Standard_Standard
4006 -- The referenced entity must either be the enclosing entity, or
4007 -- an entity declared within the current open scope.
4009 if Present (Scope (Subp))
4010 and then Scope (Subp) /= Current_Scope
4011 and then Subp /= Current_Scope
4014 ("argument of% must be entity in current scope", Assoc);
4018 -- Processing for procedure, operator or function. If subprogram
4019 -- is aliased (as for an instance) indicate that the renamed
4020 -- entity (if declared in the same unit) is inlined.
4022 if Is_Subprogram (Subp) then
4023 Inner_Subp := Ultimate_Alias (Inner_Subp);
4025 if In_Same_Source_Unit (Subp, Inner_Subp) then
4026 Set_Inline_Flags (Inner_Subp);
4028 Decl := Parent (Parent (Inner_Subp));
4030 if Nkind (Decl) = N_Subprogram_Declaration
4031 and then Present (Corresponding_Body (Decl))
4033 Set_Inline_Flags (Corresponding_Body (Decl));
4035 elsif Is_Generic_Instance (Subp) then
4037 -- Indicate that the body needs to be created for
4038 -- inlining subsequent calls. The instantiation node
4039 -- follows the declaration of the wrapper package
4042 if Scope (Subp) /= Standard_Standard
4044 Need_Subprogram_Instance_Body
4045 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4055 -- For a generic subprogram set flag as well, for use at the point
4056 -- of instantiation, to determine whether the body should be
4059 elsif Is_Generic_Subprogram (Subp) then
4060 Set_Inline_Flags (Subp);
4063 -- Literals are by definition inlined
4065 elsif Kind = E_Enumeration_Literal then
4068 -- Anything else is an error
4072 ("expect subprogram name for pragma%", Assoc);
4076 ----------------------
4077 -- Set_Inline_Flags --
4078 ----------------------
4080 procedure Set_Inline_Flags (Subp : Entity_Id) is
4083 Set_Is_Inlined (Subp, True);
4086 if not Has_Pragma_Inline (Subp) then
4087 Set_Has_Pragma_Inline (Subp);
4091 if Prag_Id = Pragma_Inline_Always then
4092 Set_Has_Pragma_Inline_Always (Subp);
4094 end Set_Inline_Flags;
4096 -- Start of processing for Process_Inline
4099 Check_No_Identifiers;
4100 Check_At_Least_N_Arguments (1);
4103 Inline_Processing_Required := True;
4107 while Present (Assoc) loop
4108 Subp_Id := Expression (Assoc);
4112 if Is_Entity_Name (Subp_Id) then
4113 Subp := Entity (Subp_Id);
4115 if Subp = Any_Id then
4117 -- If previous error, avoid cascaded errors
4125 while Present (Homonym (Subp))
4126 and then Scope (Homonym (Subp)) = Current_Scope
4128 Make_Inline (Homonym (Subp));
4129 Subp := Homonym (Subp);
4136 ("inappropriate argument for pragma%", Assoc);
4139 and then Warn_On_Redundant_Constructs
4140 and then not Suppress_All_Inlining
4142 if Inlining_Not_Possible (Subp) then
4144 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4147 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4155 ----------------------------
4156 -- Process_Interface_Name --
4157 ----------------------------
4159 procedure Process_Interface_Name
4160 (Subprogram_Def : Entity_Id;
4166 String_Val : String_Id;
4168 procedure Check_Form_Of_Interface_Name
4170 Ext_Name_Case : Boolean);
4171 -- SN is a string literal node for an interface name. This routine
4172 -- performs some minimal checks that the name is reasonable. In
4173 -- particular that no spaces or other obviously incorrect characters
4174 -- appear. This is only a warning, since any characters are allowed.
4175 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4177 ----------------------------------
4178 -- Check_Form_Of_Interface_Name --
4179 ----------------------------------
4181 procedure Check_Form_Of_Interface_Name
4183 Ext_Name_Case : Boolean)
4185 S : constant String_Id := Strval (Expr_Value_S (SN));
4186 SL : constant Nat := String_Length (S);
4191 Error_Msg_N ("interface name cannot be null string", SN);
4194 for J in 1 .. SL loop
4195 C := Get_String_Char (S, J);
4197 -- Look for dubious character and issue unconditional warning.
4198 -- Definitely dubious if not in character range.
4200 if not In_Character_Range (C)
4202 -- For all cases except CLI target,
4203 -- commas, spaces and slashes are dubious (in CLI, we use
4204 -- commas and backslashes in external names to specify
4205 -- assembly version and public key, while slashes and spaces
4206 -- can be used in names to mark nested classes and
4209 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4210 and then (Get_Character (C) = ','
4212 Get_Character (C) = '\'))
4213 or else (VM_Target /= CLI_Target
4214 and then (Get_Character (C) = ' '
4216 Get_Character (C) = '/'))
4219 ("?interface name contains illegal character",
4220 Sloc (SN) + Source_Ptr (J));
4223 end Check_Form_Of_Interface_Name;
4225 -- Start of processing for Process_Interface_Name
4228 if No (Link_Arg) then
4229 if No (Ext_Arg) then
4230 if VM_Target = CLI_Target
4231 and then Ekind (Subprogram_Def) = E_Package
4232 and then Nkind (Parent (Subprogram_Def)) =
4233 N_Package_Specification
4234 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4239 (Generic_Parent (Parent (Subprogram_Def))));
4244 elsif Chars (Ext_Arg) = Name_Link_Name then
4246 Link_Nam := Expression (Ext_Arg);
4249 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4250 Ext_Nam := Expression (Ext_Arg);
4255 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4256 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4257 Ext_Nam := Expression (Ext_Arg);
4258 Link_Nam := Expression (Link_Arg);
4261 -- Check expressions for external name and link name are static
4263 if Present (Ext_Nam) then
4264 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4265 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4267 -- Verify that external name is not the name of a local entity,
4268 -- which would hide the imported one and could lead to run-time
4269 -- surprises. The problem can only arise for entities declared in
4270 -- a package body (otherwise the external name is fully qualified
4271 -- and will not conflict).
4279 if Prag_Id = Pragma_Import then
4280 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4282 E := Entity_Id (Get_Name_Table_Info (Nam));
4284 if Nam /= Chars (Subprogram_Def)
4285 and then Present (E)
4286 and then not Is_Overloadable (E)
4287 and then Is_Immediately_Visible (E)
4288 and then not Is_Imported (E)
4289 and then Ekind (Scope (E)) = E_Package
4292 while Present (Par) loop
4293 if Nkind (Par) = N_Package_Body then
4294 Error_Msg_Sloc := Sloc (E);
4296 ("imported entity is hidden by & declared#",
4301 Par := Parent (Par);
4308 if Present (Link_Nam) then
4309 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4310 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4313 -- If there is no link name, just set the external name
4315 if No (Link_Nam) then
4316 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4318 -- For the Link_Name case, the given literal is preceded by an
4319 -- asterisk, which indicates to GCC that the given name should be
4320 -- taken literally, and in particular that no prepending of
4321 -- underlines should occur, even in systems where this is the
4327 if VM_Target = No_VM then
4328 Store_String_Char (Get_Char_Code ('*'));
4331 String_Val := Strval (Expr_Value_S (Link_Nam));
4332 Store_String_Chars (String_Val);
4334 Make_String_Literal (Sloc (Link_Nam),
4335 Strval => End_String);
4338 Set_Encoded_Interface_Name
4339 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4341 -- We allow duplicated export names in CIL, as they are always
4342 -- enclosed in a namespace that differentiates them, and overloaded
4343 -- entities are supported by the VM.
4345 if Convention (Subprogram_Def) /= Convention_CIL then
4346 Check_Duplicated_Export_Name (Link_Nam);
4348 end Process_Interface_Name;
4350 -----------------------------------------
4351 -- Process_Interrupt_Or_Attach_Handler --
4352 -----------------------------------------
4354 procedure Process_Interrupt_Or_Attach_Handler is
4355 Arg1_X : constant Node_Id := Expression (Arg1);
4356 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4357 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4360 Set_Is_Interrupt_Handler (Handler_Proc);
4362 -- If the pragma is not associated with a handler procedure within a
4363 -- protected type, then it must be for a nonprotected procedure for
4364 -- the AAMP target, in which case we don't associate a representation
4365 -- item with the procedure's scope.
4367 if Ekind (Proc_Scope) = E_Protected_Type then
4368 if Prag_Id = Pragma_Interrupt_Handler
4370 Prag_Id = Pragma_Attach_Handler
4372 Record_Rep_Item (Proc_Scope, N);
4375 end Process_Interrupt_Or_Attach_Handler;
4377 --------------------------------------------------
4378 -- Process_Restrictions_Or_Restriction_Warnings --
4379 --------------------------------------------------
4381 -- Note: some of the simple identifier cases were handled in par-prag,
4382 -- but it is harmless (and more straightforward) to simply handle all
4383 -- cases here, even if it means we repeat a bit of work in some cases.
4385 procedure Process_Restrictions_Or_Restriction_Warnings
4389 R_Id : Restriction_Id;
4394 procedure Check_Unit_Name (N : Node_Id);
4395 -- Checks unit name parameter for No_Dependence. Returns if it has
4396 -- an appropriate form, otherwise raises pragma argument error.
4398 ---------------------
4399 -- Check_Unit_Name --
4400 ---------------------
4402 procedure Check_Unit_Name (N : Node_Id) is
4404 if Nkind (N) = N_Selected_Component then
4405 Check_Unit_Name (Prefix (N));
4406 Check_Unit_Name (Selector_Name (N));
4408 elsif Nkind (N) = N_Identifier then
4413 ("wrong form for unit name for No_Dependence", N);
4415 end Check_Unit_Name;
4417 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4420 Check_Ada_83_Warning;
4421 Check_At_Least_N_Arguments (1);
4422 Check_Valid_Configuration_Pragma;
4425 while Present (Arg) loop
4427 Expr := Expression (Arg);
4429 -- Case of no restriction identifier present
4431 if Id = No_Name then
4432 if Nkind (Expr) /= N_Identifier then
4434 ("invalid form for restriction", Arg);
4439 (Process_Restriction_Synonyms (Expr));
4441 if R_Id not in All_Boolean_Restrictions then
4442 Error_Msg_Name_1 := Pname;
4444 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4446 -- Check for possible misspelling
4448 for J in Restriction_Id loop
4450 Rnm : constant String := Restriction_Id'Image (J);
4453 Name_Buffer (1 .. Rnm'Length) := Rnm;
4454 Name_Len := Rnm'Length;
4455 Set_Casing (All_Lower_Case);
4457 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4459 (Identifier_Casing (Current_Source_File));
4460 Error_Msg_String (1 .. Rnm'Length) :=
4461 Name_Buffer (1 .. Name_Len);
4462 Error_Msg_Strlen := Rnm'Length;
4463 Error_Msg_N -- CODEFIX
4464 ("\possible misspelling of ""~""",
4465 Get_Pragma_Arg (Arg));
4474 if Implementation_Restriction (R_Id) then
4475 Check_Restriction (No_Implementation_Restrictions, Arg);
4478 -- If this is a warning, then set the warning unless we already
4479 -- have a real restriction active (we never want a warning to
4480 -- override a real restriction).
4483 if not Restriction_Active (R_Id) then
4484 Set_Restriction (R_Id, N);
4485 Restriction_Warnings (R_Id) := True;
4488 -- If real restriction case, then set it and make sure that the
4489 -- restriction warning flag is off, since a real restriction
4490 -- always overrides a warning.
4493 Set_Restriction (R_Id, N);
4494 Restriction_Warnings (R_Id) := False;
4497 -- Check for obsolescent restrictions in Ada 2005 mode
4500 and then Ada_Version >= Ada_2005
4501 and then (R_Id = No_Asynchronous_Control
4503 R_Id = No_Unchecked_Deallocation
4505 R_Id = No_Unchecked_Conversion)
4507 Check_Restriction (No_Obsolescent_Features, N);
4510 -- A very special case that must be processed here: pragma
4511 -- Restrictions (No_Exceptions) turns off all run-time
4512 -- checking. This is a bit dubious in terms of the formal
4513 -- language definition, but it is what is intended by RM
4514 -- H.4(12). Restriction_Warnings never affects generated code
4515 -- so this is done only in the real restriction case.
4517 if R_Id = No_Exceptions and then not Warn then
4518 Scope_Suppress := (others => True);
4521 -- Case of No_Dependence => unit-name. Note that the parser
4522 -- already made the necessary entry in the No_Dependence table.
4524 elsif Id = Name_No_Dependence then
4525 Check_Unit_Name (Expr);
4527 -- All other cases of restriction identifier present
4530 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4531 Analyze_And_Resolve (Expr, Any_Integer);
4533 if R_Id not in All_Parameter_Restrictions then
4535 ("invalid restriction parameter identifier", Arg);
4537 elsif not Is_OK_Static_Expression (Expr) then
4538 Flag_Non_Static_Expr
4539 ("value must be static expression!", Expr);
4542 elsif not Is_Integer_Type (Etype (Expr))
4543 or else Expr_Value (Expr) < 0
4546 ("value must be non-negative integer", Arg);
4549 -- Restriction pragma is active
4551 Val := Expr_Value (Expr);
4553 if not UI_Is_In_Int_Range (Val) then
4555 ("pragma ignored, value too large?", Arg);
4558 -- Warning case. If the real restriction is active, then we
4559 -- ignore the request, since warning never overrides a real
4560 -- restriction. Otherwise we set the proper warning. Note that
4561 -- this circuit sets the warning again if it is already set,
4562 -- which is what we want, since the constant may have changed.
4565 if not Restriction_Active (R_Id) then
4567 (R_Id, N, Integer (UI_To_Int (Val)));
4568 Restriction_Warnings (R_Id) := True;
4571 -- Real restriction case, set restriction and make sure warning
4572 -- flag is off since real restriction always overrides warning.
4575 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4576 Restriction_Warnings (R_Id) := False;
4582 end Process_Restrictions_Or_Restriction_Warnings;
4584 ---------------------------------
4585 -- Process_Suppress_Unsuppress --
4586 ---------------------------------
4588 -- Note: this procedure makes entries in the check suppress data
4589 -- structures managed by Sem. See spec of package Sem for full
4590 -- details on how we handle recording of check suppression.
4592 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4597 In_Package_Spec : constant Boolean :=
4598 Is_Package_Or_Generic_Package (Current_Scope)
4599 and then not In_Package_Body (Current_Scope);
4601 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4602 -- Used to suppress a single check on the given entity
4604 --------------------------------
4605 -- Suppress_Unsuppress_Echeck --
4606 --------------------------------
4608 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4610 Set_Checks_May_Be_Suppressed (E);
4612 if In_Package_Spec then
4613 Push_Global_Suppress_Stack_Entry
4616 Suppress => Suppress_Case);
4619 Push_Local_Suppress_Stack_Entry
4622 Suppress => Suppress_Case);
4625 -- If this is a first subtype, and the base type is distinct,
4626 -- then also set the suppress flags on the base type.
4628 if Is_First_Subtype (E)
4629 and then Etype (E) /= E
4631 Suppress_Unsuppress_Echeck (Etype (E), C);
4633 end Suppress_Unsuppress_Echeck;
4635 -- Start of processing for Process_Suppress_Unsuppress
4638 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4639 -- declarative part or a package spec (RM 11.5(5)).
4641 if not Is_Configuration_Pragma then
4642 Check_Is_In_Decl_Part_Or_Package_Spec;
4645 Check_At_Least_N_Arguments (1);
4646 Check_At_Most_N_Arguments (2);
4647 Check_No_Identifier (Arg1);
4648 Check_Arg_Is_Identifier (Arg1);
4650 C := Get_Check_Id (Chars (Expression (Arg1)));
4652 if C = No_Check_Id then
4654 ("argument of pragma% is not valid check name", Arg1);
4657 if not Suppress_Case
4658 and then (C = All_Checks or else C = Overflow_Check)
4660 Opt.Overflow_Checks_Unsuppressed := True;
4663 if Arg_Count = 1 then
4665 -- Make an entry in the local scope suppress table. This is the
4666 -- table that directly shows the current value of the scope
4667 -- suppress check for any check id value.
4669 if C = All_Checks then
4671 -- For All_Checks, we set all specific predefined checks with
4672 -- the exception of Elaboration_Check, which is handled
4673 -- specially because of not wanting All_Checks to have the
4674 -- effect of deactivating static elaboration order processing.
4676 for J in Scope_Suppress'Range loop
4677 if J /= Elaboration_Check then
4678 Scope_Suppress (J) := Suppress_Case;
4682 -- If not All_Checks, and predefined check, then set appropriate
4683 -- scope entry. Note that we will set Elaboration_Check if this
4684 -- is explicitly specified.
4686 elsif C in Predefined_Check_Id then
4687 Scope_Suppress (C) := Suppress_Case;
4690 -- Also make an entry in the Local_Entity_Suppress table
4692 Push_Local_Suppress_Stack_Entry
4695 Suppress => Suppress_Case);
4697 -- Case of two arguments present, where the check is suppressed for
4698 -- a specified entity (given as the second argument of the pragma)
4701 -- This is obsolescent in Ada 2005 mode
4703 if Ada_Version >= Ada_2005 then
4704 Check_Restriction (No_Obsolescent_Features, Arg2);
4707 Check_Optional_Identifier (Arg2, Name_On);
4708 E_Id := Expression (Arg2);
4711 if not Is_Entity_Name (E_Id) then
4713 ("second argument of pragma% must be entity name", Arg2);
4722 -- Enforce RM 11.5(7) which requires that for a pragma that
4723 -- appears within a package spec, the named entity must be
4724 -- within the package spec. We allow the package name itself
4725 -- to be mentioned since that makes sense, although it is not
4726 -- strictly allowed by 11.5(7).
4729 and then E /= Current_Scope
4730 and then Scope (E) /= Current_Scope
4733 ("entity in pragma% is not in package spec (RM 11.5(7))",
4737 -- Loop through homonyms. As noted below, in the case of a package
4738 -- spec, only homonyms within the package spec are considered.
4741 Suppress_Unsuppress_Echeck (E, C);
4743 if Is_Generic_Instance (E)
4744 and then Is_Subprogram (E)
4745 and then Present (Alias (E))
4747 Suppress_Unsuppress_Echeck (Alias (E), C);
4750 -- Move to next homonym
4755 -- If we are within a package specification, the pragma only
4756 -- applies to homonyms in the same scope.
4758 exit when In_Package_Spec
4759 and then Scope (E) /= Current_Scope;
4762 end Process_Suppress_Unsuppress;
4768 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4770 if Is_Imported (E) then
4772 ("cannot export entity& that was previously imported", Arg);
4774 elsif Present (Address_Clause (E)) then
4776 ("cannot export entity& that has an address clause", Arg);
4779 Set_Is_Exported (E);
4781 -- Generate a reference for entity explicitly, because the
4782 -- identifier may be overloaded and name resolution will not
4785 Generate_Reference (E, Arg);
4787 -- Deal with exporting non-library level entity
4789 if not Is_Library_Level_Entity (E) then
4791 -- Not allowed at all for subprograms
4793 if Is_Subprogram (E) then
4794 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4796 -- Otherwise set public and statically allocated
4800 Set_Is_Statically_Allocated (E);
4802 -- Warn if the corresponding W flag is set and the pragma comes
4803 -- from source. The latter may not be true e.g. on VMS where we
4804 -- expand export pragmas for exception codes associated with
4805 -- imported or exported exceptions. We do not want to generate
4806 -- a warning for something that the user did not write.
4808 if Warn_On_Export_Import
4809 and then Comes_From_Source (Arg)
4812 ("?& has been made static as a result of Export", Arg, E);
4814 ("\this usage is non-standard and non-portable", Arg);
4819 if Warn_On_Export_Import and then Is_Type (E) then
4820 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
4823 if Warn_On_Export_Import and Inside_A_Generic then
4825 ("all instances of& will have the same external name?", Arg, E);
4829 ----------------------------------------------
4830 -- Set_Extended_Import_Export_External_Name --
4831 ----------------------------------------------
4833 procedure Set_Extended_Import_Export_External_Name
4834 (Internal_Ent : Entity_Id;
4835 Arg_External : Node_Id)
4837 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4841 if No (Arg_External) then
4845 Check_Arg_Is_External_Name (Arg_External);
4847 if Nkind (Arg_External) = N_String_Literal then
4848 if String_Length (Strval (Arg_External)) = 0 then
4851 New_Name := Adjust_External_Name_Case (Arg_External);
4854 elsif Nkind (Arg_External) = N_Identifier then
4855 New_Name := Get_Default_External_Name (Arg_External);
4857 -- Check_Arg_Is_External_Name should let through only identifiers and
4858 -- string literals or static string expressions (which are folded to
4859 -- string literals).
4862 raise Program_Error;
4865 -- If we already have an external name set (by a prior normal Import
4866 -- or Export pragma), then the external names must match
4868 if Present (Interface_Name (Internal_Ent)) then
4869 Check_Matching_Internal_Names : declare
4870 S1 : constant String_Id := Strval (Old_Name);
4871 S2 : constant String_Id := Strval (New_Name);
4874 -- Called if names do not match
4880 procedure Mismatch is
4882 Error_Msg_Sloc := Sloc (Old_Name);
4884 ("external name does not match that given #",
4888 -- Start of processing for Check_Matching_Internal_Names
4891 if String_Length (S1) /= String_Length (S2) then
4895 for J in 1 .. String_Length (S1) loop
4896 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4901 end Check_Matching_Internal_Names;
4903 -- Otherwise set the given name
4906 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4907 Check_Duplicated_Export_Name (New_Name);
4909 end Set_Extended_Import_Export_External_Name;
4915 procedure Set_Imported (E : Entity_Id) is
4917 -- Error message if already imported or exported
4919 if Is_Exported (E) or else Is_Imported (E) then
4921 -- Error if being set Exported twice
4923 if Is_Exported (E) then
4924 Error_Msg_NE ("entity& was previously exported", N, E);
4926 -- OK if Import/Interface case
4928 elsif Import_Interface_Present (N) then
4931 -- Error if being set Imported twice
4934 Error_Msg_NE ("entity& was previously imported", N, E);
4937 Error_Msg_Name_1 := Pname;
4939 ("\(pragma% applies to all previous entities)", N);
4941 Error_Msg_Sloc := Sloc (E);
4942 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4944 -- Here if not previously imported or exported, OK to import
4947 Set_Is_Imported (E);
4949 -- If the entity is an object that is not at the library level,
4950 -- then it is statically allocated. We do not worry about objects
4951 -- with address clauses in this context since they are not really
4952 -- imported in the linker sense.
4955 and then not Is_Library_Level_Entity (E)
4956 and then No (Address_Clause (E))
4958 Set_Is_Statically_Allocated (E);
4965 -------------------------
4966 -- Set_Mechanism_Value --
4967 -------------------------
4969 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4970 -- analyzed, since it is semantic nonsense), so we get it in the exact
4971 -- form created by the parser.
4973 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4976 Mech_Name_Id : Name_Id;
4978 procedure Bad_Class;
4979 -- Signal bad descriptor class name
4981 procedure Bad_Mechanism;
4982 -- Signal bad mechanism name
4988 procedure Bad_Class is
4990 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4993 -------------------------
4994 -- Bad_Mechanism_Value --
4995 -------------------------
4997 procedure Bad_Mechanism is
4999 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5002 -- Start of processing for Set_Mechanism_Value
5005 if Mechanism (Ent) /= Default_Mechanism then
5007 ("mechanism for & has already been set", Mech_Name, Ent);
5010 -- MECHANISM_NAME ::= value | reference | descriptor |
5013 if Nkind (Mech_Name) = N_Identifier then
5014 if Chars (Mech_Name) = Name_Value then
5015 Set_Mechanism (Ent, By_Copy);
5018 elsif Chars (Mech_Name) = Name_Reference then
5019 Set_Mechanism (Ent, By_Reference);
5022 elsif Chars (Mech_Name) = Name_Descriptor then
5023 Check_VMS (Mech_Name);
5025 -- Descriptor => Short_Descriptor if pragma was given
5027 if Short_Descriptors then
5028 Set_Mechanism (Ent, By_Short_Descriptor);
5030 Set_Mechanism (Ent, By_Descriptor);
5035 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5036 Check_VMS (Mech_Name);
5037 Set_Mechanism (Ent, By_Short_Descriptor);
5040 elsif Chars (Mech_Name) = Name_Copy then
5042 ("bad mechanism name, Value assumed", Mech_Name);
5048 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5049 -- short_descriptor (CLASS_NAME)
5050 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5052 -- Note: this form is parsed as an indexed component
5054 elsif Nkind (Mech_Name) = N_Indexed_Component then
5055 Class := First (Expressions (Mech_Name));
5057 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5058 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5059 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5060 or else Present (Next (Class))
5064 Mech_Name_Id := Chars (Prefix (Mech_Name));
5066 -- Change Descriptor => Short_Descriptor if pragma was given
5068 if Mech_Name_Id = Name_Descriptor
5069 and then Short_Descriptors
5071 Mech_Name_Id := Name_Short_Descriptor;
5075 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5076 -- short_descriptor (Class => CLASS_NAME)
5077 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5079 -- Note: this form is parsed as a function call
5081 elsif Nkind (Mech_Name) = N_Function_Call then
5082 Param := First (Parameter_Associations (Mech_Name));
5084 if Nkind (Name (Mech_Name)) /= N_Identifier
5085 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5086 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5087 or else Present (Next (Param))
5088 or else No (Selector_Name (Param))
5089 or else Chars (Selector_Name (Param)) /= Name_Class
5093 Class := Explicit_Actual_Parameter (Param);
5094 Mech_Name_Id := Chars (Name (Mech_Name));
5101 -- Fall through here with Class set to descriptor class name
5103 Check_VMS (Mech_Name);
5105 if Nkind (Class) /= N_Identifier then
5108 elsif Mech_Name_Id = Name_Descriptor
5109 and then Chars (Class) = Name_UBS
5111 Set_Mechanism (Ent, By_Descriptor_UBS);
5113 elsif Mech_Name_Id = Name_Descriptor
5114 and then Chars (Class) = Name_UBSB
5116 Set_Mechanism (Ent, By_Descriptor_UBSB);
5118 elsif Mech_Name_Id = Name_Descriptor
5119 and then Chars (Class) = Name_UBA
5121 Set_Mechanism (Ent, By_Descriptor_UBA);
5123 elsif Mech_Name_Id = Name_Descriptor
5124 and then Chars (Class) = Name_S
5126 Set_Mechanism (Ent, By_Descriptor_S);
5128 elsif Mech_Name_Id = Name_Descriptor
5129 and then Chars (Class) = Name_SB
5131 Set_Mechanism (Ent, By_Descriptor_SB);
5133 elsif Mech_Name_Id = Name_Descriptor
5134 and then Chars (Class) = Name_A
5136 Set_Mechanism (Ent, By_Descriptor_A);
5138 elsif Mech_Name_Id = Name_Descriptor
5139 and then Chars (Class) = Name_NCA
5141 Set_Mechanism (Ent, By_Descriptor_NCA);
5143 elsif Mech_Name_Id = Name_Short_Descriptor
5144 and then Chars (Class) = Name_UBS
5146 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5148 elsif Mech_Name_Id = Name_Short_Descriptor
5149 and then Chars (Class) = Name_UBSB
5151 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5153 elsif Mech_Name_Id = Name_Short_Descriptor
5154 and then Chars (Class) = Name_UBA
5156 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5158 elsif Mech_Name_Id = Name_Short_Descriptor
5159 and then Chars (Class) = Name_S
5161 Set_Mechanism (Ent, By_Short_Descriptor_S);
5163 elsif Mech_Name_Id = Name_Short_Descriptor
5164 and then Chars (Class) = Name_SB
5166 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5168 elsif Mech_Name_Id = Name_Short_Descriptor
5169 and then Chars (Class) = Name_A
5171 Set_Mechanism (Ent, By_Short_Descriptor_A);
5173 elsif Mech_Name_Id = Name_Short_Descriptor
5174 and then Chars (Class) = Name_NCA
5176 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5181 end Set_Mechanism_Value;
5183 ---------------------------
5184 -- Set_Ravenscar_Profile --
5185 ---------------------------
5187 -- The tasks to be done here are
5189 -- Set required policies
5191 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5192 -- pragma Locking_Policy (Ceiling_Locking)
5194 -- Set Detect_Blocking mode
5196 -- Set required restrictions (see System.Rident for detailed list)
5198 procedure Set_Ravenscar_Profile (N : Node_Id) is
5200 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5202 if Task_Dispatching_Policy /= ' '
5203 and then Task_Dispatching_Policy /= 'F'
5205 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5206 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5208 -- Set the FIFO_Within_Priorities policy, but always preserve
5209 -- System_Location since we like the error message with the run time
5213 Task_Dispatching_Policy := 'F';
5215 if Task_Dispatching_Policy_Sloc /= System_Location then
5216 Task_Dispatching_Policy_Sloc := Loc;
5220 -- pragma Locking_Policy (Ceiling_Locking)
5222 if Locking_Policy /= ' '
5223 and then Locking_Policy /= 'C'
5225 Error_Msg_Sloc := Locking_Policy_Sloc;
5226 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5228 -- Set the Ceiling_Locking policy, but preserve System_Location since
5229 -- we like the error message with the run time name.
5232 Locking_Policy := 'C';
5234 if Locking_Policy_Sloc /= System_Location then
5235 Locking_Policy_Sloc := Loc;
5239 -- pragma Detect_Blocking
5241 Detect_Blocking := True;
5243 -- Set the corresponding restrictions
5245 Set_Profile_Restrictions
5246 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5247 end Set_Ravenscar_Profile;
5249 -- Start of processing for Analyze_Pragma
5252 -- Deal with unrecognized pragma
5254 if not Is_Pragma_Name (Pname) then
5255 if Warn_On_Unrecognized_Pragma then
5256 Error_Msg_Name_1 := Pname;
5257 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5259 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5260 if Is_Bad_Spelling_Of (Pname, PN) then
5261 Error_Msg_Name_1 := PN;
5262 Error_Msg_N -- CODEFIX
5263 ("\?possible misspelling of %!", Pragma_Identifier (N));
5272 -- Here to start processing for recognized pragma
5274 Prag_Id := Get_Pragma_Id (Pname);
5283 if Present (Pragma_Argument_Associations (N)) then
5284 Arg1 := First (Pragma_Argument_Associations (N));
5286 if Present (Arg1) then
5287 Arg2 := Next (Arg1);
5289 if Present (Arg2) then
5290 Arg3 := Next (Arg2);
5292 if Present (Arg3) then
5293 Arg4 := Next (Arg3);
5299 -- Count number of arguments
5306 while Present (Arg_Node) loop
5307 Arg_Count := Arg_Count + 1;
5312 -- An enumeration type defines the pragmas that are supported by the
5313 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5314 -- into the corresponding enumeration value for the following case.
5322 -- pragma Abort_Defer;
5324 when Pragma_Abort_Defer =>
5326 Check_Arg_Count (0);
5328 -- The only required semantic processing is to check the
5329 -- placement. This pragma must appear at the start of the
5330 -- statement sequence of a handled sequence of statements.
5332 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5333 or else N /= First (Statements (Parent (N)))
5344 -- Note: this pragma also has some specific processing in Par.Prag
5345 -- because we want to set the Ada version mode during parsing.
5347 when Pragma_Ada_83 =>
5349 Check_Arg_Count (0);
5351 -- We really should check unconditionally for proper configuration
5352 -- pragma placement, since we really don't want mixed Ada modes
5353 -- within a single unit, and the GNAT reference manual has always
5354 -- said this was a configuration pragma, but we did not check and
5355 -- are hesitant to add the check now.
5357 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5358 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5359 -- or Ada 2012 mode.
5361 if Ada_Version >= Ada_05 then
5362 Check_Valid_Configuration_Pragma;
5365 -- Now set Ada 83 mode
5367 Ada_Version := Ada_83;
5368 Ada_Version_Explicit := Ada_Version;
5376 -- Note: this pragma also has some specific processing in Par.Prag
5377 -- because we want to set the Ada 83 version mode during parsing.
5379 when Pragma_Ada_95 =>
5381 Check_Arg_Count (0);
5383 -- We really should check unconditionally for proper configuration
5384 -- pragma placement, since we really don't want mixed Ada modes
5385 -- within a single unit, and the GNAT reference manual has always
5386 -- said this was a configuration pragma, but we did not check and
5387 -- are hesitant to add the check now.
5389 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5390 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5392 if Ada_Version >= Ada_05 then
5393 Check_Valid_Configuration_Pragma;
5396 -- Now set Ada 95 mode
5398 Ada_Version := Ada_95;
5399 Ada_Version_Explicit := Ada_Version;
5401 ---------------------
5402 -- Ada_05/Ada_2005 --
5403 ---------------------
5406 -- pragma Ada_05 (LOCAL_NAME);
5409 -- pragma Ada_2005 (LOCAL_NAME):
5411 -- Note: these pragmas also have some specific processing in Par.Prag
5412 -- because we want to set the Ada 2005 version mode during parsing.
5414 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5420 if Arg_Count = 1 then
5421 Check_Arg_Is_Local_Name (Arg1);
5422 E_Id := Expression (Arg1);
5424 if Etype (E_Id) = Any_Type then
5428 Set_Is_Ada_2005_Only (Entity (E_Id));
5431 Check_Arg_Count (0);
5433 -- For Ada_2005 we unconditionally enforce the documented
5434 -- configuration pragma placement, since we do not want to
5435 -- tolerate mixed modes in a unit involving Ada 2005. That
5436 -- would cause real difficulties for those cases where there
5437 -- are incompatibilities between Ada 95 and Ada 2005.
5439 Check_Valid_Configuration_Pragma;
5441 -- Now set Ada 2005 mode
5443 Ada_Version := Ada_05;
5444 Ada_Version_Explicit := Ada_05;
5448 ---------------------
5449 -- Ada_12/Ada_2012 --
5450 ---------------------
5453 -- pragma Ada_12 (LOCAL_NAME);
5456 -- pragma Ada_2012 (LOCAL_NAME):
5458 -- Note: these pragmas also have some specific processing in Par.Prag
5459 -- because we want to set the Ada 2012 version mode during parsing.
5461 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5467 if Arg_Count = 1 then
5468 Check_Arg_Is_Local_Name (Arg1);
5469 E_Id := Expression (Arg1);
5471 if Etype (E_Id) = Any_Type then
5475 Set_Is_Ada_2012_Only (Entity (E_Id));
5478 Check_Arg_Count (0);
5480 -- For Ada_2012 we unconditionally enforce the documented
5481 -- configuration pragma placement, since we do not want to
5482 -- tolerate mixed modes in a unit involving Ada 2012. That
5483 -- would cause real difficulties for those cases where there
5484 -- are incompatibilities between Ada 95 and Ada 2012. We could
5485 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5487 Check_Valid_Configuration_Pragma;
5489 -- Now set Ada 2012 mode
5491 Ada_Version := Ada_12;
5492 Ada_Version_Explicit := Ada_12;
5496 ----------------------
5497 -- All_Calls_Remote --
5498 ----------------------
5500 -- pragma All_Calls_Remote [(library_package_NAME)];
5502 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5503 Lib_Entity : Entity_Id;
5506 Check_Ada_83_Warning;
5507 Check_Valid_Library_Unit_Pragma;
5509 if Nkind (N) = N_Null_Statement then
5513 Lib_Entity := Find_Lib_Unit_Name;
5515 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5517 if Present (Lib_Entity)
5518 and then not Debug_Flag_U
5520 if not Is_Remote_Call_Interface (Lib_Entity) then
5521 Error_Pragma ("pragma% only apply to rci unit");
5523 -- Set flag for entity of the library unit
5526 Set_Has_All_Calls_Remote (Lib_Entity);
5530 end All_Calls_Remote;
5536 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5537 -- ARG ::= NAME | EXPRESSION
5539 -- The first two arguments are by convention intended to refer to an
5540 -- external tool and a tool-specific function. These arguments are
5543 when Pragma_Annotate => Annotate : begin
5545 Check_At_Least_N_Arguments (1);
5546 Check_Arg_Is_Identifier (Arg1);
5547 Check_No_Identifiers;
5555 -- Second unanalyzed parameter is optional
5561 while Present (Arg) loop
5562 Exp := Expression (Arg);
5565 if Is_Entity_Name (Exp) then
5568 -- For string literals, we assume Standard_String as the
5569 -- type, unless the string contains wide or wide_wide
5572 elsif Nkind (Exp) = N_String_Literal then
5573 if Has_Wide_Wide_Character (Exp) then
5574 Resolve (Exp, Standard_Wide_Wide_String);
5575 elsif Has_Wide_Character (Exp) then
5576 Resolve (Exp, Standard_Wide_String);
5578 Resolve (Exp, Standard_String);
5581 elsif Is_Overloaded (Exp) then
5583 ("ambiguous argument for pragma%", Exp);
5599 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5600 -- [, [Message =>] Static_String_EXPRESSION]);
5602 when Pragma_Assert => Assert : declare
5608 Check_At_Least_N_Arguments (1);
5609 Check_At_Most_N_Arguments (2);
5610 Check_Arg_Order ((Name_Check, Name_Message));
5611 Check_Optional_Identifier (Arg1, Name_Check);
5613 -- We treat pragma Assert as equivalent to:
5615 -- pragma Check (Assertion, condition [, msg]);
5617 -- So rewrite pragma in this manner, and analyze the result
5619 Expr := Get_Pragma_Arg (Arg1);
5621 Make_Pragma_Argument_Association (Loc,
5623 Make_Identifier (Loc,
5624 Chars => Name_Assertion)),
5626 Make_Pragma_Argument_Association (Sloc (Expr),
5627 Expression => Expr));
5629 if Arg_Count > 1 then
5630 Check_Optional_Identifier (Arg2, Name_Message);
5631 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5632 Append_To (Newa, Relocate_Node (Arg2));
5637 Chars => Name_Check,
5638 Pragma_Argument_Associations => Newa));
5642 ----------------------
5643 -- Assertion_Policy --
5644 ----------------------
5646 -- pragma Assertion_Policy (Check | Ignore)
5648 when Pragma_Assertion_Policy => Assertion_Policy : declare
5653 Check_Valid_Configuration_Pragma;
5654 Check_Arg_Count (1);
5655 Check_No_Identifiers;
5656 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5658 -- We treat pragma Assertion_Policy as equivalent to:
5660 -- pragma Check_Policy (Assertion, policy)
5662 -- So rewrite the pragma in that manner and link on to the chain
5663 -- of Check_Policy pragmas, marking the pragma as analyzed.
5665 Policy := Get_Pragma_Arg (Arg1);
5669 Chars => Name_Check_Policy,
5671 Pragma_Argument_Associations => New_List (
5672 Make_Pragma_Argument_Association (Loc,
5674 Make_Identifier (Loc,
5675 Chars => Name_Assertion)),
5677 Make_Pragma_Argument_Association (Loc,
5679 Make_Identifier (Sloc (Policy),
5680 Chars => Chars (Policy))))));
5683 Set_Next_Pragma (N, Opt.Check_Policy_List);
5684 Opt.Check_Policy_List := N;
5685 end Assertion_Policy;
5687 ------------------------------
5688 -- Assume_No_Invalid_Values --
5689 ------------------------------
5691 -- pragma Assume_No_Invalid_Values (On | Off);
5693 when Pragma_Assume_No_Invalid_Values =>
5695 Check_Valid_Configuration_Pragma;
5696 Check_Arg_Count (1);
5697 Check_No_Identifiers;
5698 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5700 if Chars (Expression (Arg1)) = Name_On then
5701 Assume_No_Invalid_Values := True;
5703 Assume_No_Invalid_Values := False;
5710 -- pragma AST_Entry (entry_IDENTIFIER);
5712 when Pragma_AST_Entry => AST_Entry : declare
5718 Check_Arg_Count (1);
5719 Check_No_Identifiers;
5720 Check_Arg_Is_Local_Name (Arg1);
5721 Ent := Entity (Expression (Arg1));
5723 -- Note: the implementation of the AST_Entry pragma could handle
5724 -- the entry family case fine, but for now we are consistent with
5725 -- the DEC rules, and do not allow the pragma, which of course
5726 -- has the effect of also forbidding the attribute.
5728 if Ekind (Ent) /= E_Entry then
5730 ("pragma% argument must be simple entry name", Arg1);
5732 elsif Is_AST_Entry (Ent) then
5734 ("duplicate % pragma for entry", Arg1);
5736 elsif Has_Homonym (Ent) then
5738 ("pragma% argument cannot specify overloaded entry", Arg1);
5742 FF : constant Entity_Id := First_Formal (Ent);
5745 if Present (FF) then
5746 if Present (Next_Formal (FF)) then
5748 ("entry for pragma% can have only one argument",
5751 elsif Parameter_Mode (FF) /= E_In_Parameter then
5753 ("entry parameter for pragma% must have mode IN",
5759 Set_Is_AST_Entry (Ent);
5767 -- pragma Asynchronous (LOCAL_NAME);
5769 when Pragma_Asynchronous => Asynchronous : declare
5777 procedure Process_Async_Pragma;
5778 -- Common processing for procedure and access-to-procedure case
5780 --------------------------
5781 -- Process_Async_Pragma --
5782 --------------------------
5784 procedure Process_Async_Pragma is
5787 Set_Is_Asynchronous (Nm);
5791 -- The formals should be of mode IN (RM E.4.1(6))
5794 while Present (S) loop
5795 Formal := Defining_Identifier (S);
5797 if Nkind (Formal) = N_Defining_Identifier
5798 and then Ekind (Formal) /= E_In_Parameter
5801 ("pragma% procedure can only have IN parameter",
5808 Set_Is_Asynchronous (Nm);
5809 end Process_Async_Pragma;
5811 -- Start of processing for pragma Asynchronous
5814 Check_Ada_83_Warning;
5815 Check_No_Identifiers;
5816 Check_Arg_Count (1);
5817 Check_Arg_Is_Local_Name (Arg1);
5819 if Debug_Flag_U then
5823 C_Ent := Cunit_Entity (Current_Sem_Unit);
5824 Analyze (Expression (Arg1));
5825 Nm := Entity (Expression (Arg1));
5827 if not Is_Remote_Call_Interface (C_Ent)
5828 and then not Is_Remote_Types (C_Ent)
5830 -- This pragma should only appear in an RCI or Remote Types
5831 -- unit (RM E.4.1(4)).
5834 ("pragma% not in Remote_Call_Interface or " &
5835 "Remote_Types unit");
5838 if Ekind (Nm) = E_Procedure
5839 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5841 if not Is_Remote_Call_Interface (Nm) then
5843 ("pragma% cannot be applied on non-remote procedure",
5847 L := Parameter_Specifications (Parent (Nm));
5848 Process_Async_Pragma;
5851 elsif Ekind (Nm) = E_Function then
5853 ("pragma% cannot be applied to function", Arg1);
5855 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5857 if Is_Record_Type (Nm) then
5859 -- A record type that is the Equivalent_Type for a remote
5860 -- access-to-subprogram type.
5862 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5865 -- A non-expanded RAS type (distribution is not enabled)
5867 N := Declaration_Node (Nm);
5870 if Nkind (N) = N_Full_Type_Declaration
5871 and then Nkind (Type_Definition (N)) =
5872 N_Access_Procedure_Definition
5874 L := Parameter_Specifications (Type_Definition (N));
5875 Process_Async_Pragma;
5877 if Is_Asynchronous (Nm)
5878 and then Expander_Active
5879 and then Get_PCS_Name /= Name_No_DSA
5881 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5886 ("pragma% cannot reference access-to-function type",
5890 -- Only other possibility is Access-to-class-wide type
5892 elsif Is_Access_Type (Nm)
5893 and then Is_Class_Wide_Type (Designated_Type (Nm))
5895 Check_First_Subtype (Arg1);
5896 Set_Is_Asynchronous (Nm);
5897 if Expander_Active then
5898 RACW_Type_Is_Asynchronous (Nm);
5902 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5910 -- pragma Atomic (LOCAL_NAME);
5912 when Pragma_Atomic =>
5913 Process_Atomic_Shared_Volatile;
5915 -----------------------
5916 -- Atomic_Components --
5917 -----------------------
5919 -- pragma Atomic_Components (array_LOCAL_NAME);
5921 -- This processing is shared by Volatile_Components
5923 when Pragma_Atomic_Components |
5924 Pragma_Volatile_Components =>
5926 Atomic_Components : declare
5933 Check_Ada_83_Warning;
5934 Check_No_Identifiers;
5935 Check_Arg_Count (1);
5936 Check_Arg_Is_Local_Name (Arg1);
5937 E_Id := Expression (Arg1);
5939 if Etype (E_Id) = Any_Type then
5945 if Rep_Item_Too_Early (E, N)
5947 Rep_Item_Too_Late (E, N)
5952 D := Declaration_Node (E);
5955 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5957 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5958 and then Nkind (D) = N_Object_Declaration
5959 and then Nkind (Object_Definition (D)) =
5960 N_Constrained_Array_Definition)
5962 -- The flag is set on the object, or on the base type
5964 if Nkind (D) /= N_Object_Declaration then
5968 Set_Has_Volatile_Components (E);
5970 if Prag_Id = Pragma_Atomic_Components then
5971 Set_Has_Atomic_Components (E);
5975 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5977 end Atomic_Components;
5979 --------------------
5980 -- Attach_Handler --
5981 --------------------
5983 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5985 when Pragma_Attach_Handler =>
5986 Check_Ada_83_Warning;
5987 Check_No_Identifiers;
5988 Check_Arg_Count (2);
5990 if No_Run_Time_Mode then
5991 Error_Msg_CRT ("Attach_Handler pragma", N);
5993 Check_Interrupt_Or_Attach_Handler;
5995 -- The expression that designates the attribute may
5996 -- depend on a discriminant, and is therefore a per-
5997 -- object expression, to be expanded in the init proc.
5998 -- If expansion is enabled, perform semantic checks
6001 if Expander_Active then
6003 Temp : constant Node_Id :=
6004 New_Copy_Tree (Expression (Arg2));
6006 Set_Parent (Temp, N);
6007 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6011 Analyze (Expression (Arg2));
6012 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
6015 Process_Interrupt_Or_Attach_Handler;
6018 --------------------
6019 -- C_Pass_By_Copy --
6020 --------------------
6022 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6024 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6030 Check_Valid_Configuration_Pragma;
6031 Check_Arg_Count (1);
6032 Check_Optional_Identifier (Arg1, "max_size");
6034 Arg := Expression (Arg1);
6035 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6037 Val := Expr_Value (Arg);
6041 ("maximum size for pragma% must be positive", Arg1);
6043 elsif UI_Is_In_Int_Range (Val) then
6044 Default_C_Record_Mechanism := UI_To_Int (Val);
6046 -- If a giant value is given, Int'Last will do well enough.
6047 -- If sometime someone complains that a record larger than
6048 -- two gigabytes is not copied, we will worry about it then!
6051 Default_C_Record_Mechanism := Mechanism_Type'Last;
6059 -- pragma Check ([Name =>] Identifier,
6060 -- [Check =>] Boolean_Expression
6061 -- [,[Message =>] String_Expression]);
6063 when Pragma_Check => Check : declare
6068 -- Set True if category of assertions referenced by Name enabled
6072 Check_At_Least_N_Arguments (2);
6073 Check_At_Most_N_Arguments (3);
6074 Check_Optional_Identifier (Arg1, Name_Name);
6075 Check_Optional_Identifier (Arg2, Name_Check);
6077 if Arg_Count = 3 then
6078 Check_Optional_Identifier (Arg3, Name_Message);
6079 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6082 Check_Arg_Is_Identifier (Arg1);
6084 -- Indicate if pragma is enabled. The Original_Node reference here
6085 -- is to deal with pragma Assert rewritten as a Check pragma.
6087 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6090 Set_Pragma_Enabled (N);
6091 Set_Pragma_Enabled (Original_Node (N));
6092 Set_SCO_Pragma_Enabled (Loc);
6095 -- If expansion is active and the check is not enabled then we
6096 -- rewrite the Check as:
6098 -- if False and then condition then
6102 -- The reason we do this rewriting during semantic analysis rather
6103 -- than as part of normal expansion is that we cannot analyze and
6104 -- expand the code for the boolean expression directly, or it may
6105 -- cause insertion of actions that would escape the attempt to
6106 -- suppress the check code.
6108 -- Note that the Sloc for the if statement corresponds to the
6109 -- argument condition, not the pragma itself. The reason for this
6110 -- is that we may generate a warning if the condition is False at
6111 -- compile time, and we do not want to delete this warning when we
6112 -- delete the if statement.
6114 Expr := Expression (Arg2);
6116 if Expander_Active and then not Check_On then
6117 Eloc := Sloc (Expr);
6120 Make_If_Statement (Eloc,
6122 Make_And_Then (Eloc,
6123 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6124 Right_Opnd => Expr),
6125 Then_Statements => New_List (
6126 Make_Null_Statement (Eloc))));
6133 Analyze_And_Resolve (Expr, Any_Boolean);
6141 -- pragma Check_Name (check_IDENTIFIER);
6143 when Pragma_Check_Name =>
6144 Check_No_Identifiers;
6146 Check_Valid_Configuration_Pragma;
6147 Check_Arg_Count (1);
6148 Check_Arg_Is_Identifier (Arg1);
6151 Nam : constant Name_Id := Chars (Expression (Arg1));
6154 for J in Check_Names.First .. Check_Names.Last loop
6155 if Check_Names.Table (J) = Nam then
6160 Check_Names.Append (Nam);
6167 -- pragma Check_Policy (
6168 -- [Name =>] IDENTIFIER,
6169 -- [Policy =>] POLICY_IDENTIFIER);
6171 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6173 -- Note: this is a configuration pragma, but it is allowed to appear
6176 when Pragma_Check_Policy =>
6178 Check_Arg_Count (2);
6179 Check_Optional_Identifier (Arg1, Name_Name);
6180 Check_Optional_Identifier (Arg2, Name_Policy);
6182 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6184 -- A Check_Policy pragma can appear either as a configuration
6185 -- pragma, or in a declarative part or a package spec (see RM
6186 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6187 -- followed for Check_Policy).
6189 if not Is_Configuration_Pragma then
6190 Check_Is_In_Decl_Part_Or_Package_Spec;
6193 Set_Next_Pragma (N, Opt.Check_Policy_List);
6194 Opt.Check_Policy_List := N;
6196 ---------------------
6197 -- CIL_Constructor --
6198 ---------------------
6200 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6202 -- Processing for this pragma is shared with Java_Constructor
6208 -- pragma Comment (static_string_EXPRESSION)
6210 -- Processing for pragma Comment shares the circuitry for pragma
6211 -- Ident. The only differences are that Ident enforces a limit of 31
6212 -- characters on its argument, and also enforces limitations on
6213 -- placement for DEC compatibility. Pragma Comment shares neither of
6214 -- these restrictions.
6220 -- pragma Common_Object (
6221 -- [Internal =>] LOCAL_NAME
6222 -- [, [External =>] EXTERNAL_SYMBOL]
6223 -- [, [Size =>] EXTERNAL_SYMBOL]);
6225 -- Processing for this pragma is shared with Psect_Object
6227 ------------------------
6228 -- Compile_Time_Error --
6229 ------------------------
6231 -- pragma Compile_Time_Error
6232 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6234 when Pragma_Compile_Time_Error =>
6236 Process_Compile_Time_Warning_Or_Error;
6238 --------------------------
6239 -- Compile_Time_Warning --
6240 --------------------------
6242 -- pragma Compile_Time_Warning
6243 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6245 when Pragma_Compile_Time_Warning =>
6247 Process_Compile_Time_Warning_Or_Error;
6253 when Pragma_Compiler_Unit =>
6255 Check_Arg_Count (0);
6256 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6258 -----------------------------
6259 -- Complete_Representation --
6260 -----------------------------
6262 -- pragma Complete_Representation;
6264 when Pragma_Complete_Representation =>
6266 Check_Arg_Count (0);
6268 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6270 ("pragma & must appear within record representation clause");
6273 ----------------------------
6274 -- Complex_Representation --
6275 ----------------------------
6277 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6279 when Pragma_Complex_Representation => Complex_Representation : declare
6286 Check_Arg_Count (1);
6287 Check_Optional_Identifier (Arg1, Name_Entity);
6288 Check_Arg_Is_Local_Name (Arg1);
6289 E_Id := Expression (Arg1);
6291 if Etype (E_Id) = Any_Type then
6297 if not Is_Record_Type (E) then
6299 ("argument for pragma% must be record type", Arg1);
6302 Ent := First_Entity (E);
6305 or else No (Next_Entity (Ent))
6306 or else Present (Next_Entity (Next_Entity (Ent)))
6307 or else not Is_Floating_Point_Type (Etype (Ent))
6308 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6311 ("record for pragma% must have two fields of the same "
6312 & "floating-point type", Arg1);
6315 Set_Has_Complex_Representation (Base_Type (E));
6317 -- We need to treat the type has having a non-standard
6318 -- representation, for back-end purposes, even though in
6319 -- general a complex will have the default representation
6320 -- of a record with two real components.
6322 Set_Has_Non_Standard_Rep (Base_Type (E));
6324 end Complex_Representation;
6326 -------------------------
6327 -- Component_Alignment --
6328 -------------------------
6330 -- pragma Component_Alignment (
6331 -- [Form =>] ALIGNMENT_CHOICE
6332 -- [, [Name =>] type_LOCAL_NAME]);
6334 -- ALIGNMENT_CHOICE ::=
6336 -- | Component_Size_4
6340 when Pragma_Component_Alignment => Component_AlignmentP : declare
6341 Args : Args_List (1 .. 2);
6342 Names : constant Name_List (1 .. 2) := (
6346 Form : Node_Id renames Args (1);
6347 Name : Node_Id renames Args (2);
6349 Atype : Component_Alignment_Kind;
6354 Gather_Associations (Names, Args);
6357 Error_Pragma ("missing Form argument for pragma%");
6360 Check_Arg_Is_Identifier (Form);
6362 -- Get proper alignment, note that Default = Component_Size on all
6363 -- machines we have so far, and we want to set this value rather
6364 -- than the default value to indicate that it has been explicitly
6365 -- set (and thus will not get overridden by the default component
6366 -- alignment for the current scope)
6368 if Chars (Form) = Name_Component_Size then
6369 Atype := Calign_Component_Size;
6371 elsif Chars (Form) = Name_Component_Size_4 then
6372 Atype := Calign_Component_Size_4;
6374 elsif Chars (Form) = Name_Default then
6375 Atype := Calign_Component_Size;
6377 elsif Chars (Form) = Name_Storage_Unit then
6378 Atype := Calign_Storage_Unit;
6382 ("invalid Form parameter for pragma%", Form);
6385 -- Case with no name, supplied, affects scope table entry
6389 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6391 -- Case of name supplied
6394 Check_Arg_Is_Local_Name (Name);
6396 Typ := Entity (Name);
6399 or else Rep_Item_Too_Early (Typ, N)
6403 Typ := Underlying_Type (Typ);
6406 if not Is_Record_Type (Typ)
6407 and then not Is_Array_Type (Typ)
6410 ("Name parameter of pragma% must identify record or " &
6411 "array type", Name);
6414 -- An explicit Component_Alignment pragma overrides an
6415 -- implicit pragma Pack, but not an explicit one.
6417 if not Has_Pragma_Pack (Base_Type (Typ)) then
6418 Set_Is_Packed (Base_Type (Typ), False);
6419 Set_Component_Alignment (Base_Type (Typ), Atype);
6422 end Component_AlignmentP;
6428 -- pragma Controlled (first_subtype_LOCAL_NAME);
6430 when Pragma_Controlled => Controlled : declare
6434 Check_No_Identifiers;
6435 Check_Arg_Count (1);
6436 Check_Arg_Is_Local_Name (Arg1);
6437 Arg := Expression (Arg1);
6439 if not Is_Entity_Name (Arg)
6440 or else not Is_Access_Type (Entity (Arg))
6442 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6444 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6452 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6453 -- [Entity =>] LOCAL_NAME);
6455 when Pragma_Convention => Convention : declare
6458 pragma Warnings (Off, C);
6459 pragma Warnings (Off, E);
6461 Check_Arg_Order ((Name_Convention, Name_Entity));
6462 Check_Ada_83_Warning;
6463 Check_Arg_Count (2);
6464 Process_Convention (C, E);
6467 ---------------------------
6468 -- Convention_Identifier --
6469 ---------------------------
6471 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6472 -- [Convention =>] convention_IDENTIFIER);
6474 when Pragma_Convention_Identifier => Convention_Identifier : declare
6480 Check_Arg_Order ((Name_Name, Name_Convention));
6481 Check_Arg_Count (2);
6482 Check_Optional_Identifier (Arg1, Name_Name);
6483 Check_Optional_Identifier (Arg2, Name_Convention);
6484 Check_Arg_Is_Identifier (Arg1);
6485 Check_Arg_Is_Identifier (Arg2);
6486 Idnam := Chars (Expression (Arg1));
6487 Cname := Chars (Expression (Arg2));
6489 if Is_Convention_Name (Cname) then
6490 Record_Convention_Identifier
6491 (Idnam, Get_Convention_Id (Cname));
6494 ("second arg for % pragma must be convention", Arg2);
6496 end Convention_Identifier;
6502 -- pragma CPP_Class ([Entity =>] local_NAME)
6504 when Pragma_CPP_Class => CPP_Class : declare
6509 if Warn_On_Obsolescent_Feature then
6511 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6512 " by pragma import?", N);
6516 Check_Arg_Count (1);
6517 Check_Optional_Identifier (Arg1, Name_Entity);
6518 Check_Arg_Is_Local_Name (Arg1);
6520 Arg := Expression (Arg1);
6523 if Etype (Arg) = Any_Type then
6527 if not Is_Entity_Name (Arg)
6528 or else not Is_Type (Entity (Arg))
6530 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6533 Typ := Entity (Arg);
6535 if not Is_Tagged_Type (Typ) then
6536 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6539 -- Types treated as CPP classes are treated as limited, but we
6540 -- don't require them to be declared this way. A warning is issued
6541 -- to encourage the user to declare them as limited. This is not
6542 -- an error, for compatibility reasons, because these types have
6543 -- been supported this way for some time.
6545 if not Is_Limited_Type (Typ) then
6547 ("imported 'C'P'P type should be " &
6548 "explicitly declared limited?",
6549 Get_Pragma_Arg (Arg1));
6551 ("\type will be considered limited",
6552 Get_Pragma_Arg (Arg1));
6555 Set_Is_CPP_Class (Typ);
6556 Set_Is_Limited_Record (Typ);
6557 Set_Convention (Typ, Convention_CPP);
6559 -- Imported CPP types must not have discriminants (because C++
6560 -- classes do not have discriminants).
6562 if Has_Discriminants (Typ) then
6564 ("imported 'C'P'P type cannot have discriminants",
6565 First (Discriminant_Specifications
6566 (Declaration_Node (Typ))));
6569 -- Components of imported CPP types must not have default
6570 -- expressions because the constructor (if any) is in the
6573 if Is_Incomplete_Or_Private_Type (Typ)
6574 and then No (Underlying_Type (Typ))
6576 -- It should be an error to apply pragma CPP to a private
6577 -- type if the underlying type is not visible (as it is
6578 -- for any representation item). For now, for backward
6579 -- compatibility we do nothing but we cannot check components
6580 -- because they are not available at this stage. All this code
6581 -- will be removed when we cleanup this obsolete GNAT pragma???
6587 Tdef : constant Node_Id :=
6588 Type_Definition (Declaration_Node (Typ));
6593 if Nkind (Tdef) = N_Record_Definition then
6594 Clist := Component_List (Tdef);
6596 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6597 Clist := Component_List (Record_Extension_Part (Tdef));
6600 if Present (Clist) then
6601 Comp := First (Component_Items (Clist));
6602 while Present (Comp) loop
6603 if Present (Expression (Comp)) then
6605 ("component of imported 'C'P'P type cannot have" &
6606 " default expression", Expression (Comp));
6616 ---------------------
6617 -- CPP_Constructor --
6618 ---------------------
6620 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6621 -- [, [External_Name =>] static_string_EXPRESSION ]
6622 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6624 when Pragma_CPP_Constructor => CPP_Constructor : declare
6628 Tag_Typ : Entity_Id;
6632 Check_At_Least_N_Arguments (1);
6633 Check_At_Most_N_Arguments (3);
6634 Check_Optional_Identifier (Arg1, Name_Entity);
6635 Check_Arg_Is_Local_Name (Arg1);
6637 Id := Expression (Arg1);
6638 Find_Program_Unit_Name (Id);
6640 -- If we did not find the name, we are done
6642 if Etype (Id) = Any_Type then
6646 Def_Id := Entity (Id);
6648 -- Check if already defined as constructor
6650 if Is_Constructor (Def_Id) then
6652 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
6656 if Ekind (Def_Id) = E_Function
6657 and then (Is_CPP_Class (Etype (Def_Id))
6658 or else (Is_Class_Wide_Type (Etype (Def_Id))
6660 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6662 if Arg_Count >= 2 then
6663 Set_Imported (Def_Id);
6664 Set_Is_Public (Def_Id);
6665 Process_Interface_Name (Def_Id, Arg2, Arg3);
6668 Set_Has_Completion (Def_Id);
6669 Set_Is_Constructor (Def_Id);
6671 -- Imported C++ constructors are not dispatching primitives
6672 -- because in C++ they don't have a dispatch table slot.
6673 -- However, in Ada the constructor has the profile of a
6674 -- function that returns a tagged type and therefore it has
6675 -- been treated as a primitive operation during semantic
6676 -- analysis. We now remove it from the list of primitive
6677 -- operations of the type.
6679 if Is_Tagged_Type (Etype (Def_Id))
6680 and then not Is_Class_Wide_Type (Etype (Def_Id))
6682 pragma Assert (Is_Dispatching_Operation (Def_Id));
6683 Tag_Typ := Etype (Def_Id);
6685 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6686 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6690 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6691 Set_Is_Dispatching_Operation (Def_Id, False);
6694 -- For backward compatibility, if the constructor returns a
6695 -- class wide type, and we internally change the return type to
6696 -- the corresponding root type.
6698 if Is_Class_Wide_Type (Etype (Def_Id)) then
6699 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6703 ("pragma% requires function returning a 'C'P'P_Class type",
6706 end CPP_Constructor;
6712 when Pragma_CPP_Virtual => CPP_Virtual : declare
6716 if Warn_On_Obsolescent_Feature then
6718 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6727 when Pragma_CPP_Vtable => CPP_Vtable : declare
6731 if Warn_On_Obsolescent_Feature then
6733 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6742 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6744 when Pragma_Debug => Debug : declare
6752 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6755 if Arg_Count = 2 then
6758 Left_Opnd => Relocate_Node (Cond),
6759 Right_Opnd => Expression (Arg1));
6762 -- Rewrite into a conditional with an appropriate condition. We
6763 -- wrap the procedure call in a block so that overhead from e.g.
6764 -- use of the secondary stack does not generate execution overhead
6765 -- for suppressed conditions.
6767 Rewrite (N, Make_Implicit_If_Statement (N,
6769 Then_Statements => New_List (
6770 Make_Block_Statement (Loc,
6771 Handled_Statement_Sequence =>
6772 Make_Handled_Sequence_Of_Statements (Loc,
6773 Statements => New_List (
6774 Relocate_Node (Debug_Statement (N))))))));
6782 -- pragma Debug_Policy (Check | Ignore)
6784 when Pragma_Debug_Policy =>
6786 Check_Arg_Count (1);
6787 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6788 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6790 ---------------------
6791 -- Detect_Blocking --
6792 ---------------------
6794 -- pragma Detect_Blocking;
6796 when Pragma_Detect_Blocking =>
6798 Check_Arg_Count (0);
6799 Check_Valid_Configuration_Pragma;
6800 Detect_Blocking := True;
6806 when Pragma_Dimension =>
6808 Check_Arg_Count (4);
6809 Check_No_Identifiers;
6810 Check_Arg_Is_Local_Name (Arg1);
6812 if not Is_Type (Arg1) then
6813 Error_Pragma ("first argument for pragma% must be subtype");
6816 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
6817 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
6818 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
6824 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6826 when Pragma_Discard_Names => Discard_Names : declare
6831 Check_Ada_83_Warning;
6833 -- Deal with configuration pragma case
6835 if Arg_Count = 0 and then Is_Configuration_Pragma then
6836 Global_Discard_Names := True;
6839 -- Otherwise, check correct appropriate context
6842 Check_Is_In_Decl_Part_Or_Package_Spec;
6844 if Arg_Count = 0 then
6846 -- If there is no parameter, then from now on this pragma
6847 -- applies to any enumeration, exception or tagged type
6848 -- defined in the current declarative part, and recursively
6849 -- to any nested scope.
6851 Set_Discard_Names (Current_Scope);
6855 Check_Arg_Count (1);
6856 Check_Optional_Identifier (Arg1, Name_On);
6857 Check_Arg_Is_Local_Name (Arg1);
6859 E_Id := Expression (Arg1);
6861 if Etype (E_Id) = Any_Type then
6867 if (Is_First_Subtype (E)
6869 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6870 or else Ekind (E) = E_Exception
6872 Set_Discard_Names (E);
6875 ("inappropriate entity for pragma%", Arg1);
6886 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6888 when Pragma_Elaborate => Elaborate : declare
6893 -- Pragma must be in context items list of a compilation unit
6895 if not Is_In_Context_Clause then
6899 -- Must be at least one argument
6901 if Arg_Count = 0 then
6902 Error_Pragma ("pragma% requires at least one argument");
6905 -- In Ada 83 mode, there can be no items following it in the
6906 -- context list except other pragmas and implicit with clauses
6907 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6908 -- placement rule does not apply.
6910 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6912 while Present (Citem) loop
6913 if Nkind (Citem) = N_Pragma
6914 or else (Nkind (Citem) = N_With_Clause
6915 and then Implicit_With (Citem))
6920 ("(Ada 83) pragma% must be at end of context clause");
6927 -- Finally, the arguments must all be units mentioned in a with
6928 -- clause in the same context clause. Note we already checked (in
6929 -- Par.Prag) that the arguments are all identifiers or selected
6933 Outer : while Present (Arg) loop
6934 Citem := First (List_Containing (N));
6935 Inner : while Citem /= N loop
6936 if Nkind (Citem) = N_With_Clause
6937 and then Same_Name (Name (Citem), Expression (Arg))
6939 Set_Elaborate_Present (Citem, True);
6940 Set_Unit_Name (Expression (Arg), Name (Citem));
6942 -- With the pragma present, elaboration calls on
6943 -- subprograms from the named unit need no further
6944 -- checks, as long as the pragma appears in the current
6945 -- compilation unit. If the pragma appears in some unit
6946 -- in the context, there might still be a need for an
6947 -- Elaborate_All_Desirable from the current compilation
6948 -- to the named unit, so we keep the check enabled.
6950 if In_Extended_Main_Source_Unit (N) then
6951 Set_Suppress_Elaboration_Warnings
6952 (Entity (Name (Citem)));
6963 ("argument of pragma% is not with'ed unit", Arg);
6969 -- Give a warning if operating in static mode with -gnatwl
6970 -- (elaboration warnings enabled) switch set.
6972 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6974 ("?use of pragma Elaborate may not be safe", N);
6976 ("?use pragma Elaborate_All instead if possible", N);
6984 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6986 when Pragma_Elaborate_All => Elaborate_All : declare
6991 Check_Ada_83_Warning;
6993 -- Pragma must be in context items list of a compilation unit
6995 if not Is_In_Context_Clause then
6999 -- Must be at least one argument
7001 if Arg_Count = 0 then
7002 Error_Pragma ("pragma% requires at least one argument");
7005 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7006 -- have to appear at the end of the context clause, but may
7007 -- appear mixed in with other items, even in Ada 83 mode.
7009 -- Final check: the arguments must all be units mentioned in
7010 -- a with clause in the same context clause. Note that we
7011 -- already checked (in Par.Prag) that all the arguments are
7012 -- either identifiers or selected components.
7015 Outr : while Present (Arg) loop
7016 Citem := First (List_Containing (N));
7017 Innr : while Citem /= N loop
7018 if Nkind (Citem) = N_With_Clause
7019 and then Same_Name (Name (Citem), Expression (Arg))
7021 Set_Elaborate_All_Present (Citem, True);
7022 Set_Unit_Name (Expression (Arg), Name (Citem));
7024 -- Suppress warnings and elaboration checks on the named
7025 -- unit if the pragma is in the current compilation, as
7026 -- for pragma Elaborate.
7028 if In_Extended_Main_Source_Unit (N) then
7029 Set_Suppress_Elaboration_Warnings
7030 (Entity (Name (Citem)));
7039 Set_Error_Posted (N);
7041 ("argument of pragma% is not with'ed unit", Arg);
7048 --------------------
7049 -- Elaborate_Body --
7050 --------------------
7052 -- pragma Elaborate_Body [( library_unit_NAME )];
7054 when Pragma_Elaborate_Body => Elaborate_Body : declare
7055 Cunit_Node : Node_Id;
7056 Cunit_Ent : Entity_Id;
7059 Check_Ada_83_Warning;
7060 Check_Valid_Library_Unit_Pragma;
7062 if Nkind (N) = N_Null_Statement then
7066 Cunit_Node := Cunit (Current_Sem_Unit);
7067 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7069 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7072 Error_Pragma ("pragma% must refer to a spec, not a body");
7074 Set_Body_Required (Cunit_Node, True);
7075 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7077 -- If we are in dynamic elaboration mode, then we suppress
7078 -- elaboration warnings for the unit, since it is definitely
7079 -- fine NOT to do dynamic checks at the first level (and such
7080 -- checks will be suppressed because no elaboration boolean
7081 -- is created for Elaborate_Body packages).
7083 -- But in the static model of elaboration, Elaborate_Body is
7084 -- definitely NOT good enough to ensure elaboration safety on
7085 -- its own, since the body may WITH other units that are not
7086 -- safe from an elaboration point of view, so a client must
7087 -- still do an Elaborate_All on such units.
7089 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7090 -- Elaborate_Body always suppressed elab warnings.
7092 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7093 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7098 ------------------------
7099 -- Elaboration_Checks --
7100 ------------------------
7102 -- pragma Elaboration_Checks (Static | Dynamic);
7104 when Pragma_Elaboration_Checks =>
7106 Check_Arg_Count (1);
7107 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7108 Dynamic_Elaboration_Checks :=
7109 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7115 -- pragma Eliminate (
7116 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7117 -- [,[Entity =>] IDENTIFIER |
7118 -- SELECTED_COMPONENT |
7120 -- [, OVERLOADING_RESOLUTION]);
7122 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7125 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7128 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7130 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7131 -- Result_Type => result_SUBTYPE_NAME]
7133 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7134 -- SUBTYPE_NAME ::= STRING_LITERAL
7136 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7137 -- SOURCE_TRACE ::= STRING_LITERAL
7139 when Pragma_Eliminate => Eliminate : declare
7140 Args : Args_List (1 .. 5);
7141 Names : constant Name_List (1 .. 5) := (
7144 Name_Parameter_Types,
7146 Name_Source_Location);
7148 Unit_Name : Node_Id renames Args (1);
7149 Entity : Node_Id renames Args (2);
7150 Parameter_Types : Node_Id renames Args (3);
7151 Result_Type : Node_Id renames Args (4);
7152 Source_Location : Node_Id renames Args (5);
7156 Check_Valid_Configuration_Pragma;
7157 Gather_Associations (Names, Args);
7159 if No (Unit_Name) then
7160 Error_Pragma ("missing Unit_Name argument for pragma%");
7164 and then (Present (Parameter_Types)
7166 Present (Result_Type)
7168 Present (Source_Location))
7170 Error_Pragma ("missing Entity argument for pragma%");
7173 if (Present (Parameter_Types)
7175 Present (Result_Type))
7177 Present (Source_Location)
7180 ("parameter profile and source location cannot " &
7181 "be used together in pragma%");
7184 Process_Eliminate_Pragma
7198 -- [ Convention =>] convention_IDENTIFIER,
7199 -- [ Entity =>] local_NAME
7200 -- [, [External_Name =>] static_string_EXPRESSION ]
7201 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7203 when Pragma_Export => Export : declare
7207 pragma Warnings (Off, C);
7210 Check_Ada_83_Warning;
7216 Check_At_Least_N_Arguments (2);
7217 Check_At_Most_N_Arguments (4);
7218 Process_Convention (C, Def_Id);
7220 if Ekind (Def_Id) /= E_Constant then
7221 Note_Possible_Modification (Expression (Arg2), Sure => False);
7224 Process_Interface_Name (Def_Id, Arg3, Arg4);
7225 Set_Exported (Def_Id, Arg2);
7227 -- If the entity is a deferred constant, propagate the information
7228 -- to the full view, because gigi elaborates the full view only.
7230 if Ekind (Def_Id) = E_Constant
7231 and then Present (Full_View (Def_Id))
7234 Id2 : constant Entity_Id := Full_View (Def_Id);
7236 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7237 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7238 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7243 ----------------------
7244 -- Export_Exception --
7245 ----------------------
7247 -- pragma Export_Exception (
7248 -- [Internal =>] LOCAL_NAME
7249 -- [, [External =>] EXTERNAL_SYMBOL]
7250 -- [, [Form =>] Ada | VMS]
7251 -- [, [Code =>] static_integer_EXPRESSION]);
7253 when Pragma_Export_Exception => Export_Exception : declare
7254 Args : Args_List (1 .. 4);
7255 Names : constant Name_List (1 .. 4) := (
7261 Internal : Node_Id renames Args (1);
7262 External : Node_Id renames Args (2);
7263 Form : Node_Id renames Args (3);
7264 Code : Node_Id renames Args (4);
7269 if Inside_A_Generic then
7270 Error_Pragma ("pragma% cannot be used for generic entities");
7273 Gather_Associations (Names, Args);
7274 Process_Extended_Import_Export_Exception_Pragma (
7275 Arg_Internal => Internal,
7276 Arg_External => External,
7280 if not Is_VMS_Exception (Entity (Internal)) then
7281 Set_Exported (Entity (Internal), Internal);
7283 end Export_Exception;
7285 ---------------------
7286 -- Export_Function --
7287 ---------------------
7289 -- pragma Export_Function (
7290 -- [Internal =>] LOCAL_NAME
7291 -- [, [External =>] EXTERNAL_SYMBOL]
7292 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7293 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7294 -- [, [Mechanism =>] MECHANISM]
7295 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7297 -- EXTERNAL_SYMBOL ::=
7299 -- | static_string_EXPRESSION
7301 -- PARAMETER_TYPES ::=
7303 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7305 -- TYPE_DESIGNATOR ::=
7307 -- | subtype_Name ' Access
7311 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7313 -- MECHANISM_ASSOCIATION ::=
7314 -- [formal_parameter_NAME =>] MECHANISM_NAME
7316 -- MECHANISM_NAME ::=
7319 -- | Descriptor [([Class =>] CLASS_NAME)]
7321 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7323 when Pragma_Export_Function => Export_Function : declare
7324 Args : Args_List (1 .. 6);
7325 Names : constant Name_List (1 .. 6) := (
7328 Name_Parameter_Types,
7331 Name_Result_Mechanism);
7333 Internal : Node_Id renames Args (1);
7334 External : Node_Id renames Args (2);
7335 Parameter_Types : Node_Id renames Args (3);
7336 Result_Type : Node_Id renames Args (4);
7337 Mechanism : Node_Id renames Args (5);
7338 Result_Mechanism : Node_Id renames Args (6);
7342 Gather_Associations (Names, Args);
7343 Process_Extended_Import_Export_Subprogram_Pragma (
7344 Arg_Internal => Internal,
7345 Arg_External => External,
7346 Arg_Parameter_Types => Parameter_Types,
7347 Arg_Result_Type => Result_Type,
7348 Arg_Mechanism => Mechanism,
7349 Arg_Result_Mechanism => Result_Mechanism);
7350 end Export_Function;
7356 -- pragma Export_Object (
7357 -- [Internal =>] LOCAL_NAME
7358 -- [, [External =>] EXTERNAL_SYMBOL]
7359 -- [, [Size =>] EXTERNAL_SYMBOL]);
7361 -- EXTERNAL_SYMBOL ::=
7363 -- | static_string_EXPRESSION
7365 -- PARAMETER_TYPES ::=
7367 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7369 -- TYPE_DESIGNATOR ::=
7371 -- | subtype_Name ' Access
7375 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7377 -- MECHANISM_ASSOCIATION ::=
7378 -- [formal_parameter_NAME =>] MECHANISM_NAME
7380 -- MECHANISM_NAME ::=
7383 -- | Descriptor [([Class =>] CLASS_NAME)]
7385 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7387 when Pragma_Export_Object => Export_Object : declare
7388 Args : Args_List (1 .. 3);
7389 Names : constant Name_List (1 .. 3) := (
7394 Internal : Node_Id renames Args (1);
7395 External : Node_Id renames Args (2);
7396 Size : Node_Id renames Args (3);
7400 Gather_Associations (Names, Args);
7401 Process_Extended_Import_Export_Object_Pragma (
7402 Arg_Internal => Internal,
7403 Arg_External => External,
7407 ----------------------
7408 -- Export_Procedure --
7409 ----------------------
7411 -- pragma Export_Procedure (
7412 -- [Internal =>] LOCAL_NAME
7413 -- [, [External =>] EXTERNAL_SYMBOL]
7414 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7415 -- [, [Mechanism =>] MECHANISM]);
7417 -- EXTERNAL_SYMBOL ::=
7419 -- | static_string_EXPRESSION
7421 -- PARAMETER_TYPES ::=
7423 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7425 -- TYPE_DESIGNATOR ::=
7427 -- | subtype_Name ' Access
7431 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7433 -- MECHANISM_ASSOCIATION ::=
7434 -- [formal_parameter_NAME =>] MECHANISM_NAME
7436 -- MECHANISM_NAME ::=
7439 -- | Descriptor [([Class =>] CLASS_NAME)]
7441 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7443 when Pragma_Export_Procedure => Export_Procedure : declare
7444 Args : Args_List (1 .. 4);
7445 Names : constant Name_List (1 .. 4) := (
7448 Name_Parameter_Types,
7451 Internal : Node_Id renames Args (1);
7452 External : Node_Id renames Args (2);
7453 Parameter_Types : Node_Id renames Args (3);
7454 Mechanism : Node_Id renames Args (4);
7458 Gather_Associations (Names, Args);
7459 Process_Extended_Import_Export_Subprogram_Pragma (
7460 Arg_Internal => Internal,
7461 Arg_External => External,
7462 Arg_Parameter_Types => Parameter_Types,
7463 Arg_Mechanism => Mechanism);
7464 end Export_Procedure;
7470 -- pragma Export_Value (
7471 -- [Value =>] static_integer_EXPRESSION,
7472 -- [Link_Name =>] static_string_EXPRESSION);
7474 when Pragma_Export_Value =>
7476 Check_Arg_Order ((Name_Value, Name_Link_Name));
7477 Check_Arg_Count (2);
7479 Check_Optional_Identifier (Arg1, Name_Value);
7480 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7482 Check_Optional_Identifier (Arg2, Name_Link_Name);
7483 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7485 -----------------------------
7486 -- Export_Valued_Procedure --
7487 -----------------------------
7489 -- pragma Export_Valued_Procedure (
7490 -- [Internal =>] LOCAL_NAME
7491 -- [, [External =>] EXTERNAL_SYMBOL,]
7492 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7493 -- [, [Mechanism =>] MECHANISM]);
7495 -- EXTERNAL_SYMBOL ::=
7497 -- | static_string_EXPRESSION
7499 -- PARAMETER_TYPES ::=
7501 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7503 -- TYPE_DESIGNATOR ::=
7505 -- | subtype_Name ' Access
7509 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7511 -- MECHANISM_ASSOCIATION ::=
7512 -- [formal_parameter_NAME =>] MECHANISM_NAME
7514 -- MECHANISM_NAME ::=
7517 -- | Descriptor [([Class =>] CLASS_NAME)]
7519 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7521 when Pragma_Export_Valued_Procedure =>
7522 Export_Valued_Procedure : declare
7523 Args : Args_List (1 .. 4);
7524 Names : constant Name_List (1 .. 4) := (
7527 Name_Parameter_Types,
7530 Internal : Node_Id renames Args (1);
7531 External : Node_Id renames Args (2);
7532 Parameter_Types : Node_Id renames Args (3);
7533 Mechanism : Node_Id renames Args (4);
7537 Gather_Associations (Names, Args);
7538 Process_Extended_Import_Export_Subprogram_Pragma (
7539 Arg_Internal => Internal,
7540 Arg_External => External,
7541 Arg_Parameter_Types => Parameter_Types,
7542 Arg_Mechanism => Mechanism);
7543 end Export_Valued_Procedure;
7549 -- pragma Extend_System ([Name =>] Identifier);
7551 when Pragma_Extend_System => Extend_System : declare
7554 Check_Valid_Configuration_Pragma;
7555 Check_Arg_Count (1);
7556 Check_Optional_Identifier (Arg1, Name_Name);
7557 Check_Arg_Is_Identifier (Arg1);
7559 Get_Name_String (Chars (Expression (Arg1)));
7562 and then Name_Buffer (1 .. 4) = "aux_"
7564 if Present (System_Extend_Pragma_Arg) then
7565 if Chars (Expression (Arg1)) =
7566 Chars (Expression (System_Extend_Pragma_Arg))
7570 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7571 Error_Pragma ("pragma% conflicts with that #");
7575 System_Extend_Pragma_Arg := Arg1;
7577 if not GNAT_Mode then
7578 System_Extend_Unit := Arg1;
7582 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7586 ------------------------
7587 -- Extensions_Allowed --
7588 ------------------------
7590 -- pragma Extensions_Allowed (ON | OFF);
7592 when Pragma_Extensions_Allowed =>
7594 Check_Arg_Count (1);
7595 Check_No_Identifiers;
7596 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7598 if Chars (Expression (Arg1)) = Name_On then
7599 Extensions_Allowed := True;
7600 Ada_Version := Ada_Version_Type'Last;
7603 Extensions_Allowed := False;
7604 Ada_Version := Ada_Version_Explicit;
7611 -- pragma External (
7612 -- [ Convention =>] convention_IDENTIFIER,
7613 -- [ Entity =>] local_NAME
7614 -- [, [External_Name =>] static_string_EXPRESSION ]
7615 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7617 when Pragma_External => External : declare
7621 pragma Warnings (Off, C);
7630 Check_At_Least_N_Arguments (2);
7631 Check_At_Most_N_Arguments (4);
7632 Process_Convention (C, Def_Id);
7633 Note_Possible_Modification (Expression (Arg2), Sure => False);
7634 Process_Interface_Name (Def_Id, Arg3, Arg4);
7635 Set_Exported (Def_Id, Arg2);
7638 --------------------------
7639 -- External_Name_Casing --
7640 --------------------------
7642 -- pragma External_Name_Casing (
7643 -- UPPERCASE | LOWERCASE
7644 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7646 when Pragma_External_Name_Casing => External_Name_Casing : declare
7649 Check_No_Identifiers;
7651 if Arg_Count = 2 then
7653 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7655 case Chars (Get_Pragma_Arg (Arg2)) is
7657 Opt.External_Name_Exp_Casing := As_Is;
7659 when Name_Uppercase =>
7660 Opt.External_Name_Exp_Casing := Uppercase;
7662 when Name_Lowercase =>
7663 Opt.External_Name_Exp_Casing := Lowercase;
7670 Check_Arg_Count (1);
7673 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7675 case Chars (Get_Pragma_Arg (Arg1)) is
7676 when Name_Uppercase =>
7677 Opt.External_Name_Imp_Casing := Uppercase;
7679 when Name_Lowercase =>
7680 Opt.External_Name_Imp_Casing := Lowercase;
7685 end External_Name_Casing;
7687 --------------------------
7688 -- Favor_Top_Level --
7689 --------------------------
7691 -- pragma Favor_Top_Level (type_NAME);
7693 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7694 Named_Entity : Entity_Id;
7698 Check_No_Identifiers;
7699 Check_Arg_Count (1);
7700 Check_Arg_Is_Local_Name (Arg1);
7701 Named_Entity := Entity (Expression (Arg1));
7703 -- If it's an access-to-subprogram type (in particular, not a
7704 -- subtype), set the flag on that type.
7706 if Is_Access_Subprogram_Type (Named_Entity) then
7707 Set_Can_Use_Internal_Rep (Named_Entity, False);
7709 -- Otherwise it's an error (name denotes the wrong sort of entity)
7713 ("access-to-subprogram type expected", Expression (Arg1));
7715 end Favor_Top_Level;
7721 -- pragma Fast_Math;
7723 when Pragma_Fast_Math =>
7725 Check_No_Identifiers;
7726 Check_Valid_Configuration_Pragma;
7729 ---------------------------
7730 -- Finalize_Storage_Only --
7731 ---------------------------
7733 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7735 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7736 Assoc : constant Node_Id := Arg1;
7737 Type_Id : constant Node_Id := Expression (Assoc);
7742 Check_No_Identifiers;
7743 Check_Arg_Count (1);
7744 Check_Arg_Is_Local_Name (Arg1);
7746 Find_Type (Type_Id);
7747 Typ := Entity (Type_Id);
7750 or else Rep_Item_Too_Early (Typ, N)
7754 Typ := Underlying_Type (Typ);
7757 if not Is_Controlled (Typ) then
7758 Error_Pragma ("pragma% must specify controlled type");
7761 Check_First_Subtype (Arg1);
7763 if Finalize_Storage_Only (Typ) then
7764 Error_Pragma ("duplicate pragma%, only one allowed");
7766 elsif not Rep_Item_Too_Late (Typ, N) then
7767 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7769 end Finalize_Storage;
7771 --------------------------
7772 -- Float_Representation --
7773 --------------------------
7775 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7777 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7779 when Pragma_Float_Representation => Float_Representation : declare
7787 if Arg_Count = 1 then
7788 Check_Valid_Configuration_Pragma;
7790 Check_Arg_Count (2);
7791 Check_Optional_Identifier (Arg2, Name_Entity);
7792 Check_Arg_Is_Local_Name (Arg2);
7795 Check_No_Identifier (Arg1);
7796 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7798 if not OpenVMS_On_Target then
7799 if Chars (Expression (Arg1)) = Name_VAX_Float then
7801 ("?pragma% ignored (applies only to Open'V'M'S)");
7807 -- One argument case
7809 if Arg_Count = 1 then
7810 if Chars (Expression (Arg1)) = Name_VAX_Float then
7811 if Opt.Float_Format = 'I' then
7812 Error_Pragma ("'I'E'E'E format previously specified");
7815 Opt.Float_Format := 'V';
7818 if Opt.Float_Format = 'V' then
7819 Error_Pragma ("'V'A'X format previously specified");
7822 Opt.Float_Format := 'I';
7825 Set_Standard_Fpt_Formats;
7827 -- Two argument case
7830 Argx := Get_Pragma_Arg (Arg2);
7832 if not Is_Entity_Name (Argx)
7833 or else not Is_Floating_Point_Type (Entity (Argx))
7836 ("second argument of% pragma must be floating-point type",
7840 Ent := Entity (Argx);
7841 Digs := UI_To_Int (Digits_Value (Ent));
7843 -- Two arguments, VAX_Float case
7845 if Chars (Expression (Arg1)) = Name_VAX_Float then
7847 when 6 => Set_F_Float (Ent);
7848 when 9 => Set_D_Float (Ent);
7849 when 15 => Set_G_Float (Ent);
7853 ("wrong digits value, must be 6,9 or 15", Arg2);
7856 -- Two arguments, IEEE_Float case
7860 when 6 => Set_IEEE_Short (Ent);
7861 when 15 => Set_IEEE_Long (Ent);
7865 ("wrong digits value, must be 6 or 15", Arg2);
7869 end Float_Representation;
7875 -- pragma Ident (static_string_EXPRESSION)
7877 -- Note: pragma Comment shares this processing. Pragma Comment is
7878 -- identical to Ident, except that the restriction of the argument to
7879 -- 31 characters and the placement restrictions are not enforced for
7882 when Pragma_Ident | Pragma_Comment => Ident : declare
7887 Check_Arg_Count (1);
7888 Check_No_Identifiers;
7889 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7892 -- For pragma Ident, preserve DEC compatibility by requiring the
7893 -- pragma to appear in a declarative part or package spec.
7895 if Prag_Id = Pragma_Ident then
7896 Check_Is_In_Decl_Part_Or_Package_Spec;
7899 Str := Expr_Value_S (Expression (Arg1));
7906 GP := Parent (Parent (N));
7908 if Nkind_In (GP, N_Package_Declaration,
7909 N_Generic_Package_Declaration)
7914 -- If we have a compilation unit, then record the ident value,
7915 -- checking for improper duplication.
7917 if Nkind (GP) = N_Compilation_Unit then
7918 CS := Ident_String (Current_Sem_Unit);
7920 if Present (CS) then
7922 -- For Ident, we do not permit multiple instances
7924 if Prag_Id = Pragma_Ident then
7925 Error_Pragma ("duplicate% pragma not permitted");
7927 -- For Comment, we concatenate the string, unless we want
7928 -- to preserve the tree structure for ASIS.
7930 elsif not ASIS_Mode then
7931 Start_String (Strval (CS));
7932 Store_String_Char (' ');
7933 Store_String_Chars (Strval (Str));
7934 Set_Strval (CS, End_String);
7938 -- In VMS, the effect of IDENT is achieved by passing
7939 -- --identification=name as a --for-linker switch.
7941 if OpenVMS_On_Target then
7944 ("--for-linker=--identification=");
7945 String_To_Name_Buffer (Strval (Str));
7946 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7948 -- Only the last processed IDENT is saved. The main
7949 -- purpose is so an IDENT associated with a main
7950 -- procedure will be used in preference to an IDENT
7951 -- associated with a with'd package.
7953 Replace_Linker_Option_String
7954 (End_String, "--for-linker=--identification=");
7957 Set_Ident_String (Current_Sem_Unit, Str);
7960 -- For subunits, we just ignore the Ident, since in GNAT these
7961 -- are not separate object files, and hence not separate units
7962 -- in the unit table.
7964 elsif Nkind (GP) = N_Subunit then
7967 -- Otherwise we have a misplaced pragma Ident, but we ignore
7968 -- this if we are in an instantiation, since it comes from
7969 -- a generic, and has no relevance to the instantiation.
7971 elsif Prag_Id = Pragma_Ident then
7972 if Instantiation_Location (Loc) = No_Location then
7973 Error_Pragma ("pragma% only allowed at outer level");
7983 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
7984 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
7986 when Pragma_Implemented => Implemented : declare
7987 Proc_Id : Entity_Id;
7992 Check_Arg_Count (2);
7993 Check_No_Identifiers;
7994 Check_Arg_Is_Identifier (Arg1);
7995 Check_Arg_Is_Local_Name (Arg1);
7997 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
7999 -- Extract the name of the local procedure
8001 Proc_Id := Entity (Expression (Arg1));
8003 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8004 -- primitive procedure of a synchronized tagged type.
8006 if Ekind (Proc_Id) = E_Procedure
8007 and then Is_Primitive (Proc_Id)
8008 and then Present (First_Formal (Proc_Id))
8010 Typ := Etype (First_Formal (Proc_Id));
8012 if Is_Tagged_Type (Typ)
8015 -- Check for a protected, a synchronized or a task interface
8017 ((Is_Interface (Typ)
8018 and then Is_Synchronized_Interface (Typ))
8020 -- Check for a protected type or a task type that implements
8024 (Is_Concurrent_Record_Type (Typ)
8025 and then Present (Interfaces (Typ)))
8027 -- Check for a private record extension with keyword
8031 (Ekind_In (Typ, E_Record_Type_With_Private,
8032 E_Record_Subtype_With_Private)
8033 and then Synchronized_Present (Parent (Typ))))
8038 ("controlling formal must be of synchronized " &
8039 "tagged type", Arg1);
8043 -- Procedures declared inside a protected type must be accepted
8045 elsif Ekind (Proc_Id) = E_Procedure
8046 and then Is_Protected_Type (Scope (Proc_Id))
8050 -- The first argument is not a primitive procedure
8054 ("pragma % must be applied to a primitive procedure", Arg1);
8058 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8059 -- By_Protected_Procedure to the primitive procedure of a task
8062 if Chars (Arg2) = Name_By_Protected_Procedure
8063 and then Is_Interface (Typ)
8064 and then Is_Task_Interface (Typ)
8067 ("implementation kind By_Protected_Procedure cannot be " &
8068 "applied to a task interface primitive", Arg2);
8072 Record_Rep_Item (Proc_Id, N);
8075 ----------------------
8076 -- Implicit_Packing --
8077 ----------------------
8079 -- pragma Implicit_Packing;
8081 when Pragma_Implicit_Packing =>
8083 Check_Arg_Count (0);
8084 Implicit_Packing := True;
8091 -- [Convention =>] convention_IDENTIFIER,
8092 -- [Entity =>] local_NAME
8093 -- [, [External_Name =>] static_string_EXPRESSION ]
8094 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8096 when Pragma_Import =>
8097 Check_Ada_83_Warning;
8103 Check_At_Least_N_Arguments (2);
8104 Check_At_Most_N_Arguments (4);
8105 Process_Import_Or_Interface;
8107 ----------------------
8108 -- Import_Exception --
8109 ----------------------
8111 -- pragma Import_Exception (
8112 -- [Internal =>] LOCAL_NAME
8113 -- [, [External =>] EXTERNAL_SYMBOL]
8114 -- [, [Form =>] Ada | VMS]
8115 -- [, [Code =>] static_integer_EXPRESSION]);
8117 when Pragma_Import_Exception => Import_Exception : declare
8118 Args : Args_List (1 .. 4);
8119 Names : constant Name_List (1 .. 4) := (
8125 Internal : Node_Id renames Args (1);
8126 External : Node_Id renames Args (2);
8127 Form : Node_Id renames Args (3);
8128 Code : Node_Id renames Args (4);
8132 Gather_Associations (Names, Args);
8134 if Present (External) and then Present (Code) then
8136 ("cannot give both External and Code options for pragma%");
8139 Process_Extended_Import_Export_Exception_Pragma (
8140 Arg_Internal => Internal,
8141 Arg_External => External,
8145 if not Is_VMS_Exception (Entity (Internal)) then
8146 Set_Imported (Entity (Internal));
8148 end Import_Exception;
8150 ---------------------
8151 -- Import_Function --
8152 ---------------------
8154 -- pragma Import_Function (
8155 -- [Internal =>] LOCAL_NAME,
8156 -- [, [External =>] EXTERNAL_SYMBOL]
8157 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8158 -- [, [Result_Type =>] SUBTYPE_MARK]
8159 -- [, [Mechanism =>] MECHANISM]
8160 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8161 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8163 -- EXTERNAL_SYMBOL ::=
8165 -- | static_string_EXPRESSION
8167 -- PARAMETER_TYPES ::=
8169 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8171 -- TYPE_DESIGNATOR ::=
8173 -- | subtype_Name ' Access
8177 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8179 -- MECHANISM_ASSOCIATION ::=
8180 -- [formal_parameter_NAME =>] MECHANISM_NAME
8182 -- MECHANISM_NAME ::=
8185 -- | Descriptor [([Class =>] CLASS_NAME)]
8187 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8189 when Pragma_Import_Function => Import_Function : declare
8190 Args : Args_List (1 .. 7);
8191 Names : constant Name_List (1 .. 7) := (
8194 Name_Parameter_Types,
8197 Name_Result_Mechanism,
8198 Name_First_Optional_Parameter);
8200 Internal : Node_Id renames Args (1);
8201 External : Node_Id renames Args (2);
8202 Parameter_Types : Node_Id renames Args (3);
8203 Result_Type : Node_Id renames Args (4);
8204 Mechanism : Node_Id renames Args (5);
8205 Result_Mechanism : Node_Id renames Args (6);
8206 First_Optional_Parameter : Node_Id renames Args (7);
8210 Gather_Associations (Names, Args);
8211 Process_Extended_Import_Export_Subprogram_Pragma (
8212 Arg_Internal => Internal,
8213 Arg_External => External,
8214 Arg_Parameter_Types => Parameter_Types,
8215 Arg_Result_Type => Result_Type,
8216 Arg_Mechanism => Mechanism,
8217 Arg_Result_Mechanism => Result_Mechanism,
8218 Arg_First_Optional_Parameter => First_Optional_Parameter);
8219 end Import_Function;
8225 -- pragma Import_Object (
8226 -- [Internal =>] LOCAL_NAME
8227 -- [, [External =>] EXTERNAL_SYMBOL]
8228 -- [, [Size =>] EXTERNAL_SYMBOL]);
8230 -- EXTERNAL_SYMBOL ::=
8232 -- | static_string_EXPRESSION
8234 when Pragma_Import_Object => Import_Object : declare
8235 Args : Args_List (1 .. 3);
8236 Names : constant Name_List (1 .. 3) := (
8241 Internal : Node_Id renames Args (1);
8242 External : Node_Id renames Args (2);
8243 Size : Node_Id renames Args (3);
8247 Gather_Associations (Names, Args);
8248 Process_Extended_Import_Export_Object_Pragma (
8249 Arg_Internal => Internal,
8250 Arg_External => External,
8254 ----------------------
8255 -- Import_Procedure --
8256 ----------------------
8258 -- pragma Import_Procedure (
8259 -- [Internal =>] LOCAL_NAME
8260 -- [, [External =>] EXTERNAL_SYMBOL]
8261 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8262 -- [, [Mechanism =>] MECHANISM]
8263 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8265 -- EXTERNAL_SYMBOL ::=
8267 -- | static_string_EXPRESSION
8269 -- PARAMETER_TYPES ::=
8271 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8273 -- TYPE_DESIGNATOR ::=
8275 -- | subtype_Name ' Access
8279 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8281 -- MECHANISM_ASSOCIATION ::=
8282 -- [formal_parameter_NAME =>] MECHANISM_NAME
8284 -- MECHANISM_NAME ::=
8287 -- | Descriptor [([Class =>] CLASS_NAME)]
8289 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8291 when Pragma_Import_Procedure => Import_Procedure : declare
8292 Args : Args_List (1 .. 5);
8293 Names : constant Name_List (1 .. 5) := (
8296 Name_Parameter_Types,
8298 Name_First_Optional_Parameter);
8300 Internal : Node_Id renames Args (1);
8301 External : Node_Id renames Args (2);
8302 Parameter_Types : Node_Id renames Args (3);
8303 Mechanism : Node_Id renames Args (4);
8304 First_Optional_Parameter : Node_Id renames Args (5);
8308 Gather_Associations (Names, Args);
8309 Process_Extended_Import_Export_Subprogram_Pragma (
8310 Arg_Internal => Internal,
8311 Arg_External => External,
8312 Arg_Parameter_Types => Parameter_Types,
8313 Arg_Mechanism => Mechanism,
8314 Arg_First_Optional_Parameter => First_Optional_Parameter);
8315 end Import_Procedure;
8317 -----------------------------
8318 -- Import_Valued_Procedure --
8319 -----------------------------
8321 -- pragma Import_Valued_Procedure (
8322 -- [Internal =>] LOCAL_NAME
8323 -- [, [External =>] EXTERNAL_SYMBOL]
8324 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8325 -- [, [Mechanism =>] MECHANISM]
8326 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8328 -- EXTERNAL_SYMBOL ::=
8330 -- | static_string_EXPRESSION
8332 -- PARAMETER_TYPES ::=
8334 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8336 -- TYPE_DESIGNATOR ::=
8338 -- | subtype_Name ' Access
8342 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8344 -- MECHANISM_ASSOCIATION ::=
8345 -- [formal_parameter_NAME =>] MECHANISM_NAME
8347 -- MECHANISM_NAME ::=
8350 -- | Descriptor [([Class =>] CLASS_NAME)]
8352 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8354 when Pragma_Import_Valued_Procedure =>
8355 Import_Valued_Procedure : declare
8356 Args : Args_List (1 .. 5);
8357 Names : constant Name_List (1 .. 5) := (
8360 Name_Parameter_Types,
8362 Name_First_Optional_Parameter);
8364 Internal : Node_Id renames Args (1);
8365 External : Node_Id renames Args (2);
8366 Parameter_Types : Node_Id renames Args (3);
8367 Mechanism : Node_Id renames Args (4);
8368 First_Optional_Parameter : Node_Id renames Args (5);
8372 Gather_Associations (Names, Args);
8373 Process_Extended_Import_Export_Subprogram_Pragma (
8374 Arg_Internal => Internal,
8375 Arg_External => External,
8376 Arg_Parameter_Types => Parameter_Types,
8377 Arg_Mechanism => Mechanism,
8378 Arg_First_Optional_Parameter => First_Optional_Parameter);
8379 end Import_Valued_Procedure;
8381 ------------------------
8382 -- Initialize_Scalars --
8383 ------------------------
8385 -- pragma Initialize_Scalars;
8387 when Pragma_Initialize_Scalars =>
8389 Check_Arg_Count (0);
8390 Check_Valid_Configuration_Pragma;
8391 Check_Restriction (No_Initialize_Scalars, N);
8393 -- Initialize_Scalars creates false positives in CodePeer,
8394 -- so ignore this pragma in this mode.
8396 if not Restriction_Active (No_Initialize_Scalars)
8397 and then not CodePeer_Mode
8399 Init_Or_Norm_Scalars := True;
8400 Initialize_Scalars := True;
8407 -- pragma Inline ( NAME {, NAME} );
8409 when Pragma_Inline =>
8411 -- Pragma is active if inlining option is active
8413 Process_Inline (Inline_Active);
8419 -- pragma Inline_Always ( NAME {, NAME} );
8421 when Pragma_Inline_Always =>
8424 -- Pragma always active unless in CodePeer mode, since this causes
8425 -- walk order issues.
8427 if not CodePeer_Mode then
8428 Process_Inline (True);
8431 --------------------
8432 -- Inline_Generic --
8433 --------------------
8435 -- pragma Inline_Generic (NAME {, NAME});
8437 when Pragma_Inline_Generic =>
8439 Process_Generic_List;
8441 ----------------------
8442 -- Inspection_Point --
8443 ----------------------
8445 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8447 when Pragma_Inspection_Point => Inspection_Point : declare
8452 if Arg_Count > 0 then
8455 Exp := Expression (Arg);
8458 if not Is_Entity_Name (Exp)
8459 or else not Is_Object (Entity (Exp))
8461 Error_Pragma_Arg ("object name required", Arg);
8468 end Inspection_Point;
8474 -- pragma Interface (
8475 -- [ Convention =>] convention_IDENTIFIER,
8476 -- [ Entity =>] local_NAME
8477 -- [, [External_Name =>] static_string_EXPRESSION ]
8478 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8480 when Pragma_Interface =>
8487 Check_At_Least_N_Arguments (2);
8488 Check_At_Most_N_Arguments (4);
8489 Process_Import_Or_Interface;
8491 -- In Ada 2005, the permission to use Interface (a reserved word)
8492 -- as a pragma name is considered an obsolescent feature.
8494 if Ada_Version >= Ada_2005 then
8496 (No_Obsolescent_Features, Pragma_Identifier (N));
8499 --------------------
8500 -- Interface_Name --
8501 --------------------
8503 -- pragma Interface_Name (
8504 -- [ Entity =>] local_NAME
8505 -- [,[External_Name =>] static_string_EXPRESSION ]
8506 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8508 when Pragma_Interface_Name => Interface_Name : declare
8517 ((Name_Entity, Name_External_Name, Name_Link_Name));
8518 Check_At_Least_N_Arguments (2);
8519 Check_At_Most_N_Arguments (3);
8520 Id := Expression (Arg1);
8523 if not Is_Entity_Name (Id) then
8525 ("first argument for pragma% must be entity name", Arg1);
8526 elsif Etype (Id) = Any_Type then
8529 Def_Id := Entity (Id);
8532 -- Special DEC-compatible processing for the object case, forces
8533 -- object to be imported.
8535 if Ekind (Def_Id) = E_Variable then
8536 Kill_Size_Check_Code (Def_Id);
8537 Note_Possible_Modification (Id, Sure => False);
8539 -- Initialization is not allowed for imported variable
8541 if Present (Expression (Parent (Def_Id)))
8542 and then Comes_From_Source (Expression (Parent (Def_Id)))
8544 Error_Msg_Sloc := Sloc (Def_Id);
8546 ("no initialization allowed for declaration of& #",
8550 -- For compatibility, support VADS usage of providing both
8551 -- pragmas Interface and Interface_Name to obtain the effect
8552 -- of a single Import pragma.
8554 if Is_Imported (Def_Id)
8555 and then Present (First_Rep_Item (Def_Id))
8556 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8558 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8562 Set_Imported (Def_Id);
8565 Set_Is_Public (Def_Id);
8566 Process_Interface_Name (Def_Id, Arg2, Arg3);
8569 -- Otherwise must be subprogram
8571 elsif not Is_Subprogram (Def_Id) then
8573 ("argument of pragma% is not subprogram", Arg1);
8576 Check_At_Most_N_Arguments (3);
8580 -- Loop through homonyms
8583 Def_Id := Get_Base_Subprogram (Hom_Id);
8585 if Is_Imported (Def_Id) then
8586 Process_Interface_Name (Def_Id, Arg2, Arg3);
8590 Hom_Id := Homonym (Hom_Id);
8592 exit when No (Hom_Id)
8593 or else Scope (Hom_Id) /= Current_Scope;
8598 ("argument of pragma% is not imported subprogram",
8604 -----------------------
8605 -- Interrupt_Handler --
8606 -----------------------
8608 -- pragma Interrupt_Handler (handler_NAME);
8610 when Pragma_Interrupt_Handler =>
8611 Check_Ada_83_Warning;
8612 Check_Arg_Count (1);
8613 Check_No_Identifiers;
8615 if No_Run_Time_Mode then
8616 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8618 Check_Interrupt_Or_Attach_Handler;
8619 Process_Interrupt_Or_Attach_Handler;
8622 ------------------------
8623 -- Interrupt_Priority --
8624 ------------------------
8626 -- pragma Interrupt_Priority [(EXPRESSION)];
8628 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8629 P : constant Node_Id := Parent (N);
8633 Check_Ada_83_Warning;
8635 if Arg_Count /= 0 then
8636 Arg := Expression (Arg1);
8637 Check_Arg_Count (1);
8638 Check_No_Identifiers;
8640 -- The expression must be analyzed in the special manner
8641 -- described in "Handling of Default and Per-Object
8642 -- Expressions" in sem.ads.
8644 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8647 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8651 elsif Has_Priority_Pragma (P) then
8652 Error_Pragma ("duplicate pragma% not allowed");
8655 Set_Has_Priority_Pragma (P, True);
8656 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8658 end Interrupt_Priority;
8660 ---------------------
8661 -- Interrupt_State --
8662 ---------------------
8664 -- pragma Interrupt_State (
8665 -- [Name =>] INTERRUPT_ID,
8666 -- [State =>] INTERRUPT_STATE);
8668 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8669 -- INTERRUPT_STATE => System | Runtime | User
8671 -- Note: if the interrupt id is given as an identifier, then it must
8672 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8673 -- given as a static integer expression which must be in the range of
8674 -- Ada.Interrupts.Interrupt_ID.
8676 when Pragma_Interrupt_State => Interrupt_State : declare
8678 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8679 -- This is the entity Ada.Interrupts.Interrupt_ID;
8681 State_Type : Character;
8682 -- Set to 's'/'r'/'u' for System/Runtime/User
8685 -- Index to entry in Interrupt_States table
8688 -- Value of interrupt
8690 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8691 -- The first argument to the pragma
8693 Int_Ent : Entity_Id;
8694 -- Interrupt entity in Ada.Interrupts.Names
8698 Check_Arg_Order ((Name_Name, Name_State));
8699 Check_Arg_Count (2);
8701 Check_Optional_Identifier (Arg1, Name_Name);
8702 Check_Optional_Identifier (Arg2, Name_State);
8703 Check_Arg_Is_Identifier (Arg2);
8705 -- First argument is identifier
8707 if Nkind (Arg1X) = N_Identifier then
8709 -- Search list of names in Ada.Interrupts.Names
8711 Int_Ent := First_Entity (RTE (RE_Names));
8713 if No (Int_Ent) then
8714 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8716 elsif Chars (Int_Ent) = Chars (Arg1X) then
8717 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8721 Next_Entity (Int_Ent);
8724 -- First argument is not an identifier, so it must be a static
8725 -- expression of type Ada.Interrupts.Interrupt_ID.
8728 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8729 Int_Val := Expr_Value (Arg1X);
8731 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8733 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8736 ("value not in range of type " &
8737 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8743 case Chars (Get_Pragma_Arg (Arg2)) is
8744 when Name_Runtime => State_Type := 'r';
8745 when Name_System => State_Type := 's';
8746 when Name_User => State_Type := 'u';
8749 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8752 -- Check if entry is already stored
8754 IST_Num := Interrupt_States.First;
8756 -- If entry not found, add it
8758 if IST_Num > Interrupt_States.Last then
8759 Interrupt_States.Append
8760 ((Interrupt_Number => UI_To_Int (Int_Val),
8761 Interrupt_State => State_Type,
8762 Pragma_Loc => Loc));
8765 -- Case of entry for the same entry
8767 elsif Int_Val = Interrupt_States.Table (IST_Num).
8770 -- If state matches, done, no need to make redundant entry
8773 State_Type = Interrupt_States.Table (IST_Num).
8776 -- Otherwise if state does not match, error
8779 Interrupt_States.Table (IST_Num).Pragma_Loc;
8781 ("state conflicts with that given #", Arg2);
8785 IST_Num := IST_Num + 1;
8787 end Interrupt_State;
8789 ----------------------
8790 -- Java_Constructor --
8791 ----------------------
8793 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8795 -- Also handles pragma CIL_Constructor
8797 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8798 Java_Constructor : declare
8802 Convention : Convention_Id;
8806 Check_Arg_Count (1);
8807 Check_Optional_Identifier (Arg1, Name_Entity);
8808 Check_Arg_Is_Local_Name (Arg1);
8810 Id := Expression (Arg1);
8811 Find_Program_Unit_Name (Id);
8813 -- If we did not find the name, we are done
8815 if Etype (Id) = Any_Type then
8820 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8821 when Pragma_Java_Constructor => Convention := Convention_Java;
8822 when others => null;
8825 Hom_Id := Entity (Id);
8827 -- Loop through homonyms
8830 Def_Id := Get_Base_Subprogram (Hom_Id);
8832 -- The constructor is required to be a function returning an
8833 -- access type whose designated type has convention Java/CIL.
8835 if Ekind (Def_Id) = E_Function
8837 (Is_Value_Type (Etype (Def_Id))
8839 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8841 Atree.Convention (Etype (Def_Id)) = Convention)
8843 (Ekind (Etype (Def_Id)) in Access_Kind
8846 (Designated_Type (Etype (Def_Id))) = Convention
8849 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8852 Set_Is_Constructor (Def_Id);
8853 Set_Convention (Def_Id, Convention);
8854 Set_Is_Imported (Def_Id);
8857 if Convention = Convention_Java then
8859 ("pragma% requires function returning a " &
8860 "'Java access type", Arg1);
8862 pragma Assert (Convention = Convention_CIL);
8864 ("pragma% requires function returning a " &
8865 "'C'I'L access type", Arg1);
8869 Hom_Id := Homonym (Hom_Id);
8871 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8873 end Java_Constructor;
8875 ----------------------
8876 -- Java_Interface --
8877 ----------------------
8879 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8881 when Pragma_Java_Interface => Java_Interface : declare
8887 Check_Arg_Count (1);
8888 Check_Optional_Identifier (Arg1, Name_Entity);
8889 Check_Arg_Is_Local_Name (Arg1);
8891 Arg := Expression (Arg1);
8894 if Etype (Arg) = Any_Type then
8898 if not Is_Entity_Name (Arg)
8899 or else not Is_Type (Entity (Arg))
8901 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8904 Typ := Underlying_Type (Entity (Arg));
8906 -- For now simply check some of the semantic constraints on the
8907 -- type. This currently leaves out some restrictions on interface
8908 -- types, namely that the parent type must be java.lang.Object.Typ
8909 -- and that all primitives of the type should be declared
8912 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8913 Error_Pragma_Arg ("pragma% requires an abstract "
8914 & "tagged type", Arg1);
8916 elsif not Has_Discriminants (Typ)
8917 or else Ekind (Etype (First_Discriminant (Typ)))
8918 /= E_Anonymous_Access_Type
8920 not Is_Class_Wide_Type
8921 (Designated_Type (Etype (First_Discriminant (Typ))))
8924 ("type must have a class-wide access discriminant", Arg1);
8932 -- pragma Keep_Names ([On => ] local_NAME);
8934 when Pragma_Keep_Names => Keep_Names : declare
8939 Check_Arg_Count (1);
8940 Check_Optional_Identifier (Arg1, Name_On);
8941 Check_Arg_Is_Local_Name (Arg1);
8943 Arg := Expression (Arg1);
8946 if Etype (Arg) = Any_Type then
8950 if not Is_Entity_Name (Arg)
8951 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8954 ("pragma% requires a local enumeration type", Arg1);
8957 Set_Discard_Names (Entity (Arg), False);
8964 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8966 when Pragma_License =>
8968 Check_Arg_Count (1);
8969 Check_No_Identifiers;
8970 Check_Valid_Configuration_Pragma;
8971 Check_Arg_Is_Identifier (Arg1);
8974 Sind : constant Source_File_Index :=
8975 Source_Index (Current_Sem_Unit);
8978 case Chars (Get_Pragma_Arg (Arg1)) is
8980 Set_License (Sind, GPL);
8982 when Name_Modified_GPL =>
8983 Set_License (Sind, Modified_GPL);
8985 when Name_Restricted =>
8986 Set_License (Sind, Restricted);
8988 when Name_Unrestricted =>
8989 Set_License (Sind, Unrestricted);
8992 Error_Pragma_Arg ("invalid license name", Arg1);
9000 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
9002 when Pragma_Link_With => Link_With : declare
9008 if Operating_Mode = Generate_Code
9009 and then In_Extended_Main_Source_Unit (N)
9011 Check_At_Least_N_Arguments (1);
9012 Check_No_Identifiers;
9013 Check_Is_In_Decl_Part_Or_Package_Spec;
9014 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9018 while Present (Arg) loop
9019 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9021 -- Store argument, converting sequences of spaces to a
9022 -- single null character (this is one of the differences
9023 -- in processing between Link_With and Linker_Options).
9026 C : constant Char_Code := Get_Char_Code (' ');
9027 S : constant String_Id :=
9028 Strval (Expr_Value_S (Expression (Arg)));
9029 L : constant Nat := String_Length (S);
9032 procedure Skip_Spaces;
9033 -- Advance F past any spaces
9039 procedure Skip_Spaces is
9041 while F <= L and then Get_String_Char (S, F) = C loop
9046 -- Start of processing for Arg_Store
9049 Skip_Spaces; -- skip leading spaces
9051 -- Loop through characters, changing any embedded
9052 -- sequence of spaces to a single null character (this
9053 -- is how Link_With/Linker_Options differ)
9056 if Get_String_Char (S, F) = C then
9059 Store_String_Char (ASCII.NUL);
9062 Store_String_Char (Get_String_Char (S, F));
9070 if Present (Arg) then
9071 Store_String_Char (ASCII.NUL);
9075 Store_Linker_Option_String (End_String);
9083 -- pragma Linker_Alias (
9084 -- [Entity =>] LOCAL_NAME
9085 -- [Target =>] static_string_EXPRESSION);
9087 when Pragma_Linker_Alias =>
9089 Check_Arg_Order ((Name_Entity, Name_Target));
9090 Check_Arg_Count (2);
9091 Check_Optional_Identifier (Arg1, Name_Entity);
9092 Check_Optional_Identifier (Arg2, Name_Target);
9093 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9094 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9096 -- The only processing required is to link this item on to the
9097 -- list of rep items for the given entity. This is accomplished
9098 -- by the call to Rep_Item_Too_Late (when no error is detected
9099 -- and False is returned).
9101 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9104 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9107 ------------------------
9108 -- Linker_Constructor --
9109 ------------------------
9111 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
9113 -- Code is shared with Linker_Destructor
9115 -----------------------
9116 -- Linker_Destructor --
9117 -----------------------
9119 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
9121 when Pragma_Linker_Constructor |
9122 Pragma_Linker_Destructor =>
9123 Linker_Constructor : declare
9129 Check_Arg_Count (1);
9130 Check_No_Identifiers;
9131 Check_Arg_Is_Local_Name (Arg1);
9132 Arg1_X := Expression (Arg1);
9134 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9136 if not Is_Library_Level_Entity (Proc) then
9138 ("argument for pragma% must be library level entity", Arg1);
9141 -- The only processing required is to link this item on to the
9142 -- list of rep items for the given entity. This is accomplished
9143 -- by the call to Rep_Item_Too_Late (when no error is detected
9144 -- and False is returned).
9146 if Rep_Item_Too_Late (Proc, N) then
9149 Set_Has_Gigi_Rep_Item (Proc);
9151 end Linker_Constructor;
9153 --------------------
9154 -- Linker_Options --
9155 --------------------
9157 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9159 when Pragma_Linker_Options => Linker_Options : declare
9163 Check_Ada_83_Warning;
9164 Check_No_Identifiers;
9165 Check_Arg_Count (1);
9166 Check_Is_In_Decl_Part_Or_Package_Spec;
9167 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9168 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
9171 while Present (Arg) loop
9172 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9173 Store_String_Char (ASCII.NUL);
9174 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
9178 if Operating_Mode = Generate_Code
9179 and then In_Extended_Main_Source_Unit (N)
9181 Store_Linker_Option_String (End_String);
9185 --------------------
9186 -- Linker_Section --
9187 --------------------
9189 -- pragma Linker_Section (
9190 -- [Entity =>] LOCAL_NAME
9191 -- [Section =>] static_string_EXPRESSION);
9193 when Pragma_Linker_Section =>
9195 Check_Arg_Order ((Name_Entity, Name_Section));
9196 Check_Arg_Count (2);
9197 Check_Optional_Identifier (Arg1, Name_Entity);
9198 Check_Optional_Identifier (Arg2, Name_Section);
9199 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9200 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9202 -- This pragma applies only to objects
9204 if not Is_Object (Entity (Expression (Arg1))) then
9205 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9208 -- The only processing required is to link this item on to the
9209 -- list of rep items for the given entity. This is accomplished
9210 -- by the call to Rep_Item_Too_Late (when no error is detected
9211 -- and False is returned).
9213 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9216 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9223 -- pragma List (On | Off)
9225 -- There is nothing to do here, since we did all the processing for
9226 -- this pragma in Par.Prag (so that it works properly even in syntax
9232 --------------------
9233 -- Locking_Policy --
9234 --------------------
9236 -- pragma Locking_Policy (policy_IDENTIFIER);
9238 when Pragma_Locking_Policy => declare
9242 Check_Ada_83_Warning;
9243 Check_Arg_Count (1);
9244 Check_No_Identifiers;
9245 Check_Arg_Is_Locking_Policy (Arg1);
9246 Check_Valid_Configuration_Pragma;
9247 Get_Name_String (Chars (Expression (Arg1)));
9248 LP := Fold_Upper (Name_Buffer (1));
9250 if Locking_Policy /= ' '
9251 and then Locking_Policy /= LP
9253 Error_Msg_Sloc := Locking_Policy_Sloc;
9254 Error_Pragma ("locking policy incompatible with policy#");
9256 -- Set new policy, but always preserve System_Location since we
9257 -- like the error message with the run time name.
9260 Locking_Policy := LP;
9262 if Locking_Policy_Sloc /= System_Location then
9263 Locking_Policy_Sloc := Loc;
9272 -- pragma Long_Float (D_Float | G_Float);
9274 when Pragma_Long_Float =>
9276 Check_Valid_Configuration_Pragma;
9277 Check_Arg_Count (1);
9278 Check_No_Identifier (Arg1);
9279 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9281 if not OpenVMS_On_Target then
9282 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9287 if Chars (Expression (Arg1)) = Name_D_Float then
9288 if Opt.Float_Format_Long = 'G' then
9289 Error_Pragma ("G_Float previously specified");
9292 Opt.Float_Format_Long := 'D';
9294 -- G_Float case (this is the default, does not need overriding)
9297 if Opt.Float_Format_Long = 'D' then
9298 Error_Pragma ("D_Float previously specified");
9301 Opt.Float_Format_Long := 'G';
9304 Set_Standard_Fpt_Formats;
9306 -----------------------
9307 -- Machine_Attribute --
9308 -----------------------
9310 -- pragma Machine_Attribute (
9311 -- [Entity =>] LOCAL_NAME,
9312 -- [Attribute_Name =>] static_string_EXPRESSION
9313 -- [, [Info =>] static_EXPRESSION] );
9315 when Pragma_Machine_Attribute => Machine_Attribute : declare
9320 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9322 if Arg_Count = 3 then
9323 Check_Optional_Identifier (Arg3, Name_Info);
9324 Check_Arg_Is_Static_Expression (Arg3);
9326 Check_Arg_Count (2);
9329 Check_Optional_Identifier (Arg1, Name_Entity);
9330 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9331 Check_Arg_Is_Local_Name (Arg1);
9332 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9333 Def_Id := Entity (Expression (Arg1));
9335 if Is_Access_Type (Def_Id) then
9336 Def_Id := Designated_Type (Def_Id);
9339 if Rep_Item_Too_Early (Def_Id, N) then
9343 Def_Id := Underlying_Type (Def_Id);
9345 -- The only processing required is to link this item on to the
9346 -- list of rep items for the given entity. This is accomplished
9347 -- by the call to Rep_Item_Too_Late (when no error is detected
9348 -- and False is returned).
9350 if Rep_Item_Too_Late (Def_Id, N) then
9353 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9355 end Machine_Attribute;
9362 -- (MAIN_OPTION [, MAIN_OPTION]);
9365 -- [STACK_SIZE =>] static_integer_EXPRESSION
9366 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9367 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
9369 when Pragma_Main => Main : declare
9370 Args : Args_List (1 .. 3);
9371 Names : constant Name_List (1 .. 3) := (
9373 Name_Task_Stack_Size_Default,
9374 Name_Time_Slicing_Enabled);
9380 Gather_Associations (Names, Args);
9382 for J in 1 .. 2 loop
9383 if Present (Args (J)) then
9384 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9388 if Present (Args (3)) then
9389 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9393 while Present (Nod) loop
9394 if Nkind (Nod) = N_Pragma
9395 and then Pragma_Name (Nod) = Name_Main
9397 Error_Msg_Name_1 := Pname;
9398 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9409 -- pragma Main_Storage
9410 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9412 -- MAIN_STORAGE_OPTION ::=
9413 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9414 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9416 when Pragma_Main_Storage => Main_Storage : declare
9417 Args : Args_List (1 .. 2);
9418 Names : constant Name_List (1 .. 2) := (
9419 Name_Working_Storage,
9426 Gather_Associations (Names, Args);
9428 for J in 1 .. 2 loop
9429 if Present (Args (J)) then
9430 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9434 Check_In_Main_Program;
9437 while Present (Nod) loop
9438 if Nkind (Nod) = N_Pragma
9439 and then Pragma_Name (Nod) = Name_Main_Storage
9441 Error_Msg_Name_1 := Pname;
9442 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9453 -- pragma Memory_Size (NUMERIC_LITERAL)
9455 when Pragma_Memory_Size =>
9458 -- Memory size is simply ignored
9460 Check_No_Identifiers;
9461 Check_Arg_Count (1);
9462 Check_Arg_Is_Integer_Literal (Arg1);
9470 -- The only correct use of this pragma is on its own in a file, in
9471 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9472 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9473 -- check for a file containing nothing but a No_Body pragma). If we
9474 -- attempt to process it during normal semantics processing, it means
9475 -- it was misplaced.
9477 when Pragma_No_Body =>
9485 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9487 when Pragma_No_Return => No_Return : declare
9495 Check_At_Least_N_Arguments (1);
9497 -- Loop through arguments of pragma
9500 while Present (Arg) loop
9501 Check_Arg_Is_Local_Name (Arg);
9502 Id := Expression (Arg);
9505 if not Is_Entity_Name (Id) then
9506 Error_Pragma_Arg ("entity name required", Arg);
9509 if Etype (Id) = Any_Type then
9513 -- Loop to find matching procedures
9518 and then Scope (E) = Current_Scope
9520 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
9523 -- Set flag on any alias as well
9525 if Is_Overloadable (E) and then Present (Alias (E)) then
9526 Set_No_Return (Alias (E));
9536 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9547 -- pragma No_Run_Time;
9549 -- Note: this pragma is retained for backwards compatibility. See
9550 -- body of Rtsfind for full details on its handling.
9552 when Pragma_No_Run_Time =>
9554 Check_Valid_Configuration_Pragma;
9555 Check_Arg_Count (0);
9557 No_Run_Time_Mode := True;
9558 Configurable_Run_Time_Mode := True;
9560 -- Set Duration to 32 bits if word size is 32
9562 if Ttypes.System_Word_Size = 32 then
9563 Duration_32_Bits_On_Target := True;
9566 -- Set appropriate restrictions
9568 Set_Restriction (No_Finalization, N);
9569 Set_Restriction (No_Exception_Handlers, N);
9570 Set_Restriction (Max_Tasks, N, 0);
9571 Set_Restriction (No_Tasking, N);
9573 ------------------------
9574 -- No_Strict_Aliasing --
9575 ------------------------
9577 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9579 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9584 Check_At_Most_N_Arguments (1);
9586 if Arg_Count = 0 then
9587 Check_Valid_Configuration_Pragma;
9588 Opt.No_Strict_Aliasing := True;
9591 Check_Optional_Identifier (Arg2, Name_Entity);
9592 Check_Arg_Is_Local_Name (Arg1);
9593 E_Id := Entity (Expression (Arg1));
9595 if E_Id = Any_Type then
9597 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9598 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9601 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9603 end No_Strict_Aliasing;
9605 -----------------------
9606 -- Normalize_Scalars --
9607 -----------------------
9609 -- pragma Normalize_Scalars;
9611 when Pragma_Normalize_Scalars =>
9612 Check_Ada_83_Warning;
9613 Check_Arg_Count (0);
9614 Check_Valid_Configuration_Pragma;
9616 -- Normalize_Scalars creates false positives in CodePeer, so
9617 -- ignore this pragma in this mode.
9619 if not CodePeer_Mode then
9620 Normalize_Scalars := True;
9621 Init_Or_Norm_Scalars := True;
9628 -- pragma Obsolescent;
9630 -- pragma Obsolescent (
9631 -- [Message =>] static_string_EXPRESSION
9632 -- [,[Version =>] Ada_05]]);
9634 -- pragma Obsolescent (
9636 -- [,[Message =>] static_string_EXPRESSION
9637 -- [,[Version =>] Ada_05]] );
9639 when Pragma_Obsolescent => Obsolescent : declare
9643 procedure Set_Obsolescent (E : Entity_Id);
9644 -- Given an entity Ent, mark it as obsolescent if appropriate
9646 ---------------------
9647 -- Set_Obsolescent --
9648 ---------------------
9650 procedure Set_Obsolescent (E : Entity_Id) is
9659 -- Entity name was given
9661 if Present (Ename) then
9663 -- If entity name matches, we are fine. Save entity in
9664 -- pragma argument, for ASIS use.
9666 if Chars (Ename) = Chars (Ent) then
9667 Set_Entity (Ename, Ent);
9668 Generate_Reference (Ent, Ename);
9670 -- If entity name does not match, only possibility is an
9671 -- enumeration literal from an enumeration type declaration.
9673 elsif Ekind (Ent) /= E_Enumeration_Type then
9675 ("pragma % entity name does not match declaration");
9678 Ent := First_Literal (E);
9682 ("pragma % entity name does not match any " &
9683 "enumeration literal");
9685 elsif Chars (Ent) = Chars (Ename) then
9686 Set_Entity (Ename, Ent);
9687 Generate_Reference (Ent, Ename);
9691 Ent := Next_Literal (Ent);
9697 -- Ent points to entity to be marked
9699 if Arg_Count >= 1 then
9701 -- Deal with static string argument
9703 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9704 S := Strval (Expression (Arg1));
9706 for J in 1 .. String_Length (S) loop
9707 if not In_Character_Range (Get_String_Char (S, J)) then
9709 ("pragma% argument does not allow wide characters",
9714 Obsolescent_Warnings.Append
9715 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9717 -- Check for Ada_05 parameter
9719 if Arg_Count /= 1 then
9720 Check_Arg_Count (2);
9723 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9726 Check_Arg_Is_Identifier (Argx);
9728 if Chars (Argx) /= Name_Ada_05 then
9729 Error_Msg_Name_2 := Name_Ada_05;
9731 ("only allowed argument for pragma% is %", Argx);
9734 if Ada_Version_Explicit < Ada_05
9735 or else not Warn_On_Ada_2005_Compatibility
9743 -- Set flag if pragma active
9746 Set_Is_Obsolescent (Ent);
9750 end Set_Obsolescent;
9752 -- Start of processing for pragma Obsolescent
9757 Check_At_Most_N_Arguments (3);
9759 -- See if first argument specifies an entity name
9763 (Chars (Arg1) = Name_Entity
9765 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9769 Ename := Get_Pragma_Arg (Arg1);
9771 -- Eliminate first argument, so we can share processing
9775 Arg_Count := Arg_Count - 1;
9777 -- No Entity name argument given
9783 if Arg_Count >= 1 then
9784 Check_Optional_Identifier (Arg1, Name_Message);
9786 if Arg_Count = 2 then
9787 Check_Optional_Identifier (Arg2, Name_Version);
9791 -- Get immediately preceding declaration
9794 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9798 -- Cases where we do not follow anything other than another pragma
9802 -- First case: library level compilation unit declaration with
9803 -- the pragma immediately following the declaration.
9805 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9807 (Defining_Entity (Unit (Parent (Parent (N)))));
9810 -- Case 2: library unit placement for package
9814 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9816 if Is_Package_Or_Generic_Package (Ent) then
9817 Set_Obsolescent (Ent);
9823 -- Cases where we must follow a declaration
9826 if Nkind (Decl) not in N_Declaration
9827 and then Nkind (Decl) not in N_Later_Decl_Item
9828 and then Nkind (Decl) not in N_Generic_Declaration
9829 and then Nkind (Decl) not in N_Renaming_Declaration
9832 ("pragma% misplaced, "
9833 & "must immediately follow a declaration");
9836 Set_Obsolescent (Defining_Entity (Decl));
9846 -- pragma Optimize (Time | Space | Off);
9848 -- The actual check for optimize is done in Gigi. Note that this
9849 -- pragma does not actually change the optimization setting, it
9850 -- simply checks that it is consistent with the pragma.
9852 when Pragma_Optimize =>
9853 Check_No_Identifiers;
9854 Check_Arg_Count (1);
9855 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9857 ------------------------
9858 -- Optimize_Alignment --
9859 ------------------------
9861 -- pragma Optimize_Alignment (Time | Space | Off);
9863 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
9865 Check_No_Identifiers;
9866 Check_Arg_Count (1);
9867 Check_Valid_Configuration_Pragma;
9870 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9874 Opt.Optimize_Alignment := 'T';
9876 Opt.Optimize_Alignment := 'S';
9878 Opt.Optimize_Alignment := 'O';
9880 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9884 -- Set indication that mode is set locally. If we are in fact in a
9885 -- configuration pragma file, this setting is harmless since the
9886 -- switch will get reset anyway at the start of each unit.
9888 Optimize_Alignment_Local := True;
9889 end Optimize_Alignment;
9895 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
9897 when Pragma_Ordered => Ordered : declare
9898 Assoc : constant Node_Id := Arg1;
9904 Check_No_Identifiers;
9905 Check_Arg_Count (1);
9906 Check_Arg_Is_Local_Name (Arg1);
9908 Type_Id := Expression (Assoc);
9909 Find_Type (Type_Id);
9910 Typ := Entity (Type_Id);
9912 if Typ = Any_Type then
9915 Typ := Underlying_Type (Typ);
9918 if not Is_Enumeration_Type (Typ) then
9919 Error_Pragma ("pragma% must specify enumeration type");
9922 Check_First_Subtype (Arg1);
9923 Set_Has_Pragma_Ordered (Base_Type (Typ));
9930 -- pragma Pack (first_subtype_LOCAL_NAME);
9932 when Pragma_Pack => Pack : declare
9933 Assoc : constant Node_Id := Arg1;
9937 Ignore : Boolean := False;
9940 Check_No_Identifiers;
9941 Check_Arg_Count (1);
9942 Check_Arg_Is_Local_Name (Arg1);
9944 Type_Id := Expression (Assoc);
9945 Find_Type (Type_Id);
9946 Typ := Entity (Type_Id);
9949 or else Rep_Item_Too_Early (Typ, N)
9953 Typ := Underlying_Type (Typ);
9956 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9957 Error_Pragma ("pragma% must specify array or record type");
9960 Check_First_Subtype (Arg1);
9962 if Has_Pragma_Pack (Typ) then
9963 Error_Pragma ("duplicate pragma%, only one allowed");
9967 elsif Is_Array_Type (Typ) then
9968 Ctyp := Component_Type (Typ);
9970 -- Ignore pack that does nothing
9972 if Known_Static_Esize (Ctyp)
9973 and then Known_Static_RM_Size (Ctyp)
9974 and then Esize (Ctyp) = RM_Size (Ctyp)
9975 and then Addressable (Esize (Ctyp))
9980 -- Process OK pragma Pack. Note that if there is a separate
9981 -- component clause present, the Pack will be cancelled. This
9982 -- processing is in Freeze.
9984 if not Rep_Item_Too_Late (Typ, N) then
9986 -- In the context of static code analysis, we do not need
9987 -- complex front-end expansions related to pragma Pack,
9988 -- so disable handling of pragma Pack in this case.
9990 if CodePeer_Mode then
9993 -- For normal non-VM target, do the packing
9995 elsif VM_Target = No_VM then
9997 Set_Is_Packed (Base_Type (Typ));
9998 Set_Has_Non_Standard_Rep (Base_Type (Typ));
10001 Set_Has_Pragma_Pack (Base_Type (Typ));
10003 -- If we ignore the pack for VM_Targets, then warn about
10004 -- this, except suppress the warning in GNAT mode.
10006 elsif not GNAT_Mode then
10008 ("?pragma% ignored in this configuration");
10012 -- For record types, the pack is always effective
10014 else pragma Assert (Is_Record_Type (Typ));
10015 if not Rep_Item_Too_Late (Typ, N) then
10016 if VM_Target = No_VM then
10017 Set_Is_Packed (Base_Type (Typ));
10018 Set_Has_Pragma_Pack (Base_Type (Typ));
10019 Set_Has_Non_Standard_Rep (Base_Type (Typ));
10021 elsif not GNAT_Mode then
10022 Error_Pragma ("?pragma% ignored in this configuration");
10034 -- There is nothing to do here, since we did all the processing for
10035 -- this pragma in Par.Prag (so that it works properly even in syntax
10038 when Pragma_Page =>
10045 -- pragma Passive [(PASSIVE_FORM)];
10047 -- PASSIVE_FORM ::= Semaphore | No
10049 when Pragma_Passive =>
10052 if Nkind (Parent (N)) /= N_Task_Definition then
10053 Error_Pragma ("pragma% must be within task definition");
10056 if Arg_Count /= 0 then
10057 Check_Arg_Count (1);
10058 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
10061 ----------------------------------
10062 -- Preelaborable_Initialization --
10063 ----------------------------------
10065 -- pragma Preelaborable_Initialization (DIRECT_NAME);
10067 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
10072 Check_Arg_Count (1);
10073 Check_No_Identifiers;
10074 Check_Arg_Is_Identifier (Arg1);
10075 Check_Arg_Is_Local_Name (Arg1);
10076 Check_First_Subtype (Arg1);
10077 Ent := Entity (Expression (Arg1));
10079 if not Is_Private_Type (Ent)
10080 and then not Is_Protected_Type (Ent)
10083 ("pragma % can only be applied to private or protected type",
10087 -- Give an error if the pragma is applied to a protected type that
10088 -- does not qualify (due to having entries, or due to components
10089 -- that do not qualify).
10091 if Is_Protected_Type (Ent)
10092 and then not Has_Preelaborable_Initialization (Ent)
10095 ("protected type & does not have preelaborable " &
10096 "initialization", Ent);
10098 -- Otherwise mark the type as definitely having preelaborable
10102 Set_Known_To_Have_Preelab_Init (Ent);
10105 if Has_Pragma_Preelab_Init (Ent)
10106 and then Warn_On_Redundant_Constructs
10108 Error_Pragma ("?duplicate pragma%!");
10110 Set_Has_Pragma_Preelab_Init (Ent);
10114 --------------------
10115 -- Persistent_BSS --
10116 --------------------
10118 when Pragma_Persistent_BSS => Persistent_BSS : declare
10125 Check_At_Most_N_Arguments (1);
10127 -- Case of application to specific object (one argument)
10129 if Arg_Count = 1 then
10130 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10132 if not Is_Entity_Name (Expression (Arg1))
10134 (Ekind (Entity (Expression (Arg1))) /= E_Variable
10135 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
10137 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10140 Ent := Entity (Expression (Arg1));
10141 Decl := Parent (Ent);
10143 if Rep_Item_Too_Late (Ent, N) then
10147 if Present (Expression (Decl)) then
10149 ("object for pragma% cannot have initialization", Arg1);
10152 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10154 ("object type for pragma% is not potentially persistent",
10159 Make_Linker_Section_Pragma
10160 (Ent, Sloc (N), ".persistent.bss");
10161 Insert_After (N, Prag);
10164 -- Case of use as configuration pragma with no arguments
10167 Check_Valid_Configuration_Pragma;
10168 Persistent_BSS_Mode := True;
10170 end Persistent_BSS;
10176 -- pragma Polling (ON | OFF);
10178 when Pragma_Polling =>
10180 Check_Arg_Count (1);
10181 Check_No_Identifiers;
10182 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10183 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
10185 -------------------
10186 -- Postcondition --
10187 -------------------
10189 -- pragma Postcondition ([Check =>] Boolean_Expression
10190 -- [,[Message =>] String_Expression]);
10192 when Pragma_Postcondition => Postcondition : declare
10194 pragma Warnings (Off, In_Body);
10198 Check_At_Least_N_Arguments (1);
10199 Check_At_Most_N_Arguments (2);
10200 Check_Optional_Identifier (Arg1, Name_Check);
10202 -- All we need to do here is call the common check procedure,
10203 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10205 Check_Precondition_Postcondition (In_Body);
10212 -- pragma Precondition ([Check =>] Boolean_Expression
10213 -- [,[Message =>] String_Expression]);
10215 when Pragma_Precondition => Precondition : declare
10220 Check_At_Least_N_Arguments (1);
10221 Check_At_Most_N_Arguments (2);
10222 Check_Optional_Identifier (Arg1, Name_Check);
10224 Check_Precondition_Postcondition (In_Body);
10226 -- If in spec, nothing more to do. If in body, then we convert the
10227 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
10228 -- this whether or not precondition checks are enabled. That works
10229 -- fine since pragma Check will do this check, and will also
10230 -- analyze the condition itself in the proper context.
10233 if Arg_Count = 2 then
10234 Check_Optional_Identifier (Arg3, Name_Message);
10235 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10240 Chars => Name_Check,
10241 Pragma_Argument_Associations => New_List (
10242 Make_Pragma_Argument_Association (Loc,
10244 Make_Identifier (Loc,
10245 Chars => Name_Precondition)),
10247 Make_Pragma_Argument_Association (Sloc (Arg1),
10248 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10250 if Arg_Count = 2 then
10251 Append_To (Pragma_Argument_Associations (N),
10252 Make_Pragma_Argument_Association (Sloc (Arg2),
10253 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10264 -- pragma Preelaborate [(library_unit_NAME)];
10266 -- Set the flag Is_Preelaborated of program unit name entity
10268 when Pragma_Preelaborate => Preelaborate : declare
10269 Pa : constant Node_Id := Parent (N);
10270 Pk : constant Node_Kind := Nkind (Pa);
10274 Check_Ada_83_Warning;
10275 Check_Valid_Library_Unit_Pragma;
10277 if Nkind (N) = N_Null_Statement then
10281 Ent := Find_Lib_Unit_Name;
10283 -- This filters out pragmas inside generic parent then
10284 -- show up inside instantiation
10287 and then not (Pk = N_Package_Specification
10288 and then Present (Generic_Parent (Pa)))
10290 if not Debug_Flag_U then
10291 Set_Is_Preelaborated (Ent);
10292 Set_Suppress_Elaboration_Warnings (Ent);
10297 ---------------------
10298 -- Preelaborate_05 --
10299 ---------------------
10301 -- pragma Preelaborate_05 [(library_unit_NAME)];
10303 -- This pragma is useable only in GNAT_Mode, where it is used like
10304 -- pragma Preelaborate but it is only effective in Ada 2005 mode
10305 -- (otherwise it is ignored). This is used to implement AI-362 which
10306 -- recategorizes some run-time packages in Ada 2005 mode.
10308 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10313 Check_Valid_Library_Unit_Pragma;
10315 if not GNAT_Mode then
10316 Error_Pragma ("pragma% only available in GNAT mode");
10319 if Nkind (N) = N_Null_Statement then
10323 -- This is one of the few cases where we need to test the value of
10324 -- Ada_Version_Explicit rather than Ada_Version (which is always
10325 -- set to Ada_12 in a predefined unit), we need to know the
10326 -- explicit version set to know if this pragma is active.
10328 if Ada_Version_Explicit >= Ada_05 then
10329 Ent := Find_Lib_Unit_Name;
10330 Set_Is_Preelaborated (Ent);
10331 Set_Suppress_Elaboration_Warnings (Ent);
10333 end Preelaborate_05;
10339 -- pragma Priority (EXPRESSION);
10341 when Pragma_Priority => Priority : declare
10342 P : constant Node_Id := Parent (N);
10346 Check_No_Identifiers;
10347 Check_Arg_Count (1);
10351 if Nkind (P) = N_Subprogram_Body then
10352 Check_In_Main_Program;
10354 Arg := Expression (Arg1);
10355 Analyze_And_Resolve (Arg, Standard_Integer);
10359 if not Is_Static_Expression (Arg) then
10360 Flag_Non_Static_Expr
10361 ("main subprogram priority is not static!", Arg);
10364 -- If constraint error, then we already signalled an error
10366 elsif Raises_Constraint_Error (Arg) then
10369 -- Otherwise check in range
10373 Val : constant Uint := Expr_Value (Arg);
10377 or else Val > Expr_Value (Expression
10378 (Parent (RTE (RE_Max_Priority))))
10381 ("main subprogram priority is out of range", Arg1);
10387 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10389 -- Load an arbitrary entity from System.Tasking to make sure
10390 -- this package is implicitly with'ed, since we need to have
10391 -- the tasking run-time active for the pragma Priority to have
10395 Discard : Entity_Id;
10396 pragma Warnings (Off, Discard);
10398 Discard := RTE (RE_Task_List);
10401 -- Task or Protected, must be of type Integer
10403 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10404 Arg := Expression (Arg1);
10406 -- The expression must be analyzed in the special manner
10407 -- described in "Handling of Default and Per-Object
10408 -- Expressions" in sem.ads.
10410 Preanalyze_Spec_Expression (Arg, Standard_Integer);
10412 if not Is_Static_Expression (Arg) then
10413 Check_Restriction (Static_Priorities, Arg);
10416 -- Anything else is incorrect
10422 if Has_Priority_Pragma (P) then
10423 Error_Pragma ("duplicate pragma% not allowed");
10425 Set_Has_Priority_Pragma (P, True);
10427 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10428 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10429 -- exp_ch9 should use this ???
10434 -----------------------------------
10435 -- Priority_Specific_Dispatching --
10436 -----------------------------------
10438 -- pragma Priority_Specific_Dispatching (
10439 -- policy_IDENTIFIER,
10440 -- first_priority_EXPRESSION,
10441 -- last_priority_EXPRESSION);
10443 when Pragma_Priority_Specific_Dispatching =>
10444 Priority_Specific_Dispatching : declare
10445 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10446 -- This is the entity System.Any_Priority;
10449 Lower_Bound : Node_Id;
10450 Upper_Bound : Node_Id;
10456 Check_Arg_Count (3);
10457 Check_No_Identifiers;
10458 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10459 Check_Valid_Configuration_Pragma;
10460 Get_Name_String (Chars (Expression (Arg1)));
10461 DP := Fold_Upper (Name_Buffer (1));
10463 Lower_Bound := Expression (Arg2);
10464 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10465 Lower_Val := Expr_Value (Lower_Bound);
10467 Upper_Bound := Expression (Arg3);
10468 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10469 Upper_Val := Expr_Value (Upper_Bound);
10471 -- It is not allowed to use Task_Dispatching_Policy and
10472 -- Priority_Specific_Dispatching in the same partition.
10474 if Task_Dispatching_Policy /= ' ' then
10475 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10477 ("pragma% incompatible with Task_Dispatching_Policy#");
10479 -- Check lower bound in range
10481 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10483 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10486 ("first_priority is out of range", Arg2);
10488 -- Check upper bound in range
10490 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10492 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10495 ("last_priority is out of range", Arg3);
10497 -- Check that the priority range is valid
10499 elsif Lower_Val > Upper_Val then
10501 ("last_priority_expression must be greater than" &
10502 " or equal to first_priority_expression");
10504 -- Store the new policy, but always preserve System_Location since
10505 -- we like the error message with the run-time name.
10508 -- Check overlapping in the priority ranges specified in other
10509 -- Priority_Specific_Dispatching pragmas within the same
10510 -- partition. We can only check those we know about!
10513 Specific_Dispatching.First .. Specific_Dispatching.Last
10515 if Specific_Dispatching.Table (J).First_Priority in
10516 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10517 or else Specific_Dispatching.Table (J).Last_Priority in
10518 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10521 Specific_Dispatching.Table (J).Pragma_Loc;
10523 ("priority range overlaps with "
10524 & "Priority_Specific_Dispatching#");
10528 -- The use of Priority_Specific_Dispatching is incompatible
10529 -- with Task_Dispatching_Policy.
10531 if Task_Dispatching_Policy /= ' ' then
10532 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10534 ("Priority_Specific_Dispatching incompatible "
10535 & "with Task_Dispatching_Policy#");
10538 -- The use of Priority_Specific_Dispatching forces ceiling
10541 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10542 Error_Msg_Sloc := Locking_Policy_Sloc;
10544 ("Priority_Specific_Dispatching incompatible "
10545 & "with Locking_Policy#");
10547 -- Set the Ceiling_Locking policy, but preserve System_Location
10548 -- since we like the error message with the run time name.
10551 Locking_Policy := 'C';
10553 if Locking_Policy_Sloc /= System_Location then
10554 Locking_Policy_Sloc := Loc;
10558 -- Add entry in the table
10560 Specific_Dispatching.Append
10561 ((Dispatching_Policy => DP,
10562 First_Priority => UI_To_Int (Lower_Val),
10563 Last_Priority => UI_To_Int (Upper_Val),
10564 Pragma_Loc => Loc));
10566 end Priority_Specific_Dispatching;
10572 -- pragma Profile (profile_IDENTIFIER);
10574 -- profile_IDENTIFIER => Restricted | Ravenscar
10576 when Pragma_Profile =>
10578 Check_Arg_Count (1);
10579 Check_Valid_Configuration_Pragma;
10580 Check_No_Identifiers;
10583 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10585 if Chars (Argx) = Name_Ravenscar then
10586 Set_Ravenscar_Profile (N);
10587 elsif Chars (Argx) = Name_Restricted then
10588 Set_Profile_Restrictions
10589 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10591 Error_Pragma_Arg ("& is not a valid profile", Argx);
10595 ----------------------
10596 -- Profile_Warnings --
10597 ----------------------
10599 -- pragma Profile_Warnings (profile_IDENTIFIER);
10601 -- profile_IDENTIFIER => Restricted | Ravenscar
10603 when Pragma_Profile_Warnings =>
10605 Check_Arg_Count (1);
10606 Check_Valid_Configuration_Pragma;
10607 Check_No_Identifiers;
10610 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10612 if Chars (Argx) = Name_Ravenscar then
10613 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10614 elsif Chars (Argx) = Name_Restricted then
10615 Set_Profile_Restrictions (Restricted, N, Warn => True);
10617 Error_Pragma_Arg ("& is not a valid profile", Argx);
10621 --------------------------
10622 -- Propagate_Exceptions --
10623 --------------------------
10625 -- pragma Propagate_Exceptions;
10627 -- Note: this pragma is obsolete and has no effect
10629 when Pragma_Propagate_Exceptions =>
10631 Check_Arg_Count (0);
10633 if In_Extended_Main_Source_Unit (N) then
10634 Propagate_Exceptions := True;
10641 -- pragma Psect_Object (
10642 -- [Internal =>] LOCAL_NAME,
10643 -- [, [External =>] EXTERNAL_SYMBOL]
10644 -- [, [Size =>] EXTERNAL_SYMBOL]);
10646 when Pragma_Psect_Object | Pragma_Common_Object =>
10647 Psect_Object : declare
10648 Args : Args_List (1 .. 3);
10649 Names : constant Name_List (1 .. 3) := (
10654 Internal : Node_Id renames Args (1);
10655 External : Node_Id renames Args (2);
10656 Size : Node_Id renames Args (3);
10658 Def_Id : Entity_Id;
10660 procedure Check_Too_Long (Arg : Node_Id);
10661 -- Posts message if the argument is an identifier with more
10662 -- than 31 characters, or a string literal with more than
10663 -- 31 characters, and we are operating under VMS
10665 --------------------
10666 -- Check_Too_Long --
10667 --------------------
10669 procedure Check_Too_Long (Arg : Node_Id) is
10670 X : constant Node_Id := Original_Node (Arg);
10673 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10675 ("inappropriate argument for pragma %", Arg);
10678 if OpenVMS_On_Target then
10679 if (Nkind (X) = N_String_Literal
10680 and then String_Length (Strval (X)) > 31)
10682 (Nkind (X) = N_Identifier
10683 and then Length_Of_Name (Chars (X)) > 31)
10686 ("argument for pragma % is longer than 31 characters",
10690 end Check_Too_Long;
10692 -- Start of processing for Common_Object/Psect_Object
10696 Gather_Associations (Names, Args);
10697 Process_Extended_Import_Export_Internal_Arg (Internal);
10699 Def_Id := Entity (Internal);
10701 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
10703 ("pragma% must designate an object", Internal);
10706 Check_Too_Long (Internal);
10708 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10710 ("cannot use pragma% for imported/exported object",
10714 if Is_Concurrent_Type (Etype (Internal)) then
10716 ("cannot specify pragma % for task/protected object",
10720 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10722 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10724 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10727 if Ekind (Def_Id) = E_Constant then
10729 ("cannot specify pragma % for a constant", Internal);
10732 if Is_Record_Type (Etype (Internal)) then
10738 Ent := First_Entity (Etype (Internal));
10739 while Present (Ent) loop
10740 Decl := Declaration_Node (Ent);
10742 if Ekind (Ent) = E_Component
10743 and then Nkind (Decl) = N_Component_Declaration
10744 and then Present (Expression (Decl))
10745 and then Warn_On_Export_Import
10748 ("?object for pragma % has defaults", Internal);
10758 if Present (Size) then
10759 Check_Too_Long (Size);
10762 if Present (External) then
10763 Check_Arg_Is_External_Name (External);
10764 Check_Too_Long (External);
10767 -- If all error tests pass, link pragma on to the rep item chain
10769 Record_Rep_Item (Def_Id, N);
10776 -- pragma Pure [(library_unit_NAME)];
10778 when Pragma_Pure => Pure : declare
10782 Check_Ada_83_Warning;
10783 Check_Valid_Library_Unit_Pragma;
10785 if Nkind (N) = N_Null_Statement then
10789 Ent := Find_Lib_Unit_Name;
10791 Set_Has_Pragma_Pure (Ent);
10792 Set_Suppress_Elaboration_Warnings (Ent);
10799 -- pragma Pure_05 [(library_unit_NAME)];
10801 -- This pragma is useable only in GNAT_Mode, where it is used like
10802 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10803 -- it is ignored). It may be used after a pragma Preelaborate, in
10804 -- which case it overrides the effect of the pragma Preelaborate.
10805 -- This is used to implement AI-362 which recategorizes some run-time
10806 -- packages in Ada 2005 mode.
10808 when Pragma_Pure_05 => Pure_05 : declare
10813 Check_Valid_Library_Unit_Pragma;
10815 if not GNAT_Mode then
10816 Error_Pragma ("pragma% only available in GNAT mode");
10819 if Nkind (N) = N_Null_Statement then
10823 -- This is one of the few cases where we need to test the value of
10824 -- Ada_Version_Explicit rather than Ada_Version (which is always
10825 -- set to Ada_12 in a predefined unit), we need to know the
10826 -- explicit version set to know if this pragma is active.
10828 if Ada_Version_Explicit >= Ada_05 then
10829 Ent := Find_Lib_Unit_Name;
10830 Set_Is_Preelaborated (Ent, False);
10832 Set_Suppress_Elaboration_Warnings (Ent);
10836 -------------------
10837 -- Pure_Function --
10838 -------------------
10840 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10842 when Pragma_Pure_Function => Pure_Function : declare
10845 Def_Id : Entity_Id;
10846 Effective : Boolean := False;
10850 Check_Arg_Count (1);
10851 Check_Optional_Identifier (Arg1, Name_Entity);
10852 Check_Arg_Is_Local_Name (Arg1);
10853 E_Id := Expression (Arg1);
10855 if Error_Posted (E_Id) then
10859 -- Loop through homonyms (overloadings) of referenced entity
10861 E := Entity (E_Id);
10863 if Present (E) then
10865 Def_Id := Get_Base_Subprogram (E);
10867 if not Ekind_In (Def_Id, E_Function,
10868 E_Generic_Function,
10872 ("pragma% requires a function name", Arg1);
10875 Set_Is_Pure (Def_Id);
10877 if not Has_Pragma_Pure_Function (Def_Id) then
10878 Set_Has_Pragma_Pure_Function (Def_Id);
10883 exit when No (E) or else Scope (E) /= Current_Scope;
10887 and then Warn_On_Redundant_Constructs
10890 ("pragma Pure_Function on& is redundant?",
10896 --------------------
10897 -- Queuing_Policy --
10898 --------------------
10900 -- pragma Queuing_Policy (policy_IDENTIFIER);
10902 when Pragma_Queuing_Policy => declare
10906 Check_Ada_83_Warning;
10907 Check_Arg_Count (1);
10908 Check_No_Identifiers;
10909 Check_Arg_Is_Queuing_Policy (Arg1);
10910 Check_Valid_Configuration_Pragma;
10911 Get_Name_String (Chars (Expression (Arg1)));
10912 QP := Fold_Upper (Name_Buffer (1));
10914 if Queuing_Policy /= ' '
10915 and then Queuing_Policy /= QP
10917 Error_Msg_Sloc := Queuing_Policy_Sloc;
10918 Error_Pragma ("queuing policy incompatible with policy#");
10920 -- Set new policy, but always preserve System_Location since we
10921 -- like the error message with the run time name.
10924 Queuing_Policy := QP;
10926 if Queuing_Policy_Sloc /= System_Location then
10927 Queuing_Policy_Sloc := Loc;
10932 -----------------------
10933 -- Relative_Deadline --
10934 -----------------------
10936 -- pragma Relative_Deadline (time_span_EXPRESSION);
10938 when Pragma_Relative_Deadline => Relative_Deadline : declare
10939 P : constant Node_Id := Parent (N);
10944 Check_No_Identifiers;
10945 Check_Arg_Count (1);
10947 Arg := Expression (Arg1);
10949 -- The expression must be analyzed in the special manner described
10950 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10952 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10956 if Nkind (P) = N_Subprogram_Body then
10957 Check_In_Main_Program;
10961 elsif Nkind (P) = N_Task_Definition then
10964 -- Anything else is incorrect
10970 if Has_Relative_Deadline_Pragma (P) then
10971 Error_Pragma ("duplicate pragma% not allowed");
10973 Set_Has_Relative_Deadline_Pragma (P, True);
10975 if Nkind (P) = N_Task_Definition then
10976 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10979 end Relative_Deadline;
10981 ---------------------------
10982 -- Remote_Call_Interface --
10983 ---------------------------
10985 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10987 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10988 Cunit_Node : Node_Id;
10989 Cunit_Ent : Entity_Id;
10993 Check_Ada_83_Warning;
10994 Check_Valid_Library_Unit_Pragma;
10996 if Nkind (N) = N_Null_Statement then
11000 Cunit_Node := Cunit (Current_Sem_Unit);
11001 K := Nkind (Unit (Cunit_Node));
11002 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11004 if K = N_Package_Declaration
11005 or else K = N_Generic_Package_Declaration
11006 or else K = N_Subprogram_Declaration
11007 or else K = N_Generic_Subprogram_Declaration
11008 or else (K = N_Subprogram_Body
11009 and then Acts_As_Spec (Unit (Cunit_Node)))
11014 "pragma% must apply to package or subprogram declaration");
11017 Set_Is_Remote_Call_Interface (Cunit_Ent);
11018 end Remote_Call_Interface;
11024 -- pragma Remote_Types [(library_unit_NAME)];
11026 when Pragma_Remote_Types => Remote_Types : declare
11027 Cunit_Node : Node_Id;
11028 Cunit_Ent : Entity_Id;
11031 Check_Ada_83_Warning;
11032 Check_Valid_Library_Unit_Pragma;
11034 if Nkind (N) = N_Null_Statement then
11038 Cunit_Node := Cunit (Current_Sem_Unit);
11039 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11041 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11042 N_Generic_Package_Declaration)
11045 ("pragma% can only apply to a package declaration");
11048 Set_Is_Remote_Types (Cunit_Ent);
11055 -- pragma Ravenscar;
11057 when Pragma_Ravenscar =>
11059 Check_Arg_Count (0);
11060 Check_Valid_Configuration_Pragma;
11061 Set_Ravenscar_Profile (N);
11063 if Warn_On_Obsolescent_Feature then
11064 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
11065 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
11068 -------------------------
11069 -- Restricted_Run_Time --
11070 -------------------------
11072 -- pragma Restricted_Run_Time;
11074 when Pragma_Restricted_Run_Time =>
11076 Check_Arg_Count (0);
11077 Check_Valid_Configuration_Pragma;
11078 Set_Profile_Restrictions
11079 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11081 if Warn_On_Obsolescent_Feature then
11083 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
11084 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
11091 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
11094 -- restriction_IDENTIFIER
11095 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11097 when Pragma_Restrictions =>
11098 Process_Restrictions_Or_Restriction_Warnings
11099 (Warn => Treat_Restrictions_As_Warnings);
11101 --------------------------
11102 -- Restriction_Warnings --
11103 --------------------------
11105 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
11108 -- restriction_IDENTIFIER
11109 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11111 when Pragma_Restriction_Warnings =>
11113 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
11119 -- pragma Reviewable;
11121 when Pragma_Reviewable =>
11122 Check_Ada_83_Warning;
11123 Check_Arg_Count (0);
11125 -- Call dummy debugging function rv. This is done to assist front
11126 -- end debugging. By placing a Reviewable pragma in the source
11127 -- program, a breakpoint on rv catches this place in the source,
11128 -- allowing convenient stepping to the point of interest.
11132 --------------------------
11133 -- Short_Circuit_And_Or --
11134 --------------------------
11136 when Pragma_Short_Circuit_And_Or =>
11138 Check_Arg_Count (0);
11139 Check_Valid_Configuration_Pragma;
11140 Short_Circuit_And_Or := True;
11142 -------------------
11143 -- Share_Generic --
11144 -------------------
11146 -- pragma Share_Generic (NAME {, NAME});
11148 when Pragma_Share_Generic =>
11150 Process_Generic_List;
11156 -- pragma Shared (LOCAL_NAME);
11158 when Pragma_Shared =>
11160 Process_Atomic_Shared_Volatile;
11162 --------------------
11163 -- Shared_Passive --
11164 --------------------
11166 -- pragma Shared_Passive [(library_unit_NAME)];
11168 -- Set the flag Is_Shared_Passive of program unit name entity
11170 when Pragma_Shared_Passive => Shared_Passive : declare
11171 Cunit_Node : Node_Id;
11172 Cunit_Ent : Entity_Id;
11175 Check_Ada_83_Warning;
11176 Check_Valid_Library_Unit_Pragma;
11178 if Nkind (N) = N_Null_Statement then
11182 Cunit_Node := Cunit (Current_Sem_Unit);
11183 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11185 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11186 N_Generic_Package_Declaration)
11189 ("pragma% can only apply to a package declaration");
11192 Set_Is_Shared_Passive (Cunit_Ent);
11193 end Shared_Passive;
11195 -----------------------
11196 -- Short_Descriptors --
11197 -----------------------
11199 -- pragma Short_Descriptors;
11201 when Pragma_Short_Descriptors =>
11203 Check_Arg_Count (0);
11204 Check_Valid_Configuration_Pragma;
11205 Short_Descriptors := True;
11207 ----------------------
11208 -- Source_File_Name --
11209 ----------------------
11211 -- There are five forms for this pragma:
11213 -- pragma Source_File_Name (
11214 -- [UNIT_NAME =>] unit_NAME,
11215 -- BODY_FILE_NAME => STRING_LITERAL
11216 -- [, [INDEX =>] INTEGER_LITERAL]);
11218 -- pragma Source_File_Name (
11219 -- [UNIT_NAME =>] unit_NAME,
11220 -- SPEC_FILE_NAME => STRING_LITERAL
11221 -- [, [INDEX =>] INTEGER_LITERAL]);
11223 -- pragma Source_File_Name (
11224 -- BODY_FILE_NAME => STRING_LITERAL
11225 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11226 -- [, CASING => CASING_SPEC]);
11228 -- pragma Source_File_Name (
11229 -- SPEC_FILE_NAME => STRING_LITERAL
11230 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11231 -- [, CASING => CASING_SPEC]);
11233 -- pragma Source_File_Name (
11234 -- SUBUNIT_FILE_NAME => STRING_LITERAL
11235 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11236 -- [, CASING => CASING_SPEC]);
11238 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11240 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11241 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
11242 -- only be used when no project file is used, while SFNP can only be
11243 -- used when a project file is used.
11245 -- No processing here. Processing was completed during parsing, since
11246 -- we need to have file names set as early as possible. Units are
11247 -- loaded well before semantic processing starts.
11249 -- The only processing we defer to this point is the check for
11250 -- correct placement.
11252 when Pragma_Source_File_Name =>
11254 Check_Valid_Configuration_Pragma;
11256 ------------------------------
11257 -- Source_File_Name_Project --
11258 ------------------------------
11260 -- See Source_File_Name for syntax
11262 -- No processing here. Processing was completed during parsing, since
11263 -- we need to have file names set as early as possible. Units are
11264 -- loaded well before semantic processing starts.
11266 -- The only processing we defer to this point is the check for
11267 -- correct placement.
11269 when Pragma_Source_File_Name_Project =>
11271 Check_Valid_Configuration_Pragma;
11273 -- Check that a pragma Source_File_Name_Project is used only in a
11274 -- configuration pragmas file.
11276 -- Pragmas Source_File_Name_Project should only be generated by
11277 -- the Project Manager in configuration pragmas files.
11279 -- This is really an ugly test. It seems to depend on some
11280 -- accidental and undocumented property. At the very least it
11281 -- needs to be documented, but it would be better to have a
11282 -- clean way of testing if we are in a configuration file???
11284 if Present (Parent (N)) then
11286 ("pragma% can only appear in a configuration pragmas file");
11289 ----------------------
11290 -- Source_Reference --
11291 ----------------------
11293 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11295 -- Nothing to do, all processing completed in Par.Prag, since we need
11296 -- the information for possible parser messages that are output.
11298 when Pragma_Source_Reference =>
11301 --------------------------------
11302 -- Static_Elaboration_Desired --
11303 --------------------------------
11305 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
11307 when Pragma_Static_Elaboration_Desired =>
11309 Check_At_Most_N_Arguments (1);
11311 if Is_Compilation_Unit (Current_Scope)
11312 and then Ekind (Current_Scope) = E_Package
11314 Set_Static_Elaboration_Desired (Current_Scope, True);
11316 Error_Pragma ("pragma% must apply to a library-level package");
11323 -- pragma Storage_Size (EXPRESSION);
11325 when Pragma_Storage_Size => Storage_Size : declare
11326 P : constant Node_Id := Parent (N);
11330 Check_No_Identifiers;
11331 Check_Arg_Count (1);
11333 -- The expression must be analyzed in the special manner described
11334 -- in "Handling of Default Expressions" in sem.ads.
11336 Arg := Expression (Arg1);
11337 Preanalyze_Spec_Expression (Arg, Any_Integer);
11339 if not Is_Static_Expression (Arg) then
11340 Check_Restriction (Static_Storage_Size, Arg);
11343 if Nkind (P) /= N_Task_Definition then
11348 if Has_Storage_Size_Pragma (P) then
11349 Error_Pragma ("duplicate pragma% not allowed");
11351 Set_Has_Storage_Size_Pragma (P, True);
11354 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11355 -- ??? exp_ch9 should use this!
11363 -- pragma Storage_Unit (NUMERIC_LITERAL);
11365 -- Only permitted argument is System'Storage_Unit value
11367 when Pragma_Storage_Unit =>
11368 Check_No_Identifiers;
11369 Check_Arg_Count (1);
11370 Check_Arg_Is_Integer_Literal (Arg1);
11372 if Intval (Expression (Arg1)) /=
11373 UI_From_Int (Ttypes.System_Storage_Unit)
11375 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11377 ("the only allowed argument for pragma% is ^", Arg1);
11380 --------------------
11381 -- Stream_Convert --
11382 --------------------
11384 -- pragma Stream_Convert (
11385 -- [Entity =>] type_LOCAL_NAME,
11386 -- [Read =>] function_NAME,
11387 -- [Write =>] function NAME);
11389 when Pragma_Stream_Convert => Stream_Convert : declare
11391 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11392 -- Check that the given argument is the name of a local function
11393 -- of one argument that is not overloaded earlier in the current
11394 -- local scope. A check is also made that the argument is a
11395 -- function with one parameter.
11397 --------------------------------------
11398 -- Check_OK_Stream_Convert_Function --
11399 --------------------------------------
11401 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11405 Check_Arg_Is_Local_Name (Arg);
11406 Ent := Entity (Expression (Arg));
11408 if Has_Homonym (Ent) then
11410 ("argument for pragma% may not be overloaded", Arg);
11413 if Ekind (Ent) /= E_Function
11414 or else No (First_Formal (Ent))
11415 or else Present (Next_Formal (First_Formal (Ent)))
11418 ("argument for pragma% must be" &
11419 " function of one argument", Arg);
11421 end Check_OK_Stream_Convert_Function;
11423 -- Start of processing for Stream_Convert
11427 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
11428 Check_Arg_Count (3);
11429 Check_Optional_Identifier (Arg1, Name_Entity);
11430 Check_Optional_Identifier (Arg2, Name_Read);
11431 Check_Optional_Identifier (Arg3, Name_Write);
11432 Check_Arg_Is_Local_Name (Arg1);
11433 Check_OK_Stream_Convert_Function (Arg2);
11434 Check_OK_Stream_Convert_Function (Arg3);
11437 Typ : constant Entity_Id :=
11438 Underlying_Type (Entity (Expression (Arg1)));
11439 Read : constant Entity_Id := Entity (Expression (Arg2));
11440 Write : constant Entity_Id := Entity (Expression (Arg3));
11443 Check_First_Subtype (Arg1);
11445 -- Check for too early or too late. Note that we don't enforce
11446 -- the rule about primitive operations in this case, since, as
11447 -- is the case for explicit stream attributes themselves, these
11448 -- restrictions are not appropriate. Note that the chaining of
11449 -- the pragma by Rep_Item_Too_Late is actually the critical
11450 -- processing done for this pragma.
11452 if Rep_Item_Too_Early (Typ, N)
11454 Rep_Item_Too_Late (Typ, N, FOnly => True)
11459 -- Return if previous error
11461 if Etype (Typ) = Any_Type
11463 Etype (Read) = Any_Type
11465 Etype (Write) = Any_Type
11472 if Underlying_Type (Etype (Read)) /= Typ then
11474 ("incorrect return type for function&", Arg2);
11477 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11479 ("incorrect parameter type for function&", Arg3);
11482 if Underlying_Type (Etype (First_Formal (Read))) /=
11483 Underlying_Type (Etype (Write))
11486 ("result type of & does not match Read parameter type",
11490 end Stream_Convert;
11492 -------------------------
11493 -- Style_Checks (GNAT) --
11494 -------------------------
11496 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11498 -- This is processed by the parser since some of the style checks
11499 -- take place during source scanning and parsing. This means that
11500 -- we don't need to issue error messages here.
11502 when Pragma_Style_Checks => Style_Checks : declare
11503 A : constant Node_Id := Expression (Arg1);
11509 Check_No_Identifiers;
11511 -- Two argument form
11513 if Arg_Count = 2 then
11514 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11521 E_Id := Expression (Arg2);
11524 if not Is_Entity_Name (E_Id) then
11526 ("second argument of pragma% must be entity name",
11530 E := Entity (E_Id);
11536 Set_Suppress_Style_Checks (E,
11537 (Chars (Expression (Arg1)) = Name_Off));
11538 exit when No (Homonym (E));
11544 -- One argument form
11547 Check_Arg_Count (1);
11549 if Nkind (A) = N_String_Literal then
11553 Slen : constant Natural := Natural (String_Length (S));
11554 Options : String (1 .. Slen);
11560 C := Get_String_Char (S, Int (J));
11561 exit when not In_Character_Range (C);
11562 Options (J) := Get_Character (C);
11564 -- If at end of string, set options. As per discussion
11565 -- above, no need to check for errors, since we issued
11566 -- them in the parser.
11569 Set_Style_Check_Options (Options);
11577 elsif Nkind (A) = N_Identifier then
11578 if Chars (A) = Name_All_Checks then
11580 Set_GNAT_Style_Check_Options;
11582 Set_Default_Style_Check_Options;
11585 elsif Chars (A) = Name_On then
11586 Style_Check := True;
11588 elsif Chars (A) = Name_Off then
11589 Style_Check := False;
11599 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11601 when Pragma_Subtitle =>
11603 Check_Arg_Count (1);
11604 Check_Optional_Identifier (Arg1, Name_Subtitle);
11605 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11612 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11614 when Pragma_Suppress =>
11615 Process_Suppress_Unsuppress (True);
11621 -- pragma Suppress_All;
11623 -- The only check made here is that the pragma appears in the proper
11624 -- place, i.e. following a compilation unit. If indeed it appears in
11625 -- this context, then the parser has already inserted an equivalent
11626 -- pragma Suppress (All_Checks) to get the required effect.
11628 when Pragma_Suppress_All =>
11630 Check_Arg_Count (0);
11632 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11633 or else not Is_List_Member (N)
11634 or else List_Containing (N) /= Pragmas_After (Parent (N))
11637 ("misplaced pragma%, must follow compilation unit");
11640 -------------------------
11641 -- Suppress_Debug_Info --
11642 -------------------------
11644 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11646 when Pragma_Suppress_Debug_Info =>
11648 Check_Arg_Count (1);
11649 Check_Optional_Identifier (Arg1, Name_Entity);
11650 Check_Arg_Is_Local_Name (Arg1);
11651 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11653 ----------------------------------
11654 -- Suppress_Exception_Locations --
11655 ----------------------------------
11657 -- pragma Suppress_Exception_Locations;
11659 when Pragma_Suppress_Exception_Locations =>
11661 Check_Arg_Count (0);
11662 Check_Valid_Configuration_Pragma;
11663 Exception_Locations_Suppressed := True;
11665 -----------------------------
11666 -- Suppress_Initialization --
11667 -----------------------------
11669 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11671 when Pragma_Suppress_Initialization => Suppress_Init : declare
11677 Check_Arg_Count (1);
11678 Check_Optional_Identifier (Arg1, Name_Entity);
11679 Check_Arg_Is_Local_Name (Arg1);
11681 E_Id := Expression (Arg1);
11683 if Etype (E_Id) = Any_Type then
11687 E := Entity (E_Id);
11689 if Is_Type (E) then
11690 if Is_Incomplete_Or_Private_Type (E) then
11691 if No (Full_View (Base_Type (E))) then
11693 ("argument of pragma% cannot be an incomplete type",
11696 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11699 Set_Suppress_Init_Proc (Base_Type (E));
11704 ("pragma% requires argument that is a type name", Arg1);
11712 -- pragma System_Name (DIRECT_NAME);
11714 -- Syntax check: one argument, which must be the identifier GNAT or
11715 -- the identifier GCC, no other identifiers are acceptable.
11717 when Pragma_System_Name =>
11719 Check_No_Identifiers;
11720 Check_Arg_Count (1);
11721 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11723 -----------------------------
11724 -- Task_Dispatching_Policy --
11725 -----------------------------
11727 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11729 when Pragma_Task_Dispatching_Policy => declare
11733 Check_Ada_83_Warning;
11734 Check_Arg_Count (1);
11735 Check_No_Identifiers;
11736 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11737 Check_Valid_Configuration_Pragma;
11738 Get_Name_String (Chars (Expression (Arg1)));
11739 DP := Fold_Upper (Name_Buffer (1));
11741 if Task_Dispatching_Policy /= ' '
11742 and then Task_Dispatching_Policy /= DP
11744 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11746 ("task dispatching policy incompatible with policy#");
11748 -- Set new policy, but always preserve System_Location since we
11749 -- like the error message with the run time name.
11752 Task_Dispatching_Policy := DP;
11754 if Task_Dispatching_Policy_Sloc /= System_Location then
11755 Task_Dispatching_Policy_Sloc := Loc;
11764 -- pragma Task_Info (EXPRESSION);
11766 when Pragma_Task_Info => Task_Info : declare
11767 P : constant Node_Id := Parent (N);
11772 if Nkind (P) /= N_Task_Definition then
11773 Error_Pragma ("pragma% must appear in task definition");
11776 Check_No_Identifiers;
11777 Check_Arg_Count (1);
11779 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11781 if Etype (Expression (Arg1)) = Any_Type then
11785 if Has_Task_Info_Pragma (P) then
11786 Error_Pragma ("duplicate pragma% not allowed");
11788 Set_Has_Task_Info_Pragma (P, True);
11796 -- pragma Task_Name (string_EXPRESSION);
11798 when Pragma_Task_Name => Task_Name : declare
11799 P : constant Node_Id := Parent (N);
11803 Check_No_Identifiers;
11804 Check_Arg_Count (1);
11806 Arg := Expression (Arg1);
11808 -- The expression is used in the call to Create_Task, and must be
11809 -- expanded there, not in the context of the current spec. It must
11810 -- however be analyzed to capture global references, in case it
11811 -- appears in a generic context.
11813 Preanalyze_And_Resolve (Arg, Standard_String);
11815 if Nkind (P) /= N_Task_Definition then
11819 if Has_Task_Name_Pragma (P) then
11820 Error_Pragma ("duplicate pragma% not allowed");
11822 Set_Has_Task_Name_Pragma (P, True);
11823 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11831 -- pragma Task_Storage (
11832 -- [Task_Type =>] LOCAL_NAME,
11833 -- [Top_Guard =>] static_integer_EXPRESSION);
11835 when Pragma_Task_Storage => Task_Storage : declare
11836 Args : Args_List (1 .. 2);
11837 Names : constant Name_List (1 .. 2) := (
11841 Task_Type : Node_Id renames Args (1);
11842 Top_Guard : Node_Id renames Args (2);
11848 Gather_Associations (Names, Args);
11850 if No (Task_Type) then
11852 ("missing task_type argument for pragma%");
11855 Check_Arg_Is_Local_Name (Task_Type);
11857 Ent := Entity (Task_Type);
11859 if not Is_Task_Type (Ent) then
11861 ("argument for pragma% must be task type", Task_Type);
11864 if No (Top_Guard) then
11866 ("pragma% takes two arguments", Task_Type);
11868 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11871 Check_First_Subtype (Task_Type);
11873 if Rep_Item_Too_Late (Ent, N) then
11878 --------------------------
11879 -- Thread_Local_Storage --
11880 --------------------------
11882 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11884 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11890 Check_Arg_Count (1);
11891 Check_Optional_Identifier (Arg1, Name_Entity);
11892 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11894 Id := Expression (Arg1);
11897 if not Is_Entity_Name (Id)
11898 or else Ekind (Entity (Id)) /= E_Variable
11900 Error_Pragma_Arg ("local variable name required", Arg1);
11905 if Rep_Item_Too_Early (E, N)
11906 or else Rep_Item_Too_Late (E, N)
11911 Set_Has_Pragma_Thread_Local_Storage (E);
11912 Set_Has_Gigi_Rep_Item (E);
11913 end Thread_Local_Storage;
11919 -- pragma Time_Slice (static_duration_EXPRESSION);
11921 when Pragma_Time_Slice => Time_Slice : declare
11927 Check_Arg_Count (1);
11928 Check_No_Identifiers;
11929 Check_In_Main_Program;
11930 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11932 if not Error_Posted (Arg1) then
11934 while Present (Nod) loop
11935 if Nkind (Nod) = N_Pragma
11936 and then Pragma_Name (Nod) = Name_Time_Slice
11938 Error_Msg_Name_1 := Pname;
11939 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11946 -- Process only if in main unit
11948 if Get_Source_Unit (Loc) = Main_Unit then
11949 Opt.Time_Slice_Set := True;
11950 Val := Expr_Value_R (Expression (Arg1));
11952 if Val <= Ureal_0 then
11953 Opt.Time_Slice_Value := 0;
11955 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11956 Opt.Time_Slice_Value := 1_000_000_000;
11959 Opt.Time_Slice_Value :=
11960 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11969 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11971 -- TITLING_OPTION ::=
11972 -- [Title =>] STRING_LITERAL
11973 -- | [Subtitle =>] STRING_LITERAL
11975 when Pragma_Title => Title : declare
11976 Args : Args_List (1 .. 2);
11977 Names : constant Name_List (1 .. 2) := (
11983 Gather_Associations (Names, Args);
11986 for J in 1 .. 2 loop
11987 if Present (Args (J)) then
11988 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
11993 ---------------------
11994 -- Unchecked_Union --
11995 ---------------------
11997 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11999 when Pragma_Unchecked_Union => Unchecked_Union : declare
12000 Assoc : constant Node_Id := Arg1;
12001 Type_Id : constant Node_Id := Expression (Assoc);
12012 Check_No_Identifiers;
12013 Check_Arg_Count (1);
12014 Check_Arg_Is_Local_Name (Arg1);
12016 Find_Type (Type_Id);
12017 Typ := Entity (Type_Id);
12020 or else Rep_Item_Too_Early (Typ, N)
12024 Typ := Underlying_Type (Typ);
12027 if Rep_Item_Too_Late (Typ, N) then
12031 Check_First_Subtype (Arg1);
12033 -- Note remaining cases are references to a type in the current
12034 -- declarative part. If we find an error, we post the error on
12035 -- the relevant type declaration at an appropriate point.
12037 if not Is_Record_Type (Typ) then
12038 Error_Msg_N ("Unchecked_Union must be record type", Typ);
12041 elsif Is_Tagged_Type (Typ) then
12042 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
12045 elsif Is_Limited_Type (Typ) then
12047 ("Unchecked_Union must not be limited record type", Typ);
12048 Explain_Limited_Type (Typ, Typ);
12052 if not Has_Discriminants (Typ) then
12054 ("Unchecked_Union must have one discriminant", Typ);
12058 Discr := First_Discriminant (Typ);
12059 while Present (Discr) loop
12060 if No (Discriminant_Default_Value (Discr)) then
12062 ("Unchecked_Union discriminant must have default value",
12065 Next_Discriminant (Discr);
12068 Tdef := Type_Definition (Declaration_Node (Typ));
12069 Clist := Component_List (Tdef);
12071 Comp := First (Component_Items (Clist));
12072 while Present (Comp) loop
12073 Check_Component (Comp, Typ);
12077 if No (Clist) or else No (Variant_Part (Clist)) then
12079 ("Unchecked_Union must have variant part",
12084 Vpart := Variant_Part (Clist);
12086 Variant := First (Variants (Vpart));
12087 while Present (Variant) loop
12088 Check_Variant (Variant, Typ);
12093 Set_Is_Unchecked_Union (Typ, True);
12094 Set_Convention (Typ, Convention_C);
12096 Set_Has_Unchecked_Union (Base_Type (Typ), True);
12097 Set_Is_Unchecked_Union (Base_Type (Typ), True);
12098 end Unchecked_Union;
12100 ------------------------
12101 -- Unimplemented_Unit --
12102 ------------------------
12104 -- pragma Unimplemented_Unit;
12106 -- Note: this only gives an error if we are generating code, or if
12107 -- we are in a generic library unit (where the pragma appears in the
12108 -- body, not in the spec).
12110 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
12111 Cunitent : constant Entity_Id :=
12112 Cunit_Entity (Get_Source_Unit (Loc));
12113 Ent_Kind : constant Entity_Kind :=
12118 Check_Arg_Count (0);
12120 if Operating_Mode = Generate_Code
12121 or else Ent_Kind = E_Generic_Function
12122 or else Ent_Kind = E_Generic_Procedure
12123 or else Ent_Kind = E_Generic_Package
12125 Get_Name_String (Chars (Cunitent));
12126 Set_Casing (Mixed_Case);
12127 Write_Str (Name_Buffer (1 .. Name_Len));
12128 Write_Str (" is not supported in this configuration");
12130 raise Unrecoverable_Error;
12132 end Unimplemented_Unit;
12134 ------------------------
12135 -- Universal_Aliasing --
12136 ------------------------
12138 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12140 when Pragma_Universal_Aliasing => Universal_Alias : declare
12145 Check_Arg_Count (1);
12146 Check_Optional_Identifier (Arg2, Name_Entity);
12147 Check_Arg_Is_Local_Name (Arg1);
12148 E_Id := Entity (Expression (Arg1));
12150 if E_Id = Any_Type then
12152 elsif No (E_Id) or else not Is_Type (E_Id) then
12153 Error_Pragma_Arg ("pragma% requires type", Arg1);
12156 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
12157 end Universal_Alias;
12159 --------------------
12160 -- Universal_Data --
12161 --------------------
12163 -- pragma Universal_Data [(library_unit_NAME)];
12165 when Pragma_Universal_Data =>
12168 -- If this is a configuration pragma, then set the universal
12169 -- addressing option, otherwise confirm that the pragma satisfies
12170 -- the requirements of library unit pragma placement and leave it
12171 -- to the GNAAMP back end to detect the pragma (avoids transitive
12172 -- setting of the option due to withed units).
12174 if Is_Configuration_Pragma then
12175 Universal_Addressing_On_AAMP := True;
12177 Check_Valid_Library_Unit_Pragma;
12180 if not AAMP_On_Target then
12181 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12188 -- pragma Unmodified (local_Name {, local_Name});
12190 when Pragma_Unmodified => Unmodified : declare
12191 Arg_Node : Node_Id;
12192 Arg_Expr : Node_Id;
12193 Arg_Ent : Entity_Id;
12197 Check_At_Least_N_Arguments (1);
12199 -- Loop through arguments
12202 while Present (Arg_Node) loop
12203 Check_No_Identifier (Arg_Node);
12205 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
12206 -- in fact generate reference, so that the entity will have a
12207 -- reference, which will inhibit any warnings about it not
12208 -- being referenced, and also properly show up in the ali file
12209 -- as a reference. But this reference is recorded before the
12210 -- Has_Pragma_Unreferenced flag is set, so that no warning is
12211 -- generated for this reference.
12213 Check_Arg_Is_Local_Name (Arg_Node);
12214 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12216 if Is_Entity_Name (Arg_Expr) then
12217 Arg_Ent := Entity (Arg_Expr);
12219 if not Is_Assignable (Arg_Ent) then
12221 ("pragma% can only be applied to a variable",
12224 Set_Has_Pragma_Unmodified (Arg_Ent);
12236 -- pragma Unreferenced (local_Name {, local_Name});
12238 -- or when used in a context clause:
12240 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12242 when Pragma_Unreferenced => Unreferenced : declare
12243 Arg_Node : Node_Id;
12244 Arg_Expr : Node_Id;
12245 Arg_Ent : Entity_Id;
12250 Check_At_Least_N_Arguments (1);
12252 -- Check case of appearing within context clause
12254 if Is_In_Context_Clause then
12256 -- The arguments must all be units mentioned in a with clause
12257 -- in the same context clause. Note we already checked (in
12258 -- Par.Prag) that the arguments are either identifiers or
12259 -- selected components.
12262 while Present (Arg_Node) loop
12263 Citem := First (List_Containing (N));
12264 while Citem /= N loop
12265 if Nkind (Citem) = N_With_Clause
12266 and then Same_Name (Name (Citem), Expression (Arg_Node))
12268 Set_Has_Pragma_Unreferenced
12271 (Library_Unit (Citem))));
12272 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
12281 ("argument of pragma% is not with'ed unit", Arg_Node);
12287 -- Case of not in list of context items
12291 while Present (Arg_Node) loop
12292 Check_No_Identifier (Arg_Node);
12294 -- Note: the analyze call done by Check_Arg_Is_Local_Name
12295 -- will in fact generate reference, so that the entity will
12296 -- have a reference, which will inhibit any warnings about
12297 -- it not being referenced, and also properly show up in the
12298 -- ali file as a reference. But this reference is recorded
12299 -- before the Has_Pragma_Unreferenced flag is set, so that
12300 -- no warning is generated for this reference.
12302 Check_Arg_Is_Local_Name (Arg_Node);
12303 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12305 if Is_Entity_Name (Arg_Expr) then
12306 Arg_Ent := Entity (Arg_Expr);
12308 -- If the entity is overloaded, the pragma applies to the
12309 -- most recent overloading, as documented. In this case,
12310 -- name resolution does not generate a reference, so it
12311 -- must be done here explicitly.
12313 if Is_Overloaded (Arg_Expr) then
12314 Generate_Reference (Arg_Ent, N);
12317 Set_Has_Pragma_Unreferenced (Arg_Ent);
12325 --------------------------
12326 -- Unreferenced_Objects --
12327 --------------------------
12329 -- pragma Unreferenced_Objects (local_Name {, local_Name});
12331 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12332 Arg_Node : Node_Id;
12333 Arg_Expr : Node_Id;
12337 Check_At_Least_N_Arguments (1);
12340 while Present (Arg_Node) loop
12341 Check_No_Identifier (Arg_Node);
12342 Check_Arg_Is_Local_Name (Arg_Node);
12343 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12345 if not Is_Entity_Name (Arg_Expr)
12346 or else not Is_Type (Entity (Arg_Expr))
12349 ("argument for pragma% must be type or subtype", Arg_Node);
12352 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
12355 end Unreferenced_Objects;
12357 ------------------------------
12358 -- Unreserve_All_Interrupts --
12359 ------------------------------
12361 -- pragma Unreserve_All_Interrupts;
12363 when Pragma_Unreserve_All_Interrupts =>
12365 Check_Arg_Count (0);
12367 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12368 Unreserve_All_Interrupts := True;
12375 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12377 when Pragma_Unsuppress =>
12379 Process_Suppress_Unsuppress (False);
12381 -------------------
12382 -- Use_VADS_Size --
12383 -------------------
12385 -- pragma Use_VADS_Size;
12387 when Pragma_Use_VADS_Size =>
12389 Check_Arg_Count (0);
12390 Check_Valid_Configuration_Pragma;
12391 Use_VADS_Size := True;
12393 ---------------------
12394 -- Validity_Checks --
12395 ---------------------
12397 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12399 when Pragma_Validity_Checks => Validity_Checks : declare
12400 A : constant Node_Id := Expression (Arg1);
12406 Check_Arg_Count (1);
12407 Check_No_Identifiers;
12409 if Nkind (A) = N_String_Literal then
12413 Slen : constant Natural := Natural (String_Length (S));
12414 Options : String (1 .. Slen);
12420 C := Get_String_Char (S, Int (J));
12421 exit when not In_Character_Range (C);
12422 Options (J) := Get_Character (C);
12425 Set_Validity_Check_Options (Options);
12433 elsif Nkind (A) = N_Identifier then
12435 if Chars (A) = Name_All_Checks then
12436 Set_Validity_Check_Options ("a");
12438 elsif Chars (A) = Name_On then
12439 Validity_Checks_On := True;
12441 elsif Chars (A) = Name_Off then
12442 Validity_Checks_On := False;
12446 end Validity_Checks;
12452 -- pragma Volatile (LOCAL_NAME);
12454 when Pragma_Volatile =>
12455 Process_Atomic_Shared_Volatile;
12457 -------------------------
12458 -- Volatile_Components --
12459 -------------------------
12461 -- pragma Volatile_Components (array_LOCAL_NAME);
12463 -- Volatile is handled by the same circuit as Atomic_Components
12469 -- pragma Warnings (On | Off);
12470 -- pragma Warnings (On | Off, LOCAL_NAME);
12471 -- pragma Warnings (static_string_EXPRESSION);
12472 -- pragma Warnings (On | Off, STRING_LITERAL);
12474 when Pragma_Warnings => Warnings : begin
12476 Check_At_Least_N_Arguments (1);
12477 Check_No_Identifiers;
12479 -- If debug flag -gnatd.i is set, pragma is ignored
12481 if Debug_Flag_Dot_I then
12485 -- Process various forms of the pragma
12488 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12491 -- One argument case
12493 if Arg_Count = 1 then
12495 -- On/Off one argument case was processed by parser
12497 if Nkind (Argx) = N_Identifier
12499 (Chars (Argx) = Name_On
12501 Chars (Argx) = Name_Off)
12505 -- One argument case must be ON/OFF or static string expr
12507 elsif not Is_Static_String_Expression (Arg1) then
12509 ("argument of pragma% must be On/Off or " &
12510 "static string expression", Arg1);
12512 -- One argument string expression case
12516 Lit : constant Node_Id := Expr_Value_S (Argx);
12517 Str : constant String_Id := Strval (Lit);
12518 Len : constant Nat := String_Length (Str);
12526 while J <= Len loop
12527 C := Get_String_Char (Str, J);
12528 OK := In_Character_Range (C);
12531 Chr := Get_Character (C);
12535 if J < Len and then Chr = '.' then
12537 C := Get_String_Char (Str, J);
12538 Chr := Get_Character (C);
12540 if not Set_Dot_Warning_Switch (Chr) then
12542 ("invalid warning switch character " &
12549 OK := Set_Warning_Switch (Chr);
12555 ("invalid warning switch character " & Chr,
12564 -- Two or more arguments (must be two)
12567 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12568 Check_At_Most_N_Arguments (2);
12576 E_Id := Expression (Arg2);
12579 -- In the expansion of an inlined body, a reference to
12580 -- the formal may be wrapped in a conversion if the
12581 -- actual is a conversion. Retrieve the real entity name.
12583 if (In_Instance_Body
12584 or else In_Inlined_Body)
12585 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12587 E_Id := Expression (E_Id);
12590 -- Entity name case
12592 if Is_Entity_Name (E_Id) then
12593 E := Entity (E_Id);
12600 (E, (Chars (Expression (Arg1)) = Name_Off));
12602 if Chars (Expression (Arg1)) = Name_Off
12603 and then Warn_On_Warnings_Off
12605 Warnings_Off_Pragmas.Append ((N, E));
12608 if Is_Enumeration_Type (E) then
12612 Lit := First_Literal (E);
12613 while Present (Lit) loop
12614 Set_Warnings_Off (Lit);
12615 Next_Literal (Lit);
12620 exit when No (Homonym (E));
12625 -- Error if not entity or static string literal case
12627 elsif not Is_Static_String_Expression (Arg2) then
12629 ("second argument of pragma% must be entity " &
12630 "name or static string expression", Arg2);
12632 -- String literal case
12635 String_To_Name_Buffer
12636 (Strval (Expr_Value_S (Expression (Arg2))));
12638 -- Note on configuration pragma case: If this is a
12639 -- configuration pragma, then for an OFF pragma, we
12640 -- just set Config True in the call, which is all
12641 -- that needs to be done. For the case of ON, this
12642 -- is normally an error, unless it is canceling the
12643 -- effect of a previous OFF pragma in the same file.
12644 -- In any other case, an error will be signalled (ON
12645 -- with no matching OFF).
12647 if Chars (Argx) = Name_Off then
12648 Set_Specific_Warning_Off
12649 (Loc, Name_Buffer (1 .. Name_Len),
12650 Config => Is_Configuration_Pragma);
12652 elsif Chars (Argx) = Name_On then
12653 Set_Specific_Warning_On
12654 (Loc, Name_Buffer (1 .. Name_Len), Err);
12658 ("?pragma Warnings On with no " &
12659 "matching Warnings Off",
12669 -------------------
12670 -- Weak_External --
12671 -------------------
12673 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12675 when Pragma_Weak_External => Weak_External : declare
12680 Check_Arg_Count (1);
12681 Check_Optional_Identifier (Arg1, Name_Entity);
12682 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12683 Ent := Entity (Expression (Arg1));
12685 if Rep_Item_Too_Early (Ent, N) then
12688 Ent := Underlying_Type (Ent);
12691 -- The only processing required is to link this item on to the
12692 -- list of rep items for the given entity. This is accomplished
12693 -- by the call to Rep_Item_Too_Late (when no error is detected
12694 -- and False is returned).
12696 if Rep_Item_Too_Late (Ent, N) then
12699 Set_Has_Gigi_Rep_Item (Ent);
12703 -----------------------------
12704 -- Wide_Character_Encoding --
12705 -----------------------------
12707 -- pragma Wide_Character_Encoding (IDENTIFIER);
12709 when Pragma_Wide_Character_Encoding =>
12712 -- Nothing to do, handled in parser. Note that we do not enforce
12713 -- configuration pragma placement, this pragma can appear at any
12714 -- place in the source, allowing mixed encodings within a single
12719 --------------------
12720 -- Unknown_Pragma --
12721 --------------------
12723 -- Should be impossible, since the case of an unknown pragma is
12724 -- separately processed before the case statement is entered.
12726 when Unknown_Pragma =>
12727 raise Program_Error;
12730 -- AI05-0144: detect dangerous order dependence. Disabled for now,
12731 -- until AI is formally approved.
12733 -- Check_Order_Dependence;
12736 when Pragma_Exit => null;
12737 end Analyze_Pragma;
12739 -------------------
12740 -- Check_Enabled --
12741 -------------------
12743 function Check_Enabled (Nam : Name_Id) return Boolean is
12747 PP := Opt.Check_Policy_List;
12750 return Assertions_Enabled;
12753 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12756 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12758 when Name_On | Name_Check =>
12760 when Name_Off | Name_Ignore =>
12763 raise Program_Error;
12767 PP := Next_Pragma (PP);
12772 ---------------------------------
12773 -- Delay_Config_Pragma_Analyze --
12774 ---------------------------------
12776 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12778 return Pragma_Name (N) = Name_Interrupt_State
12780 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12781 end Delay_Config_Pragma_Analyze;
12783 -------------------------
12784 -- Get_Base_Subprogram --
12785 -------------------------
12787 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12788 Result : Entity_Id;
12791 -- Follow subprogram renaming chain
12794 while Is_Subprogram (Result)
12796 (Is_Generic_Instance (Result)
12797 or else Nkind (Parent (Declaration_Node (Result))) =
12798 N_Subprogram_Renaming_Declaration)
12799 and then Present (Alias (Result))
12801 Result := Alias (Result);
12805 end Get_Base_Subprogram;
12807 --------------------
12808 -- Get_Pragma_Arg --
12809 --------------------
12811 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12813 if Nkind (Arg) = N_Pragma_Argument_Association then
12814 return Expression (Arg);
12818 end Get_Pragma_Arg;
12824 procedure Initialize is
12829 -----------------------------
12830 -- Is_Config_Static_String --
12831 -----------------------------
12833 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12835 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12836 -- This is an internal recursive function that is just like the outer
12837 -- function except that it adds the string to the name buffer rather
12838 -- than placing the string in the name buffer.
12840 ------------------------------
12841 -- Add_Config_Static_String --
12842 ------------------------------
12844 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12851 if Nkind (N) = N_Op_Concat then
12852 if Add_Config_Static_String (Left_Opnd (N)) then
12853 N := Right_Opnd (N);
12859 if Nkind (N) /= N_String_Literal then
12860 Error_Msg_N ("string literal expected for pragma argument", N);
12864 for J in 1 .. String_Length (Strval (N)) loop
12865 C := Get_String_Char (Strval (N), J);
12867 if not In_Character_Range (C) then
12869 ("string literal contains invalid wide character",
12870 Sloc (N) + 1 + Source_Ptr (J));
12874 Add_Char_To_Name_Buffer (Get_Character (C));
12879 end Add_Config_Static_String;
12881 -- Start of processing for Is_Config_Static_String
12886 return Add_Config_Static_String (Arg);
12887 end Is_Config_Static_String;
12889 -----------------------------------------
12890 -- Is_Non_Significant_Pragma_Reference --
12891 -----------------------------------------
12893 -- This function makes use of the following static table which indicates
12894 -- whether a given pragma is significant.
12896 -- -1 indicates that references in any argument position are significant
12897 -- 0 indicates that appearence in any argument is not significant
12898 -- +n indicates that appearence as argument n is significant, but all
12899 -- other arguments are not significant
12900 -- 99 special processing required (e.g. for pragma Check)
12902 Sig_Flags : constant array (Pragma_Id) of Int :=
12903 (Pragma_AST_Entry => -1,
12904 Pragma_Abort_Defer => -1,
12905 Pragma_Ada_83 => -1,
12906 Pragma_Ada_95 => -1,
12907 Pragma_Ada_05 => -1,
12908 Pragma_Ada_2005 => -1,
12909 Pragma_Ada_12 => -1,
12910 Pragma_Ada_2012 => -1,
12911 Pragma_All_Calls_Remote => -1,
12912 Pragma_Annotate => -1,
12913 Pragma_Assert => -1,
12914 Pragma_Assertion_Policy => 0,
12915 Pragma_Assume_No_Invalid_Values => 0,
12916 Pragma_Asynchronous => -1,
12917 Pragma_Atomic => 0,
12918 Pragma_Atomic_Components => 0,
12919 Pragma_Attach_Handler => -1,
12920 Pragma_Check => 99,
12921 Pragma_Check_Name => 0,
12922 Pragma_Check_Policy => 0,
12923 Pragma_CIL_Constructor => -1,
12924 Pragma_CPP_Class => 0,
12925 Pragma_CPP_Constructor => 0,
12926 Pragma_CPP_Virtual => 0,
12927 Pragma_CPP_Vtable => 0,
12928 Pragma_C_Pass_By_Copy => 0,
12929 Pragma_Comment => 0,
12930 Pragma_Common_Object => -1,
12931 Pragma_Compile_Time_Error => -1,
12932 Pragma_Compile_Time_Warning => -1,
12933 Pragma_Compiler_Unit => 0,
12934 Pragma_Complete_Representation => 0,
12935 Pragma_Complex_Representation => 0,
12936 Pragma_Component_Alignment => -1,
12937 Pragma_Controlled => 0,
12938 Pragma_Convention => 0,
12939 Pragma_Convention_Identifier => 0,
12940 Pragma_Debug => -1,
12941 Pragma_Debug_Policy => 0,
12942 Pragma_Detect_Blocking => -1,
12943 Pragma_Dimension => -1,
12944 Pragma_Discard_Names => 0,
12945 Pragma_Elaborate => -1,
12946 Pragma_Elaborate_All => -1,
12947 Pragma_Elaborate_Body => -1,
12948 Pragma_Elaboration_Checks => -1,
12949 Pragma_Eliminate => -1,
12950 Pragma_Export => -1,
12951 Pragma_Export_Exception => -1,
12952 Pragma_Export_Function => -1,
12953 Pragma_Export_Object => -1,
12954 Pragma_Export_Procedure => -1,
12955 Pragma_Export_Value => -1,
12956 Pragma_Export_Valued_Procedure => -1,
12957 Pragma_Extend_System => -1,
12958 Pragma_Extensions_Allowed => -1,
12959 Pragma_External => -1,
12960 Pragma_Favor_Top_Level => -1,
12961 Pragma_External_Name_Casing => -1,
12962 Pragma_Fast_Math => -1,
12963 Pragma_Finalize_Storage_Only => 0,
12964 Pragma_Float_Representation => 0,
12965 Pragma_Ident => -1,
12966 Pragma_Implemented => -1,
12967 Pragma_Implicit_Packing => 0,
12968 Pragma_Import => +2,
12969 Pragma_Import_Exception => 0,
12970 Pragma_Import_Function => 0,
12971 Pragma_Import_Object => 0,
12972 Pragma_Import_Procedure => 0,
12973 Pragma_Import_Valued_Procedure => 0,
12974 Pragma_Initialize_Scalars => -1,
12975 Pragma_Inline => 0,
12976 Pragma_Inline_Always => 0,
12977 Pragma_Inline_Generic => 0,
12978 Pragma_Inspection_Point => -1,
12979 Pragma_Interface => +2,
12980 Pragma_Interface_Name => +2,
12981 Pragma_Interrupt_Handler => -1,
12982 Pragma_Interrupt_Priority => -1,
12983 Pragma_Interrupt_State => -1,
12984 Pragma_Java_Constructor => -1,
12985 Pragma_Java_Interface => -1,
12986 Pragma_Keep_Names => 0,
12987 Pragma_License => -1,
12988 Pragma_Link_With => -1,
12989 Pragma_Linker_Alias => -1,
12990 Pragma_Linker_Constructor => -1,
12991 Pragma_Linker_Destructor => -1,
12992 Pragma_Linker_Options => -1,
12993 Pragma_Linker_Section => -1,
12995 Pragma_Locking_Policy => -1,
12996 Pragma_Long_Float => -1,
12997 Pragma_Machine_Attribute => -1,
12999 Pragma_Main_Storage => -1,
13000 Pragma_Memory_Size => -1,
13001 Pragma_No_Return => 0,
13002 Pragma_No_Body => 0,
13003 Pragma_No_Run_Time => -1,
13004 Pragma_No_Strict_Aliasing => -1,
13005 Pragma_Normalize_Scalars => -1,
13006 Pragma_Obsolescent => 0,
13007 Pragma_Optimize => -1,
13008 Pragma_Optimize_Alignment => -1,
13009 Pragma_Ordered => 0,
13012 Pragma_Passive => -1,
13013 Pragma_Preelaborable_Initialization => -1,
13014 Pragma_Polling => -1,
13015 Pragma_Persistent_BSS => 0,
13016 Pragma_Postcondition => -1,
13017 Pragma_Precondition => -1,
13018 Pragma_Preelaborate => -1,
13019 Pragma_Preelaborate_05 => -1,
13020 Pragma_Priority => -1,
13021 Pragma_Priority_Specific_Dispatching => -1,
13022 Pragma_Profile => 0,
13023 Pragma_Profile_Warnings => 0,
13024 Pragma_Propagate_Exceptions => -1,
13025 Pragma_Psect_Object => -1,
13027 Pragma_Pure_05 => -1,
13028 Pragma_Pure_Function => -1,
13029 Pragma_Queuing_Policy => -1,
13030 Pragma_Ravenscar => -1,
13031 Pragma_Relative_Deadline => -1,
13032 Pragma_Remote_Call_Interface => -1,
13033 Pragma_Remote_Types => -1,
13034 Pragma_Restricted_Run_Time => -1,
13035 Pragma_Restriction_Warnings => -1,
13036 Pragma_Restrictions => -1,
13037 Pragma_Reviewable => -1,
13038 Pragma_Short_Circuit_And_Or => -1,
13039 Pragma_Share_Generic => -1,
13040 Pragma_Shared => -1,
13041 Pragma_Shared_Passive => -1,
13042 Pragma_Short_Descriptors => 0,
13043 Pragma_Source_File_Name => -1,
13044 Pragma_Source_File_Name_Project => -1,
13045 Pragma_Source_Reference => -1,
13046 Pragma_Storage_Size => -1,
13047 Pragma_Storage_Unit => -1,
13048 Pragma_Static_Elaboration_Desired => -1,
13049 Pragma_Stream_Convert => -1,
13050 Pragma_Style_Checks => -1,
13051 Pragma_Subtitle => -1,
13052 Pragma_Suppress => 0,
13053 Pragma_Suppress_Exception_Locations => 0,
13054 Pragma_Suppress_All => -1,
13055 Pragma_Suppress_Debug_Info => 0,
13056 Pragma_Suppress_Initialization => 0,
13057 Pragma_System_Name => -1,
13058 Pragma_Task_Dispatching_Policy => -1,
13059 Pragma_Task_Info => -1,
13060 Pragma_Task_Name => -1,
13061 Pragma_Task_Storage => 0,
13062 Pragma_Thread_Local_Storage => 0,
13063 Pragma_Time_Slice => -1,
13064 Pragma_Title => -1,
13065 Pragma_Unchecked_Union => 0,
13066 Pragma_Unimplemented_Unit => -1,
13067 Pragma_Universal_Aliasing => -1,
13068 Pragma_Universal_Data => -1,
13069 Pragma_Unmodified => -1,
13070 Pragma_Unreferenced => -1,
13071 Pragma_Unreferenced_Objects => -1,
13072 Pragma_Unreserve_All_Interrupts => -1,
13073 Pragma_Unsuppress => 0,
13074 Pragma_Use_VADS_Size => -1,
13075 Pragma_Validity_Checks => -1,
13076 Pragma_Volatile => 0,
13077 Pragma_Volatile_Components => 0,
13078 Pragma_Warnings => -1,
13079 Pragma_Weak_External => -1,
13080 Pragma_Wide_Character_Encoding => 0,
13081 Unknown_Pragma => 0);
13083 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
13092 if Nkind (P) /= N_Pragma_Argument_Association then
13096 Id := Get_Pragma_Id (Parent (P));
13097 C := Sig_Flags (Id);
13109 -- For pragma Check, the first argument is not significant,
13110 -- the second and the third (if present) arguments are
13113 when Pragma_Check =>
13115 P = First (Pragma_Argument_Associations (Parent (P)));
13118 raise Program_Error;
13122 A := First (Pragma_Argument_Associations (Parent (P)));
13123 for J in 1 .. C - 1 loop
13131 return A = P; -- is this wrong way round ???
13134 end Is_Non_Significant_Pragma_Reference;
13136 ------------------------------
13137 -- Is_Pragma_String_Literal --
13138 ------------------------------
13140 -- This function returns true if the corresponding pragma argument is a
13141 -- static string expression. These are the only cases in which string
13142 -- literals can appear as pragma arguments. We also allow a string literal
13143 -- as the first argument to pragma Assert (although it will of course
13144 -- always generate a type error).
13146 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13147 Pragn : constant Node_Id := Parent (Par);
13148 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13149 Pname : constant Name_Id := Pragma_Name (Pragn);
13155 N := First (Assoc);
13162 if Pname = Name_Assert then
13165 elsif Pname = Name_Export then
13168 elsif Pname = Name_Ident then
13171 elsif Pname = Name_Import then
13174 elsif Pname = Name_Interface_Name then
13177 elsif Pname = Name_Linker_Alias then
13180 elsif Pname = Name_Linker_Section then
13183 elsif Pname = Name_Machine_Attribute then
13186 elsif Pname = Name_Source_File_Name then
13189 elsif Pname = Name_Source_Reference then
13192 elsif Pname = Name_Title then
13195 elsif Pname = Name_Subtitle then
13201 end Is_Pragma_String_Literal;
13203 --------------------------------------
13204 -- Process_Compilation_Unit_Pragmas --
13205 --------------------------------------
13207 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13209 -- A special check for pragma Suppress_All, a very strange DEC pragma,
13210 -- strange because it comes at the end of the unit. If we have a pragma
13211 -- Suppress_All in the Pragmas_After of the current unit, then we insert
13212 -- a pragma Suppress (All_Checks) at the start of the context clause to
13213 -- ensure the correct processing.
13216 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
13220 if Present (PA) then
13222 while Present (P) loop
13223 if Pragma_Name (P) = Name_Suppress_All then
13224 Prepend_To (Context_Items (N),
13225 Make_Pragma (Sloc (P),
13226 Chars => Name_Suppress,
13227 Pragma_Argument_Associations => New_List (
13228 Make_Pragma_Argument_Association (Sloc (P),
13230 Make_Identifier (Sloc (P),
13231 Chars => Name_All_Checks)))));
13239 end Process_Compilation_Unit_Pragmas;
13250 --------------------------------
13251 -- Set_Encoded_Interface_Name --
13252 --------------------------------
13254 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13255 Str : constant String_Id := Strval (S);
13256 Len : constant Int := String_Length (Str);
13261 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13264 -- Stores encoded value of character code CC. The encoding we use an
13265 -- underscore followed by four lower case hex digits.
13271 procedure Encode is
13273 Store_String_Char (Get_Char_Code ('_'));
13275 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13277 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13279 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13281 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13284 -- Start of processing for Set_Encoded_Interface_Name
13287 -- If first character is asterisk, this is a link name, and we leave it
13288 -- completely unmodified. We also ignore null strings (the latter case
13289 -- happens only in error cases) and no encoding should occur for Java or
13290 -- AAMP interface names.
13293 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13294 or else VM_Target /= No_VM
13295 or else AAMP_On_Target
13297 Set_Interface_Name (E, S);
13302 CC := Get_String_Char (Str, J);
13304 exit when not In_Character_Range (CC);
13306 C := Get_Character (CC);
13308 exit when C /= '_' and then C /= '$'
13309 and then C not in '0' .. '9'
13310 and then C not in 'a' .. 'z'
13311 and then C not in 'A' .. 'Z';
13314 Set_Interface_Name (E, S);
13322 -- Here we need to encode. The encoding we use as follows:
13323 -- three underscores + four hex digits (lower case)
13327 for J in 1 .. String_Length (Str) loop
13328 CC := Get_String_Char (Str, J);
13330 if not In_Character_Range (CC) then
13333 C := Get_Character (CC);
13335 if C = '_' or else C = '$'
13336 or else C in '0' .. '9'
13337 or else C in 'a' .. 'z'
13338 or else C in 'A' .. 'Z'
13340 Store_String_Char (CC);
13347 Set_Interface_Name (E,
13348 Make_String_Literal (Sloc (S),
13349 Strval => End_String));
13351 end Set_Encoded_Interface_Name;
13353 -------------------
13354 -- Set_Unit_Name --
13355 -------------------
13357 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13362 if Nkind (N) = N_Identifier
13363 and then Nkind (With_Item) = N_Identifier
13365 Set_Entity (N, Entity (With_Item));
13367 elsif Nkind (N) = N_Selected_Component then
13368 Change_Selected_Component_To_Expanded_Name (N);
13369 Set_Entity (N, Entity (With_Item));
13370 Set_Entity (Selector_Name (N), Entity (N));
13372 Pref := Prefix (N);
13373 Scop := Scope (Entity (N));
13374 while Nkind (Pref) = N_Selected_Component loop
13375 Change_Selected_Component_To_Expanded_Name (Pref);
13376 Set_Entity (Selector_Name (Pref), Scop);
13377 Set_Entity (Pref, Scop);
13378 Pref := Prefix (Pref);
13379 Scop := Scope (Scop);
13382 Set_Entity (Pref, Scop);