1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Dist; use Exp_Dist;
42 with Lib.Writ; use Lib.Writ;
43 with Lib.Xref; use Lib.Xref;
44 with Namet.Sp; use Namet.Sp;
45 with Nlists; use Nlists;
46 with Nmake; use Nmake;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch6; use Sem_Ch6;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch12; use Sem_Ch12;
58 with Sem_Ch13; use Sem_Ch13;
59 with Sem_Dist; use Sem_Dist;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Intr; use Sem_Intr;
63 with Sem_Mech; use Sem_Mech;
64 with Sem_Res; use Sem_Res;
65 with Sem_Type; use Sem_Type;
66 with Sem_Util; use Sem_Util;
67 with Sem_VFpt; use Sem_VFpt;
68 with Sem_Warn; use Sem_Warn;
69 with Stand; use Stand;
70 with Sinfo; use Sinfo;
71 with Sinfo.CN; use Sinfo.CN;
72 with Sinput; use Sinput;
73 with Snames; use Snames;
74 with Stringt; use Stringt;
75 with Stylesw; use Stylesw;
77 with Targparm; use Targparm;
78 with Tbuild; use Tbuild;
80 with Uintp; use Uintp;
81 with Uname; use Uname;
82 with Urealp; use Urealp;
83 with Validsw; use Validsw;
85 package body Sem_Prag is
87 ----------------------------------------------
88 -- Common Handling of Import-Export Pragmas --
89 ----------------------------------------------
91 -- In the following section, a number of Import_xxx and Export_xxx
92 -- pragmas are defined by GNAT. These are compatible with the DEC
93 -- pragmas of the same name, and all have the following common
94 -- form and processing:
97 -- [Internal =>] LOCAL_NAME
98 -- [, [External =>] EXTERNAL_SYMBOL]
99 -- [, other optional parameters ]);
102 -- [Internal =>] LOCAL_NAME
103 -- [, [External =>] EXTERNAL_SYMBOL]
104 -- [, other optional parameters ]);
106 -- EXTERNAL_SYMBOL ::=
108 -- | static_string_EXPRESSION
110 -- The internal LOCAL_NAME designates the entity that is imported or
111 -- exported, and must refer to an entity in the current declarative
112 -- part (as required by the rules for LOCAL_NAME).
114 -- The external linker name is designated by the External parameter if
115 -- given, or the Internal parameter if not (if there is no External
116 -- parameter, the External parameter is a copy of the Internal name).
118 -- If the External parameter is given as a string, then this string is
119 -- treated as an external name (exactly as though it had been given as an
120 -- External_Name parameter for a normal Import pragma).
122 -- If the External parameter is given as an identifier (or there is no
123 -- External parameter, so that the Internal identifier is used), then
124 -- the external name is the characters of the identifier, translated
125 -- to all upper case letters for OpenVMS versions of GNAT, and to all
126 -- lower case letters for all other versions
128 -- Note: the external name specified or implied by any of these special
129 -- Import_xxx or Export_xxx pragmas override an external or link name
130 -- specified in a previous Import or Export pragma.
132 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
133 -- named notation, following the standard rules for subprogram calls, i.e.
134 -- parameters can be given in any order if named notation is used, and
135 -- positional and named notation can be mixed, subject to the rule that all
136 -- positional parameters must appear first.
138 -- Note: All these pragmas are implemented exactly following the DEC design
139 -- and implementation and are intended to be fully compatible with the use
140 -- of these pragmas in the DEC Ada compiler.
142 --------------------------------------------
143 -- Checking for Duplicated External Names --
144 --------------------------------------------
146 -- It is suspicious if two separate Export pragmas use the same external
147 -- name. The following table is used to diagnose this situation so that
148 -- an appropriate warning can be issued.
150 -- The Node_Id stored is for the N_String_Literal node created to hold
151 -- the value of the external name. The Sloc of this node is used to
152 -- cross-reference the location of the duplication.
154 package Externals is new Table.Table (
155 Table_Component_Type => Node_Id,
156 Table_Index_Type => Int,
157 Table_Low_Bound => 0,
158 Table_Initial => 100,
159 Table_Increment => 100,
160 Table_Name => "Name_Externals");
162 -------------------------------------
163 -- Local Subprograms and Variables --
164 -------------------------------------
166 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
167 -- This routine is used for possible casing adjustment of an explicit
168 -- external name supplied as a string literal (the node N), according to
169 -- the casing requirement of Opt.External_Name_Casing. If this is set to
170 -- As_Is, then the string literal is returned unchanged, but if it is set
171 -- to Uppercase or Lowercase, then a new string literal with appropriate
172 -- casing is constructed.
174 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
175 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
176 -- original one, following the renaming chain) is returned. Otherwise the
177 -- entity is returned unchanged. Should be in Einfo???
179 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id;
180 -- All the routines that check pragma arguments take either a pragma
181 -- argument association (in which case the expression of the argument
182 -- association is checked), or the expression directly. The function
183 -- Get_Pragma_Arg is a utility used to deal with these two cases. If Arg
184 -- is a pragma argument association node, then its expression is returned,
185 -- otherwise Arg is returned unchanged.
188 -- This is a dummy function called by the processing for pragma Reviewable.
189 -- It is there for assisting front end debugging. By placing a Reviewable
190 -- pragma in the source program, a breakpoint on rv catches this place in
191 -- the source, allowing convenient stepping to the point of interest.
193 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194 -- Place semantic information on the argument of an Elaborate/Elaborate_All
195 -- pragma. Entity name for unit and its parents is taken from item in
196 -- previous with_clause that mentions the unit.
198 -------------------------------
199 -- Adjust_External_Name_Case --
200 -------------------------------
202 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
206 -- Adjust case of literal if required
208 if Opt.External_Name_Exp_Casing = As_Is then
212 -- Copy existing string
218 for J in 1 .. String_Length (Strval (N)) loop
219 CC := Get_String_Char (Strval (N), J);
221 if Opt.External_Name_Exp_Casing = Uppercase
222 and then CC >= Get_Char_Code ('a')
223 and then CC <= Get_Char_Code ('z')
225 Store_String_Char (CC - 32);
227 elsif Opt.External_Name_Exp_Casing = Lowercase
228 and then CC >= Get_Char_Code ('A')
229 and then CC <= Get_Char_Code ('Z')
231 Store_String_Char (CC + 32);
234 Store_String_Char (CC);
239 Make_String_Literal (Sloc (N),
240 Strval => End_String);
242 end Adjust_External_Name_Case;
244 ------------------------------
245 -- Analyze_PPC_In_Decl_Part --
246 ------------------------------
248 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249 Arg1 : constant Node_Id :=
250 First (Pragma_Argument_Associations (N));
251 Arg2 : constant Node_Id := Next (Arg1);
254 -- Install formals and push subprogram spec onto scope stack so that we
255 -- can see the formals from the pragma.
260 -- Preanalyze the boolean expression, we treat this as a spec expression
261 -- (i.e. similar to a default expression).
263 Preanalyze_Spec_Expression
264 (Get_Pragma_Arg (Arg1), Standard_Boolean);
266 -- If there is a message argument, analyze it the same way
268 if Present (Arg2) then
269 Preanalyze_Spec_Expression
270 (Get_Pragma_Arg (Arg2), Standard_String);
273 -- Remove the subprogram from the scope stack now that the pre-analysis
274 -- of the precondition/postcondition is done.
277 end Analyze_PPC_In_Decl_Part;
283 procedure Analyze_Pragma (N : Node_Id) is
284 Loc : constant Source_Ptr := Sloc (N);
285 Pname : constant Name_Id := Pragma_Name (N);
288 Pragma_Exit : exception;
289 -- This exception is used to exit pragma processing completely. It is
290 -- used when an error is detected, and no further processing is
291 -- required. It is also used if an earlier error has left the tree in
292 -- a state where the pragma should not be processed.
295 -- Number of pragma argument associations
301 -- First four pragma arguments (pragma argument association nodes, or
302 -- Empty if the corresponding argument does not exist).
304 type Name_List is array (Natural range <>) of Name_Id;
305 type Args_List is array (Natural range <>) of Node_Id;
306 -- Types used for arguments to Check_Arg_Order and Gather_Associations
308 procedure Ada_2005_Pragma;
309 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
310 -- Ada 95 mode, these are implementation defined pragmas, so should be
311 -- caught by the No_Implementation_Pragmas restriction
313 procedure Check_Ada_83_Warning;
314 -- Issues a warning message for the current pragma if operating in Ada
315 -- 83 mode (used for language pragmas that are not a standard part of
316 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
319 procedure Check_Arg_Count (Required : Nat);
320 -- Check argument count for pragma is equal to given parameter. If not,
321 -- then issue an error message and raise Pragma_Exit.
323 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
324 -- Arg which can either be a pragma argument association, in which case
325 -- the check is applied to the expression of the association or an
326 -- expression directly.
328 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
329 -- Check that an argument has the right form for an EXTERNAL_NAME
330 -- parameter of an extended import/export pragma. The rule is that the
331 -- name must be an identifier or string literal (in Ada 83 mode) or a
332 -- static string expression (in Ada 95 mode).
334 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
335 -- Check the specified argument Arg to make sure that it is an
336 -- identifier. If not give error and raise Pragma_Exit.
338 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
339 -- Check the specified argument Arg to make sure that it is an integer
340 -- literal. If not give error and raise Pragma_Exit.
342 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
343 -- Check the specified argument Arg to make sure that it has the proper
344 -- syntactic form for a local name and meets the semantic requirements
345 -- for a local name. The local name is analyzed as part of the
346 -- processing for this call. In addition, the local name is required
347 -- to represent an entity at the library level.
349 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
350 -- Check the specified argument Arg to make sure that it has the proper
351 -- syntactic form for a local name and meets the semantic requirements
352 -- for a local name. The local name is analyzed as part of the
353 -- processing for this call.
355 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
356 -- Check the specified argument Arg to make sure that it is a valid
357 -- locking policy name. If not give error and raise Pragma_Exit.
359 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
360 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
361 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
362 -- Check the specified argument Arg to make sure that it is an
363 -- identifier whose name matches either N1 or N2 (or N3 if present).
364 -- If not then give error and raise Pragma_Exit.
366 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
367 -- Check the specified argument Arg to make sure that it is a valid
368 -- queuing policy name. If not give error and raise Pragma_Exit.
370 procedure Check_Arg_Is_Static_Expression
372 Typ : Entity_Id := Empty);
373 -- Check the specified argument Arg to make sure that it is a static
374 -- expression of the given type (i.e. it will be analyzed and resolved
375 -- using this type, which can be any valid argument to Resolve, e.g.
376 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
377 -- Typ is left Empty, then any static expression is allowed.
379 procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
380 -- Check the specified argument Arg to make sure that it is a string
381 -- literal. If not give error and raise Pragma_Exit
383 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
384 -- Check the specified argument Arg to make sure that it is a valid task
385 -- dispatching policy name. If not give error and raise Pragma_Exit.
387 procedure Check_Arg_Order (Names : Name_List);
388 -- Checks for an instance of two arguments with identifiers for the
389 -- current pragma which are not in the sequence indicated by Names,
390 -- and if so, generates a fatal message about bad order of arguments.
392 procedure Check_At_Least_N_Arguments (N : Nat);
393 -- Check there are at least N arguments present
395 procedure Check_At_Most_N_Arguments (N : Nat);
396 -- Check there are no more than N arguments present
398 procedure Check_Component (Comp : Node_Id);
399 -- Examine Unchecked_Union component for correct use of per-object
400 -- constrained subtypes, and for restrictions on finalizable components.
402 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
403 -- Nam is an N_String_Literal node containing the external name set by
404 -- an Import or Export pragma (or extended Import or Export pragma).
405 -- This procedure checks for possible duplications if this is the export
406 -- case, and if found, issues an appropriate error message.
408 procedure Check_First_Subtype (Arg : Node_Id);
409 -- Checks that Arg, whose expression is an entity name referencing a
410 -- subtype, does not reference a type that is not a first subtype.
412 procedure Check_In_Main_Program;
413 -- Common checks for pragmas that appear within a main program
414 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline).
416 procedure Check_Interrupt_Or_Attach_Handler;
417 -- Common processing for first argument of pragma Interrupt_Handler or
418 -- pragma Attach_Handler.
420 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
421 -- Check that pragma appears in a declarative part, or in a package
422 -- specification, i.e. that it does not occur in a statement sequence
425 procedure Check_No_Identifier (Arg : Node_Id);
426 -- Checks that the given argument does not have an identifier. If
427 -- an identifier is present, then an error message is issued, and
428 -- Pragma_Exit is raised.
430 procedure Check_No_Identifiers;
431 -- Checks that none of the arguments to the pragma has an identifier.
432 -- If any argument has an identifier, then an error message is issued,
433 -- and Pragma_Exit is raised.
435 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
436 -- Checks if the given argument has an identifier, and if so, requires
437 -- it to match the given identifier name. If there is a non-matching
438 -- identifier, then an error message is given and Error_Pragmas raised.
440 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
441 -- Checks if the given argument has an identifier, and if so, requires
442 -- it to match the given identifier name. If there is a non-matching
443 -- identifier, then an error message is given and Error_Pragmas raised.
444 -- In this version of the procedure, the identifier name is given as
445 -- a string with lower case letters.
447 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
448 -- Called to process a precondition or postcondition pragma. There are
451 -- The pragma appears after a subprogram spec
453 -- If the corresponding check is not enabled, the pragma is analyzed
454 -- but otherwise ignored and control returns with In_Body set False.
456 -- If the check is enabled, then the first step is to analyze the
457 -- pragma, but this is skipped if the subprogram spec appears within
458 -- a package specification (because this is the case where we delay
459 -- analysis till the end of the spec). Then (whether or not it was
460 -- analyzed), the pragma is chained to the subprogram in question
461 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
462 -- caller with In_Body set False.
464 -- The pragma appears at the start of subprogram body declarations
466 -- In this case an immediate return to the caller is made with
467 -- In_Body set True, and the pragma is NOT analyzed.
469 -- In all other cases, an error message for bad placement is given
471 procedure Check_Static_Constraint (Constr : Node_Id);
472 -- Constr is a constraint from an N_Subtype_Indication node from a
473 -- component constraint in an Unchecked_Union type. This routine checks
474 -- that the constraint is static as required by the restrictions for
477 procedure Check_Valid_Configuration_Pragma;
478 -- Legality checks for placement of a configuration pragma
480 procedure Check_Valid_Library_Unit_Pragma;
481 -- Legality checks for library unit pragmas. A special case arises for
482 -- pragmas in generic instances that come from copies of the original
483 -- library unit pragmas in the generic templates. In the case of other
484 -- than library level instantiations these can appear in contexts which
485 -- would normally be invalid (they only apply to the original template
486 -- and to library level instantiations), and they are simply ignored,
487 -- which is implemented by rewriting them as null statements.
489 procedure Check_Variant (Variant : Node_Id);
490 -- Check Unchecked_Union variant for lack of nested variants and
491 -- presence of at least one component.
493 procedure Error_Pragma (Msg : String);
494 pragma No_Return (Error_Pragma);
495 -- Outputs error message for current pragma. The message contains a %
496 -- that will be replaced with the pragma name, and the flag is placed
497 -- on the pragma itself. Pragma_Exit is then raised.
499 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
500 pragma No_Return (Error_Pragma_Arg);
501 -- Outputs error message for current pragma. The message may contain
502 -- a % that will be replaced with the pragma name. The parameter Arg
503 -- may either be a pragma argument association, in which case the flag
504 -- is placed on the expression of this association, or an expression,
505 -- in which case the flag is placed directly on the expression. The
506 -- message is placed using Error_Msg_N, so the message may also contain
507 -- an & insertion character which will reference the given Arg value.
508 -- After placing the message, Pragma_Exit is raised.
510 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
511 pragma No_Return (Error_Pragma_Arg);
512 -- Similar to above form of Error_Pragma_Arg except that two messages
513 -- are provided, the second is a continuation comment starting with \.
515 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
516 pragma No_Return (Error_Pragma_Arg_Ident);
517 -- Outputs error message for current pragma. The message may contain
518 -- a % that will be replaced with the pragma name. The parameter Arg
519 -- must be a pragma argument association with a non-empty identifier
520 -- (i.e. its Chars field must be set), and the error message is placed
521 -- on the identifier. The message is placed using Error_Msg_N so
522 -- the message may also contain an & insertion character which will
523 -- reference the identifier. After placing the message, Pragma_Exit
526 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
527 pragma No_Return (Error_Pragma_Ref);
528 -- Outputs error message for current pragma. The message may contain
529 -- a % that will be replaced with the pragma name. The parameter Ref
530 -- must be an entity whose name can be referenced by & and sloc by #.
531 -- After placing the message, Pragma_Exit is raised.
533 function Find_Lib_Unit_Name return Entity_Id;
534 -- Used for a library unit pragma to find the entity to which the
535 -- library unit pragma applies, returns the entity found.
537 procedure Find_Program_Unit_Name (Id : Node_Id);
538 -- If the pragma is a compilation unit pragma, the id must denote the
539 -- compilation unit in the same compilation, and the pragma must appear
540 -- in the list of preceding or trailing pragmas. If it is a program
541 -- unit pragma that is not a compilation unit pragma, then the
542 -- identifier must be visible.
544 function Find_Unique_Parameterless_Procedure
546 Arg : Node_Id) return Entity_Id;
547 -- Used for a procedure pragma to find the unique parameterless
548 -- procedure identified by Name, returns it if it exists, otherwise
549 -- errors out and uses Arg as the pragma argument for the message.
551 procedure Gather_Associations
553 Args : out Args_List);
554 -- This procedure is used to gather the arguments for a pragma that
555 -- permits arbitrary ordering of parameters using the normal rules
556 -- for named and positional parameters. The Names argument is a list
557 -- of Name_Id values that corresponds to the allowed pragma argument
558 -- association identifiers in order. The result returned in Args is
559 -- a list of corresponding expressions that are the pragma arguments.
560 -- Note that this is a list of expressions, not of pragma argument
561 -- associations (Gather_Associations has completely checked all the
562 -- optional identifiers when it returns). An entry in Args is Empty
563 -- on return if the corresponding argument is not present.
565 procedure GNAT_Pragma;
566 -- Called for all GNAT defined pragmas to check the relevant restriction
567 -- (No_Implementation_Pragmas).
569 function Is_Before_First_Decl
570 (Pragma_Node : Node_Id;
571 Decls : List_Id) return Boolean;
572 -- Return True if Pragma_Node is before the first declarative item in
573 -- Decls where Decls is the list of declarative items.
575 function Is_Configuration_Pragma return Boolean;
576 -- Determines if the placement of the current pragma is appropriate
577 -- for a configuration pragma.
579 function Is_In_Context_Clause return Boolean;
580 -- Returns True if pragma appears within the context clause of a unit,
581 -- and False for any other placement (does not generate any messages).
583 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
584 -- Analyzes the argument, and determines if it is a static string
585 -- expression, returns True if so, False if non-static or not String.
587 procedure Pragma_Misplaced;
588 pragma No_Return (Pragma_Misplaced);
589 -- Issue fatal error message for misplaced pragma
591 procedure Process_Atomic_Shared_Volatile;
592 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
593 -- Shared is an obsolete Ada 83 pragma, treated as being identical
594 -- in effect to pragma Atomic.
596 procedure Process_Compile_Time_Warning_Or_Error;
597 -- Common processing for Compile_Time_Error and Compile_Time_Warning
599 procedure Process_Convention (C : out Convention_Id; E : out Entity_Id);
600 -- Common processing for Convention, Interface, Import and Export.
601 -- Checks first two arguments of pragma, and sets the appropriate
602 -- convention value in the specified entity or entities. On return
603 -- C is the convention, E is the referenced entity.
605 procedure Process_Extended_Import_Export_Exception_Pragma
606 (Arg_Internal : Node_Id;
607 Arg_External : Node_Id;
610 -- Common processing for the pragmas Import/Export_Exception. The three
611 -- arguments correspond to the three named parameters of the pragma. An
612 -- argument is empty if the corresponding parameter is not present in
615 procedure Process_Extended_Import_Export_Object_Pragma
616 (Arg_Internal : Node_Id;
617 Arg_External : Node_Id;
619 -- Common processing for the pragmas Import/Export_Object. The three
620 -- arguments correspond to the three named parameters of the pragmas. An
621 -- argument is empty if the corresponding parameter is not present in
624 procedure Process_Extended_Import_Export_Internal_Arg
625 (Arg_Internal : Node_Id := Empty);
626 -- Common processing for all extended Import and Export pragmas. The
627 -- argument is the pragma parameter for the Internal argument. If
628 -- Arg_Internal is empty or inappropriate, an error message is posted.
629 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
630 -- set to identify the referenced entity.
632 procedure Process_Extended_Import_Export_Subprogram_Pragma
633 (Arg_Internal : Node_Id;
634 Arg_External : Node_Id;
635 Arg_Parameter_Types : Node_Id;
636 Arg_Result_Type : Node_Id := Empty;
637 Arg_Mechanism : Node_Id;
638 Arg_Result_Mechanism : Node_Id := Empty;
639 Arg_First_Optional_Parameter : Node_Id := Empty);
640 -- Common processing for all extended Import and Export pragmas applying
641 -- to subprograms. The caller omits any arguments that do not apply to
642 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
643 -- only in the Import_Function and Export_Function cases). The argument
644 -- names correspond to the allowed pragma association identifiers.
646 procedure Process_Generic_List;
647 -- Common processing for Share_Generic and Inline_Generic
649 procedure Process_Import_Or_Interface;
650 -- Common processing for Import of Interface
652 procedure Process_Inline (Active : Boolean);
653 -- Common processing for Inline and Inline_Always. The parameter
654 -- indicates if the inline pragma is active, i.e. if it should actually
655 -- cause inlining to occur.
657 procedure Process_Interface_Name
658 (Subprogram_Def : Entity_Id;
661 -- Given the last two arguments of pragma Import, pragma Export, or
662 -- pragma Interface_Name, performs validity checks and sets the
663 -- Interface_Name field of the given subprogram entity to the
664 -- appropriate external or link name, depending on the arguments given.
665 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
666 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
667 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
668 -- nor Link_Arg is present, the interface name is set to the default
669 -- from the subprogram name.
671 procedure Process_Interrupt_Or_Attach_Handler;
672 -- Common processing for Interrupt and Attach_Handler pragmas
674 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
675 -- Common processing for Restrictions and Restriction_Warnings pragmas.
676 -- Warn is True for Restriction_Warnings, or for Restrictions if the
677 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
678 -- is not set in the Restrictions case.
680 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
681 -- Common processing for Suppress and Unsuppress. The boolean parameter
682 -- Suppress_Case is True for the Suppress case, and False for the
685 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
686 -- This procedure sets the Is_Exported flag for the given entity,
687 -- checking that the entity was not previously imported. Arg is
688 -- the argument that specified the entity. A check is also made
689 -- for exporting inappropriate entities.
691 procedure Set_Extended_Import_Export_External_Name
692 (Internal_Ent : Entity_Id;
693 Arg_External : Node_Id);
694 -- Common processing for all extended import export pragmas. The first
695 -- argument, Internal_Ent, is the internal entity, which has already
696 -- been checked for validity by the caller. Arg_External is from the
697 -- Import or Export pragma, and may be null if no External parameter
698 -- was present. If Arg_External is present and is a non-null string
699 -- (a null string is treated as the default), then the Interface_Name
700 -- field of Internal_Ent is set appropriately.
702 procedure Set_Imported (E : Entity_Id);
703 -- This procedure sets the Is_Imported flag for the given entity,
704 -- checking that it is not previously exported or imported.
706 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
707 -- Mech is a parameter passing mechanism (see Import_Function syntax
708 -- for MECHANISM_NAME). This routine checks that the mechanism argument
709 -- has the right form, and if not issues an error message. If the
710 -- argument has the right form then the Mechanism field of Ent is
711 -- set appropriately.
713 procedure Set_Ravenscar_Profile (N : Node_Id);
714 -- Activate the set of configuration pragmas and restrictions that make
715 -- up the Ravenscar Profile. N is the corresponding pragma node, which
716 -- is used for error messages on any constructs that violate the
719 ---------------------
720 -- Ada_2005_Pragma --
721 ---------------------
723 procedure Ada_2005_Pragma is
725 if Ada_Version <= Ada_95 then
726 Check_Restriction (No_Implementation_Pragmas, N);
730 --------------------------
731 -- Check_Ada_83_Warning --
732 --------------------------
734 procedure Check_Ada_83_Warning is
736 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
737 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
739 end Check_Ada_83_Warning;
741 ---------------------
742 -- Check_Arg_Count --
743 ---------------------
745 procedure Check_Arg_Count (Required : Nat) is
747 if Arg_Count /= Required then
748 Error_Pragma ("wrong number of arguments for pragma%");
752 --------------------------------
753 -- Check_Arg_Is_External_Name --
754 --------------------------------
756 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
757 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
760 if Nkind (Argx) = N_Identifier then
764 Analyze_And_Resolve (Argx, Standard_String);
766 if Is_OK_Static_Expression (Argx) then
769 elsif Etype (Argx) = Any_Type then
772 -- An interesting special case, if we have a string literal and
773 -- we are in Ada 83 mode, then we allow it even though it will
774 -- not be flagged as static. This allows expected Ada 83 mode
775 -- use of external names which are string literals, even though
776 -- technically these are not static in Ada 83.
778 elsif Ada_Version = Ada_83
779 and then Nkind (Argx) = N_String_Literal
783 -- Static expression that raises Constraint_Error. This has
784 -- already been flagged, so just exit from pragma processing.
786 elsif Is_Static_Expression (Argx) then
789 -- Here we have a real error (non-static expression)
792 Error_Msg_Name_1 := Pname;
794 ("argument for pragma% must be a identifier or " &
795 "static string expression!", Argx);
799 end Check_Arg_Is_External_Name;
801 -----------------------------
802 -- Check_Arg_Is_Identifier --
803 -----------------------------
805 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
806 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
808 if Nkind (Argx) /= N_Identifier then
810 ("argument for pragma% must be identifier", Argx);
812 end Check_Arg_Is_Identifier;
814 ----------------------------------
815 -- Check_Arg_Is_Integer_Literal --
816 ----------------------------------
818 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
819 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
821 if Nkind (Argx) /= N_Integer_Literal then
823 ("argument for pragma% must be integer literal", Argx);
825 end Check_Arg_Is_Integer_Literal;
827 -------------------------------------------
828 -- Check_Arg_Is_Library_Level_Local_Name --
829 -------------------------------------------
833 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
834 -- | library_unit_NAME
836 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
838 Check_Arg_Is_Local_Name (Arg);
840 if not Is_Library_Level_Entity (Entity (Expression (Arg)))
841 and then Comes_From_Source (N)
844 ("argument for pragma% must be library level entity", Arg);
846 end Check_Arg_Is_Library_Level_Local_Name;
848 -----------------------------
849 -- Check_Arg_Is_Local_Name --
850 -----------------------------
854 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
855 -- | library_unit_NAME
857 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
858 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
863 if Nkind (Argx) not in N_Direct_Name
864 and then (Nkind (Argx) /= N_Attribute_Reference
865 or else Present (Expressions (Argx))
866 or else Nkind (Prefix (Argx)) /= N_Identifier)
867 and then (not Is_Entity_Name (Argx)
868 or else not Is_Compilation_Unit (Entity (Argx)))
870 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
873 if Is_Entity_Name (Argx)
874 and then Scope (Entity (Argx)) /= Current_Scope
877 ("pragma% argument must be in same declarative part", Arg);
879 end Check_Arg_Is_Local_Name;
881 ---------------------------------
882 -- Check_Arg_Is_Locking_Policy --
883 ---------------------------------
885 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
886 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
889 Check_Arg_Is_Identifier (Argx);
891 if not Is_Locking_Policy_Name (Chars (Argx)) then
893 ("& is not a valid locking policy name", Argx);
895 end Check_Arg_Is_Locking_Policy;
897 -------------------------
898 -- Check_Arg_Is_One_Of --
899 -------------------------
901 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
902 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
905 Check_Arg_Is_Identifier (Argx);
907 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
908 Error_Msg_Name_2 := N1;
909 Error_Msg_Name_3 := N2;
910 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
912 end Check_Arg_Is_One_Of;
914 procedure Check_Arg_Is_One_Of
916 N1, N2, N3 : Name_Id)
918 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
921 Check_Arg_Is_Identifier (Argx);
923 if Chars (Argx) /= N1
924 and then Chars (Argx) /= N2
925 and then Chars (Argx) /= N3
927 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
929 end Check_Arg_Is_One_Of;
931 procedure Check_Arg_Is_One_Of
933 N1, N2, N3, N4 : Name_Id)
935 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
938 Check_Arg_Is_Identifier (Argx);
940 if Chars (Argx) /= N1
941 and then Chars (Argx) /= N2
942 and then Chars (Argx) /= N3
943 and then Chars (Argx) /= N4
945 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
947 end Check_Arg_Is_One_Of;
949 ---------------------------------
950 -- Check_Arg_Is_Queuing_Policy --
951 ---------------------------------
953 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
954 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
957 Check_Arg_Is_Identifier (Argx);
959 if not Is_Queuing_Policy_Name (Chars (Argx)) then
961 ("& is not a valid queuing policy name", Argx);
963 end Check_Arg_Is_Queuing_Policy;
965 ------------------------------------
966 -- Check_Arg_Is_Static_Expression --
967 ------------------------------------
969 procedure Check_Arg_Is_Static_Expression
971 Typ : Entity_Id := Empty)
973 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
976 if Present (Typ) then
977 Analyze_And_Resolve (Argx, Typ);
979 Analyze_And_Resolve (Argx);
982 if Is_OK_Static_Expression (Argx) then
985 elsif Etype (Argx) = Any_Type then
988 -- An interesting special case, if we have a string literal and we
989 -- are in Ada 83 mode, then we allow it even though it will not be
990 -- flagged as static. This allows the use of Ada 95 pragmas like
991 -- Import in Ada 83 mode. They will of course be flagged with
992 -- warnings as usual, but will not cause errors.
994 elsif Ada_Version = Ada_83
995 and then Nkind (Argx) = N_String_Literal
999 -- Static expression that raises Constraint_Error. This has already
1000 -- been flagged, so just exit from pragma processing.
1002 elsif Is_Static_Expression (Argx) then
1005 -- Finally, we have a real error
1008 Error_Msg_Name_1 := Pname;
1009 Flag_Non_Static_Expr
1010 ("argument for pragma% must be a static expression!", Argx);
1013 end Check_Arg_Is_Static_Expression;
1015 ---------------------------------
1016 -- Check_Arg_Is_String_Literal --
1017 ---------------------------------
1019 procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
1020 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1022 if Nkind (Argx) /= N_String_Literal then
1024 ("argument for pragma% must be string literal", Argx);
1026 end Check_Arg_Is_String_Literal;
1028 ------------------------------------------
1029 -- Check_Arg_Is_Task_Dispatching_Policy --
1030 ------------------------------------------
1032 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1033 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1036 Check_Arg_Is_Identifier (Argx);
1038 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1040 ("& is not a valid task dispatching policy name", Argx);
1042 end Check_Arg_Is_Task_Dispatching_Policy;
1044 ---------------------
1045 -- Check_Arg_Order --
1046 ---------------------
1048 procedure Check_Arg_Order (Names : Name_List) is
1051 Highest_So_Far : Natural := 0;
1052 -- Highest index in Names seen do far
1056 for J in 1 .. Arg_Count loop
1057 if Chars (Arg) /= No_Name then
1058 for K in Names'Range loop
1059 if Chars (Arg) = Names (K) then
1060 if K < Highest_So_Far then
1061 Error_Msg_Name_1 := Pname;
1063 ("parameters out of order for pragma%", Arg);
1064 Error_Msg_Name_1 := Names (K);
1065 Error_Msg_Name_2 := Names (Highest_So_Far);
1066 Error_Msg_N ("\% must appear before %", Arg);
1070 Highest_So_Far := K;
1078 end Check_Arg_Order;
1080 --------------------------------
1081 -- Check_At_Least_N_Arguments --
1082 --------------------------------
1084 procedure Check_At_Least_N_Arguments (N : Nat) is
1086 if Arg_Count < N then
1087 Error_Pragma ("too few arguments for pragma%");
1089 end Check_At_Least_N_Arguments;
1091 -------------------------------
1092 -- Check_At_Most_N_Arguments --
1093 -------------------------------
1095 procedure Check_At_Most_N_Arguments (N : Nat) is
1098 if Arg_Count > N then
1100 for J in 1 .. N loop
1102 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1105 end Check_At_Most_N_Arguments;
1107 ---------------------
1108 -- Check_Component --
1109 ---------------------
1111 procedure Check_Component (Comp : Node_Id) is
1113 if Nkind (Comp) = N_Component_Declaration then
1115 Sindic : constant Node_Id :=
1116 Subtype_Indication (Component_Definition (Comp));
1117 Typ : constant Entity_Id :=
1118 Etype (Defining_Identifier (Comp));
1120 if Nkind (Sindic) = N_Subtype_Indication then
1122 -- Ada 2005 (AI-216): If a component subtype is subject to
1123 -- a per-object constraint, then the component type shall
1124 -- be an Unchecked_Union.
1126 if Has_Per_Object_Constraint (Defining_Identifier (Comp))
1128 not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1130 Error_Msg_N ("component subtype subject to per-object" &
1131 " constraint must be an Unchecked_Union", Comp);
1135 if Is_Controlled (Typ) then
1137 ("component of unchecked union cannot be controlled", Comp);
1139 elsif Has_Task (Typ) then
1141 ("component of unchecked union cannot have tasks", Comp);
1145 end Check_Component;
1147 ----------------------------------
1148 -- Check_Duplicated_Export_Name --
1149 ----------------------------------
1151 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1152 String_Val : constant String_Id := Strval (Nam);
1155 -- We are only interested in the export case, and in the case of
1156 -- generics, it is the instance, not the template, that is the
1157 -- problem (the template will generate a warning in any case).
1159 if not Inside_A_Generic
1160 and then (Prag_Id = Pragma_Export
1162 Prag_Id = Pragma_Export_Procedure
1164 Prag_Id = Pragma_Export_Valued_Procedure
1166 Prag_Id = Pragma_Export_Function)
1168 for J in Externals.First .. Externals.Last loop
1169 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1170 Error_Msg_Sloc := Sloc (Externals.Table (J));
1171 Error_Msg_N ("external name duplicates name given#", Nam);
1176 Externals.Append (Nam);
1178 end Check_Duplicated_Export_Name;
1180 -------------------------
1181 -- Check_First_Subtype --
1182 -------------------------
1184 procedure Check_First_Subtype (Arg : Node_Id) is
1185 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1187 if not Is_First_Subtype (Entity (Argx)) then
1189 ("pragma% cannot apply to subtype", Argx);
1191 end Check_First_Subtype;
1193 ---------------------------
1194 -- Check_In_Main_Program --
1195 ---------------------------
1197 procedure Check_In_Main_Program is
1198 P : constant Node_Id := Parent (N);
1201 -- Must be at in subprogram body
1203 if Nkind (P) /= N_Subprogram_Body then
1204 Error_Pragma ("% pragma allowed only in subprogram");
1206 -- Otherwise warn if obviously not main program
1208 elsif Present (Parameter_Specifications (Specification (P)))
1209 or else not Is_Compilation_Unit (Defining_Entity (P))
1211 Error_Msg_Name_1 := Pname;
1213 ("?pragma% is only effective in main program", N);
1215 end Check_In_Main_Program;
1217 ---------------------------------------
1218 -- Check_Interrupt_Or_Attach_Handler --
1219 ---------------------------------------
1221 procedure Check_Interrupt_Or_Attach_Handler is
1222 Arg1_X : constant Node_Id := Expression (Arg1);
1223 Handler_Proc, Proc_Scope : Entity_Id;
1228 if Prag_Id = Pragma_Interrupt_Handler then
1229 Check_Restriction (No_Dynamic_Attachment, N);
1232 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1233 Proc_Scope := Scope (Handler_Proc);
1235 -- On AAMP only, a pragma Interrupt_Handler is supported for
1236 -- nonprotected parameterless procedures.
1238 if not AAMP_On_Target
1239 or else Prag_Id = Pragma_Attach_Handler
1241 if Ekind (Proc_Scope) /= E_Protected_Type then
1243 ("argument of pragma% must be protected procedure", Arg1);
1246 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1247 Error_Pragma ("pragma% must be in protected definition");
1251 if not Is_Library_Level_Entity (Proc_Scope)
1252 or else (AAMP_On_Target
1253 and then not Is_Library_Level_Entity (Handler_Proc))
1256 ("argument for pragma% must be library level entity", Arg1);
1258 end Check_Interrupt_Or_Attach_Handler;
1260 -------------------------------------------
1261 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1262 -------------------------------------------
1264 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1273 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1276 elsif Nkind_In (P, N_Package_Specification,
1281 -- Note: the following tests seem a little peculiar, because
1282 -- they test for bodies, but if we were in the statement part
1283 -- of the body, we would already have hit the handled statement
1284 -- sequence, so the only way we get here is by being in the
1285 -- declarative part of the body.
1287 elsif Nkind_In (P, N_Subprogram_Body,
1298 Error_Pragma ("pragma% is not in declarative part or package spec");
1299 end Check_Is_In_Decl_Part_Or_Package_Spec;
1301 -------------------------
1302 -- Check_No_Identifier --
1303 -------------------------
1305 procedure Check_No_Identifier (Arg : Node_Id) is
1307 if Chars (Arg) /= No_Name then
1308 Error_Pragma_Arg_Ident
1309 ("pragma% does not permit identifier& here", Arg);
1311 end Check_No_Identifier;
1313 --------------------------
1314 -- Check_No_Identifiers --
1315 --------------------------
1317 procedure Check_No_Identifiers is
1320 if Arg_Count > 0 then
1322 while Present (Arg_Node) loop
1323 Check_No_Identifier (Arg_Node);
1327 end Check_No_Identifiers;
1329 -------------------------------
1330 -- Check_Optional_Identifier --
1331 -------------------------------
1333 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1335 if Present (Arg) and then Chars (Arg) /= No_Name then
1336 if Chars (Arg) /= Id then
1337 Error_Msg_Name_1 := Pname;
1338 Error_Msg_Name_2 := Id;
1339 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1343 end Check_Optional_Identifier;
1345 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1347 Name_Buffer (1 .. Id'Length) := Id;
1348 Name_Len := Id'Length;
1349 Check_Optional_Identifier (Arg, Name_Find);
1350 end Check_Optional_Identifier;
1352 --------------------------------------
1353 -- Check_Precondition_Postcondition --
1354 --------------------------------------
1356 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1360 procedure Chain_PPC (PO : Node_Id);
1361 -- If PO is a subprogram declaration node (or a generic subprogram
1362 -- declaration node), then the precondition/postcondition applies
1363 -- to this subprogram and the processing for the pragma is completed.
1364 -- Otherwise the pragma is misplaced.
1370 procedure Chain_PPC (PO : Node_Id) is
1374 if not Nkind_In (PO, N_Subprogram_Declaration,
1375 N_Generic_Subprogram_Declaration)
1380 -- Here if we have subprogram or generic subprogram declaration
1382 S := Defining_Unit_Name (Specification (PO));
1384 -- Analyze the pragma unless it appears within a package spec,
1385 -- which is the case where we delay the analysis of the PPC until
1386 -- the end of the package declarations (for details, see
1387 -- Analyze_Package_Specification.Analyze_PPCs).
1389 if not Is_Package_Or_Generic_Package (Scope (S)) then
1390 Analyze_PPC_In_Decl_Part (N, S);
1393 -- Chain spec PPC pragma to list for subprogram
1395 Set_Next_Pragma (N, Spec_PPC_List (S));
1396 Set_Spec_PPC_List (S, N);
1398 -- Return indicating spec case
1404 -- Start of processing for Check_Precondition_Postcondition
1407 if not Is_List_Member (N) then
1411 -- Record whether pragma is enabled
1413 Set_PPC_Enabled (N, Check_Enabled (Pname));
1415 -- If we are within an inlined body, the legality of the pragma
1416 -- has been checked already.
1418 if In_Inlined_Body then
1423 -- Search prior declarations
1426 while Present (Prev (P)) loop
1429 -- If the previous node is a generic subprogram, do not go to to
1430 -- the original node, which is the unanalyzed tree: we need to
1431 -- attach the pre/postconditions to the analyzed version at this
1432 -- point. They get propagated to the original tree when analyzing
1433 -- the corresponding body.
1435 if Nkind (P) not in N_Generic_Declaration then
1436 PO := Original_Node (P);
1441 -- Skip past prior pragma
1443 if Nkind (PO) = N_Pragma then
1446 -- Skip stuff not coming from source
1448 elsif not Comes_From_Source (PO) then
1451 -- Only remaining possibility is subprogram declaration
1459 -- If we fall through loop, pragma is at start of list, so see if it
1460 -- is at the start of declarations of a subprogram body.
1462 if Nkind (Parent (N)) = N_Subprogram_Body
1463 and then List_Containing (N) = Declarations (Parent (N))
1465 if Operating_Mode /= Generate_Code
1466 or else Inside_A_Generic
1469 -- Analyze expression in pragma, for correctness
1470 -- and for ASIS use.
1472 Preanalyze_Spec_Expression
1473 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1479 -- See if it is in the pragmas after a library level subprogram
1481 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1482 Chain_PPC (Unit (Parent (Parent (N))));
1486 -- If we fall through, pragma was misplaced
1489 end Check_Precondition_Postcondition;
1491 -----------------------------
1492 -- Check_Static_Constraint --
1493 -----------------------------
1495 -- Note: for convenience in writing this procedure, in addition to
1496 -- the officially (i.e. by spec) allowed argument which is always a
1497 -- constraint, it also allows ranges and discriminant associations.
1498 -- Above is not clear ???
1500 procedure Check_Static_Constraint (Constr : Node_Id) is
1502 procedure Require_Static (E : Node_Id);
1503 -- Require given expression to be static expression
1505 --------------------
1506 -- Require_Static --
1507 --------------------
1509 procedure Require_Static (E : Node_Id) is
1511 if not Is_OK_Static_Expression (E) then
1512 Flag_Non_Static_Expr
1513 ("non-static constraint not allowed in Unchecked_Union!", E);
1518 -- Start of processing for Check_Static_Constraint
1521 case Nkind (Constr) is
1522 when N_Discriminant_Association =>
1523 Require_Static (Expression (Constr));
1526 Require_Static (Low_Bound (Constr));
1527 Require_Static (High_Bound (Constr));
1529 when N_Attribute_Reference =>
1530 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1531 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1533 when N_Range_Constraint =>
1534 Check_Static_Constraint (Range_Expression (Constr));
1536 when N_Index_Or_Discriminant_Constraint =>
1540 IDC := First (Constraints (Constr));
1541 while Present (IDC) loop
1542 Check_Static_Constraint (IDC);
1550 end Check_Static_Constraint;
1552 --------------------------------------
1553 -- Check_Valid_Configuration_Pragma --
1554 --------------------------------------
1556 -- A configuration pragma must appear in the context clause of a
1557 -- compilation unit, and only other pragmas may precede it. Note that
1558 -- the test also allows use in a configuration pragma file.
1560 procedure Check_Valid_Configuration_Pragma is
1562 if not Is_Configuration_Pragma then
1563 Error_Pragma ("incorrect placement for configuration pragma%");
1565 end Check_Valid_Configuration_Pragma;
1567 -------------------------------------
1568 -- Check_Valid_Library_Unit_Pragma --
1569 -------------------------------------
1571 procedure Check_Valid_Library_Unit_Pragma is
1573 Parent_Node : Node_Id;
1574 Unit_Name : Entity_Id;
1575 Unit_Kind : Node_Kind;
1576 Unit_Node : Node_Id;
1577 Sindex : Source_File_Index;
1580 if not Is_List_Member (N) then
1584 Plist := List_Containing (N);
1585 Parent_Node := Parent (Plist);
1587 if Parent_Node = Empty then
1590 -- Case of pragma appearing after a compilation unit. In this case
1591 -- it must have an argument with the corresponding name and must
1592 -- be part of the following pragmas of its parent.
1594 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1595 if Plist /= Pragmas_After (Parent_Node) then
1598 elsif Arg_Count = 0 then
1600 ("argument required if outside compilation unit");
1603 Check_No_Identifiers;
1604 Check_Arg_Count (1);
1605 Unit_Node := Unit (Parent (Parent_Node));
1606 Unit_Kind := Nkind (Unit_Node);
1608 Analyze (Expression (Arg1));
1610 if Unit_Kind = N_Generic_Subprogram_Declaration
1611 or else Unit_Kind = N_Subprogram_Declaration
1613 Unit_Name := Defining_Entity (Unit_Node);
1615 elsif Unit_Kind in N_Generic_Instantiation then
1616 Unit_Name := Defining_Entity (Unit_Node);
1619 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1622 if Chars (Unit_Name) /=
1623 Chars (Entity (Expression (Arg1)))
1626 ("pragma% argument is not current unit name", Arg1);
1629 if Ekind (Unit_Name) = E_Package
1630 and then Present (Renamed_Entity (Unit_Name))
1632 Error_Pragma ("pragma% not allowed for renamed package");
1636 -- Pragma appears other than after a compilation unit
1639 -- Here we check for the generic instantiation case and also
1640 -- for the case of processing a generic formal package. We
1641 -- detect these cases by noting that the Sloc on the node
1642 -- does not belong to the current compilation unit.
1644 Sindex := Source_Index (Current_Sem_Unit);
1646 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1647 Rewrite (N, Make_Null_Statement (Loc));
1650 -- If before first declaration, the pragma applies to the
1651 -- enclosing unit, and the name if present must be this name.
1653 elsif Is_Before_First_Decl (N, Plist) then
1654 Unit_Node := Unit_Declaration_Node (Current_Scope);
1655 Unit_Kind := Nkind (Unit_Node);
1657 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1660 elsif Unit_Kind = N_Subprogram_Body
1661 and then not Acts_As_Spec (Unit_Node)
1665 elsif Nkind (Parent_Node) = N_Package_Body then
1668 elsif Nkind (Parent_Node) = N_Package_Specification
1669 and then Plist = Private_Declarations (Parent_Node)
1673 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1674 or else Nkind (Parent_Node) =
1675 N_Generic_Subprogram_Declaration)
1676 and then Plist = Generic_Formal_Declarations (Parent_Node)
1680 elsif Arg_Count > 0 then
1681 Analyze (Expression (Arg1));
1683 if Entity (Expression (Arg1)) /= Current_Scope then
1685 ("name in pragma% must be enclosing unit", Arg1);
1688 -- It is legal to have no argument in this context
1694 -- Error if not before first declaration. This is because a
1695 -- library unit pragma argument must be the name of a library
1696 -- unit (RM 10.1.5(7)), but the only names permitted in this
1697 -- context are (RM 10.1.5(6)) names of subprogram declarations,
1698 -- generic subprogram declarations or generic instantiations.
1702 ("pragma% misplaced, must be before first declaration");
1706 end Check_Valid_Library_Unit_Pragma;
1712 procedure Check_Variant (Variant : Node_Id) is
1713 Clist : constant Node_Id := Component_List (Variant);
1717 if not Is_Non_Empty_List (Component_Items (Clist)) then
1719 ("Unchecked_Union may not have empty component list",
1724 Comp := First (Component_Items (Clist));
1725 while Present (Comp) loop
1726 Check_Component (Comp);
1735 procedure Error_Pragma (Msg : String) is
1737 Error_Msg_Name_1 := Pname;
1738 Error_Msg_N (Msg, N);
1742 ----------------------
1743 -- Error_Pragma_Arg --
1744 ----------------------
1746 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
1748 Error_Msg_Name_1 := Pname;
1749 Error_Msg_N (Msg, Get_Pragma_Arg (Arg));
1751 end Error_Pragma_Arg;
1753 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
1755 Error_Msg_Name_1 := Pname;
1756 Error_Msg_N (Msg1, Get_Pragma_Arg (Arg));
1757 Error_Pragma_Arg (Msg2, Arg);
1758 end Error_Pragma_Arg;
1760 ----------------------------
1761 -- Error_Pragma_Arg_Ident --
1762 ----------------------------
1764 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
1766 Error_Msg_Name_1 := Pname;
1767 Error_Msg_N (Msg, Arg);
1769 end Error_Pragma_Arg_Ident;
1771 ----------------------
1772 -- Error_Pragma_Ref --
1773 ----------------------
1775 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
1777 Error_Msg_Name_1 := Pname;
1778 Error_Msg_Sloc := Sloc (Ref);
1779 Error_Msg_NE (Msg, N, Ref);
1781 end Error_Pragma_Ref;
1783 ------------------------
1784 -- Find_Lib_Unit_Name --
1785 ------------------------
1787 function Find_Lib_Unit_Name return Entity_Id is
1789 -- Return inner compilation unit entity, for case of nested
1790 -- categorization pragmas. This happens in generic unit.
1792 if Nkind (Parent (N)) = N_Package_Specification
1793 and then Defining_Entity (Parent (N)) /= Current_Scope
1795 return Defining_Entity (Parent (N));
1797 return Current_Scope;
1799 end Find_Lib_Unit_Name;
1801 ----------------------------
1802 -- Find_Program_Unit_Name --
1803 ----------------------------
1805 procedure Find_Program_Unit_Name (Id : Node_Id) is
1806 Unit_Name : Entity_Id;
1807 Unit_Kind : Node_Kind;
1808 P : constant Node_Id := Parent (N);
1811 if Nkind (P) = N_Compilation_Unit then
1812 Unit_Kind := Nkind (Unit (P));
1814 if Unit_Kind = N_Subprogram_Declaration
1815 or else Unit_Kind = N_Package_Declaration
1816 or else Unit_Kind in N_Generic_Declaration
1818 Unit_Name := Defining_Entity (Unit (P));
1820 if Chars (Id) = Chars (Unit_Name) then
1821 Set_Entity (Id, Unit_Name);
1822 Set_Etype (Id, Etype (Unit_Name));
1824 Set_Etype (Id, Any_Type);
1826 ("cannot find program unit referenced by pragma%");
1830 Set_Etype (Id, Any_Type);
1831 Error_Pragma ("pragma% inapplicable to this unit");
1837 end Find_Program_Unit_Name;
1839 -----------------------------------------
1840 -- Find_Unique_Parameterless_Procedure --
1841 -----------------------------------------
1843 function Find_Unique_Parameterless_Procedure
1845 Arg : Node_Id) return Entity_Id
1847 Proc : Entity_Id := Empty;
1850 -- The body of this procedure needs some comments ???
1852 if not Is_Entity_Name (Name) then
1854 ("argument of pragma% must be entity name", Arg);
1856 elsif not Is_Overloaded (Name) then
1857 Proc := Entity (Name);
1859 if Ekind (Proc) /= E_Procedure
1860 or else Present (First_Formal (Proc)) then
1862 ("argument of pragma% must be parameterless procedure", Arg);
1867 Found : Boolean := False;
1869 Index : Interp_Index;
1872 Get_First_Interp (Name, Index, It);
1873 while Present (It.Nam) loop
1876 if Ekind (Proc) = E_Procedure
1877 and then No (First_Formal (Proc))
1881 Set_Entity (Name, Proc);
1882 Set_Is_Overloaded (Name, False);
1885 ("ambiguous handler name for pragma% ", Arg);
1889 Get_Next_Interp (Index, It);
1894 ("argument of pragma% must be parameterless procedure",
1897 Proc := Entity (Name);
1903 end Find_Unique_Parameterless_Procedure;
1905 -------------------------
1906 -- Gather_Associations --
1907 -------------------------
1909 procedure Gather_Associations
1911 Args : out Args_List)
1916 -- Initialize all parameters to Empty
1918 for J in Args'Range loop
1922 -- That's all we have to do if there are no argument associations
1924 if No (Pragma_Argument_Associations (N)) then
1928 -- Otherwise first deal with any positional parameters present
1930 Arg := First (Pragma_Argument_Associations (N));
1931 for Index in Args'Range loop
1932 exit when No (Arg) or else Chars (Arg) /= No_Name;
1933 Args (Index) := Expression (Arg);
1937 -- Positional parameters all processed, if any left, then we
1938 -- have too many positional parameters.
1940 if Present (Arg) and then Chars (Arg) = No_Name then
1942 ("too many positional associations for pragma%", Arg);
1945 -- Process named parameters if any are present
1947 while Present (Arg) loop
1948 if Chars (Arg) = No_Name then
1950 ("positional association cannot follow named association",
1954 for Index in Names'Range loop
1955 if Names (Index) = Chars (Arg) then
1956 if Present (Args (Index)) then
1958 ("duplicate argument association for pragma%", Arg);
1960 Args (Index) := Expression (Arg);
1965 if Index = Names'Last then
1966 Error_Msg_Name_1 := Pname;
1967 Error_Msg_N ("pragma% does not allow & argument", Arg);
1969 -- Check for possible misspelling
1971 for Index1 in Names'Range loop
1972 if Is_Bad_Spelling_Of
1973 (Chars (Arg), Names (Index1))
1975 Error_Msg_Name_1 := Names (Index1);
1976 Error_Msg_N -- CODEFIX
1977 ("\possible misspelling of%", Arg);
1989 end Gather_Associations;
1995 procedure GNAT_Pragma is
1997 Check_Restriction (No_Implementation_Pragmas, N);
2000 --------------------------
2001 -- Is_Before_First_Decl --
2002 --------------------------
2004 function Is_Before_First_Decl
2005 (Pragma_Node : Node_Id;
2006 Decls : List_Id) return Boolean
2008 Item : Node_Id := First (Decls);
2011 -- Only other pragmas can come before this pragma
2014 if No (Item) or else Nkind (Item) /= N_Pragma then
2017 elsif Item = Pragma_Node then
2023 end Is_Before_First_Decl;
2025 -----------------------------
2026 -- Is_Configuration_Pragma --
2027 -----------------------------
2029 -- A configuration pragma must appear in the context clause of a
2030 -- compilation unit, and only other pragmas may precede it. Note that
2031 -- the test below also permits use in a configuration pragma file.
2033 function Is_Configuration_Pragma return Boolean is
2034 Lis : constant List_Id := List_Containing (N);
2035 Par : constant Node_Id := Parent (N);
2039 -- If no parent, then we are in the configuration pragma file,
2040 -- so the placement is definitely appropriate.
2045 -- Otherwise we must be in the context clause of a compilation unit
2046 -- and the only thing allowed before us in the context list is more
2047 -- configuration pragmas.
2049 elsif Nkind (Par) = N_Compilation_Unit
2050 and then Context_Items (Par) = Lis
2057 elsif Nkind (Prg) /= N_Pragma then
2067 end Is_Configuration_Pragma;
2069 --------------------------
2070 -- Is_In_Context_Clause --
2071 --------------------------
2073 function Is_In_Context_Clause return Boolean is
2075 Parent_Node : Node_Id;
2078 if not Is_List_Member (N) then
2082 Plist := List_Containing (N);
2083 Parent_Node := Parent (Plist);
2085 if Parent_Node = Empty
2086 or else Nkind (Parent_Node) /= N_Compilation_Unit
2087 or else Context_Items (Parent_Node) /= Plist
2094 end Is_In_Context_Clause;
2096 ---------------------------------
2097 -- Is_Static_String_Expression --
2098 ---------------------------------
2100 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2101 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2104 Analyze_And_Resolve (Argx);
2105 return Is_OK_Static_Expression (Argx)
2106 and then Nkind (Argx) = N_String_Literal;
2107 end Is_Static_String_Expression;
2109 ----------------------
2110 -- Pragma_Misplaced --
2111 ----------------------
2113 procedure Pragma_Misplaced is
2115 Error_Pragma ("incorrect placement of pragma%");
2116 end Pragma_Misplaced;
2118 ------------------------------------
2119 -- Process Atomic_Shared_Volatile --
2120 ------------------------------------
2122 procedure Process_Atomic_Shared_Volatile is
2129 procedure Set_Atomic (E : Entity_Id);
2130 -- Set given type as atomic, and if no explicit alignment was given,
2131 -- set alignment to unknown, since back end knows what the alignment
2132 -- requirements are for atomic arrays. Note: this step is necessary
2133 -- for derived types.
2139 procedure Set_Atomic (E : Entity_Id) is
2143 if not Has_Alignment_Clause (E) then
2144 Set_Alignment (E, Uint_0);
2148 -- Start of processing for Process_Atomic_Shared_Volatile
2151 Check_Ada_83_Warning;
2152 Check_No_Identifiers;
2153 Check_Arg_Count (1);
2154 Check_Arg_Is_Local_Name (Arg1);
2155 E_Id := Expression (Arg1);
2157 if Etype (E_Id) = Any_Type then
2162 D := Declaration_Node (E);
2166 if Rep_Item_Too_Early (E, N)
2168 Rep_Item_Too_Late (E, N)
2172 Check_First_Subtype (Arg1);
2175 if Prag_Id /= Pragma_Volatile then
2177 Set_Atomic (Underlying_Type (E));
2178 Set_Atomic (Base_Type (E));
2181 -- Attribute belongs on the base type. If the view of the type is
2182 -- currently private, it also belongs on the underlying type.
2184 Set_Is_Volatile (Base_Type (E));
2185 Set_Is_Volatile (Underlying_Type (E));
2187 Set_Treat_As_Volatile (E);
2188 Set_Treat_As_Volatile (Underlying_Type (E));
2190 elsif K = N_Object_Declaration
2191 or else (K = N_Component_Declaration
2192 and then Original_Record_Component (E) = E)
2194 if Rep_Item_Too_Late (E, N) then
2198 if Prag_Id /= Pragma_Volatile then
2201 -- If the object declaration has an explicit initialization, a
2202 -- temporary may have to be created to hold the expression, to
2203 -- ensure that access to the object remain atomic.
2205 if Nkind (Parent (E)) = N_Object_Declaration
2206 and then Present (Expression (Parent (E)))
2208 Set_Has_Delayed_Freeze (E);
2211 -- An interesting improvement here. If an object of type X is
2212 -- declared atomic, and the type X is not atomic, that's a
2213 -- pity, since it may not have appropriate alignment etc. We
2214 -- can rescue this in the special case where the object and
2215 -- type are in the same unit by just setting the type as
2216 -- atomic, so that the back end will process it as atomic.
2218 Utyp := Underlying_Type (Etype (E));
2221 and then Sloc (E) > No_Location
2222 and then Sloc (Utyp) > No_Location
2224 Get_Source_File_Index (Sloc (E)) =
2225 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2227 Set_Is_Atomic (Underlying_Type (Etype (E)));
2231 Set_Is_Volatile (E);
2232 Set_Treat_As_Volatile (E);
2236 ("inappropriate entity for pragma%", Arg1);
2238 end Process_Atomic_Shared_Volatile;
2240 -------------------------------------------
2241 -- Process_Compile_Time_Warning_Or_Error --
2242 -------------------------------------------
2244 procedure Process_Compile_Time_Warning_Or_Error is
2245 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2248 Check_Arg_Count (2);
2249 Check_No_Identifiers;
2250 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2251 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2253 if Compile_Time_Known_Value (Arg1x) then
2254 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2256 Str : constant String_Id :=
2257 Strval (Get_Pragma_Arg (Arg2));
2258 Len : constant Int := String_Length (Str);
2263 Cent : constant Entity_Id :=
2264 Cunit_Entity (Current_Sem_Unit);
2266 Force : constant Boolean :=
2267 Prag_Id = Pragma_Compile_Time_Warning
2269 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2270 and then (Ekind (Cent) /= E_Package
2271 or else not In_Private_Part (Cent));
2272 -- Set True if this is the warning case, and we are in the
2273 -- visible part of a package spec, or in a subprogram spec,
2274 -- in which case we want to force the client to see the
2275 -- warning, even though it is not in the main unit.
2278 -- Loop through segments of message separated by line feeds.
2279 -- We output these segments as separate messages with
2280 -- continuation marks for all but the first.
2285 Error_Msg_Strlen := 0;
2287 -- Loop to copy characters from argument to error message
2291 exit when Ptr > Len;
2292 CC := Get_String_Char (Str, Ptr);
2295 -- Ignore wide chars ??? else store character
2297 if In_Character_Range (CC) then
2298 C := Get_Character (CC);
2299 exit when C = ASCII.LF;
2300 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2301 Error_Msg_String (Error_Msg_Strlen) := C;
2305 -- Here with one line ready to go
2307 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2309 -- If this is a warning in a spec, then we want clients
2310 -- to see the warning, so mark the message with the
2311 -- special sequence !! to force the warning. In the case
2312 -- of a package spec, we do not force this if we are in
2313 -- the private part of the spec.
2316 if Cont = False then
2317 Error_Msg_N ("<~!!", Arg1);
2320 Error_Msg_N ("\<~!!", Arg1);
2323 -- Error, rather than warning, or in a body, so we do not
2324 -- need to force visibility for client (error will be
2325 -- output in any case, and this is the situation in which
2326 -- we do not want a client to get a warning, since the
2327 -- warning is in the body or the spec private part.
2330 if Cont = False then
2331 Error_Msg_N ("<~", Arg1);
2334 Error_Msg_N ("\<~", Arg1);
2338 exit when Ptr > Len;
2343 end Process_Compile_Time_Warning_Or_Error;
2345 ------------------------
2346 -- Process_Convention --
2347 ------------------------
2349 procedure Process_Convention
2350 (C : out Convention_Id;
2356 Comp_Unit : Unit_Number_Type;
2358 procedure Set_Convention_From_Pragma (E : Entity_Id);
2359 -- Set convention in entity E, and also flag that the entity has a
2360 -- convention pragma. If entity is for a private or incomplete type,
2361 -- also set convention and flag on underlying type. This procedure
2362 -- also deals with the special case of C_Pass_By_Copy convention.
2364 --------------------------------
2365 -- Set_Convention_From_Pragma --
2366 --------------------------------
2368 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2370 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2371 -- for an overridden dispatching operation. Technically this is
2372 -- an amendment and should only be done in Ada 2005 mode. However,
2373 -- this is clearly a mistake, since the problem that is addressed
2374 -- by this AI is that there is a clear gap in the RM!
2376 if Is_Dispatching_Operation (E)
2377 and then Present (Overridden_Operation (E))
2378 and then C /= Convention (Overridden_Operation (E))
2381 ("cannot change convention for " &
2382 "overridden dispatching operation",
2386 -- Set the convention
2388 Set_Convention (E, C);
2389 Set_Has_Convention_Pragma (E);
2391 if Is_Incomplete_Or_Private_Type (E) then
2392 Set_Convention (Underlying_Type (E), C);
2393 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2396 -- A class-wide type should inherit the convention of the specific
2397 -- root type (although this isn't specified clearly by the RM).
2399 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2400 Set_Convention (Class_Wide_Type (E), C);
2403 -- If the entity is a record type, then check for special case of
2404 -- C_Pass_By_Copy, which is treated the same as C except that the
2405 -- special record flag is set. This convention is only permitted
2406 -- on record types (see AI95-00131).
2408 if Cname = Name_C_Pass_By_Copy then
2409 if Is_Record_Type (E) then
2410 Set_C_Pass_By_Copy (Base_Type (E));
2411 elsif Is_Incomplete_Or_Private_Type (E)
2412 and then Is_Record_Type (Underlying_Type (E))
2414 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2417 ("C_Pass_By_Copy convention allowed only for record type",
2422 -- If the entity is a derived boolean type, check for the special
2423 -- case of convention C, C++, or Fortran, where we consider any
2424 -- nonzero value to represent true.
2426 if Is_Discrete_Type (E)
2427 and then Root_Type (Etype (E)) = Standard_Boolean
2433 C = Convention_Fortran)
2435 Set_Nonzero_Is_True (Base_Type (E));
2437 end Set_Convention_From_Pragma;
2439 -- Start of processing for Process_Convention
2442 Check_At_Least_N_Arguments (2);
2443 Check_Optional_Identifier (Arg1, Name_Convention);
2444 Check_Arg_Is_Identifier (Arg1);
2445 Cname := Chars (Expression (Arg1));
2447 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2448 -- tested again below to set the critical flag).
2449 if Cname = Name_C_Pass_By_Copy then
2452 -- Otherwise we must have something in the standard convention list
2454 elsif Is_Convention_Name (Cname) then
2455 C := Get_Convention_Id (Chars (Expression (Arg1)));
2457 -- In DEC VMS, it seems that there is an undocumented feature that
2458 -- any unrecognized convention is treated as the default, which for
2459 -- us is convention C. It does not seem so terrible to do this
2460 -- unconditionally, silently in the VMS case, and with a warning
2461 -- in the non-VMS case.
2464 if Warn_On_Export_Import and not OpenVMS_On_Target then
2466 ("?unrecognized convention name, C assumed",
2473 Check_Optional_Identifier (Arg2, Name_Entity);
2474 Check_Arg_Is_Local_Name (Arg2);
2476 Id := Expression (Arg2);
2479 if not Is_Entity_Name (Id) then
2480 Error_Pragma_Arg ("entity name required", Arg2);
2485 -- Go to renamed subprogram if present, since convention applies to
2486 -- the actual renamed entity, not to the renaming entity. If the
2487 -- subprogram is inherited, go to parent subprogram.
2489 if Is_Subprogram (E)
2490 and then Present (Alias (E))
2492 if Nkind (Parent (Declaration_Node (E))) =
2493 N_Subprogram_Renaming_Declaration
2495 if Scope (E) /= Scope (Alias (E)) then
2497 ("cannot apply pragma% to non-local entity&#", E);
2502 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
2503 N_Private_Extension_Declaration)
2504 and then Scope (E) = Scope (Alias (E))
2510 -- Check that we are not applying this to a specless body
2512 if Is_Subprogram (E)
2513 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
2516 ("pragma% requires separate spec and must come before body");
2519 -- Check that we are not applying this to a named constant
2521 if Ekind (E) = E_Named_Integer
2523 Ekind (E) = E_Named_Real
2525 Error_Msg_Name_1 := Pname;
2527 ("cannot apply pragma% to named constant!",
2528 Get_Pragma_Arg (Arg2));
2530 ("\supply appropriate type for&!", Arg2);
2533 if Ekind (E) = E_Enumeration_Literal then
2534 Error_Pragma ("enumeration literal not allowed for pragma%");
2537 -- Check for rep item appearing too early or too late
2539 if Etype (E) = Any_Type
2540 or else Rep_Item_Too_Early (E, N)
2544 E := Underlying_Type (E);
2547 if Rep_Item_Too_Late (E, N) then
2551 if Has_Convention_Pragma (E) then
2553 ("at most one Convention/Export/Import pragma is allowed", Arg2);
2555 elsif Convention (E) = Convention_Protected
2556 or else Ekind (Scope (E)) = E_Protected_Type
2559 ("a protected operation cannot be given a different convention",
2563 -- For Intrinsic, a subprogram is required
2565 if C = Convention_Intrinsic
2566 and then not Is_Subprogram (E)
2567 and then not Is_Generic_Subprogram (E)
2570 ("second argument of pragma% must be a subprogram", Arg2);
2573 -- For Stdcall, a subprogram, variable or subprogram type is required
2575 if C = Convention_Stdcall
2576 and then not Is_Subprogram (E)
2577 and then not Is_Generic_Subprogram (E)
2578 and then Ekind (E) /= E_Variable
2581 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
2584 ("second argument of pragma% must be subprogram (type)",
2588 if not Is_Subprogram (E)
2589 and then not Is_Generic_Subprogram (E)
2591 Set_Convention_From_Pragma (E);
2595 Check_First_Subtype (Arg2);
2596 Set_Convention_From_Pragma (Base_Type (E));
2598 -- For subprograms, we must set the convention on the
2599 -- internally generated directly designated type as well.
2601 if Ekind (E) = E_Access_Subprogram_Type then
2602 Set_Convention_From_Pragma (Directly_Designated_Type (E));
2606 -- For the subprogram case, set proper convention for all homonyms
2607 -- in same scope and the same declarative part, i.e. the same
2608 -- compilation unit.
2611 Comp_Unit := Get_Source_Unit (E);
2612 Set_Convention_From_Pragma (E);
2614 -- Treat a pragma Import as an implicit body, for GPS use
2616 if Prag_Id = Pragma_Import then
2617 Generate_Reference (E, Id, 'b');
2623 exit when No (E1) or else Scope (E1) /= Current_Scope;
2625 -- Do not set the pragma on inherited operations or on formal
2628 if Comes_From_Source (E1)
2629 and then Comp_Unit = Get_Source_Unit (E1)
2630 and then not Is_Formal_Subprogram (E1)
2631 and then Nkind (Original_Node (Parent (E1))) /=
2632 N_Full_Type_Declaration
2634 if Present (Alias (E1))
2635 and then Scope (E1) /= Scope (Alias (E1))
2638 ("cannot apply pragma% to non-local entity& declared#",
2642 Set_Convention_From_Pragma (E1);
2644 if Prag_Id = Pragma_Import then
2645 Generate_Reference (E, Id, 'b');
2650 end Process_Convention;
2652 -----------------------------------------------------
2653 -- Process_Extended_Import_Export_Exception_Pragma --
2654 -----------------------------------------------------
2656 procedure Process_Extended_Import_Export_Exception_Pragma
2657 (Arg_Internal : Node_Id;
2658 Arg_External : Node_Id;
2666 if not OpenVMS_On_Target then
2668 ("?pragma% ignored (applies only to Open'V'M'S)");
2671 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2672 Def_Id := Entity (Arg_Internal);
2674 if Ekind (Def_Id) /= E_Exception then
2676 ("pragma% must refer to declared exception", Arg_Internal);
2679 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2681 if Present (Arg_Form) then
2682 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
2685 if Present (Arg_Form)
2686 and then Chars (Arg_Form) = Name_Ada
2690 Set_Is_VMS_Exception (Def_Id);
2691 Set_Exception_Code (Def_Id, No_Uint);
2694 if Present (Arg_Code) then
2695 if not Is_VMS_Exception (Def_Id) then
2697 ("Code option for pragma% not allowed for Ada case",
2701 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
2702 Code_Val := Expr_Value (Arg_Code);
2704 if not UI_Is_In_Int_Range (Code_Val) then
2706 ("Code option for pragma% must be in 32-bit range",
2710 Set_Exception_Code (Def_Id, Code_Val);
2713 end Process_Extended_Import_Export_Exception_Pragma;
2715 -------------------------------------------------
2716 -- Process_Extended_Import_Export_Internal_Arg --
2717 -------------------------------------------------
2719 procedure Process_Extended_Import_Export_Internal_Arg
2720 (Arg_Internal : Node_Id := Empty)
2723 if No (Arg_Internal) then
2724 Error_Pragma ("Internal parameter required for pragma%");
2727 if Nkind (Arg_Internal) = N_Identifier then
2730 elsif Nkind (Arg_Internal) = N_Operator_Symbol
2731 and then (Prag_Id = Pragma_Import_Function
2733 Prag_Id = Pragma_Export_Function)
2739 ("wrong form for Internal parameter for pragma%", Arg_Internal);
2742 Check_Arg_Is_Local_Name (Arg_Internal);
2743 end Process_Extended_Import_Export_Internal_Arg;
2745 --------------------------------------------------
2746 -- Process_Extended_Import_Export_Object_Pragma --
2747 --------------------------------------------------
2749 procedure Process_Extended_Import_Export_Object_Pragma
2750 (Arg_Internal : Node_Id;
2751 Arg_External : Node_Id;
2757 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2758 Def_Id := Entity (Arg_Internal);
2760 if Ekind (Def_Id) /= E_Constant
2761 and then Ekind (Def_Id) /= E_Variable
2764 ("pragma% must designate an object", Arg_Internal);
2767 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
2769 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
2772 ("previous Common/Psect_Object applies, pragma % not permitted",
2776 if Rep_Item_Too_Late (Def_Id, N) then
2780 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
2782 if Present (Arg_Size) then
2783 Check_Arg_Is_External_Name (Arg_Size);
2786 -- Export_Object case
2788 if Prag_Id = Pragma_Export_Object then
2789 if not Is_Library_Level_Entity (Def_Id) then
2791 ("argument for pragma% must be library level entity",
2795 if Ekind (Current_Scope) = E_Generic_Package then
2796 Error_Pragma ("pragma& cannot appear in a generic unit");
2799 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
2801 ("exported object must have compile time known size",
2805 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
2806 Error_Msg_N ("?duplicate Export_Object pragma", N);
2808 Set_Exported (Def_Id, Arg_Internal);
2811 -- Import_Object case
2814 if Is_Concurrent_Type (Etype (Def_Id)) then
2816 ("cannot use pragma% for task/protected object",
2820 if Ekind (Def_Id) = E_Constant then
2822 ("cannot import a constant", Arg_Internal);
2825 if Warn_On_Export_Import
2826 and then Has_Discriminants (Etype (Def_Id))
2829 ("imported value must be initialized?", Arg_Internal);
2832 if Warn_On_Export_Import
2833 and then Is_Access_Type (Etype (Def_Id))
2836 ("cannot import object of an access type?", Arg_Internal);
2839 if Warn_On_Export_Import
2840 and then Is_Imported (Def_Id)
2843 ("?duplicate Import_Object pragma", N);
2845 -- Check for explicit initialization present. Note that an
2846 -- initialization generated by the code generator, e.g. for an
2847 -- access type, does not count here.
2849 elsif Present (Expression (Parent (Def_Id)))
2852 (Original_Node (Expression (Parent (Def_Id))))
2854 Error_Msg_Sloc := Sloc (Def_Id);
2856 ("imported entities cannot be initialized (RM B.1(24))",
2857 "\no initialization allowed for & declared#", Arg1);
2859 Set_Imported (Def_Id);
2860 Note_Possible_Modification (Arg_Internal, Sure => False);
2863 end Process_Extended_Import_Export_Object_Pragma;
2865 ------------------------------------------------------
2866 -- Process_Extended_Import_Export_Subprogram_Pragma --
2867 ------------------------------------------------------
2869 procedure Process_Extended_Import_Export_Subprogram_Pragma
2870 (Arg_Internal : Node_Id;
2871 Arg_External : Node_Id;
2872 Arg_Parameter_Types : Node_Id;
2873 Arg_Result_Type : Node_Id := Empty;
2874 Arg_Mechanism : Node_Id;
2875 Arg_Result_Mechanism : Node_Id := Empty;
2876 Arg_First_Optional_Parameter : Node_Id := Empty)
2882 Ambiguous : Boolean;
2886 function Same_Base_Type
2888 Formal : Entity_Id) return Boolean;
2889 -- Determines if Ptype references the type of Formal. Note that only
2890 -- the base types need to match according to the spec. Ptype here is
2891 -- the argument from the pragma, which is either a type name, or an
2892 -- access attribute.
2894 --------------------
2895 -- Same_Base_Type --
2896 --------------------
2898 function Same_Base_Type
2900 Formal : Entity_Id) return Boolean
2902 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
2906 -- Case where pragma argument is typ'Access
2908 if Nkind (Ptype) = N_Attribute_Reference
2909 and then Attribute_Name (Ptype) = Name_Access
2911 Pref := Prefix (Ptype);
2914 if not Is_Entity_Name (Pref)
2915 or else Entity (Pref) = Any_Type
2920 -- We have a match if the corresponding argument is of an
2921 -- anonymous access type, and its designated type matches the
2922 -- type of the prefix of the access attribute
2924 return Ekind (Ftyp) = E_Anonymous_Access_Type
2925 and then Base_Type (Entity (Pref)) =
2926 Base_Type (Etype (Designated_Type (Ftyp)));
2928 -- Case where pragma argument is a type name
2933 if not Is_Entity_Name (Ptype)
2934 or else Entity (Ptype) = Any_Type
2939 -- We have a match if the corresponding argument is of the type
2940 -- given in the pragma (comparing base types)
2942 return Base_Type (Entity (Ptype)) = Ftyp;
2946 -- Start of processing for
2947 -- Process_Extended_Import_Export_Subprogram_Pragma
2950 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
2954 -- Loop through homonyms (overloadings) of the entity
2956 Hom_Id := Entity (Arg_Internal);
2957 while Present (Hom_Id) loop
2958 Def_Id := Get_Base_Subprogram (Hom_Id);
2960 -- We need a subprogram in the current scope
2962 if not Is_Subprogram (Def_Id)
2963 or else Scope (Def_Id) /= Current_Scope
2970 -- Pragma cannot apply to subprogram body
2972 if Is_Subprogram (Def_Id)
2973 and then Nkind (Parent (Declaration_Node (Def_Id))) =
2977 ("pragma% requires separate spec"
2978 & " and must come before body");
2981 -- Test result type if given, note that the result type
2982 -- parameter can only be present for the function cases.
2984 if Present (Arg_Result_Type)
2985 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
2989 elsif Etype (Def_Id) /= Standard_Void_Type
2991 (Pname = Name_Export_Procedure
2993 Pname = Name_Import_Procedure)
2997 -- Test parameter types if given. Note that this parameter
2998 -- has not been analyzed (and must not be, since it is
2999 -- semantic nonsense), so we get it as the parser left it.
3001 elsif Present (Arg_Parameter_Types) then
3002 Check_Matching_Types : declare
3007 Formal := First_Formal (Def_Id);
3009 if Nkind (Arg_Parameter_Types) = N_Null then
3010 if Present (Formal) then
3014 -- A list of one type, e.g. (List) is parsed as
3015 -- a parenthesized expression.
3017 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3018 and then Paren_Count (Arg_Parameter_Types) = 1
3021 or else Present (Next_Formal (Formal))
3026 Same_Base_Type (Arg_Parameter_Types, Formal);
3029 -- A list of more than one type is parsed as a aggregate
3031 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3032 and then Paren_Count (Arg_Parameter_Types) = 0
3034 Ptype := First (Expressions (Arg_Parameter_Types));
3035 while Present (Ptype) or else Present (Formal) loop
3038 or else not Same_Base_Type (Ptype, Formal)
3043 Next_Formal (Formal);
3048 -- Anything else is of the wrong form
3052 ("wrong form for Parameter_Types parameter",
3053 Arg_Parameter_Types);
3055 end Check_Matching_Types;
3058 -- Match is now False if the entry we found did not match
3059 -- either a supplied Parameter_Types or Result_Types argument
3065 -- Ambiguous case, the flag Ambiguous shows if we already
3066 -- detected this and output the initial messages.
3069 if not Ambiguous then
3071 Error_Msg_Name_1 := Pname;
3073 ("pragma% does not uniquely identify subprogram!",
3075 Error_Msg_Sloc := Sloc (Ent);
3076 Error_Msg_N ("matching subprogram #!", N);
3080 Error_Msg_Sloc := Sloc (Def_Id);
3081 Error_Msg_N ("matching subprogram #!", N);
3086 Hom_Id := Homonym (Hom_Id);
3089 -- See if we found an entry
3092 if not Ambiguous then
3093 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3095 ("pragma% cannot be given for generic subprogram");
3098 ("pragma% does not identify local subprogram");
3105 -- Import pragmas must be for imported entities
3107 if Prag_Id = Pragma_Import_Function
3109 Prag_Id = Pragma_Import_Procedure
3111 Prag_Id = Pragma_Import_Valued_Procedure
3113 if not Is_Imported (Ent) then
3114 Error_Pragma -- CODEFIX???
3115 ("pragma Import or Interface must precede pragma%");
3118 -- Here we have the Export case which can set the entity as exported
3120 -- But does not do so if the specified external name is null, since
3121 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3122 -- compatible) to request no external name.
3124 elsif Nkind (Arg_External) = N_String_Literal
3125 and then String_Length (Strval (Arg_External)) = 0
3129 -- In all other cases, set entity as exported
3132 Set_Exported (Ent, Arg_Internal);
3135 -- Special processing for Valued_Procedure cases
3137 if Prag_Id = Pragma_Import_Valued_Procedure
3139 Prag_Id = Pragma_Export_Valued_Procedure
3141 Formal := First_Formal (Ent);
3144 Error_Pragma ("at least one parameter required for pragma%");
3146 elsif Ekind (Formal) /= E_Out_Parameter then
3147 Error_Pragma ("first parameter must have mode out for pragma%");
3150 Set_Is_Valued_Procedure (Ent);
3154 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3156 -- Process Result_Mechanism argument if present. We have already
3157 -- checked that this is only allowed for the function case.
3159 if Present (Arg_Result_Mechanism) then
3160 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3163 -- Process Mechanism parameter if present. Note that this parameter
3164 -- is not analyzed, and must not be analyzed since it is semantic
3165 -- nonsense, so we get it in exactly as the parser left it.
3167 if Present (Arg_Mechanism) then
3175 -- A single mechanism association without a formal parameter
3176 -- name is parsed as a parenthesized expression. All other
3177 -- cases are parsed as aggregates, so we rewrite the single
3178 -- parameter case as an aggregate for consistency.
3180 if Nkind (Arg_Mechanism) /= N_Aggregate
3181 and then Paren_Count (Arg_Mechanism) = 1
3183 Rewrite (Arg_Mechanism,
3184 Make_Aggregate (Sloc (Arg_Mechanism),
3185 Expressions => New_List (
3186 Relocate_Node (Arg_Mechanism))));
3189 -- Case of only mechanism name given, applies to all formals
3191 if Nkind (Arg_Mechanism) /= N_Aggregate then
3192 Formal := First_Formal (Ent);
3193 while Present (Formal) loop
3194 Set_Mechanism_Value (Formal, Arg_Mechanism);
3195 Next_Formal (Formal);
3198 -- Case of list of mechanism associations given
3201 if Null_Record_Present (Arg_Mechanism) then
3203 ("inappropriate form for Mechanism parameter",
3207 -- Deal with positional ones first
3209 Formal := First_Formal (Ent);
3211 if Present (Expressions (Arg_Mechanism)) then
3212 Mname := First (Expressions (Arg_Mechanism));
3213 while Present (Mname) loop
3216 ("too many mechanism associations", Mname);
3219 Set_Mechanism_Value (Formal, Mname);
3220 Next_Formal (Formal);
3225 -- Deal with named entries
3227 if Present (Component_Associations (Arg_Mechanism)) then
3228 Massoc := First (Component_Associations (Arg_Mechanism));
3229 while Present (Massoc) loop
3230 Choice := First (Choices (Massoc));
3232 if Nkind (Choice) /= N_Identifier
3233 or else Present (Next (Choice))
3236 ("incorrect form for mechanism association",
3240 Formal := First_Formal (Ent);
3244 ("parameter name & not present", Choice);
3247 if Chars (Choice) = Chars (Formal) then
3249 (Formal, Expression (Massoc));
3251 -- Set entity on identifier for ASIS
3253 Set_Entity (Choice, Formal);
3258 Next_Formal (Formal);
3268 -- Process First_Optional_Parameter argument if present. We have
3269 -- already checked that this is only allowed for the Import case.
3271 if Present (Arg_First_Optional_Parameter) then
3272 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3274 ("first optional parameter must be formal parameter name",
3275 Arg_First_Optional_Parameter);
3278 Formal := First_Formal (Ent);
3282 ("specified formal parameter& not found",
3283 Arg_First_Optional_Parameter);
3286 exit when Chars (Formal) =
3287 Chars (Arg_First_Optional_Parameter);
3289 Next_Formal (Formal);
3292 Set_First_Optional_Parameter (Ent, Formal);
3294 -- Check specified and all remaining formals have right form
3296 while Present (Formal) loop
3297 if Ekind (Formal) /= E_In_Parameter then
3299 ("optional formal& is not of mode in!",
3300 Arg_First_Optional_Parameter, Formal);
3303 Dval := Default_Value (Formal);
3307 ("optional formal& does not have default value!",
3308 Arg_First_Optional_Parameter, Formal);
3310 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3315 ("default value for optional formal& is non-static!",
3316 Arg_First_Optional_Parameter, Formal);
3320 Set_Is_Optional_Parameter (Formal);
3321 Next_Formal (Formal);
3324 end Process_Extended_Import_Export_Subprogram_Pragma;
3326 --------------------------
3327 -- Process_Generic_List --
3328 --------------------------
3330 procedure Process_Generic_List is
3335 Check_No_Identifiers;
3336 Check_At_Least_N_Arguments (1);
3339 while Present (Arg) loop
3340 Exp := Expression (Arg);
3343 if not Is_Entity_Name (Exp)
3345 (not Is_Generic_Instance (Entity (Exp))
3347 not Is_Generic_Unit (Entity (Exp)))
3350 ("pragma% argument must be name of generic unit/instance",
3356 end Process_Generic_List;
3358 ---------------------------------
3359 -- Process_Import_Or_Interface --
3360 ---------------------------------
3362 procedure Process_Import_Or_Interface is
3368 Process_Convention (C, Def_Id);
3369 Kill_Size_Check_Code (Def_Id);
3370 Note_Possible_Modification (Expression (Arg2), Sure => False);
3372 if Ekind (Def_Id) = E_Variable
3374 Ekind (Def_Id) = E_Constant
3376 -- We do not permit Import to apply to a renaming declaration
3378 if Present (Renamed_Object (Def_Id)) then
3380 ("pragma% not allowed for object renaming", Arg2);
3382 -- User initialization is not allowed for imported object, but
3383 -- the object declaration may contain a default initialization,
3384 -- that will be discarded. Note that an explicit initialization
3385 -- only counts if it comes from source, otherwise it is simply
3386 -- the code generator making an implicit initialization explicit.
3388 elsif Present (Expression (Parent (Def_Id)))
3389 and then Comes_From_Source (Expression (Parent (Def_Id)))
3391 Error_Msg_Sloc := Sloc (Def_Id);
3393 ("no initialization allowed for declaration of& #",
3394 "\imported entities cannot be initialized (RM B.1(24))",
3398 Set_Imported (Def_Id);
3399 Process_Interface_Name (Def_Id, Arg3, Arg4);
3401 -- Note that we do not set Is_Public here. That's because we
3402 -- only want to set it if there is no address clause, and we
3403 -- don't know that yet, so we delay that processing till
3406 -- pragma Import completes deferred constants
3408 if Ekind (Def_Id) = E_Constant then
3409 Set_Has_Completion (Def_Id);
3412 -- It is not possible to import a constant of an unconstrained
3413 -- array type (e.g. string) because there is no simple way to
3414 -- write a meaningful subtype for it.
3416 if Is_Array_Type (Etype (Def_Id))
3417 and then not Is_Constrained (Etype (Def_Id))
3420 ("imported constant& must have a constrained subtype",
3425 elsif Is_Subprogram (Def_Id)
3426 or else Is_Generic_Subprogram (Def_Id)
3428 -- If the name is overloaded, pragma applies to all of the
3429 -- denoted entities in the same declarative part.
3432 while Present (Hom_Id) loop
3433 Def_Id := Get_Base_Subprogram (Hom_Id);
3435 -- Ignore inherited subprograms because the pragma will
3436 -- apply to the parent operation, which is the one called.
3438 if Is_Overloadable (Def_Id)
3439 and then Present (Alias (Def_Id))
3443 -- If it is not a subprogram, it must be in an outer scope and
3444 -- pragma does not apply.
3446 elsif not Is_Subprogram (Def_Id)
3447 and then not Is_Generic_Subprogram (Def_Id)
3451 -- Verify that the homonym is in the same declarative part (not
3452 -- just the same scope).
3454 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
3455 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
3460 Set_Imported (Def_Id);
3462 if Is_Subprogram (Def_Id)
3463 and then Is_Abstract_Subprogram (Def_Id)
3465 Error_Msg_Sloc := Sloc (Def_Id);
3467 ("cannot import abstract subprogram& declared#",
3471 -- Special processing for Convention_Intrinsic
3473 if C = Convention_Intrinsic then
3475 -- Link_Name argument not allowed for intrinsic
3478 and then Chars (Arg3) = Name_Link_Name
3483 if Present (Arg4) then
3485 ("Link_Name argument not allowed for " &
3490 Set_Is_Intrinsic_Subprogram (Def_Id);
3492 -- If no external name is present, then check that this
3493 -- is a valid intrinsic subprogram. If an external name
3494 -- is present, then this is handled by the back end.
3497 Check_Intrinsic_Subprogram (Def_Id, Expression (Arg2));
3501 -- All interfaced procedures need an external symbol created
3502 -- for them since they are always referenced from another
3505 Set_Is_Public (Def_Id);
3507 -- Verify that the subprogram does not have a completion
3508 -- through a renaming declaration. For other completions the
3509 -- pragma appears as a too late representation.
3512 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
3516 and then Nkind (Decl) = N_Subprogram_Declaration
3517 and then Present (Corresponding_Body (Decl))
3518 and then Nkind (Unit_Declaration_Node
3519 (Corresponding_Body (Decl))) =
3520 N_Subprogram_Renaming_Declaration
3522 Error_Msg_Sloc := Sloc (Def_Id);
3524 ("cannot import&, renaming already provided for " &
3525 "declaration #", N, Def_Id);
3529 Set_Has_Completion (Def_Id);
3530 Process_Interface_Name (Def_Id, Arg3, Arg4);
3533 if Is_Compilation_Unit (Hom_Id) then
3535 -- Its possible homonyms are not affected by the pragma.
3536 -- Such homonyms might be present in the context of other
3537 -- units being compiled.
3542 Hom_Id := Homonym (Hom_Id);
3546 -- When the convention is Java or CIL, we also allow Import to be
3547 -- given for packages, generic packages, exceptions, record
3548 -- components, and access to subprograms.
3550 elsif (C = Convention_Java or else C = Convention_CIL)
3552 (Is_Package_Or_Generic_Package (Def_Id)
3553 or else Ekind (Def_Id) = E_Exception
3554 or else Ekind (Def_Id) = E_Access_Subprogram_Type
3555 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
3557 Set_Imported (Def_Id);
3558 Set_Is_Public (Def_Id);
3559 Process_Interface_Name (Def_Id, Arg3, Arg4);
3561 -- Import a CPP class
3563 elsif Is_Record_Type (Def_Id)
3564 and then C = Convention_CPP
3566 -- Types treated as CPP classes are treated as limited, but we
3567 -- don't require them to be declared this way. A warning is
3568 -- issued to encourage the user to declare them as limited.
3569 -- This is not an error, for compatibility reasons, because
3570 -- these types have been supported this way for some time.
3572 if not Is_Limited_Type (Def_Id) then
3574 ("imported 'C'P'P type should be " &
3575 "explicitly declared limited?",
3576 Get_Pragma_Arg (Arg2));
3578 ("\type will be considered limited",
3579 Get_Pragma_Arg (Arg2));
3582 Set_Is_CPP_Class (Def_Id);
3583 Set_Is_Limited_Record (Def_Id);
3585 -- Imported CPP types must not have discriminants (because C++
3586 -- classes do not have discriminants).
3588 if Has_Discriminants (Def_Id) then
3590 ("imported 'C'P'P type cannot have discriminants",
3591 First (Discriminant_Specifications
3592 (Declaration_Node (Def_Id))));
3595 -- Components of imported CPP types must not have default
3596 -- expressions because the constructor (if any) is on the
3600 Tdef : constant Node_Id :=
3601 Type_Definition (Declaration_Node (Def_Id));
3606 if Nkind (Tdef) = N_Record_Definition then
3607 Clist := Component_List (Tdef);
3610 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
3611 Clist := Component_List (Record_Extension_Part (Tdef));
3614 if Present (Clist) then
3615 Comp := First (Component_Items (Clist));
3616 while Present (Comp) loop
3617 if Present (Expression (Comp)) then
3619 ("component of imported 'C'P'P type cannot have" &
3620 " default expression", Expression (Comp));
3630 ("second argument of pragma% must be object or subprogram",
3634 -- If this pragma applies to a compilation unit, then the unit, which
3635 -- is a subprogram, does not require (or allow) a body. We also do
3636 -- not need to elaborate imported procedures.
3638 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3640 Cunit : constant Node_Id := Parent (Parent (N));
3642 Set_Body_Required (Cunit, False);
3645 end Process_Import_Or_Interface;
3647 --------------------
3648 -- Process_Inline --
3649 --------------------
3651 procedure Process_Inline (Active : Boolean) is
3657 Effective : Boolean := False;
3659 procedure Make_Inline (Subp : Entity_Id);
3660 -- Subp is the defining unit name of the subprogram declaration. Set
3661 -- the flag, as well as the flag in the corresponding body, if there
3664 procedure Set_Inline_Flags (Subp : Entity_Id);
3665 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
3666 -- Has_Pragma_Inline_Always for the Inline_Always case.
3668 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
3669 -- Returns True if it can be determined at this stage that inlining
3670 -- is not possible, for example if the body is available and contains
3671 -- exception handlers, we prevent inlining, since otherwise we can
3672 -- get undefined symbols at link time. This function also emits a
3673 -- warning if front-end inlining is enabled and the pragma appears
3676 -- ??? is business with link symbols still valid, or does it relate
3677 -- to front end ZCX which is being phased out ???
3679 ---------------------------
3680 -- Inlining_Not_Possible --
3681 ---------------------------
3683 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
3684 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3688 if Nkind (Decl) = N_Subprogram_Body then
3689 Stats := Handled_Statement_Sequence (Decl);
3690 return Present (Exception_Handlers (Stats))
3691 or else Present (At_End_Proc (Stats));
3693 elsif Nkind (Decl) = N_Subprogram_Declaration
3694 and then Present (Corresponding_Body (Decl))
3696 if Front_End_Inlining
3697 and then Analyzed (Corresponding_Body (Decl))
3699 Error_Msg_N ("pragma appears too late, ignored?", N);
3702 -- If the subprogram is a renaming as body, the body is just a
3703 -- call to the renamed subprogram, and inlining is trivially
3707 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
3708 N_Subprogram_Renaming_Declaration
3714 Handled_Statement_Sequence
3715 (Unit_Declaration_Node (Corresponding_Body (Decl)));
3718 Present (Exception_Handlers (Stats))
3719 or else Present (At_End_Proc (Stats));
3723 -- If body is not available, assume the best, the check is
3724 -- performed again when compiling enclosing package bodies.
3728 end Inlining_Not_Possible;
3734 procedure Make_Inline (Subp : Entity_Id) is
3735 Kind : constant Entity_Kind := Ekind (Subp);
3736 Inner_Subp : Entity_Id := Subp;
3739 -- Ignore if bad type, avoid cascaded error
3741 if Etype (Subp) = Any_Type then
3745 -- Ignore if all inlining is suppressed
3747 elsif Suppress_All_Inlining then
3751 -- If inlining is not possible, for now do not treat as an error
3753 elsif Inlining_Not_Possible (Subp) then
3757 -- Here we have a candidate for inlining, but we must exclude
3758 -- derived operations. Otherwise we would end up trying to inline
3759 -- a phantom declaration, and the result would be to drag in a
3760 -- body which has no direct inlining associated with it. That
3761 -- would not only be inefficient but would also result in the
3762 -- backend doing cross-unit inlining in cases where it was
3763 -- definitely inappropriate to do so.
3765 -- However, a simple Comes_From_Source test is insufficient, since
3766 -- we do want to allow inlining of generic instances which also do
3767 -- not come from source. We also need to recognize specs generated
3768 -- by the front-end for bodies that carry the pragma. Finally,
3769 -- predefined operators do not come from source but are not
3770 -- inlineable either.
3772 elsif Is_Generic_Instance (Subp)
3773 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
3777 elsif not Comes_From_Source (Subp)
3778 and then Scope (Subp) /= Standard_Standard
3784 -- The referenced entity must either be the enclosing entity, or
3785 -- an entity declared within the current open scope.
3787 if Present (Scope (Subp))
3788 and then Scope (Subp) /= Current_Scope
3789 and then Subp /= Current_Scope
3792 ("argument of% must be entity in current scope", Assoc);
3796 -- Processing for procedure, operator or function. If subprogram
3797 -- is aliased (as for an instance) indicate that the renamed
3798 -- entity (if declared in the same unit) is inlined.
3800 if Is_Subprogram (Subp) then
3801 while Present (Alias (Inner_Subp)) loop
3802 Inner_Subp := Alias (Inner_Subp);
3805 if In_Same_Source_Unit (Subp, Inner_Subp) then
3806 Set_Inline_Flags (Inner_Subp);
3808 Decl := Parent (Parent (Inner_Subp));
3810 if Nkind (Decl) = N_Subprogram_Declaration
3811 and then Present (Corresponding_Body (Decl))
3813 Set_Inline_Flags (Corresponding_Body (Decl));
3815 elsif Is_Generic_Instance (Subp) then
3817 -- Indicate that the body needs to be created for
3818 -- inlining subsequent calls. The instantiation node
3819 -- follows the declaration of the wrapper package
3822 if Scope (Subp) /= Standard_Standard
3824 Need_Subprogram_Instance_Body
3825 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
3835 -- For a generic subprogram set flag as well, for use at the point
3836 -- of instantiation, to determine whether the body should be
3839 elsif Is_Generic_Subprogram (Subp) then
3840 Set_Inline_Flags (Subp);
3843 -- Literals are by definition inlined
3845 elsif Kind = E_Enumeration_Literal then
3848 -- Anything else is an error
3852 ("expect subprogram name for pragma%", Assoc);
3856 ----------------------
3857 -- Set_Inline_Flags --
3858 ----------------------
3860 procedure Set_Inline_Flags (Subp : Entity_Id) is
3863 Set_Is_Inlined (Subp, True);
3866 if not Has_Pragma_Inline (Subp) then
3867 Set_Has_Pragma_Inline (Subp);
3871 if Prag_Id = Pragma_Inline_Always then
3872 Set_Has_Pragma_Inline_Always (Subp);
3874 end Set_Inline_Flags;
3876 -- Start of processing for Process_Inline
3879 Check_No_Identifiers;
3880 Check_At_Least_N_Arguments (1);
3883 Inline_Processing_Required := True;
3887 while Present (Assoc) loop
3888 Subp_Id := Expression (Assoc);
3892 if Is_Entity_Name (Subp_Id) then
3893 Subp := Entity (Subp_Id);
3895 if Subp = Any_Id then
3897 -- If previous error, avoid cascaded errors
3905 while Present (Homonym (Subp))
3906 and then Scope (Homonym (Subp)) = Current_Scope
3908 Make_Inline (Homonym (Subp));
3909 Subp := Homonym (Subp);
3916 ("inappropriate argument for pragma%", Assoc);
3919 and then Warn_On_Redundant_Constructs
3920 and then not Suppress_All_Inlining
3922 if Inlining_Not_Possible (Subp) then
3924 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
3927 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
3935 ----------------------------
3936 -- Process_Interface_Name --
3937 ----------------------------
3939 procedure Process_Interface_Name
3940 (Subprogram_Def : Entity_Id;
3946 String_Val : String_Id;
3948 procedure Check_Form_Of_Interface_Name
3950 Ext_Name_Case : Boolean);
3951 -- SN is a string literal node for an interface name. This routine
3952 -- performs some minimal checks that the name is reasonable. In
3953 -- particular that no spaces or other obviously incorrect characters
3954 -- appear. This is only a warning, since any characters are allowed.
3955 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
3957 ----------------------------------
3958 -- Check_Form_Of_Interface_Name --
3959 ----------------------------------
3961 procedure Check_Form_Of_Interface_Name
3963 Ext_Name_Case : Boolean)
3965 S : constant String_Id := Strval (Expr_Value_S (SN));
3966 SL : constant Nat := String_Length (S);
3971 Error_Msg_N ("interface name cannot be null string", SN);
3974 for J in 1 .. SL loop
3975 C := Get_String_Char (S, J);
3977 -- Look for dubious character and issue unconditional warning.
3978 -- Definitely dubious if not in character range.
3980 if not In_Character_Range (C)
3982 -- For all cases except CLI target,
3983 -- commas, spaces and slashes are dubious (in CLI, we use
3984 -- commas and backslashes in external names to specify
3985 -- assembly version and public key, while slashes and spaces
3986 -- can be used in names to mark nested classes and
3989 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
3990 and then (Get_Character (C) = ','
3992 Get_Character (C) = '\'))
3993 or else (VM_Target /= CLI_Target
3994 and then (Get_Character (C) = ' '
3996 Get_Character (C) = '/'))
3999 ("?interface name contains illegal character",
4000 Sloc (SN) + Source_Ptr (J));
4003 end Check_Form_Of_Interface_Name;
4005 -- Start of processing for Process_Interface_Name
4008 if No (Link_Arg) then
4009 if No (Ext_Arg) then
4010 if VM_Target = CLI_Target
4011 and then Ekind (Subprogram_Def) = E_Package
4012 and then Nkind (Parent (Subprogram_Def)) =
4013 N_Package_Specification
4014 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4019 (Generic_Parent (Parent (Subprogram_Def))));
4024 elsif Chars (Ext_Arg) = Name_Link_Name then
4026 Link_Nam := Expression (Ext_Arg);
4029 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4030 Ext_Nam := Expression (Ext_Arg);
4035 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4036 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4037 Ext_Nam := Expression (Ext_Arg);
4038 Link_Nam := Expression (Link_Arg);
4041 -- Check expressions for external name and link name are static
4043 if Present (Ext_Nam) then
4044 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4045 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4047 -- Verify that external name is not the name of a local entity,
4048 -- which would hide the imported one and could lead to run-time
4049 -- surprises. The problem can only arise for entities declared in
4050 -- a package body (otherwise the external name is fully qualified
4051 -- and will not conflict).
4059 if Prag_Id = Pragma_Import then
4060 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4062 E := Entity_Id (Get_Name_Table_Info (Nam));
4064 if Nam /= Chars (Subprogram_Def)
4065 and then Present (E)
4066 and then not Is_Overloadable (E)
4067 and then Is_Immediately_Visible (E)
4068 and then not Is_Imported (E)
4069 and then Ekind (Scope (E)) = E_Package
4072 while Present (Par) loop
4073 if Nkind (Par) = N_Package_Body then
4074 Error_Msg_Sloc := Sloc (E);
4076 ("imported entity is hidden by & declared#",
4081 Par := Parent (Par);
4088 if Present (Link_Nam) then
4089 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4090 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4093 -- If there is no link name, just set the external name
4095 if No (Link_Nam) then
4096 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4098 -- For the Link_Name case, the given literal is preceded by an
4099 -- asterisk, which indicates to GCC that the given name should be
4100 -- taken literally, and in particular that no prepending of
4101 -- underlines should occur, even in systems where this is the
4107 if VM_Target = No_VM then
4108 Store_String_Char (Get_Char_Code ('*'));
4111 String_Val := Strval (Expr_Value_S (Link_Nam));
4112 Store_String_Chars (String_Val);
4114 Make_String_Literal (Sloc (Link_Nam),
4115 Strval => End_String);
4118 Set_Encoded_Interface_Name
4119 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4120 Check_Duplicated_Export_Name (Link_Nam);
4121 end Process_Interface_Name;
4123 -----------------------------------------
4124 -- Process_Interrupt_Or_Attach_Handler --
4125 -----------------------------------------
4127 procedure Process_Interrupt_Or_Attach_Handler is
4128 Arg1_X : constant Node_Id := Expression (Arg1);
4129 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4130 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4133 Set_Is_Interrupt_Handler (Handler_Proc);
4135 -- If the pragma is not associated with a handler procedure within a
4136 -- protected type, then it must be for a nonprotected procedure for
4137 -- the AAMP target, in which case we don't associate a representation
4138 -- item with the procedure's scope.
4140 if Ekind (Proc_Scope) = E_Protected_Type then
4141 if Prag_Id = Pragma_Interrupt_Handler
4143 Prag_Id = Pragma_Attach_Handler
4145 Record_Rep_Item (Proc_Scope, N);
4148 end Process_Interrupt_Or_Attach_Handler;
4150 --------------------------------------------------
4151 -- Process_Restrictions_Or_Restriction_Warnings --
4152 --------------------------------------------------
4154 -- Note: some of the simple identifier cases were handled in par-prag,
4155 -- but it is harmless (and more straightforward) to simply handle all
4156 -- cases here, even if it means we repeat a bit of work in some cases.
4158 procedure Process_Restrictions_Or_Restriction_Warnings
4162 R_Id : Restriction_Id;
4167 procedure Check_Unit_Name (N : Node_Id);
4168 -- Checks unit name parameter for No_Dependence. Returns if it has
4169 -- an appropriate form, otherwise raises pragma argument error.
4171 ---------------------
4172 -- Check_Unit_Name --
4173 ---------------------
4175 procedure Check_Unit_Name (N : Node_Id) is
4177 if Nkind (N) = N_Selected_Component then
4178 Check_Unit_Name (Prefix (N));
4179 Check_Unit_Name (Selector_Name (N));
4181 elsif Nkind (N) = N_Identifier then
4186 ("wrong form for unit name for No_Dependence", N);
4188 end Check_Unit_Name;
4190 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4193 Check_Ada_83_Warning;
4194 Check_At_Least_N_Arguments (1);
4195 Check_Valid_Configuration_Pragma;
4198 while Present (Arg) loop
4200 Expr := Expression (Arg);
4202 -- Case of no restriction identifier present
4204 if Id = No_Name then
4205 if Nkind (Expr) /= N_Identifier then
4207 ("invalid form for restriction", Arg);
4212 (Process_Restriction_Synonyms (Expr));
4214 if R_Id not in All_Boolean_Restrictions then
4215 Error_Msg_Name_1 := Pname;
4217 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4219 -- Check for possible misspelling
4221 for J in Restriction_Id loop
4223 Rnm : constant String := Restriction_Id'Image (J);
4226 Name_Buffer (1 .. Rnm'Length) := Rnm;
4227 Name_Len := Rnm'Length;
4228 Set_Casing (All_Lower_Case);
4230 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4232 (Identifier_Casing (Current_Source_File));
4233 Error_Msg_String (1 .. Rnm'Length) :=
4234 Name_Buffer (1 .. Name_Len);
4235 Error_Msg_Strlen := Rnm'Length;
4236 Error_Msg_N -- CODEFIX
4237 ("\possible misspelling of ""~""",
4238 Get_Pragma_Arg (Arg));
4247 if Implementation_Restriction (R_Id) then
4248 Check_Restriction (No_Implementation_Restrictions, Arg);
4251 -- If this is a warning, then set the warning unless we already
4252 -- have a real restriction active (we never want a warning to
4253 -- override a real restriction).
4256 if not Restriction_Active (R_Id) then
4257 Set_Restriction (R_Id, N);
4258 Restriction_Warnings (R_Id) := True;
4261 -- If real restriction case, then set it and make sure that the
4262 -- restriction warning flag is off, since a real restriction
4263 -- always overrides a warning.
4266 Set_Restriction (R_Id, N);
4267 Restriction_Warnings (R_Id) := False;
4270 -- A very special case that must be processed here: pragma
4271 -- Restrictions (No_Exceptions) turns off all run-time
4272 -- checking. This is a bit dubious in terms of the formal
4273 -- language definition, but it is what is intended by RM
4274 -- H.4(12). Restriction_Warnings never affects generated code
4275 -- so this is done only in the real restriction case.
4277 if R_Id = No_Exceptions and then not Warn then
4278 Scope_Suppress := (others => True);
4281 -- Case of No_Dependence => unit-name. Note that the parser
4282 -- already made the necessary entry in the No_Dependence table.
4284 elsif Id = Name_No_Dependence then
4285 Check_Unit_Name (Expr);
4287 -- All other cases of restriction identifier present
4290 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4291 Analyze_And_Resolve (Expr, Any_Integer);
4293 if R_Id not in All_Parameter_Restrictions then
4295 ("invalid restriction parameter identifier", Arg);
4297 elsif not Is_OK_Static_Expression (Expr) then
4298 Flag_Non_Static_Expr
4299 ("value must be static expression!", Expr);
4302 elsif not Is_Integer_Type (Etype (Expr))
4303 or else Expr_Value (Expr) < 0
4306 ("value must be non-negative integer", Arg);
4309 -- Restriction pragma is active
4311 Val := Expr_Value (Expr);
4313 if not UI_Is_In_Int_Range (Val) then
4315 ("pragma ignored, value too large?", Arg);
4318 -- Warning case. If the real restriction is active, then we
4319 -- ignore the request, since warning never overrides a real
4320 -- restriction. Otherwise we set the proper warning. Note that
4321 -- this circuit sets the warning again if it is already set,
4322 -- which is what we want, since the constant may have changed.
4325 if not Restriction_Active (R_Id) then
4327 (R_Id, N, Integer (UI_To_Int (Val)));
4328 Restriction_Warnings (R_Id) := True;
4331 -- Real restriction case, set restriction and make sure warning
4332 -- flag is off since real restriction always overrides warning.
4335 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4336 Restriction_Warnings (R_Id) := False;
4342 end Process_Restrictions_Or_Restriction_Warnings;
4344 ---------------------------------
4345 -- Process_Suppress_Unsuppress --
4346 ---------------------------------
4348 -- Note: this procedure makes entries in the check suppress data
4349 -- structures managed by Sem. See spec of package Sem for full
4350 -- details on how we handle recording of check suppression.
4352 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4357 In_Package_Spec : constant Boolean :=
4358 Is_Package_Or_Generic_Package (Current_Scope)
4359 and then not In_Package_Body (Current_Scope);
4361 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4362 -- Used to suppress a single check on the given entity
4364 --------------------------------
4365 -- Suppress_Unsuppress_Echeck --
4366 --------------------------------
4368 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4370 Set_Checks_May_Be_Suppressed (E);
4372 if In_Package_Spec then
4373 Push_Global_Suppress_Stack_Entry
4376 Suppress => Suppress_Case);
4379 Push_Local_Suppress_Stack_Entry
4382 Suppress => Suppress_Case);
4385 -- If this is a first subtype, and the base type is distinct,
4386 -- then also set the suppress flags on the base type.
4388 if Is_First_Subtype (E)
4389 and then Etype (E) /= E
4391 Suppress_Unsuppress_Echeck (Etype (E), C);
4393 end Suppress_Unsuppress_Echeck;
4395 -- Start of processing for Process_Suppress_Unsuppress
4398 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
4399 -- declarative part or a package spec (RM 11.5(5)).
4401 if not Is_Configuration_Pragma then
4402 Check_Is_In_Decl_Part_Or_Package_Spec;
4405 Check_At_Least_N_Arguments (1);
4406 Check_At_Most_N_Arguments (2);
4407 Check_No_Identifier (Arg1);
4408 Check_Arg_Is_Identifier (Arg1);
4410 C := Get_Check_Id (Chars (Expression (Arg1)));
4412 if C = No_Check_Id then
4414 ("argument of pragma% is not valid check name", Arg1);
4417 if not Suppress_Case
4418 and then (C = All_Checks or else C = Overflow_Check)
4420 Opt.Overflow_Checks_Unsuppressed := True;
4423 if Arg_Count = 1 then
4425 -- Make an entry in the local scope suppress table. This is the
4426 -- table that directly shows the current value of the scope
4427 -- suppress check for any check id value.
4429 if C = All_Checks then
4431 -- For All_Checks, we set all specific predefined checks with
4432 -- the exception of Elaboration_Check, which is handled
4433 -- specially because of not wanting All_Checks to have the
4434 -- effect of deactivating static elaboration order processing.
4436 for J in Scope_Suppress'Range loop
4437 if J /= Elaboration_Check then
4438 Scope_Suppress (J) := Suppress_Case;
4442 -- If not All_Checks, and predefined check, then set appropriate
4443 -- scope entry. Note that we will set Elaboration_Check if this
4444 -- is explicitly specified.
4446 elsif C in Predefined_Check_Id then
4447 Scope_Suppress (C) := Suppress_Case;
4450 -- Also make an entry in the Local_Entity_Suppress table
4452 Push_Local_Suppress_Stack_Entry
4455 Suppress => Suppress_Case);
4457 -- Case of two arguments present, where the check is suppressed for
4458 -- a specified entity (given as the second argument of the pragma)
4461 Check_Optional_Identifier (Arg2, Name_On);
4462 E_Id := Expression (Arg2);
4465 if not Is_Entity_Name (E_Id) then
4467 ("second argument of pragma% must be entity name", Arg2);
4476 -- Enforce RM 11.5(7) which requires that for a pragma that
4477 -- appears within a package spec, the named entity must be
4478 -- within the package spec. We allow the package name itself
4479 -- to be mentioned since that makes sense, although it is not
4480 -- strictly allowed by 11.5(7).
4483 and then E /= Current_Scope
4484 and then Scope (E) /= Current_Scope
4487 ("entity in pragma% is not in package spec (RM 11.5(7))",
4491 -- Loop through homonyms. As noted below, in the case of a package
4492 -- spec, only homonyms within the package spec are considered.
4495 Suppress_Unsuppress_Echeck (E, C);
4497 if Is_Generic_Instance (E)
4498 and then Is_Subprogram (E)
4499 and then Present (Alias (E))
4501 Suppress_Unsuppress_Echeck (Alias (E), C);
4504 -- Move to next homonym
4509 -- If we are within a package specification, the pragma only
4510 -- applies to homonyms in the same scope.
4512 exit when In_Package_Spec
4513 and then Scope (E) /= Current_Scope;
4516 end Process_Suppress_Unsuppress;
4522 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
4524 if Is_Imported (E) then
4526 ("cannot export entity& that was previously imported", Arg);
4528 elsif Present (Address_Clause (E)) then
4530 ("cannot export entity& that has an address clause", Arg);
4533 Set_Is_Exported (E);
4535 -- Generate a reference for entity explicitly, because the
4536 -- identifier may be overloaded and name resolution will not
4539 Generate_Reference (E, Arg);
4541 -- Deal with exporting non-library level entity
4543 if not Is_Library_Level_Entity (E) then
4545 -- Not allowed at all for subprograms
4547 if Is_Subprogram (E) then
4548 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
4550 -- Otherwise set public and statically allocated
4554 Set_Is_Statically_Allocated (E);
4556 -- Warn if the corresponding W flag is set and the pragma comes
4557 -- from source. The latter may not be true e.g. on VMS where we
4558 -- expand export pragmas for exception codes associated with
4559 -- imported or exported exceptions. We do not want to generate
4560 -- a warning for something that the user did not write.
4562 if Warn_On_Export_Import
4563 and then Comes_From_Source (Arg)
4566 ("?& has been made static as a result of Export", Arg, E);
4568 ("\this usage is non-standard and non-portable", Arg);
4573 if Warn_On_Export_Import and then Is_Type (E) then
4575 ("exporting a type has no effect?", Arg, E);
4578 if Warn_On_Export_Import and Inside_A_Generic then
4580 ("all instances of& will have the same external name?", Arg, E);
4584 ----------------------------------------------
4585 -- Set_Extended_Import_Export_External_Name --
4586 ----------------------------------------------
4588 procedure Set_Extended_Import_Export_External_Name
4589 (Internal_Ent : Entity_Id;
4590 Arg_External : Node_Id)
4592 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
4596 if No (Arg_External) then
4600 Check_Arg_Is_External_Name (Arg_External);
4602 if Nkind (Arg_External) = N_String_Literal then
4603 if String_Length (Strval (Arg_External)) = 0 then
4606 New_Name := Adjust_External_Name_Case (Arg_External);
4609 elsif Nkind (Arg_External) = N_Identifier then
4610 New_Name := Get_Default_External_Name (Arg_External);
4612 -- Check_Arg_Is_External_Name should let through only identifiers and
4613 -- string literals or static string expressions (which are folded to
4614 -- string literals).
4617 raise Program_Error;
4620 -- If we already have an external name set (by a prior normal Import
4621 -- or Export pragma), then the external names must match
4623 if Present (Interface_Name (Internal_Ent)) then
4624 Check_Matching_Internal_Names : declare
4625 S1 : constant String_Id := Strval (Old_Name);
4626 S2 : constant String_Id := Strval (New_Name);
4629 -- Called if names do not match
4635 procedure Mismatch is
4637 Error_Msg_Sloc := Sloc (Old_Name);
4639 ("external name does not match that given #",
4643 -- Start of processing for Check_Matching_Internal_Names
4646 if String_Length (S1) /= String_Length (S2) then
4650 for J in 1 .. String_Length (S1) loop
4651 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
4656 end Check_Matching_Internal_Names;
4658 -- Otherwise set the given name
4661 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
4662 Check_Duplicated_Export_Name (New_Name);
4664 end Set_Extended_Import_Export_External_Name;
4670 procedure Set_Imported (E : Entity_Id) is
4672 -- Error message if already imported or exported
4674 if Is_Exported (E) or else Is_Imported (E) then
4675 if Is_Exported (E) then
4676 Error_Msg_NE ("entity& was previously exported", N, E);
4678 Error_Msg_NE ("entity& was previously imported", N, E);
4681 Error_Msg_Name_1 := Pname;
4683 ("\(pragma% applies to all previous entities)", N);
4685 Error_Msg_Sloc := Sloc (E);
4686 Error_Msg_NE ("\import not allowed for& declared#", N, E);
4688 -- Here if not previously imported or exported, OK to import
4691 Set_Is_Imported (E);
4693 -- If the entity is an object that is not at the library level,
4694 -- then it is statically allocated. We do not worry about objects
4695 -- with address clauses in this context since they are not really
4696 -- imported in the linker sense.
4699 and then not Is_Library_Level_Entity (E)
4700 and then No (Address_Clause (E))
4702 Set_Is_Statically_Allocated (E);
4707 -------------------------
4708 -- Set_Mechanism_Value --
4709 -------------------------
4711 -- Note: the mechanism name has not been analyzed (and cannot indeed be
4712 -- analyzed, since it is semantic nonsense), so we get it in the exact
4713 -- form created by the parser.
4715 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
4718 Mech_Name_Id : Name_Id;
4720 procedure Bad_Class;
4721 -- Signal bad descriptor class name
4723 procedure Bad_Mechanism;
4724 -- Signal bad mechanism name
4730 procedure Bad_Class is
4732 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
4735 -------------------------
4736 -- Bad_Mechanism_Value --
4737 -------------------------
4739 procedure Bad_Mechanism is
4741 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
4744 -- Start of processing for Set_Mechanism_Value
4747 if Mechanism (Ent) /= Default_Mechanism then
4749 ("mechanism for & has already been set", Mech_Name, Ent);
4752 -- MECHANISM_NAME ::= value | reference | descriptor |
4755 if Nkind (Mech_Name) = N_Identifier then
4756 if Chars (Mech_Name) = Name_Value then
4757 Set_Mechanism (Ent, By_Copy);
4760 elsif Chars (Mech_Name) = Name_Reference then
4761 Set_Mechanism (Ent, By_Reference);
4764 elsif Chars (Mech_Name) = Name_Descriptor then
4765 Check_VMS (Mech_Name);
4766 Set_Mechanism (Ent, By_Descriptor);
4769 elsif Chars (Mech_Name) = Name_Short_Descriptor then
4770 Check_VMS (Mech_Name);
4771 Set_Mechanism (Ent, By_Short_Descriptor);
4774 elsif Chars (Mech_Name) = Name_Copy then
4776 ("bad mechanism name, Value assumed", Mech_Name);
4782 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
4783 -- short_descriptor (CLASS_NAME)
4784 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4786 -- Note: this form is parsed as an indexed component
4788 elsif Nkind (Mech_Name) = N_Indexed_Component then
4790 Class := First (Expressions (Mech_Name));
4792 if Nkind (Prefix (Mech_Name)) /= N_Identifier
4793 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
4794 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
4795 or else Present (Next (Class))
4799 Mech_Name_Id := Chars (Prefix (Mech_Name));
4802 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
4803 -- short_descriptor (Class => CLASS_NAME)
4804 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
4806 -- Note: this form is parsed as a function call
4808 elsif Nkind (Mech_Name) = N_Function_Call then
4810 Param := First (Parameter_Associations (Mech_Name));
4812 if Nkind (Name (Mech_Name)) /= N_Identifier
4813 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
4814 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
4815 or else Present (Next (Param))
4816 or else No (Selector_Name (Param))
4817 or else Chars (Selector_Name (Param)) /= Name_Class
4821 Class := Explicit_Actual_Parameter (Param);
4822 Mech_Name_Id := Chars (Name (Mech_Name));
4829 -- Fall through here with Class set to descriptor class name
4831 Check_VMS (Mech_Name);
4833 if Nkind (Class) /= N_Identifier then
4836 elsif Mech_Name_Id = Name_Descriptor
4837 and then Chars (Class) = Name_UBS
4839 Set_Mechanism (Ent, By_Descriptor_UBS);
4841 elsif Mech_Name_Id = Name_Descriptor
4842 and then Chars (Class) = Name_UBSB
4844 Set_Mechanism (Ent, By_Descriptor_UBSB);
4846 elsif Mech_Name_Id = Name_Descriptor
4847 and then Chars (Class) = Name_UBA
4849 Set_Mechanism (Ent, By_Descriptor_UBA);
4851 elsif Mech_Name_Id = Name_Descriptor
4852 and then Chars (Class) = Name_S
4854 Set_Mechanism (Ent, By_Descriptor_S);
4856 elsif Mech_Name_Id = Name_Descriptor
4857 and then Chars (Class) = Name_SB
4859 Set_Mechanism (Ent, By_Descriptor_SB);
4861 elsif Mech_Name_Id = Name_Descriptor
4862 and then Chars (Class) = Name_A
4864 Set_Mechanism (Ent, By_Descriptor_A);
4866 elsif Mech_Name_Id = Name_Descriptor
4867 and then Chars (Class) = Name_NCA
4869 Set_Mechanism (Ent, By_Descriptor_NCA);
4871 elsif Mech_Name_Id = Name_Short_Descriptor
4872 and then Chars (Class) = Name_UBS
4874 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
4876 elsif Mech_Name_Id = Name_Short_Descriptor
4877 and then Chars (Class) = Name_UBSB
4879 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
4881 elsif Mech_Name_Id = Name_Short_Descriptor
4882 and then Chars (Class) = Name_UBA
4884 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
4886 elsif Mech_Name_Id = Name_Short_Descriptor
4887 and then Chars (Class) = Name_S
4889 Set_Mechanism (Ent, By_Short_Descriptor_S);
4891 elsif Mech_Name_Id = Name_Short_Descriptor
4892 and then Chars (Class) = Name_SB
4894 Set_Mechanism (Ent, By_Short_Descriptor_SB);
4896 elsif Mech_Name_Id = Name_Short_Descriptor
4897 and then Chars (Class) = Name_A
4899 Set_Mechanism (Ent, By_Short_Descriptor_A);
4901 elsif Mech_Name_Id = Name_Short_Descriptor
4902 and then Chars (Class) = Name_NCA
4904 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
4909 end Set_Mechanism_Value;
4911 ---------------------------
4912 -- Set_Ravenscar_Profile --
4913 ---------------------------
4915 -- The tasks to be done here are
4917 -- Set required policies
4919 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4920 -- pragma Locking_Policy (Ceiling_Locking)
4922 -- Set Detect_Blocking mode
4924 -- Set required restrictions (see System.Rident for detailed list)
4926 procedure Set_Ravenscar_Profile (N : Node_Id) is
4928 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
4930 if Task_Dispatching_Policy /= ' '
4931 and then Task_Dispatching_Policy /= 'F'
4933 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
4934 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4936 -- Set the FIFO_Within_Priorities policy, but always preserve
4937 -- System_Location since we like the error message with the run time
4941 Task_Dispatching_Policy := 'F';
4943 if Task_Dispatching_Policy_Sloc /= System_Location then
4944 Task_Dispatching_Policy_Sloc := Loc;
4948 -- pragma Locking_Policy (Ceiling_Locking)
4950 if Locking_Policy /= ' '
4951 and then Locking_Policy /= 'C'
4953 Error_Msg_Sloc := Locking_Policy_Sloc;
4954 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
4956 -- Set the Ceiling_Locking policy, but preserve System_Location since
4957 -- we like the error message with the run time name.
4960 Locking_Policy := 'C';
4962 if Locking_Policy_Sloc /= System_Location then
4963 Locking_Policy_Sloc := Loc;
4967 -- pragma Detect_Blocking
4969 Detect_Blocking := True;
4971 -- Set the corresponding restrictions
4973 Set_Profile_Restrictions
4974 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
4975 end Set_Ravenscar_Profile;
4977 -- Start of processing for Analyze_Pragma
4980 -- Deal with unrecognized pragma
4982 if not Is_Pragma_Name (Pname) then
4983 if Warn_On_Unrecognized_Pragma then
4984 Error_Msg_Name_1 := Pname;
4985 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
4987 for PN in First_Pragma_Name .. Last_Pragma_Name loop
4988 if Is_Bad_Spelling_Of (Pname, PN) then
4989 Error_Msg_Name_1 := PN;
4990 Error_Msg_N -- CODEFIX
4991 ("\?possible misspelling of %!", Pragma_Identifier (N));
5000 -- Here to start processing for recognized pragma
5002 Prag_Id := Get_Pragma_Id (Pname);
5011 if Present (Pragma_Argument_Associations (N)) then
5012 Arg1 := First (Pragma_Argument_Associations (N));
5014 if Present (Arg1) then
5015 Arg2 := Next (Arg1);
5017 if Present (Arg2) then
5018 Arg3 := Next (Arg2);
5020 if Present (Arg3) then
5021 Arg4 := Next (Arg3);
5027 -- Count number of arguments
5034 while Present (Arg_Node) loop
5035 Arg_Count := Arg_Count + 1;
5040 -- An enumeration type defines the pragmas that are supported by the
5041 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5042 -- into the corresponding enumeration value for the following case.
5050 -- pragma Abort_Defer;
5052 when Pragma_Abort_Defer =>
5054 Check_Arg_Count (0);
5056 -- The only required semantic processing is to check the
5057 -- placement. This pragma must appear at the start of the
5058 -- statement sequence of a handled sequence of statements.
5060 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5061 or else N /= First (Statements (Parent (N)))
5072 -- Note: this pragma also has some specific processing in Par.Prag
5073 -- because we want to set the Ada version mode during parsing.
5075 when Pragma_Ada_83 =>
5077 Check_Arg_Count (0);
5079 -- We really should check unconditionally for proper configuration
5080 -- pragma placement, since we really don't want mixed Ada modes
5081 -- within a single unit, and the GNAT reference manual has always
5082 -- said this was a configuration pragma, but we did not check and
5083 -- are hesitant to add the check now.
5085 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5086 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5088 if Ada_Version >= Ada_05 then
5089 Check_Valid_Configuration_Pragma;
5092 -- Now set Ada 83 mode
5094 Ada_Version := Ada_83;
5095 Ada_Version_Explicit := Ada_Version;
5103 -- Note: this pragma also has some specific processing in Par.Prag
5104 -- because we want to set the Ada 83 version mode during parsing.
5106 when Pragma_Ada_95 =>
5108 Check_Arg_Count (0);
5110 -- We really should check unconditionally for proper configuration
5111 -- pragma placement, since we really don't want mixed Ada modes
5112 -- within a single unit, and the GNAT reference manual has always
5113 -- said this was a configuration pragma, but we did not check and
5114 -- are hesitant to add the check now.
5116 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5117 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5119 if Ada_Version >= Ada_05 then
5120 Check_Valid_Configuration_Pragma;
5123 -- Now set Ada 95 mode
5125 Ada_Version := Ada_95;
5126 Ada_Version_Explicit := Ada_Version;
5128 ---------------------
5129 -- Ada_05/Ada_2005 --
5130 ---------------------
5133 -- pragma Ada_05 (LOCAL_NAME);
5136 -- pragma Ada_2005 (LOCAL_NAME):
5138 -- Note: these pragma also have some specific processing in Par.Prag
5139 -- because we want to set the Ada 2005 version mode during parsing.
5141 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5147 if Arg_Count = 1 then
5148 Check_Arg_Is_Local_Name (Arg1);
5149 E_Id := Expression (Arg1);
5151 if Etype (E_Id) = Any_Type then
5155 Set_Is_Ada_2005_Only (Entity (E_Id));
5158 Check_Arg_Count (0);
5160 -- For Ada_2005 we unconditionally enforce the documented
5161 -- configuration pragma placement, since we do not want to
5162 -- tolerate mixed modes in a unit involving Ada 2005. That
5163 -- would cause real difficulties for those cases where there
5164 -- are incompatibilities between Ada 95 and Ada 2005.
5166 Check_Valid_Configuration_Pragma;
5168 -- Now set Ada 2005 mode
5170 Ada_Version := Ada_05;
5171 Ada_Version_Explicit := Ada_05;
5175 ----------------------
5176 -- All_Calls_Remote --
5177 ----------------------
5179 -- pragma All_Calls_Remote [(library_package_NAME)];
5181 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5182 Lib_Entity : Entity_Id;
5185 Check_Ada_83_Warning;
5186 Check_Valid_Library_Unit_Pragma;
5188 if Nkind (N) = N_Null_Statement then
5192 Lib_Entity := Find_Lib_Unit_Name;
5194 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
5196 if Present (Lib_Entity)
5197 and then not Debug_Flag_U
5199 if not Is_Remote_Call_Interface (Lib_Entity) then
5200 Error_Pragma ("pragma% only apply to rci unit");
5202 -- Set flag for entity of the library unit
5205 Set_Has_All_Calls_Remote (Lib_Entity);
5209 end All_Calls_Remote;
5215 -- pragma Annotate (IDENTIFIER {, ARG});
5216 -- ARG ::= NAME | EXPRESSION
5218 when Pragma_Annotate => Annotate : begin
5220 Check_At_Least_N_Arguments (1);
5221 Check_Arg_Is_Identifier (Arg1);
5229 while Present (Arg) loop
5230 Exp := Expression (Arg);
5233 if Is_Entity_Name (Exp) then
5236 elsif Nkind (Exp) = N_String_Literal then
5237 Resolve (Exp, Standard_String);
5239 elsif Is_Overloaded (Exp) then
5240 Error_Pragma_Arg ("ambiguous argument for pragma%", Exp);
5255 -- pragma Assert ([Check =>] Boolean_EXPRESSION
5256 -- [, [Message =>] Static_String_EXPRESSION]);
5258 when Pragma_Assert => Assert : declare
5264 Check_At_Least_N_Arguments (1);
5265 Check_At_Most_N_Arguments (2);
5266 Check_Arg_Order ((Name_Check, Name_Message));
5267 Check_Optional_Identifier (Arg1, Name_Check);
5269 -- We treat pragma Assert as equivalent to:
5271 -- pragma Check (Assertion, condition [, msg]);
5273 -- So rewrite pragma in this manner, and analyze the result
5275 Expr := Get_Pragma_Arg (Arg1);
5277 Make_Pragma_Argument_Association (Loc,
5279 Make_Identifier (Loc,
5280 Chars => Name_Assertion)),
5282 Make_Pragma_Argument_Association (Sloc (Expr),
5283 Expression => Expr));
5285 if Arg_Count > 1 then
5286 Check_Optional_Identifier (Arg2, Name_Message);
5287 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
5288 Append_To (Newa, Relocate_Node (Arg2));
5293 Chars => Name_Check,
5294 Pragma_Argument_Associations => Newa));
5298 ----------------------
5299 -- Assertion_Policy --
5300 ----------------------
5302 -- pragma Assertion_Policy (Check | Ignore)
5304 when Pragma_Assertion_Policy => Assertion_Policy : declare
5309 Check_Valid_Configuration_Pragma;
5310 Check_Arg_Count (1);
5311 Check_No_Identifiers;
5312 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
5314 -- We treat pragma Assertion_Policy as equivalent to:
5316 -- pragma Check_Policy (Assertion, policy)
5318 -- So rewrite the pragma in that manner and link on to the chain
5319 -- of Check_Policy pragmas, marking the pragma as analyzed.
5321 Policy := Get_Pragma_Arg (Arg1);
5325 Chars => Name_Check_Policy,
5327 Pragma_Argument_Associations => New_List (
5328 Make_Pragma_Argument_Association (Loc,
5330 Make_Identifier (Loc,
5331 Chars => Name_Assertion)),
5333 Make_Pragma_Argument_Association (Loc,
5335 Make_Identifier (Sloc (Policy),
5336 Chars => Chars (Policy))))));
5339 Set_Next_Pragma (N, Opt.Check_Policy_List);
5340 Opt.Check_Policy_List := N;
5341 end Assertion_Policy;
5343 ------------------------------
5344 -- Assume_No_Invalid_Values --
5345 ------------------------------
5347 -- pragma Assume_No_Invalid_Values (On | Off);
5349 when Pragma_Assume_No_Invalid_Values =>
5351 Check_Valid_Configuration_Pragma;
5352 Check_Arg_Count (1);
5353 Check_No_Identifiers;
5354 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
5356 if Chars (Expression (Arg1)) = Name_On then
5357 Assume_No_Invalid_Values := True;
5359 Assume_No_Invalid_Values := False;
5366 -- pragma AST_Entry (entry_IDENTIFIER);
5368 when Pragma_AST_Entry => AST_Entry : declare
5374 Check_Arg_Count (1);
5375 Check_No_Identifiers;
5376 Check_Arg_Is_Local_Name (Arg1);
5377 Ent := Entity (Expression (Arg1));
5379 -- Note: the implementation of the AST_Entry pragma could handle
5380 -- the entry family case fine, but for now we are consistent with
5381 -- the DEC rules, and do not allow the pragma, which of course
5382 -- has the effect of also forbidding the attribute.
5384 if Ekind (Ent) /= E_Entry then
5386 ("pragma% argument must be simple entry name", Arg1);
5388 elsif Is_AST_Entry (Ent) then
5390 ("duplicate % pragma for entry", Arg1);
5392 elsif Has_Homonym (Ent) then
5394 ("pragma% argument cannot specify overloaded entry", Arg1);
5398 FF : constant Entity_Id := First_Formal (Ent);
5401 if Present (FF) then
5402 if Present (Next_Formal (FF)) then
5404 ("entry for pragma% can have only one argument",
5407 elsif Parameter_Mode (FF) /= E_In_Parameter then
5409 ("entry parameter for pragma% must have mode IN",
5415 Set_Is_AST_Entry (Ent);
5423 -- pragma Asynchronous (LOCAL_NAME);
5425 when Pragma_Asynchronous => Asynchronous : declare
5433 procedure Process_Async_Pragma;
5434 -- Common processing for procedure and access-to-procedure case
5436 --------------------------
5437 -- Process_Async_Pragma --
5438 --------------------------
5440 procedure Process_Async_Pragma is
5443 Set_Is_Asynchronous (Nm);
5447 -- The formals should be of mode IN (RM E.4.1(6))
5450 while Present (S) loop
5451 Formal := Defining_Identifier (S);
5453 if Nkind (Formal) = N_Defining_Identifier
5454 and then Ekind (Formal) /= E_In_Parameter
5457 ("pragma% procedure can only have IN parameter",
5464 Set_Is_Asynchronous (Nm);
5465 end Process_Async_Pragma;
5467 -- Start of processing for pragma Asynchronous
5470 Check_Ada_83_Warning;
5471 Check_No_Identifiers;
5472 Check_Arg_Count (1);
5473 Check_Arg_Is_Local_Name (Arg1);
5475 if Debug_Flag_U then
5479 C_Ent := Cunit_Entity (Current_Sem_Unit);
5480 Analyze (Expression (Arg1));
5481 Nm := Entity (Expression (Arg1));
5483 if not Is_Remote_Call_Interface (C_Ent)
5484 and then not Is_Remote_Types (C_Ent)
5486 -- This pragma should only appear in an RCI or Remote Types
5487 -- unit (RM E.4.1(4)).
5490 ("pragma% not in Remote_Call_Interface or " &
5491 "Remote_Types unit");
5494 if Ekind (Nm) = E_Procedure
5495 and then Nkind (Parent (Nm)) = N_Procedure_Specification
5497 if not Is_Remote_Call_Interface (Nm) then
5499 ("pragma% cannot be applied on non-remote procedure",
5503 L := Parameter_Specifications (Parent (Nm));
5504 Process_Async_Pragma;
5507 elsif Ekind (Nm) = E_Function then
5509 ("pragma% cannot be applied to function", Arg1);
5511 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
5513 if Is_Record_Type (Nm) then
5515 -- A record type that is the Equivalent_Type for a remote
5516 -- access-to-subprogram type.
5518 N := Declaration_Node (Corresponding_Remote_Type (Nm));
5521 -- A non-expanded RAS type (distribution is not enabled)
5523 N := Declaration_Node (Nm);
5526 if Nkind (N) = N_Full_Type_Declaration
5527 and then Nkind (Type_Definition (N)) =
5528 N_Access_Procedure_Definition
5530 L := Parameter_Specifications (Type_Definition (N));
5531 Process_Async_Pragma;
5533 if Is_Asynchronous (Nm)
5534 and then Expander_Active
5535 and then Get_PCS_Name /= Name_No_DSA
5537 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
5542 ("pragma% cannot reference access-to-function type",
5546 -- Only other possibility is Access-to-class-wide type
5548 elsif Is_Access_Type (Nm)
5549 and then Is_Class_Wide_Type (Designated_Type (Nm))
5551 Check_First_Subtype (Arg1);
5552 Set_Is_Asynchronous (Nm);
5553 if Expander_Active then
5554 RACW_Type_Is_Asynchronous (Nm);
5558 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
5566 -- pragma Atomic (LOCAL_NAME);
5568 when Pragma_Atomic =>
5569 Process_Atomic_Shared_Volatile;
5571 -----------------------
5572 -- Atomic_Components --
5573 -----------------------
5575 -- pragma Atomic_Components (array_LOCAL_NAME);
5577 -- This processing is shared by Volatile_Components
5579 when Pragma_Atomic_Components |
5580 Pragma_Volatile_Components =>
5582 Atomic_Components : declare
5589 Check_Ada_83_Warning;
5590 Check_No_Identifiers;
5591 Check_Arg_Count (1);
5592 Check_Arg_Is_Local_Name (Arg1);
5593 E_Id := Expression (Arg1);
5595 if Etype (E_Id) = Any_Type then
5601 if Rep_Item_Too_Early (E, N)
5603 Rep_Item_Too_Late (E, N)
5608 D := Declaration_Node (E);
5611 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
5613 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
5614 and then Nkind (D) = N_Object_Declaration
5615 and then Nkind (Object_Definition (D)) =
5616 N_Constrained_Array_Definition)
5618 -- The flag is set on the object, or on the base type
5620 if Nkind (D) /= N_Object_Declaration then
5624 Set_Has_Volatile_Components (E);
5626 if Prag_Id = Pragma_Atomic_Components then
5627 Set_Has_Atomic_Components (E);
5629 if Is_Packed (E) then
5630 Set_Is_Packed (E, False);
5633 ("?Pack canceled, cannot pack atomic components",
5639 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
5641 end Atomic_Components;
5643 --------------------
5644 -- Attach_Handler --
5645 --------------------
5647 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
5649 when Pragma_Attach_Handler =>
5650 Check_Ada_83_Warning;
5651 Check_No_Identifiers;
5652 Check_Arg_Count (2);
5654 if No_Run_Time_Mode then
5655 Error_Msg_CRT ("Attach_Handler pragma", N);
5657 Check_Interrupt_Or_Attach_Handler;
5659 -- The expression that designates the attribute may
5660 -- depend on a discriminant, and is therefore a per-
5661 -- object expression, to be expanded in the init proc.
5662 -- If expansion is enabled, perform semantic checks
5665 if Expander_Active then
5667 Temp : constant Node_Id :=
5668 New_Copy_Tree (Expression (Arg2));
5670 Set_Parent (Temp, N);
5671 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
5675 Analyze (Expression (Arg2));
5676 Resolve (Expression (Arg2), RTE (RE_Interrupt_ID));
5679 Process_Interrupt_Or_Attach_Handler;
5682 --------------------
5683 -- C_Pass_By_Copy --
5684 --------------------
5686 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
5688 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
5694 Check_Valid_Configuration_Pragma;
5695 Check_Arg_Count (1);
5696 Check_Optional_Identifier (Arg1, "max_size");
5698 Arg := Expression (Arg1);
5699 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
5701 Val := Expr_Value (Arg);
5705 ("maximum size for pragma% must be positive", Arg1);
5707 elsif UI_Is_In_Int_Range (Val) then
5708 Default_C_Record_Mechanism := UI_To_Int (Val);
5710 -- If a giant value is given, Int'Last will do well enough.
5711 -- If sometime someone complains that a record larger than
5712 -- two gigabytes is not copied, we will worry about it then!
5715 Default_C_Record_Mechanism := Mechanism_Type'Last;
5723 -- pragma Check ([Name =>] Identifier,
5724 -- [Check =>] Boolean_Expression
5725 -- [,[Message =>] String_Expression]);
5727 when Pragma_Check => Check : declare
5732 -- Set True if category of assertions referenced by Name enabled
5736 Check_At_Least_N_Arguments (2);
5737 Check_At_Most_N_Arguments (3);
5738 Check_Optional_Identifier (Arg1, Name_Name);
5739 Check_Optional_Identifier (Arg2, Name_Check);
5741 if Arg_Count = 3 then
5742 Check_Optional_Identifier (Arg3, Name_Message);
5743 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
5746 Check_Arg_Is_Identifier (Arg1);
5747 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
5749 -- If expansion is active and the check is not enabled then we
5750 -- rewrite the Check as:
5752 -- if False and then condition then
5756 -- The reason we do this rewriting during semantic analysis rather
5757 -- than as part of normal expansion is that we cannot analyze and
5758 -- expand the code for the boolean expression directly, or it may
5759 -- cause insertion of actions that would escape the attempt to
5760 -- suppress the check code.
5762 -- Note that the Sloc for the if statement corresponds to the
5763 -- argument condition, not the pragma itself. The reason for this
5764 -- is that we may generate a warning if the condition is False at
5765 -- compile time, and we do not want to delete this warning when we
5766 -- delete the if statement.
5768 Expr := Expression (Arg2);
5770 if Expander_Active and then not Check_On then
5771 Eloc := Sloc (Expr);
5774 Make_If_Statement (Eloc,
5776 Make_And_Then (Eloc,
5777 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
5778 Right_Opnd => Expr),
5779 Then_Statements => New_List (
5780 Make_Null_Statement (Eloc))));
5787 Analyze_And_Resolve (Expr, Any_Boolean);
5795 -- pragma Check_Name (check_IDENTIFIER);
5797 when Pragma_Check_Name =>
5798 Check_No_Identifiers;
5800 Check_Valid_Configuration_Pragma;
5801 Check_Arg_Count (1);
5802 Check_Arg_Is_Identifier (Arg1);
5805 Nam : constant Name_Id := Chars (Expression (Arg1));
5808 for J in Check_Names.First .. Check_Names.Last loop
5809 if Check_Names.Table (J) = Nam then
5814 Check_Names.Append (Nam);
5821 -- pragma Check_Policy (
5822 -- [Name =>] IDENTIFIER,
5823 -- [Policy =>] POLICY_IDENTIFIER);
5825 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
5827 -- Note: this is a configuration pragma, but it is allowed to appear
5830 when Pragma_Check_Policy =>
5832 Check_Arg_Count (2);
5833 Check_Optional_Identifier (Arg1, Name_Name);
5834 Check_Optional_Identifier (Arg2, Name_Policy);
5836 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
5838 -- A Check_Policy pragma can appear either as a configuration
5839 -- pragma, or in a declarative part or a package spec (see RM
5840 -- 11.5(5) for rules for Suppress/Unsuppress which are also
5841 -- followed for Check_Policy).
5843 if not Is_Configuration_Pragma then
5844 Check_Is_In_Decl_Part_Or_Package_Spec;
5847 Set_Next_Pragma (N, Opt.Check_Policy_List);
5848 Opt.Check_Policy_List := N;
5850 ---------------------
5851 -- CIL_Constructor --
5852 ---------------------
5854 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
5856 -- Processing for this pragma is shared with Java_Constructor
5862 -- pragma Comment (static_string_EXPRESSION)
5864 -- Processing for pragma Comment shares the circuitry for pragma
5865 -- Ident. The only differences are that Ident enforces a limit of 31
5866 -- characters on its argument, and also enforces limitations on
5867 -- placement for DEC compatibility. Pragma Comment shares neither of
5868 -- these restrictions.
5874 -- pragma Common_Object (
5875 -- [Internal =>] LOCAL_NAME
5876 -- [, [External =>] EXTERNAL_SYMBOL]
5877 -- [, [Size =>] EXTERNAL_SYMBOL]);
5879 -- Processing for this pragma is shared with Psect_Object
5881 ------------------------
5882 -- Compile_Time_Error --
5883 ------------------------
5885 -- pragma Compile_Time_Error
5886 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5888 when Pragma_Compile_Time_Error =>
5890 Process_Compile_Time_Warning_Or_Error;
5892 --------------------------
5893 -- Compile_Time_Warning --
5894 --------------------------
5896 -- pragma Compile_Time_Warning
5897 -- (boolean_EXPRESSION, static_string_EXPRESSION);
5899 when Pragma_Compile_Time_Warning =>
5901 Process_Compile_Time_Warning_Or_Error;
5907 when Pragma_Compiler_Unit =>
5909 Check_Arg_Count (0);
5910 Set_Is_Compiler_Unit (Get_Source_Unit (N));
5912 -----------------------------
5913 -- Complete_Representation --
5914 -----------------------------
5916 -- pragma Complete_Representation;
5918 when Pragma_Complete_Representation =>
5920 Check_Arg_Count (0);
5922 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
5924 ("pragma & must appear within record representation clause");
5927 ----------------------------
5928 -- Complex_Representation --
5929 ----------------------------
5931 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
5933 when Pragma_Complex_Representation => Complex_Representation : declare
5940 Check_Arg_Count (1);
5941 Check_Optional_Identifier (Arg1, Name_Entity);
5942 Check_Arg_Is_Local_Name (Arg1);
5943 E_Id := Expression (Arg1);
5945 if Etype (E_Id) = Any_Type then
5951 if not Is_Record_Type (E) then
5953 ("argument for pragma% must be record type", Arg1);
5956 Ent := First_Entity (E);
5959 or else No (Next_Entity (Ent))
5960 or else Present (Next_Entity (Next_Entity (Ent)))
5961 or else not Is_Floating_Point_Type (Etype (Ent))
5962 or else Etype (Ent) /= Etype (Next_Entity (Ent))
5965 ("record for pragma% must have two fields of the same "
5966 & "floating-point type", Arg1);
5969 Set_Has_Complex_Representation (Base_Type (E));
5971 -- We need to treat the type has having a non-standard
5972 -- representation, for back-end purposes, even though in
5973 -- general a complex will have the default representation
5974 -- of a record with two real components.
5976 Set_Has_Non_Standard_Rep (Base_Type (E));
5978 end Complex_Representation;
5980 -------------------------
5981 -- Component_Alignment --
5982 -------------------------
5984 -- pragma Component_Alignment (
5985 -- [Form =>] ALIGNMENT_CHOICE
5986 -- [, [Name =>] type_LOCAL_NAME]);
5988 -- ALIGNMENT_CHOICE ::=
5990 -- | Component_Size_4
5994 when Pragma_Component_Alignment => Component_AlignmentP : declare
5995 Args : Args_List (1 .. 2);
5996 Names : constant Name_List (1 .. 2) := (
6000 Form : Node_Id renames Args (1);
6001 Name : Node_Id renames Args (2);
6003 Atype : Component_Alignment_Kind;
6008 Gather_Associations (Names, Args);
6011 Error_Pragma ("missing Form argument for pragma%");
6014 Check_Arg_Is_Identifier (Form);
6016 -- Get proper alignment, note that Default = Component_Size on all
6017 -- machines we have so far, and we want to set this value rather
6018 -- than the default value to indicate that it has been explicitly
6019 -- set (and thus will not get overridden by the default component
6020 -- alignment for the current scope)
6022 if Chars (Form) = Name_Component_Size then
6023 Atype := Calign_Component_Size;
6025 elsif Chars (Form) = Name_Component_Size_4 then
6026 Atype := Calign_Component_Size_4;
6028 elsif Chars (Form) = Name_Default then
6029 Atype := Calign_Component_Size;
6031 elsif Chars (Form) = Name_Storage_Unit then
6032 Atype := Calign_Storage_Unit;
6036 ("invalid Form parameter for pragma%", Form);
6039 -- Case with no name, supplied, affects scope table entry
6043 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6045 -- Case of name supplied
6048 Check_Arg_Is_Local_Name (Name);
6050 Typ := Entity (Name);
6053 or else Rep_Item_Too_Early (Typ, N)
6057 Typ := Underlying_Type (Typ);
6060 if not Is_Record_Type (Typ)
6061 and then not Is_Array_Type (Typ)
6064 ("Name parameter of pragma% must identify record or " &
6065 "array type", Name);
6068 -- An explicit Component_Alignment pragma overrides an
6069 -- implicit pragma Pack, but not an explicit one.
6071 if not Has_Pragma_Pack (Base_Type (Typ)) then
6072 Set_Is_Packed (Base_Type (Typ), False);
6073 Set_Component_Alignment (Base_Type (Typ), Atype);
6076 end Component_AlignmentP;
6082 -- pragma Controlled (first_subtype_LOCAL_NAME);
6084 when Pragma_Controlled => Controlled : declare
6088 Check_No_Identifiers;
6089 Check_Arg_Count (1);
6090 Check_Arg_Is_Local_Name (Arg1);
6091 Arg := Expression (Arg1);
6093 if not Is_Entity_Name (Arg)
6094 or else not Is_Access_Type (Entity (Arg))
6096 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6098 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6106 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6107 -- [Entity =>] LOCAL_NAME);
6109 when Pragma_Convention => Convention : declare
6112 pragma Warnings (Off, C);
6113 pragma Warnings (Off, E);
6115 Check_Arg_Order ((Name_Convention, Name_Entity));
6116 Check_Ada_83_Warning;
6117 Check_Arg_Count (2);
6118 Process_Convention (C, E);
6121 ---------------------------
6122 -- Convention_Identifier --
6123 ---------------------------
6125 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6126 -- [Convention =>] convention_IDENTIFIER);
6128 when Pragma_Convention_Identifier => Convention_Identifier : declare
6134 Check_Arg_Order ((Name_Name, Name_Convention));
6135 Check_Arg_Count (2);
6136 Check_Optional_Identifier (Arg1, Name_Name);
6137 Check_Optional_Identifier (Arg2, Name_Convention);
6138 Check_Arg_Is_Identifier (Arg1);
6139 Check_Arg_Is_Identifier (Arg2);
6140 Idnam := Chars (Expression (Arg1));
6141 Cname := Chars (Expression (Arg2));
6143 if Is_Convention_Name (Cname) then
6144 Record_Convention_Identifier
6145 (Idnam, Get_Convention_Id (Cname));
6148 ("second arg for % pragma must be convention", Arg2);
6150 end Convention_Identifier;
6156 -- pragma CPP_Class ([Entity =>] local_NAME)
6158 when Pragma_CPP_Class => CPP_Class : declare
6163 if Warn_On_Obsolescent_Feature then
6165 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6166 " by pragma import?", N);
6170 Check_Arg_Count (1);
6171 Check_Optional_Identifier (Arg1, Name_Entity);
6172 Check_Arg_Is_Local_Name (Arg1);
6174 Arg := Expression (Arg1);
6177 if Etype (Arg) = Any_Type then
6181 if not Is_Entity_Name (Arg)
6182 or else not Is_Type (Entity (Arg))
6184 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
6187 Typ := Entity (Arg);
6189 if not Is_Tagged_Type (Typ) then
6190 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
6193 -- Types treated as CPP classes are treated as limited, but we
6194 -- don't require them to be declared this way. A warning is issued
6195 -- to encourage the user to declare them as limited. This is not
6196 -- an error, for compatibility reasons, because these types have
6197 -- been supported this way for some time.
6199 if not Is_Limited_Type (Typ) then
6201 ("imported 'C'P'P type should be " &
6202 "explicitly declared limited?",
6203 Get_Pragma_Arg (Arg1));
6205 ("\type will be considered limited",
6206 Get_Pragma_Arg (Arg1));
6209 Set_Is_CPP_Class (Typ);
6210 Set_Is_Limited_Record (Typ);
6211 Set_Convention (Typ, Convention_CPP);
6213 -- Imported CPP types must not have discriminants (because C++
6214 -- classes do not have discriminants).
6216 if Has_Discriminants (Typ) then
6218 ("imported 'C'P'P type cannot have discriminants",
6219 First (Discriminant_Specifications
6220 (Declaration_Node (Typ))));
6223 -- Components of imported CPP types must not have default
6224 -- expressions because the constructor (if any) is in the
6227 if Is_Incomplete_Or_Private_Type (Typ)
6228 and then No (Underlying_Type (Typ))
6230 -- It should be an error to apply pragma CPP to a private
6231 -- type if the underlying type is not visible (as it is
6232 -- for any representation item). For now, for backward
6233 -- compatibility we do nothing but we cannot check components
6234 -- because they are not available at this stage. All this code
6235 -- will be removed when we cleanup this obsolete GNAT pragma???
6241 Tdef : constant Node_Id :=
6242 Type_Definition (Declaration_Node (Typ));
6247 if Nkind (Tdef) = N_Record_Definition then
6248 Clist := Component_List (Tdef);
6250 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
6251 Clist := Component_List (Record_Extension_Part (Tdef));
6254 if Present (Clist) then
6255 Comp := First (Component_Items (Clist));
6256 while Present (Comp) loop
6257 if Present (Expression (Comp)) then
6259 ("component of imported 'C'P'P type cannot have" &
6260 " default expression", Expression (Comp));
6270 ---------------------
6271 -- CPP_Constructor --
6272 ---------------------
6274 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
6275 -- [, [External_Name =>] static_string_EXPRESSION ]
6276 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6278 when Pragma_CPP_Constructor => CPP_Constructor : declare
6282 Tag_Typ : Entity_Id;
6286 Check_At_Least_N_Arguments (1);
6287 Check_At_Most_N_Arguments (3);
6288 Check_Optional_Identifier (Arg1, Name_Entity);
6289 Check_Arg_Is_Local_Name (Arg1);
6291 Id := Expression (Arg1);
6292 Find_Program_Unit_Name (Id);
6294 -- If we did not find the name, we are done
6296 if Etype (Id) = Any_Type then
6300 Def_Id := Entity (Id);
6302 if Ekind (Def_Id) = E_Function
6303 and then (Is_CPP_Class (Etype (Def_Id))
6304 or else (Is_Class_Wide_Type (Etype (Def_Id))
6306 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
6308 if Arg_Count >= 2 then
6309 Set_Imported (Def_Id);
6310 Set_Is_Public (Def_Id);
6311 Process_Interface_Name (Def_Id, Arg2, Arg3);
6314 Set_Has_Completion (Def_Id);
6315 Set_Is_Constructor (Def_Id);
6317 -- Imported C++ constructors are not dispatching primitives
6318 -- because in C++ they don't have a dispatch table slot.
6319 -- However, in Ada the constructor has the profile of a
6320 -- function that returns a tagged type and therefore it has
6321 -- been treated as a primitive operation during semantic
6322 -- analysis. We now remove it from the list of primitive
6323 -- operations of the type.
6325 if Is_Tagged_Type (Etype (Def_Id))
6326 and then not Is_Class_Wide_Type (Etype (Def_Id))
6328 pragma Assert (Is_Dispatching_Operation (Def_Id));
6329 Tag_Typ := Etype (Def_Id);
6331 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
6332 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
6336 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
6337 Set_Is_Dispatching_Operation (Def_Id, False);
6340 -- For backward compatibility, if the constructor returns a
6341 -- class wide type, and we internally change the return type to
6342 -- the corresponding root type.
6344 if Is_Class_Wide_Type (Etype (Def_Id)) then
6345 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
6349 ("pragma% requires function returning a 'C'P'P_Class type",
6352 end CPP_Constructor;
6358 when Pragma_CPP_Virtual => CPP_Virtual : declare
6362 if Warn_On_Obsolescent_Feature then
6364 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
6373 when Pragma_CPP_Vtable => CPP_Vtable : declare
6377 if Warn_On_Obsolescent_Feature then
6379 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
6388 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
6390 when Pragma_Debug => Debug : declare
6398 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
6401 if Arg_Count = 2 then
6404 Left_Opnd => Relocate_Node (Cond),
6405 Right_Opnd => Expression (Arg1));
6408 -- Rewrite into a conditional with an appropriate condition. We
6409 -- wrap the procedure call in a block so that overhead from e.g.
6410 -- use of the secondary stack does not generate execution overhead
6411 -- for suppressed conditions.
6413 Rewrite (N, Make_Implicit_If_Statement (N,
6415 Then_Statements => New_List (
6416 Make_Block_Statement (Loc,
6417 Handled_Statement_Sequence =>
6418 Make_Handled_Sequence_Of_Statements (Loc,
6419 Statements => New_List (
6420 Relocate_Node (Debug_Statement (N))))))));
6428 -- pragma Debug_Policy (Check | Ignore)
6430 when Pragma_Debug_Policy =>
6432 Check_Arg_Count (1);
6433 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6434 Debug_Pragmas_Enabled := Chars (Expression (Arg1)) = Name_Check;
6436 ---------------------
6437 -- Detect_Blocking --
6438 ---------------------
6440 -- pragma Detect_Blocking;
6442 when Pragma_Detect_Blocking =>
6444 Check_Arg_Count (0);
6445 Check_Valid_Configuration_Pragma;
6446 Detect_Blocking := True;
6452 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
6454 when Pragma_Discard_Names => Discard_Names : declare
6459 Check_Ada_83_Warning;
6461 -- Deal with configuration pragma case
6463 if Arg_Count = 0 and then Is_Configuration_Pragma then
6464 Global_Discard_Names := True;
6467 -- Otherwise, check correct appropriate context
6470 Check_Is_In_Decl_Part_Or_Package_Spec;
6472 if Arg_Count = 0 then
6474 -- If there is no parameter, then from now on this pragma
6475 -- applies to any enumeration, exception or tagged type
6476 -- defined in the current declarative part, and recursively
6477 -- to any nested scope.
6479 Set_Discard_Names (Current_Scope);
6483 Check_Arg_Count (1);
6484 Check_Optional_Identifier (Arg1, Name_On);
6485 Check_Arg_Is_Local_Name (Arg1);
6487 E_Id := Expression (Arg1);
6489 if Etype (E_Id) = Any_Type then
6495 if (Is_First_Subtype (E)
6497 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
6498 or else Ekind (E) = E_Exception
6500 Set_Discard_Names (E);
6503 ("inappropriate entity for pragma%", Arg1);
6514 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
6516 when Pragma_Elaborate => Elaborate : declare
6521 -- Pragma must be in context items list of a compilation unit
6523 if not Is_In_Context_Clause then
6527 -- Must be at least one argument
6529 if Arg_Count = 0 then
6530 Error_Pragma ("pragma% requires at least one argument");
6533 -- In Ada 83 mode, there can be no items following it in the
6534 -- context list except other pragmas and implicit with clauses
6535 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
6536 -- placement rule does not apply.
6538 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
6540 while Present (Citem) loop
6541 if Nkind (Citem) = N_Pragma
6542 or else (Nkind (Citem) = N_With_Clause
6543 and then Implicit_With (Citem))
6548 ("(Ada 83) pragma% must be at end of context clause");
6555 -- Finally, the arguments must all be units mentioned in a with
6556 -- clause in the same context clause. Note we already checked (in
6557 -- Par.Prag) that the arguments are all identifiers or selected
6561 Outer : while Present (Arg) loop
6562 Citem := First (List_Containing (N));
6563 Inner : while Citem /= N loop
6564 if Nkind (Citem) = N_With_Clause
6565 and then Same_Name (Name (Citem), Expression (Arg))
6567 Set_Elaborate_Present (Citem, True);
6568 Set_Unit_Name (Expression (Arg), Name (Citem));
6570 -- With the pragma present, elaboration calls on
6571 -- subprograms from the named unit need no further
6572 -- checks, as long as the pragma appears in the current
6573 -- compilation unit. If the pragma appears in some unit
6574 -- in the context, there might still be a need for an
6575 -- Elaborate_All_Desirable from the current compilation
6576 -- to the named unit, so we keep the check enabled.
6578 if In_Extended_Main_Source_Unit (N) then
6579 Set_Suppress_Elaboration_Warnings
6580 (Entity (Name (Citem)));
6591 ("argument of pragma% is not with'ed unit", Arg);
6597 -- Give a warning if operating in static mode with -gnatwl
6598 -- (elaboration warnings enabled) switch set.
6600 if Elab_Warnings and not Dynamic_Elaboration_Checks then
6602 ("?use of pragma Elaborate may not be safe", N);
6604 ("?use pragma Elaborate_All instead if possible", N);
6612 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
6614 when Pragma_Elaborate_All => Elaborate_All : declare
6619 Check_Ada_83_Warning;
6621 -- Pragma must be in context items list of a compilation unit
6623 if not Is_In_Context_Clause then
6627 -- Must be at least one argument
6629 if Arg_Count = 0 then
6630 Error_Pragma ("pragma% requires at least one argument");
6633 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
6634 -- have to appear at the end of the context clause, but may
6635 -- appear mixed in with other items, even in Ada 83 mode.
6637 -- Final check: the arguments must all be units mentioned in
6638 -- a with clause in the same context clause. Note that we
6639 -- already checked (in Par.Prag) that all the arguments are
6640 -- either identifiers or selected components.
6643 Outr : while Present (Arg) loop
6644 Citem := First (List_Containing (N));
6645 Innr : while Citem /= N loop
6646 if Nkind (Citem) = N_With_Clause
6647 and then Same_Name (Name (Citem), Expression (Arg))
6649 Set_Elaborate_All_Present (Citem, True);
6650 Set_Unit_Name (Expression (Arg), Name (Citem));
6652 -- Suppress warnings and elaboration checks on the named
6653 -- unit if the pragma is in the current compilation, as
6654 -- for pragma Elaborate.
6656 if In_Extended_Main_Source_Unit (N) then
6657 Set_Suppress_Elaboration_Warnings
6658 (Entity (Name (Citem)));
6667 Set_Error_Posted (N);
6669 ("argument of pragma% is not with'ed unit", Arg);
6676 --------------------
6677 -- Elaborate_Body --
6678 --------------------
6680 -- pragma Elaborate_Body [( library_unit_NAME )];
6682 when Pragma_Elaborate_Body => Elaborate_Body : declare
6683 Cunit_Node : Node_Id;
6684 Cunit_Ent : Entity_Id;
6687 Check_Ada_83_Warning;
6688 Check_Valid_Library_Unit_Pragma;
6690 if Nkind (N) = N_Null_Statement then
6694 Cunit_Node := Cunit (Current_Sem_Unit);
6695 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
6697 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
6700 Error_Pragma ("pragma% must refer to a spec, not a body");
6702 Set_Body_Required (Cunit_Node, True);
6703 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
6705 -- If we are in dynamic elaboration mode, then we suppress
6706 -- elaboration warnings for the unit, since it is definitely
6707 -- fine NOT to do dynamic checks at the first level (and such
6708 -- checks will be suppressed because no elaboration boolean
6709 -- is created for Elaborate_Body packages).
6711 -- But in the static model of elaboration, Elaborate_Body is
6712 -- definitely NOT good enough to ensure elaboration safety on
6713 -- its own, since the body may WITH other units that are not
6714 -- safe from an elaboration point of view, so a client must
6715 -- still do an Elaborate_All on such units.
6717 -- Debug flag -gnatdD restores the old behavior of 3.13, where
6718 -- Elaborate_Body always suppressed elab warnings.
6720 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
6721 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
6726 ------------------------
6727 -- Elaboration_Checks --
6728 ------------------------
6730 -- pragma Elaboration_Checks (Static | Dynamic);
6732 when Pragma_Elaboration_Checks =>
6734 Check_Arg_Count (1);
6735 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
6736 Dynamic_Elaboration_Checks :=
6737 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
6743 -- pragma Eliminate (
6744 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
6745 -- [,[Entity =>] IDENTIFIER |
6746 -- SELECTED_COMPONENT |
6748 -- [, OVERLOADING_RESOLUTION]);
6750 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
6753 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
6756 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
6758 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
6759 -- Result_Type => result_SUBTYPE_NAME]
6761 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
6762 -- SUBTYPE_NAME ::= STRING_LITERAL
6764 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
6765 -- SOURCE_TRACE ::= STRING_LITERAL
6767 when Pragma_Eliminate => Eliminate : declare
6768 Args : Args_List (1 .. 5);
6769 Names : constant Name_List (1 .. 5) := (
6772 Name_Parameter_Types,
6774 Name_Source_Location);
6776 Unit_Name : Node_Id renames Args (1);
6777 Entity : Node_Id renames Args (2);
6778 Parameter_Types : Node_Id renames Args (3);
6779 Result_Type : Node_Id renames Args (4);
6780 Source_Location : Node_Id renames Args (5);
6784 Check_Valid_Configuration_Pragma;
6785 Gather_Associations (Names, Args);
6787 if No (Unit_Name) then
6788 Error_Pragma ("missing Unit_Name argument for pragma%");
6792 and then (Present (Parameter_Types)
6794 Present (Result_Type)
6796 Present (Source_Location))
6798 Error_Pragma ("missing Entity argument for pragma%");
6801 if (Present (Parameter_Types)
6803 Present (Result_Type))
6805 Present (Source_Location)
6808 ("parameter profile and source location cannot " &
6809 "be used together in pragma%");
6812 Process_Eliminate_Pragma
6826 -- [ Convention =>] convention_IDENTIFIER,
6827 -- [ Entity =>] local_NAME
6828 -- [, [External_Name =>] static_string_EXPRESSION ]
6829 -- [, [Link_Name =>] static_string_EXPRESSION ]);
6831 when Pragma_Export => Export : declare
6835 pragma Warnings (Off, C);
6838 Check_Ada_83_Warning;
6844 Check_At_Least_N_Arguments (2);
6845 Check_At_Most_N_Arguments (4);
6846 Process_Convention (C, Def_Id);
6848 if Ekind (Def_Id) /= E_Constant then
6849 Note_Possible_Modification (Expression (Arg2), Sure => False);
6852 Process_Interface_Name (Def_Id, Arg3, Arg4);
6853 Set_Exported (Def_Id, Arg2);
6855 -- If the entity is a deferred constant, propagate the information
6856 -- to the full view, because gigi elaborates the full view only.
6858 if Ekind (Def_Id) = E_Constant
6859 and then Present (Full_View (Def_Id))
6862 Id2 : constant Entity_Id := Full_View (Def_Id);
6864 Set_Is_Exported (Id2, Is_Exported (Def_Id));
6865 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
6866 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
6871 ----------------------
6872 -- Export_Exception --
6873 ----------------------
6875 -- pragma Export_Exception (
6876 -- [Internal =>] LOCAL_NAME
6877 -- [, [External =>] EXTERNAL_SYMBOL]
6878 -- [, [Form =>] Ada | VMS]
6879 -- [, [Code =>] static_integer_EXPRESSION]);
6881 when Pragma_Export_Exception => Export_Exception : declare
6882 Args : Args_List (1 .. 4);
6883 Names : constant Name_List (1 .. 4) := (
6889 Internal : Node_Id renames Args (1);
6890 External : Node_Id renames Args (2);
6891 Form : Node_Id renames Args (3);
6892 Code : Node_Id renames Args (4);
6897 if Inside_A_Generic then
6898 Error_Pragma ("pragma% cannot be used for generic entities");
6901 Gather_Associations (Names, Args);
6902 Process_Extended_Import_Export_Exception_Pragma (
6903 Arg_Internal => Internal,
6904 Arg_External => External,
6908 if not Is_VMS_Exception (Entity (Internal)) then
6909 Set_Exported (Entity (Internal), Internal);
6911 end Export_Exception;
6913 ---------------------
6914 -- Export_Function --
6915 ---------------------
6917 -- pragma Export_Function (
6918 -- [Internal =>] LOCAL_NAME
6919 -- [, [External =>] EXTERNAL_SYMBOL]
6920 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
6921 -- [, [Result_Type =>] TYPE_DESIGNATOR]
6922 -- [, [Mechanism =>] MECHANISM]
6923 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
6925 -- EXTERNAL_SYMBOL ::=
6927 -- | static_string_EXPRESSION
6929 -- PARAMETER_TYPES ::=
6931 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6933 -- TYPE_DESIGNATOR ::=
6935 -- | subtype_Name ' Access
6939 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
6941 -- MECHANISM_ASSOCIATION ::=
6942 -- [formal_parameter_NAME =>] MECHANISM_NAME
6944 -- MECHANISM_NAME ::=
6947 -- | Descriptor [([Class =>] CLASS_NAME)]
6949 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
6951 when Pragma_Export_Function => Export_Function : declare
6952 Args : Args_List (1 .. 6);
6953 Names : constant Name_List (1 .. 6) := (
6956 Name_Parameter_Types,
6959 Name_Result_Mechanism);
6961 Internal : Node_Id renames Args (1);
6962 External : Node_Id renames Args (2);
6963 Parameter_Types : Node_Id renames Args (3);
6964 Result_Type : Node_Id renames Args (4);
6965 Mechanism : Node_Id renames Args (5);
6966 Result_Mechanism : Node_Id renames Args (6);
6970 Gather_Associations (Names, Args);
6971 Process_Extended_Import_Export_Subprogram_Pragma (
6972 Arg_Internal => Internal,
6973 Arg_External => External,
6974 Arg_Parameter_Types => Parameter_Types,
6975 Arg_Result_Type => Result_Type,
6976 Arg_Mechanism => Mechanism,
6977 Arg_Result_Mechanism => Result_Mechanism);
6978 end Export_Function;
6984 -- pragma Export_Object (
6985 -- [Internal =>] LOCAL_NAME
6986 -- [, [External =>] EXTERNAL_SYMBOL]
6987 -- [, [Size =>] EXTERNAL_SYMBOL]);
6989 -- EXTERNAL_SYMBOL ::=
6991 -- | static_string_EXPRESSION
6993 -- PARAMETER_TYPES ::=
6995 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
6997 -- TYPE_DESIGNATOR ::=
6999 -- | subtype_Name ' Access
7003 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7005 -- MECHANISM_ASSOCIATION ::=
7006 -- [formal_parameter_NAME =>] MECHANISM_NAME
7008 -- MECHANISM_NAME ::=
7011 -- | Descriptor [([Class =>] CLASS_NAME)]
7013 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7015 when Pragma_Export_Object => Export_Object : declare
7016 Args : Args_List (1 .. 3);
7017 Names : constant Name_List (1 .. 3) := (
7022 Internal : Node_Id renames Args (1);
7023 External : Node_Id renames Args (2);
7024 Size : Node_Id renames Args (3);
7028 Gather_Associations (Names, Args);
7029 Process_Extended_Import_Export_Object_Pragma (
7030 Arg_Internal => Internal,
7031 Arg_External => External,
7035 ----------------------
7036 -- Export_Procedure --
7037 ----------------------
7039 -- pragma Export_Procedure (
7040 -- [Internal =>] LOCAL_NAME
7041 -- [, [External =>] EXTERNAL_SYMBOL]
7042 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7043 -- [, [Mechanism =>] MECHANISM]);
7045 -- EXTERNAL_SYMBOL ::=
7047 -- | static_string_EXPRESSION
7049 -- PARAMETER_TYPES ::=
7051 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7053 -- TYPE_DESIGNATOR ::=
7055 -- | subtype_Name ' Access
7059 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7061 -- MECHANISM_ASSOCIATION ::=
7062 -- [formal_parameter_NAME =>] MECHANISM_NAME
7064 -- MECHANISM_NAME ::=
7067 -- | Descriptor [([Class =>] CLASS_NAME)]
7069 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7071 when Pragma_Export_Procedure => Export_Procedure : declare
7072 Args : Args_List (1 .. 4);
7073 Names : constant Name_List (1 .. 4) := (
7076 Name_Parameter_Types,
7079 Internal : Node_Id renames Args (1);
7080 External : Node_Id renames Args (2);
7081 Parameter_Types : Node_Id renames Args (3);
7082 Mechanism : Node_Id renames Args (4);
7086 Gather_Associations (Names, Args);
7087 Process_Extended_Import_Export_Subprogram_Pragma (
7088 Arg_Internal => Internal,
7089 Arg_External => External,
7090 Arg_Parameter_Types => Parameter_Types,
7091 Arg_Mechanism => Mechanism);
7092 end Export_Procedure;
7098 -- pragma Export_Value (
7099 -- [Value =>] static_integer_EXPRESSION,
7100 -- [Link_Name =>] static_string_EXPRESSION);
7102 when Pragma_Export_Value =>
7104 Check_Arg_Order ((Name_Value, Name_Link_Name));
7105 Check_Arg_Count (2);
7107 Check_Optional_Identifier (Arg1, Name_Value);
7108 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
7110 Check_Optional_Identifier (Arg2, Name_Link_Name);
7111 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
7113 -----------------------------
7114 -- Export_Valued_Procedure --
7115 -----------------------------
7117 -- pragma Export_Valued_Procedure (
7118 -- [Internal =>] LOCAL_NAME
7119 -- [, [External =>] EXTERNAL_SYMBOL,]
7120 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7121 -- [, [Mechanism =>] MECHANISM]);
7123 -- EXTERNAL_SYMBOL ::=
7125 -- | static_string_EXPRESSION
7127 -- PARAMETER_TYPES ::=
7129 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7131 -- TYPE_DESIGNATOR ::=
7133 -- | subtype_Name ' Access
7137 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7139 -- MECHANISM_ASSOCIATION ::=
7140 -- [formal_parameter_NAME =>] MECHANISM_NAME
7142 -- MECHANISM_NAME ::=
7145 -- | Descriptor [([Class =>] CLASS_NAME)]
7147 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7149 when Pragma_Export_Valued_Procedure =>
7150 Export_Valued_Procedure : declare
7151 Args : Args_List (1 .. 4);
7152 Names : constant Name_List (1 .. 4) := (
7155 Name_Parameter_Types,
7158 Internal : Node_Id renames Args (1);
7159 External : Node_Id renames Args (2);
7160 Parameter_Types : Node_Id renames Args (3);
7161 Mechanism : Node_Id renames Args (4);
7165 Gather_Associations (Names, Args);
7166 Process_Extended_Import_Export_Subprogram_Pragma (
7167 Arg_Internal => Internal,
7168 Arg_External => External,
7169 Arg_Parameter_Types => Parameter_Types,
7170 Arg_Mechanism => Mechanism);
7171 end Export_Valued_Procedure;
7177 -- pragma Extend_System ([Name =>] Identifier);
7179 when Pragma_Extend_System => Extend_System : declare
7182 Check_Valid_Configuration_Pragma;
7183 Check_Arg_Count (1);
7184 Check_Optional_Identifier (Arg1, Name_Name);
7185 Check_Arg_Is_Identifier (Arg1);
7187 Get_Name_String (Chars (Expression (Arg1)));
7190 and then Name_Buffer (1 .. 4) = "aux_"
7192 if Present (System_Extend_Pragma_Arg) then
7193 if Chars (Expression (Arg1)) =
7194 Chars (Expression (System_Extend_Pragma_Arg))
7198 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
7199 Error_Pragma ("pragma% conflicts with that #");
7203 System_Extend_Pragma_Arg := Arg1;
7205 if not GNAT_Mode then
7206 System_Extend_Unit := Arg1;
7210 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
7214 ------------------------
7215 -- Extensions_Allowed --
7216 ------------------------
7218 -- pragma Extensions_Allowed (ON | OFF);
7220 when Pragma_Extensions_Allowed =>
7222 Check_Arg_Count (1);
7223 Check_No_Identifiers;
7224 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
7226 if Chars (Expression (Arg1)) = Name_On then
7227 Extensions_Allowed := True;
7229 Extensions_Allowed := False;
7236 -- pragma External (
7237 -- [ Convention =>] convention_IDENTIFIER,
7238 -- [ Entity =>] local_NAME
7239 -- [, [External_Name =>] static_string_EXPRESSION ]
7240 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7242 when Pragma_External => External : declare
7246 pragma Warnings (Off, C);
7255 Check_At_Least_N_Arguments (2);
7256 Check_At_Most_N_Arguments (4);
7257 Process_Convention (C, Def_Id);
7258 Note_Possible_Modification (Expression (Arg2), Sure => False);
7259 Process_Interface_Name (Def_Id, Arg3, Arg4);
7260 Set_Exported (Def_Id, Arg2);
7263 --------------------------
7264 -- External_Name_Casing --
7265 --------------------------
7267 -- pragma External_Name_Casing (
7268 -- UPPERCASE | LOWERCASE
7269 -- [, AS_IS | UPPERCASE | LOWERCASE]);
7271 when Pragma_External_Name_Casing => External_Name_Casing : declare
7274 Check_No_Identifiers;
7276 if Arg_Count = 2 then
7278 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
7280 case Chars (Get_Pragma_Arg (Arg2)) is
7282 Opt.External_Name_Exp_Casing := As_Is;
7284 when Name_Uppercase =>
7285 Opt.External_Name_Exp_Casing := Uppercase;
7287 when Name_Lowercase =>
7288 Opt.External_Name_Exp_Casing := Lowercase;
7295 Check_Arg_Count (1);
7298 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
7300 case Chars (Get_Pragma_Arg (Arg1)) is
7301 when Name_Uppercase =>
7302 Opt.External_Name_Imp_Casing := Uppercase;
7304 when Name_Lowercase =>
7305 Opt.External_Name_Imp_Casing := Lowercase;
7310 end External_Name_Casing;
7312 --------------------------
7313 -- Favor_Top_Level --
7314 --------------------------
7316 -- pragma Favor_Top_Level (type_NAME);
7318 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
7319 Named_Entity : Entity_Id;
7323 Check_No_Identifiers;
7324 Check_Arg_Count (1);
7325 Check_Arg_Is_Local_Name (Arg1);
7326 Named_Entity := Entity (Expression (Arg1));
7328 -- If it's an access-to-subprogram type (in particular, not a
7329 -- subtype), set the flag on that type.
7331 if Is_Access_Subprogram_Type (Named_Entity) then
7332 Set_Can_Use_Internal_Rep (Named_Entity, False);
7334 -- Otherwise it's an error (name denotes the wrong sort of entity)
7338 ("access-to-subprogram type expected", Expression (Arg1));
7340 end Favor_Top_Level;
7346 -- pragma Fast_Math;
7348 when Pragma_Fast_Math =>
7350 Check_No_Identifiers;
7351 Check_Valid_Configuration_Pragma;
7354 ---------------------------
7355 -- Finalize_Storage_Only --
7356 ---------------------------
7358 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
7360 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
7361 Assoc : constant Node_Id := Arg1;
7362 Type_Id : constant Node_Id := Expression (Assoc);
7367 Check_No_Identifiers;
7368 Check_Arg_Count (1);
7369 Check_Arg_Is_Local_Name (Arg1);
7371 Find_Type (Type_Id);
7372 Typ := Entity (Type_Id);
7375 or else Rep_Item_Too_Early (Typ, N)
7379 Typ := Underlying_Type (Typ);
7382 if not Is_Controlled (Typ) then
7383 Error_Pragma ("pragma% must specify controlled type");
7386 Check_First_Subtype (Arg1);
7388 if Finalize_Storage_Only (Typ) then
7389 Error_Pragma ("duplicate pragma%, only one allowed");
7391 elsif not Rep_Item_Too_Late (Typ, N) then
7392 Set_Finalize_Storage_Only (Base_Type (Typ), True);
7394 end Finalize_Storage;
7396 --------------------------
7397 -- Float_Representation --
7398 --------------------------
7400 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
7402 -- FLOAT_REP ::= VAX_Float | IEEE_Float
7404 when Pragma_Float_Representation => Float_Representation : declare
7412 if Arg_Count = 1 then
7413 Check_Valid_Configuration_Pragma;
7415 Check_Arg_Count (2);
7416 Check_Optional_Identifier (Arg2, Name_Entity);
7417 Check_Arg_Is_Local_Name (Arg2);
7420 Check_No_Identifier (Arg1);
7421 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
7423 if not OpenVMS_On_Target then
7424 if Chars (Expression (Arg1)) = Name_VAX_Float then
7426 ("?pragma% ignored (applies only to Open'V'M'S)");
7432 -- One argument case
7434 if Arg_Count = 1 then
7435 if Chars (Expression (Arg1)) = Name_VAX_Float then
7436 if Opt.Float_Format = 'I' then
7437 Error_Pragma ("'I'E'E'E format previously specified");
7440 Opt.Float_Format := 'V';
7443 if Opt.Float_Format = 'V' then
7444 Error_Pragma ("'V'A'X format previously specified");
7447 Opt.Float_Format := 'I';
7450 Set_Standard_Fpt_Formats;
7452 -- Two argument case
7455 Argx := Get_Pragma_Arg (Arg2);
7457 if not Is_Entity_Name (Argx)
7458 or else not Is_Floating_Point_Type (Entity (Argx))
7461 ("second argument of% pragma must be floating-point type",
7465 Ent := Entity (Argx);
7466 Digs := UI_To_Int (Digits_Value (Ent));
7468 -- Two arguments, VAX_Float case
7470 if Chars (Expression (Arg1)) = Name_VAX_Float then
7472 when 6 => Set_F_Float (Ent);
7473 when 9 => Set_D_Float (Ent);
7474 when 15 => Set_G_Float (Ent);
7478 ("wrong digits value, must be 6,9 or 15", Arg2);
7481 -- Two arguments, IEEE_Float case
7485 when 6 => Set_IEEE_Short (Ent);
7486 when 15 => Set_IEEE_Long (Ent);
7490 ("wrong digits value, must be 6 or 15", Arg2);
7494 end Float_Representation;
7500 -- pragma Ident (static_string_EXPRESSION)
7502 -- Note: pragma Comment shares this processing. Pragma Comment is
7503 -- identical to Ident, except that the restriction of the argument to
7504 -- 31 characters and the placement restrictions are not enforced for
7507 when Pragma_Ident | Pragma_Comment => Ident : declare
7512 Check_Arg_Count (1);
7513 Check_No_Identifiers;
7514 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
7516 -- For pragma Ident, preserve DEC compatibility by requiring the
7517 -- pragma to appear in a declarative part or package spec.
7519 if Prag_Id = Pragma_Ident then
7520 Check_Is_In_Decl_Part_Or_Package_Spec;
7523 Str := Expr_Value_S (Expression (Arg1));
7530 GP := Parent (Parent (N));
7532 if Nkind_In (GP, N_Package_Declaration,
7533 N_Generic_Package_Declaration)
7538 -- If we have a compilation unit, then record the ident value,
7539 -- checking for improper duplication.
7541 if Nkind (GP) = N_Compilation_Unit then
7542 CS := Ident_String (Current_Sem_Unit);
7544 if Present (CS) then
7546 -- For Ident, we do not permit multiple instances
7548 if Prag_Id = Pragma_Ident then
7549 Error_Pragma ("duplicate% pragma not permitted");
7551 -- For Comment, we concatenate the string, unless we want
7552 -- to preserve the tree structure for ASIS.
7554 elsif not ASIS_Mode then
7555 Start_String (Strval (CS));
7556 Store_String_Char (' ');
7557 Store_String_Chars (Strval (Str));
7558 Set_Strval (CS, End_String);
7562 -- In VMS, the effect of IDENT is achieved by passing
7563 -- IDENTIFICATION=name as a --for-linker switch.
7565 if OpenVMS_On_Target then
7568 ("--for-linker=IDENTIFICATION=");
7569 String_To_Name_Buffer (Strval (Str));
7570 Store_String_Chars (Name_Buffer (1 .. Name_Len));
7572 -- Only the last processed IDENT is saved. The main
7573 -- purpose is so an IDENT associated with a main
7574 -- procedure will be used in preference to an IDENT
7575 -- associated with a with'd package.
7577 Replace_Linker_Option_String
7578 (End_String, "--for-linker=IDENTIFICATION=");
7581 Set_Ident_String (Current_Sem_Unit, Str);
7584 -- For subunits, we just ignore the Ident, since in GNAT these
7585 -- are not separate object files, and hence not separate units
7586 -- in the unit table.
7588 elsif Nkind (GP) = N_Subunit then
7591 -- Otherwise we have a misplaced pragma Ident, but we ignore
7592 -- this if we are in an instantiation, since it comes from
7593 -- a generic, and has no relevance to the instantiation.
7595 elsif Prag_Id = Pragma_Ident then
7596 if Instantiation_Location (Loc) = No_Location then
7597 Error_Pragma ("pragma% only allowed at outer level");
7603 --------------------------
7604 -- Implemented_By_Entry --
7605 --------------------------
7607 -- pragma Implemented_By_Entry (DIRECT_NAME);
7609 when Pragma_Implemented_By_Entry => Implemented_By_Entry : declare
7614 Check_Arg_Count (1);
7615 Check_No_Identifiers;
7616 Check_Arg_Is_Identifier (Arg1);
7617 Check_Arg_Is_Local_Name (Arg1);
7618 Ent := Entity (Expression (Arg1));
7620 -- Pragma Implemented_By_Entry must be applied only to protected
7621 -- synchronized or task interface primitives.
7623 if (Ekind (Ent) /= E_Function
7624 and then Ekind (Ent) /= E_Procedure)
7625 or else not Present (First_Formal (Ent))
7626 or else not Is_Concurrent_Interface (Etype (First_Formal (Ent)))
7629 ("pragma % must be applied to a concurrent interface " &
7633 if Einfo.Implemented_By_Entry (Ent)
7634 and then Warn_On_Redundant_Constructs
7636 Error_Pragma ("?duplicate pragma%!");
7638 Set_Implemented_By_Entry (Ent);
7641 end Implemented_By_Entry;
7643 -----------------------
7644 -- Implicit_Packing --
7645 -----------------------
7647 -- pragma Implicit_Packing;
7649 when Pragma_Implicit_Packing =>
7651 Check_Arg_Count (0);
7652 Implicit_Packing := True;
7659 -- [Convention =>] convention_IDENTIFIER,
7660 -- [Entity =>] local_NAME
7661 -- [, [External_Name =>] static_string_EXPRESSION ]
7662 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7664 when Pragma_Import =>
7665 Check_Ada_83_Warning;
7671 Check_At_Least_N_Arguments (2);
7672 Check_At_Most_N_Arguments (4);
7673 Process_Import_Or_Interface;
7675 ----------------------
7676 -- Import_Exception --
7677 ----------------------
7679 -- pragma Import_Exception (
7680 -- [Internal =>] LOCAL_NAME
7681 -- [, [External =>] EXTERNAL_SYMBOL]
7682 -- [, [Form =>] Ada | VMS]
7683 -- [, [Code =>] static_integer_EXPRESSION]);
7685 when Pragma_Import_Exception => Import_Exception : declare
7686 Args : Args_List (1 .. 4);
7687 Names : constant Name_List (1 .. 4) := (
7693 Internal : Node_Id renames Args (1);
7694 External : Node_Id renames Args (2);
7695 Form : Node_Id renames Args (3);
7696 Code : Node_Id renames Args (4);
7700 Gather_Associations (Names, Args);
7702 if Present (External) and then Present (Code) then
7704 ("cannot give both External and Code options for pragma%");
7707 Process_Extended_Import_Export_Exception_Pragma (
7708 Arg_Internal => Internal,
7709 Arg_External => External,
7713 if not Is_VMS_Exception (Entity (Internal)) then
7714 Set_Imported (Entity (Internal));
7716 end Import_Exception;
7718 ---------------------
7719 -- Import_Function --
7720 ---------------------
7722 -- pragma Import_Function (
7723 -- [Internal =>] LOCAL_NAME,
7724 -- [, [External =>] EXTERNAL_SYMBOL]
7725 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7726 -- [, [Result_Type =>] SUBTYPE_MARK]
7727 -- [, [Mechanism =>] MECHANISM]
7728 -- [, [Result_Mechanism =>] MECHANISM_NAME]
7729 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7731 -- EXTERNAL_SYMBOL ::=
7733 -- | static_string_EXPRESSION
7735 -- PARAMETER_TYPES ::=
7737 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7739 -- TYPE_DESIGNATOR ::=
7741 -- | subtype_Name ' Access
7745 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7747 -- MECHANISM_ASSOCIATION ::=
7748 -- [formal_parameter_NAME =>] MECHANISM_NAME
7750 -- MECHANISM_NAME ::=
7753 -- | Descriptor [([Class =>] CLASS_NAME)]
7755 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7757 when Pragma_Import_Function => Import_Function : declare
7758 Args : Args_List (1 .. 7);
7759 Names : constant Name_List (1 .. 7) := (
7762 Name_Parameter_Types,
7765 Name_Result_Mechanism,
7766 Name_First_Optional_Parameter);
7768 Internal : Node_Id renames Args (1);
7769 External : Node_Id renames Args (2);
7770 Parameter_Types : Node_Id renames Args (3);
7771 Result_Type : Node_Id renames Args (4);
7772 Mechanism : Node_Id renames Args (5);
7773 Result_Mechanism : Node_Id renames Args (6);
7774 First_Optional_Parameter : Node_Id renames Args (7);
7778 Gather_Associations (Names, Args);
7779 Process_Extended_Import_Export_Subprogram_Pragma (
7780 Arg_Internal => Internal,
7781 Arg_External => External,
7782 Arg_Parameter_Types => Parameter_Types,
7783 Arg_Result_Type => Result_Type,
7784 Arg_Mechanism => Mechanism,
7785 Arg_Result_Mechanism => Result_Mechanism,
7786 Arg_First_Optional_Parameter => First_Optional_Parameter);
7787 end Import_Function;
7793 -- pragma Import_Object (
7794 -- [Internal =>] LOCAL_NAME
7795 -- [, [External =>] EXTERNAL_SYMBOL]
7796 -- [, [Size =>] EXTERNAL_SYMBOL]);
7798 -- EXTERNAL_SYMBOL ::=
7800 -- | static_string_EXPRESSION
7802 when Pragma_Import_Object => Import_Object : declare
7803 Args : Args_List (1 .. 3);
7804 Names : constant Name_List (1 .. 3) := (
7809 Internal : Node_Id renames Args (1);
7810 External : Node_Id renames Args (2);
7811 Size : Node_Id renames Args (3);
7815 Gather_Associations (Names, Args);
7816 Process_Extended_Import_Export_Object_Pragma (
7817 Arg_Internal => Internal,
7818 Arg_External => External,
7822 ----------------------
7823 -- Import_Procedure --
7824 ----------------------
7826 -- pragma Import_Procedure (
7827 -- [Internal =>] LOCAL_NAME
7828 -- [, [External =>] EXTERNAL_SYMBOL]
7829 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7830 -- [, [Mechanism =>] MECHANISM]
7831 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7833 -- EXTERNAL_SYMBOL ::=
7835 -- | static_string_EXPRESSION
7837 -- PARAMETER_TYPES ::=
7839 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7841 -- TYPE_DESIGNATOR ::=
7843 -- | subtype_Name ' Access
7847 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7849 -- MECHANISM_ASSOCIATION ::=
7850 -- [formal_parameter_NAME =>] MECHANISM_NAME
7852 -- MECHANISM_NAME ::=
7855 -- | Descriptor [([Class =>] CLASS_NAME)]
7857 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7859 when Pragma_Import_Procedure => Import_Procedure : declare
7860 Args : Args_List (1 .. 5);
7861 Names : constant Name_List (1 .. 5) := (
7864 Name_Parameter_Types,
7866 Name_First_Optional_Parameter);
7868 Internal : Node_Id renames Args (1);
7869 External : Node_Id renames Args (2);
7870 Parameter_Types : Node_Id renames Args (3);
7871 Mechanism : Node_Id renames Args (4);
7872 First_Optional_Parameter : Node_Id renames Args (5);
7876 Gather_Associations (Names, Args);
7877 Process_Extended_Import_Export_Subprogram_Pragma (
7878 Arg_Internal => Internal,
7879 Arg_External => External,
7880 Arg_Parameter_Types => Parameter_Types,
7881 Arg_Mechanism => Mechanism,
7882 Arg_First_Optional_Parameter => First_Optional_Parameter);
7883 end Import_Procedure;
7885 -----------------------------
7886 -- Import_Valued_Procedure --
7887 -----------------------------
7889 -- pragma Import_Valued_Procedure (
7890 -- [Internal =>] LOCAL_NAME
7891 -- [, [External =>] EXTERNAL_SYMBOL]
7892 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7893 -- [, [Mechanism =>] MECHANISM]
7894 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
7896 -- EXTERNAL_SYMBOL ::=
7898 -- | static_string_EXPRESSION
7900 -- PARAMETER_TYPES ::=
7902 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7904 -- TYPE_DESIGNATOR ::=
7906 -- | subtype_Name ' Access
7910 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7912 -- MECHANISM_ASSOCIATION ::=
7913 -- [formal_parameter_NAME =>] MECHANISM_NAME
7915 -- MECHANISM_NAME ::=
7918 -- | Descriptor [([Class =>] CLASS_NAME)]
7920 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7922 when Pragma_Import_Valued_Procedure =>
7923 Import_Valued_Procedure : declare
7924 Args : Args_List (1 .. 5);
7925 Names : constant Name_List (1 .. 5) := (
7928 Name_Parameter_Types,
7930 Name_First_Optional_Parameter);
7932 Internal : Node_Id renames Args (1);
7933 External : Node_Id renames Args (2);
7934 Parameter_Types : Node_Id renames Args (3);
7935 Mechanism : Node_Id renames Args (4);
7936 First_Optional_Parameter : Node_Id renames Args (5);
7940 Gather_Associations (Names, Args);
7941 Process_Extended_Import_Export_Subprogram_Pragma (
7942 Arg_Internal => Internal,
7943 Arg_External => External,
7944 Arg_Parameter_Types => Parameter_Types,
7945 Arg_Mechanism => Mechanism,
7946 Arg_First_Optional_Parameter => First_Optional_Parameter);
7947 end Import_Valued_Procedure;
7949 ------------------------
7950 -- Initialize_Scalars --
7951 ------------------------
7953 -- pragma Initialize_Scalars;
7955 when Pragma_Initialize_Scalars =>
7957 Check_Arg_Count (0);
7958 Check_Valid_Configuration_Pragma;
7959 Check_Restriction (No_Initialize_Scalars, N);
7961 -- Initialize_Scalars creates false positives in CodePeer,
7962 -- so ignore this pragma in this mode.
7964 if not Restriction_Active (No_Initialize_Scalars)
7965 and then not CodePeer_Mode
7967 Init_Or_Norm_Scalars := True;
7968 Initialize_Scalars := True;
7975 -- pragma Inline ( NAME {, NAME} );
7977 when Pragma_Inline =>
7979 -- Pragma is active if inlining option is active
7981 Process_Inline (Inline_Active);
7987 -- pragma Inline_Always ( NAME {, NAME} );
7989 when Pragma_Inline_Always =>
7991 Process_Inline (True);
7993 --------------------
7994 -- Inline_Generic --
7995 --------------------
7997 -- pragma Inline_Generic (NAME {, NAME});
7999 when Pragma_Inline_Generic =>
8001 Process_Generic_List;
8003 ----------------------
8004 -- Inspection_Point --
8005 ----------------------
8007 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
8009 when Pragma_Inspection_Point => Inspection_Point : declare
8014 if Arg_Count > 0 then
8017 Exp := Expression (Arg);
8020 if not Is_Entity_Name (Exp)
8021 or else not Is_Object (Entity (Exp))
8023 Error_Pragma_Arg ("object name required", Arg);
8030 end Inspection_Point;
8036 -- pragma Interface (
8037 -- [ Convention =>] convention_IDENTIFIER,
8038 -- [ Entity =>] local_NAME
8039 -- [, [External_Name =>] static_string_EXPRESSION ]
8040 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8042 when Pragma_Interface =>
8049 Check_At_Least_N_Arguments (2);
8050 Check_At_Most_N_Arguments (4);
8051 Process_Import_Or_Interface;
8053 --------------------
8054 -- Interface_Name --
8055 --------------------
8057 -- pragma Interface_Name (
8058 -- [ Entity =>] local_NAME
8059 -- [,[External_Name =>] static_string_EXPRESSION ]
8060 -- [,[Link_Name =>] static_string_EXPRESSION ]);
8062 when Pragma_Interface_Name => Interface_Name : declare
8071 ((Name_Entity, Name_External_Name, Name_Link_Name));
8072 Check_At_Least_N_Arguments (2);
8073 Check_At_Most_N_Arguments (3);
8074 Id := Expression (Arg1);
8077 if not Is_Entity_Name (Id) then
8079 ("first argument for pragma% must be entity name", Arg1);
8080 elsif Etype (Id) = Any_Type then
8083 Def_Id := Entity (Id);
8086 -- Special DEC-compatible processing for the object case, forces
8087 -- object to be imported.
8089 if Ekind (Def_Id) = E_Variable then
8090 Kill_Size_Check_Code (Def_Id);
8091 Note_Possible_Modification (Id, Sure => False);
8093 -- Initialization is not allowed for imported variable
8095 if Present (Expression (Parent (Def_Id)))
8096 and then Comes_From_Source (Expression (Parent (Def_Id)))
8098 Error_Msg_Sloc := Sloc (Def_Id);
8100 ("no initialization allowed for declaration of& #",
8104 -- For compatibility, support VADS usage of providing both
8105 -- pragmas Interface and Interface_Name to obtain the effect
8106 -- of a single Import pragma.
8108 if Is_Imported (Def_Id)
8109 and then Present (First_Rep_Item (Def_Id))
8110 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
8112 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
8116 Set_Imported (Def_Id);
8119 Set_Is_Public (Def_Id);
8120 Process_Interface_Name (Def_Id, Arg2, Arg3);
8123 -- Otherwise must be subprogram
8125 elsif not Is_Subprogram (Def_Id) then
8127 ("argument of pragma% is not subprogram", Arg1);
8130 Check_At_Most_N_Arguments (3);
8134 -- Loop through homonyms
8137 Def_Id := Get_Base_Subprogram (Hom_Id);
8139 if Is_Imported (Def_Id) then
8140 Process_Interface_Name (Def_Id, Arg2, Arg3);
8144 Hom_Id := Homonym (Hom_Id);
8146 exit when No (Hom_Id)
8147 or else Scope (Hom_Id) /= Current_Scope;
8152 ("argument of pragma% is not imported subprogram",
8158 -----------------------
8159 -- Interrupt_Handler --
8160 -----------------------
8162 -- pragma Interrupt_Handler (handler_NAME);
8164 when Pragma_Interrupt_Handler =>
8165 Check_Ada_83_Warning;
8166 Check_Arg_Count (1);
8167 Check_No_Identifiers;
8169 if No_Run_Time_Mode then
8170 Error_Msg_CRT ("Interrupt_Handler pragma", N);
8172 Check_Interrupt_Or_Attach_Handler;
8173 Process_Interrupt_Or_Attach_Handler;
8176 ------------------------
8177 -- Interrupt_Priority --
8178 ------------------------
8180 -- pragma Interrupt_Priority [(EXPRESSION)];
8182 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
8183 P : constant Node_Id := Parent (N);
8187 Check_Ada_83_Warning;
8189 if Arg_Count /= 0 then
8190 Arg := Expression (Arg1);
8191 Check_Arg_Count (1);
8192 Check_No_Identifiers;
8194 -- The expression must be analyzed in the special manner
8195 -- described in "Handling of Default and Per-Object
8196 -- Expressions" in sem.ads.
8198 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
8201 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
8205 elsif Has_Priority_Pragma (P) then
8206 Error_Pragma ("duplicate pragma% not allowed");
8209 Set_Has_Priority_Pragma (P, True);
8210 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8212 end Interrupt_Priority;
8214 ---------------------
8215 -- Interrupt_State --
8216 ---------------------
8218 -- pragma Interrupt_State (
8219 -- [Name =>] INTERRUPT_ID,
8220 -- [State =>] INTERRUPT_STATE);
8222 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
8223 -- INTERRUPT_STATE => System | Runtime | User
8225 -- Note: if the interrupt id is given as an identifier, then it must
8226 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
8227 -- given as a static integer expression which must be in the range of
8228 -- Ada.Interrupts.Interrupt_ID.
8230 when Pragma_Interrupt_State => Interrupt_State : declare
8232 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
8233 -- This is the entity Ada.Interrupts.Interrupt_ID;
8235 State_Type : Character;
8236 -- Set to 's'/'r'/'u' for System/Runtime/User
8239 -- Index to entry in Interrupt_States table
8242 -- Value of interrupt
8244 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
8245 -- The first argument to the pragma
8247 Int_Ent : Entity_Id;
8248 -- Interrupt entity in Ada.Interrupts.Names
8252 Check_Arg_Order ((Name_Name, Name_State));
8253 Check_Arg_Count (2);
8255 Check_Optional_Identifier (Arg1, Name_Name);
8256 Check_Optional_Identifier (Arg2, Name_State);
8257 Check_Arg_Is_Identifier (Arg2);
8259 -- First argument is identifier
8261 if Nkind (Arg1X) = N_Identifier then
8263 -- Search list of names in Ada.Interrupts.Names
8265 Int_Ent := First_Entity (RTE (RE_Names));
8267 if No (Int_Ent) then
8268 Error_Pragma_Arg ("invalid interrupt name", Arg1);
8270 elsif Chars (Int_Ent) = Chars (Arg1X) then
8271 Int_Val := Expr_Value (Constant_Value (Int_Ent));
8275 Next_Entity (Int_Ent);
8278 -- First argument is not an identifier, so it must be a static
8279 -- expression of type Ada.Interrupts.Interrupt_ID.
8282 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8283 Int_Val := Expr_Value (Arg1X);
8285 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
8287 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
8290 ("value not in range of type " &
8291 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
8297 case Chars (Get_Pragma_Arg (Arg2)) is
8298 when Name_Runtime => State_Type := 'r';
8299 when Name_System => State_Type := 's';
8300 when Name_User => State_Type := 'u';
8303 Error_Pragma_Arg ("invalid interrupt state", Arg2);
8306 -- Check if entry is already stored
8308 IST_Num := Interrupt_States.First;
8310 -- If entry not found, add it
8312 if IST_Num > Interrupt_States.Last then
8313 Interrupt_States.Append
8314 ((Interrupt_Number => UI_To_Int (Int_Val),
8315 Interrupt_State => State_Type,
8316 Pragma_Loc => Loc));
8319 -- Case of entry for the same entry
8321 elsif Int_Val = Interrupt_States.Table (IST_Num).
8324 -- If state matches, done, no need to make redundant entry
8327 State_Type = Interrupt_States.Table (IST_Num).
8330 -- Otherwise if state does not match, error
8333 Interrupt_States.Table (IST_Num).Pragma_Loc;
8335 ("state conflicts with that given #", Arg2);
8339 IST_Num := IST_Num + 1;
8341 end Interrupt_State;
8343 ----------------------
8344 -- Java_Constructor --
8345 ----------------------
8347 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
8349 -- Also handles pragma CIL_Constructor
8351 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
8352 Java_Constructor : declare
8356 Convention : Convention_Id;
8360 Check_Arg_Count (1);
8361 Check_Optional_Identifier (Arg1, Name_Entity);
8362 Check_Arg_Is_Local_Name (Arg1);
8364 Id := Expression (Arg1);
8365 Find_Program_Unit_Name (Id);
8367 -- If we did not find the name, we are done
8369 if Etype (Id) = Any_Type then
8374 when Pragma_CIL_Constructor => Convention := Convention_CIL;
8375 when Pragma_Java_Constructor => Convention := Convention_Java;
8376 when others => null;
8379 Hom_Id := Entity (Id);
8381 -- Loop through homonyms
8384 Def_Id := Get_Base_Subprogram (Hom_Id);
8386 -- The constructor is required to be a function returning an
8387 -- access type whose designated type has convention Java/CIL.
8389 if Ekind (Def_Id) = E_Function
8391 (Is_Value_Type (Etype (Def_Id))
8393 (Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
8395 Atree.Convention (Etype (Def_Id)) = Convention)
8397 (Ekind (Etype (Def_Id)) in Access_Kind
8400 (Designated_Type (Etype (Def_Id))) = Convention
8403 (Root_Type (Designated_Type (Etype (Def_Id)))) =
8406 Set_Is_Constructor (Def_Id);
8407 Set_Convention (Def_Id, Convention);
8408 Set_Is_Imported (Def_Id);
8411 if Convention = Convention_Java then
8413 ("pragma% requires function returning a " &
8414 "'Java access type", Arg1);
8416 pragma Assert (Convention = Convention_CIL);
8418 ("pragma% requires function returning a " &
8419 "'C'I'L access type", Arg1);
8423 Hom_Id := Homonym (Hom_Id);
8425 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
8427 end Java_Constructor;
8429 ----------------------
8430 -- Java_Interface --
8431 ----------------------
8433 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
8435 when Pragma_Java_Interface => Java_Interface : declare
8441 Check_Arg_Count (1);
8442 Check_Optional_Identifier (Arg1, Name_Entity);
8443 Check_Arg_Is_Local_Name (Arg1);
8445 Arg := Expression (Arg1);
8448 if Etype (Arg) = Any_Type then
8452 if not Is_Entity_Name (Arg)
8453 or else not Is_Type (Entity (Arg))
8455 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
8458 Typ := Underlying_Type (Entity (Arg));
8460 -- For now simply check some of the semantic constraints on the
8461 -- type. This currently leaves out some restrictions on interface
8462 -- types, namely that the parent type must be java.lang.Object.Typ
8463 -- and that all primitives of the type should be declared
8466 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
8467 Error_Pragma_Arg ("pragma% requires an abstract "
8468 & "tagged type", Arg1);
8470 elsif not Has_Discriminants (Typ)
8471 or else Ekind (Etype (First_Discriminant (Typ)))
8472 /= E_Anonymous_Access_Type
8474 not Is_Class_Wide_Type
8475 (Designated_Type (Etype (First_Discriminant (Typ))))
8478 ("type must have a class-wide access discriminant", Arg1);
8486 -- pragma Keep_Names ([On => ] local_NAME);
8488 when Pragma_Keep_Names => Keep_Names : declare
8493 Check_Arg_Count (1);
8494 Check_Optional_Identifier (Arg1, Name_On);
8495 Check_Arg_Is_Local_Name (Arg1);
8497 Arg := Expression (Arg1);
8500 if Etype (Arg) = Any_Type then
8504 if not Is_Entity_Name (Arg)
8505 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
8508 ("pragma% requires a local enumeration type", Arg1);
8511 Set_Discard_Names (Entity (Arg), False);
8518 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
8520 when Pragma_License =>
8522 Check_Arg_Count (1);
8523 Check_No_Identifiers;
8524 Check_Valid_Configuration_Pragma;
8525 Check_Arg_Is_Identifier (Arg1);
8528 Sind : constant Source_File_Index :=
8529 Source_Index (Current_Sem_Unit);
8532 case Chars (Get_Pragma_Arg (Arg1)) is
8534 Set_License (Sind, GPL);
8536 when Name_Modified_GPL =>
8537 Set_License (Sind, Modified_GPL);
8539 when Name_Restricted =>
8540 Set_License (Sind, Restricted);
8542 when Name_Unrestricted =>
8543 Set_License (Sind, Unrestricted);
8546 Error_Pragma_Arg ("invalid license name", Arg1);
8554 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
8556 when Pragma_Link_With => Link_With : declare
8562 if Operating_Mode = Generate_Code
8563 and then In_Extended_Main_Source_Unit (N)
8565 Check_At_Least_N_Arguments (1);
8566 Check_No_Identifiers;
8567 Check_Is_In_Decl_Part_Or_Package_Spec;
8568 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8572 while Present (Arg) loop
8573 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8575 -- Store argument, converting sequences of spaces to a
8576 -- single null character (this is one of the differences
8577 -- in processing between Link_With and Linker_Options).
8580 C : constant Char_Code := Get_Char_Code (' ');
8581 S : constant String_Id :=
8582 Strval (Expr_Value_S (Expression (Arg)));
8583 L : constant Nat := String_Length (S);
8586 procedure Skip_Spaces;
8587 -- Advance F past any spaces
8593 procedure Skip_Spaces is
8595 while F <= L and then Get_String_Char (S, F) = C loop
8600 -- Start of processing for Arg_Store
8603 Skip_Spaces; -- skip leading spaces
8605 -- Loop through characters, changing any embedded
8606 -- sequence of spaces to a single null character (this
8607 -- is how Link_With/Linker_Options differ)
8610 if Get_String_Char (S, F) = C then
8613 Store_String_Char (ASCII.NUL);
8616 Store_String_Char (Get_String_Char (S, F));
8624 if Present (Arg) then
8625 Store_String_Char (ASCII.NUL);
8629 Store_Linker_Option_String (End_String);
8637 -- pragma Linker_Alias (
8638 -- [Entity =>] LOCAL_NAME
8639 -- [Target =>] static_string_EXPRESSION);
8641 when Pragma_Linker_Alias =>
8643 Check_Arg_Order ((Name_Entity, Name_Target));
8644 Check_Arg_Count (2);
8645 Check_Optional_Identifier (Arg1, Name_Entity);
8646 Check_Optional_Identifier (Arg2, Name_Target);
8647 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8648 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8650 -- The only processing required is to link this item on to the
8651 -- list of rep items for the given entity. This is accomplished
8652 -- by the call to Rep_Item_Too_Late (when no error is detected
8653 -- and False is returned).
8655 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8658 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8661 ------------------------
8662 -- Linker_Constructor --
8663 ------------------------
8665 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
8667 -- Code is shared with Linker_Destructor
8669 -----------------------
8670 -- Linker_Destructor --
8671 -----------------------
8673 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
8675 when Pragma_Linker_Constructor |
8676 Pragma_Linker_Destructor =>
8677 Linker_Constructor : declare
8683 Check_Arg_Count (1);
8684 Check_No_Identifiers;
8685 Check_Arg_Is_Local_Name (Arg1);
8686 Arg1_X := Expression (Arg1);
8688 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
8690 if not Is_Library_Level_Entity (Proc) then
8692 ("argument for pragma% must be library level entity", Arg1);
8695 -- The only processing required is to link this item on to the
8696 -- list of rep items for the given entity. This is accomplished
8697 -- by the call to Rep_Item_Too_Late (when no error is detected
8698 -- and False is returned).
8700 if Rep_Item_Too_Late (Proc, N) then
8703 Set_Has_Gigi_Rep_Item (Proc);
8705 end Linker_Constructor;
8707 --------------------
8708 -- Linker_Options --
8709 --------------------
8711 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
8713 when Pragma_Linker_Options => Linker_Options : declare
8717 Check_Ada_83_Warning;
8718 Check_No_Identifiers;
8719 Check_Arg_Count (1);
8720 Check_Is_In_Decl_Part_Or_Package_Spec;
8721 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8722 Start_String (Strval (Expr_Value_S (Expression (Arg1))));
8725 while Present (Arg) loop
8726 Check_Arg_Is_Static_Expression (Arg, Standard_String);
8727 Store_String_Char (ASCII.NUL);
8728 Store_String_Chars (Strval (Expr_Value_S (Expression (Arg))));
8732 if Operating_Mode = Generate_Code
8733 and then In_Extended_Main_Source_Unit (N)
8735 Store_Linker_Option_String (End_String);
8739 --------------------
8740 -- Linker_Section --
8741 --------------------
8743 -- pragma Linker_Section (
8744 -- [Entity =>] LOCAL_NAME
8745 -- [Section =>] static_string_EXPRESSION);
8747 when Pragma_Linker_Section =>
8749 Check_Arg_Order ((Name_Entity, Name_Section));
8750 Check_Arg_Count (2);
8751 Check_Optional_Identifier (Arg1, Name_Entity);
8752 Check_Optional_Identifier (Arg2, Name_Section);
8753 Check_Arg_Is_Library_Level_Local_Name (Arg1);
8754 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8756 -- This pragma applies only to objects
8758 if not Is_Object (Entity (Expression (Arg1))) then
8759 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
8762 -- The only processing required is to link this item on to the
8763 -- list of rep items for the given entity. This is accomplished
8764 -- by the call to Rep_Item_Too_Late (when no error is detected
8765 -- and False is returned).
8767 if Rep_Item_Too_Late (Entity (Expression (Arg1)), N) then
8770 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8777 -- pragma List (On | Off)
8779 -- There is nothing to do here, since we did all the processing for
8780 -- this pragma in Par.Prag (so that it works properly even in syntax
8786 --------------------
8787 -- Locking_Policy --
8788 --------------------
8790 -- pragma Locking_Policy (policy_IDENTIFIER);
8792 when Pragma_Locking_Policy => declare
8796 Check_Ada_83_Warning;
8797 Check_Arg_Count (1);
8798 Check_No_Identifiers;
8799 Check_Arg_Is_Locking_Policy (Arg1);
8800 Check_Valid_Configuration_Pragma;
8801 Get_Name_String (Chars (Expression (Arg1)));
8802 LP := Fold_Upper (Name_Buffer (1));
8804 if Locking_Policy /= ' '
8805 and then Locking_Policy /= LP
8807 Error_Msg_Sloc := Locking_Policy_Sloc;
8808 Error_Pragma ("locking policy incompatible with policy#");
8810 -- Set new policy, but always preserve System_Location since we
8811 -- like the error message with the run time name.
8814 Locking_Policy := LP;
8816 if Locking_Policy_Sloc /= System_Location then
8817 Locking_Policy_Sloc := Loc;
8826 -- pragma Long_Float (D_Float | G_Float);
8828 when Pragma_Long_Float =>
8830 Check_Valid_Configuration_Pragma;
8831 Check_Arg_Count (1);
8832 Check_No_Identifier (Arg1);
8833 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
8835 if not OpenVMS_On_Target then
8836 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
8841 if Chars (Expression (Arg1)) = Name_D_Float then
8842 if Opt.Float_Format_Long = 'G' then
8843 Error_Pragma ("G_Float previously specified");
8846 Opt.Float_Format_Long := 'D';
8848 -- G_Float case (this is the default, does not need overriding)
8851 if Opt.Float_Format_Long = 'D' then
8852 Error_Pragma ("D_Float previously specified");
8855 Opt.Float_Format_Long := 'G';
8858 Set_Standard_Fpt_Formats;
8860 -----------------------
8861 -- Machine_Attribute --
8862 -----------------------
8864 -- pragma Machine_Attribute (
8865 -- [Entity =>] LOCAL_NAME,
8866 -- [Attribute_Name =>] static_string_EXPRESSION
8867 -- [, [Info =>] static_EXPRESSION] );
8869 when Pragma_Machine_Attribute => Machine_Attribute : declare
8874 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
8876 if Arg_Count = 3 then
8877 Check_Optional_Identifier (Arg3, Name_Info);
8878 Check_Arg_Is_Static_Expression (Arg3);
8880 Check_Arg_Count (2);
8883 Check_Optional_Identifier (Arg1, Name_Entity);
8884 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
8885 Check_Arg_Is_Local_Name (Arg1);
8886 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8887 Def_Id := Entity (Expression (Arg1));
8889 if Is_Access_Type (Def_Id) then
8890 Def_Id := Designated_Type (Def_Id);
8893 if Rep_Item_Too_Early (Def_Id, N) then
8897 Def_Id := Underlying_Type (Def_Id);
8899 -- The only processing required is to link this item on to the
8900 -- list of rep items for the given entity. This is accomplished
8901 -- by the call to Rep_Item_Too_Late (when no error is detected
8902 -- and False is returned).
8904 if Rep_Item_Too_Late (Def_Id, N) then
8907 Set_Has_Gigi_Rep_Item (Entity (Expression (Arg1)));
8909 end Machine_Attribute;
8916 -- (MAIN_OPTION [, MAIN_OPTION]);
8919 -- [STACK_SIZE =>] static_integer_EXPRESSION
8920 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
8921 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
8923 when Pragma_Main => Main : declare
8924 Args : Args_List (1 .. 3);
8925 Names : constant Name_List (1 .. 3) := (
8927 Name_Task_Stack_Size_Default,
8928 Name_Time_Slicing_Enabled);
8934 Gather_Associations (Names, Args);
8936 for J in 1 .. 2 loop
8937 if Present (Args (J)) then
8938 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8942 if Present (Args (3)) then
8943 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
8947 while Present (Nod) loop
8948 if Nkind (Nod) = N_Pragma
8949 and then Pragma_Name (Nod) = Name_Main
8951 Error_Msg_Name_1 := Pname;
8952 Error_Msg_N ("duplicate pragma% not permitted", Nod);
8963 -- pragma Main_Storage
8964 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
8966 -- MAIN_STORAGE_OPTION ::=
8967 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
8968 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
8970 when Pragma_Main_Storage => Main_Storage : declare
8971 Args : Args_List (1 .. 2);
8972 Names : constant Name_List (1 .. 2) := (
8973 Name_Working_Storage,
8980 Gather_Associations (Names, Args);
8982 for J in 1 .. 2 loop
8983 if Present (Args (J)) then
8984 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
8988 Check_In_Main_Program;
8991 while Present (Nod) loop
8992 if Nkind (Nod) = N_Pragma
8993 and then Pragma_Name (Nod) = Name_Main_Storage
8995 Error_Msg_Name_1 := Pname;
8996 Error_Msg_N ("duplicate pragma% not permitted", Nod);
9007 -- pragma Memory_Size (NUMERIC_LITERAL)
9009 when Pragma_Memory_Size =>
9012 -- Memory size is simply ignored
9014 Check_No_Identifiers;
9015 Check_Arg_Count (1);
9016 Check_Arg_Is_Integer_Literal (Arg1);
9024 -- The only correct use of this pragma is on its own in a file, in
9025 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
9026 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
9027 -- check for a file containing nothing but a No_Body pragma). If we
9028 -- attempt to process it during normal semantics processing, it means
9029 -- it was misplaced.
9031 when Pragma_No_Body =>
9039 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
9041 when Pragma_No_Return => No_Return : declare
9049 Check_At_Least_N_Arguments (1);
9051 -- Loop through arguments of pragma
9054 while Present (Arg) loop
9055 Check_Arg_Is_Local_Name (Arg);
9056 Id := Expression (Arg);
9059 if not Is_Entity_Name (Id) then
9060 Error_Pragma_Arg ("entity name required", Arg);
9063 if Etype (Id) = Any_Type then
9067 -- Loop to find matching procedures
9072 and then Scope (E) = Current_Scope
9074 if Ekind (E) = E_Procedure
9075 or else Ekind (E) = E_Generic_Procedure
9079 -- Set flag on any alias as well
9081 if Is_Overloadable (E) and then Present (Alias (E)) then
9082 Set_No_Return (Alias (E));
9092 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
9103 -- pragma No_Run_Time;
9105 -- Note: this pragma is retained for backwards compatibility. See
9106 -- body of Rtsfind for full details on its handling.
9108 when Pragma_No_Run_Time =>
9110 Check_Valid_Configuration_Pragma;
9111 Check_Arg_Count (0);
9113 No_Run_Time_Mode := True;
9114 Configurable_Run_Time_Mode := True;
9116 -- Set Duration to 32 bits if word size is 32
9118 if Ttypes.System_Word_Size = 32 then
9119 Duration_32_Bits_On_Target := True;
9122 -- Set appropriate restrictions
9124 Set_Restriction (No_Finalization, N);
9125 Set_Restriction (No_Exception_Handlers, N);
9126 Set_Restriction (Max_Tasks, N, 0);
9127 Set_Restriction (No_Tasking, N);
9129 ------------------------
9130 -- No_Strict_Aliasing --
9131 ------------------------
9133 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
9135 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
9140 Check_At_Most_N_Arguments (1);
9142 if Arg_Count = 0 then
9143 Check_Valid_Configuration_Pragma;
9144 Opt.No_Strict_Aliasing := True;
9147 Check_Optional_Identifier (Arg2, Name_Entity);
9148 Check_Arg_Is_Local_Name (Arg1);
9149 E_Id := Entity (Expression (Arg1));
9151 if E_Id = Any_Type then
9153 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
9154 Error_Pragma_Arg ("pragma% requires access type", Arg1);
9157 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
9159 end No_Strict_Aliasing;
9161 -----------------------
9162 -- Normalize_Scalars --
9163 -----------------------
9165 -- pragma Normalize_Scalars;
9167 when Pragma_Normalize_Scalars =>
9168 Check_Ada_83_Warning;
9169 Check_Arg_Count (0);
9170 Check_Valid_Configuration_Pragma;
9172 -- Normalize_Scalars creates false positives in CodePeer, so
9173 -- ignore this pragma in this mode.
9175 if not CodePeer_Mode then
9176 Normalize_Scalars := True;
9177 Init_Or_Norm_Scalars := True;
9184 -- pragma Obsolescent;
9186 -- pragma Obsolescent (
9187 -- [Message =>] static_string_EXPRESSION
9188 -- [,[Version =>] Ada_05]]);
9190 -- pragma Obsolescent (
9192 -- [,[Message =>] static_string_EXPRESSION
9193 -- [,[Version =>] Ada_05]] );
9195 when Pragma_Obsolescent => Obsolescent : declare
9199 procedure Set_Obsolescent (E : Entity_Id);
9200 -- Given an entity Ent, mark it as obsolescent if appropriate
9202 ---------------------
9203 -- Set_Obsolescent --
9204 ---------------------
9206 procedure Set_Obsolescent (E : Entity_Id) is
9215 -- Entity name was given
9217 if Present (Ename) then
9219 -- If entity name matches, we are fine. Save entity in
9220 -- pragma argument, for ASIS use.
9222 if Chars (Ename) = Chars (Ent) then
9223 Set_Entity (Ename, Ent);
9224 Generate_Reference (Ent, Ename);
9226 -- If entity name does not match, only possibility is an
9227 -- enumeration literal from an enumeration type declaration.
9229 elsif Ekind (Ent) /= E_Enumeration_Type then
9231 ("pragma % entity name does not match declaration");
9234 Ent := First_Literal (E);
9238 ("pragma % entity name does not match any " &
9239 "enumeration literal");
9241 elsif Chars (Ent) = Chars (Ename) then
9242 Set_Entity (Ename, Ent);
9243 Generate_Reference (Ent, Ename);
9247 Ent := Next_Literal (Ent);
9253 -- Ent points to entity to be marked
9255 if Arg_Count >= 1 then
9257 -- Deal with static string argument
9259 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9260 S := Strval (Expression (Arg1));
9262 for J in 1 .. String_Length (S) loop
9263 if not In_Character_Range (Get_String_Char (S, J)) then
9265 ("pragma% argument does not allow wide characters",
9270 Obsolescent_Warnings.Append
9271 ((Ent => Ent, Msg => Strval (Expression (Arg1))));
9273 -- Check for Ada_05 parameter
9275 if Arg_Count /= 1 then
9276 Check_Arg_Count (2);
9279 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
9282 Check_Arg_Is_Identifier (Argx);
9284 if Chars (Argx) /= Name_Ada_05 then
9285 Error_Msg_Name_2 := Name_Ada_05;
9287 ("only allowed argument for pragma% is %", Argx);
9290 if Ada_Version_Explicit < Ada_05
9291 or else not Warn_On_Ada_2005_Compatibility
9299 -- Set flag if pragma active
9302 Set_Is_Obsolescent (Ent);
9306 end Set_Obsolescent;
9308 -- Start of processing for pragma Obsolescent
9313 Check_At_Most_N_Arguments (3);
9315 -- See if first argument specifies an entity name
9319 (Chars (Arg1) = Name_Entity
9321 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
9325 Ename := Get_Pragma_Arg (Arg1);
9327 -- Eliminate first argument, so we can share processing
9331 Arg_Count := Arg_Count - 1;
9333 -- No Entity name argument given
9339 if Arg_Count >= 1 then
9340 Check_Optional_Identifier (Arg1, Name_Message);
9342 if Arg_Count = 2 then
9343 Check_Optional_Identifier (Arg2, Name_Version);
9347 -- Get immediately preceding declaration
9350 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
9354 -- Cases where we do not follow anything other than another pragma
9358 -- First case: library level compilation unit declaration with
9359 -- the pragma immediately following the declaration.
9361 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
9363 (Defining_Entity (Unit (Parent (Parent (N)))));
9366 -- Case 2: library unit placement for package
9370 Ent : constant Entity_Id := Find_Lib_Unit_Name;
9372 if Is_Package_Or_Generic_Package (Ent) then
9373 Set_Obsolescent (Ent);
9379 -- Cases where we must follow a declaration
9382 if Nkind (Decl) not in N_Declaration
9383 and then Nkind (Decl) not in N_Later_Decl_Item
9384 and then Nkind (Decl) not in N_Generic_Declaration
9385 and then Nkind (Decl) not in N_Renaming_Declaration
9388 ("pragma% misplaced, "
9389 & "must immediately follow a declaration");
9392 Set_Obsolescent (Defining_Entity (Decl));
9402 -- pragma Optimize (Time | Space | Off);
9404 -- The actual check for optimize is done in Gigi. Note that this
9405 -- pragma does not actually change the optimization setting, it
9406 -- simply checks that it is consistent with the pragma.
9408 when Pragma_Optimize =>
9409 Check_No_Identifiers;
9410 Check_Arg_Count (1);
9411 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
9413 ------------------------
9414 -- Optimize_Alignment --
9415 ------------------------
9417 -- pragma Optimize_Alignment (Time | Space | Off);
9419 when Pragma_Optimize_Alignment =>
9421 Check_No_Identifiers;
9422 Check_Arg_Count (1);
9423 Check_Valid_Configuration_Pragma;
9426 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9430 Opt.Optimize_Alignment := 'T';
9432 Opt.Optimize_Alignment := 'S';
9434 Opt.Optimize_Alignment := 'O';
9436 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
9440 -- Set indication that mode is set locally. If we are in fact in a
9441 -- configuration pragma file, this setting is harmless since the
9442 -- switch will get reset anyway at the start of each unit.
9444 Optimize_Alignment_Local := True;
9450 -- pragma Pack (first_subtype_LOCAL_NAME);
9452 when Pragma_Pack => Pack : declare
9453 Assoc : constant Node_Id := Arg1;
9458 Check_No_Identifiers;
9459 Check_Arg_Count (1);
9460 Check_Arg_Is_Local_Name (Arg1);
9462 Type_Id := Expression (Assoc);
9463 Find_Type (Type_Id);
9464 Typ := Entity (Type_Id);
9467 or else Rep_Item_Too_Early (Typ, N)
9471 Typ := Underlying_Type (Typ);
9474 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
9475 Error_Pragma ("pragma% must specify array or record type");
9478 Check_First_Subtype (Arg1);
9480 if Has_Pragma_Pack (Typ) then
9481 Error_Pragma ("duplicate pragma%, only one allowed");
9485 elsif Is_Array_Type (Typ) then
9487 -- Pack not allowed for aliased or atomic components
9489 if Has_Aliased_Components (Base_Type (Typ)) then
9491 ("pragma% ignored, cannot pack aliased components?");
9493 elsif Has_Atomic_Components (Typ)
9494 or else Is_Atomic (Component_Type (Typ))
9497 ("?pragma% ignored, cannot pack atomic components");
9500 -- If we had an explicit component size given, then we do not
9501 -- let Pack override this given size. We also give a warning
9502 -- that Pack is being ignored unless we can tell for sure that
9503 -- the Pack would not have had any effect anyway.
9505 if Has_Component_Size_Clause (Typ) then
9506 if Known_Static_RM_Size (Component_Type (Typ))
9508 RM_Size (Component_Type (Typ)) = Component_Size (Typ)
9513 ("?pragma% ignored, explicit component size given");
9516 -- If no prior array component size given, Pack is effective
9519 if not Rep_Item_Too_Late (Typ, N) then
9521 -- In the context of static code analysis, we do not need
9522 -- complex front-end expansions related to pragma Pack,
9523 -- so disable handling of pragma Pack in this case.
9525 if CodePeer_Mode then
9528 -- For normal non-VM target, do the packing
9530 elsif VM_Target = No_VM then
9531 Set_Is_Packed (Base_Type (Typ));
9532 Set_Has_Pragma_Pack (Base_Type (Typ));
9533 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9535 -- If we ignore the pack, then warn about this, except
9536 -- that we suppress the warning in GNAT mode.
9538 elsif not GNAT_Mode then
9540 ("?pragma% ignored in this configuration");
9545 -- For record types, the pack is always effective
9547 else pragma Assert (Is_Record_Type (Typ));
9548 if not Rep_Item_Too_Late (Typ, N) then
9549 if VM_Target = No_VM then
9550 Set_Is_Packed (Base_Type (Typ));
9551 Set_Has_Pragma_Pack (Base_Type (Typ));
9552 Set_Has_Non_Standard_Rep (Base_Type (Typ));
9554 elsif not GNAT_Mode then
9555 Error_Pragma ("?pragma% ignored in this configuration");
9567 -- There is nothing to do here, since we did all the processing for
9568 -- this pragma in Par.Prag (so that it works properly even in syntax
9578 -- pragma Passive [(PASSIVE_FORM)];
9580 -- PASSIVE_FORM ::= Semaphore | No
9582 when Pragma_Passive =>
9585 if Nkind (Parent (N)) /= N_Task_Definition then
9586 Error_Pragma ("pragma% must be within task definition");
9589 if Arg_Count /= 0 then
9590 Check_Arg_Count (1);
9591 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
9594 ----------------------------------
9595 -- Preelaborable_Initialization --
9596 ----------------------------------
9598 -- pragma Preelaborable_Initialization (DIRECT_NAME);
9600 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
9605 Check_Arg_Count (1);
9606 Check_No_Identifiers;
9607 Check_Arg_Is_Identifier (Arg1);
9608 Check_Arg_Is_Local_Name (Arg1);
9609 Check_First_Subtype (Arg1);
9610 Ent := Entity (Expression (Arg1));
9612 if not Is_Private_Type (Ent)
9613 and then not Is_Protected_Type (Ent)
9616 ("pragma % can only be applied to private or protected type",
9620 -- Give an error if the pragma is applied to a protected type that
9621 -- does not qualify (due to having entries, or due to components
9622 -- that do not qualify).
9624 if Is_Protected_Type (Ent)
9625 and then not Has_Preelaborable_Initialization (Ent)
9628 ("protected type & does not have preelaborable " &
9629 "initialization", Ent);
9631 -- Otherwise mark the type as definitely having preelaborable
9635 Set_Known_To_Have_Preelab_Init (Ent);
9638 if Has_Pragma_Preelab_Init (Ent)
9639 and then Warn_On_Redundant_Constructs
9641 Error_Pragma ("?duplicate pragma%!");
9643 Set_Has_Pragma_Preelab_Init (Ent);
9647 --------------------
9648 -- Persistent_BSS --
9649 --------------------
9651 when Pragma_Persistent_BSS => Persistent_BSS : declare
9658 Check_At_Most_N_Arguments (1);
9660 -- Case of application to specific object (one argument)
9662 if Arg_Count = 1 then
9663 Check_Arg_Is_Library_Level_Local_Name (Arg1);
9665 if not Is_Entity_Name (Expression (Arg1))
9667 (Ekind (Entity (Expression (Arg1))) /= E_Variable
9668 and then Ekind (Entity (Expression (Arg1))) /= E_Constant)
9670 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
9673 Ent := Entity (Expression (Arg1));
9674 Decl := Parent (Ent);
9676 if Rep_Item_Too_Late (Ent, N) then
9680 if Present (Expression (Decl)) then
9682 ("object for pragma% cannot have initialization", Arg1);
9685 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
9687 ("object type for pragma% is not potentially persistent",
9692 Make_Linker_Section_Pragma
9693 (Ent, Sloc (N), ".persistent.bss");
9694 Insert_After (N, Prag);
9697 -- Case of use as configuration pragma with no arguments
9700 Check_Valid_Configuration_Pragma;
9701 Persistent_BSS_Mode := True;
9709 -- pragma Polling (ON | OFF);
9711 when Pragma_Polling =>
9713 Check_Arg_Count (1);
9714 Check_No_Identifiers;
9715 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9716 Polling_Required := (Chars (Expression (Arg1)) = Name_On);
9722 -- pragma Postcondition ([Check =>] Boolean_Expression
9723 -- [,[Message =>] String_Expression]);
9725 when Pragma_Postcondition => Postcondition : declare
9727 pragma Warnings (Off, In_Body);
9731 Check_At_Least_N_Arguments (1);
9732 Check_At_Most_N_Arguments (2);
9733 Check_Optional_Identifier (Arg1, Name_Check);
9735 -- All we need to do here is call the common check procedure,
9736 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
9738 Check_Precondition_Postcondition (In_Body);
9745 -- pragma Precondition ([Check =>] Boolean_Expression
9746 -- [,[Message =>] String_Expression]);
9748 when Pragma_Precondition => Precondition : declare
9753 Check_At_Least_N_Arguments (1);
9754 Check_At_Most_N_Arguments (2);
9755 Check_Optional_Identifier (Arg1, Name_Check);
9757 Check_Precondition_Postcondition (In_Body);
9759 -- If in spec, nothing more to do. If in body, then we convert the
9760 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
9761 -- this whether or not precondition checks are enabled. That works
9762 -- fine since pragma Check will do this check, and will also
9763 -- analyze the condition itself in the proper context.
9766 if Arg_Count = 2 then
9767 Check_Optional_Identifier (Arg3, Name_Message);
9768 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
9773 Chars => Name_Check,
9774 Pragma_Argument_Associations => New_List (
9775 Make_Pragma_Argument_Association (Loc,
9777 Make_Identifier (Loc,
9778 Chars => Name_Precondition)),
9780 Make_Pragma_Argument_Association (Sloc (Arg1),
9781 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
9783 if Arg_Count = 2 then
9784 Append_To (Pragma_Argument_Associations (N),
9785 Make_Pragma_Argument_Association (Sloc (Arg2),
9786 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
9797 -- pragma Preelaborate [(library_unit_NAME)];
9799 -- Set the flag Is_Preelaborated of program unit name entity
9801 when Pragma_Preelaborate => Preelaborate : declare
9802 Pa : constant Node_Id := Parent (N);
9803 Pk : constant Node_Kind := Nkind (Pa);
9807 Check_Ada_83_Warning;
9808 Check_Valid_Library_Unit_Pragma;
9810 if Nkind (N) = N_Null_Statement then
9814 Ent := Find_Lib_Unit_Name;
9816 -- This filters out pragmas inside generic parent then
9817 -- show up inside instantiation
9820 and then not (Pk = N_Package_Specification
9821 and then Present (Generic_Parent (Pa)))
9823 if not Debug_Flag_U then
9824 Set_Is_Preelaborated (Ent);
9825 Set_Suppress_Elaboration_Warnings (Ent);
9830 ---------------------
9831 -- Preelaborate_05 --
9832 ---------------------
9834 -- pragma Preelaborate_05 [(library_unit_NAME)];
9836 -- This pragma is useable only in GNAT_Mode, where it is used like
9837 -- pragma Preelaborate but it is only effective in Ada 2005 mode
9838 -- (otherwise it is ignored). This is used to implement AI-362 which
9839 -- recategorizes some run-time packages in Ada 2005 mode.
9841 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
9846 Check_Valid_Library_Unit_Pragma;
9848 if not GNAT_Mode then
9849 Error_Pragma ("pragma% only available in GNAT mode");
9852 if Nkind (N) = N_Null_Statement then
9856 -- This is one of the few cases where we need to test the value of
9857 -- Ada_Version_Explicit rather than Ada_Version (which is always
9858 -- set to Ada_05 in a predefined unit), we need to know the
9859 -- explicit version set to know if this pragma is active.
9861 if Ada_Version_Explicit >= Ada_05 then
9862 Ent := Find_Lib_Unit_Name;
9863 Set_Is_Preelaborated (Ent);
9864 Set_Suppress_Elaboration_Warnings (Ent);
9866 end Preelaborate_05;
9872 -- pragma Priority (EXPRESSION);
9874 when Pragma_Priority => Priority : declare
9875 P : constant Node_Id := Parent (N);
9879 Check_No_Identifiers;
9880 Check_Arg_Count (1);
9884 if Nkind (P) = N_Subprogram_Body then
9885 Check_In_Main_Program;
9887 Arg := Expression (Arg1);
9888 Analyze_And_Resolve (Arg, Standard_Integer);
9892 if not Is_Static_Expression (Arg) then
9893 Flag_Non_Static_Expr
9894 ("main subprogram priority is not static!", Arg);
9897 -- If constraint error, then we already signalled an error
9899 elsif Raises_Constraint_Error (Arg) then
9902 -- Otherwise check in range
9906 Val : constant Uint := Expr_Value (Arg);
9910 or else Val > Expr_Value (Expression
9911 (Parent (RTE (RE_Max_Priority))))
9914 ("main subprogram priority is out of range", Arg1);
9920 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
9922 -- Load an arbitrary entity from System.Tasking to make sure
9923 -- this package is implicitly with'ed, since we need to have
9924 -- the tasking run-time active for the pragma Priority to have
9928 Discard : Entity_Id;
9929 pragma Warnings (Off, Discard);
9931 Discard := RTE (RE_Task_List);
9934 -- Task or Protected, must be of type Integer
9936 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9937 Arg := Expression (Arg1);
9939 -- The expression must be analyzed in the special manner
9940 -- described in "Handling of Default and Per-Object
9941 -- Expressions" in sem.ads.
9943 Preanalyze_Spec_Expression (Arg, Standard_Integer);
9945 if not Is_Static_Expression (Arg) then
9946 Check_Restriction (Static_Priorities, Arg);
9949 -- Anything else is incorrect
9955 if Has_Priority_Pragma (P) then
9956 Error_Pragma ("duplicate pragma% not allowed");
9958 Set_Has_Priority_Pragma (P, True);
9960 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
9961 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9962 -- exp_ch9 should use this ???
9967 -----------------------------------
9968 -- Priority_Specific_Dispatching --
9969 -----------------------------------
9971 -- pragma Priority_Specific_Dispatching (
9972 -- policy_IDENTIFIER,
9973 -- first_priority_EXPRESSION,
9974 -- last_priority_EXPRESSION);
9976 when Pragma_Priority_Specific_Dispatching =>
9977 Priority_Specific_Dispatching : declare
9978 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
9979 -- This is the entity System.Any_Priority;
9982 Lower_Bound : Node_Id;
9983 Upper_Bound : Node_Id;
9989 Check_Arg_Count (3);
9990 Check_No_Identifiers;
9991 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
9992 Check_Valid_Configuration_Pragma;
9993 Get_Name_String (Chars (Expression (Arg1)));
9994 DP := Fold_Upper (Name_Buffer (1));
9996 Lower_Bound := Expression (Arg2);
9997 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
9998 Lower_Val := Expr_Value (Lower_Bound);
10000 Upper_Bound := Expression (Arg3);
10001 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
10002 Upper_Val := Expr_Value (Upper_Bound);
10004 -- It is not allowed to use Task_Dispatching_Policy and
10005 -- Priority_Specific_Dispatching in the same partition.
10007 if Task_Dispatching_Policy /= ' ' then
10008 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10010 ("pragma% incompatible with Task_Dispatching_Policy#");
10012 -- Check lower bound in range
10014 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10016 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
10019 ("first_priority is out of range", Arg2);
10021 -- Check upper bound in range
10023 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
10025 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
10028 ("last_priority is out of range", Arg3);
10030 -- Check that the priority range is valid
10032 elsif Lower_Val > Upper_Val then
10034 ("last_priority_expression must be greater than" &
10035 " or equal to first_priority_expression");
10037 -- Store the new policy, but always preserve System_Location since
10038 -- we like the error message with the run-time name.
10041 -- Check overlapping in the priority ranges specified in other
10042 -- Priority_Specific_Dispatching pragmas within the same
10043 -- partition. We can only check those we know about!
10046 Specific_Dispatching.First .. Specific_Dispatching.Last
10048 if Specific_Dispatching.Table (J).First_Priority in
10049 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10050 or else Specific_Dispatching.Table (J).Last_Priority in
10051 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
10054 Specific_Dispatching.Table (J).Pragma_Loc;
10056 ("priority range overlaps with "
10057 & "Priority_Specific_Dispatching#");
10061 -- The use of Priority_Specific_Dispatching is incompatible
10062 -- with Task_Dispatching_Policy.
10064 if Task_Dispatching_Policy /= ' ' then
10065 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
10067 ("Priority_Specific_Dispatching incompatible "
10068 & "with Task_Dispatching_Policy#");
10071 -- The use of Priority_Specific_Dispatching forces ceiling
10074 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
10075 Error_Msg_Sloc := Locking_Policy_Sloc;
10077 ("Priority_Specific_Dispatching incompatible "
10078 & "with Locking_Policy#");
10080 -- Set the Ceiling_Locking policy, but preserve System_Location
10081 -- since we like the error message with the run time name.
10084 Locking_Policy := 'C';
10086 if Locking_Policy_Sloc /= System_Location then
10087 Locking_Policy_Sloc := Loc;
10091 -- Add entry in the table
10093 Specific_Dispatching.Append
10094 ((Dispatching_Policy => DP,
10095 First_Priority => UI_To_Int (Lower_Val),
10096 Last_Priority => UI_To_Int (Upper_Val),
10097 Pragma_Loc => Loc));
10099 end Priority_Specific_Dispatching;
10105 -- pragma Profile (profile_IDENTIFIER);
10107 -- profile_IDENTIFIER => Restricted | Ravenscar
10109 when Pragma_Profile =>
10111 Check_Arg_Count (1);
10112 Check_Valid_Configuration_Pragma;
10113 Check_No_Identifiers;
10116 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10118 if Chars (Argx) = Name_Ravenscar then
10119 Set_Ravenscar_Profile (N);
10120 elsif Chars (Argx) = Name_Restricted then
10121 Set_Profile_Restrictions
10122 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10124 Error_Pragma_Arg ("& is not a valid profile", Argx);
10128 ----------------------
10129 -- Profile_Warnings --
10130 ----------------------
10132 -- pragma Profile_Warnings (profile_IDENTIFIER);
10134 -- profile_IDENTIFIER => Restricted | Ravenscar
10136 when Pragma_Profile_Warnings =>
10138 Check_Arg_Count (1);
10139 Check_Valid_Configuration_Pragma;
10140 Check_No_Identifiers;
10143 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
10145 if Chars (Argx) = Name_Ravenscar then
10146 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
10147 elsif Chars (Argx) = Name_Restricted then
10148 Set_Profile_Restrictions (Restricted, N, Warn => True);
10150 Error_Pragma_Arg ("& is not a valid profile", Argx);
10154 --------------------------
10155 -- Propagate_Exceptions --
10156 --------------------------
10158 -- pragma Propagate_Exceptions;
10160 -- Note: this pragma is obsolete and has no effect
10162 when Pragma_Propagate_Exceptions =>
10164 Check_Arg_Count (0);
10166 if In_Extended_Main_Source_Unit (N) then
10167 Propagate_Exceptions := True;
10174 -- pragma Psect_Object (
10175 -- [Internal =>] LOCAL_NAME,
10176 -- [, [External =>] EXTERNAL_SYMBOL]
10177 -- [, [Size =>] EXTERNAL_SYMBOL]);
10179 when Pragma_Psect_Object | Pragma_Common_Object =>
10180 Psect_Object : declare
10181 Args : Args_List (1 .. 3);
10182 Names : constant Name_List (1 .. 3) := (
10187 Internal : Node_Id renames Args (1);
10188 External : Node_Id renames Args (2);
10189 Size : Node_Id renames Args (3);
10191 Def_Id : Entity_Id;
10193 procedure Check_Too_Long (Arg : Node_Id);
10194 -- Posts message if the argument is an identifier with more
10195 -- than 31 characters, or a string literal with more than
10196 -- 31 characters, and we are operating under VMS
10198 --------------------
10199 -- Check_Too_Long --
10200 --------------------
10202 procedure Check_Too_Long (Arg : Node_Id) is
10203 X : constant Node_Id := Original_Node (Arg);
10206 if not Nkind_In (X, N_String_Literal, N_Identifier) then
10208 ("inappropriate argument for pragma %", Arg);
10211 if OpenVMS_On_Target then
10212 if (Nkind (X) = N_String_Literal
10213 and then String_Length (Strval (X)) > 31)
10215 (Nkind (X) = N_Identifier
10216 and then Length_Of_Name (Chars (X)) > 31)
10219 ("argument for pragma % is longer than 31 characters",
10223 end Check_Too_Long;
10225 -- Start of processing for Common_Object/Psect_Object
10229 Gather_Associations (Names, Args);
10230 Process_Extended_Import_Export_Internal_Arg (Internal);
10232 Def_Id := Entity (Internal);
10234 if Ekind (Def_Id) /= E_Constant
10235 and then Ekind (Def_Id) /= E_Variable
10238 ("pragma% must designate an object", Internal);
10241 Check_Too_Long (Internal);
10243 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
10245 ("cannot use pragma% for imported/exported object",
10249 if Is_Concurrent_Type (Etype (Internal)) then
10251 ("cannot specify pragma % for task/protected object",
10255 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
10257 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
10259 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
10262 if Ekind (Def_Id) = E_Constant then
10264 ("cannot specify pragma % for a constant", Internal);
10267 if Is_Record_Type (Etype (Internal)) then
10273 Ent := First_Entity (Etype (Internal));
10274 while Present (Ent) loop
10275 Decl := Declaration_Node (Ent);
10277 if Ekind (Ent) = E_Component
10278 and then Nkind (Decl) = N_Component_Declaration
10279 and then Present (Expression (Decl))
10280 and then Warn_On_Export_Import
10283 ("?object for pragma % has defaults", Internal);
10293 if Present (Size) then
10294 Check_Too_Long (Size);
10297 if Present (External) then
10298 Check_Arg_Is_External_Name (External);
10299 Check_Too_Long (External);
10302 -- If all error tests pass, link pragma on to the rep item chain
10304 Record_Rep_Item (Def_Id, N);
10311 -- pragma Pure [(library_unit_NAME)];
10313 when Pragma_Pure => Pure : declare
10317 Check_Ada_83_Warning;
10318 Check_Valid_Library_Unit_Pragma;
10320 if Nkind (N) = N_Null_Statement then
10324 Ent := Find_Lib_Unit_Name;
10326 Set_Has_Pragma_Pure (Ent);
10327 Set_Suppress_Elaboration_Warnings (Ent);
10334 -- pragma Pure_05 [(library_unit_NAME)];
10336 -- This pragma is useable only in GNAT_Mode, where it is used like
10337 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
10338 -- it is ignored). It may be used after a pragma Preelaborate, in
10339 -- which case it overrides the effect of the pragma Preelaborate.
10340 -- This is used to implement AI-362 which recategorizes some run-time
10341 -- packages in Ada 2005 mode.
10343 when Pragma_Pure_05 => Pure_05 : declare
10348 Check_Valid_Library_Unit_Pragma;
10350 if not GNAT_Mode then
10351 Error_Pragma ("pragma% only available in GNAT mode");
10354 if Nkind (N) = N_Null_Statement then
10358 -- This is one of the few cases where we need to test the value of
10359 -- Ada_Version_Explicit rather than Ada_Version (which is always
10360 -- set to Ada_05 in a predefined unit), we need to know the
10361 -- explicit version set to know if this pragma is active.
10363 if Ada_Version_Explicit >= Ada_05 then
10364 Ent := Find_Lib_Unit_Name;
10365 Set_Is_Preelaborated (Ent, False);
10367 Set_Suppress_Elaboration_Warnings (Ent);
10371 -------------------
10372 -- Pure_Function --
10373 -------------------
10375 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
10377 when Pragma_Pure_Function => Pure_Function : declare
10380 Def_Id : Entity_Id;
10381 Effective : Boolean := False;
10385 Check_Arg_Count (1);
10386 Check_Optional_Identifier (Arg1, Name_Entity);
10387 Check_Arg_Is_Local_Name (Arg1);
10388 E_Id := Expression (Arg1);
10390 if Error_Posted (E_Id) then
10394 -- Loop through homonyms (overloadings) of referenced entity
10396 E := Entity (E_Id);
10398 if Present (E) then
10400 Def_Id := Get_Base_Subprogram (E);
10402 if Ekind (Def_Id) /= E_Function
10403 and then Ekind (Def_Id) /= E_Generic_Function
10404 and then Ekind (Def_Id) /= E_Operator
10407 ("pragma% requires a function name", Arg1);
10410 Set_Is_Pure (Def_Id);
10412 if not Has_Pragma_Pure_Function (Def_Id) then
10413 Set_Has_Pragma_Pure_Function (Def_Id);
10418 exit when No (E) or else Scope (E) /= Current_Scope;
10422 and then Warn_On_Redundant_Constructs
10424 Error_Msg_NE ("pragma Pure_Function on& is redundant?",
10430 --------------------
10431 -- Queuing_Policy --
10432 --------------------
10434 -- pragma Queuing_Policy (policy_IDENTIFIER);
10436 when Pragma_Queuing_Policy => declare
10440 Check_Ada_83_Warning;
10441 Check_Arg_Count (1);
10442 Check_No_Identifiers;
10443 Check_Arg_Is_Queuing_Policy (Arg1);
10444 Check_Valid_Configuration_Pragma;
10445 Get_Name_String (Chars (Expression (Arg1)));
10446 QP := Fold_Upper (Name_Buffer (1));
10448 if Queuing_Policy /= ' '
10449 and then Queuing_Policy /= QP
10451 Error_Msg_Sloc := Queuing_Policy_Sloc;
10452 Error_Pragma ("queuing policy incompatible with policy#");
10454 -- Set new policy, but always preserve System_Location since we
10455 -- like the error message with the run time name.
10458 Queuing_Policy := QP;
10460 if Queuing_Policy_Sloc /= System_Location then
10461 Queuing_Policy_Sloc := Loc;
10466 -----------------------
10467 -- Relative_Deadline --
10468 -----------------------
10470 -- pragma Relative_Deadline (time_span_EXPRESSION);
10472 when Pragma_Relative_Deadline => Relative_Deadline : declare
10473 P : constant Node_Id := Parent (N);
10478 Check_No_Identifiers;
10479 Check_Arg_Count (1);
10481 Arg := Expression (Arg1);
10483 -- The expression must be analyzed in the special manner described
10484 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
10486 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
10490 if Nkind (P) = N_Subprogram_Body then
10491 Check_In_Main_Program;
10495 elsif Nkind (P) = N_Task_Definition then
10498 -- Anything else is incorrect
10504 if Has_Relative_Deadline_Pragma (P) then
10505 Error_Pragma ("duplicate pragma% not allowed");
10507 Set_Has_Relative_Deadline_Pragma (P, True);
10509 if Nkind (P) = N_Task_Definition then
10510 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10513 end Relative_Deadline;
10515 ---------------------------
10516 -- Remote_Call_Interface --
10517 ---------------------------
10519 -- pragma Remote_Call_Interface [(library_unit_NAME)];
10521 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
10522 Cunit_Node : Node_Id;
10523 Cunit_Ent : Entity_Id;
10527 Check_Ada_83_Warning;
10528 Check_Valid_Library_Unit_Pragma;
10530 if Nkind (N) = N_Null_Statement then
10534 Cunit_Node := Cunit (Current_Sem_Unit);
10535 K := Nkind (Unit (Cunit_Node));
10536 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10538 if K = N_Package_Declaration
10539 or else K = N_Generic_Package_Declaration
10540 or else K = N_Subprogram_Declaration
10541 or else K = N_Generic_Subprogram_Declaration
10542 or else (K = N_Subprogram_Body
10543 and then Acts_As_Spec (Unit (Cunit_Node)))
10548 "pragma% must apply to package or subprogram declaration");
10551 Set_Is_Remote_Call_Interface (Cunit_Ent);
10552 end Remote_Call_Interface;
10558 -- pragma Remote_Types [(library_unit_NAME)];
10560 when Pragma_Remote_Types => Remote_Types : declare
10561 Cunit_Node : Node_Id;
10562 Cunit_Ent : Entity_Id;
10565 Check_Ada_83_Warning;
10566 Check_Valid_Library_Unit_Pragma;
10568 if Nkind (N) = N_Null_Statement then
10572 Cunit_Node := Cunit (Current_Sem_Unit);
10573 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10575 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10576 N_Generic_Package_Declaration)
10579 ("pragma% can only apply to a package declaration");
10582 Set_Is_Remote_Types (Cunit_Ent);
10589 -- pragma Ravenscar;
10591 when Pragma_Ravenscar =>
10593 Check_Arg_Count (0);
10594 Check_Valid_Configuration_Pragma;
10595 Set_Ravenscar_Profile (N);
10597 if Warn_On_Obsolescent_Feature then
10599 ("pragma Ravenscar is an obsolescent feature?", N);
10601 ("|use pragma Profile (Ravenscar) instead", N);
10604 -------------------------
10605 -- Restricted_Run_Time --
10606 -------------------------
10608 -- pragma Restricted_Run_Time;
10610 when Pragma_Restricted_Run_Time =>
10612 Check_Arg_Count (0);
10613 Check_Valid_Configuration_Pragma;
10614 Set_Profile_Restrictions
10615 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
10617 if Warn_On_Obsolescent_Feature then
10619 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
10621 ("|use pragma Profile (Restricted) instead", N);
10628 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
10631 -- restriction_IDENTIFIER
10632 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10634 when Pragma_Restrictions =>
10635 Process_Restrictions_Or_Restriction_Warnings
10636 (Warn => Treat_Restrictions_As_Warnings);
10638 --------------------------
10639 -- Restriction_Warnings --
10640 --------------------------
10642 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
10645 -- restriction_IDENTIFIER
10646 -- | restriction_parameter_IDENTIFIER => EXPRESSION
10648 when Pragma_Restriction_Warnings =>
10650 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
10656 -- pragma Reviewable;
10658 when Pragma_Reviewable =>
10659 Check_Ada_83_Warning;
10660 Check_Arg_Count (0);
10663 -------------------
10664 -- Share_Generic --
10665 -------------------
10667 -- pragma Share_Generic (NAME {, NAME});
10669 when Pragma_Share_Generic =>
10671 Process_Generic_List;
10677 -- pragma Shared (LOCAL_NAME);
10679 when Pragma_Shared =>
10681 Process_Atomic_Shared_Volatile;
10683 --------------------
10684 -- Shared_Passive --
10685 --------------------
10687 -- pragma Shared_Passive [(library_unit_NAME)];
10689 -- Set the flag Is_Shared_Passive of program unit name entity
10691 when Pragma_Shared_Passive => Shared_Passive : declare
10692 Cunit_Node : Node_Id;
10693 Cunit_Ent : Entity_Id;
10696 Check_Ada_83_Warning;
10697 Check_Valid_Library_Unit_Pragma;
10699 if Nkind (N) = N_Null_Statement then
10703 Cunit_Node := Cunit (Current_Sem_Unit);
10704 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
10706 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
10707 N_Generic_Package_Declaration)
10710 ("pragma% can only apply to a package declaration");
10713 Set_Is_Shared_Passive (Cunit_Ent);
10714 end Shared_Passive;
10716 ----------------------
10717 -- Source_File_Name --
10718 ----------------------
10720 -- There are five forms for this pragma:
10722 -- pragma Source_File_Name (
10723 -- [UNIT_NAME =>] unit_NAME,
10724 -- BODY_FILE_NAME => STRING_LITERAL
10725 -- [, [INDEX =>] INTEGER_LITERAL]);
10727 -- pragma Source_File_Name (
10728 -- [UNIT_NAME =>] unit_NAME,
10729 -- SPEC_FILE_NAME => STRING_LITERAL
10730 -- [, [INDEX =>] INTEGER_LITERAL]);
10732 -- pragma Source_File_Name (
10733 -- BODY_FILE_NAME => STRING_LITERAL
10734 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10735 -- [, CASING => CASING_SPEC]);
10737 -- pragma Source_File_Name (
10738 -- SPEC_FILE_NAME => STRING_LITERAL
10739 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10740 -- [, CASING => CASING_SPEC]);
10742 -- pragma Source_File_Name (
10743 -- SUBUNIT_FILE_NAME => STRING_LITERAL
10744 -- [, DOT_REPLACEMENT => STRING_LITERAL]
10745 -- [, CASING => CASING_SPEC]);
10747 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
10749 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
10750 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
10751 -- only be used when no project file is used, while SFNP can only be
10752 -- used when a project file is used.
10754 -- No processing here. Processing was completed during parsing, since
10755 -- we need to have file names set as early as possible. Units are
10756 -- loaded well before semantic processing starts.
10758 -- The only processing we defer to this point is the check for
10759 -- correct placement.
10761 when Pragma_Source_File_Name =>
10763 Check_Valid_Configuration_Pragma;
10765 ------------------------------
10766 -- Source_File_Name_Project --
10767 ------------------------------
10769 -- See Source_File_Name for syntax
10771 -- No processing here. Processing was completed during parsing, since
10772 -- we need to have file names set as early as possible. Units are
10773 -- loaded well before semantic processing starts.
10775 -- The only processing we defer to this point is the check for
10776 -- correct placement.
10778 when Pragma_Source_File_Name_Project =>
10780 Check_Valid_Configuration_Pragma;
10782 -- Check that a pragma Source_File_Name_Project is used only in a
10783 -- configuration pragmas file.
10785 -- Pragmas Source_File_Name_Project should only be generated by
10786 -- the Project Manager in configuration pragmas files.
10788 -- This is really an ugly test. It seems to depend on some
10789 -- accidental and undocumented property. At the very least it
10790 -- needs to be documented, but it would be better to have a
10791 -- clean way of testing if we are in a configuration file???
10793 if Present (Parent (N)) then
10795 ("pragma% can only appear in a configuration pragmas file");
10798 ----------------------
10799 -- Source_Reference --
10800 ----------------------
10802 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
10804 -- Nothing to do, all processing completed in Par.Prag, since we need
10805 -- the information for possible parser messages that are output.
10807 when Pragma_Source_Reference =>
10810 --------------------------------
10811 -- Static_Elaboration_Desired --
10812 --------------------------------
10814 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
10816 when Pragma_Static_Elaboration_Desired =>
10818 Check_At_Most_N_Arguments (1);
10820 if Is_Compilation_Unit (Current_Scope)
10821 and then Ekind (Current_Scope) = E_Package
10823 Set_Static_Elaboration_Desired (Current_Scope, True);
10825 Error_Pragma ("pragma% must apply to a library-level package");
10832 -- pragma Storage_Size (EXPRESSION);
10834 when Pragma_Storage_Size => Storage_Size : declare
10835 P : constant Node_Id := Parent (N);
10839 Check_No_Identifiers;
10840 Check_Arg_Count (1);
10842 -- The expression must be analyzed in the special manner described
10843 -- in "Handling of Default Expressions" in sem.ads.
10845 Arg := Expression (Arg1);
10846 Preanalyze_Spec_Expression (Arg, Any_Integer);
10848 if not Is_Static_Expression (Arg) then
10849 Check_Restriction (Static_Storage_Size, Arg);
10852 if Nkind (P) /= N_Task_Definition then
10857 if Has_Storage_Size_Pragma (P) then
10858 Error_Pragma ("duplicate pragma% not allowed");
10860 Set_Has_Storage_Size_Pragma (P, True);
10863 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10864 -- ??? exp_ch9 should use this!
10872 -- pragma Storage_Unit (NUMERIC_LITERAL);
10874 -- Only permitted argument is System'Storage_Unit value
10876 when Pragma_Storage_Unit =>
10877 Check_No_Identifiers;
10878 Check_Arg_Count (1);
10879 Check_Arg_Is_Integer_Literal (Arg1);
10881 if Intval (Expression (Arg1)) /=
10882 UI_From_Int (Ttypes.System_Storage_Unit)
10884 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
10886 ("the only allowed argument for pragma% is ^", Arg1);
10889 --------------------
10890 -- Stream_Convert --
10891 --------------------
10893 -- pragma Stream_Convert (
10894 -- [Entity =>] type_LOCAL_NAME,
10895 -- [Read =>] function_NAME,
10896 -- [Write =>] function NAME);
10898 when Pragma_Stream_Convert => Stream_Convert : declare
10900 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
10901 -- Check that the given argument is the name of a local function
10902 -- of one argument that is not overloaded earlier in the current
10903 -- local scope. A check is also made that the argument is a
10904 -- function with one parameter.
10906 --------------------------------------
10907 -- Check_OK_Stream_Convert_Function --
10908 --------------------------------------
10910 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
10914 Check_Arg_Is_Local_Name (Arg);
10915 Ent := Entity (Expression (Arg));
10917 if Has_Homonym (Ent) then
10919 ("argument for pragma% may not be overloaded", Arg);
10922 if Ekind (Ent) /= E_Function
10923 or else No (First_Formal (Ent))
10924 or else Present (Next_Formal (First_Formal (Ent)))
10927 ("argument for pragma% must be" &
10928 " function of one argument", Arg);
10930 end Check_OK_Stream_Convert_Function;
10932 -- Start of processing for Stream_Convert
10936 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
10937 Check_Arg_Count (3);
10938 Check_Optional_Identifier (Arg1, Name_Entity);
10939 Check_Optional_Identifier (Arg2, Name_Read);
10940 Check_Optional_Identifier (Arg3, Name_Write);
10941 Check_Arg_Is_Local_Name (Arg1);
10942 Check_OK_Stream_Convert_Function (Arg2);
10943 Check_OK_Stream_Convert_Function (Arg3);
10946 Typ : constant Entity_Id :=
10947 Underlying_Type (Entity (Expression (Arg1)));
10948 Read : constant Entity_Id := Entity (Expression (Arg2));
10949 Write : constant Entity_Id := Entity (Expression (Arg3));
10952 Check_First_Subtype (Arg1);
10954 -- Check for too early or too late. Note that we don't enforce
10955 -- the rule about primitive operations in this case, since, as
10956 -- is the case for explicit stream attributes themselves, these
10957 -- restrictions are not appropriate. Note that the chaining of
10958 -- the pragma by Rep_Item_Too_Late is actually the critical
10959 -- processing done for this pragma.
10961 if Rep_Item_Too_Early (Typ, N)
10963 Rep_Item_Too_Late (Typ, N, FOnly => True)
10968 -- Return if previous error
10970 if Etype (Typ) = Any_Type
10972 Etype (Read) = Any_Type
10974 Etype (Write) = Any_Type
10981 if Underlying_Type (Etype (Read)) /= Typ then
10983 ("incorrect return type for function&", Arg2);
10986 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
10988 ("incorrect parameter type for function&", Arg3);
10991 if Underlying_Type (Etype (First_Formal (Read))) /=
10992 Underlying_Type (Etype (Write))
10995 ("result type of & does not match Read parameter type",
10999 end Stream_Convert;
11001 -------------------------
11002 -- Style_Checks (GNAT) --
11003 -------------------------
11005 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11007 -- This is processed by the parser since some of the style checks
11008 -- take place during source scanning and parsing. This means that
11009 -- we don't need to issue error messages here.
11011 when Pragma_Style_Checks => Style_Checks : declare
11012 A : constant Node_Id := Expression (Arg1);
11018 Check_No_Identifiers;
11020 -- Two argument form
11022 if Arg_Count = 2 then
11023 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11030 E_Id := Expression (Arg2);
11033 if not Is_Entity_Name (E_Id) then
11035 ("second argument of pragma% must be entity name",
11039 E := Entity (E_Id);
11045 Set_Suppress_Style_Checks (E,
11046 (Chars (Expression (Arg1)) = Name_Off));
11047 exit when No (Homonym (E));
11053 -- One argument form
11056 Check_Arg_Count (1);
11058 if Nkind (A) = N_String_Literal then
11062 Slen : constant Natural := Natural (String_Length (S));
11063 Options : String (1 .. Slen);
11069 C := Get_String_Char (S, Int (J));
11070 exit when not In_Character_Range (C);
11071 Options (J) := Get_Character (C);
11073 -- If at end of string, set options. As per discussion
11074 -- above, no need to check for errors, since we issued
11075 -- them in the parser.
11078 Set_Style_Check_Options (Options);
11086 elsif Nkind (A) = N_Identifier then
11087 if Chars (A) = Name_All_Checks then
11088 Set_Default_Style_Check_Options;
11090 elsif Chars (A) = Name_On then
11091 Style_Check := True;
11093 elsif Chars (A) = Name_Off then
11094 Style_Check := False;
11104 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
11106 when Pragma_Subtitle =>
11108 Check_Arg_Count (1);
11109 Check_Optional_Identifier (Arg1, Name_Subtitle);
11110 Check_Arg_Is_String_Literal (Arg1);
11116 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
11118 when Pragma_Suppress =>
11119 Process_Suppress_Unsuppress (True);
11125 -- pragma Suppress_All;
11127 -- The only check made here is that the pragma appears in the proper
11128 -- place, i.e. following a compilation unit. If indeed it appears in
11129 -- this context, then the parser has already inserted an equivalent
11130 -- pragma Suppress (All_Checks) to get the required effect.
11132 when Pragma_Suppress_All =>
11134 Check_Arg_Count (0);
11136 if Nkind (Parent (N)) /= N_Compilation_Unit_Aux
11137 or else not Is_List_Member (N)
11138 or else List_Containing (N) /= Pragmas_After (Parent (N))
11141 ("misplaced pragma%, must follow compilation unit");
11144 -------------------------
11145 -- Suppress_Debug_Info --
11146 -------------------------
11148 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
11150 when Pragma_Suppress_Debug_Info =>
11152 Check_Arg_Count (1);
11153 Check_Optional_Identifier (Arg1, Name_Entity);
11154 Check_Arg_Is_Local_Name (Arg1);
11155 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
11157 ----------------------------------
11158 -- Suppress_Exception_Locations --
11159 ----------------------------------
11161 -- pragma Suppress_Exception_Locations;
11163 when Pragma_Suppress_Exception_Locations =>
11165 Check_Arg_Count (0);
11166 Check_Valid_Configuration_Pragma;
11167 Exception_Locations_Suppressed := True;
11169 -----------------------------
11170 -- Suppress_Initialization --
11171 -----------------------------
11173 -- pragma Suppress_Initialization ([Entity =>] type_Name);
11175 when Pragma_Suppress_Initialization => Suppress_Init : declare
11181 Check_Arg_Count (1);
11182 Check_Optional_Identifier (Arg1, Name_Entity);
11183 Check_Arg_Is_Local_Name (Arg1);
11185 E_Id := Expression (Arg1);
11187 if Etype (E_Id) = Any_Type then
11191 E := Entity (E_Id);
11193 if Is_Type (E) then
11194 if Is_Incomplete_Or_Private_Type (E) then
11195 if No (Full_View (Base_Type (E))) then
11197 ("argument of pragma% cannot be an incomplete type",
11200 Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
11203 Set_Suppress_Init_Proc (Base_Type (E));
11208 ("pragma% requires argument that is a type name", Arg1);
11216 -- pragma System_Name (DIRECT_NAME);
11218 -- Syntax check: one argument, which must be the identifier GNAT or
11219 -- the identifier GCC, no other identifiers are acceptable.
11221 when Pragma_System_Name =>
11223 Check_No_Identifiers;
11224 Check_Arg_Count (1);
11225 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
11227 -----------------------------
11228 -- Task_Dispatching_Policy --
11229 -----------------------------
11231 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
11233 when Pragma_Task_Dispatching_Policy => declare
11237 Check_Ada_83_Warning;
11238 Check_Arg_Count (1);
11239 Check_No_Identifiers;
11240 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11241 Check_Valid_Configuration_Pragma;
11242 Get_Name_String (Chars (Expression (Arg1)));
11243 DP := Fold_Upper (Name_Buffer (1));
11245 if Task_Dispatching_Policy /= ' '
11246 and then Task_Dispatching_Policy /= DP
11248 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11250 ("task dispatching policy incompatible with policy#");
11252 -- Set new policy, but always preserve System_Location since we
11253 -- like the error message with the run time name.
11256 Task_Dispatching_Policy := DP;
11258 if Task_Dispatching_Policy_Sloc /= System_Location then
11259 Task_Dispatching_Policy_Sloc := Loc;
11268 -- pragma Task_Info (EXPRESSION);
11270 when Pragma_Task_Info => Task_Info : declare
11271 P : constant Node_Id := Parent (N);
11276 if Nkind (P) /= N_Task_Definition then
11277 Error_Pragma ("pragma% must appear in task definition");
11280 Check_No_Identifiers;
11281 Check_Arg_Count (1);
11283 Analyze_And_Resolve (Expression (Arg1), RTE (RE_Task_Info_Type));
11285 if Etype (Expression (Arg1)) = Any_Type then
11289 if Has_Task_Info_Pragma (P) then
11290 Error_Pragma ("duplicate pragma% not allowed");
11292 Set_Has_Task_Info_Pragma (P, True);
11300 -- pragma Task_Name (string_EXPRESSION);
11302 when Pragma_Task_Name => Task_Name : declare
11303 P : constant Node_Id := Parent (N);
11307 Check_No_Identifiers;
11308 Check_Arg_Count (1);
11310 Arg := Expression (Arg1);
11312 -- The expression is used in the call to Create_Task, and must be
11313 -- expanded there, not in the context of the current spec. It must
11314 -- however be analyzed to capture global references, in case it
11315 -- appears in a generic context.
11317 Preanalyze_And_Resolve (Arg, Standard_String);
11319 if Nkind (P) /= N_Task_Definition then
11323 if Has_Task_Name_Pragma (P) then
11324 Error_Pragma ("duplicate pragma% not allowed");
11326 Set_Has_Task_Name_Pragma (P, True);
11327 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11335 -- pragma Task_Storage (
11336 -- [Task_Type =>] LOCAL_NAME,
11337 -- [Top_Guard =>] static_integer_EXPRESSION);
11339 when Pragma_Task_Storage => Task_Storage : declare
11340 Args : Args_List (1 .. 2);
11341 Names : constant Name_List (1 .. 2) := (
11345 Task_Type : Node_Id renames Args (1);
11346 Top_Guard : Node_Id renames Args (2);
11352 Gather_Associations (Names, Args);
11354 if No (Task_Type) then
11356 ("missing task_type argument for pragma%");
11359 Check_Arg_Is_Local_Name (Task_Type);
11361 Ent := Entity (Task_Type);
11363 if not Is_Task_Type (Ent) then
11365 ("argument for pragma% must be task type", Task_Type);
11368 if No (Top_Guard) then
11370 ("pragma% takes two arguments", Task_Type);
11372 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
11375 Check_First_Subtype (Task_Type);
11377 if Rep_Item_Too_Late (Ent, N) then
11382 --------------------------
11383 -- Thread_Local_Storage --
11384 --------------------------
11386 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
11388 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
11394 Check_Arg_Count (1);
11395 Check_Optional_Identifier (Arg1, Name_Entity);
11396 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11398 Id := Expression (Arg1);
11401 if not Is_Entity_Name (Id)
11402 or else Ekind (Entity (Id)) /= E_Variable
11404 Error_Pragma_Arg ("local variable name required", Arg1);
11409 if Rep_Item_Too_Early (E, N)
11410 or else Rep_Item_Too_Late (E, N)
11415 Set_Has_Pragma_Thread_Local_Storage (E);
11416 Set_Has_Gigi_Rep_Item (E);
11417 end Thread_Local_Storage;
11423 -- pragma Time_Slice (static_duration_EXPRESSION);
11425 when Pragma_Time_Slice => Time_Slice : declare
11431 Check_Arg_Count (1);
11432 Check_No_Identifiers;
11433 Check_In_Main_Program;
11434 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
11436 if not Error_Posted (Arg1) then
11438 while Present (Nod) loop
11439 if Nkind (Nod) = N_Pragma
11440 and then Pragma_Name (Nod) = Name_Time_Slice
11442 Error_Msg_Name_1 := Pname;
11443 Error_Msg_N ("duplicate pragma% not permitted", Nod);
11450 -- Process only if in main unit
11452 if Get_Source_Unit (Loc) = Main_Unit then
11453 Opt.Time_Slice_Set := True;
11454 Val := Expr_Value_R (Expression (Arg1));
11456 if Val <= Ureal_0 then
11457 Opt.Time_Slice_Value := 0;
11459 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
11460 Opt.Time_Slice_Value := 1_000_000_000;
11463 Opt.Time_Slice_Value :=
11464 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
11473 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
11475 -- TITLING_OPTION ::=
11476 -- [Title =>] STRING_LITERAL
11477 -- | [Subtitle =>] STRING_LITERAL
11479 when Pragma_Title => Title : declare
11480 Args : Args_List (1 .. 2);
11481 Names : constant Name_List (1 .. 2) := (
11487 Gather_Associations (Names, Args);
11489 for J in 1 .. 2 loop
11490 if Present (Args (J)) then
11491 Check_Arg_Is_String_Literal (Args (J));
11496 ---------------------
11497 -- Unchecked_Union --
11498 ---------------------
11500 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
11502 when Pragma_Unchecked_Union => Unchecked_Union : declare
11503 Assoc : constant Node_Id := Arg1;
11504 Type_Id : constant Node_Id := Expression (Assoc);
11515 Check_No_Identifiers;
11516 Check_Arg_Count (1);
11517 Check_Arg_Is_Local_Name (Arg1);
11519 Find_Type (Type_Id);
11520 Typ := Entity (Type_Id);
11523 or else Rep_Item_Too_Early (Typ, N)
11527 Typ := Underlying_Type (Typ);
11530 if Rep_Item_Too_Late (Typ, N) then
11534 Check_First_Subtype (Arg1);
11536 -- Note remaining cases are references to a type in the current
11537 -- declarative part. If we find an error, we post the error on
11538 -- the relevant type declaration at an appropriate point.
11540 if not Is_Record_Type (Typ) then
11541 Error_Msg_N ("Unchecked_Union must be record type", Typ);
11544 elsif Is_Tagged_Type (Typ) then
11545 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
11548 elsif Is_Limited_Type (Typ) then
11550 ("Unchecked_Union must not be limited record type", Typ);
11551 Explain_Limited_Type (Typ, Typ);
11555 if not Has_Discriminants (Typ) then
11557 ("Unchecked_Union must have one discriminant", Typ);
11561 Discr := First_Discriminant (Typ);
11562 while Present (Discr) loop
11563 if No (Discriminant_Default_Value (Discr)) then
11565 ("Unchecked_Union discriminant must have default value",
11568 Next_Discriminant (Discr);
11571 Tdef := Type_Definition (Declaration_Node (Typ));
11572 Clist := Component_List (Tdef);
11574 Comp := First (Component_Items (Clist));
11575 while Present (Comp) loop
11576 Check_Component (Comp);
11580 if No (Clist) or else No (Variant_Part (Clist)) then
11582 ("Unchecked_Union must have variant part",
11587 Vpart := Variant_Part (Clist);
11589 Variant := First (Variants (Vpart));
11590 while Present (Variant) loop
11591 Check_Variant (Variant);
11596 Set_Is_Unchecked_Union (Typ, True);
11597 Set_Convention (Typ, Convention_C);
11599 Set_Has_Unchecked_Union (Base_Type (Typ), True);
11600 Set_Is_Unchecked_Union (Base_Type (Typ), True);
11601 end Unchecked_Union;
11603 ------------------------
11604 -- Unimplemented_Unit --
11605 ------------------------
11607 -- pragma Unimplemented_Unit;
11609 -- Note: this only gives an error if we are generating code, or if
11610 -- we are in a generic library unit (where the pragma appears in the
11611 -- body, not in the spec).
11613 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
11614 Cunitent : constant Entity_Id :=
11615 Cunit_Entity (Get_Source_Unit (Loc));
11616 Ent_Kind : constant Entity_Kind :=
11621 Check_Arg_Count (0);
11623 if Operating_Mode = Generate_Code
11624 or else Ent_Kind = E_Generic_Function
11625 or else Ent_Kind = E_Generic_Procedure
11626 or else Ent_Kind = E_Generic_Package
11628 Get_Name_String (Chars (Cunitent));
11629 Set_Casing (Mixed_Case);
11630 Write_Str (Name_Buffer (1 .. Name_Len));
11631 Write_Str (" is not supported in this configuration");
11633 raise Unrecoverable_Error;
11635 end Unimplemented_Unit;
11637 ------------------------
11638 -- Universal_Aliasing --
11639 ------------------------
11641 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
11643 when Pragma_Universal_Aliasing => Universal_Alias : declare
11648 Check_Arg_Count (1);
11649 Check_Optional_Identifier (Arg2, Name_Entity);
11650 Check_Arg_Is_Local_Name (Arg1);
11651 E_Id := Entity (Expression (Arg1));
11653 if E_Id = Any_Type then
11655 elsif No (E_Id) or else not Is_Type (E_Id) then
11656 Error_Pragma_Arg ("pragma% requires type", Arg1);
11659 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
11660 end Universal_Alias;
11662 --------------------
11663 -- Universal_Data --
11664 --------------------
11666 -- pragma Universal_Data [(library_unit_NAME)];
11668 when Pragma_Universal_Data =>
11671 -- If this is a configuration pragma, then set the universal
11672 -- addressing option, otherwise confirm that the pragma satisfies
11673 -- the requirements of library unit pragma placement and leave it
11674 -- to the GNAAMP back end to detect the pragma (avoids transitive
11675 -- setting of the option due to withed units).
11677 if Is_Configuration_Pragma then
11678 Universal_Addressing_On_AAMP := True;
11680 Check_Valid_Library_Unit_Pragma;
11683 if not AAMP_On_Target then
11684 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
11691 -- pragma Unmodified (local_Name {, local_Name});
11693 when Pragma_Unmodified => Unmodified : declare
11694 Arg_Node : Node_Id;
11695 Arg_Expr : Node_Id;
11696 Arg_Ent : Entity_Id;
11700 Check_At_Least_N_Arguments (1);
11702 -- Loop through arguments
11705 while Present (Arg_Node) loop
11706 Check_No_Identifier (Arg_Node);
11708 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
11709 -- in fact generate reference, so that the entity will have a
11710 -- reference, which will inhibit any warnings about it not
11711 -- being referenced, and also properly show up in the ali file
11712 -- as a reference. But this reference is recorded before the
11713 -- Has_Pragma_Unreferenced flag is set, so that no warning is
11714 -- generated for this reference.
11716 Check_Arg_Is_Local_Name (Arg_Node);
11717 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11719 if Is_Entity_Name (Arg_Expr) then
11720 Arg_Ent := Entity (Arg_Expr);
11722 if not Is_Assignable (Arg_Ent) then
11724 ("pragma% can only be applied to a variable",
11727 Set_Has_Pragma_Unmodified (Arg_Ent);
11739 -- pragma Unreferenced (local_Name {, local_Name});
11741 -- or when used in a context clause:
11743 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
11745 when Pragma_Unreferenced => Unreferenced : declare
11746 Arg_Node : Node_Id;
11747 Arg_Expr : Node_Id;
11748 Arg_Ent : Entity_Id;
11753 Check_At_Least_N_Arguments (1);
11755 -- Check case of appearing within context clause
11757 if Is_In_Context_Clause then
11759 -- The arguments must all be units mentioned in a with clause
11760 -- in the same context clause. Note we already checked (in
11761 -- Par.Prag) that the arguments are either identifiers or
11762 -- selected components.
11765 while Present (Arg_Node) loop
11766 Citem := First (List_Containing (N));
11767 while Citem /= N loop
11768 if Nkind (Citem) = N_With_Clause
11769 and then Same_Name (Name (Citem), Expression (Arg_Node))
11771 Set_Has_Pragma_Unreferenced
11774 (Library_Unit (Citem))));
11775 Set_Unit_Name (Expression (Arg_Node), Name (Citem));
11784 ("argument of pragma% is not with'ed unit", Arg_Node);
11790 -- Case of not in list of context items
11794 while Present (Arg_Node) loop
11795 Check_No_Identifier (Arg_Node);
11797 -- Note: the analyze call done by Check_Arg_Is_Local_Name
11798 -- will in fact generate reference, so that the entity will
11799 -- have a reference, which will inhibit any warnings about
11800 -- it not being referenced, and also properly show up in the
11801 -- ali file as a reference. But this reference is recorded
11802 -- before the Has_Pragma_Unreferenced flag is set, so that
11803 -- no warning is generated for this reference.
11805 Check_Arg_Is_Local_Name (Arg_Node);
11806 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11808 if Is_Entity_Name (Arg_Expr) then
11809 Arg_Ent := Entity (Arg_Expr);
11811 -- If the entity is overloaded, the pragma applies to the
11812 -- most recent overloading, as documented. In this case,
11813 -- name resolution does not generate a reference, so it
11814 -- must be done here explicitly.
11816 if Is_Overloaded (Arg_Expr) then
11817 Generate_Reference (Arg_Ent, N);
11820 Set_Has_Pragma_Unreferenced (Arg_Ent);
11828 --------------------------
11829 -- Unreferenced_Objects --
11830 --------------------------
11832 -- pragma Unreferenced_Objects (local_Name {, local_Name});
11834 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
11835 Arg_Node : Node_Id;
11836 Arg_Expr : Node_Id;
11840 Check_At_Least_N_Arguments (1);
11843 while Present (Arg_Node) loop
11844 Check_No_Identifier (Arg_Node);
11845 Check_Arg_Is_Local_Name (Arg_Node);
11846 Arg_Expr := Get_Pragma_Arg (Arg_Node);
11848 if not Is_Entity_Name (Arg_Expr)
11849 or else not Is_Type (Entity (Arg_Expr))
11852 ("argument for pragma% must be type or subtype", Arg_Node);
11855 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
11858 end Unreferenced_Objects;
11860 ------------------------------
11861 -- Unreserve_All_Interrupts --
11862 ------------------------------
11864 -- pragma Unreserve_All_Interrupts;
11866 when Pragma_Unreserve_All_Interrupts =>
11868 Check_Arg_Count (0);
11870 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
11871 Unreserve_All_Interrupts := True;
11878 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
11880 when Pragma_Unsuppress =>
11882 Process_Suppress_Unsuppress (False);
11884 -------------------
11885 -- Use_VADS_Size --
11886 -------------------
11888 -- pragma Use_VADS_Size;
11890 when Pragma_Use_VADS_Size =>
11892 Check_Arg_Count (0);
11893 Check_Valid_Configuration_Pragma;
11894 Use_VADS_Size := True;
11896 ---------------------
11897 -- Validity_Checks --
11898 ---------------------
11900 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
11902 when Pragma_Validity_Checks => Validity_Checks : declare
11903 A : constant Node_Id := Expression (Arg1);
11909 Check_Arg_Count (1);
11910 Check_No_Identifiers;
11912 if Nkind (A) = N_String_Literal then
11916 Slen : constant Natural := Natural (String_Length (S));
11917 Options : String (1 .. Slen);
11923 C := Get_String_Char (S, Int (J));
11924 exit when not In_Character_Range (C);
11925 Options (J) := Get_Character (C);
11928 Set_Validity_Check_Options (Options);
11936 elsif Nkind (A) = N_Identifier then
11938 if Chars (A) = Name_All_Checks then
11939 Set_Validity_Check_Options ("a");
11941 elsif Chars (A) = Name_On then
11942 Validity_Checks_On := True;
11944 elsif Chars (A) = Name_Off then
11945 Validity_Checks_On := False;
11949 end Validity_Checks;
11955 -- pragma Volatile (LOCAL_NAME);
11957 when Pragma_Volatile =>
11958 Process_Atomic_Shared_Volatile;
11960 -------------------------
11961 -- Volatile_Components --
11962 -------------------------
11964 -- pragma Volatile_Components (array_LOCAL_NAME);
11966 -- Volatile is handled by the same circuit as Atomic_Components
11972 -- pragma Warnings (On | Off);
11973 -- pragma Warnings (On | Off, LOCAL_NAME);
11974 -- pragma Warnings (static_string_EXPRESSION);
11975 -- pragma Warnings (On | Off, STRING_LITERAL);
11977 when Pragma_Warnings => Warnings : begin
11979 Check_At_Least_N_Arguments (1);
11980 Check_No_Identifiers;
11983 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11986 -- One argument case
11988 if Arg_Count = 1 then
11990 -- On/Off one argument case was processed by parser
11992 if Nkind (Argx) = N_Identifier
11994 (Chars (Argx) = Name_On
11996 Chars (Argx) = Name_Off)
12000 -- One argument case must be ON/OFF or static string expr
12002 elsif not Is_Static_String_Expression (Arg1) then
12004 ("argument of pragma% must be On/Off or " &
12005 "static string expression", Arg2);
12007 -- One argument string expression case
12011 Lit : constant Node_Id := Expr_Value_S (Argx);
12012 Str : constant String_Id := Strval (Lit);
12013 Len : constant Nat := String_Length (Str);
12021 while J <= Len loop
12022 C := Get_String_Char (Str, J);
12023 OK := In_Character_Range (C);
12026 Chr := Get_Character (C);
12030 if J < Len and then Chr = '.' then
12032 C := Get_String_Char (Str, J);
12033 Chr := Get_Character (C);
12035 if not Set_Dot_Warning_Switch (Chr) then
12037 ("invalid warning switch character " &
12044 OK := Set_Warning_Switch (Chr);
12050 ("invalid warning switch character " & Chr,
12059 -- Two or more arguments (must be two)
12062 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12063 Check_At_Most_N_Arguments (2);
12071 E_Id := Expression (Arg2);
12074 -- In the expansion of an inlined body, a reference to
12075 -- the formal may be wrapped in a conversion if the
12076 -- actual is a conversion. Retrieve the real entity name.
12078 if (In_Instance_Body
12079 or else In_Inlined_Body)
12080 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
12082 E_Id := Expression (E_Id);
12085 -- Entity name case
12087 if Is_Entity_Name (E_Id) then
12088 E := Entity (E_Id);
12095 (E, (Chars (Expression (Arg1)) = Name_Off));
12097 if Chars (Expression (Arg1)) = Name_Off
12098 and then Warn_On_Warnings_Off
12100 Warnings_Off_Pragmas.Append ((N, E));
12103 if Is_Enumeration_Type (E) then
12107 Lit := First_Literal (E);
12108 while Present (Lit) loop
12109 Set_Warnings_Off (Lit);
12110 Next_Literal (Lit);
12115 exit when No (Homonym (E));
12120 -- Error if not entity or static string literal case
12122 elsif not Is_Static_String_Expression (Arg2) then
12124 ("second argument of pragma% must be entity " &
12125 "name or static string expression", Arg2);
12127 -- String literal case
12130 String_To_Name_Buffer
12131 (Strval (Expr_Value_S (Expression (Arg2))));
12133 -- Note on configuration pragma case: If this is a
12134 -- configuration pragma, then for an OFF pragma, we
12135 -- just set Config True in the call, which is all
12136 -- that needs to be done. For the case of ON, this
12137 -- is normally an error, unless it is canceling the
12138 -- effect of a previous OFF pragma in the same file.
12139 -- In any other case, an error will be signalled (ON
12140 -- with no matching OFF).
12142 if Chars (Argx) = Name_Off then
12143 Set_Specific_Warning_Off
12144 (Loc, Name_Buffer (1 .. Name_Len),
12145 Config => Is_Configuration_Pragma);
12147 elsif Chars (Argx) = Name_On then
12148 Set_Specific_Warning_On
12149 (Loc, Name_Buffer (1 .. Name_Len), Err);
12153 ("?pragma Warnings On with no " &
12154 "matching Warnings Off",
12164 -------------------
12165 -- Weak_External --
12166 -------------------
12168 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
12170 when Pragma_Weak_External => Weak_External : declare
12175 Check_Arg_Count (1);
12176 Check_Optional_Identifier (Arg1, Name_Entity);
12177 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12178 Ent := Entity (Expression (Arg1));
12180 if Rep_Item_Too_Early (Ent, N) then
12183 Ent := Underlying_Type (Ent);
12186 -- The only processing required is to link this item on to the
12187 -- list of rep items for the given entity. This is accomplished
12188 -- by the call to Rep_Item_Too_Late (when no error is detected
12189 -- and False is returned).
12191 if Rep_Item_Too_Late (Ent, N) then
12194 Set_Has_Gigi_Rep_Item (Ent);
12198 -----------------------------
12199 -- Wide_Character_Encoding --
12200 -----------------------------
12202 -- pragma Wide_Character_Encoding (IDENTIFIER);
12204 when Pragma_Wide_Character_Encoding =>
12207 -- Nothing to do, handled in parser. Note that we do not enforce
12208 -- configuration pragma placement, this pragma can appear at any
12209 -- place in the source, allowing mixed encodings within a single
12214 --------------------
12215 -- Unknown_Pragma --
12216 --------------------
12218 -- Should be impossible, since the case of an unknown pragma is
12219 -- separately processed before the case statement is entered.
12221 when Unknown_Pragma =>
12222 raise Program_Error;
12226 when Pragma_Exit => null;
12227 end Analyze_Pragma;
12229 -------------------
12230 -- Check_Enabled --
12231 -------------------
12233 function Check_Enabled (Nam : Name_Id) return Boolean is
12237 PP := Opt.Check_Policy_List;
12240 return Assertions_Enabled;
12243 Nam = Chars (Expression (First (Pragma_Argument_Associations (PP))))
12246 Chars (Expression (Last (Pragma_Argument_Associations (PP))))
12248 when Name_On | Name_Check =>
12250 when Name_Off | Name_Ignore =>
12253 raise Program_Error;
12257 PP := Next_Pragma (PP);
12262 ---------------------------------
12263 -- Delay_Config_Pragma_Analyze --
12264 ---------------------------------
12266 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
12268 return Pragma_Name (N) = Name_Interrupt_State
12270 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
12271 end Delay_Config_Pragma_Analyze;
12273 -------------------------
12274 -- Get_Base_Subprogram --
12275 -------------------------
12277 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
12278 Result : Entity_Id;
12281 -- Follow subprogram renaming chain
12284 while Is_Subprogram (Result)
12286 (Is_Generic_Instance (Result)
12287 or else Nkind (Parent (Declaration_Node (Result))) =
12288 N_Subprogram_Renaming_Declaration)
12289 and then Present (Alias (Result))
12291 Result := Alias (Result);
12295 end Get_Base_Subprogram;
12297 --------------------
12298 -- Get_Pragma_Arg --
12299 --------------------
12301 function Get_Pragma_Arg (Arg : Node_Id) return Node_Id is
12303 if Nkind (Arg) = N_Pragma_Argument_Association then
12304 return Expression (Arg);
12308 end Get_Pragma_Arg;
12314 procedure Initialize is
12319 -----------------------------
12320 -- Is_Config_Static_String --
12321 -----------------------------
12323 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
12325 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
12326 -- This is an internal recursive function that is just like the outer
12327 -- function except that it adds the string to the name buffer rather
12328 -- than placing the string in the name buffer.
12330 ------------------------------
12331 -- Add_Config_Static_String --
12332 ------------------------------
12334 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
12341 if Nkind (N) = N_Op_Concat then
12342 if Add_Config_Static_String (Left_Opnd (N)) then
12343 N := Right_Opnd (N);
12349 if Nkind (N) /= N_String_Literal then
12350 Error_Msg_N ("string literal expected for pragma argument", N);
12354 for J in 1 .. String_Length (Strval (N)) loop
12355 C := Get_String_Char (Strval (N), J);
12357 if not In_Character_Range (C) then
12359 ("string literal contains invalid wide character",
12360 Sloc (N) + 1 + Source_Ptr (J));
12364 Add_Char_To_Name_Buffer (Get_Character (C));
12369 end Add_Config_Static_String;
12371 -- Start of processing for Is_Config_Static_String
12376 return Add_Config_Static_String (Arg);
12377 end Is_Config_Static_String;
12379 -----------------------------------------
12380 -- Is_Non_Significant_Pragma_Reference --
12381 -----------------------------------------
12383 -- This function makes use of the following static table which indicates
12384 -- whether a given pragma is significant. A value of -1 in this table
12385 -- indicates that the reference is significant. A value of zero indicates
12386 -- than appearance as any argument is insignificant, a positive value
12387 -- indicates that appearance in that parameter position is significant.
12389 -- A value of 99 flags a special case requiring a special check (this is
12390 -- used for cases not covered by this standard encoding, e.g. pragma Check
12391 -- where the first argument is not significant, but the others are).
12393 Sig_Flags : constant array (Pragma_Id) of Int :=
12394 (Pragma_AST_Entry => -1,
12395 Pragma_Abort_Defer => -1,
12396 Pragma_Ada_83 => -1,
12397 Pragma_Ada_95 => -1,
12398 Pragma_Ada_05 => -1,
12399 Pragma_Ada_2005 => -1,
12400 Pragma_All_Calls_Remote => -1,
12401 Pragma_Annotate => -1,
12402 Pragma_Assert => -1,
12403 Pragma_Assertion_Policy => 0,
12404 Pragma_Assume_No_Invalid_Values => 0,
12405 Pragma_Asynchronous => -1,
12406 Pragma_Atomic => 0,
12407 Pragma_Atomic_Components => 0,
12408 Pragma_Attach_Handler => -1,
12409 Pragma_Check => 99,
12410 Pragma_Check_Name => 0,
12411 Pragma_Check_Policy => 0,
12412 Pragma_CIL_Constructor => -1,
12413 Pragma_CPP_Class => 0,
12414 Pragma_CPP_Constructor => 0,
12415 Pragma_CPP_Virtual => 0,
12416 Pragma_CPP_Vtable => 0,
12417 Pragma_C_Pass_By_Copy => 0,
12418 Pragma_Comment => 0,
12419 Pragma_Common_Object => -1,
12420 Pragma_Compile_Time_Error => -1,
12421 Pragma_Compile_Time_Warning => -1,
12422 Pragma_Compiler_Unit => 0,
12423 Pragma_Complete_Representation => 0,
12424 Pragma_Complex_Representation => 0,
12425 Pragma_Component_Alignment => -1,
12426 Pragma_Controlled => 0,
12427 Pragma_Convention => 0,
12428 Pragma_Convention_Identifier => 0,
12429 Pragma_Debug => -1,
12430 Pragma_Debug_Policy => 0,
12431 Pragma_Detect_Blocking => -1,
12432 Pragma_Discard_Names => 0,
12433 Pragma_Elaborate => -1,
12434 Pragma_Elaborate_All => -1,
12435 Pragma_Elaborate_Body => -1,
12436 Pragma_Elaboration_Checks => -1,
12437 Pragma_Eliminate => -1,
12438 Pragma_Export => -1,
12439 Pragma_Export_Exception => -1,
12440 Pragma_Export_Function => -1,
12441 Pragma_Export_Object => -1,
12442 Pragma_Export_Procedure => -1,
12443 Pragma_Export_Value => -1,
12444 Pragma_Export_Valued_Procedure => -1,
12445 Pragma_Extend_System => -1,
12446 Pragma_Extensions_Allowed => -1,
12447 Pragma_External => -1,
12448 Pragma_Favor_Top_Level => -1,
12449 Pragma_External_Name_Casing => -1,
12450 Pragma_Fast_Math => -1,
12451 Pragma_Finalize_Storage_Only => 0,
12452 Pragma_Float_Representation => 0,
12453 Pragma_Ident => -1,
12454 Pragma_Implemented_By_Entry => -1,
12455 Pragma_Implicit_Packing => 0,
12456 Pragma_Import => +2,
12457 Pragma_Import_Exception => 0,
12458 Pragma_Import_Function => 0,
12459 Pragma_Import_Object => 0,
12460 Pragma_Import_Procedure => 0,
12461 Pragma_Import_Valued_Procedure => 0,
12462 Pragma_Initialize_Scalars => -1,
12463 Pragma_Inline => 0,
12464 Pragma_Inline_Always => 0,
12465 Pragma_Inline_Generic => 0,
12466 Pragma_Inspection_Point => -1,
12467 Pragma_Interface => +2,
12468 Pragma_Interface_Name => +2,
12469 Pragma_Interrupt_Handler => -1,
12470 Pragma_Interrupt_Priority => -1,
12471 Pragma_Interrupt_State => -1,
12472 Pragma_Java_Constructor => -1,
12473 Pragma_Java_Interface => -1,
12474 Pragma_Keep_Names => 0,
12475 Pragma_License => -1,
12476 Pragma_Link_With => -1,
12477 Pragma_Linker_Alias => -1,
12478 Pragma_Linker_Constructor => -1,
12479 Pragma_Linker_Destructor => -1,
12480 Pragma_Linker_Options => -1,
12481 Pragma_Linker_Section => -1,
12483 Pragma_Locking_Policy => -1,
12484 Pragma_Long_Float => -1,
12485 Pragma_Machine_Attribute => -1,
12487 Pragma_Main_Storage => -1,
12488 Pragma_Memory_Size => -1,
12489 Pragma_No_Return => 0,
12490 Pragma_No_Body => 0,
12491 Pragma_No_Run_Time => -1,
12492 Pragma_No_Strict_Aliasing => -1,
12493 Pragma_Normalize_Scalars => -1,
12494 Pragma_Obsolescent => 0,
12495 Pragma_Optimize => -1,
12496 Pragma_Optimize_Alignment => -1,
12499 Pragma_Passive => -1,
12500 Pragma_Preelaborable_Initialization => -1,
12501 Pragma_Polling => -1,
12502 Pragma_Persistent_BSS => 0,
12503 Pragma_Postcondition => -1,
12504 Pragma_Precondition => -1,
12505 Pragma_Preelaborate => -1,
12506 Pragma_Preelaborate_05 => -1,
12507 Pragma_Priority => -1,
12508 Pragma_Priority_Specific_Dispatching => -1,
12509 Pragma_Profile => 0,
12510 Pragma_Profile_Warnings => 0,
12511 Pragma_Propagate_Exceptions => -1,
12512 Pragma_Psect_Object => -1,
12514 Pragma_Pure_05 => -1,
12515 Pragma_Pure_Function => -1,
12516 Pragma_Queuing_Policy => -1,
12517 Pragma_Ravenscar => -1,
12518 Pragma_Relative_Deadline => -1,
12519 Pragma_Remote_Call_Interface => -1,
12520 Pragma_Remote_Types => -1,
12521 Pragma_Restricted_Run_Time => -1,
12522 Pragma_Restriction_Warnings => -1,
12523 Pragma_Restrictions => -1,
12524 Pragma_Reviewable => -1,
12525 Pragma_Share_Generic => -1,
12526 Pragma_Shared => -1,
12527 Pragma_Shared_Passive => -1,
12528 Pragma_Source_File_Name => -1,
12529 Pragma_Source_File_Name_Project => -1,
12530 Pragma_Source_Reference => -1,
12531 Pragma_Storage_Size => -1,
12532 Pragma_Storage_Unit => -1,
12533 Pragma_Static_Elaboration_Desired => -1,
12534 Pragma_Stream_Convert => -1,
12535 Pragma_Style_Checks => -1,
12536 Pragma_Subtitle => -1,
12537 Pragma_Suppress => 0,
12538 Pragma_Suppress_Exception_Locations => 0,
12539 Pragma_Suppress_All => -1,
12540 Pragma_Suppress_Debug_Info => 0,
12541 Pragma_Suppress_Initialization => 0,
12542 Pragma_System_Name => -1,
12543 Pragma_Task_Dispatching_Policy => -1,
12544 Pragma_Task_Info => -1,
12545 Pragma_Task_Name => -1,
12546 Pragma_Task_Storage => 0,
12547 Pragma_Thread_Local_Storage => 0,
12548 Pragma_Time_Slice => -1,
12549 Pragma_Title => -1,
12550 Pragma_Unchecked_Union => 0,
12551 Pragma_Unimplemented_Unit => -1,
12552 Pragma_Universal_Aliasing => -1,
12553 Pragma_Universal_Data => -1,
12554 Pragma_Unmodified => -1,
12555 Pragma_Unreferenced => -1,
12556 Pragma_Unreferenced_Objects => -1,
12557 Pragma_Unreserve_All_Interrupts => -1,
12558 Pragma_Unsuppress => 0,
12559 Pragma_Use_VADS_Size => -1,
12560 Pragma_Validity_Checks => -1,
12561 Pragma_Volatile => 0,
12562 Pragma_Volatile_Components => 0,
12563 Pragma_Warnings => -1,
12564 Pragma_Weak_External => -1,
12565 Pragma_Wide_Character_Encoding => 0,
12566 Unknown_Pragma => 0);
12568 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
12577 if Nkind (P) /= N_Pragma_Argument_Association then
12581 Id := Get_Pragma_Id (Parent (P));
12582 C := Sig_Flags (Id);
12594 -- For pragma Check, the first argument is not significant,
12595 -- the second and the third (if present) arguments are
12598 when Pragma_Check =>
12600 P = First (Pragma_Argument_Associations (Parent (P)));
12603 raise Program_Error;
12607 A := First (Pragma_Argument_Associations (Parent (P)));
12608 for J in 1 .. C - 1 loop
12616 return A = P; -- is this wrong way round ???
12619 end Is_Non_Significant_Pragma_Reference;
12621 ------------------------------
12622 -- Is_Pragma_String_Literal --
12623 ------------------------------
12625 -- This function returns true if the corresponding pragma argument is a
12626 -- static string expression. These are the only cases in which string
12627 -- literals can appear as pragma arguments. We also allow a string literal
12628 -- as the first argument to pragma Assert (although it will of course
12629 -- always generate a type error).
12631 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
12632 Pragn : constant Node_Id := Parent (Par);
12633 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
12634 Pname : constant Name_Id := Pragma_Name (Pragn);
12640 N := First (Assoc);
12647 if Pname = Name_Assert then
12650 elsif Pname = Name_Export then
12653 elsif Pname = Name_Ident then
12656 elsif Pname = Name_Import then
12659 elsif Pname = Name_Interface_Name then
12662 elsif Pname = Name_Linker_Alias then
12665 elsif Pname = Name_Linker_Section then
12668 elsif Pname = Name_Machine_Attribute then
12671 elsif Pname = Name_Source_File_Name then
12674 elsif Pname = Name_Source_Reference then
12677 elsif Pname = Name_Title then
12680 elsif Pname = Name_Subtitle then
12686 end Is_Pragma_String_Literal;
12688 --------------------------------------
12689 -- Process_Compilation_Unit_Pragmas --
12690 --------------------------------------
12692 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
12694 -- A special check for pragma Suppress_All, a very strange DEC pragma,
12695 -- strange because it comes at the end of the unit. If we have a pragma
12696 -- Suppress_All in the Pragmas_After of the current unit, then we insert
12697 -- a pragma Suppress (All_Checks) at the start of the context clause to
12698 -- ensure the correct processing.
12701 PA : constant List_Id := Pragmas_After (Aux_Decls_Node (N));
12705 if Present (PA) then
12707 while Present (P) loop
12708 if Pragma_Name (P) = Name_Suppress_All then
12709 Prepend_To (Context_Items (N),
12710 Make_Pragma (Sloc (P),
12711 Chars => Name_Suppress,
12712 Pragma_Argument_Associations => New_List (
12713 Make_Pragma_Argument_Association (Sloc (P),
12715 Make_Identifier (Sloc (P),
12716 Chars => Name_All_Checks)))));
12724 end Process_Compilation_Unit_Pragmas;
12735 --------------------------------
12736 -- Set_Encoded_Interface_Name --
12737 --------------------------------
12739 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
12740 Str : constant String_Id := Strval (S);
12741 Len : constant Int := String_Length (Str);
12746 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
12749 -- Stores encoded value of character code CC. The encoding we use an
12750 -- underscore followed by four lower case hex digits.
12756 procedure Encode is
12758 Store_String_Char (Get_Char_Code ('_'));
12760 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
12762 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
12764 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
12766 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
12769 -- Start of processing for Set_Encoded_Interface_Name
12772 -- If first character is asterisk, this is a link name, and we leave it
12773 -- completely unmodified. We also ignore null strings (the latter case
12774 -- happens only in error cases) and no encoding should occur for Java or
12775 -- AAMP interface names.
12778 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
12779 or else VM_Target /= No_VM
12780 or else AAMP_On_Target
12782 Set_Interface_Name (E, S);
12787 CC := Get_String_Char (Str, J);
12789 exit when not In_Character_Range (CC);
12791 C := Get_Character (CC);
12793 exit when C /= '_' and then C /= '$'
12794 and then C not in '0' .. '9'
12795 and then C not in 'a' .. 'z'
12796 and then C not in 'A' .. 'Z';
12799 Set_Interface_Name (E, S);
12807 -- Here we need to encode. The encoding we use as follows:
12808 -- three underscores + four hex digits (lower case)
12812 for J in 1 .. String_Length (Str) loop
12813 CC := Get_String_Char (Str, J);
12815 if not In_Character_Range (CC) then
12818 C := Get_Character (CC);
12820 if C = '_' or else C = '$'
12821 or else C in '0' .. '9'
12822 or else C in 'a' .. 'z'
12823 or else C in 'A' .. 'Z'
12825 Store_String_Char (CC);
12832 Set_Interface_Name (E,
12833 Make_String_Literal (Sloc (S),
12834 Strval => End_String));
12836 end Set_Encoded_Interface_Name;
12838 -------------------
12839 -- Set_Unit_Name --
12840 -------------------
12842 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
12847 if Nkind (N) = N_Identifier
12848 and then Nkind (With_Item) = N_Identifier
12850 Set_Entity (N, Entity (With_Item));
12852 elsif Nkind (N) = N_Selected_Component then
12853 Change_Selected_Component_To_Expanded_Name (N);
12854 Set_Entity (N, Entity (With_Item));
12855 Set_Entity (Selector_Name (N), Entity (N));
12857 Pref := Prefix (N);
12858 Scop := Scope (Entity (N));
12859 while Nkind (Pref) = N_Selected_Component loop
12860 Change_Selected_Component_To_Expanded_Name (Pref);
12861 Set_Entity (Selector_Name (Pref), Scop);
12862 Set_Entity (Pref, Scop);
12863 Pref := Prefix (Pref);
12864 Scop := Scope (Scop);
12867 Set_Entity (Pref, Scop);