1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with 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 if
114 -- 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 is
118 -- treated as an external name (exactly as though it had been given as an
119 -- 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 use of
132 -- named notation, following the standard rules for subprogram calls, i.e.
133 -- parameters can be given in any order if named notation is used, and
134 -- positional and named notation can be mixed, subject to the rule that all
135 -- positional parameters must appear first.
137 -- Note: All these pragmas are implemented exactly following the DEC design
138 -- and implementation and are intended to be fully compatible with the use
139 -- 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 hold
150 -- the value of the external name. The Sloc of this node is used to
151 -- 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 to
168 -- the casing requirement of Opt.External_Name_Casing. If this is set to
169 -- As_Is, then the string literal is returned unchanged, but if it is set
170 -- to Uppercase or Lowercase, then a new string literal with appropriate
171 -- 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 (the
175 -- original one, following the renaming chain) is returned. Otherwise the
176 -- 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/Elaborate_All
194 -- pragma. Entity name for unit and its parents is taken from item in
195 -- 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 so that we
254 -- can see the formals from the pragma.
259 -- Preanalyze the boolean expression, we treat this as a spec expression
260 -- (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 pre-analysis
273 -- 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 is
289 -- 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 in
291 -- a state where the pragma should not be processed.
294 -- Number of pragma argument associations
300 -- First four pragma arguments (pragma argument association nodes, or
301 -- 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. If not,
320 -- then issue an error message and raise Pragma_Exit.
322 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
323 -- Arg which can either be a pragma argument association, in which case
324 -- the check is applied to the expression of the association or an
325 -- 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 the
330 -- name must be an identifier or string literal (in Ada 83 mode) or a
331 -- 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 integer
339 -- 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 proper
343 -- syntactic form for a local name and meets the semantic requirements
344 -- for a local name. The local name is analyzed as part of the
345 -- processing for this call. In addition, the local name is required
346 -- 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 proper
350 -- syntactic form for a local name and meets the semantic requirements
351 -- for a local name. The local name is analyzed as part of the
352 -- 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
371 Typ : Entity_Id := Empty);
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. If
376 -- Typ is left Empty, then any static expression is allowed.
378 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
379 -- Check the specified argument Arg to make sure that it is a string
380 -- literal. If not give error and raise Pragma_Exit
382 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
383 -- Check the specified argument Arg to make sure that it is a valid task
384 -- dispatching policy name. If not give error and raise Pragma_Exit.
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 by
403 -- an Import or Export pragma (or extended Import or Export pragma).
404 -- This procedure checks for possible duplications if this is the export
405 -- 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 a
409 -- 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 or
417 -- 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. The three
610 -- arguments correspond to the three named parameters of the pragma. An
611 -- argument is empty if the corresponding parameter is not present in
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. The three
619 -- arguments correspond to the three named parameters of the pragmas. An
620 -- argument is empty if the corresponding parameter is not present in
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 applying
640 -- to subprograms. The caller omits any arguments that do not apply to
641 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
642 -- only in the Import_Function and Export_Function cases). The argument
643 -- names correspond to the allowed pragma association identifiers.
645 procedure Process_Generic_List;
646 -- Common processing for Share_Generic and Inline_Generic
648 procedure Process_Import_Or_Interface;
649 -- Common processing for Import of Interface
651 procedure Process_Inline (Active : Boolean);
652 -- Common processing for Inline and Inline_Always. The parameter
653 -- indicates if the inline pragma is active, i.e. if it should actually
654 -- cause inlining to occur.
656 procedure Process_Interface_Name
657 (Subprogram_Def : Entity_Id;
660 -- Given the last two arguments of pragma Import, pragma Export, or
661 -- pragma Interface_Name, performs validity checks and sets the
662 -- Interface_Name field of the given subprogram entity to the
663 -- appropriate external or link name, depending on the arguments given.
664 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
665 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
666 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
667 -- nor Link_Arg is present, the interface name is set to the default
668 -- from the subprogram name.
670 procedure Process_Interrupt_Or_Attach_Handler;
671 -- Common processing for Interrupt and Attach_Handler pragmas
673 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
674 -- Common processing for Restrictions and Restriction_Warnings pragmas.
675 -- Warn is True for Restriction_Warnings, or for Restrictions if the
676 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
677 -- is not set in the Restrictions case.
679 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
680 -- Common processing for Suppress and Unsuppress. The boolean parameter
681 -- Suppress_Case is True for the Suppress case, and False for the
684 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
685 -- This procedure sets the Is_Exported flag for the given entity,
686 -- checking that the entity was not previously imported. Arg is
687 -- the argument that specified the entity. A check is also made
688 -- for exporting inappropriate entities.
690 procedure Set_Extended_Import_Export_External_Name
691 (Internal_Ent : Entity_Id;
692 Arg_External : Node_Id);
693 -- Common processing for all extended import export pragmas. The first
694 -- argument, Internal_Ent, is the internal entity, which has already
695 -- been checked for validity by the caller. Arg_External is from the
696 -- Import or Export pragma, and may be null if no External parameter
697 -- was present. If Arg_External is present and is a non-null string
698 -- (a null string is treated as the default), then the Interface_Name
699 -- field of Internal_Ent is set appropriately.
701 procedure Set_Imported (E : Entity_Id);
702 -- This procedure sets the Is_Imported flag for the given entity,
703 -- checking that it is not previously exported or imported.
705 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
706 -- Mech is a parameter passing mechanism (see Import_Function syntax
707 -- for MECHANISM_NAME). This routine checks that the mechanism argument
708 -- has the right form, and if not issues an error message. If the
709 -- argument has the right form then the Mechanism field of Ent is
710 -- set appropriately.
712 procedure Set_Ravenscar_Profile (N : Node_Id);
713 -- Activate the set of configuration pragmas and restrictions that make
714 -- up the Ravenscar Profile. N is the corresponding pragma node, which
715 -- is used for error messages on any constructs that violate the
718 ---------------------
719 -- Ada_2005_Pragma --
720 ---------------------
722 procedure Ada_2005_Pragma is
724 if Ada_Version <= Ada_95 then
725 Check_Restriction (No_Implementation_Pragmas, N);
729 --------------------------
730 -- Check_Ada_83_Warning --
731 --------------------------
733 procedure Check_Ada_83_Warning is
735 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
736 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
738 end Check_Ada_83_Warning;
740 ---------------------
741 -- Check_Arg_Count --
742 ---------------------
744 procedure Check_Arg_Count (Required : Nat) is
746 if Arg_Count /= Required then
747 Error_Pragma ("wrong number of arguments for pragma%");
751 --------------------------------
752 -- Check_Arg_Is_External_Name --
753 --------------------------------
755 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
756 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
759 if Nkind (Argx) = N_Identifier then
763 Analyze_And_Resolve (Argx, Standard_String);
765 if Is_OK_Static_Expression (Argx) then
768 elsif Etype (Argx) = Any_Type then
771 -- An interesting special case, if we have a string literal and
772 -- we are in Ada 83 mode, then we allow it even though it will
773 -- not be flagged as static. This allows expected Ada 83 mode
774 -- use of external names which are string literals, even though
775 -- technically these are not static in Ada 83.
777 elsif Ada_Version = Ada_83
778 and then Nkind (Argx) = N_String_Literal
782 -- Static expression that raises Constraint_Error. This has
783 -- already been flagged, so just exit from pragma processing.
785 elsif Is_Static_Expression (Argx) then
788 -- Here we have a real error (non-static expression)
791 Error_Msg_Name_1 := Pname;
793 ("argument for pragma% must be a identifier or " &
794 "static string expression!", Argx);
798 end Check_Arg_Is_External_Name;
800 -----------------------------
801 -- Check_Arg_Is_Identifier --
802 -----------------------------
804 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
805 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
807 if Nkind (Argx) /= N_Identifier then
809 ("argument for pragma% must be identifier", Argx);
811 end Check_Arg_Is_Identifier;
813 ----------------------------------
814 -- Check_Arg_Is_Integer_Literal --
815 ----------------------------------
817 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
818 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
820 if Nkind (Argx) /= N_Integer_Literal then
822 ("argument for pragma% must be integer literal", Argx);
824 end Check_Arg_Is_Integer_Literal;
826 -------------------------------------------
827 -- Check_Arg_Is_Library_Level_Local_Name --
828 -------------------------------------------
832 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
833 -- | library_unit_NAME
835 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
837 Check_Arg_Is_Local_Name (Arg);
839 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
840 and then Comes_From_Source (N)
843 ("argument for pragma% must be library level entity", Arg);
845 end Check_Arg_Is_Library_Level_Local_Name;
847 -----------------------------
848 -- Check_Arg_Is_Local_Name --
849 -----------------------------
853 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
854 -- | library_unit_NAME
856 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
857 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
862 if Nkind (Argx) not in N_Direct_Name
863 and then (Nkind (Argx) /= N_Attribute_Reference
864 or else Present (Expressions (Argx))
865 or else Nkind (Prefix (Argx)) /= N_Identifier)
866 and then (not Is_Entity_Name (Argx)
867 or else not Is_Compilation_Unit (Entity (Argx)))
869 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
872 if Is_Entity_Name (Argx)
873 and then Scope (Entity (Argx)) /= Current_Scope
876 ("pragma% argument must be in same declarative part", Arg);
878 end Check_Arg_Is_Local_Name;
880 ---------------------------------
881 -- Check_Arg_Is_Locking_Policy --
882 ---------------------------------
884 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
885 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
888 Check_Arg_Is_Identifier (Argx);
890 if not Is_Locking_Policy_Name (Chars (Argx)) then
892 ("& is not a valid locking policy name", Argx);
894 end Check_Arg_Is_Locking_Policy;
896 -------------------------
897 -- Check_Arg_Is_One_Of --
898 -------------------------
900 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
901 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
904 Check_Arg_Is_Identifier (Argx);
906 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
907 Error_Msg_Name_2 := N1;
908 Error_Msg_Name_3 := N2;
909 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
911 end Check_Arg_Is_One_Of;
913 procedure Check_Arg_Is_One_Of
915 N1, N2, N3 : Name_Id)
917 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
920 Check_Arg_Is_Identifier (Argx);
922 if Chars (Argx) /= N1
923 and then Chars (Argx) /= N2
924 and then Chars (Argx) /= N3
926 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
928 end Check_Arg_Is_One_Of;
930 procedure Check_Arg_Is_One_Of
932 N1, N2, N3, N4 : Name_Id)
934 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
937 Check_Arg_Is_Identifier (Argx);
939 if Chars (Argx) /= N1
940 and then Chars (Argx) /= N2
941 and then Chars (Argx) /= N3
942 and then Chars (Argx) /= N4
944 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
946 end Check_Arg_Is_One_Of;
948 ---------------------------------
949 -- Check_Arg_Is_Queuing_Policy --
950 ---------------------------------
952 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
953 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
956 Check_Arg_Is_Identifier (Argx);
958 if not Is_Queuing_Policy_Name (Chars (Argx)) then
960 ("& is not a valid queuing policy name", Argx);
962 end Check_Arg_Is_Queuing_Policy;
964 ------------------------------------
965 -- Check_Arg_Is_Static_Expression --
966 ------------------------------------
968 procedure Check_Arg_Is_Static_Expression
970 Typ : Entity_Id := Empty)
972 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
975 if Present (Typ) then
976 Analyze_And_Resolve (Argx, Typ);
978 Analyze_And_Resolve (Argx);
981 if Is_OK_Static_Expression (Argx) then
984 elsif Etype (Argx) = Any_Type then
987 -- An interesting special case, if we have a string literal and we
988 -- are in Ada 83 mode, then we allow it even though it will not be
989 -- flagged as static. This allows the use of Ada 95 pragmas like
990 -- Import in Ada 83 mode. They will of course be flagged with
991 -- warnings as usual, but will not cause errors.
993 elsif Ada_Version = Ada_83
994 and then Nkind (Argx) = N_String_Literal
998 -- Static expression that raises Constraint_Error. This has already
999 -- been flagged, so just exit from pragma processing.
1001 elsif Is_Static_Expression (Argx) then
1004 -- Finally, we have a real error
1007 Error_Msg_Name_1 := Pname;
1008 Flag_Non_Static_Expr
1009 ("argument for pragma% must be a static expression!", Argx);
1012 end Check_Arg_Is_Static_Expression;
1014 ---------------------------------
1015 -- Check_Arg_Is_String_Literal --
1016 ---------------------------------
1018 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1019 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1021 if Nkind (Argx) /= N_String_Literal then
1023 ("argument for pragma% must be string literal", Argx);
1025 end Check_Arg_Is_String_Literal;
1027 ------------------------------------------
1028 -- Check_Arg_Is_Task_Dispatching_Policy --
1029 ------------------------------------------
1031 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1032 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1035 Check_Arg_Is_Identifier (Argx);
1037 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1039 ("& is not a valid task dispatching policy name", Argx);
1041 end Check_Arg_Is_Task_Dispatching_Policy;
1043 ---------------------
1044 -- Check_Arg_Order --
1045 ---------------------
1047 procedure Check_Arg_Order (Names : Name_List) is
1050 Highest_So_Far : Natural := 0;
1051 -- Highest index in Names seen do far
1055 for J in 1 .. Arg_Count loop
1056 if Chars (Arg) /= No_Name then
1057 for K in Names'Range loop
1058 if Chars (Arg) = Names (K) then
1059 if K < Highest_So_Far then
1060 Error_Msg_Name_1 := Pname;
1062 ("parameters out of order for pragma%", Arg);
1063 Error_Msg_Name_1 := Names (K);
1064 Error_Msg_Name_2 := Names (Highest_So_Far);
1065 Error_Msg_N ("\% must appear before %", Arg);
1069 Highest_So_Far := K;
1077 end Check_Arg_Order;
1079 --------------------------------
1080 -- Check_At_Least_N_Arguments --
1081 --------------------------------
1083 procedure Check_At_Least_N_Arguments (N : Nat) is
1085 if Arg_Count < N then
1086 Error_Pragma ("too few arguments for pragma%");
1088 end Check_At_Least_N_Arguments;
1090 -------------------------------
1091 -- Check_At_Most_N_Arguments --
1092 -------------------------------
1094 procedure Check_At_Most_N_Arguments (N : Nat) is
1097 if Arg_Count > N then
1099 for J in 1 .. N loop
1101 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1104 end Check_At_Most_N_Arguments;
1106 ---------------------
1107 -- Check_Component --
1108 ---------------------
1110 procedure Check_Component (Comp : Node_Id) is
1112 if Nkind (Comp) = N_Component_Declaration then
1114 Sindic : constant Node_Id :=
1115 Subtype_Indication (Component_Definition (Comp));
1116 Typ : constant Entity_Id :=
1117 Etype (Defining_Identifier (Comp));
1119 if Nkind (Sindic) = N_Subtype_Indication then
1121 -- Ada 2005 (AI-216): If a component subtype is subject to
1122 -- a per-object constraint, then the component type shall
1123 -- be an Unchecked_Union.
1125 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1127 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1129 Error_Msg_N ("component subtype subject to per-object" &
1130 " constraint must be an Unchecked_Union", Comp);
1134 if Is_Controlled (Typ) then
1136 ("component of unchecked union cannot be controlled", Comp);
1138 elsif Has_Task (Typ) then
1140 ("component of unchecked union cannot have tasks", Comp);
1144 end Check_Component;
1146 ----------------------------------
1147 -- Check_Duplicated_Export_Name --
1148 ----------------------------------
1150 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1151 String_Val : constant String_Id := Strval (Nam);
1154 -- We are only interested in the export case, and in the case of
1155 -- generics, it is the instance, not the template, that is the
1156 -- problem (the template will generate a warning in any case).
1158 if not Inside_A_Generic
1159 and then (Prag_Id = Pragma_Export
1161 Prag_Id = Pragma_Export_Procedure
1163 Prag_Id = Pragma_Export_Valued_Procedure
1165 Prag_Id = Pragma_Export_Function)
1167 for J in Externals.First .. Externals.Last loop
1168 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1169 Error_Msg_Sloc := Sloc (Externals.Table (J));
1170 Error_Msg_N ("external name duplicates name given#", Nam);
1175 Externals.Append (Nam);
1177 end Check_Duplicated_Export_Name;
1179 -------------------------
1180 -- Check_First_Subtype --
1181 -------------------------
1183 procedure Check_First_Subtype (Arg : Node_Id) is
1184 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1186 if not Is_First_Subtype (Entity (Argx)) then
1188 ("pragma% cannot apply to subtype", Argx);
1190 end Check_First_Subtype;
1192 ---------------------------
1193 -- Check_In_Main_Program --
1194 ---------------------------
1196 procedure Check_In_Main_Program is
1197 P : constant Node_Id := Parent (N);
1200 -- Must be at in subprogram body
1202 if Nkind (P) /= N_Subprogram_Body then
1203 Error_Pragma ("% pragma allowed only in subprogram");
1205 -- Otherwise warn if obviously not main program
1207 elsif Present (Parameter_Specifications (Specification (P)))
1208 or else not Is_Compilation_Unit (Defining_Entity (P))
1210 Error_Msg_Name_1 := Pname;
1212 ("?pragma% is only effective in main program", N);
1214 end Check_In_Main_Program;
1216 ---------------------------------------
1217 -- Check_Interrupt_Or_Attach_Handler --
1218 ---------------------------------------
1220 procedure Check_Interrupt_Or_Attach_Handler is
1221 Arg1_X : constant Node_Id := Expression (Arg1);
1222 Handler_Proc, Proc_Scope : Entity_Id;
1227 if Prag_Id = Pragma_Interrupt_Handler then
1228 Check_Restriction (No_Dynamic_Attachment, N);
1231 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1232 Proc_Scope := Scope (Handler_Proc);
1234 -- On AAMP only, a pragma Interrupt_Handler is supported for
1235 -- nonprotected parameterless procedures.
1237 if not AAMP_On_Target
1238 or else Prag_Id = Pragma_Attach_Handler
1240 if Ekind (Proc_Scope) /= E_Protected_Type then
1242 ("argument of pragma% must be protected procedure", Arg1);
1245 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1246 Error_Pragma ("pragma% must be in protected definition");
1250 if not Is_Library_Level_Entity (Proc_Scope)
1251 or else (AAMP_On_Target
1252 and then not Is_Library_Level_Entity (Handler_Proc))
1255 ("argument for pragma% must be library level entity", Arg1);
1257 end Check_Interrupt_Or_Attach_Handler;
1259 -------------------------------------------
1260 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1261 -------------------------------------------
1263 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1272 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1275 elsif Nkind_In (P, N_Package_Specification,
1280 -- Note: the following tests seem a little peculiar, because
1281 -- they test for bodies, but if we were in the statement part
1282 -- of the body, we would already have hit the handled statement
1283 -- sequence, so the only way we get here is by being in the
1284 -- declarative part of the body.
1286 elsif Nkind_In (P, N_Subprogram_Body,
1297 Error_Pragma ("pragma% is not in declarative part or package spec");
1298 end Check_Is_In_Decl_Part_Or_Package_Spec;
1300 -------------------------
1301 -- Check_No_Identifier --
1302 -------------------------
1304 procedure Check_No_Identifier (Arg : Node_Id) is
1306 if Chars (Arg) /= No_Name then
1307 Error_Pragma_Arg_Ident
1308 ("pragma% does not permit identifier& here", Arg);
1310 end Check_No_Identifier;
1312 --------------------------
1313 -- Check_No_Identifiers --
1314 --------------------------
1316 procedure Check_No_Identifiers is
1319 if Arg_Count > 0 then
1321 while Present (Arg_Node) loop
1322 Check_No_Identifier (Arg_Node);
1326 end Check_No_Identifiers;
1328 -------------------------------
1329 -- Check_Optional_Identifier --
1330 -------------------------------
1332 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1334 if Present (Arg) and then Chars (Arg) /= No_Name then
1335 if Chars (Arg) /= Id then
1336 Error_Msg_Name_1 := Pname;
1337 Error_Msg_Name_2 := Id;
1338 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1342 end Check_Optional_Identifier;
1344 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1346 Name_Buffer (1 .. Id'Length) := Id;
1347 Name_Len := Id'Length;
1348 Check_Optional_Identifier (Arg, Name_Find);
1349 end Check_Optional_Identifier;
1351 --------------------------------------
1352 -- Check_Precondition_Postcondition --
1353 --------------------------------------
1355 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1359 procedure Chain_PPC (PO : Node_Id);
1360 -- If PO is a subprogram declaration node (or a generic subprogram
1361 -- declaration node), then the precondition/postcondition applies
1362 -- to this subprogram and the processing for the pragma is completed.
1363 -- Otherwise the pragma is misplaced.
1369 procedure Chain_PPC (PO : Node_Id) is
1373 if not Nkind_In (PO, N_Subprogram_Declaration,
1374 N_Generic_Subprogram_Declaration)
1379 -- Here if we have subprogram or generic subprogram declaration
1381 S := Defining_Unit_Name (Specification (PO));
1383 -- Analyze the pragma unless it appears within a package spec,
1384 -- which is the case where we delay the analysis of the PPC until
1385 -- the end of the package declarations (for details, see
1386 -- Analyze_Package_Specification.Analyze_PPCs).
1388 if not Is_Package_Or_Generic_Package (Scope (S)) then
1389 Analyze_PPC_In_Decl_Part (N, S);
1392 -- Chain spec PPC pragma to list for subprogram
1394 Set_Next_Pragma (N, Spec_PPC_List (S));
1395 Set_Spec_PPC_List (S, N);
1397 -- Return indicating spec case
1403 -- Start of processing for Check_Precondition_Postcondition
1406 if not Is_List_Member (N) then
1410 -- Record whether pragma is enabled
1412 Set_PPC_Enabled (N, Check_Enabled (Pname));
1414 -- If we are within an inlined body, the legality of the pragma
1415 -- has been checked already.
1417 if In_Inlined_Body then
1422 -- Search prior declarations
1425 while Present (Prev (P)) loop
1428 -- If the previous node is a generic subprogram, do not go to to
1429 -- the original node, which is the unanalyzed tree: we need to
1430 -- attach the pre/postconditions to the analyzed version at this
1431 -- point. They get propagated to the original tree when analyzing
1432 -- the corresponding body.
1434 if Nkind (P) not in N_Generic_Declaration then
1435 PO := Original_Node (P);
1440 -- Skip past prior pragma
1442 if Nkind (PO) = N_Pragma then
1445 -- Skip stuff not coming from source
1447 elsif not Comes_From_Source (PO) then
1450 -- Only remaining possibility is subprogram declaration
1458 -- If we fall through loop, pragma is at start of list, so see if it
1459 -- is at the start of declarations of a subprogram body.
1461 if Nkind (Parent (N)) = N_Subprogram_Body
1462 and then List_Containing (N) = Declarations (Parent (N))
1464 if Operating_Mode /= Generate_Code
1465 or else Inside_A_Generic
1468 -- Analyze expression in pragma, for correctness
1469 -- and for ASIS use.
1471 Preanalyze_Spec_Expression
1472 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1478 -- See if it is in the pragmas after a library level subprogram
1480 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1481 Chain_PPC (Unit (Parent (Parent (N))));
1485 -- If we fall through, pragma was misplaced
1488 end Check_Precondition_Postcondition;
1490 -----------------------------
1491 -- Check_Static_Constraint --
1492 -----------------------------
1494 -- Note: for convenience in writing this procedure, in addition to
1495 -- the officially (i.e. by spec) allowed argument which is always a
1496 -- constraint, it also allows ranges and discriminant associations.
1497 -- Above is not clear ???
1499 procedure Check_Static_Constraint (Constr : Node_Id) is
1501 procedure Require_Static (E : Node_Id);
1502 -- Require given expression to be static expression
1504 --------------------
1505 -- Require_Static --
1506 --------------------
1508 procedure Require_Static (E : Node_Id) is
1510 if not Is_OK_Static_Expression (E) then
1511 Flag_Non_Static_Expr
1512 ("non-static constraint not allowed in Unchecked_Union!", E);
1517 -- Start of processing for Check_Static_Constraint
1520 case Nkind (Constr) is
1521 when N_Discriminant_Association =>
1522 Require_Static (Expression (Constr));
1525 Require_Static (Low_Bound (Constr));
1526 Require_Static (High_Bound (Constr));
1528 when N_Attribute_Reference =>
1529 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1530 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1532 when N_Range_Constraint =>
1533 Check_Static_Constraint (Range_Expression (Constr));
1535 when N_Index_Or_Discriminant_Constraint =>
1539 IDC := First (Constraints (Constr));
1540 while Present (IDC) loop
1541 Check_Static_Constraint (IDC);
1549 end Check_Static_Constraint;
1551 --------------------------------------
1552 -- Check_Valid_Configuration_Pragma --
1553 --------------------------------------
1555 -- A configuration pragma must appear in the context clause of a
1556 -- compilation unit, and only other pragmas may precede it. Note that
1557 -- the test also allows use in a configuration pragma file.
1559 procedure Check_Valid_Configuration_Pragma is
1561 if not Is_Configuration_Pragma then
1562 Error_Pragma ("incorrect placement for configuration pragma%");
1564 end Check_Valid_Configuration_Pragma;
1566 -------------------------------------
1567 -- Check_Valid_Library_Unit_Pragma --
1568 -------------------------------------
1570 procedure Check_Valid_Library_Unit_Pragma is
1572 Parent_Node : Node_Id;
1573 Unit_Name : Entity_Id;
1574 Unit_Kind : Node_Kind;
1575 Unit_Node : Node_Id;
1576 Sindex : Source_File_Index;
1579 if not Is_List_Member (N) then
1583 Plist := List_Containing (N);
1584 Parent_Node := Parent (Plist);
1586 if Parent_Node = Empty then
1589 -- Case of pragma appearing after a compilation unit. In this case
1590 -- it must have an argument with the corresponding name and must
1591 -- be part of the following pragmas of its parent.
1593 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1594 if Plist /= Pragmas_After (Parent_Node) then
1597 elsif Arg_Count = 0 then
1599 ("argument required if outside compilation unit");
1602 Check_No_Identifiers;
1603 Check_Arg_Count (1);
1604 Unit_Node := Unit (Parent (Parent_Node));
1605 Unit_Kind := Nkind (Unit_Node);
1607 Analyze (Expression (Arg1));
1609 if Unit_Kind = N_Generic_Subprogram_Declaration
1610 or else Unit_Kind = N_Subprogram_Declaration
1612 Unit_Name := Defining_Entity (Unit_Node);
1614 elsif Unit_Kind in N_Generic_Instantiation then
1615 Unit_Name := Defining_Entity (Unit_Node);
1618 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1621 if Chars (Unit_Name) /=
1622 Chars (Entity (Expression (Arg1)))
1625 ("pragma% argument is not current unit name", Arg1);
1628 if Ekind (Unit_Name) = E_Package
1629 and then Present (Renamed_Entity (Unit_Name))
1631 Error_Pragma ("pragma% not allowed for renamed package");
1635 -- Pragma appears other than after a compilation unit
1638 -- Here we check for the generic instantiation case and also
1639 -- for the case of processing a generic formal package. We
1640 -- detect these cases by noting that the Sloc on the node
1641 -- does not belong to the current compilation unit.
1643 Sindex := Source_Index (Current_Sem_Unit);
1645 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1646 Rewrite (N, Make_Null_Statement (Loc));
1649 -- If before first declaration, the pragma applies to the
1650 -- enclosing unit, and the name if present must be this name.
1652 elsif Is_Before_First_Decl (N, Plist) then
1653 Unit_Node := Unit_Declaration_Node (Current_Scope);
1654 Unit_Kind := Nkind (Unit_Node);
1656 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1659 elsif Unit_Kind = N_Subprogram_Body
1660 and then not Acts_As_Spec (Unit_Node)
1664 elsif Nkind (Parent_Node) = N_Package_Body then
1667 elsif Nkind (Parent_Node) = N_Package_Specification
1668 and then Plist = Private_Declarations (Parent_Node)
1672 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1673 or else Nkind (Parent_Node) =
1674 N_Generic_Subprogram_Declaration)
1675 and then Plist = Generic_Formal_Declarations (Parent_Node)
1679 elsif Arg_Count > 0 then
1680 Analyze (Expression (Arg1));
1682 if Entity (Expression (Arg1)) /= Current_Scope then
1684 ("name in pragma% must be enclosing unit", Arg1);
1687 -- It is legal to have no argument in this context
1693 -- Error if not before first declaration. This is because a
1694 -- library unit pragma argument must be the name of a library
1695 -- unit (RM 10.1.5(7)), but the only names permitted in this
1696 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1697 -- generic subprogram declarations or generic instantiations.
1701 ("pragma% misplaced, must be before first declaration");
1705 end Check_Valid_Library_Unit_Pragma;
1711 procedure Check_Variant (Variant : Node_Id) is
1712 Clist : constant Node_Id := Component_List (Variant);
1716 if not Is_Non_Empty_List (Component_Items (Clist)) then
1718 ("Unchecked_Union may not have empty component list",
1723 Comp := First (Component_Items (Clist));
1724 while Present (Comp) loop
1725 Check_Component (Comp);
1734 procedure Error_Pragma (Msg : String) is
1736 Error_Msg_Name_1 := Pname;
1737 Error_Msg_N (Msg, N);
1741 ----------------------
1742 -- Error_Pragma_Arg --
1743 ----------------------
1745 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1747 Error_Msg_Name_1 := Pname;
1748 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1750 end Error_Pragma_Arg;
1752 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1754 Error_Msg_Name_1 := Pname;
1755 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1756 Error_Pragma_Arg (Msg2, Arg);
1757 end Error_Pragma_Arg;
1759 ----------------------------
1760 -- Error_Pragma_Arg_Ident --
1761 ----------------------------
1763 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1765 Error_Msg_Name_1 := Pname;
1766 Error_Msg_N (Msg, Arg);
1768 end Error_Pragma_Arg_Ident;
1770 ----------------------
1771 -- Error_Pragma_Ref --
1772 ----------------------
1774 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1776 Error_Msg_Name_1 := Pname;
1777 Error_Msg_Sloc := Sloc (Ref);
1778 Error_Msg_NE (Msg, N, Ref);
1780 end Error_Pragma_Ref;
1782 ------------------------
1783 -- Find_Lib_Unit_Name --
1784 ------------------------
1786 function Find_Lib_Unit_Name return Entity_Id is
1788 -- Return inner compilation unit entity, for case of nested
1789 -- categorization pragmas. This happens in generic unit.
1791 if Nkind (Parent (N)) = N_Package_Specification
1792 and then Defining_Entity (Parent (N)) /= Current_Scope
1794 return Defining_Entity (Parent (N));
1796 return Current_Scope;
1798 end Find_Lib_Unit_Name;
1800 ----------------------------
1801 -- Find_Program_Unit_Name --
1802 ----------------------------
1804 procedure Find_Program_Unit_Name (Id : Node_Id) is
1805 Unit_Name : Entity_Id;
1806 Unit_Kind : Node_Kind;
1807 P : constant Node_Id := Parent (N);
1810 if Nkind (P) = N_Compilation_Unit then
1811 Unit_Kind := Nkind (Unit (P));
1813 if Unit_Kind = N_Subprogram_Declaration
1814 or else Unit_Kind = N_Package_Declaration
1815 or else Unit_Kind in N_Generic_Declaration
1817 Unit_Name := Defining_Entity (Unit (P));
1819 if Chars (Id) = Chars (Unit_Name) then
1820 Set_Entity (Id, Unit_Name);
1821 Set_Etype (Id, Etype (Unit_Name));
1823 Set_Etype (Id, Any_Type);
1825 ("cannot find program unit referenced by pragma%");
1829 Set_Etype (Id, Any_Type);
1830 Error_Pragma ("pragma% inapplicable to this unit");
1836 end Find_Program_Unit_Name;
1838 -----------------------------------------
1839 -- Find_Unique_Parameterless_Procedure --
1840 -----------------------------------------
1842 function Find_Unique_Parameterless_Procedure
1844 Arg : Node_Id) return Entity_Id
1846 Proc : Entity_Id := Empty;
1849 -- The body of this procedure needs some comments ???
1851 if not Is_Entity_Name (Name) then
1853 ("argument of pragma% must be entity name", Arg);
1855 elsif not Is_Overloaded (Name) then
1856 Proc := Entity (Name);
1858 if Ekind (Proc) /= E_Procedure
1859 or else Present (First_Formal (Proc)) then
1861 ("argument of pragma% must be parameterless procedure", Arg);
1866 Found : Boolean := False;
1868 Index : Interp_Index;
1871 Get_First_Interp (Name, Index, It);
1872 while Present (It.Nam) loop
1875 if Ekind (Proc) = E_Procedure
1876 and then No (First_Formal (Proc))
1880 Set_Entity (Name, Proc);
1881 Set_Is_Overloaded (Name, False);
1884 ("ambiguous handler name for pragma% ", Arg);
1888 Get_Next_Interp (Index, It);
1893 ("argument of pragma% must be parameterless procedure",
1896 Proc := Entity (Name);
1902 end Find_Unique_Parameterless_Procedure;
1904 -------------------------
1905 -- Gather_Associations --
1906 -------------------------
1908 procedure Gather_Associations
1910 Args : out Args_List)
1915 -- Initialize all parameters to Empty
1917 for J in Args'Range loop
1921 -- That's all we have to do if there are no argument associations
1923 if No (Pragma_Argument_Associations (N)) then
1927 -- Otherwise first deal with any positional parameters present
1929 Arg := First (Pragma_Argument_Associations (N));
1930 for Index in Args'Range loop
1931 exit when No (Arg) or else Chars (Arg) /= No_Name;
1932 Args (Index) := Expression (Arg);
1936 -- Positional parameters all processed, if any left, then we
1937 -- have too many positional parameters.
1939 if Present (Arg) and then Chars (Arg) = No_Name then
1941 ("too many positional associations for pragma%", Arg);
1944 -- Process named parameters if any are present
1946 while Present (Arg) loop
1947 if Chars (Arg) = No_Name then
1949 ("positional association cannot follow named association",
1953 for Index in Names'Range loop
1954 if Names (Index) = Chars (Arg) then
1955 if Present (Args (Index)) then
1957 ("duplicate argument association for pragma%", Arg);
1959 Args (Index) := Expression (Arg);
1964 if Index = Names'Last then
1965 Error_Msg_Name_1 := Pname;
1966 Error_Msg_N ("pragma% does not allow & argument", Arg);
1968 -- Check for possible misspelling
1970 for Index1 in Names'Range loop
1971 if Is_Bad_Spelling_Of
1972 (Chars (Arg), Names (Index1))
1974 Error_Msg_Name_1 := Names (Index1);
1975 Error_Msg_N -- CODEFIX
1976 ("\possible misspelling of%", Arg);
1988 end Gather_Associations;
1994 procedure GNAT_Pragma is
1996 Check_Restriction (No_Implementation_Pragmas, N);
1999 --------------------------
2000 -- Is_Before_First_Decl --
2001 --------------------------
2003 function Is_Before_First_Decl
2004 (Pragma_Node : Node_Id;
2005 Decls : List_Id) return Boolean
2007 Item : Node_Id := First (Decls);
2010 -- Only other pragmas can come before this pragma
2013 if No (Item) or else Nkind (Item) /= N_Pragma then
2016 elsif Item = Pragma_Node then
2022 end Is_Before_First_Decl;
2024 -----------------------------
2025 -- Is_Configuration_Pragma --
2026 -----------------------------
2028 -- A configuration pragma must appear in the context clause of a
2029 -- compilation unit, and only other pragmas may precede it. Note that
2030 -- the test below also permits use in a configuration pragma file.
2032 function Is_Configuration_Pragma return Boolean is
2033 Lis : constant List_Id := List_Containing (N);
2034 Par : constant Node_Id := Parent (N);
2038 -- If no parent, then we are in the configuration pragma file,
2039 -- so the placement is definitely appropriate.
2044 -- Otherwise we must be in the context clause of a compilation unit
2045 -- and the only thing allowed before us in the context list is more
2046 -- configuration pragmas.
2048 elsif Nkind (Par) = N_Compilation_Unit
2049 and then Context_Items (Par) = Lis
2056 elsif Nkind (Prg) /= N_Pragma then
2066 end Is_Configuration_Pragma;
2068 --------------------------
2069 -- Is_In_Context_Clause --
2070 --------------------------
2072 function Is_In_Context_Clause return Boolean is
2074 Parent_Node : Node_Id;
2077 if not Is_List_Member (N) then
2081 Plist := List_Containing (N);
2082 Parent_Node := Parent (Plist);
2084 if Parent_Node = Empty
2085 or else Nkind (Parent_Node) /= N_Compilation_Unit
2086 or else Context_Items (Parent_Node) /= Plist
2093 end Is_In_Context_Clause;
2095 ---------------------------------
2096 -- Is_Static_String_Expression --
2097 ---------------------------------
2099 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2100 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2103 Analyze_And_Resolve (Argx);
2104 return Is_OK_Static_Expression (Argx)
2105 and then Nkind (Argx) = N_String_Literal;
2106 end Is_Static_String_Expression;
2108 ----------------------
2109 -- Pragma_Misplaced --
2110 ----------------------
2112 procedure Pragma_Misplaced is
2114 Error_Pragma ("incorrect placement of pragma%");
2115 end Pragma_Misplaced;
2117 ------------------------------------
2118 -- Process Atomic_Shared_Volatile --
2119 ------------------------------------
2121 procedure Process_Atomic_Shared_Volatile is
2128 procedure Set_Atomic (E : Entity_Id);
2129 -- Set given type as atomic, and if no explicit alignment was given,
2130 -- set alignment to unknown, since back end knows what the alignment
2131 -- requirements are for atomic arrays. Note: this step is necessary
2132 -- for derived types.
2138 procedure Set_Atomic (E : Entity_Id) is
2142 if not Has_Alignment_Clause (E) then
2143 Set_Alignment (E, Uint_0);
2147 -- Start of processing for Process_Atomic_Shared_Volatile
2150 Check_Ada_83_Warning;
2151 Check_No_Identifiers;
2152 Check_Arg_Count (1);
2153 Check_Arg_Is_Local_Name (Arg1);
2154 E_Id := Expression (Arg1);
2156 if Etype (E_Id) = Any_Type then
2161 D := Declaration_Node (E);
2165 if Rep_Item_Too_Early (E, N)
2167 Rep_Item_Too_Late (E, N)
2171 Check_First_Subtype (Arg1);
2174 if Prag_Id /= Pragma_Volatile then
2176 Set_Atomic (Underlying_Type (E));
2177 Set_Atomic (Base_Type (E));
2180 -- Attribute belongs on the base type. If the view of the type is
2181 -- currently private, it also belongs on the underlying type.
2183 Set_Is_Volatile (Base_Type (E));
2184 Set_Is_Volatile (Underlying_Type (E));
2186 Set_Treat_As_Volatile (E);
2187 Set_Treat_As_Volatile (Underlying_Type (E));
2189 elsif K = N_Object_Declaration
2190 or else (K = N_Component_Declaration
2191 and then Original_Record_Component (E) = E)
2193 if Rep_Item_Too_Late (E, N) then
2197 if Prag_Id /= Pragma_Volatile then
2200 -- If the object declaration has an explicit initialization, a
2201 -- temporary may have to be created to hold the expression, to
2202 -- ensure that access to the object remain atomic.
2204 if Nkind (Parent (E)) = N_Object_Declaration
2205 and then Present (Expression (Parent (E)))
2207 Set_Has_Delayed_Freeze (E);
2210 -- An interesting improvement here. If an object of type X is
2211 -- declared atomic, and the type X is not atomic, that's a
2212 -- pity, since it may not have appropriate alignment etc. We
2213 -- can rescue this in the special case where the object and
2214 -- type are in the same unit by just setting the type as
2215 -- atomic, so that the back end will process it as atomic.
2217 Utyp := Underlying_Type (Etype (E));
2220 and then Sloc (E) > No_Location
2221 and then Sloc (Utyp) > No_Location
2223 Get_Source_File_Index (Sloc (E)) =
2224 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2226 Set_Is_Atomic (Underlying_Type (Etype (E)));
2230 Set_Is_Volatile (E);
2231 Set_Treat_As_Volatile (E);
2235 ("inappropriate entity for pragma%", Arg1);
2237 end Process_Atomic_Shared_Volatile;
2239 -------------------------------------------
2240 -- Process_Compile_Time_Warning_Or_Error --
2241 -------------------------------------------
2243 procedure Process_Compile_Time_Warning_Or_Error is
2244 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2247 Check_Arg_Count (2);
2248 Check_No_Identifiers;
2249 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2250 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2252 if Compile_Time_Known_Value (Arg1x) then
2253 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2255 Str : constant String_Id :=
2256 Strval (Get_Pragma_Arg (Arg2));
2257 Len : constant Int := String_Length (Str);
2262 Cent : constant Entity_Id :=
2263 Cunit_Entity (Current_Sem_Unit);
2265 Force : constant Boolean :=
2266 Prag_Id = Pragma_Compile_Time_Warning
2268 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2269 and then (Ekind (Cent) /= E_Package
2270 or else not In_Private_Part (Cent));
2271 -- Set True if this is the warning case, and we are in the
2272 -- visible part of a package spec, or in a subprogram spec,
2273 -- in which case we want to force the client to see the
2274 -- warning, even though it is not in the main unit.
2277 -- Loop through segments of message separated by line feeds.
2278 -- We output these segments as separate messages with
2279 -- continuation marks for all but the first.
2284 Error_Msg_Strlen := 0;
2286 -- Loop to copy characters from argument to error message
2290 exit when Ptr > Len;
2291 CC := Get_String_Char (Str, Ptr);
2294 -- Ignore wide chars ??? else store character
2296 if In_Character_Range (CC) then
2297 C := Get_Character (CC);
2298 exit when C = ASCII.LF;
2299 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2300 Error_Msg_String (Error_Msg_Strlen) := C;
2304 -- Here with one line ready to go
2306 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2308 -- If this is a warning in a spec, then we want clients
2309 -- to see the warning, so mark the message with the
2310 -- special sequence !! to force the warning. In the case
2311 -- of a package spec, we do not force this if we are in
2312 -- the private part of the spec.
2315 if Cont = False then
2316 Error_Msg_N ("<~!!", Arg1);
2319 Error_Msg_N ("\<~!!", Arg1);
2322 -- Error, rather than warning, or in a body, so we do not
2323 -- need to force visibility for client (error will be
2324 -- output in any case, and this is the situation in which
2325 -- we do not want a client to get a warning, since the
2326 -- warning is in the body or the spec private part.
2329 if Cont = False then
2330 Error_Msg_N ("<~", Arg1);
2333 Error_Msg_N ("\<~", Arg1);
2337 exit when Ptr > Len;
2342 end Process_Compile_Time_Warning_Or_Error;
2344 ------------------------
2345 -- Process_Convention --
2346 ------------------------
2348 procedure Process_Convention
2349 (C : out Convention_Id;
2355 Comp_Unit : Unit_Number_Type;
2357 procedure Set_Convention_From_Pragma (E : Entity_Id);
2358 -- Set convention in entity E, and also flag that the entity has a
2359 -- convention pragma. If entity is for a private or incomplete type,
2360 -- also set convention and flag on underlying type. This procedure
2361 -- also deals with the special case of C_Pass_By_Copy convention.
2363 --------------------------------
2364 -- Set_Convention_From_Pragma --
2365 --------------------------------
2367 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2369 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2370 -- for an overridden dispatching operation. Technically this is
2371 -- an amendment and should only be done in Ada 2005 mode. However,
2372 -- this is clearly a mistake, since the problem that is addressed
2373 -- by this AI is that there is a clear gap in the RM!
2375 if Is_Dispatching_Operation (E)
2376 and then Present (Overridden_Operation (E))
2377 and then C /= Convention (Overridden_Operation (E))
2380 ("cannot change convention for " &
2381 "overridden dispatching operation",
2385 -- Set the convention
2387 Set_Convention (E, C);
2388 Set_Has_Convention_Pragma (E);
2390 if Is_Incomplete_Or_Private_Type (E) then
2391 Set_Convention (Underlying_Type (E), C);
2392 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2395 -- A class-wide type should inherit the convention of the specific
2396 -- root type (although this isn't specified clearly by the RM).
2398 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2399 Set_Convention (Class_Wide_Type (E), C);
2402 -- If the entity is a record type, then check for special case of
2403 -- C_Pass_By_Copy, which is treated the same as C except that the
2404 -- special record flag is set. This convention is only permitted
2405 -- on record types (see AI95-00131).
2407 if Cname = Name_C_Pass_By_Copy then
2408 if Is_Record_Type (E) then
2409 Set_C_Pass_By_Copy (Base_Type (E));
2410 elsif Is_Incomplete_Or_Private_Type (E)
2411 and then Is_Record_Type (Underlying_Type (E))
2413 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2416 ("C_Pass_By_Copy convention allowed only for record type",
2421 -- If the entity is a derived boolean type, check for the special
2422 -- case of convention C, C++, or Fortran, where we consider any
2423 -- nonzero value to represent true.
2425 if Is_Discrete_Type (E)
2426 and then Root_Type (Etype (E)) = Standard_Boolean
2432 C = Convention_Fortran)
2434 Set_Nonzero_Is_True (Base_Type (E));
2436 end Set_Convention_From_Pragma;
2438 -- Start of processing for Process_Convention
2441 Check_At_Least_N_Arguments (2);
2442 Check_Optional_Identifier (Arg1, Name_Convention);
2443 Check_Arg_Is_Identifier (Arg1);
2444 Cname := Chars (Expression (Arg1));
2446 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2447 -- tested again below to set the critical flag).
2448 if Cname = Name_C_Pass_By_Copy then
2451 -- Otherwise we must have something in the standard convention list
2453 elsif Is_Convention_Name (Cname) then
2454 C := Get_Convention_Id (Chars (Expression (Arg1)));
2456 -- In DEC VMS, it seems that there is an undocumented feature that
2457 -- any unrecognized convention is treated as the default, which for
2458 -- us is convention C. It does not seem so terrible to do this
2459 -- unconditionally, silently in the VMS case, and with a warning
2460 -- in the non-VMS case.
2463 if Warn_On_Export_Import and not OpenVMS_On_Target then
2465 ("?unrecognized convention name, C assumed",
2472 Check_Optional_Identifier (Arg2, Name_Entity);
2473 Check_Arg_Is_Local_Name (Arg2);
2475 Id := Expression (Arg2);
2478 if not Is_Entity_Name (Id) then
2479 Error_Pragma_Arg ("entity name required", Arg2);
2484 -- Go to renamed subprogram if present, since convention applies to
2485 -- the actual renamed entity, not to the renaming entity. If the
2486 -- subprogram is inherited, go to parent subprogram.
2488 if Is_Subprogram (E)
2489 and then Present (Alias (E))
2491 if Nkind (Parent (Declaration_Node (E))) =
2492 N_Subprogram_Renaming_Declaration
2494 if Scope (E) /= Scope (Alias (E)) then
2496 ("cannot apply pragma% to non-local entity&#", E);
2501 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2502 N_Private_Extension_Declaration)
2503 and then Scope (E) = Scope (Alias (E))
2509 -- Check that we are not applying this to a specless body
2511 if Is_Subprogram (E)
2512 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2515 ("pragma% requires separate spec and must come before body");
2518 -- Check that we are not applying this to a named constant
2520 if Ekind (E) = E_Named_Integer
2522 Ekind (E) = E_Named_Real
2524 Error_Msg_Name_1 := Pname;
2526 ("cannot apply pragma% to named constant!",
2527 Get_Pragma_Arg (Arg2));
2529 ("\supply appropriate type for&!", Arg2);
2532 if Ekind (E) = E_Enumeration_Literal then
2533 Error_Pragma ("enumeration literal not allowed for pragma%");
2536 -- Check for rep item appearing too early or too late
2538 if Etype (E) = Any_Type
2539 or else Rep_Item_Too_Early (E, N)
2543 E := Underlying_Type (E);
2546 if Rep_Item_Too_Late (E, N) then
2550 if Has_Convention_Pragma (E) then
2552 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2554 elsif Convention (E) = Convention_Protected
2555 or else Ekind (Scope (E)) = E_Protected_Type
2558 ("a protected operation cannot be given a different convention",
2562 -- For Intrinsic, a subprogram is required
2564 if C = Convention_Intrinsic
2565 and then not Is_Subprogram (E)
2566 and then not Is_Generic_Subprogram (E)
2569 ("second argument of pragma% must be a subprogram", Arg2);
2572 -- For Stdcall, a subprogram, variable or subprogram type is required
2574 if C = Convention_Stdcall
2575 and then not Is_Subprogram (E)
2576 and then not Is_Generic_Subprogram (E)
2577 and then Ekind (E) /= E_Variable
2580 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2583 ("second argument of pragma% must be subprogram (type)",
2587 if not Is_Subprogram (E)
2588 and then not Is_Generic_Subprogram (E)
2590 Set_Convention_From_Pragma (E);
2594 Check_First_Subtype (Arg2);
2595 Set_Convention_From_Pragma (Base_Type (E));
2597 -- For subprograms, we must set the convention on the
2598 -- internally generated directly designated type as well.
2600 if Ekind (E) = E_Access_Subprogram_Type then
2601 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2605 -- For the subprogram case, set proper convention for all homonyms
2606 -- in same scope and the same declarative part, i.e. the same
2607 -- compilation unit.
2610 Comp_Unit := Get_Source_Unit (E);
2611 Set_Convention_From_Pragma (E);
2613 -- Treat a pragma Import as an implicit body, for GPS use
2615 if Prag_Id = Pragma_Import then
2616 Generate_Reference (E, Id, 'b');
2622 exit when No (E1) or else Scope (E1) /= Current_Scope;
2624 -- Do not set the pragma on inherited operations or on formal
2627 if Comes_From_Source (E1)
2628 and then Comp_Unit = Get_Source_Unit (E1)
2629 and then not Is_Formal_Subprogram (E1)
2630 and then Nkind (Original_Node (Parent (E1))) /=
2631 N_Full_Type_Declaration
2633 if Present (Alias (E1))
2634 and then Scope (E1) /= Scope (Alias (E1))
2637 ("cannot apply pragma% to non-local entity& declared#",
2641 Set_Convention_From_Pragma (E1);
2643 if Prag_Id = Pragma_Import then
2644 Generate_Reference (E, Id, 'b');
2649 end Process_Convention;
2651 -----------------------------------------------------
2652 -- Process_Extended_Import_Export_Exception_Pragma --
2653 -----------------------------------------------------
2655 procedure Process_Extended_Import_Export_Exception_Pragma
2656 (Arg_Internal : Node_Id;
2657 Arg_External : Node_Id;
2665 if not OpenVMS_On_Target then
2667 ("?pragma% ignored (applies only to Open'V'M'S)");
2670 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2671 Def_Id := Entity (Arg_Internal);
2673 if Ekind (Def_Id) /= E_Exception then
2675 ("pragma% must refer to declared exception", Arg_Internal);
2678 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2680 if Present (Arg_Form) then
2681 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2684 if Present (Arg_Form)
2685 and then Chars (Arg_Form) = Name_Ada
2689 Set_Is_VMS_Exception (Def_Id);
2690 Set_Exception_Code (Def_Id, No_Uint);
2693 if Present (Arg_Code) then
2694 if not Is_VMS_Exception (Def_Id) then
2696 ("Code option for pragma% not allowed for Ada case",
2700 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2701 Code_Val := Expr_Value (Arg_Code);
2703 if not UI_Is_In_Int_Range (Code_Val) then
2705 ("Code option for pragma% must be in 32-bit range",
2709 Set_Exception_Code (Def_Id, Code_Val);
2712 end Process_Extended_Import_Export_Exception_Pragma;
2714 -------------------------------------------------
2715 -- Process_Extended_Import_Export_Internal_Arg --
2716 -------------------------------------------------
2718 procedure Process_Extended_Import_Export_Internal_Arg
2719 (Arg_Internal : Node_Id := Empty)
2722 if No (Arg_Internal) then
2723 Error_Pragma ("Internal parameter required for pragma%");
2726 if Nkind (Arg_Internal) = N_Identifier then
2729 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2730 and then (Prag_Id = Pragma_Import_Function
2732 Prag_Id = Pragma_Export_Function)
2738 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2741 Check_Arg_Is_Local_Name (Arg_Internal);
2742 end Process_Extended_Import_Export_Internal_Arg;
2744 --------------------------------------------------
2745 -- Process_Extended_Import_Export_Object_Pragma --
2746 --------------------------------------------------
2748 procedure Process_Extended_Import_Export_Object_Pragma
2749 (Arg_Internal : Node_Id;
2750 Arg_External : Node_Id;
2756 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2757 Def_Id := Entity (Arg_Internal);
2759 if Ekind (Def_Id) /= E_Constant
2760 and then Ekind (Def_Id) /= E_Variable
2763 ("pragma% must designate an object", Arg_Internal);
2766 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2768 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2771 ("previous Common/Psect_Object applies, pragma % not permitted",
2775 if Rep_Item_Too_Late (Def_Id, N) then
2779 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2781 if Present (Arg_Size) then
2782 Check_Arg_Is_External_Name (Arg_Size);
2785 -- Export_Object case
2787 if Prag_Id = Pragma_Export_Object then
2788 if not Is_Library_Level_Entity (Def_Id) then
2790 ("argument for pragma% must be library level entity",
2794 if Ekind (Current_Scope) = E_Generic_Package then
2795 Error_Pragma ("pragma& cannot appear in a generic unit");
2798 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2800 ("exported object must have compile time known size",
2804 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2805 Error_Msg_N ("?duplicate Export_Object pragma", N);
2807 Set_Exported (Def_Id, Arg_Internal);
2810 -- Import_Object case
2813 if Is_Concurrent_Type (Etype (Def_Id)) then
2815 ("cannot use pragma% for task/protected object",
2819 if Ekind (Def_Id) = E_Constant then
2821 ("cannot import a constant", Arg_Internal);
2824 if Warn_On_Export_Import
2825 and then Has_Discriminants (Etype (Def_Id))
2828 ("imported value must be initialized?", Arg_Internal);
2831 if Warn_On_Export_Import
2832 and then Is_Access_Type (Etype (Def_Id))
2835 ("cannot import object of an access type?", Arg_Internal);
2838 if Warn_On_Export_Import
2839 and then Is_Imported (Def_Id)
2842 ("?duplicate Import_Object pragma", N);
2844 -- Check for explicit initialization present. Note that an
2845 -- initialization generated by the code generator, e.g. for an
2846 -- access type, does not count here.
2848 elsif Present (Expression (Parent (Def_Id)))
2851 (Original_Node (Expression (Parent (Def_Id))))
2853 Error_Msg_Sloc := Sloc (Def_Id);
2855 ("imported entities cannot be initialized (RM B.1(24))",
2856 "\no initialization allowed for & declared#", Arg1);
2858 Set_Imported (Def_Id);
2859 Note_Possible_Modification (Arg_Internal, Sure => False);
2862 end Process_Extended_Import_Export_Object_Pragma;
2864 ------------------------------------------------------
2865 -- Process_Extended_Import_Export_Subprogram_Pragma --
2866 ------------------------------------------------------
2868 procedure Process_Extended_Import_Export_Subprogram_Pragma
2869 (Arg_Internal : Node_Id;
2870 Arg_External : Node_Id;
2871 Arg_Parameter_Types : Node_Id;
2872 Arg_Result_Type : Node_Id := Empty;
2873 Arg_Mechanism : Node_Id;
2874 Arg_Result_Mechanism : Node_Id := Empty;
2875 Arg_First_Optional_Parameter : Node_Id := Empty)
2881 Ambiguous : Boolean;
2885 function Same_Base_Type
2887 Formal : Entity_Id) return Boolean;
2888 -- Determines if Ptype references the type of Formal. Note that only
2889 -- the base types need to match according to the spec. Ptype here is
2890 -- the argument from the pragma, which is either a type name, or an
2891 -- access attribute.
2893 --------------------
2894 -- Same_Base_Type --
2895 --------------------
2897 function Same_Base_Type
2899 Formal : Entity_Id) return Boolean
2901 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2905 -- Case where pragma argument is typ'Access
2907 if Nkind (Ptype) = N_Attribute_Reference
2908 and then Attribute_Name (Ptype) = Name_Access
2910 Pref := Prefix (Ptype);
2913 if not Is_Entity_Name (Pref)
2914 or else Entity (Pref) = Any_Type
2919 -- We have a match if the corresponding argument is of an
2920 -- anonymous access type, and its designated type matches the
2921 -- type of the prefix of the access attribute
2923 return Ekind (Ftyp) = E_Anonymous_Access_Type
2924 and then Base_Type (Entity (Pref)) =
2925 Base_Type (Etype (Designated_Type (Ftyp)));
2927 -- Case where pragma argument is a type name
2932 if not Is_Entity_Name (Ptype)
2933 or else Entity (Ptype) = Any_Type
2938 -- We have a match if the corresponding argument is of the type
2939 -- given in the pragma (comparing base types)
2941 return Base_Type (Entity (Ptype)) = Ftyp;
2945 -- Start of processing for
2946 -- Process_Extended_Import_Export_Subprogram_Pragma
2949 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2953 -- Loop through homonyms (overloadings) of the entity
2955 Hom_Id := Entity (Arg_Internal);
2956 while Present (Hom_Id) loop
2957 Def_Id := Get_Base_Subprogram (Hom_Id);
2959 -- We need a subprogram in the current scope
2961 if not Is_Subprogram (Def_Id)
2962 or else Scope (Def_Id) /= Current_Scope
2969 -- Pragma cannot apply to subprogram body
2971 if Is_Subprogram (Def_Id)
2972 and then Nkind (Parent (Declaration_Node (Def_Id))) =
2976 ("pragma% requires separate spec"
2977 & " and must come before body");
2980 -- Test result type if given, note that the result type
2981 -- parameter can only be present for the function cases.
2983 if Present (Arg_Result_Type)
2984 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2988 elsif Etype (Def_Id) /= Standard_Void_Type
2990 (Pname = Name_Export_Procedure
2992 Pname = Name_Import_Procedure)
2996 -- Test parameter types if given. Note that this parameter
2997 -- has not been analyzed (and must not be, since it is
2998 -- semantic nonsense), so we get it as the parser left it.
3000 elsif Present (Arg_Parameter_Types) then
3001 Check_Matching_Types : declare
3006 Formal := First_Formal (Def_Id);
3008 if Nkind (Arg_Parameter_Types) = N_Null then
3009 if Present (Formal) then
3013 -- A list of one type, e.g. (List) is parsed as
3014 -- a parenthesized expression.
3016 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3017 and then Paren_Count (Arg_Parameter_Types) = 1
3020 or else Present (Next_Formal (Formal))
3025 Same_Base_Type (Arg_Parameter_Types, Formal);
3028 -- A list of more than one type is parsed as a aggregate
3030 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3031 and then Paren_Count (Arg_Parameter_Types) = 0
3033 Ptype := First (Expressions (Arg_Parameter_Types));
3034 while Present (Ptype) or else Present (Formal) loop
3037 or else not Same_Base_Type (Ptype, Formal)
3042 Next_Formal (Formal);
3047 -- Anything else is of the wrong form
3051 ("wrong form for Parameter_Types parameter",
3052 Arg_Parameter_Types);
3054 end Check_Matching_Types;
3057 -- Match is now False if the entry we found did not match
3058 -- either a supplied Parameter_Types or Result_Types argument
3064 -- Ambiguous case, the flag Ambiguous shows if we already
3065 -- detected this and output the initial messages.
3068 if not Ambiguous then
3070 Error_Msg_Name_1 := Pname;
3072 ("pragma% does not uniquely identify subprogram!",
3074 Error_Msg_Sloc := Sloc (Ent);
3075 Error_Msg_N ("matching subprogram #!", N);
3079 Error_Msg_Sloc := Sloc (Def_Id);
3080 Error_Msg_N ("matching subprogram #!", N);
3085 Hom_Id := Homonym (Hom_Id);
3088 -- See if we found an entry
3091 if not Ambiguous then
3092 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3094 ("pragma% cannot be given for generic subprogram");
3097 ("pragma% does not identify local subprogram");
3104 -- Import pragmas must be for imported entities
3106 if Prag_Id = Pragma_Import_Function
3108 Prag_Id = Pragma_Import_Procedure
3110 Prag_Id = Pragma_Import_Valued_Procedure
3112 if not Is_Imported (Ent) then
3113 Error_Pragma -- CODEFIX???
3114 ("pragma Import or Interface must precede pragma%");
3117 -- Here we have the Export case which can set the entity as exported
3119 -- But does not do so if the specified external name is null, since
3120 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3121 -- compatible) to request no external name.
3123 elsif Nkind (Arg_External) = N_String_Literal
3124 and then String_Length (Strval (Arg_External)) = 0
3128 -- In all other cases, set entity as exported
3131 Set_Exported (Ent, Arg_Internal);
3134 -- Special processing for Valued_Procedure cases
3136 if Prag_Id = Pragma_Import_Valued_Procedure
3138 Prag_Id = Pragma_Export_Valued_Procedure
3140 Formal := First_Formal (Ent);
3143 Error_Pragma ("at least one parameter required for pragma%");
3145 elsif Ekind (Formal) /= E_Out_Parameter then
3146 Error_Pragma ("first parameter must have mode out for pragma%");
3149 Set_Is_Valued_Procedure (Ent);
3153 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3155 -- Process Result_Mechanism argument if present. We have already
3156 -- checked that this is only allowed for the function case.
3158 if Present (Arg_Result_Mechanism) then
3159 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3162 -- Process Mechanism parameter if present. Note that this parameter
3163 -- is not analyzed, and must not be analyzed since it is semantic
3164 -- nonsense, so we get it in exactly as the parser left it.
3166 if Present (Arg_Mechanism) then
3174 -- A single mechanism association without a formal parameter
3175 -- name is parsed as a parenthesized expression. All other
3176 -- cases are parsed as aggregates, so we rewrite the single
3177 -- parameter case as an aggregate for consistency.
3179 if Nkind (Arg_Mechanism) /= N_Aggregate
3180 and then Paren_Count (Arg_Mechanism) = 1
3182 Rewrite (Arg_Mechanism,
3183 Make_Aggregate (Sloc (Arg_Mechanism),
3184 Expressions => New_List (
3185 Relocate_Node (Arg_Mechanism))));
3188 -- Case of only mechanism name given, applies to all formals
3190 if Nkind (Arg_Mechanism) /= N_Aggregate then
3191 Formal := First_Formal (Ent);
3192 while Present (Formal) loop
3193 Set_Mechanism_Value (Formal, Arg_Mechanism);
3194 Next_Formal (Formal);
3197 -- Case of list of mechanism associations given
3200 if Null_Record_Present (Arg_Mechanism) then
3202 ("inappropriate form for Mechanism parameter",
3206 -- Deal with positional ones first
3208 Formal := First_Formal (Ent);
3210 if Present (Expressions (Arg_Mechanism)) then
3211 Mname := First (Expressions (Arg_Mechanism));
3212 while Present (Mname) loop
3215 ("too many mechanism associations", Mname);
3218 Set_Mechanism_Value (Formal, Mname);
3219 Next_Formal (Formal);
3224 -- Deal with named entries
3226 if Present (Component_Associations (Arg_Mechanism)) then
3227 Massoc := First (Component_Associations (Arg_Mechanism));
3228 while Present (Massoc) loop
3229 Choice := First (Choices (Massoc));
3231 if Nkind (Choice) /= N_Identifier
3232 or else Present (Next (Choice))
3235 ("incorrect form for mechanism association",
3239 Formal := First_Formal (Ent);
3243 ("parameter name & not present", Choice);
3246 if Chars (Choice) = Chars (Formal) then
3248 (Formal, Expression (Massoc));
3250 -- Set entity on identifier for ASIS
3252 Set_Entity (Choice, Formal);
3257 Next_Formal (Formal);
3267 -- Process First_Optional_Parameter argument if present. We have
3268 -- already checked that this is only allowed for the Import case.
3270 if Present (Arg_First_Optional_Parameter) then
3271 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3273 ("first optional parameter must be formal parameter name",
3274 Arg_First_Optional_Parameter);
3277 Formal := First_Formal (Ent);
3281 ("specified formal parameter& not found",
3282 Arg_First_Optional_Parameter);
3285 exit when Chars (Formal) =
3286 Chars (Arg_First_Optional_Parameter);
3288 Next_Formal (Formal);
3291 Set_First_Optional_Parameter (Ent, Formal);
3293 -- Check specified and all remaining formals have right form
3295 while Present (Formal) loop
3296 if Ekind (Formal) /= E_In_Parameter then
3298 ("optional formal& is not of mode in!",
3299 Arg_First_Optional_Parameter, Formal);
3302 Dval := Default_Value (Formal);
3306 ("optional formal& does not have default value!",
3307 Arg_First_Optional_Parameter, Formal);
3309 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3314 ("default value for optional formal& is non-static!",
3315 Arg_First_Optional_Parameter, Formal);
3319 Set_Is_Optional_Parameter (Formal);
3320 Next_Formal (Formal);
3323 end Process_Extended_Import_Export_Subprogram_Pragma;
3325 --------------------------
3326 -- Process_Generic_List --
3327 --------------------------
3329 procedure Process_Generic_List is
3334 Check_No_Identifiers;
3335 Check_At_Least_N_Arguments (1);
3338 while Present (Arg) loop
3339 Exp := Expression (Arg);
3342 if not Is_Entity_Name (Exp)
3344 (not Is_Generic_Instance (Entity (Exp))
3346 not Is_Generic_Unit (Entity (Exp)))
3349 ("pragma% argument must be name of generic unit/instance",
3355 end Process_Generic_List;
3357 ---------------------------------
3358 -- Process_Import_Or_Interface --
3359 ---------------------------------
3361 procedure Process_Import_Or_Interface is
3367 Process_Convention (C, Def_Id);
3368 Kill_Size_Check_Code (Def_Id);
3369 Note_Possible_Modification (Expression (Arg2), Sure => False);
3371 if Ekind (Def_Id) = E_Variable
3373 Ekind (Def_Id) = E_Constant
3375 -- We do not permit Import to apply to a renaming declaration
3377 if Present (Renamed_Object (Def_Id)) then
3379 ("pragma% not allowed for object renaming", Arg2);
3381 -- User initialization is not allowed for imported object, but
3382 -- the object declaration may contain a default initialization,
3383 -- that will be discarded. Note that an explicit initialization
3384 -- only counts if it comes from source, otherwise it is simply
3385 -- the code generator making an implicit initialization explicit.
3387 elsif Present (Expression (Parent (Def_Id)))
3388 and then Comes_From_Source (Expression (Parent (Def_Id)))
3390 Error_Msg_Sloc := Sloc (Def_Id);
3392 ("no initialization allowed for declaration of& #",
3393 "\imported entities cannot be initialized (RM B.1(24))",
3397 Set_Imported (Def_Id);
3398 Process_Interface_Name (Def_Id, Arg3, Arg4);
3400 -- Note that we do not set Is_Public here. That's because we
3401 -- only want to set it if there is no address clause, and we
3402 -- don't know that yet, so we delay that processing till
3405 -- pragma Import completes deferred constants
3407 if Ekind (Def_Id) = E_Constant then
3408 Set_Has_Completion (Def_Id);
3411 -- It is not possible to import a constant of an unconstrained
3412 -- array type (e.g. string) because there is no simple way to
3413 -- write a meaningful subtype for it.
3415 if Is_Array_Type (Etype (Def_Id))
3416 and then not Is_Constrained (Etype (Def_Id))
3419 ("imported constant& must have a constrained subtype",
3424 elsif Is_Subprogram (Def_Id)
3425 or else Is_Generic_Subprogram (Def_Id)
3427 -- If the name is overloaded, pragma applies to all of the
3428 -- denoted entities in the same declarative part.
3431 while Present (Hom_Id) loop
3432 Def_Id := Get_Base_Subprogram (Hom_Id);
3434 -- Ignore inherited subprograms because the pragma will
3435 -- apply to the parent operation, which is the one called.
3437 if Is_Overloadable (Def_Id)
3438 and then Present (Alias (Def_Id))
3442 -- If it is not a subprogram, it must be in an outer scope and
3443 -- pragma does not apply.
3445 elsif not Is_Subprogram (Def_Id)
3446 and then not Is_Generic_Subprogram (Def_Id)
3450 -- Verify that the homonym is in the same declarative part (not
3451 -- just the same scope).
3453 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3454 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3459 Set_Imported (Def_Id);
3461 -- Special processing for Convention_Intrinsic
3463 if C = Convention_Intrinsic then
3465 -- Link_Name argument not allowed for intrinsic
3468 and then Chars (Arg3) = Name_Link_Name
3473 if Present (Arg4) then
3475 ("Link_Name argument not allowed for " &
3480 Set_Is_Intrinsic_Subprogram (Def_Id);
3482 -- If no external name is present, then check that this
3483 -- is a valid intrinsic subprogram. If an external name
3484 -- is present, then this is handled by the back end.
3487 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3491 -- All interfaced procedures need an external symbol created
3492 -- for them since they are always referenced from another
3495 Set_Is_Public (Def_Id);
3497 -- Verify that the subprogram does not have a completion
3498 -- through a renaming declaration. For other completions the
3499 -- pragma appears as a too late representation.
3502 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3506 and then Nkind (Decl) = N_Subprogram_Declaration
3507 and then Present (Corresponding_Body (Decl))
3508 and then Nkind (Unit_Declaration_Node
3509 (Corresponding_Body (Decl))) =
3510 N_Subprogram_Renaming_Declaration
3512 Error_Msg_Sloc := Sloc (Def_Id);
3514 ("cannot import&, renaming already provided for " &
3515 "declaration #", N, Def_Id);
3519 Set_Has_Completion (Def_Id);
3520 Process_Interface_Name (Def_Id, Arg3, Arg4);
3523 if Is_Compilation_Unit (Hom_Id) then
3525 -- Its possible homonyms are not affected by the pragma.
3526 -- Such homonyms might be present in the context of other
3527 -- units being compiled.
3532 Hom_Id := Homonym (Hom_Id);
3536 -- When the convention is Java or CIL, we also allow Import to be
3537 -- given for packages, generic packages, exceptions, record
3538 -- components, and access to subprograms.
3540 elsif (C = Convention_Java or else C = Convention_CIL)
3542 (Is_Package_Or_Generic_Package (Def_Id)
3543 or else Ekind (Def_Id) = E_Exception
3544 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3545 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3547 Set_Imported (Def_Id);
3548 Set_Is_Public (Def_Id);
3549 Process_Interface_Name (Def_Id, Arg3, Arg4);
3551 -- Import a CPP class
3553 elsif Is_Record_Type (Def_Id)
3554 and then C = Convention_CPP
3556 if not Is_Tagged_Type (Def_Id) then
3557 Error_Msg_Sloc := Sloc (Def_Id);
3558 Error_Pragma_Arg ("imported 'C'P'P type must be tagged", Arg2);
3561 -- Types treated as CPP classes are treated as limited, but we
3562 -- don't require them to be declared this way. A warning is
3563 -- issued to encourage the user to declare them as limited.
3564 -- This is not an error, for compatibility reasons, because
3565 -- these types have been supported this way for some time.
3567 if not Is_Limited_Type (Def_Id) then
3569 ("imported 'C'P'P type should be " &
3570 "explicitly declared limited?",
3571 Get_Pragma_Arg (Arg2));
3573 ("\type will be considered limited",
3574 Get_Pragma_Arg (Arg2));
3577 Set_Is_CPP_Class (Def_Id);
3578 Set_Is_Limited_Record (Def_Id);
3580 -- Imported CPP types must not have discriminants (because C++
3581 -- classes do not have discriminants).
3583 if Has_Discriminants (Def_Id) then
3585 ("imported 'C'P'P type cannot have discriminants",
3586 First (Discriminant_Specifications
3587 (Declaration_Node (Def_Id))));
3590 -- Components of imported CPP types must not have default
3591 -- expressions because the constructor (if any) is in the
3595 Tdef : constant Node_Id :=
3596 Type_Definition (Declaration_Node (Def_Id));
3601 if Nkind (Tdef) = N_Record_Definition then
3602 Clist := Component_List (Tdef);
3605 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3606 Clist := Component_List (Record_Extension_Part (Tdef));
3609 if Present (Clist) then
3610 Comp := First (Component_Items (Clist));
3611 while Present (Comp) loop
3612 if Present (Expression (Comp)) then
3614 ("component of imported 'C'P'P type cannot have" &
3615 " default expression", Expression (Comp));
3626 ("second argument of pragma% must be object or subprogram",
3630 -- If this pragma applies to a compilation unit, then the unit, which
3631 -- is a subprogram, does not require (or allow) a body. We also do
3632 -- not need to elaborate imported procedures.
3634 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3636 Cunit : constant Node_Id := Parent (Parent (N));
3638 Set_Body_Required (Cunit, False);
3641 end Process_Import_Or_Interface;
3643 --------------------
3644 -- Process_Inline --
3645 --------------------
3647 procedure Process_Inline (Active : Boolean) is
3653 Effective : Boolean := False;
3655 procedure Make_Inline (Subp : Entity_Id);
3656 -- Subp is the defining unit name of the subprogram declaration. Set
3657 -- the flag, as well as the flag in the corresponding body, if there
3660 procedure Set_Inline_Flags (Subp : Entity_Id);
3661 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3662 -- Has_Pragma_Inline_Always for the Inline_Always case.
3664 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3665 -- Returns True if it can be determined at this stage that inlining
3666 -- is not possible, for example if the body is available and contains
3667 -- exception handlers, we prevent inlining, since otherwise we can
3668 -- get undefined symbols at link time. This function also emits a
3669 -- warning if front-end inlining is enabled and the pragma appears
3672 -- ??? is business with link symbols still valid, or does it relate
3673 -- to front end ZCX which is being phased out ???
3675 ---------------------------
3676 -- Inlining_Not_Possible --
3677 ---------------------------
3679 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3680 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3684 if Nkind (Decl) = N_Subprogram_Body then
3685 Stats := Handled_Statement_Sequence (Decl);
3686 return Present (Exception_Handlers (Stats))
3687 or else Present (At_End_Proc (Stats));
3689 elsif Nkind (Decl) = N_Subprogram_Declaration
3690 and then Present (Corresponding_Body (Decl))
3692 if Front_End_Inlining
3693 and then Analyzed (Corresponding_Body (Decl))
3695 Error_Msg_N ("pragma appears too late, ignored?", N);
3698 -- If the subprogram is a renaming as body, the body is just a
3699 -- call to the renamed subprogram, and inlining is trivially
3703 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3704 N_Subprogram_Renaming_Declaration
3710 Handled_Statement_Sequence
3711 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3714 Present (Exception_Handlers (Stats))
3715 or else Present (At_End_Proc (Stats));
3719 -- If body is not available, assume the best, the check is
3720 -- performed again when compiling enclosing package bodies.
3724 end Inlining_Not_Possible;
3730 procedure Make_Inline (Subp : Entity_Id) is
3731 Kind : constant Entity_Kind := Ekind (Subp);
3732 Inner_Subp : Entity_Id := Subp;
3735 -- Ignore if bad type, avoid cascaded error
3737 if Etype (Subp) = Any_Type then
3741 -- Ignore if all inlining is suppressed
3743 elsif Suppress_All_Inlining then
3747 -- If inlining is not possible, for now do not treat as an error
3749 elsif Inlining_Not_Possible (Subp) then
3753 -- Here we have a candidate for inlining, but we must exclude
3754 -- derived operations. Otherwise we would end up trying to inline
3755 -- a phantom declaration, and the result would be to drag in a
3756 -- body which has no direct inlining associated with it. That
3757 -- would not only be inefficient but would also result in the
3758 -- backend doing cross-unit inlining in cases where it was
3759 -- definitely inappropriate to do so.
3761 -- However, a simple Comes_From_Source test is insufficient, since
3762 -- we do want to allow inlining of generic instances which also do
3763 -- not come from source. We also need to recognize specs generated
3764 -- by the front-end for bodies that carry the pragma. Finally,
3765 -- predefined operators do not come from source but are not
3766 -- inlineable either.
3768 elsif Is_Generic_Instance (Subp)
3769 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3773 elsif not Comes_From_Source (Subp)
3774 and then Scope (Subp) /= Standard_Standard
3780 -- The referenced entity must either be the enclosing entity, or
3781 -- an entity declared within the current open scope.
3783 if Present (Scope (Subp))
3784 and then Scope (Subp) /= Current_Scope
3785 and then Subp /= Current_Scope
3788 ("argument of% must be entity in current scope", Assoc);
3792 -- Processing for procedure, operator or function. If subprogram
3793 -- is aliased (as for an instance) indicate that the renamed
3794 -- entity (if declared in the same unit) is inlined.
3796 if Is_Subprogram (Subp) then
3797 while Present (Alias (Inner_Subp)) loop
3798 Inner_Subp := Alias (Inner_Subp);
3801 if In_Same_Source_Unit (Subp, Inner_Subp) then
3802 Set_Inline_Flags (Inner_Subp);
3804 Decl := Parent (Parent (Inner_Subp));
3806 if Nkind (Decl) = N_Subprogram_Declaration
3807 and then Present (Corresponding_Body (Decl))
3809 Set_Inline_Flags (Corresponding_Body (Decl));
3811 elsif Is_Generic_Instance (Subp) then
3813 -- Indicate that the body needs to be created for
3814 -- inlining subsequent calls. The instantiation node
3815 -- follows the declaration of the wrapper package
3818 if Scope (Subp) /= Standard_Standard
3820 Need_Subprogram_Instance_Body
3821 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3831 -- For a generic subprogram set flag as well, for use at the point
3832 -- of instantiation, to determine whether the body should be
3835 elsif Is_Generic_Subprogram (Subp) then
3836 Set_Inline_Flags (Subp);
3839 -- Literals are by definition inlined
3841 elsif Kind = E_Enumeration_Literal then
3844 -- Anything else is an error
3848 ("expect subprogram name for pragma%", Assoc);
3852 ----------------------
3853 -- Set_Inline_Flags --
3854 ----------------------
3856 procedure Set_Inline_Flags (Subp : Entity_Id) is
3859 Set_Is_Inlined (Subp, True);
3862 if not Has_Pragma_Inline (Subp) then
3863 Set_Has_Pragma_Inline (Subp);
3867 if Prag_Id = Pragma_Inline_Always then
3868 Set_Has_Pragma_Inline_Always (Subp);
3870 end Set_Inline_Flags;
3872 -- Start of processing for Process_Inline
3875 Check_No_Identifiers;
3876 Check_At_Least_N_Arguments (1);
3879 Inline_Processing_Required := True;
3883 while Present (Assoc) loop
3884 Subp_Id := Expression (Assoc);
3888 if Is_Entity_Name (Subp_Id) then
3889 Subp := Entity (Subp_Id);
3891 if Subp = Any_Id then
3893 -- If previous error, avoid cascaded errors
3901 while Present (Homonym (Subp))
3902 and then Scope (Homonym (Subp)) = Current_Scope
3904 Make_Inline (Homonym (Subp));
3905 Subp := Homonym (Subp);
3912 ("inappropriate argument for pragma%", Assoc);
3915 and then Warn_On_Redundant_Constructs
3916 and then not Suppress_All_Inlining
3918 if Inlining_Not_Possible (Subp) then
3920 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3923 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3931 ----------------------------
3932 -- Process_Interface_Name --
3933 ----------------------------
3935 procedure Process_Interface_Name
3936 (Subprogram_Def : Entity_Id;
3942 String_Val : String_Id;
3944 procedure Check_Form_Of_Interface_Name
3946 Ext_Name_Case : Boolean);
3947 -- SN is a string literal node for an interface name. This routine
3948 -- performs some minimal checks that the name is reasonable. In
3949 -- particular that no spaces or other obviously incorrect characters
3950 -- appear. This is only a warning, since any characters are allowed.
3951 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3953 ----------------------------------
3954 -- Check_Form_Of_Interface_Name --
3955 ----------------------------------
3957 procedure Check_Form_Of_Interface_Name
3959 Ext_Name_Case : Boolean)
3961 S : constant String_Id := Strval (Expr_Value_S (SN));
3962 SL : constant Nat := String_Length (S);
3967 Error_Msg_N ("interface name cannot be null string", SN);
3970 for J in 1 .. SL loop
3971 C := Get_String_Char (S, J);
3973 -- Look for dubious character and issue unconditional warning.
3974 -- Definitely dubious if not in character range.
3976 if not In_Character_Range (C)
3978 -- For all cases except CLI target,
3979 -- commas, spaces and slashes are dubious (in CLI, we use
3980 -- commas and backslashes in external names to specify
3981 -- assembly version and public key, while slashes and spaces
3982 -- can be used in names to mark nested classes and
3985 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
3986 and then (Get_Character (C) = ','
3988 Get_Character (C) = '\'))
3989 or else (VM_Target /= CLI_Target
3990 and then (Get_Character (C) = ' '
3992 Get_Character (C) = '/'))
3995 ("?interface name contains illegal character",
3996 Sloc (SN) + Source_Ptr (J));
3999 end Check_Form_Of_Interface_Name;
4001 -- Start of processing for Process_Interface_Name
4004 if No (Link_Arg) then
4005 if No (Ext_Arg) then
4006 if VM_Target = CLI_Target
4007 and then Ekind (Subprogram_Def) = E_Package
4008 and then Nkind (Parent (Subprogram_Def)) =
4009 N_Package_Specification
4010 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4015 (Generic_Parent (Parent (Subprogram_Def))));
4020 elsif Chars (Ext_Arg) = Name_Link_Name then
4022 Link_Nam := Expression (Ext_Arg);
4025 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4026 Ext_Nam := Expression (Ext_Arg);
4031 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4032 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4033 Ext_Nam := Expression (Ext_Arg);
4034 Link_Nam := Expression (Link_Arg);
4037 -- Check expressions for external name and link name are static
4039 if Present (Ext_Nam) then
4040 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4041 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4043 -- Verify that external name is not the name of a local entity,
4044 -- which would hide the imported one and could lead to run-time
4045 -- surprises. The problem can only arise for entities declared in
4046 -- a package body (otherwise the external name is fully qualified
4047 -- and will not conflict).
4055 if Prag_Id = Pragma_Import then
4056 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4058 E := Entity_Id (Get_Name_Table_Info (Nam));
4060 if Nam /= Chars (Subprogram_Def)
4061 and then Present (E)
4062 and then not Is_Overloadable (E)
4063 and then Is_Immediately_Visible (E)
4064 and then not Is_Imported (E)
4065 and then Ekind (Scope (E)) = E_Package
4068 while Present (Par) loop
4069 if Nkind (Par) = N_Package_Body then
4070 Error_Msg_Sloc := Sloc (E);
4072 ("imported entity is hidden by & declared#",
4077 Par := Parent (Par);
4084 if Present (Link_Nam) then
4085 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4086 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4089 -- If there is no link name, just set the external name
4091 if No (Link_Nam) then
4092 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4094 -- For the Link_Name case, the given literal is preceded by an
4095 -- asterisk, which indicates to GCC that the given name should be
4096 -- taken literally, and in particular that no prepending of
4097 -- underlines should occur, even in systems where this is the
4103 if VM_Target = No_VM then
4104 Store_String_Char (Get_Char_Code ('*'));
4107 String_Val := Strval (Expr_Value_S (Link_Nam));
4108 Store_String_Chars (String_Val);
4110 Make_String_Literal (Sloc (Link_Nam),
4111 Strval => End_String);
4114 Set_Encoded_Interface_Name
4115 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4116 Check_Duplicated_Export_Name (Link_Nam);
4117 end Process_Interface_Name;
4119 -----------------------------------------
4120 -- Process_Interrupt_Or_Attach_Handler --
4121 -----------------------------------------
4123 procedure Process_Interrupt_Or_Attach_Handler is
4124 Arg1_X : constant Node_Id := Expression (Arg1);
4125 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4126 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4129 Set_Is_Interrupt_Handler (Handler_Proc);
4131 -- If the pragma is not associated with a handler procedure within a
4132 -- protected type, then it must be for a nonprotected procedure for
4133 -- the AAMP target, in which case we don't associate a representation
4134 -- item with the procedure's scope.
4136 if Ekind (Proc_Scope) = E_Protected_Type then
4137 if Prag_Id = Pragma_Interrupt_Handler
4139 Prag_Id = Pragma_Attach_Handler
4141 Record_Rep_Item (Proc_Scope, N);
4144 end Process_Interrupt_Or_Attach_Handler;
4146 --------------------------------------------------
4147 -- Process_Restrictions_Or_Restriction_Warnings --
4148 --------------------------------------------------
4150 -- Note: some of the simple identifier cases were handled in par-prag,
4151 -- but it is harmless (and more straightforward) to simply handle all
4152 -- cases here, even if it means we repeat a bit of work in some cases.
4154 procedure Process_Restrictions_Or_Restriction_Warnings
4158 R_Id : Restriction_Id;
4163 procedure Check_Unit_Name (N : Node_Id);
4164 -- Checks unit name parameter for No_Dependence. Returns if it has
4165 -- an appropriate form, otherwise raises pragma argument error.
4167 ---------------------
4168 -- Check_Unit_Name --
4169 ---------------------
4171 procedure Check_Unit_Name (N : Node_Id) is
4173 if Nkind (N) = N_Selected_Component then
4174 Check_Unit_Name (Prefix (N));
4175 Check_Unit_Name (Selector_Name (N));
4177 elsif Nkind (N) = N_Identifier then
4182 ("wrong form for unit name for No_Dependence", N);
4184 end Check_Unit_Name;
4186 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4189 Check_Ada_83_Warning;
4190 Check_At_Least_N_Arguments (1);
4191 Check_Valid_Configuration_Pragma;
4194 while Present (Arg) loop
4196 Expr := Expression (Arg);
4198 -- Case of no restriction identifier present
4200 if Id = No_Name then
4201 if Nkind (Expr) /= N_Identifier then
4203 ("invalid form for restriction", Arg);
4208 (Process_Restriction_Synonyms (Expr));
4210 if R_Id not in All_Boolean_Restrictions then
4211 Error_Msg_Name_1 := Pname;
4213 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4215 -- Check for possible misspelling
4217 for J in Restriction_Id loop
4219 Rnm : constant String := Restriction_Id'Image (J);
4222 Name_Buffer (1 .. Rnm'Length) := Rnm;
4223 Name_Len := Rnm'Length;
4224 Set_Casing (All_Lower_Case);
4226 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4228 (Identifier_Casing (Current_Source_File));
4229 Error_Msg_String (1 .. Rnm'Length) :=
4230 Name_Buffer (1 .. Name_Len);
4231 Error_Msg_Strlen := Rnm'Length;
4232 Error_Msg_N -- CODEFIX
4233 ("\possible misspelling of ""~""",
4234 Get_Pragma_Arg (Arg));
4243 if Implementation_Restriction (R_Id) then
4244 Check_Restriction (No_Implementation_Restrictions, Arg);
4247 -- If this is a warning, then set the warning unless we already
4248 -- have a real restriction active (we never want a warning to
4249 -- override a real restriction).
4252 if not Restriction_Active (R_Id) then
4253 Set_Restriction (R_Id, N);
4254 Restriction_Warnings (R_Id) := True;
4257 -- If real restriction case, then set it and make sure that the
4258 -- restriction warning flag is off, since a real restriction
4259 -- always overrides a warning.
4262 Set_Restriction (R_Id, N);
4263 Restriction_Warnings (R_Id) := False;
4266 -- A very special case that must be processed here: pragma
4267 -- Restrictions (No_Exceptions) turns off all run-time
4268 -- checking. This is a bit dubious in terms of the formal
4269 -- language definition, but it is what is intended by RM
4270 -- H.4(12). Restriction_Warnings never affects generated code
4271 -- so this is done only in the real restriction case.
4273 if R_Id = No_Exceptions and then not Warn then
4274 Scope_Suppress := (others => True);
4277 -- Case of No_Dependence => unit-name. Note that the parser
4278 -- already made the necessary entry in the No_Dependence table.
4280 elsif Id = Name_No_Dependence then
4281 Check_Unit_Name (Expr);
4283 -- All other cases of restriction identifier present
4286 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4287 Analyze_And_Resolve (Expr, Any_Integer);
4289 if R_Id not in All_Parameter_Restrictions then
4291 ("invalid restriction parameter identifier", Arg);
4293 elsif not Is_OK_Static_Expression (Expr) then
4294 Flag_Non_Static_Expr
4295 ("value must be static expression!", Expr);
4298 elsif not Is_Integer_Type (Etype (Expr))
4299 or else Expr_Value (Expr) < 0
4302 ("value must be non-negative integer", Arg);
4305 -- Restriction pragma is active
4307 Val := Expr_Value (Expr);
4309 if not UI_Is_In_Int_Range (Val) then
4311 ("pragma ignored, value too large?", Arg);
4314 -- Warning case. If the real restriction is active, then we
4315 -- ignore the request, since warning never overrides a real
4316 -- restriction. Otherwise we set the proper warning. Note that
4317 -- this circuit sets the warning again if it is already set,
4318 -- which is what we want, since the constant may have changed.
4321 if not Restriction_Active (R_Id) then
4323 (R_Id, N, Integer (UI_To_Int (Val)));
4324 Restriction_Warnings (R_Id) := True;
4327 -- Real restriction case, set restriction and make sure warning
4328 -- flag is off since real restriction always overrides warning.
4331 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4332 Restriction_Warnings (R_Id) := False;
4338 end Process_Restrictions_Or_Restriction_Warnings;
4340 ---------------------------------
4341 -- Process_Suppress_Unsuppress --
4342 ---------------------------------
4344 -- Note: this procedure makes entries in the check suppress data
4345 -- structures managed by Sem. See spec of package Sem for full
4346 -- details on how we handle recording of check suppression.
4348 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4353 In_Package_Spec : constant Boolean :=
4354 Is_Package_Or_Generic_Package (Current_Scope)
4355 and then not In_Package_Body (Current_Scope);
4357 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4358 -- Used to suppress a single check on the given entity
4360 --------------------------------
4361 -- Suppress_Unsuppress_Echeck --
4362 --------------------------------
4364 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4366 Set_Checks_May_Be_Suppressed (E);
4368 if In_Package_Spec then
4369 Push_Global_Suppress_Stack_Entry
4372 Suppress => Suppress_Case);
4375 Push_Local_Suppress_Stack_Entry
4378 Suppress => Suppress_Case);
4381 -- If this is a first subtype, and the base type is distinct,
4382 -- then also set the suppress flags on the base type.
4384 if Is_First_Subtype (E)
4385 and then Etype (E) /= E
4387 Suppress_Unsuppress_Echeck (Etype (E), C);
4389 end Suppress_Unsuppress_Echeck;
4391 -- Start of processing for Process_Suppress_Unsuppress
4394 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4395 -- declarative part or a package spec (RM 11.5(5)).
4397 if not Is_Configuration_Pragma then
4398 Check_Is_In_Decl_Part_Or_Package_Spec;
4401 Check_At_Least_N_Arguments (1);
4402 Check_At_Most_N_Arguments (2);
4403 Check_No_Identifier (Arg1);
4404 Check_Arg_Is_Identifier (Arg1);
4406 C := Get_Check_Id (Chars (Expression (Arg1)));
4408 if C = No_Check_Id then
4410 ("argument of pragma% is not valid check name", Arg1);
4413 if not Suppress_Case
4414 and then (C = All_Checks or else C = Overflow_Check)
4416 Opt.Overflow_Checks_Unsuppressed := True;
4419 if Arg_Count = 1 then
4421 -- Make an entry in the local scope suppress table. This is the
4422 -- table that directly shows the current value of the scope
4423 -- suppress check for any check id value.
4425 if C = All_Checks then
4427 -- For All_Checks, we set all specific predefined checks with
4428 -- the exception of Elaboration_Check, which is handled
4429 -- specially because of not wanting All_Checks to have the
4430 -- effect of deactivating static elaboration order processing.
4432 for J in Scope_Suppress'Range loop
4433 if J /= Elaboration_Check then
4434 Scope_Suppress (J) := Suppress_Case;
4438 -- If not All_Checks, and predefined check, then set appropriate
4439 -- scope entry. Note that we will set Elaboration_Check if this
4440 -- is explicitly specified.
4442 elsif C in Predefined_Check_Id then
4443 Scope_Suppress (C) := Suppress_Case;
4446 -- Also make an entry in the Local_Entity_Suppress table
4448 Push_Local_Suppress_Stack_Entry
4451 Suppress => Suppress_Case);
4453 -- Case of two arguments present, where the check is suppressed for
4454 -- a specified entity (given as the second argument of the pragma)
4457 Check_Optional_Identifier (Arg2, Name_On);
4458 E_Id := Expression (Arg2);
4461 if not Is_Entity_Name (E_Id) then
4463 ("second argument of pragma% must be entity name", Arg2);
4472 -- Enforce RM 11.5(7) which requires that for a pragma that
4473 -- appears within a package spec, the named entity must be
4474 -- within the package spec. We allow the package name itself
4475 -- to be mentioned since that makes sense, although it is not
4476 -- strictly allowed by 11.5(7).
4479 and then E /= Current_Scope
4480 and then Scope (E) /= Current_Scope
4483 ("entity in pragma% is not in package spec (RM 11.5(7))",
4487 -- Loop through homonyms. As noted below, in the case of a package
4488 -- spec, only homonyms within the package spec are considered.
4491 Suppress_Unsuppress_Echeck (E, C);
4493 if Is_Generic_Instance (E)
4494 and then Is_Subprogram (E)
4495 and then Present (Alias (E))
4497 Suppress_Unsuppress_Echeck (Alias (E), C);
4500 -- Move to next homonym
4505 -- If we are within a package specification, the pragma only
4506 -- applies to homonyms in the same scope.
4508 exit when In_Package_Spec
4509 and then Scope (E) /= Current_Scope;
4512 end Process_Suppress_Unsuppress;
4518 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4520 if Is_Imported (E) then
4522 ("cannot export entity& that was previously imported", Arg);
4524 elsif Present (Address_Clause (E)) then
4526 ("cannot export entity& that has an address clause", Arg);
4529 Set_Is_Exported (E);
4531 -- Generate a reference for entity explicitly, because the
4532 -- identifier may be overloaded and name resolution will not
4535 Generate_Reference (E, Arg);
4537 -- Deal with exporting non-library level entity
4539 if not Is_Library_Level_Entity (E) then
4541 -- Not allowed at all for subprograms
4543 if Is_Subprogram (E) then
4544 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4546 -- Otherwise set public and statically allocated
4550 Set_Is_Statically_Allocated (E);
4552 -- Warn if the corresponding W flag is set and the pragma comes
4553 -- from source. The latter may not be true e.g. on VMS where we
4554 -- expand export pragmas for exception codes associated with
4555 -- imported or exported exceptions. We do not want to generate
4556 -- a warning for something that the user did not write.
4558 if Warn_On_Export_Import
4559 and then Comes_From_Source (Arg)
4562 ("?& has been made static as a result of Export", Arg, E);
4564 ("\this usage is non-standard and non-portable", Arg);
4569 if Warn_On_Export_Import and then Is_Type (E) then
4571 ("exporting a type has no effect?", Arg, E);
4574 if Warn_On_Export_Import and Inside_A_Generic then
4576 ("all instances of& will have the same external name?", Arg, E);
4580 ----------------------------------------------
4581 -- Set_Extended_Import_Export_External_Name --
4582 ----------------------------------------------
4584 procedure Set_Extended_Import_Export_External_Name
4585 (Internal_Ent : Entity_Id;
4586 Arg_External : Node_Id)
4588 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4592 if No (Arg_External) then
4596 Check_Arg_Is_External_Name (Arg_External);
4598 if Nkind (Arg_External) = N_String_Literal then
4599 if String_Length (Strval (Arg_External)) = 0 then
4602 New_Name := Adjust_External_Name_Case (Arg_External);
4605 elsif Nkind (Arg_External) = N_Identifier then
4606 New_Name := Get_Default_External_Name (Arg_External);
4608 -- Check_Arg_Is_External_Name should let through only identifiers and
4609 -- string literals or static string expressions (which are folded to
4610 -- string literals).
4613 raise Program_Error;
4616 -- If we already have an external name set (by a prior normal Import
4617 -- or Export pragma), then the external names must match
4619 if Present (Interface_Name (Internal_Ent)) then
4620 Check_Matching_Internal_Names : declare
4621 S1 : constant String_Id := Strval (Old_Name);
4622 S2 : constant String_Id := Strval (New_Name);
4625 -- Called if names do not match
4631 procedure Mismatch is
4633 Error_Msg_Sloc := Sloc (Old_Name);
4635 ("external name does not match that given #",
4639 -- Start of processing for Check_Matching_Internal_Names
4642 if String_Length (S1) /= String_Length (S2) then
4646 for J in 1 .. String_Length (S1) loop
4647 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4652 end Check_Matching_Internal_Names;
4654 -- Otherwise set the given name
4657 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4658 Check_Duplicated_Export_Name (New_Name);
4660 end Set_Extended_Import_Export_External_Name;
4666 procedure Set_Imported (E : Entity_Id) is
4668 -- Error message if already imported or exported
4670 if Is_Exported (E) or else Is_Imported (E) then
4671 if Is_Exported (E) then
4672 Error_Msg_NE ("entity& was previously exported", N, E);
4674 Error_Msg_NE ("entity& was previously imported", N, E);
4677 Error_Msg_Name_1 := Pname;
4679 ("\(pragma% applies to all previous entities)", N);
4681 Error_Msg_Sloc := Sloc (E);
4682 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4684 -- Here if not previously imported or exported, OK to import
4687 Set_Is_Imported (E);
4689 -- If the entity is an object that is not at the library level,
4690 -- then it is statically allocated. We do not worry about objects
4691 -- with address clauses in this context since they are not really
4692 -- imported in the linker sense.
4695 and then not Is_Library_Level_Entity (E)
4696 and then No (Address_Clause (E))
4698 Set_Is_Statically_Allocated (E);
4703 -------------------------
4704 -- Set_Mechanism_Value --
4705 -------------------------
4707 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4708 -- analyzed, since it is semantic nonsense), so we get it in the exact
4709 -- form created by the parser.
4711 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4714 Mech_Name_Id : Name_Id;
4716 procedure Bad_Class;
4717 -- Signal bad descriptor class name
4719 procedure Bad_Mechanism;
4720 -- Signal bad mechanism name
4726 procedure Bad_Class is
4728 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4731 -------------------------
4732 -- Bad_Mechanism_Value --
4733 -------------------------
4735 procedure Bad_Mechanism is
4737 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4740 -- Start of processing for Set_Mechanism_Value
4743 if Mechanism (Ent) /= Default_Mechanism then
4745 ("mechanism for & has already been set", Mech_Name, Ent);
4748 -- MECHANISM_NAME ::= value | reference | descriptor |
4751 if Nkind (Mech_Name) = N_Identifier then
4752 if Chars (Mech_Name) = Name_Value then
4753 Set_Mechanism (Ent, By_Copy);
4756 elsif Chars (Mech_Name) = Name_Reference then
4757 Set_Mechanism (Ent, By_Reference);
4760 elsif Chars (Mech_Name) = Name_Descriptor then
4761 Check_VMS (Mech_Name);
4762 Set_Mechanism (Ent, By_Descriptor);
4765 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4766 Check_VMS (Mech_Name);
4767 Set_Mechanism (Ent, By_Short_Descriptor);
4770 elsif Chars (Mech_Name) = Name_Copy then
4772 ("bad mechanism name, Value assumed", Mech_Name);
4778 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4779 -- short_descriptor (CLASS_NAME)
4780 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4782 -- Note: this form is parsed as an indexed component
4784 elsif Nkind (Mech_Name) = N_Indexed_Component then
4786 Class := First (Expressions (Mech_Name));
4788 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4789 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4790 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4791 or else Present (Next (Class))
4795 Mech_Name_Id := Chars (Prefix (Mech_Name));
4798 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4799 -- short_descriptor (Class => CLASS_NAME)
4800 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4802 -- Note: this form is parsed as a function call
4804 elsif Nkind (Mech_Name) = N_Function_Call then
4806 Param := First (Parameter_Associations (Mech_Name));
4808 if Nkind (Name (Mech_Name)) /= N_Identifier
4809 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4810 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4811 or else Present (Next (Param))
4812 or else No (Selector_Name (Param))
4813 or else Chars (Selector_Name (Param)) /= Name_Class
4817 Class := Explicit_Actual_Parameter (Param);
4818 Mech_Name_Id := Chars (Name (Mech_Name));
4825 -- Fall through here with Class set to descriptor class name
4827 Check_VMS (Mech_Name);
4829 if Nkind (Class) /= N_Identifier then
4832 elsif Mech_Name_Id = Name_Descriptor
4833 and then Chars (Class) = Name_UBS
4835 Set_Mechanism (Ent, By_Descriptor_UBS);
4837 elsif Mech_Name_Id = Name_Descriptor
4838 and then Chars (Class) = Name_UBSB
4840 Set_Mechanism (Ent, By_Descriptor_UBSB);
4842 elsif Mech_Name_Id = Name_Descriptor
4843 and then Chars (Class) = Name_UBA
4845 Set_Mechanism (Ent, By_Descriptor_UBA);
4847 elsif Mech_Name_Id = Name_Descriptor
4848 and then Chars (Class) = Name_S
4850 Set_Mechanism (Ent, By_Descriptor_S);
4852 elsif Mech_Name_Id = Name_Descriptor
4853 and then Chars (Class) = Name_SB
4855 Set_Mechanism (Ent, By_Descriptor_SB);
4857 elsif Mech_Name_Id = Name_Descriptor
4858 and then Chars (Class) = Name_A
4860 Set_Mechanism (Ent, By_Descriptor_A);
4862 elsif Mech_Name_Id = Name_Descriptor
4863 and then Chars (Class) = Name_NCA
4865 Set_Mechanism (Ent, By_Descriptor_NCA);
4867 elsif Mech_Name_Id = Name_Short_Descriptor
4868 and then Chars (Class) = Name_UBS
4870 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4872 elsif Mech_Name_Id = Name_Short_Descriptor
4873 and then Chars (Class) = Name_UBSB
4875 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4877 elsif Mech_Name_Id = Name_Short_Descriptor
4878 and then Chars (Class) = Name_UBA
4880 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4882 elsif Mech_Name_Id = Name_Short_Descriptor
4883 and then Chars (Class) = Name_S
4885 Set_Mechanism (Ent, By_Short_Descriptor_S);
4887 elsif Mech_Name_Id = Name_Short_Descriptor
4888 and then Chars (Class) = Name_SB
4890 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4892 elsif Mech_Name_Id = Name_Short_Descriptor
4893 and then Chars (Class) = Name_A
4895 Set_Mechanism (Ent, By_Short_Descriptor_A);
4897 elsif Mech_Name_Id = Name_Short_Descriptor
4898 and then Chars (Class) = Name_NCA
4900 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4905 end Set_Mechanism_Value;
4907 ---------------------------
4908 -- Set_Ravenscar_Profile --
4909 ---------------------------
4911 -- The tasks to be done here are
4913 -- Set required policies
4915 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4916 -- pragma Locking_Policy (Ceiling_Locking)
4918 -- Set Detect_Blocking mode
4920 -- Set required restrictions (see System.Rident for detailed list)
4922 procedure Set_Ravenscar_Profile (N : Node_Id) is
4924 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4926 if Task_Dispatching_Policy /= ' '
4927 and then Task_Dispatching_Policy /= 'F'
4929 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4930 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4932 -- Set the FIFO_Within_Priorities policy, but always preserve
4933 -- System_Location since we like the error message with the run time
4937 Task_Dispatching_Policy := 'F';
4939 if Task_Dispatching_Policy_Sloc /= System_Location then
4940 Task_Dispatching_Policy_Sloc := Loc;
4944 -- pragma Locking_Policy (Ceiling_Locking)
4946 if Locking_Policy /= ' '
4947 and then Locking_Policy /= 'C'
4949 Error_Msg_Sloc := Locking_Policy_Sloc;
4950 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4952 -- Set the Ceiling_Locking policy, but preserve System_Location since
4953 -- we like the error message with the run time name.
4956 Locking_Policy := 'C';
4958 if Locking_Policy_Sloc /= System_Location then
4959 Locking_Policy_Sloc := Loc;
4963 -- pragma Detect_Blocking
4965 Detect_Blocking := True;
4967 -- Set the corresponding restrictions
4969 Set_Profile_Restrictions
4970 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4971 end Set_Ravenscar_Profile;
4973 -- Start of processing for Analyze_Pragma
4976 -- Deal with unrecognized pragma
4978 if not Is_Pragma_Name (Pname) then
4979 if Warn_On_Unrecognized_Pragma then
4980 Error_Msg_Name_1 := Pname;
4981 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
4983 for PN in First_Pragma_Name .. Last_Pragma_Name loop
4984 if Is_Bad_Spelling_Of (Pname, PN) then
4985 Error_Msg_Name_1 := PN;
4986 Error_Msg_N -- CODEFIX
4987 ("\?possible misspelling of %!", Pragma_Identifier (N));
4996 -- Here to start processing for recognized pragma
4998 Prag_Id := Get_Pragma_Id (Pname);
5007 if Present (Pragma_Argument_Associations (N)) then
5008 Arg1 := First (Pragma_Argument_Associations (N));
5010 if Present (Arg1) then
5011 Arg2 := Next (Arg1);
5013 if Present (Arg2) then
5014 Arg3 := Next (Arg2);
5016 if Present (Arg3) then
5017 Arg4 := Next (Arg3);
5023 -- Count number of arguments
5030 while Present (Arg_Node) loop
5031 Arg_Count := Arg_Count + 1;
5036 -- An enumeration type defines the pragmas that are supported by the
5037 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5038 -- into the corresponding enumeration value for the following case.
5046 -- pragma Abort_Defer;
5048 when Pragma_Abort_Defer =>
5050 Check_Arg_Count (0);
5052 -- The only required semantic processing is to check the
5053 -- placement. This pragma must appear at the start of the
5054 -- statement sequence of a handled sequence of statements.
5056 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5057 or else N /= First (Statements (Parent (N)))
5068 -- Note: this pragma also has some specific processing in Par.Prag
5069 -- because we want to set the Ada version mode during parsing.
5071 when Pragma_Ada_83 =>
5073 Check_Arg_Count (0);
5075 -- We really should check unconditionally for proper configuration
5076 -- pragma placement, since we really don't want mixed Ada modes
5077 -- within a single unit, and the GNAT reference manual has always
5078 -- said this was a configuration pragma, but we did not check and
5079 -- are hesitant to add the check now.
5081 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5082 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5084 if Ada_Version >= Ada_05 then
5085 Check_Valid_Configuration_Pragma;
5088 -- Now set Ada 83 mode
5090 Ada_Version := Ada_83;
5091 Ada_Version_Explicit := Ada_Version;
5099 -- Note: this pragma also has some specific processing in Par.Prag
5100 -- because we want to set the Ada 83 version mode during parsing.
5102 when Pragma_Ada_95 =>
5104 Check_Arg_Count (0);
5106 -- We really should check unconditionally for proper configuration
5107 -- pragma placement, since we really don't want mixed Ada modes
5108 -- within a single unit, and the GNAT reference manual has always
5109 -- said this was a configuration pragma, but we did not check and
5110 -- are hesitant to add the check now.
5112 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5113 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5115 if Ada_Version >= Ada_05 then
5116 Check_Valid_Configuration_Pragma;
5119 -- Now set Ada 95 mode
5121 Ada_Version := Ada_95;
5122 Ada_Version_Explicit := Ada_Version;
5124 ---------------------
5125 -- Ada_05/Ada_2005 --
5126 ---------------------
5129 -- pragma Ada_05 (LOCAL_NAME);
5132 -- pragma Ada_2005 (LOCAL_NAME):
5134 -- Note: these pragma also have some specific processing in Par.Prag
5135 -- because we want to set the Ada 2005 version mode during parsing.
5137 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5143 if Arg_Count = 1 then
5144 Check_Arg_Is_Local_Name (Arg1);
5145 E_Id := Expression (Arg1);
5147 if Etype (E_Id) = Any_Type then
5151 Set_Is_Ada_2005_Only (Entity (E_Id));
5154 Check_Arg_Count (0);
5156 -- For Ada_2005 we unconditionally enforce the documented
5157 -- configuration pragma placement, since we do not want to
5158 -- tolerate mixed modes in a unit involving Ada 2005. That
5159 -- would cause real difficulties for those cases where there
5160 -- are incompatibilities between Ada 95 and Ada 2005.
5162 Check_Valid_Configuration_Pragma;
5164 -- Now set Ada 2005 mode
5166 Ada_Version := Ada_05;
5167 Ada_Version_Explicit := Ada_05;
5171 ----------------------
5172 -- All_Calls_Remote --
5173 ----------------------
5175 -- pragma All_Calls_Remote [(library_package_NAME)];
5177 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5178 Lib_Entity : Entity_Id;
5181 Check_Ada_83_Warning;
5182 Check_Valid_Library_Unit_Pragma;
5184 if Nkind (N) = N_Null_Statement then
5188 Lib_Entity := Find_Lib_Unit_Name;
5190 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5192 if Present (Lib_Entity)
5193 and then not Debug_Flag_U
5195 if not Is_Remote_Call_Interface (Lib_Entity) then
5196 Error_Pragma ("pragma% only apply to rci unit");
5198 -- Set flag for entity of the library unit
5201 Set_Has_All_Calls_Remote (Lib_Entity);
5205 end All_Calls_Remote;
5211 -- pragma Annotate (IDENTIFIER {, ARG});
5212 -- ARG ::= NAME | EXPRESSION
5214 when Pragma_Annotate => Annotate : begin
5216 Check_At_Least_N_Arguments (1);
5217 Check_Arg_Is_Identifier (Arg1);
5225 while Present (Arg) loop
5226 Exp := Expression (Arg);
5229 if Is_Entity_Name (Exp) then
5232 elsif Nkind (Exp) = N_String_Literal then
5233 Resolve (Exp, Standard_String);
5235 elsif Is_Overloaded (Exp) then
5236 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
5251 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5252 -- [, [Message =>] Static_String_EXPRESSION]);
5254 when Pragma_Assert => Assert : declare
5260 Check_At_Least_N_Arguments (1);
5261 Check_At_Most_N_Arguments (2);
5262 Check_Arg_Order ((Name_Check, Name_Message));
5263 Check_Optional_Identifier (Arg1, Name_Check);
5265 -- We treat pragma Assert as equivalent to:
5267 -- pragma Check (Assertion, condition [, msg]);
5269 -- So rewrite pragma in this manner, and analyze the result
5271 Expr := Get_Pragma_Arg (Arg1);
5273 Make_Pragma_Argument_Association (Loc,
5275 Make_Identifier (Loc,
5276 Chars => Name_Assertion)),
5278 Make_Pragma_Argument_Association (Sloc (Expr),
5279 Expression => Expr));
5281 if Arg_Count > 1 then
5282 Check_Optional_Identifier (Arg2, Name_Message);
5283 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5284 Append_To (Newa, Relocate_Node (Arg2));
5289 Chars => Name_Check,
5290 Pragma_Argument_Associations => Newa));
5294 ----------------------
5295 -- Assertion_Policy --
5296 ----------------------
5298 -- pragma Assertion_Policy (Check | Ignore)
5300 when Pragma_Assertion_Policy => Assertion_Policy : declare
5305 Check_Valid_Configuration_Pragma;
5306 Check_Arg_Count (1);
5307 Check_No_Identifiers;
5308 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5310 -- We treat pragma Assertion_Policy as equivalent to:
5312 -- pragma Check_Policy (Assertion, policy)
5314 -- So rewrite the pragma in that manner and link on to the chain
5315 -- of Check_Policy pragmas, marking the pragma as analyzed.
5317 Policy := Get_Pragma_Arg (Arg1);
5321 Chars => Name_Check_Policy,
5323 Pragma_Argument_Associations => New_List (
5324 Make_Pragma_Argument_Association (Loc,
5326 Make_Identifier (Loc,
5327 Chars => Name_Assertion)),
5329 Make_Pragma_Argument_Association (Loc,
5331 Make_Identifier (Sloc (Policy),
5332 Chars => Chars (Policy))))));
5335 Set_Next_Pragma (N, Opt.Check_Policy_List);
5336 Opt.Check_Policy_List := N;
5337 end Assertion_Policy;
5339 ------------------------------
5340 -- Assume_No_Invalid_Values --
5341 ------------------------------
5343 -- pragma Assume_No_Invalid_Values (On | Off);
5345 when Pragma_Assume_No_Invalid_Values =>
5347 Check_Valid_Configuration_Pragma;
5348 Check_Arg_Count (1);
5349 Check_No_Identifiers;
5350 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5352 if Chars (Expression (Arg1)) = Name_On then
5353 Assume_No_Invalid_Values := True;
5355 Assume_No_Invalid_Values := False;
5362 -- pragma AST_Entry (entry_IDENTIFIER);
5364 when Pragma_AST_Entry => AST_Entry : declare
5370 Check_Arg_Count (1);
5371 Check_No_Identifiers;
5372 Check_Arg_Is_Local_Name (Arg1);
5373 Ent := Entity (Expression (Arg1));
5375 -- Note: the implementation of the AST_Entry pragma could handle
5376 -- the entry family case fine, but for now we are consistent with
5377 -- the DEC rules, and do not allow the pragma, which of course
5378 -- has the effect of also forbidding the attribute.
5380 if Ekind (Ent) /= E_Entry then
5382 ("pragma% argument must be simple entry name", Arg1);
5384 elsif Is_AST_Entry (Ent) then
5386 ("duplicate % pragma for entry", Arg1);
5388 elsif Has_Homonym (Ent) then
5390 ("pragma% argument cannot specify overloaded entry", Arg1);
5394 FF : constant Entity_Id := First_Formal (Ent);
5397 if Present (FF) then
5398 if Present (Next_Formal (FF)) then
5400 ("entry for pragma% can have only one argument",
5403 elsif Parameter_Mode (FF) /= E_In_Parameter then
5405 ("entry parameter for pragma% must have mode IN",
5411 Set_Is_AST_Entry (Ent);
5419 -- pragma Asynchronous (LOCAL_NAME);
5421 when Pragma_Asynchronous => Asynchronous : declare
5429 procedure Process_Async_Pragma;
5430 -- Common processing for procedure and access-to-procedure case
5432 --------------------------
5433 -- Process_Async_Pragma --
5434 --------------------------
5436 procedure Process_Async_Pragma is
5439 Set_Is_Asynchronous (Nm);
5443 -- The formals should be of mode IN (RM E.4.1(6))
5446 while Present (S) loop
5447 Formal := Defining_Identifier (S);
5449 if Nkind (Formal) = N_Defining_Identifier
5450 and then Ekind (Formal) /= E_In_Parameter
5453 ("pragma% procedure can only have IN parameter",
5460 Set_Is_Asynchronous (Nm);
5461 end Process_Async_Pragma;
5463 -- Start of processing for pragma Asynchronous
5466 Check_Ada_83_Warning;
5467 Check_No_Identifiers;
5468 Check_Arg_Count (1);
5469 Check_Arg_Is_Local_Name (Arg1);
5471 if Debug_Flag_U then
5475 C_Ent := Cunit_Entity (Current_Sem_Unit);
5476 Analyze (Expression (Arg1));
5477 Nm := Entity (Expression (Arg1));
5479 if not Is_Remote_Call_Interface (C_Ent)
5480 and then not Is_Remote_Types (C_Ent)
5482 -- This pragma should only appear in an RCI or Remote Types
5483 -- unit (RM E.4.1(4)).
5486 ("pragma% not in Remote_Call_Interface or " &
5487 "Remote_Types unit");
5490 if Ekind (Nm) = E_Procedure
5491 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5493 if not Is_Remote_Call_Interface (Nm) then
5495 ("pragma% cannot be applied on non-remote procedure",
5499 L := Parameter_Specifications (Parent (Nm));
5500 Process_Async_Pragma;
5503 elsif Ekind (Nm) = E_Function then
5505 ("pragma% cannot be applied to function", Arg1);
5507 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5509 if Is_Record_Type (Nm) then
5511 -- A record type that is the Equivalent_Type for a remote
5512 -- access-to-subprogram type.
5514 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5517 -- A non-expanded RAS type (distribution is not enabled)
5519 N := Declaration_Node (Nm);
5522 if Nkind (N) = N_Full_Type_Declaration
5523 and then Nkind (Type_Definition (N)) =
5524 N_Access_Procedure_Definition
5526 L := Parameter_Specifications (Type_Definition (N));
5527 Process_Async_Pragma;
5529 if Is_Asynchronous (Nm)
5530 and then Expander_Active
5531 and then Get_PCS_Name /= Name_No_DSA
5533 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5538 ("pragma% cannot reference access-to-function type",
5542 -- Only other possibility is Access-to-class-wide type
5544 elsif Is_Access_Type (Nm)
5545 and then Is_Class_Wide_Type (Designated_Type (Nm))
5547 Check_First_Subtype (Arg1);
5548 Set_Is_Asynchronous (Nm);
5549 if Expander_Active then
5550 RACW_Type_Is_Asynchronous (Nm);
5554 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5562 -- pragma Atomic (LOCAL_NAME);
5564 when Pragma_Atomic =>
5565 Process_Atomic_Shared_Volatile;
5567 -----------------------
5568 -- Atomic_Components --
5569 -----------------------
5571 -- pragma Atomic_Components (array_LOCAL_NAME);
5573 -- This processing is shared by Volatile_Components
5575 when Pragma_Atomic_Components |
5576 Pragma_Volatile_Components =>
5578 Atomic_Components : declare
5585 Check_Ada_83_Warning;
5586 Check_No_Identifiers;
5587 Check_Arg_Count (1);
5588 Check_Arg_Is_Local_Name (Arg1);
5589 E_Id := Expression (Arg1);
5591 if Etype (E_Id) = Any_Type then
5597 if Rep_Item_Too_Early (E, N)
5599 Rep_Item_Too_Late (E, N)
5604 D := Declaration_Node (E);
5607 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5609 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5610 and then Nkind (D) = N_Object_Declaration
5611 and then Nkind (Object_Definition (D)) =
5612 N_Constrained_Array_Definition)
5614 -- The flag is set on the object, or on the base type
5616 if Nkind (D) /= N_Object_Declaration then
5620 Set_Has_Volatile_Components (E);
5622 if Prag_Id = Pragma_Atomic_Components then
5623 Set_Has_Atomic_Components (E);
5625 if Is_Packed (E) then
5626 Set_Is_Packed (E, False);
5629 ("?Pack canceled, cannot pack atomic components",
5635 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5637 end Atomic_Components;
5639 --------------------
5640 -- Attach_Handler --
5641 --------------------
5643 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5645 when Pragma_Attach_Handler =>
5646 Check_Ada_83_Warning;
5647 Check_No_Identifiers;
5648 Check_Arg_Count (2);
5650 if No_Run_Time_Mode then
5651 Error_Msg_CRT ("Attach_Handler pragma", N);
5653 Check_Interrupt_Or_Attach_Handler;
5655 -- The expression that designates the attribute may
5656 -- depend on a discriminant, and is therefore a per-
5657 -- object expression, to be expanded in the init proc.
5658 -- If expansion is enabled, perform semantic checks
5661 if Expander_Active then
5663 Temp : constant Node_Id :=
5664 New_Copy_Tree (Expression (Arg2));
5666 Set_Parent (Temp, N);
5667 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5671 Analyze (Expression (Arg2));
5672 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5675 Process_Interrupt_Or_Attach_Handler;
5678 --------------------
5679 -- C_Pass_By_Copy --
5680 --------------------
5682 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5684 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5690 Check_Valid_Configuration_Pragma;
5691 Check_Arg_Count (1);
5692 Check_Optional_Identifier (Arg1, "max_size");
5694 Arg := Expression (Arg1);
5695 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5697 Val := Expr_Value (Arg);
5701 ("maximum size for pragma% must be positive", Arg1);
5703 elsif UI_Is_In_Int_Range (Val) then
5704 Default_C_Record_Mechanism := UI_To_Int (Val);
5706 -- If a giant value is given, Int'Last will do well enough.
5707 -- If sometime someone complains that a record larger than
5708 -- two gigabytes is not copied, we will worry about it then!
5711 Default_C_Record_Mechanism := Mechanism_Type'Last;
5719 -- pragma Check ([Name =>] Identifier,
5720 -- [Check =>] Boolean_Expression
5721 -- [,[Message =>] String_Expression]);
5723 when Pragma_Check => Check : declare
5728 -- Set True if category of assertions referenced by Name enabled
5732 Check_At_Least_N_Arguments (2);
5733 Check_At_Most_N_Arguments (3);
5734 Check_Optional_Identifier (Arg1, Name_Name);
5735 Check_Optional_Identifier (Arg2, Name_Check);
5737 if Arg_Count = 3 then
5738 Check_Optional_Identifier (Arg3, Name_Message);
5739 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5742 Check_Arg_Is_Identifier (Arg1);
5743 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5745 -- If expansion is active and the check is not enabled then we
5746 -- rewrite the Check as:
5748 -- if False and then condition then
5752 -- The reason we do this rewriting during semantic analysis rather
5753 -- than as part of normal expansion is that we cannot analyze and
5754 -- expand the code for the boolean expression directly, or it may
5755 -- cause insertion of actions that would escape the attempt to
5756 -- suppress the check code.
5758 -- Note that the Sloc for the if statement corresponds to the
5759 -- argument condition, not the pragma itself. The reason for this
5760 -- is that we may generate a warning if the condition is False at
5761 -- compile time, and we do not want to delete this warning when we
5762 -- delete the if statement.
5764 Expr := Expression (Arg2);
5766 if Expander_Active and then not Check_On then
5767 Eloc := Sloc (Expr);
5770 Make_If_Statement (Eloc,
5772 Make_And_Then (Eloc,
5773 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5774 Right_Opnd => Expr),
5775 Then_Statements => New_List (
5776 Make_Null_Statement (Eloc))));
5783 Analyze_And_Resolve (Expr, Any_Boolean);
5791 -- pragma Check_Name (check_IDENTIFIER);
5793 when Pragma_Check_Name =>
5794 Check_No_Identifiers;
5796 Check_Valid_Configuration_Pragma;
5797 Check_Arg_Count (1);
5798 Check_Arg_Is_Identifier (Arg1);
5801 Nam : constant Name_Id := Chars (Expression (Arg1));
5804 for J in Check_Names.First .. Check_Names.Last loop
5805 if Check_Names.Table (J) = Nam then
5810 Check_Names.Append (Nam);
5817 -- pragma Check_Policy (
5818 -- [Name =>] IDENTIFIER,
5819 -- [Policy =>] POLICY_IDENTIFIER);
5821 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5823 -- Note: this is a configuration pragma, but it is allowed to appear
5826 when Pragma_Check_Policy =>
5828 Check_Arg_Count (2);
5829 Check_Optional_Identifier (Arg1, Name_Name);
5830 Check_Optional_Identifier (Arg2, Name_Policy);
5832 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5834 -- A Check_Policy pragma can appear either as a configuration
5835 -- pragma, or in a declarative part or a package spec (see RM
5836 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5837 -- followed for Check_Policy).
5839 if not Is_Configuration_Pragma then
5840 Check_Is_In_Decl_Part_Or_Package_Spec;
5843 Set_Next_Pragma (N, Opt.Check_Policy_List);
5844 Opt.Check_Policy_List := N;
5846 ---------------------
5847 -- CIL_Constructor --
5848 ---------------------
5850 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5852 -- Processing for this pragma is shared with Java_Constructor
5858 -- pragma Comment (static_string_EXPRESSION)
5860 -- Processing for pragma Comment shares the circuitry for pragma
5861 -- Ident. The only differences are that Ident enforces a limit of 31
5862 -- characters on its argument, and also enforces limitations on
5863 -- placement for DEC compatibility. Pragma Comment shares neither of
5864 -- these restrictions.
5870 -- pragma Common_Object (
5871 -- [Internal =>] LOCAL_NAME
5872 -- [, [External =>] EXTERNAL_SYMBOL]
5873 -- [, [Size =>] EXTERNAL_SYMBOL]);
5875 -- Processing for this pragma is shared with Psect_Object
5877 ------------------------
5878 -- Compile_Time_Error --
5879 ------------------------
5881 -- pragma Compile_Time_Error
5882 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5884 when Pragma_Compile_Time_Error =>
5886 Process_Compile_Time_Warning_Or_Error;
5888 --------------------------
5889 -- Compile_Time_Warning --
5890 --------------------------
5892 -- pragma Compile_Time_Warning
5893 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5895 when Pragma_Compile_Time_Warning =>
5897 Process_Compile_Time_Warning_Or_Error;
5903 when Pragma_Compiler_Unit =>
5905 Check_Arg_Count (0);
5906 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5908 -----------------------------
5909 -- Complete_Representation --
5910 -----------------------------
5912 -- pragma Complete_Representation;
5914 when Pragma_Complete_Representation =>
5916 Check_Arg_Count (0);
5918 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5920 ("pragma & must appear within record representation clause");
5923 ----------------------------
5924 -- Complex_Representation --
5925 ----------------------------
5927 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5929 when Pragma_Complex_Representation => Complex_Representation : declare
5936 Check_Arg_Count (1);
5937 Check_Optional_Identifier (Arg1, Name_Entity);
5938 Check_Arg_Is_Local_Name (Arg1);
5939 E_Id := Expression (Arg1);
5941 if Etype (E_Id) = Any_Type then
5947 if not Is_Record_Type (E) then
5949 ("argument for pragma% must be record type", Arg1);
5952 Ent := First_Entity (E);
5955 or else No (Next_Entity (Ent))
5956 or else Present (Next_Entity (Next_Entity (Ent)))
5957 or else not Is_Floating_Point_Type (Etype (Ent))
5958 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5961 ("record for pragma% must have two fields of the same "
5962 & "floating-point type", Arg1);
5965 Set_Has_Complex_Representation (Base_Type (E));
5967 -- We need to treat the type has having a non-standard
5968 -- representation, for back-end purposes, even though in
5969 -- general a complex will have the default representation
5970 -- of a record with two real components.
5972 Set_Has_Non_Standard_Rep (Base_Type (E));
5974 end Complex_Representation;
5976 -------------------------
5977 -- Component_Alignment --
5978 -------------------------
5980 -- pragma Component_Alignment (
5981 -- [Form =>] ALIGNMENT_CHOICE
5982 -- [, [Name =>] type_LOCAL_NAME]);
5984 -- ALIGNMENT_CHOICE ::=
5986 -- | Component_Size_4
5990 when Pragma_Component_Alignment => Component_AlignmentP : declare
5991 Args : Args_List (1 .. 2);
5992 Names : constant Name_List (1 .. 2) := (
5996 Form : Node_Id renames Args (1);
5997 Name : Node_Id renames Args (2);
5999 Atype : Component_Alignment_Kind;
6004 Gather_Associations (Names, Args);
6007 Error_Pragma ("missing Form argument for pragma%");
6010 Check_Arg_Is_Identifier (Form);
6012 -- Get proper alignment, note that Default = Component_Size on all
6013 -- machines we have so far, and we want to set this value rather
6014 -- than the default value to indicate that it has been explicitly
6015 -- set (and thus will not get overridden by the default component
6016 -- alignment for the current scope)
6018 if Chars (Form) = Name_Component_Size then
6019 Atype := Calign_Component_Size;
6021 elsif Chars (Form) = Name_Component_Size_4 then
6022 Atype := Calign_Component_Size_4;
6024 elsif Chars (Form) = Name_Default then
6025 Atype := Calign_Component_Size;
6027 elsif Chars (Form) = Name_Storage_Unit then
6028 Atype := Calign_Storage_Unit;
6032 ("invalid Form parameter for pragma%", Form);
6035 -- Case with no name, supplied, affects scope table entry
6039 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6041 -- Case of name supplied
6044 Check_Arg_Is_Local_Name (Name);
6046 Typ := Entity (Name);
6049 or else Rep_Item_Too_Early (Typ, N)
6053 Typ := Underlying_Type (Typ);
6056 if not Is_Record_Type (Typ)
6057 and then not Is_Array_Type (Typ)
6060 ("Name parameter of pragma% must identify record or " &
6061 "array type", Name);
6064 -- An explicit Component_Alignment pragma overrides an
6065 -- implicit pragma Pack, but not an explicit one.
6067 if not Has_Pragma_Pack (Base_Type (Typ)) then
6068 Set_Is_Packed (Base_Type (Typ), False);
6069 Set_Component_Alignment (Base_Type (Typ), Atype);
6072 end Component_AlignmentP;
6078 -- pragma Controlled (first_subtype_LOCAL_NAME);
6080 when Pragma_Controlled => Controlled : declare
6084 Check_No_Identifiers;
6085 Check_Arg_Count (1);
6086 Check_Arg_Is_Local_Name (Arg1);
6087 Arg := Expression (Arg1);
6089 if not Is_Entity_Name (Arg)
6090 or else not Is_Access_Type (Entity (Arg))
6092 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6094 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6102 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6103 -- [Entity =>] LOCAL_NAME);
6105 when Pragma_Convention => Convention : declare
6108 pragma Warnings (Off, C);
6109 pragma Warnings (Off, E);
6111 Check_Arg_Order ((Name_Convention, Name_Entity));
6112 Check_Ada_83_Warning;
6113 Check_Arg_Count (2);
6114 Process_Convention (C, E);
6117 ---------------------------
6118 -- Convention_Identifier --
6119 ---------------------------
6121 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6122 -- [Convention =>] convention_IDENTIFIER);
6124 when Pragma_Convention_Identifier => Convention_Identifier : declare
6130 Check_Arg_Order ((Name_Name, Name_Convention));
6131 Check_Arg_Count (2);
6132 Check_Optional_Identifier (Arg1, Name_Name);
6133 Check_Optional_Identifier (Arg2, Name_Convention);
6134 Check_Arg_Is_Identifier (Arg1);
6135 Check_Arg_Is_Identifier (Arg2);
6136 Idnam := Chars (Expression (Arg1));
6137 Cname := Chars (Expression (Arg2));
6139 if Is_Convention_Name (Cname) then
6140 Record_Convention_Identifier
6141 (Idnam, Get_Convention_Id (Cname));
6144 ("second arg for % pragma must be convention", Arg2);
6146 end Convention_Identifier;
6152 -- pragma CPP_Class ([Entity =>] local_NAME)
6154 when Pragma_CPP_Class => CPP_Class : declare
6159 if Warn_On_Obsolescent_Feature then
6161 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6162 " by pragma import?", N);
6166 Check_Arg_Count (1);
6167 Check_Optional_Identifier (Arg1, Name_Entity);
6168 Check_Arg_Is_Local_Name (Arg1);
6170 Arg := Expression (Arg1);
6173 if Etype (Arg) = Any_Type then
6177 if not Is_Entity_Name (Arg)
6178 or else not Is_Type (Entity (Arg))
6180 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6183 Typ := Entity (Arg);
6185 if not Is_Tagged_Type (Typ) then
6186 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6189 -- Types treated as CPP classes are treated as limited, but we
6190 -- don't require them to be declared this way. A warning is issued
6191 -- to encourage the user to declare them as limited. This is not
6192 -- an error, for compatibility reasons, because these types have
6193 -- been supported this way for some time.
6195 if not Is_Limited_Type (Typ) then
6197 ("imported 'C'P'P type should be " &
6198 "explicitly declared limited?",
6199 Get_Pragma_Arg (Arg1));
6201 ("\type will be considered limited",
6202 Get_Pragma_Arg (Arg1));
6205 Set_Is_CPP_Class (Typ);
6206 Set_Is_Limited_Record (Typ);
6207 Set_Convention (Typ, Convention_CPP);
6209 -- Imported CPP types must not have discriminants (because C++
6210 -- classes do not have discriminants).
6212 if Has_Discriminants (Typ) then
6214 ("imported 'C'P'P type cannot have discriminants",
6215 First (Discriminant_Specifications
6216 (Declaration_Node (Typ))));
6219 -- Components of imported CPP types must not have default
6220 -- expressions because the constructor (if any) is in the
6223 if Is_Incomplete_Or_Private_Type (Typ)
6224 and then No (Underlying_Type (Typ))
6226 -- It should be an error to apply pragma CPP to a private
6227 -- type if the underlying type is not visible (as it is
6228 -- for any representation item). For now, for backward
6229 -- compatibility we do nothing but we cannot check components
6230 -- because they are not available at this stage. All this code
6231 -- will be removed when we cleanup this obsolete GNAT pragma???
6237 Tdef : constant Node_Id :=
6238 Type_Definition (Declaration_Node (Typ));
6243 if Nkind (Tdef) = N_Record_Definition then
6244 Clist := Component_List (Tdef);
6246 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6247 Clist := Component_List (Record_Extension_Part (Tdef));
6250 if Present (Clist) then
6251 Comp := First (Component_Items (Clist));
6252 while Present (Comp) loop
6253 if Present (Expression (Comp)) then
6255 ("component of imported 'C'P'P type cannot have" &
6256 " default expression", Expression (Comp));
6266 ---------------------
6267 -- CPP_Constructor --
6268 ---------------------
6270 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6271 -- [, [External_Name =>] static_string_EXPRESSION ]
6272 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6274 when Pragma_CPP_Constructor => CPP_Constructor : declare
6280 Check_At_Least_N_Arguments (1);
6281 Check_At_Most_N_Arguments (3);
6282 Check_Optional_Identifier (Arg1, Name_Entity);
6283 Check_Arg_Is_Local_Name (Arg1);
6285 Id := Expression (Arg1);
6286 Find_Program_Unit_Name (Id);
6288 -- If we did not find the name, we are done
6290 if Etype (Id) = Any_Type then
6294 Def_Id := Entity (Id);
6296 if Ekind (Def_Id) = E_Function
6297 and then Is_Class_Wide_Type (Etype (Def_Id))
6298 and then Is_CPP_Class (Etype (Etype (Def_Id)))
6300 if Arg_Count >= 2 then
6301 Set_Imported (Def_Id);
6302 Set_Is_Public (Def_Id);
6303 Process_Interface_Name (Def_Id, Arg2, Arg3);
6306 Set_Has_Completion (Def_Id);
6307 Set_Is_Constructor (Def_Id);
6311 ("pragma% requires function returning a 'C'P'P_Class type",
6314 end CPP_Constructor;
6320 when Pragma_CPP_Virtual => CPP_Virtual : declare
6324 if Warn_On_Obsolescent_Feature then
6326 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6335 when Pragma_CPP_Vtable => CPP_Vtable : declare
6339 if Warn_On_Obsolescent_Feature then
6341 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6350 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6352 when Pragma_Debug => Debug : declare
6360 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6363 if Arg_Count = 2 then
6366 Left_Opnd => Relocate_Node (Cond),
6367 Right_Opnd => Expression (Arg1));
6370 -- Rewrite into a conditional with an appropriate condition. We
6371 -- wrap the procedure call in a block so that overhead from e.g.
6372 -- use of the secondary stack does not generate execution overhead
6373 -- for suppressed conditions.
6375 Rewrite (N, Make_Implicit_If_Statement (N,
6377 Then_Statements => New_List (
6378 Make_Block_Statement (Loc,
6379 Handled_Statement_Sequence =>
6380 Make_Handled_Sequence_Of_Statements (Loc,
6381 Statements => New_List (
6382 Relocate_Node (Debug_Statement (N))))))));
6390 -- pragma Debug_Policy (Check | Ignore)
6392 when Pragma_Debug_Policy =>
6394 Check_Arg_Count (1);
6395 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6396 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6398 ---------------------
6399 -- Detect_Blocking --
6400 ---------------------
6402 -- pragma Detect_Blocking;
6404 when Pragma_Detect_Blocking =>
6406 Check_Arg_Count (0);
6407 Check_Valid_Configuration_Pragma;
6408 Detect_Blocking := True;
6414 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6416 when Pragma_Discard_Names => Discard_Names : declare
6421 Check_Ada_83_Warning;
6423 -- Deal with configuration pragma case
6425 if Arg_Count = 0 and then Is_Configuration_Pragma then
6426 Global_Discard_Names := True;
6429 -- Otherwise, check correct appropriate context
6432 Check_Is_In_Decl_Part_Or_Package_Spec;
6434 if Arg_Count = 0 then
6436 -- If there is no parameter, then from now on this pragma
6437 -- applies to any enumeration, exception or tagged type
6438 -- defined in the current declarative part, and recursively
6439 -- to any nested scope.
6441 Set_Discard_Names (Current_Scope);
6445 Check_Arg_Count (1);
6446 Check_Optional_Identifier (Arg1, Name_On);
6447 Check_Arg_Is_Local_Name (Arg1);
6449 E_Id := Expression (Arg1);
6451 if Etype (E_Id) = Any_Type then
6457 if (Is_First_Subtype (E)
6459 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6460 or else Ekind (E) = E_Exception
6462 Set_Discard_Names (E);
6465 ("inappropriate entity for pragma%", Arg1);
6476 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6478 when Pragma_Elaborate => Elaborate : declare
6483 -- Pragma must be in context items list of a compilation unit
6485 if not Is_In_Context_Clause then
6489 -- Must be at least one argument
6491 if Arg_Count = 0 then
6492 Error_Pragma ("pragma% requires at least one argument");
6495 -- In Ada 83 mode, there can be no items following it in the
6496 -- context list except other pragmas and implicit with clauses
6497 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6498 -- placement rule does not apply.
6500 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6502 while Present (Citem) loop
6503 if Nkind (Citem) = N_Pragma
6504 or else (Nkind (Citem) = N_With_Clause
6505 and then Implicit_With (Citem))
6510 ("(Ada 83) pragma% must be at end of context clause");
6517 -- Finally, the arguments must all be units mentioned in a with
6518 -- clause in the same context clause. Note we already checked (in
6519 -- Par.Prag) that the arguments are all identifiers or selected
6523 Outer : while Present (Arg) loop
6524 Citem := First (List_Containing (N));
6525 Inner : while Citem /= N loop
6526 if Nkind (Citem) = N_With_Clause
6527 and then Same_Name (Name (Citem), Expression (Arg))
6529 Set_Elaborate_Present (Citem, True);
6530 Set_Unit_Name (Expression (Arg), Name (Citem));
6532 -- With the pragma present, elaboration calls on
6533 -- subprograms from the named unit need no further
6534 -- checks, as long as the pragma appears in the current
6535 -- compilation unit. If the pragma appears in some unit
6536 -- in the context, there might still be a need for an
6537 -- Elaborate_All_Desirable from the current compilation
6538 -- to the named unit, so we keep the check enabled.
6540 if In_Extended_Main_Source_Unit (N) then
6541 Set_Suppress_Elaboration_Warnings
6542 (Entity (Name (Citem)));
6553 ("argument of pragma% is not with'ed unit", Arg);
6559 -- Give a warning if operating in static mode with -gnatwl
6560 -- (elaboration warnings enabled) switch set.
6562 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6564 ("?use of pragma Elaborate may not be safe", N);
6566 ("?use pragma Elaborate_All instead if possible", N);
6574 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6576 when Pragma_Elaborate_All => Elaborate_All : declare
6581 Check_Ada_83_Warning;
6583 -- Pragma must be in context items list of a compilation unit
6585 if not Is_In_Context_Clause then
6589 -- Must be at least one argument
6591 if Arg_Count = 0 then
6592 Error_Pragma ("pragma% requires at least one argument");
6595 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6596 -- have to appear at the end of the context clause, but may
6597 -- appear mixed in with other items, even in Ada 83 mode.
6599 -- Final check: the arguments must all be units mentioned in
6600 -- a with clause in the same context clause. Note that we
6601 -- already checked (in Par.Prag) that all the arguments are
6602 -- either identifiers or selected components.
6605 Outr : while Present (Arg) loop
6606 Citem := First (List_Containing (N));
6607 Innr : while Citem /= N loop
6608 if Nkind (Citem) = N_With_Clause
6609 and then Same_Name (Name (Citem), Expression (Arg))
6611 Set_Elaborate_All_Present (Citem, True);
6612 Set_Unit_Name (Expression (Arg), Name (Citem));
6614 -- Suppress warnings and elaboration checks on the named
6615 -- unit if the pragma is in the current compilation, as
6616 -- for pragma Elaborate.
6618 if In_Extended_Main_Source_Unit (N) then
6619 Set_Suppress_Elaboration_Warnings
6620 (Entity (Name (Citem)));
6629 Set_Error_Posted (N);
6631 ("argument of pragma% is not with'ed unit", Arg);
6638 --------------------
6639 -- Elaborate_Body --
6640 --------------------
6642 -- pragma Elaborate_Body [( library_unit_NAME )];
6644 when Pragma_Elaborate_Body => Elaborate_Body : declare
6645 Cunit_Node : Node_Id;
6646 Cunit_Ent : Entity_Id;
6649 Check_Ada_83_Warning;
6650 Check_Valid_Library_Unit_Pragma;
6652 if Nkind (N) = N_Null_Statement then
6656 Cunit_Node := Cunit (Current_Sem_Unit);
6657 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6659 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6662 Error_Pragma ("pragma% must refer to a spec, not a body");
6664 Set_Body_Required (Cunit_Node, True);
6665 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6667 -- If we are in dynamic elaboration mode, then we suppress
6668 -- elaboration warnings for the unit, since it is definitely
6669 -- fine NOT to do dynamic checks at the first level (and such
6670 -- checks will be suppressed because no elaboration boolean
6671 -- is created for Elaborate_Body packages).
6673 -- But in the static model of elaboration, Elaborate_Body is
6674 -- definitely NOT good enough to ensure elaboration safety on
6675 -- its own, since the body may WITH other units that are not
6676 -- safe from an elaboration point of view, so a client must
6677 -- still do an Elaborate_All on such units.
6679 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6680 -- Elaborate_Body always suppressed elab warnings.
6682 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6683 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6688 ------------------------
6689 -- Elaboration_Checks --
6690 ------------------------
6692 -- pragma Elaboration_Checks (Static | Dynamic);
6694 when Pragma_Elaboration_Checks =>
6696 Check_Arg_Count (1);
6697 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6698 Dynamic_Elaboration_Checks :=
6699 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6705 -- pragma Eliminate (
6706 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6707 -- [,[Entity =>] IDENTIFIER |
6708 -- SELECTED_COMPONENT |
6710 -- [, OVERLOADING_RESOLUTION]);
6712 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6715 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6718 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6720 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6721 -- Result_Type => result_SUBTYPE_NAME]
6723 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6724 -- SUBTYPE_NAME ::= STRING_LITERAL
6726 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6727 -- SOURCE_TRACE ::= STRING_LITERAL
6729 when Pragma_Eliminate => Eliminate : declare
6730 Args : Args_List (1 .. 5);
6731 Names : constant Name_List (1 .. 5) := (
6734 Name_Parameter_Types,
6736 Name_Source_Location);
6738 Unit_Name : Node_Id renames Args (1);
6739 Entity : Node_Id renames Args (2);
6740 Parameter_Types : Node_Id renames Args (3);
6741 Result_Type : Node_Id renames Args (4);
6742 Source_Location : Node_Id renames Args (5);
6746 Check_Valid_Configuration_Pragma;
6747 Gather_Associations (Names, Args);
6749 if No (Unit_Name) then
6750 Error_Pragma ("missing Unit_Name argument for pragma%");
6754 and then (Present (Parameter_Types)
6756 Present (Result_Type)
6758 Present (Source_Location))
6760 Error_Pragma ("missing Entity argument for pragma%");
6763 if (Present (Parameter_Types)
6765 Present (Result_Type))
6767 Present (Source_Location)
6770 ("parameter profile and source location cannot " &
6771 "be used together in pragma%");
6774 Process_Eliminate_Pragma
6788 -- [ Convention =>] convention_IDENTIFIER,
6789 -- [ Entity =>] local_NAME
6790 -- [, [External_Name =>] static_string_EXPRESSION ]
6791 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6793 when Pragma_Export => Export : declare
6797 pragma Warnings (Off, C);
6800 Check_Ada_83_Warning;
6806 Check_At_Least_N_Arguments (2);
6807 Check_At_Most_N_Arguments (4);
6808 Process_Convention (C, Def_Id);
6810 if Ekind (Def_Id) /= E_Constant then
6811 Note_Possible_Modification (Expression (Arg2), Sure => False);
6814 Process_Interface_Name (Def_Id, Arg3, Arg4);
6815 Set_Exported (Def_Id, Arg2);
6817 -- If the entity is a deferred constant, propagate the information
6818 -- to the full view, because gigi elaborates the full view only.
6820 if Ekind (Def_Id) = E_Constant
6821 and then Present (Full_View (Def_Id))
6824 Id2 : constant Entity_Id := Full_View (Def_Id);
6826 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6827 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6828 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6833 ----------------------
6834 -- Export_Exception --
6835 ----------------------
6837 -- pragma Export_Exception (
6838 -- [Internal =>] LOCAL_NAME
6839 -- [, [External =>] EXTERNAL_SYMBOL]
6840 -- [, [Form =>] Ada | VMS]
6841 -- [, [Code =>] static_integer_EXPRESSION]);
6843 when Pragma_Export_Exception => Export_Exception : declare
6844 Args : Args_List (1 .. 4);
6845 Names : constant Name_List (1 .. 4) := (
6851 Internal : Node_Id renames Args (1);
6852 External : Node_Id renames Args (2);
6853 Form : Node_Id renames Args (3);
6854 Code : Node_Id renames Args (4);
6859 if Inside_A_Generic then
6860 Error_Pragma ("pragma% cannot be used for generic entities");
6863 Gather_Associations (Names, Args);
6864 Process_Extended_Import_Export_Exception_Pragma (
6865 Arg_Internal => Internal,
6866 Arg_External => External,
6870 if not Is_VMS_Exception (Entity (Internal)) then
6871 Set_Exported (Entity (Internal), Internal);
6873 end Export_Exception;
6875 ---------------------
6876 -- Export_Function --
6877 ---------------------
6879 -- pragma Export_Function (
6880 -- [Internal =>] LOCAL_NAME
6881 -- [, [External =>] EXTERNAL_SYMBOL]
6882 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6883 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6884 -- [, [Mechanism =>] MECHANISM]
6885 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6887 -- EXTERNAL_SYMBOL ::=
6889 -- | static_string_EXPRESSION
6891 -- PARAMETER_TYPES ::=
6893 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6895 -- TYPE_DESIGNATOR ::=
6897 -- | subtype_Name ' Access
6901 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6903 -- MECHANISM_ASSOCIATION ::=
6904 -- [formal_parameter_NAME =>] MECHANISM_NAME
6906 -- MECHANISM_NAME ::=
6909 -- | Descriptor [([Class =>] CLASS_NAME)]
6911 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6913 when Pragma_Export_Function => Export_Function : declare
6914 Args : Args_List (1 .. 6);
6915 Names : constant Name_List (1 .. 6) := (
6918 Name_Parameter_Types,
6921 Name_Result_Mechanism);
6923 Internal : Node_Id renames Args (1);
6924 External : Node_Id renames Args (2);
6925 Parameter_Types : Node_Id renames Args (3);
6926 Result_Type : Node_Id renames Args (4);
6927 Mechanism : Node_Id renames Args (5);
6928 Result_Mechanism : Node_Id renames Args (6);
6932 Gather_Associations (Names, Args);
6933 Process_Extended_Import_Export_Subprogram_Pragma (
6934 Arg_Internal => Internal,
6935 Arg_External => External,
6936 Arg_Parameter_Types => Parameter_Types,
6937 Arg_Result_Type => Result_Type,
6938 Arg_Mechanism => Mechanism,
6939 Arg_Result_Mechanism => Result_Mechanism);
6940 end Export_Function;
6946 -- pragma Export_Object (
6947 -- [Internal =>] LOCAL_NAME
6948 -- [, [External =>] EXTERNAL_SYMBOL]
6949 -- [, [Size =>] EXTERNAL_SYMBOL]);
6951 -- EXTERNAL_SYMBOL ::=
6953 -- | static_string_EXPRESSION
6955 -- PARAMETER_TYPES ::=
6957 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6959 -- TYPE_DESIGNATOR ::=
6961 -- | subtype_Name ' Access
6965 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6967 -- MECHANISM_ASSOCIATION ::=
6968 -- [formal_parameter_NAME =>] MECHANISM_NAME
6970 -- MECHANISM_NAME ::=
6973 -- | Descriptor [([Class =>] CLASS_NAME)]
6975 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6977 when Pragma_Export_Object => Export_Object : declare
6978 Args : Args_List (1 .. 3);
6979 Names : constant Name_List (1 .. 3) := (
6984 Internal : Node_Id renames Args (1);
6985 External : Node_Id renames Args (2);
6986 Size : Node_Id renames Args (3);
6990 Gather_Associations (Names, Args);
6991 Process_Extended_Import_Export_Object_Pragma (
6992 Arg_Internal => Internal,
6993 Arg_External => External,
6997 ----------------------
6998 -- Export_Procedure --
6999 ----------------------
7001 -- pragma Export_Procedure (
7002 -- [Internal =>] LOCAL_NAME
7003 -- [, [External =>] EXTERNAL_SYMBOL]
7004 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7005 -- [, [Mechanism =>] MECHANISM]);
7007 -- EXTERNAL_SYMBOL ::=
7009 -- | static_string_EXPRESSION
7011 -- PARAMETER_TYPES ::=
7013 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7015 -- TYPE_DESIGNATOR ::=
7017 -- | subtype_Name ' Access
7021 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7023 -- MECHANISM_ASSOCIATION ::=
7024 -- [formal_parameter_NAME =>] MECHANISM_NAME
7026 -- MECHANISM_NAME ::=
7029 -- | Descriptor [([Class =>] CLASS_NAME)]
7031 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7033 when Pragma_Export_Procedure => Export_Procedure : declare
7034 Args : Args_List (1 .. 4);
7035 Names : constant Name_List (1 .. 4) := (
7038 Name_Parameter_Types,
7041 Internal : Node_Id renames Args (1);
7042 External : Node_Id renames Args (2);
7043 Parameter_Types : Node_Id renames Args (3);
7044 Mechanism : Node_Id renames Args (4);
7048 Gather_Associations (Names, Args);
7049 Process_Extended_Import_Export_Subprogram_Pragma (
7050 Arg_Internal => Internal,
7051 Arg_External => External,
7052 Arg_Parameter_Types => Parameter_Types,
7053 Arg_Mechanism => Mechanism);
7054 end Export_Procedure;
7060 -- pragma Export_Value (
7061 -- [Value =>] static_integer_EXPRESSION,
7062 -- [Link_Name =>] static_string_EXPRESSION);
7064 when Pragma_Export_Value =>
7066 Check_Arg_Order ((Name_Value, Name_Link_Name));
7067 Check_Arg_Count (2);
7069 Check_Optional_Identifier (Arg1, Name_Value);
7070 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7072 Check_Optional_Identifier (Arg2, Name_Link_Name);
7073 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7075 -----------------------------
7076 -- Export_Valued_Procedure --
7077 -----------------------------
7079 -- pragma Export_Valued_Procedure (
7080 -- [Internal =>] LOCAL_NAME
7081 -- [, [External =>] EXTERNAL_SYMBOL,]
7082 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7083 -- [, [Mechanism =>] MECHANISM]);
7085 -- EXTERNAL_SYMBOL ::=
7087 -- | static_string_EXPRESSION
7089 -- PARAMETER_TYPES ::=
7091 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7093 -- TYPE_DESIGNATOR ::=
7095 -- | subtype_Name ' Access
7099 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7101 -- MECHANISM_ASSOCIATION ::=
7102 -- [formal_parameter_NAME =>] MECHANISM_NAME
7104 -- MECHANISM_NAME ::=
7107 -- | Descriptor [([Class =>] CLASS_NAME)]
7109 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7111 when Pragma_Export_Valued_Procedure =>
7112 Export_Valued_Procedure : declare
7113 Args : Args_List (1 .. 4);
7114 Names : constant Name_List (1 .. 4) := (
7117 Name_Parameter_Types,
7120 Internal : Node_Id renames Args (1);
7121 External : Node_Id renames Args (2);
7122 Parameter_Types : Node_Id renames Args (3);
7123 Mechanism : Node_Id renames Args (4);
7127 Gather_Associations (Names, Args);
7128 Process_Extended_Import_Export_Subprogram_Pragma (
7129 Arg_Internal => Internal,
7130 Arg_External => External,
7131 Arg_Parameter_Types => Parameter_Types,
7132 Arg_Mechanism => Mechanism);
7133 end Export_Valued_Procedure;
7139 -- pragma Extend_System ([Name =>] Identifier);
7141 when Pragma_Extend_System => Extend_System : declare
7144 Check_Valid_Configuration_Pragma;
7145 Check_Arg_Count (1);
7146 Check_Optional_Identifier (Arg1, Name_Name);
7147 Check_Arg_Is_Identifier (Arg1);
7149 Get_Name_String (Chars (Expression (Arg1)));
7152 and then Name_Buffer (1 .. 4) = "aux_"
7154 if Present (System_Extend_Pragma_Arg) then
7155 if Chars (Expression (Arg1)) =
7156 Chars (Expression (System_Extend_Pragma_Arg))
7160 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7161 Error_Pragma ("pragma% conflicts with that #");
7165 System_Extend_Pragma_Arg := Arg1;
7167 if not GNAT_Mode then
7168 System_Extend_Unit := Arg1;
7172 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7176 ------------------------
7177 -- Extensions_Allowed --
7178 ------------------------
7180 -- pragma Extensions_Allowed (ON | OFF);
7182 when Pragma_Extensions_Allowed =>
7184 Check_Arg_Count (1);
7185 Check_No_Identifiers;
7186 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7188 if Chars (Expression (Arg1)) = Name_On then
7189 Extensions_Allowed := True;
7191 Extensions_Allowed := False;
7198 -- pragma External (
7199 -- [ Convention =>] convention_IDENTIFIER,
7200 -- [ Entity =>] local_NAME
7201 -- [, [External_Name =>] static_string_EXPRESSION ]
7202 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7204 when Pragma_External => External : declare
7208 pragma Warnings (Off, C);
7217 Check_At_Least_N_Arguments (2);
7218 Check_At_Most_N_Arguments (4);
7219 Process_Convention (C, Def_Id);
7220 Note_Possible_Modification (Expression (Arg2), Sure => False);
7221 Process_Interface_Name (Def_Id, Arg3, Arg4);
7222 Set_Exported (Def_Id, Arg2);
7225 --------------------------
7226 -- External_Name_Casing --
7227 --------------------------
7229 -- pragma External_Name_Casing (
7230 -- UPPERCASE | LOWERCASE
7231 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7233 when Pragma_External_Name_Casing => External_Name_Casing : declare
7236 Check_No_Identifiers;
7238 if Arg_Count = 2 then
7240 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7242 case Chars (Get_Pragma_Arg (Arg2)) is
7244 Opt.External_Name_Exp_Casing := As_Is;
7246 when Name_Uppercase =>
7247 Opt.External_Name_Exp_Casing := Uppercase;
7249 when Name_Lowercase =>
7250 Opt.External_Name_Exp_Casing := Lowercase;
7257 Check_Arg_Count (1);
7260 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7262 case Chars (Get_Pragma_Arg (Arg1)) is
7263 when Name_Uppercase =>
7264 Opt.External_Name_Imp_Casing := Uppercase;
7266 when Name_Lowercase =>
7267 Opt.External_Name_Imp_Casing := Lowercase;
7272 end External_Name_Casing;
7274 --------------------------
7275 -- Favor_Top_Level --
7276 --------------------------
7278 -- pragma Favor_Top_Level (type_NAME);
7280 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7281 Named_Entity : Entity_Id;
7285 Check_No_Identifiers;
7286 Check_Arg_Count (1);
7287 Check_Arg_Is_Local_Name (Arg1);
7288 Named_Entity := Entity (Expression (Arg1));
7290 -- If it's an access-to-subprogram type (in particular, not a
7291 -- subtype), set the flag on that type.
7293 if Is_Access_Subprogram_Type (Named_Entity) then
7294 Set_Can_Use_Internal_Rep (Named_Entity, False);
7296 -- Otherwise it's an error (name denotes the wrong sort of entity)
7300 ("access-to-subprogram type expected", Expression (Arg1));
7302 end Favor_Top_Level;
7308 -- pragma Fast_Math;
7310 when Pragma_Fast_Math =>
7312 Check_No_Identifiers;
7313 Check_Valid_Configuration_Pragma;
7316 ---------------------------
7317 -- Finalize_Storage_Only --
7318 ---------------------------
7320 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7322 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7323 Assoc : constant Node_Id := Arg1;
7324 Type_Id : constant Node_Id := Expression (Assoc);
7329 Check_No_Identifiers;
7330 Check_Arg_Count (1);
7331 Check_Arg_Is_Local_Name (Arg1);
7333 Find_Type (Type_Id);
7334 Typ := Entity (Type_Id);
7337 or else Rep_Item_Too_Early (Typ, N)
7341 Typ := Underlying_Type (Typ);
7344 if not Is_Controlled (Typ) then
7345 Error_Pragma ("pragma% must specify controlled type");
7348 Check_First_Subtype (Arg1);
7350 if Finalize_Storage_Only (Typ) then
7351 Error_Pragma ("duplicate pragma%, only one allowed");
7353 elsif not Rep_Item_Too_Late (Typ, N) then
7354 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7356 end Finalize_Storage;
7358 --------------------------
7359 -- Float_Representation --
7360 --------------------------
7362 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7364 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7366 when Pragma_Float_Representation => Float_Representation : declare
7374 if Arg_Count = 1 then
7375 Check_Valid_Configuration_Pragma;
7377 Check_Arg_Count (2);
7378 Check_Optional_Identifier (Arg2, Name_Entity);
7379 Check_Arg_Is_Local_Name (Arg2);
7382 Check_No_Identifier (Arg1);
7383 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7385 if not OpenVMS_On_Target then
7386 if Chars (Expression (Arg1)) = Name_VAX_Float then
7388 ("?pragma% ignored (applies only to Open'V'M'S)");
7394 -- One argument case
7396 if Arg_Count = 1 then
7397 if Chars (Expression (Arg1)) = Name_VAX_Float then
7398 if Opt.Float_Format = 'I' then
7399 Error_Pragma ("'I'E'E'E format previously specified");
7402 Opt.Float_Format := 'V';
7405 if Opt.Float_Format = 'V' then
7406 Error_Pragma ("'V'A'X format previously specified");
7409 Opt.Float_Format := 'I';
7412 Set_Standard_Fpt_Formats;
7414 -- Two argument case
7417 Argx := Get_Pragma_Arg (Arg2);
7419 if not Is_Entity_Name (Argx)
7420 or else not Is_Floating_Point_Type (Entity (Argx))
7423 ("second argument of% pragma must be floating-point type",
7427 Ent := Entity (Argx);
7428 Digs := UI_To_Int (Digits_Value (Ent));
7430 -- Two arguments, VAX_Float case
7432 if Chars (Expression (Arg1)) = Name_VAX_Float then
7434 when 6 => Set_F_Float (Ent);
7435 when 9 => Set_D_Float (Ent);
7436 when 15 => Set_G_Float (Ent);
7440 ("wrong digits value, must be 6,9 or 15", Arg2);
7443 -- Two arguments, IEEE_Float case
7447 when 6 => Set_IEEE_Short (Ent);
7448 when 15 => Set_IEEE_Long (Ent);
7452 ("wrong digits value, must be 6 or 15", Arg2);
7456 end Float_Representation;
7462 -- pragma Ident (static_string_EXPRESSION)
7464 -- Note: pragma Comment shares this processing. Pragma Comment is
7465 -- identical to Ident, except that the restriction of the argument to
7466 -- 31 characters and the placement restrictions are not enforced for
7469 when Pragma_Ident | Pragma_Comment => Ident : declare
7474 Check_Arg_Count (1);
7475 Check_No_Identifiers;
7476 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7478 -- For pragma Ident, preserve DEC compatibility by requiring the
7479 -- pragma to appear in a declarative part or package spec.
7481 if Prag_Id = Pragma_Ident then
7482 Check_Is_In_Decl_Part_Or_Package_Spec;
7485 Str := Expr_Value_S (Expression (Arg1));
7492 GP := Parent (Parent (N));
7494 if Nkind_In (GP, N_Package_Declaration,
7495 N_Generic_Package_Declaration)
7500 -- If we have a compilation unit, then record the ident value,
7501 -- checking for improper duplication.
7503 if Nkind (GP) = N_Compilation_Unit then
7504 CS := Ident_String (Current_Sem_Unit);
7506 if Present (CS) then
7508 -- For Ident, we do not permit multiple instances
7510 if Prag_Id = Pragma_Ident then
7511 Error_Pragma ("duplicate% pragma not permitted");
7513 -- For Comment, we concatenate the string, unless we want
7514 -- to preserve the tree structure for ASIS.
7516 elsif not ASIS_Mode then
7517 Start_String (Strval (CS));
7518 Store_String_Char (' ');
7519 Store_String_Chars (Strval (Str));
7520 Set_Strval (CS, End_String);
7524 -- In VMS, the effect of IDENT is achieved by passing
7525 -- IDENTIFICATION=name as a --for-linker switch.
7527 if OpenVMS_On_Target then
7530 ("--for-linker=IDENTIFICATION=");
7531 String_To_Name_Buffer (Strval (Str));
7532 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7534 -- Only the last processed IDENT is saved. The main
7535 -- purpose is so an IDENT associated with a main
7536 -- procedure will be used in preference to an IDENT
7537 -- associated with a with'd package.
7539 Replace_Linker_Option_String
7540 (End_String, "--for-linker=IDENTIFICATION=");
7543 Set_Ident_String (Current_Sem_Unit, Str);
7546 -- For subunits, we just ignore the Ident, since in GNAT these
7547 -- are not separate object files, and hence not separate units
7548 -- in the unit table.
7550 elsif Nkind (GP) = N_Subunit then
7553 -- Otherwise we have a misplaced pragma Ident, but we ignore
7554 -- this if we are in an instantiation, since it comes from
7555 -- a generic, and has no relevance to the instantiation.
7557 elsif Prag_Id = Pragma_Ident then
7558 if Instantiation_Location (Loc) = No_Location then
7559 Error_Pragma ("pragma% only allowed at outer level");
7565 --------------------------
7566 -- Implemented_By_Entry --
7567 --------------------------
7569 -- pragma Implemented_By_Entry (DIRECT_NAME);
7571 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7576 Check_Arg_Count (1);
7577 Check_No_Identifiers;
7578 Check_Arg_Is_Identifier (Arg1);
7579 Check_Arg_Is_Local_Name (Arg1);
7580 Ent := Entity (Expression (Arg1));
7582 -- Pragma Implemented_By_Entry must be applied only to protected
7583 -- synchronized or task interface primitives.
7585 if (Ekind (Ent) /= E_Function
7586 and then Ekind (Ent) /= E_Procedure)
7587 or else not Present (First_Formal (Ent))
7588 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7591 ("pragma % must be applied to a concurrent interface " &
7595 if Einfo.Implemented_By_Entry (Ent)
7596 and then Warn_On_Redundant_Constructs
7598 Error_Pragma ("?duplicate pragma%!");
7600 Set_Implemented_By_Entry (Ent);
7603 end Implemented_By_Entry;
7605 -----------------------
7606 -- Implicit_Packing --
7607 -----------------------
7609 -- pragma Implicit_Packing;
7611 when Pragma_Implicit_Packing =>
7613 Check_Arg_Count (0);
7614 Implicit_Packing := True;
7621 -- [Convention =>] convention_IDENTIFIER,
7622 -- [Entity =>] local_NAME
7623 -- [, [External_Name =>] static_string_EXPRESSION ]
7624 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7626 when Pragma_Import =>
7627 Check_Ada_83_Warning;
7633 Check_At_Least_N_Arguments (2);
7634 Check_At_Most_N_Arguments (4);
7635 Process_Import_Or_Interface;
7637 ----------------------
7638 -- Import_Exception --
7639 ----------------------
7641 -- pragma Import_Exception (
7642 -- [Internal =>] LOCAL_NAME
7643 -- [, [External =>] EXTERNAL_SYMBOL]
7644 -- [, [Form =>] Ada | VMS]
7645 -- [, [Code =>] static_integer_EXPRESSION]);
7647 when Pragma_Import_Exception => Import_Exception : declare
7648 Args : Args_List (1 .. 4);
7649 Names : constant Name_List (1 .. 4) := (
7655 Internal : Node_Id renames Args (1);
7656 External : Node_Id renames Args (2);
7657 Form : Node_Id renames Args (3);
7658 Code : Node_Id renames Args (4);
7662 Gather_Associations (Names, Args);
7664 if Present (External) and then Present (Code) then
7666 ("cannot give both External and Code options for pragma%");
7669 Process_Extended_Import_Export_Exception_Pragma (
7670 Arg_Internal => Internal,
7671 Arg_External => External,
7675 if not Is_VMS_Exception (Entity (Internal)) then
7676 Set_Imported (Entity (Internal));
7678 end Import_Exception;
7680 ---------------------
7681 -- Import_Function --
7682 ---------------------
7684 -- pragma Import_Function (
7685 -- [Internal =>] LOCAL_NAME,
7686 -- [, [External =>] EXTERNAL_SYMBOL]
7687 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7688 -- [, [Result_Type =>] SUBTYPE_MARK]
7689 -- [, [Mechanism =>] MECHANISM]
7690 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7691 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7693 -- EXTERNAL_SYMBOL ::=
7695 -- | static_string_EXPRESSION
7697 -- PARAMETER_TYPES ::=
7699 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7701 -- TYPE_DESIGNATOR ::=
7703 -- | subtype_Name ' Access
7707 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7709 -- MECHANISM_ASSOCIATION ::=
7710 -- [formal_parameter_NAME =>] MECHANISM_NAME
7712 -- MECHANISM_NAME ::=
7715 -- | Descriptor [([Class =>] CLASS_NAME)]
7717 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7719 when Pragma_Import_Function => Import_Function : declare
7720 Args : Args_List (1 .. 7);
7721 Names : constant Name_List (1 .. 7) := (
7724 Name_Parameter_Types,
7727 Name_Result_Mechanism,
7728 Name_First_Optional_Parameter);
7730 Internal : Node_Id renames Args (1);
7731 External : Node_Id renames Args (2);
7732 Parameter_Types : Node_Id renames Args (3);
7733 Result_Type : Node_Id renames Args (4);
7734 Mechanism : Node_Id renames Args (5);
7735 Result_Mechanism : Node_Id renames Args (6);
7736 First_Optional_Parameter : Node_Id renames Args (7);
7740 Gather_Associations (Names, Args);
7741 Process_Extended_Import_Export_Subprogram_Pragma (
7742 Arg_Internal => Internal,
7743 Arg_External => External,
7744 Arg_Parameter_Types => Parameter_Types,
7745 Arg_Result_Type => Result_Type,
7746 Arg_Mechanism => Mechanism,
7747 Arg_Result_Mechanism => Result_Mechanism,
7748 Arg_First_Optional_Parameter => First_Optional_Parameter);
7749 end Import_Function;
7755 -- pragma Import_Object (
7756 -- [Internal =>] LOCAL_NAME
7757 -- [, [External =>] EXTERNAL_SYMBOL]
7758 -- [, [Size =>] EXTERNAL_SYMBOL]);
7760 -- EXTERNAL_SYMBOL ::=
7762 -- | static_string_EXPRESSION
7764 when Pragma_Import_Object => Import_Object : declare
7765 Args : Args_List (1 .. 3);
7766 Names : constant Name_List (1 .. 3) := (
7771 Internal : Node_Id renames Args (1);
7772 External : Node_Id renames Args (2);
7773 Size : Node_Id renames Args (3);
7777 Gather_Associations (Names, Args);
7778 Process_Extended_Import_Export_Object_Pragma (
7779 Arg_Internal => Internal,
7780 Arg_External => External,
7784 ----------------------
7785 -- Import_Procedure --
7786 ----------------------
7788 -- pragma Import_Procedure (
7789 -- [Internal =>] LOCAL_NAME
7790 -- [, [External =>] EXTERNAL_SYMBOL]
7791 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7792 -- [, [Mechanism =>] MECHANISM]
7793 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7795 -- EXTERNAL_SYMBOL ::=
7797 -- | static_string_EXPRESSION
7799 -- PARAMETER_TYPES ::=
7801 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7803 -- TYPE_DESIGNATOR ::=
7805 -- | subtype_Name ' Access
7809 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7811 -- MECHANISM_ASSOCIATION ::=
7812 -- [formal_parameter_NAME =>] MECHANISM_NAME
7814 -- MECHANISM_NAME ::=
7817 -- | Descriptor [([Class =>] CLASS_NAME)]
7819 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7821 when Pragma_Import_Procedure => Import_Procedure : declare
7822 Args : Args_List (1 .. 5);
7823 Names : constant Name_List (1 .. 5) := (
7826 Name_Parameter_Types,
7828 Name_First_Optional_Parameter);
7830 Internal : Node_Id renames Args (1);
7831 External : Node_Id renames Args (2);
7832 Parameter_Types : Node_Id renames Args (3);
7833 Mechanism : Node_Id renames Args (4);
7834 First_Optional_Parameter : Node_Id renames Args (5);
7838 Gather_Associations (Names, Args);
7839 Process_Extended_Import_Export_Subprogram_Pragma (
7840 Arg_Internal => Internal,
7841 Arg_External => External,
7842 Arg_Parameter_Types => Parameter_Types,
7843 Arg_Mechanism => Mechanism,
7844 Arg_First_Optional_Parameter => First_Optional_Parameter);
7845 end Import_Procedure;
7847 -----------------------------
7848 -- Import_Valued_Procedure --
7849 -----------------------------
7851 -- pragma Import_Valued_Procedure (
7852 -- [Internal =>] LOCAL_NAME
7853 -- [, [External =>] EXTERNAL_SYMBOL]
7854 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7855 -- [, [Mechanism =>] MECHANISM]
7856 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7858 -- EXTERNAL_SYMBOL ::=
7860 -- | static_string_EXPRESSION
7862 -- PARAMETER_TYPES ::=
7864 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7866 -- TYPE_DESIGNATOR ::=
7868 -- | subtype_Name ' Access
7872 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7874 -- MECHANISM_ASSOCIATION ::=
7875 -- [formal_parameter_NAME =>] MECHANISM_NAME
7877 -- MECHANISM_NAME ::=
7880 -- | Descriptor [([Class =>] CLASS_NAME)]
7882 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7884 when Pragma_Import_Valued_Procedure =>
7885 Import_Valued_Procedure : declare
7886 Args : Args_List (1 .. 5);
7887 Names : constant Name_List (1 .. 5) := (
7890 Name_Parameter_Types,
7892 Name_First_Optional_Parameter);
7894 Internal : Node_Id renames Args (1);
7895 External : Node_Id renames Args (2);
7896 Parameter_Types : Node_Id renames Args (3);
7897 Mechanism : Node_Id renames Args (4);
7898 First_Optional_Parameter : Node_Id renames Args (5);
7902 Gather_Associations (Names, Args);
7903 Process_Extended_Import_Export_Subprogram_Pragma (
7904 Arg_Internal => Internal,
7905 Arg_External => External,
7906 Arg_Parameter_Types => Parameter_Types,
7907 Arg_Mechanism => Mechanism,
7908 Arg_First_Optional_Parameter => First_Optional_Parameter);
7909 end Import_Valued_Procedure;
7911 ------------------------
7912 -- Initialize_Scalars --
7913 ------------------------
7915 -- pragma Initialize_Scalars;
7917 when Pragma_Initialize_Scalars =>
7919 Check_Arg_Count (0);
7920 Check_Valid_Configuration_Pragma;
7921 Check_Restriction (No_Initialize_Scalars, N);
7923 if not Restriction_Active (No_Initialize_Scalars) then
7924 Init_Or_Norm_Scalars := True;
7925 Initialize_Scalars := True;
7932 -- pragma Inline ( NAME {, NAME} );
7934 when Pragma_Inline =>
7936 -- Pragma is active if inlining option is active
7938 Process_Inline (Inline_Active);
7944 -- pragma Inline_Always ( NAME {, NAME} );
7946 when Pragma_Inline_Always =>
7948 Process_Inline (True);
7950 --------------------
7951 -- Inline_Generic --
7952 --------------------
7954 -- pragma Inline_Generic (NAME {, NAME});
7956 when Pragma_Inline_Generic =>
7958 Process_Generic_List;
7960 ----------------------
7961 -- Inspection_Point --
7962 ----------------------
7964 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7966 when Pragma_Inspection_Point => Inspection_Point : declare
7971 if Arg_Count > 0 then
7974 Exp := Expression (Arg);
7977 if not Is_Entity_Name (Exp)
7978 or else not Is_Object (Entity (Exp))
7980 Error_Pragma_Arg ("object name required", Arg);
7987 end Inspection_Point;
7993 -- pragma Interface (
7994 -- [ Convention =>] convention_IDENTIFIER,
7995 -- [ Entity =>] local_NAME
7996 -- [, [External_Name =>] static_string_EXPRESSION ]
7997 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7999 when Pragma_Interface =>
8006 Check_At_Least_N_Arguments (2);
8007 Check_At_Most_N_Arguments (4);
8008 Process_Import_Or_Interface;
8010 --------------------
8011 -- Interface_Name --
8012 --------------------
8014 -- pragma Interface_Name (
8015 -- [ Entity =>] local_NAME
8016 -- [,[External_Name =>] static_string_EXPRESSION ]
8017 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8019 when Pragma_Interface_Name => Interface_Name : declare
8028 ((Name_Entity, Name_External_Name, Name_Link_Name));
8029 Check_At_Least_N_Arguments (2);
8030 Check_At_Most_N_Arguments (3);
8031 Id := Expression (Arg1);
8034 if not Is_Entity_Name (Id) then
8036 ("first argument for pragma% must be entity name", Arg1);
8037 elsif Etype (Id) = Any_Type then
8040 Def_Id := Entity (Id);
8043 -- Special DEC-compatible processing for the object case, forces
8044 -- object to be imported.
8046 if Ekind (Def_Id) = E_Variable then
8047 Kill_Size_Check_Code (Def_Id);
8048 Note_Possible_Modification (Id, Sure => False);
8050 -- Initialization is not allowed for imported variable
8052 if Present (Expression (Parent (Def_Id)))
8053 and then Comes_From_Source (Expression (Parent (Def_Id)))
8055 Error_Msg_Sloc := Sloc (Def_Id);
8057 ("no initialization allowed for declaration of& #",
8061 -- For compatibility, support VADS usage of providing both
8062 -- pragmas Interface and Interface_Name to obtain the effect
8063 -- of a single Import pragma.
8065 if Is_Imported (Def_Id)
8066 and then Present (First_Rep_Item (Def_Id))
8067 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8069 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8073 Set_Imported (Def_Id);
8076 Set_Is_Public (Def_Id);
8077 Process_Interface_Name (Def_Id, Arg2, Arg3);
8080 -- Otherwise must be subprogram
8082 elsif not Is_Subprogram (Def_Id) then
8084 ("argument of pragma% is not subprogram", Arg1);
8087 Check_At_Most_N_Arguments (3);
8091 -- Loop through homonyms
8094 Def_Id := Get_Base_Subprogram (Hom_Id);
8096 if Is_Imported (Def_Id) then
8097 Process_Interface_Name (Def_Id, Arg2, Arg3);
8101 Hom_Id := Homonym (Hom_Id);
8103 exit when No (Hom_Id)
8104 or else Scope (Hom_Id) /= Current_Scope;
8109 ("argument of pragma% is not imported subprogram",
8115 -----------------------
8116 -- Interrupt_Handler --
8117 -----------------------
8119 -- pragma Interrupt_Handler (handler_NAME);
8121 when Pragma_Interrupt_Handler =>
8122 Check_Ada_83_Warning;
8123 Check_Arg_Count (1);
8124 Check_No_Identifiers;
8126 if No_Run_Time_Mode then
8127 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8129 Check_Interrupt_Or_Attach_Handler;
8130 Process_Interrupt_Or_Attach_Handler;
8133 ------------------------
8134 -- Interrupt_Priority --
8135 ------------------------
8137 -- pragma Interrupt_Priority [(EXPRESSION)];
8139 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8140 P : constant Node_Id := Parent (N);
8144 Check_Ada_83_Warning;
8146 if Arg_Count /= 0 then
8147 Arg := Expression (Arg1);
8148 Check_Arg_Count (1);
8149 Check_No_Identifiers;
8151 -- The expression must be analyzed in the special manner
8152 -- described in "Handling of Default and Per-Object
8153 -- Expressions" in sem.ads.
8155 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8158 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8162 elsif Has_Priority_Pragma (P) then
8163 Error_Pragma ("duplicate pragma% not allowed");
8166 Set_Has_Priority_Pragma (P, True);
8167 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8169 end Interrupt_Priority;
8171 ---------------------
8172 -- Interrupt_State --
8173 ---------------------
8175 -- pragma Interrupt_State (
8176 -- [Name =>] INTERRUPT_ID,
8177 -- [State =>] INTERRUPT_STATE);
8179 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8180 -- INTERRUPT_STATE => System | Runtime | User
8182 -- Note: if the interrupt id is given as an identifier, then it must
8183 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8184 -- given as a static integer expression which must be in the range of
8185 -- Ada.Interrupts.Interrupt_ID.
8187 when Pragma_Interrupt_State => Interrupt_State : declare
8189 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8190 -- This is the entity Ada.Interrupts.Interrupt_ID;
8192 State_Type : Character;
8193 -- Set to 's'/'r'/'u' for System/Runtime/User
8196 -- Index to entry in Interrupt_States table
8199 -- Value of interrupt
8201 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8202 -- The first argument to the pragma
8204 Int_Ent : Entity_Id;
8205 -- Interrupt entity in Ada.Interrupts.Names
8209 Check_Arg_Order ((Name_Name, Name_State));
8210 Check_Arg_Count (2);
8212 Check_Optional_Identifier (Arg1, Name_Name);
8213 Check_Optional_Identifier (Arg2, Name_State);
8214 Check_Arg_Is_Identifier (Arg2);
8216 -- First argument is identifier
8218 if Nkind (Arg1X) = N_Identifier then
8220 -- Search list of names in Ada.Interrupts.Names
8222 Int_Ent := First_Entity (RTE (RE_Names));
8224 if No (Int_Ent) then
8225 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8227 elsif Chars (Int_Ent) = Chars (Arg1X) then
8228 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8232 Next_Entity (Int_Ent);
8235 -- First argument is not an identifier, so it must be a static
8236 -- expression of type Ada.Interrupts.Interrupt_ID.
8239 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8240 Int_Val := Expr_Value (Arg1X);
8242 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8244 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8247 ("value not in range of type " &
8248 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8254 case Chars (Get_Pragma_Arg (Arg2)) is
8255 when Name_Runtime => State_Type := 'r';
8256 when Name_System => State_Type := 's';
8257 when Name_User => State_Type := 'u';
8260 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8263 -- Check if entry is already stored
8265 IST_Num := Interrupt_States.First;
8267 -- If entry not found, add it
8269 if IST_Num > Interrupt_States.Last then
8270 Interrupt_States.Append
8271 ((Interrupt_Number => UI_To_Int (Int_Val),
8272 Interrupt_State => State_Type,
8273 Pragma_Loc => Loc));
8276 -- Case of entry for the same entry
8278 elsif Int_Val = Interrupt_States.Table (IST_Num).
8281 -- If state matches, done, no need to make redundant entry
8284 State_Type = Interrupt_States.Table (IST_Num).
8287 -- Otherwise if state does not match, error
8290 Interrupt_States.Table (IST_Num).Pragma_Loc;
8292 ("state conflicts with that given #", Arg2);
8296 IST_Num := IST_Num + 1;
8298 end Interrupt_State;
8300 ----------------------
8301 -- Java_Constructor --
8302 ----------------------
8304 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8306 -- Also handles pragma CIL_Constructor
8308 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8309 Java_Constructor : declare
8313 Convention : Convention_Id;
8317 Check_Arg_Count (1);
8318 Check_Optional_Identifier (Arg1, Name_Entity);
8319 Check_Arg_Is_Local_Name (Arg1);
8321 Id := Expression (Arg1);
8322 Find_Program_Unit_Name (Id);
8324 -- If we did not find the name, we are done
8326 if Etype (Id) = Any_Type then
8331 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8332 when Pragma_Java_Constructor => Convention := Convention_Java;
8333 when others => null;
8336 Hom_Id := Entity (Id);
8338 -- Loop through homonyms
8341 Def_Id := Get_Base_Subprogram (Hom_Id);
8343 -- The constructor is required to be a function returning an
8344 -- access type whose designated type has convention Java/CIL.
8346 if Ekind (Def_Id) = E_Function
8348 (Is_Value_Type (Etype (Def_Id))
8350 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8352 Atree.Convention (Etype (Def_Id)) = Convention)
8354 (Ekind (Etype (Def_Id)) in Access_Kind
8357 (Designated_Type (Etype (Def_Id))) = Convention
8360 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8363 Set_Is_Constructor (Def_Id);
8364 Set_Convention (Def_Id, Convention);
8365 Set_Is_Imported (Def_Id);
8368 if Convention = Convention_Java then
8370 ("pragma% requires function returning a " &
8371 "'Java access type", Arg1);
8373 pragma Assert (Convention = Convention_CIL);
8375 ("pragma% requires function returning a " &
8376 "'C'I'L access type", Arg1);
8380 Hom_Id := Homonym (Hom_Id);
8382 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8384 end Java_Constructor;
8386 ----------------------
8387 -- Java_Interface --
8388 ----------------------
8390 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8392 when Pragma_Java_Interface => Java_Interface : declare
8398 Check_Arg_Count (1);
8399 Check_Optional_Identifier (Arg1, Name_Entity);
8400 Check_Arg_Is_Local_Name (Arg1);
8402 Arg := Expression (Arg1);
8405 if Etype (Arg) = Any_Type then
8409 if not Is_Entity_Name (Arg)
8410 or else not Is_Type (Entity (Arg))
8412 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8415 Typ := Underlying_Type (Entity (Arg));
8417 -- For now simply check some of the semantic constraints on the
8418 -- type. This currently leaves out some restrictions on interface
8419 -- types, namely that the parent type must be java.lang.Object.Typ
8420 -- and that all primitives of the type should be declared
8423 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8424 Error_Pragma_Arg ("pragma% requires an abstract "
8425 & "tagged type", Arg1);
8427 elsif not Has_Discriminants (Typ)
8428 or else Ekind (Etype (First_Discriminant (Typ)))
8429 /= E_Anonymous_Access_Type
8431 not Is_Class_Wide_Type
8432 (Designated_Type (Etype (First_Discriminant (Typ))))
8435 ("type must have a class-wide access discriminant", Arg1);
8443 -- pragma Keep_Names ([On => ] local_NAME);
8445 when Pragma_Keep_Names => Keep_Names : declare
8450 Check_Arg_Count (1);
8451 Check_Optional_Identifier (Arg1, Name_On);
8452 Check_Arg_Is_Local_Name (Arg1);
8454 Arg := Expression (Arg1);
8457 if Etype (Arg) = Any_Type then
8461 if not Is_Entity_Name (Arg)
8462 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8465 ("pragma% requires a local enumeration type", Arg1);
8468 Set_Discard_Names (Entity (Arg), False);
8475 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8477 when Pragma_License =>
8479 Check_Arg_Count (1);
8480 Check_No_Identifiers;
8481 Check_Valid_Configuration_Pragma;
8482 Check_Arg_Is_Identifier (Arg1);
8485 Sind : constant Source_File_Index :=
8486 Source_Index (Current_Sem_Unit);
8489 case Chars (Get_Pragma_Arg (Arg1)) is
8491 Set_License (Sind, GPL);
8493 when Name_Modified_GPL =>
8494 Set_License (Sind, Modified_GPL);
8496 when Name_Restricted =>
8497 Set_License (Sind, Restricted);
8499 when Name_Unrestricted =>
8500 Set_License (Sind, Unrestricted);
8503 Error_Pragma_Arg ("invalid license name", Arg1);
8511 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8513 when Pragma_Link_With => Link_With : declare
8519 if Operating_Mode = Generate_Code
8520 and then In_Extended_Main_Source_Unit (N)
8522 Check_At_Least_N_Arguments (1);
8523 Check_No_Identifiers;
8524 Check_Is_In_Decl_Part_Or_Package_Spec;
8525 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8529 while Present (Arg) loop
8530 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8532 -- Store argument, converting sequences of spaces to a
8533 -- single null character (this is one of the differences
8534 -- in processing between Link_With and Linker_Options).
8537 C : constant Char_Code := Get_Char_Code (' ');
8538 S : constant String_Id :=
8539 Strval (Expr_Value_S (Expression (Arg)));
8540 L : constant Nat := String_Length (S);
8543 procedure Skip_Spaces;
8544 -- Advance F past any spaces
8550 procedure Skip_Spaces is
8552 while F <= L and then Get_String_Char (S, F) = C loop
8557 -- Start of processing for Arg_Store
8560 Skip_Spaces; -- skip leading spaces
8562 -- Loop through characters, changing any embedded
8563 -- sequence of spaces to a single null character (this
8564 -- is how Link_With/Linker_Options differ)
8567 if Get_String_Char (S, F) = C then
8570 Store_String_Char (ASCII.NUL);
8573 Store_String_Char (Get_String_Char (S, F));
8581 if Present (Arg) then
8582 Store_String_Char (ASCII.NUL);
8586 Store_Linker_Option_String (End_String);
8594 -- pragma Linker_Alias (
8595 -- [Entity =>] LOCAL_NAME
8596 -- [Target =>] static_string_EXPRESSION);
8598 when Pragma_Linker_Alias =>
8600 Check_Arg_Order ((Name_Entity, Name_Target));
8601 Check_Arg_Count (2);
8602 Check_Optional_Identifier (Arg1, Name_Entity);
8603 Check_Optional_Identifier (Arg2, Name_Target);
8604 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8605 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8607 -- The only processing required is to link this item on to the
8608 -- list of rep items for the given entity. This is accomplished
8609 -- by the call to Rep_Item_Too_Late (when no error is detected
8610 -- and False is returned).
8612 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8615 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8618 ------------------------
8619 -- Linker_Constructor --
8620 ------------------------
8622 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8624 -- Code is shared with Linker_Destructor
8626 -----------------------
8627 -- Linker_Destructor --
8628 -----------------------
8630 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8632 when Pragma_Linker_Constructor |
8633 Pragma_Linker_Destructor =>
8634 Linker_Constructor : declare
8640 Check_Arg_Count (1);
8641 Check_No_Identifiers;
8642 Check_Arg_Is_Local_Name (Arg1);
8643 Arg1_X := Expression (Arg1);
8645 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8647 if not Is_Library_Level_Entity (Proc) then
8649 ("argument for pragma% must be library level entity", Arg1);
8652 -- The only processing required is to link this item on to the
8653 -- list of rep items for the given entity. This is accomplished
8654 -- by the call to Rep_Item_Too_Late (when no error is detected
8655 -- and False is returned).
8657 if Rep_Item_Too_Late (Proc, N) then
8660 Set_Has_Gigi_Rep_Item (Proc);
8662 end Linker_Constructor;
8664 --------------------
8665 -- Linker_Options --
8666 --------------------
8668 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8670 when Pragma_Linker_Options => Linker_Options : declare
8674 Check_Ada_83_Warning;
8675 Check_No_Identifiers;
8676 Check_Arg_Count (1);
8677 Check_Is_In_Decl_Part_Or_Package_Spec;
8678 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8679 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8682 while Present (Arg) loop
8683 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8684 Store_String_Char (ASCII.NUL);
8685 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8689 if Operating_Mode = Generate_Code
8690 and then In_Extended_Main_Source_Unit (N)
8692 Store_Linker_Option_String (End_String);
8696 --------------------
8697 -- Linker_Section --
8698 --------------------
8700 -- pragma Linker_Section (
8701 -- [Entity =>] LOCAL_NAME
8702 -- [Section =>] static_string_EXPRESSION);
8704 when Pragma_Linker_Section =>
8706 Check_Arg_Order ((Name_Entity, Name_Section));
8707 Check_Arg_Count (2);
8708 Check_Optional_Identifier (Arg1, Name_Entity);
8709 Check_Optional_Identifier (Arg2, Name_Section);
8710 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8711 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8713 -- This pragma applies only to objects
8715 if not Is_Object (Entity (Expression (Arg1))) then
8716 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8719 -- The only processing required is to link this item on to the
8720 -- list of rep items for the given entity. This is accomplished
8721 -- by the call to Rep_Item_Too_Late (when no error is detected
8722 -- and False is returned).
8724 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8727 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8734 -- pragma List (On | Off)
8736 -- There is nothing to do here, since we did all the processing for
8737 -- this pragma in Par.Prag (so that it works properly even in syntax
8743 --------------------
8744 -- Locking_Policy --
8745 --------------------
8747 -- pragma Locking_Policy (policy_IDENTIFIER);
8749 when Pragma_Locking_Policy => declare
8753 Check_Ada_83_Warning;
8754 Check_Arg_Count (1);
8755 Check_No_Identifiers;
8756 Check_Arg_Is_Locking_Policy (Arg1);
8757 Check_Valid_Configuration_Pragma;
8758 Get_Name_String (Chars (Expression (Arg1)));
8759 LP := Fold_Upper (Name_Buffer (1));
8761 if Locking_Policy /= ' '
8762 and then Locking_Policy /= LP
8764 Error_Msg_Sloc := Locking_Policy_Sloc;
8765 Error_Pragma ("locking policy incompatible with policy#");
8767 -- Set new policy, but always preserve System_Location since we
8768 -- like the error message with the run time name.
8771 Locking_Policy := LP;
8773 if Locking_Policy_Sloc /= System_Location then
8774 Locking_Policy_Sloc := Loc;
8783 -- pragma Long_Float (D_Float | G_Float);
8785 when Pragma_Long_Float =>
8787 Check_Valid_Configuration_Pragma;
8788 Check_Arg_Count (1);
8789 Check_No_Identifier (Arg1);
8790 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8792 if not OpenVMS_On_Target then
8793 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8798 if Chars (Expression (Arg1)) = Name_D_Float then
8799 if Opt.Float_Format_Long = 'G' then
8800 Error_Pragma ("G_Float previously specified");
8803 Opt.Float_Format_Long := 'D';
8805 -- G_Float case (this is the default, does not need overriding)
8808 if Opt.Float_Format_Long = 'D' then
8809 Error_Pragma ("D_Float previously specified");
8812 Opt.Float_Format_Long := 'G';
8815 Set_Standard_Fpt_Formats;
8817 -----------------------
8818 -- Machine_Attribute --
8819 -----------------------
8821 -- pragma Machine_Attribute (
8822 -- [Entity =>] LOCAL_NAME,
8823 -- [Attribute_Name =>] static_string_EXPRESSION
8824 -- [, [Info =>] static_EXPRESSION] );
8826 when Pragma_Machine_Attribute => Machine_Attribute : declare
8831 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8833 if Arg_Count = 3 then
8834 Check_Optional_Identifier (Arg3, Name_Info);
8835 Check_Arg_Is_Static_Expression (Arg3);
8837 Check_Arg_Count (2);
8840 Check_Optional_Identifier (Arg1, Name_Entity);
8841 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8842 Check_Arg_Is_Local_Name (Arg1);
8843 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8844 Def_Id := Entity (Expression (Arg1));
8846 if Is_Access_Type (Def_Id) then
8847 Def_Id := Designated_Type (Def_Id);
8850 if Rep_Item_Too_Early (Def_Id, N) then
8854 Def_Id := Underlying_Type (Def_Id);
8856 -- The only processing required is to link this item on to the
8857 -- list of rep items for the given entity. This is accomplished
8858 -- by the call to Rep_Item_Too_Late (when no error is detected
8859 -- and False is returned).
8861 if Rep_Item_Too_Late (Def_Id, N) then
8864 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8866 end Machine_Attribute;
8873 -- (MAIN_OPTION [, MAIN_OPTION]);
8876 -- [STACK_SIZE =>] static_integer_EXPRESSION
8877 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8878 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8880 when Pragma_Main => Main : declare
8881 Args : Args_List (1 .. 3);
8882 Names : constant Name_List (1 .. 3) := (
8884 Name_Task_Stack_Size_Default,
8885 Name_Time_Slicing_Enabled);
8891 Gather_Associations (Names, Args);
8893 for J in 1 .. 2 loop
8894 if Present (Args (J)) then
8895 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8899 if Present (Args (3)) then
8900 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8904 while Present (Nod) loop
8905 if Nkind (Nod) = N_Pragma
8906 and then Pragma_Name (Nod) = Name_Main
8908 Error_Msg_Name_1 := Pname;
8909 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8920 -- pragma Main_Storage
8921 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8923 -- MAIN_STORAGE_OPTION ::=
8924 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8925 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8927 when Pragma_Main_Storage => Main_Storage : declare
8928 Args : Args_List (1 .. 2);
8929 Names : constant Name_List (1 .. 2) := (
8930 Name_Working_Storage,
8937 Gather_Associations (Names, Args);
8939 for J in 1 .. 2 loop
8940 if Present (Args (J)) then
8941 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8945 Check_In_Main_Program;
8948 while Present (Nod) loop
8949 if Nkind (Nod) = N_Pragma
8950 and then Pragma_Name (Nod) = Name_Main_Storage
8952 Error_Msg_Name_1 := Pname;
8953 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8964 -- pragma Memory_Size (NUMERIC_LITERAL)
8966 when Pragma_Memory_Size =>
8969 -- Memory size is simply ignored
8971 Check_No_Identifiers;
8972 Check_Arg_Count (1);
8973 Check_Arg_Is_Integer_Literal (Arg1);
8981 -- The only correct use of this pragma is on its own in a file, in
8982 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
8983 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
8984 -- check for a file containing nothing but a No_Body pragma). If we
8985 -- attempt to process it during normal semantics processing, it means
8986 -- it was misplaced.
8988 when Pragma_No_Body =>
8996 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8998 when Pragma_No_Return => No_Return : declare
9006 Check_At_Least_N_Arguments (1);
9008 -- Loop through arguments of pragma
9011 while Present (Arg) loop
9012 Check_Arg_Is_Local_Name (Arg);
9013 Id := Expression (Arg);
9016 if not Is_Entity_Name (Id) then
9017 Error_Pragma_Arg ("entity name required", Arg);
9020 if Etype (Id) = Any_Type then
9024 -- Loop to find matching procedures
9029 and then Scope (E) = Current_Scope
9031 if Ekind (E) = E_Procedure
9032 or else Ekind (E) = E_Generic_Procedure
9036 -- Set flag on any alias as well
9038 if Is_Overloadable (E) and then Present (Alias (E)) then
9039 Set_No_Return (Alias (E));
9049 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9060 -- pragma No_Run_Time;
9062 -- Note: this pragma is retained for backwards compatibility. See
9063 -- body of Rtsfind for full details on its handling.
9065 when Pragma_No_Run_Time =>
9067 Check_Valid_Configuration_Pragma;
9068 Check_Arg_Count (0);
9070 No_Run_Time_Mode := True;
9071 Configurable_Run_Time_Mode := True;
9073 -- Set Duration to 32 bits if word size is 32
9075 if Ttypes.System_Word_Size = 32 then
9076 Duration_32_Bits_On_Target := True;
9079 -- Set appropriate restrictions
9081 Set_Restriction (No_Finalization, N);
9082 Set_Restriction (No_Exception_Handlers, N);
9083 Set_Restriction (Max_Tasks, N, 0);
9084 Set_Restriction (No_Tasking, N);
9086 ------------------------
9087 -- No_Strict_Aliasing --
9088 ------------------------
9090 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9092 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9097 Check_At_Most_N_Arguments (1);
9099 if Arg_Count = 0 then
9100 Check_Valid_Configuration_Pragma;
9101 Opt.No_Strict_Aliasing := True;
9104 Check_Optional_Identifier (Arg2, Name_Entity);
9105 Check_Arg_Is_Local_Name (Arg1);
9106 E_Id := Entity (Expression (Arg1));
9108 if E_Id = Any_Type then
9110 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9111 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9114 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9116 end No_Strict_Aliasing;
9118 -----------------------
9119 -- Normalize_Scalars --
9120 -----------------------
9122 -- pragma Normalize_Scalars;
9124 when Pragma_Normalize_Scalars =>
9125 Check_Ada_83_Warning;
9126 Check_Arg_Count (0);
9127 Check_Valid_Configuration_Pragma;
9128 Normalize_Scalars := True;
9129 Init_Or_Norm_Scalars := True;
9135 -- pragma Obsolescent;
9137 -- pragma Obsolescent (
9138 -- [Message =>] static_string_EXPRESSION
9139 -- [,[Version =>] Ada_05]]);
9141 -- pragma Obsolescent (
9143 -- [,[Message =>] static_string_EXPRESSION
9144 -- [,[Version =>] Ada_05]] );
9146 when Pragma_Obsolescent => Obsolescent : declare
9150 procedure Set_Obsolescent (E : Entity_Id);
9151 -- Given an entity Ent, mark it as obsolescent if appropriate
9153 ---------------------
9154 -- Set_Obsolescent --
9155 ---------------------
9157 procedure Set_Obsolescent (E : Entity_Id) is
9166 -- Entity name was given
9168 if Present (Ename) then
9170 -- If entity name matches, we are fine. Save entity in
9171 -- pragma argument, for ASIS use.
9173 if Chars (Ename) = Chars (Ent) then
9174 Set_Entity (Ename, Ent);
9175 Generate_Reference (Ent, Ename);
9177 -- If entity name does not match, only possibility is an
9178 -- enumeration literal from an enumeration type declaration.
9180 elsif Ekind (Ent) /= E_Enumeration_Type then
9182 ("pragma % entity name does not match declaration");
9185 Ent := First_Literal (E);
9189 ("pragma % entity name does not match any " &
9190 "enumeration literal");
9192 elsif Chars (Ent) = Chars (Ename) then
9193 Set_Entity (Ename, Ent);
9194 Generate_Reference (Ent, Ename);
9198 Ent := Next_Literal (Ent);
9204 -- Ent points to entity to be marked
9206 if Arg_Count >= 1 then
9208 -- Deal with static string argument
9210 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9211 S := Strval (Expression (Arg1));
9213 for J in 1 .. String_Length (S) loop
9214 if not In_Character_Range (Get_String_Char (S, J)) then
9216 ("pragma% argument does not allow wide characters",
9221 Obsolescent_Warnings.Append
9222 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9224 -- Check for Ada_05 parameter
9226 if Arg_Count /= 1 then
9227 Check_Arg_Count (2);
9230 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9233 Check_Arg_Is_Identifier (Argx);
9235 if Chars (Argx) /= Name_Ada_05 then
9236 Error_Msg_Name_2 := Name_Ada_05;
9238 ("only allowed argument for pragma% is %", Argx);
9241 if Ada_Version_Explicit < Ada_05
9242 or else not Warn_On_Ada_2005_Compatibility
9250 -- Set flag if pragma active
9253 Set_Is_Obsolescent (Ent);
9257 end Set_Obsolescent;
9259 -- Start of processing for pragma Obsolescent
9264 Check_At_Most_N_Arguments (3);
9266 -- See if first argument specifies an entity name
9270 (Chars (Arg1) = Name_Entity
9272 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9276 Ename := Get_Pragma_Arg (Arg1);
9278 -- Eliminate first argument, so we can share processing
9282 Arg_Count := Arg_Count - 1;
9284 -- No Entity name argument given
9290 if Arg_Count >= 1 then
9291 Check_Optional_Identifier (Arg1, Name_Message);
9293 if Arg_Count = 2 then
9294 Check_Optional_Identifier (Arg2, Name_Version);
9298 -- Get immediately preceding declaration
9301 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9305 -- Cases where we do not follow anything other than another pragma
9309 -- First case: library level compilation unit declaration with
9310 -- the pragma immediately following the declaration.
9312 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9314 (Defining_Entity (Unit (Parent (Parent (N)))));
9317 -- Case 2: library unit placement for package
9321 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9323 if Is_Package_Or_Generic_Package (Ent) then
9324 Set_Obsolescent (Ent);
9330 -- Cases where we must follow a declaration
9333 if Nkind (Decl) not in N_Declaration
9334 and then Nkind (Decl) not in N_Later_Decl_Item
9335 and then Nkind (Decl) not in N_Generic_Declaration
9336 and then Nkind (Decl) not in N_Renaming_Declaration
9339 ("pragma% misplaced, "
9340 & "must immediately follow a declaration");
9343 Set_Obsolescent (Defining_Entity (Decl));
9353 -- pragma Optimize (Time | Space | Off);
9355 -- The actual check for optimize is done in Gigi. Note that this
9356 -- pragma does not actually change the optimization setting, it
9357 -- simply checks that it is consistent with the pragma.
9359 when Pragma_Optimize =>
9360 Check_No_Identifiers;
9361 Check_Arg_Count (1);
9362 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9364 ------------------------
9365 -- Optimize_Alignment --
9366 ------------------------
9368 -- pragma Optimize_Alignment (Time | Space | Off);
9370 when Pragma_Optimize_Alignment =>
9372 Check_No_Identifiers;
9373 Check_Arg_Count (1);
9374 Check_Valid_Configuration_Pragma;
9377 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9381 Opt.Optimize_Alignment := 'T';
9383 Opt.Optimize_Alignment := 'S';
9385 Opt.Optimize_Alignment := 'O';
9387 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9391 -- Set indication that mode is set locally. If we are in fact in a
9392 -- configuration pragma file, this setting is harmless since the
9393 -- switch will get reset anyway at the start of each unit.
9395 Optimize_Alignment_Local := True;
9401 -- pragma Pack (first_subtype_LOCAL_NAME);
9403 when Pragma_Pack => Pack : declare
9404 Assoc : constant Node_Id := Arg1;
9409 Check_No_Identifiers;
9410 Check_Arg_Count (1);
9411 Check_Arg_Is_Local_Name (Arg1);
9413 Type_Id := Expression (Assoc);
9414 Find_Type (Type_Id);
9415 Typ := Entity (Type_Id);
9418 or else Rep_Item_Too_Early (Typ, N)
9422 Typ := Underlying_Type (Typ);
9425 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9426 Error_Pragma ("pragma% must specify array or record type");
9429 Check_First_Subtype (Arg1);
9431 if Has_Pragma_Pack (Typ) then
9432 Error_Pragma ("duplicate pragma%, only one allowed");
9436 elsif Is_Array_Type (Typ) then
9438 -- Pack not allowed for aliased or atomic components
9440 if Has_Aliased_Components (Base_Type (Typ)) then
9442 ("pragma% ignored, cannot pack aliased components?");
9444 elsif Has_Atomic_Components (Typ)
9445 or else Is_Atomic (Component_Type (Typ))
9448 ("?pragma% ignored, cannot pack atomic components");
9451 -- If we had an explicit component size given, then we do not
9452 -- let Pack override this given size. We also give a warning
9453 -- that Pack is being ignored unless we can tell for sure that
9454 -- the Pack would not have had any effect anyway.
9456 if Has_Component_Size_Clause (Typ) then
9457 if Known_Static_RM_Size (Component_Type (Typ))
9459 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9464 ("?pragma% ignored, explicit component size given");
9467 -- If no prior array component size given, Pack is effective
9470 if not Rep_Item_Too_Late (Typ, N) then
9471 if VM_Target = No_VM then
9472 Set_Is_Packed (Base_Type (Typ));
9473 Set_Has_Pragma_Pack (Base_Type (Typ));
9474 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9476 elsif not GNAT_Mode then
9478 ("?pragma% ignored in this configuration");
9483 -- For record types, the pack is always effective
9485 else pragma Assert (Is_Record_Type (Typ));
9486 if not Rep_Item_Too_Late (Typ, N) then
9487 if VM_Target = No_VM then
9488 Set_Is_Packed (Base_Type (Typ));
9489 Set_Has_Pragma_Pack (Base_Type (Typ));
9490 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9492 elsif not GNAT_Mode then
9493 Error_Pragma ("?pragma% ignored in this configuration");
9505 -- There is nothing to do here, since we did all the processing for
9506 -- this pragma in Par.Prag (so that it works properly even in syntax
9516 -- pragma Passive [(PASSIVE_FORM)];
9518 -- PASSIVE_FORM ::= Semaphore | No
9520 when Pragma_Passive =>
9523 if Nkind (Parent (N)) /= N_Task_Definition then
9524 Error_Pragma ("pragma% must be within task definition");
9527 if Arg_Count /= 0 then
9528 Check_Arg_Count (1);
9529 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9532 ----------------------------------
9533 -- Preelaborable_Initialization --
9534 ----------------------------------
9536 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9538 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9543 Check_Arg_Count (1);
9544 Check_No_Identifiers;
9545 Check_Arg_Is_Identifier (Arg1);
9546 Check_Arg_Is_Local_Name (Arg1);
9547 Check_First_Subtype (Arg1);
9548 Ent := Entity (Expression (Arg1));
9550 if not Is_Private_Type (Ent)
9551 and then not Is_Protected_Type (Ent)
9554 ("pragma % can only be applied to private or protected type",
9558 -- Give an error if the pragma is applied to a protected type that
9559 -- does not qualify (due to having entries, or due to components
9560 -- that do not qualify).
9562 if Is_Protected_Type (Ent)
9563 and then not Has_Preelaborable_Initialization (Ent)
9566 ("protected type & does not have preelaborable " &
9567 "initialization", Ent);
9569 -- Otherwise mark the type as definitely having preelaborable
9573 Set_Known_To_Have_Preelab_Init (Ent);
9576 if Has_Pragma_Preelab_Init (Ent)
9577 and then Warn_On_Redundant_Constructs
9579 Error_Pragma ("?duplicate pragma%!");
9581 Set_Has_Pragma_Preelab_Init (Ent);
9585 --------------------
9586 -- Persistent_BSS --
9587 --------------------
9589 when Pragma_Persistent_BSS => Persistent_BSS : declare
9596 Check_At_Most_N_Arguments (1);
9598 -- Case of application to specific object (one argument)
9600 if Arg_Count = 1 then
9601 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9603 if not Is_Entity_Name (Expression (Arg1))
9605 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9606 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9608 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9611 Ent := Entity (Expression (Arg1));
9612 Decl := Parent (Ent);
9614 if Rep_Item_Too_Late (Ent, N) then
9618 if Present (Expression (Decl)) then
9620 ("object for pragma% cannot have initialization", Arg1);
9623 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9625 ("object type for pragma% is not potentially persistent",
9630 Make_Linker_Section_Pragma
9631 (Ent, Sloc (N), ".persistent.bss");
9632 Insert_After (N, Prag);
9635 -- Case of use as configuration pragma with no arguments
9638 Check_Valid_Configuration_Pragma;
9639 Persistent_BSS_Mode := True;
9647 -- pragma Polling (ON | OFF);
9649 when Pragma_Polling =>
9651 Check_Arg_Count (1);
9652 Check_No_Identifiers;
9653 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9654 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9660 -- pragma Postcondition ([Check =>] Boolean_Expression
9661 -- [,[Message =>] String_Expression]);
9663 when Pragma_Postcondition => Postcondition : declare
9665 pragma Warnings (Off, In_Body);
9669 Check_At_Least_N_Arguments (1);
9670 Check_At_Most_N_Arguments (2);
9671 Check_Optional_Identifier (Arg1, Name_Check);
9673 -- All we need to do here is call the common check procedure,
9674 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9676 Check_Precondition_Postcondition (In_Body);
9683 -- pragma Precondition ([Check =>] Boolean_Expression
9684 -- [,[Message =>] String_Expression]);
9686 when Pragma_Precondition => Precondition : declare
9691 Check_At_Least_N_Arguments (1);
9692 Check_At_Most_N_Arguments (2);
9693 Check_Optional_Identifier (Arg1, Name_Check);
9695 Check_Precondition_Postcondition (In_Body);
9697 -- If in spec, nothing more to do. If in body, then we convert the
9698 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
9699 -- this whether or not precondition checks are enabled. That works
9700 -- fine since pragma Check will do this check, and will also
9701 -- analyze the condition itself in the proper context.
9704 if Arg_Count = 2 then
9705 Check_Optional_Identifier (Arg3, Name_Message);
9706 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9711 Chars => Name_Check,
9712 Pragma_Argument_Associations => New_List (
9713 Make_Pragma_Argument_Association (Loc,
9715 Make_Identifier (Loc,
9716 Chars => Name_Precondition)),
9718 Make_Pragma_Argument_Association (Sloc (Arg1),
9719 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9721 if Arg_Count = 2 then
9722 Append_To (Pragma_Argument_Associations (N),
9723 Make_Pragma_Argument_Association (Sloc (Arg2),
9724 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9735 -- pragma Preelaborate [(library_unit_NAME)];
9737 -- Set the flag Is_Preelaborated of program unit name entity
9739 when Pragma_Preelaborate => Preelaborate : declare
9740 Pa : constant Node_Id := Parent (N);
9741 Pk : constant Node_Kind := Nkind (Pa);
9745 Check_Ada_83_Warning;
9746 Check_Valid_Library_Unit_Pragma;
9748 if Nkind (N) = N_Null_Statement then
9752 Ent := Find_Lib_Unit_Name;
9754 -- This filters out pragmas inside generic parent then
9755 -- show up inside instantiation
9758 and then not (Pk = N_Package_Specification
9759 and then Present (Generic_Parent (Pa)))
9761 if not Debug_Flag_U then
9762 Set_Is_Preelaborated (Ent);
9763 Set_Suppress_Elaboration_Warnings (Ent);
9768 ---------------------
9769 -- Preelaborate_05 --
9770 ---------------------
9772 -- pragma Preelaborate_05 [(library_unit_NAME)];
9774 -- This pragma is useable only in GNAT_Mode, where it is used like
9775 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9776 -- (otherwise it is ignored). This is used to implement AI-362 which
9777 -- recategorizes some run-time packages in Ada 2005 mode.
9779 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9784 Check_Valid_Library_Unit_Pragma;
9786 if not GNAT_Mode then
9787 Error_Pragma ("pragma% only available in GNAT mode");
9790 if Nkind (N) = N_Null_Statement then
9794 -- This is one of the few cases where we need to test the value of
9795 -- Ada_Version_Explicit rather than Ada_Version (which is always
9796 -- set to Ada_05 in a predefined unit), we need to know the
9797 -- explicit version set to know if this pragma is active.
9799 if Ada_Version_Explicit >= Ada_05 then
9800 Ent := Find_Lib_Unit_Name;
9801 Set_Is_Preelaborated (Ent);
9802 Set_Suppress_Elaboration_Warnings (Ent);
9804 end Preelaborate_05;
9810 -- pragma Priority (EXPRESSION);
9812 when Pragma_Priority => Priority : declare
9813 P : constant Node_Id := Parent (N);
9817 Check_No_Identifiers;
9818 Check_Arg_Count (1);
9822 if Nkind (P) = N_Subprogram_Body then
9823 Check_In_Main_Program;
9825 Arg := Expression (Arg1);
9826 Analyze_And_Resolve (Arg, Standard_Integer);
9830 if not Is_Static_Expression (Arg) then
9831 Flag_Non_Static_Expr
9832 ("main subprogram priority is not static!", Arg);
9835 -- If constraint error, then we already signalled an error
9837 elsif Raises_Constraint_Error (Arg) then
9840 -- Otherwise check in range
9844 Val : constant Uint := Expr_Value (Arg);
9848 or else Val > Expr_Value (Expression
9849 (Parent (RTE (RE_Max_Priority))))
9852 ("main subprogram priority is out of range", Arg1);
9858 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9860 -- Load an arbitrary entity from System.Tasking to make sure
9861 -- this package is implicitly with'ed, since we need to have
9862 -- the tasking run-time active for the pragma Priority to have
9866 Discard : Entity_Id;
9867 pragma Warnings (Off, Discard);
9869 Discard := RTE (RE_Task_List);
9872 -- Task or Protected, must be of type Integer
9874 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9875 Arg := Expression (Arg1);
9877 -- The expression must be analyzed in the special manner
9878 -- described in "Handling of Default and Per-Object
9879 -- Expressions" in sem.ads.
9881 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9883 if not Is_Static_Expression (Arg) then
9884 Check_Restriction (Static_Priorities, Arg);
9887 -- Anything else is incorrect
9893 if Has_Priority_Pragma (P) then
9894 Error_Pragma ("duplicate pragma% not allowed");
9896 Set_Has_Priority_Pragma (P, True);
9898 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9899 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9900 -- exp_ch9 should use this ???
9905 -----------------------------------
9906 -- Priority_Specific_Dispatching --
9907 -----------------------------------
9909 -- pragma Priority_Specific_Dispatching (
9910 -- policy_IDENTIFIER,
9911 -- first_priority_EXPRESSION,
9912 -- last_priority_EXPRESSION);
9914 when Pragma_Priority_Specific_Dispatching =>
9915 Priority_Specific_Dispatching : declare
9916 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9917 -- This is the entity System.Any_Priority;
9920 Lower_Bound : Node_Id;
9921 Upper_Bound : Node_Id;
9927 Check_Arg_Count (3);
9928 Check_No_Identifiers;
9929 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9930 Check_Valid_Configuration_Pragma;
9931 Get_Name_String (Chars (Expression (Arg1)));
9932 DP := Fold_Upper (Name_Buffer (1));
9934 Lower_Bound := Expression (Arg2);
9935 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9936 Lower_Val := Expr_Value (Lower_Bound);
9938 Upper_Bound := Expression (Arg3);
9939 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
9940 Upper_Val := Expr_Value (Upper_Bound);
9942 -- It is not allowed to use Task_Dispatching_Policy and
9943 -- Priority_Specific_Dispatching in the same partition.
9945 if Task_Dispatching_Policy /= ' ' then
9946 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9948 ("pragma% incompatible with Task_Dispatching_Policy#");
9950 -- Check lower bound in range
9952 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9954 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
9957 ("first_priority is out of range", Arg2);
9959 -- Check upper bound in range
9961 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9963 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
9966 ("last_priority is out of range", Arg3);
9968 -- Check that the priority range is valid
9970 elsif Lower_Val > Upper_Val then
9972 ("last_priority_expression must be greater than" &
9973 " or equal to first_priority_expression");
9975 -- Store the new policy, but always preserve System_Location since
9976 -- we like the error message with the run-time name.
9979 -- Check overlapping in the priority ranges specified in other
9980 -- Priority_Specific_Dispatching pragmas within the same
9981 -- partition. We can only check those we know about!
9984 Specific_Dispatching.First .. Specific_Dispatching.Last
9986 if Specific_Dispatching.Table (J).First_Priority in
9987 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9988 or else Specific_Dispatching.Table (J).Last_Priority in
9989 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9992 Specific_Dispatching.Table (J).Pragma_Loc;
9994 ("priority range overlaps with "
9995 & "Priority_Specific_Dispatching#");
9999 -- The use of Priority_Specific_Dispatching is incompatible
10000 -- with Task_Dispatching_Policy.
10002 if Task_Dispatching_Policy /= ' ' then
10003 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10005 ("Priority_Specific_Dispatching incompatible "
10006 & "with Task_Dispatching_Policy#");
10009 -- The use of Priority_Specific_Dispatching forces ceiling
10012 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10013 Error_Msg_Sloc := Locking_Policy_Sloc;
10015 ("Priority_Specific_Dispatching incompatible "
10016 & "with Locking_Policy#");
10018 -- Set the Ceiling_Locking policy, but preserve System_Location
10019 -- since we like the error message with the run time name.
10022 Locking_Policy := 'C';
10024 if Locking_Policy_Sloc /= System_Location then
10025 Locking_Policy_Sloc := Loc;
10029 -- Add entry in the table
10031 Specific_Dispatching.Append
10032 ((Dispatching_Policy => DP,
10033 First_Priority => UI_To_Int (Lower_Val),
10034 Last_Priority => UI_To_Int (Upper_Val),
10035 Pragma_Loc => Loc));
10037 end Priority_Specific_Dispatching;
10043 -- pragma Profile (profile_IDENTIFIER);
10045 -- profile_IDENTIFIER => Restricted | Ravenscar
10047 when Pragma_Profile =>
10049 Check_Arg_Count (1);
10050 Check_Valid_Configuration_Pragma;
10051 Check_No_Identifiers;
10054 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10056 if Chars (Argx) = Name_Ravenscar then
10057 Set_Ravenscar_Profile (N);
10058 elsif Chars (Argx) = Name_Restricted then
10059 Set_Profile_Restrictions
10060 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10062 Error_Pragma_Arg ("& is not a valid profile", Argx);
10066 ----------------------
10067 -- Profile_Warnings --
10068 ----------------------
10070 -- pragma Profile_Warnings (profile_IDENTIFIER);
10072 -- profile_IDENTIFIER => Restricted | Ravenscar
10074 when Pragma_Profile_Warnings =>
10076 Check_Arg_Count (1);
10077 Check_Valid_Configuration_Pragma;
10078 Check_No_Identifiers;
10081 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10083 if Chars (Argx) = Name_Ravenscar then
10084 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10085 elsif Chars (Argx) = Name_Restricted then
10086 Set_Profile_Restrictions (Restricted, N, Warn => True);
10088 Error_Pragma_Arg ("& is not a valid profile", Argx);
10092 --------------------------
10093 -- Propagate_Exceptions --
10094 --------------------------
10096 -- pragma Propagate_Exceptions;
10098 -- Note: this pragma is obsolete and has no effect
10100 when Pragma_Propagate_Exceptions =>
10102 Check_Arg_Count (0);
10104 if In_Extended_Main_Source_Unit (N) then
10105 Propagate_Exceptions := True;
10112 -- pragma Psect_Object (
10113 -- [Internal =>] LOCAL_NAME,
10114 -- [, [External =>] EXTERNAL_SYMBOL]
10115 -- [, [Size =>] EXTERNAL_SYMBOL]);
10117 when Pragma_Psect_Object | Pragma_Common_Object =>
10118 Psect_Object : declare
10119 Args : Args_List (1 .. 3);
10120 Names : constant Name_List (1 .. 3) := (
10125 Internal : Node_Id renames Args (1);
10126 External : Node_Id renames Args (2);
10127 Size : Node_Id renames Args (3);
10129 Def_Id : Entity_Id;
10131 procedure Check_Too_Long (Arg : Node_Id);
10132 -- Posts message if the argument is an identifier with more
10133 -- than 31 characters, or a string literal with more than
10134 -- 31 characters, and we are operating under VMS
10136 --------------------
10137 -- Check_Too_Long --
10138 --------------------
10140 procedure Check_Too_Long (Arg : Node_Id) is
10141 X : constant Node_Id := Original_Node (Arg);
10144 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10146 ("inappropriate argument for pragma %", Arg);
10149 if OpenVMS_On_Target then
10150 if (Nkind (X) = N_String_Literal
10151 and then String_Length (Strval (X)) > 31)
10153 (Nkind (X) = N_Identifier
10154 and then Length_Of_Name (Chars (X)) > 31)
10157 ("argument for pragma % is longer than 31 characters",
10161 end Check_Too_Long;
10163 -- Start of processing for Common_Object/Psect_Object
10167 Gather_Associations (Names, Args);
10168 Process_Extended_Import_Export_Internal_Arg (Internal);
10170 Def_Id := Entity (Internal);
10172 if Ekind (Def_Id) /= E_Constant
10173 and then Ekind (Def_Id) /= E_Variable
10176 ("pragma% must designate an object", Internal);
10179 Check_Too_Long (Internal);
10181 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10183 ("cannot use pragma% for imported/exported object",
10187 if Is_Concurrent_Type (Etype (Internal)) then
10189 ("cannot specify pragma % for task/protected object",
10193 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10195 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10197 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10200 if Ekind (Def_Id) = E_Constant then
10202 ("cannot specify pragma % for a constant", Internal);
10205 if Is_Record_Type (Etype (Internal)) then
10211 Ent := First_Entity (Etype (Internal));
10212 while Present (Ent) loop
10213 Decl := Declaration_Node (Ent);
10215 if Ekind (Ent) = E_Component
10216 and then Nkind (Decl) = N_Component_Declaration
10217 and then Present (Expression (Decl))
10218 and then Warn_On_Export_Import
10221 ("?object for pragma % has defaults", Internal);
10231 if Present (Size) then
10232 Check_Too_Long (Size);
10235 if Present (External) then
10236 Check_Arg_Is_External_Name (External);
10237 Check_Too_Long (External);
10240 -- If all error tests pass, link pragma on to the rep item chain
10242 Record_Rep_Item (Def_Id, N);
10249 -- pragma Pure [(library_unit_NAME)];
10251 when Pragma_Pure => Pure : declare
10255 Check_Ada_83_Warning;
10256 Check_Valid_Library_Unit_Pragma;
10258 if Nkind (N) = N_Null_Statement then
10262 Ent := Find_Lib_Unit_Name;
10264 Set_Has_Pragma_Pure (Ent);
10265 Set_Suppress_Elaboration_Warnings (Ent);
10272 -- pragma Pure_05 [(library_unit_NAME)];
10274 -- This pragma is useable only in GNAT_Mode, where it is used like
10275 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10276 -- it is ignored). It may be used after a pragma Preelaborate, in
10277 -- which case it overrides the effect of the pragma Preelaborate.
10278 -- This is used to implement AI-362 which recategorizes some run-time
10279 -- packages in Ada 2005 mode.
10281 when Pragma_Pure_05 => Pure_05 : declare
10286 Check_Valid_Library_Unit_Pragma;
10288 if not GNAT_Mode then
10289 Error_Pragma ("pragma% only available in GNAT mode");
10292 if Nkind (N) = N_Null_Statement then
10296 -- This is one of the few cases where we need to test the value of
10297 -- Ada_Version_Explicit rather than Ada_Version (which is always
10298 -- set to Ada_05 in a predefined unit), we need to know the
10299 -- explicit version set to know if this pragma is active.
10301 if Ada_Version_Explicit >= Ada_05 then
10302 Ent := Find_Lib_Unit_Name;
10303 Set_Is_Preelaborated (Ent, False);
10305 Set_Suppress_Elaboration_Warnings (Ent);
10309 -------------------
10310 -- Pure_Function --
10311 -------------------
10313 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10315 when Pragma_Pure_Function => Pure_Function : declare
10318 Def_Id : Entity_Id;
10319 Effective : Boolean := False;
10323 Check_Arg_Count (1);
10324 Check_Optional_Identifier (Arg1, Name_Entity);
10325 Check_Arg_Is_Local_Name (Arg1);
10326 E_Id := Expression (Arg1);
10328 if Error_Posted (E_Id) then
10332 -- Loop through homonyms (overloadings) of referenced entity
10334 E := Entity (E_Id);
10336 if Present (E) then
10338 Def_Id := Get_Base_Subprogram (E);
10340 if Ekind (Def_Id) /= E_Function
10341 and then Ekind (Def_Id) /= E_Generic_Function
10342 and then Ekind (Def_Id) /= E_Operator
10345 ("pragma% requires a function name", Arg1);
10348 Set_Is_Pure (Def_Id);
10350 if not Has_Pragma_Pure_Function (Def_Id) then
10351 Set_Has_Pragma_Pure_Function (Def_Id);
10356 exit when No (E) or else Scope (E) /= Current_Scope;
10360 and then Warn_On_Redundant_Constructs
10362 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10368 --------------------
10369 -- Queuing_Policy --
10370 --------------------
10372 -- pragma Queuing_Policy (policy_IDENTIFIER);
10374 when Pragma_Queuing_Policy => declare
10378 Check_Ada_83_Warning;
10379 Check_Arg_Count (1);
10380 Check_No_Identifiers;
10381 Check_Arg_Is_Queuing_Policy (Arg1);
10382 Check_Valid_Configuration_Pragma;
10383 Get_Name_String (Chars (Expression (Arg1)));
10384 QP := Fold_Upper (Name_Buffer (1));
10386 if Queuing_Policy /= ' '
10387 and then Queuing_Policy /= QP
10389 Error_Msg_Sloc := Queuing_Policy_Sloc;
10390 Error_Pragma ("queuing policy incompatible with policy#");
10392 -- Set new policy, but always preserve System_Location since we
10393 -- like the error message with the run time name.
10396 Queuing_Policy := QP;
10398 if Queuing_Policy_Sloc /= System_Location then
10399 Queuing_Policy_Sloc := Loc;
10404 -----------------------
10405 -- Relative_Deadline --
10406 -----------------------
10408 -- pragma Relative_Deadline (time_span_EXPRESSION);
10410 when Pragma_Relative_Deadline => Relative_Deadline : declare
10411 P : constant Node_Id := Parent (N);
10416 Check_No_Identifiers;
10417 Check_Arg_Count (1);
10419 Arg := Expression (Arg1);
10421 -- The expression must be analyzed in the special manner described
10422 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10424 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10428 if Nkind (P) = N_Subprogram_Body then
10429 Check_In_Main_Program;
10433 elsif Nkind (P) = N_Task_Definition then
10436 -- Anything else is incorrect
10442 if Has_Relative_Deadline_Pragma (P) then
10443 Error_Pragma ("duplicate pragma% not allowed");
10445 Set_Has_Relative_Deadline_Pragma (P, True);
10447 if Nkind (P) = N_Task_Definition then
10448 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10451 end Relative_Deadline;
10453 ---------------------------
10454 -- Remote_Call_Interface --
10455 ---------------------------
10457 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10459 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10460 Cunit_Node : Node_Id;
10461 Cunit_Ent : Entity_Id;
10465 Check_Ada_83_Warning;
10466 Check_Valid_Library_Unit_Pragma;
10468 if Nkind (N) = N_Null_Statement then
10472 Cunit_Node := Cunit (Current_Sem_Unit);
10473 K := Nkind (Unit (Cunit_Node));
10474 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10476 if K = N_Package_Declaration
10477 or else K = N_Generic_Package_Declaration
10478 or else K = N_Subprogram_Declaration
10479 or else K = N_Generic_Subprogram_Declaration
10480 or else (K = N_Subprogram_Body
10481 and then Acts_As_Spec (Unit (Cunit_Node)))
10486 "pragma% must apply to package or subprogram declaration");
10489 Set_Is_Remote_Call_Interface (Cunit_Ent);
10490 end Remote_Call_Interface;
10496 -- pragma Remote_Types [(library_unit_NAME)];
10498 when Pragma_Remote_Types => Remote_Types : declare
10499 Cunit_Node : Node_Id;
10500 Cunit_Ent : Entity_Id;
10503 Check_Ada_83_Warning;
10504 Check_Valid_Library_Unit_Pragma;
10506 if Nkind (N) = N_Null_Statement then
10510 Cunit_Node := Cunit (Current_Sem_Unit);
10511 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10513 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10514 N_Generic_Package_Declaration)
10517 ("pragma% can only apply to a package declaration");
10520 Set_Is_Remote_Types (Cunit_Ent);
10527 -- pragma Ravenscar;
10529 when Pragma_Ravenscar =>
10531 Check_Arg_Count (0);
10532 Check_Valid_Configuration_Pragma;
10533 Set_Ravenscar_Profile (N);
10535 if Warn_On_Obsolescent_Feature then
10537 ("pragma Ravenscar is an obsolescent feature?", N);
10539 ("|use pragma Profile (Ravenscar) instead", N);
10542 -------------------------
10543 -- Restricted_Run_Time --
10544 -------------------------
10546 -- pragma Restricted_Run_Time;
10548 when Pragma_Restricted_Run_Time =>
10550 Check_Arg_Count (0);
10551 Check_Valid_Configuration_Pragma;
10552 Set_Profile_Restrictions
10553 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10555 if Warn_On_Obsolescent_Feature then
10557 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10559 ("|use pragma Profile (Restricted) instead", N);
10566 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10569 -- restriction_IDENTIFIER
10570 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10572 when Pragma_Restrictions =>
10573 Process_Restrictions_Or_Restriction_Warnings
10574 (Warn => Treat_Restrictions_As_Warnings);
10576 --------------------------
10577 -- Restriction_Warnings --
10578 --------------------------
10580 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10583 -- restriction_IDENTIFIER
10584 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10586 when Pragma_Restriction_Warnings =>
10588 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10594 -- pragma Reviewable;
10596 when Pragma_Reviewable =>
10597 Check_Ada_83_Warning;
10598 Check_Arg_Count (0);
10601 -------------------
10602 -- Share_Generic --
10603 -------------------
10605 -- pragma Share_Generic (NAME {, NAME});
10607 when Pragma_Share_Generic =>
10609 Process_Generic_List;
10615 -- pragma Shared (LOCAL_NAME);
10617 when Pragma_Shared =>
10619 Process_Atomic_Shared_Volatile;
10621 --------------------
10622 -- Shared_Passive --
10623 --------------------
10625 -- pragma Shared_Passive [(library_unit_NAME)];
10627 -- Set the flag Is_Shared_Passive of program unit name entity
10629 when Pragma_Shared_Passive => Shared_Passive : declare
10630 Cunit_Node : Node_Id;
10631 Cunit_Ent : Entity_Id;
10634 Check_Ada_83_Warning;
10635 Check_Valid_Library_Unit_Pragma;
10637 if Nkind (N) = N_Null_Statement then
10641 Cunit_Node := Cunit (Current_Sem_Unit);
10642 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10644 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10645 N_Generic_Package_Declaration)
10648 ("pragma% can only apply to a package declaration");
10651 Set_Is_Shared_Passive (Cunit_Ent);
10652 end Shared_Passive;
10654 ----------------------
10655 -- Source_File_Name --
10656 ----------------------
10658 -- There are five forms for this pragma:
10660 -- pragma Source_File_Name (
10661 -- [UNIT_NAME =>] unit_NAME,
10662 -- BODY_FILE_NAME => STRING_LITERAL
10663 -- [, [INDEX =>] INTEGER_LITERAL]);
10665 -- pragma Source_File_Name (
10666 -- [UNIT_NAME =>] unit_NAME,
10667 -- SPEC_FILE_NAME => STRING_LITERAL
10668 -- [, [INDEX =>] INTEGER_LITERAL]);
10670 -- pragma Source_File_Name (
10671 -- BODY_FILE_NAME => STRING_LITERAL
10672 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10673 -- [, CASING => CASING_SPEC]);
10675 -- pragma Source_File_Name (
10676 -- SPEC_FILE_NAME => STRING_LITERAL
10677 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10678 -- [, CASING => CASING_SPEC]);
10680 -- pragma Source_File_Name (
10681 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10682 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10683 -- [, CASING => CASING_SPEC]);
10685 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10687 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10688 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
10689 -- only be used when no project file is used, while SFNP can only be
10690 -- used when a project file is used.
10692 -- No processing here. Processing was completed during parsing, since
10693 -- we need to have file names set as early as possible. Units are
10694 -- loaded well before semantic processing starts.
10696 -- The only processing we defer to this point is the check for
10697 -- correct placement.
10699 when Pragma_Source_File_Name =>
10701 Check_Valid_Configuration_Pragma;
10703 ------------------------------
10704 -- Source_File_Name_Project --
10705 ------------------------------
10707 -- See Source_File_Name for syntax
10709 -- No processing here. Processing was completed during parsing, since
10710 -- we need to have file names set as early as possible. Units are
10711 -- loaded well before semantic processing starts.
10713 -- The only processing we defer to this point is the check for
10714 -- correct placement.
10716 when Pragma_Source_File_Name_Project =>
10718 Check_Valid_Configuration_Pragma;
10720 -- Check that a pragma Source_File_Name_Project is used only in a
10721 -- configuration pragmas file.
10723 -- Pragmas Source_File_Name_Project should only be generated by
10724 -- the Project Manager in configuration pragmas files.
10726 -- This is really an ugly test. It seems to depend on some
10727 -- accidental and undocumented property. At the very least it
10728 -- needs to be documented, but it would be better to have a
10729 -- clean way of testing if we are in a configuration file???
10731 if Present (Parent (N)) then
10733 ("pragma% can only appear in a configuration pragmas file");
10736 ----------------------
10737 -- Source_Reference --
10738 ----------------------
10740 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10742 -- Nothing to do, all processing completed in Par.Prag, since we need
10743 -- the information for possible parser messages that are output.
10745 when Pragma_Source_Reference =>
10748 --------------------------------
10749 -- Static_Elaboration_Desired --
10750 --------------------------------
10752 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10754 when Pragma_Static_Elaboration_Desired =>
10756 Check_At_Most_N_Arguments (1);
10758 if Is_Compilation_Unit (Current_Scope)
10759 and then Ekind (Current_Scope) = E_Package
10761 Set_Static_Elaboration_Desired (Current_Scope, True);
10763 Error_Pragma ("pragma% must apply to a library-level package");
10770 -- pragma Storage_Size (EXPRESSION);
10772 when Pragma_Storage_Size => Storage_Size : declare
10773 P : constant Node_Id := Parent (N);
10777 Check_No_Identifiers;
10778 Check_Arg_Count (1);
10780 -- The expression must be analyzed in the special manner described
10781 -- in "Handling of Default Expressions" in sem.ads.
10783 Arg := Expression (Arg1);
10784 Preanalyze_Spec_Expression (Arg, Any_Integer);
10786 if not Is_Static_Expression (Arg) then
10787 Check_Restriction (Static_Storage_Size, Arg);
10790 if Nkind (P) /= N_Task_Definition then
10795 if Has_Storage_Size_Pragma (P) then
10796 Error_Pragma ("duplicate pragma% not allowed");
10798 Set_Has_Storage_Size_Pragma (P, True);
10801 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10802 -- ??? exp_ch9 should use this!
10810 -- pragma Storage_Unit (NUMERIC_LITERAL);
10812 -- Only permitted argument is System'Storage_Unit value
10814 when Pragma_Storage_Unit =>
10815 Check_No_Identifiers;
10816 Check_Arg_Count (1);
10817 Check_Arg_Is_Integer_Literal (Arg1);
10819 if Intval (Expression (Arg1)) /=
10820 UI_From_Int (Ttypes.System_Storage_Unit)
10822 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10824 ("the only allowed argument for pragma% is ^", Arg1);
10827 --------------------
10828 -- Stream_Convert --
10829 --------------------
10831 -- pragma Stream_Convert (
10832 -- [Entity =>] type_LOCAL_NAME,
10833 -- [Read =>] function_NAME,
10834 -- [Write =>] function NAME);
10836 when Pragma_Stream_Convert => Stream_Convert : declare
10838 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10839 -- Check that the given argument is the name of a local function
10840 -- of one argument that is not overloaded earlier in the current
10841 -- local scope. A check is also made that the argument is a
10842 -- function with one parameter.
10844 --------------------------------------
10845 -- Check_OK_Stream_Convert_Function --
10846 --------------------------------------
10848 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10852 Check_Arg_Is_Local_Name (Arg);
10853 Ent := Entity (Expression (Arg));
10855 if Has_Homonym (Ent) then
10857 ("argument for pragma% may not be overloaded", Arg);
10860 if Ekind (Ent) /= E_Function
10861 or else No (First_Formal (Ent))
10862 or else Present (Next_Formal (First_Formal (Ent)))
10865 ("argument for pragma% must be" &
10866 " function of one argument", Arg);
10868 end Check_OK_Stream_Convert_Function;
10870 -- Start of processing for Stream_Convert
10874 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10875 Check_Arg_Count (3);
10876 Check_Optional_Identifier (Arg1, Name_Entity);
10877 Check_Optional_Identifier (Arg2, Name_Read);
10878 Check_Optional_Identifier (Arg3, Name_Write);
10879 Check_Arg_Is_Local_Name (Arg1);
10880 Check_OK_Stream_Convert_Function (Arg2);
10881 Check_OK_Stream_Convert_Function (Arg3);
10884 Typ : constant Entity_Id :=
10885 Underlying_Type (Entity (Expression (Arg1)));
10886 Read : constant Entity_Id := Entity (Expression (Arg2));
10887 Write : constant Entity_Id := Entity (Expression (Arg3));
10890 Check_First_Subtype (Arg1);
10892 -- Check for too early or too late. Note that we don't enforce
10893 -- the rule about primitive operations in this case, since, as
10894 -- is the case for explicit stream attributes themselves, these
10895 -- restrictions are not appropriate. Note that the chaining of
10896 -- the pragma by Rep_Item_Too_Late is actually the critical
10897 -- processing done for this pragma.
10899 if Rep_Item_Too_Early (Typ, N)
10901 Rep_Item_Too_Late (Typ, N, FOnly => True)
10906 -- Return if previous error
10908 if Etype (Typ) = Any_Type
10910 Etype (Read) = Any_Type
10912 Etype (Write) = Any_Type
10919 if Underlying_Type (Etype (Read)) /= Typ then
10921 ("incorrect return type for function&", Arg2);
10924 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
10926 ("incorrect parameter type for function&", Arg3);
10929 if Underlying_Type (Etype (First_Formal (Read))) /=
10930 Underlying_Type (Etype (Write))
10933 ("result type of & does not match Read parameter type",
10937 end Stream_Convert;
10939 -------------------------
10940 -- Style_Checks (GNAT) --
10941 -------------------------
10943 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10945 -- This is processed by the parser since some of the style checks
10946 -- take place during source scanning and parsing. This means that
10947 -- we don't need to issue error messages here.
10949 when Pragma_Style_Checks => Style_Checks : declare
10950 A : constant Node_Id := Expression (Arg1);
10956 Check_No_Identifiers;
10958 -- Two argument form
10960 if Arg_Count = 2 then
10961 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10968 E_Id := Expression (Arg2);
10971 if not Is_Entity_Name (E_Id) then
10973 ("second argument of pragma% must be entity name",
10977 E := Entity (E_Id);
10983 Set_Suppress_Style_Checks (E,
10984 (Chars (Expression (Arg1)) = Name_Off));
10985 exit when No (Homonym (E));
10991 -- One argument form
10994 Check_Arg_Count (1);
10996 if Nkind (A) = N_String_Literal then
11000 Slen : constant Natural := Natural (String_Length (S));
11001 Options : String (1 .. Slen);
11007 C := Get_String_Char (S, Int (J));
11008 exit when not In_Character_Range (C);
11009 Options (J) := Get_Character (C);
11011 -- If at end of string, set options. As per discussion
11012 -- above, no need to check for errors, since we issued
11013 -- them in the parser.
11016 Set_Style_Check_Options (Options);
11024 elsif Nkind (A) = N_Identifier then
11025 if Chars (A) = Name_All_Checks then
11026 Set_Default_Style_Check_Options;
11028 elsif Chars (A) = Name_On then
11029 Style_Check := True;
11031 elsif Chars (A) = Name_Off then
11032 Style_Check := False;
11042 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11044 when Pragma_Subtitle =>
11046 Check_Arg_Count (1);
11047 Check_Optional_Identifier (Arg1, Name_Subtitle);
11048 Check_Arg_Is_String_Literal (Arg1);
11054 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11056 when Pragma_Suppress =>
11057 Process_Suppress_Unsuppress (True);
11063 -- pragma Suppress_All;
11065 -- The only check made here is that the pragma appears in the proper
11066 -- place, i.e. following a compilation unit. If indeed it appears in
11067 -- this context, then the parser has already inserted an equivalent
11068 -- pragma Suppress (All_Checks) to get the required effect.
11070 when Pragma_Suppress_All =>
11072 Check_Arg_Count (0);
11074 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11075 or else not Is_List_Member (N)
11076 or else List_Containing (N) /= Pragmas_After (Parent (N))
11079 ("misplaced pragma%, must follow compilation unit");
11082 -------------------------
11083 -- Suppress_Debug_Info --
11084 -------------------------
11086 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11088 when Pragma_Suppress_Debug_Info =>
11090 Check_Arg_Count (1);
11091 Check_Optional_Identifier (Arg1, Name_Entity);
11092 Check_Arg_Is_Local_Name (Arg1);
11093 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11095 ----------------------------------
11096 -- Suppress_Exception_Locations --
11097 ----------------------------------
11099 -- pragma Suppress_Exception_Locations;
11101 when Pragma_Suppress_Exception_Locations =>
11103 Check_Arg_Count (0);
11104 Check_Valid_Configuration_Pragma;
11105 Exception_Locations_Suppressed := True;
11107 -----------------------------
11108 -- Suppress_Initialization --
11109 -----------------------------
11111 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11113 when Pragma_Suppress_Initialization => Suppress_Init : declare
11119 Check_Arg_Count (1);
11120 Check_Optional_Identifier (Arg1, Name_Entity);
11121 Check_Arg_Is_Local_Name (Arg1);
11123 E_Id := Expression (Arg1);
11125 if Etype (E_Id) = Any_Type then
11129 E := Entity (E_Id);
11131 if Is_Type (E) then
11132 if Is_Incomplete_Or_Private_Type (E) then
11133 if No (Full_View (Base_Type (E))) then
11135 ("argument of pragma% cannot be an incomplete type",
11138 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11141 Set_Suppress_Init_Proc (Base_Type (E));
11146 ("pragma% requires argument that is a type name", Arg1);
11154 -- pragma System_Name (DIRECT_NAME);
11156 -- Syntax check: one argument, which must be the identifier GNAT or
11157 -- the identifier GCC, no other identifiers are acceptable.
11159 when Pragma_System_Name =>
11161 Check_No_Identifiers;
11162 Check_Arg_Count (1);
11163 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11165 -----------------------------
11166 -- Task_Dispatching_Policy --
11167 -----------------------------
11169 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11171 when Pragma_Task_Dispatching_Policy => declare
11175 Check_Ada_83_Warning;
11176 Check_Arg_Count (1);
11177 Check_No_Identifiers;
11178 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11179 Check_Valid_Configuration_Pragma;
11180 Get_Name_String (Chars (Expression (Arg1)));
11181 DP := Fold_Upper (Name_Buffer (1));
11183 if Task_Dispatching_Policy /= ' '
11184 and then Task_Dispatching_Policy /= DP
11186 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11188 ("task dispatching policy incompatible with policy#");
11190 -- Set new policy, but always preserve System_Location since we
11191 -- like the error message with the run time name.
11194 Task_Dispatching_Policy := DP;
11196 if Task_Dispatching_Policy_Sloc /= System_Location then
11197 Task_Dispatching_Policy_Sloc := Loc;
11206 -- pragma Task_Info (EXPRESSION);
11208 when Pragma_Task_Info => Task_Info : declare
11209 P : constant Node_Id := Parent (N);
11214 if Nkind (P) /= N_Task_Definition then
11215 Error_Pragma ("pragma% must appear in task definition");
11218 Check_No_Identifiers;
11219 Check_Arg_Count (1);
11221 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11223 if Etype (Expression (Arg1)) = Any_Type then
11227 if Has_Task_Info_Pragma (P) then
11228 Error_Pragma ("duplicate pragma% not allowed");
11230 Set_Has_Task_Info_Pragma (P, True);
11238 -- pragma Task_Name (string_EXPRESSION);
11240 when Pragma_Task_Name => Task_Name : declare
11241 P : constant Node_Id := Parent (N);
11245 Check_No_Identifiers;
11246 Check_Arg_Count (1);
11248 Arg := Expression (Arg1);
11250 -- The expression is used in the call to Create_Task, and must be
11251 -- expanded there, not in the context of the current spec.
11253 Preanalyze_And_Resolve (New_Copy_Tree (Arg), Standard_String);
11255 if Nkind (P) /= N_Task_Definition then
11259 if Has_Task_Name_Pragma (P) then
11260 Error_Pragma ("duplicate pragma% not allowed");
11262 Set_Has_Task_Name_Pragma (P, True);
11263 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11271 -- pragma Task_Storage (
11272 -- [Task_Type =>] LOCAL_NAME,
11273 -- [Top_Guard =>] static_integer_EXPRESSION);
11275 when Pragma_Task_Storage => Task_Storage : declare
11276 Args : Args_List (1 .. 2);
11277 Names : constant Name_List (1 .. 2) := (
11281 Task_Type : Node_Id renames Args (1);
11282 Top_Guard : Node_Id renames Args (2);
11288 Gather_Associations (Names, Args);
11290 if No (Task_Type) then
11292 ("missing task_type argument for pragma%");
11295 Check_Arg_Is_Local_Name (Task_Type);
11297 Ent := Entity (Task_Type);
11299 if not Is_Task_Type (Ent) then
11301 ("argument for pragma% must be task type", Task_Type);
11304 if No (Top_Guard) then
11306 ("pragma% takes two arguments", Task_Type);
11308 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11311 Check_First_Subtype (Task_Type);
11313 if Rep_Item_Too_Late (Ent, N) then
11318 --------------------------
11319 -- Thread_Local_Storage --
11320 --------------------------
11322 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11324 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11330 Check_Arg_Count (1);
11331 Check_Optional_Identifier (Arg1, Name_Entity);
11332 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11334 Id := Expression (Arg1);
11337 if not Is_Entity_Name (Id)
11338 or else Ekind (Entity (Id)) /= E_Variable
11340 Error_Pragma_Arg ("local variable name required", Arg1);
11345 if Rep_Item_Too_Early (E, N)
11346 or else Rep_Item_Too_Late (E, N)
11351 Set_Has_Pragma_Thread_Local_Storage (E);
11352 Set_Has_Gigi_Rep_Item (E);
11353 end Thread_Local_Storage;
11359 -- pragma Time_Slice (static_duration_EXPRESSION);
11361 when Pragma_Time_Slice => Time_Slice : declare
11367 Check_Arg_Count (1);
11368 Check_No_Identifiers;
11369 Check_In_Main_Program;
11370 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11372 if not Error_Posted (Arg1) then
11374 while Present (Nod) loop
11375 if Nkind (Nod) = N_Pragma
11376 and then Pragma_Name (Nod) = Name_Time_Slice
11378 Error_Msg_Name_1 := Pname;
11379 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11386 -- Process only if in main unit
11388 if Get_Source_Unit (Loc) = Main_Unit then
11389 Opt.Time_Slice_Set := True;
11390 Val := Expr_Value_R (Expression (Arg1));
11392 if Val <= Ureal_0 then
11393 Opt.Time_Slice_Value := 0;
11395 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11396 Opt.Time_Slice_Value := 1_000_000_000;
11399 Opt.Time_Slice_Value :=
11400 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11409 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11411 -- TITLING_OPTION ::=
11412 -- [Title =>] STRING_LITERAL
11413 -- | [Subtitle =>] STRING_LITERAL
11415 when Pragma_Title => Title : declare
11416 Args : Args_List (1 .. 2);
11417 Names : constant Name_List (1 .. 2) := (
11423 Gather_Associations (Names, Args);
11425 for J in 1 .. 2 loop
11426 if Present (Args (J)) then
11427 Check_Arg_Is_String_Literal (Args (J));
11432 ---------------------
11433 -- Unchecked_Union --
11434 ---------------------
11436 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11438 when Pragma_Unchecked_Union => Unchecked_Union : declare
11439 Assoc : constant Node_Id := Arg1;
11440 Type_Id : constant Node_Id := Expression (Assoc);
11451 Check_No_Identifiers;
11452 Check_Arg_Count (1);
11453 Check_Arg_Is_Local_Name (Arg1);
11455 Find_Type (Type_Id);
11456 Typ := Entity (Type_Id);
11459 or else Rep_Item_Too_Early (Typ, N)
11463 Typ := Underlying_Type (Typ);
11466 if Rep_Item_Too_Late (Typ, N) then
11470 Check_First_Subtype (Arg1);
11472 -- Note remaining cases are references to a type in the current
11473 -- declarative part. If we find an error, we post the error on
11474 -- the relevant type declaration at an appropriate point.
11476 if not Is_Record_Type (Typ) then
11477 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11480 elsif Is_Tagged_Type (Typ) then
11481 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11484 elsif Is_Limited_Type (Typ) then
11486 ("Unchecked_Union must not be limited record type", Typ);
11487 Explain_Limited_Type (Typ, Typ);
11491 if not Has_Discriminants (Typ) then
11493 ("Unchecked_Union must have one discriminant", Typ);
11497 Discr := First_Discriminant (Typ);
11498 while Present (Discr) loop
11499 if No (Discriminant_Default_Value (Discr)) then
11501 ("Unchecked_Union discriminant must have default value",
11504 Next_Discriminant (Discr);
11507 Tdef := Type_Definition (Declaration_Node (Typ));
11508 Clist := Component_List (Tdef);
11510 Comp := First (Component_Items (Clist));
11511 while Present (Comp) loop
11512 Check_Component (Comp);
11516 if No (Clist) or else No (Variant_Part (Clist)) then
11518 ("Unchecked_Union must have variant part",
11523 Vpart := Variant_Part (Clist);
11525 Variant := First (Variants (Vpart));
11526 while Present (Variant) loop
11527 Check_Variant (Variant);
11532 Set_Is_Unchecked_Union (Typ, True);
11533 Set_Convention (Typ, Convention_C);
11535 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11536 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11537 end Unchecked_Union;
11539 ------------------------
11540 -- Unimplemented_Unit --
11541 ------------------------
11543 -- pragma Unimplemented_Unit;
11545 -- Note: this only gives an error if we are generating code, or if
11546 -- we are in a generic library unit (where the pragma appears in the
11547 -- body, not in the spec).
11549 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11550 Cunitent : constant Entity_Id :=
11551 Cunit_Entity (Get_Source_Unit (Loc));
11552 Ent_Kind : constant Entity_Kind :=
11557 Check_Arg_Count (0);
11559 if Operating_Mode = Generate_Code
11560 or else Ent_Kind = E_Generic_Function
11561 or else Ent_Kind = E_Generic_Procedure
11562 or else Ent_Kind = E_Generic_Package
11564 Get_Name_String (Chars (Cunitent));
11565 Set_Casing (Mixed_Case);
11566 Write_Str (Name_Buffer (1 .. Name_Len));
11567 Write_Str (" is not supported in this configuration");
11569 raise Unrecoverable_Error;
11571 end Unimplemented_Unit;
11573 ------------------------
11574 -- Universal_Aliasing --
11575 ------------------------
11577 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11579 when Pragma_Universal_Aliasing => Universal_Alias : declare
11584 Check_Arg_Count (1);
11585 Check_Optional_Identifier (Arg2, Name_Entity);
11586 Check_Arg_Is_Local_Name (Arg1);
11587 E_Id := Entity (Expression (Arg1));
11589 if E_Id = Any_Type then
11591 elsif No (E_Id) or else not Is_Type (E_Id) then
11592 Error_Pragma_Arg ("pragma% requires type", Arg1);
11595 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11596 end Universal_Alias;
11598 --------------------
11599 -- Universal_Data --
11600 --------------------
11602 -- pragma Universal_Data [(library_unit_NAME)];
11604 when Pragma_Universal_Data =>
11607 -- If this is a configuration pragma, then set the universal
11608 -- addressing option, otherwise confirm that the pragma satisfies
11609 -- the requirements of library unit pragma placement and leave it
11610 -- to the GNAAMP back end to detect the pragma (avoids transitive
11611 -- setting of the option due to withed units).
11613 if Is_Configuration_Pragma then
11614 Universal_Addressing_On_AAMP := True;
11616 Check_Valid_Library_Unit_Pragma;
11619 if not AAMP_On_Target then
11620 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11627 -- pragma Unmodified (local_Name {, local_Name});
11629 when Pragma_Unmodified => Unmodified : declare
11630 Arg_Node : Node_Id;
11631 Arg_Expr : Node_Id;
11632 Arg_Ent : Entity_Id;
11636 Check_At_Least_N_Arguments (1);
11638 -- Loop through arguments
11641 while Present (Arg_Node) loop
11642 Check_No_Identifier (Arg_Node);
11644 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11645 -- in fact generate reference, so that the entity will have a
11646 -- reference, which will inhibit any warnings about it not
11647 -- being referenced, and also properly show up in the ali file
11648 -- as a reference. But this reference is recorded before the
11649 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11650 -- generated for this reference.
11652 Check_Arg_Is_Local_Name (Arg_Node);
11653 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11655 if Is_Entity_Name (Arg_Expr) then
11656 Arg_Ent := Entity (Arg_Expr);
11658 if not Is_Assignable (Arg_Ent) then
11660 ("pragma% can only be applied to a variable",
11663 Set_Has_Pragma_Unmodified (Arg_Ent);
11675 -- pragma Unreferenced (local_Name {, local_Name});
11677 -- or when used in a context clause:
11679 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11681 when Pragma_Unreferenced => Unreferenced : declare
11682 Arg_Node : Node_Id;
11683 Arg_Expr : Node_Id;
11684 Arg_Ent : Entity_Id;
11689 Check_At_Least_N_Arguments (1);
11691 -- Check case of appearing within context clause
11693 if Is_In_Context_Clause then
11695 -- The arguments must all be units mentioned in a with clause
11696 -- in the same context clause. Note we already checked (in
11697 -- Par.Prag) that the arguments are either identifiers or
11698 -- selected components.
11701 while Present (Arg_Node) loop
11702 Citem := First (List_Containing (N));
11703 while Citem /= N loop
11704 if Nkind (Citem) = N_With_Clause
11705 and then Same_Name (Name (Citem), Expression (Arg_Node))
11707 Set_Has_Pragma_Unreferenced
11710 (Library_Unit (Citem))));
11711 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11720 ("argument of pragma% is not with'ed unit", Arg_Node);
11726 -- Case of not in list of context items
11730 while Present (Arg_Node) loop
11731 Check_No_Identifier (Arg_Node);
11733 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11734 -- will in fact generate reference, so that the entity will
11735 -- have a reference, which will inhibit any warnings about
11736 -- it not being referenced, and also properly show up in the
11737 -- ali file as a reference. But this reference is recorded
11738 -- before the Has_Pragma_Unreferenced flag is set, so that
11739 -- no warning is generated for this reference.
11741 Check_Arg_Is_Local_Name (Arg_Node);
11742 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11744 if Is_Entity_Name (Arg_Expr) then
11745 Arg_Ent := Entity (Arg_Expr);
11747 -- If the entity is overloaded, the pragma applies to the
11748 -- most recent overloading, as documented. In this case,
11749 -- name resolution does not generate a reference, so it
11750 -- must be done here explicitly.
11752 if Is_Overloaded (Arg_Expr) then
11753 Generate_Reference (Arg_Ent, N);
11756 Set_Has_Pragma_Unreferenced (Arg_Ent);
11764 --------------------------
11765 -- Unreferenced_Objects --
11766 --------------------------
11768 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11770 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11771 Arg_Node : Node_Id;
11772 Arg_Expr : Node_Id;
11776 Check_At_Least_N_Arguments (1);
11779 while Present (Arg_Node) loop
11780 Check_No_Identifier (Arg_Node);
11781 Check_Arg_Is_Local_Name (Arg_Node);
11782 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11784 if not Is_Entity_Name (Arg_Expr)
11785 or else not Is_Type (Entity (Arg_Expr))
11788 ("argument for pragma% must be type or subtype", Arg_Node);
11791 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11794 end Unreferenced_Objects;
11796 ------------------------------
11797 -- Unreserve_All_Interrupts --
11798 ------------------------------
11800 -- pragma Unreserve_All_Interrupts;
11802 when Pragma_Unreserve_All_Interrupts =>
11804 Check_Arg_Count (0);
11806 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11807 Unreserve_All_Interrupts := True;
11814 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11816 when Pragma_Unsuppress =>
11818 Process_Suppress_Unsuppress (False);
11820 -------------------
11821 -- Use_VADS_Size --
11822 -------------------
11824 -- pragma Use_VADS_Size;
11826 when Pragma_Use_VADS_Size =>
11828 Check_Arg_Count (0);
11829 Check_Valid_Configuration_Pragma;
11830 Use_VADS_Size := True;
11832 ---------------------
11833 -- Validity_Checks --
11834 ---------------------
11836 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11838 when Pragma_Validity_Checks => Validity_Checks : declare
11839 A : constant Node_Id := Expression (Arg1);
11845 Check_Arg_Count (1);
11846 Check_No_Identifiers;
11848 if Nkind (A) = N_String_Literal then
11852 Slen : constant Natural := Natural (String_Length (S));
11853 Options : String (1 .. Slen);
11859 C := Get_String_Char (S, Int (J));
11860 exit when not In_Character_Range (C);
11861 Options (J) := Get_Character (C);
11864 Set_Validity_Check_Options (Options);
11872 elsif Nkind (A) = N_Identifier then
11874 if Chars (A) = Name_All_Checks then
11875 Set_Validity_Check_Options ("a");
11877 elsif Chars (A) = Name_On then
11878 Validity_Checks_On := True;
11880 elsif Chars (A) = Name_Off then
11881 Validity_Checks_On := False;
11885 end Validity_Checks;
11891 -- pragma Volatile (LOCAL_NAME);
11893 when Pragma_Volatile =>
11894 Process_Atomic_Shared_Volatile;
11896 -------------------------
11897 -- Volatile_Components --
11898 -------------------------
11900 -- pragma Volatile_Components (array_LOCAL_NAME);
11902 -- Volatile is handled by the same circuit as Atomic_Components
11908 -- pragma Warnings (On | Off);
11909 -- pragma Warnings (On | Off, LOCAL_NAME);
11910 -- pragma Warnings (static_string_EXPRESSION);
11911 -- pragma Warnings (On | Off, STRING_LITERAL);
11913 when Pragma_Warnings => Warnings : begin
11915 Check_At_Least_N_Arguments (1);
11916 Check_No_Identifiers;
11919 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11922 -- One argument case
11924 if Arg_Count = 1 then
11926 -- On/Off one argument case was processed by parser
11928 if Nkind (Argx) = N_Identifier
11930 (Chars (Argx) = Name_On
11932 Chars (Argx) = Name_Off)
11936 -- One argument case must be ON/OFF or static string expr
11938 elsif not Is_Static_String_Expression (Arg1) then
11940 ("argument of pragma% must be On/Off or " &
11941 "static string expression", Arg2);
11943 -- One argument string expression case
11947 Lit : constant Node_Id := Expr_Value_S (Argx);
11948 Str : constant String_Id := Strval (Lit);
11949 Len : constant Nat := String_Length (Str);
11957 while J <= Len loop
11958 C := Get_String_Char (Str, J);
11959 OK := In_Character_Range (C);
11962 Chr := Get_Character (C);
11966 if J < Len and then Chr = '.' then
11968 C := Get_String_Char (Str, J);
11969 Chr := Get_Character (C);
11971 if not Set_Dot_Warning_Switch (Chr) then
11973 ("invalid warning switch character " &
11980 OK := Set_Warning_Switch (Chr);
11986 ("invalid warning switch character " & Chr,
11995 -- Two or more arguments (must be two)
11998 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11999 Check_At_Most_N_Arguments (2);
12007 E_Id := Expression (Arg2);
12010 -- In the expansion of an inlined body, a reference to
12011 -- the formal may be wrapped in a conversion if the
12012 -- actual is a conversion. Retrieve the real entity name.
12014 if (In_Instance_Body
12015 or else In_Inlined_Body)
12016 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12018 E_Id := Expression (E_Id);
12021 -- Entity name case
12023 if Is_Entity_Name (E_Id) then
12024 E := Entity (E_Id);
12031 (E, (Chars (Expression (Arg1)) = Name_Off));
12033 if Chars (Expression (Arg1)) = Name_Off
12034 and then Warn_On_Warnings_Off
12036 Warnings_Off_Pragmas.Append ((N, E));
12039 if Is_Enumeration_Type (E) then
12043 Lit := First_Literal (E);
12044 while Present (Lit) loop
12045 Set_Warnings_Off (Lit);
12046 Next_Literal (Lit);
12051 exit when No (Homonym (E));
12056 -- Error if not entity or static string literal case
12058 elsif not Is_Static_String_Expression (Arg2) then
12060 ("second argument of pragma% must be entity " &
12061 "name or static string expression", Arg2);
12063 -- String literal case
12066 String_To_Name_Buffer
12067 (Strval (Expr_Value_S (Expression (Arg2))));
12069 -- Note on configuration pragma case: If this is a
12070 -- configuration pragma, then for an OFF pragma, we
12071 -- just set Config True in the call, which is all
12072 -- that needs to be done. For the case of ON, this
12073 -- is normally an error, unless it is canceling the
12074 -- effect of a previous OFF pragma in the same file.
12075 -- In any other case, an error will be signalled (ON
12076 -- with no matching OFF).
12078 if Chars (Argx) = Name_Off then
12079 Set_Specific_Warning_Off
12080 (Loc, Name_Buffer (1 .. Name_Len),
12081 Config => Is_Configuration_Pragma);
12083 elsif Chars (Argx) = Name_On then
12084 Set_Specific_Warning_On
12085 (Loc, Name_Buffer (1 .. Name_Len), Err);
12089 ("?pragma Warnings On with no " &
12090 "matching Warnings Off",
12100 -------------------
12101 -- Weak_External --
12102 -------------------
12104 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12106 when Pragma_Weak_External => Weak_External : declare
12111 Check_Arg_Count (1);
12112 Check_Optional_Identifier (Arg1, Name_Entity);
12113 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12114 Ent := Entity (Expression (Arg1));
12116 if Rep_Item_Too_Early (Ent, N) then
12119 Ent := Underlying_Type (Ent);
12122 -- The only processing required is to link this item on to the
12123 -- list of rep items for the given entity. This is accomplished
12124 -- by the call to Rep_Item_Too_Late (when no error is detected
12125 -- and False is returned).
12127 if Rep_Item_Too_Late (Ent, N) then
12130 Set_Has_Gigi_Rep_Item (Ent);
12134 -----------------------------
12135 -- Wide_Character_Encoding --
12136 -----------------------------
12138 -- pragma Wide_Character_Encoding (IDENTIFIER);
12140 when Pragma_Wide_Character_Encoding =>
12143 -- Nothing to do, handled in parser. Note that we do not enforce
12144 -- configuration pragma placement, this pragma can appear at any
12145 -- place in the source, allowing mixed encodings within a single
12150 --------------------
12151 -- Unknown_Pragma --
12152 --------------------
12154 -- Should be impossible, since the case of an unknown pragma is
12155 -- separately processed before the case statement is entered.
12157 when Unknown_Pragma =>
12158 raise Program_Error;
12162 when Pragma_Exit => null;
12163 end Analyze_Pragma;
12165 -------------------
12166 -- Check_Enabled --
12167 -------------------
12169 function Check_Enabled (Nam : Name_Id) return Boolean is
12173 PP := Opt.Check_Policy_List;
12176 return Assertions_Enabled;
12179 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12182 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12184 when Name_On | Name_Check =>
12186 when Name_Off | Name_Ignore =>
12189 raise Program_Error;
12193 PP := Next_Pragma (PP);
12198 ---------------------------------
12199 -- Delay_Config_Pragma_Analyze --
12200 ---------------------------------
12202 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12204 return Pragma_Name (N) = Name_Interrupt_State
12206 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12207 end Delay_Config_Pragma_Analyze;
12209 -------------------------
12210 -- Get_Base_Subprogram --
12211 -------------------------
12213 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12214 Result : Entity_Id;
12217 -- Follow subprogram renaming chain
12220 while Is_Subprogram (Result)
12222 (Is_Generic_Instance (Result)
12223 or else Nkind (Parent (Declaration_Node (Result))) =
12224 N_Subprogram_Renaming_Declaration)
12225 and then Present (Alias (Result))
12227 Result := Alias (Result);
12231 end Get_Base_Subprogram;
12233 --------------------
12234 -- Get_Pragma_Arg --
12235 --------------------
12237 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12239 if Nkind (Arg) = N_Pragma_Argument_Association then
12240 return Expression (Arg);
12244 end Get_Pragma_Arg;
12250 procedure Initialize is
12255 -----------------------------
12256 -- Is_Config_Static_String --
12257 -----------------------------
12259 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12261 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12262 -- This is an internal recursive function that is just like the outer
12263 -- function except that it adds the string to the name buffer rather
12264 -- than placing the string in the name buffer.
12266 ------------------------------
12267 -- Add_Config_Static_String --
12268 ------------------------------
12270 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12277 if Nkind (N) = N_Op_Concat then
12278 if Add_Config_Static_String (Left_Opnd (N)) then
12279 N := Right_Opnd (N);
12285 if Nkind (N) /= N_String_Literal then
12286 Error_Msg_N ("string literal expected for pragma argument", N);
12290 for J in 1 .. String_Length (Strval (N)) loop
12291 C := Get_String_Char (Strval (N), J);
12293 if not In_Character_Range (C) then
12295 ("string literal contains invalid wide character",
12296 Sloc (N) + 1 + Source_Ptr (J));
12300 Add_Char_To_Name_Buffer (Get_Character (C));
12305 end Add_Config_Static_String;
12307 -- Start of processing for Is_Config_Static_String
12312 return Add_Config_Static_String (Arg);
12313 end Is_Config_Static_String;
12315 -----------------------------------------
12316 -- Is_Non_Significant_Pragma_Reference --
12317 -----------------------------------------
12319 -- This function makes use of the following static table which indicates
12320 -- whether a given pragma is significant. A value of -1 in this table
12321 -- indicates that the reference is significant. A value of zero indicates
12322 -- than appearance as any argument is insignificant, a positive value
12323 -- indicates that appearance in that parameter position is significant.
12325 -- A value of 99 flags a special case requiring a special check (this is
12326 -- used for cases not covered by this standard encoding, e.g. pragma Check
12327 -- where the first argument is not significant, but the others are).
12329 Sig_Flags : constant array (Pragma_Id) of Int :=
12330 (Pragma_AST_Entry => -1,
12331 Pragma_Abort_Defer => -1,
12332 Pragma_Ada_83 => -1,
12333 Pragma_Ada_95 => -1,
12334 Pragma_Ada_05 => -1,
12335 Pragma_Ada_2005 => -1,
12336 Pragma_All_Calls_Remote => -1,
12337 Pragma_Annotate => -1,
12338 Pragma_Assert => -1,
12339 Pragma_Assertion_Policy => 0,
12340 Pragma_Assume_No_Invalid_Values => 0,
12341 Pragma_Asynchronous => -1,
12342 Pragma_Atomic => 0,
12343 Pragma_Atomic_Components => 0,
12344 Pragma_Attach_Handler => -1,
12345 Pragma_Check => 99,
12346 Pragma_Check_Name => 0,
12347 Pragma_Check_Policy => 0,
12348 Pragma_CIL_Constructor => -1,
12349 Pragma_CPP_Class => 0,
12350 Pragma_CPP_Constructor => 0,
12351 Pragma_CPP_Virtual => 0,
12352 Pragma_CPP_Vtable => 0,
12353 Pragma_C_Pass_By_Copy => 0,
12354 Pragma_Comment => 0,
12355 Pragma_Common_Object => -1,
12356 Pragma_Compile_Time_Error => -1,
12357 Pragma_Compile_Time_Warning => -1,
12358 Pragma_Compiler_Unit => 0,
12359 Pragma_Complete_Representation => 0,
12360 Pragma_Complex_Representation => 0,
12361 Pragma_Component_Alignment => -1,
12362 Pragma_Controlled => 0,
12363 Pragma_Convention => 0,
12364 Pragma_Convention_Identifier => 0,
12365 Pragma_Debug => -1,
12366 Pragma_Debug_Policy => 0,
12367 Pragma_Detect_Blocking => -1,
12368 Pragma_Discard_Names => 0,
12369 Pragma_Elaborate => -1,
12370 Pragma_Elaborate_All => -1,
12371 Pragma_Elaborate_Body => -1,
12372 Pragma_Elaboration_Checks => -1,
12373 Pragma_Eliminate => -1,
12374 Pragma_Export => -1,
12375 Pragma_Export_Exception => -1,
12376 Pragma_Export_Function => -1,
12377 Pragma_Export_Object => -1,
12378 Pragma_Export_Procedure => -1,
12379 Pragma_Export_Value => -1,
12380 Pragma_Export_Valued_Procedure => -1,
12381 Pragma_Extend_System => -1,
12382 Pragma_Extensions_Allowed => -1,
12383 Pragma_External => -1,
12384 Pragma_Favor_Top_Level => -1,
12385 Pragma_External_Name_Casing => -1,
12386 Pragma_Fast_Math => -1,
12387 Pragma_Finalize_Storage_Only => 0,
12388 Pragma_Float_Representation => 0,
12389 Pragma_Ident => -1,
12390 Pragma_Implemented_By_Entry => -1,
12391 Pragma_Implicit_Packing => 0,
12392 Pragma_Import => +2,
12393 Pragma_Import_Exception => 0,
12394 Pragma_Import_Function => 0,
12395 Pragma_Import_Object => 0,
12396 Pragma_Import_Procedure => 0,
12397 Pragma_Import_Valued_Procedure => 0,
12398 Pragma_Initialize_Scalars => -1,
12399 Pragma_Inline => 0,
12400 Pragma_Inline_Always => 0,
12401 Pragma_Inline_Generic => 0,
12402 Pragma_Inspection_Point => -1,
12403 Pragma_Interface => +2,
12404 Pragma_Interface_Name => +2,
12405 Pragma_Interrupt_Handler => -1,
12406 Pragma_Interrupt_Priority => -1,
12407 Pragma_Interrupt_State => -1,
12408 Pragma_Java_Constructor => -1,
12409 Pragma_Java_Interface => -1,
12410 Pragma_Keep_Names => 0,
12411 Pragma_License => -1,
12412 Pragma_Link_With => -1,
12413 Pragma_Linker_Alias => -1,
12414 Pragma_Linker_Constructor => -1,
12415 Pragma_Linker_Destructor => -1,
12416 Pragma_Linker_Options => -1,
12417 Pragma_Linker_Section => -1,
12419 Pragma_Locking_Policy => -1,
12420 Pragma_Long_Float => -1,
12421 Pragma_Machine_Attribute => -1,
12423 Pragma_Main_Storage => -1,
12424 Pragma_Memory_Size => -1,
12425 Pragma_No_Return => 0,
12426 Pragma_No_Body => 0,
12427 Pragma_No_Run_Time => -1,
12428 Pragma_No_Strict_Aliasing => -1,
12429 Pragma_Normalize_Scalars => -1,
12430 Pragma_Obsolescent => 0,
12431 Pragma_Optimize => -1,
12432 Pragma_Optimize_Alignment => -1,
12435 Pragma_Passive => -1,
12436 Pragma_Preelaborable_Initialization => -1,
12437 Pragma_Polling => -1,
12438 Pragma_Persistent_BSS => 0,
12439 Pragma_Postcondition => -1,
12440 Pragma_Precondition => -1,
12441 Pragma_Preelaborate => -1,
12442 Pragma_Preelaborate_05 => -1,
12443 Pragma_Priority => -1,
12444 Pragma_Priority_Specific_Dispatching => -1,
12445 Pragma_Profile => 0,
12446 Pragma_Profile_Warnings => 0,
12447 Pragma_Propagate_Exceptions => -1,
12448 Pragma_Psect_Object => -1,
12450 Pragma_Pure_05 => -1,
12451 Pragma_Pure_Function => -1,
12452 Pragma_Queuing_Policy => -1,
12453 Pragma_Ravenscar => -1,
12454 Pragma_Relative_Deadline => -1,
12455 Pragma_Remote_Call_Interface => -1,
12456 Pragma_Remote_Types => -1,
12457 Pragma_Restricted_Run_Time => -1,
12458 Pragma_Restriction_Warnings => -1,
12459 Pragma_Restrictions => -1,
12460 Pragma_Reviewable => -1,
12461 Pragma_Share_Generic => -1,
12462 Pragma_Shared => -1,
12463 Pragma_Shared_Passive => -1,
12464 Pragma_Source_File_Name => -1,
12465 Pragma_Source_File_Name_Project => -1,
12466 Pragma_Source_Reference => -1,
12467 Pragma_Storage_Size => -1,
12468 Pragma_Storage_Unit => -1,
12469 Pragma_Static_Elaboration_Desired => -1,
12470 Pragma_Stream_Convert => -1,
12471 Pragma_Style_Checks => -1,
12472 Pragma_Subtitle => -1,
12473 Pragma_Suppress => 0,
12474 Pragma_Suppress_Exception_Locations => 0,
12475 Pragma_Suppress_All => -1,
12476 Pragma_Suppress_Debug_Info => 0,
12477 Pragma_Suppress_Initialization => 0,
12478 Pragma_System_Name => -1,
12479 Pragma_Task_Dispatching_Policy => -1,
12480 Pragma_Task_Info => -1,
12481 Pragma_Task_Name => -1,
12482 Pragma_Task_Storage => 0,
12483 Pragma_Thread_Local_Storage => 0,
12484 Pragma_Time_Slice => -1,
12485 Pragma_Title => -1,
12486 Pragma_Unchecked_Union => 0,
12487 Pragma_Unimplemented_Unit => -1,
12488 Pragma_Universal_Aliasing => -1,
12489 Pragma_Universal_Data => -1,
12490 Pragma_Unmodified => -1,
12491 Pragma_Unreferenced => -1,
12492 Pragma_Unreferenced_Objects => -1,
12493 Pragma_Unreserve_All_Interrupts => -1,
12494 Pragma_Unsuppress => 0,
12495 Pragma_Use_VADS_Size => -1,
12496 Pragma_Validity_Checks => -1,
12497 Pragma_Volatile => 0,
12498 Pragma_Volatile_Components => 0,
12499 Pragma_Warnings => -1,
12500 Pragma_Weak_External => -1,
12501 Pragma_Wide_Character_Encoding => 0,
12502 Unknown_Pragma => 0);
12504 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12513 if Nkind (P) /= N_Pragma_Argument_Association then
12517 Id := Get_Pragma_Id (Parent (P));
12518 C := Sig_Flags (Id);
12530 -- For pragma Check, the first argument is not significant,
12531 -- the second and the third (if present) arguments are
12534 when Pragma_Check =>
12536 P = First (Pragma_Argument_Associations (Parent (P)));
12539 raise Program_Error;
12543 A := First (Pragma_Argument_Associations (Parent (P)));
12544 for J in 1 .. C - 1 loop
12552 return A = P; -- is this wrong way round ???
12555 end Is_Non_Significant_Pragma_Reference;
12557 ------------------------------
12558 -- Is_Pragma_String_Literal --
12559 ------------------------------
12561 -- This function returns true if the corresponding pragma argument is a
12562 -- static string expression. These are the only cases in which string
12563 -- literals can appear as pragma arguments. We also allow a string literal
12564 -- as the first argument to pragma Assert (although it will of course
12565 -- always generate a type error).
12567 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12568 Pragn : constant Node_Id := Parent (Par);
12569 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12570 Pname : constant Name_Id := Pragma_Name (Pragn);
12576 N := First (Assoc);
12583 if Pname = Name_Assert then
12586 elsif Pname = Name_Export then
12589 elsif Pname = Name_Ident then
12592 elsif Pname = Name_Import then
12595 elsif Pname = Name_Interface_Name then
12598 elsif Pname = Name_Linker_Alias then
12601 elsif Pname = Name_Linker_Section then
12604 elsif Pname = Name_Machine_Attribute then
12607 elsif Pname = Name_Source_File_Name then
12610 elsif Pname = Name_Source_Reference then
12613 elsif Pname = Name_Title then
12616 elsif Pname = Name_Subtitle then
12622 end Is_Pragma_String_Literal;
12624 --------------------------------------
12625 -- Process_Compilation_Unit_Pragmas --
12626 --------------------------------------
12628 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12630 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12631 -- strange because it comes at the end of the unit. If we have a pragma
12632 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12633 -- a pragma Suppress (All_Checks) at the start of the context clause to
12634 -- ensure the correct processing.
12637 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12641 if Present (PA) then
12643 while Present (P) loop
12644 if Pragma_Name (P) = Name_Suppress_All then
12645 Prepend_To (Context_Items (N),
12646 Make_Pragma (Sloc (P),
12647 Chars => Name_Suppress,
12648 Pragma_Argument_Associations => New_List (
12649 Make_Pragma_Argument_Association (Sloc (P),
12651 Make_Identifier (Sloc (P),
12652 Chars => Name_All_Checks)))));
12660 end Process_Compilation_Unit_Pragmas;
12671 --------------------------------
12672 -- Set_Encoded_Interface_Name --
12673 --------------------------------
12675 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12676 Str : constant String_Id := Strval (S);
12677 Len : constant Int := String_Length (Str);
12682 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12685 -- Stores encoded value of character code CC. The encoding we use an
12686 -- underscore followed by four lower case hex digits.
12692 procedure Encode is
12694 Store_String_Char (Get_Char_Code ('_'));
12696 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12698 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12700 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12702 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12705 -- Start of processing for Set_Encoded_Interface_Name
12708 -- If first character is asterisk, this is a link name, and we leave it
12709 -- completely unmodified. We also ignore null strings (the latter case
12710 -- happens only in error cases) and no encoding should occur for Java or
12711 -- AAMP interface names.
12714 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12715 or else VM_Target /= No_VM
12716 or else AAMP_On_Target
12718 Set_Interface_Name (E, S);
12723 CC := Get_String_Char (Str, J);
12725 exit when not In_Character_Range (CC);
12727 C := Get_Character (CC);
12729 exit when C /= '_' and then C /= '$'
12730 and then C not in '0' .. '9'
12731 and then C not in 'a' .. 'z'
12732 and then C not in 'A' .. 'Z';
12735 Set_Interface_Name (E, S);
12743 -- Here we need to encode. The encoding we use as follows:
12744 -- three underscores + four hex digits (lower case)
12748 for J in 1 .. String_Length (Str) loop
12749 CC := Get_String_Char (Str, J);
12751 if not In_Character_Range (CC) then
12754 C := Get_Character (CC);
12756 if C = '_' or else C = '$'
12757 or else C in '0' .. '9'
12758 or else C in 'a' .. 'z'
12759 or else C in 'A' .. 'Z'
12761 Store_String_Char (CC);
12768 Set_Interface_Name (E,
12769 Make_String_Literal (Sloc (S),
12770 Strval => End_String));
12772 end Set_Encoded_Interface_Name;
12774 -------------------
12775 -- Set_Unit_Name --
12776 -------------------
12778 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12783 if Nkind (N) = N_Identifier
12784 and then Nkind (With_Item) = N_Identifier
12786 Set_Entity (N, Entity (With_Item));
12788 elsif Nkind (N) = N_Selected_Component then
12789 Change_Selected_Component_To_Expanded_Name (N);
12790 Set_Entity (N, Entity (With_Item));
12791 Set_Entity (Selector_Name (N), Entity (N));
12793 Pref := Prefix (N);
12794 Scop := Scope (Entity (N));
12795 while Nkind (Pref) = N_Selected_Component loop
12796 Change_Selected_Component_To_Expanded_Name (Pref);
12797 Set_Entity (Selector_Name (Pref), Scop);
12798 Set_Entity (Pref, Scop);
12799 Pref := Prefix (Pref);
12800 Scop := Scope (Scop);
12803 Set_Entity (Pref, Scop);