1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This unit contains the semantic processing for all pragmas, both language
27 -- and implementation defined. For most pragmas, the parser only does the
28 -- most basic job of checking the syntax, so Sem_Prag also contains the code
29 -- to complete the syntax checks. Certain pragmas are handled partially or
30 -- completely by the parser (see Par.Prag for further details).
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Checks; use Checks;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Elists; use Elists;
39 with Errout; use Errout;
40 with Exp_Ch7; use Exp_Ch7;
41 with Exp_Dist; use Exp_Dist;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Par_SCO; use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Ch3; use Sem_Ch3;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res; use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand; use Stand;
73 with Sinfo; use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput; use Sinput;
76 with Snames; use Snames;
77 with Stringt; use Stringt;
78 with Stylesw; use Stylesw;
80 with Targparm; use Targparm;
81 with Tbuild; use Tbuild;
83 with Uintp; use Uintp;
84 with Uname; use Uname;
85 with Urealp; use Urealp;
86 with Validsw; use Validsw;
87 with Warnsw; use Warnsw;
89 package body Sem_Prag is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all upper case letters for OpenVMS versions of GNAT, and to all
129 -- lower case letters for all other versions
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals is new Table.Table (
158 Table_Component_Type => Node_Id,
159 Table_Index_Type => Int,
160 Table_Low_Bound => 0,
161 Table_Initial => 100,
162 Table_Increment => 100,
163 Table_Name => "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
179 -- original one, following the renaming chain) is returned. Otherwise the
180 -- entity is returned unchanged. Should be in Einfo???
183 -- This is a dummy function called by the processing for pragma Reviewable.
184 -- It is there for assisting front end debugging. By placing a Reviewable
185 -- pragma in the source program, a breakpoint on rv catches this place in
186 -- the source, allowing convenient stepping to the point of interest.
188 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
189 -- Place semantic information on the argument of an Elaborate/Elaborate_All
190 -- pragma. Entity name for unit and its parents is taken from item in
191 -- previous with_clause that mentions the unit.
193 -------------------------------
194 -- Adjust_External_Name_Case --
195 -------------------------------
197 function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
201 -- Adjust case of literal if required
203 if Opt.External_Name_Exp_Casing = As_Is then
207 -- Copy existing string
213 for J in 1 .. String_Length (Strval (N)) loop
214 CC := Get_String_Char (Strval (N), J);
216 if Opt.External_Name_Exp_Casing = Uppercase
217 and then CC >= Get_Char_Code ('a')
218 and then CC <= Get_Char_Code ('z')
220 Store_String_Char (CC - 32);
222 elsif Opt.External_Name_Exp_Casing = Lowercase
223 and then CC >= Get_Char_Code ('A')
224 and then CC <= Get_Char_Code ('Z')
226 Store_String_Char (CC + 32);
229 Store_String_Char (CC);
234 Make_String_Literal (Sloc (N),
235 Strval => End_String);
237 end Adjust_External_Name_Case;
239 ------------------------------
240 -- Analyze_PPC_In_Decl_Part --
241 ------------------------------
243 procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
244 Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
247 -- Install formals and push subprogram spec onto scope stack so that we
248 -- can see the formals from the pragma.
253 -- Preanalyze the boolean expression, we treat this as a spec expression
254 -- (i.e. similar to a default expression).
256 Preanalyze_Spec_Expression
257 (Get_Pragma_Arg (Arg1), Standard_Boolean);
259 -- Remove the subprogram from the scope stack now that the pre-analysis
260 -- of the precondition/postcondition is done.
263 end Analyze_PPC_In_Decl_Part;
269 procedure Analyze_Pragma (N : Node_Id) is
270 Loc : constant Source_Ptr := Sloc (N);
271 Pname : constant Name_Id := Pragma_Name (N);
274 Pragma_Exit : exception;
275 -- This exception is used to exit pragma processing completely. It is
276 -- used when an error is detected, and no further processing is
277 -- required. It is also used if an earlier error has left the tree in
278 -- a state where the pragma should not be processed.
281 -- Number of pragma argument associations
287 -- First four pragma arguments (pragma argument association nodes, or
288 -- Empty if the corresponding argument does not exist).
290 type Name_List is array (Natural range <>) of Name_Id;
291 type Args_List is array (Natural range <>) of Node_Id;
292 -- Types used for arguments to Check_Arg_Order and Gather_Associations
294 procedure Ada_2005_Pragma;
295 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
296 -- Ada 95 mode, these are implementation defined pragmas, so should be
297 -- caught by the No_Implementation_Pragmas restriction.
299 procedure Ada_2012_Pragma;
300 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
301 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
302 -- should be caught by the No_Implementation_Pragmas restriction.
304 procedure Check_Ada_83_Warning;
305 -- Issues a warning message for the current pragma if operating in Ada
306 -- 83 mode (used for language pragmas that are not a standard part of
307 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
310 procedure Check_Arg_Count (Required : Nat);
311 -- Check argument count for pragma is equal to given parameter. If not,
312 -- then issue an error message and raise Pragma_Exit.
314 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
315 -- Arg which can either be a pragma argument association, in which case
316 -- the check is applied to the expression of the association or an
317 -- expression directly.
319 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
320 -- Check that an argument has the right form for an EXTERNAL_NAME
321 -- parameter of an extended import/export pragma. The rule is that the
322 -- name must be an identifier or string literal (in Ada 83 mode) or a
323 -- static string expression (in Ada 95 mode).
325 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
326 -- Check the specified argument Arg to make sure that it is an
327 -- identifier. If not give error and raise Pragma_Exit.
329 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
330 -- Check the specified argument Arg to make sure that it is an integer
331 -- literal. If not give error and raise Pragma_Exit.
333 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
334 -- Check the specified argument Arg to make sure that it has the proper
335 -- syntactic form for a local name and meets the semantic requirements
336 -- for a local name. The local name is analyzed as part of the
337 -- processing for this call. In addition, the local name is required
338 -- to represent an entity at the library level.
340 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
341 -- Check the specified argument Arg to make sure that it has the proper
342 -- syntactic form for a local name and meets the semantic requirements
343 -- for a local name. The local name is analyzed as part of the
344 -- processing for this call.
346 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
347 -- Check the specified argument Arg to make sure that it is a valid
348 -- locking policy name. If not give error and raise Pragma_Exit.
350 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
351 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
352 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
353 -- Check the specified argument Arg to make sure that it is an
354 -- identifier whose name matches either N1 or N2 (or N3 if present).
355 -- If not then give error and raise Pragma_Exit.
357 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
358 -- Check the specified argument Arg to make sure that it is a valid
359 -- queuing policy name. If not give error and raise Pragma_Exit.
361 procedure Check_Arg_Is_Static_Expression
363 Typ : Entity_Id := Empty);
364 -- Check the specified argument Arg to make sure that it is a static
365 -- expression of the given type (i.e. it will be analyzed and resolved
366 -- using this type, which can be any valid argument to Resolve, e.g.
367 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
368 -- Typ is left Empty, then any static expression is allowed.
370 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
371 -- Check the specified argument Arg to make sure that it is a valid task
372 -- dispatching policy name. If not give error and raise Pragma_Exit.
374 procedure Check_Arg_Order (Names : Name_List);
375 -- Checks for an instance of two arguments with identifiers for the
376 -- current pragma which are not in the sequence indicated by Names,
377 -- and if so, generates a fatal message about bad order of arguments.
379 procedure Check_At_Least_N_Arguments (N : Nat);
380 -- Check there are at least N arguments present
382 procedure Check_At_Most_N_Arguments (N : Nat);
383 -- Check there are no more than N arguments present
385 procedure Check_Component
388 In_Variant_Part : Boolean := False);
389 -- Examine an Unchecked_Union component for correct use of per-object
390 -- constrained subtypes, and for restrictions on finalizable components.
391 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
392 -- should be set when Comp comes from a record variant.
394 procedure Check_Duplicate_Pragma (E : Entity_Id);
395 -- Check if a pragma of the same name as the current pragma is already
396 -- chained as a rep pragma to the given entity. If so give a message
397 -- about the duplicate, and then raise Pragma_Exit so does not return.
398 -- Also checks for delayed aspect specification node in the chain.
400 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
401 -- Nam is an N_String_Literal node containing the external name set by
402 -- an Import or Export pragma (or extended Import or Export pragma).
403 -- This procedure checks for possible duplications if this is the export
404 -- case, and if found, issues an appropriate error message.
406 procedure Check_First_Subtype (Arg : Node_Id);
407 -- Checks that Arg, whose expression is an entity name, references a
410 procedure Check_In_Main_Program;
411 -- Common checks for pragmas that appear within a main program
412 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
414 procedure Check_Interrupt_Or_Attach_Handler;
415 -- Common processing for first argument of pragma Interrupt_Handler or
416 -- pragma Attach_Handler.
418 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
419 -- Check that pragma appears in a declarative part, or in a package
420 -- specification, i.e. that it does not occur in a statement sequence
423 procedure Check_No_Identifier (Arg : Node_Id);
424 -- Checks that the given argument does not have an identifier. If
425 -- an identifier is present, then an error message is issued, and
426 -- Pragma_Exit is raised.
428 procedure Check_No_Identifiers;
429 -- Checks that none of the arguments to the pragma has an identifier.
430 -- If any argument has an identifier, then an error message is issued,
431 -- and Pragma_Exit is raised.
433 procedure Check_No_Link_Name;
434 -- Checks that no link name is specified
436 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
437 -- Checks if the given argument has an identifier, and if so, requires
438 -- it to match the given identifier name. If there is a non-matching
439 -- identifier, then an error message is given and Error_Pragmas raised.
441 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
442 -- Checks if the given argument has an identifier, and if so, requires
443 -- it to match the given identifier name. If there is a non-matching
444 -- identifier, then an error message is given and Error_Pragmas raised.
445 -- In this version of the procedure, the identifier name is given as
446 -- a string with lower case letters.
448 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
449 -- Called to process a precondition or postcondition pragma. There are
452 -- The pragma appears after a subprogram spec
454 -- If the corresponding check is not enabled, the pragma is analyzed
455 -- but otherwise ignored and control returns with In_Body set False.
457 -- If the check is enabled, then the first step is to analyze the
458 -- pragma, but this is skipped if the subprogram spec appears within
459 -- a package specification (because this is the case where we delay
460 -- analysis till the end of the spec). Then (whether or not it was
461 -- analyzed), the pragma is chained to the subprogram in question
462 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
463 -- caller with In_Body set False.
465 -- The pragma appears at the start of subprogram body declarations
467 -- In this case an immediate return to the caller is made with
468 -- In_Body set True, and the pragma is NOT analyzed.
470 -- In all other cases, an error message for bad placement is given
472 procedure Check_Static_Constraint (Constr : Node_Id);
473 -- Constr is a constraint from an N_Subtype_Indication node from a
474 -- component constraint in an Unchecked_Union type. This routine checks
475 -- that the constraint is static as required by the restrictions for
478 procedure Check_Valid_Configuration_Pragma;
479 -- Legality checks for placement of a configuration pragma
481 procedure Check_Valid_Library_Unit_Pragma;
482 -- Legality checks for library unit pragmas. A special case arises for
483 -- pragmas in generic instances that come from copies of the original
484 -- library unit pragmas in the generic templates. In the case of other
485 -- than library level instantiations these can appear in contexts which
486 -- would normally be invalid (they only apply to the original template
487 -- and to library level instantiations), and they are simply ignored,
488 -- which is implemented by rewriting them as null statements.
490 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
491 -- Check an Unchecked_Union variant for lack of nested variants and
492 -- presence of at least one component. UU_Typ is the related Unchecked_
495 procedure Error_Pragma (Msg : String);
496 pragma No_Return (Error_Pragma);
497 -- Outputs error message for current pragma. The message contains a %
498 -- that will be replaced with the pragma name, and the flag is placed
499 -- on the pragma itself. Pragma_Exit is then raised.
501 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
502 pragma No_Return (Error_Pragma_Arg);
503 -- Outputs error message for current pragma. The message may contain
504 -- a % that will be replaced with the pragma name. The parameter Arg
505 -- may either be a pragma argument association, in which case the flag
506 -- is placed on the expression of this association, or an expression,
507 -- in which case the flag is placed directly on the expression. The
508 -- message is placed using Error_Msg_N, so the message may also contain
509 -- an & insertion character which will reference the given Arg value.
510 -- After placing the message, Pragma_Exit is raised.
512 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
513 pragma No_Return (Error_Pragma_Arg);
514 -- Similar to above form of Error_Pragma_Arg except that two messages
515 -- are provided, the second is a continuation comment starting with \.
517 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
518 pragma No_Return (Error_Pragma_Arg_Ident);
519 -- Outputs error message for current pragma. The message may contain
520 -- a % that will be replaced with the pragma name. The parameter Arg
521 -- must be a pragma argument association with a non-empty identifier
522 -- (i.e. its Chars field must be set), and the error message is placed
523 -- on the identifier. The message is placed using Error_Msg_N so
524 -- the message may also contain an & insertion character which will
525 -- reference the identifier. After placing the message, Pragma_Exit
528 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
529 pragma No_Return (Error_Pragma_Ref);
530 -- Outputs error message for current pragma. The message may contain
531 -- a % that will be replaced with the pragma name. The parameter Ref
532 -- must be an entity whose name can be referenced by & and sloc by #.
533 -- After placing the message, Pragma_Exit is raised.
535 function Find_Lib_Unit_Name return Entity_Id;
536 -- Used for a library unit pragma to find the entity to which the
537 -- library unit pragma applies, returns the entity found.
539 procedure Find_Program_Unit_Name (Id : Node_Id);
540 -- If the pragma is a compilation unit pragma, the id must denote the
541 -- compilation unit in the same compilation, and the pragma must appear
542 -- in the list of preceding or trailing pragmas. If it is a program
543 -- unit pragma that is not a compilation unit pragma, then the
544 -- identifier must be visible.
546 function Find_Unique_Parameterless_Procedure
548 Arg : Node_Id) return Entity_Id;
549 -- Used for a procedure pragma to find the unique parameterless
550 -- procedure identified by Name, returns it if it exists, otherwise
551 -- errors out and uses Arg as the pragma argument for the message.
553 procedure Fix_Error (Msg : in out String);
554 -- This is called prior to issuing an error message. Msg is a string
555 -- which typically contains the substring pragma. If the current pragma
556 -- comes from an aspect, each such "pragma" substring is replaced with
557 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
558 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
560 procedure Gather_Associations
562 Args : out Args_List);
563 -- This procedure is used to gather the arguments for a pragma that
564 -- permits arbitrary ordering of parameters using the normal rules
565 -- for named and positional parameters. The Names argument is a list
566 -- of Name_Id values that corresponds to the allowed pragma argument
567 -- association identifiers in order. The result returned in Args is
568 -- a list of corresponding expressions that are the pragma arguments.
569 -- Note that this is a list of expressions, not of pragma argument
570 -- associations (Gather_Associations has completely checked all the
571 -- optional identifiers when it returns). An entry in Args is Empty
572 -- on return if the corresponding argument is not present.
574 procedure GNAT_Pragma;
575 -- Called for all GNAT defined pragmas to check the relevant restriction
576 -- (No_Implementation_Pragmas).
578 function Is_Before_First_Decl
579 (Pragma_Node : Node_Id;
580 Decls : List_Id) return Boolean;
581 -- Return True if Pragma_Node is before the first declarative item in
582 -- Decls where Decls is the list of declarative items.
584 function Is_Configuration_Pragma return Boolean;
585 -- Determines if the placement of the current pragma is appropriate
586 -- for a configuration pragma.
588 function Is_In_Context_Clause return Boolean;
589 -- Returns True if pragma appears within the context clause of a unit,
590 -- and False for any other placement (does not generate any messages).
592 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
593 -- Analyzes the argument, and determines if it is a static string
594 -- expression, returns True if so, False if non-static or not String.
596 procedure Pragma_Misplaced;
597 pragma No_Return (Pragma_Misplaced);
598 -- Issue fatal error message for misplaced pragma
600 procedure Process_Atomic_Shared_Volatile;
601 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
602 -- Shared is an obsolete Ada 83 pragma, treated as being identical
603 -- in effect to pragma Atomic.
605 procedure Process_Compile_Time_Warning_Or_Error;
606 -- Common processing for Compile_Time_Error and Compile_Time_Warning
608 procedure Process_Convention
609 (C : out Convention_Id;
610 Ent : out Entity_Id);
611 -- Common processing for Convention, Interface, Import and Export.
612 -- Checks first two arguments of pragma, and sets the appropriate
613 -- convention value in the specified entity or entities. On return
614 -- C is the convention, Ent is the referenced entity.
616 procedure Process_Extended_Import_Export_Exception_Pragma
617 (Arg_Internal : Node_Id;
618 Arg_External : Node_Id;
621 -- Common processing for the pragmas Import/Export_Exception. The three
622 -- arguments correspond to the three named parameters of the pragma. An
623 -- argument is empty if the corresponding parameter is not present in
626 procedure Process_Extended_Import_Export_Object_Pragma
627 (Arg_Internal : Node_Id;
628 Arg_External : Node_Id;
630 -- Common processing for the pragmas Import/Export_Object. The three
631 -- arguments correspond to the three named parameters of the pragmas. An
632 -- argument is empty if the corresponding parameter is not present in
635 procedure Process_Extended_Import_Export_Internal_Arg
636 (Arg_Internal : Node_Id := Empty);
637 -- Common processing for all extended Import and Export pragmas. The
638 -- argument is the pragma parameter for the Internal argument. If
639 -- Arg_Internal is empty or inappropriate, an error message is posted.
640 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
641 -- set to identify the referenced entity.
643 procedure Process_Extended_Import_Export_Subprogram_Pragma
644 (Arg_Internal : Node_Id;
645 Arg_External : Node_Id;
646 Arg_Parameter_Types : Node_Id;
647 Arg_Result_Type : Node_Id := Empty;
648 Arg_Mechanism : Node_Id;
649 Arg_Result_Mechanism : Node_Id := Empty;
650 Arg_First_Optional_Parameter : Node_Id := Empty);
651 -- Common processing for all extended Import and Export pragmas applying
652 -- to subprograms. The caller omits any arguments that do not apply to
653 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
654 -- only in the Import_Function and Export_Function cases). The argument
655 -- names correspond to the allowed pragma association identifiers.
657 procedure Process_Generic_List;
658 -- Common processing for Share_Generic and Inline_Generic
660 procedure Process_Import_Or_Interface;
661 -- Common processing for Import of Interface
663 procedure Process_Import_Predefined_Type;
664 -- Processing for completing a type with pragma Import. This is used
665 -- to declare types that match predefined C types, especially for cases
666 -- without corresponding Ada predefined type.
668 procedure Process_Inline (Active : Boolean);
669 -- Common processing for Inline and Inline_Always. The parameter
670 -- indicates if the inline pragma is active, i.e. if it should actually
671 -- cause inlining to occur.
673 procedure Process_Interface_Name
674 (Subprogram_Def : Entity_Id;
677 -- Given the last two arguments of pragma Import, pragma Export, or
678 -- pragma Interface_Name, performs validity checks and sets the
679 -- Interface_Name field of the given subprogram entity to the
680 -- appropriate external or link name, depending on the arguments given.
681 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
682 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
683 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
684 -- nor Link_Arg is present, the interface name is set to the default
685 -- from the subprogram name.
687 procedure Process_Interrupt_Or_Attach_Handler;
688 -- Common processing for Interrupt and Attach_Handler pragmas
690 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
691 -- Common processing for Restrictions and Restriction_Warnings pragmas.
692 -- Warn is True for Restriction_Warnings, or for Restrictions if the
693 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
694 -- is not set in the Restrictions case.
696 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
697 -- Common processing for Suppress and Unsuppress. The boolean parameter
698 -- Suppress_Case is True for the Suppress case, and False for the
701 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
702 -- This procedure sets the Is_Exported flag for the given entity,
703 -- checking that the entity was not previously imported. Arg is
704 -- the argument that specified the entity. A check is also made
705 -- for exporting inappropriate entities.
707 procedure Set_Extended_Import_Export_External_Name
708 (Internal_Ent : Entity_Id;
709 Arg_External : Node_Id);
710 -- Common processing for all extended import export pragmas. The first
711 -- argument, Internal_Ent, is the internal entity, which has already
712 -- been checked for validity by the caller. Arg_External is from the
713 -- Import or Export pragma, and may be null if no External parameter
714 -- was present. If Arg_External is present and is a non-null string
715 -- (a null string is treated as the default), then the Interface_Name
716 -- field of Internal_Ent is set appropriately.
718 procedure Set_Imported (E : Entity_Id);
719 -- This procedure sets the Is_Imported flag for the given entity,
720 -- checking that it is not previously exported or imported.
722 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
723 -- Mech is a parameter passing mechanism (see Import_Function syntax
724 -- for MECHANISM_NAME). This routine checks that the mechanism argument
725 -- has the right form, and if not issues an error message. If the
726 -- argument has the right form then the Mechanism field of Ent is
727 -- set appropriately.
729 procedure Set_Ravenscar_Profile (N : Node_Id);
730 -- Activate the set of configuration pragmas and restrictions that make
731 -- up the Ravenscar Profile. N is the corresponding pragma node, which
732 -- is used for error messages on any constructs that violate the
735 ---------------------
736 -- Ada_2005_Pragma --
737 ---------------------
739 procedure Ada_2005_Pragma is
741 if Ada_Version <= Ada_95 then
742 Check_Restriction (No_Implementation_Pragmas, N);
746 ---------------------
747 -- Ada_2012_Pragma --
748 ---------------------
750 procedure Ada_2012_Pragma is
752 if Ada_Version <= Ada_2005 then
753 Check_Restriction (No_Implementation_Pragmas, N);
757 --------------------------
758 -- Check_Ada_83_Warning --
759 --------------------------
761 procedure Check_Ada_83_Warning is
763 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
764 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
766 end Check_Ada_83_Warning;
768 ---------------------
769 -- Check_Arg_Count --
770 ---------------------
772 procedure Check_Arg_Count (Required : Nat) is
774 if Arg_Count /= Required then
775 Error_Pragma ("wrong number of arguments for pragma%");
779 --------------------------------
780 -- Check_Arg_Is_External_Name --
781 --------------------------------
783 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
784 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
787 if Nkind (Argx) = N_Identifier then
791 Analyze_And_Resolve (Argx, Standard_String);
793 if Is_OK_Static_Expression (Argx) then
796 elsif Etype (Argx) = Any_Type then
799 -- An interesting special case, if we have a string literal and
800 -- we are in Ada 83 mode, then we allow it even though it will
801 -- not be flagged as static. This allows expected Ada 83 mode
802 -- use of external names which are string literals, even though
803 -- technically these are not static in Ada 83.
805 elsif Ada_Version = Ada_83
806 and then Nkind (Argx) = N_String_Literal
810 -- Static expression that raises Constraint_Error. This has
811 -- already been flagged, so just exit from pragma processing.
813 elsif Is_Static_Expression (Argx) then
816 -- Here we have a real error (non-static expression)
819 Error_Msg_Name_1 := Pname;
823 "argument for pragma% must be a identifier or "
824 & "static string expression!";
827 Flag_Non_Static_Expr (Msg, Argx);
832 end Check_Arg_Is_External_Name;
834 -----------------------------
835 -- Check_Arg_Is_Identifier --
836 -----------------------------
838 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
839 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
841 if Nkind (Argx) /= N_Identifier then
843 ("argument for pragma% must be identifier", Argx);
845 end Check_Arg_Is_Identifier;
847 ----------------------------------
848 -- Check_Arg_Is_Integer_Literal --
849 ----------------------------------
851 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
852 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
854 if Nkind (Argx) /= N_Integer_Literal then
856 ("argument for pragma% must be integer literal", Argx);
858 end Check_Arg_Is_Integer_Literal;
860 -------------------------------------------
861 -- Check_Arg_Is_Library_Level_Local_Name --
862 -------------------------------------------
866 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
867 -- | library_unit_NAME
869 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
871 Check_Arg_Is_Local_Name (Arg);
873 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
874 and then Comes_From_Source (N)
877 ("argument for pragma% must be library level entity", Arg);
879 end Check_Arg_Is_Library_Level_Local_Name;
881 -----------------------------
882 -- Check_Arg_Is_Local_Name --
883 -----------------------------
887 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
888 -- | library_unit_NAME
890 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
891 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
896 if Nkind (Argx) not in N_Direct_Name
897 and then (Nkind (Argx) /= N_Attribute_Reference
898 or else Present (Expressions (Argx))
899 or else Nkind (Prefix (Argx)) /= N_Identifier)
900 and then (not Is_Entity_Name (Argx)
901 or else not Is_Compilation_Unit (Entity (Argx)))
903 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
906 -- No further check required if not an entity name
908 if not Is_Entity_Name (Argx) then
914 Ent : constant Entity_Id := Entity (Argx);
915 Scop : constant Entity_Id := Scope (Ent);
917 -- Case of a pragma applied to a compilation unit: pragma must
918 -- occur immediately after the program unit in the compilation.
920 if Is_Compilation_Unit (Ent) then
922 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
924 -- Case of pragma placed immediately after spec
926 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
929 -- Case of pragma placed immediately after body
931 elsif Nkind (Decl) = N_Subprogram_Declaration
932 and then Present (Corresponding_Body (Decl))
936 (Parent (Unit_Declaration_Node
937 (Corresponding_Body (Decl))));
939 -- All other cases are illegal
946 -- Special restricted placement rule from 10.2.1(11.8/2)
948 elsif Is_Generic_Formal (Ent)
949 and then Prag_Id = Pragma_Preelaborable_Initialization
951 OK := List_Containing (N) =
952 Generic_Formal_Declarations
953 (Unit_Declaration_Node (Scop));
955 -- Default case, just check that the pragma occurs in the scope
956 -- of the entity denoted by the name.
959 OK := Current_Scope = Scop;
964 ("pragma% argument must be in same declarative part", Arg);
968 end Check_Arg_Is_Local_Name;
970 ---------------------------------
971 -- Check_Arg_Is_Locking_Policy --
972 ---------------------------------
974 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
975 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
978 Check_Arg_Is_Identifier (Argx);
980 if not Is_Locking_Policy_Name (Chars (Argx)) then
981 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
983 end Check_Arg_Is_Locking_Policy;
985 -------------------------
986 -- Check_Arg_Is_One_Of --
987 -------------------------
989 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
990 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
993 Check_Arg_Is_Identifier (Argx);
995 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
996 Error_Msg_Name_2 := N1;
997 Error_Msg_Name_3 := N2;
998 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1000 end Check_Arg_Is_One_Of;
1002 procedure Check_Arg_Is_One_Of
1004 N1, N2, N3 : Name_Id)
1006 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1009 Check_Arg_Is_Identifier (Argx);
1011 if Chars (Argx) /= N1
1012 and then Chars (Argx) /= N2
1013 and then Chars (Argx) /= N3
1015 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1017 end Check_Arg_Is_One_Of;
1019 procedure Check_Arg_Is_One_Of
1021 N1, N2, N3, N4 : Name_Id)
1023 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1026 Check_Arg_Is_Identifier (Argx);
1028 if Chars (Argx) /= N1
1029 and then Chars (Argx) /= N2
1030 and then Chars (Argx) /= N3
1031 and then Chars (Argx) /= N4
1033 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1035 end Check_Arg_Is_One_Of;
1036 ---------------------------------
1037 -- Check_Arg_Is_Queuing_Policy --
1038 ---------------------------------
1040 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1041 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1044 Check_Arg_Is_Identifier (Argx);
1046 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1047 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1049 end Check_Arg_Is_Queuing_Policy;
1051 ------------------------------------
1052 -- Check_Arg_Is_Static_Expression --
1053 ------------------------------------
1055 procedure Check_Arg_Is_Static_Expression
1057 Typ : Entity_Id := Empty)
1059 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1062 if Present (Typ) then
1063 Analyze_And_Resolve (Argx, Typ);
1065 Analyze_And_Resolve (Argx);
1068 if Is_OK_Static_Expression (Argx) then
1071 elsif Etype (Argx) = Any_Type then
1074 -- An interesting special case, if we have a string literal and we
1075 -- are in Ada 83 mode, then we allow it even though it will not be
1076 -- flagged as static. This allows the use of Ada 95 pragmas like
1077 -- Import in Ada 83 mode. They will of course be flagged with
1078 -- warnings as usual, but will not cause errors.
1080 elsif Ada_Version = Ada_83
1081 and then Nkind (Argx) = N_String_Literal
1085 -- Static expression that raises Constraint_Error. This has already
1086 -- been flagged, so just exit from pragma processing.
1088 elsif Is_Static_Expression (Argx) then
1091 -- Finally, we have a real error
1094 Error_Msg_Name_1 := Pname;
1098 "argument for pragma% must be a static expression!";
1101 Flag_Non_Static_Expr (Msg, Argx);
1106 end Check_Arg_Is_Static_Expression;
1108 ------------------------------------------
1109 -- Check_Arg_Is_Task_Dispatching_Policy --
1110 ------------------------------------------
1112 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1113 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1116 Check_Arg_Is_Identifier (Argx);
1118 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1120 ("& is not a valid task dispatching policy name", Argx);
1122 end Check_Arg_Is_Task_Dispatching_Policy;
1124 ---------------------
1125 -- Check_Arg_Order --
1126 ---------------------
1128 procedure Check_Arg_Order (Names : Name_List) is
1131 Highest_So_Far : Natural := 0;
1132 -- Highest index in Names seen do far
1136 for J in 1 .. Arg_Count loop
1137 if Chars (Arg) /= No_Name then
1138 for K in Names'Range loop
1139 if Chars (Arg) = Names (K) then
1140 if K < Highest_So_Far then
1141 Error_Msg_Name_1 := Pname;
1143 ("parameters out of order for pragma%", Arg);
1144 Error_Msg_Name_1 := Names (K);
1145 Error_Msg_Name_2 := Names (Highest_So_Far);
1146 Error_Msg_N ("\% must appear before %", Arg);
1150 Highest_So_Far := K;
1158 end Check_Arg_Order;
1160 --------------------------------
1161 -- Check_At_Least_N_Arguments --
1162 --------------------------------
1164 procedure Check_At_Least_N_Arguments (N : Nat) is
1166 if Arg_Count < N then
1167 Error_Pragma ("too few arguments for pragma%");
1169 end Check_At_Least_N_Arguments;
1171 -------------------------------
1172 -- Check_At_Most_N_Arguments --
1173 -------------------------------
1175 procedure Check_At_Most_N_Arguments (N : Nat) is
1178 if Arg_Count > N then
1180 for J in 1 .. N loop
1182 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1185 end Check_At_Most_N_Arguments;
1187 ---------------------
1188 -- Check_Component --
1189 ---------------------
1191 procedure Check_Component
1194 In_Variant_Part : Boolean := False)
1196 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1197 Sindic : constant Node_Id :=
1198 Subtype_Indication (Component_Definition (Comp));
1199 Typ : constant Entity_Id := Etype (Comp_Id);
1201 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1202 -- Determine whether entity Id appears inside a generic body.
1203 -- Shouldn't this be in a more general place ???
1205 -------------------------
1206 -- Inside_Generic_Body --
1207 -------------------------
1209 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1214 while Present (S) and then S /= Standard_Standard loop
1215 if Ekind (S) = E_Generic_Package
1216 and then In_Package_Body (S)
1225 end Inside_Generic_Body;
1227 -- Start of processing for Check_Component
1230 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1231 -- object constraint, then the component type shall be an Unchecked_
1234 if Nkind (Sindic) = N_Subtype_Indication
1235 and then Has_Per_Object_Constraint (Comp_Id)
1236 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1239 ("component subtype subject to per-object constraint " &
1240 "must be an Unchecked_Union", Comp);
1242 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1243 -- the body of a generic unit, or within the body of any of its
1244 -- descendant library units, no part of the type of a component
1245 -- declared in a variant_part of the unchecked union type shall be of
1246 -- a formal private type or formal private extension declared within
1247 -- the formal part of the generic unit.
1249 elsif Ada_Version >= Ada_2012
1250 and then Inside_Generic_Body (UU_Typ)
1251 and then In_Variant_Part
1252 and then Is_Private_Type (Typ)
1253 and then Is_Generic_Type (Typ)
1256 ("component of Unchecked_Union cannot be of generic type", Comp);
1258 elsif Needs_Finalization (Typ) then
1260 ("component of Unchecked_Union cannot be controlled", Comp);
1262 elsif Has_Task (Typ) then
1264 ("component of Unchecked_Union cannot have tasks", Comp);
1266 end Check_Component;
1268 ----------------------------
1269 -- Check_Duplicate_Pragma --
1270 ----------------------------
1272 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1276 -- Nothing to do if this pragma comes from an aspect specification,
1277 -- since we could not be duplicating a pragma, and we dealt with the
1278 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1280 if From_Aspect_Specification (N) then
1284 -- Otherwise current pragma may duplicate previous pragma or a
1285 -- previously given aspect specification for the same pragma.
1287 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1290 Error_Msg_Name_1 := Pragma_Name (N);
1291 Error_Msg_Sloc := Sloc (P);
1293 if Nkind (P) = N_Aspect_Specification
1294 or else From_Aspect_Specification (P)
1296 Error_Msg_NE ("aspect% for & previously given#", N, E);
1298 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1303 end Check_Duplicate_Pragma;
1305 ----------------------------------
1306 -- Check_Duplicated_Export_Name --
1307 ----------------------------------
1309 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1310 String_Val : constant String_Id := Strval (Nam);
1313 -- We are only interested in the export case, and in the case of
1314 -- generics, it is the instance, not the template, that is the
1315 -- problem (the template will generate a warning in any case).
1317 if not Inside_A_Generic
1318 and then (Prag_Id = Pragma_Export
1320 Prag_Id = Pragma_Export_Procedure
1322 Prag_Id = Pragma_Export_Valued_Procedure
1324 Prag_Id = Pragma_Export_Function)
1326 for J in Externals.First .. Externals.Last loop
1327 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1328 Error_Msg_Sloc := Sloc (Externals.Table (J));
1329 Error_Msg_N ("external name duplicates name given#", Nam);
1334 Externals.Append (Nam);
1336 end Check_Duplicated_Export_Name;
1338 -------------------------
1339 -- Check_First_Subtype --
1340 -------------------------
1342 procedure Check_First_Subtype (Arg : Node_Id) is
1343 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1344 Ent : constant Entity_Id := Entity (Argx);
1347 if Is_First_Subtype (Ent) then
1350 elsif Is_Type (Ent) then
1352 ("pragma% cannot apply to subtype", Argx);
1354 elsif Is_Object (Ent) then
1356 ("pragma% cannot apply to object, requires a type", Argx);
1360 ("pragma% cannot apply to&, requires a type", Argx);
1362 end Check_First_Subtype;
1364 ---------------------------
1365 -- Check_In_Main_Program --
1366 ---------------------------
1368 procedure Check_In_Main_Program is
1369 P : constant Node_Id := Parent (N);
1372 -- Must be at in subprogram body
1374 if Nkind (P) /= N_Subprogram_Body then
1375 Error_Pragma ("% pragma allowed only in subprogram");
1377 -- Otherwise warn if obviously not main program
1379 elsif Present (Parameter_Specifications (Specification (P)))
1380 or else not Is_Compilation_Unit (Defining_Entity (P))
1382 Error_Msg_Name_1 := Pname;
1384 ("?pragma% is only effective in main program", N);
1386 end Check_In_Main_Program;
1388 ---------------------------------------
1389 -- Check_Interrupt_Or_Attach_Handler --
1390 ---------------------------------------
1392 procedure Check_Interrupt_Or_Attach_Handler is
1393 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1394 Handler_Proc, Proc_Scope : Entity_Id;
1399 if Prag_Id = Pragma_Interrupt_Handler then
1400 Check_Restriction (No_Dynamic_Attachment, N);
1403 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1404 Proc_Scope := Scope (Handler_Proc);
1406 -- On AAMP only, a pragma Interrupt_Handler is supported for
1407 -- nonprotected parameterless procedures.
1409 if not AAMP_On_Target
1410 or else Prag_Id = Pragma_Attach_Handler
1412 if Ekind (Proc_Scope) /= E_Protected_Type then
1414 ("argument of pragma% must be protected procedure", Arg1);
1417 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1418 Error_Pragma ("pragma% must be in protected definition");
1422 if not Is_Library_Level_Entity (Proc_Scope)
1423 or else (AAMP_On_Target
1424 and then not Is_Library_Level_Entity (Handler_Proc))
1427 ("argument for pragma% must be library level entity", Arg1);
1430 -- AI05-0033: A pragma cannot appear within a generic body, because
1431 -- instance can be in a nested scope. The check that protected type
1432 -- is itself a library-level declaration is done elsewhere.
1434 -- Note: we omit this check in Codepeer mode to properly handle code
1435 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1437 if Inside_A_Generic then
1438 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1439 and then In_Package_Body (Scope (Current_Scope))
1440 and then not CodePeer_Mode
1442 Error_Pragma ("pragma% cannot be used inside a generic");
1445 end Check_Interrupt_Or_Attach_Handler;
1447 -------------------------------------------
1448 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1449 -------------------------------------------
1451 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1460 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1463 elsif Nkind_In (P, N_Package_Specification,
1468 -- Note: the following tests seem a little peculiar, because
1469 -- they test for bodies, but if we were in the statement part
1470 -- of the body, we would already have hit the handled statement
1471 -- sequence, so the only way we get here is by being in the
1472 -- declarative part of the body.
1474 elsif Nkind_In (P, N_Subprogram_Body,
1485 Error_Pragma ("pragma% is not in declarative part or package spec");
1486 end Check_Is_In_Decl_Part_Or_Package_Spec;
1488 -------------------------
1489 -- Check_No_Identifier --
1490 -------------------------
1492 procedure Check_No_Identifier (Arg : Node_Id) is
1494 if Nkind (Arg) = N_Pragma_Argument_Association
1495 and then Chars (Arg) /= No_Name
1497 Error_Pragma_Arg_Ident
1498 ("pragma% does not permit identifier& here", Arg);
1500 end Check_No_Identifier;
1502 --------------------------
1503 -- Check_No_Identifiers --
1504 --------------------------
1506 procedure Check_No_Identifiers is
1509 if Arg_Count > 0 then
1511 while Present (Arg_Node) loop
1512 Check_No_Identifier (Arg_Node);
1516 end Check_No_Identifiers;
1518 ------------------------
1519 -- Check_No_Link_Name --
1520 ------------------------
1522 procedure Check_No_Link_Name is
1525 and then Chars (Arg3) = Name_Link_Name
1530 if Present (Arg4) then
1532 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1534 end Check_No_Link_Name;
1536 -------------------------------
1537 -- Check_Optional_Identifier --
1538 -------------------------------
1540 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1543 and then Nkind (Arg) = N_Pragma_Argument_Association
1544 and then Chars (Arg) /= No_Name
1546 if Chars (Arg) /= Id then
1547 Error_Msg_Name_1 := Pname;
1548 Error_Msg_Name_2 := Id;
1549 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1553 end Check_Optional_Identifier;
1555 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1557 Name_Buffer (1 .. Id'Length) := Id;
1558 Name_Len := Id'Length;
1559 Check_Optional_Identifier (Arg, Name_Find);
1560 end Check_Optional_Identifier;
1562 --------------------------------------
1563 -- Check_Precondition_Postcondition --
1564 --------------------------------------
1566 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1570 procedure Chain_PPC (PO : Node_Id);
1571 -- If PO is a subprogram declaration node (or a generic subprogram
1572 -- declaration node), then the precondition/postcondition applies
1573 -- to this subprogram and the processing for the pragma is completed.
1574 -- Otherwise the pragma is misplaced.
1580 procedure Chain_PPC (PO : Node_Id) is
1585 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1586 if not From_Aspect_Specification (N) then
1588 ("pragma% cannot be applied to abstract subprogram");
1590 elsif Class_Present (N) then
1595 ("aspect % requires ''Class for abstract subprogram");
1598 -- AI05-0230: The same restriction applies to null procedures. For
1599 -- compatibility with earlier uses of the Ada pragma, apply this
1600 -- rule only to aspect specifications.
1602 -- The above discrpency needs documentation. Robert is dubious
1603 -- about whether it is a good idea ???
1605 elsif Nkind (PO) = N_Subprogram_Declaration
1606 and then Nkind (Specification (PO)) = N_Procedure_Specification
1607 and then Null_Present (Specification (PO))
1608 and then From_Aspect_Specification (N)
1609 and then not Class_Present (N)
1612 ("aspect % requires ''Class for null procedure");
1614 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1615 N_Generic_Subprogram_Declaration,
1616 N_Entry_Declaration)
1621 -- Here if we have [generic] subprogram or entry declaration
1623 if Nkind (PO) = N_Entry_Declaration then
1624 S := Defining_Entity (PO);
1626 S := Defining_Unit_Name (Specification (PO));
1629 -- Make sure we do not have the case of a precondition pragma when
1630 -- the Pre'Class aspect is present.
1632 -- We do this by looking at pragmas already chained to the entity
1633 -- since the aspect derived pragma will be put on this list first.
1635 if Pragma_Name (N) = Name_Precondition then
1636 if not From_Aspect_Specification (N) then
1637 P := Spec_PPC_List (S);
1638 while Present (P) loop
1639 if Pragma_Name (P) = Name_Precondition
1640 and then From_Aspect_Specification (P)
1641 and then Class_Present (P)
1643 Error_Msg_Sloc := Sloc (P);
1645 ("pragma% not allowed, `Pre''Class` aspect given#");
1648 P := Next_Pragma (P);
1653 -- Similarly check for Pre with inherited Pre'Class. Note that
1654 -- we cover the aspect case as well here.
1656 if Pragma_Name (N) = Name_Precondition
1657 and then not Class_Present (N)
1660 Inherited : constant Subprogram_List :=
1661 Inherited_Subprograms (S);
1665 for J in Inherited'Range loop
1666 P := Spec_PPC_List (Inherited (J));
1667 while Present (P) loop
1668 if Pragma_Name (P) = Name_Precondition
1669 and then Class_Present (P)
1671 Error_Msg_Sloc := Sloc (P);
1673 ("pragma% not allowed, `Pre''Class` "
1674 & "aspect inherited from#");
1677 P := Next_Pragma (P);
1683 -- Note: we do not analyze the pragma at this point. Instead we
1684 -- delay this analysis until the end of the declarative part in
1685 -- which the pragma appears. This implements the required delay
1686 -- in this analysis, allowing forward references. The analysis
1687 -- happens at the end of Analyze_Declarations.
1689 -- Chain spec PPC pragma to list for subprogram
1691 Set_Next_Pragma (N, Spec_PPC_List (S));
1692 Set_Spec_PPC_List (S, N);
1694 -- Return indicating spec case
1700 -- Start of processing for Check_Precondition_Postcondition
1703 if not Is_List_Member (N) then
1707 -- Preanalyze message argument if present. Visibility in this
1708 -- argument is established at the point of pragma occurrence.
1710 if Arg_Count = 2 then
1711 Check_Optional_Identifier (Arg2, Name_Message);
1712 Preanalyze_Spec_Expression
1713 (Get_Pragma_Arg (Arg2), Standard_String);
1716 -- Record if pragma is enabled
1718 if Check_Enabled (Pname) then
1719 Set_Pragma_Enabled (N);
1720 Set_SCO_Pragma_Enabled (Loc);
1723 -- If we are within an inlined body, the legality of the pragma
1724 -- has been checked already.
1726 if In_Inlined_Body then
1731 -- Search prior declarations
1734 while Present (Prev (P)) loop
1737 -- If the previous node is a generic subprogram, do not go to to
1738 -- the original node, which is the unanalyzed tree: we need to
1739 -- attach the pre/postconditions to the analyzed version at this
1740 -- point. They get propagated to the original tree when analyzing
1741 -- the corresponding body.
1743 if Nkind (P) not in N_Generic_Declaration then
1744 PO := Original_Node (P);
1749 -- Skip past prior pragma
1751 if Nkind (PO) = N_Pragma then
1754 -- Skip stuff not coming from source
1756 elsif not Comes_From_Source (PO) then
1758 -- The condition may apply to a subprogram instantiation
1760 if Nkind (PO) = N_Subprogram_Declaration
1761 and then Present (Generic_Parent (Specification (PO)))
1766 -- For all other cases of non source code, do nothing
1772 -- Only remaining possibility is subprogram declaration
1780 -- If we fall through loop, pragma is at start of list, so see if it
1781 -- is at the start of declarations of a subprogram body.
1783 if Nkind (Parent (N)) = N_Subprogram_Body
1784 and then List_Containing (N) = Declarations (Parent (N))
1786 if Operating_Mode /= Generate_Code
1787 or else Inside_A_Generic
1789 -- Analyze pragma expression for correctness and for ASIS use
1791 Preanalyze_Spec_Expression
1792 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1798 -- See if it is in the pragmas after a library level subprogram
1800 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1801 Chain_PPC (Unit (Parent (Parent (N))));
1805 -- If we fall through, pragma was misplaced
1808 end Check_Precondition_Postcondition;
1810 -----------------------------
1811 -- Check_Static_Constraint --
1812 -----------------------------
1814 -- Note: for convenience in writing this procedure, in addition to
1815 -- the officially (i.e. by spec) allowed argument which is always a
1816 -- constraint, it also allows ranges and discriminant associations.
1817 -- Above is not clear ???
1819 procedure Check_Static_Constraint (Constr : Node_Id) is
1821 procedure Require_Static (E : Node_Id);
1822 -- Require given expression to be static expression
1824 --------------------
1825 -- Require_Static --
1826 --------------------
1828 procedure Require_Static (E : Node_Id) is
1830 if not Is_OK_Static_Expression (E) then
1831 Flag_Non_Static_Expr
1832 ("non-static constraint not allowed in Unchecked_Union!", E);
1837 -- Start of processing for Check_Static_Constraint
1840 case Nkind (Constr) is
1841 when N_Discriminant_Association =>
1842 Require_Static (Expression (Constr));
1845 Require_Static (Low_Bound (Constr));
1846 Require_Static (High_Bound (Constr));
1848 when N_Attribute_Reference =>
1849 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1850 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1852 when N_Range_Constraint =>
1853 Check_Static_Constraint (Range_Expression (Constr));
1855 when N_Index_Or_Discriminant_Constraint =>
1859 IDC := First (Constraints (Constr));
1860 while Present (IDC) loop
1861 Check_Static_Constraint (IDC);
1869 end Check_Static_Constraint;
1871 --------------------------------------
1872 -- Check_Valid_Configuration_Pragma --
1873 --------------------------------------
1875 -- A configuration pragma must appear in the context clause of a
1876 -- compilation unit, and only other pragmas may precede it. Note that
1877 -- the test also allows use in a configuration pragma file.
1879 procedure Check_Valid_Configuration_Pragma is
1881 if not Is_Configuration_Pragma then
1882 Error_Pragma ("incorrect placement for configuration pragma%");
1884 end Check_Valid_Configuration_Pragma;
1886 -------------------------------------
1887 -- Check_Valid_Library_Unit_Pragma --
1888 -------------------------------------
1890 procedure Check_Valid_Library_Unit_Pragma is
1892 Parent_Node : Node_Id;
1893 Unit_Name : Entity_Id;
1894 Unit_Kind : Node_Kind;
1895 Unit_Node : Node_Id;
1896 Sindex : Source_File_Index;
1899 if not Is_List_Member (N) then
1903 Plist := List_Containing (N);
1904 Parent_Node := Parent (Plist);
1906 if Parent_Node = Empty then
1909 -- Case of pragma appearing after a compilation unit. In this case
1910 -- it must have an argument with the corresponding name and must
1911 -- be part of the following pragmas of its parent.
1913 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1914 if Plist /= Pragmas_After (Parent_Node) then
1917 elsif Arg_Count = 0 then
1919 ("argument required if outside compilation unit");
1922 Check_No_Identifiers;
1923 Check_Arg_Count (1);
1924 Unit_Node := Unit (Parent (Parent_Node));
1925 Unit_Kind := Nkind (Unit_Node);
1927 Analyze (Get_Pragma_Arg (Arg1));
1929 if Unit_Kind = N_Generic_Subprogram_Declaration
1930 or else Unit_Kind = N_Subprogram_Declaration
1932 Unit_Name := Defining_Entity (Unit_Node);
1934 elsif Unit_Kind in N_Generic_Instantiation then
1935 Unit_Name := Defining_Entity (Unit_Node);
1938 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1941 if Chars (Unit_Name) /=
1942 Chars (Entity (Get_Pragma_Arg (Arg1)))
1945 ("pragma% argument is not current unit name", Arg1);
1948 if Ekind (Unit_Name) = E_Package
1949 and then Present (Renamed_Entity (Unit_Name))
1951 Error_Pragma ("pragma% not allowed for renamed package");
1955 -- Pragma appears other than after a compilation unit
1958 -- Here we check for the generic instantiation case and also
1959 -- for the case of processing a generic formal package. We
1960 -- detect these cases by noting that the Sloc on the node
1961 -- does not belong to the current compilation unit.
1963 Sindex := Source_Index (Current_Sem_Unit);
1965 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1966 Rewrite (N, Make_Null_Statement (Loc));
1969 -- If before first declaration, the pragma applies to the
1970 -- enclosing unit, and the name if present must be this name.
1972 elsif Is_Before_First_Decl (N, Plist) then
1973 Unit_Node := Unit_Declaration_Node (Current_Scope);
1974 Unit_Kind := Nkind (Unit_Node);
1976 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1979 elsif Unit_Kind = N_Subprogram_Body
1980 and then not Acts_As_Spec (Unit_Node)
1984 elsif Nkind (Parent_Node) = N_Package_Body then
1987 elsif Nkind (Parent_Node) = N_Package_Specification
1988 and then Plist = Private_Declarations (Parent_Node)
1992 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1993 or else Nkind (Parent_Node) =
1994 N_Generic_Subprogram_Declaration)
1995 and then Plist = Generic_Formal_Declarations (Parent_Node)
1999 elsif Arg_Count > 0 then
2000 Analyze (Get_Pragma_Arg (Arg1));
2002 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2004 ("name in pragma% must be enclosing unit", Arg1);
2007 -- It is legal to have no argument in this context
2013 -- Error if not before first declaration. This is because a
2014 -- library unit pragma argument must be the name of a library
2015 -- unit (RM 10.1.5(7)), but the only names permitted in this
2016 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2017 -- generic subprogram declarations or generic instantiations.
2021 ("pragma% misplaced, must be before first declaration");
2025 end Check_Valid_Library_Unit_Pragma;
2031 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2032 Clist : constant Node_Id := Component_List (Variant);
2036 if not Is_Non_Empty_List (Component_Items (Clist)) then
2038 ("Unchecked_Union may not have empty component list",
2043 Comp := First (Component_Items (Clist));
2044 while Present (Comp) loop
2045 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2054 procedure Error_Pragma (Msg : String) is
2055 MsgF : String := Msg;
2057 Error_Msg_Name_1 := Pname;
2059 Error_Msg_N (MsgF, N);
2063 ----------------------
2064 -- Error_Pragma_Arg --
2065 ----------------------
2067 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2068 MsgF : String := Msg;
2070 Error_Msg_Name_1 := Pname;
2072 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2074 end Error_Pragma_Arg;
2076 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2077 MsgF : String := Msg1;
2079 Error_Msg_Name_1 := Pname;
2081 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2082 Error_Pragma_Arg (Msg2, Arg);
2083 end Error_Pragma_Arg;
2085 ----------------------------
2086 -- Error_Pragma_Arg_Ident --
2087 ----------------------------
2089 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2090 MsgF : String := Msg;
2092 Error_Msg_Name_1 := Pname;
2094 Error_Msg_N (MsgF, Arg);
2096 end Error_Pragma_Arg_Ident;
2098 ----------------------
2099 -- Error_Pragma_Ref --
2100 ----------------------
2102 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2103 MsgF : String := Msg;
2105 Error_Msg_Name_1 := Pname;
2107 Error_Msg_Sloc := Sloc (Ref);
2108 Error_Msg_NE (MsgF, N, Ref);
2110 end Error_Pragma_Ref;
2112 ------------------------
2113 -- Find_Lib_Unit_Name --
2114 ------------------------
2116 function Find_Lib_Unit_Name return Entity_Id is
2118 -- Return inner compilation unit entity, for case of nested
2119 -- categorization pragmas. This happens in generic unit.
2121 if Nkind (Parent (N)) = N_Package_Specification
2122 and then Defining_Entity (Parent (N)) /= Current_Scope
2124 return Defining_Entity (Parent (N));
2126 return Current_Scope;
2128 end Find_Lib_Unit_Name;
2130 ----------------------------
2131 -- Find_Program_Unit_Name --
2132 ----------------------------
2134 procedure Find_Program_Unit_Name (Id : Node_Id) is
2135 Unit_Name : Entity_Id;
2136 Unit_Kind : Node_Kind;
2137 P : constant Node_Id := Parent (N);
2140 if Nkind (P) = N_Compilation_Unit then
2141 Unit_Kind := Nkind (Unit (P));
2143 if Unit_Kind = N_Subprogram_Declaration
2144 or else Unit_Kind = N_Package_Declaration
2145 or else Unit_Kind in N_Generic_Declaration
2147 Unit_Name := Defining_Entity (Unit (P));
2149 if Chars (Id) = Chars (Unit_Name) then
2150 Set_Entity (Id, Unit_Name);
2151 Set_Etype (Id, Etype (Unit_Name));
2153 Set_Etype (Id, Any_Type);
2155 ("cannot find program unit referenced by pragma%");
2159 Set_Etype (Id, Any_Type);
2160 Error_Pragma ("pragma% inapplicable to this unit");
2166 end Find_Program_Unit_Name;
2168 -----------------------------------------
2169 -- Find_Unique_Parameterless_Procedure --
2170 -----------------------------------------
2172 function Find_Unique_Parameterless_Procedure
2174 Arg : Node_Id) return Entity_Id
2176 Proc : Entity_Id := Empty;
2179 -- The body of this procedure needs some comments ???
2181 if not Is_Entity_Name (Name) then
2183 ("argument of pragma% must be entity name", Arg);
2185 elsif not Is_Overloaded (Name) then
2186 Proc := Entity (Name);
2188 if Ekind (Proc) /= E_Procedure
2189 or else Present (First_Formal (Proc))
2192 ("argument of pragma% must be parameterless procedure", Arg);
2197 Found : Boolean := False;
2199 Index : Interp_Index;
2202 Get_First_Interp (Name, Index, It);
2203 while Present (It.Nam) loop
2206 if Ekind (Proc) = E_Procedure
2207 and then No (First_Formal (Proc))
2211 Set_Entity (Name, Proc);
2212 Set_Is_Overloaded (Name, False);
2215 ("ambiguous handler name for pragma% ", Arg);
2219 Get_Next_Interp (Index, It);
2224 ("argument of pragma% must be parameterless procedure",
2227 Proc := Entity (Name);
2233 end Find_Unique_Parameterless_Procedure;
2239 procedure Fix_Error (Msg : in out String) is
2241 if From_Aspect_Specification (N) then
2242 for J in Msg'First .. Msg'Last - 5 loop
2243 if Msg (J .. J + 5) = "pragma" then
2244 Msg (J .. J + 5) := "aspect";
2248 if Error_Msg_Name_1 = Name_Precondition then
2249 Error_Msg_Name_1 := Name_Pre;
2250 elsif Error_Msg_Name_1 = Name_Postcondition then
2251 Error_Msg_Name_1 := Name_Post;
2256 -------------------------
2257 -- Gather_Associations --
2258 -------------------------
2260 procedure Gather_Associations
2262 Args : out Args_List)
2267 -- Initialize all parameters to Empty
2269 for J in Args'Range loop
2273 -- That's all we have to do if there are no argument associations
2275 if No (Pragma_Argument_Associations (N)) then
2279 -- Otherwise first deal with any positional parameters present
2281 Arg := First (Pragma_Argument_Associations (N));
2282 for Index in Args'Range loop
2283 exit when No (Arg) or else Chars (Arg) /= No_Name;
2284 Args (Index) := Get_Pragma_Arg (Arg);
2288 -- Positional parameters all processed, if any left, then we
2289 -- have too many positional parameters.
2291 if Present (Arg) and then Chars (Arg) = No_Name then
2293 ("too many positional associations for pragma%", Arg);
2296 -- Process named parameters if any are present
2298 while Present (Arg) loop
2299 if Chars (Arg) = No_Name then
2301 ("positional association cannot follow named association",
2305 for Index in Names'Range loop
2306 if Names (Index) = Chars (Arg) then
2307 if Present (Args (Index)) then
2309 ("duplicate argument association for pragma%", Arg);
2311 Args (Index) := Get_Pragma_Arg (Arg);
2316 if Index = Names'Last then
2317 Error_Msg_Name_1 := Pname;
2318 Error_Msg_N ("pragma% does not allow & argument", Arg);
2320 -- Check for possible misspelling
2322 for Index1 in Names'Range loop
2323 if Is_Bad_Spelling_Of
2324 (Chars (Arg), Names (Index1))
2326 Error_Msg_Name_1 := Names (Index1);
2327 Error_Msg_N -- CODEFIX
2328 ("\possible misspelling of%", Arg);
2340 end Gather_Associations;
2346 procedure GNAT_Pragma is
2348 Check_Restriction (No_Implementation_Pragmas, N);
2351 --------------------------
2352 -- Is_Before_First_Decl --
2353 --------------------------
2355 function Is_Before_First_Decl
2356 (Pragma_Node : Node_Id;
2357 Decls : List_Id) return Boolean
2359 Item : Node_Id := First (Decls);
2362 -- Only other pragmas can come before this pragma
2365 if No (Item) or else Nkind (Item) /= N_Pragma then
2368 elsif Item = Pragma_Node then
2374 end Is_Before_First_Decl;
2376 -----------------------------
2377 -- Is_Configuration_Pragma --
2378 -----------------------------
2380 -- A configuration pragma must appear in the context clause of a
2381 -- compilation unit, and only other pragmas may precede it. Note that
2382 -- the test below also permits use in a configuration pragma file.
2384 function Is_Configuration_Pragma return Boolean is
2385 Lis : constant List_Id := List_Containing (N);
2386 Par : constant Node_Id := Parent (N);
2390 -- If no parent, then we are in the configuration pragma file,
2391 -- so the placement is definitely appropriate.
2396 -- Otherwise we must be in the context clause of a compilation unit
2397 -- and the only thing allowed before us in the context list is more
2398 -- configuration pragmas.
2400 elsif Nkind (Par) = N_Compilation_Unit
2401 and then Context_Items (Par) = Lis
2408 elsif Nkind (Prg) /= N_Pragma then
2418 end Is_Configuration_Pragma;
2420 --------------------------
2421 -- Is_In_Context_Clause --
2422 --------------------------
2424 function Is_In_Context_Clause return Boolean is
2426 Parent_Node : Node_Id;
2429 if not Is_List_Member (N) then
2433 Plist := List_Containing (N);
2434 Parent_Node := Parent (Plist);
2436 if Parent_Node = Empty
2437 or else Nkind (Parent_Node) /= N_Compilation_Unit
2438 or else Context_Items (Parent_Node) /= Plist
2445 end Is_In_Context_Clause;
2447 ---------------------------------
2448 -- Is_Static_String_Expression --
2449 ---------------------------------
2451 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2452 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2455 Analyze_And_Resolve (Argx);
2456 return Is_OK_Static_Expression (Argx)
2457 and then Nkind (Argx) = N_String_Literal;
2458 end Is_Static_String_Expression;
2460 ----------------------
2461 -- Pragma_Misplaced --
2462 ----------------------
2464 procedure Pragma_Misplaced is
2466 Error_Pragma ("incorrect placement of pragma%");
2467 end Pragma_Misplaced;
2469 ------------------------------------
2470 -- Process Atomic_Shared_Volatile --
2471 ------------------------------------
2473 procedure Process_Atomic_Shared_Volatile is
2480 procedure Set_Atomic (E : Entity_Id);
2481 -- Set given type as atomic, and if no explicit alignment was given,
2482 -- set alignment to unknown, since back end knows what the alignment
2483 -- requirements are for atomic arrays. Note: this step is necessary
2484 -- for derived types.
2490 procedure Set_Atomic (E : Entity_Id) is
2494 if not Has_Alignment_Clause (E) then
2495 Set_Alignment (E, Uint_0);
2499 -- Start of processing for Process_Atomic_Shared_Volatile
2502 Check_Ada_83_Warning;
2503 Check_No_Identifiers;
2504 Check_Arg_Count (1);
2505 Check_Arg_Is_Local_Name (Arg1);
2506 E_Id := Get_Pragma_Arg (Arg1);
2508 if Etype (E_Id) = Any_Type then
2513 D := Declaration_Node (E);
2516 -- Check duplicate before we chain ourselves!
2518 Check_Duplicate_Pragma (E);
2520 -- Now check appropriateness of the entity
2523 if Rep_Item_Too_Early (E, N)
2525 Rep_Item_Too_Late (E, N)
2529 Check_First_Subtype (Arg1);
2532 if Prag_Id /= Pragma_Volatile then
2534 Set_Atomic (Underlying_Type (E));
2535 Set_Atomic (Base_Type (E));
2538 -- Attribute belongs on the base type. If the view of the type is
2539 -- currently private, it also belongs on the underlying type.
2541 Set_Is_Volatile (Base_Type (E));
2542 Set_Is_Volatile (Underlying_Type (E));
2544 Set_Treat_As_Volatile (E);
2545 Set_Treat_As_Volatile (Underlying_Type (E));
2547 elsif K = N_Object_Declaration
2548 or else (K = N_Component_Declaration
2549 and then Original_Record_Component (E) = E)
2551 if Rep_Item_Too_Late (E, N) then
2555 if Prag_Id /= Pragma_Volatile then
2558 -- If the object declaration has an explicit initialization, a
2559 -- temporary may have to be created to hold the expression, to
2560 -- ensure that access to the object remain atomic.
2562 if Nkind (Parent (E)) = N_Object_Declaration
2563 and then Present (Expression (Parent (E)))
2565 Set_Has_Delayed_Freeze (E);
2568 -- An interesting improvement here. If an object of type X is
2569 -- declared atomic, and the type X is not atomic, that's a
2570 -- pity, since it may not have appropriate alignment etc. We
2571 -- can rescue this in the special case where the object and
2572 -- type are in the same unit by just setting the type as
2573 -- atomic, so that the back end will process it as atomic.
2575 Utyp := Underlying_Type (Etype (E));
2578 and then Sloc (E) > No_Location
2579 and then Sloc (Utyp) > No_Location
2581 Get_Source_File_Index (Sloc (E)) =
2582 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2584 Set_Is_Atomic (Underlying_Type (Etype (E)));
2588 Set_Is_Volatile (E);
2589 Set_Treat_As_Volatile (E);
2593 ("inappropriate entity for pragma%", Arg1);
2595 end Process_Atomic_Shared_Volatile;
2597 -------------------------------------------
2598 -- Process_Compile_Time_Warning_Or_Error --
2599 -------------------------------------------
2601 procedure Process_Compile_Time_Warning_Or_Error is
2602 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2605 Check_Arg_Count (2);
2606 Check_No_Identifiers;
2607 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2608 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2610 if Compile_Time_Known_Value (Arg1x) then
2611 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2613 Str : constant String_Id :=
2614 Strval (Get_Pragma_Arg (Arg2));
2615 Len : constant Int := String_Length (Str);
2620 Cent : constant Entity_Id :=
2621 Cunit_Entity (Current_Sem_Unit);
2623 Force : constant Boolean :=
2624 Prag_Id = Pragma_Compile_Time_Warning
2626 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2627 and then (Ekind (Cent) /= E_Package
2628 or else not In_Private_Part (Cent));
2629 -- Set True if this is the warning case, and we are in the
2630 -- visible part of a package spec, or in a subprogram spec,
2631 -- in which case we want to force the client to see the
2632 -- warning, even though it is not in the main unit.
2635 -- Loop through segments of message separated by line feeds.
2636 -- We output these segments as separate messages with
2637 -- continuation marks for all but the first.
2642 Error_Msg_Strlen := 0;
2644 -- Loop to copy characters from argument to error message
2648 exit when Ptr > Len;
2649 CC := Get_String_Char (Str, Ptr);
2652 -- Ignore wide chars ??? else store character
2654 if In_Character_Range (CC) then
2655 C := Get_Character (CC);
2656 exit when C = ASCII.LF;
2657 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2658 Error_Msg_String (Error_Msg_Strlen) := C;
2662 -- Here with one line ready to go
2664 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2666 -- If this is a warning in a spec, then we want clients
2667 -- to see the warning, so mark the message with the
2668 -- special sequence !! to force the warning. In the case
2669 -- of a package spec, we do not force this if we are in
2670 -- the private part of the spec.
2673 if Cont = False then
2674 Error_Msg_N ("<~!!", Arg1);
2677 Error_Msg_N ("\<~!!", Arg1);
2680 -- Error, rather than warning, or in a body, so we do not
2681 -- need to force visibility for client (error will be
2682 -- output in any case, and this is the situation in which
2683 -- we do not want a client to get a warning, since the
2684 -- warning is in the body or the spec private part).
2687 if Cont = False then
2688 Error_Msg_N ("<~", Arg1);
2691 Error_Msg_N ("\<~", Arg1);
2695 exit when Ptr > Len;
2700 end Process_Compile_Time_Warning_Or_Error;
2702 ------------------------
2703 -- Process_Convention --
2704 ------------------------
2706 procedure Process_Convention
2707 (C : out Convention_Id;
2708 Ent : out Entity_Id)
2714 Comp_Unit : Unit_Number_Type;
2716 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2717 -- Called if we have more than one Export/Import/Convention pragma.
2718 -- This is generally illegal, but we have a special case of allowing
2719 -- Import and Interface to coexist if they specify the convention in
2720 -- a consistent manner. We are allowed to do this, since Interface is
2721 -- an implementation defined pragma, and we choose to do it since we
2722 -- know Rational allows this combination. S is the entity id of the
2723 -- subprogram in question. This procedure also sets the special flag
2724 -- Import_Interface_Present in both pragmas in the case where we do
2725 -- have matching Import and Interface pragmas.
2727 procedure Set_Convention_From_Pragma (E : Entity_Id);
2728 -- Set convention in entity E, and also flag that the entity has a
2729 -- convention pragma. If entity is for a private or incomplete type,
2730 -- also set convention and flag on underlying type. This procedure
2731 -- also deals with the special case of C_Pass_By_Copy convention.
2733 -------------------------------
2734 -- Diagnose_Multiple_Pragmas --
2735 -------------------------------
2737 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2738 Pdec : constant Node_Id := Declaration_Node (S);
2742 function Same_Convention (Decl : Node_Id) return Boolean;
2743 -- Decl is a pragma node. This function returns True if this
2744 -- pragma has a first argument that is an identifier with a
2745 -- Chars field corresponding to the Convention_Id C.
2747 function Same_Name (Decl : Node_Id) return Boolean;
2748 -- Decl is a pragma node. This function returns True if this
2749 -- pragma has a second argument that is an identifier with a
2750 -- Chars field that matches the Chars of the current subprogram.
2752 ---------------------
2753 -- Same_Convention --
2754 ---------------------
2756 function Same_Convention (Decl : Node_Id) return Boolean is
2757 Arg1 : constant Node_Id :=
2758 First (Pragma_Argument_Associations (Decl));
2761 if Present (Arg1) then
2763 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2765 if Nkind (Arg) = N_Identifier
2766 and then Is_Convention_Name (Chars (Arg))
2767 and then Get_Convention_Id (Chars (Arg)) = C
2775 end Same_Convention;
2781 function Same_Name (Decl : Node_Id) return Boolean is
2782 Arg1 : constant Node_Id :=
2783 First (Pragma_Argument_Associations (Decl));
2791 Arg2 := Next (Arg1);
2798 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2800 if Nkind (Arg) = N_Identifier
2801 and then Chars (Arg) = Chars (S)
2810 -- Start of processing for Diagnose_Multiple_Pragmas
2815 -- Definitely give message if we have Convention/Export here
2817 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2820 -- If we have an Import or Export, scan back from pragma to
2821 -- find any previous pragma applying to the same procedure.
2822 -- The scan will be terminated by the start of the list, or
2823 -- hitting the subprogram declaration. This won't allow one
2824 -- pragma to appear in the public part and one in the private
2825 -- part, but that seems very unlikely in practice.
2829 while Present (Decl) and then Decl /= Pdec loop
2831 -- Look for pragma with same name as us
2833 if Nkind (Decl) = N_Pragma
2834 and then Same_Name (Decl)
2836 -- Give error if same as our pragma or Export/Convention
2838 if Pragma_Name (Decl) = Name_Export
2840 Pragma_Name (Decl) = Name_Convention
2842 Pragma_Name (Decl) = Pragma_Name (N)
2846 -- Case of Import/Interface or the other way round
2848 elsif Pragma_Name (Decl) = Name_Interface
2850 Pragma_Name (Decl) = Name_Import
2852 -- Here we know that we have Import and Interface. It
2853 -- doesn't matter which way round they are. See if
2854 -- they specify the same convention. If so, all OK,
2855 -- and set special flags to stop other messages
2857 if Same_Convention (Decl) then
2858 Set_Import_Interface_Present (N);
2859 Set_Import_Interface_Present (Decl);
2862 -- If different conventions, special message
2865 Error_Msg_Sloc := Sloc (Decl);
2867 ("convention differs from that given#", Arg1);
2877 -- Give message if needed if we fall through those tests
2881 ("at most one Convention/Export/Import pragma is allowed",
2884 end Diagnose_Multiple_Pragmas;
2886 --------------------------------
2887 -- Set_Convention_From_Pragma --
2888 --------------------------------
2890 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2892 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2893 -- for an overridden dispatching operation. Technically this is
2894 -- an amendment and should only be done in Ada 2005 mode. However,
2895 -- this is clearly a mistake, since the problem that is addressed
2896 -- by this AI is that there is a clear gap in the RM!
2898 if Is_Dispatching_Operation (E)
2899 and then Present (Overridden_Operation (E))
2900 and then C /= Convention (Overridden_Operation (E))
2903 ("cannot change convention for " &
2904 "overridden dispatching operation",
2908 -- Set the convention
2910 Set_Convention (E, C);
2911 Set_Has_Convention_Pragma (E);
2913 if Is_Incomplete_Or_Private_Type (E)
2914 and then Present (Underlying_Type (E))
2916 Set_Convention (Underlying_Type (E), C);
2917 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2920 -- A class-wide type should inherit the convention of the specific
2921 -- root type (although this isn't specified clearly by the RM).
2923 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2924 Set_Convention (Class_Wide_Type (E), C);
2927 -- If the entity is a record type, then check for special case of
2928 -- C_Pass_By_Copy, which is treated the same as C except that the
2929 -- special record flag is set. This convention is only permitted
2930 -- on record types (see AI95-00131).
2932 if Cname = Name_C_Pass_By_Copy then
2933 if Is_Record_Type (E) then
2934 Set_C_Pass_By_Copy (Base_Type (E));
2935 elsif Is_Incomplete_Or_Private_Type (E)
2936 and then Is_Record_Type (Underlying_Type (E))
2938 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2941 ("C_Pass_By_Copy convention allowed only for record type",
2946 -- If the entity is a derived boolean type, check for the special
2947 -- case of convention C, C++, or Fortran, where we consider any
2948 -- nonzero value to represent true.
2950 if Is_Discrete_Type (E)
2951 and then Root_Type (Etype (E)) = Standard_Boolean
2957 C = Convention_Fortran)
2959 Set_Nonzero_Is_True (Base_Type (E));
2961 end Set_Convention_From_Pragma;
2963 -- Start of processing for Process_Convention
2966 Check_At_Least_N_Arguments (2);
2967 Check_Optional_Identifier (Arg1, Name_Convention);
2968 Check_Arg_Is_Identifier (Arg1);
2969 Cname := Chars (Get_Pragma_Arg (Arg1));
2971 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2972 -- tested again below to set the critical flag).
2974 if Cname = Name_C_Pass_By_Copy then
2977 -- Otherwise we must have something in the standard convention list
2979 elsif Is_Convention_Name (Cname) then
2980 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2982 -- In DEC VMS, it seems that there is an undocumented feature that
2983 -- any unrecognized convention is treated as the default, which for
2984 -- us is convention C. It does not seem so terrible to do this
2985 -- unconditionally, silently in the VMS case, and with a warning
2986 -- in the non-VMS case.
2989 if Warn_On_Export_Import and not OpenVMS_On_Target then
2991 ("?unrecognized convention name, C assumed",
2992 Get_Pragma_Arg (Arg1));
2998 Check_Optional_Identifier (Arg2, Name_Entity);
2999 Check_Arg_Is_Local_Name (Arg2);
3001 Id := Get_Pragma_Arg (Arg2);
3004 if not Is_Entity_Name (Id) then
3005 Error_Pragma_Arg ("entity name required", Arg2);
3010 -- Set entity to return
3014 -- Go to renamed subprogram if present, since convention applies to
3015 -- the actual renamed entity, not to the renaming entity. If the
3016 -- subprogram is inherited, go to parent subprogram.
3018 if Is_Subprogram (E)
3019 and then Present (Alias (E))
3021 if Nkind (Parent (Declaration_Node (E))) =
3022 N_Subprogram_Renaming_Declaration
3024 if Scope (E) /= Scope (Alias (E)) then
3026 ("cannot apply pragma% to non-local entity&#", E);
3031 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3032 N_Private_Extension_Declaration)
3033 and then Scope (E) = Scope (Alias (E))
3037 -- Return the parent subprogram the entity was inherited from
3043 -- Check that we are not applying this to a specless body
3045 if Is_Subprogram (E)
3046 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3049 ("pragma% requires separate spec and must come before body");
3052 -- Check that we are not applying this to a named constant
3054 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3055 Error_Msg_Name_1 := Pname;
3057 ("cannot apply pragma% to named constant!",
3058 Get_Pragma_Arg (Arg2));
3060 ("\supply appropriate type for&!", Arg2);
3063 if Ekind (E) = E_Enumeration_Literal then
3064 Error_Pragma ("enumeration literal not allowed for pragma%");
3067 -- Check for rep item appearing too early or too late
3069 if Etype (E) = Any_Type
3070 or else Rep_Item_Too_Early (E, N)
3074 elsif Present (Underlying_Type (E)) then
3075 E := Underlying_Type (E);
3078 if Rep_Item_Too_Late (E, N) then
3082 if Has_Convention_Pragma (E) then
3083 Diagnose_Multiple_Pragmas (E);
3085 elsif Convention (E) = Convention_Protected
3086 or else Ekind (Scope (E)) = E_Protected_Type
3089 ("a protected operation cannot be given a different convention",
3093 -- For Intrinsic, a subprogram is required
3095 if C = Convention_Intrinsic
3096 and then not Is_Subprogram (E)
3097 and then not Is_Generic_Subprogram (E)
3100 ("second argument of pragma% must be a subprogram", Arg2);
3103 -- For Stdcall, a subprogram, variable or subprogram type is required
3105 if C = Convention_Stdcall
3106 and then not Is_Subprogram (E)
3107 and then not Is_Generic_Subprogram (E)
3108 and then Ekind (E) /= E_Variable
3111 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3114 ("second argument of pragma% must be subprogram (type)",
3118 if not Is_Subprogram (E)
3119 and then not Is_Generic_Subprogram (E)
3121 Set_Convention_From_Pragma (E);
3124 Check_First_Subtype (Arg2);
3125 Set_Convention_From_Pragma (Base_Type (E));
3127 -- For subprograms, we must set the convention on the
3128 -- internally generated directly designated type as well.
3130 if Ekind (E) = E_Access_Subprogram_Type then
3131 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3135 -- For the subprogram case, set proper convention for all homonyms
3136 -- in same scope and the same declarative part, i.e. the same
3137 -- compilation unit.
3140 Comp_Unit := Get_Source_Unit (E);
3141 Set_Convention_From_Pragma (E);
3143 -- Treat a pragma Import as an implicit body, for GPS use
3145 if Prag_Id = Pragma_Import then
3146 Generate_Reference (E, Id, 'b');
3149 -- Loop through the homonyms of the pragma argument's entity
3154 exit when No (E1) or else Scope (E1) /= Current_Scope;
3156 -- Do not set the pragma on inherited operations or on formal
3159 if Comes_From_Source (E1)
3160 and then Comp_Unit = Get_Source_Unit (E1)
3161 and then not Is_Formal_Subprogram (E1)
3162 and then Nkind (Original_Node (Parent (E1))) /=
3163 N_Full_Type_Declaration
3165 if Present (Alias (E1))
3166 and then Scope (E1) /= Scope (Alias (E1))
3169 ("cannot apply pragma% to non-local entity& declared#",
3173 Set_Convention_From_Pragma (E1);
3175 if Prag_Id = Pragma_Import then
3176 Generate_Reference (E1, Id, 'b');
3180 -- For aspect case, do NOT apply to homonyms
3182 exit when From_Aspect_Specification (N);
3185 end Process_Convention;
3187 -----------------------------------------------------
3188 -- Process_Extended_Import_Export_Exception_Pragma --
3189 -----------------------------------------------------
3191 procedure Process_Extended_Import_Export_Exception_Pragma
3192 (Arg_Internal : Node_Id;
3193 Arg_External : Node_Id;
3201 if not OpenVMS_On_Target then
3203 ("?pragma% ignored (applies only to Open'V'M'S)");
3206 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3207 Def_Id := Entity (Arg_Internal);
3209 if Ekind (Def_Id) /= E_Exception then
3211 ("pragma% must refer to declared exception", Arg_Internal);
3214 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3216 if Present (Arg_Form) then
3217 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3220 if Present (Arg_Form)
3221 and then Chars (Arg_Form) = Name_Ada
3225 Set_Is_VMS_Exception (Def_Id);
3226 Set_Exception_Code (Def_Id, No_Uint);
3229 if Present (Arg_Code) then
3230 if not Is_VMS_Exception (Def_Id) then
3232 ("Code option for pragma% not allowed for Ada case",
3236 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3237 Code_Val := Expr_Value (Arg_Code);
3239 if not UI_Is_In_Int_Range (Code_Val) then
3241 ("Code option for pragma% must be in 32-bit range",
3245 Set_Exception_Code (Def_Id, Code_Val);
3248 end Process_Extended_Import_Export_Exception_Pragma;
3250 -------------------------------------------------
3251 -- Process_Extended_Import_Export_Internal_Arg --
3252 -------------------------------------------------
3254 procedure Process_Extended_Import_Export_Internal_Arg
3255 (Arg_Internal : Node_Id := Empty)
3258 if No (Arg_Internal) then
3259 Error_Pragma ("Internal parameter required for pragma%");
3262 if Nkind (Arg_Internal) = N_Identifier then
3265 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3266 and then (Prag_Id = Pragma_Import_Function
3268 Prag_Id = Pragma_Export_Function)
3274 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3277 Check_Arg_Is_Local_Name (Arg_Internal);
3278 end Process_Extended_Import_Export_Internal_Arg;
3280 --------------------------------------------------
3281 -- Process_Extended_Import_Export_Object_Pragma --
3282 --------------------------------------------------
3284 procedure Process_Extended_Import_Export_Object_Pragma
3285 (Arg_Internal : Node_Id;
3286 Arg_External : Node_Id;
3292 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3293 Def_Id := Entity (Arg_Internal);
3295 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3297 ("pragma% must designate an object", Arg_Internal);
3300 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3302 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3305 ("previous Common/Psect_Object applies, pragma % not permitted",
3309 if Rep_Item_Too_Late (Def_Id, N) then
3313 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3315 if Present (Arg_Size) then
3316 Check_Arg_Is_External_Name (Arg_Size);
3319 -- Export_Object case
3321 if Prag_Id = Pragma_Export_Object then
3322 if not Is_Library_Level_Entity (Def_Id) then
3324 ("argument for pragma% must be library level entity",
3328 if Ekind (Current_Scope) = E_Generic_Package then
3329 Error_Pragma ("pragma& cannot appear in a generic unit");
3332 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3334 ("exported object must have compile time known size",
3338 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3339 Error_Msg_N ("?duplicate Export_Object pragma", N);
3341 Set_Exported (Def_Id, Arg_Internal);
3344 -- Import_Object case
3347 if Is_Concurrent_Type (Etype (Def_Id)) then
3349 ("cannot use pragma% for task/protected object",
3353 if Ekind (Def_Id) = E_Constant then
3355 ("cannot import a constant", Arg_Internal);
3358 if Warn_On_Export_Import
3359 and then Has_Discriminants (Etype (Def_Id))
3362 ("imported value must be initialized?", Arg_Internal);
3365 if Warn_On_Export_Import
3366 and then Is_Access_Type (Etype (Def_Id))
3369 ("cannot import object of an access type?", Arg_Internal);
3372 if Warn_On_Export_Import
3373 and then Is_Imported (Def_Id)
3376 ("?duplicate Import_Object pragma", N);
3378 -- Check for explicit initialization present. Note that an
3379 -- initialization generated by the code generator, e.g. for an
3380 -- access type, does not count here.
3382 elsif Present (Expression (Parent (Def_Id)))
3385 (Original_Node (Expression (Parent (Def_Id))))
3387 Error_Msg_Sloc := Sloc (Def_Id);
3389 ("imported entities cannot be initialized (RM B.1(24))",
3390 "\no initialization allowed for & declared#", Arg1);
3392 Set_Imported (Def_Id);
3393 Note_Possible_Modification (Arg_Internal, Sure => False);
3396 end Process_Extended_Import_Export_Object_Pragma;
3398 ------------------------------------------------------
3399 -- Process_Extended_Import_Export_Subprogram_Pragma --
3400 ------------------------------------------------------
3402 procedure Process_Extended_Import_Export_Subprogram_Pragma
3403 (Arg_Internal : Node_Id;
3404 Arg_External : Node_Id;
3405 Arg_Parameter_Types : Node_Id;
3406 Arg_Result_Type : Node_Id := Empty;
3407 Arg_Mechanism : Node_Id;
3408 Arg_Result_Mechanism : Node_Id := Empty;
3409 Arg_First_Optional_Parameter : Node_Id := Empty)
3415 Ambiguous : Boolean;
3419 function Same_Base_Type
3421 Formal : Entity_Id) return Boolean;
3422 -- Determines if Ptype references the type of Formal. Note that only
3423 -- the base types need to match according to the spec. Ptype here is
3424 -- the argument from the pragma, which is either a type name, or an
3425 -- access attribute.
3427 --------------------
3428 -- Same_Base_Type --
3429 --------------------
3431 function Same_Base_Type
3433 Formal : Entity_Id) return Boolean
3435 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3439 -- Case where pragma argument is typ'Access
3441 if Nkind (Ptype) = N_Attribute_Reference
3442 and then Attribute_Name (Ptype) = Name_Access
3444 Pref := Prefix (Ptype);
3447 if not Is_Entity_Name (Pref)
3448 or else Entity (Pref) = Any_Type
3453 -- We have a match if the corresponding argument is of an
3454 -- anonymous access type, and its designated type matches the
3455 -- type of the prefix of the access attribute
3457 return Ekind (Ftyp) = E_Anonymous_Access_Type
3458 and then Base_Type (Entity (Pref)) =
3459 Base_Type (Etype (Designated_Type (Ftyp)));
3461 -- Case where pragma argument is a type name
3466 if not Is_Entity_Name (Ptype)
3467 or else Entity (Ptype) = Any_Type
3472 -- We have a match if the corresponding argument is of the type
3473 -- given in the pragma (comparing base types)
3475 return Base_Type (Entity (Ptype)) = Ftyp;
3479 -- Start of processing for
3480 -- Process_Extended_Import_Export_Subprogram_Pragma
3483 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3487 -- Loop through homonyms (overloadings) of the entity
3489 Hom_Id := Entity (Arg_Internal);
3490 while Present (Hom_Id) loop
3491 Def_Id := Get_Base_Subprogram (Hom_Id);
3493 -- We need a subprogram in the current scope
3495 if not Is_Subprogram (Def_Id)
3496 or else Scope (Def_Id) /= Current_Scope
3503 -- Pragma cannot apply to subprogram body
3505 if Is_Subprogram (Def_Id)
3506 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3510 ("pragma% requires separate spec"
3511 & " and must come before body");
3514 -- Test result type if given, note that the result type
3515 -- parameter can only be present for the function cases.
3517 if Present (Arg_Result_Type)
3518 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3522 elsif Etype (Def_Id) /= Standard_Void_Type
3524 (Pname = Name_Export_Procedure
3526 Pname = Name_Import_Procedure)
3530 -- Test parameter types if given. Note that this parameter
3531 -- has not been analyzed (and must not be, since it is
3532 -- semantic nonsense), so we get it as the parser left it.
3534 elsif Present (Arg_Parameter_Types) then
3535 Check_Matching_Types : declare
3540 Formal := First_Formal (Def_Id);
3542 if Nkind (Arg_Parameter_Types) = N_Null then
3543 if Present (Formal) then
3547 -- A list of one type, e.g. (List) is parsed as
3548 -- a parenthesized expression.
3550 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3551 and then Paren_Count (Arg_Parameter_Types) = 1
3554 or else Present (Next_Formal (Formal))
3559 Same_Base_Type (Arg_Parameter_Types, Formal);
3562 -- A list of more than one type is parsed as a aggregate
3564 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3565 and then Paren_Count (Arg_Parameter_Types) = 0
3567 Ptype := First (Expressions (Arg_Parameter_Types));
3568 while Present (Ptype) or else Present (Formal) loop
3571 or else not Same_Base_Type (Ptype, Formal)
3576 Next_Formal (Formal);
3581 -- Anything else is of the wrong form
3585 ("wrong form for Parameter_Types parameter",
3586 Arg_Parameter_Types);
3588 end Check_Matching_Types;
3591 -- Match is now False if the entry we found did not match
3592 -- either a supplied Parameter_Types or Result_Types argument
3598 -- Ambiguous case, the flag Ambiguous shows if we already
3599 -- detected this and output the initial messages.
3602 if not Ambiguous then
3604 Error_Msg_Name_1 := Pname;
3606 ("pragma% does not uniquely identify subprogram!",
3608 Error_Msg_Sloc := Sloc (Ent);
3609 Error_Msg_N ("matching subprogram #!", N);
3613 Error_Msg_Sloc := Sloc (Def_Id);
3614 Error_Msg_N ("matching subprogram #!", N);
3619 Hom_Id := Homonym (Hom_Id);
3622 -- See if we found an entry
3625 if not Ambiguous then
3626 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3628 ("pragma% cannot be given for generic subprogram");
3631 ("pragma% does not identify local subprogram");
3638 -- Import pragmas must be for imported entities
3640 if Prag_Id = Pragma_Import_Function
3642 Prag_Id = Pragma_Import_Procedure
3644 Prag_Id = Pragma_Import_Valued_Procedure
3646 if not Is_Imported (Ent) then
3648 ("pragma Import or Interface must precede pragma%");
3651 -- Here we have the Export case which can set the entity as exported
3653 -- But does not do so if the specified external name is null, since
3654 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3655 -- compatible) to request no external name.
3657 elsif Nkind (Arg_External) = N_String_Literal
3658 and then String_Length (Strval (Arg_External)) = 0
3662 -- In all other cases, set entity as exported
3665 Set_Exported (Ent, Arg_Internal);
3668 -- Special processing for Valued_Procedure cases
3670 if Prag_Id = Pragma_Import_Valued_Procedure
3672 Prag_Id = Pragma_Export_Valued_Procedure
3674 Formal := First_Formal (Ent);
3677 Error_Pragma ("at least one parameter required for pragma%");
3679 elsif Ekind (Formal) /= E_Out_Parameter then
3680 Error_Pragma ("first parameter must have mode out for pragma%");
3683 Set_Is_Valued_Procedure (Ent);
3687 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3689 -- Process Result_Mechanism argument if present. We have already
3690 -- checked that this is only allowed for the function case.
3692 if Present (Arg_Result_Mechanism) then
3693 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3696 -- Process Mechanism parameter if present. Note that this parameter
3697 -- is not analyzed, and must not be analyzed since it is semantic
3698 -- nonsense, so we get it in exactly as the parser left it.
3700 if Present (Arg_Mechanism) then
3708 -- A single mechanism association without a formal parameter
3709 -- name is parsed as a parenthesized expression. All other
3710 -- cases are parsed as aggregates, so we rewrite the single
3711 -- parameter case as an aggregate for consistency.
3713 if Nkind (Arg_Mechanism) /= N_Aggregate
3714 and then Paren_Count (Arg_Mechanism) = 1
3716 Rewrite (Arg_Mechanism,
3717 Make_Aggregate (Sloc (Arg_Mechanism),
3718 Expressions => New_List (
3719 Relocate_Node (Arg_Mechanism))));
3722 -- Case of only mechanism name given, applies to all formals
3724 if Nkind (Arg_Mechanism) /= N_Aggregate then
3725 Formal := First_Formal (Ent);
3726 while Present (Formal) loop
3727 Set_Mechanism_Value (Formal, Arg_Mechanism);
3728 Next_Formal (Formal);
3731 -- Case of list of mechanism associations given
3734 if Null_Record_Present (Arg_Mechanism) then
3736 ("inappropriate form for Mechanism parameter",
3740 -- Deal with positional ones first
3742 Formal := First_Formal (Ent);
3744 if Present (Expressions (Arg_Mechanism)) then
3745 Mname := First (Expressions (Arg_Mechanism));
3746 while Present (Mname) loop
3749 ("too many mechanism associations", Mname);
3752 Set_Mechanism_Value (Formal, Mname);
3753 Next_Formal (Formal);
3758 -- Deal with named entries
3760 if Present (Component_Associations (Arg_Mechanism)) then
3761 Massoc := First (Component_Associations (Arg_Mechanism));
3762 while Present (Massoc) loop
3763 Choice := First (Choices (Massoc));
3765 if Nkind (Choice) /= N_Identifier
3766 or else Present (Next (Choice))
3769 ("incorrect form for mechanism association",
3773 Formal := First_Formal (Ent);
3777 ("parameter name & not present", Choice);
3780 if Chars (Choice) = Chars (Formal) then
3782 (Formal, Expression (Massoc));
3784 -- Set entity on identifier (needed by ASIS)
3786 Set_Entity (Choice, Formal);
3791 Next_Formal (Formal);
3801 -- Process First_Optional_Parameter argument if present. We have
3802 -- already checked that this is only allowed for the Import case.
3804 if Present (Arg_First_Optional_Parameter) then
3805 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3807 ("first optional parameter must be formal parameter name",
3808 Arg_First_Optional_Parameter);
3811 Formal := First_Formal (Ent);
3815 ("specified formal parameter& not found",
3816 Arg_First_Optional_Parameter);
3819 exit when Chars (Formal) =
3820 Chars (Arg_First_Optional_Parameter);
3822 Next_Formal (Formal);
3825 Set_First_Optional_Parameter (Ent, Formal);
3827 -- Check specified and all remaining formals have right form
3829 while Present (Formal) loop
3830 if Ekind (Formal) /= E_In_Parameter then
3832 ("optional formal& is not of mode in!",
3833 Arg_First_Optional_Parameter, Formal);
3836 Dval := Default_Value (Formal);
3840 ("optional formal& does not have default value!",
3841 Arg_First_Optional_Parameter, Formal);
3843 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3848 ("default value for optional formal& is non-static!",
3849 Arg_First_Optional_Parameter, Formal);
3853 Set_Is_Optional_Parameter (Formal);
3854 Next_Formal (Formal);
3857 end Process_Extended_Import_Export_Subprogram_Pragma;
3859 --------------------------
3860 -- Process_Generic_List --
3861 --------------------------
3863 procedure Process_Generic_List is
3868 Check_No_Identifiers;
3869 Check_At_Least_N_Arguments (1);
3872 while Present (Arg) loop
3873 Exp := Get_Pragma_Arg (Arg);
3876 if not Is_Entity_Name (Exp)
3878 (not Is_Generic_Instance (Entity (Exp))
3880 not Is_Generic_Unit (Entity (Exp)))
3883 ("pragma% argument must be name of generic unit/instance",
3889 end Process_Generic_List;
3891 ------------------------------------
3892 -- Process_Import_Predefined_Type --
3893 ------------------------------------
3895 procedure Process_Import_Predefined_Type is
3896 Loc : constant Source_Ptr := Sloc (N);
3898 Ftyp : Node_Id := Empty;
3904 String_To_Name_Buffer (Strval (Expression (Arg3)));
3907 Elmt := First_Elmt (Predefined_Float_Types);
3908 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3912 Ftyp := Node (Elmt);
3914 if Present (Ftyp) then
3916 -- Don't build a derived type declaration, because predefined C
3917 -- types have no declaration anywhere, so cannot really be named.
3918 -- Instead build a full type declaration, starting with an
3919 -- appropriate type definition is built
3921 if Is_Floating_Point_Type (Ftyp) then
3922 Def := Make_Floating_Point_Definition (Loc,
3923 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3924 Make_Real_Range_Specification (Loc,
3925 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3926 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3928 -- Should never have a predefined type we cannot handle
3931 raise Program_Error;
3934 -- Build and insert a Full_Type_Declaration, which will be
3935 -- analyzed as soon as this list entry has been analyzed.
3937 Decl := Make_Full_Type_Declaration (Loc,
3938 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3939 Type_Definition => Def);
3941 Insert_After (N, Decl);
3942 Mark_Rewrite_Insertion (Decl);
3945 Error_Pragma_Arg ("no matching type found for pragma%",
3948 end Process_Import_Predefined_Type;
3950 ---------------------------------
3951 -- Process_Import_Or_Interface --
3952 ---------------------------------
3954 procedure Process_Import_Or_Interface is
3960 Process_Convention (C, Def_Id);
3961 Kill_Size_Check_Code (Def_Id);
3962 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3964 if Ekind_In (Def_Id, E_Variable, E_Constant) then
3966 -- We do not permit Import to apply to a renaming declaration
3968 if Present (Renamed_Object (Def_Id)) then
3970 ("pragma% not allowed for object renaming", Arg2);
3972 -- User initialization is not allowed for imported object, but
3973 -- the object declaration may contain a default initialization,
3974 -- that will be discarded. Note that an explicit initialization
3975 -- only counts if it comes from source, otherwise it is simply
3976 -- the code generator making an implicit initialization explicit.
3978 elsif Present (Expression (Parent (Def_Id)))
3979 and then Comes_From_Source (Expression (Parent (Def_Id)))
3981 Error_Msg_Sloc := Sloc (Def_Id);
3983 ("no initialization allowed for declaration of& #",
3984 "\imported entities cannot be initialized (RM B.1(24))",
3988 Set_Imported (Def_Id);
3989 Process_Interface_Name (Def_Id, Arg3, Arg4);
3991 -- Note that we do not set Is_Public here. That's because we
3992 -- only want to set it if there is no address clause, and we
3993 -- don't know that yet, so we delay that processing till
3996 -- pragma Import completes deferred constants
3998 if Ekind (Def_Id) = E_Constant then
3999 Set_Has_Completion (Def_Id);
4002 -- It is not possible to import a constant of an unconstrained
4003 -- array type (e.g. string) because there is no simple way to
4004 -- write a meaningful subtype for it.
4006 if Is_Array_Type (Etype (Def_Id))
4007 and then not Is_Constrained (Etype (Def_Id))
4010 ("imported constant& must have a constrained subtype",
4015 elsif Is_Subprogram (Def_Id)
4016 or else Is_Generic_Subprogram (Def_Id)
4018 -- If the name is overloaded, pragma applies to all of the denoted
4019 -- entities in the same declarative part.
4022 while Present (Hom_Id) loop
4023 Def_Id := Get_Base_Subprogram (Hom_Id);
4025 -- Ignore inherited subprograms because the pragma will apply
4026 -- to the parent operation, which is the one called.
4028 if Is_Overloadable (Def_Id)
4029 and then Present (Alias (Def_Id))
4033 -- If it is not a subprogram, it must be in an outer scope and
4034 -- pragma does not apply.
4036 elsif not Is_Subprogram (Def_Id)
4037 and then not Is_Generic_Subprogram (Def_Id)
4041 -- The pragma does not apply to primitives of interfaces
4043 elsif Is_Dispatching_Operation (Def_Id)
4044 and then Present (Find_Dispatching_Type (Def_Id))
4045 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4049 -- Verify that the homonym is in the same declarative part (not
4050 -- just the same scope).
4052 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4053 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4058 Set_Imported (Def_Id);
4060 -- Reject an Import applied to an abstract subprogram
4062 if Is_Subprogram (Def_Id)
4063 and then Is_Abstract_Subprogram (Def_Id)
4065 Error_Msg_Sloc := Sloc (Def_Id);
4067 ("cannot import abstract subprogram& declared#",
4071 -- Special processing for Convention_Intrinsic
4073 if C = Convention_Intrinsic then
4075 -- Link_Name argument not allowed for intrinsic
4079 Set_Is_Intrinsic_Subprogram (Def_Id);
4081 -- If no external name is present, then check that this
4082 -- is a valid intrinsic subprogram. If an external name
4083 -- is present, then this is handled by the back end.
4086 Check_Intrinsic_Subprogram
4087 (Def_Id, Get_Pragma_Arg (Arg2));
4091 -- All interfaced procedures need an external symbol created
4092 -- for them since they are always referenced from another
4095 Set_Is_Public (Def_Id);
4097 -- Verify that the subprogram does not have a completion
4098 -- through a renaming declaration. For other completions the
4099 -- pragma appears as a too late representation.
4102 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4106 and then Nkind (Decl) = N_Subprogram_Declaration
4107 and then Present (Corresponding_Body (Decl))
4108 and then Nkind (Unit_Declaration_Node
4109 (Corresponding_Body (Decl))) =
4110 N_Subprogram_Renaming_Declaration
4112 Error_Msg_Sloc := Sloc (Def_Id);
4114 ("cannot import&, renaming already provided for " &
4115 "declaration #", N, Def_Id);
4119 Set_Has_Completion (Def_Id);
4120 Process_Interface_Name (Def_Id, Arg3, Arg4);
4123 if Is_Compilation_Unit (Hom_Id) then
4125 -- Its possible homonyms are not affected by the pragma.
4126 -- Such homonyms might be present in the context of other
4127 -- units being compiled.
4132 Hom_Id := Homonym (Hom_Id);
4136 -- When the convention is Java or CIL, we also allow Import to be
4137 -- given for packages, generic packages, exceptions, record
4138 -- components, and access to subprograms.
4140 elsif (C = Convention_Java or else C = Convention_CIL)
4142 (Is_Package_Or_Generic_Package (Def_Id)
4143 or else Ekind (Def_Id) = E_Exception
4144 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4145 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4147 Set_Imported (Def_Id);
4148 Set_Is_Public (Def_Id);
4149 Process_Interface_Name (Def_Id, Arg3, Arg4);
4151 -- Import a CPP class
4153 elsif Is_Record_Type (Def_Id)
4154 and then C = Convention_CPP
4156 -- Types treated as CPP classes are treated as limited, but we
4157 -- don't require them to be declared this way. A warning is issued
4158 -- to encourage the user to declare them as limited. This is not
4159 -- an error, for compatibility reasons, because these types have
4160 -- been supported this way for some time.
4162 if not Is_Limited_Type (Def_Id) then
4164 ("imported 'C'P'P type should be " &
4165 "explicitly declared limited?",
4166 Get_Pragma_Arg (Arg2));
4168 ("\type will be considered limited",
4169 Get_Pragma_Arg (Arg2));
4172 Set_Is_CPP_Class (Def_Id);
4173 Set_Is_Limited_Record (Def_Id);
4175 -- Imported CPP types must not have discriminants (because C++
4176 -- classes do not have discriminants).
4178 if Has_Discriminants (Def_Id) then
4180 ("imported 'C'P'P type cannot have discriminants",
4181 First (Discriminant_Specifications
4182 (Declaration_Node (Def_Id))));
4185 -- Components of imported CPP types must not have default
4186 -- expressions because the constructor (if any) is on the
4190 Tdef : constant Node_Id :=
4191 Type_Definition (Declaration_Node (Def_Id));
4196 if Nkind (Tdef) = N_Record_Definition then
4197 Clist := Component_List (Tdef);
4200 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4201 Clist := Component_List (Record_Extension_Part (Tdef));
4204 if Present (Clist) then
4205 Comp := First (Component_Items (Clist));
4206 while Present (Comp) loop
4207 if Present (Expression (Comp)) then
4209 ("component of imported 'C'P'P type cannot have" &
4210 " default expression", Expression (Comp));
4218 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4220 Check_Arg_Count (3);
4221 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4223 Process_Import_Predefined_Type;
4227 ("second argument of pragma% must be object, subprogram" &
4228 " or incomplete type",
4232 -- If this pragma applies to a compilation unit, then the unit, which
4233 -- is a subprogram, does not require (or allow) a body. We also do
4234 -- not need to elaborate imported procedures.
4236 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4238 Cunit : constant Node_Id := Parent (Parent (N));
4240 Set_Body_Required (Cunit, False);
4243 end Process_Import_Or_Interface;
4245 --------------------
4246 -- Process_Inline --
4247 --------------------
4249 procedure Process_Inline (Active : Boolean) is
4256 Effective : Boolean := False;
4257 -- Set True if inline has some effect, i.e. if there is at least one
4258 -- subprogram set as inlined as a result of the use of the pragma.
4260 procedure Make_Inline (Subp : Entity_Id);
4261 -- Subp is the defining unit name of the subprogram declaration. Set
4262 -- the flag, as well as the flag in the corresponding body, if there
4265 procedure Set_Inline_Flags (Subp : Entity_Id);
4266 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4267 -- Has_Pragma_Inline_Always for the Inline_Always case.
4269 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4270 -- Returns True if it can be determined at this stage that inlining
4271 -- is not possible, for example if the body is available and contains
4272 -- exception handlers, we prevent inlining, since otherwise we can
4273 -- get undefined symbols at link time. This function also emits a
4274 -- warning if front-end inlining is enabled and the pragma appears
4277 -- ??? is business with link symbols still valid, or does it relate
4278 -- to front end ZCX which is being phased out ???
4280 ---------------------------
4281 -- Inlining_Not_Possible --
4282 ---------------------------
4284 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4285 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4289 if Nkind (Decl) = N_Subprogram_Body then
4290 Stats := Handled_Statement_Sequence (Decl);
4291 return Present (Exception_Handlers (Stats))
4292 or else Present (At_End_Proc (Stats));
4294 elsif Nkind (Decl) = N_Subprogram_Declaration
4295 and then Present (Corresponding_Body (Decl))
4297 if Front_End_Inlining
4298 and then Analyzed (Corresponding_Body (Decl))
4300 Error_Msg_N ("pragma appears too late, ignored?", N);
4303 -- If the subprogram is a renaming as body, the body is just a
4304 -- call to the renamed subprogram, and inlining is trivially
4308 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4309 N_Subprogram_Renaming_Declaration
4315 Handled_Statement_Sequence
4316 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4319 Present (Exception_Handlers (Stats))
4320 or else Present (At_End_Proc (Stats));
4324 -- If body is not available, assume the best, the check is
4325 -- performed again when compiling enclosing package bodies.
4329 end Inlining_Not_Possible;
4335 procedure Make_Inline (Subp : Entity_Id) is
4336 Kind : constant Entity_Kind := Ekind (Subp);
4337 Inner_Subp : Entity_Id := Subp;
4340 -- Ignore if bad type, avoid cascaded error
4342 if Etype (Subp) = Any_Type then
4346 -- Ignore if all inlining is suppressed
4348 elsif Suppress_All_Inlining then
4352 -- If inlining is not possible, for now do not treat as an error
4354 elsif Inlining_Not_Possible (Subp) then
4358 -- Here we have a candidate for inlining, but we must exclude
4359 -- derived operations. Otherwise we would end up trying to inline
4360 -- a phantom declaration, and the result would be to drag in a
4361 -- body which has no direct inlining associated with it. That
4362 -- would not only be inefficient but would also result in the
4363 -- backend doing cross-unit inlining in cases where it was
4364 -- definitely inappropriate to do so.
4366 -- However, a simple Comes_From_Source test is insufficient, since
4367 -- we do want to allow inlining of generic instances which also do
4368 -- not come from source. We also need to recognize specs generated
4369 -- by the front-end for bodies that carry the pragma. Finally,
4370 -- predefined operators do not come from source but are not
4371 -- inlineable either.
4373 elsif Is_Generic_Instance (Subp)
4374 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4378 elsif not Comes_From_Source (Subp)
4379 and then Scope (Subp) /= Standard_Standard
4385 -- The referenced entity must either be the enclosing entity, or
4386 -- an entity declared within the current open scope.
4388 if Present (Scope (Subp))
4389 and then Scope (Subp) /= Current_Scope
4390 and then Subp /= Current_Scope
4393 ("argument of% must be entity in current scope", Assoc);
4397 -- Processing for procedure, operator or function. If subprogram
4398 -- is aliased (as for an instance) indicate that the renamed
4399 -- entity (if declared in the same unit) is inlined.
4401 if Is_Subprogram (Subp) then
4402 Inner_Subp := Ultimate_Alias (Inner_Subp);
4404 if In_Same_Source_Unit (Subp, Inner_Subp) then
4405 Set_Inline_Flags (Inner_Subp);
4407 Decl := Parent (Parent (Inner_Subp));
4409 if Nkind (Decl) = N_Subprogram_Declaration
4410 and then Present (Corresponding_Body (Decl))
4412 Set_Inline_Flags (Corresponding_Body (Decl));
4414 elsif Is_Generic_Instance (Subp) then
4416 -- Indicate that the body needs to be created for
4417 -- inlining subsequent calls. The instantiation node
4418 -- follows the declaration of the wrapper package
4421 if Scope (Subp) /= Standard_Standard
4423 Need_Subprogram_Instance_Body
4424 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4434 -- For a generic subprogram set flag as well, for use at the point
4435 -- of instantiation, to determine whether the body should be
4438 elsif Is_Generic_Subprogram (Subp) then
4439 Set_Inline_Flags (Subp);
4442 -- Literals are by definition inlined
4444 elsif Kind = E_Enumeration_Literal then
4447 -- Anything else is an error
4451 ("expect subprogram name for pragma%", Assoc);
4455 ----------------------
4456 -- Set_Inline_Flags --
4457 ----------------------
4459 procedure Set_Inline_Flags (Subp : Entity_Id) is
4462 Set_Is_Inlined (Subp);
4465 if not Has_Pragma_Inline (Subp) then
4466 Set_Has_Pragma_Inline (Subp);
4470 if Prag_Id = Pragma_Inline_Always then
4471 Set_Has_Pragma_Inline_Always (Subp);
4473 end Set_Inline_Flags;
4475 -- Start of processing for Process_Inline
4478 Check_No_Identifiers;
4479 Check_At_Least_N_Arguments (1);
4482 Inline_Processing_Required := True;
4486 while Present (Assoc) loop
4487 Subp_Id := Get_Pragma_Arg (Assoc);
4491 if Is_Entity_Name (Subp_Id) then
4492 Subp := Entity (Subp_Id);
4494 if Subp = Any_Id then
4496 -- If previous error, avoid cascaded errors
4504 -- For the pragma case, climb homonym chain. This is
4505 -- what implements allowing the pragma in the renaming
4506 -- case, with the result applying to the ancestors.
4508 if not From_Aspect_Specification (N) then
4509 while Present (Homonym (Subp))
4510 and then Scope (Homonym (Subp)) = Current_Scope
4512 Make_Inline (Homonym (Subp));
4513 Subp := Homonym (Subp);
4521 ("inappropriate argument for pragma%", Assoc);
4524 and then Warn_On_Redundant_Constructs
4525 and then not Suppress_All_Inlining
4527 if Inlining_Not_Possible (Subp) then
4529 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4532 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4540 ----------------------------
4541 -- Process_Interface_Name --
4542 ----------------------------
4544 procedure Process_Interface_Name
4545 (Subprogram_Def : Entity_Id;
4551 String_Val : String_Id;
4553 procedure Check_Form_Of_Interface_Name
4555 Ext_Name_Case : Boolean);
4556 -- SN is a string literal node for an interface name. This routine
4557 -- performs some minimal checks that the name is reasonable. In
4558 -- particular that no spaces or other obviously incorrect characters
4559 -- appear. This is only a warning, since any characters are allowed.
4560 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4562 ----------------------------------
4563 -- Check_Form_Of_Interface_Name --
4564 ----------------------------------
4566 procedure Check_Form_Of_Interface_Name
4568 Ext_Name_Case : Boolean)
4570 S : constant String_Id := Strval (Expr_Value_S (SN));
4571 SL : constant Nat := String_Length (S);
4576 Error_Msg_N ("interface name cannot be null string", SN);
4579 for J in 1 .. SL loop
4580 C := Get_String_Char (S, J);
4582 -- Look for dubious character and issue unconditional warning.
4583 -- Definitely dubious if not in character range.
4585 if not In_Character_Range (C)
4587 -- For all cases except CLI target,
4588 -- commas, spaces and slashes are dubious (in CLI, we use
4589 -- commas and backslashes in external names to specify
4590 -- assembly version and public key, while slashes and spaces
4591 -- can be used in names to mark nested classes and
4594 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4595 and then (Get_Character (C) = ','
4597 Get_Character (C) = '\'))
4598 or else (VM_Target /= CLI_Target
4599 and then (Get_Character (C) = ' '
4601 Get_Character (C) = '/'))
4604 ("?interface name contains illegal character",
4605 Sloc (SN) + Source_Ptr (J));
4608 end Check_Form_Of_Interface_Name;
4610 -- Start of processing for Process_Interface_Name
4613 if No (Link_Arg) then
4614 if No (Ext_Arg) then
4615 if VM_Target = CLI_Target
4616 and then Ekind (Subprogram_Def) = E_Package
4617 and then Nkind (Parent (Subprogram_Def)) =
4618 N_Package_Specification
4619 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4624 (Generic_Parent (Parent (Subprogram_Def))));
4629 elsif Chars (Ext_Arg) = Name_Link_Name then
4631 Link_Nam := Expression (Ext_Arg);
4634 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4635 Ext_Nam := Expression (Ext_Arg);
4640 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4641 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4642 Ext_Nam := Expression (Ext_Arg);
4643 Link_Nam := Expression (Link_Arg);
4646 -- Check expressions for external name and link name are static
4648 if Present (Ext_Nam) then
4649 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4650 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4652 -- Verify that external name is not the name of a local entity,
4653 -- which would hide the imported one and could lead to run-time
4654 -- surprises. The problem can only arise for entities declared in
4655 -- a package body (otherwise the external name is fully qualified
4656 -- and will not conflict).
4664 if Prag_Id = Pragma_Import then
4665 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4667 E := Entity_Id (Get_Name_Table_Info (Nam));
4669 if Nam /= Chars (Subprogram_Def)
4670 and then Present (E)
4671 and then not Is_Overloadable (E)
4672 and then Is_Immediately_Visible (E)
4673 and then not Is_Imported (E)
4674 and then Ekind (Scope (E)) = E_Package
4677 while Present (Par) loop
4678 if Nkind (Par) = N_Package_Body then
4679 Error_Msg_Sloc := Sloc (E);
4681 ("imported entity is hidden by & declared#",
4686 Par := Parent (Par);
4693 if Present (Link_Nam) then
4694 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4695 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4698 -- If there is no link name, just set the external name
4700 if No (Link_Nam) then
4701 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4703 -- For the Link_Name case, the given literal is preceded by an
4704 -- asterisk, which indicates to GCC that the given name should be
4705 -- taken literally, and in particular that no prepending of
4706 -- underlines should occur, even in systems where this is the
4712 if VM_Target = No_VM then
4713 Store_String_Char (Get_Char_Code ('*'));
4716 String_Val := Strval (Expr_Value_S (Link_Nam));
4717 Store_String_Chars (String_Val);
4719 Make_String_Literal (Sloc (Link_Nam),
4720 Strval => End_String);
4723 Set_Encoded_Interface_Name
4724 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4726 -- We allow duplicated export names in CIL, as they are always
4727 -- enclosed in a namespace that differentiates them, and overloaded
4728 -- entities are supported by the VM.
4730 if Convention (Subprogram_Def) /= Convention_CIL then
4731 Check_Duplicated_Export_Name (Link_Nam);
4733 end Process_Interface_Name;
4735 -----------------------------------------
4736 -- Process_Interrupt_Or_Attach_Handler --
4737 -----------------------------------------
4739 procedure Process_Interrupt_Or_Attach_Handler is
4740 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4741 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4742 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4745 Set_Is_Interrupt_Handler (Handler_Proc);
4747 -- If the pragma is not associated with a handler procedure within a
4748 -- protected type, then it must be for a nonprotected procedure for
4749 -- the AAMP target, in which case we don't associate a representation
4750 -- item with the procedure's scope.
4752 if Ekind (Proc_Scope) = E_Protected_Type then
4753 if Prag_Id = Pragma_Interrupt_Handler
4755 Prag_Id = Pragma_Attach_Handler
4757 Record_Rep_Item (Proc_Scope, N);
4760 end Process_Interrupt_Or_Attach_Handler;
4762 --------------------------------------------------
4763 -- Process_Restrictions_Or_Restriction_Warnings --
4764 --------------------------------------------------
4766 -- Note: some of the simple identifier cases were handled in par-prag,
4767 -- but it is harmless (and more straightforward) to simply handle all
4768 -- cases here, even if it means we repeat a bit of work in some cases.
4770 procedure Process_Restrictions_Or_Restriction_Warnings
4774 R_Id : Restriction_Id;
4779 procedure Check_Unit_Name (N : Node_Id);
4780 -- Checks unit name parameter for No_Dependence. Returns if it has
4781 -- an appropriate form, otherwise raises pragma argument error.
4783 ---------------------
4784 -- Check_Unit_Name --
4785 ---------------------
4787 procedure Check_Unit_Name (N : Node_Id) is
4789 if Nkind (N) = N_Selected_Component then
4790 Check_Unit_Name (Prefix (N));
4791 Check_Unit_Name (Selector_Name (N));
4793 elsif Nkind (N) = N_Identifier then
4798 ("wrong form for unit name for No_Dependence", N);
4800 end Check_Unit_Name;
4802 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4805 -- Ignore all Restrictions pragma in CodePeer mode
4807 if CodePeer_Mode then
4811 Check_Ada_83_Warning;
4812 Check_At_Least_N_Arguments (1);
4813 Check_Valid_Configuration_Pragma;
4816 while Present (Arg) loop
4818 Expr := Get_Pragma_Arg (Arg);
4820 -- Case of no restriction identifier present
4822 if Id = No_Name then
4823 if Nkind (Expr) /= N_Identifier then
4825 ("invalid form for restriction", Arg);
4830 (Process_Restriction_Synonyms (Expr));
4832 if R_Id not in All_Boolean_Restrictions then
4833 Error_Msg_Name_1 := Pname;
4835 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4837 -- Check for possible misspelling
4839 for J in Restriction_Id loop
4841 Rnm : constant String := Restriction_Id'Image (J);
4844 Name_Buffer (1 .. Rnm'Length) := Rnm;
4845 Name_Len := Rnm'Length;
4846 Set_Casing (All_Lower_Case);
4848 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4850 (Identifier_Casing (Current_Source_File));
4851 Error_Msg_String (1 .. Rnm'Length) :=
4852 Name_Buffer (1 .. Name_Len);
4853 Error_Msg_Strlen := Rnm'Length;
4854 Error_Msg_N -- CODEFIX
4855 ("\possible misspelling of ""~""",
4856 Get_Pragma_Arg (Arg));
4865 if Implementation_Restriction (R_Id) then
4866 Check_Restriction (No_Implementation_Restrictions, Arg);
4869 -- If this is a warning, then set the warning unless we already
4870 -- have a real restriction active (we never want a warning to
4871 -- override a real restriction).
4874 if not Restriction_Active (R_Id) then
4875 Set_Restriction (R_Id, N);
4876 Restriction_Warnings (R_Id) := True;
4879 -- If real restriction case, then set it and make sure that the
4880 -- restriction warning flag is off, since a real restriction
4881 -- always overrides a warning.
4884 Set_Restriction (R_Id, N);
4885 Restriction_Warnings (R_Id) := False;
4888 -- Check for obsolescent restrictions in Ada 2005 mode
4891 and then Ada_Version >= Ada_2005
4892 and then (R_Id = No_Asynchronous_Control
4894 R_Id = No_Unchecked_Deallocation
4896 R_Id = No_Unchecked_Conversion)
4898 Check_Restriction (No_Obsolescent_Features, N);
4901 -- A very special case that must be processed here: pragma
4902 -- Restrictions (No_Exceptions) turns off all run-time
4903 -- checking. This is a bit dubious in terms of the formal
4904 -- language definition, but it is what is intended by RM
4905 -- H.4(12). Restriction_Warnings never affects generated code
4906 -- so this is done only in the real restriction case.
4908 if R_Id = No_Exceptions and then not Warn then
4909 Scope_Suppress := (others => True);
4912 -- Case of No_Dependence => unit-name. Note that the parser
4913 -- already made the necessary entry in the No_Dependence table.
4915 elsif Id = Name_No_Dependence then
4916 Check_Unit_Name (Expr);
4918 -- All other cases of restriction identifier present
4921 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4922 Analyze_And_Resolve (Expr, Any_Integer);
4924 if R_Id not in All_Parameter_Restrictions then
4926 ("invalid restriction parameter identifier", Arg);
4928 elsif not Is_OK_Static_Expression (Expr) then
4929 Flag_Non_Static_Expr
4930 ("value must be static expression!", Expr);
4933 elsif not Is_Integer_Type (Etype (Expr))
4934 or else Expr_Value (Expr) < 0
4937 ("value must be non-negative integer", Arg);
4940 -- Restriction pragma is active
4942 Val := Expr_Value (Expr);
4944 if not UI_Is_In_Int_Range (Val) then
4946 ("pragma ignored, value too large?", Arg);
4949 -- Warning case. If the real restriction is active, then we
4950 -- ignore the request, since warning never overrides a real
4951 -- restriction. Otherwise we set the proper warning. Note that
4952 -- this circuit sets the warning again if it is already set,
4953 -- which is what we want, since the constant may have changed.
4956 if not Restriction_Active (R_Id) then
4958 (R_Id, N, Integer (UI_To_Int (Val)));
4959 Restriction_Warnings (R_Id) := True;
4962 -- Real restriction case, set restriction and make sure warning
4963 -- flag is off since real restriction always overrides warning.
4966 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4967 Restriction_Warnings (R_Id) := False;
4973 end Process_Restrictions_Or_Restriction_Warnings;
4975 ---------------------------------
4976 -- Process_Suppress_Unsuppress --
4977 ---------------------------------
4979 -- Note: this procedure makes entries in the check suppress data
4980 -- structures managed by Sem. See spec of package Sem for full
4981 -- details on how we handle recording of check suppression.
4983 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4988 In_Package_Spec : constant Boolean :=
4989 Is_Package_Or_Generic_Package (Current_Scope)
4990 and then not In_Package_Body (Current_Scope);
4992 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4993 -- Used to suppress a single check on the given entity
4995 --------------------------------
4996 -- Suppress_Unsuppress_Echeck --
4997 --------------------------------
4999 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5001 Set_Checks_May_Be_Suppressed (E);
5003 if In_Package_Spec then
5004 Push_Global_Suppress_Stack_Entry
5007 Suppress => Suppress_Case);
5010 Push_Local_Suppress_Stack_Entry
5013 Suppress => Suppress_Case);
5016 -- If this is a first subtype, and the base type is distinct,
5017 -- then also set the suppress flags on the base type.
5019 if Is_First_Subtype (E)
5020 and then Etype (E) /= E
5022 Suppress_Unsuppress_Echeck (Etype (E), C);
5024 end Suppress_Unsuppress_Echeck;
5026 -- Start of processing for Process_Suppress_Unsuppress
5029 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5030 -- we want to generate checks for analysis purposes, as set by -gnatC
5032 if CodePeer_Mode and then Comes_From_Source (N) then
5036 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5037 -- declarative part or a package spec (RM 11.5(5)).
5039 if not Is_Configuration_Pragma then
5040 Check_Is_In_Decl_Part_Or_Package_Spec;
5043 Check_At_Least_N_Arguments (1);
5044 Check_At_Most_N_Arguments (2);
5045 Check_No_Identifier (Arg1);
5046 Check_Arg_Is_Identifier (Arg1);
5048 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5050 if C = No_Check_Id then
5052 ("argument of pragma% is not valid check name", Arg1);
5055 if not Suppress_Case
5056 and then (C = All_Checks or else C = Overflow_Check)
5058 Opt.Overflow_Checks_Unsuppressed := True;
5061 if Arg_Count = 1 then
5063 -- Make an entry in the local scope suppress table. This is the
5064 -- table that directly shows the current value of the scope
5065 -- suppress check for any check id value.
5067 if C = All_Checks then
5069 -- For All_Checks, we set all specific predefined checks with
5070 -- the exception of Elaboration_Check, which is handled
5071 -- specially because of not wanting All_Checks to have the
5072 -- effect of deactivating static elaboration order processing.
5074 for J in Scope_Suppress'Range loop
5075 if J /= Elaboration_Check then
5076 Scope_Suppress (J) := Suppress_Case;
5080 -- If not All_Checks, and predefined check, then set appropriate
5081 -- scope entry. Note that we will set Elaboration_Check if this
5082 -- is explicitly specified.
5084 elsif C in Predefined_Check_Id then
5085 Scope_Suppress (C) := Suppress_Case;
5088 -- Also make an entry in the Local_Entity_Suppress table
5090 Push_Local_Suppress_Stack_Entry
5093 Suppress => Suppress_Case);
5095 -- Case of two arguments present, where the check is suppressed for
5096 -- a specified entity (given as the second argument of the pragma)
5099 -- This is obsolescent in Ada 2005 mode
5101 if Ada_Version >= Ada_2005 then
5102 Check_Restriction (No_Obsolescent_Features, Arg2);
5105 Check_Optional_Identifier (Arg2, Name_On);
5106 E_Id := Get_Pragma_Arg (Arg2);
5109 if not Is_Entity_Name (E_Id) then
5111 ("second argument of pragma% must be entity name", Arg2);
5120 -- Enforce RM 11.5(7) which requires that for a pragma that
5121 -- appears within a package spec, the named entity must be
5122 -- within the package spec. We allow the package name itself
5123 -- to be mentioned since that makes sense, although it is not
5124 -- strictly allowed by 11.5(7).
5127 and then E /= Current_Scope
5128 and then Scope (E) /= Current_Scope
5131 ("entity in pragma% is not in package spec (RM 11.5(7))",
5135 -- Loop through homonyms. As noted below, in the case of a package
5136 -- spec, only homonyms within the package spec are considered.
5139 Suppress_Unsuppress_Echeck (E, C);
5141 if Is_Generic_Instance (E)
5142 and then Is_Subprogram (E)
5143 and then Present (Alias (E))
5145 Suppress_Unsuppress_Echeck (Alias (E), C);
5148 -- Move to next homonym if not aspect spec case
5150 exit when From_Aspect_Specification (N);
5154 -- If we are within a package specification, the pragma only
5155 -- applies to homonyms in the same scope.
5157 exit when In_Package_Spec
5158 and then Scope (E) /= Current_Scope;
5161 end Process_Suppress_Unsuppress;
5167 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5169 if Is_Imported (E) then
5171 ("cannot export entity& that was previously imported", Arg);
5173 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5175 ("cannot export entity& that has an address clause", Arg);
5178 Set_Is_Exported (E);
5180 -- Generate a reference for entity explicitly, because the
5181 -- identifier may be overloaded and name resolution will not
5184 Generate_Reference (E, Arg);
5186 -- Deal with exporting non-library level entity
5188 if not Is_Library_Level_Entity (E) then
5190 -- Not allowed at all for subprograms
5192 if Is_Subprogram (E) then
5193 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5195 -- Otherwise set public and statically allocated
5199 Set_Is_Statically_Allocated (E);
5201 -- Warn if the corresponding W flag is set and the pragma comes
5202 -- from source. The latter may not be true e.g. on VMS where we
5203 -- expand export pragmas for exception codes associated with
5204 -- imported or exported exceptions. We do not want to generate
5205 -- a warning for something that the user did not write.
5207 if Warn_On_Export_Import
5208 and then Comes_From_Source (Arg)
5211 ("?& has been made static as a result of Export", Arg, E);
5213 ("\this usage is non-standard and non-portable", Arg);
5218 if Warn_On_Export_Import and then Is_Type (E) then
5219 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5222 if Warn_On_Export_Import and Inside_A_Generic then
5224 ("all instances of& will have the same external name?", Arg, E);
5228 ----------------------------------------------
5229 -- Set_Extended_Import_Export_External_Name --
5230 ----------------------------------------------
5232 procedure Set_Extended_Import_Export_External_Name
5233 (Internal_Ent : Entity_Id;
5234 Arg_External : Node_Id)
5236 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5240 if No (Arg_External) then
5244 Check_Arg_Is_External_Name (Arg_External);
5246 if Nkind (Arg_External) = N_String_Literal then
5247 if String_Length (Strval (Arg_External)) = 0 then
5250 New_Name := Adjust_External_Name_Case (Arg_External);
5253 elsif Nkind (Arg_External) = N_Identifier then
5254 New_Name := Get_Default_External_Name (Arg_External);
5256 -- Check_Arg_Is_External_Name should let through only identifiers and
5257 -- string literals or static string expressions (which are folded to
5258 -- string literals).
5261 raise Program_Error;
5264 -- If we already have an external name set (by a prior normal Import
5265 -- or Export pragma), then the external names must match
5267 if Present (Interface_Name (Internal_Ent)) then
5268 Check_Matching_Internal_Names : declare
5269 S1 : constant String_Id := Strval (Old_Name);
5270 S2 : constant String_Id := Strval (New_Name);
5273 -- Called if names do not match
5279 procedure Mismatch is
5281 Error_Msg_Sloc := Sloc (Old_Name);
5283 ("external name does not match that given #",
5287 -- Start of processing for Check_Matching_Internal_Names
5290 if String_Length (S1) /= String_Length (S2) then
5294 for J in 1 .. String_Length (S1) loop
5295 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5300 end Check_Matching_Internal_Names;
5302 -- Otherwise set the given name
5305 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5306 Check_Duplicated_Export_Name (New_Name);
5308 end Set_Extended_Import_Export_External_Name;
5314 procedure Set_Imported (E : Entity_Id) is
5316 -- Error message if already imported or exported
5318 if Is_Exported (E) or else Is_Imported (E) then
5320 -- Error if being set Exported twice
5322 if Is_Exported (E) then
5323 Error_Msg_NE ("entity& was previously exported", N, E);
5325 -- OK if Import/Interface case
5327 elsif Import_Interface_Present (N) then
5330 -- Error if being set Imported twice
5333 Error_Msg_NE ("entity& was previously imported", N, E);
5336 Error_Msg_Name_1 := Pname;
5338 ("\(pragma% applies to all previous entities)", N);
5340 Error_Msg_Sloc := Sloc (E);
5341 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5343 -- Here if not previously imported or exported, OK to import
5346 Set_Is_Imported (E);
5348 -- If the entity is an object that is not at the library level,
5349 -- then it is statically allocated. We do not worry about objects
5350 -- with address clauses in this context since they are not really
5351 -- imported in the linker sense.
5354 and then not Is_Library_Level_Entity (E)
5355 and then No (Address_Clause (E))
5357 Set_Is_Statically_Allocated (E);
5364 -------------------------
5365 -- Set_Mechanism_Value --
5366 -------------------------
5368 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5369 -- analyzed, since it is semantic nonsense), so we get it in the exact
5370 -- form created by the parser.
5372 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5375 Mech_Name_Id : Name_Id;
5377 procedure Bad_Class;
5378 -- Signal bad descriptor class name
5380 procedure Bad_Mechanism;
5381 -- Signal bad mechanism name
5387 procedure Bad_Class is
5389 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5392 -------------------------
5393 -- Bad_Mechanism_Value --
5394 -------------------------
5396 procedure Bad_Mechanism is
5398 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5401 -- Start of processing for Set_Mechanism_Value
5404 if Mechanism (Ent) /= Default_Mechanism then
5406 ("mechanism for & has already been set", Mech_Name, Ent);
5409 -- MECHANISM_NAME ::= value | reference | descriptor |
5412 if Nkind (Mech_Name) = N_Identifier then
5413 if Chars (Mech_Name) = Name_Value then
5414 Set_Mechanism (Ent, By_Copy);
5417 elsif Chars (Mech_Name) = Name_Reference then
5418 Set_Mechanism (Ent, By_Reference);
5421 elsif Chars (Mech_Name) = Name_Descriptor then
5422 Check_VMS (Mech_Name);
5424 -- Descriptor => Short_Descriptor if pragma was given
5426 if Short_Descriptors then
5427 Set_Mechanism (Ent, By_Short_Descriptor);
5429 Set_Mechanism (Ent, By_Descriptor);
5434 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5435 Check_VMS (Mech_Name);
5436 Set_Mechanism (Ent, By_Short_Descriptor);
5439 elsif Chars (Mech_Name) = Name_Copy then
5441 ("bad mechanism name, Value assumed", Mech_Name);
5447 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5448 -- short_descriptor (CLASS_NAME)
5449 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5451 -- Note: this form is parsed as an indexed component
5453 elsif Nkind (Mech_Name) = N_Indexed_Component then
5454 Class := First (Expressions (Mech_Name));
5456 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5457 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5458 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5459 or else Present (Next (Class))
5463 Mech_Name_Id := Chars (Prefix (Mech_Name));
5465 -- Change Descriptor => Short_Descriptor if pragma was given
5467 if Mech_Name_Id = Name_Descriptor
5468 and then Short_Descriptors
5470 Mech_Name_Id := Name_Short_Descriptor;
5474 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5475 -- short_descriptor (Class => CLASS_NAME)
5476 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5478 -- Note: this form is parsed as a function call
5480 elsif Nkind (Mech_Name) = N_Function_Call then
5481 Param := First (Parameter_Associations (Mech_Name));
5483 if Nkind (Name (Mech_Name)) /= N_Identifier
5484 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5485 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5486 or else Present (Next (Param))
5487 or else No (Selector_Name (Param))
5488 or else Chars (Selector_Name (Param)) /= Name_Class
5492 Class := Explicit_Actual_Parameter (Param);
5493 Mech_Name_Id := Chars (Name (Mech_Name));
5500 -- Fall through here with Class set to descriptor class name
5502 Check_VMS (Mech_Name);
5504 if Nkind (Class) /= N_Identifier then
5507 elsif Mech_Name_Id = Name_Descriptor
5508 and then Chars (Class) = Name_UBS
5510 Set_Mechanism (Ent, By_Descriptor_UBS);
5512 elsif Mech_Name_Id = Name_Descriptor
5513 and then Chars (Class) = Name_UBSB
5515 Set_Mechanism (Ent, By_Descriptor_UBSB);
5517 elsif Mech_Name_Id = Name_Descriptor
5518 and then Chars (Class) = Name_UBA
5520 Set_Mechanism (Ent, By_Descriptor_UBA);
5522 elsif Mech_Name_Id = Name_Descriptor
5523 and then Chars (Class) = Name_S
5525 Set_Mechanism (Ent, By_Descriptor_S);
5527 elsif Mech_Name_Id = Name_Descriptor
5528 and then Chars (Class) = Name_SB
5530 Set_Mechanism (Ent, By_Descriptor_SB);
5532 elsif Mech_Name_Id = Name_Descriptor
5533 and then Chars (Class) = Name_A
5535 Set_Mechanism (Ent, By_Descriptor_A);
5537 elsif Mech_Name_Id = Name_Descriptor
5538 and then Chars (Class) = Name_NCA
5540 Set_Mechanism (Ent, By_Descriptor_NCA);
5542 elsif Mech_Name_Id = Name_Short_Descriptor
5543 and then Chars (Class) = Name_UBS
5545 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5547 elsif Mech_Name_Id = Name_Short_Descriptor
5548 and then Chars (Class) = Name_UBSB
5550 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5552 elsif Mech_Name_Id = Name_Short_Descriptor
5553 and then Chars (Class) = Name_UBA
5555 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5557 elsif Mech_Name_Id = Name_Short_Descriptor
5558 and then Chars (Class) = Name_S
5560 Set_Mechanism (Ent, By_Short_Descriptor_S);
5562 elsif Mech_Name_Id = Name_Short_Descriptor
5563 and then Chars (Class) = Name_SB
5565 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5567 elsif Mech_Name_Id = Name_Short_Descriptor
5568 and then Chars (Class) = Name_A
5570 Set_Mechanism (Ent, By_Short_Descriptor_A);
5572 elsif Mech_Name_Id = Name_Short_Descriptor
5573 and then Chars (Class) = Name_NCA
5575 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5580 end Set_Mechanism_Value;
5582 ---------------------------
5583 -- Set_Ravenscar_Profile --
5584 ---------------------------
5586 -- The tasks to be done here are
5588 -- Set required policies
5590 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5591 -- pragma Locking_Policy (Ceiling_Locking)
5593 -- Set Detect_Blocking mode
5595 -- Set required restrictions (see System.Rident for detailed list)
5597 -- Set the No_Dependence rules
5598 -- No_Dependence => Ada.Asynchronous_Task_Control
5599 -- No_Dependence => Ada.Calendar
5600 -- No_Dependence => Ada.Execution_Time.Group_Budget
5601 -- No_Dependence => Ada.Execution_Time.Timers
5602 -- No_Dependence => Ada.Task_Attributes
5603 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5605 procedure Set_Ravenscar_Profile (N : Node_Id) is
5606 Prefix_Entity : Entity_Id;
5607 Selector_Entity : Entity_Id;
5608 Prefix_Node : Node_Id;
5612 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5614 if Task_Dispatching_Policy /= ' '
5615 and then Task_Dispatching_Policy /= 'F'
5617 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5618 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5620 -- Set the FIFO_Within_Priorities policy, but always preserve
5621 -- System_Location since we like the error message with the run time
5625 Task_Dispatching_Policy := 'F';
5627 if Task_Dispatching_Policy_Sloc /= System_Location then
5628 Task_Dispatching_Policy_Sloc := Loc;
5632 -- pragma Locking_Policy (Ceiling_Locking)
5634 if Locking_Policy /= ' '
5635 and then Locking_Policy /= 'C'
5637 Error_Msg_Sloc := Locking_Policy_Sloc;
5638 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5640 -- Set the Ceiling_Locking policy, but preserve System_Location since
5641 -- we like the error message with the run time name.
5644 Locking_Policy := 'C';
5646 if Locking_Policy_Sloc /= System_Location then
5647 Locking_Policy_Sloc := Loc;
5651 -- pragma Detect_Blocking
5653 Detect_Blocking := True;
5655 -- Set the corresponding restrictions
5657 Set_Profile_Restrictions
5658 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5660 -- Set the No_Dependence restrictions
5662 -- The following No_Dependence restrictions:
5663 -- No_Dependence => Ada.Asynchronous_Task_Control
5664 -- No_Dependence => Ada.Calendar
5665 -- No_Dependence => Ada.Task_Attributes
5666 -- are already set by previous call to Set_Profile_Restrictions.
5668 -- Set the following restrictions which were added to Ada 2005:
5669 -- No_Dependence => Ada.Execution_Time.Group_Budget
5670 -- No_Dependence => Ada.Execution_Time.Timers
5672 if Ada_Version >= Ada_2005 then
5673 Name_Buffer (1 .. 3) := "ada";
5676 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5678 Name_Buffer (1 .. 14) := "execution_time";
5681 Selector_Entity := Make_Identifier (Loc, Name_Find);
5684 Make_Selected_Component
5686 Prefix => Prefix_Entity,
5687 Selector_Name => Selector_Entity);
5689 Name_Buffer (1 .. 13) := "group_budgets";
5692 Selector_Entity := Make_Identifier (Loc, Name_Find);
5695 Make_Selected_Component
5697 Prefix => Prefix_Node,
5698 Selector_Name => Selector_Entity);
5700 Set_Restriction_No_Dependence
5702 Warn => Treat_Restrictions_As_Warnings,
5703 Profile => Ravenscar);
5705 Name_Buffer (1 .. 6) := "timers";
5708 Selector_Entity := Make_Identifier (Loc, Name_Find);
5711 Make_Selected_Component
5713 Prefix => Prefix_Node,
5714 Selector_Name => Selector_Entity);
5716 Set_Restriction_No_Dependence
5718 Warn => Treat_Restrictions_As_Warnings,
5719 Profile => Ravenscar);
5722 -- Set the following restrictions which was added to Ada 2012 (see
5724 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5726 if Ada_Version >= Ada_2012 then
5727 Name_Buffer (1 .. 6) := "system";
5730 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5732 Name_Buffer (1 .. 15) := "multiprocessors";
5735 Selector_Entity := Make_Identifier (Loc, Name_Find);
5738 Make_Selected_Component
5740 Prefix => Prefix_Entity,
5741 Selector_Name => Selector_Entity);
5743 Name_Buffer (1 .. 19) := "dispatching_domains";
5746 Selector_Entity := Make_Identifier (Loc, Name_Find);
5749 Make_Selected_Component
5751 Prefix => Prefix_Node,
5752 Selector_Name => Selector_Entity);
5754 Set_Restriction_No_Dependence
5756 Warn => Treat_Restrictions_As_Warnings,
5757 Profile => Ravenscar);
5759 end Set_Ravenscar_Profile;
5761 -- Start of processing for Analyze_Pragma
5764 -- The following code is a defense against recursion. Not clear that
5765 -- this can happen legitimately, but perhaps some error situations
5766 -- can cause it, and we did see this recursion during testing.
5768 if Analyzed (N) then
5771 Set_Analyzed (N, True);
5774 -- Deal with unrecognized pragma
5776 if not Is_Pragma_Name (Pname) then
5777 if Warn_On_Unrecognized_Pragma then
5778 Error_Msg_Name_1 := Pname;
5779 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5781 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5782 if Is_Bad_Spelling_Of (Pname, PN) then
5783 Error_Msg_Name_1 := PN;
5784 Error_Msg_N -- CODEFIX
5785 ("\?possible misspelling of %!", Pragma_Identifier (N));
5794 -- Here to start processing for recognized pragma
5796 Prag_Id := Get_Pragma_Id (Pname);
5806 if Present (Pragma_Argument_Associations (N)) then
5807 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5808 Arg1 := First (Pragma_Argument_Associations (N));
5810 if Present (Arg1) then
5811 Arg2 := Next (Arg1);
5813 if Present (Arg2) then
5814 Arg3 := Next (Arg2);
5816 if Present (Arg3) then
5817 Arg4 := Next (Arg3);
5823 -- An enumeration type defines the pragmas that are supported by the
5824 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5825 -- into the corresponding enumeration value for the following case.
5833 -- pragma Abort_Defer;
5835 when Pragma_Abort_Defer =>
5837 Check_Arg_Count (0);
5839 -- The only required semantic processing is to check the
5840 -- placement. This pragma must appear at the start of the
5841 -- statement sequence of a handled sequence of statements.
5843 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5844 or else N /= First (Statements (Parent (N)))
5855 -- Note: this pragma also has some specific processing in Par.Prag
5856 -- because we want to set the Ada version mode during parsing.
5858 when Pragma_Ada_83 =>
5860 Check_Arg_Count (0);
5862 -- We really should check unconditionally for proper configuration
5863 -- pragma placement, since we really don't want mixed Ada modes
5864 -- within a single unit, and the GNAT reference manual has always
5865 -- said this was a configuration pragma, but we did not check and
5866 -- are hesitant to add the check now.
5868 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5869 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5870 -- or Ada 2012 mode.
5872 if Ada_Version >= Ada_2005 then
5873 Check_Valid_Configuration_Pragma;
5876 -- Now set Ada 83 mode
5878 Ada_Version := Ada_83;
5879 Ada_Version_Explicit := Ada_Version;
5887 -- Note: this pragma also has some specific processing in Par.Prag
5888 -- because we want to set the Ada 83 version mode during parsing.
5890 when Pragma_Ada_95 =>
5892 Check_Arg_Count (0);
5894 -- We really should check unconditionally for proper configuration
5895 -- pragma placement, since we really don't want mixed Ada modes
5896 -- within a single unit, and the GNAT reference manual has always
5897 -- said this was a configuration pragma, but we did not check and
5898 -- are hesitant to add the check now.
5900 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5901 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5903 if Ada_Version >= Ada_2005 then
5904 Check_Valid_Configuration_Pragma;
5907 -- Now set Ada 95 mode
5909 Ada_Version := Ada_95;
5910 Ada_Version_Explicit := Ada_Version;
5912 ---------------------
5913 -- Ada_05/Ada_2005 --
5914 ---------------------
5917 -- pragma Ada_05 (LOCAL_NAME);
5920 -- pragma Ada_2005 (LOCAL_NAME):
5922 -- Note: these pragmas also have some specific processing in Par.Prag
5923 -- because we want to set the Ada 2005 version mode during parsing.
5925 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5931 if Arg_Count = 1 then
5932 Check_Arg_Is_Local_Name (Arg1);
5933 E_Id := Get_Pragma_Arg (Arg1);
5935 if Etype (E_Id) = Any_Type then
5939 Set_Is_Ada_2005_Only (Entity (E_Id));
5942 Check_Arg_Count (0);
5944 -- For Ada_2005 we unconditionally enforce the documented
5945 -- configuration pragma placement, since we do not want to
5946 -- tolerate mixed modes in a unit involving Ada 2005. That
5947 -- would cause real difficulties for those cases where there
5948 -- are incompatibilities between Ada 95 and Ada 2005.
5950 Check_Valid_Configuration_Pragma;
5952 -- Now set appropriate Ada mode
5954 Ada_Version := Ada_2005;
5955 Ada_Version_Explicit := Ada_2005;
5959 ---------------------
5960 -- Ada_12/Ada_2012 --
5961 ---------------------
5964 -- pragma Ada_12 (LOCAL_NAME);
5967 -- pragma Ada_2012 (LOCAL_NAME):
5969 -- Note: these pragmas also have some specific processing in Par.Prag
5970 -- because we want to set the Ada 2012 version mode during parsing.
5972 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5978 if Arg_Count = 1 then
5979 Check_Arg_Is_Local_Name (Arg1);
5980 E_Id := Get_Pragma_Arg (Arg1);
5982 if Etype (E_Id) = Any_Type then
5986 Set_Is_Ada_2012_Only (Entity (E_Id));
5989 Check_Arg_Count (0);
5991 -- For Ada_2012 we unconditionally enforce the documented
5992 -- configuration pragma placement, since we do not want to
5993 -- tolerate mixed modes in a unit involving Ada 2012. That
5994 -- would cause real difficulties for those cases where there
5995 -- are incompatibilities between Ada 95 and Ada 2012. We could
5996 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5998 Check_Valid_Configuration_Pragma;
6000 -- Now set appropriate Ada mode
6002 Ada_Version := Ada_2012;
6003 Ada_Version_Explicit := Ada_2012;
6007 ----------------------
6008 -- All_Calls_Remote --
6009 ----------------------
6011 -- pragma All_Calls_Remote [(library_package_NAME)];
6013 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6014 Lib_Entity : Entity_Id;
6017 Check_Ada_83_Warning;
6018 Check_Valid_Library_Unit_Pragma;
6020 if Nkind (N) = N_Null_Statement then
6024 Lib_Entity := Find_Lib_Unit_Name;
6026 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6028 if Present (Lib_Entity)
6029 and then not Debug_Flag_U
6031 if not Is_Remote_Call_Interface (Lib_Entity) then
6032 Error_Pragma ("pragma% only apply to rci unit");
6034 -- Set flag for entity of the library unit
6037 Set_Has_All_Calls_Remote (Lib_Entity);
6041 end All_Calls_Remote;
6047 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6048 -- ARG ::= NAME | EXPRESSION
6050 -- The first two arguments are by convention intended to refer to an
6051 -- external tool and a tool-specific function. These arguments are
6054 when Pragma_Annotate => Annotate : begin
6056 Check_At_Least_N_Arguments (1);
6057 Check_Arg_Is_Identifier (Arg1);
6058 Check_No_Identifiers;
6066 -- Second unanalyzed parameter is optional
6072 while Present (Arg) loop
6073 Exp := Get_Pragma_Arg (Arg);
6076 if Is_Entity_Name (Exp) then
6079 -- For string literals, we assume Standard_String as the
6080 -- type, unless the string contains wide or wide_wide
6083 elsif Nkind (Exp) = N_String_Literal then
6084 if Has_Wide_Wide_Character (Exp) then
6085 Resolve (Exp, Standard_Wide_Wide_String);
6086 elsif Has_Wide_Character (Exp) then
6087 Resolve (Exp, Standard_Wide_String);
6089 Resolve (Exp, Standard_String);
6092 elsif Is_Overloaded (Exp) then
6094 ("ambiguous argument for pragma%", Exp);
6110 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6111 -- [, [Message =>] Static_String_EXPRESSION]);
6113 when Pragma_Assert => Assert : declare
6119 Check_At_Least_N_Arguments (1);
6120 Check_At_Most_N_Arguments (2);
6121 Check_Arg_Order ((Name_Check, Name_Message));
6122 Check_Optional_Identifier (Arg1, Name_Check);
6124 -- We treat pragma Assert as equivalent to:
6126 -- pragma Check (Assertion, condition [, msg]);
6128 -- So rewrite pragma in this manner, and analyze the result
6130 Expr := Get_Pragma_Arg (Arg1);
6132 Make_Pragma_Argument_Association (Loc,
6133 Expression => Make_Identifier (Loc, Name_Assertion)),
6135 Make_Pragma_Argument_Association (Sloc (Expr),
6136 Expression => Expr));
6138 if Arg_Count > 1 then
6139 Check_Optional_Identifier (Arg2, Name_Message);
6140 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6141 Append_To (Newa, Relocate_Node (Arg2));
6146 Chars => Name_Check,
6147 Pragma_Argument_Associations => Newa));
6151 ----------------------
6152 -- Assertion_Policy --
6153 ----------------------
6155 -- pragma Assertion_Policy (Check | Ignore)
6157 when Pragma_Assertion_Policy => Assertion_Policy : declare
6162 Check_Valid_Configuration_Pragma;
6163 Check_Arg_Count (1);
6164 Check_No_Identifiers;
6165 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6167 -- We treat pragma Assertion_Policy as equivalent to:
6169 -- pragma Check_Policy (Assertion, policy)
6171 -- So rewrite the pragma in that manner and link on to the chain
6172 -- of Check_Policy pragmas, marking the pragma as analyzed.
6174 Policy := Get_Pragma_Arg (Arg1);
6178 Chars => Name_Check_Policy,
6180 Pragma_Argument_Associations => New_List (
6181 Make_Pragma_Argument_Association (Loc,
6182 Expression => Make_Identifier (Loc, Name_Assertion)),
6184 Make_Pragma_Argument_Association (Loc,
6186 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6189 Set_Next_Pragma (N, Opt.Check_Policy_List);
6190 Opt.Check_Policy_List := N;
6191 end Assertion_Policy;
6193 ------------------------------
6194 -- Assume_No_Invalid_Values --
6195 ------------------------------
6197 -- pragma Assume_No_Invalid_Values (On | Off);
6199 when Pragma_Assume_No_Invalid_Values =>
6201 Check_Valid_Configuration_Pragma;
6202 Check_Arg_Count (1);
6203 Check_No_Identifiers;
6204 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6206 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6207 Assume_No_Invalid_Values := True;
6209 Assume_No_Invalid_Values := False;
6216 -- pragma AST_Entry (entry_IDENTIFIER);
6218 when Pragma_AST_Entry => AST_Entry : declare
6224 Check_Arg_Count (1);
6225 Check_No_Identifiers;
6226 Check_Arg_Is_Local_Name (Arg1);
6227 Ent := Entity (Get_Pragma_Arg (Arg1));
6229 -- Note: the implementation of the AST_Entry pragma could handle
6230 -- the entry family case fine, but for now we are consistent with
6231 -- the DEC rules, and do not allow the pragma, which of course
6232 -- has the effect of also forbidding the attribute.
6234 if Ekind (Ent) /= E_Entry then
6236 ("pragma% argument must be simple entry name", Arg1);
6238 elsif Is_AST_Entry (Ent) then
6240 ("duplicate % pragma for entry", Arg1);
6242 elsif Has_Homonym (Ent) then
6244 ("pragma% argument cannot specify overloaded entry", Arg1);
6248 FF : constant Entity_Id := First_Formal (Ent);
6251 if Present (FF) then
6252 if Present (Next_Formal (FF)) then
6254 ("entry for pragma% can have only one argument",
6257 elsif Parameter_Mode (FF) /= E_In_Parameter then
6259 ("entry parameter for pragma% must have mode IN",
6265 Set_Is_AST_Entry (Ent);
6273 -- pragma Asynchronous (LOCAL_NAME);
6275 when Pragma_Asynchronous => Asynchronous : declare
6283 procedure Process_Async_Pragma;
6284 -- Common processing for procedure and access-to-procedure case
6286 --------------------------
6287 -- Process_Async_Pragma --
6288 --------------------------
6290 procedure Process_Async_Pragma is
6293 Set_Is_Asynchronous (Nm);
6297 -- The formals should be of mode IN (RM E.4.1(6))
6300 while Present (S) loop
6301 Formal := Defining_Identifier (S);
6303 if Nkind (Formal) = N_Defining_Identifier
6304 and then Ekind (Formal) /= E_In_Parameter
6307 ("pragma% procedure can only have IN parameter",
6314 Set_Is_Asynchronous (Nm);
6315 end Process_Async_Pragma;
6317 -- Start of processing for pragma Asynchronous
6320 Check_Ada_83_Warning;
6321 Check_No_Identifiers;
6322 Check_Arg_Count (1);
6323 Check_Arg_Is_Local_Name (Arg1);
6325 if Debug_Flag_U then
6329 C_Ent := Cunit_Entity (Current_Sem_Unit);
6330 Analyze (Get_Pragma_Arg (Arg1));
6331 Nm := Entity (Get_Pragma_Arg (Arg1));
6333 if not Is_Remote_Call_Interface (C_Ent)
6334 and then not Is_Remote_Types (C_Ent)
6336 -- This pragma should only appear in an RCI or Remote Types
6337 -- unit (RM E.4.1(4)).
6340 ("pragma% not in Remote_Call_Interface or " &
6341 "Remote_Types unit");
6344 if Ekind (Nm) = E_Procedure
6345 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6347 if not Is_Remote_Call_Interface (Nm) then
6349 ("pragma% cannot be applied on non-remote procedure",
6353 L := Parameter_Specifications (Parent (Nm));
6354 Process_Async_Pragma;
6357 elsif Ekind (Nm) = E_Function then
6359 ("pragma% cannot be applied to function", Arg1);
6361 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6362 if Is_Record_Type (Nm) then
6364 -- A record type that is the Equivalent_Type for a remote
6365 -- access-to-subprogram type.
6367 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6370 -- A non-expanded RAS type (distribution is not enabled)
6372 N := Declaration_Node (Nm);
6375 if Nkind (N) = N_Full_Type_Declaration
6376 and then Nkind (Type_Definition (N)) =
6377 N_Access_Procedure_Definition
6379 L := Parameter_Specifications (Type_Definition (N));
6380 Process_Async_Pragma;
6382 if Is_Asynchronous (Nm)
6383 and then Expander_Active
6384 and then Get_PCS_Name /= Name_No_DSA
6386 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6391 ("pragma% cannot reference access-to-function type",
6395 -- Only other possibility is Access-to-class-wide type
6397 elsif Is_Access_Type (Nm)
6398 and then Is_Class_Wide_Type (Designated_Type (Nm))
6400 Check_First_Subtype (Arg1);
6401 Set_Is_Asynchronous (Nm);
6402 if Expander_Active then
6403 RACW_Type_Is_Asynchronous (Nm);
6407 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6415 -- pragma Atomic (LOCAL_NAME);
6417 when Pragma_Atomic =>
6418 Process_Atomic_Shared_Volatile;
6420 -----------------------
6421 -- Atomic_Components --
6422 -----------------------
6424 -- pragma Atomic_Components (array_LOCAL_NAME);
6426 -- This processing is shared by Volatile_Components
6428 when Pragma_Atomic_Components |
6429 Pragma_Volatile_Components =>
6431 Atomic_Components : declare
6438 Check_Ada_83_Warning;
6439 Check_No_Identifiers;
6440 Check_Arg_Count (1);
6441 Check_Arg_Is_Local_Name (Arg1);
6442 E_Id := Get_Pragma_Arg (Arg1);
6444 if Etype (E_Id) = Any_Type then
6450 Check_Duplicate_Pragma (E);
6452 if Rep_Item_Too_Early (E, N)
6454 Rep_Item_Too_Late (E, N)
6459 D := Declaration_Node (E);
6462 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6464 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6465 and then Nkind (D) = N_Object_Declaration
6466 and then Nkind (Object_Definition (D)) =
6467 N_Constrained_Array_Definition)
6469 -- The flag is set on the object, or on the base type
6471 if Nkind (D) /= N_Object_Declaration then
6475 Set_Has_Volatile_Components (E);
6477 if Prag_Id = Pragma_Atomic_Components then
6478 Set_Has_Atomic_Components (E);
6482 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6484 end Atomic_Components;
6486 --------------------
6487 -- Attach_Handler --
6488 --------------------
6490 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6492 when Pragma_Attach_Handler =>
6493 Check_Ada_83_Warning;
6494 Check_No_Identifiers;
6495 Check_Arg_Count (2);
6497 if No_Run_Time_Mode then
6498 Error_Msg_CRT ("Attach_Handler pragma", N);
6500 Check_Interrupt_Or_Attach_Handler;
6502 -- The expression that designates the attribute may depend on a
6503 -- discriminant, and is therefore a per- object expression, to
6504 -- be expanded in the init proc. If expansion is enabled, then
6505 -- perform semantic checks on a copy only.
6507 if Expander_Active then
6509 Temp : constant Node_Id :=
6510 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6512 Set_Parent (Temp, N);
6513 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6517 Analyze (Get_Pragma_Arg (Arg2));
6518 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6521 Process_Interrupt_Or_Attach_Handler;
6524 --------------------
6525 -- C_Pass_By_Copy --
6526 --------------------
6528 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6530 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6536 Check_Valid_Configuration_Pragma;
6537 Check_Arg_Count (1);
6538 Check_Optional_Identifier (Arg1, "max_size");
6540 Arg := Get_Pragma_Arg (Arg1);
6541 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6543 Val := Expr_Value (Arg);
6547 ("maximum size for pragma% must be positive", Arg1);
6549 elsif UI_Is_In_Int_Range (Val) then
6550 Default_C_Record_Mechanism := UI_To_Int (Val);
6552 -- If a giant value is given, Int'Last will do well enough.
6553 -- If sometime someone complains that a record larger than
6554 -- two gigabytes is not copied, we will worry about it then!
6557 Default_C_Record_Mechanism := Mechanism_Type'Last;
6565 -- pragma Check ([Name =>] Identifier,
6566 -- [Check =>] Boolean_Expression
6567 -- [,[Message =>] String_Expression]);
6569 when Pragma_Check => Check : declare
6574 -- Set True if category of assertions referenced by Name enabled
6578 Check_At_Least_N_Arguments (2);
6579 Check_At_Most_N_Arguments (3);
6580 Check_Optional_Identifier (Arg1, Name_Name);
6581 Check_Optional_Identifier (Arg2, Name_Check);
6583 if Arg_Count = 3 then
6584 Check_Optional_Identifier (Arg3, Name_Message);
6585 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6588 Check_Arg_Is_Identifier (Arg1);
6590 -- Indicate if pragma is enabled. The Original_Node reference here
6591 -- is to deal with pragma Assert rewritten as a Check pragma.
6593 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6596 Set_Pragma_Enabled (N);
6597 Set_Pragma_Enabled (Original_Node (N));
6598 Set_SCO_Pragma_Enabled (Loc);
6601 -- If expansion is active and the check is not enabled then we
6602 -- rewrite the Check as:
6604 -- if False and then condition then
6608 -- The reason we do this rewriting during semantic analysis rather
6609 -- than as part of normal expansion is that we cannot analyze and
6610 -- expand the code for the boolean expression directly, or it may
6611 -- cause insertion of actions that would escape the attempt to
6612 -- suppress the check code.
6614 -- Note that the Sloc for the if statement corresponds to the
6615 -- argument condition, not the pragma itself. The reason for this
6616 -- is that we may generate a warning if the condition is False at
6617 -- compile time, and we do not want to delete this warning when we
6618 -- delete the if statement.
6620 Expr := Get_Pragma_Arg (Arg2);
6622 if Expander_Active and then not Check_On then
6623 Eloc := Sloc (Expr);
6626 Make_If_Statement (Eloc,
6628 Make_And_Then (Eloc,
6629 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6630 Right_Opnd => Expr),
6631 Then_Statements => New_List (
6632 Make_Null_Statement (Eloc))));
6639 Analyze_And_Resolve (Expr, Any_Boolean);
6647 -- pragma Check_Name (check_IDENTIFIER);
6649 when Pragma_Check_Name =>
6650 Check_No_Identifiers;
6652 Check_Valid_Configuration_Pragma;
6653 Check_Arg_Count (1);
6654 Check_Arg_Is_Identifier (Arg1);
6657 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6660 for J in Check_Names.First .. Check_Names.Last loop
6661 if Check_Names.Table (J) = Nam then
6666 Check_Names.Append (Nam);
6673 -- pragma Check_Policy (
6674 -- [Name =>] IDENTIFIER,
6675 -- [Policy =>] POLICY_IDENTIFIER);
6677 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6679 -- Note: this is a configuration pragma, but it is allowed to appear
6682 when Pragma_Check_Policy =>
6684 Check_Arg_Count (2);
6685 Check_Optional_Identifier (Arg1, Name_Name);
6686 Check_Optional_Identifier (Arg2, Name_Policy);
6688 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6690 -- A Check_Policy pragma can appear either as a configuration
6691 -- pragma, or in a declarative part or a package spec (see RM
6692 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6693 -- followed for Check_Policy).
6695 if not Is_Configuration_Pragma then
6696 Check_Is_In_Decl_Part_Or_Package_Spec;
6699 Set_Next_Pragma (N, Opt.Check_Policy_List);
6700 Opt.Check_Policy_List := N;
6702 ---------------------
6703 -- CIL_Constructor --
6704 ---------------------
6706 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6708 -- Processing for this pragma is shared with Java_Constructor
6714 -- pragma Comment (static_string_EXPRESSION)
6716 -- Processing for pragma Comment shares the circuitry for pragma
6717 -- Ident. The only differences are that Ident enforces a limit of 31
6718 -- characters on its argument, and also enforces limitations on
6719 -- placement for DEC compatibility. Pragma Comment shares neither of
6720 -- these restrictions.
6726 -- pragma Common_Object (
6727 -- [Internal =>] LOCAL_NAME
6728 -- [, [External =>] EXTERNAL_SYMBOL]
6729 -- [, [Size =>] EXTERNAL_SYMBOL]);
6731 -- Processing for this pragma is shared with Psect_Object
6733 ------------------------
6734 -- Compile_Time_Error --
6735 ------------------------
6737 -- pragma Compile_Time_Error
6738 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6740 when Pragma_Compile_Time_Error =>
6742 Process_Compile_Time_Warning_Or_Error;
6744 --------------------------
6745 -- Compile_Time_Warning --
6746 --------------------------
6748 -- pragma Compile_Time_Warning
6749 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6751 when Pragma_Compile_Time_Warning =>
6753 Process_Compile_Time_Warning_Or_Error;
6759 when Pragma_Compiler_Unit =>
6761 Check_Arg_Count (0);
6762 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6764 -----------------------------
6765 -- Complete_Representation --
6766 -----------------------------
6768 -- pragma Complete_Representation;
6770 when Pragma_Complete_Representation =>
6772 Check_Arg_Count (0);
6774 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6776 ("pragma & must appear within record representation clause");
6779 ----------------------------
6780 -- Complex_Representation --
6781 ----------------------------
6783 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6785 when Pragma_Complex_Representation => Complex_Representation : declare
6792 Check_Arg_Count (1);
6793 Check_Optional_Identifier (Arg1, Name_Entity);
6794 Check_Arg_Is_Local_Name (Arg1);
6795 E_Id := Get_Pragma_Arg (Arg1);
6797 if Etype (E_Id) = Any_Type then
6803 if not Is_Record_Type (E) then
6805 ("argument for pragma% must be record type", Arg1);
6808 Ent := First_Entity (E);
6811 or else No (Next_Entity (Ent))
6812 or else Present (Next_Entity (Next_Entity (Ent)))
6813 or else not Is_Floating_Point_Type (Etype (Ent))
6814 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6817 ("record for pragma% must have two fields of the same "
6818 & "floating-point type", Arg1);
6821 Set_Has_Complex_Representation (Base_Type (E));
6823 -- We need to treat the type has having a non-standard
6824 -- representation, for back-end purposes, even though in
6825 -- general a complex will have the default representation
6826 -- of a record with two real components.
6828 Set_Has_Non_Standard_Rep (Base_Type (E));
6830 end Complex_Representation;
6832 -------------------------
6833 -- Component_Alignment --
6834 -------------------------
6836 -- pragma Component_Alignment (
6837 -- [Form =>] ALIGNMENT_CHOICE
6838 -- [, [Name =>] type_LOCAL_NAME]);
6840 -- ALIGNMENT_CHOICE ::=
6842 -- | Component_Size_4
6846 when Pragma_Component_Alignment => Component_AlignmentP : declare
6847 Args : Args_List (1 .. 2);
6848 Names : constant Name_List (1 .. 2) := (
6852 Form : Node_Id renames Args (1);
6853 Name : Node_Id renames Args (2);
6855 Atype : Component_Alignment_Kind;
6860 Gather_Associations (Names, Args);
6863 Error_Pragma ("missing Form argument for pragma%");
6866 Check_Arg_Is_Identifier (Form);
6868 -- Get proper alignment, note that Default = Component_Size on all
6869 -- machines we have so far, and we want to set this value rather
6870 -- than the default value to indicate that it has been explicitly
6871 -- set (and thus will not get overridden by the default component
6872 -- alignment for the current scope)
6874 if Chars (Form) = Name_Component_Size then
6875 Atype := Calign_Component_Size;
6877 elsif Chars (Form) = Name_Component_Size_4 then
6878 Atype := Calign_Component_Size_4;
6880 elsif Chars (Form) = Name_Default then
6881 Atype := Calign_Component_Size;
6883 elsif Chars (Form) = Name_Storage_Unit then
6884 Atype := Calign_Storage_Unit;
6888 ("invalid Form parameter for pragma%", Form);
6891 -- Case with no name, supplied, affects scope table entry
6895 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6897 -- Case of name supplied
6900 Check_Arg_Is_Local_Name (Name);
6902 Typ := Entity (Name);
6905 or else Rep_Item_Too_Early (Typ, N)
6909 Typ := Underlying_Type (Typ);
6912 if not Is_Record_Type (Typ)
6913 and then not Is_Array_Type (Typ)
6916 ("Name parameter of pragma% must identify record or " &
6917 "array type", Name);
6920 -- An explicit Component_Alignment pragma overrides an
6921 -- implicit pragma Pack, but not an explicit one.
6923 if not Has_Pragma_Pack (Base_Type (Typ)) then
6924 Set_Is_Packed (Base_Type (Typ), False);
6925 Set_Component_Alignment (Base_Type (Typ), Atype);
6928 end Component_AlignmentP;
6934 -- pragma Controlled (first_subtype_LOCAL_NAME);
6936 when Pragma_Controlled => Controlled : declare
6940 Check_No_Identifiers;
6941 Check_Arg_Count (1);
6942 Check_Arg_Is_Local_Name (Arg1);
6943 Arg := Get_Pragma_Arg (Arg1);
6945 if not Is_Entity_Name (Arg)
6946 or else not Is_Access_Type (Entity (Arg))
6948 Error_Pragma_Arg ("pragma% requires access type", Arg1);
6950 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6958 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
6959 -- [Entity =>] LOCAL_NAME);
6961 when Pragma_Convention => Convention : declare
6964 pragma Warnings (Off, C);
6965 pragma Warnings (Off, E);
6967 Check_Arg_Order ((Name_Convention, Name_Entity));
6968 Check_Ada_83_Warning;
6969 Check_Arg_Count (2);
6970 Process_Convention (C, E);
6973 ---------------------------
6974 -- Convention_Identifier --
6975 ---------------------------
6977 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
6978 -- [Convention =>] convention_IDENTIFIER);
6980 when Pragma_Convention_Identifier => Convention_Identifier : declare
6986 Check_Arg_Order ((Name_Name, Name_Convention));
6987 Check_Arg_Count (2);
6988 Check_Optional_Identifier (Arg1, Name_Name);
6989 Check_Optional_Identifier (Arg2, Name_Convention);
6990 Check_Arg_Is_Identifier (Arg1);
6991 Check_Arg_Is_Identifier (Arg2);
6992 Idnam := Chars (Get_Pragma_Arg (Arg1));
6993 Cname := Chars (Get_Pragma_Arg (Arg2));
6995 if Is_Convention_Name (Cname) then
6996 Record_Convention_Identifier
6997 (Idnam, Get_Convention_Id (Cname));
7000 ("second arg for % pragma must be convention", Arg2);
7002 end Convention_Identifier;
7008 -- pragma CPP_Class ([Entity =>] local_NAME)
7010 when Pragma_CPP_Class => CPP_Class : declare
7015 if Warn_On_Obsolescent_Feature then
7017 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7018 " by pragma import?", N);
7022 Check_Arg_Count (1);
7023 Check_Optional_Identifier (Arg1, Name_Entity);
7024 Check_Arg_Is_Local_Name (Arg1);
7026 Arg := Get_Pragma_Arg (Arg1);
7029 if Etype (Arg) = Any_Type then
7033 if not Is_Entity_Name (Arg)
7034 or else not Is_Type (Entity (Arg))
7036 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7039 Typ := Entity (Arg);
7041 if not Is_Tagged_Type (Typ) then
7042 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7045 -- Types treated as CPP classes are treated as limited, but we
7046 -- don't require them to be declared this way. A warning is issued
7047 -- to encourage the user to declare them as limited. This is not
7048 -- an error, for compatibility reasons, because these types have
7049 -- been supported this way for some time.
7051 if not Is_Limited_Type (Typ) then
7053 ("imported 'C'P'P type should be " &
7054 "explicitly declared limited?",
7055 Get_Pragma_Arg (Arg1));
7057 ("\type will be considered limited",
7058 Get_Pragma_Arg (Arg1));
7061 Set_Is_CPP_Class (Typ);
7062 Set_Is_Limited_Record (Typ);
7063 Set_Convention (Typ, Convention_CPP);
7065 -- Imported CPP types must not have discriminants (because C++
7066 -- classes do not have discriminants).
7068 if Has_Discriminants (Typ) then
7070 ("imported 'C'P'P type cannot have discriminants",
7071 First (Discriminant_Specifications
7072 (Declaration_Node (Typ))));
7075 -- Components of imported CPP types must not have default
7076 -- expressions because the constructor (if any) is in the
7079 if Is_Incomplete_Or_Private_Type (Typ)
7080 and then No (Underlying_Type (Typ))
7082 -- It should be an error to apply pragma CPP to a private
7083 -- type if the underlying type is not visible (as it is
7084 -- for any representation item). For now, for backward
7085 -- compatibility we do nothing but we cannot check components
7086 -- because they are not available at this stage. All this code
7087 -- will be removed when we cleanup this obsolete GNAT pragma???
7093 Tdef : constant Node_Id :=
7094 Type_Definition (Declaration_Node (Typ));
7099 if Nkind (Tdef) = N_Record_Definition then
7100 Clist := Component_List (Tdef);
7102 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7103 Clist := Component_List (Record_Extension_Part (Tdef));
7106 if Present (Clist) then
7107 Comp := First (Component_Items (Clist));
7108 while Present (Comp) loop
7109 if Present (Expression (Comp)) then
7111 ("component of imported 'C'P'P type cannot have" &
7112 " default expression", Expression (Comp));
7122 ---------------------
7123 -- CPP_Constructor --
7124 ---------------------
7126 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7127 -- [, [External_Name =>] static_string_EXPRESSION ]
7128 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7130 when Pragma_CPP_Constructor => CPP_Constructor : declare
7134 Tag_Typ : Entity_Id;
7138 Check_At_Least_N_Arguments (1);
7139 Check_At_Most_N_Arguments (3);
7140 Check_Optional_Identifier (Arg1, Name_Entity);
7141 Check_Arg_Is_Local_Name (Arg1);
7143 Id := Get_Pragma_Arg (Arg1);
7144 Find_Program_Unit_Name (Id);
7146 -- If we did not find the name, we are done
7148 if Etype (Id) = Any_Type then
7152 Def_Id := Entity (Id);
7154 -- Check if already defined as constructor
7156 if Is_Constructor (Def_Id) then
7158 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7162 if Ekind (Def_Id) = E_Function
7163 and then (Is_CPP_Class (Etype (Def_Id))
7164 or else (Is_Class_Wide_Type (Etype (Def_Id))
7166 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7168 if Arg_Count >= 2 then
7169 Set_Imported (Def_Id);
7170 Set_Is_Public (Def_Id);
7171 Process_Interface_Name (Def_Id, Arg2, Arg3);
7174 Set_Has_Completion (Def_Id);
7175 Set_Is_Constructor (Def_Id);
7177 -- Imported C++ constructors are not dispatching primitives
7178 -- because in C++ they don't have a dispatch table slot.
7179 -- However, in Ada the constructor has the profile of a
7180 -- function that returns a tagged type and therefore it has
7181 -- been treated as a primitive operation during semantic
7182 -- analysis. We now remove it from the list of primitive
7183 -- operations of the type.
7185 if Is_Tagged_Type (Etype (Def_Id))
7186 and then not Is_Class_Wide_Type (Etype (Def_Id))
7188 pragma Assert (Is_Dispatching_Operation (Def_Id));
7189 Tag_Typ := Etype (Def_Id);
7191 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7192 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7196 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7197 Set_Is_Dispatching_Operation (Def_Id, False);
7200 -- For backward compatibility, if the constructor returns a
7201 -- class wide type, and we internally change the return type to
7202 -- the corresponding root type.
7204 if Is_Class_Wide_Type (Etype (Def_Id)) then
7205 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7209 ("pragma% requires function returning a 'C'P'P_Class type",
7212 end CPP_Constructor;
7218 when Pragma_CPP_Virtual => CPP_Virtual : declare
7222 if Warn_On_Obsolescent_Feature then
7224 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7233 when Pragma_CPP_Vtable => CPP_Vtable : declare
7237 if Warn_On_Obsolescent_Feature then
7239 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7248 -- pragma CPU (EXPRESSION);
7250 when Pragma_CPU => CPU : declare
7251 P : constant Node_Id := Parent (N);
7256 Check_No_Identifiers;
7257 Check_Arg_Count (1);
7261 if Nkind (P) = N_Subprogram_Body then
7262 Check_In_Main_Program;
7264 Arg := Get_Pragma_Arg (Arg1);
7265 Analyze_And_Resolve (Arg, Any_Integer);
7269 if not Is_Static_Expression (Arg) then
7270 Flag_Non_Static_Expr
7271 ("main subprogram affinity is not static!", Arg);
7274 -- If constraint error, then we already signalled an error
7276 elsif Raises_Constraint_Error (Arg) then
7279 -- Otherwise check in range
7283 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7284 -- This is the entity System.Multiprocessors.CPU_Range;
7286 Val : constant Uint := Expr_Value (Arg);
7289 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7291 Val > Expr_Value (Type_High_Bound (CPU_Id))
7294 ("main subprogram CPU is out of range", Arg1);
7300 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7304 elsif Nkind (P) = N_Task_Definition then
7305 Arg := Get_Pragma_Arg (Arg1);
7307 -- The expression must be analyzed in the special manner
7308 -- described in "Handling of Default and Per-Object
7309 -- Expressions" in sem.ads.
7311 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7313 -- Anything else is incorrect
7319 if Has_Pragma_CPU (P) then
7320 Error_Pragma ("duplicate pragma% not allowed");
7322 Set_Has_Pragma_CPU (P, True);
7324 if Nkind (P) = N_Task_Definition then
7325 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7334 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7336 when Pragma_Debug => Debug : declare
7344 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7347 if Arg_Count = 2 then
7350 Left_Opnd => Relocate_Node (Cond),
7351 Right_Opnd => Get_Pragma_Arg (Arg1));
7354 -- Rewrite into a conditional with an appropriate condition. We
7355 -- wrap the procedure call in a block so that overhead from e.g.
7356 -- use of the secondary stack does not generate execution overhead
7357 -- for suppressed conditions.
7359 Rewrite (N, Make_Implicit_If_Statement (N,
7361 Then_Statements => New_List (
7362 Make_Block_Statement (Loc,
7363 Handled_Statement_Sequence =>
7364 Make_Handled_Sequence_Of_Statements (Loc,
7365 Statements => New_List (
7366 Relocate_Node (Debug_Statement (N))))))));
7374 -- pragma Debug_Policy (Check | Ignore)
7376 when Pragma_Debug_Policy =>
7378 Check_Arg_Count (1);
7379 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7380 Debug_Pragmas_Enabled :=
7381 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7383 ---------------------
7384 -- Detect_Blocking --
7385 ---------------------
7387 -- pragma Detect_Blocking;
7389 when Pragma_Detect_Blocking =>
7391 Check_Arg_Count (0);
7392 Check_Valid_Configuration_Pragma;
7393 Detect_Blocking := True;
7395 --------------------------
7396 -- Default_Storage_Pool --
7397 --------------------------
7399 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7401 when Pragma_Default_Storage_Pool =>
7403 Check_Arg_Count (1);
7405 -- Default_Storage_Pool can appear as a configuration pragma, or
7406 -- in a declarative part or a package spec.
7408 if not Is_Configuration_Pragma then
7409 Check_Is_In_Decl_Part_Or_Package_Spec;
7412 -- Case of Default_Storage_Pool (null);
7414 if Nkind (Expression (Arg1)) = N_Null then
7415 Analyze (Expression (Arg1));
7417 -- This is an odd case, this is not really an expression, so
7418 -- we don't have a type for it. So just set the type to Empty.
7420 Set_Etype (Expression (Arg1), Empty);
7422 -- Case of Default_Storage_Pool (storage_pool_NAME);
7425 -- If it's a configuration pragma, then the only allowed
7426 -- argument is "null".
7428 if Is_Configuration_Pragma then
7429 Error_Pragma_Arg ("NULL expected", Arg1);
7432 -- The expected type for a non-"null" argument is
7433 -- Root_Storage_Pool'Class.
7436 (Get_Pragma_Arg (Arg1),
7437 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7440 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7441 -- for an access type will use this information to set the
7442 -- appropriate attributes of the access type.
7444 Default_Pool := Expression (Arg1);
7450 when Pragma_Dimension =>
7452 Check_Arg_Count (4);
7453 Check_No_Identifiers;
7454 Check_Arg_Is_Local_Name (Arg1);
7456 if not Is_Type (Arg1) then
7457 Error_Pragma ("first argument for pragma% must be subtype");
7460 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7461 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7462 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7468 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7470 when Pragma_Discard_Names => Discard_Names : declare
7475 Check_Ada_83_Warning;
7477 -- Deal with configuration pragma case
7479 if Arg_Count = 0 and then Is_Configuration_Pragma then
7480 Global_Discard_Names := True;
7483 -- Otherwise, check correct appropriate context
7486 Check_Is_In_Decl_Part_Or_Package_Spec;
7488 if Arg_Count = 0 then
7490 -- If there is no parameter, then from now on this pragma
7491 -- applies to any enumeration, exception or tagged type
7492 -- defined in the current declarative part, and recursively
7493 -- to any nested scope.
7495 Set_Discard_Names (Current_Scope);
7499 Check_Arg_Count (1);
7500 Check_Optional_Identifier (Arg1, Name_On);
7501 Check_Arg_Is_Local_Name (Arg1);
7503 E_Id := Get_Pragma_Arg (Arg1);
7505 if Etype (E_Id) = Any_Type then
7511 if (Is_First_Subtype (E)
7513 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7514 or else Ekind (E) = E_Exception
7516 Set_Discard_Names (E);
7519 ("inappropriate entity for pragma%", Arg1);
7530 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7532 when Pragma_Elaborate => Elaborate : declare
7537 -- Pragma must be in context items list of a compilation unit
7539 if not Is_In_Context_Clause then
7543 -- Must be at least one argument
7545 if Arg_Count = 0 then
7546 Error_Pragma ("pragma% requires at least one argument");
7549 -- In Ada 83 mode, there can be no items following it in the
7550 -- context list except other pragmas and implicit with clauses
7551 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7552 -- placement rule does not apply.
7554 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7556 while Present (Citem) loop
7557 if Nkind (Citem) = N_Pragma
7558 or else (Nkind (Citem) = N_With_Clause
7559 and then Implicit_With (Citem))
7564 ("(Ada 83) pragma% must be at end of context clause");
7571 -- Finally, the arguments must all be units mentioned in a with
7572 -- clause in the same context clause. Note we already checked (in
7573 -- Par.Prag) that the arguments are all identifiers or selected
7577 Outer : while Present (Arg) loop
7578 Citem := First (List_Containing (N));
7579 Inner : while Citem /= N loop
7580 if Nkind (Citem) = N_With_Clause
7581 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7583 Set_Elaborate_Present (Citem, True);
7584 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7585 Generate_Reference (Entity (Name (Citem)), Citem);
7587 -- With the pragma present, elaboration calls on
7588 -- subprograms from the named unit need no further
7589 -- checks, as long as the pragma appears in the current
7590 -- compilation unit. If the pragma appears in some unit
7591 -- in the context, there might still be a need for an
7592 -- Elaborate_All_Desirable from the current compilation
7593 -- to the named unit, so we keep the check enabled.
7595 if In_Extended_Main_Source_Unit (N) then
7596 Set_Suppress_Elaboration_Warnings
7597 (Entity (Name (Citem)));
7608 ("argument of pragma% is not with'ed unit", Arg);
7614 -- Give a warning if operating in static mode with -gnatwl
7615 -- (elaboration warnings enabled) switch set.
7617 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7619 ("?use of pragma Elaborate may not be safe", N);
7621 ("?use pragma Elaborate_All instead if possible", N);
7629 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7631 when Pragma_Elaborate_All => Elaborate_All : declare
7636 Check_Ada_83_Warning;
7638 -- Pragma must be in context items list of a compilation unit
7640 if not Is_In_Context_Clause then
7644 -- Must be at least one argument
7646 if Arg_Count = 0 then
7647 Error_Pragma ("pragma% requires at least one argument");
7650 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7651 -- have to appear at the end of the context clause, but may
7652 -- appear mixed in with other items, even in Ada 83 mode.
7654 -- Final check: the arguments must all be units mentioned in
7655 -- a with clause in the same context clause. Note that we
7656 -- already checked (in Par.Prag) that all the arguments are
7657 -- either identifiers or selected components.
7660 Outr : while Present (Arg) loop
7661 Citem := First (List_Containing (N));
7662 Innr : while Citem /= N loop
7663 if Nkind (Citem) = N_With_Clause
7664 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7666 Set_Elaborate_All_Present (Citem, True);
7667 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7669 -- Suppress warnings and elaboration checks on the named
7670 -- unit if the pragma is in the current compilation, as
7671 -- for pragma Elaborate.
7673 if In_Extended_Main_Source_Unit (N) then
7674 Set_Suppress_Elaboration_Warnings
7675 (Entity (Name (Citem)));
7684 Set_Error_Posted (N);
7686 ("argument of pragma% is not with'ed unit", Arg);
7693 --------------------
7694 -- Elaborate_Body --
7695 --------------------
7697 -- pragma Elaborate_Body [( library_unit_NAME )];
7699 when Pragma_Elaborate_Body => Elaborate_Body : declare
7700 Cunit_Node : Node_Id;
7701 Cunit_Ent : Entity_Id;
7704 Check_Ada_83_Warning;
7705 Check_Valid_Library_Unit_Pragma;
7707 if Nkind (N) = N_Null_Statement then
7711 Cunit_Node := Cunit (Current_Sem_Unit);
7712 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7714 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7717 Error_Pragma ("pragma% must refer to a spec, not a body");
7719 Set_Body_Required (Cunit_Node, True);
7720 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7722 -- If we are in dynamic elaboration mode, then we suppress
7723 -- elaboration warnings for the unit, since it is definitely
7724 -- fine NOT to do dynamic checks at the first level (and such
7725 -- checks will be suppressed because no elaboration boolean
7726 -- is created for Elaborate_Body packages).
7728 -- But in the static model of elaboration, Elaborate_Body is
7729 -- definitely NOT good enough to ensure elaboration safety on
7730 -- its own, since the body may WITH other units that are not
7731 -- safe from an elaboration point of view, so a client must
7732 -- still do an Elaborate_All on such units.
7734 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7735 -- Elaborate_Body always suppressed elab warnings.
7737 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7738 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7743 ------------------------
7744 -- Elaboration_Checks --
7745 ------------------------
7747 -- pragma Elaboration_Checks (Static | Dynamic);
7749 when Pragma_Elaboration_Checks =>
7751 Check_Arg_Count (1);
7752 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7753 Dynamic_Elaboration_Checks :=
7754 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7760 -- pragma Eliminate (
7761 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7762 -- [,[Entity =>] IDENTIFIER |
7763 -- SELECTED_COMPONENT |
7765 -- [, OVERLOADING_RESOLUTION]);
7767 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7770 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7773 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7775 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7776 -- Result_Type => result_SUBTYPE_NAME]
7778 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7779 -- SUBTYPE_NAME ::= STRING_LITERAL
7781 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7782 -- SOURCE_TRACE ::= STRING_LITERAL
7784 when Pragma_Eliminate => Eliminate : declare
7785 Args : Args_List (1 .. 5);
7786 Names : constant Name_List (1 .. 5) := (
7789 Name_Parameter_Types,
7791 Name_Source_Location);
7793 Unit_Name : Node_Id renames Args (1);
7794 Entity : Node_Id renames Args (2);
7795 Parameter_Types : Node_Id renames Args (3);
7796 Result_Type : Node_Id renames Args (4);
7797 Source_Location : Node_Id renames Args (5);
7801 Check_Valid_Configuration_Pragma;
7802 Gather_Associations (Names, Args);
7804 if No (Unit_Name) then
7805 Error_Pragma ("missing Unit_Name argument for pragma%");
7809 and then (Present (Parameter_Types)
7811 Present (Result_Type)
7813 Present (Source_Location))
7815 Error_Pragma ("missing Entity argument for pragma%");
7818 if (Present (Parameter_Types)
7820 Present (Result_Type))
7822 Present (Source_Location)
7825 ("parameter profile and source location cannot " &
7826 "be used together in pragma%");
7829 Process_Eliminate_Pragma
7843 -- [ Convention =>] convention_IDENTIFIER,
7844 -- [ Entity =>] local_NAME
7845 -- [, [External_Name =>] static_string_EXPRESSION ]
7846 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7848 when Pragma_Export => Export : declare
7852 pragma Warnings (Off, C);
7855 Check_Ada_83_Warning;
7861 Check_At_Least_N_Arguments (2);
7862 Check_At_Most_N_Arguments (4);
7863 Process_Convention (C, Def_Id);
7865 if Ekind (Def_Id) /= E_Constant then
7866 Note_Possible_Modification
7867 (Get_Pragma_Arg (Arg2), Sure => False);
7870 Process_Interface_Name (Def_Id, Arg3, Arg4);
7871 Set_Exported (Def_Id, Arg2);
7873 -- If the entity is a deferred constant, propagate the information
7874 -- to the full view, because gigi elaborates the full view only.
7876 if Ekind (Def_Id) = E_Constant
7877 and then Present (Full_View (Def_Id))
7880 Id2 : constant Entity_Id := Full_View (Def_Id);
7882 Set_Is_Exported (Id2, Is_Exported (Def_Id));
7883 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
7884 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7889 ----------------------
7890 -- Export_Exception --
7891 ----------------------
7893 -- pragma Export_Exception (
7894 -- [Internal =>] LOCAL_NAME
7895 -- [, [External =>] EXTERNAL_SYMBOL]
7896 -- [, [Form =>] Ada | VMS]
7897 -- [, [Code =>] static_integer_EXPRESSION]);
7899 when Pragma_Export_Exception => Export_Exception : declare
7900 Args : Args_List (1 .. 4);
7901 Names : constant Name_List (1 .. 4) := (
7907 Internal : Node_Id renames Args (1);
7908 External : Node_Id renames Args (2);
7909 Form : Node_Id renames Args (3);
7910 Code : Node_Id renames Args (4);
7915 if Inside_A_Generic then
7916 Error_Pragma ("pragma% cannot be used for generic entities");
7919 Gather_Associations (Names, Args);
7920 Process_Extended_Import_Export_Exception_Pragma (
7921 Arg_Internal => Internal,
7922 Arg_External => External,
7926 if not Is_VMS_Exception (Entity (Internal)) then
7927 Set_Exported (Entity (Internal), Internal);
7929 end Export_Exception;
7931 ---------------------
7932 -- Export_Function --
7933 ---------------------
7935 -- pragma Export_Function (
7936 -- [Internal =>] LOCAL_NAME
7937 -- [, [External =>] EXTERNAL_SYMBOL]
7938 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
7939 -- [, [Result_Type =>] TYPE_DESIGNATOR]
7940 -- [, [Mechanism =>] MECHANISM]
7941 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
7943 -- EXTERNAL_SYMBOL ::=
7945 -- | static_string_EXPRESSION
7947 -- PARAMETER_TYPES ::=
7949 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
7951 -- TYPE_DESIGNATOR ::=
7953 -- | subtype_Name ' Access
7957 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
7959 -- MECHANISM_ASSOCIATION ::=
7960 -- [formal_parameter_NAME =>] MECHANISM_NAME
7962 -- MECHANISM_NAME ::=
7965 -- | Descriptor [([Class =>] CLASS_NAME)]
7967 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
7969 when Pragma_Export_Function => Export_Function : declare
7970 Args : Args_List (1 .. 6);
7971 Names : constant Name_List (1 .. 6) := (
7974 Name_Parameter_Types,
7977 Name_Result_Mechanism);
7979 Internal : Node_Id renames Args (1);
7980 External : Node_Id renames Args (2);
7981 Parameter_Types : Node_Id renames Args (3);
7982 Result_Type : Node_Id renames Args (4);
7983 Mechanism : Node_Id renames Args (5);
7984 Result_Mechanism : Node_Id renames Args (6);
7988 Gather_Associations (Names, Args);
7989 Process_Extended_Import_Export_Subprogram_Pragma (
7990 Arg_Internal => Internal,
7991 Arg_External => External,
7992 Arg_Parameter_Types => Parameter_Types,
7993 Arg_Result_Type => Result_Type,
7994 Arg_Mechanism => Mechanism,
7995 Arg_Result_Mechanism => Result_Mechanism);
7996 end Export_Function;
8002 -- pragma Export_Object (
8003 -- [Internal =>] LOCAL_NAME
8004 -- [, [External =>] EXTERNAL_SYMBOL]
8005 -- [, [Size =>] EXTERNAL_SYMBOL]);
8007 -- EXTERNAL_SYMBOL ::=
8009 -- | static_string_EXPRESSION
8011 -- PARAMETER_TYPES ::=
8013 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8015 -- TYPE_DESIGNATOR ::=
8017 -- | subtype_Name ' Access
8021 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8023 -- MECHANISM_ASSOCIATION ::=
8024 -- [formal_parameter_NAME =>] MECHANISM_NAME
8026 -- MECHANISM_NAME ::=
8029 -- | Descriptor [([Class =>] CLASS_NAME)]
8031 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8033 when Pragma_Export_Object => Export_Object : declare
8034 Args : Args_List (1 .. 3);
8035 Names : constant Name_List (1 .. 3) := (
8040 Internal : Node_Id renames Args (1);
8041 External : Node_Id renames Args (2);
8042 Size : Node_Id renames Args (3);
8046 Gather_Associations (Names, Args);
8047 Process_Extended_Import_Export_Object_Pragma (
8048 Arg_Internal => Internal,
8049 Arg_External => External,
8053 ----------------------
8054 -- Export_Procedure --
8055 ----------------------
8057 -- pragma Export_Procedure (
8058 -- [Internal =>] LOCAL_NAME
8059 -- [, [External =>] EXTERNAL_SYMBOL]
8060 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8061 -- [, [Mechanism =>] MECHANISM]);
8063 -- EXTERNAL_SYMBOL ::=
8065 -- | static_string_EXPRESSION
8067 -- PARAMETER_TYPES ::=
8069 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8071 -- TYPE_DESIGNATOR ::=
8073 -- | subtype_Name ' Access
8077 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8079 -- MECHANISM_ASSOCIATION ::=
8080 -- [formal_parameter_NAME =>] MECHANISM_NAME
8082 -- MECHANISM_NAME ::=
8085 -- | Descriptor [([Class =>] CLASS_NAME)]
8087 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8089 when Pragma_Export_Procedure => Export_Procedure : declare
8090 Args : Args_List (1 .. 4);
8091 Names : constant Name_List (1 .. 4) := (
8094 Name_Parameter_Types,
8097 Internal : Node_Id renames Args (1);
8098 External : Node_Id renames Args (2);
8099 Parameter_Types : Node_Id renames Args (3);
8100 Mechanism : Node_Id renames Args (4);
8104 Gather_Associations (Names, Args);
8105 Process_Extended_Import_Export_Subprogram_Pragma (
8106 Arg_Internal => Internal,
8107 Arg_External => External,
8108 Arg_Parameter_Types => Parameter_Types,
8109 Arg_Mechanism => Mechanism);
8110 end Export_Procedure;
8116 -- pragma Export_Value (
8117 -- [Value =>] static_integer_EXPRESSION,
8118 -- [Link_Name =>] static_string_EXPRESSION);
8120 when Pragma_Export_Value =>
8122 Check_Arg_Order ((Name_Value, Name_Link_Name));
8123 Check_Arg_Count (2);
8125 Check_Optional_Identifier (Arg1, Name_Value);
8126 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8128 Check_Optional_Identifier (Arg2, Name_Link_Name);
8129 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8131 -----------------------------
8132 -- Export_Valued_Procedure --
8133 -----------------------------
8135 -- pragma Export_Valued_Procedure (
8136 -- [Internal =>] LOCAL_NAME
8137 -- [, [External =>] EXTERNAL_SYMBOL,]
8138 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8139 -- [, [Mechanism =>] MECHANISM]);
8141 -- EXTERNAL_SYMBOL ::=
8143 -- | static_string_EXPRESSION
8145 -- PARAMETER_TYPES ::=
8147 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8149 -- TYPE_DESIGNATOR ::=
8151 -- | subtype_Name ' Access
8155 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8157 -- MECHANISM_ASSOCIATION ::=
8158 -- [formal_parameter_NAME =>] MECHANISM_NAME
8160 -- MECHANISM_NAME ::=
8163 -- | Descriptor [([Class =>] CLASS_NAME)]
8165 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8167 when Pragma_Export_Valued_Procedure =>
8168 Export_Valued_Procedure : declare
8169 Args : Args_List (1 .. 4);
8170 Names : constant Name_List (1 .. 4) := (
8173 Name_Parameter_Types,
8176 Internal : Node_Id renames Args (1);
8177 External : Node_Id renames Args (2);
8178 Parameter_Types : Node_Id renames Args (3);
8179 Mechanism : Node_Id renames Args (4);
8183 Gather_Associations (Names, Args);
8184 Process_Extended_Import_Export_Subprogram_Pragma (
8185 Arg_Internal => Internal,
8186 Arg_External => External,
8187 Arg_Parameter_Types => Parameter_Types,
8188 Arg_Mechanism => Mechanism);
8189 end Export_Valued_Procedure;
8195 -- pragma Extend_System ([Name =>] Identifier);
8197 when Pragma_Extend_System => Extend_System : declare
8200 Check_Valid_Configuration_Pragma;
8201 Check_Arg_Count (1);
8202 Check_Optional_Identifier (Arg1, Name_Name);
8203 Check_Arg_Is_Identifier (Arg1);
8205 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8208 and then Name_Buffer (1 .. 4) = "aux_"
8210 if Present (System_Extend_Pragma_Arg) then
8211 if Chars (Get_Pragma_Arg (Arg1)) =
8212 Chars (Expression (System_Extend_Pragma_Arg))
8216 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8217 Error_Pragma ("pragma% conflicts with that #");
8221 System_Extend_Pragma_Arg := Arg1;
8223 if not GNAT_Mode then
8224 System_Extend_Unit := Arg1;
8228 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8232 ------------------------
8233 -- Extensions_Allowed --
8234 ------------------------
8236 -- pragma Extensions_Allowed (ON | OFF);
8238 when Pragma_Extensions_Allowed =>
8240 Check_Arg_Count (1);
8241 Check_No_Identifiers;
8242 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8244 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8245 Extensions_Allowed := True;
8246 Ada_Version := Ada_Version_Type'Last;
8249 Extensions_Allowed := False;
8250 Ada_Version := Ada_Version_Explicit;
8257 -- pragma External (
8258 -- [ Convention =>] convention_IDENTIFIER,
8259 -- [ Entity =>] local_NAME
8260 -- [, [External_Name =>] static_string_EXPRESSION ]
8261 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8263 when Pragma_External => External : declare
8267 pragma Warnings (Off, C);
8276 Check_At_Least_N_Arguments (2);
8277 Check_At_Most_N_Arguments (4);
8278 Process_Convention (C, Def_Id);
8279 Note_Possible_Modification
8280 (Get_Pragma_Arg (Arg2), Sure => False);
8281 Process_Interface_Name (Def_Id, Arg3, Arg4);
8282 Set_Exported (Def_Id, Arg2);
8285 --------------------------
8286 -- External_Name_Casing --
8287 --------------------------
8289 -- pragma External_Name_Casing (
8290 -- UPPERCASE | LOWERCASE
8291 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8293 when Pragma_External_Name_Casing => External_Name_Casing : declare
8296 Check_No_Identifiers;
8298 if Arg_Count = 2 then
8300 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8302 case Chars (Get_Pragma_Arg (Arg2)) is
8304 Opt.External_Name_Exp_Casing := As_Is;
8306 when Name_Uppercase =>
8307 Opt.External_Name_Exp_Casing := Uppercase;
8309 when Name_Lowercase =>
8310 Opt.External_Name_Exp_Casing := Lowercase;
8317 Check_Arg_Count (1);
8320 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8322 case Chars (Get_Pragma_Arg (Arg1)) is
8323 when Name_Uppercase =>
8324 Opt.External_Name_Imp_Casing := Uppercase;
8326 when Name_Lowercase =>
8327 Opt.External_Name_Imp_Casing := Lowercase;
8332 end External_Name_Casing;
8334 --------------------------
8335 -- Favor_Top_Level --
8336 --------------------------
8338 -- pragma Favor_Top_Level (type_NAME);
8340 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8341 Named_Entity : Entity_Id;
8345 Check_No_Identifiers;
8346 Check_Arg_Count (1);
8347 Check_Arg_Is_Local_Name (Arg1);
8348 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8350 -- If it's an access-to-subprogram type (in particular, not a
8351 -- subtype), set the flag on that type.
8353 if Is_Access_Subprogram_Type (Named_Entity) then
8354 Set_Can_Use_Internal_Rep (Named_Entity, False);
8356 -- Otherwise it's an error (name denotes the wrong sort of entity)
8360 ("access-to-subprogram type expected",
8361 Get_Pragma_Arg (Arg1));
8363 end Favor_Top_Level;
8369 -- pragma Fast_Math;
8371 when Pragma_Fast_Math =>
8373 Check_No_Identifiers;
8374 Check_Valid_Configuration_Pragma;
8377 ---------------------------
8378 -- Finalize_Storage_Only --
8379 ---------------------------
8381 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8383 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8384 Assoc : constant Node_Id := Arg1;
8385 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8390 Check_No_Identifiers;
8391 Check_Arg_Count (1);
8392 Check_Arg_Is_Local_Name (Arg1);
8394 Find_Type (Type_Id);
8395 Typ := Entity (Type_Id);
8398 or else Rep_Item_Too_Early (Typ, N)
8402 Typ := Underlying_Type (Typ);
8405 if not Is_Controlled (Typ) then
8406 Error_Pragma ("pragma% must specify controlled type");
8409 Check_First_Subtype (Arg1);
8411 if Finalize_Storage_Only (Typ) then
8412 Error_Pragma ("duplicate pragma%, only one allowed");
8414 elsif not Rep_Item_Too_Late (Typ, N) then
8415 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8417 end Finalize_Storage;
8419 --------------------------
8420 -- Float_Representation --
8421 --------------------------
8423 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8425 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8427 when Pragma_Float_Representation => Float_Representation : declare
8435 if Arg_Count = 1 then
8436 Check_Valid_Configuration_Pragma;
8438 Check_Arg_Count (2);
8439 Check_Optional_Identifier (Arg2, Name_Entity);
8440 Check_Arg_Is_Local_Name (Arg2);
8443 Check_No_Identifier (Arg1);
8444 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8446 if not OpenVMS_On_Target then
8447 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8449 ("?pragma% ignored (applies only to Open'V'M'S)");
8455 -- One argument case
8457 if Arg_Count = 1 then
8458 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8459 if Opt.Float_Format = 'I' then
8460 Error_Pragma ("'I'E'E'E format previously specified");
8463 Opt.Float_Format := 'V';
8466 if Opt.Float_Format = 'V' then
8467 Error_Pragma ("'V'A'X format previously specified");
8470 Opt.Float_Format := 'I';
8473 Set_Standard_Fpt_Formats;
8475 -- Two argument case
8478 Argx := Get_Pragma_Arg (Arg2);
8480 if not Is_Entity_Name (Argx)
8481 or else not Is_Floating_Point_Type (Entity (Argx))
8484 ("second argument of% pragma must be floating-point type",
8488 Ent := Entity (Argx);
8489 Digs := UI_To_Int (Digits_Value (Ent));
8491 -- Two arguments, VAX_Float case
8493 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8495 when 6 => Set_F_Float (Ent);
8496 when 9 => Set_D_Float (Ent);
8497 when 15 => Set_G_Float (Ent);
8501 ("wrong digits value, must be 6,9 or 15", Arg2);
8504 -- Two arguments, IEEE_Float case
8508 when 6 => Set_IEEE_Short (Ent);
8509 when 15 => Set_IEEE_Long (Ent);
8513 ("wrong digits value, must be 6 or 15", Arg2);
8517 end Float_Representation;
8523 -- pragma Ident (static_string_EXPRESSION)
8525 -- Note: pragma Comment shares this processing. Pragma Comment is
8526 -- identical to Ident, except that the restriction of the argument to
8527 -- 31 characters and the placement restrictions are not enforced for
8530 when Pragma_Ident | Pragma_Comment => Ident : declare
8535 Check_Arg_Count (1);
8536 Check_No_Identifiers;
8537 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8540 -- For pragma Ident, preserve DEC compatibility by requiring the
8541 -- pragma to appear in a declarative part or package spec.
8543 if Prag_Id = Pragma_Ident then
8544 Check_Is_In_Decl_Part_Or_Package_Spec;
8547 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8554 GP := Parent (Parent (N));
8556 if Nkind_In (GP, N_Package_Declaration,
8557 N_Generic_Package_Declaration)
8562 -- If we have a compilation unit, then record the ident value,
8563 -- checking for improper duplication.
8565 if Nkind (GP) = N_Compilation_Unit then
8566 CS := Ident_String (Current_Sem_Unit);
8568 if Present (CS) then
8570 -- For Ident, we do not permit multiple instances
8572 if Prag_Id = Pragma_Ident then
8573 Error_Pragma ("duplicate% pragma not permitted");
8575 -- For Comment, we concatenate the string, unless we want
8576 -- to preserve the tree structure for ASIS.
8578 elsif not ASIS_Mode then
8579 Start_String (Strval (CS));
8580 Store_String_Char (' ');
8581 Store_String_Chars (Strval (Str));
8582 Set_Strval (CS, End_String);
8586 -- In VMS, the effect of IDENT is achieved by passing
8587 -- --identification=name as a --for-linker switch.
8589 if OpenVMS_On_Target then
8592 ("--for-linker=--identification=");
8593 String_To_Name_Buffer (Strval (Str));
8594 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8596 -- Only the last processed IDENT is saved. The main
8597 -- purpose is so an IDENT associated with a main
8598 -- procedure will be used in preference to an IDENT
8599 -- associated with a with'd package.
8601 Replace_Linker_Option_String
8602 (End_String, "--for-linker=--identification=");
8605 Set_Ident_String (Current_Sem_Unit, Str);
8608 -- For subunits, we just ignore the Ident, since in GNAT these
8609 -- are not separate object files, and hence not separate units
8610 -- in the unit table.
8612 elsif Nkind (GP) = N_Subunit then
8615 -- Otherwise we have a misplaced pragma Ident, but we ignore
8616 -- this if we are in an instantiation, since it comes from
8617 -- a generic, and has no relevance to the instantiation.
8619 elsif Prag_Id = Pragma_Ident then
8620 if Instantiation_Location (Loc) = No_Location then
8621 Error_Pragma ("pragma% only allowed at outer level");
8631 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8632 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8634 when Pragma_Implemented => Implemented : declare
8635 Proc_Id : Entity_Id;
8640 Check_Arg_Count (2);
8641 Check_No_Identifiers;
8642 Check_Arg_Is_Identifier (Arg1);
8643 Check_Arg_Is_Local_Name (Arg1);
8645 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8647 -- Extract the name of the local procedure
8649 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8651 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8652 -- primitive procedure of a synchronized tagged type.
8654 if Ekind (Proc_Id) = E_Procedure
8655 and then Is_Primitive (Proc_Id)
8656 and then Present (First_Formal (Proc_Id))
8658 Typ := Etype (First_Formal (Proc_Id));
8660 if Is_Tagged_Type (Typ)
8663 -- Check for a protected, a synchronized or a task interface
8665 ((Is_Interface (Typ)
8666 and then Is_Synchronized_Interface (Typ))
8668 -- Check for a protected type or a task type that implements
8672 (Is_Concurrent_Record_Type (Typ)
8673 and then Present (Interfaces (Typ)))
8675 -- Check for a private record extension with keyword
8679 (Ekind_In (Typ, E_Record_Type_With_Private,
8680 E_Record_Subtype_With_Private)
8681 and then Synchronized_Present (Parent (Typ))))
8686 ("controlling formal must be of synchronized " &
8687 "tagged type", Arg1);
8691 -- Procedures declared inside a protected type must be accepted
8693 elsif Ekind (Proc_Id) = E_Procedure
8694 and then Is_Protected_Type (Scope (Proc_Id))
8698 -- The first argument is not a primitive procedure
8702 ("pragma % must be applied to a primitive procedure", Arg1);
8706 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8707 -- By_Protected_Procedure to the primitive procedure of a task
8710 if Chars (Arg2) = Name_By_Protected_Procedure
8711 and then Is_Interface (Typ)
8712 and then Is_Task_Interface (Typ)
8715 ("implementation kind By_Protected_Procedure cannot be " &
8716 "applied to a task interface primitive", Arg2);
8720 Record_Rep_Item (Proc_Id, N);
8723 ----------------------
8724 -- Implicit_Packing --
8725 ----------------------
8727 -- pragma Implicit_Packing;
8729 when Pragma_Implicit_Packing =>
8731 Check_Arg_Count (0);
8732 Implicit_Packing := True;
8739 -- [Convention =>] convention_IDENTIFIER,
8740 -- [Entity =>] local_NAME
8741 -- [, [External_Name =>] static_string_EXPRESSION ]
8742 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8744 when Pragma_Import =>
8745 Check_Ada_83_Warning;
8751 Check_At_Least_N_Arguments (2);
8752 Check_At_Most_N_Arguments (4);
8753 Process_Import_Or_Interface;
8755 ----------------------
8756 -- Import_Exception --
8757 ----------------------
8759 -- pragma Import_Exception (
8760 -- [Internal =>] LOCAL_NAME
8761 -- [, [External =>] EXTERNAL_SYMBOL]
8762 -- [, [Form =>] Ada | VMS]
8763 -- [, [Code =>] static_integer_EXPRESSION]);
8765 when Pragma_Import_Exception => Import_Exception : declare
8766 Args : Args_List (1 .. 4);
8767 Names : constant Name_List (1 .. 4) := (
8773 Internal : Node_Id renames Args (1);
8774 External : Node_Id renames Args (2);
8775 Form : Node_Id renames Args (3);
8776 Code : Node_Id renames Args (4);
8780 Gather_Associations (Names, Args);
8782 if Present (External) and then Present (Code) then
8784 ("cannot give both External and Code options for pragma%");
8787 Process_Extended_Import_Export_Exception_Pragma (
8788 Arg_Internal => Internal,
8789 Arg_External => External,
8793 if not Is_VMS_Exception (Entity (Internal)) then
8794 Set_Imported (Entity (Internal));
8796 end Import_Exception;
8798 ---------------------
8799 -- Import_Function --
8800 ---------------------
8802 -- pragma Import_Function (
8803 -- [Internal =>] LOCAL_NAME,
8804 -- [, [External =>] EXTERNAL_SYMBOL]
8805 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8806 -- [, [Result_Type =>] SUBTYPE_MARK]
8807 -- [, [Mechanism =>] MECHANISM]
8808 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8809 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8811 -- EXTERNAL_SYMBOL ::=
8813 -- | static_string_EXPRESSION
8815 -- PARAMETER_TYPES ::=
8817 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8819 -- TYPE_DESIGNATOR ::=
8821 -- | subtype_Name ' Access
8825 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8827 -- MECHANISM_ASSOCIATION ::=
8828 -- [formal_parameter_NAME =>] MECHANISM_NAME
8830 -- MECHANISM_NAME ::=
8833 -- | Descriptor [([Class =>] CLASS_NAME)]
8835 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8837 when Pragma_Import_Function => Import_Function : declare
8838 Args : Args_List (1 .. 7);
8839 Names : constant Name_List (1 .. 7) := (
8842 Name_Parameter_Types,
8845 Name_Result_Mechanism,
8846 Name_First_Optional_Parameter);
8848 Internal : Node_Id renames Args (1);
8849 External : Node_Id renames Args (2);
8850 Parameter_Types : Node_Id renames Args (3);
8851 Result_Type : Node_Id renames Args (4);
8852 Mechanism : Node_Id renames Args (5);
8853 Result_Mechanism : Node_Id renames Args (6);
8854 First_Optional_Parameter : Node_Id renames Args (7);
8858 Gather_Associations (Names, Args);
8859 Process_Extended_Import_Export_Subprogram_Pragma (
8860 Arg_Internal => Internal,
8861 Arg_External => External,
8862 Arg_Parameter_Types => Parameter_Types,
8863 Arg_Result_Type => Result_Type,
8864 Arg_Mechanism => Mechanism,
8865 Arg_Result_Mechanism => Result_Mechanism,
8866 Arg_First_Optional_Parameter => First_Optional_Parameter);
8867 end Import_Function;
8873 -- pragma Import_Object (
8874 -- [Internal =>] LOCAL_NAME
8875 -- [, [External =>] EXTERNAL_SYMBOL]
8876 -- [, [Size =>] EXTERNAL_SYMBOL]);
8878 -- EXTERNAL_SYMBOL ::=
8880 -- | static_string_EXPRESSION
8882 when Pragma_Import_Object => Import_Object : declare
8883 Args : Args_List (1 .. 3);
8884 Names : constant Name_List (1 .. 3) := (
8889 Internal : Node_Id renames Args (1);
8890 External : Node_Id renames Args (2);
8891 Size : Node_Id renames Args (3);
8895 Gather_Associations (Names, Args);
8896 Process_Extended_Import_Export_Object_Pragma (
8897 Arg_Internal => Internal,
8898 Arg_External => External,
8902 ----------------------
8903 -- Import_Procedure --
8904 ----------------------
8906 -- pragma Import_Procedure (
8907 -- [Internal =>] LOCAL_NAME
8908 -- [, [External =>] EXTERNAL_SYMBOL]
8909 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8910 -- [, [Mechanism =>] MECHANISM]
8911 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8913 -- EXTERNAL_SYMBOL ::=
8915 -- | static_string_EXPRESSION
8917 -- PARAMETER_TYPES ::=
8919 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8921 -- TYPE_DESIGNATOR ::=
8923 -- | subtype_Name ' Access
8927 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8929 -- MECHANISM_ASSOCIATION ::=
8930 -- [formal_parameter_NAME =>] MECHANISM_NAME
8932 -- MECHANISM_NAME ::=
8935 -- | Descriptor [([Class =>] CLASS_NAME)]
8937 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8939 when Pragma_Import_Procedure => Import_Procedure : declare
8940 Args : Args_List (1 .. 5);
8941 Names : constant Name_List (1 .. 5) := (
8944 Name_Parameter_Types,
8946 Name_First_Optional_Parameter);
8948 Internal : Node_Id renames Args (1);
8949 External : Node_Id renames Args (2);
8950 Parameter_Types : Node_Id renames Args (3);
8951 Mechanism : Node_Id renames Args (4);
8952 First_Optional_Parameter : Node_Id renames Args (5);
8956 Gather_Associations (Names, Args);
8957 Process_Extended_Import_Export_Subprogram_Pragma (
8958 Arg_Internal => Internal,
8959 Arg_External => External,
8960 Arg_Parameter_Types => Parameter_Types,
8961 Arg_Mechanism => Mechanism,
8962 Arg_First_Optional_Parameter => First_Optional_Parameter);
8963 end Import_Procedure;
8965 -----------------------------
8966 -- Import_Valued_Procedure --
8967 -----------------------------
8969 -- pragma Import_Valued_Procedure (
8970 -- [Internal =>] LOCAL_NAME
8971 -- [, [External =>] EXTERNAL_SYMBOL]
8972 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8973 -- [, [Mechanism =>] MECHANISM]
8974 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8976 -- EXTERNAL_SYMBOL ::=
8978 -- | static_string_EXPRESSION
8980 -- PARAMETER_TYPES ::=
8982 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8984 -- TYPE_DESIGNATOR ::=
8986 -- | subtype_Name ' Access
8990 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8992 -- MECHANISM_ASSOCIATION ::=
8993 -- [formal_parameter_NAME =>] MECHANISM_NAME
8995 -- MECHANISM_NAME ::=
8998 -- | Descriptor [([Class =>] CLASS_NAME)]
9000 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9002 when Pragma_Import_Valued_Procedure =>
9003 Import_Valued_Procedure : declare
9004 Args : Args_List (1 .. 5);
9005 Names : constant Name_List (1 .. 5) := (
9008 Name_Parameter_Types,
9010 Name_First_Optional_Parameter);
9012 Internal : Node_Id renames Args (1);
9013 External : Node_Id renames Args (2);
9014 Parameter_Types : Node_Id renames Args (3);
9015 Mechanism : Node_Id renames Args (4);
9016 First_Optional_Parameter : Node_Id renames Args (5);
9020 Gather_Associations (Names, Args);
9021 Process_Extended_Import_Export_Subprogram_Pragma (
9022 Arg_Internal => Internal,
9023 Arg_External => External,
9024 Arg_Parameter_Types => Parameter_Types,
9025 Arg_Mechanism => Mechanism,
9026 Arg_First_Optional_Parameter => First_Optional_Parameter);
9027 end Import_Valued_Procedure;
9033 -- pragma Independent (LOCAL_NAME);
9035 when Pragma_Independent => Independent : declare
9042 Check_Ada_83_Warning;
9044 Check_No_Identifiers;
9045 Check_Arg_Count (1);
9046 Check_Arg_Is_Local_Name (Arg1);
9047 E_Id := Get_Pragma_Arg (Arg1);
9049 if Etype (E_Id) = Any_Type then
9054 D := Declaration_Node (E);
9057 -- Check duplicate before we chain ourselves!
9059 Check_Duplicate_Pragma (E);
9061 -- Check appropriate entity
9064 if Rep_Item_Too_Early (E, N)
9066 Rep_Item_Too_Late (E, N)
9070 Check_First_Subtype (Arg1);
9073 elsif K = N_Object_Declaration
9074 or else (K = N_Component_Declaration
9075 and then Original_Record_Component (E) = E)
9077 if Rep_Item_Too_Late (E, N) then
9083 ("inappropriate entity for pragma%", Arg1);
9086 Independence_Checks.Append ((N, E));
9089 ----------------------------
9090 -- Independent_Components --
9091 ----------------------------
9093 -- pragma Atomic_Components (array_LOCAL_NAME);
9095 -- This processing is shared by Volatile_Components
9097 when Pragma_Independent_Components => Independent_Components : declare
9104 Check_Ada_83_Warning;
9106 Check_No_Identifiers;
9107 Check_Arg_Count (1);
9108 Check_Arg_Is_Local_Name (Arg1);
9109 E_Id := Get_Pragma_Arg (Arg1);
9111 if Etype (E_Id) = Any_Type then
9117 -- Check duplicate before we chain ourselves!
9119 Check_Duplicate_Pragma (E);
9121 -- Check appropriate entity
9123 if Rep_Item_Too_Early (E, N)
9125 Rep_Item_Too_Late (E, N)
9130 D := Declaration_Node (E);
9133 if (K = N_Full_Type_Declaration
9134 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9136 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9137 and then Nkind (D) = N_Object_Declaration
9138 and then Nkind (Object_Definition (D)) =
9139 N_Constrained_Array_Definition)
9141 Independence_Checks.Append ((N, E));
9144 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9146 end Independent_Components;
9148 ------------------------
9149 -- Initialize_Scalars --
9150 ------------------------
9152 -- pragma Initialize_Scalars;
9154 when Pragma_Initialize_Scalars =>
9156 Check_Arg_Count (0);
9157 Check_Valid_Configuration_Pragma;
9158 Check_Restriction (No_Initialize_Scalars, N);
9160 -- Initialize_Scalars creates false positives in CodePeer,
9161 -- so ignore this pragma in this mode.
9163 if not Restriction_Active (No_Initialize_Scalars)
9164 and then not CodePeer_Mode
9166 Init_Or_Norm_Scalars := True;
9167 Initialize_Scalars := True;
9174 -- pragma Inline ( NAME {, NAME} );
9176 when Pragma_Inline =>
9178 -- Pragma is active if inlining option is active
9180 Process_Inline (Inline_Active);
9186 -- pragma Inline_Always ( NAME {, NAME} );
9188 when Pragma_Inline_Always =>
9191 -- Pragma always active unless in CodePeer mode, since this causes
9192 -- walk order issues.
9194 if not CodePeer_Mode then
9195 Process_Inline (True);
9198 --------------------
9199 -- Inline_Generic --
9200 --------------------
9202 -- pragma Inline_Generic (NAME {, NAME});
9204 when Pragma_Inline_Generic =>
9206 Process_Generic_List;
9208 ----------------------
9209 -- Inspection_Point --
9210 ----------------------
9212 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9214 when Pragma_Inspection_Point => Inspection_Point : declare
9219 if Arg_Count > 0 then
9222 Exp := Get_Pragma_Arg (Arg);
9225 if not Is_Entity_Name (Exp)
9226 or else not Is_Object (Entity (Exp))
9228 Error_Pragma_Arg ("object name required", Arg);
9235 end Inspection_Point;
9241 -- pragma Interface (
9242 -- [ Convention =>] convention_IDENTIFIER,
9243 -- [ Entity =>] local_NAME
9244 -- [, [External_Name =>] static_string_EXPRESSION ]
9245 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9247 when Pragma_Interface =>
9254 Check_At_Least_N_Arguments (2);
9255 Check_At_Most_N_Arguments (4);
9256 Process_Import_Or_Interface;
9258 -- In Ada 2005, the permission to use Interface (a reserved word)
9259 -- as a pragma name is considered an obsolescent feature.
9261 if Ada_Version >= Ada_2005 then
9263 (No_Obsolescent_Features, Pragma_Identifier (N));
9266 --------------------
9267 -- Interface_Name --
9268 --------------------
9270 -- pragma Interface_Name (
9271 -- [ Entity =>] local_NAME
9272 -- [,[External_Name =>] static_string_EXPRESSION ]
9273 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9275 when Pragma_Interface_Name => Interface_Name : declare
9284 ((Name_Entity, Name_External_Name, Name_Link_Name));
9285 Check_At_Least_N_Arguments (2);
9286 Check_At_Most_N_Arguments (3);
9287 Id := Get_Pragma_Arg (Arg1);
9290 if not Is_Entity_Name (Id) then
9292 ("first argument for pragma% must be entity name", Arg1);
9293 elsif Etype (Id) = Any_Type then
9296 Def_Id := Entity (Id);
9299 -- Special DEC-compatible processing for the object case, forces
9300 -- object to be imported.
9302 if Ekind (Def_Id) = E_Variable then
9303 Kill_Size_Check_Code (Def_Id);
9304 Note_Possible_Modification (Id, Sure => False);
9306 -- Initialization is not allowed for imported variable
9308 if Present (Expression (Parent (Def_Id)))
9309 and then Comes_From_Source (Expression (Parent (Def_Id)))
9311 Error_Msg_Sloc := Sloc (Def_Id);
9313 ("no initialization allowed for declaration of& #",
9317 -- For compatibility, support VADS usage of providing both
9318 -- pragmas Interface and Interface_Name to obtain the effect
9319 -- of a single Import pragma.
9321 if Is_Imported (Def_Id)
9322 and then Present (First_Rep_Item (Def_Id))
9323 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9325 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9329 Set_Imported (Def_Id);
9332 Set_Is_Public (Def_Id);
9333 Process_Interface_Name (Def_Id, Arg2, Arg3);
9336 -- Otherwise must be subprogram
9338 elsif not Is_Subprogram (Def_Id) then
9340 ("argument of pragma% is not subprogram", Arg1);
9343 Check_At_Most_N_Arguments (3);
9347 -- Loop through homonyms
9350 Def_Id := Get_Base_Subprogram (Hom_Id);
9352 if Is_Imported (Def_Id) then
9353 Process_Interface_Name (Def_Id, Arg2, Arg3);
9357 exit when From_Aspect_Specification (N);
9358 Hom_Id := Homonym (Hom_Id);
9360 exit when No (Hom_Id)
9361 or else Scope (Hom_Id) /= Current_Scope;
9366 ("argument of pragma% is not imported subprogram",
9372 -----------------------
9373 -- Interrupt_Handler --
9374 -----------------------
9376 -- pragma Interrupt_Handler (handler_NAME);
9378 when Pragma_Interrupt_Handler =>
9379 Check_Ada_83_Warning;
9380 Check_Arg_Count (1);
9381 Check_No_Identifiers;
9383 if No_Run_Time_Mode then
9384 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9386 Check_Interrupt_Or_Attach_Handler;
9387 Process_Interrupt_Or_Attach_Handler;
9390 ------------------------
9391 -- Interrupt_Priority --
9392 ------------------------
9394 -- pragma Interrupt_Priority [(EXPRESSION)];
9396 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9397 P : constant Node_Id := Parent (N);
9401 Check_Ada_83_Warning;
9403 if Arg_Count /= 0 then
9404 Arg := Get_Pragma_Arg (Arg1);
9405 Check_Arg_Count (1);
9406 Check_No_Identifiers;
9408 -- The expression must be analyzed in the special manner
9409 -- described in "Handling of Default and Per-Object
9410 -- Expressions" in sem.ads.
9412 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9415 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9419 elsif Has_Pragma_Priority (P) then
9420 Error_Pragma ("duplicate pragma% not allowed");
9423 Set_Has_Pragma_Priority (P, True);
9424 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9426 end Interrupt_Priority;
9428 ---------------------
9429 -- Interrupt_State --
9430 ---------------------
9432 -- pragma Interrupt_State (
9433 -- [Name =>] INTERRUPT_ID,
9434 -- [State =>] INTERRUPT_STATE);
9436 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9437 -- INTERRUPT_STATE => System | Runtime | User
9439 -- Note: if the interrupt id is given as an identifier, then it must
9440 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9441 -- given as a static integer expression which must be in the range of
9442 -- Ada.Interrupts.Interrupt_ID.
9444 when Pragma_Interrupt_State => Interrupt_State : declare
9446 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9447 -- This is the entity Ada.Interrupts.Interrupt_ID;
9449 State_Type : Character;
9450 -- Set to 's'/'r'/'u' for System/Runtime/User
9453 -- Index to entry in Interrupt_States table
9456 -- Value of interrupt
9458 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9459 -- The first argument to the pragma
9461 Int_Ent : Entity_Id;
9462 -- Interrupt entity in Ada.Interrupts.Names
9466 Check_Arg_Order ((Name_Name, Name_State));
9467 Check_Arg_Count (2);
9469 Check_Optional_Identifier (Arg1, Name_Name);
9470 Check_Optional_Identifier (Arg2, Name_State);
9471 Check_Arg_Is_Identifier (Arg2);
9473 -- First argument is identifier
9475 if Nkind (Arg1X) = N_Identifier then
9477 -- Search list of names in Ada.Interrupts.Names
9479 Int_Ent := First_Entity (RTE (RE_Names));
9481 if No (Int_Ent) then
9482 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9484 elsif Chars (Int_Ent) = Chars (Arg1X) then
9485 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9489 Next_Entity (Int_Ent);
9492 -- First argument is not an identifier, so it must be a static
9493 -- expression of type Ada.Interrupts.Interrupt_ID.
9496 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9497 Int_Val := Expr_Value (Arg1X);
9499 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9501 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9504 ("value not in range of type " &
9505 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9511 case Chars (Get_Pragma_Arg (Arg2)) is
9512 when Name_Runtime => State_Type := 'r';
9513 when Name_System => State_Type := 's';
9514 when Name_User => State_Type := 'u';
9517 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9520 -- Check if entry is already stored
9522 IST_Num := Interrupt_States.First;
9524 -- If entry not found, add it
9526 if IST_Num > Interrupt_States.Last then
9527 Interrupt_States.Append
9528 ((Interrupt_Number => UI_To_Int (Int_Val),
9529 Interrupt_State => State_Type,
9530 Pragma_Loc => Loc));
9533 -- Case of entry for the same entry
9535 elsif Int_Val = Interrupt_States.Table (IST_Num).
9538 -- If state matches, done, no need to make redundant entry
9541 State_Type = Interrupt_States.Table (IST_Num).
9544 -- Otherwise if state does not match, error
9547 Interrupt_States.Table (IST_Num).Pragma_Loc;
9549 ("state conflicts with that given #", Arg2);
9553 IST_Num := IST_Num + 1;
9555 end Interrupt_State;
9562 -- ([Entity =>] type_LOCAL_NAME,
9563 -- [Check =>] EXPRESSION
9564 -- [,[Message =>] String_Expression]);
9566 when Pragma_Invariant => Invariant : declare
9571 pragma Unreferenced (Discard);
9575 Check_At_Least_N_Arguments (2);
9576 Check_At_Most_N_Arguments (3);
9577 Check_Optional_Identifier (Arg1, Name_Entity);
9578 Check_Optional_Identifier (Arg2, Name_Check);
9580 if Arg_Count = 3 then
9581 Check_Optional_Identifier (Arg3, Name_Message);
9582 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9585 Check_Arg_Is_Local_Name (Arg1);
9587 Type_Id := Get_Pragma_Arg (Arg1);
9588 Find_Type (Type_Id);
9589 Typ := Entity (Type_Id);
9591 if Typ = Any_Type then
9594 elsif not Ekind_In (Typ, E_Private_Type,
9595 E_Record_Type_With_Private,
9596 E_Limited_Private_Type)
9599 ("pragma% only allowed for private type", Arg1);
9602 -- Note that the type has at least one invariant, and also that
9603 -- it has inheritable invariants if we have Invariant'Class.
9605 Set_Has_Invariants (Typ);
9607 if Class_Present (N) then
9608 Set_Has_Inheritable_Invariants (Typ);
9611 -- The remaining processing is simply to link the pragma on to
9612 -- the rep item chain, for processing when the type is frozen.
9613 -- This is accomplished by a call to Rep_Item_Too_Late.
9615 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9618 ----------------------
9619 -- Java_Constructor --
9620 ----------------------
9622 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9624 -- Also handles pragma CIL_Constructor
9626 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9627 Java_Constructor : declare
9628 Convention : Convention_Id;
9632 This_Formal : Entity_Id;
9636 Check_Arg_Count (1);
9637 Check_Optional_Identifier (Arg1, Name_Entity);
9638 Check_Arg_Is_Local_Name (Arg1);
9640 Id := Get_Pragma_Arg (Arg1);
9641 Find_Program_Unit_Name (Id);
9643 -- If we did not find the name, we are done
9645 if Etype (Id) = Any_Type then
9649 -- Check wrong use of pragma in wrong VM target
9651 if VM_Target = No_VM then
9654 elsif VM_Target = CLI_Target
9655 and then Prag_Id = Pragma_Java_Constructor
9657 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9659 elsif VM_Target = JVM_Target
9660 and then Prag_Id = Pragma_CIL_Constructor
9662 Error_Pragma ("must use pragma 'Java_'Constructor");
9666 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9667 when Pragma_Java_Constructor => Convention := Convention_Java;
9668 when others => null;
9671 Hom_Id := Entity (Id);
9673 -- Loop through homonyms
9676 Def_Id := Get_Base_Subprogram (Hom_Id);
9678 -- The constructor is required to be a function
9680 if Ekind (Def_Id) /= E_Function then
9681 if VM_Target = JVM_Target then
9683 ("pragma% requires function returning a " &
9684 "'Java access type", Def_Id);
9687 ("pragma% requires function returning a " &
9688 "'C'I'L access type", Def_Id);
9692 -- Check arguments: For tagged type the first formal must be
9693 -- named "this" and its type must be a named access type
9694 -- designating a class-wide tagged type that has convention
9695 -- CIL/Java. The first formal must also have a null default
9696 -- value. For example:
9698 -- type Typ is tagged ...
9699 -- type Ref is access all Typ;
9700 -- pragma Convention (CIL, Typ);
9702 -- function New_Typ (This : Ref) return Ref;
9703 -- function New_Typ (This : Ref; I : Integer) return Ref;
9704 -- pragma Cil_Constructor (New_Typ);
9706 -- Reason: The first formal must NOT be a primitive of the
9709 -- This rule also applies to constructors of delegates used
9710 -- to interface with standard target libraries. For example:
9712 -- type Delegate is access procedure ...
9713 -- pragma Import (CIL, Delegate, ...);
9715 -- function new_Delegate
9716 -- (This : Delegate := null; ... ) return Delegate;
9718 -- For value-types this rule does not apply.
9720 if not Is_Value_Type (Etype (Def_Id)) then
9721 if No (First_Formal (Def_Id)) then
9722 Error_Msg_Name_1 := Pname;
9723 Error_Msg_N ("% function must have parameters", Def_Id);
9727 -- In the JRE library we have several occurrences in which
9728 -- the "this" parameter is not the first formal.
9730 This_Formal := First_Formal (Def_Id);
9732 -- In the JRE library we have several occurrences in which
9733 -- the "this" parameter is not the first formal. Search for
9736 if VM_Target = JVM_Target then
9737 while Present (This_Formal)
9738 and then Get_Name_String (Chars (This_Formal)) /= "this"
9740 Next_Formal (This_Formal);
9743 if No (This_Formal) then
9744 This_Formal := First_Formal (Def_Id);
9748 -- Warning: The first parameter should be named "this".
9749 -- We temporarily allow it because we have the following
9750 -- case in the Java runtime (file s-osinte.ads) ???
9752 -- function new_Thread
9753 -- (Self_Id : System.Address) return Thread_Id;
9754 -- pragma Java_Constructor (new_Thread);
9756 if VM_Target = JVM_Target
9757 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9759 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9763 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9764 Error_Msg_Name_1 := Pname;
9766 ("first formal of % function must be named `this`",
9767 Parent (This_Formal));
9769 elsif not Is_Access_Type (Etype (This_Formal)) then
9770 Error_Msg_Name_1 := Pname;
9772 ("first formal of % function must be an access type",
9773 Parameter_Type (Parent (This_Formal)));
9775 -- For delegates the type of the first formal must be a
9776 -- named access-to-subprogram type (see previous example)
9778 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9779 and then Ekind (Etype (This_Formal))
9780 /= E_Access_Subprogram_Type
9782 Error_Msg_Name_1 := Pname;
9784 ("first formal of % function must be a named access" &
9785 " to subprogram type",
9786 Parameter_Type (Parent (This_Formal)));
9788 -- Warning: We should reject anonymous access types because
9789 -- the constructor must not be handled as a primitive of the
9790 -- tagged type. We temporarily allow it because this profile
9791 -- is currently generated by cil2ada???
9793 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9794 and then not Ekind_In (Etype (This_Formal),
9796 E_General_Access_Type,
9797 E_Anonymous_Access_Type)
9799 Error_Msg_Name_1 := Pname;
9801 ("first formal of % function must be a named access" &
9803 Parameter_Type (Parent (This_Formal)));
9805 elsif Atree.Convention
9806 (Designated_Type (Etype (This_Formal))) /= Convention
9808 Error_Msg_Name_1 := Pname;
9810 if Convention = Convention_Java then
9812 ("pragma% requires convention 'Cil in designated" &
9814 Parameter_Type (Parent (This_Formal)));
9817 ("pragma% requires convention 'Java in designated" &
9819 Parameter_Type (Parent (This_Formal)));
9822 elsif No (Expression (Parent (This_Formal)))
9823 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9825 Error_Msg_Name_1 := Pname;
9827 ("pragma% requires first formal with default `null`",
9828 Parameter_Type (Parent (This_Formal)));
9832 -- Check result type: the constructor must be a function
9834 -- * a value type (only allowed in the CIL compiler)
9835 -- * an access-to-subprogram type with convention Java/CIL
9836 -- * an access-type designating a type that has convention
9839 if Is_Value_Type (Etype (Def_Id)) then
9842 -- Access-to-subprogram type with convention Java/CIL
9844 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9845 if Atree.Convention (Etype (Def_Id)) /= Convention then
9846 if Convention = Convention_Java then
9848 ("pragma% requires function returning a " &
9849 "'Java access type", Arg1);
9851 pragma Assert (Convention = Convention_CIL);
9853 ("pragma% requires function returning a " &
9854 "'C'I'L access type", Arg1);
9858 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9859 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9860 E_General_Access_Type)
9863 (Designated_Type (Etype (Def_Id))) /= Convention
9865 Error_Msg_Name_1 := Pname;
9867 if Convention = Convention_Java then
9869 ("pragma% requires function returning a named" &
9870 "'Java access type", Arg1);
9873 ("pragma% requires function returning a named" &
9874 "'C'I'L access type", Arg1);
9879 Set_Is_Constructor (Def_Id);
9880 Set_Convention (Def_Id, Convention);
9881 Set_Is_Imported (Def_Id);
9883 exit when From_Aspect_Specification (N);
9884 Hom_Id := Homonym (Hom_Id);
9886 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9888 end Java_Constructor;
9890 ----------------------
9891 -- Java_Interface --
9892 ----------------------
9894 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
9896 when Pragma_Java_Interface => Java_Interface : declare
9902 Check_Arg_Count (1);
9903 Check_Optional_Identifier (Arg1, Name_Entity);
9904 Check_Arg_Is_Local_Name (Arg1);
9906 Arg := Get_Pragma_Arg (Arg1);
9909 if Etype (Arg) = Any_Type then
9913 if not Is_Entity_Name (Arg)
9914 or else not Is_Type (Entity (Arg))
9916 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
9919 Typ := Underlying_Type (Entity (Arg));
9921 -- For now simply check some of the semantic constraints on the
9922 -- type. This currently leaves out some restrictions on interface
9923 -- types, namely that the parent type must be java.lang.Object.Typ
9924 -- and that all primitives of the type should be declared
9927 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
9928 Error_Pragma_Arg ("pragma% requires an abstract "
9929 & "tagged type", Arg1);
9931 elsif not Has_Discriminants (Typ)
9932 or else Ekind (Etype (First_Discriminant (Typ)))
9933 /= E_Anonymous_Access_Type
9935 not Is_Class_Wide_Type
9936 (Designated_Type (Etype (First_Discriminant (Typ))))
9939 ("type must have a class-wide access discriminant", Arg1);
9947 -- pragma Keep_Names ([On => ] local_NAME);
9949 when Pragma_Keep_Names => Keep_Names : declare
9954 Check_Arg_Count (1);
9955 Check_Optional_Identifier (Arg1, Name_On);
9956 Check_Arg_Is_Local_Name (Arg1);
9958 Arg := Get_Pragma_Arg (Arg1);
9961 if Etype (Arg) = Any_Type then
9965 if not Is_Entity_Name (Arg)
9966 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
9969 ("pragma% requires a local enumeration type", Arg1);
9972 Set_Discard_Names (Entity (Arg), False);
9979 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
9981 when Pragma_License =>
9983 Check_Arg_Count (1);
9984 Check_No_Identifiers;
9985 Check_Valid_Configuration_Pragma;
9986 Check_Arg_Is_Identifier (Arg1);
9989 Sind : constant Source_File_Index :=
9990 Source_Index (Current_Sem_Unit);
9993 case Chars (Get_Pragma_Arg (Arg1)) is
9995 Set_License (Sind, GPL);
9997 when Name_Modified_GPL =>
9998 Set_License (Sind, Modified_GPL);
10000 when Name_Restricted =>
10001 Set_License (Sind, Restricted);
10003 when Name_Unrestricted =>
10004 Set_License (Sind, Unrestricted);
10007 Error_Pragma_Arg ("invalid license name", Arg1);
10015 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10017 when Pragma_Link_With => Link_With : declare
10023 if Operating_Mode = Generate_Code
10024 and then In_Extended_Main_Source_Unit (N)
10026 Check_At_Least_N_Arguments (1);
10027 Check_No_Identifiers;
10028 Check_Is_In_Decl_Part_Or_Package_Spec;
10029 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10033 while Present (Arg) loop
10034 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10036 -- Store argument, converting sequences of spaces to a
10037 -- single null character (this is one of the differences
10038 -- in processing between Link_With and Linker_Options).
10040 Arg_Store : declare
10041 C : constant Char_Code := Get_Char_Code (' ');
10042 S : constant String_Id :=
10043 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10044 L : constant Nat := String_Length (S);
10047 procedure Skip_Spaces;
10048 -- Advance F past any spaces
10054 procedure Skip_Spaces is
10056 while F <= L and then Get_String_Char (S, F) = C loop
10061 -- Start of processing for Arg_Store
10064 Skip_Spaces; -- skip leading spaces
10066 -- Loop through characters, changing any embedded
10067 -- sequence of spaces to a single null character (this
10068 -- is how Link_With/Linker_Options differ)
10071 if Get_String_Char (S, F) = C then
10074 Store_String_Char (ASCII.NUL);
10077 Store_String_Char (Get_String_Char (S, F));
10085 if Present (Arg) then
10086 Store_String_Char (ASCII.NUL);
10090 Store_Linker_Option_String (End_String);
10098 -- pragma Linker_Alias (
10099 -- [Entity =>] LOCAL_NAME
10100 -- [Target =>] static_string_EXPRESSION);
10102 when Pragma_Linker_Alias =>
10104 Check_Arg_Order ((Name_Entity, Name_Target));
10105 Check_Arg_Count (2);
10106 Check_Optional_Identifier (Arg1, Name_Entity);
10107 Check_Optional_Identifier (Arg2, Name_Target);
10108 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10109 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10111 -- The only processing required is to link this item on to the
10112 -- list of rep items for the given entity. This is accomplished
10113 -- by the call to Rep_Item_Too_Late (when no error is detected
10114 -- and False is returned).
10116 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10119 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10122 ------------------------
10123 -- Linker_Constructor --
10124 ------------------------
10126 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10128 -- Code is shared with Linker_Destructor
10130 -----------------------
10131 -- Linker_Destructor --
10132 -----------------------
10134 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10136 when Pragma_Linker_Constructor |
10137 Pragma_Linker_Destructor =>
10138 Linker_Constructor : declare
10144 Check_Arg_Count (1);
10145 Check_No_Identifiers;
10146 Check_Arg_Is_Local_Name (Arg1);
10147 Arg1_X := Get_Pragma_Arg (Arg1);
10149 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10151 if not Is_Library_Level_Entity (Proc) then
10153 ("argument for pragma% must be library level entity", Arg1);
10156 -- The only processing required is to link this item on to the
10157 -- list of rep items for the given entity. This is accomplished
10158 -- by the call to Rep_Item_Too_Late (when no error is detected
10159 -- and False is returned).
10161 if Rep_Item_Too_Late (Proc, N) then
10164 Set_Has_Gigi_Rep_Item (Proc);
10166 end Linker_Constructor;
10168 --------------------
10169 -- Linker_Options --
10170 --------------------
10172 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10174 when Pragma_Linker_Options => Linker_Options : declare
10178 Check_Ada_83_Warning;
10179 Check_No_Identifiers;
10180 Check_Arg_Count (1);
10181 Check_Is_In_Decl_Part_Or_Package_Spec;
10182 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10183 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10186 while Present (Arg) loop
10187 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10188 Store_String_Char (ASCII.NUL);
10190 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10194 if Operating_Mode = Generate_Code
10195 and then In_Extended_Main_Source_Unit (N)
10197 Store_Linker_Option_String (End_String);
10199 end Linker_Options;
10201 --------------------
10202 -- Linker_Section --
10203 --------------------
10205 -- pragma Linker_Section (
10206 -- [Entity =>] LOCAL_NAME
10207 -- [Section =>] static_string_EXPRESSION);
10209 when Pragma_Linker_Section =>
10211 Check_Arg_Order ((Name_Entity, Name_Section));
10212 Check_Arg_Count (2);
10213 Check_Optional_Identifier (Arg1, Name_Entity);
10214 Check_Optional_Identifier (Arg2, Name_Section);
10215 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10216 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10218 -- This pragma applies only to objects
10220 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10221 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10224 -- The only processing required is to link this item on to the
10225 -- list of rep items for the given entity. This is accomplished
10226 -- by the call to Rep_Item_Too_Late (when no error is detected
10227 -- and False is returned).
10229 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10232 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10239 -- pragma List (On | Off)
10241 -- There is nothing to do here, since we did all the processing for
10242 -- this pragma in Par.Prag (so that it works properly even in syntax
10245 when Pragma_List =>
10248 --------------------
10249 -- Locking_Policy --
10250 --------------------
10252 -- pragma Locking_Policy (policy_IDENTIFIER);
10254 when Pragma_Locking_Policy => declare
10258 Check_Ada_83_Warning;
10259 Check_Arg_Count (1);
10260 Check_No_Identifiers;
10261 Check_Arg_Is_Locking_Policy (Arg1);
10262 Check_Valid_Configuration_Pragma;
10263 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10264 LP := Fold_Upper (Name_Buffer (1));
10266 if Locking_Policy /= ' '
10267 and then Locking_Policy /= LP
10269 Error_Msg_Sloc := Locking_Policy_Sloc;
10270 Error_Pragma ("locking policy incompatible with policy#");
10272 -- Set new policy, but always preserve System_Location since we
10273 -- like the error message with the run time name.
10276 Locking_Policy := LP;
10278 if Locking_Policy_Sloc /= System_Location then
10279 Locking_Policy_Sloc := Loc;
10288 -- pragma Long_Float (D_Float | G_Float);
10290 when Pragma_Long_Float =>
10292 Check_Valid_Configuration_Pragma;
10293 Check_Arg_Count (1);
10294 Check_No_Identifier (Arg1);
10295 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10297 if not OpenVMS_On_Target then
10298 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10303 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10304 if Opt.Float_Format_Long = 'G' then
10305 Error_Pragma ("G_Float previously specified");
10308 Opt.Float_Format_Long := 'D';
10310 -- G_Float case (this is the default, does not need overriding)
10313 if Opt.Float_Format_Long = 'D' then
10314 Error_Pragma ("D_Float previously specified");
10317 Opt.Float_Format_Long := 'G';
10320 Set_Standard_Fpt_Formats;
10322 -----------------------
10323 -- Machine_Attribute --
10324 -----------------------
10326 -- pragma Machine_Attribute (
10327 -- [Entity =>] LOCAL_NAME,
10328 -- [Attribute_Name =>] static_string_EXPRESSION
10329 -- [, [Info =>] static_EXPRESSION] );
10331 when Pragma_Machine_Attribute => Machine_Attribute : declare
10332 Def_Id : Entity_Id;
10336 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10338 if Arg_Count = 3 then
10339 Check_Optional_Identifier (Arg3, Name_Info);
10340 Check_Arg_Is_Static_Expression (Arg3);
10342 Check_Arg_Count (2);
10345 Check_Optional_Identifier (Arg1, Name_Entity);
10346 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10347 Check_Arg_Is_Local_Name (Arg1);
10348 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10349 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10351 if Is_Access_Type (Def_Id) then
10352 Def_Id := Designated_Type (Def_Id);
10355 if Rep_Item_Too_Early (Def_Id, N) then
10359 Def_Id := Underlying_Type (Def_Id);
10361 -- The only processing required is to link this item on to the
10362 -- list of rep items for the given entity. This is accomplished
10363 -- by the call to Rep_Item_Too_Late (when no error is detected
10364 -- and False is returned).
10366 if Rep_Item_Too_Late (Def_Id, N) then
10369 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10371 end Machine_Attribute;
10378 -- (MAIN_OPTION [, MAIN_OPTION]);
10381 -- [STACK_SIZE =>] static_integer_EXPRESSION
10382 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10383 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10385 when Pragma_Main => Main : declare
10386 Args : Args_List (1 .. 3);
10387 Names : constant Name_List (1 .. 3) := (
10389 Name_Task_Stack_Size_Default,
10390 Name_Time_Slicing_Enabled);
10396 Gather_Associations (Names, Args);
10398 for J in 1 .. 2 loop
10399 if Present (Args (J)) then
10400 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10404 if Present (Args (3)) then
10405 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10409 while Present (Nod) loop
10410 if Nkind (Nod) = N_Pragma
10411 and then Pragma_Name (Nod) = Name_Main
10413 Error_Msg_Name_1 := Pname;
10414 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10425 -- pragma Main_Storage
10426 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10428 -- MAIN_STORAGE_OPTION ::=
10429 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10430 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10432 when Pragma_Main_Storage => Main_Storage : declare
10433 Args : Args_List (1 .. 2);
10434 Names : constant Name_List (1 .. 2) := (
10435 Name_Working_Storage,
10442 Gather_Associations (Names, Args);
10444 for J in 1 .. 2 loop
10445 if Present (Args (J)) then
10446 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10450 Check_In_Main_Program;
10453 while Present (Nod) loop
10454 if Nkind (Nod) = N_Pragma
10455 and then Pragma_Name (Nod) = Name_Main_Storage
10457 Error_Msg_Name_1 := Pname;
10458 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10469 -- pragma Memory_Size (NUMERIC_LITERAL)
10471 when Pragma_Memory_Size =>
10474 -- Memory size is simply ignored
10476 Check_No_Identifiers;
10477 Check_Arg_Count (1);
10478 Check_Arg_Is_Integer_Literal (Arg1);
10486 -- The only correct use of this pragma is on its own in a file, in
10487 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10488 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10489 -- check for a file containing nothing but a No_Body pragma). If we
10490 -- attempt to process it during normal semantics processing, it means
10491 -- it was misplaced.
10493 when Pragma_No_Body =>
10501 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10503 when Pragma_No_Return => No_Return : declare
10511 Check_At_Least_N_Arguments (1);
10513 -- Loop through arguments of pragma
10516 while Present (Arg) loop
10517 Check_Arg_Is_Local_Name (Arg);
10518 Id := Get_Pragma_Arg (Arg);
10521 if not Is_Entity_Name (Id) then
10522 Error_Pragma_Arg ("entity name required", Arg);
10525 if Etype (Id) = Any_Type then
10529 -- Loop to find matching procedures
10534 and then Scope (E) = Current_Scope
10536 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10539 -- Set flag on any alias as well
10541 if Is_Overloadable (E) and then Present (Alias (E)) then
10542 Set_No_Return (Alias (E));
10548 exit when From_Aspect_Specification (N);
10553 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10564 -- pragma No_Run_Time;
10566 -- Note: this pragma is retained for backwards compatibility. See
10567 -- body of Rtsfind for full details on its handling.
10569 when Pragma_No_Run_Time =>
10571 Check_Valid_Configuration_Pragma;
10572 Check_Arg_Count (0);
10574 No_Run_Time_Mode := True;
10575 Configurable_Run_Time_Mode := True;
10577 -- Set Duration to 32 bits if word size is 32
10579 if Ttypes.System_Word_Size = 32 then
10580 Duration_32_Bits_On_Target := True;
10583 -- Set appropriate restrictions
10585 Set_Restriction (No_Finalization, N);
10586 Set_Restriction (No_Exception_Handlers, N);
10587 Set_Restriction (Max_Tasks, N, 0);
10588 Set_Restriction (No_Tasking, N);
10590 ------------------------
10591 -- No_Strict_Aliasing --
10592 ------------------------
10594 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10596 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10601 Check_At_Most_N_Arguments (1);
10603 if Arg_Count = 0 then
10604 Check_Valid_Configuration_Pragma;
10605 Opt.No_Strict_Aliasing := True;
10608 Check_Optional_Identifier (Arg2, Name_Entity);
10609 Check_Arg_Is_Local_Name (Arg1);
10610 E_Id := Entity (Get_Pragma_Arg (Arg1));
10612 if E_Id = Any_Type then
10614 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10615 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10618 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10620 end No_Strict_Aliasing;
10622 -----------------------
10623 -- Normalize_Scalars --
10624 -----------------------
10626 -- pragma Normalize_Scalars;
10628 when Pragma_Normalize_Scalars =>
10629 Check_Ada_83_Warning;
10630 Check_Arg_Count (0);
10631 Check_Valid_Configuration_Pragma;
10633 -- Normalize_Scalars creates false positives in CodePeer, so
10634 -- ignore this pragma in this mode.
10636 if not CodePeer_Mode then
10637 Normalize_Scalars := True;
10638 Init_Or_Norm_Scalars := True;
10645 -- pragma Obsolescent;
10647 -- pragma Obsolescent (
10648 -- [Message =>] static_string_EXPRESSION
10649 -- [,[Version =>] Ada_05]]);
10651 -- pragma Obsolescent (
10652 -- [Entity =>] NAME
10653 -- [,[Message =>] static_string_EXPRESSION
10654 -- [,[Version =>] Ada_05]] );
10656 when Pragma_Obsolescent => Obsolescent : declare
10660 procedure Set_Obsolescent (E : Entity_Id);
10661 -- Given an entity Ent, mark it as obsolescent if appropriate
10663 ---------------------
10664 -- Set_Obsolescent --
10665 ---------------------
10667 procedure Set_Obsolescent (E : Entity_Id) is
10676 -- Entity name was given
10678 if Present (Ename) then
10680 -- If entity name matches, we are fine. Save entity in
10681 -- pragma argument, for ASIS use.
10683 if Chars (Ename) = Chars (Ent) then
10684 Set_Entity (Ename, Ent);
10685 Generate_Reference (Ent, Ename);
10687 -- If entity name does not match, only possibility is an
10688 -- enumeration literal from an enumeration type declaration.
10690 elsif Ekind (Ent) /= E_Enumeration_Type then
10692 ("pragma % entity name does not match declaration");
10695 Ent := First_Literal (E);
10699 ("pragma % entity name does not match any " &
10700 "enumeration literal");
10702 elsif Chars (Ent) = Chars (Ename) then
10703 Set_Entity (Ename, Ent);
10704 Generate_Reference (Ent, Ename);
10708 Ent := Next_Literal (Ent);
10714 -- Ent points to entity to be marked
10716 if Arg_Count >= 1 then
10718 -- Deal with static string argument
10720 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10721 S := Strval (Get_Pragma_Arg (Arg1));
10723 for J in 1 .. String_Length (S) loop
10724 if not In_Character_Range (Get_String_Char (S, J)) then
10726 ("pragma% argument does not allow wide characters",
10731 Obsolescent_Warnings.Append
10732 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10734 -- Check for Ada_05 parameter
10736 if Arg_Count /= 1 then
10737 Check_Arg_Count (2);
10740 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10743 Check_Arg_Is_Identifier (Argx);
10745 if Chars (Argx) /= Name_Ada_05 then
10746 Error_Msg_Name_2 := Name_Ada_05;
10748 ("only allowed argument for pragma% is %", Argx);
10751 if Ada_Version_Explicit < Ada_2005
10752 or else not Warn_On_Ada_2005_Compatibility
10760 -- Set flag if pragma active
10763 Set_Is_Obsolescent (Ent);
10767 end Set_Obsolescent;
10769 -- Start of processing for pragma Obsolescent
10774 Check_At_Most_N_Arguments (3);
10776 -- See if first argument specifies an entity name
10780 (Chars (Arg1) = Name_Entity
10782 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10784 N_Operator_Symbol))
10786 Ename := Get_Pragma_Arg (Arg1);
10788 -- Eliminate first argument, so we can share processing
10792 Arg_Count := Arg_Count - 1;
10794 -- No Entity name argument given
10800 if Arg_Count >= 1 then
10801 Check_Optional_Identifier (Arg1, Name_Message);
10803 if Arg_Count = 2 then
10804 Check_Optional_Identifier (Arg2, Name_Version);
10808 -- Get immediately preceding declaration
10811 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10815 -- Cases where we do not follow anything other than another pragma
10819 -- First case: library level compilation unit declaration with
10820 -- the pragma immediately following the declaration.
10822 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10824 (Defining_Entity (Unit (Parent (Parent (N)))));
10827 -- Case 2: library unit placement for package
10831 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10833 if Is_Package_Or_Generic_Package (Ent) then
10834 Set_Obsolescent (Ent);
10840 -- Cases where we must follow a declaration
10843 if Nkind (Decl) not in N_Declaration
10844 and then Nkind (Decl) not in N_Later_Decl_Item
10845 and then Nkind (Decl) not in N_Generic_Declaration
10846 and then Nkind (Decl) not in N_Renaming_Declaration
10849 ("pragma% misplaced, "
10850 & "must immediately follow a declaration");
10853 Set_Obsolescent (Defining_Entity (Decl));
10863 -- pragma Optimize (Time | Space | Off);
10865 -- The actual check for optimize is done in Gigi. Note that this
10866 -- pragma does not actually change the optimization setting, it
10867 -- simply checks that it is consistent with the pragma.
10869 when Pragma_Optimize =>
10870 Check_No_Identifiers;
10871 Check_Arg_Count (1);
10872 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10874 ------------------------
10875 -- Optimize_Alignment --
10876 ------------------------
10878 -- pragma Optimize_Alignment (Time | Space | Off);
10880 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10882 Check_No_Identifiers;
10883 Check_Arg_Count (1);
10884 Check_Valid_Configuration_Pragma;
10887 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10891 Opt.Optimize_Alignment := 'T';
10893 Opt.Optimize_Alignment := 'S';
10895 Opt.Optimize_Alignment := 'O';
10897 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10901 -- Set indication that mode is set locally. If we are in fact in a
10902 -- configuration pragma file, this setting is harmless since the
10903 -- switch will get reset anyway at the start of each unit.
10905 Optimize_Alignment_Local := True;
10906 end Optimize_Alignment;
10912 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
10914 when Pragma_Ordered => Ordered : declare
10915 Assoc : constant Node_Id := Arg1;
10921 Check_No_Identifiers;
10922 Check_Arg_Count (1);
10923 Check_Arg_Is_Local_Name (Arg1);
10925 Type_Id := Get_Pragma_Arg (Assoc);
10926 Find_Type (Type_Id);
10927 Typ := Entity (Type_Id);
10929 if Typ = Any_Type then
10932 Typ := Underlying_Type (Typ);
10935 if not Is_Enumeration_Type (Typ) then
10936 Error_Pragma ("pragma% must specify enumeration type");
10939 Check_First_Subtype (Arg1);
10940 Set_Has_Pragma_Ordered (Base_Type (Typ));
10947 -- pragma Pack (first_subtype_LOCAL_NAME);
10949 when Pragma_Pack => Pack : declare
10950 Assoc : constant Node_Id := Arg1;
10954 Ignore : Boolean := False;
10957 Check_No_Identifiers;
10958 Check_Arg_Count (1);
10959 Check_Arg_Is_Local_Name (Arg1);
10961 Type_Id := Get_Pragma_Arg (Assoc);
10962 Find_Type (Type_Id);
10963 Typ := Entity (Type_Id);
10966 or else Rep_Item_Too_Early (Typ, N)
10970 Typ := Underlying_Type (Typ);
10973 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
10974 Error_Pragma ("pragma% must specify array or record type");
10977 Check_First_Subtype (Arg1);
10978 Check_Duplicate_Pragma (Typ);
10982 if Is_Array_Type (Typ) then
10983 Ctyp := Component_Type (Typ);
10985 -- Ignore pack that does nothing
10987 if Known_Static_Esize (Ctyp)
10988 and then Known_Static_RM_Size (Ctyp)
10989 and then Esize (Ctyp) = RM_Size (Ctyp)
10990 and then Addressable (Esize (Ctyp))
10995 -- Process OK pragma Pack. Note that if there is a separate
10996 -- component clause present, the Pack will be cancelled. This
10997 -- processing is in Freeze.
10999 if not Rep_Item_Too_Late (Typ, N) then
11001 -- In the context of static code analysis, we do not need
11002 -- complex front-end expansions related to pragma Pack,
11003 -- so disable handling of pragma Pack in this case.
11005 if CodePeer_Mode then
11008 -- Don't attempt any packing for VM targets. We possibly
11009 -- could deal with some cases of array bit-packing, but we
11010 -- don't bother, since this is not a typical kind of
11011 -- representation in the VM context anyway (and would not
11012 -- for example work nicely with the debugger).
11014 elsif VM_Target /= No_VM then
11015 if not GNAT_Mode then
11017 ("?pragma% ignored in this configuration");
11020 -- Normal case where we do the pack action
11024 Set_Is_Packed (Base_Type (Typ));
11025 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11028 Set_Has_Pragma_Pack (Base_Type (Typ));
11032 -- For record types, the pack is always effective
11034 else pragma Assert (Is_Record_Type (Typ));
11035 if not Rep_Item_Too_Late (Typ, N) then
11037 -- Ignore pack request with warning in VM mode (skip warning
11038 -- if we are compiling GNAT run time library).
11040 if VM_Target /= No_VM then
11041 if not GNAT_Mode then
11043 ("?pragma% ignored in this configuration");
11046 -- Normal case of pack request active
11049 Set_Is_Packed (Base_Type (Typ));
11050 Set_Has_Pragma_Pack (Base_Type (Typ));
11051 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11063 -- There is nothing to do here, since we did all the processing for
11064 -- this pragma in Par.Prag (so that it works properly even in syntax
11067 when Pragma_Page =>
11074 -- pragma Passive [(PASSIVE_FORM)];
11076 -- PASSIVE_FORM ::= Semaphore | No
11078 when Pragma_Passive =>
11081 if Nkind (Parent (N)) /= N_Task_Definition then
11082 Error_Pragma ("pragma% must be within task definition");
11085 if Arg_Count /= 0 then
11086 Check_Arg_Count (1);
11087 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11090 ----------------------------------
11091 -- Preelaborable_Initialization --
11092 ----------------------------------
11094 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11096 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11101 Check_Arg_Count (1);
11102 Check_No_Identifiers;
11103 Check_Arg_Is_Identifier (Arg1);
11104 Check_Arg_Is_Local_Name (Arg1);
11105 Check_First_Subtype (Arg1);
11106 Ent := Entity (Get_Pragma_Arg (Arg1));
11108 if not (Is_Private_Type (Ent)
11110 Is_Protected_Type (Ent)
11112 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11115 ("pragma % can only be applied to private, formal derived or "
11116 & "protected type",
11120 -- Give an error if the pragma is applied to a protected type that
11121 -- does not qualify (due to having entries, or due to components
11122 -- that do not qualify).
11124 if Is_Protected_Type (Ent)
11125 and then not Has_Preelaborable_Initialization (Ent)
11128 ("protected type & does not have preelaborable " &
11129 "initialization", Ent);
11131 -- Otherwise mark the type as definitely having preelaborable
11135 Set_Known_To_Have_Preelab_Init (Ent);
11138 if Has_Pragma_Preelab_Init (Ent)
11139 and then Warn_On_Redundant_Constructs
11141 Error_Pragma ("?duplicate pragma%!");
11143 Set_Has_Pragma_Preelab_Init (Ent);
11147 --------------------
11148 -- Persistent_BSS --
11149 --------------------
11151 -- pragma Persistent_BSS [(object_NAME)];
11153 when Pragma_Persistent_BSS => Persistent_BSS : declare
11160 Check_At_Most_N_Arguments (1);
11162 -- Case of application to specific object (one argument)
11164 if Arg_Count = 1 then
11165 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11167 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11169 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11172 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11175 Ent := Entity (Get_Pragma_Arg (Arg1));
11176 Decl := Parent (Ent);
11178 if Rep_Item_Too_Late (Ent, N) then
11182 if Present (Expression (Decl)) then
11184 ("object for pragma% cannot have initialization", Arg1);
11187 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11189 ("object type for pragma% is not potentially persistent",
11193 Check_Duplicate_Pragma (Ent);
11196 Make_Linker_Section_Pragma
11197 (Ent, Sloc (N), ".persistent.bss");
11198 Insert_After (N, Prag);
11201 -- Case of use as configuration pragma with no arguments
11204 Check_Valid_Configuration_Pragma;
11205 Persistent_BSS_Mode := True;
11207 end Persistent_BSS;
11213 -- pragma Polling (ON | OFF);
11215 when Pragma_Polling =>
11217 Check_Arg_Count (1);
11218 Check_No_Identifiers;
11219 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11220 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11222 -------------------
11223 -- Postcondition --
11224 -------------------
11226 -- pragma Postcondition ([Check =>] Boolean_Expression
11227 -- [,[Message =>] String_Expression]);
11229 when Pragma_Postcondition => Postcondition : declare
11231 pragma Warnings (Off, In_Body);
11235 Check_At_Least_N_Arguments (1);
11236 Check_At_Most_N_Arguments (2);
11237 Check_Optional_Identifier (Arg1, Name_Check);
11239 -- All we need to do here is call the common check procedure,
11240 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11242 Check_Precondition_Postcondition (In_Body);
11249 -- pragma Precondition ([Check =>] Boolean_Expression
11250 -- [,[Message =>] String_Expression]);
11252 when Pragma_Precondition => Precondition : declare
11257 Check_At_Least_N_Arguments (1);
11258 Check_At_Most_N_Arguments (2);
11259 Check_Optional_Identifier (Arg1, Name_Check);
11260 Check_Precondition_Postcondition (In_Body);
11262 -- If in spec, nothing more to do. If in body, then we convert the
11263 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11264 -- this whether or not precondition checks are enabled. That works
11265 -- fine since pragma Check will do this check, and will also
11266 -- analyze the condition itself in the proper context.
11271 Chars => Name_Check,
11272 Pragma_Argument_Associations => New_List (
11273 Make_Pragma_Argument_Association (Loc,
11274 Expression => Make_Identifier (Loc, Name_Precondition)),
11276 Make_Pragma_Argument_Association (Sloc (Arg1),
11277 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11279 if Arg_Count = 2 then
11280 Append_To (Pragma_Argument_Associations (N),
11281 Make_Pragma_Argument_Association (Sloc (Arg2),
11282 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11293 -- pragma Predicate
11294 -- ([Entity =>] type_LOCAL_NAME,
11295 -- [Check =>] EXPRESSION);
11297 when Pragma_Predicate => Predicate : declare
11302 pragma Unreferenced (Discard);
11306 Check_Arg_Count (2);
11307 Check_Optional_Identifier (Arg1, Name_Entity);
11308 Check_Optional_Identifier (Arg2, Name_Check);
11310 Check_Arg_Is_Local_Name (Arg1);
11312 Type_Id := Get_Pragma_Arg (Arg1);
11313 Find_Type (Type_Id);
11314 Typ := Entity (Type_Id);
11316 if Typ = Any_Type then
11320 -- The remaining processing is simply to link the pragma on to
11321 -- the rep item chain, for processing when the type is frozen.
11322 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11323 -- mark the type as having predicates.
11325 Set_Has_Predicates (Typ);
11326 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11333 -- pragma Preelaborate [(library_unit_NAME)];
11335 -- Set the flag Is_Preelaborated of program unit name entity
11337 when Pragma_Preelaborate => Preelaborate : declare
11338 Pa : constant Node_Id := Parent (N);
11339 Pk : constant Node_Kind := Nkind (Pa);
11343 Check_Ada_83_Warning;
11344 Check_Valid_Library_Unit_Pragma;
11346 if Nkind (N) = N_Null_Statement then
11350 Ent := Find_Lib_Unit_Name;
11351 Check_Duplicate_Pragma (Ent);
11353 -- This filters out pragmas inside generic parent then
11354 -- show up inside instantiation
11357 and then not (Pk = N_Package_Specification
11358 and then Present (Generic_Parent (Pa)))
11360 if not Debug_Flag_U then
11361 Set_Is_Preelaborated (Ent);
11362 Set_Suppress_Elaboration_Warnings (Ent);
11367 ---------------------
11368 -- Preelaborate_05 --
11369 ---------------------
11371 -- pragma Preelaborate_05 [(library_unit_NAME)];
11373 -- This pragma is useable only in GNAT_Mode, where it is used like
11374 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11375 -- (otherwise it is ignored). This is used to implement AI-362 which
11376 -- recategorizes some run-time packages in Ada 2005 mode.
11378 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11383 Check_Valid_Library_Unit_Pragma;
11385 if not GNAT_Mode then
11386 Error_Pragma ("pragma% only available in GNAT mode");
11389 if Nkind (N) = N_Null_Statement then
11393 -- This is one of the few cases where we need to test the value of
11394 -- Ada_Version_Explicit rather than Ada_Version (which is always
11395 -- set to Ada_2012 in a predefined unit), we need to know the
11396 -- explicit version set to know if this pragma is active.
11398 if Ada_Version_Explicit >= Ada_2005 then
11399 Ent := Find_Lib_Unit_Name;
11400 Set_Is_Preelaborated (Ent);
11401 Set_Suppress_Elaboration_Warnings (Ent);
11403 end Preelaborate_05;
11409 -- pragma Priority (EXPRESSION);
11411 when Pragma_Priority => Priority : declare
11412 P : constant Node_Id := Parent (N);
11416 Check_No_Identifiers;
11417 Check_Arg_Count (1);
11421 if Nkind (P) = N_Subprogram_Body then
11422 Check_In_Main_Program;
11424 Arg := Get_Pragma_Arg (Arg1);
11425 Analyze_And_Resolve (Arg, Standard_Integer);
11429 if not Is_Static_Expression (Arg) then
11430 Flag_Non_Static_Expr
11431 ("main subprogram priority is not static!", Arg);
11434 -- If constraint error, then we already signalled an error
11436 elsif Raises_Constraint_Error (Arg) then
11439 -- Otherwise check in range
11443 Val : constant Uint := Expr_Value (Arg);
11447 or else Val > Expr_Value (Expression
11448 (Parent (RTE (RE_Max_Priority))))
11451 ("main subprogram priority is out of range", Arg1);
11457 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11459 -- Load an arbitrary entity from System.Tasking to make sure
11460 -- this package is implicitly with'ed, since we need to have
11461 -- the tasking run-time active for the pragma Priority to have
11465 Discard : Entity_Id;
11466 pragma Warnings (Off, Discard);
11468 Discard := RTE (RE_Task_List);
11471 -- Task or Protected, must be of type Integer
11473 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11474 Arg := Get_Pragma_Arg (Arg1);
11476 -- The expression must be analyzed in the special manner
11477 -- described in "Handling of Default and Per-Object
11478 -- Expressions" in sem.ads.
11480 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11482 if not Is_Static_Expression (Arg) then
11483 Check_Restriction (Static_Priorities, Arg);
11486 -- Anything else is incorrect
11492 if Has_Pragma_Priority (P) then
11493 Error_Pragma ("duplicate pragma% not allowed");
11495 Set_Has_Pragma_Priority (P, True);
11497 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11498 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11499 -- exp_ch9 should use this ???
11504 -----------------------------------
11505 -- Priority_Specific_Dispatching --
11506 -----------------------------------
11508 -- pragma Priority_Specific_Dispatching (
11509 -- policy_IDENTIFIER,
11510 -- first_priority_EXPRESSION,
11511 -- last_priority_EXPRESSION);
11513 when Pragma_Priority_Specific_Dispatching =>
11514 Priority_Specific_Dispatching : declare
11515 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11516 -- This is the entity System.Any_Priority;
11519 Lower_Bound : Node_Id;
11520 Upper_Bound : Node_Id;
11526 Check_Arg_Count (3);
11527 Check_No_Identifiers;
11528 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11529 Check_Valid_Configuration_Pragma;
11530 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11531 DP := Fold_Upper (Name_Buffer (1));
11533 Lower_Bound := Get_Pragma_Arg (Arg2);
11534 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11535 Lower_Val := Expr_Value (Lower_Bound);
11537 Upper_Bound := Get_Pragma_Arg (Arg3);
11538 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11539 Upper_Val := Expr_Value (Upper_Bound);
11541 -- It is not allowed to use Task_Dispatching_Policy and
11542 -- Priority_Specific_Dispatching in the same partition.
11544 if Task_Dispatching_Policy /= ' ' then
11545 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11547 ("pragma% incompatible with Task_Dispatching_Policy#");
11549 -- Check lower bound in range
11551 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11553 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11556 ("first_priority is out of range", Arg2);
11558 -- Check upper bound in range
11560 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11562 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11565 ("last_priority is out of range", Arg3);
11567 -- Check that the priority range is valid
11569 elsif Lower_Val > Upper_Val then
11571 ("last_priority_expression must be greater than" &
11572 " or equal to first_priority_expression");
11574 -- Store the new policy, but always preserve System_Location since
11575 -- we like the error message with the run-time name.
11578 -- Check overlapping in the priority ranges specified in other
11579 -- Priority_Specific_Dispatching pragmas within the same
11580 -- partition. We can only check those we know about!
11583 Specific_Dispatching.First .. Specific_Dispatching.Last
11585 if Specific_Dispatching.Table (J).First_Priority in
11586 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11587 or else Specific_Dispatching.Table (J).Last_Priority in
11588 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11591 Specific_Dispatching.Table (J).Pragma_Loc;
11593 ("priority range overlaps with "
11594 & "Priority_Specific_Dispatching#");
11598 -- The use of Priority_Specific_Dispatching is incompatible
11599 -- with Task_Dispatching_Policy.
11601 if Task_Dispatching_Policy /= ' ' then
11602 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11604 ("Priority_Specific_Dispatching incompatible "
11605 & "with Task_Dispatching_Policy#");
11608 -- The use of Priority_Specific_Dispatching forces ceiling
11611 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11612 Error_Msg_Sloc := Locking_Policy_Sloc;
11614 ("Priority_Specific_Dispatching incompatible "
11615 & "with Locking_Policy#");
11617 -- Set the Ceiling_Locking policy, but preserve System_Location
11618 -- since we like the error message with the run time name.
11621 Locking_Policy := 'C';
11623 if Locking_Policy_Sloc /= System_Location then
11624 Locking_Policy_Sloc := Loc;
11628 -- Add entry in the table
11630 Specific_Dispatching.Append
11631 ((Dispatching_Policy => DP,
11632 First_Priority => UI_To_Int (Lower_Val),
11633 Last_Priority => UI_To_Int (Upper_Val),
11634 Pragma_Loc => Loc));
11636 end Priority_Specific_Dispatching;
11642 -- pragma Profile (profile_IDENTIFIER);
11644 -- profile_IDENTIFIER => Restricted | Ravenscar
11646 when Pragma_Profile =>
11648 Check_Arg_Count (1);
11649 Check_Valid_Configuration_Pragma;
11650 Check_No_Identifiers;
11653 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11655 if Chars (Argx) = Name_Ravenscar then
11656 Set_Ravenscar_Profile (N);
11657 elsif Chars (Argx) = Name_Restricted then
11658 Set_Profile_Restrictions
11659 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11661 Error_Pragma_Arg ("& is not a valid profile", Argx);
11665 ----------------------
11666 -- Profile_Warnings --
11667 ----------------------
11669 -- pragma Profile_Warnings (profile_IDENTIFIER);
11671 -- profile_IDENTIFIER => Restricted | Ravenscar
11673 when Pragma_Profile_Warnings =>
11675 Check_Arg_Count (1);
11676 Check_Valid_Configuration_Pragma;
11677 Check_No_Identifiers;
11680 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11682 if Chars (Argx) = Name_Ravenscar then
11683 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11684 elsif Chars (Argx) = Name_Restricted then
11685 Set_Profile_Restrictions (Restricted, N, Warn => True);
11687 Error_Pragma_Arg ("& is not a valid profile", Argx);
11691 --------------------------
11692 -- Propagate_Exceptions --
11693 --------------------------
11695 -- pragma Propagate_Exceptions;
11697 -- Note: this pragma is obsolete and has no effect
11699 when Pragma_Propagate_Exceptions =>
11701 Check_Arg_Count (0);
11703 if In_Extended_Main_Source_Unit (N) then
11704 Propagate_Exceptions := True;
11711 -- pragma Psect_Object (
11712 -- [Internal =>] LOCAL_NAME,
11713 -- [, [External =>] EXTERNAL_SYMBOL]
11714 -- [, [Size =>] EXTERNAL_SYMBOL]);
11716 when Pragma_Psect_Object | Pragma_Common_Object =>
11717 Psect_Object : declare
11718 Args : Args_List (1 .. 3);
11719 Names : constant Name_List (1 .. 3) := (
11724 Internal : Node_Id renames Args (1);
11725 External : Node_Id renames Args (2);
11726 Size : Node_Id renames Args (3);
11728 Def_Id : Entity_Id;
11730 procedure Check_Too_Long (Arg : Node_Id);
11731 -- Posts message if the argument is an identifier with more
11732 -- than 31 characters, or a string literal with more than
11733 -- 31 characters, and we are operating under VMS
11735 --------------------
11736 -- Check_Too_Long --
11737 --------------------
11739 procedure Check_Too_Long (Arg : Node_Id) is
11740 X : constant Node_Id := Original_Node (Arg);
11743 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11745 ("inappropriate argument for pragma %", Arg);
11748 if OpenVMS_On_Target then
11749 if (Nkind (X) = N_String_Literal
11750 and then String_Length (Strval (X)) > 31)
11752 (Nkind (X) = N_Identifier
11753 and then Length_Of_Name (Chars (X)) > 31)
11756 ("argument for pragma % is longer than 31 characters",
11760 end Check_Too_Long;
11762 -- Start of processing for Common_Object/Psect_Object
11766 Gather_Associations (Names, Args);
11767 Process_Extended_Import_Export_Internal_Arg (Internal);
11769 Def_Id := Entity (Internal);
11771 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11773 ("pragma% must designate an object", Internal);
11776 Check_Too_Long (Internal);
11778 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11780 ("cannot use pragma% for imported/exported object",
11784 if Is_Concurrent_Type (Etype (Internal)) then
11786 ("cannot specify pragma % for task/protected object",
11790 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11792 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11794 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11797 if Ekind (Def_Id) = E_Constant then
11799 ("cannot specify pragma % for a constant", Internal);
11802 if Is_Record_Type (Etype (Internal)) then
11808 Ent := First_Entity (Etype (Internal));
11809 while Present (Ent) loop
11810 Decl := Declaration_Node (Ent);
11812 if Ekind (Ent) = E_Component
11813 and then Nkind (Decl) = N_Component_Declaration
11814 and then Present (Expression (Decl))
11815 and then Warn_On_Export_Import
11818 ("?object for pragma % has defaults", Internal);
11828 if Present (Size) then
11829 Check_Too_Long (Size);
11832 if Present (External) then
11833 Check_Arg_Is_External_Name (External);
11834 Check_Too_Long (External);
11837 -- If all error tests pass, link pragma on to the rep item chain
11839 Record_Rep_Item (Def_Id, N);
11846 -- pragma Pure [(library_unit_NAME)];
11848 when Pragma_Pure => Pure : declare
11852 Check_Ada_83_Warning;
11853 Check_Valid_Library_Unit_Pragma;
11855 if Nkind (N) = N_Null_Statement then
11859 Ent := Find_Lib_Unit_Name;
11861 Set_Has_Pragma_Pure (Ent);
11862 Set_Suppress_Elaboration_Warnings (Ent);
11869 -- pragma Pure_05 [(library_unit_NAME)];
11871 -- This pragma is useable only in GNAT_Mode, where it is used like
11872 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11873 -- it is ignored). It may be used after a pragma Preelaborate, in
11874 -- which case it overrides the effect of the pragma Preelaborate.
11875 -- This is used to implement AI-362 which recategorizes some run-time
11876 -- packages in Ada 2005 mode.
11878 when Pragma_Pure_05 => Pure_05 : declare
11883 Check_Valid_Library_Unit_Pragma;
11885 if not GNAT_Mode then
11886 Error_Pragma ("pragma% only available in GNAT mode");
11889 if Nkind (N) = N_Null_Statement then
11893 -- This is one of the few cases where we need to test the value of
11894 -- Ada_Version_Explicit rather than Ada_Version (which is always
11895 -- set to Ada_2012 in a predefined unit), we need to know the
11896 -- explicit version set to know if this pragma is active.
11898 if Ada_Version_Explicit >= Ada_2005 then
11899 Ent := Find_Lib_Unit_Name;
11900 Set_Is_Preelaborated (Ent, False);
11902 Set_Suppress_Elaboration_Warnings (Ent);
11906 -------------------
11907 -- Pure_Function --
11908 -------------------
11910 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
11912 when Pragma_Pure_Function => Pure_Function : declare
11915 Def_Id : Entity_Id;
11916 Effective : Boolean := False;
11920 Check_Arg_Count (1);
11921 Check_Optional_Identifier (Arg1, Name_Entity);
11922 Check_Arg_Is_Local_Name (Arg1);
11923 E_Id := Get_Pragma_Arg (Arg1);
11925 if Error_Posted (E_Id) then
11929 -- Loop through homonyms (overloadings) of referenced entity
11931 E := Entity (E_Id);
11933 if Present (E) then
11935 Def_Id := Get_Base_Subprogram (E);
11937 if not Ekind_In (Def_Id, E_Function,
11938 E_Generic_Function,
11942 ("pragma% requires a function name", Arg1);
11945 Set_Is_Pure (Def_Id);
11947 if not Has_Pragma_Pure_Function (Def_Id) then
11948 Set_Has_Pragma_Pure_Function (Def_Id);
11952 exit when From_Aspect_Specification (N);
11954 exit when No (E) or else Scope (E) /= Current_Scope;
11958 and then Warn_On_Redundant_Constructs
11961 ("pragma Pure_Function on& is redundant?",
11967 --------------------
11968 -- Queuing_Policy --
11969 --------------------
11971 -- pragma Queuing_Policy (policy_IDENTIFIER);
11973 when Pragma_Queuing_Policy => declare
11977 Check_Ada_83_Warning;
11978 Check_Arg_Count (1);
11979 Check_No_Identifiers;
11980 Check_Arg_Is_Queuing_Policy (Arg1);
11981 Check_Valid_Configuration_Pragma;
11982 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11983 QP := Fold_Upper (Name_Buffer (1));
11985 if Queuing_Policy /= ' '
11986 and then Queuing_Policy /= QP
11988 Error_Msg_Sloc := Queuing_Policy_Sloc;
11989 Error_Pragma ("queuing policy incompatible with policy#");
11991 -- Set new policy, but always preserve System_Location since we
11992 -- like the error message with the run time name.
11995 Queuing_Policy := QP;
11997 if Queuing_Policy_Sloc /= System_Location then
11998 Queuing_Policy_Sloc := Loc;
12003 -----------------------
12004 -- Relative_Deadline --
12005 -----------------------
12007 -- pragma Relative_Deadline (time_span_EXPRESSION);
12009 when Pragma_Relative_Deadline => Relative_Deadline : declare
12010 P : constant Node_Id := Parent (N);
12015 Check_No_Identifiers;
12016 Check_Arg_Count (1);
12018 Arg := Get_Pragma_Arg (Arg1);
12020 -- The expression must be analyzed in the special manner described
12021 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12023 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12027 if Nkind (P) = N_Subprogram_Body then
12028 Check_In_Main_Program;
12032 elsif Nkind (P) = N_Task_Definition then
12035 -- Anything else is incorrect
12041 if Has_Relative_Deadline_Pragma (P) then
12042 Error_Pragma ("duplicate pragma% not allowed");
12044 Set_Has_Relative_Deadline_Pragma (P, True);
12046 if Nkind (P) = N_Task_Definition then
12047 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12050 end Relative_Deadline;
12052 ---------------------------
12053 -- Remote_Call_Interface --
12054 ---------------------------
12056 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12058 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12059 Cunit_Node : Node_Id;
12060 Cunit_Ent : Entity_Id;
12064 Check_Ada_83_Warning;
12065 Check_Valid_Library_Unit_Pragma;
12067 if Nkind (N) = N_Null_Statement then
12071 Cunit_Node := Cunit (Current_Sem_Unit);
12072 K := Nkind (Unit (Cunit_Node));
12073 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12075 if K = N_Package_Declaration
12076 or else K = N_Generic_Package_Declaration
12077 or else K = N_Subprogram_Declaration
12078 or else K = N_Generic_Subprogram_Declaration
12079 or else (K = N_Subprogram_Body
12080 and then Acts_As_Spec (Unit (Cunit_Node)))
12085 "pragma% must apply to package or subprogram declaration");
12088 Set_Is_Remote_Call_Interface (Cunit_Ent);
12089 end Remote_Call_Interface;
12095 -- pragma Remote_Types [(library_unit_NAME)];
12097 when Pragma_Remote_Types => Remote_Types : declare
12098 Cunit_Node : Node_Id;
12099 Cunit_Ent : Entity_Id;
12102 Check_Ada_83_Warning;
12103 Check_Valid_Library_Unit_Pragma;
12105 if Nkind (N) = N_Null_Statement then
12109 Cunit_Node := Cunit (Current_Sem_Unit);
12110 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12112 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12113 N_Generic_Package_Declaration)
12116 ("pragma% can only apply to a package declaration");
12119 Set_Is_Remote_Types (Cunit_Ent);
12126 -- pragma Ravenscar;
12128 when Pragma_Ravenscar =>
12130 Check_Arg_Count (0);
12131 Check_Valid_Configuration_Pragma;
12132 Set_Ravenscar_Profile (N);
12134 if Warn_On_Obsolescent_Feature then
12135 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12136 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12139 -------------------------
12140 -- Restricted_Run_Time --
12141 -------------------------
12143 -- pragma Restricted_Run_Time;
12145 when Pragma_Restricted_Run_Time =>
12147 Check_Arg_Count (0);
12148 Check_Valid_Configuration_Pragma;
12149 Set_Profile_Restrictions
12150 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12152 if Warn_On_Obsolescent_Feature then
12154 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12155 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12162 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12165 -- restriction_IDENTIFIER
12166 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12168 when Pragma_Restrictions =>
12169 Process_Restrictions_Or_Restriction_Warnings
12170 (Warn => Treat_Restrictions_As_Warnings);
12172 --------------------------
12173 -- Restriction_Warnings --
12174 --------------------------
12176 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12179 -- restriction_IDENTIFIER
12180 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12182 when Pragma_Restriction_Warnings =>
12184 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12190 -- pragma Reviewable;
12192 when Pragma_Reviewable =>
12193 Check_Ada_83_Warning;
12194 Check_Arg_Count (0);
12196 -- Call dummy debugging function rv. This is done to assist front
12197 -- end debugging. By placing a Reviewable pragma in the source
12198 -- program, a breakpoint on rv catches this place in the source,
12199 -- allowing convenient stepping to the point of interest.
12203 --------------------------
12204 -- Short_Circuit_And_Or --
12205 --------------------------
12207 when Pragma_Short_Circuit_And_Or =>
12209 Check_Arg_Count (0);
12210 Check_Valid_Configuration_Pragma;
12211 Short_Circuit_And_Or := True;
12213 -------------------
12214 -- Share_Generic --
12215 -------------------
12217 -- pragma Share_Generic (NAME {, NAME});
12219 when Pragma_Share_Generic =>
12221 Process_Generic_List;
12227 -- pragma Shared (LOCAL_NAME);
12229 when Pragma_Shared =>
12231 Process_Atomic_Shared_Volatile;
12233 --------------------
12234 -- Shared_Passive --
12235 --------------------
12237 -- pragma Shared_Passive [(library_unit_NAME)];
12239 -- Set the flag Is_Shared_Passive of program unit name entity
12241 when Pragma_Shared_Passive => Shared_Passive : declare
12242 Cunit_Node : Node_Id;
12243 Cunit_Ent : Entity_Id;
12246 Check_Ada_83_Warning;
12247 Check_Valid_Library_Unit_Pragma;
12249 if Nkind (N) = N_Null_Statement then
12253 Cunit_Node := Cunit (Current_Sem_Unit);
12254 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12256 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12257 N_Generic_Package_Declaration)
12260 ("pragma% can only apply to a package declaration");
12263 Set_Is_Shared_Passive (Cunit_Ent);
12264 end Shared_Passive;
12266 -----------------------
12267 -- Short_Descriptors --
12268 -----------------------
12270 -- pragma Short_Descriptors;
12272 when Pragma_Short_Descriptors =>
12274 Check_Arg_Count (0);
12275 Check_Valid_Configuration_Pragma;
12276 Short_Descriptors := True;
12278 ----------------------
12279 -- Source_File_Name --
12280 ----------------------
12282 -- There are five forms for this pragma:
12284 -- pragma Source_File_Name (
12285 -- [UNIT_NAME =>] unit_NAME,
12286 -- BODY_FILE_NAME => STRING_LITERAL
12287 -- [, [INDEX =>] INTEGER_LITERAL]);
12289 -- pragma Source_File_Name (
12290 -- [UNIT_NAME =>] unit_NAME,
12291 -- SPEC_FILE_NAME => STRING_LITERAL
12292 -- [, [INDEX =>] INTEGER_LITERAL]);
12294 -- pragma Source_File_Name (
12295 -- BODY_FILE_NAME => STRING_LITERAL
12296 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12297 -- [, CASING => CASING_SPEC]);
12299 -- pragma Source_File_Name (
12300 -- SPEC_FILE_NAME => STRING_LITERAL
12301 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12302 -- [, CASING => CASING_SPEC]);
12304 -- pragma Source_File_Name (
12305 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12306 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12307 -- [, CASING => CASING_SPEC]);
12309 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12311 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12312 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12313 -- only be used when no project file is used, while SFNP can only be
12314 -- used when a project file is used.
12316 -- No processing here. Processing was completed during parsing, since
12317 -- we need to have file names set as early as possible. Units are
12318 -- loaded well before semantic processing starts.
12320 -- The only processing we defer to this point is the check for
12321 -- correct placement.
12323 when Pragma_Source_File_Name =>
12325 Check_Valid_Configuration_Pragma;
12327 ------------------------------
12328 -- Source_File_Name_Project --
12329 ------------------------------
12331 -- See Source_File_Name for syntax
12333 -- No processing here. Processing was completed during parsing, since
12334 -- we need to have file names set as early as possible. Units are
12335 -- loaded well before semantic processing starts.
12337 -- The only processing we defer to this point is the check for
12338 -- correct placement.
12340 when Pragma_Source_File_Name_Project =>
12342 Check_Valid_Configuration_Pragma;
12344 -- Check that a pragma Source_File_Name_Project is used only in a
12345 -- configuration pragmas file.
12347 -- Pragmas Source_File_Name_Project should only be generated by
12348 -- the Project Manager in configuration pragmas files.
12350 -- This is really an ugly test. It seems to depend on some
12351 -- accidental and undocumented property. At the very least it
12352 -- needs to be documented, but it would be better to have a
12353 -- clean way of testing if we are in a configuration file???
12355 if Present (Parent (N)) then
12357 ("pragma% can only appear in a configuration pragmas file");
12360 ----------------------
12361 -- Source_Reference --
12362 ----------------------
12364 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12366 -- Nothing to do, all processing completed in Par.Prag, since we need
12367 -- the information for possible parser messages that are output.
12369 when Pragma_Source_Reference =>
12372 --------------------------------
12373 -- Static_Elaboration_Desired --
12374 --------------------------------
12376 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12378 when Pragma_Static_Elaboration_Desired =>
12380 Check_At_Most_N_Arguments (1);
12382 if Is_Compilation_Unit (Current_Scope)
12383 and then Ekind (Current_Scope) = E_Package
12385 Set_Static_Elaboration_Desired (Current_Scope, True);
12387 Error_Pragma ("pragma% must apply to a library-level package");
12394 -- pragma Storage_Size (EXPRESSION);
12396 when Pragma_Storage_Size => Storage_Size : declare
12397 P : constant Node_Id := Parent (N);
12401 Check_No_Identifiers;
12402 Check_Arg_Count (1);
12404 -- The expression must be analyzed in the special manner described
12405 -- in "Handling of Default Expressions" in sem.ads.
12407 Arg := Get_Pragma_Arg (Arg1);
12408 Preanalyze_Spec_Expression (Arg, Any_Integer);
12410 if not Is_Static_Expression (Arg) then
12411 Check_Restriction (Static_Storage_Size, Arg);
12414 if Nkind (P) /= N_Task_Definition then
12419 if Has_Storage_Size_Pragma (P) then
12420 Error_Pragma ("duplicate pragma% not allowed");
12422 Set_Has_Storage_Size_Pragma (P, True);
12425 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12426 -- ??? exp_ch9 should use this!
12434 -- pragma Storage_Unit (NUMERIC_LITERAL);
12436 -- Only permitted argument is System'Storage_Unit value
12438 when Pragma_Storage_Unit =>
12439 Check_No_Identifiers;
12440 Check_Arg_Count (1);
12441 Check_Arg_Is_Integer_Literal (Arg1);
12443 if Intval (Get_Pragma_Arg (Arg1)) /=
12444 UI_From_Int (Ttypes.System_Storage_Unit)
12446 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12448 ("the only allowed argument for pragma% is ^", Arg1);
12451 --------------------
12452 -- Stream_Convert --
12453 --------------------
12455 -- pragma Stream_Convert (
12456 -- [Entity =>] type_LOCAL_NAME,
12457 -- [Read =>] function_NAME,
12458 -- [Write =>] function NAME);
12460 when Pragma_Stream_Convert => Stream_Convert : declare
12462 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12463 -- Check that the given argument is the name of a local function
12464 -- of one argument that is not overloaded earlier in the current
12465 -- local scope. A check is also made that the argument is a
12466 -- function with one parameter.
12468 --------------------------------------
12469 -- Check_OK_Stream_Convert_Function --
12470 --------------------------------------
12472 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12476 Check_Arg_Is_Local_Name (Arg);
12477 Ent := Entity (Get_Pragma_Arg (Arg));
12479 if Has_Homonym (Ent) then
12481 ("argument for pragma% may not be overloaded", Arg);
12484 if Ekind (Ent) /= E_Function
12485 or else No (First_Formal (Ent))
12486 or else Present (Next_Formal (First_Formal (Ent)))
12489 ("argument for pragma% must be" &
12490 " function of one argument", Arg);
12492 end Check_OK_Stream_Convert_Function;
12494 -- Start of processing for Stream_Convert
12498 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12499 Check_Arg_Count (3);
12500 Check_Optional_Identifier (Arg1, Name_Entity);
12501 Check_Optional_Identifier (Arg2, Name_Read);
12502 Check_Optional_Identifier (Arg3, Name_Write);
12503 Check_Arg_Is_Local_Name (Arg1);
12504 Check_OK_Stream_Convert_Function (Arg2);
12505 Check_OK_Stream_Convert_Function (Arg3);
12508 Typ : constant Entity_Id :=
12509 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12510 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12511 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12514 Check_First_Subtype (Arg1);
12516 -- Check for too early or too late. Note that we don't enforce
12517 -- the rule about primitive operations in this case, since, as
12518 -- is the case for explicit stream attributes themselves, these
12519 -- restrictions are not appropriate. Note that the chaining of
12520 -- the pragma by Rep_Item_Too_Late is actually the critical
12521 -- processing done for this pragma.
12523 if Rep_Item_Too_Early (Typ, N)
12525 Rep_Item_Too_Late (Typ, N, FOnly => True)
12530 -- Return if previous error
12532 if Etype (Typ) = Any_Type
12534 Etype (Read) = Any_Type
12536 Etype (Write) = Any_Type
12543 if Underlying_Type (Etype (Read)) /= Typ then
12545 ("incorrect return type for function&", Arg2);
12548 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12550 ("incorrect parameter type for function&", Arg3);
12553 if Underlying_Type (Etype (First_Formal (Read))) /=
12554 Underlying_Type (Etype (Write))
12557 ("result type of & does not match Read parameter type",
12561 end Stream_Convert;
12563 -------------------------
12564 -- Style_Checks (GNAT) --
12565 -------------------------
12567 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12569 -- This is processed by the parser since some of the style checks
12570 -- take place during source scanning and parsing. This means that
12571 -- we don't need to issue error messages here.
12573 when Pragma_Style_Checks => Style_Checks : declare
12574 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12580 Check_No_Identifiers;
12582 -- Two argument form
12584 if Arg_Count = 2 then
12585 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12592 E_Id := Get_Pragma_Arg (Arg2);
12595 if not Is_Entity_Name (E_Id) then
12597 ("second argument of pragma% must be entity name",
12601 E := Entity (E_Id);
12607 Set_Suppress_Style_Checks (E,
12608 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12609 exit when No (Homonym (E));
12615 -- One argument form
12618 Check_Arg_Count (1);
12620 if Nkind (A) = N_String_Literal then
12624 Slen : constant Natural := Natural (String_Length (S));
12625 Options : String (1 .. Slen);
12631 C := Get_String_Char (S, Int (J));
12632 exit when not In_Character_Range (C);
12633 Options (J) := Get_Character (C);
12635 -- If at end of string, set options. As per discussion
12636 -- above, no need to check for errors, since we issued
12637 -- them in the parser.
12640 Set_Style_Check_Options (Options);
12648 elsif Nkind (A) = N_Identifier then
12649 if Chars (A) = Name_All_Checks then
12651 Set_GNAT_Style_Check_Options;
12653 Set_Default_Style_Check_Options;
12656 elsif Chars (A) = Name_On then
12657 Style_Check := True;
12659 elsif Chars (A) = Name_Off then
12660 Style_Check := False;
12670 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12672 when Pragma_Subtitle =>
12674 Check_Arg_Count (1);
12675 Check_Optional_Identifier (Arg1, Name_Subtitle);
12676 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12683 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12685 when Pragma_Suppress =>
12686 Process_Suppress_Unsuppress (True);
12692 -- pragma Suppress_All;
12694 -- The only check made here is that the pragma has no arguments.
12695 -- There are no placement rules, and the processing required (setting
12696 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12697 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12698 -- then creates and inserts a pragma Suppress (All_Checks).
12700 when Pragma_Suppress_All =>
12702 Check_Arg_Count (0);
12704 -------------------------
12705 -- Suppress_Debug_Info --
12706 -------------------------
12708 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12710 when Pragma_Suppress_Debug_Info =>
12712 Check_Arg_Count (1);
12713 Check_Optional_Identifier (Arg1, Name_Entity);
12714 Check_Arg_Is_Local_Name (Arg1);
12715 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12717 ----------------------------------
12718 -- Suppress_Exception_Locations --
12719 ----------------------------------
12721 -- pragma Suppress_Exception_Locations;
12723 when Pragma_Suppress_Exception_Locations =>
12725 Check_Arg_Count (0);
12726 Check_Valid_Configuration_Pragma;
12727 Exception_Locations_Suppressed := True;
12729 -----------------------------
12730 -- Suppress_Initialization --
12731 -----------------------------
12733 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12735 when Pragma_Suppress_Initialization => Suppress_Init : declare
12741 Check_Arg_Count (1);
12742 Check_Optional_Identifier (Arg1, Name_Entity);
12743 Check_Arg_Is_Local_Name (Arg1);
12745 E_Id := Get_Pragma_Arg (Arg1);
12747 if Etype (E_Id) = Any_Type then
12751 E := Entity (E_Id);
12753 if not Is_Type (E) then
12754 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
12757 if Rep_Item_Too_Early (E, N)
12759 Rep_Item_Too_Late (E, N, FOnly => True)
12764 -- For incomplete/private type, set flag on full view
12766 if Is_Incomplete_Or_Private_Type (E) then
12767 if No (Full_View (Base_Type (E))) then
12769 ("argument of pragma% cannot be an incomplete type", Arg1);
12771 Set_Suppress_Initialization (Full_View (Base_Type (E)));
12774 -- For first subtype, set flag on base type
12776 elsif Is_First_Subtype (E) then
12777 Set_Suppress_Initialization (Base_Type (E));
12779 -- For other than first subtype, set flag on subtype itself
12782 Set_Suppress_Initialization (E);
12790 -- pragma System_Name (DIRECT_NAME);
12792 -- Syntax check: one argument, which must be the identifier GNAT or
12793 -- the identifier GCC, no other identifiers are acceptable.
12795 when Pragma_System_Name =>
12797 Check_No_Identifiers;
12798 Check_Arg_Count (1);
12799 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12801 -----------------------------
12802 -- Task_Dispatching_Policy --
12803 -----------------------------
12805 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12807 when Pragma_Task_Dispatching_Policy => declare
12811 Check_Ada_83_Warning;
12812 Check_Arg_Count (1);
12813 Check_No_Identifiers;
12814 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12815 Check_Valid_Configuration_Pragma;
12816 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12817 DP := Fold_Upper (Name_Buffer (1));
12819 if Task_Dispatching_Policy /= ' '
12820 and then Task_Dispatching_Policy /= DP
12822 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12824 ("task dispatching policy incompatible with policy#");
12826 -- Set new policy, but always preserve System_Location since we
12827 -- like the error message with the run time name.
12830 Task_Dispatching_Policy := DP;
12832 if Task_Dispatching_Policy_Sloc /= System_Location then
12833 Task_Dispatching_Policy_Sloc := Loc;
12842 -- pragma Task_Info (EXPRESSION);
12844 when Pragma_Task_Info => Task_Info : declare
12845 P : constant Node_Id := Parent (N);
12850 if Nkind (P) /= N_Task_Definition then
12851 Error_Pragma ("pragma% must appear in task definition");
12854 Check_No_Identifiers;
12855 Check_Arg_Count (1);
12857 Analyze_And_Resolve
12858 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12860 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12864 if Has_Task_Info_Pragma (P) then
12865 Error_Pragma ("duplicate pragma% not allowed");
12867 Set_Has_Task_Info_Pragma (P, True);
12875 -- pragma Task_Name (string_EXPRESSION);
12877 when Pragma_Task_Name => Task_Name : declare
12878 P : constant Node_Id := Parent (N);
12882 Check_No_Identifiers;
12883 Check_Arg_Count (1);
12885 Arg := Get_Pragma_Arg (Arg1);
12887 -- The expression is used in the call to Create_Task, and must be
12888 -- expanded there, not in the context of the current spec. It must
12889 -- however be analyzed to capture global references, in case it
12890 -- appears in a generic context.
12892 Preanalyze_And_Resolve (Arg, Standard_String);
12894 if Nkind (P) /= N_Task_Definition then
12898 if Has_Task_Name_Pragma (P) then
12899 Error_Pragma ("duplicate pragma% not allowed");
12901 Set_Has_Task_Name_Pragma (P, True);
12902 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12910 -- pragma Task_Storage (
12911 -- [Task_Type =>] LOCAL_NAME,
12912 -- [Top_Guard =>] static_integer_EXPRESSION);
12914 when Pragma_Task_Storage => Task_Storage : declare
12915 Args : Args_List (1 .. 2);
12916 Names : constant Name_List (1 .. 2) := (
12920 Task_Type : Node_Id renames Args (1);
12921 Top_Guard : Node_Id renames Args (2);
12927 Gather_Associations (Names, Args);
12929 if No (Task_Type) then
12931 ("missing task_type argument for pragma%");
12934 Check_Arg_Is_Local_Name (Task_Type);
12936 Ent := Entity (Task_Type);
12938 if not Is_Task_Type (Ent) then
12940 ("argument for pragma% must be task type", Task_Type);
12943 if No (Top_Guard) then
12945 ("pragma% takes two arguments", Task_Type);
12947 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
12950 Check_First_Subtype (Task_Type);
12952 if Rep_Item_Too_Late (Ent, N) then
12957 --------------------------
12958 -- Thread_Local_Storage --
12959 --------------------------
12961 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
12963 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
12969 Check_Arg_Count (1);
12970 Check_Optional_Identifier (Arg1, Name_Entity);
12971 Check_Arg_Is_Library_Level_Local_Name (Arg1);
12973 Id := Get_Pragma_Arg (Arg1);
12976 if not Is_Entity_Name (Id)
12977 or else Ekind (Entity (Id)) /= E_Variable
12979 Error_Pragma_Arg ("local variable name required", Arg1);
12984 if Rep_Item_Too_Early (E, N)
12985 or else Rep_Item_Too_Late (E, N)
12990 Set_Has_Pragma_Thread_Local_Storage (E);
12991 Set_Has_Gigi_Rep_Item (E);
12992 end Thread_Local_Storage;
12998 -- pragma Time_Slice (static_duration_EXPRESSION);
13000 when Pragma_Time_Slice => Time_Slice : declare
13006 Check_Arg_Count (1);
13007 Check_No_Identifiers;
13008 Check_In_Main_Program;
13009 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13011 if not Error_Posted (Arg1) then
13013 while Present (Nod) loop
13014 if Nkind (Nod) = N_Pragma
13015 and then Pragma_Name (Nod) = Name_Time_Slice
13017 Error_Msg_Name_1 := Pname;
13018 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13025 -- Process only if in main unit
13027 if Get_Source_Unit (Loc) = Main_Unit then
13028 Opt.Time_Slice_Set := True;
13029 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13031 if Val <= Ureal_0 then
13032 Opt.Time_Slice_Value := 0;
13034 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13035 Opt.Time_Slice_Value := 1_000_000_000;
13038 Opt.Time_Slice_Value :=
13039 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13048 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13050 -- TITLING_OPTION ::=
13051 -- [Title =>] STRING_LITERAL
13052 -- | [Subtitle =>] STRING_LITERAL
13054 when Pragma_Title => Title : declare
13055 Args : Args_List (1 .. 2);
13056 Names : constant Name_List (1 .. 2) := (
13062 Gather_Associations (Names, Args);
13065 for J in 1 .. 2 loop
13066 if Present (Args (J)) then
13067 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13072 ---------------------
13073 -- Unchecked_Union --
13074 ---------------------
13076 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13078 when Pragma_Unchecked_Union => Unchecked_Union : declare
13079 Assoc : constant Node_Id := Arg1;
13080 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13091 Check_No_Identifiers;
13092 Check_Arg_Count (1);
13093 Check_Arg_Is_Local_Name (Arg1);
13095 Find_Type (Type_Id);
13096 Typ := Entity (Type_Id);
13099 or else Rep_Item_Too_Early (Typ, N)
13103 Typ := Underlying_Type (Typ);
13106 if Rep_Item_Too_Late (Typ, N) then
13110 Check_First_Subtype (Arg1);
13112 -- Note remaining cases are references to a type in the current
13113 -- declarative part. If we find an error, we post the error on
13114 -- the relevant type declaration at an appropriate point.
13116 if not Is_Record_Type (Typ) then
13117 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13120 elsif Is_Tagged_Type (Typ) then
13121 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13124 elsif Is_Limited_Type (Typ) then
13126 ("Unchecked_Union must not be limited record type", Typ);
13127 Explain_Limited_Type (Typ, Typ);
13131 if not Has_Discriminants (Typ) then
13133 ("Unchecked_Union must have one discriminant", Typ);
13137 Discr := First_Discriminant (Typ);
13138 while Present (Discr) loop
13139 if No (Discriminant_Default_Value (Discr)) then
13141 ("Unchecked_Union discriminant must have default value",
13145 Next_Discriminant (Discr);
13148 Tdef := Type_Definition (Declaration_Node (Typ));
13149 Clist := Component_List (Tdef);
13151 Comp := First (Component_Items (Clist));
13152 while Present (Comp) loop
13153 Check_Component (Comp, Typ);
13157 if No (Clist) or else No (Variant_Part (Clist)) then
13159 ("Unchecked_Union must have variant part",
13164 Vpart := Variant_Part (Clist);
13166 Variant := First (Variants (Vpart));
13167 while Present (Variant) loop
13168 Check_Variant (Variant, Typ);
13173 Set_Is_Unchecked_Union (Typ);
13174 Set_Convention (Typ, Convention_C);
13175 Set_Has_Unchecked_Union (Base_Type (Typ));
13176 Set_Is_Unchecked_Union (Base_Type (Typ));
13177 end Unchecked_Union;
13179 ------------------------
13180 -- Unimplemented_Unit --
13181 ------------------------
13183 -- pragma Unimplemented_Unit;
13185 -- Note: this only gives an error if we are generating code, or if
13186 -- we are in a generic library unit (where the pragma appears in the
13187 -- body, not in the spec).
13189 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13190 Cunitent : constant Entity_Id :=
13191 Cunit_Entity (Get_Source_Unit (Loc));
13192 Ent_Kind : constant Entity_Kind :=
13197 Check_Arg_Count (0);
13199 if Operating_Mode = Generate_Code
13200 or else Ent_Kind = E_Generic_Function
13201 or else Ent_Kind = E_Generic_Procedure
13202 or else Ent_Kind = E_Generic_Package
13204 Get_Name_String (Chars (Cunitent));
13205 Set_Casing (Mixed_Case);
13206 Write_Str (Name_Buffer (1 .. Name_Len));
13207 Write_Str (" is not supported in this configuration");
13209 raise Unrecoverable_Error;
13211 end Unimplemented_Unit;
13213 ------------------------
13214 -- Universal_Aliasing --
13215 ------------------------
13217 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13219 when Pragma_Universal_Aliasing => Universal_Alias : declare
13224 Check_Arg_Count (1);
13225 Check_Optional_Identifier (Arg2, Name_Entity);
13226 Check_Arg_Is_Local_Name (Arg1);
13227 E_Id := Entity (Get_Pragma_Arg (Arg1));
13229 if E_Id = Any_Type then
13231 elsif No (E_Id) or else not Is_Type (E_Id) then
13232 Error_Pragma_Arg ("pragma% requires type", Arg1);
13235 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13236 end Universal_Alias;
13238 --------------------
13239 -- Universal_Data --
13240 --------------------
13242 -- pragma Universal_Data [(library_unit_NAME)];
13244 when Pragma_Universal_Data =>
13247 -- If this is a configuration pragma, then set the universal
13248 -- addressing option, otherwise confirm that the pragma satisfies
13249 -- the requirements of library unit pragma placement and leave it
13250 -- to the GNAAMP back end to detect the pragma (avoids transitive
13251 -- setting of the option due to withed units).
13253 if Is_Configuration_Pragma then
13254 Universal_Addressing_On_AAMP := True;
13256 Check_Valid_Library_Unit_Pragma;
13259 if not AAMP_On_Target then
13260 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13267 -- pragma Unmodified (local_Name {, local_Name});
13269 when Pragma_Unmodified => Unmodified : declare
13270 Arg_Node : Node_Id;
13271 Arg_Expr : Node_Id;
13272 Arg_Ent : Entity_Id;
13276 Check_At_Least_N_Arguments (1);
13278 -- Loop through arguments
13281 while Present (Arg_Node) loop
13282 Check_No_Identifier (Arg_Node);
13284 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13285 -- in fact generate reference, so that the entity will have a
13286 -- reference, which will inhibit any warnings about it not
13287 -- being referenced, and also properly show up in the ali file
13288 -- as a reference. But this reference is recorded before the
13289 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13290 -- generated for this reference.
13292 Check_Arg_Is_Local_Name (Arg_Node);
13293 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13295 if Is_Entity_Name (Arg_Expr) then
13296 Arg_Ent := Entity (Arg_Expr);
13298 if not Is_Assignable (Arg_Ent) then
13300 ("pragma% can only be applied to a variable",
13303 Set_Has_Pragma_Unmodified (Arg_Ent);
13315 -- pragma Unreferenced (local_Name {, local_Name});
13317 -- or when used in a context clause:
13319 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13321 when Pragma_Unreferenced => Unreferenced : declare
13322 Arg_Node : Node_Id;
13323 Arg_Expr : Node_Id;
13324 Arg_Ent : Entity_Id;
13329 Check_At_Least_N_Arguments (1);
13331 -- Check case of appearing within context clause
13333 if Is_In_Context_Clause then
13335 -- The arguments must all be units mentioned in a with clause
13336 -- in the same context clause. Note we already checked (in
13337 -- Par.Prag) that the arguments are either identifiers or
13338 -- selected components.
13341 while Present (Arg_Node) loop
13342 Citem := First (List_Containing (N));
13343 while Citem /= N loop
13344 if Nkind (Citem) = N_With_Clause
13346 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13348 Set_Has_Pragma_Unreferenced
13351 (Library_Unit (Citem))));
13353 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13362 ("argument of pragma% is not with'ed unit", Arg_Node);
13368 -- Case of not in list of context items
13372 while Present (Arg_Node) loop
13373 Check_No_Identifier (Arg_Node);
13375 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13376 -- will in fact generate reference, so that the entity will
13377 -- have a reference, which will inhibit any warnings about
13378 -- it not being referenced, and also properly show up in the
13379 -- ali file as a reference. But this reference is recorded
13380 -- before the Has_Pragma_Unreferenced flag is set, so that
13381 -- no warning is generated for this reference.
13383 Check_Arg_Is_Local_Name (Arg_Node);
13384 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13386 if Is_Entity_Name (Arg_Expr) then
13387 Arg_Ent := Entity (Arg_Expr);
13389 -- If the entity is overloaded, the pragma applies to the
13390 -- most recent overloading, as documented. In this case,
13391 -- name resolution does not generate a reference, so it
13392 -- must be done here explicitly.
13394 if Is_Overloaded (Arg_Expr) then
13395 Generate_Reference (Arg_Ent, N);
13398 Set_Has_Pragma_Unreferenced (Arg_Ent);
13406 --------------------------
13407 -- Unreferenced_Objects --
13408 --------------------------
13410 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13412 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13413 Arg_Node : Node_Id;
13414 Arg_Expr : Node_Id;
13418 Check_At_Least_N_Arguments (1);
13421 while Present (Arg_Node) loop
13422 Check_No_Identifier (Arg_Node);
13423 Check_Arg_Is_Local_Name (Arg_Node);
13424 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13426 if not Is_Entity_Name (Arg_Expr)
13427 or else not Is_Type (Entity (Arg_Expr))
13430 ("argument for pragma% must be type or subtype", Arg_Node);
13433 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13436 end Unreferenced_Objects;
13438 ------------------------------
13439 -- Unreserve_All_Interrupts --
13440 ------------------------------
13442 -- pragma Unreserve_All_Interrupts;
13444 when Pragma_Unreserve_All_Interrupts =>
13446 Check_Arg_Count (0);
13448 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13449 Unreserve_All_Interrupts := True;
13456 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13458 when Pragma_Unsuppress =>
13460 Process_Suppress_Unsuppress (False);
13462 -------------------
13463 -- Use_VADS_Size --
13464 -------------------
13466 -- pragma Use_VADS_Size;
13468 when Pragma_Use_VADS_Size =>
13470 Check_Arg_Count (0);
13471 Check_Valid_Configuration_Pragma;
13472 Use_VADS_Size := True;
13474 ---------------------
13475 -- Validity_Checks --
13476 ---------------------
13478 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13480 when Pragma_Validity_Checks => Validity_Checks : declare
13481 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13487 Check_Arg_Count (1);
13488 Check_No_Identifiers;
13490 if Nkind (A) = N_String_Literal then
13494 Slen : constant Natural := Natural (String_Length (S));
13495 Options : String (1 .. Slen);
13501 C := Get_String_Char (S, Int (J));
13502 exit when not In_Character_Range (C);
13503 Options (J) := Get_Character (C);
13506 Set_Validity_Check_Options (Options);
13514 elsif Nkind (A) = N_Identifier then
13516 if Chars (A) = Name_All_Checks then
13517 Set_Validity_Check_Options ("a");
13519 elsif Chars (A) = Name_On then
13520 Validity_Checks_On := True;
13522 elsif Chars (A) = Name_Off then
13523 Validity_Checks_On := False;
13527 end Validity_Checks;
13533 -- pragma Volatile (LOCAL_NAME);
13535 when Pragma_Volatile =>
13536 Process_Atomic_Shared_Volatile;
13538 -------------------------
13539 -- Volatile_Components --
13540 -------------------------
13542 -- pragma Volatile_Components (array_LOCAL_NAME);
13544 -- Volatile is handled by the same circuit as Atomic_Components
13550 -- pragma Warnings (On | Off);
13551 -- pragma Warnings (On | Off, LOCAL_NAME);
13552 -- pragma Warnings (static_string_EXPRESSION);
13553 -- pragma Warnings (On | Off, STRING_LITERAL);
13555 when Pragma_Warnings => Warnings : begin
13557 Check_At_Least_N_Arguments (1);
13558 Check_No_Identifiers;
13560 -- If debug flag -gnatd.i is set, pragma is ignored
13562 if Debug_Flag_Dot_I then
13566 -- Process various forms of the pragma
13569 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13572 -- One argument case
13574 if Arg_Count = 1 then
13576 -- On/Off one argument case was processed by parser
13578 if Nkind (Argx) = N_Identifier
13580 (Chars (Argx) = Name_On
13582 Chars (Argx) = Name_Off)
13586 -- One argument case must be ON/OFF or static string expr
13588 elsif not Is_Static_String_Expression (Arg1) then
13590 ("argument of pragma% must be On/Off or " &
13591 "static string expression", Arg1);
13593 -- One argument string expression case
13597 Lit : constant Node_Id := Expr_Value_S (Argx);
13598 Str : constant String_Id := Strval (Lit);
13599 Len : constant Nat := String_Length (Str);
13607 while J <= Len loop
13608 C := Get_String_Char (Str, J);
13609 OK := In_Character_Range (C);
13612 Chr := Get_Character (C);
13616 if J < Len and then Chr = '.' then
13618 C := Get_String_Char (Str, J);
13619 Chr := Get_Character (C);
13621 if not Set_Dot_Warning_Switch (Chr) then
13623 ("invalid warning switch character " &
13630 OK := Set_Warning_Switch (Chr);
13636 ("invalid warning switch character " & Chr,
13645 -- Two or more arguments (must be two)
13648 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13649 Check_At_Most_N_Arguments (2);
13657 E_Id := Get_Pragma_Arg (Arg2);
13660 -- In the expansion of an inlined body, a reference to
13661 -- the formal may be wrapped in a conversion if the
13662 -- actual is a conversion. Retrieve the real entity name.
13664 if (In_Instance_Body
13665 or else In_Inlined_Body)
13666 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13668 E_Id := Expression (E_Id);
13671 -- Entity name case
13673 if Is_Entity_Name (E_Id) then
13674 E := Entity (E_Id);
13681 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13684 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13685 and then Warn_On_Warnings_Off
13687 Warnings_Off_Pragmas.Append ((N, E));
13690 if Is_Enumeration_Type (E) then
13694 Lit := First_Literal (E);
13695 while Present (Lit) loop
13696 Set_Warnings_Off (Lit);
13697 Next_Literal (Lit);
13702 exit when No (Homonym (E));
13707 -- Error if not entity or static string literal case
13709 elsif not Is_Static_String_Expression (Arg2) then
13711 ("second argument of pragma% must be entity " &
13712 "name or static string expression", Arg2);
13714 -- String literal case
13717 String_To_Name_Buffer
13718 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13720 -- Note on configuration pragma case: If this is a
13721 -- configuration pragma, then for an OFF pragma, we
13722 -- just set Config True in the call, which is all
13723 -- that needs to be done. For the case of ON, this
13724 -- is normally an error, unless it is canceling the
13725 -- effect of a previous OFF pragma in the same file.
13726 -- In any other case, an error will be signalled (ON
13727 -- with no matching OFF).
13729 if Chars (Argx) = Name_Off then
13730 Set_Specific_Warning_Off
13731 (Loc, Name_Buffer (1 .. Name_Len),
13732 Config => Is_Configuration_Pragma);
13734 elsif Chars (Argx) = Name_On then
13735 Set_Specific_Warning_On
13736 (Loc, Name_Buffer (1 .. Name_Len), Err);
13740 ("?pragma Warnings On with no " &
13741 "matching Warnings Off",
13751 -------------------
13752 -- Weak_External --
13753 -------------------
13755 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13757 when Pragma_Weak_External => Weak_External : declare
13762 Check_Arg_Count (1);
13763 Check_Optional_Identifier (Arg1, Name_Entity);
13764 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13765 Ent := Entity (Get_Pragma_Arg (Arg1));
13767 if Rep_Item_Too_Early (Ent, N) then
13770 Ent := Underlying_Type (Ent);
13773 -- The only processing required is to link this item on to the
13774 -- list of rep items for the given entity. This is accomplished
13775 -- by the call to Rep_Item_Too_Late (when no error is detected
13776 -- and False is returned).
13778 if Rep_Item_Too_Late (Ent, N) then
13781 Set_Has_Gigi_Rep_Item (Ent);
13785 -----------------------------
13786 -- Wide_Character_Encoding --
13787 -----------------------------
13789 -- pragma Wide_Character_Encoding (IDENTIFIER);
13791 when Pragma_Wide_Character_Encoding =>
13794 -- Nothing to do, handled in parser. Note that we do not enforce
13795 -- configuration pragma placement, this pragma can appear at any
13796 -- place in the source, allowing mixed encodings within a single
13801 --------------------
13802 -- Unknown_Pragma --
13803 --------------------
13805 -- Should be impossible, since the case of an unknown pragma is
13806 -- separately processed before the case statement is entered.
13808 when Unknown_Pragma =>
13809 raise Program_Error;
13812 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13813 -- until AI is formally approved.
13815 -- Check_Order_Dependence;
13818 when Pragma_Exit => null;
13819 end Analyze_Pragma;
13821 -------------------
13822 -- Check_Enabled --
13823 -------------------
13825 function Check_Enabled (Nam : Name_Id) return Boolean is
13829 -- Loop through entries in check policy list
13831 PP := Opt.Check_Policy_List;
13833 -- If there are no specific entries that matched, then we let the
13834 -- setting of assertions govern. Note that this provides the needed
13835 -- compatibility with the RM for the cases of assertion, invariant,
13836 -- precondition, predicate, and postcondition.
13839 return Assertions_Enabled;
13841 -- Here we have an entry see if it matches
13845 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13848 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13849 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13850 when Name_On | Name_Check =>
13852 when Name_Off | Name_Ignore =>
13855 raise Program_Error;
13859 PP := Next_Pragma (PP);
13866 ---------------------------------
13867 -- Delay_Config_Pragma_Analyze --
13868 ---------------------------------
13870 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13872 return Pragma_Name (N) = Name_Interrupt_State
13874 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13875 end Delay_Config_Pragma_Analyze;
13877 -------------------------
13878 -- Get_Base_Subprogram --
13879 -------------------------
13881 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13882 Result : Entity_Id;
13885 -- Follow subprogram renaming chain
13888 while Is_Subprogram (Result)
13890 (Is_Generic_Instance (Result)
13891 or else Nkind (Parent (Declaration_Node (Result))) =
13892 N_Subprogram_Renaming_Declaration)
13893 and then Present (Alias (Result))
13895 Result := Alias (Result);
13899 end Get_Base_Subprogram;
13905 procedure Initialize is
13910 -----------------------------
13911 -- Is_Config_Static_String --
13912 -----------------------------
13914 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13916 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
13917 -- This is an internal recursive function that is just like the outer
13918 -- function except that it adds the string to the name buffer rather
13919 -- than placing the string in the name buffer.
13921 ------------------------------
13922 -- Add_Config_Static_String --
13923 ------------------------------
13925 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
13932 if Nkind (N) = N_Op_Concat then
13933 if Add_Config_Static_String (Left_Opnd (N)) then
13934 N := Right_Opnd (N);
13940 if Nkind (N) /= N_String_Literal then
13941 Error_Msg_N ("string literal expected for pragma argument", N);
13945 for J in 1 .. String_Length (Strval (N)) loop
13946 C := Get_String_Char (Strval (N), J);
13948 if not In_Character_Range (C) then
13950 ("string literal contains invalid wide character",
13951 Sloc (N) + 1 + Source_Ptr (J));
13955 Add_Char_To_Name_Buffer (Get_Character (C));
13960 end Add_Config_Static_String;
13962 -- Start of processing for Is_Config_Static_String
13967 return Add_Config_Static_String (Arg);
13968 end Is_Config_Static_String;
13970 -----------------------------------------
13971 -- Is_Non_Significant_Pragma_Reference --
13972 -----------------------------------------
13974 -- This function makes use of the following static table which indicates
13975 -- whether a given pragma is significant.
13977 -- -1 indicates that references in any argument position are significant
13978 -- 0 indicates that appearance in any argument is not significant
13979 -- +n indicates that appearance as argument n is significant, but all
13980 -- other arguments are not significant
13981 -- 99 special processing required (e.g. for pragma Check)
13983 Sig_Flags : constant array (Pragma_Id) of Int :=
13984 (Pragma_AST_Entry => -1,
13985 Pragma_Abort_Defer => -1,
13986 Pragma_Ada_83 => -1,
13987 Pragma_Ada_95 => -1,
13988 Pragma_Ada_05 => -1,
13989 Pragma_Ada_2005 => -1,
13990 Pragma_Ada_12 => -1,
13991 Pragma_Ada_2012 => -1,
13992 Pragma_All_Calls_Remote => -1,
13993 Pragma_Annotate => -1,
13994 Pragma_Assert => -1,
13995 Pragma_Assertion_Policy => 0,
13996 Pragma_Assume_No_Invalid_Values => 0,
13997 Pragma_Asynchronous => -1,
13998 Pragma_Atomic => 0,
13999 Pragma_Atomic_Components => 0,
14000 Pragma_Attach_Handler => -1,
14001 Pragma_Check => 99,
14002 Pragma_Check_Name => 0,
14003 Pragma_Check_Policy => 0,
14004 Pragma_CIL_Constructor => -1,
14005 Pragma_CPP_Class => 0,
14006 Pragma_CPP_Constructor => 0,
14007 Pragma_CPP_Virtual => 0,
14008 Pragma_CPP_Vtable => 0,
14010 Pragma_C_Pass_By_Copy => 0,
14011 Pragma_Comment => 0,
14012 Pragma_Common_Object => -1,
14013 Pragma_Compile_Time_Error => -1,
14014 Pragma_Compile_Time_Warning => -1,
14015 Pragma_Compiler_Unit => 0,
14016 Pragma_Complete_Representation => 0,
14017 Pragma_Complex_Representation => 0,
14018 Pragma_Component_Alignment => -1,
14019 Pragma_Controlled => 0,
14020 Pragma_Convention => 0,
14021 Pragma_Convention_Identifier => 0,
14022 Pragma_Debug => -1,
14023 Pragma_Debug_Policy => 0,
14024 Pragma_Detect_Blocking => -1,
14025 Pragma_Default_Storage_Pool => -1,
14026 Pragma_Dimension => -1,
14027 Pragma_Discard_Names => 0,
14028 Pragma_Elaborate => -1,
14029 Pragma_Elaborate_All => -1,
14030 Pragma_Elaborate_Body => -1,
14031 Pragma_Elaboration_Checks => -1,
14032 Pragma_Eliminate => -1,
14033 Pragma_Export => -1,
14034 Pragma_Export_Exception => -1,
14035 Pragma_Export_Function => -1,
14036 Pragma_Export_Object => -1,
14037 Pragma_Export_Procedure => -1,
14038 Pragma_Export_Value => -1,
14039 Pragma_Export_Valued_Procedure => -1,
14040 Pragma_Extend_System => -1,
14041 Pragma_Extensions_Allowed => -1,
14042 Pragma_External => -1,
14043 Pragma_Favor_Top_Level => -1,
14044 Pragma_External_Name_Casing => -1,
14045 Pragma_Fast_Math => -1,
14046 Pragma_Finalize_Storage_Only => 0,
14047 Pragma_Float_Representation => 0,
14048 Pragma_Ident => -1,
14049 Pragma_Implemented => -1,
14050 Pragma_Implicit_Packing => 0,
14051 Pragma_Import => +2,
14052 Pragma_Import_Exception => 0,
14053 Pragma_Import_Function => 0,
14054 Pragma_Import_Object => 0,
14055 Pragma_Import_Procedure => 0,
14056 Pragma_Import_Valued_Procedure => 0,
14057 Pragma_Independent => 0,
14058 Pragma_Independent_Components => 0,
14059 Pragma_Initialize_Scalars => -1,
14060 Pragma_Inline => 0,
14061 Pragma_Inline_Always => 0,
14062 Pragma_Inline_Generic => 0,
14063 Pragma_Inspection_Point => -1,
14064 Pragma_Interface => +2,
14065 Pragma_Interface_Name => +2,
14066 Pragma_Interrupt_Handler => -1,
14067 Pragma_Interrupt_Priority => -1,
14068 Pragma_Interrupt_State => -1,
14069 Pragma_Invariant => -1,
14070 Pragma_Java_Constructor => -1,
14071 Pragma_Java_Interface => -1,
14072 Pragma_Keep_Names => 0,
14073 Pragma_License => -1,
14074 Pragma_Link_With => -1,
14075 Pragma_Linker_Alias => -1,
14076 Pragma_Linker_Constructor => -1,
14077 Pragma_Linker_Destructor => -1,
14078 Pragma_Linker_Options => -1,
14079 Pragma_Linker_Section => -1,
14081 Pragma_Locking_Policy => -1,
14082 Pragma_Long_Float => -1,
14083 Pragma_Machine_Attribute => -1,
14085 Pragma_Main_Storage => -1,
14086 Pragma_Memory_Size => -1,
14087 Pragma_No_Return => 0,
14088 Pragma_No_Body => 0,
14089 Pragma_No_Run_Time => -1,
14090 Pragma_No_Strict_Aliasing => -1,
14091 Pragma_Normalize_Scalars => -1,
14092 Pragma_Obsolescent => 0,
14093 Pragma_Optimize => -1,
14094 Pragma_Optimize_Alignment => -1,
14095 Pragma_Ordered => 0,
14098 Pragma_Passive => -1,
14099 Pragma_Preelaborable_Initialization => -1,
14100 Pragma_Polling => -1,
14101 Pragma_Persistent_BSS => 0,
14102 Pragma_Postcondition => -1,
14103 Pragma_Precondition => -1,
14104 Pragma_Predicate => -1,
14105 Pragma_Preelaborate => -1,
14106 Pragma_Preelaborate_05 => -1,
14107 Pragma_Priority => -1,
14108 Pragma_Priority_Specific_Dispatching => -1,
14109 Pragma_Profile => 0,
14110 Pragma_Profile_Warnings => 0,
14111 Pragma_Propagate_Exceptions => -1,
14112 Pragma_Psect_Object => -1,
14114 Pragma_Pure_05 => -1,
14115 Pragma_Pure_Function => -1,
14116 Pragma_Queuing_Policy => -1,
14117 Pragma_Ravenscar => -1,
14118 Pragma_Relative_Deadline => -1,
14119 Pragma_Remote_Call_Interface => -1,
14120 Pragma_Remote_Types => -1,
14121 Pragma_Restricted_Run_Time => -1,
14122 Pragma_Restriction_Warnings => -1,
14123 Pragma_Restrictions => -1,
14124 Pragma_Reviewable => -1,
14125 Pragma_Short_Circuit_And_Or => -1,
14126 Pragma_Share_Generic => -1,
14127 Pragma_Shared => -1,
14128 Pragma_Shared_Passive => -1,
14129 Pragma_Short_Descriptors => 0,
14130 Pragma_Source_File_Name => -1,
14131 Pragma_Source_File_Name_Project => -1,
14132 Pragma_Source_Reference => -1,
14133 Pragma_Storage_Size => -1,
14134 Pragma_Storage_Unit => -1,
14135 Pragma_Static_Elaboration_Desired => -1,
14136 Pragma_Stream_Convert => -1,
14137 Pragma_Style_Checks => -1,
14138 Pragma_Subtitle => -1,
14139 Pragma_Suppress => 0,
14140 Pragma_Suppress_Exception_Locations => 0,
14141 Pragma_Suppress_All => -1,
14142 Pragma_Suppress_Debug_Info => 0,
14143 Pragma_Suppress_Initialization => 0,
14144 Pragma_System_Name => -1,
14145 Pragma_Task_Dispatching_Policy => -1,
14146 Pragma_Task_Info => -1,
14147 Pragma_Task_Name => -1,
14148 Pragma_Task_Storage => 0,
14149 Pragma_Thread_Local_Storage => 0,
14150 Pragma_Time_Slice => -1,
14151 Pragma_Title => -1,
14152 Pragma_Unchecked_Union => 0,
14153 Pragma_Unimplemented_Unit => -1,
14154 Pragma_Universal_Aliasing => -1,
14155 Pragma_Universal_Data => -1,
14156 Pragma_Unmodified => -1,
14157 Pragma_Unreferenced => -1,
14158 Pragma_Unreferenced_Objects => -1,
14159 Pragma_Unreserve_All_Interrupts => -1,
14160 Pragma_Unsuppress => 0,
14161 Pragma_Use_VADS_Size => -1,
14162 Pragma_Validity_Checks => -1,
14163 Pragma_Volatile => 0,
14164 Pragma_Volatile_Components => 0,
14165 Pragma_Warnings => -1,
14166 Pragma_Weak_External => -1,
14167 Pragma_Wide_Character_Encoding => 0,
14168 Unknown_Pragma => 0);
14170 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14179 if Nkind (P) /= N_Pragma_Argument_Association then
14183 Id := Get_Pragma_Id (Parent (P));
14184 C := Sig_Flags (Id);
14196 -- For pragma Check, the first argument is not significant,
14197 -- the second and the third (if present) arguments are
14200 when Pragma_Check =>
14202 P = First (Pragma_Argument_Associations (Parent (P)));
14205 raise Program_Error;
14209 A := First (Pragma_Argument_Associations (Parent (P)));
14210 for J in 1 .. C - 1 loop
14218 return A = P; -- is this wrong way round ???
14221 end Is_Non_Significant_Pragma_Reference;
14223 ------------------------------
14224 -- Is_Pragma_String_Literal --
14225 ------------------------------
14227 -- This function returns true if the corresponding pragma argument is a
14228 -- static string expression. These are the only cases in which string
14229 -- literals can appear as pragma arguments. We also allow a string literal
14230 -- as the first argument to pragma Assert (although it will of course
14231 -- always generate a type error).
14233 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14234 Pragn : constant Node_Id := Parent (Par);
14235 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14236 Pname : constant Name_Id := Pragma_Name (Pragn);
14242 N := First (Assoc);
14249 if Pname = Name_Assert then
14252 elsif Pname = Name_Export then
14255 elsif Pname = Name_Ident then
14258 elsif Pname = Name_Import then
14261 elsif Pname = Name_Interface_Name then
14264 elsif Pname = Name_Linker_Alias then
14267 elsif Pname = Name_Linker_Section then
14270 elsif Pname = Name_Machine_Attribute then
14273 elsif Pname = Name_Source_File_Name then
14276 elsif Pname = Name_Source_Reference then
14279 elsif Pname = Name_Title then
14282 elsif Pname = Name_Subtitle then
14288 end Is_Pragma_String_Literal;
14290 --------------------------------------
14291 -- Process_Compilation_Unit_Pragmas --
14292 --------------------------------------
14294 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14296 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14297 -- strange because it comes at the end of the unit. Rational has the
14298 -- same name for a pragma, but treats it as a program unit pragma, In
14299 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14300 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14301 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14302 -- the context clause to ensure the correct processing.
14304 if Has_Pragma_Suppress_All (N) then
14305 Prepend_To (Context_Items (N),
14306 Make_Pragma (Sloc (N),
14307 Chars => Name_Suppress,
14308 Pragma_Argument_Associations => New_List (
14309 Make_Pragma_Argument_Association (Sloc (N),
14310 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14313 -- Nothing else to do at the current time!
14315 end Process_Compilation_Unit_Pragmas;
14326 --------------------------------
14327 -- Set_Encoded_Interface_Name --
14328 --------------------------------
14330 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14331 Str : constant String_Id := Strval (S);
14332 Len : constant Int := String_Length (Str);
14337 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14340 -- Stores encoded value of character code CC. The encoding we use an
14341 -- underscore followed by four lower case hex digits.
14347 procedure Encode is
14349 Store_String_Char (Get_Char_Code ('_'));
14351 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14353 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14355 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14357 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14360 -- Start of processing for Set_Encoded_Interface_Name
14363 -- If first character is asterisk, this is a link name, and we leave it
14364 -- completely unmodified. We also ignore null strings (the latter case
14365 -- happens only in error cases) and no encoding should occur for Java or
14366 -- AAMP interface names.
14369 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14370 or else VM_Target /= No_VM
14371 or else AAMP_On_Target
14373 Set_Interface_Name (E, S);
14378 CC := Get_String_Char (Str, J);
14380 exit when not In_Character_Range (CC);
14382 C := Get_Character (CC);
14384 exit when C /= '_' and then C /= '$'
14385 and then C not in '0' .. '9'
14386 and then C not in 'a' .. 'z'
14387 and then C not in 'A' .. 'Z';
14390 Set_Interface_Name (E, S);
14398 -- Here we need to encode. The encoding we use as follows:
14399 -- three underscores + four hex digits (lower case)
14403 for J in 1 .. String_Length (Str) loop
14404 CC := Get_String_Char (Str, J);
14406 if not In_Character_Range (CC) then
14409 C := Get_Character (CC);
14411 if C = '_' or else C = '$'
14412 or else C in '0' .. '9'
14413 or else C in 'a' .. 'z'
14414 or else C in 'A' .. 'Z'
14416 Store_String_Char (CC);
14423 Set_Interface_Name (E,
14424 Make_String_Literal (Sloc (S),
14425 Strval => End_String));
14427 end Set_Encoded_Interface_Name;
14429 -------------------
14430 -- Set_Unit_Name --
14431 -------------------
14433 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14438 if Nkind (N) = N_Identifier
14439 and then Nkind (With_Item) = N_Identifier
14441 Set_Entity (N, Entity (With_Item));
14443 elsif Nkind (N) = N_Selected_Component then
14444 Change_Selected_Component_To_Expanded_Name (N);
14445 Set_Entity (N, Entity (With_Item));
14446 Set_Entity (Selector_Name (N), Entity (N));
14448 Pref := Prefix (N);
14449 Scop := Scope (Entity (N));
14450 while Nkind (Pref) = N_Selected_Component loop
14451 Change_Selected_Component_To_Expanded_Name (Pref);
14452 Set_Entity (Selector_Name (Pref), Scop);
14453 Set_Entity (Pref, Scop);
14454 Pref := Prefix (Pref);
14455 Scop := Scope (Scop);
14458 Set_Entity (Pref, Scop);