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
1460 or else Inside_A_Generic
1463 -- Analyze expression in pragma, for correctness
1464 -- and for ASIS use.
1466 Preanalyze_Spec_Expression
1467 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1473 -- See if it is in the pragmas after a library level subprogram
1475 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1476 Chain_PPC (Unit (Parent (Parent (N))));
1480 -- If we fall through, pragma was misplaced
1483 end Check_Precondition_Postcondition;
1485 -----------------------------
1486 -- Check_Static_Constraint --
1487 -----------------------------
1489 -- Note: for convenience in writing this procedure, in addition to
1490 -- the officially (i.e. by spec) allowed argument which is always a
1491 -- constraint, it also allows ranges and discriminant associations.
1492 -- Above is not clear ???
1494 procedure Check_Static_Constraint (Constr : Node_Id) is
1496 procedure Require_Static (E : Node_Id);
1497 -- Require given expression to be static expression
1499 --------------------
1500 -- Require_Static --
1501 --------------------
1503 procedure Require_Static (E : Node_Id) is
1505 if not Is_OK_Static_Expression (E) then
1506 Flag_Non_Static_Expr
1507 ("non-static constraint not allowed in Unchecked_Union!", E);
1512 -- Start of processing for Check_Static_Constraint
1515 case Nkind (Constr) is
1516 when N_Discriminant_Association =>
1517 Require_Static (Expression (Constr));
1520 Require_Static (Low_Bound (Constr));
1521 Require_Static (High_Bound (Constr));
1523 when N_Attribute_Reference =>
1524 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1525 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1527 when N_Range_Constraint =>
1528 Check_Static_Constraint (Range_Expression (Constr));
1530 when N_Index_Or_Discriminant_Constraint =>
1534 IDC := First (Constraints (Constr));
1535 while Present (IDC) loop
1536 Check_Static_Constraint (IDC);
1544 end Check_Static_Constraint;
1546 --------------------------------------
1547 -- Check_Valid_Configuration_Pragma --
1548 --------------------------------------
1550 -- A configuration pragma must appear in the context clause of a
1551 -- compilation unit, and only other pragmas may precede it. Note that
1552 -- the test also allows use in a configuration pragma file.
1554 procedure Check_Valid_Configuration_Pragma is
1556 if not Is_Configuration_Pragma then
1557 Error_Pragma ("incorrect placement for configuration pragma%");
1559 end Check_Valid_Configuration_Pragma;
1561 -------------------------------------
1562 -- Check_Valid_Library_Unit_Pragma --
1563 -------------------------------------
1565 procedure Check_Valid_Library_Unit_Pragma is
1567 Parent_Node : Node_Id;
1568 Unit_Name : Entity_Id;
1569 Unit_Kind : Node_Kind;
1570 Unit_Node : Node_Id;
1571 Sindex : Source_File_Index;
1574 if not Is_List_Member (N) then
1578 Plist := List_Containing (N);
1579 Parent_Node := Parent (Plist);
1581 if Parent_Node = Empty then
1584 -- Case of pragma appearing after a compilation unit. In this case
1585 -- it must have an argument with the corresponding name and must
1586 -- be part of the following pragmas of its parent.
1588 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1589 if Plist /= Pragmas_After (Parent_Node) then
1592 elsif Arg_Count = 0 then
1594 ("argument required if outside compilation unit");
1597 Check_No_Identifiers;
1598 Check_Arg_Count (1);
1599 Unit_Node := Unit (Parent (Parent_Node));
1600 Unit_Kind := Nkind (Unit_Node);
1602 Analyze (Expression (Arg1));
1604 if Unit_Kind = N_Generic_Subprogram_Declaration
1605 or else Unit_Kind = N_Subprogram_Declaration
1607 Unit_Name := Defining_Entity (Unit_Node);
1609 elsif Unit_Kind in N_Generic_Instantiation then
1610 Unit_Name := Defining_Entity (Unit_Node);
1613 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1616 if Chars (Unit_Name) /=
1617 Chars (Entity (Expression (Arg1)))
1620 ("pragma% argument is not current unit name", Arg1);
1623 if Ekind (Unit_Name) = E_Package
1624 and then Present (Renamed_Entity (Unit_Name))
1626 Error_Pragma ("pragma% not allowed for renamed package");
1630 -- Pragma appears other than after a compilation unit
1633 -- Here we check for the generic instantiation case and also
1634 -- for the case of processing a generic formal package. We
1635 -- detect these cases by noting that the Sloc on the node
1636 -- does not belong to the current compilation unit.
1638 Sindex := Source_Index (Current_Sem_Unit);
1640 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1641 Rewrite (N, Make_Null_Statement (Loc));
1644 -- If before first declaration, the pragma applies to the
1645 -- enclosing unit, and the name if present must be this name.
1647 elsif Is_Before_First_Decl (N, Plist) then
1648 Unit_Node := Unit_Declaration_Node (Current_Scope);
1649 Unit_Kind := Nkind (Unit_Node);
1651 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1654 elsif Unit_Kind = N_Subprogram_Body
1655 and then not Acts_As_Spec (Unit_Node)
1659 elsif Nkind (Parent_Node) = N_Package_Body then
1662 elsif Nkind (Parent_Node) = N_Package_Specification
1663 and then Plist = Private_Declarations (Parent_Node)
1667 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1668 or else Nkind (Parent_Node) =
1669 N_Generic_Subprogram_Declaration)
1670 and then Plist = Generic_Formal_Declarations (Parent_Node)
1674 elsif Arg_Count > 0 then
1675 Analyze (Expression (Arg1));
1677 if Entity (Expression (Arg1)) /= Current_Scope then
1679 ("name in pragma% must be enclosing unit", Arg1);
1682 -- It is legal to have no argument in this context
1688 -- Error if not before first declaration. This is because a
1689 -- library unit pragma argument must be the name of a library
1690 -- unit (RM 10.1.5(7)), but the only names permitted in this
1691 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1692 -- generic subprogram declarations or generic instantiations.
1696 ("pragma% misplaced, must be before first declaration");
1700 end Check_Valid_Library_Unit_Pragma;
1706 procedure Check_Variant (Variant : Node_Id) is
1707 Clist : constant Node_Id := Component_List (Variant);
1711 if not Is_Non_Empty_List (Component_Items (Clist)) then
1713 ("Unchecked_Union may not have empty component list",
1718 Comp := First (Component_Items (Clist));
1719 while Present (Comp) loop
1720 Check_Component (Comp);
1729 procedure Error_Pragma (Msg : String) is
1731 Error_Msg_Name_1 := Pname;
1732 Error_Msg_N (Msg, N);
1736 ----------------------
1737 -- Error_Pragma_Arg --
1738 ----------------------
1740 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1742 Error_Msg_Name_1 := Pname;
1743 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1745 end Error_Pragma_Arg;
1747 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1749 Error_Msg_Name_1 := Pname;
1750 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1751 Error_Pragma_Arg (Msg2, Arg);
1752 end Error_Pragma_Arg;
1754 ----------------------------
1755 -- Error_Pragma_Arg_Ident --
1756 ----------------------------
1758 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1760 Error_Msg_Name_1 := Pname;
1761 Error_Msg_N (Msg, Arg);
1763 end Error_Pragma_Arg_Ident;
1765 ----------------------
1766 -- Error_Pragma_Ref --
1767 ----------------------
1769 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1771 Error_Msg_Name_1 := Pname;
1772 Error_Msg_Sloc := Sloc (Ref);
1773 Error_Msg_NE (Msg, N, Ref);
1775 end Error_Pragma_Ref;
1777 ------------------------
1778 -- Find_Lib_Unit_Name --
1779 ------------------------
1781 function Find_Lib_Unit_Name return Entity_Id is
1783 -- Return inner compilation unit entity, for case of nested
1784 -- categorization pragmas. This happens in generic unit.
1786 if Nkind (Parent (N)) = N_Package_Specification
1787 and then Defining_Entity (Parent (N)) /= Current_Scope
1789 return Defining_Entity (Parent (N));
1791 return Current_Scope;
1793 end Find_Lib_Unit_Name;
1795 ----------------------------
1796 -- Find_Program_Unit_Name --
1797 ----------------------------
1799 procedure Find_Program_Unit_Name (Id : Node_Id) is
1800 Unit_Name : Entity_Id;
1801 Unit_Kind : Node_Kind;
1802 P : constant Node_Id := Parent (N);
1805 if Nkind (P) = N_Compilation_Unit then
1806 Unit_Kind := Nkind (Unit (P));
1808 if Unit_Kind = N_Subprogram_Declaration
1809 or else Unit_Kind = N_Package_Declaration
1810 or else Unit_Kind in N_Generic_Declaration
1812 Unit_Name := Defining_Entity (Unit (P));
1814 if Chars (Id) = Chars (Unit_Name) then
1815 Set_Entity (Id, Unit_Name);
1816 Set_Etype (Id, Etype (Unit_Name));
1818 Set_Etype (Id, Any_Type);
1820 ("cannot find program unit referenced by pragma%");
1824 Set_Etype (Id, Any_Type);
1825 Error_Pragma ("pragma% inapplicable to this unit");
1831 end Find_Program_Unit_Name;
1833 -----------------------------------------
1834 -- Find_Unique_Parameterless_Procedure --
1835 -----------------------------------------
1837 function Find_Unique_Parameterless_Procedure
1839 Arg : Node_Id) return Entity_Id
1841 Proc : Entity_Id := Empty;
1844 -- The body of this procedure needs some comments ???
1846 if not Is_Entity_Name (Name) then
1848 ("argument of pragma% must be entity name", Arg);
1850 elsif not Is_Overloaded (Name) then
1851 Proc := Entity (Name);
1853 if Ekind (Proc) /= E_Procedure
1854 or else Present (First_Formal (Proc)) then
1856 ("argument of pragma% must be parameterless procedure", Arg);
1861 Found : Boolean := False;
1863 Index : Interp_Index;
1866 Get_First_Interp (Name, Index, It);
1867 while Present (It.Nam) loop
1870 if Ekind (Proc) = E_Procedure
1871 and then No (First_Formal (Proc))
1875 Set_Entity (Name, Proc);
1876 Set_Is_Overloaded (Name, False);
1879 ("ambiguous handler name for pragma% ", Arg);
1883 Get_Next_Interp (Index, It);
1888 ("argument of pragma% must be parameterless procedure",
1891 Proc := Entity (Name);
1897 end Find_Unique_Parameterless_Procedure;
1899 -------------------------
1900 -- Gather_Associations --
1901 -------------------------
1903 procedure Gather_Associations
1905 Args : out Args_List)
1910 -- Initialize all parameters to Empty
1912 for J in Args'Range loop
1916 -- That's all we have to do if there are no argument associations
1918 if No (Pragma_Argument_Associations (N)) then
1922 -- Otherwise first deal with any positional parameters present
1924 Arg := First (Pragma_Argument_Associations (N));
1925 for Index in Args'Range loop
1926 exit when No (Arg) or else Chars (Arg) /= No_Name;
1927 Args (Index) := Expression (Arg);
1931 -- Positional parameters all processed, if any left, then we
1932 -- have too many positional parameters.
1934 if Present (Arg) and then Chars (Arg) = No_Name then
1936 ("too many positional associations for pragma%", Arg);
1939 -- Process named parameters if any are present
1941 while Present (Arg) loop
1942 if Chars (Arg) = No_Name then
1944 ("positional association cannot follow named association",
1948 for Index in Names'Range loop
1949 if Names (Index) = Chars (Arg) then
1950 if Present (Args (Index)) then
1952 ("duplicate argument association for pragma%", Arg);
1954 Args (Index) := Expression (Arg);
1959 if Index = Names'Last then
1960 Error_Msg_Name_1 := Pname;
1961 Error_Msg_N ("pragma% does not allow & argument", Arg);
1963 -- Check for possible misspelling
1965 for Index1 in Names'Range loop
1966 if Is_Bad_Spelling_Of
1967 (Chars (Arg), Names (Index1))
1969 Error_Msg_Name_1 := Names (Index1);
1970 Error_Msg_N ("\possible misspelling of%", Arg);
1982 end Gather_Associations;
1988 procedure GNAT_Pragma is
1990 Check_Restriction (No_Implementation_Pragmas, N);
1993 --------------------------
1994 -- Is_Before_First_Decl --
1995 --------------------------
1997 function Is_Before_First_Decl
1998 (Pragma_Node : Node_Id;
1999 Decls : List_Id) return Boolean
2001 Item : Node_Id := First (Decls);
2004 -- Only other pragmas can come before this pragma
2007 if No (Item) or else Nkind (Item) /= N_Pragma then
2010 elsif Item = Pragma_Node then
2016 end Is_Before_First_Decl;
2018 -----------------------------
2019 -- Is_Configuration_Pragma --
2020 -----------------------------
2022 -- A configuration pragma must appear in the context clause of a
2023 -- compilation unit, and only other pragmas may precede it. Note that
2024 -- the test below also permits use in a configuration pragma file.
2026 function Is_Configuration_Pragma return Boolean is
2027 Lis : constant List_Id := List_Containing (N);
2028 Par : constant Node_Id := Parent (N);
2032 -- If no parent, then we are in the configuration pragma file,
2033 -- so the placement is definitely appropriate.
2038 -- Otherwise we must be in the context clause of a compilation unit
2039 -- and the only thing allowed before us in the context list is more
2040 -- configuration pragmas.
2042 elsif Nkind (Par) = N_Compilation_Unit
2043 and then Context_Items (Par) = Lis
2050 elsif Nkind (Prg) /= N_Pragma then
2060 end Is_Configuration_Pragma;
2062 --------------------------
2063 -- Is_In_Context_Clause --
2064 --------------------------
2066 function Is_In_Context_Clause return Boolean is
2068 Parent_Node : Node_Id;
2071 if not Is_List_Member (N) then
2075 Plist := List_Containing (N);
2076 Parent_Node := Parent (Plist);
2078 if Parent_Node = Empty
2079 or else Nkind (Parent_Node) /= N_Compilation_Unit
2080 or else Context_Items (Parent_Node) /= Plist
2087 end Is_In_Context_Clause;
2089 ---------------------------------
2090 -- Is_Static_String_Expression --
2091 ---------------------------------
2093 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2094 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2097 Analyze_And_Resolve (Argx);
2098 return Is_OK_Static_Expression (Argx)
2099 and then Nkind (Argx) = N_String_Literal;
2100 end Is_Static_String_Expression;
2102 ----------------------
2103 -- Pragma_Misplaced --
2104 ----------------------
2106 procedure Pragma_Misplaced is
2108 Error_Pragma ("incorrect placement of pragma%");
2109 end Pragma_Misplaced;
2111 ------------------------------------
2112 -- Process Atomic_Shared_Volatile --
2113 ------------------------------------
2115 procedure Process_Atomic_Shared_Volatile is
2122 procedure Set_Atomic (E : Entity_Id);
2123 -- Set given type as atomic, and if no explicit alignment was given,
2124 -- set alignment to unknown, since back end knows what the alignment
2125 -- requirements are for atomic arrays. Note: this step is necessary
2126 -- for derived types.
2132 procedure Set_Atomic (E : Entity_Id) is
2136 if not Has_Alignment_Clause (E) then
2137 Set_Alignment (E, Uint_0);
2141 -- Start of processing for Process_Atomic_Shared_Volatile
2144 Check_Ada_83_Warning;
2145 Check_No_Identifiers;
2146 Check_Arg_Count (1);
2147 Check_Arg_Is_Local_Name (Arg1);
2148 E_Id := Expression (Arg1);
2150 if Etype (E_Id) = Any_Type then
2155 D := Declaration_Node (E);
2159 if Rep_Item_Too_Early (E, N)
2161 Rep_Item_Too_Late (E, N)
2165 Check_First_Subtype (Arg1);
2168 if Prag_Id /= Pragma_Volatile then
2170 Set_Atomic (Underlying_Type (E));
2171 Set_Atomic (Base_Type (E));
2174 -- Attribute belongs on the base type. If the view of the type is
2175 -- currently private, it also belongs on the underlying type.
2177 Set_Is_Volatile (Base_Type (E));
2178 Set_Is_Volatile (Underlying_Type (E));
2180 Set_Treat_As_Volatile (E);
2181 Set_Treat_As_Volatile (Underlying_Type (E));
2183 elsif K = N_Object_Declaration
2184 or else (K = N_Component_Declaration
2185 and then Original_Record_Component (E) = E)
2187 if Rep_Item_Too_Late (E, N) then
2191 if Prag_Id /= Pragma_Volatile then
2194 -- If the object declaration has an explicit initialization, a
2195 -- temporary may have to be created to hold the expression, to
2196 -- ensure that access to the object remain atomic.
2198 if Nkind (Parent (E)) = N_Object_Declaration
2199 and then Present (Expression (Parent (E)))
2201 Set_Has_Delayed_Freeze (E);
2204 -- An interesting improvement here. If an object of type X is
2205 -- declared atomic, and the type X is not atomic, that's a
2206 -- pity, since it may not have appropriate alignment etc. We
2207 -- can rescue this in the special case where the object and
2208 -- type are in the same unit by just setting the type as
2209 -- atomic, so that the back end will process it as atomic.
2211 Utyp := Underlying_Type (Etype (E));
2214 and then Sloc (E) > No_Location
2215 and then Sloc (Utyp) > No_Location
2217 Get_Source_File_Index (Sloc (E)) =
2218 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2220 Set_Is_Atomic (Underlying_Type (Etype (E)));
2224 Set_Is_Volatile (E);
2225 Set_Treat_As_Volatile (E);
2229 ("inappropriate entity for pragma%", Arg1);
2231 end Process_Atomic_Shared_Volatile;
2233 -------------------------------------------
2234 -- Process_Compile_Time_Warning_Or_Error --
2235 -------------------------------------------
2237 procedure Process_Compile_Time_Warning_Or_Error is
2238 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2241 Check_Arg_Count (2);
2242 Check_No_Identifiers;
2243 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2244 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2246 if Compile_Time_Known_Value (Arg1x) then
2247 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2249 Str : constant String_Id :=
2250 Strval (Get_Pragma_Arg (Arg2));
2251 Len : constant Int := String_Length (Str);
2256 Cent : constant Entity_Id :=
2257 Cunit_Entity (Current_Sem_Unit);
2259 Force : constant Boolean :=
2260 Prag_Id = Pragma_Compile_Time_Warning
2262 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2263 and then (Ekind (Cent) /= E_Package
2264 or else not In_Private_Part (Cent));
2265 -- Set True if this is the warning case, and we are in the
2266 -- visible part of a package spec, or in a subprogram spec,
2267 -- in which case we want to force the client to see the
2268 -- warning, even though it is not in the main unit.
2271 -- Loop through segments of message separated by line feeds.
2272 -- We output these segments as separate messages with
2273 -- continuation marks for all but the first.
2278 Error_Msg_Strlen := 0;
2280 -- Loop to copy characters from argument to error message
2284 exit when Ptr > Len;
2285 CC := Get_String_Char (Str, Ptr);
2288 -- Ignore wide chars ??? else store character
2290 if In_Character_Range (CC) then
2291 C := Get_Character (CC);
2292 exit when C = ASCII.LF;
2293 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2294 Error_Msg_String (Error_Msg_Strlen) := C;
2298 -- Here with one line ready to go
2300 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2302 -- If this is a warning in a spec, then we want clients
2303 -- to see the warning, so mark the message with the
2304 -- special sequence !! to force the warning. In the case
2305 -- of a package spec, we do not force this if we are in
2306 -- the private part of the spec.
2309 if Cont = False then
2310 Error_Msg_N ("<~!!", Arg1);
2313 Error_Msg_N ("\<~!!", Arg1);
2316 -- Error, rather than warning, or in a body, so we do not
2317 -- need to force visibility for client (error will be
2318 -- output in any case, and this is the situation in which
2319 -- we do not want a client to get a warning, since the
2320 -- warning is in the body or the spec private part.
2323 if Cont = False then
2324 Error_Msg_N ("<~", Arg1);
2327 Error_Msg_N ("\<~", Arg1);
2331 exit when Ptr > Len;
2336 end Process_Compile_Time_Warning_Or_Error;
2338 ------------------------
2339 -- Process_Convention --
2340 ------------------------
2342 procedure Process_Convention
2343 (C : out Convention_Id;
2349 Comp_Unit : Unit_Number_Type;
2351 procedure Set_Convention_From_Pragma (E : Entity_Id);
2352 -- Set convention in entity E, and also flag that the entity has a
2353 -- convention pragma. If entity is for a private or incomplete type,
2354 -- also set convention and flag on underlying type. This procedure
2355 -- also deals with the special case of C_Pass_By_Copy convention.
2357 --------------------------------
2358 -- Set_Convention_From_Pragma --
2359 --------------------------------
2361 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2363 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2364 -- for an overridden dispatching operation. Technically this is
2365 -- an amendment and should only be done in Ada 2005 mode. However,
2366 -- this is clearly a mistake, since the problem that is addressed
2367 -- by this AI is that there is a clear gap in the RM!
2369 if Is_Dispatching_Operation (E)
2370 and then Present (Overridden_Operation (E))
2371 and then C /= Convention (Overridden_Operation (E))
2374 ("cannot change convention for " &
2375 "overridden dispatching operation",
2379 -- Set the convention
2381 Set_Convention (E, C);
2382 Set_Has_Convention_Pragma (E);
2384 if Is_Incomplete_Or_Private_Type (E) then
2385 Set_Convention (Underlying_Type (E), C);
2386 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2389 -- A class-wide type should inherit the convention of the specific
2390 -- root type (although this isn't specified clearly by the RM).
2392 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2393 Set_Convention (Class_Wide_Type (E), C);
2396 -- If the entity is a record type, then check for special case of
2397 -- C_Pass_By_Copy, which is treated the same as C except that the
2398 -- special record flag is set. This convention is only permitted
2399 -- on record types (see AI95-00131).
2401 if Cname = Name_C_Pass_By_Copy then
2402 if Is_Record_Type (E) then
2403 Set_C_Pass_By_Copy (Base_Type (E));
2404 elsif Is_Incomplete_Or_Private_Type (E)
2405 and then Is_Record_Type (Underlying_Type (E))
2407 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2410 ("C_Pass_By_Copy convention allowed only for record type",
2415 -- If the entity is a derived boolean type, check for the special
2416 -- case of convention C, C++, or Fortran, where we consider any
2417 -- nonzero value to represent true.
2419 if Is_Discrete_Type (E)
2420 and then Root_Type (Etype (E)) = Standard_Boolean
2426 C = Convention_Fortran)
2428 Set_Nonzero_Is_True (Base_Type (E));
2430 end Set_Convention_From_Pragma;
2432 -- Start of processing for Process_Convention
2435 Check_At_Least_N_Arguments (2);
2436 Check_Optional_Identifier (Arg1, Name_Convention);
2437 Check_Arg_Is_Identifier (Arg1);
2438 Cname := Chars (Expression (Arg1));
2440 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2441 -- tested again below to set the critical flag).
2442 if Cname = Name_C_Pass_By_Copy then
2445 -- Otherwise we must have something in the standard convention list
2447 elsif Is_Convention_Name (Cname) then
2448 C := Get_Convention_Id (Chars (Expression (Arg1)));
2450 -- In DEC VMS, it seems that there is an undocumented feature that
2451 -- any unrecognized convention is treated as the default, which for
2452 -- us is convention C. It does not seem so terrible to do this
2453 -- unconditionally, silently in the VMS case, and with a warning
2454 -- in the non-VMS case.
2457 if Warn_On_Export_Import and not OpenVMS_On_Target then
2459 ("?unrecognized convention name, C assumed",
2466 Check_Optional_Identifier (Arg2, Name_Entity);
2467 Check_Arg_Is_Local_Name (Arg2);
2469 Id := Expression (Arg2);
2472 if not Is_Entity_Name (Id) then
2473 Error_Pragma_Arg ("entity name required", Arg2);
2478 -- Go to renamed subprogram if present, since convention applies to
2479 -- the actual renamed entity, not to the renaming entity. If the
2480 -- subprogram is inherited, go to parent subprogram.
2482 if Is_Subprogram (E)
2483 and then Present (Alias (E))
2485 if Nkind (Parent (Declaration_Node (E))) =
2486 N_Subprogram_Renaming_Declaration
2488 if Scope (E) /= Scope (Alias (E)) then
2490 ("cannot apply pragma% to non-local entity&#", E);
2495 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2496 N_Private_Extension_Declaration)
2497 and then Scope (E) = Scope (Alias (E))
2503 -- Check that we are not applying this to a specless body
2505 if Is_Subprogram (E)
2506 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2509 ("pragma% requires separate spec and must come before body");
2512 -- Check that we are not applying this to a named constant
2514 if Ekind (E) = E_Named_Integer
2516 Ekind (E) = E_Named_Real
2518 Error_Msg_Name_1 := Pname;
2520 ("cannot apply pragma% to named constant!",
2521 Get_Pragma_Arg (Arg2));
2523 ("\supply appropriate type for&!", Arg2);
2526 if Ekind (E) = E_Enumeration_Literal then
2527 Error_Pragma ("enumeration literal not allowed for pragma%");
2530 -- Check for rep item appearing too early or too late
2532 if Etype (E) = Any_Type
2533 or else Rep_Item_Too_Early (E, N)
2537 E := Underlying_Type (E);
2540 if Rep_Item_Too_Late (E, N) then
2544 if Has_Convention_Pragma (E) then
2546 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2548 elsif Convention (E) = Convention_Protected
2549 or else Ekind (Scope (E)) = E_Protected_Type
2552 ("a protected operation cannot be given a different convention",
2556 -- For Intrinsic, a subprogram is required
2558 if C = Convention_Intrinsic
2559 and then not Is_Subprogram (E)
2560 and then not Is_Generic_Subprogram (E)
2563 ("second argument of pragma% must be a subprogram", Arg2);
2566 -- For Stdcall, a subprogram, variable or subprogram type is required
2568 if C = Convention_Stdcall
2569 and then not Is_Subprogram (E)
2570 and then not Is_Generic_Subprogram (E)
2571 and then Ekind (E) /= E_Variable
2574 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2577 ("second argument of pragma% must be subprogram (type)",
2581 if not Is_Subprogram (E)
2582 and then not Is_Generic_Subprogram (E)
2584 Set_Convention_From_Pragma (E);
2588 Check_First_Subtype (Arg2);
2589 Set_Convention_From_Pragma (Base_Type (E));
2591 -- For subprograms, we must set the convention on the
2592 -- internally generated directly designated type as well.
2594 if Ekind (E) = E_Access_Subprogram_Type then
2595 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2599 -- For the subprogram case, set proper convention for all homonyms
2600 -- in same scope and the same declarative part, i.e. the same
2601 -- compilation unit.
2604 Comp_Unit := Get_Source_Unit (E);
2605 Set_Convention_From_Pragma (E);
2607 -- Treat a pragma Import as an implicit body, for GPS use
2609 if Prag_Id = Pragma_Import then
2610 Generate_Reference (E, Id, 'b');
2616 exit when No (E1) or else Scope (E1) /= Current_Scope;
2618 -- Do not set the pragma on inherited operations or on formal
2621 if Comes_From_Source (E1)
2622 and then Comp_Unit = Get_Source_Unit (E1)
2623 and then not Is_Formal_Subprogram (E1)
2624 and then Nkind (Original_Node (Parent (E1))) /=
2625 N_Full_Type_Declaration
2627 if Present (Alias (E1))
2628 and then Scope (E1) /= Scope (Alias (E1))
2631 ("cannot apply pragma% to non-local entity& declared#",
2635 Set_Convention_From_Pragma (E1);
2637 if Prag_Id = Pragma_Import then
2638 Generate_Reference (E, Id, 'b');
2643 end Process_Convention;
2645 -----------------------------------------------------
2646 -- Process_Extended_Import_Export_Exception_Pragma --
2647 -----------------------------------------------------
2649 procedure Process_Extended_Import_Export_Exception_Pragma
2650 (Arg_Internal : Node_Id;
2651 Arg_External : Node_Id;
2659 if not OpenVMS_On_Target then
2661 ("?pragma% ignored (applies only to Open'V'M'S)");
2664 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2665 Def_Id := Entity (Arg_Internal);
2667 if Ekind (Def_Id) /= E_Exception then
2669 ("pragma% must refer to declared exception", Arg_Internal);
2672 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2674 if Present (Arg_Form) then
2675 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2678 if Present (Arg_Form)
2679 and then Chars (Arg_Form) = Name_Ada
2683 Set_Is_VMS_Exception (Def_Id);
2684 Set_Exception_Code (Def_Id, No_Uint);
2687 if Present (Arg_Code) then
2688 if not Is_VMS_Exception (Def_Id) then
2690 ("Code option for pragma% not allowed for Ada case",
2694 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2695 Code_Val := Expr_Value (Arg_Code);
2697 if not UI_Is_In_Int_Range (Code_Val) then
2699 ("Code option for pragma% must be in 32-bit range",
2703 Set_Exception_Code (Def_Id, Code_Val);
2706 end Process_Extended_Import_Export_Exception_Pragma;
2708 -------------------------------------------------
2709 -- Process_Extended_Import_Export_Internal_Arg --
2710 -------------------------------------------------
2712 procedure Process_Extended_Import_Export_Internal_Arg
2713 (Arg_Internal : Node_Id := Empty)
2716 if No (Arg_Internal) then
2717 Error_Pragma ("Internal parameter required for pragma%");
2720 if Nkind (Arg_Internal) = N_Identifier then
2723 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2724 and then (Prag_Id = Pragma_Import_Function
2726 Prag_Id = Pragma_Export_Function)
2732 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2735 Check_Arg_Is_Local_Name (Arg_Internal);
2736 end Process_Extended_Import_Export_Internal_Arg;
2738 --------------------------------------------------
2739 -- Process_Extended_Import_Export_Object_Pragma --
2740 --------------------------------------------------
2742 procedure Process_Extended_Import_Export_Object_Pragma
2743 (Arg_Internal : Node_Id;
2744 Arg_External : Node_Id;
2750 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2751 Def_Id := Entity (Arg_Internal);
2753 if Ekind (Def_Id) /= E_Constant
2754 and then Ekind (Def_Id) /= E_Variable
2757 ("pragma% must designate an object", Arg_Internal);
2760 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2762 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2765 ("previous Common/Psect_Object applies, pragma % not permitted",
2769 if Rep_Item_Too_Late (Def_Id, N) then
2773 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2775 if Present (Arg_Size) then
2776 Check_Arg_Is_External_Name (Arg_Size);
2779 -- Export_Object case
2781 if Prag_Id = Pragma_Export_Object then
2782 if not Is_Library_Level_Entity (Def_Id) then
2784 ("argument for pragma% must be library level entity",
2788 if Ekind (Current_Scope) = E_Generic_Package then
2789 Error_Pragma ("pragma& cannot appear in a generic unit");
2792 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2794 ("exported object must have compile time known size",
2798 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2800 ("?duplicate Export_Object pragma", N);
2802 Set_Exported (Def_Id, Arg_Internal);
2805 -- Import_Object case
2808 if Is_Concurrent_Type (Etype (Def_Id)) then
2810 ("cannot use pragma% for task/protected object",
2814 if Ekind (Def_Id) = E_Constant then
2816 ("cannot import a constant", Arg_Internal);
2819 if Warn_On_Export_Import
2820 and then Has_Discriminants (Etype (Def_Id))
2823 ("imported value must be initialized?", Arg_Internal);
2826 if Warn_On_Export_Import
2827 and then Is_Access_Type (Etype (Def_Id))
2830 ("cannot import object of an access type?", Arg_Internal);
2833 if Warn_On_Export_Import
2834 and then Is_Imported (Def_Id)
2837 ("?duplicate Import_Object pragma", N);
2839 -- Check for explicit initialization present. Note that an
2840 -- initialization that generated by the code generator, e.g.
2841 -- for an access type, does not count here.
2843 elsif Present (Expression (Parent (Def_Id)))
2846 (Original_Node (Expression (Parent (Def_Id))))
2848 Error_Msg_Sloc := Sloc (Def_Id);
2850 ("imported entities cannot be initialized (RM B.1(24))",
2851 "\no initialization allowed for & declared#", Arg1);
2853 Set_Imported (Def_Id);
2854 Note_Possible_Modification (Arg_Internal, Sure => False);
2857 end Process_Extended_Import_Export_Object_Pragma;
2859 ------------------------------------------------------
2860 -- Process_Extended_Import_Export_Subprogram_Pragma --
2861 ------------------------------------------------------
2863 procedure Process_Extended_Import_Export_Subprogram_Pragma
2864 (Arg_Internal : Node_Id;
2865 Arg_External : Node_Id;
2866 Arg_Parameter_Types : Node_Id;
2867 Arg_Result_Type : Node_Id := Empty;
2868 Arg_Mechanism : Node_Id;
2869 Arg_Result_Mechanism : Node_Id := Empty;
2870 Arg_First_Optional_Parameter : Node_Id := Empty)
2876 Ambiguous : Boolean;
2880 function Same_Base_Type
2882 Formal : Entity_Id) return Boolean;
2883 -- Determines if Ptype references the type of Formal. Note that only
2884 -- the base types need to match according to the spec. Ptype here is
2885 -- the argument from the pragma, which is either a type name, or an
2886 -- access attribute.
2888 --------------------
2889 -- Same_Base_Type --
2890 --------------------
2892 function Same_Base_Type
2894 Formal : Entity_Id) return Boolean
2896 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2900 -- Case where pragma argument is typ'Access
2902 if Nkind (Ptype) = N_Attribute_Reference
2903 and then Attribute_Name (Ptype) = Name_Access
2905 Pref := Prefix (Ptype);
2908 if not Is_Entity_Name (Pref)
2909 or else Entity (Pref) = Any_Type
2914 -- We have a match if the corresponding argument is of an
2915 -- anonymous access type, and its designated type matches the
2916 -- type of the prefix of the access attribute
2918 return Ekind (Ftyp) = E_Anonymous_Access_Type
2919 and then Base_Type (Entity (Pref)) =
2920 Base_Type (Etype (Designated_Type (Ftyp)));
2922 -- Case where pragma argument is a type name
2927 if not Is_Entity_Name (Ptype)
2928 or else Entity (Ptype) = Any_Type
2933 -- We have a match if the corresponding argument is of the type
2934 -- given in the pragma (comparing base types)
2936 return Base_Type (Entity (Ptype)) = Ftyp;
2940 -- Start of processing for
2941 -- Process_Extended_Import_Export_Subprogram_Pragma
2944 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2948 -- Loop through homonyms (overloadings) of the entity
2950 Hom_Id := Entity (Arg_Internal);
2951 while Present (Hom_Id) loop
2952 Def_Id := Get_Base_Subprogram (Hom_Id);
2954 -- We need a subprogram in the current scope
2956 if not Is_Subprogram (Def_Id)
2957 or else Scope (Def_Id) /= Current_Scope
2964 -- Pragma cannot apply to subprogram body
2966 if Is_Subprogram (Def_Id)
2967 and then Nkind (Parent (Declaration_Node (Def_Id))) =
2971 ("pragma% requires separate spec"
2972 & " and must come before body");
2975 -- Test result type if given, note that the result type
2976 -- parameter can only be present for the function cases.
2978 if Present (Arg_Result_Type)
2979 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2983 elsif Etype (Def_Id) /= Standard_Void_Type
2985 (Pname = Name_Export_Procedure
2987 Pname = Name_Import_Procedure)
2991 -- Test parameter types if given. Note that this parameter
2992 -- has not been analyzed (and must not be, since it is
2993 -- semantic nonsense), so we get it as the parser left it.
2995 elsif Present (Arg_Parameter_Types) then
2996 Check_Matching_Types : declare
3001 Formal := First_Formal (Def_Id);
3003 if Nkind (Arg_Parameter_Types) = N_Null then
3004 if Present (Formal) then
3008 -- A list of one type, e.g. (List) is parsed as
3009 -- a parenthesized expression.
3011 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3012 and then Paren_Count (Arg_Parameter_Types) = 1
3015 or else Present (Next_Formal (Formal))
3020 Same_Base_Type (Arg_Parameter_Types, Formal);
3023 -- A list of more than one type is parsed as a aggregate
3025 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3026 and then Paren_Count (Arg_Parameter_Types) = 0
3028 Ptype := First (Expressions (Arg_Parameter_Types));
3029 while Present (Ptype) or else Present (Formal) loop
3032 or else not Same_Base_Type (Ptype, Formal)
3037 Next_Formal (Formal);
3042 -- Anything else is of the wrong form
3046 ("wrong form for Parameter_Types parameter",
3047 Arg_Parameter_Types);
3049 end Check_Matching_Types;
3052 -- Match is now False if the entry we found did not match
3053 -- either a supplied Parameter_Types or Result_Types argument
3059 -- Ambiguous case, the flag Ambiguous shows if we already
3060 -- detected this and output the initial messages.
3063 if not Ambiguous then
3065 Error_Msg_Name_1 := Pname;
3067 ("pragma% does not uniquely identify subprogram!",
3069 Error_Msg_Sloc := Sloc (Ent);
3070 Error_Msg_N ("matching subprogram #!", N);
3074 Error_Msg_Sloc := Sloc (Def_Id);
3075 Error_Msg_N ("matching subprogram #!", N);
3080 Hom_Id := Homonym (Hom_Id);
3083 -- See if we found an entry
3086 if not Ambiguous then
3087 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3089 ("pragma% cannot be given for generic subprogram");
3092 ("pragma% does not identify local subprogram");
3099 -- Import pragmas must be for imported entities
3101 if Prag_Id = Pragma_Import_Function
3103 Prag_Id = Pragma_Import_Procedure
3105 Prag_Id = Pragma_Import_Valued_Procedure
3107 if not Is_Imported (Ent) then
3109 ("pragma Import or Interface must precede pragma%");
3112 -- Here we have the Export case which can set the entity as exported
3114 -- But does not do so if the specified external name is null, since
3115 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3116 -- compatible) to request no external name.
3118 elsif Nkind (Arg_External) = N_String_Literal
3119 and then String_Length (Strval (Arg_External)) = 0
3123 -- In all other cases, set entity as exported
3126 Set_Exported (Ent, Arg_Internal);
3129 -- Special processing for Valued_Procedure cases
3131 if Prag_Id = Pragma_Import_Valued_Procedure
3133 Prag_Id = Pragma_Export_Valued_Procedure
3135 Formal := First_Formal (Ent);
3139 ("at least one parameter required for pragma%");
3141 elsif Ekind (Formal) /= E_Out_Parameter then
3143 ("first parameter must have mode out for pragma%");
3146 Set_Is_Valued_Procedure (Ent);
3150 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3152 -- Process Result_Mechanism argument if present. We have already
3153 -- checked that this is only allowed for the function case.
3155 if Present (Arg_Result_Mechanism) then
3156 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3159 -- Process Mechanism parameter if present. Note that this parameter
3160 -- is not analyzed, and must not be analyzed since it is semantic
3161 -- nonsense, so we get it in exactly as the parser left it.
3163 if Present (Arg_Mechanism) then
3171 -- A single mechanism association without a formal parameter
3172 -- name is parsed as a parenthesized expression. All other
3173 -- cases are parsed as aggregates, so we rewrite the single
3174 -- parameter case as an aggregate for consistency.
3176 if Nkind (Arg_Mechanism) /= N_Aggregate
3177 and then Paren_Count (Arg_Mechanism) = 1
3179 Rewrite (Arg_Mechanism,
3180 Make_Aggregate (Sloc (Arg_Mechanism),
3181 Expressions => New_List (
3182 Relocate_Node (Arg_Mechanism))));
3185 -- Case of only mechanism name given, applies to all formals
3187 if Nkind (Arg_Mechanism) /= N_Aggregate then
3188 Formal := First_Formal (Ent);
3189 while Present (Formal) loop
3190 Set_Mechanism_Value (Formal, Arg_Mechanism);
3191 Next_Formal (Formal);
3194 -- Case of list of mechanism associations given
3197 if Null_Record_Present (Arg_Mechanism) then
3199 ("inappropriate form for Mechanism parameter",
3203 -- Deal with positional ones first
3205 Formal := First_Formal (Ent);
3207 if Present (Expressions (Arg_Mechanism)) then
3208 Mname := First (Expressions (Arg_Mechanism));
3209 while Present (Mname) loop
3212 ("too many mechanism associations", Mname);
3215 Set_Mechanism_Value (Formal, Mname);
3216 Next_Formal (Formal);
3221 -- Deal with named entries
3223 if Present (Component_Associations (Arg_Mechanism)) then
3224 Massoc := First (Component_Associations (Arg_Mechanism));
3225 while Present (Massoc) loop
3226 Choice := First (Choices (Massoc));
3228 if Nkind (Choice) /= N_Identifier
3229 or else Present (Next (Choice))
3232 ("incorrect form for mechanism association",
3236 Formal := First_Formal (Ent);
3240 ("parameter name & not present", Choice);
3243 if Chars (Choice) = Chars (Formal) then
3245 (Formal, Expression (Massoc));
3247 -- Set entity on identifier for ASIS
3249 Set_Entity (Choice, Formal);
3254 Next_Formal (Formal);
3264 -- Process First_Optional_Parameter argument if present. We have
3265 -- already checked that this is only allowed for the Import case.
3267 if Present (Arg_First_Optional_Parameter) then
3268 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3270 ("first optional parameter must be formal parameter name",
3271 Arg_First_Optional_Parameter);
3274 Formal := First_Formal (Ent);
3278 ("specified formal parameter& not found",
3279 Arg_First_Optional_Parameter);
3282 exit when Chars (Formal) =
3283 Chars (Arg_First_Optional_Parameter);
3285 Next_Formal (Formal);
3288 Set_First_Optional_Parameter (Ent, Formal);
3290 -- Check specified and all remaining formals have right form
3292 while Present (Formal) loop
3293 if Ekind (Formal) /= E_In_Parameter then
3295 ("optional formal& is not of mode in!",
3296 Arg_First_Optional_Parameter, Formal);
3299 Dval := Default_Value (Formal);
3303 ("optional formal& does not have default value!",
3304 Arg_First_Optional_Parameter, Formal);
3306 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3311 ("default value for optional formal& is non-static!",
3312 Arg_First_Optional_Parameter, Formal);
3316 Set_Is_Optional_Parameter (Formal);
3317 Next_Formal (Formal);
3320 end Process_Extended_Import_Export_Subprogram_Pragma;
3322 --------------------------
3323 -- Process_Generic_List --
3324 --------------------------
3326 procedure Process_Generic_List is
3331 Check_No_Identifiers;
3332 Check_At_Least_N_Arguments (1);
3335 while Present (Arg) loop
3336 Exp := Expression (Arg);
3339 if not Is_Entity_Name (Exp)
3341 (not Is_Generic_Instance (Entity (Exp))
3343 not Is_Generic_Unit (Entity (Exp)))
3346 ("pragma% argument must be name of generic unit/instance",
3352 end Process_Generic_List;
3354 ---------------------------------
3355 -- Process_Import_Or_Interface --
3356 ---------------------------------
3358 procedure Process_Import_Or_Interface is
3364 Process_Convention (C, Def_Id);
3365 Kill_Size_Check_Code (Def_Id);
3366 Note_Possible_Modification (Expression (Arg2), Sure => False);
3368 if Ekind (Def_Id) = E_Variable
3370 Ekind (Def_Id) = E_Constant
3372 -- We do not permit Import to apply to a renaming declaration
3374 if Present (Renamed_Object (Def_Id)) then
3376 ("pragma% not allowed for object renaming", Arg2);
3378 -- User initialization is not allowed for imported object, but
3379 -- the object declaration may contain a default initialization,
3380 -- that will be discarded. Note that an explicit initialization
3381 -- only counts if it comes from source, otherwise it is simply
3382 -- the code generator making an implicit initialization explicit.
3384 elsif Present (Expression (Parent (Def_Id)))
3385 and then Comes_From_Source (Expression (Parent (Def_Id)))
3387 Error_Msg_Sloc := Sloc (Def_Id);
3389 ("no initialization allowed for declaration of& #",
3390 "\imported entities cannot be initialized (RM B.1(24))",
3394 Set_Imported (Def_Id);
3395 Process_Interface_Name (Def_Id, Arg3, Arg4);
3397 -- Note that we do not set Is_Public here. That's because we
3398 -- only want to set it if there is no address clause, and we
3399 -- don't know that yet, so we delay that processing till
3402 -- pragma Import completes deferred constants
3404 if Ekind (Def_Id) = E_Constant then
3405 Set_Has_Completion (Def_Id);
3408 -- It is not possible to import a constant of an unconstrained
3409 -- array type (e.g. string) because there is no simple way to
3410 -- write a meaningful subtype for it.
3412 if Is_Array_Type (Etype (Def_Id))
3413 and then not Is_Constrained (Etype (Def_Id))
3416 ("imported constant& must have a constrained subtype",
3421 elsif Is_Subprogram (Def_Id)
3422 or else Is_Generic_Subprogram (Def_Id)
3424 -- If the name is overloaded, pragma applies to all of the
3425 -- denoted entities in the same declarative part.
3428 while Present (Hom_Id) loop
3429 Def_Id := Get_Base_Subprogram (Hom_Id);
3431 -- Ignore inherited subprograms because the pragma will
3432 -- apply to the parent operation, which is the one called.
3434 if Is_Overloadable (Def_Id)
3435 and then Present (Alias (Def_Id))
3439 -- If it is not a subprogram, it must be in an outer scope and
3440 -- pragma does not apply.
3442 elsif not Is_Subprogram (Def_Id)
3443 and then not Is_Generic_Subprogram (Def_Id)
3447 -- Verify that the homonym is in the same declarative part (not
3448 -- just the same scope).
3450 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3451 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3456 Set_Imported (Def_Id);
3458 -- Special processing for Convention_Intrinsic
3460 if C = Convention_Intrinsic then
3462 -- Link_Name argument not allowed for intrinsic
3465 and then Chars (Arg3) = Name_Link_Name
3470 if Present (Arg4) then
3472 ("Link_Name argument not allowed for " &
3477 Set_Is_Intrinsic_Subprogram (Def_Id);
3479 -- If no external name is present, then check that this
3480 -- is a valid intrinsic subprogram. If an external name
3481 -- is present, then this is handled by the back end.
3484 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3488 -- All interfaced procedures need an external symbol created
3489 -- for them since they are always referenced from another
3492 Set_Is_Public (Def_Id);
3494 -- Verify that the subprogram does not have a completion
3495 -- through a renaming declaration. For other completions the
3496 -- pragma appears as a too late representation.
3499 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3503 and then Nkind (Decl) = N_Subprogram_Declaration
3504 and then Present (Corresponding_Body (Decl))
3505 and then Nkind (Unit_Declaration_Node
3506 (Corresponding_Body (Decl))) =
3507 N_Subprogram_Renaming_Declaration
3509 Error_Msg_Sloc := Sloc (Def_Id);
3511 ("cannot import&, renaming already provided for " &
3512 "declaration #", N, Def_Id);
3516 Set_Has_Completion (Def_Id);
3517 Process_Interface_Name (Def_Id, Arg3, Arg4);
3520 if Is_Compilation_Unit (Hom_Id) then
3522 -- Its possible homonyms are not affected by the pragma.
3523 -- Such homonyms might be present in the context of other
3524 -- units being compiled.
3529 Hom_Id := Homonym (Hom_Id);
3533 -- When the convention is Java or CIL, we also allow Import to be
3534 -- given for packages, generic packages, exceptions, and record
3537 elsif (C = Convention_Java or else C = Convention_CIL)
3539 (Is_Package_Or_Generic_Package (Def_Id)
3540 or else Ekind (Def_Id) = E_Exception
3541 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3543 Set_Imported (Def_Id);
3544 Set_Is_Public (Def_Id);
3545 Process_Interface_Name (Def_Id, Arg3, Arg4);
3547 -- Import a CPP class
3549 elsif Is_Record_Type (Def_Id)
3550 and then C = Convention_CPP
3552 if not Is_Tagged_Type (Def_Id) then
3553 Error_Msg_Sloc := Sloc (Def_Id);
3554 Error_Pragma_Arg ("imported 'C'P'P type must be tagged", Arg2);
3557 -- Types treated as CPP classes are treated as limited, but we
3558 -- don't require them to be declared this way. A warning is
3559 -- issued to encourage the user to declare them as limited.
3560 -- This is not an error, for compatibility reasons, because
3561 -- these types have been supported this way for some time.
3563 if not Is_Limited_Type (Def_Id) then
3565 ("imported 'C'P'P type should be " &
3566 "explicitly declared limited?",
3567 Get_Pragma_Arg (Arg2));
3569 ("\type will be considered limited",
3570 Get_Pragma_Arg (Arg2));
3573 Set_Is_CPP_Class (Def_Id);
3574 Set_Is_Limited_Record (Def_Id);
3579 ("second argument of pragma% must be object or subprogram",
3583 -- If this pragma applies to a compilation unit, then the unit, which
3584 -- is a subprogram, does not require (or allow) a body. We also do
3585 -- not need to elaborate imported procedures.
3587 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3589 Cunit : constant Node_Id := Parent (Parent (N));
3591 Set_Body_Required (Cunit, False);
3594 end Process_Import_Or_Interface;
3596 --------------------
3597 -- Process_Inline --
3598 --------------------
3600 procedure Process_Inline (Active : Boolean) is
3606 Effective : Boolean := False;
3608 procedure Make_Inline (Subp : Entity_Id);
3609 -- Subp is the defining unit name of the subprogram declaration. Set
3610 -- the flag, as well as the flag in the corresponding body, if there
3613 procedure Set_Inline_Flags (Subp : Entity_Id);
3614 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3615 -- Has_Pragma_Inline_Always for the Inline_Always case.
3617 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3618 -- Returns True if it can be determined at this stage that inlining
3619 -- is not possible, for example if the body is available and contains
3620 -- exception handlers, we prevent inlining, since otherwise we can
3621 -- get undefined symbols at link time. This function also emits a
3622 -- warning if front-end inlining is enabled and the pragma appears
3625 -- ??? is business with link symbols still valid, or does it relate
3626 -- to front end ZCX which is being phased out ???
3628 ---------------------------
3629 -- Inlining_Not_Possible --
3630 ---------------------------
3632 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3633 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3637 if Nkind (Decl) = N_Subprogram_Body then
3638 Stats := Handled_Statement_Sequence (Decl);
3639 return Present (Exception_Handlers (Stats))
3640 or else Present (At_End_Proc (Stats));
3642 elsif Nkind (Decl) = N_Subprogram_Declaration
3643 and then Present (Corresponding_Body (Decl))
3645 if Front_End_Inlining
3646 and then Analyzed (Corresponding_Body (Decl))
3648 Error_Msg_N ("pragma appears too late, ignored?", N);
3651 -- If the subprogram is a renaming as body, the body is just a
3652 -- call to the renamed subprogram, and inlining is trivially
3656 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3657 N_Subprogram_Renaming_Declaration
3663 Handled_Statement_Sequence
3664 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3667 Present (Exception_Handlers (Stats))
3668 or else Present (At_End_Proc (Stats));
3672 -- If body is not available, assume the best, the check is
3673 -- performed again when compiling enclosing package bodies.
3677 end Inlining_Not_Possible;
3683 procedure Make_Inline (Subp : Entity_Id) is
3684 Kind : constant Entity_Kind := Ekind (Subp);
3685 Inner_Subp : Entity_Id := Subp;
3688 -- Ignore if bad type, avoid cascaded error
3690 if Etype (Subp) = Any_Type then
3694 -- Ignore if all inlining is suppressed
3696 elsif Suppress_All_Inlining then
3700 -- If inlining is not possible, for now do not treat as an error
3702 elsif Inlining_Not_Possible (Subp) then
3706 -- Here we have a candidate for inlining, but we must exclude
3707 -- derived operations. Otherwise we would end up trying to inline
3708 -- a phantom declaration, and the result would be to drag in a
3709 -- body which has no direct inlining associated with it. That
3710 -- would not only be inefficient but would also result in the
3711 -- backend doing cross-unit inlining in cases where it was
3712 -- definitely inappropriate to do so.
3714 -- However, a simple Comes_From_Source test is insufficient, since
3715 -- we do want to allow inlining of generic instances which also do
3716 -- not come from source. We also need to recognize specs generated
3717 -- by the front-end for bodies that carry the pragma. Finally,
3718 -- predefined operators do not come from source but are not
3719 -- inlineable either.
3721 elsif Is_Generic_Instance (Subp)
3722 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3726 elsif not Comes_From_Source (Subp)
3727 and then Scope (Subp) /= Standard_Standard
3733 -- The referenced entity must either be the enclosing entity, or
3734 -- an entity declared within the current open scope.
3736 if Present (Scope (Subp))
3737 and then Scope (Subp) /= Current_Scope
3738 and then Subp /= Current_Scope
3741 ("argument of% must be entity in current scope", Assoc);
3745 -- Processing for procedure, operator or function. If subprogram
3746 -- is aliased (as for an instance) indicate that the renamed
3747 -- entity (if declared in the same unit) is inlined.
3749 if Is_Subprogram (Subp) then
3750 while Present (Alias (Inner_Subp)) loop
3751 Inner_Subp := Alias (Inner_Subp);
3754 if In_Same_Source_Unit (Subp, Inner_Subp) then
3755 Set_Inline_Flags (Inner_Subp);
3757 Decl := Parent (Parent (Inner_Subp));
3759 if Nkind (Decl) = N_Subprogram_Declaration
3760 and then Present (Corresponding_Body (Decl))
3762 Set_Inline_Flags (Corresponding_Body (Decl));
3764 elsif Is_Generic_Instance (Subp) then
3766 -- Indicate that the body needs to be created for
3767 -- inlining subsequent calls. The instantiation node
3768 -- follows the declaration of the wrapper package
3771 if Scope (Subp) /= Standard_Standard
3773 Need_Subprogram_Instance_Body
3774 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3784 -- For a generic subprogram set flag as well, for use at the point
3785 -- of instantiation, to determine whether the body should be
3788 elsif Is_Generic_Subprogram (Subp) then
3789 Set_Inline_Flags (Subp);
3792 -- Literals are by definition inlined
3794 elsif Kind = E_Enumeration_Literal then
3797 -- Anything else is an error
3801 ("expect subprogram name for pragma%", Assoc);
3805 ----------------------
3806 -- Set_Inline_Flags --
3807 ----------------------
3809 procedure Set_Inline_Flags (Subp : Entity_Id) is
3812 Set_Is_Inlined (Subp, True);
3815 if not Has_Pragma_Inline (Subp) then
3816 Set_Has_Pragma_Inline (Subp);
3820 if Prag_Id = Pragma_Inline_Always then
3821 Set_Has_Pragma_Inline_Always (Subp);
3823 end Set_Inline_Flags;
3825 -- Start of processing for Process_Inline
3828 Check_No_Identifiers;
3829 Check_At_Least_N_Arguments (1);
3832 Inline_Processing_Required := True;
3836 while Present (Assoc) loop
3837 Subp_Id := Expression (Assoc);
3841 if Is_Entity_Name (Subp_Id) then
3842 Subp := Entity (Subp_Id);
3844 if Subp = Any_Id then
3846 -- If previous error, avoid cascaded errors
3854 while Present (Homonym (Subp))
3855 and then Scope (Homonym (Subp)) = Current_Scope
3857 Make_Inline (Homonym (Subp));
3858 Subp := Homonym (Subp);
3865 ("inappropriate argument for pragma%", Assoc);
3868 and then Warn_On_Redundant_Constructs
3869 and then not Suppress_All_Inlining
3871 if Inlining_Not_Possible (Subp) then
3873 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3876 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3884 ----------------------------
3885 -- Process_Interface_Name --
3886 ----------------------------
3888 procedure Process_Interface_Name
3889 (Subprogram_Def : Entity_Id;
3895 String_Val : String_Id;
3897 procedure Check_Form_Of_Interface_Name
3899 Ext_Name_Case : Boolean);
3900 -- SN is a string literal node for an interface name. This routine
3901 -- performs some minimal checks that the name is reasonable. In
3902 -- particular that no spaces or other obviously incorrect characters
3903 -- appear. This is only a warning, since any characters are allowed.
3904 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3906 ----------------------------------
3907 -- Check_Form_Of_Interface_Name --
3908 ----------------------------------
3910 procedure Check_Form_Of_Interface_Name
3912 Ext_Name_Case : Boolean)
3914 S : constant String_Id := Strval (Expr_Value_S (SN));
3915 SL : constant Nat := String_Length (S);
3920 Error_Msg_N ("interface name cannot be null string", SN);
3923 for J in 1 .. SL loop
3924 C := Get_String_Char (S, J);
3926 -- Look for dubious character and issue unconditional warning.
3927 -- Definitely dubious if not in character range.
3929 if not In_Character_Range (C)
3931 -- For all cases except external names on CLI target,
3932 -- commas, spaces and slashes are dubious (in CLI, we use
3933 -- spaces and commas in external names to specify assembly
3934 -- version and public key).
3936 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
3937 and then (Get_Character (C) = ' '
3939 Get_Character (C) = ','
3941 Get_Character (C) = '/'
3943 Get_Character (C) = '\'))
3946 ("?interface name contains illegal character",
3947 Sloc (SN) + Source_Ptr (J));
3950 end Check_Form_Of_Interface_Name;
3952 -- Start of processing for Process_Interface_Name
3955 if No (Link_Arg) then
3956 if No (Ext_Arg) then
3957 if VM_Target = CLI_Target
3958 and then Ekind (Subprogram_Def) = E_Package
3959 and then Nkind (Parent (Subprogram_Def)) =
3960 N_Package_Specification
3961 and then Present (Generic_Parent (Parent (Subprogram_Def)))
3966 (Generic_Parent (Parent (Subprogram_Def))));
3971 elsif Chars (Ext_Arg) = Name_Link_Name then
3973 Link_Nam := Expression (Ext_Arg);
3976 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3977 Ext_Nam := Expression (Ext_Arg);
3982 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
3983 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
3984 Ext_Nam := Expression (Ext_Arg);
3985 Link_Nam := Expression (Link_Arg);
3988 -- Check expressions for external name and link name are static
3990 if Present (Ext_Nam) then
3991 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
3992 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
3994 -- Verify that external name is not the name of a local entity,
3995 -- which would hide the imported one and could lead to run-time
3996 -- surprises. The problem can only arise for entities declared in
3997 -- a package body (otherwise the external name is fully qualified
3998 -- and will not conflict).
4006 if Prag_Id = Pragma_Import then
4007 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4009 E := Entity_Id (Get_Name_Table_Info (Nam));
4011 if Nam /= Chars (Subprogram_Def)
4012 and then Present (E)
4013 and then not Is_Overloadable (E)
4014 and then Is_Immediately_Visible (E)
4015 and then not Is_Imported (E)
4016 and then Ekind (Scope (E)) = E_Package
4019 while Present (Par) loop
4020 if Nkind (Par) = N_Package_Body then
4021 Error_Msg_Sloc := Sloc (E);
4023 ("imported entity is hidden by & declared#",
4028 Par := Parent (Par);
4035 if Present (Link_Nam) then
4036 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4037 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4040 -- If there is no link name, just set the external name
4042 if No (Link_Nam) then
4043 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4045 -- For the Link_Name case, the given literal is preceded by an
4046 -- asterisk, which indicates to GCC that the given name should be
4047 -- taken literally, and in particular that no prepending of
4048 -- underlines should occur, even in systems where this is the
4054 if VM_Target = No_VM then
4055 Store_String_Char (Get_Char_Code ('*'));
4058 String_Val := Strval (Expr_Value_S (Link_Nam));
4059 Store_String_Chars (String_Val);
4061 Make_String_Literal (Sloc (Link_Nam),
4062 Strval => End_String);
4065 Set_Encoded_Interface_Name
4066 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4067 Check_Duplicated_Export_Name (Link_Nam);
4068 end Process_Interface_Name;
4070 -----------------------------------------
4071 -- Process_Interrupt_Or_Attach_Handler --
4072 -----------------------------------------
4074 procedure Process_Interrupt_Or_Attach_Handler is
4075 Arg1_X : constant Node_Id := Expression (Arg1);
4076 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4077 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4080 Set_Is_Interrupt_Handler (Handler_Proc);
4082 -- If the pragma is not associated with a handler procedure within a
4083 -- protected type, then it must be for a nonprotected procedure for
4084 -- the AAMP target, in which case we don't associate a representation
4085 -- item with the procedure's scope.
4087 if Ekind (Proc_Scope) = E_Protected_Type then
4088 if Prag_Id = Pragma_Interrupt_Handler
4090 Prag_Id = Pragma_Attach_Handler
4092 Record_Rep_Item (Proc_Scope, N);
4095 end Process_Interrupt_Or_Attach_Handler;
4097 --------------------------------------------------
4098 -- Process_Restrictions_Or_Restriction_Warnings --
4099 --------------------------------------------------
4101 -- Note: some of the simple identifier cases were handled in par-prag,
4102 -- but it is harmless (and more straightforward) to simply handle all
4103 -- cases here, even if it means we repeat a bit of work in some cases.
4105 procedure Process_Restrictions_Or_Restriction_Warnings
4109 R_Id : Restriction_Id;
4114 procedure Check_Unit_Name (N : Node_Id);
4115 -- Checks unit name parameter for No_Dependence. Returns if it has
4116 -- an appropriate form, otherwise raises pragma argument error.
4118 ---------------------
4119 -- Check_Unit_Name --
4120 ---------------------
4122 procedure Check_Unit_Name (N : Node_Id) is
4124 if Nkind (N) = N_Selected_Component then
4125 Check_Unit_Name (Prefix (N));
4126 Check_Unit_Name (Selector_Name (N));
4128 elsif Nkind (N) = N_Identifier then
4133 ("wrong form for unit name for No_Dependence", N);
4135 end Check_Unit_Name;
4137 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4140 Check_Ada_83_Warning;
4141 Check_At_Least_N_Arguments (1);
4142 Check_Valid_Configuration_Pragma;
4145 while Present (Arg) loop
4147 Expr := Expression (Arg);
4149 -- Case of no restriction identifier present
4151 if Id = No_Name then
4152 if Nkind (Expr) /= N_Identifier then
4154 ("invalid form for restriction", Arg);
4159 (Process_Restriction_Synonyms (Expr));
4161 if R_Id not in All_Boolean_Restrictions then
4162 Error_Msg_Name_1 := Pname;
4164 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4166 -- Check for possible misspelling
4168 for J in Restriction_Id loop
4170 Rnm : constant String := Restriction_Id'Image (J);
4173 Name_Buffer (1 .. Rnm'Length) := Rnm;
4174 Name_Len := Rnm'Length;
4175 Set_Casing (All_Lower_Case);
4177 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4179 (Identifier_Casing (Current_Source_File));
4180 Error_Msg_String (1 .. Rnm'Length) :=
4181 Name_Buffer (1 .. Name_Len);
4182 Error_Msg_Strlen := Rnm'Length;
4184 ("\possible misspelling of ""~""",
4185 Get_Pragma_Arg (Arg));
4194 if Implementation_Restriction (R_Id) then
4195 Check_Restriction (No_Implementation_Restrictions, Arg);
4198 -- If this is a warning, then set the warning unless we already
4199 -- have a real restriction active (we never want a warning to
4200 -- override a real restriction).
4203 if not Restriction_Active (R_Id) then
4204 Set_Restriction (R_Id, N);
4205 Restriction_Warnings (R_Id) := True;
4208 -- If real restriction case, then set it and make sure that the
4209 -- restriction warning flag is off, since a real restriction
4210 -- always overrides a warning.
4213 Set_Restriction (R_Id, N);
4214 Restriction_Warnings (R_Id) := False;
4217 -- A very special case that must be processed here: pragma
4218 -- Restrictions (No_Exceptions) turns off all run-time
4219 -- checking. This is a bit dubious in terms of the formal
4220 -- language definition, but it is what is intended by RM
4221 -- H.4(12). Restriction_Warnings never affects generated code
4222 -- so this is done only in the real restriction case.
4224 if R_Id = No_Exceptions and then not Warn then
4225 Scope_Suppress := (others => True);
4228 -- Case of No_Dependence => unit-name. Note that the parser
4229 -- already made the necessary entry in the No_Dependence table.
4231 elsif Id = Name_No_Dependence then
4232 Check_Unit_Name (Expr);
4234 -- All other cases of restriction identifier present
4237 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4238 Analyze_And_Resolve (Expr, Any_Integer);
4240 if R_Id not in All_Parameter_Restrictions then
4242 ("invalid restriction parameter identifier", Arg);
4244 elsif not Is_OK_Static_Expression (Expr) then
4245 Flag_Non_Static_Expr
4246 ("value must be static expression!", Expr);
4249 elsif not Is_Integer_Type (Etype (Expr))
4250 or else Expr_Value (Expr) < 0
4253 ("value must be non-negative integer", Arg);
4256 -- Restriction pragma is active
4258 Val := Expr_Value (Expr);
4260 if not UI_Is_In_Int_Range (Val) then
4262 ("pragma ignored, value too large?", Arg);
4265 -- Warning case. If the real restriction is active, then we
4266 -- ignore the request, since warning never overrides a real
4267 -- restriction. Otherwise we set the proper warning. Note that
4268 -- this circuit sets the warning again if it is already set,
4269 -- which is what we want, since the constant may have changed.
4272 if not Restriction_Active (R_Id) then
4274 (R_Id, N, Integer (UI_To_Int (Val)));
4275 Restriction_Warnings (R_Id) := True;
4278 -- Real restriction case, set restriction and make sure warning
4279 -- flag is off since real restriction always overrides warning.
4282 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4283 Restriction_Warnings (R_Id) := False;
4289 end Process_Restrictions_Or_Restriction_Warnings;
4291 ---------------------------------
4292 -- Process_Suppress_Unsuppress --
4293 ---------------------------------
4295 -- Note: this procedure makes entries in the check suppress data
4296 -- structures managed by Sem. See spec of package Sem for full
4297 -- details on how we handle recording of check suppression.
4299 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4304 In_Package_Spec : constant Boolean :=
4305 Is_Package_Or_Generic_Package (Current_Scope)
4306 and then not In_Package_Body (Current_Scope);
4308 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4309 -- Used to suppress a single check on the given entity
4311 --------------------------------
4312 -- Suppress_Unsuppress_Echeck --
4313 --------------------------------
4315 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4317 Set_Checks_May_Be_Suppressed (E);
4319 if In_Package_Spec then
4320 Push_Global_Suppress_Stack_Entry
4323 Suppress => Suppress_Case);
4326 Push_Local_Suppress_Stack_Entry
4329 Suppress => Suppress_Case);
4332 -- If this is a first subtype, and the base type is distinct,
4333 -- then also set the suppress flags on the base type.
4335 if Is_First_Subtype (E)
4336 and then Etype (E) /= E
4338 Suppress_Unsuppress_Echeck (Etype (E), C);
4340 end Suppress_Unsuppress_Echeck;
4342 -- Start of processing for Process_Suppress_Unsuppress
4345 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4346 -- declarative part or a package spec (RM 11.5(5)).
4348 if not Is_Configuration_Pragma then
4349 Check_Is_In_Decl_Part_Or_Package_Spec;
4352 Check_At_Least_N_Arguments (1);
4353 Check_At_Most_N_Arguments (2);
4354 Check_No_Identifier (Arg1);
4355 Check_Arg_Is_Identifier (Arg1);
4357 C := Get_Check_Id (Chars (Expression (Arg1)));
4359 if C = No_Check_Id then
4361 ("argument of pragma% is not valid check name", Arg1);
4364 if not Suppress_Case
4365 and then (C = All_Checks or else C = Overflow_Check)
4367 Opt.Overflow_Checks_Unsuppressed := True;
4370 if Arg_Count = 1 then
4372 -- Make an entry in the local scope suppress table. This is the
4373 -- table that directly shows the current value of the scope
4374 -- suppress check for any check id value.
4376 if C = All_Checks then
4378 -- For All_Checks, we set all specific predefined checks with
4379 -- the exception of Elaboration_Check, which is handled
4380 -- specially because of not wanting All_Checks to have the
4381 -- effect of deactivating static elaboration order processing.
4383 for J in Scope_Suppress'Range loop
4384 if J /= Elaboration_Check then
4385 Scope_Suppress (J) := Suppress_Case;
4389 -- If not All_Checks, and predefined check, then set appropriate
4390 -- scope entry. Note that we will set Elaboration_Check if this
4391 -- is explicitly specified.
4393 elsif C in Predefined_Check_Id then
4394 Scope_Suppress (C) := Suppress_Case;
4397 -- Also make an entry in the Local_Entity_Suppress table
4399 Push_Local_Suppress_Stack_Entry
4402 Suppress => Suppress_Case);
4404 -- Case of two arguments present, where the check is suppressed for
4405 -- a specified entity (given as the second argument of the pragma)
4408 Check_Optional_Identifier (Arg2, Name_On);
4409 E_Id := Expression (Arg2);
4412 if not Is_Entity_Name (E_Id) then
4414 ("second argument of pragma% must be entity name", Arg2);
4423 -- Enforce RM 11.5(7) which requires that for a pragma that
4424 -- appears within a package spec, the named entity must be
4425 -- within the package spec. We allow the package name itself
4426 -- to be mentioned since that makes sense, although it is not
4427 -- strictly allowed by 11.5(7).
4430 and then E /= Current_Scope
4431 and then Scope (E) /= Current_Scope
4434 ("entity in pragma% is not in package spec (RM 11.5(7))",
4438 -- Loop through homonyms. As noted below, in the case of a package
4439 -- spec, only homonyms within the package spec are considered.
4442 Suppress_Unsuppress_Echeck (E, C);
4444 if Is_Generic_Instance (E)
4445 and then Is_Subprogram (E)
4446 and then Present (Alias (E))
4448 Suppress_Unsuppress_Echeck (Alias (E), C);
4451 -- Move to next homonym
4456 -- If we are within a package specification, the pragma only
4457 -- applies to homonyms in the same scope.
4459 exit when In_Package_Spec
4460 and then Scope (E) /= Current_Scope;
4463 end Process_Suppress_Unsuppress;
4469 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4471 if Is_Imported (E) then
4473 ("cannot export entity& that was previously imported", Arg);
4475 elsif Present (Address_Clause (E)) then
4477 ("cannot export entity& that has an address clause", Arg);
4480 Set_Is_Exported (E);
4482 -- Generate a reference for entity explicitly, because the
4483 -- identifier may be overloaded and name resolution will not
4486 Generate_Reference (E, Arg);
4488 -- Deal with exporting non-library level entity
4490 if not Is_Library_Level_Entity (E) then
4492 -- Not allowed at all for subprograms
4494 if Is_Subprogram (E) then
4495 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4497 -- Otherwise set public and statically allocated
4501 Set_Is_Statically_Allocated (E);
4503 -- Warn if the corresponding W flag is set and the pragma comes
4504 -- from source. The latter may not be true e.g. on VMS where we
4505 -- expand export pragmas for exception codes associated with
4506 -- imported or exported exceptions. We do not want to generate
4507 -- a warning for something that the user did not write.
4509 if Warn_On_Export_Import
4510 and then Comes_From_Source (Arg)
4513 ("?& has been made static as a result of Export", Arg, E);
4515 ("\this usage is non-standard and non-portable", Arg);
4520 if Warn_On_Export_Import and then Is_Type (E) then
4522 ("exporting a type has no effect?", Arg, E);
4525 if Warn_On_Export_Import and Inside_A_Generic then
4527 ("all instances of& will have the same external name?", Arg, E);
4531 ----------------------------------------------
4532 -- Set_Extended_Import_Export_External_Name --
4533 ----------------------------------------------
4535 procedure Set_Extended_Import_Export_External_Name
4536 (Internal_Ent : Entity_Id;
4537 Arg_External : Node_Id)
4539 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4543 if No (Arg_External) then
4547 Check_Arg_Is_External_Name (Arg_External);
4549 if Nkind (Arg_External) = N_String_Literal then
4550 if String_Length (Strval (Arg_External)) = 0 then
4553 New_Name := Adjust_External_Name_Case (Arg_External);
4556 elsif Nkind (Arg_External) = N_Identifier then
4557 New_Name := Get_Default_External_Name (Arg_External);
4559 -- Check_Arg_Is_External_Name should let through only identifiers and
4560 -- string literals or static string expressions (which are folded to
4561 -- string literals).
4564 raise Program_Error;
4567 -- If we already have an external name set (by a prior normal Import
4568 -- or Export pragma), then the external names must match
4570 if Present (Interface_Name (Internal_Ent)) then
4571 Check_Matching_Internal_Names : declare
4572 S1 : constant String_Id := Strval (Old_Name);
4573 S2 : constant String_Id := Strval (New_Name);
4576 -- Called if names do not match
4582 procedure Mismatch is
4584 Error_Msg_Sloc := Sloc (Old_Name);
4586 ("external name does not match that given #",
4590 -- Start of processing for Check_Matching_Internal_Names
4593 if String_Length (S1) /= String_Length (S2) then
4597 for J in 1 .. String_Length (S1) loop
4598 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4603 end Check_Matching_Internal_Names;
4605 -- Otherwise set the given name
4608 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4609 Check_Duplicated_Export_Name (New_Name);
4611 end Set_Extended_Import_Export_External_Name;
4617 procedure Set_Imported (E : Entity_Id) is
4619 -- Error message if already imported or exported
4621 if Is_Exported (E) or else Is_Imported (E) then
4622 if Is_Exported (E) then
4623 Error_Msg_NE ("entity& was previously exported", N, E);
4625 Error_Msg_NE ("entity& was previously imported", N, E);
4628 Error_Msg_Name_1 := Pname;
4630 ("\(pragma% applies to all previous entities)", N);
4632 Error_Msg_Sloc := Sloc (E);
4633 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4635 -- Here if not previously imported or exported, OK to import
4638 Set_Is_Imported (E);
4640 -- If the entity is an object that is not at the library level,
4641 -- then it is statically allocated. We do not worry about objects
4642 -- with address clauses in this context since they are not really
4643 -- imported in the linker sense.
4646 and then not Is_Library_Level_Entity (E)
4647 and then No (Address_Clause (E))
4649 Set_Is_Statically_Allocated (E);
4654 -------------------------
4655 -- Set_Mechanism_Value --
4656 -------------------------
4658 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4659 -- analyzed, since it is semantic nonsense), so we get it in the exact
4660 -- form created by the parser.
4662 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4665 Mech_Name_Id : Name_Id;
4667 procedure Bad_Class;
4668 -- Signal bad descriptor class name
4670 procedure Bad_Mechanism;
4671 -- Signal bad mechanism name
4677 procedure Bad_Class is
4679 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4682 -------------------------
4683 -- Bad_Mechanism_Value --
4684 -------------------------
4686 procedure Bad_Mechanism is
4688 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4691 -- Start of processing for Set_Mechanism_Value
4694 if Mechanism (Ent) /= Default_Mechanism then
4696 ("mechanism for & has already been set", Mech_Name, Ent);
4699 -- MECHANISM_NAME ::= value | reference | descriptor |
4702 if Nkind (Mech_Name) = N_Identifier then
4703 if Chars (Mech_Name) = Name_Value then
4704 Set_Mechanism (Ent, By_Copy);
4707 elsif Chars (Mech_Name) = Name_Reference then
4708 Set_Mechanism (Ent, By_Reference);
4711 elsif Chars (Mech_Name) = Name_Descriptor then
4712 Check_VMS (Mech_Name);
4713 Set_Mechanism (Ent, By_Descriptor);
4716 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4717 Check_VMS (Mech_Name);
4718 Set_Mechanism (Ent, By_Short_Descriptor);
4721 elsif Chars (Mech_Name) = Name_Copy then
4723 ("bad mechanism name, Value assumed", Mech_Name);
4729 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4730 -- short_descriptor (CLASS_NAME)
4731 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4733 -- Note: this form is parsed as an indexed component
4735 elsif Nkind (Mech_Name) = N_Indexed_Component then
4737 Class := First (Expressions (Mech_Name));
4739 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4740 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4741 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4742 or else Present (Next (Class))
4746 Mech_Name_Id := Chars (Prefix (Mech_Name));
4749 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4750 -- short_descriptor (Class => CLASS_NAME)
4751 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4753 -- Note: this form is parsed as a function call
4755 elsif Nkind (Mech_Name) = N_Function_Call then
4757 Param := First (Parameter_Associations (Mech_Name));
4759 if Nkind (Name (Mech_Name)) /= N_Identifier
4760 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4761 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4762 or else Present (Next (Param))
4763 or else No (Selector_Name (Param))
4764 or else Chars (Selector_Name (Param)) /= Name_Class
4768 Class := Explicit_Actual_Parameter (Param);
4769 Mech_Name_Id := Chars (Name (Mech_Name));
4776 -- Fall through here with Class set to descriptor class name
4778 Check_VMS (Mech_Name);
4780 if Nkind (Class) /= N_Identifier then
4783 elsif Mech_Name_Id = Name_Descriptor
4784 and then Chars (Class) = Name_UBS
4786 Set_Mechanism (Ent, By_Descriptor_UBS);
4788 elsif Mech_Name_Id = Name_Descriptor
4789 and then Chars (Class) = Name_UBSB
4791 Set_Mechanism (Ent, By_Descriptor_UBSB);
4793 elsif Mech_Name_Id = Name_Descriptor
4794 and then Chars (Class) = Name_UBA
4796 Set_Mechanism (Ent, By_Descriptor_UBA);
4798 elsif Mech_Name_Id = Name_Descriptor
4799 and then Chars (Class) = Name_S
4801 Set_Mechanism (Ent, By_Descriptor_S);
4803 elsif Mech_Name_Id = Name_Descriptor
4804 and then Chars (Class) = Name_SB
4806 Set_Mechanism (Ent, By_Descriptor_SB);
4808 elsif Mech_Name_Id = Name_Descriptor
4809 and then Chars (Class) = Name_A
4811 Set_Mechanism (Ent, By_Descriptor_A);
4813 elsif Mech_Name_Id = Name_Descriptor
4814 and then Chars (Class) = Name_NCA
4816 Set_Mechanism (Ent, By_Descriptor_NCA);
4818 elsif Mech_Name_Id = Name_Short_Descriptor
4819 and then Chars (Class) = Name_UBS
4821 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4823 elsif Mech_Name_Id = Name_Short_Descriptor
4824 and then Chars (Class) = Name_UBSB
4826 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4828 elsif Mech_Name_Id = Name_Short_Descriptor
4829 and then Chars (Class) = Name_UBA
4831 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4833 elsif Mech_Name_Id = Name_Short_Descriptor
4834 and then Chars (Class) = Name_S
4836 Set_Mechanism (Ent, By_Short_Descriptor_S);
4838 elsif Mech_Name_Id = Name_Short_Descriptor
4839 and then Chars (Class) = Name_SB
4841 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4843 elsif Mech_Name_Id = Name_Short_Descriptor
4844 and then Chars (Class) = Name_A
4846 Set_Mechanism (Ent, By_Short_Descriptor_A);
4848 elsif Mech_Name_Id = Name_Short_Descriptor
4849 and then Chars (Class) = Name_NCA
4851 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4856 end Set_Mechanism_Value;
4858 ---------------------------
4859 -- Set_Ravenscar_Profile --
4860 ---------------------------
4862 -- The tasks to be done here are
4864 -- Set required policies
4866 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4867 -- pragma Locking_Policy (Ceiling_Locking)
4869 -- Set Detect_Blocking mode
4871 -- Set required restrictions (see System.Rident for detailed list)
4873 procedure Set_Ravenscar_Profile (N : Node_Id) is
4875 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4877 if Task_Dispatching_Policy /= ' '
4878 and then Task_Dispatching_Policy /= 'F'
4880 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4881 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4883 -- Set the FIFO_Within_Priorities policy, but always preserve
4884 -- System_Location since we like the error message with the run time
4888 Task_Dispatching_Policy := 'F';
4890 if Task_Dispatching_Policy_Sloc /= System_Location then
4891 Task_Dispatching_Policy_Sloc := Loc;
4895 -- pragma Locking_Policy (Ceiling_Locking)
4897 if Locking_Policy /= ' '
4898 and then Locking_Policy /= 'C'
4900 Error_Msg_Sloc := Locking_Policy_Sloc;
4901 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4903 -- Set the Ceiling_Locking policy, but preserve System_Location since
4904 -- we like the error message with the run time name.
4907 Locking_Policy := 'C';
4909 if Locking_Policy_Sloc /= System_Location then
4910 Locking_Policy_Sloc := Loc;
4914 -- pragma Detect_Blocking
4916 Detect_Blocking := True;
4918 -- Set the corresponding restrictions
4920 Set_Profile_Restrictions
4921 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4922 end Set_Ravenscar_Profile;
4924 -- Start of processing for Analyze_Pragma
4927 -- Deal with unrecognized pragma
4929 if not Is_Pragma_Name (Pname) then
4930 if Warn_On_Unrecognized_Pragma then
4931 Error_Msg_Name_1 := Pname;
4932 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
4934 for PN in First_Pragma_Name .. Last_Pragma_Name loop
4935 if Is_Bad_Spelling_Of (Pname, PN) then
4936 Error_Msg_Name_1 := PN;
4938 ("\?possible misspelling of %!", Pragma_Identifier (N));
4947 -- Here to start processing for recognized pragma
4949 Prag_Id := Get_Pragma_Id (Pname);
4958 if Present (Pragma_Argument_Associations (N)) then
4959 Arg1 := First (Pragma_Argument_Associations (N));
4961 if Present (Arg1) then
4962 Arg2 := Next (Arg1);
4964 if Present (Arg2) then
4965 Arg3 := Next (Arg2);
4967 if Present (Arg3) then
4968 Arg4 := Next (Arg3);
4974 -- Count number of arguments
4981 while Present (Arg_Node) loop
4982 Arg_Count := Arg_Count + 1;
4987 -- An enumeration type defines the pragmas that are supported by the
4988 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
4989 -- into the corresponding enumeration value for the following case.
4997 -- pragma Abort_Defer;
4999 when Pragma_Abort_Defer =>
5001 Check_Arg_Count (0);
5003 -- The only required semantic processing is to check the
5004 -- placement. This pragma must appear at the start of the
5005 -- statement sequence of a handled sequence of statements.
5007 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5008 or else N /= First (Statements (Parent (N)))
5019 -- Note: this pragma also has some specific processing in Par.Prag
5020 -- because we want to set the Ada version mode during parsing.
5022 when Pragma_Ada_83 =>
5024 Check_Arg_Count (0);
5026 -- We really should check unconditionally for proper configuration
5027 -- pragma placement, since we really don't want mixed Ada modes
5028 -- within a single unit, and the GNAT reference manual has always
5029 -- said this was a configuration pragma, but we did not check and
5030 -- are hesitant to add the check now.
5032 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5033 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5035 if Ada_Version >= Ada_05 then
5036 Check_Valid_Configuration_Pragma;
5039 -- Now set Ada 83 mode
5041 Ada_Version := Ada_83;
5042 Ada_Version_Explicit := Ada_Version;
5050 -- Note: this pragma also has some specific processing in Par.Prag
5051 -- because we want to set the Ada 83 version mode during parsing.
5053 when Pragma_Ada_95 =>
5055 Check_Arg_Count (0);
5057 -- We really should check unconditionally for proper configuration
5058 -- pragma placement, since we really don't want mixed Ada modes
5059 -- within a single unit, and the GNAT reference manual has always
5060 -- said this was a configuration pragma, but we did not check and
5061 -- are hesitant to add the check now.
5063 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5064 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5066 if Ada_Version >= Ada_05 then
5067 Check_Valid_Configuration_Pragma;
5070 -- Now set Ada 95 mode
5072 Ada_Version := Ada_95;
5073 Ada_Version_Explicit := Ada_Version;
5075 ---------------------
5076 -- Ada_05/Ada_2005 --
5077 ---------------------
5080 -- pragma Ada_05 (LOCAL_NAME);
5083 -- pragma Ada_2005 (LOCAL_NAME):
5085 -- Note: these pragma also have some specific processing in Par.Prag
5086 -- because we want to set the Ada 2005 version mode during parsing.
5088 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5094 if Arg_Count = 1 then
5095 Check_Arg_Is_Local_Name (Arg1);
5096 E_Id := Expression (Arg1);
5098 if Etype (E_Id) = Any_Type then
5102 Set_Is_Ada_2005_Only (Entity (E_Id));
5105 Check_Arg_Count (0);
5107 -- For Ada_2005 we unconditionally enforce the documented
5108 -- configuration pragma placement, since we do not want to
5109 -- tolerate mixed modes in a unit involving Ada 2005. That
5110 -- would cause real difficulties for those cases where there
5111 -- are incompatibilities between Ada 95 and Ada 2005.
5113 Check_Valid_Configuration_Pragma;
5115 -- Now set Ada 2005 mode
5117 Ada_Version := Ada_05;
5118 Ada_Version_Explicit := Ada_05;
5122 ----------------------
5123 -- All_Calls_Remote --
5124 ----------------------
5126 -- pragma All_Calls_Remote [(library_package_NAME)];
5128 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5129 Lib_Entity : Entity_Id;
5132 Check_Ada_83_Warning;
5133 Check_Valid_Library_Unit_Pragma;
5135 if Nkind (N) = N_Null_Statement then
5139 Lib_Entity := Find_Lib_Unit_Name;
5141 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5143 if Present (Lib_Entity)
5144 and then not Debug_Flag_U
5146 if not Is_Remote_Call_Interface (Lib_Entity) then
5147 Error_Pragma ("pragma% only apply to rci unit");
5149 -- Set flag for entity of the library unit
5152 Set_Has_All_Calls_Remote (Lib_Entity);
5156 end All_Calls_Remote;
5162 -- pragma Annotate (IDENTIFIER {, ARG});
5163 -- ARG ::= NAME | EXPRESSION
5165 when Pragma_Annotate => Annotate : begin
5167 Check_At_Least_N_Arguments (1);
5168 Check_Arg_Is_Identifier (Arg1);
5176 while Present (Arg) loop
5177 Exp := Expression (Arg);
5180 if Is_Entity_Name (Exp) then
5183 elsif Nkind (Exp) = N_String_Literal then
5184 Resolve (Exp, Standard_String);
5186 elsif Is_Overloaded (Exp) then
5187 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
5202 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5203 -- [, [Message =>] Static_String_EXPRESSION]);
5205 when Pragma_Assert => Assert : declare
5211 Check_At_Least_N_Arguments (1);
5212 Check_At_Most_N_Arguments (2);
5213 Check_Arg_Order ((Name_Check, Name_Message));
5214 Check_Optional_Identifier (Arg1, Name_Check);
5216 -- We treat pragma Assert as equivalent to:
5218 -- pragma Check (Assertion, condition [, msg]);
5220 -- So rewrite pragma in this manner, and analyze the result
5222 Expr := Get_Pragma_Arg (Arg1);
5224 Make_Pragma_Argument_Association (Loc,
5226 Make_Identifier (Loc,
5227 Chars => Name_Assertion)),
5229 Make_Pragma_Argument_Association (Sloc (Expr),
5230 Expression => Expr));
5232 if Arg_Count > 1 then
5233 Check_Optional_Identifier (Arg2, Name_Message);
5234 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5235 Append_To (Newa, Relocate_Node (Arg2));
5240 Chars => Name_Check,
5241 Pragma_Argument_Associations => Newa));
5245 ----------------------
5246 -- Assertion_Policy --
5247 ----------------------
5249 -- pragma Assertion_Policy (Check | Ignore)
5251 when Pragma_Assertion_Policy => Assertion_Policy : declare
5256 Check_Valid_Configuration_Pragma;
5257 Check_Arg_Count (1);
5258 Check_No_Identifiers;
5259 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5261 -- We treat pragma Assertion_Policy as equivalent to:
5263 -- pragma Check_Policy (Assertion, policy)
5265 -- So rewrite the pragma in that manner and link on to the chain
5266 -- of Check_Policy pragmas, marking the pragma as analyzed.
5268 Policy := Get_Pragma_Arg (Arg1);
5272 Chars => Name_Check_Policy,
5274 Pragma_Argument_Associations => New_List (
5275 Make_Pragma_Argument_Association (Loc,
5277 Make_Identifier (Loc,
5278 Chars => Name_Assertion)),
5280 Make_Pragma_Argument_Association (Loc,
5282 Make_Identifier (Sloc (Policy),
5283 Chars => Chars (Policy))))));
5286 Set_Next_Pragma (N, Opt.Check_Policy_List);
5287 Opt.Check_Policy_List := N;
5288 end Assertion_Policy;
5290 ------------------------------
5291 -- Assume_No_Invalid_Values --
5292 ------------------------------
5294 -- pragma Assume_No_Invalid_Values (On | Off);
5296 when Pragma_Assume_No_Invalid_Values =>
5298 Check_Valid_Configuration_Pragma;
5299 Check_Arg_Count (1);
5300 Check_No_Identifiers;
5301 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5303 if Chars (Expression (Arg1)) = Name_On then
5304 Assume_No_Invalid_Values := True;
5306 Assume_No_Invalid_Values := False;
5313 -- pragma AST_Entry (entry_IDENTIFIER);
5315 when Pragma_AST_Entry => AST_Entry : declare
5321 Check_Arg_Count (1);
5322 Check_No_Identifiers;
5323 Check_Arg_Is_Local_Name (Arg1);
5324 Ent := Entity (Expression (Arg1));
5326 -- Note: the implementation of the AST_Entry pragma could handle
5327 -- the entry family case fine, but for now we are consistent with
5328 -- the DEC rules, and do not allow the pragma, which of course
5329 -- has the effect of also forbidding the attribute.
5331 if Ekind (Ent) /= E_Entry then
5333 ("pragma% argument must be simple entry name", Arg1);
5335 elsif Is_AST_Entry (Ent) then
5337 ("duplicate % pragma for entry", Arg1);
5339 elsif Has_Homonym (Ent) then
5341 ("pragma% argument cannot specify overloaded entry", Arg1);
5345 FF : constant Entity_Id := First_Formal (Ent);
5348 if Present (FF) then
5349 if Present (Next_Formal (FF)) then
5351 ("entry for pragma% can have only one argument",
5354 elsif Parameter_Mode (FF) /= E_In_Parameter then
5356 ("entry parameter for pragma% must have mode IN",
5362 Set_Is_AST_Entry (Ent);
5370 -- pragma Asynchronous (LOCAL_NAME);
5372 when Pragma_Asynchronous => Asynchronous : declare
5380 procedure Process_Async_Pragma;
5381 -- Common processing for procedure and access-to-procedure case
5383 --------------------------
5384 -- Process_Async_Pragma --
5385 --------------------------
5387 procedure Process_Async_Pragma is
5390 Set_Is_Asynchronous (Nm);
5394 -- The formals should be of mode IN (RM E.4.1(6))
5397 while Present (S) loop
5398 Formal := Defining_Identifier (S);
5400 if Nkind (Formal) = N_Defining_Identifier
5401 and then Ekind (Formal) /= E_In_Parameter
5404 ("pragma% procedure can only have IN parameter",
5411 Set_Is_Asynchronous (Nm);
5412 end Process_Async_Pragma;
5414 -- Start of processing for pragma Asynchronous
5417 Check_Ada_83_Warning;
5418 Check_No_Identifiers;
5419 Check_Arg_Count (1);
5420 Check_Arg_Is_Local_Name (Arg1);
5422 if Debug_Flag_U then
5426 C_Ent := Cunit_Entity (Current_Sem_Unit);
5427 Analyze (Expression (Arg1));
5428 Nm := Entity (Expression (Arg1));
5430 if not Is_Remote_Call_Interface (C_Ent)
5431 and then not Is_Remote_Types (C_Ent)
5433 -- This pragma should only appear in an RCI or Remote Types
5434 -- unit (RM E.4.1(4)).
5437 ("pragma% not in Remote_Call_Interface or " &
5438 "Remote_Types unit");
5441 if Ekind (Nm) = E_Procedure
5442 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5444 if not Is_Remote_Call_Interface (Nm) then
5446 ("pragma% cannot be applied on non-remote procedure",
5450 L := Parameter_Specifications (Parent (Nm));
5451 Process_Async_Pragma;
5454 elsif Ekind (Nm) = E_Function then
5456 ("pragma% cannot be applied to function", Arg1);
5458 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5460 if Is_Record_Type (Nm) then
5462 -- A record type that is the Equivalent_Type for a remote
5463 -- access-to-subprogram type.
5465 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5468 -- A non-expanded RAS type (distribution is not enabled)
5470 N := Declaration_Node (Nm);
5473 if Nkind (N) = N_Full_Type_Declaration
5474 and then Nkind (Type_Definition (N)) =
5475 N_Access_Procedure_Definition
5477 L := Parameter_Specifications (Type_Definition (N));
5478 Process_Async_Pragma;
5480 if Is_Asynchronous (Nm)
5481 and then Expander_Active
5482 and then Get_PCS_Name /= Name_No_DSA
5484 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5489 ("pragma% cannot reference access-to-function type",
5493 -- Only other possibility is Access-to-class-wide type
5495 elsif Is_Access_Type (Nm)
5496 and then Is_Class_Wide_Type (Designated_Type (Nm))
5498 Check_First_Subtype (Arg1);
5499 Set_Is_Asynchronous (Nm);
5500 if Expander_Active then
5501 RACW_Type_Is_Asynchronous (Nm);
5505 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5513 -- pragma Atomic (LOCAL_NAME);
5515 when Pragma_Atomic =>
5516 Process_Atomic_Shared_Volatile;
5518 -----------------------
5519 -- Atomic_Components --
5520 -----------------------
5522 -- pragma Atomic_Components (array_LOCAL_NAME);
5524 -- This processing is shared by Volatile_Components
5526 when Pragma_Atomic_Components |
5527 Pragma_Volatile_Components =>
5529 Atomic_Components : declare
5536 Check_Ada_83_Warning;
5537 Check_No_Identifiers;
5538 Check_Arg_Count (1);
5539 Check_Arg_Is_Local_Name (Arg1);
5540 E_Id := Expression (Arg1);
5542 if Etype (E_Id) = Any_Type then
5548 if Rep_Item_Too_Early (E, N)
5550 Rep_Item_Too_Late (E, N)
5555 D := Declaration_Node (E);
5558 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5560 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5561 and then Nkind (D) = N_Object_Declaration
5562 and then Nkind (Object_Definition (D)) =
5563 N_Constrained_Array_Definition)
5565 -- The flag is set on the object, or on the base type
5567 if Nkind (D) /= N_Object_Declaration then
5571 Set_Has_Volatile_Components (E);
5573 if Prag_Id = Pragma_Atomic_Components then
5574 Set_Has_Atomic_Components (E);
5576 if Is_Packed (E) then
5577 Set_Is_Packed (E, False);
5580 ("?Pack canceled, cannot pack atomic components",
5586 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5588 end Atomic_Components;
5590 --------------------
5591 -- Attach_Handler --
5592 --------------------
5594 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5596 when Pragma_Attach_Handler =>
5597 Check_Ada_83_Warning;
5598 Check_No_Identifiers;
5599 Check_Arg_Count (2);
5601 if No_Run_Time_Mode then
5602 Error_Msg_CRT ("Attach_Handler pragma", N);
5604 Check_Interrupt_Or_Attach_Handler;
5606 -- The expression that designates the attribute may
5607 -- depend on a discriminant, and is therefore a per-
5608 -- object expression, to be expanded in the init proc.
5609 -- If expansion is enabled, perform semantic checks
5612 if Expander_Active then
5614 Temp : constant Node_Id :=
5615 New_Copy_Tree (Expression (Arg2));
5617 Set_Parent (Temp, N);
5618 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5622 Analyze (Expression (Arg2));
5623 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5626 Process_Interrupt_Or_Attach_Handler;
5629 --------------------
5630 -- C_Pass_By_Copy --
5631 --------------------
5633 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5635 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5641 Check_Valid_Configuration_Pragma;
5642 Check_Arg_Count (1);
5643 Check_Optional_Identifier (Arg1, "max_size");
5645 Arg := Expression (Arg1);
5646 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5648 Val := Expr_Value (Arg);
5652 ("maximum size for pragma% must be positive", Arg1);
5654 elsif UI_Is_In_Int_Range (Val) then
5655 Default_C_Record_Mechanism := UI_To_Int (Val);
5657 -- If a giant value is given, Int'Last will do well enough.
5658 -- If sometime someone complains that a record larger than
5659 -- two gigabytes is not copied, we will worry about it then!
5662 Default_C_Record_Mechanism := Mechanism_Type'Last;
5670 -- pragma Check ([Name =>] Identifier,
5671 -- [Check =>] Boolean_Expression
5672 -- [,[Message =>] String_Expression]);
5674 when Pragma_Check => Check : declare
5679 -- Set True if category of assertions referenced by Name enabled
5683 Check_At_Least_N_Arguments (2);
5684 Check_At_Most_N_Arguments (3);
5685 Check_Optional_Identifier (Arg1, Name_Name);
5686 Check_Optional_Identifier (Arg2, Name_Check);
5688 if Arg_Count = 3 then
5689 Check_Optional_Identifier (Arg3, Name_Message);
5690 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5693 Check_Arg_Is_Identifier (Arg1);
5694 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5696 -- If expansion is active and the check is not enabled then we
5697 -- rewrite the Check as:
5699 -- if False and then condition then
5703 -- The reason we do this rewriting during semantic analysis rather
5704 -- than as part of normal expansion is that we cannot analyze and
5705 -- expand the code for the boolean expression directly, or it may
5706 -- cause insertion of actions that would escape the attempt to
5707 -- suppress the check code.
5709 -- Note that the Sloc for the if statement corresponds to the
5710 -- argument condition, not the pragma itself. The reason for this
5711 -- is that we may generate a warning if the condition is False at
5712 -- compile time, and we do not want to delete this warning when we
5713 -- delete the if statement.
5715 Expr := Expression (Arg2);
5717 if Expander_Active and then not Check_On then
5718 Eloc := Sloc (Expr);
5721 Make_If_Statement (Eloc,
5723 Make_And_Then (Eloc,
5724 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5725 Right_Opnd => Expr),
5726 Then_Statements => New_List (
5727 Make_Null_Statement (Eloc))));
5734 Analyze_And_Resolve (Expr, Any_Boolean);
5737 -- If assertion is of the form (X'First = literal), where X is
5738 -- a formal, then set Low_Bound_Known flag on this formal.
5740 if Nkind (Expr) = N_Op_Eq then
5742 Right : constant Node_Id := Right_Opnd (Expr);
5743 Left : constant Node_Id := Left_Opnd (Expr);
5745 if Nkind (Left) = N_Attribute_Reference
5746 and then Attribute_Name (Left) = Name_First
5747 and then Is_Entity_Name (Prefix (Left))
5748 and then Is_Formal (Entity (Prefix (Left)))
5749 and then Nkind (Right) = N_Integer_Literal
5751 Set_Low_Bound_Known (Entity (Prefix (Left)));
5761 -- pragma Check_Name (check_IDENTIFIER);
5763 when Pragma_Check_Name =>
5764 Check_No_Identifiers;
5766 Check_Valid_Configuration_Pragma;
5767 Check_Arg_Count (1);
5768 Check_Arg_Is_Identifier (Arg1);
5771 Nam : constant Name_Id := Chars (Expression (Arg1));
5774 for J in Check_Names.First .. Check_Names.Last loop
5775 if Check_Names.Table (J) = Nam then
5780 Check_Names.Append (Nam);
5787 -- pragma Check_Policy (
5788 -- [Name =>] IDENTIFIER,
5789 -- [Policy =>] POLICY_IDENTIFIER);
5791 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5793 -- Note: this is a configuration pragma, but it is allowed to appear
5796 when Pragma_Check_Policy =>
5798 Check_Arg_Count (2);
5799 Check_Optional_Identifier (Arg1, Name_Name);
5800 Check_Optional_Identifier (Arg2, Name_Policy);
5802 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5804 -- A Check_Policy pragma can appear either as a configuration
5805 -- pragma, or in a declarative part or a package spec (see RM
5806 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5807 -- followed for Check_Policy).
5809 if not Is_Configuration_Pragma then
5810 Check_Is_In_Decl_Part_Or_Package_Spec;
5813 Set_Next_Pragma (N, Opt.Check_Policy_List);
5814 Opt.Check_Policy_List := N;
5816 ---------------------
5817 -- CIL_Constructor --
5818 ---------------------
5820 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5822 -- Processing for this pragma is shared with Java_Constructor
5828 -- pragma Comment (static_string_EXPRESSION)
5830 -- Processing for pragma Comment shares the circuitry for pragma
5831 -- Ident. The only differences are that Ident enforces a limit of 31
5832 -- characters on its argument, and also enforces limitations on
5833 -- placement for DEC compatibility. Pragma Comment shares neither of
5834 -- these restrictions.
5840 -- pragma Common_Object (
5841 -- [Internal =>] LOCAL_NAME
5842 -- [, [External =>] EXTERNAL_SYMBOL]
5843 -- [, [Size =>] EXTERNAL_SYMBOL]);
5845 -- Processing for this pragma is shared with Psect_Object
5847 ------------------------
5848 -- Compile_Time_Error --
5849 ------------------------
5851 -- pragma Compile_Time_Error
5852 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5854 when Pragma_Compile_Time_Error =>
5856 Process_Compile_Time_Warning_Or_Error;
5858 --------------------------
5859 -- Compile_Time_Warning --
5860 --------------------------
5862 -- pragma Compile_Time_Warning
5863 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5865 when Pragma_Compile_Time_Warning =>
5867 Process_Compile_Time_Warning_Or_Error;
5873 when Pragma_Compiler_Unit =>
5875 Check_Arg_Count (0);
5876 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5878 -----------------------------
5879 -- Complete_Representation --
5880 -----------------------------
5882 -- pragma Complete_Representation;
5884 when Pragma_Complete_Representation =>
5886 Check_Arg_Count (0);
5888 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5890 ("pragma & must appear within record representation clause");
5893 ----------------------------
5894 -- Complex_Representation --
5895 ----------------------------
5897 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5899 when Pragma_Complex_Representation => Complex_Representation : declare
5906 Check_Arg_Count (1);
5907 Check_Optional_Identifier (Arg1, Name_Entity);
5908 Check_Arg_Is_Local_Name (Arg1);
5909 E_Id := Expression (Arg1);
5911 if Etype (E_Id) = Any_Type then
5917 if not Is_Record_Type (E) then
5919 ("argument for pragma% must be record type", Arg1);
5922 Ent := First_Entity (E);
5925 or else No (Next_Entity (Ent))
5926 or else Present (Next_Entity (Next_Entity (Ent)))
5927 or else not Is_Floating_Point_Type (Etype (Ent))
5928 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5931 ("record for pragma% must have two fields of the same "
5932 & "floating-point type", Arg1);
5935 Set_Has_Complex_Representation (Base_Type (E));
5937 -- We need to treat the type has having a non-standard
5938 -- representation, for back-end purposes, even though in
5939 -- general a complex will have the default representation
5940 -- of a record with two real components.
5942 Set_Has_Non_Standard_Rep (Base_Type (E));
5944 end Complex_Representation;
5946 -------------------------
5947 -- Component_Alignment --
5948 -------------------------
5950 -- pragma Component_Alignment (
5951 -- [Form =>] ALIGNMENT_CHOICE
5952 -- [, [Name =>] type_LOCAL_NAME]);
5954 -- ALIGNMENT_CHOICE ::=
5956 -- | Component_Size_4
5960 when Pragma_Component_Alignment => Component_AlignmentP : declare
5961 Args : Args_List (1 .. 2);
5962 Names : constant Name_List (1 .. 2) := (
5966 Form : Node_Id renames Args (1);
5967 Name : Node_Id renames Args (2);
5969 Atype : Component_Alignment_Kind;
5974 Gather_Associations (Names, Args);
5977 Error_Pragma ("missing Form argument for pragma%");
5980 Check_Arg_Is_Identifier (Form);
5982 -- Get proper alignment, note that Default = Component_Size on all
5983 -- machines we have so far, and we want to set this value rather
5984 -- than the default value to indicate that it has been explicitly
5985 -- set (and thus will not get overridden by the default component
5986 -- alignment for the current scope)
5988 if Chars (Form) = Name_Component_Size then
5989 Atype := Calign_Component_Size;
5991 elsif Chars (Form) = Name_Component_Size_4 then
5992 Atype := Calign_Component_Size_4;
5994 elsif Chars (Form) = Name_Default then
5995 Atype := Calign_Component_Size;
5997 elsif Chars (Form) = Name_Storage_Unit then
5998 Atype := Calign_Storage_Unit;
6002 ("invalid Form parameter for pragma%", Form);
6005 -- Case with no name, supplied, affects scope table entry
6009 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6011 -- Case of name supplied
6014 Check_Arg_Is_Local_Name (Name);
6016 Typ := Entity (Name);
6019 or else Rep_Item_Too_Early (Typ, N)
6023 Typ := Underlying_Type (Typ);
6026 if not Is_Record_Type (Typ)
6027 and then not Is_Array_Type (Typ)
6030 ("Name parameter of pragma% must identify record or " &
6031 "array type", Name);
6034 -- An explicit Component_Alignment pragma overrides an
6035 -- implicit pragma Pack, but not an explicit one.
6037 if not Has_Pragma_Pack (Base_Type (Typ)) then
6038 Set_Is_Packed (Base_Type (Typ), False);
6039 Set_Component_Alignment (Base_Type (Typ), Atype);
6042 end Component_AlignmentP;
6048 -- pragma Controlled (first_subtype_LOCAL_NAME);
6050 when Pragma_Controlled => Controlled : declare
6054 Check_No_Identifiers;
6055 Check_Arg_Count (1);
6056 Check_Arg_Is_Local_Name (Arg1);
6057 Arg := Expression (Arg1);
6059 if not Is_Entity_Name (Arg)
6060 or else not Is_Access_Type (Entity (Arg))
6062 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6064 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6072 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6073 -- [Entity =>] LOCAL_NAME);
6075 when Pragma_Convention => Convention : declare
6078 pragma Warnings (Off, C);
6079 pragma Warnings (Off, E);
6081 Check_Arg_Order ((Name_Convention, Name_Entity));
6082 Check_Ada_83_Warning;
6083 Check_Arg_Count (2);
6084 Process_Convention (C, E);
6087 ---------------------------
6088 -- Convention_Identifier --
6089 ---------------------------
6091 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6092 -- [Convention =>] convention_IDENTIFIER);
6094 when Pragma_Convention_Identifier => Convention_Identifier : declare
6100 Check_Arg_Order ((Name_Name, Name_Convention));
6101 Check_Arg_Count (2);
6102 Check_Optional_Identifier (Arg1, Name_Name);
6103 Check_Optional_Identifier (Arg2, Name_Convention);
6104 Check_Arg_Is_Identifier (Arg1);
6105 Check_Arg_Is_Identifier (Arg2);
6106 Idnam := Chars (Expression (Arg1));
6107 Cname := Chars (Expression (Arg2));
6109 if Is_Convention_Name (Cname) then
6110 Record_Convention_Identifier
6111 (Idnam, Get_Convention_Id (Cname));
6114 ("second arg for % pragma must be convention", Arg2);
6116 end Convention_Identifier;
6122 -- pragma CPP_Class ([Entity =>] local_NAME)
6124 when Pragma_CPP_Class => CPP_Class : declare
6129 if Warn_On_Obsolescent_Feature then
6131 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6132 " by pragma import?", N);
6136 Check_Arg_Count (1);
6137 Check_Optional_Identifier (Arg1, Name_Entity);
6138 Check_Arg_Is_Local_Name (Arg1);
6140 Arg := Expression (Arg1);
6143 if Etype (Arg) = Any_Type then
6147 if not Is_Entity_Name (Arg)
6148 or else not Is_Type (Entity (Arg))
6150 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6153 Typ := Entity (Arg);
6155 if not Is_Tagged_Type (Typ) then
6156 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6159 -- Types treated as CPP classes are treated as limited, but we
6160 -- don't require them to be declared this way. A warning is issued
6161 -- to encourage the user to declare them as limited. This is not
6162 -- an error, for compatibility reasons, because these types have
6163 -- been supported this way for some time.
6165 if not Is_Limited_Type (Typ) then
6167 ("imported 'C'P'P type should be " &
6168 "explicitly declared limited?",
6169 Get_Pragma_Arg (Arg1));
6171 ("\type will be considered limited",
6172 Get_Pragma_Arg (Arg1));
6175 Set_Is_CPP_Class (Typ);
6176 Set_Is_Limited_Record (Typ);
6177 Set_Convention (Typ, Convention_CPP);
6180 ---------------------
6181 -- CPP_Constructor --
6182 ---------------------
6184 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6185 -- [, [External_Name =>] static_string_EXPRESSION ]
6186 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6188 when Pragma_CPP_Constructor => CPP_Constructor : declare
6194 Check_At_Least_N_Arguments (1);
6195 Check_At_Most_N_Arguments (3);
6196 Check_Optional_Identifier (Arg1, Name_Entity);
6197 Check_Arg_Is_Local_Name (Arg1);
6199 Id := Expression (Arg1);
6200 Find_Program_Unit_Name (Id);
6202 -- If we did not find the name, we are done
6204 if Etype (Id) = Any_Type then
6208 Def_Id := Entity (Id);
6210 if Ekind (Def_Id) = E_Function
6211 and then Is_Class_Wide_Type (Etype (Def_Id))
6212 and then Is_CPP_Class (Etype (Etype (Def_Id)))
6214 if Arg_Count >= 2 then
6215 Set_Imported (Def_Id);
6216 Set_Is_Public (Def_Id);
6217 Process_Interface_Name (Def_Id, Arg2, Arg3);
6220 if No (Parameter_Specifications (Parent (Def_Id))) then
6221 Set_Has_Completion (Def_Id);
6222 Set_Is_Constructor (Def_Id);
6225 ("non-default constructors not implemented", Arg1);
6230 ("pragma% requires function returning a 'C'P'P_Class type",
6233 end CPP_Constructor;
6239 when Pragma_CPP_Virtual => CPP_Virtual : declare
6243 if Warn_On_Obsolescent_Feature then
6245 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6254 when Pragma_CPP_Vtable => CPP_Vtable : declare
6258 if Warn_On_Obsolescent_Feature then
6260 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6269 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6271 when Pragma_Debug => Debug : declare
6279 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6282 if Arg_Count = 2 then
6285 Left_Opnd => Relocate_Node (Cond),
6286 Right_Opnd => Expression (Arg1));
6289 -- Rewrite into a conditional with an appropriate condition. We
6290 -- wrap the procedure call in a block so that overhead from e.g.
6291 -- use of the secondary stack does not generate execution overhead
6292 -- for suppressed conditions.
6294 Rewrite (N, Make_Implicit_If_Statement (N,
6296 Then_Statements => New_List (
6297 Make_Block_Statement (Loc,
6298 Handled_Statement_Sequence =>
6299 Make_Handled_Sequence_Of_Statements (Loc,
6300 Statements => New_List (
6301 Relocate_Node (Debug_Statement (N))))))));
6309 -- pragma Debug_Policy (Check | Ignore)
6311 when Pragma_Debug_Policy =>
6313 Check_Arg_Count (1);
6314 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6315 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6317 ---------------------
6318 -- Detect_Blocking --
6319 ---------------------
6321 -- pragma Detect_Blocking;
6323 when Pragma_Detect_Blocking =>
6325 Check_Arg_Count (0);
6326 Check_Valid_Configuration_Pragma;
6327 Detect_Blocking := True;
6333 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6335 when Pragma_Discard_Names => Discard_Names : declare
6340 Check_Ada_83_Warning;
6342 -- Deal with configuration pragma case
6344 if Arg_Count = 0 and then Is_Configuration_Pragma then
6345 Global_Discard_Names := True;
6348 -- Otherwise, check correct appropriate context
6351 Check_Is_In_Decl_Part_Or_Package_Spec;
6353 if Arg_Count = 0 then
6355 -- If there is no parameter, then from now on this pragma
6356 -- applies to any enumeration, exception or tagged type
6357 -- defined in the current declarative part, and recursively
6358 -- to any nested scope.
6360 Set_Discard_Names (Current_Scope);
6364 Check_Arg_Count (1);
6365 Check_Optional_Identifier (Arg1, Name_On);
6366 Check_Arg_Is_Local_Name (Arg1);
6368 E_Id := Expression (Arg1);
6370 if Etype (E_Id) = Any_Type then
6376 if (Is_First_Subtype (E)
6378 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6379 or else Ekind (E) = E_Exception
6381 Set_Discard_Names (E);
6384 ("inappropriate entity for pragma%", Arg1);
6395 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6397 when Pragma_Elaborate => Elaborate : declare
6402 -- Pragma must be in context items list of a compilation unit
6404 if not Is_In_Context_Clause then
6408 -- Must be at least one argument
6410 if Arg_Count = 0 then
6411 Error_Pragma ("pragma% requires at least one argument");
6414 -- In Ada 83 mode, there can be no items following it in the
6415 -- context list except other pragmas and implicit with clauses
6416 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6417 -- placement rule does not apply.
6419 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6421 while Present (Citem) loop
6422 if Nkind (Citem) = N_Pragma
6423 or else (Nkind (Citem) = N_With_Clause
6424 and then Implicit_With (Citem))
6429 ("(Ada 83) pragma% must be at end of context clause");
6436 -- Finally, the arguments must all be units mentioned in a with
6437 -- clause in the same context clause. Note we already checked (in
6438 -- Par.Prag) that the arguments are all identifiers or selected
6442 Outer : while Present (Arg) loop
6443 Citem := First (List_Containing (N));
6444 Inner : while Citem /= N loop
6445 if Nkind (Citem) = N_With_Clause
6446 and then Same_Name (Name (Citem), Expression (Arg))
6448 Set_Elaborate_Present (Citem, True);
6449 Set_Unit_Name (Expression (Arg), Name (Citem));
6451 -- With the pragma present, elaboration calls on
6452 -- subprograms from the named unit need no further
6453 -- checks, as long as the pragma appears in the current
6454 -- compilation unit. If the pragma appears in some unit
6455 -- in the context, there might still be a need for an
6456 -- Elaborate_All_Desirable from the current compilation
6457 -- to the named unit, so we keep the check enabled.
6459 if In_Extended_Main_Source_Unit (N) then
6460 Set_Suppress_Elaboration_Warnings
6461 (Entity (Name (Citem)));
6472 ("argument of pragma% is not with'ed unit", Arg);
6478 -- Give a warning if operating in static mode with -gnatwl
6479 -- (elaboration warnings enabled) switch set.
6481 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6483 ("?use of pragma Elaborate may not be safe", N);
6485 ("?use pragma Elaborate_All instead if possible", N);
6493 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6495 when Pragma_Elaborate_All => Elaborate_All : declare
6500 Check_Ada_83_Warning;
6502 -- Pragma must be in context items list of a compilation unit
6504 if not Is_In_Context_Clause then
6508 -- Must be at least one argument
6510 if Arg_Count = 0 then
6511 Error_Pragma ("pragma% requires at least one argument");
6514 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6515 -- have to appear at the end of the context clause, but may
6516 -- appear mixed in with other items, even in Ada 83 mode.
6518 -- Final check: the arguments must all be units mentioned in
6519 -- a with clause in the same context clause. Note that we
6520 -- already checked (in Par.Prag) that all the arguments are
6521 -- either identifiers or selected components.
6524 Outr : while Present (Arg) loop
6525 Citem := First (List_Containing (N));
6526 Innr : while Citem /= N loop
6527 if Nkind (Citem) = N_With_Clause
6528 and then Same_Name (Name (Citem), Expression (Arg))
6530 Set_Elaborate_All_Present (Citem, True);
6531 Set_Unit_Name (Expression (Arg), Name (Citem));
6533 -- Suppress warnings and elaboration checks on the named
6534 -- unit if the pragma is in the current compilation, as
6535 -- for pragma Elaborate.
6537 if In_Extended_Main_Source_Unit (N) then
6538 Set_Suppress_Elaboration_Warnings
6539 (Entity (Name (Citem)));
6548 Set_Error_Posted (N);
6550 ("argument of pragma% is not with'ed unit", Arg);
6557 --------------------
6558 -- Elaborate_Body --
6559 --------------------
6561 -- pragma Elaborate_Body [( library_unit_NAME )];
6563 when Pragma_Elaborate_Body => Elaborate_Body : declare
6564 Cunit_Node : Node_Id;
6565 Cunit_Ent : Entity_Id;
6568 Check_Ada_83_Warning;
6569 Check_Valid_Library_Unit_Pragma;
6571 if Nkind (N) = N_Null_Statement then
6575 Cunit_Node := Cunit (Current_Sem_Unit);
6576 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6578 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6581 Error_Pragma ("pragma% must refer to a spec, not a body");
6583 Set_Body_Required (Cunit_Node, True);
6584 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6586 -- If we are in dynamic elaboration mode, then we suppress
6587 -- elaboration warnings for the unit, since it is definitely
6588 -- fine NOT to do dynamic checks at the first level (and such
6589 -- checks will be suppressed because no elaboration boolean
6590 -- is created for Elaborate_Body packages).
6592 -- But in the static model of elaboration, Elaborate_Body is
6593 -- definitely NOT good enough to ensure elaboration safety on
6594 -- its own, since the body may WITH other units that are not
6595 -- safe from an elaboration point of view, so a client must
6596 -- still do an Elaborate_All on such units.
6598 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6599 -- Elaborate_Body always suppressed elab warnings.
6601 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6602 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6607 ------------------------
6608 -- Elaboration_Checks --
6609 ------------------------
6611 -- pragma Elaboration_Checks (Static | Dynamic);
6613 when Pragma_Elaboration_Checks =>
6615 Check_Arg_Count (1);
6616 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6617 Dynamic_Elaboration_Checks :=
6618 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6624 -- pragma Eliminate (
6625 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6626 -- [,[Entity =>] IDENTIFIER |
6627 -- SELECTED_COMPONENT |
6629 -- [, OVERLOADING_RESOLUTION]);
6631 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6634 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6637 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6639 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6640 -- Result_Type => result_SUBTYPE_NAME]
6642 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6643 -- SUBTYPE_NAME ::= STRING_LITERAL
6645 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6646 -- SOURCE_TRACE ::= STRING_LITERAL
6648 when Pragma_Eliminate => Eliminate : declare
6649 Args : Args_List (1 .. 5);
6650 Names : constant Name_List (1 .. 5) := (
6653 Name_Parameter_Types,
6655 Name_Source_Location);
6657 Unit_Name : Node_Id renames Args (1);
6658 Entity : Node_Id renames Args (2);
6659 Parameter_Types : Node_Id renames Args (3);
6660 Result_Type : Node_Id renames Args (4);
6661 Source_Location : Node_Id renames Args (5);
6665 Check_Valid_Configuration_Pragma;
6666 Gather_Associations (Names, Args);
6668 if No (Unit_Name) then
6669 Error_Pragma ("missing Unit_Name argument for pragma%");
6673 and then (Present (Parameter_Types)
6675 Present (Result_Type)
6677 Present (Source_Location))
6679 Error_Pragma ("missing Entity argument for pragma%");
6682 if (Present (Parameter_Types)
6684 Present (Result_Type))
6686 Present (Source_Location)
6689 ("parameter profile and source location cannot " &
6690 "be used together in pragma%");
6693 Process_Eliminate_Pragma
6707 -- [ Convention =>] convention_IDENTIFIER,
6708 -- [ Entity =>] local_NAME
6709 -- [, [External_Name =>] static_string_EXPRESSION ]
6710 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6712 when Pragma_Export => Export : declare
6716 pragma Warnings (Off, C);
6719 Check_Ada_83_Warning;
6725 Check_At_Least_N_Arguments (2);
6726 Check_At_Most_N_Arguments (4);
6727 Process_Convention (C, Def_Id);
6729 if Ekind (Def_Id) /= E_Constant then
6730 Note_Possible_Modification (Expression (Arg2), Sure => False);
6733 Process_Interface_Name (Def_Id, Arg3, Arg4);
6734 Set_Exported (Def_Id, Arg2);
6736 -- If the entity is a deferred constant, propagate the information
6737 -- to the full view, because gigi elaborates the full view only.
6739 if Ekind (Def_Id) = E_Constant
6740 and then Present (Full_View (Def_Id))
6743 Id2 : constant Entity_Id := Full_View (Def_Id);
6745 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6746 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6747 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6752 ----------------------
6753 -- Export_Exception --
6754 ----------------------
6756 -- pragma Export_Exception (
6757 -- [Internal =>] LOCAL_NAME
6758 -- [, [External =>] EXTERNAL_SYMBOL]
6759 -- [, [Form =>] Ada | VMS]
6760 -- [, [Code =>] static_integer_EXPRESSION]);
6762 when Pragma_Export_Exception => Export_Exception : declare
6763 Args : Args_List (1 .. 4);
6764 Names : constant Name_List (1 .. 4) := (
6770 Internal : Node_Id renames Args (1);
6771 External : Node_Id renames Args (2);
6772 Form : Node_Id renames Args (3);
6773 Code : Node_Id renames Args (4);
6778 if Inside_A_Generic then
6779 Error_Pragma ("pragma% cannot be used for generic entities");
6782 Gather_Associations (Names, Args);
6783 Process_Extended_Import_Export_Exception_Pragma (
6784 Arg_Internal => Internal,
6785 Arg_External => External,
6789 if not Is_VMS_Exception (Entity (Internal)) then
6790 Set_Exported (Entity (Internal), Internal);
6792 end Export_Exception;
6794 ---------------------
6795 -- Export_Function --
6796 ---------------------
6798 -- pragma Export_Function (
6799 -- [Internal =>] LOCAL_NAME
6800 -- [, [External =>] EXTERNAL_SYMBOL]
6801 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6802 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6803 -- [, [Mechanism =>] MECHANISM]
6804 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6806 -- EXTERNAL_SYMBOL ::=
6808 -- | static_string_EXPRESSION
6810 -- PARAMETER_TYPES ::=
6812 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6814 -- TYPE_DESIGNATOR ::=
6816 -- | subtype_Name ' Access
6820 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6822 -- MECHANISM_ASSOCIATION ::=
6823 -- [formal_parameter_NAME =>] MECHANISM_NAME
6825 -- MECHANISM_NAME ::=
6828 -- | Descriptor [([Class =>] CLASS_NAME)]
6830 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6832 when Pragma_Export_Function => Export_Function : declare
6833 Args : Args_List (1 .. 6);
6834 Names : constant Name_List (1 .. 6) := (
6837 Name_Parameter_Types,
6840 Name_Result_Mechanism);
6842 Internal : Node_Id renames Args (1);
6843 External : Node_Id renames Args (2);
6844 Parameter_Types : Node_Id renames Args (3);
6845 Result_Type : Node_Id renames Args (4);
6846 Mechanism : Node_Id renames Args (5);
6847 Result_Mechanism : Node_Id renames Args (6);
6851 Gather_Associations (Names, Args);
6852 Process_Extended_Import_Export_Subprogram_Pragma (
6853 Arg_Internal => Internal,
6854 Arg_External => External,
6855 Arg_Parameter_Types => Parameter_Types,
6856 Arg_Result_Type => Result_Type,
6857 Arg_Mechanism => Mechanism,
6858 Arg_Result_Mechanism => Result_Mechanism);
6859 end Export_Function;
6865 -- pragma Export_Object (
6866 -- [Internal =>] LOCAL_NAME
6867 -- [, [External =>] EXTERNAL_SYMBOL]
6868 -- [, [Size =>] EXTERNAL_SYMBOL]);
6870 -- EXTERNAL_SYMBOL ::=
6872 -- | static_string_EXPRESSION
6874 -- PARAMETER_TYPES ::=
6876 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6878 -- TYPE_DESIGNATOR ::=
6880 -- | subtype_Name ' Access
6884 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6886 -- MECHANISM_ASSOCIATION ::=
6887 -- [formal_parameter_NAME =>] MECHANISM_NAME
6889 -- MECHANISM_NAME ::=
6892 -- | Descriptor [([Class =>] CLASS_NAME)]
6894 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6896 when Pragma_Export_Object => Export_Object : declare
6897 Args : Args_List (1 .. 3);
6898 Names : constant Name_List (1 .. 3) := (
6903 Internal : Node_Id renames Args (1);
6904 External : Node_Id renames Args (2);
6905 Size : Node_Id renames Args (3);
6909 Gather_Associations (Names, Args);
6910 Process_Extended_Import_Export_Object_Pragma (
6911 Arg_Internal => Internal,
6912 Arg_External => External,
6916 ----------------------
6917 -- Export_Procedure --
6918 ----------------------
6920 -- pragma Export_Procedure (
6921 -- [Internal =>] LOCAL_NAME
6922 -- [, [External =>] EXTERNAL_SYMBOL]
6923 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6924 -- [, [Mechanism =>] MECHANISM]);
6926 -- EXTERNAL_SYMBOL ::=
6928 -- | static_string_EXPRESSION
6930 -- PARAMETER_TYPES ::=
6932 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6934 -- TYPE_DESIGNATOR ::=
6936 -- | subtype_Name ' Access
6940 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6942 -- MECHANISM_ASSOCIATION ::=
6943 -- [formal_parameter_NAME =>] MECHANISM_NAME
6945 -- MECHANISM_NAME ::=
6948 -- | Descriptor [([Class =>] CLASS_NAME)]
6950 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6952 when Pragma_Export_Procedure => Export_Procedure : declare
6953 Args : Args_List (1 .. 4);
6954 Names : constant Name_List (1 .. 4) := (
6957 Name_Parameter_Types,
6960 Internal : Node_Id renames Args (1);
6961 External : Node_Id renames Args (2);
6962 Parameter_Types : Node_Id renames Args (3);
6963 Mechanism : Node_Id renames Args (4);
6967 Gather_Associations (Names, Args);
6968 Process_Extended_Import_Export_Subprogram_Pragma (
6969 Arg_Internal => Internal,
6970 Arg_External => External,
6971 Arg_Parameter_Types => Parameter_Types,
6972 Arg_Mechanism => Mechanism);
6973 end Export_Procedure;
6979 -- pragma Export_Value (
6980 -- [Value =>] static_integer_EXPRESSION,
6981 -- [Link_Name =>] static_string_EXPRESSION);
6983 when Pragma_Export_Value =>
6985 Check_Arg_Order ((Name_Value, Name_Link_Name));
6986 Check_Arg_Count (2);
6988 Check_Optional_Identifier (Arg1, Name_Value);
6989 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
6991 Check_Optional_Identifier (Arg2, Name_Link_Name);
6992 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
6994 -----------------------------
6995 -- Export_Valued_Procedure --
6996 -----------------------------
6998 -- pragma Export_Valued_Procedure (
6999 -- [Internal =>] LOCAL_NAME
7000 -- [, [External =>] EXTERNAL_SYMBOL,]
7001 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7002 -- [, [Mechanism =>] MECHANISM]);
7004 -- EXTERNAL_SYMBOL ::=
7006 -- | static_string_EXPRESSION
7008 -- PARAMETER_TYPES ::=
7010 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7012 -- TYPE_DESIGNATOR ::=
7014 -- | subtype_Name ' Access
7018 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7020 -- MECHANISM_ASSOCIATION ::=
7021 -- [formal_parameter_NAME =>] MECHANISM_NAME
7023 -- MECHANISM_NAME ::=
7026 -- | Descriptor [([Class =>] CLASS_NAME)]
7028 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7030 when Pragma_Export_Valued_Procedure =>
7031 Export_Valued_Procedure : declare
7032 Args : Args_List (1 .. 4);
7033 Names : constant Name_List (1 .. 4) := (
7036 Name_Parameter_Types,
7039 Internal : Node_Id renames Args (1);
7040 External : Node_Id renames Args (2);
7041 Parameter_Types : Node_Id renames Args (3);
7042 Mechanism : Node_Id renames Args (4);
7046 Gather_Associations (Names, Args);
7047 Process_Extended_Import_Export_Subprogram_Pragma (
7048 Arg_Internal => Internal,
7049 Arg_External => External,
7050 Arg_Parameter_Types => Parameter_Types,
7051 Arg_Mechanism => Mechanism);
7052 end Export_Valued_Procedure;
7058 -- pragma Extend_System ([Name =>] Identifier);
7060 when Pragma_Extend_System => Extend_System : declare
7063 Check_Valid_Configuration_Pragma;
7064 Check_Arg_Count (1);
7065 Check_Optional_Identifier (Arg1, Name_Name);
7066 Check_Arg_Is_Identifier (Arg1);
7068 Get_Name_String (Chars (Expression (Arg1)));
7071 and then Name_Buffer (1 .. 4) = "aux_"
7073 if Present (System_Extend_Pragma_Arg) then
7074 if Chars (Expression (Arg1)) =
7075 Chars (Expression (System_Extend_Pragma_Arg))
7079 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7080 Error_Pragma ("pragma% conflicts with that #");
7084 System_Extend_Pragma_Arg := Arg1;
7086 if not GNAT_Mode then
7087 System_Extend_Unit := Arg1;
7091 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7095 ------------------------
7096 -- Extensions_Allowed --
7097 ------------------------
7099 -- pragma Extensions_Allowed (ON | OFF);
7101 when Pragma_Extensions_Allowed =>
7103 Check_Arg_Count (1);
7104 Check_No_Identifiers;
7105 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7107 if Chars (Expression (Arg1)) = Name_On then
7108 Extensions_Allowed := True;
7110 Extensions_Allowed := False;
7117 -- pragma External (
7118 -- [ Convention =>] convention_IDENTIFIER,
7119 -- [ Entity =>] local_NAME
7120 -- [, [External_Name =>] static_string_EXPRESSION ]
7121 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7123 when Pragma_External => External : declare
7127 pragma Warnings (Off, C);
7136 Check_At_Least_N_Arguments (2);
7137 Check_At_Most_N_Arguments (4);
7138 Process_Convention (C, Def_Id);
7139 Note_Possible_Modification (Expression (Arg2), Sure => False);
7140 Process_Interface_Name (Def_Id, Arg3, Arg4);
7141 Set_Exported (Def_Id, Arg2);
7144 --------------------------
7145 -- External_Name_Casing --
7146 --------------------------
7148 -- pragma External_Name_Casing (
7149 -- UPPERCASE | LOWERCASE
7150 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7152 when Pragma_External_Name_Casing => External_Name_Casing : declare
7155 Check_No_Identifiers;
7157 if Arg_Count = 2 then
7159 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7161 case Chars (Get_Pragma_Arg (Arg2)) is
7163 Opt.External_Name_Exp_Casing := As_Is;
7165 when Name_Uppercase =>
7166 Opt.External_Name_Exp_Casing := Uppercase;
7168 when Name_Lowercase =>
7169 Opt.External_Name_Exp_Casing := Lowercase;
7176 Check_Arg_Count (1);
7179 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7181 case Chars (Get_Pragma_Arg (Arg1)) is
7182 when Name_Uppercase =>
7183 Opt.External_Name_Imp_Casing := Uppercase;
7185 when Name_Lowercase =>
7186 Opt.External_Name_Imp_Casing := Lowercase;
7191 end External_Name_Casing;
7193 --------------------------
7194 -- Favor_Top_Level --
7195 --------------------------
7197 -- pragma Favor_Top_Level (type_NAME);
7199 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7200 Named_Entity : Entity_Id;
7204 Check_No_Identifiers;
7205 Check_Arg_Count (1);
7206 Check_Arg_Is_Local_Name (Arg1);
7207 Named_Entity := Entity (Expression (Arg1));
7209 -- If it's an access-to-subprogram type (in particular, not a
7210 -- subtype), set the flag on that type.
7212 if Is_Access_Subprogram_Type (Named_Entity) then
7213 Set_Can_Use_Internal_Rep (Named_Entity, False);
7215 -- Otherwise it's an error (name denotes the wrong sort of entity)
7219 ("access-to-subprogram type expected", Expression (Arg1));
7221 end Favor_Top_Level;
7227 -- pragma Fast_Math;
7229 when Pragma_Fast_Math =>
7231 Check_No_Identifiers;
7232 Check_Valid_Configuration_Pragma;
7235 ---------------------------
7236 -- Finalize_Storage_Only --
7237 ---------------------------
7239 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7241 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7242 Assoc : constant Node_Id := Arg1;
7243 Type_Id : constant Node_Id := Expression (Assoc);
7248 Check_No_Identifiers;
7249 Check_Arg_Count (1);
7250 Check_Arg_Is_Local_Name (Arg1);
7252 Find_Type (Type_Id);
7253 Typ := Entity (Type_Id);
7256 or else Rep_Item_Too_Early (Typ, N)
7260 Typ := Underlying_Type (Typ);
7263 if not Is_Controlled (Typ) then
7264 Error_Pragma ("pragma% must specify controlled type");
7267 Check_First_Subtype (Arg1);
7269 if Finalize_Storage_Only (Typ) then
7270 Error_Pragma ("duplicate pragma%, only one allowed");
7272 elsif not Rep_Item_Too_Late (Typ, N) then
7273 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7275 end Finalize_Storage;
7277 --------------------------
7278 -- Float_Representation --
7279 --------------------------
7281 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7283 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7285 when Pragma_Float_Representation => Float_Representation : declare
7293 if Arg_Count = 1 then
7294 Check_Valid_Configuration_Pragma;
7296 Check_Arg_Count (2);
7297 Check_Optional_Identifier (Arg2, Name_Entity);
7298 Check_Arg_Is_Local_Name (Arg2);
7301 Check_No_Identifier (Arg1);
7302 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7304 if not OpenVMS_On_Target then
7305 if Chars (Expression (Arg1)) = Name_VAX_Float then
7307 ("?pragma% ignored (applies only to Open'V'M'S)");
7313 -- One argument case
7315 if Arg_Count = 1 then
7316 if Chars (Expression (Arg1)) = Name_VAX_Float then
7317 if Opt.Float_Format = 'I' then
7318 Error_Pragma ("'I'E'E'E format previously specified");
7321 Opt.Float_Format := 'V';
7324 if Opt.Float_Format = 'V' then
7325 Error_Pragma ("'V'A'X format previously specified");
7328 Opt.Float_Format := 'I';
7331 Set_Standard_Fpt_Formats;
7333 -- Two argument case
7336 Argx := Get_Pragma_Arg (Arg2);
7338 if not Is_Entity_Name (Argx)
7339 or else not Is_Floating_Point_Type (Entity (Argx))
7342 ("second argument of% pragma must be floating-point type",
7346 Ent := Entity (Argx);
7347 Digs := UI_To_Int (Digits_Value (Ent));
7349 -- Two arguments, VAX_Float case
7351 if Chars (Expression (Arg1)) = Name_VAX_Float then
7353 when 6 => Set_F_Float (Ent);
7354 when 9 => Set_D_Float (Ent);
7355 when 15 => Set_G_Float (Ent);
7359 ("wrong digits value, must be 6,9 or 15", Arg2);
7362 -- Two arguments, IEEE_Float case
7366 when 6 => Set_IEEE_Short (Ent);
7367 when 15 => Set_IEEE_Long (Ent);
7371 ("wrong digits value, must be 6 or 15", Arg2);
7375 end Float_Representation;
7381 -- pragma Ident (static_string_EXPRESSION)
7383 -- Note: pragma Comment shares this processing. Pragma Comment is
7384 -- identical to Ident, except that the restriction of the argument to
7385 -- 31 characters and the placement restrictions are not enforced for
7388 when Pragma_Ident | Pragma_Comment => Ident : declare
7393 Check_Arg_Count (1);
7394 Check_No_Identifiers;
7395 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7397 -- For pragma Ident, preserve DEC compatibility by requiring the
7398 -- pragma to appear in a declarative part or package spec.
7400 if Prag_Id = Pragma_Ident then
7401 Check_Is_In_Decl_Part_Or_Package_Spec;
7404 Str := Expr_Value_S (Expression (Arg1));
7411 GP := Parent (Parent (N));
7413 if Nkind_In (GP, N_Package_Declaration,
7414 N_Generic_Package_Declaration)
7419 -- If we have a compilation unit, then record the ident value,
7420 -- checking for improper duplication.
7422 if Nkind (GP) = N_Compilation_Unit then
7423 CS := Ident_String (Current_Sem_Unit);
7425 if Present (CS) then
7427 -- For Ident, we do not permit multiple instances
7429 if Prag_Id = Pragma_Ident then
7430 Error_Pragma ("duplicate% pragma not permitted");
7432 -- For Comment, we concatenate the string, unless we want
7433 -- to preserve the tree structure for ASIS.
7435 elsif not ASIS_Mode then
7436 Start_String (Strval (CS));
7437 Store_String_Char (' ');
7438 Store_String_Chars (Strval (Str));
7439 Set_Strval (CS, End_String);
7443 -- In VMS, the effect of IDENT is achieved by passing
7444 -- IDENTIFICATION=name as a --for-linker switch.
7446 if OpenVMS_On_Target then
7449 ("--for-linker=IDENTIFICATION=");
7450 String_To_Name_Buffer (Strval (Str));
7451 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7453 -- Only the last processed IDENT is saved. The main
7454 -- purpose is so an IDENT associated with a main
7455 -- procedure will be used in preference to an IDENT
7456 -- associated with a with'd package.
7458 Replace_Linker_Option_String
7459 (End_String, "--for-linker=IDENTIFICATION=");
7462 Set_Ident_String (Current_Sem_Unit, Str);
7465 -- For subunits, we just ignore the Ident, since in GNAT these
7466 -- are not separate object files, and hence not separate units
7467 -- in the unit table.
7469 elsif Nkind (GP) = N_Subunit then
7472 -- Otherwise we have a misplaced pragma Ident, but we ignore
7473 -- this if we are in an instantiation, since it comes from
7474 -- a generic, and has no relevance to the instantiation.
7476 elsif Prag_Id = Pragma_Ident then
7477 if Instantiation_Location (Loc) = No_Location then
7478 Error_Pragma ("pragma% only allowed at outer level");
7484 --------------------------
7485 -- Implemented_By_Entry --
7486 --------------------------
7488 -- pragma Implemented_By_Entry (DIRECT_NAME);
7490 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7495 Check_Arg_Count (1);
7496 Check_No_Identifiers;
7497 Check_Arg_Is_Identifier (Arg1);
7498 Check_Arg_Is_Local_Name (Arg1);
7499 Ent := Entity (Expression (Arg1));
7501 -- Pragma Implemented_By_Entry must be applied only to protected
7502 -- synchronized or task interface primitives.
7504 if (Ekind (Ent) /= E_Function
7505 and then Ekind (Ent) /= E_Procedure)
7506 or else not Present (First_Formal (Ent))
7507 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7510 ("pragma % must be applied to a concurrent interface " &
7514 if Einfo.Implemented_By_Entry (Ent)
7515 and then Warn_On_Redundant_Constructs
7517 Error_Pragma ("?duplicate pragma%!");
7519 Set_Implemented_By_Entry (Ent);
7522 end Implemented_By_Entry;
7524 -----------------------
7525 -- Implicit_Packing --
7526 -----------------------
7528 -- pragma Implicit_Packing;
7530 when Pragma_Implicit_Packing =>
7532 Check_Arg_Count (0);
7533 Implicit_Packing := True;
7540 -- [Convention =>] convention_IDENTIFIER,
7541 -- [Entity =>] local_NAME
7542 -- [, [External_Name =>] static_string_EXPRESSION ]
7543 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7545 when Pragma_Import =>
7546 Check_Ada_83_Warning;
7552 Check_At_Least_N_Arguments (2);
7553 Check_At_Most_N_Arguments (4);
7554 Process_Import_Or_Interface;
7556 ----------------------
7557 -- Import_Exception --
7558 ----------------------
7560 -- pragma Import_Exception (
7561 -- [Internal =>] LOCAL_NAME
7562 -- [, [External =>] EXTERNAL_SYMBOL]
7563 -- [, [Form =>] Ada | VMS]
7564 -- [, [Code =>] static_integer_EXPRESSION]);
7566 when Pragma_Import_Exception => Import_Exception : declare
7567 Args : Args_List (1 .. 4);
7568 Names : constant Name_List (1 .. 4) := (
7574 Internal : Node_Id renames Args (1);
7575 External : Node_Id renames Args (2);
7576 Form : Node_Id renames Args (3);
7577 Code : Node_Id renames Args (4);
7581 Gather_Associations (Names, Args);
7583 if Present (External) and then Present (Code) then
7585 ("cannot give both External and Code options for pragma%");
7588 Process_Extended_Import_Export_Exception_Pragma (
7589 Arg_Internal => Internal,
7590 Arg_External => External,
7594 if not Is_VMS_Exception (Entity (Internal)) then
7595 Set_Imported (Entity (Internal));
7597 end Import_Exception;
7599 ---------------------
7600 -- Import_Function --
7601 ---------------------
7603 -- pragma Import_Function (
7604 -- [Internal =>] LOCAL_NAME,
7605 -- [, [External =>] EXTERNAL_SYMBOL]
7606 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7607 -- [, [Result_Type =>] SUBTYPE_MARK]
7608 -- [, [Mechanism =>] MECHANISM]
7609 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7610 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7612 -- EXTERNAL_SYMBOL ::=
7614 -- | static_string_EXPRESSION
7616 -- PARAMETER_TYPES ::=
7618 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7620 -- TYPE_DESIGNATOR ::=
7622 -- | subtype_Name ' Access
7626 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7628 -- MECHANISM_ASSOCIATION ::=
7629 -- [formal_parameter_NAME =>] MECHANISM_NAME
7631 -- MECHANISM_NAME ::=
7634 -- | Descriptor [([Class =>] CLASS_NAME)]
7636 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7638 when Pragma_Import_Function => Import_Function : declare
7639 Args : Args_List (1 .. 7);
7640 Names : constant Name_List (1 .. 7) := (
7643 Name_Parameter_Types,
7646 Name_Result_Mechanism,
7647 Name_First_Optional_Parameter);
7649 Internal : Node_Id renames Args (1);
7650 External : Node_Id renames Args (2);
7651 Parameter_Types : Node_Id renames Args (3);
7652 Result_Type : Node_Id renames Args (4);
7653 Mechanism : Node_Id renames Args (5);
7654 Result_Mechanism : Node_Id renames Args (6);
7655 First_Optional_Parameter : Node_Id renames Args (7);
7659 Gather_Associations (Names, Args);
7660 Process_Extended_Import_Export_Subprogram_Pragma (
7661 Arg_Internal => Internal,
7662 Arg_External => External,
7663 Arg_Parameter_Types => Parameter_Types,
7664 Arg_Result_Type => Result_Type,
7665 Arg_Mechanism => Mechanism,
7666 Arg_Result_Mechanism => Result_Mechanism,
7667 Arg_First_Optional_Parameter => First_Optional_Parameter);
7668 end Import_Function;
7674 -- pragma Import_Object (
7675 -- [Internal =>] LOCAL_NAME
7676 -- [, [External =>] EXTERNAL_SYMBOL]
7677 -- [, [Size =>] EXTERNAL_SYMBOL]);
7679 -- EXTERNAL_SYMBOL ::=
7681 -- | static_string_EXPRESSION
7683 when Pragma_Import_Object => Import_Object : declare
7684 Args : Args_List (1 .. 3);
7685 Names : constant Name_List (1 .. 3) := (
7690 Internal : Node_Id renames Args (1);
7691 External : Node_Id renames Args (2);
7692 Size : Node_Id renames Args (3);
7696 Gather_Associations (Names, Args);
7697 Process_Extended_Import_Export_Object_Pragma (
7698 Arg_Internal => Internal,
7699 Arg_External => External,
7703 ----------------------
7704 -- Import_Procedure --
7705 ----------------------
7707 -- pragma Import_Procedure (
7708 -- [Internal =>] LOCAL_NAME
7709 -- [, [External =>] EXTERNAL_SYMBOL]
7710 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7711 -- [, [Mechanism =>] MECHANISM]
7712 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7714 -- EXTERNAL_SYMBOL ::=
7716 -- | static_string_EXPRESSION
7718 -- PARAMETER_TYPES ::=
7720 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7722 -- TYPE_DESIGNATOR ::=
7724 -- | subtype_Name ' Access
7728 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7730 -- MECHANISM_ASSOCIATION ::=
7731 -- [formal_parameter_NAME =>] MECHANISM_NAME
7733 -- MECHANISM_NAME ::=
7736 -- | Descriptor [([Class =>] CLASS_NAME)]
7738 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7740 when Pragma_Import_Procedure => Import_Procedure : declare
7741 Args : Args_List (1 .. 5);
7742 Names : constant Name_List (1 .. 5) := (
7745 Name_Parameter_Types,
7747 Name_First_Optional_Parameter);
7749 Internal : Node_Id renames Args (1);
7750 External : Node_Id renames Args (2);
7751 Parameter_Types : Node_Id renames Args (3);
7752 Mechanism : Node_Id renames Args (4);
7753 First_Optional_Parameter : Node_Id renames Args (5);
7757 Gather_Associations (Names, Args);
7758 Process_Extended_Import_Export_Subprogram_Pragma (
7759 Arg_Internal => Internal,
7760 Arg_External => External,
7761 Arg_Parameter_Types => Parameter_Types,
7762 Arg_Mechanism => Mechanism,
7763 Arg_First_Optional_Parameter => First_Optional_Parameter);
7764 end Import_Procedure;
7766 -----------------------------
7767 -- Import_Valued_Procedure --
7768 -----------------------------
7770 -- pragma Import_Valued_Procedure (
7771 -- [Internal =>] LOCAL_NAME
7772 -- [, [External =>] EXTERNAL_SYMBOL]
7773 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7774 -- [, [Mechanism =>] MECHANISM]
7775 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7777 -- EXTERNAL_SYMBOL ::=
7779 -- | static_string_EXPRESSION
7781 -- PARAMETER_TYPES ::=
7783 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7785 -- TYPE_DESIGNATOR ::=
7787 -- | subtype_Name ' Access
7791 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7793 -- MECHANISM_ASSOCIATION ::=
7794 -- [formal_parameter_NAME =>] MECHANISM_NAME
7796 -- MECHANISM_NAME ::=
7799 -- | Descriptor [([Class =>] CLASS_NAME)]
7801 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7803 when Pragma_Import_Valued_Procedure =>
7804 Import_Valued_Procedure : declare
7805 Args : Args_List (1 .. 5);
7806 Names : constant Name_List (1 .. 5) := (
7809 Name_Parameter_Types,
7811 Name_First_Optional_Parameter);
7813 Internal : Node_Id renames Args (1);
7814 External : Node_Id renames Args (2);
7815 Parameter_Types : Node_Id renames Args (3);
7816 Mechanism : Node_Id renames Args (4);
7817 First_Optional_Parameter : Node_Id renames Args (5);
7821 Gather_Associations (Names, Args);
7822 Process_Extended_Import_Export_Subprogram_Pragma (
7823 Arg_Internal => Internal,
7824 Arg_External => External,
7825 Arg_Parameter_Types => Parameter_Types,
7826 Arg_Mechanism => Mechanism,
7827 Arg_First_Optional_Parameter => First_Optional_Parameter);
7828 end Import_Valued_Procedure;
7830 ------------------------
7831 -- Initialize_Scalars --
7832 ------------------------
7834 -- pragma Initialize_Scalars;
7836 when Pragma_Initialize_Scalars =>
7838 Check_Arg_Count (0);
7839 Check_Valid_Configuration_Pragma;
7840 Check_Restriction (No_Initialize_Scalars, N);
7842 if not Restriction_Active (No_Initialize_Scalars) then
7843 Init_Or_Norm_Scalars := True;
7844 Initialize_Scalars := True;
7851 -- pragma Inline ( NAME {, NAME} );
7853 when Pragma_Inline =>
7855 -- Pragma is active if inlining option is active
7857 Process_Inline (Inline_Active);
7863 -- pragma Inline_Always ( NAME {, NAME} );
7865 when Pragma_Inline_Always =>
7867 Process_Inline (True);
7869 --------------------
7870 -- Inline_Generic --
7871 --------------------
7873 -- pragma Inline_Generic (NAME {, NAME});
7875 when Pragma_Inline_Generic =>
7877 Process_Generic_List;
7879 ----------------------
7880 -- Inspection_Point --
7881 ----------------------
7883 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
7885 when Pragma_Inspection_Point => Inspection_Point : declare
7890 if Arg_Count > 0 then
7893 Exp := Expression (Arg);
7896 if not Is_Entity_Name (Exp)
7897 or else not Is_Object (Entity (Exp))
7899 Error_Pragma_Arg ("object name required", Arg);
7906 end Inspection_Point;
7912 -- pragma Interface (
7913 -- [ Convention =>] convention_IDENTIFIER,
7914 -- [ Entity =>] local_NAME
7915 -- [, [External_Name =>] static_string_EXPRESSION ]
7916 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7918 when Pragma_Interface =>
7925 Check_At_Least_N_Arguments (2);
7926 Check_At_Most_N_Arguments (4);
7927 Process_Import_Or_Interface;
7929 --------------------
7930 -- Interface_Name --
7931 --------------------
7933 -- pragma Interface_Name (
7934 -- [ Entity =>] local_NAME
7935 -- [,[External_Name =>] static_string_EXPRESSION ]
7936 -- [,[Link_Name =>] static_string_EXPRESSION ]);
7938 when Pragma_Interface_Name => Interface_Name : declare
7947 ((Name_Entity, Name_External_Name, Name_Link_Name));
7948 Check_At_Least_N_Arguments (2);
7949 Check_At_Most_N_Arguments (3);
7950 Id := Expression (Arg1);
7953 if not Is_Entity_Name (Id) then
7955 ("first argument for pragma% must be entity name", Arg1);
7956 elsif Etype (Id) = Any_Type then
7959 Def_Id := Entity (Id);
7962 -- Special DEC-compatible processing for the object case, forces
7963 -- object to be imported.
7965 if Ekind (Def_Id) = E_Variable then
7966 Kill_Size_Check_Code (Def_Id);
7967 Note_Possible_Modification (Id, Sure => False);
7969 -- Initialization is not allowed for imported variable
7971 if Present (Expression (Parent (Def_Id)))
7972 and then Comes_From_Source (Expression (Parent (Def_Id)))
7974 Error_Msg_Sloc := Sloc (Def_Id);
7976 ("no initialization allowed for declaration of& #",
7980 -- For compatibility, support VADS usage of providing both
7981 -- pragmas Interface and Interface_Name to obtain the effect
7982 -- of a single Import pragma.
7984 if Is_Imported (Def_Id)
7985 and then Present (First_Rep_Item (Def_Id))
7986 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
7988 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
7992 Set_Imported (Def_Id);
7995 Set_Is_Public (Def_Id);
7996 Process_Interface_Name (Def_Id, Arg2, Arg3);
7999 -- Otherwise must be subprogram
8001 elsif not Is_Subprogram (Def_Id) then
8003 ("argument of pragma% is not subprogram", Arg1);
8006 Check_At_Most_N_Arguments (3);
8010 -- Loop through homonyms
8013 Def_Id := Get_Base_Subprogram (Hom_Id);
8015 if Is_Imported (Def_Id) then
8016 Process_Interface_Name (Def_Id, Arg2, Arg3);
8020 Hom_Id := Homonym (Hom_Id);
8022 exit when No (Hom_Id)
8023 or else Scope (Hom_Id) /= Current_Scope;
8028 ("argument of pragma% is not imported subprogram",
8034 -----------------------
8035 -- Interrupt_Handler --
8036 -----------------------
8038 -- pragma Interrupt_Handler (handler_NAME);
8040 when Pragma_Interrupt_Handler =>
8041 Check_Ada_83_Warning;
8042 Check_Arg_Count (1);
8043 Check_No_Identifiers;
8045 if No_Run_Time_Mode then
8046 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8048 Check_Interrupt_Or_Attach_Handler;
8049 Process_Interrupt_Or_Attach_Handler;
8052 ------------------------
8053 -- Interrupt_Priority --
8054 ------------------------
8056 -- pragma Interrupt_Priority [(EXPRESSION)];
8058 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8059 P : constant Node_Id := Parent (N);
8063 Check_Ada_83_Warning;
8065 if Arg_Count /= 0 then
8066 Arg := Expression (Arg1);
8067 Check_Arg_Count (1);
8068 Check_No_Identifiers;
8070 -- The expression must be analyzed in the special manner
8071 -- described in "Handling of Default and Per-Object
8072 -- Expressions" in sem.ads.
8074 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8077 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8081 elsif Has_Priority_Pragma (P) then
8082 Error_Pragma ("duplicate pragma% not allowed");
8085 Set_Has_Priority_Pragma (P, True);
8086 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8088 end Interrupt_Priority;
8090 ---------------------
8091 -- Interrupt_State --
8092 ---------------------
8094 -- pragma Interrupt_State (
8095 -- [Name =>] INTERRUPT_ID,
8096 -- [State =>] INTERRUPT_STATE);
8098 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8099 -- INTERRUPT_STATE => System | Runtime | User
8101 -- Note: if the interrupt id is given as an identifier, then it must
8102 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8103 -- given as a static integer expression which must be in the range of
8104 -- Ada.Interrupts.Interrupt_ID.
8106 when Pragma_Interrupt_State => Interrupt_State : declare
8108 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8109 -- This is the entity Ada.Interrupts.Interrupt_ID;
8111 State_Type : Character;
8112 -- Set to 's'/'r'/'u' for System/Runtime/User
8115 -- Index to entry in Interrupt_States table
8118 -- Value of interrupt
8120 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8121 -- The first argument to the pragma
8123 Int_Ent : Entity_Id;
8124 -- Interrupt entity in Ada.Interrupts.Names
8128 Check_Arg_Order ((Name_Name, Name_State));
8129 Check_Arg_Count (2);
8131 Check_Optional_Identifier (Arg1, Name_Name);
8132 Check_Optional_Identifier (Arg2, Name_State);
8133 Check_Arg_Is_Identifier (Arg2);
8135 -- First argument is identifier
8137 if Nkind (Arg1X) = N_Identifier then
8139 -- Search list of names in Ada.Interrupts.Names
8141 Int_Ent := First_Entity (RTE (RE_Names));
8143 if No (Int_Ent) then
8144 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8146 elsif Chars (Int_Ent) = Chars (Arg1X) then
8147 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8151 Next_Entity (Int_Ent);
8154 -- First argument is not an identifier, so it must be a static
8155 -- expression of type Ada.Interrupts.Interrupt_ID.
8158 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8159 Int_Val := Expr_Value (Arg1X);
8161 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8163 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8166 ("value not in range of type " &
8167 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8173 case Chars (Get_Pragma_Arg (Arg2)) is
8174 when Name_Runtime => State_Type := 'r';
8175 when Name_System => State_Type := 's';
8176 when Name_User => State_Type := 'u';
8179 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8182 -- Check if entry is already stored
8184 IST_Num := Interrupt_States.First;
8186 -- If entry not found, add it
8188 if IST_Num > Interrupt_States.Last then
8189 Interrupt_States.Append
8190 ((Interrupt_Number => UI_To_Int (Int_Val),
8191 Interrupt_State => State_Type,
8192 Pragma_Loc => Loc));
8195 -- Case of entry for the same entry
8197 elsif Int_Val = Interrupt_States.Table (IST_Num).
8200 -- If state matches, done, no need to make redundant entry
8203 State_Type = Interrupt_States.Table (IST_Num).
8206 -- Otherwise if state does not match, error
8209 Interrupt_States.Table (IST_Num).Pragma_Loc;
8211 ("state conflicts with that given #", Arg2);
8215 IST_Num := IST_Num + 1;
8217 end Interrupt_State;
8219 ----------------------
8220 -- Java_Constructor --
8221 ----------------------
8223 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8225 -- Also handles pragma CIL_Constructor
8227 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8228 Java_Constructor : declare
8232 Convention : Convention_Id;
8236 Check_Arg_Count (1);
8237 Check_Optional_Identifier (Arg1, Name_Entity);
8238 Check_Arg_Is_Local_Name (Arg1);
8240 Id := Expression (Arg1);
8241 Find_Program_Unit_Name (Id);
8243 -- If we did not find the name, we are done
8245 if Etype (Id) = Any_Type then
8250 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8251 when Pragma_Java_Constructor => Convention := Convention_Java;
8252 when others => null;
8255 Hom_Id := Entity (Id);
8257 -- Loop through homonyms
8260 Def_Id := Get_Base_Subprogram (Hom_Id);
8262 -- The constructor is required to be a function returning an
8263 -- access type whose designated type has convention Java/CIL.
8265 if Ekind (Def_Id) = E_Function
8267 (Is_Value_Type (Etype (Def_Id))
8269 (Ekind (Etype (Def_Id)) in Access_Kind
8272 (Designated_Type (Etype (Def_Id))) = Convention
8275 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8278 Set_Is_Constructor (Def_Id);
8279 Set_Convention (Def_Id, Convention);
8280 Set_Is_Imported (Def_Id);
8283 if Convention = Convention_Java then
8285 ("pragma% requires function returning a " &
8286 "'Java access type", Arg1);
8288 pragma Assert (Convention = Convention_CIL);
8290 ("pragma% requires function returning a " &
8291 "'CIL access type", Arg1);
8295 Hom_Id := Homonym (Hom_Id);
8297 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8299 end Java_Constructor;
8301 ----------------------
8302 -- Java_Interface --
8303 ----------------------
8305 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8307 when Pragma_Java_Interface => Java_Interface : declare
8313 Check_Arg_Count (1);
8314 Check_Optional_Identifier (Arg1, Name_Entity);
8315 Check_Arg_Is_Local_Name (Arg1);
8317 Arg := Expression (Arg1);
8320 if Etype (Arg) = Any_Type then
8324 if not Is_Entity_Name (Arg)
8325 or else not Is_Type (Entity (Arg))
8327 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8330 Typ := Underlying_Type (Entity (Arg));
8332 -- For now simply check some of the semantic constraints on the
8333 -- type. This currently leaves out some restrictions on interface
8334 -- types, namely that the parent type must be java.lang.Object.Typ
8335 -- and that all primitives of the type should be declared
8338 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8339 Error_Pragma_Arg ("pragma% requires an abstract "
8340 & "tagged type", Arg1);
8342 elsif not Has_Discriminants (Typ)
8343 or else Ekind (Etype (First_Discriminant (Typ)))
8344 /= E_Anonymous_Access_Type
8346 not Is_Class_Wide_Type
8347 (Designated_Type (Etype (First_Discriminant (Typ))))
8350 ("type must have a class-wide access discriminant", Arg1);
8358 -- pragma Keep_Names ([On => ] local_NAME);
8360 when Pragma_Keep_Names => Keep_Names : declare
8365 Check_Arg_Count (1);
8366 Check_Optional_Identifier (Arg1, Name_On);
8367 Check_Arg_Is_Local_Name (Arg1);
8369 Arg := Expression (Arg1);
8372 if Etype (Arg) = Any_Type then
8376 if not Is_Entity_Name (Arg)
8377 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8380 ("pragma% requires a local enumeration type", Arg1);
8383 Set_Discard_Names (Entity (Arg), False);
8390 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8392 when Pragma_License =>
8394 Check_Arg_Count (1);
8395 Check_No_Identifiers;
8396 Check_Valid_Configuration_Pragma;
8397 Check_Arg_Is_Identifier (Arg1);
8400 Sind : constant Source_File_Index :=
8401 Source_Index (Current_Sem_Unit);
8404 case Chars (Get_Pragma_Arg (Arg1)) is
8406 Set_License (Sind, GPL);
8408 when Name_Modified_GPL =>
8409 Set_License (Sind, Modified_GPL);
8411 when Name_Restricted =>
8412 Set_License (Sind, Restricted);
8414 when Name_Unrestricted =>
8415 Set_License (Sind, Unrestricted);
8418 Error_Pragma_Arg ("invalid license name", Arg1);
8426 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8428 when Pragma_Link_With => Link_With : declare
8434 if Operating_Mode = Generate_Code
8435 and then In_Extended_Main_Source_Unit (N)
8437 Check_At_Least_N_Arguments (1);
8438 Check_No_Identifiers;
8439 Check_Is_In_Decl_Part_Or_Package_Spec;
8440 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8444 while Present (Arg) loop
8445 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8447 -- Store argument, converting sequences of spaces to a
8448 -- single null character (this is one of the differences
8449 -- in processing between Link_With and Linker_Options).
8452 C : constant Char_Code := Get_Char_Code (' ');
8453 S : constant String_Id :=
8454 Strval (Expr_Value_S (Expression (Arg)));
8455 L : constant Nat := String_Length (S);
8458 procedure Skip_Spaces;
8459 -- Advance F past any spaces
8465 procedure Skip_Spaces is
8467 while F <= L and then Get_String_Char (S, F) = C loop
8472 -- Start of processing for Arg_Store
8475 Skip_Spaces; -- skip leading spaces
8477 -- Loop through characters, changing any embedded
8478 -- sequence of spaces to a single null character (this
8479 -- is how Link_With/Linker_Options differ)
8482 if Get_String_Char (S, F) = C then
8485 Store_String_Char (ASCII.NUL);
8488 Store_String_Char (Get_String_Char (S, F));
8496 if Present (Arg) then
8497 Store_String_Char (ASCII.NUL);
8501 Store_Linker_Option_String (End_String);
8509 -- pragma Linker_Alias (
8510 -- [Entity =>] LOCAL_NAME
8511 -- [Target =>] static_string_EXPRESSION);
8513 when Pragma_Linker_Alias =>
8515 Check_Arg_Order ((Name_Entity, Name_Target));
8516 Check_Arg_Count (2);
8517 Check_Optional_Identifier (Arg1, Name_Entity);
8518 Check_Optional_Identifier (Arg2, Name_Target);
8519 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8520 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8522 -- The only processing required is to link this item on to the
8523 -- list of rep items for the given entity. This is accomplished
8524 -- by the call to Rep_Item_Too_Late (when no error is detected
8525 -- and False is returned).
8527 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8530 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8533 ------------------------
8534 -- Linker_Constructor --
8535 ------------------------
8537 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8539 -- Code is shared with Linker_Destructor
8541 -----------------------
8542 -- Linker_Destructor --
8543 -----------------------
8545 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8547 when Pragma_Linker_Constructor |
8548 Pragma_Linker_Destructor =>
8549 Linker_Constructor : declare
8555 Check_Arg_Count (1);
8556 Check_No_Identifiers;
8557 Check_Arg_Is_Local_Name (Arg1);
8558 Arg1_X := Expression (Arg1);
8560 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8562 if not Is_Library_Level_Entity (Proc) then
8564 ("argument for pragma% must be library level entity", Arg1);
8567 -- The only processing required is to link this item on to the
8568 -- list of rep items for the given entity. This is accomplished
8569 -- by the call to Rep_Item_Too_Late (when no error is detected
8570 -- and False is returned).
8572 if Rep_Item_Too_Late (Proc, N) then
8575 Set_Has_Gigi_Rep_Item (Proc);
8577 end Linker_Constructor;
8579 --------------------
8580 -- Linker_Options --
8581 --------------------
8583 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8585 when Pragma_Linker_Options => Linker_Options : declare
8589 Check_Ada_83_Warning;
8590 Check_No_Identifiers;
8591 Check_Arg_Count (1);
8592 Check_Is_In_Decl_Part_Or_Package_Spec;
8593 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8594 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8597 while Present (Arg) loop
8598 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8599 Store_String_Char (ASCII.NUL);
8600 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8604 if Operating_Mode = Generate_Code
8605 and then In_Extended_Main_Source_Unit (N)
8607 Store_Linker_Option_String (End_String);
8611 --------------------
8612 -- Linker_Section --
8613 --------------------
8615 -- pragma Linker_Section (
8616 -- [Entity =>] LOCAL_NAME
8617 -- [Section =>] static_string_EXPRESSION);
8619 when Pragma_Linker_Section =>
8621 Check_Arg_Order ((Name_Entity, Name_Section));
8622 Check_Arg_Count (2);
8623 Check_Optional_Identifier (Arg1, Name_Entity);
8624 Check_Optional_Identifier (Arg2, Name_Section);
8625 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8626 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8628 -- This pragma applies only to objects
8630 if not Is_Object (Entity (Expression (Arg1))) then
8631 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8634 -- The only processing required is to link this item on to the
8635 -- list of rep items for the given entity. This is accomplished
8636 -- by the call to Rep_Item_Too_Late (when no error is detected
8637 -- and False is returned).
8639 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8642 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8649 -- pragma List (On | Off)
8651 -- There is nothing to do here, since we did all the processing for
8652 -- this pragma in Par.Prag (so that it works properly even in syntax
8658 --------------------
8659 -- Locking_Policy --
8660 --------------------
8662 -- pragma Locking_Policy (policy_IDENTIFIER);
8664 when Pragma_Locking_Policy => declare
8668 Check_Ada_83_Warning;
8669 Check_Arg_Count (1);
8670 Check_No_Identifiers;
8671 Check_Arg_Is_Locking_Policy (Arg1);
8672 Check_Valid_Configuration_Pragma;
8673 Get_Name_String (Chars (Expression (Arg1)));
8674 LP := Fold_Upper (Name_Buffer (1));
8676 if Locking_Policy /= ' '
8677 and then Locking_Policy /= LP
8679 Error_Msg_Sloc := Locking_Policy_Sloc;
8680 Error_Pragma ("locking policy incompatible with policy#");
8682 -- Set new policy, but always preserve System_Location since we
8683 -- like the error message with the run time name.
8686 Locking_Policy := LP;
8688 if Locking_Policy_Sloc /= System_Location then
8689 Locking_Policy_Sloc := Loc;
8698 -- pragma Long_Float (D_Float | G_Float);
8700 when Pragma_Long_Float =>
8702 Check_Valid_Configuration_Pragma;
8703 Check_Arg_Count (1);
8704 Check_No_Identifier (Arg1);
8705 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8707 if not OpenVMS_On_Target then
8708 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8713 if Chars (Expression (Arg1)) = Name_D_Float then
8714 if Opt.Float_Format_Long = 'G' then
8715 Error_Pragma ("G_Float previously specified");
8718 Opt.Float_Format_Long := 'D';
8720 -- G_Float case (this is the default, does not need overriding)
8723 if Opt.Float_Format_Long = 'D' then
8724 Error_Pragma ("D_Float previously specified");
8727 Opt.Float_Format_Long := 'G';
8730 Set_Standard_Fpt_Formats;
8732 -----------------------
8733 -- Machine_Attribute --
8734 -----------------------
8736 -- pragma Machine_Attribute (
8737 -- [Entity =>] LOCAL_NAME,
8738 -- [Attribute_Name =>] static_string_EXPRESSION
8739 -- [, [Info =>] static_string_EXPRESSION] );
8741 when Pragma_Machine_Attribute => Machine_Attribute : declare
8746 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8748 if Arg_Count = 3 then
8749 Check_Optional_Identifier (Arg3, Name_Info);
8750 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
8752 Check_Arg_Count (2);
8755 Check_Optional_Identifier (Arg1, Name_Entity);
8756 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8757 Check_Arg_Is_Local_Name (Arg1);
8758 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8759 Def_Id := Entity (Expression (Arg1));
8761 if Is_Access_Type (Def_Id) then
8762 Def_Id := Designated_Type (Def_Id);
8765 if Rep_Item_Too_Early (Def_Id, N) then
8769 Def_Id := Underlying_Type (Def_Id);
8771 -- The only processing required is to link this item on to the
8772 -- list of rep items for the given entity. This is accomplished
8773 -- by the call to Rep_Item_Too_Late (when no error is detected
8774 -- and False is returned).
8776 if Rep_Item_Too_Late (Def_Id, N) then
8779 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8781 end Machine_Attribute;
8788 -- (MAIN_OPTION [, MAIN_OPTION]);
8791 -- [STACK_SIZE =>] static_integer_EXPRESSION
8792 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8793 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8795 when Pragma_Main => Main : declare
8796 Args : Args_List (1 .. 3);
8797 Names : constant Name_List (1 .. 3) := (
8799 Name_Task_Stack_Size_Default,
8800 Name_Time_Slicing_Enabled);
8806 Gather_Associations (Names, Args);
8808 for J in 1 .. 2 loop
8809 if Present (Args (J)) then
8810 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8814 if Present (Args (3)) then
8815 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8819 while Present (Nod) loop
8820 if Nkind (Nod) = N_Pragma
8821 and then Pragma_Name (Nod) = Name_Main
8823 Error_Msg_Name_1 := Pname;
8824 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8835 -- pragma Main_Storage
8836 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8838 -- MAIN_STORAGE_OPTION ::=
8839 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8840 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8842 when Pragma_Main_Storage => Main_Storage : declare
8843 Args : Args_List (1 .. 2);
8844 Names : constant Name_List (1 .. 2) := (
8845 Name_Working_Storage,
8852 Gather_Associations (Names, Args);
8854 for J in 1 .. 2 loop
8855 if Present (Args (J)) then
8856 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8860 Check_In_Main_Program;
8863 while Present (Nod) loop
8864 if Nkind (Nod) = N_Pragma
8865 and then Pragma_Name (Nod) = Name_Main_Storage
8867 Error_Msg_Name_1 := Pname;
8868 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8879 -- pragma Memory_Size (NUMERIC_LITERAL)
8881 when Pragma_Memory_Size =>
8884 -- Memory size is simply ignored
8886 Check_No_Identifiers;
8887 Check_Arg_Count (1);
8888 Check_Arg_Is_Integer_Literal (Arg1);
8896 -- The only correct use of this pragma is on its own in a file, in
8897 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
8898 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
8899 -- check for a file containing nothing but a No_Body pragma). If we
8900 -- attempt to process it during normal semantics processing, it means
8901 -- it was misplaced.
8903 when Pragma_No_Body =>
8911 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
8913 when Pragma_No_Return => No_Return : declare
8921 Check_At_Least_N_Arguments (1);
8923 -- Loop through arguments of pragma
8926 while Present (Arg) loop
8927 Check_Arg_Is_Local_Name (Arg);
8928 Id := Expression (Arg);
8931 if not Is_Entity_Name (Id) then
8932 Error_Pragma_Arg ("entity name required", Arg);
8935 if Etype (Id) = Any_Type then
8939 -- Loop to find matching procedures
8944 and then Scope (E) = Current_Scope
8946 if Ekind (E) = E_Procedure
8947 or else Ekind (E) = E_Generic_Procedure
8951 -- Set flag on any alias as well
8953 if Is_Overloadable (E) and then Present (Alias (E)) then
8954 Set_No_Return (Alias (E));
8964 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
8975 -- pragma No_Run_Time;
8977 -- Note: this pragma is retained for backwards compatibility. See
8978 -- body of Rtsfind for full details on its handling.
8980 when Pragma_No_Run_Time =>
8982 Check_Valid_Configuration_Pragma;
8983 Check_Arg_Count (0);
8985 No_Run_Time_Mode := True;
8986 Configurable_Run_Time_Mode := True;
8988 -- Set Duration to 32 bits if word size is 32
8990 if Ttypes.System_Word_Size = 32 then
8991 Duration_32_Bits_On_Target := True;
8994 -- Set appropriate restrictions
8996 Set_Restriction (No_Finalization, N);
8997 Set_Restriction (No_Exception_Handlers, N);
8998 Set_Restriction (Max_Tasks, N, 0);
8999 Set_Restriction (No_Tasking, N);
9001 ------------------------
9002 -- No_Strict_Aliasing --
9003 ------------------------
9005 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9007 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9012 Check_At_Most_N_Arguments (1);
9014 if Arg_Count = 0 then
9015 Check_Valid_Configuration_Pragma;
9016 Opt.No_Strict_Aliasing := True;
9019 Check_Optional_Identifier (Arg2, Name_Entity);
9020 Check_Arg_Is_Local_Name (Arg1);
9021 E_Id := Entity (Expression (Arg1));
9023 if E_Id = Any_Type then
9025 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9026 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9029 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9031 end No_Strict_Aliasing;
9033 -----------------------
9034 -- Normalize_Scalars --
9035 -----------------------
9037 -- pragma Normalize_Scalars;
9039 when Pragma_Normalize_Scalars =>
9040 Check_Ada_83_Warning;
9041 Check_Arg_Count (0);
9042 Check_Valid_Configuration_Pragma;
9043 Normalize_Scalars := True;
9044 Init_Or_Norm_Scalars := True;
9050 -- pragma Obsolescent;
9052 -- pragma Obsolescent (
9053 -- [Message =>] static_string_EXPRESSION
9054 -- [,[Version =>] Ada_05]]);
9056 -- pragma Obsolescent (
9058 -- [,[Message =>] static_string_EXPRESSION
9059 -- [,[Version =>] Ada_05]] );
9061 when Pragma_Obsolescent => Obsolescent : declare
9065 procedure Set_Obsolescent (E : Entity_Id);
9066 -- Given an entity Ent, mark it as obsolescent if appropriate
9068 ---------------------
9069 -- Set_Obsolescent --
9070 ---------------------
9072 procedure Set_Obsolescent (E : Entity_Id) is
9081 -- Entity name was given
9083 if Present (Ename) then
9085 -- If entity name matches, we are fine. Save entity in
9086 -- pragma argument, for ASIS use.
9088 if Chars (Ename) = Chars (Ent) then
9089 Set_Entity (Ename, Ent);
9090 Generate_Reference (Ent, Ename);
9092 -- If entity name does not match, only possibility is an
9093 -- enumeration literal from an enumeration type declaration.
9095 elsif Ekind (Ent) /= E_Enumeration_Type then
9097 ("pragma % entity name does not match declaration");
9100 Ent := First_Literal (E);
9104 ("pragma % entity name does not match any " &
9105 "enumeration literal");
9107 elsif Chars (Ent) = Chars (Ename) then
9108 Set_Entity (Ename, Ent);
9109 Generate_Reference (Ent, Ename);
9113 Ent := Next_Literal (Ent);
9119 -- Ent points to entity to be marked
9121 if Arg_Count >= 1 then
9123 -- Deal with static string argument
9125 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9126 S := Strval (Expression (Arg1));
9128 for J in 1 .. String_Length (S) loop
9129 if not In_Character_Range (Get_String_Char (S, J)) then
9131 ("pragma% argument does not allow wide characters",
9136 Obsolescent_Warnings.Append
9137 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9139 -- Check for Ada_05 parameter
9141 if Arg_Count /= 1 then
9142 Check_Arg_Count (2);
9145 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9148 Check_Arg_Is_Identifier (Argx);
9150 if Chars (Argx) /= Name_Ada_05 then
9151 Error_Msg_Name_2 := Name_Ada_05;
9153 ("only allowed argument for pragma% is %", Argx);
9156 if Ada_Version_Explicit < Ada_05
9157 or else not Warn_On_Ada_2005_Compatibility
9165 -- Set flag if pragma active
9168 Set_Is_Obsolescent (Ent);
9172 end Set_Obsolescent;
9174 -- Start of processing for pragma Obsolescent
9179 Check_At_Most_N_Arguments (3);
9181 -- See if first argument specifies an entity name
9185 (Chars (Arg1) = Name_Entity
9187 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9191 Ename := Get_Pragma_Arg (Arg1);
9193 -- Eliminate first argument, so we can share processing
9197 Arg_Count := Arg_Count - 1;
9199 -- No Entity name argument given
9205 if Arg_Count >= 1 then
9206 Check_Optional_Identifier (Arg1, Name_Message);
9208 if Arg_Count = 2 then
9209 Check_Optional_Identifier (Arg2, Name_Version);
9213 -- Get immediately preceding declaration
9216 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9220 -- Cases where we do not follow anything other than another pragma
9224 -- First case: library level compilation unit declaration with
9225 -- the pragma immediately following the declaration.
9227 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9229 (Defining_Entity (Unit (Parent (Parent (N)))));
9232 -- Case 2: library unit placement for package
9236 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9238 if Is_Package_Or_Generic_Package (Ent) then
9239 Set_Obsolescent (Ent);
9245 -- Cases where we must follow a declaration
9248 if Nkind (Decl) not in N_Declaration
9249 and then Nkind (Decl) not in N_Later_Decl_Item
9250 and then Nkind (Decl) not in N_Generic_Declaration
9253 ("pragma% misplaced, "
9254 & "must immediately follow a declaration");
9257 Set_Obsolescent (Defining_Entity (Decl));
9267 -- pragma Optimize (Time | Space | Off);
9269 -- The actual check for optimize is done in Gigi. Note that this
9270 -- pragma does not actually change the optimization setting, it
9271 -- simply checks that it is consistent with the pragma.
9273 when Pragma_Optimize =>
9274 Check_No_Identifiers;
9275 Check_Arg_Count (1);
9276 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9278 ------------------------
9279 -- Optimize_Alignment --
9280 ------------------------
9282 -- pragma Optimize_Alignment (Time | Space | Off);
9284 when Pragma_Optimize_Alignment =>
9286 Check_No_Identifiers;
9287 Check_Arg_Count (1);
9288 Check_Valid_Configuration_Pragma;
9291 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9295 Opt.Optimize_Alignment := 'T';
9297 Opt.Optimize_Alignment := 'S';
9299 Opt.Optimize_Alignment := 'O';
9301 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9305 -- Set indication that mode is set locally. If we are in fact in a
9306 -- configuration pragma file, this setting is harmless since the
9307 -- switch will get reset anyway at the start of each unit.
9309 Optimize_Alignment_Local := True;
9315 -- pragma Pack (first_subtype_LOCAL_NAME);
9317 when Pragma_Pack => Pack : declare
9318 Assoc : constant Node_Id := Arg1;
9323 Check_No_Identifiers;
9324 Check_Arg_Count (1);
9325 Check_Arg_Is_Local_Name (Arg1);
9327 Type_Id := Expression (Assoc);
9328 Find_Type (Type_Id);
9329 Typ := Entity (Type_Id);
9332 or else Rep_Item_Too_Early (Typ, N)
9336 Typ := Underlying_Type (Typ);
9339 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9340 Error_Pragma ("pragma% must specify array or record type");
9343 Check_First_Subtype (Arg1);
9345 if Has_Pragma_Pack (Typ) then
9346 Error_Pragma ("duplicate pragma%, only one allowed");
9350 elsif Is_Array_Type (Typ) then
9352 -- Pack not allowed for aliased or atomic components
9354 if Has_Aliased_Components (Base_Type (Typ)) then
9356 ("pragma% ignored, cannot pack aliased components?");
9358 elsif Has_Atomic_Components (Typ)
9359 or else Is_Atomic (Component_Type (Typ))
9362 ("?pragma% ignored, cannot pack atomic components");
9365 -- If we had an explicit component size given, then we do not
9366 -- let Pack override this given size. We also give a warning
9367 -- that Pack is being ignored unless we can tell for sure that
9368 -- the Pack would not have had any effect anyway.
9370 if Has_Component_Size_Clause (Typ) then
9371 if Known_Static_RM_Size (Component_Type (Typ))
9373 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9378 ("?pragma% ignored, explicit component size given");
9381 -- If no prior array component size given, Pack is effective
9384 if not Rep_Item_Too_Late (Typ, N) then
9385 if VM_Target = No_VM then
9386 Set_Is_Packed (Base_Type (Typ));
9387 elsif not GNAT_Mode then
9389 ("?pragma% ignored in this configuration");
9392 Set_Has_Pragma_Pack (Base_Type (Typ));
9393 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9397 -- For record types, the pack is always effective
9399 else pragma Assert (Is_Record_Type (Typ));
9400 if not Rep_Item_Too_Late (Typ, N) then
9401 if VM_Target = No_VM then
9402 Set_Is_Packed (Base_Type (Typ));
9403 elsif not GNAT_Mode then
9404 Error_Pragma ("?pragma% ignored in this configuration");
9407 Set_Has_Pragma_Pack (Base_Type (Typ));
9408 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9419 -- There is nothing to do here, since we did all the processing for
9420 -- this pragma in Par.Prag (so that it works properly even in syntax
9430 -- pragma Passive [(PASSIVE_FORM)];
9432 -- PASSIVE_FORM ::= Semaphore | No
9434 when Pragma_Passive =>
9437 if Nkind (Parent (N)) /= N_Task_Definition then
9438 Error_Pragma ("pragma% must be within task definition");
9441 if Arg_Count /= 0 then
9442 Check_Arg_Count (1);
9443 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9446 ----------------------------------
9447 -- Preelaborable_Initialization --
9448 ----------------------------------
9450 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9452 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9457 Check_Arg_Count (1);
9458 Check_No_Identifiers;
9459 Check_Arg_Is_Identifier (Arg1);
9460 Check_Arg_Is_Local_Name (Arg1);
9461 Check_First_Subtype (Arg1);
9462 Ent := Entity (Expression (Arg1));
9464 if not Is_Private_Type (Ent)
9465 and then not Is_Protected_Type (Ent)
9468 ("pragma % can only be applied to private or protected type",
9472 -- Give an error if the pragma is applied to a protected type that
9473 -- does not qualify (due to having entries, or due to components
9474 -- that do not qualify).
9476 if Is_Protected_Type (Ent)
9477 and then not Has_Preelaborable_Initialization (Ent)
9480 ("protected type & does not have preelaborable " &
9481 "initialization", Ent);
9483 -- Otherwise mark the type as definitely having preelaborable
9487 Set_Known_To_Have_Preelab_Init (Ent);
9490 if Has_Pragma_Preelab_Init (Ent)
9491 and then Warn_On_Redundant_Constructs
9493 Error_Pragma ("?duplicate pragma%!");
9495 Set_Has_Pragma_Preelab_Init (Ent);
9499 --------------------
9500 -- Persistent_BSS --
9501 --------------------
9503 when Pragma_Persistent_BSS => Persistent_BSS : declare
9510 Check_At_Most_N_Arguments (1);
9512 -- Case of application to specific object (one argument)
9514 if Arg_Count = 1 then
9515 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9517 if not Is_Entity_Name (Expression (Arg1))
9519 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9520 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9522 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9525 Ent := Entity (Expression (Arg1));
9526 Decl := Parent (Ent);
9528 if Rep_Item_Too_Late (Ent, N) then
9532 if Present (Expression (Decl)) then
9534 ("object for pragma% cannot have initialization", Arg1);
9537 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9539 ("object type for pragma% is not potentially persistent",
9544 Make_Linker_Section_Pragma
9545 (Ent, Sloc (N), ".persistent.bss");
9546 Insert_After (N, Prag);
9549 -- Case of use as configuration pragma with no arguments
9552 Check_Valid_Configuration_Pragma;
9553 Persistent_BSS_Mode := True;
9561 -- pragma Polling (ON | OFF);
9563 when Pragma_Polling =>
9565 Check_Arg_Count (1);
9566 Check_No_Identifiers;
9567 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9568 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9574 -- pragma Postcondition ([Check =>] Boolean_Expression
9575 -- [,[Message =>] String_Expression]);
9577 when Pragma_Postcondition => Postcondition : declare
9579 pragma Warnings (Off, In_Body);
9583 Check_At_Least_N_Arguments (1);
9584 Check_At_Most_N_Arguments (2);
9585 Check_Optional_Identifier (Arg1, Name_Check);
9587 -- All we need to do here is call the common check procedure,
9588 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9590 Check_Precondition_Postcondition (In_Body);
9597 -- pragma Precondition ([Check =>] Boolean_Expression
9598 -- [,[Message =>] String_Expression]);
9600 when Pragma_Precondition => Precondition : declare
9605 Check_At_Least_N_Arguments (1);
9606 Check_At_Most_N_Arguments (2);
9607 Check_Optional_Identifier (Arg1, Name_Check);
9609 Check_Precondition_Postcondition (In_Body);
9611 -- If in spec, nothing to do. If in body, then we convert the
9612 -- pragma to pragma Check (Precondition, cond [, msg]). Note we
9613 -- do this whether or not precondition checks are enabled. That
9614 -- works fine since pragma Check will do this check.
9617 if Arg_Count = 2 then
9618 Check_Optional_Identifier (Arg3, Name_Message);
9619 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9622 Analyze_And_Resolve (Get_Pragma_Arg (Arg1), Standard_Boolean);
9626 Chars => Name_Check,
9627 Pragma_Argument_Associations => New_List (
9628 Make_Pragma_Argument_Association (Loc,
9630 Make_Identifier (Loc,
9631 Chars => Name_Precondition)),
9633 Make_Pragma_Argument_Association (Sloc (Arg1),
9634 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9636 if Arg_Count = 2 then
9637 Append_To (Pragma_Argument_Associations (N),
9638 Make_Pragma_Argument_Association (Sloc (Arg2),
9639 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9650 -- pragma Preelaborate [(library_unit_NAME)];
9652 -- Set the flag Is_Preelaborated of program unit name entity
9654 when Pragma_Preelaborate => Preelaborate : declare
9655 Pa : constant Node_Id := Parent (N);
9656 Pk : constant Node_Kind := Nkind (Pa);
9660 Check_Ada_83_Warning;
9661 Check_Valid_Library_Unit_Pragma;
9663 if Nkind (N) = N_Null_Statement then
9667 Ent := Find_Lib_Unit_Name;
9669 -- This filters out pragmas inside generic parent then
9670 -- show up inside instantiation
9673 and then not (Pk = N_Package_Specification
9674 and then Present (Generic_Parent (Pa)))
9676 if not Debug_Flag_U then
9677 Set_Is_Preelaborated (Ent);
9678 Set_Suppress_Elaboration_Warnings (Ent);
9683 ---------------------
9684 -- Preelaborate_05 --
9685 ---------------------
9687 -- pragma Preelaborate_05 [(library_unit_NAME)];
9689 -- This pragma is useable only in GNAT_Mode, where it is used like
9690 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9691 -- (otherwise it is ignored). This is used to implement AI-362 which
9692 -- recategorizes some run-time packages in Ada 2005 mode.
9694 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9699 Check_Valid_Library_Unit_Pragma;
9701 if not GNAT_Mode then
9702 Error_Pragma ("pragma% only available in GNAT mode");
9705 if Nkind (N) = N_Null_Statement then
9709 -- This is one of the few cases where we need to test the value of
9710 -- Ada_Version_Explicit rather than Ada_Version (which is always
9711 -- set to Ada_05 in a predefined unit), we need to know the
9712 -- explicit version set to know if this pragma is active.
9714 if Ada_Version_Explicit >= Ada_05 then
9715 Ent := Find_Lib_Unit_Name;
9716 Set_Is_Preelaborated (Ent);
9717 Set_Suppress_Elaboration_Warnings (Ent);
9719 end Preelaborate_05;
9725 -- pragma Priority (EXPRESSION);
9727 when Pragma_Priority => Priority : declare
9728 P : constant Node_Id := Parent (N);
9732 Check_No_Identifiers;
9733 Check_Arg_Count (1);
9737 if Nkind (P) = N_Subprogram_Body then
9738 Check_In_Main_Program;
9740 Arg := Expression (Arg1);
9741 Analyze_And_Resolve (Arg, Standard_Integer);
9745 if not Is_Static_Expression (Arg) then
9746 Flag_Non_Static_Expr
9747 ("main subprogram priority is not static!", Arg);
9750 -- If constraint error, then we already signalled an error
9752 elsif Raises_Constraint_Error (Arg) then
9755 -- Otherwise check in range
9759 Val : constant Uint := Expr_Value (Arg);
9763 or else Val > Expr_Value (Expression
9764 (Parent (RTE (RE_Max_Priority))))
9767 ("main subprogram priority is out of range", Arg1);
9773 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9775 -- Load an arbitrary entity from System.Tasking to make sure
9776 -- this package is implicitly with'ed, since we need to have
9777 -- the tasking run-time active for the pragma Priority to have
9781 Discard : Entity_Id;
9782 pragma Warnings (Off, Discard);
9784 Discard := RTE (RE_Task_List);
9787 -- Task or Protected, must be of type Integer
9789 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9790 Arg := Expression (Arg1);
9792 -- The expression must be analyzed in the special manner
9793 -- described in "Handling of Default and Per-Object
9794 -- Expressions" in sem.ads.
9796 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9798 if not Is_Static_Expression (Arg) then
9799 Check_Restriction (Static_Priorities, Arg);
9802 -- Anything else is incorrect
9808 if Has_Priority_Pragma (P) then
9809 Error_Pragma ("duplicate pragma% not allowed");
9811 Set_Has_Priority_Pragma (P, True);
9813 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9814 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9815 -- exp_ch9 should use this ???
9820 -----------------------------------
9821 -- Priority_Specific_Dispatching --
9822 -----------------------------------
9824 -- pragma Priority_Specific_Dispatching (
9825 -- policy_IDENTIFIER,
9826 -- first_priority_EXPRESSION,
9827 -- last_priority_EXPRESSION);
9829 when Pragma_Priority_Specific_Dispatching =>
9830 Priority_Specific_Dispatching : declare
9831 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9832 -- This is the entity System.Any_Priority;
9835 Lower_Bound : Node_Id;
9836 Upper_Bound : Node_Id;
9842 Check_Arg_Count (3);
9843 Check_No_Identifiers;
9844 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9845 Check_Valid_Configuration_Pragma;
9846 Get_Name_String (Chars (Expression (Arg1)));
9847 DP := Fold_Upper (Name_Buffer (1));
9849 Lower_Bound := Expression (Arg2);
9850 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9851 Lower_Val := Expr_Value (Lower_Bound);
9853 Upper_Bound := Expression (Arg3);
9854 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
9855 Upper_Val := Expr_Value (Upper_Bound);
9857 -- It is not allowed to use Task_Dispatching_Policy and
9858 -- Priority_Specific_Dispatching in the same partition.
9860 if Task_Dispatching_Policy /= ' ' then
9861 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9863 ("pragma% incompatible with Task_Dispatching_Policy#");
9865 -- Check lower bound in range
9867 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9869 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
9872 ("first_priority is out of range", Arg2);
9874 -- Check upper bound in range
9876 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
9878 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
9881 ("last_priority is out of range", Arg3);
9883 -- Check that the priority range is valid
9885 elsif Lower_Val > Upper_Val then
9887 ("last_priority_expression must be greater than" &
9888 " or equal to first_priority_expression");
9890 -- Store the new policy, but always preserve System_Location since
9891 -- we like the error message with the run-time name.
9894 -- Check overlapping in the priority ranges specified in other
9895 -- Priority_Specific_Dispatching pragmas within the same
9896 -- partition. We can only check those we know about!
9899 Specific_Dispatching.First .. Specific_Dispatching.Last
9901 if Specific_Dispatching.Table (J).First_Priority in
9902 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9903 or else Specific_Dispatching.Table (J).Last_Priority in
9904 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
9907 Specific_Dispatching.Table (J).Pragma_Loc;
9909 ("priority range overlaps with "
9910 & "Priority_Specific_Dispatching#");
9914 -- The use of Priority_Specific_Dispatching is incompatible
9915 -- with Task_Dispatching_Policy.
9917 if Task_Dispatching_Policy /= ' ' then
9918 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
9920 ("Priority_Specific_Dispatching incompatible "
9921 & "with Task_Dispatching_Policy#");
9924 -- The use of Priority_Specific_Dispatching forces ceiling
9927 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
9928 Error_Msg_Sloc := Locking_Policy_Sloc;
9930 ("Priority_Specific_Dispatching incompatible "
9931 & "with Locking_Policy#");
9933 -- Set the Ceiling_Locking policy, but preserve System_Location
9934 -- since we like the error message with the run time name.
9937 Locking_Policy := 'C';
9939 if Locking_Policy_Sloc /= System_Location then
9940 Locking_Policy_Sloc := Loc;
9944 -- Add entry in the table
9946 Specific_Dispatching.Append
9947 ((Dispatching_Policy => DP,
9948 First_Priority => UI_To_Int (Lower_Val),
9949 Last_Priority => UI_To_Int (Upper_Val),
9950 Pragma_Loc => Loc));
9952 end Priority_Specific_Dispatching;
9958 -- pragma Profile (profile_IDENTIFIER);
9960 -- profile_IDENTIFIER => Restricted | Ravenscar
9962 when Pragma_Profile =>
9964 Check_Arg_Count (1);
9965 Check_Valid_Configuration_Pragma;
9966 Check_No_Identifiers;
9969 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9971 if Chars (Argx) = Name_Ravenscar then
9972 Set_Ravenscar_Profile (N);
9973 elsif Chars (Argx) = Name_Restricted then
9974 Set_Profile_Restrictions
9975 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
9977 Error_Pragma_Arg ("& is not a valid profile", Argx);
9981 ----------------------
9982 -- Profile_Warnings --
9983 ----------------------
9985 -- pragma Profile_Warnings (profile_IDENTIFIER);
9987 -- profile_IDENTIFIER => Restricted | Ravenscar
9989 when Pragma_Profile_Warnings =>
9991 Check_Arg_Count (1);
9992 Check_Valid_Configuration_Pragma;
9993 Check_No_Identifiers;
9996 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
9998 if Chars (Argx) = Name_Ravenscar then
9999 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10000 elsif Chars (Argx) = Name_Restricted then
10001 Set_Profile_Restrictions (Restricted, N, Warn => True);
10003 Error_Pragma_Arg ("& is not a valid profile", Argx);
10007 --------------------------
10008 -- Propagate_Exceptions --
10009 --------------------------
10011 -- pragma Propagate_Exceptions;
10013 -- Note: this pragma is obsolete and has no effect
10015 when Pragma_Propagate_Exceptions =>
10017 Check_Arg_Count (0);
10019 if In_Extended_Main_Source_Unit (N) then
10020 Propagate_Exceptions := True;
10027 -- pragma Psect_Object (
10028 -- [Internal =>] LOCAL_NAME,
10029 -- [, [External =>] EXTERNAL_SYMBOL]
10030 -- [, [Size =>] EXTERNAL_SYMBOL]);
10032 when Pragma_Psect_Object | Pragma_Common_Object =>
10033 Psect_Object : declare
10034 Args : Args_List (1 .. 3);
10035 Names : constant Name_List (1 .. 3) := (
10040 Internal : Node_Id renames Args (1);
10041 External : Node_Id renames Args (2);
10042 Size : Node_Id renames Args (3);
10044 Def_Id : Entity_Id;
10046 procedure Check_Too_Long (Arg : Node_Id);
10047 -- Posts message if the argument is an identifier with more
10048 -- than 31 characters, or a string literal with more than
10049 -- 31 characters, and we are operating under VMS
10051 --------------------
10052 -- Check_Too_Long --
10053 --------------------
10055 procedure Check_Too_Long (Arg : Node_Id) is
10056 X : constant Node_Id := Original_Node (Arg);
10059 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10061 ("inappropriate argument for pragma %", Arg);
10064 if OpenVMS_On_Target then
10065 if (Nkind (X) = N_String_Literal
10066 and then String_Length (Strval (X)) > 31)
10068 (Nkind (X) = N_Identifier
10069 and then Length_Of_Name (Chars (X)) > 31)
10072 ("argument for pragma % is longer than 31 characters",
10076 end Check_Too_Long;
10078 -- Start of processing for Common_Object/Psect_Object
10082 Gather_Associations (Names, Args);
10083 Process_Extended_Import_Export_Internal_Arg (Internal);
10085 Def_Id := Entity (Internal);
10087 if Ekind (Def_Id) /= E_Constant
10088 and then Ekind (Def_Id) /= E_Variable
10091 ("pragma% must designate an object", Internal);
10094 Check_Too_Long (Internal);
10096 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10098 ("cannot use pragma% for imported/exported object",
10102 if Is_Concurrent_Type (Etype (Internal)) then
10104 ("cannot specify pragma % for task/protected object",
10108 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10110 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10112 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10115 if Ekind (Def_Id) = E_Constant then
10117 ("cannot specify pragma % for a constant", Internal);
10120 if Is_Record_Type (Etype (Internal)) then
10126 Ent := First_Entity (Etype (Internal));
10127 while Present (Ent) loop
10128 Decl := Declaration_Node (Ent);
10130 if Ekind (Ent) = E_Component
10131 and then Nkind (Decl) = N_Component_Declaration
10132 and then Present (Expression (Decl))
10133 and then Warn_On_Export_Import
10136 ("?object for pragma % has defaults", Internal);
10146 if Present (Size) then
10147 Check_Too_Long (Size);
10150 if Present (External) then
10151 Check_Arg_Is_External_Name (External);
10152 Check_Too_Long (External);
10155 -- If all error tests pass, link pragma on to the rep item chain
10157 Record_Rep_Item (Def_Id, N);
10164 -- pragma Pure [(library_unit_NAME)];
10166 when Pragma_Pure => Pure : declare
10170 Check_Ada_83_Warning;
10171 Check_Valid_Library_Unit_Pragma;
10173 if Nkind (N) = N_Null_Statement then
10177 Ent := Find_Lib_Unit_Name;
10179 Set_Has_Pragma_Pure (Ent);
10180 Set_Suppress_Elaboration_Warnings (Ent);
10187 -- pragma Pure_05 [(library_unit_NAME)];
10189 -- This pragma is useable only in GNAT_Mode, where it is used like
10190 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10191 -- it is ignored). It may be used after a pragma Preelaborate, in
10192 -- which case it overrides the effect of the pragma Preelaborate.
10193 -- This is used to implement AI-362 which recategorizes some run-time
10194 -- packages in Ada 2005 mode.
10196 when Pragma_Pure_05 => Pure_05 : declare
10201 Check_Valid_Library_Unit_Pragma;
10203 if not GNAT_Mode then
10204 Error_Pragma ("pragma% only available in GNAT mode");
10207 if Nkind (N) = N_Null_Statement then
10211 -- This is one of the few cases where we need to test the value of
10212 -- Ada_Version_Explicit rather than Ada_Version (which is always
10213 -- set to Ada_05 in a predefined unit), we need to know the
10214 -- explicit version set to know if this pragma is active.
10216 if Ada_Version_Explicit >= Ada_05 then
10217 Ent := Find_Lib_Unit_Name;
10218 Set_Is_Preelaborated (Ent, False);
10220 Set_Suppress_Elaboration_Warnings (Ent);
10224 -------------------
10225 -- Pure_Function --
10226 -------------------
10228 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10230 when Pragma_Pure_Function => Pure_Function : declare
10233 Def_Id : Entity_Id;
10234 Effective : Boolean := False;
10238 Check_Arg_Count (1);
10239 Check_Optional_Identifier (Arg1, Name_Entity);
10240 Check_Arg_Is_Local_Name (Arg1);
10241 E_Id := Expression (Arg1);
10243 if Error_Posted (E_Id) then
10247 -- Loop through homonyms (overloadings) of referenced entity
10249 E := Entity (E_Id);
10251 if Present (E) then
10253 Def_Id := Get_Base_Subprogram (E);
10255 if Ekind (Def_Id) /= E_Function
10256 and then Ekind (Def_Id) /= E_Generic_Function
10257 and then Ekind (Def_Id) /= E_Operator
10260 ("pragma% requires a function name", Arg1);
10263 Set_Is_Pure (Def_Id);
10265 if not Has_Pragma_Pure_Function (Def_Id) then
10266 Set_Has_Pragma_Pure_Function (Def_Id);
10271 exit when No (E) or else Scope (E) /= Current_Scope;
10275 and then Warn_On_Redundant_Constructs
10277 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10283 --------------------
10284 -- Queuing_Policy --
10285 --------------------
10287 -- pragma Queuing_Policy (policy_IDENTIFIER);
10289 when Pragma_Queuing_Policy => declare
10293 Check_Ada_83_Warning;
10294 Check_Arg_Count (1);
10295 Check_No_Identifiers;
10296 Check_Arg_Is_Queuing_Policy (Arg1);
10297 Check_Valid_Configuration_Pragma;
10298 Get_Name_String (Chars (Expression (Arg1)));
10299 QP := Fold_Upper (Name_Buffer (1));
10301 if Queuing_Policy /= ' '
10302 and then Queuing_Policy /= QP
10304 Error_Msg_Sloc := Queuing_Policy_Sloc;
10305 Error_Pragma ("queuing policy incompatible with policy#");
10307 -- Set new policy, but always preserve System_Location since we
10308 -- like the error message with the run time name.
10311 Queuing_Policy := QP;
10313 if Queuing_Policy_Sloc /= System_Location then
10314 Queuing_Policy_Sloc := Loc;
10319 -----------------------
10320 -- Relative_Deadline --
10321 -----------------------
10323 -- pragma Relative_Deadline (time_span_EXPRESSION);
10325 when Pragma_Relative_Deadline => Relative_Deadline : declare
10326 P : constant Node_Id := Parent (N);
10331 Check_No_Identifiers;
10332 Check_Arg_Count (1);
10334 Arg := Expression (Arg1);
10336 -- The expression must be analyzed in the special manner described
10337 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10339 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10343 if Nkind (P) = N_Subprogram_Body then
10344 Check_In_Main_Program;
10348 elsif Nkind (P) = N_Task_Definition then
10351 -- Anything else is incorrect
10357 if Has_Relative_Deadline_Pragma (P) then
10358 Error_Pragma ("duplicate pragma% not allowed");
10360 Set_Has_Relative_Deadline_Pragma (P, True);
10362 if Nkind (P) = N_Task_Definition then
10363 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10366 end Relative_Deadline;
10368 ---------------------------
10369 -- Remote_Call_Interface --
10370 ---------------------------
10372 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10374 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10375 Cunit_Node : Node_Id;
10376 Cunit_Ent : Entity_Id;
10380 Check_Ada_83_Warning;
10381 Check_Valid_Library_Unit_Pragma;
10383 if Nkind (N) = N_Null_Statement then
10387 Cunit_Node := Cunit (Current_Sem_Unit);
10388 K := Nkind (Unit (Cunit_Node));
10389 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10391 if K = N_Package_Declaration
10392 or else K = N_Generic_Package_Declaration
10393 or else K = N_Subprogram_Declaration
10394 or else K = N_Generic_Subprogram_Declaration
10395 or else (K = N_Subprogram_Body
10396 and then Acts_As_Spec (Unit (Cunit_Node)))
10401 "pragma% must apply to package or subprogram declaration");
10404 Set_Is_Remote_Call_Interface (Cunit_Ent);
10405 end Remote_Call_Interface;
10411 -- pragma Remote_Types [(library_unit_NAME)];
10413 when Pragma_Remote_Types => Remote_Types : declare
10414 Cunit_Node : Node_Id;
10415 Cunit_Ent : Entity_Id;
10418 Check_Ada_83_Warning;
10419 Check_Valid_Library_Unit_Pragma;
10421 if Nkind (N) = N_Null_Statement then
10425 Cunit_Node := Cunit (Current_Sem_Unit);
10426 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10428 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10429 N_Generic_Package_Declaration)
10432 ("pragma% can only apply to a package declaration");
10435 Set_Is_Remote_Types (Cunit_Ent);
10442 -- pragma Ravenscar;
10444 when Pragma_Ravenscar =>
10446 Check_Arg_Count (0);
10447 Check_Valid_Configuration_Pragma;
10448 Set_Ravenscar_Profile (N);
10450 if Warn_On_Obsolescent_Feature then
10452 ("pragma Ravenscar is an obsolescent feature?", N);
10454 ("|use pragma Profile (Ravenscar) instead", N);
10457 -------------------------
10458 -- Restricted_Run_Time --
10459 -------------------------
10461 -- pragma Restricted_Run_Time;
10463 when Pragma_Restricted_Run_Time =>
10465 Check_Arg_Count (0);
10466 Check_Valid_Configuration_Pragma;
10467 Set_Profile_Restrictions
10468 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10470 if Warn_On_Obsolescent_Feature then
10472 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10474 ("|use pragma Profile (Restricted) instead", N);
10481 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10484 -- restriction_IDENTIFIER
10485 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10487 when Pragma_Restrictions =>
10488 Process_Restrictions_Or_Restriction_Warnings
10489 (Warn => Treat_Restrictions_As_Warnings);
10491 --------------------------
10492 -- Restriction_Warnings --
10493 --------------------------
10495 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10498 -- restriction_IDENTIFIER
10499 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10501 when Pragma_Restriction_Warnings =>
10503 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10509 -- pragma Reviewable;
10511 when Pragma_Reviewable =>
10512 Check_Ada_83_Warning;
10513 Check_Arg_Count (0);
10516 -------------------
10517 -- Share_Generic --
10518 -------------------
10520 -- pragma Share_Generic (NAME {, NAME});
10522 when Pragma_Share_Generic =>
10524 Process_Generic_List;
10530 -- pragma Shared (LOCAL_NAME);
10532 when Pragma_Shared =>
10534 Process_Atomic_Shared_Volatile;
10536 --------------------
10537 -- Shared_Passive --
10538 --------------------
10540 -- pragma Shared_Passive [(library_unit_NAME)];
10542 -- Set the flag Is_Shared_Passive of program unit name entity
10544 when Pragma_Shared_Passive => Shared_Passive : declare
10545 Cunit_Node : Node_Id;
10546 Cunit_Ent : Entity_Id;
10549 Check_Ada_83_Warning;
10550 Check_Valid_Library_Unit_Pragma;
10552 if Nkind (N) = N_Null_Statement then
10556 Cunit_Node := Cunit (Current_Sem_Unit);
10557 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10559 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10560 N_Generic_Package_Declaration)
10563 ("pragma% can only apply to a package declaration");
10566 Set_Is_Shared_Passive (Cunit_Ent);
10567 end Shared_Passive;
10569 ----------------------
10570 -- Source_File_Name --
10571 ----------------------
10573 -- There are five forms for this pragma:
10575 -- pragma Source_File_Name (
10576 -- [UNIT_NAME =>] unit_NAME,
10577 -- BODY_FILE_NAME => STRING_LITERAL
10578 -- [, [INDEX =>] INTEGER_LITERAL]);
10580 -- pragma Source_File_Name (
10581 -- [UNIT_NAME =>] unit_NAME,
10582 -- SPEC_FILE_NAME => STRING_LITERAL
10583 -- [, [INDEX =>] INTEGER_LITERAL]);
10585 -- pragma Source_File_Name (
10586 -- BODY_FILE_NAME => STRING_LITERAL
10587 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10588 -- [, CASING => CASING_SPEC]);
10590 -- pragma Source_File_Name (
10591 -- SPEC_FILE_NAME => STRING_LITERAL
10592 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10593 -- [, CASING => CASING_SPEC]);
10595 -- pragma Source_File_Name (
10596 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10597 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10598 -- [, CASING => CASING_SPEC]);
10600 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10602 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10603 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
10604 -- only be used when no project file is used, while SFNP can only be
10605 -- used when a project file is used.
10607 -- No processing here. Processing was completed during parsing, since
10608 -- we need to have file names set as early as possible. Units are
10609 -- loaded well before semantic processing starts.
10611 -- The only processing we defer to this point is the check for
10612 -- correct placement.
10614 when Pragma_Source_File_Name =>
10616 Check_Valid_Configuration_Pragma;
10618 ------------------------------
10619 -- Source_File_Name_Project --
10620 ------------------------------
10622 -- See Source_File_Name for syntax
10624 -- No processing here. Processing was completed during parsing, since
10625 -- we need to have file names set as early as possible. Units are
10626 -- loaded well before semantic processing starts.
10628 -- The only processing we defer to this point is the check for
10629 -- correct placement.
10631 when Pragma_Source_File_Name_Project =>
10633 Check_Valid_Configuration_Pragma;
10635 -- Check that a pragma Source_File_Name_Project is used only in a
10636 -- configuration pragmas file.
10638 -- Pragmas Source_File_Name_Project should only be generated by
10639 -- the Project Manager in configuration pragmas files.
10641 -- This is really an ugly test. It seems to depend on some
10642 -- accidental and undocumented property. At the very least it
10643 -- needs to be documented, but it would be better to have a
10644 -- clean way of testing if we are in a configuration file???
10646 if Present (Parent (N)) then
10648 ("pragma% can only appear in a configuration pragmas file");
10651 ----------------------
10652 -- Source_Reference --
10653 ----------------------
10655 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10657 -- Nothing to do, all processing completed in Par.Prag, since we need
10658 -- the information for possible parser messages that are output.
10660 when Pragma_Source_Reference =>
10663 --------------------------------
10664 -- Static_Elaboration_Desired --
10665 --------------------------------
10667 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10669 when Pragma_Static_Elaboration_Desired =>
10671 Check_At_Most_N_Arguments (1);
10673 if Is_Compilation_Unit (Current_Scope)
10674 and then Ekind (Current_Scope) = E_Package
10676 Set_Static_Elaboration_Desired (Current_Scope, True);
10678 Error_Pragma ("pragma% must apply to a library-level package");
10685 -- pragma Storage_Size (EXPRESSION);
10687 when Pragma_Storage_Size => Storage_Size : declare
10688 P : constant Node_Id := Parent (N);
10692 Check_No_Identifiers;
10693 Check_Arg_Count (1);
10695 -- The expression must be analyzed in the special manner described
10696 -- in "Handling of Default Expressions" in sem.ads.
10698 Arg := Expression (Arg1);
10699 Preanalyze_Spec_Expression (Arg, Any_Integer);
10701 if not Is_Static_Expression (Arg) then
10702 Check_Restriction (Static_Storage_Size, Arg);
10705 if Nkind (P) /= N_Task_Definition then
10710 if Has_Storage_Size_Pragma (P) then
10711 Error_Pragma ("duplicate pragma% not allowed");
10713 Set_Has_Storage_Size_Pragma (P, True);
10716 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10717 -- ??? exp_ch9 should use this!
10725 -- pragma Storage_Unit (NUMERIC_LITERAL);
10727 -- Only permitted argument is System'Storage_Unit value
10729 when Pragma_Storage_Unit =>
10730 Check_No_Identifiers;
10731 Check_Arg_Count (1);
10732 Check_Arg_Is_Integer_Literal (Arg1);
10734 if Intval (Expression (Arg1)) /=
10735 UI_From_Int (Ttypes.System_Storage_Unit)
10737 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10739 ("the only allowed argument for pragma% is ^", Arg1);
10742 --------------------
10743 -- Stream_Convert --
10744 --------------------
10746 -- pragma Stream_Convert (
10747 -- [Entity =>] type_LOCAL_NAME,
10748 -- [Read =>] function_NAME,
10749 -- [Write =>] function NAME);
10751 when Pragma_Stream_Convert => Stream_Convert : declare
10753 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10754 -- Check that the given argument is the name of a local function
10755 -- of one argument that is not overloaded earlier in the current
10756 -- local scope. A check is also made that the argument is a
10757 -- function with one parameter.
10759 --------------------------------------
10760 -- Check_OK_Stream_Convert_Function --
10761 --------------------------------------
10763 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10767 Check_Arg_Is_Local_Name (Arg);
10768 Ent := Entity (Expression (Arg));
10770 if Has_Homonym (Ent) then
10772 ("argument for pragma% may not be overloaded", Arg);
10775 if Ekind (Ent) /= E_Function
10776 or else No (First_Formal (Ent))
10777 or else Present (Next_Formal (First_Formal (Ent)))
10780 ("argument for pragma% must be" &
10781 " function of one argument", Arg);
10783 end Check_OK_Stream_Convert_Function;
10785 -- Start of processing for Stream_Convert
10789 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10790 Check_Arg_Count (3);
10791 Check_Optional_Identifier (Arg1, Name_Entity);
10792 Check_Optional_Identifier (Arg2, Name_Read);
10793 Check_Optional_Identifier (Arg3, Name_Write);
10794 Check_Arg_Is_Local_Name (Arg1);
10795 Check_OK_Stream_Convert_Function (Arg2);
10796 Check_OK_Stream_Convert_Function (Arg3);
10799 Typ : constant Entity_Id :=
10800 Underlying_Type (Entity (Expression (Arg1)));
10801 Read : constant Entity_Id := Entity (Expression (Arg2));
10802 Write : constant Entity_Id := Entity (Expression (Arg3));
10805 Check_First_Subtype (Arg1);
10807 -- Check for too early or too late. Note that we don't enforce
10808 -- the rule about primitive operations in this case, since, as
10809 -- is the case for explicit stream attributes themselves, these
10810 -- restrictions are not appropriate. Note that the chaining of
10811 -- the pragma by Rep_Item_Too_Late is actually the critical
10812 -- processing done for this pragma.
10814 if Rep_Item_Too_Early (Typ, N)
10816 Rep_Item_Too_Late (Typ, N, FOnly => True)
10821 -- Return if previous error
10823 if Etype (Typ) = Any_Type
10825 Etype (Read) = Any_Type
10827 Etype (Write) = Any_Type
10834 if Underlying_Type (Etype (Read)) /= Typ then
10836 ("incorrect return type for function&", Arg2);
10839 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
10841 ("incorrect parameter type for function&", Arg3);
10844 if Underlying_Type (Etype (First_Formal (Read))) /=
10845 Underlying_Type (Etype (Write))
10848 ("result type of & does not match Read parameter type",
10852 end Stream_Convert;
10854 -------------------------
10855 -- Style_Checks (GNAT) --
10856 -------------------------
10858 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
10860 -- This is processed by the parser since some of the style checks
10861 -- take place during source scanning and parsing. This means that
10862 -- we don't need to issue error messages here.
10864 when Pragma_Style_Checks => Style_Checks : declare
10865 A : constant Node_Id := Expression (Arg1);
10871 Check_No_Identifiers;
10873 -- Two argument form
10875 if Arg_Count = 2 then
10876 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10883 E_Id := Expression (Arg2);
10886 if not Is_Entity_Name (E_Id) then
10888 ("second argument of pragma% must be entity name",
10892 E := Entity (E_Id);
10898 Set_Suppress_Style_Checks (E,
10899 (Chars (Expression (Arg1)) = Name_Off));
10900 exit when No (Homonym (E));
10906 -- One argument form
10909 Check_Arg_Count (1);
10911 if Nkind (A) = N_String_Literal then
10915 Slen : constant Natural := Natural (String_Length (S));
10916 Options : String (1 .. Slen);
10922 C := Get_String_Char (S, Int (J));
10923 exit when not In_Character_Range (C);
10924 Options (J) := Get_Character (C);
10926 -- If at end of string, set options. As per discussion
10927 -- above, no need to check for errors, since we issued
10928 -- them in the parser.
10931 Set_Style_Check_Options (Options);
10939 elsif Nkind (A) = N_Identifier then
10940 if Chars (A) = Name_All_Checks then
10941 Set_Default_Style_Check_Options;
10943 elsif Chars (A) = Name_On then
10944 Style_Check := True;
10946 elsif Chars (A) = Name_Off then
10947 Style_Check := False;
10957 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
10959 when Pragma_Subtitle =>
10961 Check_Arg_Count (1);
10962 Check_Optional_Identifier (Arg1, Name_Subtitle);
10963 Check_Arg_Is_String_Literal (Arg1);
10969 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
10971 when Pragma_Suppress =>
10972 Process_Suppress_Unsuppress (True);
10978 -- pragma Suppress_All;
10980 -- The only check made here is that the pragma appears in the proper
10981 -- place, i.e. following a compilation unit. If indeed it appears in
10982 -- this context, then the parser has already inserted an equivalent
10983 -- pragma Suppress (All_Checks) to get the required effect.
10985 when Pragma_Suppress_All =>
10987 Check_Arg_Count (0);
10989 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
10990 or else not Is_List_Member (N)
10991 or else List_Containing (N) /= Pragmas_After (Parent (N))
10994 ("misplaced pragma%, must follow compilation unit");
10997 -------------------------
10998 -- Suppress_Debug_Info --
10999 -------------------------
11001 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11003 when Pragma_Suppress_Debug_Info =>
11005 Check_Arg_Count (1);
11006 Check_Optional_Identifier (Arg1, Name_Entity);
11007 Check_Arg_Is_Local_Name (Arg1);
11008 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11010 ----------------------------------
11011 -- Suppress_Exception_Locations --
11012 ----------------------------------
11014 -- pragma Suppress_Exception_Locations;
11016 when Pragma_Suppress_Exception_Locations =>
11018 Check_Arg_Count (0);
11019 Check_Valid_Configuration_Pragma;
11020 Exception_Locations_Suppressed := True;
11022 -----------------------------
11023 -- Suppress_Initialization --
11024 -----------------------------
11026 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11028 when Pragma_Suppress_Initialization => Suppress_Init : declare
11034 Check_Arg_Count (1);
11035 Check_Optional_Identifier (Arg1, Name_Entity);
11036 Check_Arg_Is_Local_Name (Arg1);
11038 E_Id := Expression (Arg1);
11040 if Etype (E_Id) = Any_Type then
11044 E := Entity (E_Id);
11046 if Is_Type (E) then
11047 if Is_Incomplete_Or_Private_Type (E) then
11048 if No (Full_View (Base_Type (E))) then
11050 ("argument of pragma% cannot be an incomplete type",
11053 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11056 Set_Suppress_Init_Proc (Base_Type (E));
11061 ("pragma% requires argument that is a type name", Arg1);
11069 -- pragma System_Name (DIRECT_NAME);
11071 -- Syntax check: one argument, which must be the identifier GNAT or
11072 -- the identifier GCC, no other identifiers are acceptable.
11074 when Pragma_System_Name =>
11076 Check_No_Identifiers;
11077 Check_Arg_Count (1);
11078 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11080 -----------------------------
11081 -- Task_Dispatching_Policy --
11082 -----------------------------
11084 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11086 when Pragma_Task_Dispatching_Policy => declare
11090 Check_Ada_83_Warning;
11091 Check_Arg_Count (1);
11092 Check_No_Identifiers;
11093 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11094 Check_Valid_Configuration_Pragma;
11095 Get_Name_String (Chars (Expression (Arg1)));
11096 DP := Fold_Upper (Name_Buffer (1));
11098 if Task_Dispatching_Policy /= ' '
11099 and then Task_Dispatching_Policy /= DP
11101 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11103 ("task dispatching policy incompatible with policy#");
11105 -- Set new policy, but always preserve System_Location since we
11106 -- like the error message with the run time name.
11109 Task_Dispatching_Policy := DP;
11111 if Task_Dispatching_Policy_Sloc /= System_Location then
11112 Task_Dispatching_Policy_Sloc := Loc;
11121 -- pragma Task_Info (EXPRESSION);
11123 when Pragma_Task_Info => Task_Info : declare
11124 P : constant Node_Id := Parent (N);
11129 if Nkind (P) /= N_Task_Definition then
11130 Error_Pragma ("pragma% must appear in task definition");
11133 Check_No_Identifiers;
11134 Check_Arg_Count (1);
11136 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11138 if Etype (Expression (Arg1)) = Any_Type then
11142 if Has_Task_Info_Pragma (P) then
11143 Error_Pragma ("duplicate pragma% not allowed");
11145 Set_Has_Task_Info_Pragma (P, True);
11153 -- pragma Task_Name (string_EXPRESSION);
11155 when Pragma_Task_Name => Task_Name : declare
11156 P : constant Node_Id := Parent (N);
11160 Check_No_Identifiers;
11161 Check_Arg_Count (1);
11163 Arg := Expression (Arg1);
11165 -- The expression is used in the call to Create_Task, and must be
11166 -- expanded there, not in the context of the current spec.
11168 Preanalyze_And_Resolve (New_Copy_Tree (Arg), Standard_String);
11170 if Nkind (P) /= N_Task_Definition then
11174 if Has_Task_Name_Pragma (P) then
11175 Error_Pragma ("duplicate pragma% not allowed");
11177 Set_Has_Task_Name_Pragma (P, True);
11178 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11186 -- pragma Task_Storage (
11187 -- [Task_Type =>] LOCAL_NAME,
11188 -- [Top_Guard =>] static_integer_EXPRESSION);
11190 when Pragma_Task_Storage => Task_Storage : declare
11191 Args : Args_List (1 .. 2);
11192 Names : constant Name_List (1 .. 2) := (
11196 Task_Type : Node_Id renames Args (1);
11197 Top_Guard : Node_Id renames Args (2);
11203 Gather_Associations (Names, Args);
11205 if No (Task_Type) then
11207 ("missing task_type argument for pragma%");
11210 Check_Arg_Is_Local_Name (Task_Type);
11212 Ent := Entity (Task_Type);
11214 if not Is_Task_Type (Ent) then
11216 ("argument for pragma% must be task type", Task_Type);
11219 if No (Top_Guard) then
11221 ("pragma% takes two arguments", Task_Type);
11223 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11226 Check_First_Subtype (Task_Type);
11228 if Rep_Item_Too_Late (Ent, N) then
11233 --------------------------
11234 -- Thread_Local_Storage --
11235 --------------------------
11237 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11239 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11245 Check_Arg_Count (1);
11246 Check_Optional_Identifier (Arg1, Name_Entity);
11247 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11249 Id := Expression (Arg1);
11252 if not Is_Entity_Name (Id)
11253 or else Ekind (Entity (Id)) /= E_Variable
11255 Error_Pragma_Arg ("local variable name required", Arg1);
11260 if Rep_Item_Too_Early (E, N)
11261 or else Rep_Item_Too_Late (E, N)
11266 Set_Has_Pragma_Thread_Local_Storage (E);
11267 Set_Has_Gigi_Rep_Item (E);
11268 end Thread_Local_Storage;
11274 -- pragma Time_Slice (static_duration_EXPRESSION);
11276 when Pragma_Time_Slice => Time_Slice : declare
11282 Check_Arg_Count (1);
11283 Check_No_Identifiers;
11284 Check_In_Main_Program;
11285 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11287 if not Error_Posted (Arg1) then
11289 while Present (Nod) loop
11290 if Nkind (Nod) = N_Pragma
11291 and then Pragma_Name (Nod) = Name_Time_Slice
11293 Error_Msg_Name_1 := Pname;
11294 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11301 -- Process only if in main unit
11303 if Get_Source_Unit (Loc) = Main_Unit then
11304 Opt.Time_Slice_Set := True;
11305 Val := Expr_Value_R (Expression (Arg1));
11307 if Val <= Ureal_0 then
11308 Opt.Time_Slice_Value := 0;
11310 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11311 Opt.Time_Slice_Value := 1_000_000_000;
11314 Opt.Time_Slice_Value :=
11315 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11324 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11326 -- TITLING_OPTION ::=
11327 -- [Title =>] STRING_LITERAL
11328 -- | [Subtitle =>] STRING_LITERAL
11330 when Pragma_Title => Title : declare
11331 Args : Args_List (1 .. 2);
11332 Names : constant Name_List (1 .. 2) := (
11338 Gather_Associations (Names, Args);
11340 for J in 1 .. 2 loop
11341 if Present (Args (J)) then
11342 Check_Arg_Is_String_Literal (Args (J));
11347 ---------------------
11348 -- Unchecked_Union --
11349 ---------------------
11351 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11353 when Pragma_Unchecked_Union => Unchecked_Union : declare
11354 Assoc : constant Node_Id := Arg1;
11355 Type_Id : constant Node_Id := Expression (Assoc);
11366 Check_No_Identifiers;
11367 Check_Arg_Count (1);
11368 Check_Arg_Is_Local_Name (Arg1);
11370 Find_Type (Type_Id);
11371 Typ := Entity (Type_Id);
11374 or else Rep_Item_Too_Early (Typ, N)
11378 Typ := Underlying_Type (Typ);
11381 if Rep_Item_Too_Late (Typ, N) then
11385 Check_First_Subtype (Arg1);
11387 -- Note remaining cases are references to a type in the current
11388 -- declarative part. If we find an error, we post the error on
11389 -- the relevant type declaration at an appropriate point.
11391 if not Is_Record_Type (Typ) then
11392 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11395 elsif Is_Tagged_Type (Typ) then
11396 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11399 elsif Is_Limited_Type (Typ) then
11401 ("Unchecked_Union must not be limited record type", Typ);
11402 Explain_Limited_Type (Typ, Typ);
11406 if not Has_Discriminants (Typ) then
11408 ("Unchecked_Union must have one discriminant", Typ);
11412 Discr := First_Discriminant (Typ);
11413 while Present (Discr) loop
11414 if No (Discriminant_Default_Value (Discr)) then
11416 ("Unchecked_Union discriminant must have default value",
11419 Next_Discriminant (Discr);
11422 Tdef := Type_Definition (Declaration_Node (Typ));
11423 Clist := Component_List (Tdef);
11425 Comp := First (Component_Items (Clist));
11426 while Present (Comp) loop
11427 Check_Component (Comp);
11431 if No (Clist) or else No (Variant_Part (Clist)) then
11433 ("Unchecked_Union must have variant part",
11438 Vpart := Variant_Part (Clist);
11440 Variant := First (Variants (Vpart));
11441 while Present (Variant) loop
11442 Check_Variant (Variant);
11447 Set_Is_Unchecked_Union (Typ, True);
11448 Set_Convention (Typ, Convention_C);
11450 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11451 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11452 end Unchecked_Union;
11454 ------------------------
11455 -- Unimplemented_Unit --
11456 ------------------------
11458 -- pragma Unimplemented_Unit;
11460 -- Note: this only gives an error if we are generating code, or if
11461 -- we are in a generic library unit (where the pragma appears in the
11462 -- body, not in the spec).
11464 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11465 Cunitent : constant Entity_Id :=
11466 Cunit_Entity (Get_Source_Unit (Loc));
11467 Ent_Kind : constant Entity_Kind :=
11472 Check_Arg_Count (0);
11474 if Operating_Mode = Generate_Code
11475 or else Ent_Kind = E_Generic_Function
11476 or else Ent_Kind = E_Generic_Procedure
11477 or else Ent_Kind = E_Generic_Package
11479 Get_Name_String (Chars (Cunitent));
11480 Set_Casing (Mixed_Case);
11481 Write_Str (Name_Buffer (1 .. Name_Len));
11482 Write_Str (" is not supported in this configuration");
11484 raise Unrecoverable_Error;
11486 end Unimplemented_Unit;
11488 ------------------------
11489 -- Universal_Aliasing --
11490 ------------------------
11492 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11494 when Pragma_Universal_Aliasing => Universal_Alias : declare
11499 Check_Arg_Count (1);
11500 Check_Optional_Identifier (Arg2, Name_Entity);
11501 Check_Arg_Is_Local_Name (Arg1);
11502 E_Id := Entity (Expression (Arg1));
11504 if E_Id = Any_Type then
11506 elsif No (E_Id) or else not Is_Type (E_Id) then
11507 Error_Pragma_Arg ("pragma% requires type", Arg1);
11510 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11511 end Universal_Alias;
11513 --------------------
11514 -- Universal_Data --
11515 --------------------
11517 -- pragma Universal_Data [(library_unit_NAME)];
11519 when Pragma_Universal_Data =>
11522 -- If this is a configuration pragma, then set the universal
11523 -- addressing option, otherwise confirm that the pragma satisfies
11524 -- the requirements of library unit pragma placement and leave it
11525 -- to the GNAAMP back end to detect the pragma (avoids transitive
11526 -- setting of the option due to withed units).
11528 if Is_Configuration_Pragma then
11529 Universal_Addressing_On_AAMP := True;
11531 Check_Valid_Library_Unit_Pragma;
11534 if not AAMP_On_Target then
11535 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11542 -- pragma Unmodified (local_Name {, local_Name});
11544 when Pragma_Unmodified => Unmodified : declare
11545 Arg_Node : Node_Id;
11546 Arg_Expr : Node_Id;
11547 Arg_Ent : Entity_Id;
11551 Check_At_Least_N_Arguments (1);
11553 -- Loop through arguments
11556 while Present (Arg_Node) loop
11557 Check_No_Identifier (Arg_Node);
11559 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11560 -- in fact generate reference, so that the entity will have a
11561 -- reference, which will inhibit any warnings about it not
11562 -- being referenced, and also properly show up in the ali file
11563 -- as a reference. But this reference is recorded before the
11564 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11565 -- generated for this reference.
11567 Check_Arg_Is_Local_Name (Arg_Node);
11568 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11570 if Is_Entity_Name (Arg_Expr) then
11571 Arg_Ent := Entity (Arg_Expr);
11573 if not Is_Assignable (Arg_Ent) then
11575 ("pragma% can only be applied to a variable",
11578 Set_Has_Pragma_Unmodified (Arg_Ent);
11590 -- pragma Unreferenced (local_Name {, local_Name});
11592 -- or when used in a context clause:
11594 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11596 when Pragma_Unreferenced => Unreferenced : declare
11597 Arg_Node : Node_Id;
11598 Arg_Expr : Node_Id;
11599 Arg_Ent : Entity_Id;
11604 Check_At_Least_N_Arguments (1);
11606 -- Check case of appearing within context clause
11608 if Is_In_Context_Clause then
11610 -- The arguments must all be units mentioned in a with clause
11611 -- in the same context clause. Note we already checked (in
11612 -- Par.Prag) that the arguments are either identifiers or
11613 -- selected components.
11616 while Present (Arg_Node) loop
11617 Citem := First (List_Containing (N));
11618 while Citem /= N loop
11619 if Nkind (Citem) = N_With_Clause
11620 and then Same_Name (Name (Citem), Expression (Arg_Node))
11622 Set_Has_Pragma_Unreferenced
11625 (Library_Unit (Citem))));
11626 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11635 ("argument of pragma% is not with'ed unit", Arg_Node);
11641 -- Case of not in list of context items
11645 while Present (Arg_Node) loop
11646 Check_No_Identifier (Arg_Node);
11648 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11649 -- will in fact generate reference, so that the entity will
11650 -- have a reference, which will inhibit any warnings about
11651 -- it not being referenced, and also properly show up in the
11652 -- ali file as a reference. But this reference is recorded
11653 -- before the Has_Pragma_Unreferenced flag is set, so that
11654 -- no warning is generated for this reference.
11656 Check_Arg_Is_Local_Name (Arg_Node);
11657 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11659 if Is_Entity_Name (Arg_Expr) then
11660 Arg_Ent := Entity (Arg_Expr);
11662 -- If the entity is overloaded, the pragma applies to the
11663 -- most recent overloading, as documented. In this case,
11664 -- name resolution does not generate a reference, so it
11665 -- must be done here explicitly.
11667 if Is_Overloaded (Arg_Expr) then
11668 Generate_Reference (Arg_Ent, N);
11671 Set_Has_Pragma_Unreferenced (Arg_Ent);
11679 --------------------------
11680 -- Unreferenced_Objects --
11681 --------------------------
11683 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11685 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11686 Arg_Node : Node_Id;
11687 Arg_Expr : Node_Id;
11691 Check_At_Least_N_Arguments (1);
11694 while Present (Arg_Node) loop
11695 Check_No_Identifier (Arg_Node);
11696 Check_Arg_Is_Local_Name (Arg_Node);
11697 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11699 if not Is_Entity_Name (Arg_Expr)
11700 or else not Is_Type (Entity (Arg_Expr))
11703 ("argument for pragma% must be type or subtype", Arg_Node);
11706 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11709 end Unreferenced_Objects;
11711 ------------------------------
11712 -- Unreserve_All_Interrupts --
11713 ------------------------------
11715 -- pragma Unreserve_All_Interrupts;
11717 when Pragma_Unreserve_All_Interrupts =>
11719 Check_Arg_Count (0);
11721 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11722 Unreserve_All_Interrupts := True;
11729 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11731 when Pragma_Unsuppress =>
11733 Process_Suppress_Unsuppress (False);
11735 -------------------
11736 -- Use_VADS_Size --
11737 -------------------
11739 -- pragma Use_VADS_Size;
11741 when Pragma_Use_VADS_Size =>
11743 Check_Arg_Count (0);
11744 Check_Valid_Configuration_Pragma;
11745 Use_VADS_Size := True;
11747 ---------------------
11748 -- Validity_Checks --
11749 ---------------------
11751 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11753 when Pragma_Validity_Checks => Validity_Checks : declare
11754 A : constant Node_Id := Expression (Arg1);
11760 Check_Arg_Count (1);
11761 Check_No_Identifiers;
11763 if Nkind (A) = N_String_Literal then
11767 Slen : constant Natural := Natural (String_Length (S));
11768 Options : String (1 .. Slen);
11774 C := Get_String_Char (S, Int (J));
11775 exit when not In_Character_Range (C);
11776 Options (J) := Get_Character (C);
11779 Set_Validity_Check_Options (Options);
11787 elsif Nkind (A) = N_Identifier then
11789 if Chars (A) = Name_All_Checks then
11790 Set_Validity_Check_Options ("a");
11792 elsif Chars (A) = Name_On then
11793 Validity_Checks_On := True;
11795 elsif Chars (A) = Name_Off then
11796 Validity_Checks_On := False;
11800 end Validity_Checks;
11806 -- pragma Volatile (LOCAL_NAME);
11808 when Pragma_Volatile =>
11809 Process_Atomic_Shared_Volatile;
11811 -------------------------
11812 -- Volatile_Components --
11813 -------------------------
11815 -- pragma Volatile_Components (array_LOCAL_NAME);
11817 -- Volatile is handled by the same circuit as Atomic_Components
11823 -- pragma Warnings (On | Off);
11824 -- pragma Warnings (On | Off, LOCAL_NAME);
11825 -- pragma Warnings (static_string_EXPRESSION);
11826 -- pragma Warnings (On | Off, STRING_LITERAL);
11828 when Pragma_Warnings => Warnings : begin
11830 Check_At_Least_N_Arguments (1);
11831 Check_No_Identifiers;
11834 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11837 -- One argument case
11839 if Arg_Count = 1 then
11841 -- On/Off one argument case was processed by parser
11843 if Nkind (Argx) = N_Identifier
11845 (Chars (Argx) = Name_On
11847 Chars (Argx) = Name_Off)
11851 -- One argument case must be ON/OFF or static string expr
11853 elsif not Is_Static_String_Expression (Arg1) then
11855 ("argument of pragma% must be On/Off or " &
11856 "static string expression", Arg2);
11858 -- One argument string expression case
11862 Lit : constant Node_Id := Expr_Value_S (Argx);
11863 Str : constant String_Id := Strval (Lit);
11864 Len : constant Nat := String_Length (Str);
11872 while J <= Len loop
11873 C := Get_String_Char (Str, J);
11874 OK := In_Character_Range (C);
11877 Chr := Get_Character (C);
11881 if J < Len and then Chr = '.' then
11883 C := Get_String_Char (Str, J);
11884 Chr := Get_Character (C);
11886 if not Set_Dot_Warning_Switch (Chr) then
11888 ("invalid warning switch character " &
11895 OK := Set_Warning_Switch (Chr);
11901 ("invalid warning switch character " & Chr,
11910 -- Two or more arguments (must be two)
11913 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11914 Check_At_Most_N_Arguments (2);
11922 E_Id := Expression (Arg2);
11925 -- In the expansion of an inlined body, a reference to
11926 -- the formal may be wrapped in a conversion if the
11927 -- actual is a conversion. Retrieve the real entity name.
11929 if (In_Instance_Body
11930 or else In_Inlined_Body)
11931 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
11933 E_Id := Expression (E_Id);
11936 -- Entity name case
11938 if Is_Entity_Name (E_Id) then
11939 E := Entity (E_Id);
11946 (E, (Chars (Expression (Arg1)) = Name_Off));
11948 if Chars (Expression (Arg1)) = Name_Off
11949 and then Warn_On_Warnings_Off
11951 Warnings_Off_Pragmas.Append ((N, E));
11954 if Is_Enumeration_Type (E) then
11958 Lit := First_Literal (E);
11959 while Present (Lit) loop
11960 Set_Warnings_Off (Lit);
11961 Next_Literal (Lit);
11966 exit when No (Homonym (E));
11971 -- Error if not entity or static string literal case
11973 elsif not Is_Static_String_Expression (Arg2) then
11975 ("second argument of pragma% must be entity " &
11976 "name or static string expression", Arg2);
11978 -- String literal case
11981 String_To_Name_Buffer
11982 (Strval (Expr_Value_S (Expression (Arg2))));
11984 -- Note on configuration pragma case: If this is a
11985 -- configuration pragma, then for an OFF pragma, we
11986 -- just set Config True in the call, which is all
11987 -- that needs to be done. For the case of ON, this
11988 -- is normally an error, unless it is canceling the
11989 -- effect of a previous OFF pragma in the same file.
11990 -- In any other case, an error will be signalled (ON
11991 -- with no matching OFF).
11993 if Chars (Argx) = Name_Off then
11994 Set_Specific_Warning_Off
11995 (Loc, Name_Buffer (1 .. Name_Len),
11996 Config => Is_Configuration_Pragma);
11998 elsif Chars (Argx) = Name_On then
11999 Set_Specific_Warning_On
12000 (Loc, Name_Buffer (1 .. Name_Len), Err);
12004 ("?pragma Warnings On with no " &
12005 "matching Warnings Off",
12015 -------------------
12016 -- Weak_External --
12017 -------------------
12019 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12021 when Pragma_Weak_External => Weak_External : declare
12026 Check_Arg_Count (1);
12027 Check_Optional_Identifier (Arg1, Name_Entity);
12028 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12029 Ent := Entity (Expression (Arg1));
12031 if Rep_Item_Too_Early (Ent, N) then
12034 Ent := Underlying_Type (Ent);
12037 -- The only processing required is to link this item on to the
12038 -- list of rep items for the given entity. This is accomplished
12039 -- by the call to Rep_Item_Too_Late (when no error is detected
12040 -- and False is returned).
12042 if Rep_Item_Too_Late (Ent, N) then
12045 Set_Has_Gigi_Rep_Item (Ent);
12049 -----------------------------
12050 -- Wide_Character_Encoding --
12051 -----------------------------
12053 -- pragma Wide_Character_Encoding (IDENTIFIER);
12055 when Pragma_Wide_Character_Encoding =>
12058 -- Nothing to do, handled in parser. Note that we do not enforce
12059 -- configuration pragma placement, this pragma can appear at any
12060 -- place in the source, allowing mixed encodings within a single
12065 --------------------
12066 -- Unknown_Pragma --
12067 --------------------
12069 -- Should be impossible, since the case of an unknown pragma is
12070 -- separately processed before the case statement is entered.
12072 when Unknown_Pragma =>
12073 raise Program_Error;
12077 when Pragma_Exit => null;
12078 end Analyze_Pragma;
12080 -------------------
12081 -- Check_Enabled --
12082 -------------------
12084 function Check_Enabled (Nam : Name_Id) return Boolean is
12088 PP := Opt.Check_Policy_List;
12091 return Assertions_Enabled;
12094 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12097 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12099 when Name_On | Name_Check =>
12101 when Name_Off | Name_Ignore =>
12104 raise Program_Error;
12108 PP := Next_Pragma (PP);
12113 ---------------------------------
12114 -- Delay_Config_Pragma_Analyze --
12115 ---------------------------------
12117 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12119 return Pragma_Name (N) = Name_Interrupt_State
12121 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12122 end Delay_Config_Pragma_Analyze;
12124 -------------------------
12125 -- Get_Base_Subprogram --
12126 -------------------------
12128 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12129 Result : Entity_Id;
12132 -- Follow subprogram renaming chain
12135 while Is_Subprogram (Result)
12137 (Is_Generic_Instance (Result)
12138 or else Nkind (Parent (Declaration_Node (Result))) =
12139 N_Subprogram_Renaming_Declaration)
12140 and then Present (Alias (Result))
12142 Result := Alias (Result);
12146 end Get_Base_Subprogram;
12148 --------------------
12149 -- Get_Pragma_Arg --
12150 --------------------
12152 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12154 if Nkind (Arg) = N_Pragma_Argument_Association then
12155 return Expression (Arg);
12159 end Get_Pragma_Arg;
12165 procedure Initialize is
12170 -----------------------------
12171 -- Is_Config_Static_String --
12172 -----------------------------
12174 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12176 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12177 -- This is an internal recursive function that is just like the outer
12178 -- function except that it adds the string to the name buffer rather
12179 -- than placing the string in the name buffer.
12181 ------------------------------
12182 -- Add_Config_Static_String --
12183 ------------------------------
12185 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12192 if Nkind (N) = N_Op_Concat then
12193 if Add_Config_Static_String (Left_Opnd (N)) then
12194 N := Right_Opnd (N);
12200 if Nkind (N) /= N_String_Literal then
12201 Error_Msg_N ("string literal expected for pragma argument", N);
12205 for J in 1 .. String_Length (Strval (N)) loop
12206 C := Get_String_Char (Strval (N), J);
12208 if not In_Character_Range (C) then
12210 ("string literal contains invalid wide character",
12211 Sloc (N) + 1 + Source_Ptr (J));
12215 Add_Char_To_Name_Buffer (Get_Character (C));
12220 end Add_Config_Static_String;
12222 -- Start of processing for Is_Config_Static_String
12227 return Add_Config_Static_String (Arg);
12228 end Is_Config_Static_String;
12230 -----------------------------------------
12231 -- Is_Non_Significant_Pragma_Reference --
12232 -----------------------------------------
12234 -- This function makes use of the following static table which indicates
12235 -- whether a given pragma is significant. A value of -1 in this table
12236 -- indicates that the reference is significant. A value of zero indicates
12237 -- than appearance as any argument is insignificant, a positive value
12238 -- indicates that appearance in that parameter position is significant.
12240 -- A value of 99 flags a special case requiring a special check (this is
12241 -- used for cases not covered by this standard encoding, e.g. pragma Check
12242 -- where the first argument is not significant, but the others are).
12244 Sig_Flags : constant array (Pragma_Id) of Int :=
12245 (Pragma_AST_Entry => -1,
12246 Pragma_Abort_Defer => -1,
12247 Pragma_Ada_83 => -1,
12248 Pragma_Ada_95 => -1,
12249 Pragma_Ada_05 => -1,
12250 Pragma_Ada_2005 => -1,
12251 Pragma_All_Calls_Remote => -1,
12252 Pragma_Annotate => -1,
12253 Pragma_Assert => -1,
12254 Pragma_Assertion_Policy => 0,
12255 Pragma_Assume_No_Invalid_Values => 0,
12256 Pragma_Asynchronous => -1,
12257 Pragma_Atomic => 0,
12258 Pragma_Atomic_Components => 0,
12259 Pragma_Attach_Handler => -1,
12260 Pragma_Check => 99,
12261 Pragma_Check_Name => 0,
12262 Pragma_Check_Policy => 0,
12263 Pragma_CIL_Constructor => -1,
12264 Pragma_CPP_Class => 0,
12265 Pragma_CPP_Constructor => 0,
12266 Pragma_CPP_Virtual => 0,
12267 Pragma_CPP_Vtable => 0,
12268 Pragma_C_Pass_By_Copy => 0,
12269 Pragma_Comment => 0,
12270 Pragma_Common_Object => -1,
12271 Pragma_Compile_Time_Error => -1,
12272 Pragma_Compile_Time_Warning => -1,
12273 Pragma_Compiler_Unit => 0,
12274 Pragma_Complete_Representation => 0,
12275 Pragma_Complex_Representation => 0,
12276 Pragma_Component_Alignment => -1,
12277 Pragma_Controlled => 0,
12278 Pragma_Convention => 0,
12279 Pragma_Convention_Identifier => 0,
12280 Pragma_Debug => -1,
12281 Pragma_Debug_Policy => 0,
12282 Pragma_Detect_Blocking => -1,
12283 Pragma_Discard_Names => 0,
12284 Pragma_Elaborate => -1,
12285 Pragma_Elaborate_All => -1,
12286 Pragma_Elaborate_Body => -1,
12287 Pragma_Elaboration_Checks => -1,
12288 Pragma_Eliminate => -1,
12289 Pragma_Export => -1,
12290 Pragma_Export_Exception => -1,
12291 Pragma_Export_Function => -1,
12292 Pragma_Export_Object => -1,
12293 Pragma_Export_Procedure => -1,
12294 Pragma_Export_Value => -1,
12295 Pragma_Export_Valued_Procedure => -1,
12296 Pragma_Extend_System => -1,
12297 Pragma_Extensions_Allowed => -1,
12298 Pragma_External => -1,
12299 Pragma_Favor_Top_Level => -1,
12300 Pragma_External_Name_Casing => -1,
12301 Pragma_Fast_Math => -1,
12302 Pragma_Finalize_Storage_Only => 0,
12303 Pragma_Float_Representation => 0,
12304 Pragma_Ident => -1,
12305 Pragma_Implemented_By_Entry => -1,
12306 Pragma_Implicit_Packing => 0,
12307 Pragma_Import => +2,
12308 Pragma_Import_Exception => 0,
12309 Pragma_Import_Function => 0,
12310 Pragma_Import_Object => 0,
12311 Pragma_Import_Procedure => 0,
12312 Pragma_Import_Valued_Procedure => 0,
12313 Pragma_Initialize_Scalars => -1,
12314 Pragma_Inline => 0,
12315 Pragma_Inline_Always => 0,
12316 Pragma_Inline_Generic => 0,
12317 Pragma_Inspection_Point => -1,
12318 Pragma_Interface => +2,
12319 Pragma_Interface_Name => +2,
12320 Pragma_Interrupt_Handler => -1,
12321 Pragma_Interrupt_Priority => -1,
12322 Pragma_Interrupt_State => -1,
12323 Pragma_Java_Constructor => -1,
12324 Pragma_Java_Interface => -1,
12325 Pragma_Keep_Names => 0,
12326 Pragma_License => -1,
12327 Pragma_Link_With => -1,
12328 Pragma_Linker_Alias => -1,
12329 Pragma_Linker_Constructor => -1,
12330 Pragma_Linker_Destructor => -1,
12331 Pragma_Linker_Options => -1,
12332 Pragma_Linker_Section => -1,
12334 Pragma_Locking_Policy => -1,
12335 Pragma_Long_Float => -1,
12336 Pragma_Machine_Attribute => -1,
12338 Pragma_Main_Storage => -1,
12339 Pragma_Memory_Size => -1,
12340 Pragma_No_Return => 0,
12341 Pragma_No_Body => 0,
12342 Pragma_No_Run_Time => -1,
12343 Pragma_No_Strict_Aliasing => -1,
12344 Pragma_Normalize_Scalars => -1,
12345 Pragma_Obsolescent => 0,
12346 Pragma_Optimize => -1,
12347 Pragma_Optimize_Alignment => -1,
12350 Pragma_Passive => -1,
12351 Pragma_Preelaborable_Initialization => -1,
12352 Pragma_Polling => -1,
12353 Pragma_Persistent_BSS => 0,
12354 Pragma_Postcondition => -1,
12355 Pragma_Precondition => -1,
12356 Pragma_Preelaborate => -1,
12357 Pragma_Preelaborate_05 => -1,
12358 Pragma_Priority => -1,
12359 Pragma_Priority_Specific_Dispatching => -1,
12360 Pragma_Profile => 0,
12361 Pragma_Profile_Warnings => 0,
12362 Pragma_Propagate_Exceptions => -1,
12363 Pragma_Psect_Object => -1,
12365 Pragma_Pure_05 => -1,
12366 Pragma_Pure_Function => -1,
12367 Pragma_Queuing_Policy => -1,
12368 Pragma_Ravenscar => -1,
12369 Pragma_Relative_Deadline => -1,
12370 Pragma_Remote_Call_Interface => -1,
12371 Pragma_Remote_Types => -1,
12372 Pragma_Restricted_Run_Time => -1,
12373 Pragma_Restriction_Warnings => -1,
12374 Pragma_Restrictions => -1,
12375 Pragma_Reviewable => -1,
12376 Pragma_Share_Generic => -1,
12377 Pragma_Shared => -1,
12378 Pragma_Shared_Passive => -1,
12379 Pragma_Source_File_Name => -1,
12380 Pragma_Source_File_Name_Project => -1,
12381 Pragma_Source_Reference => -1,
12382 Pragma_Storage_Size => -1,
12383 Pragma_Storage_Unit => -1,
12384 Pragma_Static_Elaboration_Desired => -1,
12385 Pragma_Stream_Convert => -1,
12386 Pragma_Style_Checks => -1,
12387 Pragma_Subtitle => -1,
12388 Pragma_Suppress => 0,
12389 Pragma_Suppress_Exception_Locations => 0,
12390 Pragma_Suppress_All => -1,
12391 Pragma_Suppress_Debug_Info => 0,
12392 Pragma_Suppress_Initialization => 0,
12393 Pragma_System_Name => -1,
12394 Pragma_Task_Dispatching_Policy => -1,
12395 Pragma_Task_Info => -1,
12396 Pragma_Task_Name => -1,
12397 Pragma_Task_Storage => 0,
12398 Pragma_Thread_Local_Storage => 0,
12399 Pragma_Time_Slice => -1,
12400 Pragma_Title => -1,
12401 Pragma_Unchecked_Union => 0,
12402 Pragma_Unimplemented_Unit => -1,
12403 Pragma_Universal_Aliasing => -1,
12404 Pragma_Universal_Data => -1,
12405 Pragma_Unmodified => -1,
12406 Pragma_Unreferenced => -1,
12407 Pragma_Unreferenced_Objects => -1,
12408 Pragma_Unreserve_All_Interrupts => -1,
12409 Pragma_Unsuppress => 0,
12410 Pragma_Use_VADS_Size => -1,
12411 Pragma_Validity_Checks => -1,
12412 Pragma_Volatile => 0,
12413 Pragma_Volatile_Components => 0,
12414 Pragma_Warnings => -1,
12415 Pragma_Weak_External => -1,
12416 Pragma_Wide_Character_Encoding => 0,
12417 Unknown_Pragma => 0);
12419 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12428 if Nkind (P) /= N_Pragma_Argument_Association then
12432 Id := Get_Pragma_Id (Parent (P));
12433 C := Sig_Flags (Id);
12445 -- For pragma Check, the first argument is not significant,
12446 -- the second and the third (if present) arguments are
12449 when Pragma_Check =>
12451 P = First (Pragma_Argument_Associations (Parent (P)));
12454 raise Program_Error;
12458 A := First (Pragma_Argument_Associations (Parent (P)));
12459 for J in 1 .. C - 1 loop
12467 return A = P; -- is this wrong way round ???
12470 end Is_Non_Significant_Pragma_Reference;
12472 ------------------------------
12473 -- Is_Pragma_String_Literal --
12474 ------------------------------
12476 -- This function returns true if the corresponding pragma argument is a
12477 -- static string expression. These are the only cases in which string
12478 -- literals can appear as pragma arguments. We also allow a string literal
12479 -- as the first argument to pragma Assert (although it will of course
12480 -- always generate a type error).
12482 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12483 Pragn : constant Node_Id := Parent (Par);
12484 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12485 Pname : constant Name_Id := Pragma_Name (Pragn);
12491 N := First (Assoc);
12498 if Pname = Name_Assert then
12501 elsif Pname = Name_Export then
12504 elsif Pname = Name_Ident then
12507 elsif Pname = Name_Import then
12510 elsif Pname = Name_Interface_Name then
12513 elsif Pname = Name_Linker_Alias then
12516 elsif Pname = Name_Linker_Section then
12519 elsif Pname = Name_Machine_Attribute then
12522 elsif Pname = Name_Source_File_Name then
12525 elsif Pname = Name_Source_Reference then
12528 elsif Pname = Name_Title then
12531 elsif Pname = Name_Subtitle then
12537 end Is_Pragma_String_Literal;
12539 --------------------------------------
12540 -- Process_Compilation_Unit_Pragmas --
12541 --------------------------------------
12543 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12545 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12546 -- strange because it comes at the end of the unit. If we have a pragma
12547 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12548 -- a pragma Suppress (All_Checks) at the start of the context clause to
12549 -- ensure the correct processing.
12552 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12556 if Present (PA) then
12558 while Present (P) loop
12559 if Pragma_Name (P) = Name_Suppress_All then
12560 Prepend_To (Context_Items (N),
12561 Make_Pragma (Sloc (P),
12562 Chars => Name_Suppress,
12563 Pragma_Argument_Associations => New_List (
12564 Make_Pragma_Argument_Association (Sloc (P),
12566 Make_Identifier (Sloc (P),
12567 Chars => Name_All_Checks)))));
12575 end Process_Compilation_Unit_Pragmas;
12586 --------------------------------
12587 -- Set_Encoded_Interface_Name --
12588 --------------------------------
12590 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12591 Str : constant String_Id := Strval (S);
12592 Len : constant Int := String_Length (Str);
12597 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12600 -- Stores encoded value of character code CC. The encoding we use an
12601 -- underscore followed by four lower case hex digits.
12607 procedure Encode is
12609 Store_String_Char (Get_Char_Code ('_'));
12611 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12613 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12615 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12617 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12620 -- Start of processing for Set_Encoded_Interface_Name
12623 -- If first character is asterisk, this is a link name, and we leave it
12624 -- completely unmodified. We also ignore null strings (the latter case
12625 -- happens only in error cases) and no encoding should occur for Java or
12626 -- AAMP interface names.
12629 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12630 or else VM_Target /= No_VM
12631 or else AAMP_On_Target
12633 Set_Interface_Name (E, S);
12638 CC := Get_String_Char (Str, J);
12640 exit when not In_Character_Range (CC);
12642 C := Get_Character (CC);
12644 exit when C /= '_' and then C /= '$'
12645 and then C not in '0' .. '9'
12646 and then C not in 'a' .. 'z'
12647 and then C not in 'A' .. 'Z';
12650 Set_Interface_Name (E, S);
12658 -- Here we need to encode. The encoding we use as follows:
12659 -- three underscores + four hex digits (lower case)
12663 for J in 1 .. String_Length (Str) loop
12664 CC := Get_String_Char (Str, J);
12666 if not In_Character_Range (CC) then
12669 C := Get_Character (CC);
12671 if C = '_' or else C = '$'
12672 or else C in '0' .. '9'
12673 or else C in 'a' .. 'z'
12674 or else C in 'A' .. 'Z'
12676 Store_String_Char (CC);
12683 Set_Interface_Name (E,
12684 Make_String_Literal (Sloc (S),
12685 Strval => End_String));
12687 end Set_Encoded_Interface_Name;
12689 -------------------
12690 -- Set_Unit_Name --
12691 -------------------
12693 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12698 if Nkind (N) = N_Identifier
12699 and then Nkind (With_Item) = N_Identifier
12701 Set_Entity (N, Entity (With_Item));
12703 elsif Nkind (N) = N_Selected_Component then
12704 Change_Selected_Component_To_Expanded_Name (N);
12705 Set_Entity (N, Entity (With_Item));
12706 Set_Entity (Selector_Name (N), Entity (N));
12708 Pref := Prefix (N);
12709 Scop := Scope (Entity (N));
12710 while Nkind (Pref) = N_Selected_Component loop
12711 Change_Selected_Component_To_Expanded_Name (Pref);
12712 Set_Entity (Selector_Name (Pref), Scop);
12713 Set_Entity (Pref, Scop);
12714 Pref := Prefix (Pref);
12715 Scop := Scope (Scop);
12718 Set_Entity (Pref, Scop);