1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elim; use Sem_Elim;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Intr; use Sem_Intr;
65 with Sem_Mech; use Sem_Mech;
66 with Sem_Res; use Sem_Res;
67 with Sem_Type; use Sem_Type;
68 with Sem_Util; use Sem_Util;
69 with Sem_VFpt; use Sem_VFpt;
70 with Sem_Warn; use Sem_Warn;
71 with Stand; use Stand;
72 with Sinfo; use Sinfo;
73 with Sinfo.CN; use Sinfo.CN;
74 with Sinput; use Sinput;
75 with Snames; use Snames;
76 with Stringt; use Stringt;
77 with Stylesw; use Stylesw;
79 with Targparm; use Targparm;
80 with Tbuild; use Tbuild;
82 with Uintp; use Uintp;
83 with Uname; use Uname;
84 with Urealp; use Urealp;
85 with Validsw; use Validsw;
87 package body Sem_Prag is
89 ----------------------------------------------
90 -- Common Handling of Import-Export Pragmas --
91 ----------------------------------------------
93 -- In the following section, a number of Import_xxx and Export_xxx
94 -- pragmas are defined by GNAT. These are compatible with the DEC
95 -- pragmas of the same name, and all have the following common
96 -- form and processing:
99 -- [Internal =>] LOCAL_NAME
100 -- [, [External =>] EXTERNAL_SYMBOL]
101 -- [, other optional parameters ]);
104 -- [Internal =>] LOCAL_NAME
105 -- [, [External =>] EXTERNAL_SYMBOL]
106 -- [, other optional parameters ]);
108 -- EXTERNAL_SYMBOL ::=
110 -- | static_string_EXPRESSION
112 -- The internal LOCAL_NAME designates the entity that is imported or
113 -- exported, and must refer to an entity in the current declarative
114 -- part (as required by the rules for LOCAL_NAME).
116 -- The external linker name is designated by the External parameter if
117 -- given, or the Internal parameter if not (if there is no External
118 -- parameter, the External parameter is a copy of the Internal name).
120 -- If the External parameter is given as a string, then this string is
121 -- treated as an external name (exactly as though it had been given as an
122 -- External_Name parameter for a normal Import pragma).
124 -- If the External parameter is given as an identifier (or there is no
125 -- External parameter, so that the Internal identifier is used), then
126 -- the external name is the characters of the identifier, translated
127 -- to all upper case letters for OpenVMS versions of GNAT, and to all
128 -- lower case letters for all other versions
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals is new Table.Table (
157 Table_Component_Type => Node_Id,
158 Table_Index_Type => Int,
159 Table_Low_Bound => 0,
160 Table_Initial => 100,
161 Table_Increment => 100,
162 Table_Name => "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
169 -- This routine is used for possible casing adjustment of an explicit
170 -- external name supplied as a string literal (the node N), according to
171 -- the casing requirement of Opt.External_Name_Casing. If this is set to
172 -- As_Is, then the string literal is returned unchanged, but if it is set
173 -- to Uppercase or Lowercase, then a new string literal with appropriate
174 -- casing is constructed.
176 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
177 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
178 -- original one, following the renaming chain) is returned. Otherwise the
179 -- entity is returned unchanged. Should be in Einfo???
181 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
182 -- All the routines that check pragma arguments take either a pragma
183 -- argument association (in which case the expression of the argument
184 -- association is checked), or the expression directly. The function
185 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
186 -- is a pragma argument association node, then its expression is returned,
187 -- otherwise Arg is returned unchanged.
190 -- This is a dummy function called by the processing for pragma Reviewable.
191 -- It is there for assisting front end debugging. By placing a Reviewable
192 -- pragma in the source program, a breakpoint on rv catches this place in
193 -- the source, allowing convenient stepping to the point of interest.
195 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196 -- Place semantic information on the argument of an Elaborate/Elaborate_All
197 -- pragma. Entity name for unit and its parents is taken from item in
198 -- previous with_clause that mentions the unit.
200 -------------------------------
201 -- Adjust_External_Name_Case --
202 -------------------------------
204 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
208 -- Adjust case of literal if required
210 if Opt.External_Name_Exp_Casing = As_Is then
214 -- Copy existing string
220 for J in 1 .. String_Length (Strval (N)) loop
221 CC := Get_String_Char (Strval (N), J);
223 if Opt.External_Name_Exp_Casing = Uppercase
224 and then CC >= Get_Char_Code ('a')
225 and then CC <= Get_Char_Code ('z')
227 Store_String_Char (CC - 32);
229 elsif Opt.External_Name_Exp_Casing = Lowercase
230 and then CC >= Get_Char_Code ('A')
231 and then CC <= Get_Char_Code ('Z')
233 Store_String_Char (CC + 32);
236 Store_String_Char (CC);
241 Make_String_Literal (Sloc (N),
242 Strval => End_String);
244 end Adjust_External_Name_Case;
246 ------------------------------
247 -- Analyze_PPC_In_Decl_Part --
248 ------------------------------
250 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251 Arg1 : constant Node_Id :=
252 First (Pragma_Argument_Associations (N));
253 Arg2 : constant Node_Id := Next (Arg1);
256 -- Install formals and push subprogram spec onto scope stack so that we
257 -- can see the formals from the pragma.
262 -- Preanalyze the boolean expression, we treat this as a spec expression
263 -- (i.e. similar to a default expression).
265 Preanalyze_Spec_Expression
266 (Get_Pragma_Arg (Arg1), Standard_Boolean);
268 -- If there is a message argument, analyze it the same way
270 if Present (Arg2) then
271 Preanalyze_Spec_Expression
272 (Get_Pragma_Arg (Arg2), Standard_String);
275 -- Remove the subprogram from the scope stack now that the pre-analysis
276 -- of the precondition/postcondition is done.
279 end Analyze_PPC_In_Decl_Part;
285 procedure Analyze_Pragma (N : Node_Id) is
286 Loc : constant Source_Ptr := Sloc (N);
287 Pname : constant Name_Id := Pragma_Name (N);
290 Pragma_Exit : exception;
291 -- This exception is used to exit pragma processing completely. It is
292 -- used when an error is detected, and no further processing is
293 -- required. It is also used if an earlier error has left the tree in
294 -- a state where the pragma should not be processed.
297 -- Number of pragma argument associations
303 -- First four pragma arguments (pragma argument association nodes, or
304 -- Empty if the corresponding argument does not exist).
306 type Name_List is array (Natural range <>) of Name_Id;
307 type Args_List is array (Natural range <>) of Node_Id;
308 -- Types used for arguments to Check_Arg_Order and Gather_Associations
310 procedure Ada_2005_Pragma;
311 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
312 -- Ada 95 mode, these are implementation defined pragmas, so should be
313 -- caught by the No_Implementation_Pragmas restriction
315 procedure Check_Ada_83_Warning;
316 -- Issues a warning message for the current pragma if operating in Ada
317 -- 83 mode (used for language pragmas that are not a standard part of
318 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
321 procedure Check_Arg_Count (Required : Nat);
322 -- Check argument count for pragma is equal to given parameter. If not,
323 -- then issue an error message and raise Pragma_Exit.
325 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
326 -- Arg which can either be a pragma argument association, in which case
327 -- the check is applied to the expression of the association or an
328 -- expression directly.
330 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
331 -- Check that an argument has the right form for an EXTERNAL_NAME
332 -- parameter of an extended import/export pragma. The rule is that the
333 -- name must be an identifier or string literal (in Ada 83 mode) or a
334 -- static string expression (in Ada 95 mode).
336 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
337 -- Check the specified argument Arg to make sure that it is an
338 -- identifier. If not give error and raise Pragma_Exit.
340 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
341 -- Check the specified argument Arg to make sure that it is an integer
342 -- literal. If not give error and raise Pragma_Exit.
344 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
345 -- Check the specified argument Arg to make sure that it has the proper
346 -- syntactic form for a local name and meets the semantic requirements
347 -- for a local name. The local name is analyzed as part of the
348 -- processing for this call. In addition, the local name is required
349 -- to represent an entity at the library level.
351 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
352 -- Check the specified argument Arg to make sure that it has the proper
353 -- syntactic form for a local name and meets the semantic requirements
354 -- for a local name. The local name is analyzed as part of the
355 -- processing for this call.
357 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
358 -- Check the specified argument Arg to make sure that it is a valid
359 -- locking policy name. If not give error and raise Pragma_Exit.
361 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
362 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
363 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
364 -- Check the specified argument Arg to make sure that it is an
365 -- identifier whose name matches either N1 or N2 (or N3 if present).
366 -- If not then give error and raise Pragma_Exit.
368 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
369 -- Check the specified argument Arg to make sure that it is a valid
370 -- queuing policy name. If not give error and raise Pragma_Exit.
372 procedure Check_Arg_Is_Static_Expression
374 Typ : Entity_Id := Empty);
375 -- Check the specified argument Arg to make sure that it is a static
376 -- expression of the given type (i.e. it will be analyzed and resolved
377 -- using this type, which can be any valid argument to Resolve, e.g.
378 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
379 -- Typ is left Empty, then any static expression is allowed.
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
399 In_Variant_Part : Boolean := False);
400 -- Examine an Unchecked_Union component for correct use of per-object
401 -- constrained subtypes, and for restrictions on finalizable components.
402 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
403 -- should be set when Comp comes from a record variant.
405 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
406 -- Nam is an N_String_Literal node containing the external name set by
407 -- an Import or Export pragma (or extended Import or Export pragma).
408 -- This procedure checks for possible duplications if this is the export
409 -- case, and if found, issues an appropriate error message.
411 procedure Check_First_Subtype (Arg : Node_Id);
412 -- Checks that Arg, whose expression is an entity name referencing a
413 -- subtype, does not reference a type that is not a first subtype.
415 procedure Check_In_Main_Program;
416 -- Common checks for pragmas that appear within a main program
417 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
419 procedure Check_Interrupt_Or_Attach_Handler;
420 -- Common processing for first argument of pragma Interrupt_Handler or
421 -- pragma Attach_Handler.
423 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
424 -- Check that pragma appears in a declarative part, or in a package
425 -- specification, i.e. that it does not occur in a statement sequence
428 procedure Check_No_Identifier (Arg : Node_Id);
429 -- Checks that the given argument does not have an identifier. If
430 -- an identifier is present, then an error message is issued, and
431 -- Pragma_Exit is raised.
433 procedure Check_No_Identifiers;
434 -- Checks that none of the arguments to the pragma has an identifier.
435 -- If any argument has an identifier, then an error message is issued,
436 -- and Pragma_Exit is raised.
438 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
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.
443 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
444 -- Checks if the given argument has an identifier, and if so, requires
445 -- it to match the given identifier name. If there is a non-matching
446 -- identifier, then an error message is given and Error_Pragmas raised.
447 -- In this version of the procedure, the identifier name is given as
448 -- a string with lower case letters.
450 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
451 -- Called to process a precondition or postcondition pragma. There are
454 -- The pragma appears after a subprogram spec
456 -- If the corresponding check is not enabled, the pragma is analyzed
457 -- but otherwise ignored and control returns with In_Body set False.
459 -- If the check is enabled, then the first step is to analyze the
460 -- pragma, but this is skipped if the subprogram spec appears within
461 -- a package specification (because this is the case where we delay
462 -- analysis till the end of the spec). Then (whether or not it was
463 -- analyzed), the pragma is chained to the subprogram in question
464 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
465 -- caller with In_Body set False.
467 -- The pragma appears at the start of subprogram body declarations
469 -- In this case an immediate return to the caller is made with
470 -- In_Body set True, and the pragma is NOT analyzed.
472 -- In all other cases, an error message for bad placement is given
474 procedure Check_Static_Constraint (Constr : Node_Id);
475 -- Constr is a constraint from an N_Subtype_Indication node from a
476 -- component constraint in an Unchecked_Union type. This routine checks
477 -- that the constraint is static as required by the restrictions for
480 procedure Check_Valid_Configuration_Pragma;
481 -- Legality checks for placement of a configuration pragma
483 procedure Check_Valid_Library_Unit_Pragma;
484 -- Legality checks for library unit pragmas. A special case arises for
485 -- pragmas in generic instances that come from copies of the original
486 -- library unit pragmas in the generic templates. In the case of other
487 -- than library level instantiations these can appear in contexts which
488 -- would normally be invalid (they only apply to the original template
489 -- and to library level instantiations), and they are simply ignored,
490 -- which is implemented by rewriting them as null statements.
492 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
493 -- Check an Unchecked_Union variant for lack of nested variants and
494 -- presence of at least one component. UU_Typ is the related Unchecked_
497 procedure Error_Pragma (Msg : String);
498 pragma No_Return (Error_Pragma);
499 -- Outputs error message for current pragma. The message contains a %
500 -- that will be replaced with the pragma name, and the flag is placed
501 -- on the pragma itself. Pragma_Exit is then raised.
503 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
504 pragma No_Return (Error_Pragma_Arg);
505 -- Outputs error message for current pragma. The message may contain
506 -- a % that will be replaced with the pragma name. The parameter Arg
507 -- may either be a pragma argument association, in which case the flag
508 -- is placed on the expression of this association, or an expression,
509 -- in which case the flag is placed directly on the expression. The
510 -- message is placed using Error_Msg_N, so the message may also contain
511 -- an & insertion character which will reference the given Arg value.
512 -- After placing the message, Pragma_Exit is raised.
514 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
515 pragma No_Return (Error_Pragma_Arg);
516 -- Similar to above form of Error_Pragma_Arg except that two messages
517 -- are provided, the second is a continuation comment starting with \.
519 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
520 pragma No_Return (Error_Pragma_Arg_Ident);
521 -- Outputs error message for current pragma. The message may contain
522 -- a % that will be replaced with the pragma name. The parameter Arg
523 -- must be a pragma argument association with a non-empty identifier
524 -- (i.e. its Chars field must be set), and the error message is placed
525 -- on the identifier. The message is placed using Error_Msg_N so
526 -- the message may also contain an & insertion character which will
527 -- reference the identifier. After placing the message, Pragma_Exit
530 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
531 pragma No_Return (Error_Pragma_Ref);
532 -- Outputs error message for current pragma. The message may contain
533 -- a % that will be replaced with the pragma name. The parameter Ref
534 -- must be an entity whose name can be referenced by & and sloc by #.
535 -- After placing the message, Pragma_Exit is raised.
537 function Find_Lib_Unit_Name return Entity_Id;
538 -- Used for a library unit pragma to find the entity to which the
539 -- library unit pragma applies, returns the entity found.
541 procedure Find_Program_Unit_Name (Id : Node_Id);
542 -- If the pragma is a compilation unit pragma, the id must denote the
543 -- compilation unit in the same compilation, and the pragma must appear
544 -- in the list of preceding or trailing pragmas. If it is a program
545 -- unit pragma that is not a compilation unit pragma, then the
546 -- identifier must be visible.
548 function Find_Unique_Parameterless_Procedure
550 Arg : Node_Id) return Entity_Id;
551 -- Used for a procedure pragma to find the unique parameterless
552 -- procedure identified by Name, returns it if it exists, otherwise
553 -- errors out and uses Arg as the pragma argument for the message.
555 procedure Gather_Associations
557 Args : out Args_List);
558 -- This procedure is used to gather the arguments for a pragma that
559 -- permits arbitrary ordering of parameters using the normal rules
560 -- for named and positional parameters. The Names argument is a list
561 -- of Name_Id values that corresponds to the allowed pragma argument
562 -- association identifiers in order. The result returned in Args is
563 -- a list of corresponding expressions that are the pragma arguments.
564 -- Note that this is a list of expressions, not of pragma argument
565 -- associations (Gather_Associations has completely checked all the
566 -- optional identifiers when it returns). An entry in Args is Empty
567 -- on return if the corresponding argument is not present.
569 procedure GNAT_Pragma;
570 -- Called for all GNAT defined pragmas to check the relevant restriction
571 -- (No_Implementation_Pragmas).
573 function Is_Before_First_Decl
574 (Pragma_Node : Node_Id;
575 Decls : List_Id) return Boolean;
576 -- Return True if Pragma_Node is before the first declarative item in
577 -- Decls where Decls is the list of declarative items.
579 function Is_Configuration_Pragma return Boolean;
580 -- Determines if the placement of the current pragma is appropriate
581 -- for a configuration pragma.
583 function Is_In_Context_Clause return Boolean;
584 -- Returns True if pragma appears within the context clause of a unit,
585 -- and False for any other placement (does not generate any messages).
587 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
588 -- Analyzes the argument, and determines if it is a static string
589 -- expression, returns True if so, False if non-static or not String.
591 procedure Pragma_Misplaced;
592 pragma No_Return (Pragma_Misplaced);
593 -- Issue fatal error message for misplaced pragma
595 procedure Process_Atomic_Shared_Volatile;
596 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
597 -- Shared is an obsolete Ada 83 pragma, treated as being identical
598 -- in effect to pragma Atomic.
600 procedure Process_Compile_Time_Warning_Or_Error;
601 -- Common processing for Compile_Time_Error and Compile_Time_Warning
603 procedure Process_Convention
604 (C : out Convention_Id;
605 Ent : out Entity_Id);
606 -- Common processing for Convention, Interface, Import and Export.
607 -- Checks first two arguments of pragma, and sets the appropriate
608 -- convention value in the specified entity or entities. On return
609 -- C is the convention, Ent is the referenced entity.
611 procedure Process_Extended_Import_Export_Exception_Pragma
612 (Arg_Internal : Node_Id;
613 Arg_External : Node_Id;
616 -- Common processing for the pragmas Import/Export_Exception. The three
617 -- arguments correspond to the three named parameters of the pragma. An
618 -- argument is empty if the corresponding parameter is not present in
621 procedure Process_Extended_Import_Export_Object_Pragma
622 (Arg_Internal : Node_Id;
623 Arg_External : Node_Id;
625 -- Common processing for the pragmas Import/Export_Object. The three
626 -- arguments correspond to the three named parameters of the pragmas. An
627 -- argument is empty if the corresponding parameter is not present in
630 procedure Process_Extended_Import_Export_Internal_Arg
631 (Arg_Internal : Node_Id := Empty);
632 -- Common processing for all extended Import and Export pragmas. The
633 -- argument is the pragma parameter for the Internal argument. If
634 -- Arg_Internal is empty or inappropriate, an error message is posted.
635 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
636 -- set to identify the referenced entity.
638 procedure Process_Extended_Import_Export_Subprogram_Pragma
639 (Arg_Internal : Node_Id;
640 Arg_External : Node_Id;
641 Arg_Parameter_Types : Node_Id;
642 Arg_Result_Type : Node_Id := Empty;
643 Arg_Mechanism : Node_Id;
644 Arg_Result_Mechanism : Node_Id := Empty;
645 Arg_First_Optional_Parameter : Node_Id := Empty);
646 -- Common processing for all extended Import and Export pragmas applying
647 -- to subprograms. The caller omits any arguments that do not apply to
648 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
649 -- only in the Import_Function and Export_Function cases). The argument
650 -- names correspond to the allowed pragma association identifiers.
652 procedure Process_Generic_List;
653 -- Common processing for Share_Generic and Inline_Generic
655 procedure Process_Import_Or_Interface;
656 -- Common processing for Import of Interface
658 procedure Process_Inline (Active : Boolean);
659 -- Common processing for Inline and Inline_Always. The parameter
660 -- indicates if the inline pragma is active, i.e. if it should actually
661 -- cause inlining to occur.
663 procedure Process_Interface_Name
664 (Subprogram_Def : Entity_Id;
667 -- Given the last two arguments of pragma Import, pragma Export, or
668 -- pragma Interface_Name, performs validity checks and sets the
669 -- Interface_Name field of the given subprogram entity to the
670 -- appropriate external or link name, depending on the arguments given.
671 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
672 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
673 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
674 -- nor Link_Arg is present, the interface name is set to the default
675 -- from the subprogram name.
677 procedure Process_Interrupt_Or_Attach_Handler;
678 -- Common processing for Interrupt and Attach_Handler pragmas
680 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
681 -- Common processing for Restrictions and Restriction_Warnings pragmas.
682 -- Warn is True for Restriction_Warnings, or for Restrictions if the
683 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
684 -- is not set in the Restrictions case.
686 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
687 -- Common processing for Suppress and Unsuppress. The boolean parameter
688 -- Suppress_Case is True for the Suppress case, and False for the
691 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
692 -- This procedure sets the Is_Exported flag for the given entity,
693 -- checking that the entity was not previously imported. Arg is
694 -- the argument that specified the entity. A check is also made
695 -- for exporting inappropriate entities.
697 procedure Set_Extended_Import_Export_External_Name
698 (Internal_Ent : Entity_Id;
699 Arg_External : Node_Id);
700 -- Common processing for all extended import export pragmas. The first
701 -- argument, Internal_Ent, is the internal entity, which has already
702 -- been checked for validity by the caller. Arg_External is from the
703 -- Import or Export pragma, and may be null if no External parameter
704 -- was present. If Arg_External is present and is a non-null string
705 -- (a null string is treated as the default), then the Interface_Name
706 -- field of Internal_Ent is set appropriately.
708 procedure Set_Imported (E : Entity_Id);
709 -- This procedure sets the Is_Imported flag for the given entity,
710 -- checking that it is not previously exported or imported.
712 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
713 -- Mech is a parameter passing mechanism (see Import_Function syntax
714 -- for MECHANISM_NAME). This routine checks that the mechanism argument
715 -- has the right form, and if not issues an error message. If the
716 -- argument has the right form then the Mechanism field of Ent is
717 -- set appropriately.
719 procedure Set_Ravenscar_Profile (N : Node_Id);
720 -- Activate the set of configuration pragmas and restrictions that make
721 -- up the Ravenscar Profile. N is the corresponding pragma node, which
722 -- is used for error messages on any constructs that violate the
725 ---------------------
726 -- Ada_2005_Pragma --
727 ---------------------
729 procedure Ada_2005_Pragma is
731 if Ada_Version <= Ada_95 then
732 Check_Restriction (No_Implementation_Pragmas, N);
736 --------------------------
737 -- Check_Ada_83_Warning --
738 --------------------------
740 procedure Check_Ada_83_Warning is
742 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
743 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
745 end Check_Ada_83_Warning;
747 ---------------------
748 -- Check_Arg_Count --
749 ---------------------
751 procedure Check_Arg_Count (Required : Nat) is
753 if Arg_Count /= Required then
754 Error_Pragma ("wrong number of arguments for pragma%");
758 --------------------------------
759 -- Check_Arg_Is_External_Name --
760 --------------------------------
762 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
763 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
766 if Nkind (Argx) = N_Identifier then
770 Analyze_And_Resolve (Argx, Standard_String);
772 if Is_OK_Static_Expression (Argx) then
775 elsif Etype (Argx) = Any_Type then
778 -- An interesting special case, if we have a string literal and
779 -- we are in Ada 83 mode, then we allow it even though it will
780 -- not be flagged as static. This allows expected Ada 83 mode
781 -- use of external names which are string literals, even though
782 -- technically these are not static in Ada 83.
784 elsif Ada_Version = Ada_83
785 and then Nkind (Argx) = N_String_Literal
789 -- Static expression that raises Constraint_Error. This has
790 -- already been flagged, so just exit from pragma processing.
792 elsif Is_Static_Expression (Argx) then
795 -- Here we have a real error (non-static expression)
798 Error_Msg_Name_1 := Pname;
800 ("argument for pragma% must be a identifier or " &
801 "static string expression!", Argx);
805 end Check_Arg_Is_External_Name;
807 -----------------------------
808 -- Check_Arg_Is_Identifier --
809 -----------------------------
811 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
812 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
814 if Nkind (Argx) /= N_Identifier then
816 ("argument for pragma% must be identifier", Argx);
818 end Check_Arg_Is_Identifier;
820 ----------------------------------
821 -- Check_Arg_Is_Integer_Literal --
822 ----------------------------------
824 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
825 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
827 if Nkind (Argx) /= N_Integer_Literal then
829 ("argument for pragma% must be integer literal", Argx);
831 end Check_Arg_Is_Integer_Literal;
833 -------------------------------------------
834 -- Check_Arg_Is_Library_Level_Local_Name --
835 -------------------------------------------
839 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
840 -- | library_unit_NAME
842 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
844 Check_Arg_Is_Local_Name (Arg);
846 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
847 and then Comes_From_Source (N)
850 ("argument for pragma% must be library level entity", Arg);
852 end Check_Arg_Is_Library_Level_Local_Name;
854 -----------------------------
855 -- Check_Arg_Is_Local_Name --
856 -----------------------------
860 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
861 -- | library_unit_NAME
863 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
864 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
869 if Nkind (Argx) not in N_Direct_Name
870 and then (Nkind (Argx) /= N_Attribute_Reference
871 or else Present (Expressions (Argx))
872 or else Nkind (Prefix (Argx)) /= N_Identifier)
873 and then (not Is_Entity_Name (Argx)
874 or else not Is_Compilation_Unit (Entity (Argx)))
876 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
879 if Is_Entity_Name (Argx)
880 and then Scope (Entity (Argx)) /= Current_Scope
883 ("pragma% argument must be in same declarative part", Arg);
885 end Check_Arg_Is_Local_Name;
887 ---------------------------------
888 -- Check_Arg_Is_Locking_Policy --
889 ---------------------------------
891 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
892 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
895 Check_Arg_Is_Identifier (Argx);
897 if not Is_Locking_Policy_Name (Chars (Argx)) then
899 ("& is not a valid locking policy name", Argx);
901 end Check_Arg_Is_Locking_Policy;
903 -------------------------
904 -- Check_Arg_Is_One_Of --
905 -------------------------
907 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
908 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
911 Check_Arg_Is_Identifier (Argx);
913 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
914 Error_Msg_Name_2 := N1;
915 Error_Msg_Name_3 := N2;
916 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
918 end Check_Arg_Is_One_Of;
920 procedure Check_Arg_Is_One_Of
922 N1, N2, N3 : Name_Id)
924 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
927 Check_Arg_Is_Identifier (Argx);
929 if Chars (Argx) /= N1
930 and then Chars (Argx) /= N2
931 and then Chars (Argx) /= N3
933 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
935 end Check_Arg_Is_One_Of;
937 procedure Check_Arg_Is_One_Of
939 N1, N2, N3, N4 : Name_Id)
941 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
944 Check_Arg_Is_Identifier (Argx);
946 if Chars (Argx) /= N1
947 and then Chars (Argx) /= N2
948 and then Chars (Argx) /= N3
949 and then Chars (Argx) /= N4
951 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
953 end Check_Arg_Is_One_Of;
955 ---------------------------------
956 -- Check_Arg_Is_Queuing_Policy --
957 ---------------------------------
959 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
960 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
963 Check_Arg_Is_Identifier (Argx);
965 if not Is_Queuing_Policy_Name (Chars (Argx)) then
967 ("& is not a valid queuing policy name", Argx);
969 end Check_Arg_Is_Queuing_Policy;
971 ------------------------------------
972 -- Check_Arg_Is_Static_Expression --
973 ------------------------------------
975 procedure Check_Arg_Is_Static_Expression
977 Typ : Entity_Id := Empty)
979 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
982 if Present (Typ) then
983 Analyze_And_Resolve (Argx, Typ);
985 Analyze_And_Resolve (Argx);
988 if Is_OK_Static_Expression (Argx) then
991 elsif Etype (Argx) = Any_Type then
994 -- An interesting special case, if we have a string literal and we
995 -- are in Ada 83 mode, then we allow it even though it will not be
996 -- flagged as static. This allows the use of Ada 95 pragmas like
997 -- Import in Ada 83 mode. They will of course be flagged with
998 -- warnings as usual, but will not cause errors.
1000 elsif Ada_Version = Ada_83
1001 and then Nkind (Argx) = N_String_Literal
1005 -- Static expression that raises Constraint_Error. This has already
1006 -- been flagged, so just exit from pragma processing.
1008 elsif Is_Static_Expression (Argx) then
1011 -- Finally, we have a real error
1014 Error_Msg_Name_1 := Pname;
1015 Flag_Non_Static_Expr
1016 ("argument for pragma% must be a static expression!", Argx);
1019 end Check_Arg_Is_Static_Expression;
1021 ------------------------------------------
1022 -- Check_Arg_Is_Task_Dispatching_Policy --
1023 ------------------------------------------
1025 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1026 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1029 Check_Arg_Is_Identifier (Argx);
1031 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1033 ("& is not a valid task dispatching policy name", Argx);
1035 end Check_Arg_Is_Task_Dispatching_Policy;
1037 ---------------------
1038 -- Check_Arg_Order --
1039 ---------------------
1041 procedure Check_Arg_Order (Names : Name_List) is
1044 Highest_So_Far : Natural := 0;
1045 -- Highest index in Names seen do far
1049 for J in 1 .. Arg_Count loop
1050 if Chars (Arg) /= No_Name then
1051 for K in Names'Range loop
1052 if Chars (Arg) = Names (K) then
1053 if K < Highest_So_Far then
1054 Error_Msg_Name_1 := Pname;
1056 ("parameters out of order for pragma%", Arg);
1057 Error_Msg_Name_1 := Names (K);
1058 Error_Msg_Name_2 := Names (Highest_So_Far);
1059 Error_Msg_N ("\% must appear before %", Arg);
1063 Highest_So_Far := K;
1071 end Check_Arg_Order;
1073 --------------------------------
1074 -- Check_At_Least_N_Arguments --
1075 --------------------------------
1077 procedure Check_At_Least_N_Arguments (N : Nat) is
1079 if Arg_Count < N then
1080 Error_Pragma ("too few arguments for pragma%");
1082 end Check_At_Least_N_Arguments;
1084 -------------------------------
1085 -- Check_At_Most_N_Arguments --
1086 -------------------------------
1088 procedure Check_At_Most_N_Arguments (N : Nat) is
1091 if Arg_Count > N then
1093 for J in 1 .. N loop
1095 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1098 end Check_At_Most_N_Arguments;
1100 ---------------------
1101 -- Check_Component --
1102 ---------------------
1104 procedure Check_Component
1107 In_Variant_Part : Boolean := False)
1109 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1110 Sindic : constant Node_Id :=
1111 Subtype_Indication (Component_Definition (Comp));
1112 Typ : constant Entity_Id := Etype (Comp_Id);
1114 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1115 -- Determine whether entity Id appears inside a generic body
1117 -------------------------
1118 -- Inside_Generic_Body --
1119 -------------------------
1121 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1122 S : Entity_Id := Id;
1126 and then S /= Standard_Standard
1128 if Ekind (S) = E_Generic_Package
1129 and then In_Package_Body (S)
1138 end Inside_Generic_Body;
1140 -- Start of processing for Check_Component
1143 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1144 -- object constraint, then the component type shall be an Unchecked_
1147 if Nkind (Sindic) = N_Subtype_Indication
1148 and then Has_Per_Object_Constraint (Comp_Id)
1149 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1152 ("component subtype subject to per-object constraint " &
1153 "must be an Unchecked_Union", Comp);
1155 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1156 -- the body of a generic unit, or within the body of any of its
1157 -- descendant library units, no part of the type of a component
1158 -- declared in a variant_part of the unchecked union type shall be of
1159 -- a formal private type or formal private extension declared within
1160 -- the formal part of the generic unit.
1162 elsif Ada_Version >= Ada_2012
1163 and then Inside_Generic_Body (UU_Typ)
1164 and then In_Variant_Part
1165 and then Is_Private_Type (Typ)
1166 and then Is_Generic_Type (Typ)
1169 ("component of Unchecked_Union cannot be of generic type", Comp);
1171 elsif Needs_Finalization (Typ) then
1173 ("component of Unchecked_Union cannot be controlled", Comp);
1175 elsif Has_Task (Typ) then
1177 ("component of Unchecked_Union cannot have tasks", Comp);
1179 end Check_Component;
1181 ----------------------------------
1182 -- Check_Duplicated_Export_Name --
1183 ----------------------------------
1185 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1186 String_Val : constant String_Id := Strval (Nam);
1189 -- We are only interested in the export case, and in the case of
1190 -- generics, it is the instance, not the template, that is the
1191 -- problem (the template will generate a warning in any case).
1193 if not Inside_A_Generic
1194 and then (Prag_Id = Pragma_Export
1196 Prag_Id = Pragma_Export_Procedure
1198 Prag_Id = Pragma_Export_Valued_Procedure
1200 Prag_Id = Pragma_Export_Function)
1202 for J in Externals.First .. Externals.Last loop
1203 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1204 Error_Msg_Sloc := Sloc (Externals.Table (J));
1205 Error_Msg_N ("external name duplicates name given#", Nam);
1210 Externals.Append (Nam);
1212 end Check_Duplicated_Export_Name;
1214 -------------------------
1215 -- Check_First_Subtype --
1216 -------------------------
1218 procedure Check_First_Subtype (Arg : Node_Id) is
1219 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1221 if not Is_First_Subtype (Entity (Argx)) then
1223 ("pragma% cannot apply to subtype", Argx);
1225 end Check_First_Subtype;
1227 ---------------------------
1228 -- Check_In_Main_Program --
1229 ---------------------------
1231 procedure Check_In_Main_Program is
1232 P : constant Node_Id := Parent (N);
1235 -- Must be at in subprogram body
1237 if Nkind (P) /= N_Subprogram_Body then
1238 Error_Pragma ("% pragma allowed only in subprogram");
1240 -- Otherwise warn if obviously not main program
1242 elsif Present (Parameter_Specifications (Specification (P)))
1243 or else not Is_Compilation_Unit (Defining_Entity (P))
1245 Error_Msg_Name_1 := Pname;
1247 ("?pragma% is only effective in main program", N);
1249 end Check_In_Main_Program;
1251 ---------------------------------------
1252 -- Check_Interrupt_Or_Attach_Handler --
1253 ---------------------------------------
1255 procedure Check_Interrupt_Or_Attach_Handler is
1256 Arg1_X : constant Node_Id := Expression (Arg1);
1257 Handler_Proc, Proc_Scope : Entity_Id;
1262 if Prag_Id = Pragma_Interrupt_Handler then
1263 Check_Restriction (No_Dynamic_Attachment, N);
1266 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1267 Proc_Scope := Scope (Handler_Proc);
1269 -- On AAMP only, a pragma Interrupt_Handler is supported for
1270 -- nonprotected parameterless procedures.
1272 if not AAMP_On_Target
1273 or else Prag_Id = Pragma_Attach_Handler
1275 if Ekind (Proc_Scope) /= E_Protected_Type then
1277 ("argument of pragma% must be protected procedure", Arg1);
1280 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1281 Error_Pragma ("pragma% must be in protected definition");
1285 if not Is_Library_Level_Entity (Proc_Scope)
1286 or else (AAMP_On_Target
1287 and then not Is_Library_Level_Entity (Handler_Proc))
1290 ("argument for pragma% must be library level entity", Arg1);
1292 end Check_Interrupt_Or_Attach_Handler;
1294 -------------------------------------------
1295 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1296 -------------------------------------------
1298 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1307 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1310 elsif Nkind_In (P, N_Package_Specification,
1315 -- Note: the following tests seem a little peculiar, because
1316 -- they test for bodies, but if we were in the statement part
1317 -- of the body, we would already have hit the handled statement
1318 -- sequence, so the only way we get here is by being in the
1319 -- declarative part of the body.
1321 elsif Nkind_In (P, N_Subprogram_Body,
1332 Error_Pragma ("pragma% is not in declarative part or package spec");
1333 end Check_Is_In_Decl_Part_Or_Package_Spec;
1335 -------------------------
1336 -- Check_No_Identifier --
1337 -------------------------
1339 procedure Check_No_Identifier (Arg : Node_Id) is
1341 if Chars (Arg) /= No_Name then
1342 Error_Pragma_Arg_Ident
1343 ("pragma% does not permit identifier& here", Arg);
1345 end Check_No_Identifier;
1347 --------------------------
1348 -- Check_No_Identifiers --
1349 --------------------------
1351 procedure Check_No_Identifiers is
1354 if Arg_Count > 0 then
1356 while Present (Arg_Node) loop
1357 Check_No_Identifier (Arg_Node);
1361 end Check_No_Identifiers;
1363 -------------------------------
1364 -- Check_Optional_Identifier --
1365 -------------------------------
1367 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1369 if Present (Arg) and then Chars (Arg) /= No_Name then
1370 if Chars (Arg) /= Id then
1371 Error_Msg_Name_1 := Pname;
1372 Error_Msg_Name_2 := Id;
1373 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1377 end Check_Optional_Identifier;
1379 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1381 Name_Buffer (1 .. Id'Length) := Id;
1382 Name_Len := Id'Length;
1383 Check_Optional_Identifier (Arg, Name_Find);
1384 end Check_Optional_Identifier;
1386 --------------------------------------
1387 -- Check_Precondition_Postcondition --
1388 --------------------------------------
1390 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1394 procedure Chain_PPC (PO : Node_Id);
1395 -- If PO is a subprogram declaration node (or a generic subprogram
1396 -- declaration node), then the precondition/postcondition applies
1397 -- to this subprogram and the processing for the pragma is completed.
1398 -- Otherwise the pragma is misplaced.
1404 procedure Chain_PPC (PO : Node_Id) is
1408 if not Nkind_In (PO, N_Subprogram_Declaration,
1409 N_Generic_Subprogram_Declaration)
1414 -- Here if we have subprogram or generic subprogram declaration
1416 S := Defining_Unit_Name (Specification (PO));
1418 -- Analyze the pragma unless it appears within a package spec,
1419 -- which is the case where we delay the analysis of the PPC until
1420 -- the end of the package declarations (for details, see
1421 -- Analyze_Package_Specification.Analyze_PPCs).
1423 if not Is_Package_Or_Generic_Package (Scope (S)) then
1424 Analyze_PPC_In_Decl_Part (N, S);
1427 -- Chain spec PPC pragma to list for subprogram
1429 Set_Next_Pragma (N, Spec_PPC_List (S));
1430 Set_Spec_PPC_List (S, N);
1432 -- Return indicating spec case
1438 -- Start of processing for Check_Precondition_Postcondition
1441 if not Is_List_Member (N) then
1445 -- Record if pragma is enabled
1447 if Check_Enabled (Pname) then
1448 Set_Pragma_Enabled (N);
1449 Set_SCO_Pragma_Enabled (Loc);
1452 -- If we are within an inlined body, the legality of the pragma
1453 -- has been checked already.
1455 if In_Inlined_Body then
1460 -- Search prior declarations
1463 while Present (Prev (P)) loop
1466 -- If the previous node is a generic subprogram, do not go to to
1467 -- the original node, which is the unanalyzed tree: we need to
1468 -- attach the pre/postconditions to the analyzed version at this
1469 -- point. They get propagated to the original tree when analyzing
1470 -- the corresponding body.
1472 if Nkind (P) not in N_Generic_Declaration then
1473 PO := Original_Node (P);
1478 -- Skip past prior pragma
1480 if Nkind (PO) = N_Pragma then
1483 -- Skip stuff not coming from source
1485 elsif not Comes_From_Source (PO) then
1488 -- Only remaining possibility is subprogram declaration
1496 -- If we fall through loop, pragma is at start of list, so see if it
1497 -- is at the start of declarations of a subprogram body.
1499 if Nkind (Parent (N)) = N_Subprogram_Body
1500 and then List_Containing (N) = Declarations (Parent (N))
1502 if Operating_Mode /= Generate_Code
1503 or else Inside_A_Generic
1506 -- Analyze expression in pragma, for correctness
1507 -- and for ASIS use.
1509 Preanalyze_Spec_Expression
1510 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1516 -- See if it is in the pragmas after a library level subprogram
1518 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1519 Chain_PPC (Unit (Parent (Parent (N))));
1523 -- If we fall through, pragma was misplaced
1526 end Check_Precondition_Postcondition;
1528 -----------------------------
1529 -- Check_Static_Constraint --
1530 -----------------------------
1532 -- Note: for convenience in writing this procedure, in addition to
1533 -- the officially (i.e. by spec) allowed argument which is always a
1534 -- constraint, it also allows ranges and discriminant associations.
1535 -- Above is not clear ???
1537 procedure Check_Static_Constraint (Constr : Node_Id) is
1539 procedure Require_Static (E : Node_Id);
1540 -- Require given expression to be static expression
1542 --------------------
1543 -- Require_Static --
1544 --------------------
1546 procedure Require_Static (E : Node_Id) is
1548 if not Is_OK_Static_Expression (E) then
1549 Flag_Non_Static_Expr
1550 ("non-static constraint not allowed in Unchecked_Union!", E);
1555 -- Start of processing for Check_Static_Constraint
1558 case Nkind (Constr) is
1559 when N_Discriminant_Association =>
1560 Require_Static (Expression (Constr));
1563 Require_Static (Low_Bound (Constr));
1564 Require_Static (High_Bound (Constr));
1566 when N_Attribute_Reference =>
1567 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1568 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1570 when N_Range_Constraint =>
1571 Check_Static_Constraint (Range_Expression (Constr));
1573 when N_Index_Or_Discriminant_Constraint =>
1577 IDC := First (Constraints (Constr));
1578 while Present (IDC) loop
1579 Check_Static_Constraint (IDC);
1587 end Check_Static_Constraint;
1589 --------------------------------------
1590 -- Check_Valid_Configuration_Pragma --
1591 --------------------------------------
1593 -- A configuration pragma must appear in the context clause of a
1594 -- compilation unit, and only other pragmas may precede it. Note that
1595 -- the test also allows use in a configuration pragma file.
1597 procedure Check_Valid_Configuration_Pragma is
1599 if not Is_Configuration_Pragma then
1600 Error_Pragma ("incorrect placement for configuration pragma%");
1602 end Check_Valid_Configuration_Pragma;
1604 -------------------------------------
1605 -- Check_Valid_Library_Unit_Pragma --
1606 -------------------------------------
1608 procedure Check_Valid_Library_Unit_Pragma is
1610 Parent_Node : Node_Id;
1611 Unit_Name : Entity_Id;
1612 Unit_Kind : Node_Kind;
1613 Unit_Node : Node_Id;
1614 Sindex : Source_File_Index;
1617 if not Is_List_Member (N) then
1621 Plist := List_Containing (N);
1622 Parent_Node := Parent (Plist);
1624 if Parent_Node = Empty then
1627 -- Case of pragma appearing after a compilation unit. In this case
1628 -- it must have an argument with the corresponding name and must
1629 -- be part of the following pragmas of its parent.
1631 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1632 if Plist /= Pragmas_After (Parent_Node) then
1635 elsif Arg_Count = 0 then
1637 ("argument required if outside compilation unit");
1640 Check_No_Identifiers;
1641 Check_Arg_Count (1);
1642 Unit_Node := Unit (Parent (Parent_Node));
1643 Unit_Kind := Nkind (Unit_Node);
1645 Analyze (Expression (Arg1));
1647 if Unit_Kind = N_Generic_Subprogram_Declaration
1648 or else Unit_Kind = N_Subprogram_Declaration
1650 Unit_Name := Defining_Entity (Unit_Node);
1652 elsif Unit_Kind in N_Generic_Instantiation then
1653 Unit_Name := Defining_Entity (Unit_Node);
1656 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1659 if Chars (Unit_Name) /=
1660 Chars (Entity (Expression (Arg1)))
1663 ("pragma% argument is not current unit name", Arg1);
1666 if Ekind (Unit_Name) = E_Package
1667 and then Present (Renamed_Entity (Unit_Name))
1669 Error_Pragma ("pragma% not allowed for renamed package");
1673 -- Pragma appears other than after a compilation unit
1676 -- Here we check for the generic instantiation case and also
1677 -- for the case of processing a generic formal package. We
1678 -- detect these cases by noting that the Sloc on the node
1679 -- does not belong to the current compilation unit.
1681 Sindex := Source_Index (Current_Sem_Unit);
1683 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1684 Rewrite (N, Make_Null_Statement (Loc));
1687 -- If before first declaration, the pragma applies to the
1688 -- enclosing unit, and the name if present must be this name.
1690 elsif Is_Before_First_Decl (N, Plist) then
1691 Unit_Node := Unit_Declaration_Node (Current_Scope);
1692 Unit_Kind := Nkind (Unit_Node);
1694 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1697 elsif Unit_Kind = N_Subprogram_Body
1698 and then not Acts_As_Spec (Unit_Node)
1702 elsif Nkind (Parent_Node) = N_Package_Body then
1705 elsif Nkind (Parent_Node) = N_Package_Specification
1706 and then Plist = Private_Declarations (Parent_Node)
1710 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1711 or else Nkind (Parent_Node) =
1712 N_Generic_Subprogram_Declaration)
1713 and then Plist = Generic_Formal_Declarations (Parent_Node)
1717 elsif Arg_Count > 0 then
1718 Analyze (Expression (Arg1));
1720 if Entity (Expression (Arg1)) /= Current_Scope then
1722 ("name in pragma% must be enclosing unit", Arg1);
1725 -- It is legal to have no argument in this context
1731 -- Error if not before first declaration. This is because a
1732 -- library unit pragma argument must be the name of a library
1733 -- unit (RM 10.1.5(7)), but the only names permitted in this
1734 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1735 -- generic subprogram declarations or generic instantiations.
1739 ("pragma% misplaced, must be before first declaration");
1743 end Check_Valid_Library_Unit_Pragma;
1749 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
1750 Clist : constant Node_Id := Component_List (Variant);
1754 if not Is_Non_Empty_List (Component_Items (Clist)) then
1756 ("Unchecked_Union may not have empty component list",
1761 Comp := First (Component_Items (Clist));
1762 while Present (Comp) loop
1763 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
1772 procedure Error_Pragma (Msg : String) is
1774 Error_Msg_Name_1 := Pname;
1775 Error_Msg_N (Msg, N);
1779 ----------------------
1780 -- Error_Pragma_Arg --
1781 ----------------------
1783 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1785 Error_Msg_Name_1 := Pname;
1786 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1788 end Error_Pragma_Arg;
1790 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1792 Error_Msg_Name_1 := Pname;
1793 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1794 Error_Pragma_Arg (Msg2, Arg);
1795 end Error_Pragma_Arg;
1797 ----------------------------
1798 -- Error_Pragma_Arg_Ident --
1799 ----------------------------
1801 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1803 Error_Msg_Name_1 := Pname;
1804 Error_Msg_N (Msg, Arg);
1806 end Error_Pragma_Arg_Ident;
1808 ----------------------
1809 -- Error_Pragma_Ref --
1810 ----------------------
1812 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1814 Error_Msg_Name_1 := Pname;
1815 Error_Msg_Sloc := Sloc (Ref);
1816 Error_Msg_NE (Msg, N, Ref);
1818 end Error_Pragma_Ref;
1820 ------------------------
1821 -- Find_Lib_Unit_Name --
1822 ------------------------
1824 function Find_Lib_Unit_Name return Entity_Id is
1826 -- Return inner compilation unit entity, for case of nested
1827 -- categorization pragmas. This happens in generic unit.
1829 if Nkind (Parent (N)) = N_Package_Specification
1830 and then Defining_Entity (Parent (N)) /= Current_Scope
1832 return Defining_Entity (Parent (N));
1834 return Current_Scope;
1836 end Find_Lib_Unit_Name;
1838 ----------------------------
1839 -- Find_Program_Unit_Name --
1840 ----------------------------
1842 procedure Find_Program_Unit_Name (Id : Node_Id) is
1843 Unit_Name : Entity_Id;
1844 Unit_Kind : Node_Kind;
1845 P : constant Node_Id := Parent (N);
1848 if Nkind (P) = N_Compilation_Unit then
1849 Unit_Kind := Nkind (Unit (P));
1851 if Unit_Kind = N_Subprogram_Declaration
1852 or else Unit_Kind = N_Package_Declaration
1853 or else Unit_Kind in N_Generic_Declaration
1855 Unit_Name := Defining_Entity (Unit (P));
1857 if Chars (Id) = Chars (Unit_Name) then
1858 Set_Entity (Id, Unit_Name);
1859 Set_Etype (Id, Etype (Unit_Name));
1861 Set_Etype (Id, Any_Type);
1863 ("cannot find program unit referenced by pragma%");
1867 Set_Etype (Id, Any_Type);
1868 Error_Pragma ("pragma% inapplicable to this unit");
1874 end Find_Program_Unit_Name;
1876 -----------------------------------------
1877 -- Find_Unique_Parameterless_Procedure --
1878 -----------------------------------------
1880 function Find_Unique_Parameterless_Procedure
1882 Arg : Node_Id) return Entity_Id
1884 Proc : Entity_Id := Empty;
1887 -- The body of this procedure needs some comments ???
1889 if not Is_Entity_Name (Name) then
1891 ("argument of pragma% must be entity name", Arg);
1893 elsif not Is_Overloaded (Name) then
1894 Proc := Entity (Name);
1896 if Ekind (Proc) /= E_Procedure
1897 or else Present (First_Formal (Proc))
1900 ("argument of pragma% must be parameterless procedure", Arg);
1905 Found : Boolean := False;
1907 Index : Interp_Index;
1910 Get_First_Interp (Name, Index, It);
1911 while Present (It.Nam) loop
1914 if Ekind (Proc) = E_Procedure
1915 and then No (First_Formal (Proc))
1919 Set_Entity (Name, Proc);
1920 Set_Is_Overloaded (Name, False);
1923 ("ambiguous handler name for pragma% ", Arg);
1927 Get_Next_Interp (Index, It);
1932 ("argument of pragma% must be parameterless procedure",
1935 Proc := Entity (Name);
1941 end Find_Unique_Parameterless_Procedure;
1943 -------------------------
1944 -- Gather_Associations --
1945 -------------------------
1947 procedure Gather_Associations
1949 Args : out Args_List)
1954 -- Initialize all parameters to Empty
1956 for J in Args'Range loop
1960 -- That's all we have to do if there are no argument associations
1962 if No (Pragma_Argument_Associations (N)) then
1966 -- Otherwise first deal with any positional parameters present
1968 Arg := First (Pragma_Argument_Associations (N));
1969 for Index in Args'Range loop
1970 exit when No (Arg) or else Chars (Arg) /= No_Name;
1971 Args (Index) := Expression (Arg);
1975 -- Positional parameters all processed, if any left, then we
1976 -- have too many positional parameters.
1978 if Present (Arg) and then Chars (Arg) = No_Name then
1980 ("too many positional associations for pragma%", Arg);
1983 -- Process named parameters if any are present
1985 while Present (Arg) loop
1986 if Chars (Arg) = No_Name then
1988 ("positional association cannot follow named association",
1992 for Index in Names'Range loop
1993 if Names (Index) = Chars (Arg) then
1994 if Present (Args (Index)) then
1996 ("duplicate argument association for pragma%", Arg);
1998 Args (Index) := Expression (Arg);
2003 if Index = Names'Last then
2004 Error_Msg_Name_1 := Pname;
2005 Error_Msg_N ("pragma% does not allow & argument", Arg);
2007 -- Check for possible misspelling
2009 for Index1 in Names'Range loop
2010 if Is_Bad_Spelling_Of
2011 (Chars (Arg), Names (Index1))
2013 Error_Msg_Name_1 := Names (Index1);
2014 Error_Msg_N -- CODEFIX
2015 ("\possible misspelling of%", Arg);
2027 end Gather_Associations;
2033 procedure GNAT_Pragma is
2035 Check_Restriction (No_Implementation_Pragmas, N);
2038 --------------------------
2039 -- Is_Before_First_Decl --
2040 --------------------------
2042 function Is_Before_First_Decl
2043 (Pragma_Node : Node_Id;
2044 Decls : List_Id) return Boolean
2046 Item : Node_Id := First (Decls);
2049 -- Only other pragmas can come before this pragma
2052 if No (Item) or else Nkind (Item) /= N_Pragma then
2055 elsif Item = Pragma_Node then
2061 end Is_Before_First_Decl;
2063 -----------------------------
2064 -- Is_Configuration_Pragma --
2065 -----------------------------
2067 -- A configuration pragma must appear in the context clause of a
2068 -- compilation unit, and only other pragmas may precede it. Note that
2069 -- the test below also permits use in a configuration pragma file.
2071 function Is_Configuration_Pragma return Boolean is
2072 Lis : constant List_Id := List_Containing (N);
2073 Par : constant Node_Id := Parent (N);
2077 -- If no parent, then we are in the configuration pragma file,
2078 -- so the placement is definitely appropriate.
2083 -- Otherwise we must be in the context clause of a compilation unit
2084 -- and the only thing allowed before us in the context list is more
2085 -- configuration pragmas.
2087 elsif Nkind (Par) = N_Compilation_Unit
2088 and then Context_Items (Par) = Lis
2095 elsif Nkind (Prg) /= N_Pragma then
2105 end Is_Configuration_Pragma;
2107 --------------------------
2108 -- Is_In_Context_Clause --
2109 --------------------------
2111 function Is_In_Context_Clause return Boolean is
2113 Parent_Node : Node_Id;
2116 if not Is_List_Member (N) then
2120 Plist := List_Containing (N);
2121 Parent_Node := Parent (Plist);
2123 if Parent_Node = Empty
2124 or else Nkind (Parent_Node) /= N_Compilation_Unit
2125 or else Context_Items (Parent_Node) /= Plist
2132 end Is_In_Context_Clause;
2134 ---------------------------------
2135 -- Is_Static_String_Expression --
2136 ---------------------------------
2138 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2139 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2142 Analyze_And_Resolve (Argx);
2143 return Is_OK_Static_Expression (Argx)
2144 and then Nkind (Argx) = N_String_Literal;
2145 end Is_Static_String_Expression;
2147 ----------------------
2148 -- Pragma_Misplaced --
2149 ----------------------
2151 procedure Pragma_Misplaced is
2153 Error_Pragma ("incorrect placement of pragma%");
2154 end Pragma_Misplaced;
2156 ------------------------------------
2157 -- Process Atomic_Shared_Volatile --
2158 ------------------------------------
2160 procedure Process_Atomic_Shared_Volatile is
2167 procedure Set_Atomic (E : Entity_Id);
2168 -- Set given type as atomic, and if no explicit alignment was given,
2169 -- set alignment to unknown, since back end knows what the alignment
2170 -- requirements are for atomic arrays. Note: this step is necessary
2171 -- for derived types.
2177 procedure Set_Atomic (E : Entity_Id) is
2181 if not Has_Alignment_Clause (E) then
2182 Set_Alignment (E, Uint_0);
2186 -- Start of processing for Process_Atomic_Shared_Volatile
2189 Check_Ada_83_Warning;
2190 Check_No_Identifiers;
2191 Check_Arg_Count (1);
2192 Check_Arg_Is_Local_Name (Arg1);
2193 E_Id := Expression (Arg1);
2195 if Etype (E_Id) = Any_Type then
2200 D := Declaration_Node (E);
2204 if Rep_Item_Too_Early (E, N)
2206 Rep_Item_Too_Late (E, N)
2210 Check_First_Subtype (Arg1);
2213 if Prag_Id /= Pragma_Volatile then
2215 Set_Atomic (Underlying_Type (E));
2216 Set_Atomic (Base_Type (E));
2219 -- Attribute belongs on the base type. If the view of the type is
2220 -- currently private, it also belongs on the underlying type.
2222 Set_Is_Volatile (Base_Type (E));
2223 Set_Is_Volatile (Underlying_Type (E));
2225 Set_Treat_As_Volatile (E);
2226 Set_Treat_As_Volatile (Underlying_Type (E));
2228 elsif K = N_Object_Declaration
2229 or else (K = N_Component_Declaration
2230 and then Original_Record_Component (E) = E)
2232 if Rep_Item_Too_Late (E, N) then
2236 if Prag_Id /= Pragma_Volatile then
2239 -- If the object declaration has an explicit initialization, a
2240 -- temporary may have to be created to hold the expression, to
2241 -- ensure that access to the object remain atomic.
2243 if Nkind (Parent (E)) = N_Object_Declaration
2244 and then Present (Expression (Parent (E)))
2246 Set_Has_Delayed_Freeze (E);
2249 -- An interesting improvement here. If an object of type X is
2250 -- declared atomic, and the type X is not atomic, that's a
2251 -- pity, since it may not have appropriate alignment etc. We
2252 -- can rescue this in the special case where the object and
2253 -- type are in the same unit by just setting the type as
2254 -- atomic, so that the back end will process it as atomic.
2256 Utyp := Underlying_Type (Etype (E));
2259 and then Sloc (E) > No_Location
2260 and then Sloc (Utyp) > No_Location
2262 Get_Source_File_Index (Sloc (E)) =
2263 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2265 Set_Is_Atomic (Underlying_Type (Etype (E)));
2269 Set_Is_Volatile (E);
2270 Set_Treat_As_Volatile (E);
2274 ("inappropriate entity for pragma%", Arg1);
2276 end Process_Atomic_Shared_Volatile;
2278 -------------------------------------------
2279 -- Process_Compile_Time_Warning_Or_Error --
2280 -------------------------------------------
2282 procedure Process_Compile_Time_Warning_Or_Error is
2283 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2286 Check_Arg_Count (2);
2287 Check_No_Identifiers;
2288 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2289 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2291 if Compile_Time_Known_Value (Arg1x) then
2292 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2294 Str : constant String_Id :=
2295 Strval (Get_Pragma_Arg (Arg2));
2296 Len : constant Int := String_Length (Str);
2301 Cent : constant Entity_Id :=
2302 Cunit_Entity (Current_Sem_Unit);
2304 Force : constant Boolean :=
2305 Prag_Id = Pragma_Compile_Time_Warning
2307 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2308 and then (Ekind (Cent) /= E_Package
2309 or else not In_Private_Part (Cent));
2310 -- Set True if this is the warning case, and we are in the
2311 -- visible part of a package spec, or in a subprogram spec,
2312 -- in which case we want to force the client to see the
2313 -- warning, even though it is not in the main unit.
2316 -- Loop through segments of message separated by line feeds.
2317 -- We output these segments as separate messages with
2318 -- continuation marks for all but the first.
2323 Error_Msg_Strlen := 0;
2325 -- Loop to copy characters from argument to error message
2329 exit when Ptr > Len;
2330 CC := Get_String_Char (Str, Ptr);
2333 -- Ignore wide chars ??? else store character
2335 if In_Character_Range (CC) then
2336 C := Get_Character (CC);
2337 exit when C = ASCII.LF;
2338 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2339 Error_Msg_String (Error_Msg_Strlen) := C;
2343 -- Here with one line ready to go
2345 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2347 -- If this is a warning in a spec, then we want clients
2348 -- to see the warning, so mark the message with the
2349 -- special sequence !! to force the warning. In the case
2350 -- of a package spec, we do not force this if we are in
2351 -- the private part of the spec.
2354 if Cont = False then
2355 Error_Msg_N ("<~!!", Arg1);
2358 Error_Msg_N ("\<~!!", Arg1);
2361 -- Error, rather than warning, or in a body, so we do not
2362 -- need to force visibility for client (error will be
2363 -- output in any case, and this is the situation in which
2364 -- we do not want a client to get a warning, since the
2365 -- warning is in the body or the spec private part.
2368 if Cont = False then
2369 Error_Msg_N ("<~", Arg1);
2372 Error_Msg_N ("\<~", Arg1);
2376 exit when Ptr > Len;
2381 end Process_Compile_Time_Warning_Or_Error;
2383 ------------------------
2384 -- Process_Convention --
2385 ------------------------
2387 procedure Process_Convention
2388 (C : out Convention_Id;
2389 Ent : out Entity_Id)
2395 Comp_Unit : Unit_Number_Type;
2397 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2398 -- Called if we have more than one Export/Import/Convention pragma.
2399 -- This is generally illegal, but we have a special case of allowing
2400 -- Import and Interface to coexist if they specify the convention in
2401 -- a consistent manner. We are allowed to do this, since Interface is
2402 -- an implementation defined pragma, and we choose to do it since we
2403 -- know Rational allows this combination. S is the entity id of the
2404 -- subprogram in question. This procedure also sets the special flag
2405 -- Import_Interface_Present in both pragmas in the case where we do
2406 -- have matching Import and Interface pragmas.
2408 procedure Set_Convention_From_Pragma (E : Entity_Id);
2409 -- Set convention in entity E, and also flag that the entity has a
2410 -- convention pragma. If entity is for a private or incomplete type,
2411 -- also set convention and flag on underlying type. This procedure
2412 -- also deals with the special case of C_Pass_By_Copy convention.
2414 -------------------------------
2415 -- Diagnose_Multiple_Pragmas --
2416 -------------------------------
2418 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2419 Pdec : constant Node_Id := Declaration_Node (S);
2423 function Same_Convention (Decl : Node_Id) return Boolean;
2424 -- Decl is a pragma node. This function returns True if this
2425 -- pragma has a first argument that is an identifier with a
2426 -- Chars field corresponding to the Convention_Id C.
2428 function Same_Name (Decl : Node_Id) return Boolean;
2429 -- Decl is a pragma node. This function returns True if this
2430 -- pragma has a second argument that is an identifier with a
2431 -- Chars field that matches the Chars of the current subprogram.
2433 ---------------------
2434 -- Same_Convention --
2435 ---------------------
2437 function Same_Convention (Decl : Node_Id) return Boolean is
2438 Arg1 : constant Node_Id :=
2439 First (Pragma_Argument_Associations (Decl));
2442 if Present (Arg1) then
2444 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2446 if Nkind (Arg) = N_Identifier
2447 and then Is_Convention_Name (Chars (Arg))
2448 and then Get_Convention_Id (Chars (Arg)) = C
2456 end Same_Convention;
2462 function Same_Name (Decl : Node_Id) return Boolean is
2463 Arg1 : constant Node_Id :=
2464 First (Pragma_Argument_Associations (Decl));
2472 Arg2 := Next (Arg1);
2479 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2481 if Nkind (Arg) = N_Identifier
2482 and then Chars (Arg) = Chars (S)
2491 -- Start of processing for Diagnose_Multiple_Pragmas
2496 -- Definitely give message if we have Convention/Export here
2498 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2501 -- If we have an Import or Export, scan back from pragma to
2502 -- find any previous pragma applying to the same procedure.
2503 -- The scan will be terminated by the start of the list, or
2504 -- hitting the subprogram declaration. This won't allow one
2505 -- pragma to appear in the public part and one in the private
2506 -- part, but that seems very unlikely in practice.
2510 while Present (Decl) and then Decl /= Pdec loop
2512 -- Look for pragma with same name as us
2514 if Nkind (Decl) = N_Pragma
2515 and then Same_Name (Decl)
2517 -- Give error if same as our pragma or Export/Convention
2519 if Pragma_Name (Decl) = Name_Export
2521 Pragma_Name (Decl) = Name_Convention
2523 Pragma_Name (Decl) = Pragma_Name (N)
2527 -- Case of Import/Interface or the other way round
2529 elsif Pragma_Name (Decl) = Name_Interface
2531 Pragma_Name (Decl) = Name_Import
2533 -- Here we know that we have Import and Interface. It
2534 -- doesn't matter which way round they are. See if
2535 -- they specify the same convention. If so, all OK,
2536 -- and set special flags to stop other messages
2538 if Same_Convention (Decl) then
2539 Set_Import_Interface_Present (N);
2540 Set_Import_Interface_Present (Decl);
2543 -- If different conventions, special message
2546 Error_Msg_Sloc := Sloc (Decl);
2548 ("convention differs from that given#", Arg1);
2558 -- Give message if needed if we fall through those tests
2562 ("at most one Convention/Export/Import pragma is allowed",
2565 end Diagnose_Multiple_Pragmas;
2567 --------------------------------
2568 -- Set_Convention_From_Pragma --
2569 --------------------------------
2571 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2573 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2574 -- for an overridden dispatching operation. Technically this is
2575 -- an amendment and should only be done in Ada 2005 mode. However,
2576 -- this is clearly a mistake, since the problem that is addressed
2577 -- by this AI is that there is a clear gap in the RM!
2579 if Is_Dispatching_Operation (E)
2580 and then Present (Overridden_Operation (E))
2581 and then C /= Convention (Overridden_Operation (E))
2584 ("cannot change convention for " &
2585 "overridden dispatching operation",
2589 -- Set the convention
2591 Set_Convention (E, C);
2592 Set_Has_Convention_Pragma (E);
2594 if Is_Incomplete_Or_Private_Type (E) then
2595 Set_Convention (Underlying_Type (E), C);
2596 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2599 -- A class-wide type should inherit the convention of the specific
2600 -- root type (although this isn't specified clearly by the RM).
2602 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2603 Set_Convention (Class_Wide_Type (E), C);
2606 -- If the entity is a record type, then check for special case of
2607 -- C_Pass_By_Copy, which is treated the same as C except that the
2608 -- special record flag is set. This convention is only permitted
2609 -- on record types (see AI95-00131).
2611 if Cname = Name_C_Pass_By_Copy then
2612 if Is_Record_Type (E) then
2613 Set_C_Pass_By_Copy (Base_Type (E));
2614 elsif Is_Incomplete_Or_Private_Type (E)
2615 and then Is_Record_Type (Underlying_Type (E))
2617 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2620 ("C_Pass_By_Copy convention allowed only for record type",
2625 -- If the entity is a derived boolean type, check for the special
2626 -- case of convention C, C++, or Fortran, where we consider any
2627 -- nonzero value to represent true.
2629 if Is_Discrete_Type (E)
2630 and then Root_Type (Etype (E)) = Standard_Boolean
2636 C = Convention_Fortran)
2638 Set_Nonzero_Is_True (Base_Type (E));
2640 end Set_Convention_From_Pragma;
2642 -- Start of processing for Process_Convention
2645 Check_At_Least_N_Arguments (2);
2646 Check_Optional_Identifier (Arg1, Name_Convention);
2647 Check_Arg_Is_Identifier (Arg1);
2648 Cname := Chars (Expression (Arg1));
2650 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2651 -- tested again below to set the critical flag).
2652 if Cname = Name_C_Pass_By_Copy then
2655 -- Otherwise we must have something in the standard convention list
2657 elsif Is_Convention_Name (Cname) then
2658 C := Get_Convention_Id (Chars (Expression (Arg1)));
2660 -- In DEC VMS, it seems that there is an undocumented feature that
2661 -- any unrecognized convention is treated as the default, which for
2662 -- us is convention C. It does not seem so terrible to do this
2663 -- unconditionally, silently in the VMS case, and with a warning
2664 -- in the non-VMS case.
2667 if Warn_On_Export_Import and not OpenVMS_On_Target then
2669 ("?unrecognized convention name, C assumed",
2676 Check_Optional_Identifier (Arg2, Name_Entity);
2677 Check_Arg_Is_Local_Name (Arg2);
2679 Id := Expression (Arg2);
2682 if not Is_Entity_Name (Id) then
2683 Error_Pragma_Arg ("entity name required", Arg2);
2688 -- Set entity to return
2692 -- Go to renamed subprogram if present, since convention applies to
2693 -- the actual renamed entity, not to the renaming entity. If the
2694 -- subprogram is inherited, go to parent subprogram.
2696 if Is_Subprogram (E)
2697 and then Present (Alias (E))
2699 if Nkind (Parent (Declaration_Node (E))) =
2700 N_Subprogram_Renaming_Declaration
2702 if Scope (E) /= Scope (Alias (E)) then
2704 ("cannot apply pragma% to non-local entity&#", E);
2709 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2710 N_Private_Extension_Declaration)
2711 and then Scope (E) = Scope (Alias (E))
2715 -- Return the parent subprogram the entity was inherited from
2721 -- Check that we are not applying this to a specless body
2723 if Is_Subprogram (E)
2724 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2727 ("pragma% requires separate spec and must come before body");
2730 -- Check that we are not applying this to a named constant
2732 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
2733 Error_Msg_Name_1 := Pname;
2735 ("cannot apply pragma% to named constant!",
2736 Get_Pragma_Arg (Arg2));
2738 ("\supply appropriate type for&!", Arg2);
2741 if Ekind (E) = E_Enumeration_Literal then
2742 Error_Pragma ("enumeration literal not allowed for pragma%");
2745 -- Check for rep item appearing too early or too late
2747 if Etype (E) = Any_Type
2748 or else Rep_Item_Too_Early (E, N)
2752 E := Underlying_Type (E);
2755 if Rep_Item_Too_Late (E, N) then
2759 if Has_Convention_Pragma (E) then
2760 Diagnose_Multiple_Pragmas (E);
2762 elsif Convention (E) = Convention_Protected
2763 or else Ekind (Scope (E)) = E_Protected_Type
2766 ("a protected operation cannot be given a different convention",
2770 -- For Intrinsic, a subprogram is required
2772 if C = Convention_Intrinsic
2773 and then not Is_Subprogram (E)
2774 and then not Is_Generic_Subprogram (E)
2777 ("second argument of pragma% must be a subprogram", Arg2);
2780 -- For Stdcall, a subprogram, variable or subprogram type is required
2782 if C = Convention_Stdcall
2783 and then not Is_Subprogram (E)
2784 and then not Is_Generic_Subprogram (E)
2785 and then Ekind (E) /= E_Variable
2788 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2791 ("second argument of pragma% must be subprogram (type)",
2795 if not Is_Subprogram (E)
2796 and then not Is_Generic_Subprogram (E)
2798 Set_Convention_From_Pragma (E);
2801 Check_First_Subtype (Arg2);
2802 Set_Convention_From_Pragma (Base_Type (E));
2804 -- For subprograms, we must set the convention on the
2805 -- internally generated directly designated type as well.
2807 if Ekind (E) = E_Access_Subprogram_Type then
2808 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2812 -- For the subprogram case, set proper convention for all homonyms
2813 -- in same scope and the same declarative part, i.e. the same
2814 -- compilation unit.
2817 Comp_Unit := Get_Source_Unit (E);
2818 Set_Convention_From_Pragma (E);
2820 -- Treat a pragma Import as an implicit body, for GPS use
2822 if Prag_Id = Pragma_Import then
2823 Generate_Reference (E, Id, 'b');
2826 -- Loop through the homonyms of the pragma argument's entity
2831 exit when No (E1) or else Scope (E1) /= Current_Scope;
2833 -- Do not set the pragma on inherited operations or on formal
2836 if Comes_From_Source (E1)
2837 and then Comp_Unit = Get_Source_Unit (E1)
2838 and then not Is_Formal_Subprogram (E1)
2839 and then Nkind (Original_Node (Parent (E1))) /=
2840 N_Full_Type_Declaration
2842 if Present (Alias (E1))
2843 and then Scope (E1) /= Scope (Alias (E1))
2846 ("cannot apply pragma% to non-local entity& declared#",
2850 Set_Convention_From_Pragma (E1);
2852 if Prag_Id = Pragma_Import then
2853 Generate_Reference (E1, Id, 'b');
2858 end Process_Convention;
2860 -----------------------------------------------------
2861 -- Process_Extended_Import_Export_Exception_Pragma --
2862 -----------------------------------------------------
2864 procedure Process_Extended_Import_Export_Exception_Pragma
2865 (Arg_Internal : Node_Id;
2866 Arg_External : Node_Id;
2874 if not OpenVMS_On_Target then
2876 ("?pragma% ignored (applies only to Open'V'M'S)");
2879 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2880 Def_Id := Entity (Arg_Internal);
2882 if Ekind (Def_Id) /= E_Exception then
2884 ("pragma% must refer to declared exception", Arg_Internal);
2887 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2889 if Present (Arg_Form) then
2890 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2893 if Present (Arg_Form)
2894 and then Chars (Arg_Form) = Name_Ada
2898 Set_Is_VMS_Exception (Def_Id);
2899 Set_Exception_Code (Def_Id, No_Uint);
2902 if Present (Arg_Code) then
2903 if not Is_VMS_Exception (Def_Id) then
2905 ("Code option for pragma% not allowed for Ada case",
2909 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2910 Code_Val := Expr_Value (Arg_Code);
2912 if not UI_Is_In_Int_Range (Code_Val) then
2914 ("Code option for pragma% must be in 32-bit range",
2918 Set_Exception_Code (Def_Id, Code_Val);
2921 end Process_Extended_Import_Export_Exception_Pragma;
2923 -------------------------------------------------
2924 -- Process_Extended_Import_Export_Internal_Arg --
2925 -------------------------------------------------
2927 procedure Process_Extended_Import_Export_Internal_Arg
2928 (Arg_Internal : Node_Id := Empty)
2931 if No (Arg_Internal) then
2932 Error_Pragma ("Internal parameter required for pragma%");
2935 if Nkind (Arg_Internal) = N_Identifier then
2938 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2939 and then (Prag_Id = Pragma_Import_Function
2941 Prag_Id = Pragma_Export_Function)
2947 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2950 Check_Arg_Is_Local_Name (Arg_Internal);
2951 end Process_Extended_Import_Export_Internal_Arg;
2953 --------------------------------------------------
2954 -- Process_Extended_Import_Export_Object_Pragma --
2955 --------------------------------------------------
2957 procedure Process_Extended_Import_Export_Object_Pragma
2958 (Arg_Internal : Node_Id;
2959 Arg_External : Node_Id;
2965 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2966 Def_Id := Entity (Arg_Internal);
2968 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
2970 ("pragma% must designate an object", Arg_Internal);
2973 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2975 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2978 ("previous Common/Psect_Object applies, pragma % not permitted",
2982 if Rep_Item_Too_Late (Def_Id, N) then
2986 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2988 if Present (Arg_Size) then
2989 Check_Arg_Is_External_Name (Arg_Size);
2992 -- Export_Object case
2994 if Prag_Id = Pragma_Export_Object then
2995 if not Is_Library_Level_Entity (Def_Id) then
2997 ("argument for pragma% must be library level entity",
3001 if Ekind (Current_Scope) = E_Generic_Package then
3002 Error_Pragma ("pragma& cannot appear in a generic unit");
3005 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3007 ("exported object must have compile time known size",
3011 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3012 Error_Msg_N ("?duplicate Export_Object pragma", N);
3014 Set_Exported (Def_Id, Arg_Internal);
3017 -- Import_Object case
3020 if Is_Concurrent_Type (Etype (Def_Id)) then
3022 ("cannot use pragma% for task/protected object",
3026 if Ekind (Def_Id) = E_Constant then
3028 ("cannot import a constant", Arg_Internal);
3031 if Warn_On_Export_Import
3032 and then Has_Discriminants (Etype (Def_Id))
3035 ("imported value must be initialized?", Arg_Internal);
3038 if Warn_On_Export_Import
3039 and then Is_Access_Type (Etype (Def_Id))
3042 ("cannot import object of an access type?", Arg_Internal);
3045 if Warn_On_Export_Import
3046 and then Is_Imported (Def_Id)
3049 ("?duplicate Import_Object pragma", N);
3051 -- Check for explicit initialization present. Note that an
3052 -- initialization generated by the code generator, e.g. for an
3053 -- access type, does not count here.
3055 elsif Present (Expression (Parent (Def_Id)))
3058 (Original_Node (Expression (Parent (Def_Id))))
3060 Error_Msg_Sloc := Sloc (Def_Id);
3062 ("imported entities cannot be initialized (RM B.1(24))",
3063 "\no initialization allowed for & declared#", Arg1);
3065 Set_Imported (Def_Id);
3066 Note_Possible_Modification (Arg_Internal, Sure => False);
3069 end Process_Extended_Import_Export_Object_Pragma;
3071 ------------------------------------------------------
3072 -- Process_Extended_Import_Export_Subprogram_Pragma --
3073 ------------------------------------------------------
3075 procedure Process_Extended_Import_Export_Subprogram_Pragma
3076 (Arg_Internal : Node_Id;
3077 Arg_External : Node_Id;
3078 Arg_Parameter_Types : Node_Id;
3079 Arg_Result_Type : Node_Id := Empty;
3080 Arg_Mechanism : Node_Id;
3081 Arg_Result_Mechanism : Node_Id := Empty;
3082 Arg_First_Optional_Parameter : Node_Id := Empty)
3088 Ambiguous : Boolean;
3092 function Same_Base_Type
3094 Formal : Entity_Id) return Boolean;
3095 -- Determines if Ptype references the type of Formal. Note that only
3096 -- the base types need to match according to the spec. Ptype here is
3097 -- the argument from the pragma, which is either a type name, or an
3098 -- access attribute.
3100 --------------------
3101 -- Same_Base_Type --
3102 --------------------
3104 function Same_Base_Type
3106 Formal : Entity_Id) return Boolean
3108 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3112 -- Case where pragma argument is typ'Access
3114 if Nkind (Ptype) = N_Attribute_Reference
3115 and then Attribute_Name (Ptype) = Name_Access
3117 Pref := Prefix (Ptype);
3120 if not Is_Entity_Name (Pref)
3121 or else Entity (Pref) = Any_Type
3126 -- We have a match if the corresponding argument is of an
3127 -- anonymous access type, and its designated type matches the
3128 -- type of the prefix of the access attribute
3130 return Ekind (Ftyp) = E_Anonymous_Access_Type
3131 and then Base_Type (Entity (Pref)) =
3132 Base_Type (Etype (Designated_Type (Ftyp)));
3134 -- Case where pragma argument is a type name
3139 if not Is_Entity_Name (Ptype)
3140 or else Entity (Ptype) = Any_Type
3145 -- We have a match if the corresponding argument is of the type
3146 -- given in the pragma (comparing base types)
3148 return Base_Type (Entity (Ptype)) = Ftyp;
3152 -- Start of processing for
3153 -- Process_Extended_Import_Export_Subprogram_Pragma
3156 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3160 -- Loop through homonyms (overloadings) of the entity
3162 Hom_Id := Entity (Arg_Internal);
3163 while Present (Hom_Id) loop
3164 Def_Id := Get_Base_Subprogram (Hom_Id);
3166 -- We need a subprogram in the current scope
3168 if not Is_Subprogram (Def_Id)
3169 or else Scope (Def_Id) /= Current_Scope
3176 -- Pragma cannot apply to subprogram body
3178 if Is_Subprogram (Def_Id)
3179 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3183 ("pragma% requires separate spec"
3184 & " and must come before body");
3187 -- Test result type if given, note that the result type
3188 -- parameter can only be present for the function cases.
3190 if Present (Arg_Result_Type)
3191 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3195 elsif Etype (Def_Id) /= Standard_Void_Type
3197 (Pname = Name_Export_Procedure
3199 Pname = Name_Import_Procedure)
3203 -- Test parameter types if given. Note that this parameter
3204 -- has not been analyzed (and must not be, since it is
3205 -- semantic nonsense), so we get it as the parser left it.
3207 elsif Present (Arg_Parameter_Types) then
3208 Check_Matching_Types : declare
3213 Formal := First_Formal (Def_Id);
3215 if Nkind (Arg_Parameter_Types) = N_Null then
3216 if Present (Formal) then
3220 -- A list of one type, e.g. (List) is parsed as
3221 -- a parenthesized expression.
3223 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3224 and then Paren_Count (Arg_Parameter_Types) = 1
3227 or else Present (Next_Formal (Formal))
3232 Same_Base_Type (Arg_Parameter_Types, Formal);
3235 -- A list of more than one type is parsed as a aggregate
3237 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3238 and then Paren_Count (Arg_Parameter_Types) = 0
3240 Ptype := First (Expressions (Arg_Parameter_Types));
3241 while Present (Ptype) or else Present (Formal) loop
3244 or else not Same_Base_Type (Ptype, Formal)
3249 Next_Formal (Formal);
3254 -- Anything else is of the wrong form
3258 ("wrong form for Parameter_Types parameter",
3259 Arg_Parameter_Types);
3261 end Check_Matching_Types;
3264 -- Match is now False if the entry we found did not match
3265 -- either a supplied Parameter_Types or Result_Types argument
3271 -- Ambiguous case, the flag Ambiguous shows if we already
3272 -- detected this and output the initial messages.
3275 if not Ambiguous then
3277 Error_Msg_Name_1 := Pname;
3279 ("pragma% does not uniquely identify subprogram!",
3281 Error_Msg_Sloc := Sloc (Ent);
3282 Error_Msg_N ("matching subprogram #!", N);
3286 Error_Msg_Sloc := Sloc (Def_Id);
3287 Error_Msg_N ("matching subprogram #!", N);
3292 Hom_Id := Homonym (Hom_Id);
3295 -- See if we found an entry
3298 if not Ambiguous then
3299 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3301 ("pragma% cannot be given for generic subprogram");
3304 ("pragma% does not identify local subprogram");
3311 -- Import pragmas must be for imported entities
3313 if Prag_Id = Pragma_Import_Function
3315 Prag_Id = Pragma_Import_Procedure
3317 Prag_Id = Pragma_Import_Valued_Procedure
3319 if not Is_Imported (Ent) then
3321 ("pragma Import or Interface must precede pragma%");
3324 -- Here we have the Export case which can set the entity as exported
3326 -- But does not do so if the specified external name is null, since
3327 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3328 -- compatible) to request no external name.
3330 elsif Nkind (Arg_External) = N_String_Literal
3331 and then String_Length (Strval (Arg_External)) = 0
3335 -- In all other cases, set entity as exported
3338 Set_Exported (Ent, Arg_Internal);
3341 -- Special processing for Valued_Procedure cases
3343 if Prag_Id = Pragma_Import_Valued_Procedure
3345 Prag_Id = Pragma_Export_Valued_Procedure
3347 Formal := First_Formal (Ent);
3350 Error_Pragma ("at least one parameter required for pragma%");
3352 elsif Ekind (Formal) /= E_Out_Parameter then
3353 Error_Pragma ("first parameter must have mode out for pragma%");
3356 Set_Is_Valued_Procedure (Ent);
3360 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3362 -- Process Result_Mechanism argument if present. We have already
3363 -- checked that this is only allowed for the function case.
3365 if Present (Arg_Result_Mechanism) then
3366 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3369 -- Process Mechanism parameter if present. Note that this parameter
3370 -- is not analyzed, and must not be analyzed since it is semantic
3371 -- nonsense, so we get it in exactly as the parser left it.
3373 if Present (Arg_Mechanism) then
3381 -- A single mechanism association without a formal parameter
3382 -- name is parsed as a parenthesized expression. All other
3383 -- cases are parsed as aggregates, so we rewrite the single
3384 -- parameter case as an aggregate for consistency.
3386 if Nkind (Arg_Mechanism) /= N_Aggregate
3387 and then Paren_Count (Arg_Mechanism) = 1
3389 Rewrite (Arg_Mechanism,
3390 Make_Aggregate (Sloc (Arg_Mechanism),
3391 Expressions => New_List (
3392 Relocate_Node (Arg_Mechanism))));
3395 -- Case of only mechanism name given, applies to all formals
3397 if Nkind (Arg_Mechanism) /= N_Aggregate then
3398 Formal := First_Formal (Ent);
3399 while Present (Formal) loop
3400 Set_Mechanism_Value (Formal, Arg_Mechanism);
3401 Next_Formal (Formal);
3404 -- Case of list of mechanism associations given
3407 if Null_Record_Present (Arg_Mechanism) then
3409 ("inappropriate form for Mechanism parameter",
3413 -- Deal with positional ones first
3415 Formal := First_Formal (Ent);
3417 if Present (Expressions (Arg_Mechanism)) then
3418 Mname := First (Expressions (Arg_Mechanism));
3419 while Present (Mname) loop
3422 ("too many mechanism associations", Mname);
3425 Set_Mechanism_Value (Formal, Mname);
3426 Next_Formal (Formal);
3431 -- Deal with named entries
3433 if Present (Component_Associations (Arg_Mechanism)) then
3434 Massoc := First (Component_Associations (Arg_Mechanism));
3435 while Present (Massoc) loop
3436 Choice := First (Choices (Massoc));
3438 if Nkind (Choice) /= N_Identifier
3439 or else Present (Next (Choice))
3442 ("incorrect form for mechanism association",
3446 Formal := First_Formal (Ent);
3450 ("parameter name & not present", Choice);
3453 if Chars (Choice) = Chars (Formal) then
3455 (Formal, Expression (Massoc));
3457 -- Set entity on identifier for ASIS
3459 Set_Entity (Choice, Formal);
3464 Next_Formal (Formal);
3474 -- Process First_Optional_Parameter argument if present. We have
3475 -- already checked that this is only allowed for the Import case.
3477 if Present (Arg_First_Optional_Parameter) then
3478 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3480 ("first optional parameter must be formal parameter name",
3481 Arg_First_Optional_Parameter);
3484 Formal := First_Formal (Ent);
3488 ("specified formal parameter& not found",
3489 Arg_First_Optional_Parameter);
3492 exit when Chars (Formal) =
3493 Chars (Arg_First_Optional_Parameter);
3495 Next_Formal (Formal);
3498 Set_First_Optional_Parameter (Ent, Formal);
3500 -- Check specified and all remaining formals have right form
3502 while Present (Formal) loop
3503 if Ekind (Formal) /= E_In_Parameter then
3505 ("optional formal& is not of mode in!",
3506 Arg_First_Optional_Parameter, Formal);
3509 Dval := Default_Value (Formal);
3513 ("optional formal& does not have default value!",
3514 Arg_First_Optional_Parameter, Formal);
3516 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3521 ("default value for optional formal& is non-static!",
3522 Arg_First_Optional_Parameter, Formal);
3526 Set_Is_Optional_Parameter (Formal);
3527 Next_Formal (Formal);
3530 end Process_Extended_Import_Export_Subprogram_Pragma;
3532 --------------------------
3533 -- Process_Generic_List --
3534 --------------------------
3536 procedure Process_Generic_List is
3541 Check_No_Identifiers;
3542 Check_At_Least_N_Arguments (1);
3545 while Present (Arg) loop
3546 Exp := Expression (Arg);
3549 if not Is_Entity_Name (Exp)
3551 (not Is_Generic_Instance (Entity (Exp))
3553 not Is_Generic_Unit (Entity (Exp)))
3556 ("pragma% argument must be name of generic unit/instance",
3562 end Process_Generic_List;
3564 ---------------------------------
3565 -- Process_Import_Or_Interface --
3566 ---------------------------------
3568 procedure Process_Import_Or_Interface is
3574 Process_Convention (C, Def_Id);
3575 Kill_Size_Check_Code (Def_Id);
3576 Note_Possible_Modification (Expression (Arg2), Sure => False);
3578 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3580 -- We do not permit Import to apply to a renaming declaration
3582 if Present (Renamed_Object (Def_Id)) then
3584 ("pragma% not allowed for object renaming", Arg2);
3586 -- User initialization is not allowed for imported object, but
3587 -- the object declaration may contain a default initialization,
3588 -- that will be discarded. Note that an explicit initialization
3589 -- only counts if it comes from source, otherwise it is simply
3590 -- the code generator making an implicit initialization explicit.
3592 elsif Present (Expression (Parent (Def_Id)))
3593 and then Comes_From_Source (Expression (Parent (Def_Id)))
3595 Error_Msg_Sloc := Sloc (Def_Id);
3597 ("no initialization allowed for declaration of& #",
3598 "\imported entities cannot be initialized (RM B.1(24))",
3602 Set_Imported (Def_Id);
3603 Process_Interface_Name (Def_Id, Arg3, Arg4);
3605 -- Note that we do not set Is_Public here. That's because we
3606 -- only want to set it if there is no address clause, and we
3607 -- don't know that yet, so we delay that processing till
3610 -- pragma Import completes deferred constants
3612 if Ekind (Def_Id) = E_Constant then
3613 Set_Has_Completion (Def_Id);
3616 -- It is not possible to import a constant of an unconstrained
3617 -- array type (e.g. string) because there is no simple way to
3618 -- write a meaningful subtype for it.
3620 if Is_Array_Type (Etype (Def_Id))
3621 and then not Is_Constrained (Etype (Def_Id))
3624 ("imported constant& must have a constrained subtype",
3629 elsif Is_Subprogram (Def_Id)
3630 or else Is_Generic_Subprogram (Def_Id)
3632 -- If the name is overloaded, pragma applies to all of the
3633 -- denoted entities in the same declarative part.
3636 while Present (Hom_Id) loop
3637 Def_Id := Get_Base_Subprogram (Hom_Id);
3639 -- Ignore inherited subprograms because the pragma will
3640 -- apply to the parent operation, which is the one called.
3642 if Is_Overloadable (Def_Id)
3643 and then Present (Alias (Def_Id))
3647 -- If it is not a subprogram, it must be in an outer scope and
3648 -- pragma does not apply.
3650 elsif not Is_Subprogram (Def_Id)
3651 and then not Is_Generic_Subprogram (Def_Id)
3655 -- Verify that the homonym is in the same declarative part (not
3656 -- just the same scope).
3658 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3659 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3664 Set_Imported (Def_Id);
3666 -- Reject an Import applied to an abstract subprogram
3668 if Is_Subprogram (Def_Id)
3669 and then Is_Abstract_Subprogram (Def_Id)
3671 Error_Msg_Sloc := Sloc (Def_Id);
3673 ("cannot import abstract subprogram& declared#",
3677 -- Special processing for Convention_Intrinsic
3679 if C = Convention_Intrinsic then
3681 -- Link_Name argument not allowed for intrinsic
3684 and then Chars (Arg3) = Name_Link_Name
3689 if Present (Arg4) then
3691 ("Link_Name argument not allowed for " &
3696 Set_Is_Intrinsic_Subprogram (Def_Id);
3698 -- If no external name is present, then check that this
3699 -- is a valid intrinsic subprogram. If an external name
3700 -- is present, then this is handled by the back end.
3703 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3707 -- All interfaced procedures need an external symbol created
3708 -- for them since they are always referenced from another
3711 Set_Is_Public (Def_Id);
3713 -- Verify that the subprogram does not have a completion
3714 -- through a renaming declaration. For other completions the
3715 -- pragma appears as a too late representation.
3718 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3722 and then Nkind (Decl) = N_Subprogram_Declaration
3723 and then Present (Corresponding_Body (Decl))
3724 and then Nkind (Unit_Declaration_Node
3725 (Corresponding_Body (Decl))) =
3726 N_Subprogram_Renaming_Declaration
3728 Error_Msg_Sloc := Sloc (Def_Id);
3730 ("cannot import&, renaming already provided for " &
3731 "declaration #", N, Def_Id);
3735 Set_Has_Completion (Def_Id);
3736 Process_Interface_Name (Def_Id, Arg3, Arg4);
3739 if Is_Compilation_Unit (Hom_Id) then
3741 -- Its possible homonyms are not affected by the pragma.
3742 -- Such homonyms might be present in the context of other
3743 -- units being compiled.
3748 Hom_Id := Homonym (Hom_Id);
3752 -- When the convention is Java or CIL, we also allow Import to be
3753 -- given for packages, generic packages, exceptions, record
3754 -- components, and access to subprograms.
3756 elsif (C = Convention_Java or else C = Convention_CIL)
3758 (Is_Package_Or_Generic_Package (Def_Id)
3759 or else Ekind (Def_Id) = E_Exception
3760 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3761 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3763 Set_Imported (Def_Id);
3764 Set_Is_Public (Def_Id);
3765 Process_Interface_Name (Def_Id, Arg3, Arg4);
3767 -- Import a CPP class
3769 elsif Is_Record_Type (Def_Id)
3770 and then C = Convention_CPP
3772 -- Types treated as CPP classes are treated as limited, but we
3773 -- don't require them to be declared this way. A warning is
3774 -- issued to encourage the user to declare them as limited.
3775 -- This is not an error, for compatibility reasons, because
3776 -- these types have been supported this way for some time.
3778 if not Is_Limited_Type (Def_Id) then
3780 ("imported 'C'P'P type should be " &
3781 "explicitly declared limited?",
3782 Get_Pragma_Arg (Arg2));
3784 ("\type will be considered limited",
3785 Get_Pragma_Arg (Arg2));
3788 Set_Is_CPP_Class (Def_Id);
3789 Set_Is_Limited_Record (Def_Id);
3791 -- Imported CPP types must not have discriminants (because C++
3792 -- classes do not have discriminants).
3794 if Has_Discriminants (Def_Id) then
3796 ("imported 'C'P'P type cannot have discriminants",
3797 First (Discriminant_Specifications
3798 (Declaration_Node (Def_Id))));
3801 -- Components of imported CPP types must not have default
3802 -- expressions because the constructor (if any) is on the
3806 Tdef : constant Node_Id :=
3807 Type_Definition (Declaration_Node (Def_Id));
3812 if Nkind (Tdef) = N_Record_Definition then
3813 Clist := Component_List (Tdef);
3816 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3817 Clist := Component_List (Record_Extension_Part (Tdef));
3820 if Present (Clist) then
3821 Comp := First (Component_Items (Clist));
3822 while Present (Comp) loop
3823 if Present (Expression (Comp)) then
3825 ("component of imported 'C'P'P type cannot have" &
3826 " default expression", Expression (Comp));
3836 ("second argument of pragma% must be object or subprogram",
3840 -- If this pragma applies to a compilation unit, then the unit, which
3841 -- is a subprogram, does not require (or allow) a body. We also do
3842 -- not need to elaborate imported procedures.
3844 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3846 Cunit : constant Node_Id := Parent (Parent (N));
3848 Set_Body_Required (Cunit, False);
3851 end Process_Import_Or_Interface;
3853 --------------------
3854 -- Process_Inline --
3855 --------------------
3857 procedure Process_Inline (Active : Boolean) is
3863 Effective : Boolean := False;
3865 procedure Make_Inline (Subp : Entity_Id);
3866 -- Subp is the defining unit name of the subprogram declaration. Set
3867 -- the flag, as well as the flag in the corresponding body, if there
3870 procedure Set_Inline_Flags (Subp : Entity_Id);
3871 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3872 -- Has_Pragma_Inline_Always for the Inline_Always case.
3874 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3875 -- Returns True if it can be determined at this stage that inlining
3876 -- is not possible, for example if the body is available and contains
3877 -- exception handlers, we prevent inlining, since otherwise we can
3878 -- get undefined symbols at link time. This function also emits a
3879 -- warning if front-end inlining is enabled and the pragma appears
3882 -- ??? is business with link symbols still valid, or does it relate
3883 -- to front end ZCX which is being phased out ???
3885 ---------------------------
3886 -- Inlining_Not_Possible --
3887 ---------------------------
3889 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3890 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3894 if Nkind (Decl) = N_Subprogram_Body then
3895 Stats := Handled_Statement_Sequence (Decl);
3896 return Present (Exception_Handlers (Stats))
3897 or else Present (At_End_Proc (Stats));
3899 elsif Nkind (Decl) = N_Subprogram_Declaration
3900 and then Present (Corresponding_Body (Decl))
3902 if Front_End_Inlining
3903 and then Analyzed (Corresponding_Body (Decl))
3905 Error_Msg_N ("pragma appears too late, ignored?", N);
3908 -- If the subprogram is a renaming as body, the body is just a
3909 -- call to the renamed subprogram, and inlining is trivially
3913 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3914 N_Subprogram_Renaming_Declaration
3920 Handled_Statement_Sequence
3921 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3924 Present (Exception_Handlers (Stats))
3925 or else Present (At_End_Proc (Stats));
3929 -- If body is not available, assume the best, the check is
3930 -- performed again when compiling enclosing package bodies.
3934 end Inlining_Not_Possible;
3940 procedure Make_Inline (Subp : Entity_Id) is
3941 Kind : constant Entity_Kind := Ekind (Subp);
3942 Inner_Subp : Entity_Id := Subp;
3945 -- Ignore if bad type, avoid cascaded error
3947 if Etype (Subp) = Any_Type then
3951 -- Ignore if all inlining is suppressed
3953 elsif Suppress_All_Inlining then
3957 -- If inlining is not possible, for now do not treat as an error
3959 elsif Inlining_Not_Possible (Subp) then
3963 -- Here we have a candidate for inlining, but we must exclude
3964 -- derived operations. Otherwise we would end up trying to inline
3965 -- a phantom declaration, and the result would be to drag in a
3966 -- body which has no direct inlining associated with it. That
3967 -- would not only be inefficient but would also result in the
3968 -- backend doing cross-unit inlining in cases where it was
3969 -- definitely inappropriate to do so.
3971 -- However, a simple Comes_From_Source test is insufficient, since
3972 -- we do want to allow inlining of generic instances which also do
3973 -- not come from source. We also need to recognize specs generated
3974 -- by the front-end for bodies that carry the pragma. Finally,
3975 -- predefined operators do not come from source but are not
3976 -- inlineable either.
3978 elsif Is_Generic_Instance (Subp)
3979 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3983 elsif not Comes_From_Source (Subp)
3984 and then Scope (Subp) /= Standard_Standard
3990 -- The referenced entity must either be the enclosing entity, or
3991 -- an entity declared within the current open scope.
3993 if Present (Scope (Subp))
3994 and then Scope (Subp) /= Current_Scope
3995 and then Subp /= Current_Scope
3998 ("argument of% must be entity in current scope", Assoc);
4002 -- Processing for procedure, operator or function. If subprogram
4003 -- is aliased (as for an instance) indicate that the renamed
4004 -- entity (if declared in the same unit) is inlined.
4006 if Is_Subprogram (Subp) then
4007 Inner_Subp := Ultimate_Alias (Inner_Subp);
4009 if In_Same_Source_Unit (Subp, Inner_Subp) then
4010 Set_Inline_Flags (Inner_Subp);
4012 Decl := Parent (Parent (Inner_Subp));
4014 if Nkind (Decl) = N_Subprogram_Declaration
4015 and then Present (Corresponding_Body (Decl))
4017 Set_Inline_Flags (Corresponding_Body (Decl));
4019 elsif Is_Generic_Instance (Subp) then
4021 -- Indicate that the body needs to be created for
4022 -- inlining subsequent calls. The instantiation node
4023 -- follows the declaration of the wrapper package
4026 if Scope (Subp) /= Standard_Standard
4028 Need_Subprogram_Instance_Body
4029 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4039 -- For a generic subprogram set flag as well, for use at the point
4040 -- of instantiation, to determine whether the body should be
4043 elsif Is_Generic_Subprogram (Subp) then
4044 Set_Inline_Flags (Subp);
4047 -- Literals are by definition inlined
4049 elsif Kind = E_Enumeration_Literal then
4052 -- Anything else is an error
4056 ("expect subprogram name for pragma%", Assoc);
4060 ----------------------
4061 -- Set_Inline_Flags --
4062 ----------------------
4064 procedure Set_Inline_Flags (Subp : Entity_Id) is
4067 Set_Is_Inlined (Subp, True);
4070 if not Has_Pragma_Inline (Subp) then
4071 Set_Has_Pragma_Inline (Subp);
4075 if Prag_Id = Pragma_Inline_Always then
4076 Set_Has_Pragma_Inline_Always (Subp);
4078 end Set_Inline_Flags;
4080 -- Start of processing for Process_Inline
4083 Check_No_Identifiers;
4084 Check_At_Least_N_Arguments (1);
4087 Inline_Processing_Required := True;
4091 while Present (Assoc) loop
4092 Subp_Id := Expression (Assoc);
4096 if Is_Entity_Name (Subp_Id) then
4097 Subp := Entity (Subp_Id);
4099 if Subp = Any_Id then
4101 -- If previous error, avoid cascaded errors
4109 while Present (Homonym (Subp))
4110 and then Scope (Homonym (Subp)) = Current_Scope
4112 Make_Inline (Homonym (Subp));
4113 Subp := Homonym (Subp);
4120 ("inappropriate argument for pragma%", Assoc);
4123 and then Warn_On_Redundant_Constructs
4124 and then not Suppress_All_Inlining
4126 if Inlining_Not_Possible (Subp) then
4128 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4131 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4139 ----------------------------
4140 -- Process_Interface_Name --
4141 ----------------------------
4143 procedure Process_Interface_Name
4144 (Subprogram_Def : Entity_Id;
4150 String_Val : String_Id;
4152 procedure Check_Form_Of_Interface_Name
4154 Ext_Name_Case : Boolean);
4155 -- SN is a string literal node for an interface name. This routine
4156 -- performs some minimal checks that the name is reasonable. In
4157 -- particular that no spaces or other obviously incorrect characters
4158 -- appear. This is only a warning, since any characters are allowed.
4159 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4161 ----------------------------------
4162 -- Check_Form_Of_Interface_Name --
4163 ----------------------------------
4165 procedure Check_Form_Of_Interface_Name
4167 Ext_Name_Case : Boolean)
4169 S : constant String_Id := Strval (Expr_Value_S (SN));
4170 SL : constant Nat := String_Length (S);
4175 Error_Msg_N ("interface name cannot be null string", SN);
4178 for J in 1 .. SL loop
4179 C := Get_String_Char (S, J);
4181 -- Look for dubious character and issue unconditional warning.
4182 -- Definitely dubious if not in character range.
4184 if not In_Character_Range (C)
4186 -- For all cases except CLI target,
4187 -- commas, spaces and slashes are dubious (in CLI, we use
4188 -- commas and backslashes in external names to specify
4189 -- assembly version and public key, while slashes and spaces
4190 -- can be used in names to mark nested classes and
4193 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4194 and then (Get_Character (C) = ','
4196 Get_Character (C) = '\'))
4197 or else (VM_Target /= CLI_Target
4198 and then (Get_Character (C) = ' '
4200 Get_Character (C) = '/'))
4203 ("?interface name contains illegal character",
4204 Sloc (SN) + Source_Ptr (J));
4207 end Check_Form_Of_Interface_Name;
4209 -- Start of processing for Process_Interface_Name
4212 if No (Link_Arg) then
4213 if No (Ext_Arg) then
4214 if VM_Target = CLI_Target
4215 and then Ekind (Subprogram_Def) = E_Package
4216 and then Nkind (Parent (Subprogram_Def)) =
4217 N_Package_Specification
4218 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4223 (Generic_Parent (Parent (Subprogram_Def))));
4228 elsif Chars (Ext_Arg) = Name_Link_Name then
4230 Link_Nam := Expression (Ext_Arg);
4233 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4234 Ext_Nam := Expression (Ext_Arg);
4239 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4240 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4241 Ext_Nam := Expression (Ext_Arg);
4242 Link_Nam := Expression (Link_Arg);
4245 -- Check expressions for external name and link name are static
4247 if Present (Ext_Nam) then
4248 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4249 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4251 -- Verify that external name is not the name of a local entity,
4252 -- which would hide the imported one and could lead to run-time
4253 -- surprises. The problem can only arise for entities declared in
4254 -- a package body (otherwise the external name is fully qualified
4255 -- and will not conflict).
4263 if Prag_Id = Pragma_Import then
4264 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4266 E := Entity_Id (Get_Name_Table_Info (Nam));
4268 if Nam /= Chars (Subprogram_Def)
4269 and then Present (E)
4270 and then not Is_Overloadable (E)
4271 and then Is_Immediately_Visible (E)
4272 and then not Is_Imported (E)
4273 and then Ekind (Scope (E)) = E_Package
4276 while Present (Par) loop
4277 if Nkind (Par) = N_Package_Body then
4278 Error_Msg_Sloc := Sloc (E);
4280 ("imported entity is hidden by & declared#",
4285 Par := Parent (Par);
4292 if Present (Link_Nam) then
4293 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4294 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4297 -- If there is no link name, just set the external name
4299 if No (Link_Nam) then
4300 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4302 -- For the Link_Name case, the given literal is preceded by an
4303 -- asterisk, which indicates to GCC that the given name should be
4304 -- taken literally, and in particular that no prepending of
4305 -- underlines should occur, even in systems where this is the
4311 if VM_Target = No_VM then
4312 Store_String_Char (Get_Char_Code ('*'));
4315 String_Val := Strval (Expr_Value_S (Link_Nam));
4316 Store_String_Chars (String_Val);
4318 Make_String_Literal (Sloc (Link_Nam),
4319 Strval => End_String);
4322 Set_Encoded_Interface_Name
4323 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4325 -- We allow duplicated export names in CIL, as they are always
4326 -- enclosed in a namespace that differentiates them, and overloaded
4327 -- entities are supported by the VM.
4329 if Convention (Subprogram_Def) /= Convention_CIL then
4330 Check_Duplicated_Export_Name (Link_Nam);
4332 end Process_Interface_Name;
4334 -----------------------------------------
4335 -- Process_Interrupt_Or_Attach_Handler --
4336 -----------------------------------------
4338 procedure Process_Interrupt_Or_Attach_Handler is
4339 Arg1_X : constant Node_Id := Expression (Arg1);
4340 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4341 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4344 Set_Is_Interrupt_Handler (Handler_Proc);
4346 -- If the pragma is not associated with a handler procedure within a
4347 -- protected type, then it must be for a nonprotected procedure for
4348 -- the AAMP target, in which case we don't associate a representation
4349 -- item with the procedure's scope.
4351 if Ekind (Proc_Scope) = E_Protected_Type then
4352 if Prag_Id = Pragma_Interrupt_Handler
4354 Prag_Id = Pragma_Attach_Handler
4356 Record_Rep_Item (Proc_Scope, N);
4359 end Process_Interrupt_Or_Attach_Handler;
4361 --------------------------------------------------
4362 -- Process_Restrictions_Or_Restriction_Warnings --
4363 --------------------------------------------------
4365 -- Note: some of the simple identifier cases were handled in par-prag,
4366 -- but it is harmless (and more straightforward) to simply handle all
4367 -- cases here, even if it means we repeat a bit of work in some cases.
4369 procedure Process_Restrictions_Or_Restriction_Warnings
4373 R_Id : Restriction_Id;
4378 procedure Check_Unit_Name (N : Node_Id);
4379 -- Checks unit name parameter for No_Dependence. Returns if it has
4380 -- an appropriate form, otherwise raises pragma argument error.
4382 ---------------------
4383 -- Check_Unit_Name --
4384 ---------------------
4386 procedure Check_Unit_Name (N : Node_Id) is
4388 if Nkind (N) = N_Selected_Component then
4389 Check_Unit_Name (Prefix (N));
4390 Check_Unit_Name (Selector_Name (N));
4392 elsif Nkind (N) = N_Identifier then
4397 ("wrong form for unit name for No_Dependence", N);
4399 end Check_Unit_Name;
4401 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4404 Check_Ada_83_Warning;
4405 Check_At_Least_N_Arguments (1);
4406 Check_Valid_Configuration_Pragma;
4409 while Present (Arg) loop
4411 Expr := Expression (Arg);
4413 -- Case of no restriction identifier present
4415 if Id = No_Name then
4416 if Nkind (Expr) /= N_Identifier then
4418 ("invalid form for restriction", Arg);
4423 (Process_Restriction_Synonyms (Expr));
4425 if R_Id not in All_Boolean_Restrictions then
4426 Error_Msg_Name_1 := Pname;
4428 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4430 -- Check for possible misspelling
4432 for J in Restriction_Id loop
4434 Rnm : constant String := Restriction_Id'Image (J);
4437 Name_Buffer (1 .. Rnm'Length) := Rnm;
4438 Name_Len := Rnm'Length;
4439 Set_Casing (All_Lower_Case);
4441 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4443 (Identifier_Casing (Current_Source_File));
4444 Error_Msg_String (1 .. Rnm'Length) :=
4445 Name_Buffer (1 .. Name_Len);
4446 Error_Msg_Strlen := Rnm'Length;
4447 Error_Msg_N -- CODEFIX
4448 ("\possible misspelling of ""~""",
4449 Get_Pragma_Arg (Arg));
4458 if Implementation_Restriction (R_Id) then
4459 Check_Restriction (No_Implementation_Restrictions, Arg);
4462 -- If this is a warning, then set the warning unless we already
4463 -- have a real restriction active (we never want a warning to
4464 -- override a real restriction).
4467 if not Restriction_Active (R_Id) then
4468 Set_Restriction (R_Id, N);
4469 Restriction_Warnings (R_Id) := True;
4472 -- If real restriction case, then set it and make sure that the
4473 -- restriction warning flag is off, since a real restriction
4474 -- always overrides a warning.
4477 Set_Restriction (R_Id, N);
4478 Restriction_Warnings (R_Id) := False;
4481 -- Check for obsolescent restrictions in Ada 2005 mode
4484 and then Ada_Version >= Ada_2005
4485 and then (R_Id = No_Asynchronous_Control
4487 R_Id = No_Unchecked_Deallocation
4489 R_Id = No_Unchecked_Conversion)
4491 Check_Restriction (No_Obsolescent_Features, N);
4494 -- A very special case that must be processed here: pragma
4495 -- Restrictions (No_Exceptions) turns off all run-time
4496 -- checking. This is a bit dubious in terms of the formal
4497 -- language definition, but it is what is intended by RM
4498 -- H.4(12). Restriction_Warnings never affects generated code
4499 -- so this is done only in the real restriction case.
4501 if R_Id = No_Exceptions and then not Warn then
4502 Scope_Suppress := (others => True);
4505 -- Case of No_Dependence => unit-name. Note that the parser
4506 -- already made the necessary entry in the No_Dependence table.
4508 elsif Id = Name_No_Dependence then
4509 Check_Unit_Name (Expr);
4511 -- All other cases of restriction identifier present
4514 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4515 Analyze_And_Resolve (Expr, Any_Integer);
4517 if R_Id not in All_Parameter_Restrictions then
4519 ("invalid restriction parameter identifier", Arg);
4521 elsif not Is_OK_Static_Expression (Expr) then
4522 Flag_Non_Static_Expr
4523 ("value must be static expression!", Expr);
4526 elsif not Is_Integer_Type (Etype (Expr))
4527 or else Expr_Value (Expr) < 0
4530 ("value must be non-negative integer", Arg);
4533 -- Restriction pragma is active
4535 Val := Expr_Value (Expr);
4537 if not UI_Is_In_Int_Range (Val) then
4539 ("pragma ignored, value too large?", Arg);
4542 -- Warning case. If the real restriction is active, then we
4543 -- ignore the request, since warning never overrides a real
4544 -- restriction. Otherwise we set the proper warning. Note that
4545 -- this circuit sets the warning again if it is already set,
4546 -- which is what we want, since the constant may have changed.
4549 if not Restriction_Active (R_Id) then
4551 (R_Id, N, Integer (UI_To_Int (Val)));
4552 Restriction_Warnings (R_Id) := True;
4555 -- Real restriction case, set restriction and make sure warning
4556 -- flag is off since real restriction always overrides warning.
4559 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4560 Restriction_Warnings (R_Id) := False;
4566 end Process_Restrictions_Or_Restriction_Warnings;
4568 ---------------------------------
4569 -- Process_Suppress_Unsuppress --
4570 ---------------------------------
4572 -- Note: this procedure makes entries in the check suppress data
4573 -- structures managed by Sem. See spec of package Sem for full
4574 -- details on how we handle recording of check suppression.
4576 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4581 In_Package_Spec : constant Boolean :=
4582 Is_Package_Or_Generic_Package (Current_Scope)
4583 and then not In_Package_Body (Current_Scope);
4585 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4586 -- Used to suppress a single check on the given entity
4588 --------------------------------
4589 -- Suppress_Unsuppress_Echeck --
4590 --------------------------------
4592 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4594 Set_Checks_May_Be_Suppressed (E);
4596 if In_Package_Spec then
4597 Push_Global_Suppress_Stack_Entry
4600 Suppress => Suppress_Case);
4603 Push_Local_Suppress_Stack_Entry
4606 Suppress => Suppress_Case);
4609 -- If this is a first subtype, and the base type is distinct,
4610 -- then also set the suppress flags on the base type.
4612 if Is_First_Subtype (E)
4613 and then Etype (E) /= E
4615 Suppress_Unsuppress_Echeck (Etype (E), C);
4617 end Suppress_Unsuppress_Echeck;
4619 -- Start of processing for Process_Suppress_Unsuppress
4622 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4623 -- declarative part or a package spec (RM 11.5(5)).
4625 if not Is_Configuration_Pragma then
4626 Check_Is_In_Decl_Part_Or_Package_Spec;
4629 Check_At_Least_N_Arguments (1);
4630 Check_At_Most_N_Arguments (2);
4631 Check_No_Identifier (Arg1);
4632 Check_Arg_Is_Identifier (Arg1);
4634 C := Get_Check_Id (Chars (Expression (Arg1)));
4636 if C = No_Check_Id then
4638 ("argument of pragma% is not valid check name", Arg1);
4641 if not Suppress_Case
4642 and then (C = All_Checks or else C = Overflow_Check)
4644 Opt.Overflow_Checks_Unsuppressed := True;
4647 if Arg_Count = 1 then
4649 -- Make an entry in the local scope suppress table. This is the
4650 -- table that directly shows the current value of the scope
4651 -- suppress check for any check id value.
4653 if C = All_Checks then
4655 -- For All_Checks, we set all specific predefined checks with
4656 -- the exception of Elaboration_Check, which is handled
4657 -- specially because of not wanting All_Checks to have the
4658 -- effect of deactivating static elaboration order processing.
4660 for J in Scope_Suppress'Range loop
4661 if J /= Elaboration_Check then
4662 Scope_Suppress (J) := Suppress_Case;
4666 -- If not All_Checks, and predefined check, then set appropriate
4667 -- scope entry. Note that we will set Elaboration_Check if this
4668 -- is explicitly specified.
4670 elsif C in Predefined_Check_Id then
4671 Scope_Suppress (C) := Suppress_Case;
4674 -- Also make an entry in the Local_Entity_Suppress table
4676 Push_Local_Suppress_Stack_Entry
4679 Suppress => Suppress_Case);
4681 -- Case of two arguments present, where the check is suppressed for
4682 -- a specified entity (given as the second argument of the pragma)
4685 -- This is obsolescent in Ada 2005 mode
4687 if Ada_Version >= Ada_2005 then
4688 Check_Restriction (No_Obsolescent_Features, Arg2);
4691 Check_Optional_Identifier (Arg2, Name_On);
4692 E_Id := Expression (Arg2);
4695 if not Is_Entity_Name (E_Id) then
4697 ("second argument of pragma% must be entity name", Arg2);
4706 -- Enforce RM 11.5(7) which requires that for a pragma that
4707 -- appears within a package spec, the named entity must be
4708 -- within the package spec. We allow the package name itself
4709 -- to be mentioned since that makes sense, although it is not
4710 -- strictly allowed by 11.5(7).
4713 and then E /= Current_Scope
4714 and then Scope (E) /= Current_Scope
4717 ("entity in pragma% is not in package spec (RM 11.5(7))",
4721 -- Loop through homonyms. As noted below, in the case of a package
4722 -- spec, only homonyms within the package spec are considered.
4725 Suppress_Unsuppress_Echeck (E, C);
4727 if Is_Generic_Instance (E)
4728 and then Is_Subprogram (E)
4729 and then Present (Alias (E))
4731 Suppress_Unsuppress_Echeck (Alias (E), C);
4734 -- Move to next homonym
4739 -- If we are within a package specification, the pragma only
4740 -- applies to homonyms in the same scope.
4742 exit when In_Package_Spec
4743 and then Scope (E) /= Current_Scope;
4746 end Process_Suppress_Unsuppress;
4752 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4754 if Is_Imported (E) then
4756 ("cannot export entity& that was previously imported", Arg);
4758 elsif Present (Address_Clause (E)) then
4760 ("cannot export entity& that has an address clause", Arg);
4763 Set_Is_Exported (E);
4765 -- Generate a reference for entity explicitly, because the
4766 -- identifier may be overloaded and name resolution will not
4769 Generate_Reference (E, Arg);
4771 -- Deal with exporting non-library level entity
4773 if not Is_Library_Level_Entity (E) then
4775 -- Not allowed at all for subprograms
4777 if Is_Subprogram (E) then
4778 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4780 -- Otherwise set public and statically allocated
4784 Set_Is_Statically_Allocated (E);
4786 -- Warn if the corresponding W flag is set and the pragma comes
4787 -- from source. The latter may not be true e.g. on VMS where we
4788 -- expand export pragmas for exception codes associated with
4789 -- imported or exported exceptions. We do not want to generate
4790 -- a warning for something that the user did not write.
4792 if Warn_On_Export_Import
4793 and then Comes_From_Source (Arg)
4796 ("?& has been made static as a result of Export", Arg, E);
4798 ("\this usage is non-standard and non-portable", Arg);
4803 if Warn_On_Export_Import and then Is_Type (E) then
4804 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
4807 if Warn_On_Export_Import and Inside_A_Generic then
4809 ("all instances of& will have the same external name?", Arg, E);
4813 ----------------------------------------------
4814 -- Set_Extended_Import_Export_External_Name --
4815 ----------------------------------------------
4817 procedure Set_Extended_Import_Export_External_Name
4818 (Internal_Ent : Entity_Id;
4819 Arg_External : Node_Id)
4821 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4825 if No (Arg_External) then
4829 Check_Arg_Is_External_Name (Arg_External);
4831 if Nkind (Arg_External) = N_String_Literal then
4832 if String_Length (Strval (Arg_External)) = 0 then
4835 New_Name := Adjust_External_Name_Case (Arg_External);
4838 elsif Nkind (Arg_External) = N_Identifier then
4839 New_Name := Get_Default_External_Name (Arg_External);
4841 -- Check_Arg_Is_External_Name should let through only identifiers and
4842 -- string literals or static string expressions (which are folded to
4843 -- string literals).
4846 raise Program_Error;
4849 -- If we already have an external name set (by a prior normal Import
4850 -- or Export pragma), then the external names must match
4852 if Present (Interface_Name (Internal_Ent)) then
4853 Check_Matching_Internal_Names : declare
4854 S1 : constant String_Id := Strval (Old_Name);
4855 S2 : constant String_Id := Strval (New_Name);
4858 -- Called if names do not match
4864 procedure Mismatch is
4866 Error_Msg_Sloc := Sloc (Old_Name);
4868 ("external name does not match that given #",
4872 -- Start of processing for Check_Matching_Internal_Names
4875 if String_Length (S1) /= String_Length (S2) then
4879 for J in 1 .. String_Length (S1) loop
4880 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4885 end Check_Matching_Internal_Names;
4887 -- Otherwise set the given name
4890 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4891 Check_Duplicated_Export_Name (New_Name);
4893 end Set_Extended_Import_Export_External_Name;
4899 procedure Set_Imported (E : Entity_Id) is
4901 -- Error message if already imported or exported
4903 if Is_Exported (E) or else Is_Imported (E) then
4905 -- Error if being set Exported twice
4907 if Is_Exported (E) then
4908 Error_Msg_NE ("entity& was previously exported", N, E);
4910 -- OK if Import/Interface case
4912 elsif Import_Interface_Present (N) then
4915 -- Error if being set Imported twice
4918 Error_Msg_NE ("entity& was previously imported", N, E);
4921 Error_Msg_Name_1 := Pname;
4923 ("\(pragma% applies to all previous entities)", N);
4925 Error_Msg_Sloc := Sloc (E);
4926 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4928 -- Here if not previously imported or exported, OK to import
4931 Set_Is_Imported (E);
4933 -- If the entity is an object that is not at the library level,
4934 -- then it is statically allocated. We do not worry about objects
4935 -- with address clauses in this context since they are not really
4936 -- imported in the linker sense.
4939 and then not Is_Library_Level_Entity (E)
4940 and then No (Address_Clause (E))
4942 Set_Is_Statically_Allocated (E);
4949 -------------------------
4950 -- Set_Mechanism_Value --
4951 -------------------------
4953 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4954 -- analyzed, since it is semantic nonsense), so we get it in the exact
4955 -- form created by the parser.
4957 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4960 Mech_Name_Id : Name_Id;
4962 procedure Bad_Class;
4963 -- Signal bad descriptor class name
4965 procedure Bad_Mechanism;
4966 -- Signal bad mechanism name
4972 procedure Bad_Class is
4974 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4977 -------------------------
4978 -- Bad_Mechanism_Value --
4979 -------------------------
4981 procedure Bad_Mechanism is
4983 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4986 -- Start of processing for Set_Mechanism_Value
4989 if Mechanism (Ent) /= Default_Mechanism then
4991 ("mechanism for & has already been set", Mech_Name, Ent);
4994 -- MECHANISM_NAME ::= value | reference | descriptor |
4997 if Nkind (Mech_Name) = N_Identifier then
4998 if Chars (Mech_Name) = Name_Value then
4999 Set_Mechanism (Ent, By_Copy);
5002 elsif Chars (Mech_Name) = Name_Reference then
5003 Set_Mechanism (Ent, By_Reference);
5006 elsif Chars (Mech_Name) = Name_Descriptor then
5007 Check_VMS (Mech_Name);
5009 -- Descriptor => Short_Descriptor if pragma was given
5011 if Short_Descriptors then
5012 Set_Mechanism (Ent, By_Short_Descriptor);
5014 Set_Mechanism (Ent, By_Descriptor);
5019 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5020 Check_VMS (Mech_Name);
5021 Set_Mechanism (Ent, By_Short_Descriptor);
5024 elsif Chars (Mech_Name) = Name_Copy then
5026 ("bad mechanism name, Value assumed", Mech_Name);
5032 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5033 -- short_descriptor (CLASS_NAME)
5034 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5036 -- Note: this form is parsed as an indexed component
5038 elsif Nkind (Mech_Name) = N_Indexed_Component then
5039 Class := First (Expressions (Mech_Name));
5041 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5042 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5043 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5044 or else Present (Next (Class))
5048 Mech_Name_Id := Chars (Prefix (Mech_Name));
5050 -- Change Descriptor => Short_Descriptor if pragma was given
5052 if Mech_Name_Id = Name_Descriptor
5053 and then Short_Descriptors
5055 Mech_Name_Id := Name_Short_Descriptor;
5059 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5060 -- short_descriptor (Class => CLASS_NAME)
5061 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5063 -- Note: this form is parsed as a function call
5065 elsif Nkind (Mech_Name) = N_Function_Call then
5066 Param := First (Parameter_Associations (Mech_Name));
5068 if Nkind (Name (Mech_Name)) /= N_Identifier
5069 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5070 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5071 or else Present (Next (Param))
5072 or else No (Selector_Name (Param))
5073 or else Chars (Selector_Name (Param)) /= Name_Class
5077 Class := Explicit_Actual_Parameter (Param);
5078 Mech_Name_Id := Chars (Name (Mech_Name));
5085 -- Fall through here with Class set to descriptor class name
5087 Check_VMS (Mech_Name);
5089 if Nkind (Class) /= N_Identifier then
5092 elsif Mech_Name_Id = Name_Descriptor
5093 and then Chars (Class) = Name_UBS
5095 Set_Mechanism (Ent, By_Descriptor_UBS);
5097 elsif Mech_Name_Id = Name_Descriptor
5098 and then Chars (Class) = Name_UBSB
5100 Set_Mechanism (Ent, By_Descriptor_UBSB);
5102 elsif Mech_Name_Id = Name_Descriptor
5103 and then Chars (Class) = Name_UBA
5105 Set_Mechanism (Ent, By_Descriptor_UBA);
5107 elsif Mech_Name_Id = Name_Descriptor
5108 and then Chars (Class) = Name_S
5110 Set_Mechanism (Ent, By_Descriptor_S);
5112 elsif Mech_Name_Id = Name_Descriptor
5113 and then Chars (Class) = Name_SB
5115 Set_Mechanism (Ent, By_Descriptor_SB);
5117 elsif Mech_Name_Id = Name_Descriptor
5118 and then Chars (Class) = Name_A
5120 Set_Mechanism (Ent, By_Descriptor_A);
5122 elsif Mech_Name_Id = Name_Descriptor
5123 and then Chars (Class) = Name_NCA
5125 Set_Mechanism (Ent, By_Descriptor_NCA);
5127 elsif Mech_Name_Id = Name_Short_Descriptor
5128 and then Chars (Class) = Name_UBS
5130 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5132 elsif Mech_Name_Id = Name_Short_Descriptor
5133 and then Chars (Class) = Name_UBSB
5135 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5137 elsif Mech_Name_Id = Name_Short_Descriptor
5138 and then Chars (Class) = Name_UBA
5140 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5142 elsif Mech_Name_Id = Name_Short_Descriptor
5143 and then Chars (Class) = Name_S
5145 Set_Mechanism (Ent, By_Short_Descriptor_S);
5147 elsif Mech_Name_Id = Name_Short_Descriptor
5148 and then Chars (Class) = Name_SB
5150 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5152 elsif Mech_Name_Id = Name_Short_Descriptor
5153 and then Chars (Class) = Name_A
5155 Set_Mechanism (Ent, By_Short_Descriptor_A);
5157 elsif Mech_Name_Id = Name_Short_Descriptor
5158 and then Chars (Class) = Name_NCA
5160 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5165 end Set_Mechanism_Value;
5167 ---------------------------
5168 -- Set_Ravenscar_Profile --
5169 ---------------------------
5171 -- The tasks to be done here are
5173 -- Set required policies
5175 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5176 -- pragma Locking_Policy (Ceiling_Locking)
5178 -- Set Detect_Blocking mode
5180 -- Set required restrictions (see System.Rident for detailed list)
5182 procedure Set_Ravenscar_Profile (N : Node_Id) is
5184 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5186 if Task_Dispatching_Policy /= ' '
5187 and then Task_Dispatching_Policy /= 'F'
5189 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5190 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5192 -- Set the FIFO_Within_Priorities policy, but always preserve
5193 -- System_Location since we like the error message with the run time
5197 Task_Dispatching_Policy := 'F';
5199 if Task_Dispatching_Policy_Sloc /= System_Location then
5200 Task_Dispatching_Policy_Sloc := Loc;
5204 -- pragma Locking_Policy (Ceiling_Locking)
5206 if Locking_Policy /= ' '
5207 and then Locking_Policy /= 'C'
5209 Error_Msg_Sloc := Locking_Policy_Sloc;
5210 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5212 -- Set the Ceiling_Locking policy, but preserve System_Location since
5213 -- we like the error message with the run time name.
5216 Locking_Policy := 'C';
5218 if Locking_Policy_Sloc /= System_Location then
5219 Locking_Policy_Sloc := Loc;
5223 -- pragma Detect_Blocking
5225 Detect_Blocking := True;
5227 -- Set the corresponding restrictions
5229 Set_Profile_Restrictions
5230 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5231 end Set_Ravenscar_Profile;
5233 -- Start of processing for Analyze_Pragma
5236 -- Deal with unrecognized pragma
5238 if not Is_Pragma_Name (Pname) then
5239 if Warn_On_Unrecognized_Pragma then
5240 Error_Msg_Name_1 := Pname;
5241 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5243 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5244 if Is_Bad_Spelling_Of (Pname, PN) then
5245 Error_Msg_Name_1 := PN;
5246 Error_Msg_N -- CODEFIX
5247 ("\?possible misspelling of %!", Pragma_Identifier (N));
5256 -- Here to start processing for recognized pragma
5258 Prag_Id := Get_Pragma_Id (Pname);
5267 if Present (Pragma_Argument_Associations (N)) then
5268 Arg1 := First (Pragma_Argument_Associations (N));
5270 if Present (Arg1) then
5271 Arg2 := Next (Arg1);
5273 if Present (Arg2) then
5274 Arg3 := Next (Arg2);
5276 if Present (Arg3) then
5277 Arg4 := Next (Arg3);
5283 -- Count number of arguments
5290 while Present (Arg_Node) loop
5291 Arg_Count := Arg_Count + 1;
5296 -- An enumeration type defines the pragmas that are supported by the
5297 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5298 -- into the corresponding enumeration value for the following case.
5306 -- pragma Abort_Defer;
5308 when Pragma_Abort_Defer =>
5310 Check_Arg_Count (0);
5312 -- The only required semantic processing is to check the
5313 -- placement. This pragma must appear at the start of the
5314 -- statement sequence of a handled sequence of statements.
5316 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5317 or else N /= First (Statements (Parent (N)))
5328 -- Note: this pragma also has some specific processing in Par.Prag
5329 -- because we want to set the Ada version mode during parsing.
5331 when Pragma_Ada_83 =>
5333 Check_Arg_Count (0);
5335 -- We really should check unconditionally for proper configuration
5336 -- pragma placement, since we really don't want mixed Ada modes
5337 -- within a single unit, and the GNAT reference manual has always
5338 -- said this was a configuration pragma, but we did not check and
5339 -- are hesitant to add the check now.
5341 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5342 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5343 -- or Ada 2012 mode.
5345 if Ada_Version >= Ada_05 then
5346 Check_Valid_Configuration_Pragma;
5349 -- Now set Ada 83 mode
5351 Ada_Version := Ada_83;
5352 Ada_Version_Explicit := Ada_Version;
5360 -- Note: this pragma also has some specific processing in Par.Prag
5361 -- because we want to set the Ada 83 version mode during parsing.
5363 when Pragma_Ada_95 =>
5365 Check_Arg_Count (0);
5367 -- We really should check unconditionally for proper configuration
5368 -- pragma placement, since we really don't want mixed Ada modes
5369 -- within a single unit, and the GNAT reference manual has always
5370 -- said this was a configuration pragma, but we did not check and
5371 -- are hesitant to add the check now.
5373 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5374 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5376 if Ada_Version >= Ada_05 then
5377 Check_Valid_Configuration_Pragma;
5380 -- Now set Ada 95 mode
5382 Ada_Version := Ada_95;
5383 Ada_Version_Explicit := Ada_Version;
5385 ---------------------
5386 -- Ada_05/Ada_2005 --
5387 ---------------------
5390 -- pragma Ada_05 (LOCAL_NAME);
5393 -- pragma Ada_2005 (LOCAL_NAME):
5395 -- Note: these pragmas also have some specific processing in Par.Prag
5396 -- because we want to set the Ada 2005 version mode during parsing.
5398 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5404 if Arg_Count = 1 then
5405 Check_Arg_Is_Local_Name (Arg1);
5406 E_Id := Expression (Arg1);
5408 if Etype (E_Id) = Any_Type then
5412 Set_Is_Ada_2005_Only (Entity (E_Id));
5415 Check_Arg_Count (0);
5417 -- For Ada_2005 we unconditionally enforce the documented
5418 -- configuration pragma placement, since we do not want to
5419 -- tolerate mixed modes in a unit involving Ada 2005. That
5420 -- would cause real difficulties for those cases where there
5421 -- are incompatibilities between Ada 95 and Ada 2005.
5423 Check_Valid_Configuration_Pragma;
5425 -- Now set Ada 2005 mode
5427 Ada_Version := Ada_05;
5428 Ada_Version_Explicit := Ada_05;
5432 ---------------------
5433 -- Ada_12/Ada_2012 --
5434 ---------------------
5437 -- pragma Ada_12 (LOCAL_NAME);
5440 -- pragma Ada_2012 (LOCAL_NAME):
5442 -- Note: these pragmas also have some specific processing in Par.Prag
5443 -- because we want to set the Ada 2012 version mode during parsing.
5445 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5451 if Arg_Count = 1 then
5452 Check_Arg_Is_Local_Name (Arg1);
5453 E_Id := Expression (Arg1);
5455 if Etype (E_Id) = Any_Type then
5459 Set_Is_Ada_2012_Only (Entity (E_Id));
5462 Check_Arg_Count (0);
5464 -- For Ada_2012 we unconditionally enforce the documented
5465 -- configuration pragma placement, since we do not want to
5466 -- tolerate mixed modes in a unit involving Ada 2012. That
5467 -- would cause real difficulties for those cases where there
5468 -- are incompatibilities between Ada 95 and Ada 2012. We could
5469 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5471 Check_Valid_Configuration_Pragma;
5473 -- Now set Ada 2012 mode
5475 Ada_Version := Ada_12;
5476 Ada_Version_Explicit := Ada_12;
5480 ----------------------
5481 -- All_Calls_Remote --
5482 ----------------------
5484 -- pragma All_Calls_Remote [(library_package_NAME)];
5486 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5487 Lib_Entity : Entity_Id;
5490 Check_Ada_83_Warning;
5491 Check_Valid_Library_Unit_Pragma;
5493 if Nkind (N) = N_Null_Statement then
5497 Lib_Entity := Find_Lib_Unit_Name;
5499 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5501 if Present (Lib_Entity)
5502 and then not Debug_Flag_U
5504 if not Is_Remote_Call_Interface (Lib_Entity) then
5505 Error_Pragma ("pragma% only apply to rci unit");
5507 -- Set flag for entity of the library unit
5510 Set_Has_All_Calls_Remote (Lib_Entity);
5514 end All_Calls_Remote;
5520 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
5521 -- ARG ::= NAME | EXPRESSION
5523 -- The first two arguments are by convention intended to refer to an
5524 -- external tool and a tool-specific function. These arguments are
5527 when Pragma_Annotate => Annotate : begin
5529 Check_At_Least_N_Arguments (1);
5530 Check_Arg_Is_Identifier (Arg1);
5531 Check_No_Identifiers;
5539 -- Second unanalyzed parameter is optional
5545 while Present (Arg) loop
5546 Exp := Expression (Arg);
5549 if Is_Entity_Name (Exp) then
5552 -- For string literals, we assume Standard_String as the
5553 -- type, unless the string contains wide or wide_wide
5556 elsif Nkind (Exp) = N_String_Literal then
5557 if Has_Wide_Wide_Character (Exp) then
5558 Resolve (Exp, Standard_Wide_Wide_String);
5559 elsif Has_Wide_Character (Exp) then
5560 Resolve (Exp, Standard_Wide_String);
5562 Resolve (Exp, Standard_String);
5565 elsif Is_Overloaded (Exp) then
5567 ("ambiguous argument for pragma%", Exp);
5583 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5584 -- [, [Message =>] Static_String_EXPRESSION]);
5586 when Pragma_Assert => Assert : declare
5592 Check_At_Least_N_Arguments (1);
5593 Check_At_Most_N_Arguments (2);
5594 Check_Arg_Order ((Name_Check, Name_Message));
5595 Check_Optional_Identifier (Arg1, Name_Check);
5597 -- We treat pragma Assert as equivalent to:
5599 -- pragma Check (Assertion, condition [, msg]);
5601 -- So rewrite pragma in this manner, and analyze the result
5603 Expr := Get_Pragma_Arg (Arg1);
5605 Make_Pragma_Argument_Association (Loc,
5607 Make_Identifier (Loc,
5608 Chars => Name_Assertion)),
5610 Make_Pragma_Argument_Association (Sloc (Expr),
5611 Expression => Expr));
5613 if Arg_Count > 1 then
5614 Check_Optional_Identifier (Arg2, Name_Message);
5615 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5616 Append_To (Newa, Relocate_Node (Arg2));
5621 Chars => Name_Check,
5622 Pragma_Argument_Associations => Newa));
5626 ----------------------
5627 -- Assertion_Policy --
5628 ----------------------
5630 -- pragma Assertion_Policy (Check | Ignore)
5632 when Pragma_Assertion_Policy => Assertion_Policy : declare
5637 Check_Valid_Configuration_Pragma;
5638 Check_Arg_Count (1);
5639 Check_No_Identifiers;
5640 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5642 -- We treat pragma Assertion_Policy as equivalent to:
5644 -- pragma Check_Policy (Assertion, policy)
5646 -- So rewrite the pragma in that manner and link on to the chain
5647 -- of Check_Policy pragmas, marking the pragma as analyzed.
5649 Policy := Get_Pragma_Arg (Arg1);
5653 Chars => Name_Check_Policy,
5655 Pragma_Argument_Associations => New_List (
5656 Make_Pragma_Argument_Association (Loc,
5658 Make_Identifier (Loc,
5659 Chars => Name_Assertion)),
5661 Make_Pragma_Argument_Association (Loc,
5663 Make_Identifier (Sloc (Policy),
5664 Chars => Chars (Policy))))));
5667 Set_Next_Pragma (N, Opt.Check_Policy_List);
5668 Opt.Check_Policy_List := N;
5669 end Assertion_Policy;
5671 ------------------------------
5672 -- Assume_No_Invalid_Values --
5673 ------------------------------
5675 -- pragma Assume_No_Invalid_Values (On | Off);
5677 when Pragma_Assume_No_Invalid_Values =>
5679 Check_Valid_Configuration_Pragma;
5680 Check_Arg_Count (1);
5681 Check_No_Identifiers;
5682 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5684 if Chars (Expression (Arg1)) = Name_On then
5685 Assume_No_Invalid_Values := True;
5687 Assume_No_Invalid_Values := False;
5694 -- pragma AST_Entry (entry_IDENTIFIER);
5696 when Pragma_AST_Entry => AST_Entry : declare
5702 Check_Arg_Count (1);
5703 Check_No_Identifiers;
5704 Check_Arg_Is_Local_Name (Arg1);
5705 Ent := Entity (Expression (Arg1));
5707 -- Note: the implementation of the AST_Entry pragma could handle
5708 -- the entry family case fine, but for now we are consistent with
5709 -- the DEC rules, and do not allow the pragma, which of course
5710 -- has the effect of also forbidding the attribute.
5712 if Ekind (Ent) /= E_Entry then
5714 ("pragma% argument must be simple entry name", Arg1);
5716 elsif Is_AST_Entry (Ent) then
5718 ("duplicate % pragma for entry", Arg1);
5720 elsif Has_Homonym (Ent) then
5722 ("pragma% argument cannot specify overloaded entry", Arg1);
5726 FF : constant Entity_Id := First_Formal (Ent);
5729 if Present (FF) then
5730 if Present (Next_Formal (FF)) then
5732 ("entry for pragma% can have only one argument",
5735 elsif Parameter_Mode (FF) /= E_In_Parameter then
5737 ("entry parameter for pragma% must have mode IN",
5743 Set_Is_AST_Entry (Ent);
5751 -- pragma Asynchronous (LOCAL_NAME);
5753 when Pragma_Asynchronous => Asynchronous : declare
5761 procedure Process_Async_Pragma;
5762 -- Common processing for procedure and access-to-procedure case
5764 --------------------------
5765 -- Process_Async_Pragma --
5766 --------------------------
5768 procedure Process_Async_Pragma is
5771 Set_Is_Asynchronous (Nm);
5775 -- The formals should be of mode IN (RM E.4.1(6))
5778 while Present (S) loop
5779 Formal := Defining_Identifier (S);
5781 if Nkind (Formal) = N_Defining_Identifier
5782 and then Ekind (Formal) /= E_In_Parameter
5785 ("pragma% procedure can only have IN parameter",
5792 Set_Is_Asynchronous (Nm);
5793 end Process_Async_Pragma;
5795 -- Start of processing for pragma Asynchronous
5798 Check_Ada_83_Warning;
5799 Check_No_Identifiers;
5800 Check_Arg_Count (1);
5801 Check_Arg_Is_Local_Name (Arg1);
5803 if Debug_Flag_U then
5807 C_Ent := Cunit_Entity (Current_Sem_Unit);
5808 Analyze (Expression (Arg1));
5809 Nm := Entity (Expression (Arg1));
5811 if not Is_Remote_Call_Interface (C_Ent)
5812 and then not Is_Remote_Types (C_Ent)
5814 -- This pragma should only appear in an RCI or Remote Types
5815 -- unit (RM E.4.1(4)).
5818 ("pragma% not in Remote_Call_Interface or " &
5819 "Remote_Types unit");
5822 if Ekind (Nm) = E_Procedure
5823 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5825 if not Is_Remote_Call_Interface (Nm) then
5827 ("pragma% cannot be applied on non-remote procedure",
5831 L := Parameter_Specifications (Parent (Nm));
5832 Process_Async_Pragma;
5835 elsif Ekind (Nm) = E_Function then
5837 ("pragma% cannot be applied to function", Arg1);
5839 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5841 if Is_Record_Type (Nm) then
5843 -- A record type that is the Equivalent_Type for a remote
5844 -- access-to-subprogram type.
5846 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5849 -- A non-expanded RAS type (distribution is not enabled)
5851 N := Declaration_Node (Nm);
5854 if Nkind (N) = N_Full_Type_Declaration
5855 and then Nkind (Type_Definition (N)) =
5856 N_Access_Procedure_Definition
5858 L := Parameter_Specifications (Type_Definition (N));
5859 Process_Async_Pragma;
5861 if Is_Asynchronous (Nm)
5862 and then Expander_Active
5863 and then Get_PCS_Name /= Name_No_DSA
5865 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5870 ("pragma% cannot reference access-to-function type",
5874 -- Only other possibility is Access-to-class-wide type
5876 elsif Is_Access_Type (Nm)
5877 and then Is_Class_Wide_Type (Designated_Type (Nm))
5879 Check_First_Subtype (Arg1);
5880 Set_Is_Asynchronous (Nm);
5881 if Expander_Active then
5882 RACW_Type_Is_Asynchronous (Nm);
5886 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5894 -- pragma Atomic (LOCAL_NAME);
5896 when Pragma_Atomic =>
5897 Process_Atomic_Shared_Volatile;
5899 -----------------------
5900 -- Atomic_Components --
5901 -----------------------
5903 -- pragma Atomic_Components (array_LOCAL_NAME);
5905 -- This processing is shared by Volatile_Components
5907 when Pragma_Atomic_Components |
5908 Pragma_Volatile_Components =>
5910 Atomic_Components : declare
5917 Check_Ada_83_Warning;
5918 Check_No_Identifiers;
5919 Check_Arg_Count (1);
5920 Check_Arg_Is_Local_Name (Arg1);
5921 E_Id := Expression (Arg1);
5923 if Etype (E_Id) = Any_Type then
5929 if Rep_Item_Too_Early (E, N)
5931 Rep_Item_Too_Late (E, N)
5936 D := Declaration_Node (E);
5939 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5941 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5942 and then Nkind (D) = N_Object_Declaration
5943 and then Nkind (Object_Definition (D)) =
5944 N_Constrained_Array_Definition)
5946 -- The flag is set on the object, or on the base type
5948 if Nkind (D) /= N_Object_Declaration then
5952 Set_Has_Volatile_Components (E);
5954 if Prag_Id = Pragma_Atomic_Components then
5955 Set_Has_Atomic_Components (E);
5957 if Is_Packed (E) then
5958 Set_Is_Packed (E, False);
5961 ("?Pack canceled, cannot pack atomic components",
5967 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5969 end Atomic_Components;
5971 --------------------
5972 -- Attach_Handler --
5973 --------------------
5975 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5977 when Pragma_Attach_Handler =>
5978 Check_Ada_83_Warning;
5979 Check_No_Identifiers;
5980 Check_Arg_Count (2);
5982 if No_Run_Time_Mode then
5983 Error_Msg_CRT ("Attach_Handler pragma", N);
5985 Check_Interrupt_Or_Attach_Handler;
5987 -- The expression that designates the attribute may
5988 -- depend on a discriminant, and is therefore a per-
5989 -- object expression, to be expanded in the init proc.
5990 -- If expansion is enabled, perform semantic checks
5993 if Expander_Active then
5995 Temp : constant Node_Id :=
5996 New_Copy_Tree (Expression (Arg2));
5998 Set_Parent (Temp, N);
5999 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6003 Analyze (Expression (Arg2));
6004 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
6007 Process_Interrupt_Or_Attach_Handler;
6010 --------------------
6011 -- C_Pass_By_Copy --
6012 --------------------
6014 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6016 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6022 Check_Valid_Configuration_Pragma;
6023 Check_Arg_Count (1);
6024 Check_Optional_Identifier (Arg1, "max_size");
6026 Arg := Expression (Arg1);
6027 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6029 Val := Expr_Value (Arg);
6033 ("maximum size for pragma% must be positive", Arg1);
6035 elsif UI_Is_In_Int_Range (Val) then
6036 Default_C_Record_Mechanism := UI_To_Int (Val);
6038 -- If a giant value is given, Int'Last will do well enough.
6039 -- If sometime someone complains that a record larger than
6040 -- two gigabytes is not copied, we will worry about it then!
6043 Default_C_Record_Mechanism := Mechanism_Type'Last;
6051 -- pragma Check ([Name =>] Identifier,
6052 -- [Check =>] Boolean_Expression
6053 -- [,[Message =>] String_Expression]);
6055 when Pragma_Check => Check : declare
6060 -- Set True if category of assertions referenced by Name enabled
6064 Check_At_Least_N_Arguments (2);
6065 Check_At_Most_N_Arguments (3);
6066 Check_Optional_Identifier (Arg1, Name_Name);
6067 Check_Optional_Identifier (Arg2, Name_Check);
6069 if Arg_Count = 3 then
6070 Check_Optional_Identifier (Arg3, Name_Message);
6071 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6074 Check_Arg_Is_Identifier (Arg1);
6076 -- Indicate if pragma is enabled. The Original_Node reference here
6077 -- is to deal with pragma Assert rewritten as a Check pragma.
6079 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6082 Set_Pragma_Enabled (N);
6083 Set_Pragma_Enabled (Original_Node (N));
6084 Set_SCO_Pragma_Enabled (Loc);
6087 -- If expansion is active and the check is not enabled then we
6088 -- rewrite the Check as:
6090 -- if False and then condition then
6094 -- The reason we do this rewriting during semantic analysis rather
6095 -- than as part of normal expansion is that we cannot analyze and
6096 -- expand the code for the boolean expression directly, or it may
6097 -- cause insertion of actions that would escape the attempt to
6098 -- suppress the check code.
6100 -- Note that the Sloc for the if statement corresponds to the
6101 -- argument condition, not the pragma itself. The reason for this
6102 -- is that we may generate a warning if the condition is False at
6103 -- compile time, and we do not want to delete this warning when we
6104 -- delete the if statement.
6106 Expr := Expression (Arg2);
6108 if Expander_Active and then not Check_On then
6109 Eloc := Sloc (Expr);
6112 Make_If_Statement (Eloc,
6114 Make_And_Then (Eloc,
6115 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6116 Right_Opnd => Expr),
6117 Then_Statements => New_List (
6118 Make_Null_Statement (Eloc))));
6125 Analyze_And_Resolve (Expr, Any_Boolean);
6133 -- pragma Check_Name (check_IDENTIFIER);
6135 when Pragma_Check_Name =>
6136 Check_No_Identifiers;
6138 Check_Valid_Configuration_Pragma;
6139 Check_Arg_Count (1);
6140 Check_Arg_Is_Identifier (Arg1);
6143 Nam : constant Name_Id := Chars (Expression (Arg1));
6146 for J in Check_Names.First .. Check_Names.Last loop
6147 if Check_Names.Table (J) = Nam then
6152 Check_Names.Append (Nam);
6159 -- pragma Check_Policy (
6160 -- [Name =>] IDENTIFIER,
6161 -- [Policy =>] POLICY_IDENTIFIER);
6163 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6165 -- Note: this is a configuration pragma, but it is allowed to appear
6168 when Pragma_Check_Policy =>
6170 Check_Arg_Count (2);
6171 Check_Optional_Identifier (Arg1, Name_Name);
6172 Check_Optional_Identifier (Arg2, Name_Policy);
6174 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6176 -- A Check_Policy pragma can appear either as a configuration
6177 -- pragma, or in a declarative part or a package spec (see RM
6178 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6179 -- followed for Check_Policy).
6181 if not Is_Configuration_Pragma then
6182 Check_Is_In_Decl_Part_Or_Package_Spec;
6185 Set_Next_Pragma (N, Opt.Check_Policy_List);
6186 Opt.Check_Policy_List := N;
6188 ---------------------
6189 -- CIL_Constructor --
6190 ---------------------
6192 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6194 -- Processing for this pragma is shared with Java_Constructor
6200 -- pragma Comment (static_string_EXPRESSION)
6202 -- Processing for pragma Comment shares the circuitry for pragma
6203 -- Ident. The only differences are that Ident enforces a limit of 31
6204 -- characters on its argument, and also enforces limitations on
6205 -- placement for DEC compatibility. Pragma Comment shares neither of
6206 -- these restrictions.
6212 -- pragma Common_Object (
6213 -- [Internal =>] LOCAL_NAME
6214 -- [, [External =>] EXTERNAL_SYMBOL]
6215 -- [, [Size =>] EXTERNAL_SYMBOL]);
6217 -- Processing for this pragma is shared with Psect_Object
6219 ------------------------
6220 -- Compile_Time_Error --
6221 ------------------------
6223 -- pragma Compile_Time_Error
6224 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6226 when Pragma_Compile_Time_Error =>
6228 Process_Compile_Time_Warning_Or_Error;
6230 --------------------------
6231 -- Compile_Time_Warning --
6232 --------------------------
6234 -- pragma Compile_Time_Warning
6235 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6237 when Pragma_Compile_Time_Warning =>
6239 Process_Compile_Time_Warning_Or_Error;
6245 when Pragma_Compiler_Unit =>
6247 Check_Arg_Count (0);
6248 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6250 -----------------------------
6251 -- Complete_Representation --
6252 -----------------------------
6254 -- pragma Complete_Representation;
6256 when Pragma_Complete_Representation =>
6258 Check_Arg_Count (0);
6260 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6262 ("pragma & must appear within record representation clause");
6265 ----------------------------
6266 -- Complex_Representation --
6267 ----------------------------
6269 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6271 when Pragma_Complex_Representation => Complex_Representation : declare
6278 Check_Arg_Count (1);
6279 Check_Optional_Identifier (Arg1, Name_Entity);
6280 Check_Arg_Is_Local_Name (Arg1);
6281 E_Id := Expression (Arg1);
6283 if Etype (E_Id) = Any_Type then
6289 if not Is_Record_Type (E) then
6291 ("argument for pragma% must be record type", Arg1);
6294 Ent := First_Entity (E);
6297 or else No (Next_Entity (Ent))
6298 or else Present (Next_Entity (Next_Entity (Ent)))
6299 or else not Is_Floating_Point_Type (Etype (Ent))
6300 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6303 ("record for pragma% must have two fields of the same "
6304 & "floating-point type", Arg1);
6307 Set_Has_Complex_Representation (Base_Type (E));
6309 -- We need to treat the type has having a non-standard
6310 -- representation, for back-end purposes, even though in
6311 -- general a complex will have the default representation
6312 -- of a record with two real components.
6314 Set_Has_Non_Standard_Rep (Base_Type (E));
6316 end Complex_Representation;
6318 -------------------------
6319 -- Component_Alignment --
6320 -------------------------
6322 -- pragma Component_Alignment (
6323 -- [Form =>] ALIGNMENT_CHOICE
6324 -- [, [Name =>] type_LOCAL_NAME]);
6326 -- ALIGNMENT_CHOICE ::=
6328 -- | Component_Size_4
6332 when Pragma_Component_Alignment => Component_AlignmentP : declare
6333 Args : Args_List (1 .. 2);
6334 Names : constant Name_List (1 .. 2) := (
6338 Form : Node_Id renames Args (1);
6339 Name : Node_Id renames Args (2);
6341 Atype : Component_Alignment_Kind;
6346 Gather_Associations (Names, Args);
6349 Error_Pragma ("missing Form argument for pragma%");
6352 Check_Arg_Is_Identifier (Form);
6354 -- Get proper alignment, note that Default = Component_Size on all
6355 -- machines we have so far, and we want to set this value rather
6356 -- than the default value to indicate that it has been explicitly
6357 -- set (and thus will not get overridden by the default component
6358 -- alignment for the current scope)
6360 if Chars (Form) = Name_Component_Size then
6361 Atype := Calign_Component_Size;
6363 elsif Chars (Form) = Name_Component_Size_4 then
6364 Atype := Calign_Component_Size_4;
6366 elsif Chars (Form) = Name_Default then
6367 Atype := Calign_Component_Size;
6369 elsif Chars (Form) = Name_Storage_Unit then
6370 Atype := Calign_Storage_Unit;
6374 ("invalid Form parameter for pragma%", Form);
6377 -- Case with no name, supplied, affects scope table entry
6381 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6383 -- Case of name supplied
6386 Check_Arg_Is_Local_Name (Name);
6388 Typ := Entity (Name);
6391 or else Rep_Item_Too_Early (Typ, N)
6395 Typ := Underlying_Type (Typ);
6398 if not Is_Record_Type (Typ)
6399 and then not Is_Array_Type (Typ)
6402 ("Name parameter of pragma% must identify record or " &
6403 "array type", Name);
6406 -- An explicit Component_Alignment pragma overrides an
6407 -- implicit pragma Pack, but not an explicit one.
6409 if not Has_Pragma_Pack (Base_Type (Typ)) then
6410 Set_Is_Packed (Base_Type (Typ), False);
6411 Set_Component_Alignment (Base_Type (Typ), Atype);
6414 end Component_AlignmentP;
6420 -- pragma Controlled (first_subtype_LOCAL_NAME);
6422 when Pragma_Controlled => Controlled : declare
6426 Check_No_Identifiers;
6427 Check_Arg_Count (1);
6428 Check_Arg_Is_Local_Name (Arg1);
6429 Arg := Expression (Arg1);
6431 if not Is_Entity_Name (Arg)
6432 or else not Is_Access_Type (Entity (Arg))
6434 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6436 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6444 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6445 -- [Entity =>] LOCAL_NAME);
6447 when Pragma_Convention => Convention : declare
6450 pragma Warnings (Off, C);
6451 pragma Warnings (Off, E);
6453 Check_Arg_Order ((Name_Convention, Name_Entity));
6454 Check_Ada_83_Warning;
6455 Check_Arg_Count (2);
6456 Process_Convention (C, E);
6459 ---------------------------
6460 -- Convention_Identifier --
6461 ---------------------------
6463 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6464 -- [Convention =>] convention_IDENTIFIER);
6466 when Pragma_Convention_Identifier => Convention_Identifier : declare
6472 Check_Arg_Order ((Name_Name, Name_Convention));
6473 Check_Arg_Count (2);
6474 Check_Optional_Identifier (Arg1, Name_Name);
6475 Check_Optional_Identifier (Arg2, Name_Convention);
6476 Check_Arg_Is_Identifier (Arg1);
6477 Check_Arg_Is_Identifier (Arg2);
6478 Idnam := Chars (Expression (Arg1));
6479 Cname := Chars (Expression (Arg2));
6481 if Is_Convention_Name (Cname) then
6482 Record_Convention_Identifier
6483 (Idnam, Get_Convention_Id (Cname));
6486 ("second arg for % pragma must be convention", Arg2);
6488 end Convention_Identifier;
6494 -- pragma CPP_Class ([Entity =>] local_NAME)
6496 when Pragma_CPP_Class => CPP_Class : declare
6501 if Warn_On_Obsolescent_Feature then
6503 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6504 " by pragma import?", N);
6508 Check_Arg_Count (1);
6509 Check_Optional_Identifier (Arg1, Name_Entity);
6510 Check_Arg_Is_Local_Name (Arg1);
6512 Arg := Expression (Arg1);
6515 if Etype (Arg) = Any_Type then
6519 if not Is_Entity_Name (Arg)
6520 or else not Is_Type (Entity (Arg))
6522 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6525 Typ := Entity (Arg);
6527 if not Is_Tagged_Type (Typ) then
6528 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6531 -- Types treated as CPP classes are treated as limited, but we
6532 -- don't require them to be declared this way. A warning is issued
6533 -- to encourage the user to declare them as limited. This is not
6534 -- an error, for compatibility reasons, because these types have
6535 -- been supported this way for some time.
6537 if not Is_Limited_Type (Typ) then
6539 ("imported 'C'P'P type should be " &
6540 "explicitly declared limited?",
6541 Get_Pragma_Arg (Arg1));
6543 ("\type will be considered limited",
6544 Get_Pragma_Arg (Arg1));
6547 Set_Is_CPP_Class (Typ);
6548 Set_Is_Limited_Record (Typ);
6549 Set_Convention (Typ, Convention_CPP);
6551 -- Imported CPP types must not have discriminants (because C++
6552 -- classes do not have discriminants).
6554 if Has_Discriminants (Typ) then
6556 ("imported 'C'P'P type cannot have discriminants",
6557 First (Discriminant_Specifications
6558 (Declaration_Node (Typ))));
6561 -- Components of imported CPP types must not have default
6562 -- expressions because the constructor (if any) is in the
6565 if Is_Incomplete_Or_Private_Type (Typ)
6566 and then No (Underlying_Type (Typ))
6568 -- It should be an error to apply pragma CPP to a private
6569 -- type if the underlying type is not visible (as it is
6570 -- for any representation item). For now, for backward
6571 -- compatibility we do nothing but we cannot check components
6572 -- because they are not available at this stage. All this code
6573 -- will be removed when we cleanup this obsolete GNAT pragma???
6579 Tdef : constant Node_Id :=
6580 Type_Definition (Declaration_Node (Typ));
6585 if Nkind (Tdef) = N_Record_Definition then
6586 Clist := Component_List (Tdef);
6588 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6589 Clist := Component_List (Record_Extension_Part (Tdef));
6592 if Present (Clist) then
6593 Comp := First (Component_Items (Clist));
6594 while Present (Comp) loop
6595 if Present (Expression (Comp)) then
6597 ("component of imported 'C'P'P type cannot have" &
6598 " default expression", Expression (Comp));
6608 ---------------------
6609 -- CPP_Constructor --
6610 ---------------------
6612 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6613 -- [, [External_Name =>] static_string_EXPRESSION ]
6614 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6616 when Pragma_CPP_Constructor => CPP_Constructor : declare
6620 Tag_Typ : Entity_Id;
6624 Check_At_Least_N_Arguments (1);
6625 Check_At_Most_N_Arguments (3);
6626 Check_Optional_Identifier (Arg1, Name_Entity);
6627 Check_Arg_Is_Local_Name (Arg1);
6629 Id := Expression (Arg1);
6630 Find_Program_Unit_Name (Id);
6632 -- If we did not find the name, we are done
6634 if Etype (Id) = Any_Type then
6638 Def_Id := Entity (Id);
6640 -- Check if already defined as constructor
6642 if Is_Constructor (Def_Id) then
6644 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
6648 if Ekind (Def_Id) = E_Function
6649 and then (Is_CPP_Class (Etype (Def_Id))
6650 or else (Is_Class_Wide_Type (Etype (Def_Id))
6652 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6654 if Arg_Count >= 2 then
6655 Set_Imported (Def_Id);
6656 Set_Is_Public (Def_Id);
6657 Process_Interface_Name (Def_Id, Arg2, Arg3);
6660 Set_Has_Completion (Def_Id);
6661 Set_Is_Constructor (Def_Id);
6663 -- Imported C++ constructors are not dispatching primitives
6664 -- because in C++ they don't have a dispatch table slot.
6665 -- However, in Ada the constructor has the profile of a
6666 -- function that returns a tagged type and therefore it has
6667 -- been treated as a primitive operation during semantic
6668 -- analysis. We now remove it from the list of primitive
6669 -- operations of the type.
6671 if Is_Tagged_Type (Etype (Def_Id))
6672 and then not Is_Class_Wide_Type (Etype (Def_Id))
6674 pragma Assert (Is_Dispatching_Operation (Def_Id));
6675 Tag_Typ := Etype (Def_Id);
6677 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6678 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6682 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6683 Set_Is_Dispatching_Operation (Def_Id, False);
6686 -- For backward compatibility, if the constructor returns a
6687 -- class wide type, and we internally change the return type to
6688 -- the corresponding root type.
6690 if Is_Class_Wide_Type (Etype (Def_Id)) then
6691 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6695 ("pragma% requires function returning a 'C'P'P_Class type",
6698 end CPP_Constructor;
6704 when Pragma_CPP_Virtual => CPP_Virtual : declare
6708 if Warn_On_Obsolescent_Feature then
6710 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6719 when Pragma_CPP_Vtable => CPP_Vtable : declare
6723 if Warn_On_Obsolescent_Feature then
6725 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6734 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6736 when Pragma_Debug => Debug : declare
6744 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6747 if Arg_Count = 2 then
6750 Left_Opnd => Relocate_Node (Cond),
6751 Right_Opnd => Expression (Arg1));
6754 -- Rewrite into a conditional with an appropriate condition. We
6755 -- wrap the procedure call in a block so that overhead from e.g.
6756 -- use of the secondary stack does not generate execution overhead
6757 -- for suppressed conditions.
6759 Rewrite (N, Make_Implicit_If_Statement (N,
6761 Then_Statements => New_List (
6762 Make_Block_Statement (Loc,
6763 Handled_Statement_Sequence =>
6764 Make_Handled_Sequence_Of_Statements (Loc,
6765 Statements => New_List (
6766 Relocate_Node (Debug_Statement (N))))))));
6774 -- pragma Debug_Policy (Check | Ignore)
6776 when Pragma_Debug_Policy =>
6778 Check_Arg_Count (1);
6779 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6780 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6782 ---------------------
6783 -- Detect_Blocking --
6784 ---------------------
6786 -- pragma Detect_Blocking;
6788 when Pragma_Detect_Blocking =>
6790 Check_Arg_Count (0);
6791 Check_Valid_Configuration_Pragma;
6792 Detect_Blocking := True;
6798 when Pragma_Dimension =>
6800 Check_Arg_Count (4);
6801 Check_No_Identifiers;
6802 Check_Arg_Is_Local_Name (Arg1);
6804 if not Is_Type (Arg1) then
6805 Error_Pragma ("first argument for pragma% must be subtype");
6808 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
6809 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
6810 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
6816 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6818 when Pragma_Discard_Names => Discard_Names : declare
6823 Check_Ada_83_Warning;
6825 -- Deal with configuration pragma case
6827 if Arg_Count = 0 and then Is_Configuration_Pragma then
6828 Global_Discard_Names := True;
6831 -- Otherwise, check correct appropriate context
6834 Check_Is_In_Decl_Part_Or_Package_Spec;
6836 if Arg_Count = 0 then
6838 -- If there is no parameter, then from now on this pragma
6839 -- applies to any enumeration, exception or tagged type
6840 -- defined in the current declarative part, and recursively
6841 -- to any nested scope.
6843 Set_Discard_Names (Current_Scope);
6847 Check_Arg_Count (1);
6848 Check_Optional_Identifier (Arg1, Name_On);
6849 Check_Arg_Is_Local_Name (Arg1);
6851 E_Id := Expression (Arg1);
6853 if Etype (E_Id) = Any_Type then
6859 if (Is_First_Subtype (E)
6861 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6862 or else Ekind (E) = E_Exception
6864 Set_Discard_Names (E);
6867 ("inappropriate entity for pragma%", Arg1);
6878 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6880 when Pragma_Elaborate => Elaborate : declare
6885 -- Pragma must be in context items list of a compilation unit
6887 if not Is_In_Context_Clause then
6891 -- Must be at least one argument
6893 if Arg_Count = 0 then
6894 Error_Pragma ("pragma% requires at least one argument");
6897 -- In Ada 83 mode, there can be no items following it in the
6898 -- context list except other pragmas and implicit with clauses
6899 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6900 -- placement rule does not apply.
6902 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6904 while Present (Citem) loop
6905 if Nkind (Citem) = N_Pragma
6906 or else (Nkind (Citem) = N_With_Clause
6907 and then Implicit_With (Citem))
6912 ("(Ada 83) pragma% must be at end of context clause");
6919 -- Finally, the arguments must all be units mentioned in a with
6920 -- clause in the same context clause. Note we already checked (in
6921 -- Par.Prag) that the arguments are all identifiers or selected
6925 Outer : while Present (Arg) loop
6926 Citem := First (List_Containing (N));
6927 Inner : while Citem /= N loop
6928 if Nkind (Citem) = N_With_Clause
6929 and then Same_Name (Name (Citem), Expression (Arg))
6931 Set_Elaborate_Present (Citem, True);
6932 Set_Unit_Name (Expression (Arg), Name (Citem));
6934 -- With the pragma present, elaboration calls on
6935 -- subprograms from the named unit need no further
6936 -- checks, as long as the pragma appears in the current
6937 -- compilation unit. If the pragma appears in some unit
6938 -- in the context, there might still be a need for an
6939 -- Elaborate_All_Desirable from the current compilation
6940 -- to the named unit, so we keep the check enabled.
6942 if In_Extended_Main_Source_Unit (N) then
6943 Set_Suppress_Elaboration_Warnings
6944 (Entity (Name (Citem)));
6955 ("argument of pragma% is not with'ed unit", Arg);
6961 -- Give a warning if operating in static mode with -gnatwl
6962 -- (elaboration warnings enabled) switch set.
6964 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6966 ("?use of pragma Elaborate may not be safe", N);
6968 ("?use pragma Elaborate_All instead if possible", N);
6976 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6978 when Pragma_Elaborate_All => Elaborate_All : declare
6983 Check_Ada_83_Warning;
6985 -- Pragma must be in context items list of a compilation unit
6987 if not Is_In_Context_Clause then
6991 -- Must be at least one argument
6993 if Arg_Count = 0 then
6994 Error_Pragma ("pragma% requires at least one argument");
6997 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6998 -- have to appear at the end of the context clause, but may
6999 -- appear mixed in with other items, even in Ada 83 mode.
7001 -- Final check: the arguments must all be units mentioned in
7002 -- a with clause in the same context clause. Note that we
7003 -- already checked (in Par.Prag) that all the arguments are
7004 -- either identifiers or selected components.
7007 Outr : while Present (Arg) loop
7008 Citem := First (List_Containing (N));
7009 Innr : while Citem /= N loop
7010 if Nkind (Citem) = N_With_Clause
7011 and then Same_Name (Name (Citem), Expression (Arg))
7013 Set_Elaborate_All_Present (Citem, True);
7014 Set_Unit_Name (Expression (Arg), Name (Citem));
7016 -- Suppress warnings and elaboration checks on the named
7017 -- unit if the pragma is in the current compilation, as
7018 -- for pragma Elaborate.
7020 if In_Extended_Main_Source_Unit (N) then
7021 Set_Suppress_Elaboration_Warnings
7022 (Entity (Name (Citem)));
7031 Set_Error_Posted (N);
7033 ("argument of pragma% is not with'ed unit", Arg);
7040 --------------------
7041 -- Elaborate_Body --
7042 --------------------
7044 -- pragma Elaborate_Body [( library_unit_NAME )];
7046 when Pragma_Elaborate_Body => Elaborate_Body : declare
7047 Cunit_Node : Node_Id;
7048 Cunit_Ent : Entity_Id;
7051 Check_Ada_83_Warning;
7052 Check_Valid_Library_Unit_Pragma;
7054 if Nkind (N) = N_Null_Statement then
7058 Cunit_Node := Cunit (Current_Sem_Unit);
7059 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7061 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7064 Error_Pragma ("pragma% must refer to a spec, not a body");
7066 Set_Body_Required (Cunit_Node, True);
7067 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7069 -- If we are in dynamic elaboration mode, then we suppress
7070 -- elaboration warnings for the unit, since it is definitely
7071 -- fine NOT to do dynamic checks at the first level (and such
7072 -- checks will be suppressed because no elaboration boolean
7073 -- is created for Elaborate_Body packages).
7075 -- But in the static model of elaboration, Elaborate_Body is
7076 -- definitely NOT good enough to ensure elaboration safety on
7077 -- its own, since the body may WITH other units that are not
7078 -- safe from an elaboration point of view, so a client must
7079 -- still do an Elaborate_All on such units.
7081 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7082 -- Elaborate_Body always suppressed elab warnings.
7084 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7085 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7090 ------------------------
7091 -- Elaboration_Checks --
7092 ------------------------
7094 -- pragma Elaboration_Checks (Static | Dynamic);
7096 when Pragma_Elaboration_Checks =>
7098 Check_Arg_Count (1);
7099 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7100 Dynamic_Elaboration_Checks :=
7101 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7107 -- pragma Eliminate (
7108 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7109 -- [,[Entity =>] IDENTIFIER |
7110 -- SELECTED_COMPONENT |
7112 -- [, OVERLOADING_RESOLUTION]);
7114 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7117 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7120 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7122 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7123 -- Result_Type => result_SUBTYPE_NAME]
7125 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7126 -- SUBTYPE_NAME ::= STRING_LITERAL
7128 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7129 -- SOURCE_TRACE ::= STRING_LITERAL
7131 when Pragma_Eliminate => Eliminate : declare
7132 Args : Args_List (1 .. 5);
7133 Names : constant Name_List (1 .. 5) := (
7136 Name_Parameter_Types,
7138 Name_Source_Location);
7140 Unit_Name : Node_Id renames Args (1);
7141 Entity : Node_Id renames Args (2);
7142 Parameter_Types : Node_Id renames Args (3);
7143 Result_Type : Node_Id renames Args (4);
7144 Source_Location : Node_Id renames Args (5);
7148 Check_Valid_Configuration_Pragma;
7149 Gather_Associations (Names, Args);
7151 if No (Unit_Name) then
7152 Error_Pragma ("missing Unit_Name argument for pragma%");
7156 and then (Present (Parameter_Types)
7158 Present (Result_Type)
7160 Present (Source_Location))
7162 Error_Pragma ("missing Entity argument for pragma%");
7165 if (Present (Parameter_Types)
7167 Present (Result_Type))
7169 Present (Source_Location)
7172 ("parameter profile and source location cannot " &
7173 "be used together in pragma%");
7176 Process_Eliminate_Pragma
7190 -- [ Convention =>] convention_IDENTIFIER,
7191 -- [ Entity =>] local_NAME
7192 -- [, [External_Name =>] static_string_EXPRESSION ]
7193 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7195 when Pragma_Export => Export : declare
7199 pragma Warnings (Off, C);
7202 Check_Ada_83_Warning;
7208 Check_At_Least_N_Arguments (2);
7209 Check_At_Most_N_Arguments (4);
7210 Process_Convention (C, Def_Id);
7212 if Ekind (Def_Id) /= E_Constant then
7213 Note_Possible_Modification (Expression (Arg2), Sure => False);
7216 Process_Interface_Name (Def_Id, Arg3, Arg4);
7217 Set_Exported (Def_Id, Arg2);
7219 -- If the entity is a deferred constant, propagate the information
7220 -- to the full view, because gigi elaborates the full view only.
7222 if Ekind (Def_Id) = E_Constant
7223 and then Present (Full_View (Def_Id))
7226 Id2 : constant Entity_Id := Full_View (Def_Id);
7228 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7229 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7230 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7235 ----------------------
7236 -- Export_Exception --
7237 ----------------------
7239 -- pragma Export_Exception (
7240 -- [Internal =>] LOCAL_NAME
7241 -- [, [External =>] EXTERNAL_SYMBOL]
7242 -- [, [Form =>] Ada | VMS]
7243 -- [, [Code =>] static_integer_EXPRESSION]);
7245 when Pragma_Export_Exception => Export_Exception : declare
7246 Args : Args_List (1 .. 4);
7247 Names : constant Name_List (1 .. 4) := (
7253 Internal : Node_Id renames Args (1);
7254 External : Node_Id renames Args (2);
7255 Form : Node_Id renames Args (3);
7256 Code : Node_Id renames Args (4);
7261 if Inside_A_Generic then
7262 Error_Pragma ("pragma% cannot be used for generic entities");
7265 Gather_Associations (Names, Args);
7266 Process_Extended_Import_Export_Exception_Pragma (
7267 Arg_Internal => Internal,
7268 Arg_External => External,
7272 if not Is_VMS_Exception (Entity (Internal)) then
7273 Set_Exported (Entity (Internal), Internal);
7275 end Export_Exception;
7277 ---------------------
7278 -- Export_Function --
7279 ---------------------
7281 -- pragma Export_Function (
7282 -- [Internal =>] LOCAL_NAME
7283 -- [, [External =>] EXTERNAL_SYMBOL]
7284 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7285 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7286 -- [, [Mechanism =>] MECHANISM]
7287 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7289 -- EXTERNAL_SYMBOL ::=
7291 -- | static_string_EXPRESSION
7293 -- PARAMETER_TYPES ::=
7295 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7297 -- TYPE_DESIGNATOR ::=
7299 -- | subtype_Name ' Access
7303 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7305 -- MECHANISM_ASSOCIATION ::=
7306 -- [formal_parameter_NAME =>] MECHANISM_NAME
7308 -- MECHANISM_NAME ::=
7311 -- | Descriptor [([Class =>] CLASS_NAME)]
7313 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7315 when Pragma_Export_Function => Export_Function : declare
7316 Args : Args_List (1 .. 6);
7317 Names : constant Name_List (1 .. 6) := (
7320 Name_Parameter_Types,
7323 Name_Result_Mechanism);
7325 Internal : Node_Id renames Args (1);
7326 External : Node_Id renames Args (2);
7327 Parameter_Types : Node_Id renames Args (3);
7328 Result_Type : Node_Id renames Args (4);
7329 Mechanism : Node_Id renames Args (5);
7330 Result_Mechanism : Node_Id renames Args (6);
7334 Gather_Associations (Names, Args);
7335 Process_Extended_Import_Export_Subprogram_Pragma (
7336 Arg_Internal => Internal,
7337 Arg_External => External,
7338 Arg_Parameter_Types => Parameter_Types,
7339 Arg_Result_Type => Result_Type,
7340 Arg_Mechanism => Mechanism,
7341 Arg_Result_Mechanism => Result_Mechanism);
7342 end Export_Function;
7348 -- pragma Export_Object (
7349 -- [Internal =>] LOCAL_NAME
7350 -- [, [External =>] EXTERNAL_SYMBOL]
7351 -- [, [Size =>] EXTERNAL_SYMBOL]);
7353 -- EXTERNAL_SYMBOL ::=
7355 -- | static_string_EXPRESSION
7357 -- PARAMETER_TYPES ::=
7359 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7361 -- TYPE_DESIGNATOR ::=
7363 -- | subtype_Name ' Access
7367 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7369 -- MECHANISM_ASSOCIATION ::=
7370 -- [formal_parameter_NAME =>] MECHANISM_NAME
7372 -- MECHANISM_NAME ::=
7375 -- | Descriptor [([Class =>] CLASS_NAME)]
7377 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7379 when Pragma_Export_Object => Export_Object : declare
7380 Args : Args_List (1 .. 3);
7381 Names : constant Name_List (1 .. 3) := (
7386 Internal : Node_Id renames Args (1);
7387 External : Node_Id renames Args (2);
7388 Size : Node_Id renames Args (3);
7392 Gather_Associations (Names, Args);
7393 Process_Extended_Import_Export_Object_Pragma (
7394 Arg_Internal => Internal,
7395 Arg_External => External,
7399 ----------------------
7400 -- Export_Procedure --
7401 ----------------------
7403 -- pragma Export_Procedure (
7404 -- [Internal =>] LOCAL_NAME
7405 -- [, [External =>] EXTERNAL_SYMBOL]
7406 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7407 -- [, [Mechanism =>] MECHANISM]);
7409 -- EXTERNAL_SYMBOL ::=
7411 -- | static_string_EXPRESSION
7413 -- PARAMETER_TYPES ::=
7415 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7417 -- TYPE_DESIGNATOR ::=
7419 -- | subtype_Name ' Access
7423 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7425 -- MECHANISM_ASSOCIATION ::=
7426 -- [formal_parameter_NAME =>] MECHANISM_NAME
7428 -- MECHANISM_NAME ::=
7431 -- | Descriptor [([Class =>] CLASS_NAME)]
7433 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7435 when Pragma_Export_Procedure => Export_Procedure : declare
7436 Args : Args_List (1 .. 4);
7437 Names : constant Name_List (1 .. 4) := (
7440 Name_Parameter_Types,
7443 Internal : Node_Id renames Args (1);
7444 External : Node_Id renames Args (2);
7445 Parameter_Types : Node_Id renames Args (3);
7446 Mechanism : Node_Id renames Args (4);
7450 Gather_Associations (Names, Args);
7451 Process_Extended_Import_Export_Subprogram_Pragma (
7452 Arg_Internal => Internal,
7453 Arg_External => External,
7454 Arg_Parameter_Types => Parameter_Types,
7455 Arg_Mechanism => Mechanism);
7456 end Export_Procedure;
7462 -- pragma Export_Value (
7463 -- [Value =>] static_integer_EXPRESSION,
7464 -- [Link_Name =>] static_string_EXPRESSION);
7466 when Pragma_Export_Value =>
7468 Check_Arg_Order ((Name_Value, Name_Link_Name));
7469 Check_Arg_Count (2);
7471 Check_Optional_Identifier (Arg1, Name_Value);
7472 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7474 Check_Optional_Identifier (Arg2, Name_Link_Name);
7475 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7477 -----------------------------
7478 -- Export_Valued_Procedure --
7479 -----------------------------
7481 -- pragma Export_Valued_Procedure (
7482 -- [Internal =>] LOCAL_NAME
7483 -- [, [External =>] EXTERNAL_SYMBOL,]
7484 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7485 -- [, [Mechanism =>] MECHANISM]);
7487 -- EXTERNAL_SYMBOL ::=
7489 -- | static_string_EXPRESSION
7491 -- PARAMETER_TYPES ::=
7493 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7495 -- TYPE_DESIGNATOR ::=
7497 -- | subtype_Name ' Access
7501 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7503 -- MECHANISM_ASSOCIATION ::=
7504 -- [formal_parameter_NAME =>] MECHANISM_NAME
7506 -- MECHANISM_NAME ::=
7509 -- | Descriptor [([Class =>] CLASS_NAME)]
7511 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7513 when Pragma_Export_Valued_Procedure =>
7514 Export_Valued_Procedure : declare
7515 Args : Args_List (1 .. 4);
7516 Names : constant Name_List (1 .. 4) := (
7519 Name_Parameter_Types,
7522 Internal : Node_Id renames Args (1);
7523 External : Node_Id renames Args (2);
7524 Parameter_Types : Node_Id renames Args (3);
7525 Mechanism : Node_Id renames Args (4);
7529 Gather_Associations (Names, Args);
7530 Process_Extended_Import_Export_Subprogram_Pragma (
7531 Arg_Internal => Internal,
7532 Arg_External => External,
7533 Arg_Parameter_Types => Parameter_Types,
7534 Arg_Mechanism => Mechanism);
7535 end Export_Valued_Procedure;
7541 -- pragma Extend_System ([Name =>] Identifier);
7543 when Pragma_Extend_System => Extend_System : declare
7546 Check_Valid_Configuration_Pragma;
7547 Check_Arg_Count (1);
7548 Check_Optional_Identifier (Arg1, Name_Name);
7549 Check_Arg_Is_Identifier (Arg1);
7551 Get_Name_String (Chars (Expression (Arg1)));
7554 and then Name_Buffer (1 .. 4) = "aux_"
7556 if Present (System_Extend_Pragma_Arg) then
7557 if Chars (Expression (Arg1)) =
7558 Chars (Expression (System_Extend_Pragma_Arg))
7562 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7563 Error_Pragma ("pragma% conflicts with that #");
7567 System_Extend_Pragma_Arg := Arg1;
7569 if not GNAT_Mode then
7570 System_Extend_Unit := Arg1;
7574 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7578 ------------------------
7579 -- Extensions_Allowed --
7580 ------------------------
7582 -- pragma Extensions_Allowed (ON | OFF);
7584 when Pragma_Extensions_Allowed =>
7586 Check_Arg_Count (1);
7587 Check_No_Identifiers;
7588 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7590 if Chars (Expression (Arg1)) = Name_On then
7591 Extensions_Allowed := True;
7592 Ada_Version := Ada_Version_Type'Last;
7595 Extensions_Allowed := False;
7596 Ada_Version := Ada_Version_Explicit;
7603 -- pragma External (
7604 -- [ Convention =>] convention_IDENTIFIER,
7605 -- [ Entity =>] local_NAME
7606 -- [, [External_Name =>] static_string_EXPRESSION ]
7607 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7609 when Pragma_External => External : declare
7613 pragma Warnings (Off, C);
7622 Check_At_Least_N_Arguments (2);
7623 Check_At_Most_N_Arguments (4);
7624 Process_Convention (C, Def_Id);
7625 Note_Possible_Modification (Expression (Arg2), Sure => False);
7626 Process_Interface_Name (Def_Id, Arg3, Arg4);
7627 Set_Exported (Def_Id, Arg2);
7630 --------------------------
7631 -- External_Name_Casing --
7632 --------------------------
7634 -- pragma External_Name_Casing (
7635 -- UPPERCASE | LOWERCASE
7636 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7638 when Pragma_External_Name_Casing => External_Name_Casing : declare
7641 Check_No_Identifiers;
7643 if Arg_Count = 2 then
7645 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7647 case Chars (Get_Pragma_Arg (Arg2)) is
7649 Opt.External_Name_Exp_Casing := As_Is;
7651 when Name_Uppercase =>
7652 Opt.External_Name_Exp_Casing := Uppercase;
7654 when Name_Lowercase =>
7655 Opt.External_Name_Exp_Casing := Lowercase;
7662 Check_Arg_Count (1);
7665 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7667 case Chars (Get_Pragma_Arg (Arg1)) is
7668 when Name_Uppercase =>
7669 Opt.External_Name_Imp_Casing := Uppercase;
7671 when Name_Lowercase =>
7672 Opt.External_Name_Imp_Casing := Lowercase;
7677 end External_Name_Casing;
7679 --------------------------
7680 -- Favor_Top_Level --
7681 --------------------------
7683 -- pragma Favor_Top_Level (type_NAME);
7685 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7686 Named_Entity : Entity_Id;
7690 Check_No_Identifiers;
7691 Check_Arg_Count (1);
7692 Check_Arg_Is_Local_Name (Arg1);
7693 Named_Entity := Entity (Expression (Arg1));
7695 -- If it's an access-to-subprogram type (in particular, not a
7696 -- subtype), set the flag on that type.
7698 if Is_Access_Subprogram_Type (Named_Entity) then
7699 Set_Can_Use_Internal_Rep (Named_Entity, False);
7701 -- Otherwise it's an error (name denotes the wrong sort of entity)
7705 ("access-to-subprogram type expected", Expression (Arg1));
7707 end Favor_Top_Level;
7713 -- pragma Fast_Math;
7715 when Pragma_Fast_Math =>
7717 Check_No_Identifiers;
7718 Check_Valid_Configuration_Pragma;
7721 ---------------------------
7722 -- Finalize_Storage_Only --
7723 ---------------------------
7725 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7727 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7728 Assoc : constant Node_Id := Arg1;
7729 Type_Id : constant Node_Id := Expression (Assoc);
7734 Check_No_Identifiers;
7735 Check_Arg_Count (1);
7736 Check_Arg_Is_Local_Name (Arg1);
7738 Find_Type (Type_Id);
7739 Typ := Entity (Type_Id);
7742 or else Rep_Item_Too_Early (Typ, N)
7746 Typ := Underlying_Type (Typ);
7749 if not Is_Controlled (Typ) then
7750 Error_Pragma ("pragma% must specify controlled type");
7753 Check_First_Subtype (Arg1);
7755 if Finalize_Storage_Only (Typ) then
7756 Error_Pragma ("duplicate pragma%, only one allowed");
7758 elsif not Rep_Item_Too_Late (Typ, N) then
7759 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7761 end Finalize_Storage;
7763 --------------------------
7764 -- Float_Representation --
7765 --------------------------
7767 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7769 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7771 when Pragma_Float_Representation => Float_Representation : declare
7779 if Arg_Count = 1 then
7780 Check_Valid_Configuration_Pragma;
7782 Check_Arg_Count (2);
7783 Check_Optional_Identifier (Arg2, Name_Entity);
7784 Check_Arg_Is_Local_Name (Arg2);
7787 Check_No_Identifier (Arg1);
7788 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7790 if not OpenVMS_On_Target then
7791 if Chars (Expression (Arg1)) = Name_VAX_Float then
7793 ("?pragma% ignored (applies only to Open'V'M'S)");
7799 -- One argument case
7801 if Arg_Count = 1 then
7802 if Chars (Expression (Arg1)) = Name_VAX_Float then
7803 if Opt.Float_Format = 'I' then
7804 Error_Pragma ("'I'E'E'E format previously specified");
7807 Opt.Float_Format := 'V';
7810 if Opt.Float_Format = 'V' then
7811 Error_Pragma ("'V'A'X format previously specified");
7814 Opt.Float_Format := 'I';
7817 Set_Standard_Fpt_Formats;
7819 -- Two argument case
7822 Argx := Get_Pragma_Arg (Arg2);
7824 if not Is_Entity_Name (Argx)
7825 or else not Is_Floating_Point_Type (Entity (Argx))
7828 ("second argument of% pragma must be floating-point type",
7832 Ent := Entity (Argx);
7833 Digs := UI_To_Int (Digits_Value (Ent));
7835 -- Two arguments, VAX_Float case
7837 if Chars (Expression (Arg1)) = Name_VAX_Float then
7839 when 6 => Set_F_Float (Ent);
7840 when 9 => Set_D_Float (Ent);
7841 when 15 => Set_G_Float (Ent);
7845 ("wrong digits value, must be 6,9 or 15", Arg2);
7848 -- Two arguments, IEEE_Float case
7852 when 6 => Set_IEEE_Short (Ent);
7853 when 15 => Set_IEEE_Long (Ent);
7857 ("wrong digits value, must be 6 or 15", Arg2);
7861 end Float_Representation;
7867 -- pragma Ident (static_string_EXPRESSION)
7869 -- Note: pragma Comment shares this processing. Pragma Comment is
7870 -- identical to Ident, except that the restriction of the argument to
7871 -- 31 characters and the placement restrictions are not enforced for
7874 when Pragma_Ident | Pragma_Comment => Ident : declare
7879 Check_Arg_Count (1);
7880 Check_No_Identifiers;
7881 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7884 -- For pragma Ident, preserve DEC compatibility by requiring the
7885 -- pragma to appear in a declarative part or package spec.
7887 if Prag_Id = Pragma_Ident then
7888 Check_Is_In_Decl_Part_Or_Package_Spec;
7891 Str := Expr_Value_S (Expression (Arg1));
7898 GP := Parent (Parent (N));
7900 if Nkind_In (GP, N_Package_Declaration,
7901 N_Generic_Package_Declaration)
7906 -- If we have a compilation unit, then record the ident value,
7907 -- checking for improper duplication.
7909 if Nkind (GP) = N_Compilation_Unit then
7910 CS := Ident_String (Current_Sem_Unit);
7912 if Present (CS) then
7914 -- For Ident, we do not permit multiple instances
7916 if Prag_Id = Pragma_Ident then
7917 Error_Pragma ("duplicate% pragma not permitted");
7919 -- For Comment, we concatenate the string, unless we want
7920 -- to preserve the tree structure for ASIS.
7922 elsif not ASIS_Mode then
7923 Start_String (Strval (CS));
7924 Store_String_Char (' ');
7925 Store_String_Chars (Strval (Str));
7926 Set_Strval (CS, End_String);
7930 -- In VMS, the effect of IDENT is achieved by passing
7931 -- --identification=name as a --for-linker switch.
7933 if OpenVMS_On_Target then
7936 ("--for-linker=--identification=");
7937 String_To_Name_Buffer (Strval (Str));
7938 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7940 -- Only the last processed IDENT is saved. The main
7941 -- purpose is so an IDENT associated with a main
7942 -- procedure will be used in preference to an IDENT
7943 -- associated with a with'd package.
7945 Replace_Linker_Option_String
7946 (End_String, "--for-linker=--identification=");
7949 Set_Ident_String (Current_Sem_Unit, Str);
7952 -- For subunits, we just ignore the Ident, since in GNAT these
7953 -- are not separate object files, and hence not separate units
7954 -- in the unit table.
7956 elsif Nkind (GP) = N_Subunit then
7959 -- Otherwise we have a misplaced pragma Ident, but we ignore
7960 -- this if we are in an instantiation, since it comes from
7961 -- a generic, and has no relevance to the instantiation.
7963 elsif Prag_Id = Pragma_Ident then
7964 if Instantiation_Location (Loc) = No_Location then
7965 Error_Pragma ("pragma% only allowed at outer level");
7971 --------------------------
7972 -- Implemented_By_Entry --
7973 --------------------------
7975 -- pragma Implemented_By_Entry (DIRECT_NAME);
7977 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7982 Check_Arg_Count (1);
7983 Check_No_Identifiers;
7984 Check_Arg_Is_Identifier (Arg1);
7985 Check_Arg_Is_Local_Name (Arg1);
7986 Ent := Entity (Expression (Arg1));
7988 -- Pragma Implemented_By_Entry must be applied only to protected
7989 -- synchronized or task interface primitives.
7991 if (Ekind (Ent) /= E_Function
7992 and then Ekind (Ent) /= E_Procedure)
7993 or else not Present (First_Formal (Ent))
7994 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7997 ("pragma % must be applied to a concurrent interface " &
8001 if Einfo.Implemented_By_Entry (Ent)
8002 and then Warn_On_Redundant_Constructs
8004 Error_Pragma ("?duplicate pragma%!");
8006 Set_Implemented_By_Entry (Ent);
8009 end Implemented_By_Entry;
8011 -----------------------
8012 -- Implicit_Packing --
8013 -----------------------
8015 -- pragma Implicit_Packing;
8017 when Pragma_Implicit_Packing =>
8019 Check_Arg_Count (0);
8020 Implicit_Packing := True;
8027 -- [Convention =>] convention_IDENTIFIER,
8028 -- [Entity =>] local_NAME
8029 -- [, [External_Name =>] static_string_EXPRESSION ]
8030 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8032 when Pragma_Import =>
8033 Check_Ada_83_Warning;
8039 Check_At_Least_N_Arguments (2);
8040 Check_At_Most_N_Arguments (4);
8041 Process_Import_Or_Interface;
8043 ----------------------
8044 -- Import_Exception --
8045 ----------------------
8047 -- pragma Import_Exception (
8048 -- [Internal =>] LOCAL_NAME
8049 -- [, [External =>] EXTERNAL_SYMBOL]
8050 -- [, [Form =>] Ada | VMS]
8051 -- [, [Code =>] static_integer_EXPRESSION]);
8053 when Pragma_Import_Exception => Import_Exception : declare
8054 Args : Args_List (1 .. 4);
8055 Names : constant Name_List (1 .. 4) := (
8061 Internal : Node_Id renames Args (1);
8062 External : Node_Id renames Args (2);
8063 Form : Node_Id renames Args (3);
8064 Code : Node_Id renames Args (4);
8068 Gather_Associations (Names, Args);
8070 if Present (External) and then Present (Code) then
8072 ("cannot give both External and Code options for pragma%");
8075 Process_Extended_Import_Export_Exception_Pragma (
8076 Arg_Internal => Internal,
8077 Arg_External => External,
8081 if not Is_VMS_Exception (Entity (Internal)) then
8082 Set_Imported (Entity (Internal));
8084 end Import_Exception;
8086 ---------------------
8087 -- Import_Function --
8088 ---------------------
8090 -- pragma Import_Function (
8091 -- [Internal =>] LOCAL_NAME,
8092 -- [, [External =>] EXTERNAL_SYMBOL]
8093 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8094 -- [, [Result_Type =>] SUBTYPE_MARK]
8095 -- [, [Mechanism =>] MECHANISM]
8096 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8097 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8099 -- EXTERNAL_SYMBOL ::=
8101 -- | static_string_EXPRESSION
8103 -- PARAMETER_TYPES ::=
8105 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8107 -- TYPE_DESIGNATOR ::=
8109 -- | subtype_Name ' Access
8113 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8115 -- MECHANISM_ASSOCIATION ::=
8116 -- [formal_parameter_NAME =>] MECHANISM_NAME
8118 -- MECHANISM_NAME ::=
8121 -- | Descriptor [([Class =>] CLASS_NAME)]
8123 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8125 when Pragma_Import_Function => Import_Function : declare
8126 Args : Args_List (1 .. 7);
8127 Names : constant Name_List (1 .. 7) := (
8130 Name_Parameter_Types,
8133 Name_Result_Mechanism,
8134 Name_First_Optional_Parameter);
8136 Internal : Node_Id renames Args (1);
8137 External : Node_Id renames Args (2);
8138 Parameter_Types : Node_Id renames Args (3);
8139 Result_Type : Node_Id renames Args (4);
8140 Mechanism : Node_Id renames Args (5);
8141 Result_Mechanism : Node_Id renames Args (6);
8142 First_Optional_Parameter : Node_Id renames Args (7);
8146 Gather_Associations (Names, Args);
8147 Process_Extended_Import_Export_Subprogram_Pragma (
8148 Arg_Internal => Internal,
8149 Arg_External => External,
8150 Arg_Parameter_Types => Parameter_Types,
8151 Arg_Result_Type => Result_Type,
8152 Arg_Mechanism => Mechanism,
8153 Arg_Result_Mechanism => Result_Mechanism,
8154 Arg_First_Optional_Parameter => First_Optional_Parameter);
8155 end Import_Function;
8161 -- pragma Import_Object (
8162 -- [Internal =>] LOCAL_NAME
8163 -- [, [External =>] EXTERNAL_SYMBOL]
8164 -- [, [Size =>] EXTERNAL_SYMBOL]);
8166 -- EXTERNAL_SYMBOL ::=
8168 -- | static_string_EXPRESSION
8170 when Pragma_Import_Object => Import_Object : declare
8171 Args : Args_List (1 .. 3);
8172 Names : constant Name_List (1 .. 3) := (
8177 Internal : Node_Id renames Args (1);
8178 External : Node_Id renames Args (2);
8179 Size : Node_Id renames Args (3);
8183 Gather_Associations (Names, Args);
8184 Process_Extended_Import_Export_Object_Pragma (
8185 Arg_Internal => Internal,
8186 Arg_External => External,
8190 ----------------------
8191 -- Import_Procedure --
8192 ----------------------
8194 -- pragma Import_Procedure (
8195 -- [Internal =>] LOCAL_NAME
8196 -- [, [External =>] EXTERNAL_SYMBOL]
8197 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8198 -- [, [Mechanism =>] MECHANISM]
8199 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8201 -- EXTERNAL_SYMBOL ::=
8203 -- | static_string_EXPRESSION
8205 -- PARAMETER_TYPES ::=
8207 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8209 -- TYPE_DESIGNATOR ::=
8211 -- | subtype_Name ' Access
8215 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8217 -- MECHANISM_ASSOCIATION ::=
8218 -- [formal_parameter_NAME =>] MECHANISM_NAME
8220 -- MECHANISM_NAME ::=
8223 -- | Descriptor [([Class =>] CLASS_NAME)]
8225 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8227 when Pragma_Import_Procedure => Import_Procedure : declare
8228 Args : Args_List (1 .. 5);
8229 Names : constant Name_List (1 .. 5) := (
8232 Name_Parameter_Types,
8234 Name_First_Optional_Parameter);
8236 Internal : Node_Id renames Args (1);
8237 External : Node_Id renames Args (2);
8238 Parameter_Types : Node_Id renames Args (3);
8239 Mechanism : Node_Id renames Args (4);
8240 First_Optional_Parameter : Node_Id renames Args (5);
8244 Gather_Associations (Names, Args);
8245 Process_Extended_Import_Export_Subprogram_Pragma (
8246 Arg_Internal => Internal,
8247 Arg_External => External,
8248 Arg_Parameter_Types => Parameter_Types,
8249 Arg_Mechanism => Mechanism,
8250 Arg_First_Optional_Parameter => First_Optional_Parameter);
8251 end Import_Procedure;
8253 -----------------------------
8254 -- Import_Valued_Procedure --
8255 -----------------------------
8257 -- pragma Import_Valued_Procedure (
8258 -- [Internal =>] LOCAL_NAME
8259 -- [, [External =>] EXTERNAL_SYMBOL]
8260 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8261 -- [, [Mechanism =>] MECHANISM]
8262 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8264 -- EXTERNAL_SYMBOL ::=
8266 -- | static_string_EXPRESSION
8268 -- PARAMETER_TYPES ::=
8270 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8272 -- TYPE_DESIGNATOR ::=
8274 -- | subtype_Name ' Access
8278 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8280 -- MECHANISM_ASSOCIATION ::=
8281 -- [formal_parameter_NAME =>] MECHANISM_NAME
8283 -- MECHANISM_NAME ::=
8286 -- | Descriptor [([Class =>] CLASS_NAME)]
8288 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8290 when Pragma_Import_Valued_Procedure =>
8291 Import_Valued_Procedure : declare
8292 Args : Args_List (1 .. 5);
8293 Names : constant Name_List (1 .. 5) := (
8296 Name_Parameter_Types,
8298 Name_First_Optional_Parameter);
8300 Internal : Node_Id renames Args (1);
8301 External : Node_Id renames Args (2);
8302 Parameter_Types : Node_Id renames Args (3);
8303 Mechanism : Node_Id renames Args (4);
8304 First_Optional_Parameter : Node_Id renames Args (5);
8308 Gather_Associations (Names, Args);
8309 Process_Extended_Import_Export_Subprogram_Pragma (
8310 Arg_Internal => Internal,
8311 Arg_External => External,
8312 Arg_Parameter_Types => Parameter_Types,
8313 Arg_Mechanism => Mechanism,
8314 Arg_First_Optional_Parameter => First_Optional_Parameter);
8315 end Import_Valued_Procedure;
8317 ------------------------
8318 -- Initialize_Scalars --
8319 ------------------------
8321 -- pragma Initialize_Scalars;
8323 when Pragma_Initialize_Scalars =>
8325 Check_Arg_Count (0);
8326 Check_Valid_Configuration_Pragma;
8327 Check_Restriction (No_Initialize_Scalars, N);
8329 -- Initialize_Scalars creates false positives in CodePeer,
8330 -- so ignore this pragma in this mode.
8332 if not Restriction_Active (No_Initialize_Scalars)
8333 and then not CodePeer_Mode
8335 Init_Or_Norm_Scalars := True;
8336 Initialize_Scalars := True;
8343 -- pragma Inline ( NAME {, NAME} );
8345 when Pragma_Inline =>
8347 -- Pragma is active if inlining option is active
8349 Process_Inline (Inline_Active);
8355 -- pragma Inline_Always ( NAME {, NAME} );
8357 when Pragma_Inline_Always =>
8360 -- Pragma always active unless in CodePeer mode, since this causes
8361 -- walk order issues.
8363 if not CodePeer_Mode then
8364 Process_Inline (True);
8367 --------------------
8368 -- Inline_Generic --
8369 --------------------
8371 -- pragma Inline_Generic (NAME {, NAME});
8373 when Pragma_Inline_Generic =>
8375 Process_Generic_List;
8377 ----------------------
8378 -- Inspection_Point --
8379 ----------------------
8381 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8383 when Pragma_Inspection_Point => Inspection_Point : declare
8388 if Arg_Count > 0 then
8391 Exp := Expression (Arg);
8394 if not Is_Entity_Name (Exp)
8395 or else not Is_Object (Entity (Exp))
8397 Error_Pragma_Arg ("object name required", Arg);
8404 end Inspection_Point;
8410 -- pragma Interface (
8411 -- [ Convention =>] convention_IDENTIFIER,
8412 -- [ Entity =>] local_NAME
8413 -- [, [External_Name =>] static_string_EXPRESSION ]
8414 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8416 when Pragma_Interface =>
8423 Check_At_Least_N_Arguments (2);
8424 Check_At_Most_N_Arguments (4);
8425 Process_Import_Or_Interface;
8427 -- In Ada 2005, the permission to use Interface (a reserved word)
8428 -- as a pragma name is considered an obsolescent feature.
8430 if Ada_Version >= Ada_2005 then
8432 (No_Obsolescent_Features, Pragma_Identifier (N));
8435 --------------------
8436 -- Interface_Name --
8437 --------------------
8439 -- pragma Interface_Name (
8440 -- [ Entity =>] local_NAME
8441 -- [,[External_Name =>] static_string_EXPRESSION ]
8442 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8444 when Pragma_Interface_Name => Interface_Name : declare
8453 ((Name_Entity, Name_External_Name, Name_Link_Name));
8454 Check_At_Least_N_Arguments (2);
8455 Check_At_Most_N_Arguments (3);
8456 Id := Expression (Arg1);
8459 if not Is_Entity_Name (Id) then
8461 ("first argument for pragma% must be entity name", Arg1);
8462 elsif Etype (Id) = Any_Type then
8465 Def_Id := Entity (Id);
8468 -- Special DEC-compatible processing for the object case, forces
8469 -- object to be imported.
8471 if Ekind (Def_Id) = E_Variable then
8472 Kill_Size_Check_Code (Def_Id);
8473 Note_Possible_Modification (Id, Sure => False);
8475 -- Initialization is not allowed for imported variable
8477 if Present (Expression (Parent (Def_Id)))
8478 and then Comes_From_Source (Expression (Parent (Def_Id)))
8480 Error_Msg_Sloc := Sloc (Def_Id);
8482 ("no initialization allowed for declaration of& #",
8486 -- For compatibility, support VADS usage of providing both
8487 -- pragmas Interface and Interface_Name to obtain the effect
8488 -- of a single Import pragma.
8490 if Is_Imported (Def_Id)
8491 and then Present (First_Rep_Item (Def_Id))
8492 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8494 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8498 Set_Imported (Def_Id);
8501 Set_Is_Public (Def_Id);
8502 Process_Interface_Name (Def_Id, Arg2, Arg3);
8505 -- Otherwise must be subprogram
8507 elsif not Is_Subprogram (Def_Id) then
8509 ("argument of pragma% is not subprogram", Arg1);
8512 Check_At_Most_N_Arguments (3);
8516 -- Loop through homonyms
8519 Def_Id := Get_Base_Subprogram (Hom_Id);
8521 if Is_Imported (Def_Id) then
8522 Process_Interface_Name (Def_Id, Arg2, Arg3);
8526 Hom_Id := Homonym (Hom_Id);
8528 exit when No (Hom_Id)
8529 or else Scope (Hom_Id) /= Current_Scope;
8534 ("argument of pragma% is not imported subprogram",
8540 -----------------------
8541 -- Interrupt_Handler --
8542 -----------------------
8544 -- pragma Interrupt_Handler (handler_NAME);
8546 when Pragma_Interrupt_Handler =>
8547 Check_Ada_83_Warning;
8548 Check_Arg_Count (1);
8549 Check_No_Identifiers;
8551 if No_Run_Time_Mode then
8552 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8554 Check_Interrupt_Or_Attach_Handler;
8555 Process_Interrupt_Or_Attach_Handler;
8558 ------------------------
8559 -- Interrupt_Priority --
8560 ------------------------
8562 -- pragma Interrupt_Priority [(EXPRESSION)];
8564 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8565 P : constant Node_Id := Parent (N);
8569 Check_Ada_83_Warning;
8571 if Arg_Count /= 0 then
8572 Arg := Expression (Arg1);
8573 Check_Arg_Count (1);
8574 Check_No_Identifiers;
8576 -- The expression must be analyzed in the special manner
8577 -- described in "Handling of Default and Per-Object
8578 -- Expressions" in sem.ads.
8580 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8583 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8587 elsif Has_Priority_Pragma (P) then
8588 Error_Pragma ("duplicate pragma% not allowed");
8591 Set_Has_Priority_Pragma (P, True);
8592 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8594 end Interrupt_Priority;
8596 ---------------------
8597 -- Interrupt_State --
8598 ---------------------
8600 -- pragma Interrupt_State (
8601 -- [Name =>] INTERRUPT_ID,
8602 -- [State =>] INTERRUPT_STATE);
8604 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8605 -- INTERRUPT_STATE => System | Runtime | User
8607 -- Note: if the interrupt id is given as an identifier, then it must
8608 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8609 -- given as a static integer expression which must be in the range of
8610 -- Ada.Interrupts.Interrupt_ID.
8612 when Pragma_Interrupt_State => Interrupt_State : declare
8614 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8615 -- This is the entity Ada.Interrupts.Interrupt_ID;
8617 State_Type : Character;
8618 -- Set to 's'/'r'/'u' for System/Runtime/User
8621 -- Index to entry in Interrupt_States table
8624 -- Value of interrupt
8626 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8627 -- The first argument to the pragma
8629 Int_Ent : Entity_Id;
8630 -- Interrupt entity in Ada.Interrupts.Names
8634 Check_Arg_Order ((Name_Name, Name_State));
8635 Check_Arg_Count (2);
8637 Check_Optional_Identifier (Arg1, Name_Name);
8638 Check_Optional_Identifier (Arg2, Name_State);
8639 Check_Arg_Is_Identifier (Arg2);
8641 -- First argument is identifier
8643 if Nkind (Arg1X) = N_Identifier then
8645 -- Search list of names in Ada.Interrupts.Names
8647 Int_Ent := First_Entity (RTE (RE_Names));
8649 if No (Int_Ent) then
8650 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8652 elsif Chars (Int_Ent) = Chars (Arg1X) then
8653 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8657 Next_Entity (Int_Ent);
8660 -- First argument is not an identifier, so it must be a static
8661 -- expression of type Ada.Interrupts.Interrupt_ID.
8664 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8665 Int_Val := Expr_Value (Arg1X);
8667 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8669 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8672 ("value not in range of type " &
8673 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8679 case Chars (Get_Pragma_Arg (Arg2)) is
8680 when Name_Runtime => State_Type := 'r';
8681 when Name_System => State_Type := 's';
8682 when Name_User => State_Type := 'u';
8685 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8688 -- Check if entry is already stored
8690 IST_Num := Interrupt_States.First;
8692 -- If entry not found, add it
8694 if IST_Num > Interrupt_States.Last then
8695 Interrupt_States.Append
8696 ((Interrupt_Number => UI_To_Int (Int_Val),
8697 Interrupt_State => State_Type,
8698 Pragma_Loc => Loc));
8701 -- Case of entry for the same entry
8703 elsif Int_Val = Interrupt_States.Table (IST_Num).
8706 -- If state matches, done, no need to make redundant entry
8709 State_Type = Interrupt_States.Table (IST_Num).
8712 -- Otherwise if state does not match, error
8715 Interrupt_States.Table (IST_Num).Pragma_Loc;
8717 ("state conflicts with that given #", Arg2);
8721 IST_Num := IST_Num + 1;
8723 end Interrupt_State;
8725 ----------------------
8726 -- Java_Constructor --
8727 ----------------------
8729 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8731 -- Also handles pragma CIL_Constructor
8733 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8734 Java_Constructor : declare
8738 Convention : Convention_Id;
8742 Check_Arg_Count (1);
8743 Check_Optional_Identifier (Arg1, Name_Entity);
8744 Check_Arg_Is_Local_Name (Arg1);
8746 Id := Expression (Arg1);
8747 Find_Program_Unit_Name (Id);
8749 -- If we did not find the name, we are done
8751 if Etype (Id) = Any_Type then
8756 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8757 when Pragma_Java_Constructor => Convention := Convention_Java;
8758 when others => null;
8761 Hom_Id := Entity (Id);
8763 -- Loop through homonyms
8766 Def_Id := Get_Base_Subprogram (Hom_Id);
8768 -- The constructor is required to be a function returning an
8769 -- access type whose designated type has convention Java/CIL.
8771 if Ekind (Def_Id) = E_Function
8773 (Is_Value_Type (Etype (Def_Id))
8775 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8777 Atree.Convention (Etype (Def_Id)) = Convention)
8779 (Ekind (Etype (Def_Id)) in Access_Kind
8782 (Designated_Type (Etype (Def_Id))) = Convention
8785 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8788 Set_Is_Constructor (Def_Id);
8789 Set_Convention (Def_Id, Convention);
8790 Set_Is_Imported (Def_Id);
8793 if Convention = Convention_Java then
8795 ("pragma% requires function returning a " &
8796 "'Java access type", Arg1);
8798 pragma Assert (Convention = Convention_CIL);
8800 ("pragma% requires function returning a " &
8801 "'C'I'L access type", Arg1);
8805 Hom_Id := Homonym (Hom_Id);
8807 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8809 end Java_Constructor;
8811 ----------------------
8812 -- Java_Interface --
8813 ----------------------
8815 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8817 when Pragma_Java_Interface => Java_Interface : declare
8823 Check_Arg_Count (1);
8824 Check_Optional_Identifier (Arg1, Name_Entity);
8825 Check_Arg_Is_Local_Name (Arg1);
8827 Arg := Expression (Arg1);
8830 if Etype (Arg) = Any_Type then
8834 if not Is_Entity_Name (Arg)
8835 or else not Is_Type (Entity (Arg))
8837 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8840 Typ := Underlying_Type (Entity (Arg));
8842 -- For now simply check some of the semantic constraints on the
8843 -- type. This currently leaves out some restrictions on interface
8844 -- types, namely that the parent type must be java.lang.Object.Typ
8845 -- and that all primitives of the type should be declared
8848 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8849 Error_Pragma_Arg ("pragma% requires an abstract "
8850 & "tagged type", Arg1);
8852 elsif not Has_Discriminants (Typ)
8853 or else Ekind (Etype (First_Discriminant (Typ)))
8854 /= E_Anonymous_Access_Type
8856 not Is_Class_Wide_Type
8857 (Designated_Type (Etype (First_Discriminant (Typ))))
8860 ("type must have a class-wide access discriminant", Arg1);
8868 -- pragma Keep_Names ([On => ] local_NAME);
8870 when Pragma_Keep_Names => Keep_Names : declare
8875 Check_Arg_Count (1);
8876 Check_Optional_Identifier (Arg1, Name_On);
8877 Check_Arg_Is_Local_Name (Arg1);
8879 Arg := Expression (Arg1);
8882 if Etype (Arg) = Any_Type then
8886 if not Is_Entity_Name (Arg)
8887 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8890 ("pragma% requires a local enumeration type", Arg1);
8893 Set_Discard_Names (Entity (Arg), False);
8900 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8902 when Pragma_License =>
8904 Check_Arg_Count (1);
8905 Check_No_Identifiers;
8906 Check_Valid_Configuration_Pragma;
8907 Check_Arg_Is_Identifier (Arg1);
8910 Sind : constant Source_File_Index :=
8911 Source_Index (Current_Sem_Unit);
8914 case Chars (Get_Pragma_Arg (Arg1)) is
8916 Set_License (Sind, GPL);
8918 when Name_Modified_GPL =>
8919 Set_License (Sind, Modified_GPL);
8921 when Name_Restricted =>
8922 Set_License (Sind, Restricted);
8924 when Name_Unrestricted =>
8925 Set_License (Sind, Unrestricted);
8928 Error_Pragma_Arg ("invalid license name", Arg1);
8936 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8938 when Pragma_Link_With => Link_With : declare
8944 if Operating_Mode = Generate_Code
8945 and then In_Extended_Main_Source_Unit (N)
8947 Check_At_Least_N_Arguments (1);
8948 Check_No_Identifiers;
8949 Check_Is_In_Decl_Part_Or_Package_Spec;
8950 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8954 while Present (Arg) loop
8955 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8957 -- Store argument, converting sequences of spaces to a
8958 -- single null character (this is one of the differences
8959 -- in processing between Link_With and Linker_Options).
8962 C : constant Char_Code := Get_Char_Code (' ');
8963 S : constant String_Id :=
8964 Strval (Expr_Value_S (Expression (Arg)));
8965 L : constant Nat := String_Length (S);
8968 procedure Skip_Spaces;
8969 -- Advance F past any spaces
8975 procedure Skip_Spaces is
8977 while F <= L and then Get_String_Char (S, F) = C loop
8982 -- Start of processing for Arg_Store
8985 Skip_Spaces; -- skip leading spaces
8987 -- Loop through characters, changing any embedded
8988 -- sequence of spaces to a single null character (this
8989 -- is how Link_With/Linker_Options differ)
8992 if Get_String_Char (S, F) = C then
8995 Store_String_Char (ASCII.NUL);
8998 Store_String_Char (Get_String_Char (S, F));
9006 if Present (Arg) then
9007 Store_String_Char (ASCII.NUL);
9011 Store_Linker_Option_String (End_String);
9019 -- pragma Linker_Alias (
9020 -- [Entity =>] LOCAL_NAME
9021 -- [Target =>] static_string_EXPRESSION);
9023 when Pragma_Linker_Alias =>
9025 Check_Arg_Order ((Name_Entity, Name_Target));
9026 Check_Arg_Count (2);
9027 Check_Optional_Identifier (Arg1, Name_Entity);
9028 Check_Optional_Identifier (Arg2, Name_Target);
9029 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9030 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9032 -- The only processing required is to link this item on to the
9033 -- list of rep items for the given entity. This is accomplished
9034 -- by the call to Rep_Item_Too_Late (when no error is detected
9035 -- and False is returned).
9037 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9040 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9043 ------------------------
9044 -- Linker_Constructor --
9045 ------------------------
9047 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
9049 -- Code is shared with Linker_Destructor
9051 -----------------------
9052 -- Linker_Destructor --
9053 -----------------------
9055 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
9057 when Pragma_Linker_Constructor |
9058 Pragma_Linker_Destructor =>
9059 Linker_Constructor : declare
9065 Check_Arg_Count (1);
9066 Check_No_Identifiers;
9067 Check_Arg_Is_Local_Name (Arg1);
9068 Arg1_X := Expression (Arg1);
9070 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
9072 if not Is_Library_Level_Entity (Proc) then
9074 ("argument for pragma% must be library level entity", Arg1);
9077 -- The only processing required is to link this item on to the
9078 -- list of rep items for the given entity. This is accomplished
9079 -- by the call to Rep_Item_Too_Late (when no error is detected
9080 -- and False is returned).
9082 if Rep_Item_Too_Late (Proc, N) then
9085 Set_Has_Gigi_Rep_Item (Proc);
9087 end Linker_Constructor;
9089 --------------------
9090 -- Linker_Options --
9091 --------------------
9093 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
9095 when Pragma_Linker_Options => Linker_Options : declare
9099 Check_Ada_83_Warning;
9100 Check_No_Identifiers;
9101 Check_Arg_Count (1);
9102 Check_Is_In_Decl_Part_Or_Package_Spec;
9103 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9104 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
9107 while Present (Arg) loop
9108 Check_Arg_Is_Static_Expression (Arg, Standard_String);
9109 Store_String_Char (ASCII.NUL);
9110 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
9114 if Operating_Mode = Generate_Code
9115 and then In_Extended_Main_Source_Unit (N)
9117 Store_Linker_Option_String (End_String);
9121 --------------------
9122 -- Linker_Section --
9123 --------------------
9125 -- pragma Linker_Section (
9126 -- [Entity =>] LOCAL_NAME
9127 -- [Section =>] static_string_EXPRESSION);
9129 when Pragma_Linker_Section =>
9131 Check_Arg_Order ((Name_Entity, Name_Section));
9132 Check_Arg_Count (2);
9133 Check_Optional_Identifier (Arg1, Name_Entity);
9134 Check_Optional_Identifier (Arg2, Name_Section);
9135 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9136 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9138 -- This pragma applies only to objects
9140 if not Is_Object (Entity (Expression (Arg1))) then
9141 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
9144 -- The only processing required is to link this item on to the
9145 -- list of rep items for the given entity. This is accomplished
9146 -- by the call to Rep_Item_Too_Late (when no error is detected
9147 -- and False is returned).
9149 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
9152 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9159 -- pragma List (On | Off)
9161 -- There is nothing to do here, since we did all the processing for
9162 -- this pragma in Par.Prag (so that it works properly even in syntax
9168 --------------------
9169 -- Locking_Policy --
9170 --------------------
9172 -- pragma Locking_Policy (policy_IDENTIFIER);
9174 when Pragma_Locking_Policy => declare
9178 Check_Ada_83_Warning;
9179 Check_Arg_Count (1);
9180 Check_No_Identifiers;
9181 Check_Arg_Is_Locking_Policy (Arg1);
9182 Check_Valid_Configuration_Pragma;
9183 Get_Name_String (Chars (Expression (Arg1)));
9184 LP := Fold_Upper (Name_Buffer (1));
9186 if Locking_Policy /= ' '
9187 and then Locking_Policy /= LP
9189 Error_Msg_Sloc := Locking_Policy_Sloc;
9190 Error_Pragma ("locking policy incompatible with policy#");
9192 -- Set new policy, but always preserve System_Location since we
9193 -- like the error message with the run time name.
9196 Locking_Policy := LP;
9198 if Locking_Policy_Sloc /= System_Location then
9199 Locking_Policy_Sloc := Loc;
9208 -- pragma Long_Float (D_Float | G_Float);
9210 when Pragma_Long_Float =>
9212 Check_Valid_Configuration_Pragma;
9213 Check_Arg_Count (1);
9214 Check_No_Identifier (Arg1);
9215 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
9217 if not OpenVMS_On_Target then
9218 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
9223 if Chars (Expression (Arg1)) = Name_D_Float then
9224 if Opt.Float_Format_Long = 'G' then
9225 Error_Pragma ("G_Float previously specified");
9228 Opt.Float_Format_Long := 'D';
9230 -- G_Float case (this is the default, does not need overriding)
9233 if Opt.Float_Format_Long = 'D' then
9234 Error_Pragma ("D_Float previously specified");
9237 Opt.Float_Format_Long := 'G';
9240 Set_Standard_Fpt_Formats;
9242 -----------------------
9243 -- Machine_Attribute --
9244 -----------------------
9246 -- pragma Machine_Attribute (
9247 -- [Entity =>] LOCAL_NAME,
9248 -- [Attribute_Name =>] static_string_EXPRESSION
9249 -- [, [Info =>] static_EXPRESSION] );
9251 when Pragma_Machine_Attribute => Machine_Attribute : declare
9256 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
9258 if Arg_Count = 3 then
9259 Check_Optional_Identifier (Arg3, Name_Info);
9260 Check_Arg_Is_Static_Expression (Arg3);
9262 Check_Arg_Count (2);
9265 Check_Optional_Identifier (Arg1, Name_Entity);
9266 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
9267 Check_Arg_Is_Local_Name (Arg1);
9268 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
9269 Def_Id := Entity (Expression (Arg1));
9271 if Is_Access_Type (Def_Id) then
9272 Def_Id := Designated_Type (Def_Id);
9275 if Rep_Item_Too_Early (Def_Id, N) then
9279 Def_Id := Underlying_Type (Def_Id);
9281 -- The only processing required is to link this item on to the
9282 -- list of rep items for the given entity. This is accomplished
9283 -- by the call to Rep_Item_Too_Late (when no error is detected
9284 -- and False is returned).
9286 if Rep_Item_Too_Late (Def_Id, N) then
9289 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
9291 end Machine_Attribute;
9298 -- (MAIN_OPTION [, MAIN_OPTION]);
9301 -- [STACK_SIZE =>] static_integer_EXPRESSION
9302 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
9303 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
9305 when Pragma_Main => Main : declare
9306 Args : Args_List (1 .. 3);
9307 Names : constant Name_List (1 .. 3) := (
9309 Name_Task_Stack_Size_Default,
9310 Name_Time_Slicing_Enabled);
9316 Gather_Associations (Names, Args);
9318 for J in 1 .. 2 loop
9319 if Present (Args (J)) then
9320 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9324 if Present (Args (3)) then
9325 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
9329 while Present (Nod) loop
9330 if Nkind (Nod) = N_Pragma
9331 and then Pragma_Name (Nod) = Name_Main
9333 Error_Msg_Name_1 := Pname;
9334 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9345 -- pragma Main_Storage
9346 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
9348 -- MAIN_STORAGE_OPTION ::=
9349 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
9350 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
9352 when Pragma_Main_Storage => Main_Storage : declare
9353 Args : Args_List (1 .. 2);
9354 Names : constant Name_List (1 .. 2) := (
9355 Name_Working_Storage,
9362 Gather_Associations (Names, Args);
9364 for J in 1 .. 2 loop
9365 if Present (Args (J)) then
9366 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
9370 Check_In_Main_Program;
9373 while Present (Nod) loop
9374 if Nkind (Nod) = N_Pragma
9375 and then Pragma_Name (Nod) = Name_Main_Storage
9377 Error_Msg_Name_1 := Pname;
9378 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9389 -- pragma Memory_Size (NUMERIC_LITERAL)
9391 when Pragma_Memory_Size =>
9394 -- Memory size is simply ignored
9396 Check_No_Identifiers;
9397 Check_Arg_Count (1);
9398 Check_Arg_Is_Integer_Literal (Arg1);
9406 -- The only correct use of this pragma is on its own in a file, in
9407 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9408 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9409 -- check for a file containing nothing but a No_Body pragma). If we
9410 -- attempt to process it during normal semantics processing, it means
9411 -- it was misplaced.
9413 when Pragma_No_Body =>
9421 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9423 when Pragma_No_Return => No_Return : declare
9431 Check_At_Least_N_Arguments (1);
9433 -- Loop through arguments of pragma
9436 while Present (Arg) loop
9437 Check_Arg_Is_Local_Name (Arg);
9438 Id := Expression (Arg);
9441 if not Is_Entity_Name (Id) then
9442 Error_Pragma_Arg ("entity name required", Arg);
9445 if Etype (Id) = Any_Type then
9449 -- Loop to find matching procedures
9454 and then Scope (E) = Current_Scope
9456 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
9459 -- Set flag on any alias as well
9461 if Is_Overloadable (E) and then Present (Alias (E)) then
9462 Set_No_Return (Alias (E));
9472 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9483 -- pragma No_Run_Time;
9485 -- Note: this pragma is retained for backwards compatibility. See
9486 -- body of Rtsfind for full details on its handling.
9488 when Pragma_No_Run_Time =>
9490 Check_Valid_Configuration_Pragma;
9491 Check_Arg_Count (0);
9493 No_Run_Time_Mode := True;
9494 Configurable_Run_Time_Mode := True;
9496 -- Set Duration to 32 bits if word size is 32
9498 if Ttypes.System_Word_Size = 32 then
9499 Duration_32_Bits_On_Target := True;
9502 -- Set appropriate restrictions
9504 Set_Restriction (No_Finalization, N);
9505 Set_Restriction (No_Exception_Handlers, N);
9506 Set_Restriction (Max_Tasks, N, 0);
9507 Set_Restriction (No_Tasking, N);
9509 ------------------------
9510 -- No_Strict_Aliasing --
9511 ------------------------
9513 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9515 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9520 Check_At_Most_N_Arguments (1);
9522 if Arg_Count = 0 then
9523 Check_Valid_Configuration_Pragma;
9524 Opt.No_Strict_Aliasing := True;
9527 Check_Optional_Identifier (Arg2, Name_Entity);
9528 Check_Arg_Is_Local_Name (Arg1);
9529 E_Id := Entity (Expression (Arg1));
9531 if E_Id = Any_Type then
9533 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9534 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9537 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9539 end No_Strict_Aliasing;
9541 -----------------------
9542 -- Normalize_Scalars --
9543 -----------------------
9545 -- pragma Normalize_Scalars;
9547 when Pragma_Normalize_Scalars =>
9548 Check_Ada_83_Warning;
9549 Check_Arg_Count (0);
9550 Check_Valid_Configuration_Pragma;
9552 -- Normalize_Scalars creates false positives in CodePeer, so
9553 -- ignore this pragma in this mode.
9555 if not CodePeer_Mode then
9556 Normalize_Scalars := True;
9557 Init_Or_Norm_Scalars := True;
9564 -- pragma Obsolescent;
9566 -- pragma Obsolescent (
9567 -- [Message =>] static_string_EXPRESSION
9568 -- [,[Version =>] Ada_05]]);
9570 -- pragma Obsolescent (
9572 -- [,[Message =>] static_string_EXPRESSION
9573 -- [,[Version =>] Ada_05]] );
9575 when Pragma_Obsolescent => Obsolescent : declare
9579 procedure Set_Obsolescent (E : Entity_Id);
9580 -- Given an entity Ent, mark it as obsolescent if appropriate
9582 ---------------------
9583 -- Set_Obsolescent --
9584 ---------------------
9586 procedure Set_Obsolescent (E : Entity_Id) is
9595 -- Entity name was given
9597 if Present (Ename) then
9599 -- If entity name matches, we are fine. Save entity in
9600 -- pragma argument, for ASIS use.
9602 if Chars (Ename) = Chars (Ent) then
9603 Set_Entity (Ename, Ent);
9604 Generate_Reference (Ent, Ename);
9606 -- If entity name does not match, only possibility is an
9607 -- enumeration literal from an enumeration type declaration.
9609 elsif Ekind (Ent) /= E_Enumeration_Type then
9611 ("pragma % entity name does not match declaration");
9614 Ent := First_Literal (E);
9618 ("pragma % entity name does not match any " &
9619 "enumeration literal");
9621 elsif Chars (Ent) = Chars (Ename) then
9622 Set_Entity (Ename, Ent);
9623 Generate_Reference (Ent, Ename);
9627 Ent := Next_Literal (Ent);
9633 -- Ent points to entity to be marked
9635 if Arg_Count >= 1 then
9637 -- Deal with static string argument
9639 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9640 S := Strval (Expression (Arg1));
9642 for J in 1 .. String_Length (S) loop
9643 if not In_Character_Range (Get_String_Char (S, J)) then
9645 ("pragma% argument does not allow wide characters",
9650 Obsolescent_Warnings.Append
9651 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9653 -- Check for Ada_05 parameter
9655 if Arg_Count /= 1 then
9656 Check_Arg_Count (2);
9659 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9662 Check_Arg_Is_Identifier (Argx);
9664 if Chars (Argx) /= Name_Ada_05 then
9665 Error_Msg_Name_2 := Name_Ada_05;
9667 ("only allowed argument for pragma% is %", Argx);
9670 if Ada_Version_Explicit < Ada_05
9671 or else not Warn_On_Ada_2005_Compatibility
9679 -- Set flag if pragma active
9682 Set_Is_Obsolescent (Ent);
9686 end Set_Obsolescent;
9688 -- Start of processing for pragma Obsolescent
9693 Check_At_Most_N_Arguments (3);
9695 -- See if first argument specifies an entity name
9699 (Chars (Arg1) = Name_Entity
9701 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9705 Ename := Get_Pragma_Arg (Arg1);
9707 -- Eliminate first argument, so we can share processing
9711 Arg_Count := Arg_Count - 1;
9713 -- No Entity name argument given
9719 if Arg_Count >= 1 then
9720 Check_Optional_Identifier (Arg1, Name_Message);
9722 if Arg_Count = 2 then
9723 Check_Optional_Identifier (Arg2, Name_Version);
9727 -- Get immediately preceding declaration
9730 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9734 -- Cases where we do not follow anything other than another pragma
9738 -- First case: library level compilation unit declaration with
9739 -- the pragma immediately following the declaration.
9741 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9743 (Defining_Entity (Unit (Parent (Parent (N)))));
9746 -- Case 2: library unit placement for package
9750 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9752 if Is_Package_Or_Generic_Package (Ent) then
9753 Set_Obsolescent (Ent);
9759 -- Cases where we must follow a declaration
9762 if Nkind (Decl) not in N_Declaration
9763 and then Nkind (Decl) not in N_Later_Decl_Item
9764 and then Nkind (Decl) not in N_Generic_Declaration
9765 and then Nkind (Decl) not in N_Renaming_Declaration
9768 ("pragma% misplaced, "
9769 & "must immediately follow a declaration");
9772 Set_Obsolescent (Defining_Entity (Decl));
9782 -- pragma Optimize (Time | Space | Off);
9784 -- The actual check for optimize is done in Gigi. Note that this
9785 -- pragma does not actually change the optimization setting, it
9786 -- simply checks that it is consistent with the pragma.
9788 when Pragma_Optimize =>
9789 Check_No_Identifiers;
9790 Check_Arg_Count (1);
9791 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9793 ------------------------
9794 -- Optimize_Alignment --
9795 ------------------------
9797 -- pragma Optimize_Alignment (Time | Space | Off);
9799 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
9801 Check_No_Identifiers;
9802 Check_Arg_Count (1);
9803 Check_Valid_Configuration_Pragma;
9806 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9810 Opt.Optimize_Alignment := 'T';
9812 Opt.Optimize_Alignment := 'S';
9814 Opt.Optimize_Alignment := 'O';
9816 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9820 -- Set indication that mode is set locally. If we are in fact in a
9821 -- configuration pragma file, this setting is harmless since the
9822 -- switch will get reset anyway at the start of each unit.
9824 Optimize_Alignment_Local := True;
9825 end Optimize_Alignment;
9831 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
9833 when Pragma_Ordered => Ordered : declare
9834 Assoc : constant Node_Id := Arg1;
9840 Check_No_Identifiers;
9841 Check_Arg_Count (1);
9842 Check_Arg_Is_Local_Name (Arg1);
9844 Type_Id := Expression (Assoc);
9845 Find_Type (Type_Id);
9846 Typ := Entity (Type_Id);
9848 if Typ = Any_Type then
9851 Typ := Underlying_Type (Typ);
9854 if not Is_Enumeration_Type (Typ) then
9855 Error_Pragma ("pragma% must specify enumeration type");
9858 Check_First_Subtype (Arg1);
9859 Set_Has_Pragma_Ordered (Base_Type (Typ));
9866 -- pragma Pack (first_subtype_LOCAL_NAME);
9868 when Pragma_Pack => Pack : declare
9869 Assoc : constant Node_Id := Arg1;
9874 Check_No_Identifiers;
9875 Check_Arg_Count (1);
9876 Check_Arg_Is_Local_Name (Arg1);
9878 Type_Id := Expression (Assoc);
9879 Find_Type (Type_Id);
9880 Typ := Entity (Type_Id);
9883 or else Rep_Item_Too_Early (Typ, N)
9887 Typ := Underlying_Type (Typ);
9890 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9891 Error_Pragma ("pragma% must specify array or record type");
9894 Check_First_Subtype (Arg1);
9896 if Has_Pragma_Pack (Typ) then
9897 Error_Pragma ("duplicate pragma%, only one allowed");
9901 elsif Is_Array_Type (Typ) then
9903 -- Pack not allowed for aliased or atomic components
9905 if Has_Aliased_Components (Base_Type (Typ)) then
9907 ("pragma% ignored, cannot pack aliased components?");
9909 elsif Has_Atomic_Components (Typ)
9910 or else Is_Atomic (Component_Type (Typ))
9913 ("?pragma% ignored, cannot pack atomic components");
9916 -- If we had an explicit component size given, then we do not
9917 -- let Pack override this given size. We also give a warning
9918 -- that Pack is being ignored unless we can tell for sure that
9919 -- the Pack would not have had any effect anyway.
9921 if Has_Component_Size_Clause (Typ) then
9922 if Known_Static_RM_Size (Component_Type (Typ))
9924 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9929 ("?pragma% ignored, explicit component size given");
9932 -- If no prior array component size given, Pack is effective
9935 if not Rep_Item_Too_Late (Typ, N) then
9937 -- In the context of static code analysis, we do not need
9938 -- complex front-end expansions related to pragma Pack,
9939 -- so disable handling of pragma Pack in this case.
9941 if CodePeer_Mode then
9944 -- For normal non-VM target, do the packing
9946 elsif VM_Target = No_VM then
9947 Set_Is_Packed (Base_Type (Typ));
9948 Set_Has_Pragma_Pack (Base_Type (Typ));
9949 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9951 -- If we ignore the pack, then warn about this, except
9952 -- that we suppress the warning in GNAT mode.
9954 elsif not GNAT_Mode then
9956 ("?pragma% ignored in this configuration");
9961 -- For record types, the pack is always effective
9963 else pragma Assert (Is_Record_Type (Typ));
9964 if not Rep_Item_Too_Late (Typ, N) then
9965 if VM_Target = No_VM then
9966 Set_Is_Packed (Base_Type (Typ));
9967 Set_Has_Pragma_Pack (Base_Type (Typ));
9968 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9970 elsif not GNAT_Mode then
9971 Error_Pragma ("?pragma% ignored in this configuration");
9983 -- There is nothing to do here, since we did all the processing for
9984 -- this pragma in Par.Prag (so that it works properly even in syntax
9994 -- pragma Passive [(PASSIVE_FORM)];
9996 -- PASSIVE_FORM ::= Semaphore | No
9998 when Pragma_Passive =>
10001 if Nkind (Parent (N)) /= N_Task_Definition then
10002 Error_Pragma ("pragma% must be within task definition");
10005 if Arg_Count /= 0 then
10006 Check_Arg_Count (1);
10007 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
10010 ----------------------------------
10011 -- Preelaborable_Initialization --
10012 ----------------------------------
10014 -- pragma Preelaborable_Initialization (DIRECT_NAME);
10016 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
10021 Check_Arg_Count (1);
10022 Check_No_Identifiers;
10023 Check_Arg_Is_Identifier (Arg1);
10024 Check_Arg_Is_Local_Name (Arg1);
10025 Check_First_Subtype (Arg1);
10026 Ent := Entity (Expression (Arg1));
10028 if not Is_Private_Type (Ent)
10029 and then not Is_Protected_Type (Ent)
10032 ("pragma % can only be applied to private or protected type",
10036 -- Give an error if the pragma is applied to a protected type that
10037 -- does not qualify (due to having entries, or due to components
10038 -- that do not qualify).
10040 if Is_Protected_Type (Ent)
10041 and then not Has_Preelaborable_Initialization (Ent)
10044 ("protected type & does not have preelaborable " &
10045 "initialization", Ent);
10047 -- Otherwise mark the type as definitely having preelaborable
10051 Set_Known_To_Have_Preelab_Init (Ent);
10054 if Has_Pragma_Preelab_Init (Ent)
10055 and then Warn_On_Redundant_Constructs
10057 Error_Pragma ("?duplicate pragma%!");
10059 Set_Has_Pragma_Preelab_Init (Ent);
10063 --------------------
10064 -- Persistent_BSS --
10065 --------------------
10067 when Pragma_Persistent_BSS => Persistent_BSS : declare
10074 Check_At_Most_N_Arguments (1);
10076 -- Case of application to specific object (one argument)
10078 if Arg_Count = 1 then
10079 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10081 if not Is_Entity_Name (Expression (Arg1))
10083 (Ekind (Entity (Expression (Arg1))) /= E_Variable
10084 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
10086 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
10089 Ent := Entity (Expression (Arg1));
10090 Decl := Parent (Ent);
10092 if Rep_Item_Too_Late (Ent, N) then
10096 if Present (Expression (Decl)) then
10098 ("object for pragma% cannot have initialization", Arg1);
10101 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
10103 ("object type for pragma% is not potentially persistent",
10108 Make_Linker_Section_Pragma
10109 (Ent, Sloc (N), ".persistent.bss");
10110 Insert_After (N, Prag);
10113 -- Case of use as configuration pragma with no arguments
10116 Check_Valid_Configuration_Pragma;
10117 Persistent_BSS_Mode := True;
10119 end Persistent_BSS;
10125 -- pragma Polling (ON | OFF);
10127 when Pragma_Polling =>
10129 Check_Arg_Count (1);
10130 Check_No_Identifiers;
10131 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
10132 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
10134 -------------------
10135 -- Postcondition --
10136 -------------------
10138 -- pragma Postcondition ([Check =>] Boolean_Expression
10139 -- [,[Message =>] String_Expression]);
10141 when Pragma_Postcondition => Postcondition : declare
10143 pragma Warnings (Off, In_Body);
10147 Check_At_Least_N_Arguments (1);
10148 Check_At_Most_N_Arguments (2);
10149 Check_Optional_Identifier (Arg1, Name_Check);
10151 -- All we need to do here is call the common check procedure,
10152 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
10154 Check_Precondition_Postcondition (In_Body);
10161 -- pragma Precondition ([Check =>] Boolean_Expression
10162 -- [,[Message =>] String_Expression]);
10164 when Pragma_Precondition => Precondition : declare
10169 Check_At_Least_N_Arguments (1);
10170 Check_At_Most_N_Arguments (2);
10171 Check_Optional_Identifier (Arg1, Name_Check);
10173 Check_Precondition_Postcondition (In_Body);
10175 -- If in spec, nothing more to do. If in body, then we convert the
10176 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
10177 -- this whether or not precondition checks are enabled. That works
10178 -- fine since pragma Check will do this check, and will also
10179 -- analyze the condition itself in the proper context.
10182 if Arg_Count = 2 then
10183 Check_Optional_Identifier (Arg3, Name_Message);
10184 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
10189 Chars => Name_Check,
10190 Pragma_Argument_Associations => New_List (
10191 Make_Pragma_Argument_Association (Loc,
10193 Make_Identifier (Loc,
10194 Chars => Name_Precondition)),
10196 Make_Pragma_Argument_Association (Sloc (Arg1),
10197 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
10199 if Arg_Count = 2 then
10200 Append_To (Pragma_Argument_Associations (N),
10201 Make_Pragma_Argument_Association (Sloc (Arg2),
10202 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
10213 -- pragma Preelaborate [(library_unit_NAME)];
10215 -- Set the flag Is_Preelaborated of program unit name entity
10217 when Pragma_Preelaborate => Preelaborate : declare
10218 Pa : constant Node_Id := Parent (N);
10219 Pk : constant Node_Kind := Nkind (Pa);
10223 Check_Ada_83_Warning;
10224 Check_Valid_Library_Unit_Pragma;
10226 if Nkind (N) = N_Null_Statement then
10230 Ent := Find_Lib_Unit_Name;
10232 -- This filters out pragmas inside generic parent then
10233 -- show up inside instantiation
10236 and then not (Pk = N_Package_Specification
10237 and then Present (Generic_Parent (Pa)))
10239 if not Debug_Flag_U then
10240 Set_Is_Preelaborated (Ent);
10241 Set_Suppress_Elaboration_Warnings (Ent);
10246 ---------------------
10247 -- Preelaborate_05 --
10248 ---------------------
10250 -- pragma Preelaborate_05 [(library_unit_NAME)];
10252 -- This pragma is useable only in GNAT_Mode, where it is used like
10253 -- pragma Preelaborate but it is only effective in Ada 2005 mode
10254 -- (otherwise it is ignored). This is used to implement AI-362 which
10255 -- recategorizes some run-time packages in Ada 2005 mode.
10257 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
10262 Check_Valid_Library_Unit_Pragma;
10264 if not GNAT_Mode then
10265 Error_Pragma ("pragma% only available in GNAT mode");
10268 if Nkind (N) = N_Null_Statement then
10272 -- This is one of the few cases where we need to test the value of
10273 -- Ada_Version_Explicit rather than Ada_Version (which is always
10274 -- set to Ada_12 in a predefined unit), we need to know the
10275 -- explicit version set to know if this pragma is active.
10277 if Ada_Version_Explicit >= Ada_05 then
10278 Ent := Find_Lib_Unit_Name;
10279 Set_Is_Preelaborated (Ent);
10280 Set_Suppress_Elaboration_Warnings (Ent);
10282 end Preelaborate_05;
10288 -- pragma Priority (EXPRESSION);
10290 when Pragma_Priority => Priority : declare
10291 P : constant Node_Id := Parent (N);
10295 Check_No_Identifiers;
10296 Check_Arg_Count (1);
10300 if Nkind (P) = N_Subprogram_Body then
10301 Check_In_Main_Program;
10303 Arg := Expression (Arg1);
10304 Analyze_And_Resolve (Arg, Standard_Integer);
10308 if not Is_Static_Expression (Arg) then
10309 Flag_Non_Static_Expr
10310 ("main subprogram priority is not static!", Arg);
10313 -- If constraint error, then we already signalled an error
10315 elsif Raises_Constraint_Error (Arg) then
10318 -- Otherwise check in range
10322 Val : constant Uint := Expr_Value (Arg);
10326 or else Val > Expr_Value (Expression
10327 (Parent (RTE (RE_Max_Priority))))
10330 ("main subprogram priority is out of range", Arg1);
10336 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10338 -- Load an arbitrary entity from System.Tasking to make sure
10339 -- this package is implicitly with'ed, since we need to have
10340 -- the tasking run-time active for the pragma Priority to have
10344 Discard : Entity_Id;
10345 pragma Warnings (Off, Discard);
10347 Discard := RTE (RE_Task_List);
10350 -- Task or Protected, must be of type Integer
10352 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10353 Arg := Expression (Arg1);
10355 -- The expression must be analyzed in the special manner
10356 -- described in "Handling of Default and Per-Object
10357 -- Expressions" in sem.ads.
10359 Preanalyze_Spec_Expression (Arg, Standard_Integer);
10361 if not Is_Static_Expression (Arg) then
10362 Check_Restriction (Static_Priorities, Arg);
10365 -- Anything else is incorrect
10371 if Has_Priority_Pragma (P) then
10372 Error_Pragma ("duplicate pragma% not allowed");
10374 Set_Has_Priority_Pragma (P, True);
10376 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
10377 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10378 -- exp_ch9 should use this ???
10383 -----------------------------------
10384 -- Priority_Specific_Dispatching --
10385 -----------------------------------
10387 -- pragma Priority_Specific_Dispatching (
10388 -- policy_IDENTIFIER,
10389 -- first_priority_EXPRESSION,
10390 -- last_priority_EXPRESSION);
10392 when Pragma_Priority_Specific_Dispatching =>
10393 Priority_Specific_Dispatching : declare
10394 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
10395 -- This is the entity System.Any_Priority;
10398 Lower_Bound : Node_Id;
10399 Upper_Bound : Node_Id;
10405 Check_Arg_Count (3);
10406 Check_No_Identifiers;
10407 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
10408 Check_Valid_Configuration_Pragma;
10409 Get_Name_String (Chars (Expression (Arg1)));
10410 DP := Fold_Upper (Name_Buffer (1));
10412 Lower_Bound := Expression (Arg2);
10413 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
10414 Lower_Val := Expr_Value (Lower_Bound);
10416 Upper_Bound := Expression (Arg3);
10417 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10418 Upper_Val := Expr_Value (Upper_Bound);
10420 -- It is not allowed to use Task_Dispatching_Policy and
10421 -- Priority_Specific_Dispatching in the same partition.
10423 if Task_Dispatching_Policy /= ' ' then
10424 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10426 ("pragma% incompatible with Task_Dispatching_Policy#");
10428 -- Check lower bound in range
10430 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10432 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10435 ("first_priority is out of range", Arg2);
10437 -- Check upper bound in range
10439 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10441 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10444 ("last_priority is out of range", Arg3);
10446 -- Check that the priority range is valid
10448 elsif Lower_Val > Upper_Val then
10450 ("last_priority_expression must be greater than" &
10451 " or equal to first_priority_expression");
10453 -- Store the new policy, but always preserve System_Location since
10454 -- we like the error message with the run-time name.
10457 -- Check overlapping in the priority ranges specified in other
10458 -- Priority_Specific_Dispatching pragmas within the same
10459 -- partition. We can only check those we know about!
10462 Specific_Dispatching.First .. Specific_Dispatching.Last
10464 if Specific_Dispatching.Table (J).First_Priority in
10465 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10466 or else Specific_Dispatching.Table (J).Last_Priority in
10467 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10470 Specific_Dispatching.Table (J).Pragma_Loc;
10472 ("priority range overlaps with "
10473 & "Priority_Specific_Dispatching#");
10477 -- The use of Priority_Specific_Dispatching is incompatible
10478 -- with Task_Dispatching_Policy.
10480 if Task_Dispatching_Policy /= ' ' then
10481 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10483 ("Priority_Specific_Dispatching incompatible "
10484 & "with Task_Dispatching_Policy#");
10487 -- The use of Priority_Specific_Dispatching forces ceiling
10490 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10491 Error_Msg_Sloc := Locking_Policy_Sloc;
10493 ("Priority_Specific_Dispatching incompatible "
10494 & "with Locking_Policy#");
10496 -- Set the Ceiling_Locking policy, but preserve System_Location
10497 -- since we like the error message with the run time name.
10500 Locking_Policy := 'C';
10502 if Locking_Policy_Sloc /= System_Location then
10503 Locking_Policy_Sloc := Loc;
10507 -- Add entry in the table
10509 Specific_Dispatching.Append
10510 ((Dispatching_Policy => DP,
10511 First_Priority => UI_To_Int (Lower_Val),
10512 Last_Priority => UI_To_Int (Upper_Val),
10513 Pragma_Loc => Loc));
10515 end Priority_Specific_Dispatching;
10521 -- pragma Profile (profile_IDENTIFIER);
10523 -- profile_IDENTIFIER => Restricted | Ravenscar
10525 when Pragma_Profile =>
10527 Check_Arg_Count (1);
10528 Check_Valid_Configuration_Pragma;
10529 Check_No_Identifiers;
10532 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10534 if Chars (Argx) = Name_Ravenscar then
10535 Set_Ravenscar_Profile (N);
10536 elsif Chars (Argx) = Name_Restricted then
10537 Set_Profile_Restrictions
10538 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10540 Error_Pragma_Arg ("& is not a valid profile", Argx);
10544 ----------------------
10545 -- Profile_Warnings --
10546 ----------------------
10548 -- pragma Profile_Warnings (profile_IDENTIFIER);
10550 -- profile_IDENTIFIER => Restricted | Ravenscar
10552 when Pragma_Profile_Warnings =>
10554 Check_Arg_Count (1);
10555 Check_Valid_Configuration_Pragma;
10556 Check_No_Identifiers;
10559 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10561 if Chars (Argx) = Name_Ravenscar then
10562 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10563 elsif Chars (Argx) = Name_Restricted then
10564 Set_Profile_Restrictions (Restricted, N, Warn => True);
10566 Error_Pragma_Arg ("& is not a valid profile", Argx);
10570 --------------------------
10571 -- Propagate_Exceptions --
10572 --------------------------
10574 -- pragma Propagate_Exceptions;
10576 -- Note: this pragma is obsolete and has no effect
10578 when Pragma_Propagate_Exceptions =>
10580 Check_Arg_Count (0);
10582 if In_Extended_Main_Source_Unit (N) then
10583 Propagate_Exceptions := True;
10590 -- pragma Psect_Object (
10591 -- [Internal =>] LOCAL_NAME,
10592 -- [, [External =>] EXTERNAL_SYMBOL]
10593 -- [, [Size =>] EXTERNAL_SYMBOL]);
10595 when Pragma_Psect_Object | Pragma_Common_Object =>
10596 Psect_Object : declare
10597 Args : Args_List (1 .. 3);
10598 Names : constant Name_List (1 .. 3) := (
10603 Internal : Node_Id renames Args (1);
10604 External : Node_Id renames Args (2);
10605 Size : Node_Id renames Args (3);
10607 Def_Id : Entity_Id;
10609 procedure Check_Too_Long (Arg : Node_Id);
10610 -- Posts message if the argument is an identifier with more
10611 -- than 31 characters, or a string literal with more than
10612 -- 31 characters, and we are operating under VMS
10614 --------------------
10615 -- Check_Too_Long --
10616 --------------------
10618 procedure Check_Too_Long (Arg : Node_Id) is
10619 X : constant Node_Id := Original_Node (Arg);
10622 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10624 ("inappropriate argument for pragma %", Arg);
10627 if OpenVMS_On_Target then
10628 if (Nkind (X) = N_String_Literal
10629 and then String_Length (Strval (X)) > 31)
10631 (Nkind (X) = N_Identifier
10632 and then Length_Of_Name (Chars (X)) > 31)
10635 ("argument for pragma % is longer than 31 characters",
10639 end Check_Too_Long;
10641 -- Start of processing for Common_Object/Psect_Object
10645 Gather_Associations (Names, Args);
10646 Process_Extended_Import_Export_Internal_Arg (Internal);
10648 Def_Id := Entity (Internal);
10650 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
10652 ("pragma% must designate an object", Internal);
10655 Check_Too_Long (Internal);
10657 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10659 ("cannot use pragma% for imported/exported object",
10663 if Is_Concurrent_Type (Etype (Internal)) then
10665 ("cannot specify pragma % for task/protected object",
10669 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10671 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10673 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10676 if Ekind (Def_Id) = E_Constant then
10678 ("cannot specify pragma % for a constant", Internal);
10681 if Is_Record_Type (Etype (Internal)) then
10687 Ent := First_Entity (Etype (Internal));
10688 while Present (Ent) loop
10689 Decl := Declaration_Node (Ent);
10691 if Ekind (Ent) = E_Component
10692 and then Nkind (Decl) = N_Component_Declaration
10693 and then Present (Expression (Decl))
10694 and then Warn_On_Export_Import
10697 ("?object for pragma % has defaults", Internal);
10707 if Present (Size) then
10708 Check_Too_Long (Size);
10711 if Present (External) then
10712 Check_Arg_Is_External_Name (External);
10713 Check_Too_Long (External);
10716 -- If all error tests pass, link pragma on to the rep item chain
10718 Record_Rep_Item (Def_Id, N);
10725 -- pragma Pure [(library_unit_NAME)];
10727 when Pragma_Pure => Pure : declare
10731 Check_Ada_83_Warning;
10732 Check_Valid_Library_Unit_Pragma;
10734 if Nkind (N) = N_Null_Statement then
10738 Ent := Find_Lib_Unit_Name;
10740 Set_Has_Pragma_Pure (Ent);
10741 Set_Suppress_Elaboration_Warnings (Ent);
10748 -- pragma Pure_05 [(library_unit_NAME)];
10750 -- This pragma is useable only in GNAT_Mode, where it is used like
10751 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10752 -- it is ignored). It may be used after a pragma Preelaborate, in
10753 -- which case it overrides the effect of the pragma Preelaborate.
10754 -- This is used to implement AI-362 which recategorizes some run-time
10755 -- packages in Ada 2005 mode.
10757 when Pragma_Pure_05 => Pure_05 : declare
10762 Check_Valid_Library_Unit_Pragma;
10764 if not GNAT_Mode then
10765 Error_Pragma ("pragma% only available in GNAT mode");
10768 if Nkind (N) = N_Null_Statement then
10772 -- This is one of the few cases where we need to test the value of
10773 -- Ada_Version_Explicit rather than Ada_Version (which is always
10774 -- set to Ada_12 in a predefined unit), we need to know the
10775 -- explicit version set to know if this pragma is active.
10777 if Ada_Version_Explicit >= Ada_05 then
10778 Ent := Find_Lib_Unit_Name;
10779 Set_Is_Preelaborated (Ent, False);
10781 Set_Suppress_Elaboration_Warnings (Ent);
10785 -------------------
10786 -- Pure_Function --
10787 -------------------
10789 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10791 when Pragma_Pure_Function => Pure_Function : declare
10794 Def_Id : Entity_Id;
10795 Effective : Boolean := False;
10799 Check_Arg_Count (1);
10800 Check_Optional_Identifier (Arg1, Name_Entity);
10801 Check_Arg_Is_Local_Name (Arg1);
10802 E_Id := Expression (Arg1);
10804 if Error_Posted (E_Id) then
10808 -- Loop through homonyms (overloadings) of referenced entity
10810 E := Entity (E_Id);
10812 if Present (E) then
10814 Def_Id := Get_Base_Subprogram (E);
10816 if not Ekind_In (Def_Id, E_Function,
10817 E_Generic_Function,
10821 ("pragma% requires a function name", Arg1);
10824 Set_Is_Pure (Def_Id);
10826 if not Has_Pragma_Pure_Function (Def_Id) then
10827 Set_Has_Pragma_Pure_Function (Def_Id);
10832 exit when No (E) or else Scope (E) /= Current_Scope;
10836 and then Warn_On_Redundant_Constructs
10839 ("pragma Pure_Function on& is redundant?",
10845 --------------------
10846 -- Queuing_Policy --
10847 --------------------
10849 -- pragma Queuing_Policy (policy_IDENTIFIER);
10851 when Pragma_Queuing_Policy => declare
10855 Check_Ada_83_Warning;
10856 Check_Arg_Count (1);
10857 Check_No_Identifiers;
10858 Check_Arg_Is_Queuing_Policy (Arg1);
10859 Check_Valid_Configuration_Pragma;
10860 Get_Name_String (Chars (Expression (Arg1)));
10861 QP := Fold_Upper (Name_Buffer (1));
10863 if Queuing_Policy /= ' '
10864 and then Queuing_Policy /= QP
10866 Error_Msg_Sloc := Queuing_Policy_Sloc;
10867 Error_Pragma ("queuing policy incompatible with policy#");
10869 -- Set new policy, but always preserve System_Location since we
10870 -- like the error message with the run time name.
10873 Queuing_Policy := QP;
10875 if Queuing_Policy_Sloc /= System_Location then
10876 Queuing_Policy_Sloc := Loc;
10881 -----------------------
10882 -- Relative_Deadline --
10883 -----------------------
10885 -- pragma Relative_Deadline (time_span_EXPRESSION);
10887 when Pragma_Relative_Deadline => Relative_Deadline : declare
10888 P : constant Node_Id := Parent (N);
10893 Check_No_Identifiers;
10894 Check_Arg_Count (1);
10896 Arg := Expression (Arg1);
10898 -- The expression must be analyzed in the special manner described
10899 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10901 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10905 if Nkind (P) = N_Subprogram_Body then
10906 Check_In_Main_Program;
10910 elsif Nkind (P) = N_Task_Definition then
10913 -- Anything else is incorrect
10919 if Has_Relative_Deadline_Pragma (P) then
10920 Error_Pragma ("duplicate pragma% not allowed");
10922 Set_Has_Relative_Deadline_Pragma (P, True);
10924 if Nkind (P) = N_Task_Definition then
10925 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10928 end Relative_Deadline;
10930 ---------------------------
10931 -- Remote_Call_Interface --
10932 ---------------------------
10934 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10936 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10937 Cunit_Node : Node_Id;
10938 Cunit_Ent : Entity_Id;
10942 Check_Ada_83_Warning;
10943 Check_Valid_Library_Unit_Pragma;
10945 if Nkind (N) = N_Null_Statement then
10949 Cunit_Node := Cunit (Current_Sem_Unit);
10950 K := Nkind (Unit (Cunit_Node));
10951 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10953 if K = N_Package_Declaration
10954 or else K = N_Generic_Package_Declaration
10955 or else K = N_Subprogram_Declaration
10956 or else K = N_Generic_Subprogram_Declaration
10957 or else (K = N_Subprogram_Body
10958 and then Acts_As_Spec (Unit (Cunit_Node)))
10963 "pragma% must apply to package or subprogram declaration");
10966 Set_Is_Remote_Call_Interface (Cunit_Ent);
10967 end Remote_Call_Interface;
10973 -- pragma Remote_Types [(library_unit_NAME)];
10975 when Pragma_Remote_Types => Remote_Types : declare
10976 Cunit_Node : Node_Id;
10977 Cunit_Ent : Entity_Id;
10980 Check_Ada_83_Warning;
10981 Check_Valid_Library_Unit_Pragma;
10983 if Nkind (N) = N_Null_Statement then
10987 Cunit_Node := Cunit (Current_Sem_Unit);
10988 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10990 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10991 N_Generic_Package_Declaration)
10994 ("pragma% can only apply to a package declaration");
10997 Set_Is_Remote_Types (Cunit_Ent);
11004 -- pragma Ravenscar;
11006 when Pragma_Ravenscar =>
11008 Check_Arg_Count (0);
11009 Check_Valid_Configuration_Pragma;
11010 Set_Ravenscar_Profile (N);
11012 if Warn_On_Obsolescent_Feature then
11013 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
11014 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
11017 -------------------------
11018 -- Restricted_Run_Time --
11019 -------------------------
11021 -- pragma Restricted_Run_Time;
11023 when Pragma_Restricted_Run_Time =>
11025 Check_Arg_Count (0);
11026 Check_Valid_Configuration_Pragma;
11027 Set_Profile_Restrictions
11028 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11030 if Warn_On_Obsolescent_Feature then
11032 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
11033 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
11040 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
11043 -- restriction_IDENTIFIER
11044 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11046 when Pragma_Restrictions =>
11047 Process_Restrictions_Or_Restriction_Warnings
11048 (Warn => Treat_Restrictions_As_Warnings);
11050 --------------------------
11051 -- Restriction_Warnings --
11052 --------------------------
11054 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
11057 -- restriction_IDENTIFIER
11058 -- | restriction_parameter_IDENTIFIER => EXPRESSION
11060 when Pragma_Restriction_Warnings =>
11062 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
11068 -- pragma Reviewable;
11070 when Pragma_Reviewable =>
11071 Check_Ada_83_Warning;
11072 Check_Arg_Count (0);
11074 -- Call dummy debugging function rv. This is done to assist front
11075 -- end debugging. By placing a Reviewable pragma in the source
11076 -- program, a breakpoint on rv catches this place in the source,
11077 -- allowing convenient stepping to the point of interest.
11081 --------------------------
11082 -- Short_Circuit_And_Or --
11083 --------------------------
11085 when Pragma_Short_Circuit_And_Or =>
11087 Check_Arg_Count (0);
11088 Check_Valid_Configuration_Pragma;
11089 Short_Circuit_And_Or := True;
11091 -------------------
11092 -- Share_Generic --
11093 -------------------
11095 -- pragma Share_Generic (NAME {, NAME});
11097 when Pragma_Share_Generic =>
11099 Process_Generic_List;
11105 -- pragma Shared (LOCAL_NAME);
11107 when Pragma_Shared =>
11109 Process_Atomic_Shared_Volatile;
11111 --------------------
11112 -- Shared_Passive --
11113 --------------------
11115 -- pragma Shared_Passive [(library_unit_NAME)];
11117 -- Set the flag Is_Shared_Passive of program unit name entity
11119 when Pragma_Shared_Passive => Shared_Passive : declare
11120 Cunit_Node : Node_Id;
11121 Cunit_Ent : Entity_Id;
11124 Check_Ada_83_Warning;
11125 Check_Valid_Library_Unit_Pragma;
11127 if Nkind (N) = N_Null_Statement then
11131 Cunit_Node := Cunit (Current_Sem_Unit);
11132 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
11134 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
11135 N_Generic_Package_Declaration)
11138 ("pragma% can only apply to a package declaration");
11141 Set_Is_Shared_Passive (Cunit_Ent);
11142 end Shared_Passive;
11144 -----------------------
11145 -- Short_Descriptors --
11146 -----------------------
11148 -- pragma Short_Descriptors;
11150 when Pragma_Short_Descriptors =>
11152 Check_Arg_Count (0);
11153 Check_Valid_Configuration_Pragma;
11154 Short_Descriptors := True;
11156 ----------------------
11157 -- Source_File_Name --
11158 ----------------------
11160 -- There are five forms for this pragma:
11162 -- pragma Source_File_Name (
11163 -- [UNIT_NAME =>] unit_NAME,
11164 -- BODY_FILE_NAME => STRING_LITERAL
11165 -- [, [INDEX =>] INTEGER_LITERAL]);
11167 -- pragma Source_File_Name (
11168 -- [UNIT_NAME =>] unit_NAME,
11169 -- SPEC_FILE_NAME => STRING_LITERAL
11170 -- [, [INDEX =>] INTEGER_LITERAL]);
11172 -- pragma Source_File_Name (
11173 -- BODY_FILE_NAME => STRING_LITERAL
11174 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11175 -- [, CASING => CASING_SPEC]);
11177 -- pragma Source_File_Name (
11178 -- SPEC_FILE_NAME => STRING_LITERAL
11179 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11180 -- [, CASING => CASING_SPEC]);
11182 -- pragma Source_File_Name (
11183 -- SUBUNIT_FILE_NAME => STRING_LITERAL
11184 -- [, DOT_REPLACEMENT => STRING_LITERAL]
11185 -- [, CASING => CASING_SPEC]);
11187 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
11189 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
11190 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
11191 -- only be used when no project file is used, while SFNP can only be
11192 -- used when a project file is used.
11194 -- No processing here. Processing was completed during parsing, since
11195 -- we need to have file names set as early as possible. Units are
11196 -- loaded well before semantic processing starts.
11198 -- The only processing we defer to this point is the check for
11199 -- correct placement.
11201 when Pragma_Source_File_Name =>
11203 Check_Valid_Configuration_Pragma;
11205 ------------------------------
11206 -- Source_File_Name_Project --
11207 ------------------------------
11209 -- See Source_File_Name for syntax
11211 -- No processing here. Processing was completed during parsing, since
11212 -- we need to have file names set as early as possible. Units are
11213 -- loaded well before semantic processing starts.
11215 -- The only processing we defer to this point is the check for
11216 -- correct placement.
11218 when Pragma_Source_File_Name_Project =>
11220 Check_Valid_Configuration_Pragma;
11222 -- Check that a pragma Source_File_Name_Project is used only in a
11223 -- configuration pragmas file.
11225 -- Pragmas Source_File_Name_Project should only be generated by
11226 -- the Project Manager in configuration pragmas files.
11228 -- This is really an ugly test. It seems to depend on some
11229 -- accidental and undocumented property. At the very least it
11230 -- needs to be documented, but it would be better to have a
11231 -- clean way of testing if we are in a configuration file???
11233 if Present (Parent (N)) then
11235 ("pragma% can only appear in a configuration pragmas file");
11238 ----------------------
11239 -- Source_Reference --
11240 ----------------------
11242 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
11244 -- Nothing to do, all processing completed in Par.Prag, since we need
11245 -- the information for possible parser messages that are output.
11247 when Pragma_Source_Reference =>
11250 --------------------------------
11251 -- Static_Elaboration_Desired --
11252 --------------------------------
11254 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
11256 when Pragma_Static_Elaboration_Desired =>
11258 Check_At_Most_N_Arguments (1);
11260 if Is_Compilation_Unit (Current_Scope)
11261 and then Ekind (Current_Scope) = E_Package
11263 Set_Static_Elaboration_Desired (Current_Scope, True);
11265 Error_Pragma ("pragma% must apply to a library-level package");
11272 -- pragma Storage_Size (EXPRESSION);
11274 when Pragma_Storage_Size => Storage_Size : declare
11275 P : constant Node_Id := Parent (N);
11279 Check_No_Identifiers;
11280 Check_Arg_Count (1);
11282 -- The expression must be analyzed in the special manner described
11283 -- in "Handling of Default Expressions" in sem.ads.
11285 Arg := Expression (Arg1);
11286 Preanalyze_Spec_Expression (Arg, Any_Integer);
11288 if not Is_Static_Expression (Arg) then
11289 Check_Restriction (Static_Storage_Size, Arg);
11292 if Nkind (P) /= N_Task_Definition then
11297 if Has_Storage_Size_Pragma (P) then
11298 Error_Pragma ("duplicate pragma% not allowed");
11300 Set_Has_Storage_Size_Pragma (P, True);
11303 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11304 -- ??? exp_ch9 should use this!
11312 -- pragma Storage_Unit (NUMERIC_LITERAL);
11314 -- Only permitted argument is System'Storage_Unit value
11316 when Pragma_Storage_Unit =>
11317 Check_No_Identifiers;
11318 Check_Arg_Count (1);
11319 Check_Arg_Is_Integer_Literal (Arg1);
11321 if Intval (Expression (Arg1)) /=
11322 UI_From_Int (Ttypes.System_Storage_Unit)
11324 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
11326 ("the only allowed argument for pragma% is ^", Arg1);
11329 --------------------
11330 -- Stream_Convert --
11331 --------------------
11333 -- pragma Stream_Convert (
11334 -- [Entity =>] type_LOCAL_NAME,
11335 -- [Read =>] function_NAME,
11336 -- [Write =>] function NAME);
11338 when Pragma_Stream_Convert => Stream_Convert : declare
11340 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
11341 -- Check that the given argument is the name of a local function
11342 -- of one argument that is not overloaded earlier in the current
11343 -- local scope. A check is also made that the argument is a
11344 -- function with one parameter.
11346 --------------------------------------
11347 -- Check_OK_Stream_Convert_Function --
11348 --------------------------------------
11350 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
11354 Check_Arg_Is_Local_Name (Arg);
11355 Ent := Entity (Expression (Arg));
11357 if Has_Homonym (Ent) then
11359 ("argument for pragma% may not be overloaded", Arg);
11362 if Ekind (Ent) /= E_Function
11363 or else No (First_Formal (Ent))
11364 or else Present (Next_Formal (First_Formal (Ent)))
11367 ("argument for pragma% must be" &
11368 " function of one argument", Arg);
11370 end Check_OK_Stream_Convert_Function;
11372 -- Start of processing for Stream_Convert
11376 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
11377 Check_Arg_Count (3);
11378 Check_Optional_Identifier (Arg1, Name_Entity);
11379 Check_Optional_Identifier (Arg2, Name_Read);
11380 Check_Optional_Identifier (Arg3, Name_Write);
11381 Check_Arg_Is_Local_Name (Arg1);
11382 Check_OK_Stream_Convert_Function (Arg2);
11383 Check_OK_Stream_Convert_Function (Arg3);
11386 Typ : constant Entity_Id :=
11387 Underlying_Type (Entity (Expression (Arg1)));
11388 Read : constant Entity_Id := Entity (Expression (Arg2));
11389 Write : constant Entity_Id := Entity (Expression (Arg3));
11392 Check_First_Subtype (Arg1);
11394 -- Check for too early or too late. Note that we don't enforce
11395 -- the rule about primitive operations in this case, since, as
11396 -- is the case for explicit stream attributes themselves, these
11397 -- restrictions are not appropriate. Note that the chaining of
11398 -- the pragma by Rep_Item_Too_Late is actually the critical
11399 -- processing done for this pragma.
11401 if Rep_Item_Too_Early (Typ, N)
11403 Rep_Item_Too_Late (Typ, N, FOnly => True)
11408 -- Return if previous error
11410 if Etype (Typ) = Any_Type
11412 Etype (Read) = Any_Type
11414 Etype (Write) = Any_Type
11421 if Underlying_Type (Etype (Read)) /= Typ then
11423 ("incorrect return type for function&", Arg2);
11426 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
11428 ("incorrect parameter type for function&", Arg3);
11431 if Underlying_Type (Etype (First_Formal (Read))) /=
11432 Underlying_Type (Etype (Write))
11435 ("result type of & does not match Read parameter type",
11439 end Stream_Convert;
11441 -------------------------
11442 -- Style_Checks (GNAT) --
11443 -------------------------
11445 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11447 -- This is processed by the parser since some of the style checks
11448 -- take place during source scanning and parsing. This means that
11449 -- we don't need to issue error messages here.
11451 when Pragma_Style_Checks => Style_Checks : declare
11452 A : constant Node_Id := Expression (Arg1);
11458 Check_No_Identifiers;
11460 -- Two argument form
11462 if Arg_Count = 2 then
11463 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11470 E_Id := Expression (Arg2);
11473 if not Is_Entity_Name (E_Id) then
11475 ("second argument of pragma% must be entity name",
11479 E := Entity (E_Id);
11485 Set_Suppress_Style_Checks (E,
11486 (Chars (Expression (Arg1)) = Name_Off));
11487 exit when No (Homonym (E));
11493 -- One argument form
11496 Check_Arg_Count (1);
11498 if Nkind (A) = N_String_Literal then
11502 Slen : constant Natural := Natural (String_Length (S));
11503 Options : String (1 .. Slen);
11509 C := Get_String_Char (S, Int (J));
11510 exit when not In_Character_Range (C);
11511 Options (J) := Get_Character (C);
11513 -- If at end of string, set options. As per discussion
11514 -- above, no need to check for errors, since we issued
11515 -- them in the parser.
11518 Set_Style_Check_Options (Options);
11526 elsif Nkind (A) = N_Identifier then
11527 if Chars (A) = Name_All_Checks then
11529 Set_GNAT_Style_Check_Options;
11531 Set_Default_Style_Check_Options;
11534 elsif Chars (A) = Name_On then
11535 Style_Check := True;
11537 elsif Chars (A) = Name_Off then
11538 Style_Check := False;
11548 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11550 when Pragma_Subtitle =>
11552 Check_Arg_Count (1);
11553 Check_Optional_Identifier (Arg1, Name_Subtitle);
11554 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11561 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11563 when Pragma_Suppress =>
11564 Process_Suppress_Unsuppress (True);
11570 -- pragma Suppress_All;
11572 -- The only check made here is that the pragma appears in the proper
11573 -- place, i.e. following a compilation unit. If indeed it appears in
11574 -- this context, then the parser has already inserted an equivalent
11575 -- pragma Suppress (All_Checks) to get the required effect.
11577 when Pragma_Suppress_All =>
11579 Check_Arg_Count (0);
11581 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11582 or else not Is_List_Member (N)
11583 or else List_Containing (N) /= Pragmas_After (Parent (N))
11586 ("misplaced pragma%, must follow compilation unit");
11589 -------------------------
11590 -- Suppress_Debug_Info --
11591 -------------------------
11593 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11595 when Pragma_Suppress_Debug_Info =>
11597 Check_Arg_Count (1);
11598 Check_Optional_Identifier (Arg1, Name_Entity);
11599 Check_Arg_Is_Local_Name (Arg1);
11600 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11602 ----------------------------------
11603 -- Suppress_Exception_Locations --
11604 ----------------------------------
11606 -- pragma Suppress_Exception_Locations;
11608 when Pragma_Suppress_Exception_Locations =>
11610 Check_Arg_Count (0);
11611 Check_Valid_Configuration_Pragma;
11612 Exception_Locations_Suppressed := True;
11614 -----------------------------
11615 -- Suppress_Initialization --
11616 -----------------------------
11618 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11620 when Pragma_Suppress_Initialization => Suppress_Init : declare
11626 Check_Arg_Count (1);
11627 Check_Optional_Identifier (Arg1, Name_Entity);
11628 Check_Arg_Is_Local_Name (Arg1);
11630 E_Id := Expression (Arg1);
11632 if Etype (E_Id) = Any_Type then
11636 E := Entity (E_Id);
11638 if Is_Type (E) then
11639 if Is_Incomplete_Or_Private_Type (E) then
11640 if No (Full_View (Base_Type (E))) then
11642 ("argument of pragma% cannot be an incomplete type",
11645 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11648 Set_Suppress_Init_Proc (Base_Type (E));
11653 ("pragma% requires argument that is a type name", Arg1);
11661 -- pragma System_Name (DIRECT_NAME);
11663 -- Syntax check: one argument, which must be the identifier GNAT or
11664 -- the identifier GCC, no other identifiers are acceptable.
11666 when Pragma_System_Name =>
11668 Check_No_Identifiers;
11669 Check_Arg_Count (1);
11670 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11672 -----------------------------
11673 -- Task_Dispatching_Policy --
11674 -----------------------------
11676 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11678 when Pragma_Task_Dispatching_Policy => declare
11682 Check_Ada_83_Warning;
11683 Check_Arg_Count (1);
11684 Check_No_Identifiers;
11685 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11686 Check_Valid_Configuration_Pragma;
11687 Get_Name_String (Chars (Expression (Arg1)));
11688 DP := Fold_Upper (Name_Buffer (1));
11690 if Task_Dispatching_Policy /= ' '
11691 and then Task_Dispatching_Policy /= DP
11693 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11695 ("task dispatching policy incompatible with policy#");
11697 -- Set new policy, but always preserve System_Location since we
11698 -- like the error message with the run time name.
11701 Task_Dispatching_Policy := DP;
11703 if Task_Dispatching_Policy_Sloc /= System_Location then
11704 Task_Dispatching_Policy_Sloc := Loc;
11713 -- pragma Task_Info (EXPRESSION);
11715 when Pragma_Task_Info => Task_Info : declare
11716 P : constant Node_Id := Parent (N);
11721 if Nkind (P) /= N_Task_Definition then
11722 Error_Pragma ("pragma% must appear in task definition");
11725 Check_No_Identifiers;
11726 Check_Arg_Count (1);
11728 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11730 if Etype (Expression (Arg1)) = Any_Type then
11734 if Has_Task_Info_Pragma (P) then
11735 Error_Pragma ("duplicate pragma% not allowed");
11737 Set_Has_Task_Info_Pragma (P, True);
11745 -- pragma Task_Name (string_EXPRESSION);
11747 when Pragma_Task_Name => Task_Name : declare
11748 P : constant Node_Id := Parent (N);
11752 Check_No_Identifiers;
11753 Check_Arg_Count (1);
11755 Arg := Expression (Arg1);
11757 -- The expression is used in the call to Create_Task, and must be
11758 -- expanded there, not in the context of the current spec. It must
11759 -- however be analyzed to capture global references, in case it
11760 -- appears in a generic context.
11762 Preanalyze_And_Resolve (Arg, Standard_String);
11764 if Nkind (P) /= N_Task_Definition then
11768 if Has_Task_Name_Pragma (P) then
11769 Error_Pragma ("duplicate pragma% not allowed");
11771 Set_Has_Task_Name_Pragma (P, True);
11772 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11780 -- pragma Task_Storage (
11781 -- [Task_Type =>] LOCAL_NAME,
11782 -- [Top_Guard =>] static_integer_EXPRESSION);
11784 when Pragma_Task_Storage => Task_Storage : declare
11785 Args : Args_List (1 .. 2);
11786 Names : constant Name_List (1 .. 2) := (
11790 Task_Type : Node_Id renames Args (1);
11791 Top_Guard : Node_Id renames Args (2);
11797 Gather_Associations (Names, Args);
11799 if No (Task_Type) then
11801 ("missing task_type argument for pragma%");
11804 Check_Arg_Is_Local_Name (Task_Type);
11806 Ent := Entity (Task_Type);
11808 if not Is_Task_Type (Ent) then
11810 ("argument for pragma% must be task type", Task_Type);
11813 if No (Top_Guard) then
11815 ("pragma% takes two arguments", Task_Type);
11817 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11820 Check_First_Subtype (Task_Type);
11822 if Rep_Item_Too_Late (Ent, N) then
11827 --------------------------
11828 -- Thread_Local_Storage --
11829 --------------------------
11831 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11833 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11839 Check_Arg_Count (1);
11840 Check_Optional_Identifier (Arg1, Name_Entity);
11841 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11843 Id := Expression (Arg1);
11846 if not Is_Entity_Name (Id)
11847 or else Ekind (Entity (Id)) /= E_Variable
11849 Error_Pragma_Arg ("local variable name required", Arg1);
11854 if Rep_Item_Too_Early (E, N)
11855 or else Rep_Item_Too_Late (E, N)
11860 Set_Has_Pragma_Thread_Local_Storage (E);
11861 Set_Has_Gigi_Rep_Item (E);
11862 end Thread_Local_Storage;
11868 -- pragma Time_Slice (static_duration_EXPRESSION);
11870 when Pragma_Time_Slice => Time_Slice : declare
11876 Check_Arg_Count (1);
11877 Check_No_Identifiers;
11878 Check_In_Main_Program;
11879 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11881 if not Error_Posted (Arg1) then
11883 while Present (Nod) loop
11884 if Nkind (Nod) = N_Pragma
11885 and then Pragma_Name (Nod) = Name_Time_Slice
11887 Error_Msg_Name_1 := Pname;
11888 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11895 -- Process only if in main unit
11897 if Get_Source_Unit (Loc) = Main_Unit then
11898 Opt.Time_Slice_Set := True;
11899 Val := Expr_Value_R (Expression (Arg1));
11901 if Val <= Ureal_0 then
11902 Opt.Time_Slice_Value := 0;
11904 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11905 Opt.Time_Slice_Value := 1_000_000_000;
11908 Opt.Time_Slice_Value :=
11909 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11918 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11920 -- TITLING_OPTION ::=
11921 -- [Title =>] STRING_LITERAL
11922 -- | [Subtitle =>] STRING_LITERAL
11924 when Pragma_Title => Title : declare
11925 Args : Args_List (1 .. 2);
11926 Names : constant Name_List (1 .. 2) := (
11932 Gather_Associations (Names, Args);
11935 for J in 1 .. 2 loop
11936 if Present (Args (J)) then
11937 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
11942 ---------------------
11943 -- Unchecked_Union --
11944 ---------------------
11946 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11948 when Pragma_Unchecked_Union => Unchecked_Union : declare
11949 Assoc : constant Node_Id := Arg1;
11950 Type_Id : constant Node_Id := Expression (Assoc);
11961 Check_No_Identifiers;
11962 Check_Arg_Count (1);
11963 Check_Arg_Is_Local_Name (Arg1);
11965 Find_Type (Type_Id);
11966 Typ := Entity (Type_Id);
11969 or else Rep_Item_Too_Early (Typ, N)
11973 Typ := Underlying_Type (Typ);
11976 if Rep_Item_Too_Late (Typ, N) then
11980 Check_First_Subtype (Arg1);
11982 -- Note remaining cases are references to a type in the current
11983 -- declarative part. If we find an error, we post the error on
11984 -- the relevant type declaration at an appropriate point.
11986 if not Is_Record_Type (Typ) then
11987 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11990 elsif Is_Tagged_Type (Typ) then
11991 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11994 elsif Is_Limited_Type (Typ) then
11996 ("Unchecked_Union must not be limited record type", Typ);
11997 Explain_Limited_Type (Typ, Typ);
12001 if not Has_Discriminants (Typ) then
12003 ("Unchecked_Union must have one discriminant", Typ);
12007 Discr := First_Discriminant (Typ);
12008 while Present (Discr) loop
12009 if No (Discriminant_Default_Value (Discr)) then
12011 ("Unchecked_Union discriminant must have default value",
12014 Next_Discriminant (Discr);
12017 Tdef := Type_Definition (Declaration_Node (Typ));
12018 Clist := Component_List (Tdef);
12020 Comp := First (Component_Items (Clist));
12021 while Present (Comp) loop
12022 Check_Component (Comp, Typ);
12026 if No (Clist) or else No (Variant_Part (Clist)) then
12028 ("Unchecked_Union must have variant part",
12033 Vpart := Variant_Part (Clist);
12035 Variant := First (Variants (Vpart));
12036 while Present (Variant) loop
12037 Check_Variant (Variant, Typ);
12042 Set_Is_Unchecked_Union (Typ, True);
12043 Set_Convention (Typ, Convention_C);
12045 Set_Has_Unchecked_Union (Base_Type (Typ), True);
12046 Set_Is_Unchecked_Union (Base_Type (Typ), True);
12047 end Unchecked_Union;
12049 ------------------------
12050 -- Unimplemented_Unit --
12051 ------------------------
12053 -- pragma Unimplemented_Unit;
12055 -- Note: this only gives an error if we are generating code, or if
12056 -- we are in a generic library unit (where the pragma appears in the
12057 -- body, not in the spec).
12059 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
12060 Cunitent : constant Entity_Id :=
12061 Cunit_Entity (Get_Source_Unit (Loc));
12062 Ent_Kind : constant Entity_Kind :=
12067 Check_Arg_Count (0);
12069 if Operating_Mode = Generate_Code
12070 or else Ent_Kind = E_Generic_Function
12071 or else Ent_Kind = E_Generic_Procedure
12072 or else Ent_Kind = E_Generic_Package
12074 Get_Name_String (Chars (Cunitent));
12075 Set_Casing (Mixed_Case);
12076 Write_Str (Name_Buffer (1 .. Name_Len));
12077 Write_Str (" is not supported in this configuration");
12079 raise Unrecoverable_Error;
12081 end Unimplemented_Unit;
12083 ------------------------
12084 -- Universal_Aliasing --
12085 ------------------------
12087 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
12089 when Pragma_Universal_Aliasing => Universal_Alias : declare
12094 Check_Arg_Count (1);
12095 Check_Optional_Identifier (Arg2, Name_Entity);
12096 Check_Arg_Is_Local_Name (Arg1);
12097 E_Id := Entity (Expression (Arg1));
12099 if E_Id = Any_Type then
12101 elsif No (E_Id) or else not Is_Type (E_Id) then
12102 Error_Pragma_Arg ("pragma% requires type", Arg1);
12105 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
12106 end Universal_Alias;
12108 --------------------
12109 -- Universal_Data --
12110 --------------------
12112 -- pragma Universal_Data [(library_unit_NAME)];
12114 when Pragma_Universal_Data =>
12117 -- If this is a configuration pragma, then set the universal
12118 -- addressing option, otherwise confirm that the pragma satisfies
12119 -- the requirements of library unit pragma placement and leave it
12120 -- to the GNAAMP back end to detect the pragma (avoids transitive
12121 -- setting of the option due to withed units).
12123 if Is_Configuration_Pragma then
12124 Universal_Addressing_On_AAMP := True;
12126 Check_Valid_Library_Unit_Pragma;
12129 if not AAMP_On_Target then
12130 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
12137 -- pragma Unmodified (local_Name {, local_Name});
12139 when Pragma_Unmodified => Unmodified : declare
12140 Arg_Node : Node_Id;
12141 Arg_Expr : Node_Id;
12142 Arg_Ent : Entity_Id;
12146 Check_At_Least_N_Arguments (1);
12148 -- Loop through arguments
12151 while Present (Arg_Node) loop
12152 Check_No_Identifier (Arg_Node);
12154 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
12155 -- in fact generate reference, so that the entity will have a
12156 -- reference, which will inhibit any warnings about it not
12157 -- being referenced, and also properly show up in the ali file
12158 -- as a reference. But this reference is recorded before the
12159 -- Has_Pragma_Unreferenced flag is set, so that no warning is
12160 -- generated for this reference.
12162 Check_Arg_Is_Local_Name (Arg_Node);
12163 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12165 if Is_Entity_Name (Arg_Expr) then
12166 Arg_Ent := Entity (Arg_Expr);
12168 if not Is_Assignable (Arg_Ent) then
12170 ("pragma% can only be applied to a variable",
12173 Set_Has_Pragma_Unmodified (Arg_Ent);
12185 -- pragma Unreferenced (local_Name {, local_Name});
12187 -- or when used in a context clause:
12189 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
12191 when Pragma_Unreferenced => Unreferenced : declare
12192 Arg_Node : Node_Id;
12193 Arg_Expr : Node_Id;
12194 Arg_Ent : Entity_Id;
12199 Check_At_Least_N_Arguments (1);
12201 -- Check case of appearing within context clause
12203 if Is_In_Context_Clause then
12205 -- The arguments must all be units mentioned in a with clause
12206 -- in the same context clause. Note we already checked (in
12207 -- Par.Prag) that the arguments are either identifiers or
12208 -- selected components.
12211 while Present (Arg_Node) loop
12212 Citem := First (List_Containing (N));
12213 while Citem /= N loop
12214 if Nkind (Citem) = N_With_Clause
12215 and then Same_Name (Name (Citem), Expression (Arg_Node))
12217 Set_Has_Pragma_Unreferenced
12220 (Library_Unit (Citem))));
12221 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
12230 ("argument of pragma% is not with'ed unit", Arg_Node);
12236 -- Case of not in list of context items
12240 while Present (Arg_Node) loop
12241 Check_No_Identifier (Arg_Node);
12243 -- Note: the analyze call done by Check_Arg_Is_Local_Name
12244 -- will in fact generate reference, so that the entity will
12245 -- have a reference, which will inhibit any warnings about
12246 -- it not being referenced, and also properly show up in the
12247 -- ali file as a reference. But this reference is recorded
12248 -- before the Has_Pragma_Unreferenced flag is set, so that
12249 -- no warning is generated for this reference.
12251 Check_Arg_Is_Local_Name (Arg_Node);
12252 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12254 if Is_Entity_Name (Arg_Expr) then
12255 Arg_Ent := Entity (Arg_Expr);
12257 -- If the entity is overloaded, the pragma applies to the
12258 -- most recent overloading, as documented. In this case,
12259 -- name resolution does not generate a reference, so it
12260 -- must be done here explicitly.
12262 if Is_Overloaded (Arg_Expr) then
12263 Generate_Reference (Arg_Ent, N);
12266 Set_Has_Pragma_Unreferenced (Arg_Ent);
12274 --------------------------
12275 -- Unreferenced_Objects --
12276 --------------------------
12278 -- pragma Unreferenced_Objects (local_Name {, local_Name});
12280 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
12281 Arg_Node : Node_Id;
12282 Arg_Expr : Node_Id;
12286 Check_At_Least_N_Arguments (1);
12289 while Present (Arg_Node) loop
12290 Check_No_Identifier (Arg_Node);
12291 Check_Arg_Is_Local_Name (Arg_Node);
12292 Arg_Expr := Get_Pragma_Arg (Arg_Node);
12294 if not Is_Entity_Name (Arg_Expr)
12295 or else not Is_Type (Entity (Arg_Expr))
12298 ("argument for pragma% must be type or subtype", Arg_Node);
12301 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
12304 end Unreferenced_Objects;
12306 ------------------------------
12307 -- Unreserve_All_Interrupts --
12308 ------------------------------
12310 -- pragma Unreserve_All_Interrupts;
12312 when Pragma_Unreserve_All_Interrupts =>
12314 Check_Arg_Count (0);
12316 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
12317 Unreserve_All_Interrupts := True;
12324 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
12326 when Pragma_Unsuppress =>
12328 Process_Suppress_Unsuppress (False);
12330 -------------------
12331 -- Use_VADS_Size --
12332 -------------------
12334 -- pragma Use_VADS_Size;
12336 when Pragma_Use_VADS_Size =>
12338 Check_Arg_Count (0);
12339 Check_Valid_Configuration_Pragma;
12340 Use_VADS_Size := True;
12342 ---------------------
12343 -- Validity_Checks --
12344 ---------------------
12346 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12348 when Pragma_Validity_Checks => Validity_Checks : declare
12349 A : constant Node_Id := Expression (Arg1);
12355 Check_Arg_Count (1);
12356 Check_No_Identifiers;
12358 if Nkind (A) = N_String_Literal then
12362 Slen : constant Natural := Natural (String_Length (S));
12363 Options : String (1 .. Slen);
12369 C := Get_String_Char (S, Int (J));
12370 exit when not In_Character_Range (C);
12371 Options (J) := Get_Character (C);
12374 Set_Validity_Check_Options (Options);
12382 elsif Nkind (A) = N_Identifier then
12384 if Chars (A) = Name_All_Checks then
12385 Set_Validity_Check_Options ("a");
12387 elsif Chars (A) = Name_On then
12388 Validity_Checks_On := True;
12390 elsif Chars (A) = Name_Off then
12391 Validity_Checks_On := False;
12395 end Validity_Checks;
12401 -- pragma Volatile (LOCAL_NAME);
12403 when Pragma_Volatile =>
12404 Process_Atomic_Shared_Volatile;
12406 -------------------------
12407 -- Volatile_Components --
12408 -------------------------
12410 -- pragma Volatile_Components (array_LOCAL_NAME);
12412 -- Volatile is handled by the same circuit as Atomic_Components
12418 -- pragma Warnings (On | Off);
12419 -- pragma Warnings (On | Off, LOCAL_NAME);
12420 -- pragma Warnings (static_string_EXPRESSION);
12421 -- pragma Warnings (On | Off, STRING_LITERAL);
12423 when Pragma_Warnings => Warnings : begin
12425 Check_At_Least_N_Arguments (1);
12426 Check_No_Identifiers;
12428 -- If debug flag -gnatd.i is set, pragma is ignored
12430 if Debug_Flag_Dot_I then
12434 -- Process various forms of the pragma
12437 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12440 -- One argument case
12442 if Arg_Count = 1 then
12444 -- On/Off one argument case was processed by parser
12446 if Nkind (Argx) = N_Identifier
12448 (Chars (Argx) = Name_On
12450 Chars (Argx) = Name_Off)
12454 -- One argument case must be ON/OFF or static string expr
12456 elsif not Is_Static_String_Expression (Arg1) then
12458 ("argument of pragma% must be On/Off or " &
12459 "static string expression", Arg1);
12461 -- One argument string expression case
12465 Lit : constant Node_Id := Expr_Value_S (Argx);
12466 Str : constant String_Id := Strval (Lit);
12467 Len : constant Nat := String_Length (Str);
12475 while J <= Len loop
12476 C := Get_String_Char (Str, J);
12477 OK := In_Character_Range (C);
12480 Chr := Get_Character (C);
12484 if J < Len and then Chr = '.' then
12486 C := Get_String_Char (Str, J);
12487 Chr := Get_Character (C);
12489 if not Set_Dot_Warning_Switch (Chr) then
12491 ("invalid warning switch character " &
12498 OK := Set_Warning_Switch (Chr);
12504 ("invalid warning switch character " & Chr,
12513 -- Two or more arguments (must be two)
12516 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12517 Check_At_Most_N_Arguments (2);
12525 E_Id := Expression (Arg2);
12528 -- In the expansion of an inlined body, a reference to
12529 -- the formal may be wrapped in a conversion if the
12530 -- actual is a conversion. Retrieve the real entity name.
12532 if (In_Instance_Body
12533 or else In_Inlined_Body)
12534 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12536 E_Id := Expression (E_Id);
12539 -- Entity name case
12541 if Is_Entity_Name (E_Id) then
12542 E := Entity (E_Id);
12549 (E, (Chars (Expression (Arg1)) = Name_Off));
12551 if Chars (Expression (Arg1)) = Name_Off
12552 and then Warn_On_Warnings_Off
12554 Warnings_Off_Pragmas.Append ((N, E));
12557 if Is_Enumeration_Type (E) then
12561 Lit := First_Literal (E);
12562 while Present (Lit) loop
12563 Set_Warnings_Off (Lit);
12564 Next_Literal (Lit);
12569 exit when No (Homonym (E));
12574 -- Error if not entity or static string literal case
12576 elsif not Is_Static_String_Expression (Arg2) then
12578 ("second argument of pragma% must be entity " &
12579 "name or static string expression", Arg2);
12581 -- String literal case
12584 String_To_Name_Buffer
12585 (Strval (Expr_Value_S (Expression (Arg2))));
12587 -- Note on configuration pragma case: If this is a
12588 -- configuration pragma, then for an OFF pragma, we
12589 -- just set Config True in the call, which is all
12590 -- that needs to be done. For the case of ON, this
12591 -- is normally an error, unless it is canceling the
12592 -- effect of a previous OFF pragma in the same file.
12593 -- In any other case, an error will be signalled (ON
12594 -- with no matching OFF).
12596 if Chars (Argx) = Name_Off then
12597 Set_Specific_Warning_Off
12598 (Loc, Name_Buffer (1 .. Name_Len),
12599 Config => Is_Configuration_Pragma);
12601 elsif Chars (Argx) = Name_On then
12602 Set_Specific_Warning_On
12603 (Loc, Name_Buffer (1 .. Name_Len), Err);
12607 ("?pragma Warnings On with no " &
12608 "matching Warnings Off",
12618 -------------------
12619 -- Weak_External --
12620 -------------------
12622 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12624 when Pragma_Weak_External => Weak_External : declare
12629 Check_Arg_Count (1);
12630 Check_Optional_Identifier (Arg1, Name_Entity);
12631 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12632 Ent := Entity (Expression (Arg1));
12634 if Rep_Item_Too_Early (Ent, N) then
12637 Ent := Underlying_Type (Ent);
12640 -- The only processing required is to link this item on to the
12641 -- list of rep items for the given entity. This is accomplished
12642 -- by the call to Rep_Item_Too_Late (when no error is detected
12643 -- and False is returned).
12645 if Rep_Item_Too_Late (Ent, N) then
12648 Set_Has_Gigi_Rep_Item (Ent);
12652 -----------------------------
12653 -- Wide_Character_Encoding --
12654 -----------------------------
12656 -- pragma Wide_Character_Encoding (IDENTIFIER);
12658 when Pragma_Wide_Character_Encoding =>
12661 -- Nothing to do, handled in parser. Note that we do not enforce
12662 -- configuration pragma placement, this pragma can appear at any
12663 -- place in the source, allowing mixed encodings within a single
12668 --------------------
12669 -- Unknown_Pragma --
12670 --------------------
12672 -- Should be impossible, since the case of an unknown pragma is
12673 -- separately processed before the case statement is entered.
12675 when Unknown_Pragma =>
12676 raise Program_Error;
12679 -- AI05-0144: detect dangerous order dependence. Disabled for now,
12680 -- until AI is formally approved.
12682 -- Check_Order_Dependence;
12685 when Pragma_Exit => null;
12686 end Analyze_Pragma;
12688 -------------------
12689 -- Check_Enabled --
12690 -------------------
12692 function Check_Enabled (Nam : Name_Id) return Boolean is
12696 PP := Opt.Check_Policy_List;
12699 return Assertions_Enabled;
12702 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12705 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12707 when Name_On | Name_Check =>
12709 when Name_Off | Name_Ignore =>
12712 raise Program_Error;
12716 PP := Next_Pragma (PP);
12721 ---------------------------------
12722 -- Delay_Config_Pragma_Analyze --
12723 ---------------------------------
12725 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12727 return Pragma_Name (N) = Name_Interrupt_State
12729 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12730 end Delay_Config_Pragma_Analyze;
12732 -------------------------
12733 -- Get_Base_Subprogram --
12734 -------------------------
12736 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12737 Result : Entity_Id;
12740 -- Follow subprogram renaming chain
12743 while Is_Subprogram (Result)
12745 (Is_Generic_Instance (Result)
12746 or else Nkind (Parent (Declaration_Node (Result))) =
12747 N_Subprogram_Renaming_Declaration)
12748 and then Present (Alias (Result))
12750 Result := Alias (Result);
12754 end Get_Base_Subprogram;
12756 --------------------
12757 -- Get_Pragma_Arg --
12758 --------------------
12760 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12762 if Nkind (Arg) = N_Pragma_Argument_Association then
12763 return Expression (Arg);
12767 end Get_Pragma_Arg;
12773 procedure Initialize is
12778 -----------------------------
12779 -- Is_Config_Static_String --
12780 -----------------------------
12782 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12784 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12785 -- This is an internal recursive function that is just like the outer
12786 -- function except that it adds the string to the name buffer rather
12787 -- than placing the string in the name buffer.
12789 ------------------------------
12790 -- Add_Config_Static_String --
12791 ------------------------------
12793 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12800 if Nkind (N) = N_Op_Concat then
12801 if Add_Config_Static_String (Left_Opnd (N)) then
12802 N := Right_Opnd (N);
12808 if Nkind (N) /= N_String_Literal then
12809 Error_Msg_N ("string literal expected for pragma argument", N);
12813 for J in 1 .. String_Length (Strval (N)) loop
12814 C := Get_String_Char (Strval (N), J);
12816 if not In_Character_Range (C) then
12818 ("string literal contains invalid wide character",
12819 Sloc (N) + 1 + Source_Ptr (J));
12823 Add_Char_To_Name_Buffer (Get_Character (C));
12828 end Add_Config_Static_String;
12830 -- Start of processing for Is_Config_Static_String
12835 return Add_Config_Static_String (Arg);
12836 end Is_Config_Static_String;
12838 -----------------------------------------
12839 -- Is_Non_Significant_Pragma_Reference --
12840 -----------------------------------------
12842 -- This function makes use of the following static table which indicates
12843 -- whether a given pragma is significant.
12845 -- -1 indicates that references in any argument position are significant
12846 -- 0 indicates that appearence in any argument is not significant
12847 -- +n indicates that appearence as argument n is significant, but all
12848 -- other arguments are not significant
12849 -- 99 special processing required (e.g. for pragma Check)
12851 Sig_Flags : constant array (Pragma_Id) of Int :=
12852 (Pragma_AST_Entry => -1,
12853 Pragma_Abort_Defer => -1,
12854 Pragma_Ada_83 => -1,
12855 Pragma_Ada_95 => -1,
12856 Pragma_Ada_05 => -1,
12857 Pragma_Ada_2005 => -1,
12858 Pragma_Ada_12 => -1,
12859 Pragma_Ada_2012 => -1,
12860 Pragma_All_Calls_Remote => -1,
12861 Pragma_Annotate => -1,
12862 Pragma_Assert => -1,
12863 Pragma_Assertion_Policy => 0,
12864 Pragma_Assume_No_Invalid_Values => 0,
12865 Pragma_Asynchronous => -1,
12866 Pragma_Atomic => 0,
12867 Pragma_Atomic_Components => 0,
12868 Pragma_Attach_Handler => -1,
12869 Pragma_Check => 99,
12870 Pragma_Check_Name => 0,
12871 Pragma_Check_Policy => 0,
12872 Pragma_CIL_Constructor => -1,
12873 Pragma_CPP_Class => 0,
12874 Pragma_CPP_Constructor => 0,
12875 Pragma_CPP_Virtual => 0,
12876 Pragma_CPP_Vtable => 0,
12877 Pragma_C_Pass_By_Copy => 0,
12878 Pragma_Comment => 0,
12879 Pragma_Common_Object => -1,
12880 Pragma_Compile_Time_Error => -1,
12881 Pragma_Compile_Time_Warning => -1,
12882 Pragma_Compiler_Unit => 0,
12883 Pragma_Complete_Representation => 0,
12884 Pragma_Complex_Representation => 0,
12885 Pragma_Component_Alignment => -1,
12886 Pragma_Controlled => 0,
12887 Pragma_Convention => 0,
12888 Pragma_Convention_Identifier => 0,
12889 Pragma_Debug => -1,
12890 Pragma_Debug_Policy => 0,
12891 Pragma_Detect_Blocking => -1,
12892 Pragma_Dimension => -1,
12893 Pragma_Discard_Names => 0,
12894 Pragma_Elaborate => -1,
12895 Pragma_Elaborate_All => -1,
12896 Pragma_Elaborate_Body => -1,
12897 Pragma_Elaboration_Checks => -1,
12898 Pragma_Eliminate => -1,
12899 Pragma_Export => -1,
12900 Pragma_Export_Exception => -1,
12901 Pragma_Export_Function => -1,
12902 Pragma_Export_Object => -1,
12903 Pragma_Export_Procedure => -1,
12904 Pragma_Export_Value => -1,
12905 Pragma_Export_Valued_Procedure => -1,
12906 Pragma_Extend_System => -1,
12907 Pragma_Extensions_Allowed => -1,
12908 Pragma_External => -1,
12909 Pragma_Favor_Top_Level => -1,
12910 Pragma_External_Name_Casing => -1,
12911 Pragma_Fast_Math => -1,
12912 Pragma_Finalize_Storage_Only => 0,
12913 Pragma_Float_Representation => 0,
12914 Pragma_Ident => -1,
12915 Pragma_Implemented_By_Entry => -1,
12916 Pragma_Implicit_Packing => 0,
12917 Pragma_Import => +2,
12918 Pragma_Import_Exception => 0,
12919 Pragma_Import_Function => 0,
12920 Pragma_Import_Object => 0,
12921 Pragma_Import_Procedure => 0,
12922 Pragma_Import_Valued_Procedure => 0,
12923 Pragma_Initialize_Scalars => -1,
12924 Pragma_Inline => 0,
12925 Pragma_Inline_Always => 0,
12926 Pragma_Inline_Generic => 0,
12927 Pragma_Inspection_Point => -1,
12928 Pragma_Interface => +2,
12929 Pragma_Interface_Name => +2,
12930 Pragma_Interrupt_Handler => -1,
12931 Pragma_Interrupt_Priority => -1,
12932 Pragma_Interrupt_State => -1,
12933 Pragma_Java_Constructor => -1,
12934 Pragma_Java_Interface => -1,
12935 Pragma_Keep_Names => 0,
12936 Pragma_License => -1,
12937 Pragma_Link_With => -1,
12938 Pragma_Linker_Alias => -1,
12939 Pragma_Linker_Constructor => -1,
12940 Pragma_Linker_Destructor => -1,
12941 Pragma_Linker_Options => -1,
12942 Pragma_Linker_Section => -1,
12944 Pragma_Locking_Policy => -1,
12945 Pragma_Long_Float => -1,
12946 Pragma_Machine_Attribute => -1,
12948 Pragma_Main_Storage => -1,
12949 Pragma_Memory_Size => -1,
12950 Pragma_No_Return => 0,
12951 Pragma_No_Body => 0,
12952 Pragma_No_Run_Time => -1,
12953 Pragma_No_Strict_Aliasing => -1,
12954 Pragma_Normalize_Scalars => -1,
12955 Pragma_Obsolescent => 0,
12956 Pragma_Optimize => -1,
12957 Pragma_Optimize_Alignment => -1,
12958 Pragma_Ordered => 0,
12961 Pragma_Passive => -1,
12962 Pragma_Preelaborable_Initialization => -1,
12963 Pragma_Polling => -1,
12964 Pragma_Persistent_BSS => 0,
12965 Pragma_Postcondition => -1,
12966 Pragma_Precondition => -1,
12967 Pragma_Preelaborate => -1,
12968 Pragma_Preelaborate_05 => -1,
12969 Pragma_Priority => -1,
12970 Pragma_Priority_Specific_Dispatching => -1,
12971 Pragma_Profile => 0,
12972 Pragma_Profile_Warnings => 0,
12973 Pragma_Propagate_Exceptions => -1,
12974 Pragma_Psect_Object => -1,
12976 Pragma_Pure_05 => -1,
12977 Pragma_Pure_Function => -1,
12978 Pragma_Queuing_Policy => -1,
12979 Pragma_Ravenscar => -1,
12980 Pragma_Relative_Deadline => -1,
12981 Pragma_Remote_Call_Interface => -1,
12982 Pragma_Remote_Types => -1,
12983 Pragma_Restricted_Run_Time => -1,
12984 Pragma_Restriction_Warnings => -1,
12985 Pragma_Restrictions => -1,
12986 Pragma_Reviewable => -1,
12987 Pragma_Short_Circuit_And_Or => -1,
12988 Pragma_Share_Generic => -1,
12989 Pragma_Shared => -1,
12990 Pragma_Shared_Passive => -1,
12991 Pragma_Short_Descriptors => 0,
12992 Pragma_Source_File_Name => -1,
12993 Pragma_Source_File_Name_Project => -1,
12994 Pragma_Source_Reference => -1,
12995 Pragma_Storage_Size => -1,
12996 Pragma_Storage_Unit => -1,
12997 Pragma_Static_Elaboration_Desired => -1,
12998 Pragma_Stream_Convert => -1,
12999 Pragma_Style_Checks => -1,
13000 Pragma_Subtitle => -1,
13001 Pragma_Suppress => 0,
13002 Pragma_Suppress_Exception_Locations => 0,
13003 Pragma_Suppress_All => -1,
13004 Pragma_Suppress_Debug_Info => 0,
13005 Pragma_Suppress_Initialization => 0,
13006 Pragma_System_Name => -1,
13007 Pragma_Task_Dispatching_Policy => -1,
13008 Pragma_Task_Info => -1,
13009 Pragma_Task_Name => -1,
13010 Pragma_Task_Storage => 0,
13011 Pragma_Thread_Local_Storage => 0,
13012 Pragma_Time_Slice => -1,
13013 Pragma_Title => -1,
13014 Pragma_Unchecked_Union => 0,
13015 Pragma_Unimplemented_Unit => -1,
13016 Pragma_Universal_Aliasing => -1,
13017 Pragma_Universal_Data => -1,
13018 Pragma_Unmodified => -1,
13019 Pragma_Unreferenced => -1,
13020 Pragma_Unreferenced_Objects => -1,
13021 Pragma_Unreserve_All_Interrupts => -1,
13022 Pragma_Unsuppress => 0,
13023 Pragma_Use_VADS_Size => -1,
13024 Pragma_Validity_Checks => -1,
13025 Pragma_Volatile => 0,
13026 Pragma_Volatile_Components => 0,
13027 Pragma_Warnings => -1,
13028 Pragma_Weak_External => -1,
13029 Pragma_Wide_Character_Encoding => 0,
13030 Unknown_Pragma => 0);
13032 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
13041 if Nkind (P) /= N_Pragma_Argument_Association then
13045 Id := Get_Pragma_Id (Parent (P));
13046 C := Sig_Flags (Id);
13058 -- For pragma Check, the first argument is not significant,
13059 -- the second and the third (if present) arguments are
13062 when Pragma_Check =>
13064 P = First (Pragma_Argument_Associations (Parent (P)));
13067 raise Program_Error;
13071 A := First (Pragma_Argument_Associations (Parent (P)));
13072 for J in 1 .. C - 1 loop
13080 return A = P; -- is this wrong way round ???
13083 end Is_Non_Significant_Pragma_Reference;
13085 ------------------------------
13086 -- Is_Pragma_String_Literal --
13087 ------------------------------
13089 -- This function returns true if the corresponding pragma argument is a
13090 -- static string expression. These are the only cases in which string
13091 -- literals can appear as pragma arguments. We also allow a string literal
13092 -- as the first argument to pragma Assert (although it will of course
13093 -- always generate a type error).
13095 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
13096 Pragn : constant Node_Id := Parent (Par);
13097 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
13098 Pname : constant Name_Id := Pragma_Name (Pragn);
13104 N := First (Assoc);
13111 if Pname = Name_Assert then
13114 elsif Pname = Name_Export then
13117 elsif Pname = Name_Ident then
13120 elsif Pname = Name_Import then
13123 elsif Pname = Name_Interface_Name then
13126 elsif Pname = Name_Linker_Alias then
13129 elsif Pname = Name_Linker_Section then
13132 elsif Pname = Name_Machine_Attribute then
13135 elsif Pname = Name_Source_File_Name then
13138 elsif Pname = Name_Source_Reference then
13141 elsif Pname = Name_Title then
13144 elsif Pname = Name_Subtitle then
13150 end Is_Pragma_String_Literal;
13152 --------------------------------------
13153 -- Process_Compilation_Unit_Pragmas --
13154 --------------------------------------
13156 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
13158 -- A special check for pragma Suppress_All, a very strange DEC pragma,
13159 -- strange because it comes at the end of the unit. If we have a pragma
13160 -- Suppress_All in the Pragmas_After of the current unit, then we insert
13161 -- a pragma Suppress (All_Checks) at the start of the context clause to
13162 -- ensure the correct processing.
13165 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
13169 if Present (PA) then
13171 while Present (P) loop
13172 if Pragma_Name (P) = Name_Suppress_All then
13173 Prepend_To (Context_Items (N),
13174 Make_Pragma (Sloc (P),
13175 Chars => Name_Suppress,
13176 Pragma_Argument_Associations => New_List (
13177 Make_Pragma_Argument_Association (Sloc (P),
13179 Make_Identifier (Sloc (P),
13180 Chars => Name_All_Checks)))));
13188 end Process_Compilation_Unit_Pragmas;
13199 --------------------------------
13200 -- Set_Encoded_Interface_Name --
13201 --------------------------------
13203 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
13204 Str : constant String_Id := Strval (S);
13205 Len : constant Int := String_Length (Str);
13210 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
13213 -- Stores encoded value of character code CC. The encoding we use an
13214 -- underscore followed by four lower case hex digits.
13220 procedure Encode is
13222 Store_String_Char (Get_Char_Code ('_'));
13224 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
13226 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
13228 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
13230 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
13233 -- Start of processing for Set_Encoded_Interface_Name
13236 -- If first character is asterisk, this is a link name, and we leave it
13237 -- completely unmodified. We also ignore null strings (the latter case
13238 -- happens only in error cases) and no encoding should occur for Java or
13239 -- AAMP interface names.
13242 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
13243 or else VM_Target /= No_VM
13244 or else AAMP_On_Target
13246 Set_Interface_Name (E, S);
13251 CC := Get_String_Char (Str, J);
13253 exit when not In_Character_Range (CC);
13255 C := Get_Character (CC);
13257 exit when C /= '_' and then C /= '$'
13258 and then C not in '0' .. '9'
13259 and then C not in 'a' .. 'z'
13260 and then C not in 'A' .. 'Z';
13263 Set_Interface_Name (E, S);
13271 -- Here we need to encode. The encoding we use as follows:
13272 -- three underscores + four hex digits (lower case)
13276 for J in 1 .. String_Length (Str) loop
13277 CC := Get_String_Char (Str, J);
13279 if not In_Character_Range (CC) then
13282 C := Get_Character (CC);
13284 if C = '_' or else C = '$'
13285 or else C in '0' .. '9'
13286 or else C in 'a' .. 'z'
13287 or else C in 'A' .. 'Z'
13289 Store_String_Char (CC);
13296 Set_Interface_Name (E,
13297 Make_String_Literal (Sloc (S),
13298 Strval => End_String));
13300 end Set_Encoded_Interface_Name;
13302 -------------------
13303 -- Set_Unit_Name --
13304 -------------------
13306 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
13311 if Nkind (N) = N_Identifier
13312 and then Nkind (With_Item) = N_Identifier
13314 Set_Entity (N, Entity (With_Item));
13316 elsif Nkind (N) = N_Selected_Component then
13317 Change_Selected_Component_To_Expanded_Name (N);
13318 Set_Entity (N, Entity (With_Item));
13319 Set_Entity (Selector_Name (N), Entity (N));
13321 Pref := Prefix (N);
13322 Scop := Scope (Entity (N));
13323 while Nkind (Pref) = N_Selected_Component loop
13324 Change_Selected_Component_To_Expanded_Name (Pref);
13325 Set_Entity (Selector_Name (Pref), Scop);
13326 Set_Entity (Pref, Scop);
13327 Pref := Prefix (Pref);
13328 Scop := Scope (Scop);
13331 Set_Entity (Pref, Scop);