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_Dist; use Exp_Dist;
41 with Exp_Util; use Exp_Util;
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 pragma Assert (In_Pre_Post_Expression = False);
257 In_Pre_Post_Expression := True;
258 Preanalyze_Spec_Expression
259 (Get_Pragma_Arg (Arg1), Standard_Boolean);
260 In_Pre_Post_Expression := False;
262 -- Remove the subprogram from the scope stack now that the pre-analysis
263 -- of the precondition/postcondition is done.
266 end Analyze_PPC_In_Decl_Part;
272 procedure Analyze_Pragma (N : Node_Id) is
273 Loc : constant Source_Ptr := Sloc (N);
274 Pname : constant Name_Id := Pragma_Name (N);
277 Pragma_Exit : exception;
278 -- This exception is used to exit pragma processing completely. It is
279 -- used when an error is detected, and no further processing is
280 -- required. It is also used if an earlier error has left the tree in
281 -- a state where the pragma should not be processed.
284 -- Number of pragma argument associations
290 -- First four pragma arguments (pragma argument association nodes, or
291 -- Empty if the corresponding argument does not exist).
293 type Name_List is array (Natural range <>) of Name_Id;
294 type Args_List is array (Natural range <>) of Node_Id;
295 -- Types used for arguments to Check_Arg_Order and Gather_Associations
297 procedure Ada_2005_Pragma;
298 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
299 -- Ada 95 mode, these are implementation defined pragmas, so should be
300 -- caught by the No_Implementation_Pragmas restriction.
302 procedure Ada_2012_Pragma;
303 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
304 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
305 -- should be caught by the No_Implementation_Pragmas restriction.
307 procedure Check_Ada_83_Warning;
308 -- Issues a warning message for the current pragma if operating in Ada
309 -- 83 mode (used for language pragmas that are not a standard part of
310 -- Ada 83). This procedure does not raise Error_Pragma. Also notes use
313 procedure Check_Arg_Count (Required : Nat);
314 -- Check argument count for pragma is equal to given parameter. If not,
315 -- then issue an error message and raise Pragma_Exit.
317 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
318 -- Arg which can either be a pragma argument association, in which case
319 -- the check is applied to the expression of the association or an
320 -- expression directly.
322 procedure Check_Arg_Is_External_Name (Arg : Node_Id);
323 -- Check that an argument has the right form for an EXTERNAL_NAME
324 -- parameter of an extended import/export pragma. The rule is that the
325 -- name must be an identifier or string literal (in Ada 83 mode) or a
326 -- static string expression (in Ada 95 mode).
328 procedure Check_Arg_Is_Identifier (Arg : Node_Id);
329 -- Check the specified argument Arg to make sure that it is an
330 -- identifier. If not give error and raise Pragma_Exit.
332 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
333 -- Check the specified argument Arg to make sure that it is an integer
334 -- literal. If not give error and raise Pragma_Exit.
336 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
337 -- Check the specified argument Arg to make sure that it has the proper
338 -- syntactic form for a local name and meets the semantic requirements
339 -- for a local name. The local name is analyzed as part of the
340 -- processing for this call. In addition, the local name is required
341 -- to represent an entity at the library level.
343 procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
344 -- Check the specified argument Arg to make sure that it has the proper
345 -- syntactic form for a local name and meets the semantic requirements
346 -- for a local name. The local name is analyzed as part of the
347 -- processing for this call.
349 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
350 -- Check the specified argument Arg to make sure that it is a valid
351 -- locking policy name. If not give error and raise Pragma_Exit.
353 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
354 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
355 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
356 -- Check the specified argument Arg to make sure that it is an
357 -- identifier whose name matches either N1 or N2 (or N3 if present).
358 -- If not then give error and raise Pragma_Exit.
360 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
361 -- Check the specified argument Arg to make sure that it is a valid
362 -- queuing policy name. If not give error and raise Pragma_Exit.
364 procedure Check_Arg_Is_Static_Expression
366 Typ : Entity_Id := Empty);
367 -- Check the specified argument Arg to make sure that it is a static
368 -- expression of the given type (i.e. it will be analyzed and resolved
369 -- using this type, which can be any valid argument to Resolve, e.g.
370 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
371 -- Typ is left Empty, then any static expression is allowed.
373 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
374 -- Check the specified argument Arg to make sure that it is a valid task
375 -- dispatching policy name. If not give error and raise Pragma_Exit.
377 procedure Check_Arg_Order (Names : Name_List);
378 -- Checks for an instance of two arguments with identifiers for the
379 -- current pragma which are not in the sequence indicated by Names,
380 -- and if so, generates a fatal message about bad order of arguments.
382 procedure Check_At_Least_N_Arguments (N : Nat);
383 -- Check there are at least N arguments present
385 procedure Check_At_Most_N_Arguments (N : Nat);
386 -- Check there are no more than N arguments present
388 procedure Check_Component
391 In_Variant_Part : Boolean := False);
392 -- Examine an Unchecked_Union component for correct use of per-object
393 -- constrained subtypes, and for restrictions on finalizable components.
394 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
395 -- should be set when Comp comes from a record variant.
397 procedure Check_Duplicate_Pragma (E : Entity_Id);
398 -- Check if a pragma of the same name as the current pragma is already
399 -- chained as a rep pragma to the given entity. If so give a message
400 -- about the duplicate, and then raise Pragma_Exit so does not return.
401 -- Also checks for delayed aspect specification node in the chain.
403 procedure Check_Duplicated_Export_Name (Nam : Node_Id);
404 -- Nam is an N_String_Literal node containing the external name set by
405 -- an Import or Export pragma (or extended Import or Export pragma).
406 -- This procedure checks for possible duplications if this is the export
407 -- case, and if found, issues an appropriate error message.
409 procedure Check_First_Subtype (Arg : Node_Id);
410 -- Checks that Arg, whose expression is an entity name, references a
413 procedure Check_In_Main_Program;
414 -- Common checks for pragmas that appear within a main program
415 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
417 procedure Check_Interrupt_Or_Attach_Handler;
418 -- Common processing for first argument of pragma Interrupt_Handler or
419 -- pragma Attach_Handler.
421 procedure Check_Is_In_Decl_Part_Or_Package_Spec;
422 -- Check that pragma appears in a declarative part, or in a package
423 -- specification, i.e. that it does not occur in a statement sequence
426 procedure Check_No_Identifier (Arg : Node_Id);
427 -- Checks that the given argument does not have an identifier. If
428 -- an identifier is present, then an error message is issued, and
429 -- Pragma_Exit is raised.
431 procedure Check_No_Identifiers;
432 -- Checks that none of the arguments to the pragma has an identifier.
433 -- If any argument has an identifier, then an error message is issued,
434 -- and Pragma_Exit is raised.
436 procedure Check_No_Link_Name;
437 -- Checks that no link name is specified
439 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
440 -- Checks if the given argument has an identifier, and if so, requires
441 -- it to match the given identifier name. If there is a non-matching
442 -- identifier, then an error message is given and Error_Pragmas raised.
444 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
445 -- Checks if the given argument has an identifier, and if so, requires
446 -- it to match the given identifier name. If there is a non-matching
447 -- identifier, then an error message is given and Error_Pragmas raised.
448 -- In this version of the procedure, the identifier name is given as
449 -- a string with lower case letters.
451 procedure Check_Precondition_Postcondition (In_Body : out Boolean);
452 -- Called to process a precondition or postcondition pragma. There are
455 -- The pragma appears after a subprogram spec
457 -- If the corresponding check is not enabled, the pragma is analyzed
458 -- but otherwise ignored and control returns with In_Body set False.
460 -- If the check is enabled, then the first step is to analyze the
461 -- pragma, but this is skipped if the subprogram spec appears within
462 -- a package specification (because this is the case where we delay
463 -- analysis till the end of the spec). Then (whether or not it was
464 -- analyzed), the pragma is chained to the subprogram in question
465 -- (using Spec_PPC_List and Next_Pragma) and control returns to the
466 -- caller with In_Body set False.
468 -- The pragma appears at the start of subprogram body declarations
470 -- In this case an immediate return to the caller is made with
471 -- In_Body set True, and the pragma is NOT analyzed.
473 -- In all other cases, an error message for bad placement is given
475 procedure Check_Static_Constraint (Constr : Node_Id);
476 -- Constr is a constraint from an N_Subtype_Indication node from a
477 -- component constraint in an Unchecked_Union type. This routine checks
478 -- that the constraint is static as required by the restrictions for
481 procedure Check_Valid_Configuration_Pragma;
482 -- Legality checks for placement of a configuration pragma
484 procedure Check_Valid_Library_Unit_Pragma;
485 -- Legality checks for library unit pragmas. A special case arises for
486 -- pragmas in generic instances that come from copies of the original
487 -- library unit pragmas in the generic templates. In the case of other
488 -- than library level instantiations these can appear in contexts which
489 -- would normally be invalid (they only apply to the original template
490 -- and to library level instantiations), and they are simply ignored,
491 -- which is implemented by rewriting them as null statements.
493 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
494 -- Check an Unchecked_Union variant for lack of nested variants and
495 -- presence of at least one component. UU_Typ is the related Unchecked_
498 procedure Error_Pragma (Msg : String);
499 pragma No_Return (Error_Pragma);
500 -- Outputs error message for current pragma. The message contains a %
501 -- that will be replaced with the pragma name, and the flag is placed
502 -- on the pragma itself. Pragma_Exit is then raised.
504 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
505 pragma No_Return (Error_Pragma_Arg);
506 -- Outputs error message for current pragma. The message may contain
507 -- a % that will be replaced with the pragma name. The parameter Arg
508 -- may either be a pragma argument association, in which case the flag
509 -- is placed on the expression of this association, or an expression,
510 -- in which case the flag is placed directly on the expression. The
511 -- message is placed using Error_Msg_N, so the message may also contain
512 -- an & insertion character which will reference the given Arg value.
513 -- After placing the message, Pragma_Exit is raised.
515 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
516 pragma No_Return (Error_Pragma_Arg);
517 -- Similar to above form of Error_Pragma_Arg except that two messages
518 -- are provided, the second is a continuation comment starting with \.
520 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
521 pragma No_Return (Error_Pragma_Arg_Ident);
522 -- Outputs error message for current pragma. The message may contain
523 -- a % that will be replaced with the pragma name. The parameter Arg
524 -- must be a pragma argument association with a non-empty identifier
525 -- (i.e. its Chars field must be set), and the error message is placed
526 -- on the identifier. The message is placed using Error_Msg_N so
527 -- the message may also contain an & insertion character which will
528 -- reference the identifier. After placing the message, Pragma_Exit
531 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
532 pragma No_Return (Error_Pragma_Ref);
533 -- Outputs error message for current pragma. The message may contain
534 -- a % that will be replaced with the pragma name. The parameter Ref
535 -- must be an entity whose name can be referenced by & and sloc by #.
536 -- After placing the message, Pragma_Exit is raised.
538 function Find_Lib_Unit_Name return Entity_Id;
539 -- Used for a library unit pragma to find the entity to which the
540 -- library unit pragma applies, returns the entity found.
542 procedure Find_Program_Unit_Name (Id : Node_Id);
543 -- If the pragma is a compilation unit pragma, the id must denote the
544 -- compilation unit in the same compilation, and the pragma must appear
545 -- in the list of preceding or trailing pragmas. If it is a program
546 -- unit pragma that is not a compilation unit pragma, then the
547 -- identifier must be visible.
549 function Find_Unique_Parameterless_Procedure
551 Arg : Node_Id) return Entity_Id;
552 -- Used for a procedure pragma to find the unique parameterless
553 -- procedure identified by Name, returns it if it exists, otherwise
554 -- errors out and uses Arg as the pragma argument for the message.
556 procedure Fix_Error (Msg : in out String);
557 -- This is called prior to issuing an error message. Msg is a string
558 -- which typically contains the substring pragma. If the current pragma
559 -- comes from an aspect, each such "pragma" substring is replaced with
560 -- the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
561 -- (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
563 procedure Gather_Associations
565 Args : out Args_List);
566 -- This procedure is used to gather the arguments for a pragma that
567 -- permits arbitrary ordering of parameters using the normal rules
568 -- for named and positional parameters. The Names argument is a list
569 -- of Name_Id values that corresponds to the allowed pragma argument
570 -- association identifiers in order. The result returned in Args is
571 -- a list of corresponding expressions that are the pragma arguments.
572 -- Note that this is a list of expressions, not of pragma argument
573 -- associations (Gather_Associations has completely checked all the
574 -- optional identifiers when it returns). An entry in Args is Empty
575 -- on return if the corresponding argument is not present.
577 procedure GNAT_Pragma;
578 -- Called for all GNAT defined pragmas to check the relevant restriction
579 -- (No_Implementation_Pragmas).
581 function Is_Before_First_Decl
582 (Pragma_Node : Node_Id;
583 Decls : List_Id) return Boolean;
584 -- Return True if Pragma_Node is before the first declarative item in
585 -- Decls where Decls is the list of declarative items.
587 function Is_Configuration_Pragma return Boolean;
588 -- Determines if the placement of the current pragma is appropriate
589 -- for a configuration pragma.
591 function Is_In_Context_Clause return Boolean;
592 -- Returns True if pragma appears within the context clause of a unit,
593 -- and False for any other placement (does not generate any messages).
595 function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
596 -- Analyzes the argument, and determines if it is a static string
597 -- expression, returns True if so, False if non-static or not String.
599 procedure Pragma_Misplaced;
600 pragma No_Return (Pragma_Misplaced);
601 -- Issue fatal error message for misplaced pragma
603 procedure Process_Atomic_Shared_Volatile;
604 -- Common processing for pragmas Atomic, Shared, Volatile. Note that
605 -- Shared is an obsolete Ada 83 pragma, treated as being identical
606 -- in effect to pragma Atomic.
608 procedure Process_Compile_Time_Warning_Or_Error;
609 -- Common processing for Compile_Time_Error and Compile_Time_Warning
611 procedure Process_Convention
612 (C : out Convention_Id;
613 Ent : out Entity_Id);
614 -- Common processing for Convention, Interface, Import and Export.
615 -- Checks first two arguments of pragma, and sets the appropriate
616 -- convention value in the specified entity or entities. On return
617 -- C is the convention, Ent is the referenced entity.
619 procedure Process_Extended_Import_Export_Exception_Pragma
620 (Arg_Internal : Node_Id;
621 Arg_External : Node_Id;
624 -- Common processing for the pragmas Import/Export_Exception. The three
625 -- arguments correspond to the three named parameters of the pragma. An
626 -- argument is empty if the corresponding parameter is not present in
629 procedure Process_Extended_Import_Export_Object_Pragma
630 (Arg_Internal : Node_Id;
631 Arg_External : Node_Id;
633 -- Common processing for the pragmas Import/Export_Object. The three
634 -- arguments correspond to the three named parameters of the pragmas. An
635 -- argument is empty if the corresponding parameter is not present in
638 procedure Process_Extended_Import_Export_Internal_Arg
639 (Arg_Internal : Node_Id := Empty);
640 -- Common processing for all extended Import and Export pragmas. The
641 -- argument is the pragma parameter for the Internal argument. If
642 -- Arg_Internal is empty or inappropriate, an error message is posted.
643 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
644 -- set to identify the referenced entity.
646 procedure Process_Extended_Import_Export_Subprogram_Pragma
647 (Arg_Internal : Node_Id;
648 Arg_External : Node_Id;
649 Arg_Parameter_Types : Node_Id;
650 Arg_Result_Type : Node_Id := Empty;
651 Arg_Mechanism : Node_Id;
652 Arg_Result_Mechanism : Node_Id := Empty;
653 Arg_First_Optional_Parameter : Node_Id := Empty);
654 -- Common processing for all extended Import and Export pragmas applying
655 -- to subprograms. The caller omits any arguments that do not apply to
656 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
657 -- only in the Import_Function and Export_Function cases). The argument
658 -- names correspond to the allowed pragma association identifiers.
660 procedure Process_Generic_List;
661 -- Common processing for Share_Generic and Inline_Generic
663 procedure Process_Import_Or_Interface;
664 -- Common processing for Import of Interface
666 procedure Process_Import_Predefined_Type;
667 -- Processing for completing a type with pragma Import. This is used
668 -- to declare types that match predefined C types, especially for cases
669 -- without corresponding Ada predefined type.
671 procedure Process_Inline (Active : Boolean);
672 -- Common processing for Inline and Inline_Always. The parameter
673 -- indicates if the inline pragma is active, i.e. if it should actually
674 -- cause inlining to occur.
676 procedure Process_Interface_Name
677 (Subprogram_Def : Entity_Id;
680 -- Given the last two arguments of pragma Import, pragma Export, or
681 -- pragma Interface_Name, performs validity checks and sets the
682 -- Interface_Name field of the given subprogram entity to the
683 -- appropriate external or link name, depending on the arguments given.
684 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
685 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
686 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
687 -- nor Link_Arg is present, the interface name is set to the default
688 -- from the subprogram name.
690 procedure Process_Interrupt_Or_Attach_Handler;
691 -- Common processing for Interrupt and Attach_Handler pragmas
693 procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
694 -- Common processing for Restrictions and Restriction_Warnings pragmas.
695 -- Warn is True for Restriction_Warnings, or for Restrictions if the
696 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
697 -- is not set in the Restrictions case.
699 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
700 -- Common processing for Suppress and Unsuppress. The boolean parameter
701 -- Suppress_Case is True for the Suppress case, and False for the
704 procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
705 -- This procedure sets the Is_Exported flag for the given entity,
706 -- checking that the entity was not previously imported. Arg is
707 -- the argument that specified the entity. A check is also made
708 -- for exporting inappropriate entities.
710 procedure Set_Extended_Import_Export_External_Name
711 (Internal_Ent : Entity_Id;
712 Arg_External : Node_Id);
713 -- Common processing for all extended import export pragmas. The first
714 -- argument, Internal_Ent, is the internal entity, which has already
715 -- been checked for validity by the caller. Arg_External is from the
716 -- Import or Export pragma, and may be null if no External parameter
717 -- was present. If Arg_External is present and is a non-null string
718 -- (a null string is treated as the default), then the Interface_Name
719 -- field of Internal_Ent is set appropriately.
721 procedure Set_Imported (E : Entity_Id);
722 -- This procedure sets the Is_Imported flag for the given entity,
723 -- checking that it is not previously exported or imported.
725 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
726 -- Mech is a parameter passing mechanism (see Import_Function syntax
727 -- for MECHANISM_NAME). This routine checks that the mechanism argument
728 -- has the right form, and if not issues an error message. If the
729 -- argument has the right form then the Mechanism field of Ent is
730 -- set appropriately.
732 procedure Set_Ravenscar_Profile (N : Node_Id);
733 -- Activate the set of configuration pragmas and restrictions that make
734 -- up the Ravenscar Profile. N is the corresponding pragma node, which
735 -- is used for error messages on any constructs that violate the
738 ---------------------
739 -- Ada_2005_Pragma --
740 ---------------------
742 procedure Ada_2005_Pragma is
744 if Ada_Version <= Ada_95 then
745 Check_Restriction (No_Implementation_Pragmas, N);
749 ---------------------
750 -- Ada_2012_Pragma --
751 ---------------------
753 procedure Ada_2012_Pragma is
755 if Ada_Version <= Ada_2005 then
756 Check_Restriction (No_Implementation_Pragmas, N);
760 --------------------------
761 -- Check_Ada_83_Warning --
762 --------------------------
764 procedure Check_Ada_83_Warning is
766 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
767 Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
769 end Check_Ada_83_Warning;
771 ---------------------
772 -- Check_Arg_Count --
773 ---------------------
775 procedure Check_Arg_Count (Required : Nat) is
777 if Arg_Count /= Required then
778 Error_Pragma ("wrong number of arguments for pragma%");
782 --------------------------------
783 -- Check_Arg_Is_External_Name --
784 --------------------------------
786 procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
787 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
790 if Nkind (Argx) = N_Identifier then
794 Analyze_And_Resolve (Argx, Standard_String);
796 if Is_OK_Static_Expression (Argx) then
799 elsif Etype (Argx) = Any_Type then
802 -- An interesting special case, if we have a string literal and
803 -- we are in Ada 83 mode, then we allow it even though it will
804 -- not be flagged as static. This allows expected Ada 83 mode
805 -- use of external names which are string literals, even though
806 -- technically these are not static in Ada 83.
808 elsif Ada_Version = Ada_83
809 and then Nkind (Argx) = N_String_Literal
813 -- Static expression that raises Constraint_Error. This has
814 -- already been flagged, so just exit from pragma processing.
816 elsif Is_Static_Expression (Argx) then
819 -- Here we have a real error (non-static expression)
822 Error_Msg_Name_1 := Pname;
826 "argument for pragma% must be a identifier or "
827 & "static string expression!";
830 Flag_Non_Static_Expr (Msg, Argx);
835 end Check_Arg_Is_External_Name;
837 -----------------------------
838 -- Check_Arg_Is_Identifier --
839 -----------------------------
841 procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
842 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
844 if Nkind (Argx) /= N_Identifier then
846 ("argument for pragma% must be identifier", Argx);
848 end Check_Arg_Is_Identifier;
850 ----------------------------------
851 -- Check_Arg_Is_Integer_Literal --
852 ----------------------------------
854 procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
855 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
857 if Nkind (Argx) /= N_Integer_Literal then
859 ("argument for pragma% must be integer literal", Argx);
861 end Check_Arg_Is_Integer_Literal;
863 -------------------------------------------
864 -- Check_Arg_Is_Library_Level_Local_Name --
865 -------------------------------------------
869 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
870 -- | library_unit_NAME
872 procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
874 Check_Arg_Is_Local_Name (Arg);
876 if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
877 and then Comes_From_Source (N)
880 ("argument for pragma% must be library level entity", Arg);
882 end Check_Arg_Is_Library_Level_Local_Name;
884 -----------------------------
885 -- Check_Arg_Is_Local_Name --
886 -----------------------------
890 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
891 -- | library_unit_NAME
893 procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
894 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
899 if Nkind (Argx) not in N_Direct_Name
900 and then (Nkind (Argx) /= N_Attribute_Reference
901 or else Present (Expressions (Argx))
902 or else Nkind (Prefix (Argx)) /= N_Identifier)
903 and then (not Is_Entity_Name (Argx)
904 or else not Is_Compilation_Unit (Entity (Argx)))
906 Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
909 -- No further check required if not an entity name
911 if not Is_Entity_Name (Argx) then
917 Ent : constant Entity_Id := Entity (Argx);
918 Scop : constant Entity_Id := Scope (Ent);
920 -- Case of a pragma applied to a compilation unit: pragma must
921 -- occur immediately after the program unit in the compilation.
923 if Is_Compilation_Unit (Ent) then
925 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
927 -- Case of pragma placed immediately after spec
929 if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
932 -- Case of pragma placed immediately after body
934 elsif Nkind (Decl) = N_Subprogram_Declaration
935 and then Present (Corresponding_Body (Decl))
939 (Parent (Unit_Declaration_Node
940 (Corresponding_Body (Decl))));
942 -- All other cases are illegal
949 -- Special restricted placement rule from 10.2.1(11.8/2)
951 elsif Is_Generic_Formal (Ent)
952 and then Prag_Id = Pragma_Preelaborable_Initialization
954 OK := List_Containing (N) =
955 Generic_Formal_Declarations
956 (Unit_Declaration_Node (Scop));
958 -- Default case, just check that the pragma occurs in the scope
959 -- of the entity denoted by the name.
962 OK := Current_Scope = Scop;
967 ("pragma% argument must be in same declarative part", Arg);
971 end Check_Arg_Is_Local_Name;
973 ---------------------------------
974 -- Check_Arg_Is_Locking_Policy --
975 ---------------------------------
977 procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
978 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
981 Check_Arg_Is_Identifier (Argx);
983 if not Is_Locking_Policy_Name (Chars (Argx)) then
984 Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
986 end Check_Arg_Is_Locking_Policy;
988 -------------------------
989 -- Check_Arg_Is_One_Of --
990 -------------------------
992 procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
993 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
996 Check_Arg_Is_Identifier (Argx);
998 if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
999 Error_Msg_Name_2 := N1;
1000 Error_Msg_Name_3 := N2;
1001 Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1003 end Check_Arg_Is_One_Of;
1005 procedure Check_Arg_Is_One_Of
1007 N1, N2, N3 : Name_Id)
1009 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1012 Check_Arg_Is_Identifier (Argx);
1014 if Chars (Argx) /= N1
1015 and then Chars (Argx) /= N2
1016 and then Chars (Argx) /= N3
1018 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1020 end Check_Arg_Is_One_Of;
1022 procedure Check_Arg_Is_One_Of
1024 N1, N2, N3, N4 : Name_Id)
1026 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1029 Check_Arg_Is_Identifier (Argx);
1031 if Chars (Argx) /= N1
1032 and then Chars (Argx) /= N2
1033 and then Chars (Argx) /= N3
1034 and then Chars (Argx) /= N4
1036 Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1038 end Check_Arg_Is_One_Of;
1039 ---------------------------------
1040 -- Check_Arg_Is_Queuing_Policy --
1041 ---------------------------------
1043 procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1044 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1047 Check_Arg_Is_Identifier (Argx);
1049 if not Is_Queuing_Policy_Name (Chars (Argx)) then
1050 Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1052 end Check_Arg_Is_Queuing_Policy;
1054 ------------------------------------
1055 -- Check_Arg_Is_Static_Expression --
1056 ------------------------------------
1058 procedure Check_Arg_Is_Static_Expression
1060 Typ : Entity_Id := Empty)
1062 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1065 if Present (Typ) then
1066 Analyze_And_Resolve (Argx, Typ);
1068 Analyze_And_Resolve (Argx);
1071 if Is_OK_Static_Expression (Argx) then
1074 elsif Etype (Argx) = Any_Type then
1077 -- An interesting special case, if we have a string literal and we
1078 -- are in Ada 83 mode, then we allow it even though it will not be
1079 -- flagged as static. This allows the use of Ada 95 pragmas like
1080 -- Import in Ada 83 mode. They will of course be flagged with
1081 -- warnings as usual, but will not cause errors.
1083 elsif Ada_Version = Ada_83
1084 and then Nkind (Argx) = N_String_Literal
1088 -- Static expression that raises Constraint_Error. This has already
1089 -- been flagged, so just exit from pragma processing.
1091 elsif Is_Static_Expression (Argx) then
1094 -- Finally, we have a real error
1097 Error_Msg_Name_1 := Pname;
1101 "argument for pragma% must be a static expression!";
1104 Flag_Non_Static_Expr (Msg, Argx);
1109 end Check_Arg_Is_Static_Expression;
1111 ------------------------------------------
1112 -- Check_Arg_Is_Task_Dispatching_Policy --
1113 ------------------------------------------
1115 procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1116 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1119 Check_Arg_Is_Identifier (Argx);
1121 if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1123 ("& is not a valid task dispatching policy name", Argx);
1125 end Check_Arg_Is_Task_Dispatching_Policy;
1127 ---------------------
1128 -- Check_Arg_Order --
1129 ---------------------
1131 procedure Check_Arg_Order (Names : Name_List) is
1134 Highest_So_Far : Natural := 0;
1135 -- Highest index in Names seen do far
1139 for J in 1 .. Arg_Count loop
1140 if Chars (Arg) /= No_Name then
1141 for K in Names'Range loop
1142 if Chars (Arg) = Names (K) then
1143 if K < Highest_So_Far then
1144 Error_Msg_Name_1 := Pname;
1146 ("parameters out of order for pragma%", Arg);
1147 Error_Msg_Name_1 := Names (K);
1148 Error_Msg_Name_2 := Names (Highest_So_Far);
1149 Error_Msg_N ("\% must appear before %", Arg);
1153 Highest_So_Far := K;
1161 end Check_Arg_Order;
1163 --------------------------------
1164 -- Check_At_Least_N_Arguments --
1165 --------------------------------
1167 procedure Check_At_Least_N_Arguments (N : Nat) is
1169 if Arg_Count < N then
1170 Error_Pragma ("too few arguments for pragma%");
1172 end Check_At_Least_N_Arguments;
1174 -------------------------------
1175 -- Check_At_Most_N_Arguments --
1176 -------------------------------
1178 procedure Check_At_Most_N_Arguments (N : Nat) is
1181 if Arg_Count > N then
1183 for J in 1 .. N loop
1185 Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1188 end Check_At_Most_N_Arguments;
1190 ---------------------
1191 -- Check_Component --
1192 ---------------------
1194 procedure Check_Component
1197 In_Variant_Part : Boolean := False)
1199 Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1200 Sindic : constant Node_Id :=
1201 Subtype_Indication (Component_Definition (Comp));
1202 Typ : constant Entity_Id := Etype (Comp_Id);
1204 function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1205 -- Determine whether entity Id appears inside a generic body.
1206 -- Shouldn't this be in a more general place ???
1208 -------------------------
1209 -- Inside_Generic_Body --
1210 -------------------------
1212 function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1217 while Present (S) and then S /= Standard_Standard loop
1218 if Ekind (S) = E_Generic_Package
1219 and then In_Package_Body (S)
1228 end Inside_Generic_Body;
1230 -- Start of processing for Check_Component
1233 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
1234 -- object constraint, then the component type shall be an Unchecked_
1237 if Nkind (Sindic) = N_Subtype_Indication
1238 and then Has_Per_Object_Constraint (Comp_Id)
1239 and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1242 ("component subtype subject to per-object constraint " &
1243 "must be an Unchecked_Union", Comp);
1245 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
1246 -- the body of a generic unit, or within the body of any of its
1247 -- descendant library units, no part of the type of a component
1248 -- declared in a variant_part of the unchecked union type shall be of
1249 -- a formal private type or formal private extension declared within
1250 -- the formal part of the generic unit.
1252 elsif Ada_Version >= Ada_2012
1253 and then Inside_Generic_Body (UU_Typ)
1254 and then In_Variant_Part
1255 and then Is_Private_Type (Typ)
1256 and then Is_Generic_Type (Typ)
1259 ("component of Unchecked_Union cannot be of generic type", Comp);
1261 elsif Needs_Finalization (Typ) then
1263 ("component of Unchecked_Union cannot be controlled", Comp);
1265 elsif Has_Task (Typ) then
1267 ("component of Unchecked_Union cannot have tasks", Comp);
1269 end Check_Component;
1271 ----------------------------
1272 -- Check_Duplicate_Pragma --
1273 ----------------------------
1275 procedure Check_Duplicate_Pragma (E : Entity_Id) is
1279 -- Nothing to do if this pragma comes from an aspect specification,
1280 -- since we could not be duplicating a pragma, and we dealt with the
1281 -- case of duplicated aspects in Analyze_Aspect_Specifications.
1283 if From_Aspect_Specification (N) then
1287 -- Otherwise current pragma may duplicate previous pragma or a
1288 -- previously given aspect specification for the same pragma.
1290 P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1293 Error_Msg_Name_1 := Pragma_Name (N);
1294 Error_Msg_Sloc := Sloc (P);
1296 if Nkind (P) = N_Aspect_Specification
1297 or else From_Aspect_Specification (P)
1299 Error_Msg_NE ("aspect% for & previously given#", N, E);
1301 Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1306 end Check_Duplicate_Pragma;
1308 ----------------------------------
1309 -- Check_Duplicated_Export_Name --
1310 ----------------------------------
1312 procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1313 String_Val : constant String_Id := Strval (Nam);
1316 -- We are only interested in the export case, and in the case of
1317 -- generics, it is the instance, not the template, that is the
1318 -- problem (the template will generate a warning in any case).
1320 if not Inside_A_Generic
1321 and then (Prag_Id = Pragma_Export
1323 Prag_Id = Pragma_Export_Procedure
1325 Prag_Id = Pragma_Export_Valued_Procedure
1327 Prag_Id = Pragma_Export_Function)
1329 for J in Externals.First .. Externals.Last loop
1330 if String_Equal (String_Val, Strval (Externals.Table (J))) then
1331 Error_Msg_Sloc := Sloc (Externals.Table (J));
1332 Error_Msg_N ("external name duplicates name given#", Nam);
1337 Externals.Append (Nam);
1339 end Check_Duplicated_Export_Name;
1341 -------------------------
1342 -- Check_First_Subtype --
1343 -------------------------
1345 procedure Check_First_Subtype (Arg : Node_Id) is
1346 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1347 Ent : constant Entity_Id := Entity (Argx);
1350 if Is_First_Subtype (Ent) then
1353 elsif Is_Type (Ent) then
1355 ("pragma% cannot apply to subtype", Argx);
1357 elsif Is_Object (Ent) then
1359 ("pragma% cannot apply to object, requires a type", Argx);
1363 ("pragma% cannot apply to&, requires a type", Argx);
1365 end Check_First_Subtype;
1367 ---------------------------
1368 -- Check_In_Main_Program --
1369 ---------------------------
1371 procedure Check_In_Main_Program is
1372 P : constant Node_Id := Parent (N);
1375 -- Must be at in subprogram body
1377 if Nkind (P) /= N_Subprogram_Body then
1378 Error_Pragma ("% pragma allowed only in subprogram");
1380 -- Otherwise warn if obviously not main program
1382 elsif Present (Parameter_Specifications (Specification (P)))
1383 or else not Is_Compilation_Unit (Defining_Entity (P))
1385 Error_Msg_Name_1 := Pname;
1387 ("?pragma% is only effective in main program", N);
1389 end Check_In_Main_Program;
1391 ---------------------------------------
1392 -- Check_Interrupt_Or_Attach_Handler --
1393 ---------------------------------------
1395 procedure Check_Interrupt_Or_Attach_Handler is
1396 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1397 Handler_Proc, Proc_Scope : Entity_Id;
1402 if Prag_Id = Pragma_Interrupt_Handler then
1403 Check_Restriction (No_Dynamic_Attachment, N);
1406 Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1407 Proc_Scope := Scope (Handler_Proc);
1409 -- On AAMP only, a pragma Interrupt_Handler is supported for
1410 -- nonprotected parameterless procedures.
1412 if not AAMP_On_Target
1413 or else Prag_Id = Pragma_Attach_Handler
1415 if Ekind (Proc_Scope) /= E_Protected_Type then
1417 ("argument of pragma% must be protected procedure", Arg1);
1420 if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1421 Error_Pragma ("pragma% must be in protected definition");
1425 if not Is_Library_Level_Entity (Proc_Scope)
1426 or else (AAMP_On_Target
1427 and then not Is_Library_Level_Entity (Handler_Proc))
1430 ("argument for pragma% must be library level entity", Arg1);
1433 -- AI05-0033: A pragma cannot appear within a generic body, because
1434 -- instance can be in a nested scope. The check that protected type
1435 -- is itself a library-level declaration is done elsewhere.
1437 -- Note: we omit this check in Codepeer mode to properly handle code
1438 -- prior to AI-0033 (pragmas don't matter to codepeer in any case).
1440 if Inside_A_Generic then
1441 if Ekind (Scope (Current_Scope)) = E_Generic_Package
1442 and then In_Package_Body (Scope (Current_Scope))
1443 and then not CodePeer_Mode
1445 Error_Pragma ("pragma% cannot be used inside a generic");
1448 end Check_Interrupt_Or_Attach_Handler;
1450 -------------------------------------------
1451 -- Check_Is_In_Decl_Part_Or_Package_Spec --
1452 -------------------------------------------
1454 procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1463 elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1466 elsif Nkind_In (P, N_Package_Specification,
1471 -- Note: the following tests seem a little peculiar, because
1472 -- they test for bodies, but if we were in the statement part
1473 -- of the body, we would already have hit the handled statement
1474 -- sequence, so the only way we get here is by being in the
1475 -- declarative part of the body.
1477 elsif Nkind_In (P, N_Subprogram_Body,
1488 Error_Pragma ("pragma% is not in declarative part or package spec");
1489 end Check_Is_In_Decl_Part_Or_Package_Spec;
1491 -------------------------
1492 -- Check_No_Identifier --
1493 -------------------------
1495 procedure Check_No_Identifier (Arg : Node_Id) is
1497 if Nkind (Arg) = N_Pragma_Argument_Association
1498 and then Chars (Arg) /= No_Name
1500 Error_Pragma_Arg_Ident
1501 ("pragma% does not permit identifier& here", Arg);
1503 end Check_No_Identifier;
1505 --------------------------
1506 -- Check_No_Identifiers --
1507 --------------------------
1509 procedure Check_No_Identifiers is
1512 if Arg_Count > 0 then
1514 while Present (Arg_Node) loop
1515 Check_No_Identifier (Arg_Node);
1519 end Check_No_Identifiers;
1521 ------------------------
1522 -- Check_No_Link_Name --
1523 ------------------------
1525 procedure Check_No_Link_Name is
1528 and then Chars (Arg3) = Name_Link_Name
1533 if Present (Arg4) then
1535 ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1537 end Check_No_Link_Name;
1539 -------------------------------
1540 -- Check_Optional_Identifier --
1541 -------------------------------
1543 procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1546 and then Nkind (Arg) = N_Pragma_Argument_Association
1547 and then Chars (Arg) /= No_Name
1549 if Chars (Arg) /= Id then
1550 Error_Msg_Name_1 := Pname;
1551 Error_Msg_Name_2 := Id;
1552 Error_Msg_N ("pragma% argument expects identifier%", Arg);
1556 end Check_Optional_Identifier;
1558 procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1560 Name_Buffer (1 .. Id'Length) := Id;
1561 Name_Len := Id'Length;
1562 Check_Optional_Identifier (Arg, Name_Find);
1563 end Check_Optional_Identifier;
1565 --------------------------------------
1566 -- Check_Precondition_Postcondition --
1567 --------------------------------------
1569 procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1573 procedure Chain_PPC (PO : Node_Id);
1574 -- If PO is a subprogram declaration node (or a generic subprogram
1575 -- declaration node), then the precondition/postcondition applies
1576 -- to this subprogram and the processing for the pragma is completed.
1577 -- Otherwise the pragma is misplaced.
1583 procedure Chain_PPC (PO : Node_Id) is
1588 if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1589 if not From_Aspect_Specification (N) then
1591 ("pragma% cannot be applied to abstract subprogram");
1593 elsif Class_Present (N) then
1598 ("aspect % requires ''Class for abstract subprogram");
1601 -- AI05-0230: The same restriction applies to null procedures. For
1602 -- compatibility with earlier uses of the Ada pragma, apply this
1603 -- rule only to aspect specifications.
1605 -- The above discrpency needs documentation. Robert is dubious
1606 -- about whether it is a good idea ???
1608 elsif Nkind (PO) = N_Subprogram_Declaration
1609 and then Nkind (Specification (PO)) = N_Procedure_Specification
1610 and then Null_Present (Specification (PO))
1611 and then From_Aspect_Specification (N)
1612 and then not Class_Present (N)
1615 ("aspect % requires ''Class for null procedure");
1617 elsif not Nkind_In (PO, N_Subprogram_Declaration,
1618 N_Generic_Subprogram_Declaration,
1619 N_Entry_Declaration)
1624 -- Here if we have [generic] subprogram or entry declaration
1626 if Nkind (PO) = N_Entry_Declaration then
1627 S := Defining_Entity (PO);
1629 S := Defining_Unit_Name (Specification (PO));
1632 -- Make sure we do not have the case of a precondition pragma when
1633 -- the Pre'Class aspect is present.
1635 -- We do this by looking at pragmas already chained to the entity
1636 -- since the aspect derived pragma will be put on this list first.
1638 if Pragma_Name (N) = Name_Precondition then
1639 if not From_Aspect_Specification (N) then
1640 P := Spec_PPC_List (S);
1641 while Present (P) loop
1642 if Pragma_Name (P) = Name_Precondition
1643 and then From_Aspect_Specification (P)
1644 and then Class_Present (P)
1646 Error_Msg_Sloc := Sloc (P);
1648 ("pragma% not allowed, `Pre''Class` aspect given#");
1651 P := Next_Pragma (P);
1656 -- Similarly check for Pre with inherited Pre'Class. Note that
1657 -- we cover the aspect case as well here.
1659 if Pragma_Name (N) = Name_Precondition
1660 and then not Class_Present (N)
1663 Inherited : constant Subprogram_List :=
1664 Inherited_Subprograms (S);
1668 for J in Inherited'Range loop
1669 P := Spec_PPC_List (Inherited (J));
1670 while Present (P) loop
1671 if Pragma_Name (P) = Name_Precondition
1672 and then Class_Present (P)
1674 Error_Msg_Sloc := Sloc (P);
1676 ("pragma% not allowed, `Pre''Class` "
1677 & "aspect inherited from#");
1680 P := Next_Pragma (P);
1686 -- Note: we do not analyze the pragma at this point. Instead we
1687 -- delay this analysis until the end of the declarative part in
1688 -- which the pragma appears. This implements the required delay
1689 -- in this analysis, allowing forward references. The analysis
1690 -- happens at the end of Analyze_Declarations.
1692 -- Chain spec PPC pragma to list for subprogram
1694 Set_Next_Pragma (N, Spec_PPC_List (S));
1695 Set_Spec_PPC_List (S, N);
1697 -- Return indicating spec case
1703 -- Start of processing for Check_Precondition_Postcondition
1706 if not Is_List_Member (N) then
1710 -- Preanalyze message argument if present. Visibility in this
1711 -- argument is established at the point of pragma occurrence.
1713 if Arg_Count = 2 then
1714 Check_Optional_Identifier (Arg2, Name_Message);
1715 Preanalyze_Spec_Expression
1716 (Get_Pragma_Arg (Arg2), Standard_String);
1719 -- Record if pragma is enabled
1721 if Check_Enabled (Pname) then
1722 Set_SCO_Pragma_Enabled (Loc);
1725 -- If we are within an inlined body, the legality of the pragma
1726 -- has been checked already.
1728 if In_Inlined_Body then
1733 -- Search prior declarations
1736 while Present (Prev (P)) loop
1739 -- If the previous node is a generic subprogram, do not go to to
1740 -- the original node, which is the unanalyzed tree: we need to
1741 -- attach the pre/postconditions to the analyzed version at this
1742 -- point. They get propagated to the original tree when analyzing
1743 -- the corresponding body.
1745 if Nkind (P) not in N_Generic_Declaration then
1746 PO := Original_Node (P);
1751 -- Skip past prior pragma
1753 if Nkind (PO) = N_Pragma then
1756 -- Skip stuff not coming from source
1758 elsif not Comes_From_Source (PO) then
1760 -- The condition may apply to a subprogram instantiation
1762 if Nkind (PO) = N_Subprogram_Declaration
1763 and then Present (Generic_Parent (Specification (PO)))
1768 -- For all other cases of non source code, do nothing
1774 -- Only remaining possibility is subprogram declaration
1782 -- If we fall through loop, pragma is at start of list, so see if it
1783 -- is at the start of declarations of a subprogram body.
1785 if Nkind (Parent (N)) = N_Subprogram_Body
1786 and then List_Containing (N) = Declarations (Parent (N))
1788 if Operating_Mode /= Generate_Code
1789 or else Inside_A_Generic
1791 -- Analyze pragma expression for correctness and for ASIS use
1793 Preanalyze_Spec_Expression
1794 (Get_Pragma_Arg (Arg1), Standard_Boolean);
1800 -- See if it is in the pragmas after a library level subprogram
1802 elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1803 Chain_PPC (Unit (Parent (Parent (N))));
1807 -- If we fall through, pragma was misplaced
1810 end Check_Precondition_Postcondition;
1812 -----------------------------
1813 -- Check_Static_Constraint --
1814 -----------------------------
1816 -- Note: for convenience in writing this procedure, in addition to
1817 -- the officially (i.e. by spec) allowed argument which is always a
1818 -- constraint, it also allows ranges and discriminant associations.
1819 -- Above is not clear ???
1821 procedure Check_Static_Constraint (Constr : Node_Id) is
1823 procedure Require_Static (E : Node_Id);
1824 -- Require given expression to be static expression
1826 --------------------
1827 -- Require_Static --
1828 --------------------
1830 procedure Require_Static (E : Node_Id) is
1832 if not Is_OK_Static_Expression (E) then
1833 Flag_Non_Static_Expr
1834 ("non-static constraint not allowed in Unchecked_Union!", E);
1839 -- Start of processing for Check_Static_Constraint
1842 case Nkind (Constr) is
1843 when N_Discriminant_Association =>
1844 Require_Static (Expression (Constr));
1847 Require_Static (Low_Bound (Constr));
1848 Require_Static (High_Bound (Constr));
1850 when N_Attribute_Reference =>
1851 Require_Static (Type_Low_Bound (Etype (Prefix (Constr))));
1852 Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1854 when N_Range_Constraint =>
1855 Check_Static_Constraint (Range_Expression (Constr));
1857 when N_Index_Or_Discriminant_Constraint =>
1861 IDC := First (Constraints (Constr));
1862 while Present (IDC) loop
1863 Check_Static_Constraint (IDC);
1871 end Check_Static_Constraint;
1873 --------------------------------------
1874 -- Check_Valid_Configuration_Pragma --
1875 --------------------------------------
1877 -- A configuration pragma must appear in the context clause of a
1878 -- compilation unit, and only other pragmas may precede it. Note that
1879 -- the test also allows use in a configuration pragma file.
1881 procedure Check_Valid_Configuration_Pragma is
1883 if not Is_Configuration_Pragma then
1884 Error_Pragma ("incorrect placement for configuration pragma%");
1886 end Check_Valid_Configuration_Pragma;
1888 -------------------------------------
1889 -- Check_Valid_Library_Unit_Pragma --
1890 -------------------------------------
1892 procedure Check_Valid_Library_Unit_Pragma is
1894 Parent_Node : Node_Id;
1895 Unit_Name : Entity_Id;
1896 Unit_Kind : Node_Kind;
1897 Unit_Node : Node_Id;
1898 Sindex : Source_File_Index;
1901 if not Is_List_Member (N) then
1905 Plist := List_Containing (N);
1906 Parent_Node := Parent (Plist);
1908 if Parent_Node = Empty then
1911 -- Case of pragma appearing after a compilation unit. In this case
1912 -- it must have an argument with the corresponding name and must
1913 -- be part of the following pragmas of its parent.
1915 elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
1916 if Plist /= Pragmas_After (Parent_Node) then
1919 elsif Arg_Count = 0 then
1921 ("argument required if outside compilation unit");
1924 Check_No_Identifiers;
1925 Check_Arg_Count (1);
1926 Unit_Node := Unit (Parent (Parent_Node));
1927 Unit_Kind := Nkind (Unit_Node);
1929 Analyze (Get_Pragma_Arg (Arg1));
1931 if Unit_Kind = N_Generic_Subprogram_Declaration
1932 or else Unit_Kind = N_Subprogram_Declaration
1934 Unit_Name := Defining_Entity (Unit_Node);
1936 elsif Unit_Kind in N_Generic_Instantiation then
1937 Unit_Name := Defining_Entity (Unit_Node);
1940 Unit_Name := Cunit_Entity (Current_Sem_Unit);
1943 if Chars (Unit_Name) /=
1944 Chars (Entity (Get_Pragma_Arg (Arg1)))
1947 ("pragma% argument is not current unit name", Arg1);
1950 if Ekind (Unit_Name) = E_Package
1951 and then Present (Renamed_Entity (Unit_Name))
1953 Error_Pragma ("pragma% not allowed for renamed package");
1957 -- Pragma appears other than after a compilation unit
1960 -- Here we check for the generic instantiation case and also
1961 -- for the case of processing a generic formal package. We
1962 -- detect these cases by noting that the Sloc on the node
1963 -- does not belong to the current compilation unit.
1965 Sindex := Source_Index (Current_Sem_Unit);
1967 if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
1968 Rewrite (N, Make_Null_Statement (Loc));
1971 -- If before first declaration, the pragma applies to the
1972 -- enclosing unit, and the name if present must be this name.
1974 elsif Is_Before_First_Decl (N, Plist) then
1975 Unit_Node := Unit_Declaration_Node (Current_Scope);
1976 Unit_Kind := Nkind (Unit_Node);
1978 if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
1981 elsif Unit_Kind = N_Subprogram_Body
1982 and then not Acts_As_Spec (Unit_Node)
1986 elsif Nkind (Parent_Node) = N_Package_Body then
1989 elsif Nkind (Parent_Node) = N_Package_Specification
1990 and then Plist = Private_Declarations (Parent_Node)
1994 elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
1995 or else Nkind (Parent_Node) =
1996 N_Generic_Subprogram_Declaration)
1997 and then Plist = Generic_Formal_Declarations (Parent_Node)
2001 elsif Arg_Count > 0 then
2002 Analyze (Get_Pragma_Arg (Arg1));
2004 if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2006 ("name in pragma% must be enclosing unit", Arg1);
2009 -- It is legal to have no argument in this context
2015 -- Error if not before first declaration. This is because a
2016 -- library unit pragma argument must be the name of a library
2017 -- unit (RM 10.1.5(7)), but the only names permitted in this
2018 -- context are (RM 10.1.5(6)) names of subprogram declarations,
2019 -- generic subprogram declarations or generic instantiations.
2023 ("pragma% misplaced, must be before first declaration");
2027 end Check_Valid_Library_Unit_Pragma;
2033 procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2034 Clist : constant Node_Id := Component_List (Variant);
2038 if not Is_Non_Empty_List (Component_Items (Clist)) then
2040 ("Unchecked_Union may not have empty component list",
2045 Comp := First (Component_Items (Clist));
2046 while Present (Comp) loop
2047 Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2056 procedure Error_Pragma (Msg : String) is
2057 MsgF : String := Msg;
2059 Error_Msg_Name_1 := Pname;
2061 Error_Msg_N (MsgF, N);
2065 ----------------------
2066 -- Error_Pragma_Arg --
2067 ----------------------
2069 procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2070 MsgF : String := Msg;
2072 Error_Msg_Name_1 := Pname;
2074 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2076 end Error_Pragma_Arg;
2078 procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2079 MsgF : String := Msg1;
2081 Error_Msg_Name_1 := Pname;
2083 Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2084 Error_Pragma_Arg (Msg2, Arg);
2085 end Error_Pragma_Arg;
2087 ----------------------------
2088 -- Error_Pragma_Arg_Ident --
2089 ----------------------------
2091 procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2092 MsgF : String := Msg;
2094 Error_Msg_Name_1 := Pname;
2096 Error_Msg_N (MsgF, Arg);
2098 end Error_Pragma_Arg_Ident;
2100 ----------------------
2101 -- Error_Pragma_Ref --
2102 ----------------------
2104 procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2105 MsgF : String := Msg;
2107 Error_Msg_Name_1 := Pname;
2109 Error_Msg_Sloc := Sloc (Ref);
2110 Error_Msg_NE (MsgF, N, Ref);
2112 end Error_Pragma_Ref;
2114 ------------------------
2115 -- Find_Lib_Unit_Name --
2116 ------------------------
2118 function Find_Lib_Unit_Name return Entity_Id is
2120 -- Return inner compilation unit entity, for case of nested
2121 -- categorization pragmas. This happens in generic unit.
2123 if Nkind (Parent (N)) = N_Package_Specification
2124 and then Defining_Entity (Parent (N)) /= Current_Scope
2126 return Defining_Entity (Parent (N));
2128 return Current_Scope;
2130 end Find_Lib_Unit_Name;
2132 ----------------------------
2133 -- Find_Program_Unit_Name --
2134 ----------------------------
2136 procedure Find_Program_Unit_Name (Id : Node_Id) is
2137 Unit_Name : Entity_Id;
2138 Unit_Kind : Node_Kind;
2139 P : constant Node_Id := Parent (N);
2142 if Nkind (P) = N_Compilation_Unit then
2143 Unit_Kind := Nkind (Unit (P));
2145 if Unit_Kind = N_Subprogram_Declaration
2146 or else Unit_Kind = N_Package_Declaration
2147 or else Unit_Kind in N_Generic_Declaration
2149 Unit_Name := Defining_Entity (Unit (P));
2151 if Chars (Id) = Chars (Unit_Name) then
2152 Set_Entity (Id, Unit_Name);
2153 Set_Etype (Id, Etype (Unit_Name));
2155 Set_Etype (Id, Any_Type);
2157 ("cannot find program unit referenced by pragma%");
2161 Set_Etype (Id, Any_Type);
2162 Error_Pragma ("pragma% inapplicable to this unit");
2168 end Find_Program_Unit_Name;
2170 -----------------------------------------
2171 -- Find_Unique_Parameterless_Procedure --
2172 -----------------------------------------
2174 function Find_Unique_Parameterless_Procedure
2176 Arg : Node_Id) return Entity_Id
2178 Proc : Entity_Id := Empty;
2181 -- The body of this procedure needs some comments ???
2183 if not Is_Entity_Name (Name) then
2185 ("argument of pragma% must be entity name", Arg);
2187 elsif not Is_Overloaded (Name) then
2188 Proc := Entity (Name);
2190 if Ekind (Proc) /= E_Procedure
2191 or else Present (First_Formal (Proc))
2194 ("argument of pragma% must be parameterless procedure", Arg);
2199 Found : Boolean := False;
2201 Index : Interp_Index;
2204 Get_First_Interp (Name, Index, It);
2205 while Present (It.Nam) loop
2208 if Ekind (Proc) = E_Procedure
2209 and then No (First_Formal (Proc))
2213 Set_Entity (Name, Proc);
2214 Set_Is_Overloaded (Name, False);
2217 ("ambiguous handler name for pragma% ", Arg);
2221 Get_Next_Interp (Index, It);
2226 ("argument of pragma% must be parameterless procedure",
2229 Proc := Entity (Name);
2235 end Find_Unique_Parameterless_Procedure;
2241 procedure Fix_Error (Msg : in out String) is
2243 if From_Aspect_Specification (N) then
2244 for J in Msg'First .. Msg'Last - 5 loop
2245 if Msg (J .. J + 5) = "pragma" then
2246 Msg (J .. J + 5) := "aspect";
2250 if Error_Msg_Name_1 = Name_Precondition then
2251 Error_Msg_Name_1 := Name_Pre;
2252 elsif Error_Msg_Name_1 = Name_Postcondition then
2253 Error_Msg_Name_1 := Name_Post;
2258 -------------------------
2259 -- Gather_Associations --
2260 -------------------------
2262 procedure Gather_Associations
2264 Args : out Args_List)
2269 -- Initialize all parameters to Empty
2271 for J in Args'Range loop
2275 -- That's all we have to do if there are no argument associations
2277 if No (Pragma_Argument_Associations (N)) then
2281 -- Otherwise first deal with any positional parameters present
2283 Arg := First (Pragma_Argument_Associations (N));
2284 for Index in Args'Range loop
2285 exit when No (Arg) or else Chars (Arg) /= No_Name;
2286 Args (Index) := Get_Pragma_Arg (Arg);
2290 -- Positional parameters all processed, if any left, then we
2291 -- have too many positional parameters.
2293 if Present (Arg) and then Chars (Arg) = No_Name then
2295 ("too many positional associations for pragma%", Arg);
2298 -- Process named parameters if any are present
2300 while Present (Arg) loop
2301 if Chars (Arg) = No_Name then
2303 ("positional association cannot follow named association",
2307 for Index in Names'Range loop
2308 if Names (Index) = Chars (Arg) then
2309 if Present (Args (Index)) then
2311 ("duplicate argument association for pragma%", Arg);
2313 Args (Index) := Get_Pragma_Arg (Arg);
2318 if Index = Names'Last then
2319 Error_Msg_Name_1 := Pname;
2320 Error_Msg_N ("pragma% does not allow & argument", Arg);
2322 -- Check for possible misspelling
2324 for Index1 in Names'Range loop
2325 if Is_Bad_Spelling_Of
2326 (Chars (Arg), Names (Index1))
2328 Error_Msg_Name_1 := Names (Index1);
2329 Error_Msg_N -- CODEFIX
2330 ("\possible misspelling of%", Arg);
2342 end Gather_Associations;
2348 procedure GNAT_Pragma is
2350 Check_Restriction (No_Implementation_Pragmas, N);
2353 --------------------------
2354 -- Is_Before_First_Decl --
2355 --------------------------
2357 function Is_Before_First_Decl
2358 (Pragma_Node : Node_Id;
2359 Decls : List_Id) return Boolean
2361 Item : Node_Id := First (Decls);
2364 -- Only other pragmas can come before this pragma
2367 if No (Item) or else Nkind (Item) /= N_Pragma then
2370 elsif Item = Pragma_Node then
2376 end Is_Before_First_Decl;
2378 -----------------------------
2379 -- Is_Configuration_Pragma --
2380 -----------------------------
2382 -- A configuration pragma must appear in the context clause of a
2383 -- compilation unit, and only other pragmas may precede it. Note that
2384 -- the test below also permits use in a configuration pragma file.
2386 function Is_Configuration_Pragma return Boolean is
2387 Lis : constant List_Id := List_Containing (N);
2388 Par : constant Node_Id := Parent (N);
2392 -- If no parent, then we are in the configuration pragma file,
2393 -- so the placement is definitely appropriate.
2398 -- Otherwise we must be in the context clause of a compilation unit
2399 -- and the only thing allowed before us in the context list is more
2400 -- configuration pragmas.
2402 elsif Nkind (Par) = N_Compilation_Unit
2403 and then Context_Items (Par) = Lis
2410 elsif Nkind (Prg) /= N_Pragma then
2420 end Is_Configuration_Pragma;
2422 --------------------------
2423 -- Is_In_Context_Clause --
2424 --------------------------
2426 function Is_In_Context_Clause return Boolean is
2428 Parent_Node : Node_Id;
2431 if not Is_List_Member (N) then
2435 Plist := List_Containing (N);
2436 Parent_Node := Parent (Plist);
2438 if Parent_Node = Empty
2439 or else Nkind (Parent_Node) /= N_Compilation_Unit
2440 or else Context_Items (Parent_Node) /= Plist
2447 end Is_In_Context_Clause;
2449 ---------------------------------
2450 -- Is_Static_String_Expression --
2451 ---------------------------------
2453 function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2454 Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2457 Analyze_And_Resolve (Argx);
2458 return Is_OK_Static_Expression (Argx)
2459 and then Nkind (Argx) = N_String_Literal;
2460 end Is_Static_String_Expression;
2462 ----------------------
2463 -- Pragma_Misplaced --
2464 ----------------------
2466 procedure Pragma_Misplaced is
2468 Error_Pragma ("incorrect placement of pragma%");
2469 end Pragma_Misplaced;
2471 ------------------------------------
2472 -- Process Atomic_Shared_Volatile --
2473 ------------------------------------
2475 procedure Process_Atomic_Shared_Volatile is
2482 procedure Set_Atomic (E : Entity_Id);
2483 -- Set given type as atomic, and if no explicit alignment was given,
2484 -- set alignment to unknown, since back end knows what the alignment
2485 -- requirements are for atomic arrays. Note: this step is necessary
2486 -- for derived types.
2492 procedure Set_Atomic (E : Entity_Id) is
2496 if not Has_Alignment_Clause (E) then
2497 Set_Alignment (E, Uint_0);
2501 -- Start of processing for Process_Atomic_Shared_Volatile
2504 Check_Ada_83_Warning;
2505 Check_No_Identifiers;
2506 Check_Arg_Count (1);
2507 Check_Arg_Is_Local_Name (Arg1);
2508 E_Id := Get_Pragma_Arg (Arg1);
2510 if Etype (E_Id) = Any_Type then
2515 D := Declaration_Node (E);
2518 -- Check duplicate before we chain ourselves!
2520 Check_Duplicate_Pragma (E);
2522 -- Now check appropriateness of the entity
2525 if Rep_Item_Too_Early (E, N)
2527 Rep_Item_Too_Late (E, N)
2531 Check_First_Subtype (Arg1);
2534 if Prag_Id /= Pragma_Volatile then
2536 Set_Atomic (Underlying_Type (E));
2537 Set_Atomic (Base_Type (E));
2540 -- Attribute belongs on the base type. If the view of the type is
2541 -- currently private, it also belongs on the underlying type.
2543 Set_Is_Volatile (Base_Type (E));
2544 Set_Is_Volatile (Underlying_Type (E));
2546 Set_Treat_As_Volatile (E);
2547 Set_Treat_As_Volatile (Underlying_Type (E));
2549 elsif K = N_Object_Declaration
2550 or else (K = N_Component_Declaration
2551 and then Original_Record_Component (E) = E)
2553 if Rep_Item_Too_Late (E, N) then
2557 if Prag_Id /= Pragma_Volatile then
2560 -- If the object declaration has an explicit initialization, a
2561 -- temporary may have to be created to hold the expression, to
2562 -- ensure that access to the object remain atomic.
2564 if Nkind (Parent (E)) = N_Object_Declaration
2565 and then Present (Expression (Parent (E)))
2567 Set_Has_Delayed_Freeze (E);
2570 -- An interesting improvement here. If an object of type X is
2571 -- declared atomic, and the type X is not atomic, that's a
2572 -- pity, since it may not have appropriate alignment etc. We
2573 -- can rescue this in the special case where the object and
2574 -- type are in the same unit by just setting the type as
2575 -- atomic, so that the back end will process it as atomic.
2577 Utyp := Underlying_Type (Etype (E));
2580 and then Sloc (E) > No_Location
2581 and then Sloc (Utyp) > No_Location
2583 Get_Source_File_Index (Sloc (E)) =
2584 Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2586 Set_Is_Atomic (Underlying_Type (Etype (E)));
2590 Set_Is_Volatile (E);
2591 Set_Treat_As_Volatile (E);
2595 ("inappropriate entity for pragma%", Arg1);
2597 end Process_Atomic_Shared_Volatile;
2599 -------------------------------------------
2600 -- Process_Compile_Time_Warning_Or_Error --
2601 -------------------------------------------
2603 procedure Process_Compile_Time_Warning_Or_Error is
2604 Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2607 Check_Arg_Count (2);
2608 Check_No_Identifiers;
2609 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2610 Analyze_And_Resolve (Arg1x, Standard_Boolean);
2612 if Compile_Time_Known_Value (Arg1x) then
2613 if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2615 Str : constant String_Id :=
2616 Strval (Get_Pragma_Arg (Arg2));
2617 Len : constant Int := String_Length (Str);
2622 Cent : constant Entity_Id :=
2623 Cunit_Entity (Current_Sem_Unit);
2625 Force : constant Boolean :=
2626 Prag_Id = Pragma_Compile_Time_Warning
2628 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2629 and then (Ekind (Cent) /= E_Package
2630 or else not In_Private_Part (Cent));
2631 -- Set True if this is the warning case, and we are in the
2632 -- visible part of a package spec, or in a subprogram spec,
2633 -- in which case we want to force the client to see the
2634 -- warning, even though it is not in the main unit.
2637 -- Loop through segments of message separated by line feeds.
2638 -- We output these segments as separate messages with
2639 -- continuation marks for all but the first.
2644 Error_Msg_Strlen := 0;
2646 -- Loop to copy characters from argument to error message
2650 exit when Ptr > Len;
2651 CC := Get_String_Char (Str, Ptr);
2654 -- Ignore wide chars ??? else store character
2656 if In_Character_Range (CC) then
2657 C := Get_Character (CC);
2658 exit when C = ASCII.LF;
2659 Error_Msg_Strlen := Error_Msg_Strlen + 1;
2660 Error_Msg_String (Error_Msg_Strlen) := C;
2664 -- Here with one line ready to go
2666 Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2668 -- If this is a warning in a spec, then we want clients
2669 -- to see the warning, so mark the message with the
2670 -- special sequence !! to force the warning. In the case
2671 -- of a package spec, we do not force this if we are in
2672 -- the private part of the spec.
2675 if Cont = False then
2676 Error_Msg_N ("<~!!", Arg1);
2679 Error_Msg_N ("\<~!!", Arg1);
2682 -- Error, rather than warning, or in a body, so we do not
2683 -- need to force visibility for client (error will be
2684 -- output in any case, and this is the situation in which
2685 -- we do not want a client to get a warning, since the
2686 -- warning is in the body or the spec private part).
2689 if Cont = False then
2690 Error_Msg_N ("<~", Arg1);
2693 Error_Msg_N ("\<~", Arg1);
2697 exit when Ptr > Len;
2702 end Process_Compile_Time_Warning_Or_Error;
2704 ------------------------
2705 -- Process_Convention --
2706 ------------------------
2708 procedure Process_Convention
2709 (C : out Convention_Id;
2710 Ent : out Entity_Id)
2716 Comp_Unit : Unit_Number_Type;
2718 procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2719 -- Called if we have more than one Export/Import/Convention pragma.
2720 -- This is generally illegal, but we have a special case of allowing
2721 -- Import and Interface to coexist if they specify the convention in
2722 -- a consistent manner. We are allowed to do this, since Interface is
2723 -- an implementation defined pragma, and we choose to do it since we
2724 -- know Rational allows this combination. S is the entity id of the
2725 -- subprogram in question. This procedure also sets the special flag
2726 -- Import_Interface_Present in both pragmas in the case where we do
2727 -- have matching Import and Interface pragmas.
2729 procedure Set_Convention_From_Pragma (E : Entity_Id);
2730 -- Set convention in entity E, and also flag that the entity has a
2731 -- convention pragma. If entity is for a private or incomplete type,
2732 -- also set convention and flag on underlying type. This procedure
2733 -- also deals with the special case of C_Pass_By_Copy convention.
2735 -------------------------------
2736 -- Diagnose_Multiple_Pragmas --
2737 -------------------------------
2739 procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2740 Pdec : constant Node_Id := Declaration_Node (S);
2744 function Same_Convention (Decl : Node_Id) return Boolean;
2745 -- Decl is a pragma node. This function returns True if this
2746 -- pragma has a first argument that is an identifier with a
2747 -- Chars field corresponding to the Convention_Id C.
2749 function Same_Name (Decl : Node_Id) return Boolean;
2750 -- Decl is a pragma node. This function returns True if this
2751 -- pragma has a second argument that is an identifier with a
2752 -- Chars field that matches the Chars of the current subprogram.
2754 ---------------------
2755 -- Same_Convention --
2756 ---------------------
2758 function Same_Convention (Decl : Node_Id) return Boolean is
2759 Arg1 : constant Node_Id :=
2760 First (Pragma_Argument_Associations (Decl));
2763 if Present (Arg1) then
2765 Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2767 if Nkind (Arg) = N_Identifier
2768 and then Is_Convention_Name (Chars (Arg))
2769 and then Get_Convention_Id (Chars (Arg)) = C
2777 end Same_Convention;
2783 function Same_Name (Decl : Node_Id) return Boolean is
2784 Arg1 : constant Node_Id :=
2785 First (Pragma_Argument_Associations (Decl));
2793 Arg2 := Next (Arg1);
2800 Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2802 if Nkind (Arg) = N_Identifier
2803 and then Chars (Arg) = Chars (S)
2812 -- Start of processing for Diagnose_Multiple_Pragmas
2817 -- Definitely give message if we have Convention/Export here
2819 if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
2822 -- If we have an Import or Export, scan back from pragma to
2823 -- find any previous pragma applying to the same procedure.
2824 -- The scan will be terminated by the start of the list, or
2825 -- hitting the subprogram declaration. This won't allow one
2826 -- pragma to appear in the public part and one in the private
2827 -- part, but that seems very unlikely in practice.
2831 while Present (Decl) and then Decl /= Pdec loop
2833 -- Look for pragma with same name as us
2835 if Nkind (Decl) = N_Pragma
2836 and then Same_Name (Decl)
2838 -- Give error if same as our pragma or Export/Convention
2840 if Pragma_Name (Decl) = Name_Export
2842 Pragma_Name (Decl) = Name_Convention
2844 Pragma_Name (Decl) = Pragma_Name (N)
2848 -- Case of Import/Interface or the other way round
2850 elsif Pragma_Name (Decl) = Name_Interface
2852 Pragma_Name (Decl) = Name_Import
2854 -- Here we know that we have Import and Interface. It
2855 -- doesn't matter which way round they are. See if
2856 -- they specify the same convention. If so, all OK,
2857 -- and set special flags to stop other messages
2859 if Same_Convention (Decl) then
2860 Set_Import_Interface_Present (N);
2861 Set_Import_Interface_Present (Decl);
2864 -- If different conventions, special message
2867 Error_Msg_Sloc := Sloc (Decl);
2869 ("convention differs from that given#", Arg1);
2879 -- Give message if needed if we fall through those tests
2883 ("at most one Convention/Export/Import pragma is allowed",
2886 end Diagnose_Multiple_Pragmas;
2888 --------------------------------
2889 -- Set_Convention_From_Pragma --
2890 --------------------------------
2892 procedure Set_Convention_From_Pragma (E : Entity_Id) is
2894 -- Ada 2005 (AI-430): Check invalid attempt to change convention
2895 -- for an overridden dispatching operation. Technically this is
2896 -- an amendment and should only be done in Ada 2005 mode. However,
2897 -- this is clearly a mistake, since the problem that is addressed
2898 -- by this AI is that there is a clear gap in the RM!
2900 if Is_Dispatching_Operation (E)
2901 and then Present (Overridden_Operation (E))
2902 and then C /= Convention (Overridden_Operation (E))
2905 ("cannot change convention for " &
2906 "overridden dispatching operation",
2910 -- Set the convention
2912 Set_Convention (E, C);
2913 Set_Has_Convention_Pragma (E);
2915 if Is_Incomplete_Or_Private_Type (E)
2916 and then Present (Underlying_Type (E))
2918 Set_Convention (Underlying_Type (E), C);
2919 Set_Has_Convention_Pragma (Underlying_Type (E), True);
2922 -- A class-wide type should inherit the convention of the specific
2923 -- root type (although this isn't specified clearly by the RM).
2925 if Is_Type (E) and then Present (Class_Wide_Type (E)) then
2926 Set_Convention (Class_Wide_Type (E), C);
2929 -- If the entity is a record type, then check for special case of
2930 -- C_Pass_By_Copy, which is treated the same as C except that the
2931 -- special record flag is set. This convention is only permitted
2932 -- on record types (see AI95-00131).
2934 if Cname = Name_C_Pass_By_Copy then
2935 if Is_Record_Type (E) then
2936 Set_C_Pass_By_Copy (Base_Type (E));
2937 elsif Is_Incomplete_Or_Private_Type (E)
2938 and then Is_Record_Type (Underlying_Type (E))
2940 Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
2943 ("C_Pass_By_Copy convention allowed only for record type",
2948 -- If the entity is a derived boolean type, check for the special
2949 -- case of convention C, C++, or Fortran, where we consider any
2950 -- nonzero value to represent true.
2952 if Is_Discrete_Type (E)
2953 and then Root_Type (Etype (E)) = Standard_Boolean
2959 C = Convention_Fortran)
2961 Set_Nonzero_Is_True (Base_Type (E));
2963 end Set_Convention_From_Pragma;
2965 -- Start of processing for Process_Convention
2968 Check_At_Least_N_Arguments (2);
2969 Check_Optional_Identifier (Arg1, Name_Convention);
2970 Check_Arg_Is_Identifier (Arg1);
2971 Cname := Chars (Get_Pragma_Arg (Arg1));
2973 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
2974 -- tested again below to set the critical flag).
2976 if Cname = Name_C_Pass_By_Copy then
2979 -- Otherwise we must have something in the standard convention list
2981 elsif Is_Convention_Name (Cname) then
2982 C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
2984 -- In DEC VMS, it seems that there is an undocumented feature that
2985 -- any unrecognized convention is treated as the default, which for
2986 -- us is convention C. It does not seem so terrible to do this
2987 -- unconditionally, silently in the VMS case, and with a warning
2988 -- in the non-VMS case.
2991 if Warn_On_Export_Import and not OpenVMS_On_Target then
2993 ("?unrecognized convention name, C assumed",
2994 Get_Pragma_Arg (Arg1));
3000 Check_Optional_Identifier (Arg2, Name_Entity);
3001 Check_Arg_Is_Local_Name (Arg2);
3003 Id := Get_Pragma_Arg (Arg2);
3006 if not Is_Entity_Name (Id) then
3007 Error_Pragma_Arg ("entity name required", Arg2);
3012 -- Set entity to return
3016 -- Ada_Pass_By_Copy special checking
3018 if C = Convention_Ada_Pass_By_Copy then
3019 if not Is_First_Subtype (E) then
3021 ("convention `Ada_Pass_By_Copy` only "
3022 & "allowed for types", Arg2);
3025 if Is_By_Reference_Type (E) then
3027 ("convention `Ada_Pass_By_Copy` not allowed for "
3028 & "by-reference type", Arg1);
3032 -- Ada_Pass_By_Reference special checking
3034 if C = Convention_Ada_Pass_By_Reference then
3035 if not Is_First_Subtype (E) then
3037 ("convention `Ada_Pass_By_Reference` only "
3038 & "allowed for types", Arg2);
3041 if Is_By_Copy_Type (E) then
3043 ("convention `Ada_Pass_By_Reference` not allowed for "
3044 & "by-copy type", Arg1);
3048 -- Go to renamed subprogram if present, since convention applies to
3049 -- the actual renamed entity, not to the renaming entity. If the
3050 -- subprogram is inherited, go to parent subprogram.
3052 if Is_Subprogram (E)
3053 and then Present (Alias (E))
3055 if Nkind (Parent (Declaration_Node (E))) =
3056 N_Subprogram_Renaming_Declaration
3058 if Scope (E) /= Scope (Alias (E)) then
3060 ("cannot apply pragma% to non-local entity&#", E);
3065 elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3066 N_Private_Extension_Declaration)
3067 and then Scope (E) = Scope (Alias (E))
3071 -- Return the parent subprogram the entity was inherited from
3077 -- Check that we are not applying this to a specless body
3079 if Is_Subprogram (E)
3080 and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3083 ("pragma% requires separate spec and must come before body");
3086 -- Check that we are not applying this to a named constant
3088 if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3089 Error_Msg_Name_1 := Pname;
3091 ("cannot apply pragma% to named constant!",
3092 Get_Pragma_Arg (Arg2));
3094 ("\supply appropriate type for&!", Arg2);
3097 if Ekind (E) = E_Enumeration_Literal then
3098 Error_Pragma ("enumeration literal not allowed for pragma%");
3101 -- Check for rep item appearing too early or too late
3103 if Etype (E) = Any_Type
3104 or else Rep_Item_Too_Early (E, N)
3108 elsif Present (Underlying_Type (E)) then
3109 E := Underlying_Type (E);
3112 if Rep_Item_Too_Late (E, N) then
3116 if Has_Convention_Pragma (E) then
3117 Diagnose_Multiple_Pragmas (E);
3119 elsif Convention (E) = Convention_Protected
3120 or else Ekind (Scope (E)) = E_Protected_Type
3123 ("a protected operation cannot be given a different convention",
3127 -- For Intrinsic, a subprogram is required
3129 if C = Convention_Intrinsic
3130 and then not Is_Subprogram (E)
3131 and then not Is_Generic_Subprogram (E)
3134 ("second argument of pragma% must be a subprogram", Arg2);
3137 -- For Stdcall, a subprogram, variable or subprogram type is required
3139 if C = Convention_Stdcall
3140 and then not Is_Subprogram (E)
3141 and then not Is_Generic_Subprogram (E)
3142 and then Ekind (E) /= E_Variable
3145 and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3148 ("second argument of pragma% must be subprogram (type)",
3152 if not Is_Subprogram (E)
3153 and then not Is_Generic_Subprogram (E)
3155 Set_Convention_From_Pragma (E);
3158 Check_First_Subtype (Arg2);
3159 Set_Convention_From_Pragma (Base_Type (E));
3161 -- For subprograms, we must set the convention on the
3162 -- internally generated directly designated type as well.
3164 if Ekind (E) = E_Access_Subprogram_Type then
3165 Set_Convention_From_Pragma (Directly_Designated_Type (E));
3169 -- For the subprogram case, set proper convention for all homonyms
3170 -- in same scope and the same declarative part, i.e. the same
3171 -- compilation unit.
3174 Comp_Unit := Get_Source_Unit (E);
3175 Set_Convention_From_Pragma (E);
3177 -- Treat a pragma Import as an implicit body, for GPS use
3179 if Prag_Id = Pragma_Import then
3180 Generate_Reference (E, Id, 'b');
3183 -- Loop through the homonyms of the pragma argument's entity
3188 exit when No (E1) or else Scope (E1) /= Current_Scope;
3190 -- Do not set the pragma on inherited operations or on formal
3193 if Comes_From_Source (E1)
3194 and then Comp_Unit = Get_Source_Unit (E1)
3195 and then not Is_Formal_Subprogram (E1)
3196 and then Nkind (Original_Node (Parent (E1))) /=
3197 N_Full_Type_Declaration
3199 if Present (Alias (E1))
3200 and then Scope (E1) /= Scope (Alias (E1))
3203 ("cannot apply pragma% to non-local entity& declared#",
3207 Set_Convention_From_Pragma (E1);
3209 if Prag_Id = Pragma_Import then
3210 Generate_Reference (E1, Id, 'b');
3214 -- For aspect case, do NOT apply to homonyms
3216 exit when From_Aspect_Specification (N);
3219 end Process_Convention;
3221 -----------------------------------------------------
3222 -- Process_Extended_Import_Export_Exception_Pragma --
3223 -----------------------------------------------------
3225 procedure Process_Extended_Import_Export_Exception_Pragma
3226 (Arg_Internal : Node_Id;
3227 Arg_External : Node_Id;
3235 if not OpenVMS_On_Target then
3237 ("?pragma% ignored (applies only to Open'V'M'S)");
3240 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3241 Def_Id := Entity (Arg_Internal);
3243 if Ekind (Def_Id) /= E_Exception then
3245 ("pragma% must refer to declared exception", Arg_Internal);
3248 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3250 if Present (Arg_Form) then
3251 Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3254 if Present (Arg_Form)
3255 and then Chars (Arg_Form) = Name_Ada
3259 Set_Is_VMS_Exception (Def_Id);
3260 Set_Exception_Code (Def_Id, No_Uint);
3263 if Present (Arg_Code) then
3264 if not Is_VMS_Exception (Def_Id) then
3266 ("Code option for pragma% not allowed for Ada case",
3270 Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3271 Code_Val := Expr_Value (Arg_Code);
3273 if not UI_Is_In_Int_Range (Code_Val) then
3275 ("Code option for pragma% must be in 32-bit range",
3279 Set_Exception_Code (Def_Id, Code_Val);
3282 end Process_Extended_Import_Export_Exception_Pragma;
3284 -------------------------------------------------
3285 -- Process_Extended_Import_Export_Internal_Arg --
3286 -------------------------------------------------
3288 procedure Process_Extended_Import_Export_Internal_Arg
3289 (Arg_Internal : Node_Id := Empty)
3292 if No (Arg_Internal) then
3293 Error_Pragma ("Internal parameter required for pragma%");
3296 if Nkind (Arg_Internal) = N_Identifier then
3299 elsif Nkind (Arg_Internal) = N_Operator_Symbol
3300 and then (Prag_Id = Pragma_Import_Function
3302 Prag_Id = Pragma_Export_Function)
3308 ("wrong form for Internal parameter for pragma%", Arg_Internal);
3311 Check_Arg_Is_Local_Name (Arg_Internal);
3312 end Process_Extended_Import_Export_Internal_Arg;
3314 --------------------------------------------------
3315 -- Process_Extended_Import_Export_Object_Pragma --
3316 --------------------------------------------------
3318 procedure Process_Extended_Import_Export_Object_Pragma
3319 (Arg_Internal : Node_Id;
3320 Arg_External : Node_Id;
3326 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3327 Def_Id := Entity (Arg_Internal);
3329 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3331 ("pragma% must designate an object", Arg_Internal);
3334 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3336 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3339 ("previous Common/Psect_Object applies, pragma % not permitted",
3343 if Rep_Item_Too_Late (Def_Id, N) then
3347 Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3349 if Present (Arg_Size) then
3350 Check_Arg_Is_External_Name (Arg_Size);
3353 -- Export_Object case
3355 if Prag_Id = Pragma_Export_Object then
3356 if not Is_Library_Level_Entity (Def_Id) then
3358 ("argument for pragma% must be library level entity",
3362 if Ekind (Current_Scope) = E_Generic_Package then
3363 Error_Pragma ("pragma& cannot appear in a generic unit");
3366 if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3368 ("exported object must have compile time known size",
3372 if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3373 Error_Msg_N ("?duplicate Export_Object pragma", N);
3375 Set_Exported (Def_Id, Arg_Internal);
3378 -- Import_Object case
3381 if Is_Concurrent_Type (Etype (Def_Id)) then
3383 ("cannot use pragma% for task/protected object",
3387 if Ekind (Def_Id) = E_Constant then
3389 ("cannot import a constant", Arg_Internal);
3392 if Warn_On_Export_Import
3393 and then Has_Discriminants (Etype (Def_Id))
3396 ("imported value must be initialized?", Arg_Internal);
3399 if Warn_On_Export_Import
3400 and then Is_Access_Type (Etype (Def_Id))
3403 ("cannot import object of an access type?", Arg_Internal);
3406 if Warn_On_Export_Import
3407 and then Is_Imported (Def_Id)
3410 ("?duplicate Import_Object pragma", N);
3412 -- Check for explicit initialization present. Note that an
3413 -- initialization generated by the code generator, e.g. for an
3414 -- access type, does not count here.
3416 elsif Present (Expression (Parent (Def_Id)))
3419 (Original_Node (Expression (Parent (Def_Id))))
3421 Error_Msg_Sloc := Sloc (Def_Id);
3423 ("imported entities cannot be initialized (RM B.1(24))",
3424 "\no initialization allowed for & declared#", Arg1);
3426 Set_Imported (Def_Id);
3427 Note_Possible_Modification (Arg_Internal, Sure => False);
3430 end Process_Extended_Import_Export_Object_Pragma;
3432 ------------------------------------------------------
3433 -- Process_Extended_Import_Export_Subprogram_Pragma --
3434 ------------------------------------------------------
3436 procedure Process_Extended_Import_Export_Subprogram_Pragma
3437 (Arg_Internal : Node_Id;
3438 Arg_External : Node_Id;
3439 Arg_Parameter_Types : Node_Id;
3440 Arg_Result_Type : Node_Id := Empty;
3441 Arg_Mechanism : Node_Id;
3442 Arg_Result_Mechanism : Node_Id := Empty;
3443 Arg_First_Optional_Parameter : Node_Id := Empty)
3449 Ambiguous : Boolean;
3453 function Same_Base_Type
3455 Formal : Entity_Id) return Boolean;
3456 -- Determines if Ptype references the type of Formal. Note that only
3457 -- the base types need to match according to the spec. Ptype here is
3458 -- the argument from the pragma, which is either a type name, or an
3459 -- access attribute.
3461 --------------------
3462 -- Same_Base_Type --
3463 --------------------
3465 function Same_Base_Type
3467 Formal : Entity_Id) return Boolean
3469 Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3473 -- Case where pragma argument is typ'Access
3475 if Nkind (Ptype) = N_Attribute_Reference
3476 and then Attribute_Name (Ptype) = Name_Access
3478 Pref := Prefix (Ptype);
3481 if not Is_Entity_Name (Pref)
3482 or else Entity (Pref) = Any_Type
3487 -- We have a match if the corresponding argument is of an
3488 -- anonymous access type, and its designated type matches the
3489 -- type of the prefix of the access attribute
3491 return Ekind (Ftyp) = E_Anonymous_Access_Type
3492 and then Base_Type (Entity (Pref)) =
3493 Base_Type (Etype (Designated_Type (Ftyp)));
3495 -- Case where pragma argument is a type name
3500 if not Is_Entity_Name (Ptype)
3501 or else Entity (Ptype) = Any_Type
3506 -- We have a match if the corresponding argument is of the type
3507 -- given in the pragma (comparing base types)
3509 return Base_Type (Entity (Ptype)) = Ftyp;
3513 -- Start of processing for
3514 -- Process_Extended_Import_Export_Subprogram_Pragma
3517 Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3521 -- Loop through homonyms (overloadings) of the entity
3523 Hom_Id := Entity (Arg_Internal);
3524 while Present (Hom_Id) loop
3525 Def_Id := Get_Base_Subprogram (Hom_Id);
3527 -- We need a subprogram in the current scope
3529 if not Is_Subprogram (Def_Id)
3530 or else Scope (Def_Id) /= Current_Scope
3537 -- Pragma cannot apply to subprogram body
3539 if Is_Subprogram (Def_Id)
3540 and then Nkind (Parent (Declaration_Node (Def_Id))) =
3544 ("pragma% requires separate spec"
3545 & " and must come before body");
3548 -- Test result type if given, note that the result type
3549 -- parameter can only be present for the function cases.
3551 if Present (Arg_Result_Type)
3552 and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3556 elsif Etype (Def_Id) /= Standard_Void_Type
3558 (Pname = Name_Export_Procedure
3560 Pname = Name_Import_Procedure)
3564 -- Test parameter types if given. Note that this parameter
3565 -- has not been analyzed (and must not be, since it is
3566 -- semantic nonsense), so we get it as the parser left it.
3568 elsif Present (Arg_Parameter_Types) then
3569 Check_Matching_Types : declare
3574 Formal := First_Formal (Def_Id);
3576 if Nkind (Arg_Parameter_Types) = N_Null then
3577 if Present (Formal) then
3581 -- A list of one type, e.g. (List) is parsed as
3582 -- a parenthesized expression.
3584 elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3585 and then Paren_Count (Arg_Parameter_Types) = 1
3588 or else Present (Next_Formal (Formal))
3593 Same_Base_Type (Arg_Parameter_Types, Formal);
3596 -- A list of more than one type is parsed as a aggregate
3598 elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3599 and then Paren_Count (Arg_Parameter_Types) = 0
3601 Ptype := First (Expressions (Arg_Parameter_Types));
3602 while Present (Ptype) or else Present (Formal) loop
3605 or else not Same_Base_Type (Ptype, Formal)
3610 Next_Formal (Formal);
3615 -- Anything else is of the wrong form
3619 ("wrong form for Parameter_Types parameter",
3620 Arg_Parameter_Types);
3622 end Check_Matching_Types;
3625 -- Match is now False if the entry we found did not match
3626 -- either a supplied Parameter_Types or Result_Types argument
3632 -- Ambiguous case, the flag Ambiguous shows if we already
3633 -- detected this and output the initial messages.
3636 if not Ambiguous then
3638 Error_Msg_Name_1 := Pname;
3640 ("pragma% does not uniquely identify subprogram!",
3642 Error_Msg_Sloc := Sloc (Ent);
3643 Error_Msg_N ("matching subprogram #!", N);
3647 Error_Msg_Sloc := Sloc (Def_Id);
3648 Error_Msg_N ("matching subprogram #!", N);
3653 Hom_Id := Homonym (Hom_Id);
3656 -- See if we found an entry
3659 if not Ambiguous then
3660 if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3662 ("pragma% cannot be given for generic subprogram");
3665 ("pragma% does not identify local subprogram");
3672 -- Import pragmas must be for imported entities
3674 if Prag_Id = Pragma_Import_Function
3676 Prag_Id = Pragma_Import_Procedure
3678 Prag_Id = Pragma_Import_Valued_Procedure
3680 if not Is_Imported (Ent) then
3682 ("pragma Import or Interface must precede pragma%");
3685 -- Here we have the Export case which can set the entity as exported
3687 -- But does not do so if the specified external name is null, since
3688 -- that is taken as a signal in DEC Ada 83 (with which we want to be
3689 -- compatible) to request no external name.
3691 elsif Nkind (Arg_External) = N_String_Literal
3692 and then String_Length (Strval (Arg_External)) = 0
3696 -- In all other cases, set entity as exported
3699 Set_Exported (Ent, Arg_Internal);
3702 -- Special processing for Valued_Procedure cases
3704 if Prag_Id = Pragma_Import_Valued_Procedure
3706 Prag_Id = Pragma_Export_Valued_Procedure
3708 Formal := First_Formal (Ent);
3711 Error_Pragma ("at least one parameter required for pragma%");
3713 elsif Ekind (Formal) /= E_Out_Parameter then
3714 Error_Pragma ("first parameter must have mode out for pragma%");
3717 Set_Is_Valued_Procedure (Ent);
3721 Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3723 -- Process Result_Mechanism argument if present. We have already
3724 -- checked that this is only allowed for the function case.
3726 if Present (Arg_Result_Mechanism) then
3727 Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3730 -- Process Mechanism parameter if present. Note that this parameter
3731 -- is not analyzed, and must not be analyzed since it is semantic
3732 -- nonsense, so we get it in exactly as the parser left it.
3734 if Present (Arg_Mechanism) then
3742 -- A single mechanism association without a formal parameter
3743 -- name is parsed as a parenthesized expression. All other
3744 -- cases are parsed as aggregates, so we rewrite the single
3745 -- parameter case as an aggregate for consistency.
3747 if Nkind (Arg_Mechanism) /= N_Aggregate
3748 and then Paren_Count (Arg_Mechanism) = 1
3750 Rewrite (Arg_Mechanism,
3751 Make_Aggregate (Sloc (Arg_Mechanism),
3752 Expressions => New_List (
3753 Relocate_Node (Arg_Mechanism))));
3756 -- Case of only mechanism name given, applies to all formals
3758 if Nkind (Arg_Mechanism) /= N_Aggregate then
3759 Formal := First_Formal (Ent);
3760 while Present (Formal) loop
3761 Set_Mechanism_Value (Formal, Arg_Mechanism);
3762 Next_Formal (Formal);
3765 -- Case of list of mechanism associations given
3768 if Null_Record_Present (Arg_Mechanism) then
3770 ("inappropriate form for Mechanism parameter",
3774 -- Deal with positional ones first
3776 Formal := First_Formal (Ent);
3778 if Present (Expressions (Arg_Mechanism)) then
3779 Mname := First (Expressions (Arg_Mechanism));
3780 while Present (Mname) loop
3783 ("too many mechanism associations", Mname);
3786 Set_Mechanism_Value (Formal, Mname);
3787 Next_Formal (Formal);
3792 -- Deal with named entries
3794 if Present (Component_Associations (Arg_Mechanism)) then
3795 Massoc := First (Component_Associations (Arg_Mechanism));
3796 while Present (Massoc) loop
3797 Choice := First (Choices (Massoc));
3799 if Nkind (Choice) /= N_Identifier
3800 or else Present (Next (Choice))
3803 ("incorrect form for mechanism association",
3807 Formal := First_Formal (Ent);
3811 ("parameter name & not present", Choice);
3814 if Chars (Choice) = Chars (Formal) then
3816 (Formal, Expression (Massoc));
3818 -- Set entity on identifier (needed by ASIS)
3820 Set_Entity (Choice, Formal);
3825 Next_Formal (Formal);
3835 -- Process First_Optional_Parameter argument if present. We have
3836 -- already checked that this is only allowed for the Import case.
3838 if Present (Arg_First_Optional_Parameter) then
3839 if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
3841 ("first optional parameter must be formal parameter name",
3842 Arg_First_Optional_Parameter);
3845 Formal := First_Formal (Ent);
3849 ("specified formal parameter& not found",
3850 Arg_First_Optional_Parameter);
3853 exit when Chars (Formal) =
3854 Chars (Arg_First_Optional_Parameter);
3856 Next_Formal (Formal);
3859 Set_First_Optional_Parameter (Ent, Formal);
3861 -- Check specified and all remaining formals have right form
3863 while Present (Formal) loop
3864 if Ekind (Formal) /= E_In_Parameter then
3866 ("optional formal& is not of mode in!",
3867 Arg_First_Optional_Parameter, Formal);
3870 Dval := Default_Value (Formal);
3874 ("optional formal& does not have default value!",
3875 Arg_First_Optional_Parameter, Formal);
3877 elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
3882 ("default value for optional formal& is non-static!",
3883 Arg_First_Optional_Parameter, Formal);
3887 Set_Is_Optional_Parameter (Formal);
3888 Next_Formal (Formal);
3891 end Process_Extended_Import_Export_Subprogram_Pragma;
3893 --------------------------
3894 -- Process_Generic_List --
3895 --------------------------
3897 procedure Process_Generic_List is
3902 Check_No_Identifiers;
3903 Check_At_Least_N_Arguments (1);
3906 while Present (Arg) loop
3907 Exp := Get_Pragma_Arg (Arg);
3910 if not Is_Entity_Name (Exp)
3912 (not Is_Generic_Instance (Entity (Exp))
3914 not Is_Generic_Unit (Entity (Exp)))
3917 ("pragma% argument must be name of generic unit/instance",
3923 end Process_Generic_List;
3925 ------------------------------------
3926 -- Process_Import_Predefined_Type --
3927 ------------------------------------
3929 procedure Process_Import_Predefined_Type is
3930 Loc : constant Source_Ptr := Sloc (N);
3932 Ftyp : Node_Id := Empty;
3938 String_To_Name_Buffer (Strval (Expression (Arg3)));
3941 Elmt := First_Elmt (Predefined_Float_Types);
3942 while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
3946 Ftyp := Node (Elmt);
3948 if Present (Ftyp) then
3950 -- Don't build a derived type declaration, because predefined C
3951 -- types have no declaration anywhere, so cannot really be named.
3952 -- Instead build a full type declaration, starting with an
3953 -- appropriate type definition is built
3955 if Is_Floating_Point_Type (Ftyp) then
3956 Def := Make_Floating_Point_Definition (Loc,
3957 Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3958 Make_Real_Range_Specification (Loc,
3959 Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3960 Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3962 -- Should never have a predefined type we cannot handle
3965 raise Program_Error;
3968 -- Build and insert a Full_Type_Declaration, which will be
3969 -- analyzed as soon as this list entry has been analyzed.
3971 Decl := Make_Full_Type_Declaration (Loc,
3972 Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3973 Type_Definition => Def);
3975 Insert_After (N, Decl);
3976 Mark_Rewrite_Insertion (Decl);
3979 Error_Pragma_Arg ("no matching type found for pragma%",
3982 end Process_Import_Predefined_Type;
3984 ---------------------------------
3985 -- Process_Import_Or_Interface --
3986 ---------------------------------
3988 procedure Process_Import_Or_Interface is
3994 Process_Convention (C, Def_Id);
3995 Kill_Size_Check_Code (Def_Id);
3996 Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3998 if Ekind_In (Def_Id, E_Variable, E_Constant) then
4000 -- We do not permit Import to apply to a renaming declaration
4002 if Present (Renamed_Object (Def_Id)) then
4004 ("pragma% not allowed for object renaming", Arg2);
4006 -- User initialization is not allowed for imported object, but
4007 -- the object declaration may contain a default initialization,
4008 -- that will be discarded. Note that an explicit initialization
4009 -- only counts if it comes from source, otherwise it is simply
4010 -- the code generator making an implicit initialization explicit.
4012 elsif Present (Expression (Parent (Def_Id)))
4013 and then Comes_From_Source (Expression (Parent (Def_Id)))
4015 Error_Msg_Sloc := Sloc (Def_Id);
4017 ("no initialization allowed for declaration of& #",
4018 "\imported entities cannot be initialized (RM B.1(24))",
4022 Set_Imported (Def_Id);
4023 Process_Interface_Name (Def_Id, Arg3, Arg4);
4025 -- Note that we do not set Is_Public here. That's because we
4026 -- only want to set it if there is no address clause, and we
4027 -- don't know that yet, so we delay that processing till
4030 -- pragma Import completes deferred constants
4032 if Ekind (Def_Id) = E_Constant then
4033 Set_Has_Completion (Def_Id);
4036 -- It is not possible to import a constant of an unconstrained
4037 -- array type (e.g. string) because there is no simple way to
4038 -- write a meaningful subtype for it.
4040 if Is_Array_Type (Etype (Def_Id))
4041 and then not Is_Constrained (Etype (Def_Id))
4044 ("imported constant& must have a constrained subtype",
4049 elsif Is_Subprogram (Def_Id)
4050 or else Is_Generic_Subprogram (Def_Id)
4052 -- If the name is overloaded, pragma applies to all of the denoted
4053 -- entities in the same declarative part.
4056 while Present (Hom_Id) loop
4057 Def_Id := Get_Base_Subprogram (Hom_Id);
4059 -- Ignore inherited subprograms because the pragma will apply
4060 -- to the parent operation, which is the one called.
4062 if Is_Overloadable (Def_Id)
4063 and then Present (Alias (Def_Id))
4067 -- If it is not a subprogram, it must be in an outer scope and
4068 -- pragma does not apply.
4070 elsif not Is_Subprogram (Def_Id)
4071 and then not Is_Generic_Subprogram (Def_Id)
4075 -- The pragma does not apply to primitives of interfaces
4077 elsif Is_Dispatching_Operation (Def_Id)
4078 and then Present (Find_Dispatching_Type (Def_Id))
4079 and then Is_Interface (Find_Dispatching_Type (Def_Id))
4083 -- Verify that the homonym is in the same declarative part (not
4084 -- just the same scope).
4086 elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4087 and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4092 Set_Imported (Def_Id);
4094 -- Reject an Import applied to an abstract subprogram
4096 if Is_Subprogram (Def_Id)
4097 and then Is_Abstract_Subprogram (Def_Id)
4099 Error_Msg_Sloc := Sloc (Def_Id);
4101 ("cannot import abstract subprogram& declared#",
4105 -- Special processing for Convention_Intrinsic
4107 if C = Convention_Intrinsic then
4109 -- Link_Name argument not allowed for intrinsic
4113 Set_Is_Intrinsic_Subprogram (Def_Id);
4115 -- If no external name is present, then check that this
4116 -- is a valid intrinsic subprogram. If an external name
4117 -- is present, then this is handled by the back end.
4120 Check_Intrinsic_Subprogram
4121 (Def_Id, Get_Pragma_Arg (Arg2));
4125 -- All interfaced procedures need an external symbol created
4126 -- for them since they are always referenced from another
4129 Set_Is_Public (Def_Id);
4131 -- Verify that the subprogram does not have a completion
4132 -- through a renaming declaration. For other completions the
4133 -- pragma appears as a too late representation.
4136 Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4140 and then Nkind (Decl) = N_Subprogram_Declaration
4141 and then Present (Corresponding_Body (Decl))
4142 and then Nkind (Unit_Declaration_Node
4143 (Corresponding_Body (Decl))) =
4144 N_Subprogram_Renaming_Declaration
4146 Error_Msg_Sloc := Sloc (Def_Id);
4148 ("cannot import&, renaming already provided for " &
4149 "declaration #", N, Def_Id);
4153 Set_Has_Completion (Def_Id);
4154 Process_Interface_Name (Def_Id, Arg3, Arg4);
4157 if Is_Compilation_Unit (Hom_Id) then
4159 -- Its possible homonyms are not affected by the pragma.
4160 -- Such homonyms might be present in the context of other
4161 -- units being compiled.
4166 Hom_Id := Homonym (Hom_Id);
4170 -- When the convention is Java or CIL, we also allow Import to be
4171 -- given for packages, generic packages, exceptions, record
4172 -- components, and access to subprograms.
4174 elsif (C = Convention_Java or else C = Convention_CIL)
4176 (Is_Package_Or_Generic_Package (Def_Id)
4177 or else Ekind (Def_Id) = E_Exception
4178 or else Ekind (Def_Id) = E_Access_Subprogram_Type
4179 or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4181 Set_Imported (Def_Id);
4182 Set_Is_Public (Def_Id);
4183 Process_Interface_Name (Def_Id, Arg3, Arg4);
4185 -- Import a CPP class
4187 elsif Is_Record_Type (Def_Id)
4188 and then C = Convention_CPP
4190 -- Types treated as CPP classes must be declared limited (note:
4191 -- this used to be a warning but there is no real benefit to it
4192 -- since we did effectively intend to treat the type as limited
4195 if not Is_Limited_Type (Def_Id) then
4197 ("imported 'C'P'P type must be limited",
4198 Get_Pragma_Arg (Arg2));
4201 Set_Is_CPP_Class (Def_Id);
4203 -- Imported CPP types must not have discriminants (because C++
4204 -- classes do not have discriminants).
4206 if Has_Discriminants (Def_Id) then
4208 ("imported 'C'P'P type cannot have discriminants",
4209 First (Discriminant_Specifications
4210 (Declaration_Node (Def_Id))));
4213 -- Components of imported CPP types must not have default
4214 -- expressions because the constructor (if any) is on the
4218 Tdef : constant Node_Id :=
4219 Type_Definition (Declaration_Node (Def_Id));
4224 if Nkind (Tdef) = N_Record_Definition then
4225 Clist := Component_List (Tdef);
4228 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4229 Clist := Component_List (Record_Extension_Part (Tdef));
4232 if Present (Clist) then
4233 Comp := First (Component_Items (Clist));
4234 while Present (Comp) loop
4235 if Present (Expression (Comp)) then
4237 ("component of imported 'C'P'P type cannot have" &
4238 " default expression", Expression (Comp));
4246 elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4248 Check_Arg_Count (3);
4249 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4251 Process_Import_Predefined_Type;
4255 ("second argument of pragma% must be object, subprogram" &
4256 " or incomplete type",
4260 -- If this pragma applies to a compilation unit, then the unit, which
4261 -- is a subprogram, does not require (or allow) a body. We also do
4262 -- not need to elaborate imported procedures.
4264 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4266 Cunit : constant Node_Id := Parent (Parent (N));
4268 Set_Body_Required (Cunit, False);
4271 end Process_Import_Or_Interface;
4273 --------------------
4274 -- Process_Inline --
4275 --------------------
4277 procedure Process_Inline (Active : Boolean) is
4284 Effective : Boolean := False;
4285 -- Set True if inline has some effect, i.e. if there is at least one
4286 -- subprogram set as inlined as a result of the use of the pragma.
4288 procedure Make_Inline (Subp : Entity_Id);
4289 -- Subp is the defining unit name of the subprogram declaration. Set
4290 -- the flag, as well as the flag in the corresponding body, if there
4293 procedure Set_Inline_Flags (Subp : Entity_Id);
4294 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4295 -- Has_Pragma_Inline_Always for the Inline_Always case.
4297 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4298 -- Returns True if it can be determined at this stage that inlining
4299 -- is not possible, for example if the body is available and contains
4300 -- exception handlers, we prevent inlining, since otherwise we can
4301 -- get undefined symbols at link time. This function also emits a
4302 -- warning if front-end inlining is enabled and the pragma appears
4305 -- ??? is business with link symbols still valid, or does it relate
4306 -- to front end ZCX which is being phased out ???
4308 ---------------------------
4309 -- Inlining_Not_Possible --
4310 ---------------------------
4312 function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4313 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
4317 if Nkind (Decl) = N_Subprogram_Body then
4318 Stats := Handled_Statement_Sequence (Decl);
4319 return Present (Exception_Handlers (Stats))
4320 or else Present (At_End_Proc (Stats));
4322 elsif Nkind (Decl) = N_Subprogram_Declaration
4323 and then Present (Corresponding_Body (Decl))
4325 if Front_End_Inlining
4326 and then Analyzed (Corresponding_Body (Decl))
4328 Error_Msg_N ("pragma appears too late, ignored?", N);
4331 -- If the subprogram is a renaming as body, the body is just a
4332 -- call to the renamed subprogram, and inlining is trivially
4336 Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4337 N_Subprogram_Renaming_Declaration
4343 Handled_Statement_Sequence
4344 (Unit_Declaration_Node (Corresponding_Body (Decl)));
4347 Present (Exception_Handlers (Stats))
4348 or else Present (At_End_Proc (Stats));
4352 -- If body is not available, assume the best, the check is
4353 -- performed again when compiling enclosing package bodies.
4357 end Inlining_Not_Possible;
4363 procedure Make_Inline (Subp : Entity_Id) is
4364 Kind : constant Entity_Kind := Ekind (Subp);
4365 Inner_Subp : Entity_Id := Subp;
4368 -- Ignore if bad type, avoid cascaded error
4370 if Etype (Subp) = Any_Type then
4374 -- Ignore if all inlining is suppressed
4376 elsif Suppress_All_Inlining then
4380 -- If inlining is not possible, for now do not treat as an error
4382 elsif Inlining_Not_Possible (Subp) then
4386 -- Here we have a candidate for inlining, but we must exclude
4387 -- derived operations. Otherwise we would end up trying to inline
4388 -- a phantom declaration, and the result would be to drag in a
4389 -- body which has no direct inlining associated with it. That
4390 -- would not only be inefficient but would also result in the
4391 -- backend doing cross-unit inlining in cases where it was
4392 -- definitely inappropriate to do so.
4394 -- However, a simple Comes_From_Source test is insufficient, since
4395 -- we do want to allow inlining of generic instances which also do
4396 -- not come from source. We also need to recognize specs generated
4397 -- by the front-end for bodies that carry the pragma. Finally,
4398 -- predefined operators do not come from source but are not
4399 -- inlineable either.
4401 elsif Is_Generic_Instance (Subp)
4402 or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4406 elsif not Comes_From_Source (Subp)
4407 and then Scope (Subp) /= Standard_Standard
4413 -- The referenced entity must either be the enclosing entity, or
4414 -- an entity declared within the current open scope.
4416 if Present (Scope (Subp))
4417 and then Scope (Subp) /= Current_Scope
4418 and then Subp /= Current_Scope
4421 ("argument of% must be entity in current scope", Assoc);
4425 -- Processing for procedure, operator or function. If subprogram
4426 -- is aliased (as for an instance) indicate that the renamed
4427 -- entity (if declared in the same unit) is inlined.
4429 if Is_Subprogram (Subp) then
4430 Inner_Subp := Ultimate_Alias (Inner_Subp);
4432 if In_Same_Source_Unit (Subp, Inner_Subp) then
4433 Set_Inline_Flags (Inner_Subp);
4435 Decl := Parent (Parent (Inner_Subp));
4437 if Nkind (Decl) = N_Subprogram_Declaration
4438 and then Present (Corresponding_Body (Decl))
4440 Set_Inline_Flags (Corresponding_Body (Decl));
4442 elsif Is_Generic_Instance (Subp) then
4444 -- Indicate that the body needs to be created for
4445 -- inlining subsequent calls. The instantiation node
4446 -- follows the declaration of the wrapper package
4449 if Scope (Subp) /= Standard_Standard
4451 Need_Subprogram_Instance_Body
4452 (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4462 -- For a generic subprogram set flag as well, for use at the point
4463 -- of instantiation, to determine whether the body should be
4466 elsif Is_Generic_Subprogram (Subp) then
4467 Set_Inline_Flags (Subp);
4470 -- Literals are by definition inlined
4472 elsif Kind = E_Enumeration_Literal then
4475 -- Anything else is an error
4479 ("expect subprogram name for pragma%", Assoc);
4483 ----------------------
4484 -- Set_Inline_Flags --
4485 ----------------------
4487 procedure Set_Inline_Flags (Subp : Entity_Id) is
4490 Set_Is_Inlined (Subp);
4493 if not Has_Pragma_Inline (Subp) then
4494 Set_Has_Pragma_Inline (Subp);
4498 if Prag_Id = Pragma_Inline_Always then
4499 Set_Has_Pragma_Inline_Always (Subp);
4501 end Set_Inline_Flags;
4503 -- Start of processing for Process_Inline
4506 Check_No_Identifiers;
4507 Check_At_Least_N_Arguments (1);
4510 Inline_Processing_Required := True;
4514 while Present (Assoc) loop
4515 Subp_Id := Get_Pragma_Arg (Assoc);
4519 if Is_Entity_Name (Subp_Id) then
4520 Subp := Entity (Subp_Id);
4522 if Subp = Any_Id then
4524 -- If previous error, avoid cascaded errors
4532 -- For the pragma case, climb homonym chain. This is
4533 -- what implements allowing the pragma in the renaming
4534 -- case, with the result applying to the ancestors.
4536 if not From_Aspect_Specification (N) then
4537 while Present (Homonym (Subp))
4538 and then Scope (Homonym (Subp)) = Current_Scope
4540 Make_Inline (Homonym (Subp));
4541 Subp := Homonym (Subp);
4549 ("inappropriate argument for pragma%", Assoc);
4552 and then Warn_On_Redundant_Constructs
4553 and then not Suppress_All_Inlining
4555 if Inlining_Not_Possible (Subp) then
4557 ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4560 ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4568 ----------------------------
4569 -- Process_Interface_Name --
4570 ----------------------------
4572 procedure Process_Interface_Name
4573 (Subprogram_Def : Entity_Id;
4579 String_Val : String_Id;
4581 procedure Check_Form_Of_Interface_Name
4583 Ext_Name_Case : Boolean);
4584 -- SN is a string literal node for an interface name. This routine
4585 -- performs some minimal checks that the name is reasonable. In
4586 -- particular that no spaces or other obviously incorrect characters
4587 -- appear. This is only a warning, since any characters are allowed.
4588 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
4590 ----------------------------------
4591 -- Check_Form_Of_Interface_Name --
4592 ----------------------------------
4594 procedure Check_Form_Of_Interface_Name
4596 Ext_Name_Case : Boolean)
4598 S : constant String_Id := Strval (Expr_Value_S (SN));
4599 SL : constant Nat := String_Length (S);
4604 Error_Msg_N ("interface name cannot be null string", SN);
4607 for J in 1 .. SL loop
4608 C := Get_String_Char (S, J);
4610 -- Look for dubious character and issue unconditional warning.
4611 -- Definitely dubious if not in character range.
4613 if not In_Character_Range (C)
4615 -- For all cases except CLI target,
4616 -- commas, spaces and slashes are dubious (in CLI, we use
4617 -- commas and backslashes in external names to specify
4618 -- assembly version and public key, while slashes and spaces
4619 -- can be used in names to mark nested classes and
4622 or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4623 and then (Get_Character (C) = ','
4625 Get_Character (C) = '\'))
4626 or else (VM_Target /= CLI_Target
4627 and then (Get_Character (C) = ' '
4629 Get_Character (C) = '/'))
4632 ("?interface name contains illegal character",
4633 Sloc (SN) + Source_Ptr (J));
4636 end Check_Form_Of_Interface_Name;
4638 -- Start of processing for Process_Interface_Name
4641 if No (Link_Arg) then
4642 if No (Ext_Arg) then
4643 if VM_Target = CLI_Target
4644 and then Ekind (Subprogram_Def) = E_Package
4645 and then Nkind (Parent (Subprogram_Def)) =
4646 N_Package_Specification
4647 and then Present (Generic_Parent (Parent (Subprogram_Def)))
4652 (Generic_Parent (Parent (Subprogram_Def))));
4657 elsif Chars (Ext_Arg) = Name_Link_Name then
4659 Link_Nam := Expression (Ext_Arg);
4662 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4663 Ext_Nam := Expression (Ext_Arg);
4668 Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4669 Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4670 Ext_Nam := Expression (Ext_Arg);
4671 Link_Nam := Expression (Link_Arg);
4674 -- Check expressions for external name and link name are static
4676 if Present (Ext_Nam) then
4677 Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4678 Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4680 -- Verify that external name is not the name of a local entity,
4681 -- which would hide the imported one and could lead to run-time
4682 -- surprises. The problem can only arise for entities declared in
4683 -- a package body (otherwise the external name is fully qualified
4684 -- and will not conflict).
4692 if Prag_Id = Pragma_Import then
4693 String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4695 E := Entity_Id (Get_Name_Table_Info (Nam));
4697 if Nam /= Chars (Subprogram_Def)
4698 and then Present (E)
4699 and then not Is_Overloadable (E)
4700 and then Is_Immediately_Visible (E)
4701 and then not Is_Imported (E)
4702 and then Ekind (Scope (E)) = E_Package
4705 while Present (Par) loop
4706 if Nkind (Par) = N_Package_Body then
4707 Error_Msg_Sloc := Sloc (E);
4709 ("imported entity is hidden by & declared#",
4714 Par := Parent (Par);
4721 if Present (Link_Nam) then
4722 Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4723 Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4726 -- If there is no link name, just set the external name
4728 if No (Link_Nam) then
4729 Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4731 -- For the Link_Name case, the given literal is preceded by an
4732 -- asterisk, which indicates to GCC that the given name should be
4733 -- taken literally, and in particular that no prepending of
4734 -- underlines should occur, even in systems where this is the
4740 if VM_Target = No_VM then
4741 Store_String_Char (Get_Char_Code ('*'));
4744 String_Val := Strval (Expr_Value_S (Link_Nam));
4745 Store_String_Chars (String_Val);
4747 Make_String_Literal (Sloc (Link_Nam),
4748 Strval => End_String);
4751 -- Set the interface name. If the entity is a generic instance, use
4752 -- its alias, which is the callable entity.
4754 if Is_Generic_Instance (Subprogram_Def) then
4755 Set_Encoded_Interface_Name
4756 (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
4758 Set_Encoded_Interface_Name
4759 (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4762 -- We allow duplicated export names in CIL/Java, as they are always
4763 -- enclosed in a namespace that differentiates them, and overloaded
4764 -- entities are supported by the VM.
4766 if Convention (Subprogram_Def) /= Convention_CIL
4768 Convention (Subprogram_Def) /= Convention_Java
4770 Check_Duplicated_Export_Name (Link_Nam);
4772 end Process_Interface_Name;
4774 -----------------------------------------
4775 -- Process_Interrupt_Or_Attach_Handler --
4776 -----------------------------------------
4778 procedure Process_Interrupt_Or_Attach_Handler is
4779 Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
4780 Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4781 Proc_Scope : constant Entity_Id := Scope (Handler_Proc);
4784 Set_Is_Interrupt_Handler (Handler_Proc);
4786 -- If the pragma is not associated with a handler procedure within a
4787 -- protected type, then it must be for a nonprotected procedure for
4788 -- the AAMP target, in which case we don't associate a representation
4789 -- item with the procedure's scope.
4791 if Ekind (Proc_Scope) = E_Protected_Type then
4792 if Prag_Id = Pragma_Interrupt_Handler
4794 Prag_Id = Pragma_Attach_Handler
4796 Record_Rep_Item (Proc_Scope, N);
4799 end Process_Interrupt_Or_Attach_Handler;
4801 --------------------------------------------------
4802 -- Process_Restrictions_Or_Restriction_Warnings --
4803 --------------------------------------------------
4805 -- Note: some of the simple identifier cases were handled in par-prag,
4806 -- but it is harmless (and more straightforward) to simply handle all
4807 -- cases here, even if it means we repeat a bit of work in some cases.
4809 procedure Process_Restrictions_Or_Restriction_Warnings
4813 R_Id : Restriction_Id;
4818 procedure Check_Unit_Name (N : Node_Id);
4819 -- Checks unit name parameter for No_Dependence. Returns if it has
4820 -- an appropriate form, otherwise raises pragma argument error.
4822 ---------------------
4823 -- Check_Unit_Name --
4824 ---------------------
4826 procedure Check_Unit_Name (N : Node_Id) is
4828 if Nkind (N) = N_Selected_Component then
4829 Check_Unit_Name (Prefix (N));
4830 Check_Unit_Name (Selector_Name (N));
4832 elsif Nkind (N) = N_Identifier then
4837 ("wrong form for unit name for No_Dependence", N);
4839 end Check_Unit_Name;
4841 -- Start of processing for Process_Restrictions_Or_Restriction_Warnings
4844 -- Ignore all Restrictions pragma in CodePeer mode
4846 if CodePeer_Mode then
4850 Check_Ada_83_Warning;
4851 Check_At_Least_N_Arguments (1);
4852 Check_Valid_Configuration_Pragma;
4855 while Present (Arg) loop
4857 Expr := Get_Pragma_Arg (Arg);
4859 -- Case of no restriction identifier present
4861 if Id = No_Name then
4862 if Nkind (Expr) /= N_Identifier then
4864 ("invalid form for restriction", Arg);
4869 (Process_Restriction_Synonyms (Expr));
4871 if R_Id not in All_Boolean_Restrictions then
4872 Error_Msg_Name_1 := Pname;
4874 ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4876 -- Check for possible misspelling
4878 for J in Restriction_Id loop
4880 Rnm : constant String := Restriction_Id'Image (J);
4883 Name_Buffer (1 .. Rnm'Length) := Rnm;
4884 Name_Len := Rnm'Length;
4885 Set_Casing (All_Lower_Case);
4887 if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4889 (Identifier_Casing (Current_Source_File));
4890 Error_Msg_String (1 .. Rnm'Length) :=
4891 Name_Buffer (1 .. Name_Len);
4892 Error_Msg_Strlen := Rnm'Length;
4893 Error_Msg_N -- CODEFIX
4894 ("\possible misspelling of ""~""",
4895 Get_Pragma_Arg (Arg));
4904 if Implementation_Restriction (R_Id) then
4905 Check_Restriction (No_Implementation_Restrictions, Arg);
4908 -- If this is a warning, then set the warning unless we already
4909 -- have a real restriction active (we never want a warning to
4910 -- override a real restriction).
4913 if not Restriction_Active (R_Id) then
4914 Set_Restriction (R_Id, N);
4915 Restriction_Warnings (R_Id) := True;
4918 -- If real restriction case, then set it and make sure that the
4919 -- restriction warning flag is off, since a real restriction
4920 -- always overrides a warning.
4923 Set_Restriction (R_Id, N);
4924 Restriction_Warnings (R_Id) := False;
4927 -- Check for obsolescent restrictions in Ada 2005 mode
4930 and then Ada_Version >= Ada_2005
4931 and then (R_Id = No_Asynchronous_Control
4933 R_Id = No_Unchecked_Deallocation
4935 R_Id = No_Unchecked_Conversion)
4937 Check_Restriction (No_Obsolescent_Features, N);
4940 -- A very special case that must be processed here: pragma
4941 -- Restrictions (No_Exceptions) turns off all run-time
4942 -- checking. This is a bit dubious in terms of the formal
4943 -- language definition, but it is what is intended by RM
4944 -- H.4(12). Restriction_Warnings never affects generated code
4945 -- so this is done only in the real restriction case.
4947 if R_Id = No_Exceptions and then not Warn then
4948 Scope_Suppress := (others => True);
4951 -- Case of No_Dependence => unit-name. Note that the parser
4952 -- already made the necessary entry in the No_Dependence table.
4954 elsif Id = Name_No_Dependence then
4955 Check_Unit_Name (Expr);
4957 -- All other cases of restriction identifier present
4960 R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4961 Analyze_And_Resolve (Expr, Any_Integer);
4963 if R_Id not in All_Parameter_Restrictions then
4965 ("invalid restriction parameter identifier", Arg);
4967 elsif not Is_OK_Static_Expression (Expr) then
4968 Flag_Non_Static_Expr
4969 ("value must be static expression!", Expr);
4972 elsif not Is_Integer_Type (Etype (Expr))
4973 or else Expr_Value (Expr) < 0
4976 ("value must be non-negative integer", Arg);
4979 -- Restriction pragma is active
4981 Val := Expr_Value (Expr);
4983 if not UI_Is_In_Int_Range (Val) then
4985 ("pragma ignored, value too large?", Arg);
4988 -- Warning case. If the real restriction is active, then we
4989 -- ignore the request, since warning never overrides a real
4990 -- restriction. Otherwise we set the proper warning. Note that
4991 -- this circuit sets the warning again if it is already set,
4992 -- which is what we want, since the constant may have changed.
4995 if not Restriction_Active (R_Id) then
4997 (R_Id, N, Integer (UI_To_Int (Val)));
4998 Restriction_Warnings (R_Id) := True;
5001 -- Real restriction case, set restriction and make sure warning
5002 -- flag is off since real restriction always overrides warning.
5005 Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5006 Restriction_Warnings (R_Id) := False;
5012 end Process_Restrictions_Or_Restriction_Warnings;
5014 ---------------------------------
5015 -- Process_Suppress_Unsuppress --
5016 ---------------------------------
5018 -- Note: this procedure makes entries in the check suppress data
5019 -- structures managed by Sem. See spec of package Sem for full
5020 -- details on how we handle recording of check suppression.
5022 procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5027 In_Package_Spec : constant Boolean :=
5028 Is_Package_Or_Generic_Package (Current_Scope)
5029 and then not In_Package_Body (Current_Scope);
5031 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5032 -- Used to suppress a single check on the given entity
5034 --------------------------------
5035 -- Suppress_Unsuppress_Echeck --
5036 --------------------------------
5038 procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5040 Set_Checks_May_Be_Suppressed (E);
5042 if In_Package_Spec then
5043 Push_Global_Suppress_Stack_Entry
5046 Suppress => Suppress_Case);
5049 Push_Local_Suppress_Stack_Entry
5052 Suppress => Suppress_Case);
5055 -- If this is a first subtype, and the base type is distinct,
5056 -- then also set the suppress flags on the base type.
5058 if Is_First_Subtype (E)
5059 and then Etype (E) /= E
5061 Suppress_Unsuppress_Echeck (Etype (E), C);
5063 end Suppress_Unsuppress_Echeck;
5065 -- Start of processing for Process_Suppress_Unsuppress
5068 -- Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5069 -- we want to generate checks for analysis purposes, as set by -gnatC
5071 if CodePeer_Mode and then Comes_From_Source (N) then
5075 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
5076 -- declarative part or a package spec (RM 11.5(5)).
5078 if not Is_Configuration_Pragma then
5079 Check_Is_In_Decl_Part_Or_Package_Spec;
5082 Check_At_Least_N_Arguments (1);
5083 Check_At_Most_N_Arguments (2);
5084 Check_No_Identifier (Arg1);
5085 Check_Arg_Is_Identifier (Arg1);
5087 C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5089 if C = No_Check_Id then
5091 ("argument of pragma% is not valid check name", Arg1);
5094 if not Suppress_Case
5095 and then (C = All_Checks or else C = Overflow_Check)
5097 Opt.Overflow_Checks_Unsuppressed := True;
5100 if Arg_Count = 1 then
5102 -- Make an entry in the local scope suppress table. This is the
5103 -- table that directly shows the current value of the scope
5104 -- suppress check for any check id value.
5106 if C = All_Checks then
5108 -- For All_Checks, we set all specific predefined checks with
5109 -- the exception of Elaboration_Check, which is handled
5110 -- specially because of not wanting All_Checks to have the
5111 -- effect of deactivating static elaboration order processing.
5113 for J in Scope_Suppress'Range loop
5114 if J /= Elaboration_Check then
5115 Scope_Suppress (J) := Suppress_Case;
5119 -- If not All_Checks, and predefined check, then set appropriate
5120 -- scope entry. Note that we will set Elaboration_Check if this
5121 -- is explicitly specified.
5123 elsif C in Predefined_Check_Id then
5124 Scope_Suppress (C) := Suppress_Case;
5127 -- Also make an entry in the Local_Entity_Suppress table
5129 Push_Local_Suppress_Stack_Entry
5132 Suppress => Suppress_Case);
5134 -- Case of two arguments present, where the check is suppressed for
5135 -- a specified entity (given as the second argument of the pragma)
5138 -- This is obsolescent in Ada 2005 mode
5140 if Ada_Version >= Ada_2005 then
5141 Check_Restriction (No_Obsolescent_Features, Arg2);
5144 Check_Optional_Identifier (Arg2, Name_On);
5145 E_Id := Get_Pragma_Arg (Arg2);
5148 if not Is_Entity_Name (E_Id) then
5150 ("second argument of pragma% must be entity name", Arg2);
5159 -- Enforce RM 11.5(7) which requires that for a pragma that
5160 -- appears within a package spec, the named entity must be
5161 -- within the package spec. We allow the package name itself
5162 -- to be mentioned since that makes sense, although it is not
5163 -- strictly allowed by 11.5(7).
5166 and then E /= Current_Scope
5167 and then Scope (E) /= Current_Scope
5170 ("entity in pragma% is not in package spec (RM 11.5(7))",
5174 -- Loop through homonyms. As noted below, in the case of a package
5175 -- spec, only homonyms within the package spec are considered.
5178 Suppress_Unsuppress_Echeck (E, C);
5180 if Is_Generic_Instance (E)
5181 and then Is_Subprogram (E)
5182 and then Present (Alias (E))
5184 Suppress_Unsuppress_Echeck (Alias (E), C);
5187 -- Move to next homonym if not aspect spec case
5189 exit when From_Aspect_Specification (N);
5193 -- If we are within a package specification, the pragma only
5194 -- applies to homonyms in the same scope.
5196 exit when In_Package_Spec
5197 and then Scope (E) /= Current_Scope;
5200 end Process_Suppress_Unsuppress;
5206 procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5208 if Is_Imported (E) then
5210 ("cannot export entity& that was previously imported", Arg);
5212 elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5214 ("cannot export entity& that has an address clause", Arg);
5217 Set_Is_Exported (E);
5219 -- Generate a reference for entity explicitly, because the
5220 -- identifier may be overloaded and name resolution will not
5223 Generate_Reference (E, Arg);
5225 -- Deal with exporting non-library level entity
5227 if not Is_Library_Level_Entity (E) then
5229 -- Not allowed at all for subprograms
5231 if Is_Subprogram (E) then
5232 Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5234 -- Otherwise set public and statically allocated
5238 Set_Is_Statically_Allocated (E);
5240 -- Warn if the corresponding W flag is set and the pragma comes
5241 -- from source. The latter may not be true e.g. on VMS where we
5242 -- expand export pragmas for exception codes associated with
5243 -- imported or exported exceptions. We do not want to generate
5244 -- a warning for something that the user did not write.
5246 if Warn_On_Export_Import
5247 and then Comes_From_Source (Arg)
5250 ("?& has been made static as a result of Export", Arg, E);
5252 ("\this usage is non-standard and non-portable", Arg);
5257 if Warn_On_Export_Import and then Is_Type (E) then
5258 Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5261 if Warn_On_Export_Import and Inside_A_Generic then
5263 ("all instances of& will have the same external name?", Arg, E);
5267 ----------------------------------------------
5268 -- Set_Extended_Import_Export_External_Name --
5269 ----------------------------------------------
5271 procedure Set_Extended_Import_Export_External_Name
5272 (Internal_Ent : Entity_Id;
5273 Arg_External : Node_Id)
5275 Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5279 if No (Arg_External) then
5283 Check_Arg_Is_External_Name (Arg_External);
5285 if Nkind (Arg_External) = N_String_Literal then
5286 if String_Length (Strval (Arg_External)) = 0 then
5289 New_Name := Adjust_External_Name_Case (Arg_External);
5292 elsif Nkind (Arg_External) = N_Identifier then
5293 New_Name := Get_Default_External_Name (Arg_External);
5295 -- Check_Arg_Is_External_Name should let through only identifiers and
5296 -- string literals or static string expressions (which are folded to
5297 -- string literals).
5300 raise Program_Error;
5303 -- If we already have an external name set (by a prior normal Import
5304 -- or Export pragma), then the external names must match
5306 if Present (Interface_Name (Internal_Ent)) then
5307 Check_Matching_Internal_Names : declare
5308 S1 : constant String_Id := Strval (Old_Name);
5309 S2 : constant String_Id := Strval (New_Name);
5312 -- Called if names do not match
5318 procedure Mismatch is
5320 Error_Msg_Sloc := Sloc (Old_Name);
5322 ("external name does not match that given #",
5326 -- Start of processing for Check_Matching_Internal_Names
5329 if String_Length (S1) /= String_Length (S2) then
5333 for J in 1 .. String_Length (S1) loop
5334 if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5339 end Check_Matching_Internal_Names;
5341 -- Otherwise set the given name
5344 Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5345 Check_Duplicated_Export_Name (New_Name);
5347 end Set_Extended_Import_Export_External_Name;
5353 procedure Set_Imported (E : Entity_Id) is
5355 -- Error message if already imported or exported
5357 if Is_Exported (E) or else Is_Imported (E) then
5359 -- Error if being set Exported twice
5361 if Is_Exported (E) then
5362 Error_Msg_NE ("entity& was previously exported", N, E);
5364 -- OK if Import/Interface case
5366 elsif Import_Interface_Present (N) then
5369 -- Error if being set Imported twice
5372 Error_Msg_NE ("entity& was previously imported", N, E);
5375 Error_Msg_Name_1 := Pname;
5377 ("\(pragma% applies to all previous entities)", N);
5379 Error_Msg_Sloc := Sloc (E);
5380 Error_Msg_NE ("\import not allowed for& declared#", N, E);
5382 -- Here if not previously imported or exported, OK to import
5385 Set_Is_Imported (E);
5387 -- If the entity is an object that is not at the library level,
5388 -- then it is statically allocated. We do not worry about objects
5389 -- with address clauses in this context since they are not really
5390 -- imported in the linker sense.
5393 and then not Is_Library_Level_Entity (E)
5394 and then No (Address_Clause (E))
5396 Set_Is_Statically_Allocated (E);
5403 -------------------------
5404 -- Set_Mechanism_Value --
5405 -------------------------
5407 -- Note: the mechanism name has not been analyzed (and cannot indeed be
5408 -- analyzed, since it is semantic nonsense), so we get it in the exact
5409 -- form created by the parser.
5411 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5414 Mech_Name_Id : Name_Id;
5416 procedure Bad_Class;
5417 -- Signal bad descriptor class name
5419 procedure Bad_Mechanism;
5420 -- Signal bad mechanism name
5426 procedure Bad_Class is
5428 Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5431 -------------------------
5432 -- Bad_Mechanism_Value --
5433 -------------------------
5435 procedure Bad_Mechanism is
5437 Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5440 -- Start of processing for Set_Mechanism_Value
5443 if Mechanism (Ent) /= Default_Mechanism then
5445 ("mechanism for & has already been set", Mech_Name, Ent);
5448 -- MECHANISM_NAME ::= value | reference | descriptor |
5451 if Nkind (Mech_Name) = N_Identifier then
5452 if Chars (Mech_Name) = Name_Value then
5453 Set_Mechanism (Ent, By_Copy);
5456 elsif Chars (Mech_Name) = Name_Reference then
5457 Set_Mechanism (Ent, By_Reference);
5460 elsif Chars (Mech_Name) = Name_Descriptor then
5461 Check_VMS (Mech_Name);
5463 -- Descriptor => Short_Descriptor if pragma was given
5465 if Short_Descriptors then
5466 Set_Mechanism (Ent, By_Short_Descriptor);
5468 Set_Mechanism (Ent, By_Descriptor);
5473 elsif Chars (Mech_Name) = Name_Short_Descriptor then
5474 Check_VMS (Mech_Name);
5475 Set_Mechanism (Ent, By_Short_Descriptor);
5478 elsif Chars (Mech_Name) = Name_Copy then
5480 ("bad mechanism name, Value assumed", Mech_Name);
5486 -- MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5487 -- short_descriptor (CLASS_NAME)
5488 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5490 -- Note: this form is parsed as an indexed component
5492 elsif Nkind (Mech_Name) = N_Indexed_Component then
5493 Class := First (Expressions (Mech_Name));
5495 if Nkind (Prefix (Mech_Name)) /= N_Identifier
5496 or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5497 Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5498 or else Present (Next (Class))
5502 Mech_Name_Id := Chars (Prefix (Mech_Name));
5504 -- Change Descriptor => Short_Descriptor if pragma was given
5506 if Mech_Name_Id = Name_Descriptor
5507 and then Short_Descriptors
5509 Mech_Name_Id := Name_Short_Descriptor;
5513 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5514 -- short_descriptor (Class => CLASS_NAME)
5515 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
5517 -- Note: this form is parsed as a function call
5519 elsif Nkind (Mech_Name) = N_Function_Call then
5520 Param := First (Parameter_Associations (Mech_Name));
5522 if Nkind (Name (Mech_Name)) /= N_Identifier
5523 or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5524 Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5525 or else Present (Next (Param))
5526 or else No (Selector_Name (Param))
5527 or else Chars (Selector_Name (Param)) /= Name_Class
5531 Class := Explicit_Actual_Parameter (Param);
5532 Mech_Name_Id := Chars (Name (Mech_Name));
5539 -- Fall through here with Class set to descriptor class name
5541 Check_VMS (Mech_Name);
5543 if Nkind (Class) /= N_Identifier then
5546 elsif Mech_Name_Id = Name_Descriptor
5547 and then Chars (Class) = Name_UBS
5549 Set_Mechanism (Ent, By_Descriptor_UBS);
5551 elsif Mech_Name_Id = Name_Descriptor
5552 and then Chars (Class) = Name_UBSB
5554 Set_Mechanism (Ent, By_Descriptor_UBSB);
5556 elsif Mech_Name_Id = Name_Descriptor
5557 and then Chars (Class) = Name_UBA
5559 Set_Mechanism (Ent, By_Descriptor_UBA);
5561 elsif Mech_Name_Id = Name_Descriptor
5562 and then Chars (Class) = Name_S
5564 Set_Mechanism (Ent, By_Descriptor_S);
5566 elsif Mech_Name_Id = Name_Descriptor
5567 and then Chars (Class) = Name_SB
5569 Set_Mechanism (Ent, By_Descriptor_SB);
5571 elsif Mech_Name_Id = Name_Descriptor
5572 and then Chars (Class) = Name_A
5574 Set_Mechanism (Ent, By_Descriptor_A);
5576 elsif Mech_Name_Id = Name_Descriptor
5577 and then Chars (Class) = Name_NCA
5579 Set_Mechanism (Ent, By_Descriptor_NCA);
5581 elsif Mech_Name_Id = Name_Short_Descriptor
5582 and then Chars (Class) = Name_UBS
5584 Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5586 elsif Mech_Name_Id = Name_Short_Descriptor
5587 and then Chars (Class) = Name_UBSB
5589 Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5591 elsif Mech_Name_Id = Name_Short_Descriptor
5592 and then Chars (Class) = Name_UBA
5594 Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5596 elsif Mech_Name_Id = Name_Short_Descriptor
5597 and then Chars (Class) = Name_S
5599 Set_Mechanism (Ent, By_Short_Descriptor_S);
5601 elsif Mech_Name_Id = Name_Short_Descriptor
5602 and then Chars (Class) = Name_SB
5604 Set_Mechanism (Ent, By_Short_Descriptor_SB);
5606 elsif Mech_Name_Id = Name_Short_Descriptor
5607 and then Chars (Class) = Name_A
5609 Set_Mechanism (Ent, By_Short_Descriptor_A);
5611 elsif Mech_Name_Id = Name_Short_Descriptor
5612 and then Chars (Class) = Name_NCA
5614 Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5619 end Set_Mechanism_Value;
5621 ---------------------------
5622 -- Set_Ravenscar_Profile --
5623 ---------------------------
5625 -- The tasks to be done here are
5627 -- Set required policies
5629 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5630 -- pragma Locking_Policy (Ceiling_Locking)
5632 -- Set Detect_Blocking mode
5634 -- Set required restrictions (see System.Rident for detailed list)
5636 -- Set the No_Dependence rules
5637 -- No_Dependence => Ada.Asynchronous_Task_Control
5638 -- No_Dependence => Ada.Calendar
5639 -- No_Dependence => Ada.Execution_Time.Group_Budget
5640 -- No_Dependence => Ada.Execution_Time.Timers
5641 -- No_Dependence => Ada.Task_Attributes
5642 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5644 procedure Set_Ravenscar_Profile (N : Node_Id) is
5645 Prefix_Entity : Entity_Id;
5646 Selector_Entity : Entity_Id;
5647 Prefix_Node : Node_Id;
5651 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5653 if Task_Dispatching_Policy /= ' '
5654 and then Task_Dispatching_Policy /= 'F'
5656 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5657 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5659 -- Set the FIFO_Within_Priorities policy, but always preserve
5660 -- System_Location since we like the error message with the run time
5664 Task_Dispatching_Policy := 'F';
5666 if Task_Dispatching_Policy_Sloc /= System_Location then
5667 Task_Dispatching_Policy_Sloc := Loc;
5671 -- pragma Locking_Policy (Ceiling_Locking)
5673 if Locking_Policy /= ' '
5674 and then Locking_Policy /= 'C'
5676 Error_Msg_Sloc := Locking_Policy_Sloc;
5677 Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5679 -- Set the Ceiling_Locking policy, but preserve System_Location since
5680 -- we like the error message with the run time name.
5683 Locking_Policy := 'C';
5685 if Locking_Policy_Sloc /= System_Location then
5686 Locking_Policy_Sloc := Loc;
5690 -- pragma Detect_Blocking
5692 Detect_Blocking := True;
5694 -- Set the corresponding restrictions
5696 Set_Profile_Restrictions
5697 (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5699 -- Set the No_Dependence restrictions
5701 -- The following No_Dependence restrictions:
5702 -- No_Dependence => Ada.Asynchronous_Task_Control
5703 -- No_Dependence => Ada.Calendar
5704 -- No_Dependence => Ada.Task_Attributes
5705 -- are already set by previous call to Set_Profile_Restrictions.
5707 -- Set the following restrictions which were added to Ada 2005:
5708 -- No_Dependence => Ada.Execution_Time.Group_Budget
5709 -- No_Dependence => Ada.Execution_Time.Timers
5711 if Ada_Version >= Ada_2005 then
5712 Name_Buffer (1 .. 3) := "ada";
5715 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5717 Name_Buffer (1 .. 14) := "execution_time";
5720 Selector_Entity := Make_Identifier (Loc, Name_Find);
5723 Make_Selected_Component
5725 Prefix => Prefix_Entity,
5726 Selector_Name => Selector_Entity);
5728 Name_Buffer (1 .. 13) := "group_budgets";
5731 Selector_Entity := Make_Identifier (Loc, Name_Find);
5734 Make_Selected_Component
5736 Prefix => Prefix_Node,
5737 Selector_Name => Selector_Entity);
5739 Set_Restriction_No_Dependence
5741 Warn => Treat_Restrictions_As_Warnings,
5742 Profile => Ravenscar);
5744 Name_Buffer (1 .. 6) := "timers";
5747 Selector_Entity := Make_Identifier (Loc, Name_Find);
5750 Make_Selected_Component
5752 Prefix => Prefix_Node,
5753 Selector_Name => Selector_Entity);
5755 Set_Restriction_No_Dependence
5757 Warn => Treat_Restrictions_As_Warnings,
5758 Profile => Ravenscar);
5761 -- Set the following restrictions which was added to Ada 2012 (see
5763 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
5765 if Ada_Version >= Ada_2012 then
5766 Name_Buffer (1 .. 6) := "system";
5769 Prefix_Entity := Make_Identifier (Loc, Name_Find);
5771 Name_Buffer (1 .. 15) := "multiprocessors";
5774 Selector_Entity := Make_Identifier (Loc, Name_Find);
5777 Make_Selected_Component
5779 Prefix => Prefix_Entity,
5780 Selector_Name => Selector_Entity);
5782 Name_Buffer (1 .. 19) := "dispatching_domains";
5785 Selector_Entity := Make_Identifier (Loc, Name_Find);
5788 Make_Selected_Component
5790 Prefix => Prefix_Node,
5791 Selector_Name => Selector_Entity);
5793 Set_Restriction_No_Dependence
5795 Warn => Treat_Restrictions_As_Warnings,
5796 Profile => Ravenscar);
5798 end Set_Ravenscar_Profile;
5800 -- Start of processing for Analyze_Pragma
5803 -- The following code is a defense against recursion. Not clear that
5804 -- this can happen legitimately, but perhaps some error situations
5805 -- can cause it, and we did see this recursion during testing.
5807 if Analyzed (N) then
5810 Set_Analyzed (N, True);
5813 -- Deal with unrecognized pragma
5815 if not Is_Pragma_Name (Pname) then
5816 if Warn_On_Unrecognized_Pragma then
5817 Error_Msg_Name_1 := Pname;
5818 Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5820 for PN in First_Pragma_Name .. Last_Pragma_Name loop
5821 if Is_Bad_Spelling_Of (Pname, PN) then
5822 Error_Msg_Name_1 := PN;
5823 Error_Msg_N -- CODEFIX
5824 ("\?possible misspelling of %!", Pragma_Identifier (N));
5833 -- Here to start processing for recognized pragma
5835 Prag_Id := Get_Pragma_Id (Pname);
5845 if Present (Pragma_Argument_Associations (N)) then
5846 Arg_Count := List_Length (Pragma_Argument_Associations (N));
5847 Arg1 := First (Pragma_Argument_Associations (N));
5849 if Present (Arg1) then
5850 Arg2 := Next (Arg1);
5852 if Present (Arg2) then
5853 Arg3 := Next (Arg2);
5855 if Present (Arg3) then
5856 Arg4 := Next (Arg3);
5862 -- An enumeration type defines the pragmas that are supported by the
5863 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
5864 -- into the corresponding enumeration value for the following case.
5872 -- pragma Abort_Defer;
5874 when Pragma_Abort_Defer =>
5876 Check_Arg_Count (0);
5878 -- The only required semantic processing is to check the
5879 -- placement. This pragma must appear at the start of the
5880 -- statement sequence of a handled sequence of statements.
5882 if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5883 or else N /= First (Statements (Parent (N)))
5894 -- Note: this pragma also has some specific processing in Par.Prag
5895 -- because we want to set the Ada version mode during parsing.
5897 when Pragma_Ada_83 =>
5899 Check_Arg_Count (0);
5901 -- We really should check unconditionally for proper configuration
5902 -- pragma placement, since we really don't want mixed Ada modes
5903 -- within a single unit, and the GNAT reference manual has always
5904 -- said this was a configuration pragma, but we did not check and
5905 -- are hesitant to add the check now.
5907 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5908 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5909 -- or Ada 2012 mode.
5911 if Ada_Version >= Ada_2005 then
5912 Check_Valid_Configuration_Pragma;
5915 -- Now set Ada 83 mode
5917 Ada_Version := Ada_83;
5918 Ada_Version_Explicit := Ada_Version;
5926 -- Note: this pragma also has some specific processing in Par.Prag
5927 -- because we want to set the Ada 83 version mode during parsing.
5929 when Pragma_Ada_95 =>
5931 Check_Arg_Count (0);
5933 -- We really should check unconditionally for proper configuration
5934 -- pragma placement, since we really don't want mixed Ada modes
5935 -- within a single unit, and the GNAT reference manual has always
5936 -- said this was a configuration pragma, but we did not check and
5937 -- are hesitant to add the check now.
5939 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
5940 -- or Ada 95, so we must check if we are in Ada 2005 mode.
5942 if Ada_Version >= Ada_2005 then
5943 Check_Valid_Configuration_Pragma;
5946 -- Now set Ada 95 mode
5948 Ada_Version := Ada_95;
5949 Ada_Version_Explicit := Ada_Version;
5951 ---------------------
5952 -- Ada_05/Ada_2005 --
5953 ---------------------
5956 -- pragma Ada_05 (LOCAL_NAME);
5959 -- pragma Ada_2005 (LOCAL_NAME):
5961 -- Note: these pragmas also have some specific processing in Par.Prag
5962 -- because we want to set the Ada 2005 version mode during parsing.
5964 when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5970 if Arg_Count = 1 then
5971 Check_Arg_Is_Local_Name (Arg1);
5972 E_Id := Get_Pragma_Arg (Arg1);
5974 if Etype (E_Id) = Any_Type then
5978 Set_Is_Ada_2005_Only (Entity (E_Id));
5981 Check_Arg_Count (0);
5983 -- For Ada_2005 we unconditionally enforce the documented
5984 -- configuration pragma placement, since we do not want to
5985 -- tolerate mixed modes in a unit involving Ada 2005. That
5986 -- would cause real difficulties for those cases where there
5987 -- are incompatibilities between Ada 95 and Ada 2005.
5989 Check_Valid_Configuration_Pragma;
5991 -- Now set appropriate Ada mode
5993 Ada_Version := Ada_2005;
5994 Ada_Version_Explicit := Ada_2005;
5998 ---------------------
5999 -- Ada_12/Ada_2012 --
6000 ---------------------
6003 -- pragma Ada_12 (LOCAL_NAME);
6006 -- pragma Ada_2012 (LOCAL_NAME):
6008 -- Note: these pragmas also have some specific processing in Par.Prag
6009 -- because we want to set the Ada 2012 version mode during parsing.
6011 when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6017 if Arg_Count = 1 then
6018 Check_Arg_Is_Local_Name (Arg1);
6019 E_Id := Get_Pragma_Arg (Arg1);
6021 if Etype (E_Id) = Any_Type then
6025 Set_Is_Ada_2012_Only (Entity (E_Id));
6028 Check_Arg_Count (0);
6030 -- For Ada_2012 we unconditionally enforce the documented
6031 -- configuration pragma placement, since we do not want to
6032 -- tolerate mixed modes in a unit involving Ada 2012. That
6033 -- would cause real difficulties for those cases where there
6034 -- are incompatibilities between Ada 95 and Ada 2012. We could
6035 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6037 Check_Valid_Configuration_Pragma;
6039 -- Now set appropriate Ada mode
6041 Ada_Version := Ada_2012;
6042 Ada_Version_Explicit := Ada_2012;
6046 ----------------------
6047 -- All_Calls_Remote --
6048 ----------------------
6050 -- pragma All_Calls_Remote [(library_package_NAME)];
6052 when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6053 Lib_Entity : Entity_Id;
6056 Check_Ada_83_Warning;
6057 Check_Valid_Library_Unit_Pragma;
6059 if Nkind (N) = N_Null_Statement then
6063 Lib_Entity := Find_Lib_Unit_Name;
6065 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
6067 if Present (Lib_Entity)
6068 and then not Debug_Flag_U
6070 if not Is_Remote_Call_Interface (Lib_Entity) then
6071 Error_Pragma ("pragma% only apply to rci unit");
6073 -- Set flag for entity of the library unit
6076 Set_Has_All_Calls_Remote (Lib_Entity);
6080 end All_Calls_Remote;
6086 -- pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6087 -- ARG ::= NAME | EXPRESSION
6089 -- The first two arguments are by convention intended to refer to an
6090 -- external tool and a tool-specific function. These arguments are
6093 -- The following is a special form used in conjunction with the
6094 -- ALFA subset of Ada:
6096 -- pragma Annotate (Formal_Proof, MODE);
6097 -- MODE ::= On | Off
6099 -- This pragma either forces (mode On) or disables (mode Off)
6100 -- formal verification of the subprogram in which it is added. When
6101 -- formal verification is forced, all violations of the the ALFA
6102 -- subset of Ada present in the subprogram are reported as errors
6105 when Pragma_Annotate => Annotate : declare
6111 Check_At_Least_N_Arguments (1);
6112 Check_Arg_Is_Identifier (Arg1);
6113 Check_No_Identifiers;
6116 -- Special processing for Formal_Proof case
6118 if Chars (Get_Pragma_Arg (Arg1)) = Name_Formal_Proof then
6121 ("missing second argument for pragma%", Arg1);
6124 Check_Arg_Count (2);
6125 Check_Arg_Is_One_Of (Arg2, Name_On, Name_Off);
6128 Cur_Subp : constant Entity_Id := Current_Subprogram;
6131 if Present (Cur_Subp)
6132 and then (Is_Subprogram (Cur_Subp)
6133 or else Is_Generic_Subprogram (Cur_Subp))
6135 -- Notify user if some ALFA violation occurred before
6136 -- this point in Cur_Subp. These violations are not
6137 -- precisly located, but this is better than ignoring
6138 -- these violations.
6140 if Chars (Get_Pragma_Arg (Arg2)) = Name_On
6141 and then (not Is_In_ALFA (Cur_Subp)
6142 or else not Body_Is_In_ALFA (Cur_Subp))
6145 ("pragma% is placed after violation"
6149 -- We treat this as a Rep_Item to record it on the rep
6150 -- item chain for easy location later on.
6152 Record_Rep_Item (Cur_Subp, N);
6155 Error_Pragma ("wrong placement for pragma%");
6159 -- Second parameter is optional, it is never analyzed
6161 elsif No (Arg2) then
6164 -- Here if we have a second parameter
6167 -- Second parameter must be identifier
6169 Check_Arg_Is_Identifier (Arg2);
6171 -- Process remaining parameters if any
6174 while Present (Arg) loop
6175 Exp := Get_Pragma_Arg (Arg);
6178 if Is_Entity_Name (Exp) then
6181 -- For string literals, we assume Standard_String as the
6182 -- type, unless the string contains wide or wide_wide
6185 elsif Nkind (Exp) = N_String_Literal then
6186 if Has_Wide_Wide_Character (Exp) then
6187 Resolve (Exp, Standard_Wide_Wide_String);
6188 elsif Has_Wide_Character (Exp) then
6189 Resolve (Exp, Standard_Wide_String);
6191 Resolve (Exp, Standard_String);
6194 elsif Is_Overloaded (Exp) then
6196 ("ambiguous argument for pragma%", Exp);
6211 -- pragma Assert ([Check =>] Boolean_EXPRESSION
6212 -- [, [Message =>] Static_String_EXPRESSION]);
6214 when Pragma_Assert => Assert : declare
6220 Check_At_Least_N_Arguments (1);
6221 Check_At_Most_N_Arguments (2);
6222 Check_Arg_Order ((Name_Check, Name_Message));
6223 Check_Optional_Identifier (Arg1, Name_Check);
6225 -- We treat pragma Assert as equivalent to:
6227 -- pragma Check (Assertion, condition [, msg]);
6229 -- So rewrite pragma in this manner, and analyze the result
6231 Expr := Get_Pragma_Arg (Arg1);
6233 Make_Pragma_Argument_Association (Loc,
6234 Expression => Make_Identifier (Loc, Name_Assertion)),
6236 Make_Pragma_Argument_Association (Sloc (Expr),
6237 Expression => Expr));
6239 if Arg_Count > 1 then
6240 Check_Optional_Identifier (Arg2, Name_Message);
6241 Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6242 Append_To (Newa, Relocate_Node (Arg2));
6247 Chars => Name_Check,
6248 Pragma_Argument_Associations => Newa));
6252 ----------------------
6253 -- Assertion_Policy --
6254 ----------------------
6256 -- pragma Assertion_Policy (Check | Ignore)
6258 when Pragma_Assertion_Policy => Assertion_Policy : declare
6263 Check_Valid_Configuration_Pragma;
6264 Check_Arg_Count (1);
6265 Check_No_Identifiers;
6266 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6268 -- We treat pragma Assertion_Policy as equivalent to:
6270 -- pragma Check_Policy (Assertion, policy)
6272 -- So rewrite the pragma in that manner and link on to the chain
6273 -- of Check_Policy pragmas, marking the pragma as analyzed.
6275 Policy := Get_Pragma_Arg (Arg1);
6279 Chars => Name_Check_Policy,
6281 Pragma_Argument_Associations => New_List (
6282 Make_Pragma_Argument_Association (Loc,
6283 Expression => Make_Identifier (Loc, Name_Assertion)),
6285 Make_Pragma_Argument_Association (Loc,
6287 Make_Identifier (Sloc (Policy), Chars (Policy))))));
6290 Set_Next_Pragma (N, Opt.Check_Policy_List);
6291 Opt.Check_Policy_List := N;
6292 end Assertion_Policy;
6294 ------------------------------
6295 -- Assume_No_Invalid_Values --
6296 ------------------------------
6298 -- pragma Assume_No_Invalid_Values (On | Off);
6300 when Pragma_Assume_No_Invalid_Values =>
6302 Check_Valid_Configuration_Pragma;
6303 Check_Arg_Count (1);
6304 Check_No_Identifiers;
6305 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6307 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6308 Assume_No_Invalid_Values := True;
6310 Assume_No_Invalid_Values := False;
6317 -- pragma AST_Entry (entry_IDENTIFIER);
6319 when Pragma_AST_Entry => AST_Entry : declare
6325 Check_Arg_Count (1);
6326 Check_No_Identifiers;
6327 Check_Arg_Is_Local_Name (Arg1);
6328 Ent := Entity (Get_Pragma_Arg (Arg1));
6330 -- Note: the implementation of the AST_Entry pragma could handle
6331 -- the entry family case fine, but for now we are consistent with
6332 -- the DEC rules, and do not allow the pragma, which of course
6333 -- has the effect of also forbidding the attribute.
6335 if Ekind (Ent) /= E_Entry then
6337 ("pragma% argument must be simple entry name", Arg1);
6339 elsif Is_AST_Entry (Ent) then
6341 ("duplicate % pragma for entry", Arg1);
6343 elsif Has_Homonym (Ent) then
6345 ("pragma% argument cannot specify overloaded entry", Arg1);
6349 FF : constant Entity_Id := First_Formal (Ent);
6352 if Present (FF) then
6353 if Present (Next_Formal (FF)) then
6355 ("entry for pragma% can have only one argument",
6358 elsif Parameter_Mode (FF) /= E_In_Parameter then
6360 ("entry parameter for pragma% must have mode IN",
6366 Set_Is_AST_Entry (Ent);
6374 -- pragma Asynchronous (LOCAL_NAME);
6376 when Pragma_Asynchronous => Asynchronous : declare
6384 procedure Process_Async_Pragma;
6385 -- Common processing for procedure and access-to-procedure case
6387 --------------------------
6388 -- Process_Async_Pragma --
6389 --------------------------
6391 procedure Process_Async_Pragma is
6394 Set_Is_Asynchronous (Nm);
6398 -- The formals should be of mode IN (RM E.4.1(6))
6401 while Present (S) loop
6402 Formal := Defining_Identifier (S);
6404 if Nkind (Formal) = N_Defining_Identifier
6405 and then Ekind (Formal) /= E_In_Parameter
6408 ("pragma% procedure can only have IN parameter",
6415 Set_Is_Asynchronous (Nm);
6416 end Process_Async_Pragma;
6418 -- Start of processing for pragma Asynchronous
6421 Check_Ada_83_Warning;
6422 Check_No_Identifiers;
6423 Check_Arg_Count (1);
6424 Check_Arg_Is_Local_Name (Arg1);
6426 if Debug_Flag_U then
6430 C_Ent := Cunit_Entity (Current_Sem_Unit);
6431 Analyze (Get_Pragma_Arg (Arg1));
6432 Nm := Entity (Get_Pragma_Arg (Arg1));
6434 if not Is_Remote_Call_Interface (C_Ent)
6435 and then not Is_Remote_Types (C_Ent)
6437 -- This pragma should only appear in an RCI or Remote Types
6438 -- unit (RM E.4.1(4)).
6441 ("pragma% not in Remote_Call_Interface or " &
6442 "Remote_Types unit");
6445 if Ekind (Nm) = E_Procedure
6446 and then Nkind (Parent (Nm)) = N_Procedure_Specification
6448 if not Is_Remote_Call_Interface (Nm) then
6450 ("pragma% cannot be applied on non-remote procedure",
6454 L := Parameter_Specifications (Parent (Nm));
6455 Process_Async_Pragma;
6458 elsif Ekind (Nm) = E_Function then
6460 ("pragma% cannot be applied to function", Arg1);
6462 elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6463 if Is_Record_Type (Nm) then
6465 -- A record type that is the Equivalent_Type for a remote
6466 -- access-to-subprogram type.
6468 N := Declaration_Node (Corresponding_Remote_Type (Nm));
6471 -- A non-expanded RAS type (distribution is not enabled)
6473 N := Declaration_Node (Nm);
6476 if Nkind (N) = N_Full_Type_Declaration
6477 and then Nkind (Type_Definition (N)) =
6478 N_Access_Procedure_Definition
6480 L := Parameter_Specifications (Type_Definition (N));
6481 Process_Async_Pragma;
6483 if Is_Asynchronous (Nm)
6484 and then Expander_Active
6485 and then Get_PCS_Name /= Name_No_DSA
6487 RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6492 ("pragma% cannot reference access-to-function type",
6496 -- Only other possibility is Access-to-class-wide type
6498 elsif Is_Access_Type (Nm)
6499 and then Is_Class_Wide_Type (Designated_Type (Nm))
6501 Check_First_Subtype (Arg1);
6502 Set_Is_Asynchronous (Nm);
6503 if Expander_Active then
6504 RACW_Type_Is_Asynchronous (Nm);
6508 Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6516 -- pragma Atomic (LOCAL_NAME);
6518 when Pragma_Atomic =>
6519 Process_Atomic_Shared_Volatile;
6521 -----------------------
6522 -- Atomic_Components --
6523 -----------------------
6525 -- pragma Atomic_Components (array_LOCAL_NAME);
6527 -- This processing is shared by Volatile_Components
6529 when Pragma_Atomic_Components |
6530 Pragma_Volatile_Components =>
6532 Atomic_Components : declare
6539 Check_Ada_83_Warning;
6540 Check_No_Identifiers;
6541 Check_Arg_Count (1);
6542 Check_Arg_Is_Local_Name (Arg1);
6543 E_Id := Get_Pragma_Arg (Arg1);
6545 if Etype (E_Id) = Any_Type then
6551 Check_Duplicate_Pragma (E);
6553 if Rep_Item_Too_Early (E, N)
6555 Rep_Item_Too_Late (E, N)
6560 D := Declaration_Node (E);
6563 if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6565 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6566 and then Nkind (D) = N_Object_Declaration
6567 and then Nkind (Object_Definition (D)) =
6568 N_Constrained_Array_Definition)
6570 -- The flag is set on the object, or on the base type
6572 if Nkind (D) /= N_Object_Declaration then
6576 Set_Has_Volatile_Components (E);
6578 if Prag_Id = Pragma_Atomic_Components then
6579 Set_Has_Atomic_Components (E);
6583 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6585 end Atomic_Components;
6587 --------------------
6588 -- Attach_Handler --
6589 --------------------
6591 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
6593 when Pragma_Attach_Handler =>
6594 Check_Ada_83_Warning;
6595 Check_No_Identifiers;
6596 Check_Arg_Count (2);
6598 if No_Run_Time_Mode then
6599 Error_Msg_CRT ("Attach_Handler pragma", N);
6601 Check_Interrupt_Or_Attach_Handler;
6603 -- The expression that designates the attribute may depend on a
6604 -- discriminant, and is therefore a per- object expression, to
6605 -- be expanded in the init proc. If expansion is enabled, then
6606 -- perform semantic checks on a copy only.
6608 if Expander_Active then
6610 Temp : constant Node_Id :=
6611 New_Copy_Tree (Get_Pragma_Arg (Arg2));
6613 Set_Parent (Temp, N);
6614 Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6618 Analyze (Get_Pragma_Arg (Arg2));
6619 Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6622 Process_Interrupt_Or_Attach_Handler;
6625 --------------------
6626 -- C_Pass_By_Copy --
6627 --------------------
6629 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6631 when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6637 Check_Valid_Configuration_Pragma;
6638 Check_Arg_Count (1);
6639 Check_Optional_Identifier (Arg1, "max_size");
6641 Arg := Get_Pragma_Arg (Arg1);
6642 Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6644 Val := Expr_Value (Arg);
6648 ("maximum size for pragma% must be positive", Arg1);
6650 elsif UI_Is_In_Int_Range (Val) then
6651 Default_C_Record_Mechanism := UI_To_Int (Val);
6653 -- If a giant value is given, Int'Last will do well enough.
6654 -- If sometime someone complains that a record larger than
6655 -- two gigabytes is not copied, we will worry about it then!
6658 Default_C_Record_Mechanism := Mechanism_Type'Last;
6666 -- pragma Check ([Name =>] Identifier,
6667 -- [Check =>] Boolean_Expression
6668 -- [,[Message =>] String_Expression]);
6670 when Pragma_Check => Check : declare
6675 -- Set True if category of assertions referenced by Name enabled
6679 Check_At_Least_N_Arguments (2);
6680 Check_At_Most_N_Arguments (3);
6681 Check_Optional_Identifier (Arg1, Name_Name);
6682 Check_Optional_Identifier (Arg2, Name_Check);
6684 if Arg_Count = 3 then
6685 Check_Optional_Identifier (Arg3, Name_Message);
6686 Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6689 Check_Arg_Is_Identifier (Arg1);
6691 -- Indicate if pragma is enabled. The Original_Node reference here
6692 -- is to deal with pragma Assert rewritten as a Check pragma.
6694 Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6697 Set_SCO_Pragma_Enabled (Loc);
6700 -- If expansion is active and the check is not enabled then we
6701 -- rewrite the Check as:
6703 -- if False and then condition then
6707 -- The reason we do this rewriting during semantic analysis rather
6708 -- than as part of normal expansion is that we cannot analyze and
6709 -- expand the code for the boolean expression directly, or it may
6710 -- cause insertion of actions that would escape the attempt to
6711 -- suppress the check code.
6713 -- Note that the Sloc for the IF statement corresponds to the
6714 -- argument condition, not the pragma itself. The reason for this
6715 -- is that we may generate a warning if the condition is False at
6716 -- compile time, and we do not want to delete this warning when we
6717 -- delete the IF statement.
6719 Expr := Get_Pragma_Arg (Arg2);
6721 if Expander_Active and then not Check_On then
6722 Eloc := Sloc (Expr);
6725 Make_If_Statement (Eloc,
6727 Make_And_Then (Eloc,
6728 Left_Opnd => New_Occurrence_Of (Standard_False, Eloc),
6729 Right_Opnd => Expr),
6730 Then_Statements => New_List (
6731 Make_Null_Statement (Eloc))));
6738 Analyze_And_Resolve (Expr, Any_Boolean);
6746 -- pragma Check_Name (check_IDENTIFIER);
6748 when Pragma_Check_Name =>
6749 Check_No_Identifiers;
6751 Check_Valid_Configuration_Pragma;
6752 Check_Arg_Count (1);
6753 Check_Arg_Is_Identifier (Arg1);
6756 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6759 for J in Check_Names.First .. Check_Names.Last loop
6760 if Check_Names.Table (J) = Nam then
6765 Check_Names.Append (Nam);
6772 -- pragma Check_Policy (
6773 -- [Name =>] IDENTIFIER,
6774 -- [Policy =>] POLICY_IDENTIFIER);
6776 -- POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6778 -- Note: this is a configuration pragma, but it is allowed to appear
6781 when Pragma_Check_Policy =>
6783 Check_Arg_Count (2);
6784 Check_Optional_Identifier (Arg1, Name_Name);
6785 Check_Optional_Identifier (Arg2, Name_Policy);
6787 (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6789 -- A Check_Policy pragma can appear either as a configuration
6790 -- pragma, or in a declarative part or a package spec (see RM
6791 -- 11.5(5) for rules for Suppress/Unsuppress which are also
6792 -- followed for Check_Policy).
6794 if not Is_Configuration_Pragma then
6795 Check_Is_In_Decl_Part_Or_Package_Spec;
6798 Set_Next_Pragma (N, Opt.Check_Policy_List);
6799 Opt.Check_Policy_List := N;
6801 ---------------------
6802 -- CIL_Constructor --
6803 ---------------------
6805 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6807 -- Processing for this pragma is shared with Java_Constructor
6813 -- pragma Comment (static_string_EXPRESSION)
6815 -- Processing for pragma Comment shares the circuitry for pragma
6816 -- Ident. The only differences are that Ident enforces a limit of 31
6817 -- characters on its argument, and also enforces limitations on
6818 -- placement for DEC compatibility. Pragma Comment shares neither of
6819 -- these restrictions.
6825 -- pragma Common_Object (
6826 -- [Internal =>] LOCAL_NAME
6827 -- [, [External =>] EXTERNAL_SYMBOL]
6828 -- [, [Size =>] EXTERNAL_SYMBOL]);
6830 -- Processing for this pragma is shared with Psect_Object
6832 ------------------------
6833 -- Compile_Time_Error --
6834 ------------------------
6836 -- pragma Compile_Time_Error
6837 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6839 when Pragma_Compile_Time_Error =>
6841 Process_Compile_Time_Warning_Or_Error;
6843 --------------------------
6844 -- Compile_Time_Warning --
6845 --------------------------
6847 -- pragma Compile_Time_Warning
6848 -- (boolean_EXPRESSION, static_string_EXPRESSION);
6850 when Pragma_Compile_Time_Warning =>
6852 Process_Compile_Time_Warning_Or_Error;
6858 when Pragma_Compiler_Unit =>
6860 Check_Arg_Count (0);
6861 Set_Is_Compiler_Unit (Get_Source_Unit (N));
6863 -----------------------------
6864 -- Complete_Representation --
6865 -----------------------------
6867 -- pragma Complete_Representation;
6869 when Pragma_Complete_Representation =>
6871 Check_Arg_Count (0);
6873 if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6875 ("pragma & must appear within record representation clause");
6878 ----------------------------
6879 -- Complex_Representation --
6880 ----------------------------
6882 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6884 when Pragma_Complex_Representation => Complex_Representation : declare
6891 Check_Arg_Count (1);
6892 Check_Optional_Identifier (Arg1, Name_Entity);
6893 Check_Arg_Is_Local_Name (Arg1);
6894 E_Id := Get_Pragma_Arg (Arg1);
6896 if Etype (E_Id) = Any_Type then
6902 if not Is_Record_Type (E) then
6904 ("argument for pragma% must be record type", Arg1);
6907 Ent := First_Entity (E);
6910 or else No (Next_Entity (Ent))
6911 or else Present (Next_Entity (Next_Entity (Ent)))
6912 or else not Is_Floating_Point_Type (Etype (Ent))
6913 or else Etype (Ent) /= Etype (Next_Entity (Ent))
6916 ("record for pragma% must have two fields of the same "
6917 & "floating-point type", Arg1);
6920 Set_Has_Complex_Representation (Base_Type (E));
6922 -- We need to treat the type has having a non-standard
6923 -- representation, for back-end purposes, even though in
6924 -- general a complex will have the default representation
6925 -- of a record with two real components.
6927 Set_Has_Non_Standard_Rep (Base_Type (E));
6929 end Complex_Representation;
6931 -------------------------
6932 -- Component_Alignment --
6933 -------------------------
6935 -- pragma Component_Alignment (
6936 -- [Form =>] ALIGNMENT_CHOICE
6937 -- [, [Name =>] type_LOCAL_NAME]);
6939 -- ALIGNMENT_CHOICE ::=
6941 -- | Component_Size_4
6945 when Pragma_Component_Alignment => Component_AlignmentP : declare
6946 Args : Args_List (1 .. 2);
6947 Names : constant Name_List (1 .. 2) := (
6951 Form : Node_Id renames Args (1);
6952 Name : Node_Id renames Args (2);
6954 Atype : Component_Alignment_Kind;
6959 Gather_Associations (Names, Args);
6962 Error_Pragma ("missing Form argument for pragma%");
6965 Check_Arg_Is_Identifier (Form);
6967 -- Get proper alignment, note that Default = Component_Size on all
6968 -- machines we have so far, and we want to set this value rather
6969 -- than the default value to indicate that it has been explicitly
6970 -- set (and thus will not get overridden by the default component
6971 -- alignment for the current scope)
6973 if Chars (Form) = Name_Component_Size then
6974 Atype := Calign_Component_Size;
6976 elsif Chars (Form) = Name_Component_Size_4 then
6977 Atype := Calign_Component_Size_4;
6979 elsif Chars (Form) = Name_Default then
6980 Atype := Calign_Component_Size;
6982 elsif Chars (Form) = Name_Storage_Unit then
6983 Atype := Calign_Storage_Unit;
6987 ("invalid Form parameter for pragma%", Form);
6990 -- Case with no name, supplied, affects scope table entry
6994 (Scope_Stack.Last).Component_Alignment_Default := Atype;
6996 -- Case of name supplied
6999 Check_Arg_Is_Local_Name (Name);
7001 Typ := Entity (Name);
7004 or else Rep_Item_Too_Early (Typ, N)
7008 Typ := Underlying_Type (Typ);
7011 if not Is_Record_Type (Typ)
7012 and then not Is_Array_Type (Typ)
7015 ("Name parameter of pragma% must identify record or " &
7016 "array type", Name);
7019 -- An explicit Component_Alignment pragma overrides an
7020 -- implicit pragma Pack, but not an explicit one.
7022 if not Has_Pragma_Pack (Base_Type (Typ)) then
7023 Set_Is_Packed (Base_Type (Typ), False);
7024 Set_Component_Alignment (Base_Type (Typ), Atype);
7027 end Component_AlignmentP;
7033 -- pragma Controlled (first_subtype_LOCAL_NAME);
7035 when Pragma_Controlled => Controlled : declare
7039 Check_No_Identifiers;
7040 Check_Arg_Count (1);
7041 Check_Arg_Is_Local_Name (Arg1);
7042 Arg := Get_Pragma_Arg (Arg1);
7044 if not Is_Entity_Name (Arg)
7045 or else not Is_Access_Type (Entity (Arg))
7047 Error_Pragma_Arg ("pragma% requires access type", Arg1);
7049 Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7057 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
7058 -- [Entity =>] LOCAL_NAME);
7060 when Pragma_Convention => Convention : declare
7063 pragma Warnings (Off, C);
7064 pragma Warnings (Off, E);
7066 Check_Arg_Order ((Name_Convention, Name_Entity));
7067 Check_Ada_83_Warning;
7068 Check_Arg_Count (2);
7069 Process_Convention (C, E);
7072 ---------------------------
7073 -- Convention_Identifier --
7074 ---------------------------
7076 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
7077 -- [Convention =>] convention_IDENTIFIER);
7079 when Pragma_Convention_Identifier => Convention_Identifier : declare
7085 Check_Arg_Order ((Name_Name, Name_Convention));
7086 Check_Arg_Count (2);
7087 Check_Optional_Identifier (Arg1, Name_Name);
7088 Check_Optional_Identifier (Arg2, Name_Convention);
7089 Check_Arg_Is_Identifier (Arg1);
7090 Check_Arg_Is_Identifier (Arg2);
7091 Idnam := Chars (Get_Pragma_Arg (Arg1));
7092 Cname := Chars (Get_Pragma_Arg (Arg2));
7094 if Is_Convention_Name (Cname) then
7095 Record_Convention_Identifier
7096 (Idnam, Get_Convention_Id (Cname));
7099 ("second arg for % pragma must be convention", Arg2);
7101 end Convention_Identifier;
7107 -- pragma CPP_Class ([Entity =>] local_NAME)
7109 when Pragma_CPP_Class => CPP_Class : declare
7114 if Warn_On_Obsolescent_Feature then
7116 ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7117 " by pragma import?", N);
7121 Check_Arg_Count (1);
7122 Check_Optional_Identifier (Arg1, Name_Entity);
7123 Check_Arg_Is_Local_Name (Arg1);
7125 Arg := Get_Pragma_Arg (Arg1);
7128 if Etype (Arg) = Any_Type then
7132 if not Is_Entity_Name (Arg)
7133 or else not Is_Type (Entity (Arg))
7135 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7138 Typ := Entity (Arg);
7140 if not Is_Tagged_Type (Typ) then
7141 Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7144 -- Types treated as CPP classes must be declared limited (note:
7145 -- this used to be a warning but there is no real benefit to it
7146 -- since we did effectively intend to treat the type as limited
7149 if not Is_Limited_Type (Typ) then
7151 ("imported 'C'P'P type must be limited",
7152 Get_Pragma_Arg (Arg1));
7155 Set_Is_CPP_Class (Typ);
7156 Set_Convention (Typ, Convention_CPP);
7158 -- Imported CPP types must not have discriminants (because C++
7159 -- classes do not have discriminants).
7161 if Has_Discriminants (Typ) then
7163 ("imported 'C'P'P type cannot have discriminants",
7164 First (Discriminant_Specifications
7165 (Declaration_Node (Typ))));
7168 -- Components of imported CPP types must not have default
7169 -- expressions because the constructor (if any) is in the
7172 if Is_Incomplete_Or_Private_Type (Typ)
7173 and then No (Underlying_Type (Typ))
7175 -- It should be an error to apply pragma CPP to a private
7176 -- type if the underlying type is not visible (as it is
7177 -- for any representation item). For now, for backward
7178 -- compatibility we do nothing but we cannot check components
7179 -- because they are not available at this stage. All this code
7180 -- will be removed when we cleanup this obsolete GNAT pragma???
7186 Tdef : constant Node_Id :=
7187 Type_Definition (Declaration_Node (Typ));
7192 if Nkind (Tdef) = N_Record_Definition then
7193 Clist := Component_List (Tdef);
7195 pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7196 Clist := Component_List (Record_Extension_Part (Tdef));
7199 if Present (Clist) then
7200 Comp := First (Component_Items (Clist));
7201 while Present (Comp) loop
7202 if Present (Expression (Comp)) then
7204 ("component of imported 'C'P'P type cannot have" &
7205 " default expression", Expression (Comp));
7215 ---------------------
7216 -- CPP_Constructor --
7217 ---------------------
7219 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7220 -- [, [External_Name =>] static_string_EXPRESSION ]
7221 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7223 when Pragma_CPP_Constructor => CPP_Constructor : declare
7227 Tag_Typ : Entity_Id;
7231 Check_At_Least_N_Arguments (1);
7232 Check_At_Most_N_Arguments (3);
7233 Check_Optional_Identifier (Arg1, Name_Entity);
7234 Check_Arg_Is_Local_Name (Arg1);
7236 Id := Get_Pragma_Arg (Arg1);
7237 Find_Program_Unit_Name (Id);
7239 -- If we did not find the name, we are done
7241 if Etype (Id) = Any_Type then
7245 Def_Id := Entity (Id);
7247 -- Check if already defined as constructor
7249 if Is_Constructor (Def_Id) then
7251 ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7255 if Ekind (Def_Id) = E_Function
7256 and then (Is_CPP_Class (Etype (Def_Id))
7257 or else (Is_Class_Wide_Type (Etype (Def_Id))
7259 Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7261 if Arg_Count >= 2 then
7262 Set_Imported (Def_Id);
7263 Set_Is_Public (Def_Id);
7264 Process_Interface_Name (Def_Id, Arg2, Arg3);
7267 Set_Has_Completion (Def_Id);
7268 Set_Is_Constructor (Def_Id);
7270 -- Imported C++ constructors are not dispatching primitives
7271 -- because in C++ they don't have a dispatch table slot.
7272 -- However, in Ada the constructor has the profile of a
7273 -- function that returns a tagged type and therefore it has
7274 -- been treated as a primitive operation during semantic
7275 -- analysis. We now remove it from the list of primitive
7276 -- operations of the type.
7278 if Is_Tagged_Type (Etype (Def_Id))
7279 and then not Is_Class_Wide_Type (Etype (Def_Id))
7281 pragma Assert (Is_Dispatching_Operation (Def_Id));
7282 Tag_Typ := Etype (Def_Id);
7284 Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7285 while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7289 Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7290 Set_Is_Dispatching_Operation (Def_Id, False);
7293 -- For backward compatibility, if the constructor returns a
7294 -- class wide type, and we internally change the return type to
7295 -- the corresponding root type.
7297 if Is_Class_Wide_Type (Etype (Def_Id)) then
7298 Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7302 ("pragma% requires function returning a 'C'P'P_Class type",
7305 end CPP_Constructor;
7311 when Pragma_CPP_Virtual => CPP_Virtual : declare
7315 if Warn_On_Obsolescent_Feature then
7317 ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7326 when Pragma_CPP_Vtable => CPP_Vtable : declare
7330 if Warn_On_Obsolescent_Feature then
7332 ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7341 -- pragma CPU (EXPRESSION);
7343 when Pragma_CPU => CPU : declare
7344 P : constant Node_Id := Parent (N);
7349 Check_No_Identifiers;
7350 Check_Arg_Count (1);
7354 if Nkind (P) = N_Subprogram_Body then
7355 Check_In_Main_Program;
7357 Arg := Get_Pragma_Arg (Arg1);
7358 Analyze_And_Resolve (Arg, Any_Integer);
7362 if not Is_Static_Expression (Arg) then
7363 Flag_Non_Static_Expr
7364 ("main subprogram affinity is not static!", Arg);
7367 -- If constraint error, then we already signalled an error
7369 elsif Raises_Constraint_Error (Arg) then
7372 -- Otherwise check in range
7376 CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7377 -- This is the entity System.Multiprocessors.CPU_Range;
7379 Val : constant Uint := Expr_Value (Arg);
7382 if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7384 Val > Expr_Value (Type_High_Bound (CPU_Id))
7387 ("main subprogram CPU is out of range", Arg1);
7393 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7397 elsif Nkind (P) = N_Task_Definition then
7398 Arg := Get_Pragma_Arg (Arg1);
7400 -- The expression must be analyzed in the special manner
7401 -- described in "Handling of Default and Per-Object
7402 -- Expressions" in sem.ads.
7404 Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7406 -- Anything else is incorrect
7412 if Has_Pragma_CPU (P) then
7413 Error_Pragma ("duplicate pragma% not allowed");
7415 Set_Has_Pragma_CPU (P, True);
7417 if Nkind (P) = N_Task_Definition then
7418 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7427 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7429 when Pragma_Debug => Debug : declare
7438 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7441 if Arg_Count = 2 then
7444 Left_Opnd => Relocate_Node (Cond),
7445 Right_Opnd => Get_Pragma_Arg (Arg1));
7446 Call := Get_Pragma_Arg (Arg2);
7448 Call := Get_Pragma_Arg (Arg1);
7452 N_Indexed_Component,
7455 N_Selected_Component)
7457 -- If this pragma Debug comes from source, its argument was
7458 -- parsed as a name form (which is syntactically identical).
7459 -- Change it to a procedure call statement now.
7461 Change_Name_To_Procedure_Call_Statement (Call);
7463 elsif Nkind (Call) = N_Procedure_Call_Statement then
7465 -- Already in the form of a procedure call statement: nothing
7466 -- to do (could happen in case of an internally generated
7472 -- All other cases: diagnose error
7475 ("argument of pragma% is not procedure call", Sloc (Call));
7479 -- Rewrite into a conditional with an appropriate condition. We
7480 -- wrap the procedure call in a block so that overhead from e.g.
7481 -- use of the secondary stack does not generate execution overhead
7482 -- for suppressed conditions.
7484 Rewrite (N, Make_Implicit_If_Statement (N,
7486 Then_Statements => New_List (
7487 Make_Block_Statement (Loc,
7488 Handled_Statement_Sequence =>
7489 Make_Handled_Sequence_Of_Statements (Loc,
7490 Statements => New_List (Relocate_Node (Call)))))));
7498 -- pragma Debug_Policy (Check | Ignore)
7500 when Pragma_Debug_Policy =>
7502 Check_Arg_Count (1);
7503 Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7504 Debug_Pragmas_Enabled :=
7505 Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7507 ---------------------
7508 -- Detect_Blocking --
7509 ---------------------
7511 -- pragma Detect_Blocking;
7513 when Pragma_Detect_Blocking =>
7515 Check_Arg_Count (0);
7516 Check_Valid_Configuration_Pragma;
7517 Detect_Blocking := True;
7519 --------------------------
7520 -- Default_Storage_Pool --
7521 --------------------------
7523 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
7525 when Pragma_Default_Storage_Pool =>
7527 Check_Arg_Count (1);
7529 -- Default_Storage_Pool can appear as a configuration pragma, or
7530 -- in a declarative part or a package spec.
7532 if not Is_Configuration_Pragma then
7533 Check_Is_In_Decl_Part_Or_Package_Spec;
7536 -- Case of Default_Storage_Pool (null);
7538 if Nkind (Expression (Arg1)) = N_Null then
7539 Analyze (Expression (Arg1));
7541 -- This is an odd case, this is not really an expression, so
7542 -- we don't have a type for it. So just set the type to Empty.
7544 Set_Etype (Expression (Arg1), Empty);
7546 -- Case of Default_Storage_Pool (storage_pool_NAME);
7549 -- If it's a configuration pragma, then the only allowed
7550 -- argument is "null".
7552 if Is_Configuration_Pragma then
7553 Error_Pragma_Arg ("NULL expected", Arg1);
7556 -- The expected type for a non-"null" argument is
7557 -- Root_Storage_Pool'Class.
7560 (Get_Pragma_Arg (Arg1),
7561 Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7564 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
7565 -- for an access type will use this information to set the
7566 -- appropriate attributes of the access type.
7568 Default_Pool := Expression (Arg1);
7574 when Pragma_Dimension =>
7576 Check_Arg_Count (4);
7577 Check_No_Identifiers;
7578 Check_Arg_Is_Local_Name (Arg1);
7580 if not Is_Type (Arg1) then
7581 Error_Pragma ("first argument for pragma% must be subtype");
7584 Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7585 Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7586 Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7592 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
7594 when Pragma_Discard_Names => Discard_Names : declare
7599 Check_Ada_83_Warning;
7601 -- Deal with configuration pragma case
7603 if Arg_Count = 0 and then Is_Configuration_Pragma then
7604 Global_Discard_Names := True;
7607 -- Otherwise, check correct appropriate context
7610 Check_Is_In_Decl_Part_Or_Package_Spec;
7612 if Arg_Count = 0 then
7614 -- If there is no parameter, then from now on this pragma
7615 -- applies to any enumeration, exception or tagged type
7616 -- defined in the current declarative part, and recursively
7617 -- to any nested scope.
7619 Set_Discard_Names (Current_Scope);
7623 Check_Arg_Count (1);
7624 Check_Optional_Identifier (Arg1, Name_On);
7625 Check_Arg_Is_Local_Name (Arg1);
7627 E_Id := Get_Pragma_Arg (Arg1);
7629 if Etype (E_Id) = Any_Type then
7635 if (Is_First_Subtype (E)
7637 (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7638 or else Ekind (E) = E_Exception
7640 Set_Discard_Names (E);
7643 ("inappropriate entity for pragma%", Arg1);
7654 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7656 when Pragma_Elaborate => Elaborate : declare
7661 -- Pragma must be in context items list of a compilation unit
7663 if not Is_In_Context_Clause then
7667 -- Must be at least one argument
7669 if Arg_Count = 0 then
7670 Error_Pragma ("pragma% requires at least one argument");
7673 -- In Ada 83 mode, there can be no items following it in the
7674 -- context list except other pragmas and implicit with clauses
7675 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7676 -- placement rule does not apply.
7678 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7680 while Present (Citem) loop
7681 if Nkind (Citem) = N_Pragma
7682 or else (Nkind (Citem) = N_With_Clause
7683 and then Implicit_With (Citem))
7688 ("(Ada 83) pragma% must be at end of context clause");
7695 -- Finally, the arguments must all be units mentioned in a with
7696 -- clause in the same context clause. Note we already checked (in
7697 -- Par.Prag) that the arguments are all identifiers or selected
7701 Outer : while Present (Arg) loop
7702 Citem := First (List_Containing (N));
7703 Inner : while Citem /= N loop
7704 if Nkind (Citem) = N_With_Clause
7705 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7707 Set_Elaborate_Present (Citem, True);
7708 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7709 Generate_Reference (Entity (Name (Citem)), Citem);
7711 -- With the pragma present, elaboration calls on
7712 -- subprograms from the named unit need no further
7713 -- checks, as long as the pragma appears in the current
7714 -- compilation unit. If the pragma appears in some unit
7715 -- in the context, there might still be a need for an
7716 -- Elaborate_All_Desirable from the current compilation
7717 -- to the named unit, so we keep the check enabled.
7719 if In_Extended_Main_Source_Unit (N) then
7720 Set_Suppress_Elaboration_Warnings
7721 (Entity (Name (Citem)));
7732 ("argument of pragma% is not with'ed unit", Arg);
7738 -- Give a warning if operating in static mode with -gnatwl
7739 -- (elaboration warnings enabled) switch set.
7741 if Elab_Warnings and not Dynamic_Elaboration_Checks then
7743 ("?use of pragma Elaborate may not be safe", N);
7745 ("?use pragma Elaborate_All instead if possible", N);
7753 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7755 when Pragma_Elaborate_All => Elaborate_All : declare
7760 Check_Ada_83_Warning;
7762 -- Pragma must be in context items list of a compilation unit
7764 if not Is_In_Context_Clause then
7768 -- Must be at least one argument
7770 if Arg_Count = 0 then
7771 Error_Pragma ("pragma% requires at least one argument");
7774 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
7775 -- have to appear at the end of the context clause, but may
7776 -- appear mixed in with other items, even in Ada 83 mode.
7778 -- Final check: the arguments must all be units mentioned in
7779 -- a with clause in the same context clause. Note that we
7780 -- already checked (in Par.Prag) that all the arguments are
7781 -- either identifiers or selected components.
7784 Outr : while Present (Arg) loop
7785 Citem := First (List_Containing (N));
7786 Innr : while Citem /= N loop
7787 if Nkind (Citem) = N_With_Clause
7788 and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7790 Set_Elaborate_All_Present (Citem, True);
7791 Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7793 -- Suppress warnings and elaboration checks on the named
7794 -- unit if the pragma is in the current compilation, as
7795 -- for pragma Elaborate.
7797 if In_Extended_Main_Source_Unit (N) then
7798 Set_Suppress_Elaboration_Warnings
7799 (Entity (Name (Citem)));
7808 Set_Error_Posted (N);
7810 ("argument of pragma% is not with'ed unit", Arg);
7817 --------------------
7818 -- Elaborate_Body --
7819 --------------------
7821 -- pragma Elaborate_Body [( library_unit_NAME )];
7823 when Pragma_Elaborate_Body => Elaborate_Body : declare
7824 Cunit_Node : Node_Id;
7825 Cunit_Ent : Entity_Id;
7828 Check_Ada_83_Warning;
7829 Check_Valid_Library_Unit_Pragma;
7831 if Nkind (N) = N_Null_Statement then
7835 Cunit_Node := Cunit (Current_Sem_Unit);
7836 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
7838 if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7841 Error_Pragma ("pragma% must refer to a spec, not a body");
7843 Set_Body_Required (Cunit_Node, True);
7844 Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7846 -- If we are in dynamic elaboration mode, then we suppress
7847 -- elaboration warnings for the unit, since it is definitely
7848 -- fine NOT to do dynamic checks at the first level (and such
7849 -- checks will be suppressed because no elaboration boolean
7850 -- is created for Elaborate_Body packages).
7852 -- But in the static model of elaboration, Elaborate_Body is
7853 -- definitely NOT good enough to ensure elaboration safety on
7854 -- its own, since the body may WITH other units that are not
7855 -- safe from an elaboration point of view, so a client must
7856 -- still do an Elaborate_All on such units.
7858 -- Debug flag -gnatdD restores the old behavior of 3.13, where
7859 -- Elaborate_Body always suppressed elab warnings.
7861 if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7862 Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7867 ------------------------
7868 -- Elaboration_Checks --
7869 ------------------------
7871 -- pragma Elaboration_Checks (Static | Dynamic);
7873 when Pragma_Elaboration_Checks =>
7875 Check_Arg_Count (1);
7876 Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7877 Dynamic_Elaboration_Checks :=
7878 (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7884 -- pragma Eliminate (
7885 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
7886 -- [,[Entity =>] IDENTIFIER |
7887 -- SELECTED_COMPONENT |
7889 -- [, OVERLOADING_RESOLUTION]);
7891 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7894 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7897 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7899 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7900 -- Result_Type => result_SUBTYPE_NAME]
7902 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7903 -- SUBTYPE_NAME ::= STRING_LITERAL
7905 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7906 -- SOURCE_TRACE ::= STRING_LITERAL
7908 when Pragma_Eliminate => Eliminate : declare
7909 Args : Args_List (1 .. 5);
7910 Names : constant Name_List (1 .. 5) := (
7913 Name_Parameter_Types,
7915 Name_Source_Location);
7917 Unit_Name : Node_Id renames Args (1);
7918 Entity : Node_Id renames Args (2);
7919 Parameter_Types : Node_Id renames Args (3);
7920 Result_Type : Node_Id renames Args (4);
7921 Source_Location : Node_Id renames Args (5);
7925 Check_Valid_Configuration_Pragma;
7926 Gather_Associations (Names, Args);
7928 if No (Unit_Name) then
7929 Error_Pragma ("missing Unit_Name argument for pragma%");
7933 and then (Present (Parameter_Types)
7935 Present (Result_Type)
7937 Present (Source_Location))
7939 Error_Pragma ("missing Entity argument for pragma%");
7942 if (Present (Parameter_Types)
7944 Present (Result_Type))
7946 Present (Source_Location)
7949 ("parameter profile and source location cannot " &
7950 "be used together in pragma%");
7953 Process_Eliminate_Pragma
7967 -- [ Convention =>] convention_IDENTIFIER,
7968 -- [ Entity =>] local_NAME
7969 -- [, [External_Name =>] static_string_EXPRESSION ]
7970 -- [, [Link_Name =>] static_string_EXPRESSION ]);
7972 when Pragma_Export => Export : declare
7976 pragma Warnings (Off, C);
7979 Check_Ada_83_Warning;
7985 Check_At_Least_N_Arguments (2);
7986 Check_At_Most_N_Arguments (4);
7987 Process_Convention (C, Def_Id);
7989 if Ekind (Def_Id) /= E_Constant then
7990 Note_Possible_Modification
7991 (Get_Pragma_Arg (Arg2), Sure => False);
7994 Process_Interface_Name (Def_Id, Arg3, Arg4);
7995 Set_Exported (Def_Id, Arg2);
7997 -- If the entity is a deferred constant, propagate the information
7998 -- to the full view, because gigi elaborates the full view only.
8000 if Ekind (Def_Id) = E_Constant
8001 and then Present (Full_View (Def_Id))
8004 Id2 : constant Entity_Id := Full_View (Def_Id);
8006 Set_Is_Exported (Id2, Is_Exported (Def_Id));
8007 Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id));
8008 Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8013 ----------------------
8014 -- Export_Exception --
8015 ----------------------
8017 -- pragma Export_Exception (
8018 -- [Internal =>] LOCAL_NAME
8019 -- [, [External =>] EXTERNAL_SYMBOL]
8020 -- [, [Form =>] Ada | VMS]
8021 -- [, [Code =>] static_integer_EXPRESSION]);
8023 when Pragma_Export_Exception => Export_Exception : declare
8024 Args : Args_List (1 .. 4);
8025 Names : constant Name_List (1 .. 4) := (
8031 Internal : Node_Id renames Args (1);
8032 External : Node_Id renames Args (2);
8033 Form : Node_Id renames Args (3);
8034 Code : Node_Id renames Args (4);
8039 if Inside_A_Generic then
8040 Error_Pragma ("pragma% cannot be used for generic entities");
8043 Gather_Associations (Names, Args);
8044 Process_Extended_Import_Export_Exception_Pragma (
8045 Arg_Internal => Internal,
8046 Arg_External => External,
8050 if not Is_VMS_Exception (Entity (Internal)) then
8051 Set_Exported (Entity (Internal), Internal);
8053 end Export_Exception;
8055 ---------------------
8056 -- Export_Function --
8057 ---------------------
8059 -- pragma Export_Function (
8060 -- [Internal =>] LOCAL_NAME
8061 -- [, [External =>] EXTERNAL_SYMBOL]
8062 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8063 -- [, [Result_Type =>] TYPE_DESIGNATOR]
8064 -- [, [Mechanism =>] MECHANISM]
8065 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
8067 -- EXTERNAL_SYMBOL ::=
8069 -- | static_string_EXPRESSION
8071 -- PARAMETER_TYPES ::=
8073 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8075 -- TYPE_DESIGNATOR ::=
8077 -- | subtype_Name ' Access
8081 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8083 -- MECHANISM_ASSOCIATION ::=
8084 -- [formal_parameter_NAME =>] MECHANISM_NAME
8086 -- MECHANISM_NAME ::=
8089 -- | Descriptor [([Class =>] CLASS_NAME)]
8091 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8093 when Pragma_Export_Function => Export_Function : declare
8094 Args : Args_List (1 .. 6);
8095 Names : constant Name_List (1 .. 6) := (
8098 Name_Parameter_Types,
8101 Name_Result_Mechanism);
8103 Internal : Node_Id renames Args (1);
8104 External : Node_Id renames Args (2);
8105 Parameter_Types : Node_Id renames Args (3);
8106 Result_Type : Node_Id renames Args (4);
8107 Mechanism : Node_Id renames Args (5);
8108 Result_Mechanism : Node_Id renames Args (6);
8112 Gather_Associations (Names, Args);
8113 Process_Extended_Import_Export_Subprogram_Pragma (
8114 Arg_Internal => Internal,
8115 Arg_External => External,
8116 Arg_Parameter_Types => Parameter_Types,
8117 Arg_Result_Type => Result_Type,
8118 Arg_Mechanism => Mechanism,
8119 Arg_Result_Mechanism => Result_Mechanism);
8120 end Export_Function;
8126 -- pragma Export_Object (
8127 -- [Internal =>] LOCAL_NAME
8128 -- [, [External =>] EXTERNAL_SYMBOL]
8129 -- [, [Size =>] EXTERNAL_SYMBOL]);
8131 -- EXTERNAL_SYMBOL ::=
8133 -- | static_string_EXPRESSION
8135 -- PARAMETER_TYPES ::=
8137 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8139 -- TYPE_DESIGNATOR ::=
8141 -- | subtype_Name ' Access
8145 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8147 -- MECHANISM_ASSOCIATION ::=
8148 -- [formal_parameter_NAME =>] MECHANISM_NAME
8150 -- MECHANISM_NAME ::=
8153 -- | Descriptor [([Class =>] CLASS_NAME)]
8155 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8157 when Pragma_Export_Object => Export_Object : declare
8158 Args : Args_List (1 .. 3);
8159 Names : constant Name_List (1 .. 3) := (
8164 Internal : Node_Id renames Args (1);
8165 External : Node_Id renames Args (2);
8166 Size : Node_Id renames Args (3);
8170 Gather_Associations (Names, Args);
8171 Process_Extended_Import_Export_Object_Pragma (
8172 Arg_Internal => Internal,
8173 Arg_External => External,
8177 ----------------------
8178 -- Export_Procedure --
8179 ----------------------
8181 -- pragma Export_Procedure (
8182 -- [Internal =>] LOCAL_NAME
8183 -- [, [External =>] EXTERNAL_SYMBOL]
8184 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8185 -- [, [Mechanism =>] MECHANISM]);
8187 -- EXTERNAL_SYMBOL ::=
8189 -- | static_string_EXPRESSION
8191 -- PARAMETER_TYPES ::=
8193 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8195 -- TYPE_DESIGNATOR ::=
8197 -- | subtype_Name ' Access
8201 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8203 -- MECHANISM_ASSOCIATION ::=
8204 -- [formal_parameter_NAME =>] MECHANISM_NAME
8206 -- MECHANISM_NAME ::=
8209 -- | Descriptor [([Class =>] CLASS_NAME)]
8211 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8213 when Pragma_Export_Procedure => Export_Procedure : declare
8214 Args : Args_List (1 .. 4);
8215 Names : constant Name_List (1 .. 4) := (
8218 Name_Parameter_Types,
8221 Internal : Node_Id renames Args (1);
8222 External : Node_Id renames Args (2);
8223 Parameter_Types : Node_Id renames Args (3);
8224 Mechanism : Node_Id renames Args (4);
8228 Gather_Associations (Names, Args);
8229 Process_Extended_Import_Export_Subprogram_Pragma (
8230 Arg_Internal => Internal,
8231 Arg_External => External,
8232 Arg_Parameter_Types => Parameter_Types,
8233 Arg_Mechanism => Mechanism);
8234 end Export_Procedure;
8240 -- pragma Export_Value (
8241 -- [Value =>] static_integer_EXPRESSION,
8242 -- [Link_Name =>] static_string_EXPRESSION);
8244 when Pragma_Export_Value =>
8246 Check_Arg_Order ((Name_Value, Name_Link_Name));
8247 Check_Arg_Count (2);
8249 Check_Optional_Identifier (Arg1, Name_Value);
8250 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8252 Check_Optional_Identifier (Arg2, Name_Link_Name);
8253 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8255 -----------------------------
8256 -- Export_Valued_Procedure --
8257 -----------------------------
8259 -- pragma Export_Valued_Procedure (
8260 -- [Internal =>] LOCAL_NAME
8261 -- [, [External =>] EXTERNAL_SYMBOL,]
8262 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8263 -- [, [Mechanism =>] MECHANISM]);
8265 -- EXTERNAL_SYMBOL ::=
8267 -- | static_string_EXPRESSION
8269 -- PARAMETER_TYPES ::=
8271 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8273 -- TYPE_DESIGNATOR ::=
8275 -- | subtype_Name ' Access
8279 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8281 -- MECHANISM_ASSOCIATION ::=
8282 -- [formal_parameter_NAME =>] MECHANISM_NAME
8284 -- MECHANISM_NAME ::=
8287 -- | Descriptor [([Class =>] CLASS_NAME)]
8289 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8291 when Pragma_Export_Valued_Procedure =>
8292 Export_Valued_Procedure : declare
8293 Args : Args_List (1 .. 4);
8294 Names : constant Name_List (1 .. 4) := (
8297 Name_Parameter_Types,
8300 Internal : Node_Id renames Args (1);
8301 External : Node_Id renames Args (2);
8302 Parameter_Types : Node_Id renames Args (3);
8303 Mechanism : Node_Id renames Args (4);
8307 Gather_Associations (Names, Args);
8308 Process_Extended_Import_Export_Subprogram_Pragma (
8309 Arg_Internal => Internal,
8310 Arg_External => External,
8311 Arg_Parameter_Types => Parameter_Types,
8312 Arg_Mechanism => Mechanism);
8313 end Export_Valued_Procedure;
8319 -- pragma Extend_System ([Name =>] Identifier);
8321 when Pragma_Extend_System => Extend_System : declare
8324 Check_Valid_Configuration_Pragma;
8325 Check_Arg_Count (1);
8326 Check_Optional_Identifier (Arg1, Name_Name);
8327 Check_Arg_Is_Identifier (Arg1);
8329 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8332 and then Name_Buffer (1 .. 4) = "aux_"
8334 if Present (System_Extend_Pragma_Arg) then
8335 if Chars (Get_Pragma_Arg (Arg1)) =
8336 Chars (Expression (System_Extend_Pragma_Arg))
8340 Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8341 Error_Pragma ("pragma% conflicts with that #");
8345 System_Extend_Pragma_Arg := Arg1;
8347 if not GNAT_Mode then
8348 System_Extend_Unit := Arg1;
8352 Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8356 ------------------------
8357 -- Extensions_Allowed --
8358 ------------------------
8360 -- pragma Extensions_Allowed (ON | OFF);
8362 when Pragma_Extensions_Allowed =>
8364 Check_Arg_Count (1);
8365 Check_No_Identifiers;
8366 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8368 if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8369 Extensions_Allowed := True;
8370 Ada_Version := Ada_Version_Type'Last;
8373 Extensions_Allowed := False;
8374 Ada_Version := Ada_Version_Explicit;
8381 -- pragma External (
8382 -- [ Convention =>] convention_IDENTIFIER,
8383 -- [ Entity =>] local_NAME
8384 -- [, [External_Name =>] static_string_EXPRESSION ]
8385 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8387 when Pragma_External => External : declare
8391 pragma Warnings (Off, C);
8400 Check_At_Least_N_Arguments (2);
8401 Check_At_Most_N_Arguments (4);
8402 Process_Convention (C, Def_Id);
8403 Note_Possible_Modification
8404 (Get_Pragma_Arg (Arg2), Sure => False);
8405 Process_Interface_Name (Def_Id, Arg3, Arg4);
8406 Set_Exported (Def_Id, Arg2);
8409 --------------------------
8410 -- External_Name_Casing --
8411 --------------------------
8413 -- pragma External_Name_Casing (
8414 -- UPPERCASE | LOWERCASE
8415 -- [, AS_IS | UPPERCASE | LOWERCASE]);
8417 when Pragma_External_Name_Casing => External_Name_Casing : declare
8420 Check_No_Identifiers;
8422 if Arg_Count = 2 then
8424 (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8426 case Chars (Get_Pragma_Arg (Arg2)) is
8428 Opt.External_Name_Exp_Casing := As_Is;
8430 when Name_Uppercase =>
8431 Opt.External_Name_Exp_Casing := Uppercase;
8433 when Name_Lowercase =>
8434 Opt.External_Name_Exp_Casing := Lowercase;
8441 Check_Arg_Count (1);
8444 Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8446 case Chars (Get_Pragma_Arg (Arg1)) is
8447 when Name_Uppercase =>
8448 Opt.External_Name_Imp_Casing := Uppercase;
8450 when Name_Lowercase =>
8451 Opt.External_Name_Imp_Casing := Lowercase;
8456 end External_Name_Casing;
8458 --------------------------
8459 -- Favor_Top_Level --
8460 --------------------------
8462 -- pragma Favor_Top_Level (type_NAME);
8464 when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8465 Named_Entity : Entity_Id;
8469 Check_No_Identifiers;
8470 Check_Arg_Count (1);
8471 Check_Arg_Is_Local_Name (Arg1);
8472 Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8474 -- If it's an access-to-subprogram type (in particular, not a
8475 -- subtype), set the flag on that type.
8477 if Is_Access_Subprogram_Type (Named_Entity) then
8478 Set_Can_Use_Internal_Rep (Named_Entity, False);
8480 -- Otherwise it's an error (name denotes the wrong sort of entity)
8484 ("access-to-subprogram type expected",
8485 Get_Pragma_Arg (Arg1));
8487 end Favor_Top_Level;
8493 -- pragma Fast_Math;
8495 when Pragma_Fast_Math =>
8497 Check_No_Identifiers;
8498 Check_Valid_Configuration_Pragma;
8501 ---------------------------
8502 -- Finalize_Storage_Only --
8503 ---------------------------
8505 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8507 when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8508 Assoc : constant Node_Id := Arg1;
8509 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8514 Check_No_Identifiers;
8515 Check_Arg_Count (1);
8516 Check_Arg_Is_Local_Name (Arg1);
8518 Find_Type (Type_Id);
8519 Typ := Entity (Type_Id);
8522 or else Rep_Item_Too_Early (Typ, N)
8526 Typ := Underlying_Type (Typ);
8529 if not Is_Controlled (Typ) then
8530 Error_Pragma ("pragma% must specify controlled type");
8533 Check_First_Subtype (Arg1);
8535 if Finalize_Storage_Only (Typ) then
8536 Error_Pragma ("duplicate pragma%, only one allowed");
8538 elsif not Rep_Item_Too_Late (Typ, N) then
8539 Set_Finalize_Storage_Only (Base_Type (Typ), True);
8541 end Finalize_Storage;
8543 --------------------------
8544 -- Float_Representation --
8545 --------------------------
8547 -- pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8549 -- FLOAT_REP ::= VAX_Float | IEEE_Float
8551 when Pragma_Float_Representation => Float_Representation : declare
8559 if Arg_Count = 1 then
8560 Check_Valid_Configuration_Pragma;
8562 Check_Arg_Count (2);
8563 Check_Optional_Identifier (Arg2, Name_Entity);
8564 Check_Arg_Is_Local_Name (Arg2);
8567 Check_No_Identifier (Arg1);
8568 Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8570 if not OpenVMS_On_Target then
8571 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8573 ("?pragma% ignored (applies only to Open'V'M'S)");
8579 -- One argument case
8581 if Arg_Count = 1 then
8582 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8583 if Opt.Float_Format = 'I' then
8584 Error_Pragma ("'I'E'E'E format previously specified");
8587 Opt.Float_Format := 'V';
8590 if Opt.Float_Format = 'V' then
8591 Error_Pragma ("'V'A'X format previously specified");
8594 Opt.Float_Format := 'I';
8597 Set_Standard_Fpt_Formats;
8599 -- Two argument case
8602 Argx := Get_Pragma_Arg (Arg2);
8604 if not Is_Entity_Name (Argx)
8605 or else not Is_Floating_Point_Type (Entity (Argx))
8608 ("second argument of% pragma must be floating-point type",
8612 Ent := Entity (Argx);
8613 Digs := UI_To_Int (Digits_Value (Ent));
8615 -- Two arguments, VAX_Float case
8617 if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8619 when 6 => Set_F_Float (Ent);
8620 when 9 => Set_D_Float (Ent);
8621 when 15 => Set_G_Float (Ent);
8625 ("wrong digits value, must be 6,9 or 15", Arg2);
8628 -- Two arguments, IEEE_Float case
8632 when 6 => Set_IEEE_Short (Ent);
8633 when 15 => Set_IEEE_Long (Ent);
8637 ("wrong digits value, must be 6 or 15", Arg2);
8641 end Float_Representation;
8647 -- pragma Ident (static_string_EXPRESSION)
8649 -- Note: pragma Comment shares this processing. Pragma Comment is
8650 -- identical to Ident, except that the restriction of the argument to
8651 -- 31 characters and the placement restrictions are not enforced for
8654 when Pragma_Ident | Pragma_Comment => Ident : declare
8659 Check_Arg_Count (1);
8660 Check_No_Identifiers;
8661 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8664 -- For pragma Ident, preserve DEC compatibility by requiring the
8665 -- pragma to appear in a declarative part or package spec.
8667 if Prag_Id = Pragma_Ident then
8668 Check_Is_In_Decl_Part_Or_Package_Spec;
8671 Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8678 GP := Parent (Parent (N));
8680 if Nkind_In (GP, N_Package_Declaration,
8681 N_Generic_Package_Declaration)
8686 -- If we have a compilation unit, then record the ident value,
8687 -- checking for improper duplication.
8689 if Nkind (GP) = N_Compilation_Unit then
8690 CS := Ident_String (Current_Sem_Unit);
8692 if Present (CS) then
8694 -- For Ident, we do not permit multiple instances
8696 if Prag_Id = Pragma_Ident then
8697 Error_Pragma ("duplicate% pragma not permitted");
8699 -- For Comment, we concatenate the string, unless we want
8700 -- to preserve the tree structure for ASIS.
8702 elsif not ASIS_Mode then
8703 Start_String (Strval (CS));
8704 Store_String_Char (' ');
8705 Store_String_Chars (Strval (Str));
8706 Set_Strval (CS, End_String);
8710 -- In VMS, the effect of IDENT is achieved by passing
8711 -- --identification=name as a --for-linker switch.
8713 if OpenVMS_On_Target then
8716 ("--for-linker=--identification=");
8717 String_To_Name_Buffer (Strval (Str));
8718 Store_String_Chars (Name_Buffer (1 .. Name_Len));
8720 -- Only the last processed IDENT is saved. The main
8721 -- purpose is so an IDENT associated with a main
8722 -- procedure will be used in preference to an IDENT
8723 -- associated with a with'd package.
8725 Replace_Linker_Option_String
8726 (End_String, "--for-linker=--identification=");
8729 Set_Ident_String (Current_Sem_Unit, Str);
8732 -- For subunits, we just ignore the Ident, since in GNAT these
8733 -- are not separate object files, and hence not separate units
8734 -- in the unit table.
8736 elsif Nkind (GP) = N_Subunit then
8739 -- Otherwise we have a misplaced pragma Ident, but we ignore
8740 -- this if we are in an instantiation, since it comes from
8741 -- a generic, and has no relevance to the instantiation.
8743 elsif Prag_Id = Pragma_Ident then
8744 if Instantiation_Location (Loc) = No_Location then
8745 Error_Pragma ("pragma% only allowed at outer level");
8755 -- pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8756 -- implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8758 when Pragma_Implemented => Implemented : declare
8759 Proc_Id : Entity_Id;
8764 Check_Arg_Count (2);
8765 Check_No_Identifiers;
8766 Check_Arg_Is_Identifier (Arg1);
8767 Check_Arg_Is_Local_Name (Arg1);
8769 (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8771 -- Extract the name of the local procedure
8773 Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8775 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8776 -- primitive procedure of a synchronized tagged type.
8778 if Ekind (Proc_Id) = E_Procedure
8779 and then Is_Primitive (Proc_Id)
8780 and then Present (First_Formal (Proc_Id))
8782 Typ := Etype (First_Formal (Proc_Id));
8784 if Is_Tagged_Type (Typ)
8787 -- Check for a protected, a synchronized or a task interface
8789 ((Is_Interface (Typ)
8790 and then Is_Synchronized_Interface (Typ))
8792 -- Check for a protected type or a task type that implements
8796 (Is_Concurrent_Record_Type (Typ)
8797 and then Present (Interfaces (Typ)))
8799 -- Check for a private record extension with keyword
8803 (Ekind_In (Typ, E_Record_Type_With_Private,
8804 E_Record_Subtype_With_Private)
8805 and then Synchronized_Present (Parent (Typ))))
8810 ("controlling formal must be of synchronized " &
8811 "tagged type", Arg1);
8815 -- Procedures declared inside a protected type must be accepted
8817 elsif Ekind (Proc_Id) = E_Procedure
8818 and then Is_Protected_Type (Scope (Proc_Id))
8822 -- The first argument is not a primitive procedure
8826 ("pragma % must be applied to a primitive procedure", Arg1);
8830 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8831 -- By_Protected_Procedure to the primitive procedure of a task
8834 if Chars (Arg2) = Name_By_Protected_Procedure
8835 and then Is_Interface (Typ)
8836 and then Is_Task_Interface (Typ)
8839 ("implementation kind By_Protected_Procedure cannot be " &
8840 "applied to a task interface primitive", Arg2);
8844 Record_Rep_Item (Proc_Id, N);
8847 ----------------------
8848 -- Implicit_Packing --
8849 ----------------------
8851 -- pragma Implicit_Packing;
8853 when Pragma_Implicit_Packing =>
8855 Check_Arg_Count (0);
8856 Implicit_Packing := True;
8863 -- [Convention =>] convention_IDENTIFIER,
8864 -- [Entity =>] local_NAME
8865 -- [, [External_Name =>] static_string_EXPRESSION ]
8866 -- [, [Link_Name =>] static_string_EXPRESSION ]);
8868 when Pragma_Import =>
8869 Check_Ada_83_Warning;
8875 Check_At_Least_N_Arguments (2);
8876 Check_At_Most_N_Arguments (4);
8877 Process_Import_Or_Interface;
8879 ----------------------
8880 -- Import_Exception --
8881 ----------------------
8883 -- pragma Import_Exception (
8884 -- [Internal =>] LOCAL_NAME
8885 -- [, [External =>] EXTERNAL_SYMBOL]
8886 -- [, [Form =>] Ada | VMS]
8887 -- [, [Code =>] static_integer_EXPRESSION]);
8889 when Pragma_Import_Exception => Import_Exception : declare
8890 Args : Args_List (1 .. 4);
8891 Names : constant Name_List (1 .. 4) := (
8897 Internal : Node_Id renames Args (1);
8898 External : Node_Id renames Args (2);
8899 Form : Node_Id renames Args (3);
8900 Code : Node_Id renames Args (4);
8904 Gather_Associations (Names, Args);
8906 if Present (External) and then Present (Code) then
8908 ("cannot give both External and Code options for pragma%");
8911 Process_Extended_Import_Export_Exception_Pragma (
8912 Arg_Internal => Internal,
8913 Arg_External => External,
8917 if not Is_VMS_Exception (Entity (Internal)) then
8918 Set_Imported (Entity (Internal));
8920 end Import_Exception;
8922 ---------------------
8923 -- Import_Function --
8924 ---------------------
8926 -- pragma Import_Function (
8927 -- [Internal =>] LOCAL_NAME,
8928 -- [, [External =>] EXTERNAL_SYMBOL]
8929 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
8930 -- [, [Result_Type =>] SUBTYPE_MARK]
8931 -- [, [Mechanism =>] MECHANISM]
8932 -- [, [Result_Mechanism =>] MECHANISM_NAME]
8933 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
8935 -- EXTERNAL_SYMBOL ::=
8937 -- | static_string_EXPRESSION
8939 -- PARAMETER_TYPES ::=
8941 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8943 -- TYPE_DESIGNATOR ::=
8945 -- | subtype_Name ' Access
8949 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8951 -- MECHANISM_ASSOCIATION ::=
8952 -- [formal_parameter_NAME =>] MECHANISM_NAME
8954 -- MECHANISM_NAME ::=
8957 -- | Descriptor [([Class =>] CLASS_NAME)]
8959 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8961 when Pragma_Import_Function => Import_Function : declare
8962 Args : Args_List (1 .. 7);
8963 Names : constant Name_List (1 .. 7) := (
8966 Name_Parameter_Types,
8969 Name_Result_Mechanism,
8970 Name_First_Optional_Parameter);
8972 Internal : Node_Id renames Args (1);
8973 External : Node_Id renames Args (2);
8974 Parameter_Types : Node_Id renames Args (3);
8975 Result_Type : Node_Id renames Args (4);
8976 Mechanism : Node_Id renames Args (5);
8977 Result_Mechanism : Node_Id renames Args (6);
8978 First_Optional_Parameter : Node_Id renames Args (7);
8982 Gather_Associations (Names, Args);
8983 Process_Extended_Import_Export_Subprogram_Pragma (
8984 Arg_Internal => Internal,
8985 Arg_External => External,
8986 Arg_Parameter_Types => Parameter_Types,
8987 Arg_Result_Type => Result_Type,
8988 Arg_Mechanism => Mechanism,
8989 Arg_Result_Mechanism => Result_Mechanism,
8990 Arg_First_Optional_Parameter => First_Optional_Parameter);
8991 end Import_Function;
8997 -- pragma Import_Object (
8998 -- [Internal =>] LOCAL_NAME
8999 -- [, [External =>] EXTERNAL_SYMBOL]
9000 -- [, [Size =>] EXTERNAL_SYMBOL]);
9002 -- EXTERNAL_SYMBOL ::=
9004 -- | static_string_EXPRESSION
9006 when Pragma_Import_Object => Import_Object : declare
9007 Args : Args_List (1 .. 3);
9008 Names : constant Name_List (1 .. 3) := (
9013 Internal : Node_Id renames Args (1);
9014 External : Node_Id renames Args (2);
9015 Size : Node_Id renames Args (3);
9019 Gather_Associations (Names, Args);
9020 Process_Extended_Import_Export_Object_Pragma (
9021 Arg_Internal => Internal,
9022 Arg_External => External,
9026 ----------------------
9027 -- Import_Procedure --
9028 ----------------------
9030 -- pragma Import_Procedure (
9031 -- [Internal =>] LOCAL_NAME
9032 -- [, [External =>] EXTERNAL_SYMBOL]
9033 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9034 -- [, [Mechanism =>] MECHANISM]
9035 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9037 -- EXTERNAL_SYMBOL ::=
9039 -- | static_string_EXPRESSION
9041 -- PARAMETER_TYPES ::=
9043 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9045 -- TYPE_DESIGNATOR ::=
9047 -- | subtype_Name ' Access
9051 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9053 -- MECHANISM_ASSOCIATION ::=
9054 -- [formal_parameter_NAME =>] MECHANISM_NAME
9056 -- MECHANISM_NAME ::=
9059 -- | Descriptor [([Class =>] CLASS_NAME)]
9061 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9063 when Pragma_Import_Procedure => Import_Procedure : declare
9064 Args : Args_List (1 .. 5);
9065 Names : constant Name_List (1 .. 5) := (
9068 Name_Parameter_Types,
9070 Name_First_Optional_Parameter);
9072 Internal : Node_Id renames Args (1);
9073 External : Node_Id renames Args (2);
9074 Parameter_Types : Node_Id renames Args (3);
9075 Mechanism : Node_Id renames Args (4);
9076 First_Optional_Parameter : Node_Id renames Args (5);
9080 Gather_Associations (Names, Args);
9081 Process_Extended_Import_Export_Subprogram_Pragma (
9082 Arg_Internal => Internal,
9083 Arg_External => External,
9084 Arg_Parameter_Types => Parameter_Types,
9085 Arg_Mechanism => Mechanism,
9086 Arg_First_Optional_Parameter => First_Optional_Parameter);
9087 end Import_Procedure;
9089 -----------------------------
9090 -- Import_Valued_Procedure --
9091 -----------------------------
9093 -- pragma Import_Valued_Procedure (
9094 -- [Internal =>] LOCAL_NAME
9095 -- [, [External =>] EXTERNAL_SYMBOL]
9096 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
9097 -- [, [Mechanism =>] MECHANISM]
9098 -- [, [First_Optional_Parameter =>] IDENTIFIER]);
9100 -- EXTERNAL_SYMBOL ::=
9102 -- | static_string_EXPRESSION
9104 -- PARAMETER_TYPES ::=
9106 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9108 -- TYPE_DESIGNATOR ::=
9110 -- | subtype_Name ' Access
9114 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9116 -- MECHANISM_ASSOCIATION ::=
9117 -- [formal_parameter_NAME =>] MECHANISM_NAME
9119 -- MECHANISM_NAME ::=
9122 -- | Descriptor [([Class =>] CLASS_NAME)]
9124 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9126 when Pragma_Import_Valued_Procedure =>
9127 Import_Valued_Procedure : declare
9128 Args : Args_List (1 .. 5);
9129 Names : constant Name_List (1 .. 5) := (
9132 Name_Parameter_Types,
9134 Name_First_Optional_Parameter);
9136 Internal : Node_Id renames Args (1);
9137 External : Node_Id renames Args (2);
9138 Parameter_Types : Node_Id renames Args (3);
9139 Mechanism : Node_Id renames Args (4);
9140 First_Optional_Parameter : Node_Id renames Args (5);
9144 Gather_Associations (Names, Args);
9145 Process_Extended_Import_Export_Subprogram_Pragma (
9146 Arg_Internal => Internal,
9147 Arg_External => External,
9148 Arg_Parameter_Types => Parameter_Types,
9149 Arg_Mechanism => Mechanism,
9150 Arg_First_Optional_Parameter => First_Optional_Parameter);
9151 end Import_Valued_Procedure;
9157 -- pragma Independent (LOCAL_NAME);
9159 when Pragma_Independent => Independent : declare
9166 Check_Ada_83_Warning;
9168 Check_No_Identifiers;
9169 Check_Arg_Count (1);
9170 Check_Arg_Is_Local_Name (Arg1);
9171 E_Id := Get_Pragma_Arg (Arg1);
9173 if Etype (E_Id) = Any_Type then
9178 D := Declaration_Node (E);
9181 -- Check duplicate before we chain ourselves!
9183 Check_Duplicate_Pragma (E);
9185 -- Check appropriate entity
9188 if Rep_Item_Too_Early (E, N)
9190 Rep_Item_Too_Late (E, N)
9194 Check_First_Subtype (Arg1);
9197 elsif K = N_Object_Declaration
9198 or else (K = N_Component_Declaration
9199 and then Original_Record_Component (E) = E)
9201 if Rep_Item_Too_Late (E, N) then
9207 ("inappropriate entity for pragma%", Arg1);
9210 Independence_Checks.Append ((N, E));
9213 ----------------------------
9214 -- Independent_Components --
9215 ----------------------------
9217 -- pragma Atomic_Components (array_LOCAL_NAME);
9219 -- This processing is shared by Volatile_Components
9221 when Pragma_Independent_Components => Independent_Components : declare
9228 Check_Ada_83_Warning;
9230 Check_No_Identifiers;
9231 Check_Arg_Count (1);
9232 Check_Arg_Is_Local_Name (Arg1);
9233 E_Id := Get_Pragma_Arg (Arg1);
9235 if Etype (E_Id) = Any_Type then
9241 -- Check duplicate before we chain ourselves!
9243 Check_Duplicate_Pragma (E);
9245 -- Check appropriate entity
9247 if Rep_Item_Too_Early (E, N)
9249 Rep_Item_Too_Late (E, N)
9254 D := Declaration_Node (E);
9257 if (K = N_Full_Type_Declaration
9258 and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9260 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9261 and then Nkind (D) = N_Object_Declaration
9262 and then Nkind (Object_Definition (D)) =
9263 N_Constrained_Array_Definition)
9265 Independence_Checks.Append ((N, E));
9268 Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9270 end Independent_Components;
9272 ------------------------
9273 -- Initialize_Scalars --
9274 ------------------------
9276 -- pragma Initialize_Scalars;
9278 when Pragma_Initialize_Scalars =>
9280 Check_Arg_Count (0);
9281 Check_Valid_Configuration_Pragma;
9282 Check_Restriction (No_Initialize_Scalars, N);
9284 -- Initialize_Scalars creates false positives in CodePeer,
9285 -- so ignore this pragma in this mode.
9287 if not Restriction_Active (No_Initialize_Scalars)
9288 and then not CodePeer_Mode
9290 Init_Or_Norm_Scalars := True;
9291 Initialize_Scalars := True;
9298 -- pragma Inline ( NAME {, NAME} );
9300 when Pragma_Inline =>
9302 -- Pragma is active if inlining option is active
9304 Process_Inline (Inline_Active);
9310 -- pragma Inline_Always ( NAME {, NAME} );
9312 when Pragma_Inline_Always =>
9315 -- Pragma always active unless in CodePeer mode, since this causes
9316 -- walk order issues.
9318 if not CodePeer_Mode then
9319 Process_Inline (True);
9322 --------------------
9323 -- Inline_Generic --
9324 --------------------
9326 -- pragma Inline_Generic (NAME {, NAME});
9328 when Pragma_Inline_Generic =>
9330 Process_Generic_List;
9332 ----------------------
9333 -- Inspection_Point --
9334 ----------------------
9336 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
9338 when Pragma_Inspection_Point => Inspection_Point : declare
9343 if Arg_Count > 0 then
9346 Exp := Get_Pragma_Arg (Arg);
9349 if not Is_Entity_Name (Exp)
9350 or else not Is_Object (Entity (Exp))
9352 Error_Pragma_Arg ("object name required", Arg);
9359 end Inspection_Point;
9365 -- pragma Interface (
9366 -- [ Convention =>] convention_IDENTIFIER,
9367 -- [ Entity =>] local_NAME
9368 -- [, [External_Name =>] static_string_EXPRESSION ]
9369 -- [, [Link_Name =>] static_string_EXPRESSION ]);
9371 when Pragma_Interface =>
9378 Check_At_Least_N_Arguments (2);
9379 Check_At_Most_N_Arguments (4);
9380 Process_Import_Or_Interface;
9382 -- In Ada 2005, the permission to use Interface (a reserved word)
9383 -- as a pragma name is considered an obsolescent feature.
9385 if Ada_Version >= Ada_2005 then
9387 (No_Obsolescent_Features, Pragma_Identifier (N));
9390 --------------------
9391 -- Interface_Name --
9392 --------------------
9394 -- pragma Interface_Name (
9395 -- [ Entity =>] local_NAME
9396 -- [,[External_Name =>] static_string_EXPRESSION ]
9397 -- [,[Link_Name =>] static_string_EXPRESSION ]);
9399 when Pragma_Interface_Name => Interface_Name : declare
9408 ((Name_Entity, Name_External_Name, Name_Link_Name));
9409 Check_At_Least_N_Arguments (2);
9410 Check_At_Most_N_Arguments (3);
9411 Id := Get_Pragma_Arg (Arg1);
9414 if not Is_Entity_Name (Id) then
9416 ("first argument for pragma% must be entity name", Arg1);
9417 elsif Etype (Id) = Any_Type then
9420 Def_Id := Entity (Id);
9423 -- Special DEC-compatible processing for the object case, forces
9424 -- object to be imported.
9426 if Ekind (Def_Id) = E_Variable then
9427 Kill_Size_Check_Code (Def_Id);
9428 Note_Possible_Modification (Id, Sure => False);
9430 -- Initialization is not allowed for imported variable
9432 if Present (Expression (Parent (Def_Id)))
9433 and then Comes_From_Source (Expression (Parent (Def_Id)))
9435 Error_Msg_Sloc := Sloc (Def_Id);
9437 ("no initialization allowed for declaration of& #",
9441 -- For compatibility, support VADS usage of providing both
9442 -- pragmas Interface and Interface_Name to obtain the effect
9443 -- of a single Import pragma.
9445 if Is_Imported (Def_Id)
9446 and then Present (First_Rep_Item (Def_Id))
9447 and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9449 Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9453 Set_Imported (Def_Id);
9456 Set_Is_Public (Def_Id);
9457 Process_Interface_Name (Def_Id, Arg2, Arg3);
9460 -- Otherwise must be subprogram
9462 elsif not Is_Subprogram (Def_Id) then
9464 ("argument of pragma% is not subprogram", Arg1);
9467 Check_At_Most_N_Arguments (3);
9471 -- Loop through homonyms
9474 Def_Id := Get_Base_Subprogram (Hom_Id);
9476 if Is_Imported (Def_Id) then
9477 Process_Interface_Name (Def_Id, Arg2, Arg3);
9481 exit when From_Aspect_Specification (N);
9482 Hom_Id := Homonym (Hom_Id);
9484 exit when No (Hom_Id)
9485 or else Scope (Hom_Id) /= Current_Scope;
9490 ("argument of pragma% is not imported subprogram",
9496 -----------------------
9497 -- Interrupt_Handler --
9498 -----------------------
9500 -- pragma Interrupt_Handler (handler_NAME);
9502 when Pragma_Interrupt_Handler =>
9503 Check_Ada_83_Warning;
9504 Check_Arg_Count (1);
9505 Check_No_Identifiers;
9507 if No_Run_Time_Mode then
9508 Error_Msg_CRT ("Interrupt_Handler pragma", N);
9510 Check_Interrupt_Or_Attach_Handler;
9511 Process_Interrupt_Or_Attach_Handler;
9514 ------------------------
9515 -- Interrupt_Priority --
9516 ------------------------
9518 -- pragma Interrupt_Priority [(EXPRESSION)];
9520 when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9521 P : constant Node_Id := Parent (N);
9525 Check_Ada_83_Warning;
9527 if Arg_Count /= 0 then
9528 Arg := Get_Pragma_Arg (Arg1);
9529 Check_Arg_Count (1);
9530 Check_No_Identifiers;
9532 -- The expression must be analyzed in the special manner
9533 -- described in "Handling of Default and Per-Object
9534 -- Expressions" in sem.ads.
9536 Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9539 if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9543 elsif Has_Pragma_Priority (P) then
9544 Error_Pragma ("duplicate pragma% not allowed");
9547 Set_Has_Pragma_Priority (P, True);
9548 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9550 end Interrupt_Priority;
9552 ---------------------
9553 -- Interrupt_State --
9554 ---------------------
9556 -- pragma Interrupt_State (
9557 -- [Name =>] INTERRUPT_ID,
9558 -- [State =>] INTERRUPT_STATE);
9560 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9561 -- INTERRUPT_STATE => System | Runtime | User
9563 -- Note: if the interrupt id is given as an identifier, then it must
9564 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9565 -- given as a static integer expression which must be in the range of
9566 -- Ada.Interrupts.Interrupt_ID.
9568 when Pragma_Interrupt_State => Interrupt_State : declare
9570 Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9571 -- This is the entity Ada.Interrupts.Interrupt_ID;
9573 State_Type : Character;
9574 -- Set to 's'/'r'/'u' for System/Runtime/User
9577 -- Index to entry in Interrupt_States table
9580 -- Value of interrupt
9582 Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9583 -- The first argument to the pragma
9585 Int_Ent : Entity_Id;
9586 -- Interrupt entity in Ada.Interrupts.Names
9590 Check_Arg_Order ((Name_Name, Name_State));
9591 Check_Arg_Count (2);
9593 Check_Optional_Identifier (Arg1, Name_Name);
9594 Check_Optional_Identifier (Arg2, Name_State);
9595 Check_Arg_Is_Identifier (Arg2);
9597 -- First argument is identifier
9599 if Nkind (Arg1X) = N_Identifier then
9601 -- Search list of names in Ada.Interrupts.Names
9603 Int_Ent := First_Entity (RTE (RE_Names));
9605 if No (Int_Ent) then
9606 Error_Pragma_Arg ("invalid interrupt name", Arg1);
9608 elsif Chars (Int_Ent) = Chars (Arg1X) then
9609 Int_Val := Expr_Value (Constant_Value (Int_Ent));
9613 Next_Entity (Int_Ent);
9616 -- First argument is not an identifier, so it must be a static
9617 -- expression of type Ada.Interrupts.Interrupt_ID.
9620 Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9621 Int_Val := Expr_Value (Arg1X);
9623 if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9625 Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9628 ("value not in range of type " &
9629 """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9635 case Chars (Get_Pragma_Arg (Arg2)) is
9636 when Name_Runtime => State_Type := 'r';
9637 when Name_System => State_Type := 's';
9638 when Name_User => State_Type := 'u';
9641 Error_Pragma_Arg ("invalid interrupt state", Arg2);
9644 -- Check if entry is already stored
9646 IST_Num := Interrupt_States.First;
9648 -- If entry not found, add it
9650 if IST_Num > Interrupt_States.Last then
9651 Interrupt_States.Append
9652 ((Interrupt_Number => UI_To_Int (Int_Val),
9653 Interrupt_State => State_Type,
9654 Pragma_Loc => Loc));
9657 -- Case of entry for the same entry
9659 elsif Int_Val = Interrupt_States.Table (IST_Num).
9662 -- If state matches, done, no need to make redundant entry
9665 State_Type = Interrupt_States.Table (IST_Num).
9668 -- Otherwise if state does not match, error
9671 Interrupt_States.Table (IST_Num).Pragma_Loc;
9673 ("state conflicts with that given #", Arg2);
9677 IST_Num := IST_Num + 1;
9679 end Interrupt_State;
9686 -- ([Entity =>] type_LOCAL_NAME,
9687 -- [Check =>] EXPRESSION
9688 -- [,[Message =>] String_Expression]);
9690 when Pragma_Invariant => Invariant : declare
9695 pragma Unreferenced (Discard);
9699 Check_At_Least_N_Arguments (2);
9700 Check_At_Most_N_Arguments (3);
9701 Check_Optional_Identifier (Arg1, Name_Entity);
9702 Check_Optional_Identifier (Arg2, Name_Check);
9704 if Arg_Count = 3 then
9705 Check_Optional_Identifier (Arg3, Name_Message);
9706 Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9709 Check_Arg_Is_Local_Name (Arg1);
9711 Type_Id := Get_Pragma_Arg (Arg1);
9712 Find_Type (Type_Id);
9713 Typ := Entity (Type_Id);
9715 if Typ = Any_Type then
9718 elsif not Ekind_In (Typ, E_Private_Type,
9719 E_Record_Type_With_Private,
9720 E_Limited_Private_Type)
9723 ("pragma% only allowed for private type", Arg1);
9726 -- Note that the type has at least one invariant, and also that
9727 -- it has inheritable invariants if we have Invariant'Class.
9729 Set_Has_Invariants (Typ);
9731 if Class_Present (N) then
9732 Set_Has_Inheritable_Invariants (Typ);
9735 -- The remaining processing is simply to link the pragma on to
9736 -- the rep item chain, for processing when the type is frozen.
9737 -- This is accomplished by a call to Rep_Item_Too_Late.
9739 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9742 ----------------------
9743 -- Java_Constructor --
9744 ----------------------
9746 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9748 -- Also handles pragma CIL_Constructor
9750 when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9751 Java_Constructor : declare
9752 Convention : Convention_Id;
9756 This_Formal : Entity_Id;
9760 Check_Arg_Count (1);
9761 Check_Optional_Identifier (Arg1, Name_Entity);
9762 Check_Arg_Is_Local_Name (Arg1);
9764 Id := Get_Pragma_Arg (Arg1);
9765 Find_Program_Unit_Name (Id);
9767 -- If we did not find the name, we are done
9769 if Etype (Id) = Any_Type then
9773 -- Check wrong use of pragma in wrong VM target
9775 if VM_Target = No_VM then
9778 elsif VM_Target = CLI_Target
9779 and then Prag_Id = Pragma_Java_Constructor
9781 Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9783 elsif VM_Target = JVM_Target
9784 and then Prag_Id = Pragma_CIL_Constructor
9786 Error_Pragma ("must use pragma 'Java_'Constructor");
9790 when Pragma_CIL_Constructor => Convention := Convention_CIL;
9791 when Pragma_Java_Constructor => Convention := Convention_Java;
9792 when others => null;
9795 Hom_Id := Entity (Id);
9797 -- Loop through homonyms
9800 Def_Id := Get_Base_Subprogram (Hom_Id);
9802 -- The constructor is required to be a function
9804 if Ekind (Def_Id) /= E_Function then
9805 if VM_Target = JVM_Target then
9807 ("pragma% requires function returning a " &
9808 "'Java access type", Def_Id);
9811 ("pragma% requires function returning a " &
9812 "'C'I'L access type", Def_Id);
9816 -- Check arguments: For tagged type the first formal must be
9817 -- named "this" and its type must be a named access type
9818 -- designating a class-wide tagged type that has convention
9819 -- CIL/Java. The first formal must also have a null default
9820 -- value. For example:
9822 -- type Typ is tagged ...
9823 -- type Ref is access all Typ;
9824 -- pragma Convention (CIL, Typ);
9826 -- function New_Typ (This : Ref) return Ref;
9827 -- function New_Typ (This : Ref; I : Integer) return Ref;
9828 -- pragma Cil_Constructor (New_Typ);
9830 -- Reason: The first formal must NOT be a primitive of the
9833 -- This rule also applies to constructors of delegates used
9834 -- to interface with standard target libraries. For example:
9836 -- type Delegate is access procedure ...
9837 -- pragma Import (CIL, Delegate, ...);
9839 -- function new_Delegate
9840 -- (This : Delegate := null; ... ) return Delegate;
9842 -- For value-types this rule does not apply.
9844 if not Is_Value_Type (Etype (Def_Id)) then
9845 if No (First_Formal (Def_Id)) then
9846 Error_Msg_Name_1 := Pname;
9847 Error_Msg_N ("% function must have parameters", Def_Id);
9851 -- In the JRE library we have several occurrences in which
9852 -- the "this" parameter is not the first formal.
9854 This_Formal := First_Formal (Def_Id);
9856 -- In the JRE library we have several occurrences in which
9857 -- the "this" parameter is not the first formal. Search for
9860 if VM_Target = JVM_Target then
9861 while Present (This_Formal)
9862 and then Get_Name_String (Chars (This_Formal)) /= "this"
9864 Next_Formal (This_Formal);
9867 if No (This_Formal) then
9868 This_Formal := First_Formal (Def_Id);
9872 -- Warning: The first parameter should be named "this".
9873 -- We temporarily allow it because we have the following
9874 -- case in the Java runtime (file s-osinte.ads) ???
9876 -- function new_Thread
9877 -- (Self_Id : System.Address) return Thread_Id;
9878 -- pragma Java_Constructor (new_Thread);
9880 if VM_Target = JVM_Target
9881 and then Get_Name_String (Chars (First_Formal (Def_Id)))
9883 and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9887 elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9888 Error_Msg_Name_1 := Pname;
9890 ("first formal of % function must be named `this`",
9891 Parent (This_Formal));
9893 elsif not Is_Access_Type (Etype (This_Formal)) then
9894 Error_Msg_Name_1 := Pname;
9896 ("first formal of % function must be an access type",
9897 Parameter_Type (Parent (This_Formal)));
9899 -- For delegates the type of the first formal must be a
9900 -- named access-to-subprogram type (see previous example)
9902 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9903 and then Ekind (Etype (This_Formal))
9904 /= E_Access_Subprogram_Type
9906 Error_Msg_Name_1 := Pname;
9908 ("first formal of % function must be a named access" &
9909 " to subprogram type",
9910 Parameter_Type (Parent (This_Formal)));
9912 -- Warning: We should reject anonymous access types because
9913 -- the constructor must not be handled as a primitive of the
9914 -- tagged type. We temporarily allow it because this profile
9915 -- is currently generated by cil2ada???
9917 elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9918 and then not Ekind_In (Etype (This_Formal),
9920 E_General_Access_Type,
9921 E_Anonymous_Access_Type)
9923 Error_Msg_Name_1 := Pname;
9925 ("first formal of % function must be a named access" &
9927 Parameter_Type (Parent (This_Formal)));
9929 elsif Atree.Convention
9930 (Designated_Type (Etype (This_Formal))) /= Convention
9932 Error_Msg_Name_1 := Pname;
9934 if Convention = Convention_Java then
9936 ("pragma% requires convention 'Cil in designated" &
9938 Parameter_Type (Parent (This_Formal)));
9941 ("pragma% requires convention 'Java in designated" &
9943 Parameter_Type (Parent (This_Formal)));
9946 elsif No (Expression (Parent (This_Formal)))
9947 or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9949 Error_Msg_Name_1 := Pname;
9951 ("pragma% requires first formal with default `null`",
9952 Parameter_Type (Parent (This_Formal)));
9956 -- Check result type: the constructor must be a function
9958 -- * a value type (only allowed in the CIL compiler)
9959 -- * an access-to-subprogram type with convention Java/CIL
9960 -- * an access-type designating a type that has convention
9963 if Is_Value_Type (Etype (Def_Id)) then
9966 -- Access-to-subprogram type with convention Java/CIL
9968 elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9969 if Atree.Convention (Etype (Def_Id)) /= Convention then
9970 if Convention = Convention_Java then
9972 ("pragma% requires function returning a " &
9973 "'Java access type", Arg1);
9975 pragma Assert (Convention = Convention_CIL);
9977 ("pragma% requires function returning a " &
9978 "'C'I'L access type", Arg1);
9982 elsif Ekind (Etype (Def_Id)) in Access_Kind then
9983 if not Ekind_In (Etype (Def_Id), E_Access_Type,
9984 E_General_Access_Type)
9987 (Designated_Type (Etype (Def_Id))) /= Convention
9989 Error_Msg_Name_1 := Pname;
9991 if Convention = Convention_Java then
9993 ("pragma% requires function returning a named" &
9994 "'Java access type", Arg1);
9997 ("pragma% requires function returning a named" &
9998 "'C'I'L access type", Arg1);
10003 Set_Is_Constructor (Def_Id);
10004 Set_Convention (Def_Id, Convention);
10005 Set_Is_Imported (Def_Id);
10007 exit when From_Aspect_Specification (N);
10008 Hom_Id := Homonym (Hom_Id);
10010 exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10012 end Java_Constructor;
10014 ----------------------
10015 -- Java_Interface --
10016 ----------------------
10018 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
10020 when Pragma_Java_Interface => Java_Interface : declare
10026 Check_Arg_Count (1);
10027 Check_Optional_Identifier (Arg1, Name_Entity);
10028 Check_Arg_Is_Local_Name (Arg1);
10030 Arg := Get_Pragma_Arg (Arg1);
10033 if Etype (Arg) = Any_Type then
10037 if not Is_Entity_Name (Arg)
10038 or else not Is_Type (Entity (Arg))
10040 Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10043 Typ := Underlying_Type (Entity (Arg));
10045 -- For now simply check some of the semantic constraints on the
10046 -- type. This currently leaves out some restrictions on interface
10047 -- types, namely that the parent type must be java.lang.Object.Typ
10048 -- and that all primitives of the type should be declared
10051 if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10052 Error_Pragma_Arg ("pragma% requires an abstract "
10053 & "tagged type", Arg1);
10055 elsif not Has_Discriminants (Typ)
10056 or else Ekind (Etype (First_Discriminant (Typ)))
10057 /= E_Anonymous_Access_Type
10059 not Is_Class_Wide_Type
10060 (Designated_Type (Etype (First_Discriminant (Typ))))
10063 ("type must have a class-wide access discriminant", Arg1);
10065 end Java_Interface;
10071 -- pragma Keep_Names ([On => ] local_NAME);
10073 when Pragma_Keep_Names => Keep_Names : declare
10078 Check_Arg_Count (1);
10079 Check_Optional_Identifier (Arg1, Name_On);
10080 Check_Arg_Is_Local_Name (Arg1);
10082 Arg := Get_Pragma_Arg (Arg1);
10085 if Etype (Arg) = Any_Type then
10089 if not Is_Entity_Name (Arg)
10090 or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10093 ("pragma% requires a local enumeration type", Arg1);
10096 Set_Discard_Names (Entity (Arg), False);
10103 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10105 when Pragma_License =>
10107 Check_Arg_Count (1);
10108 Check_No_Identifiers;
10109 Check_Valid_Configuration_Pragma;
10110 Check_Arg_Is_Identifier (Arg1);
10113 Sind : constant Source_File_Index :=
10114 Source_Index (Current_Sem_Unit);
10117 case Chars (Get_Pragma_Arg (Arg1)) is
10119 Set_License (Sind, GPL);
10121 when Name_Modified_GPL =>
10122 Set_License (Sind, Modified_GPL);
10124 when Name_Restricted =>
10125 Set_License (Sind, Restricted);
10127 when Name_Unrestricted =>
10128 Set_License (Sind, Unrestricted);
10131 Error_Pragma_Arg ("invalid license name", Arg1);
10139 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10141 when Pragma_Link_With => Link_With : declare
10147 if Operating_Mode = Generate_Code
10148 and then In_Extended_Main_Source_Unit (N)
10150 Check_At_Least_N_Arguments (1);
10151 Check_No_Identifiers;
10152 Check_Is_In_Decl_Part_Or_Package_Spec;
10153 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10157 while Present (Arg) loop
10158 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10160 -- Store argument, converting sequences of spaces to a
10161 -- single null character (this is one of the differences
10162 -- in processing between Link_With and Linker_Options).
10164 Arg_Store : declare
10165 C : constant Char_Code := Get_Char_Code (' ');
10166 S : constant String_Id :=
10167 Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10168 L : constant Nat := String_Length (S);
10171 procedure Skip_Spaces;
10172 -- Advance F past any spaces
10178 procedure Skip_Spaces is
10180 while F <= L and then Get_String_Char (S, F) = C loop
10185 -- Start of processing for Arg_Store
10188 Skip_Spaces; -- skip leading spaces
10190 -- Loop through characters, changing any embedded
10191 -- sequence of spaces to a single null character (this
10192 -- is how Link_With/Linker_Options differ)
10195 if Get_String_Char (S, F) = C then
10198 Store_String_Char (ASCII.NUL);
10201 Store_String_Char (Get_String_Char (S, F));
10209 if Present (Arg) then
10210 Store_String_Char (ASCII.NUL);
10214 Store_Linker_Option_String (End_String);
10222 -- pragma Linker_Alias (
10223 -- [Entity =>] LOCAL_NAME
10224 -- [Target =>] static_string_EXPRESSION);
10226 when Pragma_Linker_Alias =>
10228 Check_Arg_Order ((Name_Entity, Name_Target));
10229 Check_Arg_Count (2);
10230 Check_Optional_Identifier (Arg1, Name_Entity);
10231 Check_Optional_Identifier (Arg2, Name_Target);
10232 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10233 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10235 -- The only processing required is to link this item on to the
10236 -- list of rep items for the given entity. This is accomplished
10237 -- by the call to Rep_Item_Too_Late (when no error is detected
10238 -- and False is returned).
10240 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10243 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10246 ------------------------
10247 -- Linker_Constructor --
10248 ------------------------
10250 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
10252 -- Code is shared with Linker_Destructor
10254 -----------------------
10255 -- Linker_Destructor --
10256 -----------------------
10258 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
10260 when Pragma_Linker_Constructor |
10261 Pragma_Linker_Destructor =>
10262 Linker_Constructor : declare
10268 Check_Arg_Count (1);
10269 Check_No_Identifiers;
10270 Check_Arg_Is_Local_Name (Arg1);
10271 Arg1_X := Get_Pragma_Arg (Arg1);
10273 Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10275 if not Is_Library_Level_Entity (Proc) then
10277 ("argument for pragma% must be library level entity", Arg1);
10280 -- The only processing required is to link this item on to the
10281 -- list of rep items for the given entity. This is accomplished
10282 -- by the call to Rep_Item_Too_Late (when no error is detected
10283 -- and False is returned).
10285 if Rep_Item_Too_Late (Proc, N) then
10288 Set_Has_Gigi_Rep_Item (Proc);
10290 end Linker_Constructor;
10292 --------------------
10293 -- Linker_Options --
10294 --------------------
10296 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10298 when Pragma_Linker_Options => Linker_Options : declare
10302 Check_Ada_83_Warning;
10303 Check_No_Identifiers;
10304 Check_Arg_Count (1);
10305 Check_Is_In_Decl_Part_Or_Package_Spec;
10306 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10307 Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10310 while Present (Arg) loop
10311 Check_Arg_Is_Static_Expression (Arg, Standard_String);
10312 Store_String_Char (ASCII.NUL);
10314 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10318 if Operating_Mode = Generate_Code
10319 and then In_Extended_Main_Source_Unit (N)
10321 Store_Linker_Option_String (End_String);
10323 end Linker_Options;
10325 --------------------
10326 -- Linker_Section --
10327 --------------------
10329 -- pragma Linker_Section (
10330 -- [Entity =>] LOCAL_NAME
10331 -- [Section =>] static_string_EXPRESSION);
10333 when Pragma_Linker_Section =>
10335 Check_Arg_Order ((Name_Entity, Name_Section));
10336 Check_Arg_Count (2);
10337 Check_Optional_Identifier (Arg1, Name_Entity);
10338 Check_Optional_Identifier (Arg2, Name_Section);
10339 Check_Arg_Is_Library_Level_Local_Name (Arg1);
10340 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10342 -- This pragma applies only to objects
10344 if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10345 Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10348 -- The only processing required is to link this item on to the
10349 -- list of rep items for the given entity. This is accomplished
10350 -- by the call to Rep_Item_Too_Late (when no error is detected
10351 -- and False is returned).
10353 if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10356 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10363 -- pragma List (On | Off)
10365 -- There is nothing to do here, since we did all the processing for
10366 -- this pragma in Par.Prag (so that it works properly even in syntax
10369 when Pragma_List =>
10372 --------------------
10373 -- Locking_Policy --
10374 --------------------
10376 -- pragma Locking_Policy (policy_IDENTIFIER);
10378 when Pragma_Locking_Policy => declare
10382 Check_Ada_83_Warning;
10383 Check_Arg_Count (1);
10384 Check_No_Identifiers;
10385 Check_Arg_Is_Locking_Policy (Arg1);
10386 Check_Valid_Configuration_Pragma;
10387 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10388 LP := Fold_Upper (Name_Buffer (1));
10390 if Locking_Policy /= ' '
10391 and then Locking_Policy /= LP
10393 Error_Msg_Sloc := Locking_Policy_Sloc;
10394 Error_Pragma ("locking policy incompatible with policy#");
10396 -- Set new policy, but always preserve System_Location since we
10397 -- like the error message with the run time name.
10400 Locking_Policy := LP;
10402 if Locking_Policy_Sloc /= System_Location then
10403 Locking_Policy_Sloc := Loc;
10412 -- pragma Long_Float (D_Float | G_Float);
10414 when Pragma_Long_Float =>
10416 Check_Valid_Configuration_Pragma;
10417 Check_Arg_Count (1);
10418 Check_No_Identifier (Arg1);
10419 Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10421 if not OpenVMS_On_Target then
10422 Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10427 if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10428 if Opt.Float_Format_Long = 'G' then
10429 Error_Pragma ("G_Float previously specified");
10432 Opt.Float_Format_Long := 'D';
10434 -- G_Float case (this is the default, does not need overriding)
10437 if Opt.Float_Format_Long = 'D' then
10438 Error_Pragma ("D_Float previously specified");
10441 Opt.Float_Format_Long := 'G';
10444 Set_Standard_Fpt_Formats;
10446 -----------------------
10447 -- Machine_Attribute --
10448 -----------------------
10450 -- pragma Machine_Attribute (
10451 -- [Entity =>] LOCAL_NAME,
10452 -- [Attribute_Name =>] static_string_EXPRESSION
10453 -- [, [Info =>] static_EXPRESSION] );
10455 when Pragma_Machine_Attribute => Machine_Attribute : declare
10456 Def_Id : Entity_Id;
10460 Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10462 if Arg_Count = 3 then
10463 Check_Optional_Identifier (Arg3, Name_Info);
10464 Check_Arg_Is_Static_Expression (Arg3);
10466 Check_Arg_Count (2);
10469 Check_Optional_Identifier (Arg1, Name_Entity);
10470 Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10471 Check_Arg_Is_Local_Name (Arg1);
10472 Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10473 Def_Id := Entity (Get_Pragma_Arg (Arg1));
10475 if Is_Access_Type (Def_Id) then
10476 Def_Id := Designated_Type (Def_Id);
10479 if Rep_Item_Too_Early (Def_Id, N) then
10483 Def_Id := Underlying_Type (Def_Id);
10485 -- The only processing required is to link this item on to the
10486 -- list of rep items for the given entity. This is accomplished
10487 -- by the call to Rep_Item_Too_Late (when no error is detected
10488 -- and False is returned).
10490 if Rep_Item_Too_Late (Def_Id, N) then
10493 Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10495 end Machine_Attribute;
10502 -- (MAIN_OPTION [, MAIN_OPTION]);
10505 -- [STACK_SIZE =>] static_integer_EXPRESSION
10506 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10507 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
10509 when Pragma_Main => Main : declare
10510 Args : Args_List (1 .. 3);
10511 Names : constant Name_List (1 .. 3) := (
10513 Name_Task_Stack_Size_Default,
10514 Name_Time_Slicing_Enabled);
10520 Gather_Associations (Names, Args);
10522 for J in 1 .. 2 loop
10523 if Present (Args (J)) then
10524 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10528 if Present (Args (3)) then
10529 Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10533 while Present (Nod) loop
10534 if Nkind (Nod) = N_Pragma
10535 and then Pragma_Name (Nod) = Name_Main
10537 Error_Msg_Name_1 := Pname;
10538 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10549 -- pragma Main_Storage
10550 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10552 -- MAIN_STORAGE_OPTION ::=
10553 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10554 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10556 when Pragma_Main_Storage => Main_Storage : declare
10557 Args : Args_List (1 .. 2);
10558 Names : constant Name_List (1 .. 2) := (
10559 Name_Working_Storage,
10566 Gather_Associations (Names, Args);
10568 for J in 1 .. 2 loop
10569 if Present (Args (J)) then
10570 Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10574 Check_In_Main_Program;
10577 while Present (Nod) loop
10578 if Nkind (Nod) = N_Pragma
10579 and then Pragma_Name (Nod) = Name_Main_Storage
10581 Error_Msg_Name_1 := Pname;
10582 Error_Msg_N ("duplicate pragma% not permitted", Nod);
10593 -- pragma Memory_Size (NUMERIC_LITERAL)
10595 when Pragma_Memory_Size =>
10598 -- Memory size is simply ignored
10600 Check_No_Identifiers;
10601 Check_Arg_Count (1);
10602 Check_Arg_Is_Integer_Literal (Arg1);
10610 -- The only correct use of this pragma is on its own in a file, in
10611 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
10612 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10613 -- check for a file containing nothing but a No_Body pragma). If we
10614 -- attempt to process it during normal semantics processing, it means
10615 -- it was misplaced.
10617 when Pragma_No_Body =>
10625 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10627 when Pragma_No_Return => No_Return : declare
10635 Check_At_Least_N_Arguments (1);
10637 -- Loop through arguments of pragma
10640 while Present (Arg) loop
10641 Check_Arg_Is_Local_Name (Arg);
10642 Id := Get_Pragma_Arg (Arg);
10645 if not Is_Entity_Name (Id) then
10646 Error_Pragma_Arg ("entity name required", Arg);
10649 if Etype (Id) = Any_Type then
10653 -- Loop to find matching procedures
10658 and then Scope (E) = Current_Scope
10660 if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10663 -- Set flag on any alias as well
10665 if Is_Overloadable (E) and then Present (Alias (E)) then
10666 Set_No_Return (Alias (E));
10672 exit when From_Aspect_Specification (N);
10677 Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10688 -- pragma No_Run_Time;
10690 -- Note: this pragma is retained for backwards compatibility. See
10691 -- body of Rtsfind for full details on its handling.
10693 when Pragma_No_Run_Time =>
10695 Check_Valid_Configuration_Pragma;
10696 Check_Arg_Count (0);
10698 No_Run_Time_Mode := True;
10699 Configurable_Run_Time_Mode := True;
10701 -- Set Duration to 32 bits if word size is 32
10703 if Ttypes.System_Word_Size = 32 then
10704 Duration_32_Bits_On_Target := True;
10707 -- Set appropriate restrictions
10709 Set_Restriction (No_Finalization, N);
10710 Set_Restriction (No_Exception_Handlers, N);
10711 Set_Restriction (Max_Tasks, N, 0);
10712 Set_Restriction (No_Tasking, N);
10714 ------------------------
10715 -- No_Strict_Aliasing --
10716 ------------------------
10718 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10720 when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10725 Check_At_Most_N_Arguments (1);
10727 if Arg_Count = 0 then
10728 Check_Valid_Configuration_Pragma;
10729 Opt.No_Strict_Aliasing := True;
10732 Check_Optional_Identifier (Arg2, Name_Entity);
10733 Check_Arg_Is_Local_Name (Arg1);
10734 E_Id := Entity (Get_Pragma_Arg (Arg1));
10736 if E_Id = Any_Type then
10738 elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10739 Error_Pragma_Arg ("pragma% requires access type", Arg1);
10742 Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10744 end No_Strict_Aliasing;
10746 -----------------------
10747 -- Normalize_Scalars --
10748 -----------------------
10750 -- pragma Normalize_Scalars;
10752 when Pragma_Normalize_Scalars =>
10753 Check_Ada_83_Warning;
10754 Check_Arg_Count (0);
10755 Check_Valid_Configuration_Pragma;
10757 -- Normalize_Scalars creates false positives in CodePeer, so
10758 -- ignore this pragma in this mode.
10760 if not CodePeer_Mode then
10761 Normalize_Scalars := True;
10762 Init_Or_Norm_Scalars := True;
10769 -- pragma Obsolescent;
10771 -- pragma Obsolescent (
10772 -- [Message =>] static_string_EXPRESSION
10773 -- [,[Version =>] Ada_05]]);
10775 -- pragma Obsolescent (
10776 -- [Entity =>] NAME
10777 -- [,[Message =>] static_string_EXPRESSION
10778 -- [,[Version =>] Ada_05]] );
10780 when Pragma_Obsolescent => Obsolescent : declare
10784 procedure Set_Obsolescent (E : Entity_Id);
10785 -- Given an entity Ent, mark it as obsolescent if appropriate
10787 ---------------------
10788 -- Set_Obsolescent --
10789 ---------------------
10791 procedure Set_Obsolescent (E : Entity_Id) is
10800 -- Entity name was given
10802 if Present (Ename) then
10804 -- If entity name matches, we are fine. Save entity in
10805 -- pragma argument, for ASIS use.
10807 if Chars (Ename) = Chars (Ent) then
10808 Set_Entity (Ename, Ent);
10809 Generate_Reference (Ent, Ename);
10811 -- If entity name does not match, only possibility is an
10812 -- enumeration literal from an enumeration type declaration.
10814 elsif Ekind (Ent) /= E_Enumeration_Type then
10816 ("pragma % entity name does not match declaration");
10819 Ent := First_Literal (E);
10823 ("pragma % entity name does not match any " &
10824 "enumeration literal");
10826 elsif Chars (Ent) = Chars (Ename) then
10827 Set_Entity (Ename, Ent);
10828 Generate_Reference (Ent, Ename);
10832 Ent := Next_Literal (Ent);
10838 -- Ent points to entity to be marked
10840 if Arg_Count >= 1 then
10842 -- Deal with static string argument
10844 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10845 S := Strval (Get_Pragma_Arg (Arg1));
10847 for J in 1 .. String_Length (S) loop
10848 if not In_Character_Range (Get_String_Char (S, J)) then
10850 ("pragma% argument does not allow wide characters",
10855 Obsolescent_Warnings.Append
10856 ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10858 -- Check for Ada_05 parameter
10860 if Arg_Count /= 1 then
10861 Check_Arg_Count (2);
10864 Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10867 Check_Arg_Is_Identifier (Argx);
10869 if Chars (Argx) /= Name_Ada_05 then
10870 Error_Msg_Name_2 := Name_Ada_05;
10872 ("only allowed argument for pragma% is %", Argx);
10875 if Ada_Version_Explicit < Ada_2005
10876 or else not Warn_On_Ada_2005_Compatibility
10884 -- Set flag if pragma active
10887 Set_Is_Obsolescent (Ent);
10891 end Set_Obsolescent;
10893 -- Start of processing for pragma Obsolescent
10898 Check_At_Most_N_Arguments (3);
10900 -- See if first argument specifies an entity name
10904 (Chars (Arg1) = Name_Entity
10906 Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10908 N_Operator_Symbol))
10910 Ename := Get_Pragma_Arg (Arg1);
10912 -- Eliminate first argument, so we can share processing
10916 Arg_Count := Arg_Count - 1;
10918 -- No Entity name argument given
10924 if Arg_Count >= 1 then
10925 Check_Optional_Identifier (Arg1, Name_Message);
10927 if Arg_Count = 2 then
10928 Check_Optional_Identifier (Arg2, Name_Version);
10932 -- Get immediately preceding declaration
10935 while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10939 -- Cases where we do not follow anything other than another pragma
10943 -- First case: library level compilation unit declaration with
10944 -- the pragma immediately following the declaration.
10946 if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10948 (Defining_Entity (Unit (Parent (Parent (N)))));
10951 -- Case 2: library unit placement for package
10955 Ent : constant Entity_Id := Find_Lib_Unit_Name;
10957 if Is_Package_Or_Generic_Package (Ent) then
10958 Set_Obsolescent (Ent);
10964 -- Cases where we must follow a declaration
10967 if Nkind (Decl) not in N_Declaration
10968 and then Nkind (Decl) not in N_Later_Decl_Item
10969 and then Nkind (Decl) not in N_Generic_Declaration
10970 and then Nkind (Decl) not in N_Renaming_Declaration
10973 ("pragma% misplaced, "
10974 & "must immediately follow a declaration");
10977 Set_Obsolescent (Defining_Entity (Decl));
10987 -- pragma Optimize (Time | Space | Off);
10989 -- The actual check for optimize is done in Gigi. Note that this
10990 -- pragma does not actually change the optimization setting, it
10991 -- simply checks that it is consistent with the pragma.
10993 when Pragma_Optimize =>
10994 Check_No_Identifiers;
10995 Check_Arg_Count (1);
10996 Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10998 ------------------------
10999 -- Optimize_Alignment --
11000 ------------------------
11002 -- pragma Optimize_Alignment (Time | Space | Off);
11004 when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11006 Check_No_Identifiers;
11007 Check_Arg_Count (1);
11008 Check_Valid_Configuration_Pragma;
11011 Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11015 Opt.Optimize_Alignment := 'T';
11017 Opt.Optimize_Alignment := 'S';
11019 Opt.Optimize_Alignment := 'O';
11021 Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11025 -- Set indication that mode is set locally. If we are in fact in a
11026 -- configuration pragma file, this setting is harmless since the
11027 -- switch will get reset anyway at the start of each unit.
11029 Optimize_Alignment_Local := True;
11030 end Optimize_Alignment;
11036 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11038 when Pragma_Ordered => Ordered : declare
11039 Assoc : constant Node_Id := Arg1;
11045 Check_No_Identifiers;
11046 Check_Arg_Count (1);
11047 Check_Arg_Is_Local_Name (Arg1);
11049 Type_Id := Get_Pragma_Arg (Assoc);
11050 Find_Type (Type_Id);
11051 Typ := Entity (Type_Id);
11053 if Typ = Any_Type then
11056 Typ := Underlying_Type (Typ);
11059 if not Is_Enumeration_Type (Typ) then
11060 Error_Pragma ("pragma% must specify enumeration type");
11063 Check_First_Subtype (Arg1);
11064 Set_Has_Pragma_Ordered (Base_Type (Typ));
11071 -- pragma Pack (first_subtype_LOCAL_NAME);
11073 when Pragma_Pack => Pack : declare
11074 Assoc : constant Node_Id := Arg1;
11078 Ignore : Boolean := False;
11081 Check_No_Identifiers;
11082 Check_Arg_Count (1);
11083 Check_Arg_Is_Local_Name (Arg1);
11085 Type_Id := Get_Pragma_Arg (Assoc);
11086 Find_Type (Type_Id);
11087 Typ := Entity (Type_Id);
11090 or else Rep_Item_Too_Early (Typ, N)
11094 Typ := Underlying_Type (Typ);
11097 if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11098 Error_Pragma ("pragma% must specify array or record type");
11101 Check_First_Subtype (Arg1);
11102 Check_Duplicate_Pragma (Typ);
11106 if Is_Array_Type (Typ) then
11107 Ctyp := Component_Type (Typ);
11109 -- Ignore pack that does nothing
11111 if Known_Static_Esize (Ctyp)
11112 and then Known_Static_RM_Size (Ctyp)
11113 and then Esize (Ctyp) = RM_Size (Ctyp)
11114 and then Addressable (Esize (Ctyp))
11119 -- Process OK pragma Pack. Note that if there is a separate
11120 -- component clause present, the Pack will be cancelled. This
11121 -- processing is in Freeze.
11123 if not Rep_Item_Too_Late (Typ, N) then
11125 -- In the context of static code analysis, we do not need
11126 -- complex front-end expansions related to pragma Pack,
11127 -- so disable handling of pragma Pack in this case.
11129 if CodePeer_Mode then
11132 -- Don't attempt any packing for VM targets. We possibly
11133 -- could deal with some cases of array bit-packing, but we
11134 -- don't bother, since this is not a typical kind of
11135 -- representation in the VM context anyway (and would not
11136 -- for example work nicely with the debugger).
11138 elsif VM_Target /= No_VM then
11139 if not GNAT_Mode then
11141 ("?pragma% ignored in this configuration");
11144 -- Normal case where we do the pack action
11148 Set_Is_Packed (Base_Type (Typ));
11149 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11152 Set_Has_Pragma_Pack (Base_Type (Typ));
11156 -- For record types, the pack is always effective
11158 else pragma Assert (Is_Record_Type (Typ));
11159 if not Rep_Item_Too_Late (Typ, N) then
11161 -- Ignore pack request with warning in VM mode (skip warning
11162 -- if we are compiling GNAT run time library).
11164 if VM_Target /= No_VM then
11165 if not GNAT_Mode then
11167 ("?pragma% ignored in this configuration");
11170 -- Normal case of pack request active
11173 Set_Is_Packed (Base_Type (Typ));
11174 Set_Has_Pragma_Pack (Base_Type (Typ));
11175 Set_Has_Non_Standard_Rep (Base_Type (Typ));
11187 -- There is nothing to do here, since we did all the processing for
11188 -- this pragma in Par.Prag (so that it works properly even in syntax
11191 when Pragma_Page =>
11198 -- pragma Passive [(PASSIVE_FORM)];
11200 -- PASSIVE_FORM ::= Semaphore | No
11202 when Pragma_Passive =>
11205 if Nkind (Parent (N)) /= N_Task_Definition then
11206 Error_Pragma ("pragma% must be within task definition");
11209 if Arg_Count /= 0 then
11210 Check_Arg_Count (1);
11211 Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11214 ----------------------------------
11215 -- Preelaborable_Initialization --
11216 ----------------------------------
11218 -- pragma Preelaborable_Initialization (DIRECT_NAME);
11220 when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11225 Check_Arg_Count (1);
11226 Check_No_Identifiers;
11227 Check_Arg_Is_Identifier (Arg1);
11228 Check_Arg_Is_Local_Name (Arg1);
11229 Check_First_Subtype (Arg1);
11230 Ent := Entity (Get_Pragma_Arg (Arg1));
11232 if not (Is_Private_Type (Ent)
11234 Is_Protected_Type (Ent)
11236 (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11239 ("pragma % can only be applied to private, formal derived or "
11240 & "protected type",
11244 -- Give an error if the pragma is applied to a protected type that
11245 -- does not qualify (due to having entries, or due to components
11246 -- that do not qualify).
11248 if Is_Protected_Type (Ent)
11249 and then not Has_Preelaborable_Initialization (Ent)
11252 ("protected type & does not have preelaborable " &
11253 "initialization", Ent);
11255 -- Otherwise mark the type as definitely having preelaborable
11259 Set_Known_To_Have_Preelab_Init (Ent);
11262 if Has_Pragma_Preelab_Init (Ent)
11263 and then Warn_On_Redundant_Constructs
11265 Error_Pragma ("?duplicate pragma%!");
11267 Set_Has_Pragma_Preelab_Init (Ent);
11271 --------------------
11272 -- Persistent_BSS --
11273 --------------------
11275 -- pragma Persistent_BSS [(object_NAME)];
11277 when Pragma_Persistent_BSS => Persistent_BSS : declare
11284 Check_At_Most_N_Arguments (1);
11286 -- Case of application to specific object (one argument)
11288 if Arg_Count = 1 then
11289 Check_Arg_Is_Library_Level_Local_Name (Arg1);
11291 if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11293 Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11296 Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11299 Ent := Entity (Get_Pragma_Arg (Arg1));
11300 Decl := Parent (Ent);
11302 if Rep_Item_Too_Late (Ent, N) then
11306 if Present (Expression (Decl)) then
11308 ("object for pragma% cannot have initialization", Arg1);
11311 if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11313 ("object type for pragma% is not potentially persistent",
11317 Check_Duplicate_Pragma (Ent);
11320 Make_Linker_Section_Pragma
11321 (Ent, Sloc (N), ".persistent.bss");
11322 Insert_After (N, Prag);
11325 -- Case of use as configuration pragma with no arguments
11328 Check_Valid_Configuration_Pragma;
11329 Persistent_BSS_Mode := True;
11331 end Persistent_BSS;
11337 -- pragma Polling (ON | OFF);
11339 when Pragma_Polling =>
11341 Check_Arg_Count (1);
11342 Check_No_Identifiers;
11343 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11344 Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11346 -------------------
11347 -- Postcondition --
11348 -------------------
11350 -- pragma Postcondition ([Check =>] Boolean_Expression
11351 -- [,[Message =>] String_Expression]);
11353 when Pragma_Postcondition => Postcondition : declare
11355 pragma Warnings (Off, In_Body);
11359 Check_At_Least_N_Arguments (1);
11360 Check_At_Most_N_Arguments (2);
11361 Check_Optional_Identifier (Arg1, Name_Check);
11363 -- All we need to do here is call the common check procedure,
11364 -- the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11366 Check_Precondition_Postcondition (In_Body);
11373 -- pragma Precondition ([Check =>] Boolean_Expression
11374 -- [,[Message =>] String_Expression]);
11376 when Pragma_Precondition => Precondition : declare
11381 Check_At_Least_N_Arguments (1);
11382 Check_At_Most_N_Arguments (2);
11383 Check_Optional_Identifier (Arg1, Name_Check);
11384 Check_Precondition_Postcondition (In_Body);
11386 -- If in spec, nothing more to do. If in body, then we convert the
11387 -- pragma to pragma Check (Precondition, cond [, msg]). Note we do
11388 -- this whether or not precondition checks are enabled. That works
11389 -- fine since pragma Check will do this check, and will also
11390 -- analyze the condition itself in the proper context.
11395 Chars => Name_Check,
11396 Pragma_Argument_Associations => New_List (
11397 Make_Pragma_Argument_Association (Loc,
11398 Expression => Make_Identifier (Loc, Name_Precondition)),
11400 Make_Pragma_Argument_Association (Sloc (Arg1),
11401 Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11403 if Arg_Count = 2 then
11404 Append_To (Pragma_Argument_Associations (N),
11405 Make_Pragma_Argument_Association (Sloc (Arg2),
11406 Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11417 -- pragma Predicate
11418 -- ([Entity =>] type_LOCAL_NAME,
11419 -- [Check =>] EXPRESSION);
11421 when Pragma_Predicate => Predicate : declare
11426 pragma Unreferenced (Discard);
11430 Check_Arg_Count (2);
11431 Check_Optional_Identifier (Arg1, Name_Entity);
11432 Check_Optional_Identifier (Arg2, Name_Check);
11434 Check_Arg_Is_Local_Name (Arg1);
11436 Type_Id := Get_Pragma_Arg (Arg1);
11437 Find_Type (Type_Id);
11438 Typ := Entity (Type_Id);
11440 if Typ = Any_Type then
11444 -- The remaining processing is simply to link the pragma on to
11445 -- the rep item chain, for processing when the type is frozen.
11446 -- This is accomplished by a call to Rep_Item_Too_Late. We also
11447 -- mark the type as having predicates.
11449 Set_Has_Predicates (Typ);
11450 Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11457 -- pragma Preelaborate [(library_unit_NAME)];
11459 -- Set the flag Is_Preelaborated of program unit name entity
11461 when Pragma_Preelaborate => Preelaborate : declare
11462 Pa : constant Node_Id := Parent (N);
11463 Pk : constant Node_Kind := Nkind (Pa);
11467 Check_Ada_83_Warning;
11468 Check_Valid_Library_Unit_Pragma;
11470 if Nkind (N) = N_Null_Statement then
11474 Ent := Find_Lib_Unit_Name;
11475 Check_Duplicate_Pragma (Ent);
11477 -- This filters out pragmas inside generic parent then
11478 -- show up inside instantiation
11481 and then not (Pk = N_Package_Specification
11482 and then Present (Generic_Parent (Pa)))
11484 if not Debug_Flag_U then
11485 Set_Is_Preelaborated (Ent);
11486 Set_Suppress_Elaboration_Warnings (Ent);
11491 ---------------------
11492 -- Preelaborate_05 --
11493 ---------------------
11495 -- pragma Preelaborate_05 [(library_unit_NAME)];
11497 -- This pragma is useable only in GNAT_Mode, where it is used like
11498 -- pragma Preelaborate but it is only effective in Ada 2005 mode
11499 -- (otherwise it is ignored). This is used to implement AI-362 which
11500 -- recategorizes some run-time packages in Ada 2005 mode.
11502 when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11507 Check_Valid_Library_Unit_Pragma;
11509 if not GNAT_Mode then
11510 Error_Pragma ("pragma% only available in GNAT mode");
11513 if Nkind (N) = N_Null_Statement then
11517 -- This is one of the few cases where we need to test the value of
11518 -- Ada_Version_Explicit rather than Ada_Version (which is always
11519 -- set to Ada_2012 in a predefined unit), we need to know the
11520 -- explicit version set to know if this pragma is active.
11522 if Ada_Version_Explicit >= Ada_2005 then
11523 Ent := Find_Lib_Unit_Name;
11524 Set_Is_Preelaborated (Ent);
11525 Set_Suppress_Elaboration_Warnings (Ent);
11527 end Preelaborate_05;
11533 -- pragma Priority (EXPRESSION);
11535 when Pragma_Priority => Priority : declare
11536 P : constant Node_Id := Parent (N);
11540 Check_No_Identifiers;
11541 Check_Arg_Count (1);
11545 if Nkind (P) = N_Subprogram_Body then
11546 Check_In_Main_Program;
11548 Arg := Get_Pragma_Arg (Arg1);
11549 Analyze_And_Resolve (Arg, Standard_Integer);
11553 if not Is_Static_Expression (Arg) then
11554 Flag_Non_Static_Expr
11555 ("main subprogram priority is not static!", Arg);
11558 -- If constraint error, then we already signalled an error
11560 elsif Raises_Constraint_Error (Arg) then
11563 -- Otherwise check in range
11567 Val : constant Uint := Expr_Value (Arg);
11571 or else Val > Expr_Value (Expression
11572 (Parent (RTE (RE_Max_Priority))))
11575 ("main subprogram priority is out of range", Arg1);
11581 (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11583 -- Load an arbitrary entity from System.Tasking to make sure
11584 -- this package is implicitly with'ed, since we need to have
11585 -- the tasking run-time active for the pragma Priority to have
11589 Discard : Entity_Id;
11590 pragma Warnings (Off, Discard);
11592 Discard := RTE (RE_Task_List);
11595 -- Task or Protected, must be of type Integer
11597 elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11598 Arg := Get_Pragma_Arg (Arg1);
11600 -- The expression must be analyzed in the special manner
11601 -- described in "Handling of Default and Per-Object
11602 -- Expressions" in sem.ads.
11604 Preanalyze_Spec_Expression (Arg, Standard_Integer);
11606 if not Is_Static_Expression (Arg) then
11607 Check_Restriction (Static_Priorities, Arg);
11610 -- Anything else is incorrect
11616 if Has_Pragma_Priority (P) then
11617 Error_Pragma ("duplicate pragma% not allowed");
11619 Set_Has_Pragma_Priority (P, True);
11621 if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11622 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11623 -- exp_ch9 should use this ???
11628 -----------------------------------
11629 -- Priority_Specific_Dispatching --
11630 -----------------------------------
11632 -- pragma Priority_Specific_Dispatching (
11633 -- policy_IDENTIFIER,
11634 -- first_priority_EXPRESSION,
11635 -- last_priority_EXPRESSION);
11637 when Pragma_Priority_Specific_Dispatching =>
11638 Priority_Specific_Dispatching : declare
11639 Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11640 -- This is the entity System.Any_Priority;
11643 Lower_Bound : Node_Id;
11644 Upper_Bound : Node_Id;
11650 Check_Arg_Count (3);
11651 Check_No_Identifiers;
11652 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11653 Check_Valid_Configuration_Pragma;
11654 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11655 DP := Fold_Upper (Name_Buffer (1));
11657 Lower_Bound := Get_Pragma_Arg (Arg2);
11658 Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11659 Lower_Val := Expr_Value (Lower_Bound);
11661 Upper_Bound := Get_Pragma_Arg (Arg3);
11662 Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11663 Upper_Val := Expr_Value (Upper_Bound);
11665 -- It is not allowed to use Task_Dispatching_Policy and
11666 -- Priority_Specific_Dispatching in the same partition.
11668 if Task_Dispatching_Policy /= ' ' then
11669 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11671 ("pragma% incompatible with Task_Dispatching_Policy#");
11673 -- Check lower bound in range
11675 elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11677 Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11680 ("first_priority is out of range", Arg2);
11682 -- Check upper bound in range
11684 elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11686 Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11689 ("last_priority is out of range", Arg3);
11691 -- Check that the priority range is valid
11693 elsif Lower_Val > Upper_Val then
11695 ("last_priority_expression must be greater than" &
11696 " or equal to first_priority_expression");
11698 -- Store the new policy, but always preserve System_Location since
11699 -- we like the error message with the run-time name.
11702 -- Check overlapping in the priority ranges specified in other
11703 -- Priority_Specific_Dispatching pragmas within the same
11704 -- partition. We can only check those we know about!
11707 Specific_Dispatching.First .. Specific_Dispatching.Last
11709 if Specific_Dispatching.Table (J).First_Priority in
11710 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11711 or else Specific_Dispatching.Table (J).Last_Priority in
11712 UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11715 Specific_Dispatching.Table (J).Pragma_Loc;
11717 ("priority range overlaps with "
11718 & "Priority_Specific_Dispatching#");
11722 -- The use of Priority_Specific_Dispatching is incompatible
11723 -- with Task_Dispatching_Policy.
11725 if Task_Dispatching_Policy /= ' ' then
11726 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11728 ("Priority_Specific_Dispatching incompatible "
11729 & "with Task_Dispatching_Policy#");
11732 -- The use of Priority_Specific_Dispatching forces ceiling
11735 if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11736 Error_Msg_Sloc := Locking_Policy_Sloc;
11738 ("Priority_Specific_Dispatching incompatible "
11739 & "with Locking_Policy#");
11741 -- Set the Ceiling_Locking policy, but preserve System_Location
11742 -- since we like the error message with the run time name.
11745 Locking_Policy := 'C';
11747 if Locking_Policy_Sloc /= System_Location then
11748 Locking_Policy_Sloc := Loc;
11752 -- Add entry in the table
11754 Specific_Dispatching.Append
11755 ((Dispatching_Policy => DP,
11756 First_Priority => UI_To_Int (Lower_Val),
11757 Last_Priority => UI_To_Int (Upper_Val),
11758 Pragma_Loc => Loc));
11760 end Priority_Specific_Dispatching;
11766 -- pragma Profile (profile_IDENTIFIER);
11768 -- profile_IDENTIFIER => Restricted | Ravenscar
11770 when Pragma_Profile =>
11772 Check_Arg_Count (1);
11773 Check_Valid_Configuration_Pragma;
11774 Check_No_Identifiers;
11777 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11779 if Chars (Argx) = Name_Ravenscar then
11780 Set_Ravenscar_Profile (N);
11781 elsif Chars (Argx) = Name_Restricted then
11782 Set_Profile_Restrictions
11783 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11785 Error_Pragma_Arg ("& is not a valid profile", Argx);
11789 ----------------------
11790 -- Profile_Warnings --
11791 ----------------------
11793 -- pragma Profile_Warnings (profile_IDENTIFIER);
11795 -- profile_IDENTIFIER => Restricted | Ravenscar
11797 when Pragma_Profile_Warnings =>
11799 Check_Arg_Count (1);
11800 Check_Valid_Configuration_Pragma;
11801 Check_No_Identifiers;
11804 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11806 if Chars (Argx) = Name_Ravenscar then
11807 Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11808 elsif Chars (Argx) = Name_Restricted then
11809 Set_Profile_Restrictions (Restricted, N, Warn => True);
11811 Error_Pragma_Arg ("& is not a valid profile", Argx);
11815 --------------------------
11816 -- Propagate_Exceptions --
11817 --------------------------
11819 -- pragma Propagate_Exceptions;
11821 -- Note: this pragma is obsolete and has no effect
11823 when Pragma_Propagate_Exceptions =>
11825 Check_Arg_Count (0);
11827 if In_Extended_Main_Source_Unit (N) then
11828 Propagate_Exceptions := True;
11835 -- pragma Psect_Object (
11836 -- [Internal =>] LOCAL_NAME,
11837 -- [, [External =>] EXTERNAL_SYMBOL]
11838 -- [, [Size =>] EXTERNAL_SYMBOL]);
11840 when Pragma_Psect_Object | Pragma_Common_Object =>
11841 Psect_Object : declare
11842 Args : Args_List (1 .. 3);
11843 Names : constant Name_List (1 .. 3) := (
11848 Internal : Node_Id renames Args (1);
11849 External : Node_Id renames Args (2);
11850 Size : Node_Id renames Args (3);
11852 Def_Id : Entity_Id;
11854 procedure Check_Too_Long (Arg : Node_Id);
11855 -- Posts message if the argument is an identifier with more
11856 -- than 31 characters, or a string literal with more than
11857 -- 31 characters, and we are operating under VMS
11859 --------------------
11860 -- Check_Too_Long --
11861 --------------------
11863 procedure Check_Too_Long (Arg : Node_Id) is
11864 X : constant Node_Id := Original_Node (Arg);
11867 if not Nkind_In (X, N_String_Literal, N_Identifier) then
11869 ("inappropriate argument for pragma %", Arg);
11872 if OpenVMS_On_Target then
11873 if (Nkind (X) = N_String_Literal
11874 and then String_Length (Strval (X)) > 31)
11876 (Nkind (X) = N_Identifier
11877 and then Length_Of_Name (Chars (X)) > 31)
11880 ("argument for pragma % is longer than 31 characters",
11884 end Check_Too_Long;
11886 -- Start of processing for Common_Object/Psect_Object
11890 Gather_Associations (Names, Args);
11891 Process_Extended_Import_Export_Internal_Arg (Internal);
11893 Def_Id := Entity (Internal);
11895 if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11897 ("pragma% must designate an object", Internal);
11900 Check_Too_Long (Internal);
11902 if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11904 ("cannot use pragma% for imported/exported object",
11908 if Is_Concurrent_Type (Etype (Internal)) then
11910 ("cannot specify pragma % for task/protected object",
11914 if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11916 Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11918 Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11921 if Ekind (Def_Id) = E_Constant then
11923 ("cannot specify pragma % for a constant", Internal);
11926 if Is_Record_Type (Etype (Internal)) then
11932 Ent := First_Entity (Etype (Internal));
11933 while Present (Ent) loop
11934 Decl := Declaration_Node (Ent);
11936 if Ekind (Ent) = E_Component
11937 and then Nkind (Decl) = N_Component_Declaration
11938 and then Present (Expression (Decl))
11939 and then Warn_On_Export_Import
11942 ("?object for pragma % has defaults", Internal);
11952 if Present (Size) then
11953 Check_Too_Long (Size);
11956 if Present (External) then
11957 Check_Arg_Is_External_Name (External);
11958 Check_Too_Long (External);
11961 -- If all error tests pass, link pragma on to the rep item chain
11963 Record_Rep_Item (Def_Id, N);
11970 -- pragma Pure [(library_unit_NAME)];
11972 when Pragma_Pure => Pure : declare
11976 Check_Ada_83_Warning;
11977 Check_Valid_Library_Unit_Pragma;
11979 if Nkind (N) = N_Null_Statement then
11983 Ent := Find_Lib_Unit_Name;
11985 Set_Has_Pragma_Pure (Ent);
11986 Set_Suppress_Elaboration_Warnings (Ent);
11993 -- pragma Pure_05 [(library_unit_NAME)];
11995 -- This pragma is useable only in GNAT_Mode, where it is used like
11996 -- pragma Pure but it is only effective in Ada 2005 mode (otherwise
11997 -- it is ignored). It may be used after a pragma Preelaborate, in
11998 -- which case it overrides the effect of the pragma Preelaborate.
11999 -- This is used to implement AI-362 which recategorizes some run-time
12000 -- packages in Ada 2005 mode.
12002 when Pragma_Pure_05 => Pure_05 : declare
12007 Check_Valid_Library_Unit_Pragma;
12009 if not GNAT_Mode then
12010 Error_Pragma ("pragma% only available in GNAT mode");
12013 if Nkind (N) = N_Null_Statement then
12017 -- This is one of the few cases where we need to test the value of
12018 -- Ada_Version_Explicit rather than Ada_Version (which is always
12019 -- set to Ada_2012 in a predefined unit), we need to know the
12020 -- explicit version set to know if this pragma is active.
12022 if Ada_Version_Explicit >= Ada_2005 then
12023 Ent := Find_Lib_Unit_Name;
12024 Set_Is_Preelaborated (Ent, False);
12026 Set_Suppress_Elaboration_Warnings (Ent);
12030 -------------------
12031 -- Pure_Function --
12032 -------------------
12034 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12036 when Pragma_Pure_Function => Pure_Function : declare
12039 Def_Id : Entity_Id;
12040 Effective : Boolean := False;
12044 Check_Arg_Count (1);
12045 Check_Optional_Identifier (Arg1, Name_Entity);
12046 Check_Arg_Is_Local_Name (Arg1);
12047 E_Id := Get_Pragma_Arg (Arg1);
12049 if Error_Posted (E_Id) then
12053 -- Loop through homonyms (overloadings) of referenced entity
12055 E := Entity (E_Id);
12057 if Present (E) then
12059 Def_Id := Get_Base_Subprogram (E);
12061 if not Ekind_In (Def_Id, E_Function,
12062 E_Generic_Function,
12066 ("pragma% requires a function name", Arg1);
12069 Set_Is_Pure (Def_Id);
12071 if not Has_Pragma_Pure_Function (Def_Id) then
12072 Set_Has_Pragma_Pure_Function (Def_Id);
12076 exit when From_Aspect_Specification (N);
12078 exit when No (E) or else Scope (E) /= Current_Scope;
12082 and then Warn_On_Redundant_Constructs
12085 ("pragma Pure_Function on& is redundant?",
12091 --------------------
12092 -- Queuing_Policy --
12093 --------------------
12095 -- pragma Queuing_Policy (policy_IDENTIFIER);
12097 when Pragma_Queuing_Policy => declare
12101 Check_Ada_83_Warning;
12102 Check_Arg_Count (1);
12103 Check_No_Identifiers;
12104 Check_Arg_Is_Queuing_Policy (Arg1);
12105 Check_Valid_Configuration_Pragma;
12106 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12107 QP := Fold_Upper (Name_Buffer (1));
12109 if Queuing_Policy /= ' '
12110 and then Queuing_Policy /= QP
12112 Error_Msg_Sloc := Queuing_Policy_Sloc;
12113 Error_Pragma ("queuing policy incompatible with policy#");
12115 -- Set new policy, but always preserve System_Location since we
12116 -- like the error message with the run time name.
12119 Queuing_Policy := QP;
12121 if Queuing_Policy_Sloc /= System_Location then
12122 Queuing_Policy_Sloc := Loc;
12127 -----------------------
12128 -- Relative_Deadline --
12129 -----------------------
12131 -- pragma Relative_Deadline (time_span_EXPRESSION);
12133 when Pragma_Relative_Deadline => Relative_Deadline : declare
12134 P : constant Node_Id := Parent (N);
12139 Check_No_Identifiers;
12140 Check_Arg_Count (1);
12142 Arg := Get_Pragma_Arg (Arg1);
12144 -- The expression must be analyzed in the special manner described
12145 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
12147 Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12151 if Nkind (P) = N_Subprogram_Body then
12152 Check_In_Main_Program;
12156 elsif Nkind (P) = N_Task_Definition then
12159 -- Anything else is incorrect
12165 if Has_Relative_Deadline_Pragma (P) then
12166 Error_Pragma ("duplicate pragma% not allowed");
12168 Set_Has_Relative_Deadline_Pragma (P, True);
12170 if Nkind (P) = N_Task_Definition then
12171 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12174 end Relative_Deadline;
12176 ---------------------------
12177 -- Remote_Call_Interface --
12178 ---------------------------
12180 -- pragma Remote_Call_Interface [(library_unit_NAME)];
12182 when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12183 Cunit_Node : Node_Id;
12184 Cunit_Ent : Entity_Id;
12188 Check_Ada_83_Warning;
12189 Check_Valid_Library_Unit_Pragma;
12191 if Nkind (N) = N_Null_Statement then
12195 Cunit_Node := Cunit (Current_Sem_Unit);
12196 K := Nkind (Unit (Cunit_Node));
12197 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12199 if K = N_Package_Declaration
12200 or else K = N_Generic_Package_Declaration
12201 or else K = N_Subprogram_Declaration
12202 or else K = N_Generic_Subprogram_Declaration
12203 or else (K = N_Subprogram_Body
12204 and then Acts_As_Spec (Unit (Cunit_Node)))
12209 "pragma% must apply to package or subprogram declaration");
12212 Set_Is_Remote_Call_Interface (Cunit_Ent);
12213 end Remote_Call_Interface;
12219 -- pragma Remote_Types [(library_unit_NAME)];
12221 when Pragma_Remote_Types => Remote_Types : declare
12222 Cunit_Node : Node_Id;
12223 Cunit_Ent : Entity_Id;
12226 Check_Ada_83_Warning;
12227 Check_Valid_Library_Unit_Pragma;
12229 if Nkind (N) = N_Null_Statement then
12233 Cunit_Node := Cunit (Current_Sem_Unit);
12234 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12236 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12237 N_Generic_Package_Declaration)
12240 ("pragma% can only apply to a package declaration");
12243 Set_Is_Remote_Types (Cunit_Ent);
12250 -- pragma Ravenscar;
12252 when Pragma_Ravenscar =>
12254 Check_Arg_Count (0);
12255 Check_Valid_Configuration_Pragma;
12256 Set_Ravenscar_Profile (N);
12258 if Warn_On_Obsolescent_Feature then
12259 Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12260 Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12263 -------------------------
12264 -- Restricted_Run_Time --
12265 -------------------------
12267 -- pragma Restricted_Run_Time;
12269 when Pragma_Restricted_Run_Time =>
12271 Check_Arg_Count (0);
12272 Check_Valid_Configuration_Pragma;
12273 Set_Profile_Restrictions
12274 (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12276 if Warn_On_Obsolescent_Feature then
12278 ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12279 Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12286 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
12289 -- restriction_IDENTIFIER
12290 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12292 when Pragma_Restrictions =>
12293 Process_Restrictions_Or_Restriction_Warnings
12294 (Warn => Treat_Restrictions_As_Warnings);
12296 --------------------------
12297 -- Restriction_Warnings --
12298 --------------------------
12300 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12303 -- restriction_IDENTIFIER
12304 -- | restriction_parameter_IDENTIFIER => EXPRESSION
12306 when Pragma_Restriction_Warnings =>
12308 Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12314 -- pragma Reviewable;
12316 when Pragma_Reviewable =>
12317 Check_Ada_83_Warning;
12318 Check_Arg_Count (0);
12320 -- Call dummy debugging function rv. This is done to assist front
12321 -- end debugging. By placing a Reviewable pragma in the source
12322 -- program, a breakpoint on rv catches this place in the source,
12323 -- allowing convenient stepping to the point of interest.
12327 --------------------------
12328 -- Short_Circuit_And_Or --
12329 --------------------------
12331 when Pragma_Short_Circuit_And_Or =>
12333 Check_Arg_Count (0);
12334 Check_Valid_Configuration_Pragma;
12335 Short_Circuit_And_Or := True;
12337 -------------------
12338 -- Share_Generic --
12339 -------------------
12341 -- pragma Share_Generic (NAME {, NAME});
12343 when Pragma_Share_Generic =>
12345 Process_Generic_List;
12351 -- pragma Shared (LOCAL_NAME);
12353 when Pragma_Shared =>
12355 Process_Atomic_Shared_Volatile;
12357 --------------------
12358 -- Shared_Passive --
12359 --------------------
12361 -- pragma Shared_Passive [(library_unit_NAME)];
12363 -- Set the flag Is_Shared_Passive of program unit name entity
12365 when Pragma_Shared_Passive => Shared_Passive : declare
12366 Cunit_Node : Node_Id;
12367 Cunit_Ent : Entity_Id;
12370 Check_Ada_83_Warning;
12371 Check_Valid_Library_Unit_Pragma;
12373 if Nkind (N) = N_Null_Statement then
12377 Cunit_Node := Cunit (Current_Sem_Unit);
12378 Cunit_Ent := Cunit_Entity (Current_Sem_Unit);
12380 if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12381 N_Generic_Package_Declaration)
12384 ("pragma% can only apply to a package declaration");
12387 Set_Is_Shared_Passive (Cunit_Ent);
12388 end Shared_Passive;
12390 -----------------------
12391 -- Short_Descriptors --
12392 -----------------------
12394 -- pragma Short_Descriptors;
12396 when Pragma_Short_Descriptors =>
12398 Check_Arg_Count (0);
12399 Check_Valid_Configuration_Pragma;
12400 Short_Descriptors := True;
12402 ----------------------
12403 -- Source_File_Name --
12404 ----------------------
12406 -- There are five forms for this pragma:
12408 -- pragma Source_File_Name (
12409 -- [UNIT_NAME =>] unit_NAME,
12410 -- BODY_FILE_NAME => STRING_LITERAL
12411 -- [, [INDEX =>] INTEGER_LITERAL]);
12413 -- pragma Source_File_Name (
12414 -- [UNIT_NAME =>] unit_NAME,
12415 -- SPEC_FILE_NAME => STRING_LITERAL
12416 -- [, [INDEX =>] INTEGER_LITERAL]);
12418 -- pragma Source_File_Name (
12419 -- BODY_FILE_NAME => STRING_LITERAL
12420 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12421 -- [, CASING => CASING_SPEC]);
12423 -- pragma Source_File_Name (
12424 -- SPEC_FILE_NAME => STRING_LITERAL
12425 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12426 -- [, CASING => CASING_SPEC]);
12428 -- pragma Source_File_Name (
12429 -- SUBUNIT_FILE_NAME => STRING_LITERAL
12430 -- [, DOT_REPLACEMENT => STRING_LITERAL]
12431 -- [, CASING => CASING_SPEC]);
12433 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12435 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12436 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
12437 -- only be used when no project file is used, while SFNP can only be
12438 -- used when a project file is used.
12440 -- No processing here. Processing was completed during parsing, since
12441 -- we need to have file names set as early as possible. Units are
12442 -- loaded well before semantic processing starts.
12444 -- The only processing we defer to this point is the check for
12445 -- correct placement.
12447 when Pragma_Source_File_Name =>
12449 Check_Valid_Configuration_Pragma;
12451 ------------------------------
12452 -- Source_File_Name_Project --
12453 ------------------------------
12455 -- See Source_File_Name for syntax
12457 -- No processing here. Processing was completed during parsing, since
12458 -- we need to have file names set as early as possible. Units are
12459 -- loaded well before semantic processing starts.
12461 -- The only processing we defer to this point is the check for
12462 -- correct placement.
12464 when Pragma_Source_File_Name_Project =>
12466 Check_Valid_Configuration_Pragma;
12468 -- Check that a pragma Source_File_Name_Project is used only in a
12469 -- configuration pragmas file.
12471 -- Pragmas Source_File_Name_Project should only be generated by
12472 -- the Project Manager in configuration pragmas files.
12474 -- This is really an ugly test. It seems to depend on some
12475 -- accidental and undocumented property. At the very least it
12476 -- needs to be documented, but it would be better to have a
12477 -- clean way of testing if we are in a configuration file???
12479 if Present (Parent (N)) then
12481 ("pragma% can only appear in a configuration pragmas file");
12484 ----------------------
12485 -- Source_Reference --
12486 ----------------------
12488 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12490 -- Nothing to do, all processing completed in Par.Prag, since we need
12491 -- the information for possible parser messages that are output.
12493 when Pragma_Source_Reference =>
12496 --------------------------------
12497 -- Static_Elaboration_Desired --
12498 --------------------------------
12500 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
12502 when Pragma_Static_Elaboration_Desired =>
12504 Check_At_Most_N_Arguments (1);
12506 if Is_Compilation_Unit (Current_Scope)
12507 and then Ekind (Current_Scope) = E_Package
12509 Set_Static_Elaboration_Desired (Current_Scope, True);
12511 Error_Pragma ("pragma% must apply to a library-level package");
12518 -- pragma Storage_Size (EXPRESSION);
12520 when Pragma_Storage_Size => Storage_Size : declare
12521 P : constant Node_Id := Parent (N);
12525 Check_No_Identifiers;
12526 Check_Arg_Count (1);
12528 -- The expression must be analyzed in the special manner described
12529 -- in "Handling of Default Expressions" in sem.ads.
12531 Arg := Get_Pragma_Arg (Arg1);
12532 Preanalyze_Spec_Expression (Arg, Any_Integer);
12534 if not Is_Static_Expression (Arg) then
12535 Check_Restriction (Static_Storage_Size, Arg);
12538 if Nkind (P) /= N_Task_Definition then
12543 if Has_Storage_Size_Pragma (P) then
12544 Error_Pragma ("duplicate pragma% not allowed");
12546 Set_Has_Storage_Size_Pragma (P, True);
12549 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12550 -- ??? exp_ch9 should use this!
12558 -- pragma Storage_Unit (NUMERIC_LITERAL);
12560 -- Only permitted argument is System'Storage_Unit value
12562 when Pragma_Storage_Unit =>
12563 Check_No_Identifiers;
12564 Check_Arg_Count (1);
12565 Check_Arg_Is_Integer_Literal (Arg1);
12567 if Intval (Get_Pragma_Arg (Arg1)) /=
12568 UI_From_Int (Ttypes.System_Storage_Unit)
12570 Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12572 ("the only allowed argument for pragma% is ^", Arg1);
12575 --------------------
12576 -- Stream_Convert --
12577 --------------------
12579 -- pragma Stream_Convert (
12580 -- [Entity =>] type_LOCAL_NAME,
12581 -- [Read =>] function_NAME,
12582 -- [Write =>] function NAME);
12584 when Pragma_Stream_Convert => Stream_Convert : declare
12586 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12587 -- Check that the given argument is the name of a local function
12588 -- of one argument that is not overloaded earlier in the current
12589 -- local scope. A check is also made that the argument is a
12590 -- function with one parameter.
12592 --------------------------------------
12593 -- Check_OK_Stream_Convert_Function --
12594 --------------------------------------
12596 procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12600 Check_Arg_Is_Local_Name (Arg);
12601 Ent := Entity (Get_Pragma_Arg (Arg));
12603 if Has_Homonym (Ent) then
12605 ("argument for pragma% may not be overloaded", Arg);
12608 if Ekind (Ent) /= E_Function
12609 or else No (First_Formal (Ent))
12610 or else Present (Next_Formal (First_Formal (Ent)))
12613 ("argument for pragma% must be" &
12614 " function of one argument", Arg);
12616 end Check_OK_Stream_Convert_Function;
12618 -- Start of processing for Stream_Convert
12622 Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12623 Check_Arg_Count (3);
12624 Check_Optional_Identifier (Arg1, Name_Entity);
12625 Check_Optional_Identifier (Arg2, Name_Read);
12626 Check_Optional_Identifier (Arg3, Name_Write);
12627 Check_Arg_Is_Local_Name (Arg1);
12628 Check_OK_Stream_Convert_Function (Arg2);
12629 Check_OK_Stream_Convert_Function (Arg3);
12632 Typ : constant Entity_Id :=
12633 Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12634 Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12635 Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12638 Check_First_Subtype (Arg1);
12640 -- Check for too early or too late. Note that we don't enforce
12641 -- the rule about primitive operations in this case, since, as
12642 -- is the case for explicit stream attributes themselves, these
12643 -- restrictions are not appropriate. Note that the chaining of
12644 -- the pragma by Rep_Item_Too_Late is actually the critical
12645 -- processing done for this pragma.
12647 if Rep_Item_Too_Early (Typ, N)
12649 Rep_Item_Too_Late (Typ, N, FOnly => True)
12654 -- Return if previous error
12656 if Etype (Typ) = Any_Type
12658 Etype (Read) = Any_Type
12660 Etype (Write) = Any_Type
12667 if Underlying_Type (Etype (Read)) /= Typ then
12669 ("incorrect return type for function&", Arg2);
12672 if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12674 ("incorrect parameter type for function&", Arg3);
12677 if Underlying_Type (Etype (First_Formal (Read))) /=
12678 Underlying_Type (Etype (Write))
12681 ("result type of & does not match Read parameter type",
12685 end Stream_Convert;
12687 -------------------------
12688 -- Style_Checks (GNAT) --
12689 -------------------------
12691 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12693 -- This is processed by the parser since some of the style checks
12694 -- take place during source scanning and parsing. This means that
12695 -- we don't need to issue error messages here.
12697 when Pragma_Style_Checks => Style_Checks : declare
12698 A : constant Node_Id := Get_Pragma_Arg (Arg1);
12704 Check_No_Identifiers;
12706 -- Two argument form
12708 if Arg_Count = 2 then
12709 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12716 E_Id := Get_Pragma_Arg (Arg2);
12719 if not Is_Entity_Name (E_Id) then
12721 ("second argument of pragma% must be entity name",
12725 E := Entity (E_Id);
12731 Set_Suppress_Style_Checks (E,
12732 (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12733 exit when No (Homonym (E));
12739 -- One argument form
12742 Check_Arg_Count (1);
12744 if Nkind (A) = N_String_Literal then
12748 Slen : constant Natural := Natural (String_Length (S));
12749 Options : String (1 .. Slen);
12755 C := Get_String_Char (S, Int (J));
12756 exit when not In_Character_Range (C);
12757 Options (J) := Get_Character (C);
12759 -- If at end of string, set options. As per discussion
12760 -- above, no need to check for errors, since we issued
12761 -- them in the parser.
12764 Set_Style_Check_Options (Options);
12772 elsif Nkind (A) = N_Identifier then
12773 if Chars (A) = Name_All_Checks then
12775 Set_GNAT_Style_Check_Options;
12777 Set_Default_Style_Check_Options;
12780 elsif Chars (A) = Name_On then
12781 Style_Check := True;
12783 elsif Chars (A) = Name_Off then
12784 Style_Check := False;
12794 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12796 when Pragma_Subtitle =>
12798 Check_Arg_Count (1);
12799 Check_Optional_Identifier (Arg1, Name_Subtitle);
12800 Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12807 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12809 when Pragma_Suppress =>
12810 Process_Suppress_Unsuppress (True);
12816 -- pragma Suppress_All;
12818 -- The only check made here is that the pragma has no arguments.
12819 -- There are no placement rules, and the processing required (setting
12820 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
12821 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
12822 -- then creates and inserts a pragma Suppress (All_Checks).
12824 when Pragma_Suppress_All =>
12826 Check_Arg_Count (0);
12828 -------------------------
12829 -- Suppress_Debug_Info --
12830 -------------------------
12832 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12834 when Pragma_Suppress_Debug_Info =>
12836 Check_Arg_Count (1);
12837 Check_Optional_Identifier (Arg1, Name_Entity);
12838 Check_Arg_Is_Local_Name (Arg1);
12839 Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12841 ----------------------------------
12842 -- Suppress_Exception_Locations --
12843 ----------------------------------
12845 -- pragma Suppress_Exception_Locations;
12847 when Pragma_Suppress_Exception_Locations =>
12849 Check_Arg_Count (0);
12850 Check_Valid_Configuration_Pragma;
12851 Exception_Locations_Suppressed := True;
12853 -----------------------------
12854 -- Suppress_Initialization --
12855 -----------------------------
12857 -- pragma Suppress_Initialization ([Entity =>] type_Name);
12859 when Pragma_Suppress_Initialization => Suppress_Init : declare
12865 Check_Arg_Count (1);
12866 Check_Optional_Identifier (Arg1, Name_Entity);
12867 Check_Arg_Is_Local_Name (Arg1);
12869 E_Id := Get_Pragma_Arg (Arg1);
12871 if Etype (E_Id) = Any_Type then
12875 E := Entity (E_Id);
12877 if not Is_Type (E) then
12878 Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
12881 if Rep_Item_Too_Early (E, N)
12883 Rep_Item_Too_Late (E, N, FOnly => True)
12888 -- For incomplete/private type, set flag on full view
12890 if Is_Incomplete_Or_Private_Type (E) then
12891 if No (Full_View (Base_Type (E))) then
12893 ("argument of pragma% cannot be an incomplete type", Arg1);
12895 Set_Suppress_Initialization (Full_View (Base_Type (E)));
12898 -- For first subtype, set flag on base type
12900 elsif Is_First_Subtype (E) then
12901 Set_Suppress_Initialization (Base_Type (E));
12903 -- For other than first subtype, set flag on subtype itself
12906 Set_Suppress_Initialization (E);
12914 -- pragma System_Name (DIRECT_NAME);
12916 -- Syntax check: one argument, which must be the identifier GNAT or
12917 -- the identifier GCC, no other identifiers are acceptable.
12919 when Pragma_System_Name =>
12921 Check_No_Identifiers;
12922 Check_Arg_Count (1);
12923 Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12925 -----------------------------
12926 -- Task_Dispatching_Policy --
12927 -----------------------------
12929 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12931 when Pragma_Task_Dispatching_Policy => declare
12935 Check_Ada_83_Warning;
12936 Check_Arg_Count (1);
12937 Check_No_Identifiers;
12938 Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12939 Check_Valid_Configuration_Pragma;
12940 Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12941 DP := Fold_Upper (Name_Buffer (1));
12943 if Task_Dispatching_Policy /= ' '
12944 and then Task_Dispatching_Policy /= DP
12946 Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12948 ("task dispatching policy incompatible with policy#");
12950 -- Set new policy, but always preserve System_Location since we
12951 -- like the error message with the run time name.
12954 Task_Dispatching_Policy := DP;
12956 if Task_Dispatching_Policy_Sloc /= System_Location then
12957 Task_Dispatching_Policy_Sloc := Loc;
12966 -- pragma Task_Info (EXPRESSION);
12968 when Pragma_Task_Info => Task_Info : declare
12969 P : constant Node_Id := Parent (N);
12974 if Nkind (P) /= N_Task_Definition then
12975 Error_Pragma ("pragma% must appear in task definition");
12978 Check_No_Identifiers;
12979 Check_Arg_Count (1);
12981 Analyze_And_Resolve
12982 (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12984 if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12988 if Has_Task_Info_Pragma (P) then
12989 Error_Pragma ("duplicate pragma% not allowed");
12991 Set_Has_Task_Info_Pragma (P, True);
12999 -- pragma Task_Name (string_EXPRESSION);
13001 when Pragma_Task_Name => Task_Name : declare
13002 P : constant Node_Id := Parent (N);
13006 Check_No_Identifiers;
13007 Check_Arg_Count (1);
13009 Arg := Get_Pragma_Arg (Arg1);
13011 -- The expression is used in the call to Create_Task, and must be
13012 -- expanded there, not in the context of the current spec. It must
13013 -- however be analyzed to capture global references, in case it
13014 -- appears in a generic context.
13016 Preanalyze_And_Resolve (Arg, Standard_String);
13018 if Nkind (P) /= N_Task_Definition then
13022 if Has_Task_Name_Pragma (P) then
13023 Error_Pragma ("duplicate pragma% not allowed");
13025 Set_Has_Task_Name_Pragma (P, True);
13026 Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13034 -- pragma Task_Storage (
13035 -- [Task_Type =>] LOCAL_NAME,
13036 -- [Top_Guard =>] static_integer_EXPRESSION);
13038 when Pragma_Task_Storage => Task_Storage : declare
13039 Args : Args_List (1 .. 2);
13040 Names : constant Name_List (1 .. 2) := (
13044 Task_Type : Node_Id renames Args (1);
13045 Top_Guard : Node_Id renames Args (2);
13051 Gather_Associations (Names, Args);
13053 if No (Task_Type) then
13055 ("missing task_type argument for pragma%");
13058 Check_Arg_Is_Local_Name (Task_Type);
13060 Ent := Entity (Task_Type);
13062 if not Is_Task_Type (Ent) then
13064 ("argument for pragma% must be task type", Task_Type);
13067 if No (Top_Guard) then
13069 ("pragma% takes two arguments", Task_Type);
13071 Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13074 Check_First_Subtype (Task_Type);
13076 if Rep_Item_Too_Late (Ent, N) then
13081 --------------------------
13082 -- Thread_Local_Storage --
13083 --------------------------
13085 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13087 when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13093 Check_Arg_Count (1);
13094 Check_Optional_Identifier (Arg1, Name_Entity);
13095 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13097 Id := Get_Pragma_Arg (Arg1);
13100 if not Is_Entity_Name (Id)
13101 or else Ekind (Entity (Id)) /= E_Variable
13103 Error_Pragma_Arg ("local variable name required", Arg1);
13108 if Rep_Item_Too_Early (E, N)
13109 or else Rep_Item_Too_Late (E, N)
13114 Set_Has_Pragma_Thread_Local_Storage (E);
13115 Set_Has_Gigi_Rep_Item (E);
13116 end Thread_Local_Storage;
13122 -- pragma Time_Slice (static_duration_EXPRESSION);
13124 when Pragma_Time_Slice => Time_Slice : declare
13130 Check_Arg_Count (1);
13131 Check_No_Identifiers;
13132 Check_In_Main_Program;
13133 Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13135 if not Error_Posted (Arg1) then
13137 while Present (Nod) loop
13138 if Nkind (Nod) = N_Pragma
13139 and then Pragma_Name (Nod) = Name_Time_Slice
13141 Error_Msg_Name_1 := Pname;
13142 Error_Msg_N ("duplicate pragma% not permitted", Nod);
13149 -- Process only if in main unit
13151 if Get_Source_Unit (Loc) = Main_Unit then
13152 Opt.Time_Slice_Set := True;
13153 Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13155 if Val <= Ureal_0 then
13156 Opt.Time_Slice_Value := 0;
13158 elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13159 Opt.Time_Slice_Value := 1_000_000_000;
13162 Opt.Time_Slice_Value :=
13163 UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13172 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
13174 -- TITLING_OPTION ::=
13175 -- [Title =>] STRING_LITERAL
13176 -- | [Subtitle =>] STRING_LITERAL
13178 when Pragma_Title => Title : declare
13179 Args : Args_List (1 .. 2);
13180 Names : constant Name_List (1 .. 2) := (
13186 Gather_Associations (Names, Args);
13189 for J in 1 .. 2 loop
13190 if Present (Args (J)) then
13191 Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13196 ---------------------
13197 -- Unchecked_Union --
13198 ---------------------
13200 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13202 when Pragma_Unchecked_Union => Unchecked_Union : declare
13203 Assoc : constant Node_Id := Arg1;
13204 Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13215 Check_No_Identifiers;
13216 Check_Arg_Count (1);
13217 Check_Arg_Is_Local_Name (Arg1);
13219 Find_Type (Type_Id);
13220 Typ := Entity (Type_Id);
13223 or else Rep_Item_Too_Early (Typ, N)
13227 Typ := Underlying_Type (Typ);
13230 if Rep_Item_Too_Late (Typ, N) then
13234 Check_First_Subtype (Arg1);
13236 -- Note remaining cases are references to a type in the current
13237 -- declarative part. If we find an error, we post the error on
13238 -- the relevant type declaration at an appropriate point.
13240 if not Is_Record_Type (Typ) then
13241 Error_Msg_N ("Unchecked_Union must be record type", Typ);
13244 elsif Is_Tagged_Type (Typ) then
13245 Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13248 elsif Is_Limited_Type (Typ) then
13250 ("Unchecked_Union must not be limited record type", Typ);
13251 Explain_Limited_Type (Typ, Typ);
13255 if not Has_Discriminants (Typ) then
13257 ("Unchecked_Union must have one discriminant", Typ);
13261 Discr := First_Discriminant (Typ);
13262 while Present (Discr) loop
13263 if No (Discriminant_Default_Value (Discr)) then
13265 ("Unchecked_Union discriminant must have default value",
13269 Next_Discriminant (Discr);
13272 Tdef := Type_Definition (Declaration_Node (Typ));
13273 Clist := Component_List (Tdef);
13275 Comp := First (Component_Items (Clist));
13276 while Present (Comp) loop
13277 Check_Component (Comp, Typ);
13281 if No (Clist) or else No (Variant_Part (Clist)) then
13283 ("Unchecked_Union must have variant part",
13288 Vpart := Variant_Part (Clist);
13290 Variant := First (Variants (Vpart));
13291 while Present (Variant) loop
13292 Check_Variant (Variant, Typ);
13297 Set_Is_Unchecked_Union (Typ);
13298 Set_Convention (Typ, Convention_C);
13299 Set_Has_Unchecked_Union (Base_Type (Typ));
13300 Set_Is_Unchecked_Union (Base_Type (Typ));
13301 end Unchecked_Union;
13303 ------------------------
13304 -- Unimplemented_Unit --
13305 ------------------------
13307 -- pragma Unimplemented_Unit;
13309 -- Note: this only gives an error if we are generating code, or if
13310 -- we are in a generic library unit (where the pragma appears in the
13311 -- body, not in the spec).
13313 when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13314 Cunitent : constant Entity_Id :=
13315 Cunit_Entity (Get_Source_Unit (Loc));
13316 Ent_Kind : constant Entity_Kind :=
13321 Check_Arg_Count (0);
13323 if Operating_Mode = Generate_Code
13324 or else Ent_Kind = E_Generic_Function
13325 or else Ent_Kind = E_Generic_Procedure
13326 or else Ent_Kind = E_Generic_Package
13328 Get_Name_String (Chars (Cunitent));
13329 Set_Casing (Mixed_Case);
13330 Write_Str (Name_Buffer (1 .. Name_Len));
13331 Write_Str (" is not supported in this configuration");
13333 raise Unrecoverable_Error;
13335 end Unimplemented_Unit;
13337 ------------------------
13338 -- Universal_Aliasing --
13339 ------------------------
13341 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13343 when Pragma_Universal_Aliasing => Universal_Alias : declare
13348 Check_Arg_Count (1);
13349 Check_Optional_Identifier (Arg2, Name_Entity);
13350 Check_Arg_Is_Local_Name (Arg1);
13351 E_Id := Entity (Get_Pragma_Arg (Arg1));
13353 if E_Id = Any_Type then
13355 elsif No (E_Id) or else not Is_Type (E_Id) then
13356 Error_Pragma_Arg ("pragma% requires type", Arg1);
13359 Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13360 end Universal_Alias;
13362 --------------------
13363 -- Universal_Data --
13364 --------------------
13366 -- pragma Universal_Data [(library_unit_NAME)];
13368 when Pragma_Universal_Data =>
13371 -- If this is a configuration pragma, then set the universal
13372 -- addressing option, otherwise confirm that the pragma satisfies
13373 -- the requirements of library unit pragma placement and leave it
13374 -- to the GNAAMP back end to detect the pragma (avoids transitive
13375 -- setting of the option due to withed units).
13377 if Is_Configuration_Pragma then
13378 Universal_Addressing_On_AAMP := True;
13380 Check_Valid_Library_Unit_Pragma;
13383 if not AAMP_On_Target then
13384 Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13391 -- pragma Unmodified (local_Name {, local_Name});
13393 when Pragma_Unmodified => Unmodified : declare
13394 Arg_Node : Node_Id;
13395 Arg_Expr : Node_Id;
13396 Arg_Ent : Entity_Id;
13400 Check_At_Least_N_Arguments (1);
13402 -- Loop through arguments
13405 while Present (Arg_Node) loop
13406 Check_No_Identifier (Arg_Node);
13408 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
13409 -- in fact generate reference, so that the entity will have a
13410 -- reference, which will inhibit any warnings about it not
13411 -- being referenced, and also properly show up in the ali file
13412 -- as a reference. But this reference is recorded before the
13413 -- Has_Pragma_Unreferenced flag is set, so that no warning is
13414 -- generated for this reference.
13416 Check_Arg_Is_Local_Name (Arg_Node);
13417 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13419 if Is_Entity_Name (Arg_Expr) then
13420 Arg_Ent := Entity (Arg_Expr);
13422 if not Is_Assignable (Arg_Ent) then
13424 ("pragma% can only be applied to a variable",
13427 Set_Has_Pragma_Unmodified (Arg_Ent);
13439 -- pragma Unreferenced (local_Name {, local_Name});
13441 -- or when used in a context clause:
13443 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13445 when Pragma_Unreferenced => Unreferenced : declare
13446 Arg_Node : Node_Id;
13447 Arg_Expr : Node_Id;
13448 Arg_Ent : Entity_Id;
13453 Check_At_Least_N_Arguments (1);
13455 -- Check case of appearing within context clause
13457 if Is_In_Context_Clause then
13459 -- The arguments must all be units mentioned in a with clause
13460 -- in the same context clause. Note we already checked (in
13461 -- Par.Prag) that the arguments are either identifiers or
13462 -- selected components.
13465 while Present (Arg_Node) loop
13466 Citem := First (List_Containing (N));
13467 while Citem /= N loop
13468 if Nkind (Citem) = N_With_Clause
13470 Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13472 Set_Has_Pragma_Unreferenced
13475 (Library_Unit (Citem))));
13477 (Get_Pragma_Arg (Arg_Node), Name (Citem));
13486 ("argument of pragma% is not with'ed unit", Arg_Node);
13492 -- Case of not in list of context items
13496 while Present (Arg_Node) loop
13497 Check_No_Identifier (Arg_Node);
13499 -- Note: the analyze call done by Check_Arg_Is_Local_Name
13500 -- will in fact generate reference, so that the entity will
13501 -- have a reference, which will inhibit any warnings about
13502 -- it not being referenced, and also properly show up in the
13503 -- ali file as a reference. But this reference is recorded
13504 -- before the Has_Pragma_Unreferenced flag is set, so that
13505 -- no warning is generated for this reference.
13507 Check_Arg_Is_Local_Name (Arg_Node);
13508 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13510 if Is_Entity_Name (Arg_Expr) then
13511 Arg_Ent := Entity (Arg_Expr);
13513 -- If the entity is overloaded, the pragma applies to the
13514 -- most recent overloading, as documented. In this case,
13515 -- name resolution does not generate a reference, so it
13516 -- must be done here explicitly.
13518 if Is_Overloaded (Arg_Expr) then
13519 Generate_Reference (Arg_Ent, N);
13522 Set_Has_Pragma_Unreferenced (Arg_Ent);
13530 --------------------------
13531 -- Unreferenced_Objects --
13532 --------------------------
13534 -- pragma Unreferenced_Objects (local_Name {, local_Name});
13536 when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13537 Arg_Node : Node_Id;
13538 Arg_Expr : Node_Id;
13542 Check_At_Least_N_Arguments (1);
13545 while Present (Arg_Node) loop
13546 Check_No_Identifier (Arg_Node);
13547 Check_Arg_Is_Local_Name (Arg_Node);
13548 Arg_Expr := Get_Pragma_Arg (Arg_Node);
13550 if not Is_Entity_Name (Arg_Expr)
13551 or else not Is_Type (Entity (Arg_Expr))
13554 ("argument for pragma% must be type or subtype", Arg_Node);
13557 Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13560 end Unreferenced_Objects;
13562 ------------------------------
13563 -- Unreserve_All_Interrupts --
13564 ------------------------------
13566 -- pragma Unreserve_All_Interrupts;
13568 when Pragma_Unreserve_All_Interrupts =>
13570 Check_Arg_Count (0);
13572 if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13573 Unreserve_All_Interrupts := True;
13580 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13582 when Pragma_Unsuppress =>
13584 Process_Suppress_Unsuppress (False);
13586 -------------------
13587 -- Use_VADS_Size --
13588 -------------------
13590 -- pragma Use_VADS_Size;
13592 when Pragma_Use_VADS_Size =>
13594 Check_Arg_Count (0);
13595 Check_Valid_Configuration_Pragma;
13596 Use_VADS_Size := True;
13598 ---------------------
13599 -- Validity_Checks --
13600 ---------------------
13602 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13604 when Pragma_Validity_Checks => Validity_Checks : declare
13605 A : constant Node_Id := Get_Pragma_Arg (Arg1);
13611 Check_Arg_Count (1);
13612 Check_No_Identifiers;
13614 if Nkind (A) = N_String_Literal then
13618 Slen : constant Natural := Natural (String_Length (S));
13619 Options : String (1 .. Slen);
13625 C := Get_String_Char (S, Int (J));
13626 exit when not In_Character_Range (C);
13627 Options (J) := Get_Character (C);
13630 Set_Validity_Check_Options (Options);
13638 elsif Nkind (A) = N_Identifier then
13640 if Chars (A) = Name_All_Checks then
13641 Set_Validity_Check_Options ("a");
13643 elsif Chars (A) = Name_On then
13644 Validity_Checks_On := True;
13646 elsif Chars (A) = Name_Off then
13647 Validity_Checks_On := False;
13651 end Validity_Checks;
13657 -- pragma Volatile (LOCAL_NAME);
13659 when Pragma_Volatile =>
13660 Process_Atomic_Shared_Volatile;
13662 -------------------------
13663 -- Volatile_Components --
13664 -------------------------
13666 -- pragma Volatile_Components (array_LOCAL_NAME);
13668 -- Volatile is handled by the same circuit as Atomic_Components
13674 -- pragma Warnings (On | Off);
13675 -- pragma Warnings (On | Off, LOCAL_NAME);
13676 -- pragma Warnings (static_string_EXPRESSION);
13677 -- pragma Warnings (On | Off, STRING_LITERAL);
13679 when Pragma_Warnings => Warnings : begin
13681 Check_At_Least_N_Arguments (1);
13682 Check_No_Identifiers;
13684 -- If debug flag -gnatd.i is set, pragma is ignored
13686 if Debug_Flag_Dot_I then
13690 -- Process various forms of the pragma
13693 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13696 -- One argument case
13698 if Arg_Count = 1 then
13700 -- On/Off one argument case was processed by parser
13702 if Nkind (Argx) = N_Identifier
13704 (Chars (Argx) = Name_On
13706 Chars (Argx) = Name_Off)
13710 -- One argument case must be ON/OFF or static string expr
13712 elsif not Is_Static_String_Expression (Arg1) then
13714 ("argument of pragma% must be On/Off or " &
13715 "static string expression", Arg1);
13717 -- One argument string expression case
13721 Lit : constant Node_Id := Expr_Value_S (Argx);
13722 Str : constant String_Id := Strval (Lit);
13723 Len : constant Nat := String_Length (Str);
13731 while J <= Len loop
13732 C := Get_String_Char (Str, J);
13733 OK := In_Character_Range (C);
13736 Chr := Get_Character (C);
13740 if J < Len and then Chr = '.' then
13742 C := Get_String_Char (Str, J);
13743 Chr := Get_Character (C);
13745 if not Set_Dot_Warning_Switch (Chr) then
13747 ("invalid warning switch character " &
13754 OK := Set_Warning_Switch (Chr);
13760 ("invalid warning switch character " & Chr,
13769 -- Two or more arguments (must be two)
13772 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13773 Check_At_Most_N_Arguments (2);
13781 E_Id := Get_Pragma_Arg (Arg2);
13784 -- In the expansion of an inlined body, a reference to
13785 -- the formal may be wrapped in a conversion if the
13786 -- actual is a conversion. Retrieve the real entity name.
13788 if (In_Instance_Body
13789 or else In_Inlined_Body)
13790 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13792 E_Id := Expression (E_Id);
13795 -- Entity name case
13797 if Is_Entity_Name (E_Id) then
13798 E := Entity (E_Id);
13805 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13808 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13809 and then Warn_On_Warnings_Off
13811 Warnings_Off_Pragmas.Append ((N, E));
13814 if Is_Enumeration_Type (E) then
13818 Lit := First_Literal (E);
13819 while Present (Lit) loop
13820 Set_Warnings_Off (Lit);
13821 Next_Literal (Lit);
13826 exit when No (Homonym (E));
13831 -- Error if not entity or static string literal case
13833 elsif not Is_Static_String_Expression (Arg2) then
13835 ("second argument of pragma% must be entity " &
13836 "name or static string expression", Arg2);
13838 -- String literal case
13841 String_To_Name_Buffer
13842 (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13844 -- Note on configuration pragma case: If this is a
13845 -- configuration pragma, then for an OFF pragma, we
13846 -- just set Config True in the call, which is all
13847 -- that needs to be done. For the case of ON, this
13848 -- is normally an error, unless it is canceling the
13849 -- effect of a previous OFF pragma in the same file.
13850 -- In any other case, an error will be signalled (ON
13851 -- with no matching OFF).
13853 if Chars (Argx) = Name_Off then
13854 Set_Specific_Warning_Off
13855 (Loc, Name_Buffer (1 .. Name_Len),
13856 Config => Is_Configuration_Pragma);
13858 elsif Chars (Argx) = Name_On then
13859 Set_Specific_Warning_On
13860 (Loc, Name_Buffer (1 .. Name_Len), Err);
13864 ("?pragma Warnings On with no " &
13865 "matching Warnings Off",
13875 -------------------
13876 -- Weak_External --
13877 -------------------
13879 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
13881 when Pragma_Weak_External => Weak_External : declare
13886 Check_Arg_Count (1);
13887 Check_Optional_Identifier (Arg1, Name_Entity);
13888 Check_Arg_Is_Library_Level_Local_Name (Arg1);
13889 Ent := Entity (Get_Pragma_Arg (Arg1));
13891 if Rep_Item_Too_Early (Ent, N) then
13894 Ent := Underlying_Type (Ent);
13897 -- The only processing required is to link this item on to the
13898 -- list of rep items for the given entity. This is accomplished
13899 -- by the call to Rep_Item_Too_Late (when no error is detected
13900 -- and False is returned).
13902 if Rep_Item_Too_Late (Ent, N) then
13905 Set_Has_Gigi_Rep_Item (Ent);
13909 -----------------------------
13910 -- Wide_Character_Encoding --
13911 -----------------------------
13913 -- pragma Wide_Character_Encoding (IDENTIFIER);
13915 when Pragma_Wide_Character_Encoding =>
13918 -- Nothing to do, handled in parser. Note that we do not enforce
13919 -- configuration pragma placement, this pragma can appear at any
13920 -- place in the source, allowing mixed encodings within a single
13925 --------------------
13926 -- Unknown_Pragma --
13927 --------------------
13929 -- Should be impossible, since the case of an unknown pragma is
13930 -- separately processed before the case statement is entered.
13932 when Unknown_Pragma =>
13933 raise Program_Error;
13936 -- AI05-0144: detect dangerous order dependence. Disabled for now,
13937 -- until AI is formally approved.
13939 -- Check_Order_Dependence;
13942 when Pragma_Exit => null;
13943 end Analyze_Pragma;
13945 -------------------
13946 -- Check_Enabled --
13947 -------------------
13949 function Check_Enabled (Nam : Name_Id) return Boolean is
13953 -- Loop through entries in check policy list
13955 PP := Opt.Check_Policy_List;
13957 -- If there are no specific entries that matched, then we let the
13958 -- setting of assertions govern. Note that this provides the needed
13959 -- compatibility with the RM for the cases of assertion, invariant,
13960 -- precondition, predicate, and postcondition.
13963 return Assertions_Enabled;
13965 -- Here we have an entry see if it matches
13969 PPA : constant List_Id := Pragma_Argument_Associations (PP);
13972 if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13973 case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13974 when Name_On | Name_Check =>
13976 when Name_Off | Name_Ignore =>
13979 raise Program_Error;
13983 PP := Next_Pragma (PP);
13990 ---------------------------------
13991 -- Delay_Config_Pragma_Analyze --
13992 ---------------------------------
13994 function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13996 return Pragma_Name (N) = Name_Interrupt_State
13998 Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13999 end Delay_Config_Pragma_Analyze;
14001 -------------------------
14002 -- Get_Base_Subprogram --
14003 -------------------------
14005 function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14006 Result : Entity_Id;
14009 -- Follow subprogram renaming chain
14012 while Is_Subprogram (Result)
14014 Nkind (Parent (Declaration_Node (Result))) =
14015 N_Subprogram_Renaming_Declaration
14016 and then Present (Alias (Result))
14018 Result := Alias (Result);
14022 end Get_Base_Subprogram;
14028 procedure Initialize is
14033 -----------------------------
14034 -- Is_Config_Static_String --
14035 -----------------------------
14037 function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14039 function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14040 -- This is an internal recursive function that is just like the outer
14041 -- function except that it adds the string to the name buffer rather
14042 -- than placing the string in the name buffer.
14044 ------------------------------
14045 -- Add_Config_Static_String --
14046 ------------------------------
14048 function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14055 if Nkind (N) = N_Op_Concat then
14056 if Add_Config_Static_String (Left_Opnd (N)) then
14057 N := Right_Opnd (N);
14063 if Nkind (N) /= N_String_Literal then
14064 Error_Msg_N ("string literal expected for pragma argument", N);
14068 for J in 1 .. String_Length (Strval (N)) loop
14069 C := Get_String_Char (Strval (N), J);
14071 if not In_Character_Range (C) then
14073 ("string literal contains invalid wide character",
14074 Sloc (N) + 1 + Source_Ptr (J));
14078 Add_Char_To_Name_Buffer (Get_Character (C));
14083 end Add_Config_Static_String;
14085 -- Start of processing for Is_Config_Static_String
14090 return Add_Config_Static_String (Arg);
14091 end Is_Config_Static_String;
14093 -----------------------------------------
14094 -- Is_Non_Significant_Pragma_Reference --
14095 -----------------------------------------
14097 -- This function makes use of the following static table which indicates
14098 -- whether a given pragma is significant.
14100 -- -1 indicates that references in any argument position are significant
14101 -- 0 indicates that appearance in any argument is not significant
14102 -- +n indicates that appearance as argument n is significant, but all
14103 -- other arguments are not significant
14104 -- 99 special processing required (e.g. for pragma Check)
14106 Sig_Flags : constant array (Pragma_Id) of Int :=
14107 (Pragma_AST_Entry => -1,
14108 Pragma_Abort_Defer => -1,
14109 Pragma_Ada_83 => -1,
14110 Pragma_Ada_95 => -1,
14111 Pragma_Ada_05 => -1,
14112 Pragma_Ada_2005 => -1,
14113 Pragma_Ada_12 => -1,
14114 Pragma_Ada_2012 => -1,
14115 Pragma_All_Calls_Remote => -1,
14116 Pragma_Annotate => -1,
14117 Pragma_Assert => -1,
14118 Pragma_Assertion_Policy => 0,
14119 Pragma_Assume_No_Invalid_Values => 0,
14120 Pragma_Asynchronous => -1,
14121 Pragma_Atomic => 0,
14122 Pragma_Atomic_Components => 0,
14123 Pragma_Attach_Handler => -1,
14124 Pragma_Check => 99,
14125 Pragma_Check_Name => 0,
14126 Pragma_Check_Policy => 0,
14127 Pragma_CIL_Constructor => -1,
14128 Pragma_CPP_Class => 0,
14129 Pragma_CPP_Constructor => 0,
14130 Pragma_CPP_Virtual => 0,
14131 Pragma_CPP_Vtable => 0,
14133 Pragma_C_Pass_By_Copy => 0,
14134 Pragma_Comment => 0,
14135 Pragma_Common_Object => -1,
14136 Pragma_Compile_Time_Error => -1,
14137 Pragma_Compile_Time_Warning => -1,
14138 Pragma_Compiler_Unit => 0,
14139 Pragma_Complete_Representation => 0,
14140 Pragma_Complex_Representation => 0,
14141 Pragma_Component_Alignment => -1,
14142 Pragma_Controlled => 0,
14143 Pragma_Convention => 0,
14144 Pragma_Convention_Identifier => 0,
14145 Pragma_Debug => -1,
14146 Pragma_Debug_Policy => 0,
14147 Pragma_Detect_Blocking => -1,
14148 Pragma_Default_Storage_Pool => -1,
14149 Pragma_Dimension => -1,
14150 Pragma_Discard_Names => 0,
14151 Pragma_Elaborate => -1,
14152 Pragma_Elaborate_All => -1,
14153 Pragma_Elaborate_Body => -1,
14154 Pragma_Elaboration_Checks => -1,
14155 Pragma_Eliminate => -1,
14156 Pragma_Export => -1,
14157 Pragma_Export_Exception => -1,
14158 Pragma_Export_Function => -1,
14159 Pragma_Export_Object => -1,
14160 Pragma_Export_Procedure => -1,
14161 Pragma_Export_Value => -1,
14162 Pragma_Export_Valued_Procedure => -1,
14163 Pragma_Extend_System => -1,
14164 Pragma_Extensions_Allowed => -1,
14165 Pragma_External => -1,
14166 Pragma_Favor_Top_Level => -1,
14167 Pragma_External_Name_Casing => -1,
14168 Pragma_Fast_Math => -1,
14169 Pragma_Finalize_Storage_Only => 0,
14170 Pragma_Float_Representation => 0,
14171 Pragma_Ident => -1,
14172 Pragma_Implemented => -1,
14173 Pragma_Implicit_Packing => 0,
14174 Pragma_Import => +2,
14175 Pragma_Import_Exception => 0,
14176 Pragma_Import_Function => 0,
14177 Pragma_Import_Object => 0,
14178 Pragma_Import_Procedure => 0,
14179 Pragma_Import_Valued_Procedure => 0,
14180 Pragma_Independent => 0,
14181 Pragma_Independent_Components => 0,
14182 Pragma_Initialize_Scalars => -1,
14183 Pragma_Inline => 0,
14184 Pragma_Inline_Always => 0,
14185 Pragma_Inline_Generic => 0,
14186 Pragma_Inspection_Point => -1,
14187 Pragma_Interface => +2,
14188 Pragma_Interface_Name => +2,
14189 Pragma_Interrupt_Handler => -1,
14190 Pragma_Interrupt_Priority => -1,
14191 Pragma_Interrupt_State => -1,
14192 Pragma_Invariant => -1,
14193 Pragma_Java_Constructor => -1,
14194 Pragma_Java_Interface => -1,
14195 Pragma_Keep_Names => 0,
14196 Pragma_License => -1,
14197 Pragma_Link_With => -1,
14198 Pragma_Linker_Alias => -1,
14199 Pragma_Linker_Constructor => -1,
14200 Pragma_Linker_Destructor => -1,
14201 Pragma_Linker_Options => -1,
14202 Pragma_Linker_Section => -1,
14204 Pragma_Locking_Policy => -1,
14205 Pragma_Long_Float => -1,
14206 Pragma_Machine_Attribute => -1,
14208 Pragma_Main_Storage => -1,
14209 Pragma_Memory_Size => -1,
14210 Pragma_No_Return => 0,
14211 Pragma_No_Body => 0,
14212 Pragma_No_Run_Time => -1,
14213 Pragma_No_Strict_Aliasing => -1,
14214 Pragma_Normalize_Scalars => -1,
14215 Pragma_Obsolescent => 0,
14216 Pragma_Optimize => -1,
14217 Pragma_Optimize_Alignment => -1,
14218 Pragma_Ordered => 0,
14221 Pragma_Passive => -1,
14222 Pragma_Preelaborable_Initialization => -1,
14223 Pragma_Polling => -1,
14224 Pragma_Persistent_BSS => 0,
14225 Pragma_Postcondition => -1,
14226 Pragma_Precondition => -1,
14227 Pragma_Predicate => -1,
14228 Pragma_Preelaborate => -1,
14229 Pragma_Preelaborate_05 => -1,
14230 Pragma_Priority => -1,
14231 Pragma_Priority_Specific_Dispatching => -1,
14232 Pragma_Profile => 0,
14233 Pragma_Profile_Warnings => 0,
14234 Pragma_Propagate_Exceptions => -1,
14235 Pragma_Psect_Object => -1,
14237 Pragma_Pure_05 => -1,
14238 Pragma_Pure_Function => -1,
14239 Pragma_Queuing_Policy => -1,
14240 Pragma_Ravenscar => -1,
14241 Pragma_Relative_Deadline => -1,
14242 Pragma_Remote_Call_Interface => -1,
14243 Pragma_Remote_Types => -1,
14244 Pragma_Restricted_Run_Time => -1,
14245 Pragma_Restriction_Warnings => -1,
14246 Pragma_Restrictions => -1,
14247 Pragma_Reviewable => -1,
14248 Pragma_Short_Circuit_And_Or => -1,
14249 Pragma_Share_Generic => -1,
14250 Pragma_Shared => -1,
14251 Pragma_Shared_Passive => -1,
14252 Pragma_Short_Descriptors => 0,
14253 Pragma_Source_File_Name => -1,
14254 Pragma_Source_File_Name_Project => -1,
14255 Pragma_Source_Reference => -1,
14256 Pragma_Storage_Size => -1,
14257 Pragma_Storage_Unit => -1,
14258 Pragma_Static_Elaboration_Desired => -1,
14259 Pragma_Stream_Convert => -1,
14260 Pragma_Style_Checks => -1,
14261 Pragma_Subtitle => -1,
14262 Pragma_Suppress => 0,
14263 Pragma_Suppress_Exception_Locations => 0,
14264 Pragma_Suppress_All => -1,
14265 Pragma_Suppress_Debug_Info => 0,
14266 Pragma_Suppress_Initialization => 0,
14267 Pragma_System_Name => -1,
14268 Pragma_Task_Dispatching_Policy => -1,
14269 Pragma_Task_Info => -1,
14270 Pragma_Task_Name => -1,
14271 Pragma_Task_Storage => 0,
14272 Pragma_Thread_Local_Storage => 0,
14273 Pragma_Time_Slice => -1,
14274 Pragma_Title => -1,
14275 Pragma_Unchecked_Union => 0,
14276 Pragma_Unimplemented_Unit => -1,
14277 Pragma_Universal_Aliasing => -1,
14278 Pragma_Universal_Data => -1,
14279 Pragma_Unmodified => -1,
14280 Pragma_Unreferenced => -1,
14281 Pragma_Unreferenced_Objects => -1,
14282 Pragma_Unreserve_All_Interrupts => -1,
14283 Pragma_Unsuppress => 0,
14284 Pragma_Use_VADS_Size => -1,
14285 Pragma_Validity_Checks => -1,
14286 Pragma_Volatile => 0,
14287 Pragma_Volatile_Components => 0,
14288 Pragma_Warnings => -1,
14289 Pragma_Weak_External => -1,
14290 Pragma_Wide_Character_Encoding => 0,
14291 Unknown_Pragma => 0);
14293 function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14302 if Nkind (P) /= N_Pragma_Argument_Association then
14306 Id := Get_Pragma_Id (Parent (P));
14307 C := Sig_Flags (Id);
14319 -- For pragma Check, the first argument is not significant,
14320 -- the second and the third (if present) arguments are
14323 when Pragma_Check =>
14325 P = First (Pragma_Argument_Associations (Parent (P)));
14328 raise Program_Error;
14332 A := First (Pragma_Argument_Associations (Parent (P)));
14333 for J in 1 .. C - 1 loop
14341 return A = P; -- is this wrong way round ???
14344 end Is_Non_Significant_Pragma_Reference;
14346 ------------------------------
14347 -- Is_Pragma_String_Literal --
14348 ------------------------------
14350 -- This function returns true if the corresponding pragma argument is a
14351 -- static string expression. These are the only cases in which string
14352 -- literals can appear as pragma arguments. We also allow a string literal
14353 -- as the first argument to pragma Assert (although it will of course
14354 -- always generate a type error).
14356 function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14357 Pragn : constant Node_Id := Parent (Par);
14358 Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14359 Pname : constant Name_Id := Pragma_Name (Pragn);
14365 N := First (Assoc);
14372 if Pname = Name_Assert then
14375 elsif Pname = Name_Export then
14378 elsif Pname = Name_Ident then
14381 elsif Pname = Name_Import then
14384 elsif Pname = Name_Interface_Name then
14387 elsif Pname = Name_Linker_Alias then
14390 elsif Pname = Name_Linker_Section then
14393 elsif Pname = Name_Machine_Attribute then
14396 elsif Pname = Name_Source_File_Name then
14399 elsif Pname = Name_Source_Reference then
14402 elsif Pname = Name_Title then
14405 elsif Pname = Name_Subtitle then
14411 end Is_Pragma_String_Literal;
14413 --------------------------------------
14414 -- Process_Compilation_Unit_Pragmas --
14415 --------------------------------------
14417 procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14419 -- A special check for pragma Suppress_All, a very strange DEC pragma,
14420 -- strange because it comes at the end of the unit. Rational has the
14421 -- same name for a pragma, but treats it as a program unit pragma, In
14422 -- GNAT we just decide to allow it anywhere at all. If it appeared then
14423 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
14424 -- node, and we insert a pragma Suppress (All_Checks) at the start of
14425 -- the context clause to ensure the correct processing.
14427 if Has_Pragma_Suppress_All (N) then
14428 Prepend_To (Context_Items (N),
14429 Make_Pragma (Sloc (N),
14430 Chars => Name_Suppress,
14431 Pragma_Argument_Associations => New_List (
14432 Make_Pragma_Argument_Association (Sloc (N),
14433 Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14436 -- Nothing else to do at the current time!
14438 end Process_Compilation_Unit_Pragmas;
14449 --------------------------------
14450 -- Set_Encoded_Interface_Name --
14451 --------------------------------
14453 procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14454 Str : constant String_Id := Strval (S);
14455 Len : constant Int := String_Length (Str);
14460 Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14463 -- Stores encoded value of character code CC. The encoding we use an
14464 -- underscore followed by four lower case hex digits.
14470 procedure Encode is
14472 Store_String_Char (Get_Char_Code ('_'));
14474 (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14476 (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14478 (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14480 (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14483 -- Start of processing for Set_Encoded_Interface_Name
14486 -- If first character is asterisk, this is a link name, and we leave it
14487 -- completely unmodified. We also ignore null strings (the latter case
14488 -- happens only in error cases) and no encoding should occur for Java or
14489 -- AAMP interface names.
14492 or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14493 or else VM_Target /= No_VM
14494 or else AAMP_On_Target
14496 Set_Interface_Name (E, S);
14501 CC := Get_String_Char (Str, J);
14503 exit when not In_Character_Range (CC);
14505 C := Get_Character (CC);
14507 exit when C /= '_' and then C /= '$'
14508 and then C not in '0' .. '9'
14509 and then C not in 'a' .. 'z'
14510 and then C not in 'A' .. 'Z';
14513 Set_Interface_Name (E, S);
14521 -- Here we need to encode. The encoding we use as follows:
14522 -- three underscores + four hex digits (lower case)
14526 for J in 1 .. String_Length (Str) loop
14527 CC := Get_String_Char (Str, J);
14529 if not In_Character_Range (CC) then
14532 C := Get_Character (CC);
14534 if C = '_' or else C = '$'
14535 or else C in '0' .. '9'
14536 or else C in 'a' .. 'z'
14537 or else C in 'A' .. 'Z'
14539 Store_String_Char (CC);
14546 Set_Interface_Name (E,
14547 Make_String_Literal (Sloc (S),
14548 Strval => End_String));
14550 end Set_Encoded_Interface_Name;
14552 -------------------
14553 -- Set_Unit_Name --
14554 -------------------
14556 procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14561 if Nkind (N) = N_Identifier
14562 and then Nkind (With_Item) = N_Identifier
14564 Set_Entity (N, Entity (With_Item));
14566 elsif Nkind (N) = N_Selected_Component then
14567 Change_Selected_Component_To_Expanded_Name (N);
14568 Set_Entity (N, Entity (With_Item));
14569 Set_Entity (Selector_Name (N), Entity (N));
14571 Pref := Prefix (N);
14572 Scop := Scope (Entity (N));
14573 while Nkind (Pref) = N_Selected_Component loop
14574 Change_Selected_Component_To_Expanded_Name (Pref);
14575 Set_Entity (Selector_Name (Pref), Scop);
14576 Set_Entity (Pref, Scop);
14577 Pref := Prefix (Pref);
14578 Scop := Scope (Scop);
14581 Set_Entity (Pref, Scop);