1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Errout; use Errout;
39 with Exp_Dist; use Exp_Dist;
41 with Lib.Writ; use Lib.Writ;
42 with Lib.Xref; use Lib.Xref;
43 with Namet.Sp; use Namet.Sp;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Output; use Output;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Ch3; use Sem_Ch3;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch12; use Sem_Ch12;
57 with Sem_Ch13; use Sem_Ch13;
58 with Sem_Dist; use Sem_Dist;
59 with Sem_Elim; use Sem_Elim;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Intr; use Sem_Intr;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Res; use Sem_Res;
64 with Sem_Type; use Sem_Type;
65 with Sem_Util; use Sem_Util;
66 with Sem_VFpt; use Sem_VFpt;
67 with Sem_Warn; use Sem_Warn;
68 with Stand; use Stand;
69 with Sinfo; use Sinfo;
70 with Sinfo.CN; use Sinfo.CN;
71 with Sinput; use Sinput;
72 with Snames; use Snames;
73 with Stringt; use Stringt;
74 with Stylesw; use Stylesw;
76 with Targparm; use Targparm;
77 with Tbuild; use Tbuild;
79 with Uintp; use Uintp;
80 with Uname; use Uname;
81 with Urealp; use Urealp;
82 with Validsw; use Validsw;
84 package body Sem_Prag is
86 ----------------------------------------------
87 -- Common Handling of Import-Export Pragmas --
88 ----------------------------------------------
90 -- In the following section, a number of Import_xxx and Export_xxx
91 -- pragmas are defined by GNAT. These are compatible with the DEC
92 -- pragmas of the same name, and all have the following common
93 -- form and processing:
96 -- [Internal =>] LOCAL_NAME
97 -- [, [External =>] EXTERNAL_SYMBOL]
98 -- [, other optional parameters ]);
101 -- [Internal =>] LOCAL_NAME
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
105 -- EXTERNAL_SYMBOL ::=
107 -- | static_string_EXPRESSION
109 -- The internal LOCAL_NAME designates the entity that is imported or
110 -- exported, and must refer to an entity in the current declarative
111 -- part (as required by the rules for LOCAL_NAME).
113 -- The external linker name is designated by the External parameter
114 -- if given, or the Internal parameter if not (if there is no External
115 -- parameter, the External parameter is a copy of the Internal name).
117 -- If the External parameter is given as a string, then this string
118 -- is treated as an external name (exactly as though it had been given
119 -- as an External_Name parameter for a normal Import pragma).
121 -- If the External parameter is given as an identifier (or there is no
122 -- External parameter, so that the Internal identifier is used), then
123 -- the external name is the characters of the identifier, translated
124 -- to all upper case letters for OpenVMS versions of GNAT, and to all
125 -- lower case letters for all other versions
127 -- Note: the external name specified or implied by any of these special
128 -- Import_xxx or Export_xxx pragmas override an external or link name
129 -- specified in a previous Import or Export pragma.
131 -- Note: these and all other DEC-compatible GNAT pragmas allow full
132 -- use of named notation, following the standard rules for subprogram
133 -- calls, i.e. parameters can be given in any order if named notation
134 -- is used, and positional and named notation can be mixed, subject to
135 -- the rule that all positional parameters must appear first.
137 -- Note: All these pragmas are implemented exactly following the DEC
138 -- design and implementation and are intended to be fully compatible
139 -- with the use of these pragmas in the DEC Ada compiler.
141 --------------------------------------------
142 -- Checking for Duplicated External Names --
143 --------------------------------------------
145 -- It is suspicious if two separate Export pragmas use the same external
146 -- name. The following table is used to diagnose this situation so that
147 -- an appropriate warning can be issued.
149 -- The Node_Id stored is for the N_String_Literal node created to
150 -- hold the value of the external name. The Sloc of this node is
151 -- used to cross-reference the location of the duplication.
153 package Externals is new Table.Table (
154 Table_Component_Type => Node_Id,
155 Table_Index_Type => Int,
156 Table_Low_Bound => 0,
157 Table_Initial => 100,
158 Table_Increment => 100,
159 Table_Name => "Name_Externals");
161 -------------------------------------
162 -- Local Subprograms and Variables --
163 -------------------------------------
165 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
166 -- This routine is used for possible casing adjustment of an explicit
167 -- external name supplied as a string literal (the node N), according
168 -- to the casing requirement of Opt.External_Name_Casing. If this is
169 -- set to As_Is, then the string literal is returned unchanged, but if
170 -- it is set to Uppercase or Lowercase, then a new string literal with
171 -- appropriate casing is constructed.
173 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
174 -- If Def_Id refers to a renamed subprogram, then the base subprogram
175 -- (the original one, following the renaming chain) is returned.
176 -- Otherwise the entity is returned unchanged. Should be in Einfo???
178 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
179 -- All the routines that check pragma arguments take either a pragma
180 -- argument association (in which case the expression of the argument
181 -- association is checked), or the expression directly. The function
182 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
183 -- is a pragma argument association node, then its expression is returned,
184 -- otherwise Arg is returned unchanged.
187 -- This is a dummy function called by the processing for pragma Reviewable.
188 -- It is there for assisting front end debugging. By placing a Reviewable
189 -- pragma in the source program, a breakpoint on rv catches this place in
190 -- the source, allowing convenient stepping to the point of interest.
192 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
193 -- Place semantic information on the argument of an Elaborate or
194 -- Elaborate_All pragma. Entity name for unit and its parents is
195 -- taken from item in previous with_clause that mentions the unit.
197 -------------------------------
198 -- Adjust_External_Name_Case --
199 -------------------------------
201 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205 -- Adjust case of literal if required
207 if Opt.External_Name_Exp_Casing = As_Is then
211 -- Copy existing string
217 for J in 1 .. String_Length (Strval (N)) loop
218 CC := Get_String_Char (Strval (N), J);
220 if Opt.External_Name_Exp_Casing = Uppercase
221 and then CC >= Get_Char_Code ('a')
222 and then CC <= Get_Char_Code ('z')
224 Store_String_Char (CC - 32);
226 elsif Opt.External_Name_Exp_Casing = Lowercase
227 and then CC >= Get_Char_Code ('A')
228 and then CC <= Get_Char_Code ('Z')
230 Store_String_Char (CC + 32);
233 Store_String_Char (CC);
238 Make_String_Literal (Sloc (N),
239 Strval => End_String);
241 end Adjust_External_Name_Case;
243 ------------------------------
244 -- Analyze_PPC_In_Decl_Part --
245 ------------------------------
247 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
248 Arg1 : constant Node_Id :=
249 First (Pragma_Argument_Associations (N));
250 Arg2 : constant Node_Id := Next (Arg1);
253 -- Install formals and push subprogram spec onto scope stack
254 -- so that we can see the formals from the pragma.
259 -- Preanalyze the boolean expression, we treat this as a
260 -- spec expression (i.e. similar to a default expression).
262 Preanalyze_Spec_Expression
263 (Get_Pragma_Arg (Arg1), Standard_Boolean);
265 -- If there is a message argument, analyze it the same way
267 if Present (Arg2) then
268 Preanalyze_Spec_Expression
269 (Get_Pragma_Arg (Arg2), Standard_String);
272 -- Remove the subprogram from the scope stack now that the
273 -- pre-analysis of the precondition/postcondition is done.
276 end Analyze_PPC_In_Decl_Part;
282 procedure Analyze_Pragma (N : Node_Id) is
283 Loc : constant Source_Ptr := Sloc (N);
284 Pname : constant Name_Id := Pragma_Name (N);
287 Pragma_Exit : exception;
288 -- This exception is used to exit pragma processing completely. It
289 -- is used when an error is detected, and no further processing is
290 -- required. It is also used if an earlier error has left the tree
291 -- in a state where the pragma should not be processed.
294 -- Number of pragma argument associations
300 -- First four pragma arguments (pragma argument association nodes,
301 -- or Empty if the corresponding argument does not exist).
303 type Name_List is array (Natural range <>) of Name_Id;
304 type Args_List is array (Natural range <>) of Node_Id;
305 -- Types used for arguments to Check_Arg_Order and Gather_Associations
307 procedure Ada_2005_Pragma;
308 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
309 -- Ada 95 mode, these are implementation defined pragmas, so should be
310 -- caught by the No_Implementation_Pragmas restriction
312 procedure Check_Ada_83_Warning;
313 -- Issues a warning message for the current pragma if operating in Ada
314 -- 83 mode (used for language pragmas that are not a standard part of
315 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
318 procedure Check_Arg_Count (Required : Nat);
319 -- Check argument count for pragma is equal to given parameter.
320 -- If not, then issue an error message and raise Pragma_Exit.
322 -- Note: all routines whose name is Check_Arg_Is_xxx take an
323 -- argument Arg which can either be a pragma argument association,
324 -- in which case the check is applied to the expression of the
325 -- association or an expression directly.
327 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
328 -- Check that an argument has the right form for an EXTERNAL_NAME
329 -- parameter of an extended import/export pragma. The rule is that
330 -- the name must be an identifier or string literal (in Ada 83 mode)
331 -- or a static string expression (in Ada 95 mode).
333 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
334 -- Check the specified argument Arg to make sure that it is an
335 -- identifier. If not give error and raise Pragma_Exit.
337 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
338 -- Check the specified argument Arg to make sure that it is an
339 -- integer literal. If not give error and raise Pragma_Exit.
341 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
342 -- Check the specified argument Arg to make sure that it has the
343 -- proper syntactic form for a local name and meets the semantic
344 -- requirements for a local name. The local name is analyzed as
345 -- part of the processing for this call. In addition, the local
346 -- name is required to represent an entity at the library level.
348 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
349 -- Check the specified argument Arg to make sure that it has the
350 -- proper syntactic form for a local name and meets the semantic
351 -- requirements for a local name. The local name is analyzed as
352 -- part of the processing for this call.
354 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
355 -- Check the specified argument Arg to make sure that it is a valid
356 -- locking policy name. If not give error and raise Pragma_Exit.
358 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
359 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
360 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
361 -- Check the specified argument Arg to make sure that it is an
362 -- identifier whose name matches either N1 or N2 (or N3 if present).
363 -- If not then give error and raise Pragma_Exit.
365 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
366 -- Check the specified argument Arg to make sure that it is a valid
367 -- queuing policy name. If not give error and raise Pragma_Exit.
369 procedure Check_Arg_Is_Static_Expression
372 -- Check the specified argument Arg to make sure that it is a static
373 -- expression of the given type (i.e. it will be analyzed and resolved
374 -- using this type, which can be any valid argument to Resolve, e.g.
375 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
377 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
378 -- Check the specified argument Arg to make sure that it is a
379 -- string literal. If not give error and raise Pragma_Exit
381 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
382 -- Check the specified argument Arg to make sure that it is a valid
383 -- valid task dispatching policy name. If not give error and raise
386 procedure Check_Arg_Order (Names : Name_List);
387 -- Checks for an instance of two arguments with identifiers for the
388 -- current pragma which are not in the sequence indicated by Names,
389 -- and if so, generates a fatal message about bad order of arguments.
391 procedure Check_At_Least_N_Arguments (N : Nat);
392 -- Check there are at least N arguments present
394 procedure Check_At_Most_N_Arguments (N : Nat);
395 -- Check there are no more than N arguments present
397 procedure Check_Component (Comp : Node_Id);
398 -- Examine Unchecked_Union component for correct use of per-object
399 -- constrained subtypes, and for restrictions on finalizable components.
401 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
402 -- Nam is an N_String_Literal node containing the external name set
403 -- by an Import or Export pragma (or extended Import or Export pragma).
404 -- This procedure checks for possible duplications if this is the
405 -- export case, and if found, issues an appropriate error message.
407 procedure Check_First_Subtype (Arg : Node_Id);
408 -- Checks that Arg, whose expression is an entity name referencing
409 -- a subtype, does not reference a type that is not a first subtype.
411 procedure Check_In_Main_Program;
412 -- Common checks for pragmas that appear within a main program
413 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
415 procedure Check_Interrupt_Or_Attach_Handler;
416 -- Common processing for first argument of pragma Interrupt_Handler
417 -- or pragma Attach_Handler.
419 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
420 -- Check that pragma appears in a declarative part, or in a package
421 -- specification, i.e. that it does not occur in a statement sequence
424 procedure Check_No_Identifier (Arg : Node_Id);
425 -- Checks that the given argument does not have an identifier. If
426 -- an identifier is present, then an error message is issued, and
427 -- Pragma_Exit is raised.
429 procedure Check_No_Identifiers;
430 -- Checks that none of the arguments to the pragma has an identifier.
431 -- If any argument has an identifier, then an error message is issued,
432 -- and Pragma_Exit is raised.
434 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
435 -- Checks if the given argument has an identifier, and if so, requires
436 -- it to match the given identifier name. If there is a non-matching
437 -- identifier, then an error message is given and Error_Pragmas raised.
439 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
440 -- Checks if the given argument has an identifier, and if so, requires
441 -- it to match the given identifier name. If there is a non-matching
442 -- identifier, then an error message is given and Error_Pragmas raised.
443 -- In this version of the procedure, the identifier name is given as
444 -- a string with lower case letters.
446 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
447 -- Called to process a precondition or postcondition pragma. There are
450 -- The pragma appears after a subprogram spec
452 -- If the corresponding check is not enabled, the pragma is analyzed
453 -- but otherwise ignored and control returns with In_Body set False.
455 -- If the check is enabled, then the first step is to analyze the
456 -- pragma, but this is skipped if the subprogram spec appears within
457 -- a package specification (because this is the case where we delay
458 -- analysis till the end of the spec). Then (whether or not it was
459 -- analyzed), the pragma is chained to the subprogram in question
460 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
461 -- caller with In_Body set False.
463 -- The pragma appears at the start of subprogram body declarations
465 -- In this case an immediate return to the caller is made with
466 -- In_Body set True, and the pragma is NOT analyzed.
468 -- In all other cases, an error message for bad placement is given
470 procedure Check_Static_Constraint (Constr : Node_Id);
471 -- Constr is a constraint from an N_Subtype_Indication node from a
472 -- component constraint in an Unchecked_Union type. This routine checks
473 -- that the constraint is static as required by the restrictions for
476 procedure Check_Valid_Configuration_Pragma;
477 -- Legality checks for placement of a configuration pragma
479 procedure Check_Valid_Library_Unit_Pragma;
480 -- Legality checks for library unit pragmas. A special case arises for
481 -- pragmas in generic instances that come from copies of the original
482 -- library unit pragmas in the generic templates. In the case of other
483 -- than library level instantiations these can appear in contexts which
484 -- would normally be invalid (they only apply to the original template
485 -- and to library level instantiations), and they are simply ignored,
486 -- which is implemented by rewriting them as null statements.
488 procedure Check_Variant (Variant : Node_Id);
489 -- Check Unchecked_Union variant for lack of nested variants and
490 -- presence of at least one component.
492 procedure Error_Pragma (Msg : String);
493 pragma No_Return (Error_Pragma);
494 -- Outputs error message for current pragma. The message contains a %
495 -- that will be replaced with the pragma name, and the flag is placed
496 -- on the pragma itself. Pragma_Exit is then raised.
498 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
499 pragma No_Return (Error_Pragma_Arg);
500 -- Outputs error message for current pragma. The message may contain
501 -- a % that will be replaced with the pragma name. The parameter Arg
502 -- may either be a pragma argument association, in which case the flag
503 -- is placed on the expression of this association, or an expression,
504 -- in which case the flag is placed directly on the expression. The
505 -- message is placed using Error_Msg_N, so the message may also contain
506 -- an & insertion character which will reference the given Arg value.
507 -- After placing the message, Pragma_Exit is raised.
509 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
510 pragma No_Return (Error_Pragma_Arg);
511 -- Similar to above form of Error_Pragma_Arg except that two messages
512 -- are provided, the second is a continuation comment starting with \.
514 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
515 pragma No_Return (Error_Pragma_Arg_Ident);
516 -- Outputs error message for current pragma. The message may contain
517 -- a % that will be replaced with the pragma name. The parameter Arg
518 -- must be a pragma argument association with a non-empty identifier
519 -- (i.e. its Chars field must be set), and the error message is placed
520 -- on the identifier. The message is placed using Error_Msg_N so
521 -- the message may also contain an & insertion character which will
522 -- reference the identifier. After placing the message, Pragma_Exit
525 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
526 pragma No_Return (Error_Pragma_Ref);
527 -- Outputs error message for current pragma. The message may contain
528 -- a % that will be replaced with the pragma name. The parameter Ref
529 -- must be an entity whose name can be referenced by & and sloc by #.
530 -- After placing the message, Pragma_Exit is raised.
532 function Find_Lib_Unit_Name return Entity_Id;
533 -- Used for a library unit pragma to find the entity to which the
534 -- library unit pragma applies, returns the entity found.
536 procedure Find_Program_Unit_Name (Id : Node_Id);
537 -- If the pragma is a compilation unit pragma, the id must denote the
538 -- compilation unit in the same compilation, and the pragma must appear
539 -- in the list of preceding or trailing pragmas. If it is a program
540 -- unit pragma that is not a compilation unit pragma, then the
541 -- identifier must be visible.
543 function Find_Unique_Parameterless_Procedure
545 Arg : Node_Id) return Entity_Id;
546 -- Used for a procedure pragma to find the unique parameterless
547 -- procedure identified by Name, returns it if it exists, otherwise
548 -- errors out and uses Arg as the pragma argument for the message.
550 procedure Gather_Associations
552 Args : out Args_List);
553 -- This procedure is used to gather the arguments for a pragma that
554 -- permits arbitrary ordering of parameters using the normal rules
555 -- for named and positional parameters. The Names argument is a list
556 -- of Name_Id values that corresponds to the allowed pragma argument
557 -- association identifiers in order. The result returned in Args is
558 -- a list of corresponding expressions that are the pragma arguments.
559 -- Note that this is a list of expressions, not of pragma argument
560 -- associations (Gather_Associations has completely checked all the
561 -- optional identifiers when it returns). An entry in Args is Empty
562 -- on return if the corresponding argument is not present.
564 procedure GNAT_Pragma;
565 -- Called for all GNAT defined pragmas to check the relevant restriction
566 -- (No_Implementation_Pragmas).
568 function Is_Before_First_Decl
569 (Pragma_Node : Node_Id;
570 Decls : List_Id) return Boolean;
571 -- Return True if Pragma_Node is before the first declarative item in
572 -- Decls where Decls is the list of declarative items.
574 function Is_Configuration_Pragma return Boolean;
575 -- Determines if the placement of the current pragma is appropriate
576 -- for a configuration pragma.
578 function Is_In_Context_Clause return Boolean;
579 -- Returns True if pragma appears within the context clause of a unit,
580 -- and False for any other placement (does not generate any messages).
582 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
583 -- Analyzes the argument, and determines if it is a static string
584 -- expression, returns True if so, False if non-static or not String.
586 procedure Pragma_Misplaced;
587 pragma No_Return (Pragma_Misplaced);
588 -- Issue fatal error message for misplaced pragma
590 procedure Process_Atomic_Shared_Volatile;
591 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
592 -- Shared is an obsolete Ada 83 pragma, treated as being identical
593 -- in effect to pragma Atomic.
595 procedure Process_Compile_Time_Warning_Or_Error;
596 -- Common processing for Compile_Time_Error and Compile_Time_Warning
598 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
599 -- Common processing for Convention, Interface, Import and Export.
600 -- Checks first two arguments of pragma, and sets the appropriate
601 -- convention value in the specified entity or entities. On return
602 -- C is the convention, E is the referenced entity.
604 procedure Process_Extended_Import_Export_Exception_Pragma
605 (Arg_Internal : Node_Id;
606 Arg_External : Node_Id;
609 -- Common processing for the pragmas Import/Export_Exception.
610 -- The three arguments correspond to the three named parameters of
611 -- the pragma. An argument is empty if the corresponding parameter
612 -- is not present in the pragma.
614 procedure Process_Extended_Import_Export_Object_Pragma
615 (Arg_Internal : Node_Id;
616 Arg_External : Node_Id;
618 -- Common processing for the pragmas Import/Export_Object.
619 -- The three arguments correspond to the three named parameters
620 -- of the pragmas. An argument is empty if the corresponding
621 -- parameter is not present in the pragma.
623 procedure Process_Extended_Import_Export_Internal_Arg
624 (Arg_Internal : Node_Id := Empty);
625 -- Common processing for all extended Import and Export pragmas. The
626 -- argument is the pragma parameter for the Internal argument. If
627 -- Arg_Internal is empty or inappropriate, an error message is posted.
628 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
629 -- set to identify the referenced entity.
631 procedure Process_Extended_Import_Export_Subprogram_Pragma
632 (Arg_Internal : Node_Id;
633 Arg_External : Node_Id;
634 Arg_Parameter_Types : Node_Id;
635 Arg_Result_Type : Node_Id := Empty;
636 Arg_Mechanism : Node_Id;
637 Arg_Result_Mechanism : Node_Id := Empty;
638 Arg_First_Optional_Parameter : Node_Id := Empty);
639 -- Common processing for all extended Import and Export pragmas
640 -- applying to subprograms. The caller omits any arguments that do
641 -- not apply to the pragma in question (for example, Arg_Result_Type
642 -- can be non-Empty only in the Import_Function and Export_Function
643 -- cases). The argument names correspond to the allowed pragma
644 -- association identifiers.
646 procedure Process_Generic_List;
647 -- Common processing for Share_Generic and Inline_Generic
649 procedure Process_Import_Or_Interface;
650 -- Common processing for Import of Interface
652 procedure Process_Inline (Active : Boolean);
653 -- Common processing for Inline and Inline_Always. The parameter
654 -- indicates if the inline pragma is active, i.e. if it should
655 -- actually cause inlining to occur.
657 procedure Process_Interface_Name
658 (Subprogram_Def : Entity_Id;
661 -- Given the last two arguments of pragma Import, pragma Export, or
662 -- pragma Interface_Name, performs validity checks and sets the
663 -- Interface_Name field of the given subprogram entity to the
664 -- appropriate external or link name, depending on the arguments
665 -- given. Ext_Arg is always present, but Link_Arg may be missing.
666 -- Note that Ext_Arg may represent the Link_Name if Link_Arg is
667 -- missing, and appropriate named notation is used for Ext_Arg.
668 -- If neither Ext_Arg nor Link_Arg is present, the interface name
669 -- is set to the default from the subprogram name.
671 procedure Process_Interrupt_Or_Attach_Handler;
672 -- Common processing for Interrupt and Attach_Handler pragmas
674 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
675 -- Common processing for Restrictions and Restriction_Warnings pragmas.
676 -- Warn is True for Restriction_Warnings, or for Restrictions if the
677 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
678 -- is not set in the Restrictions case.
680 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
681 -- Common processing for Suppress and Unsuppress. The boolean parameter
682 -- Suppress_Case is True for the Suppress case, and False for the
685 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
686 -- This procedure sets the Is_Exported flag for the given entity,
687 -- checking that the entity was not previously imported. Arg is
688 -- the argument that specified the entity. A check is also made
689 -- for exporting inappropriate entities.
691 procedure Set_Extended_Import_Export_External_Name
692 (Internal_Ent : Entity_Id;
693 Arg_External : Node_Id);
694 -- Common processing for all extended import export pragmas. The first
695 -- argument, Internal_Ent, is the internal entity, which has already
696 -- been checked for validity by the caller. Arg_External is from the
697 -- Import or Export pragma, and may be null if no External parameter
698 -- was present. If Arg_External is present and is a non-null string
699 -- (a null string is treated as the default), then the Interface_Name
700 -- field of Internal_Ent is set appropriately.
702 procedure Set_Imported (E : Entity_Id);
703 -- This procedure sets the Is_Imported flag for the given entity,
704 -- checking that it is not previously exported or imported.
706 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
707 -- Mech is a parameter passing mechanism (see Import_Function syntax
708 -- for MECHANISM_NAME). This routine checks that the mechanism argument
709 -- has the right form, and if not issues an error message. If the
710 -- argument has the right form then the Mechanism field of Ent is
711 -- set appropriately.
713 procedure Set_Ravenscar_Profile (N : Node_Id);
714 -- Activate the set of configuration pragmas and restrictions that
715 -- make up the Ravenscar Profile. N is the corresponding pragma
716 -- node, which is used for error messages on any constructs
717 -- that violate the profile.
719 ---------------------
720 -- Ada_2005_Pragma --
721 ---------------------
723 procedure Ada_2005_Pragma is
725 if Ada_Version <= Ada_95 then
726 Check_Restriction (No_Implementation_Pragmas, N);
730 --------------------------
731 -- Check_Ada_83_Warning --
732 --------------------------
734 procedure Check_Ada_83_Warning is
736 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
737 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
739 end Check_Ada_83_Warning;
741 ---------------------
742 -- Check_Arg_Count --
743 ---------------------
745 procedure Check_Arg_Count (Required : Nat) is
747 if Arg_Count /= Required then
748 Error_Pragma ("wrong number of arguments for pragma%");
752 --------------------------------
753 -- Check_Arg_Is_External_Name --
754 --------------------------------
756 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
757 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
760 if Nkind (Argx) = N_Identifier then
764 Analyze_And_Resolve (Argx, Standard_String);
766 if Is_OK_Static_Expression (Argx) then
769 elsif Etype (Argx) = Any_Type then
772 -- An interesting special case, if we have a string literal and
773 -- we are in Ada 83 mode, then we allow it even though it will
774 -- not be flagged as static. This allows expected Ada 83 mode
775 -- use of external names which are string literals, even though
776 -- technically these are not static in Ada 83.
778 elsif Ada_Version = Ada_83
779 and then Nkind (Argx) = N_String_Literal
783 -- Static expression that raises Constraint_Error. This has
784 -- already been flagged, so just exit from pragma processing.
786 elsif Is_Static_Expression (Argx) then
789 -- Here we have a real error (non-static expression)
792 Error_Msg_Name_1 := Pname;
794 ("argument for pragma% must be a identifier or " &
795 "static string expression!", Argx);
799 end Check_Arg_Is_External_Name;
801 -----------------------------
802 -- Check_Arg_Is_Identifier --
803 -----------------------------
805 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
806 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
808 if Nkind (Argx) /= N_Identifier then
810 ("argument for pragma% must be identifier", Argx);
812 end Check_Arg_Is_Identifier;
814 ----------------------------------
815 -- Check_Arg_Is_Integer_Literal --
816 ----------------------------------
818 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
819 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
821 if Nkind (Argx) /= N_Integer_Literal then
823 ("argument for pragma% must be integer literal", Argx);
825 end Check_Arg_Is_Integer_Literal;
827 -------------------------------------------
828 -- Check_Arg_Is_Library_Level_Local_Name --
829 -------------------------------------------
833 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
834 -- | library_unit_NAME
836 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
838 Check_Arg_Is_Local_Name (Arg);
840 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
841 and then Comes_From_Source (N)
844 ("argument for pragma% must be library level entity", Arg);
846 end Check_Arg_Is_Library_Level_Local_Name;
848 -----------------------------
849 -- Check_Arg_Is_Local_Name --
850 -----------------------------
854 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
855 -- | library_unit_NAME
857 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
858 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
863 if Nkind (Argx) not in N_Direct_Name
864 and then (Nkind (Argx) /= N_Attribute_Reference
865 or else Present (Expressions (Argx))
866 or else Nkind (Prefix (Argx)) /= N_Identifier)
867 and then (not Is_Entity_Name (Argx)
868 or else not Is_Compilation_Unit (Entity (Argx)))
870 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
873 if Is_Entity_Name (Argx)
874 and then Scope (Entity (Argx)) /= Current_Scope
877 ("pragma% argument must be in same declarative part", Arg);
879 end Check_Arg_Is_Local_Name;
881 ---------------------------------
882 -- Check_Arg_Is_Locking_Policy --
883 ---------------------------------
885 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
886 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
889 Check_Arg_Is_Identifier (Argx);
891 if not Is_Locking_Policy_Name (Chars (Argx)) then
893 ("& is not a valid locking policy name", Argx);
895 end Check_Arg_Is_Locking_Policy;
897 -------------------------
898 -- Check_Arg_Is_One_Of --
899 -------------------------
901 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
902 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
905 Check_Arg_Is_Identifier (Argx);
907 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
908 Error_Msg_Name_2 := N1;
909 Error_Msg_Name_3 := N2;
910 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
912 end Check_Arg_Is_One_Of;
914 procedure Check_Arg_Is_One_Of
916 N1, N2, N3 : Name_Id)
918 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
921 Check_Arg_Is_Identifier (Argx);
923 if Chars (Argx) /= N1
924 and then Chars (Argx) /= N2
925 and then Chars (Argx) /= N3
927 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
929 end Check_Arg_Is_One_Of;
931 procedure Check_Arg_Is_One_Of
933 N1, N2, N3, N4 : Name_Id)
935 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
938 Check_Arg_Is_Identifier (Argx);
940 if Chars (Argx) /= N1
941 and then Chars (Argx) /= N2
942 and then Chars (Argx) /= N3
943 and then Chars (Argx) /= N4
945 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
947 end Check_Arg_Is_One_Of;
949 ---------------------------------
950 -- Check_Arg_Is_Queuing_Policy --
951 ---------------------------------
953 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
954 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
957 Check_Arg_Is_Identifier (Argx);
959 if not Is_Queuing_Policy_Name (Chars (Argx)) then
961 ("& is not a valid queuing policy name", Argx);
963 end Check_Arg_Is_Queuing_Policy;
965 ------------------------------------
966 -- Check_Arg_Is_Static_Expression --
967 ------------------------------------
969 procedure Check_Arg_Is_Static_Expression
973 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
976 Analyze_And_Resolve (Argx, Typ);
978 if Is_OK_Static_Expression (Argx) then
981 elsif Etype (Argx) = Any_Type then
984 -- An interesting special case, if we have a string literal and
985 -- we are in Ada 83 mode, then we allow it even though it will
986 -- not be flagged as static. This allows the use of Ada 95
987 -- pragmas like Import in Ada 83 mode. They will of course be
988 -- flagged with warnings as usual, but will not cause errors.
990 elsif Ada_Version = Ada_83
991 and then Nkind (Argx) = N_String_Literal
995 -- Static expression that raises Constraint_Error. This has
996 -- already been flagged, so just exit from pragma processing.
998 elsif Is_Static_Expression (Argx) then
1001 -- Finally, we have a real error
1004 Error_Msg_Name_1 := Pname;
1005 Flag_Non_Static_Expr
1006 ("argument for pragma% must be a static expression!", Argx);
1009 end Check_Arg_Is_Static_Expression;
1011 ---------------------------------
1012 -- Check_Arg_Is_String_Literal --
1013 ---------------------------------
1015 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1016 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1018 if Nkind (Argx) /= N_String_Literal then
1020 ("argument for pragma% must be string literal", Argx);
1022 end Check_Arg_Is_String_Literal;
1024 ------------------------------------------
1025 -- Check_Arg_Is_Task_Dispatching_Policy --
1026 ------------------------------------------
1028 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1029 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1032 Check_Arg_Is_Identifier (Argx);
1034 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1036 ("& is not a valid task dispatching policy name", Argx);
1038 end Check_Arg_Is_Task_Dispatching_Policy;
1040 ---------------------
1041 -- Check_Arg_Order --
1042 ---------------------
1044 procedure Check_Arg_Order (Names : Name_List) is
1047 Highest_So_Far : Natural := 0;
1048 -- Highest index in Names seen do far
1052 for J in 1 .. Arg_Count loop
1053 if Chars (Arg) /= No_Name then
1054 for K in Names'Range loop
1055 if Chars (Arg) = Names (K) then
1056 if K < Highest_So_Far then
1057 Error_Msg_Name_1 := Pname;
1059 ("parameters out of order for pragma%", Arg);
1060 Error_Msg_Name_1 := Names (K);
1061 Error_Msg_Name_2 := Names (Highest_So_Far);
1062 Error_Msg_N ("\% must appear before %", Arg);
1066 Highest_So_Far := K;
1074 end Check_Arg_Order;
1076 --------------------------------
1077 -- Check_At_Least_N_Arguments --
1078 --------------------------------
1080 procedure Check_At_Least_N_Arguments (N : Nat) is
1082 if Arg_Count < N then
1083 Error_Pragma ("too few arguments for pragma%");
1085 end Check_At_Least_N_Arguments;
1087 -------------------------------
1088 -- Check_At_Most_N_Arguments --
1089 -------------------------------
1091 procedure Check_At_Most_N_Arguments (N : Nat) is
1094 if Arg_Count > N then
1096 for J in 1 .. N loop
1098 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1101 end Check_At_Most_N_Arguments;
1103 ---------------------
1104 -- Check_Component --
1105 ---------------------
1107 procedure Check_Component (Comp : Node_Id) is
1109 if Nkind (Comp) = N_Component_Declaration then
1111 Sindic : constant Node_Id :=
1112 Subtype_Indication (Component_Definition (Comp));
1113 Typ : constant Entity_Id :=
1114 Etype (Defining_Identifier (Comp));
1116 if Nkind (Sindic) = N_Subtype_Indication then
1118 -- Ada 2005 (AI-216): If a component subtype is subject to
1119 -- a per-object constraint, then the component type shall
1120 -- be an Unchecked_Union.
1122 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1124 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1126 Error_Msg_N ("component subtype subject to per-object" &
1127 " constraint must be an Unchecked_Union", Comp);
1131 if Is_Controlled (Typ) then
1133 ("component of unchecked union cannot be controlled", Comp);
1135 elsif Has_Task (Typ) then
1137 ("component of unchecked union cannot have tasks", Comp);
1141 end Check_Component;
1143 ----------------------------------
1144 -- Check_Duplicated_Export_Name --
1145 ----------------------------------
1147 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1148 String_Val : constant String_Id := Strval (Nam);
1151 -- We are only interested in the export case, and in the case of
1152 -- generics, it is the instance, not the template, that is the
1153 -- problem (the template will generate a warning in any case).
1155 if not Inside_A_Generic
1156 and then (Prag_Id = Pragma_Export
1158 Prag_Id = Pragma_Export_Procedure
1160 Prag_Id = Pragma_Export_Valued_Procedure
1162 Prag_Id = Pragma_Export_Function)
1164 for J in Externals.First .. Externals.Last loop
1165 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1166 Error_Msg_Sloc := Sloc (Externals.Table (J));
1167 Error_Msg_N ("external name duplicates name given#", Nam);
1172 Externals.Append (Nam);
1174 end Check_Duplicated_Export_Name;
1176 -------------------------
1177 -- Check_First_Subtype --
1178 -------------------------
1180 procedure Check_First_Subtype (Arg : Node_Id) is
1181 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1183 if not Is_First_Subtype (Entity (Argx)) then
1185 ("pragma% cannot apply to subtype", Argx);
1187 end Check_First_Subtype;
1189 ---------------------------
1190 -- Check_In_Main_Program --
1191 ---------------------------
1193 procedure Check_In_Main_Program is
1194 P : constant Node_Id := Parent (N);
1197 -- Must be at in subprogram body
1199 if Nkind (P) /= N_Subprogram_Body then
1200 Error_Pragma ("% pragma allowed only in subprogram");
1202 -- Otherwise warn if obviously not main program
1204 elsif Present (Parameter_Specifications (Specification (P)))
1205 or else not Is_Compilation_Unit (Defining_Entity (P))
1207 Error_Msg_Name_1 := Pname;
1209 ("?pragma% is only effective in main program", N);
1211 end Check_In_Main_Program;
1213 ---------------------------------------
1214 -- Check_Interrupt_Or_Attach_Handler --
1215 ---------------------------------------
1217 procedure Check_Interrupt_Or_Attach_Handler is
1218 Arg1_X : constant Node_Id := Expression (Arg1);
1219 Handler_Proc, Proc_Scope : Entity_Id;
1224 if Prag_Id = Pragma_Interrupt_Handler then
1225 Check_Restriction (No_Dynamic_Attachment, N);
1228 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1229 Proc_Scope := Scope (Handler_Proc);
1231 -- On AAMP only, a pragma Interrupt_Handler is supported for
1232 -- nonprotected parameterless procedures.
1234 if not AAMP_On_Target
1235 or else Prag_Id = Pragma_Attach_Handler
1237 if Ekind (Proc_Scope) /= E_Protected_Type then
1239 ("argument of pragma% must be protected procedure", Arg1);
1242 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1243 Error_Pragma ("pragma% must be in protected definition");
1247 if not Is_Library_Level_Entity (Proc_Scope)
1248 or else (AAMP_On_Target
1249 and then not Is_Library_Level_Entity (Handler_Proc))
1252 ("argument for pragma% must be library level entity", Arg1);
1254 end Check_Interrupt_Or_Attach_Handler;
1256 -------------------------------------------
1257 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1258 -------------------------------------------
1260 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1269 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1272 elsif Nkind (P) = N_Package_Specification then
1275 elsif Nkind (P) = N_Block_Statement then
1278 -- Note: the following tests seem a little peculiar, because
1279 -- they test for bodies, but if we were in the statement part
1280 -- of the body, we would already have hit the handled statement
1281 -- sequence, so the only way we get here is by being in the
1282 -- declarative part of the body.
1284 elsif Nkind (P) = N_Subprogram_Body
1285 or else Nkind (P) = N_Package_Body
1286 or else Nkind (P) = N_Task_Body
1287 or else Nkind (P) = N_Entry_Body
1295 Error_Pragma ("pragma% is not in declarative part or package spec");
1296 end Check_Is_In_Decl_Part_Or_Package_Spec;
1298 -------------------------
1299 -- Check_No_Identifier --
1300 -------------------------
1302 procedure Check_No_Identifier (Arg : Node_Id) is
1304 if Chars (Arg) /= No_Name then
1305 Error_Pragma_Arg_Ident
1306 ("pragma% does not permit identifier& here", Arg);
1308 end Check_No_Identifier;
1310 --------------------------
1311 -- Check_No_Identifiers --
1312 --------------------------
1314 procedure Check_No_Identifiers is
1317 if Arg_Count > 0 then
1319 while Present (Arg_Node) loop
1320 Check_No_Identifier (Arg_Node);
1324 end Check_No_Identifiers;
1326 -------------------------------
1327 -- Check_Optional_Identifier --
1328 -------------------------------
1330 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1332 if Present (Arg) and then Chars (Arg) /= No_Name then
1333 if Chars (Arg) /= Id then
1334 Error_Msg_Name_1 := Pname;
1335 Error_Msg_Name_2 := Id;
1336 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1340 end Check_Optional_Identifier;
1342 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1344 Name_Buffer (1 .. Id'Length) := Id;
1345 Name_Len := Id'Length;
1346 Check_Optional_Identifier (Arg, Name_Find);
1347 end Check_Optional_Identifier;
1349 --------------------------------------
1350 -- Check_Precondition_Postcondition --
1351 --------------------------------------
1353 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1357 procedure Chain_PPC (PO : Node_Id);
1358 -- If PO is a subprogram declaration node (or a generic subprogram
1359 -- declaration node), then the precondition/postcondition applies
1360 -- to this subprogram and the processing for the pragma is completed.
1361 -- Otherwise the pragma is misplaced.
1367 procedure Chain_PPC (PO : Node_Id) is
1371 if not Nkind_In (PO, N_Subprogram_Declaration,
1372 N_Generic_Subprogram_Declaration)
1377 -- Here if we have subprogram or generic subprogram declaration
1379 S := Defining_Unit_Name (Specification (PO));
1381 -- Analyze the pragma unless it appears within a package spec,
1382 -- which is the case where we delay the analysis of the PPC until
1383 -- the end of the package declarations (for details, see
1384 -- Analyze_Package_Specification.Analyze_PPCs).
1386 if Ekind (Scope (S)) /= E_Package
1388 Ekind (Scope (S)) /= E_Generic_Package
1390 Analyze_PPC_In_Decl_Part (N, S);
1393 -- Chain spec PPC pragma to list for subprogram
1395 Set_Next_Pragma (N, Spec_PPC_List (S));
1396 Set_Spec_PPC_List (S, N);
1398 -- Return indicating spec case
1404 -- Start of processing for Check_Precondition_Postcondition
1407 if not Is_List_Member (N) then
1411 -- Record whether pragma is enabled
1413 Set_PPC_Enabled (N, Check_Enabled (Pname));
1415 -- If we are within an inlined body, the legality of the pragma
1416 -- has been checked already.
1418 if In_Inlined_Body then
1423 -- Search prior declarations
1426 while Present (Prev (P)) loop
1428 PO := Original_Node (P);
1430 -- Skip past prior pragma
1432 if Nkind (PO) = N_Pragma then
1435 -- Skip stuff not coming from source
1437 elsif not Comes_From_Source (PO) then
1440 -- Only remaining possibility is subprogram declaration
1448 -- If we fall through loop, pragma is at start of list, so see if
1449 -- it is at the start of declarations of a subprogram body.
1451 if Nkind (Parent (N)) = N_Subprogram_Body
1452 and then List_Containing (N) = Declarations (Parent (N))
1454 if Operating_Mode /= Generate_Code then
1456 -- Analyze expression in pragma, for correctness
1457 -- and for ASIS use.
1459 Preanalyze_Spec_Expression
1460 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1466 -- See if it is in the pragmas after a library level subprogram
1468 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1469 Chain_PPC (Unit (Parent (Parent (N))));
1473 -- If we fall through, pragma was misplaced
1476 end Check_Precondition_Postcondition;
1478 -----------------------------
1479 -- Check_Static_Constraint --
1480 -----------------------------
1482 -- Note: for convenience in writing this procedure, in addition to
1483 -- the officially (i.e. by spec) allowed argument which is always
1484 -- a constraint, it also allows ranges and discriminant associations.
1485 -- Above is not clear ???
1487 procedure Check_Static_Constraint (Constr : Node_Id) is
1489 procedure Require_Static (E : Node_Id);
1490 -- Require given expression to be static expression
1492 --------------------
1493 -- Require_Static --
1494 --------------------
1496 procedure Require_Static (E : Node_Id) is
1498 if not Is_OK_Static_Expression (E) then
1499 Flag_Non_Static_Expr
1500 ("non-static constraint not allowed in Unchecked_Union!", E);
1505 -- Start of processing for Check_Static_Constraint
1508 case Nkind (Constr) is
1509 when N_Discriminant_Association =>
1510 Require_Static (Expression (Constr));
1513 Require_Static (Low_Bound (Constr));
1514 Require_Static (High_Bound (Constr));
1516 when N_Attribute_Reference =>
1517 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1518 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1520 when N_Range_Constraint =>
1521 Check_Static_Constraint (Range_Expression (Constr));
1523 when N_Index_Or_Discriminant_Constraint =>
1527 IDC := First (Constraints (Constr));
1528 while Present (IDC) loop
1529 Check_Static_Constraint (IDC);
1537 end Check_Static_Constraint;
1539 --------------------------------------
1540 -- Check_Valid_Configuration_Pragma --
1541 --------------------------------------
1543 -- A configuration pragma must appear in the context clause of a
1544 -- compilation unit, and only other pragmas may precede it. Note that
1545 -- the test also allows use in a configuration pragma file.
1547 procedure Check_Valid_Configuration_Pragma is
1549 if not Is_Configuration_Pragma then
1550 Error_Pragma ("incorrect placement for configuration pragma%");
1552 end Check_Valid_Configuration_Pragma;
1554 -------------------------------------
1555 -- Check_Valid_Library_Unit_Pragma --
1556 -------------------------------------
1558 procedure Check_Valid_Library_Unit_Pragma is
1560 Parent_Node : Node_Id;
1561 Unit_Name : Entity_Id;
1562 Unit_Kind : Node_Kind;
1563 Unit_Node : Node_Id;
1564 Sindex : Source_File_Index;
1567 if not Is_List_Member (N) then
1571 Plist := List_Containing (N);
1572 Parent_Node := Parent (Plist);
1574 if Parent_Node = Empty then
1577 -- Case of pragma appearing after a compilation unit. In this
1578 -- case it must have an argument with the corresponding name
1579 -- and must be part of the following pragmas of its parent.
1581 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1582 if Plist /= Pragmas_After (Parent_Node) then
1585 elsif Arg_Count = 0 then
1587 ("argument required if outside compilation unit");
1590 Check_No_Identifiers;
1591 Check_Arg_Count (1);
1592 Unit_Node := Unit (Parent (Parent_Node));
1593 Unit_Kind := Nkind (Unit_Node);
1595 Analyze (Expression (Arg1));
1597 if Unit_Kind = N_Generic_Subprogram_Declaration
1598 or else Unit_Kind = N_Subprogram_Declaration
1600 Unit_Name := Defining_Entity (Unit_Node);
1602 elsif Unit_Kind in N_Generic_Instantiation then
1603 Unit_Name := Defining_Entity (Unit_Node);
1606 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1609 if Chars (Unit_Name) /=
1610 Chars (Entity (Expression (Arg1)))
1613 ("pragma% argument is not current unit name", Arg1);
1616 if Ekind (Unit_Name) = E_Package
1617 and then Present (Renamed_Entity (Unit_Name))
1619 Error_Pragma ("pragma% not allowed for renamed package");
1623 -- Pragma appears other than after a compilation unit
1626 -- Here we check for the generic instantiation case and also
1627 -- for the case of processing a generic formal package. We
1628 -- detect these cases by noting that the Sloc on the node
1629 -- does not belong to the current compilation unit.
1631 Sindex := Source_Index (Current_Sem_Unit);
1633 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1634 Rewrite (N, Make_Null_Statement (Loc));
1637 -- If before first declaration, the pragma applies to the
1638 -- enclosing unit, and the name if present must be this name.
1640 elsif Is_Before_First_Decl (N, Plist) then
1641 Unit_Node := Unit_Declaration_Node (Current_Scope);
1642 Unit_Kind := Nkind (Unit_Node);
1644 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1647 elsif Unit_Kind = N_Subprogram_Body
1648 and then not Acts_As_Spec (Unit_Node)
1652 elsif Nkind (Parent_Node) = N_Package_Body then
1655 elsif Nkind (Parent_Node) = N_Package_Specification
1656 and then Plist = Private_Declarations (Parent_Node)
1660 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1661 or else Nkind (Parent_Node) =
1662 N_Generic_Subprogram_Declaration)
1663 and then Plist = Generic_Formal_Declarations (Parent_Node)
1667 elsif Arg_Count > 0 then
1668 Analyze (Expression (Arg1));
1670 if Entity (Expression (Arg1)) /= Current_Scope then
1672 ("name in pragma% must be enclosing unit", Arg1);
1675 -- It is legal to have no argument in this context
1681 -- Error if not before first declaration. This is because a
1682 -- library unit pragma argument must be the name of a library
1683 -- unit (RM 10.1.5(7)), but the only names permitted in this
1684 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1685 -- generic subprogram declarations or generic instantiations.
1689 ("pragma% misplaced, must be before first declaration");
1693 end Check_Valid_Library_Unit_Pragma;
1699 procedure Check_Variant (Variant : Node_Id) is
1700 Clist : constant Node_Id := Component_List (Variant);
1704 if not Is_Non_Empty_List (Component_Items (Clist)) then
1706 ("Unchecked_Union may not have empty component list",
1711 Comp := First (Component_Items (Clist));
1712 while Present (Comp) loop
1713 Check_Component (Comp);
1722 procedure Error_Pragma (Msg : String) is
1724 Error_Msg_Name_1 := Pname;
1725 Error_Msg_N (Msg, N);
1729 ----------------------
1730 -- Error_Pragma_Arg --
1731 ----------------------
1733 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1735 Error_Msg_Name_1 := Pname;
1736 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1738 end Error_Pragma_Arg;
1740 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1742 Error_Msg_Name_1 := Pname;
1743 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1744 Error_Pragma_Arg (Msg2, Arg);
1745 end Error_Pragma_Arg;
1747 ----------------------------
1748 -- Error_Pragma_Arg_Ident --
1749 ----------------------------
1751 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1753 Error_Msg_Name_1 := Pname;
1754 Error_Msg_N (Msg, Arg);
1756 end Error_Pragma_Arg_Ident;
1758 ----------------------
1759 -- Error_Pragma_Ref --
1760 ----------------------
1762 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1764 Error_Msg_Name_1 := Pname;
1765 Error_Msg_Sloc := Sloc (Ref);
1766 Error_Msg_NE (Msg, N, Ref);
1768 end Error_Pragma_Ref;
1770 ------------------------
1771 -- Find_Lib_Unit_Name --
1772 ------------------------
1774 function Find_Lib_Unit_Name return Entity_Id is
1776 -- Return inner compilation unit entity, for case of nested
1777 -- categorization pragmas. This happens in generic unit.
1779 if Nkind (Parent (N)) = N_Package_Specification
1780 and then Defining_Entity (Parent (N)) /= Current_Scope
1782 return Defining_Entity (Parent (N));
1784 return Current_Scope;
1786 end Find_Lib_Unit_Name;
1788 ----------------------------
1789 -- Find_Program_Unit_Name --
1790 ----------------------------
1792 procedure Find_Program_Unit_Name (Id : Node_Id) is
1793 Unit_Name : Entity_Id;
1794 Unit_Kind : Node_Kind;
1795 P : constant Node_Id := Parent (N);
1798 if Nkind (P) = N_Compilation_Unit then
1799 Unit_Kind := Nkind (Unit (P));
1801 if Unit_Kind = N_Subprogram_Declaration
1802 or else Unit_Kind = N_Package_Declaration
1803 or else Unit_Kind in N_Generic_Declaration
1805 Unit_Name := Defining_Entity (Unit (P));
1807 if Chars (Id) = Chars (Unit_Name) then
1808 Set_Entity (Id, Unit_Name);
1809 Set_Etype (Id, Etype (Unit_Name));
1811 Set_Etype (Id, Any_Type);
1813 ("cannot find program unit referenced by pragma%");
1817 Set_Etype (Id, Any_Type);
1818 Error_Pragma ("pragma% inapplicable to this unit");
1824 end Find_Program_Unit_Name;
1826 -----------------------------------------
1827 -- Find_Unique_Parameterless_Procedure --
1828 -----------------------------------------
1830 function Find_Unique_Parameterless_Procedure
1832 Arg : Node_Id) return Entity_Id
1834 Proc : Entity_Id := Empty;
1837 -- The body of this procedure needs some comments ???
1839 if not Is_Entity_Name (Name) then
1841 ("argument of pragma% must be entity name", Arg);
1843 elsif not Is_Overloaded (Name) then
1844 Proc := Entity (Name);
1846 if Ekind (Proc) /= E_Procedure
1847 or else Present (First_Formal (Proc)) then
1849 ("argument of pragma% must be parameterless procedure", Arg);
1854 Found : Boolean := False;
1856 Index : Interp_Index;
1859 Get_First_Interp (Name, Index, It);
1860 while Present (It.Nam) loop
1863 if Ekind (Proc) = E_Procedure
1864 and then No (First_Formal (Proc))
1868 Set_Entity (Name, Proc);
1869 Set_Is_Overloaded (Name, False);
1872 ("ambiguous handler name for pragma% ", Arg);
1876 Get_Next_Interp (Index, It);
1881 ("argument of pragma% must be parameterless procedure",
1884 Proc := Entity (Name);
1890 end Find_Unique_Parameterless_Procedure;
1892 -------------------------
1893 -- Gather_Associations --
1894 -------------------------
1896 procedure Gather_Associations
1898 Args : out Args_List)
1903 -- Initialize all parameters to Empty
1905 for J in Args'Range loop
1909 -- That's all we have to do if there are no argument associations
1911 if No (Pragma_Argument_Associations (N)) then
1915 -- Otherwise first deal with any positional parameters present
1917 Arg := First (Pragma_Argument_Associations (N));
1918 for Index in Args'Range loop
1919 exit when No (Arg) or else Chars (Arg) /= No_Name;
1920 Args (Index) := Expression (Arg);
1924 -- Positional parameters all processed, if any left, then we
1925 -- have too many positional parameters.
1927 if Present (Arg) and then Chars (Arg) = No_Name then
1929 ("too many positional associations for pragma%", Arg);
1932 -- Process named parameters if any are present
1934 while Present (Arg) loop
1935 if Chars (Arg) = No_Name then
1937 ("positional association cannot follow named association",
1941 for Index in Names'Range loop
1942 if Names (Index) = Chars (Arg) then
1943 if Present (Args (Index)) then
1945 ("duplicate argument association for pragma%", Arg);
1947 Args (Index) := Expression (Arg);
1952 if Index = Names'Last then
1953 Error_Msg_Name_1 := Pname;
1954 Error_Msg_N ("pragma% does not allow & argument", Arg);
1956 -- Check for possible misspelling
1958 for Index1 in Names'Range loop
1959 if Is_Bad_Spelling_Of
1960 (Chars (Arg), Names (Index1))
1962 Error_Msg_Name_1 := Names (Index1);
1963 Error_Msg_N ("\possible misspelling of%", Arg);
1975 end Gather_Associations;
1981 procedure GNAT_Pragma is
1983 Check_Restriction (No_Implementation_Pragmas, N);
1986 --------------------------
1987 -- Is_Before_First_Decl --
1988 --------------------------
1990 function Is_Before_First_Decl
1991 (Pragma_Node : Node_Id;
1992 Decls : List_Id) return Boolean
1994 Item : Node_Id := First (Decls);
1997 -- Only other pragmas can come before this pragma
2000 if No (Item) or else Nkind (Item) /= N_Pragma then
2003 elsif Item = Pragma_Node then
2009 end Is_Before_First_Decl;
2011 -----------------------------
2012 -- Is_Configuration_Pragma --
2013 -----------------------------
2015 -- A configuration pragma must appear in the context clause of a
2016 -- compilation unit, and only other pragmas may precede it. Note that
2017 -- the test below also permits use in a configuration pragma file.
2019 function Is_Configuration_Pragma return Boolean is
2020 Lis : constant List_Id := List_Containing (N);
2021 Par : constant Node_Id := Parent (N);
2025 -- If no parent, then we are in the configuration pragma file,
2026 -- so the placement is definitely appropriate.
2031 -- Otherwise we must be in the context clause of a compilation unit
2032 -- and the only thing allowed before us in the context list is more
2033 -- configuration pragmas.
2035 elsif Nkind (Par) = N_Compilation_Unit
2036 and then Context_Items (Par) = Lis
2043 elsif Nkind (Prg) /= N_Pragma then
2053 end Is_Configuration_Pragma;
2055 --------------------------
2056 -- Is_In_Context_Clause --
2057 --------------------------
2059 function Is_In_Context_Clause return Boolean is
2061 Parent_Node : Node_Id;
2064 if not Is_List_Member (N) then
2068 Plist := List_Containing (N);
2069 Parent_Node := Parent (Plist);
2071 if Parent_Node = Empty
2072 or else Nkind (Parent_Node) /= N_Compilation_Unit
2073 or else Context_Items (Parent_Node) /= Plist
2080 end Is_In_Context_Clause;
2082 ---------------------------------
2083 -- Is_Static_String_Expression --
2084 ---------------------------------
2086 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2087 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2090 Analyze_And_Resolve (Argx);
2091 return Is_OK_Static_Expression (Argx)
2092 and then Nkind (Argx) = N_String_Literal;
2093 end Is_Static_String_Expression;
2095 ----------------------
2096 -- Pragma_Misplaced --
2097 ----------------------
2099 procedure Pragma_Misplaced is
2101 Error_Pragma ("incorrect placement of pragma%");
2102 end Pragma_Misplaced;
2104 ------------------------------------
2105 -- Process Atomic_Shared_Volatile --
2106 ------------------------------------
2108 procedure Process_Atomic_Shared_Volatile is
2115 procedure Set_Atomic (E : Entity_Id);
2116 -- Set given type as atomic, and if no explicit alignment was given,
2117 -- set alignment to unknown, since back end knows what the alignment
2118 -- requirements are for atomic arrays. Note: this step is necessary
2119 -- for derived types.
2125 procedure Set_Atomic (E : Entity_Id) is
2129 if not Has_Alignment_Clause (E) then
2130 Set_Alignment (E, Uint_0);
2134 -- Start of processing for Process_Atomic_Shared_Volatile
2137 Check_Ada_83_Warning;
2138 Check_No_Identifiers;
2139 Check_Arg_Count (1);
2140 Check_Arg_Is_Local_Name (Arg1);
2141 E_Id := Expression (Arg1);
2143 if Etype (E_Id) = Any_Type then
2148 D := Declaration_Node (E);
2152 if Rep_Item_Too_Early (E, N)
2154 Rep_Item_Too_Late (E, N)
2158 Check_First_Subtype (Arg1);
2161 if Prag_Id /= Pragma_Volatile then
2163 Set_Atomic (Underlying_Type (E));
2164 Set_Atomic (Base_Type (E));
2167 -- Attribute belongs on the base type. If the view of the type is
2168 -- currently private, it also belongs on the underlying type.
2170 Set_Is_Volatile (Base_Type (E));
2171 Set_Is_Volatile (Underlying_Type (E));
2173 Set_Treat_As_Volatile (E);
2174 Set_Treat_As_Volatile (Underlying_Type (E));
2176 elsif K = N_Object_Declaration
2177 or else (K = N_Component_Declaration
2178 and then Original_Record_Component (E) = E)
2180 if Rep_Item_Too_Late (E, N) then
2184 if Prag_Id /= Pragma_Volatile then
2187 -- If the object declaration has an explicit initialization, a
2188 -- temporary may have to be created to hold the expression, to
2189 -- ensure that access to the object remain atomic.
2191 if Nkind (Parent (E)) = N_Object_Declaration
2192 and then Present (Expression (Parent (E)))
2194 Set_Has_Delayed_Freeze (E);
2197 -- An interesting improvement here. If an object of type X
2198 -- is declared atomic, and the type X is not atomic, that's
2199 -- a pity, since it may not have appropriate alignment etc.
2200 -- We can rescue this in the special case where the object
2201 -- and type are in the same unit by just setting the type
2202 -- as atomic, so that the back end will process it as atomic.
2204 Utyp := Underlying_Type (Etype (E));
2207 and then Sloc (E) > No_Location
2208 and then Sloc (Utyp) > No_Location
2210 Get_Source_File_Index (Sloc (E)) =
2211 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2213 Set_Is_Atomic (Underlying_Type (Etype (E)));
2217 Set_Is_Volatile (E);
2218 Set_Treat_As_Volatile (E);
2222 ("inappropriate entity for pragma%", Arg1);
2224 end Process_Atomic_Shared_Volatile;
2226 -------------------------------------------
2227 -- Process_Compile_Time_Warning_Or_Error --
2228 -------------------------------------------
2230 procedure Process_Compile_Time_Warning_Or_Error is
2231 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2234 Check_Arg_Count (2);
2235 Check_No_Identifiers;
2236 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2237 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2239 if Compile_Time_Known_Value (Arg1x) then
2240 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2242 Str : constant String_Id :=
2243 Strval (Get_Pragma_Arg (Arg2));
2244 Len : constant Int := String_Length (Str);
2249 Cent : constant Entity_Id :=
2250 Cunit_Entity (Current_Sem_Unit);
2252 Force : constant Boolean :=
2253 Prag_Id = Pragma_Compile_Time_Warning
2255 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2256 and then (Ekind (Cent) /= E_Package
2257 or else not In_Private_Part (Cent));
2258 -- Set True if this is the warning case, and we are in the
2259 -- visible part of a package spec, or in a subprogram spec,
2260 -- in which case we want to force the client to see the
2261 -- warning, even though it is not in the main unit.
2264 -- Loop through segments of message separated by line
2265 -- feeds. We output these segments as separate messages
2266 -- with continuation marks for all but the first.
2271 Error_Msg_Strlen := 0;
2273 -- Loop to copy characters from argument to error
2274 -- message string buffer.
2277 exit when Ptr > Len;
2278 CC := Get_String_Char (Str, Ptr);
2281 -- Ignore wide chars ??? else store character
2283 if In_Character_Range (CC) then
2284 C := Get_Character (CC);
2285 exit when C = ASCII.LF;
2286 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2287 Error_Msg_String (Error_Msg_Strlen) := C;
2291 -- Here with one line ready to go
2293 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2295 -- If this is a warning in a spec, then we want clients
2296 -- to see the warning, so mark the message with the
2297 -- special sequence !! to force the warning. In the case
2298 -- of a package spec, we do not force this if we are in
2299 -- the private part of the spec.
2302 if Cont = False then
2303 Error_Msg_N ("<~!!", Arg1);
2306 Error_Msg_N ("\<~!!", Arg1);
2309 -- Error, rather than warning, or in a body, so we do not
2310 -- need to force visibility for client (error will be
2311 -- output in any case, and this is the situation in which
2312 -- we do not want a client to get a warning, since the
2313 -- warning is in the body or the spec private part.
2316 if Cont = False then
2317 Error_Msg_N ("<~", Arg1);
2320 Error_Msg_N ("\<~", Arg1);
2324 exit when Ptr > Len;
2329 end Process_Compile_Time_Warning_Or_Error;
2331 ------------------------
2332 -- Process_Convention --
2333 ------------------------
2335 procedure Process_Convention
2336 (C : out Convention_Id;
2342 Comp_Unit : Unit_Number_Type;
2344 procedure Set_Convention_From_Pragma (E : Entity_Id);
2345 -- Set convention in entity E, and also flag that the entity has a
2346 -- convention pragma. If entity is for a private or incomplete type,
2347 -- also set convention and flag on underlying type. This procedure
2348 -- also deals with the special case of C_Pass_By_Copy convention.
2350 --------------------------------
2351 -- Set_Convention_From_Pragma --
2352 --------------------------------
2354 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2356 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2357 -- for an overridden dispatching operation. Technically this is
2358 -- an amendment and should only be done in Ada 2005 mode. However,
2359 -- this is clearly a mistake, since the problem that is addressed
2360 -- by this AI is that there is a clear gap in the RM!
2362 if Is_Dispatching_Operation (E)
2363 and then Present (Overridden_Operation (E))
2364 and then C /= Convention (Overridden_Operation (E))
2367 ("cannot change convention for " &
2368 "overridden dispatching operation",
2372 -- Set the convention
2374 Set_Convention (E, C);
2375 Set_Has_Convention_Pragma (E);
2377 if Is_Incomplete_Or_Private_Type (E) then
2378 Set_Convention (Underlying_Type (E), C);
2379 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2382 -- A class-wide type should inherit the convention of
2383 -- the specific root type (although this isn't specified
2384 -- clearly by the RM).
2386 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2387 Set_Convention (Class_Wide_Type (E), C);
2390 -- If the entity is a record type, then check for special case of
2391 -- C_Pass_By_Copy, which is treated the same as C except that the
2392 -- special record flag is set. This convention is only permitted
2393 -- on record types (see AI95-00131).
2395 if Cname = Name_C_Pass_By_Copy then
2396 if Is_Record_Type (E) then
2397 Set_C_Pass_By_Copy (Base_Type (E));
2398 elsif Is_Incomplete_Or_Private_Type (E)
2399 and then Is_Record_Type (Underlying_Type (E))
2401 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2404 ("C_Pass_By_Copy convention allowed only for record type",
2409 -- If the entity is a derived boolean type, check for the
2410 -- special case of convention C, C++, or Fortran, where we
2411 -- consider any nonzero value to represent true.
2413 if Is_Discrete_Type (E)
2414 and then Root_Type (Etype (E)) = Standard_Boolean
2420 C = Convention_Fortran)
2422 Set_Nonzero_Is_True (Base_Type (E));
2424 end Set_Convention_From_Pragma;
2426 -- Start of processing for Process_Convention
2429 Check_At_Least_N_Arguments (2);
2430 Check_Optional_Identifier (Arg1, Name_Convention);
2431 Check_Arg_Is_Identifier (Arg1);
2432 Cname := Chars (Expression (Arg1));
2434 -- C_Pass_By_Copy is treated as a synonym for convention C
2435 -- (this is tested again below to set the critical flag)
2437 if Cname = Name_C_Pass_By_Copy then
2440 -- Otherwise we must have something in the standard convention list
2442 elsif Is_Convention_Name (Cname) then
2443 C := Get_Convention_Id (Chars (Expression (Arg1)));
2445 -- In DEC VMS, it seems that there is an undocumented feature that
2446 -- any unrecognized convention is treated as the default, which for
2447 -- us is convention C. It does not seem so terrible to do this
2448 -- unconditionally, silently in the VMS case, and with a warning
2449 -- in the non-VMS case.
2452 if Warn_On_Export_Import and not OpenVMS_On_Target then
2454 ("?unrecognized convention name, C assumed",
2461 Check_Optional_Identifier (Arg2, Name_Entity);
2462 Check_Arg_Is_Local_Name (Arg2);
2464 Id := Expression (Arg2);
2467 if not Is_Entity_Name (Id) then
2468 Error_Pragma_Arg ("entity name required", Arg2);
2473 -- Go to renamed subprogram if present, since convention applies to
2474 -- the actual renamed entity, not to the renaming entity. If the
2475 -- subprogram is inherited, go to parent subprogram.
2477 if Is_Subprogram (E)
2478 and then Present (Alias (E))
2480 if Nkind (Parent (Declaration_Node (E))) =
2481 N_Subprogram_Renaming_Declaration
2483 if Scope (E) /= Scope (Alias (E)) then
2485 ("cannot apply pragma% to non-local renaming&#", E);
2489 elsif Nkind (Parent (E)) = N_Full_Type_Declaration
2490 and then Scope (E) = Scope (Alias (E))
2496 -- Check that we are not applying this to a specless body
2498 if Is_Subprogram (E)
2499 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2502 ("pragma% requires separate spec and must come before body");
2505 -- Check that we are not applying this to a named constant
2507 if Ekind (E) = E_Named_Integer
2509 Ekind (E) = E_Named_Real
2511 Error_Msg_Name_1 := Pname;
2513 ("cannot apply pragma% to named constant!",
2514 Get_Pragma_Arg (Arg2));
2516 ("\supply appropriate type for&!", Arg2);
2519 if Ekind (E) = E_Enumeration_Literal then
2520 Error_Pragma ("enumeration literal not allowed for pragma%");
2523 -- Check for rep item appearing too early or too late
2525 if Etype (E) = Any_Type
2526 or else Rep_Item_Too_Early (E, N)
2530 E := Underlying_Type (E);
2533 if Rep_Item_Too_Late (E, N) then
2537 if Has_Convention_Pragma (E) then
2539 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2541 elsif Convention (E) = Convention_Protected
2542 or else Ekind (Scope (E)) = E_Protected_Type
2545 ("a protected operation cannot be given a different convention",
2549 -- For Intrinsic, a subprogram is required
2551 if C = Convention_Intrinsic
2552 and then not Is_Subprogram (E)
2553 and then not Is_Generic_Subprogram (E)
2556 ("second argument of pragma% must be a subprogram", Arg2);
2559 -- For Stdcall, a subprogram, variable or subprogram type is required
2561 if C = Convention_Stdcall
2562 and then not Is_Subprogram (E)
2563 and then not Is_Generic_Subprogram (E)
2564 and then Ekind (E) /= E_Variable
2567 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2570 ("second argument of pragma% must be subprogram (type)",
2574 if not Is_Subprogram (E)
2575 and then not Is_Generic_Subprogram (E)
2577 Set_Convention_From_Pragma (E);
2581 Check_First_Subtype (Arg2);
2582 Set_Convention_From_Pragma (Base_Type (E));
2584 -- For subprograms, we must set the convention on the
2585 -- internally generated directly designated type as well.
2587 if Ekind (E) = E_Access_Subprogram_Type then
2588 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2592 -- For the subprogram case, set proper convention for all homonyms
2593 -- in same scope and the same declarative part, i.e. the same
2594 -- compilation unit.
2597 Comp_Unit := Get_Source_Unit (E);
2598 Set_Convention_From_Pragma (E);
2600 -- Treat a pragma Import as an implicit body, for GPS use
2602 if Prag_Id = Pragma_Import then
2603 Generate_Reference (E, Id, 'b');
2609 exit when No (E1) or else Scope (E1) /= Current_Scope;
2611 -- Do not set the pragma on inherited operations or on
2612 -- formal subprograms.
2614 if Comes_From_Source (E1)
2615 and then Comp_Unit = Get_Source_Unit (E1)
2616 and then not Is_Formal_Subprogram (E1)
2617 and then Nkind (Original_Node (Parent (E1))) /=
2618 N_Full_Type_Declaration
2620 if Present (Alias (E1))
2621 and then Scope (E1) /= Scope (Alias (E1))
2624 ("cannot apply pragma% to non-local renaming&#", E1);
2626 Set_Convention_From_Pragma (E1);
2628 if Prag_Id = Pragma_Import then
2629 Generate_Reference (E, Id, 'b');
2634 end Process_Convention;
2636 -----------------------------------------------------
2637 -- Process_Extended_Import_Export_Exception_Pragma --
2638 -----------------------------------------------------
2640 procedure Process_Extended_Import_Export_Exception_Pragma
2641 (Arg_Internal : Node_Id;
2642 Arg_External : Node_Id;
2650 if not OpenVMS_On_Target then
2652 ("?pragma% ignored (applies only to Open'V'M'S)");
2655 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2656 Def_Id := Entity (Arg_Internal);
2658 if Ekind (Def_Id) /= E_Exception then
2660 ("pragma% must refer to declared exception", Arg_Internal);
2663 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2665 if Present (Arg_Form) then
2666 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2669 if Present (Arg_Form)
2670 and then Chars (Arg_Form) = Name_Ada
2674 Set_Is_VMS_Exception (Def_Id);
2675 Set_Exception_Code (Def_Id, No_Uint);
2678 if Present (Arg_Code) then
2679 if not Is_VMS_Exception (Def_Id) then
2681 ("Code option for pragma% not allowed for Ada case",
2685 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2686 Code_Val := Expr_Value (Arg_Code);
2688 if not UI_Is_In_Int_Range (Code_Val) then
2690 ("Code option for pragma% must be in 32-bit range",
2694 Set_Exception_Code (Def_Id, Code_Val);
2697 end Process_Extended_Import_Export_Exception_Pragma;
2699 -------------------------------------------------
2700 -- Process_Extended_Import_Export_Internal_Arg --
2701 -------------------------------------------------
2703 procedure Process_Extended_Import_Export_Internal_Arg
2704 (Arg_Internal : Node_Id := Empty)
2707 if No (Arg_Internal) then
2708 Error_Pragma ("Internal parameter required for pragma%");
2711 if Nkind (Arg_Internal) = N_Identifier then
2714 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2715 and then (Prag_Id = Pragma_Import_Function
2717 Prag_Id = Pragma_Export_Function)
2723 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2726 Check_Arg_Is_Local_Name (Arg_Internal);
2727 end Process_Extended_Import_Export_Internal_Arg;
2729 --------------------------------------------------
2730 -- Process_Extended_Import_Export_Object_Pragma --
2731 --------------------------------------------------
2733 procedure Process_Extended_Import_Export_Object_Pragma
2734 (Arg_Internal : Node_Id;
2735 Arg_External : Node_Id;
2741 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2742 Def_Id := Entity (Arg_Internal);
2744 if Ekind (Def_Id) /= E_Constant
2745 and then Ekind (Def_Id) /= E_Variable
2748 ("pragma% must designate an object", Arg_Internal);
2751 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2753 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2756 ("previous Common/Psect_Object applies, pragma % not permitted",
2760 if Rep_Item_Too_Late (Def_Id, N) then
2764 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2766 if Present (Arg_Size) then
2767 Check_Arg_Is_External_Name (Arg_Size);
2770 -- Export_Object case
2772 if Prag_Id = Pragma_Export_Object then
2773 if not Is_Library_Level_Entity (Def_Id) then
2775 ("argument for pragma% must be library level entity",
2779 if Ekind (Current_Scope) = E_Generic_Package then
2780 Error_Pragma ("pragma& cannot appear in a generic unit");
2783 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2785 ("exported object must have compile time known size",
2789 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2791 ("?duplicate Export_Object pragma", N);
2793 Set_Exported (Def_Id, Arg_Internal);
2796 -- Import_Object case
2799 if Is_Concurrent_Type (Etype (Def_Id)) then
2801 ("cannot use pragma% for task/protected object",
2805 if Ekind (Def_Id) = E_Constant then
2807 ("cannot import a constant", Arg_Internal);
2810 if Warn_On_Export_Import
2811 and then Has_Discriminants (Etype (Def_Id))
2814 ("imported value must be initialized?", Arg_Internal);
2817 if Warn_On_Export_Import
2818 and then Is_Access_Type (Etype (Def_Id))
2821 ("cannot import object of an access type?", Arg_Internal);
2824 if Warn_On_Export_Import
2825 and then Is_Imported (Def_Id)
2828 ("?duplicate Import_Object pragma", N);
2830 -- Check for explicit initialization present. Note that an
2831 -- initialization that generated by the code generator, e.g.
2832 -- for an access type, does not count here.
2834 elsif Present (Expression (Parent (Def_Id)))
2837 (Original_Node (Expression (Parent (Def_Id))))
2839 Error_Msg_Sloc := Sloc (Def_Id);
2841 ("imported entities cannot be initialized (RM B.1(24))",
2842 "\no initialization allowed for & declared#", Arg1);
2844 Set_Imported (Def_Id);
2845 Note_Possible_Modification (Arg_Internal, Sure => False);
2848 end Process_Extended_Import_Export_Object_Pragma;
2850 ------------------------------------------------------
2851 -- Process_Extended_Import_Export_Subprogram_Pragma --
2852 ------------------------------------------------------
2854 procedure Process_Extended_Import_Export_Subprogram_Pragma
2855 (Arg_Internal : Node_Id;
2856 Arg_External : Node_Id;
2857 Arg_Parameter_Types : Node_Id;
2858 Arg_Result_Type : Node_Id := Empty;
2859 Arg_Mechanism : Node_Id;
2860 Arg_Result_Mechanism : Node_Id := Empty;
2861 Arg_First_Optional_Parameter : Node_Id := Empty)
2867 Ambiguous : Boolean;
2871 function Same_Base_Type
2873 Formal : Entity_Id) return Boolean;
2874 -- Determines if Ptype references the type of Formal. Note that
2875 -- only the base types need to match according to the spec. Ptype
2876 -- here is the argument from the pragma, which is either a type
2877 -- name, or an access attribute.
2879 --------------------
2880 -- Same_Base_Type --
2881 --------------------
2883 function Same_Base_Type
2885 Formal : Entity_Id) return Boolean
2887 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2891 -- Case where pragma argument is typ'Access
2893 if Nkind (Ptype) = N_Attribute_Reference
2894 and then Attribute_Name (Ptype) = Name_Access
2896 Pref := Prefix (Ptype);
2899 if not Is_Entity_Name (Pref)
2900 or else Entity (Pref) = Any_Type
2905 -- We have a match if the corresponding argument is of an
2906 -- anonymous access type, and its designated type matches
2907 -- the type of the prefix of the access attribute
2909 return Ekind (Ftyp) = E_Anonymous_Access_Type
2910 and then Base_Type (Entity (Pref)) =
2911 Base_Type (Etype (Designated_Type (Ftyp)));
2913 -- Case where pragma argument is a type name
2918 if not Is_Entity_Name (Ptype)
2919 or else Entity (Ptype) = Any_Type
2924 -- We have a match if the corresponding argument is of
2925 -- the type given in the pragma (comparing base types)
2927 return Base_Type (Entity (Ptype)) = Ftyp;
2931 -- Start of processing for
2932 -- Process_Extended_Import_Export_Subprogram_Pragma
2935 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2939 -- Loop through homonyms (overloadings) of the entity
2941 Hom_Id := Entity (Arg_Internal);
2942 while Present (Hom_Id) loop
2943 Def_Id := Get_Base_Subprogram (Hom_Id);
2945 -- We need a subprogram in the current scope
2947 if not Is_Subprogram (Def_Id)
2948 or else Scope (Def_Id) /= Current_Scope
2955 -- Pragma cannot apply to subprogram body
2957 if Is_Subprogram (Def_Id)
2960 (Declaration_Node (Def_Id))) = N_Subprogram_Body
2963 ("pragma% requires separate spec"
2964 & " and must come before body");
2967 -- Test result type if given, note that the result type
2968 -- parameter can only be present for the function cases.
2970 if Present (Arg_Result_Type)
2971 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2975 elsif Etype (Def_Id) /= Standard_Void_Type
2977 (Pname = Name_Export_Procedure
2979 Pname = Name_Import_Procedure)
2983 -- Test parameter types if given. Note that this parameter
2984 -- has not been analyzed (and must not be, since it is
2985 -- semantic nonsense), so we get it as the parser left it.
2987 elsif Present (Arg_Parameter_Types) then
2988 Check_Matching_Types : declare
2993 Formal := First_Formal (Def_Id);
2995 if Nkind (Arg_Parameter_Types) = N_Null then
2996 if Present (Formal) then
3000 -- A list of one type, e.g. (List) is parsed as
3001 -- a parenthesized expression.
3003 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3004 and then Paren_Count (Arg_Parameter_Types) = 1
3007 or else Present (Next_Formal (Formal))
3012 Same_Base_Type (Arg_Parameter_Types, Formal);
3015 -- A list of more than one type is parsed as a aggregate
3017 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3018 and then Paren_Count (Arg_Parameter_Types) = 0
3020 Ptype := First (Expressions (Arg_Parameter_Types));
3021 while Present (Ptype) or else Present (Formal) loop
3024 or else not Same_Base_Type (Ptype, Formal)
3029 Next_Formal (Formal);
3034 -- Anything else is of the wrong form
3038 ("wrong form for Parameter_Types parameter",
3039 Arg_Parameter_Types);
3041 end Check_Matching_Types;
3044 -- Match is now False if the entry we found did not match
3045 -- either a supplied Parameter_Types or Result_Types argument
3051 -- Ambiguous case, the flag Ambiguous shows if we already
3052 -- detected this and output the initial messages.
3055 if not Ambiguous then
3057 Error_Msg_Name_1 := Pname;
3059 ("pragma% does not uniquely identify subprogram!",
3061 Error_Msg_Sloc := Sloc (Ent);
3062 Error_Msg_N ("matching subprogram #!", N);
3066 Error_Msg_Sloc := Sloc (Def_Id);
3067 Error_Msg_N ("matching subprogram #!", N);
3072 Hom_Id := Homonym (Hom_Id);
3075 -- See if we found an entry
3078 if not Ambiguous then
3079 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3081 ("pragma% cannot be given for generic subprogram");
3084 ("pragma% does not identify local subprogram");
3091 -- Import pragmas must be be for imported entities
3093 if Prag_Id = Pragma_Import_Function
3095 Prag_Id = Pragma_Import_Procedure
3097 Prag_Id = Pragma_Import_Valued_Procedure
3099 if not Is_Imported (Ent) then
3101 ("pragma Import or Interface must precede pragma%");
3104 -- Here we have the Export case which can set the entity as exported
3106 -- But does not do so if the specified external name is null, since
3107 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3108 -- compatible) to request no external name.
3110 elsif Nkind (Arg_External) = N_String_Literal
3111 and then String_Length (Strval (Arg_External)) = 0
3115 -- In all other cases, set entity as exported
3118 Set_Exported (Ent, Arg_Internal);
3121 -- Special processing for Valued_Procedure cases
3123 if Prag_Id = Pragma_Import_Valued_Procedure
3125 Prag_Id = Pragma_Export_Valued_Procedure
3127 Formal := First_Formal (Ent);
3131 ("at least one parameter required for pragma%");
3133 elsif Ekind (Formal) /= E_Out_Parameter then
3135 ("first parameter must have mode out for pragma%");
3138 Set_Is_Valued_Procedure (Ent);
3142 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3144 -- Process Result_Mechanism argument if present. We have already
3145 -- checked that this is only allowed for the function case.
3147 if Present (Arg_Result_Mechanism) then
3148 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3151 -- Process Mechanism parameter if present. Note that this parameter
3152 -- is not analyzed, and must not be analyzed since it is semantic
3153 -- nonsense, so we get it in exactly as the parser left it.
3155 if Present (Arg_Mechanism) then
3163 -- A single mechanism association without a formal parameter
3164 -- name is parsed as a parenthesized expression. All other
3165 -- cases are parsed as aggregates, so we rewrite the single
3166 -- parameter case as an aggregate for consistency.
3168 if Nkind (Arg_Mechanism) /= N_Aggregate
3169 and then Paren_Count (Arg_Mechanism) = 1
3171 Rewrite (Arg_Mechanism,
3172 Make_Aggregate (Sloc (Arg_Mechanism),
3173 Expressions => New_List (
3174 Relocate_Node (Arg_Mechanism))));
3177 -- Case of only mechanism name given, applies to all formals
3179 if Nkind (Arg_Mechanism) /= N_Aggregate then
3180 Formal := First_Formal (Ent);
3181 while Present (Formal) loop
3182 Set_Mechanism_Value (Formal, Arg_Mechanism);
3183 Next_Formal (Formal);
3186 -- Case of list of mechanism associations given
3189 if Null_Record_Present (Arg_Mechanism) then
3191 ("inappropriate form for Mechanism parameter",
3195 -- Deal with positional ones first
3197 Formal := First_Formal (Ent);
3199 if Present (Expressions (Arg_Mechanism)) then
3200 Mname := First (Expressions (Arg_Mechanism));
3201 while Present (Mname) loop
3204 ("too many mechanism associations", Mname);
3207 Set_Mechanism_Value (Formal, Mname);
3208 Next_Formal (Formal);
3213 -- Deal with named entries
3215 if Present (Component_Associations (Arg_Mechanism)) then
3216 Massoc := First (Component_Associations (Arg_Mechanism));
3217 while Present (Massoc) loop
3218 Choice := First (Choices (Massoc));
3220 if Nkind (Choice) /= N_Identifier
3221 or else Present (Next (Choice))
3224 ("incorrect form for mechanism association",
3228 Formal := First_Formal (Ent);
3232 ("parameter name & not present", Choice);
3235 if Chars (Choice) = Chars (Formal) then
3237 (Formal, Expression (Massoc));
3239 -- Set entity on identifier for ASIS
3241 Set_Entity (Choice, Formal);
3246 Next_Formal (Formal);
3256 -- Process First_Optional_Parameter argument if present. We have
3257 -- already checked that this is only allowed for the Import case.
3259 if Present (Arg_First_Optional_Parameter) then
3260 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3262 ("first optional parameter must be formal parameter name",
3263 Arg_First_Optional_Parameter);
3266 Formal := First_Formal (Ent);
3270 ("specified formal parameter& not found",
3271 Arg_First_Optional_Parameter);
3274 exit when Chars (Formal) =
3275 Chars (Arg_First_Optional_Parameter);
3277 Next_Formal (Formal);
3280 Set_First_Optional_Parameter (Ent, Formal);
3282 -- Check specified and all remaining formals have right form
3284 while Present (Formal) loop
3285 if Ekind (Formal) /= E_In_Parameter then
3287 ("optional formal& is not of mode in!",
3288 Arg_First_Optional_Parameter, Formal);
3291 Dval := Default_Value (Formal);
3295 ("optional formal& does not have default value!",
3296 Arg_First_Optional_Parameter, Formal);
3298 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3303 ("default value for optional formal& is non-static!",
3304 Arg_First_Optional_Parameter, Formal);
3308 Set_Is_Optional_Parameter (Formal);
3309 Next_Formal (Formal);
3312 end Process_Extended_Import_Export_Subprogram_Pragma;
3314 --------------------------
3315 -- Process_Generic_List --
3316 --------------------------
3318 procedure Process_Generic_List is
3323 Check_No_Identifiers;
3324 Check_At_Least_N_Arguments (1);
3327 while Present (Arg) loop
3328 Exp := Expression (Arg);
3331 if not Is_Entity_Name (Exp)
3333 (not Is_Generic_Instance (Entity (Exp))
3335 not Is_Generic_Unit (Entity (Exp)))
3338 ("pragma% argument must be name of generic unit/instance",
3344 end Process_Generic_List;
3346 ---------------------------------
3347 -- Process_Import_Or_Interface --
3348 ---------------------------------
3350 procedure Process_Import_Or_Interface is
3356 Process_Convention (C, Def_Id);
3357 Kill_Size_Check_Code (Def_Id);
3358 Note_Possible_Modification (Expression (Arg2), Sure => False);
3360 if Ekind (Def_Id) = E_Variable
3362 Ekind (Def_Id) = E_Constant
3364 -- We do not permit Import to apply to a renaming declaration
3366 if Present (Renamed_Object (Def_Id)) then
3368 ("pragma% not allowed for object renaming", Arg2);
3370 -- User initialization is not allowed for imported object, but
3371 -- the object declaration may contain a default initialization,
3372 -- that will be discarded. Note that an explicit initialization
3373 -- only counts if it comes from source, otherwise it is simply
3374 -- the code generator making an implicit initialization explicit.
3376 elsif Present (Expression (Parent (Def_Id)))
3377 and then Comes_From_Source (Expression (Parent (Def_Id)))
3379 Error_Msg_Sloc := Sloc (Def_Id);
3381 ("no initialization allowed for declaration of& #",
3382 "\imported entities cannot be initialized (RM B.1(24))",
3386 Set_Imported (Def_Id);
3387 Process_Interface_Name (Def_Id, Arg3, Arg4);
3389 -- Note that we do not set Is_Public here. That's because we
3390 -- only want to set if if there is no address clause, and we
3391 -- don't know that yet, so we delay that processing till
3394 -- pragma Import completes deferred constants
3396 if Ekind (Def_Id) = E_Constant then
3397 Set_Has_Completion (Def_Id);
3400 -- It is not possible to import a constant of an unconstrained
3401 -- array type (e.g. string) because there is no simple way to
3402 -- write a meaningful subtype for it.
3404 if Is_Array_Type (Etype (Def_Id))
3405 and then not Is_Constrained (Etype (Def_Id))
3408 ("imported constant& must have a constrained subtype",
3413 elsif Is_Subprogram (Def_Id)
3414 or else Is_Generic_Subprogram (Def_Id)
3416 -- If the name is overloaded, pragma applies to all of the
3417 -- denoted entities in the same declarative part.
3420 while Present (Hom_Id) loop
3421 Def_Id := Get_Base_Subprogram (Hom_Id);
3423 -- Ignore inherited subprograms because the pragma will
3424 -- apply to the parent operation, which is the one called.
3426 if Is_Overloadable (Def_Id)
3427 and then Present (Alias (Def_Id))
3431 -- If it is not a subprogram, it must be in an outer
3432 -- scope and pragma does not apply.
3434 elsif not Is_Subprogram (Def_Id)
3435 and then not Is_Generic_Subprogram (Def_Id)
3439 -- Verify that the homonym is in the same declarative
3440 -- part (not just the same scope).
3442 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3443 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3448 Set_Imported (Def_Id);
3450 -- Special processing for Convention_Intrinsic
3452 if C = Convention_Intrinsic then
3454 -- Link_Name argument not allowed for intrinsic
3457 and then Chars (Arg3) = Name_Link_Name
3462 if Present (Arg4) then
3464 ("Link_Name argument not allowed for " &
3469 Set_Is_Intrinsic_Subprogram (Def_Id);
3471 -- If no external name is present, then check that
3472 -- this is a valid intrinsic subprogram. If an external
3473 -- name is present, then this is handled by the back end.
3476 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3480 -- All interfaced procedures need an external symbol
3481 -- created for them since they are always referenced
3482 -- from another object file.
3484 Set_Is_Public (Def_Id);
3486 -- Verify that the subprogram does not have a completion
3487 -- through a renaming declaration. For other completions
3488 -- the pragma appears as a too late representation.
3491 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3495 and then Nkind (Decl) = N_Subprogram_Declaration
3496 and then Present (Corresponding_Body (Decl))
3499 (Unit_Declaration_Node
3500 (Corresponding_Body (Decl))) =
3501 N_Subprogram_Renaming_Declaration
3503 Error_Msg_Sloc := Sloc (Def_Id);
3505 ("cannot import&, renaming already provided for " &
3506 "declaration #", N, Def_Id);
3510 Set_Has_Completion (Def_Id);
3511 Process_Interface_Name (Def_Id, Arg3, Arg4);
3514 if Is_Compilation_Unit (Hom_Id) then
3516 -- Its possible homonyms are not affected by the pragma.
3517 -- Such homonyms might be present in the context of other
3518 -- units being compiled.
3523 Hom_Id := Homonym (Hom_Id);
3527 -- When the convention is Java or CIL, we also allow Import to be
3528 -- given for packages, generic packages, exceptions, and record
3531 elsif (C = Convention_Java or else C = Convention_CIL)
3533 (Ekind (Def_Id) = E_Package
3534 or else Ekind (Def_Id) = E_Generic_Package
3535 or else Ekind (Def_Id) = E_Exception
3536 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3538 Set_Imported (Def_Id);
3539 Set_Is_Public (Def_Id);
3540 Process_Interface_Name (Def_Id, Arg3, Arg4);
3542 -- Import a CPP class
3544 elsif Is_Record_Type (Def_Id)
3545 and then C = Convention_CPP
3547 if not Is_Tagged_Type (Def_Id) then
3548 Error_Msg_Sloc := Sloc (Def_Id);
3549 Error_Pragma_Arg ("imported 'C'P'P type must be tagged", Arg2);
3552 -- Types treated as CPP classes are treated as limited, but we
3553 -- don't require them to be declared this way. A warning is
3554 -- issued to encourage the user to declare them as limited.
3555 -- This is not an error, for compatibility reasons, because
3556 -- these types have been supported this way for some time.
3558 if not Is_Limited_Type (Def_Id) then
3560 ("imported 'C'P'P type should be " &
3561 "explicitly declared limited?",
3562 Get_Pragma_Arg (Arg2));
3564 ("\type will be considered limited",
3565 Get_Pragma_Arg (Arg2));
3568 Set_Is_CPP_Class (Def_Id);
3569 Set_Is_Limited_Record (Def_Id);
3574 ("second argument of pragma% must be object or subprogram",
3578 -- If this pragma applies to a compilation unit, then the unit,
3579 -- which is a subprogram, does not require (or allow) a body.
3580 -- We also do not need to elaborate imported procedures.
3582 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3584 Cunit : constant Node_Id := Parent (Parent (N));
3586 Set_Body_Required (Cunit, False);
3589 end Process_Import_Or_Interface;
3591 --------------------
3592 -- Process_Inline --
3593 --------------------
3595 procedure Process_Inline (Active : Boolean) is
3601 Effective : Boolean := False;
3603 procedure Make_Inline (Subp : Entity_Id);
3604 -- Subp is the defining unit name of the subprogram
3605 -- declaration. Set the flag, as well as the flag in the
3606 -- corresponding body, if there is one present.
3608 procedure Set_Inline_Flags (Subp : Entity_Id);
3609 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3610 -- Has_Pragma_Inline_Always for the Inline_Always case.
3612 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3613 -- Returns True if it can be determined at this stage that inlining
3614 -- is not possible, for example if the body is available and contains
3615 -- exception handlers, we prevent inlining, since otherwise we can
3616 -- get undefined symbols at link time. This function also emits a
3617 -- warning if front-end inlining is enabled and the pragma appears
3620 -- ??? is business with link symbols still valid, or does it relate
3621 -- to front end ZCX which is being phased out ???
3623 ---------------------------
3624 -- Inlining_Not_Possible --
3625 ---------------------------
3627 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3628 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3632 if Nkind (Decl) = N_Subprogram_Body then
3633 Stats := Handled_Statement_Sequence (Decl);
3634 return Present (Exception_Handlers (Stats))
3635 or else Present (At_End_Proc (Stats));
3637 elsif Nkind (Decl) = N_Subprogram_Declaration
3638 and then Present (Corresponding_Body (Decl))
3640 if Front_End_Inlining
3641 and then Analyzed (Corresponding_Body (Decl))
3643 Error_Msg_N ("pragma appears too late, ignored?", N);
3646 -- If the subprogram is a renaming as body, the body is
3647 -- just a call to the renamed subprogram, and inlining is
3648 -- trivially possible.
3651 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3652 N_Subprogram_Renaming_Declaration
3658 Handled_Statement_Sequence
3659 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3662 Present (Exception_Handlers (Stats))
3663 or else Present (At_End_Proc (Stats));
3667 -- If body is not available, assume the best, the check is
3668 -- performed again when compiling enclosing package bodies.
3672 end Inlining_Not_Possible;
3678 procedure Make_Inline (Subp : Entity_Id) is
3679 Kind : constant Entity_Kind := Ekind (Subp);
3680 Inner_Subp : Entity_Id := Subp;
3683 -- Ignore if bad type, avoid cascaded error
3685 if Etype (Subp) = Any_Type then
3689 -- Ignore if all inlining is suppressed
3691 elsif Suppress_All_Inlining then
3695 -- If inlining is not possible, for now do not treat as an error
3697 elsif Inlining_Not_Possible (Subp) then
3701 -- Here we have a candidate for inlining, but we must exclude
3702 -- derived operations. Otherwise we would end up trying to inline
3703 -- a phantom declaration, and the result would be to drag in a
3704 -- body which has no direct inlining associated with it. That
3705 -- would not only be inefficient but would also result in the
3706 -- backend doing cross-unit inlining in cases where it was
3707 -- definitely inappropriate to do so.
3709 -- However, a simple Comes_From_Source test is insufficient, since
3710 -- we do want to allow inlining of generic instances which also do
3711 -- not come from source. We also need to recognize specs
3712 -- generated by the front-end for bodies that carry the pragma.
3713 -- Finally, predefined operators do not come from source but are
3714 -- not inlineable either.
3716 elsif Is_Generic_Instance (Subp)
3717 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3721 elsif not Comes_From_Source (Subp)
3722 and then Scope (Subp) /= Standard_Standard
3728 -- The referenced entity must either be the enclosing entity,
3729 -- or an entity declared within the current open scope.
3731 if Present (Scope (Subp))
3732 and then Scope (Subp) /= Current_Scope
3733 and then Subp /= Current_Scope
3736 ("argument of% must be entity in current scope", Assoc);
3740 -- Processing for procedure, operator or function.
3741 -- If subprogram is aliased (as for an instance) indicate
3742 -- that the renamed entity (if declared in the same unit)
3745 if Is_Subprogram (Subp) then
3746 while Present (Alias (Inner_Subp)) loop
3747 Inner_Subp := Alias (Inner_Subp);
3750 if In_Same_Source_Unit (Subp, Inner_Subp) then
3751 Set_Inline_Flags (Inner_Subp);
3753 Decl := Parent (Parent (Inner_Subp));
3755 if Nkind (Decl) = N_Subprogram_Declaration
3756 and then Present (Corresponding_Body (Decl))
3758 Set_Inline_Flags (Corresponding_Body (Decl));
3760 elsif Is_Generic_Instance (Subp) then
3762 -- Indicate that the body needs to be created for
3763 -- inlining subsequent calls. The instantiation
3764 -- node follows the declaration of the wrapper
3765 -- package created for it.
3767 if Scope (Subp) /= Standard_Standard
3769 Need_Subprogram_Instance_Body
3770 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3780 -- For a generic subprogram set flag as well, for use at
3781 -- the point of instantiation, to determine whether the
3782 -- body should be generated.
3784 elsif Is_Generic_Subprogram (Subp) then
3785 Set_Inline_Flags (Subp);
3788 -- Literals are by definition inlined
3790 elsif Kind = E_Enumeration_Literal then
3793 -- Anything else is an error
3797 ("expect subprogram name for pragma%", Assoc);
3801 ----------------------
3802 -- Set_Inline_Flags --
3803 ----------------------
3805 procedure Set_Inline_Flags (Subp : Entity_Id) is
3808 Set_Is_Inlined (Subp, True);
3811 if not Has_Pragma_Inline (Subp) then
3812 Set_Has_Pragma_Inline (Subp);
3816 if Prag_Id = Pragma_Inline_Always then
3817 Set_Has_Pragma_Inline_Always (Subp);
3819 end Set_Inline_Flags;
3821 -- Start of processing for Process_Inline
3824 Check_No_Identifiers;
3825 Check_At_Least_N_Arguments (1);
3828 Inline_Processing_Required := True;
3832 while Present (Assoc) loop
3833 Subp_Id := Expression (Assoc);
3837 if Is_Entity_Name (Subp_Id) then
3838 Subp := Entity (Subp_Id);
3840 if Subp = Any_Id then
3842 -- If previous error, avoid cascaded errors
3850 while Present (Homonym (Subp))
3851 and then Scope (Homonym (Subp)) = Current_Scope
3853 Make_Inline (Homonym (Subp));
3854 Subp := Homonym (Subp);
3861 ("inappropriate argument for pragma%", Assoc);
3864 and then Warn_On_Redundant_Constructs
3865 and then not Suppress_All_Inlining
3867 if Inlining_Not_Possible (Subp) then
3869 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3872 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3880 ----------------------------
3881 -- Process_Interface_Name --
3882 ----------------------------
3884 procedure Process_Interface_Name
3885 (Subprogram_Def : Entity_Id;
3891 String_Val : String_Id;
3893 procedure Check_Form_Of_Interface_Name
3895 Ext_Name_Case : Boolean);
3896 -- SN is a string literal node for an interface name. This routine
3897 -- performs some minimal checks that the name is reasonable. In
3898 -- particular that no spaces or other obviously incorrect characters
3899 -- appear. This is only a warning, since any characters are allowed.
3900 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3902 ----------------------------------
3903 -- Check_Form_Of_Interface_Name --
3904 ----------------------------------
3906 procedure Check_Form_Of_Interface_Name
3908 Ext_Name_Case : Boolean)
3910 S : constant String_Id := Strval (Expr_Value_S (SN));
3911 SL : constant Nat := String_Length (S);
3916 Error_Msg_N ("interface name cannot be null string", SN);
3919 for J in 1 .. SL loop
3920 C := Get_String_Char (S, J);
3922 -- Look for dubious character and issue unconditional warning.
3923 -- Definitely dubious if not in character range.
3925 if not In_Character_Range (C)
3929 or else Get_Character (C) = ','
3931 -- For all cases except link names on a CLI target, spaces
3932 -- and slashes are also dubious (in CLI for link names, we
3933 -- use spaces and possibly slashes for special purposes).
3935 -- Where is this usage documented ???
3937 or else ((Ext_Name_Case or else VM_Target /= CLI_Target)
3938 and then (Get_Character (C) = ' '
3940 Get_Character (C) = '/'
3942 Get_Character (C) = '\'))
3945 ("?interface name contains illegal character",
3946 Sloc (SN) + Source_Ptr (J));
3949 end Check_Form_Of_Interface_Name;
3951 -- Start of processing for Process_Interface_Name
3954 if No (Link_Arg) then
3955 if No (Ext_Arg) then
3956 if VM_Target = CLI_Target
3957 and then Ekind (Subprogram_Def) = E_Package
3958 and then Nkind (Parent (Subprogram_Def)) =
3959 N_Package_Specification
3960 and then Present (Generic_Parent (Parent (Subprogram_Def)))
3965 (Generic_Parent (Parent (Subprogram_Def))));
3970 elsif Chars (Ext_Arg) = Name_Link_Name then
3972 Link_Nam := Expression (Ext_Arg);
3975 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3976 Ext_Nam := Expression (Ext_Arg);
3981 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3982 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3983 Ext_Nam := Expression (Ext_Arg);
3984 Link_Nam := Expression (Link_Arg);
3987 -- Check expressions for external name and link name are static
3989 if Present (Ext_Nam) then
3990 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3991 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
3993 -- Verify that external name is not the name of a local entity,
3994 -- which would hide the imported one and could lead to run-time
3995 -- surprises. The problem can only arise for entities declared in
3996 -- a package body (otherwise the external name is fully qualified
3997 -- and will not conflict).
4005 if Prag_Id = Pragma_Import then
4006 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4008 E := Entity_Id (Get_Name_Table_Info (Nam));
4010 if Nam /= Chars (Subprogram_Def)
4011 and then Present (E)
4012 and then not Is_Overloadable (E)
4013 and then Is_Immediately_Visible (E)
4014 and then not Is_Imported (E)
4015 and then Ekind (Scope (E)) = E_Package
4018 while Present (Par) loop
4019 if Nkind (Par) = N_Package_Body then
4020 Error_Msg_Sloc := Sloc (E);
4022 ("imported entity is hidden by & declared#",
4027 Par := Parent (Par);
4034 if Present (Link_Nam) then
4035 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4036 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4039 -- If there is no link name, just set the external name
4041 if No (Link_Nam) then
4042 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4044 -- For the Link_Name case, the given literal is preceded by an
4045 -- asterisk, which indicates to GCC that the given name should
4046 -- be taken literally, and in particular that no prepending of
4047 -- underlines should occur, even in systems where this is the
4053 if VM_Target = No_VM then
4054 Store_String_Char (Get_Char_Code ('*'));
4057 String_Val := Strval (Expr_Value_S (Link_Nam));
4058 Store_String_Chars (String_Val);
4060 Make_String_Literal (Sloc (Link_Nam),
4061 Strval => End_String);
4064 Set_Encoded_Interface_Name
4065 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4066 Check_Duplicated_Export_Name (Link_Nam);
4067 end Process_Interface_Name;
4069 -----------------------------------------
4070 -- Process_Interrupt_Or_Attach_Handler --
4071 -----------------------------------------
4073 procedure Process_Interrupt_Or_Attach_Handler is
4074 Arg1_X : constant Node_Id := Expression (Arg1);
4075 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4076 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4079 Set_Is_Interrupt_Handler (Handler_Proc);
4081 -- If the pragma is not associated with a handler procedure
4082 -- within a protected type, then it must be for a nonprotected
4083 -- procedure for the AAMP target, in which case we don't
4084 -- associate a representation item with the procedure's scope.
4086 if Ekind (Proc_Scope) = E_Protected_Type then
4087 if Prag_Id = Pragma_Interrupt_Handler
4089 Prag_Id = Pragma_Attach_Handler
4091 Record_Rep_Item (Proc_Scope, N);
4094 end Process_Interrupt_Or_Attach_Handler;
4096 --------------------------------------------------
4097 -- Process_Restrictions_Or_Restriction_Warnings --
4098 --------------------------------------------------
4100 -- Note: some of the simple identifier cases were handled in par-prag,
4101 -- but it is harmless (and more straightforward) to simply handle all
4102 -- cases here, even if it means we repeat a bit of work in some cases.
4104 procedure Process_Restrictions_Or_Restriction_Warnings
4108 R_Id : Restriction_Id;
4113 procedure Check_Unit_Name (N : Node_Id);
4114 -- Checks unit name parameter for No_Dependence. Returns if it has
4115 -- an appropriate form, otherwise raises pragma argument error.
4117 ---------------------
4118 -- Check_Unit_Name --
4119 ---------------------
4121 procedure Check_Unit_Name (N : Node_Id) is
4123 if Nkind (N) = N_Selected_Component then
4124 Check_Unit_Name (Prefix (N));
4125 Check_Unit_Name (Selector_Name (N));
4127 elsif Nkind (N) = N_Identifier then
4132 ("wrong form for unit name for No_Dependence", N);
4134 end Check_Unit_Name;
4136 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4139 Check_Ada_83_Warning;
4140 Check_At_Least_N_Arguments (1);
4141 Check_Valid_Configuration_Pragma;
4144 while Present (Arg) loop
4146 Expr := Expression (Arg);
4148 -- Case of no restriction identifier present
4150 if Id = No_Name then
4151 if Nkind (Expr) /= N_Identifier then
4153 ("invalid form for restriction", Arg);
4158 (Process_Restriction_Synonyms (Expr));
4160 if R_Id not in All_Boolean_Restrictions then
4161 Error_Msg_Name_1 := Pname;
4163 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4165 -- Check for possible misspelling
4167 for J in Restriction_Id loop
4169 Rnm : constant String := Restriction_Id'Image (J);
4172 Name_Buffer (1 .. Rnm'Length) := Rnm;
4173 Name_Len := Rnm'Length;
4174 Set_Casing (All_Lower_Case);
4176 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4178 (Identifier_Casing (Current_Source_File));
4179 Error_Msg_String (1 .. Rnm'Length) :=
4180 Name_Buffer (1 .. Name_Len);
4181 Error_Msg_Strlen := Rnm'Length;
4183 ("\possible misspelling of ""~""",
4184 Get_Pragma_Arg (Arg));
4193 if Implementation_Restriction (R_Id) then
4194 Check_Restriction (No_Implementation_Restrictions, Arg);
4197 -- If this is a warning, then set the warning unless we already
4198 -- have a real restriction active (we never want a warning to
4199 -- override a real restriction).
4202 if not Restriction_Active (R_Id) then
4203 Set_Restriction (R_Id, N);
4204 Restriction_Warnings (R_Id) := True;
4207 -- If real restriction case, then set it and make sure that the
4208 -- restriction warning flag is off, since a real restriction
4209 -- always overrides a warning.
4212 Set_Restriction (R_Id, N);
4213 Restriction_Warnings (R_Id) := False;
4216 -- A very special case that must be processed here: pragma
4217 -- Restrictions (No_Exceptions) turns off all run-time
4218 -- checking. This is a bit dubious in terms of the formal
4219 -- language definition, but it is what is intended by RM
4220 -- H.4(12). Restriction_Warnings never affects generated code
4221 -- so this is done only in the real restriction case.
4223 if R_Id = No_Exceptions and then not Warn then
4224 Scope_Suppress := (others => True);
4227 -- Case of No_Dependence => unit-name. Note that the parser
4228 -- already made the necessary entry in the No_Dependence table.
4230 elsif Id = Name_No_Dependence then
4231 Check_Unit_Name (Expr);
4233 -- All other cases of restriction identifier present
4236 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4237 Analyze_And_Resolve (Expr, Any_Integer);
4239 if R_Id not in All_Parameter_Restrictions then
4241 ("invalid restriction parameter identifier", Arg);
4243 elsif not Is_OK_Static_Expression (Expr) then
4244 Flag_Non_Static_Expr
4245 ("value must be static expression!", Expr);
4248 elsif not Is_Integer_Type (Etype (Expr))
4249 or else Expr_Value (Expr) < 0
4252 ("value must be non-negative integer", Arg);
4255 -- Restriction pragma is active
4257 Val := Expr_Value (Expr);
4259 if not UI_Is_In_Int_Range (Val) then
4261 ("pragma ignored, value too large?", Arg);
4264 -- Warning case. If the real restriction is active, then we
4265 -- ignore the request, since warning never overrides a real
4266 -- restriction. Otherwise we set the proper warning. Note that
4267 -- this circuit sets the warning again if it is already set,
4268 -- which is what we want, since the constant may have changed.
4271 if not Restriction_Active (R_Id) then
4273 (R_Id, N, Integer (UI_To_Int (Val)));
4274 Restriction_Warnings (R_Id) := True;
4277 -- Real restriction case, set restriction and make sure warning
4278 -- flag is off since real restriction always overrides warning.
4281 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4282 Restriction_Warnings (R_Id) := False;
4288 end Process_Restrictions_Or_Restriction_Warnings;
4290 ---------------------------------
4291 -- Process_Suppress_Unsuppress --
4292 ---------------------------------
4294 -- Note: this procedure makes entries in the check suppress data
4295 -- structures managed by Sem. See spec of package Sem for full
4296 -- details on how we handle recording of check suppression.
4298 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4303 In_Package_Spec : constant Boolean :=
4304 (Ekind (Current_Scope) = E_Package
4306 Ekind (Current_Scope) = E_Generic_Package)
4307 and then not In_Package_Body (Current_Scope);
4309 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4310 -- Used to suppress a single check on the given entity
4312 --------------------------------
4313 -- Suppress_Unsuppress_Echeck --
4314 --------------------------------
4316 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4318 Set_Checks_May_Be_Suppressed (E);
4320 if In_Package_Spec then
4321 Push_Global_Suppress_Stack_Entry
4324 Suppress => Suppress_Case);
4327 Push_Local_Suppress_Stack_Entry
4330 Suppress => Suppress_Case);
4333 -- If this is a first subtype, and the base type is distinct,
4334 -- then also set the suppress flags on the base type.
4336 if Is_First_Subtype (E)
4337 and then Etype (E) /= E
4339 Suppress_Unsuppress_Echeck (Etype (E), C);
4341 end Suppress_Unsuppress_Echeck;
4343 -- Start of processing for Process_Suppress_Unsuppress
4346 -- Suppress/Unsuppress can appear as a configuration pragma,
4347 -- or in a declarative part or a package spec (RM 11.5(5))
4349 if not Is_Configuration_Pragma then
4350 Check_Is_In_Decl_Part_Or_Package_Spec;
4353 Check_At_Least_N_Arguments (1);
4354 Check_At_Most_N_Arguments (2);
4355 Check_No_Identifier (Arg1);
4356 Check_Arg_Is_Identifier (Arg1);
4358 C := Get_Check_Id (Chars (Expression (Arg1)));
4360 if C = No_Check_Id then
4362 ("argument of pragma% is not valid check name", Arg1);
4365 if not Suppress_Case
4366 and then (C = All_Checks or else C = Overflow_Check)
4368 Opt.Overflow_Checks_Unsuppressed := True;
4371 if Arg_Count = 1 then
4373 -- Make an entry in the local scope suppress table. This is the
4374 -- table that directly shows the current value of the scope
4375 -- suppress check for any check id value.
4377 if C = All_Checks then
4379 -- For All_Checks, we set all specific predefined checks with
4380 -- the exception of Elaboration_Check, which is handled
4381 -- specially because of not wanting All_Checks to have the
4382 -- effect of deactivating static elaboration order processing.
4384 for J in Scope_Suppress'Range loop
4385 if J /= Elaboration_Check then
4386 Scope_Suppress (J) := Suppress_Case;
4390 -- If not All_Checks, and predefined check, then set appropriate
4391 -- scope entry. Note that we will set Elaboration_Check if this
4392 -- is explicitly specified.
4394 elsif C in Predefined_Check_Id then
4395 Scope_Suppress (C) := Suppress_Case;
4398 -- Also make an entry in the Local_Entity_Suppress table
4400 Push_Local_Suppress_Stack_Entry
4403 Suppress => Suppress_Case);
4405 -- Case of two arguments present, where the check is suppressed for
4406 -- a specified entity (given as the second argument of the pragma)
4409 Check_Optional_Identifier (Arg2, Name_On);
4410 E_Id := Expression (Arg2);
4413 if not Is_Entity_Name (E_Id) then
4415 ("second argument of pragma% must be entity name", Arg2);
4424 -- Enforce RM 11.5(7) which requires that for a pragma that
4425 -- appears within a package spec, the named entity must be
4426 -- within the package spec. We allow the package name itself
4427 -- to be mentioned since that makes sense, although it is not
4428 -- strictly allowed by 11.5(7).
4431 and then E /= Current_Scope
4432 and then Scope (E) /= Current_Scope
4435 ("entity in pragma% is not in package spec (RM 11.5(7))",
4439 -- Loop through homonyms. As noted below, in the case of a package
4440 -- spec, only homonyms within the package spec are considered.
4443 Suppress_Unsuppress_Echeck (E, C);
4445 if Is_Generic_Instance (E)
4446 and then Is_Subprogram (E)
4447 and then Present (Alias (E))
4449 Suppress_Unsuppress_Echeck (Alias (E), C);
4452 -- Move to next homonym
4457 -- If we are within a package specification, the
4458 -- pragma only applies to homonyms in the same scope.
4460 exit when In_Package_Spec
4461 and then Scope (E) /= Current_Scope;
4464 end Process_Suppress_Unsuppress;
4470 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4472 if Is_Imported (E) then
4474 ("cannot export entity& that was previously imported", Arg);
4476 elsif Present (Address_Clause (E)) then
4478 ("cannot export entity& that has an address clause", Arg);
4481 Set_Is_Exported (E);
4483 -- Generate a reference for entity explicitly, because the
4484 -- identifier may be overloaded and name resolution will not
4487 Generate_Reference (E, Arg);
4489 -- Deal with exporting non-library level entity
4491 if not Is_Library_Level_Entity (E) then
4493 -- Not allowed at all for subprograms
4495 if Is_Subprogram (E) then
4496 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4498 -- Otherwise set public and statically allocated
4502 Set_Is_Statically_Allocated (E);
4504 -- Warn if the corresponding W flag is set and the pragma
4505 -- comes from source. The latter may not be true e.g. on
4506 -- VMS where we expand export pragmas for exception codes
4507 -- associated with imported or exported exceptions. We do
4508 -- not want to generate a warning for something that the
4509 -- user did not write.
4511 if Warn_On_Export_Import
4512 and then Comes_From_Source (Arg)
4515 ("?& has been made static as a result of Export", Arg, E);
4517 ("\this usage is non-standard and non-portable", Arg);
4522 if Warn_On_Export_Import and then Is_Type (E) then
4524 ("exporting a type has no effect?", Arg, E);
4527 if Warn_On_Export_Import and Inside_A_Generic then
4529 ("all instances of& will have the same external name?", Arg, E);
4533 ----------------------------------------------
4534 -- Set_Extended_Import_Export_External_Name --
4535 ----------------------------------------------
4537 procedure Set_Extended_Import_Export_External_Name
4538 (Internal_Ent : Entity_Id;
4539 Arg_External : Node_Id)
4541 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4545 if No (Arg_External) then
4549 Check_Arg_Is_External_Name (Arg_External);
4551 if Nkind (Arg_External) = N_String_Literal then
4552 if String_Length (Strval (Arg_External)) = 0 then
4555 New_Name := Adjust_External_Name_Case (Arg_External);
4558 elsif Nkind (Arg_External) = N_Identifier then
4559 New_Name := Get_Default_External_Name (Arg_External);
4561 -- Check_Arg_Is_External_Name should let through only
4562 -- identifiers and string literals or static string
4563 -- expressions (which are folded to string literals).
4566 raise Program_Error;
4569 -- If we already have an external name set (by a prior normal
4570 -- Import or Export pragma), then the external names must match
4572 if Present (Interface_Name (Internal_Ent)) then
4573 Check_Matching_Internal_Names : declare
4574 S1 : constant String_Id := Strval (Old_Name);
4575 S2 : constant String_Id := Strval (New_Name);
4578 -- Called if names do not match
4584 procedure Mismatch is
4586 Error_Msg_Sloc := Sloc (Old_Name);
4588 ("external name does not match that given #",
4592 -- Start of processing for Check_Matching_Internal_Names
4595 if String_Length (S1) /= String_Length (S2) then
4599 for J in 1 .. String_Length (S1) loop
4600 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4605 end Check_Matching_Internal_Names;
4607 -- Otherwise set the given name
4610 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4611 Check_Duplicated_Export_Name (New_Name);
4613 end Set_Extended_Import_Export_External_Name;
4619 procedure Set_Imported (E : Entity_Id) is
4621 -- Error message if already imported or exported
4623 if Is_Exported (E) or else Is_Imported (E) then
4624 if Is_Exported (E) then
4625 Error_Msg_NE ("entity& was previously exported", N, E);
4627 Error_Msg_NE ("entity& was previously imported", N, E);
4630 Error_Msg_Name_1 := Pname;
4632 ("\(pragma% applies to all previous entities)", N);
4634 Error_Msg_Sloc := Sloc (E);
4635 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4637 -- Here if not previously imported or exported, OK to import
4640 Set_Is_Imported (E);
4642 -- If the entity is an object that is not at the library
4643 -- level, then it is statically allocated. We do not worry
4644 -- about objects with address clauses in this context since
4645 -- they are not really imported in the linker sense.
4648 and then not Is_Library_Level_Entity (E)
4649 and then No (Address_Clause (E))
4651 Set_Is_Statically_Allocated (E);
4656 -------------------------
4657 -- Set_Mechanism_Value --
4658 -------------------------
4660 -- Note: the mechanism name has not been analyzed (and cannot indeed
4661 -- be analyzed, since it is semantic nonsense), so we get it in the
4662 -- exact form created by the parser.
4664 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4667 Mech_Name_Id : Name_Id;
4669 procedure Bad_Class;
4670 -- Signal bad descriptor class name
4672 procedure Bad_Mechanism;
4673 -- Signal bad mechanism name
4679 procedure Bad_Class is
4681 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4684 -------------------------
4685 -- Bad_Mechanism_Value --
4686 -------------------------
4688 procedure Bad_Mechanism is
4690 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4693 -- Start of processing for Set_Mechanism_Value
4696 if Mechanism (Ent) /= Default_Mechanism then
4698 ("mechanism for & has already been set", Mech_Name, Ent);
4701 -- MECHANISM_NAME ::= value | reference | descriptor |
4704 if Nkind (Mech_Name) = N_Identifier then
4705 if Chars (Mech_Name) = Name_Value then
4706 Set_Mechanism (Ent, By_Copy);
4709 elsif Chars (Mech_Name) = Name_Reference then
4710 Set_Mechanism (Ent, By_Reference);
4713 elsif Chars (Mech_Name) = Name_Descriptor then
4714 Check_VMS (Mech_Name);
4715 Set_Mechanism (Ent, By_Descriptor);
4718 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4719 Check_VMS (Mech_Name);
4720 Set_Mechanism (Ent, By_Short_Descriptor);
4723 elsif Chars (Mech_Name) = Name_Copy then
4725 ("bad mechanism name, Value assumed", Mech_Name);
4731 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4732 -- short_descriptor (CLASS_NAME)
4733 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4735 -- Note: this form is parsed as an indexed component
4737 elsif Nkind (Mech_Name) = N_Indexed_Component then
4739 Class := First (Expressions (Mech_Name));
4741 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4742 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4743 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4744 or else Present (Next (Class))
4748 Mech_Name_Id := Chars (Prefix (Mech_Name));
4751 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4752 -- short_descriptor (Class => CLASS_NAME)
4753 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4755 -- Note: this form is parsed as a function call
4757 elsif Nkind (Mech_Name) = N_Function_Call then
4759 Param := First (Parameter_Associations (Mech_Name));
4761 if Nkind (Name (Mech_Name)) /= N_Identifier
4762 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4763 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4764 or else Present (Next (Param))
4765 or else No (Selector_Name (Param))
4766 or else Chars (Selector_Name (Param)) /= Name_Class
4770 Class := Explicit_Actual_Parameter (Param);
4771 Mech_Name_Id := Chars (Name (Mech_Name));
4778 -- Fall through here with Class set to descriptor class name
4780 Check_VMS (Mech_Name);
4782 if Nkind (Class) /= N_Identifier then
4785 elsif Mech_Name_Id = Name_Descriptor
4786 and then Chars (Class) = Name_UBS
4788 Set_Mechanism (Ent, By_Descriptor_UBS);
4790 elsif Mech_Name_Id = Name_Descriptor
4791 and then Chars (Class) = Name_UBSB
4793 Set_Mechanism (Ent, By_Descriptor_UBSB);
4795 elsif Mech_Name_Id = Name_Descriptor
4796 and then Chars (Class) = Name_UBA
4798 Set_Mechanism (Ent, By_Descriptor_UBA);
4800 elsif Mech_Name_Id = Name_Descriptor
4801 and then Chars (Class) = Name_S
4803 Set_Mechanism (Ent, By_Descriptor_S);
4805 elsif Mech_Name_Id = Name_Descriptor
4806 and then Chars (Class) = Name_SB
4808 Set_Mechanism (Ent, By_Descriptor_SB);
4810 elsif Mech_Name_Id = Name_Descriptor
4811 and then Chars (Class) = Name_A
4813 Set_Mechanism (Ent, By_Descriptor_A);
4815 elsif Mech_Name_Id = Name_Descriptor
4816 and then Chars (Class) = Name_NCA
4818 Set_Mechanism (Ent, By_Descriptor_NCA);
4820 elsif Mech_Name_Id = Name_Short_Descriptor
4821 and then Chars (Class) = Name_UBS
4823 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4825 elsif Mech_Name_Id = Name_Short_Descriptor
4826 and then Chars (Class) = Name_UBSB
4828 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4830 elsif Mech_Name_Id = Name_Short_Descriptor
4831 and then Chars (Class) = Name_UBA
4833 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4835 elsif Mech_Name_Id = Name_Short_Descriptor
4836 and then Chars (Class) = Name_S
4838 Set_Mechanism (Ent, By_Short_Descriptor_S);
4840 elsif Mech_Name_Id = Name_Short_Descriptor
4841 and then Chars (Class) = Name_SB
4843 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4845 elsif Mech_Name_Id = Name_Short_Descriptor
4846 and then Chars (Class) = Name_A
4848 Set_Mechanism (Ent, By_Short_Descriptor_A);
4850 elsif Mech_Name_Id = Name_Short_Descriptor
4851 and then Chars (Class) = Name_NCA
4853 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4858 end Set_Mechanism_Value;
4860 ---------------------------
4861 -- Set_Ravenscar_Profile --
4862 ---------------------------
4864 -- The tasks to be done here are
4866 -- Set required policies
4868 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4869 -- pragma Locking_Policy (Ceiling_Locking)
4871 -- Set Detect_Blocking mode
4873 -- Set required restrictions (see System.Rident for detailed list)
4875 procedure Set_Ravenscar_Profile (N : Node_Id) is
4877 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4879 if Task_Dispatching_Policy /= ' '
4880 and then Task_Dispatching_Policy /= 'F'
4882 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4883 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4885 -- Set the FIFO_Within_Priorities policy, but always preserve
4886 -- System_Location since we like the error message with the run time
4890 Task_Dispatching_Policy := 'F';
4892 if Task_Dispatching_Policy_Sloc /= System_Location then
4893 Task_Dispatching_Policy_Sloc := Loc;
4897 -- pragma Locking_Policy (Ceiling_Locking)
4899 if Locking_Policy /= ' '
4900 and then Locking_Policy /= 'C'
4902 Error_Msg_Sloc := Locking_Policy_Sloc;
4903 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4905 -- Set the Ceiling_Locking policy, but preserve System_Location since
4906 -- we like the error message with the run time name.
4909 Locking_Policy := 'C';
4911 if Locking_Policy_Sloc /= System_Location then
4912 Locking_Policy_Sloc := Loc;
4916 -- pragma Detect_Blocking
4918 Detect_Blocking := True;
4920 -- Set the corresponding restrictions
4922 Set_Profile_Restrictions
4923 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4924 end Set_Ravenscar_Profile;
4926 -- Start of processing for Analyze_Pragma
4929 -- Deal with unrecognized pragma
4931 if not Is_Pragma_Name (Pname) then
4932 if Warn_On_Unrecognized_Pragma then
4933 Error_Msg_Name_1 := Pname;
4934 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
4936 for PN in First_Pragma_Name .. Last_Pragma_Name loop
4937 if Is_Bad_Spelling_Of (Pname, PN) then
4938 Error_Msg_Name_1 := PN;
4940 ("\?possible misspelling of %!", Pragma_Identifier (N));
4949 -- Here to start processing for recognized pragma
4951 Prag_Id := Get_Pragma_Id (Pname);
4960 if Present (Pragma_Argument_Associations (N)) then
4961 Arg1 := First (Pragma_Argument_Associations (N));
4963 if Present (Arg1) then
4964 Arg2 := Next (Arg1);
4966 if Present (Arg2) then
4967 Arg3 := Next (Arg2);
4969 if Present (Arg3) then
4970 Arg4 := Next (Arg3);
4976 -- Count number of arguments
4983 while Present (Arg_Node) loop
4984 Arg_Count := Arg_Count + 1;
4989 -- An enumeration type defines the pragmas that are supported by the
4990 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
4991 -- into the corresponding enumeration value for the following case.
4999 -- pragma Abort_Defer;
5001 when Pragma_Abort_Defer =>
5003 Check_Arg_Count (0);
5005 -- The only required semantic processing is to check the
5006 -- placement. This pragma must appear at the start of the
5007 -- statement sequence of a handled sequence of statements.
5009 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5010 or else N /= First (Statements (Parent (N)))
5021 -- Note: this pragma also has some specific processing in Par.Prag
5022 -- because we want to set the Ada version mode during parsing.
5024 when Pragma_Ada_83 =>
5026 Check_Arg_Count (0);
5028 -- We really should check unconditionally for proper configuration
5029 -- pragma placement, since we really don't want mixed Ada modes
5030 -- within a single unit, and the GNAT reference manual has always
5031 -- said this was a configuration pragma, but we did not check and
5032 -- are hesitant to add the check now.
5034 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5035 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5037 if Ada_Version >= Ada_05 then
5038 Check_Valid_Configuration_Pragma;
5041 -- Now set Ada 83 mode
5043 Ada_Version := Ada_83;
5044 Ada_Version_Explicit := Ada_Version;
5052 -- Note: this pragma also has some specific processing in Par.Prag
5053 -- because we want to set the Ada 83 version mode during parsing.
5055 when Pragma_Ada_95 =>
5057 Check_Arg_Count (0);
5059 -- We really should check unconditionally for proper configuration
5060 -- pragma placement, since we really don't want mixed Ada modes
5061 -- within a single unit, and the GNAT reference manual has always
5062 -- said this was a configuration pragma, but we did not check and
5063 -- are hesitant to add the check now.
5065 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5066 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5068 if Ada_Version >= Ada_05 then
5069 Check_Valid_Configuration_Pragma;
5072 -- Now set Ada 95 mode
5074 Ada_Version := Ada_95;
5075 Ada_Version_Explicit := Ada_Version;
5077 ---------------------
5078 -- Ada_05/Ada_2005 --
5079 ---------------------
5082 -- pragma Ada_05 (LOCAL_NAME);
5085 -- pragma Ada_2005 (LOCAL_NAME):
5087 -- Note: these pragma also have some specific processing in Par.Prag
5088 -- because we want to set the Ada 2005 version mode during parsing.
5090 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5096 if Arg_Count = 1 then
5097 Check_Arg_Is_Local_Name (Arg1);
5098 E_Id := Expression (Arg1);
5100 if Etype (E_Id) = Any_Type then
5104 Set_Is_Ada_2005_Only (Entity (E_Id));
5107 Check_Arg_Count (0);
5109 -- For Ada_2005 we unconditionally enforce the documented
5110 -- configuration pragma placement, since we do not want to
5111 -- tolerate mixed modes in a unit involving Ada 2005. That
5112 -- would cause real difficulties for those cases where there
5113 -- are incompatibilities between Ada 95 and Ada 2005.
5115 Check_Valid_Configuration_Pragma;
5117 -- Now set Ada 2005 mode
5119 Ada_Version := Ada_05;
5120 Ada_Version_Explicit := Ada_05;
5124 ----------------------
5125 -- All_Calls_Remote --
5126 ----------------------
5128 -- pragma All_Calls_Remote [(library_package_NAME)];
5130 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5131 Lib_Entity : Entity_Id;
5134 Check_Ada_83_Warning;
5135 Check_Valid_Library_Unit_Pragma;
5137 if Nkind (N) = N_Null_Statement then
5141 Lib_Entity := Find_Lib_Unit_Name;
5143 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5145 if Present (Lib_Entity)
5146 and then not Debug_Flag_U
5148 if not Is_Remote_Call_Interface (Lib_Entity) then
5149 Error_Pragma ("pragma% only apply to rci unit");
5151 -- Set flag for entity of the library unit
5154 Set_Has_All_Calls_Remote (Lib_Entity);
5158 end All_Calls_Remote;
5164 -- pragma Annotate (IDENTIFIER {, ARG});
5165 -- ARG ::= NAME | EXPRESSION
5167 when Pragma_Annotate => Annotate : begin
5169 Check_At_Least_N_Arguments (1);
5170 Check_Arg_Is_Identifier (Arg1);
5178 while Present (Arg) loop
5179 Exp := Expression (Arg);
5182 if Is_Entity_Name (Exp) then
5185 elsif Nkind (Exp) = N_String_Literal then
5186 Resolve (Exp, Standard_String);
5188 elsif Is_Overloaded (Exp) then
5189 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
5204 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5205 -- [, [Message =>] Static_String_EXPRESSION]);
5207 when Pragma_Assert => Assert : declare
5213 Check_At_Least_N_Arguments (1);
5214 Check_At_Most_N_Arguments (2);
5215 Check_Arg_Order ((Name_Check, Name_Message));
5216 Check_Optional_Identifier (Arg1, Name_Check);
5218 -- We treat pragma Assert as equivalent to:
5220 -- pragma Check (Assertion, condition [, msg]);
5222 -- So rewrite pragma in this manner, and analyze the result
5224 Expr := Get_Pragma_Arg (Arg1);
5226 Make_Pragma_Argument_Association (Loc,
5228 Make_Identifier (Loc,
5229 Chars => Name_Assertion)),
5231 Make_Pragma_Argument_Association (Sloc (Expr),
5232 Expression => Expr));
5234 if Arg_Count > 1 then
5235 Check_Optional_Identifier (Arg2, Name_Message);
5236 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5237 Append_To (Newa, Relocate_Node (Arg2));
5242 Chars => Name_Check,
5243 Pragma_Argument_Associations => Newa));
5247 ----------------------
5248 -- Assertion_Policy --
5249 ----------------------
5251 -- pragma Assertion_Policy (Check | Ignore)
5253 when Pragma_Assertion_Policy => Assertion_Policy : declare
5258 Check_Valid_Configuration_Pragma;
5259 Check_Arg_Count (1);
5260 Check_No_Identifiers;
5261 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5263 -- We treat pragma Assertion_Policy as equivalent to:
5265 -- pragma Check_Policy (Assertion, policy)
5267 -- So rewrite the pragma in that manner and link on to the chain
5268 -- of Check_Policy pragmas, marking the pragma as analyzed.
5270 Policy := Get_Pragma_Arg (Arg1);
5274 Chars => Name_Check_Policy,
5276 Pragma_Argument_Associations => New_List (
5277 Make_Pragma_Argument_Association (Loc,
5279 Make_Identifier (Loc,
5280 Chars => Name_Assertion)),
5282 Make_Pragma_Argument_Association (Loc,
5284 Make_Identifier (Sloc (Policy),
5285 Chars => Chars (Policy))))));
5288 Set_Next_Pragma (N, Opt.Check_Policy_List);
5289 Opt.Check_Policy_List := N;
5290 end Assertion_Policy;
5296 -- pragma AST_Entry (entry_IDENTIFIER);
5298 when Pragma_AST_Entry => AST_Entry : declare
5304 Check_Arg_Count (1);
5305 Check_No_Identifiers;
5306 Check_Arg_Is_Local_Name (Arg1);
5307 Ent := Entity (Expression (Arg1));
5309 -- Note: the implementation of the AST_Entry pragma could handle
5310 -- the entry family case fine, but for now we are consistent with
5311 -- the DEC rules, and do not allow the pragma, which of course
5312 -- has the effect of also forbidding the attribute.
5314 if Ekind (Ent) /= E_Entry then
5316 ("pragma% argument must be simple entry name", Arg1);
5318 elsif Is_AST_Entry (Ent) then
5320 ("duplicate % pragma for entry", Arg1);
5322 elsif Has_Homonym (Ent) then
5324 ("pragma% argument cannot specify overloaded entry", Arg1);
5328 FF : constant Entity_Id := First_Formal (Ent);
5331 if Present (FF) then
5332 if Present (Next_Formal (FF)) then
5334 ("entry for pragma% can have only one argument",
5337 elsif Parameter_Mode (FF) /= E_In_Parameter then
5339 ("entry parameter for pragma% must have mode IN",
5345 Set_Is_AST_Entry (Ent);
5353 -- pragma Asynchronous (LOCAL_NAME);
5355 when Pragma_Asynchronous => Asynchronous : declare
5363 procedure Process_Async_Pragma;
5364 -- Common processing for procedure and access-to-procedure case
5366 --------------------------
5367 -- Process_Async_Pragma --
5368 --------------------------
5370 procedure Process_Async_Pragma is
5373 Set_Is_Asynchronous (Nm);
5377 -- The formals should be of mode IN (RM E.4.1(6))
5380 while Present (S) loop
5381 Formal := Defining_Identifier (S);
5383 if Nkind (Formal) = N_Defining_Identifier
5384 and then Ekind (Formal) /= E_In_Parameter
5387 ("pragma% procedure can only have IN parameter",
5394 Set_Is_Asynchronous (Nm);
5395 end Process_Async_Pragma;
5397 -- Start of processing for pragma Asynchronous
5400 Check_Ada_83_Warning;
5401 Check_No_Identifiers;
5402 Check_Arg_Count (1);
5403 Check_Arg_Is_Local_Name (Arg1);
5405 if Debug_Flag_U then
5409 C_Ent := Cunit_Entity (Current_Sem_Unit);
5410 Analyze (Expression (Arg1));
5411 Nm := Entity (Expression (Arg1));
5413 if not Is_Remote_Call_Interface (C_Ent)
5414 and then not Is_Remote_Types (C_Ent)
5416 -- This pragma should only appear in an RCI or Remote Types
5417 -- unit (RM E.4.1(4))
5420 ("pragma% not in Remote_Call_Interface or " &
5421 "Remote_Types unit");
5424 if Ekind (Nm) = E_Procedure
5425 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5427 if not Is_Remote_Call_Interface (Nm) then
5429 ("pragma% cannot be applied on non-remote procedure",
5433 L := Parameter_Specifications (Parent (Nm));
5434 Process_Async_Pragma;
5437 elsif Ekind (Nm) = E_Function then
5439 ("pragma% cannot be applied to function", Arg1);
5441 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5443 if Is_Record_Type (Nm) then
5444 -- A record type that is the Equivalent_Type for
5445 -- a remote access-to-subprogram type.
5447 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5450 -- A non-expanded RAS type (case where distribution is
5453 N := Declaration_Node (Nm);
5456 if Nkind (N) = N_Full_Type_Declaration
5457 and then Nkind (Type_Definition (N)) =
5458 N_Access_Procedure_Definition
5460 L := Parameter_Specifications (Type_Definition (N));
5461 Process_Async_Pragma;
5463 if Is_Asynchronous (Nm)
5464 and then Expander_Active
5465 and then Get_PCS_Name /= Name_No_DSA
5467 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5472 ("pragma% cannot reference access-to-function type",
5476 -- Only other possibility is Access-to-class-wide type
5478 elsif Is_Access_Type (Nm)
5479 and then Is_Class_Wide_Type (Designated_Type (Nm))
5481 Check_First_Subtype (Arg1);
5482 Set_Is_Asynchronous (Nm);
5483 if Expander_Active then
5484 RACW_Type_Is_Asynchronous (Nm);
5488 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5496 -- pragma Atomic (LOCAL_NAME);
5498 when Pragma_Atomic =>
5499 Process_Atomic_Shared_Volatile;
5501 -----------------------
5502 -- Atomic_Components --
5503 -----------------------
5505 -- pragma Atomic_Components (array_LOCAL_NAME);
5507 -- This processing is shared by Volatile_Components
5509 when Pragma_Atomic_Components |
5510 Pragma_Volatile_Components =>
5512 Atomic_Components : declare
5519 Check_Ada_83_Warning;
5520 Check_No_Identifiers;
5521 Check_Arg_Count (1);
5522 Check_Arg_Is_Local_Name (Arg1);
5523 E_Id := Expression (Arg1);
5525 if Etype (E_Id) = Any_Type then
5531 if Rep_Item_Too_Early (E, N)
5533 Rep_Item_Too_Late (E, N)
5538 D := Declaration_Node (E);
5541 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5543 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5544 and then Nkind (D) = N_Object_Declaration
5545 and then Nkind (Object_Definition (D)) =
5546 N_Constrained_Array_Definition)
5548 -- The flag is set on the object, or on the base type
5550 if Nkind (D) /= N_Object_Declaration then
5554 Set_Has_Volatile_Components (E);
5556 if Prag_Id = Pragma_Atomic_Components then
5557 Set_Has_Atomic_Components (E);
5559 if Is_Packed (E) then
5560 Set_Is_Packed (E, False);
5563 ("?Pack canceled, cannot pack atomic components",
5569 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5571 end Atomic_Components;
5573 --------------------
5574 -- Attach_Handler --
5575 --------------------
5577 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5579 when Pragma_Attach_Handler =>
5580 Check_Ada_83_Warning;
5581 Check_No_Identifiers;
5582 Check_Arg_Count (2);
5584 if No_Run_Time_Mode then
5585 Error_Msg_CRT ("Attach_Handler pragma", N);
5587 Check_Interrupt_Or_Attach_Handler;
5589 -- The expression that designates the attribute may
5590 -- depend on a discriminant, and is therefore a per-
5591 -- object expression, to be expanded in the init proc.
5592 -- If expansion is enabled, perform semantic checks
5595 if Expander_Active then
5597 Temp : constant Node_Id :=
5598 New_Copy_Tree (Expression (Arg2));
5600 Set_Parent (Temp, N);
5601 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5605 Analyze (Expression (Arg2));
5606 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5609 Process_Interrupt_Or_Attach_Handler;
5612 --------------------
5613 -- C_Pass_By_Copy --
5614 --------------------
5616 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5618 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5624 Check_Valid_Configuration_Pragma;
5625 Check_Arg_Count (1);
5626 Check_Optional_Identifier (Arg1, "max_size");
5628 Arg := Expression (Arg1);
5629 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5631 Val := Expr_Value (Arg);
5635 ("maximum size for pragma% must be positive", Arg1);
5637 elsif UI_Is_In_Int_Range (Val) then
5638 Default_C_Record_Mechanism := UI_To_Int (Val);
5640 -- If a giant value is given, Int'Last will do well enough.
5641 -- If sometime someone complains that a record larger than
5642 -- two gigabytes is not copied, we will worry about it then!
5645 Default_C_Record_Mechanism := Mechanism_Type'Last;
5653 -- pragma Check ([Name =>] Identifier,
5654 -- [Check =>] Boolean_Expression
5655 -- [,[Message =>] String_Expression]);
5657 when Pragma_Check => Check : declare
5662 -- Set True if category of assertions referenced by Name enabled
5666 Check_At_Least_N_Arguments (2);
5667 Check_At_Most_N_Arguments (3);
5668 Check_Optional_Identifier (Arg1, Name_Name);
5669 Check_Optional_Identifier (Arg2, Name_Check);
5671 if Arg_Count = 3 then
5672 Check_Optional_Identifier (Arg3, Name_Message);
5673 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5676 Check_Arg_Is_Identifier (Arg1);
5677 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5679 -- If expansion is active and the check is not enabled then we
5680 -- rewrite the Check as:
5682 -- if False and then condition then
5686 -- The reason we do this rewriting during semantic analysis rather
5687 -- than as part of normal expansion is that we cannot analyze and
5688 -- expand the code for the boolean expression directly, or it may
5689 -- cause insertion of actions that would escape the attempt to
5690 -- suppress the check code.
5692 -- Note that the Sloc for the if statement corresponds to the
5693 -- argument condition, not the pragma itself. The reason for this
5694 -- is that we may generate a warning if the condition is False at
5695 -- compile time, and we do not want to delete this warning when we
5696 -- delete the if statement.
5698 Expr := Expression (Arg2);
5700 if Expander_Active and then not Check_On then
5701 Eloc := Sloc (Expr);
5704 Make_If_Statement (Eloc,
5706 Make_And_Then (Eloc,
5707 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5708 Right_Opnd => Expr),
5709 Then_Statements => New_List (
5710 Make_Null_Statement (Eloc))));
5717 Analyze_And_Resolve (Expr, Any_Boolean);
5720 -- If assertion is of the form (X'First = literal), where X is
5721 -- a formal, then set Low_Bound_Known flag on this formal.
5723 if Nkind (Expr) = N_Op_Eq then
5725 Right : constant Node_Id := Right_Opnd (Expr);
5726 Left : constant Node_Id := Left_Opnd (Expr);
5728 if Nkind (Left) = N_Attribute_Reference
5729 and then Attribute_Name (Left) = Name_First
5730 and then Is_Entity_Name (Prefix (Left))
5731 and then Is_Formal (Entity (Prefix (Left)))
5732 and then Nkind (Right) = N_Integer_Literal
5734 Set_Low_Bound_Known (Entity (Prefix (Left)));
5744 -- pragma Check_Name (check_IDENTIFIER);
5746 when Pragma_Check_Name =>
5747 Check_No_Identifiers;
5749 Check_Valid_Configuration_Pragma;
5750 Check_Arg_Count (1);
5751 Check_Arg_Is_Identifier (Arg1);
5754 Nam : constant Name_Id := Chars (Expression (Arg1));
5757 for J in Check_Names.First .. Check_Names.Last loop
5758 if Check_Names.Table (J) = Nam then
5763 Check_Names.Append (Nam);
5770 -- pragma Check_Policy ([Name =>] IDENTIFIER,
5771 -- POLICY_IDENTIFIER;
5773 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5775 -- Note: this is a configuration pragma, but it is allowed to
5776 -- appear anywhere else.
5778 when Pragma_Check_Policy =>
5780 Check_Arg_Count (2);
5781 Check_No_Identifier (Arg2);
5782 Check_Optional_Identifier (Arg1, Name_Name);
5784 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5786 -- A Check_Policy pragma can appear either as a configuration
5787 -- pragma, or in a declarative part or a package spec (see RM
5788 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5789 -- followed for Check_Policy).
5791 if not Is_Configuration_Pragma then
5792 Check_Is_In_Decl_Part_Or_Package_Spec;
5795 Set_Next_Pragma (N, Opt.Check_Policy_List);
5796 Opt.Check_Policy_List := N;
5798 ---------------------
5799 -- CIL_Constructor --
5800 ---------------------
5802 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5804 -- Processing for this pragma is shared with Java_Constructor
5810 -- pragma Comment (static_string_EXPRESSION)
5812 -- Processing for pragma Comment shares the circuitry for pragma
5813 -- Ident. The only differences are that Ident enforces a limit of 31
5814 -- characters on its argument, and also enforces limitations on
5815 -- placement for DEC compatibility. Pragma Comment shares neither of
5816 -- these restrictions.
5822 -- pragma Common_Object (
5823 -- [Internal =>] LOCAL_NAME
5824 -- [, [External =>] EXTERNAL_SYMBOL]
5825 -- [, [Size =>] EXTERNAL_SYMBOL]);
5827 -- Processing for this pragma is shared with Psect_Object
5829 ------------------------
5830 -- Compile_Time_Error --
5831 ------------------------
5833 -- pragma Compile_Time_Error
5834 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5836 when Pragma_Compile_Time_Error =>
5838 Process_Compile_Time_Warning_Or_Error;
5840 --------------------------
5841 -- Compile_Time_Warning --
5842 --------------------------
5844 -- pragma Compile_Time_Warning
5845 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5847 when Pragma_Compile_Time_Warning =>
5849 Process_Compile_Time_Warning_Or_Error;
5855 when Pragma_Compiler_Unit =>
5857 Check_Arg_Count (0);
5858 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5860 -----------------------------
5861 -- Complete_Representation --
5862 -----------------------------
5864 -- pragma Complete_Representation;
5866 when Pragma_Complete_Representation =>
5868 Check_Arg_Count (0);
5870 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5872 ("pragma & must appear within record representation clause");
5875 ----------------------------
5876 -- Complex_Representation --
5877 ----------------------------
5879 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5881 when Pragma_Complex_Representation => Complex_Representation : declare
5888 Check_Arg_Count (1);
5889 Check_Optional_Identifier (Arg1, Name_Entity);
5890 Check_Arg_Is_Local_Name (Arg1);
5891 E_Id := Expression (Arg1);
5893 if Etype (E_Id) = Any_Type then
5899 if not Is_Record_Type (E) then
5901 ("argument for pragma% must be record type", Arg1);
5904 Ent := First_Entity (E);
5907 or else No (Next_Entity (Ent))
5908 or else Present (Next_Entity (Next_Entity (Ent)))
5909 or else not Is_Floating_Point_Type (Etype (Ent))
5910 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5913 ("record for pragma% must have two fields of the same "
5914 & "floating-point type", Arg1);
5917 Set_Has_Complex_Representation (Base_Type (E));
5919 -- We need to treat the type has having a non-standard
5920 -- representation, for back-end purposes, even though in
5921 -- general a complex will have the default representation
5922 -- of a record with two real components.
5924 Set_Has_Non_Standard_Rep (Base_Type (E));
5926 end Complex_Representation;
5928 -------------------------
5929 -- Component_Alignment --
5930 -------------------------
5932 -- pragma Component_Alignment (
5933 -- [Form =>] ALIGNMENT_CHOICE
5934 -- [, [Name =>] type_LOCAL_NAME]);
5936 -- ALIGNMENT_CHOICE ::=
5938 -- | Component_Size_4
5942 when Pragma_Component_Alignment => Component_AlignmentP : declare
5943 Args : Args_List (1 .. 2);
5944 Names : constant Name_List (1 .. 2) := (
5948 Form : Node_Id renames Args (1);
5949 Name : Node_Id renames Args (2);
5951 Atype : Component_Alignment_Kind;
5956 Gather_Associations (Names, Args);
5959 Error_Pragma ("missing Form argument for pragma%");
5962 Check_Arg_Is_Identifier (Form);
5964 -- Get proper alignment, note that Default = Component_Size
5965 -- on all machines we have so far, and we want to set this
5966 -- value rather than the default value to indicate that it
5967 -- has been explicitly set (and thus will not get overridden
5968 -- by the default component alignment for the current scope)
5970 if Chars (Form) = Name_Component_Size then
5971 Atype := Calign_Component_Size;
5973 elsif Chars (Form) = Name_Component_Size_4 then
5974 Atype := Calign_Component_Size_4;
5976 elsif Chars (Form) = Name_Default then
5977 Atype := Calign_Component_Size;
5979 elsif Chars (Form) = Name_Storage_Unit then
5980 Atype := Calign_Storage_Unit;
5984 ("invalid Form parameter for pragma%", Form);
5987 -- Case with no name, supplied, affects scope table entry
5991 (Scope_Stack.Last).Component_Alignment_Default := Atype;
5993 -- Case of name supplied
5996 Check_Arg_Is_Local_Name (Name);
5998 Typ := Entity (Name);
6001 or else Rep_Item_Too_Early (Typ, N)
6005 Typ := Underlying_Type (Typ);
6008 if not Is_Record_Type (Typ)
6009 and then not Is_Array_Type (Typ)
6012 ("Name parameter of pragma% must identify record or " &
6013 "array type", Name);
6016 -- An explicit Component_Alignment pragma overrides an
6017 -- implicit pragma Pack, but not an explicit one.
6019 if not Has_Pragma_Pack (Base_Type (Typ)) then
6020 Set_Is_Packed (Base_Type (Typ), False);
6021 Set_Component_Alignment (Base_Type (Typ), Atype);
6024 end Component_AlignmentP;
6030 -- pragma Controlled (first_subtype_LOCAL_NAME);
6032 when Pragma_Controlled => Controlled : declare
6036 Check_No_Identifiers;
6037 Check_Arg_Count (1);
6038 Check_Arg_Is_Local_Name (Arg1);
6039 Arg := Expression (Arg1);
6041 if not Is_Entity_Name (Arg)
6042 or else not Is_Access_Type (Entity (Arg))
6044 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6046 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6054 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6055 -- [Entity =>] LOCAL_NAME);
6057 when Pragma_Convention => Convention : declare
6060 pragma Warnings (Off, C);
6061 pragma Warnings (Off, E);
6063 Check_Arg_Order ((Name_Convention, Name_Entity));
6064 Check_Ada_83_Warning;
6065 Check_Arg_Count (2);
6066 Process_Convention (C, E);
6069 ---------------------------
6070 -- Convention_Identifier --
6071 ---------------------------
6073 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6074 -- [Convention =>] convention_IDENTIFIER);
6076 when Pragma_Convention_Identifier => Convention_Identifier : declare
6082 Check_Arg_Order ((Name_Name, Name_Convention));
6083 Check_Arg_Count (2);
6084 Check_Optional_Identifier (Arg1, Name_Name);
6085 Check_Optional_Identifier (Arg2, Name_Convention);
6086 Check_Arg_Is_Identifier (Arg1);
6087 Check_Arg_Is_Identifier (Arg2);
6088 Idnam := Chars (Expression (Arg1));
6089 Cname := Chars (Expression (Arg2));
6091 if Is_Convention_Name (Cname) then
6092 Record_Convention_Identifier
6093 (Idnam, Get_Convention_Id (Cname));
6096 ("second arg for % pragma must be convention", Arg2);
6098 end Convention_Identifier;
6104 -- pragma CPP_Class ([Entity =>] local_NAME)
6106 when Pragma_CPP_Class => CPP_Class : declare
6111 if Warn_On_Obsolescent_Feature then
6113 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6114 " by pragma import?", N);
6118 Check_Arg_Count (1);
6119 Check_Optional_Identifier (Arg1, Name_Entity);
6120 Check_Arg_Is_Local_Name (Arg1);
6122 Arg := Expression (Arg1);
6125 if Etype (Arg) = Any_Type then
6129 if not Is_Entity_Name (Arg)
6130 or else not Is_Type (Entity (Arg))
6132 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6135 Typ := Entity (Arg);
6137 if not Is_Tagged_Type (Typ) then
6138 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6141 -- Types treated as CPP classes are treated as limited, but we
6142 -- don't require them to be declared this way. A warning is issued
6143 -- to encourage the user to declare them as limited. This is not
6144 -- an error, for compatibility reasons, because these types have
6145 -- been supported this way for some time.
6147 if not Is_Limited_Type (Typ) then
6149 ("imported 'C'P'P type should be " &
6150 "explicitly declared limited?",
6151 Get_Pragma_Arg (Arg1));
6153 ("\type will be considered limited",
6154 Get_Pragma_Arg (Arg1));
6157 Set_Is_CPP_Class (Typ);
6158 Set_Is_Limited_Record (Typ);
6159 Set_Convention (Typ, Convention_CPP);
6162 ---------------------
6163 -- CPP_Constructor --
6164 ---------------------
6166 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6167 -- [, [External_Name =>] static_string_EXPRESSION ]
6168 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6170 when Pragma_CPP_Constructor => CPP_Constructor : declare
6176 Check_At_Least_N_Arguments (1);
6177 Check_At_Most_N_Arguments (3);
6178 Check_Optional_Identifier (Arg1, Name_Entity);
6179 Check_Arg_Is_Local_Name (Arg1);
6181 Id := Expression (Arg1);
6182 Find_Program_Unit_Name (Id);
6184 -- If we did not find the name, we are done
6186 if Etype (Id) = Any_Type then
6190 Def_Id := Entity (Id);
6192 if Ekind (Def_Id) = E_Function
6193 and then Is_Class_Wide_Type (Etype (Def_Id))
6194 and then Is_CPP_Class (Etype (Etype (Def_Id)))
6196 if Arg_Count >= 2 then
6197 Set_Imported (Def_Id);
6198 Set_Is_Public (Def_Id);
6199 Process_Interface_Name (Def_Id, Arg2, Arg3);
6202 if No (Parameter_Specifications (Parent (Def_Id))) then
6203 Set_Has_Completion (Def_Id);
6204 Set_Is_Constructor (Def_Id);
6207 ("non-default constructors not implemented", Arg1);
6212 ("pragma% requires function returning a 'C'P'P_Class type",
6215 end CPP_Constructor;
6221 when Pragma_CPP_Virtual => CPP_Virtual : declare
6225 if Warn_On_Obsolescent_Feature then
6227 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6236 when Pragma_CPP_Vtable => CPP_Vtable : declare
6240 if Warn_On_Obsolescent_Feature then
6242 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6251 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6253 when Pragma_Debug => Debug : declare
6261 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6264 if Arg_Count = 2 then
6267 Left_Opnd => Relocate_Node (Cond),
6268 Right_Opnd => Expression (Arg1));
6271 -- Rewrite into a conditional with an appropriate condition. We
6272 -- wrap the procedure call in a block so that overhead from e.g.
6273 -- use of the secondary stack does not generate execution overhead
6274 -- for suppressed conditions.
6276 Rewrite (N, Make_Implicit_If_Statement (N,
6278 Then_Statements => New_List (
6279 Make_Block_Statement (Loc,
6280 Handled_Statement_Sequence =>
6281 Make_Handled_Sequence_Of_Statements (Loc,
6282 Statements => New_List (
6283 Relocate_Node (Debug_Statement (N))))))));
6291 -- pragma Debug_Policy (Check | Ignore)
6293 when Pragma_Debug_Policy =>
6295 Check_Arg_Count (1);
6296 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6297 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6299 ---------------------
6300 -- Detect_Blocking --
6301 ---------------------
6303 -- pragma Detect_Blocking;
6305 when Pragma_Detect_Blocking =>
6307 Check_Arg_Count (0);
6308 Check_Valid_Configuration_Pragma;
6309 Detect_Blocking := True;
6315 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6317 when Pragma_Discard_Names => Discard_Names : declare
6322 Check_Ada_83_Warning;
6324 -- Deal with configuration pragma case
6326 if Arg_Count = 0 and then Is_Configuration_Pragma then
6327 Global_Discard_Names := True;
6330 -- Otherwise, check correct appropriate context
6333 Check_Is_In_Decl_Part_Or_Package_Spec;
6335 if Arg_Count = 0 then
6337 -- If there is no parameter, then from now on this pragma
6338 -- applies to any enumeration, exception or tagged type
6339 -- defined in the current declarative part, and recursively
6340 -- to any nested scope.
6342 Set_Discard_Names (Current_Scope);
6346 Check_Arg_Count (1);
6347 Check_Optional_Identifier (Arg1, Name_On);
6348 Check_Arg_Is_Local_Name (Arg1);
6349 E_Id := Expression (Arg1);
6351 if Etype (E_Id) = Any_Type then
6357 if (Is_First_Subtype (E)
6358 and then (Is_Enumeration_Type (E)
6359 or else Is_Tagged_Type (E)))
6360 or else Ekind (E) = E_Exception
6362 Set_Discard_Names (E);
6365 ("inappropriate entity for pragma%", Arg1);
6375 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6377 when Pragma_Elaborate => Elaborate : declare
6382 -- Pragma must be in context items list of a compilation unit
6384 if not Is_In_Context_Clause then
6388 -- Must be at least one argument
6390 if Arg_Count = 0 then
6391 Error_Pragma ("pragma% requires at least one argument");
6394 -- In Ada 83 mode, there can be no items following it in the
6395 -- context list except other pragmas and implicit with clauses
6396 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6397 -- placement rule does not apply.
6399 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6401 while Present (Citem) loop
6402 if Nkind (Citem) = N_Pragma
6403 or else (Nkind (Citem) = N_With_Clause
6404 and then Implicit_With (Citem))
6409 ("(Ada 83) pragma% must be at end of context clause");
6416 -- Finally, the arguments must all be units mentioned in a with
6417 -- clause in the same context clause. Note we already checked (in
6418 -- Par.Prag) that the arguments are all identifiers or selected
6422 Outer : while Present (Arg) loop
6423 Citem := First (List_Containing (N));
6424 Inner : while Citem /= N loop
6425 if Nkind (Citem) = N_With_Clause
6426 and then Same_Name (Name (Citem), Expression (Arg))
6428 Set_Elaborate_Present (Citem, True);
6429 Set_Unit_Name (Expression (Arg), Name (Citem));
6431 -- With the pragma present, elaboration calls on
6432 -- subprograms from the named unit need no further
6433 -- checks, as long as the pragma appears in the current
6434 -- compilation unit. If the pragma appears in some unit
6435 -- in the context, there might still be a need for an
6436 -- Elaborate_All_Desirable from the current compilation
6437 -- to the named unit, so we keep the check enabled.
6439 if In_Extended_Main_Source_Unit (N) then
6440 Set_Suppress_Elaboration_Warnings
6441 (Entity (Name (Citem)));
6452 ("argument of pragma% is not with'ed unit", Arg);
6458 -- Give a warning if operating in static mode with -gnatwl
6459 -- (elaboration warnings enabled) switch set.
6461 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6463 ("?use of pragma Elaborate may not be safe", N);
6465 ("?use pragma Elaborate_All instead if possible", N);
6473 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6475 when Pragma_Elaborate_All => Elaborate_All : declare
6480 Check_Ada_83_Warning;
6482 -- Pragma must be in context items list of a compilation unit
6484 if not Is_In_Context_Clause then
6488 -- Must be at least one argument
6490 if Arg_Count = 0 then
6491 Error_Pragma ("pragma% requires at least one argument");
6494 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6495 -- have to appear at the end of the context clause, but may
6496 -- appear mixed in with other items, even in Ada 83 mode.
6498 -- Final check: the arguments must all be units mentioned in
6499 -- a with clause in the same context clause. Note that we
6500 -- already checked (in Par.Prag) that all the arguments are
6501 -- either identifiers or selected components.
6504 Outr : while Present (Arg) loop
6505 Citem := First (List_Containing (N));
6506 Innr : while Citem /= N loop
6507 if Nkind (Citem) = N_With_Clause
6508 and then Same_Name (Name (Citem), Expression (Arg))
6510 Set_Elaborate_All_Present (Citem, True);
6511 Set_Unit_Name (Expression (Arg), Name (Citem));
6513 -- Suppress warnings and elaboration checks on the named
6514 -- unit if the pragma is in the current compilation, as
6515 -- for pragma Elaborate.
6517 if In_Extended_Main_Source_Unit (N) then
6518 Set_Suppress_Elaboration_Warnings
6519 (Entity (Name (Citem)));
6528 Set_Error_Posted (N);
6530 ("argument of pragma% is not with'ed unit", Arg);
6537 --------------------
6538 -- Elaborate_Body --
6539 --------------------
6541 -- pragma Elaborate_Body [( library_unit_NAME )];
6543 when Pragma_Elaborate_Body => Elaborate_Body : declare
6544 Cunit_Node : Node_Id;
6545 Cunit_Ent : Entity_Id;
6548 Check_Ada_83_Warning;
6549 Check_Valid_Library_Unit_Pragma;
6551 if Nkind (N) = N_Null_Statement then
6555 Cunit_Node := Cunit (Current_Sem_Unit);
6556 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6558 if Nkind (Unit (Cunit_Node)) = N_Package_Body
6560 Nkind (Unit (Cunit_Node)) = N_Subprogram_Body
6562 Error_Pragma ("pragma% must refer to a spec, not a body");
6564 Set_Body_Required (Cunit_Node, True);
6565 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6567 -- If we are in dynamic elaboration mode, then we suppress
6568 -- elaboration warnings for the unit, since it is definitely
6569 -- fine NOT to do dynamic checks at the first level (and such
6570 -- checks will be suppressed because no elaboration boolean
6571 -- is created for Elaborate_Body packages).
6573 -- But in the static model of elaboration, Elaborate_Body is
6574 -- definitely NOT good enough to ensure elaboration safety on
6575 -- its own, since the body may WITH other units that are not
6576 -- safe from an elaboration point of view, so a client must
6577 -- still do an Elaborate_All on such units.
6579 -- Debug flag -gnatdD restores the old behavior of 3.13,
6580 -- where Elaborate_Body always suppressed elab warnings.
6582 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6583 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6588 ------------------------
6589 -- Elaboration_Checks --
6590 ------------------------
6592 -- pragma Elaboration_Checks (Static | Dynamic);
6594 when Pragma_Elaboration_Checks =>
6596 Check_Arg_Count (1);
6597 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6598 Dynamic_Elaboration_Checks :=
6599 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6605 -- pragma Eliminate (
6606 -- [Unit_Name =>] IDENTIFIER |
6607 -- SELECTED_COMPONENT
6608 -- [,[Entity =>] IDENTIFIER |
6609 -- SELECTED_COMPONENT |
6611 -- [,]OVERLOADING_RESOLUTION);
6613 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6616 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6619 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6621 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6622 -- Result_Type => result_SUBTYPE_NAME]
6624 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6625 -- SUBTYPE_NAME ::= STRING_LITERAL
6627 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6628 -- SOURCE_TRACE ::= STRING_LITERAL
6630 when Pragma_Eliminate => Eliminate : declare
6631 Args : Args_List (1 .. 5);
6632 Names : constant Name_List (1 .. 5) := (
6635 Name_Parameter_Types,
6637 Name_Source_Location);
6639 Unit_Name : Node_Id renames Args (1);
6640 Entity : Node_Id renames Args (2);
6641 Parameter_Types : Node_Id renames Args (3);
6642 Result_Type : Node_Id renames Args (4);
6643 Source_Location : Node_Id renames Args (5);
6647 Check_Valid_Configuration_Pragma;
6648 Gather_Associations (Names, Args);
6650 if No (Unit_Name) then
6651 Error_Pragma ("missing Unit_Name argument for pragma%");
6655 and then (Present (Parameter_Types)
6657 Present (Result_Type)
6659 Present (Source_Location))
6661 Error_Pragma ("missing Entity argument for pragma%");
6664 if (Present (Parameter_Types)
6666 Present (Result_Type))
6668 Present (Source_Location)
6671 ("parameter profile and source location cannot " &
6672 "be used together in pragma%");
6675 Process_Eliminate_Pragma
6689 -- [ Convention =>] convention_IDENTIFIER,
6690 -- [ Entity =>] local_NAME
6691 -- [, [External_Name =>] static_string_EXPRESSION ]
6692 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6694 when Pragma_Export => Export : declare
6698 pragma Warnings (Off, C);
6701 Check_Ada_83_Warning;
6707 Check_At_Least_N_Arguments (2);
6708 Check_At_Most_N_Arguments (4);
6709 Process_Convention (C, Def_Id);
6711 if Ekind (Def_Id) /= E_Constant then
6712 Note_Possible_Modification (Expression (Arg2), Sure => False);
6715 Process_Interface_Name (Def_Id, Arg3, Arg4);
6716 Set_Exported (Def_Id, Arg2);
6718 -- If the entity is a deferred constant, propagate the
6719 -- information to the full view, because gigi elaborates
6720 -- the full view only.
6722 if Ekind (Def_Id) = E_Constant
6723 and then Present (Full_View (Def_Id))
6726 Id2 : constant Entity_Id := Full_View (Def_Id);
6728 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6729 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6730 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6735 ----------------------
6736 -- Export_Exception --
6737 ----------------------
6739 -- pragma Export_Exception (
6740 -- [Internal =>] LOCAL_NAME
6741 -- [, [External =>] EXTERNAL_SYMBOL]
6742 -- [, [Form =>] Ada | VMS]
6743 -- [, [Code =>] static_integer_EXPRESSION]);
6745 when Pragma_Export_Exception => Export_Exception : declare
6746 Args : Args_List (1 .. 4);
6747 Names : constant Name_List (1 .. 4) := (
6753 Internal : Node_Id renames Args (1);
6754 External : Node_Id renames Args (2);
6755 Form : Node_Id renames Args (3);
6756 Code : Node_Id renames Args (4);
6761 if Inside_A_Generic then
6762 Error_Pragma ("pragma% cannot be used for generic entities");
6765 Gather_Associations (Names, Args);
6766 Process_Extended_Import_Export_Exception_Pragma (
6767 Arg_Internal => Internal,
6768 Arg_External => External,
6772 if not Is_VMS_Exception (Entity (Internal)) then
6773 Set_Exported (Entity (Internal), Internal);
6775 end Export_Exception;
6777 ---------------------
6778 -- Export_Function --
6779 ---------------------
6781 -- pragma Export_Function (
6782 -- [Internal =>] LOCAL_NAME
6783 -- [, [External =>] EXTERNAL_SYMBOL]
6784 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6785 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6786 -- [, [Mechanism =>] MECHANISM]
6787 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6789 -- EXTERNAL_SYMBOL ::=
6791 -- | static_string_EXPRESSION
6793 -- PARAMETER_TYPES ::=
6795 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6797 -- TYPE_DESIGNATOR ::=
6799 -- | subtype_Name ' Access
6803 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6805 -- MECHANISM_ASSOCIATION ::=
6806 -- [formal_parameter_NAME =>] MECHANISM_NAME
6808 -- MECHANISM_NAME ::=
6811 -- | Descriptor [([Class =>] CLASS_NAME)]
6813 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6815 when Pragma_Export_Function => Export_Function : declare
6816 Args : Args_List (1 .. 6);
6817 Names : constant Name_List (1 .. 6) := (
6820 Name_Parameter_Types,
6823 Name_Result_Mechanism);
6825 Internal : Node_Id renames Args (1);
6826 External : Node_Id renames Args (2);
6827 Parameter_Types : Node_Id renames Args (3);
6828 Result_Type : Node_Id renames Args (4);
6829 Mechanism : Node_Id renames Args (5);
6830 Result_Mechanism : Node_Id renames Args (6);
6834 Gather_Associations (Names, Args);
6835 Process_Extended_Import_Export_Subprogram_Pragma (
6836 Arg_Internal => Internal,
6837 Arg_External => External,
6838 Arg_Parameter_Types => Parameter_Types,
6839 Arg_Result_Type => Result_Type,
6840 Arg_Mechanism => Mechanism,
6841 Arg_Result_Mechanism => Result_Mechanism);
6842 end Export_Function;
6848 -- pragma Export_Object (
6849 -- [Internal =>] LOCAL_NAME
6850 -- [, [External =>] EXTERNAL_SYMBOL]
6851 -- [, [Size =>] EXTERNAL_SYMBOL]);
6853 -- EXTERNAL_SYMBOL ::=
6855 -- | static_string_EXPRESSION
6857 -- PARAMETER_TYPES ::=
6859 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6861 -- TYPE_DESIGNATOR ::=
6863 -- | subtype_Name ' Access
6867 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6869 -- MECHANISM_ASSOCIATION ::=
6870 -- [formal_parameter_NAME =>] MECHANISM_NAME
6872 -- MECHANISM_NAME ::=
6875 -- | Descriptor [([Class =>] CLASS_NAME)]
6877 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6879 when Pragma_Export_Object => Export_Object : declare
6880 Args : Args_List (1 .. 3);
6881 Names : constant Name_List (1 .. 3) := (
6886 Internal : Node_Id renames Args (1);
6887 External : Node_Id renames Args (2);
6888 Size : Node_Id renames Args (3);
6892 Gather_Associations (Names, Args);
6893 Process_Extended_Import_Export_Object_Pragma (
6894 Arg_Internal => Internal,
6895 Arg_External => External,
6899 ----------------------
6900 -- Export_Procedure --
6901 ----------------------
6903 -- pragma Export_Procedure (
6904 -- [Internal =>] LOCAL_NAME
6905 -- [, [External =>] EXTERNAL_SYMBOL]
6906 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6907 -- [, [Mechanism =>] MECHANISM]);
6909 -- EXTERNAL_SYMBOL ::=
6911 -- | static_string_EXPRESSION
6913 -- PARAMETER_TYPES ::=
6915 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6917 -- TYPE_DESIGNATOR ::=
6919 -- | subtype_Name ' Access
6923 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6925 -- MECHANISM_ASSOCIATION ::=
6926 -- [formal_parameter_NAME =>] MECHANISM_NAME
6928 -- MECHANISM_NAME ::=
6931 -- | Descriptor [([Class =>] CLASS_NAME)]
6933 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6935 when Pragma_Export_Procedure => Export_Procedure : declare
6936 Args : Args_List (1 .. 4);
6937 Names : constant Name_List (1 .. 4) := (
6940 Name_Parameter_Types,
6943 Internal : Node_Id renames Args (1);
6944 External : Node_Id renames Args (2);
6945 Parameter_Types : Node_Id renames Args (3);
6946 Mechanism : Node_Id renames Args (4);
6950 Gather_Associations (Names, Args);
6951 Process_Extended_Import_Export_Subprogram_Pragma (
6952 Arg_Internal => Internal,
6953 Arg_External => External,
6954 Arg_Parameter_Types => Parameter_Types,
6955 Arg_Mechanism => Mechanism);
6956 end Export_Procedure;
6962 -- pragma Export_Value (
6963 -- [Value =>] static_integer_EXPRESSION,
6964 -- [Link_Name =>] static_string_EXPRESSION);
6966 when Pragma_Export_Value =>
6968 Check_Arg_Order ((Name_Value, Name_Link_Name));
6969 Check_Arg_Count (2);
6971 Check_Optional_Identifier (Arg1, Name_Value);
6972 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6974 Check_Optional_Identifier (Arg2, Name_Link_Name);
6975 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6977 -----------------------------
6978 -- Export_Valued_Procedure --
6979 -----------------------------
6981 -- pragma Export_Valued_Procedure (
6982 -- [Internal =>] LOCAL_NAME
6983 -- [, [External =>] EXTERNAL_SYMBOL,]
6984 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6985 -- [, [Mechanism =>] MECHANISM]);
6987 -- EXTERNAL_SYMBOL ::=
6989 -- | static_string_EXPRESSION
6991 -- PARAMETER_TYPES ::=
6993 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6995 -- TYPE_DESIGNATOR ::=
6997 -- | subtype_Name ' Access
7001 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7003 -- MECHANISM_ASSOCIATION ::=
7004 -- [formal_parameter_NAME =>] MECHANISM_NAME
7006 -- MECHANISM_NAME ::=
7009 -- | Descriptor [([Class =>] CLASS_NAME)]
7011 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7013 when Pragma_Export_Valued_Procedure =>
7014 Export_Valued_Procedure : declare
7015 Args : Args_List (1 .. 4);
7016 Names : constant Name_List (1 .. 4) := (
7019 Name_Parameter_Types,
7022 Internal : Node_Id renames Args (1);
7023 External : Node_Id renames Args (2);
7024 Parameter_Types : Node_Id renames Args (3);
7025 Mechanism : Node_Id renames Args (4);
7029 Gather_Associations (Names, Args);
7030 Process_Extended_Import_Export_Subprogram_Pragma (
7031 Arg_Internal => Internal,
7032 Arg_External => External,
7033 Arg_Parameter_Types => Parameter_Types,
7034 Arg_Mechanism => Mechanism);
7035 end Export_Valued_Procedure;
7041 -- pragma Extend_System ([Name =>] Identifier);
7043 when Pragma_Extend_System => Extend_System : declare
7046 Check_Valid_Configuration_Pragma;
7047 Check_Arg_Count (1);
7048 Check_Optional_Identifier (Arg1, Name_Name);
7049 Check_Arg_Is_Identifier (Arg1);
7051 Get_Name_String (Chars (Expression (Arg1)));
7054 and then Name_Buffer (1 .. 4) = "aux_"
7056 if Present (System_Extend_Pragma_Arg) then
7057 if Chars (Expression (Arg1)) =
7058 Chars (Expression (System_Extend_Pragma_Arg))
7062 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7063 Error_Pragma ("pragma% conflicts with that #");
7067 System_Extend_Pragma_Arg := Arg1;
7069 if not GNAT_Mode then
7070 System_Extend_Unit := Arg1;
7074 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7078 ------------------------
7079 -- Extensions_Allowed --
7080 ------------------------
7082 -- pragma Extensions_Allowed (ON | OFF);
7084 when Pragma_Extensions_Allowed =>
7086 Check_Arg_Count (1);
7087 Check_No_Identifiers;
7088 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7090 if Chars (Expression (Arg1)) = Name_On then
7091 Extensions_Allowed := True;
7093 Extensions_Allowed := False;
7100 -- pragma External (
7101 -- [ Convention =>] convention_IDENTIFIER,
7102 -- [ Entity =>] local_NAME
7103 -- [, [External_Name =>] static_string_EXPRESSION ]
7104 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7106 when Pragma_External => External : declare
7110 pragma Warnings (Off, C);
7119 Check_At_Least_N_Arguments (2);
7120 Check_At_Most_N_Arguments (4);
7121 Process_Convention (C, Def_Id);
7122 Note_Possible_Modification (Expression (Arg2), Sure => False);
7123 Process_Interface_Name (Def_Id, Arg3, Arg4);
7124 Set_Exported (Def_Id, Arg2);
7127 --------------------------
7128 -- External_Name_Casing --
7129 --------------------------
7131 -- pragma External_Name_Casing (
7132 -- UPPERCASE | LOWERCASE
7133 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7135 when Pragma_External_Name_Casing => External_Name_Casing : declare
7138 Check_No_Identifiers;
7140 if Arg_Count = 2 then
7142 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7144 case Chars (Get_Pragma_Arg (Arg2)) is
7146 Opt.External_Name_Exp_Casing := As_Is;
7148 when Name_Uppercase =>
7149 Opt.External_Name_Exp_Casing := Uppercase;
7151 when Name_Lowercase =>
7152 Opt.External_Name_Exp_Casing := Lowercase;
7159 Check_Arg_Count (1);
7162 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7164 case Chars (Get_Pragma_Arg (Arg1)) is
7165 when Name_Uppercase =>
7166 Opt.External_Name_Imp_Casing := Uppercase;
7168 when Name_Lowercase =>
7169 Opt.External_Name_Imp_Casing := Lowercase;
7174 end External_Name_Casing;
7176 --------------------------
7177 -- Favor_Top_Level --
7178 --------------------------
7180 -- pragma Favor_Top_Level (type_NAME);
7182 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7183 Named_Entity : Entity_Id;
7187 Check_No_Identifiers;
7188 Check_Arg_Count (1);
7189 Check_Arg_Is_Local_Name (Arg1);
7190 Named_Entity := Entity (Expression (Arg1));
7192 -- If it's an access-to-subprogram type (in particular, not a
7193 -- subtype), set the flag on that type.
7195 if Is_Access_Subprogram_Type (Named_Entity) then
7196 Set_Can_Use_Internal_Rep (Named_Entity, False);
7198 -- Otherwise it's an error (name denotes the wrong sort of entity)
7202 ("access-to-subprogram type expected", Expression (Arg1));
7204 end Favor_Top_Level;
7210 -- pragma Fast_Math;
7212 when Pragma_Fast_Math =>
7214 Check_No_Identifiers;
7215 Check_Valid_Configuration_Pragma;
7218 ---------------------------
7219 -- Finalize_Storage_Only --
7220 ---------------------------
7222 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7224 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7225 Assoc : constant Node_Id := Arg1;
7226 Type_Id : constant Node_Id := Expression (Assoc);
7231 Check_No_Identifiers;
7232 Check_Arg_Count (1);
7233 Check_Arg_Is_Local_Name (Arg1);
7235 Find_Type (Type_Id);
7236 Typ := Entity (Type_Id);
7239 or else Rep_Item_Too_Early (Typ, N)
7243 Typ := Underlying_Type (Typ);
7246 if not Is_Controlled (Typ) then
7247 Error_Pragma ("pragma% must specify controlled type");
7250 Check_First_Subtype (Arg1);
7252 if Finalize_Storage_Only (Typ) then
7253 Error_Pragma ("duplicate pragma%, only one allowed");
7255 elsif not Rep_Item_Too_Late (Typ, N) then
7256 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7258 end Finalize_Storage;
7260 --------------------------
7261 -- Float_Representation --
7262 --------------------------
7264 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7266 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7268 when Pragma_Float_Representation => Float_Representation : declare
7276 if Arg_Count = 1 then
7277 Check_Valid_Configuration_Pragma;
7279 Check_Arg_Count (2);
7280 Check_Optional_Identifier (Arg2, Name_Entity);
7281 Check_Arg_Is_Local_Name (Arg2);
7284 Check_No_Identifier (Arg1);
7285 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7287 if not OpenVMS_On_Target then
7288 if Chars (Expression (Arg1)) = Name_VAX_Float then
7290 ("?pragma% ignored (applies only to Open'V'M'S)");
7296 -- One argument case
7298 if Arg_Count = 1 then
7299 if Chars (Expression (Arg1)) = Name_VAX_Float then
7300 if Opt.Float_Format = 'I' then
7301 Error_Pragma ("'I'E'E'E format previously specified");
7304 Opt.Float_Format := 'V';
7307 if Opt.Float_Format = 'V' then
7308 Error_Pragma ("'V'A'X format previously specified");
7311 Opt.Float_Format := 'I';
7314 Set_Standard_Fpt_Formats;
7316 -- Two argument case
7319 Argx := Get_Pragma_Arg (Arg2);
7321 if not Is_Entity_Name (Argx)
7322 or else not Is_Floating_Point_Type (Entity (Argx))
7325 ("second argument of% pragma must be floating-point type",
7329 Ent := Entity (Argx);
7330 Digs := UI_To_Int (Digits_Value (Ent));
7332 -- Two arguments, VAX_Float case
7334 if Chars (Expression (Arg1)) = Name_VAX_Float then
7336 when 6 => Set_F_Float (Ent);
7337 when 9 => Set_D_Float (Ent);
7338 when 15 => Set_G_Float (Ent);
7342 ("wrong digits value, must be 6,9 or 15", Arg2);
7345 -- Two arguments, IEEE_Float case
7349 when 6 => Set_IEEE_Short (Ent);
7350 when 15 => Set_IEEE_Long (Ent);
7354 ("wrong digits value, must be 6 or 15", Arg2);
7358 end Float_Representation;
7364 -- pragma Ident (static_string_EXPRESSION)
7366 -- Note: pragma Comment shares this processing. Pragma Comment
7367 -- is identical to Ident, except that the restriction of the
7368 -- argument to 31 characters and the placement restrictions
7369 -- are not enforced for pragma Comment.
7371 when Pragma_Ident | Pragma_Comment => Ident : declare
7376 Check_Arg_Count (1);
7377 Check_No_Identifiers;
7378 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7380 -- For pragma Ident, preserve DEC compatibility by requiring
7381 -- the pragma to appear in a declarative part or package spec.
7383 if Prag_Id = Pragma_Ident then
7384 Check_Is_In_Decl_Part_Or_Package_Spec;
7387 Str := Expr_Value_S (Expression (Arg1));
7394 GP := Parent (Parent (N));
7396 if Nkind (GP) = N_Package_Declaration
7398 Nkind (GP) = N_Generic_Package_Declaration
7403 -- If we have a compilation unit, then record the ident
7404 -- value, checking for improper duplication.
7406 if Nkind (GP) = N_Compilation_Unit then
7407 CS := Ident_String (Current_Sem_Unit);
7409 if Present (CS) then
7411 -- For Ident, we do not permit multiple instances
7413 if Prag_Id = Pragma_Ident then
7414 Error_Pragma ("duplicate% pragma not permitted");
7416 -- For Comment, we concatenate the string, unless we
7417 -- want to preserve the tree structure for ASIS.
7419 elsif not ASIS_Mode then
7420 Start_String (Strval (CS));
7421 Store_String_Char (' ');
7422 Store_String_Chars (Strval (Str));
7423 Set_Strval (CS, End_String);
7427 -- In VMS, the effect of IDENT is achieved by passing
7428 -- IDENTIFICATION=name as a --for-linker switch.
7430 if OpenVMS_On_Target then
7433 ("--for-linker=IDENTIFICATION=");
7434 String_To_Name_Buffer (Strval (Str));
7435 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7437 -- Only the last processed IDENT is saved. The main
7438 -- purpose is so an IDENT associated with a main
7439 -- procedure will be used in preference to an IDENT
7440 -- associated with a with'd package.
7442 Replace_Linker_Option_String
7443 (End_String, "--for-linker=IDENTIFICATION=");
7446 Set_Ident_String (Current_Sem_Unit, Str);
7449 -- For subunits, we just ignore the Ident, since in GNAT
7450 -- these are not separate object files, and hence not
7451 -- separate units in the unit table.
7453 elsif Nkind (GP) = N_Subunit then
7456 -- Otherwise we have a misplaced pragma Ident, but we ignore
7457 -- this if we are in an instantiation, since it comes from
7458 -- a generic, and has no relevance to the instantiation.
7460 elsif Prag_Id = Pragma_Ident then
7461 if Instantiation_Location (Loc) = No_Location then
7462 Error_Pragma ("pragma% only allowed at outer level");
7468 --------------------------
7469 -- Implemented_By_Entry --
7470 --------------------------
7472 -- pragma Implemented_By_Entry (DIRECT_NAME);
7474 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7479 Check_Arg_Count (1);
7480 Check_No_Identifiers;
7481 Check_Arg_Is_Identifier (Arg1);
7482 Check_Arg_Is_Local_Name (Arg1);
7483 Ent := Entity (Expression (Arg1));
7485 -- Pragma Implemented_By_Entry must be applied only to protected
7486 -- synchronized or task interface primitives.
7488 if (Ekind (Ent) /= E_Function
7489 and then Ekind (Ent) /= E_Procedure)
7490 or else not Present (First_Formal (Ent))
7491 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7494 ("pragma % must be applied to a concurrent interface " &
7498 if Einfo.Implemented_By_Entry (Ent)
7499 and then Warn_On_Redundant_Constructs
7501 Error_Pragma ("?duplicate pragma%!");
7503 Set_Implemented_By_Entry (Ent);
7506 end Implemented_By_Entry;
7508 -----------------------
7509 -- Implicit_Packing --
7510 -----------------------
7512 -- pragma Implicit_Packing;
7514 when Pragma_Implicit_Packing =>
7516 Check_Arg_Count (0);
7517 Implicit_Packing := True;
7524 -- [Convention =>] convention_IDENTIFIER,
7525 -- [Entity =>] local_NAME
7526 -- [, [External_Name =>] static_string_EXPRESSION ]
7527 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7529 when Pragma_Import =>
7530 Check_Ada_83_Warning;
7536 Check_At_Least_N_Arguments (2);
7537 Check_At_Most_N_Arguments (4);
7538 Process_Import_Or_Interface;
7540 ----------------------
7541 -- Import_Exception --
7542 ----------------------
7544 -- pragma Import_Exception (
7545 -- [Internal =>] LOCAL_NAME
7546 -- [, [External =>] EXTERNAL_SYMBOL]
7547 -- [, [Form =>] Ada | VMS]
7548 -- [, [Code =>] static_integer_EXPRESSION]);
7550 when Pragma_Import_Exception => Import_Exception : declare
7551 Args : Args_List (1 .. 4);
7552 Names : constant Name_List (1 .. 4) := (
7558 Internal : Node_Id renames Args (1);
7559 External : Node_Id renames Args (2);
7560 Form : Node_Id renames Args (3);
7561 Code : Node_Id renames Args (4);
7565 Gather_Associations (Names, Args);
7567 if Present (External) and then Present (Code) then
7569 ("cannot give both External and Code options for pragma%");
7572 Process_Extended_Import_Export_Exception_Pragma (
7573 Arg_Internal => Internal,
7574 Arg_External => External,
7578 if not Is_VMS_Exception (Entity (Internal)) then
7579 Set_Imported (Entity (Internal));
7581 end Import_Exception;
7583 ---------------------
7584 -- Import_Function --
7585 ---------------------
7587 -- pragma Import_Function (
7588 -- [Internal =>] LOCAL_NAME,
7589 -- [, [External =>] EXTERNAL_SYMBOL]
7590 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7591 -- [, [Result_Type =>] SUBTYPE_MARK]
7592 -- [, [Mechanism =>] MECHANISM]
7593 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7594 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7596 -- EXTERNAL_SYMBOL ::=
7598 -- | static_string_EXPRESSION
7600 -- PARAMETER_TYPES ::=
7602 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7604 -- TYPE_DESIGNATOR ::=
7606 -- | subtype_Name ' Access
7610 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7612 -- MECHANISM_ASSOCIATION ::=
7613 -- [formal_parameter_NAME =>] MECHANISM_NAME
7615 -- MECHANISM_NAME ::=
7618 -- | Descriptor [([Class =>] CLASS_NAME)]
7620 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7622 when Pragma_Import_Function => Import_Function : declare
7623 Args : Args_List (1 .. 7);
7624 Names : constant Name_List (1 .. 7) := (
7627 Name_Parameter_Types,
7630 Name_Result_Mechanism,
7631 Name_First_Optional_Parameter);
7633 Internal : Node_Id renames Args (1);
7634 External : Node_Id renames Args (2);
7635 Parameter_Types : Node_Id renames Args (3);
7636 Result_Type : Node_Id renames Args (4);
7637 Mechanism : Node_Id renames Args (5);
7638 Result_Mechanism : Node_Id renames Args (6);
7639 First_Optional_Parameter : Node_Id renames Args (7);
7643 Gather_Associations (Names, Args);
7644 Process_Extended_Import_Export_Subprogram_Pragma (
7645 Arg_Internal => Internal,
7646 Arg_External => External,
7647 Arg_Parameter_Types => Parameter_Types,
7648 Arg_Result_Type => Result_Type,
7649 Arg_Mechanism => Mechanism,
7650 Arg_Result_Mechanism => Result_Mechanism,
7651 Arg_First_Optional_Parameter => First_Optional_Parameter);
7652 end Import_Function;
7658 -- pragma Import_Object (
7659 -- [Internal =>] LOCAL_NAME
7660 -- [, [External =>] EXTERNAL_SYMBOL]
7661 -- [, [Size =>] EXTERNAL_SYMBOL]);
7663 -- EXTERNAL_SYMBOL ::=
7665 -- | static_string_EXPRESSION
7667 when Pragma_Import_Object => Import_Object : declare
7668 Args : Args_List (1 .. 3);
7669 Names : constant Name_List (1 .. 3) := (
7674 Internal : Node_Id renames Args (1);
7675 External : Node_Id renames Args (2);
7676 Size : Node_Id renames Args (3);
7680 Gather_Associations (Names, Args);
7681 Process_Extended_Import_Export_Object_Pragma (
7682 Arg_Internal => Internal,
7683 Arg_External => External,
7687 ----------------------
7688 -- Import_Procedure --
7689 ----------------------
7691 -- pragma Import_Procedure (
7692 -- [Internal =>] LOCAL_NAME
7693 -- [, [External =>] EXTERNAL_SYMBOL]
7694 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7695 -- [, [Mechanism =>] MECHANISM]
7696 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7698 -- EXTERNAL_SYMBOL ::=
7700 -- | static_string_EXPRESSION
7702 -- PARAMETER_TYPES ::=
7704 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7706 -- TYPE_DESIGNATOR ::=
7708 -- | subtype_Name ' Access
7712 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7714 -- MECHANISM_ASSOCIATION ::=
7715 -- [formal_parameter_NAME =>] MECHANISM_NAME
7717 -- MECHANISM_NAME ::=
7720 -- | Descriptor [([Class =>] CLASS_NAME)]
7722 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7724 when Pragma_Import_Procedure => Import_Procedure : declare
7725 Args : Args_List (1 .. 5);
7726 Names : constant Name_List (1 .. 5) := (
7729 Name_Parameter_Types,
7731 Name_First_Optional_Parameter);
7733 Internal : Node_Id renames Args (1);
7734 External : Node_Id renames Args (2);
7735 Parameter_Types : Node_Id renames Args (3);
7736 Mechanism : Node_Id renames Args (4);
7737 First_Optional_Parameter : Node_Id renames Args (5);
7741 Gather_Associations (Names, Args);
7742 Process_Extended_Import_Export_Subprogram_Pragma (
7743 Arg_Internal => Internal,
7744 Arg_External => External,
7745 Arg_Parameter_Types => Parameter_Types,
7746 Arg_Mechanism => Mechanism,
7747 Arg_First_Optional_Parameter => First_Optional_Parameter);
7748 end Import_Procedure;
7750 -----------------------------
7751 -- Import_Valued_Procedure --
7752 -----------------------------
7754 -- pragma Import_Valued_Procedure (
7755 -- [Internal =>] LOCAL_NAME
7756 -- [, [External =>] EXTERNAL_SYMBOL]
7757 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7758 -- [, [Mechanism =>] MECHANISM]
7759 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7761 -- EXTERNAL_SYMBOL ::=
7763 -- | static_string_EXPRESSION
7765 -- PARAMETER_TYPES ::=
7767 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7769 -- TYPE_DESIGNATOR ::=
7771 -- | subtype_Name ' Access
7775 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7777 -- MECHANISM_ASSOCIATION ::=
7778 -- [formal_parameter_NAME =>] MECHANISM_NAME
7780 -- MECHANISM_NAME ::=
7783 -- | Descriptor [([Class =>] CLASS_NAME)]
7785 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7787 when Pragma_Import_Valued_Procedure =>
7788 Import_Valued_Procedure : declare
7789 Args : Args_List (1 .. 5);
7790 Names : constant Name_List (1 .. 5) := (
7793 Name_Parameter_Types,
7795 Name_First_Optional_Parameter);
7797 Internal : Node_Id renames Args (1);
7798 External : Node_Id renames Args (2);
7799 Parameter_Types : Node_Id renames Args (3);
7800 Mechanism : Node_Id renames Args (4);
7801 First_Optional_Parameter : Node_Id renames Args (5);
7805 Gather_Associations (Names, Args);
7806 Process_Extended_Import_Export_Subprogram_Pragma (
7807 Arg_Internal => Internal,
7808 Arg_External => External,
7809 Arg_Parameter_Types => Parameter_Types,
7810 Arg_Mechanism => Mechanism,
7811 Arg_First_Optional_Parameter => First_Optional_Parameter);
7812 end Import_Valued_Procedure;
7814 ------------------------
7815 -- Initialize_Scalars --
7816 ------------------------
7818 -- pragma Initialize_Scalars;
7820 when Pragma_Initialize_Scalars =>
7822 Check_Arg_Count (0);
7823 Check_Valid_Configuration_Pragma;
7824 Check_Restriction (No_Initialize_Scalars, N);
7826 if not Restriction_Active (No_Initialize_Scalars) then
7827 Init_Or_Norm_Scalars := True;
7828 Initialize_Scalars := True;
7835 -- pragma Inline ( NAME {, NAME} );
7837 when Pragma_Inline =>
7839 -- Pragma is active if inlining option is active
7841 Process_Inline (Inline_Active);
7847 -- pragma Inline_Always ( NAME {, NAME} );
7849 when Pragma_Inline_Always =>
7851 Process_Inline (True);
7853 --------------------
7854 -- Inline_Generic --
7855 --------------------
7857 -- pragma Inline_Generic (NAME {, NAME});
7859 when Pragma_Inline_Generic =>
7861 Process_Generic_List;
7863 ----------------------
7864 -- Inspection_Point --
7865 ----------------------
7867 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7869 when Pragma_Inspection_Point => Inspection_Point : declare
7874 if Arg_Count > 0 then
7877 Exp := Expression (Arg);
7880 if not Is_Entity_Name (Exp)
7881 or else not Is_Object (Entity (Exp))
7883 Error_Pragma_Arg ("object name required", Arg);
7890 end Inspection_Point;
7896 -- pragma Interface (
7897 -- [ Convention =>] convention_IDENTIFIER,
7898 -- [ Entity =>] local_NAME
7899 -- [, [External_Name =>] static_string_EXPRESSION ]
7900 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7902 when Pragma_Interface =>
7909 Check_At_Least_N_Arguments (2);
7910 Check_At_Most_N_Arguments (4);
7911 Process_Import_Or_Interface;
7913 --------------------
7914 -- Interface_Name --
7915 --------------------
7917 -- pragma Interface_Name (
7918 -- [ Entity =>] local_NAME
7919 -- [,[External_Name =>] static_string_EXPRESSION ]
7920 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7922 when Pragma_Interface_Name => Interface_Name : declare
7931 ((Name_Entity, Name_External_Name, Name_Link_Name));
7932 Check_At_Least_N_Arguments (2);
7933 Check_At_Most_N_Arguments (3);
7934 Id := Expression (Arg1);
7937 if not Is_Entity_Name (Id) then
7939 ("first argument for pragma% must be entity name", Arg1);
7940 elsif Etype (Id) = Any_Type then
7943 Def_Id := Entity (Id);
7946 -- Special DEC-compatible processing for the object case, forces
7947 -- object to be imported.
7949 if Ekind (Def_Id) = E_Variable then
7950 Kill_Size_Check_Code (Def_Id);
7951 Note_Possible_Modification (Id, Sure => False);
7953 -- Initialization is not allowed for imported variable
7955 if Present (Expression (Parent (Def_Id)))
7956 and then Comes_From_Source (Expression (Parent (Def_Id)))
7958 Error_Msg_Sloc := Sloc (Def_Id);
7960 ("no initialization allowed for declaration of& #",
7964 -- For compatibility, support VADS usage of providing both
7965 -- pragmas Interface and Interface_Name to obtain the effect
7966 -- of a single Import pragma.
7968 if Is_Imported (Def_Id)
7969 and then Present (First_Rep_Item (Def_Id))
7970 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7972 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
7976 Set_Imported (Def_Id);
7979 Set_Is_Public (Def_Id);
7980 Process_Interface_Name (Def_Id, Arg2, Arg3);
7983 -- Otherwise must be subprogram
7985 elsif not Is_Subprogram (Def_Id) then
7987 ("argument of pragma% is not subprogram", Arg1);
7990 Check_At_Most_N_Arguments (3);
7994 -- Loop through homonyms
7997 Def_Id := Get_Base_Subprogram (Hom_Id);
7999 if Is_Imported (Def_Id) then
8000 Process_Interface_Name (Def_Id, Arg2, Arg3);
8004 Hom_Id := Homonym (Hom_Id);
8006 exit when No (Hom_Id)
8007 or else Scope (Hom_Id) /= Current_Scope;
8012 ("argument of pragma% is not imported subprogram",
8018 -----------------------
8019 -- Interrupt_Handler --
8020 -----------------------
8022 -- pragma Interrupt_Handler (handler_NAME);
8024 when Pragma_Interrupt_Handler =>
8025 Check_Ada_83_Warning;
8026 Check_Arg_Count (1);
8027 Check_No_Identifiers;
8029 if No_Run_Time_Mode then
8030 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8032 Check_Interrupt_Or_Attach_Handler;
8033 Process_Interrupt_Or_Attach_Handler;
8036 ------------------------
8037 -- Interrupt_Priority --
8038 ------------------------
8040 -- pragma Interrupt_Priority [(EXPRESSION)];
8042 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8043 P : constant Node_Id := Parent (N);
8047 Check_Ada_83_Warning;
8049 if Arg_Count /= 0 then
8050 Arg := Expression (Arg1);
8051 Check_Arg_Count (1);
8052 Check_No_Identifiers;
8054 -- The expression must be analyzed in the special manner
8055 -- described in "Handling of Default and Per-Object
8056 -- Expressions" in sem.ads.
8058 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8061 if Nkind (P) /= N_Task_Definition
8062 and then Nkind (P) /= N_Protected_Definition
8067 elsif Has_Priority_Pragma (P) then
8068 Error_Pragma ("duplicate pragma% not allowed");
8071 Set_Has_Priority_Pragma (P, True);
8072 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8074 end Interrupt_Priority;
8076 ---------------------
8077 -- Interrupt_State --
8078 ---------------------
8080 -- pragma Interrupt_State (
8081 -- [Name =>] INTERRUPT_ID,
8082 -- [State =>] INTERRUPT_STATE);
8084 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8085 -- INTERRUPT_STATE => System | Runtime | User
8087 -- Note: if the interrupt id is given as an identifier, then
8088 -- it must be one of the identifiers in Ada.Interrupts.Names.
8089 -- Otherwise it is given as a static integer expression which
8090 -- must be in the range of Ada.Interrupts.Interrupt_ID.
8092 when Pragma_Interrupt_State => Interrupt_State : declare
8094 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8095 -- This is the entity Ada.Interrupts.Interrupt_ID;
8097 State_Type : Character;
8098 -- Set to 's'/'r'/'u' for System/Runtime/User
8101 -- Index to entry in Interrupt_States table
8104 -- Value of interrupt
8106 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8107 -- The first argument to the pragma
8109 Int_Ent : Entity_Id;
8110 -- Interrupt entity in Ada.Interrupts.Names
8114 Check_Arg_Order ((Name_Name, Name_State));
8115 Check_Arg_Count (2);
8117 Check_Optional_Identifier (Arg1, Name_Name);
8118 Check_Optional_Identifier (Arg2, Name_State);
8119 Check_Arg_Is_Identifier (Arg2);
8121 -- First argument is identifier
8123 if Nkind (Arg1X) = N_Identifier then
8125 -- Search list of names in Ada.Interrupts.Names
8127 Int_Ent := First_Entity (RTE (RE_Names));
8129 if No (Int_Ent) then
8130 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8132 elsif Chars (Int_Ent) = Chars (Arg1X) then
8133 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8137 Next_Entity (Int_Ent);
8140 -- First argument is not an identifier, so it must be a
8141 -- static expression of type Ada.Interrupts.Interrupt_ID.
8144 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8145 Int_Val := Expr_Value (Arg1X);
8147 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8149 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8152 ("value not in range of type " &
8153 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8159 case Chars (Get_Pragma_Arg (Arg2)) is
8160 when Name_Runtime => State_Type := 'r';
8161 when Name_System => State_Type := 's';
8162 when Name_User => State_Type := 'u';
8165 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8168 -- Check if entry is already stored
8170 IST_Num := Interrupt_States.First;
8172 -- If entry not found, add it
8174 if IST_Num > Interrupt_States.Last then
8175 Interrupt_States.Append
8176 ((Interrupt_Number => UI_To_Int (Int_Val),
8177 Interrupt_State => State_Type,
8178 Pragma_Loc => Loc));
8181 -- Case of entry for the same entry
8183 elsif Int_Val = Interrupt_States.Table (IST_Num).
8186 -- If state matches, done, no need to make redundant entry
8189 State_Type = Interrupt_States.Table (IST_Num).
8192 -- Otherwise if state does not match, error
8195 Interrupt_States.Table (IST_Num).Pragma_Loc;
8197 ("state conflicts with that given #", Arg2);
8201 IST_Num := IST_Num + 1;
8203 end Interrupt_State;
8205 ----------------------
8206 -- Java_Constructor --
8207 ----------------------
8209 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8211 -- Also handles pragma CIL_Constructor
8213 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8214 Java_Constructor : declare
8218 Convention : Convention_Id;
8222 Check_Arg_Count (1);
8223 Check_Optional_Identifier (Arg1, Name_Entity);
8224 Check_Arg_Is_Local_Name (Arg1);
8226 Id := Expression (Arg1);
8227 Find_Program_Unit_Name (Id);
8229 -- If we did not find the name, we are done
8231 if Etype (Id) = Any_Type then
8236 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8237 when Pragma_Java_Constructor => Convention := Convention_Java;
8238 when others => null;
8241 Hom_Id := Entity (Id);
8243 -- Loop through homonyms
8246 Def_Id := Get_Base_Subprogram (Hom_Id);
8248 -- The constructor is required to be a function returning an
8249 -- access type whose designated type has convention Java/CIL.
8251 if Ekind (Def_Id) = E_Function
8253 (Is_Value_Type (Etype (Def_Id))
8255 (Ekind (Etype (Def_Id)) in Access_Kind
8258 (Designated_Type (Etype (Def_Id))) = Convention
8261 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8264 Set_Is_Constructor (Def_Id);
8265 Set_Convention (Def_Id, Convention);
8266 Set_Is_Imported (Def_Id);
8269 if Convention = Convention_Java then
8271 ("pragma% requires function returning a " &
8272 "'Java access type", Arg1);
8274 pragma Assert (Convention = Convention_CIL);
8276 ("pragma% requires function returning a " &
8277 "'CIL access type", Arg1);
8281 Hom_Id := Homonym (Hom_Id);
8283 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8285 end Java_Constructor;
8287 ----------------------
8288 -- Java_Interface --
8289 ----------------------
8291 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8293 when Pragma_Java_Interface => Java_Interface : declare
8299 Check_Arg_Count (1);
8300 Check_Optional_Identifier (Arg1, Name_Entity);
8301 Check_Arg_Is_Local_Name (Arg1);
8303 Arg := Expression (Arg1);
8306 if Etype (Arg) = Any_Type then
8310 if not Is_Entity_Name (Arg)
8311 or else not Is_Type (Entity (Arg))
8313 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8316 Typ := Underlying_Type (Entity (Arg));
8318 -- For now we simply check some of the semantic constraints
8319 -- on the type. This currently leaves out some restrictions
8320 -- on interface types, namely that the parent type must be
8321 -- java.lang.Object.Typ and that all primitives of the type
8322 -- should be declared abstract. ???
8324 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8325 Error_Pragma_Arg ("pragma% requires an abstract "
8326 & "tagged type", Arg1);
8328 elsif not Has_Discriminants (Typ)
8329 or else Ekind (Etype (First_Discriminant (Typ)))
8330 /= E_Anonymous_Access_Type
8332 not Is_Class_Wide_Type
8333 (Designated_Type (Etype (First_Discriminant (Typ))))
8336 ("type must have a class-wide access discriminant", Arg1);
8344 -- pragma Keep_Names ([On => ] local_NAME);
8346 when Pragma_Keep_Names => Keep_Names : declare
8351 Check_Arg_Count (1);
8352 Check_Optional_Identifier (Arg1, Name_On);
8353 Check_Arg_Is_Local_Name (Arg1);
8355 Arg := Expression (Arg1);
8358 if Etype (Arg) = Any_Type then
8362 if not Is_Entity_Name (Arg)
8363 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8366 ("pragma% requires a local enumeration type", Arg1);
8369 Set_Discard_Names (Entity (Arg), False);
8376 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8378 when Pragma_License =>
8380 Check_Arg_Count (1);
8381 Check_No_Identifiers;
8382 Check_Valid_Configuration_Pragma;
8383 Check_Arg_Is_Identifier (Arg1);
8386 Sind : constant Source_File_Index :=
8387 Source_Index (Current_Sem_Unit);
8390 case Chars (Get_Pragma_Arg (Arg1)) is
8392 Set_License (Sind, GPL);
8394 when Name_Modified_GPL =>
8395 Set_License (Sind, Modified_GPL);
8397 when Name_Restricted =>
8398 Set_License (Sind, Restricted);
8400 when Name_Unrestricted =>
8401 Set_License (Sind, Unrestricted);
8404 Error_Pragma_Arg ("invalid license name", Arg1);
8412 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8414 when Pragma_Link_With => Link_With : declare
8420 if Operating_Mode = Generate_Code
8421 and then In_Extended_Main_Source_Unit (N)
8423 Check_At_Least_N_Arguments (1);
8424 Check_No_Identifiers;
8425 Check_Is_In_Decl_Part_Or_Package_Spec;
8426 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8430 while Present (Arg) loop
8431 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8433 -- Store argument, converting sequences of spaces
8434 -- to a single null character (this is one of the
8435 -- differences in processing between Link_With
8436 -- and Linker_Options).
8439 C : constant Char_Code := Get_Char_Code (' ');
8440 S : constant String_Id :=
8441 Strval (Expr_Value_S (Expression (Arg)));
8442 L : constant Nat := String_Length (S);
8445 procedure Skip_Spaces;
8446 -- Advance F past any spaces
8452 procedure Skip_Spaces is
8454 while F <= L and then Get_String_Char (S, F) = C loop
8459 -- Start of processing for Arg_Store
8462 Skip_Spaces; -- skip leading spaces
8464 -- Loop through characters, changing any embedded
8465 -- sequence of spaces to a single null character
8466 -- (this is how Link_With/Linker_Options differ)
8469 if Get_String_Char (S, F) = C then
8472 Store_String_Char (ASCII.NUL);
8475 Store_String_Char (Get_String_Char (S, F));
8483 if Present (Arg) then
8484 Store_String_Char (ASCII.NUL);
8488 Store_Linker_Option_String (End_String);
8496 -- pragma Linker_Alias (
8497 -- [Entity =>] LOCAL_NAME
8498 -- [Target =>] static_string_EXPRESSION);
8500 when Pragma_Linker_Alias =>
8502 Check_Arg_Order ((Name_Entity, Name_Target));
8503 Check_Arg_Count (2);
8504 Check_Optional_Identifier (Arg1, Name_Entity);
8505 Check_Optional_Identifier (Arg2, Name_Target);
8506 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8507 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8509 -- The only processing required is to link this item on to the
8510 -- list of rep items for the given entity. This is accomplished
8511 -- by the call to Rep_Item_Too_Late (when no error is detected
8512 -- and False is returned).
8514 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8517 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8520 ------------------------
8521 -- Linker_Constructor --
8522 ------------------------
8524 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8526 -- Code is shared with Linker_Destructor
8528 -----------------------
8529 -- Linker_Destructor --
8530 -----------------------
8532 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8534 when Pragma_Linker_Constructor |
8535 Pragma_Linker_Destructor =>
8536 Linker_Constructor : declare
8542 Check_Arg_Count (1);
8543 Check_No_Identifiers;
8544 Check_Arg_Is_Local_Name (Arg1);
8545 Arg1_X := Expression (Arg1);
8547 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8549 if not Is_Library_Level_Entity (Proc) then
8551 ("argument for pragma% must be library level entity", Arg1);
8554 -- The only processing required is to link this item on to the
8555 -- list of rep items for the given entity. This is accomplished
8556 -- by the call to Rep_Item_Too_Late (when no error is detected
8557 -- and False is returned).
8559 if Rep_Item_Too_Late (Proc, N) then
8562 Set_Has_Gigi_Rep_Item (Proc);
8564 end Linker_Constructor;
8566 --------------------
8567 -- Linker_Options --
8568 --------------------
8570 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8572 when Pragma_Linker_Options => Linker_Options : declare
8576 Check_Ada_83_Warning;
8577 Check_No_Identifiers;
8578 Check_Arg_Count (1);
8579 Check_Is_In_Decl_Part_Or_Package_Spec;
8580 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8581 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8584 while Present (Arg) loop
8585 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8586 Store_String_Char (ASCII.NUL);
8587 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8591 if Operating_Mode = Generate_Code
8592 and then In_Extended_Main_Source_Unit (N)
8594 Store_Linker_Option_String (End_String);
8598 --------------------
8599 -- Linker_Section --
8600 --------------------
8602 -- pragma Linker_Section (
8603 -- [Entity =>] LOCAL_NAME
8604 -- [Section =>] static_string_EXPRESSION);
8606 when Pragma_Linker_Section =>
8608 Check_Arg_Order ((Name_Entity, Name_Section));
8609 Check_Arg_Count (2);
8610 Check_Optional_Identifier (Arg1, Name_Entity);
8611 Check_Optional_Identifier (Arg2, Name_Section);
8612 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8613 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8615 -- This pragma applies only to objects
8617 if not Is_Object (Entity (Expression (Arg1))) then
8618 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8621 -- The only processing required is to link this item on to the
8622 -- list of rep items for the given entity. This is accomplished
8623 -- by the call to Rep_Item_Too_Late (when no error is detected
8624 -- and False is returned).
8626 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8629 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8636 -- pragma List (On | Off)
8638 -- There is nothing to do here, since we did all the processing
8639 -- for this pragma in Par.Prag (so that it works properly even in
8640 -- syntax only mode)
8645 --------------------
8646 -- Locking_Policy --
8647 --------------------
8649 -- pragma Locking_Policy (policy_IDENTIFIER);
8651 when Pragma_Locking_Policy => declare
8655 Check_Ada_83_Warning;
8656 Check_Arg_Count (1);
8657 Check_No_Identifiers;
8658 Check_Arg_Is_Locking_Policy (Arg1);
8659 Check_Valid_Configuration_Pragma;
8660 Get_Name_String (Chars (Expression (Arg1)));
8661 LP := Fold_Upper (Name_Buffer (1));
8663 if Locking_Policy /= ' '
8664 and then Locking_Policy /= LP
8666 Error_Msg_Sloc := Locking_Policy_Sloc;
8667 Error_Pragma ("locking policy incompatible with policy#");
8669 -- Set new policy, but always preserve System_Location since
8670 -- we like the error message with the run time name.
8673 Locking_Policy := LP;
8675 if Locking_Policy_Sloc /= System_Location then
8676 Locking_Policy_Sloc := Loc;
8685 -- pragma Long_Float (D_Float | G_Float);
8687 when Pragma_Long_Float =>
8689 Check_Valid_Configuration_Pragma;
8690 Check_Arg_Count (1);
8691 Check_No_Identifier (Arg1);
8692 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8694 if not OpenVMS_On_Target then
8695 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8700 if Chars (Expression (Arg1)) = Name_D_Float then
8701 if Opt.Float_Format_Long = 'G' then
8702 Error_Pragma ("G_Float previously specified");
8705 Opt.Float_Format_Long := 'D';
8707 -- G_Float case (this is the default, does not need overriding)
8710 if Opt.Float_Format_Long = 'D' then
8711 Error_Pragma ("D_Float previously specified");
8714 Opt.Float_Format_Long := 'G';
8717 Set_Standard_Fpt_Formats;
8719 -----------------------
8720 -- Machine_Attribute --
8721 -----------------------
8723 -- pragma Machine_Attribute (
8724 -- [Entity =>] LOCAL_NAME,
8725 -- [Attribute_Name =>] static_string_EXPRESSION
8726 -- [, [Info =>] static_string_EXPRESSION] );
8728 when Pragma_Machine_Attribute => Machine_Attribute : declare
8733 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8735 if Arg_Count = 3 then
8736 Check_Optional_Identifier (Arg3, Name_Info);
8737 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
8739 Check_Arg_Count (2);
8742 Check_Optional_Identifier (Arg1, Name_Entity);
8743 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8744 Check_Arg_Is_Local_Name (Arg1);
8745 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8746 Def_Id := Entity (Expression (Arg1));
8748 if Is_Access_Type (Def_Id) then
8749 Def_Id := Designated_Type (Def_Id);
8752 if Rep_Item_Too_Early (Def_Id, N) then
8756 Def_Id := Underlying_Type (Def_Id);
8758 -- The only processing required is to link this item on to the
8759 -- list of rep items for the given entity. This is accomplished
8760 -- by the call to Rep_Item_Too_Late (when no error is detected
8761 -- and False is returned).
8763 if Rep_Item_Too_Late (Def_Id, N) then
8766 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8768 end Machine_Attribute;
8775 -- (MAIN_OPTION [, MAIN_OPTION]);
8778 -- [STACK_SIZE =>] static_integer_EXPRESSION
8779 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8780 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8782 when Pragma_Main => Main : declare
8783 Args : Args_List (1 .. 3);
8784 Names : constant Name_List (1 .. 3) := (
8786 Name_Task_Stack_Size_Default,
8787 Name_Time_Slicing_Enabled);
8793 Gather_Associations (Names, Args);
8795 for J in 1 .. 2 loop
8796 if Present (Args (J)) then
8797 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8801 if Present (Args (3)) then
8802 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8806 while Present (Nod) loop
8807 if Nkind (Nod) = N_Pragma
8808 and then Pragma_Name (Nod) = Name_Main
8810 Error_Msg_Name_1 := Pname;
8811 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8822 -- pragma Main_Storage
8823 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8825 -- MAIN_STORAGE_OPTION ::=
8826 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8827 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8829 when Pragma_Main_Storage => Main_Storage : declare
8830 Args : Args_List (1 .. 2);
8831 Names : constant Name_List (1 .. 2) := (
8832 Name_Working_Storage,
8839 Gather_Associations (Names, Args);
8841 for J in 1 .. 2 loop
8842 if Present (Args (J)) then
8843 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8847 Check_In_Main_Program;
8850 while Present (Nod) loop
8851 if Nkind (Nod) = N_Pragma
8852 and then Pragma_Name (Nod) = Name_Main_Storage
8854 Error_Msg_Name_1 := Pname;
8855 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8866 -- pragma Memory_Size (NUMERIC_LITERAL)
8868 when Pragma_Memory_Size =>
8871 -- Memory size is simply ignored
8873 Check_No_Identifiers;
8874 Check_Arg_Count (1);
8875 Check_Arg_Is_Integer_Literal (Arg1);
8883 -- The only correct use of this pragma is on its own in a file, in
8884 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
8885 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
8886 -- check for a file containing nothing but a No_Body pragma). If we
8887 -- attempt to process it during normal semantics processing, it means
8888 -- it was misplaced.
8890 when Pragma_No_Body =>
8898 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8900 when Pragma_No_Return => No_Return : declare
8908 Check_At_Least_N_Arguments (1);
8910 -- Loop through arguments of pragma
8913 while Present (Arg) loop
8914 Check_Arg_Is_Local_Name (Arg);
8915 Id := Expression (Arg);
8918 if not Is_Entity_Name (Id) then
8919 Error_Pragma_Arg ("entity name required", Arg);
8922 if Etype (Id) = Any_Type then
8926 -- Loop to find matching procedures
8931 and then Scope (E) = Current_Scope
8933 if Ekind (E) = E_Procedure
8934 or else Ekind (E) = E_Generic_Procedure
8938 -- Set flag on any alias as well
8940 if Is_Overloadable (E) and then Present (Alias (E)) then
8941 Set_No_Return (Alias (E));
8951 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
8962 -- pragma No_Run_Time;
8964 -- Note: this pragma is retained for backwards compatibility.
8965 -- See body of Rtsfind for full details on its handling.
8967 when Pragma_No_Run_Time =>
8969 Check_Valid_Configuration_Pragma;
8970 Check_Arg_Count (0);
8972 No_Run_Time_Mode := True;
8973 Configurable_Run_Time_Mode := True;
8975 -- Set Duration to 32 bits if word size is 32
8977 if Ttypes.System_Word_Size = 32 then
8978 Duration_32_Bits_On_Target := True;
8981 -- Set appropriate restrictions
8983 Set_Restriction (No_Finalization, N);
8984 Set_Restriction (No_Exception_Handlers, N);
8985 Set_Restriction (Max_Tasks, N, 0);
8986 Set_Restriction (No_Tasking, N);
8988 ------------------------
8989 -- No_Strict_Aliasing --
8990 ------------------------
8992 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
8994 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
8999 Check_At_Most_N_Arguments (1);
9001 if Arg_Count = 0 then
9002 Check_Valid_Configuration_Pragma;
9003 Opt.No_Strict_Aliasing := True;
9006 Check_Optional_Identifier (Arg2, Name_Entity);
9007 Check_Arg_Is_Local_Name (Arg1);
9008 E_Id := Entity (Expression (Arg1));
9010 if E_Id = Any_Type then
9012 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9013 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9016 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9018 end No_Strict_Aliasing;
9020 -----------------------
9021 -- Normalize_Scalars --
9022 -----------------------
9024 -- pragma Normalize_Scalars;
9026 when Pragma_Normalize_Scalars =>
9027 Check_Ada_83_Warning;
9028 Check_Arg_Count (0);
9029 Check_Valid_Configuration_Pragma;
9030 Normalize_Scalars := True;
9031 Init_Or_Norm_Scalars := True;
9037 -- pragma Obsolescent [(
9038 -- [Entity => NAME,]
9039 -- [(static_string_EXPRESSION [, Ada_05])];
9041 when Pragma_Obsolescent => Obsolescent : declare
9045 procedure Set_Obsolescent (E : Entity_Id);
9046 -- Given an entity Ent, mark it as obsolescent if appropriate
9048 ---------------------
9049 -- Set_Obsolescent --
9050 ---------------------
9052 procedure Set_Obsolescent (E : Entity_Id) is
9061 -- Entity name was given
9063 if Present (Ename) then
9065 -- If entity name matches, we are fine
9067 if Chars (Ename) = Chars (Ent) then
9070 -- If entity name does not match, only possibility is an
9071 -- enumeration literal from an enumeration type declaration.
9073 elsif Ekind (Ent) /= E_Enumeration_Type then
9075 ("pragma % entity name does not match declaration");
9078 Ent := First_Literal (E);
9082 ("pragma % entity name does not match any " &
9083 "enumeration literal");
9085 elsif Chars (Ent) = Chars (Ename) then
9089 Ent := Next_Literal (Ent);
9095 -- Ent points to entity to be marked
9097 if Arg_Count >= 1 then
9099 -- Deal with static string argument
9101 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9102 S := Strval (Expression (Arg1));
9104 for J in 1 .. String_Length (S) loop
9105 if not In_Character_Range (Get_String_Char (S, J)) then
9107 ("pragma% argument does not allow wide characters",
9112 Obsolescent_Warnings.Append
9113 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9115 -- Check for Ada_05 parameter
9117 if Arg_Count /= 1 then
9118 Check_Arg_Count (2);
9121 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9124 Check_Arg_Is_Identifier (Argx);
9126 if Chars (Argx) /= Name_Ada_05 then
9127 Error_Msg_Name_2 := Name_Ada_05;
9129 ("only allowed argument for pragma% is %", Argx);
9132 if Ada_Version_Explicit < Ada_05
9133 or else not Warn_On_Ada_2005_Compatibility
9141 -- Set flag if pragma active
9144 Set_Is_Obsolescent (Ent);
9148 end Set_Obsolescent;
9150 -- Start of processing for pragma Obsolescent
9155 Check_At_Most_N_Arguments (3);
9157 -- See if first argument specifies an entity name
9160 and then Chars (Arg1) = Name_Entity
9162 Ename := Get_Pragma_Arg (Arg1);
9164 if Nkind (Ename) /= N_Character_Literal
9166 Nkind (Ename) /= N_Identifier
9168 Nkind (Ename) /= N_Operator_Symbol
9170 Error_Pragma_Arg ("entity name expected for pragma%", Arg1);
9173 -- Eliminate first argument, so we can share processing
9177 Arg_Count := Arg_Count - 1;
9179 -- No Entity name argument given
9185 Check_No_Identifiers;
9187 -- Get immediately preceding declaration
9190 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9194 -- Cases where we do not follow anything other than another pragma
9198 -- First case: library level compilation unit declaration with
9199 -- the pragma immediately following the declaration.
9201 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9203 (Defining_Entity (Unit (Parent (Parent (N)))));
9206 -- Case 2: library unit placement for package
9210 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9212 if Ekind (Ent) = E_Package
9213 or else Ekind (Ent) = E_Generic_Package
9215 Set_Obsolescent (Ent);
9221 -- Cases where we must follow a declaration
9224 if Nkind (Decl) not in N_Declaration
9225 and then Nkind (Decl) not in N_Later_Decl_Item
9226 and then Nkind (Decl) not in N_Generic_Declaration
9229 ("pragma% misplaced, " &
9230 "must immediately follow a declaration");
9233 Set_Obsolescent (Defining_Entity (Decl));
9243 -- pragma Optimize (Time | Space | Off);
9245 -- The actual check for optimize is done in Gigi. Note that this
9246 -- pragma does not actually change the optimization setting, it
9247 -- simply checks that it is consistent with the pragma.
9249 when Pragma_Optimize =>
9250 Check_No_Identifiers;
9251 Check_Arg_Count (1);
9252 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9254 ------------------------
9255 -- Optimize_Alignment --
9256 ------------------------
9258 -- pragma Optimize_Alignment (Time | Space | Off);
9260 when Pragma_Optimize_Alignment =>
9262 Check_No_Identifiers;
9263 Check_Arg_Count (1);
9264 Check_Valid_Configuration_Pragma;
9267 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9271 Opt.Optimize_Alignment := 'T';
9273 Opt.Optimize_Alignment := 'S';
9275 Opt.Optimize_Alignment := 'O';
9277 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9281 -- Set indication that mode is set locally. If we are in fact in a
9282 -- configuration pragma file, this setting is harmless since the
9283 -- switch will get reset anyway at the start of each unit.
9285 Optimize_Alignment_Local := True;
9291 -- pragma Pack (first_subtype_LOCAL_NAME);
9293 when Pragma_Pack => Pack : declare
9294 Assoc : constant Node_Id := Arg1;
9299 Check_No_Identifiers;
9300 Check_Arg_Count (1);
9301 Check_Arg_Is_Local_Name (Arg1);
9303 Type_Id := Expression (Assoc);
9304 Find_Type (Type_Id);
9305 Typ := Entity (Type_Id);
9308 or else Rep_Item_Too_Early (Typ, N)
9312 Typ := Underlying_Type (Typ);
9315 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9316 Error_Pragma ("pragma% must specify array or record type");
9319 Check_First_Subtype (Arg1);
9321 if Has_Pragma_Pack (Typ) then
9322 Error_Pragma ("duplicate pragma%, only one allowed");
9326 elsif Is_Array_Type (Typ) then
9328 -- Pack not allowed for aliased or atomic components
9330 if Has_Aliased_Components (Base_Type (Typ)) then
9332 ("pragma% ignored, cannot pack aliased components?");
9334 elsif Has_Atomic_Components (Typ)
9335 or else Is_Atomic (Component_Type (Typ))
9338 ("?pragma% ignored, cannot pack atomic components");
9341 -- If we had an explicit component size given, then we do not
9342 -- let Pack override this given size. We also give a warning
9343 -- that Pack is being ignored unless we can tell for sure that
9344 -- the Pack would not have had any effect anyway.
9346 if Has_Component_Size_Clause (Typ) then
9347 if Known_Static_RM_Size (Component_Type (Typ))
9349 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9354 ("?pragma% ignored, explicit component size given");
9357 -- If no prior array component size given, Pack is effective
9360 if not Rep_Item_Too_Late (Typ, N) then
9361 if VM_Target = No_VM then
9362 Set_Is_Packed (Base_Type (Typ));
9363 elsif not GNAT_Mode then
9365 ("?pragma% ignored in this configuration");
9368 Set_Has_Pragma_Pack (Base_Type (Typ));
9369 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9373 -- For record types, the pack is always effective
9375 else pragma Assert (Is_Record_Type (Typ));
9376 if not Rep_Item_Too_Late (Typ, N) then
9377 if VM_Target = No_VM then
9378 Set_Is_Packed (Base_Type (Typ));
9379 elsif not GNAT_Mode then
9380 Error_Pragma ("?pragma% ignored in this configuration");
9383 Set_Has_Pragma_Pack (Base_Type (Typ));
9384 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9395 -- There is nothing to do here, since we did all the processing
9396 -- for this pragma in Par.Prag (so that it works properly even in
9397 -- syntax only mode)
9406 -- pragma Passive [(PASSIVE_FORM)];
9408 -- PASSIVE_FORM ::= Semaphore | No
9410 when Pragma_Passive =>
9413 if Nkind (Parent (N)) /= N_Task_Definition then
9414 Error_Pragma ("pragma% must be within task definition");
9417 if Arg_Count /= 0 then
9418 Check_Arg_Count (1);
9419 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9422 ----------------------------------
9423 -- Preelaborable_Initialization --
9424 ----------------------------------
9426 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9428 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9433 Check_Arg_Count (1);
9434 Check_No_Identifiers;
9435 Check_Arg_Is_Identifier (Arg1);
9436 Check_Arg_Is_Local_Name (Arg1);
9437 Check_First_Subtype (Arg1);
9438 Ent := Entity (Expression (Arg1));
9440 if not Is_Private_Type (Ent)
9441 and then not Is_Protected_Type (Ent)
9444 ("pragma % can only be applied to private or protected type",
9448 -- Give an error if the pragma is applied to a protected type that
9449 -- does not qualify (due to having entries, or due to components
9450 -- that do not qualify).
9452 if Is_Protected_Type (Ent)
9453 and then not Has_Preelaborable_Initialization (Ent)
9456 ("protected type & does not have preelaborable " &
9457 "initialization", Ent);
9459 -- Otherwise mark the type as definitely having preelaborable
9463 Set_Known_To_Have_Preelab_Init (Ent);
9466 if Has_Pragma_Preelab_Init (Ent)
9467 and then Warn_On_Redundant_Constructs
9469 Error_Pragma ("?duplicate pragma%!");
9471 Set_Has_Pragma_Preelab_Init (Ent);
9475 --------------------
9476 -- Persistent_BSS --
9477 --------------------
9479 when Pragma_Persistent_BSS => Persistent_BSS : declare
9486 Check_At_Most_N_Arguments (1);
9488 -- Case of application to specific object (one argument)
9490 if Arg_Count = 1 then
9491 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9493 if not Is_Entity_Name (Expression (Arg1))
9495 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9496 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9498 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9501 Ent := Entity (Expression (Arg1));
9502 Decl := Parent (Ent);
9504 if Rep_Item_Too_Late (Ent, N) then
9508 if Present (Expression (Decl)) then
9510 ("object for pragma% cannot have initialization", Arg1);
9513 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9515 ("object type for pragma% is not potentially persistent",
9520 Make_Linker_Section_Pragma
9521 (Ent, Sloc (N), ".persistent.bss");
9522 Insert_After (N, Prag);
9525 -- Case of use as configuration pragma with no arguments
9528 Check_Valid_Configuration_Pragma;
9529 Persistent_BSS_Mode := True;
9537 -- pragma Polling (ON | OFF);
9539 when Pragma_Polling =>
9541 Check_Arg_Count (1);
9542 Check_No_Identifiers;
9543 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9544 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9550 -- pragma Postcondition ([Check =>] Boolean_Expression
9551 -- [,[Message =>] String_Expression]);
9553 when Pragma_Postcondition => Postcondition : declare
9555 pragma Warnings (Off, In_Body);
9559 Check_At_Least_N_Arguments (1);
9560 Check_At_Most_N_Arguments (2);
9561 Check_Optional_Identifier (Arg1, Name_Check);
9563 -- All we need to do here is call the common check procedure,
9564 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9566 Check_Precondition_Postcondition (In_Body);
9573 -- pragma Precondition ([Check =>] Boolean_Expression
9574 -- [,[Message =>] String_Expression]);
9576 when Pragma_Precondition => Precondition : declare
9581 Check_At_Least_N_Arguments (1);
9582 Check_At_Most_N_Arguments (2);
9583 Check_Optional_Identifier (Arg1, Name_Check);
9585 Check_Precondition_Postcondition (In_Body);
9587 -- If in spec, nothing to do. If in body, then we convert the
9588 -- pragma to pragma Check (Precondition, cond [, msg]). Note we
9589 -- do this whether or not precondition checks are enabled. That
9590 -- works fine since pragma Check will do this check.
9593 if Arg_Count = 2 then
9594 Check_Optional_Identifier (Arg3, Name_Message);
9595 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9598 Analyze_And_Resolve (Get_Pragma_Arg (Arg1), Standard_Boolean);
9602 Chars => Name_Check,
9603 Pragma_Argument_Associations => New_List (
9604 Make_Pragma_Argument_Association (Loc,
9606 Make_Identifier (Loc,
9607 Chars => Name_Precondition)),
9609 Make_Pragma_Argument_Association (Sloc (Arg1),
9610 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9612 if Arg_Count = 2 then
9613 Append_To (Pragma_Argument_Associations (N),
9614 Make_Pragma_Argument_Association (Sloc (Arg2),
9615 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9626 -- pragma Preelaborate [(library_unit_NAME)];
9628 -- Set the flag Is_Preelaborated of program unit name entity
9630 when Pragma_Preelaborate => Preelaborate : declare
9631 Pa : constant Node_Id := Parent (N);
9632 Pk : constant Node_Kind := Nkind (Pa);
9636 Check_Ada_83_Warning;
9637 Check_Valid_Library_Unit_Pragma;
9639 if Nkind (N) = N_Null_Statement then
9643 Ent := Find_Lib_Unit_Name;
9645 -- This filters out pragmas inside generic parent then
9646 -- show up inside instantiation
9649 and then not (Pk = N_Package_Specification
9650 and then Present (Generic_Parent (Pa)))
9652 if not Debug_Flag_U then
9653 Set_Is_Preelaborated (Ent);
9654 Set_Suppress_Elaboration_Warnings (Ent);
9659 ---------------------
9660 -- Preelaborate_05 --
9661 ---------------------
9663 -- pragma Preelaborate_05 [(library_unit_NAME)];
9665 -- This pragma is useable only in GNAT_Mode, where it is used like
9666 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9667 -- (otherwise it is ignored). This is used to implement AI-362 which
9668 -- recategorizes some run-time packages in Ada 2005 mode.
9670 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9675 Check_Valid_Library_Unit_Pragma;
9677 if not GNAT_Mode then
9678 Error_Pragma ("pragma% only available in GNAT mode");
9681 if Nkind (N) = N_Null_Statement then
9685 -- This is one of the few cases where we need to test the value of
9686 -- Ada_Version_Explicit rather than Ada_Version (which is always
9687 -- set to Ada_05 in a predefined unit), we need to know the
9688 -- explicit version set to know if this pragma is active.
9690 if Ada_Version_Explicit >= Ada_05 then
9691 Ent := Find_Lib_Unit_Name;
9692 Set_Is_Preelaborated (Ent);
9693 Set_Suppress_Elaboration_Warnings (Ent);
9695 end Preelaborate_05;
9701 -- pragma Priority (EXPRESSION);
9703 when Pragma_Priority => Priority : declare
9704 P : constant Node_Id := Parent (N);
9708 Check_No_Identifiers;
9709 Check_Arg_Count (1);
9713 if Nkind (P) = N_Subprogram_Body then
9714 Check_In_Main_Program;
9716 Arg := Expression (Arg1);
9717 Analyze_And_Resolve (Arg, Standard_Integer);
9721 if not Is_Static_Expression (Arg) then
9722 Flag_Non_Static_Expr
9723 ("main subprogram priority is not static!", Arg);
9726 -- If constraint error, then we already signalled an error
9728 elsif Raises_Constraint_Error (Arg) then
9731 -- Otherwise check in range
9735 Val : constant Uint := Expr_Value (Arg);
9739 or else Val > Expr_Value (Expression
9740 (Parent (RTE (RE_Max_Priority))))
9743 ("main subprogram priority is out of range", Arg1);
9749 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9751 -- Load an arbitrary entity from System.Tasking to make sure
9752 -- this package is implicitly with'ed, since we need to have
9753 -- the tasking run-time active for the pragma Priority to have
9757 Discard : Entity_Id;
9758 pragma Warnings (Off, Discard);
9760 Discard := RTE (RE_Task_List);
9763 -- Task or Protected, must be of type Integer
9765 elsif Nkind (P) = N_Protected_Definition
9767 Nkind (P) = N_Task_Definition
9769 Arg := Expression (Arg1);
9771 -- The expression must be analyzed in the special manner
9772 -- described in "Handling of Default and Per-Object
9773 -- Expressions" in sem.ads.
9775 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9777 if not Is_Static_Expression (Arg) then
9778 Check_Restriction (Static_Priorities, Arg);
9781 -- Anything else is incorrect
9787 if Has_Priority_Pragma (P) then
9788 Error_Pragma ("duplicate pragma% not allowed");
9790 Set_Has_Priority_Pragma (P, True);
9792 if Nkind (P) = N_Protected_Definition
9794 Nkind (P) = N_Task_Definition
9796 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9797 -- exp_ch9 should use this ???
9802 -----------------------------------
9803 -- Priority_Specific_Dispatching --
9804 -----------------------------------
9806 -- pragma Priority_Specific_Dispatching (
9807 -- policy_IDENTIFIER,
9808 -- first_priority_EXPRESSION,
9809 -- last_priority_EXPRESSION);
9811 when Pragma_Priority_Specific_Dispatching =>
9812 Priority_Specific_Dispatching : declare
9813 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9814 -- This is the entity System.Any_Priority;
9817 Lower_Bound : Node_Id;
9818 Upper_Bound : Node_Id;
9824 Check_Arg_Count (3);
9825 Check_No_Identifiers;
9826 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9827 Check_Valid_Configuration_Pragma;
9828 Get_Name_String (Chars (Expression (Arg1)));
9829 DP := Fold_Upper (Name_Buffer (1));
9831 Lower_Bound := Expression (Arg2);
9832 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9833 Lower_Val := Expr_Value (Lower_Bound);
9835 Upper_Bound := Expression (Arg3);
9836 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
9837 Upper_Val := Expr_Value (Upper_Bound);
9839 -- It is not allowed to use Task_Dispatching_Policy and
9840 -- Priority_Specific_Dispatching in the same partition.
9842 if Task_Dispatching_Policy /= ' ' then
9843 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9845 ("pragma% incompatible with Task_Dispatching_Policy#");
9847 -- Check lower bound in range
9849 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9851 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
9854 ("first_priority is out of range", Arg2);
9856 -- Check upper bound in range
9858 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9860 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
9863 ("last_priority is out of range", Arg3);
9865 -- Check that the priority range is valid
9867 elsif Lower_Val > Upper_Val then
9869 ("last_priority_expression must be greater than" &
9870 " or equal to first_priority_expression");
9872 -- Store the new policy, but always preserve System_Location since
9873 -- we like the error message with the run-time name.
9876 -- Check overlapping in the priority ranges specified in other
9877 -- Priority_Specific_Dispatching pragmas within the same
9878 -- partition. We can only check those we know about!
9881 Specific_Dispatching.First .. Specific_Dispatching.Last
9883 if Specific_Dispatching.Table (J).First_Priority in
9884 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9885 or else Specific_Dispatching.Table (J).Last_Priority in
9886 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9889 Specific_Dispatching.Table (J).Pragma_Loc;
9891 ("priority range overlaps with "
9892 & "Priority_Specific_Dispatching#");
9896 -- The use of Priority_Specific_Dispatching is incompatible
9897 -- with Task_Dispatching_Policy.
9899 if Task_Dispatching_Policy /= ' ' then
9900 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9902 ("Priority_Specific_Dispatching incompatible "
9903 & "with Task_Dispatching_Policy#");
9906 -- The use of Priority_Specific_Dispatching forces ceiling
9909 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
9910 Error_Msg_Sloc := Locking_Policy_Sloc;
9912 ("Priority_Specific_Dispatching incompatible "
9913 & "with Locking_Policy#");
9915 -- Set the Ceiling_Locking policy, but preserve System_Location
9916 -- since we like the error message with the run time name.
9919 Locking_Policy := 'C';
9921 if Locking_Policy_Sloc /= System_Location then
9922 Locking_Policy_Sloc := Loc;
9926 -- Add entry in the table
9928 Specific_Dispatching.Append
9929 ((Dispatching_Policy => DP,
9930 First_Priority => UI_To_Int (Lower_Val),
9931 Last_Priority => UI_To_Int (Upper_Val),
9932 Pragma_Loc => Loc));
9934 end Priority_Specific_Dispatching;
9940 -- pragma Profile (profile_IDENTIFIER);
9942 -- profile_IDENTIFIER => Restricted | Ravenscar
9944 when Pragma_Profile =>
9946 Check_Arg_Count (1);
9947 Check_Valid_Configuration_Pragma;
9948 Check_No_Identifiers;
9951 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9953 if Chars (Argx) = Name_Ravenscar then
9954 Set_Ravenscar_Profile (N);
9955 elsif Chars (Argx) = Name_Restricted then
9956 Set_Profile_Restrictions
9957 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
9959 Error_Pragma_Arg ("& is not a valid profile", Argx);
9963 ----------------------
9964 -- Profile_Warnings --
9965 ----------------------
9967 -- pragma Profile_Warnings (profile_IDENTIFIER);
9969 -- profile_IDENTIFIER => Restricted | Ravenscar
9971 when Pragma_Profile_Warnings =>
9973 Check_Arg_Count (1);
9974 Check_Valid_Configuration_Pragma;
9975 Check_No_Identifiers;
9978 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9980 if Chars (Argx) = Name_Ravenscar then
9981 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
9982 elsif Chars (Argx) = Name_Restricted then
9983 Set_Profile_Restrictions (Restricted, N, Warn => True);
9985 Error_Pragma_Arg ("& is not a valid profile", Argx);
9989 --------------------------
9990 -- Propagate_Exceptions --
9991 --------------------------
9993 -- pragma Propagate_Exceptions;
9995 -- Note: this pragma is obsolete and has no effect
9997 when Pragma_Propagate_Exceptions =>
9999 Check_Arg_Count (0);
10001 if In_Extended_Main_Source_Unit (N) then
10002 Propagate_Exceptions := True;
10009 -- pragma Psect_Object (
10010 -- [Internal =>] LOCAL_NAME,
10011 -- [, [External =>] EXTERNAL_SYMBOL]
10012 -- [, [Size =>] EXTERNAL_SYMBOL]);
10014 when Pragma_Psect_Object | Pragma_Common_Object =>
10015 Psect_Object : declare
10016 Args : Args_List (1 .. 3);
10017 Names : constant Name_List (1 .. 3) := (
10022 Internal : Node_Id renames Args (1);
10023 External : Node_Id renames Args (2);
10024 Size : Node_Id renames Args (3);
10026 Def_Id : Entity_Id;
10028 procedure Check_Too_Long (Arg : Node_Id);
10029 -- Posts message if the argument is an identifier with more
10030 -- than 31 characters, or a string literal with more than
10031 -- 31 characters, and we are operating under VMS
10033 --------------------
10034 -- Check_Too_Long --
10035 --------------------
10037 procedure Check_Too_Long (Arg : Node_Id) is
10038 X : constant Node_Id := Original_Node (Arg);
10041 if Nkind (X) /= N_String_Literal
10043 Nkind (X) /= N_Identifier
10046 ("inappropriate argument for pragma %", Arg);
10049 if OpenVMS_On_Target then
10050 if (Nkind (X) = N_String_Literal
10051 and then String_Length (Strval (X)) > 31)
10053 (Nkind (X) = N_Identifier
10054 and then Length_Of_Name (Chars (X)) > 31)
10057 ("argument for pragma % is longer than 31 characters",
10061 end Check_Too_Long;
10063 -- Start of processing for Common_Object/Psect_Object
10067 Gather_Associations (Names, Args);
10068 Process_Extended_Import_Export_Internal_Arg (Internal);
10070 Def_Id := Entity (Internal);
10072 if Ekind (Def_Id) /= E_Constant
10073 and then Ekind (Def_Id) /= E_Variable
10076 ("pragma% must designate an object", Internal);
10079 Check_Too_Long (Internal);
10081 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10083 ("cannot use pragma% for imported/exported object",
10087 if Is_Concurrent_Type (Etype (Internal)) then
10089 ("cannot specify pragma % for task/protected object",
10093 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10095 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10097 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10100 if Ekind (Def_Id) = E_Constant then
10102 ("cannot specify pragma % for a constant", Internal);
10105 if Is_Record_Type (Etype (Internal)) then
10111 Ent := First_Entity (Etype (Internal));
10112 while Present (Ent) loop
10113 Decl := Declaration_Node (Ent);
10115 if Ekind (Ent) = E_Component
10116 and then Nkind (Decl) = N_Component_Declaration
10117 and then Present (Expression (Decl))
10118 and then Warn_On_Export_Import
10121 ("?object for pragma % has defaults", Internal);
10131 if Present (Size) then
10132 Check_Too_Long (Size);
10135 if Present (External) then
10136 Check_Arg_Is_External_Name (External);
10137 Check_Too_Long (External);
10140 -- If all error tests pass, link pragma on to the rep item chain
10142 Record_Rep_Item (Def_Id, N);
10149 -- pragma Pure [(library_unit_NAME)];
10151 when Pragma_Pure => Pure : declare
10155 Check_Ada_83_Warning;
10156 Check_Valid_Library_Unit_Pragma;
10158 if Nkind (N) = N_Null_Statement then
10162 Ent := Find_Lib_Unit_Name;
10164 Set_Has_Pragma_Pure (Ent);
10165 Set_Suppress_Elaboration_Warnings (Ent);
10172 -- pragma Pure_05 [(library_unit_NAME)];
10174 -- This pragma is useable only in GNAT_Mode, where it is used like
10175 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10176 -- it is ignored). It may be used after a pragma Preelaborate, in
10177 -- which case it overrides the effect of the pragma Preelaborate.
10178 -- This is used to implement AI-362 which recategorizes some run-time
10179 -- packages in Ada 2005 mode.
10181 when Pragma_Pure_05 => Pure_05 : declare
10186 Check_Valid_Library_Unit_Pragma;
10188 if not GNAT_Mode then
10189 Error_Pragma ("pragma% only available in GNAT mode");
10191 if Nkind (N) = N_Null_Statement then
10195 -- This is one of the few cases where we need to test the value of
10196 -- Ada_Version_Explicit rather than Ada_Version (which is always
10197 -- set to Ada_05 in a predefined unit), we need to know the
10198 -- explicit version set to know if this pragma is active.
10200 if Ada_Version_Explicit >= Ada_05 then
10201 Ent := Find_Lib_Unit_Name;
10202 Set_Is_Preelaborated (Ent, False);
10204 Set_Suppress_Elaboration_Warnings (Ent);
10208 -------------------
10209 -- Pure_Function --
10210 -------------------
10212 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10214 when Pragma_Pure_Function => Pure_Function : declare
10217 Def_Id : Entity_Id;
10218 Effective : Boolean := False;
10222 Check_Arg_Count (1);
10223 Check_Optional_Identifier (Arg1, Name_Entity);
10224 Check_Arg_Is_Local_Name (Arg1);
10225 E_Id := Expression (Arg1);
10227 if Error_Posted (E_Id) then
10231 -- Loop through homonyms (overloadings) of referenced entity
10233 E := Entity (E_Id);
10235 if Present (E) then
10237 Def_Id := Get_Base_Subprogram (E);
10239 if Ekind (Def_Id) /= E_Function
10240 and then Ekind (Def_Id) /= E_Generic_Function
10241 and then Ekind (Def_Id) /= E_Operator
10244 ("pragma% requires a function name", Arg1);
10247 Set_Is_Pure (Def_Id);
10249 if not Has_Pragma_Pure_Function (Def_Id) then
10250 Set_Has_Pragma_Pure_Function (Def_Id);
10255 exit when No (E) or else Scope (E) /= Current_Scope;
10259 and then Warn_On_Redundant_Constructs
10261 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10267 --------------------
10268 -- Queuing_Policy --
10269 --------------------
10271 -- pragma Queuing_Policy (policy_IDENTIFIER);
10273 when Pragma_Queuing_Policy => declare
10277 Check_Ada_83_Warning;
10278 Check_Arg_Count (1);
10279 Check_No_Identifiers;
10280 Check_Arg_Is_Queuing_Policy (Arg1);
10281 Check_Valid_Configuration_Pragma;
10282 Get_Name_String (Chars (Expression (Arg1)));
10283 QP := Fold_Upper (Name_Buffer (1));
10285 if Queuing_Policy /= ' '
10286 and then Queuing_Policy /= QP
10288 Error_Msg_Sloc := Queuing_Policy_Sloc;
10289 Error_Pragma ("queuing policy incompatible with policy#");
10291 -- Set new policy, but always preserve System_Location since
10292 -- we like the error message with the run time name.
10295 Queuing_Policy := QP;
10297 if Queuing_Policy_Sloc /= System_Location then
10298 Queuing_Policy_Sloc := Loc;
10303 -----------------------
10304 -- Relative_Deadline --
10305 -----------------------
10307 -- pragma Relative_Deadline (time_span_EXPRESSION);
10309 when Pragma_Relative_Deadline => Relative_Deadline : declare
10310 P : constant Node_Id := Parent (N);
10315 Check_No_Identifiers;
10316 Check_Arg_Count (1);
10318 Arg := Expression (Arg1);
10320 -- The expression must be analyzed in the special manner described
10321 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10323 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10327 if Nkind (P) = N_Subprogram_Body then
10328 Check_In_Main_Program;
10332 elsif Nkind (P) = N_Task_Definition then
10335 -- Anything else is incorrect
10341 if Has_Relative_Deadline_Pragma (P) then
10342 Error_Pragma ("duplicate pragma% not allowed");
10344 Set_Has_Relative_Deadline_Pragma (P, True);
10346 if Nkind (P) = N_Task_Definition then
10347 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10350 end Relative_Deadline;
10352 ---------------------------
10353 -- Remote_Call_Interface --
10354 ---------------------------
10356 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10358 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10359 Cunit_Node : Node_Id;
10360 Cunit_Ent : Entity_Id;
10364 Check_Ada_83_Warning;
10365 Check_Valid_Library_Unit_Pragma;
10367 if Nkind (N) = N_Null_Statement then
10371 Cunit_Node := Cunit (Current_Sem_Unit);
10372 K := Nkind (Unit (Cunit_Node));
10373 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10375 if K = N_Package_Declaration
10376 or else K = N_Generic_Package_Declaration
10377 or else K = N_Subprogram_Declaration
10378 or else K = N_Generic_Subprogram_Declaration
10379 or else (K = N_Subprogram_Body
10380 and then Acts_As_Spec (Unit (Cunit_Node)))
10385 "pragma% must apply to package or subprogram declaration");
10388 Set_Is_Remote_Call_Interface (Cunit_Ent);
10389 end Remote_Call_Interface;
10395 -- pragma Remote_Types [(library_unit_NAME)];
10397 when Pragma_Remote_Types => Remote_Types : declare
10398 Cunit_Node : Node_Id;
10399 Cunit_Ent : Entity_Id;
10402 Check_Ada_83_Warning;
10403 Check_Valid_Library_Unit_Pragma;
10405 if Nkind (N) = N_Null_Statement then
10409 Cunit_Node := Cunit (Current_Sem_Unit);
10410 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10412 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
10414 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
10417 "pragma% can only apply to a package declaration");
10420 Set_Is_Remote_Types (Cunit_Ent);
10427 -- pragma Ravenscar;
10429 when Pragma_Ravenscar =>
10431 Check_Arg_Count (0);
10432 Check_Valid_Configuration_Pragma;
10433 Set_Ravenscar_Profile (N);
10435 if Warn_On_Obsolescent_Feature then
10437 ("pragma Ravenscar is an obsolescent feature?", N);
10439 ("|use pragma Profile (Ravenscar) instead", N);
10442 -------------------------
10443 -- Restricted_Run_Time --
10444 -------------------------
10446 -- pragma Restricted_Run_Time;
10448 when Pragma_Restricted_Run_Time =>
10450 Check_Arg_Count (0);
10451 Check_Valid_Configuration_Pragma;
10452 Set_Profile_Restrictions
10453 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10455 if Warn_On_Obsolescent_Feature then
10457 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10459 ("|use pragma Profile (Restricted) instead", N);
10466 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10469 -- restriction_IDENTIFIER
10470 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10472 when Pragma_Restrictions =>
10473 Process_Restrictions_Or_Restriction_Warnings
10474 (Warn => Treat_Restrictions_As_Warnings);
10476 --------------------------
10477 -- Restriction_Warnings --
10478 --------------------------
10480 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10483 -- restriction_IDENTIFIER
10484 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10486 when Pragma_Restriction_Warnings =>
10488 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10494 -- pragma Reviewable;
10496 when Pragma_Reviewable =>
10497 Check_Ada_83_Warning;
10498 Check_Arg_Count (0);
10501 -------------------
10502 -- Share_Generic --
10503 -------------------
10505 -- pragma Share_Generic (NAME {, NAME});
10507 when Pragma_Share_Generic =>
10509 Process_Generic_List;
10515 -- pragma Shared (LOCAL_NAME);
10517 when Pragma_Shared =>
10519 Process_Atomic_Shared_Volatile;
10521 --------------------
10522 -- Shared_Passive --
10523 --------------------
10525 -- pragma Shared_Passive [(library_unit_NAME)];
10527 -- Set the flag Is_Shared_Passive of program unit name entity
10529 when Pragma_Shared_Passive => Shared_Passive : declare
10530 Cunit_Node : Node_Id;
10531 Cunit_Ent : Entity_Id;
10534 Check_Ada_83_Warning;
10535 Check_Valid_Library_Unit_Pragma;
10537 if Nkind (N) = N_Null_Statement then
10541 Cunit_Node := Cunit (Current_Sem_Unit);
10542 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10544 if Nkind (Unit (Cunit_Node)) /= N_Package_Declaration
10546 Nkind (Unit (Cunit_Node)) /= N_Generic_Package_Declaration
10549 "pragma% can only apply to a package declaration");
10552 Set_Is_Shared_Passive (Cunit_Ent);
10553 end Shared_Passive;
10555 ----------------------
10556 -- Source_File_Name --
10557 ----------------------
10559 -- There are five forms for this pragma:
10561 -- pragma Source_File_Name (
10562 -- [UNIT_NAME =>] unit_NAME,
10563 -- BODY_FILE_NAME => STRING_LITERAL
10564 -- [, [INDEX =>] INTEGER_LITERAL]);
10566 -- pragma Source_File_Name (
10567 -- [UNIT_NAME =>] unit_NAME,
10568 -- SPEC_FILE_NAME => STRING_LITERAL
10569 -- [, [INDEX =>] INTEGER_LITERAL]);
10571 -- pragma Source_File_Name (
10572 -- BODY_FILE_NAME => STRING_LITERAL
10573 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10574 -- [, CASING => CASING_SPEC]);
10576 -- pragma Source_File_Name (
10577 -- SPEC_FILE_NAME => STRING_LITERAL
10578 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10579 -- [, CASING => CASING_SPEC]);
10581 -- pragma Source_File_Name (
10582 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10583 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10584 -- [, CASING => CASING_SPEC]);
10586 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10588 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10589 -- Source_File_Name (SFN), however their usage is exclusive:
10590 -- SFN can only be used when no project file is used, while
10591 -- SFNP can only be used when a project file is used.
10593 -- No processing here. Processing was completed during parsing,
10594 -- since we need to have file names set as early as possible.
10595 -- Units are loaded well before semantic processing starts.
10597 -- The only processing we defer to this point is the check
10598 -- for correct placement.
10600 when Pragma_Source_File_Name =>
10602 Check_Valid_Configuration_Pragma;
10604 ------------------------------
10605 -- Source_File_Name_Project --
10606 ------------------------------
10608 -- See Source_File_Name for syntax
10610 -- No processing here. Processing was completed during parsing,
10611 -- since we need to have file names set as early as possible.
10612 -- Units are loaded well before semantic processing starts.
10614 -- The only processing we defer to this point is the check
10615 -- for correct placement.
10617 when Pragma_Source_File_Name_Project =>
10619 Check_Valid_Configuration_Pragma;
10621 -- Check that a pragma Source_File_Name_Project is used only
10622 -- in a configuration pragmas file.
10624 -- Pragmas Source_File_Name_Project should only be generated
10625 -- by the Project Manager in configuration pragmas files.
10627 -- This is really an ugly test. It seems to depend on some
10628 -- accidental and undocumented property. At the very least
10629 -- it needs to be documented, but it would be better to have
10630 -- a clean way of testing if we are in a configuration file???
10632 if Present (Parent (N)) then
10634 ("pragma% can only appear in a configuration pragmas file");
10637 ----------------------
10638 -- Source_Reference --
10639 ----------------------
10641 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10643 -- Nothing to do, all processing completed in Par.Prag, since we
10644 -- need the information for possible parser messages that are output
10646 when Pragma_Source_Reference =>
10649 --------------------------------
10650 -- Static_Elaboration_Desired --
10651 --------------------------------
10653 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10655 when Pragma_Static_Elaboration_Desired =>
10657 Check_At_Most_N_Arguments (1);
10659 if Is_Compilation_Unit (Current_Scope)
10660 and then Ekind (Current_Scope) = E_Package
10662 Set_Static_Elaboration_Desired (Current_Scope, True);
10664 Error_Pragma ("pragma% must apply to a library-level package");
10671 -- pragma Storage_Size (EXPRESSION);
10673 when Pragma_Storage_Size => Storage_Size : declare
10674 P : constant Node_Id := Parent (N);
10678 Check_No_Identifiers;
10679 Check_Arg_Count (1);
10681 -- The expression must be analyzed in the special manner described
10682 -- in "Handling of Default Expressions" in sem.ads.
10684 Arg := Expression (Arg1);
10685 Preanalyze_Spec_Expression (Arg, Any_Integer);
10687 if not Is_Static_Expression (Arg) then
10688 Check_Restriction (Static_Storage_Size, Arg);
10691 if Nkind (P) /= N_Task_Definition then
10696 if Has_Storage_Size_Pragma (P) then
10697 Error_Pragma ("duplicate pragma% not allowed");
10699 Set_Has_Storage_Size_Pragma (P, True);
10702 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10703 -- ??? exp_ch9 should use this!
10711 -- pragma Storage_Unit (NUMERIC_LITERAL);
10713 -- Only permitted argument is System'Storage_Unit value
10715 when Pragma_Storage_Unit =>
10716 Check_No_Identifiers;
10717 Check_Arg_Count (1);
10718 Check_Arg_Is_Integer_Literal (Arg1);
10720 if Intval (Expression (Arg1)) /=
10721 UI_From_Int (Ttypes.System_Storage_Unit)
10723 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10725 ("the only allowed argument for pragma% is ^", Arg1);
10728 --------------------
10729 -- Stream_Convert --
10730 --------------------
10732 -- pragma Stream_Convert (
10733 -- [Entity =>] type_LOCAL_NAME,
10734 -- [Read =>] function_NAME,
10735 -- [Write =>] function NAME);
10737 when Pragma_Stream_Convert => Stream_Convert : declare
10739 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10740 -- Check that the given argument is the name of a local
10741 -- function of one argument that is not overloaded earlier
10742 -- in the current local scope. A check is also made that the
10743 -- argument is a function with one parameter.
10745 --------------------------------------
10746 -- Check_OK_Stream_Convert_Function --
10747 --------------------------------------
10749 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10753 Check_Arg_Is_Local_Name (Arg);
10754 Ent := Entity (Expression (Arg));
10756 if Has_Homonym (Ent) then
10758 ("argument for pragma% may not be overloaded", Arg);
10761 if Ekind (Ent) /= E_Function
10762 or else No (First_Formal (Ent))
10763 or else Present (Next_Formal (First_Formal (Ent)))
10766 ("argument for pragma% must be" &
10767 " function of one argument", Arg);
10769 end Check_OK_Stream_Convert_Function;
10771 -- Start of processing for Stream_Convert
10775 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10776 Check_Arg_Count (3);
10777 Check_Optional_Identifier (Arg1, Name_Entity);
10778 Check_Optional_Identifier (Arg2, Name_Read);
10779 Check_Optional_Identifier (Arg3, Name_Write);
10780 Check_Arg_Is_Local_Name (Arg1);
10781 Check_OK_Stream_Convert_Function (Arg2);
10782 Check_OK_Stream_Convert_Function (Arg3);
10785 Typ : constant Entity_Id :=
10786 Underlying_Type (Entity (Expression (Arg1)));
10787 Read : constant Entity_Id := Entity (Expression (Arg2));
10788 Write : constant Entity_Id := Entity (Expression (Arg3));
10791 Check_First_Subtype (Arg1);
10793 -- Check for too early or too late. Note that we don't enforce
10794 -- the rule about primitive operations in this case, since, as
10795 -- is the case for explicit stream attributes themselves, these
10796 -- restrictions are not appropriate. Note that the chaining of
10797 -- the pragma by Rep_Item_Too_Late is actually the critical
10798 -- processing done for this pragma.
10800 if Rep_Item_Too_Early (Typ, N)
10802 Rep_Item_Too_Late (Typ, N, FOnly => True)
10807 -- Return if previous error
10809 if Etype (Typ) = Any_Type
10811 Etype (Read) = Any_Type
10813 Etype (Write) = Any_Type
10820 if Underlying_Type (Etype (Read)) /= Typ then
10822 ("incorrect return type for function&", Arg2);
10825 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
10827 ("incorrect parameter type for function&", Arg3);
10830 if Underlying_Type (Etype (First_Formal (Read))) /=
10831 Underlying_Type (Etype (Write))
10834 ("result type of & does not match Read parameter type",
10838 end Stream_Convert;
10840 -------------------------
10841 -- Style_Checks (GNAT) --
10842 -------------------------
10844 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10846 -- This is processed by the parser since some of the style
10847 -- checks take place during source scanning and parsing. This
10848 -- means that we don't need to issue error messages here.
10850 when Pragma_Style_Checks => Style_Checks : declare
10851 A : constant Node_Id := Expression (Arg1);
10857 Check_No_Identifiers;
10859 -- Two argument form
10861 if Arg_Count = 2 then
10862 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10869 E_Id := Expression (Arg2);
10872 if not Is_Entity_Name (E_Id) then
10874 ("second argument of pragma% must be entity name",
10878 E := Entity (E_Id);
10884 Set_Suppress_Style_Checks (E,
10885 (Chars (Expression (Arg1)) = Name_Off));
10886 exit when No (Homonym (E));
10892 -- One argument form
10895 Check_Arg_Count (1);
10897 if Nkind (A) = N_String_Literal then
10901 Slen : constant Natural := Natural (String_Length (S));
10902 Options : String (1 .. Slen);
10908 C := Get_String_Char (S, Int (J));
10909 exit when not In_Character_Range (C);
10910 Options (J) := Get_Character (C);
10912 -- If at end of string, set options. As per discussion
10913 -- above, no need to check for errors, since we issued
10914 -- them in the parser.
10917 Set_Style_Check_Options (Options);
10925 elsif Nkind (A) = N_Identifier then
10926 if Chars (A) = Name_All_Checks then
10927 Set_Default_Style_Check_Options;
10929 elsif Chars (A) = Name_On then
10930 Style_Check := True;
10932 elsif Chars (A) = Name_Off then
10933 Style_Check := False;
10943 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
10945 when Pragma_Subtitle =>
10947 Check_Arg_Count (1);
10948 Check_Optional_Identifier (Arg1, Name_Subtitle);
10949 Check_Arg_Is_String_Literal (Arg1);
10955 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
10957 when Pragma_Suppress =>
10958 Process_Suppress_Unsuppress (True);
10964 -- pragma Suppress_All;
10966 -- The only check made here is that the pragma appears in the
10967 -- proper place, i.e. following a compilation unit. If indeed
10968 -- it appears in this context, then the parser has already
10969 -- inserted an equivalent pragma Suppress (All_Checks) to get
10970 -- the required effect.
10972 when Pragma_Suppress_All =>
10974 Check_Arg_Count (0);
10976 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
10977 or else not Is_List_Member (N)
10978 or else List_Containing (N) /= Pragmas_After (Parent (N))
10981 ("misplaced pragma%, must follow compilation unit");
10984 -------------------------
10985 -- Suppress_Debug_Info --
10986 -------------------------
10988 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
10990 when Pragma_Suppress_Debug_Info =>
10992 Check_Arg_Count (1);
10993 Check_Optional_Identifier (Arg1, Name_Entity);
10994 Check_Arg_Is_Local_Name (Arg1);
10995 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
10997 ----------------------------------
10998 -- Suppress_Exception_Locations --
10999 ----------------------------------
11001 -- pragma Suppress_Exception_Locations;
11003 when Pragma_Suppress_Exception_Locations =>
11005 Check_Arg_Count (0);
11006 Check_Valid_Configuration_Pragma;
11007 Exception_Locations_Suppressed := True;
11009 -----------------------------
11010 -- Suppress_Initialization --
11011 -----------------------------
11013 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11015 when Pragma_Suppress_Initialization => Suppress_Init : declare
11021 Check_Arg_Count (1);
11022 Check_Optional_Identifier (Arg1, Name_Entity);
11023 Check_Arg_Is_Local_Name (Arg1);
11025 E_Id := Expression (Arg1);
11027 if Etype (E_Id) = Any_Type then
11031 E := Entity (E_Id);
11033 if Is_Type (E) then
11034 if Is_Incomplete_Or_Private_Type (E) then
11035 if No (Full_View (Base_Type (E))) then
11037 ("argument of pragma% cannot be an incomplete type",
11040 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11043 Set_Suppress_Init_Proc (Base_Type (E));
11048 ("pragma% requires argument that is a type name", Arg1);
11056 -- pragma System_Name (DIRECT_NAME);
11058 -- Syntax check: one argument, which must be the identifier GNAT
11059 -- or the identifier GCC, no other identifiers are acceptable.
11061 when Pragma_System_Name =>
11063 Check_No_Identifiers;
11064 Check_Arg_Count (1);
11065 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11067 -----------------------------
11068 -- Task_Dispatching_Policy --
11069 -----------------------------
11071 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11073 when Pragma_Task_Dispatching_Policy => declare
11077 Check_Ada_83_Warning;
11078 Check_Arg_Count (1);
11079 Check_No_Identifiers;
11080 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11081 Check_Valid_Configuration_Pragma;
11082 Get_Name_String (Chars (Expression (Arg1)));
11083 DP := Fold_Upper (Name_Buffer (1));
11085 if Task_Dispatching_Policy /= ' '
11086 and then Task_Dispatching_Policy /= DP
11088 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11090 ("task dispatching policy incompatible with policy#");
11092 -- Set new policy, but always preserve System_Location since
11093 -- we like the error message with the run time name.
11096 Task_Dispatching_Policy := DP;
11098 if Task_Dispatching_Policy_Sloc /= System_Location then
11099 Task_Dispatching_Policy_Sloc := Loc;
11108 -- pragma Task_Info (EXPRESSION);
11110 when Pragma_Task_Info => Task_Info : declare
11111 P : constant Node_Id := Parent (N);
11116 if Nkind (P) /= N_Task_Definition then
11117 Error_Pragma ("pragma% must appear in task definition");
11120 Check_No_Identifiers;
11121 Check_Arg_Count (1);
11123 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11125 if Etype (Expression (Arg1)) = Any_Type then
11129 if Has_Task_Info_Pragma (P) then
11130 Error_Pragma ("duplicate pragma% not allowed");
11132 Set_Has_Task_Info_Pragma (P, True);
11140 -- pragma Task_Name (string_EXPRESSION);
11142 when Pragma_Task_Name => Task_Name : declare
11143 P : constant Node_Id := Parent (N);
11147 Check_No_Identifiers;
11148 Check_Arg_Count (1);
11150 Arg := Expression (Arg1);
11151 Analyze_And_Resolve (Arg, Standard_String);
11153 if Nkind (P) /= N_Task_Definition then
11157 if Has_Task_Name_Pragma (P) then
11158 Error_Pragma ("duplicate pragma% not allowed");
11160 Set_Has_Task_Name_Pragma (P, True);
11161 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11169 -- pragma Task_Storage (
11170 -- [Task_Type =>] LOCAL_NAME,
11171 -- [Top_Guard =>] static_integer_EXPRESSION);
11173 when Pragma_Task_Storage => Task_Storage : declare
11174 Args : Args_List (1 .. 2);
11175 Names : constant Name_List (1 .. 2) := (
11179 Task_Type : Node_Id renames Args (1);
11180 Top_Guard : Node_Id renames Args (2);
11186 Gather_Associations (Names, Args);
11188 if No (Task_Type) then
11190 ("missing task_type argument for pragma%");
11193 Check_Arg_Is_Local_Name (Task_Type);
11195 Ent := Entity (Task_Type);
11197 if not Is_Task_Type (Ent) then
11199 ("argument for pragma% must be task type", Task_Type);
11202 if No (Top_Guard) then
11204 ("pragma% takes two arguments", Task_Type);
11206 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11209 Check_First_Subtype (Task_Type);
11211 if Rep_Item_Too_Late (Ent, N) then
11220 -- pragma Time_Slice (static_duration_EXPRESSION);
11222 when Pragma_Time_Slice => Time_Slice : declare
11228 Check_Arg_Count (1);
11229 Check_No_Identifiers;
11230 Check_In_Main_Program;
11231 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11233 if not Error_Posted (Arg1) then
11235 while Present (Nod) loop
11236 if Nkind (Nod) = N_Pragma
11237 and then Pragma_Name (Nod) = Name_Time_Slice
11239 Error_Msg_Name_1 := Pname;
11240 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11247 -- Process only if in main unit
11249 if Get_Source_Unit (Loc) = Main_Unit then
11250 Opt.Time_Slice_Set := True;
11251 Val := Expr_Value_R (Expression (Arg1));
11253 if Val <= Ureal_0 then
11254 Opt.Time_Slice_Value := 0;
11256 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11257 Opt.Time_Slice_Value := 1_000_000_000;
11260 Opt.Time_Slice_Value :=
11261 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11270 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11272 -- TITLING_OPTION ::=
11273 -- [Title =>] STRING_LITERAL
11274 -- | [Subtitle =>] STRING_LITERAL
11276 when Pragma_Title => Title : declare
11277 Args : Args_List (1 .. 2);
11278 Names : constant Name_List (1 .. 2) := (
11284 Gather_Associations (Names, Args);
11286 for J in 1 .. 2 loop
11287 if Present (Args (J)) then
11288 Check_Arg_Is_String_Literal (Args (J));
11293 ---------------------
11294 -- Unchecked_Union --
11295 ---------------------
11297 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11299 when Pragma_Unchecked_Union => Unchecked_Union : declare
11300 Assoc : constant Node_Id := Arg1;
11301 Type_Id : constant Node_Id := Expression (Assoc);
11312 Check_No_Identifiers;
11313 Check_Arg_Count (1);
11314 Check_Arg_Is_Local_Name (Arg1);
11316 Find_Type (Type_Id);
11317 Typ := Entity (Type_Id);
11320 or else Rep_Item_Too_Early (Typ, N)
11324 Typ := Underlying_Type (Typ);
11327 if Rep_Item_Too_Late (Typ, N) then
11331 Check_First_Subtype (Arg1);
11333 -- Note remaining cases are references to a type in the current
11334 -- declarative part. If we find an error, we post the error on
11335 -- the relevant type declaration at an appropriate point.
11337 if not Is_Record_Type (Typ) then
11338 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11341 elsif Is_Tagged_Type (Typ) then
11342 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11345 elsif Is_Limited_Type (Typ) then
11347 ("Unchecked_Union must not be limited record type", Typ);
11348 Explain_Limited_Type (Typ, Typ);
11352 if not Has_Discriminants (Typ) then
11354 ("Unchecked_Union must have one discriminant", Typ);
11358 Discr := First_Discriminant (Typ);
11359 while Present (Discr) loop
11360 if No (Discriminant_Default_Value (Discr)) then
11362 ("Unchecked_Union discriminant must have default value",
11365 Next_Discriminant (Discr);
11368 Tdef := Type_Definition (Declaration_Node (Typ));
11369 Clist := Component_List (Tdef);
11371 Comp := First (Component_Items (Clist));
11372 while Present (Comp) loop
11373 Check_Component (Comp);
11377 if No (Clist) or else No (Variant_Part (Clist)) then
11379 ("Unchecked_Union must have variant part",
11384 Vpart := Variant_Part (Clist);
11386 Variant := First (Variants (Vpart));
11387 while Present (Variant) loop
11388 Check_Variant (Variant);
11393 Set_Is_Unchecked_Union (Typ, True);
11394 Set_Convention (Typ, Convention_C);
11396 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11397 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11398 end Unchecked_Union;
11400 ------------------------
11401 -- Unimplemented_Unit --
11402 ------------------------
11404 -- pragma Unimplemented_Unit;
11406 -- Note: this only gives an error if we are generating code,
11407 -- or if we are in a generic library unit (where the pragma
11408 -- appears in the body, not in the spec).
11410 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11411 Cunitent : constant Entity_Id :=
11412 Cunit_Entity (Get_Source_Unit (Loc));
11413 Ent_Kind : constant Entity_Kind :=
11418 Check_Arg_Count (0);
11420 if Operating_Mode = Generate_Code
11421 or else Ent_Kind = E_Generic_Function
11422 or else Ent_Kind = E_Generic_Procedure
11423 or else Ent_Kind = E_Generic_Package
11425 Get_Name_String (Chars (Cunitent));
11426 Set_Casing (Mixed_Case);
11427 Write_Str (Name_Buffer (1 .. Name_Len));
11428 Write_Str (" is not supported in this configuration");
11430 raise Unrecoverable_Error;
11432 end Unimplemented_Unit;
11434 ------------------------
11435 -- Universal_Aliasing --
11436 ------------------------
11438 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11440 when Pragma_Universal_Aliasing => Universal_Alias : declare
11445 Check_Arg_Count (1);
11446 Check_Optional_Identifier (Arg2, Name_Entity);
11447 Check_Arg_Is_Local_Name (Arg1);
11448 E_Id := Entity (Expression (Arg1));
11450 if E_Id = Any_Type then
11452 elsif No (E_Id) or else not Is_Type (E_Id) then
11453 Error_Pragma_Arg ("pragma% requires type", Arg1);
11456 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11457 end Universal_Alias;
11459 --------------------
11460 -- Universal_Data --
11461 --------------------
11463 -- pragma Universal_Data [(library_unit_NAME)];
11465 when Pragma_Universal_Data =>
11468 -- If this is a configuration pragma, then set the universal
11469 -- addressing option, otherwise confirm that the pragma
11470 -- satisfies the requirements of library unit pragma placement
11471 -- and leave it to the GNAAMP back end to detect the pragma
11472 -- (avoids transitive setting of the option due to withed units).
11474 if Is_Configuration_Pragma then
11475 Universal_Addressing_On_AAMP := True;
11477 Check_Valid_Library_Unit_Pragma;
11480 if not AAMP_On_Target then
11481 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11488 -- pragma Unmodified (local_Name {, local_Name});
11490 when Pragma_Unmodified => Unmodified : declare
11491 Arg_Node : Node_Id;
11492 Arg_Expr : Node_Id;
11493 Arg_Ent : Entity_Id;
11497 Check_At_Least_N_Arguments (1);
11499 -- Loop through arguments
11502 while Present (Arg_Node) loop
11503 Check_No_Identifier (Arg_Node);
11505 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11506 -- will in fact generate reference, so that the entity will
11507 -- have a reference, which will inhibit any warnings about
11508 -- it not being referenced, and also properly show up in the
11509 -- ali file as a reference. But this reference is recorded
11510 -- before the Has_Pragma_Unreferenced flag is set, so that
11511 -- no warning is generated for this reference.
11513 Check_Arg_Is_Local_Name (Arg_Node);
11514 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11516 if Is_Entity_Name (Arg_Expr) then
11517 Arg_Ent := Entity (Arg_Expr);
11519 if not Is_Assignable (Arg_Ent) then
11521 ("pragma% can only be applied to a variable",
11524 Set_Has_Pragma_Unmodified (Arg_Ent);
11536 -- pragma Unreferenced (local_Name {, local_Name});
11538 -- or when used in a context clause:
11540 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11542 when Pragma_Unreferenced => Unreferenced : declare
11543 Arg_Node : Node_Id;
11544 Arg_Expr : Node_Id;
11545 Arg_Ent : Entity_Id;
11550 Check_At_Least_N_Arguments (1);
11552 -- Check case of appearing within context clause
11554 if Is_In_Context_Clause then
11556 -- The arguments must all be units mentioned in a with clause
11557 -- in the same context clause. Note we already checked (in
11558 -- Par.Prag) that the arguments are either identifiers or
11559 -- selected components.
11562 while Present (Arg_Node) loop
11563 Citem := First (List_Containing (N));
11564 while Citem /= N loop
11565 if Nkind (Citem) = N_With_Clause
11566 and then Same_Name (Name (Citem), Expression (Arg_Node))
11568 Set_Has_Pragma_Unreferenced
11571 (Library_Unit (Citem))));
11572 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11581 ("argument of pragma% is not with'ed unit", Arg_Node);
11587 -- Case of not in list of context items
11591 while Present (Arg_Node) loop
11592 Check_No_Identifier (Arg_Node);
11594 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11595 -- will in fact generate reference, so that the entity will
11596 -- have a reference, which will inhibit any warnings about
11597 -- it not being referenced, and also properly show up in the
11598 -- ali file as a reference. But this reference is recorded
11599 -- before the Has_Pragma_Unreferenced flag is set, so that
11600 -- no warning is generated for this reference.
11602 Check_Arg_Is_Local_Name (Arg_Node);
11603 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11605 if Is_Entity_Name (Arg_Expr) then
11606 Arg_Ent := Entity (Arg_Expr);
11608 -- If the entity is overloaded, the pragma applies to the
11609 -- most recent overloading, as documented. In this case,
11610 -- name resolution does not generate a reference, so it
11611 -- must be done here explicitly.
11613 if Is_Overloaded (Arg_Expr) then
11614 Generate_Reference (Arg_Ent, N);
11617 Set_Has_Pragma_Unreferenced (Arg_Ent);
11625 --------------------------
11626 -- Unreferenced_Objects --
11627 --------------------------
11629 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11631 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11632 Arg_Node : Node_Id;
11633 Arg_Expr : Node_Id;
11637 Check_At_Least_N_Arguments (1);
11640 while Present (Arg_Node) loop
11641 Check_No_Identifier (Arg_Node);
11642 Check_Arg_Is_Local_Name (Arg_Node);
11643 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11645 if not Is_Entity_Name (Arg_Expr)
11646 or else not Is_Type (Entity (Arg_Expr))
11649 ("argument for pragma% must be type or subtype", Arg_Node);
11652 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11655 end Unreferenced_Objects;
11657 ------------------------------
11658 -- Unreserve_All_Interrupts --
11659 ------------------------------
11661 -- pragma Unreserve_All_Interrupts;
11663 when Pragma_Unreserve_All_Interrupts =>
11665 Check_Arg_Count (0);
11667 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11668 Unreserve_All_Interrupts := True;
11675 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11677 when Pragma_Unsuppress =>
11679 Process_Suppress_Unsuppress (False);
11681 -------------------
11682 -- Use_VADS_Size --
11683 -------------------
11685 -- pragma Use_VADS_Size;
11687 when Pragma_Use_VADS_Size =>
11689 Check_Arg_Count (0);
11690 Check_Valid_Configuration_Pragma;
11691 Use_VADS_Size := True;
11693 ---------------------
11694 -- Validity_Checks --
11695 ---------------------
11697 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11699 when Pragma_Validity_Checks => Validity_Checks : declare
11700 A : constant Node_Id := Expression (Arg1);
11706 Check_Arg_Count (1);
11707 Check_No_Identifiers;
11709 if Nkind (A) = N_String_Literal then
11713 Slen : constant Natural := Natural (String_Length (S));
11714 Options : String (1 .. Slen);
11720 C := Get_String_Char (S, Int (J));
11721 exit when not In_Character_Range (C);
11722 Options (J) := Get_Character (C);
11725 Set_Validity_Check_Options (Options);
11733 elsif Nkind (A) = N_Identifier then
11735 if Chars (A) = Name_All_Checks then
11736 Set_Validity_Check_Options ("a");
11738 elsif Chars (A) = Name_On then
11739 Validity_Checks_On := True;
11741 elsif Chars (A) = Name_Off then
11742 Validity_Checks_On := False;
11746 end Validity_Checks;
11752 -- pragma Volatile (LOCAL_NAME);
11754 when Pragma_Volatile =>
11755 Process_Atomic_Shared_Volatile;
11757 -------------------------
11758 -- Volatile_Components --
11759 -------------------------
11761 -- pragma Volatile_Components (array_LOCAL_NAME);
11763 -- Volatile is handled by the same circuit as Atomic_Components
11769 -- pragma Warnings (On | Off);
11770 -- pragma Warnings (On | Off, LOCAL_NAME);
11771 -- pragma Warnings (static_string_EXPRESSION);
11772 -- pragma Warnings (On | Off, STRING_LITERAL);
11774 when Pragma_Warnings => Warnings : begin
11776 Check_At_Least_N_Arguments (1);
11777 Check_No_Identifiers;
11780 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11783 -- One argument case
11785 if Arg_Count = 1 then
11787 -- On/Off one argument case was processed by parser
11789 if Nkind (Argx) = N_Identifier
11791 (Chars (Argx) = Name_On
11793 Chars (Argx) = Name_Off)
11797 -- One argument case must be ON/OFF or static string expr
11799 elsif not Is_Static_String_Expression (Arg1) then
11801 ("argument of pragma% must be On/Off or " &
11802 "static string expression", Arg2);
11804 -- One argument string expression case
11808 Lit : constant Node_Id := Expr_Value_S (Argx);
11809 Str : constant String_Id := Strval (Lit);
11810 Len : constant Nat := String_Length (Str);
11818 while J <= Len loop
11819 C := Get_String_Char (Str, J);
11820 OK := In_Character_Range (C);
11823 Chr := Get_Character (C);
11827 if J < Len and then Chr = '.' then
11829 C := Get_String_Char (Str, J);
11830 Chr := Get_Character (C);
11832 if not Set_Dot_Warning_Switch (Chr) then
11834 ("invalid warning switch character " &
11841 OK := Set_Warning_Switch (Chr);
11847 ("invalid warning switch character " & Chr,
11856 -- Two or more arguments (must be two)
11859 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11860 Check_At_Most_N_Arguments (2);
11868 E_Id := Expression (Arg2);
11871 -- In the expansion of an inlined body, a reference to
11872 -- the formal may be wrapped in a conversion if the
11873 -- actual is a conversion. Retrieve the real entity name.
11875 if (In_Instance_Body
11876 or else In_Inlined_Body)
11877 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
11879 E_Id := Expression (E_Id);
11882 -- Entity name case
11884 if Is_Entity_Name (E_Id) then
11885 E := Entity (E_Id);
11892 (E, (Chars (Expression (Arg1)) = Name_Off));
11894 if Chars (Expression (Arg1)) = Name_Off
11895 and then Warn_On_Warnings_Off
11897 Warnings_Off_Pragmas.Append ((N, E));
11900 if Is_Enumeration_Type (E) then
11904 Lit := First_Literal (E);
11905 while Present (Lit) loop
11906 Set_Warnings_Off (Lit);
11907 Next_Literal (Lit);
11912 exit when No (Homonym (E));
11917 -- Error if not entity or static string literal case
11919 elsif not Is_Static_String_Expression (Arg2) then
11921 ("second argument of pragma% must be entity " &
11922 "name or static string expression", Arg2);
11924 -- String literal case
11927 String_To_Name_Buffer
11928 (Strval (Expr_Value_S (Expression (Arg2))));
11930 -- Note on configuration pragma case: If this is a
11931 -- configuration pragma, then for an OFF pragma, we
11932 -- just set Config True in the call, which is all
11933 -- that needs to be done. For the case of ON, this
11934 -- is normally an error, unless it is canceling the
11935 -- effect of a previous OFF pragma in the same file.
11936 -- In any other case, an error will be signalled (ON
11937 -- with no matching OFF).
11939 if Chars (Argx) = Name_Off then
11940 Set_Specific_Warning_Off
11941 (Loc, Name_Buffer (1 .. Name_Len),
11942 Config => Is_Configuration_Pragma);
11944 elsif Chars (Argx) = Name_On then
11945 Set_Specific_Warning_On
11946 (Loc, Name_Buffer (1 .. Name_Len), Err);
11950 ("?pragma Warnings On with no " &
11951 "matching Warnings Off",
11961 -------------------
11962 -- Weak_External --
11963 -------------------
11965 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
11967 when Pragma_Weak_External => Weak_External : declare
11972 Check_Arg_Count (1);
11973 Check_Optional_Identifier (Arg1, Name_Entity);
11974 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11975 Ent := Entity (Expression (Arg1));
11977 if Rep_Item_Too_Early (Ent, N) then
11980 Ent := Underlying_Type (Ent);
11983 -- The only processing required is to link this item on to the
11984 -- list of rep items for the given entity. This is accomplished
11985 -- by the call to Rep_Item_Too_Late (when no error is detected
11986 -- and False is returned).
11988 if Rep_Item_Too_Late (Ent, N) then
11991 Set_Has_Gigi_Rep_Item (Ent);
11995 -----------------------------
11996 -- Wide_Character_Encoding --
11997 -----------------------------
11999 -- pragma Wide_Character_Encoding (IDENTIFIER);
12001 when Pragma_Wide_Character_Encoding =>
12004 -- Nothing to do, handled in parser. Note that we do not enforce
12005 -- configuration pragma placement, this pragma can appear at any
12006 -- place in the source, allowing mixed encodings within a single
12011 --------------------
12012 -- Unknown_Pragma --
12013 --------------------
12015 -- Should be impossible, since the case of an unknown pragma is
12016 -- separately processed before the case statement is entered.
12018 when Unknown_Pragma =>
12019 raise Program_Error;
12023 when Pragma_Exit => null;
12024 end Analyze_Pragma;
12026 -------------------
12027 -- Check_Enabled --
12028 -------------------
12030 function Check_Enabled (Nam : Name_Id) return Boolean is
12034 PP := Opt.Check_Policy_List;
12037 return Assertions_Enabled;
12040 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12043 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12045 when Name_On | Name_Check =>
12047 when Name_Off | Name_Ignore =>
12050 raise Program_Error;
12054 PP := Next_Pragma (PP);
12059 ---------------------------------
12060 -- Delay_Config_Pragma_Analyze --
12061 ---------------------------------
12063 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12065 return Pragma_Name (N) = Name_Interrupt_State
12067 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12068 end Delay_Config_Pragma_Analyze;
12070 -------------------------
12071 -- Get_Base_Subprogram --
12072 -------------------------
12074 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12075 Result : Entity_Id;
12078 -- Follow subprogram renaming chain
12081 while Is_Subprogram (Result)
12083 (Is_Generic_Instance (Result)
12084 or else Nkind (Parent (Declaration_Node (Result))) =
12085 N_Subprogram_Renaming_Declaration)
12086 and then Present (Alias (Result))
12088 Result := Alias (Result);
12092 end Get_Base_Subprogram;
12094 --------------------
12095 -- Get_Pragma_Arg --
12096 --------------------
12098 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12100 if Nkind (Arg) = N_Pragma_Argument_Association then
12101 return Expression (Arg);
12105 end Get_Pragma_Arg;
12111 procedure Initialize is
12116 -----------------------------
12117 -- Is_Config_Static_String --
12118 -----------------------------
12120 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12122 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12123 -- This is an internal recursive function that is just like the
12124 -- outer function except that it adds the string to the name buffer
12125 -- rather than placing the string in the name buffer.
12127 ------------------------------
12128 -- Add_Config_Static_String --
12129 ------------------------------
12131 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12138 if Nkind (N) = N_Op_Concat then
12139 if Add_Config_Static_String (Left_Opnd (N)) then
12140 N := Right_Opnd (N);
12146 if Nkind (N) /= N_String_Literal then
12147 Error_Msg_N ("string literal expected for pragma argument", N);
12151 for J in 1 .. String_Length (Strval (N)) loop
12152 C := Get_String_Char (Strval (N), J);
12154 if not In_Character_Range (C) then
12156 ("string literal contains invalid wide character",
12157 Sloc (N) + 1 + Source_Ptr (J));
12161 Add_Char_To_Name_Buffer (Get_Character (C));
12166 end Add_Config_Static_String;
12168 -- Start of processing for Is_Config_Static_String
12173 return Add_Config_Static_String (Arg);
12174 end Is_Config_Static_String;
12176 -----------------------------------------
12177 -- Is_Non_Significant_Pragma_Reference --
12178 -----------------------------------------
12180 -- This function makes use of the following static table which indicates
12181 -- whether a given pragma is significant. A value of -1 in this table
12182 -- indicates that the reference is significant. A value of zero indicates
12183 -- than appearance as any argument is insignificant, a positive value
12184 -- indicates that appearance in that parameter position is significant.
12186 -- A value of 99 flags a special case requiring a special check (this is
12187 -- used for cases not covered by this standard encoding, e.g. pragma Check
12188 -- where the first argument is not significant, but the others are).
12190 Sig_Flags : constant array (Pragma_Id) of Int :=
12191 (Pragma_AST_Entry => -1,
12192 Pragma_Abort_Defer => -1,
12193 Pragma_Ada_83 => -1,
12194 Pragma_Ada_95 => -1,
12195 Pragma_Ada_05 => -1,
12196 Pragma_Ada_2005 => -1,
12197 Pragma_All_Calls_Remote => -1,
12198 Pragma_Annotate => -1,
12199 Pragma_Assert => -1,
12200 Pragma_Assertion_Policy => 0,
12201 Pragma_Asynchronous => -1,
12202 Pragma_Atomic => 0,
12203 Pragma_Atomic_Components => 0,
12204 Pragma_Attach_Handler => -1,
12205 Pragma_Check => 99,
12206 Pragma_Check_Name => 0,
12207 Pragma_Check_Policy => 0,
12208 Pragma_CIL_Constructor => -1,
12209 Pragma_CPP_Class => 0,
12210 Pragma_CPP_Constructor => 0,
12211 Pragma_CPP_Virtual => 0,
12212 Pragma_CPP_Vtable => 0,
12213 Pragma_C_Pass_By_Copy => 0,
12214 Pragma_Comment => 0,
12215 Pragma_Common_Object => -1,
12216 Pragma_Compile_Time_Error => -1,
12217 Pragma_Compile_Time_Warning => -1,
12218 Pragma_Compiler_Unit => 0,
12219 Pragma_Complete_Representation => 0,
12220 Pragma_Complex_Representation => 0,
12221 Pragma_Component_Alignment => -1,
12222 Pragma_Controlled => 0,
12223 Pragma_Convention => 0,
12224 Pragma_Convention_Identifier => 0,
12225 Pragma_Debug => -1,
12226 Pragma_Debug_Policy => 0,
12227 Pragma_Detect_Blocking => -1,
12228 Pragma_Discard_Names => 0,
12229 Pragma_Elaborate => -1,
12230 Pragma_Elaborate_All => -1,
12231 Pragma_Elaborate_Body => -1,
12232 Pragma_Elaboration_Checks => -1,
12233 Pragma_Eliminate => -1,
12234 Pragma_Export => -1,
12235 Pragma_Export_Exception => -1,
12236 Pragma_Export_Function => -1,
12237 Pragma_Export_Object => -1,
12238 Pragma_Export_Procedure => -1,
12239 Pragma_Export_Value => -1,
12240 Pragma_Export_Valued_Procedure => -1,
12241 Pragma_Extend_System => -1,
12242 Pragma_Extensions_Allowed => -1,
12243 Pragma_External => -1,
12244 Pragma_Favor_Top_Level => -1,
12245 Pragma_External_Name_Casing => -1,
12246 Pragma_Fast_Math => -1,
12247 Pragma_Finalize_Storage_Only => 0,
12248 Pragma_Float_Representation => 0,
12249 Pragma_Ident => -1,
12250 Pragma_Implemented_By_Entry => -1,
12251 Pragma_Implicit_Packing => 0,
12252 Pragma_Import => +2,
12253 Pragma_Import_Exception => 0,
12254 Pragma_Import_Function => 0,
12255 Pragma_Import_Object => 0,
12256 Pragma_Import_Procedure => 0,
12257 Pragma_Import_Valued_Procedure => 0,
12258 Pragma_Initialize_Scalars => -1,
12259 Pragma_Inline => 0,
12260 Pragma_Inline_Always => 0,
12261 Pragma_Inline_Generic => 0,
12262 Pragma_Inspection_Point => -1,
12263 Pragma_Interface => +2,
12264 Pragma_Interface_Name => +2,
12265 Pragma_Interrupt_Handler => -1,
12266 Pragma_Interrupt_Priority => -1,
12267 Pragma_Interrupt_State => -1,
12268 Pragma_Java_Constructor => -1,
12269 Pragma_Java_Interface => -1,
12270 Pragma_Keep_Names => 0,
12271 Pragma_License => -1,
12272 Pragma_Link_With => -1,
12273 Pragma_Linker_Alias => -1,
12274 Pragma_Linker_Constructor => -1,
12275 Pragma_Linker_Destructor => -1,
12276 Pragma_Linker_Options => -1,
12277 Pragma_Linker_Section => -1,
12279 Pragma_Locking_Policy => -1,
12280 Pragma_Long_Float => -1,
12281 Pragma_Machine_Attribute => -1,
12283 Pragma_Main_Storage => -1,
12284 Pragma_Memory_Size => -1,
12285 Pragma_No_Return => 0,
12286 Pragma_No_Body => 0,
12287 Pragma_No_Run_Time => -1,
12288 Pragma_No_Strict_Aliasing => -1,
12289 Pragma_Normalize_Scalars => -1,
12290 Pragma_Obsolescent => 0,
12291 Pragma_Optimize => -1,
12292 Pragma_Optimize_Alignment => -1,
12295 Pragma_Passive => -1,
12296 Pragma_Preelaborable_Initialization => -1,
12297 Pragma_Polling => -1,
12298 Pragma_Persistent_BSS => 0,
12299 Pragma_Postcondition => -1,
12300 Pragma_Precondition => -1,
12301 Pragma_Preelaborate => -1,
12302 Pragma_Preelaborate_05 => -1,
12303 Pragma_Priority => -1,
12304 Pragma_Priority_Specific_Dispatching => -1,
12305 Pragma_Profile => 0,
12306 Pragma_Profile_Warnings => 0,
12307 Pragma_Propagate_Exceptions => -1,
12308 Pragma_Psect_Object => -1,
12310 Pragma_Pure_05 => -1,
12311 Pragma_Pure_Function => -1,
12312 Pragma_Queuing_Policy => -1,
12313 Pragma_Ravenscar => -1,
12314 Pragma_Relative_Deadline => -1,
12315 Pragma_Remote_Call_Interface => -1,
12316 Pragma_Remote_Types => -1,
12317 Pragma_Restricted_Run_Time => -1,
12318 Pragma_Restriction_Warnings => -1,
12319 Pragma_Restrictions => -1,
12320 Pragma_Reviewable => -1,
12321 Pragma_Share_Generic => -1,
12322 Pragma_Shared => -1,
12323 Pragma_Shared_Passive => -1,
12324 Pragma_Source_File_Name => -1,
12325 Pragma_Source_File_Name_Project => -1,
12326 Pragma_Source_Reference => -1,
12327 Pragma_Storage_Size => -1,
12328 Pragma_Storage_Unit => -1,
12329 Pragma_Static_Elaboration_Desired => -1,
12330 Pragma_Stream_Convert => -1,
12331 Pragma_Style_Checks => -1,
12332 Pragma_Subtitle => -1,
12333 Pragma_Suppress => 0,
12334 Pragma_Suppress_Exception_Locations => 0,
12335 Pragma_Suppress_All => -1,
12336 Pragma_Suppress_Debug_Info => 0,
12337 Pragma_Suppress_Initialization => 0,
12338 Pragma_System_Name => -1,
12339 Pragma_Task_Dispatching_Policy => -1,
12340 Pragma_Task_Info => -1,
12341 Pragma_Task_Name => -1,
12342 Pragma_Task_Storage => 0,
12343 Pragma_Time_Slice => -1,
12344 Pragma_Title => -1,
12345 Pragma_Unchecked_Union => 0,
12346 Pragma_Unimplemented_Unit => -1,
12347 Pragma_Universal_Aliasing => -1,
12348 Pragma_Universal_Data => -1,
12349 Pragma_Unmodified => -1,
12350 Pragma_Unreferenced => -1,
12351 Pragma_Unreferenced_Objects => -1,
12352 Pragma_Unreserve_All_Interrupts => -1,
12353 Pragma_Unsuppress => 0,
12354 Pragma_Use_VADS_Size => -1,
12355 Pragma_Validity_Checks => -1,
12356 Pragma_Volatile => 0,
12357 Pragma_Volatile_Components => 0,
12358 Pragma_Warnings => -1,
12359 Pragma_Weak_External => -1,
12360 Pragma_Wide_Character_Encoding => 0,
12361 Unknown_Pragma => 0);
12363 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12372 if Nkind (P) /= N_Pragma_Argument_Association then
12376 Id := Get_Pragma_Id (Parent (P));
12377 C := Sig_Flags (Id);
12389 -- For pragma Check, the first argument is not significant,
12390 -- the second and the third (if present) arguments are
12393 when Pragma_Check =>
12395 P = First (Pragma_Argument_Associations (Parent (P)));
12398 raise Program_Error;
12402 A := First (Pragma_Argument_Associations (Parent (P)));
12403 for J in 1 .. C - 1 loop
12411 return A = P; -- is this wrong way round ???
12414 end Is_Non_Significant_Pragma_Reference;
12416 ------------------------------
12417 -- Is_Pragma_String_Literal --
12418 ------------------------------
12420 -- This function returns true if the corresponding pragma argument is
12421 -- a static string expression. These are the only cases in which string
12422 -- literals can appear as pragma arguments. We also allow a string
12423 -- literal as the first argument to pragma Assert (although it will
12424 -- of course always generate a type error).
12426 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12427 Pragn : constant Node_Id := Parent (Par);
12428 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12429 Pname : constant Name_Id := Pragma_Name (Pragn);
12435 N := First (Assoc);
12442 if Pname = Name_Assert then
12445 elsif Pname = Name_Export then
12448 elsif Pname = Name_Ident then
12451 elsif Pname = Name_Import then
12454 elsif Pname = Name_Interface_Name then
12457 elsif Pname = Name_Linker_Alias then
12460 elsif Pname = Name_Linker_Section then
12463 elsif Pname = Name_Machine_Attribute then
12466 elsif Pname = Name_Source_File_Name then
12469 elsif Pname = Name_Source_Reference then
12472 elsif Pname = Name_Title then
12475 elsif Pname = Name_Subtitle then
12481 end Is_Pragma_String_Literal;
12483 --------------------------------------
12484 -- Process_Compilation_Unit_Pragmas --
12485 --------------------------------------
12487 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12489 -- A special check for pragma Suppress_All. This is a strange DEC
12490 -- pragma, strange because it comes at the end of the unit. If we
12491 -- have a pragma Suppress_All in the Pragmas_After of the current
12492 -- unit, then we insert a pragma Suppress (All_Checks) at the start
12493 -- of the context clause to ensure the correct processing.
12496 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12500 if Present (PA) then
12502 while Present (P) loop
12503 if Pragma_Name (P) = Name_Suppress_All then
12504 Prepend_To (Context_Items (N),
12505 Make_Pragma (Sloc (P),
12506 Chars => Name_Suppress,
12507 Pragma_Argument_Associations => New_List (
12508 Make_Pragma_Argument_Association (Sloc (P),
12510 Make_Identifier (Sloc (P),
12511 Chars => Name_All_Checks)))));
12519 end Process_Compilation_Unit_Pragmas;
12530 --------------------------------
12531 -- Set_Encoded_Interface_Name --
12532 --------------------------------
12534 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12535 Str : constant String_Id := Strval (S);
12536 Len : constant Int := String_Length (Str);
12541 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12544 -- Stores encoded value of character code CC. The encoding we
12545 -- use an underscore followed by four lower case hex digits.
12551 procedure Encode is
12553 Store_String_Char (Get_Char_Code ('_'));
12555 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12557 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12559 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12561 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12564 -- Start of processing for Set_Encoded_Interface_Name
12567 -- If first character is asterisk, this is a link name, and we
12568 -- leave it completely unmodified. We also ignore null strings
12569 -- (the latter case happens only in error cases) and no encoding
12570 -- should occur for Java or AAMP interface names.
12573 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12574 or else VM_Target /= No_VM
12575 or else AAMP_On_Target
12577 Set_Interface_Name (E, S);
12582 CC := Get_String_Char (Str, J);
12584 exit when not In_Character_Range (CC);
12586 C := Get_Character (CC);
12588 exit when C /= '_' and then C /= '$'
12589 and then C not in '0' .. '9'
12590 and then C not in 'a' .. 'z'
12591 and then C not in 'A' .. 'Z';
12594 Set_Interface_Name (E, S);
12602 -- Here we need to encode. The encoding we use as follows:
12603 -- three underscores + four hex digits (lower case)
12607 for J in 1 .. String_Length (Str) loop
12608 CC := Get_String_Char (Str, J);
12610 if not In_Character_Range (CC) then
12613 C := Get_Character (CC);
12615 if C = '_' or else C = '$'
12616 or else C in '0' .. '9'
12617 or else C in 'a' .. 'z'
12618 or else C in 'A' .. 'Z'
12620 Store_String_Char (CC);
12627 Set_Interface_Name (E,
12628 Make_String_Literal (Sloc (S),
12629 Strval => End_String));
12631 end Set_Encoded_Interface_Name;
12633 -------------------
12634 -- Set_Unit_Name --
12635 -------------------
12637 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12642 if Nkind (N) = N_Identifier
12643 and then Nkind (With_Item) = N_Identifier
12645 Set_Entity (N, Entity (With_Item));
12647 elsif Nkind (N) = N_Selected_Component then
12648 Change_Selected_Component_To_Expanded_Name (N);
12649 Set_Entity (N, Entity (With_Item));
12650 Set_Entity (Selector_Name (N), Entity (N));
12652 Pref := Prefix (N);
12653 Scop := Scope (Entity (N));
12654 while Nkind (Pref) = N_Selected_Component loop
12655 Change_Selected_Component_To_Expanded_Name (Pref);
12656 Set_Entity (Selector_Name (Pref), Scop);
12657 Set_Entity (Pref, Scop);
12658 Pref := Prefix (Pref);
12659 Scop := Scope (Scop);
12662 Set_Entity (Pref, Scop);