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
372 -- Check the specified argument Arg to make sure that it is a static
373 -- expression of the given type (i.e. it will be analyzed and resolved
374 -- using this type, which can be any valid argument to Resolve, e.g.
375 -- Any_Integer is OK). If not, given error and raise Pragma_Exit.
377 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
378 -- Check the specified argument Arg to make sure that it is a string
379 -- literal. If not give error and raise Pragma_Exit
381 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
382 -- Check the specified argument Arg to make sure that it is a valid task
383 -- dispatching policy name. If not give error and raise Pragma_Exit.
385 procedure Check_Arg_Order (Names : Name_List);
386 -- Checks for an instance of two arguments with identifiers for the
387 -- current pragma which are not in the sequence indicated by Names,
388 -- and if so, generates a fatal message about bad order of arguments.
390 procedure Check_At_Least_N_Arguments (N : Nat);
391 -- Check there are at least N arguments present
393 procedure Check_At_Most_N_Arguments (N : Nat);
394 -- Check there are no more than N arguments present
396 procedure Check_Component (Comp : Node_Id);
397 -- Examine Unchecked_Union component for correct use of per-object
398 -- constrained subtypes, and for restrictions on finalizable components.
400 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
401 -- Nam is an N_String_Literal node containing the external name set by
402 -- an Import or Export pragma (or extended Import or Export pragma).
403 -- This procedure checks for possible duplications if this is the export
404 -- case, and if found, issues an appropriate error message.
406 procedure Check_First_Subtype (Arg : Node_Id);
407 -- Checks that Arg, whose expression is an entity name referencing a
408 -- subtype, does not reference a type that is not a first subtype.
410 procedure Check_In_Main_Program;
411 -- Common checks for pragmas that appear within a main program
412 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
414 procedure Check_Interrupt_Or_Attach_Handler;
415 -- Common processing for first argument of pragma Interrupt_Handler or
416 -- pragma Attach_Handler.
418 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
419 -- Check that pragma appears in a declarative part, or in a package
420 -- specification, i.e. that it does not occur in a statement sequence
423 procedure Check_No_Identifier (Arg : Node_Id);
424 -- Checks that the given argument does not have an identifier. If
425 -- an identifier is present, then an error message is issued, and
426 -- Pragma_Exit is raised.
428 procedure Check_No_Identifiers;
429 -- Checks that none of the arguments to the pragma has an identifier.
430 -- If any argument has an identifier, then an error message is issued,
431 -- and Pragma_Exit is raised.
433 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
434 -- Checks if the given argument has an identifier, and if so, requires
435 -- it to match the given identifier name. If there is a non-matching
436 -- identifier, then an error message is given and Error_Pragmas raised.
438 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
439 -- Checks if the given argument has an identifier, and if so, requires
440 -- it to match the given identifier name. If there is a non-matching
441 -- identifier, then an error message is given and Error_Pragmas raised.
442 -- In this version of the procedure, the identifier name is given as
443 -- a string with lower case letters.
445 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
446 -- Called to process a precondition or postcondition pragma. There are
449 -- The pragma appears after a subprogram spec
451 -- If the corresponding check is not enabled, the pragma is analyzed
452 -- but otherwise ignored and control returns with In_Body set False.
454 -- If the check is enabled, then the first step is to analyze the
455 -- pragma, but this is skipped if the subprogram spec appears within
456 -- a package specification (because this is the case where we delay
457 -- analysis till the end of the spec). Then (whether or not it was
458 -- analyzed), the pragma is chained to the subprogram in question
459 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
460 -- caller with In_Body set False.
462 -- The pragma appears at the start of subprogram body declarations
464 -- In this case an immediate return to the caller is made with
465 -- In_Body set True, and the pragma is NOT analyzed.
467 -- In all other cases, an error message for bad placement is given
469 procedure Check_Static_Constraint (Constr : Node_Id);
470 -- Constr is a constraint from an N_Subtype_Indication node from a
471 -- component constraint in an Unchecked_Union type. This routine checks
472 -- that the constraint is static as required by the restrictions for
475 procedure Check_Valid_Configuration_Pragma;
476 -- Legality checks for placement of a configuration pragma
478 procedure Check_Valid_Library_Unit_Pragma;
479 -- Legality checks for library unit pragmas. A special case arises for
480 -- pragmas in generic instances that come from copies of the original
481 -- library unit pragmas in the generic templates. In the case of other
482 -- than library level instantiations these can appear in contexts which
483 -- would normally be invalid (they only apply to the original template
484 -- and to library level instantiations), and they are simply ignored,
485 -- which is implemented by rewriting them as null statements.
487 procedure Check_Variant (Variant : Node_Id);
488 -- Check Unchecked_Union variant for lack of nested variants and
489 -- presence of at least one component.
491 procedure Error_Pragma (Msg : String);
492 pragma No_Return (Error_Pragma);
493 -- Outputs error message for current pragma. The message contains a %
494 -- that will be replaced with the pragma name, and the flag is placed
495 -- on the pragma itself. Pragma_Exit is then raised.
497 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
498 pragma No_Return (Error_Pragma_Arg);
499 -- Outputs error message for current pragma. The message may contain
500 -- a % that will be replaced with the pragma name. The parameter Arg
501 -- may either be a pragma argument association, in which case the flag
502 -- is placed on the expression of this association, or an expression,
503 -- in which case the flag is placed directly on the expression. The
504 -- message is placed using Error_Msg_N, so the message may also contain
505 -- an & insertion character which will reference the given Arg value.
506 -- After placing the message, Pragma_Exit is raised.
508 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
509 pragma No_Return (Error_Pragma_Arg);
510 -- Similar to above form of Error_Pragma_Arg except that two messages
511 -- are provided, the second is a continuation comment starting with \.
513 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
514 pragma No_Return (Error_Pragma_Arg_Ident);
515 -- Outputs error message for current pragma. The message may contain
516 -- a % that will be replaced with the pragma name. The parameter Arg
517 -- must be a pragma argument association with a non-empty identifier
518 -- (i.e. its Chars field must be set), and the error message is placed
519 -- on the identifier. The message is placed using Error_Msg_N so
520 -- the message may also contain an & insertion character which will
521 -- reference the identifier. After placing the message, Pragma_Exit
524 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
525 pragma No_Return (Error_Pragma_Ref);
526 -- Outputs error message for current pragma. The message may contain
527 -- a % that will be replaced with the pragma name. The parameter Ref
528 -- must be an entity whose name can be referenced by & and sloc by #.
529 -- After placing the message, Pragma_Exit is raised.
531 function Find_Lib_Unit_Name return Entity_Id;
532 -- Used for a library unit pragma to find the entity to which the
533 -- library unit pragma applies, returns the entity found.
535 procedure Find_Program_Unit_Name (Id : Node_Id);
536 -- If the pragma is a compilation unit pragma, the id must denote the
537 -- compilation unit in the same compilation, and the pragma must appear
538 -- in the list of preceding or trailing pragmas. If it is a program
539 -- unit pragma that is not a compilation unit pragma, then the
540 -- identifier must be visible.
542 function Find_Unique_Parameterless_Procedure
544 Arg : Node_Id) return Entity_Id;
545 -- Used for a procedure pragma to find the unique parameterless
546 -- procedure identified by Name, returns it if it exists, otherwise
547 -- errors out and uses Arg as the pragma argument for the message.
549 procedure Gather_Associations
551 Args : out Args_List);
552 -- This procedure is used to gather the arguments for a pragma that
553 -- permits arbitrary ordering of parameters using the normal rules
554 -- for named and positional parameters. The Names argument is a list
555 -- of Name_Id values that corresponds to the allowed pragma argument
556 -- association identifiers in order. The result returned in Args is
557 -- a list of corresponding expressions that are the pragma arguments.
558 -- Note that this is a list of expressions, not of pragma argument
559 -- associations (Gather_Associations has completely checked all the
560 -- optional identifiers when it returns). An entry in Args is Empty
561 -- on return if the corresponding argument is not present.
563 procedure GNAT_Pragma;
564 -- Called for all GNAT defined pragmas to check the relevant restriction
565 -- (No_Implementation_Pragmas).
567 function Is_Before_First_Decl
568 (Pragma_Node : Node_Id;
569 Decls : List_Id) return Boolean;
570 -- Return True if Pragma_Node is before the first declarative item in
571 -- Decls where Decls is the list of declarative items.
573 function Is_Configuration_Pragma return Boolean;
574 -- Determines if the placement of the current pragma is appropriate
575 -- for a configuration pragma.
577 function Is_In_Context_Clause return Boolean;
578 -- Returns True if pragma appears within the context clause of a unit,
579 -- and False for any other placement (does not generate any messages).
581 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
582 -- Analyzes the argument, and determines if it is a static string
583 -- expression, returns True if so, False if non-static or not String.
585 procedure Pragma_Misplaced;
586 pragma No_Return (Pragma_Misplaced);
587 -- Issue fatal error message for misplaced pragma
589 procedure Process_Atomic_Shared_Volatile;
590 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
591 -- Shared is an obsolete Ada 83 pragma, treated as being identical
592 -- in effect to pragma Atomic.
594 procedure Process_Compile_Time_Warning_Or_Error;
595 -- Common processing for Compile_Time_Error and Compile_Time_Warning
597 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
598 -- Common processing for Convention, Interface, Import and Export.
599 -- Checks first two arguments of pragma, and sets the appropriate
600 -- convention value in the specified entity or entities. On return
601 -- C is the convention, E is the referenced entity.
603 procedure Process_Extended_Import_Export_Exception_Pragma
604 (Arg_Internal : Node_Id;
605 Arg_External : Node_Id;
608 -- Common processing for the pragmas Import/Export_Exception. The three
609 -- arguments correspond to the three named parameters of the pragma. An
610 -- argument is empty if the corresponding parameter is not present in
613 procedure Process_Extended_Import_Export_Object_Pragma
614 (Arg_Internal : Node_Id;
615 Arg_External : Node_Id;
617 -- Common processing for the pragmas Import/Export_Object. The three
618 -- arguments correspond to the three named parameters of the pragmas. An
619 -- argument is empty if the corresponding parameter is not present in
622 procedure Process_Extended_Import_Export_Internal_Arg
623 (Arg_Internal : Node_Id := Empty);
624 -- Common processing for all extended Import and Export pragmas. The
625 -- argument is the pragma parameter for the Internal argument. If
626 -- Arg_Internal is empty or inappropriate, an error message is posted.
627 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
628 -- set to identify the referenced entity.
630 procedure Process_Extended_Import_Export_Subprogram_Pragma
631 (Arg_Internal : Node_Id;
632 Arg_External : Node_Id;
633 Arg_Parameter_Types : Node_Id;
634 Arg_Result_Type : Node_Id := Empty;
635 Arg_Mechanism : Node_Id;
636 Arg_Result_Mechanism : Node_Id := Empty;
637 Arg_First_Optional_Parameter : Node_Id := Empty);
638 -- Common processing for all extended Import and Export pragmas applying
639 -- to subprograms. The caller omits any arguments that do not apply to
640 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
641 -- only in the Import_Function and Export_Function cases). The argument
642 -- names correspond to the allowed pragma association identifiers.
644 procedure Process_Generic_List;
645 -- Common processing for Share_Generic and Inline_Generic
647 procedure Process_Import_Or_Interface;
648 -- Common processing for Import of Interface
650 procedure Process_Inline (Active : Boolean);
651 -- Common processing for Inline and Inline_Always. The parameter
652 -- indicates if the inline pragma is active, i.e. if it should actually
653 -- cause inlining to occur.
655 procedure Process_Interface_Name
656 (Subprogram_Def : Entity_Id;
659 -- Given the last two arguments of pragma Import, pragma Export, or
660 -- pragma Interface_Name, performs validity checks and sets the
661 -- Interface_Name field of the given subprogram entity to the
662 -- appropriate external or link name, depending on the arguments given.
663 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
664 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
665 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
666 -- nor Link_Arg is present, the interface name is set to the default
667 -- from the subprogram name.
669 procedure Process_Interrupt_Or_Attach_Handler;
670 -- Common processing for Interrupt and Attach_Handler pragmas
672 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
673 -- Common processing for Restrictions and Restriction_Warnings pragmas.
674 -- Warn is True for Restriction_Warnings, or for Restrictions if the
675 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
676 -- is not set in the Restrictions case.
678 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
679 -- Common processing for Suppress and Unsuppress. The boolean parameter
680 -- Suppress_Case is True for the Suppress case, and False for the
683 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
684 -- This procedure sets the Is_Exported flag for the given entity,
685 -- checking that the entity was not previously imported. Arg is
686 -- the argument that specified the entity. A check is also made
687 -- for exporting inappropriate entities.
689 procedure Set_Extended_Import_Export_External_Name
690 (Internal_Ent : Entity_Id;
691 Arg_External : Node_Id);
692 -- Common processing for all extended import export pragmas. The first
693 -- argument, Internal_Ent, is the internal entity, which has already
694 -- been checked for validity by the caller. Arg_External is from the
695 -- Import or Export pragma, and may be null if no External parameter
696 -- was present. If Arg_External is present and is a non-null string
697 -- (a null string is treated as the default), then the Interface_Name
698 -- field of Internal_Ent is set appropriately.
700 procedure Set_Imported (E : Entity_Id);
701 -- This procedure sets the Is_Imported flag for the given entity,
702 -- checking that it is not previously exported or imported.
704 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
705 -- Mech is a parameter passing mechanism (see Import_Function syntax
706 -- for MECHANISM_NAME). This routine checks that the mechanism argument
707 -- has the right form, and if not issues an error message. If the
708 -- argument has the right form then the Mechanism field of Ent is
709 -- set appropriately.
711 procedure Set_Ravenscar_Profile (N : Node_Id);
712 -- Activate the set of configuration pragmas and restrictions that make
713 -- up the Ravenscar Profile. N is the corresponding pragma node, which
714 -- is used for error messages on any constructs that violate the
717 ---------------------
718 -- Ada_2005_Pragma --
719 ---------------------
721 procedure Ada_2005_Pragma is
723 if Ada_Version <= Ada_95 then
724 Check_Restriction (No_Implementation_Pragmas, N);
728 --------------------------
729 -- Check_Ada_83_Warning --
730 --------------------------
732 procedure Check_Ada_83_Warning is
734 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
735 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
737 end Check_Ada_83_Warning;
739 ---------------------
740 -- Check_Arg_Count --
741 ---------------------
743 procedure Check_Arg_Count (Required : Nat) is
745 if Arg_Count /= Required then
746 Error_Pragma ("wrong number of arguments for pragma%");
750 --------------------------------
751 -- Check_Arg_Is_External_Name --
752 --------------------------------
754 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
755 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
758 if Nkind (Argx) = N_Identifier then
762 Analyze_And_Resolve (Argx, Standard_String);
764 if Is_OK_Static_Expression (Argx) then
767 elsif Etype (Argx) = Any_Type then
770 -- An interesting special case, if we have a string literal and
771 -- we are in Ada 83 mode, then we allow it even though it will
772 -- not be flagged as static. This allows expected Ada 83 mode
773 -- use of external names which are string literals, even though
774 -- technically these are not static in Ada 83.
776 elsif Ada_Version = Ada_83
777 and then Nkind (Argx) = N_String_Literal
781 -- Static expression that raises Constraint_Error. This has
782 -- already been flagged, so just exit from pragma processing.
784 elsif Is_Static_Expression (Argx) then
787 -- Here we have a real error (non-static expression)
790 Error_Msg_Name_1 := Pname;
792 ("argument for pragma% must be a identifier or " &
793 "static string expression!", Argx);
797 end Check_Arg_Is_External_Name;
799 -----------------------------
800 -- Check_Arg_Is_Identifier --
801 -----------------------------
803 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
804 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
806 if Nkind (Argx) /= N_Identifier then
808 ("argument for pragma% must be identifier", Argx);
810 end Check_Arg_Is_Identifier;
812 ----------------------------------
813 -- Check_Arg_Is_Integer_Literal --
814 ----------------------------------
816 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
817 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
819 if Nkind (Argx) /= N_Integer_Literal then
821 ("argument for pragma% must be integer literal", Argx);
823 end Check_Arg_Is_Integer_Literal;
825 -------------------------------------------
826 -- Check_Arg_Is_Library_Level_Local_Name --
827 -------------------------------------------
831 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
832 -- | library_unit_NAME
834 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
836 Check_Arg_Is_Local_Name (Arg);
838 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
839 and then Comes_From_Source (N)
842 ("argument for pragma% must be library level entity", Arg);
844 end Check_Arg_Is_Library_Level_Local_Name;
846 -----------------------------
847 -- Check_Arg_Is_Local_Name --
848 -----------------------------
852 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
853 -- | library_unit_NAME
855 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
856 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
861 if Nkind (Argx) not in N_Direct_Name
862 and then (Nkind (Argx) /= N_Attribute_Reference
863 or else Present (Expressions (Argx))
864 or else Nkind (Prefix (Argx)) /= N_Identifier)
865 and then (not Is_Entity_Name (Argx)
866 or else not Is_Compilation_Unit (Entity (Argx)))
868 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
871 if Is_Entity_Name (Argx)
872 and then Scope (Entity (Argx)) /= Current_Scope
875 ("pragma% argument must be in same declarative part", Arg);
877 end Check_Arg_Is_Local_Name;
879 ---------------------------------
880 -- Check_Arg_Is_Locking_Policy --
881 ---------------------------------
883 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
884 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
887 Check_Arg_Is_Identifier (Argx);
889 if not Is_Locking_Policy_Name (Chars (Argx)) then
891 ("& is not a valid locking policy name", Argx);
893 end Check_Arg_Is_Locking_Policy;
895 -------------------------
896 -- Check_Arg_Is_One_Of --
897 -------------------------
899 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
900 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
903 Check_Arg_Is_Identifier (Argx);
905 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
906 Error_Msg_Name_2 := N1;
907 Error_Msg_Name_3 := N2;
908 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
910 end Check_Arg_Is_One_Of;
912 procedure Check_Arg_Is_One_Of
914 N1, N2, N3 : Name_Id)
916 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
919 Check_Arg_Is_Identifier (Argx);
921 if Chars (Argx) /= N1
922 and then Chars (Argx) /= N2
923 and then Chars (Argx) /= N3
925 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
927 end Check_Arg_Is_One_Of;
929 procedure Check_Arg_Is_One_Of
931 N1, N2, N3, N4 : Name_Id)
933 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
936 Check_Arg_Is_Identifier (Argx);
938 if Chars (Argx) /= N1
939 and then Chars (Argx) /= N2
940 and then Chars (Argx) /= N3
941 and then Chars (Argx) /= N4
943 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
945 end Check_Arg_Is_One_Of;
947 ---------------------------------
948 -- Check_Arg_Is_Queuing_Policy --
949 ---------------------------------
951 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
952 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
955 Check_Arg_Is_Identifier (Argx);
957 if not Is_Queuing_Policy_Name (Chars (Argx)) then
959 ("& is not a valid queuing policy name", Argx);
961 end Check_Arg_Is_Queuing_Policy;
963 ------------------------------------
964 -- Check_Arg_Is_Static_Expression --
965 ------------------------------------
967 procedure Check_Arg_Is_Static_Expression
971 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
974 Analyze_And_Resolve (Argx, Typ);
976 if Is_OK_Static_Expression (Argx) then
979 elsif Etype (Argx) = Any_Type then
982 -- An interesting special case, if we have a string literal and we
983 -- are in Ada 83 mode, then we allow it even though it will not be
984 -- flagged as static. This allows the use of Ada 95 pragmas like
985 -- Import in Ada 83 mode. They will of course be flagged with
986 -- warnings as usual, but will not cause errors.
988 elsif Ada_Version = Ada_83
989 and then Nkind (Argx) = N_String_Literal
993 -- Static expression that raises Constraint_Error. This has already
994 -- been flagged, so just exit from pragma processing.
996 elsif Is_Static_Expression (Argx) then
999 -- Finally, we have a real error
1002 Error_Msg_Name_1 := Pname;
1003 Flag_Non_Static_Expr
1004 ("argument for pragma% must be a static expression!", Argx);
1007 end Check_Arg_Is_Static_Expression;
1009 ---------------------------------
1010 -- Check_Arg_Is_String_Literal --
1011 ---------------------------------
1013 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1014 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1016 if Nkind (Argx) /= N_String_Literal then
1018 ("argument for pragma% must be string literal", Argx);
1020 end Check_Arg_Is_String_Literal;
1022 ------------------------------------------
1023 -- Check_Arg_Is_Task_Dispatching_Policy --
1024 ------------------------------------------
1026 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1027 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1030 Check_Arg_Is_Identifier (Argx);
1032 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1034 ("& is not a valid task dispatching policy name", Argx);
1036 end Check_Arg_Is_Task_Dispatching_Policy;
1038 ---------------------
1039 -- Check_Arg_Order --
1040 ---------------------
1042 procedure Check_Arg_Order (Names : Name_List) is
1045 Highest_So_Far : Natural := 0;
1046 -- Highest index in Names seen do far
1050 for J in 1 .. Arg_Count loop
1051 if Chars (Arg) /= No_Name then
1052 for K in Names'Range loop
1053 if Chars (Arg) = Names (K) then
1054 if K < Highest_So_Far then
1055 Error_Msg_Name_1 := Pname;
1057 ("parameters out of order for pragma%", Arg);
1058 Error_Msg_Name_1 := Names (K);
1059 Error_Msg_Name_2 := Names (Highest_So_Far);
1060 Error_Msg_N ("\% must appear before %", Arg);
1064 Highest_So_Far := K;
1072 end Check_Arg_Order;
1074 --------------------------------
1075 -- Check_At_Least_N_Arguments --
1076 --------------------------------
1078 procedure Check_At_Least_N_Arguments (N : Nat) is
1080 if Arg_Count < N then
1081 Error_Pragma ("too few arguments for pragma%");
1083 end Check_At_Least_N_Arguments;
1085 -------------------------------
1086 -- Check_At_Most_N_Arguments --
1087 -------------------------------
1089 procedure Check_At_Most_N_Arguments (N : Nat) is
1092 if Arg_Count > N then
1094 for J in 1 .. N loop
1096 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1099 end Check_At_Most_N_Arguments;
1101 ---------------------
1102 -- Check_Component --
1103 ---------------------
1105 procedure Check_Component (Comp : Node_Id) is
1107 if Nkind (Comp) = N_Component_Declaration then
1109 Sindic : constant Node_Id :=
1110 Subtype_Indication (Component_Definition (Comp));
1111 Typ : constant Entity_Id :=
1112 Etype (Defining_Identifier (Comp));
1114 if Nkind (Sindic) = N_Subtype_Indication then
1116 -- Ada 2005 (AI-216): If a component subtype is subject to
1117 -- a per-object constraint, then the component type shall
1118 -- be an Unchecked_Union.
1120 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1122 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1124 Error_Msg_N ("component subtype subject to per-object" &
1125 " constraint must be an Unchecked_Union", Comp);
1129 if Is_Controlled (Typ) then
1131 ("component of unchecked union cannot be controlled", Comp);
1133 elsif Has_Task (Typ) then
1135 ("component of unchecked union cannot have tasks", Comp);
1139 end Check_Component;
1141 ----------------------------------
1142 -- Check_Duplicated_Export_Name --
1143 ----------------------------------
1145 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1146 String_Val : constant String_Id := Strval (Nam);
1149 -- We are only interested in the export case, and in the case of
1150 -- generics, it is the instance, not the template, that is the
1151 -- problem (the template will generate a warning in any case).
1153 if not Inside_A_Generic
1154 and then (Prag_Id = Pragma_Export
1156 Prag_Id = Pragma_Export_Procedure
1158 Prag_Id = Pragma_Export_Valued_Procedure
1160 Prag_Id = Pragma_Export_Function)
1162 for J in Externals.First .. Externals.Last loop
1163 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1164 Error_Msg_Sloc := Sloc (Externals.Table (J));
1165 Error_Msg_N ("external name duplicates name given#", Nam);
1170 Externals.Append (Nam);
1172 end Check_Duplicated_Export_Name;
1174 -------------------------
1175 -- Check_First_Subtype --
1176 -------------------------
1178 procedure Check_First_Subtype (Arg : Node_Id) is
1179 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1181 if not Is_First_Subtype (Entity (Argx)) then
1183 ("pragma% cannot apply to subtype", Argx);
1185 end Check_First_Subtype;
1187 ---------------------------
1188 -- Check_In_Main_Program --
1189 ---------------------------
1191 procedure Check_In_Main_Program is
1192 P : constant Node_Id := Parent (N);
1195 -- Must be at in subprogram body
1197 if Nkind (P) /= N_Subprogram_Body then
1198 Error_Pragma ("% pragma allowed only in subprogram");
1200 -- Otherwise warn if obviously not main program
1202 elsif Present (Parameter_Specifications (Specification (P)))
1203 or else not Is_Compilation_Unit (Defining_Entity (P))
1205 Error_Msg_Name_1 := Pname;
1207 ("?pragma% is only effective in main program", N);
1209 end Check_In_Main_Program;
1211 ---------------------------------------
1212 -- Check_Interrupt_Or_Attach_Handler --
1213 ---------------------------------------
1215 procedure Check_Interrupt_Or_Attach_Handler is
1216 Arg1_X : constant Node_Id := Expression (Arg1);
1217 Handler_Proc, Proc_Scope : Entity_Id;
1222 if Prag_Id = Pragma_Interrupt_Handler then
1223 Check_Restriction (No_Dynamic_Attachment, N);
1226 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1227 Proc_Scope := Scope (Handler_Proc);
1229 -- On AAMP only, a pragma Interrupt_Handler is supported for
1230 -- nonprotected parameterless procedures.
1232 if not AAMP_On_Target
1233 or else Prag_Id = Pragma_Attach_Handler
1235 if Ekind (Proc_Scope) /= E_Protected_Type then
1237 ("argument of pragma% must be protected procedure", Arg1);
1240 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1241 Error_Pragma ("pragma% must be in protected definition");
1245 if not Is_Library_Level_Entity (Proc_Scope)
1246 or else (AAMP_On_Target
1247 and then not Is_Library_Level_Entity (Handler_Proc))
1250 ("argument for pragma% must be library level entity", Arg1);
1252 end Check_Interrupt_Or_Attach_Handler;
1254 -------------------------------------------
1255 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1256 -------------------------------------------
1258 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1267 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1270 elsif Nkind_In (P, N_Package_Specification,
1275 -- Note: the following tests seem a little peculiar, because
1276 -- they test for bodies, but if we were in the statement part
1277 -- of the body, we would already have hit the handled statement
1278 -- sequence, so the only way we get here is by being in the
1279 -- declarative part of the body.
1281 elsif Nkind_In (P, N_Subprogram_Body,
1292 Error_Pragma ("pragma% is not in declarative part or package spec");
1293 end Check_Is_In_Decl_Part_Or_Package_Spec;
1295 -------------------------
1296 -- Check_No_Identifier --
1297 -------------------------
1299 procedure Check_No_Identifier (Arg : Node_Id) is
1301 if Chars (Arg) /= No_Name then
1302 Error_Pragma_Arg_Ident
1303 ("pragma% does not permit identifier& here", Arg);
1305 end Check_No_Identifier;
1307 --------------------------
1308 -- Check_No_Identifiers --
1309 --------------------------
1311 procedure Check_No_Identifiers is
1314 if Arg_Count > 0 then
1316 while Present (Arg_Node) loop
1317 Check_No_Identifier (Arg_Node);
1321 end Check_No_Identifiers;
1323 -------------------------------
1324 -- Check_Optional_Identifier --
1325 -------------------------------
1327 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1329 if Present (Arg) and then Chars (Arg) /= No_Name then
1330 if Chars (Arg) /= Id then
1331 Error_Msg_Name_1 := Pname;
1332 Error_Msg_Name_2 := Id;
1333 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1337 end Check_Optional_Identifier;
1339 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1341 Name_Buffer (1 .. Id'Length) := Id;
1342 Name_Len := Id'Length;
1343 Check_Optional_Identifier (Arg, Name_Find);
1344 end Check_Optional_Identifier;
1346 --------------------------------------
1347 -- Check_Precondition_Postcondition --
1348 --------------------------------------
1350 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1354 procedure Chain_PPC (PO : Node_Id);
1355 -- If PO is a subprogram declaration node (or a generic subprogram
1356 -- declaration node), then the precondition/postcondition applies
1357 -- to this subprogram and the processing for the pragma is completed.
1358 -- Otherwise the pragma is misplaced.
1364 procedure Chain_PPC (PO : Node_Id) is
1368 if not Nkind_In (PO, N_Subprogram_Declaration,
1369 N_Generic_Subprogram_Declaration)
1374 -- Here if we have subprogram or generic subprogram declaration
1376 S := Defining_Unit_Name (Specification (PO));
1378 -- Analyze the pragma unless it appears within a package spec,
1379 -- which is the case where we delay the analysis of the PPC until
1380 -- the end of the package declarations (for details, see
1381 -- Analyze_Package_Specification.Analyze_PPCs).
1383 if not Is_Package_Or_Generic_Package (Scope (S)) then
1384 Analyze_PPC_In_Decl_Part (N, S);
1387 -- Chain spec PPC pragma to list for subprogram
1389 Set_Next_Pragma (N, Spec_PPC_List (S));
1390 Set_Spec_PPC_List (S, N);
1392 -- Return indicating spec case
1398 -- Start of processing for Check_Precondition_Postcondition
1401 if not Is_List_Member (N) then
1405 -- Record whether pragma is enabled
1407 Set_PPC_Enabled (N, Check_Enabled (Pname));
1409 -- If we are within an inlined body, the legality of the pragma
1410 -- has been checked already.
1412 if In_Inlined_Body then
1417 -- Search prior declarations
1420 while Present (Prev (P)) loop
1423 -- If the previous node is a generic subprogram, do not go to to
1424 -- the original node, which is the unanalyzed tree: we need to
1425 -- attach the pre/postconditions to the analyzed version at this
1426 -- point. They get propagated to the original tree when analyzing
1427 -- the corresponding body.
1429 if Nkind (P) not in N_Generic_Declaration then
1430 PO := Original_Node (P);
1435 -- Skip past prior pragma
1437 if Nkind (PO) = N_Pragma then
1440 -- Skip stuff not coming from source
1442 elsif not Comes_From_Source (PO) then
1445 -- Only remaining possibility is subprogram declaration
1453 -- If we fall through loop, pragma is at start of list, so see if it
1454 -- is at the start of declarations of a subprogram body.
1456 if Nkind (Parent (N)) = N_Subprogram_Body
1457 and then List_Containing (N) = Declarations (Parent (N))
1459 if Operating_Mode /= Generate_Code then
1461 -- Analyze expression in pragma, for correctness
1462 -- and for ASIS use.
1464 Preanalyze_Spec_Expression
1465 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1471 -- See if it is in the pragmas after a library level subprogram
1473 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1474 Chain_PPC (Unit (Parent (Parent (N))));
1478 -- If we fall through, pragma was misplaced
1481 end Check_Precondition_Postcondition;
1483 -----------------------------
1484 -- Check_Static_Constraint --
1485 -----------------------------
1487 -- Note: for convenience in writing this procedure, in addition to
1488 -- the officially (i.e. by spec) allowed argument which is always a
1489 -- constraint, it also allows ranges and discriminant associations.
1490 -- Above is not clear ???
1492 procedure Check_Static_Constraint (Constr : Node_Id) is
1494 procedure Require_Static (E : Node_Id);
1495 -- Require given expression to be static expression
1497 --------------------
1498 -- Require_Static --
1499 --------------------
1501 procedure Require_Static (E : Node_Id) is
1503 if not Is_OK_Static_Expression (E) then
1504 Flag_Non_Static_Expr
1505 ("non-static constraint not allowed in Unchecked_Union!", E);
1510 -- Start of processing for Check_Static_Constraint
1513 case Nkind (Constr) is
1514 when N_Discriminant_Association =>
1515 Require_Static (Expression (Constr));
1518 Require_Static (Low_Bound (Constr));
1519 Require_Static (High_Bound (Constr));
1521 when N_Attribute_Reference =>
1522 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1523 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1525 when N_Range_Constraint =>
1526 Check_Static_Constraint (Range_Expression (Constr));
1528 when N_Index_Or_Discriminant_Constraint =>
1532 IDC := First (Constraints (Constr));
1533 while Present (IDC) loop
1534 Check_Static_Constraint (IDC);
1542 end Check_Static_Constraint;
1544 --------------------------------------
1545 -- Check_Valid_Configuration_Pragma --
1546 --------------------------------------
1548 -- A configuration pragma must appear in the context clause of a
1549 -- compilation unit, and only other pragmas may precede it. Note that
1550 -- the test also allows use in a configuration pragma file.
1552 procedure Check_Valid_Configuration_Pragma is
1554 if not Is_Configuration_Pragma then
1555 Error_Pragma ("incorrect placement for configuration pragma%");
1557 end Check_Valid_Configuration_Pragma;
1559 -------------------------------------
1560 -- Check_Valid_Library_Unit_Pragma --
1561 -------------------------------------
1563 procedure Check_Valid_Library_Unit_Pragma is
1565 Parent_Node : Node_Id;
1566 Unit_Name : Entity_Id;
1567 Unit_Kind : Node_Kind;
1568 Unit_Node : Node_Id;
1569 Sindex : Source_File_Index;
1572 if not Is_List_Member (N) then
1576 Plist := List_Containing (N);
1577 Parent_Node := Parent (Plist);
1579 if Parent_Node = Empty then
1582 -- Case of pragma appearing after a compilation unit. In this case
1583 -- it must have an argument with the corresponding name and must
1584 -- be part of the following pragmas of its parent.
1586 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1587 if Plist /= Pragmas_After (Parent_Node) then
1590 elsif Arg_Count = 0 then
1592 ("argument required if outside compilation unit");
1595 Check_No_Identifiers;
1596 Check_Arg_Count (1);
1597 Unit_Node := Unit (Parent (Parent_Node));
1598 Unit_Kind := Nkind (Unit_Node);
1600 Analyze (Expression (Arg1));
1602 if Unit_Kind = N_Generic_Subprogram_Declaration
1603 or else Unit_Kind = N_Subprogram_Declaration
1605 Unit_Name := Defining_Entity (Unit_Node);
1607 elsif Unit_Kind in N_Generic_Instantiation then
1608 Unit_Name := Defining_Entity (Unit_Node);
1611 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1614 if Chars (Unit_Name) /=
1615 Chars (Entity (Expression (Arg1)))
1618 ("pragma% argument is not current unit name", Arg1);
1621 if Ekind (Unit_Name) = E_Package
1622 and then Present (Renamed_Entity (Unit_Name))
1624 Error_Pragma ("pragma% not allowed for renamed package");
1628 -- Pragma appears other than after a compilation unit
1631 -- Here we check for the generic instantiation case and also
1632 -- for the case of processing a generic formal package. We
1633 -- detect these cases by noting that the Sloc on the node
1634 -- does not belong to the current compilation unit.
1636 Sindex := Source_Index (Current_Sem_Unit);
1638 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1639 Rewrite (N, Make_Null_Statement (Loc));
1642 -- If before first declaration, the pragma applies to the
1643 -- enclosing unit, and the name if present must be this name.
1645 elsif Is_Before_First_Decl (N, Plist) then
1646 Unit_Node := Unit_Declaration_Node (Current_Scope);
1647 Unit_Kind := Nkind (Unit_Node);
1649 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1652 elsif Unit_Kind = N_Subprogram_Body
1653 and then not Acts_As_Spec (Unit_Node)
1657 elsif Nkind (Parent_Node) = N_Package_Body then
1660 elsif Nkind (Parent_Node) = N_Package_Specification
1661 and then Plist = Private_Declarations (Parent_Node)
1665 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1666 or else Nkind (Parent_Node) =
1667 N_Generic_Subprogram_Declaration)
1668 and then Plist = Generic_Formal_Declarations (Parent_Node)
1672 elsif Arg_Count > 0 then
1673 Analyze (Expression (Arg1));
1675 if Entity (Expression (Arg1)) /= Current_Scope then
1677 ("name in pragma% must be enclosing unit", Arg1);
1680 -- It is legal to have no argument in this context
1686 -- Error if not before first declaration. This is because a
1687 -- library unit pragma argument must be the name of a library
1688 -- unit (RM 10.1.5(7)), but the only names permitted in this
1689 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1690 -- generic subprogram declarations or generic instantiations.
1694 ("pragma% misplaced, must be before first declaration");
1698 end Check_Valid_Library_Unit_Pragma;
1704 procedure Check_Variant (Variant : Node_Id) is
1705 Clist : constant Node_Id := Component_List (Variant);
1709 if not Is_Non_Empty_List (Component_Items (Clist)) then
1711 ("Unchecked_Union may not have empty component list",
1716 Comp := First (Component_Items (Clist));
1717 while Present (Comp) loop
1718 Check_Component (Comp);
1727 procedure Error_Pragma (Msg : String) is
1729 Error_Msg_Name_1 := Pname;
1730 Error_Msg_N (Msg, N);
1734 ----------------------
1735 -- Error_Pragma_Arg --
1736 ----------------------
1738 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1740 Error_Msg_Name_1 := Pname;
1741 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1743 end Error_Pragma_Arg;
1745 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1747 Error_Msg_Name_1 := Pname;
1748 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1749 Error_Pragma_Arg (Msg2, Arg);
1750 end Error_Pragma_Arg;
1752 ----------------------------
1753 -- Error_Pragma_Arg_Ident --
1754 ----------------------------
1756 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1758 Error_Msg_Name_1 := Pname;
1759 Error_Msg_N (Msg, Arg);
1761 end Error_Pragma_Arg_Ident;
1763 ----------------------
1764 -- Error_Pragma_Ref --
1765 ----------------------
1767 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1769 Error_Msg_Name_1 := Pname;
1770 Error_Msg_Sloc := Sloc (Ref);
1771 Error_Msg_NE (Msg, N, Ref);
1773 end Error_Pragma_Ref;
1775 ------------------------
1776 -- Find_Lib_Unit_Name --
1777 ------------------------
1779 function Find_Lib_Unit_Name return Entity_Id is
1781 -- Return inner compilation unit entity, for case of nested
1782 -- categorization pragmas. This happens in generic unit.
1784 if Nkind (Parent (N)) = N_Package_Specification
1785 and then Defining_Entity (Parent (N)) /= Current_Scope
1787 return Defining_Entity (Parent (N));
1789 return Current_Scope;
1791 end Find_Lib_Unit_Name;
1793 ----------------------------
1794 -- Find_Program_Unit_Name --
1795 ----------------------------
1797 procedure Find_Program_Unit_Name (Id : Node_Id) is
1798 Unit_Name : Entity_Id;
1799 Unit_Kind : Node_Kind;
1800 P : constant Node_Id := Parent (N);
1803 if Nkind (P) = N_Compilation_Unit then
1804 Unit_Kind := Nkind (Unit (P));
1806 if Unit_Kind = N_Subprogram_Declaration
1807 or else Unit_Kind = N_Package_Declaration
1808 or else Unit_Kind in N_Generic_Declaration
1810 Unit_Name := Defining_Entity (Unit (P));
1812 if Chars (Id) = Chars (Unit_Name) then
1813 Set_Entity (Id, Unit_Name);
1814 Set_Etype (Id, Etype (Unit_Name));
1816 Set_Etype (Id, Any_Type);
1818 ("cannot find program unit referenced by pragma%");
1822 Set_Etype (Id, Any_Type);
1823 Error_Pragma ("pragma% inapplicable to this unit");
1829 end Find_Program_Unit_Name;
1831 -----------------------------------------
1832 -- Find_Unique_Parameterless_Procedure --
1833 -----------------------------------------
1835 function Find_Unique_Parameterless_Procedure
1837 Arg : Node_Id) return Entity_Id
1839 Proc : Entity_Id := Empty;
1842 -- The body of this procedure needs some comments ???
1844 if not Is_Entity_Name (Name) then
1846 ("argument of pragma% must be entity name", Arg);
1848 elsif not Is_Overloaded (Name) then
1849 Proc := Entity (Name);
1851 if Ekind (Proc) /= E_Procedure
1852 or else Present (First_Formal (Proc)) then
1854 ("argument of pragma% must be parameterless procedure", Arg);
1859 Found : Boolean := False;
1861 Index : Interp_Index;
1864 Get_First_Interp (Name, Index, It);
1865 while Present (It.Nam) loop
1868 if Ekind (Proc) = E_Procedure
1869 and then No (First_Formal (Proc))
1873 Set_Entity (Name, Proc);
1874 Set_Is_Overloaded (Name, False);
1877 ("ambiguous handler name for pragma% ", Arg);
1881 Get_Next_Interp (Index, It);
1886 ("argument of pragma% must be parameterless procedure",
1889 Proc := Entity (Name);
1895 end Find_Unique_Parameterless_Procedure;
1897 -------------------------
1898 -- Gather_Associations --
1899 -------------------------
1901 procedure Gather_Associations
1903 Args : out Args_List)
1908 -- Initialize all parameters to Empty
1910 for J in Args'Range loop
1914 -- That's all we have to do if there are no argument associations
1916 if No (Pragma_Argument_Associations (N)) then
1920 -- Otherwise first deal with any positional parameters present
1922 Arg := First (Pragma_Argument_Associations (N));
1923 for Index in Args'Range loop
1924 exit when No (Arg) or else Chars (Arg) /= No_Name;
1925 Args (Index) := Expression (Arg);
1929 -- Positional parameters all processed, if any left, then we
1930 -- have too many positional parameters.
1932 if Present (Arg) and then Chars (Arg) = No_Name then
1934 ("too many positional associations for pragma%", Arg);
1937 -- Process named parameters if any are present
1939 while Present (Arg) loop
1940 if Chars (Arg) = No_Name then
1942 ("positional association cannot follow named association",
1946 for Index in Names'Range loop
1947 if Names (Index) = Chars (Arg) then
1948 if Present (Args (Index)) then
1950 ("duplicate argument association for pragma%", Arg);
1952 Args (Index) := Expression (Arg);
1957 if Index = Names'Last then
1958 Error_Msg_Name_1 := Pname;
1959 Error_Msg_N ("pragma% does not allow & argument", Arg);
1961 -- Check for possible misspelling
1963 for Index1 in Names'Range loop
1964 if Is_Bad_Spelling_Of
1965 (Chars (Arg), Names (Index1))
1967 Error_Msg_Name_1 := Names (Index1);
1968 Error_Msg_N ("\possible misspelling of%", Arg);
1980 end Gather_Associations;
1986 procedure GNAT_Pragma is
1988 Check_Restriction (No_Implementation_Pragmas, N);
1991 --------------------------
1992 -- Is_Before_First_Decl --
1993 --------------------------
1995 function Is_Before_First_Decl
1996 (Pragma_Node : Node_Id;
1997 Decls : List_Id) return Boolean
1999 Item : Node_Id := First (Decls);
2002 -- Only other pragmas can come before this pragma
2005 if No (Item) or else Nkind (Item) /= N_Pragma then
2008 elsif Item = Pragma_Node then
2014 end Is_Before_First_Decl;
2016 -----------------------------
2017 -- Is_Configuration_Pragma --
2018 -----------------------------
2020 -- A configuration pragma must appear in the context clause of a
2021 -- compilation unit, and only other pragmas may precede it. Note that
2022 -- the test below also permits use in a configuration pragma file.
2024 function Is_Configuration_Pragma return Boolean is
2025 Lis : constant List_Id := List_Containing (N);
2026 Par : constant Node_Id := Parent (N);
2030 -- If no parent, then we are in the configuration pragma file,
2031 -- so the placement is definitely appropriate.
2036 -- Otherwise we must be in the context clause of a compilation unit
2037 -- and the only thing allowed before us in the context list is more
2038 -- configuration pragmas.
2040 elsif Nkind (Par) = N_Compilation_Unit
2041 and then Context_Items (Par) = Lis
2048 elsif Nkind (Prg) /= N_Pragma then
2058 end Is_Configuration_Pragma;
2060 --------------------------
2061 -- Is_In_Context_Clause --
2062 --------------------------
2064 function Is_In_Context_Clause return Boolean is
2066 Parent_Node : Node_Id;
2069 if not Is_List_Member (N) then
2073 Plist := List_Containing (N);
2074 Parent_Node := Parent (Plist);
2076 if Parent_Node = Empty
2077 or else Nkind (Parent_Node) /= N_Compilation_Unit
2078 or else Context_Items (Parent_Node) /= Plist
2085 end Is_In_Context_Clause;
2087 ---------------------------------
2088 -- Is_Static_String_Expression --
2089 ---------------------------------
2091 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2092 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2095 Analyze_And_Resolve (Argx);
2096 return Is_OK_Static_Expression (Argx)
2097 and then Nkind (Argx) = N_String_Literal;
2098 end Is_Static_String_Expression;
2100 ----------------------
2101 -- Pragma_Misplaced --
2102 ----------------------
2104 procedure Pragma_Misplaced is
2106 Error_Pragma ("incorrect placement of pragma%");
2107 end Pragma_Misplaced;
2109 ------------------------------------
2110 -- Process Atomic_Shared_Volatile --
2111 ------------------------------------
2113 procedure Process_Atomic_Shared_Volatile is
2120 procedure Set_Atomic (E : Entity_Id);
2121 -- Set given type as atomic, and if no explicit alignment was given,
2122 -- set alignment to unknown, since back end knows what the alignment
2123 -- requirements are for atomic arrays. Note: this step is necessary
2124 -- for derived types.
2130 procedure Set_Atomic (E : Entity_Id) is
2134 if not Has_Alignment_Clause (E) then
2135 Set_Alignment (E, Uint_0);
2139 -- Start of processing for Process_Atomic_Shared_Volatile
2142 Check_Ada_83_Warning;
2143 Check_No_Identifiers;
2144 Check_Arg_Count (1);
2145 Check_Arg_Is_Local_Name (Arg1);
2146 E_Id := Expression (Arg1);
2148 if Etype (E_Id) = Any_Type then
2153 D := Declaration_Node (E);
2157 if Rep_Item_Too_Early (E, N)
2159 Rep_Item_Too_Late (E, N)
2163 Check_First_Subtype (Arg1);
2166 if Prag_Id /= Pragma_Volatile then
2168 Set_Atomic (Underlying_Type (E));
2169 Set_Atomic (Base_Type (E));
2172 -- Attribute belongs on the base type. If the view of the type is
2173 -- currently private, it also belongs on the underlying type.
2175 Set_Is_Volatile (Base_Type (E));
2176 Set_Is_Volatile (Underlying_Type (E));
2178 Set_Treat_As_Volatile (E);
2179 Set_Treat_As_Volatile (Underlying_Type (E));
2181 elsif K = N_Object_Declaration
2182 or else (K = N_Component_Declaration
2183 and then Original_Record_Component (E) = E)
2185 if Rep_Item_Too_Late (E, N) then
2189 if Prag_Id /= Pragma_Volatile then
2192 -- If the object declaration has an explicit initialization, a
2193 -- temporary may have to be created to hold the expression, to
2194 -- ensure that access to the object remain atomic.
2196 if Nkind (Parent (E)) = N_Object_Declaration
2197 and then Present (Expression (Parent (E)))
2199 Set_Has_Delayed_Freeze (E);
2202 -- An interesting improvement here. If an object of type X is
2203 -- declared atomic, and the type X is not atomic, that's a
2204 -- pity, since it may not have appropriate alignment etc. We
2205 -- can rescue this in the special case where the object and
2206 -- type are in the same unit by just setting the type as
2207 -- atomic, so that the back end will process it as atomic.
2209 Utyp := Underlying_Type (Etype (E));
2212 and then Sloc (E) > No_Location
2213 and then Sloc (Utyp) > No_Location
2215 Get_Source_File_Index (Sloc (E)) =
2216 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2218 Set_Is_Atomic (Underlying_Type (Etype (E)));
2222 Set_Is_Volatile (E);
2223 Set_Treat_As_Volatile (E);
2227 ("inappropriate entity for pragma%", Arg1);
2229 end Process_Atomic_Shared_Volatile;
2231 -------------------------------------------
2232 -- Process_Compile_Time_Warning_Or_Error --
2233 -------------------------------------------
2235 procedure Process_Compile_Time_Warning_Or_Error is
2236 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2239 Check_Arg_Count (2);
2240 Check_No_Identifiers;
2241 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2242 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2244 if Compile_Time_Known_Value (Arg1x) then
2245 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2247 Str : constant String_Id :=
2248 Strval (Get_Pragma_Arg (Arg2));
2249 Len : constant Int := String_Length (Str);
2254 Cent : constant Entity_Id :=
2255 Cunit_Entity (Current_Sem_Unit);
2257 Force : constant Boolean :=
2258 Prag_Id = Pragma_Compile_Time_Warning
2260 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2261 and then (Ekind (Cent) /= E_Package
2262 or else not In_Private_Part (Cent));
2263 -- Set True if this is the warning case, and we are in the
2264 -- visible part of a package spec, or in a subprogram spec,
2265 -- in which case we want to force the client to see the
2266 -- warning, even though it is not in the main unit.
2269 -- Loop through segments of message separated by line feeds.
2270 -- We output these segments as separate messages with
2271 -- continuation marks for all but the first.
2276 Error_Msg_Strlen := 0;
2278 -- Loop to copy characters from argument to error message
2282 exit when Ptr > Len;
2283 CC := Get_String_Char (Str, Ptr);
2286 -- Ignore wide chars ??? else store character
2288 if In_Character_Range (CC) then
2289 C := Get_Character (CC);
2290 exit when C = ASCII.LF;
2291 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2292 Error_Msg_String (Error_Msg_Strlen) := C;
2296 -- Here with one line ready to go
2298 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2300 -- If this is a warning in a spec, then we want clients
2301 -- to see the warning, so mark the message with the
2302 -- special sequence !! to force the warning. In the case
2303 -- of a package spec, we do not force this if we are in
2304 -- the private part of the spec.
2307 if Cont = False then
2308 Error_Msg_N ("<~!!", Arg1);
2311 Error_Msg_N ("\<~!!", Arg1);
2314 -- Error, rather than warning, or in a body, so we do not
2315 -- need to force visibility for client (error will be
2316 -- output in any case, and this is the situation in which
2317 -- we do not want a client to get a warning, since the
2318 -- warning is in the body or the spec private part.
2321 if Cont = False then
2322 Error_Msg_N ("<~", Arg1);
2325 Error_Msg_N ("\<~", Arg1);
2329 exit when Ptr > Len;
2334 end Process_Compile_Time_Warning_Or_Error;
2336 ------------------------
2337 -- Process_Convention --
2338 ------------------------
2340 procedure Process_Convention
2341 (C : out Convention_Id;
2347 Comp_Unit : Unit_Number_Type;
2349 procedure Set_Convention_From_Pragma (E : Entity_Id);
2350 -- Set convention in entity E, and also flag that the entity has a
2351 -- convention pragma. If entity is for a private or incomplete type,
2352 -- also set convention and flag on underlying type. This procedure
2353 -- also deals with the special case of C_Pass_By_Copy convention.
2355 --------------------------------
2356 -- Set_Convention_From_Pragma --
2357 --------------------------------
2359 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2361 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2362 -- for an overridden dispatching operation. Technically this is
2363 -- an amendment and should only be done in Ada 2005 mode. However,
2364 -- this is clearly a mistake, since the problem that is addressed
2365 -- by this AI is that there is a clear gap in the RM!
2367 if Is_Dispatching_Operation (E)
2368 and then Present (Overridden_Operation (E))
2369 and then C /= Convention (Overridden_Operation (E))
2372 ("cannot change convention for " &
2373 "overridden dispatching operation",
2377 -- Set the convention
2379 Set_Convention (E, C);
2380 Set_Has_Convention_Pragma (E);
2382 if Is_Incomplete_Or_Private_Type (E) then
2383 Set_Convention (Underlying_Type (E), C);
2384 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2387 -- A class-wide type should inherit the convention of the specific
2388 -- root type (although this isn't specified clearly by the RM).
2390 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2391 Set_Convention (Class_Wide_Type (E), C);
2394 -- If the entity is a record type, then check for special case of
2395 -- C_Pass_By_Copy, which is treated the same as C except that the
2396 -- special record flag is set. This convention is only permitted
2397 -- on record types (see AI95-00131).
2399 if Cname = Name_C_Pass_By_Copy then
2400 if Is_Record_Type (E) then
2401 Set_C_Pass_By_Copy (Base_Type (E));
2402 elsif Is_Incomplete_Or_Private_Type (E)
2403 and then Is_Record_Type (Underlying_Type (E))
2405 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2408 ("C_Pass_By_Copy convention allowed only for record type",
2413 -- If the entity is a derived boolean type, check for the special
2414 -- case of convention C, C++, or Fortran, where we consider any
2415 -- nonzero value to represent true.
2417 if Is_Discrete_Type (E)
2418 and then Root_Type (Etype (E)) = Standard_Boolean
2424 C = Convention_Fortran)
2426 Set_Nonzero_Is_True (Base_Type (E));
2428 end Set_Convention_From_Pragma;
2430 -- Start of processing for Process_Convention
2433 Check_At_Least_N_Arguments (2);
2434 Check_Optional_Identifier (Arg1, Name_Convention);
2435 Check_Arg_Is_Identifier (Arg1);
2436 Cname := Chars (Expression (Arg1));
2438 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2439 -- tested again below to set the critical flag).
2440 if Cname = Name_C_Pass_By_Copy then
2443 -- Otherwise we must have something in the standard convention list
2445 elsif Is_Convention_Name (Cname) then
2446 C := Get_Convention_Id (Chars (Expression (Arg1)));
2448 -- In DEC VMS, it seems that there is an undocumented feature that
2449 -- any unrecognized convention is treated as the default, which for
2450 -- us is convention C. It does not seem so terrible to do this
2451 -- unconditionally, silently in the VMS case, and with a warning
2452 -- in the non-VMS case.
2455 if Warn_On_Export_Import and not OpenVMS_On_Target then
2457 ("?unrecognized convention name, C assumed",
2464 Check_Optional_Identifier (Arg2, Name_Entity);
2465 Check_Arg_Is_Local_Name (Arg2);
2467 Id := Expression (Arg2);
2470 if not Is_Entity_Name (Id) then
2471 Error_Pragma_Arg ("entity name required", Arg2);
2476 -- Go to renamed subprogram if present, since convention applies to
2477 -- the actual renamed entity, not to the renaming entity. If the
2478 -- subprogram is inherited, go to parent subprogram.
2480 if Is_Subprogram (E)
2481 and then Present (Alias (E))
2483 if Nkind (Parent (Declaration_Node (E))) =
2484 N_Subprogram_Renaming_Declaration
2486 if Scope (E) /= Scope (Alias (E)) then
2488 ("cannot apply pragma% to non-local entity&#", E);
2493 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2494 N_Private_Extension_Declaration)
2495 and then Scope (E) = Scope (Alias (E))
2501 -- Check that we are not applying this to a specless body
2503 if Is_Subprogram (E)
2504 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2507 ("pragma% requires separate spec and must come before body");
2510 -- Check that we are not applying this to a named constant
2512 if Ekind (E) = E_Named_Integer
2514 Ekind (E) = E_Named_Real
2516 Error_Msg_Name_1 := Pname;
2518 ("cannot apply pragma% to named constant!",
2519 Get_Pragma_Arg (Arg2));
2521 ("\supply appropriate type for&!", Arg2);
2524 if Ekind (E) = E_Enumeration_Literal then
2525 Error_Pragma ("enumeration literal not allowed for pragma%");
2528 -- Check for rep item appearing too early or too late
2530 if Etype (E) = Any_Type
2531 or else Rep_Item_Too_Early (E, N)
2535 E := Underlying_Type (E);
2538 if Rep_Item_Too_Late (E, N) then
2542 if Has_Convention_Pragma (E) then
2544 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2546 elsif Convention (E) = Convention_Protected
2547 or else Ekind (Scope (E)) = E_Protected_Type
2550 ("a protected operation cannot be given a different convention",
2554 -- For Intrinsic, a subprogram is required
2556 if C = Convention_Intrinsic
2557 and then not Is_Subprogram (E)
2558 and then not Is_Generic_Subprogram (E)
2561 ("second argument of pragma% must be a subprogram", Arg2);
2564 -- For Stdcall, a subprogram, variable or subprogram type is required
2566 if C = Convention_Stdcall
2567 and then not Is_Subprogram (E)
2568 and then not Is_Generic_Subprogram (E)
2569 and then Ekind (E) /= E_Variable
2572 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2575 ("second argument of pragma% must be subprogram (type)",
2579 if not Is_Subprogram (E)
2580 and then not Is_Generic_Subprogram (E)
2582 Set_Convention_From_Pragma (E);
2586 Check_First_Subtype (Arg2);
2587 Set_Convention_From_Pragma (Base_Type (E));
2589 -- For subprograms, we must set the convention on the
2590 -- internally generated directly designated type as well.
2592 if Ekind (E) = E_Access_Subprogram_Type then
2593 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2597 -- For the subprogram case, set proper convention for all homonyms
2598 -- in same scope and the same declarative part, i.e. the same
2599 -- compilation unit.
2602 Comp_Unit := Get_Source_Unit (E);
2603 Set_Convention_From_Pragma (E);
2605 -- Treat a pragma Import as an implicit body, for GPS use
2607 if Prag_Id = Pragma_Import then
2608 Generate_Reference (E, Id, 'b');
2614 exit when No (E1) or else Scope (E1) /= Current_Scope;
2616 -- Do not set the pragma on inherited operations or on formal
2619 if Comes_From_Source (E1)
2620 and then Comp_Unit = Get_Source_Unit (E1)
2621 and then not Is_Formal_Subprogram (E1)
2622 and then Nkind (Original_Node (Parent (E1))) /=
2623 N_Full_Type_Declaration
2625 if Present (Alias (E1))
2626 and then Scope (E1) /= Scope (Alias (E1))
2629 ("cannot apply pragma% to non-local entity& declared#",
2633 Set_Convention_From_Pragma (E1);
2635 if Prag_Id = Pragma_Import then
2636 Generate_Reference (E, Id, 'b');
2641 end Process_Convention;
2643 -----------------------------------------------------
2644 -- Process_Extended_Import_Export_Exception_Pragma --
2645 -----------------------------------------------------
2647 procedure Process_Extended_Import_Export_Exception_Pragma
2648 (Arg_Internal : Node_Id;
2649 Arg_External : Node_Id;
2657 if not OpenVMS_On_Target then
2659 ("?pragma% ignored (applies only to Open'V'M'S)");
2662 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2663 Def_Id := Entity (Arg_Internal);
2665 if Ekind (Def_Id) /= E_Exception then
2667 ("pragma% must refer to declared exception", Arg_Internal);
2670 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2672 if Present (Arg_Form) then
2673 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2676 if Present (Arg_Form)
2677 and then Chars (Arg_Form) = Name_Ada
2681 Set_Is_VMS_Exception (Def_Id);
2682 Set_Exception_Code (Def_Id, No_Uint);
2685 if Present (Arg_Code) then
2686 if not Is_VMS_Exception (Def_Id) then
2688 ("Code option for pragma% not allowed for Ada case",
2692 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2693 Code_Val := Expr_Value (Arg_Code);
2695 if not UI_Is_In_Int_Range (Code_Val) then
2697 ("Code option for pragma% must be in 32-bit range",
2701 Set_Exception_Code (Def_Id, Code_Val);
2704 end Process_Extended_Import_Export_Exception_Pragma;
2706 -------------------------------------------------
2707 -- Process_Extended_Import_Export_Internal_Arg --
2708 -------------------------------------------------
2710 procedure Process_Extended_Import_Export_Internal_Arg
2711 (Arg_Internal : Node_Id := Empty)
2714 if No (Arg_Internal) then
2715 Error_Pragma ("Internal parameter required for pragma%");
2718 if Nkind (Arg_Internal) = N_Identifier then
2721 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2722 and then (Prag_Id = Pragma_Import_Function
2724 Prag_Id = Pragma_Export_Function)
2730 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2733 Check_Arg_Is_Local_Name (Arg_Internal);
2734 end Process_Extended_Import_Export_Internal_Arg;
2736 --------------------------------------------------
2737 -- Process_Extended_Import_Export_Object_Pragma --
2738 --------------------------------------------------
2740 procedure Process_Extended_Import_Export_Object_Pragma
2741 (Arg_Internal : Node_Id;
2742 Arg_External : Node_Id;
2748 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2749 Def_Id := Entity (Arg_Internal);
2751 if Ekind (Def_Id) /= E_Constant
2752 and then Ekind (Def_Id) /= E_Variable
2755 ("pragma% must designate an object", Arg_Internal);
2758 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2760 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2763 ("previous Common/Psect_Object applies, pragma % not permitted",
2767 if Rep_Item_Too_Late (Def_Id, N) then
2771 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2773 if Present (Arg_Size) then
2774 Check_Arg_Is_External_Name (Arg_Size);
2777 -- Export_Object case
2779 if Prag_Id = Pragma_Export_Object then
2780 if not Is_Library_Level_Entity (Def_Id) then
2782 ("argument for pragma% must be library level entity",
2786 if Ekind (Current_Scope) = E_Generic_Package then
2787 Error_Pragma ("pragma& cannot appear in a generic unit");
2790 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2792 ("exported object must have compile time known size",
2796 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2798 ("?duplicate Export_Object pragma", N);
2800 Set_Exported (Def_Id, Arg_Internal);
2803 -- Import_Object case
2806 if Is_Concurrent_Type (Etype (Def_Id)) then
2808 ("cannot use pragma% for task/protected object",
2812 if Ekind (Def_Id) = E_Constant then
2814 ("cannot import a constant", Arg_Internal);
2817 if Warn_On_Export_Import
2818 and then Has_Discriminants (Etype (Def_Id))
2821 ("imported value must be initialized?", Arg_Internal);
2824 if Warn_On_Export_Import
2825 and then Is_Access_Type (Etype (Def_Id))
2828 ("cannot import object of an access type?", Arg_Internal);
2831 if Warn_On_Export_Import
2832 and then Is_Imported (Def_Id)
2835 ("?duplicate Import_Object pragma", N);
2837 -- Check for explicit initialization present. Note that an
2838 -- initialization that generated by the code generator, e.g.
2839 -- for an access type, does not count here.
2841 elsif Present (Expression (Parent (Def_Id)))
2844 (Original_Node (Expression (Parent (Def_Id))))
2846 Error_Msg_Sloc := Sloc (Def_Id);
2848 ("imported entities cannot be initialized (RM B.1(24))",
2849 "\no initialization allowed for & declared#", Arg1);
2851 Set_Imported (Def_Id);
2852 Note_Possible_Modification (Arg_Internal, Sure => False);
2855 end Process_Extended_Import_Export_Object_Pragma;
2857 ------------------------------------------------------
2858 -- Process_Extended_Import_Export_Subprogram_Pragma --
2859 ------------------------------------------------------
2861 procedure Process_Extended_Import_Export_Subprogram_Pragma
2862 (Arg_Internal : Node_Id;
2863 Arg_External : Node_Id;
2864 Arg_Parameter_Types : Node_Id;
2865 Arg_Result_Type : Node_Id := Empty;
2866 Arg_Mechanism : Node_Id;
2867 Arg_Result_Mechanism : Node_Id := Empty;
2868 Arg_First_Optional_Parameter : Node_Id := Empty)
2874 Ambiguous : Boolean;
2878 function Same_Base_Type
2880 Formal : Entity_Id) return Boolean;
2881 -- Determines if Ptype references the type of Formal. Note that only
2882 -- the base types need to match according to the spec. Ptype here is
2883 -- the argument from the pragma, which is either a type name, or an
2884 -- access attribute.
2886 --------------------
2887 -- Same_Base_Type --
2888 --------------------
2890 function Same_Base_Type
2892 Formal : Entity_Id) return Boolean
2894 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2898 -- Case where pragma argument is typ'Access
2900 if Nkind (Ptype) = N_Attribute_Reference
2901 and then Attribute_Name (Ptype) = Name_Access
2903 Pref := Prefix (Ptype);
2906 if not Is_Entity_Name (Pref)
2907 or else Entity (Pref) = Any_Type
2912 -- We have a match if the corresponding argument is of an
2913 -- anonymous access type, and its designated type matches the
2914 -- type of the prefix of the access attribute
2916 return Ekind (Ftyp) = E_Anonymous_Access_Type
2917 and then Base_Type (Entity (Pref)) =
2918 Base_Type (Etype (Designated_Type (Ftyp)));
2920 -- Case where pragma argument is a type name
2925 if not Is_Entity_Name (Ptype)
2926 or else Entity (Ptype) = Any_Type
2931 -- We have a match if the corresponding argument is of the type
2932 -- given in the pragma (comparing base types)
2934 return Base_Type (Entity (Ptype)) = Ftyp;
2938 -- Start of processing for
2939 -- Process_Extended_Import_Export_Subprogram_Pragma
2942 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2946 -- Loop through homonyms (overloadings) of the entity
2948 Hom_Id := Entity (Arg_Internal);
2949 while Present (Hom_Id) loop
2950 Def_Id := Get_Base_Subprogram (Hom_Id);
2952 -- We need a subprogram in the current scope
2954 if not Is_Subprogram (Def_Id)
2955 or else Scope (Def_Id) /= Current_Scope
2962 -- Pragma cannot apply to subprogram body
2964 if Is_Subprogram (Def_Id)
2965 and then Nkind (Parent (Declaration_Node (Def_Id))) =
2969 ("pragma% requires separate spec"
2970 & " and must come before body");
2973 -- Test result type if given, note that the result type
2974 -- parameter can only be present for the function cases.
2976 if Present (Arg_Result_Type)
2977 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2981 elsif Etype (Def_Id) /= Standard_Void_Type
2983 (Pname = Name_Export_Procedure
2985 Pname = Name_Import_Procedure)
2989 -- Test parameter types if given. Note that this parameter
2990 -- has not been analyzed (and must not be, since it is
2991 -- semantic nonsense), so we get it as the parser left it.
2993 elsif Present (Arg_Parameter_Types) then
2994 Check_Matching_Types : declare
2999 Formal := First_Formal (Def_Id);
3001 if Nkind (Arg_Parameter_Types) = N_Null then
3002 if Present (Formal) then
3006 -- A list of one type, e.g. (List) is parsed as
3007 -- a parenthesized expression.
3009 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3010 and then Paren_Count (Arg_Parameter_Types) = 1
3013 or else Present (Next_Formal (Formal))
3018 Same_Base_Type (Arg_Parameter_Types, Formal);
3021 -- A list of more than one type is parsed as a aggregate
3023 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3024 and then Paren_Count (Arg_Parameter_Types) = 0
3026 Ptype := First (Expressions (Arg_Parameter_Types));
3027 while Present (Ptype) or else Present (Formal) loop
3030 or else not Same_Base_Type (Ptype, Formal)
3035 Next_Formal (Formal);
3040 -- Anything else is of the wrong form
3044 ("wrong form for Parameter_Types parameter",
3045 Arg_Parameter_Types);
3047 end Check_Matching_Types;
3050 -- Match is now False if the entry we found did not match
3051 -- either a supplied Parameter_Types or Result_Types argument
3057 -- Ambiguous case, the flag Ambiguous shows if we already
3058 -- detected this and output the initial messages.
3061 if not Ambiguous then
3063 Error_Msg_Name_1 := Pname;
3065 ("pragma% does not uniquely identify subprogram!",
3067 Error_Msg_Sloc := Sloc (Ent);
3068 Error_Msg_N ("matching subprogram #!", N);
3072 Error_Msg_Sloc := Sloc (Def_Id);
3073 Error_Msg_N ("matching subprogram #!", N);
3078 Hom_Id := Homonym (Hom_Id);
3081 -- See if we found an entry
3084 if not Ambiguous then
3085 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3087 ("pragma% cannot be given for generic subprogram");
3090 ("pragma% does not identify local subprogram");
3097 -- Import pragmas must be for imported entities
3099 if Prag_Id = Pragma_Import_Function
3101 Prag_Id = Pragma_Import_Procedure
3103 Prag_Id = Pragma_Import_Valued_Procedure
3105 if not Is_Imported (Ent) then
3107 ("pragma Import or Interface must precede pragma%");
3110 -- Here we have the Export case which can set the entity as exported
3112 -- But does not do so if the specified external name is null, since
3113 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3114 -- compatible) to request no external name.
3116 elsif Nkind (Arg_External) = N_String_Literal
3117 and then String_Length (Strval (Arg_External)) = 0
3121 -- In all other cases, set entity as exported
3124 Set_Exported (Ent, Arg_Internal);
3127 -- Special processing for Valued_Procedure cases
3129 if Prag_Id = Pragma_Import_Valued_Procedure
3131 Prag_Id = Pragma_Export_Valued_Procedure
3133 Formal := First_Formal (Ent);
3137 ("at least one parameter required for pragma%");
3139 elsif Ekind (Formal) /= E_Out_Parameter then
3141 ("first parameter must have mode out for pragma%");
3144 Set_Is_Valued_Procedure (Ent);
3148 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3150 -- Process Result_Mechanism argument if present. We have already
3151 -- checked that this is only allowed for the function case.
3153 if Present (Arg_Result_Mechanism) then
3154 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3157 -- Process Mechanism parameter if present. Note that this parameter
3158 -- is not analyzed, and must not be analyzed since it is semantic
3159 -- nonsense, so we get it in exactly as the parser left it.
3161 if Present (Arg_Mechanism) then
3169 -- A single mechanism association without a formal parameter
3170 -- name is parsed as a parenthesized expression. All other
3171 -- cases are parsed as aggregates, so we rewrite the single
3172 -- parameter case as an aggregate for consistency.
3174 if Nkind (Arg_Mechanism) /= N_Aggregate
3175 and then Paren_Count (Arg_Mechanism) = 1
3177 Rewrite (Arg_Mechanism,
3178 Make_Aggregate (Sloc (Arg_Mechanism),
3179 Expressions => New_List (
3180 Relocate_Node (Arg_Mechanism))));
3183 -- Case of only mechanism name given, applies to all formals
3185 if Nkind (Arg_Mechanism) /= N_Aggregate then
3186 Formal := First_Formal (Ent);
3187 while Present (Formal) loop
3188 Set_Mechanism_Value (Formal, Arg_Mechanism);
3189 Next_Formal (Formal);
3192 -- Case of list of mechanism associations given
3195 if Null_Record_Present (Arg_Mechanism) then
3197 ("inappropriate form for Mechanism parameter",
3201 -- Deal with positional ones first
3203 Formal := First_Formal (Ent);
3205 if Present (Expressions (Arg_Mechanism)) then
3206 Mname := First (Expressions (Arg_Mechanism));
3207 while Present (Mname) loop
3210 ("too many mechanism associations", Mname);
3213 Set_Mechanism_Value (Formal, Mname);
3214 Next_Formal (Formal);
3219 -- Deal with named entries
3221 if Present (Component_Associations (Arg_Mechanism)) then
3222 Massoc := First (Component_Associations (Arg_Mechanism));
3223 while Present (Massoc) loop
3224 Choice := First (Choices (Massoc));
3226 if Nkind (Choice) /= N_Identifier
3227 or else Present (Next (Choice))
3230 ("incorrect form for mechanism association",
3234 Formal := First_Formal (Ent);
3238 ("parameter name & not present", Choice);
3241 if Chars (Choice) = Chars (Formal) then
3243 (Formal, Expression (Massoc));
3245 -- Set entity on identifier for ASIS
3247 Set_Entity (Choice, Formal);
3252 Next_Formal (Formal);
3262 -- Process First_Optional_Parameter argument if present. We have
3263 -- already checked that this is only allowed for the Import case.
3265 if Present (Arg_First_Optional_Parameter) then
3266 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3268 ("first optional parameter must be formal parameter name",
3269 Arg_First_Optional_Parameter);
3272 Formal := First_Formal (Ent);
3276 ("specified formal parameter& not found",
3277 Arg_First_Optional_Parameter);
3280 exit when Chars (Formal) =
3281 Chars (Arg_First_Optional_Parameter);
3283 Next_Formal (Formal);
3286 Set_First_Optional_Parameter (Ent, Formal);
3288 -- Check specified and all remaining formals have right form
3290 while Present (Formal) loop
3291 if Ekind (Formal) /= E_In_Parameter then
3293 ("optional formal& is not of mode in!",
3294 Arg_First_Optional_Parameter, Formal);
3297 Dval := Default_Value (Formal);
3301 ("optional formal& does not have default value!",
3302 Arg_First_Optional_Parameter, Formal);
3304 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3309 ("default value for optional formal& is non-static!",
3310 Arg_First_Optional_Parameter, Formal);
3314 Set_Is_Optional_Parameter (Formal);
3315 Next_Formal (Formal);
3318 end Process_Extended_Import_Export_Subprogram_Pragma;
3320 --------------------------
3321 -- Process_Generic_List --
3322 --------------------------
3324 procedure Process_Generic_List is
3329 Check_No_Identifiers;
3330 Check_At_Least_N_Arguments (1);
3333 while Present (Arg) loop
3334 Exp := Expression (Arg);
3337 if not Is_Entity_Name (Exp)
3339 (not Is_Generic_Instance (Entity (Exp))
3341 not Is_Generic_Unit (Entity (Exp)))
3344 ("pragma% argument must be name of generic unit/instance",
3350 end Process_Generic_List;
3352 ---------------------------------
3353 -- Process_Import_Or_Interface --
3354 ---------------------------------
3356 procedure Process_Import_Or_Interface is
3362 Process_Convention (C, Def_Id);
3363 Kill_Size_Check_Code (Def_Id);
3364 Note_Possible_Modification (Expression (Arg2), Sure => False);
3366 if Ekind (Def_Id) = E_Variable
3368 Ekind (Def_Id) = E_Constant
3370 -- We do not permit Import to apply to a renaming declaration
3372 if Present (Renamed_Object (Def_Id)) then
3374 ("pragma% not allowed for object renaming", Arg2);
3376 -- User initialization is not allowed for imported object, but
3377 -- the object declaration may contain a default initialization,
3378 -- that will be discarded. Note that an explicit initialization
3379 -- only counts if it comes from source, otherwise it is simply
3380 -- the code generator making an implicit initialization explicit.
3382 elsif Present (Expression (Parent (Def_Id)))
3383 and then Comes_From_Source (Expression (Parent (Def_Id)))
3385 Error_Msg_Sloc := Sloc (Def_Id);
3387 ("no initialization allowed for declaration of& #",
3388 "\imported entities cannot be initialized (RM B.1(24))",
3392 Set_Imported (Def_Id);
3393 Process_Interface_Name (Def_Id, Arg3, Arg4);
3395 -- Note that we do not set Is_Public here. That's because we
3396 -- only want to set it if there is no address clause, and we
3397 -- don't know that yet, so we delay that processing till
3400 -- pragma Import completes deferred constants
3402 if Ekind (Def_Id) = E_Constant then
3403 Set_Has_Completion (Def_Id);
3406 -- It is not possible to import a constant of an unconstrained
3407 -- array type (e.g. string) because there is no simple way to
3408 -- write a meaningful subtype for it.
3410 if Is_Array_Type (Etype (Def_Id))
3411 and then not Is_Constrained (Etype (Def_Id))
3414 ("imported constant& must have a constrained subtype",
3419 elsif Is_Subprogram (Def_Id)
3420 or else Is_Generic_Subprogram (Def_Id)
3422 -- If the name is overloaded, pragma applies to all of the
3423 -- denoted entities in the same declarative part.
3426 while Present (Hom_Id) loop
3427 Def_Id := Get_Base_Subprogram (Hom_Id);
3429 -- Ignore inherited subprograms because the pragma will
3430 -- apply to the parent operation, which is the one called.
3432 if Is_Overloadable (Def_Id)
3433 and then Present (Alias (Def_Id))
3437 -- If it is not a subprogram, it must be in an outer scope and
3438 -- pragma does not apply.
3440 elsif not Is_Subprogram (Def_Id)
3441 and then not Is_Generic_Subprogram (Def_Id)
3445 -- Verify that the homonym is in the same declarative part (not
3446 -- just the same scope).
3448 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3449 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3454 Set_Imported (Def_Id);
3456 -- Special processing for Convention_Intrinsic
3458 if C = Convention_Intrinsic then
3460 -- Link_Name argument not allowed for intrinsic
3463 and then Chars (Arg3) = Name_Link_Name
3468 if Present (Arg4) then
3470 ("Link_Name argument not allowed for " &
3475 Set_Is_Intrinsic_Subprogram (Def_Id);
3477 -- If no external name is present, then check that this
3478 -- is a valid intrinsic subprogram. If an external name
3479 -- is present, then this is handled by the back end.
3482 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3486 -- All interfaced procedures need an external symbol created
3487 -- for them since they are always referenced from another
3490 Set_Is_Public (Def_Id);
3492 -- Verify that the subprogram does not have a completion
3493 -- through a renaming declaration. For other completions the
3494 -- pragma appears as a too late representation.
3497 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3501 and then Nkind (Decl) = N_Subprogram_Declaration
3502 and then Present (Corresponding_Body (Decl))
3503 and then Nkind (Unit_Declaration_Node
3504 (Corresponding_Body (Decl))) =
3505 N_Subprogram_Renaming_Declaration
3507 Error_Msg_Sloc := Sloc (Def_Id);
3509 ("cannot import&, renaming already provided for " &
3510 "declaration #", N, Def_Id);
3514 Set_Has_Completion (Def_Id);
3515 Process_Interface_Name (Def_Id, Arg3, Arg4);
3518 if Is_Compilation_Unit (Hom_Id) then
3520 -- Its possible homonyms are not affected by the pragma.
3521 -- Such homonyms might be present in the context of other
3522 -- units being compiled.
3527 Hom_Id := Homonym (Hom_Id);
3531 -- When the convention is Java or CIL, we also allow Import to be
3532 -- given for packages, generic packages, exceptions, and record
3535 elsif (C = Convention_Java or else C = Convention_CIL)
3537 (Is_Package_Or_Generic_Package (Def_Id)
3538 or else Ekind (Def_Id) = E_Exception
3539 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3541 Set_Imported (Def_Id);
3542 Set_Is_Public (Def_Id);
3543 Process_Interface_Name (Def_Id, Arg3, Arg4);
3545 -- Import a CPP class
3547 elsif Is_Record_Type (Def_Id)
3548 and then C = Convention_CPP
3550 if not Is_Tagged_Type (Def_Id) then
3551 Error_Msg_Sloc := Sloc (Def_Id);
3552 Error_Pragma_Arg ("imported 'C'P'P type must be tagged", Arg2);
3555 -- Types treated as CPP classes are treated as limited, but we
3556 -- don't require them to be declared this way. A warning is
3557 -- issued to encourage the user to declare them as limited.
3558 -- This is not an error, for compatibility reasons, because
3559 -- these types have been supported this way for some time.
3561 if not Is_Limited_Type (Def_Id) then
3563 ("imported 'C'P'P type should be " &
3564 "explicitly declared limited?",
3565 Get_Pragma_Arg (Arg2));
3567 ("\type will be considered limited",
3568 Get_Pragma_Arg (Arg2));
3571 Set_Is_CPP_Class (Def_Id);
3572 Set_Is_Limited_Record (Def_Id);
3577 ("second argument of pragma% must be object or subprogram",
3581 -- If this pragma applies to a compilation unit, then the unit, which
3582 -- is a subprogram, does not require (or allow) a body. We also do
3583 -- not need to elaborate imported procedures.
3585 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3587 Cunit : constant Node_Id := Parent (Parent (N));
3589 Set_Body_Required (Cunit, False);
3592 end Process_Import_Or_Interface;
3594 --------------------
3595 -- Process_Inline --
3596 --------------------
3598 procedure Process_Inline (Active : Boolean) is
3604 Effective : Boolean := False;
3606 procedure Make_Inline (Subp : Entity_Id);
3607 -- Subp is the defining unit name of the subprogram declaration. Set
3608 -- the flag, as well as the flag in the corresponding body, if there
3611 procedure Set_Inline_Flags (Subp : Entity_Id);
3612 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3613 -- Has_Pragma_Inline_Always for the Inline_Always case.
3615 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3616 -- Returns True if it can be determined at this stage that inlining
3617 -- is not possible, for example if the body is available and contains
3618 -- exception handlers, we prevent inlining, since otherwise we can
3619 -- get undefined symbols at link time. This function also emits a
3620 -- warning if front-end inlining is enabled and the pragma appears
3623 -- ??? is business with link symbols still valid, or does it relate
3624 -- to front end ZCX which is being phased out ???
3626 ---------------------------
3627 -- Inlining_Not_Possible --
3628 ---------------------------
3630 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3631 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3635 if Nkind (Decl) = N_Subprogram_Body then
3636 Stats := Handled_Statement_Sequence (Decl);
3637 return Present (Exception_Handlers (Stats))
3638 or else Present (At_End_Proc (Stats));
3640 elsif Nkind (Decl) = N_Subprogram_Declaration
3641 and then Present (Corresponding_Body (Decl))
3643 if Front_End_Inlining
3644 and then Analyzed (Corresponding_Body (Decl))
3646 Error_Msg_N ("pragma appears too late, ignored?", N);
3649 -- If the subprogram is a renaming as body, the body is just a
3650 -- call to the renamed subprogram, and inlining is trivially
3654 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3655 N_Subprogram_Renaming_Declaration
3661 Handled_Statement_Sequence
3662 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3665 Present (Exception_Handlers (Stats))
3666 or else Present (At_End_Proc (Stats));
3670 -- If body is not available, assume the best, the check is
3671 -- performed again when compiling enclosing package bodies.
3675 end Inlining_Not_Possible;
3681 procedure Make_Inline (Subp : Entity_Id) is
3682 Kind : constant Entity_Kind := Ekind (Subp);
3683 Inner_Subp : Entity_Id := Subp;
3686 -- Ignore if bad type, avoid cascaded error
3688 if Etype (Subp) = Any_Type then
3692 -- Ignore if all inlining is suppressed
3694 elsif Suppress_All_Inlining then
3698 -- If inlining is not possible, for now do not treat as an error
3700 elsif Inlining_Not_Possible (Subp) then
3704 -- Here we have a candidate for inlining, but we must exclude
3705 -- derived operations. Otherwise we would end up trying to inline
3706 -- a phantom declaration, and the result would be to drag in a
3707 -- body which has no direct inlining associated with it. That
3708 -- would not only be inefficient but would also result in the
3709 -- backend doing cross-unit inlining in cases where it was
3710 -- definitely inappropriate to do so.
3712 -- However, a simple Comes_From_Source test is insufficient, since
3713 -- we do want to allow inlining of generic instances which also do
3714 -- not come from source. We also need to recognize specs generated
3715 -- by the front-end for bodies that carry the pragma. Finally,
3716 -- predefined operators do not come from source but are not
3717 -- inlineable either.
3719 elsif Is_Generic_Instance (Subp)
3720 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3724 elsif not Comes_From_Source (Subp)
3725 and then Scope (Subp) /= Standard_Standard
3731 -- The referenced entity must either be the enclosing entity, or
3732 -- an entity declared within the current open scope.
3734 if Present (Scope (Subp))
3735 and then Scope (Subp) /= Current_Scope
3736 and then Subp /= Current_Scope
3739 ("argument of% must be entity in current scope", Assoc);
3743 -- Processing for procedure, operator or function. If subprogram
3744 -- is aliased (as for an instance) indicate that the renamed
3745 -- entity (if declared in the same unit) is inlined.
3747 if Is_Subprogram (Subp) then
3748 while Present (Alias (Inner_Subp)) loop
3749 Inner_Subp := Alias (Inner_Subp);
3752 if In_Same_Source_Unit (Subp, Inner_Subp) then
3753 Set_Inline_Flags (Inner_Subp);
3755 Decl := Parent (Parent (Inner_Subp));
3757 if Nkind (Decl) = N_Subprogram_Declaration
3758 and then Present (Corresponding_Body (Decl))
3760 Set_Inline_Flags (Corresponding_Body (Decl));
3762 elsif Is_Generic_Instance (Subp) then
3764 -- Indicate that the body needs to be created for
3765 -- inlining subsequent calls. The instantiation node
3766 -- follows the declaration of the wrapper package
3769 if Scope (Subp) /= Standard_Standard
3771 Need_Subprogram_Instance_Body
3772 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3782 -- For a generic subprogram set flag as well, for use at the point
3783 -- of instantiation, to determine whether the body should be
3786 elsif Is_Generic_Subprogram (Subp) then
3787 Set_Inline_Flags (Subp);
3790 -- Literals are by definition inlined
3792 elsif Kind = E_Enumeration_Literal then
3795 -- Anything else is an error
3799 ("expect subprogram name for pragma%", Assoc);
3803 ----------------------
3804 -- Set_Inline_Flags --
3805 ----------------------
3807 procedure Set_Inline_Flags (Subp : Entity_Id) is
3810 Set_Is_Inlined (Subp, True);
3813 if not Has_Pragma_Inline (Subp) then
3814 Set_Has_Pragma_Inline (Subp);
3818 if Prag_Id = Pragma_Inline_Always then
3819 Set_Has_Pragma_Inline_Always (Subp);
3821 end Set_Inline_Flags;
3823 -- Start of processing for Process_Inline
3826 Check_No_Identifiers;
3827 Check_At_Least_N_Arguments (1);
3830 Inline_Processing_Required := True;
3834 while Present (Assoc) loop
3835 Subp_Id := Expression (Assoc);
3839 if Is_Entity_Name (Subp_Id) then
3840 Subp := Entity (Subp_Id);
3842 if Subp = Any_Id then
3844 -- If previous error, avoid cascaded errors
3852 while Present (Homonym (Subp))
3853 and then Scope (Homonym (Subp)) = Current_Scope
3855 Make_Inline (Homonym (Subp));
3856 Subp := Homonym (Subp);
3863 ("inappropriate argument for pragma%", Assoc);
3866 and then Warn_On_Redundant_Constructs
3867 and then not Suppress_All_Inlining
3869 if Inlining_Not_Possible (Subp) then
3871 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3874 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3882 ----------------------------
3883 -- Process_Interface_Name --
3884 ----------------------------
3886 procedure Process_Interface_Name
3887 (Subprogram_Def : Entity_Id;
3893 String_Val : String_Id;
3895 procedure Check_Form_Of_Interface_Name
3897 Ext_Name_Case : Boolean);
3898 -- SN is a string literal node for an interface name. This routine
3899 -- performs some minimal checks that the name is reasonable. In
3900 -- particular that no spaces or other obviously incorrect characters
3901 -- appear. This is only a warning, since any characters are allowed.
3902 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3904 ----------------------------------
3905 -- Check_Form_Of_Interface_Name --
3906 ----------------------------------
3908 procedure Check_Form_Of_Interface_Name
3910 Ext_Name_Case : Boolean)
3912 S : constant String_Id := Strval (Expr_Value_S (SN));
3913 SL : constant Nat := String_Length (S);
3918 Error_Msg_N ("interface name cannot be null string", SN);
3921 for J in 1 .. SL loop
3922 C := Get_String_Char (S, J);
3924 -- Look for dubious character and issue unconditional warning.
3925 -- Definitely dubious if not in character range.
3927 if not In_Character_Range (C)
3929 -- For all cases except external names on CLI target,
3930 -- commas, spaces and slashes are dubious (in CLI, we use
3931 -- spaces and commas in external names to specify assembly
3932 -- version and public key).
3934 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
3935 and then (Get_Character (C) = ' '
3937 Get_Character (C) = ','
3939 Get_Character (C) = '/'
3941 Get_Character (C) = '\'))
3944 ("?interface name contains illegal character",
3945 Sloc (SN) + Source_Ptr (J));
3948 end Check_Form_Of_Interface_Name;
3950 -- Start of processing for Process_Interface_Name
3953 if No (Link_Arg) then
3954 if No (Ext_Arg) then
3955 if VM_Target = CLI_Target
3956 and then Ekind (Subprogram_Def) = E_Package
3957 and then Nkind (Parent (Subprogram_Def)) =
3958 N_Package_Specification
3959 and then Present (Generic_Parent (Parent (Subprogram_Def)))
3964 (Generic_Parent (Parent (Subprogram_Def))));
3969 elsif Chars (Ext_Arg) = Name_Link_Name then
3971 Link_Nam := Expression (Ext_Arg);
3974 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3975 Ext_Nam := Expression (Ext_Arg);
3980 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3981 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3982 Ext_Nam := Expression (Ext_Arg);
3983 Link_Nam := Expression (Link_Arg);
3986 -- Check expressions for external name and link name are static
3988 if Present (Ext_Nam) then
3989 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3990 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
3992 -- Verify that external name is not the name of a local entity,
3993 -- which would hide the imported one and could lead to run-time
3994 -- surprises. The problem can only arise for entities declared in
3995 -- a package body (otherwise the external name is fully qualified
3996 -- and will not conflict).
4004 if Prag_Id = Pragma_Import then
4005 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4007 E := Entity_Id (Get_Name_Table_Info (Nam));
4009 if Nam /= Chars (Subprogram_Def)
4010 and then Present (E)
4011 and then not Is_Overloadable (E)
4012 and then Is_Immediately_Visible (E)
4013 and then not Is_Imported (E)
4014 and then Ekind (Scope (E)) = E_Package
4017 while Present (Par) loop
4018 if Nkind (Par) = N_Package_Body then
4019 Error_Msg_Sloc := Sloc (E);
4021 ("imported entity is hidden by & declared#",
4026 Par := Parent (Par);
4033 if Present (Link_Nam) then
4034 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4035 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4038 -- If there is no link name, just set the external name
4040 if No (Link_Nam) then
4041 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4043 -- For the Link_Name case, the given literal is preceded by an
4044 -- asterisk, which indicates to GCC that the given name should be
4045 -- taken literally, and in particular that no prepending of
4046 -- underlines should occur, even in systems where this is the
4052 if VM_Target = No_VM then
4053 Store_String_Char (Get_Char_Code ('*'));
4056 String_Val := Strval (Expr_Value_S (Link_Nam));
4057 Store_String_Chars (String_Val);
4059 Make_String_Literal (Sloc (Link_Nam),
4060 Strval => End_String);
4063 Set_Encoded_Interface_Name
4064 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4065 Check_Duplicated_Export_Name (Link_Nam);
4066 end Process_Interface_Name;
4068 -----------------------------------------
4069 -- Process_Interrupt_Or_Attach_Handler --
4070 -----------------------------------------
4072 procedure Process_Interrupt_Or_Attach_Handler is
4073 Arg1_X : constant Node_Id := Expression (Arg1);
4074 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4075 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4078 Set_Is_Interrupt_Handler (Handler_Proc);
4080 -- If the pragma is not associated with a handler procedure within a
4081 -- protected type, then it must be for a nonprotected procedure for
4082 -- the AAMP target, in which case we don't associate a representation
4083 -- item with the procedure's scope.
4085 if Ekind (Proc_Scope) = E_Protected_Type then
4086 if Prag_Id = Pragma_Interrupt_Handler
4088 Prag_Id = Pragma_Attach_Handler
4090 Record_Rep_Item (Proc_Scope, N);
4093 end Process_Interrupt_Or_Attach_Handler;
4095 --------------------------------------------------
4096 -- Process_Restrictions_Or_Restriction_Warnings --
4097 --------------------------------------------------
4099 -- Note: some of the simple identifier cases were handled in par-prag,
4100 -- but it is harmless (and more straightforward) to simply handle all
4101 -- cases here, even if it means we repeat a bit of work in some cases.
4103 procedure Process_Restrictions_Or_Restriction_Warnings
4107 R_Id : Restriction_Id;
4112 procedure Check_Unit_Name (N : Node_Id);
4113 -- Checks unit name parameter for No_Dependence. Returns if it has
4114 -- an appropriate form, otherwise raises pragma argument error.
4116 ---------------------
4117 -- Check_Unit_Name --
4118 ---------------------
4120 procedure Check_Unit_Name (N : Node_Id) is
4122 if Nkind (N) = N_Selected_Component then
4123 Check_Unit_Name (Prefix (N));
4124 Check_Unit_Name (Selector_Name (N));
4126 elsif Nkind (N) = N_Identifier then
4131 ("wrong form for unit name for No_Dependence", N);
4133 end Check_Unit_Name;
4135 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4138 Check_Ada_83_Warning;
4139 Check_At_Least_N_Arguments (1);
4140 Check_Valid_Configuration_Pragma;
4143 while Present (Arg) loop
4145 Expr := Expression (Arg);
4147 -- Case of no restriction identifier present
4149 if Id = No_Name then
4150 if Nkind (Expr) /= N_Identifier then
4152 ("invalid form for restriction", Arg);
4157 (Process_Restriction_Synonyms (Expr));
4159 if R_Id not in All_Boolean_Restrictions then
4160 Error_Msg_Name_1 := Pname;
4162 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4164 -- Check for possible misspelling
4166 for J in Restriction_Id loop
4168 Rnm : constant String := Restriction_Id'Image (J);
4171 Name_Buffer (1 .. Rnm'Length) := Rnm;
4172 Name_Len := Rnm'Length;
4173 Set_Casing (All_Lower_Case);
4175 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4177 (Identifier_Casing (Current_Source_File));
4178 Error_Msg_String (1 .. Rnm'Length) :=
4179 Name_Buffer (1 .. Name_Len);
4180 Error_Msg_Strlen := Rnm'Length;
4182 ("\possible misspelling of ""~""",
4183 Get_Pragma_Arg (Arg));
4192 if Implementation_Restriction (R_Id) then
4193 Check_Restriction (No_Implementation_Restrictions, Arg);
4196 -- If this is a warning, then set the warning unless we already
4197 -- have a real restriction active (we never want a warning to
4198 -- override a real restriction).
4201 if not Restriction_Active (R_Id) then
4202 Set_Restriction (R_Id, N);
4203 Restriction_Warnings (R_Id) := True;
4206 -- If real restriction case, then set it and make sure that the
4207 -- restriction warning flag is off, since a real restriction
4208 -- always overrides a warning.
4211 Set_Restriction (R_Id, N);
4212 Restriction_Warnings (R_Id) := False;
4215 -- A very special case that must be processed here: pragma
4216 -- Restrictions (No_Exceptions) turns off all run-time
4217 -- checking. This is a bit dubious in terms of the formal
4218 -- language definition, but it is what is intended by RM
4219 -- H.4(12). Restriction_Warnings never affects generated code
4220 -- so this is done only in the real restriction case.
4222 if R_Id = No_Exceptions and then not Warn then
4223 Scope_Suppress := (others => True);
4226 -- Case of No_Dependence => unit-name. Note that the parser
4227 -- already made the necessary entry in the No_Dependence table.
4229 elsif Id = Name_No_Dependence then
4230 Check_Unit_Name (Expr);
4232 -- All other cases of restriction identifier present
4235 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4236 Analyze_And_Resolve (Expr, Any_Integer);
4238 if R_Id not in All_Parameter_Restrictions then
4240 ("invalid restriction parameter identifier", Arg);
4242 elsif not Is_OK_Static_Expression (Expr) then
4243 Flag_Non_Static_Expr
4244 ("value must be static expression!", Expr);
4247 elsif not Is_Integer_Type (Etype (Expr))
4248 or else Expr_Value (Expr) < 0
4251 ("value must be non-negative integer", Arg);
4254 -- Restriction pragma is active
4256 Val := Expr_Value (Expr);
4258 if not UI_Is_In_Int_Range (Val) then
4260 ("pragma ignored, value too large?", Arg);
4263 -- Warning case. If the real restriction is active, then we
4264 -- ignore the request, since warning never overrides a real
4265 -- restriction. Otherwise we set the proper warning. Note that
4266 -- this circuit sets the warning again if it is already set,
4267 -- which is what we want, since the constant may have changed.
4270 if not Restriction_Active (R_Id) then
4272 (R_Id, N, Integer (UI_To_Int (Val)));
4273 Restriction_Warnings (R_Id) := True;
4276 -- Real restriction case, set restriction and make sure warning
4277 -- flag is off since real restriction always overrides warning.
4280 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4281 Restriction_Warnings (R_Id) := False;
4287 end Process_Restrictions_Or_Restriction_Warnings;
4289 ---------------------------------
4290 -- Process_Suppress_Unsuppress --
4291 ---------------------------------
4293 -- Note: this procedure makes entries in the check suppress data
4294 -- structures managed by Sem. See spec of package Sem for full
4295 -- details on how we handle recording of check suppression.
4297 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4302 In_Package_Spec : constant Boolean :=
4303 Is_Package_Or_Generic_Package (Current_Scope)
4304 and then not In_Package_Body (Current_Scope);
4306 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4307 -- Used to suppress a single check on the given entity
4309 --------------------------------
4310 -- Suppress_Unsuppress_Echeck --
4311 --------------------------------
4313 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4315 Set_Checks_May_Be_Suppressed (E);
4317 if In_Package_Spec then
4318 Push_Global_Suppress_Stack_Entry
4321 Suppress => Suppress_Case);
4324 Push_Local_Suppress_Stack_Entry
4327 Suppress => Suppress_Case);
4330 -- If this is a first subtype, and the base type is distinct,
4331 -- then also set the suppress flags on the base type.
4333 if Is_First_Subtype (E)
4334 and then Etype (E) /= E
4336 Suppress_Unsuppress_Echeck (Etype (E), C);
4338 end Suppress_Unsuppress_Echeck;
4340 -- Start of processing for Process_Suppress_Unsuppress
4343 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4344 -- declarative part or a package spec (RM 11.5(5)).
4346 if not Is_Configuration_Pragma then
4347 Check_Is_In_Decl_Part_Or_Package_Spec;
4350 Check_At_Least_N_Arguments (1);
4351 Check_At_Most_N_Arguments (2);
4352 Check_No_Identifier (Arg1);
4353 Check_Arg_Is_Identifier (Arg1);
4355 C := Get_Check_Id (Chars (Expression (Arg1)));
4357 if C = No_Check_Id then
4359 ("argument of pragma% is not valid check name", Arg1);
4362 if not Suppress_Case
4363 and then (C = All_Checks or else C = Overflow_Check)
4365 Opt.Overflow_Checks_Unsuppressed := True;
4368 if Arg_Count = 1 then
4370 -- Make an entry in the local scope suppress table. This is the
4371 -- table that directly shows the current value of the scope
4372 -- suppress check for any check id value.
4374 if C = All_Checks then
4376 -- For All_Checks, we set all specific predefined checks with
4377 -- the exception of Elaboration_Check, which is handled
4378 -- specially because of not wanting All_Checks to have the
4379 -- effect of deactivating static elaboration order processing.
4381 for J in Scope_Suppress'Range loop
4382 if J /= Elaboration_Check then
4383 Scope_Suppress (J) := Suppress_Case;
4387 -- If not All_Checks, and predefined check, then set appropriate
4388 -- scope entry. Note that we will set Elaboration_Check if this
4389 -- is explicitly specified.
4391 elsif C in Predefined_Check_Id then
4392 Scope_Suppress (C) := Suppress_Case;
4395 -- Also make an entry in the Local_Entity_Suppress table
4397 Push_Local_Suppress_Stack_Entry
4400 Suppress => Suppress_Case);
4402 -- Case of two arguments present, where the check is suppressed for
4403 -- a specified entity (given as the second argument of the pragma)
4406 Check_Optional_Identifier (Arg2, Name_On);
4407 E_Id := Expression (Arg2);
4410 if not Is_Entity_Name (E_Id) then
4412 ("second argument of pragma% must be entity name", Arg2);
4421 -- Enforce RM 11.5(7) which requires that for a pragma that
4422 -- appears within a package spec, the named entity must be
4423 -- within the package spec. We allow the package name itself
4424 -- to be mentioned since that makes sense, although it is not
4425 -- strictly allowed by 11.5(7).
4428 and then E /= Current_Scope
4429 and then Scope (E) /= Current_Scope
4432 ("entity in pragma% is not in package spec (RM 11.5(7))",
4436 -- Loop through homonyms. As noted below, in the case of a package
4437 -- spec, only homonyms within the package spec are considered.
4440 Suppress_Unsuppress_Echeck (E, C);
4442 if Is_Generic_Instance (E)
4443 and then Is_Subprogram (E)
4444 and then Present (Alias (E))
4446 Suppress_Unsuppress_Echeck (Alias (E), C);
4449 -- Move to next homonym
4454 -- If we are within a package specification, the pragma only
4455 -- applies to homonyms in the same scope.
4457 exit when In_Package_Spec
4458 and then Scope (E) /= Current_Scope;
4461 end Process_Suppress_Unsuppress;
4467 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4469 if Is_Imported (E) then
4471 ("cannot export entity& that was previously imported", Arg);
4473 elsif Present (Address_Clause (E)) then
4475 ("cannot export entity& that has an address clause", Arg);
4478 Set_Is_Exported (E);
4480 -- Generate a reference for entity explicitly, because the
4481 -- identifier may be overloaded and name resolution will not
4484 Generate_Reference (E, Arg);
4486 -- Deal with exporting non-library level entity
4488 if not Is_Library_Level_Entity (E) then
4490 -- Not allowed at all for subprograms
4492 if Is_Subprogram (E) then
4493 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4495 -- Otherwise set public and statically allocated
4499 Set_Is_Statically_Allocated (E);
4501 -- Warn if the corresponding W flag is set and the pragma comes
4502 -- from source. The latter may not be true e.g. on VMS where we
4503 -- expand export pragmas for exception codes associated with
4504 -- imported or exported exceptions. We do not want to generate
4505 -- a warning for something that the user did not write.
4507 if Warn_On_Export_Import
4508 and then Comes_From_Source (Arg)
4511 ("?& has been made static as a result of Export", Arg, E);
4513 ("\this usage is non-standard and non-portable", Arg);
4518 if Warn_On_Export_Import and then Is_Type (E) then
4520 ("exporting a type has no effect?", Arg, E);
4523 if Warn_On_Export_Import and Inside_A_Generic then
4525 ("all instances of& will have the same external name?", Arg, E);
4529 ----------------------------------------------
4530 -- Set_Extended_Import_Export_External_Name --
4531 ----------------------------------------------
4533 procedure Set_Extended_Import_Export_External_Name
4534 (Internal_Ent : Entity_Id;
4535 Arg_External : Node_Id)
4537 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4541 if No (Arg_External) then
4545 Check_Arg_Is_External_Name (Arg_External);
4547 if Nkind (Arg_External) = N_String_Literal then
4548 if String_Length (Strval (Arg_External)) = 0 then
4551 New_Name := Adjust_External_Name_Case (Arg_External);
4554 elsif Nkind (Arg_External) = N_Identifier then
4555 New_Name := Get_Default_External_Name (Arg_External);
4557 -- Check_Arg_Is_External_Name should let through only identifiers and
4558 -- string literals or static string expressions (which are folded to
4559 -- string literals).
4562 raise Program_Error;
4565 -- If we already have an external name set (by a prior normal Import
4566 -- or Export pragma), then the external names must match
4568 if Present (Interface_Name (Internal_Ent)) then
4569 Check_Matching_Internal_Names : declare
4570 S1 : constant String_Id := Strval (Old_Name);
4571 S2 : constant String_Id := Strval (New_Name);
4574 -- Called if names do not match
4580 procedure Mismatch is
4582 Error_Msg_Sloc := Sloc (Old_Name);
4584 ("external name does not match that given #",
4588 -- Start of processing for Check_Matching_Internal_Names
4591 if String_Length (S1) /= String_Length (S2) then
4595 for J in 1 .. String_Length (S1) loop
4596 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4601 end Check_Matching_Internal_Names;
4603 -- Otherwise set the given name
4606 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4607 Check_Duplicated_Export_Name (New_Name);
4609 end Set_Extended_Import_Export_External_Name;
4615 procedure Set_Imported (E : Entity_Id) is
4617 -- Error message if already imported or exported
4619 if Is_Exported (E) or else Is_Imported (E) then
4620 if Is_Exported (E) then
4621 Error_Msg_NE ("entity& was previously exported", N, E);
4623 Error_Msg_NE ("entity& was previously imported", N, E);
4626 Error_Msg_Name_1 := Pname;
4628 ("\(pragma% applies to all previous entities)", N);
4630 Error_Msg_Sloc := Sloc (E);
4631 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4633 -- Here if not previously imported or exported, OK to import
4636 Set_Is_Imported (E);
4638 -- If the entity is an object that is not at the library level,
4639 -- then it is statically allocated. We do not worry about objects
4640 -- with address clauses in this context since they are not really
4641 -- imported in the linker sense.
4644 and then not Is_Library_Level_Entity (E)
4645 and then No (Address_Clause (E))
4647 Set_Is_Statically_Allocated (E);
4652 -------------------------
4653 -- Set_Mechanism_Value --
4654 -------------------------
4656 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4657 -- analyzed, since it is semantic nonsense), so we get it in the exact
4658 -- form created by the parser.
4660 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4663 Mech_Name_Id : Name_Id;
4665 procedure Bad_Class;
4666 -- Signal bad descriptor class name
4668 procedure Bad_Mechanism;
4669 -- Signal bad mechanism name
4675 procedure Bad_Class is
4677 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4680 -------------------------
4681 -- Bad_Mechanism_Value --
4682 -------------------------
4684 procedure Bad_Mechanism is
4686 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4689 -- Start of processing for Set_Mechanism_Value
4692 if Mechanism (Ent) /= Default_Mechanism then
4694 ("mechanism for & has already been set", Mech_Name, Ent);
4697 -- MECHANISM_NAME ::= value | reference | descriptor |
4700 if Nkind (Mech_Name) = N_Identifier then
4701 if Chars (Mech_Name) = Name_Value then
4702 Set_Mechanism (Ent, By_Copy);
4705 elsif Chars (Mech_Name) = Name_Reference then
4706 Set_Mechanism (Ent, By_Reference);
4709 elsif Chars (Mech_Name) = Name_Descriptor then
4710 Check_VMS (Mech_Name);
4711 Set_Mechanism (Ent, By_Descriptor);
4714 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4715 Check_VMS (Mech_Name);
4716 Set_Mechanism (Ent, By_Short_Descriptor);
4719 elsif Chars (Mech_Name) = Name_Copy then
4721 ("bad mechanism name, Value assumed", Mech_Name);
4727 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4728 -- short_descriptor (CLASS_NAME)
4729 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4731 -- Note: this form is parsed as an indexed component
4733 elsif Nkind (Mech_Name) = N_Indexed_Component then
4735 Class := First (Expressions (Mech_Name));
4737 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4738 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4739 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4740 or else Present (Next (Class))
4744 Mech_Name_Id := Chars (Prefix (Mech_Name));
4747 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4748 -- short_descriptor (Class => CLASS_NAME)
4749 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4751 -- Note: this form is parsed as a function call
4753 elsif Nkind (Mech_Name) = N_Function_Call then
4755 Param := First (Parameter_Associations (Mech_Name));
4757 if Nkind (Name (Mech_Name)) /= N_Identifier
4758 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4759 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4760 or else Present (Next (Param))
4761 or else No (Selector_Name (Param))
4762 or else Chars (Selector_Name (Param)) /= Name_Class
4766 Class := Explicit_Actual_Parameter (Param);
4767 Mech_Name_Id := Chars (Name (Mech_Name));
4774 -- Fall through here with Class set to descriptor class name
4776 Check_VMS (Mech_Name);
4778 if Nkind (Class) /= N_Identifier then
4781 elsif Mech_Name_Id = Name_Descriptor
4782 and then Chars (Class) = Name_UBS
4784 Set_Mechanism (Ent, By_Descriptor_UBS);
4786 elsif Mech_Name_Id = Name_Descriptor
4787 and then Chars (Class) = Name_UBSB
4789 Set_Mechanism (Ent, By_Descriptor_UBSB);
4791 elsif Mech_Name_Id = Name_Descriptor
4792 and then Chars (Class) = Name_UBA
4794 Set_Mechanism (Ent, By_Descriptor_UBA);
4796 elsif Mech_Name_Id = Name_Descriptor
4797 and then Chars (Class) = Name_S
4799 Set_Mechanism (Ent, By_Descriptor_S);
4801 elsif Mech_Name_Id = Name_Descriptor
4802 and then Chars (Class) = Name_SB
4804 Set_Mechanism (Ent, By_Descriptor_SB);
4806 elsif Mech_Name_Id = Name_Descriptor
4807 and then Chars (Class) = Name_A
4809 Set_Mechanism (Ent, By_Descriptor_A);
4811 elsif Mech_Name_Id = Name_Descriptor
4812 and then Chars (Class) = Name_NCA
4814 Set_Mechanism (Ent, By_Descriptor_NCA);
4816 elsif Mech_Name_Id = Name_Short_Descriptor
4817 and then Chars (Class) = Name_UBS
4819 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4821 elsif Mech_Name_Id = Name_Short_Descriptor
4822 and then Chars (Class) = Name_UBSB
4824 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4826 elsif Mech_Name_Id = Name_Short_Descriptor
4827 and then Chars (Class) = Name_UBA
4829 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4831 elsif Mech_Name_Id = Name_Short_Descriptor
4832 and then Chars (Class) = Name_S
4834 Set_Mechanism (Ent, By_Short_Descriptor_S);
4836 elsif Mech_Name_Id = Name_Short_Descriptor
4837 and then Chars (Class) = Name_SB
4839 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4841 elsif Mech_Name_Id = Name_Short_Descriptor
4842 and then Chars (Class) = Name_A
4844 Set_Mechanism (Ent, By_Short_Descriptor_A);
4846 elsif Mech_Name_Id = Name_Short_Descriptor
4847 and then Chars (Class) = Name_NCA
4849 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4854 end Set_Mechanism_Value;
4856 ---------------------------
4857 -- Set_Ravenscar_Profile --
4858 ---------------------------
4860 -- The tasks to be done here are
4862 -- Set required policies
4864 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4865 -- pragma Locking_Policy (Ceiling_Locking)
4867 -- Set Detect_Blocking mode
4869 -- Set required restrictions (see System.Rident for detailed list)
4871 procedure Set_Ravenscar_Profile (N : Node_Id) is
4873 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4875 if Task_Dispatching_Policy /= ' '
4876 and then Task_Dispatching_Policy /= 'F'
4878 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4879 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4881 -- Set the FIFO_Within_Priorities policy, but always preserve
4882 -- System_Location since we like the error message with the run time
4886 Task_Dispatching_Policy := 'F';
4888 if Task_Dispatching_Policy_Sloc /= System_Location then
4889 Task_Dispatching_Policy_Sloc := Loc;
4893 -- pragma Locking_Policy (Ceiling_Locking)
4895 if Locking_Policy /= ' '
4896 and then Locking_Policy /= 'C'
4898 Error_Msg_Sloc := Locking_Policy_Sloc;
4899 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4901 -- Set the Ceiling_Locking policy, but preserve System_Location since
4902 -- we like the error message with the run time name.
4905 Locking_Policy := 'C';
4907 if Locking_Policy_Sloc /= System_Location then
4908 Locking_Policy_Sloc := Loc;
4912 -- pragma Detect_Blocking
4914 Detect_Blocking := True;
4916 -- Set the corresponding restrictions
4918 Set_Profile_Restrictions
4919 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4920 end Set_Ravenscar_Profile;
4922 -- Start of processing for Analyze_Pragma
4925 -- Deal with unrecognized pragma
4927 if not Is_Pragma_Name (Pname) then
4928 if Warn_On_Unrecognized_Pragma then
4929 Error_Msg_Name_1 := Pname;
4930 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
4932 for PN in First_Pragma_Name .. Last_Pragma_Name loop
4933 if Is_Bad_Spelling_Of (Pname, PN) then
4934 Error_Msg_Name_1 := PN;
4936 ("\?possible misspelling of %!", Pragma_Identifier (N));
4945 -- Here to start processing for recognized pragma
4947 Prag_Id := Get_Pragma_Id (Pname);
4956 if Present (Pragma_Argument_Associations (N)) then
4957 Arg1 := First (Pragma_Argument_Associations (N));
4959 if Present (Arg1) then
4960 Arg2 := Next (Arg1);
4962 if Present (Arg2) then
4963 Arg3 := Next (Arg2);
4965 if Present (Arg3) then
4966 Arg4 := Next (Arg3);
4972 -- Count number of arguments
4979 while Present (Arg_Node) loop
4980 Arg_Count := Arg_Count + 1;
4985 -- An enumeration type defines the pragmas that are supported by the
4986 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
4987 -- into the corresponding enumeration value for the following case.
4995 -- pragma Abort_Defer;
4997 when Pragma_Abort_Defer =>
4999 Check_Arg_Count (0);
5001 -- The only required semantic processing is to check the
5002 -- placement. This pragma must appear at the start of the
5003 -- statement sequence of a handled sequence of statements.
5005 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5006 or else N /= First (Statements (Parent (N)))
5017 -- Note: this pragma also has some specific processing in Par.Prag
5018 -- because we want to set the Ada version mode during parsing.
5020 when Pragma_Ada_83 =>
5022 Check_Arg_Count (0);
5024 -- We really should check unconditionally for proper configuration
5025 -- pragma placement, since we really don't want mixed Ada modes
5026 -- within a single unit, and the GNAT reference manual has always
5027 -- said this was a configuration pragma, but we did not check and
5028 -- are hesitant to add the check now.
5030 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5031 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5033 if Ada_Version >= Ada_05 then
5034 Check_Valid_Configuration_Pragma;
5037 -- Now set Ada 83 mode
5039 Ada_Version := Ada_83;
5040 Ada_Version_Explicit := Ada_Version;
5048 -- Note: this pragma also has some specific processing in Par.Prag
5049 -- because we want to set the Ada 83 version mode during parsing.
5051 when Pragma_Ada_95 =>
5053 Check_Arg_Count (0);
5055 -- We really should check unconditionally for proper configuration
5056 -- pragma placement, since we really don't want mixed Ada modes
5057 -- within a single unit, and the GNAT reference manual has always
5058 -- said this was a configuration pragma, but we did not check and
5059 -- are hesitant to add the check now.
5061 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5062 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5064 if Ada_Version >= Ada_05 then
5065 Check_Valid_Configuration_Pragma;
5068 -- Now set Ada 95 mode
5070 Ada_Version := Ada_95;
5071 Ada_Version_Explicit := Ada_Version;
5073 ---------------------
5074 -- Ada_05/Ada_2005 --
5075 ---------------------
5078 -- pragma Ada_05 (LOCAL_NAME);
5081 -- pragma Ada_2005 (LOCAL_NAME):
5083 -- Note: these pragma also have some specific processing in Par.Prag
5084 -- because we want to set the Ada 2005 version mode during parsing.
5086 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5092 if Arg_Count = 1 then
5093 Check_Arg_Is_Local_Name (Arg1);
5094 E_Id := Expression (Arg1);
5096 if Etype (E_Id) = Any_Type then
5100 Set_Is_Ada_2005_Only (Entity (E_Id));
5103 Check_Arg_Count (0);
5105 -- For Ada_2005 we unconditionally enforce the documented
5106 -- configuration pragma placement, since we do not want to
5107 -- tolerate mixed modes in a unit involving Ada 2005. That
5108 -- would cause real difficulties for those cases where there
5109 -- are incompatibilities between Ada 95 and Ada 2005.
5111 Check_Valid_Configuration_Pragma;
5113 -- Now set Ada 2005 mode
5115 Ada_Version := Ada_05;
5116 Ada_Version_Explicit := Ada_05;
5120 ----------------------
5121 -- All_Calls_Remote --
5122 ----------------------
5124 -- pragma All_Calls_Remote [(library_package_NAME)];
5126 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5127 Lib_Entity : Entity_Id;
5130 Check_Ada_83_Warning;
5131 Check_Valid_Library_Unit_Pragma;
5133 if Nkind (N) = N_Null_Statement then
5137 Lib_Entity := Find_Lib_Unit_Name;
5139 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5141 if Present (Lib_Entity)
5142 and then not Debug_Flag_U
5144 if not Is_Remote_Call_Interface (Lib_Entity) then
5145 Error_Pragma ("pragma% only apply to rci unit");
5147 -- Set flag for entity of the library unit
5150 Set_Has_All_Calls_Remote (Lib_Entity);
5154 end All_Calls_Remote;
5160 -- pragma Annotate (IDENTIFIER {, ARG});
5161 -- ARG ::= NAME | EXPRESSION
5163 when Pragma_Annotate => Annotate : begin
5165 Check_At_Least_N_Arguments (1);
5166 Check_Arg_Is_Identifier (Arg1);
5174 while Present (Arg) loop
5175 Exp := Expression (Arg);
5178 if Is_Entity_Name (Exp) then
5181 elsif Nkind (Exp) = N_String_Literal then
5182 Resolve (Exp, Standard_String);
5184 elsif Is_Overloaded (Exp) then
5185 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
5200 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5201 -- [, [Message =>] Static_String_EXPRESSION]);
5203 when Pragma_Assert => Assert : declare
5209 Check_At_Least_N_Arguments (1);
5210 Check_At_Most_N_Arguments (2);
5211 Check_Arg_Order ((Name_Check, Name_Message));
5212 Check_Optional_Identifier (Arg1, Name_Check);
5214 -- We treat pragma Assert as equivalent to:
5216 -- pragma Check (Assertion, condition [, msg]);
5218 -- So rewrite pragma in this manner, and analyze the result
5220 Expr := Get_Pragma_Arg (Arg1);
5222 Make_Pragma_Argument_Association (Loc,
5224 Make_Identifier (Loc,
5225 Chars => Name_Assertion)),
5227 Make_Pragma_Argument_Association (Sloc (Expr),
5228 Expression => Expr));
5230 if Arg_Count > 1 then
5231 Check_Optional_Identifier (Arg2, Name_Message);
5232 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5233 Append_To (Newa, Relocate_Node (Arg2));
5238 Chars => Name_Check,
5239 Pragma_Argument_Associations => Newa));
5243 ----------------------
5244 -- Assertion_Policy --
5245 ----------------------
5247 -- pragma Assertion_Policy (Check | Ignore)
5249 when Pragma_Assertion_Policy => Assertion_Policy : declare
5254 Check_Valid_Configuration_Pragma;
5255 Check_Arg_Count (1);
5256 Check_No_Identifiers;
5257 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5259 -- We treat pragma Assertion_Policy as equivalent to:
5261 -- pragma Check_Policy (Assertion, policy)
5263 -- So rewrite the pragma in that manner and link on to the chain
5264 -- of Check_Policy pragmas, marking the pragma as analyzed.
5266 Policy := Get_Pragma_Arg (Arg1);
5270 Chars => Name_Check_Policy,
5272 Pragma_Argument_Associations => New_List (
5273 Make_Pragma_Argument_Association (Loc,
5275 Make_Identifier (Loc,
5276 Chars => Name_Assertion)),
5278 Make_Pragma_Argument_Association (Loc,
5280 Make_Identifier (Sloc (Policy),
5281 Chars => Chars (Policy))))));
5284 Set_Next_Pragma (N, Opt.Check_Policy_List);
5285 Opt.Check_Policy_List := N;
5286 end Assertion_Policy;
5288 ------------------------------
5289 -- Assume_No_Invalid_Values --
5290 ------------------------------
5292 -- pragma Assume_No_Invalid_Values (On | Off);
5294 when Pragma_Assume_No_Invalid_Values =>
5296 Check_Valid_Configuration_Pragma;
5297 Check_Arg_Count (1);
5298 Check_No_Identifiers;
5299 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5301 if Chars (Expression (Arg1)) = Name_On then
5302 Assume_No_Invalid_Values := True;
5304 Assume_No_Invalid_Values := False;
5311 -- pragma AST_Entry (entry_IDENTIFIER);
5313 when Pragma_AST_Entry => AST_Entry : declare
5319 Check_Arg_Count (1);
5320 Check_No_Identifiers;
5321 Check_Arg_Is_Local_Name (Arg1);
5322 Ent := Entity (Expression (Arg1));
5324 -- Note: the implementation of the AST_Entry pragma could handle
5325 -- the entry family case fine, but for now we are consistent with
5326 -- the DEC rules, and do not allow the pragma, which of course
5327 -- has the effect of also forbidding the attribute.
5329 if Ekind (Ent) /= E_Entry then
5331 ("pragma% argument must be simple entry name", Arg1);
5333 elsif Is_AST_Entry (Ent) then
5335 ("duplicate % pragma for entry", Arg1);
5337 elsif Has_Homonym (Ent) then
5339 ("pragma% argument cannot specify overloaded entry", Arg1);
5343 FF : constant Entity_Id := First_Formal (Ent);
5346 if Present (FF) then
5347 if Present (Next_Formal (FF)) then
5349 ("entry for pragma% can have only one argument",
5352 elsif Parameter_Mode (FF) /= E_In_Parameter then
5354 ("entry parameter for pragma% must have mode IN",
5360 Set_Is_AST_Entry (Ent);
5368 -- pragma Asynchronous (LOCAL_NAME);
5370 when Pragma_Asynchronous => Asynchronous : declare
5378 procedure Process_Async_Pragma;
5379 -- Common processing for procedure and access-to-procedure case
5381 --------------------------
5382 -- Process_Async_Pragma --
5383 --------------------------
5385 procedure Process_Async_Pragma is
5388 Set_Is_Asynchronous (Nm);
5392 -- The formals should be of mode IN (RM E.4.1(6))
5395 while Present (S) loop
5396 Formal := Defining_Identifier (S);
5398 if Nkind (Formal) = N_Defining_Identifier
5399 and then Ekind (Formal) /= E_In_Parameter
5402 ("pragma% procedure can only have IN parameter",
5409 Set_Is_Asynchronous (Nm);
5410 end Process_Async_Pragma;
5412 -- Start of processing for pragma Asynchronous
5415 Check_Ada_83_Warning;
5416 Check_No_Identifiers;
5417 Check_Arg_Count (1);
5418 Check_Arg_Is_Local_Name (Arg1);
5420 if Debug_Flag_U then
5424 C_Ent := Cunit_Entity (Current_Sem_Unit);
5425 Analyze (Expression (Arg1));
5426 Nm := Entity (Expression (Arg1));
5428 if not Is_Remote_Call_Interface (C_Ent)
5429 and then not Is_Remote_Types (C_Ent)
5431 -- This pragma should only appear in an RCI or Remote Types
5432 -- unit (RM E.4.1(4)).
5435 ("pragma% not in Remote_Call_Interface or " &
5436 "Remote_Types unit");
5439 if Ekind (Nm) = E_Procedure
5440 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5442 if not Is_Remote_Call_Interface (Nm) then
5444 ("pragma% cannot be applied on non-remote procedure",
5448 L := Parameter_Specifications (Parent (Nm));
5449 Process_Async_Pragma;
5452 elsif Ekind (Nm) = E_Function then
5454 ("pragma% cannot be applied to function", Arg1);
5456 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5458 if Is_Record_Type (Nm) then
5460 -- A record type that is the Equivalent_Type for a remote
5461 -- access-to-subprogram type.
5463 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5466 -- A non-expanded RAS type (distribution is not enabled)
5468 N := Declaration_Node (Nm);
5471 if Nkind (N) = N_Full_Type_Declaration
5472 and then Nkind (Type_Definition (N)) =
5473 N_Access_Procedure_Definition
5475 L := Parameter_Specifications (Type_Definition (N));
5476 Process_Async_Pragma;
5478 if Is_Asynchronous (Nm)
5479 and then Expander_Active
5480 and then Get_PCS_Name /= Name_No_DSA
5482 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5487 ("pragma% cannot reference access-to-function type",
5491 -- Only other possibility is Access-to-class-wide type
5493 elsif Is_Access_Type (Nm)
5494 and then Is_Class_Wide_Type (Designated_Type (Nm))
5496 Check_First_Subtype (Arg1);
5497 Set_Is_Asynchronous (Nm);
5498 if Expander_Active then
5499 RACW_Type_Is_Asynchronous (Nm);
5503 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5511 -- pragma Atomic (LOCAL_NAME);
5513 when Pragma_Atomic =>
5514 Process_Atomic_Shared_Volatile;
5516 -----------------------
5517 -- Atomic_Components --
5518 -----------------------
5520 -- pragma Atomic_Components (array_LOCAL_NAME);
5522 -- This processing is shared by Volatile_Components
5524 when Pragma_Atomic_Components |
5525 Pragma_Volatile_Components =>
5527 Atomic_Components : declare
5534 Check_Ada_83_Warning;
5535 Check_No_Identifiers;
5536 Check_Arg_Count (1);
5537 Check_Arg_Is_Local_Name (Arg1);
5538 E_Id := Expression (Arg1);
5540 if Etype (E_Id) = Any_Type then
5546 if Rep_Item_Too_Early (E, N)
5548 Rep_Item_Too_Late (E, N)
5553 D := Declaration_Node (E);
5556 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5558 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5559 and then Nkind (D) = N_Object_Declaration
5560 and then Nkind (Object_Definition (D)) =
5561 N_Constrained_Array_Definition)
5563 -- The flag is set on the object, or on the base type
5565 if Nkind (D) /= N_Object_Declaration then
5569 Set_Has_Volatile_Components (E);
5571 if Prag_Id = Pragma_Atomic_Components then
5572 Set_Has_Atomic_Components (E);
5574 if Is_Packed (E) then
5575 Set_Is_Packed (E, False);
5578 ("?Pack canceled, cannot pack atomic components",
5584 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5586 end Atomic_Components;
5588 --------------------
5589 -- Attach_Handler --
5590 --------------------
5592 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5594 when Pragma_Attach_Handler =>
5595 Check_Ada_83_Warning;
5596 Check_No_Identifiers;
5597 Check_Arg_Count (2);
5599 if No_Run_Time_Mode then
5600 Error_Msg_CRT ("Attach_Handler pragma", N);
5602 Check_Interrupt_Or_Attach_Handler;
5604 -- The expression that designates the attribute may
5605 -- depend on a discriminant, and is therefore a per-
5606 -- object expression, to be expanded in the init proc.
5607 -- If expansion is enabled, perform semantic checks
5610 if Expander_Active then
5612 Temp : constant Node_Id :=
5613 New_Copy_Tree (Expression (Arg2));
5615 Set_Parent (Temp, N);
5616 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5620 Analyze (Expression (Arg2));
5621 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5624 Process_Interrupt_Or_Attach_Handler;
5627 --------------------
5628 -- C_Pass_By_Copy --
5629 --------------------
5631 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5633 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5639 Check_Valid_Configuration_Pragma;
5640 Check_Arg_Count (1);
5641 Check_Optional_Identifier (Arg1, "max_size");
5643 Arg := Expression (Arg1);
5644 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5646 Val := Expr_Value (Arg);
5650 ("maximum size for pragma% must be positive", Arg1);
5652 elsif UI_Is_In_Int_Range (Val) then
5653 Default_C_Record_Mechanism := UI_To_Int (Val);
5655 -- If a giant value is given, Int'Last will do well enough.
5656 -- If sometime someone complains that a record larger than
5657 -- two gigabytes is not copied, we will worry about it then!
5660 Default_C_Record_Mechanism := Mechanism_Type'Last;
5668 -- pragma Check ([Name =>] Identifier,
5669 -- [Check =>] Boolean_Expression
5670 -- [,[Message =>] String_Expression]);
5672 when Pragma_Check => Check : declare
5677 -- Set True if category of assertions referenced by Name enabled
5681 Check_At_Least_N_Arguments (2);
5682 Check_At_Most_N_Arguments (3);
5683 Check_Optional_Identifier (Arg1, Name_Name);
5684 Check_Optional_Identifier (Arg2, Name_Check);
5686 if Arg_Count = 3 then
5687 Check_Optional_Identifier (Arg3, Name_Message);
5688 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5691 Check_Arg_Is_Identifier (Arg1);
5692 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5694 -- If expansion is active and the check is not enabled then we
5695 -- rewrite the Check as:
5697 -- if False and then condition then
5701 -- The reason we do this rewriting during semantic analysis rather
5702 -- than as part of normal expansion is that we cannot analyze and
5703 -- expand the code for the boolean expression directly, or it may
5704 -- cause insertion of actions that would escape the attempt to
5705 -- suppress the check code.
5707 -- Note that the Sloc for the if statement corresponds to the
5708 -- argument condition, not the pragma itself. The reason for this
5709 -- is that we may generate a warning if the condition is False at
5710 -- compile time, and we do not want to delete this warning when we
5711 -- delete the if statement.
5713 Expr := Expression (Arg2);
5715 if Expander_Active and then not Check_On then
5716 Eloc := Sloc (Expr);
5719 Make_If_Statement (Eloc,
5721 Make_And_Then (Eloc,
5722 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5723 Right_Opnd => Expr),
5724 Then_Statements => New_List (
5725 Make_Null_Statement (Eloc))));
5732 Analyze_And_Resolve (Expr, Any_Boolean);
5735 -- If assertion is of the form (X'First = literal), where X is
5736 -- a formal, then set Low_Bound_Known flag on this formal.
5738 if Nkind (Expr) = N_Op_Eq then
5740 Right : constant Node_Id := Right_Opnd (Expr);
5741 Left : constant Node_Id := Left_Opnd (Expr);
5743 if Nkind (Left) = N_Attribute_Reference
5744 and then Attribute_Name (Left) = Name_First
5745 and then Is_Entity_Name (Prefix (Left))
5746 and then Is_Formal (Entity (Prefix (Left)))
5747 and then Nkind (Right) = N_Integer_Literal
5749 Set_Low_Bound_Known (Entity (Prefix (Left)));
5759 -- pragma Check_Name (check_IDENTIFIER);
5761 when Pragma_Check_Name =>
5762 Check_No_Identifiers;
5764 Check_Valid_Configuration_Pragma;
5765 Check_Arg_Count (1);
5766 Check_Arg_Is_Identifier (Arg1);
5769 Nam : constant Name_Id := Chars (Expression (Arg1));
5772 for J in Check_Names.First .. Check_Names.Last loop
5773 if Check_Names.Table (J) = Nam then
5778 Check_Names.Append (Nam);
5785 -- pragma Check_Policy (
5786 -- [Name =>] IDENTIFIER,
5787 -- [Policy =>] POLICY_IDENTIFIER);
5789 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5791 -- Note: this is a configuration pragma, but it is allowed to appear
5794 when Pragma_Check_Policy =>
5796 Check_Arg_Count (2);
5797 Check_Optional_Identifier (Arg1, Name_Name);
5798 Check_Optional_Identifier (Arg2, Name_Policy);
5800 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5802 -- A Check_Policy pragma can appear either as a configuration
5803 -- pragma, or in a declarative part or a package spec (see RM
5804 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5805 -- followed for Check_Policy).
5807 if not Is_Configuration_Pragma then
5808 Check_Is_In_Decl_Part_Or_Package_Spec;
5811 Set_Next_Pragma (N, Opt.Check_Policy_List);
5812 Opt.Check_Policy_List := N;
5814 ---------------------
5815 -- CIL_Constructor --
5816 ---------------------
5818 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5820 -- Processing for this pragma is shared with Java_Constructor
5826 -- pragma Comment (static_string_EXPRESSION)
5828 -- Processing for pragma Comment shares the circuitry for pragma
5829 -- Ident. The only differences are that Ident enforces a limit of 31
5830 -- characters on its argument, and also enforces limitations on
5831 -- placement for DEC compatibility. Pragma Comment shares neither of
5832 -- these restrictions.
5838 -- pragma Common_Object (
5839 -- [Internal =>] LOCAL_NAME
5840 -- [, [External =>] EXTERNAL_SYMBOL]
5841 -- [, [Size =>] EXTERNAL_SYMBOL]);
5843 -- Processing for this pragma is shared with Psect_Object
5845 ------------------------
5846 -- Compile_Time_Error --
5847 ------------------------
5849 -- pragma Compile_Time_Error
5850 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5852 when Pragma_Compile_Time_Error =>
5854 Process_Compile_Time_Warning_Or_Error;
5856 --------------------------
5857 -- Compile_Time_Warning --
5858 --------------------------
5860 -- pragma Compile_Time_Warning
5861 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5863 when Pragma_Compile_Time_Warning =>
5865 Process_Compile_Time_Warning_Or_Error;
5871 when Pragma_Compiler_Unit =>
5873 Check_Arg_Count (0);
5874 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5876 -----------------------------
5877 -- Complete_Representation --
5878 -----------------------------
5880 -- pragma Complete_Representation;
5882 when Pragma_Complete_Representation =>
5884 Check_Arg_Count (0);
5886 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5888 ("pragma & must appear within record representation clause");
5891 ----------------------------
5892 -- Complex_Representation --
5893 ----------------------------
5895 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5897 when Pragma_Complex_Representation => Complex_Representation : declare
5904 Check_Arg_Count (1);
5905 Check_Optional_Identifier (Arg1, Name_Entity);
5906 Check_Arg_Is_Local_Name (Arg1);
5907 E_Id := Expression (Arg1);
5909 if Etype (E_Id) = Any_Type then
5915 if not Is_Record_Type (E) then
5917 ("argument for pragma% must be record type", Arg1);
5920 Ent := First_Entity (E);
5923 or else No (Next_Entity (Ent))
5924 or else Present (Next_Entity (Next_Entity (Ent)))
5925 or else not Is_Floating_Point_Type (Etype (Ent))
5926 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5929 ("record for pragma% must have two fields of the same "
5930 & "floating-point type", Arg1);
5933 Set_Has_Complex_Representation (Base_Type (E));
5935 -- We need to treat the type has having a non-standard
5936 -- representation, for back-end purposes, even though in
5937 -- general a complex will have the default representation
5938 -- of a record with two real components.
5940 Set_Has_Non_Standard_Rep (Base_Type (E));
5942 end Complex_Representation;
5944 -------------------------
5945 -- Component_Alignment --
5946 -------------------------
5948 -- pragma Component_Alignment (
5949 -- [Form =>] ALIGNMENT_CHOICE
5950 -- [, [Name =>] type_LOCAL_NAME]);
5952 -- ALIGNMENT_CHOICE ::=
5954 -- | Component_Size_4
5958 when Pragma_Component_Alignment => Component_AlignmentP : declare
5959 Args : Args_List (1 .. 2);
5960 Names : constant Name_List (1 .. 2) := (
5964 Form : Node_Id renames Args (1);
5965 Name : Node_Id renames Args (2);
5967 Atype : Component_Alignment_Kind;
5972 Gather_Associations (Names, Args);
5975 Error_Pragma ("missing Form argument for pragma%");
5978 Check_Arg_Is_Identifier (Form);
5980 -- Get proper alignment, note that Default = Component_Size on all
5981 -- machines we have so far, and we want to set this value rather
5982 -- than the default value to indicate that it has been explicitly
5983 -- set (and thus will not get overridden by the default component
5984 -- alignment for the current scope)
5986 if Chars (Form) = Name_Component_Size then
5987 Atype := Calign_Component_Size;
5989 elsif Chars (Form) = Name_Component_Size_4 then
5990 Atype := Calign_Component_Size_4;
5992 elsif Chars (Form) = Name_Default then
5993 Atype := Calign_Component_Size;
5995 elsif Chars (Form) = Name_Storage_Unit then
5996 Atype := Calign_Storage_Unit;
6000 ("invalid Form parameter for pragma%", Form);
6003 -- Case with no name, supplied, affects scope table entry
6007 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6009 -- Case of name supplied
6012 Check_Arg_Is_Local_Name (Name);
6014 Typ := Entity (Name);
6017 or else Rep_Item_Too_Early (Typ, N)
6021 Typ := Underlying_Type (Typ);
6024 if not Is_Record_Type (Typ)
6025 and then not Is_Array_Type (Typ)
6028 ("Name parameter of pragma% must identify record or " &
6029 "array type", Name);
6032 -- An explicit Component_Alignment pragma overrides an
6033 -- implicit pragma Pack, but not an explicit one.
6035 if not Has_Pragma_Pack (Base_Type (Typ)) then
6036 Set_Is_Packed (Base_Type (Typ), False);
6037 Set_Component_Alignment (Base_Type (Typ), Atype);
6040 end Component_AlignmentP;
6046 -- pragma Controlled (first_subtype_LOCAL_NAME);
6048 when Pragma_Controlled => Controlled : declare
6052 Check_No_Identifiers;
6053 Check_Arg_Count (1);
6054 Check_Arg_Is_Local_Name (Arg1);
6055 Arg := Expression (Arg1);
6057 if not Is_Entity_Name (Arg)
6058 or else not Is_Access_Type (Entity (Arg))
6060 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6062 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6070 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6071 -- [Entity =>] LOCAL_NAME);
6073 when Pragma_Convention => Convention : declare
6076 pragma Warnings (Off, C);
6077 pragma Warnings (Off, E);
6079 Check_Arg_Order ((Name_Convention, Name_Entity));
6080 Check_Ada_83_Warning;
6081 Check_Arg_Count (2);
6082 Process_Convention (C, E);
6085 ---------------------------
6086 -- Convention_Identifier --
6087 ---------------------------
6089 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6090 -- [Convention =>] convention_IDENTIFIER);
6092 when Pragma_Convention_Identifier => Convention_Identifier : declare
6098 Check_Arg_Order ((Name_Name, Name_Convention));
6099 Check_Arg_Count (2);
6100 Check_Optional_Identifier (Arg1, Name_Name);
6101 Check_Optional_Identifier (Arg2, Name_Convention);
6102 Check_Arg_Is_Identifier (Arg1);
6103 Check_Arg_Is_Identifier (Arg2);
6104 Idnam := Chars (Expression (Arg1));
6105 Cname := Chars (Expression (Arg2));
6107 if Is_Convention_Name (Cname) then
6108 Record_Convention_Identifier
6109 (Idnam, Get_Convention_Id (Cname));
6112 ("second arg for % pragma must be convention", Arg2);
6114 end Convention_Identifier;
6120 -- pragma CPP_Class ([Entity =>] local_NAME)
6122 when Pragma_CPP_Class => CPP_Class : declare
6127 if Warn_On_Obsolescent_Feature then
6129 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6130 " by pragma import?", N);
6134 Check_Arg_Count (1);
6135 Check_Optional_Identifier (Arg1, Name_Entity);
6136 Check_Arg_Is_Local_Name (Arg1);
6138 Arg := Expression (Arg1);
6141 if Etype (Arg) = Any_Type then
6145 if not Is_Entity_Name (Arg)
6146 or else not Is_Type (Entity (Arg))
6148 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6151 Typ := Entity (Arg);
6153 if not Is_Tagged_Type (Typ) then
6154 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6157 -- Types treated as CPP classes are treated as limited, but we
6158 -- don't require them to be declared this way. A warning is issued
6159 -- to encourage the user to declare them as limited. This is not
6160 -- an error, for compatibility reasons, because these types have
6161 -- been supported this way for some time.
6163 if not Is_Limited_Type (Typ) then
6165 ("imported 'C'P'P type should be " &
6166 "explicitly declared limited?",
6167 Get_Pragma_Arg (Arg1));
6169 ("\type will be considered limited",
6170 Get_Pragma_Arg (Arg1));
6173 Set_Is_CPP_Class (Typ);
6174 Set_Is_Limited_Record (Typ);
6175 Set_Convention (Typ, Convention_CPP);
6178 ---------------------
6179 -- CPP_Constructor --
6180 ---------------------
6182 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6183 -- [, [External_Name =>] static_string_EXPRESSION ]
6184 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6186 when Pragma_CPP_Constructor => CPP_Constructor : declare
6192 Check_At_Least_N_Arguments (1);
6193 Check_At_Most_N_Arguments (3);
6194 Check_Optional_Identifier (Arg1, Name_Entity);
6195 Check_Arg_Is_Local_Name (Arg1);
6197 Id := Expression (Arg1);
6198 Find_Program_Unit_Name (Id);
6200 -- If we did not find the name, we are done
6202 if Etype (Id) = Any_Type then
6206 Def_Id := Entity (Id);
6208 if Ekind (Def_Id) = E_Function
6209 and then Is_Class_Wide_Type (Etype (Def_Id))
6210 and then Is_CPP_Class (Etype (Etype (Def_Id)))
6212 if Arg_Count >= 2 then
6213 Set_Imported (Def_Id);
6214 Set_Is_Public (Def_Id);
6215 Process_Interface_Name (Def_Id, Arg2, Arg3);
6218 if No (Parameter_Specifications (Parent (Def_Id))) then
6219 Set_Has_Completion (Def_Id);
6220 Set_Is_Constructor (Def_Id);
6223 ("non-default constructors not implemented", Arg1);
6228 ("pragma% requires function returning a 'C'P'P_Class type",
6231 end CPP_Constructor;
6237 when Pragma_CPP_Virtual => CPP_Virtual : declare
6241 if Warn_On_Obsolescent_Feature then
6243 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6252 when Pragma_CPP_Vtable => CPP_Vtable : declare
6256 if Warn_On_Obsolescent_Feature then
6258 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6267 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6269 when Pragma_Debug => Debug : declare
6277 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6280 if Arg_Count = 2 then
6283 Left_Opnd => Relocate_Node (Cond),
6284 Right_Opnd => Expression (Arg1));
6287 -- Rewrite into a conditional with an appropriate condition. We
6288 -- wrap the procedure call in a block so that overhead from e.g.
6289 -- use of the secondary stack does not generate execution overhead
6290 -- for suppressed conditions.
6292 Rewrite (N, Make_Implicit_If_Statement (N,
6294 Then_Statements => New_List (
6295 Make_Block_Statement (Loc,
6296 Handled_Statement_Sequence =>
6297 Make_Handled_Sequence_Of_Statements (Loc,
6298 Statements => New_List (
6299 Relocate_Node (Debug_Statement (N))))))));
6307 -- pragma Debug_Policy (Check | Ignore)
6309 when Pragma_Debug_Policy =>
6311 Check_Arg_Count (1);
6312 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6313 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6315 ---------------------
6316 -- Detect_Blocking --
6317 ---------------------
6319 -- pragma Detect_Blocking;
6321 when Pragma_Detect_Blocking =>
6323 Check_Arg_Count (0);
6324 Check_Valid_Configuration_Pragma;
6325 Detect_Blocking := True;
6331 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6333 when Pragma_Discard_Names => Discard_Names : declare
6338 Check_Ada_83_Warning;
6340 -- Deal with configuration pragma case
6342 if Arg_Count = 0 and then Is_Configuration_Pragma then
6343 Global_Discard_Names := True;
6346 -- Otherwise, check correct appropriate context
6349 Check_Is_In_Decl_Part_Or_Package_Spec;
6351 if Arg_Count = 0 then
6353 -- If there is no parameter, then from now on this pragma
6354 -- applies to any enumeration, exception or tagged type
6355 -- defined in the current declarative part, and recursively
6356 -- to any nested scope.
6358 Set_Discard_Names (Current_Scope);
6362 Check_Arg_Count (1);
6363 Check_Optional_Identifier (Arg1, Name_On);
6364 Check_Arg_Is_Local_Name (Arg1);
6366 E_Id := Expression (Arg1);
6368 if Etype (E_Id) = Any_Type then
6374 if (Is_First_Subtype (E)
6376 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6377 or else Ekind (E) = E_Exception
6379 Set_Discard_Names (E);
6382 ("inappropriate entity for pragma%", Arg1);
6393 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6395 when Pragma_Elaborate => Elaborate : declare
6400 -- Pragma must be in context items list of a compilation unit
6402 if not Is_In_Context_Clause then
6406 -- Must be at least one argument
6408 if Arg_Count = 0 then
6409 Error_Pragma ("pragma% requires at least one argument");
6412 -- In Ada 83 mode, there can be no items following it in the
6413 -- context list except other pragmas and implicit with clauses
6414 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6415 -- placement rule does not apply.
6417 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6419 while Present (Citem) loop
6420 if Nkind (Citem) = N_Pragma
6421 or else (Nkind (Citem) = N_With_Clause
6422 and then Implicit_With (Citem))
6427 ("(Ada 83) pragma% must be at end of context clause");
6434 -- Finally, the arguments must all be units mentioned in a with
6435 -- clause in the same context clause. Note we already checked (in
6436 -- Par.Prag) that the arguments are all identifiers or selected
6440 Outer : while Present (Arg) loop
6441 Citem := First (List_Containing (N));
6442 Inner : while Citem /= N loop
6443 if Nkind (Citem) = N_With_Clause
6444 and then Same_Name (Name (Citem), Expression (Arg))
6446 Set_Elaborate_Present (Citem, True);
6447 Set_Unit_Name (Expression (Arg), Name (Citem));
6449 -- With the pragma present, elaboration calls on
6450 -- subprograms from the named unit need no further
6451 -- checks, as long as the pragma appears in the current
6452 -- compilation unit. If the pragma appears in some unit
6453 -- in the context, there might still be a need for an
6454 -- Elaborate_All_Desirable from the current compilation
6455 -- to the named unit, so we keep the check enabled.
6457 if In_Extended_Main_Source_Unit (N) then
6458 Set_Suppress_Elaboration_Warnings
6459 (Entity (Name (Citem)));
6470 ("argument of pragma% is not with'ed unit", Arg);
6476 -- Give a warning if operating in static mode with -gnatwl
6477 -- (elaboration warnings enabled) switch set.
6479 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6481 ("?use of pragma Elaborate may not be safe", N);
6483 ("?use pragma Elaborate_All instead if possible", N);
6491 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6493 when Pragma_Elaborate_All => Elaborate_All : declare
6498 Check_Ada_83_Warning;
6500 -- Pragma must be in context items list of a compilation unit
6502 if not Is_In_Context_Clause then
6506 -- Must be at least one argument
6508 if Arg_Count = 0 then
6509 Error_Pragma ("pragma% requires at least one argument");
6512 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6513 -- have to appear at the end of the context clause, but may
6514 -- appear mixed in with other items, even in Ada 83 mode.
6516 -- Final check: the arguments must all be units mentioned in
6517 -- a with clause in the same context clause. Note that we
6518 -- already checked (in Par.Prag) that all the arguments are
6519 -- either identifiers or selected components.
6522 Outr : while Present (Arg) loop
6523 Citem := First (List_Containing (N));
6524 Innr : while Citem /= N loop
6525 if Nkind (Citem) = N_With_Clause
6526 and then Same_Name (Name (Citem), Expression (Arg))
6528 Set_Elaborate_All_Present (Citem, True);
6529 Set_Unit_Name (Expression (Arg), Name (Citem));
6531 -- Suppress warnings and elaboration checks on the named
6532 -- unit if the pragma is in the current compilation, as
6533 -- for pragma Elaborate.
6535 if In_Extended_Main_Source_Unit (N) then
6536 Set_Suppress_Elaboration_Warnings
6537 (Entity (Name (Citem)));
6546 Set_Error_Posted (N);
6548 ("argument of pragma% is not with'ed unit", Arg);
6555 --------------------
6556 -- Elaborate_Body --
6557 --------------------
6559 -- pragma Elaborate_Body [( library_unit_NAME )];
6561 when Pragma_Elaborate_Body => Elaborate_Body : declare
6562 Cunit_Node : Node_Id;
6563 Cunit_Ent : Entity_Id;
6566 Check_Ada_83_Warning;
6567 Check_Valid_Library_Unit_Pragma;
6569 if Nkind (N) = N_Null_Statement then
6573 Cunit_Node := Cunit (Current_Sem_Unit);
6574 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6576 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6579 Error_Pragma ("pragma% must refer to a spec, not a body");
6581 Set_Body_Required (Cunit_Node, True);
6582 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6584 -- If we are in dynamic elaboration mode, then we suppress
6585 -- elaboration warnings for the unit, since it is definitely
6586 -- fine NOT to do dynamic checks at the first level (and such
6587 -- checks will be suppressed because no elaboration boolean
6588 -- is created for Elaborate_Body packages).
6590 -- But in the static model of elaboration, Elaborate_Body is
6591 -- definitely NOT good enough to ensure elaboration safety on
6592 -- its own, since the body may WITH other units that are not
6593 -- safe from an elaboration point of view, so a client must
6594 -- still do an Elaborate_All on such units.
6596 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6597 -- Elaborate_Body always suppressed elab warnings.
6599 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6600 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6605 ------------------------
6606 -- Elaboration_Checks --
6607 ------------------------
6609 -- pragma Elaboration_Checks (Static | Dynamic);
6611 when Pragma_Elaboration_Checks =>
6613 Check_Arg_Count (1);
6614 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6615 Dynamic_Elaboration_Checks :=
6616 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6622 -- pragma Eliminate (
6623 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6624 -- [,[Entity =>] IDENTIFIER |
6625 -- SELECTED_COMPONENT |
6627 -- [, OVERLOADING_RESOLUTION]);
6629 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6632 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6635 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6637 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6638 -- Result_Type => result_SUBTYPE_NAME]
6640 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6641 -- SUBTYPE_NAME ::= STRING_LITERAL
6643 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6644 -- SOURCE_TRACE ::= STRING_LITERAL
6646 when Pragma_Eliminate => Eliminate : declare
6647 Args : Args_List (1 .. 5);
6648 Names : constant Name_List (1 .. 5) := (
6651 Name_Parameter_Types,
6653 Name_Source_Location);
6655 Unit_Name : Node_Id renames Args (1);
6656 Entity : Node_Id renames Args (2);
6657 Parameter_Types : Node_Id renames Args (3);
6658 Result_Type : Node_Id renames Args (4);
6659 Source_Location : Node_Id renames Args (5);
6663 Check_Valid_Configuration_Pragma;
6664 Gather_Associations (Names, Args);
6666 if No (Unit_Name) then
6667 Error_Pragma ("missing Unit_Name argument for pragma%");
6671 and then (Present (Parameter_Types)
6673 Present (Result_Type)
6675 Present (Source_Location))
6677 Error_Pragma ("missing Entity argument for pragma%");
6680 if (Present (Parameter_Types)
6682 Present (Result_Type))
6684 Present (Source_Location)
6687 ("parameter profile and source location cannot " &
6688 "be used together in pragma%");
6691 Process_Eliminate_Pragma
6705 -- [ Convention =>] convention_IDENTIFIER,
6706 -- [ Entity =>] local_NAME
6707 -- [, [External_Name =>] static_string_EXPRESSION ]
6708 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6710 when Pragma_Export => Export : declare
6714 pragma Warnings (Off, C);
6717 Check_Ada_83_Warning;
6723 Check_At_Least_N_Arguments (2);
6724 Check_At_Most_N_Arguments (4);
6725 Process_Convention (C, Def_Id);
6727 if Ekind (Def_Id) /= E_Constant then
6728 Note_Possible_Modification (Expression (Arg2), Sure => False);
6731 Process_Interface_Name (Def_Id, Arg3, Arg4);
6732 Set_Exported (Def_Id, Arg2);
6734 -- If the entity is a deferred constant, propagate the information
6735 -- to the full view, because gigi elaborates the full view only.
6737 if Ekind (Def_Id) = E_Constant
6738 and then Present (Full_View (Def_Id))
6741 Id2 : constant Entity_Id := Full_View (Def_Id);
6743 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6744 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6745 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6750 ----------------------
6751 -- Export_Exception --
6752 ----------------------
6754 -- pragma Export_Exception (
6755 -- [Internal =>] LOCAL_NAME
6756 -- [, [External =>] EXTERNAL_SYMBOL]
6757 -- [, [Form =>] Ada | VMS]
6758 -- [, [Code =>] static_integer_EXPRESSION]);
6760 when Pragma_Export_Exception => Export_Exception : declare
6761 Args : Args_List (1 .. 4);
6762 Names : constant Name_List (1 .. 4) := (
6768 Internal : Node_Id renames Args (1);
6769 External : Node_Id renames Args (2);
6770 Form : Node_Id renames Args (3);
6771 Code : Node_Id renames Args (4);
6776 if Inside_A_Generic then
6777 Error_Pragma ("pragma% cannot be used for generic entities");
6780 Gather_Associations (Names, Args);
6781 Process_Extended_Import_Export_Exception_Pragma (
6782 Arg_Internal => Internal,
6783 Arg_External => External,
6787 if not Is_VMS_Exception (Entity (Internal)) then
6788 Set_Exported (Entity (Internal), Internal);
6790 end Export_Exception;
6792 ---------------------
6793 -- Export_Function --
6794 ---------------------
6796 -- pragma Export_Function (
6797 -- [Internal =>] LOCAL_NAME
6798 -- [, [External =>] EXTERNAL_SYMBOL]
6799 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6800 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6801 -- [, [Mechanism =>] MECHANISM]
6802 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6804 -- EXTERNAL_SYMBOL ::=
6806 -- | static_string_EXPRESSION
6808 -- PARAMETER_TYPES ::=
6810 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6812 -- TYPE_DESIGNATOR ::=
6814 -- | subtype_Name ' Access
6818 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6820 -- MECHANISM_ASSOCIATION ::=
6821 -- [formal_parameter_NAME =>] MECHANISM_NAME
6823 -- MECHANISM_NAME ::=
6826 -- | Descriptor [([Class =>] CLASS_NAME)]
6828 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6830 when Pragma_Export_Function => Export_Function : declare
6831 Args : Args_List (1 .. 6);
6832 Names : constant Name_List (1 .. 6) := (
6835 Name_Parameter_Types,
6838 Name_Result_Mechanism);
6840 Internal : Node_Id renames Args (1);
6841 External : Node_Id renames Args (2);
6842 Parameter_Types : Node_Id renames Args (3);
6843 Result_Type : Node_Id renames Args (4);
6844 Mechanism : Node_Id renames Args (5);
6845 Result_Mechanism : Node_Id renames Args (6);
6849 Gather_Associations (Names, Args);
6850 Process_Extended_Import_Export_Subprogram_Pragma (
6851 Arg_Internal => Internal,
6852 Arg_External => External,
6853 Arg_Parameter_Types => Parameter_Types,
6854 Arg_Result_Type => Result_Type,
6855 Arg_Mechanism => Mechanism,
6856 Arg_Result_Mechanism => Result_Mechanism);
6857 end Export_Function;
6863 -- pragma Export_Object (
6864 -- [Internal =>] LOCAL_NAME
6865 -- [, [External =>] EXTERNAL_SYMBOL]
6866 -- [, [Size =>] EXTERNAL_SYMBOL]);
6868 -- EXTERNAL_SYMBOL ::=
6870 -- | static_string_EXPRESSION
6872 -- PARAMETER_TYPES ::=
6874 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6876 -- TYPE_DESIGNATOR ::=
6878 -- | subtype_Name ' Access
6882 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6884 -- MECHANISM_ASSOCIATION ::=
6885 -- [formal_parameter_NAME =>] MECHANISM_NAME
6887 -- MECHANISM_NAME ::=
6890 -- | Descriptor [([Class =>] CLASS_NAME)]
6892 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6894 when Pragma_Export_Object => Export_Object : declare
6895 Args : Args_List (1 .. 3);
6896 Names : constant Name_List (1 .. 3) := (
6901 Internal : Node_Id renames Args (1);
6902 External : Node_Id renames Args (2);
6903 Size : Node_Id renames Args (3);
6907 Gather_Associations (Names, Args);
6908 Process_Extended_Import_Export_Object_Pragma (
6909 Arg_Internal => Internal,
6910 Arg_External => External,
6914 ----------------------
6915 -- Export_Procedure --
6916 ----------------------
6918 -- pragma Export_Procedure (
6919 -- [Internal =>] LOCAL_NAME
6920 -- [, [External =>] EXTERNAL_SYMBOL]
6921 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6922 -- [, [Mechanism =>] MECHANISM]);
6924 -- EXTERNAL_SYMBOL ::=
6926 -- | static_string_EXPRESSION
6928 -- PARAMETER_TYPES ::=
6930 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6932 -- TYPE_DESIGNATOR ::=
6934 -- | subtype_Name ' Access
6938 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6940 -- MECHANISM_ASSOCIATION ::=
6941 -- [formal_parameter_NAME =>] MECHANISM_NAME
6943 -- MECHANISM_NAME ::=
6946 -- | Descriptor [([Class =>] CLASS_NAME)]
6948 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6950 when Pragma_Export_Procedure => Export_Procedure : declare
6951 Args : Args_List (1 .. 4);
6952 Names : constant Name_List (1 .. 4) := (
6955 Name_Parameter_Types,
6958 Internal : Node_Id renames Args (1);
6959 External : Node_Id renames Args (2);
6960 Parameter_Types : Node_Id renames Args (3);
6961 Mechanism : Node_Id renames Args (4);
6965 Gather_Associations (Names, Args);
6966 Process_Extended_Import_Export_Subprogram_Pragma (
6967 Arg_Internal => Internal,
6968 Arg_External => External,
6969 Arg_Parameter_Types => Parameter_Types,
6970 Arg_Mechanism => Mechanism);
6971 end Export_Procedure;
6977 -- pragma Export_Value (
6978 -- [Value =>] static_integer_EXPRESSION,
6979 -- [Link_Name =>] static_string_EXPRESSION);
6981 when Pragma_Export_Value =>
6983 Check_Arg_Order ((Name_Value, Name_Link_Name));
6984 Check_Arg_Count (2);
6986 Check_Optional_Identifier (Arg1, Name_Value);
6987 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6989 Check_Optional_Identifier (Arg2, Name_Link_Name);
6990 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6992 -----------------------------
6993 -- Export_Valued_Procedure --
6994 -----------------------------
6996 -- pragma Export_Valued_Procedure (
6997 -- [Internal =>] LOCAL_NAME
6998 -- [, [External =>] EXTERNAL_SYMBOL,]
6999 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7000 -- [, [Mechanism =>] MECHANISM]);
7002 -- EXTERNAL_SYMBOL ::=
7004 -- | static_string_EXPRESSION
7006 -- PARAMETER_TYPES ::=
7008 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7010 -- TYPE_DESIGNATOR ::=
7012 -- | subtype_Name ' Access
7016 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7018 -- MECHANISM_ASSOCIATION ::=
7019 -- [formal_parameter_NAME =>] MECHANISM_NAME
7021 -- MECHANISM_NAME ::=
7024 -- | Descriptor [([Class =>] CLASS_NAME)]
7026 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7028 when Pragma_Export_Valued_Procedure =>
7029 Export_Valued_Procedure : declare
7030 Args : Args_List (1 .. 4);
7031 Names : constant Name_List (1 .. 4) := (
7034 Name_Parameter_Types,
7037 Internal : Node_Id renames Args (1);
7038 External : Node_Id renames Args (2);
7039 Parameter_Types : Node_Id renames Args (3);
7040 Mechanism : Node_Id renames Args (4);
7044 Gather_Associations (Names, Args);
7045 Process_Extended_Import_Export_Subprogram_Pragma (
7046 Arg_Internal => Internal,
7047 Arg_External => External,
7048 Arg_Parameter_Types => Parameter_Types,
7049 Arg_Mechanism => Mechanism);
7050 end Export_Valued_Procedure;
7056 -- pragma Extend_System ([Name =>] Identifier);
7058 when Pragma_Extend_System => Extend_System : declare
7061 Check_Valid_Configuration_Pragma;
7062 Check_Arg_Count (1);
7063 Check_Optional_Identifier (Arg1, Name_Name);
7064 Check_Arg_Is_Identifier (Arg1);
7066 Get_Name_String (Chars (Expression (Arg1)));
7069 and then Name_Buffer (1 .. 4) = "aux_"
7071 if Present (System_Extend_Pragma_Arg) then
7072 if Chars (Expression (Arg1)) =
7073 Chars (Expression (System_Extend_Pragma_Arg))
7077 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7078 Error_Pragma ("pragma% conflicts with that #");
7082 System_Extend_Pragma_Arg := Arg1;
7084 if not GNAT_Mode then
7085 System_Extend_Unit := Arg1;
7089 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7093 ------------------------
7094 -- Extensions_Allowed --
7095 ------------------------
7097 -- pragma Extensions_Allowed (ON | OFF);
7099 when Pragma_Extensions_Allowed =>
7101 Check_Arg_Count (1);
7102 Check_No_Identifiers;
7103 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7105 if Chars (Expression (Arg1)) = Name_On then
7106 Extensions_Allowed := True;
7108 Extensions_Allowed := False;
7115 -- pragma External (
7116 -- [ Convention =>] convention_IDENTIFIER,
7117 -- [ Entity =>] local_NAME
7118 -- [, [External_Name =>] static_string_EXPRESSION ]
7119 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7121 when Pragma_External => External : declare
7125 pragma Warnings (Off, C);
7134 Check_At_Least_N_Arguments (2);
7135 Check_At_Most_N_Arguments (4);
7136 Process_Convention (C, Def_Id);
7137 Note_Possible_Modification (Expression (Arg2), Sure => False);
7138 Process_Interface_Name (Def_Id, Arg3, Arg4);
7139 Set_Exported (Def_Id, Arg2);
7142 --------------------------
7143 -- External_Name_Casing --
7144 --------------------------
7146 -- pragma External_Name_Casing (
7147 -- UPPERCASE | LOWERCASE
7148 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7150 when Pragma_External_Name_Casing => External_Name_Casing : declare
7153 Check_No_Identifiers;
7155 if Arg_Count = 2 then
7157 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7159 case Chars (Get_Pragma_Arg (Arg2)) is
7161 Opt.External_Name_Exp_Casing := As_Is;
7163 when Name_Uppercase =>
7164 Opt.External_Name_Exp_Casing := Uppercase;
7166 when Name_Lowercase =>
7167 Opt.External_Name_Exp_Casing := Lowercase;
7174 Check_Arg_Count (1);
7177 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7179 case Chars (Get_Pragma_Arg (Arg1)) is
7180 when Name_Uppercase =>
7181 Opt.External_Name_Imp_Casing := Uppercase;
7183 when Name_Lowercase =>
7184 Opt.External_Name_Imp_Casing := Lowercase;
7189 end External_Name_Casing;
7191 --------------------------
7192 -- Favor_Top_Level --
7193 --------------------------
7195 -- pragma Favor_Top_Level (type_NAME);
7197 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7198 Named_Entity : Entity_Id;
7202 Check_No_Identifiers;
7203 Check_Arg_Count (1);
7204 Check_Arg_Is_Local_Name (Arg1);
7205 Named_Entity := Entity (Expression (Arg1));
7207 -- If it's an access-to-subprogram type (in particular, not a
7208 -- subtype), set the flag on that type.
7210 if Is_Access_Subprogram_Type (Named_Entity) then
7211 Set_Can_Use_Internal_Rep (Named_Entity, False);
7213 -- Otherwise it's an error (name denotes the wrong sort of entity)
7217 ("access-to-subprogram type expected", Expression (Arg1));
7219 end Favor_Top_Level;
7225 -- pragma Fast_Math;
7227 when Pragma_Fast_Math =>
7229 Check_No_Identifiers;
7230 Check_Valid_Configuration_Pragma;
7233 ---------------------------
7234 -- Finalize_Storage_Only --
7235 ---------------------------
7237 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7239 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7240 Assoc : constant Node_Id := Arg1;
7241 Type_Id : constant Node_Id := Expression (Assoc);
7246 Check_No_Identifiers;
7247 Check_Arg_Count (1);
7248 Check_Arg_Is_Local_Name (Arg1);
7250 Find_Type (Type_Id);
7251 Typ := Entity (Type_Id);
7254 or else Rep_Item_Too_Early (Typ, N)
7258 Typ := Underlying_Type (Typ);
7261 if not Is_Controlled (Typ) then
7262 Error_Pragma ("pragma% must specify controlled type");
7265 Check_First_Subtype (Arg1);
7267 if Finalize_Storage_Only (Typ) then
7268 Error_Pragma ("duplicate pragma%, only one allowed");
7270 elsif not Rep_Item_Too_Late (Typ, N) then
7271 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7273 end Finalize_Storage;
7275 --------------------------
7276 -- Float_Representation --
7277 --------------------------
7279 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7281 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7283 when Pragma_Float_Representation => Float_Representation : declare
7291 if Arg_Count = 1 then
7292 Check_Valid_Configuration_Pragma;
7294 Check_Arg_Count (2);
7295 Check_Optional_Identifier (Arg2, Name_Entity);
7296 Check_Arg_Is_Local_Name (Arg2);
7299 Check_No_Identifier (Arg1);
7300 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7302 if not OpenVMS_On_Target then
7303 if Chars (Expression (Arg1)) = Name_VAX_Float then
7305 ("?pragma% ignored (applies only to Open'V'M'S)");
7311 -- One argument case
7313 if Arg_Count = 1 then
7314 if Chars (Expression (Arg1)) = Name_VAX_Float then
7315 if Opt.Float_Format = 'I' then
7316 Error_Pragma ("'I'E'E'E format previously specified");
7319 Opt.Float_Format := 'V';
7322 if Opt.Float_Format = 'V' then
7323 Error_Pragma ("'V'A'X format previously specified");
7326 Opt.Float_Format := 'I';
7329 Set_Standard_Fpt_Formats;
7331 -- Two argument case
7334 Argx := Get_Pragma_Arg (Arg2);
7336 if not Is_Entity_Name (Argx)
7337 or else not Is_Floating_Point_Type (Entity (Argx))
7340 ("second argument of% pragma must be floating-point type",
7344 Ent := Entity (Argx);
7345 Digs := UI_To_Int (Digits_Value (Ent));
7347 -- Two arguments, VAX_Float case
7349 if Chars (Expression (Arg1)) = Name_VAX_Float then
7351 when 6 => Set_F_Float (Ent);
7352 when 9 => Set_D_Float (Ent);
7353 when 15 => Set_G_Float (Ent);
7357 ("wrong digits value, must be 6,9 or 15", Arg2);
7360 -- Two arguments, IEEE_Float case
7364 when 6 => Set_IEEE_Short (Ent);
7365 when 15 => Set_IEEE_Long (Ent);
7369 ("wrong digits value, must be 6 or 15", Arg2);
7373 end Float_Representation;
7379 -- pragma Ident (static_string_EXPRESSION)
7381 -- Note: pragma Comment shares this processing. Pragma Comment is
7382 -- identical to Ident, except that the restriction of the argument to
7383 -- 31 characters and the placement restrictions are not enforced for
7386 when Pragma_Ident | Pragma_Comment => Ident : declare
7391 Check_Arg_Count (1);
7392 Check_No_Identifiers;
7393 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7395 -- For pragma Ident, preserve DEC compatibility by requiring the
7396 -- pragma to appear in a declarative part or package spec.
7398 if Prag_Id = Pragma_Ident then
7399 Check_Is_In_Decl_Part_Or_Package_Spec;
7402 Str := Expr_Value_S (Expression (Arg1));
7409 GP := Parent (Parent (N));
7411 if Nkind_In (GP, N_Package_Declaration,
7412 N_Generic_Package_Declaration)
7417 -- If we have a compilation unit, then record the ident value,
7418 -- checking for improper duplication.
7420 if Nkind (GP) = N_Compilation_Unit then
7421 CS := Ident_String (Current_Sem_Unit);
7423 if Present (CS) then
7425 -- For Ident, we do not permit multiple instances
7427 if Prag_Id = Pragma_Ident then
7428 Error_Pragma ("duplicate% pragma not permitted");
7430 -- For Comment, we concatenate the string, unless we want
7431 -- to preserve the tree structure for ASIS.
7433 elsif not ASIS_Mode then
7434 Start_String (Strval (CS));
7435 Store_String_Char (' ');
7436 Store_String_Chars (Strval (Str));
7437 Set_Strval (CS, End_String);
7441 -- In VMS, the effect of IDENT is achieved by passing
7442 -- IDENTIFICATION=name as a --for-linker switch.
7444 if OpenVMS_On_Target then
7447 ("--for-linker=IDENTIFICATION=");
7448 String_To_Name_Buffer (Strval (Str));
7449 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7451 -- Only the last processed IDENT is saved. The main
7452 -- purpose is so an IDENT associated with a main
7453 -- procedure will be used in preference to an IDENT
7454 -- associated with a with'd package.
7456 Replace_Linker_Option_String
7457 (End_String, "--for-linker=IDENTIFICATION=");
7460 Set_Ident_String (Current_Sem_Unit, Str);
7463 -- For subunits, we just ignore the Ident, since in GNAT these
7464 -- are not separate object files, and hence not separate units
7465 -- in the unit table.
7467 elsif Nkind (GP) = N_Subunit then
7470 -- Otherwise we have a misplaced pragma Ident, but we ignore
7471 -- this if we are in an instantiation, since it comes from
7472 -- a generic, and has no relevance to the instantiation.
7474 elsif Prag_Id = Pragma_Ident then
7475 if Instantiation_Location (Loc) = No_Location then
7476 Error_Pragma ("pragma% only allowed at outer level");
7482 --------------------------
7483 -- Implemented_By_Entry --
7484 --------------------------
7486 -- pragma Implemented_By_Entry (DIRECT_NAME);
7488 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7493 Check_Arg_Count (1);
7494 Check_No_Identifiers;
7495 Check_Arg_Is_Identifier (Arg1);
7496 Check_Arg_Is_Local_Name (Arg1);
7497 Ent := Entity (Expression (Arg1));
7499 -- Pragma Implemented_By_Entry must be applied only to protected
7500 -- synchronized or task interface primitives.
7502 if (Ekind (Ent) /= E_Function
7503 and then Ekind (Ent) /= E_Procedure)
7504 or else not Present (First_Formal (Ent))
7505 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7508 ("pragma % must be applied to a concurrent interface " &
7512 if Einfo.Implemented_By_Entry (Ent)
7513 and then Warn_On_Redundant_Constructs
7515 Error_Pragma ("?duplicate pragma%!");
7517 Set_Implemented_By_Entry (Ent);
7520 end Implemented_By_Entry;
7522 -----------------------
7523 -- Implicit_Packing --
7524 -----------------------
7526 -- pragma Implicit_Packing;
7528 when Pragma_Implicit_Packing =>
7530 Check_Arg_Count (0);
7531 Implicit_Packing := True;
7538 -- [Convention =>] convention_IDENTIFIER,
7539 -- [Entity =>] local_NAME
7540 -- [, [External_Name =>] static_string_EXPRESSION ]
7541 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7543 when Pragma_Import =>
7544 Check_Ada_83_Warning;
7550 Check_At_Least_N_Arguments (2);
7551 Check_At_Most_N_Arguments (4);
7552 Process_Import_Or_Interface;
7554 ----------------------
7555 -- Import_Exception --
7556 ----------------------
7558 -- pragma Import_Exception (
7559 -- [Internal =>] LOCAL_NAME
7560 -- [, [External =>] EXTERNAL_SYMBOL]
7561 -- [, [Form =>] Ada | VMS]
7562 -- [, [Code =>] static_integer_EXPRESSION]);
7564 when Pragma_Import_Exception => Import_Exception : declare
7565 Args : Args_List (1 .. 4);
7566 Names : constant Name_List (1 .. 4) := (
7572 Internal : Node_Id renames Args (1);
7573 External : Node_Id renames Args (2);
7574 Form : Node_Id renames Args (3);
7575 Code : Node_Id renames Args (4);
7579 Gather_Associations (Names, Args);
7581 if Present (External) and then Present (Code) then
7583 ("cannot give both External and Code options for pragma%");
7586 Process_Extended_Import_Export_Exception_Pragma (
7587 Arg_Internal => Internal,
7588 Arg_External => External,
7592 if not Is_VMS_Exception (Entity (Internal)) then
7593 Set_Imported (Entity (Internal));
7595 end Import_Exception;
7597 ---------------------
7598 -- Import_Function --
7599 ---------------------
7601 -- pragma Import_Function (
7602 -- [Internal =>] LOCAL_NAME,
7603 -- [, [External =>] EXTERNAL_SYMBOL]
7604 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7605 -- [, [Result_Type =>] SUBTYPE_MARK]
7606 -- [, [Mechanism =>] MECHANISM]
7607 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7608 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7610 -- EXTERNAL_SYMBOL ::=
7612 -- | static_string_EXPRESSION
7614 -- PARAMETER_TYPES ::=
7616 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7618 -- TYPE_DESIGNATOR ::=
7620 -- | subtype_Name ' Access
7624 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7626 -- MECHANISM_ASSOCIATION ::=
7627 -- [formal_parameter_NAME =>] MECHANISM_NAME
7629 -- MECHANISM_NAME ::=
7632 -- | Descriptor [([Class =>] CLASS_NAME)]
7634 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7636 when Pragma_Import_Function => Import_Function : declare
7637 Args : Args_List (1 .. 7);
7638 Names : constant Name_List (1 .. 7) := (
7641 Name_Parameter_Types,
7644 Name_Result_Mechanism,
7645 Name_First_Optional_Parameter);
7647 Internal : Node_Id renames Args (1);
7648 External : Node_Id renames Args (2);
7649 Parameter_Types : Node_Id renames Args (3);
7650 Result_Type : Node_Id renames Args (4);
7651 Mechanism : Node_Id renames Args (5);
7652 Result_Mechanism : Node_Id renames Args (6);
7653 First_Optional_Parameter : Node_Id renames Args (7);
7657 Gather_Associations (Names, Args);
7658 Process_Extended_Import_Export_Subprogram_Pragma (
7659 Arg_Internal => Internal,
7660 Arg_External => External,
7661 Arg_Parameter_Types => Parameter_Types,
7662 Arg_Result_Type => Result_Type,
7663 Arg_Mechanism => Mechanism,
7664 Arg_Result_Mechanism => Result_Mechanism,
7665 Arg_First_Optional_Parameter => First_Optional_Parameter);
7666 end Import_Function;
7672 -- pragma Import_Object (
7673 -- [Internal =>] LOCAL_NAME
7674 -- [, [External =>] EXTERNAL_SYMBOL]
7675 -- [, [Size =>] EXTERNAL_SYMBOL]);
7677 -- EXTERNAL_SYMBOL ::=
7679 -- | static_string_EXPRESSION
7681 when Pragma_Import_Object => Import_Object : declare
7682 Args : Args_List (1 .. 3);
7683 Names : constant Name_List (1 .. 3) := (
7688 Internal : Node_Id renames Args (1);
7689 External : Node_Id renames Args (2);
7690 Size : Node_Id renames Args (3);
7694 Gather_Associations (Names, Args);
7695 Process_Extended_Import_Export_Object_Pragma (
7696 Arg_Internal => Internal,
7697 Arg_External => External,
7701 ----------------------
7702 -- Import_Procedure --
7703 ----------------------
7705 -- pragma Import_Procedure (
7706 -- [Internal =>] LOCAL_NAME
7707 -- [, [External =>] EXTERNAL_SYMBOL]
7708 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7709 -- [, [Mechanism =>] MECHANISM]
7710 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7712 -- EXTERNAL_SYMBOL ::=
7714 -- | static_string_EXPRESSION
7716 -- PARAMETER_TYPES ::=
7718 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7720 -- TYPE_DESIGNATOR ::=
7722 -- | subtype_Name ' Access
7726 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7728 -- MECHANISM_ASSOCIATION ::=
7729 -- [formal_parameter_NAME =>] MECHANISM_NAME
7731 -- MECHANISM_NAME ::=
7734 -- | Descriptor [([Class =>] CLASS_NAME)]
7736 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7738 when Pragma_Import_Procedure => Import_Procedure : declare
7739 Args : Args_List (1 .. 5);
7740 Names : constant Name_List (1 .. 5) := (
7743 Name_Parameter_Types,
7745 Name_First_Optional_Parameter);
7747 Internal : Node_Id renames Args (1);
7748 External : Node_Id renames Args (2);
7749 Parameter_Types : Node_Id renames Args (3);
7750 Mechanism : Node_Id renames Args (4);
7751 First_Optional_Parameter : Node_Id renames Args (5);
7755 Gather_Associations (Names, Args);
7756 Process_Extended_Import_Export_Subprogram_Pragma (
7757 Arg_Internal => Internal,
7758 Arg_External => External,
7759 Arg_Parameter_Types => Parameter_Types,
7760 Arg_Mechanism => Mechanism,
7761 Arg_First_Optional_Parameter => First_Optional_Parameter);
7762 end Import_Procedure;
7764 -----------------------------
7765 -- Import_Valued_Procedure --
7766 -----------------------------
7768 -- pragma Import_Valued_Procedure (
7769 -- [Internal =>] LOCAL_NAME
7770 -- [, [External =>] EXTERNAL_SYMBOL]
7771 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7772 -- [, [Mechanism =>] MECHANISM]
7773 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7775 -- EXTERNAL_SYMBOL ::=
7777 -- | static_string_EXPRESSION
7779 -- PARAMETER_TYPES ::=
7781 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7783 -- TYPE_DESIGNATOR ::=
7785 -- | subtype_Name ' Access
7789 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7791 -- MECHANISM_ASSOCIATION ::=
7792 -- [formal_parameter_NAME =>] MECHANISM_NAME
7794 -- MECHANISM_NAME ::=
7797 -- | Descriptor [([Class =>] CLASS_NAME)]
7799 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7801 when Pragma_Import_Valued_Procedure =>
7802 Import_Valued_Procedure : declare
7803 Args : Args_List (1 .. 5);
7804 Names : constant Name_List (1 .. 5) := (
7807 Name_Parameter_Types,
7809 Name_First_Optional_Parameter);
7811 Internal : Node_Id renames Args (1);
7812 External : Node_Id renames Args (2);
7813 Parameter_Types : Node_Id renames Args (3);
7814 Mechanism : Node_Id renames Args (4);
7815 First_Optional_Parameter : Node_Id renames Args (5);
7819 Gather_Associations (Names, Args);
7820 Process_Extended_Import_Export_Subprogram_Pragma (
7821 Arg_Internal => Internal,
7822 Arg_External => External,
7823 Arg_Parameter_Types => Parameter_Types,
7824 Arg_Mechanism => Mechanism,
7825 Arg_First_Optional_Parameter => First_Optional_Parameter);
7826 end Import_Valued_Procedure;
7828 ------------------------
7829 -- Initialize_Scalars --
7830 ------------------------
7832 -- pragma Initialize_Scalars;
7834 when Pragma_Initialize_Scalars =>
7836 Check_Arg_Count (0);
7837 Check_Valid_Configuration_Pragma;
7838 Check_Restriction (No_Initialize_Scalars, N);
7840 if not Restriction_Active (No_Initialize_Scalars) then
7841 Init_Or_Norm_Scalars := True;
7842 Initialize_Scalars := True;
7849 -- pragma Inline ( NAME {, NAME} );
7851 when Pragma_Inline =>
7853 -- Pragma is active if inlining option is active
7855 Process_Inline (Inline_Active);
7861 -- pragma Inline_Always ( NAME {, NAME} );
7863 when Pragma_Inline_Always =>
7865 Process_Inline (True);
7867 --------------------
7868 -- Inline_Generic --
7869 --------------------
7871 -- pragma Inline_Generic (NAME {, NAME});
7873 when Pragma_Inline_Generic =>
7875 Process_Generic_List;
7877 ----------------------
7878 -- Inspection_Point --
7879 ----------------------
7881 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7883 when Pragma_Inspection_Point => Inspection_Point : declare
7888 if Arg_Count > 0 then
7891 Exp := Expression (Arg);
7894 if not Is_Entity_Name (Exp)
7895 or else not Is_Object (Entity (Exp))
7897 Error_Pragma_Arg ("object name required", Arg);
7904 end Inspection_Point;
7910 -- pragma Interface (
7911 -- [ Convention =>] convention_IDENTIFIER,
7912 -- [ Entity =>] local_NAME
7913 -- [, [External_Name =>] static_string_EXPRESSION ]
7914 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7916 when Pragma_Interface =>
7923 Check_At_Least_N_Arguments (2);
7924 Check_At_Most_N_Arguments (4);
7925 Process_Import_Or_Interface;
7927 --------------------
7928 -- Interface_Name --
7929 --------------------
7931 -- pragma Interface_Name (
7932 -- [ Entity =>] local_NAME
7933 -- [,[External_Name =>] static_string_EXPRESSION ]
7934 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7936 when Pragma_Interface_Name => Interface_Name : declare
7945 ((Name_Entity, Name_External_Name, Name_Link_Name));
7946 Check_At_Least_N_Arguments (2);
7947 Check_At_Most_N_Arguments (3);
7948 Id := Expression (Arg1);
7951 if not Is_Entity_Name (Id) then
7953 ("first argument for pragma% must be entity name", Arg1);
7954 elsif Etype (Id) = Any_Type then
7957 Def_Id := Entity (Id);
7960 -- Special DEC-compatible processing for the object case, forces
7961 -- object to be imported.
7963 if Ekind (Def_Id) = E_Variable then
7964 Kill_Size_Check_Code (Def_Id);
7965 Note_Possible_Modification (Id, Sure => False);
7967 -- Initialization is not allowed for imported variable
7969 if Present (Expression (Parent (Def_Id)))
7970 and then Comes_From_Source (Expression (Parent (Def_Id)))
7972 Error_Msg_Sloc := Sloc (Def_Id);
7974 ("no initialization allowed for declaration of& #",
7978 -- For compatibility, support VADS usage of providing both
7979 -- pragmas Interface and Interface_Name to obtain the effect
7980 -- of a single Import pragma.
7982 if Is_Imported (Def_Id)
7983 and then Present (First_Rep_Item (Def_Id))
7984 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7986 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
7990 Set_Imported (Def_Id);
7993 Set_Is_Public (Def_Id);
7994 Process_Interface_Name (Def_Id, Arg2, Arg3);
7997 -- Otherwise must be subprogram
7999 elsif not Is_Subprogram (Def_Id) then
8001 ("argument of pragma% is not subprogram", Arg1);
8004 Check_At_Most_N_Arguments (3);
8008 -- Loop through homonyms
8011 Def_Id := Get_Base_Subprogram (Hom_Id);
8013 if Is_Imported (Def_Id) then
8014 Process_Interface_Name (Def_Id, Arg2, Arg3);
8018 Hom_Id := Homonym (Hom_Id);
8020 exit when No (Hom_Id)
8021 or else Scope (Hom_Id) /= Current_Scope;
8026 ("argument of pragma% is not imported subprogram",
8032 -----------------------
8033 -- Interrupt_Handler --
8034 -----------------------
8036 -- pragma Interrupt_Handler (handler_NAME);
8038 when Pragma_Interrupt_Handler =>
8039 Check_Ada_83_Warning;
8040 Check_Arg_Count (1);
8041 Check_No_Identifiers;
8043 if No_Run_Time_Mode then
8044 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8046 Check_Interrupt_Or_Attach_Handler;
8047 Process_Interrupt_Or_Attach_Handler;
8050 ------------------------
8051 -- Interrupt_Priority --
8052 ------------------------
8054 -- pragma Interrupt_Priority [(EXPRESSION)];
8056 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8057 P : constant Node_Id := Parent (N);
8061 Check_Ada_83_Warning;
8063 if Arg_Count /= 0 then
8064 Arg := Expression (Arg1);
8065 Check_Arg_Count (1);
8066 Check_No_Identifiers;
8068 -- The expression must be analyzed in the special manner
8069 -- described in "Handling of Default and Per-Object
8070 -- Expressions" in sem.ads.
8072 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8075 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8079 elsif Has_Priority_Pragma (P) then
8080 Error_Pragma ("duplicate pragma% not allowed");
8083 Set_Has_Priority_Pragma (P, True);
8084 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8086 end Interrupt_Priority;
8088 ---------------------
8089 -- Interrupt_State --
8090 ---------------------
8092 -- pragma Interrupt_State (
8093 -- [Name =>] INTERRUPT_ID,
8094 -- [State =>] INTERRUPT_STATE);
8096 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8097 -- INTERRUPT_STATE => System | Runtime | User
8099 -- Note: if the interrupt id is given as an identifier, then it must
8100 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8101 -- given as a static integer expression which must be in the range of
8102 -- Ada.Interrupts.Interrupt_ID.
8104 when Pragma_Interrupt_State => Interrupt_State : declare
8106 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8107 -- This is the entity Ada.Interrupts.Interrupt_ID;
8109 State_Type : Character;
8110 -- Set to 's'/'r'/'u' for System/Runtime/User
8113 -- Index to entry in Interrupt_States table
8116 -- Value of interrupt
8118 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8119 -- The first argument to the pragma
8121 Int_Ent : Entity_Id;
8122 -- Interrupt entity in Ada.Interrupts.Names
8126 Check_Arg_Order ((Name_Name, Name_State));
8127 Check_Arg_Count (2);
8129 Check_Optional_Identifier (Arg1, Name_Name);
8130 Check_Optional_Identifier (Arg2, Name_State);
8131 Check_Arg_Is_Identifier (Arg2);
8133 -- First argument is identifier
8135 if Nkind (Arg1X) = N_Identifier then
8137 -- Search list of names in Ada.Interrupts.Names
8139 Int_Ent := First_Entity (RTE (RE_Names));
8141 if No (Int_Ent) then
8142 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8144 elsif Chars (Int_Ent) = Chars (Arg1X) then
8145 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8149 Next_Entity (Int_Ent);
8152 -- First argument is not an identifier, so it must be a static
8153 -- expression of type Ada.Interrupts.Interrupt_ID.
8156 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8157 Int_Val := Expr_Value (Arg1X);
8159 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8161 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8164 ("value not in range of type " &
8165 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8171 case Chars (Get_Pragma_Arg (Arg2)) is
8172 when Name_Runtime => State_Type := 'r';
8173 when Name_System => State_Type := 's';
8174 when Name_User => State_Type := 'u';
8177 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8180 -- Check if entry is already stored
8182 IST_Num := Interrupt_States.First;
8184 -- If entry not found, add it
8186 if IST_Num > Interrupt_States.Last then
8187 Interrupt_States.Append
8188 ((Interrupt_Number => UI_To_Int (Int_Val),
8189 Interrupt_State => State_Type,
8190 Pragma_Loc => Loc));
8193 -- Case of entry for the same entry
8195 elsif Int_Val = Interrupt_States.Table (IST_Num).
8198 -- If state matches, done, no need to make redundant entry
8201 State_Type = Interrupt_States.Table (IST_Num).
8204 -- Otherwise if state does not match, error
8207 Interrupt_States.Table (IST_Num).Pragma_Loc;
8209 ("state conflicts with that given #", Arg2);
8213 IST_Num := IST_Num + 1;
8215 end Interrupt_State;
8217 ----------------------
8218 -- Java_Constructor --
8219 ----------------------
8221 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8223 -- Also handles pragma CIL_Constructor
8225 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8226 Java_Constructor : declare
8230 Convention : Convention_Id;
8234 Check_Arg_Count (1);
8235 Check_Optional_Identifier (Arg1, Name_Entity);
8236 Check_Arg_Is_Local_Name (Arg1);
8238 Id := Expression (Arg1);
8239 Find_Program_Unit_Name (Id);
8241 -- If we did not find the name, we are done
8243 if Etype (Id) = Any_Type then
8248 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8249 when Pragma_Java_Constructor => Convention := Convention_Java;
8250 when others => null;
8253 Hom_Id := Entity (Id);
8255 -- Loop through homonyms
8258 Def_Id := Get_Base_Subprogram (Hom_Id);
8260 -- The constructor is required to be a function returning an
8261 -- access type whose designated type has convention Java/CIL.
8263 if Ekind (Def_Id) = E_Function
8265 (Is_Value_Type (Etype (Def_Id))
8267 (Ekind (Etype (Def_Id)) in Access_Kind
8270 (Designated_Type (Etype (Def_Id))) = Convention
8273 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8276 Set_Is_Constructor (Def_Id);
8277 Set_Convention (Def_Id, Convention);
8278 Set_Is_Imported (Def_Id);
8281 if Convention = Convention_Java then
8283 ("pragma% requires function returning a " &
8284 "'Java access type", Arg1);
8286 pragma Assert (Convention = Convention_CIL);
8288 ("pragma% requires function returning a " &
8289 "'CIL access type", Arg1);
8293 Hom_Id := Homonym (Hom_Id);
8295 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8297 end Java_Constructor;
8299 ----------------------
8300 -- Java_Interface --
8301 ----------------------
8303 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8305 when Pragma_Java_Interface => Java_Interface : declare
8311 Check_Arg_Count (1);
8312 Check_Optional_Identifier (Arg1, Name_Entity);
8313 Check_Arg_Is_Local_Name (Arg1);
8315 Arg := Expression (Arg1);
8318 if Etype (Arg) = Any_Type then
8322 if not Is_Entity_Name (Arg)
8323 or else not Is_Type (Entity (Arg))
8325 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8328 Typ := Underlying_Type (Entity (Arg));
8330 -- For now simply check some of the semantic constraints on the
8331 -- type. This currently leaves out some restrictions on interface
8332 -- types, namely that the parent type must be java.lang.Object.Typ
8333 -- and that all primitives of the type should be declared
8336 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8337 Error_Pragma_Arg ("pragma% requires an abstract "
8338 & "tagged type", Arg1);
8340 elsif not Has_Discriminants (Typ)
8341 or else Ekind (Etype (First_Discriminant (Typ)))
8342 /= E_Anonymous_Access_Type
8344 not Is_Class_Wide_Type
8345 (Designated_Type (Etype (First_Discriminant (Typ))))
8348 ("type must have a class-wide access discriminant", Arg1);
8356 -- pragma Keep_Names ([On => ] local_NAME);
8358 when Pragma_Keep_Names => Keep_Names : declare
8363 Check_Arg_Count (1);
8364 Check_Optional_Identifier (Arg1, Name_On);
8365 Check_Arg_Is_Local_Name (Arg1);
8367 Arg := Expression (Arg1);
8370 if Etype (Arg) = Any_Type then
8374 if not Is_Entity_Name (Arg)
8375 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8378 ("pragma% requires a local enumeration type", Arg1);
8381 Set_Discard_Names (Entity (Arg), False);
8388 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8390 when Pragma_License =>
8392 Check_Arg_Count (1);
8393 Check_No_Identifiers;
8394 Check_Valid_Configuration_Pragma;
8395 Check_Arg_Is_Identifier (Arg1);
8398 Sind : constant Source_File_Index :=
8399 Source_Index (Current_Sem_Unit);
8402 case Chars (Get_Pragma_Arg (Arg1)) is
8404 Set_License (Sind, GPL);
8406 when Name_Modified_GPL =>
8407 Set_License (Sind, Modified_GPL);
8409 when Name_Restricted =>
8410 Set_License (Sind, Restricted);
8412 when Name_Unrestricted =>
8413 Set_License (Sind, Unrestricted);
8416 Error_Pragma_Arg ("invalid license name", Arg1);
8424 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8426 when Pragma_Link_With => Link_With : declare
8432 if Operating_Mode = Generate_Code
8433 and then In_Extended_Main_Source_Unit (N)
8435 Check_At_Least_N_Arguments (1);
8436 Check_No_Identifiers;
8437 Check_Is_In_Decl_Part_Or_Package_Spec;
8438 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8442 while Present (Arg) loop
8443 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8445 -- Store argument, converting sequences of spaces to a
8446 -- single null character (this is one of the differences
8447 -- in processing between Link_With and Linker_Options).
8450 C : constant Char_Code := Get_Char_Code (' ');
8451 S : constant String_Id :=
8452 Strval (Expr_Value_S (Expression (Arg)));
8453 L : constant Nat := String_Length (S);
8456 procedure Skip_Spaces;
8457 -- Advance F past any spaces
8463 procedure Skip_Spaces is
8465 while F <= L and then Get_String_Char (S, F) = C loop
8470 -- Start of processing for Arg_Store
8473 Skip_Spaces; -- skip leading spaces
8475 -- Loop through characters, changing any embedded
8476 -- sequence of spaces to a single null character (this
8477 -- is how Link_With/Linker_Options differ)
8480 if Get_String_Char (S, F) = C then
8483 Store_String_Char (ASCII.NUL);
8486 Store_String_Char (Get_String_Char (S, F));
8494 if Present (Arg) then
8495 Store_String_Char (ASCII.NUL);
8499 Store_Linker_Option_String (End_String);
8507 -- pragma Linker_Alias (
8508 -- [Entity =>] LOCAL_NAME
8509 -- [Target =>] static_string_EXPRESSION);
8511 when Pragma_Linker_Alias =>
8513 Check_Arg_Order ((Name_Entity, Name_Target));
8514 Check_Arg_Count (2);
8515 Check_Optional_Identifier (Arg1, Name_Entity);
8516 Check_Optional_Identifier (Arg2, Name_Target);
8517 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8518 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8520 -- The only processing required is to link this item on to the
8521 -- list of rep items for the given entity. This is accomplished
8522 -- by the call to Rep_Item_Too_Late (when no error is detected
8523 -- and False is returned).
8525 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8528 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8531 ------------------------
8532 -- Linker_Constructor --
8533 ------------------------
8535 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8537 -- Code is shared with Linker_Destructor
8539 -----------------------
8540 -- Linker_Destructor --
8541 -----------------------
8543 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8545 when Pragma_Linker_Constructor |
8546 Pragma_Linker_Destructor =>
8547 Linker_Constructor : declare
8553 Check_Arg_Count (1);
8554 Check_No_Identifiers;
8555 Check_Arg_Is_Local_Name (Arg1);
8556 Arg1_X := Expression (Arg1);
8558 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8560 if not Is_Library_Level_Entity (Proc) then
8562 ("argument for pragma% must be library level entity", Arg1);
8565 -- The only processing required is to link this item on to the
8566 -- list of rep items for the given entity. This is accomplished
8567 -- by the call to Rep_Item_Too_Late (when no error is detected
8568 -- and False is returned).
8570 if Rep_Item_Too_Late (Proc, N) then
8573 Set_Has_Gigi_Rep_Item (Proc);
8575 end Linker_Constructor;
8577 --------------------
8578 -- Linker_Options --
8579 --------------------
8581 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8583 when Pragma_Linker_Options => Linker_Options : declare
8587 Check_Ada_83_Warning;
8588 Check_No_Identifiers;
8589 Check_Arg_Count (1);
8590 Check_Is_In_Decl_Part_Or_Package_Spec;
8591 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8592 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8595 while Present (Arg) loop
8596 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8597 Store_String_Char (ASCII.NUL);
8598 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8602 if Operating_Mode = Generate_Code
8603 and then In_Extended_Main_Source_Unit (N)
8605 Store_Linker_Option_String (End_String);
8609 --------------------
8610 -- Linker_Section --
8611 --------------------
8613 -- pragma Linker_Section (
8614 -- [Entity =>] LOCAL_NAME
8615 -- [Section =>] static_string_EXPRESSION);
8617 when Pragma_Linker_Section =>
8619 Check_Arg_Order ((Name_Entity, Name_Section));
8620 Check_Arg_Count (2);
8621 Check_Optional_Identifier (Arg1, Name_Entity);
8622 Check_Optional_Identifier (Arg2, Name_Section);
8623 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8624 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8626 -- This pragma applies only to objects
8628 if not Is_Object (Entity (Expression (Arg1))) then
8629 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8632 -- The only processing required is to link this item on to the
8633 -- list of rep items for the given entity. This is accomplished
8634 -- by the call to Rep_Item_Too_Late (when no error is detected
8635 -- and False is returned).
8637 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8640 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8647 -- pragma List (On | Off)
8649 -- There is nothing to do here, since we did all the processing for
8650 -- this pragma in Par.Prag (so that it works properly even in syntax
8656 --------------------
8657 -- Locking_Policy --
8658 --------------------
8660 -- pragma Locking_Policy (policy_IDENTIFIER);
8662 when Pragma_Locking_Policy => declare
8666 Check_Ada_83_Warning;
8667 Check_Arg_Count (1);
8668 Check_No_Identifiers;
8669 Check_Arg_Is_Locking_Policy (Arg1);
8670 Check_Valid_Configuration_Pragma;
8671 Get_Name_String (Chars (Expression (Arg1)));
8672 LP := Fold_Upper (Name_Buffer (1));
8674 if Locking_Policy /= ' '
8675 and then Locking_Policy /= LP
8677 Error_Msg_Sloc := Locking_Policy_Sloc;
8678 Error_Pragma ("locking policy incompatible with policy#");
8680 -- Set new policy, but always preserve System_Location since we
8681 -- like the error message with the run time name.
8684 Locking_Policy := LP;
8686 if Locking_Policy_Sloc /= System_Location then
8687 Locking_Policy_Sloc := Loc;
8696 -- pragma Long_Float (D_Float | G_Float);
8698 when Pragma_Long_Float =>
8700 Check_Valid_Configuration_Pragma;
8701 Check_Arg_Count (1);
8702 Check_No_Identifier (Arg1);
8703 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8705 if not OpenVMS_On_Target then
8706 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8711 if Chars (Expression (Arg1)) = Name_D_Float then
8712 if Opt.Float_Format_Long = 'G' then
8713 Error_Pragma ("G_Float previously specified");
8716 Opt.Float_Format_Long := 'D';
8718 -- G_Float case (this is the default, does not need overriding)
8721 if Opt.Float_Format_Long = 'D' then
8722 Error_Pragma ("D_Float previously specified");
8725 Opt.Float_Format_Long := 'G';
8728 Set_Standard_Fpt_Formats;
8730 -----------------------
8731 -- Machine_Attribute --
8732 -----------------------
8734 -- pragma Machine_Attribute (
8735 -- [Entity =>] LOCAL_NAME,
8736 -- [Attribute_Name =>] static_string_EXPRESSION
8737 -- [, [Info =>] static_string_EXPRESSION] );
8739 when Pragma_Machine_Attribute => Machine_Attribute : declare
8744 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8746 if Arg_Count = 3 then
8747 Check_Optional_Identifier (Arg3, Name_Info);
8748 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
8750 Check_Arg_Count (2);
8753 Check_Optional_Identifier (Arg1, Name_Entity);
8754 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8755 Check_Arg_Is_Local_Name (Arg1);
8756 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8757 Def_Id := Entity (Expression (Arg1));
8759 if Is_Access_Type (Def_Id) then
8760 Def_Id := Designated_Type (Def_Id);
8763 if Rep_Item_Too_Early (Def_Id, N) then
8767 Def_Id := Underlying_Type (Def_Id);
8769 -- The only processing required is to link this item on to the
8770 -- list of rep items for the given entity. This is accomplished
8771 -- by the call to Rep_Item_Too_Late (when no error is detected
8772 -- and False is returned).
8774 if Rep_Item_Too_Late (Def_Id, N) then
8777 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8779 end Machine_Attribute;
8786 -- (MAIN_OPTION [, MAIN_OPTION]);
8789 -- [STACK_SIZE =>] static_integer_EXPRESSION
8790 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8791 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8793 when Pragma_Main => Main : declare
8794 Args : Args_List (1 .. 3);
8795 Names : constant Name_List (1 .. 3) := (
8797 Name_Task_Stack_Size_Default,
8798 Name_Time_Slicing_Enabled);
8804 Gather_Associations (Names, Args);
8806 for J in 1 .. 2 loop
8807 if Present (Args (J)) then
8808 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8812 if Present (Args (3)) then
8813 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8817 while Present (Nod) loop
8818 if Nkind (Nod) = N_Pragma
8819 and then Pragma_Name (Nod) = Name_Main
8821 Error_Msg_Name_1 := Pname;
8822 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8833 -- pragma Main_Storage
8834 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8836 -- MAIN_STORAGE_OPTION ::=
8837 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8838 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8840 when Pragma_Main_Storage => Main_Storage : declare
8841 Args : Args_List (1 .. 2);
8842 Names : constant Name_List (1 .. 2) := (
8843 Name_Working_Storage,
8850 Gather_Associations (Names, Args);
8852 for J in 1 .. 2 loop
8853 if Present (Args (J)) then
8854 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8858 Check_In_Main_Program;
8861 while Present (Nod) loop
8862 if Nkind (Nod) = N_Pragma
8863 and then Pragma_Name (Nod) = Name_Main_Storage
8865 Error_Msg_Name_1 := Pname;
8866 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8877 -- pragma Memory_Size (NUMERIC_LITERAL)
8879 when Pragma_Memory_Size =>
8882 -- Memory size is simply ignored
8884 Check_No_Identifiers;
8885 Check_Arg_Count (1);
8886 Check_Arg_Is_Integer_Literal (Arg1);
8894 -- The only correct use of this pragma is on its own in a file, in
8895 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
8896 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
8897 -- check for a file containing nothing but a No_Body pragma). If we
8898 -- attempt to process it during normal semantics processing, it means
8899 -- it was misplaced.
8901 when Pragma_No_Body =>
8909 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8911 when Pragma_No_Return => No_Return : declare
8919 Check_At_Least_N_Arguments (1);
8921 -- Loop through arguments of pragma
8924 while Present (Arg) loop
8925 Check_Arg_Is_Local_Name (Arg);
8926 Id := Expression (Arg);
8929 if not Is_Entity_Name (Id) then
8930 Error_Pragma_Arg ("entity name required", Arg);
8933 if Etype (Id) = Any_Type then
8937 -- Loop to find matching procedures
8942 and then Scope (E) = Current_Scope
8944 if Ekind (E) = E_Procedure
8945 or else Ekind (E) = E_Generic_Procedure
8949 -- Set flag on any alias as well
8951 if Is_Overloadable (E) and then Present (Alias (E)) then
8952 Set_No_Return (Alias (E));
8962 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
8973 -- pragma No_Run_Time;
8975 -- Note: this pragma is retained for backwards compatibility. See
8976 -- body of Rtsfind for full details on its handling.
8978 when Pragma_No_Run_Time =>
8980 Check_Valid_Configuration_Pragma;
8981 Check_Arg_Count (0);
8983 No_Run_Time_Mode := True;
8984 Configurable_Run_Time_Mode := True;
8986 -- Set Duration to 32 bits if word size is 32
8988 if Ttypes.System_Word_Size = 32 then
8989 Duration_32_Bits_On_Target := True;
8992 -- Set appropriate restrictions
8994 Set_Restriction (No_Finalization, N);
8995 Set_Restriction (No_Exception_Handlers, N);
8996 Set_Restriction (Max_Tasks, N, 0);
8997 Set_Restriction (No_Tasking, N);
8999 ------------------------
9000 -- No_Strict_Aliasing --
9001 ------------------------
9003 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9005 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9010 Check_At_Most_N_Arguments (1);
9012 if Arg_Count = 0 then
9013 Check_Valid_Configuration_Pragma;
9014 Opt.No_Strict_Aliasing := True;
9017 Check_Optional_Identifier (Arg2, Name_Entity);
9018 Check_Arg_Is_Local_Name (Arg1);
9019 E_Id := Entity (Expression (Arg1));
9021 if E_Id = Any_Type then
9023 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9024 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9027 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9029 end No_Strict_Aliasing;
9031 -----------------------
9032 -- Normalize_Scalars --
9033 -----------------------
9035 -- pragma Normalize_Scalars;
9037 when Pragma_Normalize_Scalars =>
9038 Check_Ada_83_Warning;
9039 Check_Arg_Count (0);
9040 Check_Valid_Configuration_Pragma;
9041 Normalize_Scalars := True;
9042 Init_Or_Norm_Scalars := True;
9048 -- pragma Obsolescent;
9050 -- pragma Obsolescent (
9051 -- [Message =>] static_string_EXPRESSION
9052 -- [,[Version =>] Ada_05]]);
9054 -- pragma Obsolescent (
9056 -- [,[Message =>] static_string_EXPRESSION
9057 -- [,[Version =>] Ada_05]] );
9059 when Pragma_Obsolescent => Obsolescent : declare
9063 procedure Set_Obsolescent (E : Entity_Id);
9064 -- Given an entity Ent, mark it as obsolescent if appropriate
9066 ---------------------
9067 -- Set_Obsolescent --
9068 ---------------------
9070 procedure Set_Obsolescent (E : Entity_Id) is
9079 -- Entity name was given
9081 if Present (Ename) then
9083 -- If entity name matches, we are fine. Save entity in
9084 -- pragma argument, for ASIS use.
9086 if Chars (Ename) = Chars (Ent) then
9087 Set_Entity (Ename, Ent);
9088 Generate_Reference (Ent, Ename);
9090 -- If entity name does not match, only possibility is an
9091 -- enumeration literal from an enumeration type declaration.
9093 elsif Ekind (Ent) /= E_Enumeration_Type then
9095 ("pragma % entity name does not match declaration");
9098 Ent := First_Literal (E);
9102 ("pragma % entity name does not match any " &
9103 "enumeration literal");
9105 elsif Chars (Ent) = Chars (Ename) then
9106 Set_Entity (Ename, Ent);
9107 Generate_Reference (Ent, Ename);
9111 Ent := Next_Literal (Ent);
9117 -- Ent points to entity to be marked
9119 if Arg_Count >= 1 then
9121 -- Deal with static string argument
9123 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9124 S := Strval (Expression (Arg1));
9126 for J in 1 .. String_Length (S) loop
9127 if not In_Character_Range (Get_String_Char (S, J)) then
9129 ("pragma% argument does not allow wide characters",
9134 Obsolescent_Warnings.Append
9135 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9137 -- Check for Ada_05 parameter
9139 if Arg_Count /= 1 then
9140 Check_Arg_Count (2);
9143 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9146 Check_Arg_Is_Identifier (Argx);
9148 if Chars (Argx) /= Name_Ada_05 then
9149 Error_Msg_Name_2 := Name_Ada_05;
9151 ("only allowed argument for pragma% is %", Argx);
9154 if Ada_Version_Explicit < Ada_05
9155 or else not Warn_On_Ada_2005_Compatibility
9163 -- Set flag if pragma active
9166 Set_Is_Obsolescent (Ent);
9170 end Set_Obsolescent;
9172 -- Start of processing for pragma Obsolescent
9177 Check_At_Most_N_Arguments (3);
9179 -- See if first argument specifies an entity name
9183 (Chars (Arg1) = Name_Entity
9185 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9189 Ename := Get_Pragma_Arg (Arg1);
9191 -- Eliminate first argument, so we can share processing
9195 Arg_Count := Arg_Count - 1;
9197 -- No Entity name argument given
9203 if Arg_Count >= 1 then
9204 Check_Optional_Identifier (Arg1, Name_Message);
9206 if Arg_Count = 2 then
9207 Check_Optional_Identifier (Arg2, Name_Version);
9211 -- Get immediately preceding declaration
9214 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9218 -- Cases where we do not follow anything other than another pragma
9222 -- First case: library level compilation unit declaration with
9223 -- the pragma immediately following the declaration.
9225 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9227 (Defining_Entity (Unit (Parent (Parent (N)))));
9230 -- Case 2: library unit placement for package
9234 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9236 if Is_Package_Or_Generic_Package (Ent) then
9237 Set_Obsolescent (Ent);
9243 -- Cases where we must follow a declaration
9246 if Nkind (Decl) not in N_Declaration
9247 and then Nkind (Decl) not in N_Later_Decl_Item
9248 and then Nkind (Decl) not in N_Generic_Declaration
9251 ("pragma% misplaced, "
9252 & "must immediately follow a declaration");
9255 Set_Obsolescent (Defining_Entity (Decl));
9265 -- pragma Optimize (Time | Space | Off);
9267 -- The actual check for optimize is done in Gigi. Note that this
9268 -- pragma does not actually change the optimization setting, it
9269 -- simply checks that it is consistent with the pragma.
9271 when Pragma_Optimize =>
9272 Check_No_Identifiers;
9273 Check_Arg_Count (1);
9274 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9276 ------------------------
9277 -- Optimize_Alignment --
9278 ------------------------
9280 -- pragma Optimize_Alignment (Time | Space | Off);
9282 when Pragma_Optimize_Alignment =>
9284 Check_No_Identifiers;
9285 Check_Arg_Count (1);
9286 Check_Valid_Configuration_Pragma;
9289 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9293 Opt.Optimize_Alignment := 'T';
9295 Opt.Optimize_Alignment := 'S';
9297 Opt.Optimize_Alignment := 'O';
9299 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9303 -- Set indication that mode is set locally. If we are in fact in a
9304 -- configuration pragma file, this setting is harmless since the
9305 -- switch will get reset anyway at the start of each unit.
9307 Optimize_Alignment_Local := True;
9313 -- pragma Pack (first_subtype_LOCAL_NAME);
9315 when Pragma_Pack => Pack : declare
9316 Assoc : constant Node_Id := Arg1;
9321 Check_No_Identifiers;
9322 Check_Arg_Count (1);
9323 Check_Arg_Is_Local_Name (Arg1);
9325 Type_Id := Expression (Assoc);
9326 Find_Type (Type_Id);
9327 Typ := Entity (Type_Id);
9330 or else Rep_Item_Too_Early (Typ, N)
9334 Typ := Underlying_Type (Typ);
9337 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9338 Error_Pragma ("pragma% must specify array or record type");
9341 Check_First_Subtype (Arg1);
9343 if Has_Pragma_Pack (Typ) then
9344 Error_Pragma ("duplicate pragma%, only one allowed");
9348 elsif Is_Array_Type (Typ) then
9350 -- Pack not allowed for aliased or atomic components
9352 if Has_Aliased_Components (Base_Type (Typ)) then
9354 ("pragma% ignored, cannot pack aliased components?");
9356 elsif Has_Atomic_Components (Typ)
9357 or else Is_Atomic (Component_Type (Typ))
9360 ("?pragma% ignored, cannot pack atomic components");
9363 -- If we had an explicit component size given, then we do not
9364 -- let Pack override this given size. We also give a warning
9365 -- that Pack is being ignored unless we can tell for sure that
9366 -- the Pack would not have had any effect anyway.
9368 if Has_Component_Size_Clause (Typ) then
9369 if Known_Static_RM_Size (Component_Type (Typ))
9371 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9376 ("?pragma% ignored, explicit component size given");
9379 -- If no prior array component size given, Pack is effective
9382 if not Rep_Item_Too_Late (Typ, N) then
9383 if VM_Target = No_VM then
9384 Set_Is_Packed (Base_Type (Typ));
9385 elsif not GNAT_Mode then
9387 ("?pragma% ignored in this configuration");
9390 Set_Has_Pragma_Pack (Base_Type (Typ));
9391 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9395 -- For record types, the pack is always effective
9397 else pragma Assert (Is_Record_Type (Typ));
9398 if not Rep_Item_Too_Late (Typ, N) then
9399 if VM_Target = No_VM then
9400 Set_Is_Packed (Base_Type (Typ));
9401 elsif not GNAT_Mode then
9402 Error_Pragma ("?pragma% ignored in this configuration");
9405 Set_Has_Pragma_Pack (Base_Type (Typ));
9406 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9417 -- There is nothing to do here, since we did all the processing for
9418 -- this pragma in Par.Prag (so that it works properly even in syntax
9428 -- pragma Passive [(PASSIVE_FORM)];
9430 -- PASSIVE_FORM ::= Semaphore | No
9432 when Pragma_Passive =>
9435 if Nkind (Parent (N)) /= N_Task_Definition then
9436 Error_Pragma ("pragma% must be within task definition");
9439 if Arg_Count /= 0 then
9440 Check_Arg_Count (1);
9441 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9444 ----------------------------------
9445 -- Preelaborable_Initialization --
9446 ----------------------------------
9448 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9450 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9455 Check_Arg_Count (1);
9456 Check_No_Identifiers;
9457 Check_Arg_Is_Identifier (Arg1);
9458 Check_Arg_Is_Local_Name (Arg1);
9459 Check_First_Subtype (Arg1);
9460 Ent := Entity (Expression (Arg1));
9462 if not Is_Private_Type (Ent)
9463 and then not Is_Protected_Type (Ent)
9466 ("pragma % can only be applied to private or protected type",
9470 -- Give an error if the pragma is applied to a protected type that
9471 -- does not qualify (due to having entries, or due to components
9472 -- that do not qualify).
9474 if Is_Protected_Type (Ent)
9475 and then not Has_Preelaborable_Initialization (Ent)
9478 ("protected type & does not have preelaborable " &
9479 "initialization", Ent);
9481 -- Otherwise mark the type as definitely having preelaborable
9485 Set_Known_To_Have_Preelab_Init (Ent);
9488 if Has_Pragma_Preelab_Init (Ent)
9489 and then Warn_On_Redundant_Constructs
9491 Error_Pragma ("?duplicate pragma%!");
9493 Set_Has_Pragma_Preelab_Init (Ent);
9497 --------------------
9498 -- Persistent_BSS --
9499 --------------------
9501 when Pragma_Persistent_BSS => Persistent_BSS : declare
9508 Check_At_Most_N_Arguments (1);
9510 -- Case of application to specific object (one argument)
9512 if Arg_Count = 1 then
9513 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9515 if not Is_Entity_Name (Expression (Arg1))
9517 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9518 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9520 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9523 Ent := Entity (Expression (Arg1));
9524 Decl := Parent (Ent);
9526 if Rep_Item_Too_Late (Ent, N) then
9530 if Present (Expression (Decl)) then
9532 ("object for pragma% cannot have initialization", Arg1);
9535 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9537 ("object type for pragma% is not potentially persistent",
9542 Make_Linker_Section_Pragma
9543 (Ent, Sloc (N), ".persistent.bss");
9544 Insert_After (N, Prag);
9547 -- Case of use as configuration pragma with no arguments
9550 Check_Valid_Configuration_Pragma;
9551 Persistent_BSS_Mode := True;
9559 -- pragma Polling (ON | OFF);
9561 when Pragma_Polling =>
9563 Check_Arg_Count (1);
9564 Check_No_Identifiers;
9565 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9566 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9572 -- pragma Postcondition ([Check =>] Boolean_Expression
9573 -- [,[Message =>] String_Expression]);
9575 when Pragma_Postcondition => Postcondition : declare
9577 pragma Warnings (Off, In_Body);
9581 Check_At_Least_N_Arguments (1);
9582 Check_At_Most_N_Arguments (2);
9583 Check_Optional_Identifier (Arg1, Name_Check);
9585 -- All we need to do here is call the common check procedure,
9586 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9588 Check_Precondition_Postcondition (In_Body);
9595 -- pragma Precondition ([Check =>] Boolean_Expression
9596 -- [,[Message =>] String_Expression]);
9598 when Pragma_Precondition => Precondition : declare
9603 Check_At_Least_N_Arguments (1);
9604 Check_At_Most_N_Arguments (2);
9605 Check_Optional_Identifier (Arg1, Name_Check);
9607 Check_Precondition_Postcondition (In_Body);
9609 -- If in spec, nothing to do. If in body, then we convert the
9610 -- pragma to pragma Check (Precondition, cond [, msg]). Note we
9611 -- do this whether or not precondition checks are enabled. That
9612 -- works fine since pragma Check will do this check.
9615 if Arg_Count = 2 then
9616 Check_Optional_Identifier (Arg3, Name_Message);
9617 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9620 Analyze_And_Resolve (Get_Pragma_Arg (Arg1), Standard_Boolean);
9624 Chars => Name_Check,
9625 Pragma_Argument_Associations => New_List (
9626 Make_Pragma_Argument_Association (Loc,
9628 Make_Identifier (Loc,
9629 Chars => Name_Precondition)),
9631 Make_Pragma_Argument_Association (Sloc (Arg1),
9632 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9634 if Arg_Count = 2 then
9635 Append_To (Pragma_Argument_Associations (N),
9636 Make_Pragma_Argument_Association (Sloc (Arg2),
9637 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9648 -- pragma Preelaborate [(library_unit_NAME)];
9650 -- Set the flag Is_Preelaborated of program unit name entity
9652 when Pragma_Preelaborate => Preelaborate : declare
9653 Pa : constant Node_Id := Parent (N);
9654 Pk : constant Node_Kind := Nkind (Pa);
9658 Check_Ada_83_Warning;
9659 Check_Valid_Library_Unit_Pragma;
9661 if Nkind (N) = N_Null_Statement then
9665 Ent := Find_Lib_Unit_Name;
9667 -- This filters out pragmas inside generic parent then
9668 -- show up inside instantiation
9671 and then not (Pk = N_Package_Specification
9672 and then Present (Generic_Parent (Pa)))
9674 if not Debug_Flag_U then
9675 Set_Is_Preelaborated (Ent);
9676 Set_Suppress_Elaboration_Warnings (Ent);
9681 ---------------------
9682 -- Preelaborate_05 --
9683 ---------------------
9685 -- pragma Preelaborate_05 [(library_unit_NAME)];
9687 -- This pragma is useable only in GNAT_Mode, where it is used like
9688 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9689 -- (otherwise it is ignored). This is used to implement AI-362 which
9690 -- recategorizes some run-time packages in Ada 2005 mode.
9692 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9697 Check_Valid_Library_Unit_Pragma;
9699 if not GNAT_Mode then
9700 Error_Pragma ("pragma% only available in GNAT mode");
9703 if Nkind (N) = N_Null_Statement then
9707 -- This is one of the few cases where we need to test the value of
9708 -- Ada_Version_Explicit rather than Ada_Version (which is always
9709 -- set to Ada_05 in a predefined unit), we need to know the
9710 -- explicit version set to know if this pragma is active.
9712 if Ada_Version_Explicit >= Ada_05 then
9713 Ent := Find_Lib_Unit_Name;
9714 Set_Is_Preelaborated (Ent);
9715 Set_Suppress_Elaboration_Warnings (Ent);
9717 end Preelaborate_05;
9723 -- pragma Priority (EXPRESSION);
9725 when Pragma_Priority => Priority : declare
9726 P : constant Node_Id := Parent (N);
9730 Check_No_Identifiers;
9731 Check_Arg_Count (1);
9735 if Nkind (P) = N_Subprogram_Body then
9736 Check_In_Main_Program;
9738 Arg := Expression (Arg1);
9739 Analyze_And_Resolve (Arg, Standard_Integer);
9743 if not Is_Static_Expression (Arg) then
9744 Flag_Non_Static_Expr
9745 ("main subprogram priority is not static!", Arg);
9748 -- If constraint error, then we already signalled an error
9750 elsif Raises_Constraint_Error (Arg) then
9753 -- Otherwise check in range
9757 Val : constant Uint := Expr_Value (Arg);
9761 or else Val > Expr_Value (Expression
9762 (Parent (RTE (RE_Max_Priority))))
9765 ("main subprogram priority is out of range", Arg1);
9771 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9773 -- Load an arbitrary entity from System.Tasking to make sure
9774 -- this package is implicitly with'ed, since we need to have
9775 -- the tasking run-time active for the pragma Priority to have
9779 Discard : Entity_Id;
9780 pragma Warnings (Off, Discard);
9782 Discard := RTE (RE_Task_List);
9785 -- Task or Protected, must be of type Integer
9787 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9788 Arg := Expression (Arg1);
9790 -- The expression must be analyzed in the special manner
9791 -- described in "Handling of Default and Per-Object
9792 -- Expressions" in sem.ads.
9794 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9796 if not Is_Static_Expression (Arg) then
9797 Check_Restriction (Static_Priorities, Arg);
9800 -- Anything else is incorrect
9806 if Has_Priority_Pragma (P) then
9807 Error_Pragma ("duplicate pragma% not allowed");
9809 Set_Has_Priority_Pragma (P, True);
9811 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9812 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9813 -- exp_ch9 should use this ???
9818 -----------------------------------
9819 -- Priority_Specific_Dispatching --
9820 -----------------------------------
9822 -- pragma Priority_Specific_Dispatching (
9823 -- policy_IDENTIFIER,
9824 -- first_priority_EXPRESSION,
9825 -- last_priority_EXPRESSION);
9827 when Pragma_Priority_Specific_Dispatching =>
9828 Priority_Specific_Dispatching : declare
9829 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9830 -- This is the entity System.Any_Priority;
9833 Lower_Bound : Node_Id;
9834 Upper_Bound : Node_Id;
9840 Check_Arg_Count (3);
9841 Check_No_Identifiers;
9842 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9843 Check_Valid_Configuration_Pragma;
9844 Get_Name_String (Chars (Expression (Arg1)));
9845 DP := Fold_Upper (Name_Buffer (1));
9847 Lower_Bound := Expression (Arg2);
9848 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9849 Lower_Val := Expr_Value (Lower_Bound);
9851 Upper_Bound := Expression (Arg3);
9852 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
9853 Upper_Val := Expr_Value (Upper_Bound);
9855 -- It is not allowed to use Task_Dispatching_Policy and
9856 -- Priority_Specific_Dispatching in the same partition.
9858 if Task_Dispatching_Policy /= ' ' then
9859 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9861 ("pragma% incompatible with Task_Dispatching_Policy#");
9863 -- Check lower bound in range
9865 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9867 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
9870 ("first_priority is out of range", Arg2);
9872 -- Check upper bound in range
9874 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9876 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
9879 ("last_priority is out of range", Arg3);
9881 -- Check that the priority range is valid
9883 elsif Lower_Val > Upper_Val then
9885 ("last_priority_expression must be greater than" &
9886 " or equal to first_priority_expression");
9888 -- Store the new policy, but always preserve System_Location since
9889 -- we like the error message with the run-time name.
9892 -- Check overlapping in the priority ranges specified in other
9893 -- Priority_Specific_Dispatching pragmas within the same
9894 -- partition. We can only check those we know about!
9897 Specific_Dispatching.First .. Specific_Dispatching.Last
9899 if Specific_Dispatching.Table (J).First_Priority in
9900 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9901 or else Specific_Dispatching.Table (J).Last_Priority in
9902 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9905 Specific_Dispatching.Table (J).Pragma_Loc;
9907 ("priority range overlaps with "
9908 & "Priority_Specific_Dispatching#");
9912 -- The use of Priority_Specific_Dispatching is incompatible
9913 -- with Task_Dispatching_Policy.
9915 if Task_Dispatching_Policy /= ' ' then
9916 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9918 ("Priority_Specific_Dispatching incompatible "
9919 & "with Task_Dispatching_Policy#");
9922 -- The use of Priority_Specific_Dispatching forces ceiling
9925 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
9926 Error_Msg_Sloc := Locking_Policy_Sloc;
9928 ("Priority_Specific_Dispatching incompatible "
9929 & "with Locking_Policy#");
9931 -- Set the Ceiling_Locking policy, but preserve System_Location
9932 -- since we like the error message with the run time name.
9935 Locking_Policy := 'C';
9937 if Locking_Policy_Sloc /= System_Location then
9938 Locking_Policy_Sloc := Loc;
9942 -- Add entry in the table
9944 Specific_Dispatching.Append
9945 ((Dispatching_Policy => DP,
9946 First_Priority => UI_To_Int (Lower_Val),
9947 Last_Priority => UI_To_Int (Upper_Val),
9948 Pragma_Loc => Loc));
9950 end Priority_Specific_Dispatching;
9956 -- pragma Profile (profile_IDENTIFIER);
9958 -- profile_IDENTIFIER => Restricted | Ravenscar
9960 when Pragma_Profile =>
9962 Check_Arg_Count (1);
9963 Check_Valid_Configuration_Pragma;
9964 Check_No_Identifiers;
9967 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9969 if Chars (Argx) = Name_Ravenscar then
9970 Set_Ravenscar_Profile (N);
9971 elsif Chars (Argx) = Name_Restricted then
9972 Set_Profile_Restrictions
9973 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
9975 Error_Pragma_Arg ("& is not a valid profile", Argx);
9979 ----------------------
9980 -- Profile_Warnings --
9981 ----------------------
9983 -- pragma Profile_Warnings (profile_IDENTIFIER);
9985 -- profile_IDENTIFIER => Restricted | Ravenscar
9987 when Pragma_Profile_Warnings =>
9989 Check_Arg_Count (1);
9990 Check_Valid_Configuration_Pragma;
9991 Check_No_Identifiers;
9994 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9996 if Chars (Argx) = Name_Ravenscar then
9997 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
9998 elsif Chars (Argx) = Name_Restricted then
9999 Set_Profile_Restrictions (Restricted, N, Warn => True);
10001 Error_Pragma_Arg ("& is not a valid profile", Argx);
10005 --------------------------
10006 -- Propagate_Exceptions --
10007 --------------------------
10009 -- pragma Propagate_Exceptions;
10011 -- Note: this pragma is obsolete and has no effect
10013 when Pragma_Propagate_Exceptions =>
10015 Check_Arg_Count (0);
10017 if In_Extended_Main_Source_Unit (N) then
10018 Propagate_Exceptions := True;
10025 -- pragma Psect_Object (
10026 -- [Internal =>] LOCAL_NAME,
10027 -- [, [External =>] EXTERNAL_SYMBOL]
10028 -- [, [Size =>] EXTERNAL_SYMBOL]);
10030 when Pragma_Psect_Object | Pragma_Common_Object =>
10031 Psect_Object : declare
10032 Args : Args_List (1 .. 3);
10033 Names : constant Name_List (1 .. 3) := (
10038 Internal : Node_Id renames Args (1);
10039 External : Node_Id renames Args (2);
10040 Size : Node_Id renames Args (3);
10042 Def_Id : Entity_Id;
10044 procedure Check_Too_Long (Arg : Node_Id);
10045 -- Posts message if the argument is an identifier with more
10046 -- than 31 characters, or a string literal with more than
10047 -- 31 characters, and we are operating under VMS
10049 --------------------
10050 -- Check_Too_Long --
10051 --------------------
10053 procedure Check_Too_Long (Arg : Node_Id) is
10054 X : constant Node_Id := Original_Node (Arg);
10057 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10059 ("inappropriate argument for pragma %", Arg);
10062 if OpenVMS_On_Target then
10063 if (Nkind (X) = N_String_Literal
10064 and then String_Length (Strval (X)) > 31)
10066 (Nkind (X) = N_Identifier
10067 and then Length_Of_Name (Chars (X)) > 31)
10070 ("argument for pragma % is longer than 31 characters",
10074 end Check_Too_Long;
10076 -- Start of processing for Common_Object/Psect_Object
10080 Gather_Associations (Names, Args);
10081 Process_Extended_Import_Export_Internal_Arg (Internal);
10083 Def_Id := Entity (Internal);
10085 if Ekind (Def_Id) /= E_Constant
10086 and then Ekind (Def_Id) /= E_Variable
10089 ("pragma% must designate an object", Internal);
10092 Check_Too_Long (Internal);
10094 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10096 ("cannot use pragma% for imported/exported object",
10100 if Is_Concurrent_Type (Etype (Internal)) then
10102 ("cannot specify pragma % for task/protected object",
10106 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10108 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10110 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10113 if Ekind (Def_Id) = E_Constant then
10115 ("cannot specify pragma % for a constant", Internal);
10118 if Is_Record_Type (Etype (Internal)) then
10124 Ent := First_Entity (Etype (Internal));
10125 while Present (Ent) loop
10126 Decl := Declaration_Node (Ent);
10128 if Ekind (Ent) = E_Component
10129 and then Nkind (Decl) = N_Component_Declaration
10130 and then Present (Expression (Decl))
10131 and then Warn_On_Export_Import
10134 ("?object for pragma % has defaults", Internal);
10144 if Present (Size) then
10145 Check_Too_Long (Size);
10148 if Present (External) then
10149 Check_Arg_Is_External_Name (External);
10150 Check_Too_Long (External);
10153 -- If all error tests pass, link pragma on to the rep item chain
10155 Record_Rep_Item (Def_Id, N);
10162 -- pragma Pure [(library_unit_NAME)];
10164 when Pragma_Pure => Pure : declare
10168 Check_Ada_83_Warning;
10169 Check_Valid_Library_Unit_Pragma;
10171 if Nkind (N) = N_Null_Statement then
10175 Ent := Find_Lib_Unit_Name;
10177 Set_Has_Pragma_Pure (Ent);
10178 Set_Suppress_Elaboration_Warnings (Ent);
10185 -- pragma Pure_05 [(library_unit_NAME)];
10187 -- This pragma is useable only in GNAT_Mode, where it is used like
10188 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10189 -- it is ignored). It may be used after a pragma Preelaborate, in
10190 -- which case it overrides the effect of the pragma Preelaborate.
10191 -- This is used to implement AI-362 which recategorizes some run-time
10192 -- packages in Ada 2005 mode.
10194 when Pragma_Pure_05 => Pure_05 : declare
10199 Check_Valid_Library_Unit_Pragma;
10201 if not GNAT_Mode then
10202 Error_Pragma ("pragma% only available in GNAT mode");
10205 if Nkind (N) = N_Null_Statement then
10209 -- This is one of the few cases where we need to test the value of
10210 -- Ada_Version_Explicit rather than Ada_Version (which is always
10211 -- set to Ada_05 in a predefined unit), we need to know the
10212 -- explicit version set to know if this pragma is active.
10214 if Ada_Version_Explicit >= Ada_05 then
10215 Ent := Find_Lib_Unit_Name;
10216 Set_Is_Preelaborated (Ent, False);
10218 Set_Suppress_Elaboration_Warnings (Ent);
10222 -------------------
10223 -- Pure_Function --
10224 -------------------
10226 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10228 when Pragma_Pure_Function => Pure_Function : declare
10231 Def_Id : Entity_Id;
10232 Effective : Boolean := False;
10236 Check_Arg_Count (1);
10237 Check_Optional_Identifier (Arg1, Name_Entity);
10238 Check_Arg_Is_Local_Name (Arg1);
10239 E_Id := Expression (Arg1);
10241 if Error_Posted (E_Id) then
10245 -- Loop through homonyms (overloadings) of referenced entity
10247 E := Entity (E_Id);
10249 if Present (E) then
10251 Def_Id := Get_Base_Subprogram (E);
10253 if Ekind (Def_Id) /= E_Function
10254 and then Ekind (Def_Id) /= E_Generic_Function
10255 and then Ekind (Def_Id) /= E_Operator
10258 ("pragma% requires a function name", Arg1);
10261 Set_Is_Pure (Def_Id);
10263 if not Has_Pragma_Pure_Function (Def_Id) then
10264 Set_Has_Pragma_Pure_Function (Def_Id);
10269 exit when No (E) or else Scope (E) /= Current_Scope;
10273 and then Warn_On_Redundant_Constructs
10275 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10281 --------------------
10282 -- Queuing_Policy --
10283 --------------------
10285 -- pragma Queuing_Policy (policy_IDENTIFIER);
10287 when Pragma_Queuing_Policy => declare
10291 Check_Ada_83_Warning;
10292 Check_Arg_Count (1);
10293 Check_No_Identifiers;
10294 Check_Arg_Is_Queuing_Policy (Arg1);
10295 Check_Valid_Configuration_Pragma;
10296 Get_Name_String (Chars (Expression (Arg1)));
10297 QP := Fold_Upper (Name_Buffer (1));
10299 if Queuing_Policy /= ' '
10300 and then Queuing_Policy /= QP
10302 Error_Msg_Sloc := Queuing_Policy_Sloc;
10303 Error_Pragma ("queuing policy incompatible with policy#");
10305 -- Set new policy, but always preserve System_Location since we
10306 -- like the error message with the run time name.
10309 Queuing_Policy := QP;
10311 if Queuing_Policy_Sloc /= System_Location then
10312 Queuing_Policy_Sloc := Loc;
10317 -----------------------
10318 -- Relative_Deadline --
10319 -----------------------
10321 -- pragma Relative_Deadline (time_span_EXPRESSION);
10323 when Pragma_Relative_Deadline => Relative_Deadline : declare
10324 P : constant Node_Id := Parent (N);
10329 Check_No_Identifiers;
10330 Check_Arg_Count (1);
10332 Arg := Expression (Arg1);
10334 -- The expression must be analyzed in the special manner described
10335 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10337 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10341 if Nkind (P) = N_Subprogram_Body then
10342 Check_In_Main_Program;
10346 elsif Nkind (P) = N_Task_Definition then
10349 -- Anything else is incorrect
10355 if Has_Relative_Deadline_Pragma (P) then
10356 Error_Pragma ("duplicate pragma% not allowed");
10358 Set_Has_Relative_Deadline_Pragma (P, True);
10360 if Nkind (P) = N_Task_Definition then
10361 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10364 end Relative_Deadline;
10366 ---------------------------
10367 -- Remote_Call_Interface --
10368 ---------------------------
10370 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10372 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10373 Cunit_Node : Node_Id;
10374 Cunit_Ent : Entity_Id;
10378 Check_Ada_83_Warning;
10379 Check_Valid_Library_Unit_Pragma;
10381 if Nkind (N) = N_Null_Statement then
10385 Cunit_Node := Cunit (Current_Sem_Unit);
10386 K := Nkind (Unit (Cunit_Node));
10387 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10389 if K = N_Package_Declaration
10390 or else K = N_Generic_Package_Declaration
10391 or else K = N_Subprogram_Declaration
10392 or else K = N_Generic_Subprogram_Declaration
10393 or else (K = N_Subprogram_Body
10394 and then Acts_As_Spec (Unit (Cunit_Node)))
10399 "pragma% must apply to package or subprogram declaration");
10402 Set_Is_Remote_Call_Interface (Cunit_Ent);
10403 end Remote_Call_Interface;
10409 -- pragma Remote_Types [(library_unit_NAME)];
10411 when Pragma_Remote_Types => Remote_Types : declare
10412 Cunit_Node : Node_Id;
10413 Cunit_Ent : Entity_Id;
10416 Check_Ada_83_Warning;
10417 Check_Valid_Library_Unit_Pragma;
10419 if Nkind (N) = N_Null_Statement then
10423 Cunit_Node := Cunit (Current_Sem_Unit);
10424 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10426 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10427 N_Generic_Package_Declaration)
10430 ("pragma% can only apply to a package declaration");
10433 Set_Is_Remote_Types (Cunit_Ent);
10440 -- pragma Ravenscar;
10442 when Pragma_Ravenscar =>
10444 Check_Arg_Count (0);
10445 Check_Valid_Configuration_Pragma;
10446 Set_Ravenscar_Profile (N);
10448 if Warn_On_Obsolescent_Feature then
10450 ("pragma Ravenscar is an obsolescent feature?", N);
10452 ("|use pragma Profile (Ravenscar) instead", N);
10455 -------------------------
10456 -- Restricted_Run_Time --
10457 -------------------------
10459 -- pragma Restricted_Run_Time;
10461 when Pragma_Restricted_Run_Time =>
10463 Check_Arg_Count (0);
10464 Check_Valid_Configuration_Pragma;
10465 Set_Profile_Restrictions
10466 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10468 if Warn_On_Obsolescent_Feature then
10470 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10472 ("|use pragma Profile (Restricted) instead", N);
10479 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10482 -- restriction_IDENTIFIER
10483 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10485 when Pragma_Restrictions =>
10486 Process_Restrictions_Or_Restriction_Warnings
10487 (Warn => Treat_Restrictions_As_Warnings);
10489 --------------------------
10490 -- Restriction_Warnings --
10491 --------------------------
10493 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10496 -- restriction_IDENTIFIER
10497 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10499 when Pragma_Restriction_Warnings =>
10501 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10507 -- pragma Reviewable;
10509 when Pragma_Reviewable =>
10510 Check_Ada_83_Warning;
10511 Check_Arg_Count (0);
10514 -------------------
10515 -- Share_Generic --
10516 -------------------
10518 -- pragma Share_Generic (NAME {, NAME});
10520 when Pragma_Share_Generic =>
10522 Process_Generic_List;
10528 -- pragma Shared (LOCAL_NAME);
10530 when Pragma_Shared =>
10532 Process_Atomic_Shared_Volatile;
10534 --------------------
10535 -- Shared_Passive --
10536 --------------------
10538 -- pragma Shared_Passive [(library_unit_NAME)];
10540 -- Set the flag Is_Shared_Passive of program unit name entity
10542 when Pragma_Shared_Passive => Shared_Passive : declare
10543 Cunit_Node : Node_Id;
10544 Cunit_Ent : Entity_Id;
10547 Check_Ada_83_Warning;
10548 Check_Valid_Library_Unit_Pragma;
10550 if Nkind (N) = N_Null_Statement then
10554 Cunit_Node := Cunit (Current_Sem_Unit);
10555 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10557 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10558 N_Generic_Package_Declaration)
10561 ("pragma% can only apply to a package declaration");
10564 Set_Is_Shared_Passive (Cunit_Ent);
10565 end Shared_Passive;
10567 ----------------------
10568 -- Source_File_Name --
10569 ----------------------
10571 -- There are five forms for this pragma:
10573 -- pragma Source_File_Name (
10574 -- [UNIT_NAME =>] unit_NAME,
10575 -- BODY_FILE_NAME => STRING_LITERAL
10576 -- [, [INDEX =>] INTEGER_LITERAL]);
10578 -- pragma Source_File_Name (
10579 -- [UNIT_NAME =>] unit_NAME,
10580 -- SPEC_FILE_NAME => STRING_LITERAL
10581 -- [, [INDEX =>] INTEGER_LITERAL]);
10583 -- pragma Source_File_Name (
10584 -- BODY_FILE_NAME => STRING_LITERAL
10585 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10586 -- [, CASING => CASING_SPEC]);
10588 -- pragma Source_File_Name (
10589 -- SPEC_FILE_NAME => STRING_LITERAL
10590 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10591 -- [, CASING => CASING_SPEC]);
10593 -- pragma Source_File_Name (
10594 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10595 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10596 -- [, CASING => CASING_SPEC]);
10598 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10600 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10601 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
10602 -- only be used when no project file is used, while SFNP can only be
10603 -- used when a project file is used.
10605 -- No processing here. Processing was completed during parsing, since
10606 -- we need to have file names set as early as possible. Units are
10607 -- loaded well before semantic processing starts.
10609 -- The only processing we defer to this point is the check for
10610 -- correct placement.
10612 when Pragma_Source_File_Name =>
10614 Check_Valid_Configuration_Pragma;
10616 ------------------------------
10617 -- Source_File_Name_Project --
10618 ------------------------------
10620 -- See Source_File_Name for syntax
10622 -- No processing here. Processing was completed during parsing, since
10623 -- we need to have file names set as early as possible. Units are
10624 -- loaded well before semantic processing starts.
10626 -- The only processing we defer to this point is the check for
10627 -- correct placement.
10629 when Pragma_Source_File_Name_Project =>
10631 Check_Valid_Configuration_Pragma;
10633 -- Check that a pragma Source_File_Name_Project is used only in a
10634 -- configuration pragmas file.
10636 -- Pragmas Source_File_Name_Project should only be generated by
10637 -- the Project Manager in configuration pragmas files.
10639 -- This is really an ugly test. It seems to depend on some
10640 -- accidental and undocumented property. At the very least it
10641 -- needs to be documented, but it would be better to have a
10642 -- clean way of testing if we are in a configuration file???
10644 if Present (Parent (N)) then
10646 ("pragma% can only appear in a configuration pragmas file");
10649 ----------------------
10650 -- Source_Reference --
10651 ----------------------
10653 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10655 -- Nothing to do, all processing completed in Par.Prag, since we need
10656 -- the information for possible parser messages that are output.
10658 when Pragma_Source_Reference =>
10661 --------------------------------
10662 -- Static_Elaboration_Desired --
10663 --------------------------------
10665 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10667 when Pragma_Static_Elaboration_Desired =>
10669 Check_At_Most_N_Arguments (1);
10671 if Is_Compilation_Unit (Current_Scope)
10672 and then Ekind (Current_Scope) = E_Package
10674 Set_Static_Elaboration_Desired (Current_Scope, True);
10676 Error_Pragma ("pragma% must apply to a library-level package");
10683 -- pragma Storage_Size (EXPRESSION);
10685 when Pragma_Storage_Size => Storage_Size : declare
10686 P : constant Node_Id := Parent (N);
10690 Check_No_Identifiers;
10691 Check_Arg_Count (1);
10693 -- The expression must be analyzed in the special manner described
10694 -- in "Handling of Default Expressions" in sem.ads.
10696 Arg := Expression (Arg1);
10697 Preanalyze_Spec_Expression (Arg, Any_Integer);
10699 if not Is_Static_Expression (Arg) then
10700 Check_Restriction (Static_Storage_Size, Arg);
10703 if Nkind (P) /= N_Task_Definition then
10708 if Has_Storage_Size_Pragma (P) then
10709 Error_Pragma ("duplicate pragma% not allowed");
10711 Set_Has_Storage_Size_Pragma (P, True);
10714 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10715 -- ??? exp_ch9 should use this!
10723 -- pragma Storage_Unit (NUMERIC_LITERAL);
10725 -- Only permitted argument is System'Storage_Unit value
10727 when Pragma_Storage_Unit =>
10728 Check_No_Identifiers;
10729 Check_Arg_Count (1);
10730 Check_Arg_Is_Integer_Literal (Arg1);
10732 if Intval (Expression (Arg1)) /=
10733 UI_From_Int (Ttypes.System_Storage_Unit)
10735 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10737 ("the only allowed argument for pragma% is ^", Arg1);
10740 --------------------
10741 -- Stream_Convert --
10742 --------------------
10744 -- pragma Stream_Convert (
10745 -- [Entity =>] type_LOCAL_NAME,
10746 -- [Read =>] function_NAME,
10747 -- [Write =>] function NAME);
10749 when Pragma_Stream_Convert => Stream_Convert : declare
10751 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10752 -- Check that the given argument is the name of a local function
10753 -- of one argument that is not overloaded earlier in the current
10754 -- local scope. A check is also made that the argument is a
10755 -- function with one parameter.
10757 --------------------------------------
10758 -- Check_OK_Stream_Convert_Function --
10759 --------------------------------------
10761 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10765 Check_Arg_Is_Local_Name (Arg);
10766 Ent := Entity (Expression (Arg));
10768 if Has_Homonym (Ent) then
10770 ("argument for pragma% may not be overloaded", Arg);
10773 if Ekind (Ent) /= E_Function
10774 or else No (First_Formal (Ent))
10775 or else Present (Next_Formal (First_Formal (Ent)))
10778 ("argument for pragma% must be" &
10779 " function of one argument", Arg);
10781 end Check_OK_Stream_Convert_Function;
10783 -- Start of processing for Stream_Convert
10787 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10788 Check_Arg_Count (3);
10789 Check_Optional_Identifier (Arg1, Name_Entity);
10790 Check_Optional_Identifier (Arg2, Name_Read);
10791 Check_Optional_Identifier (Arg3, Name_Write);
10792 Check_Arg_Is_Local_Name (Arg1);
10793 Check_OK_Stream_Convert_Function (Arg2);
10794 Check_OK_Stream_Convert_Function (Arg3);
10797 Typ : constant Entity_Id :=
10798 Underlying_Type (Entity (Expression (Arg1)));
10799 Read : constant Entity_Id := Entity (Expression (Arg2));
10800 Write : constant Entity_Id := Entity (Expression (Arg3));
10803 Check_First_Subtype (Arg1);
10805 -- Check for too early or too late. Note that we don't enforce
10806 -- the rule about primitive operations in this case, since, as
10807 -- is the case for explicit stream attributes themselves, these
10808 -- restrictions are not appropriate. Note that the chaining of
10809 -- the pragma by Rep_Item_Too_Late is actually the critical
10810 -- processing done for this pragma.
10812 if Rep_Item_Too_Early (Typ, N)
10814 Rep_Item_Too_Late (Typ, N, FOnly => True)
10819 -- Return if previous error
10821 if Etype (Typ) = Any_Type
10823 Etype (Read) = Any_Type
10825 Etype (Write) = Any_Type
10832 if Underlying_Type (Etype (Read)) /= Typ then
10834 ("incorrect return type for function&", Arg2);
10837 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
10839 ("incorrect parameter type for function&", Arg3);
10842 if Underlying_Type (Etype (First_Formal (Read))) /=
10843 Underlying_Type (Etype (Write))
10846 ("result type of & does not match Read parameter type",
10850 end Stream_Convert;
10852 -------------------------
10853 -- Style_Checks (GNAT) --
10854 -------------------------
10856 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10858 -- This is processed by the parser since some of the style checks
10859 -- take place during source scanning and parsing. This means that
10860 -- we don't need to issue error messages here.
10862 when Pragma_Style_Checks => Style_Checks : declare
10863 A : constant Node_Id := Expression (Arg1);
10869 Check_No_Identifiers;
10871 -- Two argument form
10873 if Arg_Count = 2 then
10874 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10881 E_Id := Expression (Arg2);
10884 if not Is_Entity_Name (E_Id) then
10886 ("second argument of pragma% must be entity name",
10890 E := Entity (E_Id);
10896 Set_Suppress_Style_Checks (E,
10897 (Chars (Expression (Arg1)) = Name_Off));
10898 exit when No (Homonym (E));
10904 -- One argument form
10907 Check_Arg_Count (1);
10909 if Nkind (A) = N_String_Literal then
10913 Slen : constant Natural := Natural (String_Length (S));
10914 Options : String (1 .. Slen);
10920 C := Get_String_Char (S, Int (J));
10921 exit when not In_Character_Range (C);
10922 Options (J) := Get_Character (C);
10924 -- If at end of string, set options. As per discussion
10925 -- above, no need to check for errors, since we issued
10926 -- them in the parser.
10929 Set_Style_Check_Options (Options);
10937 elsif Nkind (A) = N_Identifier then
10938 if Chars (A) = Name_All_Checks then
10939 Set_Default_Style_Check_Options;
10941 elsif Chars (A) = Name_On then
10942 Style_Check := True;
10944 elsif Chars (A) = Name_Off then
10945 Style_Check := False;
10955 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
10957 when Pragma_Subtitle =>
10959 Check_Arg_Count (1);
10960 Check_Optional_Identifier (Arg1, Name_Subtitle);
10961 Check_Arg_Is_String_Literal (Arg1);
10967 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
10969 when Pragma_Suppress =>
10970 Process_Suppress_Unsuppress (True);
10976 -- pragma Suppress_All;
10978 -- The only check made here is that the pragma appears in the proper
10979 -- place, i.e. following a compilation unit. If indeed it appears in
10980 -- this context, then the parser has already inserted an equivalent
10981 -- pragma Suppress (All_Checks) to get the required effect.
10983 when Pragma_Suppress_All =>
10985 Check_Arg_Count (0);
10987 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
10988 or else not Is_List_Member (N)
10989 or else List_Containing (N) /= Pragmas_After (Parent (N))
10992 ("misplaced pragma%, must follow compilation unit");
10995 -------------------------
10996 -- Suppress_Debug_Info --
10997 -------------------------
10999 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11001 when Pragma_Suppress_Debug_Info =>
11003 Check_Arg_Count (1);
11004 Check_Optional_Identifier (Arg1, Name_Entity);
11005 Check_Arg_Is_Local_Name (Arg1);
11006 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11008 ----------------------------------
11009 -- Suppress_Exception_Locations --
11010 ----------------------------------
11012 -- pragma Suppress_Exception_Locations;
11014 when Pragma_Suppress_Exception_Locations =>
11016 Check_Arg_Count (0);
11017 Check_Valid_Configuration_Pragma;
11018 Exception_Locations_Suppressed := True;
11020 -----------------------------
11021 -- Suppress_Initialization --
11022 -----------------------------
11024 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11026 when Pragma_Suppress_Initialization => Suppress_Init : declare
11032 Check_Arg_Count (1);
11033 Check_Optional_Identifier (Arg1, Name_Entity);
11034 Check_Arg_Is_Local_Name (Arg1);
11036 E_Id := Expression (Arg1);
11038 if Etype (E_Id) = Any_Type then
11042 E := Entity (E_Id);
11044 if Is_Type (E) then
11045 if Is_Incomplete_Or_Private_Type (E) then
11046 if No (Full_View (Base_Type (E))) then
11048 ("argument of pragma% cannot be an incomplete type",
11051 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11054 Set_Suppress_Init_Proc (Base_Type (E));
11059 ("pragma% requires argument that is a type name", Arg1);
11067 -- pragma System_Name (DIRECT_NAME);
11069 -- Syntax check: one argument, which must be the identifier GNAT or
11070 -- the identifier GCC, no other identifiers are acceptable.
11072 when Pragma_System_Name =>
11074 Check_No_Identifiers;
11075 Check_Arg_Count (1);
11076 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11078 -----------------------------
11079 -- Task_Dispatching_Policy --
11080 -----------------------------
11082 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11084 when Pragma_Task_Dispatching_Policy => declare
11088 Check_Ada_83_Warning;
11089 Check_Arg_Count (1);
11090 Check_No_Identifiers;
11091 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11092 Check_Valid_Configuration_Pragma;
11093 Get_Name_String (Chars (Expression (Arg1)));
11094 DP := Fold_Upper (Name_Buffer (1));
11096 if Task_Dispatching_Policy /= ' '
11097 and then Task_Dispatching_Policy /= DP
11099 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11101 ("task dispatching policy incompatible with policy#");
11103 -- Set new policy, but always preserve System_Location since we
11104 -- like the error message with the run time name.
11107 Task_Dispatching_Policy := DP;
11109 if Task_Dispatching_Policy_Sloc /= System_Location then
11110 Task_Dispatching_Policy_Sloc := Loc;
11119 -- pragma Task_Info (EXPRESSION);
11121 when Pragma_Task_Info => Task_Info : declare
11122 P : constant Node_Id := Parent (N);
11127 if Nkind (P) /= N_Task_Definition then
11128 Error_Pragma ("pragma% must appear in task definition");
11131 Check_No_Identifiers;
11132 Check_Arg_Count (1);
11134 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11136 if Etype (Expression (Arg1)) = Any_Type then
11140 if Has_Task_Info_Pragma (P) then
11141 Error_Pragma ("duplicate pragma% not allowed");
11143 Set_Has_Task_Info_Pragma (P, True);
11151 -- pragma Task_Name (string_EXPRESSION);
11153 when Pragma_Task_Name => Task_Name : declare
11154 P : constant Node_Id := Parent (N);
11158 Check_No_Identifiers;
11159 Check_Arg_Count (1);
11161 Arg := Expression (Arg1);
11163 -- The expression is used in the call to Create_Task, and must be
11164 -- expanded there, not in the context of the current spec.
11166 Preanalyze_And_Resolve (New_Copy_Tree (Arg), Standard_String);
11168 if Nkind (P) /= N_Task_Definition then
11172 if Has_Task_Name_Pragma (P) then
11173 Error_Pragma ("duplicate pragma% not allowed");
11175 Set_Has_Task_Name_Pragma (P, True);
11176 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11184 -- pragma Task_Storage (
11185 -- [Task_Type =>] LOCAL_NAME,
11186 -- [Top_Guard =>] static_integer_EXPRESSION);
11188 when Pragma_Task_Storage => Task_Storage : declare
11189 Args : Args_List (1 .. 2);
11190 Names : constant Name_List (1 .. 2) := (
11194 Task_Type : Node_Id renames Args (1);
11195 Top_Guard : Node_Id renames Args (2);
11201 Gather_Associations (Names, Args);
11203 if No (Task_Type) then
11205 ("missing task_type argument for pragma%");
11208 Check_Arg_Is_Local_Name (Task_Type);
11210 Ent := Entity (Task_Type);
11212 if not Is_Task_Type (Ent) then
11214 ("argument for pragma% must be task type", Task_Type);
11217 if No (Top_Guard) then
11219 ("pragma% takes two arguments", Task_Type);
11221 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11224 Check_First_Subtype (Task_Type);
11226 if Rep_Item_Too_Late (Ent, N) then
11231 --------------------------
11232 -- Thread_Local_Storage --
11233 --------------------------
11235 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11237 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11243 Check_Arg_Count (1);
11244 Check_Optional_Identifier (Arg1, Name_Entity);
11245 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11247 Id := Expression (Arg1);
11250 if not Is_Entity_Name (Id)
11251 or else Ekind (Entity (Id)) /= E_Variable
11253 Error_Pragma_Arg ("local variable name required", Arg1);
11258 if Rep_Item_Too_Early (E, N)
11259 or else Rep_Item_Too_Late (E, N)
11264 Set_Has_Pragma_Thread_Local_Storage (E);
11265 Set_Has_Gigi_Rep_Item (E);
11266 end Thread_Local_Storage;
11272 -- pragma Time_Slice (static_duration_EXPRESSION);
11274 when Pragma_Time_Slice => Time_Slice : declare
11280 Check_Arg_Count (1);
11281 Check_No_Identifiers;
11282 Check_In_Main_Program;
11283 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11285 if not Error_Posted (Arg1) then
11287 while Present (Nod) loop
11288 if Nkind (Nod) = N_Pragma
11289 and then Pragma_Name (Nod) = Name_Time_Slice
11291 Error_Msg_Name_1 := Pname;
11292 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11299 -- Process only if in main unit
11301 if Get_Source_Unit (Loc) = Main_Unit then
11302 Opt.Time_Slice_Set := True;
11303 Val := Expr_Value_R (Expression (Arg1));
11305 if Val <= Ureal_0 then
11306 Opt.Time_Slice_Value := 0;
11308 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11309 Opt.Time_Slice_Value := 1_000_000_000;
11312 Opt.Time_Slice_Value :=
11313 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11322 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11324 -- TITLING_OPTION ::=
11325 -- [Title =>] STRING_LITERAL
11326 -- | [Subtitle =>] STRING_LITERAL
11328 when Pragma_Title => Title : declare
11329 Args : Args_List (1 .. 2);
11330 Names : constant Name_List (1 .. 2) := (
11336 Gather_Associations (Names, Args);
11338 for J in 1 .. 2 loop
11339 if Present (Args (J)) then
11340 Check_Arg_Is_String_Literal (Args (J));
11345 ---------------------
11346 -- Unchecked_Union --
11347 ---------------------
11349 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11351 when Pragma_Unchecked_Union => Unchecked_Union : declare
11352 Assoc : constant Node_Id := Arg1;
11353 Type_Id : constant Node_Id := Expression (Assoc);
11364 Check_No_Identifiers;
11365 Check_Arg_Count (1);
11366 Check_Arg_Is_Local_Name (Arg1);
11368 Find_Type (Type_Id);
11369 Typ := Entity (Type_Id);
11372 or else Rep_Item_Too_Early (Typ, N)
11376 Typ := Underlying_Type (Typ);
11379 if Rep_Item_Too_Late (Typ, N) then
11383 Check_First_Subtype (Arg1);
11385 -- Note remaining cases are references to a type in the current
11386 -- declarative part. If we find an error, we post the error on
11387 -- the relevant type declaration at an appropriate point.
11389 if not Is_Record_Type (Typ) then
11390 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11393 elsif Is_Tagged_Type (Typ) then
11394 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11397 elsif Is_Limited_Type (Typ) then
11399 ("Unchecked_Union must not be limited record type", Typ);
11400 Explain_Limited_Type (Typ, Typ);
11404 if not Has_Discriminants (Typ) then
11406 ("Unchecked_Union must have one discriminant", Typ);
11410 Discr := First_Discriminant (Typ);
11411 while Present (Discr) loop
11412 if No (Discriminant_Default_Value (Discr)) then
11414 ("Unchecked_Union discriminant must have default value",
11417 Next_Discriminant (Discr);
11420 Tdef := Type_Definition (Declaration_Node (Typ));
11421 Clist := Component_List (Tdef);
11423 Comp := First (Component_Items (Clist));
11424 while Present (Comp) loop
11425 Check_Component (Comp);
11429 if No (Clist) or else No (Variant_Part (Clist)) then
11431 ("Unchecked_Union must have variant part",
11436 Vpart := Variant_Part (Clist);
11438 Variant := First (Variants (Vpart));
11439 while Present (Variant) loop
11440 Check_Variant (Variant);
11445 Set_Is_Unchecked_Union (Typ, True);
11446 Set_Convention (Typ, Convention_C);
11448 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11449 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11450 end Unchecked_Union;
11452 ------------------------
11453 -- Unimplemented_Unit --
11454 ------------------------
11456 -- pragma Unimplemented_Unit;
11458 -- Note: this only gives an error if we are generating code, or if
11459 -- we are in a generic library unit (where the pragma appears in the
11460 -- body, not in the spec).
11462 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11463 Cunitent : constant Entity_Id :=
11464 Cunit_Entity (Get_Source_Unit (Loc));
11465 Ent_Kind : constant Entity_Kind :=
11470 Check_Arg_Count (0);
11472 if Operating_Mode = Generate_Code
11473 or else Ent_Kind = E_Generic_Function
11474 or else Ent_Kind = E_Generic_Procedure
11475 or else Ent_Kind = E_Generic_Package
11477 Get_Name_String (Chars (Cunitent));
11478 Set_Casing (Mixed_Case);
11479 Write_Str (Name_Buffer (1 .. Name_Len));
11480 Write_Str (" is not supported in this configuration");
11482 raise Unrecoverable_Error;
11484 end Unimplemented_Unit;
11486 ------------------------
11487 -- Universal_Aliasing --
11488 ------------------------
11490 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11492 when Pragma_Universal_Aliasing => Universal_Alias : declare
11497 Check_Arg_Count (1);
11498 Check_Optional_Identifier (Arg2, Name_Entity);
11499 Check_Arg_Is_Local_Name (Arg1);
11500 E_Id := Entity (Expression (Arg1));
11502 if E_Id = Any_Type then
11504 elsif No (E_Id) or else not Is_Type (E_Id) then
11505 Error_Pragma_Arg ("pragma% requires type", Arg1);
11508 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11509 end Universal_Alias;
11511 --------------------
11512 -- Universal_Data --
11513 --------------------
11515 -- pragma Universal_Data [(library_unit_NAME)];
11517 when Pragma_Universal_Data =>
11520 -- If this is a configuration pragma, then set the universal
11521 -- addressing option, otherwise confirm that the pragma satisfies
11522 -- the requirements of library unit pragma placement and leave it
11523 -- to the GNAAMP back end to detect the pragma (avoids transitive
11524 -- setting of the option due to withed units).
11526 if Is_Configuration_Pragma then
11527 Universal_Addressing_On_AAMP := True;
11529 Check_Valid_Library_Unit_Pragma;
11532 if not AAMP_On_Target then
11533 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11540 -- pragma Unmodified (local_Name {, local_Name});
11542 when Pragma_Unmodified => Unmodified : declare
11543 Arg_Node : Node_Id;
11544 Arg_Expr : Node_Id;
11545 Arg_Ent : Entity_Id;
11549 Check_At_Least_N_Arguments (1);
11551 -- Loop through arguments
11554 while Present (Arg_Node) loop
11555 Check_No_Identifier (Arg_Node);
11557 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11558 -- in fact generate reference, so that the entity will have a
11559 -- reference, which will inhibit any warnings about it not
11560 -- being referenced, and also properly show up in the ali file
11561 -- as a reference. But this reference is recorded before the
11562 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11563 -- generated for this reference.
11565 Check_Arg_Is_Local_Name (Arg_Node);
11566 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11568 if Is_Entity_Name (Arg_Expr) then
11569 Arg_Ent := Entity (Arg_Expr);
11571 if not Is_Assignable (Arg_Ent) then
11573 ("pragma% can only be applied to a variable",
11576 Set_Has_Pragma_Unmodified (Arg_Ent);
11588 -- pragma Unreferenced (local_Name {, local_Name});
11590 -- or when used in a context clause:
11592 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11594 when Pragma_Unreferenced => Unreferenced : declare
11595 Arg_Node : Node_Id;
11596 Arg_Expr : Node_Id;
11597 Arg_Ent : Entity_Id;
11602 Check_At_Least_N_Arguments (1);
11604 -- Check case of appearing within context clause
11606 if Is_In_Context_Clause then
11608 -- The arguments must all be units mentioned in a with clause
11609 -- in the same context clause. Note we already checked (in
11610 -- Par.Prag) that the arguments are either identifiers or
11611 -- selected components.
11614 while Present (Arg_Node) loop
11615 Citem := First (List_Containing (N));
11616 while Citem /= N loop
11617 if Nkind (Citem) = N_With_Clause
11618 and then Same_Name (Name (Citem), Expression (Arg_Node))
11620 Set_Has_Pragma_Unreferenced
11623 (Library_Unit (Citem))));
11624 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11633 ("argument of pragma% is not with'ed unit", Arg_Node);
11639 -- Case of not in list of context items
11643 while Present (Arg_Node) loop
11644 Check_No_Identifier (Arg_Node);
11646 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11647 -- will in fact generate reference, so that the entity will
11648 -- have a reference, which will inhibit any warnings about
11649 -- it not being referenced, and also properly show up in the
11650 -- ali file as a reference. But this reference is recorded
11651 -- before the Has_Pragma_Unreferenced flag is set, so that
11652 -- no warning is generated for this reference.
11654 Check_Arg_Is_Local_Name (Arg_Node);
11655 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11657 if Is_Entity_Name (Arg_Expr) then
11658 Arg_Ent := Entity (Arg_Expr);
11660 -- If the entity is overloaded, the pragma applies to the
11661 -- most recent overloading, as documented. In this case,
11662 -- name resolution does not generate a reference, so it
11663 -- must be done here explicitly.
11665 if Is_Overloaded (Arg_Expr) then
11666 Generate_Reference (Arg_Ent, N);
11669 Set_Has_Pragma_Unreferenced (Arg_Ent);
11677 --------------------------
11678 -- Unreferenced_Objects --
11679 --------------------------
11681 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11683 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11684 Arg_Node : Node_Id;
11685 Arg_Expr : Node_Id;
11689 Check_At_Least_N_Arguments (1);
11692 while Present (Arg_Node) loop
11693 Check_No_Identifier (Arg_Node);
11694 Check_Arg_Is_Local_Name (Arg_Node);
11695 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11697 if not Is_Entity_Name (Arg_Expr)
11698 or else not Is_Type (Entity (Arg_Expr))
11701 ("argument for pragma% must be type or subtype", Arg_Node);
11704 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11707 end Unreferenced_Objects;
11709 ------------------------------
11710 -- Unreserve_All_Interrupts --
11711 ------------------------------
11713 -- pragma Unreserve_All_Interrupts;
11715 when Pragma_Unreserve_All_Interrupts =>
11717 Check_Arg_Count (0);
11719 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11720 Unreserve_All_Interrupts := True;
11727 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11729 when Pragma_Unsuppress =>
11731 Process_Suppress_Unsuppress (False);
11733 -------------------
11734 -- Use_VADS_Size --
11735 -------------------
11737 -- pragma Use_VADS_Size;
11739 when Pragma_Use_VADS_Size =>
11741 Check_Arg_Count (0);
11742 Check_Valid_Configuration_Pragma;
11743 Use_VADS_Size := True;
11745 ---------------------
11746 -- Validity_Checks --
11747 ---------------------
11749 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11751 when Pragma_Validity_Checks => Validity_Checks : declare
11752 A : constant Node_Id := Expression (Arg1);
11758 Check_Arg_Count (1);
11759 Check_No_Identifiers;
11761 if Nkind (A) = N_String_Literal then
11765 Slen : constant Natural := Natural (String_Length (S));
11766 Options : String (1 .. Slen);
11772 C := Get_String_Char (S, Int (J));
11773 exit when not In_Character_Range (C);
11774 Options (J) := Get_Character (C);
11777 Set_Validity_Check_Options (Options);
11785 elsif Nkind (A) = N_Identifier then
11787 if Chars (A) = Name_All_Checks then
11788 Set_Validity_Check_Options ("a");
11790 elsif Chars (A) = Name_On then
11791 Validity_Checks_On := True;
11793 elsif Chars (A) = Name_Off then
11794 Validity_Checks_On := False;
11798 end Validity_Checks;
11804 -- pragma Volatile (LOCAL_NAME);
11806 when Pragma_Volatile =>
11807 Process_Atomic_Shared_Volatile;
11809 -------------------------
11810 -- Volatile_Components --
11811 -------------------------
11813 -- pragma Volatile_Components (array_LOCAL_NAME);
11815 -- Volatile is handled by the same circuit as Atomic_Components
11821 -- pragma Warnings (On | Off);
11822 -- pragma Warnings (On | Off, LOCAL_NAME);
11823 -- pragma Warnings (static_string_EXPRESSION);
11824 -- pragma Warnings (On | Off, STRING_LITERAL);
11826 when Pragma_Warnings => Warnings : begin
11828 Check_At_Least_N_Arguments (1);
11829 Check_No_Identifiers;
11832 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11835 -- One argument case
11837 if Arg_Count = 1 then
11839 -- On/Off one argument case was processed by parser
11841 if Nkind (Argx) = N_Identifier
11843 (Chars (Argx) = Name_On
11845 Chars (Argx) = Name_Off)
11849 -- One argument case must be ON/OFF or static string expr
11851 elsif not Is_Static_String_Expression (Arg1) then
11853 ("argument of pragma% must be On/Off or " &
11854 "static string expression", Arg2);
11856 -- One argument string expression case
11860 Lit : constant Node_Id := Expr_Value_S (Argx);
11861 Str : constant String_Id := Strval (Lit);
11862 Len : constant Nat := String_Length (Str);
11870 while J <= Len loop
11871 C := Get_String_Char (Str, J);
11872 OK := In_Character_Range (C);
11875 Chr := Get_Character (C);
11879 if J < Len and then Chr = '.' then
11881 C := Get_String_Char (Str, J);
11882 Chr := Get_Character (C);
11884 if not Set_Dot_Warning_Switch (Chr) then
11886 ("invalid warning switch character " &
11893 OK := Set_Warning_Switch (Chr);
11899 ("invalid warning switch character " & Chr,
11908 -- Two or more arguments (must be two)
11911 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11912 Check_At_Most_N_Arguments (2);
11920 E_Id := Expression (Arg2);
11923 -- In the expansion of an inlined body, a reference to
11924 -- the formal may be wrapped in a conversion if the
11925 -- actual is a conversion. Retrieve the real entity name.
11927 if (In_Instance_Body
11928 or else In_Inlined_Body)
11929 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
11931 E_Id := Expression (E_Id);
11934 -- Entity name case
11936 if Is_Entity_Name (E_Id) then
11937 E := Entity (E_Id);
11944 (E, (Chars (Expression (Arg1)) = Name_Off));
11946 if Chars (Expression (Arg1)) = Name_Off
11947 and then Warn_On_Warnings_Off
11949 Warnings_Off_Pragmas.Append ((N, E));
11952 if Is_Enumeration_Type (E) then
11956 Lit := First_Literal (E);
11957 while Present (Lit) loop
11958 Set_Warnings_Off (Lit);
11959 Next_Literal (Lit);
11964 exit when No (Homonym (E));
11969 -- Error if not entity or static string literal case
11971 elsif not Is_Static_String_Expression (Arg2) then
11973 ("second argument of pragma% must be entity " &
11974 "name or static string expression", Arg2);
11976 -- String literal case
11979 String_To_Name_Buffer
11980 (Strval (Expr_Value_S (Expression (Arg2))));
11982 -- Note on configuration pragma case: If this is a
11983 -- configuration pragma, then for an OFF pragma, we
11984 -- just set Config True in the call, which is all
11985 -- that needs to be done. For the case of ON, this
11986 -- is normally an error, unless it is canceling the
11987 -- effect of a previous OFF pragma in the same file.
11988 -- In any other case, an error will be signalled (ON
11989 -- with no matching OFF).
11991 if Chars (Argx) = Name_Off then
11992 Set_Specific_Warning_Off
11993 (Loc, Name_Buffer (1 .. Name_Len),
11994 Config => Is_Configuration_Pragma);
11996 elsif Chars (Argx) = Name_On then
11997 Set_Specific_Warning_On
11998 (Loc, Name_Buffer (1 .. Name_Len), Err);
12002 ("?pragma Warnings On with no " &
12003 "matching Warnings Off",
12013 -------------------
12014 -- Weak_External --
12015 -------------------
12017 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12019 when Pragma_Weak_External => Weak_External : declare
12024 Check_Arg_Count (1);
12025 Check_Optional_Identifier (Arg1, Name_Entity);
12026 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12027 Ent := Entity (Expression (Arg1));
12029 if Rep_Item_Too_Early (Ent, N) then
12032 Ent := Underlying_Type (Ent);
12035 -- The only processing required is to link this item on to the
12036 -- list of rep items for the given entity. This is accomplished
12037 -- by the call to Rep_Item_Too_Late (when no error is detected
12038 -- and False is returned).
12040 if Rep_Item_Too_Late (Ent, N) then
12043 Set_Has_Gigi_Rep_Item (Ent);
12047 -----------------------------
12048 -- Wide_Character_Encoding --
12049 -----------------------------
12051 -- pragma Wide_Character_Encoding (IDENTIFIER);
12053 when Pragma_Wide_Character_Encoding =>
12056 -- Nothing to do, handled in parser. Note that we do not enforce
12057 -- configuration pragma placement, this pragma can appear at any
12058 -- place in the source, allowing mixed encodings within a single
12063 --------------------
12064 -- Unknown_Pragma --
12065 --------------------
12067 -- Should be impossible, since the case of an unknown pragma is
12068 -- separately processed before the case statement is entered.
12070 when Unknown_Pragma =>
12071 raise Program_Error;
12075 when Pragma_Exit => null;
12076 end Analyze_Pragma;
12078 -------------------
12079 -- Check_Enabled --
12080 -------------------
12082 function Check_Enabled (Nam : Name_Id) return Boolean is
12086 PP := Opt.Check_Policy_List;
12089 return Assertions_Enabled;
12092 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12095 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12097 when Name_On | Name_Check =>
12099 when Name_Off | Name_Ignore =>
12102 raise Program_Error;
12106 PP := Next_Pragma (PP);
12111 ---------------------------------
12112 -- Delay_Config_Pragma_Analyze --
12113 ---------------------------------
12115 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12117 return Pragma_Name (N) = Name_Interrupt_State
12119 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12120 end Delay_Config_Pragma_Analyze;
12122 -------------------------
12123 -- Get_Base_Subprogram --
12124 -------------------------
12126 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12127 Result : Entity_Id;
12130 -- Follow subprogram renaming chain
12133 while Is_Subprogram (Result)
12135 (Is_Generic_Instance (Result)
12136 or else Nkind (Parent (Declaration_Node (Result))) =
12137 N_Subprogram_Renaming_Declaration)
12138 and then Present (Alias (Result))
12140 Result := Alias (Result);
12144 end Get_Base_Subprogram;
12146 --------------------
12147 -- Get_Pragma_Arg --
12148 --------------------
12150 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12152 if Nkind (Arg) = N_Pragma_Argument_Association then
12153 return Expression (Arg);
12157 end Get_Pragma_Arg;
12163 procedure Initialize is
12168 -----------------------------
12169 -- Is_Config_Static_String --
12170 -----------------------------
12172 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12174 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12175 -- This is an internal recursive function that is just like the outer
12176 -- function except that it adds the string to the name buffer rather
12177 -- than placing the string in the name buffer.
12179 ------------------------------
12180 -- Add_Config_Static_String --
12181 ------------------------------
12183 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12190 if Nkind (N) = N_Op_Concat then
12191 if Add_Config_Static_String (Left_Opnd (N)) then
12192 N := Right_Opnd (N);
12198 if Nkind (N) /= N_String_Literal then
12199 Error_Msg_N ("string literal expected for pragma argument", N);
12203 for J in 1 .. String_Length (Strval (N)) loop
12204 C := Get_String_Char (Strval (N), J);
12206 if not In_Character_Range (C) then
12208 ("string literal contains invalid wide character",
12209 Sloc (N) + 1 + Source_Ptr (J));
12213 Add_Char_To_Name_Buffer (Get_Character (C));
12218 end Add_Config_Static_String;
12220 -- Start of processing for Is_Config_Static_String
12225 return Add_Config_Static_String (Arg);
12226 end Is_Config_Static_String;
12228 -----------------------------------------
12229 -- Is_Non_Significant_Pragma_Reference --
12230 -----------------------------------------
12232 -- This function makes use of the following static table which indicates
12233 -- whether a given pragma is significant. A value of -1 in this table
12234 -- indicates that the reference is significant. A value of zero indicates
12235 -- than appearance as any argument is insignificant, a positive value
12236 -- indicates that appearance in that parameter position is significant.
12238 -- A value of 99 flags a special case requiring a special check (this is
12239 -- used for cases not covered by this standard encoding, e.g. pragma Check
12240 -- where the first argument is not significant, but the others are).
12242 Sig_Flags : constant array (Pragma_Id) of Int :=
12243 (Pragma_AST_Entry => -1,
12244 Pragma_Abort_Defer => -1,
12245 Pragma_Ada_83 => -1,
12246 Pragma_Ada_95 => -1,
12247 Pragma_Ada_05 => -1,
12248 Pragma_Ada_2005 => -1,
12249 Pragma_All_Calls_Remote => -1,
12250 Pragma_Annotate => -1,
12251 Pragma_Assert => -1,
12252 Pragma_Assertion_Policy => 0,
12253 Pragma_Assume_No_Invalid_Values => 0,
12254 Pragma_Asynchronous => -1,
12255 Pragma_Atomic => 0,
12256 Pragma_Atomic_Components => 0,
12257 Pragma_Attach_Handler => -1,
12258 Pragma_Check => 99,
12259 Pragma_Check_Name => 0,
12260 Pragma_Check_Policy => 0,
12261 Pragma_CIL_Constructor => -1,
12262 Pragma_CPP_Class => 0,
12263 Pragma_CPP_Constructor => 0,
12264 Pragma_CPP_Virtual => 0,
12265 Pragma_CPP_Vtable => 0,
12266 Pragma_C_Pass_By_Copy => 0,
12267 Pragma_Comment => 0,
12268 Pragma_Common_Object => -1,
12269 Pragma_Compile_Time_Error => -1,
12270 Pragma_Compile_Time_Warning => -1,
12271 Pragma_Compiler_Unit => 0,
12272 Pragma_Complete_Representation => 0,
12273 Pragma_Complex_Representation => 0,
12274 Pragma_Component_Alignment => -1,
12275 Pragma_Controlled => 0,
12276 Pragma_Convention => 0,
12277 Pragma_Convention_Identifier => 0,
12278 Pragma_Debug => -1,
12279 Pragma_Debug_Policy => 0,
12280 Pragma_Detect_Blocking => -1,
12281 Pragma_Discard_Names => 0,
12282 Pragma_Elaborate => -1,
12283 Pragma_Elaborate_All => -1,
12284 Pragma_Elaborate_Body => -1,
12285 Pragma_Elaboration_Checks => -1,
12286 Pragma_Eliminate => -1,
12287 Pragma_Export => -1,
12288 Pragma_Export_Exception => -1,
12289 Pragma_Export_Function => -1,
12290 Pragma_Export_Object => -1,
12291 Pragma_Export_Procedure => -1,
12292 Pragma_Export_Value => -1,
12293 Pragma_Export_Valued_Procedure => -1,
12294 Pragma_Extend_System => -1,
12295 Pragma_Extensions_Allowed => -1,
12296 Pragma_External => -1,
12297 Pragma_Favor_Top_Level => -1,
12298 Pragma_External_Name_Casing => -1,
12299 Pragma_Fast_Math => -1,
12300 Pragma_Finalize_Storage_Only => 0,
12301 Pragma_Float_Representation => 0,
12302 Pragma_Ident => -1,
12303 Pragma_Implemented_By_Entry => -1,
12304 Pragma_Implicit_Packing => 0,
12305 Pragma_Import => +2,
12306 Pragma_Import_Exception => 0,
12307 Pragma_Import_Function => 0,
12308 Pragma_Import_Object => 0,
12309 Pragma_Import_Procedure => 0,
12310 Pragma_Import_Valued_Procedure => 0,
12311 Pragma_Initialize_Scalars => -1,
12312 Pragma_Inline => 0,
12313 Pragma_Inline_Always => 0,
12314 Pragma_Inline_Generic => 0,
12315 Pragma_Inspection_Point => -1,
12316 Pragma_Interface => +2,
12317 Pragma_Interface_Name => +2,
12318 Pragma_Interrupt_Handler => -1,
12319 Pragma_Interrupt_Priority => -1,
12320 Pragma_Interrupt_State => -1,
12321 Pragma_Java_Constructor => -1,
12322 Pragma_Java_Interface => -1,
12323 Pragma_Keep_Names => 0,
12324 Pragma_License => -1,
12325 Pragma_Link_With => -1,
12326 Pragma_Linker_Alias => -1,
12327 Pragma_Linker_Constructor => -1,
12328 Pragma_Linker_Destructor => -1,
12329 Pragma_Linker_Options => -1,
12330 Pragma_Linker_Section => -1,
12332 Pragma_Locking_Policy => -1,
12333 Pragma_Long_Float => -1,
12334 Pragma_Machine_Attribute => -1,
12336 Pragma_Main_Storage => -1,
12337 Pragma_Memory_Size => -1,
12338 Pragma_No_Return => 0,
12339 Pragma_No_Body => 0,
12340 Pragma_No_Run_Time => -1,
12341 Pragma_No_Strict_Aliasing => -1,
12342 Pragma_Normalize_Scalars => -1,
12343 Pragma_Obsolescent => 0,
12344 Pragma_Optimize => -1,
12345 Pragma_Optimize_Alignment => -1,
12348 Pragma_Passive => -1,
12349 Pragma_Preelaborable_Initialization => -1,
12350 Pragma_Polling => -1,
12351 Pragma_Persistent_BSS => 0,
12352 Pragma_Postcondition => -1,
12353 Pragma_Precondition => -1,
12354 Pragma_Preelaborate => -1,
12355 Pragma_Preelaborate_05 => -1,
12356 Pragma_Priority => -1,
12357 Pragma_Priority_Specific_Dispatching => -1,
12358 Pragma_Profile => 0,
12359 Pragma_Profile_Warnings => 0,
12360 Pragma_Propagate_Exceptions => -1,
12361 Pragma_Psect_Object => -1,
12363 Pragma_Pure_05 => -1,
12364 Pragma_Pure_Function => -1,
12365 Pragma_Queuing_Policy => -1,
12366 Pragma_Ravenscar => -1,
12367 Pragma_Relative_Deadline => -1,
12368 Pragma_Remote_Call_Interface => -1,
12369 Pragma_Remote_Types => -1,
12370 Pragma_Restricted_Run_Time => -1,
12371 Pragma_Restriction_Warnings => -1,
12372 Pragma_Restrictions => -1,
12373 Pragma_Reviewable => -1,
12374 Pragma_Share_Generic => -1,
12375 Pragma_Shared => -1,
12376 Pragma_Shared_Passive => -1,
12377 Pragma_Source_File_Name => -1,
12378 Pragma_Source_File_Name_Project => -1,
12379 Pragma_Source_Reference => -1,
12380 Pragma_Storage_Size => -1,
12381 Pragma_Storage_Unit => -1,
12382 Pragma_Static_Elaboration_Desired => -1,
12383 Pragma_Stream_Convert => -1,
12384 Pragma_Style_Checks => -1,
12385 Pragma_Subtitle => -1,
12386 Pragma_Suppress => 0,
12387 Pragma_Suppress_Exception_Locations => 0,
12388 Pragma_Suppress_All => -1,
12389 Pragma_Suppress_Debug_Info => 0,
12390 Pragma_Suppress_Initialization => 0,
12391 Pragma_System_Name => -1,
12392 Pragma_Task_Dispatching_Policy => -1,
12393 Pragma_Task_Info => -1,
12394 Pragma_Task_Name => -1,
12395 Pragma_Task_Storage => 0,
12396 Pragma_Thread_Local_Storage => 0,
12397 Pragma_Time_Slice => -1,
12398 Pragma_Title => -1,
12399 Pragma_Unchecked_Union => 0,
12400 Pragma_Unimplemented_Unit => -1,
12401 Pragma_Universal_Aliasing => -1,
12402 Pragma_Universal_Data => -1,
12403 Pragma_Unmodified => -1,
12404 Pragma_Unreferenced => -1,
12405 Pragma_Unreferenced_Objects => -1,
12406 Pragma_Unreserve_All_Interrupts => -1,
12407 Pragma_Unsuppress => 0,
12408 Pragma_Use_VADS_Size => -1,
12409 Pragma_Validity_Checks => -1,
12410 Pragma_Volatile => 0,
12411 Pragma_Volatile_Components => 0,
12412 Pragma_Warnings => -1,
12413 Pragma_Weak_External => -1,
12414 Pragma_Wide_Character_Encoding => 0,
12415 Unknown_Pragma => 0);
12417 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12426 if Nkind (P) /= N_Pragma_Argument_Association then
12430 Id := Get_Pragma_Id (Parent (P));
12431 C := Sig_Flags (Id);
12443 -- For pragma Check, the first argument is not significant,
12444 -- the second and the third (if present) arguments are
12447 when Pragma_Check =>
12449 P = First (Pragma_Argument_Associations (Parent (P)));
12452 raise Program_Error;
12456 A := First (Pragma_Argument_Associations (Parent (P)));
12457 for J in 1 .. C - 1 loop
12465 return A = P; -- is this wrong way round ???
12468 end Is_Non_Significant_Pragma_Reference;
12470 ------------------------------
12471 -- Is_Pragma_String_Literal --
12472 ------------------------------
12474 -- This function returns true if the corresponding pragma argument is a
12475 -- static string expression. These are the only cases in which string
12476 -- literals can appear as pragma arguments. We also allow a string literal
12477 -- as the first argument to pragma Assert (although it will of course
12478 -- always generate a type error).
12480 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12481 Pragn : constant Node_Id := Parent (Par);
12482 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12483 Pname : constant Name_Id := Pragma_Name (Pragn);
12489 N := First (Assoc);
12496 if Pname = Name_Assert then
12499 elsif Pname = Name_Export then
12502 elsif Pname = Name_Ident then
12505 elsif Pname = Name_Import then
12508 elsif Pname = Name_Interface_Name then
12511 elsif Pname = Name_Linker_Alias then
12514 elsif Pname = Name_Linker_Section then
12517 elsif Pname = Name_Machine_Attribute then
12520 elsif Pname = Name_Source_File_Name then
12523 elsif Pname = Name_Source_Reference then
12526 elsif Pname = Name_Title then
12529 elsif Pname = Name_Subtitle then
12535 end Is_Pragma_String_Literal;
12537 --------------------------------------
12538 -- Process_Compilation_Unit_Pragmas --
12539 --------------------------------------
12541 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12543 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12544 -- strange because it comes at the end of the unit. If we have a pragma
12545 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12546 -- a pragma Suppress (All_Checks) at the start of the context clause to
12547 -- ensure the correct processing.
12550 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12554 if Present (PA) then
12556 while Present (P) loop
12557 if Pragma_Name (P) = Name_Suppress_All then
12558 Prepend_To (Context_Items (N),
12559 Make_Pragma (Sloc (P),
12560 Chars => Name_Suppress,
12561 Pragma_Argument_Associations => New_List (
12562 Make_Pragma_Argument_Association (Sloc (P),
12564 Make_Identifier (Sloc (P),
12565 Chars => Name_All_Checks)))));
12573 end Process_Compilation_Unit_Pragmas;
12584 --------------------------------
12585 -- Set_Encoded_Interface_Name --
12586 --------------------------------
12588 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12589 Str : constant String_Id := Strval (S);
12590 Len : constant Int := String_Length (Str);
12595 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12598 -- Stores encoded value of character code CC. The encoding we use an
12599 -- underscore followed by four lower case hex digits.
12605 procedure Encode is
12607 Store_String_Char (Get_Char_Code ('_'));
12609 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12611 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12613 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12615 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12618 -- Start of processing for Set_Encoded_Interface_Name
12621 -- If first character is asterisk, this is a link name, and we leave it
12622 -- completely unmodified. We also ignore null strings (the latter case
12623 -- happens only in error cases) and no encoding should occur for Java or
12624 -- AAMP interface names.
12627 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12628 or else VM_Target /= No_VM
12629 or else AAMP_On_Target
12631 Set_Interface_Name (E, S);
12636 CC := Get_String_Char (Str, J);
12638 exit when not In_Character_Range (CC);
12640 C := Get_Character (CC);
12642 exit when C /= '_' and then C /= '$'
12643 and then C not in '0' .. '9'
12644 and then C not in 'a' .. 'z'
12645 and then C not in 'A' .. 'Z';
12648 Set_Interface_Name (E, S);
12656 -- Here we need to encode. The encoding we use as follows:
12657 -- three underscores + four hex digits (lower case)
12661 for J in 1 .. String_Length (Str) loop
12662 CC := Get_String_Char (Str, J);
12664 if not In_Character_Range (CC) then
12667 C := Get_Character (CC);
12669 if C = '_' or else C = '$'
12670 or else C in '0' .. '9'
12671 or else C in 'a' .. 'z'
12672 or else C in 'A' .. 'Z'
12674 Store_String_Char (CC);
12681 Set_Interface_Name (E,
12682 Make_String_Literal (Sloc (S),
12683 Strval => End_String));
12685 end Set_Encoded_Interface_Name;
12687 -------------------
12688 -- Set_Unit_Name --
12689 -------------------
12691 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12696 if Nkind (N) = N_Identifier
12697 and then Nkind (With_Item) = N_Identifier
12699 Set_Entity (N, Entity (With_Item));
12701 elsif Nkind (N) = N_Selected_Component then
12702 Change_Selected_Component_To_Expanded_Name (N);
12703 Set_Entity (N, Entity (With_Item));
12704 Set_Entity (Selector_Name (N), Entity (N));
12706 Pref := Prefix (N);
12707 Scop := Scope (Entity (N));
12708 while Nkind (Pref) = N_Selected_Component loop
12709 Change_Selected_Component_To_Expanded_Name (Pref);
12710 Set_Entity (Selector_Name (Pref), Scop);
12711 Set_Entity (Pref, Scop);
12712 Pref := Prefix (Pref);
12713 Scop := Scope (Scop);
12716 Set_Entity (Pref, Scop);